react-semaphor 0.1.525 → 0.1.526

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 (54) hide show
  1. package/dist/brand-studio/index.js +37 -37
  2. package/dist/briefings/index.js +3 -3
  3. package/dist/chunks/{calculated-field-identity-Dy_WpDdo.js → calculated-field-identity-D1ofR4KJ.js} +28 -28
  4. package/dist/chunks/{card-config-utils-CAyjC5Tp.js → card-config-utils-9sv4e-Vb.js} +15 -15
  5. package/dist/chunks/{switch-CWPcwAZ4.js → code-highlight-994tgM9v.js} +6309 -8642
  6. package/dist/chunks/dashboard-CsHvEtjN.js +15 -0
  7. package/dist/chunks/{dashboard-briefing-launcher-BilVIEyw.js → dashboard-briefing-launcher-DXz1GhFZ.js} +364 -370
  8. package/dist/chunks/{dashboard-controls-DyLPcvCK.js → dashboard-controls-Df8qOSrs.js} +163 -168
  9. package/dist/chunks/dashboard-json-Xldp0qww.js +65 -0
  10. package/dist/chunks/{edit-dashboard-visual-DtmKNNdE.js → edit-dashboard-visual-COHBqyic.js} +1108 -1107
  11. package/dist/chunks/editor-action-buttons-DahlP57T.js +2071 -0
  12. package/dist/chunks/{index-ON7Gpvcv.js → index-CbjuruKe.js} +40 -40
  13. package/dist/chunks/{matrix-control-sources-B1K7x0SL.js → matrix-control-sources-2VAzGlt8.js} +29 -29
  14. package/dist/chunks/pre-block-Cq1RqhZX.js +3987 -0
  15. package/dist/chunks/report-preferences-dialog-BcH-0lR-.js +1232 -0
  16. package/dist/chunks/search-CJz-QQ0Q.js +24 -0
  17. package/dist/chunks/{selection-reducer-CvCBQbl2.js → selection-reducer-NF5C07yM.js} +25 -46
  18. package/dist/chunks/{index-DYOaHuLS.js → semaphor-ready-indicator-BLRDuLr4.js} +142229 -147767
  19. package/dist/chunks/slider-BYIH4icg.js +877 -0
  20. package/dist/chunks/switch-XaAACBrJ.js +2234 -0
  21. package/dist/dashboard/index.js +1 -1
  22. package/dist/dashboard-authoring/index.js +4 -4
  23. package/dist/data-app-builder/index.js +67 -67
  24. package/dist/data-app-sdk/index.js +33 -32
  25. package/dist/index.js +435 -243
  26. package/dist/surfboard/index.js +4 -5
  27. package/dist/types/components/dashboard/dashboard-container.d.ts +1 -1
  28. package/dist/types/components/dashboard/sheet/layout-change-guard.d.ts +1 -1
  29. package/dist/types/components/dashboard/sheet/sheet-layout.d.ts +1 -1
  30. package/dist/types/components/editor/editor-main/text-card.d.ts +1 -1
  31. package/dist/types/components/editor/editor.d.ts +1 -1
  32. package/dist/types/components/providers/semaphor-context-provider.d.ts +1 -1
  33. package/dist/types/components/providers/theme-provider-context.d.ts +1 -1
  34. package/dist/types/components/providers/theme-provider.d.ts +1 -1
  35. package/dist/types/components/shared/unsaved-changes/use-pristine-snapshot-initializer.d.ts +1 -1
  36. package/dist/types/components/surfboard/dashboard-plus.d.ts +1 -1
  37. package/dist/types/components/visual/column-display-utils.d.ts +1 -1
  38. package/dist/types/components/visual/kpi-visual/kpi-utils.d.ts +1 -1
  39. package/dist/types/components/visual/settings/color-format.d.ts +1 -1
  40. package/dist/types/components/visual/visual-utils.d.ts +1 -1
  41. package/dist/types/lib/actions/data-point-click-action.d.ts +2 -1
  42. package/dist/types/lib/dashboard/normalize-dashboard-for-dirty-check.d.ts +1 -1
  43. package/dist/types/lib/hooks/explorer/use-schemas.d.ts +1 -1
  44. package/dist/types/lib/hooks/use-dashboard.d.ts +2 -2
  45. package/dist/types/lib/interactions/get-click-context-from-chartjs.d.ts +1 -2
  46. package/dist/types/lib/stores/editor-store.d.ts +1 -2
  47. package/dist/types/lib/stores/table-actions.d.ts +2 -1
  48. package/dist/types/lib/types/token-types.d.ts +0 -12
  49. package/dist/types/lib/utils.d.ts +0 -2
  50. package/package.json +2 -1
  51. package/dist/chunks/dashboard-json-QEoU-mx4.js +0 -75
  52. package/dist/chunks/editor-action-buttons-B9VRW3Bh.js +0 -2019
  53. package/dist/chunks/report-preferences-dialog-BLaFmlE2.js +0 -723
  54. package/dist/types/lib/encrypt-utils.d.ts +0 -9
