react-semaphor 0.1.603 → 0.1.605

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 (208) hide show
  1. package/dist/activity/index.js +1 -73
  2. package/dist/analytics-protocol/index.js +1 -1491
  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 +3 -1598
  8. package/dist/briefings/index.js +1 -70
  9. package/dist/chunks/add-to-dashboard-CEmZUf9o.js +12 -0
  10. package/dist/chunks/analytics-base-schemas-DMFrDqn_.js +1 -0
  11. package/dist/chunks/appearance-provider-CfoAVQuG.js +608 -0
  12. package/dist/chunks/appearance-runtime-provider-Bx8H-moR.js +1 -0
  13. package/dist/chunks/applied-constraints-CinevlKD.js +1 -0
  14. package/dist/chunks/assistant-chat-DgUaCE9k.js +51 -0
  15. package/dist/chunks/attachment-filter-line-C_zHMhGh.js +1 -0
  16. package/dist/chunks/attribution-BEFSsbNn.js +1 -0
  17. package/dist/chunks/availability-3AIOf6Z-.js +1 -0
  18. package/dist/chunks/bookmark-impact-BAtemeyK.js +1 -0
  19. package/dist/chunks/bookmark-state-DScd31KT.js +1 -0
  20. package/dist/chunks/brand-C9APUFaP.js +1 -0
  21. package/dist/chunks/card-filter-builder-ClWrXB7P.js +11 -0
  22. package/dist/chunks/column-bands-DwxbZ6UI.js +1 -0
  23. package/dist/chunks/comparison-window-caption-tguyN24S.js +1 -0
  24. package/dist/chunks/context-CntvtZwC.js +2 -0
  25. package/dist/chunks/conversation-JMK2kyTK.js +1 -0
  26. package/dist/chunks/dashboard-ChIcbVTx.js +1 -0
  27. package/dist/chunks/dashboard-briefing-launcher-CwMlhkxV.js +42 -0
  28. package/dist/chunks/dashboard-controls-UCSAFCGA.js +42 -0
  29. package/dist/chunks/dashboard-json-B120hYDa.js +1 -0
  30. package/dist/chunks/dashboard-temporal-snapshot-BFJKbp_6.js +1 -0
  31. package/dist/chunks/edit-dashboard-visual-DvHp03h_.js +73 -0
  32. package/dist/chunks/export-file-format-B-wQNHIn.js +4 -0
  33. package/dist/chunks/filter-line-WwUV5JzN.js +1 -0
  34. package/dist/chunks/filter-reach-preview-C5M5_hf_.js +1 -0
  35. package/dist/chunks/filter-value-text-DqTHe_vu.js +1 -0
  36. package/dist/chunks/index-DViPGDFj.js +1 -0
  37. package/dist/chunks/index-bkP6SnYu.js +1 -0
  38. package/dist/chunks/kpi-trend-rule-B87LNzcz.js +1 -0
  39. package/dist/chunks/layout-grid-CFzqJ7GC.js +6 -0
  40. package/dist/chunks/matrix-analytical-definition-5T-2euHZ.js +1 -0
  41. package/dist/chunks/matrix-member-presentation-vVAv-aqg.js +1 -0
  42. package/dist/chunks/matrix-operation-contract-CWvcEsQ0.js +1 -0
  43. package/dist/chunks/normalize-dashboard-for-dirty-check-ILKfqgL3.js +1 -0
  44. package/dist/chunks/numeric-range-options-C8tr-Bls.js +1 -0
  45. package/dist/chunks/palette-NvEIuXHN.js +6 -0
  46. package/dist/chunks/pivot-result-contract-expectations-BNWhS8mv.js +1 -0
  47. package/dist/chunks/pivot-result-identity-B0eWVMXg.js +1 -0
  48. package/dist/chunks/raw-temporal-value-BHQ-ldpW.js +1 -0
  49. package/dist/chunks/rendered-file-BbvwaU6z.js +1 -0
  50. package/dist/chunks/report-preferences-dialog-Bseb2Rlg.js +1 -0
  51. package/dist/chunks/report-runtime-context-Cd1b5pku.js +1 -0
  52. package/dist/chunks/resolve-dashboard-input-context-BDY7KwRe.js +8 -0
  53. package/dist/chunks/resolver-CjsW8Rz0.js +1 -0
  54. package/dist/chunks/saved-dashboard-context-C3lWc4Dx.js +1 -0
  55. package/dist/chunks/schema-O1Y3WTGF.js +4 -0
  56. package/dist/chunks/selection-filter-compiler-kYsRugss.js +1 -0
  57. package/dist/chunks/semaphor-ready-indicator-BQarSo6S.js +612 -0
  58. package/dist/chunks/set-6mOnfQeH.js +1 -0
  59. package/dist/chunks/slider-BPnHdMGq.js +4 -0
  60. package/dist/chunks/stored-dashboard-DfrxDLhR.js +1 -0
  61. package/dist/chunks/table-export-sheet-xaczzWZF.js +2 -0
  62. package/dist/chunks/token-types-1vzMWjI-.js +1 -0
  63. package/dist/chunks/validators-Dg2kyF4_.js +1 -0
  64. package/dist/chunks/variable-draft-B4_xqr4Y.js +1 -0
  65. package/dist/chunks/visual-choice-DgEFfkE-.js +1 -0
  66. package/dist/dashboard/index.js +1 -7
  67. package/dist/dashboard-authoring/index.js +1 -4614
  68. package/dist/format-utils/index.js +1 -425
  69. package/dist/index.js +1 -554
  70. package/dist/layouts/index.js +1 -7
  71. package/dist/live-channel/index.js +1 -124
  72. package/dist/pdf-export-policy/index.js +1 -92
  73. package/dist/pdf-table-layout/index.js +1 -993
  74. package/dist/report-runtime-context/index.js +1 -9
  75. package/dist/shared/index.js +1 -6
  76. package/dist/style.css +1 -1
  77. package/dist/surfboard/index.js +1 -9
  78. package/dist/types/brand-studio/brand-studio-draft.d.ts +45 -13
  79. package/dist/types/brand-studio/brand-studio-editor.d.ts +13 -2
  80. package/dist/types/components/index.d.ts +1 -0
  81. package/dist/types/components/visual/data-table/hooks/use-data-table-logic.d.ts +17 -6
  82. package/dist/types/components/visual/data-table/types/data-table.d.ts +52 -42
  83. package/dist/types/index.js +1 -88
  84. package/dist/types/lib/appearance/aliases.d.ts +3 -0
  85. package/dist/types/lib/appearance/index.d.ts +1 -0
  86. package/dist/types/lib/appearance/table-density.d.ts +18 -0
  87. package/dist/types/lib/appearance/types.d.ts +39 -1
  88. package/dist/types/lib/dashboard-viewer/column-header-actions.d.ts +100 -0
  89. package/dist/types/lib/dashboard-viewer/table-view-edit.d.ts +0 -27
  90. package/dist/types/lib/dashboard-viewer/table-view.d.ts +26 -2
  91. package/dist/types/lib/dashboard-viewer/use-table-view.d.ts +2 -0
  92. package/dist/types/lib/filter-values/build-card-filter-definition.d.ts +32 -0
  93. package/dist/types/lib/hooks/use-add-new-frame.d.ts +7 -0
  94. package/dist/types/lib/hooks/use-dashboard-card.d.ts +4 -0
  95. package/dist/types/lib/interactions/get-click-context-from-chartjs.d.ts +8 -0
  96. package/dist/types/lib/query-context/dashboard-filter-mapping-resolution.d.ts +9 -0
  97. package/dist/types/lib/stores/dashboard-store.d.ts +14 -2
  98. package/dist/types/lib/stores/explorer-actions.d.ts +7 -10
  99. package/dist/types/lib/types/common-types.d.ts +1 -2
  100. package/dist/types/lib/types/semantic-types.d.ts +6 -10
  101. package/dist/types/lib/utils/card-config-utils.d.ts +13 -0
  102. package/dist/types/lib/utils/field-placement.d.ts +17 -0
  103. package/dist/types/lib/utils/field-state-calculator.d.ts +7 -19
  104. package/dist/types/shared/analytics-protocol/analytics-refusal.d.ts +21 -1
  105. package/dist/types/shared/analytics-protocol/field-provenance.d.ts +7 -4
  106. package/dist/types/shared/dashboard-authoring/calculations/definition.d.ts +13 -0
  107. package/dist/types/shared/dashboard-authoring/card-data-source/card-base.d.ts +125 -0
  108. package/dist/types/shared/dashboard-authoring/card-data-source/card-field-folders.d.ts +55 -0
  109. package/dist/types/shared/dashboard-authoring/card-data-source/card-joins.d.ts +114 -0
  110. package/dist/types/shared/dashboard-authoring/card-data-source/card-prune.d.ts +12 -0
  111. package/dist/types/shared/dashboard-authoring/card-data-source/filter-field-catalog.d.ts +60 -0
  112. package/dist/types/shared/dashboard-authoring/card-data-source/filter-field-folders.d.ts +180 -0
  113. package/dist/types/shared/dashboard-authoring/card-data-source/index.d.ts +7 -0
  114. package/dist/types/shared/dashboard-authoring/card-data-source/join-reach.d.ts +42 -0
  115. package/dist/types/shared/dashboard-authoring/card-field-places.d.ts +28 -0
  116. package/dist/types/shared/dashboard-authoring/card-settings/card-display-write.d.ts +2 -8
  117. package/dist/types/shared/dashboard-authoring/card-settings/card-kinds.d.ts +1 -1
  118. package/dist/types/shared/dashboard-authoring/card-settings/column-display-values.d.ts +5 -0
  119. package/dist/types/shared/dashboard-authoring/card-settings/column-display.d.ts +52 -0
  120. package/dist/types/shared/dashboard-authoring/card-settings/index.d.ts +1 -0
  121. package/dist/types/shared/dashboard-authoring/card-settings/inputs.d.ts +9 -0
  122. package/dist/types/shared/dashboard-authoring/card-settings/resolved.d.ts +4 -0
  123. package/dist/types/shared/dashboard-authoring/card-settings/table-viewer-switches.d.ts +15 -0
  124. package/dist/types/shared/dashboard-authoring/card-settings/views.d.ts +5 -0
  125. package/dist/types/shared/dashboard-authoring/changes/card-query-part.d.ts +6 -0
  126. package/dist/types/shared/dashboard-authoring/changes/dashboard-change.d.ts +132 -3
  127. package/dist/types/shared/dashboard-authoring/changes/diagnostics.d.ts +3 -1
  128. package/dist/types/shared/dashboard-authoring/conditional-formatting/schema.d.ts +10 -10
  129. package/dist/types/shared/dashboard-authoring/conditional-formatting/store.d.ts +10 -1
  130. package/dist/types/shared/dashboard-authoring/field-aggregations.d.ts +9 -2
  131. package/dist/types/shared/dashboard-authoring/field-folders/field-folders.d.ts +116 -0
  132. package/dist/types/shared/dashboard-authoring/field-folders/index.d.ts +1 -0
  133. package/dist/types/shared/dashboard-authoring/filter-reach-decision.d.ts +11 -0
  134. package/dist/types/shared/dashboard-authoring/index.d.ts +7 -1
  135. package/dist/types/shared/dashboard-authoring/operations/card-operations.d.ts +2 -0
  136. package/dist/types/shared/dashboard-authoring/operations/operation-types.d.ts +7 -2
  137. package/dist/types/shared/dashboard-authoring/outline/outline-dashboard.d.ts +6 -2
  138. package/dist/types/shared/dashboard-authoring/outline/outline-filters.d.ts +2 -0
  139. package/dist/types/shared/dashboard-authoring/see-records/result.d.ts +7 -22
  140. package/dist/types/shared/dashboard-authoring/sheet-kinds.d.ts +36 -0
  141. package/dist/types/shared/dashboard-authoring/table-sheet-shape.d.ts +140 -0
  142. package/dist/types/shared/dashboard-viewer/table-column-move.d.ts +15 -0
  143. package/dist/types/shared/dashboard-viewer/table-settings.d.ts +8 -2
  144. package/dist/types/shared/format-utils/types/format-types.d.ts +1 -1
  145. package/dist/usage-events/index.js +1 -285
  146. package/dist/value-format-preferences/index.js +1 -635
  147. package/package.json +5 -2
  148. package/dist/chunks/add-to-dashboard-CFF-wFU-.js +0 -291
  149. package/dist/chunks/analytics-base-schemas-DsUh5Q3C.js +0 -680
  150. package/dist/chunks/appearance-context-BwBp25ZG.js +0 -162
  151. package/dist/chunks/appearance-runtime-provider-BRHYELkC.js +0 -80
  152. package/dist/chunks/applied-constraints-DU-wndZ7.js +0 -47
  153. package/dist/chunks/assistant-chat-B6hNQI1t.js +0 -6115
  154. package/dist/chunks/attribution-BvoKvhcj.js +0 -32
  155. package/dist/chunks/availability-Bp5Gfu1I.js +0 -44
  156. package/dist/chunks/bookmark-impact-Ba2PLcGp.js +0 -76
  157. package/dist/chunks/bookmark-state-n7AaNzR_.js +0 -1667
  158. package/dist/chunks/brand-BoUV0iHF.js +0 -54
  159. package/dist/chunks/card-filter-builder-Y22HizVx.js +0 -4069
  160. package/dist/chunks/column-bands-RdM-kjDe.js +0 -47
  161. package/dist/chunks/comparison-window-caption-Ck2TIbnR.js +0 -741
  162. package/dist/chunks/context-UCQ7sere.js +0 -369
  163. package/dist/chunks/conversation-sQiWYUOb.js +0 -16
  164. package/dist/chunks/dashboard-BghI99oY.js +0 -14
  165. package/dist/chunks/dashboard-briefing-launcher-DtBAnGiH.js +0 -4875
  166. package/dist/chunks/dashboard-controls-CtFXlyjV.js +0 -2290
  167. package/dist/chunks/dashboard-json-DfGBUtCd.js +0 -66
  168. package/dist/chunks/dates-BnrXF4bb.js +0 -185
  169. package/dist/chunks/edit-9df1zOWe.js +0 -226
  170. package/dist/chunks/edit-dashboard-visual-oxt3x1wb.js +0 -18397
  171. package/dist/chunks/export-file-format-C-tJsxsf.js +0 -111
  172. package/dist/chunks/filter-line-Cy5YYqRL.js +0 -703
  173. package/dist/chunks/filter-reach-copy-CE_ZX147.js +0 -5111
  174. package/dist/chunks/filter-value-text-fWvSDwkl.js +0 -153
  175. package/dist/chunks/index-BVKzKl5d.js +0 -90
  176. package/dist/chunks/index-CV_Kzou0.js +0 -595
  177. package/dist/chunks/index-D5rxbtS4.js +0 -2795
  178. package/dist/chunks/layout-grid-9LndRoLa.js +0 -16
  179. package/dist/chunks/matrix-analytical-definition-CCp48UCw.js +0 -1233
  180. package/dist/chunks/matrix-member-presentation-zNehruXR.js +0 -391
  181. package/dist/chunks/matrix-operation-contract-DPBj69D8.js +0 -1413
  182. package/dist/chunks/metric-comparison-B0FR-Q8I.js +0 -600
  183. package/dist/chunks/normalize-dashboard-for-dirty-check-XKgH3GFX.js +0 -119
  184. package/dist/chunks/paintbrush-58FQYY-y.js +0 -27
  185. package/dist/chunks/palette-Be62Tkoa.js +0 -23
  186. package/dist/chunks/pickers-DkqmtnTL.js +0 -2403
  187. package/dist/chunks/pivot-result-contract-expectations-BYqAmG9n.js +0 -5092
  188. package/dist/chunks/pivot-result-identity-CAP4--iq.js +0 -77
  189. package/dist/chunks/raw-temporal-value-Dg_MTFF7.js +0 -3778
  190. package/dist/chunks/rendered-file-D8xEuVVx.js +0 -108
  191. package/dist/chunks/report-preferences-dialog-uJp9GBTM.js +0 -1651
  192. package/dist/chunks/report-runtime-context-c77_KF9v.js +0 -388
  193. package/dist/chunks/resolve-dashboard-input-context-Rtl1ffmE.js +0 -25324
  194. package/dist/chunks/resolver-DG_tfEpt.js +0 -156
  195. package/dist/chunks/save-C5A0JnEV.js +0 -21
  196. package/dist/chunks/saved-dashboard-context-tcyTU8jm.js +0 -618
  197. package/dist/chunks/schema-C9NPiIru.js +0 -2568
  198. package/dist/chunks/selection-filter-compiler-DNijjI5y.js +0 -150
  199. package/dist/chunks/semaphor-ready-indicator-FBvunj6S.js +0 -145603
  200. package/dist/chunks/shelf-drop-preview-context-QKStrcK9.js +0 -2466
  201. package/dist/chunks/stored-dashboard-CHozcAY9.js +0 -4075
  202. package/dist/chunks/style-sheet-parts-CDCG-8Ej.js +0 -8681
  203. package/dist/chunks/table-export-sheet-ZFIvs6Sj.js +0 -949
  204. package/dist/chunks/token-types-XbM6QByy.js +0 -8
  205. package/dist/chunks/upload-H15d7uHK.js +0 -15
  206. package/dist/chunks/validators-Baf3VIf5.js +0 -3686
  207. package/dist/chunks/variable-draft-C2y8Jp6Z.js +0 -242
  208. package/dist/chunks/visual-choice-DDfHfHvY.js +0 -172
