Free, simple, and intuitive online database diagram editor and SQL generator.
JavaScript databasedatabase-designdatabase-diagramdatabase-schemadbmldiagram-editoreditorer-diagramerderdiagramindexeddbmariadbmcporacle-databaseoracle-dbpostgresqlschema-designsqlsql-serversqlite
Complete menu bar somewhat
1ilit4ec9f3f55be4
diff --git a/src/components/control_panel.jsx b/src/components/control_panel.jsxindex 0fbc26e3..b44613c7 100644--- a/src/components/control_panel.jsx+++ b/src/components/control_panel.jsx@@ -88,6 +88,210 @@ export default function ControlPanel(props) {const { undoStack, redoStack, setUndoStack, setRedoStack } =useContext(UndoRedoContext);+ const invertLayout = (component) =>+ setLayout((prev) => ({ ...prev, [component]: !prev[component] }));++ const diagramIsEmpty = () => {+ return (+ tables.length === 0 &&+ relationships.length === 0 &&+ notes.length === 0 &&+ areas.length === 0+ );+ };++ const overwriteDiagram = () => {+ setTables(data.tables);+ setRelationships(data.relationships);+ setAreas(data.subjectAreas);+ setNotes(data.notes);+ };++ const addTable = () => {+ setTables((prev) => [+ ...prev,+ {+ id: prev.length,+ name: `table_${prev.length}`,+ x: 0,+ y: 0,+ fields: [+ {+ name: "id",+ type: "UUID",+ default: "",+ check: "",+ primary: true,+ unique: true,+ notNull: true,+ increment: true,+ comment: "",+ },+ ],+ comment: "",+ indices: [],+ color: defaultTableTheme,+ },+ ]);+ };++ const addArea = () => {+ setAreas((prev) => [+ ...prev,+ {+ id: prev.length,+ name: `area_${prev.length}`,+ x: 0,+ y: 0,+ width: 200,+ height: 200,+ color: defaultTableTheme,+ },+ ]);+ };++ const addNote = () => {+ setNotes((prev) => [+ ...prev,+ {+ id: prev.length,+ x: 0,+ y: 0,+ title: `note_${prev.length}`,+ content: "",+ color: defaultNoteTheme,+ height: 88,+ },+ ]);+ };++ const moveTable = (id, x, y) => {+ setTables((prev) =>+ prev.map((t) => {+ if (t.id === id) {+ return {+ ...t,+ x: x,+ y: y,+ };+ }+ return t;+ })+ );+ };++ const moveArea = (id, x, y) => {+ setAreas((prev) =>+ prev.map((t) => {+ if (t.id === id) {+ return {+ ...t,+ x: x,+ y: y,+ };+ }+ return t;+ })+ );+ };++ const moveNote = (id, x, y) => {+ setNotes((prev) =>+ prev.map((t) => {+ if (t.id === id) {+ return {+ ...t,+ x: x,+ y: y,+ };+ }+ return t;+ })+ );+ };++ const undo = () => {+ if (undoStack.length === 0) return;+ const a = undoStack.pop();+ if (a.action === Action.ADD) {+ if (a.element === ObjectType.TABLE) {+ setTables((prev) =>+ prev+ .filter((e) => e.id !== prev.length - 1)+ .map((e, i) => ({ ...e, id: i }))+ );+ } else if (a.element === ObjectType.AREA) {+ setAreas((prev) =>+ prev+ .filter((e) => e.id !== prev.length - 1)+ .map((e, i) => ({ ...e, id: i }))+ );+ } else if (a.element === ObjectType.NOTE) {+ setNotes((prev) =>+ prev+ .filter((e) => e.id !== prev.length - 1)+ .map((e, i) => ({ ...e, id: i }))+ );+ }+ setRedoStack((prev) => [...prev, a]);+ } else if (a.action === Action.MOVE) {+ if (a.element === ObjectType.TABLE) {+ setRedoStack((prev) => [+ ...prev,+ { ...a, x: tables[a.id].x, y: tables[a.id].y },+ ]);+ moveTable(a.id, a.x, a.y);+ } else if (a.element === ObjectType.AREA) {+ setRedoStack((prev) => [+ ...prev,+ { ...a, x: areas[a.id].x, y: areas[a.id].y },+ ]);+ moveArea(a.id, a.x, a.y);+ } else if (a.element === ObjectType.NOTE) {+ setRedoStack((prev) => [+ ...prev,+ { ...a, x: notes[a.id].x, y: notes[a.id].y },+ ]);+ moveNote(a.id, a.x, a.y);+ }+ }+ };++ const redo = () => {+ if (redoStack.length === 0) return;+ const a = redoStack.pop();+ if (a.action === Action.ADD) {+ if (a.element === ObjectType.TABLE) {+ addTable();+ } else if (a.element === ObjectType.AREA) {+ addArea();+ } else if (a.element === ObjectType.NOTE) {+ addNote();+ }+ setUndoStack((prev) => [...prev, a]);+ } else if (a.action === Action.MOVE) {+ if (a.element === ObjectType.TABLE) {+ setUndoStack((prev) => [+ ...prev,+ { ...a, x: tables[a.id].x, y: tables[a.id].y },+ ]);+ moveTable(a.id, a.x, a.y);+ } else if (a.element === ObjectType.AREA) {+ setUndoStack((prev) => [+ ...prev,+ { ...a, x: areas[a.id].x, y: areas[a.id].y },+ ]);+ moveArea(a.id, a.x, a.y);+ } else if (a.element === ObjectType.NOTE) {+ setUndoStack((prev) => [+ ...prev,+ { ...a, x: notes[a.id].x, y: notes[a.id].y },+ ]);+ moveNote(a.id, a.x, a.y);+ }+ }+ };+const menu = {File: {New: {@@ -249,11 +453,11 @@ export default function ControlPanel(props) {Edit: {Undo: {children: [],- function: () => {},+ function: undo,},Redo: {children: [],- function: () => {},+ function: redo,},Clear: {children: [],@@ -264,6 +468,10 @@ export default function ControlPanel(props) {setNotes([]);},},+ Edit: {+ children: [],+ function: () => {},+ },Cut: {children: [],function: () => {},@@ -276,6 +484,14 @@ export default function ControlPanel(props) {children: [],function: () => {},},+ Duplicate: {+ children: [],+ function: () => {},+ },+ Delete: {+ children: [],+ function: () => {},+ },"Copy as image": {children: [],function: () => {@@ -292,32 +508,27 @@ export default function ControlPanel(props) {});},},- Delete: {- children: [],- function: () => {},- },- "Edit table": {- children: [],- function: () => {},- },},View: {- Toolbar: {+ Header: {children: [],- function: () => {},+ function: () =>+ setLayout((prev) => ({ ...prev, header: !prev.header })),},- Grid: {+ Sidebar: {children: [],function: () =>- setSettings((prev) => ({ ...prev, showGrid: !prev.showGrid })),+ setLayout((prev) => ({ ...prev, sidebar: !prev.sidebar })),},- Sidebar: {+ Issues: {children: [],- function: () => {},+ function: () =>+ setLayout((prev) => ({ ...prev, issues: !prev.issues })),},- Editor: {+ Services: {children: [],- function: () => {},+ function: () =>+ setLayout((prev) => ({ ...prev, services: !prev.services })),},"Strict mode": {children: [],@@ -346,6 +557,11 @@ export default function ControlPanel(props) {children: [],function: () => {},},+ Grid: {+ children: [],+ function: () =>+ setSettings((prev) => ({ ...prev, showGrid: !prev.showGrid })),+ },Theme: {children: [{ Light: () => {} }, { Dark: () => {} }],function: () => {},@@ -403,210 +619,6 @@ export default function ControlPanel(props) {},};- const invertLayout = (component) =>- setLayout((prev) => ({ ...prev, [component]: !prev[component] }));-- const diagramIsEmpty = () => {- return (- tables.length === 0 &&- relationships.length === 0 &&- notes.length === 0 &&- areas.length === 0- );- };-- const overwriteDiagram = () => {- setTables(data.tables);- setRelationships(data.relationships);- setAreas(data.subjectAreas);- setNotes(data.notes);- };-- const addTable = () => {- setTables((prev) => [- ...prev,- {- id: prev.length,- name: `table_${prev.length}`,- x: 0,- y: 0,- fields: [- {- name: "id",- type: "UUID",- default: "",- check: "",- primary: true,- unique: true,- notNull: true,- increment: true,- comment: "",- },- ],- comment: "",- indices: [],- color: defaultTableTheme,- },- ]);- };-- const addArea = () => {- setAreas((prev) => [- ...prev,- {- id: prev.length,- name: `area_${prev.length}`,- x: 0,- y: 0,- width: 200,- height: 200,- color: defaultTableTheme,- },- ]);- };-- const addNote = () => {- setNotes((prev) => [- ...prev,- {- id: prev.length,- x: 0,- y: 0,- title: `note_${prev.length}`,- content: "",- color: defaultNoteTheme,- height: 88,- },- ]);- };-- const moveTable = (id, x, y) => {- setTables((prev) =>- prev.map((t) => {- if (t.id === id) {- return {- ...t,- x: x,- y: y,- };- }- return t;- })- );- };-- const moveArea = (id, x, y) => {- setAreas((prev) =>- prev.map((t) => {- if (t.id === id) {- return {- ...t,- x: x,- y: y,- };- }- return t;- })- );- };-- const moveNote = (id, x, y) => {- setNotes((prev) =>- prev.map((t) => {- if (t.id === id) {- return {- ...t,- x: x,- y: y,- };- }- return t;- })- );- };-- const undo = () => {- if (undoStack.length === 0) return;- const a = undoStack.pop();- if (a.action === Action.ADD) {- if (a.element === ObjectType.TABLE) {- setTables((prev) =>- prev- .filter((e) => e.id !== prev.length - 1)- .map((e, i) => ({ ...e, id: i }))- );- } else if (a.element === ObjectType.AREA) {- setAreas((prev) =>- prev- .filter((e) => e.id !== prev.length - 1)- .map((e, i) => ({ ...e, id: i }))- );- } else if (a.element === ObjectType.NOTE) {- setNotes((prev) =>- prev- .filter((e) => e.id !== prev.length - 1)- .map((e, i) => ({ ...e, id: i }))- );- }- setRedoStack((prev) => [...prev, a]);- } else if (a.action === Action.MOVE) {- if (a.element === ObjectType.TABLE) {- setRedoStack((prev) => [- ...prev,- { ...a, x: tables[a.id].x, y: tables[a.id].y },- ]);- moveTable(a.id, a.x, a.y);- } else if (a.element === ObjectType.AREA) {- setRedoStack((prev) => [- ...prev,- { ...a, x: areas[a.id].x, y: areas[a.id].y },- ]);- moveArea(a.id, a.x, a.y);- } else if (a.element === ObjectType.NOTE) {- setRedoStack((prev) => [- ...prev,- { ...a, x: notes[a.id].x, y: notes[a.id].y },- ]);- moveNote(a.id, a.x, a.y);- }- }- };-- const redo = () => {- if (redoStack.length === 0) return;- const a = redoStack.pop();- if (a.action === Action.ADD) {- if (a.element === ObjectType.TABLE) {- addTable();- } else if (a.element === ObjectType.AREA) {- addArea();- } else if (a.element === ObjectType.NOTE) {- addNote();- }- setUndoStack((prev) => [...prev, a]);- } else if (a.action === Action.MOVE) {- if (a.element === ObjectType.TABLE) {- setUndoStack((prev) => [- ...prev,- { ...a, x: tables[a.id].x, y: tables[a.id].y },- ]);- moveTable(a.id, a.x, a.y);- }else if (a.element === ObjectType.AREA) {- setUndoStack((prev) => [- ...prev,- { ...a, x: areas[a.id].x, y: areas[a.id].y },- ]);- moveArea(a.id, a.x, a.y);- } else if (a.element === ObjectType.NOTE) {- setUndoStack((prev) => [- ...prev,- { ...a, x: notes[a.id].x, y: notes[a.id].y },- ]);- moveNote(a.id, a.x, a.y);- }- }- };-return (<div>{layout.header && header()}