Skip to content

Commit

Permalink
feat: convert dbml to database object in editor
Browse files Browse the repository at this point in the history
  • Loading branch information
alswl committed May 1, 2024
1 parent de4ffff commit 16ee195
Show file tree
Hide file tree
Showing 3 changed files with 93 additions and 2 deletions.
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,16 @@
"dependencies": {
"@antv/x6": "^2.18.1",
"@antv/x6-react-shape": "^2.2.3",
"@dbml/core": "^3.4.3",
"antd": "^5.16.5",
"axios": "^1.6.8",
"lodash-es": "^4.17.21",
"monaco-editor": "^0.48.0",
"react-monaco-editor": "^0.55.0",
"umi": "^4.1.10"
},
"devDependencies": {
"@types/lodash-es": "^4.17.12",
"@types/react": "^18.0.33",
"@types/react-dom": "^18.0.11",
"@umijs/plugins": "^4.1.10",
Expand Down
79 changes: 79 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 11 additions & 2 deletions src/pages/index.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import registerER from '@/nodes/er';
import { Graph, Node } from '@antv/x6';
import { register } from '@antv/x6-react-shape';
import { Parser } from '@dbml/core';
import { Col, Dropdown, Row, theme } from 'antd';
import { debounce } from 'lodash-es';
import { useEffect, useRef, useState } from 'react';
import MonacoEditor from 'react-monaco-editor';

import './index.less';

const CustomComponent = ({ node }: { node: Node }) => {
Expand Down Expand Up @@ -276,6 +279,7 @@ export default () => {
}`;
const [code, setCode] = useState(initCode);
const containerRef = useRef(null);
const parser = new Parser();

useEffect(() => {
registerER();
Expand All @@ -299,8 +303,10 @@ export default () => {

// onchange
const onChange = (newValue: any, e: any) => {
console.log('onChange', newValue, e);
const database = parser.parse(newValue, 'dbmlv2');
console.log(database);
};
const debouncedOnChange = debounce(onChange, 500);

return (
<Row>
Expand All @@ -314,8 +320,11 @@ export default () => {
value={code}
options={{
selectOnLineNumbers: true,
minimap: {
enabled: false,
},
}}
onChange={onChange}
onChange={debouncedOnChange}
editorDidMount={editorDidMount}
/>
</Col>
Expand Down

0 comments on commit 16ee195

Please sign in to comment.