react-semaphor 0.1.602 → 0.1.604

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 (211) hide show
  1. package/dist/activity/index.js +1 -73
  2. package/dist/analytics-protocol/index.js +1 -1451
  3. package/dist/appearance/index.js +1 -12
  4. package/dist/appearance-runtime/index.js +1 -5
  5. package/dist/assistant-context/index.js +1 -11
  6. package/dist/assistant-protocol/index.js +1 -152
  7. package/dist/brand-studio/index.js +4 -1594
  8. package/dist/briefings/index.js +1 -70
  9. package/dist/chunks/add-to-dashboard-DeHEBEqG.js +12 -0
  10. package/dist/chunks/analytics-base-schemas-BREc5WGv.js +1 -0
  11. package/dist/chunks/appearance-context-BqBZrijL.js +1 -0
  12. package/dist/chunks/appearance-runtime-provider-DmbCrOOG.js +1 -0
  13. package/dist/chunks/applied-constraints-CinevlKD.js +1 -0
  14. package/dist/chunks/assistant-chat-CjYrwVDa.js +56 -0
  15. package/dist/chunks/attribution-BEFSsbNn.js +1 -0
  16. package/dist/chunks/availability-3AIOf6Z-.js +1 -0
  17. package/dist/chunks/bookmark-impact-C89zBLq3.js +1 -0
  18. package/dist/chunks/bookmark-state-69YYnRql.js +1 -0
  19. package/dist/chunks/brand-DCaZyRt6.js +1 -0
  20. package/dist/chunks/card-filter-builder-CTp6RAz1.js +17 -0
  21. package/dist/chunks/column-bands-DwxbZ6UI.js +1 -0
  22. package/dist/chunks/comparison-window-caption-C312mn3s.js +1 -0
  23. package/dist/chunks/context-ALdccLHw.js +2 -0
  24. package/dist/chunks/conversation-JMK2kyTK.js +1 -0
  25. package/dist/chunks/dashboard-BX28ld6s.js +1 -0
  26. package/dist/chunks/dashboard-briefing-launcher-qo7GH4EO.js +37 -0
  27. package/dist/chunks/dashboard-controls-DhRjB7MA.js +42 -0
  28. package/dist/chunks/dashboard-json-9cHzhSjC.js +1 -0
  29. package/dist/chunks/dates-D-KP8G-z.js +1 -0
  30. package/dist/chunks/edit-DEAK0UZo.js +1 -0
  31. package/dist/chunks/edit-dashboard-visual-Duq_QkB_.js +93 -0
  32. package/dist/chunks/export-file-format-B-wQNHIn.js +4 -0
  33. package/dist/chunks/filter-line-CwQrqORc.js +1 -0
  34. package/dist/chunks/filter-reach-preview-gixPFlZj.js +1 -0
  35. package/dist/chunks/filter-value-text-B3tXakhd.js +1 -0
  36. package/dist/chunks/index-B-VF1ogs.js +1 -0
  37. package/dist/chunks/index-BE1DfxNs.js +1 -0
  38. package/dist/chunks/index-DViPGDFj.js +1 -0
  39. package/dist/chunks/layout-grid-BWtlgw0T.js +6 -0
  40. package/dist/chunks/matrix-analytical-definition-CtFqWyCK.js +1 -0
  41. package/dist/chunks/matrix-member-presentation-Q0MCJ-YK.js +1 -0
  42. package/dist/chunks/matrix-operation-contract-D1RC1bfi.js +1 -0
  43. package/dist/chunks/metric-comparison-DEZYXROZ.js +1 -0
  44. package/dist/chunks/normalize-dashboard-for-dirty-check-ILKfqgL3.js +1 -0
  45. package/dist/chunks/paintbrush-BjS3SbrH.js +6 -0
  46. package/dist/chunks/palette-BzC-CGOc.js +6 -0
  47. package/dist/chunks/pickers-DuBrUht0.js +1 -0
  48. package/dist/chunks/pivot-result-contract-expectations-DTQAgr4n.js +1 -0
  49. package/dist/chunks/pivot-result-identity-DTNCB--h.js +1 -0
  50. package/dist/chunks/raw-temporal-value-DeyEhL0S.js +1 -0
  51. package/dist/chunks/rendered-file-BbvwaU6z.js +1 -0
  52. package/dist/chunks/report-preferences-dialog-B_gUmCzG.js +1 -0
  53. package/dist/chunks/report-runtime-context-BWzIHCKK.js +1 -0
  54. package/dist/chunks/resolve-dashboard-input-context-B-TtRqxu.js +8 -0
  55. package/dist/chunks/resolver-AN9ChBfZ.js +1 -0
  56. package/dist/chunks/save-DdFUZcbi.js +6 -0
  57. package/dist/chunks/saved-dashboard-context-BAJ5tWiq.js +1 -0
  58. package/dist/chunks/schema-MC0cQSAb.js +4 -0
  59. package/dist/chunks/selection-filter-compiler-CCoCD25M.js +1 -0
  60. package/dist/chunks/semaphor-ready-indicator-DzjorP3t.js +999 -0
  61. package/dist/chunks/set-DuJfGkbY.js +1 -0
  62. package/dist/chunks/shelf-drop-preview-context-BlLJ5RsT.js +6 -0
  63. package/dist/chunks/stored-dashboard-Ctcpkllg.js +1 -0
  64. package/dist/chunks/style-sheet-parts-BRGt9O05.js +178 -0
  65. package/dist/chunks/table-export-sheet-rC5pKmXg.js +2 -0
  66. package/dist/chunks/token-types-Bj9iMy0w.js +1 -0
  67. package/dist/chunks/validators-CqV3Yka1.js +1 -0
  68. package/dist/chunks/variable-draft-DJrfUyhv.js +1 -0
  69. package/dist/chunks/visual-choice-DgEFfkE-.js +1 -0
  70. package/dist/dashboard/index.js +1 -7
  71. package/dist/dashboard-authoring/index.js +1 -4491
  72. package/dist/format-utils/index.js +1 -424
  73. package/dist/index.js +1 -554
  74. package/dist/layouts/index.js +1 -7
  75. package/dist/live-channel/index.js +1 -124
  76. package/dist/pdf-export-policy/index.js +1 -92
  77. package/dist/pdf-table-layout/index.js +1 -993
  78. package/dist/report-runtime-context/index.js +1 -9
  79. package/dist/shared/index.js +1 -6
  80. package/dist/style.css +1 -1
  81. package/dist/surfboard/index.js +1 -9
  82. package/dist/types/components/ui-custom/date-range-presets.d.ts +8 -0
  83. package/dist/types/index.js +1 -88
  84. package/dist/types/lib/document/document-edits.d.ts +0 -4
  85. package/dist/types/lib/filter-values/build-card-filter-definition.d.ts +32 -0
  86. package/dist/types/lib/query-context/dashboard-filter-mapping-resolution.d.ts +9 -0
  87. package/dist/types/lib/stores/dashboard-store.d.ts +0 -1
  88. package/dist/types/lib/stores/explorer-actions.d.ts +7 -6
  89. package/dist/types/lib/types/common-types.d.ts +0 -2
  90. package/dist/types/lib/types/explorer-types.d.ts +1 -1
  91. package/dist/types/lib/types/semantic-types.d.ts +6 -10
  92. package/dist/types/lib/utils/field-state-calculator.d.ts +7 -19
  93. package/dist/types/shared/analytics-protocol/analytics-base-schemas.d.ts +18 -0
  94. package/dist/types/shared/analytics-protocol/analyze-result-types.d.ts +3 -0
  95. package/dist/types/shared/analytics-protocol/comparison-choices.d.ts +92 -0
  96. package/dist/types/shared/analytics-protocol/comparison-placement.d.ts +30 -0
  97. package/dist/types/shared/analytics-protocol/contracts.d.ts +11 -5
  98. package/dist/types/shared/analytics-protocol/date-window.d.ts +105 -0
  99. package/dist/types/shared/analytics-protocol/filter-field-ownership.d.ts +27 -0
  100. package/dist/types/shared/analytics-protocol/fixtures.d.ts +4 -2
  101. package/dist/types/shared/analytics-protocol/index.d.ts +3 -0
  102. package/dist/types/shared/analytics-protocol/metric-comparison.d.ts +93 -11
  103. package/dist/types/shared/assistant-protocol/context.d.ts +16 -16
  104. package/dist/types/shared/dashboard-authoring/calculations/calculated-column.d.ts +1 -1
  105. package/dist/types/shared/dashboard-authoring/calculations/definition.d.ts +13 -0
  106. package/dist/types/shared/dashboard-authoring/card-data-source/card-base.d.ts +125 -0
  107. package/dist/types/shared/dashboard-authoring/card-data-source/card-field-folders.d.ts +55 -0
  108. package/dist/types/shared/dashboard-authoring/card-data-source/card-joins.d.ts +114 -0
  109. package/dist/types/shared/dashboard-authoring/card-data-source/card-prune.d.ts +12 -0
  110. package/dist/types/shared/dashboard-authoring/card-data-source/filter-field-catalog.d.ts +60 -0
  111. package/dist/types/shared/dashboard-authoring/card-data-source/filter-field-folders.d.ts +132 -0
  112. package/dist/types/shared/dashboard-authoring/card-data-source/index.d.ts +7 -0
  113. package/dist/types/shared/dashboard-authoring/card-data-source/join-reach.d.ts +42 -0
  114. package/dist/types/shared/dashboard-authoring/card-field-places.d.ts +28 -0
  115. package/dist/types/shared/dashboard-authoring/card-settings/card-display-write.d.ts +8 -0
  116. package/dist/types/shared/dashboard-authoring/card-settings/card-kinds.d.ts +1 -1
  117. package/dist/types/shared/dashboard-authoring/card-settings/inputs.d.ts +2 -1
  118. package/dist/types/shared/dashboard-authoring/card-settings/resolved.d.ts +0 -3
  119. package/dist/types/shared/dashboard-authoring/changes/dashboard-change.d.ts +21 -358
  120. package/dist/types/shared/dashboard-authoring/changes/diagnostics.d.ts +2 -0
  121. package/dist/types/shared/dashboard-authoring/conditional-formatting/schema.d.ts +10 -10
  122. package/dist/types/shared/dashboard-authoring/dashboard-variable-card.d.ts +2 -4
  123. package/dist/types/shared/dashboard-authoring/field-folders/field-folders.d.ts +115 -0
  124. package/dist/types/shared/dashboard-authoring/field-folders/index.d.ts +1 -0
  125. package/dist/types/shared/dashboard-authoring/filter-reach-decision.d.ts +11 -0
  126. package/dist/types/shared/dashboard-authoring/index.d.ts +6 -1
  127. package/dist/types/shared/dashboard-authoring/kpi-date-context.d.ts +2 -0
  128. package/dist/types/shared/dashboard-authoring/kpi-figure.d.ts +18 -0
  129. package/dist/types/shared/dashboard-authoring/measure-calculations/comparison.d.ts +8 -7
  130. package/dist/types/shared/dashboard-authoring/measure-calculations/dates.d.ts +11 -1
  131. package/dist/types/shared/dashboard-authoring/measure-calculations/index.d.ts +2 -2
  132. package/dist/types/shared/dashboard-authoring/measure-calculations/options.d.ts +4 -0
  133. package/dist/types/shared/dashboard-authoring/measure-calculations/read.d.ts +18 -1
  134. package/dist/types/shared/dashboard-authoring/measure-calculations/resolve.d.ts +2 -0
  135. package/dist/types/shared/dashboard-authoring/measure-calculations/schemas.d.ts +46 -88
  136. package/dist/types/shared/dashboard-authoring/operations/calculated-field-operations.d.ts +33 -8
  137. package/dist/types/shared/dashboard-authoring/operations/operation-types.d.ts +0 -2
  138. package/dist/types/shared/dashboard-authoring/outline/outline-filters.d.ts +5 -0
  139. package/dist/types/shared/dashboard-authoring/see-records/result.d.ts +7 -22
  140. package/dist/types/shared/format-utils/comparison-detail.d.ts +34 -0
  141. package/dist/types/shared/format-utils/index.d.ts +1 -0
  142. package/dist/types/shared/format-utils/partial-period.d.ts +4 -2
  143. package/dist/types/shared/temporal/calendar-periods.d.ts +11 -0
  144. package/dist/types/shared/temporal/index.d.ts +2 -0
  145. package/dist/types/shared/temporal/temporal-text.d.ts +33 -0
  146. package/dist/types/shared/temporal/temporal.d.ts +27 -0
  147. package/dist/types/shared/temporal/zoned-wall-clock.d.ts +4 -3
  148. package/dist/usage-events/index.js +1 -285
  149. package/dist/value-format-preferences/index.js +1 -635
  150. package/package.json +6 -2
  151. package/dist/chunks/add-to-dashboard-ClhEIFst.js +0 -291
  152. package/dist/chunks/analytics-base-schemas-DevrgqQb.js +0 -678
  153. package/dist/chunks/appearance-context-BwBp25ZG.js +0 -162
  154. package/dist/chunks/appearance-runtime-provider-BRHYELkC.js +0 -80
  155. package/dist/chunks/applied-constraints-DU-wndZ7.js +0 -47
  156. package/dist/chunks/assistant-chat-BWF3GYip.js +0 -6115
  157. package/dist/chunks/attribution-BvoKvhcj.js +0 -32
  158. package/dist/chunks/availability-Bp5Gfu1I.js +0 -44
  159. package/dist/chunks/bookmark-impact-BF3iRx5a.js +0 -76
  160. package/dist/chunks/bookmark-state-CBSTdW6q.js +0 -1666
  161. package/dist/chunks/brand-BoUV0iHF.js +0 -54
  162. package/dist/chunks/card-filter-builder-B8XHwMY6.js +0 -4069
  163. package/dist/chunks/column-bands-RdM-kjDe.js +0 -47
  164. package/dist/chunks/comparison-window-caption-W83qB4V5.js +0 -741
  165. package/dist/chunks/context-BJoEFgNl.js +0 -369
  166. package/dist/chunks/conversation-sQiWYUOb.js +0 -16
  167. package/dist/chunks/dashboard-DG5EIYYB.js +0 -14
  168. package/dist/chunks/dashboard-briefing-launcher-CBSrhyWZ.js +0 -4875
  169. package/dist/chunks/dashboard-controls-D6ECO4N1.js +0 -2290
  170. package/dist/chunks/dashboard-json-DrJftBSL.js +0 -66
  171. package/dist/chunks/dates-Bz-qM5px.js +0 -164
  172. package/dist/chunks/edit-9df1zOWe.js +0 -226
  173. package/dist/chunks/edit-dashboard-visual-BDYAJIbb.js +0 -18605
  174. package/dist/chunks/export-file-format-C-tJsxsf.js +0 -111
  175. package/dist/chunks/filter-line-BXT6y303.js +0 -703
  176. package/dist/chunks/filter-reach-copy-BukhZmzm.js +0 -5250
  177. package/dist/chunks/filter-value-text-D3-bf3_b.js +0 -153
  178. package/dist/chunks/index-BVKzKl5d.js +0 -90
  179. package/dist/chunks/index-BW0yozjs.js +0 -2795
  180. package/dist/chunks/index-CV_Kzou0.js +0 -595
  181. package/dist/chunks/layout-grid-Ds0diMeY.js +0 -16
  182. package/dist/chunks/matrix-analytical-definition-CgQgVeeI.js +0 -1162
  183. package/dist/chunks/matrix-member-presentation-DSBIIudt.js +0 -258
  184. package/dist/chunks/matrix-operation-contract--DkNCOzd.js +0 -1412
  185. package/dist/chunks/metric-comparison-zMylnIkc.js +0 -541
  186. package/dist/chunks/normalize-dashboard-for-dirty-check-XKgH3GFX.js +0 -119
  187. package/dist/chunks/paintbrush-CX8pao1j.js +0 -27
  188. package/dist/chunks/palette-CuA0HlzF.js +0 -23
  189. package/dist/chunks/pickers-DkqmtnTL.js +0 -2403
  190. package/dist/chunks/pivot-result-contract-expectations-C8KL7hPx.js +0 -5046
  191. package/dist/chunks/pivot-result-identity-C1AOH1PS.js +0 -77
  192. package/dist/chunks/raw-temporal-value-E416F-0L.js +0 -454
  193. package/dist/chunks/rendered-file-D8xEuVVx.js +0 -108
  194. package/dist/chunks/report-preferences-dialog-CbuVNDGi.js +0 -1637
  195. package/dist/chunks/report-runtime-context-E7USjN7E.js +0 -388
  196. package/dist/chunks/resolve-dashboard-input-context-CULCE_hM.js +0 -25172
  197. package/dist/chunks/resolver-DG_tfEpt.js +0 -156
  198. package/dist/chunks/save-BKHlDONy.js +0 -21
  199. package/dist/chunks/saved-dashboard-context-C1WlOx5z.js +0 -632
  200. package/dist/chunks/schema-C9NPiIru.js +0 -2568
  201. package/dist/chunks/selection-filter-compiler-ifT8JCXS.js +0 -131
  202. package/dist/chunks/semaphor-ready-indicator-CBIRcDWs.js +0 -145326
  203. package/dist/chunks/shelf-drop-preview-context-xR69SMA8.js +0 -2466
  204. package/dist/chunks/stored-dashboard-BuM8vnWf.js +0 -4070
  205. package/dist/chunks/style-sheet-parts-Bt9ZNre8.js +0 -8674
  206. package/dist/chunks/table-export-sheet-DVljtHkG.js +0 -949
  207. package/dist/chunks/token-types-D_xKgyVS.js +0 -8
  208. package/dist/chunks/upload-Dll_M7XQ.js +0 -15
  209. package/dist/chunks/validators-ClWHpYql.js +0 -3686
  210. package/dist/chunks/variable-draft-CDGGl53R.js +0 -242
  211. package/dist/chunks/visual-choice-DDfHfHvY.js +0 -172
