react-semaphor 0.1.438 → 0.1.440

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