@datnguye/erd-flow 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +151 -0
- package/dist/erd-flow.css +1 -0
- package/dist/index.d.ts +193 -0
- package/dist/index.js +987 -0
- package/package.json +69 -0
package/dist/index.js
ADDED
|
@@ -0,0 +1,987 @@
|
|
|
1
|
+
import { jsxs as $, jsx as b } from "react/jsx-runtime";
|
|
2
|
+
import { memo as St, useCallback as P, useMemo as T, useState as nt, useRef as R, useEffect as W } from "react";
|
|
3
|
+
import { useInternalNode as st, getSmoothStepPath as Fe, Position as z, BaseEdge as Ye, Handle as Zt, useNodesState as We, useEdgesState as ze, ReactFlow as Ke, Background as je, Controls as Ve, MiniMap as Xe } from "@xyflow/react";
|
|
4
|
+
import Jt from "@dagrejs/dagre";
|
|
5
|
+
function qe(t) {
|
|
6
|
+
const n = /* @__PURE__ */ new Map(), e = (o, s) => {
|
|
7
|
+
if (!s) return;
|
|
8
|
+
const c = n.get(o) ?? /* @__PURE__ */ new Set();
|
|
9
|
+
c.add(s), n.set(o, c);
|
|
10
|
+
};
|
|
11
|
+
for (const o of t) {
|
|
12
|
+
if (!o.selected) continue;
|
|
13
|
+
const s = o.data ?? {};
|
|
14
|
+
e(o.source, s.from_column), e(o.target, s.to_column);
|
|
15
|
+
for (const c of s.from_columns ?? []) e(o.source, c);
|
|
16
|
+
for (const c of s.to_columns ?? []) e(o.target, c);
|
|
17
|
+
}
|
|
18
|
+
return n;
|
|
19
|
+
}
|
|
20
|
+
const Ze = 5, Je = 5;
|
|
21
|
+
function X(t, n = !0) {
|
|
22
|
+
return n && t > Ze;
|
|
23
|
+
}
|
|
24
|
+
function it(t, n, e = !0) {
|
|
25
|
+
return X(t, e) && !n ? Je : t;
|
|
26
|
+
}
|
|
27
|
+
const Qe = 24, he = 32, wt = 22, fe = 4, tn = 4, ge = 1, pe = 220, Qt = /* @__PURE__ */ new WeakMap();
|
|
28
|
+
function en(t) {
|
|
29
|
+
const n = Qt.get(t);
|
|
30
|
+
if (n) return n;
|
|
31
|
+
const e = /* @__PURE__ */ new Map();
|
|
32
|
+
return t.forEach((o, s) => {
|
|
33
|
+
e.has(o.name) || e.set(o.name, s);
|
|
34
|
+
}), Qt.set(t, e), e;
|
|
35
|
+
}
|
|
36
|
+
function ct(t) {
|
|
37
|
+
var e, o, s, c;
|
|
38
|
+
if (!t) return null;
|
|
39
|
+
const n = ((e = t.data) == null ? void 0 : e.columns) ?? [];
|
|
40
|
+
return {
|
|
41
|
+
base: t.internals.positionAbsolute,
|
|
42
|
+
width: ((o = t.measured) == null ? void 0 : o.width) ?? t.width ?? pe,
|
|
43
|
+
columnIndex: en(n),
|
|
44
|
+
columnCount: n.length,
|
|
45
|
+
expanded: ((s = t.data) == null ? void 0 : s.__expanded) === !0,
|
|
46
|
+
collapse: ((c = t.data) == null ? void 0 : c.__collapse) !== !1
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
function nn(t) {
|
|
50
|
+
return ge + he + fe + t * wt + wt / 2;
|
|
51
|
+
}
|
|
52
|
+
function on(t, n) {
|
|
53
|
+
const e = it(t.columnCount, t.expanded, t.collapse), o = n ? t.columnIndex.get(n) ?? -1 : -1;
|
|
54
|
+
return o >= 0 && o < e ? o : Math.max(0, e - 1);
|
|
55
|
+
}
|
|
56
|
+
function rt(t, n, e) {
|
|
57
|
+
return { x: e ? t.base.x : t.base.x + t.width, y: t.base.y + nn(on(t, n)) };
|
|
58
|
+
}
|
|
59
|
+
function _e(t, n) {
|
|
60
|
+
const e = t.base.x <= n.base.x;
|
|
61
|
+
return { fromIsLeft: !e, toIsLeft: e };
|
|
62
|
+
}
|
|
63
|
+
function ye(t, n) {
|
|
64
|
+
return {
|
|
65
|
+
stroke: t ? "var(--erd-edge-selected, #e5c07b)" : "var(--erd-edge, #007acc)",
|
|
66
|
+
strokeWidth: t ? "var(--erd-edge-selected-width, 3)" : "var(--erd-edge-width, 2)",
|
|
67
|
+
fill: "none",
|
|
68
|
+
...n
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
const te = 40, sn = 0.6, cn = 0.7;
|
|
72
|
+
function ee(t) {
|
|
73
|
+
return t.reduce((n, e) => n + e.y, 0) / t.length;
|
|
74
|
+
}
|
|
75
|
+
function ne(t, n, e, o) {
|
|
76
|
+
const s = e ? t.x + n : t.x, c = e ? te : -te;
|
|
77
|
+
return { x: s + c, y: o };
|
|
78
|
+
}
|
|
79
|
+
function xe(t, n, e, o) {
|
|
80
|
+
const s = Math.abs(n.x - t.x) * e, c = t.x + (o ? s : -s), i = n.x - (o ? s : -s);
|
|
81
|
+
return `M ${t.x} ${t.y} C ${c} ${t.y}, ${i} ${n.y}, ${n.x} ${n.y}`;
|
|
82
|
+
}
|
|
83
|
+
function rn(t, n, e) {
|
|
84
|
+
return xe(t, n, cn, e);
|
|
85
|
+
}
|
|
86
|
+
function Mt(t, n) {
|
|
87
|
+
return xe(t, n, sn, n.x - t.x >= 0);
|
|
88
|
+
}
|
|
89
|
+
function oe(t, n, e) {
|
|
90
|
+
const o = n.map((s) => rt(t, s, e));
|
|
91
|
+
return o.length > 0 ? o : [rt(t, null, e)];
|
|
92
|
+
}
|
|
93
|
+
const an = St(function({
|
|
94
|
+
source: n,
|
|
95
|
+
target: e,
|
|
96
|
+
data: o,
|
|
97
|
+
style: s,
|
|
98
|
+
markerEnd: c,
|
|
99
|
+
selected: i
|
|
100
|
+
}) {
|
|
101
|
+
const d = st(n), a = st(e), r = o, m = ct(d), u = ct(a);
|
|
102
|
+
if (!m || !u || !r) return null;
|
|
103
|
+
const { fromIsLeft: f, toIsLeft: x } = _e(m, u), g = oe(m, r.from_columns, f), w = oe(u, r.to_columns, x), y = ne(m.base, m.width, !f, ee(g)), I = ne(u.base, u.width, !x, ee(w)), M = ye(i ?? !1, s), E = i || r.__animated === !1 ? "" : " animated", p = rn(y, I, !f);
|
|
104
|
+
return /* @__PURE__ */ $("g", { className: "react-flow__edge-path erd-composite-edge", children: [
|
|
105
|
+
/* @__PURE__ */ b(
|
|
106
|
+
"path",
|
|
107
|
+
{
|
|
108
|
+
d: p,
|
|
109
|
+
className: "react-flow__edge-interaction",
|
|
110
|
+
fill: "none",
|
|
111
|
+
stroke: "transparent",
|
|
112
|
+
strokeWidth: 20
|
|
113
|
+
}
|
|
114
|
+
),
|
|
115
|
+
g.map((S, N) => /* @__PURE__ */ b(
|
|
116
|
+
"path",
|
|
117
|
+
{
|
|
118
|
+
d: Mt(S, y),
|
|
119
|
+
className: "erd-composite-tail",
|
|
120
|
+
style: M
|
|
121
|
+
},
|
|
122
|
+
`from-${N}`
|
|
123
|
+
)),
|
|
124
|
+
/* @__PURE__ */ b(
|
|
125
|
+
"path",
|
|
126
|
+
{
|
|
127
|
+
d: p,
|
|
128
|
+
className: `erd-composite-bundle${E}`,
|
|
129
|
+
style: M,
|
|
130
|
+
markerEnd: c
|
|
131
|
+
}
|
|
132
|
+
),
|
|
133
|
+
w.map((S, N) => /* @__PURE__ */ b(
|
|
134
|
+
"path",
|
|
135
|
+
{
|
|
136
|
+
d: Mt(I, S),
|
|
137
|
+
className: `erd-composite-tail${E}`,
|
|
138
|
+
style: M
|
|
139
|
+
},
|
|
140
|
+
`to-${N}`
|
|
141
|
+
))
|
|
142
|
+
] });
|
|
143
|
+
}), dn = St(function({
|
|
144
|
+
source: n,
|
|
145
|
+
target: e,
|
|
146
|
+
data: o,
|
|
147
|
+
style: s,
|
|
148
|
+
markerEnd: c,
|
|
149
|
+
selected: i
|
|
150
|
+
}) {
|
|
151
|
+
const d = st(n), a = st(e), r = ct(d), m = ct(a);
|
|
152
|
+
if (!r || !m) return null;
|
|
153
|
+
const u = o, f = (u == null ? void 0 : u.from_column) ?? null, x = (u == null ? void 0 : u.to_column) ?? null, { fromIsLeft: g, toIsLeft: w } = _e(r, m), y = rt(r, f, g), I = rt(m, x, w), M = (u == null ? void 0 : u.__edgePath) === "smoothstep" ? Fe({
|
|
154
|
+
sourceX: y.x,
|
|
155
|
+
sourceY: y.y,
|
|
156
|
+
sourcePosition: g ? z.Left : z.Right,
|
|
157
|
+
targetX: I.x,
|
|
158
|
+
targetY: I.y,
|
|
159
|
+
targetPosition: w ? z.Left : z.Right
|
|
160
|
+
})[0] : Mt(y, I), E = (u == null ? void 0 : u.__animated) !== !1 && !i;
|
|
161
|
+
return /* @__PURE__ */ b(
|
|
162
|
+
Ye,
|
|
163
|
+
{
|
|
164
|
+
path: M,
|
|
165
|
+
markerEnd: c,
|
|
166
|
+
className: `erd-single-edge${E ? " animated" : ""}`,
|
|
167
|
+
style: ye(i ?? !1, s)
|
|
168
|
+
}
|
|
169
|
+
);
|
|
170
|
+
}), ln = {
|
|
171
|
+
composite: an,
|
|
172
|
+
single: dn
|
|
173
|
+
};
|
|
174
|
+
function be(t) {
|
|
175
|
+
return {
|
|
176
|
+
width: t,
|
|
177
|
+
height: t,
|
|
178
|
+
viewBox: "0 0 24 24",
|
|
179
|
+
fill: "none",
|
|
180
|
+
stroke: "currentColor",
|
|
181
|
+
strokeWidth: 2,
|
|
182
|
+
strokeLinecap: "round",
|
|
183
|
+
strokeLinejoin: "round"
|
|
184
|
+
};
|
|
185
|
+
}
|
|
186
|
+
function un({ size: t = 14, className: n }) {
|
|
187
|
+
return /* @__PURE__ */ b("svg", { ...be(t), className: n, "aria-hidden": "true", children: /* @__PURE__ */ b("path", { d: "M9 3H5a2 2 0 0 0-2 2v4m6-6h10a2 2 0 0 1 2 2v4M9 3v18m0 0h10a2 2 0 0 0 2-2V9M9 21H5a2 2 0 0 1-2-2V9m0 0h18" }) });
|
|
188
|
+
}
|
|
189
|
+
function mn({ size: t = 14, className: n }) {
|
|
190
|
+
return /* @__PURE__ */ $("svg", { ...be(t), className: n, "aria-hidden": "true", children: [
|
|
191
|
+
/* @__PURE__ */ b("ellipse", { cx: "12", cy: "5", rx: "9", ry: "3" }),
|
|
192
|
+
/* @__PURE__ */ b("path", { d: "M3 5v14a9 3 0 0 0 18 0V5" }),
|
|
193
|
+
/* @__PURE__ */ b("path", { d: "M3 12a9 3 0 0 0 18 0" })
|
|
194
|
+
] });
|
|
195
|
+
}
|
|
196
|
+
function hn(t) {
|
|
197
|
+
return t.is_primary_key ? "PK" : t.is_foreign_key ? "FK" : "";
|
|
198
|
+
}
|
|
199
|
+
function fn({ col: t, highlighted: n }) {
|
|
200
|
+
const e = hn(t);
|
|
201
|
+
return /* @__PURE__ */ $("li", { className: "erd-column", "data-highlighted": n ? "true" : "false", children: [
|
|
202
|
+
/* @__PURE__ */ b("span", { className: `erd-column-badge badge-${e.toLowerCase() || "none"}`, children: e }),
|
|
203
|
+
/* @__PURE__ */ b("span", { className: "erd-column-name", children: t.name }),
|
|
204
|
+
/* @__PURE__ */ b("span", { className: "erd-column-type", children: t.data_type ?? "" })
|
|
205
|
+
] });
|
|
206
|
+
}
|
|
207
|
+
const gn = St(function({ id: n, data: e }) {
|
|
208
|
+
const o = typeof e.compiled_sql == "string" && e.compiled_sql.length > 0, s = e.__collapse !== !1, c = X(e.columns.length, s), i = e.__expanded === !0, d = e.__onToggleExpand, a = P(
|
|
209
|
+
(p) => {
|
|
210
|
+
p.stopPropagation(), d == null || d(n);
|
|
211
|
+
},
|
|
212
|
+
[n, d]
|
|
213
|
+
), r = P((p) => {
|
|
214
|
+
p.key !== "Enter" && p.key !== " " || (p.preventDefault(), p.currentTarget.click());
|
|
215
|
+
}, []), m = e.columns.slice(
|
|
216
|
+
0,
|
|
217
|
+
it(e.columns.length, i, s)
|
|
218
|
+
), u = e.columns.length - m.length, f = e.__filterState, x = e.__active === !0, g = e.__focus === !0, w = e.__dimmed === !0, y = e.__showSchema === !0 && !!e.schema_name, I = e.hidden_column_count ?? 0, M = e.__highlightColumns, E = e.__icon;
|
|
219
|
+
return /* @__PURE__ */ $(
|
|
220
|
+
"div",
|
|
221
|
+
{
|
|
222
|
+
className: "erd-table",
|
|
223
|
+
"data-resource": e.resource_type,
|
|
224
|
+
"data-filter": f ?? "off",
|
|
225
|
+
"data-active": x ? "true" : "false",
|
|
226
|
+
"data-focus": g ? "true" : "false",
|
|
227
|
+
"data-dimmed": w ? "true" : "false",
|
|
228
|
+
children: [
|
|
229
|
+
/* @__PURE__ */ b(Zt, { type: "target", position: z.Left, id: "__node_in", className: "erd-hidden-handle" }),
|
|
230
|
+
/* @__PURE__ */ b(Zt, { type: "source", position: z.Right, id: "__node_out", className: "erd-hidden-handle" }),
|
|
231
|
+
/* @__PURE__ */ $(
|
|
232
|
+
"header",
|
|
233
|
+
{
|
|
234
|
+
className: "erd-table-header nokey",
|
|
235
|
+
title: o ? "Double-click to open" : "",
|
|
236
|
+
role: "button",
|
|
237
|
+
tabIndex: 0,
|
|
238
|
+
onKeyDown: r,
|
|
239
|
+
children: [
|
|
240
|
+
/* @__PURE__ */ b("span", { className: "erd-table-icon", children: E === "database" ? /* @__PURE__ */ b(mn, { size: 14 }) : /* @__PURE__ */ b(un, { size: 14 }) }),
|
|
241
|
+
/* @__PURE__ */ b("span", { className: "erd-table-name", children: e.name }),
|
|
242
|
+
y ? /* @__PURE__ */ b("span", { className: "erd-table-schema", children: e.schema_name }) : null
|
|
243
|
+
]
|
|
244
|
+
}
|
|
245
|
+
),
|
|
246
|
+
/* @__PURE__ */ b("ul", { className: "erd-table-columns", children: m.map((p, S) => /* @__PURE__ */ b(
|
|
247
|
+
fn,
|
|
248
|
+
{
|
|
249
|
+
col: p,
|
|
250
|
+
highlighted: (M == null ? void 0 : M.has(p.name)) ?? !1
|
|
251
|
+
},
|
|
252
|
+
`${p.name}-${S}`
|
|
253
|
+
)) }),
|
|
254
|
+
I > 0 ? /* @__PURE__ */ $("div", { className: "erd-table-more", children: [
|
|
255
|
+
"+",
|
|
256
|
+
I,
|
|
257
|
+
" more columns"
|
|
258
|
+
] }) : null,
|
|
259
|
+
c ? /* @__PURE__ */ b(
|
|
260
|
+
"button",
|
|
261
|
+
{
|
|
262
|
+
type: "button",
|
|
263
|
+
className: "erd-table-expand",
|
|
264
|
+
onClick: a,
|
|
265
|
+
title: i ? "Collapse columns" : `Show ${u} more columns`,
|
|
266
|
+
children: i ? "▲ Collapse" : `▼ ${u} more`
|
|
267
|
+
}
|
|
268
|
+
) : null
|
|
269
|
+
]
|
|
270
|
+
}
|
|
271
|
+
);
|
|
272
|
+
}), pn = {
|
|
273
|
+
erdTable: gn
|
|
274
|
+
}, _n = 440, yn = 7, xn = 60, bn = 80;
|
|
275
|
+
function wn(t) {
|
|
276
|
+
const n = (s) => s.name.length + (s.data_type ? s.data_type.length + 2 : 0), o = t.columns.reduce(
|
|
277
|
+
(s, c) => Math.max(s, n(c)),
|
|
278
|
+
t.name.length
|
|
279
|
+
) * yn + xn;
|
|
280
|
+
return Math.min(_n, Math.max(pe, o));
|
|
281
|
+
}
|
|
282
|
+
function Mn(t, n = !0) {
|
|
283
|
+
const e = t.columns.length, o = it(e, !1, n), s = t.hidden_column_count ? 1 : 0, c = X(e, n) ? Qe : 0;
|
|
284
|
+
return Math.max(
|
|
285
|
+
bn,
|
|
286
|
+
he + (o + s) * wt + fe + tn + 2 * ge + c
|
|
287
|
+
);
|
|
288
|
+
}
|
|
289
|
+
function we(t, n = !0) {
|
|
290
|
+
return { width: wn(t), height: Mn(t, n) };
|
|
291
|
+
}
|
|
292
|
+
function En(t, n = !0, e) {
|
|
293
|
+
return t.map((o) => {
|
|
294
|
+
const s = e ? e(
|
|
295
|
+
o,
|
|
296
|
+
it(o.columns.length, !1, n),
|
|
297
|
+
X(o.columns.length, n)
|
|
298
|
+
) : we(o, n);
|
|
299
|
+
return { ...o, ...s };
|
|
300
|
+
});
|
|
301
|
+
}
|
|
302
|
+
function Nt(t) {
|
|
303
|
+
return new Map(t.map((n) => [n.id, { width: n.width, height: n.height }]));
|
|
304
|
+
}
|
|
305
|
+
const Sn = 6, Me = 40;
|
|
306
|
+
function se(t, n, e) {
|
|
307
|
+
return Math.min(e, Math.max(n, t));
|
|
308
|
+
}
|
|
309
|
+
function vt(t, n = !0) {
|
|
310
|
+
const e = /* @__PURE__ */ new Map();
|
|
311
|
+
for (const o of t) e.set(o.id, we(o, n));
|
|
312
|
+
return e;
|
|
313
|
+
}
|
|
314
|
+
function Ee(t, n) {
|
|
315
|
+
return { x: t.x - n.width / 2, y: t.y - n.height / 2 };
|
|
316
|
+
}
|
|
317
|
+
function Se(t, n, e) {
|
|
318
|
+
return t.map((o) => {
|
|
319
|
+
const s = n.get(o.id) ?? { x: 0, y: 0 };
|
|
320
|
+
return { id: o.id, x: s.x, y: s.y, dimensions: e.get(o.id) };
|
|
321
|
+
});
|
|
322
|
+
}
|
|
323
|
+
function It(t) {
|
|
324
|
+
const n = /* @__PURE__ */ new Map(), e = (o, s) => {
|
|
325
|
+
const c = n.get(o) ?? /* @__PURE__ */ new Set();
|
|
326
|
+
c.add(s), n.set(o, c);
|
|
327
|
+
};
|
|
328
|
+
for (const o of t)
|
|
329
|
+
o.from_id !== o.to_id && (e(o.from_id, o.to_id), e(o.to_id, o.from_id));
|
|
330
|
+
return n;
|
|
331
|
+
}
|
|
332
|
+
function Ne(t, n) {
|
|
333
|
+
const e = [], o = [];
|
|
334
|
+
for (const s of t)
|
|
335
|
+
(n.has(s) ? e : o).push(s);
|
|
336
|
+
return { connected: e, islands: o };
|
|
337
|
+
}
|
|
338
|
+
function Nn(t, n) {
|
|
339
|
+
const e = /* @__PURE__ */ new Set(), o = [];
|
|
340
|
+
for (const s of t) {
|
|
341
|
+
if (e.has(s)) continue;
|
|
342
|
+
const c = [s];
|
|
343
|
+
e.add(s);
|
|
344
|
+
const i = [];
|
|
345
|
+
for (; c.length > 0; ) {
|
|
346
|
+
const d = c.shift();
|
|
347
|
+
i.push(d);
|
|
348
|
+
for (const a of n.get(d) ?? [])
|
|
349
|
+
e.has(a) || (e.add(a), c.push(a));
|
|
350
|
+
}
|
|
351
|
+
o.push(i);
|
|
352
|
+
}
|
|
353
|
+
return o;
|
|
354
|
+
}
|
|
355
|
+
function ve(t, n, e = 0, o = 0, s = Me) {
|
|
356
|
+
const c = /* @__PURE__ */ new Map(), i = t.reduce((m, u) => Math.max(m, n.get(u).width), 0) + s;
|
|
357
|
+
let d = o, a = 0, r = 0;
|
|
358
|
+
return t.forEach((m, u) => {
|
|
359
|
+
const f = u % Sn;
|
|
360
|
+
f === 0 && u > 0 && (d += a + s, a = 0);
|
|
361
|
+
const x = n.get(m);
|
|
362
|
+
c.set(m, { x: e + f * i, y: d }), a = Math.max(a, x.height), r = Math.max(r, f * i + x.width);
|
|
363
|
+
}), { positions: c, width: r, height: d + a - o };
|
|
364
|
+
}
|
|
365
|
+
function Ie(t, n, e) {
|
|
366
|
+
const o = /* @__PURE__ */ new Map();
|
|
367
|
+
let s = 1 / 0, c = 1 / 0, i = -1 / 0, d = -1 / 0;
|
|
368
|
+
for (const a of t) {
|
|
369
|
+
const r = n.get(a) ?? { x: 0, y: 0 }, m = e.get(a), { x: u, y: f } = Ee(r, m);
|
|
370
|
+
o.set(a, { x: u, y: f }), s = Math.min(s, u), c = Math.min(c, f), i = Math.max(i, u + m.width), d = Math.max(d, f + m.height);
|
|
371
|
+
}
|
|
372
|
+
Number.isFinite(s) || (s = 0, c = 0, i = 0, d = 0);
|
|
373
|
+
for (const [a, r] of o)
|
|
374
|
+
o.set(a, { x: r.x - s, y: r.y - c });
|
|
375
|
+
return { positions: o, box: { minX: s, minY: c, maxX: i, maxY: d } };
|
|
376
|
+
}
|
|
377
|
+
const vn = "LR", In = 40, Cn = 80, ce = 24, Ln = "network-simplex", kn = "UL";
|
|
378
|
+
function Tn(t, n, e = !0, o) {
|
|
379
|
+
const s = new Jt.graphlib.Graph({ compound: !1 });
|
|
380
|
+
s.setGraph({
|
|
381
|
+
rankdir: vn,
|
|
382
|
+
nodesep: In,
|
|
383
|
+
ranksep: Cn,
|
|
384
|
+
marginx: ce,
|
|
385
|
+
marginy: ce,
|
|
386
|
+
ranker: Ln,
|
|
387
|
+
align: kn
|
|
388
|
+
}), s.setDefaultEdgeLabel(() => ({}));
|
|
389
|
+
const c = o ?? vt(t, e);
|
|
390
|
+
for (const i of t)
|
|
391
|
+
s.setNode(i.id, c.get(i.id));
|
|
392
|
+
for (const i of n)
|
|
393
|
+
s.setEdge(i.from_id, i.to_id);
|
|
394
|
+
return Jt.layout(s), t.map((i) => {
|
|
395
|
+
const d = s.node(i.id), a = c.get(i.id), { x: r, y: m } = Ee(d, a);
|
|
396
|
+
return { id: i.id, x: r, y: m, dimensions: a };
|
|
397
|
+
});
|
|
398
|
+
}
|
|
399
|
+
function Ce(t, n, e, o, s = 40) {
|
|
400
|
+
for (let c = 0; c < s; c++) {
|
|
401
|
+
let i = !1;
|
|
402
|
+
for (let d = 0; d < t.length; d++)
|
|
403
|
+
for (let a = d + 1; a < t.length; a++) {
|
|
404
|
+
const r = n.get(t[d]), m = n.get(t[a]), u = e.get(t[d]), f = e.get(t[a]), x = u.width / 2 + f.width / 2 + o, g = u.height / 2 + f.height / 2 + o, w = m.x - r.x, y = m.y - r.y, I = x - Math.abs(w), M = g - Math.abs(y);
|
|
405
|
+
if (!(I <= 0 || M <= 0)) {
|
|
406
|
+
if (I < M) {
|
|
407
|
+
const E = I / 2 * (w < 0 ? -1 : 1);
|
|
408
|
+
r.x -= E, m.x += E;
|
|
409
|
+
} else {
|
|
410
|
+
const E = M / 2 * (y < 0 ? -1 : 1);
|
|
411
|
+
r.y -= E, m.y += E;
|
|
412
|
+
}
|
|
413
|
+
i = !0;
|
|
414
|
+
}
|
|
415
|
+
}
|
|
416
|
+
if (!i) break;
|
|
417
|
+
}
|
|
418
|
+
}
|
|
419
|
+
const An = 300, Rn = 32e4, On = 0.02, Le = 80, re = 0.012, ie = 0.85, ot = 60, ae = 1;
|
|
420
|
+
function Pn(t, n) {
|
|
421
|
+
const e = new Map(t.map((s) => [s.id, s])), o = n.map((s) => ({ a: e.get(s.from_id), b: e.get(s.to_id) })).filter((s) => !!s.a && !!s.b && s.a !== s.b);
|
|
422
|
+
for (let s = 0; s < An; s++) {
|
|
423
|
+
for (let c = 0; c < t.length; c++) {
|
|
424
|
+
const i = t[c];
|
|
425
|
+
for (let d = c + 1; d < t.length; d++) {
|
|
426
|
+
const a = t[d];
|
|
427
|
+
let r = i.x - a.x, m = i.y - a.y, u = r * r + m * m;
|
|
428
|
+
u === 0 && (r = c - d || 1, m = 1, u = r * r + m * m), u = Math.max(u, ae * ae);
|
|
429
|
+
const f = Math.sqrt(u), x = i.radius + a.radius, g = Rn / u + (f < x ? (x - f) * 4 : 0), w = r / f * g, y = m / f * g;
|
|
430
|
+
i.vx += w, i.vy += y, a.vx -= w, a.vy -= y;
|
|
431
|
+
}
|
|
432
|
+
}
|
|
433
|
+
for (const { a: c, b: i } of o) {
|
|
434
|
+
const d = i.x - c.x, a = i.y - c.y, r = Math.sqrt(d * d + a * a) || 1, m = c.radius + i.radius + Le, u = On * (r - m), f = d / r * u, x = a / r * u;
|
|
435
|
+
c.vx += f, c.vy += x, i.vx -= f, i.vy -= x;
|
|
436
|
+
}
|
|
437
|
+
for (const c of t)
|
|
438
|
+
c.vx -= c.x * re, c.vy -= c.y * re, c.vx *= ie, c.vy *= ie, c.x += se(c.vx, -ot, ot), c.y += se(c.vy, -ot, ot);
|
|
439
|
+
}
|
|
440
|
+
}
|
|
441
|
+
function Dn(t, n, e = !0, o) {
|
|
442
|
+
const s = o ?? vt(t, e), c = It(n), { connected: i, islands: d } = Ne(
|
|
443
|
+
t.map((y) => y.id),
|
|
444
|
+
c
|
|
445
|
+
), a = new Set(i), r = t.filter((y) => a.has(y.id)), m = Math.max(200, r.length * 24), u = r.map((y, I) => {
|
|
446
|
+
const M = I / Math.max(r.length, 1) * 2 * Math.PI, E = s.get(y.id);
|
|
447
|
+
return {
|
|
448
|
+
id: y.id,
|
|
449
|
+
x: Math.cos(M) * m,
|
|
450
|
+
y: Math.sin(M) * m,
|
|
451
|
+
vx: 0,
|
|
452
|
+
vy: 0,
|
|
453
|
+
radius: Math.hypot(E.width, E.height) / 2,
|
|
454
|
+
dim: E
|
|
455
|
+
};
|
|
456
|
+
});
|
|
457
|
+
Pn(u, n);
|
|
458
|
+
const f = new Map(u.map((y) => [y.id, { x: y.x, y: y.y }]));
|
|
459
|
+
Ce(i, f, s, Le / 2);
|
|
460
|
+
const { positions: x, box: g } = Ie(i, f, s), w = g.maxY - g.minY;
|
|
461
|
+
if (d.length > 0) {
|
|
462
|
+
const { positions: y } = ve(
|
|
463
|
+
d,
|
|
464
|
+
s,
|
|
465
|
+
0,
|
|
466
|
+
w + Me
|
|
467
|
+
);
|
|
468
|
+
for (const [I, M] of y) x.set(I, M);
|
|
469
|
+
}
|
|
470
|
+
return Se(t, x, s);
|
|
471
|
+
}
|
|
472
|
+
const Hn = 120, de = 60, bt = 120;
|
|
473
|
+
function Gn(t, n, e) {
|
|
474
|
+
const o = (p) => {
|
|
475
|
+
var S;
|
|
476
|
+
return ((S = n.get(p)) == null ? void 0 : S.size) ?? 0;
|
|
477
|
+
}, c = [...t].sort((p, S) => o(S) - o(p))[0], i = /* @__PURE__ */ new Map([[c, null]]), d = /* @__PURE__ */ new Map([[c, 0]]), a = /* @__PURE__ */ new Map(), r = [c];
|
|
478
|
+
for (; r.length > 0; ) {
|
|
479
|
+
const p = r.shift(), S = [...n.get(p) ?? []].sort((N, L) => o(L) - o(N));
|
|
480
|
+
for (const N of S)
|
|
481
|
+
if (!i.has(N)) {
|
|
482
|
+
i.set(N, p), d.set(N, d.get(p) + 1);
|
|
483
|
+
const L = a.get(p) ?? [];
|
|
484
|
+
L.push(N), a.set(p, L), r.push(N);
|
|
485
|
+
}
|
|
486
|
+
}
|
|
487
|
+
const m = t.reduce((p, S) => {
|
|
488
|
+
const N = e.get(S);
|
|
489
|
+
return Math.max(p, N.width, N.height);
|
|
490
|
+
}, 0), u = m + Hn, f = m + de, x = /* @__PURE__ */ new Map([[c, { x: 0, y: 0 }]]), g = /* @__PURE__ */ new Map(), w = (p) => {
|
|
491
|
+
const S = a.get(p) ?? [];
|
|
492
|
+
if (S.length === 0)
|
|
493
|
+
return g.set(p, 1), 1;
|
|
494
|
+
const N = S.reduce((L, U) => L + w(U), 0);
|
|
495
|
+
return g.set(p, N), N;
|
|
496
|
+
};
|
|
497
|
+
w(c);
|
|
498
|
+
const y = (p) => {
|
|
499
|
+
const N = (a.get(c) ?? []).length * f / (2 * Math.PI);
|
|
500
|
+
return Math.max(u, N) + (p - 1) * u;
|
|
501
|
+
}, I = (p, S, N) => {
|
|
502
|
+
const L = a.get(p) ?? [];
|
|
503
|
+
if (L.length === 0) return;
|
|
504
|
+
const U = N - S, K = g.get(p), F = f * L.length / Math.max(U, 1e-3), j = Math.max(y(d.get(L[0])), F);
|
|
505
|
+
let Y = S;
|
|
506
|
+
for (const D of L) {
|
|
507
|
+
const q = g.get(D) / K, H = Y, k = Y + U * q, V = (H + k) / 2;
|
|
508
|
+
x.set(D, {
|
|
509
|
+
x: Math.cos(V) * j,
|
|
510
|
+
y: Math.sin(V) * j
|
|
511
|
+
}), I(D, H, k), Y = k;
|
|
512
|
+
}
|
|
513
|
+
};
|
|
514
|
+
I(c, 0, 2 * Math.PI), Ce(t, x, e, de / 2);
|
|
515
|
+
const { positions: M, box: E } = Ie(t, x, e);
|
|
516
|
+
return {
|
|
517
|
+
ids: t,
|
|
518
|
+
width: E.maxX - E.minX,
|
|
519
|
+
height: E.maxY - E.minY,
|
|
520
|
+
positions: M
|
|
521
|
+
};
|
|
522
|
+
}
|
|
523
|
+
function Bn(t, n, e = !0, o) {
|
|
524
|
+
const s = o ?? vt(t, e), c = It(n), { connected: i, islands: d } = Ne(
|
|
525
|
+
t.map((g) => g.id),
|
|
526
|
+
c
|
|
527
|
+
), a = Nn(i, c).map((g) => Gn(g, c, s)).sort((g, w) => w.ids.length - g.ids.length);
|
|
528
|
+
if (d.length > 0) {
|
|
529
|
+
const g = ve(d, s);
|
|
530
|
+
a.push({ ids: d, ...g });
|
|
531
|
+
}
|
|
532
|
+
const r = Math.max(...a.map((g) => g.width), 1) * 2 + bt, m = /* @__PURE__ */ new Map();
|
|
533
|
+
let u = 0, f = 0, x = 0;
|
|
534
|
+
for (const g of a) {
|
|
535
|
+
u > 0 && u + g.width > r && (u = 0, f += x + bt, x = 0);
|
|
536
|
+
for (const w of g.ids) {
|
|
537
|
+
const y = g.positions.get(w);
|
|
538
|
+
m.set(w, { x: u + y.x, y: f + y.y });
|
|
539
|
+
}
|
|
540
|
+
u += g.width + bt, x = Math.max(x, g.height);
|
|
541
|
+
}
|
|
542
|
+
return Se(t, m, s);
|
|
543
|
+
}
|
|
544
|
+
const $n = ["hierarchical", "radial", "force"], Ct = "radial";
|
|
545
|
+
function eo(t) {
|
|
546
|
+
return typeof t == "string" && $n.includes(t);
|
|
547
|
+
}
|
|
548
|
+
const Et = /* @__PURE__ */ new Map();
|
|
549
|
+
function Lt(t, n) {
|
|
550
|
+
Et.set(t, n);
|
|
551
|
+
}
|
|
552
|
+
function Un(t) {
|
|
553
|
+
return Et.get(t) ?? Et.get(Ct);
|
|
554
|
+
}
|
|
555
|
+
Lt(
|
|
556
|
+
"hierarchical",
|
|
557
|
+
(t, n) => Tn(t, n, !0, Nt(t))
|
|
558
|
+
);
|
|
559
|
+
Lt(
|
|
560
|
+
"radial",
|
|
561
|
+
(t, n) => Bn(t, n, !0, Nt(t))
|
|
562
|
+
);
|
|
563
|
+
Lt(
|
|
564
|
+
"force",
|
|
565
|
+
(t, n) => Dn(t, n, !0, Nt(t))
|
|
566
|
+
);
|
|
567
|
+
function Fn(t) {
|
|
568
|
+
const n = new Set(t.nodes.map((e) => e.id));
|
|
569
|
+
return t.edges.filter((e) => n.has(e.from_id) && n.has(e.to_id));
|
|
570
|
+
}
|
|
571
|
+
function Yn(t, n = Ct, e = !0, o = {}) {
|
|
572
|
+
const s = En(t.nodes, e, o.estimateSize), c = Un(n)(s, Fn(t), {
|
|
573
|
+
centerId: o.centerId ?? null
|
|
574
|
+
}), i = new Map(c.map((r) => [r.id, r])), d = t.nodes.map((r) => {
|
|
575
|
+
const m = i.get(r.id);
|
|
576
|
+
return {
|
|
577
|
+
id: r.id,
|
|
578
|
+
type: "erdTable",
|
|
579
|
+
data: { ...r, __collapse: e },
|
|
580
|
+
position: { x: m.x, y: m.y }
|
|
581
|
+
};
|
|
582
|
+
}), a = t.edges.flatMap((r) => Wn(r, o));
|
|
583
|
+
return { nodes: d, edges: a };
|
|
584
|
+
}
|
|
585
|
+
function le(t, n) {
|
|
586
|
+
return t && t.length > 0 ? t : n ? [n] : [];
|
|
587
|
+
}
|
|
588
|
+
function Wn(t, n) {
|
|
589
|
+
const e = le(t.from_columns, t.from_column), o = le(t.to_columns, t.to_column), s = (e.length > 1 || o.length > 1) && e.length > 0 && o.length > 0, c = n.animateEdge ? n.animateEdge(t) : !0, i = {};
|
|
590
|
+
if (c || (i.__animated = !1), n.edgePath === "smoothstep" && (i.__edgePath = "smoothstep"), s && n.compositeEdges === "fan") {
|
|
591
|
+
const d = Math.max(e.length, o.length);
|
|
592
|
+
return Array.from({ length: d }, (a, r) => ({
|
|
593
|
+
id: `${t.id}__${r}`,
|
|
594
|
+
source: t.from_id,
|
|
595
|
+
target: t.to_id,
|
|
596
|
+
type: "single",
|
|
597
|
+
animated: c,
|
|
598
|
+
data: {
|
|
599
|
+
from_column: e[Math.min(r, e.length - 1)] ?? null,
|
|
600
|
+
to_column: o[Math.min(r, o.length - 1)] ?? null,
|
|
601
|
+
relationship_type: t.relationship_type,
|
|
602
|
+
...i
|
|
603
|
+
}
|
|
604
|
+
}));
|
|
605
|
+
}
|
|
606
|
+
return s ? [
|
|
607
|
+
{
|
|
608
|
+
id: t.id,
|
|
609
|
+
source: t.from_id,
|
|
610
|
+
target: t.to_id,
|
|
611
|
+
type: "composite",
|
|
612
|
+
animated: c,
|
|
613
|
+
data: { from_columns: e, to_columns: o, ...i }
|
|
614
|
+
}
|
|
615
|
+
] : [
|
|
616
|
+
{
|
|
617
|
+
id: t.id,
|
|
618
|
+
source: t.from_id,
|
|
619
|
+
target: t.to_id,
|
|
620
|
+
type: "single",
|
|
621
|
+
animated: c,
|
|
622
|
+
data: {
|
|
623
|
+
from_column: e[0] ?? null,
|
|
624
|
+
to_column: o[0] ?? null,
|
|
625
|
+
relationship_type: t.relationship_type,
|
|
626
|
+
...i
|
|
627
|
+
}
|
|
628
|
+
}
|
|
629
|
+
];
|
|
630
|
+
}
|
|
631
|
+
function zn(t, n, e = 1) {
|
|
632
|
+
const o = /* @__PURE__ */ new Set([n]), s = It(t.edges);
|
|
633
|
+
let c = [n];
|
|
634
|
+
for (let i = e; i > 0 && c.length > 0; i--) {
|
|
635
|
+
const d = [];
|
|
636
|
+
for (const a of c)
|
|
637
|
+
for (const r of s.get(a) ?? [])
|
|
638
|
+
o.has(r) || (o.add(r), d.push(r));
|
|
639
|
+
c = d;
|
|
640
|
+
}
|
|
641
|
+
return o;
|
|
642
|
+
}
|
|
643
|
+
function Kn(t) {
|
|
644
|
+
return t.is_primary_key === !0 || t.is_foreign_key === !0;
|
|
645
|
+
}
|
|
646
|
+
function jn(t) {
|
|
647
|
+
const n = t.filter(Kn);
|
|
648
|
+
return n.length ? n : t;
|
|
649
|
+
}
|
|
650
|
+
function Vn(t, n) {
|
|
651
|
+
const { focus: e, focusDepth: o = 1, compact: s = !1 } = n;
|
|
652
|
+
let c = t.nodes, i = t.edges;
|
|
653
|
+
if (e) {
|
|
654
|
+
const d = zn(t, e, o);
|
|
655
|
+
c = c.filter((a) => d.has(a.id)), i = i.filter((a) => d.has(a.from_id) && d.has(a.to_id));
|
|
656
|
+
}
|
|
657
|
+
return s && (c = c.map((d) => {
|
|
658
|
+
const a = jn(d.columns), r = d.columns.length - a.length;
|
|
659
|
+
return r > 0 ? { ...d, columns: a, hidden_column_count: r } : { ...d, columns: a };
|
|
660
|
+
})), { ...t, nodes: c, edges: i };
|
|
661
|
+
}
|
|
662
|
+
const Xn = {
|
|
663
|
+
model: { color: "#2f6feb", icon: "table" },
|
|
664
|
+
source: { color: "#16a34a", icon: "database" },
|
|
665
|
+
seed: { color: "#b45309", icon: "table" },
|
|
666
|
+
snapshot: { color: "#7c3aed", icon: "table" }
|
|
667
|
+
}, ue = {
|
|
668
|
+
nodeBg: "--erd-node-bg",
|
|
669
|
+
nodeFg: "--erd-node-fg",
|
|
670
|
+
border: "--erd-border",
|
|
671
|
+
accent: "--erd-accent",
|
|
672
|
+
fk: "--erd-fk",
|
|
673
|
+
headerBg: "--erd-header-bg",
|
|
674
|
+
hoverBg: "--erd-hover-bg",
|
|
675
|
+
mutedFg: "--erd-muted-fg",
|
|
676
|
+
linkFg: "--erd-link-fg",
|
|
677
|
+
divider: "--erd-divider",
|
|
678
|
+
icon: "--erd-icon",
|
|
679
|
+
fontMono: "--erd-font-mono",
|
|
680
|
+
edge: "--erd-edge",
|
|
681
|
+
edgeSelected: "--erd-edge-selected",
|
|
682
|
+
edgeWidth: "--erd-edge-width",
|
|
683
|
+
edgeSelectedWidth: "--erd-edge-selected-width",
|
|
684
|
+
minimapBg: "--erd-minimap-bg",
|
|
685
|
+
minimapDim: "--erd-minimap-dim",
|
|
686
|
+
minimapMask: "--erd-minimap-mask",
|
|
687
|
+
shadow: "--erd-shadow"
|
|
688
|
+
};
|
|
689
|
+
function qn(t) {
|
|
690
|
+
if (!t) return {};
|
|
691
|
+
const n = {};
|
|
692
|
+
for (const e of Object.keys(ue)) {
|
|
693
|
+
const o = t[e];
|
|
694
|
+
o != null && (n[ue[e]] = o);
|
|
695
|
+
}
|
|
696
|
+
return n;
|
|
697
|
+
}
|
|
698
|
+
function me(t) {
|
|
699
|
+
return t.trim().toLowerCase();
|
|
700
|
+
}
|
|
701
|
+
function no(t) {
|
|
702
|
+
const {
|
|
703
|
+
data: n,
|
|
704
|
+
focus: e = null,
|
|
705
|
+
focusDepth: o = 1,
|
|
706
|
+
compact: s = !1,
|
|
707
|
+
collapseColumns: c = !0,
|
|
708
|
+
expandAll: i,
|
|
709
|
+
onExpandStateChange: d,
|
|
710
|
+
interactive: a = !0,
|
|
711
|
+
onNodeActivate: r,
|
|
712
|
+
onOpenNode: m,
|
|
713
|
+
resourceMeta: u,
|
|
714
|
+
labelFor: f,
|
|
715
|
+
theme: x,
|
|
716
|
+
colorMode: g = "dark",
|
|
717
|
+
minimap: w = !0,
|
|
718
|
+
controls: y = !0,
|
|
719
|
+
background: I = !0,
|
|
720
|
+
showSchema: M = !1,
|
|
721
|
+
compositeEdges: E = "bundle",
|
|
722
|
+
edgePath: p = "cubic",
|
|
723
|
+
animateEdge: S,
|
|
724
|
+
estimateSize: N,
|
|
725
|
+
dimOnSelect: L = !1,
|
|
726
|
+
onlyRenderVisibleElements: U = !1,
|
|
727
|
+
fitViewOptions: K,
|
|
728
|
+
refitKey: F,
|
|
729
|
+
className: j
|
|
730
|
+
} = t, Y = t.layout ?? t.defaultLayout ?? Ct, D = t.filter ?? "", q = t.hideUnconnected ?? !1, H = T(
|
|
731
|
+
() => ({ ...Xn, ...u ?? {} }),
|
|
732
|
+
[u]
|
|
733
|
+
), [k, V] = nt([]), [Z, ke] = nt([]), [Te, kt, Tt] = We([]), [O, At, Ae] = ze([]), [Rt, Ot] = nt(), [J, Pt] = nt(/* @__PURE__ */ new Set()), Dt = P((l) => {
|
|
734
|
+
Pt((_) => {
|
|
735
|
+
const h = new Set(_);
|
|
736
|
+
return h.has(l) ? h.delete(l) : h.add(l), h;
|
|
737
|
+
});
|
|
738
|
+
}, []), at = R(null), dt = R(!1), Ht = R(f);
|
|
739
|
+
Ht.current = f;
|
|
740
|
+
const Gt = R(N);
|
|
741
|
+
Gt.current = N;
|
|
742
|
+
const Bt = R(S);
|
|
743
|
+
Bt.current = S, W(() => {
|
|
744
|
+
const l = Vn(n, { focus: e, focusDepth: o, compact: s }), _ = Yn(l, Y, c, {
|
|
745
|
+
centerId: e ?? null,
|
|
746
|
+
estimateSize: Gt.current,
|
|
747
|
+
compositeEdges: E,
|
|
748
|
+
edgePath: p,
|
|
749
|
+
animateEdge: Bt.current
|
|
750
|
+
}), h = Ht.current;
|
|
751
|
+
if (h)
|
|
752
|
+
for (const C of _.nodes) C.data.name = h(C.data);
|
|
753
|
+
V(_.nodes), ke(_.edges), dt.current = !0;
|
|
754
|
+
}, [n, e, o, s, c, Y, E, p]);
|
|
755
|
+
const $t = T(() => {
|
|
756
|
+
const l = me(D);
|
|
757
|
+
if (!l) return /* @__PURE__ */ new Set();
|
|
758
|
+
const _ = /* @__PURE__ */ new Set();
|
|
759
|
+
for (const h of k)
|
|
760
|
+
me(h.data.name).includes(l) && _.add(h.id);
|
|
761
|
+
return _;
|
|
762
|
+
}, [D, k]), lt = D.trim().length > 0, Ut = T(
|
|
763
|
+
() => new Set(Z.flatMap((l) => [l.source, l.target])),
|
|
764
|
+
[Z]
|
|
765
|
+
), Q = T(
|
|
766
|
+
() => qe(O),
|
|
767
|
+
[O]
|
|
768
|
+
), Ft = T(() => {
|
|
769
|
+
const l = /* @__PURE__ */ new Map();
|
|
770
|
+
for (const [_, h] of Q)
|
|
771
|
+
l.set(_, [...h].sort().join(","));
|
|
772
|
+
return l;
|
|
773
|
+
}, [Q]), tt = T(
|
|
774
|
+
() => q ? k.filter((l) => l.id === e || Ut.has(l.id)) : k,
|
|
775
|
+
[k, Ut, q, e]
|
|
776
|
+
), G = T(
|
|
777
|
+
() => new Set(tt.map((l) => l.id)),
|
|
778
|
+
[tt]
|
|
779
|
+
), ut = T(() => {
|
|
780
|
+
if (!L) return /* @__PURE__ */ new Set();
|
|
781
|
+
const l = /* @__PURE__ */ new Set();
|
|
782
|
+
for (const _ of O)
|
|
783
|
+
_.selected && (l.add(_.source), l.add(_.target));
|
|
784
|
+
return l;
|
|
785
|
+
}, [L, O]), Yt = R(/* @__PURE__ */ new Map()), Wt = T(() => {
|
|
786
|
+
const l = Yt.current, _ = /* @__PURE__ */ new Map(), h = ut.size > 0, C = tt.map((v) => {
|
|
787
|
+
var qt;
|
|
788
|
+
const ht = lt ? $t.has(v.id) : !1, ft = v.id === Rt, gt = lt ? ht ? "match" : "dim" : void 0, Ue = Q.get(v.id), Xt = Ft.get(v.id) ?? "", pt = J.has(v.id), _t = ((qt = H[v.data.resource_type ?? ""]) == null ? void 0 : qt.icon) ?? "table", yt = v.id === e, xt = h && !ut.has(v.id), A = l.get(v.id);
|
|
789
|
+
let et;
|
|
790
|
+
return A && A.source === v && A.filterState === gt && A.active === ft && A.expanded === pt && A.highlightKey === Xt && A.icon === _t && A.focus === yt && A.dimmed === xt && A.showSchema === M ? et = A : et = {
|
|
791
|
+
source: v,
|
|
792
|
+
filterState: gt,
|
|
793
|
+
active: ft,
|
|
794
|
+
expanded: pt,
|
|
795
|
+
highlightKey: Xt,
|
|
796
|
+
icon: _t,
|
|
797
|
+
focus: yt,
|
|
798
|
+
dimmed: xt,
|
|
799
|
+
showSchema: M,
|
|
800
|
+
decorated: {
|
|
801
|
+
...v,
|
|
802
|
+
data: {
|
|
803
|
+
...v.data,
|
|
804
|
+
__filterState: gt,
|
|
805
|
+
__active: ft,
|
|
806
|
+
__highlightColumns: Ue,
|
|
807
|
+
__expanded: pt,
|
|
808
|
+
__onToggleExpand: Dt,
|
|
809
|
+
__icon: _t,
|
|
810
|
+
__focus: yt,
|
|
811
|
+
__dimmed: xt,
|
|
812
|
+
__showSchema: M
|
|
813
|
+
}
|
|
814
|
+
}
|
|
815
|
+
}, _.set(v.id, et), et.decorated;
|
|
816
|
+
});
|
|
817
|
+
return Yt.current = _, C;
|
|
818
|
+
}, [
|
|
819
|
+
tt,
|
|
820
|
+
$t,
|
|
821
|
+
lt,
|
|
822
|
+
Rt,
|
|
823
|
+
Q,
|
|
824
|
+
Ft,
|
|
825
|
+
J,
|
|
826
|
+
Dt,
|
|
827
|
+
H,
|
|
828
|
+
e,
|
|
829
|
+
ut,
|
|
830
|
+
M
|
|
831
|
+
]), zt = T(
|
|
832
|
+
() => Z.filter((l) => G.has(l.source) && G.has(l.target)),
|
|
833
|
+
[Z, G]
|
|
834
|
+
), mt = R(K);
|
|
835
|
+
mt.current = K;
|
|
836
|
+
const Kt = R(null);
|
|
837
|
+
W(() => {
|
|
838
|
+
var C;
|
|
839
|
+
kt(Wt);
|
|
840
|
+
const l = Kt.current, _ = l !== null && (l.size !== G.size || [...G].some((v) => !l.has(v)));
|
|
841
|
+
Kt.current = G;
|
|
842
|
+
const h = dt.current;
|
|
843
|
+
dt.current = !1, (_ || h) && ((C = at.current) == null || C.fitView({ duration: 200, ...mt.current }));
|
|
844
|
+
}, [Wt, kt, G]);
|
|
845
|
+
const jt = R(F);
|
|
846
|
+
W(() => {
|
|
847
|
+
if (jt.current === F) return;
|
|
848
|
+
jt.current = F;
|
|
849
|
+
const l = setTimeout(() => {
|
|
850
|
+
var _;
|
|
851
|
+
(_ = at.current) == null || _.fitView({ duration: 200, ...mt.current });
|
|
852
|
+
}, 120);
|
|
853
|
+
return () => clearTimeout(l);
|
|
854
|
+
}, [F]), W(() => {
|
|
855
|
+
At((l) => {
|
|
856
|
+
const _ = new Set(l.filter((h) => h.selected).map((h) => h.id));
|
|
857
|
+
return zt.map((h) => _.has(h.id) ? { ...h, selected: !0 } : h);
|
|
858
|
+
});
|
|
859
|
+
}, [zt, At]);
|
|
860
|
+
const Re = P(
|
|
861
|
+
(l, _) => {
|
|
862
|
+
var v;
|
|
863
|
+
const h = l.target;
|
|
864
|
+
if (!(h != null && h.closest(".erd-table-header"))) return;
|
|
865
|
+
Ot(_.id);
|
|
866
|
+
const C = (v = k.find((ht) => ht.id === _.id)) == null ? void 0 : v.data;
|
|
867
|
+
C && (r == null || r(C));
|
|
868
|
+
},
|
|
869
|
+
[k, r]
|
|
870
|
+
), Oe = P(
|
|
871
|
+
(l, _) => {
|
|
872
|
+
var C;
|
|
873
|
+
const h = (C = k.find((v) => v.id === _.id)) == null ? void 0 : C.data;
|
|
874
|
+
h && (m == null || m(h));
|
|
875
|
+
},
|
|
876
|
+
[k, m]
|
|
877
|
+
), Pe = P(
|
|
878
|
+
(l) => {
|
|
879
|
+
Tt(l);
|
|
880
|
+
const _ = /* @__PURE__ */ new Map();
|
|
881
|
+
for (const h of l)
|
|
882
|
+
h.type === "position" && h.dragging === !1 && h.position && _.set(h.id, h.position);
|
|
883
|
+
_.size !== 0 && V(
|
|
884
|
+
(h) => h.map((C) => {
|
|
885
|
+
const v = _.get(C.id);
|
|
886
|
+
return v ? { ...C, position: v } : C;
|
|
887
|
+
})
|
|
888
|
+
);
|
|
889
|
+
},
|
|
890
|
+
[Tt]
|
|
891
|
+
), De = P(() => {
|
|
892
|
+
Ot(void 0), r == null || r(null);
|
|
893
|
+
}, [r]), B = T(
|
|
894
|
+
() => c ? k.filter((l) => X(l.data.columns.length)).map((l) => l.id) : [],
|
|
895
|
+
[k, c]
|
|
896
|
+
), He = [...B].sort().join(",");
|
|
897
|
+
W(() => {
|
|
898
|
+
i !== void 0 && Pt(i ? new Set(B) : /* @__PURE__ */ new Set());
|
|
899
|
+
}, [i, He]);
|
|
900
|
+
const Vt = T(
|
|
901
|
+
() => B.length > 0 && B.every((l) => J.has(l)),
|
|
902
|
+
[B, J]
|
|
903
|
+
);
|
|
904
|
+
W(() => {
|
|
905
|
+
d == null || d({ allExpanded: Vt, canExpand: B.length > 0 });
|
|
906
|
+
}, [Vt, B.length, d]);
|
|
907
|
+
const Ge = P(
|
|
908
|
+
(l) => {
|
|
909
|
+
var C;
|
|
910
|
+
const _ = l.data ?? {};
|
|
911
|
+
if (_.__filterState === "dim")
|
|
912
|
+
return "var(--erd-minimap-dim, rgba(120, 120, 120, 0.45))";
|
|
913
|
+
const h = _.resource_type;
|
|
914
|
+
return h && ((C = H[h]) == null ? void 0 : C.color) || "var(--erd-border, #007acc)";
|
|
915
|
+
},
|
|
916
|
+
[H]
|
|
917
|
+
), Be = T(() => qn(x), [x]), $e = T(() => !L || !O.some((l) => l.selected) ? O : O.map(
|
|
918
|
+
(l) => l.selected ? { ...l, animated: !0 } : { ...l, style: { ...l.style, opacity: 0.1 } }
|
|
919
|
+
), [L, O]);
|
|
920
|
+
return /* @__PURE__ */ b("div", { className: `erd-flow${j ? ` ${j}` : ""}`, style: Be, children: /* @__PURE__ */ $(
|
|
921
|
+
Ke,
|
|
922
|
+
{
|
|
923
|
+
nodes: Te,
|
|
924
|
+
edges: $e,
|
|
925
|
+
onNodesChange: Pe,
|
|
926
|
+
onEdgesChange: Ae,
|
|
927
|
+
onNodeClick: Re,
|
|
928
|
+
onNodeDoubleClick: Oe,
|
|
929
|
+
onPaneClick: De,
|
|
930
|
+
nodeTypes: pn,
|
|
931
|
+
edgeTypes: ln,
|
|
932
|
+
onInit: (l) => {
|
|
933
|
+
at.current = l;
|
|
934
|
+
},
|
|
935
|
+
fitView: !0,
|
|
936
|
+
fitViewOptions: K,
|
|
937
|
+
onlyRenderVisibleElements: U,
|
|
938
|
+
minZoom: 0.05,
|
|
939
|
+
colorMode: g,
|
|
940
|
+
proOptions: { hideAttribution: !0 },
|
|
941
|
+
panOnDrag: a,
|
|
942
|
+
zoomOnScroll: a,
|
|
943
|
+
zoomOnPinch: a,
|
|
944
|
+
zoomOnDoubleClick: a,
|
|
945
|
+
nodesDraggable: a,
|
|
946
|
+
panOnScroll: !1,
|
|
947
|
+
children: [
|
|
948
|
+
I ? /* @__PURE__ */ b(je, {}) : null,
|
|
949
|
+
y ? /* @__PURE__ */ b(Ve, {}) : null,
|
|
950
|
+
w ? /* @__PURE__ */ b(
|
|
951
|
+
Xe,
|
|
952
|
+
{
|
|
953
|
+
position: "bottom-right",
|
|
954
|
+
pannable: !0,
|
|
955
|
+
zoomable: !0,
|
|
956
|
+
ariaLabel: "Mini-map",
|
|
957
|
+
nodeColor: Ge,
|
|
958
|
+
nodeStrokeColor: "var(--erd-border, #007acc)",
|
|
959
|
+
nodeStrokeWidth: 2,
|
|
960
|
+
nodeBorderRadius: 4,
|
|
961
|
+
maskColor: "var(--erd-minimap-mask, rgba(0, 0, 0, 0.4))",
|
|
962
|
+
style: {
|
|
963
|
+
background: "var(--erd-minimap-bg, #1e1e1e)",
|
|
964
|
+
border: "1px solid var(--erd-divider, #3c3c3c)",
|
|
965
|
+
borderRadius: 6
|
|
966
|
+
}
|
|
967
|
+
}
|
|
968
|
+
) : null
|
|
969
|
+
]
|
|
970
|
+
}
|
|
971
|
+
) });
|
|
972
|
+
}
|
|
973
|
+
export {
|
|
974
|
+
Ct as DEFAULT_LAYOUT,
|
|
975
|
+
Xn as DEFAULT_RESOURCE_META,
|
|
976
|
+
no as ErdFlow,
|
|
977
|
+
$n as LAYOUT_STYLES,
|
|
978
|
+
jn as compactColumns,
|
|
979
|
+
zn as erdNeighborhood,
|
|
980
|
+
eo as isLayoutStyle,
|
|
981
|
+
En as measureNodes,
|
|
982
|
+
Lt as registerLayout,
|
|
983
|
+
Un as resolveLayout,
|
|
984
|
+
qn as themeStyle,
|
|
985
|
+
Yn as toFlowGraph,
|
|
986
|
+
Vn as windowPayload
|
|
987
|
+
};
|