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