@@ -1,4069 +0,0 @@
1
- import { c as nt, B as G, X as ce, x as Ne, q as fn, a3 as xn, t as at, u as rt, v as st, w as ot, a4 as Ft, F as _e, s as ie, y as xe, z as ge, A as be, D as ve, E as re, e as lt, f as it, h as dt, L as gn, d as bn } from "./style-sheet-parts-Bt9ZNre8.js";
2
- import { jsx as t, jsxs as i, Fragment as he } from "react/jsx-runtime";
3
- import * as Fe from "react";
4
- import bt, { useMemo as P, useState as Y, useRef as $e, useCallback as ne, useEffect as de, forwardRef as vn, Fragment as yn } from "react";
5
- import { b8 as ct, u as ut, am as se, bL as Vt, bM as J, bN as Nn, bO as Te, bP as Ue, bQ as Rt, bR as Cn, bS as Ve, bT as wn, an as Et, bG as kn, bH as Sn, bJ as Dn, bU as Tn, bV as In, o as Ln, bW as $n, bX as An, bY as vt, bZ as zt, b_ as On, b$ as Mt, c0 as qt, c1 as _n, c2 as Fn, c3 as Vn, c4 as Rn, c5 as En, c6 as zn, c7 as Mn, bz as qn, c8 as yt, c9 as jt, ca as Nt, bC as jn, cb as Un, cc as Gn, cd as Bn, ce as ye, cf as Ut, cg as Wn, ch as Qn, ci as Kn, cj as Pn, ck as Hn, cl as Je, cm as fe, cn as Ze, co as et, cp as tt, cq as Yn, cr as Re, cs as Ee, ct as ze, cu as Me, cv as Gt, cw as Bt, cx as Wt } from "./semaphor-ready-indicator-CBIRcDWs.js";
6
- import { D as Xn } from "./token-types-D_xKgyVS.js";
7
- import { hn as Qt, cL as Kt, cK as Pt, ho as Jn, hp as Zn, hq as Ae, hr as Ct, hs as wt, ht as Qe, hu as Ke, hv as ea, hw as ta, hx as kt, hy as na, hz as aa, hA as Oe, hB as ra, hC as St, hD as Ht, hE as Yt, hF as Xt, hG as Jt, hH as sa, hI as oa, hJ as Dt, hK as la, hL as Tt, hM as ia, hN as da, hO as ca, hP as ua, hQ as Pe, e as qe, hR as ma, hS as It, hT as pa, hU as He, aQ as ha, hV as fa, hW as xa, hX as ga, hY as ba } from "./resolve-dashboard-input-context-CULCE_hM.js";
8
- import { c as q } from "./pickers-DkqmtnTL.js";
9
- import { k as Zt, r as va, aE as en, aF as tn } from "./validators-ClWHpYql.js";
10
- import "./matrix-operation-contract--DkNCOzd.js";
11
- import "./analytics-base-schemas-DevrgqQb.js";
12
- import "../value-format-preferences/index.js";
13
- import { U as ya } from "./upload-Dll_M7XQ.js";
14
- import { a as nn } from "./metric-comparison-zMylnIkc.js";
15
- import { r as Na, j as Ca } from "./raw-temporal-value-E416F-0L.js";
16
- /**
17
- * @license lucide-react v0.453.0 - ISC
18
- *
19
- * This source code is licensed under the ISC license.
20
- * See the LICENSE file in the root directory of this source tree.
21
- */
22
- const wa = nt("Boxes", [
23
- [
24
- "path",
25
- {
26
- d: "M2.97 12.92A2 2 0 0 0 2 14.63v3.24a2 2 0 0 0 .97 1.71l3 1.8a2 2 0 0 0 2.06 0L12 19v-5.5l-5-3-4.03 2.42Z",
27
- key: "lc1i9w"
28
- }
29
- ],
30
- ["path", { d: "m7 16.5-4.74-2.85", key: "1o9zyk" }],
31
- ["path", { d: "m7 16.5 5-3", key: "va8pkn" }],
32
- ["path", { d: "M7 16.5v5.17", key: "jnp8gn" }],
33
- [
34
- "path",
35
- {
36
- d: "M12 13.5V19l3.97 2.38a2 2 0 0 0 2.06 0l3-1.8a2 2 0 0 0 .97-1.71v-3.24a2 2 0 0 0-.97-1.71L17 10.5l-5 3Z",
37
- key: "8zsnat"
38
- }
39
- ],
40
- ["path", { d: "m17 16.5-5-3", key: "8arw3v" }],
41
- ["path", { d: "m17 16.5 4.74-2.85", key: "8rfmw" }],
42
- ["path", { d: "M17 16.5v5.17", key: "k6z78m" }],
43
- [
44
- "path",
45
- {
46
- d: "M7.97 4.42A2 2 0 0 0 7 6.13v4.37l5 3 5-3V6.13a2 2 0 0 0-.97-1.71l-3-1.8a2 2 0 0 0-2.06 0l-3 1.8Z",
47
- key: "1xygjf"
48
- }
49
- ],
50
- ["path", { d: "M12 8 7.26 5.15", key: "1vbdud" }],
51
- ["path", { d: "m12 8 4.74-2.85", key: "3rx089" }],
52
- ["path", { d: "M12 13.5V8", key: "1io7kd" }]
53
- ]);
54
- /**
55
- * @license lucide-react v0.453.0 - ISC
56
- *
57
- * This source code is licensed under the ISC license.
58
- * See the LICENSE file in the root directory of this source tree.
59
- */
60
- const kr = nt("FilterX", [
61
- ["path", { d: "M13.013 3H2l8 9.46V19l4 2v-8.54l.9-1.055", key: "1fi1da" }],
62
- ["path", { d: "m22 3-5 5", key: "12jva0" }],
63
- ["path", { d: "m17 3 5 5", key: "k36vhe" }]
64
- ]);
65
- /**
66
- * @license lucide-react v0.453.0 - ISC
67
- *
68
- * This source code is licensed under the ISC license.
69
- * See the LICENSE file in the root directory of this source tree.
70
- */
71
- const ka = nt("Library", [
72
- ["path", { d: "m16 6 4 14", key: "ji33uf" }],
73
- ["path", { d: "M12 6v14", key: "1n7gus" }],
74
- ["path", { d: "M8 8v12", key: "1gg7y9" }],
75
- ["path", { d: "M4 4v16", key: "6qkkli" }]
76
- ]);
77
- function Sa(e, n, a) {
78
- switch (e) {
79
- case "none":
80
- return !1;
81
- case "include":
82
- return a.includes(n);
83
- case "exclude":
84
- return !a.includes(n);
85
- case "all":
86
- default:
87
- return !0;
88
- }
89
- }
90
- function Da({
91
- mode: e,
92
- currentDomainId: n,
93
- scopedDomainIds: a,
94
- hasSelectedEntities: o
95
- }) {
96
- return e === "all" ? !1 : e === "none" ? !!n || o : n ? !Sa(e, n, a) : o;
97
- }
98
- function an(e) {
99
- const { tokenProps: n } = ct(), a = ut((s) => s.authToken) || e;
100
- se(
101
- (s) => s.selectedConnectionId
102
- ), se(
103
- (s) => {
104
- var c, x;
105
- return (x = (c = s == null ? void 0 : s.card) == null ? void 0 : c.dataSource) == null ? void 0 : x.connectionId;
106
- }
107
- );
108
- const {
109
- refetch: o,
110
- isPending: m,
111
- data: d,
112
- isLoading: u,
113
- isError: l
114
- } = Vt({
115
- queryKey: ["semantic-domains"],
116
- queryFn: () => Qt(
117
- `${n.apiServiceUrl}/v1/domains`,
118
- (a == null ? void 0 : a.accessToken) || ""
119
- ),
120
- enabled: !!(a != null && a.accessToken)
121
- // Only fetch if authToken is present
122
- });
123
- return {
124
- isPending: m,
125
- error: l,
126
- semanticDomainsData: d,
127
- semanticDomains: (d == null ? void 0 : d.domains) || [],
128
- isSemanticDomainsLoading: u,
129
- isSemanticDomainsError: l,
130
- refetchSemanticDomains: o
131
- };
132
- }
133
- function Ta(e, n) {
134
- if (e.some(
135
- (d) => J(d, n)
136
- ))
137
- return e.filter(
138
- (d) => !J(d, n)
139
- );
140
- const o = Pt(e);
141
- return e.some(
142
- (d) => !("domainId" in d)
143
- ) || [...o].some((d) => d !== n.domainId) ? [n] : [...e, n];
144
- }
145
- function Ia(e, n) {
146
- const a = Kt(n), o = Pt(e), m = e.some(
147
- (u) => !("domainId" in u)
148
- );
149
- if (a && (m || [...o].some(
150
- (u) => u !== a
151
- )))
152
- return n;
153
- const d = [...e];
154
- for (const u of n)
155
- d.some((l) => J(l, u)) || d.push(u);
156
- return d;
157
- }
158
- function La({
159
- domainAccess: e,
160
- search: n,
161
- scopeDomainId: a,
162
- selectedEntities: o,
163
- onSelectionChange: m
164
- }) {
165
- const { semanticDomains: d, isSemanticDomainsLoading: u } = an(), l = P(() => Aa(d, e), [d, e]), s = P(() => a ? l.filter((x) => x.id === a) : l, [l, a]);
166
- if (u && s.length === 0)
167
- return /* @__PURE__ */ t("div", { className: "px-3 py-4 text-[11px] text-muted-foreground", children: "Loading semantic domains…" });
168
- if (s.length === 0)
169
- return null;
170
- const c = !!a;
171
- return /* @__PURE__ */ i("div", { children: [
172
- /* @__PURE__ */ t(rn, { label: "Semantic Domains" }),
173
- s.map((x) => /* @__PURE__ */ t(
174
- $a,
175
- {
176
- domain: x,
177
- search: n,
178
- forceExpanded: c,
179
- selectedEntities: o,
180
- onSelectionChange: m
181
- },
182
- x.id
183
- ))
184
- ] });
185
- }
186
- function $a({
187
- domain: e,
188
- search: n,
189
- forceExpanded: a,
190
- selectedEntities: o,
191
- onSelectionChange: m
192
- }) {
193
- const [d, u] = Y(!1), l = d || n.length > 0 || !!a, { datasets: s, isPending: c } = Nn(
194
- l ? e.id : void 0
195
- ), x = P(() => {
196
- if (!n) return s;
197
- const C = n.trim().toLowerCase();
198
- return s.filter(
199
- (T) => `${T.label ?? ""} ${T.name ?? ""} ${T.description ?? ""}`.toLowerCase().includes(C)
200
- );
201
- }, [s, n]), k = n.length > 0 && x.length > 0, y = d || k || !!a, f = s.length, N = P(() => x.filter(
202
- (C) => o.some(
203
- (T) => J(T, Le(C))
204
- )
205
- ).length, [x, o]), S = P(
206
- () => x.map(Le),
207
- [x]
208
- ), V = S.length > 0 && S.every(
209
- (C) => o.some((T) => J(T, C))
210
- ), F = () => {
211
- if (S.length !== 0) {
212
- if (V) {
213
- m(
214
- o.filter(
215
- (C) => !S.some(
216
- (T) => J(C, T)
217
- )
218
- )
219
- );
220
- return;
221
- }
222
- m(
223
- Ia(
224
- o,
225
- S
226
- )
227
- );
228
- }
229
- }, K = (C) => {
230
- const T = Le(C);
231
- m(
232
- Ta(
233
- o,
234
- T
235
- )
236
- );
237
- };
238
- return n.length > 0 && !k && !c ? null : /* @__PURE__ */ i("div", { children: [
239
- /* @__PURE__ */ i("div", { className: "flex items-center rounded-[4px] px-3 py-1.5 transition-colors hover:bg-muted/50", children: [
240
- /* @__PURE__ */ i(
241
- "button",
242
- {
243
- type: "button",
244
- onClick: () => u((C) => !C),
245
- className: "flex min-w-0 flex-1 items-center gap-1.5 text-left",
246
- children: [
247
- /* @__PURE__ */ t(
248
- Te,
249
- {
250
- className: q(
251
- "h-3 w-3 shrink-0 text-muted-foreground transition-transform",
252
- y && "rotate-90"
253
- ),
254
- strokeWidth: 1.75
255
- }
256
- ),
257
- /* @__PURE__ */ t("span", { className: "truncate text-[13px] font-medium text-foreground", children: e.label || e.name }),
258
- f > 0 && /* @__PURE__ */ i("span", { className: "shrink-0 text-[11px] text-muted-foreground", children: [
259
- "· ",
260
- f,
261
- " dataset",
262
- f === 1 ? "" : "s",
263
- " · curated"
264
- ] })
265
- ]
266
- }
267
- ),
268
- y && !c && S.length > 0 && /* @__PURE__ */ t(
269
- "button",
270
- {
271
- type: "button",
272
- onClick: F,
273
- className: "ml-2 shrink-0 rounded-[3px] px-1.5 py-0.5 text-[10.5px] font-medium text-muted-foreground hover:bg-background hover:text-foreground",
274
- children: V ? "Clear" : "Select all"
275
- }
276
- ),
277
- /* @__PURE__ */ t("span", { className: "ml-auto font-mono text-[10px] tabular-nums text-muted-foreground", children: N > 0 ? N : "" })
278
- ] }),
279
- y && /* @__PURE__ */ t("ul", { className: "space-y-px pb-1", children: c && s.length === 0 ? /* @__PURE__ */ t("li", { className: "px-9 py-1.5 text-[11px] text-muted-foreground", children: "Loading datasets…" }) : x.length === 0 ? /* @__PURE__ */ t("li", { className: "px-9 py-1.5 text-[11px] text-muted-foreground", children: "No datasets in this domain." }) : x.map((C) => {
280
- const T = Le(C), U = o.some(
281
- (Z) => J(Z, T)
282
- );
283
- return /* @__PURE__ */ t("li", { children: /* @__PURE__ */ i("label", { className: "flex cursor-pointer items-start gap-2 rounded-[4px] px-9 py-1.5 transition-colors hover:bg-muted/40", children: [
284
- /* @__PURE__ */ t(
285
- Ue,
286
- {
287
- checked: U,
288
- onCheckedChange: () => K(C),
289
- className: "mt-[3px] h-3.5 w-3.5 shrink-0"
290
- }
291
- ),
292
- /* @__PURE__ */ i("div", { className: "min-w-0 flex-1", children: [
293
- /* @__PURE__ */ i("div", { className: "flex items-baseline gap-1.5", children: [
294
- /* @__PURE__ */ t("span", { className: "truncate text-[13px] text-foreground", children: C.label || C.name }),
295
- /* @__PURE__ */ t("span", { className: "shrink-0 font-mono text-[10px] uppercase tracking-[0.06em] text-muted-foreground/70", children: C.type === "virtual" ? "virtual" : "dataset" })
296
- ] }),
297
- C.description && /* @__PURE__ */ t("p", { className: "mt-0.5 text-[11px] leading-[1.4] text-muted-foreground", children: C.description })
298
- ] })
299
- ] }) }, C.id);
300
- }) })
301
- ] });
302
- }
303
- function rn({ label: e }) {
304
- return /* @__PURE__ */ t("div", { className: "px-3 pb-1.5 pt-2.5", children: /* @__PURE__ */ t("p", { className: "text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground", children: e }) });
305
- }
306
- function Aa(e, n) {
307
- if (!n || n.mode === "all") return e;
308
- const a = new Set(n.domainIds ?? []);
309
- return n.mode === "include" ? e.filter((o) => a.has(o.id)) : n.mode === "exclude" ? e.filter((o) => !a.has(o.id)) : [];
310
- }
311
- function Le(e) {
312
- return {
313
- id: e.id,
314
- datasetType: e.type,
315
- name: e.name || e.table,
316
- label: e.label,
317
- domainId: e.domainId,
318
- description: e.description,
319
- database: e.database,
320
- schema: e.schema,
321
- table: e.table,
322
- type: "dataset",
323
- connectionId: e.connectionId,
324
- connectionType: e.connectionType,
325
- dialect: e.dialect,
326
- datamodelId: e.datamodelId,
327
- sql: e.sql
328
- };
329
- }
330
- function Oa({
331
- search: e,
332
- scopeConnectionId: n,
333
- selectedEntities: a,
334
- onSelectionChange: o
335
- }) {
336
- const { connections: m, isConnectionsLoading: d } = Rt(), u = P(() => n ? m.filter((s) => s.id === n) : m, [m, n]);
337
- if (d && u.length === 0)
338
- return /* @__PURE__ */ t("div", { className: "px-3 py-4 text-[11px] text-muted-foreground", children: "Loading connections…" });
339
- if (u.length === 0)
340
- return null;
341
- const l = !!n;
342
- return /* @__PURE__ */ i("div", { children: [
343
- /* @__PURE__ */ t(rn, { label: "Direct Sources" }),
344
- u.map((s) => /* @__PURE__ */ t(
345
- _a,
346
- {
347
- connection: s,
348
- search: e,
349
- forceExpanded: l,
350
- selectedEntities: a,
351
- onSelectionChange: o
352
- },
353
- s.id
354
- ))
355
- ] });
356
- }
357
- function _a({
358
- connection: e,
359
- search: n,
360
- forceExpanded: a,
361
- selectedEntities: o,
362
- onSelectionChange: m
363
- }) {
364
- var N;
365
- const [d, u] = Y(!1), l = d || n.length > 0 || !!a, s = ((N = e.capabilities) == null ? void 0 : N.path) ?? [], c = s.includes("database"), x = s.includes("schema"), k = e.type === "upload", y = e.type === "url", f = P(
366
- () => o.filter((S) => S.connectionId === e.id).length,
367
- [o, e.id]
368
- );
369
- return /* @__PURE__ */ i("div", { className: "border-b border-border/60 last:border-b-0", children: [
370
- /* @__PURE__ */ i(
371
- "button",
372
- {
373
- type: "button",
374
- onClick: () => u((S) => !S),
375
- className: "flex w-full items-center gap-2 px-4 py-1.5 text-left transition-colors hover:bg-muted/40",
376
- children: [
377
- /* @__PURE__ */ t(
378
- Te,
379
- {
380
- className: q(
381
- "h-3 w-3 shrink-0 text-muted-foreground transition-transform",
382
- l && "rotate-90"
383
- ),
384
- strokeWidth: 1.75
385
- }
386
- ),
387
- /* @__PURE__ */ t("span", { className: "truncate text-[13px] font-medium text-foreground/90", children: e.name }),
388
- /* @__PURE__ */ i("span", { className: "truncate text-[11px] text-muted-foreground", children: [
389
- "· ",
390
- e.type
391
- ] }),
392
- /* @__PURE__ */ t("span", { className: "ml-auto shrink-0 font-mono text-[10px] tabular-nums text-muted-foreground", children: f > 0 ? f : "" })
393
- ]
394
- }
395
- ),
396
- l && /* @__PURE__ */ i(he, { children: [
397
- k ? /* @__PURE__ */ t(
398
- Fa,
399
- {
400
- connection: e,
401
- selectedEntities: o,
402
- onSelectionChange: m
403
- }
404
- ) : y ? /* @__PURE__ */ t(
405
- Va,
406
- {
407
- connection: e,
408
- selectedEntities: o,
409
- onSelectionChange: m
410
- }
411
- ) : c ? /* @__PURE__ */ t(
412
- Ra,
413
- {
414
- connection: e,
415
- requiresSchema: x,
416
- search: n,
417
- selectedEntities: o,
418
- onSelectionChange: m
419
- }
420
- ) : x ? /* @__PURE__ */ t(
421
- sn,
422
- {
423
- connection: e,
424
- databaseName: "",
425
- search: n,
426
- selectedEntities: o,
427
- onSelectionChange: m
428
- }
429
- ) : /* @__PURE__ */ t(
430
- mt,
431
- {
432
- connection: e,
433
- databaseName: "",
434
- schemaName: "",
435
- search: n,
436
- selectedEntities: o,
437
- onSelectionChange: m
438
- }
439
- ),
440
- !k && !y && /* @__PURE__ */ t(
441
- Ea,
442
- {
443
- connection: e,
444
- search: n,
445
- selectedEntities: o,
446
- onSelectionChange: m
447
- }
448
- )
449
- ] })
450
- ] });
451
- }
452
- function Fa({
453
- connection: e,
454
- selectedEntities: n,
455
- onSelectionChange: a
456
- }) {
457
- const o = `upload-source-${e.id}`, m = n.filter(
458
- (l) => l.connectionId === e.id && (l.type === "upload" || l.type === "file")
459
- ), d = (l) => {
460
- if (!(l != null && l.length)) return;
461
- const s = Array.from(l).map((c) => ({
462
- id: `file-${Date.now()}-${Math.random()}`,
463
- name: c.name,
464
- type: "upload",
465
- connectionId: e.id,
466
- connectionType: e.type,
467
- label: c.name,
468
- description: `Uploaded ${(/* @__PURE__ */ new Date()).toLocaleString()}`,
469
- originalName: c.name,
470
- file: c
471
- }));
472
- a([...n, ...s]);
473
- }, u = (l) => {
474
- a(
475
- n.filter(
476
- (s) => !("id" in s && s.id === l && s.connectionId === e.id && (s.type === "upload" || s.type === "file"))
477
- )
478
- );
479
- };
480
- return /* @__PURE__ */ i("div", { className: "space-y-2 px-8 py-2", children: [
481
- /* @__PURE__ */ i("div", { className: "rounded-[6px] border border-dashed border-border bg-muted/20 p-4 text-center", children: [
482
- /* @__PURE__ */ t(ya, { className: "mx-auto mb-2 h-5 w-5 text-muted-foreground" }),
483
- /* @__PURE__ */ t("p", { className: "text-[12px] text-muted-foreground", children: "Add CSV, JSON, or Excel files." }),
484
- /* @__PURE__ */ t(
485
- "input",
486
- {
487
- id: o,
488
- type: "file",
489
- multiple: !0,
490
- className: "hidden",
491
- onChange: (l) => d(l.target.files),
492
- accept: ".csv,.json,.xlsx,.xls"
493
- }
494
- ),
495
- /* @__PURE__ */ t(
496
- G,
497
- {
498
- type: "button",
499
- variant: "outline",
500
- size: "sm",
501
- className: "mt-2 h-7 text-[12px]",
502
- onClick: () => {
503
- var l;
504
- return (l = document.getElementById(o)) == null ? void 0 : l.click();
505
- },
506
- children: "Select files"
507
- }
508
- )
509
- ] }),
510
- m.length > 0 && /* @__PURE__ */ t("ul", { className: "space-y-1", children: m.map((l) => /* @__PURE__ */ i(
511
- "li",
512
- {
513
- className: "flex items-center gap-2 rounded-[5px] border border-border bg-background px-2 py-1.5",
514
- children: [
515
- /* @__PURE__ */ t(Cn, { className: "h-3.5 w-3.5 shrink-0 text-muted-foreground" }),
516
- /* @__PURE__ */ t("span", { className: "min-w-0 flex-1 truncate text-[12px]", children: l.originalName || l.name }),
517
- /* @__PURE__ */ t(
518
- "button",
519
- {
520
- type: "button",
521
- "aria-label": `Remove ${l.originalName || l.name}`,
522
- onClick: () => u(l.id),
523
- className: "inline-flex h-5 w-5 shrink-0 items-center justify-center rounded-[3px] text-muted-foreground hover:bg-muted hover:text-foreground",
524
- children: /* @__PURE__ */ t(ce, { className: "h-3 w-3" })
525
- }
526
- )
527
- ]
528
- },
529
- l.id
530
- )) })
531
- ] });
532
- }
533
- function Va({
534
- connection: e,
535
- selectedEntities: n,
536
- onSelectionChange: a
537
- }) {
538
- const [o, m] = Y(""), [d, u] = Y(""), [l, s] = Y("api"), c = n.filter(
539
- (y) => y.connectionId === e.id && y.type === "url"
540
- ), x = () => {
541
- const y = o.trim(), f = d.trim();
542
- if (!y || !f) return;
543
- const N = {
544
- id: `url-${Date.now()}-${Math.random()}`,
545
- name: y,
546
- type: "url",
547
- connectionId: e.id,
548
- connectionType: e.type,
549
- label: y,
550
- description: `URL source of type ${l}`,
551
- originalName: y,
552
- url: f,
553
- sourceType: l
554
- };
555
- a([...n, N]), m(""), u(""), s("api");
556
- }, k = (y) => {
557
- a(
558
- n.filter(
559
- (f) => !("id" in f && f.id === y && f.connectionId === e.id && f.type === "url")
560
- )
561
- );
562
- };
563
- return /* @__PURE__ */ i("div", { className: "space-y-2 px-8 py-2", children: [
564
- /* @__PURE__ */ i("div", { className: "space-y-2 rounded-[6px] border border-border bg-muted/20 p-3", children: [
565
- /* @__PURE__ */ t(
566
- Ne,
567
- {
568
- value: o,
569
- onChange: (y) => m(y.target.value),
570
- placeholder: "Source name",
571
- className: "h-7 text-[12px]"
572
- }
573
- ),
574
- /* @__PURE__ */ t(
575
- Ne,
576
- {
577
- value: d,
578
- onChange: (y) => u(y.target.value),
579
- placeholder: "https://api.example.com/data",
580
- className: "h-7 text-[12px]"
581
- }
582
- ),
583
- /* @__PURE__ */ i("div", { className: "flex items-center gap-2", children: [
584
- /* @__PURE__ */ i(
585
- "select",
586
- {
587
- value: l,
588
- onChange: (y) => s(y.target.value),
589
- className: "h-7 flex-1 rounded-control border border-input bg-background px-2 text-[12px]",
590
- children: [
591
- /* @__PURE__ */ t("option", { value: "api", children: "API endpoint" }),
592
- /* @__PURE__ */ t("option", { value: "csv", children: "CSV file" }),
593
- /* @__PURE__ */ t("option", { value: "json", children: "JSON file" })
594
- ]
595
- }
596
- ),
597
- /* @__PURE__ */ i(
598
- G,
599
- {
600
- type: "button",
601
- size: "sm",
602
- className: "h-7 text-[12px]",
603
- disabled: !o.trim() || !d.trim(),
604
- onClick: x,
605
- children: [
606
- /* @__PURE__ */ t(Ve, { className: "mr-1 h-3 w-3" }),
607
- "Add"
608
- ]
609
- }
610
- )
611
- ] })
612
- ] }),
613
- c.length > 0 && /* @__PURE__ */ t("ul", { className: "space-y-1", children: c.map((y) => /* @__PURE__ */ i(
614
- "li",
615
- {
616
- className: "flex items-center gap-2 rounded-[5px] border border-border bg-background px-2 py-1.5",
617
- children: [
618
- /* @__PURE__ */ t(wn, { className: "h-3.5 w-3.5 shrink-0 text-muted-foreground" }),
619
- /* @__PURE__ */ i("div", { className: "min-w-0 flex-1", children: [
620
- /* @__PURE__ */ t("p", { className: "truncate text-[12px]", children: y.name }),
621
- /* @__PURE__ */ t("p", { className: "truncate text-[11px] text-muted-foreground", children: y.url })
622
- ] }),
623
- /* @__PURE__ */ t(
624
- "button",
625
- {
626
- type: "button",
627
- "aria-label": `Remove ${y.name}`,
628
- onClick: () => k(y.id),
629
- className: "inline-flex h-5 w-5 shrink-0 items-center justify-center rounded-[3px] text-muted-foreground hover:bg-muted hover:text-foreground",
630
- children: /* @__PURE__ */ t(ce, { className: "h-3 w-3" })
631
- }
632
- )
633
- ]
634
- },
635
- y.id
636
- )) })
637
- ] });
638
- }
639
- function Ra({
640
- connection: e,
641
- requiresSchema: n,
642
- search: a,
643
- selectedEntities: o,
644
- onSelectionChange: m
645
- }) {
646
- var l;
647
- const d = Ge("/v1/databases", { connection_id: e.id }, [
648
- "databases",
649
- e.id
650
- ]);
651
- if (d.isLoading)
652
- return /* @__PURE__ */ t("div", { className: "px-8 py-1.5 text-[11px] text-muted-foreground", children: "Loading databases…" });
653
- const u = ((l = d.data) == null ? void 0 : l.databases) ?? [];
654
- return u.length === 0 ? /* @__PURE__ */ t("div", { className: "px-8 py-1.5 text-[11px] text-muted-foreground", children: "No databases." }) : /* @__PURE__ */ t("div", { children: u.map((s) => /* @__PURE__ */ t(
655
- on,
656
- {
657
- label: s.database_name,
658
- indentLevel: 1,
659
- search: a,
660
- renderChildren: (c) => c && (n ? /* @__PURE__ */ t(
661
- sn,
662
- {
663
- connection: e,
664
- databaseName: s.database_name,
665
- search: a,
666
- selectedEntities: o,
667
- onSelectionChange: m
668
- }
669
- ) : /* @__PURE__ */ t(
670
- mt,
671
- {
672
- connection: e,
673
- databaseName: s.database_name,
674
- schemaName: "",
675
- search: a,
676
- selectedEntities: o,
677
- onSelectionChange: m
678
- }
679
- ))
680
- },
681
- s.database_name
682
- )) });
683
- }
684
- function sn({
685
- connection: e,
686
- databaseName: n,
687
- search: a,
688
- selectedEntities: o,
689
- onSelectionChange: m
690
- }) {
691
- var l;
692
- const d = Ge(
693
- "/v1/schemas",
694
- {
695
- connection_id: e.id,
696
- database_name: n || "NA"
697
- },
698
- ["schemas", e.id, n],
699
- !!e.id
700
- );
701
- if (d.isLoading)
702
- return /* @__PURE__ */ t("div", { className: "px-8 py-1.5 text-[11px] text-muted-foreground", children: "Loading schemas…" });
703
- const u = ((l = d.data) == null ? void 0 : l.schemas) ?? [];
704
- return u.length === 0 ? /* @__PURE__ */ t("div", { className: "px-8 py-1.5 text-[11px] text-muted-foreground", children: "No schemas." }) : /* @__PURE__ */ t("div", { children: u.map((s) => /* @__PURE__ */ t(
705
- on,
706
- {
707
- label: s.schema_name,
708
- indentLevel: n ? 2 : 1,
709
- search: a,
710
- renderChildren: (c) => c && /* @__PURE__ */ t(
711
- mt,
712
- {
713
- connection: e,
714
- databaseName: n,
715
- schemaName: s.schema_name,
716
- search: a,
717
- selectedEntities: o,
718
- onSelectionChange: m
719
- }
720
- )
721
- },
722
- s.schema_name
723
- )) });
724
- }
725
- function mt({
726
- connection: e,
727
- databaseName: n,
728
- schemaName: a,
729
- search: o,
730
- selectedEntities: m,
731
- onSelectionChange: d
732
- }) {
733
- const u = Ge(
734
- "/v1/tables",
735
- {
736
- connection_id: e.id,
737
- database_name: n || void 0,
738
- schema_name: a || void 0
739
- },
740
- ["tables", e.id, n, a]
741
- ), l = P(() => {
742
- var S;
743
- const f = ((S = u.data) == null ? void 0 : S.tables) ?? [];
744
- if (!o) return f;
745
- const N = o.trim().toLowerCase();
746
- return f.filter((V) => V.table_name.toLowerCase().includes(N));
747
- }, [u.data, o]), s = (f, N) => ({
748
- connectionId: e.id,
749
- connectionType: e.type,
750
- type: "table",
751
- dialect: e.dialect,
752
- database: n || void 0,
753
- schema: a || void 0,
754
- name: f,
755
- dbObjectType: N == null ? void 0 : N.toLowerCase()
756
- });
757
- if (u.isLoading)
758
- return /* @__PURE__ */ t("div", { className: "px-10 py-1.5 text-[11px] text-muted-foreground", children: "Loading tables…" });
759
- if (l.length === 0)
760
- return o ? null : /* @__PURE__ */ t("div", { className: "px-10 py-1.5 text-[11px] text-muted-foreground", children: "No tables." });
761
- const c = l.map(
762
- (f) => s(f.table_name, f.table_type)
763
- ), x = c.length > 0 && c.every(
764
- (f) => m.some((N) => J(N, f))
765
- ), k = (f, N) => {
766
- const S = s(f, N), V = m.some(
767
- (F) => J(F, S)
768
- );
769
- d(
770
- V ? m.filter((F) => !J(F, S)) : [...m, S]
771
- );
772
- }, y = () => {
773
- if (c.length === 0) return;
774
- if (x) {
775
- d(
776
- m.filter(
777
- (N) => !c.some(
778
- (S) => J(N, S)
779
- )
780
- )
781
- );
782
- return;
783
- }
784
- const f = [...m];
785
- for (const N of c)
786
- f.some((S) => J(S, N)) || f.push(N);
787
- d(f);
788
- };
789
- return /* @__PURE__ */ i("ul", { children: [
790
- /* @__PURE__ */ i("li", { className: "flex items-center justify-between gap-2 py-1 pl-12 pr-4", children: [
791
- /* @__PURE__ */ i("span", { className: "text-[10.5px] font-medium uppercase tracking-[0.06em] text-muted-foreground", children: [
792
- l.length,
793
- " table",
794
- l.length === 1 ? "" : "s"
795
- ] }),
796
- /* @__PURE__ */ t(
797
- "button",
798
- {
799
- type: "button",
800
- onClick: y,
801
- className: "rounded-[3px] px-1.5 py-0.5 text-[10.5px] font-medium text-muted-foreground hover:bg-muted hover:text-foreground",
802
- children: x ? "Clear" : "Select all"
803
- }
804
- )
805
- ] }),
806
- l.map((f) => {
807
- const N = s(f.table_name, f.table_type), S = m.some(
808
- (V) => J(V, N)
809
- );
810
- return /* @__PURE__ */ t("li", { children: /* @__PURE__ */ i("label", { className: "flex cursor-pointer items-center gap-2.5 py-1.5 pl-12 pr-4 transition-colors hover:bg-muted/40", children: [
811
- /* @__PURE__ */ t(
812
- Ue,
813
- {
814
- checked: S,
815
- onCheckedChange: () => k(f.table_name, f.table_type),
816
- className: "h-3.5 w-3.5 shrink-0"
817
- }
818
- ),
819
- /* @__PURE__ */ t(
820
- fn,
821
- {
822
- className: "h-3.5 w-3.5 shrink-0 text-muted-foreground",
823
- strokeWidth: 1.75
824
- }
825
- ),
826
- /* @__PURE__ */ i("div", { className: "flex min-w-0 flex-1 items-baseline gap-1.5", children: [
827
- /* @__PURE__ */ t("span", { className: "truncate text-[13px] text-foreground/90", children: f.table_name }),
828
- /* @__PURE__ */ t("span", { className: "shrink-0 font-mono text-[10px] uppercase tracking-[0.06em] text-muted-foreground/70", children: f.table_type ?? "table" })
829
- ] })
830
- ] }) }, f.table_name);
831
- })
832
- ] });
833
- }
834
- function Ea({
835
- connection: e,
836
- search: n,
837
- selectedEntities: a,
838
- onSelectionChange: o
839
- }) {
840
- const m = Ge("/v1/datamodels", { connection_id: e.id }, [
841
- "datamodels",
842
- e.id
843
- ]), d = P(() => {
844
- var c;
845
- const l = ((c = m.data) == null ? void 0 : c.datamodels) ?? [];
846
- if (!n) return l;
847
- const s = n.trim().toLowerCase();
848
- return l.filter(
849
- (x) => `${x.label ?? ""} ${x.name ?? ""} ${x.description ?? ""}`.toLowerCase().includes(s)
850
- );
851
- }, [m.data, n]);
852
- if (m.isLoading || d.length === 0) return null;
853
- const u = (l) => {
854
- const s = {
855
- id: l.id,
856
- name: l.name,
857
- label: l.label || "",
858
- description: l.description || "",
859
- connectionId: e.id,
860
- connectionType: e.type,
861
- type: "model",
862
- dialect: l.dialect ?? e.dialect,
863
- database: l.database || "",
864
- schema: l.schema || ""
865
- }, c = a.some(
866
- (x) => J(x, s)
867
- );
868
- o(
869
- c ? a.filter((x) => !J(x, s)) : [...a, s]
870
- );
871
- };
872
- return /* @__PURE__ */ i("div", { children: [
873
- /* @__PURE__ */ t("div", { className: "px-8 pb-1 pt-2", children: /* @__PURE__ */ t("p", { className: "text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground", children: "Data models" }) }),
874
- /* @__PURE__ */ t("ul", { children: d.map((l) => {
875
- const s = {
876
- id: l.id,
877
- name: l.name,
878
- label: l.label || "",
879
- description: l.description || "",
880
- connectionId: e.id,
881
- connectionType: e.type,
882
- type: "model",
883
- dialect: l.dialect ?? e.dialect,
884
- database: l.database || "",
885
- schema: l.schema || ""
886
- }, c = a.some(
887
- (x) => J(x, s)
888
- );
889
- return /* @__PURE__ */ t("li", { children: /* @__PURE__ */ i("label", { className: "flex cursor-pointer items-start gap-2.5 py-1.5 pl-12 pr-4 transition-colors hover:bg-muted/40", children: [
890
- /* @__PURE__ */ t(
891
- Ue,
892
- {
893
- checked: c,
894
- onCheckedChange: () => u(l),
895
- className: "mt-[2px] h-3.5 w-3.5 shrink-0"
896
- }
897
- ),
898
- /* @__PURE__ */ t(
899
- wa,
900
- {
901
- className: "mt-[2px] h-3.5 w-3.5 shrink-0 text-muted-foreground",
902
- strokeWidth: 1.75
903
- }
904
- ),
905
- /* @__PURE__ */ i("div", { className: "min-w-0 flex-1", children: [
906
- /* @__PURE__ */ i("div", { className: "flex items-baseline gap-1.5", children: [
907
- /* @__PURE__ */ t("span", { className: "truncate text-[13px] text-foreground/90", children: l.label || l.name }),
908
- /* @__PURE__ */ t("span", { className: "shrink-0 font-mono text-[10px] uppercase tracking-[0.06em] text-muted-foreground/70", children: "model" })
909
- ] }),
910
- l.description && /* @__PURE__ */ t("p", { className: "mt-0.5 line-clamp-2 text-[11px] leading-[1.4] text-muted-foreground", children: l.description })
911
- ] })
912
- ] }) }, l.id);
913
- }) })
914
- ] });
915
- }
916
- function on({
917
- label: e,
918
- indentLevel: n,
919
- search: a,
920
- renderChildren: o
921
- }) {
922
- const [m, d] = Y(!1), u = m || a.length > 0;
923
- return /* @__PURE__ */ i("div", { children: [
924
- /* @__PURE__ */ i(
925
- "button",
926
- {
927
- type: "button",
928
- onClick: () => d((s) => !s),
929
- className: q(
930
- "flex h-6 w-full items-center gap-1.5 pr-4 text-left transition-colors hover:bg-muted/40",
931
- n === 1 ? "pl-8" : "pl-10"
932
- ),
933
- children: [
934
- /* @__PURE__ */ t(
935
- Te,
936
- {
937
- className: q(
938
- "h-2.5 w-2.5 shrink-0 text-muted-foreground transition-transform",
939
- u && "rotate-90"
940
- ),
941
- strokeWidth: 1.75
942
- }
943
- ),
944
- /* @__PURE__ */ t("span", { className: "truncate font-mono text-[11px] text-muted-foreground", children: e })
945
- ]
946
- }
947
- ),
948
- o(u)
949
- ] });
950
- }
951
- function Ge(e, n, a, o = !0) {
952
- const { tokenProps: m } = ct(), d = ut((l) => l.authToken), u = P(
953
- () => Object.fromEntries(
954
- Object.entries(n).filter(([, l]) => l !== void 0)
955
- ),
956
- [n]
957
- );
958
- return Vt({
959
- queryKey: a,
960
- queryFn: () => Qt(
961
- `${m.apiServiceUrl}${e}`,
962
- (d == null ? void 0 : d.accessToken) || "",
963
- u
964
- ),
965
- enabled: o && !!(d != null && d.accessToken) && Object.values(u).every((l) => l.length > 0)
966
- });
967
- }
968
- function za(e) {
969
- return e.type === "dataset" && e.label || e.name;
970
- }
971
- function Ma(e, n) {
972
- if (!(e.type !== "dataset" || !e.domainId || !n))
973
- return n.get(e.domainId);
974
- }
975
- function qa({
976
- selectedEntities: e,
977
- onDeselectEntity: n,
978
- semanticDomainLabels: a
979
- }) {
980
- return e.length === 0 ? null : /* @__PURE__ */ t("div", { className: "flex flex-wrap gap-1", children: e.map((o, m) => /* @__PURE__ */ t(
981
- ja,
982
- {
983
- entity: o,
984
- semanticDomainLabels: a,
985
- onDeselect: n
986
- },
987
- `${o.type}-${o.name}-${m}`
988
- )) });
989
- }
990
- function ja({
991
- entity: e,
992
- semanticDomainLabels: n,
993
- onDeselect: a
994
- }) {
995
- const o = za(e), m = Ma(e, n), d = m ? `${o} from ${m}` : o;
996
- return /* @__PURE__ */ i(
997
- "span",
998
- {
999
- className: "inline-flex items-center gap-1 rounded-control border border-input bg-muted/50 py-0.5 pl-1.5 pr-0.5 text-[11px] text-foreground/80",
1000
- title: d,
1001
- children: [
1002
- /* @__PURE__ */ i("span", { className: "max-w-[180px] truncate", children: [
1003
- o,
1004
- m ? /* @__PURE__ */ i("span", { className: "text-muted-foreground", children: [
1005
- " · ",
1006
- m
1007
- ] }) : null
1008
- ] }),
1009
- /* @__PURE__ */ t(
1010
- "button",
1011
- {
1012
- type: "button",
1013
- onClick: (u) => {
1014
- u.stopPropagation(), a(e);
1015
- },
1016
- "aria-label": `Remove ${d}`,
1017
- className: "inline-flex h-3.5 w-3.5 shrink-0 items-center justify-center rounded-control text-muted-foreground transition-colors hover:bg-muted hover:text-foreground",
1018
- children: /* @__PURE__ */ t(ce, { className: "h-2.5 w-2.5" })
1019
- }
1020
- )
1021
- ]
1022
- }
1023
- );
1024
- }
1025
- function Ye(e) {
1026
- if (e != null && e.length)
1027
- return e.every((n) => n.type === "dataset") ? "semanticDomain" : e.every((n) => n.type === "url") ? "url" : e.every(
1028
- (n) => n.type === "upload" || n.type === "file"
1029
- ) ? "upload" : "database";
1030
- }
1031
- function Sr({
1032
- open: e,
1033
- onOpenChange: n,
1034
- dataSource: a,
1035
- incomingSelectedEntities: o,
1036
- onDataSourceChange: m
1037
- }) {
1038
- var Se, me;
1039
- const { tokenProps: d } = ct(), u = d.config, l = d.semanticDomainAccess || Xn, [s, c] = Y([]), [x, k] = Y(""), [y, f] = Y("all"), [N, S] = Y(
1040
- void 0
1041
- ), V = $e(!1), { updateDataSource: F } = Et(), K = m ?? F, C = l.mode, T = (u == null ? void 0 : u.showDirectSource) !== !1, U = C === "include" || C === "exclude" || !T, Z = C !== "all", p = T && !U, I = U ? "semanticDomain" : a.mode, $ = !T, D = C === "include" && (((Se = l.domainIds) == null ? void 0 : Se.length) || 0) === 1 ? (me = l.domainIds) == null ? void 0 : me[0] : void 0, v = ne(
1042
- (A) => {
1043
- V.current = !0, K({
1044
- ...a,
1045
- connectionId: (a == null ? void 0 : a.connectionId) || "",
1046
- connectionType: (a == null ? void 0 : a.connectionType) || "",
1047
- mode: A,
1048
- selectedEntities: (a == null ? void 0 : a.selectedEntities) || [],
1049
- ...A !== "semanticDomain" && { semanticDomainId: void 0 }
1050
- });
1051
- },
1052
- [a, K]
1053
- ), h = ne(
1054
- (A) => {
1055
- K({
1056
- ...a,
1057
- ...A
1058
- });
1059
- },
1060
- [a, K]
1061
- );
1062
- de(() => {
1063
- var b;
1064
- if (U && a.mode !== "semanticDomain") {
1065
- v("semanticDomain");
1066
- return;
1067
- }
1068
- if (!Z || I !== "semanticDomain") return;
1069
- const A = l.domainIds ?? [], ae = (((b = a.selectedEntities) == null ? void 0 : b.length) ?? 0) > 0, r = ((s == null ? void 0 : s.length) ?? 0) > 0;
1070
- Da({
1071
- mode: C,
1072
- currentDomainId: a.semanticDomainId,
1073
- scopedDomainIds: A,
1074
- hasSelectedEntities: ae
1075
- }) && (h({
1076
- semanticDomainId: void 0,
1077
- selectedEntities: []
1078
- }), r && c([]));
1079
- }, [
1080
- U,
1081
- Z,
1082
- I,
1083
- a.mode,
1084
- a.semanticDomainId,
1085
- a.selectedEntities,
1086
- s,
1087
- l.domainIds,
1088
- C,
1089
- h,
1090
- v
1091
- ]), de(() => {
1092
- D && !a.semanticDomainId && h({ semanticDomainId: D });
1093
- }, [D, a.semanticDomainId, h]), de(() => {
1094
- if (!e) {
1095
- V.current = !1, k(""), S(void 0), f(U ? "semantic" : "all");
1096
- return;
1097
- }
1098
- V.current || (c([...o || []]), S(
1099
- Ye(o)
1100
- ));
1101
- }, [e, o, U]);
1102
- const E = (A) => {
1103
- V.current = !0, c(
1104
- s.filter((ae) => !J(ae, A))
1105
- );
1106
- }, w = ne(
1107
- (A, ae) => {
1108
- V.current = !0, c(A), S(
1109
- ae ?? Ye(A)
1110
- );
1111
- },
1112
- []
1113
- ), H = () => {
1114
- var ae, r;
1115
- const A = Ye(s) ?? N ?? I;
1116
- if (A === "semanticDomain") {
1117
- const g = Kt(s) || a.semanticDomainId, b = ((ae = s == null ? void 0 : s[0]) == null ? void 0 : ae.connectionId) || a.connectionId, L = ((r = s == null ? void 0 : s[0]) == null ? void 0 : r.connectionType) || a.connectionType;
1118
- K({
1119
- ...a,
1120
- mode: "semanticDomain",
1121
- semanticDomainId: g,
1122
- connectionId: b,
1123
- connectionType: L,
1124
- selectedEntities: s
1125
- });
1126
- } else if (A === "upload" || A === "url") {
1127
- const g = s == null ? void 0 : s[0];
1128
- K({
1129
- ...a,
1130
- mode: A,
1131
- semanticDomainId: void 0,
1132
- connectionId: (g == null ? void 0 : g.connectionId) || a.connectionId,
1133
- connectionType: (g == null ? void 0 : g.connectionType) || a.connectionType,
1134
- selectedEntities: s
1135
- });
1136
- } else {
1137
- const g = s == null ? void 0 : s[0];
1138
- K({
1139
- ...a,
1140
- mode: "database",
1141
- semanticDomainId: void 0,
1142
- connectionId: (g == null ? void 0 : g.connectionId) || a.connectionId,
1143
- connectionType: (g == null ? void 0 : g.connectionType) || a.connectionType,
1144
- selectedEntities: s
1145
- });
1146
- }
1147
- n(!1);
1148
- }, { semanticDomains: _ } = an(), { connections: z } = Rt(), B = P(
1149
- () => new Map(
1150
- _.map((A) => [
1151
- A.id,
1152
- A.label || A.name
1153
- ])
1154
- ),
1155
- [_]
1156
- ), j = (A) => {
1157
- f(A), A === "semantic" || A.startsWith("domain:") ? a.mode !== "semanticDomain" && v("semanticDomain") : (A === "direct" || A.startsWith("conn:")) && a.mode === "semanticDomain" && v("database");
1158
- }, ee = y.startsWith("domain:"), te = y.startsWith("conn:"), Be = ee ? y.slice(7) : void 0, We = te ? y.slice(5) : void 0, oe = !p || y === "all" || y === "semantic" || ee, Ie = T && !U && (y === "all" || y === "direct" || te), ue = ((o == null ? void 0 : o.length) ?? 0) > 0, Ce = s.length === 0 && !ue, we = s.length === 0 && ue ? "Clear" : "Add", ke = $ ? "Select dataset" : "Add data";
1159
- return /* @__PURE__ */ t(kn, { open: e, onOpenChange: n, children: /* @__PURE__ */ i(
1160
- Sn,
1161
- {
1162
- showCloseButton: !1,
1163
- className: "flex h-[560px] w-[620px] max-w-[620px] flex-col gap-0 overflow-hidden rounded-[6px] border border-border bg-popover p-0",
1164
- children: [
1165
- /* @__PURE__ */ t(xn, { children: /* @__PURE__ */ t(Dn, { children: ke }) }),
1166
- /* @__PURE__ */ i("div", { className: "flex items-start justify-between border-b border-border px-4 py-2.5", children: [
1167
- /* @__PURE__ */ i("div", { children: [
1168
- /* @__PURE__ */ t("p", { className: "text-[14px] font-semibold text-foreground", children: ke }),
1169
- /* @__PURE__ */ t("p", { className: "text-[11px] text-muted-foreground", children: $ ? "Choose a curated dataset to analyze" : "Search your semantic domains and connections" })
1170
- ] }),
1171
- /* @__PURE__ */ t(
1172
- "button",
1173
- {
1174
- type: "button",
1175
- onClick: () => n(!1),
1176
- "aria-label": "Close",
1177
- className: "inline-flex h-6 w-6 shrink-0 items-center justify-center rounded-[4px] text-muted-foreground transition-colors hover:bg-muted hover:text-foreground",
1178
- children: /* @__PURE__ */ t(ce, { className: "h-3.5 w-3.5" })
1179
- }
1180
- )
1181
- ] }),
1182
- /* @__PURE__ */ i("div", { className: "border-b border-border px-4 py-2.5", children: [
1183
- /* @__PURE__ */ i("div", { className: "flex h-7 items-center gap-1.5 rounded-control border border-input bg-background px-2 focus-within:border-ring", children: [
1184
- /* @__PURE__ */ t(Tn, { className: "h-3 w-3 shrink-0 text-muted-foreground" }),
1185
- /* @__PURE__ */ t(
1186
- "input",
1187
- {
1188
- type: "text",
1189
- value: x,
1190
- onChange: (A) => k(A.target.value),
1191
- placeholder: "Search datasets, tables, views, models",
1192
- className: "h-full w-full bg-transparent text-[12px] text-foreground placeholder:text-muted-foreground/60 focus:outline-none"
1193
- }
1194
- ),
1195
- x && /* @__PURE__ */ t(
1196
- "button",
1197
- {
1198
- type: "button",
1199
- onClick: () => k(""),
1200
- "aria-label": "Clear search",
1201
- className: "inline-flex h-4 w-4 shrink-0 items-center justify-center rounded-control text-muted-foreground hover:bg-muted hover:text-foreground",
1202
- children: /* @__PURE__ */ t(ce, { className: "h-3 w-3" })
1203
- }
1204
- )
1205
- ] }),
1206
- p && // Horizontal scroll strip — chips stay on a single row
1207
- // regardless of how many sources exist. Mock canon: the
1208
- // chip rail never grows the picker's header height.
1209
- /* @__PURE__ */ t("div", { className: "-mx-4 mt-2 overflow-x-auto px-4 [scrollbar-width:none] [&::-webkit-scrollbar]:hidden", children: /* @__PURE__ */ i("div", { className: "flex w-max items-center gap-1", children: [
1210
- /* @__PURE__ */ t(
1211
- De,
1212
- {
1213
- label: "All",
1214
- active: y === "all",
1215
- onClick: () => j("all")
1216
- }
1217
- ),
1218
- (_.length > 0 || z.length > 0) && /* @__PURE__ */ i(he, { children: [
1219
- /* @__PURE__ */ t(
1220
- De,
1221
- {
1222
- label: "Semantic",
1223
- active: y === "semantic",
1224
- onClick: () => j("semantic")
1225
- }
1226
- ),
1227
- /* @__PURE__ */ t(
1228
- De,
1229
- {
1230
- label: "Direct",
1231
- active: y === "direct",
1232
- onClick: () => j("direct")
1233
- }
1234
- ),
1235
- /* @__PURE__ */ t("span", { className: "shrink-0 px-0.5 text-muted-foreground/50", children: "·" })
1236
- ] }),
1237
- _.map((A) => /* @__PURE__ */ t(
1238
- De,
1239
- {
1240
- label: A.label || A.name,
1241
- active: y === `domain:${A.id}`,
1242
- onClick: () => j(`domain:${A.id}`)
1243
- },
1244
- `domain:${A.id}`
1245
- )),
1246
- z.map((A) => /* @__PURE__ */ t(
1247
- De,
1248
- {
1249
- label: A.name,
1250
- active: y === `conn:${A.id}`,
1251
- onClick: () => j(`conn:${A.id}`)
1252
- },
1253
- `conn:${A.id}`
1254
- ))
1255
- ] }) })
1256
- ] }),
1257
- /* @__PURE__ */ i("div", { className: "flex-1 overflow-y-auto py-1", children: [
1258
- oe && /* @__PURE__ */ t(
1259
- La,
1260
- {
1261
- domainAccess: l,
1262
- search: x,
1263
- scopeDomainId: Be,
1264
- selectedEntities: s,
1265
- onSelectionChange: (A) => w(A, "semanticDomain")
1266
- }
1267
- ),
1268
- Ie && /* @__PURE__ */ t(
1269
- Oa,
1270
- {
1271
- search: x,
1272
- scopeConnectionId: We,
1273
- selectedEntities: s,
1274
- onSelectionChange: (A) => w(A)
1275
- }
1276
- )
1277
- ] }),
1278
- /* @__PURE__ */ i("div", { className: "flex flex-col gap-0.5 border-t border-border px-4 py-2.5", children: [
1279
- /* @__PURE__ */ i("div", { className: "flex items-center justify-between gap-3", children: [
1280
- /* @__PURE__ */ i("div", { className: "flex items-center gap-1.5 text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground", children: [
1281
- /* @__PURE__ */ t("span", { children: "Selected" }),
1282
- /* @__PURE__ */ i("span", { className: "font-mono tabular-nums text-muted-foreground/70", children: [
1283
- "· ",
1284
- s.length
1285
- ] })
1286
- ] }),
1287
- /* @__PURE__ */ i("div", { className: "flex items-center gap-1.5", children: [
1288
- /* @__PURE__ */ t(
1289
- "button",
1290
- {
1291
- type: "button",
1292
- onClick: () => n(!1),
1293
- className: "inline-flex h-7 items-center rounded-control px-2.5 text-[12px] font-medium text-muted-foreground transition-colors hover:bg-muted hover:text-foreground",
1294
- children: "Cancel"
1295
- }
1296
- ),
1297
- /* @__PURE__ */ i(
1298
- "button",
1299
- {
1300
- type: "button",
1301
- onClick: H,
1302
- disabled: Ce,
1303
- className: q(
1304
- "inline-flex h-7 items-center gap-1.5 rounded-control bg-primary px-2.5 text-[12px] font-medium text-primary-foreground transition-colors hover:bg-primary/90",
1305
- Ce && "cursor-not-allowed opacity-50 hover:bg-primary"
1306
- ),
1307
- children: [
1308
- /* @__PURE__ */ t("span", { children: we }),
1309
- s.length > 0 && /* @__PURE__ */ i("span", { className: "font-mono tabular-nums text-primary-foreground/70", children: [
1310
- "· ",
1311
- s.length
1312
- ] })
1313
- ]
1314
- }
1315
- )
1316
- ] })
1317
- ] }),
1318
- s.length > 0 && /* @__PURE__ */ t(
1319
- qa,
1320
- {
1321
- selectedEntities: s,
1322
- onDeselectEntity: E,
1323
- semanticDomainLabels: B
1324
- }
1325
- )
1326
- ] })
1327
- ]
1328
- }
1329
- ) });
1330
- }
1331
- function De({
1332
- label: e,
1333
- active: n,
1334
- onClick: a
1335
- }) {
1336
- return /* @__PURE__ */ t(
1337
- "button",
1338
- {
1339
- type: "button",
1340
- onClick: a,
1341
- "aria-pressed": n,
1342
- className: q(
1343
- "inline-flex h-6 shrink-0 items-center whitespace-nowrap rounded-control px-2 text-[11px] font-medium transition-colors",
1344
- n ? "bg-primary text-primary-foreground hover:bg-primary/90" : "text-muted-foreground hover:bg-muted hover:text-foreground"
1345
- ),
1346
- children: e
1347
- }
1348
- );
1349
- }
1350
- function Dr() {
1351
- const e = se((u) => u.card.dataSource), {
1352
- setSelectedConnectionId: n,
1353
- setSelectedDatabaseName: a,
1354
- setSelectedSchemaName: o,
1355
- setSelectedTableName: m,
1356
- setSelectedDatamodelId: d
1357
- } = Et();
1358
- de(() => {
1359
- var f;
1360
- if (!e) return;
1361
- const { tableName: u, schemaName: l, databaseName: s, connectionId: c } = In(e), x = (f = e.selectedEntities) == null ? void 0 : f[0], y = (x == null ? void 0 : x.type) === "model" && "id" in x ? x.id : "";
1362
- n(c || ""), a(s || ""), o(l || ""), m(u || ""), d(y);
1363
- }, [
1364
- e,
1365
- n,
1366
- a,
1367
- o,
1368
- m,
1369
- d
1370
- ]);
1371
- }
1372
- function Tr({
1373
- type: e,
1374
- isLinked: n,
1375
- className: a,
1376
- showLabel: o = !1,
1377
- showLocal: m = !1
1378
- }) {
1379
- const d = ut((S) => S.selectedFrameId), u = Ln((S) => S.selectedVisual), l = se((S) => S.frame);
1380
- let s;
1381
- if (e)
1382
- s = e;
1383
- else if (n !== void 0)
1384
- s = n ? "linked" : "library";
1385
- else if (!!!(l != null && l.visualId || u != null && u.id) && d)
1386
- s = "local";
1387
- else if (u && !d)
1388
- s = "library";
1389
- else if (l != null && l.visualId && d)
1390
- s = "linked";
1391
- else if (u != null && u.id && d)
1392
- s = "library";
1393
- else
1394
- return null;
1395
- if (s === "local" && !m)
1396
- return null;
1397
- const c = {
1398
- 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",
1399
- 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",
1400
- 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"
1401
- }, x = {
1402
- local: "Local to this dashboard: Changes made here only affect this dashboard copy.",
1403
- linked: "Linked to library: Changes made here update the library visual and all linked instances.",
1404
- library: "Library visual: Share and reuse this visual across multiple dashboards."
1405
- }, k = {
1406
- local: "border-slate-200 bg-slate-50 text-slate-900 dark:border-slate-700 dark:bg-slate-900 dark:text-slate-100",
1407
- linked: "border-purple-200 bg-purple-50 text-purple-900 dark:border-purple-800 dark:bg-purple-950 dark:text-purple-100",
1408
- library: "border-blue-200 bg-blue-50 text-blue-900 dark:border-blue-800 dark:bg-blue-950 dark:text-blue-100"
1409
- }, y = {
1410
- local: "fill-slate-50 dark:fill-slate-900",
1411
- linked: "fill-purple-50 dark:fill-purple-950",
1412
- library: "fill-blue-50 dark:fill-blue-950"
1413
- }, f = {
1414
- local: /* @__PURE__ */ t("span", { className: "h-2 w-2 rounded-full bg-current/70" }),
1415
- linked: /* @__PURE__ */ t(An, { className: "h-3.5 w-3.5" }),
1416
- library: /* @__PURE__ */ t(ka, { className: "h-3.5 w-3.5" })
1417
- }, N = {
1418
- local: "Local",
1419
- linked: "Linked",
1420
- library: "Library"
1421
- };
1422
- return /* @__PURE__ */ t(at, { children: /* @__PURE__ */ i(rt, { delayDuration: 300, children: [
1423
- /* @__PURE__ */ t(st, { asChild: !0, children: /* @__PURE__ */ i(
1424
- $n,
1425
- {
1426
- variant: "outline",
1427
- className: q(
1428
- "cursor-help select-none transition-all",
1429
- c[s],
1430
- a
1431
- ),
1432
- children: [
1433
- f[s],
1434
- o && /* @__PURE__ */ t("span", { className: "ml-1 text-xs font-medium leading-none", children: N[s] })
1435
- ]
1436
- }
1437
- ) }),
1438
- /* @__PURE__ */ i(
1439
- ot,
1440
- {
1441
- side: "bottom",
1442
- className: q("max-w-xs", k[s]),
1443
- children: [
1444
- /* @__PURE__ */ t(Ft, { className: y[s] }),
1445
- /* @__PURE__ */ t("p", { children: x[s] })
1446
- ]
1447
- }
1448
- )
1449
- ] }) });
1450
- }
1451
- const Ua = vn(
1452
- ({
1453
- side: e = "bottom",
1454
- children: n,
1455
- className: a,
1456
- tooltip: o,
1457
- onClick: m,
1458
- openDelay: d = 300,
1459
- buttonProps: u,
1460
- disabled: l,
1461
- ...s
1462
- }, c) => /* @__PURE__ */ t(at, { children: /* @__PURE__ */ i(rt, { delayDuration: d, children: [
1463
- /* @__PURE__ */ t(st, { asChild: !0, children: /* @__PURE__ */ t(
1464
- G,
1465
- {
1466
- disabled: l,
1467
- ref: c,
1468
- size: "sm",
1469
- variant: "ghost",
1470
- onClick: m,
1471
- ...s,
1472
- ...u,
1473
- className: q(`${Jn}`, a),
1474
- children: n
1475
- }
1476
- ) }),
1477
- o && /* @__PURE__ */ i(
1478
- ot,
1479
- {
1480
- side: e,
1481
- sideOffset: 10,
1482
- className: q(
1483
- "border-foreground/20 bg-foreground text-background"
1484
- ),
1485
- children: [
1486
- o,
1487
- /* @__PURE__ */ t(Ft, { className: "fill-foreground" })
1488
- ]
1489
- }
1490
- )
1491
- ] }) })
1492
- );
1493
- Ua.displayName = "IconButton";
1494
- function ln(e) {
1495
- const { control: n, onChange: a } = e;
1496
- return /* @__PURE__ */ i("div", { className: "flex flex-col gap-1.5", children: [
1497
- /* @__PURE__ */ t(ie, { className: "text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground", children: "Label" }),
1498
- /* @__PURE__ */ t(
1499
- Ne,
1500
- {
1501
- size: "xs",
1502
- value: n.label,
1503
- placeholder: "Control label",
1504
- onChange: (o) => a(o.target.value)
1505
- }
1506
- )
1507
- ] });
1508
- }
1509
- function Ga(e) {
1510
- const { currentStep: n, labels: a } = e;
1511
- return /* @__PURE__ */ t("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__ */ t("div", { className: "flex flex-wrap items-center gap-2 sm:gap-2.5", children: a.map((o, m) => {
1512
- const d = m + 1, u = d === n, l = d < n;
1513
- return /* @__PURE__ */ i(yn, { children: [
1514
- /* @__PURE__ */ i("div", { className: "flex items-center gap-1.5", children: [
1515
- /* @__PURE__ */ t(
1516
- "span",
1517
- {
1518
- className: q(
1519
- "flex h-5 w-5 items-center justify-center rounded-full border text-[10px] font-medium tabular-nums",
1520
- u ? "border-foreground bg-foreground text-background" : l ? "border-foreground/30 bg-foreground/10 text-foreground" : "border-border/60 bg-background text-muted-foreground"
1521
- ),
1522
- children: d
1523
- }
1524
- ),
1525
- /* @__PURE__ */ t(
1526
- "span",
1527
- {
1528
- className: q(
1529
- "text-[12px]",
1530
- u ? "font-medium text-foreground" : "text-muted-foreground"
1531
- ),
1532
- children: o
1533
- }
1534
- )
1535
- ] }),
1536
- m < a.length - 1 ? /* @__PURE__ */ t(
1537
- "span",
1538
- {
1539
- className: "h-px w-4 bg-border/60 sm:w-6",
1540
- "aria-hidden": "true"
1541
- }
1542
- ) : null
1543
- ] }, o);
1544
- }) }) });
1545
- }
1546
- function je(e) {
1547
- const { secondary: n, tertiary: a, primary: o } = e;
1548
- return /* @__PURE__ */ i("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: [
1549
- n,
1550
- a,
1551
- o
1552
- ] });
1553
- }
1554
- function Ba(e) {
1555
- const { control: n, scope: a, detail: o } = e;
1556
- return /* @__PURE__ */ i("div", { className: "flex items-start gap-2.5 rounded-control border border-border/60 bg-muted/30 px-3 py-2.5", children: [
1557
- /* @__PURE__ */ t(zn, { className: "mt-0.5 h-3.5 w-3.5 shrink-0 text-foreground" }),
1558
- /* @__PURE__ */ i("div", { className: "min-w-0 space-y-0.5", children: [
1559
- /* @__PURE__ */ t("div", { className: "text-[13px] font-medium text-foreground", children: n.label }),
1560
- /* @__PURE__ */ i("div", { className: "text-[12px] text-muted-foreground", children: [
1561
- Ht(n.type).label,
1562
- " ·",
1563
- " ",
1564
- Xt(n),
1565
- " ·",
1566
- " ",
1567
- Yt(a, n.placement)
1568
- ] }),
1569
- o ? /* @__PURE__ */ t("div", { className: "text-[12px] text-muted-foreground", children: o }) : null
1570
- ] })
1571
- ] });
1572
- }
1573
- function Lt(e) {
1574
- const {
1575
- control: n,
1576
- defaultValue: a,
1577
- availableFieldChoices: o,
1578
- availableMetricChoices: m,
1579
- previewControlDefinitions: d,
1580
- previewControlValues: u,
1581
- onControlChange: l,
1582
- onLabelChange: s,
1583
- onDefaultValueChange: c,
1584
- onBack: x,
1585
- onNext: k,
1586
- nextDisabled: y
1587
- } = e;
1588
- return /* @__PURE__ */ i("div", { className: "space-y-3", children: [
1589
- /* @__PURE__ */ t(ln, { control: n, onChange: s }),
1590
- /* @__PURE__ */ t(
1591
- Mt,
1592
- {
1593
- control: n,
1594
- availableFieldChoices: o,
1595
- availableMetricChoices: m,
1596
- previewControlDefinitions: d,
1597
- previewControlValues: u,
1598
- controlLifecycle: "create",
1599
- onChange: l
1600
- }
1601
- ),
1602
- /* @__PURE__ */ t(
1603
- qt,
1604
- {
1605
- control: n,
1606
- value: a,
1607
- onChange: c,
1608
- allowNoDefault: !0,
1609
- allowCardDefault: !0,
1610
- hint: "This is the value viewers will see first.",
1611
- previewControlDefinitions: d,
1612
- previewControlValues: u
1613
- }
1614
- ),
1615
- /* @__PURE__ */ t(
1616
- je,
1617
- {
1618
- secondary: /* @__PURE__ */ t(G, { type: "button", variant: "outline", size: "xs", onClick: x, children: "Back" }),
1619
- primary: /* @__PURE__ */ t(
1620
- G,
1621
- {
1622
- type: "button",
1623
- size: "xs",
1624
- onClick: k,
1625
- disabled: y,
1626
- children: "Next"
1627
- }
1628
- )
1629
- }
1630
- )
1631
- ] });
1632
- }
1633
- const Wa = /* @__PURE__ */ new Set([
1634
- "grain_selector",
1635
- "aggregation_selector",
1636
- "field_selector",
1637
- "metric_selector"
1638
- ]);
1639
- function $t(e) {
1640
- const { text: n, ariaLabel: a } = e, [o, m] = Y(!1);
1641
- return /* @__PURE__ */ i(
1642
- "button",
1643
- {
1644
- type: "button",
1645
- "aria-label": a,
1646
- onClick: async () => {
1647
- try {
1648
- await navigator.clipboard.writeText(n), m(!0), setTimeout(() => m(!1), 1200);
1649
- } catch (d) {
1650
- console.error("Failed to copy", d);
1651
- }
1652
- },
1653
- 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",
1654
- children: [
1655
- /* @__PURE__ */ t("code", { className: "min-w-0 truncate font-mono text-[12px] text-foreground", children: n }),
1656
- /* @__PURE__ */ t("span", { className: "shrink-0 text-[11px] text-muted-foreground opacity-0 transition-opacity group-hover:opacity-100", children: o ? "Copied" : "Click to copy" })
1657
- ]
1658
- }
1659
- );
1660
- }
1661
- function At(e) {
1662
- const {
1663
- control: n,
1664
- scope: a,
1665
- createdReference: o,
1666
- explorerContent: m,
1667
- sqlDescription: d,
1668
- summaryDetail: u,
1669
- onBack: l,
1670
- onCancel: s,
1671
- onDone: c
1672
- } = e, x = Wa.has(n.type), k = o.match(/\[\[param\.(.+?)\]\]/), y = k ? `{{ param('${k[1]}') }}` : "";
1673
- return /* @__PURE__ */ i("div", { className: "space-y-4", children: [
1674
- /* @__PURE__ */ t(
1675
- Ba,
1676
- {
1677
- control: n,
1678
- scope: a,
1679
- detail: u
1680
- }
1681
- ),
1682
- /* @__PURE__ */ i("div", { className: "space-y-2", children: [
1683
- /* @__PURE__ */ t("p", { className: "text-[13px] font-medium text-foreground", children: "How cards use this control" }),
1684
- /* @__PURE__ */ i("div", { className: "divide-y divide-border/60 overflow-hidden rounded-control border border-border/60", children: [
1685
- x ? /* @__PURE__ */ i("div", { className: "space-y-1 px-3 py-2.5", children: [
1686
- /* @__PURE__ */ t("p", { className: "text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground", children: "Explorer cards" }),
1687
- /* @__PURE__ */ t("div", { className: "text-[12px] text-muted-foreground", children: m })
1688
- ] }) : null,
1689
- /* @__PURE__ */ i("div", { className: "space-y-1.5 px-3 py-2.5", children: [
1690
- /* @__PURE__ */ t("p", { className: "text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground", children: "SQL cards" }),
1691
- /* @__PURE__ */ t(
1692
- $t,
1693
- {
1694
- text: o,
1695
- ariaLabel: "Copy SQL control reference"
1696
- }
1697
- ),
1698
- y ? /* @__PURE__ */ t(
1699
- $t,
1700
- {
1701
- text: y,
1702
- ariaLabel: "Copy Jinja control reference"
1703
- }
1704
- ) : null,
1705
- /* @__PURE__ */ i("p", { className: "text-[12px] text-muted-foreground", children: [
1706
- d,
1707
- " ",
1708
- /* @__PURE__ */ t(
1709
- "a",
1710
- {
1711
- href: "https://docs.semaphor.cloud/docs/concepts/template-expressions",
1712
- target: "_blank",
1713
- rel: "noreferrer",
1714
- className: "underline underline-offset-2 hover:text-foreground",
1715
- children: "Template expressions docs"
1716
- }
1717
- ),
1718
- "."
1719
- ] })
1720
- ] })
1721
- ] })
1722
- ] }),
1723
- /* @__PURE__ */ t(
1724
- je,
1725
- {
1726
- secondary: /* @__PURE__ */ t(G, { type: "button", variant: "outline", size: "xs", onClick: l, children: "Back" }),
1727
- tertiary: /* @__PURE__ */ t(G, { type: "button", variant: "outline", size: "xs", onClick: s, children: "Cancel" }),
1728
- primary: /* @__PURE__ */ t(G, { type: "button", size: "xs", onClick: c, children: "Done" })
1729
- }
1730
- )
1731
- ] });
1732
- }
1733
- function Qa(e) {
1734
- const n = Ae(
1735
- e.scope,
1736
- e.existingControls,
1737
- e.reservedIds
1738
- ), a = e.type === n.type ? {
1739
- ...n,
1740
- label: Pe[e.type]
1741
- } : {
1742
- ...Jt({
1743
- controls: [
1744
- {
1745
- ...n,
1746
- label: Pe[e.type]
1747
- }
1748
- ],
1749
- controlId: n.id,
1750
- nextType: e.type
1751
- }).controls[0],
1752
- label: Pe[e.type]
1753
- };
1754
- return {
1755
- step: 2,
1756
- control: a,
1757
- defaultValue: Oe(a, void 0)
1758
- };
1759
- }
1760
- function Ir({
1761
- scope: e,
1762
- controls: n,
1763
- reservedControlIds: a,
1764
- defaultValues: o,
1765
- onChange: m,
1766
- emptyMessage: d,
1767
- initialCreateFlow: u = !1,
1768
- usageByControlId: l,
1769
- availableFieldChoices: s,
1770
- availableMetricChoices: c,
1771
- structuralParticipants: x,
1772
- structuralParticipantIdsByControlId: k,
1773
- card: y,
1774
- allowedControlTypes: f,
1775
- onCreateFlowActiveChange: N,
1776
- onCreateFlowComplete: S
1777
- }) {
1778
- const V = P(
1779
- () => new Set(a || []),
1780
- [a]
1781
- ), F = sa(e), K = Zn(e), [C, T] = Y(
1782
- null
1783
- ), [U, Z] = Y(
1784
- null
1785
- ), [p, I] = Y(
1786
- () => u ? {
1787
- step: 1,
1788
- control: Ae(e, n, Array.from(V))
1789
- } : null
1790
- ), $ = $e({}), D = $e(void 0), v = $e(u), h = P(() => {
1791
- const r = Ct({ scope: e, card: y });
1792
- if (!f)
1793
- return r;
1794
- const g = new Set(f);
1795
- return r.filter((b) => g.has(b.value));
1796
- }, [f, y, e]), E = ne(
1797
- (r) => {
1798
- const g = Ct({
1799
- scope: e,
1800
- card: y,
1801
- includeType: f ? void 0 : r
1802
- });
1803
- if (!f)
1804
- return g;
1805
- const b = new Set(f);
1806
- return g.filter((L) => b.has(L.value));
1807
- },
1808
- [f, y, e]
1809
- ), w = ne(
1810
- (r) => e === "dashboard" && (r === "field_selector" || r === "metric_selector"),
1811
- [e]
1812
- ), H = P(
1813
- () => p ? wt(
1814
- x || [],
1815
- p.control.type
1816
- ) : [],
1817
- [p, x]
1818
- ), _ = P(() => {
1819
- if (!p)
1820
- return {
1821
- fields: s || [],
1822
- metrics: c || []
1823
- };
1824
- if (!w(p.control.type))
1825
- return {
1826
- fields: s || [],
1827
- metrics: c || []
1828
- };
1829
- const r = p.selectedCardIds || [], g = Qe({
1830
- controlType: p.control.type,
1831
- participants: x || [],
1832
- selectedCardIds: r
1833
- });
1834
- return {
1835
- fields: p.control.type === "field_selector" ? g.choices.map((b) => ({
1836
- option: b,
1837
- target: g.fieldTargetMap[b.value]
1838
- })) : [],
1839
- metrics: p.control.type === "metric_selector" ? g.choices.map((b) => ({
1840
- option: b,
1841
- target: g.metricTargetMap[b.value]
1842
- })) : []
1843
- };
1844
- }, [
1845
- s,
1846
- c,
1847
- p,
1848
- w,
1849
- x
1850
- ]);
1851
- de(() => {
1852
- N == null || N(!!p);
1853
- }, [p, N]), de(() => {
1854
- const r = u && !v.current;
1855
- v.current = u, r && (I({
1856
- step: 1,
1857
- control: Ae(e, n, Array.from(V))
1858
- }), Z(null), T(null));
1859
- }, [n, u, V, e]);
1860
- const z = (r) => {
1861
- if (!w(r.type))
1862
- return {
1863
- fields: s || [],
1864
- metrics: c || []
1865
- };
1866
- const g = (k == null ? void 0 : k[r.id]) || [];
1867
- if (g.length === 0)
1868
- return {
1869
- fields: s || [],
1870
- metrics: c || []
1871
- };
1872
- const b = Qe({
1873
- controlType: r.type,
1874
- participants: x || [],
1875
- selectedCardIds: g
1876
- });
1877
- return {
1878
- fields: r.type === "field_selector" ? b.choices.map((L) => ({
1879
- option: L,
1880
- target: b.fieldTargetMap[L.value]
1881
- })) : [],
1882
- metrics: r.type === "metric_selector" ? b.choices.map((L) => ({
1883
- option: L,
1884
- target: b.metricTargetMap[L.value]
1885
- })) : []
1886
- };
1887
- }, B = (r) => {
1888
- if (!w(r.control.type))
1889
- return {
1890
- nextControl: r.control,
1891
- cardBindingsById: void 0
1892
- };
1893
- const g = (k == null ? void 0 : k[r.control.id]) || [], b = Qe({
1894
- controlType: r.control.type,
1895
- participants: x || [],
1896
- selectedCardIds: r.nextSelectedCardIds
1897
- }), L = ca({
1898
- control: r.control,
1899
- choices: b.choices
1900
- }), R = Object.fromEntries(
1901
- g.filter((M) => !r.nextSelectedCardIds.includes(M)).map((M) => [M, void 0])
1902
- );
1903
- return r.nextSelectedCardIds.length > 0 && L.source.kind === "manual" && L.source.options.length > 0 && Object.assign(
1904
- R,
1905
- Tt({
1906
- control: L,
1907
- participants: x || [],
1908
- selectedCardIds: r.nextSelectedCardIds,
1909
- matrixTargetIds: r.matrixTargetIds
1910
- })
1911
- ), {
1912
- nextControl: L,
1913
- cardBindingsById: R
1914
- };
1915
- }, j = ne(
1916
- (r, g = o, b = { type: "update" }) => {
1917
- const L = r.map((R) => (Ke({
1918
- control: R,
1919
- defaultValues: g
1920
- }), ea(
1921
- R
1922
- )));
1923
- m(L, g, b);
1924
- },
1925
- [o, m]
1926
- ), ee = (r, g) => {
1927
- const b = n.find(
1928
- (Q) => Q.id === r
1929
- );
1930
- let L = n.map((Q) => Q.id !== r ? Q : g(Q));
1931
- const R = L.find(
1932
- (Q) => Q.id === r
1933
- );
1934
- let M, O;
1935
- if (R && (!b || ia({ control: b }, { control: R })) && e === "dashboard" && (R.type === "field_selector" || R.type === "metric_selector")) {
1936
- const Q = (k == null ? void 0 : k[R.id]) || [], pe = B({
1937
- control: R,
1938
- nextSelectedCardIds: Q
1939
- });
1940
- L = L.map(
1941
- (le) => le.id === r ? pe.nextControl : le
1942
- ), M = pe.cardBindingsById, O = [R.id];
1943
- } else if (b && (!R || !da(R.type)) && e === "dashboard" && (b.type === "field_selector" || b.type === "metric_selector")) {
1944
- const Q = (k == null ? void 0 : k[b.id]) || [];
1945
- M = Object.fromEntries(
1946
- Q.map((pe) => [pe, void 0])
1947
- ), O = [b.id];
1948
- }
1949
- const W = L.find(
1950
- (Q) => Q.id === r
1951
- );
1952
- let X = o;
1953
- if (b && W) {
1954
- const Q = Ke({
1955
- control: b,
1956
- defaultValues: o
1957
- });
1958
- b.source.kind === "manual" && W.source.kind === "sql_query" && ($.current[r] = Q);
1959
- const pe = Q === void 0 && b.source.kind === "sql_query" && W.source.kind === "manual" ? $.current[r] : Q, le = Dt({
1960
- previousControl: b,
1961
- nextControl: W,
1962
- currentDefaultValue: pe
1963
- });
1964
- W.source.kind === "manual" && ($.current[r] = le), o && (X = { ...o }, le === void 0 ? delete X[r] : X[r] = le), L = L.map(
1965
- (gt) => gt.id === r ? { ...W, defaultValue: le } : gt
1966
- );
1967
- }
1968
- j(L, X, {
1969
- type: "update",
1970
- cardBindingsById: M,
1971
- affectedBindingControlIds: O
1972
- });
1973
- }, te = (r, g) => {
1974
- if (!g.trim())
1975
- return;
1976
- const b = ua(g);
1977
- if (b === r || V.has(b) || n.some(
1978
- (M) => M.id === b && M.id !== r
1979
- ))
1980
- return;
1981
- const L = n.map(
1982
- (M) => M.id === r ? { ...M, id: b } : M
1983
- );
1984
- if (!o) {
1985
- j(L, void 0, {
1986
- type: "rename",
1987
- oldId: r,
1988
- newId: b
1989
- });
1990
- return;
1991
- }
1992
- const R = { ...o };
1993
- Object.prototype.hasOwnProperty.call(R, r) && (R[b] = R[r], delete R[r]), j(L, R, {
1994
- type: "rename",
1995
- oldId: r,
1996
- newId: b
1997
- });
1998
- }, Be = (r) => {
1999
- const g = n.filter((L) => L.id !== r);
2000
- if (!o) {
2001
- j(g, void 0, { type: "remove", controlId: r });
2002
- return;
2003
- }
2004
- const b = { ...o };
2005
- delete b[r], j(g, b, { type: "remove", controlId: r });
2006
- }, We = ne(() => {
2007
- D.current = void 0, I({
2008
- step: 1,
2009
- control: Ae(e, n, Array.from(V))
2010
- }), Z(null), T(null);
2011
- }, [n, V, e]), oe = (r) => {
2012
- I(
2013
- (g) => g && (() => {
2014
- const b = r(g.control);
2015
- g.control.source.kind === "manual" && b.source.kind === "sql_query" && (D.current = g.defaultValue);
2016
- const L = g.defaultValue === void 0 && g.control.source.kind === "sql_query" && b.source.kind === "manual" ? D.current : g.defaultValue, R = Dt({
2017
- previousControl: g.control,
2018
- nextControl: b,
2019
- currentDefaultValue: L
2020
- });
2021
- return b.source.kind === "manual" && (D.current = R), {
2022
- ...g,
2023
- control: b,
2024
- defaultValue: R
2025
- };
2026
- })()
2027
- );
2028
- }, Ie = (r) => {
2029
- I(
2030
- (g) => g && (g.control.source.kind === "manual" && (D.current = r), {
2031
- ...g,
2032
- defaultValue: r
2033
- })
2034
- );
2035
- }, ue = (() => {
2036
- if (!p)
2037
- return !1;
2038
- if (p.step === 2 && w(p.control.type))
2039
- return (p.selectedCardIds || []).length > 0 && ta({
2040
- participants: x || [],
2041
- selectedCardIds: p.selectedCardIds || [],
2042
- control: p.control,
2043
- selected: p.matrixTargetIds
2044
- });
2045
- if (p.step !== 2 && p.step !== 3 || !p.control.label.trim())
2046
- return !1;
2047
- const g = p.control.source.kind === "sql_query" ? p.control : kt(p.control);
2048
- if (g.source.kind === "manual" && (na(g) && g.source.options.length === 0 || g.source.options.some(
2049
- (L) => L.label.trim().length === 0 || L.value.trim().length === 0
2050
- )))
2051
- return !1;
2052
- if (g.source.kind === "sql_query") {
2053
- const { connectionId: b, sql: L, valueColumn: R } = g.source;
2054
- return b.trim().length > 0 && L.trim().length > 0 && R.trim().length > 0;
2055
- }
2056
- return aa(
2057
- Oe(g, p.defaultValue)
2058
- );
2059
- })(), Ce = () => {
2060
- var M;
2061
- if (!p)
2062
- return;
2063
- const r = kt(p.control), g = la({
2064
- label: r.label,
2065
- fallbackId: r.id,
2066
- existingControls: n,
2067
- reservedIds: Array.from(V)
2068
- }), b = {
2069
- ...r,
2070
- id: g
2071
- }, L = e === "dashboard" && (b.type === "field_selector" || b.type === "metric_selector") && ((M = p.selectedCardIds) != null && M.length) ? Tt({
2072
- control: b,
2073
- participants: x || [],
2074
- selectedCardIds: p.selectedCardIds,
2075
- matrixTargetIds: p.matrixTargetIds
2076
- }) : void 0, R = Oe(
2077
- b,
2078
- p.defaultValue
2079
- );
2080
- I({
2081
- step: e === "dashboard" && (b.type === "field_selector" || b.type === "metric_selector") ? 4 : 3,
2082
- control: b,
2083
- defaultValue: R,
2084
- createdControlId: g,
2085
- selectedCardIds: p.selectedCardIds,
2086
- matrixTargetIds: p.matrixTargetIds,
2087
- cardBindingsById: L
2088
- });
2089
- }, we = ne(() => {
2090
- I(null);
2091
- }, []), ke = ne(() => {
2092
- if (!(p != null && p.createdControlId)) {
2093
- I(null);
2094
- return;
2095
- }
2096
- const r = p.control, g = p.createdControlId, b = Oe(
2097
- r,
2098
- p.defaultValue
2099
- );
2100
- if (o) {
2101
- const L = { ...o };
2102
- b === void 0 ? delete L[g] : L[g] = b, j(
2103
- [
2104
- ...n,
2105
- {
2106
- ...r,
2107
- defaultValue: b
2108
- }
2109
- ],
2110
- L,
2111
- {
2112
- type: "add",
2113
- cardBindingsById: p.cardBindingsById
2114
- }
2115
- );
2116
- } else
2117
- j(
2118
- [
2119
- ...n,
2120
- {
2121
- ...r,
2122
- defaultValue: b
2123
- }
2124
- ],
2125
- void 0,
2126
- {
2127
- type: "add",
2128
- cardBindingsById: p.cardBindingsById
2129
- }
2130
- );
2131
- Z(g), I(null), S == null || S();
2132
- }, [n, p, o, j, S]), xt = p ? w(p.control.type) ? ["Choose type", "Select cards", "Configure", "Finish"] : ["Choose type", "Configure", "Finish"] : [], Se = p != null && p.createdControlId ? `[[param.${p.createdControlId}]]` : p ? `[[param.${ra(p.control.label) || p.control.id}]]` : "", me = St({
2133
- controls: n,
2134
- defaultValues: o
2135
- }), A = p ? [...n, p.control] : n, ae = p ? St({
2136
- controls: A,
2137
- defaultValues: o,
2138
- overrides: [
2139
- {
2140
- controlId: p.control.id,
2141
- value: p.defaultValue
2142
- }
2143
- ]
2144
- }) : me;
2145
- return /* @__PURE__ */ i("div", { className: "space-y-4", children: [
2146
- p ? /* @__PURE__ */ i("div", { className: "space-y-4 pb-1", children: [
2147
- /* @__PURE__ */ t(
2148
- Ga,
2149
- {
2150
- currentStep: p.step,
2151
- labels: xt
2152
- }
2153
- ),
2154
- p.step === 1 && (() => {
2155
- const r = /* @__PURE__ */ new Set([
2156
- "grain_selector",
2157
- "aggregation_selector",
2158
- "field_selector",
2159
- "metric_selector"
2160
- ]), g = /* @__PURE__ */ new Set([
2161
- // Temporarily hide these from the add-control dialog while
2162
- // keeping the shared definitions for existing controls.
2163
- "date",
2164
- "text"
2165
- ]), b = h.filter(
2166
- (M) => !r.has(M.value) && !g.has(M.value)
2167
- ), L = h.filter(
2168
- (M) => r.has(M.value)
2169
- ), R = (M) => /* @__PURE__ */ i(
2170
- "button",
2171
- {
2172
- type: "button",
2173
- 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",
2174
- onClick: () => I(
2175
- Qa({
2176
- scope: e,
2177
- existingControls: n,
2178
- reservedIds: Array.from(V),
2179
- type: M.value
2180
- })
2181
- ),
2182
- children: [
2183
- /* @__PURE__ */ t("div", { className: "text-[13px] font-medium text-foreground", children: M.label }),
2184
- /* @__PURE__ */ t("p", { className: "mt-0.5 text-[12px] text-muted-foreground", children: M.description })
2185
- ]
2186
- },
2187
- M.value
2188
- );
2189
- return /* @__PURE__ */ i("div", { className: "space-y-4", children: [
2190
- e === "card" && (y == null ? void 0 : y.sql) == null ? /* @__PURE__ */ t("p", { className: "text-[12px] text-muted-foreground", children: "Explorer cards support displayed metric, group by field, aggregation, and time grain controls here." }) : null,
2191
- b.length > 0 && /* @__PURE__ */ i("div", { className: "space-y-1.5", children: [
2192
- /* @__PURE__ */ t("p", { className: "text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground", children: "Input controls" }),
2193
- /* @__PURE__ */ t("div", { className: "grid gap-1.5 sm:grid-cols-2", children: b.map(R) })
2194
- ] }),
2195
- L.length > 0 && /* @__PURE__ */ i("div", { className: "space-y-1.5", children: [
2196
- /* @__PURE__ */ t("p", { className: "text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground", children: "Data-driven controls" }),
2197
- /* @__PURE__ */ t("div", { className: "grid gap-1.5 sm:grid-cols-2", children: L.map(R) })
2198
- ] }),
2199
- /* @__PURE__ */ t(
2200
- je,
2201
- {
2202
- secondary: /* @__PURE__ */ t(
2203
- G,
2204
- {
2205
- type: "button",
2206
- variant: "outline",
2207
- size: "xs",
2208
- onClick: we,
2209
- children: "Back to controls"
2210
- }
2211
- )
2212
- }
2213
- )
2214
- ] });
2215
- })(),
2216
- p.step === 2 && w(p.control.type) && /* @__PURE__ */ i("div", { className: "space-y-3", children: [
2217
- /* @__PURE__ */ i("div", { className: "space-y-3", children: [
2218
- /* @__PURE__ */ t(
2219
- ln,
2220
- {
2221
- control: p.control,
2222
- onChange: (r) => oe((g) => ({
2223
- ...g,
2224
- label: r
2225
- }))
2226
- }
2227
- ),
2228
- /* @__PURE__ */ t("p", { className: "text-[12px] text-muted-foreground", children: "Choose which cards should respond to this shared control." })
2229
- ] }),
2230
- H.length === 0 ? /* @__PURE__ */ t("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__ */ t("div", { className: "space-y-1 rounded-control border border-border/60 bg-background p-2", children: H.map((r) => {
2231
- const g = (p.selectedCardIds || []).includes(r.cardId);
2232
- return /* @__PURE__ */ i(
2233
- "label",
2234
- {
2235
- className: "flex items-start gap-2 rounded-control px-1.5 py-1 text-[13px] hover:bg-muted/40",
2236
- children: [
2237
- /* @__PURE__ */ t(
2238
- Ue,
2239
- {
2240
- checked: g,
2241
- onCheckedChange: (b) => I(
2242
- (L) => L && {
2243
- ...L,
2244
- selectedCardIds: b === !0 ? [
2245
- ...L.selectedCardIds || [],
2246
- r.cardId
2247
- ] : (L.selectedCardIds || []).filter(
2248
- (R) => R !== r.cardId
2249
- )
2250
- }
2251
- )
2252
- }
2253
- ),
2254
- /* @__PURE__ */ i("div", { className: "min-w-0", children: [
2255
- /* @__PURE__ */ t("div", { className: "font-medium text-foreground", children: r.title }),
2256
- /* @__PURE__ */ t("div", { className: "text-[12px] text-muted-foreground", children: p.control.type === "field_selector" ? `${r.fieldChoices.length} compatible group-by fields` : `${r.metricChoices.length} compatible metrics` })
2257
- ] })
2258
- ]
2259
- },
2260
- r.cardId
2261
- );
2262
- }) }),
2263
- /* @__PURE__ */ t(
2264
- vt,
2265
- {
2266
- participants: H,
2267
- selectedCardIds: p.selectedCardIds || [],
2268
- control: p.control,
2269
- selected: p.matrixTargetIds,
2270
- onChange: (r, g) => I((b) => b && { ...b, matrixTargetIds: { ...b.matrixTargetIds, [r]: g } })
2271
- }
2272
- ),
2273
- /* @__PURE__ */ t(
2274
- je,
2275
- {
2276
- secondary: /* @__PURE__ */ t(
2277
- G,
2278
- {
2279
- type: "button",
2280
- variant: "outline",
2281
- size: "xs",
2282
- onClick: () => I(
2283
- (r) => r && {
2284
- ...r,
2285
- step: 1,
2286
- selectedCardIds: []
2287
- }
2288
- ),
2289
- children: "Back"
2290
- }
2291
- ),
2292
- primary: /* @__PURE__ */ t(
2293
- G,
2294
- {
2295
- type: "button",
2296
- size: "xs",
2297
- onClick: () => I(
2298
- (r) => r && {
2299
- ...r,
2300
- step: 3
2301
- }
2302
- ),
2303
- disabled: !ue,
2304
- children: "Next"
2305
- }
2306
- )
2307
- }
2308
- )
2309
- ] }),
2310
- p.step === 2 && !w(p.control.type) && /* @__PURE__ */ t(
2311
- Lt,
2312
- {
2313
- control: p.control,
2314
- defaultValue: p.defaultValue,
2315
- availableFieldChoices: _.fields,
2316
- availableMetricChoices: _.metrics,
2317
- previewControlDefinitions: A,
2318
- previewControlValues: ae,
2319
- onControlChange: (r) => oe(() => r),
2320
- onLabelChange: (r) => oe((g) => ({
2321
- ...g,
2322
- label: r
2323
- })),
2324
- onDefaultValueChange: Ie,
2325
- onBack: () => I(
2326
- (r) => r && {
2327
- ...r,
2328
- step: 1
2329
- }
2330
- ),
2331
- onNext: Ce,
2332
- nextDisabled: !ue
2333
- }
2334
- ),
2335
- p.step === 3 && w(p.control.type) && /* @__PURE__ */ t(
2336
- Lt,
2337
- {
2338
- control: p.control,
2339
- defaultValue: p.defaultValue,
2340
- availableFieldChoices: _.fields,
2341
- availableMetricChoices: _.metrics,
2342
- previewControlDefinitions: A,
2343
- previewControlValues: ae,
2344
- onControlChange: (r) => oe(() => r),
2345
- onLabelChange: (r) => oe((g) => ({
2346
- ...g,
2347
- label: r
2348
- })),
2349
- onDefaultValueChange: Ie,
2350
- onBack: () => I(
2351
- (r) => r && {
2352
- ...r,
2353
- step: 2
2354
- }
2355
- ),
2356
- onNext: Ce,
2357
- nextDisabled: !ue
2358
- }
2359
- ),
2360
- p.step === 3 && !w(p.control.type) && /* @__PURE__ */ t(
2361
- At,
2362
- {
2363
- control: p.control,
2364
- scope: e,
2365
- createdReference: Se,
2366
- explorerContent: /* @__PURE__ */ i(he, { children: [
2367
- "Open the card and use",
2368
- " ",
2369
- /* @__PURE__ */ t("span", { className: "font-medium text-foreground", children: "Settings → Controls" }),
2370
- " ",
2371
- "to choose what this control changes."
2372
- ] }),
2373
- sqlDescription: "Reference this control directly in the SQL editor.",
2374
- onBack: () => I(
2375
- (r) => r && {
2376
- ...r,
2377
- step: 2
2378
- }
2379
- ),
2380
- onCancel: we,
2381
- onDone: ke
2382
- }
2383
- ),
2384
- p.step === 4 && w(p.control.type) && /* @__PURE__ */ t(
2385
- At,
2386
- {
2387
- control: p.control,
2388
- scope: e,
2389
- createdReference: Se,
2390
- summaryDetail: /* @__PURE__ */ i(he, { children: [
2391
- "Used by ",
2392
- (p.selectedCardIds || []).length,
2393
- " selected card",
2394
- (p.selectedCardIds || []).length === 1 ? "" : "s"
2395
- ] }),
2396
- explorerContent: /* @__PURE__ */ t(he, { children: "Selected cards have been set up to respond to this control automatically." }),
2397
- sqlDescription: "SQL cards can still reference this control directly in the SQL editor.",
2398
- onBack: () => I(
2399
- (r) => r && {
2400
- ...r,
2401
- step: 3
2402
- }
2403
- ),
2404
- onCancel: we,
2405
- onDone: ke
2406
- }
2407
- )
2408
- ] }) : null,
2409
- !p && n.length === 0 ? /* @__PURE__ */ t("div", { className: "rounded-md border border-dashed p-3 text-sm text-muted-foreground", children: d }) : null,
2410
- !p && n.map((r) => {
2411
- const g = z(r), b = l == null ? void 0 : l[r.id], L = Ke({
2412
- control: r,
2413
- defaultValues: o
2414
- }), R = U === r.id, M = "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";
2415
- return /* @__PURE__ */ i(
2416
- "div",
2417
- {
2418
- className: "rounded-control border border-border/60",
2419
- children: [
2420
- /* @__PURE__ */ i("div", { className: "flex items-center gap-2 px-3 py-2.5", children: [
2421
- /* @__PURE__ */ i(
2422
- "button",
2423
- {
2424
- type: "button",
2425
- className: "flex min-w-0 flex-1 items-start gap-2 rounded-control text-left focus:outline-none focus-visible:bg-muted/40",
2426
- onClick: () => Z(
2427
- (O) => O === r.id ? null : r.id
2428
- ),
2429
- children: [
2430
- R ? /* @__PURE__ */ t(_e, { className: "mt-0.5 h-3.5 w-3.5 shrink-0 text-muted-foreground" }) : /* @__PURE__ */ t(Te, { className: "mt-0.5 h-3.5 w-3.5 shrink-0 text-muted-foreground" }),
2431
- /* @__PURE__ */ i("div", { className: "min-w-0", children: [
2432
- /* @__PURE__ */ i("div", { className: "flex flex-wrap items-center gap-1.5", children: [
2433
- /* @__PURE__ */ t("span", { className: "truncate text-[13px] font-medium text-foreground", children: r.label || "Untitled control" }),
2434
- /* @__PURE__ */ t("span", { className: M, children: Ht(r.type).label }),
2435
- /* @__PURE__ */ t("span", { className: M, children: Yt(e, r.placement) })
2436
- ] }),
2437
- /* @__PURE__ */ i("div", { className: "mt-0.5 text-[12px] text-muted-foreground", children: [
2438
- Xt(r),
2439
- b != null && b.status ? ` · ${b.status}` : ""
2440
- ] })
2441
- ] })
2442
- ]
2443
- }
2444
- ),
2445
- /* @__PURE__ */ t(
2446
- G,
2447
- {
2448
- type: "button",
2449
- size: "xs",
2450
- variant: "ghost",
2451
- className: "h-7 w-7 shrink-0 p-0 text-muted-foreground",
2452
- onClick: () => Be(r.id),
2453
- "aria-label": `Remove ${r.label}`,
2454
- children: /* @__PURE__ */ t(zt, { className: "h-3.5 w-3.5" })
2455
- }
2456
- )
2457
- ] }),
2458
- R && /* @__PURE__ */ i("div", { className: "space-y-4 border-t border-border/60 px-3 py-3", children: [
2459
- /* @__PURE__ */ i("div", { className: "grid gap-3 md:grid-cols-3", children: [
2460
- /* @__PURE__ */ i("div", { className: "flex flex-col gap-1.5", children: [
2461
- /* @__PURE__ */ t(ie, { className: "text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground", children: "Label" }),
2462
- /* @__PURE__ */ t(
2463
- Ne,
2464
- {
2465
- size: "xs",
2466
- value: r.label,
2467
- placeholder: "Control label",
2468
- onChange: (O) => ee(r.id, (W) => ({
2469
- ...W,
2470
- label: O.target.value
2471
- }))
2472
- }
2473
- )
2474
- ] }),
2475
- /* @__PURE__ */ i("div", { className: "flex flex-col gap-1.5", children: [
2476
- /* @__PURE__ */ t(ie, { className: "text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground", children: "Type" }),
2477
- /* @__PURE__ */ i(
2478
- xe,
2479
- {
2480
- value: r.type,
2481
- onValueChange: (O) => {
2482
- const W = Jt({
2483
- controls: n,
2484
- controlId: r.id,
2485
- nextType: O,
2486
- defaultValues: o
2487
- });
2488
- j(W.controls, W.defaultValues);
2489
- },
2490
- children: [
2491
- /* @__PURE__ */ t(ge, { size: "xs", children: /* @__PURE__ */ t(be, {}) }),
2492
- /* @__PURE__ */ t(ve, { children: E(r.type).map(
2493
- (O) => /* @__PURE__ */ t(
2494
- re,
2495
- {
2496
- value: O.value,
2497
- children: O.label
2498
- },
2499
- O.value
2500
- )
2501
- ) })
2502
- ]
2503
- }
2504
- )
2505
- ] }),
2506
- /* @__PURE__ */ i("div", { className: "flex flex-col gap-1.5", children: [
2507
- /* @__PURE__ */ t(ie, { className: "text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground", children: "Show in" }),
2508
- /* @__PURE__ */ i(
2509
- xe,
2510
- {
2511
- value: r.placement || K,
2512
- onValueChange: (O) => ee(r.id, (W) => ({
2513
- ...W,
2514
- placement: O
2515
- })),
2516
- children: [
2517
- /* @__PURE__ */ t(ge, { size: "xs", children: /* @__PURE__ */ t(be, {}) }),
2518
- /* @__PURE__ */ t(ve, { children: F.map((O) => /* @__PURE__ */ t(re, { value: O.value, children: O.label }, O.value)) })
2519
- ]
2520
- }
2521
- )
2522
- ] })
2523
- ] }),
2524
- w(r.type) ? /* @__PURE__ */ i(he, { children: [
2525
- /* @__PURE__ */ t(
2526
- On,
2527
- {
2528
- type: r.type,
2529
- participants: wt(
2530
- x || [],
2531
- r.type
2532
- ).map((O) => ({
2533
- cardId: O.cardId,
2534
- title: O.title,
2535
- choiceCount: r.type === "field_selector" ? O.fieldChoices.length : O.metricChoices.length
2536
- })),
2537
- selectedCardIds: (k == null ? void 0 : k[r.id]) || [],
2538
- onChange: (O) => {
2539
- const W = B({
2540
- control: r,
2541
- nextSelectedCardIds: O
2542
- }), X = n.map(
2543
- (Q) => Q.id === r.id ? W.nextControl : Q
2544
- );
2545
- j(X, o, {
2546
- type: "update",
2547
- cardBindingsById: W.cardBindingsById
2548
- });
2549
- }
2550
- }
2551
- ),
2552
- /* @__PURE__ */ t(
2553
- vt,
2554
- {
2555
- participants: x || [],
2556
- selectedCardIds: (k == null ? void 0 : k[r.id]) || [],
2557
- control: r,
2558
- onChange: (O, W) => {
2559
- const X = B({
2560
- control: r,
2561
- nextSelectedCardIds: (k == null ? void 0 : k[r.id]) || [],
2562
- matrixTargetIds: { [O]: W }
2563
- });
2564
- j(
2565
- n.map((Q) => Q.id === r.id ? X.nextControl : Q),
2566
- o,
2567
- { type: "update", cardBindingsById: X.cardBindingsById }
2568
- );
2569
- }
2570
- }
2571
- )
2572
- ] }) : null,
2573
- /* @__PURE__ */ t(
2574
- Mt,
2575
- {
2576
- control: r,
2577
- availableFieldChoices: g.fields,
2578
- availableMetricChoices: g.metrics,
2579
- previewControlDefinitions: n,
2580
- previewControlValues: me,
2581
- controlLifecycle: "edit",
2582
- onChange: (O) => ee(r.id, () => O)
2583
- }
2584
- ),
2585
- r.initialValueStrategy === "saved_default" && /* @__PURE__ */ t(
2586
- qt,
2587
- {
2588
- control: r,
2589
- value: L,
2590
- allowNoDefault: !0,
2591
- allowCardDefault: !0,
2592
- previewControlDefinitions: n,
2593
- previewControlValues: me,
2594
- onChange: (O) => {
2595
- const W = n.map(
2596
- (X) => X.id === r.id ? { ...X, defaultValue: O } : X
2597
- );
2598
- if (r.source.kind === "manual" && ($.current[r.id] = O), o) {
2599
- const X = { ...o };
2600
- O === void 0 ? delete X[r.id] : X[r.id] = O, j(W, X);
2601
- return;
2602
- }
2603
- j(W, void 0);
2604
- }
2605
- }
2606
- ),
2607
- /* @__PURE__ */ i(
2608
- _n,
2609
- {
2610
- open: C === r.id,
2611
- onOpenChange: (O) => T(O ? r.id : null),
2612
- children: [
2613
- /* @__PURE__ */ t(Fn, { asChild: !0, children: /* @__PURE__ */ i(
2614
- G,
2615
- {
2616
- type: "button",
2617
- variant: "ghost",
2618
- size: "xs",
2619
- className: "-ml-2 gap-1 text-muted-foreground hover:text-foreground",
2620
- children: [
2621
- C === r.id ? /* @__PURE__ */ t(_e, { className: "h-3.5 w-3.5" }) : /* @__PURE__ */ t(Te, { className: "h-3.5 w-3.5" }),
2622
- "Advanced"
2623
- ]
2624
- }
2625
- ) }),
2626
- /* @__PURE__ */ i(Vn, { className: "space-y-3 pt-2", children: [
2627
- /* @__PURE__ */ i("div", { className: "grid gap-3 md:grid-cols-2", children: [
2628
- /* @__PURE__ */ i("div", { className: "flex flex-col gap-1.5", children: [
2629
- /* @__PURE__ */ t(ie, { className: "text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground", children: "Variable name" }),
2630
- /* @__PURE__ */ t(
2631
- Rn,
2632
- {
2633
- controlId: r.id,
2634
- onCommit: (O) => te(r.id, O)
2635
- },
2636
- r.id
2637
- )
2638
- ] }),
2639
- /* @__PURE__ */ i("div", { className: "flex flex-col gap-1.5", children: [
2640
- /* @__PURE__ */ t(ie, { className: "text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground", children: "Initial value" }),
2641
- /* @__PURE__ */ i(
2642
- xe,
2643
- {
2644
- value: r.initialValueStrategy,
2645
- onValueChange: (O) => ee(r.id, (W) => ({
2646
- ...W,
2647
- initialValueStrategy: O
2648
- })),
2649
- children: [
2650
- /* @__PURE__ */ t(ge, { size: "xs", children: /* @__PURE__ */ t(be, {}) }),
2651
- /* @__PURE__ */ t(ve, { children: oa.map((O) => /* @__PURE__ */ t(
2652
- re,
2653
- {
2654
- value: O.value,
2655
- children: O.label
2656
- },
2657
- O.value
2658
- )) })
2659
- ]
2660
- }
2661
- )
2662
- ] })
2663
- ] }),
2664
- /* @__PURE__ */ t(
2665
- En,
2666
- {
2667
- control: r,
2668
- onChange: (O) => ee(r.id, () => O)
2669
- }
2670
- )
2671
- ] })
2672
- ]
2673
- }
2674
- )
2675
- ] })
2676
- ]
2677
- },
2678
- r.id
2679
- );
2680
- }),
2681
- !p && /* @__PURE__ */ i(
2682
- G,
2683
- {
2684
- type: "button",
2685
- variant: "outline",
2686
- size: "xs",
2687
- onClick: We,
2688
- children: [
2689
- /* @__PURE__ */ t(Ve, { className: "h-3.5 w-3.5" }),
2690
- "Add control"
2691
- ]
2692
- }
2693
- )
2694
- ] });
2695
- }
2696
- function Lr(e) {
2697
- const {
2698
- open: n,
2699
- onOpenChange: a,
2700
- initialCreateFlowActive: o = !1,
2701
- dismissMode: m = "passive"
2702
- } = e, d = n !== void 0, [u, l] = Y(!1), [s, c] = Y(
2703
- o
2704
- ), x = d ? n : u, k = ne(
2705
- (N) => {
2706
- !N && s && m === "passive" || (d || l(N), N || c(!1), a == null || a(N));
2707
- },
2708
- [d, s, m, a]
2709
- ), y = ne(() => {
2710
- d || l(!1), c(!1), a == null || a(!1);
2711
- }, [d, a]);
2712
- de(() => {
2713
- x || c(!1);
2714
- }, [x]);
2715
- const f = ne(
2716
- (N) => {
2717
- s && N.preventDefault();
2718
- },
2719
- [s]
2720
- );
2721
- return {
2722
- forceClose: y,
2723
- handleOpenChange: k,
2724
- isCreateFlowActive: s,
2725
- preventPassiveDismissDuringCreate: f,
2726
- resolvedOpen: x,
2727
- setIsCreateFlowActive: c
2728
- };
2729
- }
2730
- function dn(e) {
2731
- const {
2732
- relativeMeta: n,
2733
- latestValue: a,
2734
- ...o
2735
- } = e;
2736
- return o;
2737
- }
2738
- function pt(e, n) {
2739
- const a = dn(e);
2740
- return n.relativeMeta ? { ...a, value: n.value, relativeMeta: n.relativeMeta } : { ...a, value: n.value };
2741
- }
2742
- function Ka(e, n) {
2743
- const a = n === "in" || n === "not in" || n === "between" || n === "not between" ? [] : n === "isNull" || n === "isNotNull" ? null : "";
2744
- return pt({ ...e, operator: n }, { value: a });
2745
- }
2746
- function Pa(e, n) {
2747
- const a = qe(n.dataType) === "date";
2748
- return pt(
2749
- { ...e, field: n, operator: a ? "between" : "=" },
2750
- { value: "" }
2751
- );
2752
- }
2753
- function Ha({
2754
- initialFilters: e,
2755
- availableFields: n,
2756
- onChange: a
2757
- } = {}) {
2758
- const [o, m] = Y(
2759
- e || {
2760
- id: `group-${Date.now()}`,
2761
- logicalOperator: "AND",
2762
- negate: !1,
2763
- conditions: [],
2764
- groups: []
2765
- }
2766
- ), d = (I) => {
2767
- m(I), a == null || a(I);
2768
- };
2769
- se((I) => I.card.dataSource);
2770
- const { filterableFields: u, isLoading: l } = Mn(), s = n || u || [], c = {
2771
- id: "default",
2772
- qualifiedFieldName: "default",
2773
- name: "default",
2774
- dataType: "string",
2775
- label: "Default",
2776
- entityId: "default",
2777
- entityName: "Default",
2778
- entityType: "table"
2779
- }, x = (I) => {
2780
- const $ = (D) => {
2781
- if (D.id === I) {
2782
- const v = s[0] || c, h = qe(v.dataType) === "date";
2783
- return {
2784
- ...D,
2785
- conditions: [
2786
- ...D.conditions,
2787
- {
2788
- id: `condition-${Date.now()}`,
2789
- field: v,
2790
- operator: h ? "between" : "=",
2791
- value: h ? [] : ""
2792
- }
2793
- ]
2794
- };
2795
- }
2796
- return {
2797
- ...D,
2798
- groups: D.groups.map($)
2799
- };
2800
- };
2801
- d($(o));
2802
- }, k = (I) => {
2803
- const $ = (D) => {
2804
- if (D.id === I) {
2805
- const v = s[0] || c, h = qe(v.dataType) === "date";
2806
- return {
2807
- ...D,
2808
- groups: [
2809
- ...D.groups,
2810
- {
2811
- id: `group-${Date.now()}`,
2812
- logicalOperator: "AND",
2813
- negate: !1,
2814
- conditions: [
2815
- {
2816
- id: `condition-${Date.now()}`,
2817
- field: v,
2818
- operator: h ? "between" : "=",
2819
- value: h ? [] : ""
2820
- }
2821
- ],
2822
- groups: []
2823
- }
2824
- ]
2825
- };
2826
- }
2827
- return {
2828
- ...D,
2829
- groups: D.groups.map($)
2830
- };
2831
- };
2832
- d($(o));
2833
- }, y = (I, $) => {
2834
- const D = (v) => v.id === I ? {
2835
- ...v,
2836
- conditions: v.conditions.filter((h) => h.id !== $)
2837
- } : {
2838
- ...v,
2839
- groups: v.groups.map(D)
2840
- };
2841
- d(D(o));
2842
- }, f = (I, $) => {
2843
- const D = (v) => v.id === I ? {
2844
- ...v,
2845
- groups: v.groups.filter((h) => h.id !== $)
2846
- } : {
2847
- ...v,
2848
- groups: v.groups.map(D)
2849
- };
2850
- d(D(o));
2851
- }, N = (I, $, D) => {
2852
- const v = (h) => h.id === I ? {
2853
- ...h,
2854
- conditions: h.conditions.map(
2855
- (E) => E.id === $ ? D(E) : E
2856
- )
2857
- } : {
2858
- ...h,
2859
- groups: h.groups.map(v)
2860
- };
2861
- d(v(o));
2862
- }, S = (I, $, D) => N(I, $, (v) => ({
2863
- ..."value" in D || "operator" in D || "field" in D ? dn(v) : v,
2864
- ...D
2865
- })), V = (I, $, D) => N(I, $, () => D), F = qn(), K = (I, $) => {
2866
- const D = (v) => v.id === I ? {
2867
- ...v,
2868
- logicalOperator: $
2869
- } : {
2870
- ...v,
2871
- groups: v.groups.map(D)
2872
- };
2873
- d(D(o));
2874
- }, C = (I, $) => {
2875
- const D = (v) => v.id === I ? {
2876
- ...v,
2877
- negate: $
2878
- } : {
2879
- ...v,
2880
- groups: v.groups.map(D)
2881
- };
2882
- d(D(o));
2883
- }, T = (I, $, D) => {
2884
- const v = (h) => h.id === I ? {
2885
- ...h,
2886
- conditions: yt(h.conditions, $, D)
2887
- } : {
2888
- ...h,
2889
- groups: h.groups.map(v)
2890
- };
2891
- d(v(o));
2892
- }, U = (I, $, D) => {
2893
- const v = (h) => h.id === I ? {
2894
- ...h,
2895
- groups: yt(h.groups, $, D)
2896
- } : {
2897
- ...h,
2898
- groups: h.groups.map(v)
2899
- };
2900
- d(v(o));
2901
- }, Z = (I) => {
2902
- if (!I || I.conditions.length === 0 && I.groups.length === 0)
2903
- return "-- No filters defined";
2904
- const $ = (v) => {
2905
- let h = "";
2906
- typeof v.field == "object" ? h = v.field.entityName ? `${v.field.entityName}.${v.field.name}` : v.field.name : h = String(v.field);
2907
- const E = v.operator;
2908
- let w = v.value;
2909
- if (v.latestValue && E === "=")
2910
- return `${h} = ${jt} /* the latest value each time the card runs */`;
2911
- const H = Zt(v.relativeMeta);
2912
- if (H && va(E) && en(E, H)) {
2913
- const _ = Na(E, H), { label: z, range: B } = Nt(H, {
2914
- tz: (F == null ? void 0 : F.tz) ?? "UTC",
2915
- weekStart: (F == null ? void 0 : F.weekStart) ?? 1,
2916
- anchor: (F == null ? void 0 : F.anchor) ?? "now"
2917
- }), j = _ ? Ca(_) : z;
2918
- if (B) {
2919
- const [ee] = tn(E, [B.start, B.end]);
2920
- return `${h} ${E} '${ee.toISOString()}' /* ${j}: the date updates each time the card runs */`;
2921
- }
2922
- return `${h} ${E} ${j} /* the date follows your calendar each time the card runs */`;
2923
- }
2924
- if (H && (E === "between" || E === "not between")) {
2925
- const _ = E === "between" ? "BETWEEN" : "NOT BETWEEN", { label: z, range: B } = Nt(H, {
2926
- tz: (F == null ? void 0 : F.tz) ?? "UTC",
2927
- weekStart: (F == null ? void 0 : F.weekStart) ?? 1,
2928
- anchor: (F == null ? void 0 : F.anchor) ?? "now"
2929
- });
2930
- return B ? `${h} ${_} '${B.start.toISOString()}' AND '${B.end.toISOString()}' /* ${z}: dates update each time the card runs */` : nn(H).dataAnchored ? `${h} ${_} ${z} /* dates count back from the latest data each time the card runs */` : `${h} ${_} ${z} /* dates follow your calendar each time the card runs */`;
2931
- }
2932
- if (v.field.dataType === "string" && !["in", "not in"].includes(v.operator))
2933
- typeof w == "string" ? w = `'${w}'` : Array.isArray(w) && (w = `'${w.join(", ")}'`);
2934
- else if (v.field.dataType === "date" || v.field.dataType === "datetime" || v.field.dataType === "timestamp")
2935
- if (v.operator === "between" && Array.isArray(w) && w.length === 2) {
2936
- const _ = w[0] ? `'${w[0]}'` : "NULL", z = w[1] ? `'${w[1]}'` : "NULL";
2937
- return `${h} BETWEEN ${_} AND ${z}`;
2938
- } else if ((v.operator === "in" || v.operator === "not in") && Array.isArray(w)) {
2939
- const _ = w.map((z) => z ? `'${z}'` : "NULL").join(", ");
2940
- return `${h} ${E} (${_})`;
2941
- } else typeof w == "string" || w instanceof Date ? w = `'${w}'` : Array.isArray(w) && w.length > 0 && (w = `'${w[0]}'`);
2942
- else if (["in", "not in"].includes(v.operator)) {
2943
- let _ = [];
2944
- Array.isArray(w) ? _ = w.map(
2945
- (z) => typeof z == "string" ? `'${z}'` : String(z)
2946
- ) : typeof w == "string" ? _ = w.split(",").map((z) => {
2947
- const B = z.trim();
2948
- return v.field.dataType === "string" ? `'${B}'` : B;
2949
- }) : typeof w == "number" && (_ = [String(w)]), w = `(${_.join(", ")})`;
2950
- }
2951
- switch (E) {
2952
- case "contains":
2953
- return typeof w == "string" ? `${h} LIKE '%${w.replace(/'/g, "")}'` : `${h} LIKE '%${String(w)}'`;
2954
- case "startsWith":
2955
- return typeof w == "string" ? `${h} LIKE '${w.replace(/'/g, "")}%'` : `${h} LIKE '${String(w)}%'`;
2956
- case "endsWith":
2957
- return typeof w == "string" ? `${h} LIKE '%${w.replace(/'/g, "")}'` : `${h} LIKE '%${String(w)}'`;
2958
- case "isNull":
2959
- return `${h} IS NULL`;
2960
- case "isNotNull":
2961
- return `${h} IS NOT NULL`;
2962
- default:
2963
- return `${h} ${E} ${w}`;
2964
- }
2965
- }, D = (v) => {
2966
- const h = v.conditions.map($), E = v.groups.map(
2967
- (z) => D(z)
2968
- ), w = [...h, ...E].filter(Boolean);
2969
- if (w.length === 0) return "";
2970
- const H = w.join(` ${v.logicalOperator} `), _ = w.length > 1 ? `(${H})` : H;
2971
- return v.negate ? `NOT ${_}` : _;
2972
- };
2973
- return D(I);
2974
- }, p = o.conditions.length > 0 || o.groups.length > 0;
2975
- return {
2976
- currentFilters: o,
2977
- setCurrentFilters: d,
2978
- availableFields: s,
2979
- isLoading: l,
2980
- addCondition: x,
2981
- addGroup: k,
2982
- removeCondition: y,
2983
- removeGroup: f,
2984
- updateConditionFields: S,
2985
- replaceCondition: V,
2986
- updateGroupOperator: K,
2987
- updateGroupNegate: C,
2988
- reorderConditions: T,
2989
- reorderGroups: U,
2990
- generateSQLPreview: Z,
2991
- hasAnyFilters: p
2992
- };
2993
- }
2994
- function Ya({
2995
- children: e,
2996
- className: n,
2997
- delayDuration: a
2998
- }) {
2999
- return /* @__PURE__ */ t(at, { children: /* @__PURE__ */ i(rt, { delayDuration: a, children: [
3000
- /* @__PURE__ */ t(st, { asChild: !0, children: /* @__PURE__ */ t(
3001
- "div",
3002
- {
3003
- className: q(
3004
- "w-[200px] overflow-hidden text-ellipsis whitespace-nowrap text-sm",
3005
- n
3006
- ),
3007
- children: e
3008
- }
3009
- ) }),
3010
- /* @__PURE__ */ t(ot, { children: e })
3011
- ] }) });
3012
- }
3013
- function Xa({
3014
- value: e,
3015
- onValueChange: n,
3016
- availableFields: a,
3017
- placeholder: o = "Select field",
3018
- className: m
3019
- }) {
3020
- const [d, u] = bt.useState(!1), l = bt.useMemo(
3021
- () => new Set(e ? [e.id] : []),
3022
- [e]
3023
- ), s = e ? ma(e) : null;
3024
- return /* @__PURE__ */ i(lt, { modal: !0, open: d, onOpenChange: u, children: [
3025
- /* @__PURE__ */ t(it, { asChild: !0, children: /* @__PURE__ */ i(
3026
- G,
3027
- {
3028
- variant: "outline",
3029
- size: "xs",
3030
- role: "combobox",
3031
- "aria-expanded": d,
3032
- title: e ? `${e.entityName}.${e.name}` : void 0,
3033
- className: q(
3034
- "min-w-0 justify-between gap-1.5 font-normal",
3035
- !e && "text-muted-foreground",
3036
- m
3037
- ),
3038
- children: [
3039
- s ? /* @__PURE__ */ t(Ya, { className: "w-auto min-w-0 flex-1 text-left text-[12px]", children: s }) : /* @__PURE__ */ t("span", { className: "min-w-0 flex-1 truncate text-left", children: o }),
3040
- /* @__PURE__ */ t(jn, { className: "h-3.5 w-3.5 shrink-0 opacity-50" })
3041
- ]
3042
- }
3043
- ) }),
3044
- /* @__PURE__ */ t(
3045
- dt,
3046
- {
3047
- className: "flex w-80 flex-col rounded-control p-1.5",
3048
- align: "start",
3049
- onOpenAutoFocus: (c) => {
3050
- var x, k;
3051
- c.preventDefault(), (k = (x = c.currentTarget) == null ? void 0 : x.querySelector('input[type="text"]')) == null || k.focus();
3052
- },
3053
- children: /* @__PURE__ */ t(
3054
- Un,
3055
- {
3056
- fields: a,
3057
- selectedIds: l,
3058
- onSelect: (c) => {
3059
- n(c), u(!1);
3060
- },
3061
- density: "compact",
3062
- listLabel: "Fields",
3063
- listClassName: "max-h-80"
3064
- }
3065
- )
3066
- }
3067
- )
3068
- ] });
3069
- }
3070
- function cn(e, n) {
3071
- const a = se((c) => c.card.dataSource), o = se(
3072
- (c) => c.card.connectionId
3073
- ), m = se(
3074
- (c) => c.selectedConnectionId
3075
- ), { dataSource: d, connectionId: u } = n ? It(n) : It({ dataSource: a, connectionId: o }, m), l = P(
3076
- () => ({
3077
- id: `card-filter-option:${e.id}`,
3078
- ...pa(e, { dataSource: d, connectionId: u })
3079
- }),
3080
- [u, d, e]
3081
- ), s = P(
3082
- () => Gn({ filter: l }),
3083
- [l]
3084
- );
3085
- return Bn(l, {
3086
- inputContext: s,
3087
- currentSelectionPolicy: "exclude"
3088
- });
3089
- }
3090
- function Ja({
3091
- field: e,
3092
- source: n,
3093
- selected: a,
3094
- onChange: o,
3095
- placeholder: m = "Select values…",
3096
- className: d
3097
- }) {
3098
- const [u, l] = Fe.useState(!1), s = cn(e, n), c = Fe.useMemo(
3099
- () => new Set(a.map((f) => ye(f))),
3100
- [a]
3101
- ), x = (f) => {
3102
- var N, S;
3103
- return ((S = (N = s.allRecords.find((V) => ye(V.value) === ye(f))) == null ? void 0 : N.label) == null ? void 0 : S.toString()) ?? f;
3104
- }, k = (f) => {
3105
- o(a.filter((N) => N !== f));
3106
- }, y = (f) => {
3107
- l(f), !f && s.query && s.setQuery("");
3108
- };
3109
- return /* @__PURE__ */ t("div", { className: q("w-full", d), children: /* @__PURE__ */ i(lt, { open: u, onOpenChange: y, modal: !0, children: [
3110
- /* @__PURE__ */ t(it, { asChild: !0, children: /* @__PURE__ */ i(
3111
- G,
3112
- {
3113
- variant: "outline",
3114
- size: "xs",
3115
- role: "combobox",
3116
- "aria-expanded": u,
3117
- className: "h-auto min-h-7 w-full justify-between gap-1.5 px-2 py-0.5 font-normal",
3118
- children: [
3119
- /* @__PURE__ */ t("div", { className: "flex min-w-0 flex-1 flex-wrap gap-1", children: a.length > 0 ? a.map((f) => {
3120
- const N = x(f);
3121
- return (
3122
- // Selected values render as small square chips (4px
3123
- // radius), not pills. Pill badges are reserved for
3124
- // avatars and status dots.
3125
- /* @__PURE__ */ i(
3126
- "span",
3127
- {
3128
- className: "inline-flex max-w-full items-center gap-1 rounded-[4px] border border-border/70 bg-muted/40 px-1.5 py-0.5 text-[11px] leading-[14px] text-foreground",
3129
- children: [
3130
- /* @__PURE__ */ t("span", { className: "truncate", children: N }),
3131
- /* @__PURE__ */ t(
3132
- "span",
3133
- {
3134
- role: "button",
3135
- tabIndex: 0,
3136
- "aria-label": `Remove ${N}`,
3137
- className: "shrink-0 rounded-[2px] text-muted-foreground outline-none hover:text-foreground focus-visible:ring-1 focus-visible:ring-ring",
3138
- onKeyDown: (S) => {
3139
- S.key === "Enter" && k(f);
3140
- },
3141
- onMouseDown: (S) => {
3142
- S.preventDefault(), S.stopPropagation();
3143
- },
3144
- onClick: (S) => {
3145
- S.stopPropagation(), k(f);
3146
- },
3147
- children: /* @__PURE__ */ t(ce, { className: "h-3 w-3" })
3148
- }
3149
- )
3150
- ]
3151
- },
3152
- f
3153
- )
3154
- );
3155
- }) : /* @__PURE__ */ t("span", { className: "truncate text-muted-foreground", children: m }) }),
3156
- /* @__PURE__ */ t(_e, { className: "h-3.5 w-3.5 shrink-0 opacity-50" })
3157
- ]
3158
- }
3159
- ) }),
3160
- /* @__PURE__ */ t(
3161
- dt,
3162
- {
3163
- className: "w-[var(--radix-popover-trigger-width)] min-w-[240px] rounded-control p-1.5",
3164
- align: "start",
3165
- onOpenAutoFocus: (f) => {
3166
- var N, S;
3167
- f.preventDefault(), (S = (N = f.currentTarget) == null ? void 0 : N.querySelector('input[type="text"]')) == null || S.focus();
3168
- },
3169
- children: /* @__PURE__ */ t(
3170
- Ut,
3171
- {
3172
- records: s.displayRecords,
3173
- selectedIdentities: c,
3174
- onToggle: (f) => {
3175
- const N = String(f.value);
3176
- a.includes(N) ? k(N) : o([...a, N]);
3177
- },
3178
- browse: s,
3179
- searchPlaceholder: `Search ${(e.label || e.name).toLowerCase()}`,
3180
- listLabel: e.label || e.name,
3181
- density: "compact"
3182
- }
3183
- )
3184
- }
3185
- )
3186
- ] }) });
3187
- }
3188
- function Za({
3189
- field: e,
3190
- source: n,
3191
- value: a,
3192
- onChange: o,
3193
- placeholder: m = "Select value…",
3194
- className: d
3195
- }) {
3196
- var y, f;
3197
- const [u, l] = Fe.useState(!1), s = cn(e, n), c = Fe.useMemo(
3198
- () => new Set(a ? [ye(a)] : []),
3199
- [a]
3200
- ), x = a ? ((f = (y = s.allRecords.find(
3201
- (N) => ye(N.value) === ye(a)
3202
- )) == null ? void 0 : y.label) == null ? void 0 : f.toString()) ?? a : "", k = (N) => {
3203
- l(N), !N && s.query && s.setQuery("");
3204
- };
3205
- return /* @__PURE__ */ i(lt, { open: u, onOpenChange: k, modal: !0, children: [
3206
- /* @__PURE__ */ t(it, { asChild: !0, children: /* @__PURE__ */ i(
3207
- G,
3208
- {
3209
- variant: "outline",
3210
- size: "xs",
3211
- role: "combobox",
3212
- "aria-expanded": u,
3213
- className: q(
3214
- "min-w-0 flex-1 justify-between gap-1.5 px-2 font-normal",
3215
- d
3216
- ),
3217
- children: [
3218
- /* @__PURE__ */ t(
3219
- "span",
3220
- {
3221
- className: q("truncate", !a && "text-muted-foreground"),
3222
- children: a ? x : m
3223
- }
3224
- ),
3225
- /* @__PURE__ */ t(_e, { className: "h-3.5 w-3.5 shrink-0 opacity-50" })
3226
- ]
3227
- }
3228
- ) }),
3229
- /* @__PURE__ */ t(
3230
- dt,
3231
- {
3232
- className: "w-[var(--radix-popover-trigger-width)] min-w-[240px] rounded-control p-1.5",
3233
- align: "start",
3234
- onOpenAutoFocus: (N) => {
3235
- var S, V;
3236
- N.preventDefault(), (V = (S = N.currentTarget) == null ? void 0 : S.querySelector('input[type="text"]')) == null || V.focus();
3237
- },
3238
- children: /* @__PURE__ */ t(
3239
- Ut,
3240
- {
3241
- records: s.displayRecords,
3242
- selectedIdentities: c,
3243
- onToggle: (N) => {
3244
- o(String(N.value)), k(!1);
3245
- },
3246
- selectionMode: "single",
3247
- browse: s,
3248
- searchPlaceholder: `Search ${(e.label || e.name).toLowerCase()}`,
3249
- listLabel: e.label || e.name,
3250
- density: "compact"
3251
- }
3252
- )
3253
- }
3254
- )
3255
- ] });
3256
- }
3257
- function er({
3258
- value: e,
3259
- operator: n,
3260
- relativeMeta: a,
3261
- latestValue: o,
3262
- field: m,
3263
- onChange: d,
3264
- className: u
3265
- }) {
3266
- const l = Wn(), s = Qn(), c = n === "between" || n === "not between", x = en(n), k = x ? a : void 0, y = P(() => {
3267
- if (!c || !a) return;
3268
- const C = s(a);
3269
- return {
3270
- ...C,
3271
- tooltip: C.dates ? void 0 : nn(a).dataAnchored ? Kn : Pn
3272
- };
3273
- }, [c, a, s]), f = P(() => {
3274
- if (c) {
3275
- if (y) {
3276
- const { range: C } = y;
3277
- return C ? { from: C.start, to: C.end } : void 0;
3278
- }
3279
- if (e && Array.isArray(e) && e.length === 2) {
3280
- const C = He(e[0], l, "start"), T = He(e[1], l, "end");
3281
- if (C && T)
3282
- return { from: C, to: T };
3283
- }
3284
- }
3285
- }, [e, c, y, l]), N = P(() => {
3286
- if (!e || c || o) return;
3287
- const C = Array.isArray(e) ? e[0] : e;
3288
- return He(C, l, "start");
3289
- }, [e, c, o, l]), S = (C) => n === "<=" || n === ">" ? xa(C, l) : ga(C, l);
3290
- return /* @__PURE__ */ t(
3291
- Hn,
3292
- {
3293
- value: c ? f : void 0,
3294
- selectionMode: c ? "range" : "single",
3295
- singleValue: c ? void 0 : N,
3296
- singleValueLabel: !c && o ? jt : void 0,
3297
- onChange: (C) => {
3298
- if (C != null && C.from && C.to) {
3299
- d({ value: [C.from.toISOString(), C.to.toISOString()] });
3300
- return;
3301
- }
3302
- d({ value: [] });
3303
- },
3304
- onSingleChange: (C) => {
3305
- if (!C) {
3306
- d({ value: "" });
3307
- return;
3308
- }
3309
- const T = S(C), U = fa(T, n, {
3310
- timezone: l
3311
- });
3312
- d({ value: typeof U == "string" ? U : U.toISOString() });
3313
- },
3314
- onRelativeSelect: x ? (C, T) => {
3315
- if (!C.from || !C.to) {
3316
- d({ value: c ? [] : "" });
3317
- return;
3318
- }
3319
- const U = tn(n, [
3320
- C.from.toISOString(),
3321
- C.to.toISOString()
3322
- ]);
3323
- d({
3324
- value: U.length === 1 ? U[0] : U,
3325
- relativeMeta: T
3326
- });
3327
- } : void 0,
3328
- relativeValue: k,
3329
- comparisonValue: !c && x ? n : void 0,
3330
- relativePoints: !c && x ? { operator: n } : "none",
3331
- relativeSummary: y,
3332
- supplementalFooter: x ? /* @__PURE__ */ t("p", { className: "border-t border-border px-3 py-2 text-[11px] text-muted-foreground", children: "Presets and Relative update each time the card runs. Static dates stay fixed." }) : void 0,
3333
- timezone: l,
3334
- enableTimePrecision: ha(m),
3335
- staticTimeInputs: !1,
3336
- showRelativeTab: x,
3337
- className: q("min-w-0", u),
3338
- buttonClassName: "h-7 text-[12px] [&>span]:text-[12px]",
3339
- placeholder: "Select date…"
3340
- }
3341
- );
3342
- }
3343
- const tr = (e) => e.conditions.length > 0 || e.groups.length > 0, ht = [
3344
- "contains",
3345
- "startsWith",
3346
- "endsWith",
3347
- "like",
3348
- "not like"
3349
- ], nr = [
3350
- "=",
3351
- "!=",
3352
- ">",
3353
- ">=",
3354
- "<",
3355
- "<=",
3356
- ...ht,
3357
- "in",
3358
- "not in",
3359
- "isNull",
3360
- "isNotNull"
3361
- ], ar = [
3362
- "=",
3363
- "!=",
3364
- ...ht,
3365
- "in",
3366
- "not in",
3367
- "isNull",
3368
- "isNotNull"
3369
- ], rr = [
3370
- "=",
3371
- "!=",
3372
- ">",
3373
- ">=",
3374
- "<",
3375
- "<=",
3376
- "in",
3377
- "not in",
3378
- "isNull",
3379
- "isNotNull"
3380
- ], sr = ["=", "!=", "isNull", "isNotNull"], or = [
3381
- "between",
3382
- // Default operator for dates
3383
- "=",
3384
- "!=",
3385
- "<",
3386
- "<=",
3387
- ">",
3388
- ">=",
3389
- "isNull",
3390
- "isNotNull"
3391
- ], lr = {
3392
- "=": "Equals",
3393
- "!=": "Not equals",
3394
- ">": "Greater than",
3395
- ">=": "Greater than or equal",
3396
- "<": "Less than",
3397
- "<=": "Less than or equal",
3398
- contains: "Contains",
3399
- startsWith: "Starts with",
3400
- endsWith: "Ends with",
3401
- like: "Like",
3402
- "not like": "Not like",
3403
- in: "In",
3404
- "not in": "Not in",
3405
- between: "Between",
3406
- isNull: "Is null",
3407
- isNotNull: "Is not null",
3408
- "not between": "Not between"
3409
- };
3410
- function Xe(e) {
3411
- return lr[e] || ba(e);
3412
- }
3413
- function ir(e) {
3414
- switch (e) {
3415
- case "string":
3416
- return ar;
3417
- case "number":
3418
- return rr;
3419
- case "boolean":
3420
- return sr;
3421
- case "date":
3422
- return or;
3423
- default:
3424
- return nr;
3425
- }
3426
- }
3427
- const un = "w-[68px] shrink-0", Ot = "group-data-[inline]/filters:w-auto group-data-[inline]/filters:min-w-0 group-data-[inline]/filters:flex-1 group-data-[inline]/filters:shrink", ft = "text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground";
3428
- function mn({
3429
- value: e,
3430
- onValueChange: n,
3431
- "aria-label": a
3432
- }) {
3433
- return /* @__PURE__ */ i(
3434
- xe,
3435
- {
3436
- value: e,
3437
- onValueChange: (o) => n(o),
3438
- children: [
3439
- /* @__PURE__ */ t(
3440
- ge,
3441
- {
3442
- size: "xs",
3443
- "aria-label": a,
3444
- className: q(un, "font-medium"),
3445
- children: /* @__PURE__ */ t(be, {})
3446
- }
3447
- ),
3448
- /* @__PURE__ */ i(ve, { className: "min-w-[var(--radix-select-trigger-width)]", children: [
3449
- /* @__PURE__ */ t(re, { value: "AND", className: "text-[12px] font-medium", children: "AND" }),
3450
- /* @__PURE__ */ t(re, { value: "OR", className: "text-[12px] font-medium", children: "OR" })
3451
- ] })
3452
- ]
3453
- }
3454
- );
3455
- }
3456
- function pn({
3457
- condition: e,
3458
- index: n,
3459
- groupId: a,
3460
- groupLogicalOperator: o,
3461
- onRemoveCondition: m,
3462
- onUpdateGroupOperator: d,
3463
- availableFields: u,
3464
- source: l,
3465
- updateConditionFields: s,
3466
- replaceCondition: c
3467
- }) {
3468
- const {
3469
- attributes: x,
3470
- listeners: k,
3471
- setNodeRef: y,
3472
- transform: f,
3473
- transition: N,
3474
- isDragging: S
3475
- } = Gt({ id: e.id }), V = {
3476
- transform: Bt.Transform.toString(f),
3477
- transition: N
3478
- }, F = qe(e.field.dataType), K = e.operator === "isNull" || e.operator === "isNotNull", C = e.operator === "in" || e.operator === "not in";
3479
- return /* @__PURE__ */ i(
3480
- "div",
3481
- {
3482
- ref: y,
3483
- style: V,
3484
- className: q(
3485
- "flex items-center gap-2 rounded-control px-1.5 py-1 transition-colors hover:bg-muted/40",
3486
- S && "z-50 opacity-50"
3487
- ),
3488
- children: [
3489
- /* @__PURE__ */ t(
3490
- "button",
3491
- {
3492
- type: "button",
3493
- ...x,
3494
- ...k,
3495
- "aria-label": "Drag to reorder condition",
3496
- className: "flex h-7 w-5 shrink-0 cursor-grab items-center justify-center rounded-control text-muted-foreground/60 hover:text-foreground focus-visible:outline-none active:cursor-grabbing",
3497
- children: /* @__PURE__ */ t(Wt, { className: "h-3.5 w-3.5" })
3498
- }
3499
- ),
3500
- n > 0 ? /* @__PURE__ */ t(
3501
- mn,
3502
- {
3503
- value: o,
3504
- onValueChange: (T) => d(a, T),
3505
- "aria-label": "Logical operator"
3506
- }
3507
- ) : /* @__PURE__ */ t("span", { className: q(un, "text-center", ft), children: "Where" }),
3508
- /* @__PURE__ */ t(
3509
- Xa,
3510
- {
3511
- value: e.field,
3512
- onValueChange: (T) => {
3513
- c(
3514
- a,
3515
- e.id,
3516
- Pa(e, T)
3517
- );
3518
- },
3519
- availableFields: u,
3520
- placeholder: "Select field",
3521
- className: q("w-60 shrink-0", Ot)
3522
- }
3523
- ),
3524
- /* @__PURE__ */ i(
3525
- xe,
3526
- {
3527
- value: e.operator,
3528
- onValueChange: (T) => c(
3529
- a,
3530
- e.id,
3531
- Ka(e, T)
3532
- ),
3533
- children: [
3534
- /* @__PURE__ */ t(
3535
- ge,
3536
- {
3537
- size: "xs",
3538
- "aria-label": "Operator",
3539
- className: q("w-40 shrink-0", Ot),
3540
- children: /* @__PURE__ */ t(be, { children: e.operator ? Xe(e.operator) : "" })
3541
- }
3542
- ),
3543
- /* @__PURE__ */ t(ve, { children: ir(F).map((T) => /* @__PURE__ */ t(re, { value: T, children: Xe(T) }, T)) })
3544
- ]
3545
- }
3546
- ),
3547
- K ? /* @__PURE__ */ t("div", { className: "min-w-0 flex-1" }) : F === "string" ? C ? /* @__PURE__ */ t(
3548
- Ja,
3549
- {
3550
- field: e.field,
3551
- source: l,
3552
- selected: Array.isArray(e.value) && e.value.every((T) => typeof T == "string") ? e.value : [],
3553
- onChange: (T) => s(a, e.id, {
3554
- value: T
3555
- }),
3556
- placeholder: "Select values…",
3557
- className: "min-w-0 flex-1"
3558
- }
3559
- ) : ht.includes(e.operator) ? /* @__PURE__ */ t(
3560
- Ne,
3561
- {
3562
- size: "xs",
3563
- value: typeof e.value == "string" ? e.value : "",
3564
- onChange: (T) => s(a, e.id, {
3565
- value: T.target.value
3566
- }),
3567
- className: "min-w-0 flex-1",
3568
- placeholder: `${Xe(e.operator)}…`
3569
- }
3570
- ) : /* @__PURE__ */ t(
3571
- Za,
3572
- {
3573
- field: e.field,
3574
- source: l,
3575
- value: typeof e.value == "string" ? e.value : "",
3576
- onChange: (T) => s(a, e.id, { value: T }),
3577
- placeholder: "Select value…",
3578
- className: "min-w-0 flex-1"
3579
- }
3580
- ) : F === "boolean" ? /* @__PURE__ */ i(
3581
- xe,
3582
- {
3583
- value: typeof e.value == "boolean" ? String(e.value) : "",
3584
- onValueChange: (T) => s(a, e.id, {
3585
- value: T === "true"
3586
- }),
3587
- children: [
3588
- /* @__PURE__ */ t(ge, { size: "xs", className: "min-w-0 flex-1", children: /* @__PURE__ */ t(be, { placeholder: "Select value…" }) }),
3589
- /* @__PURE__ */ i(ve, { children: [
3590
- /* @__PURE__ */ t(re, { value: "true", children: "True" }),
3591
- /* @__PURE__ */ t(re, { value: "false", children: "False" })
3592
- ] })
3593
- ]
3594
- }
3595
- ) : F === "date" ? (
3596
- // Date fields use CardDateFilter which:
3597
- // - Formats dates as ISO strings for backend compatibility
3598
- // - Handles different operators (=, !=, >, <, between, in, etc.)
3599
- // - Saves relative choices ("This month") with the range
3600
- /* @__PURE__ */ t(
3601
- er,
3602
- {
3603
- value: e.value,
3604
- operator: e.operator,
3605
- relativeMeta: Zt(e.relativeMeta),
3606
- latestValue: e.latestValue === !0,
3607
- field: e.field,
3608
- onChange: (T) => c(
3609
- a,
3610
- e.id,
3611
- pt(e, T)
3612
- ),
3613
- className: "min-w-0 flex-1"
3614
- }
3615
- )
3616
- ) : /* @__PURE__ */ t(
3617
- Ne,
3618
- {
3619
- size: "xs",
3620
- value: typeof e.value == "string" || typeof e.value == "number" ? e.value : "",
3621
- onChange: (T) => s(a, e.id, {
3622
- value: T.target.value
3623
- }),
3624
- className: "min-w-0 flex-1",
3625
- placeholder: C ? "value1, value2, value3" : "Value"
3626
- }
3627
- ),
3628
- /* @__PURE__ */ t(
3629
- G,
3630
- {
3631
- variant: "ghost",
3632
- size: "xs",
3633
- "aria-label": "Remove condition",
3634
- className: "h-7 w-7 shrink-0 p-0 text-muted-foreground hover:text-foreground",
3635
- onClick: () => m(a, e.id),
3636
- children: /* @__PURE__ */ t(ce, { className: "h-3.5 w-3.5" })
3637
- }
3638
- )
3639
- ]
3640
- }
3641
- );
3642
- }
3643
- const _t = "group-data-[inline]/filters:h-auto group-data-[inline]/filters:gap-1 group-data-[inline]/filters:border-0 group-data-[inline]/filters:bg-transparent group-data-[inline]/filters:px-0 group-data-[inline]/filters:py-0.5 group-data-[inline]/filters:text-[11px] group-data-[inline]/filters:font-medium group-data-[inline]/filters:text-muted-foreground group-data-[inline]/filters:shadow-none group-data-[inline]/filters:underline-offset-2 group-data-[inline]/filters:hover:bg-transparent group-data-[inline]/filters:hover:text-foreground group-data-[inline]/filters:hover:underline";
3644
- function hn({
3645
- onAddCondition: e,
3646
- onAddGroup: n
3647
- }) {
3648
- return /* @__PURE__ */ i("div", { className: "mt-2 flex items-center gap-1.5 group-data-[inline]/filters:mt-1 group-data-[inline]/filters:gap-3", children: [
3649
- /* @__PURE__ */ i(
3650
- G,
3651
- {
3652
- type: "button",
3653
- size: "xs",
3654
- variant: "outline",
3655
- className: q("gap-1.5", _t),
3656
- onClick: e,
3657
- children: [
3658
- /* @__PURE__ */ t(Ve, { className: "h-3 w-3" }),
3659
- "Add condition"
3660
- ]
3661
- }
3662
- ),
3663
- n && /* @__PURE__ */ i(
3664
- G,
3665
- {
3666
- type: "button",
3667
- size: "xs",
3668
- variant: "ghost",
3669
- className: q("gap-1.5 text-muted-foreground hover:text-foreground", _t),
3670
- onClick: n,
3671
- children: [
3672
- /* @__PURE__ */ t(Ve, { className: "h-3 w-3" }),
3673
- "Add group"
3674
- ]
3675
- }
3676
- )
3677
- ] });
3678
- }
3679
- function dr({
3680
- group: e,
3681
- depth: n,
3682
- parentGroupId: a,
3683
- onUpdateGroupOperator: o,
3684
- onUpdateGroupNegate: m,
3685
- onRemoveGroup: d,
3686
- onRemoveCondition: u,
3687
- onReorderConditions: l,
3688
- onReorderGroups: s,
3689
- onAddCondition: c,
3690
- onAddGroup: x,
3691
- availableFields: k,
3692
- source: y,
3693
- renderFilterGroup: f,
3694
- updateConditionFields: N,
3695
- replaceCondition: S
3696
- }) {
3697
- const {
3698
- attributes: V,
3699
- listeners: F,
3700
- setNodeRef: K,
3701
- transform: C,
3702
- transition: T,
3703
- isDragging: U
3704
- } = Gt({ id: e.id }), Z = {
3705
- transform: Bt.Transform.toString(C),
3706
- transition: T
3707
- }, p = ($) => {
3708
- const { active: D, over: v } = $;
3709
- if (v && D.id !== v.id) {
3710
- const h = e.conditions.findIndex(
3711
- (w) => w.id === D.id
3712
- ), E = e.conditions.findIndex(
3713
- (w) => w.id === v.id
3714
- );
3715
- h !== -1 && E !== -1 && l(e.id, h, E);
3716
- }
3717
- }, I = ($) => {
3718
- const { active: D, over: v } = $;
3719
- if (v && D.id !== v.id && a) {
3720
- const h = e.groups.findIndex((w) => w.id === D.id), E = e.groups.findIndex((w) => w.id === v.id);
3721
- h !== -1 && E !== -1 && s(a, h, E);
3722
- }
3723
- };
3724
- return /* @__PURE__ */ i(
3725
- "div",
3726
- {
3727
- ref: K,
3728
- style: Z,
3729
- className: q(
3730
- n > 0 && "mt-2 overflow-hidden rounded-[6px] border border-border/60",
3731
- U && "z-50 opacity-50"
3732
- ),
3733
- children: [
3734
- n > 0 && /* @__PURE__ */ i("div", { className: "flex items-center justify-between gap-2 border-b border-border/60 bg-muted/40 px-2 py-1", children: [
3735
- /* @__PURE__ */ i("div", { className: "flex items-center gap-1.5", children: [
3736
- /* @__PURE__ */ t(
3737
- "button",
3738
- {
3739
- type: "button",
3740
- ...V,
3741
- ...F,
3742
- "aria-label": "Drag to reorder group",
3743
- className: "flex h-7 w-5 shrink-0 cursor-grab items-center justify-center rounded-control text-muted-foreground/60 hover:text-foreground focus-visible:outline-none active:cursor-grabbing",
3744
- children: /* @__PURE__ */ t(Wt, { className: "h-3.5 w-3.5" })
3745
- }
3746
- ),
3747
- /* @__PURE__ */ t(
3748
- G,
3749
- {
3750
- type: "button",
3751
- variant: e.negate ? "default" : "outline",
3752
- size: "xs",
3753
- "aria-pressed": e.negate,
3754
- className: "px-2",
3755
- onClick: () => m(e.id, !e.negate),
3756
- children: "NOT"
3757
- }
3758
- ),
3759
- /* @__PURE__ */ t(
3760
- mn,
3761
- {
3762
- value: e.logicalOperator,
3763
- onValueChange: ($) => o(e.id, $),
3764
- "aria-label": "Group logical operator"
3765
- }
3766
- ),
3767
- /* @__PURE__ */ t("span", { className: ft, children: "Group" })
3768
- ] }),
3769
- /* @__PURE__ */ t(
3770
- G,
3771
- {
3772
- type: "button",
3773
- variant: "ghost",
3774
- size: "xs",
3775
- "aria-label": "Remove group",
3776
- className: "h-7 w-7 p-0 text-muted-foreground hover:text-foreground",
3777
- onClick: () => a && d(a, e.id),
3778
- children: /* @__PURE__ */ t(zt, { className: "h-3.5 w-3.5" })
3779
- }
3780
- )
3781
- ] }),
3782
- /* @__PURE__ */ i("div", { className: q(n > 0 && "p-2"), children: [
3783
- /* @__PURE__ */ t(
3784
- Re,
3785
- {
3786
- sensors: Je(
3787
- fe(tt),
3788
- fe(et, {
3789
- coordinateGetter: Ze
3790
- })
3791
- ),
3792
- collisionDetection: Ee,
3793
- onDragEnd: p,
3794
- children: /* @__PURE__ */ t(
3795
- ze,
3796
- {
3797
- items: e.conditions.map(($) => $.id),
3798
- strategy: Me,
3799
- children: /* @__PURE__ */ t("div", { className: "space-y-0.5", children: e.conditions.map(($, D) => /* @__PURE__ */ t(
3800
- pn,
3801
- {
3802
- condition: $,
3803
- index: D,
3804
- groupId: e.id,
3805
- groupLogicalOperator: e.logicalOperator,
3806
- onRemoveCondition: u,
3807
- onUpdateGroupOperator: o,
3808
- availableFields: k,
3809
- source: y,
3810
- updateConditionFields: N,
3811
- replaceCondition: S
3812
- },
3813
- $.id
3814
- )) })
3815
- }
3816
- )
3817
- }
3818
- ),
3819
- /* @__PURE__ */ t(
3820
- Re,
3821
- {
3822
- sensors: Je(
3823
- fe(tt),
3824
- fe(et, {
3825
- coordinateGetter: Ze
3826
- })
3827
- ),
3828
- collisionDetection: Ee,
3829
- onDragEnd: I,
3830
- children: /* @__PURE__ */ t(
3831
- ze,
3832
- {
3833
- items: e.groups.map(($) => $.id),
3834
- strategy: Me,
3835
- children: e.groups.map(
3836
- ($) => f($, n + 1, e.id)
3837
- )
3838
- }
3839
- )
3840
- }
3841
- ),
3842
- e.conditions.length === 0 && e.groups.length === 0 && /* @__PURE__ */ t("p", { className: "rounded-control border border-dashed border-border/60 px-3 py-2 text-center text-[11.5px] text-muted-foreground", children: "No conditions in this group." }),
3843
- /* @__PURE__ */ t(
3844
- hn,
3845
- {
3846
- onAddCondition: () => c(e.id),
3847
- onAddGroup: () => x(e.id)
3848
- }
3849
- )
3850
- ] })
3851
- ]
3852
- }
3853
- );
3854
- }
3855
- function $r({
3856
- filters: e,
3857
- availableFields: n,
3858
- source: a,
3859
- onSave: o,
3860
- onClearAll: m,
3861
- onCancel: d,
3862
- onChange: u
3863
- }) {
3864
- const l = u !== void 0, {
3865
- currentFilters: s,
3866
- availableFields: c,
3867
- isLoading: x,
3868
- addCondition: k,
3869
- addGroup: y,
3870
- removeCondition: f,
3871
- removeGroup: N,
3872
- updateConditionFields: S,
3873
- replaceCondition: V,
3874
- updateGroupOperator: F,
3875
- updateGroupNegate: K,
3876
- reorderConditions: C,
3877
- reorderGroups: T,
3878
- generateSQLPreview: U,
3879
- hasAnyFilters: Z
3880
- } = Ha({
3881
- initialFilters: e,
3882
- availableFields: n,
3883
- ...u ? {
3884
- onChange: (h) => u(tr(h) ? h : null)
3885
- } : {}
3886
- }), p = Je(
3887
- fe(tt),
3888
- fe(et, {
3889
- coordinateGetter: Ze
3890
- })
3891
- ), [I, $] = Y(!1), D = (h, E = 0, w) => {
3892
- if (E === 0) {
3893
- const H = h.conditions.length === 0 && h.groups.length === 0;
3894
- return /* @__PURE__ */ i("div", { children: [
3895
- /* @__PURE__ */ t(
3896
- Re,
3897
- {
3898
- sensors: p,
3899
- collisionDetection: Ee,
3900
- onDragEnd: (_) => {
3901
- const { active: z, over: B } = _;
3902
- if (B && z.id !== B.id) {
3903
- const j = h.conditions.findIndex(
3904
- (te) => te.id === z.id
3905
- ), ee = h.conditions.findIndex(
3906
- (te) => te.id === B.id
3907
- );
3908
- j !== -1 && ee !== -1 && C(h.id, j, ee);
3909
- }
3910
- },
3911
- children: /* @__PURE__ */ t(
3912
- ze,
3913
- {
3914
- items: h.conditions.map((_) => _.id),
3915
- strategy: Me,
3916
- children: /* @__PURE__ */ t("div", { className: "space-y-0.5", children: h.conditions.map((_, z) => /* @__PURE__ */ t(
3917
- pn,
3918
- {
3919
- condition: _,
3920
- index: z,
3921
- groupId: h.id,
3922
- groupLogicalOperator: h.logicalOperator,
3923
- onRemoveCondition: f,
3924
- onUpdateGroupOperator: F,
3925
- availableFields: c,
3926
- source: a,
3927
- updateConditionFields: S,
3928
- replaceCondition: V
3929
- },
3930
- _.id
3931
- )) })
3932
- }
3933
- )
3934
- }
3935
- ),
3936
- /* @__PURE__ */ t(
3937
- Re,
3938
- {
3939
- sensors: p,
3940
- collisionDetection: Ee,
3941
- onDragEnd: (_) => {
3942
- const { active: z, over: B } = _;
3943
- if (B && z.id !== B.id) {
3944
- const j = h.groups.findIndex(
3945
- (te) => te.id === z.id
3946
- ), ee = h.groups.findIndex(
3947
- (te) => te.id === B.id
3948
- );
3949
- j !== -1 && ee !== -1 && T(h.id, j, ee);
3950
- }
3951
- },
3952
- children: /* @__PURE__ */ t(
3953
- ze,
3954
- {
3955
- items: h.groups.map((_) => _.id),
3956
- strategy: Me,
3957
- children: h.groups.map(
3958
- (_) => D(_, E + 1, h.id)
3959
- )
3960
- }
3961
- )
3962
- }
3963
- ),
3964
- H && !l && /* @__PURE__ */ t("p", { className: "rounded-control border border-dashed border-border/60 px-3 py-2 text-center text-[11.5px] text-muted-foreground", children: "No filters yet. Add a condition to limit the rows this card shows." }),
3965
- /* @__PURE__ */ t(
3966
- hn,
3967
- {
3968
- onAddCondition: () => k(h.id),
3969
- onAddGroup: (
3970
- // In place, grouping is offered once there are two conditions to group,
3971
- // not as a mode to switch on first.
3972
- (l ? h.conditions.length + h.groups.length >= 2 : I) ? () => y(h.id) : void 0
3973
- )
3974
- }
3975
- )
3976
- ] }, h.id);
3977
- }
3978
- return /* @__PURE__ */ t(
3979
- dr,
3980
- {
3981
- group: h,
3982
- depth: E,
3983
- parentGroupId: w,
3984
- onUpdateGroupOperator: F,
3985
- onUpdateGroupNegate: K,
3986
- onRemoveGroup: N,
3987
- onRemoveCondition: f,
3988
- onReorderConditions: C,
3989
- onReorderGroups: T,
3990
- onAddCondition: k,
3991
- onAddGroup: y,
3992
- availableFields: c,
3993
- source: a,
3994
- renderFilterGroup: D,
3995
- updateConditionFields: S,
3996
- replaceCondition: V
3997
- },
3998
- h.id
3999
- );
4000
- }, v = Yn(e);
4001
- return /* @__PURE__ */ i("div", { className: q("group/filters", l ? "flex flex-col" : "flex min-h-0 flex-1 flex-col"), "data-inline": l || void 0, children: [
4002
- /* @__PURE__ */ i("div", { className: l ? "" : "min-h-0 flex-1 overflow-y-auto px-3 py-3", children: [
4003
- x ? /* @__PURE__ */ i("div", { className: "flex items-center justify-center gap-2 py-6 text-[12px] text-muted-foreground", children: [
4004
- /* @__PURE__ */ t(gn, { className: "h-3.5 w-3.5 animate-spin" }),
4005
- "Loading columns…"
4006
- ] }) : D(s),
4007
- !l && /* @__PURE__ */ i("div", { className: "mt-3 flex items-center gap-2 border-t border-border/60 pt-3", children: [
4008
- /* @__PURE__ */ t(
4009
- bn,
4010
- {
4011
- size: "xs",
4012
- id: "advanced-mode",
4013
- checked: I,
4014
- onCheckedChange: (h) => $(h)
4015
- }
4016
- ),
4017
- /* @__PURE__ */ t(
4018
- ie,
4019
- {
4020
- htmlFor: "advanced-mode",
4021
- className: "text-[12px] font-normal leading-none text-foreground",
4022
- children: "Advanced mode"
4023
- }
4024
- ),
4025
- /* @__PURE__ */ t("span", { className: "text-[11px] text-muted-foreground", children: "Nest conditions in groups" })
4026
- ] }),
4027
- Z && !l && /* @__PURE__ */ i("div", { className: "mt-3 border-t border-border/60 pt-3", children: [
4028
- /* @__PURE__ */ t("div", { className: q("mb-1.5", ft), children: "Where clause" }),
4029
- /* @__PURE__ */ t("pre", { className: "overflow-x-auto whitespace-pre-wrap break-words rounded-[6px] border border-border bg-muted/40 px-3 py-2 font-mono text-[12px] leading-[1.55] text-foreground", children: U(s) })
4030
- ] })
4031
- ] }),
4032
- l ? null : /* @__PURE__ */ i("div", { className: "flex shrink-0 items-center justify-between gap-2 border-t border-border px-3 py-2.5", children: [
4033
- /* @__PURE__ */ t("div", { children: v > 0 && /* @__PURE__ */ t(
4034
- G,
4035
- {
4036
- size: "xs",
4037
- variant: "ghost",
4038
- className: "text-muted-foreground hover:text-foreground",
4039
- onClick: () => m == null ? void 0 : m(),
4040
- children: "Clear all"
4041
- }
4042
- ) }),
4043
- /* @__PURE__ */ i("div", { className: "flex items-center gap-1.5", children: [
4044
- /* @__PURE__ */ t(G, { size: "xs", variant: "ghost", onClick: () => d == null ? void 0 : d(), children: "Cancel" }),
4045
- /* @__PURE__ */ t(
4046
- G,
4047
- {
4048
- size: "xs",
4049
- onClick: () => o == null ? void 0 : o(Z ? s : null),
4050
- children: "Apply filters"
4051
- }
4052
- )
4053
- ] })
4054
- ] })
4055
- ] });
4056
- }
4057
- export {
4058
- Sr as A,
4059
- Ir as C,
4060
- kr as F,
4061
- Ua as I,
4062
- ka as L,
4063
- Tr as V,
4064
- Dr as a,
4065
- $r as b,
4066
- an as c,
4067
- Ma as g,
4068
- Lr as u
4069
- };