react-semaphor 0.1.525 → 0.1.527

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