dbml-erd-viewer 0.1.1 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +36 -7
- package/dist/dbml-erd-viewer.css +1 -1
- package/dist/dbml-erd-viewer.js +517 -382
- package/dist/dbml-erd-viewer.umd.cjs +1 -1
- package/dist/index.d.ts +22 -3
- package/package.json +1 -1
package/dist/dbml-erd-viewer.js
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { Background as
|
|
3
|
-
import * as
|
|
4
|
-
import { Fragment as
|
|
1
|
+
import { createContext as e, forwardRef as t, memo as n, useCallback as r, useContext as i, useEffect as a, useImperativeHandle as o, useMemo as s, useRef as c, useState as l } from "react";
|
|
2
|
+
import { Background as u, ControlButton as d, Controls as f, Handle as p, MiniMap as m, Position as h, ReactFlow as ee, getBezierPath as te, getNodesBounds as ne, getSmoothStepPath as re, useEdgesState as ie, useInternalNode as g, useNodesState as ae } from "@xyflow/react";
|
|
3
|
+
import * as _ from "@dbml/core";
|
|
4
|
+
import { Fragment as v, jsx as y, jsxs as b } from "react/jsx-runtime";
|
|
5
5
|
//#region src/parser/parseDbml.ts
|
|
6
|
-
var
|
|
7
|
-
if (!
|
|
8
|
-
var
|
|
6
|
+
var x = _, S = x.Parser ?? x.default?.Parser;
|
|
7
|
+
if (!S) throw Error("Could not resolve `Parser` export from @dbml/core.");
|
|
8
|
+
var oe = S, C = "public", w = class extends Error {
|
|
9
9
|
diagnostics;
|
|
10
10
|
constructor(e, t) {
|
|
11
11
|
super(e, t), this.name = "DbmlParseError", this.diagnostics = t?.diagnostics ?? [];
|
|
12
12
|
}
|
|
13
13
|
};
|
|
14
|
-
function
|
|
14
|
+
function T(e) {
|
|
15
15
|
let t = e?.diags;
|
|
16
16
|
return Array.isArray(t) ? t.map((e) => ({
|
|
17
17
|
message: e.message ?? "Unknown error",
|
|
@@ -20,43 +20,43 @@ function w(e) {
|
|
|
20
20
|
code: e.code
|
|
21
21
|
})) : [];
|
|
22
22
|
}
|
|
23
|
-
function
|
|
23
|
+
function E(e, t) {
|
|
24
24
|
if (e.length === 0) return `Failed to parse DBML: ${t}`;
|
|
25
25
|
let n = e.map((e) => ` • ${e.line == null ? "" : `Line ${e.line}${e.column == null ? "" : `:${e.column}`} — `}${e.message}`);
|
|
26
26
|
return `${e.length === 1 ? "Failed to parse DBML:" : `Failed to parse DBML (${e.length} errors):`}\n${n.join("\n")}`;
|
|
27
27
|
}
|
|
28
|
-
function
|
|
28
|
+
function D(e) {
|
|
29
29
|
if (e) return typeof e == "string" ? e : e.value ?? void 0;
|
|
30
30
|
}
|
|
31
|
-
function
|
|
32
|
-
return e && e !==
|
|
31
|
+
function O(e, t) {
|
|
32
|
+
return e && e !== C ? `${e}.${t}` : t;
|
|
33
33
|
}
|
|
34
|
-
function
|
|
34
|
+
function k(e) {
|
|
35
35
|
let t = /* @__PURE__ */ new Set();
|
|
36
36
|
for (let n of e.fields) n.pk && t.add(n.name);
|
|
37
37
|
for (let n of e.indexes ?? []) if (n.pk) for (let e of n.columns ?? []) e.type === "column" && e.value && t.add(e.value);
|
|
38
38
|
return t;
|
|
39
39
|
}
|
|
40
|
-
function
|
|
40
|
+
function A(e) {
|
|
41
41
|
let t;
|
|
42
42
|
try {
|
|
43
|
-
t = new
|
|
43
|
+
t = new oe().parse(e, "dbmlv2");
|
|
44
44
|
} catch (e) {
|
|
45
|
-
let t =
|
|
46
|
-
throw new
|
|
45
|
+
let t = T(e);
|
|
46
|
+
throw new w(E(t, e instanceof Error ? e.message : String(e)), {
|
|
47
47
|
cause: e,
|
|
48
48
|
diagnostics: t
|
|
49
49
|
});
|
|
50
50
|
}
|
|
51
51
|
let n = /* @__PURE__ */ new Map();
|
|
52
52
|
for (let e of t.schemas) for (let t of e.tables) {
|
|
53
|
-
let r =
|
|
53
|
+
let r = O(e.name, t.name), i = k(t), a = /* @__PURE__ */ new Map();
|
|
54
54
|
for (let e of t.fields) {
|
|
55
55
|
let t = i.has(e.name);
|
|
56
56
|
a.set(e.name, {
|
|
57
57
|
pk: t,
|
|
58
58
|
notNull: t || !!e.not_null,
|
|
59
|
-
note:
|
|
59
|
+
note: D(e.note)
|
|
60
60
|
});
|
|
61
61
|
}
|
|
62
62
|
n.set(r, a);
|
|
@@ -71,7 +71,7 @@ function ie(e) {
|
|
|
71
71
|
for (let e of t.schemas) for (let t of e.refs) {
|
|
72
72
|
if (t.endpoints.length !== 2) continue;
|
|
73
73
|
let [n, c] = t.endpoints.map((t) => ({
|
|
74
|
-
tableId:
|
|
74
|
+
tableId: O(t.schemaName ?? e.name, t.tableName),
|
|
75
75
|
columns: t.fieldNames,
|
|
76
76
|
relation: t.relation
|
|
77
77
|
})), l, u, d = n.relation === "*";
|
|
@@ -98,7 +98,7 @@ function ie(e) {
|
|
|
98
98
|
for (let e of t.schemas) {
|
|
99
99
|
let t = e.name;
|
|
100
100
|
for (let n of e.tables) {
|
|
101
|
-
let e =
|
|
101
|
+
let e = O(t, n.name), r = k(n), i = n.fields.map((t) => ({
|
|
102
102
|
name: t.name,
|
|
103
103
|
type: t.type?.type_name ?? "unknown",
|
|
104
104
|
pk: r.has(t.name),
|
|
@@ -106,14 +106,14 @@ function ie(e) {
|
|
|
106
106
|
unique: !!t.unique,
|
|
107
107
|
increment: !!t.increment,
|
|
108
108
|
defaultValue: t.dbdefault?.value,
|
|
109
|
-
note:
|
|
109
|
+
note: D(t.note),
|
|
110
110
|
isForeignKey: s.has(`${e}::${t.name}`)
|
|
111
111
|
}));
|
|
112
112
|
c.push({
|
|
113
113
|
id: e,
|
|
114
114
|
name: n.name,
|
|
115
|
-
schema: t ===
|
|
116
|
-
note:
|
|
115
|
+
schema: t === C ? void 0 : t,
|
|
116
|
+
note: D(n.note),
|
|
117
117
|
headerColor: n.headerColor ?? void 0,
|
|
118
118
|
columns: i
|
|
119
119
|
});
|
|
@@ -126,64 +126,78 @@ function ie(e) {
|
|
|
126
126
|
}
|
|
127
127
|
//#endregion
|
|
128
128
|
//#region src/layout/layout.ts
|
|
129
|
-
var
|
|
130
|
-
function
|
|
129
|
+
var se = 160, j = 320, M = 320, N = 40, P = 28;
|
|
130
|
+
function F(e) {
|
|
131
131
|
return 40 + Math.max(e.columns.length, 1) * 28;
|
|
132
132
|
}
|
|
133
|
-
var
|
|
134
|
-
function
|
|
135
|
-
let n = t.minWidth ?? 160, r = t.maxWidth ?? 320, i =
|
|
133
|
+
var I = 24, ce = 8, L = 24, R = 12, z = 24, B = 6.8, V = 7.4;
|
|
134
|
+
function H(e, t = {}) {
|
|
135
|
+
let n = t.minWidth ?? 160, r = t.maxWidth ?? 320, i = z + U(e) * V;
|
|
136
136
|
for (let t of e.columns) {
|
|
137
|
-
let e = (t.pk || t.isForeignKey ?
|
|
138
|
-
i = Math.max(i,
|
|
137
|
+
let e = (t.pk || t.isForeignKey ? L : 0) + t.name.length * B, n = t.type.length * B + R;
|
|
138
|
+
i = Math.max(i, I + e + ce + n);
|
|
139
139
|
}
|
|
140
140
|
return Math.round(Math.min(r, Math.max(n, i)));
|
|
141
141
|
}
|
|
142
|
-
function
|
|
142
|
+
function U(e) {
|
|
143
143
|
return (e.schema ? e.schema.length + 1 : 0) + e.name.length;
|
|
144
144
|
}
|
|
145
|
-
function
|
|
146
|
-
let
|
|
147
|
-
for (let
|
|
148
|
-
let
|
|
149
|
-
for (let
|
|
145
|
+
function W(e, t) {
|
|
146
|
+
let n = /* @__PURE__ */ new Map();
|
|
147
|
+
for (let t of e) n.set(t.id, 0);
|
|
148
|
+
let r = t.map((e) => [e.from.tableId, e.to.tableId]).filter(([e, t]) => e !== t && n.has(e) && n.has(t));
|
|
149
|
+
for (let t = 0; t < e.length; t++) {
|
|
150
150
|
let e = !1;
|
|
151
|
-
for (let [
|
|
152
|
-
let
|
|
153
|
-
|
|
151
|
+
for (let [t, i] of r) {
|
|
152
|
+
let r = n.get(t) + 1;
|
|
153
|
+
n.get(i) < r && (n.set(i, r), e = !0);
|
|
154
154
|
}
|
|
155
155
|
if (!e) break;
|
|
156
156
|
}
|
|
157
|
-
return
|
|
157
|
+
return n;
|
|
158
158
|
}
|
|
159
|
-
function
|
|
159
|
+
function G(e, t = {}) {
|
|
160
160
|
let n = t.horizontalGap ?? 120, r = t.verticalGap ?? 40, i = {
|
|
161
161
|
minWidth: t.minNodeWidth,
|
|
162
162
|
maxWidth: t.maxNodeWidth
|
|
163
|
-
}, a =
|
|
164
|
-
for (let t of e.
|
|
165
|
-
|
|
166
|
-
|
|
163
|
+
}, a = /* @__PURE__ */ new Set();
|
|
164
|
+
for (let t of e.relations) a.add(t.from.tableId), a.add(t.to.tableId);
|
|
165
|
+
let o = e.tables.filter((e) => a.has(e.id)), s = e.tables.filter((e) => !a.has(e.id)), c = /* @__PURE__ */ new Map(), l = W(o, e.relations), u = /* @__PURE__ */ new Map();
|
|
166
|
+
for (let e of o) {
|
|
167
|
+
let t = l.get(e.id) ?? 0, n = u.get(t);
|
|
168
|
+
n || (n = [], u.set(t, n)), n.push(e);
|
|
167
169
|
}
|
|
168
|
-
let
|
|
169
|
-
for (let e of
|
|
170
|
-
let t =
|
|
170
|
+
let d = 0, f = 0, p = 0;
|
|
171
|
+
for (let e of [...u.keys()].sort((e, t) => e - t)) {
|
|
172
|
+
let t = u.get(e).sort((e, t) => e.name.localeCompare(t.name)), a = 0, o = 0;
|
|
171
173
|
for (let e of t) {
|
|
172
|
-
let t =
|
|
173
|
-
|
|
174
|
-
x:
|
|
175
|
-
y:
|
|
174
|
+
let t = H(e, i), n = F(e);
|
|
175
|
+
c.set(e.id, {
|
|
176
|
+
x: p,
|
|
177
|
+
y: o,
|
|
176
178
|
width: t,
|
|
177
179
|
height: n
|
|
178
|
-
}), a = Math.max(a, t),
|
|
180
|
+
}), a = Math.max(a, t), o += n + r;
|
|
179
181
|
}
|
|
180
|
-
|
|
182
|
+
d = Math.max(d, p + a), f = Math.max(f, o - r), p += a + n;
|
|
181
183
|
}
|
|
182
|
-
|
|
184
|
+
if (s.length > 0) {
|
|
185
|
+
let e = d > 0 ? d : Math.ceil(Math.sqrt(s.length)) * (320 + n), t = 0, a = f > 0 ? f + r * 2 : 0, o = 0;
|
|
186
|
+
for (let l of [...s].sort((e, t) => e.name.localeCompare(t.name))) {
|
|
187
|
+
let s = H(l, i), u = F(l);
|
|
188
|
+
t > 0 && t + s > e && (t = 0, a += o + r, o = 0), c.set(l.id, {
|
|
189
|
+
x: t,
|
|
190
|
+
y: a,
|
|
191
|
+
width: s,
|
|
192
|
+
height: u
|
|
193
|
+
}), t += s + n, o = Math.max(o, u);
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
return c;
|
|
183
197
|
}
|
|
184
198
|
//#endregion
|
|
185
199
|
//#region src/layout/dagre.ts
|
|
186
|
-
async function
|
|
200
|
+
async function le(e, t = {}) {
|
|
187
201
|
let n = await import("@dagrejs/dagre"), r = t.horizontalGap ?? 120, i = t.verticalGap ?? 40, a = {
|
|
188
202
|
minWidth: t.minNodeWidth,
|
|
189
203
|
maxWidth: t.maxNodeWidth
|
|
@@ -194,8 +208,8 @@ async function W(e, t = {}) {
|
|
|
194
208
|
nodesep: i
|
|
195
209
|
}), s.setDefaultEdgeLabel(() => ({}));
|
|
196
210
|
for (let t of e.tables) s.setNode(t.id, {
|
|
197
|
-
width:
|
|
198
|
-
height:
|
|
211
|
+
width: H(t, a),
|
|
212
|
+
height: F(t)
|
|
199
213
|
});
|
|
200
214
|
for (let t of e.relations) s.hasNode(t.from.tableId) && s.hasNode(t.to.tableId) && s.setEdge(t.from.tableId, t.to.tableId);
|
|
201
215
|
n.layout(s);
|
|
@@ -213,7 +227,7 @@ async function W(e, t = {}) {
|
|
|
213
227
|
}
|
|
214
228
|
//#endregion
|
|
215
229
|
//#region src/layout/elk.ts
|
|
216
|
-
async function
|
|
230
|
+
async function K(e, t = {}) {
|
|
217
231
|
let n = new (await (import("elkjs/lib/elk.bundled.js"))).default(), r = t.horizontalGap ?? 120, i = t.verticalGap ?? 40, a = {
|
|
218
232
|
minWidth: t.minNodeWidth,
|
|
219
233
|
maxWidth: t.maxNodeWidth
|
|
@@ -227,8 +241,8 @@ async function G(e, t = {}) {
|
|
|
227
241
|
},
|
|
228
242
|
children: e.tables.map((e) => ({
|
|
229
243
|
id: e.id,
|
|
230
|
-
width:
|
|
231
|
-
height:
|
|
244
|
+
width: H(e, a),
|
|
245
|
+
height: F(e)
|
|
232
246
|
})),
|
|
233
247
|
edges: e.relations.map((e, t) => ({
|
|
234
248
|
id: `e${t}`,
|
|
@@ -246,23 +260,23 @@ async function G(e, t = {}) {
|
|
|
246
260
|
}
|
|
247
261
|
//#endregion
|
|
248
262
|
//#region src/layout/computeLayout.ts
|
|
249
|
-
var
|
|
263
|
+
var q = class extends Error {
|
|
250
264
|
constructor(e, t) {
|
|
251
265
|
super(e, t), this.name = "LayoutError";
|
|
252
266
|
}
|
|
253
267
|
};
|
|
254
|
-
async function
|
|
268
|
+
async function J(e, t = {}) {
|
|
255
269
|
let n = t.algorithm ?? "simple";
|
|
256
|
-
if (n === "simple") return
|
|
270
|
+
if (n === "simple") return G(e, t);
|
|
257
271
|
try {
|
|
258
|
-
return n === "dagre" ? await
|
|
272
|
+
return n === "dagre" ? await le(e, t) : await K(e, t);
|
|
259
273
|
} catch (e) {
|
|
260
|
-
throw new
|
|
274
|
+
throw new q(`"${n}" layout failed. Is the optional dependency "${n === "dagre" ? "@dagrejs/dagre" : "elkjs"}" installed? (${e instanceof Error ? e.message : String(e)})`, { cause: e });
|
|
261
275
|
}
|
|
262
276
|
}
|
|
263
277
|
//#endregion
|
|
264
278
|
//#region src/export.ts
|
|
265
|
-
var
|
|
279
|
+
var ue = [
|
|
266
280
|
"--dv-canvas",
|
|
267
281
|
"--dv-bg",
|
|
268
282
|
"--dv-border",
|
|
@@ -283,7 +297,7 @@ var J = [
|
|
|
283
297
|
super(e, t), this.name = "ExportError";
|
|
284
298
|
}
|
|
285
299
|
};
|
|
286
|
-
function
|
|
300
|
+
function de(e, t) {
|
|
287
301
|
let n = e.x, r = e.y, i = e.x + e.width, a = e.y + e.height;
|
|
288
302
|
for (let e of t.querySelectorAll(".dv-erd-edge")) {
|
|
289
303
|
let t;
|
|
@@ -301,7 +315,7 @@ function se(e, t) {
|
|
|
301
315
|
height: a - r
|
|
302
316
|
};
|
|
303
317
|
}
|
|
304
|
-
async function
|
|
318
|
+
async function fe(e, t, n = {}) {
|
|
305
319
|
let { type: r = "png", padding: i = 24, backgroundColor: a, pixelRatio: o = 2 } = n, s;
|
|
306
320
|
try {
|
|
307
321
|
s = await import("html-to-image");
|
|
@@ -320,7 +334,7 @@ async function ce(e, t, n = {}) {
|
|
|
320
334
|
height: `${l}px`,
|
|
321
335
|
transform: u
|
|
322
336
|
}
|
|
323
|
-
}, f =
|
|
337
|
+
}, f = pe(e, t, i);
|
|
324
338
|
try {
|
|
325
339
|
return r === "svg" ? await s.toSvg(e, d) : await s.toPng(e, {
|
|
326
340
|
...d,
|
|
@@ -332,11 +346,11 @@ async function ce(e, t, n = {}) {
|
|
|
332
346
|
f();
|
|
333
347
|
}
|
|
334
348
|
}
|
|
335
|
-
function
|
|
349
|
+
function pe(e, t, n) {
|
|
336
350
|
let r = [], i = e.closest(".dv-viewer");
|
|
337
351
|
if (i) {
|
|
338
352
|
let t = getComputedStyle(i);
|
|
339
|
-
for (let n of
|
|
353
|
+
for (let n of ue) {
|
|
340
354
|
let i = t.getPropertyValue(n);
|
|
341
355
|
if (!i) continue;
|
|
342
356
|
let a = e.style.getPropertyValue(n);
|
|
@@ -354,7 +368,7 @@ function le(e, t, n) {
|
|
|
354
368
|
}
|
|
355
369
|
return () => r.forEach((e) => e());
|
|
356
370
|
}
|
|
357
|
-
function
|
|
371
|
+
function me(e, t) {
|
|
358
372
|
let n = document.createElement("a");
|
|
359
373
|
n.href = e, n.download = t, n.click();
|
|
360
374
|
}
|
|
@@ -364,217 +378,307 @@ function X(e, t, n) {
|
|
|
364
378
|
return `${e}__${t}__${n}`;
|
|
365
379
|
}
|
|
366
380
|
//#endregion
|
|
367
|
-
//#region src/components/
|
|
368
|
-
|
|
381
|
+
//#region src/components/columnHoverContext.ts
|
|
382
|
+
var he = e(void 0), ge = e("column");
|
|
383
|
+
function Z(e) {
|
|
369
384
|
return 40 + e * 28 + 28 / 2;
|
|
370
385
|
}
|
|
371
|
-
|
|
386
|
+
var _e = 4;
|
|
387
|
+
function ve({ column: e, top: t }) {
|
|
372
388
|
let n = {
|
|
373
|
-
top: t,
|
|
389
|
+
top: t - _e,
|
|
390
|
+
opacity: 0
|
|
391
|
+
}, r = {
|
|
392
|
+
top: t + _e,
|
|
374
393
|
opacity: 0
|
|
375
394
|
};
|
|
376
|
-
return /* @__PURE__ */ v
|
|
377
|
-
/* @__PURE__ */
|
|
395
|
+
return /* @__PURE__ */ b(v, { children: [
|
|
396
|
+
/* @__PURE__ */ y(p, {
|
|
378
397
|
id: X(e, "left", "target"),
|
|
379
398
|
type: "target",
|
|
380
|
-
position:
|
|
381
|
-
style:
|
|
399
|
+
position: h.Left,
|
|
400
|
+
style: r,
|
|
382
401
|
isConnectable: !1
|
|
383
402
|
}),
|
|
384
|
-
/* @__PURE__ */
|
|
403
|
+
/* @__PURE__ */ y(p, {
|
|
385
404
|
id: X(e, "left", "source"),
|
|
386
405
|
type: "source",
|
|
387
|
-
position:
|
|
406
|
+
position: h.Left,
|
|
388
407
|
style: n,
|
|
389
408
|
isConnectable: !1
|
|
390
409
|
}),
|
|
391
|
-
/* @__PURE__ */
|
|
410
|
+
/* @__PURE__ */ y(p, {
|
|
392
411
|
id: X(e, "right", "target"),
|
|
393
412
|
type: "target",
|
|
394
|
-
position:
|
|
395
|
-
style:
|
|
413
|
+
position: h.Right,
|
|
414
|
+
style: r,
|
|
396
415
|
isConnectable: !1
|
|
397
416
|
}),
|
|
398
|
-
/* @__PURE__ */
|
|
417
|
+
/* @__PURE__ */ y(p, {
|
|
399
418
|
id: X(e, "right", "source"),
|
|
400
419
|
type: "source",
|
|
401
|
-
position:
|
|
420
|
+
position: h.Right,
|
|
402
421
|
style: n,
|
|
403
422
|
isConnectable: !1
|
|
404
423
|
})
|
|
405
424
|
] });
|
|
406
425
|
}
|
|
407
|
-
function
|
|
408
|
-
let { table: t, highlightedColumns: n, widthBounds: r } = e;
|
|
409
|
-
return /* @__PURE__ */
|
|
426
|
+
function ye({ data: e }) {
|
|
427
|
+
let { table: t, highlightedColumns: n, widthBounds: r, connectedColumns: a } = e, o = i(he), s = i(ge) === "floating";
|
|
428
|
+
return /* @__PURE__ */ b("div", {
|
|
410
429
|
className: "dv-table",
|
|
411
|
-
style: { width:
|
|
412
|
-
children: [
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
className:
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
430
|
+
style: { width: H(t, r) },
|
|
431
|
+
children: [
|
|
432
|
+
s && /* @__PURE__ */ b(v, { children: [/* @__PURE__ */ y(p, {
|
|
433
|
+
type: "source",
|
|
434
|
+
position: h.Right,
|
|
435
|
+
style: { opacity: 0 },
|
|
436
|
+
isConnectable: !1
|
|
437
|
+
}), /* @__PURE__ */ y(p, {
|
|
438
|
+
type: "target",
|
|
439
|
+
position: h.Left,
|
|
440
|
+
style: { opacity: 0 },
|
|
441
|
+
isConnectable: !1
|
|
442
|
+
})] }),
|
|
443
|
+
/* @__PURE__ */ b("div", {
|
|
444
|
+
className: "dv-table__header",
|
|
445
|
+
style: t.headerColor ? {
|
|
446
|
+
background: t.headerColor,
|
|
447
|
+
height: 40
|
|
448
|
+
} : { height: 40 },
|
|
449
|
+
title: t.note,
|
|
450
|
+
children: [t.schema && /* @__PURE__ */ b("span", {
|
|
451
|
+
className: "dv-table__schema",
|
|
452
|
+
children: [t.schema, "."]
|
|
453
|
+
}), /* @__PURE__ */ y("span", {
|
|
454
|
+
className: "dv-table__name",
|
|
455
|
+
title: t.name,
|
|
456
|
+
children: t.name
|
|
457
|
+
})]
|
|
458
|
+
}),
|
|
459
|
+
/* @__PURE__ */ y("div", {
|
|
460
|
+
className: "dv-table__body",
|
|
461
|
+
children: t.columns.map((e, r) => {
|
|
462
|
+
let i = n?.has(e.name);
|
|
463
|
+
return /* @__PURE__ */ b("div", {
|
|
464
|
+
className: `dv-row${i ? " dv-row--highlighted" : ""}`,
|
|
465
|
+
style: { height: 28 },
|
|
466
|
+
title: e.note,
|
|
467
|
+
onMouseEnter: () => o?.(t.id, e.name),
|
|
468
|
+
onMouseLeave: () => o?.(t.id, null),
|
|
469
|
+
children: [
|
|
470
|
+
/* @__PURE__ */ b("span", {
|
|
471
|
+
className: `dv-row__name${e.pk ? " dv-row__name--pk" : ""}`,
|
|
472
|
+
children: [
|
|
473
|
+
e.pk && /* @__PURE__ */ y("span", {
|
|
474
|
+
className: "dv-badge dv-badge--pk",
|
|
475
|
+
title: "Primary key",
|
|
476
|
+
children: "PK"
|
|
477
|
+
}),
|
|
478
|
+
e.isForeignKey && !e.pk && /* @__PURE__ */ y("span", {
|
|
479
|
+
className: "dv-badge dv-badge--fk",
|
|
480
|
+
title: "Foreign key",
|
|
481
|
+
children: "FK"
|
|
482
|
+
}),
|
|
483
|
+
/* @__PURE__ */ y("span", {
|
|
484
|
+
className: "dv-row__label",
|
|
485
|
+
title: e.name,
|
|
486
|
+
children: e.name
|
|
487
|
+
})
|
|
488
|
+
]
|
|
489
|
+
}),
|
|
490
|
+
/* @__PURE__ */ b("span", {
|
|
491
|
+
className: "dv-row__type",
|
|
492
|
+
children: [/* @__PURE__ */ y("span", {
|
|
493
|
+
className: "dv-row__typename",
|
|
494
|
+
title: e.type,
|
|
495
|
+
children: e.type
|
|
496
|
+
}), /* @__PURE__ */ y("span", {
|
|
497
|
+
className: `dv-row__null${e.notNull ? " dv-row__null--notnull" : ""}`,
|
|
498
|
+
title: e.notNull ? "Not null" : "Nullable"
|
|
499
|
+
})]
|
|
500
|
+
}),
|
|
501
|
+
!s && a?.has(e.name) && /* @__PURE__ */ y(ve, {
|
|
502
|
+
column: e.name,
|
|
503
|
+
top: Z(r)
|
|
504
|
+
})
|
|
505
|
+
]
|
|
506
|
+
}, e.name);
|
|
507
|
+
})
|
|
473
508
|
})
|
|
474
|
-
|
|
509
|
+
]
|
|
475
510
|
});
|
|
476
511
|
}
|
|
477
|
-
var
|
|
478
|
-
|
|
479
|
-
|
|
512
|
+
var be = n(ye), xe = 8, Q = 13, Se = 7, Ce = 13, we = 16, Te = {
|
|
513
|
+
[h.Right]: 0,
|
|
514
|
+
[h.Left]: 180,
|
|
515
|
+
[h.Top]: -90,
|
|
516
|
+
[h.Bottom]: 90
|
|
517
|
+
};
|
|
518
|
+
function Ee(e, t, n, r, i, a) {
|
|
519
|
+
let o = [], s = {
|
|
480
520
|
stroke: i,
|
|
481
521
|
strokeWidth: a
|
|
482
|
-
},
|
|
483
|
-
x1: e
|
|
484
|
-
y1:
|
|
485
|
-
x2: e
|
|
486
|
-
y2:
|
|
487
|
-
style:
|
|
488
|
-
},
|
|
489
|
-
cx: e
|
|
490
|
-
cy:
|
|
522
|
+
}, c = (e, t) => o.push(/* @__PURE__ */ y("line", {
|
|
523
|
+
x1: e,
|
|
524
|
+
y1: -8,
|
|
525
|
+
x2: e,
|
|
526
|
+
y2: xe,
|
|
527
|
+
style: s
|
|
528
|
+
}, t)), l = (e, t) => o.push(/* @__PURE__ */ y("circle", {
|
|
529
|
+
cx: e,
|
|
530
|
+
cy: 0,
|
|
491
531
|
r: 4,
|
|
492
532
|
style: {
|
|
493
533
|
stroke: i,
|
|
494
534
|
strokeWidth: a,
|
|
495
535
|
fill: "var(--dv-bg)"
|
|
496
536
|
}
|
|
497
|
-
},
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
style: c
|
|
518
|
-
}, "cf3")), r.optional === !0 ? u(17, "fr") : l(14, "fb");
|
|
519
|
-
} else l(me, "b1"), r.optional === !0 ? u(ge, "r") : r.optional === !1 && l(he, "b2");
|
|
520
|
-
return /* @__PURE__ */ _("g", {
|
|
537
|
+
}, t));
|
|
538
|
+
return r.cardinality === "*" ? (o.push(/* @__PURE__ */ y("line", {
|
|
539
|
+
x1: Q,
|
|
540
|
+
y1: 0,
|
|
541
|
+
x2: 0,
|
|
542
|
+
y2: -8,
|
|
543
|
+
style: s
|
|
544
|
+
}, "cf1"), /* @__PURE__ */ y("line", {
|
|
545
|
+
x1: Q,
|
|
546
|
+
y1: 0,
|
|
547
|
+
x2: 0,
|
|
548
|
+
y2: 0,
|
|
549
|
+
style: s
|
|
550
|
+
}, "cf2"), /* @__PURE__ */ y("line", {
|
|
551
|
+
x1: Q,
|
|
552
|
+
y1: 0,
|
|
553
|
+
x2: 0,
|
|
554
|
+
y2: xe,
|
|
555
|
+
style: s
|
|
556
|
+
}, "cf3")), r.optional === !0 ? l(17, "fr") : c(14, "fb")) : (c(Se, "b1"), r.optional === !0 ? l(we, "r") : r.optional === !1 && c(Ce, "b2")), /* @__PURE__ */ y("g", {
|
|
521
557
|
className: "dv-erd-marker",
|
|
522
|
-
|
|
558
|
+
transform: `translate(${e}, ${t}) rotate(${Te[n]})`,
|
|
559
|
+
children: o
|
|
523
560
|
});
|
|
524
561
|
}
|
|
525
|
-
function
|
|
526
|
-
let
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
sourcePosition: i,
|
|
530
|
-
targetX: n,
|
|
531
|
-
targetY: r,
|
|
532
|
-
targetPosition: a,
|
|
533
|
-
borderRadius: 8
|
|
534
|
-
}), l = o, u = l?.kind === "non-identifying", d = s || l?.hovered, f = d ? "var(--dv-edge-active)" : "var(--dv-edge)", p = d ? 2 : 1.5;
|
|
535
|
-
return /* @__PURE__ */ v("g", {
|
|
536
|
-
className: `dv-erd-edge${d ? " dv-erd-edge--active" : ""}`,
|
|
562
|
+
function De(e, t, n, r, i, a, o, s, c) {
|
|
563
|
+
let l = t?.kind === "non-identifying", u = n ? "var(--dv-edge-active)" : "var(--dv-edge)", d = n ? 2 : 1.5;
|
|
564
|
+
return /* @__PURE__ */ b("g", {
|
|
565
|
+
className: `dv-erd-edge${n ? " dv-erd-edge--active" : ""}`,
|
|
537
566
|
children: [
|
|
538
|
-
/* @__PURE__ */
|
|
567
|
+
/* @__PURE__ */ y("path", {
|
|
539
568
|
className: "dv-erd-edge__interaction",
|
|
540
|
-
d:
|
|
569
|
+
d: e,
|
|
541
570
|
fill: "none"
|
|
542
571
|
}),
|
|
543
|
-
/* @__PURE__ */
|
|
572
|
+
/* @__PURE__ */ y("path", {
|
|
544
573
|
className: "dv-erd-edge__path",
|
|
545
|
-
d:
|
|
574
|
+
d: e,
|
|
546
575
|
fill: "none",
|
|
547
576
|
style: {
|
|
548
|
-
stroke:
|
|
549
|
-
strokeWidth:
|
|
577
|
+
stroke: u,
|
|
578
|
+
strokeWidth: d
|
|
550
579
|
},
|
|
551
|
-
strokeDasharray:
|
|
580
|
+
strokeDasharray: l ? "6 4" : void 0
|
|
552
581
|
}),
|
|
553
|
-
|
|
554
|
-
|
|
582
|
+
t && Ee(r, i, a, t.sourceEnd, u, d),
|
|
583
|
+
t && Ee(o, s, c, t.targetEnd, u, d)
|
|
555
584
|
]
|
|
556
585
|
});
|
|
557
586
|
}
|
|
558
|
-
|
|
587
|
+
function Oe({ sourceX: e, sourceY: t, targetX: n, targetY: r, sourcePosition: i, targetPosition: a, data: o, selected: s }) {
|
|
588
|
+
let [c] = re({
|
|
589
|
+
sourceX: e,
|
|
590
|
+
sourceY: t,
|
|
591
|
+
sourcePosition: i,
|
|
592
|
+
targetX: n,
|
|
593
|
+
targetY: r,
|
|
594
|
+
targetPosition: a,
|
|
595
|
+
borderRadius: 8
|
|
596
|
+
}), l = o;
|
|
597
|
+
return De(c, l, !!(s || l?.hovered), e, t, i, n, r, a);
|
|
598
|
+
}
|
|
599
|
+
var ke = n(Oe);
|
|
600
|
+
function $(e) {
|
|
601
|
+
let t = e.measured?.width ?? 0, n = e.measured?.height ?? 0, { x: r, y: i } = e.internals.positionAbsolute;
|
|
602
|
+
return {
|
|
603
|
+
x: r,
|
|
604
|
+
y: i,
|
|
605
|
+
w: t,
|
|
606
|
+
h: n,
|
|
607
|
+
cx: r + t / 2,
|
|
608
|
+
cy: i + n / 2
|
|
609
|
+
};
|
|
610
|
+
}
|
|
611
|
+
function Ae(e, t) {
|
|
612
|
+
let n = $(e), r = $(t), i = n.w / 2, a = n.h / 2, o = (r.cx - n.cx) / (2 * i) - (r.cy - n.cy) / (2 * a), s = (r.cx - n.cx) / (2 * i) + (r.cy - n.cy) / (2 * a), c = 1 / (Math.abs(o) + Math.abs(s) || 1);
|
|
613
|
+
return {
|
|
614
|
+
x: i * c * (o + s) + n.cx,
|
|
615
|
+
y: a * c * (-o + s) + n.cy
|
|
616
|
+
};
|
|
617
|
+
}
|
|
618
|
+
function je(e, t) {
|
|
619
|
+
let n = $(e), r = Math.round(t.x), i = Math.round(t.y);
|
|
620
|
+
return r <= Math.round(n.x) + 1 ? h.Left : r >= Math.round(n.x + n.w) - 1 ? h.Right : i <= Math.round(n.y) + 1 ? h.Top : h.Bottom;
|
|
621
|
+
}
|
|
622
|
+
var Me = 14;
|
|
623
|
+
function Ne({ id: e, source: t, target: n, data: r, selected: i }) {
|
|
624
|
+
let a = g(t), o = g(n);
|
|
625
|
+
if (!a || !o) return null;
|
|
626
|
+
let s = r, c = !!(i || s?.hovered), l, u, d, f, p, m;
|
|
627
|
+
if (t === n) {
|
|
628
|
+
let e = $(a);
|
|
629
|
+
l = d = e.x + e.w, u = e.cy - Me, f = e.cy + Me, p = m = h.Right;
|
|
630
|
+
} else {
|
|
631
|
+
let e = Ae(a, o), t = Ae(o, a);
|
|
632
|
+
l = e.x, u = e.y, d = t.x, f = t.y, p = je(a, e), m = je(o, t);
|
|
633
|
+
}
|
|
634
|
+
let [ee] = te({
|
|
635
|
+
sourceX: l,
|
|
636
|
+
sourceY: u,
|
|
637
|
+
sourcePosition: p,
|
|
638
|
+
targetX: d,
|
|
639
|
+
targetY: f,
|
|
640
|
+
targetPosition: m
|
|
641
|
+
});
|
|
642
|
+
return De(ee, s, c, l, u, p, d, f, m);
|
|
643
|
+
}
|
|
644
|
+
var Pe = n(Ne);
|
|
559
645
|
//#endregion
|
|
560
646
|
//#region src/components/useRelationHighlight.ts
|
|
561
|
-
function
|
|
562
|
-
let [i,
|
|
647
|
+
function Fe(e, t, n) {
|
|
648
|
+
let [i, a] = l(null), [o, c] = l(null), u = s(() => {
|
|
563
649
|
let t = /* @__PURE__ */ new Map();
|
|
564
650
|
for (let n of e) t.set(n.id, n);
|
|
565
651
|
return t;
|
|
566
|
-
}, [e]),
|
|
567
|
-
let
|
|
568
|
-
if (
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
652
|
+
}, [e]), d = s(() => {
|
|
653
|
+
let t = /* @__PURE__ */ new Set();
|
|
654
|
+
if (i && t.add(i), o) for (let n of e) {
|
|
655
|
+
let e = (e) => e.tableId === o.tableId && e.columns.includes(o.column);
|
|
656
|
+
(e(n.from) || e(n.to)) && t.add(n.id);
|
|
657
|
+
}
|
|
658
|
+
return t;
|
|
659
|
+
}, [
|
|
660
|
+
i,
|
|
661
|
+
o,
|
|
662
|
+
e
|
|
663
|
+
]), f = s(() => {
|
|
664
|
+
let e = /* @__PURE__ */ new Map();
|
|
665
|
+
for (let t of d) {
|
|
666
|
+
let n = u.get(t);
|
|
667
|
+
if (n) for (let t of [n.from, n.to]) {
|
|
668
|
+
let n = e.get(t.tableId) ?? /* @__PURE__ */ new Set();
|
|
669
|
+
t.columns.forEach((e) => n.add(e)), e.set(t.tableId, n);
|
|
670
|
+
}
|
|
572
671
|
}
|
|
573
672
|
return e;
|
|
574
|
-
}, [
|
|
673
|
+
}, [d, u]), p = r((e, t) => {
|
|
674
|
+
c(t ? {
|
|
675
|
+
tableId: e,
|
|
676
|
+
column: t
|
|
677
|
+
} : null);
|
|
678
|
+
}, []);
|
|
575
679
|
return {
|
|
576
|
-
displayNodes:
|
|
577
|
-
let t =
|
|
680
|
+
displayNodes: s(() => d.size === 0 ? t : t.map((e) => {
|
|
681
|
+
let t = f.get(e.id);
|
|
578
682
|
return t ? {
|
|
579
683
|
...e,
|
|
580
684
|
data: {
|
|
@@ -582,26 +686,27 @@ function be(e, t, r) {
|
|
|
582
686
|
highlightedColumns: t
|
|
583
687
|
}
|
|
584
688
|
} : e;
|
|
585
|
-
})
|
|
689
|
+
}), [
|
|
586
690
|
t,
|
|
587
|
-
|
|
588
|
-
|
|
691
|
+
d,
|
|
692
|
+
f
|
|
589
693
|
]),
|
|
590
|
-
displayEdges:
|
|
694
|
+
displayEdges: s(() => d.size === 0 ? n : n.map((e) => d.has(e.id) ? {
|
|
591
695
|
...e,
|
|
592
696
|
data: {
|
|
593
697
|
...e.data,
|
|
594
698
|
hovered: !0
|
|
595
699
|
},
|
|
596
700
|
zIndex: 1
|
|
597
|
-
} : e)
|
|
598
|
-
onEdgeMouseEnter:
|
|
599
|
-
onEdgeMouseLeave:
|
|
701
|
+
} : e), [n, d]),
|
|
702
|
+
onEdgeMouseEnter: r((e, t) => a(t.id), []),
|
|
703
|
+
onEdgeMouseLeave: r(() => a(null), []),
|
|
704
|
+
onColumnHover: p
|
|
600
705
|
};
|
|
601
706
|
}
|
|
602
707
|
//#endregion
|
|
603
708
|
//#region src/theme.ts
|
|
604
|
-
var
|
|
709
|
+
var Ie = {
|
|
605
710
|
canvas: "--dv-canvas",
|
|
606
711
|
background: "--dv-bg",
|
|
607
712
|
border: "--dv-border",
|
|
@@ -616,7 +721,7 @@ var xe = {
|
|
|
616
721
|
edge: "--dv-edge",
|
|
617
722
|
edgeActive: "--dv-edge-active",
|
|
618
723
|
fontFamily: "--dv-font"
|
|
619
|
-
},
|
|
724
|
+
}, Le = {
|
|
620
725
|
canvas: "#fafbfc",
|
|
621
726
|
background: "#ffffff",
|
|
622
727
|
border: "#d9dee5",
|
|
@@ -630,7 +735,7 @@ var xe = {
|
|
|
630
735
|
foreignKey: "#2b6cb0",
|
|
631
736
|
edge: "#94a3b8",
|
|
632
737
|
edgeActive: "#2b6cb0"
|
|
633
|
-
},
|
|
738
|
+
}, Re = {
|
|
634
739
|
canvas: "#0f172a",
|
|
635
740
|
background: "#1e293b",
|
|
636
741
|
border: "#334155",
|
|
@@ -645,48 +750,51 @@ var xe = {
|
|
|
645
750
|
edge: "#64748b",
|
|
646
751
|
edgeActive: "#60a5fa"
|
|
647
752
|
};
|
|
648
|
-
function
|
|
753
|
+
function ze(e) {
|
|
649
754
|
if (!e) return {};
|
|
650
755
|
let t = {};
|
|
651
756
|
for (let n of Object.keys(e)) {
|
|
652
757
|
let r = e[n];
|
|
653
|
-
r != null && (t[
|
|
758
|
+
r != null && (t[Ie[n]] = r);
|
|
654
759
|
}
|
|
655
760
|
return t;
|
|
656
761
|
}
|
|
657
762
|
//#endregion
|
|
658
763
|
//#region src/components/DbmlViewer.tsx
|
|
659
|
-
var
|
|
660
|
-
|
|
661
|
-
|
|
764
|
+
var Be = [], Ve = { table: be }, He = {
|
|
765
|
+
erd: ke,
|
|
766
|
+
"erd-floating": Pe
|
|
767
|
+
};
|
|
768
|
+
function Ue() {
|
|
769
|
+
return /* @__PURE__ */ b("svg", {
|
|
662
770
|
viewBox: "0 0 24 24",
|
|
663
771
|
width: "100%",
|
|
664
772
|
height: "100%",
|
|
665
773
|
fill: "currentColor",
|
|
666
774
|
"aria-hidden": "true",
|
|
667
775
|
children: [
|
|
668
|
-
/* @__PURE__ */
|
|
776
|
+
/* @__PURE__ */ y("rect", {
|
|
669
777
|
x: "3",
|
|
670
778
|
y: "3",
|
|
671
779
|
width: "8",
|
|
672
780
|
height: "8",
|
|
673
781
|
rx: "1.5"
|
|
674
782
|
}),
|
|
675
|
-
/* @__PURE__ */
|
|
783
|
+
/* @__PURE__ */ y("rect", {
|
|
676
784
|
x: "13",
|
|
677
785
|
y: "3",
|
|
678
786
|
width: "8",
|
|
679
787
|
height: "8",
|
|
680
788
|
rx: "1.5"
|
|
681
789
|
}),
|
|
682
|
-
/* @__PURE__ */
|
|
790
|
+
/* @__PURE__ */ y("rect", {
|
|
683
791
|
x: "3",
|
|
684
792
|
y: "13",
|
|
685
793
|
width: "8",
|
|
686
794
|
height: "8",
|
|
687
795
|
rx: "1.5"
|
|
688
796
|
}),
|
|
689
|
-
/* @__PURE__ */
|
|
797
|
+
/* @__PURE__ */ y("rect", {
|
|
690
798
|
x: "13",
|
|
691
799
|
y: "13",
|
|
692
800
|
width: "8",
|
|
@@ -696,7 +804,7 @@ function Oe() {
|
|
|
696
804
|
]
|
|
697
805
|
});
|
|
698
806
|
}
|
|
699
|
-
function
|
|
807
|
+
function We(e, t, n, r) {
|
|
700
808
|
let i = /* @__PURE__ */ new Map();
|
|
701
809
|
for (let a of e.tables) {
|
|
702
810
|
let e = t.get(a.id);
|
|
@@ -707,27 +815,27 @@ function ke(e, t, n, r) {
|
|
|
707
815
|
}
|
|
708
816
|
return i;
|
|
709
817
|
}
|
|
710
|
-
function
|
|
818
|
+
function Ge(e, t) {
|
|
711
819
|
if (e.length !== t.length) return !1;
|
|
712
820
|
let n = new Set(e);
|
|
713
821
|
return t.every((e) => n.has(e));
|
|
714
822
|
}
|
|
715
|
-
function
|
|
823
|
+
function Ke(e, t, n) {
|
|
716
824
|
return e.x < t.x + t.w + n && e.x + e.w + n > t.x && e.y < t.y + t.h + n && e.y + e.h + n > t.y;
|
|
717
825
|
}
|
|
718
|
-
function
|
|
826
|
+
function qe(e, t, n, r, i) {
|
|
719
827
|
let a = (e, t) => ({
|
|
720
828
|
x: t.x,
|
|
721
829
|
y: t.y,
|
|
722
|
-
w:
|
|
723
|
-
h:
|
|
830
|
+
w: H(e, i),
|
|
831
|
+
h: F(e)
|
|
724
832
|
}), o = [];
|
|
725
833
|
for (let r of e.tables) n(r.id) && o.push(a(r, t.get(r.id)));
|
|
726
834
|
for (let i of e.tables) {
|
|
727
835
|
if (n(i.id)) continue;
|
|
728
836
|
let e = t.get(i.id), s = a(i, e), c = 0;
|
|
729
837
|
for (; c++ < 1e3;) {
|
|
730
|
-
let t = o.filter((e) =>
|
|
838
|
+
let t = o.filter((e) => Ke(s, e, r));
|
|
731
839
|
if (t.length === 0) break;
|
|
732
840
|
let n = Math.max(...t.map((e) => e.y + e.h));
|
|
733
841
|
e = {
|
|
@@ -738,14 +846,23 @@ function Me(e, t, n, r, i) {
|
|
|
738
846
|
t.set(i.id, e), o.push(s);
|
|
739
847
|
}
|
|
740
848
|
}
|
|
741
|
-
async function
|
|
849
|
+
async function Je(e, t, n) {
|
|
742
850
|
try {
|
|
743
|
-
return await
|
|
851
|
+
return await J(e, t);
|
|
744
852
|
} catch (r) {
|
|
745
|
-
return n(r instanceof
|
|
853
|
+
return n(r instanceof q ? r : new q(String(r), { cause: r })), G(e, t);
|
|
746
854
|
}
|
|
747
855
|
}
|
|
748
|
-
function
|
|
856
|
+
function Ye(e) {
|
|
857
|
+
let t = /* @__PURE__ */ new Map(), n = (e, n) => {
|
|
858
|
+
if (!n) return;
|
|
859
|
+
let r = t.get(e);
|
|
860
|
+
r || (r = /* @__PURE__ */ new Set(), t.set(e, r)), r.add(n);
|
|
861
|
+
};
|
|
862
|
+
for (let t of e.relations) t.from.columns.forEach((e) => n(t.from.tableId, e)), t.to.columns.forEach((e) => n(t.to.tableId, e));
|
|
863
|
+
return t;
|
|
864
|
+
}
|
|
865
|
+
function Xe(e, t, n, r) {
|
|
749
866
|
return e.tables.map((e) => ({
|
|
750
867
|
id: e.id,
|
|
751
868
|
type: "table",
|
|
@@ -755,20 +872,31 @@ function Pe(e, t, n) {
|
|
|
755
872
|
},
|
|
756
873
|
data: {
|
|
757
874
|
table: e,
|
|
758
|
-
widthBounds: n
|
|
875
|
+
widthBounds: n,
|
|
876
|
+
connectedColumns: r.get(e.id)
|
|
759
877
|
}
|
|
760
878
|
}));
|
|
761
879
|
}
|
|
762
|
-
function
|
|
880
|
+
function Ze(e, t) {
|
|
881
|
+
let n = e.from.tableId === e.to.tableId, r = n ? !1 : (t.get(e.from.tableId)?.x ?? 0) > (t.get(e.to.tableId)?.x ?? 0), i = r ? "left" : "right", a = n || r ? "right" : "left";
|
|
882
|
+
return {
|
|
883
|
+
sourceHandle: X(e.from.columns[0] ?? "", i, "source"),
|
|
884
|
+
targetHandle: X(e.to.columns[0] ?? "", a, "target")
|
|
885
|
+
};
|
|
886
|
+
}
|
|
887
|
+
function Qe(e, t, n) {
|
|
888
|
+
let r = n === "floating";
|
|
763
889
|
return e.relations.map((e) => {
|
|
764
|
-
let n =
|
|
890
|
+
let n = r ? {
|
|
891
|
+
sourceHandle: void 0,
|
|
892
|
+
targetHandle: void 0
|
|
893
|
+
} : Ze(e, t);
|
|
765
894
|
return {
|
|
766
895
|
id: e.id,
|
|
767
896
|
source: e.from.tableId,
|
|
768
897
|
target: e.to.tableId,
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
type: "erd",
|
|
898
|
+
...n,
|
|
899
|
+
type: r ? "erd-floating" : "erd",
|
|
772
900
|
data: {
|
|
773
901
|
kind: e.kind,
|
|
774
902
|
sourceEnd: {
|
|
@@ -783,26 +911,26 @@ function Fe(e, t) {
|
|
|
783
911
|
};
|
|
784
912
|
});
|
|
785
913
|
}
|
|
786
|
-
var
|
|
787
|
-
let
|
|
914
|
+
var $e = t(function({ dbml: e, className: t, style: n, theme: i, fitView: l = !0, showControls: p = !0, showMiniMap: h = !1, showBackground: te = !0, layoutOptions: re, edgeConnection: g = "column", onParseError: _, onLayoutError: v, nodePositions: x, onNodePositionsChange: S }, oe) {
|
|
915
|
+
let C = s(() => {
|
|
788
916
|
try {
|
|
789
917
|
return {
|
|
790
918
|
ok: !0,
|
|
791
|
-
schema:
|
|
919
|
+
schema: A(e)
|
|
792
920
|
};
|
|
793
921
|
} catch (e) {
|
|
794
922
|
return {
|
|
795
923
|
ok: !1,
|
|
796
|
-
error: e instanceof
|
|
924
|
+
error: e instanceof w ? e : new w(String(e), { cause: e })
|
|
797
925
|
};
|
|
798
926
|
}
|
|
799
|
-
}, [e]), [
|
|
800
|
-
|
|
927
|
+
}, [e]), [T, E, D] = ae([]), [O, k, se] = ie([]), j = c(null), M = c(null), N = c(T);
|
|
928
|
+
N.current = T, o(oe, () => {
|
|
801
929
|
let e = async (e) => {
|
|
802
|
-
let t =
|
|
930
|
+
let t = j.current, n = M.current?.querySelector(".react-flow__viewport");
|
|
803
931
|
if (!t || !n) throw new Y("The diagram is not ready to export yet.");
|
|
804
|
-
let r =
|
|
805
|
-
return
|
|
932
|
+
let r = de(ne(t.getNodes()), n), i = e?.backgroundColor ?? (M.current ? getComputedStyle(M.current).backgroundColor : void 0);
|
|
933
|
+
return fe(n, r, {
|
|
806
934
|
...e,
|
|
807
935
|
backgroundColor: i
|
|
808
936
|
});
|
|
@@ -810,183 +938,190 @@ var Ie = e(function({ dbml: e, className: t, style: s, theme: d, fitView: p = !0
|
|
|
810
938
|
return {
|
|
811
939
|
toDataUrl: e,
|
|
812
940
|
download: async (t, n) => {
|
|
813
|
-
|
|
941
|
+
me(await e(n), t);
|
|
814
942
|
},
|
|
815
|
-
fitView: (e) =>
|
|
816
|
-
zoomIn: (e) =>
|
|
817
|
-
zoomOut: (e) =>
|
|
818
|
-
zoomTo: (e, t) =>
|
|
819
|
-
setCenter: (e, t, n) =>
|
|
820
|
-
fitBounds: (e, t) =>
|
|
821
|
-
setViewport: (e, t) =>
|
|
822
|
-
getViewport: () =>
|
|
943
|
+
fitView: (e) => j.current?.fitView(e),
|
|
944
|
+
zoomIn: (e) => j.current?.zoomIn(e),
|
|
945
|
+
zoomOut: (e) => j.current?.zoomOut(e),
|
|
946
|
+
zoomTo: (e, t) => j.current?.zoomTo(e, t),
|
|
947
|
+
setCenter: (e, t, n) => j.current?.setCenter(e, t, n),
|
|
948
|
+
fitBounds: (e, t) => j.current?.fitBounds(e, t),
|
|
949
|
+
setViewport: (e, t) => j.current?.setViewport(e, t),
|
|
950
|
+
getViewport: () => j.current?.getViewport()
|
|
823
951
|
};
|
|
824
952
|
}, []);
|
|
825
|
-
let
|
|
826
|
-
|
|
827
|
-
let
|
|
828
|
-
|
|
829
|
-
let
|
|
830
|
-
|
|
831
|
-
let
|
|
832
|
-
let e =
|
|
953
|
+
let P = c(v);
|
|
954
|
+
P.current = v;
|
|
955
|
+
let F = c(S);
|
|
956
|
+
F.current = S;
|
|
957
|
+
let I = c(x);
|
|
958
|
+
I.current = x;
|
|
959
|
+
let ce = r(() => {
|
|
960
|
+
let e = F.current;
|
|
833
961
|
if (!e) return;
|
|
834
962
|
let t = {};
|
|
835
|
-
for (let e of
|
|
963
|
+
for (let e of N.current) t[e.id] = {
|
|
836
964
|
x: e.position.x,
|
|
837
965
|
y: e.position.y
|
|
838
966
|
};
|
|
839
967
|
e(t);
|
|
840
|
-
}, []), { algorithm:
|
|
968
|
+
}, []), { algorithm: L = "simple", direction: R = "LR", horizontalGap: z, verticalGap: B, minNodeWidth: V, maxNodeWidth: H } = re ?? {}, U = c(null), W = `${L}|${R}|${z}|${B}|${V}|${H}`, G = r((e, t, n, r, i) => {
|
|
841
969
|
let a = {
|
|
842
|
-
minWidth:
|
|
843
|
-
maxWidth:
|
|
844
|
-
}, o =
|
|
970
|
+
minWidth: V,
|
|
971
|
+
maxWidth: H
|
|
972
|
+
}, o = We(e, r, i.saved, i.prior);
|
|
845
973
|
if (i.prior) {
|
|
846
974
|
let t = i.prior, n = i.saved;
|
|
847
|
-
|
|
975
|
+
qe(e, o, (e) => t.has(e) || n?.[e] !== void 0, B ?? 40, a);
|
|
848
976
|
}
|
|
849
|
-
if (
|
|
977
|
+
if (E(Xe(e, o, a, Ye(e))), k(Qe(e, o, g)), U.current = {
|
|
850
978
|
ids: t,
|
|
851
979
|
optionsKey: n
|
|
852
980
|
}, i.emit) {
|
|
853
981
|
let e = {};
|
|
854
982
|
o.forEach((t, n) => {
|
|
855
983
|
e[n] = t;
|
|
856
|
-
}),
|
|
984
|
+
}), F.current?.(e);
|
|
857
985
|
}
|
|
858
|
-
i.fit && requestAnimationFrame(() => void
|
|
986
|
+
i.fit && requestAnimationFrame(() => void j.current?.fitView());
|
|
859
987
|
}, [
|
|
860
|
-
|
|
861
|
-
|
|
988
|
+
E,
|
|
989
|
+
k,
|
|
990
|
+
B,
|
|
862
991
|
V,
|
|
863
992
|
H,
|
|
864
|
-
|
|
993
|
+
g
|
|
865
994
|
]);
|
|
866
|
-
|
|
867
|
-
if (!
|
|
868
|
-
|
|
995
|
+
a(() => {
|
|
996
|
+
if (!C.ok) {
|
|
997
|
+
E([]), k([]), U.current = null;
|
|
869
998
|
return;
|
|
870
999
|
}
|
|
871
|
-
let e =
|
|
872
|
-
algorithm:
|
|
873
|
-
direction:
|
|
874
|
-
horizontalGap:
|
|
875
|
-
verticalGap:
|
|
876
|
-
minNodeWidth:
|
|
877
|
-
maxNodeWidth:
|
|
878
|
-
}, n = e.tables.map((e) => e.id), r = new Map(
|
|
1000
|
+
let e = C.schema, t = {
|
|
1001
|
+
algorithm: L,
|
|
1002
|
+
direction: R,
|
|
1003
|
+
horizontalGap: z,
|
|
1004
|
+
verticalGap: B,
|
|
1005
|
+
minNodeWidth: V,
|
|
1006
|
+
maxNodeWidth: H
|
|
1007
|
+
}, n = e.tables.map((e) => e.id), r = new Map(N.current.map((e) => [e.id, {
|
|
879
1008
|
x: e.position.x,
|
|
880
1009
|
y: e.position.y
|
|
881
|
-
}])), i =
|
|
882
|
-
if (i && i.optionsKey ===
|
|
883
|
-
|
|
1010
|
+
}])), i = U.current, a = n.every((e) => r.has(e));
|
|
1011
|
+
if (i && i.optionsKey === W && a && Ge(i.ids, n)) {
|
|
1012
|
+
G(e, n, W, /* @__PURE__ */ new Map(), { prior: r });
|
|
884
1013
|
return;
|
|
885
1014
|
}
|
|
886
|
-
let o = i && i.optionsKey ===
|
|
887
|
-
return
|
|
888
|
-
s ||
|
|
889
|
-
saved:
|
|
1015
|
+
let o = i && i.optionsKey === W ? r : void 0, s = !1;
|
|
1016
|
+
return Je(e, t, (e) => P.current?.(e)).then((t) => {
|
|
1017
|
+
s || G(e, n, W, t, {
|
|
1018
|
+
saved: I.current,
|
|
890
1019
|
prior: o,
|
|
891
|
-
fit:
|
|
1020
|
+
fit: l
|
|
892
1021
|
});
|
|
893
1022
|
}), () => {
|
|
894
1023
|
s = !0;
|
|
895
1024
|
};
|
|
896
1025
|
}, [
|
|
897
|
-
|
|
1026
|
+
C,
|
|
1027
|
+
L,
|
|
898
1028
|
R,
|
|
899
1029
|
z,
|
|
900
1030
|
B,
|
|
901
1031
|
V,
|
|
902
1032
|
H,
|
|
903
|
-
|
|
1033
|
+
W,
|
|
1034
|
+
l,
|
|
904
1035
|
G,
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
O,
|
|
908
|
-
A
|
|
1036
|
+
E,
|
|
1037
|
+
k
|
|
909
1038
|
]);
|
|
910
|
-
let
|
|
911
|
-
if (!
|
|
912
|
-
let e =
|
|
913
|
-
algorithm:
|
|
914
|
-
direction:
|
|
915
|
-
horizontalGap:
|
|
916
|
-
verticalGap:
|
|
917
|
-
minNodeWidth:
|
|
918
|
-
maxNodeWidth:
|
|
1039
|
+
let le = r(() => {
|
|
1040
|
+
if (!C.ok) return;
|
|
1041
|
+
let e = C.schema, t = {
|
|
1042
|
+
algorithm: L,
|
|
1043
|
+
direction: R,
|
|
1044
|
+
horizontalGap: z,
|
|
1045
|
+
verticalGap: B,
|
|
1046
|
+
minNodeWidth: V,
|
|
1047
|
+
maxNodeWidth: H
|
|
919
1048
|
}, n = e.tables.map((e) => e.id);
|
|
920
|
-
|
|
921
|
-
|
|
1049
|
+
Je(e, t, (e) => P.current?.(e)).then((t) => {
|
|
1050
|
+
G(e, n, W, t, {
|
|
922
1051
|
emit: !0,
|
|
923
1052
|
fit: !0
|
|
924
1053
|
});
|
|
925
1054
|
});
|
|
926
1055
|
}, [
|
|
927
|
-
|
|
1056
|
+
C,
|
|
1057
|
+
L,
|
|
928
1058
|
R,
|
|
929
1059
|
z,
|
|
930
1060
|
B,
|
|
931
1061
|
V,
|
|
932
1062
|
H,
|
|
933
|
-
|
|
934
|
-
G
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
let { displayNodes: le, displayEdges: X, onEdgeMouseEnter: de, onEdgeMouseLeave: fe } = be(E.ok ? E.schema.relations : Te, D, ae), Z = {
|
|
1063
|
+
W,
|
|
1064
|
+
G
|
|
1065
|
+
]), K = r(() => {
|
|
1066
|
+
C.ok || _?.(C.error);
|
|
1067
|
+
}, [C, _]);
|
|
1068
|
+
a(K, [K]);
|
|
1069
|
+
let { displayNodes: q, displayEdges: J, onEdgeMouseEnter: ue, onEdgeMouseLeave: pe, onColumnHover: X } = Fe(C.ok ? C.schema.relations : Be, T, O), Z = {
|
|
941
1070
|
width: "100%",
|
|
942
1071
|
height: "100%",
|
|
943
|
-
...
|
|
944
|
-
...
|
|
1072
|
+
...ze(i),
|
|
1073
|
+
...n
|
|
945
1074
|
};
|
|
946
|
-
return
|
|
947
|
-
ref:
|
|
1075
|
+
return C.ok ? /* @__PURE__ */ y("div", {
|
|
1076
|
+
ref: M,
|
|
948
1077
|
className: `dv-viewer${t ? ` ${t}` : ""}`,
|
|
949
1078
|
style: Z,
|
|
950
|
-
children: /* @__PURE__ */
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
1079
|
+
children: /* @__PURE__ */ y(ge.Provider, {
|
|
1080
|
+
value: g,
|
|
1081
|
+
children: /* @__PURE__ */ y(he.Provider, {
|
|
1082
|
+
value: X,
|
|
1083
|
+
children: /* @__PURE__ */ b(ee, {
|
|
1084
|
+
nodes: q,
|
|
1085
|
+
edges: J,
|
|
1086
|
+
nodeTypes: Ve,
|
|
1087
|
+
edgeTypes: He,
|
|
1088
|
+
onNodesChange: D,
|
|
1089
|
+
onEdgesChange: se,
|
|
1090
|
+
onEdgeMouseEnter: ue,
|
|
1091
|
+
onEdgeMouseLeave: pe,
|
|
1092
|
+
onNodeDragStop: ce,
|
|
1093
|
+
onInit: (e) => {
|
|
1094
|
+
j.current = e;
|
|
1095
|
+
},
|
|
1096
|
+
fitView: l,
|
|
1097
|
+
nodesConnectable: !1,
|
|
1098
|
+
elementsSelectable: !0,
|
|
1099
|
+
minZoom: .1,
|
|
1100
|
+
proOptions: { hideAttribution: !0 },
|
|
1101
|
+
children: [
|
|
1102
|
+
te && /* @__PURE__ */ y(u, {}),
|
|
1103
|
+
p && /* @__PURE__ */ y(f, { children: /* @__PURE__ */ y(d, {
|
|
1104
|
+
onClick: le,
|
|
1105
|
+
title: "Auto layout",
|
|
1106
|
+
"aria-label": "Auto layout",
|
|
1107
|
+
children: /* @__PURE__ */ y(Ue, {})
|
|
1108
|
+
}) }),
|
|
1109
|
+
h && /* @__PURE__ */ y(m, {
|
|
1110
|
+
pannable: !0,
|
|
1111
|
+
zoomable: !0
|
|
1112
|
+
})
|
|
1113
|
+
]
|
|
979
1114
|
})
|
|
980
|
-
|
|
1115
|
+
})
|
|
981
1116
|
})
|
|
982
|
-
}) : /* @__PURE__ */
|
|
1117
|
+
}) : /* @__PURE__ */ y("div", {
|
|
983
1118
|
className: `dv-error${t ? ` ${t}` : ""}`,
|
|
984
1119
|
style: Z,
|
|
985
|
-
children: /* @__PURE__ */
|
|
1120
|
+
children: /* @__PURE__ */ y("pre", {
|
|
986
1121
|
className: "dv-error__message",
|
|
987
|
-
children:
|
|
1122
|
+
children: C.error.message
|
|
988
1123
|
})
|
|
989
1124
|
});
|
|
990
1125
|
});
|
|
991
1126
|
//#endregion
|
|
992
|
-
export {
|
|
1127
|
+
export { w as DbmlParseError, $e as DbmlViewer, ke as ErdEdge, Y as ExportError, N as HEADER_HEIGHT, q as LayoutError, j as MAX_NODE_WIDTH, se as MIN_NODE_WIDTH, M as NODE_WIDTH, P as ROW_HEIGHT, be as TableNode, J as computeLayout, Re as darkTheme, me as downloadDataUrl, G as layoutSchema, Le as lightTheme, A as parseDbml, fe as renderDiagram, F as tableHeight, H as tableWidth, ze as themeToCssVars };
|