react-semaphor 0.1.375 → 0.1.377

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