mirror of
https://github.com/drawdb-io/drawdb.git
synced 2025-05-24 10:29:11 +00:00
Add dbml editor to sidepanel
This commit is contained in:
parent
aaf83b6f28
commit
51b68e86b8
30
package-lock.json
generated
30
package-lock.json
generated
@ -13,7 +13,7 @@
|
|||||||
"@douyinfe/semi-ui": "^2.51.3",
|
"@douyinfe/semi-ui": "^2.51.3",
|
||||||
"@lexical/react": "^0.12.5",
|
"@lexical/react": "^0.12.5",
|
||||||
"@uiw/codemirror-theme-github": "^4.21.25",
|
"@uiw/codemirror-theme-github": "^4.21.25",
|
||||||
"@uiw/codemirror-theme-vscode": "^4.21.25",
|
"@uiw/codemirror-theme-vscode": "^4.23.6",
|
||||||
"@uiw/react-codemirror": "^4.21.25",
|
"@uiw/react-codemirror": "^4.21.25",
|
||||||
"@vercel/analytics": "^1.2.2",
|
"@vercel/analytics": "^1.2.2",
|
||||||
"axios": "^1.7.4",
|
"axios": "^1.7.4",
|
||||||
@ -2195,16 +2195,36 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/@uiw/codemirror-theme-vscode": {
|
"node_modules/@uiw/codemirror-theme-vscode": {
|
||||||
"version": "4.21.25",
|
"version": "4.23.6",
|
||||||
"resolved": "https://registry.npmjs.org/@uiw/codemirror-theme-vscode/-/codemirror-theme-vscode-4.21.25.tgz",
|
"resolved": "https://registry.npmjs.org/@uiw/codemirror-theme-vscode/-/codemirror-theme-vscode-4.23.6.tgz",
|
||||||
"integrity": "sha512-1gubCz7kHE5XH3H1IUTSrnyK/G3dQRmOIgPFsefE9e+TizhBJnkbKSDSfRfpm5l7jl1G7v/as0HQvN3cYg/Rkg==",
|
"integrity": "sha512-xUo1ic+Kk5hnv5gy+cXU12GZVSnDjic8s8weKq8loPHF1dSR1e6gkKVIKZRnvoOZ302taKRk7phWpBUaWIuKQg==",
|
||||||
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@uiw/codemirror-themes": "4.21.25"
|
"@uiw/codemirror-themes": "4.23.6"
|
||||||
},
|
},
|
||||||
"funding": {
|
"funding": {
|
||||||
"url": "https://jaywcjlove.github.io/#/sponsor"
|
"url": "https://jaywcjlove.github.io/#/sponsor"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/@uiw/codemirror-theme-vscode/node_modules/@uiw/codemirror-themes": {
|
||||||
|
"version": "4.23.6",
|
||||||
|
"resolved": "https://registry.npmjs.org/@uiw/codemirror-themes/-/codemirror-themes-4.23.6.tgz",
|
||||||
|
"integrity": "sha512-0dpuLQW+V6zrKvfvor/eo71V3tpr2L2Hsu8QZAdtSzksjWABxTOzH3ShaBRxCEsrz6sU9sa9o7ShwBMMDz59bQ==",
|
||||||
|
"license": "MIT",
|
||||||
|
"dependencies": {
|
||||||
|
"@codemirror/language": "^6.0.0",
|
||||||
|
"@codemirror/state": "^6.0.0",
|
||||||
|
"@codemirror/view": "^6.0.0"
|
||||||
|
},
|
||||||
|
"funding": {
|
||||||
|
"url": "https://jaywcjlove.github.io/#/sponsor"
|
||||||
|
},
|
||||||
|
"peerDependencies": {
|
||||||
|
"@codemirror/language": ">=6.0.0",
|
||||||
|
"@codemirror/state": ">=6.0.0",
|
||||||
|
"@codemirror/view": ">=6.0.0"
|
||||||
|
}
|
||||||
|
},
|
||||||
"node_modules/@uiw/codemirror-themes": {
|
"node_modules/@uiw/codemirror-themes": {
|
||||||
"version": "4.21.25",
|
"version": "4.21.25",
|
||||||
"resolved": "https://registry.npmjs.org/@uiw/codemirror-themes/-/codemirror-themes-4.21.25.tgz",
|
"resolved": "https://registry.npmjs.org/@uiw/codemirror-themes/-/codemirror-themes-4.21.25.tgz",
|
||||||
|
@ -15,7 +15,7 @@
|
|||||||
"@douyinfe/semi-ui": "^2.51.3",
|
"@douyinfe/semi-ui": "^2.51.3",
|
||||||
"@lexical/react": "^0.12.5",
|
"@lexical/react": "^0.12.5",
|
||||||
"@uiw/codemirror-theme-github": "^4.21.25",
|
"@uiw/codemirror-theme-github": "^4.21.25",
|
||||||
"@uiw/codemirror-theme-vscode": "^4.21.25",
|
"@uiw/codemirror-theme-vscode": "^4.23.6",
|
||||||
"@uiw/react-codemirror": "^4.21.25",
|
"@uiw/react-codemirror": "^4.21.25",
|
||||||
"@vercel/analytics": "^1.2.2",
|
"@vercel/analytics": "^1.2.2",
|
||||||
"axios": "^1.7.4",
|
"axios": "^1.7.4",
|
||||||
|
@ -516,6 +516,9 @@ export default function ControlPanel({
|
|||||||
const viewStrictMode = () => {
|
const viewStrictMode = () => {
|
||||||
setSettings((prev) => ({ ...prev, strictMode: !prev.strictMode }));
|
setSettings((prev) => ({ ...prev, strictMode: !prev.strictMode }));
|
||||||
};
|
};
|
||||||
|
const toggleDBMLEditor = () => {
|
||||||
|
setLayout((prev) => ({ ...prev, dbmlEditor: !prev.dbmlEditor }));
|
||||||
|
};
|
||||||
const viewFieldSummary = () => {
|
const viewFieldSummary = () => {
|
||||||
setSettings((prev) => ({
|
setSettings((prev) => ({
|
||||||
...prev,
|
...prev,
|
||||||
@ -1175,6 +1178,15 @@ export default function ControlPanel({
|
|||||||
function: () =>
|
function: () =>
|
||||||
setLayout((prev) => ({ ...prev, issues: !prev.issues })),
|
setLayout((prev) => ({ ...prev, issues: !prev.issues })),
|
||||||
},
|
},
|
||||||
|
dbml_editor: {
|
||||||
|
state: layout.dbmlEditor ? (
|
||||||
|
<i className="bi bi-toggle-off" />
|
||||||
|
) : (
|
||||||
|
<i className="bi bi-toggle-on" />
|
||||||
|
),
|
||||||
|
function: toggleDBMLEditor,
|
||||||
|
shortcut: "Alt+E",
|
||||||
|
},
|
||||||
strict_mode: {
|
strict_mode: {
|
||||||
state: settings.strictMode ? (
|
state: settings.strictMode ? (
|
||||||
<i className="bi bi-toggle-off" />
|
<i className="bi bi-toggle-off" />
|
||||||
@ -1386,6 +1398,7 @@ export default function ControlPanel({
|
|||||||
preventDefault: true,
|
preventDefault: true,
|
||||||
});
|
});
|
||||||
useHotkeys("ctrl+alt+w, meta+alt+w", fitWindow, { preventDefault: true });
|
useHotkeys("ctrl+alt+w, meta+alt+w", fitWindow, { preventDefault: true });
|
||||||
|
useHotkeys("alt+e", toggleDBMLEditor, { preventDefault: true });
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
|
18
src/components/EditorSidePanel/DBMLEditor/DBMLEditor.jsx
Normal file
18
src/components/EditorSidePanel/DBMLEditor/DBMLEditor.jsx
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
import CodeMirror from "@uiw/react-codemirror";
|
||||||
|
import { vscodeDark, vscodeLight } from "@uiw/codemirror-theme-vscode";
|
||||||
|
import { languageExtension } from "../../../data/editorExtensions";
|
||||||
|
import { useSettings } from "../../../hooks";
|
||||||
|
import "./styles.css";
|
||||||
|
|
||||||
|
export default function DBMLEditor() {
|
||||||
|
const { settings } = useSettings();
|
||||||
|
return (
|
||||||
|
<div>
|
||||||
|
<CodeMirror
|
||||||
|
extensions={languageExtension.sql}
|
||||||
|
onChange={() => {}}
|
||||||
|
theme={settings.mode === "dark" ? vscodeDark : vscodeLight}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
11
src/components/EditorSidePanel/DBMLEditor/styles.css
Normal file
11
src/components/EditorSidePanel/DBMLEditor/styles.css
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
.cm-editor {
|
||||||
|
font-size: 13px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.ͼ1o {
|
||||||
|
background-color: var(--semi-color-bg-0);
|
||||||
|
}
|
||||||
|
|
||||||
|
.ͼ1o .cm-gutters {
|
||||||
|
background-color: var(--semi-color-bg-0);
|
||||||
|
}
|
@ -21,6 +21,7 @@ import { databases } from "../../data/databases";
|
|||||||
import EnumsTab from "./EnumsTab/EnumsTab";
|
import EnumsTab from "./EnumsTab/EnumsTab";
|
||||||
import { isRtl } from "../../i18n/utils/rtl";
|
import { isRtl } from "../../i18n/utils/rtl";
|
||||||
import i18n from "../../i18n/i18n";
|
import i18n from "../../i18n/i18n";
|
||||||
|
import DBMLEditor from "./DBMLEditor/DBMLEditor";
|
||||||
|
|
||||||
export default function SidePanel({ width, resize, setResize }) {
|
export default function SidePanel({ width, resize, setResize }) {
|
||||||
const { layout } = useLayout();
|
const { layout } = useLayout();
|
||||||
@ -91,6 +92,7 @@ export default function SidePanel({ width, resize, setResize }) {
|
|||||||
style={{ width: `${width}px` }}
|
style={{ width: `${width}px` }}
|
||||||
>
|
>
|
||||||
<div className="h-full flex-1 overflow-y-auto">
|
<div className="h-full flex-1 overflow-y-auto">
|
||||||
|
<<<<<<< HEAD
|
||||||
<Tabs
|
<Tabs
|
||||||
type="card"
|
type="card"
|
||||||
activeKey={selectedElement.currentTab}
|
activeKey={selectedElement.currentTab}
|
||||||
@ -109,6 +111,33 @@ export default function SidePanel({ width, resize, setResize }) {
|
|||||||
</TabPane>
|
</TabPane>
|
||||||
))}
|
))}
|
||||||
</Tabs>
|
</Tabs>
|
||||||
|
=======
|
||||||
|
{layout.dbmlEditor ? (
|
||||||
|
<Tabs
|
||||||
|
type="card"
|
||||||
|
activeKey={selectedElement.currentTab}
|
||||||
|
lazyRender
|
||||||
|
onChange={(key) =>
|
||||||
|
setSelectedElement((prev) => ({ ...prev, currentTab: key }))
|
||||||
|
}
|
||||||
|
collapsible
|
||||||
|
tabBarStyle={{ direction: "ltr" }}
|
||||||
|
>
|
||||||
|
{tabList.length &&
|
||||||
|
tabList.map((tab) => (
|
||||||
|
<TabPane
|
||||||
|
tab={tab.tab}
|
||||||
|
itemKey={tab.itemKey}
|
||||||
|
key={tab.itemKey}
|
||||||
|
>
|
||||||
|
<div className="p-2">{tab.component}</div>
|
||||||
|
</TabPane>
|
||||||
|
))}
|
||||||
|
</Tabs>
|
||||||
|
) : (
|
||||||
|
<DBMLEditor />
|
||||||
|
)}
|
||||||
|
>>>>>>> feb41e8 (Add dbml editor to sidepanel)
|
||||||
</div>
|
</div>
|
||||||
{layout.issues && (
|
{layout.issues && (
|
||||||
<div className="mt-auto border-t-2 border-color shadow-inner">
|
<div className="mt-auto border-t-2 border-color shadow-inner">
|
||||||
|
@ -8,6 +8,7 @@ export default function LayoutContextProvider({ children }) {
|
|||||||
sidebar: true,
|
sidebar: true,
|
||||||
issues: true,
|
issues: true,
|
||||||
toolbar: true,
|
toolbar: true,
|
||||||
|
dbmlEditor: false,
|
||||||
});
|
});
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
7
src/data/editorExtensions.js
Normal file
7
src/data/editorExtensions.js
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
import { sql } from "@codemirror/lang-sql";
|
||||||
|
import { json } from "@codemirror/lang-json";
|
||||||
|
|
||||||
|
export const languageExtension = {
|
||||||
|
sql: [sql()],
|
||||||
|
json: [json()],
|
||||||
|
};
|
@ -243,7 +243,11 @@ const en = {
|
|||||||
failed_to_load: "Failed to load. Make sure the link is correct.",
|
failed_to_load: "Failed to load. Make sure the link is correct.",
|
||||||
share_info:
|
share_info:
|
||||||
"* Sharing this link will not create a live real-time collaboration session.",
|
"* Sharing this link will not create a live real-time collaboration session.",
|
||||||
|
<<<<<<< HEAD
|
||||||
show_relationship_labels: "Show relationship labels",
|
show_relationship_labels: "Show relationship labels",
|
||||||
|
=======
|
||||||
|
dbml_editor: "DBML editor",
|
||||||
|
>>>>>>> feb41e8 (Add dbml editor to sidepanel)
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -58,7 +58,7 @@
|
|||||||
background-color: rgba(var(--semi-blue-6), 1);
|
background-color: rgba(var(--semi-blue-6), 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
.semi-spin-wrapper{
|
.semi-spin-wrapper {
|
||||||
color: inherit;
|
color: inherit;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user