drizzle-cube 0.4.26 → 0.4.27

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.
@@ -0,0 +1,578 @@
1
+ import { jsx as e, jsxs as u, Fragment as ve } from "react/jsx-runtime";
2
+ import { createContext as we, useContext as Ce, useState as k, useEffect as P, Suspense as ke, lazy as Ee, useMemo as z, useRef as $, useCallback as _ } from "react";
3
+ import { u as Se } from "./providers-Ds7DRmnO.js";
4
+ import { g as ee } from "./icons-CwvgmdIP.js";
5
+ const ne = we(null), Le = ne.Provider;
6
+ function V() {
7
+ const c = Ce(ne);
8
+ if (!c) throw new Error("useXyflow must be used within XyflowProvider");
9
+ return c;
10
+ }
11
+ let Z = !1;
12
+ function Me(c) {
13
+ return /* @__PURE__ */ e("div", { className: "dc:flex dc:items-center dc:justify-center dc:h-full dc:p-8", children: /* @__PURE__ */ u("div", { className: "dc:text-center dc:max-w-md", children: [
14
+ /* @__PURE__ */ e("div", { className: "dc:text-4xl dc:mb-4", children: "🔍" }),
15
+ /* @__PURE__ */ e("h3", { className: "dc:text-lg dc:font-semibold text-dc-text dc:mb-2", children: "Schema Visualization requires additional packages" }),
16
+ /* @__PURE__ */ e("p", { className: "dc:text-sm text-dc-text-secondary dc:mb-4", children: "Install the required dependencies to enable the interactive schema diagram:" }),
17
+ /* @__PURE__ */ e("code", { className: "dc:block dc:px-4 dc:py-2 dc:rounded bg-dc-surface-secondary dc:text-sm dc:font-mono text-dc-text dc:border border-dc-border", children: "npm install @xyflow/react elkjs" })
18
+ ] }) });
19
+ }
20
+ function te() {
21
+ return /* @__PURE__ */ e("div", { className: "dc:flex dc:items-center dc:justify-center dc:h-full", children: /* @__PURE__ */ u("div", { className: "dc:text-center", children: [
22
+ /* @__PURE__ */ e("div", { className: "dc:animate-spin dc:rounded-full dc:h-8 dc:w-8 dc:border-b-2 border-dc-accent dc:mx-auto dc:mb-2" }),
23
+ /* @__PURE__ */ e("p", { className: "dc:text-sm text-dc-text-muted", children: "Loading schema visualization..." })
24
+ ] }) });
25
+ }
26
+ const Re = Ee(async () => ({ default: (await Promise.resolve().then(() => Ae)).SchemaVisualization }));
27
+ function Ke(c) {
28
+ const [d, i] = k(null), [s, o] = k(Z);
29
+ return P(() => {
30
+ if (Z) return;
31
+ let a = !1;
32
+ return import("@xyflow/react").then((p) => {
33
+ a || i(p);
34
+ }).catch(() => {
35
+ Z = !0, a || o(!0);
36
+ }), () => {
37
+ a = !0;
38
+ };
39
+ }, []), s ? /* @__PURE__ */ e(Me, { ...c }) : d ? /* @__PURE__ */ e(Le, { value: d, children: /* @__PURE__ */ e(ke, { fallback: /* @__PURE__ */ e(te, {}), children: /* @__PURE__ */ e(Re, { ...c }) }) }) : /* @__PURE__ */ e(te, {});
40
+ }
41
+ function Te({ data: c }) {
42
+ const { Handle: d, Position: i } = V(), { cube: s, onFieldClick: o, isHighlighted: a, highlightedFields: p, searchTerm: h } = c, N = (t, f) => {
43
+ o && o(s.name, t, f);
44
+ }, x = (t) => p.includes(t), b = (t) => {
45
+ if (!h?.trim()) return !0;
46
+ const f = h.toLowerCase();
47
+ return t.name.toLowerCase().includes(f) || t.title && t.title.toLowerCase().includes(f);
48
+ }, E = h?.trim() ? s.measures.some((t) => b(t)) || s.dimensions.some((t) => b(t)) : !0, w = (t, f, C) => {
49
+ const v = "dc:px-4 dc:py-2 dc:text-xs dc:cursor-pointer dc:transition-all dc:border-b border-dc-border last:dc:border-b-0 nodrag nopan";
50
+ return !E && h?.trim() ? f ? `${v} bg-dc-accent-bg text-dc-accent dc:font-semibold` : `${v} dc:hover:bg-dc-surface-hover text-dc-text-secondary` : h?.trim() && !b(t) ? `${v} dc:opacity-40 dc:hover:opacity-60 text-dc-text-muted` : h?.trim() && b(t) && !f ? `${v} dc:font-bold dc:hover:bg-dc-accent-bg` : f ? `${v} bg-dc-accent-bg text-dc-accent dc:font-semibold` : `${v} dc:hover:bg-dc-surface-hover text-dc-text-secondary`;
51
+ }, n = s.dimensions.filter((t) => t.type === "time"), g = s.dimensions.filter((t) => t.type !== "time");
52
+ return /* @__PURE__ */ u(
53
+ "div",
54
+ {
55
+ className: `
56
+ dc:border-2 dc:rounded-lg dc:shadow-lg dc:min-w-[280px] dc:overflow-hidden dc:transition-all
57
+ ${!E && h?.trim() ? "dc:opacity-30 dc:grayscale" : ""}
58
+ ${a ? "border-dc-accent dc:ring-2 ring-dc-accent" : "border-dc-border"}
59
+ `,
60
+ style: { backgroundColor: "var(--dc-surface)" },
61
+ children: [
62
+ /* @__PURE__ */ e("div", { className: `dc:px-4 dc:py-3 dc:transition-colors ${a ? "bg-dc-accent-bg" : "bg-dc-surface-secondary dc:hover:bg-dc-surface-hover"}`, children: /* @__PURE__ */ u("div", { className: "dc:flex dc:items-center dc:justify-between", children: [
63
+ /* @__PURE__ */ u("div", { children: [
64
+ /* @__PURE__ */ e("h3", { className: "dc:font-semibold text-dc-text dc:text-sm", children: s.title || s.name }),
65
+ s.description && /* @__PURE__ */ e("p", { className: "dc:text-xs text-dc-text-muted dc:mt-1 dc:line-clamp-2", children: s.description })
66
+ ] }),
67
+ /* @__PURE__ */ u("div", { className: "dc:text-xs text-dc-text-muted dc:ml-2", children: [
68
+ /* @__PURE__ */ u("div", { children: [
69
+ s.measures.length,
70
+ "M"
71
+ ] }),
72
+ /* @__PURE__ */ u("div", { children: [
73
+ s.dimensions.length,
74
+ "D"
75
+ ] })
76
+ ] })
77
+ ] }) }),
78
+ s.measures.length > 0 && /* @__PURE__ */ u("div", { className: "dc:border-t border-dc-border", children: [
79
+ /* @__PURE__ */ e("div", { className: "dc:px-4 dc:py-1.5 dc:border-b border-dc-border", style: { backgroundColor: "color-mix(in srgb, var(--dc-warning) 10%, var(--dc-surface))" }, children: /* @__PURE__ */ u("h4", { className: "dc:text-xs dc:font-medium text-dc-text-secondary dc:flex dc:items-center", children: [
80
+ /* @__PURE__ */ e("span", { className: "dc:w-2 dc:h-2 bg-dc-warning dc:rounded-full dc:mr-2" }),
81
+ "Measures (",
82
+ s.measures.length,
83
+ ")"
84
+ ] }) }),
85
+ /* @__PURE__ */ e("div", { className: "dc:max-h-64 dc:overflow-y-auto nowheel", children: s.measures.map((t) => {
86
+ const f = t.name.split(".")[1] || t.name, C = x(t.name);
87
+ return /* @__PURE__ */ e(
88
+ "div",
89
+ {
90
+ className: w(t, C),
91
+ onClick: () => N(f, "measure"),
92
+ title: t.title,
93
+ children: /* @__PURE__ */ u("div", { className: "dc:flex dc:items-center dc:justify-between", children: [
94
+ /* @__PURE__ */ e("span", { className: "dc:font-mono dc:truncate", children: t.shortTitle || t.title || f }),
95
+ /* @__PURE__ */ e("span", { className: "text-dc-text-muted dc:ml-2 dc:text-[10px] dc:uppercase", children: t.type })
96
+ ] })
97
+ },
98
+ t.name
99
+ );
100
+ }) })
101
+ ] }),
102
+ n.length > 0 && /* @__PURE__ */ u("div", { className: "dc:border-t border-dc-border", children: [
103
+ /* @__PURE__ */ e("div", { className: "dc:px-4 dc:py-1.5 dc:border-b border-dc-border", style: { backgroundColor: "color-mix(in srgb, var(--dc-accent) 10%, var(--dc-surface))" }, children: /* @__PURE__ */ u("h4", { className: "dc:text-xs dc:font-medium text-dc-text-secondary dc:flex dc:items-center", children: [
104
+ /* @__PURE__ */ e("span", { className: "dc:w-2 dc:h-2 bg-dc-accent dc:rounded-full dc:mr-2" }),
105
+ "Time Dimensions (",
106
+ n.length,
107
+ ")"
108
+ ] }) }),
109
+ /* @__PURE__ */ e("div", { className: "dc:max-h-64 dc:overflow-y-auto nowheel", children: n.map((t) => {
110
+ const f = t.name.split(".")[1] || t.name, C = x(t.name);
111
+ return /* @__PURE__ */ e(
112
+ "div",
113
+ {
114
+ className: w(t, C),
115
+ onClick: () => N(f, "dimension"),
116
+ title: t.title,
117
+ children: /* @__PURE__ */ u("div", { className: "dc:flex dc:items-center dc:justify-between", children: [
118
+ /* @__PURE__ */ e("span", { className: "dc:font-mono dc:truncate", children: t.shortTitle || t.title || f }),
119
+ /* @__PURE__ */ e("span", { className: "text-dc-text-muted dc:ml-2 dc:text-[10px] dc:uppercase", children: t.type })
120
+ ] })
121
+ },
122
+ t.name
123
+ );
124
+ }) })
125
+ ] }),
126
+ g.length > 0 && /* @__PURE__ */ u("div", { className: "dc:border-t border-dc-border", children: [
127
+ /* @__PURE__ */ e("div", { className: "dc:px-4 dc:py-1.5 dc:border-b border-dc-border", style: { backgroundColor: "color-mix(in srgb, var(--dc-success) 10%, var(--dc-surface))" }, children: /* @__PURE__ */ u("h4", { className: "dc:text-xs dc:font-medium text-dc-text-secondary dc:flex dc:items-center", children: [
128
+ /* @__PURE__ */ e("span", { className: "dc:w-2 dc:h-2 bg-dc-success dc:rounded-full dc:mr-2" }),
129
+ "Dimensions (",
130
+ g.length,
131
+ ")"
132
+ ] }) }),
133
+ /* @__PURE__ */ e("div", { className: "dc:max-h-64 dc:overflow-y-auto nowheel", children: g.map((t) => {
134
+ const f = t.name.split(".")[1] || t.name, C = x(t.name);
135
+ return /* @__PURE__ */ e(
136
+ "div",
137
+ {
138
+ className: w(t, C),
139
+ onClick: () => N(f, "dimension"),
140
+ title: t.title,
141
+ children: /* @__PURE__ */ u("div", { className: "dc:flex dc:items-center dc:justify-between", children: [
142
+ /* @__PURE__ */ e("span", { className: "dc:font-mono dc:truncate", children: t.shortTitle || t.title || f }),
143
+ /* @__PURE__ */ e("span", { className: "text-dc-text-muted dc:ml-2 dc:text-[10px] dc:uppercase", children: t.type })
144
+ ] })
145
+ },
146
+ t.name
147
+ );
148
+ }) })
149
+ ] }),
150
+ /* @__PURE__ */ e(d, { type: "source", position: i.Right, id: "right", className: "dc:opacity-0", isConnectable: !1 }),
151
+ /* @__PURE__ */ e(d, { type: "target", position: i.Left, id: "left", className: "dc:opacity-0", isConnectable: !1 }),
152
+ /* @__PURE__ */ e(d, { type: "source", position: i.Bottom, id: "bottom", className: "dc:opacity-0", isConnectable: !1 }),
153
+ /* @__PURE__ */ e(d, { type: "target", position: i.Top, id: "top", className: "dc:opacity-0", isConnectable: !1 })
154
+ ]
155
+ }
156
+ );
157
+ }
158
+ function $e({
159
+ sourceX: c,
160
+ sourceY: d,
161
+ targetX: i,
162
+ targetY: s,
163
+ sourcePosition: o,
164
+ targetPosition: a,
165
+ style: p = {},
166
+ data: h,
167
+ markerEnd: N
168
+ }) {
169
+ const { getBezierPath: x, BaseEdge: b, EdgeLabelRenderer: l } = V(), [E, w, n] = x({
170
+ sourceX: c,
171
+ sourceY: d,
172
+ sourcePosition: o,
173
+ targetX: i,
174
+ targetY: s,
175
+ targetPosition: a
176
+ });
177
+ if (!h) return null;
178
+ const { relationship: g, joinFields: t } = h, f = (L) => {
179
+ switch (L) {
180
+ case "belongsTo":
181
+ return "∈";
182
+ // belongs to
183
+ case "hasOne":
184
+ return "1:1";
185
+ case "hasMany":
186
+ return "1:M";
187
+ case "belongsToMany":
188
+ return "M:M";
189
+ default:
190
+ return "?";
191
+ }
192
+ }, v = ((L) => {
193
+ switch (L) {
194
+ case "belongsTo":
195
+ return "#10b981";
196
+ case "hasOne":
197
+ return "#3b82f6";
198
+ case "hasMany":
199
+ return "#f59e0b";
200
+ case "belongsToMany":
201
+ return "#8b5cf6";
202
+ default:
203
+ return "#6b7280";
204
+ }
205
+ })(g.relationship), M = f(g.relationship);
206
+ return /* @__PURE__ */ u(ve, { children: [
207
+ /* @__PURE__ */ e(b, { path: E, markerEnd: N, style: { ...p, stroke: v } }),
208
+ /* @__PURE__ */ e(l, { children: /* @__PURE__ */ e(
209
+ "div",
210
+ {
211
+ style: {
212
+ position: "absolute",
213
+ transform: `translate(-50%, -50%) translate(${w}px,${n}px)`,
214
+ fontSize: 10,
215
+ pointerEvents: "all"
216
+ },
217
+ className: "nodrag nopan",
218
+ children: /* @__PURE__ */ e(
219
+ "div",
220
+ {
221
+ className: "dc:border-2 dc:rounded-md dc:px-2 dc:py-1 dc:shadow-xs",
222
+ style: { backgroundColor: "var(--dc-surface)", borderColor: v },
223
+ children: /* @__PURE__ */ u("div", { className: "dc:text-center", children: [
224
+ /* @__PURE__ */ e("div", { className: "dc:font-bold dc:text-xs dc:mb-1", style: { color: v }, children: M }),
225
+ /* @__PURE__ */ e("div", { className: "dc:text-[9px] text-dc-text-muted dc:leading-tight", children: t.map((L, I) => /* @__PURE__ */ u("div", { className: "dc:font-mono", children: [
226
+ L.sourceField,
227
+ " → ",
228
+ L.targetField
229
+ ] }, I)) })
230
+ ] })
231
+ }
232
+ )
233
+ }
234
+ ) })
235
+ ] });
236
+ }
237
+ const _e = {
238
+ direction: "LR",
239
+ nodeWidth: 340,
240
+ nodeSep: 150,
241
+ rankSep: 350
242
+ };
243
+ function de(c) {
244
+ switch (c) {
245
+ case "TB":
246
+ return "top";
247
+ case "LR":
248
+ return "left";
249
+ default:
250
+ return "top";
251
+ }
252
+ }
253
+ function re(c) {
254
+ switch (c) {
255
+ case "TB":
256
+ return "bottom";
257
+ case "LR":
258
+ return "right";
259
+ default:
260
+ return "bottom";
261
+ }
262
+ }
263
+ function se(c) {
264
+ const d = c.data?.cube;
265
+ if (!d) return 300;
266
+ const i = d.description ? 80 : 56, s = 36, o = 34, a = 256, p = 30;
267
+ let h = i;
268
+ const N = d.measures?.length ?? 0, x = d.dimensions?.filter((l) => l.type === "time").length ?? 0, b = d.dimensions?.filter((l) => l.type !== "time").length ?? 0;
269
+ return N > 0 && (h += s + Math.min(N * o, a)), x > 0 && (h += s + Math.min(x * o, a)), b > 0 && (h += s + Math.min(b * o, a)), h + p;
270
+ }
271
+ let W = null;
272
+ const Pe = import("elkjs/lib/elk.bundled.js").then((c) => {
273
+ const d = c.default || c;
274
+ return W = new d(), W;
275
+ }).catch(() => null);
276
+ async function Ie(c, d, i) {
277
+ if (await Pe, !W)
278
+ return { nodes: oe(c, i), edges: d };
279
+ const s = i.direction === "LR" ? "EAST" : "SOUTH", o = i.direction === "LR" ? "WEST" : "NORTH", a = /* @__PURE__ */ new Map(), p = /* @__PURE__ */ new Map();
280
+ d.forEach((n) => {
281
+ a.has(n.source) || a.set(n.source, []), a.get(n.source).push(n.id), p.has(n.target) || p.set(n.target, []), p.get(n.target).push(n.id);
282
+ });
283
+ const h = c.map((n) => {
284
+ const g = i.nodeWidth, t = se(n), f = a.get(n.id) || [], C = p.get(n.id) || [], v = [
285
+ ...f.map((M) => ({
286
+ id: `${n.id}__src__${M}`,
287
+ layoutOptions: { "elk.port.side": s }
288
+ })),
289
+ ...C.map((M) => ({
290
+ id: `${n.id}__tgt__${M}`,
291
+ layoutOptions: { "elk.port.side": o }
292
+ }))
293
+ ];
294
+ return {
295
+ id: n.id,
296
+ width: g,
297
+ height: t,
298
+ layoutOptions: { "elk.portConstraints": "FIXED_SIDE" },
299
+ ports: v
300
+ };
301
+ }), N = d.map((n) => ({
302
+ id: n.id,
303
+ sources: [`${n.source}__src__${n.id}`],
304
+ targets: [`${n.target}__tgt__${n.id}`]
305
+ })), b = {
306
+ id: "root",
307
+ layoutOptions: {
308
+ "elk.algorithm": "layered",
309
+ "elk.direction": i.direction === "LR" ? "RIGHT" : "DOWN",
310
+ "elk.edgeRouting": "SPLINES",
311
+ "elk.layered.edgeRouting.splines.mode": "CONSERVATIVE",
312
+ "elk.spacing.nodeNode": String(i.nodeSep),
313
+ "elk.layered.spacing.nodeNodeBetweenLayers": String(i.rankSep),
314
+ "elk.spacing.edgeNode": "60",
315
+ "elk.layered.spacing.edgeNodeBetweenLayers": "60",
316
+ "elk.spacing.edgeEdge": "25",
317
+ "elk.layered.nodePlacement.strategy": "NETWORK_SIMPLEX",
318
+ "elk.layered.crossingMinimization.strategy": "LAYER_SWEEP"
319
+ },
320
+ children: h,
321
+ edges: N
322
+ }, l = await W.layout(b), E = /* @__PURE__ */ new Map();
323
+ if (l.children)
324
+ for (const n of l.children)
325
+ E.set(n.id, { x: n.x, y: n.y });
326
+ return { nodes: c.map((n) => ({
327
+ ...n,
328
+ position: E.get(n.id) || n.position,
329
+ targetPosition: de(i.direction),
330
+ sourcePosition: re(i.direction)
331
+ })), edges: d };
332
+ }
333
+ function oe(c, d) {
334
+ let s = 0, o = 0;
335
+ return c.map((a) => {
336
+ const p = se(a);
337
+ o + p > 1200 && o > 0 && (s++, o = 0);
338
+ const h = { x: s * (d.nodeWidth + d.nodeSep), y: o };
339
+ return o += p + 40, {
340
+ ...a,
341
+ position: h,
342
+ sourcePosition: re(d.direction),
343
+ targetPosition: de(d.direction)
344
+ };
345
+ });
346
+ }
347
+ function Oe(c, d, i = {}) {
348
+ const s = z(
349
+ () => ({ ..._e, ...i }),
350
+ // eslint-disable-next-line react-hooks/exhaustive-deps
351
+ [i.direction, i.nodeWidth, i.nodeSep, i.rankSep]
352
+ ), o = z(() => c.length === 0 ? "" : c.map((g) => g.id).sort().join(",") + "|" + d.map((g) => g.id).sort().join(","), [c, d]), a = $(c), p = $(d), h = $(s);
353
+ a.current = c, p.current = d, h.current = s;
354
+ const [N, x] = k("waiting"), [b, l] = k(null), [E, w] = k(""), n = $(0);
355
+ return P(() => {
356
+ if (!o) {
357
+ x("ready"), l(null), w("");
358
+ return;
359
+ }
360
+ const g = ++n.current;
361
+ x("computing"), Ie(a.current, p.current, h.current).then((t) => {
362
+ g === n.current && (l(t), w(o), x("ready"));
363
+ }).catch(() => {
364
+ g === n.current && (l({
365
+ nodes: oe(a.current, h.current),
366
+ edges: p.current
367
+ }), w(o), x("ready"));
368
+ });
369
+ }, [o]), N === "ready" && b && E === o ? { nodes: b.nodes, edges: b.edges, phase: "ready" } : { nodes: [], edges: [], phase: N };
370
+ }
371
+ const je = { cubeNode: Te }, ze = { relationshipEdge: $e };
372
+ function Fe({ token: c }) {
373
+ const { useNodesInitialized: d, useReactFlow: i } = V(), s = d(), { fitView: o } = i(), a = $(0);
374
+ return P(() => {
375
+ c === 0 || c === a.current || s && (a.current = c, o({ padding: 0.1 }));
376
+ }, [c, s, o]), null;
377
+ }
378
+ const ce = [];
379
+ function De(c) {
380
+ switch (c) {
381
+ case "belongsTo":
382
+ return "#10b981";
383
+ case "hasOne":
384
+ return "#3b82f6";
385
+ case "hasMany":
386
+ return "#f59e0b";
387
+ case "belongsToMany":
388
+ return "#8b5cf6";
389
+ default:
390
+ return "#6b7280";
391
+ }
392
+ }
393
+ function He({
394
+ className: c = "",
395
+ onFieldClick: d,
396
+ highlightedCubes: i,
397
+ highlightedFields: s,
398
+ searchTerm: o,
399
+ height: a = "100%"
400
+ }) {
401
+ const {
402
+ ReactFlow: p,
403
+ Controls: h,
404
+ MiniMap: N,
405
+ Background: x,
406
+ applyNodeChanges: b
407
+ } = V(), { meta: l, metaLoading: E, metaError: w } = Se(), n = i || ce, g = s || ce, [t, f] = k(null), [C, v] = k(o || ""), [M, L] = k(0), [I, X] = k({}), [B, ie] = k(!1), ae = ee("search"), le = ee("close"), F = o !== void 0 ? o : C;
408
+ P(() => {
409
+ try {
410
+ const r = localStorage.getItem("drizzle-cube-erd-node-positions");
411
+ r && X(JSON.parse(r));
412
+ } catch {
413
+ }
414
+ ie(!0);
415
+ }, []);
416
+ const { structuralNodes: K, structuralEdges: G } = z(() => {
417
+ if (!l) return { structuralNodes: [], structuralEdges: [] };
418
+ const r = l.cubes.map((m, y) => ({
419
+ id: m.name,
420
+ type: "cubeNode",
421
+ // Placeholder position — ELK will override for auto-layout
422
+ position: { x: y % 3 * 400, y: Math.floor(y / 3) * 300 },
423
+ data: { cube: m }
424
+ })), S = [];
425
+ return l.cubes.forEach((m) => {
426
+ m.relationships && m.relationships.forEach((y, T) => {
427
+ y.relationship !== "belongsTo" && S.push({
428
+ id: `${m.name}-${y.targetCube}-${T}`,
429
+ source: m.name,
430
+ target: y.targetCube,
431
+ type: "relationshipEdge",
432
+ data: { relationship: y, joinFields: y.joinFields || [] },
433
+ animated: !1,
434
+ style: { stroke: De(y.relationship), strokeWidth: 2 }
435
+ });
436
+ });
437
+ }), { structuralNodes: r, structuralEdges: S };
438
+ }, [l]), R = M > 0 || B && Object.keys(I).length === 0, { nodes: Y, edges: q, phase: ue } = Oe(
439
+ R ? K : [],
440
+ R ? G : [],
441
+ { direction: "LR", nodeWidth: 340, nodeSep: 150, rankSep: 350 }
442
+ ), O = _((r) => ({
443
+ cube: r,
444
+ onFieldClick: d,
445
+ isHighlighted: n.includes(r.name),
446
+ highlightedFields: g,
447
+ searchTerm: F
448
+ }), [d, n, g, F]), j = !R || ue === "ready", D = z(() => !l || !j || !B ? [] : R && Y.length > 0 ? Y.map((r) => ({
449
+ ...r,
450
+ data: O(r.data?.cube || l.cubes.find((S) => S.name === r.id))
451
+ })) : K.map((r) => ({
452
+ ...r,
453
+ position: I[r.id] || r.position,
454
+ data: O(r.data?.cube)
455
+ })), [l, j, B, R, Y, K, I, O]), U = z(() => !l || !j ? [] : R && q.length > 0 ? q : G, [l, j, R, q, G]), [J, H] = k([]), [me, he] = k([]), A = $(""), [fe, pe] = k(0);
456
+ P(() => {
457
+ if (D.length === 0) return;
458
+ const r = D.map((m) => `${m.id}:${Math.round(m.position.x)},${Math.round(m.position.y)}`).join("|");
459
+ if (r === A.current) return;
460
+ const S = A.current === "";
461
+ A.current = r, H(D), he(U), S && pe((m) => m + 1);
462
+ }, [D, U]);
463
+ const Q = $("");
464
+ P(() => {
465
+ const r = `${n.join(",")}|${g.join(",")}|${F}|${String(d)}`;
466
+ r !== Q.current && (Q.current = r, !(J.length === 0 || !l) && H((S) => S.map((m) => {
467
+ const y = l.cubes.find((T) => T.name === m.id);
468
+ return y ? { ...m, data: O(y) } : m;
469
+ })));
470
+ }, [n, g, F, d, J.length, l, O]);
471
+ const ge = _((r) => {
472
+ H((m) => b(r, m)), r.filter(
473
+ (m) => m.type === "position" && "dragging" in m && m.dragging === !1
474
+ ).length > 0 && H((m) => {
475
+ const y = {};
476
+ m.forEach((T) => {
477
+ T.position && (y[T.id] = T.position);
478
+ });
479
+ try {
480
+ localStorage.setItem("drizzle-cube-erd-node-positions", JSON.stringify(y));
481
+ } catch {
482
+ }
483
+ return X(y), m;
484
+ });
485
+ }, []), be = _((r) => {
486
+ }, []), xe = _((r) => {
487
+ r.preventDefault(), r.stopPropagation(), f({ x: r.clientX, y: r.clientY });
488
+ }, []), ye = _(() => {
489
+ t && f(null);
490
+ }, [t]), Ne = _(() => {
491
+ X({}), A.current = "";
492
+ try {
493
+ localStorage.removeItem("drizzle-cube-erd-node-positions");
494
+ } catch {
495
+ }
496
+ L((r) => r + 1), f(null);
497
+ }, []);
498
+ return E ? /* @__PURE__ */ e("div", { className: `dc:flex dc:items-center dc:justify-center dc:h-96 ${c}`, children: /* @__PURE__ */ u("div", { className: "dc:text-center", children: [
499
+ /* @__PURE__ */ e("div", { className: "dc:animate-spin dc:rounded-full dc:h-8 dc:w-8 dc:border-b-2 border-dc-accent dc:mx-auto dc:mb-2" }),
500
+ /* @__PURE__ */ e("p", { className: "text-dc-text-muted", children: "Loading cube schema..." })
501
+ ] }) }) : w ? /* @__PURE__ */ e("div", { className: `dc:flex dc:items-center dc:justify-center dc:h-96 ${c}`, children: /* @__PURE__ */ u("div", { className: "dc:text-center text-dc-error", children: [
502
+ /* @__PURE__ */ e("p", { className: "dc:font-medium", children: "Failed to load cube schema" }),
503
+ /* @__PURE__ */ e("p", { className: "dc:text-sm dc:mt-1", children: w })
504
+ ] }) }) : !l || l.cubes.length === 0 ? /* @__PURE__ */ e("div", { className: `dc:flex dc:items-center dc:justify-center dc:h-96 ${c}`, children: /* @__PURE__ */ u("div", { className: "dc:text-center text-dc-text-muted", children: [
505
+ /* @__PURE__ */ e("p", { className: "dc:font-medium", children: "No cubes found" }),
506
+ /* @__PURE__ */ e("p", { className: "dc:text-sm dc:mt-1", children: "Register some cubes to see the relationship diagram" })
507
+ ] }) }) : j ? /* @__PURE__ */ u("div", { className: `dc:flex dc:flex-col ${c}`, style: { height: a, minHeight: 400 }, children: [
508
+ o === void 0 && /* @__PURE__ */ u("div", { className: "dc:px-3 dc:py-2 dc:border-b border-dc-border bg-dc-surface dc:flex dc:items-center dc:gap-2 dc:flex-shrink-0", children: [
509
+ /* @__PURE__ */ e(ae, { className: "dc:w-4 dc:h-4 text-dc-text-muted" }),
510
+ /* @__PURE__ */ e(
511
+ "input",
512
+ {
513
+ type: "text",
514
+ value: C,
515
+ onChange: (r) => v(r.target.value),
516
+ placeholder: "Search cubes and fields...",
517
+ className: "dc:flex-1 dc:text-sm dc:bg-transparent dc:outline-none text-dc-text dc:placeholder:text-dc-text-muted"
518
+ }
519
+ ),
520
+ C && /* @__PURE__ */ e("button", { onClick: () => v(""), className: "text-dc-text-muted dc:hover:text-dc-text", children: /* @__PURE__ */ e(le, { className: "dc:w-3 dc:h-3" }) })
521
+ ] }),
522
+ /* @__PURE__ */ e("div", { className: "dc:relative dc:flex-1 dc:min-h-0", children: /* @__PURE__ */ e("div", { style: { position: "absolute", inset: 0 }, children: /* @__PURE__ */ u(
523
+ p,
524
+ {
525
+ nodes: J,
526
+ edges: me,
527
+ onNodesChange: ge,
528
+ onEdgesChange: be,
529
+ nodeTypes: je,
530
+ edgeTypes: ze,
531
+ connectionMode: "loose",
532
+ minZoom: 0.1,
533
+ maxZoom: 2,
534
+ proOptions: { hideAttribution: !0 },
535
+ onPaneContextMenu: xe,
536
+ onPaneClick: ye,
537
+ children: [
538
+ /* @__PURE__ */ e(h, {}),
539
+ /* @__PURE__ */ e(
540
+ N,
541
+ {
542
+ nodeColor: (r) => n.includes(r.id) ? "#8b5cf6" : "#e5e7eb",
543
+ maskColor: "rgb(240, 242, 246, 0.7)"
544
+ }
545
+ ),
546
+ /* @__PURE__ */ e(x, { variant: "dots", gap: 12, size: 1 }),
547
+ /* @__PURE__ */ e(Fe, { token: fe })
548
+ ]
549
+ }
550
+ ) }) }),
551
+ t && /* @__PURE__ */ e(
552
+ "div",
553
+ {
554
+ className: "dc:fixed dc:z-50 bg-dc-surface dc:rounded-md dc:shadow-lg dc:border border-dc-border dc:py-1 dc:min-w-[120px]",
555
+ style: { left: t.x, top: t.y },
556
+ children: /* @__PURE__ */ e(
557
+ "button",
558
+ {
559
+ onClick: Ne,
560
+ className: "dc:w-full dc:px-3 dc:py-2 dc:text-sm text-dc-text-secondary dc:hover:bg-dc-surface-hover dc:text-left",
561
+ children: "Auto Layout"
562
+ }
563
+ )
564
+ }
565
+ )
566
+ ] }) : /* @__PURE__ */ e("div", { className: `dc:flex dc:items-center dc:justify-center dc:h-96 ${c}`, children: /* @__PURE__ */ u("div", { className: "dc:text-center", children: [
567
+ /* @__PURE__ */ e("div", { className: "dc:animate-spin dc:rounded-full dc:h-8 dc:w-8 dc:border-b-2 border-dc-accent dc:mx-auto dc:mb-2" }),
568
+ /* @__PURE__ */ e("p", { className: "text-dc-text-muted", children: "Computing layout..." })
569
+ ] }) });
570
+ }
571
+ const Ae = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
572
+ __proto__: null,
573
+ SchemaVisualization: He
574
+ }, Symbol.toStringTag, { value: "Module" }));
575
+ export {
576
+ Ke as S
577
+ };
578
+ //# sourceMappingURL=schema-visualization-BCLktQwU.js.map