react-semaphor 0.1.534 → 0.1.535

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