Skip to content

Commit 6513b2d

Browse files
Merge branch 'main' into build-and-toggle
2 parents 0aa4424 + e2d4940 commit 6513b2d

File tree

18 files changed

+323
-216
lines changed

18 files changed

+323
-216
lines changed

package-lock.json

Lines changed: 9 additions & 75 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,7 @@
2121
"@lexical/utils": "^0.12.6",
2222
"@monaco-editor/react": "^4.7.0",
2323
"@vercel/analytics": "^1.2.2",
24-
"@vercel/speed-insights": "^1.2.0",
2524
"axios": "^1.12.0",
26-
"classnames": "^2.5.1",
2725
"dexie": "^3.2.4",
2826
"dexie-react-hooks": "^1.1.7",
2927
"file-saver": "^2.0.5",
@@ -46,7 +44,6 @@
4644
"react-i18next": "^14.1.1",
4745
"react-router-dom": "^6.21.0",
4846
"react-tweet": "^3.2.1",
49-
"url": "^0.11.1",
5047
"usehooks-ts": "^3.1.0"
5148
},
5249
"devDependencies": {
@@ -63,8 +60,5 @@
6360
"prettier": "3.2.5",
6461
"tailwindcss": "^4.0.14",
6562
"vite": "^6.4.1"
66-
},
67-
"overrides": {
68-
"follow-redirects": "^1.15.4"
6963
}
7064
}

src/components/EditorHeader/ControlPanel.jsx

Lines changed: 34 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -165,9 +165,9 @@ export default function ControlPanel({
165165
} else if (a.element === ObjectType.RELATIONSHIP) {
166166
deleteRelationship(a.data.relationship.id, false);
167167
} else if (a.element === ObjectType.TYPE) {
168-
deleteType(types.length - 1, false);
168+
deleteType(a.data.type.id, false);
169169
} else if (a.element === ObjectType.ENUM) {
170-
deleteEnum(enums.length - 1, false);
170+
deleteEnum(a.data.enum.id, false);
171171
}
172172
setRedoStack((prev) => [...prev, a]);
173173
} else if (a.action === Action.MOVE) {
@@ -199,9 +199,9 @@ export default function ControlPanel({
199199
} else if (a.element === ObjectType.AREA) {
200200
addArea(a.data, false);
201201
} else if (a.element === ObjectType.TYPE) {
202-
addType({ id: a.id, ...a.data }, false);
202+
addType(a.data, false);
203203
} else if (a.element === ObjectType.ENUM) {
204-
addEnum({ id: a.id, ...a.data }, false);
204+
addEnum(a.data, false);
205205
}
206206
setRedoStack((prev) => [...prev, a]);
207207
} else if (a.action === Action.EDIT) {
@@ -258,9 +258,12 @@ export default function ControlPanel({
258258
updateRelationship(a.rid, a.undo);
259259
} else if (a.element === ObjectType.TYPE) {
260260
if (a.component === "field_add") {
261+
const type = types.find((t, i) =>
262+
typeof a.tid === "number" ? i === a.tid : t.id === a.tid,
263+
);
261264
updateType(a.tid, {
262-
fields: types[a.tid].fields.filter(
263-
(_, i) => i !== types[a.tid].fields.length - 1,
265+
fields: type.fields.filter((f, i) =>
266+
f.id ? f.id !== a.data.field.id : i !== type.fields.length - 1,
264267
),
265268
});
266269
}
@@ -334,9 +337,9 @@ export default function ControlPanel({
334337
} else if (a.element === ObjectType.RELATIONSHIP) {
335338
addRelationship(a.data, false);
336339
} else if (a.element === ObjectType.TYPE) {
337-
addType(null, false);
340+
addType(a.data, false);
338341
} else if (a.element === ObjectType.ENUM) {
339-
addEnum(null, false);
342+
addEnum(a.data, false);
340343
}
341344
setUndoStack((prev) => [...prev, a]);
342345
} else if (a.action === Action.MOVE) {
@@ -367,9 +370,9 @@ export default function ControlPanel({
367370
} else if (a.element === ObjectType.AREA) {
368371
deleteArea(a.data.id, false);
369372
} else if (a.element === ObjectType.TYPE) {
370-
deleteType(a.id, false);
373+
deleteType(a.data.type.id, false);
371374
} else if (a.element === ObjectType.ENUM) {
372-
deleteEnum(a.id, false);
375+
deleteEnum(a.data.enum.id, false);
373376
}
374377
setUndoStack((prev) => [...prev, a]);
375378
} else if (a.action === Action.EDIT) {
@@ -436,14 +439,11 @@ export default function ControlPanel({
436439
updateRelationship(a.rid, a.redo);
437440
} else if (a.element === ObjectType.TYPE) {
438441
if (a.component === "field_add") {
442+
const type = types.find((t, i) =>
443+
typeof a.tid === "number" ? i === a.tid : t.id === a.tid,
444+
);
439445
updateType(a.tid, {
440-
fields: [
441-
...types[a.tid].fields,
442-
{
443-
name: "",
444-
type: "",
445-
},
446-
],
446+
fields: [...type.fields, a.data.field],
447447
});
448448
} else if (a.component === "field") {
449449
updateType(a.tid, {
@@ -711,7 +711,6 @@ export default function ControlPanel({
711711
return;
712712
}
713713
const v = new Validator();
714-
console.log(obj);
715714
if (v.validate(obj, tableSchema).valid) {
716715
addTable({
717716
table: {
@@ -782,11 +781,24 @@ export default function ControlPanel({
782781
setUndoStack([]);
783782
setRedoStack([]);
784783
if (databases[database].hasTypes) {
785-
setTypes(diagram.types ?? []);
786-
}
787-
if (databases[database].hasEnums) {
788-
setEnums(diagram.enums ?? []);
784+
setTypes(
785+
diagram.types.map((t) =>
786+
t.id
787+
? t
788+
: {
789+
...t,
790+
id: nanoid(),
791+
fields: t.fields.map((f) =>
792+
f.id ? f : { ...f, id: nanoid() },
793+
),
794+
},
795+
),
796+
);
789797
}
798+
setEnums(
799+
diagram.enums.map((e) => (!e.id ? { ...e, id: nanoid() } : e)) ??
800+
[],
801+
);
790802
window.name = `d ${diagram.id}`;
791803
} else {
792804
window.name = "";

0 commit comments

Comments
 (0)