@@ -1,4075 +0,0 @@
1
- import { jw as Vn, dE as Mn, cN as kn, bi as xn, bP as Pn, v as wn, cF as On, jx as Te, fx as dt, fA as _n, cl as An, jy as En, aM as Bn, iA as ut, iC as Rn, c6 as Ve, jz as ft, e8 as de, Z as qn, iE as jn, s as _, it as ue, u as Me, jA as Nn, iJ as zn, e0 as pt, e2 as mt, dN as Ln, e7 as Kn, e5 as Ge, e6 as Gn, h as Hn, dP as Un, d$ as Qn, dZ as $n, c9 as gt, bK as Zn, a8 as A, hj as yt, cR as Wn, ac as Jn, jB as fe, jC as bt, jD as Yn, w as Xn, jE as ke, jq as pe, jF as er, jG as xe, jH as tr, jI as nr, jJ as rr, jK as or, jL as ir, y as Pe, jM as ar, z as U, r as sr, m as lr, jN as L, jO as cr, jP as te, jQ as It, ij as we, T as dr, jR as ur, jS as fr, ib as Ct, jT as pr, jU as mr, o as gr, jV as yr, jW as ht, jX as br, jY as Ir, jZ as Cr, cm as vt, j_ as hr, j$ as vr, k0 as Ft, x as Oe, di as Fr, ad as Dr, q as Dt, hi as Sr, k1 as Tr, k2 as Vr, k3 as Mr, dh as kr, jn as xr, C as Pr, D as He, M as wr, k4 as Or, k5 as _r, dj as Ar, k6 as Er } from "./resolve-dashboard-input-context-Rtl1ffmE.js";
2
- import { am as Br, a6 as Z, K as Rr, w as qr, ay as Ce, x as jr, a9 as ne, aA as St, V as Nr, b as zr, k as Lr, aE as Kr, aF as Gr } from "./validators-Baf3VIf5.js";
3
- import { q as Tt } from "./matrix-operation-contract-DPBj69D8.js";
4
- import "./analytics-base-schemas-DsUh5Q3C.js";
5
- import "./pickers-DkqmtnTL.js";
6
- import { canonicalizeSupportedCurrencyCode as Vt } from "../value-format-preferences/index.js";
7
- import { ZodError as Hr } from "zod";
8
- import { b as re, r as Ur, ba as Qr, i as $r, aT as Zr, ak as Ue, aP as Qe } from "./pivot-result-contract-expectations-BYqAmG9n.js";
9
- import { aE as Mt, aF as kt, aG as be, a4 as Wr, aD as xt, C as he, aH as N, A as W, i as Pt, w as Jr, q as Yr, v as Xr, B as _e, aI as eo, am as to, I as wt, H as no, L as $e, Q as Ot, R as _t, K as At } from "./bookmark-state-n7AaNzR_.js";
10
- import "./schema-C9NPiIru.js";
11
- import "./index-CV_Kzou0.js";
12
- import "./context-UCQ7sere.js";
13
- import { a as ro, i as oo } from "./matrix-analytical-definition-CCp48UCw.js";
14
- import { D as io } from "./report-runtime-context-c77_KF9v.js";
15
- import { isPdfTableCardType as ao, PDF_CAPACITY as so } from "../pdf-export-policy/index.js";
16
- import { a4 as Ze } from "./raw-temporal-value-Dg_MTFF7.js";
17
- import { g as Et } from "./metric-comparison-B0FR-Q8I.js";
18
- import { t as lo, c as co, n as uo } from "./selection-filter-compiler-DNijjI5y.js";
19
- const fo = (e, t) => {
20
- const n = {};
21
- if (e === null || t === null)
22
- return t;
23
- const r = /* @__PURE__ */ new Set([...Object.keys(e), ...Object.keys(t)]);
24
- for (const o of r) {
25
- if (!(o in e) && o in t) {
26
- n[o] = t[o];
27
- continue;
28
- }
29
- if (o in e && !(o in t)) {
30
- n[o] = void 0;
31
- continue;
32
- }
33
- const i = e[o], a = t[o];
34
- if (!ve(i, a))
35
- if (Array.isArray(i) && Array.isArray(a))
36
- n[o] = a;
37
- else if (We(i) && We(a)) {
38
- const s = fo(i, a);
39
- Object.keys(s).length > 0 && (n[o] = s);
40
- } else
41
- n[o] = a;
42
- }
43
- return n;
44
- }, ve = (e, t) => {
45
- if (e === t) return !0;
46
- if (e && t && typeof e == "object" && typeof t == "object") {
47
- if (Array.isArray(e) && Array.isArray(t))
48
- return e.length !== t.length ? !1 : e.every((o, i) => ve(o, t[i]));
49
- const n = Object.keys(e), r = Object.keys(t);
50
- return n.length !== r.length ? !1 : n.every((o) => ve(e[o], t[o]));
51
- }
52
- return !1;
53
- }, We = (e) => e !== null && typeof e == "object" && !Array.isArray(e), oe = (e) => {
54
- if (e === null || typeof e != "object")
55
- return e;
56
- if (e instanceof Date)
57
- return new Date(e);
58
- if (e instanceof RegExp)
59
- return new RegExp(e);
60
- if (Array.isArray(e))
61
- return e.map((n) => oe(n));
62
- const t = {};
63
- for (const n in e)
64
- Object.prototype.hasOwnProperty.call(e, n) && (t[n] = oe(e[n]));
65
- return t;
66
- }, po = /^(?:[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}|00000000-0000-0000-0000-000000000000)$/i;
67
- function mo(e) {
68
- return typeof e == "string" && po.test(e);
69
- }
70
- function go(e) {
71
- if (!mo(e))
72
- throw TypeError("Invalid UUID");
73
- let t;
74
- const n = new Uint8Array(16);
75
- return n[0] = (t = parseInt(e.slice(0, 8), 16)) >>> 24, n[1] = t >>> 16 & 255, n[2] = t >>> 8 & 255, n[3] = t & 255, n[4] = (t = parseInt(e.slice(9, 13), 16)) >>> 8, n[5] = t & 255, n[6] = (t = parseInt(e.slice(14, 18), 16)) >>> 8, n[7] = t & 255, n[8] = (t = parseInt(e.slice(19, 23), 16)) >>> 8, n[9] = t & 255, n[10] = (t = parseInt(e.slice(24, 36), 16)) / 1099511627776 & 255, n[11] = t / 4294967296 & 255, n[12] = t >>> 24 & 255, n[13] = t >>> 16 & 255, n[14] = t >>> 8 & 255, n[15] = t & 255, n;
76
- }
77
- function yo(e) {
78
- e = unescape(encodeURIComponent(e));
79
- const t = [];
80
- for (let n = 0; n < e.length; ++n)
81
- t.push(e.charCodeAt(n));
82
- return t;
83
- }
84
- const bo = "6ba7b810-9dad-11d1-80b4-00c04fd430c8", Io = "6ba7b811-9dad-11d1-80b4-00c04fd430c8";
85
- function Co(e, t, n) {
86
- function r(o, i, a, s) {
87
- var l;
88
- if (typeof o == "string" && (o = yo(o)), typeof i == "string" && (i = go(i)), ((l = i) === null || l === void 0 ? void 0 : l.length) !== 16)
89
- throw TypeError("Namespace must be array-like (16 iterable integer values, 0-255)");
90
- let c = new Uint8Array(16 + o.length);
91
- if (c.set(i), c.set(o, i.length), c = n(c), c[6] = c[6] & 15 | t, c[8] = c[8] & 63 | 128, a) {
92
- s = s || 0;
93
- for (let d = 0; d < 16; ++d)
94
- a[s + d] = c[d];
95
- return a;
96
- }
97
- return Vn(c);
98
- }
99
- try {
100
- r.name = e;
101
- } catch {
102
- }
103
- return r.DNS = bo, r.URL = Io, r;
104
- }
105
- function ho(e, t, n, r) {
106
- switch (e) {
107
- case 0:
108
- return t & n ^ ~t & r;
109
- case 1:
110
- return t ^ n ^ r;
111
- case 2:
112
- return t & n ^ t & r ^ n & r;
113
- case 3:
114
- return t ^ n ^ r;
115
- }
116
- }
117
- function Ie(e, t) {
118
- return e << t | e >>> 32 - t;
119
- }
120
- function vo(e) {
121
- const t = [1518500249, 1859775393, 2400959708, 3395469782], n = [1732584193, 4023233417, 2562383102, 271733878, 3285377520];
122
- if (typeof e == "string") {
123
- const a = unescape(encodeURIComponent(e));
124
- e = [];
125
- for (let s = 0; s < a.length; ++s)
126
- e.push(a.charCodeAt(s));
127
- } else Array.isArray(e) || (e = Array.prototype.slice.call(e));
128
- e.push(128);
129
- const r = e.length / 4 + 2, o = Math.ceil(r / 16), i = new Array(o);
130
- for (let a = 0; a < o; ++a) {
131
- const s = new Uint32Array(16);
132
- for (let l = 0; l < 16; ++l)
133
- s[l] = e[a * 64 + l * 4] << 24 | e[a * 64 + l * 4 + 1] << 16 | e[a * 64 + l * 4 + 2] << 8 | e[a * 64 + l * 4 + 3];
134
- i[a] = s;
135
- }
136
- i[o - 1][14] = (e.length - 1) * 8 / Math.pow(2, 32), i[o - 1][14] = Math.floor(i[o - 1][14]), i[o - 1][15] = (e.length - 1) * 8 & 4294967295;
137
- for (let a = 0; a < o; ++a) {
138
- const s = new Uint32Array(80);
139
- for (let m = 0; m < 16; ++m)
140
- s[m] = i[a][m];
141
- for (let m = 16; m < 80; ++m)
142
- s[m] = Ie(s[m - 3] ^ s[m - 8] ^ s[m - 14] ^ s[m - 16], 1);
143
- let l = n[0], c = n[1], d = n[2], u = n[3], f = n[4];
144
- for (let m = 0; m < 80; ++m) {
145
- const y = Math.floor(m / 20), p = Ie(l, 5) + ho(y, c, d, u) + f + t[y] + s[m] >>> 0;
146
- f = u, u = d, d = Ie(c, 30) >>> 0, c = l, l = p;
147
- }
148
- n[0] = n[0] + l >>> 0, n[1] = n[1] + c >>> 0, n[2] = n[2] + d >>> 0, n[3] = n[3] + u >>> 0, n[4] = n[4] + f >>> 0;
149
- }
150
- return [n[0] >> 24 & 255, n[0] >> 16 & 255, n[0] >> 8 & 255, n[0] & 255, n[1] >> 24 & 255, n[1] >> 16 & 255, n[1] >> 8 & 255, n[1] & 255, n[2] >> 24 & 255, n[2] >> 16 & 255, n[2] >> 8 & 255, n[2] & 255, n[3] >> 24 & 255, n[3] >> 16 & 255, n[3] >> 8 & 255, n[3] & 255, n[4] >> 24 & 255, n[4] >> 16 & 255, n[4] >> 8 & 255, n[4] & 255];
151
- }
152
- const Fo = Co("v5", 80, vo), Je = /\[\[\s*param\.([A-Za-z0-9_.-]+)\s*\]\]/g, Ye = /\bparam\s*\(\s*(['"])([^'"]+)\1/g;
153
- function Do(e) {
154
- const t = [];
155
- let n = 0;
156
- for (; n < e.length; ) {
157
- const r = e.indexOf("{{", n), o = e.indexOf("{%", n);
158
- let i = -1, a = "";
159
- if (r === -1 ? (i = o, a = "%}") : o === -1 || r < o ? (i = r, a = "}}") : (i = o, a = "%}"), i === -1)
160
- break;
161
- const s = e.indexOf(a, i + 2);
162
- if (s === -1) {
163
- n = i + 2;
164
- continue;
165
- }
166
- t.push(e.slice(i + 2, s)), n = s + 2;
167
- }
168
- return t;
169
- }
170
- function Bt(e) {
171
- var r, o;
172
- if (!e)
173
- return [];
174
- const t = /* @__PURE__ */ new Set();
175
- let n;
176
- for (Je.lastIndex = 0; (n = Je.exec(e)) !== null; ) {
177
- const i = (r = n[1]) == null ? void 0 : r.trim();
178
- i && t.add(i);
179
- }
180
- for (const i of Do(e))
181
- for (Ye.lastIndex = 0; (n = Ye.exec(i)) !== null; ) {
182
- const a = (o = n[2]) == null ? void 0 : o.trim();
183
- a && t.add(a);
184
- }
185
- return Array.from(t);
186
- }
187
- function Ae(e) {
188
- const t = /* @__PURE__ */ new Set(), n = /* @__PURE__ */ new Map();
189
- for (const r of e.controlBindings || [])
190
- t.add(r.controlId), r.target === "sql_param" && n.set(r.paramId, r.controlId);
191
- for (const r of Bt(e.sql))
192
- t.add(n.get(r) ?? r);
193
- return Array.from(t);
194
- }
195
- function So(e) {
196
- const t = /* @__PURE__ */ new Map(), n = /* @__PURE__ */ new Map();
197
- for (const r of e.controlBindings || [])
198
- r.target === "sql_param" && n.set(r.paramId, r.controlId);
199
- for (const r of Bt(e.sql))
200
- t.set(r, {
201
- paramId: r,
202
- controlId: n.get(r) ?? r
203
- });
204
- return Array.from(t.values());
205
- }
206
- function To(e, t) {
207
- var o;
208
- const n = (o = e.controlBindings) == null ? void 0 : o.map((i) => ({
209
- ...i,
210
- controlId: t.get(i.controlId) ?? i.controlId
211
- })), r = So(e).flatMap(
212
- ({ paramId: i, controlId: a }) => {
213
- var l;
214
- const s = t.get(a);
215
- return !s || s === a || (l = e.controlBindings) != null && l.some(
216
- (c) => c.target === "sql_param" && c.paramId === i
217
- ) ? [] : [{ target: "sql_param", paramId: i, controlId: s }];
218
- }
219
- );
220
- return r.length ? [...n ?? [], ...r] : n;
221
- }
222
- function Rt(e, t) {
223
- var a, s;
224
- const n = be(e) ?? e, r = n.source === "dashboardInputAlias" ? (a = t.inputAliases) == null ? void 0 : a[n.variableName] : void 0, o = n.source === "dashboardInputAlias" && r ? be(r) ?? be({ ...r, export: n.export ?? "label" }) ?? n : n, i = n.source === "dashboardInputAlias" && o !== n ? { ...o, export: n.export ?? "label" } : o;
225
- return i.source === "input" ? {
226
- ...i,
227
- inputId: ((s = t.inputIds) == null ? void 0 : s[i.inputId]) ?? i.inputId
228
- } : i;
229
- }
230
- function Vo(e, t) {
231
- var o;
232
- const n = {};
233
- for (const i of [
234
- "cardIds",
235
- "sheetIds",
236
- "inputIds",
237
- "controlIds",
238
- "filterIds"
239
- ]) {
240
- const a = { ...t[i] };
241
- for (const [s, l] of Object.entries((e == null ? void 0 : e[i]) ?? {}))
242
- a[s] = ((o = t[i]) == null ? void 0 : o[l]) ?? l;
243
- Object.keys(a).length && (n[i] = a);
244
- }
245
- const r = { ...t.inputAliases };
246
- for (const [i, a] of Object.entries((e == null ? void 0 : e.inputAliases) ?? {}))
247
- r[i] = Rt(a, t);
248
- return Object.keys(r).length && (n.inputAliases = r), n;
249
- }
250
- function ts(e, t) {
251
- var o, i, a, s;
252
- const n = oe(Mt(e));
253
- n.controlBindings = To(
254
- e,
255
- new Map(Object.entries(t.controlIds ?? {}))
256
- );
257
- for (const l of n.controls ?? [])
258
- l.id = ((o = t.controlIds) == null ? void 0 : o[l.id]) ?? l.id;
259
- for (const l of n.inlineFilters ?? [])
260
- l.id = ((i = t.filterIds) == null ? void 0 : i[l.id]) ?? l.id;
261
- const r = (l) => {
262
- var d;
263
- if (!l || typeof l != "object") return;
264
- if (Array.isArray(l)) {
265
- l.forEach(r);
266
- return;
267
- }
268
- const c = l;
269
- if (Object.assign(
270
- c,
271
- kt(
272
- c,
273
- (u) => u && typeof u == "object" ? Rt(u, t) : u
274
- )
275
- ), typeof c.entityId == "string") {
276
- const u = c.entityId;
277
- c.fieldScope === "card" && (c.entityId = ((d = t.cardIds) == null ? void 0 : d[u]) ?? u);
278
- }
279
- for (const [u, f] of Object.entries(c))
280
- u !== "linkedReferenceOverrides" && r(f);
281
- };
282
- r(n), n.clickToFilter && (n.clickToFilter = Mn(n.clickToFilter, t));
283
- for (const l of Object.values(
284
- ((a = n.customCardPreferences) == null ? void 0 : a.dataInputCardIds) ?? {}
285
- ))
286
- l.cardId = ((s = t.cardIds) == null ? void 0 : s[l.cardId]) ?? l.cardId;
287
- return n;
288
- }
289
- const Mo = "9677efdd-86ec-4afb-b9bb-5ead8b5442af";
290
- function ko(e) {
291
- let t = 0;
292
- return () => Fo(`${e}#${t++}`, Mo);
293
- }
294
- const xo = [
295
- { code: "matrix_definition_incomplete", label: "Matrix definition" }
296
- ], Po = [
297
- { code: "connection_type_unresolved", label: "Connection type" }
298
- ], G = (e) => !Array.isArray(e) || e.length === 0;
299
- function wo(e) {
300
- var i;
301
- const t = e.config ?? {};
302
- if ((i = e.sql) != null && i.trim() || !G(t.pivotByColumns)) return "matrixTable";
303
- const n = !G(t.groupByColumns), r = !G(t.metricColumns), o = e.type === "pivotTable" && (n || r) && G(t.rowAggregates) && G(t.columnAggregates);
304
- return n && !r || o ? "table" : "matrixTable";
305
- }
306
- function Oo(e) {
307
- var o;
308
- const t = e.dataSource;
309
- if (!t || (o = t.connectionType) != null && o.trim()) return e;
310
- const n = Br(On(t.selectedEntities));
311
- if (!n) return e;
312
- const r = Array.isArray(t.selectedEntities) ? t.selectedEntities.map((i) => i && typeof i == "object" && "connectionType" in i && !String(i.connectionType ?? "").trim() ? { ...i, connectionType: n } : i) : t.selectedEntities;
313
- return { ...e, dataSource: { ...t, connectionType: n, selectedEntities: r } };
314
- }
315
- function qt(e) {
316
- var a, s;
317
- const t = e;
318
- if (!kn(t)) return { status: "not_legacy", card: e };
319
- const n = Oo(t), r = wo(t) === "table" ? xn(n, "table") : Pn(n, "matrixTable", { createId: ko(t.id) });
320
- if (r.status !== "changed") throw new Error(`Card ${t.id} could not leave ${t.type}.`);
321
- const o = r.card.type === "matrixTable" && wn(r.card).status !== "ready", i = !!n.dataSource && !((s = (a = n.dataSource) == null ? void 0 : a.connectionType) != null && s.trim());
322
- return {
323
- status: "routed",
324
- card: r.card,
325
- gaps: [
326
- ...r.gaps,
327
- ...o ? xo : [],
328
- ...i ? Po : []
329
- ]
330
- };
331
- }
332
- function ns(e) {
333
- if (!e.cards) return e;
334
- const t = e.cards.map((n) => qt(n).card);
335
- return t.every((n, r) => n === e.cards[r]) ? e : { ...e, cards: t };
336
- }
337
- function _o(e) {
338
- const t = [];
339
- return { dashboard: Wr(e, (r, o) => {
340
- const i = qt(r);
341
- return i.status === "routed" && i.gaps.length && t.push({ location: o, gaps: i.gaps }), i.card;
342
- }), routedWithGaps: t };
343
- }
344
- function Ao(e, t) {
345
- return e.name === t.name && e.qualifiedEntityName === t.qualifiedEntityName;
346
- }
347
- function Eo(e, t, n) {
348
- var o, i;
349
- if (n.sortPolicy === "dropUnrelatedSorts") {
350
- const a = new Set(
351
- (e.metricColumns || []).map((s) => s.id)
352
- );
353
- return {
354
- ...e,
355
- groupByColumns: [t],
356
- sortByColumns: (e.sortByColumns || []).filter(
357
- (s) => s.id === t.id || a.has(s.id)
358
- )
359
- };
360
- }
361
- const r = (o = e.groupByColumns) == null ? void 0 : o[0];
362
- return {
363
- ...e,
364
- groupByColumns: [t],
365
- sortByColumns: (i = e.sortByColumns) == null ? void 0 : i.map(
366
- (a) => r && Ao(a, r) ? {
367
- ...t,
368
- role: "sortby",
369
- direction: a.direction
370
- } : a
371
- )
372
- };
373
- }
374
- function ie(e) {
375
- return e == null ? void 0 : e.map(
376
- ({
377
- format: t,
378
- formatOrigin: n,
379
- semanticTemporalPresentation: r,
380
- ...o
381
- }) => o
382
- );
383
- }
384
- function ae(e) {
385
- if (!e)
386
- return;
387
- const {
388
- format: t,
389
- formatOrigin: n,
390
- semanticTemporalPresentation: r,
391
- ...o
392
- } = e;
393
- return Q(o);
394
- }
395
- function jt(e, t) {
396
- return e == null ? void 0 : e.map(
397
- (n) => dt(Q(ie([n])[0]), n.format, t)
398
- );
399
- }
400
- function Bo(e, t) {
401
- return e == null ? void 0 : e.map(
402
- (n) => _n(Q(ie([n])[0]), n.format, t)
403
- );
404
- }
405
- function Ro(e, t) {
406
- const { dateFormat: n, customFormat: r, ...o } = ae(e.field);
407
- return {
408
- ...e,
409
- field: t ? o : dt(ae(e.field), e.field.format, "raw")
410
- };
411
- }
412
- function me(e, t = !1) {
413
- if (e)
414
- return {
415
- ...e,
416
- conditions: e.conditions.map((n) => Ro(n, t)),
417
- groups: e.groups.map((n) => me(n, t))
418
- };
419
- }
420
- function Q(e) {
421
- var n, r;
422
- const t = { ...e };
423
- return (n = t.calculatedFormula) != null && n.inputFields && (t.calculatedFormula = {
424
- ...t.calculatedFormula,
425
- inputFields: t.calculatedFormula.inputFields.map(
426
- (o) => ae(o)
427
- )
428
- }), (r = t.parameters) != null && r.filters && (t.parameters = {
429
- ...t.parameters,
430
- filters: me(t.parameters.filters)
431
- }), t;
432
- }
433
- function qo(e, t) {
434
- return t.cardType === "detailTable" || !An(t.cardType) || t.temporalResultOwner !== "config" ? jt(e, "grouped") : e == null ? void 0 : e.map((n) => {
435
- const r = En(n), o = ae(r ?? n);
436
- if (!r)
437
- return o;
438
- const { dateFormat: i, customFormat: a, ...s } = o;
439
- return s;
440
- });
441
- }
442
- function Nt(e, t) {
443
- if (!e)
444
- return;
445
- const n = { type: t.cardType, config: e };
446
- return Te(n) ? jo(n, t) : e.matrix === void 0 ? {} : { matrix: e.matrix };
447
- }
448
- function jo(e, t = {}) {
449
- var i, a, s;
450
- const n = e.config;
451
- if (!n) return;
452
- const r = { ...t, cardType: e.type };
453
- return {
454
- ...n,
455
- groupByColumns: qo(n.groupByColumns, r),
456
- metricColumns: (i = ie(n.metricColumns)) == null ? void 0 : i.map(
457
- Q
458
- ),
459
- pivotByColumns: jt(n.pivotByColumns, "grouped"),
460
- sortByColumns: (a = ie(n.sortByColumns)) == null ? void 0 : a.map(
461
- Q
462
- ),
463
- detailColumns: Bo(n.detailColumns, (s = r.dataSource) == null ? void 0 : s.connectionType),
464
- filters: me(n.filters)
465
- };
466
- }
467
- function se(e) {
468
- return (e == null ? void 0 : e.type) === "number" || (e == null ? void 0 : e.type) === "currency";
469
- }
470
- function No(e) {
471
- return (e == null ? void 0 : e.type) === "number";
472
- }
473
- function zo(e) {
474
- var n;
475
- if (!No(e))
476
- return !1;
477
- const t = (n = e == null ? void 0 : e.numberFormat) == null ? void 0 : n.style;
478
- return t === void 0 || t === "decimal" || t === "currency";
479
- }
480
- function Lo(e, t) {
481
- const n = t == null ? void 0 : t.type;
482
- if (n && n !== "none" && n !== "number")
483
- return { currencyBindable: !1 };
484
- const r = n === "number" ? t != null && t.numberFormat ? Rn(t.numberFormat, {
485
- preserveOmittedProperties: !0
486
- }) : { type: "number" } : void 0, o = re(e.format, {
487
- preserveOmittedProperties: !0
488
- }), i = Z(e.dataType) === "number" ? { type: "number" } : void 0, s = (t == null ? void 0 : t.inheritMetricFormat) === !1 || !!(t != null && t.numberFormat) && (t == null ? void 0 : t.inheritMetricFormat) !== !0 ? r : o || i || r;
489
- return {
490
- authoredFormat: s,
491
- currencyBindable: se(s)
492
- };
493
- }
494
- function Ko(e, t) {
495
- const n = re(t.format, {
496
- preserveOmittedProperties: !0
497
- }), r = Z(t.dataType) === "number" ? { type: "number" } : void 0, o = n || r;
498
- return {
499
- authoredFormat: o,
500
- source: n ? "semantic" : r ? "inferred" : void 0,
501
- currencyBindable: se(o)
502
- };
503
- }
504
- function Fe(e, t = {}) {
505
- var l, c, d;
506
- const n = t.column ?? ((l = Bn(e)) == null ? void 0 : l.value);
507
- if ((n == null ? void 0 : n.kind) === "sqlKpiValue") {
508
- const u = t.resultColumnKey ? {
509
- kind: "column",
510
- columnKey: t.resultColumnKey
511
- } : void 0, f = re(
512
- Ur({ card: e, column: { kind: "sqlKpiValue" }, surface: "kpiValue" }).format,
513
- { preserveOmittedProperties: !0 }
514
- );
515
- return {
516
- target: u,
517
- authoredFormat: f,
518
- ...f ? { source: "stored" } : {},
519
- currencyBindable: !!u && se(f)
520
- };
521
- }
522
- const r = n ? (d = (c = e.config) == null ? void 0 : c.metricColumns) == null ? void 0 : d.find((u) => u.id === n.fieldId) : void 0, o = r != null && r.id ? {
523
- kind: "metric",
524
- metricId: r.id
525
- } : void 0, i = re(r == null ? void 0 : r.format, {
526
- preserveOmittedProperties: !0
527
- }), a = Z(r == null ? void 0 : r.dataType) === "number" ? { type: "number" } : void 0, s = i || a;
528
- return {
529
- target: o,
530
- authoredFormat: s,
531
- ...i ? { source: "stored" } : a ? { source: "inferred" } : {},
532
- currencyBindable: ut(e.type) && !!o && se(s)
533
- };
534
- }
535
- function zt(e, t, n) {
536
- var o;
537
- const r = n(e, t);
538
- return ((o = e.derivedField) == null ? void 0 : o.format) ?? (r == null ? void 0 : r.format) ?? (r == null ? void 0 : r.resolvedField.format);
539
- }
540
- function Lt(e, t, n) {
541
- return e.kind === "calculated" ? e.definition.format : zt(e.field, t, n);
542
- }
543
- function rs(e, t) {
544
- const n = ft(t), r = (o, i) => Object.fromEntries(o.flatMap((a) => {
545
- const s = i(a);
546
- return s ? [[a.id, s]] : [];
547
- }));
548
- return {
549
- measureFormats: r(e.measures, (o) => Lt(o, e.source, n)),
550
- levelFormats: r([...e.rows, ...e.columns], (o) => zt(o.field, e.source, n))
551
- };
552
- }
553
- function Kt(e, t = []) {
554
- const n = Ve(e);
555
- if (n.status !== "ready") return [];
556
- const { spec: r, presentation: o } = n.config, i = ft(t);
557
- return r.measures.map((a) => {
558
- var m;
559
- const s = a.kind === "aggregate" ? i(a.field, r.source) : void 0, l = Qr(o.measureFormats[a.id], Lt(a, r.source, i)), c = a.kind === "calculated" ? a.definition.dataType : ["MIN", "MAX"].includes(a.aggregate) ? ((m = a.field.derivedField) == null ? void 0 : m.dataType) ?? (s == null ? void 0 : s.resolvedField.dataType) ?? a.field.dataType : "number", d = Z(c) === "number", u = a.kind === "calculated" || !!(s || a.field.derivedField || a.field.name === "*"), f = l && $r(l) ? l : !l && d && u ? { type: "number" } : void 0;
560
- return { measureId: a.id, label: Zr(a, o), canonical: f };
561
- });
562
- }
563
- function Go(e) {
564
- var t, n;
565
- return e.type === "detailTable" ? ((t = e.config) == null ? void 0 : t.detailColumns) || [] : ((n = e.config) == null ? void 0 : n.metricColumns) || [];
566
- }
567
- function Gt(e) {
568
- return new Set(
569
- xt(e).flatMap(
570
- (t) => (t.controlBindings || []).filter(de).map((n) => n.controlId)
571
- )
572
- );
573
- }
574
- function Ho(e, t) {
575
- const n = [
576
- t.id,
577
- t.alias,
578
- t.label,
579
- t.name,
580
- t.qualifiedFieldName
581
- ].filter((i) => !!i);
582
- for (const i of n)
583
- if (e[i])
584
- return e[i];
585
- const r = new Set(
586
- n.map((i) => i.trim().toLowerCase())
587
- ), o = Object.entries(e).find(
588
- ([i]) => r.has(i.trim().toLowerCase())
589
- );
590
- return o == null ? void 0 : o[1];
591
- }
592
- function Xe(e) {
593
- return [
594
- ...new Map(
595
- e.map((t) => [
596
- z(t),
597
- t
598
- ])
599
- ).values()
600
- ];
601
- }
602
- function Uo(e, t = [], n) {
603
- var S;
604
- const r = !!((S = e.sql) != null && S.trim()), o = ut(e.type), i = r && o && e.type !== "kpi" && e.type !== "matrixTable", a = Go(e), s = qn(e), l = !r && e.type === "kpi" ? a.map(
605
- (g) => Fe(e, {
606
- column: { kind: "field", fieldId: g.id }
607
- })
608
- ) : [], c = !r && e.type === "matrixTable" ? Kt(e, n) : [], d = (r ? [] : a).map(
609
- (g) => ({
610
- kind: "metric",
611
- metricId: g.id
612
- })
613
- ), u = c.map(
614
- (g) => ({
615
- kind: "matrix_measure",
616
- measureId: g.measureId
617
- })
618
- ), f = c.filter((g) => {
619
- var V, P;
620
- return ((V = g.canonical) == null ? void 0 : V.type) === "number" || ((P = g.canonical) == null ? void 0 : P.type) === "currency";
621
- }).map(
622
- (g) => ({
623
- kind: "matrix_measure",
624
- measureId: g.measureId
625
- })
626
- ), m = e.type === "matrixTable" ? [] : e.type === "kpi" ? l.filter((g) => g.currencyBindable).flatMap(
627
- (g) => g.target ? [g.target] : []
628
- ) : (r || !o ? [] : a).filter(
629
- (g) => (jn(e.type) ? Lo(
630
- g,
631
- Ho(s, g)
632
- ) : Ko(e, g)).currencyBindable
633
- ).map(
634
- (g) => ({
635
- kind: "metric",
636
- metricId: g.id
637
- })
638
- ), y = [...new Set(t)], p = (i ? y : []).map(
639
- (g) => ({
640
- kind: "column",
641
- columnKey: g
642
- })
643
- ), b = (i ? y : []).filter(
644
- (g) => zo(
645
- s[g]
646
- )
647
- ).map(
648
- (g) => ({
649
- kind: "column",
650
- columnKey: g
651
- })
652
- ), I = (r && e.type === "kpi" ? y.slice(0, 1) : []).map(
653
- (g) => ({
654
- kind: "column",
655
- columnKey: g
656
- })
657
- ), C = r && e.type === "kpi" ? Fe(e, {
658
- resultColumnKey: y[0]
659
- }) : void 0, h = o && (C != null && C.currencyBindable) ? I : [];
660
- return {
661
- knownTargets: Xe([
662
- ...e.type === "matrixTable" ? u : d,
663
- ...p,
664
- ...I
665
- ]),
666
- eligibleTargets: Xe([
667
- ...m,
668
- ...f,
669
- ...b,
670
- ...h
671
- ])
672
- };
673
- }
674
- function os(e, t) {
675
- const n = Fe(e, {
676
- resultColumnKey: t
677
- });
678
- return n.currencyBindable ? n.target : void 0;
679
- }
680
- function is(e) {
681
- var t;
682
- return (t = e.card.sql) != null && t.trim() ? { kind: "column", columnKey: e.columnKey } : e.metricId ? { kind: "metric", metricId: e.metricId } : void 0;
683
- }
684
- function z(e) {
685
- return e.kind === "metric" ? `metric:${e.metricId}` : e.kind === "column" ? `column:${e.columnKey}` : `matrix_measure:${e.measureId}`;
686
- }
687
- function Qo(e) {
688
- if (!e || typeof e != "object" || Array.isArray(e))
689
- return;
690
- const t = e;
691
- if (t.kind === "metric" && typeof t.metricId == "string" && t.metricId.trim())
692
- return { kind: "metric", metricId: t.metricId };
693
- if (t.kind === "column" && typeof t.columnKey == "string" && t.columnKey.trim())
694
- return { kind: "column", columnKey: t.columnKey };
695
- if (t.kind === "matrix_measure" && typeof t.measureId == "string" && t.measureId.trim())
696
- return { kind: "matrix_measure", measureId: t.measureId };
697
- }
698
- function et(e) {
699
- const t = Vt(e);
700
- return typeof e == "string" && e === t ? t : void 0;
701
- }
702
- function Ht(e) {
703
- if (e.type !== "enum" || e.source.kind !== "manual")
704
- return { diagnostic: "invalid_control_type" };
705
- const t = e.source.options.map(
706
- (n) => et(n.value)
707
- );
708
- if (t.length === 0 || t.some((n) => !n))
709
- return { diagnostic: "invalid_currency_option" };
710
- if (e.requiredAtExecution) {
711
- const n = e.initialValueStrategy === "saved_default" ? et(e.defaultValue) : void 0;
712
- if (!n || !t.includes(n))
713
- return { diagnostic: "invalid_control_default" };
714
- }
715
- return {
716
- control: e,
717
- currencies: t
718
- };
719
- }
720
- function as(e) {
721
- return "control" in Ht(e);
722
- }
723
- function Ut(e) {
724
- const t = Gt(e.dashboard);
725
- if (t.size === 0)
726
- return {
727
- definitions: e.definitions || [],
728
- values: e.values || {}
729
- };
730
- const n = new Set(
731
- [...t].filter(
732
- (r) => !e.referencedControlIds.has(r)
733
- )
734
- );
735
- return {
736
- definitions: (e.definitions || []).filter(
737
- (r) => !n.has(r.id)
738
- ),
739
- values: Object.fromEntries(
740
- Object.entries(e.values || {}).filter(
741
- ([r]) => !n.has(r)
742
- )
743
- )
744
- };
745
- }
746
- function ss(e) {
747
- return Ut({
748
- ...e,
749
- referencedControlIds: new Set(
750
- Ae({
751
- sql: e.filterSql,
752
- controlBindings: []
753
- })
754
- )
755
- });
756
- }
757
- function ls(e) {
758
- var t;
759
- return Ut({
760
- ...e,
761
- referencedControlIds: new Set(
762
- Ae({
763
- sql: (t = e.source) == null ? void 0 : t.sql,
764
- controlBindings: []
765
- })
766
- )
767
- });
768
- }
769
- function Qt(e) {
770
- return {
771
- knownKeys: new Set(
772
- e.knownTargets.map(z)
773
- ),
774
- eligibleKeys: new Set(
775
- e.eligibleTargets.map(z)
776
- ),
777
- controlsById: new Map(
778
- (e.controls || []).map((t) => [t.id, t])
779
- )
780
- };
781
- }
782
- function $t(e, t) {
783
- if (!e || typeof e != "object" || e.target !== "presentation_currency")
784
- return {};
785
- const n = e, r = typeof n.controlId == "string" && n.controlId.trim() ? n.controlId : void 0;
786
- if (!r)
787
- return { diagnostic: { code: "invalid_binding_shape" } };
788
- const o = Qo(
789
- n.presentationTarget
790
- );
791
- if (!o)
792
- return {
793
- diagnostic: { code: "missing_target", controlId: r }
794
- };
795
- const i = z(o);
796
- if (!t.knownKeys.has(i))
797
- return {
798
- diagnostic: { code: "stale_target", controlId: r }
799
- };
800
- if (!t.eligibleKeys.has(i))
801
- return {
802
- diagnostic: { code: "inapplicable_target", controlId: r }
803
- };
804
- const a = t.controlsById.get(r);
805
- if (!a)
806
- return {
807
- diagnostic: { code: "missing_control", controlId: r }
808
- };
809
- const s = Ht(a);
810
- return "diagnostic" in s ? {
811
- diagnostic: { code: s.diagnostic, controlId: r }
812
- } : {
813
- binding: {
814
- controlId: r,
815
- presentationTarget: o,
816
- control: s.control,
817
- currencies: s.currencies
818
- }
819
- };
820
- }
821
- function cs(e) {
822
- const t = Qt(e);
823
- return (e.bindings || []).flatMap((n) => {
824
- const r = $t(n, t);
825
- return "diagnostic" in r ? [r.diagnostic] : [];
826
- });
827
- }
828
- function $o(e) {
829
- var o;
830
- const t = [], n = z(e.target), r = Qt(e);
831
- for (const i of e.bindings || []) {
832
- const a = $t(i, r);
833
- if ("diagnostic" in a) {
834
- t.push(a.diagnostic);
835
- continue;
836
- }
837
- const s = a.binding;
838
- if (!s || z(
839
- s.presentationTarget
840
- ) !== n) continue;
841
- const c = Vt(
842
- (o = e.values) == null ? void 0 : o[s.control.id]
843
- );
844
- if (!(!c || !s.currencies.includes(c)))
845
- return { currency: c, diagnostics: t };
846
- }
847
- return { diagnostics: t };
848
- }
849
- function Zo(e, t, n, r) {
850
- const o = { ...e, config: { ...e.config, matrix: t } }, i = Uo(o, [], r), a = Kt(o, r), s = { ...t.presentation.measureFormats };
851
- for (const l of a) {
852
- const c = { kind: "matrix_measure", measureId: l.measureId }, { currency: d } = $o({
853
- ...n,
854
- ...i,
855
- bindings: e.controlBindings,
856
- target: c
857
- });
858
- if (!d || !l.canonical) continue;
859
- const { locale: u, ...f } = l.canonical;
860
- s[l.measureId] = { ...f, type: "currency", currency: d };
861
- }
862
- return { ...t.presentation, measureFormats: s };
863
- }
864
- function Wo(e, t) {
865
- if (!e || typeof e != "object" || !("kind" in e))
866
- return e;
867
- switch (e.kind) {
868
- case "manual":
869
- return {
870
- kind: "manual",
871
- ...t != null && t.includePresentation ? {
872
- options: e.options.map((n) => ({
873
- value: n.value,
874
- label: n.label,
875
- presentation: n.presentation
876
- }))
877
- } : {
878
- optionValues: e.options.map((n) => n.value).sort()
879
- }
880
- };
881
- case "dataset_values":
882
- return {
883
- kind: "dataset_values",
884
- fieldId: e.fieldId,
885
- connectionId: e.connectionId || ""
886
- };
887
- case "field_allowlist":
888
- return {
889
- kind: "field_allowlist",
890
- fieldIds: [...e.fieldIds].sort()
891
- };
892
- case "metric_allowlist":
893
- return {
894
- kind: "metric_allowlist",
895
- metricIds: [...e.metricIds].sort()
896
- };
897
- case "sql_query":
898
- return {
899
- kind: "sql_query",
900
- connectionId: e.connectionId,
901
- sql: e.sql,
902
- valueColumn: e.valueColumn,
903
- labelColumn: e.labelColumn
904
- };
905
- default:
906
- return e;
907
- }
908
- }
909
- function Jo(e, t) {
910
- return {
911
- id: e.id,
912
- scope: e.scope,
913
- type: e.type,
914
- source: Wo(e.source, t),
915
- initialValueStrategy: e.initialValueStrategy,
916
- defaultValue: e.defaultValue,
917
- requiredAtExecution: e.requiredAtExecution,
918
- ...t != null && t.includePresentation ? {
919
- label: e.label,
920
- helpText: e.helpText,
921
- hidden: e.hidden,
922
- locked: e.locked,
923
- placement: e.placement,
924
- showLabel: e.showLabel,
925
- toolbarWidth: e.toolbarWidth
926
- } : {}
927
- };
928
- }
929
- function Yo(e, t) {
930
- return e.target === "sql_param" || e.target === "presentation_currency" ? e : e.target === "config_field_selector" && !(t != null && t.includePresentation) ? {
931
- ...e,
932
- mapping: Object.fromEntries(
933
- Object.entries(e.mapping).sort(([n], [r]) => n.localeCompare(r)).map(([n, r]) => {
934
- if ("kind" in r) return [n, r];
935
- const o = { ...r };
936
- return delete o.format, delete o.dateFormat, delete o.customFormat, delete o.semanticTemporalPresentation, [n, o];
937
- })
938
- )
939
- } : {
940
- ...e,
941
- mapping: Object.fromEntries(
942
- Object.entries(e.mapping).sort(([n], [r]) => n.localeCompare(r)).map(([n, r]) => [
943
- n,
944
- r && typeof r == "object" && !Array.isArray(r) ? Object.fromEntries(
945
- Object.entries(r).sort(
946
- ([o], [i]) => o.localeCompare(i)
947
- )
948
- ) : r
949
- ])
950
- )
951
- };
952
- }
953
- function tt(e = [], t) {
954
- return [...e].map((n) => Jo(n, t)).sort(
955
- (n, r) => n.id.localeCompare(r.id) || n.scope.localeCompare(r.scope) || n.type.localeCompare(r.type)
956
- );
957
- }
958
- function Xo(e = [], t) {
959
- return e.filter(
960
- (n) => (t == null ? void 0 : t.includePresentation) || !de(n)
961
- ).map((n) => Yo(n, t)).sort(
962
- (n, r) => _(n).localeCompare(_(r))
963
- );
964
- }
965
- function ei(e, t) {
966
- return e ? _({
967
- controlDefinitions: tt(e.controlDefinitions, t),
968
- cardControlDefinitions: tt(
969
- e.cardControlDefinitions,
970
- t
971
- ),
972
- controlBindings: Xo(e.controlBindings, t)
973
- }) : "__none__";
974
- }
975
- const ti = ["table", "detailTable"], nt = (e) => ti.includes(e.type), ni = "calendar-context";
976
- function ri(e) {
977
- const { id: t, label: n, field: r, ...o } = e;
978
- return {
979
- ...o,
980
- field: Ee(
981
- r
982
- )
983
- };
984
- }
985
- function ge(e) {
986
- if (!e)
987
- return;
988
- const { id: t, conditions: n, groups: r, ...o } = e;
989
- return {
990
- ...o,
991
- conditions: n.map(ri),
992
- groups: r.map((i) => ge(i))
993
- };
994
- }
995
- function Ee(e) {
996
- var r, o;
997
- const { label: t, ...n } = e;
998
- return {
999
- ...n,
1000
- ...(r = e.calculatedFormula) != null && r.inputFields ? {
1001
- calculatedFormula: {
1002
- ...e.calculatedFormula,
1003
- inputFields: e.calculatedFormula.inputFields.map(
1004
- Ee
1005
- )
1006
- }
1007
- } : {},
1008
- ...(o = e.parameters) != null && o.filters ? {
1009
- parameters: {
1010
- ...e.parameters,
1011
- filters: ge(
1012
- e.parameters.filters
1013
- )
1014
- }
1015
- } : {}
1016
- };
1017
- }
1018
- function oi(e) {
1019
- const t = (n) => n == null ? void 0 : n.map(Ee);
1020
- return {
1021
- ...e,
1022
- groupByColumns: t(e.groupByColumns),
1023
- metricColumns: t(e.metricColumns),
1024
- pivotByColumns: t(e.pivotByColumns),
1025
- sortByColumns: t(e.sortByColumns),
1026
- detailColumns: t(e.detailColumns),
1027
- filters: e.filters ? ge(e.filters) : void 0
1028
- };
1029
- }
1030
- function ii(e, t, n) {
1031
- if (!e)
1032
- return JSON.stringify(e);
1033
- if (n === "matrixTable" && e.matrix) return _(ro(e.matrix.spec));
1034
- const { matrix: r, ...o } = e, i = t ? oi(o) : o;
1035
- return JSON.stringify({
1036
- ...i,
1037
- filters: ge(i.filters)
1038
- });
1039
- }
1040
- function ai(e) {
1041
- if (!e)
1042
- return null;
1043
- const { format: t, ...n } = e;
1044
- return n;
1045
- }
1046
- function si(e, t) {
1047
- const n = /* @__PURE__ */ new Map();
1048
- for (const o of (t == null ? void 0 : t.controlDefinitions) || [])
1049
- n.set(o.id, o.type);
1050
- for (const o of (t == null ? void 0 : t.cardControlDefinitions) || [])
1051
- n.set(o.id, o.type);
1052
- const r = Object.fromEntries(
1053
- Object.entries(e || {}).map(([o, i]) => n.get(o) === "multi_enum" && Array.isArray(i) ? [
1054
- o,
1055
- [...i].sort(
1056
- (a, s) => _(a).localeCompare(_(s))
1057
- )
1058
- ] : [o, i])
1059
- );
1060
- return _(r);
1061
- }
1062
- function li(e, {
1063
- finalFiltersKey: t,
1064
- cardFilterValues: n,
1065
- controlValues: r,
1066
- controlDefinitions: o,
1067
- cardControlDefinitions: i,
1068
- controlBindings: a,
1069
- queryRelevantConfig: s,
1070
- resolvedPrimaryDateField: l,
1071
- globalDateComparison: c,
1072
- calendarContext: d
1073
- }) {
1074
- const { filterColumns: u, ...f } = e.queryConfig || {}, m = u == null ? void 0 : u.filter(
1075
- (h) => {
1076
- var S, g;
1077
- return (g = (S = e.queryConfig) == null ? void 0 : S.filters) == null ? void 0 : g.some((V) => V.filterColumnName === h.name);
1078
- }
1079
- ), y = (e == null ? void 0 : e.sql) || "", p = Me((e == null ? void 0 : e.python) || ""), b = ["table", "detailTable", "matrixTable"].includes(
1080
- e.type
1081
- ) ? "table" : e.type === "kpi" ? "kpi" : "chart", I = s || Nt(e.config, { cardType: e.type, dataSource: e.dataSource }), C = Nn.includes(
1082
- e.type
1083
- );
1084
- return [
1085
- "query",
1086
- e == null ? void 0 : e.id,
1087
- b,
1088
- y,
1089
- p,
1090
- JSON.stringify(n),
1091
- si(r, {
1092
- controlDefinitions: o,
1093
- cardControlDefinitions: i
1094
- }),
1095
- ei({
1096
- controlDefinitions: o,
1097
- cardControlDefinitions: i,
1098
- controlBindings: a
1099
- }),
1100
- _(
1101
- ai(l)
1102
- ),
1103
- _(c ?? null),
1104
- ni,
1105
- _(d),
1106
- JSON.stringify(f),
1107
- JSON.stringify(m),
1108
- ii(
1109
- I,
1110
- C,
1111
- e.type
1112
- ),
1113
- t
1114
- ];
1115
- }
1116
- function ci(e, t, n) {
1117
- var s, l, c;
1118
- const r = li(e, t), o = _(r), i = ((s = n == null ? void 0 : n.resolvePaginationConfig) == null ? void 0 : s.call(n, o)) ?? e.paginationConfig, a = nt(e) && ue(e.config) || nt(e) && e.sql && ((c = (l = e.preferences) == null ? void 0 : l.tablePrefs) == null ? void 0 : c.enableDevModePagination);
1119
- return {
1120
- queryKey: [
1121
- ...r,
1122
- a ? JSON.stringify(i) : ""
1123
- ],
1124
- queryInputIdentity: o,
1125
- paginationConfig: i
1126
- };
1127
- }
1128
- function di(e, t, n, r) {
1129
- return ci(
1130
- e,
1131
- {
1132
- finalFiltersKey: t.finalFiltersKey,
1133
- cardFilterValues: t.cardFilterValues,
1134
- controlValues: t.controlValues,
1135
- controlDefinitions: t.controlDefinitions,
1136
- cardControlDefinitions: t.cardControlDefinitions,
1137
- controlBindings: t.controlBindings,
1138
- queryRelevantConfig: t.queryRelevantConfig,
1139
- resolvedPrimaryDateField: t.resolvedPrimaryDateField || void 0,
1140
- globalDateComparison: t.globalDateComparison,
1141
- calendarContext: n
1142
- },
1143
- r
1144
- );
1145
- }
1146
- const ui = 500, fi = 250;
1147
- function De(e) {
1148
- return e.type === "table" || e.type === "detailTable";
1149
- }
1150
- function pi(e) {
1151
- var t, n, r;
1152
- return !!((t = e.sql) != null && t.trim() && De(e) && ((r = (n = e.preferences) == null ? void 0 : n.tablePrefs) != null && r.enableDevModePagination));
1153
- }
1154
- function ds(e) {
1155
- return e === "export-full-with-cap" ? ui : fi;
1156
- }
1157
- function mi({
1158
- card: e,
1159
- isTablePrintMode: t,
1160
- isDocumentSectionRuntime: n,
1161
- documentTableDataPolicy: r
1162
- }) {
1163
- var l, c;
1164
- const o = n && r !== void 0 && De(e), i = t && !o, a = ue(e.config) && De(e) && !e.sql, s = o ? pi(e) : !!(e.sql && ((c = (l = e.preferences) == null ? void 0 : l.tablePrefs) != null && c.enableDevModePagination));
1165
- return !i && (a || s);
1166
- }
1167
- function gi(e) {
1168
- var t, n, r;
1169
- return ((t = e.paginationConfig) == null ? void 0 : t.pageSize) || ((r = (n = e.preferences) == null ? void 0 : n.tablePrefs) == null ? void 0 : r.pageSize) || 50;
1170
- }
1171
- function us({
1172
- current: e,
1173
- defaultPageSize: t,
1174
- queryInputIdentity: n
1175
- }) {
1176
- return (e == null ? void 0 : e.queryInputIdentity) === n ? {
1177
- page: e.page,
1178
- pageSize: e.pageSize
1179
- } : {
1180
- page: 1,
1181
- pageSize: (e == null ? void 0 : e.pageSize) ?? t
1182
- };
1183
- }
1184
- function fs(e, t, n) {
1185
- return (e == null ? void 0 : e.queryInputIdentity) === n && e.page === t.page && e.pageSize === t.pageSize;
1186
- }
1187
- function ps(e, t) {
1188
- return !e || !t || e.page === t.page && e.pageSize === t.pageSize ? e : {
1189
- ...e,
1190
- page: t.page,
1191
- pageSize: t.pageSize,
1192
- hasPrevPage: t.page > 1
1193
- };
1194
- }
1195
- function yi(e) {
1196
- return { page: 1, pageSize: gi(e) };
1197
- }
1198
- function bi(e) {
1199
- var a, s, l, c, d;
1200
- const { card: t } = e, n = mi({
1201
- card: t,
1202
- isTablePrintMode: ((a = e.display) == null ? void 0 : a.isTablePrintMode) ?? !1,
1203
- isDocumentSectionRuntime: !!e.documentSection,
1204
- documentTableDataPolicy: (s = e.documentSection) == null ? void 0 : s.documentTableDataPolicy
1205
- }), { page: r } = e, o = e.documentSection && !e.documentSection.totalsRow ? void 0 : zn(t, e.finalConfig), i = !!((l = e.display) != null && l.deliveryStrict && e.display.isTablePrintMode && !e.documentSection && ao(t.type));
1206
- return {
1207
- ...o ? { tableTotalsRequest: o } : {},
1208
- ...i ? { sourceRowProbe: { limit: so.maxTableRows } } : {},
1209
- ...n ? {
1210
- pagination: {
1211
- page: (r == null ? void 0 : r.page) || 1,
1212
- pageSize: (r == null ? void 0 : r.pageSize) || ((d = (c = t.preferences) == null ? void 0 : c.tablePrefs) == null ? void 0 : d.pageSize) || 50
1213
- }
1214
- } : {}
1215
- };
1216
- }
1217
- function Ii(e, t = {}) {
1218
- var o, i, a;
1219
- const n = ((o = e.connectionId) == null ? void 0 : o.trim()) || void 0;
1220
- if (t.editorDevMode) return n;
1221
- const r = ((a = (i = e.dataSource) == null ? void 0 : i.connectionId) == null ? void 0 : a.trim()) || void 0;
1222
- return e.sql ? n || r : r || n;
1223
- }
1224
- function Ci(e, t) {
1225
- var n;
1226
- return {
1227
- connectionId: t,
1228
- connectionType: ((n = e.dataSource) == null ? void 0 : n.connectionType) || "unknown",
1229
- mode: "database",
1230
- selectedEntities: []
1231
- };
1232
- }
1233
- function ms(e, t, n = {}) {
1234
- const r = Ii(e, n);
1235
- if (!r)
1236
- throw new Error("No connection ID found for card");
1237
- const o = t.cardDataSource || e.dataSource;
1238
- return {
1239
- connectionId: r,
1240
- requestPayloadBase: {
1241
- ...t,
1242
- cardDataSource: n.liveDataSource ? o : o || Ci(e, r)
1243
- }
1244
- };
1245
- }
1246
- const hi = /* @__PURE__ */ new Set([
1247
- "day",
1248
- "week",
1249
- "month",
1250
- "quarter",
1251
- "year",
1252
- "hour",
1253
- "minute",
1254
- "second"
1255
- ]);
1256
- function vi(e) {
1257
- let t = e.spec;
1258
- const n = pt(
1259
- e.controlDefinitions || [],
1260
- e.cardControlDefinitions || []
1261
- ), r = (e.controlBindings || []).filter(
1262
- (p) => p.target !== "sql_param"
1263
- ), o = r.filter(
1264
- (p) => p.target === "config_metric_selector" || p.target === "config_field_selector"
1265
- ), i = r.filter(
1266
- (p) => p.target === "config_grain" || p.target === "config_aggregation"
1267
- ), a = /* @__PURE__ */ new Set(), s = /* @__PURE__ */ new Map();
1268
- let l;
1269
- const c = () => {
1270
- if (l) return l;
1271
- const p = e.catalog, b = /* @__PURE__ */ new Map();
1272
- for (const I of p) {
1273
- const C = b.get(I.id) ?? [];
1274
- b.set(I.id, [...C, I]);
1275
- }
1276
- return l = { refs: p, byId: b }, l;
1277
- }, d = (p, b) => {
1278
- throw new Qn(p, {
1279
- code: $n,
1280
- ...b ? { controlId: b } : {}
1281
- });
1282
- }, u = (p, b) => {
1283
- var C;
1284
- if (p.derivedField) return p.derivedField.dataType;
1285
- const I = c().refs.filter((h) => h.field.name === p.name && Ce(h.field.source ?? e.spec.source, p.source ?? e.spec.source));
1286
- return I.length > 1 ? d("The selected field is ambiguous in the authorized Matrix field catalog.", b) : Z(((C = I[0]) == null ? void 0 : C.field.dataType) ?? p.dataType);
1287
- }, f = (p, b) => Ln(p, b.target, (I) => u(I, b.controlId)), m = Rr.safeParse(t);
1288
- if (!m.success) return d(m.error.message);
1289
- t = m.data;
1290
- const y = [...o, ...i].map((p) => {
1291
- const b = mt({ binding: p, definitions: n, controlValues: e.controlValues }), I = !p.matrixTargetId && b !== void 0 && b !== he ? f(m.data, p) : [];
1292
- return {
1293
- binding: p,
1294
- selectedValue: b,
1295
- targetId: p.matrixTargetId ?? (I.length === 1 ? I[0].id : void 0)
1296
- };
1297
- });
1298
- for (const { binding: p, targetId: b, selectedValue: I } of y) {
1299
- if (I === void 0 || I === he)
1300
- continue;
1301
- const C = (v) => d(v, p.controlId), h = p.target === "config_metric_selector" || p.target === "config_aggregation", S = f(t, p);
1302
- (!b || !S.some((v) => v.id === b)) && C("Choose a valid Matrix level or measure target for this control.");
1303
- const g = `${p.target}:${b}`;
1304
- a.has(g) && C("Multiple controls cannot replace the same Matrix target."), a.add(g);
1305
- const V = (v) => {
1306
- const T = (c().byId.get(v.id) ?? []).filter((k) => !v.source || Ce(v.source, k.field.source ?? e.spec.source));
1307
- if (T.length !== 1) return C(T.length ? "The selected field is ambiguous in the authorized Matrix field catalog." : "The selected field is not in the authorized Matrix field catalog.");
1308
- const M = jr.safeParse(T[0].field);
1309
- return M.success ? M.data : C(M.error.message);
1310
- }, P = p.target === "config_metric_selector" || p.target === "config_field_selector" ? p.mapping[I] : void 0, x = P && typeof P == "object" && "kind" in P && P.kind === "matrix_instance" ? P.id : void 0;
1311
- if (h) {
1312
- s.set(b, p.controlId);
1313
- const v = x === void 0 ? void 0 : m.data.measures.find(
1314
- (F) => F.id === x && F.kind === "aggregate"
1315
- );
1316
- x !== void 0 && !v && C("The selected Matrix aggregate measure is no longer available.");
1317
- const T = p.target === "config_metric_selector" && !v ? Kn({ binding: p, selectedValue: I }) : void 0, M = ((v == null ? void 0 : v.kind) === "aggregate" ? v.aggregate : T == null ? void 0 : T.aggregate) ?? (p.target === "config_aggregation" ? Ge({ binding: p, selectedValue: I }) : void 0), k = M === void 0 ? void 0 : qr.safeParse(M);
1318
- k && !k.success && C("This aggregation is not supported by Matrix."), t = {
1319
- ...t,
1320
- measures: t.measures.map(
1321
- (F) => F.id !== b || F.kind !== "aggregate" ? F : {
1322
- ...F,
1323
- ...T ? { field: V(T) } : {},
1324
- ...(v == null ? void 0 : v.kind) === "aggregate" ? { field: v.field } : {},
1325
- aggregate: k != null && k.success ? k.data : F.aggregate
1326
- }
1327
- )
1328
- };
1329
- } else {
1330
- const v = x === void 0 ? void 0 : [...m.data.rows, ...m.data.columns].find(
1331
- (F) => F.id === x
1332
- );
1333
- x !== void 0 && !v && C("The selected Matrix level is no longer available.");
1334
- const T = p.target === "config_field_selector" && !v ? Gn({ binding: p, selectedValue: I }) : void 0, M = p.target === "config_grain" ? Ge({ binding: p, selectedValue: I }) : v ? v.grain : T == null ? void 0 : T.granularity;
1335
- M !== void 0 && !hi.has(M) && C("This time grain is not supported by Matrix.");
1336
- const k = (F) => F.map((D) => {
1337
- if (D.id !== b) return D;
1338
- const w = (v == null ? void 0 : v.field) ?? (T ? V(T) : D.field), B = u(w, p.controlId), R = M ?? (T && ne(B) ? D.grain : void 0);
1339
- return R && !ne(B) && C("A time grain requires a temporal Matrix level."), { ...D, field: w, grain: R };
1340
- });
1341
- t = {
1342
- ...t,
1343
- rows: k(t.rows),
1344
- columns: k(t.columns)
1345
- };
1346
- }
1347
- }
1348
- for (const [p, b] of Array.from(s)) {
1349
- const I = t.measures.find((h) => h.id === p);
1350
- if (!I || I.kind !== "aggregate") continue;
1351
- const C = u(I.field, b);
1352
- Hn(C).some((h) => h.value === I.aggregate) || d(`Aggregation '${I.aggregate}' is not eligible for this Matrix field datatype.`, b);
1353
- }
1354
- try {
1355
- return Un(m.data, t);
1356
- } catch (p) {
1357
- if (p instanceof Hr) return d(p.message);
1358
- throw p;
1359
- }
1360
- }
1361
- function Zt(e, t) {
1362
- const n = [], r = (o) => {
1363
- if (o.source) {
1364
- const i = Nr.safeParse(o.source);
1365
- if (i.success) n.push(i.data);
1366
- else if (t) throw i.error;
1367
- }
1368
- o.derivedField && Object.values(o.derivedField.inputs).forEach((i) => r(i.field));
1369
- };
1370
- for (const o of e) {
1371
- if (o.target !== "config_field_selector" && o.target !== "config_metric_selector") continue;
1372
- const i = t == null ? void 0 : t.get(o), a = t ? i && i !== he ? [o.mapping[i]] : [] : Object.values(o.mapping);
1373
- for (const s of a)
1374
- s && "role" in s && r(s);
1375
- }
1376
- return n;
1377
- }
1378
- function Fi(e, t = [], n = []) {
1379
- return St([...gt(e), ...Zt(t), ...n]);
1380
- }
1381
- function Di(e, t = {}) {
1382
- const n = t.controlBindings ?? [], r = pt(t.controlDefinitions ?? [], t.cardControlDefinitions ?? []), o = new Map(n.filter((i) => i.target === "config_field_selector" || i.target === "config_metric_selector").map((i) => [i, mt({ binding: i, definitions: r, controlValues: t.controlValues })]));
1383
- return St([...gt(e), ...Zt(n, o)]);
1384
- }
1385
- function Wt(e, t) {
1386
- return Te(e) ? Ti(e, t) : e.config ?? {};
1387
- }
1388
- function Si(e, t) {
1389
- return t != null && t.steps.length ? { ...e, config: Wt(e, t) } : e;
1390
- }
1391
- function Ti(e, t) {
1392
- var r;
1393
- const n = (r = t == null ? void 0 : t.steps[t.steps.length - 1]) == null ? void 0 : r.toField;
1394
- return n ? Eo(e.config ?? {}, n, {
1395
- sortPolicy: "retargetDimensionSort"
1396
- }) : e.config ?? {};
1397
- }
1398
- function Vi(e, t) {
1399
- const n = (e == null ? void 0 : e.steps) ?? [];
1400
- if (n.length !== 0)
1401
- return {
1402
- id: `${t}-drill-root`,
1403
- logicalOperator: "AND",
1404
- negate: !1,
1405
- conditions: [],
1406
- groups: n.map((r, o) => ({
1407
- id: `breadcrumb-${o}`,
1408
- logicalOperator: "OR",
1409
- negate: !1,
1410
- conditions: [],
1411
- groups: [
1412
- {
1413
- id: `breadcrumb-${o}-group-0`,
1414
- logicalOperator: "AND",
1415
- negate: !1,
1416
- conditions: r.conditions.map(
1417
- (i) => lo(
1418
- i,
1419
- `${i.field.id}-${i.value}`
1420
- )
1421
- ),
1422
- groups: []
1423
- }
1424
- ]
1425
- }))
1426
- };
1427
- }
1428
- const ye = (e) => typeof e == "object" && e !== null && !Array.isArray(e);
1429
- function H(e) {
1430
- return e instanceof Date ? JSON.stringify(Number.isNaN(e.getTime()) ? null : e.toISOString()) : Array.isArray(e) ? `[${e.map(H).join(",")}]` : ye(e) ? `{${Object.keys(e).sort().filter((t) => e[t] !== void 0).map((t) => `${JSON.stringify(t)}:${H(e[t])}`).join(",")}}` : JSON.stringify(e) ?? "null";
1431
- }
1432
- function Mi(e) {
1433
- const t = e;
1434
- return t.valueType === "date" || t.relativeMeta !== void 0 || t.temporalBucket !== void 0 || ne(t.dataType);
1435
- }
1436
- function ki(e) {
1437
- const t = ye(e.field) ? e.field : void 0;
1438
- return e.temporalBucket !== void 0 || e.rawTemporal !== void 0 || e.relativeMeta !== void 0 || ne(t == null ? void 0 : t.dataType);
1439
- }
1440
- function Jt(e) {
1441
- return e ? [...(e.conditions ?? []).filter(ki).map((n) => {
1442
- const r = ye(n.field) ? n.field : {};
1443
- return {
1444
- field: r.qualifiedFieldName ?? r.name,
1445
- operator: n.operator,
1446
- value: n.value,
1447
- temporalBucket: n.temporalBucket,
1448
- rawTemporal: n.rawTemporal,
1449
- relativeMeta: n.relativeMeta
1450
- };
1451
- }), ...(e.groups ?? []).flatMap((n) => Jt(n))] : [];
1452
- }
1453
- function rt(e) {
1454
- const t = e.filterValues.filter(Mi).map((r) => {
1455
- const o = r, i = ye(o.fieldMeta) ? o.fieldMeta : void 0;
1456
- return {
1457
- field: (i == null ? void 0 : i.qualifiedFieldName) ?? o.name,
1458
- operation: o.operation,
1459
- ...o.relativeMeta !== void 0 ? { relativeMeta: o.relativeMeta } : { values: o.values },
1460
- temporalBucket: o.temporalBucket
1461
- };
1462
- }), n = Jt(e.selectionFilters);
1463
- return H({
1464
- values: t.map(H).sort(),
1465
- conditions: n.map(H).sort(),
1466
- ...e.zoom ? { zoom: [e.zoom.from, e.zoom.to] } : {}
1467
- });
1468
- }
1469
- function xi(e, t, n) {
1470
- if (!t || n.drillActive || t.madeUnder !== n.currentFingerprint) return e;
1471
- const r = e.groupByColumns ?? [];
1472
- return r.some((o) => o.id === t.fieldId && o.grainMode === "automatic") ? {
1473
- ...e,
1474
- groupByColumns: r.map((o) => {
1475
- if (o.id !== t.fieldId || o.grainMode !== "automatic") return o;
1476
- const { grainMode: i, ...a } = o;
1477
- return { ...a, granularity: t.granularity };
1478
- })
1479
- } : e;
1480
- }
1481
- function gs(e) {
1482
- var t;
1483
- return (((t = e.config) == null ? void 0 : t.groupByColumns) ?? []).find(
1484
- (n) => n.grainMode === "automatic" && Zn({ cardType: e.type, configBacked: !0, shelf: "groupBy", dataType: n.dataType }).ok
1485
- );
1486
- }
1487
- function Pi(e, t) {
1488
- if (!e || !t || t.id !== e.fieldId || zr(t)) return;
1489
- const {
1490
- granularity: n,
1491
- grainMode: r,
1492
- dateFormat: o,
1493
- timeDrillPath: i,
1494
- ...a
1495
- } = t;
1496
- return {
1497
- id: `zoom:${e.fieldId}`,
1498
- logicalOperator: "AND",
1499
- negate: !1,
1500
- conditions: [
1501
- {
1502
- id: `zoom:${e.fieldId}:range`,
1503
- field: a,
1504
- operator: "between",
1505
- value: [e.from, e.to],
1506
- viewerZoom: !0
1507
- }
1508
- ],
1509
- groups: []
1510
- };
1511
- }
1512
- function ys(e, t, n) {
1513
- const r = Ue(e, n), o = Ue(t, n);
1514
- if (!r || !o) return;
1515
- const [i, a] = r.first <= o.first ? [r, o] : [o, r];
1516
- return { from: i.first, to: a.last };
1517
- }
1518
- function wi(e, t, n) {
1519
- if (!e || e.madeUnder !== n) return;
1520
- const r = t == null ? void 0 : t.find((i) => i.id === e.fieldId && i.grainMode === "automatic"), o = Pi(e, r);
1521
- return o ? { zoom: e, filterGroup: o } : void 0;
1522
- }
1523
- function bs(e, t, n) {
1524
- if (!e) return;
1525
- const [r, o] = t <= n ? [t, n] : [n, t];
1526
- if (r < 0 || o >= e.length) return;
1527
- const i = e.slice(r, o + 1);
1528
- if (!i.every((d) => typeof d == "string" && d !== "")) return;
1529
- const a = [...i].sort(), s = a[0], l = a[a.length - 1];
1530
- return e.some(
1531
- (d, u) => (u < r || u > o) && typeof d == "string" && d > s && d < l
1532
- ) ? void 0 : { first: s, last: l };
1533
- }
1534
- function Is(e, t, n) {
1535
- if (!t || !n) return { from: e.from, to: e.to };
1536
- const r = Ze(new Date(t.startInclusive), n), o = Ze(new Date(Date.parse(t.endExclusive) - 1), n), i = e.from < r ? r : e.from, a = e.to > o ? o : e.to;
1537
- return i <= a ? { from: i, to: a } : { from: e.from, to: e.to };
1538
- }
1539
- function Cs(e, t, n) {
1540
- const r = (i) => /* @__PURE__ */ new Date(`${i}T00:00:00.000Z`), o = new Intl.DateTimeFormat(t, { dateStyle: n, timeZone: "UTC" });
1541
- return e.from === e.to ? o.format(r(e.from)) : o.formatRange(r(e.from), r(e.to));
1542
- }
1543
- function Be(e) {
1544
- return e === "in" || e === "not in";
1545
- }
1546
- function Re(e) {
1547
- return e === "not in" ? "exclude" : "include";
1548
- }
1549
- function Oi(e) {
1550
- return e === "exclude" ? "not in" : "in";
1551
- }
1552
- function hs(e) {
1553
- var n;
1554
- const t = (n = e.liveValue) == null ? void 0 : n.operation;
1555
- return Be(t) ? Re(t) : e.pendingMode ?? e.authoredMode;
1556
- }
1557
- function _i(e) {
1558
- var r;
1559
- let t = !1;
1560
- const n = (r = e.inputs) == null ? void 0 : r.map((o) => {
1561
- if (o.kind !== "filter" || !o.filter) return o;
1562
- const i = Ai(
1563
- o.filter,
1564
- new Set(Ei(e.defaultInputValues, o))
1565
- );
1566
- return i === o.filter ? o : (t = !0, { ...o, filter: i });
1567
- });
1568
- return t ? { ...e, inputs: n } : e;
1569
- }
1570
- function Ai(e, t) {
1571
- if (t.size !== 1 || !Be(e.operation))
1572
- return e;
1573
- const [n] = t;
1574
- return Re(e.operation) === n ? e : { ...e, operation: Oi(n) };
1575
- }
1576
- function Ei(e, t) {
1577
- var o;
1578
- const n = (i) => Object.values(i ?? {}).map((a) => a[t.id]);
1579
- return (t.runtimeScope === "shared" ? [(o = e == null ? void 0 : e.shared) == null ? void 0 : o[t.id]] : t.runtimeScope === "perSheet" ? n(e == null ? void 0 : e.bySheetId) : t.runtimeScope === "perCard" ? n(e == null ? void 0 : e.byCardId) : t.runtimeScope === "perDocumentSection" ? n(e == null ? void 0 : e.byDocumentSectionId) : []).flatMap(
1580
- (i) => (i == null ? void 0 : i.status) === "set" && i.value.kind === "filter" ? Bi(i.value.filterValue) : []
1581
- );
1582
- }
1583
- function Bi(e) {
1584
- return Be(e.operation) ? [Re(e.operation)] : [];
1585
- }
1586
- function vs(e) {
1587
- const t = Mt(e), r = A(t).issues.length ? t : Ba(t);
1588
- return yt(
1589
- _o(
1590
- Wn(_i(r))
1591
- ).dashboard
1592
- );
1593
- }
1594
- function qe(e, t) {
1595
- const n = {};
1596
- for (const r of xt(e)) {
1597
- if (!r.inlineFilters || r.inlineFilters.length === 0)
1598
- continue;
1599
- const o = [];
1600
- for (const i of r.inlineFilters) {
1601
- const a = Jn(i, t);
1602
- a && o.push(a);
1603
- }
1604
- o.length > 0 && (n[r.id] = o);
1605
- }
1606
- return n;
1607
- }
1608
- function $(e) {
1609
- const t = fe(e ?? {}), n = [];
1610
- for (const [r, o] of Object.entries(t.shared ?? {}))
1611
- n.push({ scope: "shared", target: null, inputId: r, slot: o });
1612
- for (const r of ["bySheetId", "byCardId"])
1613
- for (const [o, i] of Object.entries(t[r] ?? {}))
1614
- for (const [a, s] of Object.entries(i))
1615
- n.push({ scope: r, target: o, inputId: a, slot: s });
1616
- return n;
1617
- }
1618
- function le(e, t, n) {
1619
- const r = e;
1620
- if (t.scope === "shared") {
1621
- r.shared = { ...r.shared, [t.inputId]: n };
1622
- return;
1623
- }
1624
- const o = { ...r[t.scope] ?? {} };
1625
- o[t.target] = { ...o[t.target], [t.inputId]: n }, r[t.scope] = o;
1626
- }
1627
- function Yt(e, t, n) {
1628
- const r = bt(
1629
- e,
1630
- t.controlOverrides,
1631
- { hasExplicitRuntimeOverrides: t.controlOverrides !== void 0 }
1632
- );
1633
- return {
1634
- adHocFilterValues: [...t.adHocFilterValues],
1635
- controlValues: r.dashboardControlValues,
1636
- cardControlValuesMap: r.cardControlValuesMap,
1637
- dashboardInputValues: t.dashboardInputValues,
1638
- inlineFilterValuesMap: t.inlineFilterValuesMap ?? qe(e, n)
1639
- };
1640
- }
1641
- function je(e, t, n) {
1642
- return Xt(
1643
- e,
1644
- Yt(e, t, n),
1645
- n
1646
- );
1647
- }
1648
- function Fs(e, t, n) {
1649
- return Xt(e, t, n);
1650
- }
1651
- function Xt(e, t, n) {
1652
- const r = e.sheets ?? [], o = r.filter((s) => (s.kind ?? "dashboard") === "dashboard").map((s) => s.id), i = r.filter((s) => s.kind === "document"), a = o.length ? er({
1653
- dashboard: e,
1654
- sheetIds: o,
1655
- mode: "dashboard",
1656
- runtimeValues: t,
1657
- transientContexts: void 0,
1658
- calendar: n ?? null
1659
- }).snapshot.dashboardInputValues : {};
1660
- return i.reduce(
1661
- (s, l) => {
1662
- var c;
1663
- return xe(
1664
- s,
1665
- tr({
1666
- dashboard: e,
1667
- sheetId: l.id,
1668
- sheetKind: "document",
1669
- mode: "document",
1670
- sectionIds: (((c = l.document) == null ? void 0 : c.sections) ?? []).map(
1671
- (d) => d.id
1672
- ),
1673
- runtimeValues: t,
1674
- transientContexts: void 0,
1675
- calendar: n ?? null
1676
- }).snapshot.dashboardInputValues
1677
- );
1678
- },
1679
- a
1680
- );
1681
- }
1682
- function en(e, t) {
1683
- const n = {}, r = {}, o = /* @__PURE__ */ new Map();
1684
- for (const i of $(t)) {
1685
- const a = e.get(i.inputId), { slot: s } = i, l = () => s.status === "set" && s.value.kind === "filter" ? s.value.filterValue : s.status === "cleared" ? null : void 0;
1686
- if ((a == null ? void 0 : a.source) === "cardInlineFilter") {
1687
- const c = l();
1688
- if (c !== void 0) {
1689
- const d = o.get(a.cardId) ?? /* @__PURE__ */ new Map();
1690
- d.set(a.filterId, c), o.set(a.cardId, d);
1691
- }
1692
- } else if ((a == null ? void 0 : a.source) === "dashboardControl" || (a == null ? void 0 : a.source) === "cardControl")
1693
- s.status === "set" && s.value.kind === "control" ? r[a.controlId] = s.value.value : s.status === "cleared" && (r[a.controlId] = void 0);
1694
- else {
1695
- le(n, i, s);
1696
- continue;
1697
- }
1698
- s.comparisonSelection && le(n, i, {
1699
- comparisonSelection: s.comparisonSelection
1700
- });
1701
- }
1702
- return {
1703
- runtime: fe(n),
1704
- controlValues: r,
1705
- inlineFilterValues: o
1706
- };
1707
- }
1708
- function Ri(e, t) {
1709
- if (!t.size) return [...e];
1710
- const n = e.filter((o) => !t.has(o.filterId)), r = [...t.values()].filter(
1711
- (o) => o !== null
1712
- );
1713
- return nr(n, r);
1714
- }
1715
- function tn(e, t, n) {
1716
- if (!Object.keys(n).length) return t;
1717
- const r = bt(
1718
- e,
1719
- t,
1720
- { hasExplicitRuntimeOverrides: t !== void 0 }
1721
- );
1722
- return {
1723
- ...Yn({
1724
- dashboardValues: r.dashboardControlValues,
1725
- cardValuesMap: r.cardControlValuesMap
1726
- }),
1727
- ...n
1728
- };
1729
- }
1730
- function qi(e, t) {
1731
- if (!t.size) return;
1732
- const n = Object.fromEntries(
1733
- Object.entries(e).map(([r, o]) => [r, [...o]])
1734
- );
1735
- for (const [r, o] of t)
1736
- n[r] = Ri(n[r] ?? [], o);
1737
- return n;
1738
- }
1739
- function ji(e, t, n) {
1740
- const r = new Map(
1741
- N(e).map(({ card: a }) => [
1742
- a.id,
1743
- // Column filters too (TCF-D4): a viewer's column filter survives a refetch.
1744
- new Map(Xn(a).map((s) => [s.id, s]))
1745
- ])
1746
- );
1747
- let o = !1;
1748
- const i = Object.fromEntries(
1749
- Object.entries(t).map(([a, s]) => [a, [...s]])
1750
- );
1751
- for (const [a, s] of Object.entries(n)) {
1752
- const l = r.get(a), c = (s ?? []).filter((d) => {
1753
- const u = l == null ? void 0 : l.get(d.filterId);
1754
- return u ? ke(u, d) : !1;
1755
- });
1756
- pe(c, i[a] ?? []) || (o = !0), i[a] = c;
1757
- }
1758
- return o ? i : void 0;
1759
- }
1760
- function Ds(e) {
1761
- const { dashboard: t, capture: n, calendar: r } = e, o = Tn(t, n.filterValues, {
1762
- calendar: r
1763
- }), i = n.dashboardInputExecutionSnapshot, a = n.controlValues, s = {
1764
- ...Yt(
1765
- t,
1766
- {
1767
- adHocFilterValues: o.adHocFilterValues,
1768
- controlOverrides: a,
1769
- // The snapshot replays exactly over the listed values.
1770
- dashboardInputValues: i ? xe(
1771
- o.slots,
1772
- or({
1773
- dashboard: t,
1774
- dashboardInputValues: i.dashboardInputValues,
1775
- sheetId: i.sheetId,
1776
- cardId: i.cardId
1777
- })
1778
- ) : o.slots
1779
- },
1780
- r
1781
- ),
1782
- cardViewState: i ? rr(i.cardViewState) : {}
1783
- }, l = i ? ir(i.transientContexts) : void 0;
1784
- return {
1785
- runtimeValues: s,
1786
- controlOverrides: a,
1787
- ...l != null && l.length ? { transientContexts: l } : {}
1788
- };
1789
- }
1790
- function Ss(e, t) {
1791
- const { controlContractOverrides: n, cardId: r } = t;
1792
- if (!n || (n.controlDefinitions !== void 0 && (e.controls = n.controlDefinitions), typeof r != "string" || r.trim().length === 0))
1793
- return e;
1794
- const o = W(e, r);
1795
- return o && (n.cardControlDefinitions !== void 0 && (o.controls = n.cardControlDefinitions), n.controlBindings !== void 0 && (o.controlBindings = n.controlBindings)), e;
1796
- }
1797
- const Ni = ["bySheetId", "byCardId", "byDocumentSectionId"];
1798
- function zi(e, t) {
1799
- const n = A(e);
1800
- let r = !1;
1801
- const o = (a) => {
1802
- if (!a) return a;
1803
- const s = Object.entries(a).filter(([l, c]) => {
1804
- var u;
1805
- if (c.status !== "set" || c.value.kind !== "filter") return !0;
1806
- const d = (u = n.findFilterInput({ inputId: l })) == null ? void 0 : u.input.filter;
1807
- return !d || ke(d, c.value.filterValue) ? !0 : (r = !0, !1);
1808
- });
1809
- return Object.fromEntries(s);
1810
- }, i = {
1811
- ...t,
1812
- ...t.shared ? { shared: o(t.shared) } : {}
1813
- };
1814
- for (const a of Ni) {
1815
- const s = t[a];
1816
- s && (i[a] = Object.fromEntries(
1817
- Object.entries(s).map(([l, c]) => [l, o(c) ?? {}])
1818
- ));
1819
- }
1820
- return r ? i : t;
1821
- }
1822
- function Li(e) {
1823
- var t, n;
1824
- return ((n = (t = e.sheets) == null ? void 0 : t[0]) == null ? void 0 : n.id) ?? null;
1825
- }
1826
- function J(e, t) {
1827
- var n;
1828
- return !!t && !!((n = e.sheets) != null && n.some((r) => r.id === t));
1829
- }
1830
- function Ts(e) {
1831
- const { dashboard: t, host: n, calendar: r } = e, o = Tn(t, n.filterValues, {
1832
- calendar: r
1833
- }).slots, i = n.controlValues, a = J(t, n.selectedSheetId) ? n.selectedSheetId : Li(t);
1834
- return {
1835
- hostInputValues: o,
1836
- controlOverrides: i,
1837
- selectedSheetId: a,
1838
- hostSelectedSheetId: n.selectedSheetId ?? null,
1839
- materializedInputs: e.materializeInputs === !1 ? {} : je(
1840
- t,
1841
- {
1842
- adHocFilterValues: [],
1843
- controlOverrides: i,
1844
- dashboardInputValues: o
1845
- },
1846
- r
1847
- )
1848
- };
1849
- }
1850
- function nn(e) {
1851
- const t = /* @__PURE__ */ new Map(), n = /* @__PURE__ */ new Set(), r = /* @__PURE__ */ new Map();
1852
- for (const o of Pe(e))
1853
- o.kind === "filter" && o.filter ? t.set(o.id, o.filter) : o.kind === "control" && n.add(o.id), o.compatibility && r.set(o.id, o.compatibility);
1854
- return { filterInputs: t, controlInputIds: n, compatibility: r };
1855
- }
1856
- function rn(e, t) {
1857
- const n = Tt(t);
1858
- if (!n) return;
1859
- const r = W(e, n);
1860
- return r ? ar(r, e) ? "applies" : "not-eligible" : "removed";
1861
- }
1862
- function Vs(e, t) {
1863
- const n = rn(e, t);
1864
- return n ? n === "applies" : Pe(e).some(
1865
- (r) => r.id === t
1866
- );
1867
- }
1868
- function on(e, t, n, r) {
1869
- if (!n) return {};
1870
- const o = new Set((e.sheets ?? []).map((c) => c.id)), i = new Set(
1871
- N(e).map(({ card: c }) => c.id)
1872
- ), a = A(e), s = (c) => {
1873
- var u;
1874
- if (!c) return;
1875
- const d = {};
1876
- for (const [f, m] of Object.entries(c)) {
1877
- const y = t.filterInputs.has(f) || t.controlInputIds.has(f) ? f : ((u = a.findFilterInput({ inputId: f })) == null ? void 0 : u.input.id) ?? f;
1878
- if (y !== f && c[y]) continue;
1879
- const p = rn(e, y);
1880
- if (p) {
1881
- if (p !== "applies") {
1882
- r.push({
1883
- kind: "setting-no-longer-applies",
1884
- target: "selection",
1885
- id: y,
1886
- reason: p
1887
- });
1888
- continue;
1889
- }
1890
- d[y] = m;
1891
- continue;
1892
- }
1893
- const b = t.filterInputs.get(y);
1894
- if (!b && !t.controlInputIds.has(y)) {
1895
- r.push({
1896
- kind: "setting-no-longer-applies",
1897
- target: "input",
1898
- id: y,
1899
- reason: "removed"
1900
- });
1901
- continue;
1902
- }
1903
- if (b && m.status === "set" && m.value.kind === "filter" && !ke(b, m.value.filterValue)) {
1904
- r.push({
1905
- kind: "setting-no-longer-applies",
1906
- target: "input",
1907
- id: y,
1908
- reason: "incompatible"
1909
- });
1910
- continue;
1911
- }
1912
- d[y] = m;
1913
- }
1914
- return Object.keys(d).length ? d : void 0;
1915
- }, l = (c, d) => {
1916
- if (!c) return;
1917
- const u = {};
1918
- for (const [f, m] of Object.entries(c)) {
1919
- if (!d(f)) {
1920
- for (const p of Object.keys(m))
1921
- r.push({
1922
- kind: "setting-no-longer-applies",
1923
- target: "input",
1924
- id: p,
1925
- reason: "removed"
1926
- });
1927
- continue;
1928
- }
1929
- const y = s(m);
1930
- y && (u[f] = y);
1931
- }
1932
- return u;
1933
- };
1934
- return fe({
1935
- shared: s(n.shared),
1936
- bySheetId: l(n.bySheetId, (c) => o.has(c)),
1937
- byCardId: l(n.byCardId, (c) => i.has(c))
1938
- // Document sections are not viewer state.
1939
- });
1940
- }
1941
- function O(e, t, n, r = {}) {
1942
- const o = new Map(
1943
- N(e).map(({ card: a }) => [a.id, a])
1944
- ), i = {};
1945
- for (const [a, s] of Object.entries(t ?? {})) {
1946
- const l = o.get(a);
1947
- if (l && Jr(l)) {
1948
- Yr(s) || (i[a] = s);
1949
- continue;
1950
- }
1951
- if (l && r.sessionSorts && Xr(l)) {
1952
- s.sort && (i[a] = { sort: s.sort });
1953
- continue;
1954
- }
1955
- n == null || n.push({
1956
- kind: "setting-no-longer-applies",
1957
- target: "card",
1958
- id: a,
1959
- reason: W(e, a) ? "not-eligible" : "removed"
1960
- });
1961
- }
1962
- return i;
1963
- }
1964
- function Ki(e, t, n) {
1965
- if (t) {
1966
- if (J(e, t)) return t;
1967
- n.push({
1968
- kind: "setting-no-longer-applies",
1969
- target: "sheet",
1970
- id: t,
1971
- reason: "removed"
1972
- });
1973
- }
1974
- }
1975
- const Ne = (e, t) => pe(e ?? null, t ?? null);
1976
- function an(e) {
1977
- return {
1978
- adHocFilterValues: e.adHocFilterValues,
1979
- controlOverrides: e.controlOverrides,
1980
- dashboardInputValues: e.dashboardInputValues,
1981
- ...e.inlineFilterValuesMap ? { inlineFilterValuesMap: e.inlineFilterValuesMap } : {},
1982
- selectedSheetId: e.selectedSheetId,
1983
- tableSettings: e.tableSettings
1984
- };
1985
- }
1986
- function X(e, t) {
1987
- return {
1988
- adHocFilterValues: [],
1989
- controlOverrides: e.controlOverrides,
1990
- dashboardInputValues: e.hostInputValues,
1991
- selectedSheetId: e.selectedSheetId,
1992
- tableSettings: t
1993
- };
1994
- }
1995
- function sn(e, t) {
1996
- const n = t.dashboardInputValues === e.baseline.hostInputValues && !t.inlineFilterValuesMap && !t.adHocFilterValues.length && t.controlOverrides === e.baseline.controlOverrides;
1997
- return {
1998
- selectedSheetId: t.selectedSheetId,
1999
- // Overlay: the bookmark's values on the baseline's runtime values.
2000
- inputs: n ? e.baseline.materializedInputs : je(e.dashboard, t, e.calendar),
2001
- tableSettings: t.tableSettings
2002
- };
2003
- }
2004
- function j(e, t) {
2005
- const n = an(t), r = t.restore ?? n;
2006
- return {
2007
- ...n,
2008
- appliedBookmarkId: t.appliedBookmarkId,
2009
- rememberedWrites: t.rememberedWrites ?? [],
2010
- notices: t.notices ?? [],
2011
- opened: sn(e, r),
2012
- restore: r
2013
- };
2014
- }
2015
- function ot(e, t, n, r) {
2016
- const { dashboard: o, baseline: i } = e, a = [], s = Pt(t.state, _e), l = s.ok ? s.value : {};
2017
- for (const y of s.ok ? s.issues : [])
2018
- a.push(Gi(y));
2019
- const c = nn(o), d = en(
2020
- c.compatibility,
2021
- on(o, c, l.inputs, a)
2022
- ), u = Ki(o, l.selectedSheetId, a) ?? i.selectedSheetId, f = O(
2023
- o,
2024
- l.tableSettings,
2025
- a
2026
- ), m = O(
2027
- o,
2028
- n,
2029
- void 0
2030
- );
2031
- return j(e, {
2032
- appliedBookmarkId: t.id,
2033
- // A bookmark opens without ad-hoc values, as today (P4a-02 f).
2034
- adHocFilterValues: [],
2035
- controlOverrides: tn(
2036
- o,
2037
- i.controlOverrides,
2038
- d.controlValues
2039
- ),
2040
- // Overlay, never replacement: the bookmark's slots over the host's.
2041
- dashboardInputValues: xe(
2042
- i.hostInputValues,
2043
- d.runtime
2044
- ),
2045
- ...ln(
2046
- qi(
2047
- qe(o, e.calendar),
2048
- d.inlineFilterValues
2049
- )
2050
- ),
2051
- selectedSheetId: u,
2052
- tableSettings: r.writeRemembered ? { ...m, ...f } : (
2053
- // A default bookmark on load: remembered settings per card win.
2054
- { ...f, ...m }
2055
- ),
2056
- rememberedWrites: r.writeRemembered ? Object.entries(f).filter(
2057
- ([y, p]) => !Ne(m[y], p)
2058
- ).map(([y, p]) => ({
2059
- kind: "set",
2060
- cardId: y,
2061
- settings: p
2062
- })) : [],
2063
- notices: a
2064
- });
2065
- }
2066
- function Gi(e) {
2067
- return {
2068
- kind: "setting-no-longer-applies",
2069
- target: e.target,
2070
- id: e.id,
2071
- reason: "invalid"
2072
- };
2073
- }
2074
- function ln(e) {
2075
- return e ? { inlineFilterValuesMap: e } : {};
2076
- }
2077
- function it(e, t, n) {
2078
- const { dashboard: r, baseline: o } = e;
2079
- return {
2080
- // A reload in place keeps ad-hoc values, as today (P4a-02 f), unless the
2081
- // template now defines a filter with that id.
2082
- adHocFilterValues: t.adHocFilterValues.filter(
2083
- (i) => !A(r).findFilterInput({ filterId: i.filterId })
2084
- ),
2085
- // A host's new control defaults are the baseline's, not the viewer's.
2086
- controlOverrides: n.controlsChanged ? o.controlOverrides : t.controlOverrides,
2087
- // Live slots stay, except a filter value this template no longer accepts:
2088
- // that filter loads its new default, as the old list did. The resolver
2089
- // ignores slots this template no longer has.
2090
- dashboardInputValues: zi(
2091
- r,
2092
- t.dashboardInputValues
2093
- ),
2094
- ...ln(
2095
- ji(
2096
- r,
2097
- qe(r, e.calendar),
2098
- t.inlineFilterValuesMap ?? {}
2099
- )
2100
- ),
2101
- selectedSheetId: !n.sheetChanged && J(r, t.selectedSheetId) ? t.selectedSheetId : o.selectedSheetId,
2102
- tableSettings: O(
2103
- r,
2104
- t.tableSettings,
2105
- void 0,
2106
- { sessionSorts: !0 }
2107
- )
2108
- };
2109
- }
2110
- function Ms(e) {
2111
- const { dashboard: t, baseline: n, event: r } = e, o = e.rememberedTableSettings;
2112
- switch (r.kind) {
2113
- case "initial-load":
2114
- return r.defaultBookmark ? ot(e, r.defaultBookmark, o, {
2115
- writeRemembered: !1
2116
- }) : j(e, {
2117
- appliedBookmarkId: null,
2118
- ...X(
2119
- n,
2120
- O(t, o, void 0, {
2121
- sessionSorts: r.captured
2122
- })
2123
- )
2124
- });
2125
- case "refetch": {
2126
- const { live: i } = r, a = i.applied, s = {
2127
- sheetChanged: !!i.previousBaseline && i.previousBaseline.hostSelectedSheetId !== n.hostSelectedSheetId,
2128
- controlsChanged: !!i.previousBaseline && !pe(
2129
- i.previousBaseline.controlOverrides ?? null,
2130
- n.controlOverrides ?? null
2131
- )
2132
- }, l = it(
2133
- e,
2134
- {
2135
- adHocFilterValues: i.adHocFilterValues,
2136
- controlOverrides: i.controlValues ?? n.controlOverrides,
2137
- dashboardInputValues: i.dashboardInputValues,
2138
- inlineFilterValuesMap: i.inlineFilterValuesMap,
2139
- selectedSheetId: i.selectedSheetId,
2140
- tableSettings: i.tableSettings
2141
- },
2142
- s
2143
- ), c = a ? it(e, a.restore, s) : X(
2144
- n,
2145
- O(t, o, void 0)
2146
- );
2147
- return j(e, {
2148
- appliedBookmarkId: (a == null ? void 0 : a.appliedBookmarkId) ?? null,
2149
- ...l,
2150
- notices: (a == null ? void 0 : a.notices) ?? [],
2151
- restore: c
2152
- });
2153
- }
2154
- case "open-bookmark":
2155
- return ot(e, r.bookmark, o, {
2156
- writeRemembered: !0
2157
- });
2158
- case "open-default-view":
2159
- return j(e, {
2160
- appliedBookmarkId: null,
2161
- ...X(
2162
- n,
2163
- O(t, o, void 0)
2164
- )
2165
- });
2166
- case "reset-to-default-view":
2167
- return j(e, {
2168
- appliedBookmarkId: null,
2169
- ...X(n, {}),
2170
- rememberedWrites: [{ kind: "clear-all" }]
2171
- });
2172
- case "discard-changes": {
2173
- const { restore: i } = r.applied, a = O(
2174
- t,
2175
- i.tableSettings,
2176
- void 0,
2177
- { sessionSorts: !0 }
2178
- ), s = O(t, a, void 0), l = O(t, o, void 0), c = [];
2179
- for (const d of /* @__PURE__ */ new Set([
2180
- ...Object.keys(l),
2181
- ...Object.keys(s)
2182
- ])) {
2183
- if (Ne(l[d], s[d])) continue;
2184
- const u = s[d];
2185
- c.push(
2186
- u ? { kind: "set", cardId: d, settings: u } : { kind: "clear", cardId: d }
2187
- );
2188
- }
2189
- return j(e, {
2190
- appliedBookmarkId: r.applied.appliedBookmarkId,
2191
- ...i,
2192
- selectedSheetId: J(t, i.selectedSheetId) ? i.selectedSheetId : n.selectedSheetId,
2193
- tableSettings: a,
2194
- rememberedWrites: c,
2195
- notices: r.applied.notices,
2196
- restore: i
2197
- });
2198
- }
2199
- }
2200
- }
2201
- function ks(e) {
2202
- const { dashboard: t, calendar: n } = e, r = e.hostControlValues, o = {
2203
- ...e.baseline,
2204
- controlOverrides: r,
2205
- materializedInputs: je(
2206
- t,
2207
- {
2208
- adHocFilterValues: [],
2209
- controlOverrides: r,
2210
- dashboardInputValues: e.baseline.hostInputValues
2211
- },
2212
- n
2213
- )
2214
- };
2215
- let i = r;
2216
- if (e.appliedBookmark) {
2217
- const l = Pt(
2218
- e.appliedBookmark.state,
2219
- _e
2220
- ), c = nn(t), d = en(
2221
- c.compatibility,
2222
- on(
2223
- t,
2224
- c,
2225
- l.ok ? l.value.inputs : void 0,
2226
- []
2227
- )
2228
- ).controlValues;
2229
- i = tn(t, r, d);
2230
- }
2231
- const a = e.applied;
2232
- if (!a) return { baseline: o, controlOverrides: i, applied: null };
2233
- const s = { ...a.restore, controlOverrides: i };
2234
- return {
2235
- baseline: o,
2236
- controlOverrides: i,
2237
- applied: {
2238
- ...a,
2239
- controlOverrides: i,
2240
- restore: s,
2241
- opened: sn({ dashboard: t, baseline: o, calendar: n }, s)
2242
- }
2243
- };
2244
- }
2245
- function xs(e, t, n) {
2246
- const r = an(n.values);
2247
- return {
2248
- ...r,
2249
- appliedBookmarkId: t,
2250
- rememberedWrites: [],
2251
- notices: e.notices,
2252
- opened: n.snapshot,
2253
- restore: r
2254
- };
2255
- }
2256
- const at = (e) => JSON.stringify([e.scope, e.target, e.inputId]);
2257
- function ee(e) {
2258
- return !e || e.status === "cleared" && !e.comparisonSelection;
2259
- }
2260
- function cn(e, t) {
2261
- const n = new Map(
2262
- $(e).map((i) => [at(i), i])
2263
- ), r = new Map(
2264
- $(t).map((i) => [at(i), i])
2265
- ), o = {};
2266
- for (const [i, a] of r) {
2267
- const s = n.get(i);
2268
- s && pe(s.slot, a.slot) || ee(a.slot) && ee(s == null ? void 0 : s.slot) || le(
2269
- o,
2270
- a,
2271
- ee(a.slot) ? { status: "cleared" } : a.slot
2272
- );
2273
- }
2274
- for (const [i, a] of n)
2275
- r.has(i) || ee(a.slot) || le(o, a, { status: "cleared" });
2276
- return fe(o);
2277
- }
2278
- function Ps(e) {
2279
- const { dashboard: t, baseline: n, current: r } = e, o = cn(n.materializedInputs, r.inputs), i = O(
2280
- t,
2281
- r.tableSettings,
2282
- void 0
2283
- ), a = r.selectedSheetId && r.selectedSheetId !== n.selectedSheetId && J(t, r.selectedSheetId) ? r.selectedSheetId : void 0;
2284
- return {
2285
- version: _e,
2286
- ...a ? { selectedSheetId: a } : {},
2287
- ...$(o).length ? { inputs: o } : {},
2288
- ...Object.keys(i).length ? { tableSettings: i } : {}
2289
- };
2290
- }
2291
- function Hi(e) {
2292
- const t = /* @__PURE__ */ new Map();
2293
- for (const n of Pe(e))
2294
- n.label && t.set(n.id, n.label);
2295
- return t;
2296
- }
2297
- function Ui(e, t, n) {
2298
- var o, i;
2299
- const r = Tt(n);
2300
- if (r) {
2301
- const a = (i = (o = W(e, r)) == null ? void 0 : o.title) == null ? void 0 : i.trim();
2302
- return a ? `Selection in ${a}` : "Selection";
2303
- }
2304
- return t.get(n) ?? n;
2305
- }
2306
- function ws(e) {
2307
- var c, d;
2308
- const { dashboard: t, opened: n, current: r } = e, o = [], i = Hi(t), a = /* @__PURE__ */ new Set();
2309
- for (const u of $(
2310
- cn(n.inputs, r.inputs)
2311
- ))
2312
- a.has(u.inputId) || (a.add(u.inputId), o.push({
2313
- target: "input",
2314
- inputId: u.inputId,
2315
- label: Ui(t, i, u.inputId)
2316
- }));
2317
- (n.selectedSheetId ?? null) !== (r.selectedSheetId ?? null) && o.push({ target: "sheet" });
2318
- const s = O(
2319
- t,
2320
- n.tableSettings,
2321
- void 0
2322
- ), l = O(
2323
- t,
2324
- r.tableSettings,
2325
- void 0
2326
- );
2327
- for (const u of /* @__PURE__ */ new Set([
2328
- ...Object.keys(s),
2329
- ...Object.keys(l)
2330
- ]))
2331
- Ne(s[u], l[u]) || o.push({
2332
- target: "table",
2333
- cardId: u,
2334
- cardTitle: ((d = (c = W(t, u)) == null ? void 0 : c.title) == null ? void 0 : d.trim()) || "Table"
2335
- });
2336
- return o;
2337
- }
2338
- function st(e) {
2339
- const t = U(e.filter);
2340
- return {
2341
- inputId: e.inputId,
2342
- filterId: e.filterId,
2343
- label: e.label,
2344
- selection: e.selection,
2345
- owner: t ? { kind: "global_date" } : {
2346
- kind: "field_date",
2347
- filterId: e.filterId,
2348
- label: e.label
2349
- }
2350
- };
2351
- }
2352
- function Qi(e) {
2353
- var o, i;
2354
- if ((o = e.card.sql) != null && o.trim())
2355
- return {
2356
- inputs: e.inputs,
2357
- fieldCandidates: [],
2358
- resolution: { status: "none" }
2359
- };
2360
- const t = e.inputs.filter((a) => !U(a.filter)).map((a) => ({
2361
- input: a,
2362
- resolution: sr({
2363
- filter: a.filter,
2364
- filterValue: a.filterValue,
2365
- effectiveFilterValue: a.effectiveFilterValue,
2366
- mappedFilterValue: a.mappedFilterValue,
2367
- temporalBinding: e.temporalBinding,
2368
- card: e.card
2369
- })
2370
- }));
2371
- if (!e.temporalBinding)
2372
- return { inputs: e.inputs, fieldCandidates: t, resolution: { status: "none" } };
2373
- const n = e.inputs.find(
2374
- (a) => U(a.filter)
2375
- );
2376
- if (n && ((i = n.filterValue) == null ? void 0 : i.filterId) === n.filterId && n.effectiveFilterValue.filterId === n.filterId && lr(n.effectiveFilterValue))
2377
- return {
2378
- inputs: e.inputs,
2379
- fieldCandidates: t,
2380
- resolution: {
2381
- status: "resolved",
2382
- resolvedOwner: st(n)
2383
- }
2384
- };
2385
- const r = t.filter(
2386
- (a) => a.resolution.status === "eligible"
2387
- );
2388
- return r.length === 1 ? {
2389
- inputs: e.inputs,
2390
- fieldCandidates: t,
2391
- resolution: {
2392
- status: "resolved",
2393
- resolvedOwner: st(r[0].input)
2394
- }
2395
- } : r.length > 1 ? {
2396
- inputs: e.inputs,
2397
- fieldCandidates: t,
2398
- resolution: {
2399
- status: "ambiguous",
2400
- candidateInputIds: r.map(
2401
- (a) => a.input.inputId
2402
- )
2403
- }
2404
- } : { inputs: e.inputs, fieldCandidates: t, resolution: { status: "none" } };
2405
- }
2406
- function Os(e) {
2407
- const t = {
2408
- ownerCardCount: 0,
2409
- matchingCardCount: 0,
2410
- globalPrecedenceCardCount: 0,
2411
- ambiguousCardCount: 0
2412
- };
2413
- for (const n of e.targets) {
2414
- const r = n.plan.fieldCandidates.find(
2415
- (i) => i.input.inputId === e.inputId
2416
- );
2417
- if (!r || r.resolution.status !== "eligible") continue;
2418
- t.matchingCardCount += 1;
2419
- const { resolution: o } = n.plan;
2420
- o.status === "resolved" && o.resolvedOwner.inputId === e.inputId ? t.ownerCardCount += 1 : o.status === "resolved" && o.resolvedOwner.owner.kind === "global_date" ? t.globalPrecedenceCardCount += 1 : o.status === "ambiguous" && o.candidateInputIds.includes(e.inputId) && (t.ambiguousCardCount += 1);
2421
- }
2422
- return t;
2423
- }
2424
- const $i = /* @__PURE__ */ new Set([
2425
- "between",
2426
- "not between",
2427
- "=",
2428
- "!=",
2429
- ">",
2430
- ">=",
2431
- "<",
2432
- "<=",
2433
- "is null",
2434
- "is not null"
2435
- ]), Zi = /^(\d{4}-\d{2}-\d{2})T/, Wi = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}(?::\d{2}(?:\.\d{1,9})?)?(?:Z|[+-]\d{2}:\d{2})$/;
2436
- function ze(e) {
2437
- return $i.has(e);
2438
- }
2439
- function Ji(e, t) {
2440
- if (e instanceof Date)
2441
- return Number.isNaN(e.getTime()) ? e : t ? Qe(e, t, "yyyy-MM-dd") : e.toISOString().slice(0, 10);
2442
- if (typeof e != "string")
2443
- return e;
2444
- const n = e.trim();
2445
- if (t && Wi.test(n)) {
2446
- const o = new Date(n);
2447
- if (!Number.isNaN(o.getTime()))
2448
- return Qe(o, t, "yyyy-MM-dd");
2449
- }
2450
- const r = Zi.exec(n);
2451
- return r ? r[1] : e;
2452
- }
2453
- function dn(e, t) {
2454
- return Array.isArray(e) ? e.map(
2455
- (n) => Ji(n, t)
2456
- ) : e;
2457
- }
2458
- function un(e) {
2459
- return typeof e.allowMinutePrecision == "boolean" ? e.allowMinutePrecision : we(
2460
- e.dashboard,
2461
- e.semanticExecutionPayload
2462
- ).allEligibleTargetsAreDateTime;
2463
- }
2464
- function fn(e) {
2465
- const {
2466
- globalDateFilter: t,
2467
- globalDateFilterValue: n,
2468
- timezone: r,
2469
- allowMinutePrecision: o = !1
2470
- } = e;
2471
- if (!t || !n)
2472
- return;
2473
- if (!ze(n.operation))
2474
- return {
2475
- ...n,
2476
- filterId: t.id
2477
- };
2478
- const i = n, a = i.temporalPrecision === "minute" || te(i.relativeMeta) === "minute", s = !o && a, l = i.operation === "is null" || i.operation === "is not null" ? [] : s ? dn(i.values, r) : i.values, c = o || te(i.relativeMeta) !== "minute" ? i.relativeMeta : void 0, d = o && i.temporalPrecision === "minute" ? i.temporalPrecision : void 0, {
2479
- relativeMeta: u,
2480
- temporalPrecision: f,
2481
- values: m,
2482
- ...y
2483
- } = n;
2484
- return {
2485
- ...y,
2486
- filterId: t.id,
2487
- values: l,
2488
- ...c ? { relativeMeta: c } : {},
2489
- ...d ? { temporalPrecision: d } : {}
2490
- };
2491
- }
2492
- function Yi(e) {
2493
- const t = L(e.filters);
2494
- if (!t)
2495
- return e.filterValues;
2496
- const n = un(e);
2497
- return e.filterValues.map((r) => r.filterId !== t.id ? r : fn({
2498
- globalDateFilter: t,
2499
- globalDateFilterValue: r,
2500
- timezone: e.timezone,
2501
- allowMinutePrecision: n
2502
- }) || r);
2503
- }
2504
- function pn(e) {
2505
- const {
2506
- globalDateFilter: t,
2507
- globalDateFilterValue: n,
2508
- resolvedPrimaryDateField: r,
2509
- semanticContext: o,
2510
- timezone: i,
2511
- allowMinutePrecision: a = !1
2512
- } = e;
2513
- if (!t || !n || !r || !ze(n.operation))
2514
- return null;
2515
- const s = n, l = cr(
2516
- r.dataType
2517
- ), c = a && l, d = s.temporalPrecision === "minute" || te(s.relativeMeta) === "minute", u = c && s.temporalPrecision === "minute" ? s.temporalPrecision : void 0, f = c || te(s.relativeMeta) !== "minute" ? s.relativeMeta : void 0, m = !c && d;
2518
- return {
2519
- filterId: t.id,
2520
- dateOwner: "global_date",
2521
- name: r.qualifiedFieldName || r.name,
2522
- operation: s.operation,
2523
- valueType: "date",
2524
- values: s.operation === "is null" || s.operation === "is not null" ? [] : m ? dn(
2525
- s.values,
2526
- i
2527
- ) : s.values,
2528
- dataType: r.dataType || "date",
2529
- // The exact type travels with the filter, so the server formats the predicate for
2530
- // the column's storage type (it read it from `dataType` before 2.1 split the two).
2531
- ...r.nativeDataType ? { nativeDataType: r.nativeDataType } : {},
2532
- fieldMeta: {
2533
- name: r.name,
2534
- qualifiedFieldName: r.qualifiedFieldName,
2535
- qualifiedEntityName: r.qualifiedEntityName,
2536
- entityId: r.entityId,
2537
- entityName: r.entityName,
2538
- entityType: r.entityType,
2539
- dataType: r.dataType,
2540
- ...r.nativeDataType ? { nativeDataType: r.nativeDataType } : {},
2541
- role: "groupby",
2542
- ...t != null && t.title ? { label: t.title } : {}
2543
- },
2544
- ...o ? { semanticContext: o } : {},
2545
- ...f ? { relativeMeta: f } : {},
2546
- ...u ? { temporalPrecision: u } : {}
2547
- };
2548
- }
2549
- function E(e) {
2550
- return typeof e == "string" ? e.trim() : "";
2551
- }
2552
- function Xi(e) {
2553
- var t;
2554
- return (((t = e.semanticContext) == null ? void 0 : t.selectedEntities) || []).filter((n) => typeof n == "object" && n !== null).filter((n) => n.type === "dataset").map((n) => {
2555
- var r;
2556
- return {
2557
- domainId: E(n.domainId) || E((r = e.semanticContext) == null ? void 0 : r.semanticDomainId),
2558
- datasetName: E(n.name),
2559
- selectedEntityId: E(n.id)
2560
- };
2561
- }).filter((n) => n.domainId && n.datasetName);
2562
- }
2563
- function ea(e) {
2564
- var l, c, d, u, f;
2565
- if (U(e) || (l = e.sql) != null && l.trim())
2566
- return null;
2567
- const t = Xi(e), n = E((c = e.semanticContext) == null ? void 0 : c.semanticDomainId), r = E((d = e.fieldMeta) == null ? void 0 : d.entityId), o = E((u = e.fieldMeta) == null ? void 0 : u.entityName), i = E((f = e.fieldMeta) == null ? void 0 : f.entityType) === "dataset", a = t.find(
2568
- (m) => r && m.selectedEntityId === r
2569
- );
2570
- if (a)
2571
- return a;
2572
- const s = t.find(
2573
- (m) => o && m.datasetName === o && (!n || m.domainId === n)
2574
- );
2575
- return s || (t.length === 1 ? t[0] : i && o && n ? {
2576
- domainId: n,
2577
- datasetName: o
2578
- } : null);
2579
- }
2580
- function ta(e) {
2581
- var o, i;
2582
- const { filter: t, semanticExecutionPayload: n } = e;
2583
- if (!n)
2584
- return null;
2585
- const r = ea(t);
2586
- return r && ((i = (o = n.domainsById[r.domainId]) == null ? void 0 : o.datasetsByName[r.datasetName]) == null ? void 0 : i.primaryDateField) || null;
2587
- }
2588
- function mn(e) {
2589
- const t = L(e.filters);
2590
- return t ? e.filterValues.filter(
2591
- (n) => n.filterId !== t.id
2592
- ) : e.filterValues;
2593
- }
2594
- function _s(e) {
2595
- const t = L(e.filters), n = mn({
2596
- filters: e.filters,
2597
- filterValues: e.filterValues
2598
- });
2599
- if (!t || U(e.filter))
2600
- return n;
2601
- const r = e.filterValues.find(
2602
- (a) => a.filterId === t.id
2603
- ), o = ta({
2604
- filter: e.filter,
2605
- semanticExecutionPayload: e.semanticExecutionPayload
2606
- }), i = pn({
2607
- globalDateFilter: t,
2608
- globalDateFilterValue: r,
2609
- resolvedPrimaryDateField: o || void 0,
2610
- semanticContext: e.filter.semanticContext,
2611
- timezone: e.timezone,
2612
- allowMinutePrecision: e.allowMinutePrecision
2613
- });
2614
- return i ? [i, ...n] : n;
2615
- }
2616
- function na(e) {
2617
- var d;
2618
- const t = L(e.filters), n = t ? e.cardFilterValues.find(
2619
- (u) => u.filterId === t.id
2620
- ) : void 0, r = t ? e.cardFilterValues.filter(
2621
- (u) => u.filterId !== t.id
2622
- ) : e.cardFilterValues, o = e.resolvedPrimaryDateField ?? It({
2623
- card: e.card,
2624
- cardConfig: e.cardConfig,
2625
- resolvedFields: e.resolvedFields,
2626
- semanticExecutionPayload: e.semanticExecutionPayload
2627
- }), i = pn({
2628
- globalDateFilter: t,
2629
- globalDateFilterValue: n,
2630
- resolvedPrimaryDateField: o || void 0,
2631
- timezone: e.timezone,
2632
- allowMinutePrecision: e.allowMinutePrecision
2633
- }), a = i ? [i, ...r] : r, s = new Map(
2634
- a.map((u) => [
2635
- u.filterId,
2636
- u
2637
- ])
2638
- ), l = ((d = e.dateComparisonInputs) == null ? void 0 : d.flatMap((u) => {
2639
- var m;
2640
- const f = s.get(
2641
- u.filterId
2642
- );
2643
- return f ? [{
2644
- ...u,
2645
- effectiveFilterValue: f,
2646
- mappedFilterValue: (m = e.mappedFilterValuesByInputId) == null ? void 0 : m.get(u.inputId)
2647
- }] : [];
2648
- })) || [], c = Qi({
2649
- inputs: l,
2650
- temporalBinding: o,
2651
- card: e.card
2652
- });
2653
- return {
2654
- cardFilterValues: a,
2655
- resolvedPrimaryDateField: o,
2656
- dateComparisonPlan: c
2657
- };
2658
- }
2659
- function As(e) {
2660
- const t = L(e.filters), n = un(e), r = t ? e.filterValues.find(
2661
- (a) => a.filterId === t.id
2662
- ) : void 0, o = mn(e);
2663
- return !t || !r || !ze(r.operation) ? o : [
2664
- {
2665
- ...fn({
2666
- globalDateFilter: t,
2667
- globalDateFilterValue: r,
2668
- timezone: e.timezone,
2669
- allowMinutePrecision: n
2670
- }) || r,
2671
- filterId: t.id,
2672
- name: t.title || t.column
2673
- },
2674
- ...o
2675
- ];
2676
- }
2677
- class ra extends Error {
2678
- }
2679
- function Es(e, t) {
2680
- const n = new Map((e ? N(e) : []).map(({ card: r }) => [r.id, r]));
2681
- return t && n.set(t.id, t), [...n.values()].flatMap((r) => {
2682
- const o = Ve(r);
2683
- return o.status === "ready" ? Fi(o.config.spec, r.controlBindings) : [];
2684
- });
2685
- }
2686
- function oa(e, t, n) {
2687
- const r = dr(e);
2688
- if (!r) throw new Error("Matrix card definition is required.");
2689
- const o = n && vi({
2690
- ...n,
2691
- spec: r.spec,
2692
- catalog: t.map((d) => ({ ...d, id: d.resolvedField.id }))
2693
- }), i = o ? { ...r, spec: o.spec } : r, a = ur(t), s = fr(t), l = (d) => {
2694
- const u = s(d, i.spec.source);
2695
- if (!(!u && d.derivedField)) {
2696
- if (!u) throw new ra(`Matrix field metadata is unavailable: ${d.name}`);
2697
- return { ...u, ...d.derivedField ? { derivedField: d.derivedField } : {} };
2698
- }
2699
- }, c = {
2700
- rows: i.spec.rows.flatMap((d) => {
2701
- const u = l(d.field);
2702
- return u ? [{ ...u, id: d.id, granularity: d.grain, role: "groupby" }] : [];
2703
- }),
2704
- columns: i.spec.columns.flatMap((d) => {
2705
- const u = l(d.field);
2706
- return u ? [{ ...u, id: d.id, granularity: d.grain, role: "pivotby" }] : [];
2707
- }),
2708
- // Aggregate-stage expressions have no source-column filter target. They stay
2709
- // authoritative in matrix.spec, including all dependencies and controls.
2710
- metrics: i.spec.measures.flatMap((d) => {
2711
- if (d.kind !== "aggregate" || d.field.name === "*") return [];
2712
- const u = l(d.field);
2713
- return u ? [{ ...u, id: d.id, aggregate: d.aggregate, role: "metric" }] : [];
2714
- })
2715
- };
2716
- return { config: i, fields: c, resolveField: a };
2717
- }
2718
- function ia(e) {
2719
- const t = e.filter(Boolean);
2720
- if (t.length !== 0)
2721
- return t.length === 1 ? t[0] : {
2722
- id: Ct(),
2723
- logicalOperator: "AND",
2724
- negate: !1,
2725
- conditions: [],
2726
- groups: t
2727
- };
2728
- }
2729
- function aa(e) {
2730
- if (!e) return;
2731
- const t = (n) => ({
2732
- logicalOperator: n.logicalOperator,
2733
- negate: n.negate,
2734
- conditions: n.conditions.map((r) => ({
2735
- field: r.field.id,
2736
- operator: r.operator,
2737
- value: r.value,
2738
- temporalBucket: r.temporalBucket,
2739
- rawTemporal: r.rawTemporal,
2740
- // The run-time markers decide what runs, so they belong in the key.
2741
- relativeMeta: r.relativeMeta,
2742
- latestValue: r.latestValue,
2743
- viewerZoom: r.viewerZoom
2744
- })),
2745
- groups: n.groups.map(t)
2746
- });
2747
- return JSON.stringify(t(e));
2748
- }
2749
- function sa(e, t, n = {}) {
2750
- const r = e.metricColumns || [];
2751
- if (r.length === 0) return e;
2752
- if (n.hidden)
2753
- return { ...e, metricColumns: r.map((c) => ({ ...c, comparison: { mode: "off" } })) };
2754
- const o = pr.includes(
2755
- t
2756
- ), i = mr.includes(
2757
- t
2758
- ), a = (c) => {
2759
- var d;
2760
- return (d = c.parameters) != null && d.windowTransform ? {
2761
- ...c,
2762
- parameters: {
2763
- ...c.parameters,
2764
- windowTransform: void 0
2765
- }
2766
- } : c;
2767
- };
2768
- let s = !1;
2769
- const l = r.map(
2770
- (c) => {
2771
- var f;
2772
- const d = eo(c);
2773
- if (d === "none")
2774
- return c;
2775
- let u = c;
2776
- return (f = u.parameters) != null && f.windowTransform && (s = !0, u = a(u)), n.keepsPeriodComparison && d !== "target" ? u : o ? d === "target" && !i ? (s = !0, {
2777
- ...u,
2778
- comparison: void 0
2779
- }) : u : (s = !0, { ...u, comparison: void 0 });
2780
- }
2781
- );
2782
- return s ? {
2783
- ...e,
2784
- metricColumns: l
2785
- } : e;
2786
- }
2787
- function Bs(e, t = {}) {
2788
- return gn(yn(e, t));
2789
- }
2790
- function gn(e) {
2791
- const t = [e.drill, e.selections, e.zoom, e.search];
2792
- return e.authored ? uo(e.authored, t, Ct()) : ia(t);
2793
- }
2794
- function yn(e, t = {}) {
2795
- return {
2796
- authored: t.includeAuthoredFilters === !1 ? void 0 : gr(e),
2797
- drill: Vi(t.drill, e.id),
2798
- selections: co(t.selections ?? []),
2799
- ...t.zoom ? { zoom: t.zoom } : {}
2800
- };
2801
- }
2802
- function la(e, t, n) {
2803
- var o;
2804
- const r = Wt(e, t);
2805
- return Te(e) ? sa(
2806
- { ...r, filters: n },
2807
- e.type,
2808
- // A data variable's card keeps its own period comparison (P3b-03); a card saved
2809
- // with its comparisons hidden runs none (compare-with CW-D28).
2810
- { keepsPeriodComparison: to(e), hidden: Et((o = e.preferences) == null ? void 0 : o.comparisonPresentation) }
2811
- ) : r;
2812
- }
2813
- function ca(e) {
2814
- const t = yr(e);
2815
- return {
2816
- contextMode: t,
2817
- shouldApplyDashboardFilters: !t || t === "full"
2818
- };
2819
- }
2820
- function da(e) {
2821
- const t = e.dashboardControls || [], n = e.card.controls || [], r = /* @__PURE__ */ new Set([
2822
- ...t.map((o) => o.id),
2823
- ...n.map((o) => o.id)
2824
- ]);
2825
- return bn(
2826
- e.card,
2827
- {
2828
- controlValues: ht({
2829
- relevantControlIds: r,
2830
- dashboardValues: e.dashboardControlValues,
2831
- cardValues: e.cardControlValues
2832
- }),
2833
- controlDefinitions: t,
2834
- cardControlDefinitions: n,
2835
- controlBindings: e.card.controlBindings || []
2836
- },
2837
- e.presentationControlIds
2838
- );
2839
- }
2840
- function bn(e, t, n) {
2841
- const o = t.controlBindings.filter(
2842
- (f) => !de(f)
2843
- ), i = new Set(
2844
- Ae({
2845
- sql: e.sql,
2846
- controlBindings: o
2847
- })
2848
- ), a = new Set(
2849
- [...n].filter(
2850
- (f) => !i.has(f)
2851
- )
2852
- ), s = t.controlDefinitions.filter(
2853
- (f) => !a.has(f.id)
2854
- ), l = t.cardControlDefinitions.filter(
2855
- (f) => !a.has(f.id)
2856
- ), c = /* @__PURE__ */ new Set([
2857
- ...s.map((f) => f.id),
2858
- ...l.map((f) => f.id)
2859
- ]), d = o.filter(
2860
- (f) => c.has(f.controlId)
2861
- );
2862
- return {
2863
- controlValues: ht({
2864
- relevantControlIds: c,
2865
- dashboardValues: t.controlValues
2866
- }),
2867
- controlDefinitions: s,
2868
- cardControlDefinitions: l,
2869
- controlBindings: d
2870
- };
2871
- }
2872
- function ua(e, t) {
2873
- return !!t && e.endsWith(t);
2874
- }
2875
- function In(e, t) {
2876
- return (e ?? []).filter(
2877
- (n) => ua(n.filterId, t)
2878
- );
2879
- }
2880
- function Cn(e, t, n) {
2881
- var r, o;
2882
- if (!(!t || e.dataVariableId || Et((r = e.preferences) == null ? void 0 : r.comparisonPresentation)))
2883
- return {
2884
- selection: t,
2885
- ...((o = e.preferences) == null ? void 0 : o.inheritGlobalComparison) === !1 ? { inheritGlobalComparison: !1 } : {},
2886
- ...n ? { owner: n } : {}
2887
- };
2888
- }
2889
- function fa(e) {
2890
- if (e.resolution.status === "resolved")
2891
- return Cn(
2892
- e.card,
2893
- e.resolution.resolvedOwner.selection,
2894
- e.resolution.resolvedOwner.owner
2895
- );
2896
- }
2897
- function pa(e) {
2898
- return `Set ${e.join(", ")} to run this card.`;
2899
- }
2900
- function ma({
2901
- dashboardInputContext: e,
2902
- shouldApplyDashboardFilters: t
2903
- }) {
2904
- if (t)
2905
- return e.activeFilters;
2906
- const n = new Set(
2907
- e.inputs.flatMap(
2908
- (r) => r.kind === "filter" && wt(r) ? [r.filter.id] : []
2909
- )
2910
- );
2911
- return e.activeFilters.filter(
2912
- (r) => n.has(r.filterId)
2913
- );
2914
- }
2915
- function ga({
2916
- dashboardInputFilterValues: e,
2917
- adHocFilterValues: t
2918
- }) {
2919
- const n = [...e], r = new Set(
2920
- n.map((o) => o.filterId)
2921
- );
2922
- for (const o of t)
2923
- r.has(o.filterId) || (n.push(o), r.add(o.filterId));
2924
- return n;
2925
- }
2926
- function ce(e, t) {
2927
- const n = t.shouldApplyDashboardFilters ? In(t.adHocFilterValues, t.selectedSheetId) : [], r = t.selectionFilterValues ?? [];
2928
- if (!t.dashboardInputContext)
2929
- return {
2930
- status: "ready",
2931
- filterValues: [...n, ...t.inlineFilterValues, ...r],
2932
- mappingDispositions: []
2933
- };
2934
- const o = t.dashboardInputContext.inputs.filter(
2935
- (u) => u.kind === "filter" && !!u.application
2936
- ), i = new Set(
2937
- o.map((u) => u.filter.id)
2938
- ), a = new Set(
2939
- t.dashboardInputContext.inputs.flatMap(
2940
- (u) => {
2941
- var f;
2942
- return u.kind === "filter" && ((f = u.compatibility) == null ? void 0 : f.source) === "cardInlineFilter" ? [u.filter.id] : [];
2943
- }
2944
- )
2945
- ), s = ma({
2946
- dashboardInputContext: t.dashboardInputContext,
2947
- shouldApplyDashboardFilters: t.shouldApplyDashboardFilters
2948
- }).filter((u) => !i.has(u.filterId)), l = s.filter(
2949
- (u) => !a.has(u.filterId)
2950
- ), c = s.filter(
2951
- (u) => a.has(u.filterId)
2952
- ), d = br({
2953
- card: e,
2954
- inputs: o,
2955
- resolvedInputs: t.dashboardInputContext.resolvedInputs,
2956
- activeFilterValues: t.dashboardInputContext.activeFilters,
2957
- shouldApplyDashboardFilters: t.shouldApplyDashboardFilters
2958
- });
2959
- return d.status === "blocked" ? {
2960
- status: "blocked",
2961
- mappingDispositions: d.dispositions
2962
- } : {
2963
- status: "ready",
2964
- filterValues: [
2965
- ...ga({
2966
- dashboardInputFilterValues: [
2967
- ...l,
2968
- ...d.filterValues
2969
- ],
2970
- adHocFilterValues: n
2971
- }),
2972
- ...c,
2973
- ...r
2974
- ],
2975
- mappingDispositions: d.dispositions
2976
- };
2977
- }
2978
- function ya(e, t) {
2979
- const n = e.dashboardInputContext;
2980
- if (!n) return [];
2981
- const r = new Set(
2982
- t.flatMap(
2983
- (i) => i.status === "skip" && (i.reason === "explicitlyExcluded" || i.reason === "outsideScope") ? [i.inputId] : []
2984
- )
2985
- ), o = new Map(n.inputs.map((i) => [i.id, i]));
2986
- return n.resolvedInputs.flatMap((i) => {
2987
- if (!i.missingRequiredValue) return [];
2988
- const a = o.get(i.id);
2989
- return a ? a.kind === "filter" && (!e.shouldApplyDashboardFilters && !wt(a) || r.has(a.id)) ? [] : [i.label] : [];
2990
- });
2991
- }
2992
- function ba({
2993
- card: e,
2994
- cardConfig: t,
2995
- input: n,
2996
- resolvedPrimaryDateField: r,
2997
- resolvedFields: o,
2998
- semanticExecutionPayload: i,
2999
- timezone: a,
3000
- allowMinutePrecision: s
3001
- }) {
3002
- var p;
3003
- const l = n.dashboardInputContext ? n.dashboardInputContext.inputs.flatMap(
3004
- (b) => b.kind === "filter" ? [b.filter] : []
3005
- ) : [], c = ce(e, n), d = ya(
3006
- n,
3007
- c.mappingDispositions
3008
- );
3009
- if (d.length)
3010
- return {
3011
- status: "blocked",
3012
- cardId: e.id,
3013
- reason: "requiredInput",
3014
- mappingDispositions: c.mappingDispositions,
3015
- missingRequiredLabels: d
3016
- };
3017
- if (c.status === "blocked")
3018
- return {
3019
- status: "blocked",
3020
- cardId: e.id,
3021
- reason: "mapping",
3022
- mappingDispositions: c.mappingDispositions,
3023
- missingRequiredLabels: []
3024
- };
3025
- const u = na({
3026
- card: e,
3027
- cardConfig: t,
3028
- filters: l,
3029
- cardFilterValues: c.filterValues,
3030
- resolvedPrimaryDateField: r,
3031
- resolvedFields: o,
3032
- semanticExecutionPayload: i,
3033
- timezone: a,
3034
- allowMinutePrecision: s,
3035
- dateComparisonInputs: n.dateComparisonInputs,
3036
- mappedFilterValuesByInputId: new Map(
3037
- c.mappingDispositions.flatMap(
3038
- (b) => b.status === "apply" ? [[b.inputId, b.filterValue]] : []
3039
- )
3040
- )
3041
- }), f = L(l), m = !!(f && u.cardFilterValues.some(
3042
- (b) => b.filterId === f.id
3043
- )), y = u.resolvedPrimaryDateField && !((p = e.sql) != null && p.trim()) ? u.dateComparisonPlan.inputs.length ? fa({
3044
- card: e,
3045
- resolution: u.dateComparisonPlan.resolution
3046
- }) : m ? Cn(
3047
- e,
3048
- n.globalDateComparisonSelection
3049
- ) : void 0 : void 0;
3050
- return {
3051
- status: "ready",
3052
- ...u,
3053
- queryFilterDefinitions: l,
3054
- globalDateComparison: y,
3055
- mappingDispositions: c.mappingDispositions
3056
- };
3057
- }
3058
- function Ia({
3059
- card: e,
3060
- dashboard: t,
3061
- transientContexts: n,
3062
- cardViewState: r,
3063
- viewerTableSettings: o,
3064
- adHocFilterValues: i,
3065
- selectedSheetId: a,
3066
- inlineFilterValuesMap: s,
3067
- dashboardControls: l,
3068
- dashboardControlValues: c,
3069
- cardControlValuesMap: d,
3070
- dashboardInputContext: u,
3071
- includeAuthoredFilters: f
3072
- }) {
3073
- var K, Y, Le, Ke;
3074
- const m = Gt(t);
3075
- for (const q of e.controlBindings || [])
3076
- de(q) && m.add(q.controlId);
3077
- const { shouldApplyDashboardFilters: y } = ca(n), p = u != null && u.inputs.length ? u : void 0, b = ((u == null ? void 0 : u.selections) ?? []).filter(
3078
- (q) => q.status === "apply"
3079
- ), I = yn(e, {
3080
- includeAuthoredFilters: f,
3081
- selections: b,
3082
- drill: r == null ? void 0 : r.drill
3083
- }), C = {
3084
- adHocFilterValues: i || [],
3085
- selectedSheetId: a,
3086
- inlineFilterValues: (s == null ? void 0 : s[e.id]) || [],
3087
- // Outside the input-context gate: a dashboard whose only input is a
3088
- // click still sends them.
3089
- selectionFilterValues: b.flatMap((q) => q.filterValues),
3090
- shouldApplyDashboardFilters: y,
3091
- ...p ? {
3092
- dashboardInputContext: {
3093
- inputs: p.inputs,
3094
- resolvedInputs: p.resolvedInputs,
3095
- activeFilters: p.activeFilters
3096
- }
3097
- } : {},
3098
- ...p != null && p.globalDateComparisonSelection ? {
3099
- globalDateComparisonSelection: p.globalDateComparisonSelection
3100
- } : {},
3101
- ...p != null && p.dateComparisonInputs ? {
3102
- dateComparisonInputs: p.dateComparisonInputs
3103
- } : {}
3104
- }, h = ce(e, C), S = {
3105
- filterValues: h.status === "ready" ? h.filterValues : [],
3106
- selectionFilters: I.selections
3107
- }, g = rt(S), V = wi(r == null ? void 0 : r.zoom, (K = e.config) == null ? void 0 : K.groupByColumns, g), P = Ir(
3108
- Si(e, r == null ? void 0 : r.drill),
3109
- (Y = r == null ? void 0 : r.search) == null ? void 0 : Y.text,
3110
- o
3111
- ), x = {
3112
- ...I,
3113
- ...V ? { zoom: V.filterGroup } : {},
3114
- ...P ? { search: P } : {}
3115
- }, v = V ? rt({ ...S, zoom: V.zoom }) : g, T = gn(x), M = f === !1 ? me(T, !0) : T, k = la(
3116
- e,
3117
- r == null ? void 0 : r.drill,
3118
- M
3119
- ), F = xi(k, r == null ? void 0 : r.grainPick, {
3120
- currentFingerprint: v,
3121
- drillActive: (((Le = r == null ? void 0 : r.drill) == null ? void 0 : Le.steps.length) ?? 0) > 0
3122
- }), D = Cr({ ...e, config: F }, o) ?? F, w = Nt(D, {
3123
- cardType: e.type,
3124
- dataSource: e.dataSource,
3125
- temporalResultOwner: vt({
3126
- hasExecutableConfig: ue(D, e.type),
3127
- sql: e.sql,
3128
- normalizedPython: Me(e.python || "")
3129
- })
3130
- }) || D, B = aa(M) || "", R = p ? bn(
3131
- e,
3132
- {
3133
- controlValues: p.controlValues,
3134
- controlDefinitions: p.controlDefinitions,
3135
- cardControlDefinitions: p.cardControlDefinitions,
3136
- controlBindings: p.controlBindings
3137
- },
3138
- m
3139
- ) : da({
3140
- card: e,
3141
- presentationControlIds: m,
3142
- dashboardControls: l,
3143
- dashboardControlValues: c,
3144
- cardControlValues: d == null ? void 0 : d[e.id]
3145
- });
3146
- return {
3147
- filterCompilationInput: C,
3148
- ...R,
3149
- resolvedFilters: M,
3150
- resolvedFilterParts: x,
3151
- drillSteps: ((Ke = r == null ? void 0 : r.drill) == null ? void 0 : Ke.steps) ?? hr,
3152
- dateContextKey: v,
3153
- zoomContextKey: g,
3154
- ...V ? { activeZoom: V.zoom } : {},
3155
- finalConfig: D,
3156
- queryRelevantConfig: w,
3157
- finalFiltersKey: B
3158
- };
3159
- }
3160
- function hn(e, t, n) {
3161
- const r = ba({
3162
- resolvedFields: t.resolvedDateFields,
3163
- ...n,
3164
- card: e,
3165
- cardConfig: t.queryRelevantConfig,
3166
- input: t.filterCompilationInput
3167
- });
3168
- if (r.status === "blocked") return r;
3169
- const { filterCompilationInput: o, ...i } = t;
3170
- return { status: "ready", queryContext: {
3171
- ...i,
3172
- cardFilterValues: r.cardFilterValues,
3173
- queryFilterDefinitions: r.queryFilterDefinitions,
3174
- resolvedPrimaryDateField: r.resolvedPrimaryDateField,
3175
- globalDateComparison: r.globalDateComparison,
3176
- globalDateComparisonSelection: o.globalDateComparisonSelection,
3177
- dateComparisonInputs: o.dateComparisonInputs
3178
- }, compiledFilters: r };
3179
- }
3180
- function Ca(e, t, n) {
3181
- const r = vr(e), o = hn(e, t, {
3182
- resolvedPrimaryDateField: n.resolvedPrimaryDateField,
3183
- timezone: n.calendarContext.tz,
3184
- allowMinutePrecision: n.allowGlobalDateMinutePrecision
3185
- });
3186
- if (o.status === "blocked")
3187
- return { ...o, tableConfig: r };
3188
- const { compiledFilters: i } = o, {
3189
- cardFilterValues: a,
3190
- resolvedPrimaryDateField: s,
3191
- globalDateComparison: l
3192
- } = i, { queryKey: c, queryInputIdentity: d, paginationConfig: u } = di(
3193
- e,
3194
- o.queryContext,
3195
- n.calendarContext,
3196
- { resolvePaginationConfig: n.resolvePaginationConfig }
3197
- ), f = t.queryRelevantConfig, m = Me(e.python || ""), y = vt({
3198
- hasExecutableConfig: ue(f, e.type),
3199
- sql: e.sql,
3200
- normalizedPython: m
3201
- });
3202
- return {
3203
- status: "ready",
3204
- queryKey: c,
3205
- queryInputIdentity: d,
3206
- paginationConfig: u,
3207
- tableConfig: r,
3208
- compiledFilters: i,
3209
- requestPayloadBase: {
3210
- cardId: e.id,
3211
- sql: (e == null ? void 0 : e.sql) || "",
3212
- python: m,
3213
- resultOwner: y,
3214
- active_filters: a,
3215
- controlValues: t.controlValues,
3216
- controlDefinitions: t.controlDefinitions,
3217
- cardControlDefinitions: t.cardControlDefinitions,
3218
- controlBindings: t.controlBindings,
3219
- cache_config: n.globalCacheConfig,
3220
- queryConfig: e.queryConfig,
3221
- tableConfig: r,
3222
- cardType: e.type,
3223
- cardTitle: e.title || "",
3224
- cardConfig: f,
3225
- cardDataSource: e.dataSource,
3226
- resolvedPrimaryDateField: s || void 0,
3227
- calendarContext: n.calendarContext,
3228
- ...l ? { globalDateComparison: l } : {},
3229
- ...t.sqlRowLimit ? { sqlRowLimit: t.sqlRowLimit } : {}
3230
- }
3231
- };
3232
- }
3233
- const lt = [], ha = [], va = {};
3234
- function Rs(e, t) {
3235
- return {
3236
- sheetId: e.sheetId,
3237
- sectionId: e.sectionId,
3238
- documentFilterValues: e.documentFilterValues ?? lt,
3239
- documentControlDefinitions: e.documentControlDefinitions ?? ha,
3240
- documentControlValues: e.documentControlValues ?? va,
3241
- editorFilterValues: t ?? lt
3242
- };
3243
- }
3244
- function Fa({
3245
- card: e,
3246
- dashboard: t,
3247
- runtime: n,
3248
- dashboardRuntimeValues: r,
3249
- calendar: o
3250
- }) {
3251
- const i = Ft({
3252
- dashboard: t,
3253
- dashboardInputValues: r.dashboardInputValues,
3254
- transientContexts: void 0
3255
- }) ? Oe({
3256
- transientContexts: void 0,
3257
- dashboard: t,
3258
- sheetId: n.sheetId,
3259
- sheetKind: "document",
3260
- sectionId: n.sectionId,
3261
- card: e,
3262
- runtimeValues: {
3263
- ...r,
3264
- dashboardInputValues: n.documentDashboardInputValues || r.dashboardInputValues
3265
- },
3266
- calendar: o
3267
- }) : void 0, a = i && (i.inputs.length > 0 || i.selections.length > 0) ? i : void 0, s = !!(i != null && i.inputs.length), l = [
3268
- ...n.editorFilterValues || [],
3269
- ...n.documentFilterValues
3270
- ];
3271
- return {
3272
- card: s ? e : Da(
3273
- e,
3274
- n.documentControlDefinitions
3275
- ),
3276
- dashboard: t,
3277
- transientContexts: void 0,
3278
- // Document section cards do not drill.
3279
- cardViewState: void 0,
3280
- // Document section cards are not viewer-customizable tables.
3281
- viewerTableSettings: void 0,
3282
- adHocFilterValues: [],
3283
- inlineFilterValuesMap: !s && l.length ? { [e.id]: l } : {},
3284
- dashboardControls: [],
3285
- dashboardControlValues: {},
3286
- cardControlValuesMap: !s && Object.keys(n.documentControlValues).length > 0 ? { [e.id]: n.documentControlValues } : {},
3287
- dashboardInputContext: a
3288
- };
3289
- }
3290
- function Da(e, t) {
3291
- if (t.length === 0)
3292
- return e;
3293
- const n = /* @__PURE__ */ new Map();
3294
- for (const r of e.controls || [])
3295
- n.set(r.id, r);
3296
- for (const r of t)
3297
- n.set(r.id, r);
3298
- return {
3299
- ...e,
3300
- controls: Array.from(n.values())
3301
- };
3302
- }
3303
- function qs({
3304
- card: e,
3305
- place: t,
3306
- source: n
3307
- }) {
3308
- ({ card: e, place: t, source: n } = vn(e, t, n));
3309
- const r = Se(e, t, n);
3310
- return {
3311
- card: r.card,
3312
- context: r.context,
3313
- inputContext: r.inputContext
3314
- };
3315
- }
3316
- function Sa(e, t, n) {
3317
- return {
3318
- calendarContext: n ?? io,
3319
- allowGlobalDateMinutePrecision: we(
3320
- e,
3321
- t
3322
- ).allEligibleTargetsAreDateTime,
3323
- semanticExecutionPayload: t,
3324
- globalCacheConfig: e.globalCacheConfig
3325
- };
3326
- }
3327
- function js(e, t) {
3328
- return Sn(
3329
- e,
3330
- t,
3331
- t.allowGlobalDateMinutePrecision
3332
- );
3333
- }
3334
- function Ta(e, t, n = {}) {
3335
- const r = Dn(e, t);
3336
- return {
3337
- ...Ca(e.card, e.context, {
3338
- resolvedPrimaryDateField: r,
3339
- calendarContext: t.calendarContext,
3340
- allowGlobalDateMinutePrecision: t.allowGlobalDateMinutePrecision,
3341
- globalCacheConfig: t.globalCacheConfig,
3342
- resolvePaginationConfig: n.resolvePaginationConfig
3343
- }),
3344
- resolvedPrimaryDateField: r
3345
- };
3346
- }
3347
- function Va({
3348
- card: e,
3349
- place: t,
3350
- source: n,
3351
- semanticExecutionPayload: r,
3352
- matrixCatalog: o,
3353
- withRequest: i = !1
3354
- }) {
3355
- var p, b;
3356
- ({ card: e, place: t, source: n } = vn(e, t, n));
3357
- const { dashboard: a } = n, s = e.id, l = (I, C) => {
3358
- var S;
3359
- let h;
3360
- try {
3361
- const g = Ve(I);
3362
- if (g.status === "invalid") throw g.error;
3363
- const V = Se(
3364
- I,
3365
- C,
3366
- n,
3367
- g.status === "absent"
3368
- );
3369
- if (h = V.context, g.status === "absent")
3370
- return { status: "ready", value: { assembled: V } };
3371
- if (!o)
3372
- return {
3373
- status: "blocked",
3374
- reason: "metadata",
3375
- message: "Matrix field metadata is required.",
3376
- context: h
3377
- };
3378
- const P = Di(g.config.spec, h), x = o.filter(
3379
- (D) => D.field.source && P.some(
3380
- (w) => Ce(w, D.field.source)
3381
- )
3382
- ), v = oa(I, x, h), { params: T } = V, M = T.dashboardInputContext;
3383
- v.config = {
3384
- ...v.config,
3385
- presentation: Zo(
3386
- I,
3387
- v.config,
3388
- {
3389
- controls: M ? [
3390
- ...M.controlDefinitions,
3391
- ...M.cardControlDefinitions
3392
- ] : [
3393
- ...T.dashboardControls ?? a.controls ?? [],
3394
- ...T.card.controls ?? []
3395
- ],
3396
- values: (M == null ? void 0 : M.controlValues) ?? {
3397
- ...T.dashboardControlValues,
3398
- ...(S = T.cardControlValuesMap) == null ? void 0 : S[I.id]
3399
- }
3400
- },
3401
- x
3402
- )
3403
- };
3404
- const k = {
3405
- ...I,
3406
- config: { matrix: v.config }
3407
- }, F = Se(k, C, n, !1);
3408
- return {
3409
- status: "ready",
3410
- value: {
3411
- assembled: {
3412
- card: k,
3413
- context: { ...F.context, resolvedDateFields: v.fields },
3414
- inputContext: F.inputContext
3415
- },
3416
- matrix: v
3417
- }
3418
- };
3419
- } catch (g) {
3420
- return {
3421
- status: "blocked",
3422
- reason: "configuration",
3423
- message: g instanceof Error ? g.message : "Card configuration is invalid.",
3424
- context: h
3425
- };
3426
- }
3427
- }, c = l(e, t);
3428
- if (c.status === "blocked")
3429
- return {
3430
- status: "blocked",
3431
- cardId: s,
3432
- mappingDispositions: [],
3433
- reason: c.reason,
3434
- missingRequiredLabels: [],
3435
- message: c.message
3436
- };
3437
- const { assembled: d, matrix: u } = c.value, f = Sa(
3438
- a,
3439
- r,
3440
- n.calendar
3441
- ), m = d.context.filterCompilationInput, y = Fr(a);
3442
- try {
3443
- const I = ce(d.card, m), C = u && y && I.status === "ready" && I.filterValues.some((V) => V.filterId === y.id);
3444
- let h = f.allowGlobalDateMinutePrecision;
3445
- if (C) {
3446
- const V = (p = m.dashboardInputContext) == null ? void 0 : p.inputs.find(
3447
- (F) => F.kind === "filter" && F.filter.id === y.id
3448
- ), x = Dr(a, y).filter(
3449
- ({ card: F, sheet: D }) => !V || no(V, {
3450
- cardId: F.id,
3451
- sheetId: D.id,
3452
- sheetKind: Dt(D) ? "document" : "dashboard"
3453
- })
3454
- ).map(({ card: F, sheet: D }) => ({
3455
- card: F,
3456
- value: F.id === s ? c : l(F, { kind: "sheet", sheetId: D.id })
3457
- })), v = new Map(
3458
- x.map(({ card: F, value: D }) => [
3459
- F.id,
3460
- D.status === "ready" ? D.value.assembled.card : null
3461
- ])
3462
- ), T = new Map(
3463
- x.map(({ card: F, value: D }) => {
3464
- var w;
3465
- return [
3466
- F.id,
3467
- D.status === "ready" ? (w = D.value.matrix) == null ? void 0 : w.fields : void 0
3468
- ];
3469
- })
3470
- ), M = x.flatMap(
3471
- ({ card: F, value: D }) => {
3472
- const w = F.id, B = D.status === "ready" ? D.value.assembled.context : D.context;
3473
- if (!B) return [w];
3474
- const R = D.status === "ready" ? D.value.assembled.card : F;
3475
- try {
3476
- const K = ce(
3477
- R,
3478
- B.filterCompilationInput
3479
- );
3480
- return K.status === "blocked" || K.filterValues.some((Y) => Y.filterId === y.id) ? [w] : [];
3481
- } catch {
3482
- return v.set(w, null), [w];
3483
- }
3484
- }
3485
- ), k = we(
3486
- a,
3487
- r,
3488
- y,
3489
- v,
3490
- T,
3491
- M
3492
- );
3493
- if ((b = k.unresolvedCardIds) != null && b.length)
3494
- return {
3495
- status: "blocked",
3496
- cardId: s,
3497
- mappingDispositions: [],
3498
- reason: "coverage",
3499
- missingRequiredLabels: [],
3500
- message: `Date precision requires field metadata and valid inputs for: ${k.unresolvedCardIds.join(", ")}.`
3501
- };
3502
- h = k.allEligibleTargetsAreDateTime;
3503
- }
3504
- const S = Sn(d, f, h);
3505
- if (S.status === "blocked")
3506
- return {
3507
- status: "blocked",
3508
- cardId: S.cardId,
3509
- mappingDispositions: S.mappingDispositions,
3510
- reason: S.reason,
3511
- missingRequiredLabels: S.missingRequiredLabels,
3512
- ...S.reason === "requiredInput" ? { message: pa(S.missingRequiredLabels) } : {},
3513
- ...S.resolvedPrimaryDateField ? { resolvedPrimaryDateField: S.resolvedPrimaryDateField } : {}
3514
- };
3515
- const g = i && !u ? Ta(d, f) : void 0;
3516
- return {
3517
- ...S,
3518
- ...u ? { matrix: u } : {},
3519
- // The whole request a card runs with: the contract's payload and its
3520
- // extras (server pagination, table totals) from the one extras owner,
3521
- // on the first page a new viewer opens (ledger P3-78).
3522
- ...(g == null ? void 0 : g.status) === "ready" ? {
3523
- request: {
3524
- ...g.requestPayloadBase,
3525
- ...bi({
3526
- card: d.card,
3527
- finalConfig: d.context.finalConfig,
3528
- documentSection: t.kind === "documentSection" ? {} : void 0,
3529
- page: yi(d.card)
3530
- })
3531
- }
3532
- } : {}
3533
- };
3534
- } catch (I) {
3535
- return {
3536
- status: "blocked",
3537
- cardId: s,
3538
- mappingDispositions: [],
3539
- reason: "configuration",
3540
- missingRequiredLabels: [],
3541
- message: I instanceof Error ? I.message : "Card filter configuration is invalid."
3542
- };
3543
- }
3544
- }
3545
- function vn(e, t, n) {
3546
- var s, l, c;
3547
- const r = ((s = n.editor) == null ? void 0 : s.calculatedFields) ?? n.dashboard.calculatedFields;
3548
- if (!(r != null && r.length)) return { card: e, place: t, source: n };
3549
- const o = (d) => Sr(d, r), i = {
3550
- ...n,
3551
- dashboard: yt(n.dashboard, r),
3552
- adHocFilterValues: o(n.adHocFilterValues),
3553
- inlineFilterValuesMap: o(n.inlineFilterValuesMap),
3554
- dashboardInputValues: o(n.dashboardInputValues),
3555
- ...n.editor ? { editor: { ...n.editor, inlineFilterValuesMap: o(n.editor.inlineFilterValuesMap) } } : {}
3556
- }, a = i.dashboard === n.dashboard && i.adHocFilterValues === n.adHocFilterValues && i.inlineFilterValuesMap === n.inlineFilterValuesMap && i.dashboardInputValues === n.dashboardInputValues && ((l = i.editor) == null ? void 0 : l.inlineFilterValuesMap) === ((c = n.editor) == null ? void 0 : c.inlineFilterValuesMap);
3557
- return {
3558
- card: o(e),
3559
- place: t.kind === "documentSection" ? { ...t, section: o(t.section) } : t,
3560
- source: a ? n : i
3561
- };
3562
- }
3563
- function Ma(e, t) {
3564
- const n = e.editor ? {
3565
- ...e.inlineFilterValuesMap,
3566
- ...Object.fromEntries(
3567
- Object.entries(e.editor.inlineFilterValuesMap).filter(
3568
- (a) => a[1] !== void 0
3569
- )
3570
- )
3571
- } : e.inlineFilterValuesMap, r = n == null ? void 0 : n[t.id], o = Tr(t, r), i = o === r ? n : { ...n, [t.id]: o };
3572
- return {
3573
- dashboardInputValues: e.dashboardInputValues,
3574
- adHocFilterValues: e.adHocFilterValues,
3575
- controlValues: e.controlValues,
3576
- inlineFilterValuesMap: i,
3577
- cardControlValuesMap: e.cardControlValuesMap
3578
- };
3579
- }
3580
- function Se(e, t, n, r) {
3581
- var c, d;
3582
- const { dashboard: o } = n, i = Ma(n, e), a = t.kind === "documentSection" ? {
3583
- ...Fa({
3584
- card: e,
3585
- dashboard: o,
3586
- runtime: t.section,
3587
- dashboardRuntimeValues: i,
3588
- calendar: n.calendar
3589
- }),
3590
- selectedSheetId: t.section.sheetId,
3591
- includeAuthoredFilters: r
3592
- } : ka(e, t.sheetId, n, i, r), s = Ia(a), l = (c = e.config) == null ? void 0 : c.rowLimit;
3593
- return (d = e.sql) != null && d.trim() && l && Fn(o, e.id) && (s.sqlRowLimit = l), {
3594
- card: a.card,
3595
- params: a,
3596
- context: s,
3597
- inputContext: a.dashboardInputContext
3598
- };
3599
- }
3600
- function Fn(e, t) {
3601
- return (e.variables ?? []).some((n) => n.id === t);
3602
- }
3603
- function ka(e, t, n, r, o) {
3604
- var c, d, u;
3605
- const { dashboard: i } = n, a = Fn(i, e.id), s = a ? void 0 : n.transientContexts, l = Ft({
3606
- dashboard: i,
3607
- dashboardInputValues: r.dashboardInputValues,
3608
- transientContexts: s
3609
- }) ? Oe({
3610
- transientContexts: s,
3611
- dashboard: i,
3612
- sheetId: t,
3613
- card: e,
3614
- runtimeValues: r,
3615
- calendar: n.calendar
3616
- }) : void 0;
3617
- return {
3618
- card: e,
3619
- dashboard: i,
3620
- transientContexts: s,
3621
- // The editor previews the card without a viewer's zoom (chart date zoom
3622
- // DZ-D1) or search (table column filters TCF-D10): it shows the
3623
- // dashboard's dates and every row, and its save never sees either.
3624
- cardViewState: a ? void 0 : n.editor ? Vr(
3625
- Mr((c = n.cardViewStates) == null ? void 0 : c[e.id], null),
3626
- null
3627
- ) : (d = n.cardViewStates) == null ? void 0 : d[e.id],
3628
- viewerTableSettings: n.editor || a || (u = n.viewerTableSettings) == null ? void 0 : u[e.id],
3629
- adHocFilterValues: a ? [] : r.adHocFilterValues,
3630
- selectedSheetId: t,
3631
- inlineFilterValuesMap: r.inlineFilterValuesMap,
3632
- dashboardControls: i.controls,
3633
- dashboardControlValues: r.controlValues,
3634
- cardControlValuesMap: r.cardControlValuesMap,
3635
- // Keep a selection-only context so the query has one resolved-input contract.
3636
- dashboardInputContext: l && (l.inputs.length > 0 || l.selections.length > 0) ? l : void 0,
3637
- includeAuthoredFilters: o
3638
- };
3639
- }
3640
- function Dn({ card: e, context: t }, n) {
3641
- return It({
3642
- card: e,
3643
- cardConfig: t.queryRelevantConfig,
3644
- resolvedFields: t.resolvedDateFields,
3645
- semanticExecutionPayload: n.semanticExecutionPayload
3646
- });
3647
- }
3648
- function Sn(e, t, n) {
3649
- const { card: r } = e, o = Dn(e, t), i = hn(r, e.context, {
3650
- resolvedPrimaryDateField: o,
3651
- timezone: t.calendarContext.tz,
3652
- allowMinutePrecision: n
3653
- });
3654
- return i.status === "blocked" ? { ...i, card: r, resolvedPrimaryDateField: o } : {
3655
- status: "ready",
3656
- card: r,
3657
- queryContext: i.queryContext,
3658
- compiledFilters: i.compiledFilters,
3659
- resolvedPrimaryDateField: o
3660
- };
3661
- }
3662
- function Ns({
3663
- dashboard: e,
3664
- dashboardInputValues: t,
3665
- adHocFilterValues: n,
3666
- calendar: r,
3667
- selectedSheetId: o,
3668
- sheetSelection: i = "current",
3669
- dashboardControlValues: a,
3670
- cardControlValuesMap: s,
3671
- semanticExecutionPayload: l,
3672
- timezone: c
3673
- }) {
3674
- const d = e ? [...kr(e)] : void 0, u = o ?? null, f = (C) => {
3675
- var h;
3676
- return e ? wa({
3677
- dashboard: e,
3678
- runtimeValues: { dashboardInputValues: t },
3679
- adHocFilterValues: n,
3680
- sheetId: C,
3681
- sheetKind: Dt(
3682
- (h = e.sheets) == null ? void 0 : h.find((S) => S.id === C)
3683
- ) ? "document" : "dashboard",
3684
- calendar: r
3685
- }) : [];
3686
- }, m = i === "all" ? Array.from(
3687
- new Map(
3688
- ((e == null ? void 0 : e.sheets) || []).flatMap(
3689
- (C) => f(C.id).map(
3690
- (h) => [h.filterId, h]
3691
- )
3692
- )
3693
- ).values()
3694
- ) : f(u), y = {
3695
- ...a || {}
3696
- }, p = i === "all" ? N({ sheets: (e == null ? void 0 : e.sheets) || [] }) : u ? N({ sheets: (e == null ? void 0 : e.sheets) || [] }).filter(
3697
- (C) => C.sheet.id === u
3698
- ) : [];
3699
- for (const C of p)
3700
- Object.assign(y, (s == null ? void 0 : s[C.card.id]) || {});
3701
- const b = xr({
3702
- filterDefinitions: d,
3703
- filterValues: m
3704
- }), I = Yi({
3705
- filters: d,
3706
- filterValues: b,
3707
- dashboard: e,
3708
- semanticExecutionPayload: l,
3709
- timezone: c
3710
- });
3711
- return {
3712
- selectedSheetId: u,
3713
- filterValues: I,
3714
- controlValues: y
3715
- };
3716
- }
3717
- function zs({
3718
- dashboard: e,
3719
- cardId: t,
3720
- transientContexts: n,
3721
- cardViewStates: r,
3722
- viewerTableSettings: o,
3723
- semanticExecutionPayload: i,
3724
- adHocFilterValues: a,
3725
- inlineFilterValuesMap: s,
3726
- dashboardControlValues: l,
3727
- cardControlValuesMap: c,
3728
- dashboardInputValues: d,
3729
- calendar: u,
3730
- matrixCatalog: f,
3731
- cardOverride: m,
3732
- sheetId: y,
3733
- documentSection: p,
3734
- editor: b,
3735
- withRequest: I
3736
- }) {
3737
- var S;
3738
- if (!e)
3739
- return null;
3740
- m && !$e(e, t) && y && (e = { ...e, sheets: (S = e.sheets) == null ? void 0 : S.map((g) => g.id === y ? { ...g, cards: [...g.cards ?? [], m] } : g) });
3741
- const C = $e(e, t);
3742
- if (!C)
3743
- return null;
3744
- const h = Va({
3745
- card: m ?? C.card,
3746
- place: p ? { kind: "documentSection", section: p } : { kind: "sheet", sheetId: C.sheet.id },
3747
- source: {
3748
- dashboard: e,
3749
- adHocFilterValues: a,
3750
- controlValues: l,
3751
- inlineFilterValuesMap: s,
3752
- cardControlValuesMap: c ? Object.fromEntries(
3753
- Object.entries(c).filter(
3754
- (g) => g[1] !== void 0
3755
- )
3756
- ) : void 0,
3757
- dashboardInputValues: d,
3758
- transientContexts: n,
3759
- cardViewStates: r,
3760
- viewerTableSettings: o,
3761
- calendar: u,
3762
- ...b ? { editor: b } : {}
3763
- },
3764
- semanticExecutionPayload: i,
3765
- matrixCatalog: f,
3766
- withRequest: I
3767
- });
3768
- return h.status === "blocked" ? h : {
3769
- status: "ready",
3770
- card: m ?? C.card,
3771
- sheetId: C.sheet.id,
3772
- queryContext: h.queryContext,
3773
- compiledFilters: h.compiledFilters,
3774
- resolvedPrimaryDateField: h.resolvedPrimaryDateField,
3775
- ...h.matrix ? { matrix: h.matrix } : {},
3776
- ...h.request ? { request: h.request } : {}
3777
- };
3778
- }
3779
- function xa(e, t, n) {
3780
- const r = t === "date" && "relativeMeta" in e ? Lr(e.relativeMeta) : void 0;
3781
- if (!r) return { values: e.values };
3782
- const o = _r(r, n ?? void 0), i = Kr(String(e.operation), r);
3783
- return {
3784
- values: o && i ? Gr(String(e.operation), o) : e.values,
3785
- relativeMeta: r,
3786
- ..."temporalPrecision" in e && e.temporalPrecision === "minute" ? { temporalPrecision: "minute" } : {}
3787
- };
3788
- }
3789
- function Pa(e, t, n) {
3790
- const r = t, o = wr(e);
3791
- return Or({
3792
- definition: e,
3793
- sourceValue: r,
3794
- value: {
3795
- filterId: r.filterId,
3796
- name: e.column,
3797
- operation: r.operation ?? e.operation,
3798
- valueType: o,
3799
- dataType: e.dataType,
3800
- fieldMeta: e.fieldMeta,
3801
- semanticContext: e.semanticContext,
3802
- ...xa(r, o, n)
3803
- }
3804
- });
3805
- }
3806
- function Tn(e, t, n) {
3807
- const r = A(e);
3808
- let o = {};
3809
- const i = [], a = [];
3810
- for (const s of t ?? []) {
3811
- if (oo(s.filterId)) {
3812
- a.push(s.filterId);
3813
- continue;
3814
- }
3815
- const l = r.findFilterInput({ filterId: s.filterId }), c = l == null ? void 0 : l.input;
3816
- if (c || i.push(s), !c || c.runtimeScope === "perCard" || c.runtimeScope === "perDocumentSection") {
3817
- a.push(s.filterId);
3818
- continue;
3819
- }
3820
- const d = Pr(
3821
- Pa(c.filter, s, n.calendar)
3822
- );
3823
- if (d) {
3824
- if (c.runtimeScope === "shared") {
3825
- o = He(o, c, {}, d);
3826
- continue;
3827
- }
3828
- for (const u of Ot(e).values())
3829
- _t(c, u) && (o = He(
3830
- o,
3831
- c,
3832
- { sheetId: u.sheetId },
3833
- d
3834
- ));
3835
- }
3836
- }
3837
- return { slots: o, adHocFilterValues: i, droppedFilterIds: a };
3838
- }
3839
- function wa(e) {
3840
- const { dashboard: t, sheetId: n } = e, r = [];
3841
- if (n)
3842
- for (const { input: o } of Ar(t, n, e.sheetKind)) {
3843
- const i = Er({
3844
- dashboard: t,
3845
- input: o,
3846
- runtimeValues: { dashboardInputValues: e.runtimeValues.dashboardInputValues },
3847
- target: { sheetId: n },
3848
- calendar: e.calendar
3849
- });
3850
- i.kind === "filter" && i.filterValue && r.push(i.filterValue);
3851
- }
3852
- return [...r, ...In(e.adHocFilterValues, n)];
3853
- }
3854
- function Ls(e, t) {
3855
- switch (t.runtimeScope) {
3856
- case "shared":
3857
- return [{}];
3858
- case "perSheet":
3859
- return [...Ot(e).values()].filter((n) => _t(t, n)).map((n) => ({ sheetId: n.sheetId }));
3860
- case "perCard": {
3861
- const n = A(e);
3862
- return [
3863
- ...n.reachedCards({ inputId: t.id }).map((r) => ({ sheetId: r.sheetId, cardId: r.cardId })),
3864
- // A variable holds a value at each place it is used (DV-D35).
3865
- ...n.reachedVariables({ inputId: t.id }).flatMap(
3866
- (r) => r.places.map((o) => ({ sheetId: o.sheetId, cardId: r.variableId }))
3867
- )
3868
- ];
3869
- }
3870
- case "perDocumentSection": {
3871
- const n = /* @__PURE__ */ new Map();
3872
- for (const r of A(e).reachedCards({ inputId: t.id }))
3873
- r.kind === "documentSectionCard" && n.set(r.sectionId, { sheetId: r.sheetId, sectionId: r.sectionId });
3874
- return [...n.values()];
3875
- }
3876
- default:
3877
- return [];
3878
- }
3879
- }
3880
- function ct(e) {
3881
- var t;
3882
- return [
3883
- ...e.cards ?? [],
3884
- ...(e.frames ?? []).flatMap((n) => n.cards),
3885
- ...(((t = e.document) == null ? void 0 : t.sections) ?? []).flatMap(
3886
- (n) => At(n)
3887
- )
3888
- ];
3889
- }
3890
- function Oa(e, t) {
3891
- var n, r;
3892
- return {
3893
- sheetId: e.id,
3894
- cardId: t.id,
3895
- sheetKind: e.kind ?? "dashboard",
3896
- sectionId: (r = (n = e.document) == null ? void 0 : n.sections.find(
3897
- (o) => At(o).some(({ id: i }) => i === t.id)
3898
- )) == null ? void 0 : r.id
3899
- };
3900
- }
3901
- function _a(e, t, n, r) {
3902
- var c, d, u;
3903
- const o = {}, i = (c = e.preferences) == null ? void 0 : c.textVisualOptions;
3904
- if (!i) return o;
3905
- const a = Oe({
3906
- // Authoring: carried drill context never applies to a dashboard being edited.
3907
- transientContexts: void 0,
3908
- dashboard: n,
3909
- ...Oa(r, t),
3910
- card: t,
3911
- runtimeValues: {},
3912
- // Aliases only: no input value is read.
3913
- calendar: null
3914
- }), s = (f) => {
3915
- if (f.source !== "dashboardInputAlias") return f;
3916
- const m = a.variablesByName[f.variableName], y = m ? {
3917
- source: "input",
3918
- inputId: m.id,
3919
- export: f.export ?? "label"
3920
- } : f;
3921
- return m && (o[f.variableName] = y), y;
3922
- }, l = (f) => {
3923
- Object.assign(f, kt(f, (m) => s(m))), f.type === "link" && [...f.children, ...Array.isArray(f.url) ? f.url : []].forEach((m) => l(m)), f.type === "when" && [...f.then ?? [], ...f.else ?? []].forEach(l);
3924
- };
3925
- return (d = i.content) == null || d.forEach((f) => {
3926
- f.type === "variable" && (f.ref = s(f.ref));
3927
- }), (u = i.richContent) == null || u.blocks.forEach((f) => {
3928
- f.type === "list" ? f.items.forEach((m) => m.forEach(l)) : f.children.forEach(l);
3929
- }), o;
3930
- }
3931
- function Aa(e, t) {
3932
- var i;
3933
- const n = ct(e);
3934
- if (!n.some((a) => {
3935
- var s;
3936
- return (s = a.preferences) == null ? void 0 : s.textVisualOptions;
3937
- }))
3938
- return e;
3939
- const r = oe(e), o = ct(r);
3940
- for (let a = 0; a < o.length; a++) {
3941
- const s = _a(
3942
- o[a],
3943
- n[a],
3944
- t,
3945
- e
3946
- );
3947
- (i = e.frames) != null && i.some(
3948
- (l) => l.visualId && l.cards.some((c) => c.id === o[a].id)
3949
- ) && (o[a].linkedReferenceOverrides = Vo(
3950
- o[a].linkedReferenceOverrides,
3951
- { inputAliases: s }
3952
- ));
3953
- }
3954
- return r;
3955
- }
3956
- function Ea(e) {
3957
- var n;
3958
- const t = (n = e.sheets) == null ? void 0 : n.map(
3959
- (r) => Aa(r, e)
3960
- );
3961
- return t && t.some((r, o) => r !== e.sheets[o]) ? { ...e, sheets: t } : e;
3962
- }
3963
- function Ba(e) {
3964
- const t = A(e);
3965
- return t.issues.length === 0 && !t.needsUpgrade ? e : t.issues.length ? t.toStoredDashboard() : A(
3966
- Ea(e)
3967
- ).toStoredDashboard();
3968
- }
3969
- export {
3970
- Oa as $,
3971
- ua as A,
3972
- In as B,
3973
- Vo as C,
3974
- ts as D,
3975
- Eo as E,
3976
- vi as F,
3977
- nt as G,
3978
- Ko as H,
3979
- Lo as I,
3980
- No as J,
3981
- is as K,
3982
- Mo as L,
3983
- Kt as M,
3984
- Fe as N,
3985
- Uo as O,
3986
- z as P,
3987
- $o as Q,
3988
- Re as R,
3989
- Be as S,
3990
- fo as T,
3991
- as as U,
3992
- cs as V,
3993
- Go as W,
3994
- rs as X,
3995
- js as Y,
3996
- Sa as Z,
3997
- ct as _,
3998
- Ui as a,
3999
- _a as a0,
4000
- Aa as a1,
4001
- xs as a2,
4002
- Ms as a3,
4003
- Yt as a4,
4004
- ks as a5,
4005
- ei as a6,
4006
- pa as a7,
4007
- Ns as a8,
4008
- la as a9,
4009
- ce as aA,
4010
- Va as aB,
4011
- Es as aC,
4012
- os as aD,
4013
- ra as aE,
4014
- Si as aF,
4015
- pn as aG,
4016
- Ae as aH,
4017
- ls as aI,
4018
- ds as aJ,
4019
- fi as aK,
4020
- $ as aL,
4021
- Fs as aM,
4022
- ws as aN,
4023
- Ps as aO,
4024
- Bs as aa,
4025
- qs as ab,
4026
- mi as ac,
4027
- gi as ad,
4028
- Ta as ae,
4029
- us as af,
4030
- fs as ag,
4031
- bi as ah,
4032
- De as ai,
4033
- pi as aj,
4034
- Ii as ak,
4035
- ps as al,
4036
- Rs as am,
4037
- As as an,
4038
- gs as ao,
4039
- bs as ap,
4040
- ys as aq,
4041
- Is as ar,
4042
- Cs as as,
4043
- Bt as at,
4044
- ss as au,
4045
- _s as av,
4046
- hs as aw,
4047
- Oi as ax,
4048
- Os as ay,
4049
- fn as az,
4050
- ca as b,
4051
- di as c,
4052
- ms as d,
4053
- So as e,
4054
- Ss as f,
4055
- oe as g,
4056
- Vs as h,
4057
- zs as i,
4058
- Ts as j,
4059
- Pa as k,
4060
- Hi as l,
4061
- je as m,
4062
- Fi as n,
4063
- Di as o,
4064
- vs as p,
4065
- ko as q,
4066
- Ds as r,
4067
- wo as s,
4068
- qt as t,
4069
- ns as u,
4070
- _o as v,
4071
- Ba as w,
4072
- Tn as x,
4073
- wa as y,
4074
- Ls as z
4075
- };