drawDB/src/components/editor_panel.jsx

94 lines
2.7 KiB
React
Raw Normal View History

2023-09-19 20:48:57 +08:00
import { React, useContext } from "react";
2023-09-19 20:47:01 +08:00
import CodeMirror from "@uiw/react-codemirror";
import { createTheme } from "@uiw/codemirror-themes";
import { sql } from "@codemirror/lang-sql";
import { tags as t } from "@lezer/highlight";
2023-09-19 20:47:50 +08:00
import { Tabs } from "@douyinfe/semi-ui";
import TableOverview from "./table_overview";
import ReferenceOverview from "./reference_overview";
2023-09-19 20:48:55 +08:00
import AreaOverview from "./area_overview";
2023-09-19 20:48:57 +08:00
import { Tab } from "../data/data";
import { TabContext } from "../pages/editor";
2023-09-19 20:49:09 +08:00
import NotesOverview from "./notes_overview";
2023-09-19 20:49:13 +08:00
import Issues from "./issues";
2023-09-19 20:47:01 +08:00
const myTheme = createTheme({
dark: "light",
settings: {},
styles: [
{ tag: t.comment, color: "#8ab0ed" },
{ tag: t.string, color: "#e68e29" },
{ tag: t.number, color: "#e68e29" },
{ tag: t.keyword, color: "#295be6" },
{ tag: t.variableName, color: "#1a00db" },
{ tag: t.typeName, color: "#295be6" },
{ tag: t.tagName, color: "#008a02" },
],
});
2023-09-19 20:48:14 +08:00
const EditorPanel = (props) => {
2023-09-19 20:48:48 +08:00
// const map = useRef(new Map());
2023-09-19 20:49:13 +08:00
const { tab, setTab } = useContext(TabContext);
2023-09-19 20:47:01 +08:00
2023-09-19 20:47:50 +08:00
const tabList = [
2023-09-19 20:48:57 +08:00
{ tab: "Tables", itemKey: Tab.tables },
{ tab: "Relationships", itemKey: Tab.relationships },
{ tab: "Subject Areas", itemKey: Tab.subject_areas },
{ tab: "Editor", itemKey: Tab.editor },
2023-09-19 20:49:09 +08:00
{ tab: "Notes", itemKey: Tab.notes },
2023-09-19 20:47:50 +08:00
];
const contentList = [
2023-09-19 20:48:53 +08:00
<TableOverview
selectedTable={props.selectedTable}
setSelectedTable={props.setSelectedTable}
/>,
<ReferenceOverview />,
2023-09-19 20:49:13 +08:00
<AreaOverview />,
2023-09-19 20:48:32 +08:00
<CodeMirror
value={props.code}
height="100%"
theme={myTheme}
extensions={[sql()]}
onChange={(e) => {
props.setCode(e);
}}
/>,
2023-09-19 20:49:13 +08:00
<NotesOverview />,
2023-09-19 20:47:50 +08:00
];
2023-09-19 20:47:01 +08:00
return (
2023-09-19 20:48:38 +08:00
<div className="flex h-full">
2023-09-19 20:49:13 +08:00
<div className="flex flex-col h-full relative">
<div className="h-full flex-1 overflow-y-auto">
<div style={{ width: `${props.width}px` }}>
<Tabs
type="card"
activeKey={tab}
tabList={tabList}
onChange={(key) => {
setTab(key);
}}
collapsible
>
<div className="p-2">{contentList[parseInt(tab) - 1]}</div>
</Tabs>
</div>
</div>
<div className="mt-auto border-t-2 border-gray-300">
<Issues />
</div>
2023-09-19 20:47:01 +08:00
</div>
2023-09-19 20:48:30 +08:00
<div
2023-09-19 20:48:38 +08:00
className={`flex justify-center items-center p-1 h-auto hover:bg-slate-300 cursor-col-resize ${
2023-09-19 20:48:32 +08:00
props.resize ? "bg-slate-300" : ""
}`}
2023-09-19 20:48:30 +08:00
onMouseDown={() => props.setResize(true)}
>
<div className="w-1 border-x border-white h-1/6" />
</div>
</div>
2023-09-19 20:47:01 +08:00
);
2023-09-19 20:48:14 +08:00
};
2023-09-19 20:48:13 +08:00
export default EditorPanel;