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.
@@ -1,17 +1,17 @@
1
- import { forwardRef as e, memo as t, useCallback as n, useEffect as r, useImperativeHandle as i, useMemo as a, useRef as o, useState as s } from "react";
2
- import { Background as c, ControlButton as l, Controls as u, Handle as d, MiniMap as f, Position as p, ReactFlow as ee, getNodesBounds as te, getSmoothStepPath as m, useEdgesState as ne, useNodesState as re } from "@xyflow/react";
3
- import * as h from "@dbml/core";
4
- import { Fragment as g, jsx as _, jsxs as v } from "react/jsx-runtime";
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 y = h, b = y.Parser ?? y.default?.Parser;
7
- if (!b) throw Error("Could not resolve `Parser` export from @dbml/core.");
8
- var x = b, S = "public", C = class extends Error {
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 w(e) {
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 T(e, t) {
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 E(e) {
28
+ function D(e) {
29
29
  if (e) return typeof e == "string" ? e : e.value ?? void 0;
30
30
  }
31
- function D(e, t) {
32
- return e && e !== S ? `${e}.${t}` : t;
31
+ function O(e, t) {
32
+ return e && e !== C ? `${e}.${t}` : t;
33
33
  }
34
- function O(e) {
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 ie(e) {
40
+ function A(e) {
41
41
  let t;
42
42
  try {
43
- t = new x().parse(e, "dbmlv2");
43
+ t = new oe().parse(e, "dbmlv2");
44
44
  } catch (e) {
45
- let t = w(e);
46
- throw new C(T(t, e instanceof Error ? e.message : String(e)), {
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 = D(e.name, t.name), i = O(t), a = /* @__PURE__ */ new Map();
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: E(e.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: D(t.schemaName ?? e.name, t.tableName),
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 = D(t, n.name), r = O(n), i = n.fields.map((t) => ({
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: E(t.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 === S ? void 0 : t,
116
- note: E(n.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 k = 160, ae = 320, A = 320, j = 40, M = 28;
130
- function N(e) {
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 P = 24, F = 8, I = 24, L = 12, oe = 24, R = 6.8, z = 7.4;
134
- function B(e, t = {}) {
135
- let n = t.minWidth ?? 160, r = t.maxWidth ?? 320, i = oe + V(e) * z;
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 ? I : 0) + t.name.length * R, n = t.type.length * R + L;
138
- i = Math.max(i, P + e + F + n);
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 V(e) {
142
+ function U(e) {
143
143
  return (e.schema ? e.schema.length + 1 : 0) + e.name.length;
144
144
  }
145
- function H(e) {
146
- let t = /* @__PURE__ */ new Map();
147
- for (let n of e.tables) t.set(n.id, 0);
148
- let n = e.relations.map((e) => [e.from.tableId, e.to.tableId]).filter(([e, n]) => e !== n && t.has(e) && t.has(n));
149
- for (let r = 0; r < e.tables.length; r++) {
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 [r, i] of n) {
152
- let n = t.get(r) + 1;
153
- t.get(i) < n && (t.set(i, n), e = !0);
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 t;
157
+ return n;
158
158
  }
159
- function U(e, t = {}) {
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 = H(e), o = /* @__PURE__ */ new Map();
164
- for (let t of e.tables) {
165
- let e = a.get(t.id) ?? 0, n = o.get(e);
166
- n || (n = [], o.set(e, n)), n.push(t);
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 s = /* @__PURE__ */ new Map(), c = [...o.keys()].sort((e, t) => e - t), l = 0;
169
- for (let e of c) {
170
- let t = o.get(e).sort((e, t) => e.name.localeCompare(t.name)), a = 0, c = 0;
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 = B(e, i), n = N(e);
173
- s.set(e.id, {
174
- x: l,
175
- y: c,
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), c += n + r;
180
+ }), a = Math.max(a, t), o += n + r;
179
181
  }
180
- l += a + n;
182
+ d = Math.max(d, p + a), f = Math.max(f, o - r), p += a + n;
181
183
  }
182
- return s;
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 W(e, t = {}) {
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: B(t, a),
198
- height: N(t)
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 G(e, t = {}) {
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: B(e, a),
231
- height: N(e)
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 K = class extends Error {
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 q(e, t = {}) {
268
+ async function J(e, t = {}) {
255
269
  let n = t.algorithm ?? "simple";
256
- if (n === "simple") return U(e, t);
270
+ if (n === "simple") return G(e, t);
257
271
  try {
258
- return n === "dagre" ? await W(e, t) : await G(e, t);
272
+ return n === "dagre" ? await le(e, t) : await K(e, t);
259
273
  } catch (e) {
260
- throw new K(`"${n}" layout failed. Is the optional dependency "${n === "dagre" ? "@dagrejs/dagre" : "elkjs"}" installed? (${e instanceof Error ? e.message : String(e)})`, { cause: e });
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 J = [
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 se(e, t) {
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 ce(e, t, n = {}) {
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 = le(e, t, i);
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 le(e, t, n) {
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 J) {
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 ue(e, t) {
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/TableNode.tsx
368
- function de(e) {
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
- function fe({ column: e, top: t }) {
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(g, { children: [
377
- /* @__PURE__ */ _(d, {
395
+ return /* @__PURE__ */ b(v, { children: [
396
+ /* @__PURE__ */ y(p, {
378
397
  id: X(e, "left", "target"),
379
398
  type: "target",
380
- position: p.Left,
381
- style: n,
399
+ position: h.Left,
400
+ style: r,
382
401
  isConnectable: !1
383
402
  }),
384
- /* @__PURE__ */ _(d, {
403
+ /* @__PURE__ */ y(p, {
385
404
  id: X(e, "left", "source"),
386
405
  type: "source",
387
- position: p.Left,
406
+ position: h.Left,
388
407
  style: n,
389
408
  isConnectable: !1
390
409
  }),
391
- /* @__PURE__ */ _(d, {
410
+ /* @__PURE__ */ y(p, {
392
411
  id: X(e, "right", "target"),
393
412
  type: "target",
394
- position: p.Right,
395
- style: n,
413
+ position: h.Right,
414
+ style: r,
396
415
  isConnectable: !1
397
416
  }),
398
- /* @__PURE__ */ _(d, {
417
+ /* @__PURE__ */ y(p, {
399
418
  id: X(e, "right", "source"),
400
419
  type: "source",
401
- position: p.Right,
420
+ position: h.Right,
402
421
  style: n,
403
422
  isConnectable: !1
404
423
  })
405
424
  ] });
406
425
  }
407
- function Z({ data: e }) {
408
- let { table: t, highlightedColumns: n, widthBounds: r } = e;
409
- return /* @__PURE__ */ v("div", {
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: B(t, r) },
412
- children: [/* @__PURE__ */ v("div", {
413
- className: "dv-table__header",
414
- style: t.headerColor ? {
415
- background: t.headerColor,
416
- height: 40
417
- } : { height: 40 },
418
- title: t.note,
419
- children: [t.schema && /* @__PURE__ */ v("span", {
420
- className: "dv-table__schema",
421
- children: [t.schema, "."]
422
- }), /* @__PURE__ */ _("span", {
423
- className: "dv-table__name",
424
- title: t.name,
425
- children: t.name
426
- })]
427
- }), /* @__PURE__ */ _("div", {
428
- className: "dv-table__body",
429
- children: t.columns.map((e, t) => {
430
- let r = n?.has(e.name);
431
- return /* @__PURE__ */ v("div", {
432
- className: `dv-row${r ? " dv-row--highlighted" : ""}`,
433
- style: { height: 28 },
434
- title: e.note,
435
- children: [
436
- /* @__PURE__ */ v("span", {
437
- className: `dv-row__name${e.pk ? " dv-row__name--pk" : ""}`,
438
- children: [
439
- e.pk && /* @__PURE__ */ _("span", {
440
- className: "dv-badge dv-badge--pk",
441
- title: "Primary key",
442
- children: "PK"
443
- }),
444
- e.isForeignKey && !e.pk && /* @__PURE__ */ _("span", {
445
- className: "dv-badge dv-badge--fk",
446
- title: "Foreign key",
447
- children: "FK"
448
- }),
449
- /* @__PURE__ */ _("span", {
450
- className: "dv-row__label",
451
- title: e.name,
452
- children: e.name
453
- })
454
- ]
455
- }),
456
- /* @__PURE__ */ v("span", {
457
- className: "dv-row__type",
458
- children: [/* @__PURE__ */ _("span", {
459
- className: "dv-row__typename",
460
- title: e.type,
461
- children: e.type
462
- }), /* @__PURE__ */ _("span", {
463
- className: `dv-row__null${e.notNull ? " dv-row__null--notnull" : ""}`,
464
- title: e.notNull ? "Not null" : "Nullable"
465
- })]
466
- }),
467
- /* @__PURE__ */ _(fe, {
468
- column: e.name,
469
- top: de(t)
470
- })
471
- ]
472
- }, e.name);
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 Q = t(Z), $ = 8, pe = 13, me = 7, he = 13, ge = 16;
478
- function _e(e, t, n, r, i, a) {
479
- let o = -(n === p.Left ? 1 : -1), s = [], c = {
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
- }, l = (n, r) => s.push(/* @__PURE__ */ _("line", {
483
- x1: e + o * n,
484
- y1: t - $,
485
- x2: e + o * n,
486
- y2: t + $,
487
- style: c
488
- }, r)), u = (n, r) => s.push(/* @__PURE__ */ _("circle", {
489
- cx: e + o * n,
490
- cy: t,
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
- }, r));
498
- if (r.cardinality === "*") {
499
- let n = e + o * pe;
500
- s.push(/* @__PURE__ */ _("line", {
501
- x1: n,
502
- y1: t,
503
- x2: e,
504
- y2: t - $,
505
- style: c
506
- }, "cf1"), /* @__PURE__ */ _("line", {
507
- x1: n,
508
- y1: t,
509
- x2: e,
510
- y2: t,
511
- style: c
512
- }, "cf2"), /* @__PURE__ */ _("line", {
513
- x1: n,
514
- y1: t,
515
- x2: e,
516
- y2: t + $,
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
- children: s
558
+ transform: `translate(${e}, ${t}) rotate(${Te[n]})`,
559
+ children: o
523
560
  });
524
561
  }
525
- function ve({ sourceX: e, sourceY: t, targetX: n, targetY: r, sourcePosition: i, targetPosition: a, data: o, selected: s }) {
526
- let [c] = m({
527
- sourceX: e,
528
- sourceY: t,
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__ */ _("path", {
567
+ /* @__PURE__ */ y("path", {
539
568
  className: "dv-erd-edge__interaction",
540
- d: c,
569
+ d: e,
541
570
  fill: "none"
542
571
  }),
543
- /* @__PURE__ */ _("path", {
572
+ /* @__PURE__ */ y("path", {
544
573
  className: "dv-erd-edge__path",
545
- d: c,
574
+ d: e,
546
575
  fill: "none",
547
576
  style: {
548
- stroke: f,
549
- strokeWidth: p
577
+ stroke: u,
578
+ strokeWidth: d
550
579
  },
551
- strokeDasharray: u ? "6 4" : void 0
580
+ strokeDasharray: l ? "6 4" : void 0
552
581
  }),
553
- l && _e(e, t, i, l.sourceEnd, f, p),
554
- l && _e(n, r, a, l.targetEnd, f, p)
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
- var ye = t(ve);
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 be(e, t, r) {
562
- let [i, o] = s(null), c = a(() => {
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]), l = a(() => {
567
- let e = /* @__PURE__ */ new Map(), t = i ? c.get(i) : void 0;
568
- if (!t) return e;
569
- for (let n of [t.from, t.to]) {
570
- let t = e.get(n.tableId) ?? /* @__PURE__ */ new Set();
571
- n.columns.forEach((e) => t.add(e)), e.set(n.tableId, t);
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
- }, [i, c]);
673
+ }, [d, u]), p = r((e, t) => {
674
+ c(t ? {
675
+ tableId: e,
676
+ column: t
677
+ } : null);
678
+ }, []);
575
679
  return {
576
- displayNodes: a(() => i ? t.map((e) => {
577
- let t = l.get(e.id);
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
- }) : t, [
689
+ }), [
586
690
  t,
587
- i,
588
- l
691
+ d,
692
+ f
589
693
  ]),
590
- displayEdges: a(() => i ? r.map((e) => e.id === i ? {
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) : r, [r, i]),
598
- onEdgeMouseEnter: n((e, t) => o(t.id), []),
599
- onEdgeMouseLeave: n(() => o(null), [])
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 xe = {
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
- }, Se = {
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
- }, Ce = {
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 we(e) {
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[xe[n]] = r);
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 Te = [], Ee = { table: Q }, De = { erd: ye };
660
- function Oe() {
661
- return /* @__PURE__ */ v("svg", {
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__ */ _("rect", {
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__ */ _("rect", {
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__ */ _("rect", {
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__ */ _("rect", {
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 ke(e, t, n, r) {
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 Ae(e, t) {
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 je(e, t, n) {
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 Me(e, t, n, r, i) {
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: B(e, i),
723
- h: N(e)
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) => je(s, e, r));
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 Ne(e, t, n) {
849
+ async function Je(e, t, n) {
742
850
  try {
743
- return await q(e, t);
851
+ return await J(e, t);
744
852
  } catch (r) {
745
- return n(r instanceof K ? r : new K(String(r), { cause: r })), U(e, t);
853
+ return n(r instanceof q ? r : new q(String(r), { cause: r })), G(e, t);
746
854
  }
747
855
  }
748
- function Pe(e, t, n) {
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 Fe(e, t) {
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 = t.get(e.from.tableId), r = t.get(e.to.tableId), i = (n?.x ?? 0) > (r?.x ?? 0), a = i ? "left" : "right", o = i ? "right" : "left", s = e.from.columns[0] ?? "", c = e.to.columns[0] ?? "";
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
- sourceHandle: X(s, a, "source"),
770
- targetHandle: X(c, o, "target"),
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 Ie = e(function({ dbml: e, className: t, style: s, theme: d, fitView: p = !0, showControls: m = !0, showMiniMap: h = !1, showBackground: g = !0, layoutOptions: y, onParseError: b, onLayoutError: x, nodePositions: S, onNodePositionsChange: w }, T) {
787
- let E = a(() => {
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: ie(e)
919
+ schema: A(e)
792
920
  };
793
921
  } catch (e) {
794
922
  return {
795
923
  ok: !1,
796
- error: e instanceof C ? e : new C(String(e), { cause: e })
924
+ error: e instanceof w ? e : new w(String(e), { cause: e })
797
925
  };
798
926
  }
799
- }, [e]), [D, O, k] = re([]), [ae, A, j] = ne([]), M = o(null), N = o(null), P = o(D);
800
- P.current = D, i(T, () => {
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 = M.current, n = N.current?.querySelector(".react-flow__viewport");
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 = se(te(t.getNodes()), n), i = e?.backgroundColor ?? (N.current ? getComputedStyle(N.current).backgroundColor : void 0);
805
- return ce(n, r, {
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
- ue(await e(n), t);
941
+ me(await e(n), t);
814
942
  },
815
- fitView: (e) => M.current?.fitView(e),
816
- zoomIn: (e) => M.current?.zoomIn(e),
817
- zoomOut: (e) => M.current?.zoomOut(e),
818
- zoomTo: (e, t) => M.current?.zoomTo(e, t),
819
- setCenter: (e, t, n) => M.current?.setCenter(e, t, n),
820
- fitBounds: (e, t) => M.current?.fitBounds(e, t),
821
- setViewport: (e, t) => M.current?.setViewport(e, t),
822
- getViewport: () => M.current?.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 F = o(x);
826
- F.current = x;
827
- let I = o(w);
828
- I.current = w;
829
- let L = o(S);
830
- L.current = S;
831
- let oe = n(() => {
832
- let e = I.current;
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 P.current) t[e.id] = {
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: R = "simple", direction: z = "LR", horizontalGap: B, verticalGap: V, minNodeWidth: H, maxNodeWidth: U } = y ?? {}, W = o(null), G = `${R}|${z}|${B}|${V}|${H}|${U}`, K = n((e, t, n, r, i) => {
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: H,
843
- maxWidth: U
844
- }, o = ke(e, r, i.saved, i.prior);
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
- Me(e, o, (e) => t.has(e) || n?.[e] !== void 0, V ?? 40, a);
975
+ qe(e, o, (e) => t.has(e) || n?.[e] !== void 0, B ?? 40, a);
848
976
  }
849
- if (O(Pe(e, o, a)), A(Fe(e, o)), W.current = {
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
- }), I.current?.(e);
984
+ }), F.current?.(e);
857
985
  }
858
- i.fit && requestAnimationFrame(() => void M.current?.fitView());
986
+ i.fit && requestAnimationFrame(() => void j.current?.fitView());
859
987
  }, [
860
- O,
861
- A,
988
+ E,
989
+ k,
990
+ B,
862
991
  V,
863
992
  H,
864
- U
993
+ g
865
994
  ]);
866
- r(() => {
867
- if (!E.ok) {
868
- O([]), A([]), W.current = null;
995
+ a(() => {
996
+ if (!C.ok) {
997
+ E([]), k([]), U.current = null;
869
998
  return;
870
999
  }
871
- let e = E.schema, t = {
872
- algorithm: R,
873
- direction: z,
874
- horizontalGap: B,
875
- verticalGap: V,
876
- minNodeWidth: H,
877
- maxNodeWidth: U
878
- }, n = e.tables.map((e) => e.id), r = new Map(P.current.map((e) => [e.id, {
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 = W.current, a = n.every((e) => r.has(e));
882
- if (i && i.optionsKey === G && a && Ae(i.ids, n)) {
883
- K(e, n, G, /* @__PURE__ */ new Map(), { prior: r });
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 === G ? r : void 0, s = !1;
887
- return Ne(e, t, (e) => F.current?.(e)).then((t) => {
888
- s || K(e, n, G, t, {
889
- saved: L.current,
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: p
1020
+ fit: l
892
1021
  });
893
1022
  }), () => {
894
1023
  s = !0;
895
1024
  };
896
1025
  }, [
897
- E,
1026
+ C,
1027
+ L,
898
1028
  R,
899
1029
  z,
900
1030
  B,
901
1031
  V,
902
1032
  H,
903
- U,
1033
+ W,
1034
+ l,
904
1035
  G,
905
- p,
906
- K,
907
- O,
908
- A
1036
+ E,
1037
+ k
909
1038
  ]);
910
- let q = n(() => {
911
- if (!E.ok) return;
912
- let e = E.schema, t = {
913
- algorithm: R,
914
- direction: z,
915
- horizontalGap: B,
916
- verticalGap: V,
917
- minNodeWidth: H,
918
- maxNodeWidth: U
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
- Ne(e, t, (e) => F.current?.(e)).then((t) => {
921
- K(e, n, G, t, {
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
- E,
1056
+ C,
1057
+ L,
928
1058
  R,
929
1059
  z,
930
1060
  B,
931
1061
  V,
932
1062
  H,
933
- U,
934
- G,
935
- K
936
- ]), J = n(() => {
937
- E.ok || b?.(E.error);
938
- }, [E, b]);
939
- r(J, [J]);
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
- ...we(d),
944
- ...s
1072
+ ...ze(i),
1073
+ ...n
945
1074
  };
946
- return E.ok ? /* @__PURE__ */ _("div", {
947
- ref: N,
1075
+ return C.ok ? /* @__PURE__ */ y("div", {
1076
+ ref: M,
948
1077
  className: `dv-viewer${t ? ` ${t}` : ""}`,
949
1078
  style: Z,
950
- children: /* @__PURE__ */ v(ee, {
951
- nodes: le,
952
- edges: X,
953
- nodeTypes: Ee,
954
- edgeTypes: De,
955
- onNodesChange: k,
956
- onEdgesChange: j,
957
- onEdgeMouseEnter: de,
958
- onEdgeMouseLeave: fe,
959
- onNodeDragStop: oe,
960
- onInit: (e) => {
961
- M.current = e;
962
- },
963
- fitView: p,
964
- nodesConnectable: !1,
965
- elementsSelectable: !0,
966
- minZoom: .1,
967
- proOptions: { hideAttribution: !0 },
968
- children: [
969
- g && /* @__PURE__ */ _(c, {}),
970
- m && /* @__PURE__ */ _(u, { children: /* @__PURE__ */ _(l, {
971
- onClick: q,
972
- title: "Auto layout",
973
- "aria-label": "Auto layout",
974
- children: /* @__PURE__ */ _(Oe, {})
975
- }) }),
976
- h && /* @__PURE__ */ _(f, {
977
- pannable: !0,
978
- zoomable: !0
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__ */ _("div", {
1117
+ }) : /* @__PURE__ */ y("div", {
983
1118
  className: `dv-error${t ? ` ${t}` : ""}`,
984
1119
  style: Z,
985
- children: /* @__PURE__ */ _("pre", {
1120
+ children: /* @__PURE__ */ y("pre", {
986
1121
  className: "dv-error__message",
987
- children: E.error.message
1122
+ children: C.error.message
988
1123
  })
989
1124
  });
990
1125
  });
991
1126
  //#endregion
992
- export { C as DbmlParseError, Ie as DbmlViewer, ye as ErdEdge, Y as ExportError, j as HEADER_HEIGHT, K as LayoutError, ae as MAX_NODE_WIDTH, k as MIN_NODE_WIDTH, A as NODE_WIDTH, M as ROW_HEIGHT, Q as TableNode, q as computeLayout, Ce as darkTheme, ue as downloadDataUrl, U as layoutSchema, Se as lightTheme, ie as parseDbml, ce as renderDiagram, N as tableHeight, B as tableWidth, we as themeToCssVars };
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 };