react-semaphor 0.1.374 → 0.1.376

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