@@ -0,0 +1,2071 @@
1
+ import { c as _e, C as Re, X as tt } from "./x-CXDkqdur.js";
2
+ import { useState as W, useEffect as ie, useCallback as z, useMemo as $, useRef as Se, Fragment as yt } from "react";
3
+ import { H as de, E as Le, u as Z, _ as j, G as M, c as fe, a0 as vt, a1 as me, a2 as Be, a3 as $e, a4 as ke, a5 as Ne, a6 as xt, a7 as Ct, a8 as He, a9 as St, aa as kt, ab as pe, ac as Nt, ad as Pe, B as q, ae as at, af as rt, ag as st, S as we, d as De, e as Ee, f as Ie, g as Te, ah as nt, ai as wt, aj as Dt, ak as Ke, al as Et, am as We, an as It, ao as Tt, ap as Ft, aq as Vt, ar as Fe, C as _t, L as ot, as as Lt } from "./code-highlight-994tgM9v.js";
4
+ import { aZ as At, a_ as qt, ax as Mt, a$ as Ot, b0 as Ae, b1 as Ut, b2 as zt, b3 as jt, b4 as Qt, b5 as Rt, az as Bt, av as lt, u as $t, b6 as Ht, b7 as Pt, b8 as Ye, b9 as Kt, ba as Wt, bb as it, bc as dt, bd as Yt, be as Gt, bf as Xt, bg as Jt, bh as Zt, bi as ea, bj as ct, bk as ta } from "./semaphor-ready-indicator-BLRDuLr4.js";
5
+ import { jsx as r, jsxs as f, Fragment as ee } from "react/jsx-runtime";
6
+ import { t as aa } from "./validators-CsdOtZI6.js";
7
+ import "./matrix-operation-contract-D32U2CSw.js";
8
+ import "../value-format-preferences/index.js";
9
+ import { i as ra, j as sa, k as na, l as oa, o as la, L as oe, m as ut } from "./switch-XaAACBrJ.js";
10
+ import { C as Ge } from "./search-CJz-QQ0Q.js";
11
+ import { u as ce, P as ia } from "./pre-block-Cq1RqhZX.js";
12
+ import { f as mt, r as da, g as ca, a as ua, b as ma } from "./index-CbjuruKe.js";
13
+ import { S as pt } from "./save-DgMfP0j8.js";
14
+ /**
15
+ * @license lucide-react v0.453.0 - ISC
16
+ *
17
+ * This source code is licensed under the ISC license.
18
+ * See the LICENSE file in the root directory of this source tree.
19
+ */
20
+ const Ba = _e("FilterX", [
21
+ ["path", { d: "M13.013 3H2l8 9.46V19l4 2v-8.54l.9-1.055", key: "1fi1da" }],
22
+ ["path", { d: "m22 3-5 5", key: "12jva0" }],
23
+ ["path", { d: "m17 3 5 5", key: "k36vhe" }]
24
+ ]);
25
+ /**
26
+ * @license lucide-react v0.453.0 - ISC
27
+ *
28
+ * This source code is licensed under the ISC license.
29
+ * See the LICENSE file in the root directory of this source tree.
30
+ */
31
+ const pa = _e("Library", [
32
+ ["path", { d: "m16 6 4 14", key: "ji33uf" }],
33
+ ["path", { d: "M12 6v14", key: "1n7gus" }],
34
+ ["path", { d: "M8 8v12", key: "1gg7y9" }],
35
+ ["path", { d: "M4 4v16", key: "6qkkli" }]
36
+ ]);
37
+ /**
38
+ * @license lucide-react v0.453.0 - ISC
39
+ *
40
+ * This source code is licensed under the ISC license.
41
+ * See the LICENSE file in the root directory of this source tree.
42
+ */
43
+ const fa = _e("Link2", [
44
+ ["path", { d: "M9 17H7A5 5 0 0 1 7 7h2", key: "8i5ue5" }],
45
+ ["path", { d: "M15 7h2a5 5 0 1 1 0 10h-2", key: "1b9ql8" }],
46
+ ["line", { x1: "8", x2: "16", y1: "12", y2: "12", key: "1jonct" }]
47
+ ]);
48
+ function ha(e) {
49
+ const [a, n] = W(null), [s, l] = W(null), d = At();
50
+ return ie(() => {
51
+ if (!e || e.trim() === "") {
52
+ n(null), l(null);
53
+ return;
54
+ }
55
+ if (!d)
56
+ return;
57
+ (async () => {
58
+ try {
59
+ if (!e.startsWith("http://") && !e.startsWith("https://"))
60
+ throw new Error(`Invalid URL format: ${e}`);
61
+ try {
62
+ new URL(e);
63
+ } catch {
64
+ throw new Error(`Invalid URL: ${e}`);
65
+ }
66
+ const u = `${e.endsWith("/") ? e : `${e}/`}index.js`;
67
+ try {
68
+ if (!(await fetch(u, { method: "HEAD" })).ok)
69
+ throw new Error(`Module not found at ${u}`);
70
+ } catch {
71
+ }
72
+ const v = await import(
73
+ /* @vite-ignore */
74
+ /* webpackIgnore: true */
75
+ u
76
+ );
77
+ if (typeof v.useChartStore != "function")
78
+ throw new Error("useChartStore is not a function");
79
+ n(() => v.useChartStore), l(null);
80
+ } catch (h) {
81
+ const u = h instanceof Error ? h.message : "Unknown error";
82
+ console.error("Failed to load remote chart store:", u), l(u), n(null);
83
+ }
84
+ })();
85
+ }, [e, d]), a;
86
+ }
87
+ function ga(e, a) {
88
+ if (e.length === 0)
89
+ return "";
90
+ const n = e.find(
91
+ (s) => {
92
+ var l, d;
93
+ return ((l = s.customCardPreferences) == null ? void 0 : l.visualType) === "multiple" || !!((d = s.customCardPreferences) != null && d.dataInputCardIds);
94
+ }
95
+ );
96
+ if (n)
97
+ return n.id;
98
+ if (a) {
99
+ const s = e.find((l) => l.id === a);
100
+ if (s) {
101
+ const l = s.tabTitle;
102
+ if (l == "All__Header")
103
+ return e[0].id;
104
+ if (l && l.endsWith("__Header")) {
105
+ const p = l.split("__")[0], h = e.find(
106
+ (u) => u.tabTitle === p
107
+ );
108
+ return h ? h.id : e[0].id;
109
+ }
110
+ return a;
111
+ }
112
+ }
113
+ return e[0].id;
114
+ }
115
+ function ba(e, a) {
116
+ return a ? {
117
+ ...e,
118
+ settings: a
119
+ } : e;
120
+ }
121
+ function ya(e, a) {
122
+ const n = a.selectedConnectionId || e.connectionId || "";
123
+ if (!e.dataSource) {
124
+ if (!n)
125
+ return;
126
+ const s = a.selectedDatabaseName || e.lastSelectedDatabase, l = a.selectedSchemaName || e.lastSelectedSchema, d = a.selectedTableName || e.lastSelectedTable;
127
+ return {
128
+ connectionId: n,
129
+ connectionType: "",
130
+ mode: "database",
131
+ selectedEntities: [],
132
+ ...s && l && d ? {
133
+ dbSelection: {
134
+ database: s,
135
+ schema: l,
136
+ entityType: "table"
137
+ }
138
+ } : {}
139
+ };
140
+ }
141
+ return {
142
+ ...e.dataSource,
143
+ connectionId: a.selectedConnectionId || e.dataSource.connectionId || e.connectionId || ""
144
+ };
145
+ }
146
+ function va(e, {
147
+ isDevMode: a,
148
+ cardSql: n,
149
+ isShowingVisual: s,
150
+ selectedSchemaName: l,
151
+ selectedDatamodelId: d,
152
+ selectedDatabaseName: p,
153
+ selectedTableName: h,
154
+ selectedConnectionId: u,
155
+ remoteChartSettings: v,
156
+ stripConfig: g
157
+ }) {
158
+ const m = a || qt(e);
159
+ return {
160
+ ...e,
161
+ dataSource: ya(e, {
162
+ selectedConnectionId: u,
163
+ selectedDatabaseName: p,
164
+ selectedSchemaName: l,
165
+ selectedTableName: h
166
+ }),
167
+ lastSelectedSchema: l,
168
+ lastSelectedDatamodelId: d,
169
+ lastSelectedDatabase: p,
170
+ lastSelectedTable: h,
171
+ connectionId: u || e.connectionId,
172
+ sql: m ? n || e.sql : void 0,
173
+ python: m ? e.python : void 0,
174
+ config: a || !e.config ? void 0 : g(e.config),
175
+ customCfg: s ? e.customCfg : null,
176
+ preferences: e.preferences,
177
+ customCardPreferences: ba(
178
+ e.customCardPreferences,
179
+ v
180
+ )
181
+ };
182
+ }
183
+ const Ve = /* @__PURE__ */ new Set();
184
+ function $a(e) {
185
+ return Ve.add(e), () => {
186
+ Ve.delete(e);
187
+ };
188
+ }
189
+ function xa() {
190
+ Ve.forEach((e) => {
191
+ e();
192
+ });
193
+ }
194
+ const Ca = (e) => {
195
+ if (!e || !("detailTableBackup" in e))
196
+ return e;
197
+ const { detailTableBackup: a, ...n } = e;
198
+ return n;
199
+ };
200
+ async function Xe(e, a, n, s, l = "Opening library visual...") {
201
+ if (!a || !n)
202
+ throw new Error("Missing auth token or visual ID");
203
+ const d = ["resource-by-id", "visual", n], p = s.getQueryData(d);
204
+ if (p)
205
+ return console.log("Using cached visual data for:", n), { data: p, fromCache: !0 };
206
+ console.log("Fetching visual data from network for:", n);
207
+ const h = j.loading(l, {
208
+ position: "top-center"
209
+ });
210
+ try {
211
+ const u = await fetch(
212
+ `${e}/management/v1/visuals/${n}`,
213
+ {
214
+ headers: {
215
+ Authorization: `Bearer ${a}`
216
+ }
217
+ }
218
+ );
219
+ if (!u.ok)
220
+ throw new Error("Failed to load visual");
221
+ const v = await u.json();
222
+ return s.setQueryData(d, v), j.dismiss(h), { data: v, fromCache: !1 };
223
+ } catch (u) {
224
+ throw j.dismiss(h), u;
225
+ }
226
+ }
227
+ function ft(e) {
228
+ if (typeof e == "string")
229
+ return JSON.parse(e);
230
+ if (typeof e == "object")
231
+ return e;
232
+ throw new Error("Invalid frame object format");
233
+ }
234
+ function Sa(e, a) {
235
+ var d, p;
236
+ const n = (e == null ? void 0 : e.frameObject) ?? ((d = e == null ? void 0 : e.visual) == null ? void 0 : d.frameObject);
237
+ if (!n)
238
+ return !1;
239
+ const s = ft(n);
240
+ if (!(s != null && s.cards) || s.cards.length === 0)
241
+ return !1;
242
+ const l = (p = s.cards) == null ? void 0 : p.find(
243
+ (h) => h.id === s.activeCardId
244
+ );
245
+ return l ? (Qt({
246
+ ...a,
247
+ frame: s,
248
+ card: l,
249
+ visualId: (e == null ? void 0 : e.id) || s.visualId
250
+ }), !0) : !1;
251
+ }
252
+ function ka() {
253
+ const e = M(
254
+ (s) => {
255
+ var l;
256
+ return ((l = s.card.customCardPreferences) == null ? void 0 : l.url) || "";
257
+ }
258
+ ), a = ha(e);
259
+ return { getUpdatedFrame: z(() => {
260
+ var V;
261
+ xa();
262
+ const {
263
+ frame: s,
264
+ card: l,
265
+ isDevMode: d,
266
+ isShowingVisual: p,
267
+ selectedSchemaName: h,
268
+ selectedDatamodelId: u,
269
+ selectedDatabaseName: v,
270
+ selectedTableName: g,
271
+ selectedConnectionId: m
272
+ } = M.getState(), x = l.sql, I = (V = a == null ? void 0 : a.getState()) == null ? void 0 : V.settings, S = va(l, {
273
+ isDevMode: d,
274
+ cardSql: x,
275
+ isShowingVisual: p,
276
+ selectedSchemaName: h,
277
+ selectedDatamodelId: u,
278
+ selectedDatabaseName: v,
279
+ selectedTableName: g,
280
+ selectedConnectionId: m,
281
+ remoteChartSettings: I,
282
+ stripConfig: Ca
283
+ }), N = s.cards.map(
284
+ (Q) => Q.id === l.id ? S : Q
285
+ );
286
+ return {
287
+ ...s,
288
+ cards: N,
289
+ activeCardId: ga(N, s.activeCardId)
290
+ };
291
+ }, [a]) };
292
+ }
293
+ function qe() {
294
+ const { authToken: e, tokenProps: a } = Mt(), n = ce(), s = Ot(), l = Ae(), { selectVisual: d } = Ut(), {
295
+ setFrame: p,
296
+ setCard: h,
297
+ setIsDevMode: u,
298
+ initializeModeDrafts: v,
299
+ setActiveTabCardId: g,
300
+ updateDataSource: m,
301
+ setQueryResultColumns: x,
302
+ setSelectedConnectionId: I,
303
+ setSelectedDatabaseName: S,
304
+ setSelectedSchemaName: N,
305
+ setSelectedTableName: V,
306
+ setSelectedDatamodelId: Q,
307
+ setFilterValues: G,
308
+ setInlineFilterValuesMap: R,
309
+ setApplyFilters: H,
310
+ clearEditorContext: te
311
+ } = de(), {
312
+ setIsDashboardEditing: T,
313
+ setIsVisualEditing: o,
314
+ setSelectedFrameId: w,
315
+ clearSelectedFrameId: P
316
+ } = Le(), U = Z((_) => _.selectedSheetId), X = Z((_) => _.selectedFrameId), J = Z((_) => _.dashboard), ae = Z((_) => _.filterValues), O = Z(
317
+ (_) => _.inlineFilterValuesMap
318
+ ), Y = zt((l == null ? void 0 : l.id) || "", {
319
+ enabled: !!(l != null && l.id) && !!(e != null && e.accessToken)
320
+ }), se = z(
321
+ async (_) => {
322
+ try {
323
+ d(_), P(), te();
324
+ const { data: F, fromCache: K } = await Xe(
325
+ a.apiServiceUrl,
326
+ (e == null ? void 0 : e.accessToken) || "",
327
+ _.id,
328
+ n,
329
+ "Opening library visual..."
330
+ );
331
+ if (!Sa(F, {
332
+ setFrame: p,
333
+ setCard: h,
334
+ setIsDevMode: u,
335
+ initializeModeDrafts: v,
336
+ setActiveTabCardId: g,
337
+ updateDataSource: m,
338
+ setQueryResultColumns: x,
339
+ setSelectedConnectionId: I,
340
+ setSelectedDatabaseName: S,
341
+ setSelectedSchemaName: N,
342
+ setSelectedTableName: V,
343
+ setSelectedDatamodelId: Q,
344
+ setFilterValues: G,
345
+ setInlineFilterValuesMap: R,
346
+ setApplyFilters: H,
347
+ setIsDashboardEditing: T,
348
+ setIsVisualEditing: o,
349
+ dashboard: J,
350
+ selectedSheetId: U,
351
+ selectedFrameId: X,
352
+ filterValues: ae,
353
+ inlineFilterValuesMap: O
354
+ }))
355
+ throw new Error("Failed to setup editor with visual data");
356
+ return { success: !0, fromCache: K };
357
+ } catch (F) {
358
+ return console.error("Error editing visual:", F), { success: !1, error: "Failed to load visual for editing" };
359
+ }
360
+ },
361
+ [
362
+ e == null ? void 0 : e.accessToken,
363
+ a.apiServiceUrl,
364
+ n,
365
+ d,
366
+ p,
367
+ h,
368
+ T,
369
+ o,
370
+ u,
371
+ v,
372
+ g,
373
+ m,
374
+ x,
375
+ I,
376
+ S,
377
+ N,
378
+ V,
379
+ Q,
380
+ G,
381
+ R,
382
+ H,
383
+ te,
384
+ P,
385
+ J,
386
+ U,
387
+ X,
388
+ ae,
389
+ O
390
+ ]
391
+ ), ge = z(
392
+ async (_) => {
393
+ var K;
394
+ const F = (A) => (j.error(A), { success: !1, error: A });
395
+ try {
396
+ if (d(_), !U)
397
+ return F("No sheet selected. Please select a sheet first.");
398
+ const { data: A, fromCache: be } = await Xe(
399
+ a.apiServiceUrl,
400
+ (e == null ? void 0 : e.accessToken) || "",
401
+ _.id,
402
+ n,
403
+ "Adding visual to dashboard..."
404
+ ), ue = (A == null ? void 0 : A.frameObject) ?? ((K = A == null ? void 0 : A.visual) == null ? void 0 : K.frameObject);
405
+ if (!ue)
406
+ return F("Visual has no frame data");
407
+ const B = ft(ue);
408
+ if (!(B != null && B.cards) || B.cards.length === 0)
409
+ return F("Visual frame is malformed");
410
+ const le = {
411
+ ...jt(B),
412
+ visualId: _.id
413
+ // Link this frame to the library visual
414
+ };
415
+ return await s(
416
+ U,
417
+ le,
418
+ "end"
419
+ ), T(!0), w(le.id), { success: !0, fromCache: be };
420
+ } catch (A) {
421
+ return console.error("Error adding visual:", A), F(
422
+ A instanceof Error ? A.message : "Failed to add visual to dashboard"
423
+ );
424
+ }
425
+ },
426
+ [
427
+ e == null ? void 0 : e.accessToken,
428
+ a.apiServiceUrl,
429
+ n,
430
+ d,
431
+ U,
432
+ T,
433
+ w,
434
+ s
435
+ ]
436
+ );
437
+ return {
438
+ visual: Y.data,
439
+ isLoading: Y.isLoading,
440
+ isError: Y.isError,
441
+ error: Y.error,
442
+ handleEditLibraryVisual: se,
443
+ handleAddLibraryVisual: ge,
444
+ getUpdatedFrame: ka().getUpdatedFrame,
445
+ refetch: Y.refetch
446
+ };
447
+ }
448
+ function Ha() {
449
+ const e = M((p) => p.card.dataSource), {
450
+ setSelectedConnectionId: a,
451
+ setSelectedDatabaseName: n,
452
+ setSelectedSchemaName: s,
453
+ setSelectedTableName: l,
454
+ setSelectedDatamodelId: d
455
+ } = de();
456
+ ie(() => {
457
+ var I;
458
+ if (!e) return;
459
+ const { tableName: p, schemaName: h, databaseName: u, connectionId: v } = Rt(e), g = (I = e.selectedEntities) == null ? void 0 : I[0], x = (g == null ? void 0 : g.type) === "model" && "id" in g ? g.id : "";
460
+ a(v || ""), n(u || ""), s(h || ""), l(p || ""), d(x);
461
+ }, [
462
+ e,
463
+ a,
464
+ n,
465
+ s,
466
+ l,
467
+ d
468
+ ]);
469
+ }
470
+ function ht() {
471
+ var u, v;
472
+ const e = M((g) => g.card), a = M((g) => g.frame), n = $(
473
+ () => mt(a, e),
474
+ [a, e]
475
+ ), { manifest: s } = Bt(
476
+ ((u = n == null ? void 0 : n.customCardPreferences) == null ? void 0 : u.url) || ""
477
+ ), l = $(
478
+ () => {
479
+ var g;
480
+ return (g = s == null ? void 0 : s.visuals) == null ? void 0 : g.find(
481
+ (m) => {
482
+ var x;
483
+ return m.name === ((x = n == null ? void 0 : n.customCardPreferences) == null ? void 0 : x.componentName);
484
+ }
485
+ );
486
+ },
487
+ [s, (v = n == null ? void 0 : n.customCardPreferences) == null ? void 0 : v.componentName]
488
+ ), d = da(n, l), p = $(
489
+ () => ca({
490
+ frame: a,
491
+ configCard: n,
492
+ isMultiInputVisual: d === "multiple"
493
+ }),
494
+ [a, n, d]
495
+ ), h = $(() => {
496
+ const g = p.findIndex(
497
+ (m) => (m == null ? void 0 : m.id) === e.id
498
+ );
499
+ return g < 0 ? -1 : ua(e, g);
500
+ }, [p, e]);
501
+ return $(() => !n || d !== "multiple" || h < 0 ? e.type : ma(
502
+ e,
503
+ h,
504
+ l == null ? void 0 : l.slots
505
+ ) ?? e.type, [n, d, h, e, l == null ? void 0 : l.slots]);
506
+ }
507
+ function Na(e, a) {
508
+ return {
509
+ ...e,
510
+ sql: "",
511
+ python: "",
512
+ config: void 0,
513
+ customCfg: "",
514
+ preferences: {},
515
+ interactionConfig: void 0,
516
+ linkedInteractionTargetOverrides: void 0,
517
+ customCardPreferences: a ? e.customCardPreferences : void 0,
518
+ type: a ? e.type : "bar"
519
+ };
520
+ }
521
+ function wa() {
522
+ const { setTempQueryData: e } = de(), a = ce(), n = M((R) => R.tempQueryData), s = M((R) => R.card), l = ht(), d = $(() => l !== s.type ? { ...s, type: l } : s, [s, l]), { queryKey: p } = lt(d), {
523
+ setCardSql: h,
524
+ setSqlGen: u,
525
+ setCardPython: v,
526
+ setCardCustomCfg: g,
527
+ setCardPreferences: m,
528
+ clearQueryConfig: x,
529
+ setCardConfig: I,
530
+ setCardType: S,
531
+ setFrame: N,
532
+ setCard: V,
533
+ setActiveTabCardId: Q
534
+ } = de();
535
+ function G() {
536
+ var P, U, X, J;
537
+ const R = a.getQueryData(p);
538
+ n != null && n.queryData || e({
539
+ queryKey: p,
540
+ queryData: R
541
+ }), a.setQueryData(p, null), a.removeQueries({ queryKey: p, exact: !0 }), h(""), u({}), x(), I(void 0), v(""), g(""), m({});
542
+ const H = M.getState().frame, te = M.getState().card, T = mt(H, te), o = ((P = T == null ? void 0 : T.customCardPreferences) == null ? void 0 : P.visualType) === "multiple" || !!((U = T == null ? void 0 : T.customCardPreferences) != null && U.dataInputCardIds) || (((X = T == null ? void 0 : T.customCardPreferences) == null ? void 0 : X.minInputs) || 0) > 1 || (((J = T == null ? void 0 : T.customCardPreferences) == null ? void 0 : J.maxInputs) || 0) > 1, w = Na(te, o);
543
+ N({
544
+ ...H,
545
+ cards: H.cards.map(
546
+ (ae) => ae.id === w.id ? w : ae
547
+ )
548
+ }), Q(w.id), V(w), o || S("bar");
549
+ }
550
+ return G;
551
+ }
552
+ function Pa({
553
+ type: e,
554
+ isLinked: a,
555
+ className: n,
556
+ showLabel: s = !1,
557
+ showLocal: l = !1
558
+ }) {
559
+ const d = Z((N) => N.selectedFrameId), p = $t((N) => N.selectedVisual), h = M((N) => N.frame);
560
+ let u;
561
+ if (e)
562
+ u = e;
563
+ else if (a !== void 0)
564
+ u = a ? "linked" : "library";
565
+ else if (!!!(h != null && h.visualId || p != null && p.id) && d)
566
+ u = "local";
567
+ else if (p && !d)
568
+ u = "library";
569
+ else if (h != null && h.visualId && d)
570
+ u = "linked";
571
+ else if (p != null && p.id && d)
572
+ u = "library";
573
+ else
574
+ return null;
575
+ if (u === "local" && !l)
576
+ return null;
577
+ const v = {
578
+ local: "border-slate-200/70 bg-slate-50/80 text-slate-700 shadow-sm hover:bg-slate-100/80 dark:border-slate-700 dark:bg-slate-900/70 dark:text-slate-200 dark:hover:bg-slate-800/80",
579
+ linked: "border-purple-200/70 bg-gradient-to-r from-purple-50/50 to-purple-100/30 text-purple-900 shadow-sm hover:from-purple-100/60 hover:to-purple-100/50 hover:shadow-md dark:border-purple-800/50 dark:from-purple-950/40 dark:to-purple-900/30 dark:text-purple-100 dark:hover:from-purple-950/60 dark:hover:to-purple-900/50",
580
+ library: "border-blue-200/70 bg-gradient-to-r from-blue-50/50 to-blue-100/30 text-blue-900 shadow-sm hover:from-blue-100/60 hover:to-blue-100/50 hover:shadow-md dark:border-blue-800/50 dark:from-blue-950/40 dark:to-blue-900/30 dark:text-blue-100 dark:hover:from-blue-950/60 dark:hover:to-blue-900/50"
581
+ }, g = {
582
+ local: "Local to this dashboard: Changes made here only affect this dashboard copy.",
583
+ linked: "Linked to library: Changes made here update the library visual and all linked instances.",
584
+ library: "Library visual: Share and reuse this visual across multiple dashboards."
585
+ }, m = {
586
+ local: "border-slate-200 bg-slate-50 text-slate-900 dark:border-slate-700 dark:bg-slate-900 dark:text-slate-100",
587
+ linked: "border-purple-200 bg-purple-50 text-purple-900 dark:border-purple-800 dark:bg-purple-950 dark:text-purple-100",
588
+ library: "border-blue-200 bg-blue-50 text-blue-900 dark:border-blue-800 dark:bg-blue-950 dark:text-blue-100"
589
+ }, x = {
590
+ local: "fill-slate-50 dark:fill-slate-900",
591
+ linked: "fill-purple-50 dark:fill-purple-950",
592
+ library: "fill-blue-50 dark:fill-blue-950"
593
+ }, I = {
594
+ local: /* @__PURE__ */ r("span", { className: "h-2 w-2 rounded-full bg-current/70" }),
595
+ linked: /* @__PURE__ */ r(fa, { className: "h-3.5 w-3.5" }),
596
+ library: /* @__PURE__ */ r(pa, { className: "h-3.5 w-3.5" })
597
+ }, S = {
598
+ local: "Local",
599
+ linked: "Linked",
600
+ library: "Library"
601
+ };
602
+ return /* @__PURE__ */ r(ra, { children: /* @__PURE__ */ f(sa, { delayDuration: 300, children: [
603
+ /* @__PURE__ */ r(na, { asChild: !0, children: /* @__PURE__ */ f(
604
+ Ht,
605
+ {
606
+ variant: "outline",
607
+ className: fe(
608
+ "cursor-help select-none transition-all",
609
+ v[u],
610
+ n
611
+ ),
612
+ children: [
613
+ I[u],
614
+ s && /* @__PURE__ */ r("span", { className: "ml-1 text-xs font-medium leading-none", children: S[u] })
615
+ ]
616
+ }
617
+ ) }),
618
+ /* @__PURE__ */ f(
619
+ oa,
620
+ {
621
+ side: "bottom",
622
+ className: fe("max-w-xs", m[u]),
623
+ children: [
624
+ /* @__PURE__ */ r(la, { className: x[u] }),
625
+ /* @__PURE__ */ r("p", { children: g[u] })
626
+ ]
627
+ }
628
+ )
629
+ ] }) });
630
+ }
631
+ function gt(e) {
632
+ const { control: a, onChange: n } = e;
633
+ return /* @__PURE__ */ f("div", { className: "flex flex-col gap-1.5", children: [
634
+ /* @__PURE__ */ r(oe, { className: "text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground", children: "Label" }),
635
+ /* @__PURE__ */ r(
636
+ ut,
637
+ {
638
+ size: "xs",
639
+ value: a.label,
640
+ placeholder: "Control label",
641
+ onChange: (s) => n(s.target.value)
642
+ }
643
+ )
644
+ ] });
645
+ }
646
+ function Da(e) {
647
+ const { currentStep: a, labels: n } = e;
648
+ return /* @__PURE__ */ r("div", { className: "sticky top-0 z-10 -mx-1 border-b border-border/60 bg-background/95 px-1 pb-2.5 pt-1 backdrop-blur supports-[backdrop-filter]:bg-background/85", children: /* @__PURE__ */ r("div", { className: "flex flex-wrap items-center gap-2 sm:gap-2.5", children: n.map((s, l) => {
649
+ const d = l + 1, p = d === a, h = d < a;
650
+ return /* @__PURE__ */ f(yt, { children: [
651
+ /* @__PURE__ */ f("div", { className: "flex items-center gap-1.5", children: [
652
+ /* @__PURE__ */ r(
653
+ "span",
654
+ {
655
+ className: fe(
656
+ "flex h-5 w-5 items-center justify-center rounded-full border text-[10px] font-medium tabular-nums",
657
+ p ? "border-foreground bg-foreground text-background" : h ? "border-foreground/30 bg-foreground/10 text-foreground" : "border-border/60 bg-background text-muted-foreground"
658
+ ),
659
+ children: d
660
+ }
661
+ ),
662
+ /* @__PURE__ */ r(
663
+ "span",
664
+ {
665
+ className: fe(
666
+ "text-[12px]",
667
+ p ? "font-medium text-foreground" : "text-muted-foreground"
668
+ ),
669
+ children: s
670
+ }
671
+ )
672
+ ] }),
673
+ l < n.length - 1 ? /* @__PURE__ */ r(
674
+ "span",
675
+ {
676
+ className: "h-px w-4 bg-border/60 sm:w-6",
677
+ "aria-hidden": "true"
678
+ }
679
+ ) : null
680
+ ] }, s);
681
+ }) }) });
682
+ }
683
+ function he(e) {
684
+ const { secondary: a, tertiary: n, primary: s } = e;
685
+ return /* @__PURE__ */ f("div", { className: "sticky bottom-0 z-10 -mx-1 flex justify-end gap-2 border-t bg-background/95 px-1 pb-1 pt-3 backdrop-blur supports-[backdrop-filter]:bg-background/85", children: [
686
+ a,
687
+ n,
688
+ s
689
+ ] });
690
+ }
691
+ function Ea(e) {
692
+ const { control: a, scope: n, detail: s } = e;
693
+ return /* @__PURE__ */ f("div", { className: "flex items-start gap-2.5 rounded-control border border-border/60 bg-muted/30 px-3 py-2.5", children: [
694
+ /* @__PURE__ */ r(ea, { className: "mt-0.5 h-3.5 w-3.5 shrink-0 text-foreground" }),
695
+ /* @__PURE__ */ f("div", { className: "min-w-0 space-y-0.5", children: [
696
+ /* @__PURE__ */ r("div", { className: "text-[13px] font-medium text-foreground", children: a.label }),
697
+ /* @__PURE__ */ f("div", { className: "text-[12px] text-muted-foreground", children: [
698
+ at(a.type).label,
699
+ " ·",
700
+ " ",
701
+ st(a),
702
+ " ·",
703
+ " ",
704
+ rt(n, a.placement)
705
+ ] }),
706
+ s ? /* @__PURE__ */ r("div", { className: "text-[12px] text-muted-foreground", children: s }) : null
707
+ ] })
708
+ ] });
709
+ }
710
+ function Je(e) {
711
+ const {
712
+ control: a,
713
+ defaultValue: n,
714
+ availableFieldChoices: s,
715
+ availableMetricChoices: l,
716
+ previewControlDefinitions: d,
717
+ previewControlValues: p,
718
+ onControlChange: h,
719
+ onLabelChange: u,
720
+ onDefaultValueChange: v,
721
+ onBack: g,
722
+ onNext: m,
723
+ nextDisabled: x
724
+ } = e;
725
+ return /* @__PURE__ */ f("div", { className: "space-y-3", children: [
726
+ /* @__PURE__ */ r(gt, { control: a, onChange: u }),
727
+ /* @__PURE__ */ r(
728
+ it,
729
+ {
730
+ control: a,
731
+ availableFieldChoices: s,
732
+ availableMetricChoices: l,
733
+ previewControlDefinitions: d,
734
+ previewControlValues: p,
735
+ controlLifecycle: "create",
736
+ onChange: h
737
+ }
738
+ ),
739
+ /* @__PURE__ */ r(
740
+ dt,
741
+ {
742
+ control: a,
743
+ value: n,
744
+ onChange: v,
745
+ allowNoDefault: !0,
746
+ allowCardDefault: !0,
747
+ hint: "This is the value viewers will see first.",
748
+ previewControlDefinitions: d,
749
+ previewControlValues: p
750
+ }
751
+ ),
752
+ /* @__PURE__ */ r(
753
+ he,
754
+ {
755
+ secondary: /* @__PURE__ */ r(q, { type: "button", variant: "outline", size: "xs", onClick: g, children: "Back" }),
756
+ primary: /* @__PURE__ */ r(
757
+ q,
758
+ {
759
+ type: "button",
760
+ size: "xs",
761
+ onClick: m,
762
+ disabled: x,
763
+ children: "Next"
764
+ }
765
+ )
766
+ }
767
+ )
768
+ ] });
769
+ }
770
+ const Ia = /* @__PURE__ */ new Set([
771
+ "grain_selector",
772
+ "aggregation_selector",
773
+ "field_selector",
774
+ "metric_selector"
775
+ ]);
776
+ function Ze(e) {
777
+ const { text: a, ariaLabel: n } = e, [s, l] = W(!1);
778
+ return /* @__PURE__ */ f(
779
+ "button",
780
+ {
781
+ type: "button",
782
+ "aria-label": n,
783
+ onClick: async () => {
784
+ try {
785
+ await navigator.clipboard.writeText(a), l(!0), setTimeout(() => l(!1), 1200);
786
+ } catch (d) {
787
+ console.error("Failed to copy", d);
788
+ }
789
+ },
790
+ className: "group flex w-full items-center justify-between gap-2 rounded-control bg-muted/40 px-2 py-1 text-left transition-colors hover:bg-muted/60 focus-visible:bg-muted/60 focus-visible:outline-none",
791
+ children: [
792
+ /* @__PURE__ */ r("code", { className: "min-w-0 truncate font-mono text-[12px] text-foreground", children: a }),
793
+ /* @__PURE__ */ r("span", { className: "shrink-0 text-[11px] text-muted-foreground opacity-0 transition-opacity group-hover:opacity-100", children: s ? "Copied" : "Click to copy" })
794
+ ]
795
+ }
796
+ );
797
+ }
798
+ function et(e) {
799
+ const {
800
+ control: a,
801
+ scope: n,
802
+ createdReference: s,
803
+ explorerContent: l,
804
+ sqlDescription: d,
805
+ summaryDetail: p,
806
+ onBack: h,
807
+ onCancel: u,
808
+ onDone: v
809
+ } = e, g = Ia.has(a.type), m = s.match(/\[\[param\.(.+?)\]\]/), x = m ? `{{ param('${m[1]}') }}` : "";
810
+ return /* @__PURE__ */ f("div", { className: "space-y-4", children: [
811
+ /* @__PURE__ */ r(
812
+ Ea,
813
+ {
814
+ control: a,
815
+ scope: n,
816
+ detail: p
817
+ }
818
+ ),
819
+ /* @__PURE__ */ f("div", { className: "space-y-2", children: [
820
+ /* @__PURE__ */ r("p", { className: "text-[13px] font-medium text-foreground", children: "How cards use this control" }),
821
+ /* @__PURE__ */ f("div", { className: "divide-y divide-border/60 overflow-hidden rounded-control border border-border/60", children: [
822
+ g ? /* @__PURE__ */ f("div", { className: "space-y-1 px-3 py-2.5", children: [
823
+ /* @__PURE__ */ r("p", { className: "text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground", children: "Explorer cards" }),
824
+ /* @__PURE__ */ r("div", { className: "text-[12px] text-muted-foreground", children: l })
825
+ ] }) : null,
826
+ /* @__PURE__ */ f("div", { className: "space-y-1.5 px-3 py-2.5", children: [
827
+ /* @__PURE__ */ r("p", { className: "text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground", children: "SQL cards" }),
828
+ /* @__PURE__ */ r(
829
+ Ze,
830
+ {
831
+ text: s,
832
+ ariaLabel: "Copy SQL control reference"
833
+ }
834
+ ),
835
+ x ? /* @__PURE__ */ r(
836
+ Ze,
837
+ {
838
+ text: x,
839
+ ariaLabel: "Copy Jinja control reference"
840
+ }
841
+ ) : null,
842
+ /* @__PURE__ */ f("p", { className: "text-[12px] text-muted-foreground", children: [
843
+ d,
844
+ " ",
845
+ /* @__PURE__ */ r(
846
+ "a",
847
+ {
848
+ href: "https://docs.semaphor.cloud/docs/concepts/template-expressions",
849
+ target: "_blank",
850
+ rel: "noreferrer",
851
+ className: "underline underline-offset-2 hover:text-foreground",
852
+ children: "Template expressions docs"
853
+ }
854
+ ),
855
+ "."
856
+ ] })
857
+ ] })
858
+ ] })
859
+ ] }),
860
+ /* @__PURE__ */ r(
861
+ he,
862
+ {
863
+ secondary: /* @__PURE__ */ r(q, { type: "button", variant: "outline", size: "xs", onClick: h, children: "Back" }),
864
+ tertiary: /* @__PURE__ */ r(q, { type: "button", variant: "outline", size: "xs", onClick: u, children: "Cancel" }),
865
+ primary: /* @__PURE__ */ r(q, { type: "button", size: "xs", onClick: v, children: "Done" })
866
+ }
867
+ )
868
+ ] });
869
+ }
870
+ function Ta(e) {
871
+ const a = me(
872
+ e.scope,
873
+ e.existingControls,
874
+ e.reservedIds
875
+ ), n = e.type === a.type ? {
876
+ ...a,
877
+ label: Fe[e.type]
878
+ } : {
879
+ ...nt({
880
+ controls: [
881
+ {
882
+ ...a,
883
+ label: Fe[e.type]
884
+ }
885
+ ],
886
+ controlId: a.id,
887
+ nextType: e.type
888
+ }).controls[0],
889
+ label: Fe[e.type]
890
+ };
891
+ return {
892
+ step: 2,
893
+ control: n,
894
+ defaultValue: pe(n, void 0)
895
+ };
896
+ }
897
+ function Ka({
898
+ scope: e,
899
+ controls: a,
900
+ reservedControlIds: n,
901
+ defaultValues: s,
902
+ onChange: l,
903
+ emptyMessage: d,
904
+ initialCreateFlow: p = !1,
905
+ usageByControlId: h,
906
+ availableFieldChoices: u,
907
+ availableMetricChoices: v,
908
+ structuralParticipants: g,
909
+ structuralParticipantIdsByControlId: m,
910
+ card: x,
911
+ allowedControlTypes: I,
912
+ onCreateFlowActiveChange: S,
913
+ onCreateFlowComplete: N
914
+ }) {
915
+ const V = $(
916
+ () => new Set(n || []),
917
+ [n]
918
+ ), Q = wt(e), G = vt(e), [R, H] = W(
919
+ null
920
+ ), [te, T] = W(
921
+ null
922
+ ), [o, w] = W(
923
+ () => p ? {
924
+ step: 1,
925
+ control: me(e, a, Array.from(V))
926
+ } : null
927
+ ), P = Se({}), U = Se(void 0), X = Se(p), J = $(() => {
928
+ const t = Be({ scope: e, card: x });
929
+ if (!I)
930
+ return t;
931
+ const c = new Set(I);
932
+ return t.filter((i) => c.has(i.value));
933
+ }, [I, x, e]), ae = z(
934
+ (t) => {
935
+ const c = Be({
936
+ scope: e,
937
+ card: x,
938
+ includeType: I ? void 0 : t
939
+ });
940
+ if (!I)
941
+ return c;
942
+ const i = new Set(I);
943
+ return c.filter((b) => i.has(b.value));
944
+ },
945
+ [I, x, e]
946
+ ), O = z(
947
+ (t) => e === "dashboard" && (t === "field_selector" || t === "metric_selector"),
948
+ [e]
949
+ ), Y = $(
950
+ () => o ? $e(
951
+ g || [],
952
+ o.control.type
953
+ ) : [],
954
+ [o, g]
955
+ ), se = $(() => {
956
+ if (!o)
957
+ return {
958
+ fields: u || [],
959
+ metrics: v || []
960
+ };
961
+ if (!O(o.control.type))
962
+ return {
963
+ fields: u || [],
964
+ metrics: v || []
965
+ };
966
+ const t = o.selectedCardIds || [], c = ke({
967
+ controlType: o.control.type,
968
+ participants: g || [],
969
+ selectedCardIds: t
970
+ });
971
+ return {
972
+ fields: o.control.type === "field_selector" ? c.choices.map((i) => ({
973
+ option: i,
974
+ target: c.fieldTargetMap[i.value]
975
+ })) : [],
976
+ metrics: o.control.type === "metric_selector" ? c.choices.map((i) => ({
977
+ option: i,
978
+ target: c.metricTargetMap[i.value]
979
+ })) : []
980
+ };
981
+ }, [
982
+ u,
983
+ v,
984
+ o,
985
+ O,
986
+ g
987
+ ]);
988
+ ie(() => {
989
+ S == null || S(!!o);
990
+ }, [o, S]), ie(() => {
991
+ const t = p && !X.current;
992
+ X.current = p, t && (w({
993
+ step: 1,
994
+ control: me(e, a, Array.from(V))
995
+ }), T(null), H(null));
996
+ }, [a, p, V, e]);
997
+ const ge = (t) => {
998
+ if (!O(t.type))
999
+ return {
1000
+ fields: u || [],
1001
+ metrics: v || []
1002
+ };
1003
+ const c = (m == null ? void 0 : m[t.id]) || [];
1004
+ if (c.length === 0)
1005
+ return {
1006
+ fields: u || [],
1007
+ metrics: v || []
1008
+ };
1009
+ const i = ke({
1010
+ controlType: t.type,
1011
+ participants: g || [],
1012
+ selectedCardIds: c
1013
+ });
1014
+ return {
1015
+ fields: t.type === "field_selector" ? i.choices.map((b) => ({
1016
+ option: b,
1017
+ target: i.fieldTargetMap[b.value]
1018
+ })) : [],
1019
+ metrics: t.type === "metric_selector" ? i.choices.map((b) => ({
1020
+ option: b,
1021
+ target: i.metricTargetMap[b.value]
1022
+ })) : []
1023
+ };
1024
+ }, _ = (t) => {
1025
+ if (!O(t.control.type))
1026
+ return {
1027
+ nextControl: t.control,
1028
+ cardBindingsById: void 0
1029
+ };
1030
+ const c = (m == null ? void 0 : m[t.control.id]) || [], i = ke({
1031
+ controlType: t.control.type,
1032
+ participants: g || [],
1033
+ selectedCardIds: t.nextSelectedCardIds
1034
+ }), b = Ft({
1035
+ control: t.control,
1036
+ choices: i.choices
1037
+ }), C = Object.fromEntries(
1038
+ c.filter((k) => !t.nextSelectedCardIds.includes(k)).map((k) => [k, void 0])
1039
+ );
1040
+ return t.nextSelectedCardIds.length > 0 && b.source.kind === "manual" && b.source.options.length > 0 && Object.assign(
1041
+ C,
1042
+ We({
1043
+ control: b,
1044
+ participants: g || [],
1045
+ selectedCardIds: t.nextSelectedCardIds,
1046
+ matrixTargetIds: t.matrixTargetIds
1047
+ })
1048
+ ), {
1049
+ nextControl: b,
1050
+ cardBindingsById: C
1051
+ };
1052
+ }, F = z(
1053
+ (t, c = s, i = { type: "update" }) => {
1054
+ const b = t.map((C) => (Ne({
1055
+ control: C,
1056
+ defaultValues: c
1057
+ }), xt(
1058
+ C
1059
+ )));
1060
+ l(b, c, i);
1061
+ },
1062
+ [s, l]
1063
+ ), K = (t, c) => {
1064
+ const i = a.find(
1065
+ (E) => E.id === t
1066
+ );
1067
+ let b = a.map((E) => E.id !== t ? E : c(E));
1068
+ const C = b.find(
1069
+ (E) => E.id === t
1070
+ );
1071
+ let k, y;
1072
+ if (C && (!i || It({ control: i }, { control: C })) && e === "dashboard" && (C.type === "field_selector" || C.type === "metric_selector")) {
1073
+ const E = (m == null ? void 0 : m[C.id]) || [], ne = _({
1074
+ control: C,
1075
+ nextSelectedCardIds: E
1076
+ });
1077
+ b = b.map(
1078
+ (re) => re.id === t ? ne.nextControl : re
1079
+ ), k = ne.cardBindingsById, y = [C.id];
1080
+ } else if (i && (!C || !Tt(C.type)) && e === "dashboard" && (i.type === "field_selector" || i.type === "metric_selector")) {
1081
+ const E = (m == null ? void 0 : m[i.id]) || [];
1082
+ k = Object.fromEntries(
1083
+ E.map((ne) => [ne, void 0])
1084
+ ), y = [i.id];
1085
+ }
1086
+ const D = b.find(
1087
+ (E) => E.id === t
1088
+ );
1089
+ let L = s;
1090
+ if (i && D) {
1091
+ const E = Ne({
1092
+ control: i,
1093
+ defaultValues: s
1094
+ });
1095
+ i.source.kind === "manual" && D.source.kind === "sql_query" && (P.current[t] = E);
1096
+ const ne = E === void 0 && i.source.kind === "sql_query" && D.source.kind === "manual" ? P.current[t] : E, re = Ke({
1097
+ previousControl: i,
1098
+ nextControl: D,
1099
+ currentDefaultValue: ne
1100
+ });
1101
+ D.source.kind === "manual" && (P.current[t] = re), s && (L = { ...s }, re === void 0 ? delete L[t] : L[t] = re), b = b.map(
1102
+ (Qe) => Qe.id === t ? { ...D, defaultValue: re } : Qe
1103
+ );
1104
+ }
1105
+ F(b, L, {
1106
+ type: "update",
1107
+ cardBindingsById: k,
1108
+ affectedBindingControlIds: y
1109
+ });
1110
+ }, A = (t, c) => {
1111
+ if (!c.trim())
1112
+ return;
1113
+ const i = Vt(c);
1114
+ if (i === t || V.has(i) || a.some(
1115
+ (k) => k.id === i && k.id !== t
1116
+ ))
1117
+ return;
1118
+ const b = a.map(
1119
+ (k) => k.id === t ? { ...k, id: i } : k
1120
+ );
1121
+ if (!s) {
1122
+ F(b, void 0, {
1123
+ type: "rename",
1124
+ oldId: t,
1125
+ newId: i
1126
+ });
1127
+ return;
1128
+ }
1129
+ const C = { ...s };
1130
+ Object.prototype.hasOwnProperty.call(C, t) && (C[i] = C[t], delete C[t]), F(b, C, {
1131
+ type: "rename",
1132
+ oldId: t,
1133
+ newId: i
1134
+ });
1135
+ }, be = (t) => {
1136
+ const c = a.filter((b) => b.id !== t);
1137
+ if (!s) {
1138
+ F(c, void 0, { type: "remove", controlId: t });
1139
+ return;
1140
+ }
1141
+ const i = { ...s };
1142
+ delete i[t], F(c, i, { type: "remove", controlId: t });
1143
+ }, ue = z(() => {
1144
+ U.current = void 0, w({
1145
+ step: 1,
1146
+ control: me(e, a, Array.from(V))
1147
+ }), T(null), H(null);
1148
+ }, [a, V, e]), B = (t) => {
1149
+ w(
1150
+ (c) => c && (() => {
1151
+ const i = t(c.control);
1152
+ c.control.source.kind === "manual" && i.source.kind === "sql_query" && (U.current = c.defaultValue);
1153
+ const b = c.defaultValue === void 0 && c.control.source.kind === "sql_query" && i.source.kind === "manual" ? U.current : c.defaultValue, C = Ke({
1154
+ previousControl: c.control,
1155
+ nextControl: i,
1156
+ currentDefaultValue: b
1157
+ });
1158
+ return i.source.kind === "manual" && (U.current = C), {
1159
+ ...c,
1160
+ control: i,
1161
+ defaultValue: C
1162
+ };
1163
+ })()
1164
+ );
1165
+ }, le = (t) => {
1166
+ w(
1167
+ (c) => c && (c.control.source.kind === "manual" && (U.current = t), {
1168
+ ...c,
1169
+ defaultValue: t
1170
+ })
1171
+ );
1172
+ }, ye = (() => {
1173
+ if (!o)
1174
+ return !1;
1175
+ if (o.step === 2 && O(o.control.type))
1176
+ return (o.selectedCardIds || []).length > 0 && Ct({
1177
+ participants: g || [],
1178
+ selectedCardIds: o.selectedCardIds || [],
1179
+ control: o.control,
1180
+ selected: o.matrixTargetIds
1181
+ });
1182
+ if (o.step !== 2 && o.step !== 3 || !o.control.label.trim())
1183
+ return !1;
1184
+ const c = o.control.source.kind === "sql_query" ? o.control : He(o.control);
1185
+ if (c.source.kind === "manual" && (St(c) && c.source.options.length === 0 || c.source.options.some(
1186
+ (b) => b.label.trim().length === 0 || b.value.trim().length === 0
1187
+ )))
1188
+ return !1;
1189
+ if (c.source.kind === "sql_query") {
1190
+ const { connectionId: i, sql: b, valueColumn: C } = c.source;
1191
+ return i.trim().length > 0 && b.trim().length > 0 && C.trim().length > 0;
1192
+ }
1193
+ return kt(
1194
+ pe(c, o.defaultValue)
1195
+ );
1196
+ })(), Oe = () => {
1197
+ var k;
1198
+ if (!o)
1199
+ return;
1200
+ const t = He(o.control), c = Et({
1201
+ label: t.label,
1202
+ fallbackId: t.id,
1203
+ existingControls: a,
1204
+ reservedIds: Array.from(V)
1205
+ }), i = {
1206
+ ...t,
1207
+ id: c
1208
+ }, b = e === "dashboard" && (i.type === "field_selector" || i.type === "metric_selector") && ((k = o.selectedCardIds) != null && k.length) ? We({
1209
+ control: i,
1210
+ participants: g || [],
1211
+ selectedCardIds: o.selectedCardIds,
1212
+ matrixTargetIds: o.matrixTargetIds
1213
+ }) : void 0, C = pe(
1214
+ i,
1215
+ o.defaultValue
1216
+ );
1217
+ w({
1218
+ step: e === "dashboard" && (i.type === "field_selector" || i.type === "metric_selector") ? 4 : 3,
1219
+ control: i,
1220
+ defaultValue: C,
1221
+ createdControlId: c,
1222
+ selectedCardIds: o.selectedCardIds,
1223
+ matrixTargetIds: o.matrixTargetIds,
1224
+ cardBindingsById: b
1225
+ });
1226
+ }, ve = z(() => {
1227
+ w(null);
1228
+ }, []), Ue = z(() => {
1229
+ if (!(o != null && o.createdControlId)) {
1230
+ w(null);
1231
+ return;
1232
+ }
1233
+ const t = o.control, c = o.createdControlId, i = pe(
1234
+ t,
1235
+ o.defaultValue
1236
+ );
1237
+ if (s) {
1238
+ const b = { ...s };
1239
+ i === void 0 ? delete b[c] : b[c] = i, F(
1240
+ [
1241
+ ...a,
1242
+ {
1243
+ ...t,
1244
+ defaultValue: i
1245
+ }
1246
+ ],
1247
+ b,
1248
+ {
1249
+ type: "add",
1250
+ cardBindingsById: o.cardBindingsById
1251
+ }
1252
+ );
1253
+ } else
1254
+ F(
1255
+ [
1256
+ ...a,
1257
+ {
1258
+ ...t,
1259
+ defaultValue: i
1260
+ }
1261
+ ],
1262
+ void 0,
1263
+ {
1264
+ type: "add",
1265
+ cardBindingsById: o.cardBindingsById
1266
+ }
1267
+ );
1268
+ T(c), w(null), N == null || N();
1269
+ }, [a, o, s, F, N]), bt = o ? O(o.control.type) ? ["Choose type", "Select cards", "Configure", "Finish"] : ["Choose type", "Configure", "Finish"] : [], ze = o != null && o.createdControlId ? `[[param.${o.createdControlId}]]` : o ? `[[param.${Nt(o.control.label) || o.control.id}]]` : "", xe = Pe({
1270
+ controls: a,
1271
+ defaultValues: s
1272
+ }), Ce = o ? [...a, o.control] : a, je = o ? Pe({
1273
+ controls: Ce,
1274
+ defaultValues: s,
1275
+ overrides: [
1276
+ {
1277
+ controlId: o.control.id,
1278
+ value: o.defaultValue
1279
+ }
1280
+ ]
1281
+ }) : xe;
1282
+ return /* @__PURE__ */ f("div", { className: "space-y-4", children: [
1283
+ o ? /* @__PURE__ */ f("div", { className: "space-y-4 pb-1", children: [
1284
+ /* @__PURE__ */ r(
1285
+ Da,
1286
+ {
1287
+ currentStep: o.step,
1288
+ labels: bt
1289
+ }
1290
+ ),
1291
+ o.step === 1 && (() => {
1292
+ const t = /* @__PURE__ */ new Set([
1293
+ "grain_selector",
1294
+ "aggregation_selector",
1295
+ "field_selector",
1296
+ "metric_selector"
1297
+ ]), c = /* @__PURE__ */ new Set([
1298
+ // Temporarily hide these from the add-control dialog while
1299
+ // keeping the shared definitions for existing controls.
1300
+ "date",
1301
+ "text"
1302
+ ]), i = J.filter(
1303
+ (k) => !t.has(k.value) && !c.has(k.value)
1304
+ ), b = J.filter(
1305
+ (k) => t.has(k.value)
1306
+ ), C = (k) => /* @__PURE__ */ f(
1307
+ "button",
1308
+ {
1309
+ type: "button",
1310
+ className: "rounded-control border border-border/60 bg-background px-3 py-2.5 text-left transition-colors hover:bg-muted/40 focus-visible:bg-muted/40 focus-visible:outline-none",
1311
+ onClick: () => w(
1312
+ Ta({
1313
+ scope: e,
1314
+ existingControls: a,
1315
+ reservedIds: Array.from(V),
1316
+ type: k.value
1317
+ })
1318
+ ),
1319
+ children: [
1320
+ /* @__PURE__ */ r("div", { className: "text-[13px] font-medium text-foreground", children: k.label }),
1321
+ /* @__PURE__ */ r("p", { className: "mt-0.5 text-[12px] text-muted-foreground", children: k.description })
1322
+ ]
1323
+ },
1324
+ k.value
1325
+ );
1326
+ return /* @__PURE__ */ f("div", { className: "space-y-4", children: [
1327
+ e === "card" && (x == null ? void 0 : x.sql) == null ? /* @__PURE__ */ r("p", { className: "text-[12px] text-muted-foreground", children: "Explorer cards support displayed metric, group by field, aggregation, and time grain controls here." }) : null,
1328
+ i.length > 0 && /* @__PURE__ */ f("div", { className: "space-y-1.5", children: [
1329
+ /* @__PURE__ */ r("p", { className: "text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground", children: "Input controls" }),
1330
+ /* @__PURE__ */ r("div", { className: "grid gap-1.5 sm:grid-cols-2", children: i.map(C) })
1331
+ ] }),
1332
+ b.length > 0 && /* @__PURE__ */ f("div", { className: "space-y-1.5", children: [
1333
+ /* @__PURE__ */ r("p", { className: "text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground", children: "Data-driven controls" }),
1334
+ /* @__PURE__ */ r("div", { className: "grid gap-1.5 sm:grid-cols-2", children: b.map(C) })
1335
+ ] }),
1336
+ /* @__PURE__ */ r(
1337
+ he,
1338
+ {
1339
+ secondary: /* @__PURE__ */ r(
1340
+ q,
1341
+ {
1342
+ type: "button",
1343
+ variant: "outline",
1344
+ size: "xs",
1345
+ onClick: ve,
1346
+ children: "Back to controls"
1347
+ }
1348
+ )
1349
+ }
1350
+ )
1351
+ ] });
1352
+ })(),
1353
+ o.step === 2 && O(o.control.type) && /* @__PURE__ */ f("div", { className: "space-y-3", children: [
1354
+ /* @__PURE__ */ f("div", { className: "space-y-3", children: [
1355
+ /* @__PURE__ */ r(
1356
+ gt,
1357
+ {
1358
+ control: o.control,
1359
+ onChange: (t) => B((c) => ({
1360
+ ...c,
1361
+ label: t
1362
+ }))
1363
+ }
1364
+ ),
1365
+ /* @__PURE__ */ r("p", { className: "text-[12px] text-muted-foreground", children: "Choose which cards should respond to this shared control." })
1366
+ ] }),
1367
+ Y.length === 0 ? /* @__PURE__ */ r("div", { className: "rounded-control border border-border/60 bg-muted/30 px-3 py-2.5 text-[12px] text-muted-foreground", children: "No eligible cards are available yet. Add compatible metrics or group-by fields to cards first." }) : /* @__PURE__ */ r("div", { className: "space-y-1 rounded-control border border-border/60 bg-background p-2", children: Y.map((t) => {
1368
+ const c = (o.selectedCardIds || []).includes(t.cardId);
1369
+ return /* @__PURE__ */ f(
1370
+ "label",
1371
+ {
1372
+ className: "flex items-start gap-2 rounded-control px-1.5 py-1 text-[13px] hover:bg-muted/40",
1373
+ children: [
1374
+ /* @__PURE__ */ r(
1375
+ Pt,
1376
+ {
1377
+ checked: c,
1378
+ onCheckedChange: (i) => w(
1379
+ (b) => b && {
1380
+ ...b,
1381
+ selectedCardIds: i === !0 ? [
1382
+ ...b.selectedCardIds || [],
1383
+ t.cardId
1384
+ ] : (b.selectedCardIds || []).filter(
1385
+ (C) => C !== t.cardId
1386
+ )
1387
+ }
1388
+ )
1389
+ }
1390
+ ),
1391
+ /* @__PURE__ */ f("div", { className: "min-w-0", children: [
1392
+ /* @__PURE__ */ r("div", { className: "font-medium text-foreground", children: t.title }),
1393
+ /* @__PURE__ */ r("div", { className: "text-[12px] text-muted-foreground", children: o.control.type === "field_selector" ? `${t.fieldChoices.length} compatible group-by fields` : `${t.metricChoices.length} compatible metrics` })
1394
+ ] })
1395
+ ]
1396
+ },
1397
+ t.cardId
1398
+ );
1399
+ }) }),
1400
+ /* @__PURE__ */ r(
1401
+ Ye,
1402
+ {
1403
+ participants: Y,
1404
+ selectedCardIds: o.selectedCardIds || [],
1405
+ control: o.control,
1406
+ selected: o.matrixTargetIds,
1407
+ onChange: (t, c) => w((i) => i && { ...i, matrixTargetIds: { ...i.matrixTargetIds, [t]: c } })
1408
+ }
1409
+ ),
1410
+ /* @__PURE__ */ r(
1411
+ he,
1412
+ {
1413
+ secondary: /* @__PURE__ */ r(
1414
+ q,
1415
+ {
1416
+ type: "button",
1417
+ variant: "outline",
1418
+ size: "xs",
1419
+ onClick: () => w(
1420
+ (t) => t && {
1421
+ ...t,
1422
+ step: 1,
1423
+ selectedCardIds: []
1424
+ }
1425
+ ),
1426
+ children: "Back"
1427
+ }
1428
+ ),
1429
+ primary: /* @__PURE__ */ r(
1430
+ q,
1431
+ {
1432
+ type: "button",
1433
+ size: "xs",
1434
+ onClick: () => w(
1435
+ (t) => t && {
1436
+ ...t,
1437
+ step: 3
1438
+ }
1439
+ ),
1440
+ disabled: !ye,
1441
+ children: "Next"
1442
+ }
1443
+ )
1444
+ }
1445
+ )
1446
+ ] }),
1447
+ o.step === 2 && !O(o.control.type) && /* @__PURE__ */ r(
1448
+ Je,
1449
+ {
1450
+ control: o.control,
1451
+ defaultValue: o.defaultValue,
1452
+ availableFieldChoices: se.fields,
1453
+ availableMetricChoices: se.metrics,
1454
+ previewControlDefinitions: Ce,
1455
+ previewControlValues: je,
1456
+ onControlChange: (t) => B(() => t),
1457
+ onLabelChange: (t) => B((c) => ({
1458
+ ...c,
1459
+ label: t
1460
+ })),
1461
+ onDefaultValueChange: le,
1462
+ onBack: () => w(
1463
+ (t) => t && {
1464
+ ...t,
1465
+ step: 1
1466
+ }
1467
+ ),
1468
+ onNext: Oe,
1469
+ nextDisabled: !ye
1470
+ }
1471
+ ),
1472
+ o.step === 3 && O(o.control.type) && /* @__PURE__ */ r(
1473
+ Je,
1474
+ {
1475
+ control: o.control,
1476
+ defaultValue: o.defaultValue,
1477
+ availableFieldChoices: se.fields,
1478
+ availableMetricChoices: se.metrics,
1479
+ previewControlDefinitions: Ce,
1480
+ previewControlValues: je,
1481
+ onControlChange: (t) => B(() => t),
1482
+ onLabelChange: (t) => B((c) => ({
1483
+ ...c,
1484
+ label: t
1485
+ })),
1486
+ onDefaultValueChange: le,
1487
+ onBack: () => w(
1488
+ (t) => t && {
1489
+ ...t,
1490
+ step: 2
1491
+ }
1492
+ ),
1493
+ onNext: Oe,
1494
+ nextDisabled: !ye
1495
+ }
1496
+ ),
1497
+ o.step === 3 && !O(o.control.type) && /* @__PURE__ */ r(
1498
+ et,
1499
+ {
1500
+ control: o.control,
1501
+ scope: e,
1502
+ createdReference: ze,
1503
+ explorerContent: /* @__PURE__ */ f(ee, { children: [
1504
+ "Open the card and use",
1505
+ " ",
1506
+ /* @__PURE__ */ r("span", { className: "font-medium text-foreground", children: "Settings → Controls" }),
1507
+ " ",
1508
+ "to choose what this control changes."
1509
+ ] }),
1510
+ sqlDescription: "Reference this control directly in the SQL editor.",
1511
+ onBack: () => w(
1512
+ (t) => t && {
1513
+ ...t,
1514
+ step: 2
1515
+ }
1516
+ ),
1517
+ onCancel: ve,
1518
+ onDone: Ue
1519
+ }
1520
+ ),
1521
+ o.step === 4 && O(o.control.type) && /* @__PURE__ */ r(
1522
+ et,
1523
+ {
1524
+ control: o.control,
1525
+ scope: e,
1526
+ createdReference: ze,
1527
+ summaryDetail: /* @__PURE__ */ f(ee, { children: [
1528
+ "Used by ",
1529
+ (o.selectedCardIds || []).length,
1530
+ " selected card",
1531
+ (o.selectedCardIds || []).length === 1 ? "" : "s"
1532
+ ] }),
1533
+ explorerContent: /* @__PURE__ */ r(ee, { children: "Selected cards have been set up to respond to this control automatically." }),
1534
+ sqlDescription: "SQL cards can still reference this control directly in the SQL editor.",
1535
+ onBack: () => w(
1536
+ (t) => t && {
1537
+ ...t,
1538
+ step: 3
1539
+ }
1540
+ ),
1541
+ onCancel: ve,
1542
+ onDone: Ue
1543
+ }
1544
+ )
1545
+ ] }) : null,
1546
+ !o && a.length === 0 ? /* @__PURE__ */ r("div", { className: "rounded-md border border-dashed p-3 text-sm text-muted-foreground", children: d }) : null,
1547
+ !o && a.map((t) => {
1548
+ const c = ge(t), i = h == null ? void 0 : h[t.id], b = Ne({
1549
+ control: t,
1550
+ defaultValues: s
1551
+ }), C = te === t.id, k = "inline-flex shrink-0 items-center rounded-[4px] border border-border/60 bg-muted/40 px-1.5 py-0.5 text-[11px] font-medium text-muted-foreground";
1552
+ return /* @__PURE__ */ f(
1553
+ "div",
1554
+ {
1555
+ className: "rounded-control border border-border/60",
1556
+ children: [
1557
+ /* @__PURE__ */ f("div", { className: "flex items-center gap-2 px-3 py-2.5", children: [
1558
+ /* @__PURE__ */ f(
1559
+ "button",
1560
+ {
1561
+ type: "button",
1562
+ className: "flex min-w-0 flex-1 items-start gap-2 rounded-control text-left focus:outline-none focus-visible:bg-muted/40",
1563
+ onClick: () => T(
1564
+ (y) => y === t.id ? null : t.id
1565
+ ),
1566
+ children: [
1567
+ C ? /* @__PURE__ */ r(Re, { className: "mt-0.5 h-3.5 w-3.5 shrink-0 text-muted-foreground" }) : /* @__PURE__ */ r(Ge, { className: "mt-0.5 h-3.5 w-3.5 shrink-0 text-muted-foreground" }),
1568
+ /* @__PURE__ */ f("div", { className: "min-w-0", children: [
1569
+ /* @__PURE__ */ f("div", { className: "flex flex-wrap items-center gap-1.5", children: [
1570
+ /* @__PURE__ */ r("span", { className: "truncate text-[13px] font-medium text-foreground", children: t.label || "Untitled control" }),
1571
+ /* @__PURE__ */ r("span", { className: k, children: at(t.type).label }),
1572
+ /* @__PURE__ */ r("span", { className: k, children: rt(e, t.placement) })
1573
+ ] }),
1574
+ /* @__PURE__ */ f("div", { className: "mt-0.5 text-[12px] text-muted-foreground", children: [
1575
+ st(t),
1576
+ i != null && i.status ? ` · ${i.status}` : ""
1577
+ ] })
1578
+ ] })
1579
+ ]
1580
+ }
1581
+ ),
1582
+ /* @__PURE__ */ r(
1583
+ q,
1584
+ {
1585
+ type: "button",
1586
+ size: "xs",
1587
+ variant: "ghost",
1588
+ className: "h-7 w-7 shrink-0 p-0 text-muted-foreground",
1589
+ onClick: () => be(t.id),
1590
+ "aria-label": `Remove ${t.label}`,
1591
+ children: /* @__PURE__ */ r(Kt, { className: "h-3.5 w-3.5" })
1592
+ }
1593
+ )
1594
+ ] }),
1595
+ C && /* @__PURE__ */ f("div", { className: "space-y-4 border-t border-border/60 px-3 py-3", children: [
1596
+ /* @__PURE__ */ f("div", { className: "grid gap-3 md:grid-cols-3", children: [
1597
+ /* @__PURE__ */ f("div", { className: "flex flex-col gap-1.5", children: [
1598
+ /* @__PURE__ */ r(oe, { className: "text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground", children: "Label" }),
1599
+ /* @__PURE__ */ r(
1600
+ ut,
1601
+ {
1602
+ size: "xs",
1603
+ value: t.label,
1604
+ placeholder: "Control label",
1605
+ onChange: (y) => K(t.id, (D) => ({
1606
+ ...D,
1607
+ label: y.target.value
1608
+ }))
1609
+ }
1610
+ )
1611
+ ] }),
1612
+ /* @__PURE__ */ f("div", { className: "flex flex-col gap-1.5", children: [
1613
+ /* @__PURE__ */ r(oe, { className: "text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground", children: "Type" }),
1614
+ /* @__PURE__ */ f(
1615
+ we,
1616
+ {
1617
+ value: t.type,
1618
+ onValueChange: (y) => {
1619
+ const D = nt({
1620
+ controls: a,
1621
+ controlId: t.id,
1622
+ nextType: y,
1623
+ defaultValues: s
1624
+ });
1625
+ F(D.controls, D.defaultValues);
1626
+ },
1627
+ children: [
1628
+ /* @__PURE__ */ r(De, { size: "xs", children: /* @__PURE__ */ r(Ee, {}) }),
1629
+ /* @__PURE__ */ r(Ie, { children: ae(t.type).map(
1630
+ (y) => /* @__PURE__ */ r(
1631
+ Te,
1632
+ {
1633
+ value: y.value,
1634
+ children: y.label
1635
+ },
1636
+ y.value
1637
+ )
1638
+ ) })
1639
+ ]
1640
+ }
1641
+ )
1642
+ ] }),
1643
+ /* @__PURE__ */ f("div", { className: "flex flex-col gap-1.5", children: [
1644
+ /* @__PURE__ */ r(oe, { className: "text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground", children: "Show in" }),
1645
+ /* @__PURE__ */ f(
1646
+ we,
1647
+ {
1648
+ value: t.placement || G,
1649
+ onValueChange: (y) => K(t.id, (D) => ({
1650
+ ...D,
1651
+ placement: y
1652
+ })),
1653
+ children: [
1654
+ /* @__PURE__ */ r(De, { size: "xs", children: /* @__PURE__ */ r(Ee, {}) }),
1655
+ /* @__PURE__ */ r(Ie, { children: Q.map((y) => /* @__PURE__ */ r(Te, { value: y.value, children: y.label }, y.value)) })
1656
+ ]
1657
+ }
1658
+ )
1659
+ ] })
1660
+ ] }),
1661
+ O(t.type) ? /* @__PURE__ */ f(ee, { children: [
1662
+ /* @__PURE__ */ r(
1663
+ Wt,
1664
+ {
1665
+ type: t.type,
1666
+ participants: $e(
1667
+ g || [],
1668
+ t.type
1669
+ ).map((y) => ({
1670
+ cardId: y.cardId,
1671
+ title: y.title,
1672
+ choiceCount: t.type === "field_selector" ? y.fieldChoices.length : y.metricChoices.length
1673
+ })),
1674
+ selectedCardIds: (m == null ? void 0 : m[t.id]) || [],
1675
+ onChange: (y) => {
1676
+ const D = _({
1677
+ control: t,
1678
+ nextSelectedCardIds: y
1679
+ }), L = a.map(
1680
+ (E) => E.id === t.id ? D.nextControl : E
1681
+ );
1682
+ F(L, s, {
1683
+ type: "update",
1684
+ cardBindingsById: D.cardBindingsById
1685
+ });
1686
+ }
1687
+ }
1688
+ ),
1689
+ /* @__PURE__ */ r(
1690
+ Ye,
1691
+ {
1692
+ participants: g || [],
1693
+ selectedCardIds: (m == null ? void 0 : m[t.id]) || [],
1694
+ control: t,
1695
+ onChange: (y, D) => {
1696
+ const L = _({
1697
+ control: t,
1698
+ nextSelectedCardIds: (m == null ? void 0 : m[t.id]) || [],
1699
+ matrixTargetIds: { [y]: D }
1700
+ });
1701
+ F(
1702
+ a.map((E) => E.id === t.id ? L.nextControl : E),
1703
+ s,
1704
+ { type: "update", cardBindingsById: L.cardBindingsById }
1705
+ );
1706
+ }
1707
+ }
1708
+ )
1709
+ ] }) : null,
1710
+ /* @__PURE__ */ r(
1711
+ it,
1712
+ {
1713
+ control: t,
1714
+ availableFieldChoices: c.fields,
1715
+ availableMetricChoices: c.metrics,
1716
+ previewControlDefinitions: a,
1717
+ previewControlValues: xe,
1718
+ controlLifecycle: "edit",
1719
+ onChange: (y) => K(t.id, () => y)
1720
+ }
1721
+ ),
1722
+ t.initialValueStrategy === "saved_default" && /* @__PURE__ */ r(
1723
+ dt,
1724
+ {
1725
+ control: t,
1726
+ value: b,
1727
+ allowNoDefault: !0,
1728
+ allowCardDefault: !0,
1729
+ previewControlDefinitions: a,
1730
+ previewControlValues: xe,
1731
+ onChange: (y) => {
1732
+ const D = a.map(
1733
+ (L) => L.id === t.id ? { ...L, defaultValue: y } : L
1734
+ );
1735
+ if (t.source.kind === "manual" && (P.current[t.id] = y), s) {
1736
+ const L = { ...s };
1737
+ y === void 0 ? delete L[t.id] : L[t.id] = y, F(D, L);
1738
+ return;
1739
+ }
1740
+ F(D, void 0);
1741
+ }
1742
+ }
1743
+ ),
1744
+ /* @__PURE__ */ f(
1745
+ Yt,
1746
+ {
1747
+ open: R === t.id,
1748
+ onOpenChange: (y) => H(y ? t.id : null),
1749
+ children: [
1750
+ /* @__PURE__ */ r(Gt, { asChild: !0, children: /* @__PURE__ */ f(
1751
+ q,
1752
+ {
1753
+ type: "button",
1754
+ variant: "ghost",
1755
+ size: "xs",
1756
+ className: "-ml-2 gap-1 text-muted-foreground hover:text-foreground",
1757
+ children: [
1758
+ R === t.id ? /* @__PURE__ */ r(Re, { className: "h-3.5 w-3.5" }) : /* @__PURE__ */ r(Ge, { className: "h-3.5 w-3.5" }),
1759
+ "Advanced"
1760
+ ]
1761
+ }
1762
+ ) }),
1763
+ /* @__PURE__ */ f(Xt, { className: "space-y-3 pt-2", children: [
1764
+ /* @__PURE__ */ f("div", { className: "grid gap-3 md:grid-cols-2", children: [
1765
+ /* @__PURE__ */ f("div", { className: "flex flex-col gap-1.5", children: [
1766
+ /* @__PURE__ */ r(oe, { className: "text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground", children: "Variable name" }),
1767
+ /* @__PURE__ */ r(
1768
+ Jt,
1769
+ {
1770
+ controlId: t.id,
1771
+ onCommit: (y) => A(t.id, y)
1772
+ },
1773
+ t.id
1774
+ )
1775
+ ] }),
1776
+ /* @__PURE__ */ f("div", { className: "flex flex-col gap-1.5", children: [
1777
+ /* @__PURE__ */ r(oe, { className: "text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground", children: "Initial value" }),
1778
+ /* @__PURE__ */ f(
1779
+ we,
1780
+ {
1781
+ value: t.initialValueStrategy,
1782
+ onValueChange: (y) => K(t.id, (D) => ({
1783
+ ...D,
1784
+ initialValueStrategy: y
1785
+ })),
1786
+ children: [
1787
+ /* @__PURE__ */ r(De, { size: "xs", children: /* @__PURE__ */ r(Ee, {}) }),
1788
+ /* @__PURE__ */ r(Ie, { children: Dt.map((y) => /* @__PURE__ */ r(
1789
+ Te,
1790
+ {
1791
+ value: y.value,
1792
+ children: y.label
1793
+ },
1794
+ y.value
1795
+ )) })
1796
+ ]
1797
+ }
1798
+ )
1799
+ ] })
1800
+ ] }),
1801
+ /* @__PURE__ */ r(
1802
+ Zt,
1803
+ {
1804
+ control: t,
1805
+ onChange: (y) => K(t.id, () => y)
1806
+ }
1807
+ )
1808
+ ] })
1809
+ ]
1810
+ }
1811
+ )
1812
+ ] })
1813
+ ]
1814
+ },
1815
+ t.id
1816
+ );
1817
+ }),
1818
+ !o && /* @__PURE__ */ f(
1819
+ q,
1820
+ {
1821
+ type: "button",
1822
+ variant: "outline",
1823
+ size: "xs",
1824
+ onClick: ue,
1825
+ children: [
1826
+ /* @__PURE__ */ r(ia, { className: "h-3.5 w-3.5" }),
1827
+ "Add control"
1828
+ ]
1829
+ }
1830
+ )
1831
+ ] });
1832
+ }
1833
+ function Wa(e) {
1834
+ const {
1835
+ open: a,
1836
+ onOpenChange: n,
1837
+ initialCreateFlowActive: s = !1,
1838
+ dismissMode: l = "passive"
1839
+ } = e, d = a !== void 0, [p, h] = W(!1), [u, v] = W(
1840
+ s
1841
+ ), g = d ? a : p, m = z(
1842
+ (S) => {
1843
+ !S && u && l === "passive" || (d || h(S), S || v(!1), n == null || n(S));
1844
+ },
1845
+ [d, u, l, n]
1846
+ ), x = z(() => {
1847
+ d || h(!1), v(!1), n == null || n(!1);
1848
+ }, [d, n]);
1849
+ ie(() => {
1850
+ g || v(!1);
1851
+ }, [g]);
1852
+ const I = z(
1853
+ (S) => {
1854
+ u && S.preventDefault();
1855
+ },
1856
+ [u]
1857
+ );
1858
+ return {
1859
+ forceClose: x,
1860
+ handleOpenChange: m,
1861
+ isCreateFlowActive: u,
1862
+ preventPassiveDismissDuringCreate: I,
1863
+ resolvedOpen: g,
1864
+ setIsCreateFlowActive: v
1865
+ };
1866
+ }
1867
+ function Me(e) {
1868
+ var a;
1869
+ for (const n of e.cards)
1870
+ if (n.type === "matrixTable" && !aa.safeParse((a = n.config) == null ? void 0 : a.matrix).success)
1871
+ return j.error("Matrix requires at least one row field, one metric, and valid settings."), !1;
1872
+ return !0;
1873
+ }
1874
+ function Ya({
1875
+ className: e,
1876
+ variant: a = "outline"
1877
+ }) {
1878
+ const n = M((d) => d.onSave), { getUpdatedFrame: s } = qe();
1879
+ function l() {
1880
+ const d = s();
1881
+ Me(d) && (n == null || n(d));
1882
+ }
1883
+ return /* @__PURE__ */ f(
1884
+ q,
1885
+ {
1886
+ onClick: l,
1887
+ className: e,
1888
+ size: "xs",
1889
+ variant: a,
1890
+ children: [
1891
+ /* @__PURE__ */ r(_t, { className: "h-3.5 w-3.5" }),
1892
+ "Accept"
1893
+ ]
1894
+ }
1895
+ );
1896
+ }
1897
+ function Ga({
1898
+ className: e,
1899
+ variant: a = "default"
1900
+ }) {
1901
+ const n = ce(), [s, l] = W(!1), { setIsVisualEditing: d } = Le(), { getUpdatedFrame: p } = qe(), h = Ae(), u = M((m) => m.frame), v = ct();
1902
+ return /* @__PURE__ */ r(
1903
+ q,
1904
+ {
1905
+ onClick: () => {
1906
+ const m = p();
1907
+ if (!Me(m))
1908
+ return;
1909
+ const x = (u == null ? void 0 : u.visualId) || (h == null ? void 0 : h.id);
1910
+ if (!x) {
1911
+ j.error("No visual to save");
1912
+ return;
1913
+ }
1914
+ l(!0), v.mutate(
1915
+ {
1916
+ visualId: x,
1917
+ data: {
1918
+ frameObject: m
1919
+ }
1920
+ },
1921
+ {
1922
+ onSuccess: () => {
1923
+ l(!1), j.success("Visual updated successfully"), n.invalidateQueries({
1924
+ queryKey: ["resource-by-id", "visual", x],
1925
+ exact: !0
1926
+ });
1927
+ },
1928
+ onError: () => {
1929
+ l(!1), j.error("Failed to update visual");
1930
+ }
1931
+ }
1932
+ );
1933
+ },
1934
+ className: e,
1935
+ size: "xs",
1936
+ variant: a,
1937
+ children: s ? /* @__PURE__ */ f(ee, { children: [
1938
+ /* @__PURE__ */ r(ot, { className: "h-3.5 w-3.5 animate-spin" }),
1939
+ "Saving"
1940
+ ] }) : /* @__PURE__ */ f(ee, { children: [
1941
+ /* @__PURE__ */ r(pt, { className: "h-3.5 w-3.5" }),
1942
+ "Save to Library"
1943
+ ] })
1944
+ }
1945
+ );
1946
+ }
1947
+ function Xa({
1948
+ className: e
1949
+ }) {
1950
+ const a = ce(), [n, s] = W(!1), l = Ae(), d = M((S) => S.frame), p = Z((S) => S.selectedSheetId), h = Z((S) => S.dashboard), { updateFrame: u, setIsVisualEditing: v } = Le(), { getUpdatedFrame: g } = qe(), m = ct(), x = ta();
1951
+ return /* @__PURE__ */ r(
1952
+ q,
1953
+ {
1954
+ onClick: async () => {
1955
+ if (!p) {
1956
+ j.error("No sheet selected");
1957
+ return;
1958
+ }
1959
+ const S = (d == null ? void 0 : d.visualId) || (l == null ? void 0 : l.id);
1960
+ if (!S) {
1961
+ j.error("No visual to update");
1962
+ return;
1963
+ }
1964
+ s(!0);
1965
+ try {
1966
+ const N = g();
1967
+ if (!Me(N)) {
1968
+ s(!1);
1969
+ return;
1970
+ }
1971
+ const V = {
1972
+ ...N,
1973
+ visualId: S
1974
+ // Keep the link to library visual
1975
+ }, Q = Lt(h, V.id), G = await x(V, {
1976
+ previousFrame: Q
1977
+ });
1978
+ await m.mutateAsync({
1979
+ visualId: S,
1980
+ data: {
1981
+ frameObject: N
1982
+ }
1983
+ }), u(p, V, {
1984
+ semanticExecutionPayload: G
1985
+ }), a.invalidateQueries({ queryKey: ["visuals"] }), a.invalidateQueries({ queryKey: ["visual", S] }), j.success("Saved to library and applied locally"), setTimeout(() => {
1986
+ v(!1);
1987
+ }, 300);
1988
+ } catch (N) {
1989
+ console.error("Failed to save and apply:", N), j.error(
1990
+ N instanceof Error ? N.message : "Failed to save and apply changes"
1991
+ );
1992
+ } finally {
1993
+ s(!1);
1994
+ }
1995
+ },
1996
+ className: e,
1997
+ size: "xs",
1998
+ variant: "default",
1999
+ disabled: n,
2000
+ children: n ? /* @__PURE__ */ f(ee, { children: [
2001
+ /* @__PURE__ */ r(ot, { className: "h-3.5 w-3.5 animate-spin" }),
2002
+ "Saving..."
2003
+ ] }) : /* @__PURE__ */ f(ee, { children: [
2004
+ /* @__PURE__ */ r(pt, { className: "h-3.5 w-3.5" }),
2005
+ "Save & Apply"
2006
+ ] })
2007
+ }
2008
+ );
2009
+ }
2010
+ function Ja({ className: e }) {
2011
+ const { setTempQueryData: a, setSqlGen: n } = de(), s = ce(), l = M((m) => m.tempQueryData), d = M((m) => m.onClose), p = M((m) => m.card), h = ht(), u = $(() => h !== p.type ? { ...p, type: h } : p, [p, h]), { queryKey: v } = lt(u);
2012
+ function g() {
2013
+ if (l) {
2014
+ const { queryKey: m, queryData: x } = l;
2015
+ m && x && s.setQueryData(m, x);
2016
+ }
2017
+ n({}), d == null || d();
2018
+ }
2019
+ return /* @__PURE__ */ f(
2020
+ q,
2021
+ {
2022
+ onClick: g,
2023
+ className: e,
2024
+ size: "xs",
2025
+ variant: "outline",
2026
+ children: [
2027
+ /* @__PURE__ */ r(tt, { className: "h-3.5 w-3.5" }),
2028
+ "Close"
2029
+ ]
2030
+ }
2031
+ );
2032
+ }
2033
+ function Za({
2034
+ label: e = "Clear",
2035
+ variant: a = "secondary",
2036
+ className: n
2037
+ } = {}) {
2038
+ const s = wa();
2039
+ return /* @__PURE__ */ f(
2040
+ q,
2041
+ {
2042
+ onClick: s,
2043
+ className: n,
2044
+ size: "xs",
2045
+ variant: a,
2046
+ children: [
2047
+ /* @__PURE__ */ r(tt, { className: "h-3.5 w-3.5" }),
2048
+ e
2049
+ ]
2050
+ }
2051
+ );
2052
+ }
2053
+ export {
2054
+ Ka as C,
2055
+ Ya as E,
2056
+ Ba as F,
2057
+ pa as L,
2058
+ Pa as V,
2059
+ qe as a,
2060
+ Ja as b,
2061
+ Ga as c,
2062
+ Xa as d,
2063
+ fa as e,
2064
+ xa as f,
2065
+ Wa as g,
2066
+ Ha as h,
2067
+ wa as i,
2068
+ Za as j,
2069
+ $a as r,
2070
+ ht as u
2071
+ };