react-semaphor 0.1.98 → 0.1.100

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.
Files changed (24) hide show
  1. package/dist/chunks/{dashboard-controls-SfIULlwq.js → dashboard-controls-DKci3my0.js} +1 -1
  2. package/dist/chunks/{dashboard-controls-B7wa2KRe.js → dashboard-controls-DW1JJWP7.js} +28 -28
  3. package/dist/chunks/{dashboard-json-BJtvpPq-.js → dashboard-json-BDAEIUep.js} +1 -1
  4. package/dist/chunks/{dashboard-json-CmSkMcC5.js → dashboard-json-C0CKQW3d.js} +1 -1
  5. package/dist/chunks/{edit-dashboard-visual-Dx85J19h.js → edit-dashboard-visual-BtV3RWgf.js} +1 -1
  6. package/dist/chunks/{edit-dashboard-visual-BFFO7nug.js → edit-dashboard-visual-DQzy1fUR.js} +165 -165
  7. package/dist/chunks/{editor-action-buttons-B_i5UaKQ.js → editor-action-buttons-BJRrkj_n.js} +2 -2
  8. package/dist/chunks/{editor-action-buttons-DljIU0p-.js → editor-action-buttons-CReBF7FV.js} +1 -1
  9. package/dist/chunks/{index-C37s4iSV.js → index-BDtdPUUE.js} +155 -155
  10. package/dist/chunks/{index-DNQRM5V-.js → index-f2IZ7tlh.js} +7590 -7575
  11. package/dist/chunks/{resource-management-panel-h3nqEz3m.js → resource-management-panel-BQVERuRi.js} +1 -1
  12. package/dist/chunks/{resource-management-panel-CMoCDvGf.js → resource-management-panel-DNpbhYNu.js} +51 -51
  13. package/dist/chunks/{schedule-dashboard-CGKeVpPU.js → schedule-dashboard-CfeYnMXp.js} +149 -141
  14. package/dist/chunks/schedule-dashboard-D8ctQToc.js +6 -0
  15. package/dist/chunks/{use-visual-utils-not8LVVZ.js → use-visual-utils-BN4h1-xa.js} +1 -1
  16. package/dist/chunks/{use-visual-utils-B1-TK4CN.js → use-visual-utils-CRA2-3Z2.js} +14 -15
  17. package/dist/dashboard/index.cjs +1 -1
  18. package/dist/dashboard/index.js +1 -1
  19. package/dist/index.cjs +1 -1
  20. package/dist/index.js +4 -4
  21. package/dist/surfboard/index.cjs +1 -1
  22. package/dist/surfboard/index.js +1 -1
  23. package/package.json +1 -1
  24. package/dist/chunks/schedule-dashboard-D1TDsh3L.js +0 -6
