From 7cea7c9f5fed9c0d22aca57023ab7543756ca447 Mon Sep 17 00:00:00 2001 From: 1ilit Date: Mon, 12 Feb 2024 21:05:21 +0200 Subject: [PATCH] Fix dependencies --- package-lock.json | 194 +++++++++----------------- package.json | 9 +- src/components/ControlPanel.jsx | 240 +++++++++++++++++++------------- src/main.jsx | 8 +- 4 files changed, 217 insertions(+), 234 deletions(-) diff --git a/package-lock.json b/package-lock.json index d4fcc19..92fd19e 100644 --- a/package-lock.json +++ b/package-lock.json @@ -24,13 +24,9 @@ "react": "^18.2.0", "react-cookie": "^7.0.1", "react-dom": "^18.2.0", - "react-google-recaptcha": "^3.1.0", "react-hotkeys-hook": "^4.4.1", "react-icons": "^4.12.0", - "react-router": "^6.21.0", "react-router-dom": "^6.21.0", - "socket.io-client": "^4.7.2", - "unique-names-generator": "^4.7.1", "url": "^0.11.1" }, "devDependencies": { @@ -44,7 +40,7 @@ "eslint-plugin-react-refresh": "^0.4.5", "postcss": "^8.4.32", "tailwindcss": "^3.3.6", - "vite": "^5.0.8" + "vite": "^5.0.11" } }, "node_modules/@aashutoshrathi/word-wrap": { @@ -1557,11 +1553,6 @@ "win32" ] }, - "node_modules/@socket.io/component-emitter": { - "version": "3.1.0", - "resolved": "https://registry.npmjs.org/@socket.io/component-emitter/-/component-emitter-3.1.0.tgz", - "integrity": "sha512-+9jVqKhRSpsc591z5vX+X5Yyw+he/HCB4iQ/RYxw35CEPaY1gnsNE43nf9n9AaYjAQrTiI/mOwKUKdUs9vf7Xg==" - }, "node_modules/@types/babel__core": { "version": "7.20.5", "resolved": "https://registry.npmjs.org/@types/babel__core/-/babel__core-7.20.5.tgz", @@ -2347,6 +2338,7 @@ "version": "4.3.4", "resolved": "https://registry.npmjs.org/debug/-/debug-4.3.4.tgz", "integrity": "sha512-PRWFHuSU3eDtQJPvnNY7Jcket1j0t5OuOsFzPPzsekD52Zl8qUfFIPEiswXqIvHWGVHOgX+7G/vCNNhehwxfkQ==", + "dev": true, "dependencies": { "ms": "2.1.2" }, @@ -2457,26 +2449,6 @@ "integrity": "sha512-X4ze/9Sc3QWs6h92yerwqv7aB/uU8vCjZcrMjA8N9R1pjMFRe44dLsck5FzLilOYvcXuDn93B+bpGYyufc70gQ==", "dev": true }, - "node_modules/engine.io-client": { - "version": "6.5.3", - "resolved": "https://registry.npmjs.org/engine.io-client/-/engine.io-client-6.5.3.tgz", - "integrity": "sha512-9Z0qLB0NIisTRt1DZ/8U2k12RJn8yls/nXMZLn+/N8hANT3TcYjKFKcwbw5zFQiN4NTde3TSY9zb79e1ij6j9Q==", - "dependencies": { - "@socket.io/component-emitter": "~3.1.0", - "debug": "~4.3.1", - "engine.io-parser": "~5.2.1", - "ws": "~8.11.0", - "xmlhttprequest-ssl": "~2.0.0" - } - }, - "node_modules/engine.io-parser": { - "version": "5.2.1", - "resolved": "https://registry.npmjs.org/engine.io-parser/-/engine.io-parser-5.2.1.tgz", - "integrity": "sha512-9JktcM3u18nU9N2Lz3bWeBgxVgOKpw7yhRaoxQA3FUDZzzw+9WlA6p4G4u0RixNkg14fH7EfEc/RhpurtiROTQ==", - "engines": { - "node": ">=10.0.0" - } - }, "node_modules/es-abstract": { "version": "1.22.3", "resolved": "https://registry.npmjs.org/es-abstract/-/es-abstract-1.22.3.tgz", @@ -3075,9 +3047,9 @@ "dev": true }, "node_modules/follow-redirects": { - "version": "1.15.3", - "resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.15.3.tgz", - "integrity": "sha512-1VzOtuEM8pC9SFU1E+8KfTjZyMztRsgEfwQl44z8A25uy13jSzTj6dyK2Df52iV0vgHCfBwLhDWevLn95w5v6Q==", + "version": "1.15.5", + "resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.15.5.tgz", + "integrity": "sha512-vSFWUON1B+yAw1VN4xMfxgn5fTUiaOzAJCKBwIIgT/+7CuGy9+r+5gITvP62j3RmaD5Ph65UaERdOSRGUzZtgw==", "funding": [ { "type": "individual", @@ -3819,6 +3791,16 @@ "integrity": "sha512-RHxMLp9lnKHGHRng9QFhRCMbYAcVpn69smSGcq3f36xjgVVWThj4qqLbTLlq7Ssj8B+fIQ1EuCEGI2lKsyQeIw==", "dev": true }, + "node_modules/isomorphic.js": { + "version": "0.2.5", + "resolved": "https://registry.npmjs.org/isomorphic.js/-/isomorphic.js-0.2.5.tgz", + "integrity": "sha512-PIeMbHqMt4DnUP3MA/Flc0HElYjMXArsw1qwJZcm9sqR8mq3l8NYizFMty0pWwE/tzIGH3EKK5+jes5mAr85yw==", + "peer": true, + "funding": { + "type": "GitHub Sponsors ❤", + "url": "https://github.com/sponsors/dmonad" + } + }, "node_modules/iterator.prototype": { "version": "1.1.2", "resolved": "https://registry.npmjs.org/iterator.prototype/-/iterator.prototype-1.1.2.tgz", @@ -3967,6 +3949,26 @@ "resolved": "https://registry.npmjs.org/lexical/-/lexical-0.12.5.tgz", "integrity": "sha512-ZMqisIxNe+JBqaUa1Qmz7ghpvnmARHxgYz+F0rcXRtSPZtgEL8OT2c9xk8CJ4ccVpf+qRQlONzCEIZfQQHd/RA==" }, + "node_modules/lib0": { + "version": "0.2.88", + "resolved": "https://registry.npmjs.org/lib0/-/lib0-0.2.88.tgz", + "integrity": "sha512-KyroiEvCeZcZEMx5Ys+b4u4eEBbA1ch7XUaBhYpwa/nPMrzTjUhI4RfcytmQfYoTBPcdyx+FX6WFNIoNuJzJfQ==", + "peer": true, + "dependencies": { + "isomorphic.js": "^0.2.4" + }, + "bin": { + "0gentesthtml": "bin/gentesthtml.js", + "0serve": "bin/0serve.js" + }, + "engines": { + "node": ">=16" + }, + "funding": { + "type": "GitHub Sponsors ❤", + "url": "https://github.com/sponsors/dmonad" + } + }, "node_modules/lilconfig": { "version": "2.1.0", "resolved": "https://registry.npmjs.org/lilconfig/-/lilconfig-2.1.0.tgz", @@ -4085,10 +4087,17 @@ "node": "*" } }, + "node_modules/monaco-editor": { + "version": "0.46.0", + "resolved": "https://registry.npmjs.org/monaco-editor/-/monaco-editor-0.46.0.tgz", + "integrity": "sha512-ADwtLIIww+9FKybWscd7OCfm9odsFYHImBRI1v9AviGce55QY8raT+9ihH8jX/E/e6QVSGM+pKj4jSUSRmALNQ==", + "peer": true + }, "node_modules/ms": { "version": "2.1.2", "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz", - "integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==" + "integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==", + "dev": true }, "node_modules/mz": { "version": "2.7.0", @@ -4415,9 +4424,9 @@ } }, "node_modules/postcss": { - "version": "8.4.32", - "resolved": "https://registry.npmjs.org/postcss/-/postcss-8.4.32.tgz", - "integrity": "sha512-D/kj5JNu6oo2EIy+XL/26JEDTlIbB8hw85G8StOE6L74RQAVVP5rej6wxCNqyMbR4RkPfqvezVbPw81Ngd6Kcw==", + "version": "8.4.35", + "resolved": "https://registry.npmjs.org/postcss/-/postcss-8.4.35.tgz", + "integrity": "sha512-u5U8qYpBCpN13BsiEB0CbR1Hhh4Gc0zLFuedrHJKMctHCHAGrMdG0PRM/KErzAL3CU6/eckEtmHNB3x6e3c0vA==", "dev": true, "funding": [ { @@ -4672,18 +4681,6 @@ "node": ">=0.10.0" } }, - "node_modules/react-async-script": { - "version": "1.2.0", - "resolved": "https://registry.npmjs.org/react-async-script/-/react-async-script-1.2.0.tgz", - "integrity": "sha512-bCpkbm9JiAuMGhkqoAiC0lLkb40DJ0HOEJIku+9JDjxX3Rcs+ztEOG13wbrOskt3n2DTrjshhaQ/iay+SnGg5Q==", - "dependencies": { - "hoist-non-react-statics": "^3.3.0", - "prop-types": "^15.5.0" - }, - "peerDependencies": { - "react": ">=16.4.1" - } - }, "node_modules/react-cookie": { "version": "7.0.1", "resolved": "https://registry.npmjs.org/react-cookie/-/react-cookie-7.0.1.tgz", @@ -4737,18 +4734,6 @@ "react": ">=16.13.1" } }, - "node_modules/react-google-recaptcha": { - "version": "3.1.0", - "resolved": "https://registry.npmjs.org/react-google-recaptcha/-/react-google-recaptcha-3.1.0.tgz", - "integrity": "sha512-cYW2/DWas8nEKZGD7SCu9BSuVz8iOcOLHChHyi7upUuVhkpkhYG/6N3KDiTQ3XAiZ2UAZkfvYKMfAHOzBOcGEg==", - "dependencies": { - "prop-types": "^15.5.0", - "react-async-script": "^1.2.0" - }, - "peerDependencies": { - "react": ">=16.4.1" - } - }, "node_modules/react-hotkeys-hook": { "version": "4.4.1", "resolved": "https://registry.npmjs.org/react-hotkeys-hook/-/react-hotkeys-hook-4.4.1.tgz", @@ -5137,32 +5122,6 @@ "url": "https://github.com/sponsors/ljharb" } }, - "node_modules/socket.io-client": { - "version": "4.7.2", - "resolved": "https://registry.npmjs.org/socket.io-client/-/socket.io-client-4.7.2.tgz", - "integrity": "sha512-vtA0uD4ibrYD793SOIAwlo8cj6haOeMHrGvwPxJsxH7CeIksqJ+3Zc06RvWTIFgiSqx4A3sOnTXpfAEE2Zyz6w==", - "dependencies": { - "@socket.io/component-emitter": "~3.1.0", - "debug": "~4.3.2", - "engine.io-client": "~6.5.2", - "socket.io-parser": "~4.2.4" - }, - "engines": { - "node": ">=10.0.0" - } - }, - "node_modules/socket.io-parser": { - "version": "4.2.4", - "resolved": "https://registry.npmjs.org/socket.io-parser/-/socket.io-parser-4.2.4.tgz", - "integrity": "sha512-/GbIKmo8ioc+NIWIhwdecY0ge+qVBSMdgxGygevmdHj24bsfgtCmcUUcQ5ZzcylGFHsN3k4HB4Cgkl96KVnuew==", - "dependencies": { - "@socket.io/component-emitter": "~3.1.0", - "debug": "~4.3.1" - }, - "engines": { - "node": ">=10.0.0" - } - }, "node_modules/source-map-js": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/source-map-js/-/source-map-js-1.0.2.tgz", @@ -5576,14 +5535,6 @@ "url": "https://github.com/sponsors/ljharb" } }, - "node_modules/unique-names-generator": { - "version": "4.7.1", - "resolved": "https://registry.npmjs.org/unique-names-generator/-/unique-names-generator-4.7.1.tgz", - "integrity": "sha512-lMx9dX+KRmG8sq6gulYYpKWZc9RlGsgBR6aoO8Qsm3qvkSJ+3rAymr+TnV8EDMrIrwuFJ4kruzMWM/OpYzPoow==", - "engines": { - "node": ">=8" - } - }, "node_modules/universal-cookie": { "version": "7.0.1", "resolved": "https://registry.npmjs.org/universal-cookie/-/universal-cookie-7.0.1.tgz", @@ -5670,13 +5621,13 @@ } }, "node_modules/vite": { - "version": "5.0.10", - "resolved": "https://registry.npmjs.org/vite/-/vite-5.0.10.tgz", - "integrity": "sha512-2P8J7WWgmc355HUMlFrwofacvr98DAjoE52BfdbwQtyLH06XKwaL/FMnmKM2crF0iX4MpmMKoDlNCB1ok7zHCw==", + "version": "5.1.1", + "resolved": "https://registry.npmjs.org/vite/-/vite-5.1.1.tgz", + "integrity": "sha512-wclpAgY3F1tR7t9LL5CcHC41YPkQIpKUGeIuT8MdNwNZr6OqOTLs7JX5vIHAtzqLWXts0T+GDrh9pN2arneKqg==", "dev": true, "dependencies": { "esbuild": "^0.19.3", - "postcss": "^8.4.32", + "postcss": "^8.4.35", "rollup": "^4.2.0" }, "bin": { @@ -5820,34 +5771,6 @@ "resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz", "integrity": "sha512-l4Sp/DRseor9wL6EvV2+TuQn63dMkPjZ/sp9XkghTEbV9KlPS1xUsZ3u7/IQO4wxtcFB4bgpQPRcR3QCvezPcQ==" }, - "node_modules/ws": { - "version": "8.11.0", - "resolved": "https://registry.npmjs.org/ws/-/ws-8.11.0.tgz", - "integrity": "sha512-HPG3wQd9sNQoT9xHyNCXoDUa+Xw/VevmY9FoHyQ+g+rrMn4j6FB4np7Z0OhdTgjx6MgQLK7jwSy1YecU1+4Asg==", - "engines": { - "node": ">=10.0.0" - }, - "peerDependencies": { - "bufferutil": "^4.0.1", - "utf-8-validate": "^5.0.2" - }, - "peerDependenciesMeta": { - "bufferutil": { - "optional": true - }, - "utf-8-validate": { - "optional": true - } - } - }, - "node_modules/xmlhttprequest-ssl": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/xmlhttprequest-ssl/-/xmlhttprequest-ssl-2.0.0.tgz", - "integrity": "sha512-QKxVRxiRACQcVuQEYFsI1hhkrMlrXHPegbbd1yn9UHOmRxY+si12nQYzri3vbzt8VdTTRviqcKxcyllFas5z2A==", - "engines": { - "node": ">=0.4.0" - } - }, "node_modules/yallist": { "version": "3.1.1", "resolved": "https://registry.npmjs.org/yallist/-/yallist-3.1.1.tgz", @@ -5863,6 +5786,23 @@ "node": ">= 14" } }, + "node_modules/yjs": { + "version": "13.6.12", + "resolved": "https://registry.npmjs.org/yjs/-/yjs-13.6.12.tgz", + "integrity": "sha512-KOT8ILoyVH2f/PxPadeu5kVVS055D1r3x1iFfJVJzFdnN98pVGM8H07NcKsO+fG3F7/0tf30Vnokf5YIqhU/iw==", + "peer": true, + "dependencies": { + "lib0": "^0.2.86" + }, + "engines": { + "node": ">=16.0.0", + "npm": ">=8.0.0" + }, + "funding": { + "type": "GitHub Sponsors ❤", + "url": "https://github.com/sponsors/dmonad" + } + }, "node_modules/yocto-queue": { "version": "0.1.0", "resolved": "https://registry.npmjs.org/yocto-queue/-/yocto-queue-0.1.0.tgz", diff --git a/package.json b/package.json index 3b46123..52c3796 100644 --- a/package.json +++ b/package.json @@ -26,13 +26,9 @@ "react": "^18.2.0", "react-cookie": "^7.0.1", "react-dom": "^18.2.0", - "react-google-recaptcha": "^3.1.0", "react-hotkeys-hook": "^4.4.1", "react-icons": "^4.12.0", - "react-router": "^6.21.0", "react-router-dom": "^6.21.0", - "socket.io-client": "^4.7.2", - "unique-names-generator": "^4.7.1", "url": "^0.11.1" }, "devDependencies": { @@ -46,6 +42,9 @@ "eslint-plugin-react-refresh": "^0.4.5", "postcss": "^8.4.32", "tailwindcss": "^3.3.6", - "vite": "^5.0.8" + "vite": "^5.0.11" + }, + "overrides": { + "follow-redirects": "^1.15.4" } } diff --git a/src/components/ControlPanel.jsx b/src/components/ControlPanel.jsx index c10abf7..62c4f6a 100644 --- a/src/components/ControlPanel.jsx +++ b/src/components/ControlPanel.jsx @@ -47,7 +47,7 @@ import { jsonToPostgreSQL, jsonToSQLite, jsonToMariaDB, - jsonToSQLServer + jsonToSQLServer, } from "../utils"; import { AreaContext, @@ -66,7 +66,7 @@ import jsPDF from "jspdf"; import { useHotkeys } from "react-hotkeys-hook"; import { Validator } from "jsonschema"; import { areaSchema, noteSchema, tableSchema } from "../data/schemas"; -import { Editor } from "@monaco-editor/react"; +import Editor from "@monaco-editor/react"; import { db } from "../data/db"; import { useLiveQuery } from "dexie-react-hooks"; import { Parser } from "node-sql-parser"; @@ -168,7 +168,7 @@ export default function ControlPanel({ const undo = () => { if (undoStack.length === 0) return; const a = undoStack[undoStack.length - 1]; - setUndoStack(prev => prev.filter((e, i) => i !== prev.length - 1)); + setUndoStack((prev) => prev.filter((e, i) => i !== prev.length - 1)); if (a.action === Action.ADD) { if (a.element === ObjectType.TABLE) { deleteTable(tables[tables.length - 1].id, false); @@ -272,9 +272,9 @@ export default function ControlPanel({ indices: tables[a.tid].indices.map((index) => index.id === a.iid ? { - ...index, - ...a.undo, - } + ...index, + ...a.undo, + } : index ), }); @@ -341,7 +341,7 @@ export default function ControlPanel({ const redo = () => { if (redoStack.length === 0) return; const a = redoStack[redoStack.length - 1]; - setRedoStack(prev => prev.filter((e, i) => i !== prev.length - 1)); + setRedoStack((prev) => prev.filter((e, i) => i !== prev.length - 1)); if (a.action === Action.ADD) { if (a.element === ObjectType.TABLE) { addTable(false); @@ -465,9 +465,9 @@ export default function ControlPanel({ indices: tables[a.tid].indices.map((index) => index.id === a.iid ? { - ...index, - ...a.redo, - } + ...index, + ...a.redo, + } : index ), }); @@ -837,8 +837,8 @@ export default function ControlPanel({ "Import from source": { function: () => { setData({ src: "", overwrite: true, dbms: "MySQL" }); - setVisible(MODAL.IMPORT_SRC) - } + setVisible(MODAL.IMPORT_SRC); + }, }, "Export as": { children: [ @@ -947,7 +947,7 @@ export default function ControlPanel({ }, }, ], - function: () => { }, + function: () => {}, }, "Export source": { children: [ @@ -1024,13 +1024,13 @@ export default function ControlPanel({ data: src, extension: "sql", })); - } + }, }, ], - function: () => { }, + function: () => {}, }, Exit: { - function: () => { }, + function: () => {}, }, }, Edit: { @@ -1100,14 +1100,14 @@ export default function ControlPanel({ }, "Presentation mode": { function: () => { - setLayout(prev => ({ + setLayout((prev) => ({ ...prev, header: false, sidebar: false, toolbar: false, })); enterFullscreen(); - } + }, }, "Field summary": { function: viewFieldSummary, @@ -1151,7 +1151,7 @@ export default function ControlPanel({ }, }, ], - function: () => { }, + function: () => {}, }, "Zoom in": { function: zoomIn, @@ -1169,9 +1169,7 @@ export default function ControlPanel({ Autosave: { function: () => setSettings((prev) => { - Toast.success( - `Autosave is ${settings.autosave ? "off" : "on"}` - ); + Toast.success(`Autosave is ${settings.autosave ? "off" : "on"}`); return { ...prev, autosave: !prev.autosave }; }), }, @@ -1201,7 +1199,7 @@ export default function ControlPanel({ shortcut: "Ctrl+H", }, "Ask us on discord": { - function: () => { }, + function: () => {}, }, "Report a bug": { function: () => window.open("/bug_report", "_blank"), @@ -1289,10 +1287,12 @@ export default function ControlPanel({ const parser = new Parser(); let ast = null; try { - console.log(data.dbms) + console.log(data.dbms); ast = parser.astify(data.src, { database: data.dbms }); } catch (err) { - Toast.error("Could not parse the sql file. Make sure there are no syntax errors."); + Toast.error( + "Could not parse the sql file. Make sure there are no syntax errors." + ); console.log(err); return; } @@ -1301,7 +1301,7 @@ export default function ControlPanel({ const relationships = []; const inlineForeignKeys = []; - ast.forEach(((e) => { + ast.forEach((e) => { if (e.type === "create") { if (e.keyword === "table") { const table = {}; @@ -1334,14 +1334,31 @@ export default function ControlPanel({ let check = ""; if (d.check.definition[0].left.column) { let value = d.check.definition[0].right.value; - if (d.check.definition[0].right.type === "double_quote_string" || d.check.definition[0].right.type === "single_quote_string") - value = '\'' + value + '\'' - check = d.check.definition[0].left.column + " " + d.check.definition[0].operator + " " + value; + if ( + d.check.definition[0].right.type === + "double_quote_string" || + d.check.definition[0].right.type === "single_quote_string" + ) + value = "'" + value + "'"; + check = + d.check.definition[0].left.column + + " " + + d.check.definition[0].operator + + " " + + value; } else { let value = d.check.definition[0].right.value; - if (d.check.definition[0].left.type === "double_quote_string" || d.check.definition[0].left.type === "single_quote_string") - value = '\'' + value + '\'' - check = value + " " + d.check.definition[0].operator + " " + d.check.definition[0].right.column; + if ( + d.check.definition[0].left.type === "double_quote_string" || + d.check.definition[0].left.type === "single_quote_string" + ) + value = "'" + value + "'"; + check = + value + + " " + + d.check.definition[0].operator + + " " + + d.check.definition[0].right.column; } field.check = check; } @@ -1349,15 +1366,15 @@ export default function ControlPanel({ table.fields.push(field); } else if (d.resource === "constraint") { if (d.constraint_type === "primary key") { - d.definition.forEach(c => { + d.definition.forEach((c) => { table.fields.forEach((f) => { if (f.name === c.column && !f.primary) { f.primary = true; } - }) + }); }); } else if (d.constraint_type === "FOREIGN KEY") { - inlineForeignKeys.push({ ...d, startTable: e.table[0].table }) + inlineForeignKeys.push({ ...d, startTable: e.table[0].table }); } } }); @@ -1366,16 +1383,15 @@ export default function ControlPanel({ e.id = i; e.fields.forEach((f, j) => { f.id = j; - }) - }) - } - else if (e.keyword === "index") { + }); + }); + } else if (e.keyword === "index") { const index = {}; index.name = e.index; index.unique = false; if (e.index_type === "unique") index.unique = true; index.fields = []; - e.index_columns.forEach(f => index.fields.push(f.column)); + e.index_columns.forEach((f) => index.fields.push(f.column)); let found = -1; tables.forEach((t, i) => { @@ -1386,34 +1402,45 @@ export default function ControlPanel({ } }); - if (found !== -1) - tables[found].indices.forEach((i, j) => i.id = j); + if (found !== -1) tables[found].indices.forEach((i, j) => (i.id = j)); } } else if (e.type === "alter") { - if (e.expr[0].action === "add" && e.expr[0].create_definitions.constraint_type === "FOREIGN KEY") { + if ( + e.expr[0].action === "add" && + e.expr[0].create_definitions.constraint_type === "FOREIGN KEY" + ) { const relationship = {}; const startTable = e.table[0].table; const startField = e.expr[0].create_definitions.definition[0].column; - const endTable = e.expr[0].create_definitions.reference_definition.table[0].table; - const endField = e.expr[0].create_definitions.reference_definition.definition[0].column; + const endTable = + e.expr[0].create_definitions.reference_definition.table[0].table; + const endField = + e.expr[0].create_definitions.reference_definition.definition[0] + .column; let updateConstraint = "No action"; let deleteConstraint = "No action"; - e.expr[0].create_definitions.reference_definition.on_action.forEach(c => { - if (c.type === "on update") { - updateConstraint = c.value.value; - updateConstraint = updateConstraint[0].toUpperCase() + updateConstraint.substring(1); - } else if (c.type === "on delete") { - deleteConstraint = c.value.value; - deleteConstraint = deleteConstraint[0].toUpperCase() + deleteConstraint.substring(1); + e.expr[0].create_definitions.reference_definition.on_action.forEach( + (c) => { + if (c.type === "on update") { + updateConstraint = c.value.value; + updateConstraint = + updateConstraint[0].toUpperCase() + + updateConstraint.substring(1); + } else if (c.type === "on delete") { + deleteConstraint = c.value.value; + deleteConstraint = + deleteConstraint[0].toUpperCase() + + deleteConstraint.substring(1); + } } - }); + ); let startTableId = -1; let startFieldId = -1; let endTableId = -1; let endFieldId = -1; - tables.forEach(t => { + tables.forEach((t) => { if (t.name === startTable) { startTableId = t.id; return; @@ -1422,11 +1449,11 @@ export default function ControlPanel({ if (t.name === endTable) { endTableId = t.id; } - }) + }); if (startTableId === -1 || endTableId === -1) return; - tables[startTableId].fields.forEach(f => { + tables[startTableId].fields.forEach((f) => { if (f.name === startField) { startFieldId = f.id; return; @@ -1435,7 +1462,7 @@ export default function ControlPanel({ if (f.name === endField) { endFieldId = f.id; } - }) + }); if (startFieldId === -1 || endFieldId === -1) return; @@ -1460,10 +1487,10 @@ export default function ControlPanel({ relationship.endY = endY; relationships.push(relationship); - relationships.forEach((r, i) => r.id = i); + relationships.forEach((r, i) => (r.id = i)); } } - })); + }); inlineForeignKeys.forEach((fk) => { const relationship = {}; @@ -1473,13 +1500,15 @@ export default function ControlPanel({ const endField = fk.reference_definition.definition[0].column; let updateConstraint = "No action"; let deleteConstraint = "No action"; - fk.reference_definition.on_action.forEach(c => { + fk.reference_definition.on_action.forEach((c) => { if (c.type === "on update") { updateConstraint = c.value.value; - updateConstraint = updateConstraint[0].toUpperCase() + updateConstraint.substring(1); + updateConstraint = + updateConstraint[0].toUpperCase() + updateConstraint.substring(1); } else if (c.type === "on delete") { deleteConstraint = c.value.value; - deleteConstraint = deleteConstraint[0].toUpperCase() + deleteConstraint.substring(1); + deleteConstraint = + deleteConstraint[0].toUpperCase() + deleteConstraint.substring(1); } }); @@ -1488,7 +1517,7 @@ export default function ControlPanel({ let endTableId = -1; let endFieldId = -1; - tables.forEach(t => { + tables.forEach((t) => { if (t.name === startTable) { startTableId = t.id; return; @@ -1497,11 +1526,11 @@ export default function ControlPanel({ if (t.name === endTable) { endTableId = t.id; } - }) + }); if (startTableId === -1 || endTableId === -1) return; - tables[startTableId].fields.forEach(f => { + tables[startTableId].fields.forEach((f) => { if (f.name === startField) { startFieldId = f.id; return; @@ -1510,7 +1539,7 @@ export default function ControlPanel({ if (f.name === endField) { endFieldId = f.id; } - }) + }); if (startFieldId === -1 || endFieldId === -1) return; @@ -1534,7 +1563,7 @@ export default function ControlPanel({ relationships.push(relationship); }); - relationships.forEach((r, i) => r.id = i); + relationships.forEach((r, i) => (r.id = i)); if (data.overwrite) { setTables(tables); @@ -1545,13 +1574,13 @@ export default function ControlPanel({ setUndoStack([]); setRedoStack([]); } else { - setTables(prev => [...prev, ...tables]); - setRelationships(prev => [...prev, ...relationships]) + setTables((prev) => [...prev, ...tables]); + setRelationships((prev) => [...prev, ...relationships]); } console.log(tables); console.log(relationships); - } + }; const getModalOnOk = async () => { switch (visible) { @@ -1580,7 +1609,7 @@ export default function ControlPanel({ return; case MODAL.IMPORT_SRC: parseSQLAndLoadDiagram(); - setVisible(MODAL.NONE) + setVisible(MODAL.NONE); return; case MODAL.OPEN: if (selectedDiagramId === 0) return; @@ -1732,7 +1761,7 @@ export default function ControlPanel({ } const reader = new FileReader(); reader.onload = async (e) => { - setData(prev => ({ ...prev, src: e.target.result })) + setData((prev) => ({ ...prev, src: e.target.result })); }; reader.readAsText(f); @@ -1752,9 +1781,8 @@ export default function ControlPanel({ type: STATUS.NONE, message: "", }); - setData(prev => ({ ...prev, src: "" })); - } - } + setData((prev) => ({ ...prev, src: "" })); + }} onFileChange={() => setError({ type: STATUS.NONE, @@ -1765,18 +1793,24 @@ export default function ControlPanel({ >
Select DBMS
- - setData((prev) => ({ ...prev, dbms: e }))} + className="w-full" + > + setData(prev => ({ ...prev, overwrite: e.target.checked }))} - className="my-2"> + onChange={(e) => + setData((prev) => ({ ...prev, overwrite: e.target.checked })) + } + className="my-2" + > Overwrite existing diagram
@@ -1788,10 +1822,11 @@ export default function ControlPanel({
setSelectedTemplateId(0)} > @@ -1801,10 +1836,11 @@ export default function ControlPanel({ {[1, 2, 3, 4, 5, 6, 7, 8].map((i) => (
setSelectedTemplateId(i)} > + @@ -1865,10 +1901,11 @@ export default function ControlPanel({ return ( { setSelectedDiagramId(d.id); }} @@ -1973,7 +2010,8 @@ export default function ControlPanel({ closeOnEsc={true} okText={getOkText()} okButtonProps={{ - disabled: (error && error.type && error.type === STATUS.ERROR) || + disabled: + (error && error.type && error.type === STATUS.ERROR) || (visible === MODAL.IMPORT && (error.type === STATUS.ERROR || !data)) || ((visible === MODAL.IMG || visible === MODAL.CODE) && @@ -2199,12 +2237,18 @@ export default function ControlPanel({ - - diff --git a/src/main.jsx b/src/main.jsx index 96fc8f6..dfeade9 100644 --- a/src/main.jsx +++ b/src/main.jsx @@ -1,14 +1,14 @@ // import React from 'react'; -import ReactDOM from 'react-dom/client' -import App from './App.jsx' -import './index.css' +import ReactDOM from 'react-dom/client'; +import App from './App.jsx'; +import './index.css'; import { LocaleProvider } from "@douyinfe/semi-ui"; import en_US from "@douyinfe/semi-ui/lib/es/locale/source/en_US"; const root = ReactDOM.createRoot(document.getElementById("root")); root.render( // - + //