import { React, useState } from "react"; import { IconCaretdown, IconChevronRight, IconShareStroked, IconChevronUp, IconChevronDown, IconCheckboxTick, } from "@douyinfe/semi-icons"; import { Link } from "react-router-dom"; import icon from "../assets/icon_dark_64.png"; import { Avatar, AvatarGroup, Button, Divider, Dropdown, Form, Image, Modal, } from "@douyinfe/semi-ui"; import { toPng, toJpeg, toSvg } from "html-to-image"; import { saveAs } from "file-saver"; export default function ControlPanel() { const [showToolBar, setShowToolBar] = useState(true); const [visible, setVisible] = useState(false); const [dataUrl, setDataUrl] = useState(""); const [filename, setFilename] = useState( `diagram_${new Date().toISOString()}` ); const [extension, setExtension] = useState(""); 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); setExtension("png"); }, }, { JPEG: () => { toJpeg(document.getElementById("canvas"), { quality: 0.95 }).then( function (dataUrl) { setDataUrl(dataUrl); } ); setVisible(true); setExtension("jpeg"); }, }, { XML: () => {} }, { SVG: () => { const filter = (node) => node.tagName !== "i"; toSvg(document.getElementById("canvas"), { filter: filter }).then( function (dataUrl) { setDataUrl(dataUrl); } ); setVisible(true); setExtension("svg"); }, }, { PDF: () => {} }, ], 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 ( <> {showToolBar && ( )}
) : (
) } onClick={() => setShowToolBar((prev) => !prev)} > Header
}> Overview }> Services }> Fullscreen } trigger="click" >
Fit window {[ "25%", "50%", "75%", "100%", "125%", "150%", "200%", "300%", ].map((e, i) => ( {e} ))}
%
} /> } trigger="click" >
zoom
Table Note Subject area Text } trigger="click" >
saveAs(dataUrl, `${filename}.${extension}`)} afterClose={() => { setFilename(`diagram_${new Date().toISOString()}`); setDataUrl(""); }} onCancel={() => setVisible(false)} centered closeOnEsc={true} okText="Export" cancelText="Cancel" width={470} > Diagram
{ setFilename((prev) => value.values["filename"] !== undefined ? value.values["filename"] : prev ); }} > {`.${extension}`}} initValue={filename} />
); }