@@ -1,8 +1,8 @@
1
- import { jsx as e, jsxs as l, Fragment as E } from "react/jsx-runtime";
2
- import { b as W, ao as _, ap as $, aq as G, ar as J, as as K, at as M, au as R, av as X, aw as T, ax as Q, B as y, ac as Y, aa as k, ae as Z, u as b, ak as ee, a8 as q, ay as ae, am as B, ah as x, az as se, aA as te, c as w, aB as O, aC as P, aD as z, aE as L, aF as j, ab as ne, aG as de, aH as le, aI as ie, I as re, aJ as oe, aK as ce } from "./index-DNQRM5V-.js";
3
- import { E as he, V as ue, a as me, b as ve, S as U, c as pe } from "./editor-action-buttons-B_i5UaKQ.js";
4
- import fe, { useState as D, useContext as be } from "react";
5
- import { a as H } from "./use-visual-utils-B1-TK4CN.js";
1
+ import { jsx as e, jsxs as r, Fragment as E } from "react/jsx-runtime";
2
+ import { b as W, ao as _, ap as $, aq as G, ar as J, as as K, at as M, au as R, av as X, aw as T, ax as Q, B as k, ac as Y, aa as N, ae as Z, u as g, ak as ee, a8 as q, ay as ae, az as B, ah as w, aA as se, aB as te, c as y, aC as O, aD as P, aE as L, aF as z, aG as j, ab as ne, aH as de, aI as le, aJ as re, I as ie, aK as oe, aL as ce } from "./index-f2IZ7tlh.js";
3
+ import { E as he, V as ue, a as me, b as ve, S as U, c as pe } from "./editor-action-buttons-BJRrkj_n.js";
4
+ import fe, { useState as C, useContext as be } from "react";
5
+ import { a as H } from "./use-visual-utils-CRA2-3Z2.js";
6
6
  /**
7
7
  * @license lucide-react v0.453.0 - ISC
8
8
  *
@@ -19,72 +19,72 @@ function De({
19
19
  onOpenChange: d,
20
20
  isLibraryVisual: s,
21
21
  currentVisualName: t,
22
- isSaving: i = !1,
23
- onConfirm: h
22
+ isSaving: o = !1,
23
+ onConfirm: u
24
24
  }) {
25
- const [u, n] = D(
25
+ const [i, n] = C(
26
26
  s && t ? `Copy of ${t}` : t || ""
27
- ), [o, v] = D(""), [p, g] = D(!s), [f, C] = D(!0);
27
+ ), [c, v] = C(""), [f, D] = C(!s), [b, S] = C(!0);
28
28
  fe.useEffect(() => {
29
29
  a && (n(
30
30
  s && t ? `Copy of ${t}` : t || ""
31
- ), v(""), g(!s), C(!0));
31
+ ), v(""), D(!s), S(!0));
32
32
  }, [a, s, t]);
33
33
  const I = () => {
34
- u.trim() && (!p && !f || h({
35
- name: u.trim(),
36
- description: o.trim() || void 0,
37
- saveToLibrary: p,
38
- saveToCurrentDashboard: f
34
+ i.trim() && (!f && !b || u({
35
+ name: i.trim(),
36
+ description: c.trim() || void 0,
37
+ saveToLibrary: f,
38
+ saveToCurrentDashboard: b
39
39
  }));
40
- }, S = u.trim() && (p || f);
41
- return /* @__PURE__ */ e(_, { open: a, onOpenChange: d, children: /* @__PURE__ */ l($, { className: "sm:max-w-[425px]", children: [
42
- /* @__PURE__ */ l(G, { children: [
40
+ }, A = i.trim() && (f || b);
41
+ return /* @__PURE__ */ e(_, { open: a, onOpenChange: d, children: /* @__PURE__ */ r($, { className: "sm:max-w-[425px]", children: [
42
+ /* @__PURE__ */ r(G, { children: [
43
43
  /* @__PURE__ */ e(J, { children: "Save Visual As" }),
44
44
  /* @__PURE__ */ e(K, { children: s ? "Create a copy of this visual with a new name" : "Save this visual to make it reusable" })
45
45
  ] }),
46
- /* @__PURE__ */ l("div", { className: "grid gap-4 py-4", children: [
47
- /* @__PURE__ */ l("div", { className: "grid gap-2", children: [
46
+ /* @__PURE__ */ r("div", { className: "grid gap-4 py-4", children: [
47
+ /* @__PURE__ */ r("div", { className: "grid gap-2", children: [
48
48
  /* @__PURE__ */ e(M, { htmlFor: "name", children: "Name" }),
49
49
  /* @__PURE__ */ e(
50
50
  R,
51
51
  {
52
52
  id: "name",
53
- value: u,
53
+ value: i,
54
54
  onChange: (m) => n(m.target.value),
55
55
  placeholder: "Enter visual name",
56
- disabled: i
56
+ disabled: o
57
57
  }
58
58
  )
59
59
  ] }),
60
- /* @__PURE__ */ l("div", { className: "grid gap-2", children: [
60
+ /* @__PURE__ */ r("div", { className: "grid gap-2", children: [
61
61
  /* @__PURE__ */ e(M, { htmlFor: "description", children: "Description (optional)" }),
62
62
  /* @__PURE__ */ e(
63
63
  X,
64
64
  {
65
65
  id: "description",
66
- value: o,
66
+ value: c,
67
67
  onChange: (m) => v(m.target.value),
68
68
  placeholder: "Enter visual description",
69
69
  rows: 3,
70
- disabled: i
70
+ disabled: o
71
71
  }
72
72
  )
73
73
  ] }),
74
- /* @__PURE__ */ l("div", { className: "space-y-4", children: [
74
+ /* @__PURE__ */ r("div", { className: "space-y-4", children: [
75
75
  /* @__PURE__ */ e(M, { children: "Save to:" }),
76
- /* @__PURE__ */ l("div", { className: "space-y-2", children: [
77
- /* @__PURE__ */ l("div", { className: "flex items-center space-x-2", children: [
76
+ /* @__PURE__ */ r("div", { className: "space-y-2", children: [
77
+ /* @__PURE__ */ r("div", { className: "flex items-center space-x-2", children: [
78
78
  /* @__PURE__ */ e(
79
79
  T,
80
80
  {
81
81
  id: "save-to-dashboard",
82
- checked: f,
83
- onCheckedChange: (m) => C(!!m),
84
- disabled: i
82
+ checked: b,
83
+ onCheckedChange: (m) => S(!!m),
84
+ disabled: o
85
85
  }
86
86
  ),
87
- /* @__PURE__ */ l(
87
+ /* @__PURE__ */ r(
88
88
  "label",
89
89
  {
90
90
  htmlFor: "save-to-dashboard",
@@ -96,17 +96,17 @@ function De({
96
96
  }
97
97
  )
98
98
  ] }),
99
- /* @__PURE__ */ l("div", { className: "flex items-center space-x-2", children: [
99
+ /* @__PURE__ */ r("div", { className: "flex items-center space-x-2", children: [
100
100
  /* @__PURE__ */ e(
101
101
  T,
102
102
  {
103
103
  id: "save-to-library",
104
- checked: p,
105
- onCheckedChange: (m) => g(!!m),
106
- disabled: i
104
+ checked: f,
105
+ onCheckedChange: (m) => D(!!m),
106
+ disabled: o
107
107
  }
108
108
  ),
109
- /* @__PURE__ */ l(
109
+ /* @__PURE__ */ r(
110
110
  "label",
111
111
  {
112
112
  htmlFor: "save-to-library",
@@ -119,111 +119,119 @@ function De({
119
119
  )
120
120
  ] })
121
121
  ] }),
122
- !p && !f && /* @__PURE__ */ e("p", { className: "text-sm text-destructive", children: "Please select at least one destination" })
122
+ !f && !b && /* @__PURE__ */ e("p", { className: "text-sm text-destructive", children: "Please select at least one destination" })
123
123
  ] })
124
124
  ] }),
125
- /* @__PURE__ */ l(Q, { children: [
125
+ /* @__PURE__ */ r(Q, { children: [
126
126
  /* @__PURE__ */ e(
127
- y,
127
+ k,
128
128
  {
129
129
  variant: "outline",
130
130
  onClick: () => d(!1),
131
- disabled: i,
131
+ disabled: o,
132
132
  children: "Cancel"
133
133
  }
134
134
  ),
135
- /* @__PURE__ */ l(y, { onClick: I, disabled: !S || i, children: [
136
- i && /* @__PURE__ */ e(Y, { className: "mr-2 h-4 w-4 animate-spin" }),
137
- i ? "Saving..." : "Save"
135
+ /* @__PURE__ */ r(k, { onClick: I, disabled: !A || o, children: [
136
+ o && /* @__PURE__ */ e(Y, { className: "mr-2 h-4 w-4 animate-spin" }),
137
+ o ? "Saving..." : "Save"
138
138
  ] })
139
139
  ] })
140
140
  ] }) });
141
141
  }
142
142
  function Ce() {
143
- const [a, d] = D(!1), [s, t] = D(!1), [i, h] = D(null), u = k((r) => r.frame), n = k((r) => r.card), o = Z(), v = b((r) => r.selectedSheetId), p = b(
144
- (r) => r.actions.setIsDashboardPanelOpen
145
- ), { getUpdatedFrame: g } = H(), { selectVisual: f } = ee(), { addFrame: C, setSelectedFrameId: I, setIsVisualEditing: S } = q(), m = !!(u != null && u.visualId), F = (o == null ? void 0 : o.title) || (n == null ? void 0 : n.title) || "Untitled Visual", c = ae((r) => {
146
- if (r != null && r.id) {
147
- if (f(r), s && i && v) {
148
- const A = {
149
- ...i,
143
+ const [a, d] = C(!1), [s, t] = C(!1), [o, u] = C(null), i = N((l) => l.frame), n = N((l) => l.card), c = Z(), v = g((l) => l.selectedSheetId), f = g(
144
+ (l) => l.actions.setIsDashboardPanelOpen
145
+ ), { getUpdatedFrame: D } = H(), { selectVisual: b } = ee(), { addFrame: S, setSelectedFrameId: I, setIsVisualEditing: A } = q(), m = !!(i != null && i.visualId), F = (() => {
146
+ var l, p;
147
+ return c != null && c.title ? c.title : ((l = i == null ? void 0 : i.cards) == null ? void 0 : l.length) === 1 && ((p = i.cards[0]) != null && p.title) ? i.cards[0].title : (n == null ? void 0 : n.title) || "Untitled Visual";
148
+ })(), h = ae((l) => {
149
+ if (l != null && l.id) {
150
+ if (b(l), s && o && v) {
151
+ const p = {
152
+ ...o,
150
153
  id: B(),
151
- visualId: r.id
154
+ visualId: l.id
152
155
  // Link to the newly created library visual
153
156
  };
154
- C(v, A, "end"), I(A.id), t(!1), h(null), S(!1);
157
+ S(v, p, "end"), I(p.id), t(!1), u(null), A(!1);
155
158
  }
156
- p(!0), d(!1);
159
+ f(!0), d(!1);
157
160
  }
158
161
  });
159
162
  return {
160
163
  saveAsDialogOpen: a,
161
164
  setSaveAsDialogOpen: d,
162
- handleSaveAs: async (r) => {
165
+ handleSaveAs: async (l) => {
163
166
  if (!v) {
164
- x.error("No sheet selected");
167
+ w.error("No sheet selected");
165
168
  return;
166
169
  }
167
- const A = g();
168
- if (r.saveToLibrary) {
169
- t(r.saveToCurrentDashboard), h(A);
170
- const N = {
171
- title: r.name,
172
- description: r.description,
173
- frameObject: A,
170
+ const p = D(), V = p.cards.length === 1 ? {
171
+ ...p,
172
+ cards: p.cards.map((x) => ({
173
+ ...x,
174
+ title: l.name
175
+ // Use visual name as card title
176
+ }))
177
+ } : p;
178
+ if (l.saveToLibrary) {
179
+ t(l.saveToCurrentDashboard), u(V);
180
+ const x = {
181
+ title: l.name,
182
+ description: l.description,
183
+ frameObject: V,
184
+ // Card title synced for single-card frames
174
185
  isPrivate: !1
175
186
  };
176
- c.mutate(N);
177
- } else if (r.saveToCurrentDashboard) {
178
- const N = {
179
- ...A,
187
+ h.mutate(x);
188
+ } else if (l.saveToCurrentDashboard) {
189
+ const x = {
190
+ ...V,
191
+ // Card title already synced
180
192
  id: B(),
181
- visualId: void 0,
193
+ visualId: void 0
182
194
  // Explicitly no visualId for local visuals
183
- cards: A.cards.map((V) => ({
184
- ...V,
185
- title: V.id === n.id ? r.name : V.title
186
- }))
187
195
  };
188
- C(v, N, "end"), I(N.id), x.success("Visual saved to dashboard"), d(!1), S(!1);
196
+ S(v, x, "end"), I(x.id), w.success("Visual saved to dashboard"), d(!1), A(!1);
189
197
  }
190
198
  },
191
199
  isLibraryVisual: m,
192
200
  currentVisualName: F,
193
- isSaving: c.isPending
201
+ isSaving: h.isPending
194
202
  };
195
203
  }
196
- function Fe({
204
+ function Ve({
197
205
  className: a
198
206
  }) {
199
- const d = k((c) => c.frame), s = k((c) => c.card), t = se((c) => c.selectedVisual), i = b((c) => c.selectedFrameId), h = b((c) => c.selectedSheetId), { setIsVisualEditing: u } = q(), n = !!(d != null && d.visualId || t != null && t.id), o = !!(d != null && d.visualId && i), v = n && !o, {
200
- saveAsDialogOpen: p,
201
- setSaveAsDialogOpen: g,
202
- handleSaveAs: f,
203
- isLibraryVisual: C,
207
+ const d = N((h) => h.frame), s = N((h) => h.card), t = se((h) => h.selectedVisual), o = g((h) => h.selectedFrameId), u = g((h) => h.selectedSheetId), { setIsVisualEditing: i } = q(), n = !!(d != null && d.visualId || t != null && t.id), c = !!(d != null && d.visualId && o), v = n && !c, {
208
+ saveAsDialogOpen: f,
209
+ setSaveAsDialogOpen: D,
210
+ handleSaveAs: b,
211
+ isLibraryVisual: S,
204
212
  currentVisualName: I,
205
- isSaving: S
213
+ isSaving: A
206
214
  } = Ce(), { handleAddLibraryVisual: m } = H(), F = async () => {
207
- if (!h) {
208
- x.error("No dashboard sheet selected");
215
+ if (!u) {
216
+ w.error("No dashboard sheet selected");
209
217
  return;
210
218
  }
211
219
  if (!t) {
212
- x.error("No visual selected");
220
+ w.error("No visual selected");
213
221
  return;
214
222
  }
215
- const c = await m(t);
216
- c.success ? (x.success("Visual added to dashboard"), u(!1)) : x.error(c.error || "Failed to add visual to dashboard");
223
+ const h = await m(t);
224
+ h.success ? (w.success("Visual added to dashboard"), i(!1)) : w.error(h.error || "Failed to add visual to dashboard");
217
225
  };
218
- return /* @__PURE__ */ l(E, { children: [
226
+ return /* @__PURE__ */ r(E, { children: [
219
227
  !n && /* @__PURE__ */ e(he, { className: a, variant: "default" }),
220
- n && /* @__PURE__ */ l(E, { children: [
221
- o && /* @__PURE__ */ e(ue, { className: a }),
222
- v && h && s && (s.sql || te(s.config)) && /* @__PURE__ */ l(
223
- y,
228
+ n && /* @__PURE__ */ r(E, { children: [
229
+ c && /* @__PURE__ */ e(ue, { className: a }),
230
+ v && u && s && (s.sql || te(s.config)) && /* @__PURE__ */ r(
231
+ k,
224
232
  {
225
233
  onClick: F,
226
- className: w(a),
234
+ className: y(a),
227
235
  size: "sm",
228
236
  variant: "outline",
229
237
  children: [
@@ -233,22 +241,22 @@ function Fe({
233
241
  }
234
242
  ),
235
243
  v && /* @__PURE__ */ e(me, { className: a, variant: "default" }),
236
- o && /* @__PURE__ */ e(ve, { className: a }),
237
- /* @__PURE__ */ l(O, { modal: !1, children: [
244
+ c && /* @__PURE__ */ e(ve, { className: a }),
245
+ /* @__PURE__ */ r(O, { modal: !1, children: [
238
246
  /* @__PURE__ */ e(P, { asChild: !0, children: /* @__PURE__ */ e(
239
- y,
247
+ k,
240
248
  {
241
249
  variant: "outline",
242
250
  size: "sm",
243
- className: w(a, "w-8 p-0"),
244
- children: /* @__PURE__ */ e(z, { className: "h-4 w-4" })
251
+ className: y(a, "w-8 p-0"),
252
+ children: /* @__PURE__ */ e(L, { className: "h-4 w-4" })
245
253
  }
246
254
  ) }),
247
- /* @__PURE__ */ e(L, { align: "end", children: /* @__PURE__ */ l(
255
+ /* @__PURE__ */ e(z, { align: "end", children: /* @__PURE__ */ r(
248
256
  j,
249
257
  {
250
- onClick: (c) => {
251
- c.stopPropagation(), g(!0);
258
+ onClick: (h) => {
259
+ h.stopPropagation(), D(!0);
252
260
  },
253
261
  children: [
254
262
  /* @__PURE__ */ e(U, { className: "mr-2 h-4 w-4" }),
@@ -258,17 +266,17 @@ function Fe({
258
266
  ) })
259
267
  ] })
260
268
  ] }),
261
- !n && /* @__PURE__ */ l(O, { modal: !1, children: [
269
+ !n && /* @__PURE__ */ r(O, { modal: !1, children: [
262
270
  /* @__PURE__ */ e(P, { asChild: !0, children: /* @__PURE__ */ e(
263
- y,
271
+ k,
264
272
  {
265
273
  variant: "outline",
266
274
  size: "sm",
267
- className: w(a, "w-8 p-0"),
268
- children: /* @__PURE__ */ e(z, { className: "h-4 w-4" })
275
+ className: y(a, "w-8 p-0"),
276
+ children: /* @__PURE__ */ e(L, { className: "h-4 w-4" })
269
277
  }
270
278
  ) }),
271
- /* @__PURE__ */ e(L, { align: "end", children: /* @__PURE__ */ l(j, { onClick: () => g(!0), children: [
279
+ /* @__PURE__ */ e(z, { align: "end", children: /* @__PURE__ */ r(j, { onClick: () => D(!0), children: [
272
280
  /* @__PURE__ */ e(U, { className: "mr-2 h-4 w-4" }),
273
281
  "Save As..."
274
282
  ] }) })
@@ -277,40 +285,40 @@ function Fe({
277
285
  /* @__PURE__ */ e(
278
286
  De,
279
287
  {
280
- open: p,
281
- onOpenChange: (c) => {
282
- S || g(c);
288
+ open: f,
289
+ onOpenChange: (h) => {
290
+ A || D(h);
283
291
  },
284
- isLibraryVisual: C,
292
+ isLibraryVisual: S,
285
293
  currentVisualName: I,
286
- isSaving: S,
287
- onConfirm: f
294
+ isSaving: A,
295
+ onConfirm: b
288
296
  }
289
297
  )
290
298
  ] });
291
299
  }
292
- function Ve({
300
+ function Me({
293
301
  className: a,
294
302
  //labelClassName,
295
303
  switchClassName: d
296
304
  }) {
297
- const s = k((n) => n.isDevMode), t = b((n) => n.isVisualEditing), { setIsDevMode: i } = ne(), { config: h } = be(de).tokenProps, u = (h == null ? void 0 : h.showAdvancedMode) !== !1;
298
- return !t || !u ? null : /* @__PURE__ */ l("div", { className: w("flex items-center space-x-2", a), children: [
305
+ const s = N((n) => n.isDevMode), t = g((n) => n.isVisualEditing), { setIsDevMode: o } = ne(), { config: u } = be(de).tokenProps, i = (u == null ? void 0 : u.showAdvancedMode) !== !1;
306
+ return !t || !i ? null : /* @__PURE__ */ r("div", { className: y("flex items-center space-x-2", a), children: [
299
307
  /* @__PURE__ */ e(
300
308
  le,
301
309
  {
302
- className: w("", d),
310
+ className: y("", d),
303
311
  checked: s,
304
- onCheckedChange: () => i(!s),
312
+ onCheckedChange: () => o(!s),
305
313
  id: "advanced-mode",
306
- icon: /* @__PURE__ */ e(ie, { className: "h-4 w-4" }),
314
+ icon: /* @__PURE__ */ e(re, { className: "h-4 w-4" }),
307
315
  tooltip: s ? "Standard Mode" : "Advanced Mode"
308
316
  }
309
317
  ),
310
318
  /* @__PURE__ */ e("label", { htmlFor: "advanced-mode", className: "sr-only", children: "Advanced Mode" })
311
319
  ] });
312
320
  }
313
- function Me(a) {
321
+ function Ee(a) {
314
322
  var d;
315
323
  return {
316
324
  ...a,
@@ -318,11 +326,11 @@ function Me(a) {
318
326
  var t;
319
327
  return {
320
328
  ...s,
321
- frames: (t = s.frames) == null ? void 0 : t.map((i) => {
322
- var h;
329
+ frames: (t = s.frames) == null ? void 0 : t.map((o) => {
330
+ var u;
323
331
  return {
324
- ...i,
325
- cards: (h = i.cards) == null ? void 0 : h.map((u) => Se(u))
332
+ ...o,
333
+ cards: (u = o.cards) == null ? void 0 : u.map((i) => Se(i))
326
334
  };
327
335
  })
328
336
  };
@@ -364,25 +372,25 @@ function Ae(a) {
364
372
  }
365
373
  } : null;
366
374
  }
367
- function Ee({
375
+ function Te({
368
376
  triggerButtonClassName: a
369
377
  }) {
370
- const [d, s] = D(!1), t = b((n) => {
371
- var o;
372
- return (o = n.dashboard) == null ? void 0 : o.id;
373
- }), i = b((n) => {
374
- var o;
375
- return (o = n.dashboard) == null ? void 0 : o.title;
376
- }), h = b((n) => {
377
- var o;
378
- return (o = n.dashboard) == null ? void 0 : o.sheets;
379
- }), u = b((n) => n.selectedSheetId);
380
- return h == null || h.find((n) => n.id === u), t ? /* @__PURE__ */ l(E, { children: [
378
+ const [d, s] = C(!1), t = g((n) => {
379
+ var c;
380
+ return (c = n.dashboard) == null ? void 0 : c.id;
381
+ }), o = g((n) => {
382
+ var c;
383
+ return (c = n.dashboard) == null ? void 0 : c.title;
384
+ }), u = g((n) => {
385
+ var c;
386
+ return (c = n.dashboard) == null ? void 0 : c.sheets;
387
+ }), i = g((n) => n.selectedSheetId);
388
+ return u == null || u.find((n) => n.id === i), t ? /* @__PURE__ */ r(E, { children: [
381
389
  /* @__PURE__ */ e(
382
- re,
390
+ ie,
383
391
  {
384
392
  tooltip: "Schedule Dashboard",
385
- className: w("h-7 p-2", a),
393
+ className: y("h-7 p-2", a),
386
394
  onClick: () => s(!0),
387
395
  children: /* @__PURE__ */ e(oe, { className: "size-4" })
388
396
  }
@@ -393,15 +401,15 @@ function Ee({
393
401
  open: d,
394
402
  onOpenChange: s,
395
403
  dashboardId: t,
396
- dashboardName: i
404
+ dashboardName: o
397
405
  }
398
406
  )
399
407
  ] }) : null;
400
408
  }
401
409
  export {
402
- Ve as A,
403
- Ee as S,
404
- Fe as V,
410
+ Me as A,
411
+ Te as S,
412
+ Ve as V,
405
413
  Se as c,
406
- Me as g
414
+ Ee as g
407
415
  };
@@ -0,0 +1,6 @@
1
+ "use strict";const s=require("react/jsx-runtime"),e=require("./index-BDtdPUUE.js"),f=require("./editor-action-buttons-CReBF7FV.js"),p=require("react"),y=require("./use-visual-utils-BN4h1-xa.js");/**
2
+ * @license lucide-react v0.453.0 - ISC
3
+ *
4
+ * This source code is licensed under the ISC license.
5
+ * See the LICENSE file in the root directory of this source tree.
6
+ */const k=e.createLucideIcon("CirclePlus",[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["path",{d:"M8 12h8",key:"1wcyev"}],["path",{d:"M12 8v8",key:"napkw2"}]]);function F({open:a,onOpenChange:r,isLibraryVisual:t,currentVisualName:n,isSaving:l=!1,onConfirm:h}){const[i,d]=p.useState(t&&n?`Copy of ${n}`:n||""),[c,v]=p.useState(""),[b,D]=p.useState(!t),[j,S]=p.useState(!0);p.useEffect(()=>{a&&(d(t&&n?`Copy of ${n}`:n||""),v(""),D(!t),S(!0))},[a,t,n]);const C=()=>{i.trim()&&(!b&&!j||h({name:i.trim(),description:c.trim()||void 0,saveToLibrary:b,saveToCurrentDashboard:j}))},g=i.trim()&&(b||j);return s.jsx(e.Dialog,{open:a,onOpenChange:r,children:s.jsxs(e.DialogContent,{className:"sm:max-w-[425px]",children:[s.jsxs(e.DialogHeader,{children:[s.jsx(e.DialogTitle,{children:"Save Visual As"}),s.jsx(e.DialogDescription,{children:t?"Create a copy of this visual with a new name":"Save this visual to make it reusable"})]}),s.jsxs("div",{className:"grid gap-4 py-4",children:[s.jsxs("div",{className:"grid gap-2",children:[s.jsx(e.Label,{htmlFor:"name",children:"Name"}),s.jsx(e.Input,{id:"name",value:i,onChange:m=>d(m.target.value),placeholder:"Enter visual name",disabled:l})]}),s.jsxs("div",{className:"grid gap-2",children:[s.jsx(e.Label,{htmlFor:"description",children:"Description (optional)"}),s.jsx(e.Textarea,{id:"description",value:c,onChange:m=>v(m.target.value),placeholder:"Enter visual description",rows:3,disabled:l})]}),s.jsxs("div",{className:"space-y-4",children:[s.jsx(e.Label,{children:"Save to:"}),s.jsxs("div",{className:"space-y-2",children:[s.jsxs("div",{className:"flex items-center space-x-2",children:[s.jsx(e.Checkbox,{id:"save-to-dashboard",checked:j,onCheckedChange:m=>S(!!m),disabled:l}),s.jsxs("label",{htmlFor:"save-to-dashboard",className:"text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70",children:["Current Dashboard",s.jsx("span",{className:"ml-2 text-xs text-muted-foreground",children:t?"(add copy to this dashboard)":"(keep as local visual)"})]})]}),s.jsxs("div",{className:"flex items-center space-x-2",children:[s.jsx(e.Checkbox,{id:"save-to-library",checked:b,onCheckedChange:m=>D(!!m),disabled:l}),s.jsxs("label",{htmlFor:"save-to-library",className:"text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70",children:["Visual Library",s.jsx("span",{className:"ml-2 text-xs text-muted-foreground",children:t?"(save as new reusable visual)":"(make available to all dashboards)"})]})]})]}),!b&&!j&&s.jsx("p",{className:"text-sm text-destructive",children:"Please select at least one destination"})]})]}),s.jsxs(e.DialogFooter,{children:[s.jsx(e.Button,{variant:"outline",onClick:()=>r(!1),disabled:l,children:"Cancel"}),s.jsxs(e.Button,{onClick:C,disabled:!g||l,children:[l&&s.jsx(e.LoaderCircle,{className:"mr-2 h-4 w-4 animate-spin"}),l?"Saving...":"Save"]})]})]})})}function N(){const[a,r]=p.useState(!1),[t,n]=p.useState(!1),[l,h]=p.useState(null),i=e.useEditorStore(o=>o.frame),d=e.useEditorStore(o=>o.card),c=e.useSelectedVisual(),v=e.useDashboardStore(o=>o.selectedSheetId),b=e.useDashboardStore(o=>o.actions.setIsDashboardPanelOpen),{getUpdatedFrame:D}=y.useVisualUtils(),{selectVisual:j}=e.useManagementActions(),{addFrame:S,setSelectedFrameId:C,setIsVisualEditing:g}=e.useDashboardActions(),m=!!(i!=null&&i.visualId),w=(()=>{var o,x;return c!=null&&c.title?c.title:((o=i==null?void 0:i.cards)==null?void 0:o.length)===1&&((x=i.cards[0])!=null&&x.title)?i.cards[0].title:(d==null?void 0:d.title)||"Untitled Visual"})(),u=e.useCreateVisualWithFrame(o=>{if(o!=null&&o.id){if(j(o),t&&l&&v){const x={...l,id:e.v4(),visualId:o.id};S(v,x,"end"),C(x.id),n(!1),h(null),g(!1)}b(!0),r(!1)}});return{saveAsDialogOpen:a,setSaveAsDialogOpen:r,handleSaveAs:async o=>{if(!v){e.ue.error("No sheet selected");return}const x=D(),I=x.cards.length===1?{...x,cards:x.cards.map(A=>({...A,title:o.name}))}:x;if(o.saveToLibrary){n(o.saveToCurrentDashboard),h(I);const A={title:o.name,description:o.description,frameObject:I,isPrivate:!1};u.mutate(A)}else if(o.saveToCurrentDashboard){const A={...I,id:e.v4(),visualId:void 0};S(v,A,"end"),C(A.id),e.ue.success("Visual saved to dashboard"),r(!1),g(!1)}},isLibraryVisual:m,currentVisualName:w,isSaving:u.isPending}}function V({className:a}){const r=e.useEditorStore(u=>u.frame),t=e.useEditorStore(u=>u.card),n=e.useManagementStore(u=>u.selectedVisual),l=e.useDashboardStore(u=>u.selectedFrameId),h=e.useDashboardStore(u=>u.selectedSheetId),{setIsVisualEditing:i}=e.useDashboardActions(),d=!!(r!=null&&r.visualId||n!=null&&n.id),c=!!(r!=null&&r.visualId&&l),v=d&&!c,{saveAsDialogOpen:b,setSaveAsDialogOpen:D,handleSaveAs:j,isLibraryVisual:S,currentVisualName:C,isSaving:g}=N(),{handleAddLibraryVisual:m}=y.useVisualUtils(),w=async()=>{if(!h){e.ue.error("No dashboard sheet selected");return}if(!n){e.ue.error("No visual selected");return}const u=await m(n);u.success?(e.ue.success("Visual added to dashboard"),i(!1)):e.ue.error(u.error||"Failed to add visual to dashboard")};return s.jsxs(s.Fragment,{children:[!d&&s.jsx(f.EditorAcceptButton,{className:a,variant:"default"}),d&&s.jsxs(s.Fragment,{children:[c&&s.jsx(f.VisualApplyLocalButton,{className:a}),v&&h&&t&&(t.sql||e.hasValidCardConfig(t.config))&&s.jsxs(e.Button,{onClick:w,className:e.cn(a),size:"sm",variant:"outline",children:[s.jsx(k,{className:"mr-2 size-4 font-bold"}),"Add to Dashboard"]}),v&&s.jsx(f.VisualSaveButton,{className:a,variant:"default"}),c&&s.jsx(f.VisualSaveAndApplyButton,{className:a}),s.jsxs(e.DropdownMenu,{modal:!1,children:[s.jsx(e.DropdownMenuTrigger,{asChild:!0,children:s.jsx(e.Button,{variant:"outline",size:"sm",className:e.cn(a,"w-8 p-0"),children:s.jsx(e.EllipsisVertical,{className:"h-4 w-4"})})}),s.jsx(e.DropdownMenuContent,{align:"end",children:s.jsxs(e.DropdownMenuItem,{onClick:u=>{u.stopPropagation(),D(!0)},children:[s.jsx(f.Save,{className:"mr-2 h-4 w-4"}),"Save As..."]})})]})]}),!d&&s.jsxs(e.DropdownMenu,{modal:!1,children:[s.jsx(e.DropdownMenuTrigger,{asChild:!0,children:s.jsx(e.Button,{variant:"outline",size:"sm",className:e.cn(a,"w-8 p-0"),children:s.jsx(e.EllipsisVertical,{className:"h-4 w-4"})})}),s.jsx(e.DropdownMenuContent,{align:"end",children:s.jsxs(e.DropdownMenuItem,{onClick:()=>D(!0),children:[s.jsx(f.Save,{className:"mr-2 h-4 w-4"}),"Save As..."]})})]}),s.jsx(f.EditorCancelButton,{className:a}),s.jsx(F,{open:b,onOpenChange:u=>{g||D(u)},isLibraryVisual:S,currentVisualName:C,isSaving:g,onConfirm:j})]})}function E({className:a,switchClassName:r}){const t=e.useEditorStore(d=>d.isDevMode),n=e.useDashboardStore(d=>d.isVisualEditing),{setIsDevMode:l}=e.useEditorActions(),{config:h}=p.useContext(e.SemaphorContext).tokenProps,i=(h==null?void 0:h.showAdvancedMode)!==!1;return!n||!i?null:s.jsxs("div",{className:e.cn("flex items-center space-x-2",a),children:[s.jsx(e.DevModeSwitch,{className:e.cn("",r),checked:t,onCheckedChange:()=>l(!t),id:"advanced-mode",icon:s.jsx(e.CodeXml,{className:"h-4 w-4"}),tooltip:t?"Standard Mode":"Advanced Mode"}),s.jsx("label",{htmlFor:"advanced-mode",className:"sr-only",children:"Advanced Mode"})]})}function T(a){var r;return{...a,sheets:(r=a==null?void 0:a.sheets)==null?void 0:r.map(t=>{var n;return{...t,frames:(n=t.frames)==null?void 0:n.map(l=>{var h;return{...l,cards:(h=l.cards)==null?void 0:h.map(i=>M(i))}})}})}}function M(a){return{...a,customCfg:B(a.customCfg),data:[]}}function B(a){var r,t;return a?{...a,data:{...a==null?void 0:a.data,labels:[],datasets:(t=(r=a==null?void 0:a.data)==null?void 0:r.datasets)==null?void 0:t.map(n=>({...n,data:[]}))}}:null}function O({triggerButtonClassName:a}){const[r,t]=p.useState(!1),n=e.useDashboardStore(d=>{var c;return(c=d.dashboard)==null?void 0:c.id}),l=e.useDashboardStore(d=>{var c;return(c=d.dashboard)==null?void 0:c.title}),h=e.useDashboardStore(d=>{var c;return(c=d.dashboard)==null?void 0:c.sheets}),i=e.useDashboardStore(d=>d.selectedSheetId);return h==null||h.find(d=>d.id===i),n?s.jsxs(s.Fragment,{children:[s.jsx(e.IconButton,{tooltip:"Schedule Dashboard",className:e.cn("h-7 p-2",a),onClick:()=>t(!0),children:s.jsx(e.Clock,{className:"size-4"})}),s.jsx(e.EmailScheduleDialog,{open:r,onOpenChange:t,dashboardId:n,dashboardName:l})]}):null}exports.AdvancedModeToggle=E;exports.ScheduleDashboard=O;exports.VisualEditingControls=V;exports.cleanCard=M;exports.getDashbaordStateWithoutData=T;
@@ -1 +1 @@
1
- "use strict";const o=require("./index-C37s4iSV.js"),b=require("react");function _(e){const a=e.toUpperCase().indexOf("WHERE"),r=e.toUpperCase().indexOf("GROUP BY"),t=e.toUpperCase().indexOf("LIMIT"),d=e.toUpperCase().indexOf("ORDER BY");let c=e.length;if(d!==-1&&(c=d),t!==-1&&t<c&&(c=t),a!==-1){const n=e.substring(0,a),s=e.substring(a);return`${n} {{ filters | where }} AND ${s.substring(6)}`}else if(r!==-1){const n=e.substring(0,r),s=e.substring(r);return`${n} {{ filters | where }} ${s}`}else{const n=e.substring(0,c),s=e.substring(c);return console.log("beforeClause",n),console.log("afterClause",s),s?`${n} {{ filters | where }} ${s}`:`${n.replace(/;$/,"")} {{ filters | where }}`}}function B(e){const[a,r]=b.useState(null),[t,d]=b.useState(null),c=o.useEnsureReactGlobals();return b.useEffect(()=>{if(!e||e.trim()===""){r(null),d(null);return}if(!c)return;(async()=>{try{if(!e.startsWith("http://")&&!e.startsWith("https://"))throw new Error(`Invalid URL format: ${e}`);try{new URL(e)}catch{throw new Error(`Invalid URL: ${e}`)}const l=`${e.endsWith("/")?e:`${e}/`}index.js`;try{if(!(await fetch(l,{method:"HEAD"})).ok)throw new Error(`Module not found at ${l}`)}catch{}const m=await import(l);if(typeof m.useChartStore!="function")throw new Error("useChartStore is not a function");r(()=>m.useChartStore),d(null)}catch(s){const l=s instanceof Error?s.message:"Unknown error";console.error("Failed to load remote chart store:",l),d(l),r(null)}})()},[e,c]),a}function H(e,a){if(e.length===0)return"";if(a){const r=e.find(t=>t.id===a);if(r){const t=r.tabTitle;if(t=="All__Header")return e[0].id;if(t&&t.endsWith("__Header")){const c=t.split("__")[0],n=e.find(s=>s.tabTitle===c);return n?n.id:e[0].id}return a}}return e[0].id}async function j(e,a,r,t){if(!a||!r)throw new Error("Missing auth token or visual ID");const d=["resource-by-id","visual",r],c=t.getQueryData(d);if(c)return console.log("Using cached visual data for:",r),{data:c,fromCache:!0};console.log("Fetching visual data from network for:",r);const n=o.ue.loading("Loading visual...",{position:"top-center"});try{const s=await fetch(`${e}/management/v1/visuals/${r}`,{headers:{Authorization:`Bearer ${a}`}});if(!s.ok)throw new Error("Failed to load visual");const l=await s.json();return t.setQueryData(d,l),o.ue.dismiss(n),{data:l,fromCache:!1}}catch(s){throw o.ue.dismiss(n),s}}function T(e){if(typeof e=="string")return JSON.parse(e);if(typeof e=="object")return e;throw new Error("Invalid frame object format")}function Q(e,a){var c,n;const r=(e==null?void 0:e.frameObject)??((c=e==null?void 0:e.visual)==null?void 0:c.frameObject);if(!r)return!1;const t=T(r);if(!(t!=null&&t.cards)||t.cards.length===0)return!1;const d=(n=t.cards)==null?void 0:n.find(s=>s.id===t.activeCardId);return d?(o.setupEditorWithCard({...a,frame:t,card:d,visualId:(e==null?void 0:e.id)||t.visualId}),!0):!1}function G(){var g;const{setCardSql:e}=o.useEditorActions(),a=o.useEditorStore(i=>i.frame),r=o.useEditorStore(i=>i.card),t=B(((g=r.customCardPreferences)==null?void 0:g.url)||""),d=o.useEditorStore(i=>i.selectedSchemaName),c=o.useEditorStore(i=>i.selectedDatamodelId),n=o.useEditorStore(i=>i.selectedDatabaseName),s=o.useEditorStore(i=>i.selectedTableName),l=o.useEditorStore(i=>i.selectedConnectionId),m=o.useEditorStore(i=>i.isShowingVisual),f=r.sql;return{getUpdatedFrame:b.useCallback(()=>{var E;let i=f;f&&!f.includes("{{")&&(i=_(f),e(i));const C=(E=t==null?void 0:t.getState())==null?void 0:E.settings,F={...r,dataSource:r.dataSource||{mode:"directSource"},lastSelectedSchema:d,lastSelectedDatamodelId:c,lastSelectedDatabase:n,lastSelectedTable:s,connectionId:l,sql:i,customCfg:m?r.customCfg:null,preferences:r.preferences,...C&&{customCardPreferences:{...r.customCardPreferences,settings:C}}},w=a.cards.map(S=>S.id===r.id?F:S);return{...a,cards:w,activeCardId:H(w,a.activeCardId)}},[r,a,m,d,c,n,s,l,e,t,f])}}function z(){const{authToken:e,tokenProps:a}=o.useSemaphorContext(),r=o.useQueryClient(),t=o.useSelectedVisual(),{selectVisual:d}=o.useManagementActions(),{setFrame:c,setCard:n,setIsDevMode:s,setActiveTabCardId:l,updateDataSource:m,setQueryResultColumns:f,setSelectedConnectionId:v,setSelectedDatabaseName:g,setSelectedSchemaName:i,setSelectedTableName:C,setSelectedDatamodelId:F,setFilterValues:w,setApplyFilters:E}=o.useEditorActions(),{setIsDashboardEditing:S,setIsVisualEditing:V,setSelectedFrameId:$,clearSelectedFrameId:A,addFrame:R,setIsDashboardPanelOpen:D}=o.useDashboardActions(),I=o.useDashboardStore(u=>u.selectedSheetId),N=o.useDashboardStore(u=>u.selectedFrameId),O=o.useDashboardStore(u=>u.dashboard),x=o.useDashboardStore(u=>u.filterValues),y=o.useVisualById((t==null?void 0:t.id)||"",{enabled:!!(t!=null&&t.id)&&!!(e!=null&&e.accessToken)}),M=b.useCallback(async u=>{try{d(u),A();const{data:p,fromCache:h}=await j(a.apiServiceUrl,(e==null?void 0:e.accessToken)||"",u.id,r);if(!Q(p,{setFrame:c,setCard:n,setIsDevMode:s,setActiveTabCardId:l,updateDataSource:m,setQueryResultColumns:f,setSelectedConnectionId:v,setSelectedDatabaseName:g,setSelectedSchemaName:i,setSelectedTableName:C,setSelectedDatamodelId:F,setFilterValues:w,setApplyFilters:E,setIsDashboardEditing:S,setIsVisualEditing:V,dashboard:O,selectedSheetId:I,selectedFrameId:N,filterValues:x}))throw new Error("Failed to setup editor with visual data");return{success:!0,fromCache:h}}catch(p){return console.error("Error editing visual:",p),{success:!1,error:"Failed to load visual for editing"}}},[e==null?void 0:e.accessToken,a.apiServiceUrl,r,d,c,n,S,V,s,l,m,f,v,g,i,C,F,w,E,A,O,I,N,x]),k=b.useCallback(async u=>{var p;try{if(d(u),!I)return{success:!1,error:"No sheet selected. Please select a sheet first."};const{data:h,fromCache:W}=await j(a.apiServiceUrl,(e==null?void 0:e.accessToken)||"",u.id,r),L=(h==null?void 0:h.frameObject)??((p=h==null?void 0:h.visual)==null?void 0:p.frameObject);if(!L)return{success:!1,error:"Visual has no frame data"};const U=T(L);if(!(U!=null&&U.cards)||U.cards.length===0)return{success:!1,error:"Visual frame is malformed"};const P={...U,id:o.v4(),visualId:u.id};return R(I,P,"end"),S(!0),$(P.id),D(!1),{success:!0,fromCache:W}}catch(h){return console.error("Error adding visual:",h),{success:!1,error:"Failed to add visual to dashboard"}}},[e==null?void 0:e.accessToken,a.apiServiceUrl,r,d,I,R,S,$,D]);return{visual:y.data,isLoading:y.isLoading,isError:y.isError,error:y.error,handleEditLibraryVisual:M,handleAddLibraryVisual:k,getUpdatedFrame:G().getUpdatedFrame,refetch:y.refetch}}exports.useRemoteChartStore=B;exports.useVisualUtils=z;
1
+ "use strict";const o=require("./index-BDtdPUUE.js"),b=require("react");function _(e){const a=e.toUpperCase().indexOf("WHERE"),r=e.toUpperCase().indexOf("GROUP BY"),t=e.toUpperCase().indexOf("LIMIT"),d=e.toUpperCase().indexOf("ORDER BY");let c=e.length;if(d!==-1&&(c=d),t!==-1&&t<c&&(c=t),a!==-1){const n=e.substring(0,a),s=e.substring(a);return`${n} {{ filters | where }} AND ${s.substring(6)}`}else if(r!==-1){const n=e.substring(0,r),s=e.substring(r);return`${n} {{ filters | where }} ${s}`}else{const n=e.substring(0,c),s=e.substring(c);return console.log("beforeClause",n),console.log("afterClause",s),s?`${n} {{ filters | where }} ${s}`:`${n.replace(/;$/,"")} {{ filters | where }}`}}function B(e){const[a,r]=b.useState(null),[t,d]=b.useState(null),c=o.useEnsureReactGlobals();return b.useEffect(()=>{if(!e||e.trim()===""){r(null),d(null);return}if(!c)return;(async()=>{try{if(!e.startsWith("http://")&&!e.startsWith("https://"))throw new Error(`Invalid URL format: ${e}`);try{new URL(e)}catch{throw new Error(`Invalid URL: ${e}`)}const l=`${e.endsWith("/")?e:`${e}/`}index.js`;try{if(!(await fetch(l,{method:"HEAD"})).ok)throw new Error(`Module not found at ${l}`)}catch{}const m=await import(l);if(typeof m.useChartStore!="function")throw new Error("useChartStore is not a function");r(()=>m.useChartStore),d(null)}catch(s){const l=s instanceof Error?s.message:"Unknown error";console.error("Failed to load remote chart store:",l),d(l),r(null)}})()},[e,c]),a}function H(e,a){if(e.length===0)return"";if(a){const r=e.find(t=>t.id===a);if(r){const t=r.tabTitle;if(t=="All__Header")return e[0].id;if(t&&t.endsWith("__Header")){const c=t.split("__")[0],n=e.find(s=>s.tabTitle===c);return n?n.id:e[0].id}return a}}return e[0].id}async function j(e,a,r,t){if(!a||!r)throw new Error("Missing auth token or visual ID");const d=["resource-by-id","visual",r],c=t.getQueryData(d);if(c)return console.log("Using cached visual data for:",r),{data:c,fromCache:!0};console.log("Fetching visual data from network for:",r);const n=o.ue.loading("Loading visual...",{position:"top-center"});try{const s=await fetch(`${e}/management/v1/visuals/${r}`,{headers:{Authorization:`Bearer ${a}`}});if(!s.ok)throw new Error("Failed to load visual");const l=await s.json();return t.setQueryData(d,l),o.ue.dismiss(n),{data:l,fromCache:!1}}catch(s){throw o.ue.dismiss(n),s}}function T(e){if(typeof e=="string")return JSON.parse(e);if(typeof e=="object")return e;throw new Error("Invalid frame object format")}function Q(e,a){var c,n;const r=(e==null?void 0:e.frameObject)??((c=e==null?void 0:e.visual)==null?void 0:c.frameObject);if(!r)return!1;const t=T(r);if(!(t!=null&&t.cards)||t.cards.length===0)return!1;const d=(n=t.cards)==null?void 0:n.find(s=>s.id===t.activeCardId);return d?(o.setupEditorWithCard({...a,frame:t,card:d,visualId:(e==null?void 0:e.id)||t.visualId}),!0):!1}function G(){var g;const{setCardSql:e}=o.useEditorActions(),a=o.useEditorStore(i=>i.frame),r=o.useEditorStore(i=>i.card),t=B(((g=r.customCardPreferences)==null?void 0:g.url)||""),d=o.useEditorStore(i=>i.selectedSchemaName),c=o.useEditorStore(i=>i.selectedDatamodelId),n=o.useEditorStore(i=>i.selectedDatabaseName),s=o.useEditorStore(i=>i.selectedTableName),l=o.useEditorStore(i=>i.selectedConnectionId),m=o.useEditorStore(i=>i.isShowingVisual),f=r.sql;return{getUpdatedFrame:b.useCallback(()=>{var E;let i=f;f&&!f.includes("{{")&&(i=_(f),e(i));const C=(E=t==null?void 0:t.getState())==null?void 0:E.settings,U={...r,dataSource:r.dataSource||{mode:"directSource"},lastSelectedSchema:d,lastSelectedDatamodelId:c,lastSelectedDatabase:n,lastSelectedTable:s,connectionId:l,sql:i,customCfg:m?r.customCfg:null,preferences:r.preferences,...C&&{customCardPreferences:{...r.customCardPreferences,settings:C}}},w=a.cards.map(S=>S.id===r.id?U:S);return{...a,cards:w,activeCardId:H(w,a.activeCardId)}},[r,a,m,d,c,n,s,l,e,t,f])}}function z(){const{authToken:e,tokenProps:a}=o.useSemaphorContext(),r=o.useQueryClient(),t=o.useSelectedVisual(),{selectVisual:d}=o.useManagementActions(),{setFrame:c,setCard:n,setIsDevMode:s,setActiveTabCardId:l,updateDataSource:m,setQueryResultColumns:f,setSelectedConnectionId:V,setSelectedDatabaseName:g,setSelectedSchemaName:i,setSelectedTableName:C,setSelectedDatamodelId:U,setFilterValues:w,setApplyFilters:E}=o.useEditorActions(),{setIsDashboardEditing:S,setIsVisualEditing:$,setSelectedFrameId:v,clearSelectedFrameId:A,addFrame:N,setIsDashboardPanelOpen:R}=o.useDashboardActions(),I=o.useDashboardStore(u=>u.selectedSheetId),D=o.useDashboardStore(u=>u.selectedFrameId),O=o.useDashboardStore(u=>u.dashboard),x=o.useDashboardStore(u=>u.filterValues),y=o.useVisualById((t==null?void 0:t.id)||"",{enabled:!!(t!=null&&t.id)&&!!(e!=null&&e.accessToken)}),M=b.useCallback(async u=>{try{d(u),A();const{data:p,fromCache:h}=await j(a.apiServiceUrl,(e==null?void 0:e.accessToken)||"",u.id,r);if(!Q(p,{setFrame:c,setCard:n,setIsDevMode:s,setActiveTabCardId:l,updateDataSource:m,setQueryResultColumns:f,setSelectedConnectionId:V,setSelectedDatabaseName:g,setSelectedSchemaName:i,setSelectedTableName:C,setSelectedDatamodelId:U,setFilterValues:w,setApplyFilters:E,setIsDashboardEditing:S,setIsVisualEditing:$,dashboard:O,selectedSheetId:I,selectedFrameId:D,filterValues:x}))throw new Error("Failed to setup editor with visual data");return{success:!0,fromCache:h}}catch(p){return console.error("Error editing visual:",p),{success:!1,error:"Failed to load visual for editing"}}},[e==null?void 0:e.accessToken,a.apiServiceUrl,r,d,c,n,S,$,s,l,m,f,V,g,i,C,U,w,E,A,O,I,D,x]),k=b.useCallback(async u=>{var p;try{if(d(u),!I)return{success:!1,error:"No sheet selected. Please select a sheet first."};const{data:h,fromCache:W}=await j(a.apiServiceUrl,(e==null?void 0:e.accessToken)||"",u.id,r),L=(h==null?void 0:h.frameObject)??((p=h==null?void 0:h.visual)==null?void 0:p.frameObject);if(!L)return{success:!1,error:"Visual has no frame data"};const F=T(L);if(!(F!=null&&F.cards)||F.cards.length===0)return{success:!1,error:"Visual frame is malformed"};const P={...o.cloneFrameWithNewIds(F),visualId:u.id};return N(I,P,"end"),S(!0),v(P.id),R(!1),{success:!0,fromCache:W}}catch(h){return console.error("Error adding visual:",h),{success:!1,error:"Failed to add visual to dashboard"}}},[e==null?void 0:e.accessToken,a.apiServiceUrl,r,d,I,N,S,v,R]);return{visual:y.data,isLoading:y.isLoading,isError:y.isError,error:y.error,handleEditLibraryVisual:M,handleAddLibraryVisual:k,getUpdatedFrame:G().getUpdatedFrame,refetch:y.refetch}}exports.useRemoteChartStore=B;exports.useVisualUtils=z;