react-semaphor 0.1.602 → 0.1.604

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