diff --git a/package.json b/package.json index 0178487a59e..97af239f962 100644 --- a/package.json +++ b/package.json @@ -101,12 +101,14 @@ "majo": "^0.7.1", "markdown-toc": "^1.2.0", "moment": "^2.24.0", + "monaco-editor": "^0.18.1", "onchange": "^5.2.0", "prettier": "^1.18.2", "pretty-format": "^24.0.0", "react": "^16.8.3", "react-dom": "^16.8.3", "react-eva": "^1.1.7", + "react-monaco-editor": "^0.32.1", "react-test-renderer": "^16.11.0", "remark-parse": "^6.0.3", "remark-stringify": "^6.0.4", diff --git a/packages/react-schema-editor/src/components/SchemaCode.tsx b/packages/react-schema-editor/src/components/SchemaCode.tsx index e817715480c..04bea9c82a4 100644 --- a/packages/react-schema-editor/src/components/SchemaCode.tsx +++ b/packages/react-schema-editor/src/components/SchemaCode.tsx @@ -1,24 +1,97 @@ -import React from 'react' -// import MonacoEditor from 'react-monaco-editor' +import React, { useState } from 'react' +import { Button, Drawer, Icon, Tooltip, notification } from 'antd'; +import MonacoEditor from 'react-monaco-editor' +import moment from 'moment'; import { ISchemaCodeProps } from '../utils/types' +const options = { + selectOnLineNumbers: true +}; + +const styles = { + icon: { + fontSize: '24px', + color: '#fff', + marginBottom: '15px' + } +}; + export const SchemaCode: React.FC = ({ schema, onChange }) => { + const [showDrawer, setShowDrawer] = useState(false); + if (typeof schema === 'object') { schema = JSON.stringify(schema, null, '\t') } + const copySchema = () => { + const oEle = document.createElement('textarea'); + oEle.value = schema; + document.body.appendChild(oEle); + oEle.select(); + document.execCommand('Copy'); + oEle.style.display = 'none'; + notification + notification.open({ + message: 'shcema复制成功', + duration: 2, + }); + } + + const downloadSchema = () => { + const aEle = document.createElement('a'); + aEle.download = `${moment().format('YYYYMMDD-HHmmss')}schema.json`; + aEle.style.display = 'none'; + var blob = new Blob([schema], {type:'application/json,charset=utf-8;'}); + aEle.href = URL.createObjectURL(blob); + document.body.appendChild(aEle); + aEle.click(); + document.body.removeChild(aEle); + } + + const aside = ( +
+ + { setShowDrawer(true) }} style={styles.icon} /> + + + + + + + +
+ ); + return ( -
- {/* */} +
+ { + !showDrawer ? aside : null + } + + setShowDrawer(false)} > +
+ onChange(JSON.parse(schema))} + value={schema} + /> + { + showDrawer ? aside : null + } +
+
) } diff --git a/packages/react-schema-editor/src/index.tsx b/packages/react-schema-editor/src/index.tsx index 07376adbfab..94a44ec7902 100644 --- a/packages/react-schema-editor/src/index.tsx +++ b/packages/react-schema-editor/src/index.tsx @@ -17,11 +17,14 @@ export const SchemaEditor: React.FC<{ 预览
- - + + - + diff --git a/packages/react-schema-editor/src/main.scss b/packages/react-schema-editor/src/main.scss index d5ed7753ca1..2d2140842b0 100644 --- a/packages/react-schema-editor/src/main.scss +++ b/packages/react-schema-editor/src/main.scss @@ -29,7 +29,10 @@ .schema-tree {} /* 代码编辑 */ - .schema-code {} + .schema-code { + position: absolute; + right: 0; + } } .field-editor {