export png
This commit is contained in:
parent
ddaeec79ec
commit
92343dd645
@ -1,5 +1,4 @@
|
|||||||
import { React, useState } from "react";
|
import { React, useState } from "react";
|
||||||
import { menu } from "../data/data";
|
|
||||||
import {
|
import {
|
||||||
IconCaretdown,
|
IconCaretdown,
|
||||||
IconChevronRight,
|
IconChevronRight,
|
||||||
@ -17,18 +16,241 @@ import {
|
|||||||
Divider,
|
Divider,
|
||||||
Dropdown,
|
Dropdown,
|
||||||
Form,
|
Form,
|
||||||
|
Image,
|
||||||
|
Modal,
|
||||||
} from "@douyinfe/semi-ui";
|
} from "@douyinfe/semi-ui";
|
||||||
|
import { toPng } from "html-to-image";
|
||||||
|
import { saveAs } from "file-saver";
|
||||||
|
|
||||||
export default function ControlPanel() {
|
export default function ControlPanel() {
|
||||||
const [showToolBar, setShowToolBar] = useState(true);
|
const [showToolBar, setShowToolBar] = useState(true);
|
||||||
|
|
||||||
|
const [visible, setVisible] = useState(false);
|
||||||
|
const [dataUrl, setDataUrl] = useState("");
|
||||||
|
const [filename, setFilename] = useState(
|
||||||
|
`diagram_${new Date().toISOString()}`
|
||||||
|
);
|
||||||
|
|
||||||
|
const menu = {
|
||||||
|
File: {
|
||||||
|
New: {
|
||||||
|
children: [],
|
||||||
|
function: () => console.log("New"),
|
||||||
|
},
|
||||||
|
"New window": {
|
||||||
|
children: [],
|
||||||
|
function: () => {},
|
||||||
|
},
|
||||||
|
Save: {
|
||||||
|
children: [],
|
||||||
|
function: () => {},
|
||||||
|
},
|
||||||
|
"Save as": {
|
||||||
|
children: [],
|
||||||
|
function: () => {},
|
||||||
|
},
|
||||||
|
Share: {
|
||||||
|
children: [],
|
||||||
|
function: () => {},
|
||||||
|
},
|
||||||
|
Rename: {
|
||||||
|
children: [],
|
||||||
|
function: () => {},
|
||||||
|
},
|
||||||
|
Import: {
|
||||||
|
children: [],
|
||||||
|
function: () => {},
|
||||||
|
},
|
||||||
|
"Export as": {
|
||||||
|
children: [
|
||||||
|
{
|
||||||
|
".png": () => {
|
||||||
|
toPng(document.getElementById("canvas")).then(function (dataUrl) {
|
||||||
|
setDataUrl(dataUrl);
|
||||||
|
});
|
||||||
|
setVisible(true);
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{ ".jpg": () => {} },
|
||||||
|
{ ".xml": () => {} },
|
||||||
|
{ ".svg": () => {} },
|
||||||
|
{ ".xml": () => {} },
|
||||||
|
],
|
||||||
|
function: () => {},
|
||||||
|
},
|
||||||
|
"Export source": {
|
||||||
|
children: [
|
||||||
|
{ MySQL: () => {} },
|
||||||
|
{ PostgreSQL: () => {} },
|
||||||
|
{ DBML: () => {} },
|
||||||
|
],
|
||||||
|
function: () => {},
|
||||||
|
},
|
||||||
|
Properties: {
|
||||||
|
children: [],
|
||||||
|
function: () => {},
|
||||||
|
},
|
||||||
|
Close: {
|
||||||
|
children: [],
|
||||||
|
function: () => {},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
Edit: {
|
||||||
|
Undo: {
|
||||||
|
children: [],
|
||||||
|
function: () => {},
|
||||||
|
},
|
||||||
|
Redo: {
|
||||||
|
children: [],
|
||||||
|
function: () => {},
|
||||||
|
},
|
||||||
|
Cut: {
|
||||||
|
children: [],
|
||||||
|
function: () => {},
|
||||||
|
},
|
||||||
|
Copy: {
|
||||||
|
children: [],
|
||||||
|
function: () => {},
|
||||||
|
},
|
||||||
|
"Copy as image": {
|
||||||
|
children: [],
|
||||||
|
function: () => {},
|
||||||
|
},
|
||||||
|
Paste: {
|
||||||
|
children: [],
|
||||||
|
function: () => {},
|
||||||
|
},
|
||||||
|
Delete: {
|
||||||
|
children: [],
|
||||||
|
function: () => {},
|
||||||
|
},
|
||||||
|
"Edit table": {
|
||||||
|
children: [],
|
||||||
|
function: () => {},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
View: {
|
||||||
|
Toolbar: {
|
||||||
|
children: [],
|
||||||
|
function: () => {},
|
||||||
|
},
|
||||||
|
Grid: {
|
||||||
|
children: [],
|
||||||
|
function: () => {},
|
||||||
|
},
|
||||||
|
Sidebar: {
|
||||||
|
children: [],
|
||||||
|
function: () => {},
|
||||||
|
},
|
||||||
|
Editor: {
|
||||||
|
children: [],
|
||||||
|
function: () => {},
|
||||||
|
},
|
||||||
|
"Strict mode": {
|
||||||
|
children: [],
|
||||||
|
function: () => {},
|
||||||
|
},
|
||||||
|
"Reset view": {
|
||||||
|
children: [],
|
||||||
|
function: () => {},
|
||||||
|
},
|
||||||
|
"View schema": {
|
||||||
|
children: [],
|
||||||
|
function: () => {},
|
||||||
|
},
|
||||||
|
Theme: {
|
||||||
|
children: [{ Light: () => {} }, { Dark: () => {} }],
|
||||||
|
function: () => {},
|
||||||
|
},
|
||||||
|
"Zoom in": {
|
||||||
|
children: [],
|
||||||
|
function: () => {},
|
||||||
|
},
|
||||||
|
"Zoom out": {
|
||||||
|
children: [],
|
||||||
|
function: () => {},
|
||||||
|
},
|
||||||
|
Fullscreen: {
|
||||||
|
children: [],
|
||||||
|
function: () => {},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
Insert: {
|
||||||
|
"New table": {
|
||||||
|
children: [],
|
||||||
|
function: () => {},
|
||||||
|
},
|
||||||
|
"New relationship": {
|
||||||
|
children: [],
|
||||||
|
function: () => {},
|
||||||
|
},
|
||||||
|
Note: {
|
||||||
|
children: [],
|
||||||
|
function: () => {},
|
||||||
|
},
|
||||||
|
Image: {
|
||||||
|
children: [],
|
||||||
|
function: () => {},
|
||||||
|
},
|
||||||
|
Textbox: {
|
||||||
|
children: [],
|
||||||
|
function: () => {},
|
||||||
|
},
|
||||||
|
Shape: {
|
||||||
|
children: [],
|
||||||
|
function: () => {},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
Logs: {
|
||||||
|
"Open logs": {
|
||||||
|
children: [],
|
||||||
|
function: () => {},
|
||||||
|
},
|
||||||
|
"Commit changes": {
|
||||||
|
children: [],
|
||||||
|
function: () => {},
|
||||||
|
},
|
||||||
|
"Revert changes": {
|
||||||
|
children: [],
|
||||||
|
function: () => {},
|
||||||
|
},
|
||||||
|
"View commits": {
|
||||||
|
children: [],
|
||||||
|
function: () => {},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
Help: {
|
||||||
|
Shortcuts: {
|
||||||
|
children: [],
|
||||||
|
function: () => {},
|
||||||
|
},
|
||||||
|
"Ask us on discord": {
|
||||||
|
children: [],
|
||||||
|
function: () => {},
|
||||||
|
},
|
||||||
|
"Tweet us": {
|
||||||
|
children: [],
|
||||||
|
function: () => {},
|
||||||
|
},
|
||||||
|
"Found a bug": {
|
||||||
|
children: [],
|
||||||
|
function: () => {},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
{showToolBar && (
|
{showToolBar && (
|
||||||
<nav className="flex justify-between pt-1 items-center">
|
<nav className="flex justify-between pt-1 items-center whitespace-nowrap">
|
||||||
<div className="flex justify-start items-center text-slate-800">
|
<div className="flex justify-start items-center text-slate-800">
|
||||||
<Link to="/">
|
<Link to="/">
|
||||||
<img width={54} src={icon} alt="logo" className="ms-8" />
|
<img
|
||||||
|
width={54}
|
||||||
|
src={icon}
|
||||||
|
alt="logo"
|
||||||
|
className="ms-8 min-w-[54px]"
|
||||||
|
/>
|
||||||
</Link>
|
</Link>
|
||||||
<div className="ms-1 mt-1">
|
<div className="ms-1 mt-1">
|
||||||
<div className="text-xl ms-3">Project1 / Untitled</div>
|
<div className="text-xl ms-3">Project1 / Untitled</div>
|
||||||
@ -52,12 +274,11 @@ export default function ControlPanel() {
|
|||||||
<Dropdown.Menu>
|
<Dropdown.Menu>
|
||||||
{menu[category][item].children.map(
|
{menu[category][item].children.map(
|
||||||
(e, i) => (
|
(e, i) => (
|
||||||
<Dropdown.Item key={i}>
|
<Dropdown.Item
|
||||||
<button
|
key={i}
|
||||||
onClick={Object.values(e)[0]}
|
onClick={Object.values(e)[0]}
|
||||||
>
|
>
|
||||||
{Object.keys(e)[0]}
|
{Object.keys(e)[0]}
|
||||||
</button>
|
|
||||||
</Dropdown.Item>
|
</Dropdown.Item>
|
||||||
)
|
)
|
||||||
)}
|
)}
|
||||||
@ -70,22 +291,20 @@ export default function ControlPanel() {
|
|||||||
justifyContent: "space-between",
|
justifyContent: "space-between",
|
||||||
alignItems: "center",
|
alignItems: "center",
|
||||||
}}
|
}}
|
||||||
|
onClick={menu[category][item].function}
|
||||||
>
|
>
|
||||||
<button
|
{item}
|
||||||
onClick={menu[category][item].function}
|
|
||||||
>
|
|
||||||
{item}
|
|
||||||
</button>
|
|
||||||
<IconChevronRight />
|
<IconChevronRight />
|
||||||
</Dropdown.Item>
|
</Dropdown.Item>
|
||||||
</Dropdown>
|
</Dropdown>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
return (
|
return (
|
||||||
<Dropdown.Item key={index}>
|
<Dropdown.Item
|
||||||
<button onClick={menu[category][item].function}>
|
key={index}
|
||||||
{item}
|
onClick={menu[category][item].function}
|
||||||
</button>
|
>
|
||||||
|
{item}
|
||||||
</Dropdown.Item>
|
</Dropdown.Item>
|
||||||
);
|
);
|
||||||
})}
|
})}
|
||||||
@ -252,6 +471,35 @@ export default function ControlPanel() {
|
|||||||
{showToolBar ? <IconChevronUp /> : <IconChevronDown />}
|
{showToolBar ? <IconChevronUp /> : <IconChevronDown />}
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
|
<Modal
|
||||||
|
title="Export diagram"
|
||||||
|
visible={visible}
|
||||||
|
onOk={() => saveAs(dataUrl, `${filename}.png`)}
|
||||||
|
afterClose={() => setFilename(`diagram_${new Date().toISOString()}`)}
|
||||||
|
onCancel={() => setVisible(false)}
|
||||||
|
centered
|
||||||
|
closeOnEsc={true}
|
||||||
|
okText="Export"
|
||||||
|
cancelText="Cancel"
|
||||||
|
width={470}
|
||||||
|
>
|
||||||
|
<Image src={dataUrl} alt="Diagram" width={420}></Image>
|
||||||
|
<Form
|
||||||
|
labelPosition="left"
|
||||||
|
labelAlign="right"
|
||||||
|
onChange={(value) => {
|
||||||
|
console.log(value.values);
|
||||||
|
setFilename(value.values["filename"]);
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<Form.Input
|
||||||
|
field="filename"
|
||||||
|
label="Filename"
|
||||||
|
suffix={<div className="p-2">.png</div>}
|
||||||
|
initValue={filename}
|
||||||
|
/>
|
||||||
|
</Form>
|
||||||
|
</Modal>
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -5,7 +5,6 @@ import { createTheme } from "@uiw/codemirror-themes";
|
|||||||
import { sql } from "@codemirror/lang-sql";
|
import { sql } from "@codemirror/lang-sql";
|
||||||
import { tags as t } from "@lezer/highlight";
|
import { tags as t } from "@lezer/highlight";
|
||||||
import Shape from "./shape";
|
import Shape from "./shape";
|
||||||
// import { saveAs } from "file-saver";
|
|
||||||
import { toPng } from "html-to-image";
|
import { toPng } from "html-to-image";
|
||||||
import { Parser } from "node-sql-parser";
|
import { Parser } from "node-sql-parser";
|
||||||
import { Tabs } from "@douyinfe/semi-ui";
|
import { Tabs } from "@douyinfe/semi-ui";
|
||||||
@ -13,7 +12,7 @@ import "react-resizable/css/styles.css";
|
|||||||
import TableOverview from "./table_overview";
|
import TableOverview from "./table_overview";
|
||||||
import ReferenceOverview from "./reference_overview";
|
import ReferenceOverview from "./reference_overview";
|
||||||
import { defaultTableTheme } from "../data/data";
|
import { defaultTableTheme } from "../data/data";
|
||||||
import { ImagePreview, Image } from "@douyinfe/semi-ui";
|
import { ImagePreview } from "@douyinfe/semi-ui";
|
||||||
|
|
||||||
const myTheme = createTheme({
|
const myTheme = createTheme({
|
||||||
dark: "light",
|
dark: "light",
|
||||||
@ -187,15 +186,6 @@ const EditorPanel = (props) => {
|
|||||||
visible={visible1}
|
visible={visible1}
|
||||||
onVisibleChange={visibleChange1}
|
onVisibleChange={visibleChange1}
|
||||||
>
|
>
|
||||||
<div>
|
|
||||||
{visible1&&<Image
|
|
||||||
src={"https://lf3-static.bytednsdoc.com/obj/eden-cn/ptlz_zlp/ljhwZthlaukjlkulzlp/root-web-sites/abstract.jpg"}
|
|
||||||
width={200}
|
|
||||||
alt={`lamp${1}`}
|
|
||||||
|
|
||||||
style={{ marginRight: 5 }}
|
|
||||||
/>}
|
|
||||||
</div>
|
|
||||||
</ImagePreview>
|
</ImagePreview>
|
||||||
</div>
|
</div>
|
||||||
</ResizableBox>
|
</ResizableBox>
|
||||||
|
192
src/data/data.js
192
src/data/data.js
@ -1,194 +1,3 @@
|
|||||||
const menu = {
|
|
||||||
File: {
|
|
||||||
New: {
|
|
||||||
children: [],
|
|
||||||
function: () => console.log("New"),
|
|
||||||
},
|
|
||||||
"New window": {
|
|
||||||
children: [],
|
|
||||||
function: () => {},
|
|
||||||
},
|
|
||||||
Save: {
|
|
||||||
children: [],
|
|
||||||
function: () => {},
|
|
||||||
},
|
|
||||||
"Save as": {
|
|
||||||
children: [],
|
|
||||||
function: () => {},
|
|
||||||
},
|
|
||||||
Share: {
|
|
||||||
children: [],
|
|
||||||
function: () => {},
|
|
||||||
},
|
|
||||||
Rename: {
|
|
||||||
children: [],
|
|
||||||
function: () => {},
|
|
||||||
},
|
|
||||||
Import: {
|
|
||||||
children: [],
|
|
||||||
function: () => {},
|
|
||||||
},
|
|
||||||
"Export as": {
|
|
||||||
children: [{".png": ()=>console.log("exporting png")}, {".jpg": ()=>{}}, {".xml": ()=>{}},{".svg": ()=>{}}, {".xml": ()=>{}}],
|
|
||||||
function: () => {},
|
|
||||||
},
|
|
||||||
"Export source": {
|
|
||||||
children: [{"MySQL": ()=>{}}, {"PostgreSQL": ()=>{}}, {"DBML": ()=>{}}],
|
|
||||||
function: () => {},
|
|
||||||
},
|
|
||||||
Properties: {
|
|
||||||
children: [],
|
|
||||||
function: () => {},
|
|
||||||
},
|
|
||||||
Close: {
|
|
||||||
children: [],
|
|
||||||
function: () => {},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
Edit: {
|
|
||||||
Undo: {
|
|
||||||
children: [],
|
|
||||||
function: () => {},
|
|
||||||
},
|
|
||||||
Redo: {
|
|
||||||
children: [],
|
|
||||||
function: () => {},
|
|
||||||
},
|
|
||||||
Cut: {
|
|
||||||
children: [],
|
|
||||||
function: () => {},
|
|
||||||
},
|
|
||||||
Copy: {
|
|
||||||
children: [],
|
|
||||||
function: () => {},
|
|
||||||
},
|
|
||||||
"Copy as image": {
|
|
||||||
children: [],
|
|
||||||
function: () => {},
|
|
||||||
},
|
|
||||||
Paste: {
|
|
||||||
children: [],
|
|
||||||
function: () => {},
|
|
||||||
},
|
|
||||||
Delete: {
|
|
||||||
children: [],
|
|
||||||
function: () => {},
|
|
||||||
},
|
|
||||||
"Edit table": {
|
|
||||||
children: [],
|
|
||||||
function: () => {},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
View: {
|
|
||||||
Toolbar: {
|
|
||||||
children: [],
|
|
||||||
function: () => {},
|
|
||||||
},
|
|
||||||
Grid: {
|
|
||||||
children: [],
|
|
||||||
function: () => {},
|
|
||||||
},
|
|
||||||
Sidebar: {
|
|
||||||
children: [],
|
|
||||||
function: () => {},
|
|
||||||
},
|
|
||||||
Editor: {
|
|
||||||
children: [],
|
|
||||||
function: () => {},
|
|
||||||
},
|
|
||||||
"Strict mode": {
|
|
||||||
children: [],
|
|
||||||
function: () => {},
|
|
||||||
},
|
|
||||||
"Reset view": {
|
|
||||||
children: [],
|
|
||||||
function: () => {},
|
|
||||||
},
|
|
||||||
"View schema": {
|
|
||||||
children: [],
|
|
||||||
function: () => {},
|
|
||||||
},
|
|
||||||
Theme: {
|
|
||||||
children: [{Light: ()=>{}}, {Dark: ()=>{}}],
|
|
||||||
function: ()=>{}
|
|
||||||
},
|
|
||||||
"Zoom in": {
|
|
||||||
children: [],
|
|
||||||
function: () => {},
|
|
||||||
},
|
|
||||||
"Zoom out": {
|
|
||||||
children: [],
|
|
||||||
function: () => {},
|
|
||||||
},
|
|
||||||
Fullscreen: {
|
|
||||||
children: [],
|
|
||||||
function: () => {},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
Insert: {
|
|
||||||
"New table": {
|
|
||||||
children: [],
|
|
||||||
function: () => {},
|
|
||||||
},
|
|
||||||
"New relationship": {
|
|
||||||
children: [],
|
|
||||||
function: () => {},
|
|
||||||
},
|
|
||||||
Note: {
|
|
||||||
children: [],
|
|
||||||
function: () => {},
|
|
||||||
},
|
|
||||||
Image: {
|
|
||||||
children: [],
|
|
||||||
function: () => {},
|
|
||||||
},
|
|
||||||
Textbox: {
|
|
||||||
children: [],
|
|
||||||
function: () => {},
|
|
||||||
},
|
|
||||||
Shape: {
|
|
||||||
children: [],
|
|
||||||
function: () => {},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
Logs: {
|
|
||||||
"Open logs": {
|
|
||||||
children: [],
|
|
||||||
function: () => {},
|
|
||||||
},
|
|
||||||
"Commit changes": {
|
|
||||||
children: [],
|
|
||||||
function: () => {},
|
|
||||||
},
|
|
||||||
"Revert changes": {
|
|
||||||
children: [],
|
|
||||||
function: () => {},
|
|
||||||
},
|
|
||||||
"View commits": {
|
|
||||||
children: [],
|
|
||||||
function: () => {},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
Help: {
|
|
||||||
Shortcuts: {
|
|
||||||
children: [],
|
|
||||||
function: () => {},
|
|
||||||
},
|
|
||||||
"Ask us on discord": {
|
|
||||||
children: [],
|
|
||||||
function: () => {},
|
|
||||||
},
|
|
||||||
"Tweet us": {
|
|
||||||
children: [],
|
|
||||||
function: () => {},
|
|
||||||
},
|
|
||||||
"Found a bug": {
|
|
||||||
children: [],
|
|
||||||
function: () => {},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
const sqlDataTypes = [
|
const sqlDataTypes = [
|
||||||
"INT",
|
"INT",
|
||||||
"SMALLINT",
|
"SMALLINT",
|
||||||
@ -249,7 +58,6 @@ const Constraint = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export {
|
export {
|
||||||
menu,
|
|
||||||
bgBlue,
|
bgBlue,
|
||||||
sqlDataTypes,
|
sqlDataTypes,
|
||||||
tableThemes,
|
tableThemes,
|
||||||
|
Loading…
Reference in New Issue
Block a user