Skip to content

Commit feb41e8

Browse files
committed
Add dbml editor to sidepanel
1 parent 881768b commit feb41e8

File tree

11 files changed

+105
-31
lines changed

11 files changed

+105
-31
lines changed

package-lock.json

+25-5
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
"@douyinfe/semi-ui": "^2.51.3",
1616
"@lexical/react": "^0.12.5",
1717
"@uiw/codemirror-theme-github": "^4.21.25",
18-
"@uiw/codemirror-theme-vscode": "^4.21.25",
18+
"@uiw/codemirror-theme-vscode": "^4.23.6",
1919
"@uiw/react-codemirror": "^4.21.25",
2020
"@vercel/analytics": "^1.2.2",
2121
"axios": "^1.7.4",

src/components/EditorHeader/ControlPanel.jsx

+13
Original file line numberDiff line numberDiff line change
@@ -519,6 +519,9 @@ export default function ControlPanel({
519519
const viewStrictMode = () => {
520520
setSettings((prev) => ({ ...prev, strictMode: !prev.strictMode }));
521521
};
522+
const toggleDBMLEditor = () => {
523+
setLayout((prev) => ({ ...prev, dbmlEditor: !prev.dbmlEditor }));
524+
};
522525
const viewFieldSummary = () => {
523526
setSettings((prev) => ({
524527
...prev,
@@ -1178,6 +1181,15 @@ export default function ControlPanel({
11781181
function: () =>
11791182
setLayout((prev) => ({ ...prev, issues: !prev.issues })),
11801183
},
1184+
dbml_editor: {
1185+
state: layout.dbmlEditor ? (
1186+
<i className="bi bi-toggle-off" />
1187+
) : (
1188+
<i className="bi bi-toggle-on" />
1189+
),
1190+
function: toggleDBMLEditor,
1191+
shortcut: "Alt+E",
1192+
},
11811193
strict_mode: {
11821194
state: settings.strictMode ? (
11831195
<i className="bi bi-toggle-off" />
@@ -1377,6 +1389,7 @@ export default function ControlPanel({
13771389
preventDefault: true,
13781390
});
13791391
useHotkeys("ctrl+alt+w, meta+alt+w", fitWindow, { preventDefault: true });
1392+
useHotkeys("alt+e", toggleDBMLEditor, { preventDefault: true });
13801393

13811394
return (
13821395
<>

src/components/EditorHeader/Modal/Modal.jsx

+1-7
Original file line numberDiff line numberDiff line change
@@ -35,19 +35,13 @@ import SetTableWidth from "./SetTableWidth";
3535
import Language from "./Language";
3636
import Share from "./Share";
3737
import CodeMirror from "@uiw/react-codemirror";
38-
import { sql } from "@codemirror/lang-sql";
3938
import { vscodeDark } from "@uiw/codemirror-theme-vscode";
40-
import { json } from "@codemirror/lang-json";
4139
import { githubLight } from "@uiw/codemirror-theme-github";
4240
import { useTranslation } from "react-i18next";
4341
import { importSQL } from "../../../utils/importSQL";
4442
import { databases } from "../../../data/databases";
4543
import { isRtl } from "../../../i18n/utils/rtl";
46-
47-
const languageExtension = {
48-
sql: [sql()],
49-
json: [json()],
50-
};
44+
import { languageExtension } from "../../../data/editorExtensions";
5145

5246
export default function Modal({
5347
modal,
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import CodeMirror from "@uiw/react-codemirror";
2+
import { vscodeDark, vscodeLight } from "@uiw/codemirror-theme-vscode";
3+
import { languageExtension } from "../../../data/editorExtensions";
4+
import { useSettings } from "../../../hooks";
5+
import "./styles.css";
6+
7+
export default function DBMLEditor() {
8+
const { settings } = useSettings();
9+
return (
10+
<div>
11+
<CodeMirror
12+
extensions={languageExtension.sql}
13+
onChange={() => {}}
14+
theme={settings.mode === "dark" ? vscodeDark : vscodeLight}
15+
/>
16+
</div>
17+
);
18+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
.cm-editor {
2+
font-size: 13px;
3+
}
4+
5+
.ͼ1o {
6+
background-color: var(--semi-color-bg-0);
7+
}
8+
9+
.ͼ1o .cm-gutters {
10+
background-color: var(--semi-color-bg-0);
11+
}

src/components/EditorSidePanel/SidePanel.jsx

+26-17
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import { databases } from "../../data/databases";
1313
import EnumsTab from "./EnumsTab/EnumsTab";
1414
import { isRtl } from "../../i18n/utils/rtl";
1515
import i18n from "../../i18n/i18n";
16+
import DBMLEditor from "./DBMLEditor/DBMLEditor";
1617

1718
export default function SidePanel({ width, resize, setResize }) {
1819
const { layout } = useLayout();
@@ -58,23 +59,31 @@ export default function SidePanel({ width, resize, setResize }) {
5859
style={{ width: `${width}px` }}
5960
>
6061
<div className="h-full flex-1 overflow-y-auto">
61-
<Tabs
62-
type="card"
63-
activeKey={selectedElement.currentTab}
64-
lazyRender
65-
onChange={(key) =>
66-
setSelectedElement((prev) => ({ ...prev, currentTab: key }))
67-
}
68-
collapsible
69-
tabBarStyle={{ direction: "ltr" }}
70-
>
71-
{tabList.length &&
72-
tabList.map((tab) => (
73-
<TabPane tab={tab.tab} itemKey={tab.itemKey} key={tab.itemKey}>
74-
<div className="p-2">{tab.component}</div>
75-
</TabPane>
76-
))}
77-
</Tabs>
62+
{layout.dbmlEditor ? (
63+
<Tabs
64+
type="card"
65+
activeKey={selectedElement.currentTab}
66+
lazyRender
67+
onChange={(key) =>
68+
setSelectedElement((prev) => ({ ...prev, currentTab: key }))
69+
}
70+
collapsible
71+
tabBarStyle={{ direction: "ltr" }}
72+
>
73+
{tabList.length &&
74+
tabList.map((tab) => (
75+
<TabPane
76+
tab={tab.tab}
77+
itemKey={tab.itemKey}
78+
key={tab.itemKey}
79+
>
80+
<div className="p-2">{tab.component}</div>
81+
</TabPane>
82+
))}
83+
</Tabs>
84+
) : (
85+
<DBMLEditor />
86+
)}
7887
</div>
7988
{layout.issues && (
8089
<div className="mt-auto border-t-2 border-color shadow-inner">

src/context/LayoutContext.jsx

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ export default function LayoutContextProvider({ children }) {
88
sidebar: true,
99
issues: true,
1010
toolbar: true,
11+
dbmlEditor: false,
1112
});
1213

1314
return (

src/data/editorExtensions.js

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import { sql } from "@codemirror/lang-sql";
2+
import { json } from "@codemirror/lang-json";
3+
4+
export const languageExtension = {
5+
sql: [sql()],
6+
json: [json()],
7+
};

src/i18n/locales/en.js

+1
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,7 @@ const en = {
243243
failed_to_load: "Failed to load. Make sure the link is correct.",
244244
share_info:
245245
"* Sharing this link will not create a live real-time collaboration session.",
246+
dbml_editor: "DBML editor",
246247
},
247248
};
248249

src/index.css

+1-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@
5858
background-color: rgba(var(--semi-blue-6), 1);
5959
}
6060

61-
.semi-spin-wrapper{
61+
.semi-spin-wrapper {
6262
color: inherit;
6363
}
6464

0 commit comments

Comments
 (0)