Skip to content

Commit

Permalink
Parse input
Browse files Browse the repository at this point in the history
  • Loading branch information
1ilit committed Nov 24, 2024
1 parent feb41e8 commit 2eb1b4b
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 1 deletion.
53 changes: 53 additions & 0 deletions package-lock.json

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

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"dependencies": {
"@codemirror/lang-json": "^6.0.1",
"@codemirror/lang-sql": "^6.6.3",
"@dbml/core": "^3.9.3",
"@douyinfe/semi-ui": "^2.51.3",
"@lexical/react": "^0.12.5",
"@uiw/codemirror-theme-github": "^4.21.25",
Expand Down
21 changes: 20 additions & 1 deletion src/components/EditorSidePanel/DBMLEditor/DBMLEditor.jsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,35 @@
import { useEffect, useState } from "react";
import CodeMirror from "@uiw/react-codemirror";
import { vscodeDark, vscodeLight } from "@uiw/codemirror-theme-vscode";
import { languageExtension } from "../../../data/editorExtensions";
import { useSettings } from "../../../hooks";
import { useDebounceValue } from "usehooks-ts";
import { Parser } from "@dbml/core";
import "./styles.css";

const parser = new Parser();

export default function DBMLEditor() {
const { settings } = useSettings();
const [value, setValue] = useState("");
const [debouncedValue] = useDebounceValue(value, 1000);

useEffect(() => {
if (debouncedValue) {
try {
const database = parser.parse(debouncedValue, "dbml");
console.log(database);
} catch (e) {
console.log(e);
}
}
}, [debouncedValue]);

return (
<div>
<CodeMirror
extensions={languageExtension.sql}
onChange={() => {}}
onChange={(v) => setValue(v)}
theme={settings.mode === "dark" ? vscodeDark : vscodeLight}
/>
</div>
Expand Down

0 comments on commit 2eb1b4b

Please sign in to comment.