dbml-erd-viewer 0.1.0 → 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 ie from "@dbml/core";
4
- import { Fragment as h, jsx as g, jsxs as _ } 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 v = ie, y = v.Parser ?? v.default?.Parser;
7
- if (!y) throw Error("Could not resolve `Parser` export from @dbml/core.");
8
- var b = y, x = "public", S = 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 C(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 C(e) {
20
20
  code: e.code
21
21
  })) : [];
22
22
  }
23
- function w(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 T(e) {
28
+ function D(e) {
29
29
  if (e) return typeof e == "string" ? e : e.value ?? void 0;
30
30
  }
31
- function E(e, t) {
32
- return e && e !== x ? `${e}.${t}` : t;
31
+ function O(e, t) {
32
+ return e && e !== C ? `${e}.${t}` : t;
33
33
  }
34
- function D(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 O(e) {
40
+ function A(e) {
41
41
  let t;
42
42
  try {
43
- t = new b().parse(e, "dbmlv2");
43
+ t = new oe().parse(e, "dbmlv2");
44
44
  } catch (e) {
45
- let t = C(e);
46
- throw new S(w(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 = E(e.name, t.name), i = D(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: T(e.note)
59
+ note: D(e.note)
60
60
  });
61
61
  }
62
62
  n.set(r, a);
@@ -71,7 +71,7 @@ function O(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: E(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 O(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 = E(t, n.name), r = D(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 O(e) {
106
106
  unique: !!t.unique,
107
107
  increment: !!t.increment,
108
108
  defaultValue: t.dbdefault?.value,
109
- note: T(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 === x ? void 0 : t,
116
- note: T(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,75 +126,112 @@ function O(e) {
126
126
  }
127
127
  //#endregion
128
128
  //#region src/layout/layout.ts
129
- var k = 240, A = 40, j = 28;
130
- function M(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
- function N(e) {
134
- let t = /* @__PURE__ */ new Map();
135
- for (let n of e.tables) t.set(n.id, 0);
136
- let n = e.relations.map((e) => [e.from.tableId, e.to.tableId]).filter(([e, n]) => e !== n && t.has(e) && t.has(n));
137
- for (let r = 0; r < e.tables.length; r++) {
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
+ for (let t of e.columns) {
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
+ }
140
+ return Math.round(Math.min(r, Math.max(n, i)));
141
+ }
142
+ function U(e) {
143
+ return (e.schema ? e.schema.length + 1 : 0) + e.name.length;
144
+ }
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++) {
138
150
  let e = !1;
139
- for (let [r, i] of n) {
140
- let n = t.get(r) + 1;
141
- 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);
142
154
  }
143
155
  if (!e) break;
144
156
  }
145
- return t;
157
+ return n;
146
158
  }
147
- function P(e, t = {}) {
148
- let n = t.horizontalGap ?? 120, r = t.verticalGap ?? 40, i = N(e), a = /* @__PURE__ */ new Map();
149
- for (let t of e.tables) {
150
- let e = i.get(t.id) ?? 0, n = a.get(e);
151
- n || (n = [], a.set(e, n)), n.push(t);
159
+ function G(e, t = {}) {
160
+ let n = t.horizontalGap ?? 120, r = t.verticalGap ?? 40, i = {
161
+ minWidth: t.minNodeWidth,
162
+ maxWidth: t.maxNodeWidth
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);
169
+ }
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;
173
+ for (let e of t) {
174
+ let t = H(e, i), n = F(e);
175
+ c.set(e.id, {
176
+ x: p,
177
+ y: o,
178
+ width: t,
179
+ height: n
180
+ }), a = Math.max(a, t), o += n + r;
181
+ }
182
+ d = Math.max(d, p + a), f = Math.max(f, o - r), p += a + n;
152
183
  }
153
- let o = /* @__PURE__ */ new Map();
154
- return [...a.keys()].sort((e, t) => e - t).forEach((e, t) => {
155
- let i = a.get(e).sort((e, t) => e.name.localeCompare(t.name)), s = t * (240 + n), c = 0;
156
- for (let e of i) {
157
- let t = M(e);
158
- o.set(e.id, {
159
- x: s,
160
- y: c,
161
- width: 240,
162
- height: t
163
- }), c += t + r;
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);
164
194
  }
165
- }), o;
195
+ }
196
+ return c;
166
197
  }
167
198
  //#endregion
168
199
  //#region src/layout/dagre.ts
169
- async function F(e, t = {}) {
170
- let n = await import("@dagrejs/dagre"), r = t.horizontalGap ?? 120, i = t.verticalGap ?? 40, a = t.direction === "TB" ? "TB" : "LR", o = new n.graphlib.Graph();
171
- o.setGraph({
172
- rankdir: a,
200
+ async function le(e, t = {}) {
201
+ let n = await import("@dagrejs/dagre"), r = t.horizontalGap ?? 120, i = t.verticalGap ?? 40, a = {
202
+ minWidth: t.minNodeWidth,
203
+ maxWidth: t.maxNodeWidth
204
+ }, o = t.direction === "TB" ? "TB" : "LR", s = new n.graphlib.Graph();
205
+ s.setGraph({
206
+ rankdir: o,
173
207
  ranksep: r,
174
208
  nodesep: i
175
- }), o.setDefaultEdgeLabel(() => ({}));
176
- for (let t of e.tables) o.setNode(t.id, {
177
- width: 240,
178
- height: M(t)
209
+ }), s.setDefaultEdgeLabel(() => ({}));
210
+ for (let t of e.tables) s.setNode(t.id, {
211
+ width: H(t, a),
212
+ height: F(t)
179
213
  });
180
- for (let t of e.relations) o.hasNode(t.from.tableId) && o.hasNode(t.to.tableId) && o.setEdge(t.from.tableId, t.to.tableId);
181
- n.layout(o);
182
- let s = /* @__PURE__ */ new Map();
183
- for (let e of o.nodes()) {
184
- let t = o.node(e);
185
- t && s.set(e, {
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);
215
+ n.layout(s);
216
+ let c = /* @__PURE__ */ new Map();
217
+ for (let e of s.nodes()) {
218
+ let t = s.node(e);
219
+ t && c.set(e, {
186
220
  x: t.x - t.width / 2,
187
221
  y: t.y - t.height / 2,
188
222
  width: t.width,
189
223
  height: t.height
190
224
  });
191
225
  }
192
- return s;
226
+ return c;
193
227
  }
194
228
  //#endregion
195
229
  //#region src/layout/elk.ts
196
- async function I(e, t = {}) {
230
+ async function K(e, t = {}) {
197
231
  let n = new (await (import("elkjs/lib/elk.bundled.js"))).default(), r = t.horizontalGap ?? 120, i = t.verticalGap ?? 40, a = {
232
+ minWidth: t.minNodeWidth,
233
+ maxWidth: t.maxNodeWidth
234
+ }, o = {
198
235
  id: "root",
199
236
  layoutOptions: {
200
237
  "elk.algorithm": "layered",
@@ -204,42 +241,42 @@ async function I(e, t = {}) {
204
241
  },
205
242
  children: e.tables.map((e) => ({
206
243
  id: e.id,
207
- width: 240,
208
- height: M(e)
244
+ width: H(e, a),
245
+ height: F(e)
209
246
  })),
210
247
  edges: e.relations.map((e, t) => ({
211
248
  id: `e${t}`,
212
249
  sources: [e.from.tableId],
213
250
  targets: [e.to.tableId]
214
251
  }))
215
- }, o = await n.layout(a), s = /* @__PURE__ */ new Map();
216
- for (let e of o.children ?? []) s.set(e.id, {
252
+ }, s = await n.layout(o), c = /* @__PURE__ */ new Map();
253
+ for (let e of s.children ?? []) c.set(e.id, {
217
254
  x: e.x ?? 0,
218
255
  y: e.y ?? 0,
219
- width: e.width ?? 240,
256
+ width: e.width ?? 160,
220
257
  height: e.height ?? 0
221
258
  });
222
- return s;
259
+ return c;
223
260
  }
224
261
  //#endregion
225
262
  //#region src/layout/computeLayout.ts
226
- var L = class extends Error {
263
+ var q = class extends Error {
227
264
  constructor(e, t) {
228
265
  super(e, t), this.name = "LayoutError";
229
266
  }
230
267
  };
231
- async function R(e, t = {}) {
268
+ async function J(e, t = {}) {
232
269
  let n = t.algorithm ?? "simple";
233
- if (n === "simple") return P(e, t);
270
+ if (n === "simple") return G(e, t);
234
271
  try {
235
- return n === "dagre" ? await F(e, t) : await I(e, t);
272
+ return n === "dagre" ? await le(e, t) : await K(e, t);
236
273
  } catch (e) {
237
- throw new L(`"${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 });
238
275
  }
239
276
  }
240
277
  //#endregion
241
278
  //#region src/export.ts
242
- var ae = [
279
+ var ue = [
243
280
  "--dv-canvas",
244
281
  "--dv-bg",
245
282
  "--dv-border",
@@ -255,12 +292,12 @@ var ae = [
255
292
  "--dv-edge",
256
293
  "--dv-edge-active",
257
294
  "--dv-font"
258
- ], z = class extends Error {
295
+ ], Y = class extends Error {
259
296
  constructor(e, t) {
260
297
  super(e, t), this.name = "ExportError";
261
298
  }
262
299
  };
263
- function oe(e, t) {
300
+ function de(e, t) {
264
301
  let n = e.x, r = e.y, i = e.x + e.width, a = e.y + e.height;
265
302
  for (let e of t.querySelectorAll(".dv-erd-edge")) {
266
303
  let t;
@@ -278,12 +315,12 @@ function oe(e, t) {
278
315
  height: a - r
279
316
  };
280
317
  }
281
- async function B(e, t, n = {}) {
318
+ async function fe(e, t, n = {}) {
282
319
  let { type: r = "png", padding: i = 24, backgroundColor: a, pixelRatio: o = 2 } = n, s;
283
320
  try {
284
321
  s = await import("html-to-image");
285
322
  } catch (e) {
286
- throw new z("Export requires the optional dependency \"html-to-image\". Install it to enable PNG/SVG export.", { cause: e });
323
+ throw new Y("Export requires the optional dependency \"html-to-image\". Install it to enable PNG/SVG export.", { cause: e });
287
324
  }
288
325
  if (typeof document < "u" && document.fonts?.ready) try {
289
326
  await document.fonts.ready;
@@ -297,23 +334,23 @@ async function B(e, t, n = {}) {
297
334
  height: `${l}px`,
298
335
  transform: u
299
336
  }
300
- }, f = V(e, t, i);
337
+ }, f = pe(e, t, i);
301
338
  try {
302
339
  return r === "svg" ? await s.toSvg(e, d) : await s.toPng(e, {
303
340
  ...d,
304
341
  pixelRatio: o
305
342
  });
306
343
  } catch (e) {
307
- throw new z(`Failed to render diagram image: ${e instanceof Error ? e.message : String(e)}`, { cause: e });
344
+ throw new Y(`Failed to render diagram image: ${e instanceof Error ? e.message : String(e)}`, { cause: e });
308
345
  } finally {
309
346
  f();
310
347
  }
311
348
  }
312
- function V(e, t, n) {
349
+ function pe(e, t, n) {
313
350
  let r = [], i = e.closest(".dv-viewer");
314
351
  if (i) {
315
352
  let t = getComputedStyle(i);
316
- for (let n of ae) {
353
+ for (let n of ue) {
317
354
  let i = t.getPropertyValue(n);
318
355
  if (!i) continue;
319
356
  let a = e.style.getPropertyValue(n);
@@ -331,218 +368,317 @@ function V(e, t, n) {
331
368
  }
332
369
  return () => r.forEach((e) => e());
333
370
  }
334
- function H(e, t) {
371
+ function me(e, t) {
335
372
  let n = document.createElement("a");
336
373
  n.href = e, n.download = t, n.click();
337
374
  }
338
375
  //#endregion
339
376
  //#region src/components/handles.ts
340
- function U(e, t, n) {
377
+ function X(e, t, n) {
341
378
  return `${e}__${t}__${n}`;
342
379
  }
343
380
  //#endregion
344
- //#region src/components/TableNode.tsx
345
- function W(e) {
381
+ //#region src/components/columnHoverContext.ts
382
+ var he = e(void 0), ge = e("column");
383
+ function Z(e) {
346
384
  return 40 + e * 28 + 28 / 2;
347
385
  }
348
- function G({ column: e, top: t }) {
386
+ var _e = 4;
387
+ function ve({ column: e, top: t }) {
349
388
  let n = {
350
- top: t,
389
+ top: t - _e,
390
+ opacity: 0
391
+ }, r = {
392
+ top: t + _e,
351
393
  opacity: 0
352
394
  };
353
- return /* @__PURE__ */ _(h, { children: [
354
- /* @__PURE__ */ g(d, {
355
- id: U(e, "left", "target"),
395
+ return /* @__PURE__ */ b(v, { children: [
396
+ /* @__PURE__ */ y(p, {
397
+ id: X(e, "left", "target"),
356
398
  type: "target",
357
- position: p.Left,
358
- style: n,
399
+ position: h.Left,
400
+ style: r,
359
401
  isConnectable: !1
360
402
  }),
361
- /* @__PURE__ */ g(d, {
362
- id: U(e, "left", "source"),
403
+ /* @__PURE__ */ y(p, {
404
+ id: X(e, "left", "source"),
363
405
  type: "source",
364
- position: p.Left,
406
+ position: h.Left,
365
407
  style: n,
366
408
  isConnectable: !1
367
409
  }),
368
- /* @__PURE__ */ g(d, {
369
- id: U(e, "right", "target"),
410
+ /* @__PURE__ */ y(p, {
411
+ id: X(e, "right", "target"),
370
412
  type: "target",
371
- position: p.Right,
372
- style: n,
413
+ position: h.Right,
414
+ style: r,
373
415
  isConnectable: !1
374
416
  }),
375
- /* @__PURE__ */ g(d, {
376
- id: U(e, "right", "source"),
417
+ /* @__PURE__ */ y(p, {
418
+ id: X(e, "right", "source"),
377
419
  type: "source",
378
- position: p.Right,
420
+ position: h.Right,
379
421
  style: n,
380
422
  isConnectable: !1
381
423
  })
382
424
  ] });
383
425
  }
384
- function K({ data: e }) {
385
- let { table: t, highlightedColumns: n } = e;
386
- return /* @__PURE__ */ _("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", {
387
429
  className: "dv-table",
388
- style: { width: 240 },
389
- children: [/* @__PURE__ */ _("div", {
390
- className: "dv-table__header",
391
- style: t.headerColor ? {
392
- background: t.headerColor,
393
- height: 40
394
- } : { height: 40 },
395
- title: t.note,
396
- children: [t.schema && /* @__PURE__ */ _("span", {
397
- className: "dv-table__schema",
398
- children: [t.schema, "."]
399
- }), /* @__PURE__ */ g("span", {
400
- className: "dv-table__name",
401
- children: t.name
402
- })]
403
- }), /* @__PURE__ */ g("div", {
404
- className: "dv-table__body",
405
- children: t.columns.map((e, t) => {
406
- let r = n?.has(e.name);
407
- return /* @__PURE__ */ _("div", {
408
- className: `dv-row${r ? " dv-row--highlighted" : ""}`,
409
- style: { height: 28 },
410
- title: e.note,
411
- children: [
412
- /* @__PURE__ */ _("span", {
413
- className: `dv-row__name${e.pk ? " dv-row__name--pk" : ""}`,
414
- children: [
415
- e.pk && /* @__PURE__ */ g("span", {
416
- className: "dv-badge dv-badge--pk",
417
- title: "Primary key",
418
- children: "PK"
419
- }),
420
- e.isForeignKey && !e.pk && /* @__PURE__ */ g("span", {
421
- className: "dv-badge dv-badge--fk",
422
- title: "Foreign key",
423
- children: "FK"
424
- }),
425
- e.name
426
- ]
427
- }),
428
- /* @__PURE__ */ _("span", {
429
- className: "dv-row__type",
430
- children: [e.type, /* @__PURE__ */ g("span", {
431
- className: `dv-row__null${e.notNull ? " dv-row__null--notnull" : ""}`,
432
- title: e.notNull ? "Not null" : "Nullable"
433
- })]
434
- }),
435
- /* @__PURE__ */ g(G, {
436
- column: e.name,
437
- top: W(t)
438
- })
439
- ]
440
- }, 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
+ })
441
508
  })
442
- })]
509
+ ]
443
510
  });
444
511
  }
445
- var q = t(K), J = 8, Y = 13, X = 7, se = 13, ce = 16;
446
- function Z(e, t, n, r, i, a) {
447
- 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 = {
448
520
  stroke: i,
449
521
  strokeWidth: a
450
- }, l = (n, r) => s.push(/* @__PURE__ */ g("line", {
451
- x1: e + o * n,
452
- y1: t - J,
453
- x2: e + o * n,
454
- y2: t + J,
455
- style: c
456
- }, r)), u = (n, r) => s.push(/* @__PURE__ */ g("circle", {
457
- cx: e + o * n,
458
- 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,
459
531
  r: 4,
460
532
  style: {
461
533
  stroke: i,
462
534
  strokeWidth: a,
463
535
  fill: "var(--dv-bg)"
464
536
  }
465
- }, r));
466
- if (r.cardinality === "*") {
467
- let n = e + o * Y;
468
- s.push(/* @__PURE__ */ g("line", {
469
- x1: n,
470
- y1: t,
471
- x2: e,
472
- y2: t - J,
473
- style: c
474
- }, "cf1"), /* @__PURE__ */ g("line", {
475
- x1: n,
476
- y1: t,
477
- x2: e,
478
- y2: t,
479
- style: c
480
- }, "cf2"), /* @__PURE__ */ g("line", {
481
- x1: n,
482
- y1: t,
483
- x2: e,
484
- y2: t + J,
485
- style: c
486
- }, "cf3")), r.optional === !0 ? u(17, "fr") : l(14, "fb");
487
- } else l(X, "b1"), r.optional === !0 ? u(ce, "r") : r.optional === !1 && l(se, "b2");
488
- return /* @__PURE__ */ g("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", {
489
557
  className: "dv-erd-marker",
490
- children: s
558
+ transform: `translate(${e}, ${t}) rotate(${Te[n]})`,
559
+ children: o
491
560
  });
492
561
  }
493
- function le({ sourceX: e, sourceY: t, targetX: n, targetY: r, sourcePosition: i, targetPosition: a, data: o, selected: s }) {
494
- let [c] = m({
495
- sourceX: e,
496
- sourceY: t,
497
- sourcePosition: i,
498
- targetX: n,
499
- targetY: r,
500
- targetPosition: a,
501
- borderRadius: 8
502
- }), 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;
503
- return /* @__PURE__ */ _("g", {
504
- 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" : ""}`,
505
566
  children: [
506
- /* @__PURE__ */ g("path", {
567
+ /* @__PURE__ */ y("path", {
507
568
  className: "dv-erd-edge__interaction",
508
- d: c,
569
+ d: e,
509
570
  fill: "none"
510
571
  }),
511
- /* @__PURE__ */ g("path", {
572
+ /* @__PURE__ */ y("path", {
512
573
  className: "dv-erd-edge__path",
513
- d: c,
574
+ d: e,
514
575
  fill: "none",
515
576
  style: {
516
- stroke: f,
517
- strokeWidth: p
577
+ stroke: u,
578
+ strokeWidth: d
518
579
  },
519
- strokeDasharray: u ? "6 4" : void 0
580
+ strokeDasharray: l ? "6 4" : void 0
520
581
  }),
521
- l && Z(e, t, i, l.sourceEnd, f, p),
522
- l && Z(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)
523
584
  ]
524
585
  });
525
586
  }
526
- var Q = t(le);
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);
527
645
  //#endregion
528
646
  //#region src/components/useRelationHighlight.ts
529
- function ue(e, t, r) {
530
- 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(() => {
531
649
  let t = /* @__PURE__ */ new Map();
532
650
  for (let n of e) t.set(n.id, n);
533
651
  return t;
534
- }, [e]), l = a(() => {
535
- let e = /* @__PURE__ */ new Map(), t = i ? c.get(i) : void 0;
536
- if (!t) return e;
537
- for (let n of [t.from, t.to]) {
538
- let t = e.get(n.tableId) ?? /* @__PURE__ */ new Set();
539
- 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
+ }
540
671
  }
541
672
  return e;
542
- }, [i, c]);
673
+ }, [d, u]), p = r((e, t) => {
674
+ c(t ? {
675
+ tableId: e,
676
+ column: t
677
+ } : null);
678
+ }, []);
543
679
  return {
544
- displayNodes: a(() => i ? t.map((e) => {
545
- let t = l.get(e.id);
680
+ displayNodes: s(() => d.size === 0 ? t : t.map((e) => {
681
+ let t = f.get(e.id);
546
682
  return t ? {
547
683
  ...e,
548
684
  data: {
@@ -550,26 +686,27 @@ function ue(e, t, r) {
550
686
  highlightedColumns: t
551
687
  }
552
688
  } : e;
553
- }) : t, [
689
+ }), [
554
690
  t,
555
- i,
556
- l
691
+ d,
692
+ f
557
693
  ]),
558
- displayEdges: a(() => i ? r.map((e) => e.id === i ? {
694
+ displayEdges: s(() => d.size === 0 ? n : n.map((e) => d.has(e.id) ? {
559
695
  ...e,
560
696
  data: {
561
697
  ...e.data,
562
698
  hovered: !0
563
699
  },
564
700
  zIndex: 1
565
- } : e) : r, [r, i]),
566
- onEdgeMouseEnter: n((e, t) => o(t.id), []),
567
- onEdgeMouseLeave: n(() => o(null), [])
701
+ } : e), [n, d]),
702
+ onEdgeMouseEnter: r((e, t) => a(t.id), []),
703
+ onEdgeMouseLeave: r(() => a(null), []),
704
+ onColumnHover: p
568
705
  };
569
706
  }
570
707
  //#endregion
571
708
  //#region src/theme.ts
572
- var de = {
709
+ var Ie = {
573
710
  canvas: "--dv-canvas",
574
711
  background: "--dv-bg",
575
712
  border: "--dv-border",
@@ -584,7 +721,7 @@ var de = {
584
721
  edge: "--dv-edge",
585
722
  edgeActive: "--dv-edge-active",
586
723
  fontFamily: "--dv-font"
587
- }, fe = {
724
+ }, Le = {
588
725
  canvas: "#fafbfc",
589
726
  background: "#ffffff",
590
727
  border: "#d9dee5",
@@ -598,7 +735,7 @@ var de = {
598
735
  foreignKey: "#2b6cb0",
599
736
  edge: "#94a3b8",
600
737
  edgeActive: "#2b6cb0"
601
- }, pe = {
738
+ }, Re = {
602
739
  canvas: "#0f172a",
603
740
  background: "#1e293b",
604
741
  border: "#334155",
@@ -613,48 +750,51 @@ var de = {
613
750
  edge: "#64748b",
614
751
  edgeActive: "#60a5fa"
615
752
  };
616
- function me(e) {
753
+ function ze(e) {
617
754
  if (!e) return {};
618
755
  let t = {};
619
756
  for (let n of Object.keys(e)) {
620
757
  let r = e[n];
621
- r != null && (t[de[n]] = r);
758
+ r != null && (t[Ie[n]] = r);
622
759
  }
623
760
  return t;
624
761
  }
625
762
  //#endregion
626
763
  //#region src/components/DbmlViewer.tsx
627
- var he = [], ge = { table: q }, _e = { erd: Q };
628
- function ve() {
629
- return /* @__PURE__ */ _("svg", {
764
+ var Be = [], Ve = { table: be }, He = {
765
+ erd: ke,
766
+ "erd-floating": Pe
767
+ };
768
+ function Ue() {
769
+ return /* @__PURE__ */ b("svg", {
630
770
  viewBox: "0 0 24 24",
631
771
  width: "100%",
632
772
  height: "100%",
633
773
  fill: "currentColor",
634
774
  "aria-hidden": "true",
635
775
  children: [
636
- /* @__PURE__ */ g("rect", {
776
+ /* @__PURE__ */ y("rect", {
637
777
  x: "3",
638
778
  y: "3",
639
779
  width: "8",
640
780
  height: "8",
641
781
  rx: "1.5"
642
782
  }),
643
- /* @__PURE__ */ g("rect", {
783
+ /* @__PURE__ */ y("rect", {
644
784
  x: "13",
645
785
  y: "3",
646
786
  width: "8",
647
787
  height: "8",
648
788
  rx: "1.5"
649
789
  }),
650
- /* @__PURE__ */ g("rect", {
790
+ /* @__PURE__ */ y("rect", {
651
791
  x: "3",
652
792
  y: "13",
653
793
  width: "8",
654
794
  height: "8",
655
795
  rx: "1.5"
656
796
  }),
657
- /* @__PURE__ */ g("rect", {
797
+ /* @__PURE__ */ y("rect", {
658
798
  x: "13",
659
799
  y: "13",
660
800
  width: "8",
@@ -664,7 +804,7 @@ function ve() {
664
804
  ]
665
805
  });
666
806
  }
667
- function ye(e, t, n, r) {
807
+ function We(e, t, n, r) {
668
808
  let i = /* @__PURE__ */ new Map();
669
809
  for (let a of e.tables) {
670
810
  let e = t.get(a.id);
@@ -675,19 +815,54 @@ function ye(e, t, n, r) {
675
815
  }
676
816
  return i;
677
817
  }
678
- function be(e, t) {
818
+ function Ge(e, t) {
679
819
  if (e.length !== t.length) return !1;
680
820
  let n = new Set(e);
681
821
  return t.every((e) => n.has(e));
682
822
  }
683
- async function $(e, t, n) {
823
+ function Ke(e, t, n) {
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;
825
+ }
826
+ function qe(e, t, n, r, i) {
827
+ let a = (e, t) => ({
828
+ x: t.x,
829
+ y: t.y,
830
+ w: H(e, i),
831
+ h: F(e)
832
+ }), o = [];
833
+ for (let r of e.tables) n(r.id) && o.push(a(r, t.get(r.id)));
834
+ for (let i of e.tables) {
835
+ if (n(i.id)) continue;
836
+ let e = t.get(i.id), s = a(i, e), c = 0;
837
+ for (; c++ < 1e3;) {
838
+ let t = o.filter((e) => Ke(s, e, r));
839
+ if (t.length === 0) break;
840
+ let n = Math.max(...t.map((e) => e.y + e.h));
841
+ e = {
842
+ x: e.x,
843
+ y: n + r
844
+ }, s = a(i, e);
845
+ }
846
+ t.set(i.id, e), o.push(s);
847
+ }
848
+ }
849
+ async function Je(e, t, n) {
684
850
  try {
685
- return await R(e, t);
851
+ return await J(e, t);
686
852
  } catch (r) {
687
- return n(r instanceof L ? r : new L(String(r), { cause: r })), P(e, t);
853
+ return n(r instanceof q ? r : new q(String(r), { cause: r })), G(e, t);
688
854
  }
689
855
  }
690
- function xe(e, t) {
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) {
691
866
  return e.tables.map((e) => ({
692
867
  id: e.id,
693
868
  type: "table",
@@ -695,19 +870,33 @@ function xe(e, t) {
695
870
  x: 0,
696
871
  y: 0
697
872
  },
698
- data: { table: e }
873
+ data: {
874
+ table: e,
875
+ widthBounds: n,
876
+ connectedColumns: r.get(e.id)
877
+ }
699
878
  }));
700
879
  }
701
- function Se(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";
702
889
  return e.relations.map((e) => {
703
- 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);
704
894
  return {
705
895
  id: e.id,
706
896
  source: e.from.tableId,
707
897
  target: e.to.tableId,
708
- sourceHandle: U(s, a, "source"),
709
- targetHandle: U(c, o, "target"),
710
- type: "erd",
898
+ ...n,
899
+ type: r ? "erd-floating" : "erd",
711
900
  data: {
712
901
  kind: e.kind,
713
902
  sourceEnd: {
@@ -722,26 +911,26 @@ function Se(e, t) {
722
911
  };
723
912
  });
724
913
  }
725
- var Ce = e(function({ dbml: e, className: t, style: s, theme: d, fitView: p = !0, showControls: m = !0, showMiniMap: ie = !1, showBackground: h = !0, layoutOptions: v, onParseError: y, onLayoutError: b, nodePositions: x, onNodePositionsChange: C }, w) {
726
- let T = 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(() => {
727
916
  try {
728
917
  return {
729
918
  ok: !0,
730
- schema: O(e)
919
+ schema: A(e)
731
920
  };
732
921
  } catch (e) {
733
922
  return {
734
923
  ok: !1,
735
- error: e instanceof S ? e : new S(String(e), { cause: e })
924
+ error: e instanceof w ? e : new w(String(e), { cause: e })
736
925
  };
737
926
  }
738
- }, [e]), [E, D, k] = re([]), [A, j, M] = ne([]), N = o(null), P = o(null), F = o(E);
739
- F.current = E, i(w, () => {
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, () => {
740
929
  let e = async (e) => {
741
- let t = N.current, n = P.current?.querySelector(".react-flow__viewport");
742
- if (!t || !n) throw new z("The diagram is not ready to export yet.");
743
- let r = oe(te(t.getNodes()), n), i = e?.backgroundColor ?? (P.current ? getComputedStyle(P.current).backgroundColor : void 0);
744
- return B(n, r, {
930
+ let t = j.current, n = M.current?.querySelector(".react-flow__viewport");
931
+ if (!t || !n) throw new Y("The diagram is not ready to export yet.");
932
+ let r = de(ne(t.getNodes()), n), i = e?.backgroundColor ?? (M.current ? getComputedStyle(M.current).backgroundColor : void 0);
933
+ return fe(n, r, {
745
934
  ...e,
746
935
  backgroundColor: i
747
936
  });
@@ -749,154 +938,190 @@ var Ce = e(function({ dbml: e, className: t, style: s, theme: d, fitView: p = !0
749
938
  return {
750
939
  toDataUrl: e,
751
940
  download: async (t, n) => {
752
- H(await e(n), t);
753
- }
941
+ me(await e(n), t);
942
+ },
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()
754
951
  };
755
952
  }, []);
756
- let I = o(b);
757
- I.current = b;
758
- let L = o(C);
759
- L.current = C;
760
- let R = o(x);
761
- R.current = x;
762
- let ae = n(() => {
763
- let e = L.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;
764
961
  if (!e) return;
765
962
  let t = {};
766
- for (let e of F.current) t[e.id] = {
963
+ for (let e of N.current) t[e.id] = {
767
964
  x: e.position.x,
768
965
  y: e.position.y
769
966
  };
770
967
  e(t);
771
- }, []), { algorithm: V = "simple", direction: U = "LR", horizontalGap: W, verticalGap: G } = v ?? {}, K = o(null), q = `${V}|${U}|${W}|${G}`, J = n((e, t, n, r, i) => {
772
- let a = ye(e, r, i.saved, i.prior);
773
- if (D(xe(e, a)), j(Se(e, a)), K.current = {
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) => {
969
+ let a = {
970
+ minWidth: V,
971
+ maxWidth: H
972
+ }, o = We(e, r, i.saved, i.prior);
973
+ if (i.prior) {
974
+ let t = i.prior, n = i.saved;
975
+ qe(e, o, (e) => t.has(e) || n?.[e] !== void 0, B ?? 40, a);
976
+ }
977
+ if (E(Xe(e, o, a, Ye(e))), k(Qe(e, o, g)), U.current = {
774
978
  ids: t,
775
979
  optionsKey: n
776
980
  }, i.emit) {
777
981
  let e = {};
778
- a.forEach((t, n) => {
982
+ o.forEach((t, n) => {
779
983
  e[n] = t;
780
- }), L.current?.(e);
984
+ }), F.current?.(e);
781
985
  }
782
- i.fit && requestAnimationFrame(() => void N.current?.fitView());
783
- }, [D, j]);
784
- r(() => {
785
- if (!T.ok) {
786
- D([]), j([]), K.current = null;
986
+ i.fit && requestAnimationFrame(() => void j.current?.fitView());
987
+ }, [
988
+ E,
989
+ k,
990
+ B,
991
+ V,
992
+ H,
993
+ g
994
+ ]);
995
+ a(() => {
996
+ if (!C.ok) {
997
+ E([]), k([]), U.current = null;
787
998
  return;
788
999
  }
789
- let e = T.schema, t = {
790
- algorithm: V,
791
- direction: U,
792
- horizontalGap: W,
793
- verticalGap: G
794
- }, n = e.tables.map((e) => e.id), r = new Map(F.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, {
795
1008
  x: e.position.x,
796
1009
  y: e.position.y
797
- }])), i = K.current, a = n.every((e) => r.has(e));
798
- if (i && i.optionsKey === q && a && be(i.ids, n)) {
799
- J(e, n, q, /* @__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 });
800
1013
  return;
801
1014
  }
802
- let o = i && i.optionsKey === q ? r : void 0, s = !1;
803
- return $(e, t, (e) => I.current?.(e)).then((t) => {
804
- s || J(e, n, q, t, {
805
- saved: R.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,
806
1019
  prior: o,
807
- fit: p
1020
+ fit: l
808
1021
  });
809
1022
  }), () => {
810
1023
  s = !0;
811
1024
  };
812
1025
  }, [
813
- T,
1026
+ C,
1027
+ L,
1028
+ R,
1029
+ z,
1030
+ B,
814
1031
  V,
815
- U,
1032
+ H,
816
1033
  W,
1034
+ l,
817
1035
  G,
818
- q,
819
- p,
820
- J,
821
- D,
822
- j
1036
+ E,
1037
+ k
823
1038
  ]);
824
- let Y = n(() => {
825
- if (!T.ok) return;
826
- let e = T.schema, t = {
827
- algorithm: V,
828
- direction: U,
829
- horizontalGap: W,
830
- verticalGap: G
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
831
1048
  }, n = e.tables.map((e) => e.id);
832
- $(e, t, (e) => I.current?.(e)).then((t) => {
833
- J(e, n, q, t, {
1049
+ Je(e, t, (e) => P.current?.(e)).then((t) => {
1050
+ G(e, n, W, t, {
834
1051
  emit: !0,
835
1052
  fit: !0
836
1053
  });
837
1054
  });
838
1055
  }, [
839
- T,
1056
+ C,
1057
+ L,
1058
+ R,
1059
+ z,
1060
+ B,
840
1061
  V,
841
- U,
1062
+ H,
842
1063
  W,
843
- G,
844
- q,
845
- J
846
- ]), X = n(() => {
847
- T.ok || y?.(T.error);
848
- }, [T, y]);
849
- r(X, [X]);
850
- let { displayNodes: se, displayEdges: ce, onEdgeMouseEnter: Z, onEdgeMouseLeave: le } = ue(T.ok ? T.schema.relations : he, E, A), Q = {
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 = {
851
1070
  width: "100%",
852
1071
  height: "100%",
853
- ...me(d),
854
- ...s
1072
+ ...ze(i),
1073
+ ...n
855
1074
  };
856
- return T.ok ? /* @__PURE__ */ g("div", {
857
- ref: P,
1075
+ return C.ok ? /* @__PURE__ */ y("div", {
1076
+ ref: M,
858
1077
  className: `dv-viewer${t ? ` ${t}` : ""}`,
859
- style: Q,
860
- children: /* @__PURE__ */ _(ee, {
861
- nodes: se,
862
- edges: ce,
863
- nodeTypes: ge,
864
- edgeTypes: _e,
865
- onNodesChange: k,
866
- onEdgesChange: M,
867
- onEdgeMouseEnter: Z,
868
- onEdgeMouseLeave: le,
869
- onNodeDragStop: ae,
870
- onInit: (e) => {
871
- N.current = e;
872
- },
873
- fitView: p,
874
- nodesConnectable: !1,
875
- elementsSelectable: !0,
876
- minZoom: .1,
877
- proOptions: { hideAttribution: !0 },
878
- children: [
879
- h && /* @__PURE__ */ g(c, {}),
880
- m && /* @__PURE__ */ g(u, { children: /* @__PURE__ */ g(l, {
881
- onClick: Y,
882
- title: "Auto layout",
883
- "aria-label": "Auto layout",
884
- children: /* @__PURE__ */ g(ve, {})
885
- }) }),
886
- ie && /* @__PURE__ */ g(f, {
887
- pannable: !0,
888
- zoomable: !0
1078
+ style: Z,
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
+ ]
889
1114
  })
890
- ]
1115
+ })
891
1116
  })
892
- }) : /* @__PURE__ */ g("div", {
1117
+ }) : /* @__PURE__ */ y("div", {
893
1118
  className: `dv-error${t ? ` ${t}` : ""}`,
894
- style: Q,
895
- children: /* @__PURE__ */ g("pre", {
1119
+ style: Z,
1120
+ children: /* @__PURE__ */ y("pre", {
896
1121
  className: "dv-error__message",
897
- children: T.error.message
1122
+ children: C.error.message
898
1123
  })
899
1124
  });
900
1125
  });
901
1126
  //#endregion
902
- export { S as DbmlParseError, Ce as DbmlViewer, Q as ErdEdge, z as ExportError, A as HEADER_HEIGHT, L as LayoutError, k as NODE_WIDTH, j as ROW_HEIGHT, q as TableNode, R as computeLayout, pe as darkTheme, H as downloadDataUrl, P as layoutSchema, fe as lightTheme, O as parseDbml, B as renderDiagram, M as tableHeight, me 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 };