react-semaphor 0.1.590 → 0.1.592

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 (87) hide show
  1. package/dist/analytics-protocol/index.js +254 -236
  2. package/dist/assistant-context/index.js +1 -1
  3. package/dist/brand-studio/index.js +7 -7
  4. package/dist/briefings/index.js +4 -4
  5. package/dist/chunks/{aggregate-measure-field-BrkXsSJp.js → aggregate-measure-field-DHlDj0Pc.js} +2 -2
  6. package/dist/chunks/{assistant-chat-C_6dBLUk.js → assistant-chat-BusR-5uT.js} +13 -13
  7. package/dist/chunks/bookmark-impact-DozXJZDS.js +76 -0
  8. package/dist/chunks/{bookmark-state-Bn7k3ttp.js → bookmark-state-Be2W3s6t.js} +632 -592
  9. package/dist/chunks/{card-filter-builder-6vflbF9O.js → card-filter-builder-DBTJ74yy.js} +916 -897
  10. package/dist/chunks/{comparison-window-caption-fqijZdVd.js → comparison-window-caption-h8w3ySL6.js} +90 -91
  11. package/dist/chunks/{dashboard-DpgRl65K.js → dashboard-CmzJzmph.js} +1 -1
  12. package/dist/chunks/{dashboard-briefing-launcher-BLbhONJz.js → dashboard-briefing-launcher-BOQGpYr2.js} +160 -160
  13. package/dist/chunks/{dashboard-controls-kCTYEEsq.js → dashboard-controls-BxI3e2_o.js} +64 -64
  14. package/dist/chunks/{dashboard-json-CNIFresY.js → dashboard-json-BMqXV2Rx.js} +4 -4
  15. package/dist/chunks/{dates-BoeweqEo.js → dates-DBsscxL_.js} +8 -8
  16. package/dist/chunks/{edit-dashboard-visual-D0eWTlPL.js → edit-dashboard-visual-Dvc_Pkfg.js} +5443 -5417
  17. package/dist/chunks/filter-line-CYT7KIXb.js +133 -0
  18. package/dist/chunks/{filter-reach-copy-eMhDPTYH.js → filter-reach-copy-hEzlpBu7.js} +224 -224
  19. package/dist/chunks/filter-value-text-CHBm4IU7.js +153 -0
  20. package/dist/chunks/{index-D8LFjI8j.js → index-BoYJqc3F.js} +24 -24
  21. package/dist/chunks/{layout-grid-BG__sPkb.js → layout-grid-DoFIfQGd.js} +1 -1
  22. package/dist/chunks/{list-filter-Cb8i7N8f.js → list-filter-BeTQxjNy.js} +1 -1
  23. package/dist/chunks/{matrix-analytical-definition-D9Ll_9R-.js → matrix-analytical-definition-CyWOwLmE.js} +17 -17
  24. package/dist/chunks/{matrix-member-presentation-DVBJR0MA.js → matrix-member-presentation-Bj2YcHAP.js} +1 -1
  25. package/dist/chunks/{matrix-operation-contract-JSmproo9.js → matrix-operation-contract-CAanJeCj.js} +60 -60
  26. package/dist/chunks/{metric-comparison-xE_J6hkg.js → metric-comparison-BeKnUD08.js} +27 -31
  27. package/dist/chunks/{paintbrush-C310xSuR.js → paintbrush-KeaU1L1a.js} +1 -1
  28. package/dist/chunks/{palette-Ci5P91Zb.js → palette-BcFJLeXB.js} +1 -1
  29. package/dist/chunks/{pivot-result-contract-expectations-DbBahmgc.js → pivot-result-contract-expectations-CaS0y823.js} +522 -486
  30. package/dist/chunks/{pivot-result-identity-CUsMt_4r.js → pivot-result-identity-BKUjYO1u.js} +1 -1
  31. package/dist/chunks/raw-temporal-value-BzdgeDa7.js +454 -0
  32. package/dist/chunks/{report-preferences-dialog-dUlVLgEk.js → report-preferences-dialog-Cu_f-8Kw.js} +13 -13
  33. package/dist/chunks/{report-runtime-context-CrOgmuxO.js → report-runtime-context-g4Zp_TU9.js} +1 -1
  34. package/dist/chunks/{resolve-dashboard-input-context-NurwNg4I.js → resolve-dashboard-input-context-CkMk1RW6.js} +7600 -6398
  35. package/dist/chunks/{save-BhhXfp4s.js → save-C9CZAk6V.js} +1 -1
  36. package/dist/chunks/{saved-dashboard-context-CPp--vXU.js → saved-dashboard-context-RgBS_PIj.js} +19 -19
  37. package/dist/chunks/{selection-filter-compiler-CHG-8xnW.js → selection-filter-compiler-BclSpK3P.js} +1 -1
  38. package/dist/chunks/{semaphor-ready-indicator-CXojR95M.js → semaphor-ready-indicator-DXpTZJ7R.js} +31502 -31453
  39. package/dist/chunks/{shelf-drop-preview-context-BDScAUdq.js → shelf-drop-preview-context-qdlJKaH7.js} +5 -5
  40. package/dist/chunks/stored-dashboard-Baw6Bp2A.js +4029 -0
  41. package/dist/chunks/{style-sheet-parts-CmXmKqGw.js → style-sheet-parts-DM_Mw_sm.js} +45 -42
  42. package/dist/chunks/{table-export-sheet-ClSgERQC.js → table-export-sheet-Cd6z7SsG.js} +1 -1
  43. package/dist/chunks/{token-types-DTocOcwt.js → token-types-BB2ImFx6.js} +1 -1
  44. package/dist/chunks/{upload-DDYc1Qjj.js → upload-CMTCg47S.js} +1 -1
  45. package/dist/chunks/{validators-CrYXNnNE.js → validators-BlEWWX9O.js} +576 -562
  46. package/dist/chunks/{variable-draft-Bi3RlULA.js → variable-draft-BxtN6YcG.js} +4 -4
  47. package/dist/dashboard/index.js +2 -2
  48. package/dist/dashboard-authoring/index.js +1672 -1633
  49. package/dist/format-utils/index.js +217 -218
  50. package/dist/index.js +62 -62
  51. package/dist/report-runtime-context/index.js +1 -1
  52. package/dist/style.css +1 -1
  53. package/dist/surfboard/index.js +2 -2
  54. package/dist/types/components/surfboard/filter/types.d.ts +7 -5
  55. package/dist/types/components/visual/data-table/hooks/use-data-table-logic.d.ts +3 -3
  56. package/dist/types/components/visual/data-table/types/data-table.d.ts +24 -2
  57. package/dist/types/index.js +30 -29
  58. package/dist/types/lib/dashboard-inputs/dashboard-date-comparison-plan.d.ts +0 -1
  59. package/dist/types/lib/dashboard-viewer/table-view-edit.d.ts +27 -0
  60. package/dist/types/lib/dashboard-viewer/table-view.d.ts +37 -1
  61. package/dist/types/lib/formatters/raw-temporal-presentation.d.ts +0 -2
  62. package/dist/types/shared/analytics-protocol/agent-time-window.d.ts +1 -1
  63. package/dist/types/shared/analytics-protocol/relative-date/index.d.ts +2 -1
  64. package/dist/types/shared/analytics-protocol/relative-date/sentence.d.ts +81 -0
  65. package/dist/types/shared/analytics-protocol/relative-date/traits.d.ts +0 -9
  66. package/dist/types/shared/analytics-protocol/relative-date/window.d.ts +23 -2
  67. package/dist/types/shared/dashboard-authoring/canonical-result-keys.d.ts +20 -0
  68. package/dist/types/shared/dashboard-authoring/card-formats/detail-date-display.d.ts +84 -0
  69. package/dist/types/shared/dashboard-authoring/card-settings/card-kinds.d.ts +1 -1
  70. package/dist/types/shared/dashboard-authoring/card-settings/column-names.d.ts +2 -0
  71. package/dist/types/shared/dashboard-authoring/card-settings/inputs.d.ts +6 -0
  72. package/dist/types/shared/dashboard-authoring/card-settings/resolved.d.ts +11 -0
  73. package/dist/types/shared/dashboard-authoring/changes/dashboard-change.d.ts +36 -36
  74. package/dist/types/shared/dashboard-authoring/filter-model/date-filter-default.d.ts +37 -0
  75. package/dist/types/shared/dashboard-authoring/filter-model/index.d.ts +1 -0
  76. package/dist/types/shared/dashboard-authoring/index.d.ts +1 -0
  77. package/dist/types/shared/dashboard-viewer/table-column-move.d.ts +56 -0
  78. package/dist/types/shared/dashboard-viewer/table-settings.d.ts +7 -0
  79. package/dist/types/shared/format-utils/filter-line.d.ts +2 -0
  80. package/package.json +1 -1
  81. package/dist/chunks/bookmark-impact-DkZABEd3.js +0 -75
  82. package/dist/chunks/filter-line-Dza3ee4w.js +0 -131
  83. package/dist/chunks/filter-value-text-DQw4v3nC.js +0 -146
  84. package/dist/chunks/pivot-header-presentation-D-DfPAjb.js +0 -42
  85. package/dist/chunks/raw-temporal-value-BnGCWJAL.js +0 -322
  86. package/dist/chunks/stored-dashboard-KkH4zOhq.js +0 -4998
  87. package/dist/types/components/visual/shared/utils/table-column-order.d.ts +0 -53
@@ -1,4998 +0,0 @@
1
- import { hB as fo, cP as mo, cf as po, aV as go, bh as yo, f as bo, c7 as ho, N as ie, hC as Co, hD as ze, ex as Nt, eA as Io, bQ as vo, hE as Fo, aw as Do, gF as Lt, gH as So, bB as Ge, hF as jt, P as To, gJ as Mo, dj as Te, s as R, gA as Me, n as He, hG as Vo, gN as ko, db as zt, dd as Gt, cY as Po, di as xo, dg as ht, dh as wo, b as Oo, c_ as Bo, da as Ao, d8 as Eo, bE as Ht, bc as _o, a4 as N, hd as Ro, hH as Ve, hI as Ut, hJ as Ko, hK as Ue, hs as ke, hL as qo, hM as $e, hN as No, hO as Lo, hP as jo, hQ as zo, hR as Go, l as Qe, hS as Ho, k as ne, r as Uo, h as $o, hT as W, gr as Je, hU as ye, hV as $t, hW as Qo, J as Jo, hX as Wo, hY as Yo, gk as Qt, hZ as Zo, h_ as Xo, e as er, h$ as tr, i0 as Jt, i1 as nr, a0 as Wt, i2 as or, i3 as rr, i4 as Yt, j as We, i5 as ir, cG as sr, a5 as ar, o as Zt, cF as lr, hp as cr, q as dr, t as Ct, C as ur, i6 as fr, i7 as mr, cH as pr, i8 as gr } from "./resolve-dashboard-input-context-NurwNg4I.js";
2
- import { ak as yr, a5 as se, J as br, v as hr, aw as _e, w as Cr, a7 as be, ay as Xt, U as Ir, b as vr, r as Fr } from "./validators-CrYXNnNE.js";
3
- import { r as en } from "./matrix-operation-contract-JSmproo9.js";
4
- import { S as Ye } from "./analytics-base-schemas-8wz9vqn_.js";
5
- import "./pickers-DkqmtnTL.js";
6
- import { canonicalizeSupportedCurrencyCode as tn } from "../value-format-preferences/index.js";
7
- import { ZodError as Dr } from "zod";
8
- import { c as he, r as Sr, b4 as Tr, i as Mr, aN as Vr, aj as It, aL as vt } from "./pivot-result-contract-expectations-DbBahmgc.js";
9
- import { aB as nn, aC as on, aD as Oe, a0 as kr, aE as rn, aF as sn, aA as an, aG as ln, n as Pr, l as xr, v as cn, t as U, aH as dn, k as un, C as Re, aI as Q, z as ae, i as fn, o as wr, u as Or, B as Ze, aJ as Br, ai as Ar, F as mn, D as Er, J as Ft, O as pn, P as gn, I as yn } from "./bookmark-state-Bn7k3ttp.js";
10
- import "./schema-C9NPiIru.js";
11
- import "./index-CV_Kzou0.js";
12
- import "./context-CVXTFljo.js";
13
- import { a as _r, k as Rr, s as Kr, i as qr } from "./matrix-analytical-definition-D9Ll_9R-.js";
14
- import { D as Nr } from "./report-runtime-context-CrOgmuxO.js";
15
- import { isPdfTableCardType as Lr, PDF_CAPACITY as jr } from "../pdf-export-policy/index.js";
16
- import { o as Dt } from "./raw-temporal-value-BnGCWJAL.js";
17
- import { t as zr, n as Gr, c as Hr } from "./selection-filter-compiler-CHG-8xnW.js";
18
- import { a as le, C as Ur } from "./metric-comparison-xE_J6hkg.js";
19
- import { r as $r } from "./pivot-result-identity-CUsMt_4r.js";
20
- import { p as Qr } from "./pivot-header-presentation-D-DfPAjb.js";
21
- const Jr = (e, t) => {
22
- const n = {};
23
- if (e === null || t === null)
24
- return t;
25
- const o = /* @__PURE__ */ new Set([...Object.keys(e), ...Object.keys(t)]);
26
- for (const r of o) {
27
- if (!(r in e) && r in t) {
28
- n[r] = t[r];
29
- continue;
30
- }
31
- if (r in e && !(r in t)) {
32
- n[r] = void 0;
33
- continue;
34
- }
35
- const i = e[r], s = t[r];
36
- if (!Ke(i, s))
37
- if (Array.isArray(i) && Array.isArray(s))
38
- n[r] = s;
39
- else if (St(i) && St(s)) {
40
- const a = Jr(i, s);
41
- Object.keys(a).length > 0 && (n[r] = a);
42
- } else
43
- n[r] = s;
44
- }
45
- return n;
46
- }, Ke = (e, t) => {
47
- if (e === t) return !0;
48
- if (e && t && typeof e == "object" && typeof t == "object") {
49
- if (Array.isArray(e) && Array.isArray(t))
50
- return e.length !== t.length ? !1 : e.every((r, i) => Ke(r, t[i]));
51
- const n = Object.keys(e), o = Object.keys(t);
52
- return n.length !== o.length ? !1 : n.every((r) => Ke(e[r], t[r]));
53
- }
54
- return !1;
55
- }, St = (e) => e !== null && typeof e == "object" && !Array.isArray(e), Ce = (e) => {
56
- if (e === null || typeof e != "object")
57
- return e;
58
- if (e instanceof Date)
59
- return new Date(e);
60
- if (e instanceof RegExp)
61
- return new RegExp(e);
62
- if (Array.isArray(e))
63
- return e.map((n) => Ce(n));
64
- const t = {};
65
- for (const n in e)
66
- Object.prototype.hasOwnProperty.call(e, n) && (t[n] = Ce(e[n]));
67
- return t;
68
- }, Wr = /^(?:[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;
69
- function Yr(e) {
70
- return typeof e == "string" && Wr.test(e);
71
- }
72
- function Zr(e) {
73
- if (!Yr(e))
74
- throw TypeError("Invalid UUID");
75
- let t;
76
- const n = new Uint8Array(16);
77
- 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;
78
- }
79
- function Xr(e) {
80
- e = unescape(encodeURIComponent(e));
81
- const t = [];
82
- for (let n = 0; n < e.length; ++n)
83
- t.push(e.charCodeAt(n));
84
- return t;
85
- }
86
- const ei = "6ba7b810-9dad-11d1-80b4-00c04fd430c8", ti = "6ba7b811-9dad-11d1-80b4-00c04fd430c8";
87
- function ni(e, t, n) {
88
- function o(r, i, s, a) {
89
- var c;
90
- if (typeof r == "string" && (r = Xr(r)), typeof i == "string" && (i = Zr(i)), ((c = i) === null || c === void 0 ? void 0 : c.length) !== 16)
91
- throw TypeError("Namespace must be array-like (16 iterable integer values, 0-255)");
92
- let l = new Uint8Array(16 + r.length);
93
- if (l.set(i), l.set(r, i.length), l = n(l), l[6] = l[6] & 15 | t, l[8] = l[8] & 63 | 128, s) {
94
- a = a || 0;
95
- for (let d = 0; d < 16; ++d)
96
- s[a + d] = l[d];
97
- return s;
98
- }
99
- return fo(l);
100
- }
101
- try {
102
- o.name = e;
103
- } catch {
104
- }
105
- return o.DNS = ei, o.URL = ti, o;
106
- }
107
- function oi(e, t, n, o) {
108
- switch (e) {
109
- case 0:
110
- return t & n ^ ~t & o;
111
- case 1:
112
- return t ^ n ^ o;
113
- case 2:
114
- return t & n ^ t & o ^ n & o;
115
- case 3:
116
- return t ^ n ^ o;
117
- }
118
- }
119
- function Be(e, t) {
120
- return e << t | e >>> 32 - t;
121
- }
122
- function ri(e) {
123
- const t = [1518500249, 1859775393, 2400959708, 3395469782], n = [1732584193, 4023233417, 2562383102, 271733878, 3285377520];
124
- if (typeof e == "string") {
125
- const s = unescape(encodeURIComponent(e));
126
- e = [];
127
- for (let a = 0; a < s.length; ++a)
128
- e.push(s.charCodeAt(a));
129
- } else Array.isArray(e) || (e = Array.prototype.slice.call(e));
130
- e.push(128);
131
- const o = e.length / 4 + 2, r = Math.ceil(o / 16), i = new Array(r);
132
- for (let s = 0; s < r; ++s) {
133
- const a = new Uint32Array(16);
134
- for (let c = 0; c < 16; ++c)
135
- a[c] = e[s * 64 + c * 4] << 24 | e[s * 64 + c * 4 + 1] << 16 | e[s * 64 + c * 4 + 2] << 8 | e[s * 64 + c * 4 + 3];
136
- i[s] = a;
137
- }
138
- i[r - 1][14] = (e.length - 1) * 8 / Math.pow(2, 32), i[r - 1][14] = Math.floor(i[r - 1][14]), i[r - 1][15] = (e.length - 1) * 8 & 4294967295;
139
- for (let s = 0; s < r; ++s) {
140
- const a = new Uint32Array(80);
141
- for (let p = 0; p < 16; ++p)
142
- a[p] = i[s][p];
143
- for (let p = 16; p < 80; ++p)
144
- a[p] = Be(a[p - 3] ^ a[p - 8] ^ a[p - 14] ^ a[p - 16], 1);
145
- let c = n[0], l = n[1], d = n[2], u = n[3], f = n[4];
146
- for (let p = 0; p < 80; ++p) {
147
- const g = Math.floor(p / 20), m = Be(c, 5) + oi(g, l, d, u) + f + t[g] + a[p] >>> 0;
148
- f = u, u = d, d = Be(l, 30) >>> 0, l = c, c = m;
149
- }
150
- n[0] = n[0] + c >>> 0, n[1] = n[1] + l >>> 0, n[2] = n[2] + d >>> 0, n[3] = n[3] + u >>> 0, n[4] = n[4] + f >>> 0;
151
- }
152
- 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];
153
- }
154
- const ii = ni("v5", 80, ri), Tt = /\[\[\s*param\.([A-Za-z0-9_.-]+)\s*\]\]/g, Mt = /\bparam\s*\(\s*(['"])([^'"]+)\1/g;
155
- function si(e) {
156
- const t = [];
157
- let n = 0;
158
- for (; n < e.length; ) {
159
- const o = e.indexOf("{{", n), r = e.indexOf("{%", n);
160
- let i = -1, s = "";
161
- if (o === -1 ? (i = r, s = "%}") : r === -1 || o < r ? (i = o, s = "}}") : (i = r, s = "%}"), i === -1)
162
- break;
163
- const a = e.indexOf(s, i + 2);
164
- if (a === -1) {
165
- n = i + 2;
166
- continue;
167
- }
168
- t.push(e.slice(i + 2, a)), n = a + 2;
169
- }
170
- return t;
171
- }
172
- function bn(e) {
173
- var o, r;
174
- if (!e)
175
- return [];
176
- const t = /* @__PURE__ */ new Set();
177
- let n;
178
- for (Tt.lastIndex = 0; (n = Tt.exec(e)) !== null; ) {
179
- const i = (o = n[1]) == null ? void 0 : o.trim();
180
- i && t.add(i);
181
- }
182
- for (const i of si(e))
183
- for (Mt.lastIndex = 0; (n = Mt.exec(i)) !== null; ) {
184
- const s = (r = n[2]) == null ? void 0 : r.trim();
185
- s && t.add(s);
186
- }
187
- return Array.from(t);
188
- }
189
- function Xe(e) {
190
- const t = /* @__PURE__ */ new Set(), n = /* @__PURE__ */ new Map();
191
- for (const o of e.controlBindings || [])
192
- t.add(o.controlId), o.target === "sql_param" && n.set(o.paramId, o.controlId);
193
- for (const o of bn(e.sql))
194
- t.add(n.get(o) ?? o);
195
- return Array.from(t);
196
- }
197
- function ai(e) {
198
- const t = /* @__PURE__ */ new Map(), n = /* @__PURE__ */ new Map();
199
- for (const o of e.controlBindings || [])
200
- o.target === "sql_param" && n.set(o.paramId, o.controlId);
201
- for (const o of bn(e.sql))
202
- t.set(o, {
203
- paramId: o,
204
- controlId: n.get(o) ?? o
205
- });
206
- return Array.from(t.values());
207
- }
208
- function li(e, t) {
209
- var r;
210
- const n = (r = e.controlBindings) == null ? void 0 : r.map((i) => ({
211
- ...i,
212
- controlId: t.get(i.controlId) ?? i.controlId
213
- })), o = ai(e).flatMap(
214
- ({ paramId: i, controlId: s }) => {
215
- var c;
216
- const a = t.get(s);
217
- return !a || a === s || (c = e.controlBindings) != null && c.some(
218
- (l) => l.target === "sql_param" && l.paramId === i
219
- ) ? [] : [{ target: "sql_param", paramId: i, controlId: a }];
220
- }
221
- );
222
- return o.length ? [...n ?? [], ...o] : n;
223
- }
224
- function hn(e, t) {
225
- var s, a;
226
- const n = Oe(e) ?? e, o = n.source === "dashboardInputAlias" ? (s = t.inputAliases) == null ? void 0 : s[n.variableName] : void 0, r = n.source === "dashboardInputAlias" && o ? Oe(o) ?? Oe({ ...o, export: n.export ?? "label" }) ?? n : n, i = n.source === "dashboardInputAlias" && r !== n ? { ...r, export: n.export ?? "label" } : r;
227
- return i.source === "input" ? {
228
- ...i,
229
- inputId: ((a = t.inputIds) == null ? void 0 : a[i.inputId]) ?? i.inputId
230
- } : i;
231
- }
232
- function ci(e, t) {
233
- var r;
234
- const n = {};
235
- for (const i of [
236
- "cardIds",
237
- "sheetIds",
238
- "inputIds",
239
- "controlIds",
240
- "filterIds"
241
- ]) {
242
- const s = { ...t[i] };
243
- for (const [a, c] of Object.entries((e == null ? void 0 : e[i]) ?? {}))
244
- s[a] = ((r = t[i]) == null ? void 0 : r[c]) ?? c;
245
- Object.keys(s).length && (n[i] = s);
246
- }
247
- const o = { ...t.inputAliases };
248
- for (const [i, s] of Object.entries((e == null ? void 0 : e.inputAliases) ?? {}))
249
- o[i] = hn(s, t);
250
- return Object.keys(o).length && (n.inputAliases = o), n;
251
- }
252
- function dl(e, t) {
253
- var r, i, s, a;
254
- const n = Ce(nn(e));
255
- n.controlBindings = li(
256
- e,
257
- new Map(Object.entries(t.controlIds ?? {}))
258
- );
259
- for (const c of n.controls ?? [])
260
- c.id = ((r = t.controlIds) == null ? void 0 : r[c.id]) ?? c.id;
261
- for (const c of n.inlineFilters ?? [])
262
- c.id = ((i = t.filterIds) == null ? void 0 : i[c.id]) ?? c.id;
263
- const o = (c) => {
264
- var d, u;
265
- if (!c || typeof c != "object") return;
266
- if (Array.isArray(c)) {
267
- c.forEach(o);
268
- return;
269
- }
270
- const l = c;
271
- if (Object.assign(
272
- l,
273
- on(
274
- l,
275
- (f) => f && typeof f == "object" ? hn(f, t) : f
276
- )
277
- ), typeof l.entityId == "string") {
278
- const f = l.entityId;
279
- l.fieldScope === "card" && (l.entityId = ((d = t.cardIds) == null ? void 0 : d[f]) ?? f), l.fieldScope === "sheet" && (l.entityId = ((u = t.sheetIds) == null ? void 0 : u[f]) ?? f);
280
- }
281
- for (const [f, p] of Object.entries(l))
282
- f !== "linkedReferenceOverrides" && o(p);
283
- };
284
- o(n), n.clickToFilter && (n.clickToFilter = mo(n.clickToFilter, t));
285
- for (const c of Object.values(
286
- ((s = n.customCardPreferences) == null ? void 0 : s.dataInputCardIds) ?? {}
287
- ))
288
- c.cardId = ((a = t.cardIds) == null ? void 0 : a[c.cardId]) ?? c.cardId;
289
- return n;
290
- }
291
- const di = "9677efdd-86ec-4afb-b9bb-5ead8b5442af";
292
- function ui(e) {
293
- let t = 0;
294
- return () => ii(`${e}#${t++}`, di);
295
- }
296
- const fi = [
297
- { code: "matrix_definition_incomplete", label: "Matrix definition" }
298
- ], mi = [
299
- { code: "connection_type_unresolved", label: "Connection type" }
300
- ], ee = (e) => !Array.isArray(e) || e.length === 0;
301
- function pi(e) {
302
- var i;
303
- const t = e.config ?? {};
304
- if ((i = e.sql) != null && i.trim() || !ee(t.pivotByColumns)) return "matrixTable";
305
- const n = !ee(t.groupByColumns), o = !ee(t.metricColumns), r = e.type === "pivotTable" && (n || o) && ee(t.rowAggregates) && ee(t.columnAggregates);
306
- return n && !o || r ? "table" : "matrixTable";
307
- }
308
- function gi(e) {
309
- var r;
310
- const t = e.dataSource;
311
- if (!t || (r = t.connectionType) != null && r.trim()) return e;
312
- const n = yr(ho(t.selectedEntities));
313
- if (!n) return e;
314
- const o = 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;
315
- return { ...e, dataSource: { ...t, connectionType: n, selectedEntities: o } };
316
- }
317
- function Cn(e) {
318
- var s, a;
319
- const t = e;
320
- if (!po(t)) return { status: "not_legacy", card: e };
321
- const n = gi(t), o = pi(t) === "table" ? go(n, "table") : yo(n, "matrixTable", { createId: ui(t.id) });
322
- if (o.status !== "changed") throw new Error(`Card ${t.id} could not leave ${t.type}.`);
323
- const r = o.card.type === "matrixTable" && bo(o.card).status !== "ready", i = !!n.dataSource && !((a = (s = n.dataSource) == null ? void 0 : s.connectionType) != null && a.trim());
324
- return {
325
- status: "routed",
326
- card: o.card,
327
- gaps: [
328
- ...o.gaps,
329
- ...r ? fi : [],
330
- ...i ? mi : []
331
- ]
332
- };
333
- }
334
- function ul(e) {
335
- if (!e.cards) return e;
336
- const t = e.cards.map((n) => Cn(n).card);
337
- return t.every((n, o) => n === e.cards[o]) ? e : { ...e, cards: t };
338
- }
339
- function yi(e) {
340
- const t = [];
341
- return { dashboard: kr(e, (o, r) => {
342
- const i = Cn(o);
343
- return i.status === "routed" && i.gaps.length && t.push({ location: r, gaps: i.gaps }), i.card;
344
- }), routedWithGaps: t };
345
- }
346
- function bi(e, t) {
347
- return e.name === t.name && e.qualifiedEntityName === t.qualifiedEntityName;
348
- }
349
- function hi(e, t, n) {
350
- var r, i;
351
- if (n.sortPolicy === "dropUnrelatedSorts") {
352
- const s = new Set(
353
- (e.metricColumns || []).map((a) => a.id)
354
- );
355
- return {
356
- ...e,
357
- groupByColumns: [t],
358
- sortByColumns: (e.sortByColumns || []).filter(
359
- (a) => a.id === t.id || s.has(a.id)
360
- )
361
- };
362
- }
363
- const o = (r = e.groupByColumns) == null ? void 0 : r[0];
364
- return {
365
- ...e,
366
- groupByColumns: [t],
367
- sortByColumns: (i = e.sortByColumns) == null ? void 0 : i.map(
368
- (s) => o && bi(s, o) ? {
369
- ...t,
370
- role: "sortby",
371
- direction: s.direction
372
- } : s
373
- )
374
- };
375
- }
376
- function fl(e) {
377
- switch (e) {
378
- case "previous_period":
379
- return "Previous";
380
- case "previous_year":
381
- return "Last Year";
382
- case "target":
383
- return "Target";
384
- default:
385
- return "Comparison";
386
- }
387
- }
388
- function In(e, t, n) {
389
- var o;
390
- if (((o = n == null ? void 0 : n.output) == null ? void 0 : o.availability.status) === "available" && n.output.comparisonColumnKey)
391
- return n.output.comparisonColumnKey;
392
- }
393
- function Ci(e, t) {
394
- return `${e} Δ`;
395
- }
396
- function ml(e, t) {
397
- return rn(e, t);
398
- }
399
- function Ii(e, t) {
400
- return e.rawKey === t.rawKey && e.outputKey === t.outputKey;
401
- }
402
- function vn(e) {
403
- var a;
404
- const { card: t, columnKeyMap: n, metricAlias: o, metricId: r } = e;
405
- if (!(t != null && t.config) || !n || !o || ie(t) !== "config")
406
- return;
407
- const i = (a = n.byMetricAlias) == null ? void 0 : a[o];
408
- if (!i) return;
409
- const s = (t.config.metricColumns || []).filter((c) => {
410
- var d;
411
- if (r && c.id !== r) return !1;
412
- const l = (d = n.byMetricAlias) == null ? void 0 : d[le(c)];
413
- return !!(l && Ii(i, l));
414
- });
415
- return s.length === 1 ? s[0] : void 0;
416
- }
417
- function pl(e, t) {
418
- return t ? { ...e, config: t } : e;
419
- }
420
- function vi(e) {
421
- return [
422
- e.alias,
423
- e.name,
424
- e.qualifiedFieldName,
425
- e.id
426
- ].filter((t) => !!t);
427
- }
428
- function Y(e) {
429
- return e != null && e.config ? ie(e) === "config" : !1;
430
- }
431
- function Fi(e, t, n, o) {
432
- if (t === -1 || n === -1 || t === n)
433
- return null;
434
- const r = [...e], [i] = r.splice(t, 1), s = o === "before" ? n > t ? n - 1 : n : n > t ? n : n + 1;
435
- return r.splice(s, 0, i), r;
436
- }
437
- function Ae(e, t, n) {
438
- if (!(e != null && e.length)) return null;
439
- const o = e.findIndex(
440
- (i) => n(i).includes(t.draggingColumnId)
441
- ), r = e.findIndex(
442
- (i) => n(i).includes(t.targetColumnId)
443
- );
444
- return Fi(e, o, r, t.side);
445
- }
446
- function Ee(e, t, n) {
447
- return n ? {
448
- ...e ?? {},
449
- [t]: n
450
- } : null;
451
- }
452
- function gl(e, t, n) {
453
- if (!Y(e) || !n) return null;
454
- const o = e.config;
455
- return e.type === "detailTable" ? Ee(
456
- o,
457
- "detailColumns",
458
- Ae(
459
- o == null ? void 0 : o.detailColumns,
460
- t,
461
- (r) => ge(r, "detail", n)
462
- )
463
- ) : Ee(
464
- o,
465
- "groupByColumns",
466
- Ae(
467
- o == null ? void 0 : o.groupByColumns,
468
- t,
469
- (r) => ge(r, "groupby", n)
470
- )
471
- ) ?? Ee(
472
- o,
473
- "metricColumns",
474
- Ae(
475
- o == null ? void 0 : o.metricColumns,
476
- t,
477
- (r) => ge(r, "metric", n)
478
- )
479
- );
480
- }
481
- function Di(e) {
482
- var t, n, o, r, i, s;
483
- return Y(e) ? e.type === "detailTable" ? !!((n = (t = e.config) == null ? void 0 : t.detailColumns) != null && n.length) : !!((r = (o = e.config) == null ? void 0 : o.groupByColumns) != null && r.length || (s = (i = e.config) == null ? void 0 : i.metricColumns) != null && s.length) : !1;
484
- }
485
- function yl(e, t) {
486
- return Di(e) && !!t;
487
- }
488
- function ge(e, t, n) {
489
- if (!n) return [];
490
- const o = t === "metric" ? [
491
- le(e),
492
- e.alias
493
- ].filter((i) => !!i).flatMap((i) => {
494
- var a;
495
- const s = (a = n.byMetricAlias) == null ? void 0 : a[i];
496
- return s ? [s] : [];
497
- }) : [], r = $r(
498
- n,
499
- e.id,
500
- t
501
- );
502
- return [...o, r].flatMap((i) => [i == null ? void 0 : i.outputKey, i == null ? void 0 : i.rawKey]).filter((i) => !!i);
503
- }
504
- function ce(e, t, n, o) {
505
- const r = ge(
506
- e,
507
- t,
508
- o
509
- );
510
- return o ? r.find(
511
- (i) => n.includes(i)
512
- ) : vi(e).find(
513
- (i) => n.includes(i)
514
- );
515
- }
516
- function Fn(e, t, n) {
517
- if (!Y(t) || !n)
518
- return;
519
- const o = t.type === "detailTable" ? [{ role: "detail", fields: t.config.detailColumns }] : [
520
- { role: "groupby", fields: t.config.groupByColumns },
521
- { role: "metric", fields: t.config.metricColumns }
522
- ];
523
- for (const { role: r, fields: i } of o)
524
- for (const s of i || [])
525
- if (ce(
526
- s,
527
- r,
528
- [e],
529
- n
530
- ) === e && typeof s.label == "string" && s.label.length > 0)
531
- return s.label;
532
- }
533
- function Si(e, t) {
534
- if (!e) return;
535
- const n = JSON.stringify(t), o = t.every((r) => r !== null) ? t.join("__") : void 0;
536
- return e[n] || (o ? e[o] : void 0);
537
- }
538
- function Ti(e, t, n) {
539
- if (!e) return;
540
- let o = e, r = !1;
541
- return t.forEach((i, s) => {
542
- const a = n[s] ?? "";
543
- [
544
- i.entityName ? `{{${i.entityName}.${i.name}}}` : void 0,
545
- `{{${i.name}}}`
546
- ].filter((l) => !!l).forEach((l) => {
547
- o.includes(l) && (o = o.split(l).join(a), r = !0);
548
- });
549
- }), r && o.trim() ? o : void 0;
550
- }
551
- function Mi(e) {
552
- const t = (e.card.config.metricColumns || []).filter(
553
- (n) => n.id === e.metricId && le(n) === e.metricAlias
554
- );
555
- return t.length === 1 ? t[0] : vn({
556
- card: e.card,
557
- columnKeyMap: e.columnKeyMap,
558
- metricAlias: e.metricAlias,
559
- metricId: e.metricId
560
- });
561
- }
562
- function et(e) {
563
- var s;
564
- const t = (s = e.resultColumn) == null ? void 0 : s.pivotIdentity, n = e.card.config.pivotByColumns || [];
565
- if (!t || n.length === 0 || t.members.length !== n.length || t.members.some(
566
- (a, c) => {
567
- var l;
568
- return a.fieldId !== ((l = n[c]) == null ? void 0 : l.id);
569
- }
570
- ))
571
- return;
572
- const o = e.card.config.metricColumns || [], r = Mi({
573
- card: e.card,
574
- columnKeyMap: e.columnKeyMap,
575
- metricId: t.metricId,
576
- metricAlias: t.metricAlias
577
- }), i = o.length === 0 && t.metricId === Ye;
578
- if (!(!r && !i))
579
- return {
580
- resultColumn: e.resultColumn,
581
- identity: t,
582
- pivotFields: n,
583
- authoredMetrics: o,
584
- authoredMetric: r
585
- };
586
- }
587
- function Vi(e) {
588
- const {
589
- columnId: t,
590
- card: n,
591
- columnKeyMap: o,
592
- resultColumns: r,
593
- temporalPresentation: i,
594
- metricLabelOverride: s
595
- } = e;
596
- if (!Y(n) || n.type !== "table")
597
- return;
598
- const a = et({
599
- resultColumn: r == null ? void 0 : r.find((I) => I.key === t),
600
- card: n,
601
- columnKeyMap: o
602
- });
603
- if (!a) return;
604
- const { identity: c, pivotFields: l, authoredMetrics: d, authoredMetric: u } = a, p = Qr({
605
- members: c.members,
606
- resolveTemporalFormat: (I) => {
607
- var v;
608
- return (v = Co({
609
- presentation: i,
610
- fieldId: I,
611
- role: "pivotby"
612
- })) == null ? void 0 : v.resolved.format;
613
- }
614
- }).memberLabels.map(
615
- (I) => I || "(Blank)"
616
- ), g = c.members.map((I) => I.value), m = Si(u == null ? void 0 : u.valueAliases, g) || Ti(
617
- u == null ? void 0 : u.aliasTemplate,
618
- l,
619
- p
620
- ), y = m ? [m] : p, b = s || (d.length > 1 ? (u == null ? void 0 : u.label) || (u == null ? void 0 : u.name) : void 0);
621
- return [...y, ...b ? [b] : []].join(" / ");
622
- }
623
- function H(e, t, n, o) {
624
- return e != null && e.length ? e.map(
625
- (r) => ce(
626
- r,
627
- n,
628
- t,
629
- o
630
- )
631
- ).filter((r) => !!r) : [];
632
- }
633
- function Vt(e, t, n, o) {
634
- if (!Y(t) || !o) return e;
635
- const r = [], i = (s) => {
636
- s && e.includes(s) && !r.includes(s) && r.push(s);
637
- };
638
- return t.type === "detailTable" ? H(
639
- t.config.detailColumns,
640
- e,
641
- "detail",
642
- o
643
- ).forEach(i) : (H(
644
- t.config.groupByColumns,
645
- e,
646
- "groupby",
647
- o
648
- ).forEach(i), H(
649
- t.config.metricColumns,
650
- e,
651
- "metric",
652
- o
653
- ).forEach((s) => {
654
- i(s), i(n == null ? void 0 : n(s));
655
- })), e.forEach(i), r;
656
- }
657
- function ki(e, t) {
658
- var f, p, g;
659
- const { keys: n, card: o, columnKeyMap: r, resultColumns: i } = e;
660
- if (!((f = o.config.pivotByColumns) != null && f.length)) return null;
661
- if (!r || !(i != null && i.length)) return [...n];
662
- const s = n.every(
663
- (m) => i.some((y) => y.key === m)
664
- ), a = [
665
- ...H(
666
- o.config.groupByColumns,
667
- n,
668
- "groupby",
669
- r
670
- ),
671
- ...H(
672
- o.config.metricColumns,
673
- n,
674
- "metric",
675
- r
676
- )
677
- ].length === (((p = o.config.groupByColumns) == null ? void 0 : p.length) || 0) + (((g = o.config.metricColumns) == null ? void 0 : g.length) || 0);
678
- if (!s || !a)
679
- return [...n];
680
- const c = i.filter(
681
- (m) => m.pivotIdentity && n.includes(m.key)
682
- );
683
- if (c.some(
684
- (m) => !et({
685
- resultColumn: m,
686
- card: o,
687
- columnKeyMap: r
688
- })
689
- ))
690
- return [...n];
691
- const l = c.map((m) => m.key);
692
- if (l.length === 0) return [...n];
693
- const d = [], u = (m) => {
694
- m && n.includes(m) && !d.includes(m) && d.push(m);
695
- };
696
- return H(
697
- o.config.groupByColumns,
698
- n,
699
- "groupby",
700
- r
701
- ).forEach(u), l.forEach(u), H(
702
- o.config.metricColumns,
703
- n,
704
- "metric",
705
- r
706
- ).forEach((m) => {
707
- u(m), u(t(m));
708
- }), n.forEach(u), d;
709
- }
710
- function Pi(e) {
711
- var c;
712
- const { keys: t, card: n, comparisonMetadata: o, columnKeyMap: r, resultColumns: i } = e;
713
- if ((n == null ? void 0 : n.type) !== "table")
714
- return Vt(
715
- t,
716
- n,
717
- void 0,
718
- r
719
- );
720
- const s = /* @__PURE__ */ new Map();
721
- (((c = n.config) == null ? void 0 : c.metricColumns) || []).forEach((l) => {
722
- const { comparisonKind: d, metadata: u } = sn(o, l);
723
- if (d === "none") return;
724
- const f = l.label || l.name, p = ce(
725
- l,
726
- "metric",
727
- t,
728
- r
729
- );
730
- if (!p) return;
731
- const g = In(
732
- f,
733
- d,
734
- u
735
- );
736
- g && s.set(p, g);
737
- });
738
- const a = (l) => s.get(l) ?? null;
739
- if (Y(n)) {
740
- const l = ki(
741
- { keys: t, card: n, columnKeyMap: r, resultColumns: i },
742
- a
743
- );
744
- if (l) return l;
745
- }
746
- return Vt(
747
- t,
748
- n,
749
- a,
750
- r
751
- );
752
- }
753
- function Ie(e) {
754
- return e == null ? void 0 : e.map(
755
- ({
756
- format: t,
757
- formatOrigin: n,
758
- semanticTemporalPresentation: o,
759
- ...r
760
- }) => r
761
- );
762
- }
763
- function ve(e) {
764
- if (!e)
765
- return;
766
- const {
767
- format: t,
768
- formatOrigin: n,
769
- semanticTemporalPresentation: o,
770
- ...r
771
- } = e;
772
- return oe(r);
773
- }
774
- function Dn(e, t) {
775
- return e == null ? void 0 : e.map(
776
- (n) => Nt(oe(Ie([n])[0]), n.format, t)
777
- );
778
- }
779
- function xi(e, t) {
780
- return e == null ? void 0 : e.map(
781
- (n) => Io(oe(Ie([n])[0]), n.format, t)
782
- );
783
- }
784
- function wi(e, t) {
785
- const { dateFormat: n, customFormat: o, ...r } = ve(e.field);
786
- return {
787
- ...e,
788
- field: t ? r : Nt(ve(e.field), e.field.format, "raw")
789
- };
790
- }
791
- function Pe(e, t = !1) {
792
- if (e)
793
- return {
794
- ...e,
795
- conditions: e.conditions.map((n) => wi(n, t)),
796
- groups: e.groups.map((n) => Pe(n, t))
797
- };
798
- }
799
- function oe(e) {
800
- var n, o;
801
- const t = { ...e };
802
- return (n = t.calculatedFormula) != null && n.inputFields && (t.calculatedFormula = {
803
- ...t.calculatedFormula,
804
- inputFields: t.calculatedFormula.inputFields.map(
805
- (r) => ve(r)
806
- )
807
- }), (o = t.parameters) != null && o.filters && (t.parameters = {
808
- ...t.parameters,
809
- filters: Pe(t.parameters.filters)
810
- }), t;
811
- }
812
- function Oi(e, t) {
813
- return t.cardType === "detailTable" || !vo(t.cardType) || t.temporalResultOwner !== "config" ? Dn(e, "grouped") : e == null ? void 0 : e.map((n) => {
814
- const o = Fo(n), r = ve(o ?? n);
815
- if (!o)
816
- return r;
817
- const { dateFormat: i, customFormat: s, ...a } = r;
818
- return a;
819
- });
820
- }
821
- function Sn(e, t) {
822
- if (!e)
823
- return;
824
- const n = { type: t.cardType, config: e };
825
- return ze(n) ? Bi(n, t) : e.matrix === void 0 ? {} : { matrix: e.matrix };
826
- }
827
- function Bi(e, t = {}) {
828
- var i, s, a;
829
- const n = e.config;
830
- if (!n) return;
831
- const o = { ...t, cardType: e.type };
832
- return {
833
- ...n,
834
- groupByColumns: Oi(n.groupByColumns, o),
835
- metricColumns: (i = Ie(n.metricColumns)) == null ? void 0 : i.map(
836
- oe
837
- ),
838
- pivotByColumns: Dn(n.pivotByColumns, "grouped"),
839
- sortByColumns: (s = Ie(n.sortByColumns)) == null ? void 0 : s.map(
840
- oe
841
- ),
842
- detailColumns: xi(n.detailColumns, (a = o.dataSource) == null ? void 0 : a.connectionType),
843
- filters: Pe(n.filters)
844
- };
845
- }
846
- function Fe(e) {
847
- return (e == null ? void 0 : e.type) === "number" || (e == null ? void 0 : e.type) === "currency";
848
- }
849
- function Ai(e) {
850
- return (e == null ? void 0 : e.type) === "number";
851
- }
852
- function Ei(e) {
853
- var n;
854
- if (!Ai(e))
855
- return !1;
856
- const t = (n = e == null ? void 0 : e.numberFormat) == null ? void 0 : n.style;
857
- return t === void 0 || t === "decimal" || t === "currency";
858
- }
859
- function _i(e, t) {
860
- const n = t == null ? void 0 : t.type;
861
- if (n && n !== "none" && n !== "number")
862
- return { currencyBindable: !1 };
863
- const o = n === "number" ? t != null && t.numberFormat ? So(t.numberFormat, {
864
- preserveOmittedProperties: !0
865
- }) : { type: "number" } : void 0, r = he(e.format, {
866
- preserveOmittedProperties: !0
867
- }), i = se(e.dataType) === "number" ? { type: "number" } : void 0, a = (t == null ? void 0 : t.inheritMetricFormat) === !1 || !!(t != null && t.numberFormat) && (t == null ? void 0 : t.inheritMetricFormat) !== !0 ? o : r || i || o;
868
- return {
869
- authoredFormat: a,
870
- currencyBindable: Fe(a)
871
- };
872
- }
873
- function Ri(e, t) {
874
- const n = he(t.format, {
875
- preserveOmittedProperties: !0
876
- }), o = se(t.dataType) === "number" ? { type: "number" } : void 0, r = n || o;
877
- return {
878
- authoredFormat: r,
879
- source: n ? "semantic" : o ? "inferred" : void 0,
880
- currencyBindable: Fe(r)
881
- };
882
- }
883
- function qe(e, t = {}) {
884
- var c, l, d;
885
- const n = t.column ?? ((c = Do(e)) == null ? void 0 : c.value);
886
- if ((n == null ? void 0 : n.kind) === "sqlKpiValue") {
887
- const u = t.resultColumnKey ? {
888
- kind: "column",
889
- columnKey: t.resultColumnKey
890
- } : void 0, f = he(
891
- Sr({ card: e, column: { kind: "sqlKpiValue" }, surface: "kpiValue" }).format,
892
- { preserveOmittedProperties: !0 }
893
- );
894
- return {
895
- target: u,
896
- authoredFormat: f,
897
- ...f ? { source: "stored" } : {},
898
- currencyBindable: !!u && Fe(f)
899
- };
900
- }
901
- const o = n ? (d = (l = e.config) == null ? void 0 : l.metricColumns) == null ? void 0 : d.find((u) => u.id === n.fieldId) : void 0, r = o != null && o.id ? {
902
- kind: "metric",
903
- metricId: o.id
904
- } : void 0, i = he(o == null ? void 0 : o.format, {
905
- preserveOmittedProperties: !0
906
- }), s = se(o == null ? void 0 : o.dataType) === "number" ? { type: "number" } : void 0, a = i || s;
907
- return {
908
- target: r,
909
- authoredFormat: a,
910
- ...i ? { source: "stored" } : s ? { source: "inferred" } : {},
911
- currencyBindable: Lt(e.type) && !!r && Fe(a)
912
- };
913
- }
914
- function Tn(e, t, n) {
915
- var r;
916
- const o = n(e, t);
917
- return ((r = e.derivedField) == null ? void 0 : r.format) ?? (o == null ? void 0 : o.format) ?? (o == null ? void 0 : o.resolvedField.format);
918
- }
919
- function Mn(e, t, n) {
920
- return e.kind === "calculated" ? e.definition.format : Tn(e.field, t, n);
921
- }
922
- function bl(e, t) {
923
- const n = jt(t), o = (r, i) => Object.fromEntries(r.flatMap((s) => {
924
- const a = i(s);
925
- return a ? [[s.id, a]] : [];
926
- }));
927
- return {
928
- measureFormats: o(e.measures, (r) => Mn(r, e.source, n)),
929
- levelFormats: o([...e.rows, ...e.columns], (r) => Tn(r.field, e.source, n))
930
- };
931
- }
932
- function Vn(e, t = []) {
933
- const n = Ge(e);
934
- if (n.status !== "ready") return [];
935
- const { spec: o, presentation: r } = n.config, i = jt(t);
936
- return o.measures.map((s) => {
937
- var p;
938
- const a = s.kind === "aggregate" ? i(s.field, o.source) : void 0, c = Tr(r.measureFormats[s.id], Mn(s, o.source, i)), l = s.kind === "calculated" ? s.definition.dataType : ["MIN", "MAX"].includes(s.aggregate) ? ((p = s.field.derivedField) == null ? void 0 : p.dataType) ?? (a == null ? void 0 : a.resolvedField.dataType) ?? s.field.dataType : "number", d = se(l) === "number", u = s.kind === "calculated" || !!(a || s.field.derivedField || s.field.name === "*"), f = c && Mr(c) ? c : !c && d && u ? { type: "number" } : void 0;
939
- return { measureId: s.id, label: Vr(s, r), canonical: f };
940
- });
941
- }
942
- function Ki(e) {
943
- var t, n;
944
- return e.type === "detailTable" ? ((t = e.config) == null ? void 0 : t.detailColumns) || [] : ((n = e.config) == null ? void 0 : n.metricColumns) || [];
945
- }
946
- function kn(e) {
947
- return new Set(
948
- an(e).flatMap(
949
- (t) => (t.controlBindings || []).filter(Te).map((n) => n.controlId)
950
- )
951
- );
952
- }
953
- function qi(e, t) {
954
- const n = [
955
- t.id,
956
- t.alias,
957
- t.label,
958
- t.name,
959
- t.qualifiedFieldName
960
- ].filter((i) => !!i);
961
- for (const i of n)
962
- if (e[i])
963
- return e[i];
964
- const o = new Set(
965
- n.map((i) => i.trim().toLowerCase())
966
- ), r = Object.entries(e).find(
967
- ([i]) => o.has(i.trim().toLowerCase())
968
- );
969
- return r == null ? void 0 : r[1];
970
- }
971
- function kt(e) {
972
- return [
973
- ...new Map(
974
- e.map((t) => [
975
- J(t),
976
- t
977
- ])
978
- ).values()
979
- ];
980
- }
981
- function Ni(e, t = [], n) {
982
- var M;
983
- const o = !!((M = e.sql) != null && M.trim()), r = Lt(e.type), i = o && r && e.type !== "kpi" && e.type !== "matrixTable", s = Ki(e), a = To(e), c = !o && e.type === "kpi" ? s.map(
984
- (C) => qe(e, {
985
- column: { kind: "field", fieldId: C.id }
986
- })
987
- ) : [], l = !o && e.type === "matrixTable" ? Vn(e, n) : [], d = (o ? [] : s).map(
988
- (C) => ({
989
- kind: "metric",
990
- metricId: C.id
991
- })
992
- ), u = l.map(
993
- (C) => ({
994
- kind: "matrix_measure",
995
- measureId: C.measureId
996
- })
997
- ), f = l.filter((C) => {
998
- var w, B;
999
- return ((w = C.canonical) == null ? void 0 : w.type) === "number" || ((B = C.canonical) == null ? void 0 : B.type) === "currency";
1000
- }).map(
1001
- (C) => ({
1002
- kind: "matrix_measure",
1003
- measureId: C.measureId
1004
- })
1005
- ), p = e.type === "matrixTable" ? [] : e.type === "kpi" ? c.filter((C) => C.currencyBindable).flatMap(
1006
- (C) => C.target ? [C.target] : []
1007
- ) : (o || !r ? [] : s).filter(
1008
- (C) => (Mo(e.type) ? _i(
1009
- C,
1010
- qi(a, C)
1011
- ) : Ri(e, C)).currencyBindable
1012
- ).map(
1013
- (C) => ({
1014
- kind: "metric",
1015
- metricId: C.id
1016
- })
1017
- ), g = [...new Set(t)], m = (i ? g : []).map(
1018
- (C) => ({
1019
- kind: "column",
1020
- columnKey: C
1021
- })
1022
- ), y = (i ? g : []).filter(
1023
- (C) => Ei(
1024
- a[C]
1025
- )
1026
- ).map(
1027
- (C) => ({
1028
- kind: "column",
1029
- columnKey: C
1030
- })
1031
- ), b = (o && e.type === "kpi" ? g.slice(0, 1) : []).map(
1032
- (C) => ({
1033
- kind: "column",
1034
- columnKey: C
1035
- })
1036
- ), I = o && e.type === "kpi" ? qe(e, {
1037
- resultColumnKey: g[0]
1038
- }) : void 0, v = r && (I != null && I.currencyBindable) ? b : [];
1039
- return {
1040
- knownTargets: kt([
1041
- ...e.type === "matrixTable" ? u : d,
1042
- ...m,
1043
- ...b
1044
- ]),
1045
- eligibleTargets: kt([
1046
- ...p,
1047
- ...f,
1048
- ...y,
1049
- ...v
1050
- ])
1051
- };
1052
- }
1053
- function hl(e, t) {
1054
- const n = qe(e, {
1055
- resultColumnKey: t
1056
- });
1057
- return n.currencyBindable ? n.target : void 0;
1058
- }
1059
- function Cl(e) {
1060
- var t;
1061
- return (t = e.card.sql) != null && t.trim() ? { kind: "column", columnKey: e.columnKey } : e.metricId ? { kind: "metric", metricId: e.metricId } : void 0;
1062
- }
1063
- function J(e) {
1064
- return e.kind === "metric" ? `metric:${e.metricId}` : e.kind === "column" ? `column:${e.columnKey}` : `matrix_measure:${e.measureId}`;
1065
- }
1066
- function Li(e) {
1067
- if (!e || typeof e != "object" || Array.isArray(e))
1068
- return;
1069
- const t = e;
1070
- if (t.kind === "metric" && typeof t.metricId == "string" && t.metricId.trim())
1071
- return { kind: "metric", metricId: t.metricId };
1072
- if (t.kind === "column" && typeof t.columnKey == "string" && t.columnKey.trim())
1073
- return { kind: "column", columnKey: t.columnKey };
1074
- if (t.kind === "matrix_measure" && typeof t.measureId == "string" && t.measureId.trim())
1075
- return { kind: "matrix_measure", measureId: t.measureId };
1076
- }
1077
- function Pt(e) {
1078
- const t = tn(e);
1079
- return typeof e == "string" && e === t ? t : void 0;
1080
- }
1081
- function Pn(e) {
1082
- if (e.type !== "enum" || e.source.kind !== "manual")
1083
- return { diagnostic: "invalid_control_type" };
1084
- const t = e.source.options.map(
1085
- (n) => Pt(n.value)
1086
- );
1087
- if (t.length === 0 || t.some((n) => !n))
1088
- return { diagnostic: "invalid_currency_option" };
1089
- if (e.requiredAtExecution) {
1090
- const n = e.initialValueStrategy === "saved_default" ? Pt(e.defaultValue) : void 0;
1091
- if (!n || !t.includes(n))
1092
- return { diagnostic: "invalid_control_default" };
1093
- }
1094
- return {
1095
- control: e,
1096
- currencies: t
1097
- };
1098
- }
1099
- function Il(e) {
1100
- return "control" in Pn(e);
1101
- }
1102
- function xn(e) {
1103
- const t = kn(e.dashboard);
1104
- if (t.size === 0)
1105
- return {
1106
- definitions: e.definitions || [],
1107
- values: e.values || {}
1108
- };
1109
- const n = new Set(
1110
- [...t].filter(
1111
- (o) => !e.referencedControlIds.has(o)
1112
- )
1113
- );
1114
- return {
1115
- definitions: (e.definitions || []).filter(
1116
- (o) => !n.has(o.id)
1117
- ),
1118
- values: Object.fromEntries(
1119
- Object.entries(e.values || {}).filter(
1120
- ([o]) => !n.has(o)
1121
- )
1122
- )
1123
- };
1124
- }
1125
- function vl(e) {
1126
- return xn({
1127
- ...e,
1128
- referencedControlIds: new Set(
1129
- Xe({
1130
- sql: e.filterSql,
1131
- controlBindings: []
1132
- })
1133
- )
1134
- });
1135
- }
1136
- function Fl(e) {
1137
- var t;
1138
- return xn({
1139
- ...e,
1140
- referencedControlIds: new Set(
1141
- Xe({
1142
- sql: (t = e.source) == null ? void 0 : t.sql,
1143
- controlBindings: []
1144
- })
1145
- )
1146
- });
1147
- }
1148
- function wn(e) {
1149
- return {
1150
- knownKeys: new Set(
1151
- e.knownTargets.map(J)
1152
- ),
1153
- eligibleKeys: new Set(
1154
- e.eligibleTargets.map(J)
1155
- ),
1156
- controlsById: new Map(
1157
- (e.controls || []).map((t) => [t.id, t])
1158
- )
1159
- };
1160
- }
1161
- function On(e, t) {
1162
- if (!e || typeof e != "object" || e.target !== "presentation_currency")
1163
- return {};
1164
- const n = e, o = typeof n.controlId == "string" && n.controlId.trim() ? n.controlId : void 0;
1165
- if (!o)
1166
- return { diagnostic: { code: "invalid_binding_shape" } };
1167
- const r = Li(
1168
- n.presentationTarget
1169
- );
1170
- if (!r)
1171
- return {
1172
- diagnostic: { code: "missing_target", controlId: o }
1173
- };
1174
- const i = J(r);
1175
- if (!t.knownKeys.has(i))
1176
- return {
1177
- diagnostic: { code: "stale_target", controlId: o }
1178
- };
1179
- if (!t.eligibleKeys.has(i))
1180
- return {
1181
- diagnostic: { code: "inapplicable_target", controlId: o }
1182
- };
1183
- const s = t.controlsById.get(o);
1184
- if (!s)
1185
- return {
1186
- diagnostic: { code: "missing_control", controlId: o }
1187
- };
1188
- const a = Pn(s);
1189
- return "diagnostic" in a ? {
1190
- diagnostic: { code: a.diagnostic, controlId: o }
1191
- } : {
1192
- binding: {
1193
- controlId: o,
1194
- presentationTarget: r,
1195
- control: a.control,
1196
- currencies: a.currencies
1197
- }
1198
- };
1199
- }
1200
- function Dl(e) {
1201
- const t = wn(e);
1202
- return (e.bindings || []).flatMap((n) => {
1203
- const o = On(n, t);
1204
- return "diagnostic" in o ? [o.diagnostic] : [];
1205
- });
1206
- }
1207
- function ji(e) {
1208
- var r;
1209
- const t = [], n = J(e.target), o = wn(e);
1210
- for (const i of e.bindings || []) {
1211
- const s = On(i, o);
1212
- if ("diagnostic" in s) {
1213
- t.push(s.diagnostic);
1214
- continue;
1215
- }
1216
- const a = s.binding;
1217
- if (!a || J(
1218
- a.presentationTarget
1219
- ) !== n) continue;
1220
- const l = tn(
1221
- (r = e.values) == null ? void 0 : r[a.control.id]
1222
- );
1223
- if (!(!l || !a.currencies.includes(l)))
1224
- return { currency: l, diagnostics: t };
1225
- }
1226
- return { diagnostics: t };
1227
- }
1228
- function zi(e, t, n, o) {
1229
- const r = { ...e, config: { ...e.config, matrix: t } }, i = Ni(r, [], o), s = Vn(r, o), a = { ...t.presentation.measureFormats };
1230
- for (const c of s) {
1231
- const l = { kind: "matrix_measure", measureId: c.measureId }, { currency: d } = ji({
1232
- ...n,
1233
- ...i,
1234
- bindings: e.controlBindings,
1235
- target: l
1236
- });
1237
- if (!d || !c.canonical) continue;
1238
- const { locale: u, ...f } = c.canonical;
1239
- a[c.measureId] = { ...f, type: "currency", currency: d };
1240
- }
1241
- return { ...t.presentation, measureFormats: a };
1242
- }
1243
- function Gi(e, t) {
1244
- if (!e || typeof e != "object" || !("kind" in e))
1245
- return e;
1246
- switch (e.kind) {
1247
- case "manual":
1248
- return {
1249
- kind: "manual",
1250
- ...t != null && t.includePresentation ? {
1251
- options: e.options.map((n) => ({
1252
- value: n.value,
1253
- label: n.label,
1254
- presentation: n.presentation
1255
- }))
1256
- } : {
1257
- optionValues: e.options.map((n) => n.value).sort()
1258
- }
1259
- };
1260
- case "dataset_values":
1261
- return {
1262
- kind: "dataset_values",
1263
- fieldId: e.fieldId,
1264
- connectionId: e.connectionId || ""
1265
- };
1266
- case "field_allowlist":
1267
- return {
1268
- kind: "field_allowlist",
1269
- fieldIds: [...e.fieldIds].sort()
1270
- };
1271
- case "metric_allowlist":
1272
- return {
1273
- kind: "metric_allowlist",
1274
- metricIds: [...e.metricIds].sort()
1275
- };
1276
- case "sql_query":
1277
- return {
1278
- kind: "sql_query",
1279
- connectionId: e.connectionId,
1280
- sql: e.sql,
1281
- valueColumn: e.valueColumn,
1282
- labelColumn: e.labelColumn
1283
- };
1284
- default:
1285
- return e;
1286
- }
1287
- }
1288
- function Hi(e, t) {
1289
- return {
1290
- id: e.id,
1291
- scope: e.scope,
1292
- type: e.type,
1293
- source: Gi(e.source, t),
1294
- initialValueStrategy: e.initialValueStrategy,
1295
- defaultValue: e.defaultValue,
1296
- requiredAtExecution: e.requiredAtExecution,
1297
- ...t != null && t.includePresentation ? {
1298
- label: e.label,
1299
- helpText: e.helpText,
1300
- hidden: e.hidden,
1301
- locked: e.locked,
1302
- placement: e.placement,
1303
- showLabel: e.showLabel,
1304
- toolbarWidth: e.toolbarWidth
1305
- } : {}
1306
- };
1307
- }
1308
- function Ui(e, t) {
1309
- return e.target === "sql_param" || e.target === "presentation_currency" ? e : e.target === "config_field_selector" && !(t != null && t.includePresentation) ? {
1310
- ...e,
1311
- mapping: Object.fromEntries(
1312
- Object.entries(e.mapping).sort(([n], [o]) => n.localeCompare(o)).map(([n, o]) => {
1313
- if ("kind" in o) return [n, o];
1314
- const r = { ...o };
1315
- return delete r.format, delete r.dateFormat, delete r.customFormat, delete r.semanticTemporalPresentation, [n, r];
1316
- })
1317
- )
1318
- } : {
1319
- ...e,
1320
- mapping: Object.fromEntries(
1321
- Object.entries(e.mapping).sort(([n], [o]) => n.localeCompare(o)).map(([n, o]) => [
1322
- n,
1323
- o && typeof o == "object" && !Array.isArray(o) ? Object.fromEntries(
1324
- Object.entries(o).sort(
1325
- ([r], [i]) => r.localeCompare(i)
1326
- )
1327
- ) : o
1328
- ])
1329
- )
1330
- };
1331
- }
1332
- function xt(e = [], t) {
1333
- return [...e].map((n) => Hi(n, t)).sort(
1334
- (n, o) => n.id.localeCompare(o.id) || n.scope.localeCompare(o.scope) || n.type.localeCompare(o.type)
1335
- );
1336
- }
1337
- function $i(e = [], t) {
1338
- return e.filter(
1339
- (n) => (t == null ? void 0 : t.includePresentation) || !Te(n)
1340
- ).map((n) => Ui(n, t)).sort(
1341
- (n, o) => R(n).localeCompare(R(o))
1342
- );
1343
- }
1344
- function Qi(e, t) {
1345
- return e ? R({
1346
- controlDefinitions: xt(e.controlDefinitions, t),
1347
- cardControlDefinitions: xt(
1348
- e.cardControlDefinitions,
1349
- t
1350
- ),
1351
- controlBindings: $i(e.controlBindings, t)
1352
- }) : "__none__";
1353
- }
1354
- const Ji = ["table", "detailTable"], wt = (e) => Ji.includes(e.type), Wi = "calendar-context";
1355
- function Yi(e) {
1356
- const { id: t, label: n, field: o, ...r } = e;
1357
- return {
1358
- ...r,
1359
- field: tt(
1360
- o
1361
- )
1362
- };
1363
- }
1364
- function xe(e) {
1365
- if (!e)
1366
- return;
1367
- const { id: t, conditions: n, groups: o, ...r } = e;
1368
- return {
1369
- ...r,
1370
- conditions: n.map(Yi),
1371
- groups: o.map((i) => xe(i))
1372
- };
1373
- }
1374
- function tt(e) {
1375
- var o, r;
1376
- const { label: t, ...n } = e;
1377
- return {
1378
- ...n,
1379
- ...(o = e.calculatedFormula) != null && o.inputFields ? {
1380
- calculatedFormula: {
1381
- ...e.calculatedFormula,
1382
- inputFields: e.calculatedFormula.inputFields.map(
1383
- tt
1384
- )
1385
- }
1386
- } : {},
1387
- ...(r = e.parameters) != null && r.filters ? {
1388
- parameters: {
1389
- ...e.parameters,
1390
- filters: xe(
1391
- e.parameters.filters
1392
- )
1393
- }
1394
- } : {}
1395
- };
1396
- }
1397
- function Zi(e) {
1398
- const t = (n) => n == null ? void 0 : n.map(tt);
1399
- return {
1400
- ...e,
1401
- groupByColumns: t(e.groupByColumns),
1402
- metricColumns: t(e.metricColumns),
1403
- pivotByColumns: t(e.pivotByColumns),
1404
- sortByColumns: t(e.sortByColumns),
1405
- detailColumns: t(e.detailColumns),
1406
- filters: e.filters ? xe(e.filters) : void 0
1407
- };
1408
- }
1409
- function Xi(e, t, n) {
1410
- if (!e)
1411
- return JSON.stringify(e);
1412
- if (n === "matrixTable" && e.matrix) return R(_r(e.matrix.spec));
1413
- const { matrix: o, ...r } = e, i = t ? Zi(r) : r;
1414
- return JSON.stringify({
1415
- ...i,
1416
- filters: xe(i.filters)
1417
- });
1418
- }
1419
- function es(e) {
1420
- if (!e)
1421
- return null;
1422
- const { format: t, ...n } = e;
1423
- return n;
1424
- }
1425
- function ts(e, t) {
1426
- const n = /* @__PURE__ */ new Map();
1427
- for (const r of (t == null ? void 0 : t.controlDefinitions) || [])
1428
- n.set(r.id, r.type);
1429
- for (const r of (t == null ? void 0 : t.cardControlDefinitions) || [])
1430
- n.set(r.id, r.type);
1431
- const o = Object.fromEntries(
1432
- Object.entries(e || {}).map(([r, i]) => n.get(r) === "multi_enum" && Array.isArray(i) ? [
1433
- r,
1434
- [...i].sort(
1435
- (s, a) => R(s).localeCompare(R(a))
1436
- )
1437
- ] : [r, i])
1438
- );
1439
- return R(o);
1440
- }
1441
- function ns(e, {
1442
- finalFiltersKey: t,
1443
- cardFilterValues: n,
1444
- controlValues: o,
1445
- controlDefinitions: r,
1446
- cardControlDefinitions: i,
1447
- controlBindings: s,
1448
- queryRelevantConfig: a,
1449
- resolvedPrimaryDateField: c,
1450
- globalDateComparison: l,
1451
- calendarContext: d
1452
- }) {
1453
- const { filterColumns: u, ...f } = e.queryConfig || {}, p = u == null ? void 0 : u.filter(
1454
- (v) => {
1455
- var M, C;
1456
- return (C = (M = e.queryConfig) == null ? void 0 : M.filters) == null ? void 0 : C.some((w) => w.filterColumnName === v.name);
1457
- }
1458
- ), g = (e == null ? void 0 : e.sql) || "", m = He((e == null ? void 0 : e.python) || ""), y = ["table", "detailTable", "matrixTable"].includes(
1459
- e.type
1460
- ) ? "table" : e.type === "kpi" ? "kpi" : "chart", b = a || Sn(e.config, { cardType: e.type, dataSource: e.dataSource }), I = Vo.includes(
1461
- e.type
1462
- );
1463
- return [
1464
- "query",
1465
- e == null ? void 0 : e.id,
1466
- y,
1467
- g,
1468
- m,
1469
- JSON.stringify(n),
1470
- ts(o, {
1471
- controlDefinitions: r,
1472
- cardControlDefinitions: i
1473
- }),
1474
- Qi({
1475
- controlDefinitions: r,
1476
- cardControlDefinitions: i,
1477
- controlBindings: s
1478
- }),
1479
- R(
1480
- es(c)
1481
- ),
1482
- R(l ?? null),
1483
- Wi,
1484
- R(d),
1485
- JSON.stringify(f),
1486
- JSON.stringify(p),
1487
- Xi(
1488
- b,
1489
- I,
1490
- e.type
1491
- ),
1492
- t
1493
- ];
1494
- }
1495
- function os(e, t, n) {
1496
- var a, c, l;
1497
- const o = ns(e, t), r = R(o), i = ((a = n == null ? void 0 : n.resolvePaginationConfig) == null ? void 0 : a.call(n, r)) ?? e.paginationConfig, s = wt(e) && Me(e.config) || wt(e) && e.sql && ((l = (c = e.preferences) == null ? void 0 : c.tablePrefs) == null ? void 0 : l.enableDevModePagination);
1498
- return {
1499
- queryKey: [
1500
- ...o,
1501
- s ? JSON.stringify(i) : ""
1502
- ],
1503
- queryInputIdentity: r,
1504
- paginationConfig: i
1505
- };
1506
- }
1507
- function rs(e, t, n, o) {
1508
- return os(
1509
- e,
1510
- {
1511
- finalFiltersKey: t.finalFiltersKey,
1512
- cardFilterValues: t.cardFilterValues,
1513
- controlValues: t.controlValues,
1514
- controlDefinitions: t.controlDefinitions,
1515
- cardControlDefinitions: t.cardControlDefinitions,
1516
- controlBindings: t.controlBindings,
1517
- queryRelevantConfig: t.queryRelevantConfig,
1518
- resolvedPrimaryDateField: t.resolvedPrimaryDateField || void 0,
1519
- globalDateComparison: t.globalDateComparison,
1520
- calendarContext: n
1521
- },
1522
- o
1523
- );
1524
- }
1525
- function Bn(e) {
1526
- const t = {
1527
- ...Ur,
1528
- ...e.presentation
1529
- }, n = t.displayMode, {
1530
- bookkeepingKeys: o,
1531
- comparisonColumnKeys: r,
1532
- deltaColumnKeys: i,
1533
- percentChangeColumnKeys: s,
1534
- ratioColumnKeys: a
1535
- } = ln(e.comparisonMetadata), c = /* @__PURE__ */ new Set();
1536
- t.showComparison && (n === "difference" || n === "both") && i.forEach((f) => c.add(f)), t.showComparison && (n === "percent_change" || n === "both") && s.forEach((f) => c.add(f)), t.showComparison && n === "ratio" && a.forEach((f) => c.add(f));
1537
- const l = new Set(o);
1538
- t.showComparison || r.forEach((f) => l.add(f)), [i, s, a].forEach(
1539
- (f) => f.forEach((p) => {
1540
- c.has(p) || l.add(p);
1541
- })
1542
- );
1543
- const d = /* @__PURE__ */ new Map(), u = /* @__PURE__ */ new Map();
1544
- return Object.entries(e.comparisonMetadata || {}).forEach(
1545
- ([f, p]) => {
1546
- var b;
1547
- const g = p.output;
1548
- if (!g || g.outputId !== f || g.availability.status !== "available")
1549
- return;
1550
- const m = ((b = e.resolveMetricName) == null ? void 0 : b.call(e, {
1551
- metricId: g.metricId,
1552
- metricAlias: g.metricAlias
1553
- })) || p.displayName || g.metricId, y = p.displayLabel || "Comparison";
1554
- g.comparisonColumnKey && (d.set(
1555
- g.comparisonColumnKey,
1556
- `${m} (${y})`
1557
- ), u.set(g.comparisonColumnKey, {
1558
- metricId: g.metricId,
1559
- metricAlias: g.metricAlias,
1560
- kind: "comparison"
1561
- })), g.deltaColumnKey && c.has(g.deltaColumnKey) && (d.set(g.deltaColumnKey, `${m} Difference`), u.set(g.deltaColumnKey, {
1562
- metricId: g.metricId,
1563
- metricAlias: g.metricAlias,
1564
- kind: "delta"
1565
- })), g.percentChangeColumnKey && c.has(g.percentChangeColumnKey) && (d.set(
1566
- g.percentChangeColumnKey,
1567
- `${m} Percent Change`
1568
- ), u.set(g.percentChangeColumnKey, {
1569
- metricId: g.metricId,
1570
- metricAlias: g.metricAlias,
1571
- kind: "percent_change"
1572
- })), g.ratioColumnKey && c.has(g.ratioColumnKey) && (d.set(
1573
- g.ratioColumnKey,
1574
- `${m} Ratio (current ÷ comparison)`
1575
- ), u.set(g.ratioColumnKey, {
1576
- metricId: g.metricId,
1577
- metricAlias: g.metricAlias,
1578
- kind: "ratio"
1579
- }));
1580
- }
1581
- ), {
1582
- excludedKeys: l,
1583
- selectedDerivedKeys: c,
1584
- columnLabels: d,
1585
- columnPresentationOwners: u
1586
- };
1587
- }
1588
- function Sl(e) {
1589
- var t, n;
1590
- return Bn({
1591
- comparisonMetadata: e.comparisonMetadata,
1592
- presentation: (n = (t = e.card) == null ? void 0 : t.preferences) == null ? void 0 : n.comparisonPresentation,
1593
- resolveMetricName: ({ metricId: o, metricAlias: r }) => {
1594
- var i;
1595
- return (i = vn({
1596
- card: e.card,
1597
- columnKeyMap: e.columnKeyMap,
1598
- metricId: o,
1599
- metricAlias: r
1600
- })) == null ? void 0 : i.label;
1601
- }
1602
- });
1603
- }
1604
- function Tl(e) {
1605
- var n;
1606
- return (((n = e.card.config) == null ? void 0 : n.metricColumns) || []).filter(
1607
- (o) => {
1608
- var r;
1609
- return ((r = o.comparison) == null ? void 0 : r.mode) === "explicit";
1610
- }
1611
- ).some(
1612
- (o) => !rn(e.comparisonMetadata, o)
1613
- );
1614
- }
1615
- function is(e) {
1616
- return e.part === "base" && !!e.columnId;
1617
- }
1618
- function nt(e) {
1619
- const t = e.config ?? {};
1620
- return e.type === "detailTable" ? [{ role: "detail", fields: t.detailColumns ?? [] }] : [
1621
- { role: "groupby", fields: t.groupByColumns ?? [] },
1622
- { role: "metric", fields: t.metricColumns ?? [] },
1623
- { role: "detail", fields: t.detailColumns ?? [] }
1624
- ];
1625
- }
1626
- function ot(e, t) {
1627
- if (e.id)
1628
- return t === "metric" ? {
1629
- kind: "metric",
1630
- metricId: e.id,
1631
- metricAlias: le(e)
1632
- } : { kind: "dimension", role: t, fieldId: e.id };
1633
- }
1634
- function Ot(e) {
1635
- const t = /* @__PURE__ */ new Map();
1636
- for (const n of e) t.set(n, (t.get(n) ?? 0) + 1);
1637
- return t;
1638
- }
1639
- function ss(e, t) {
1640
- var u, f;
1641
- const n = [...t.keys], o = new Set(n), r = t.columnKeyMap, i = nt(e).flatMap(
1642
- ({ role: p, fields: g }) => g.flatMap((m) => {
1643
- const y = ot(m, p);
1644
- return y ? [
1645
- {
1646
- identity: y,
1647
- columnId: U(y),
1648
- field: m,
1649
- // Identity comes from result metadata (PLAN B2): no key map, no address.
1650
- outputKey: r ? ce(m, p, n, r) : void 0
1651
- }
1652
- ] : [];
1653
- })
1654
- ), s = Ot(i.map((p) => p.columnId)), a = Ot(
1655
- i.flatMap(
1656
- (p) => p.outputKey ? [p.outputKey] : []
1657
- )
1658
- ), c = /* @__PURE__ */ new Map(), l = /* @__PURE__ */ new Map();
1659
- for (const p of i) {
1660
- if (s.get(p.columnId) !== 1) continue;
1661
- const g = p.outputKey && a.get(p.outputKey) === 1 ? p.outputKey : void 0;
1662
- c.set(p.columnId, {
1663
- columnId: p.columnId,
1664
- identity: p.identity,
1665
- field: p.field,
1666
- baseKey: g,
1667
- // Today's header for the column's own key; a metric shown only as pivot
1668
- // members is named by its field.
1669
- authorLabel: g ? Fn(g, e, r) ?? g : p.field.label || p.field.name || p.columnId
1670
- }), g && l.set(g, { columnId: p.columnId, part: "base" });
1671
- }
1672
- const d = e.config;
1673
- if (e.type === "table" && ((u = d == null ? void 0 : d.pivotByColumns) != null && u.length) && ((f = t.columns) != null && f.length)) {
1674
- const p = e;
1675
- for (const g of t.columns) {
1676
- if (!g.pivotIdentity || !o.has(g.key) || l.has(g.key))
1677
- continue;
1678
- const m = et({
1679
- resultColumn: g,
1680
- card: p,
1681
- columnKeyMap: r
1682
- });
1683
- if (!m) continue;
1684
- const y = {
1685
- kind: "metric",
1686
- metricId: m.identity.metricId,
1687
- metricAlias: m.identity.metricAlias
1688
- }, b = U(y);
1689
- if (m.authoredMetric) {
1690
- if (!c.has(b))
1691
- continue;
1692
- } else {
1693
- if (m.identity.metricId !== Ye)
1694
- continue;
1695
- c.has(b) || c.set(b, { columnId: b, identity: y, authorLabel: "Count" });
1696
- }
1697
- l.set(g.key, { columnId: b, part: "pivot-member" });
1698
- }
1699
- }
1700
- for (const [p, g] of Object.entries(
1701
- t.comparisonMetadata ?? {}
1702
- )) {
1703
- const m = g.output;
1704
- if (m.outputId !== p || m.availability.status !== "available")
1705
- continue;
1706
- const y = U({
1707
- kind: "metric",
1708
- metricId: m.metricId,
1709
- metricAlias: m.metricAlias
1710
- });
1711
- if (c.has(y))
1712
- for (const b of [
1713
- m.comparisonColumnKey,
1714
- m.deltaColumnKey,
1715
- m.percentChangeColumnKey,
1716
- m.ratioColumnKey
1717
- ])
1718
- b && !l.has(b) && l.set(b, { columnId: y, part: "comparison" });
1719
- }
1720
- return { entries: c, owners: l };
1721
- }
1722
- function as(e) {
1723
- const t = /* @__PURE__ */ new Map(), n = /* @__PURE__ */ new Map();
1724
- for (const o of e.keys) {
1725
- const r = { kind: "result", key: o }, i = U(r);
1726
- t.set(i, {
1727
- columnId: i,
1728
- identity: r,
1729
- baseKey: o,
1730
- authorLabel: o
1731
- }), n.set(o, { columnId: i, part: "base" });
1732
- }
1733
- return { entries: t, owners: n };
1734
- }
1735
- function Ml(e) {
1736
- const t = /* @__PURE__ */ new Set();
1737
- for (const n of e ?? [])
1738
- if (n && typeof n == "object")
1739
- for (const o of Object.keys(n)) t.add(o);
1740
- return [...t];
1741
- }
1742
- function ls(e, t) {
1743
- if (e.toLowerCase() !== "count") return !1;
1744
- const n = t == null ? void 0 : t.find((o) => (o == null ? void 0 : o[e]) != null);
1745
- return n ? typeof n[e] == "number" : !1;
1746
- }
1747
- function cs(e, t, n, o) {
1748
- var c, l, d, u;
1749
- let r = [...t.keys], i = /* @__PURE__ */ new Map();
1750
- const s = t.comparisonMetadata;
1751
- if (n === "screen") {
1752
- const f = ln(s);
1753
- r = r.filter((g) => !f.internalKeys.has(g));
1754
- const p = e.type === "table" ? (c = e.preferences) == null ? void 0 : c.comparisonPresentation : void 0;
1755
- dn(p) || (r = r.filter((g) => !f.comparisonColumnKeys.has(g)));
1756
- } else {
1757
- const f = Bn({
1758
- comparisonMetadata: s,
1759
- presentation: (l = e.preferences) == null ? void 0 : l.comparisonPresentation,
1760
- resolveMetricName: o
1761
- });
1762
- r = r.filter((p) => !f.excludedKeys.has(p)), i = f.columnLabels;
1763
- }
1764
- const a = e.config;
1765
- return e.type === "table" && !((d = a == null ? void 0 : a.metricColumns) != null && d.length) && ((u = a == null ? void 0 : a.groupByColumns) != null && u.length) && !e.sql && (r = r.filter((f) => !ls(f, t.rows))), {
1766
- keys: Pi({
1767
- keys: r,
1768
- card: e,
1769
- comparisonMetadata: s,
1770
- columnKeyMap: t.columnKeyMap,
1771
- resultColumns: t.columns
1772
- }),
1773
- exportLabels: i
1774
- };
1775
- }
1776
- function ds(e, t, n) {
1777
- var r, i;
1778
- const o = /* @__PURE__ */ new Map();
1779
- if (e.type !== "table" || !dn((r = e.preferences) == null ? void 0 : r.comparisonPresentation))
1780
- return o;
1781
- for (const s of ((i = e.config) == null ? void 0 : i.metricColumns) ?? []) {
1782
- const { comparisonKind: a, metadata: c } = sn(
1783
- t.comparisonMetadata,
1784
- s
1785
- );
1786
- if (a === "none" || !ce(
1787
- s,
1788
- "metric",
1789
- [...n],
1790
- t.columnKeyMap
1791
- )) continue;
1792
- const d = In(
1793
- s.label || s.name,
1794
- a,
1795
- c
1796
- );
1797
- d && o.set(d, { metric: s, kind: a });
1798
- }
1799
- return o;
1800
- }
1801
- function us(e) {
1802
- const t = nt(e);
1803
- return [
1804
- ...t.filter((n) => n.role === "metric"),
1805
- ...t.filter((n) => n.role !== "metric")
1806
- ];
1807
- }
1808
- function fs(e, t, n) {
1809
- if (!t.length) return [];
1810
- const o = us(e), r = [], i = /* @__PURE__ */ new Set();
1811
- for (const s of t) {
1812
- const a = Rr(o, s);
1813
- if (!a) continue;
1814
- const c = o[a.group], l = ot(c.fields[a.index], c.role);
1815
- if (!l) continue;
1816
- const d = U(l);
1817
- !n.has(d) || i.has(d) || (i.add(d), r.push({
1818
- columnId: d,
1819
- direction: s.direction === "desc" ? "desc" : "asc"
1820
- }));
1821
- }
1822
- return r;
1823
- }
1824
- function ms(e, t) {
1825
- return e ? "query" : t === "server" ? "page-only" : "browser";
1826
- }
1827
- function An(e, t) {
1828
- var n, o, r;
1829
- return !!t && ((r = (o = (n = e.preferences) == null ? void 0 : n.tablePrefs) == null ? void 0 : o.columnVisibility) == null ? void 0 : r[t]) === !1;
1830
- }
1831
- function ps(e) {
1832
- return e.type !== "table" && e.type !== "detailTable" ? "card-type" : cn(e) ? void 0 : "author-disabled";
1833
- }
1834
- function Ne(e, t) {
1835
- const n = [], o = /* @__PURE__ */ new Map();
1836
- for (const r of e) {
1837
- const i = t(r), s = i ? `column:${i.columnId}` : `key:${r}`;
1838
- let a = o.get(s);
1839
- a || (a = { id: s, columnId: i == null ? void 0 : i.columnId, keys: [] }, o.set(s, a), n.push(a)), a.keys.push(r);
1840
- }
1841
- return n;
1842
- }
1843
- function fe(e, t, n) {
1844
- const o = Ne(e, t), r = new Set(n), i = new Map(
1845
- o.flatMap(
1846
- (a) => a.columnId ? [[a.columnId, a]] : []
1847
- )
1848
- ), s = n.flatMap((a) => {
1849
- const c = i.get(a);
1850
- return c ? [c] : [];
1851
- });
1852
- return o.forEach((a, c) => {
1853
- if (a.columnId && r.has(a.columnId)) return;
1854
- const l = c > 0 ? o[c - 1] : void 0, d = l ? s.indexOf(l) + 1 : 0;
1855
- s.splice(d, 0, a);
1856
- }), s.flatMap((a) => a.keys);
1857
- }
1858
- function gs(e) {
1859
- return e != null && e.pivotIdentity ? JSON.stringify(e.pivotIdentity.members.map((t) => t.value)) : void 0;
1860
- }
1861
- function ys(e, t, n, o) {
1862
- const r = e.findIndex(
1863
- (l) => {
1864
- var d;
1865
- return ((d = t(l)) == null ? void 0 : d.part) === "pivot-member";
1866
- }
1867
- );
1868
- if (r === -1) return fe(e, t, n);
1869
- let i = r;
1870
- e.forEach((l, d) => {
1871
- var u;
1872
- ((u = t(l)) == null ? void 0 : u.part) === "pivot-member" && (i = d);
1873
- });
1874
- const s = new Map(
1875
- (o ?? []).map((l) => [l.key, l])
1876
- ), a = [];
1877
- let c;
1878
- for (const l of e.slice(r, i + 1)) {
1879
- const d = gs(s.get(l)) ?? `key:${l}`;
1880
- (!a.length || d !== c) && a.push([]), a[a.length - 1].push(l), c = d;
1881
- }
1882
- return [
1883
- ...fe(e.slice(0, r), t, n),
1884
- ...a.flatMap((l) => fe(l, t, n)),
1885
- ...fe(e.slice(i + 1), t, n)
1886
- ];
1887
- }
1888
- function Vl(e) {
1889
- if (ie(e) !== "config") return;
1890
- const t = /* @__PURE__ */ new Set();
1891
- for (const { role: n, fields: o } of nt(e))
1892
- for (const r of o) {
1893
- const i = ot(r, n);
1894
- i && t.add(U(i));
1895
- }
1896
- return t;
1897
- }
1898
- function kl(e) {
1899
- const t = un(e);
1900
- return (t == null ? void 0 : t.kind) === "metric" && t.metricId === Ye;
1901
- }
1902
- function Pl(e) {
1903
- var ut, ft, mt, pt, gt, yt, bt;
1904
- const { card: t, result: n } = e, o = e.projection ?? "screen", r = ie(t) === "config", i = ps(t), s = i === "card-type" ? void 0 : i === "author-disabled" ? (ut = e.settings) != null && ut.sort ? { sort: e.settings.sort } : void 0 : e.settings, a = ms(r, e.paginationMode), c = n.columnKeyMap, l = r ? ss(t, n) : as(n), d = (h) => {
1905
- var F, P;
1906
- return h && ((P = (F = s == null ? void 0 : s.labels) == null ? void 0 : F[h]) == null ? void 0 : P.trim()) || void 0;
1907
- }, u = (h) => U({ kind: "metric", ...h }), { keys: f, exportLabels: p } = cs(
1908
- t,
1909
- n,
1910
- o,
1911
- (h) => {
1912
- var P;
1913
- const F = u(h);
1914
- return d(l.entries.has(F) ? F : void 0) ?? ((P = l.entries.get(F)) == null ? void 0 : P.authorLabel);
1915
- }
1916
- ), g = (h) => An(t, h), m = (h) => {
1917
- const F = l.owners.get(h);
1918
- if (!F || i === "card-type") return;
1919
- const P = l.entries.get(F.columnId);
1920
- if (!(!P || P.baseKey && g(P.baseKey)))
1921
- return F;
1922
- }, y = f.filter((h) => !g(h)), I = Ne(y, m).flatMap(
1923
- (h) => h.columnId ? [h.columnId] : []
1924
- ), v = new Set(I), M = r ? fs(
1925
- t,
1926
- ((ft = t.config) == null ? void 0 : ft.sortByColumns) ?? [],
1927
- l.entries
1928
- ).filter((h) => v.has(h.columnId)) : [], C = [
1929
- ...(s == null ? void 0 : s.order) ?? [],
1930
- ...(s == null ? void 0 : s.hidden) ?? [],
1931
- ...Object.keys((s == null ? void 0 : s.labels) ?? {}),
1932
- ...((s == null ? void 0 : s.sort) ?? []).map((h) => h.columnId),
1933
- ...Object.keys((s == null ? void 0 : s.widths) ?? {})
1934
- ], w = [
1935
- ...new Set(C.filter((h) => !v.has(h)))
1936
- ];
1937
- let B;
1938
- if (s != null && s.sort && a !== "page-only") {
1939
- const h = s.sort.filter(
1940
- (F) => v.has(F.columnId)
1941
- );
1942
- B = h.length || !s.sort.length ? h : void 0;
1943
- }
1944
- const T = Pr(
1945
- s ? {
1946
- order: (mt = s.order) == null ? void 0 : mt.filter(
1947
- (h) => v.has(h)
1948
- ),
1949
- hidden: (pt = s.hidden) == null ? void 0 : pt.filter(
1950
- (h) => v.has(h)
1951
- ),
1952
- labels: Object.fromEntries(
1953
- Object.entries(s.labels ?? {}).filter(
1954
- ([h]) => v.has(h)
1955
- )
1956
- ),
1957
- sort: B,
1958
- widths: Object.fromEntries(
1959
- Object.entries(s.widths ?? {}).filter(
1960
- ([h]) => v.has(h)
1961
- )
1962
- )
1963
- } : void 0
1964
- ), D = T == null ? void 0 : T.order, V = D ? ys(y, m, D, n.columns) : y, O = D ? [...V, ...f.filter(g)] : f, x = Ne(V, m).flatMap(
1965
- (h) => h.columnId ? [h.columnId] : []
1966
- ), S = new Set((T == null ? void 0 : T.hidden) ?? []);
1967
- x.length && x.every((h) => S.has(h)) && S.delete(x[0]);
1968
- const k = o === "screen" ? ds(t, n, f) : /* @__PURE__ */ new Map(), A = (h, F) => {
1969
- const P = d(F == null ? void 0 : F.columnId);
1970
- if ((F == null ? void 0 : F.part) === "base" && P) return P;
1971
- const K = k.get(h);
1972
- if (K)
1973
- return Ci(
1974
- ((F == null ? void 0 : F.part) === "comparison" ? P : void 0) ?? (K.metric.label || K.metric.name),
1975
- K.kind
1976
- );
1977
- const Z = p.get(h);
1978
- if (Z) return Z;
1979
- const X = Vi({
1980
- columnId: h,
1981
- card: t,
1982
- columnKeyMap: c,
1983
- resultColumns: n.columns,
1984
- // No temporal presentation: a flat table never formats pivot members
1985
- // as dates (its temporal activation covers group columns only).
1986
- metricLabelOverride: (F == null ? void 0 : F.part) === "pivot-member" ? P : void 0
1987
- });
1988
- return X || (Fn(h, t, c) ?? h);
1989
- }, E = O.map((h) => {
1990
- var K;
1991
- const F = m(h), P = (F == null ? void 0 : F.part) ?? ((K = l.owners.get(h)) == null ? void 0 : K.part) ?? "base";
1992
- return {
1993
- outputKey: h,
1994
- ...F ? { columnId: F.columnId } : {},
1995
- part: P,
1996
- visible: !g(h) && !(F && S.has(F.columnId)),
1997
- label: A(h, F),
1998
- resizable: !i && is({ part: P, columnId: F == null ? void 0 : F.columnId })
1999
- };
2000
- }), q = Object.fromEntries(
2001
- E.map((h) => [h.outputKey, h.label])
2002
- ), L = {
2003
- ...((yt = (gt = t.preferences) == null ? void 0 : gt.tablePrefs) == null ? void 0 : yt.columnSizing) ?? {}
2004
- };
2005
- for (const h of E) {
2006
- const F = h.resizable ? (bt = T == null ? void 0 : T.widths) == null ? void 0 : bt[h.columnId] : void 0;
2007
- F !== void 0 && (L[h.outputKey] = F);
2008
- }
2009
- const G = a === "page-only" ? [] : a === "query" ? M : (T == null ? void 0 : T.sort) ?? [], j = new Map(
2010
- G.map((h) => [h.columnId, h.direction])
2011
- ), uo = G.flatMap((h) => {
2012
- var P;
2013
- const F = (P = l.entries.get(h.columnId)) == null ? void 0 : P.baseKey;
2014
- return F && y.includes(F) ? [{ outputKey: F, desc: h.direction === "desc" }] : [];
2015
- }), dt = !i && xr(T);
2016
- let ue;
2017
- if (i)
2018
- ue = { available: !1, reason: i };
2019
- else if (!x.length)
2020
- ue = { available: !1, reason: "no-addressable-columns" };
2021
- else {
2022
- const h = new Set(D ?? []), F = x.filter(
2023
- (P) => !S.has(P)
2024
- ).length;
2025
- ue = {
2026
- available: !0,
2027
- canReset: dt,
2028
- items: x.map((P) => {
2029
- const K = l.entries.get(P), Z = S.has(P), X = j.get(P);
2030
- return {
2031
- columnId: P,
2032
- label: d(P) ?? K.authorLabel,
2033
- authorLabel: K.authorLabel,
2034
- hidden: Z,
2035
- isNew: D !== void 0 && !h.has(P),
2036
- canHide: !Z && F > 1,
2037
- ...X ? { sort: X } : {}
2038
- };
2039
- })
2040
- };
2041
- }
2042
- return {
2043
- columns: E,
2044
- visibleKeys: E.filter((h) => h.visible).map((h) => h.outputKey),
2045
- labels: q,
2046
- columnSizing: L,
2047
- sortMode: a,
2048
- clientSort: uo,
2049
- panel: ue,
2050
- ...T ? { settings: T } : {},
2051
- dropped: w,
2052
- isCustomized: dt,
2053
- canSort: i !== "card-type" && a !== "page-only",
2054
- author: { order: I }
2055
- };
2056
- }
2057
- function xl(e, t) {
2058
- var n;
2059
- return (n = En(e, t)) == null ? void 0 : n.field;
2060
- }
2061
- function En(e, t) {
2062
- const n = un(t), o = e.config;
2063
- if (!n || !o) return;
2064
- let r = [], i;
2065
- if (n.kind === "dimension")
2066
- i = n.role, r = ((n.role === "detail" ? o.detailColumns : o.groupByColumns) ?? []).filter((a) => a.id === n.fieldId);
2067
- else if (n.kind === "metric")
2068
- i = "metric", r = (o.metricColumns ?? []).filter(
2069
- (s) => s.id === n.metricId && le(s) === n.metricAlias
2070
- );
2071
- else
2072
- return;
2073
- return r.length === 1 ? { field: r[0], role: i } : void 0;
2074
- }
2075
- function bs(e, t) {
2076
- const n = t == null ? void 0 : t.sort;
2077
- if (!n || !e.config || e.type !== "table" && e.type !== "detailTable" || ie(e) !== "config")
2078
- return e.config;
2079
- const o = n.flatMap((r) => {
2080
- const i = En(e, r.columnId);
2081
- if (!i) return [];
2082
- const s = Kr(i.field, i.role);
2083
- return An(e, s) ? [] : [
2084
- {
2085
- ...i.field,
2086
- alias: s,
2087
- role: "sortby",
2088
- direction: r.direction
2089
- }
2090
- ];
2091
- });
2092
- return n.length > 0 && o.length === 0 ? e.config : { ...e.config, sortByColumns: o };
2093
- }
2094
- const hs = 500, Cs = 250;
2095
- function Le(e) {
2096
- return e.type === "table" || e.type === "detailTable";
2097
- }
2098
- function Is(e) {
2099
- var t, n, o;
2100
- return !!((t = e.sql) != null && t.trim() && Le(e) && ((o = (n = e.preferences) == null ? void 0 : n.tablePrefs) != null && o.enableDevModePagination));
2101
- }
2102
- function wl(e) {
2103
- return e === "export-full-with-cap" ? hs : Cs;
2104
- }
2105
- function vs({
2106
- card: e,
2107
- isTablePrintMode: t,
2108
- isDocumentSectionRuntime: n,
2109
- documentTableDataPolicy: o
2110
- }) {
2111
- var c, l;
2112
- const r = n && o !== void 0 && Le(e), i = t && !r, s = Me(e.config) && Le(e) && !e.sql, a = r ? Is(e) : !!(e.sql && ((l = (c = e.preferences) == null ? void 0 : c.tablePrefs) != null && l.enableDevModePagination));
2113
- return !i && (s || a);
2114
- }
2115
- function Fs(e) {
2116
- var t, n, o;
2117
- return ((t = e.paginationConfig) == null ? void 0 : t.pageSize) || ((o = (n = e.preferences) == null ? void 0 : n.tablePrefs) == null ? void 0 : o.pageSize) || 50;
2118
- }
2119
- function Ol({
2120
- current: e,
2121
- defaultPageSize: t,
2122
- queryInputIdentity: n
2123
- }) {
2124
- return (e == null ? void 0 : e.queryInputIdentity) === n ? {
2125
- page: e.page,
2126
- pageSize: e.pageSize
2127
- } : {
2128
- page: 1,
2129
- pageSize: (e == null ? void 0 : e.pageSize) ?? t
2130
- };
2131
- }
2132
- function Bl(e, t, n) {
2133
- return (e == null ? void 0 : e.queryInputIdentity) === n && e.page === t.page && e.pageSize === t.pageSize;
2134
- }
2135
- function Al(e, t) {
2136
- return !e || !t || e.page === t.page && e.pageSize === t.pageSize ? e : {
2137
- ...e,
2138
- page: t.page,
2139
- pageSize: t.pageSize,
2140
- hasPrevPage: t.page > 1
2141
- };
2142
- }
2143
- function Ds(e) {
2144
- return { page: 1, pageSize: Fs(e) };
2145
- }
2146
- function Ss(e) {
2147
- var s, a, c, l, d;
2148
- const { card: t } = e, n = vs({
2149
- card: t,
2150
- isTablePrintMode: ((s = e.display) == null ? void 0 : s.isTablePrintMode) ?? !1,
2151
- isDocumentSectionRuntime: !!e.documentSection,
2152
- documentTableDataPolicy: (a = e.documentSection) == null ? void 0 : a.documentTableDataPolicy
2153
- }), { page: o } = e, r = e.documentSection && !e.documentSection.totalsRow ? void 0 : ko(t, e.finalConfig), i = !!((c = e.display) != null && c.deliveryStrict && e.display.isTablePrintMode && !e.documentSection && Lr(t.type));
2154
- return {
2155
- ...r ? { tableTotalsRequest: r } : {},
2156
- ...i ? { sourceRowProbe: { limit: jr.maxTableRows } } : {},
2157
- ...n ? {
2158
- pagination: {
2159
- page: (o == null ? void 0 : o.page) || 1,
2160
- pageSize: (o == null ? void 0 : o.pageSize) || ((d = (l = t.preferences) == null ? void 0 : l.tablePrefs) == null ? void 0 : d.pageSize) || 50
2161
- }
2162
- } : {}
2163
- };
2164
- }
2165
- function Ts(e, t = {}) {
2166
- var r, i, s;
2167
- const n = ((r = e.connectionId) == null ? void 0 : r.trim()) || void 0;
2168
- if (t.editorDevMode) return n;
2169
- const o = ((s = (i = e.dataSource) == null ? void 0 : i.connectionId) == null ? void 0 : s.trim()) || void 0;
2170
- return e.sql ? n || o : o || n;
2171
- }
2172
- function Ms(e, t) {
2173
- var n;
2174
- return {
2175
- connectionId: t,
2176
- connectionType: ((n = e.dataSource) == null ? void 0 : n.connectionType) || "unknown",
2177
- mode: "database",
2178
- selectedEntities: []
2179
- };
2180
- }
2181
- function El(e, t, n = {}) {
2182
- const o = Ts(e, n);
2183
- if (!o)
2184
- throw new Error("No connection ID found for card");
2185
- const r = t.cardDataSource || e.dataSource;
2186
- return {
2187
- connectionId: o,
2188
- requestPayloadBase: {
2189
- ...t,
2190
- cardDataSource: n.liveDataSource ? r : r || Ms(e, o)
2191
- }
2192
- };
2193
- }
2194
- const Vs = /* @__PURE__ */ new Set([
2195
- "day",
2196
- "week",
2197
- "month",
2198
- "quarter",
2199
- "year",
2200
- "hour",
2201
- "minute",
2202
- "second"
2203
- ]);
2204
- function ks(e) {
2205
- let t = e.spec;
2206
- const n = zt(
2207
- e.controlDefinitions || [],
2208
- e.cardControlDefinitions || []
2209
- ), o = (e.controlBindings || []).filter(
2210
- (m) => m.target !== "sql_param"
2211
- ), r = o.filter(
2212
- (m) => m.target === "config_metric_selector" || m.target === "config_field_selector"
2213
- ), i = o.filter(
2214
- (m) => m.target === "config_grain" || m.target === "config_aggregation"
2215
- ), s = /* @__PURE__ */ new Set(), a = /* @__PURE__ */ new Map();
2216
- let c;
2217
- const l = () => {
2218
- if (c) return c;
2219
- const m = e.catalog, y = /* @__PURE__ */ new Map();
2220
- for (const b of m) {
2221
- const I = y.get(b.id) ?? [];
2222
- y.set(b.id, [...I, b]);
2223
- }
2224
- return c = { refs: m, byId: y }, c;
2225
- }, d = (m, y) => {
2226
- throw new Ao(m, {
2227
- code: Eo,
2228
- ...y ? { controlId: y } : {}
2229
- });
2230
- }, u = (m, y) => {
2231
- var I;
2232
- if (m.derivedField) return m.derivedField.dataType;
2233
- const b = l().refs.filter((v) => v.field.name === m.name && _e(v.field.source ?? e.spec.source, m.source ?? e.spec.source));
2234
- return b.length > 1 ? d("The selected field is ambiguous in the authorized Matrix field catalog.", y) : se(((I = b[0]) == null ? void 0 : I.field.dataType) ?? m.dataType);
2235
- }, f = (m, y) => Po(m, y.target, (b) => u(b, y.controlId)), p = br.safeParse(t);
2236
- if (!p.success) return d(p.error.message);
2237
- t = p.data;
2238
- const g = [...r, ...i].map((m) => {
2239
- const y = Gt({ binding: m, definitions: n, controlValues: e.controlValues }), b = !m.matrixTargetId && y !== void 0 && y !== Re ? f(p.data, m) : [];
2240
- return {
2241
- binding: m,
2242
- selectedValue: y,
2243
- targetId: m.matrixTargetId ?? (b.length === 1 ? b[0].id : void 0)
2244
- };
2245
- });
2246
- for (const { binding: m, targetId: y, selectedValue: b } of g) {
2247
- if (b === void 0 || b === Re)
2248
- continue;
2249
- const I = (D) => d(D, m.controlId), v = m.target === "config_metric_selector" || m.target === "config_aggregation", M = f(t, m);
2250
- (!y || !M.some((D) => D.id === y)) && I("Choose a valid Matrix level or measure target for this control.");
2251
- const C = `${m.target}:${y}`;
2252
- s.has(C) && I("Multiple controls cannot replace the same Matrix target."), s.add(C);
2253
- const w = (D) => {
2254
- const V = (l().byId.get(D.id) ?? []).filter((x) => !D.source || _e(D.source, x.field.source ?? e.spec.source));
2255
- if (V.length !== 1) return I(V.length ? "The selected field is ambiguous in the authorized Matrix field catalog." : "The selected field is not in the authorized Matrix field catalog.");
2256
- const O = Cr.safeParse(V[0].field);
2257
- return O.success ? O.data : I(O.error.message);
2258
- }, B = m.target === "config_metric_selector" || m.target === "config_field_selector" ? m.mapping[b] : void 0, T = B && typeof B == "object" && "kind" in B && B.kind === "matrix_instance" ? B.id : void 0;
2259
- if (v) {
2260
- a.set(y, m.controlId);
2261
- const D = T === void 0 ? void 0 : p.data.measures.find(
2262
- (S) => S.id === T && S.kind === "aggregate"
2263
- );
2264
- T !== void 0 && !D && I("The selected Matrix aggregate measure is no longer available.");
2265
- const V = m.target === "config_metric_selector" && !D ? xo({ binding: m, selectedValue: b }) : void 0, O = ((D == null ? void 0 : D.kind) === "aggregate" ? D.aggregate : V == null ? void 0 : V.aggregate) ?? (m.target === "config_aggregation" ? ht({ binding: m, selectedValue: b }) : void 0), x = O === void 0 ? void 0 : hr.safeParse(O);
2266
- x && !x.success && I("This aggregation is not supported by Matrix."), t = {
2267
- ...t,
2268
- measures: t.measures.map(
2269
- (S) => S.id !== y || S.kind !== "aggregate" ? S : {
2270
- ...S,
2271
- ...V ? { field: w(V) } : {},
2272
- ...(D == null ? void 0 : D.kind) === "aggregate" ? { field: D.field } : {},
2273
- aggregate: x != null && x.success ? x.data : S.aggregate
2274
- }
2275
- )
2276
- };
2277
- } else {
2278
- const D = T === void 0 ? void 0 : [...p.data.rows, ...p.data.columns].find(
2279
- (S) => S.id === T
2280
- );
2281
- T !== void 0 && !D && I("The selected Matrix level is no longer available.");
2282
- const V = m.target === "config_field_selector" && !D ? wo({ binding: m, selectedValue: b }) : void 0, O = m.target === "config_grain" ? ht({ binding: m, selectedValue: b }) : D ? D.grain : V == null ? void 0 : V.granularity;
2283
- O !== void 0 && !Vs.has(O) && I("This time grain is not supported by Matrix.");
2284
- const x = (S) => S.map((k) => {
2285
- if (k.id !== y) return k;
2286
- const A = (D == null ? void 0 : D.field) ?? (V ? w(V) : k.field), E = u(A, m.controlId), q = O ?? (V && be(E) ? k.grain : void 0);
2287
- return q && !be(E) && I("A time grain requires a temporal Matrix level."), { ...k, field: A, grain: q };
2288
- });
2289
- t = {
2290
- ...t,
2291
- rows: x(t.rows),
2292
- columns: x(t.columns)
2293
- };
2294
- }
2295
- }
2296
- for (const [m, y] of Array.from(a)) {
2297
- const b = t.measures.find((v) => v.id === m);
2298
- if (!b || b.kind !== "aggregate") continue;
2299
- const I = u(b.field, y);
2300
- Oo(I).some((v) => v.value === b.aggregate) || d(`Aggregation '${b.aggregate}' is not eligible for this Matrix field datatype.`, y);
2301
- }
2302
- try {
2303
- return Bo(p.data, t);
2304
- } catch (m) {
2305
- if (m instanceof Dr) return d(m.message);
2306
- throw m;
2307
- }
2308
- }
2309
- function _n(e, t) {
2310
- const n = [], o = (r) => {
2311
- if (r.source) {
2312
- const i = Ir.safeParse(r.source);
2313
- if (i.success) n.push(i.data);
2314
- else if (t) throw i.error;
2315
- }
2316
- r.derivedField && Object.values(r.derivedField.inputs).forEach((i) => o(i.field));
2317
- };
2318
- for (const r of e) {
2319
- if (r.target !== "config_field_selector" && r.target !== "config_metric_selector") continue;
2320
- const i = t == null ? void 0 : t.get(r), s = t ? i && i !== Re ? [r.mapping[i]] : [] : Object.values(r.mapping);
2321
- for (const a of s)
2322
- a && "role" in a && o(a);
2323
- }
2324
- return n;
2325
- }
2326
- function Ps(e, t = [], n = []) {
2327
- return Xt([...Ht(e), ..._n(t), ...n]);
2328
- }
2329
- function xs(e, t = {}) {
2330
- const n = t.controlBindings ?? [], o = zt(t.controlDefinitions ?? [], t.cardControlDefinitions ?? []), r = new Map(n.filter((i) => i.target === "config_field_selector" || i.target === "config_metric_selector").map((i) => [i, Gt({ binding: i, definitions: o, controlValues: t.controlValues })]));
2331
- return Xt([...Ht(e), ..._n(n, r)]);
2332
- }
2333
- function ws(e, t) {
2334
- return ze(e) ? Os(e, t) : e.config ?? {};
2335
- }
2336
- function Os(e, t) {
2337
- var o;
2338
- const n = (o = t == null ? void 0 : t.steps[t.steps.length - 1]) == null ? void 0 : o.toField;
2339
- return n ? hi(e.config ?? {}, n, {
2340
- sortPolicy: "retargetDimensionSort"
2341
- }) : e.config ?? {};
2342
- }
2343
- function Bs(e, t) {
2344
- const n = (e == null ? void 0 : e.steps) ?? [];
2345
- if (n.length !== 0)
2346
- return {
2347
- id: `${t}-drill-root`,
2348
- logicalOperator: "AND",
2349
- negate: !1,
2350
- conditions: [],
2351
- groups: n.map((o, r) => ({
2352
- id: `breadcrumb-${r}`,
2353
- logicalOperator: "OR",
2354
- negate: !1,
2355
- conditions: [],
2356
- groups: [
2357
- {
2358
- id: `breadcrumb-${r}-group-0`,
2359
- logicalOperator: "AND",
2360
- negate: !1,
2361
- conditions: o.conditions.map(
2362
- (i) => zr(
2363
- i,
2364
- `${i.field.id}-${i.value}`
2365
- )
2366
- ),
2367
- groups: []
2368
- }
2369
- ]
2370
- }))
2371
- };
2372
- }
2373
- const we = (e) => typeof e == "object" && e !== null && !Array.isArray(e);
2374
- function te(e) {
2375
- return e instanceof Date ? JSON.stringify(Number.isNaN(e.getTime()) ? null : e.toISOString()) : Array.isArray(e) ? `[${e.map(te).join(",")}]` : we(e) ? `{${Object.keys(e).sort().filter((t) => e[t] !== void 0).map((t) => `${JSON.stringify(t)}:${te(e[t])}`).join(",")}}` : JSON.stringify(e) ?? "null";
2376
- }
2377
- function As(e) {
2378
- const t = e;
2379
- return t.valueType === "date" || t.relativeMeta !== void 0 || t.temporalBucket !== void 0 || be(t.dataType);
2380
- }
2381
- function Es(e) {
2382
- const t = we(e.field) ? e.field : void 0;
2383
- return e.temporalBucket !== void 0 || e.rawTemporal !== void 0 || e.relativeMeta !== void 0 || be(t == null ? void 0 : t.dataType);
2384
- }
2385
- function Rn(e) {
2386
- return e ? [...(e.conditions ?? []).filter(Es).map((n) => {
2387
- const o = we(n.field) ? n.field : {};
2388
- return {
2389
- field: o.qualifiedFieldName ?? o.name,
2390
- operator: n.operator,
2391
- value: n.value,
2392
- temporalBucket: n.temporalBucket,
2393
- rawTemporal: n.rawTemporal,
2394
- relativeMeta: n.relativeMeta
2395
- };
2396
- }), ...(e.groups ?? []).flatMap((n) => Rn(n))] : [];
2397
- }
2398
- function Bt(e) {
2399
- const t = e.filterValues.filter(As).map((o) => {
2400
- const r = o, i = we(r.fieldMeta) ? r.fieldMeta : void 0;
2401
- return {
2402
- field: (i == null ? void 0 : i.qualifiedFieldName) ?? r.name,
2403
- operation: r.operation,
2404
- ...r.relativeMeta !== void 0 ? { relativeMeta: r.relativeMeta } : { values: r.values },
2405
- temporalBucket: r.temporalBucket
2406
- };
2407
- }), n = Rn(e.selectionFilters);
2408
- return te({
2409
- values: t.map(te).sort(),
2410
- conditions: n.map(te).sort(),
2411
- ...e.zoom ? { zoom: [e.zoom.from, e.zoom.to] } : {}
2412
- });
2413
- }
2414
- function _s(e, t, n) {
2415
- if (!t || n.drillActive || t.madeUnder !== n.currentFingerprint) return e;
2416
- const o = e.groupByColumns ?? [];
2417
- return o.some((r) => r.id === t.fieldId && r.grainMode === "automatic") ? {
2418
- ...e,
2419
- groupByColumns: o.map((r) => {
2420
- if (r.id !== t.fieldId || r.grainMode !== "automatic") return r;
2421
- const { grainMode: i, ...s } = r;
2422
- return { ...s, granularity: t.granularity };
2423
- })
2424
- } : e;
2425
- }
2426
- function _l(e) {
2427
- var t;
2428
- return (((t = e.config) == null ? void 0 : t.groupByColumns) ?? []).find(
2429
- (n) => n.grainMode === "automatic" && _o({ cardType: e.type, configBacked: !0, shelf: "groupBy", dataType: n.dataType }).ok
2430
- );
2431
- }
2432
- function Rs(e, t) {
2433
- if (!e || !t || t.id !== e.fieldId || vr(t)) return;
2434
- const {
2435
- granularity: n,
2436
- grainMode: o,
2437
- dateFormat: r,
2438
- timeDrillPath: i,
2439
- ...s
2440
- } = t;
2441
- return {
2442
- id: `zoom:${e.fieldId}`,
2443
- logicalOperator: "AND",
2444
- negate: !1,
2445
- conditions: [
2446
- {
2447
- id: `zoom:${e.fieldId}:range`,
2448
- field: s,
2449
- operator: "between",
2450
- value: [e.from, e.to],
2451
- viewerZoom: !0
2452
- }
2453
- ],
2454
- groups: []
2455
- };
2456
- }
2457
- function Rl(e, t, n) {
2458
- const o = It(e, n), r = It(t, n);
2459
- if (!o || !r) return;
2460
- const [i, s] = o.first <= r.first ? [o, r] : [r, o];
2461
- return { from: i.first, to: s.last };
2462
- }
2463
- function Ks(e, t, n) {
2464
- if (!e || e.madeUnder !== n) return;
2465
- const o = t == null ? void 0 : t.find((i) => i.id === e.fieldId && i.grainMode === "automatic"), r = Rs(e, o);
2466
- return r ? { zoom: e, filterGroup: r } : void 0;
2467
- }
2468
- function Kl(e, t, n) {
2469
- if (!e) return;
2470
- const [o, r] = t <= n ? [t, n] : [n, t];
2471
- if (o < 0 || r >= e.length) return;
2472
- const i = e.slice(o, r + 1);
2473
- if (!i.every((d) => typeof d == "string" && d !== "")) return;
2474
- const s = [...i].sort(), a = s[0], c = s[s.length - 1];
2475
- return e.some(
2476
- (d, u) => (u < o || u > r) && typeof d == "string" && d > a && d < c
2477
- ) ? void 0 : { first: a, last: c };
2478
- }
2479
- function ql(e, t, n) {
2480
- if (!t || !n) return { from: e.from, to: e.to };
2481
- const o = Dt(new Date(t.startInclusive), n), r = Dt(new Date(Date.parse(t.endExclusive) - 1), n), i = e.from < o ? o : e.from, s = e.to > r ? r : e.to;
2482
- return i <= s ? { from: i, to: s } : { from: e.from, to: e.to };
2483
- }
2484
- function Nl(e, t, n) {
2485
- const o = (i) => /* @__PURE__ */ new Date(`${i}T00:00:00.000Z`), r = new Intl.DateTimeFormat(t, { dateStyle: n, timeZone: "UTC" });
2486
- return e.from === e.to ? r.format(o(e.from)) : r.formatRange(o(e.from), o(e.to));
2487
- }
2488
- function rt(e) {
2489
- return e === "in" || e === "not in";
2490
- }
2491
- function it(e) {
2492
- return e === "not in" ? "exclude" : "include";
2493
- }
2494
- function qs(e) {
2495
- return e === "exclude" ? "not in" : "in";
2496
- }
2497
- function Ll(e) {
2498
- var n;
2499
- const t = (n = e.liveValue) == null ? void 0 : n.operation;
2500
- return rt(t) ? it(t) : e.pendingMode ?? e.authoredMode;
2501
- }
2502
- function Ns(e) {
2503
- var o;
2504
- let t = !1;
2505
- const n = (o = e.inputs) == null ? void 0 : o.map((r) => {
2506
- if (r.kind !== "filter" || !r.filter) return r;
2507
- const i = Ls(
2508
- r.filter,
2509
- new Set(js(e.defaultInputValues, r))
2510
- );
2511
- return i === r.filter ? r : (t = !0, { ...r, filter: i });
2512
- });
2513
- return t ? { ...e, inputs: n } : e;
2514
- }
2515
- function Ls(e, t) {
2516
- if (t.size !== 1 || !rt(e.operation))
2517
- return e;
2518
- const [n] = t;
2519
- return it(e.operation) === n ? e : { ...e, operation: qs(n) };
2520
- }
2521
- function js(e, t) {
2522
- var r;
2523
- const n = (i) => Object.values(i ?? {}).map((s) => s[t.id]);
2524
- return (t.runtimeScope === "shared" ? [(r = e == null ? void 0 : e.shared) == null ? void 0 : r[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(
2525
- (i) => (i == null ? void 0 : i.status) === "set" && i.value.kind === "filter" ? zs(i.value.filterValue) : []
2526
- );
2527
- }
2528
- function zs(e) {
2529
- return rt(e.operation) ? [it(e.operation)] : [];
2530
- }
2531
- function jl(e) {
2532
- const t = nn(e), o = N(t).issues.length ? t : za(t);
2533
- return yi(Ns(o)).dashboard;
2534
- }
2535
- function st(e, t) {
2536
- const n = {};
2537
- for (const o of an(e)) {
2538
- if (!o.inlineFilters || o.inlineFilters.length === 0)
2539
- continue;
2540
- const r = [];
2541
- for (const i of o.inlineFilters) {
2542
- const s = Ro(i, t);
2543
- s && r.push(s);
2544
- }
2545
- r.length > 0 && (n[o.id] = r);
2546
- }
2547
- return n;
2548
- }
2549
- function re(e) {
2550
- const t = Ve(e ?? {}), n = [];
2551
- for (const [o, r] of Object.entries(t.shared ?? {}))
2552
- n.push({ scope: "shared", target: null, inputId: o, slot: r });
2553
- for (const o of ["bySheetId", "byCardId"])
2554
- for (const [r, i] of Object.entries(t[o] ?? {}))
2555
- for (const [s, a] of Object.entries(i))
2556
- n.push({ scope: o, target: r, inputId: s, slot: a });
2557
- return n;
2558
- }
2559
- function De(e, t, n) {
2560
- const o = e;
2561
- if (t.scope === "shared") {
2562
- o.shared = { ...o.shared, [t.inputId]: n };
2563
- return;
2564
- }
2565
- const r = { ...o[t.scope] ?? {} };
2566
- r[t.target] = { ...r[t.target], [t.inputId]: n }, o[t.scope] = r;
2567
- }
2568
- function Kn(e, t, n) {
2569
- const o = Ut(
2570
- e,
2571
- t.controlOverrides,
2572
- { hasExplicitRuntimeOverrides: t.controlOverrides !== void 0 }
2573
- );
2574
- return {
2575
- adHocFilterValues: [...t.adHocFilterValues],
2576
- controlValues: o.dashboardControlValues,
2577
- cardControlValuesMap: o.cardControlValuesMap,
2578
- dashboardInputValues: t.dashboardInputValues,
2579
- inlineFilterValuesMap: t.inlineFilterValuesMap ?? st(e, n)
2580
- };
2581
- }
2582
- function at(e, t, n) {
2583
- return qn(
2584
- e,
2585
- Kn(e, t, n),
2586
- n
2587
- );
2588
- }
2589
- function zl(e, t, n) {
2590
- return qn(e, t, n);
2591
- }
2592
- function qn(e, t, n) {
2593
- const o = e.sheets ?? [], r = o.filter((a) => (a.kind ?? "dashboard") === "dashboard").map((a) => a.id), i = o.filter((a) => a.kind === "document"), s = r.length ? qo({
2594
- dashboard: e,
2595
- sheetIds: r,
2596
- mode: "dashboard",
2597
- runtimeValues: t,
2598
- transientContexts: void 0,
2599
- calendar: n ?? null
2600
- }).snapshot.dashboardInputValues : {};
2601
- return i.reduce(
2602
- (a, c) => {
2603
- var l;
2604
- return $e(
2605
- a,
2606
- No({
2607
- dashboard: e,
2608
- sheetId: c.id,
2609
- sheetKind: "document",
2610
- mode: "document",
2611
- sectionIds: (((l = c.document) == null ? void 0 : l.sections) ?? []).map(
2612
- (d) => d.id
2613
- ),
2614
- runtimeValues: t,
2615
- transientContexts: void 0,
2616
- calendar: n ?? null
2617
- }).snapshot.dashboardInputValues
2618
- );
2619
- },
2620
- s
2621
- );
2622
- }
2623
- function Nn(e, t) {
2624
- const n = {}, o = {}, r = /* @__PURE__ */ new Map();
2625
- for (const i of re(t)) {
2626
- const s = e.get(i.inputId), { slot: a } = i, c = () => a.status === "set" && a.value.kind === "filter" ? a.value.filterValue : a.status === "cleared" ? null : void 0;
2627
- if ((s == null ? void 0 : s.source) === "cardInlineFilter") {
2628
- const l = c();
2629
- if (l !== void 0) {
2630
- const d = r.get(s.cardId) ?? /* @__PURE__ */ new Map();
2631
- d.set(s.filterId, l), r.set(s.cardId, d);
2632
- }
2633
- } else if ((s == null ? void 0 : s.source) === "dashboardControl" || (s == null ? void 0 : s.source) === "cardControl")
2634
- a.status === "set" && a.value.kind === "control" ? o[s.controlId] = a.value.value : a.status === "cleared" && (o[s.controlId] = void 0);
2635
- else {
2636
- De(n, i, a);
2637
- continue;
2638
- }
2639
- a.comparisonSelection && De(n, i, {
2640
- comparisonSelection: a.comparisonSelection
2641
- });
2642
- }
2643
- return {
2644
- runtime: Ve(n),
2645
- controlValues: o,
2646
- inlineFilterValues: r
2647
- };
2648
- }
2649
- function Gs(e, t) {
2650
- if (!t.size) return [...e];
2651
- const n = e.filter((r) => !t.has(r.filterId)), o = [...t.values()].filter(
2652
- (r) => r !== null
2653
- );
2654
- return Lo(n, o);
2655
- }
2656
- function Ln(e, t, n) {
2657
- if (!Object.keys(n).length) return t;
2658
- const o = Ut(
2659
- e,
2660
- t,
2661
- { hasExplicitRuntimeOverrides: t !== void 0 }
2662
- );
2663
- return {
2664
- ...Ko({
2665
- dashboardValues: o.dashboardControlValues,
2666
- cardValuesMap: o.cardControlValuesMap
2667
- }),
2668
- ...n
2669
- };
2670
- }
2671
- function Hs(e, t) {
2672
- if (!t.size) return;
2673
- const n = Object.fromEntries(
2674
- Object.entries(e).map(([o, r]) => [o, [...r]])
2675
- );
2676
- for (const [o, r] of t)
2677
- n[o] = Gs(n[o] ?? [], r);
2678
- return n;
2679
- }
2680
- function Us(e, t, n) {
2681
- const o = new Map(
2682
- Q(e).map(({ card: s }) => [
2683
- s.id,
2684
- new Map((s.inlineFilters ?? []).map((a) => [a.id, a]))
2685
- ])
2686
- );
2687
- let r = !1;
2688
- const i = Object.fromEntries(
2689
- Object.entries(t).map(([s, a]) => [s, [...a]])
2690
- );
2691
- for (const [s, a] of Object.entries(n)) {
2692
- const c = o.get(s), l = (a ?? []).filter((d) => {
2693
- const u = c == null ? void 0 : c.get(d.filterId);
2694
- return u ? Ue(u, d) : !1;
2695
- });
2696
- ke(l, i[s] ?? []) || (r = !0), i[s] = l;
2697
- }
2698
- return r ? i : void 0;
2699
- }
2700
- function Gl(e) {
2701
- const { dashboard: t, capture: n, calendar: o } = e, r = co(t, n.filterValues, {
2702
- calendar: o
2703
- }), i = n.dashboardInputExecutionSnapshot, s = n.controlValues, a = {
2704
- ...Kn(
2705
- t,
2706
- {
2707
- adHocFilterValues: r.adHocFilterValues,
2708
- controlOverrides: s,
2709
- // The snapshot replays exactly over the listed values.
2710
- dashboardInputValues: i ? $e(
2711
- r.slots,
2712
- zo({
2713
- dashboard: t,
2714
- dashboardInputValues: i.dashboardInputValues,
2715
- sheetId: i.sheetId,
2716
- cardId: i.cardId
2717
- })
2718
- ) : r.slots
2719
- },
2720
- o
2721
- ),
2722
- cardViewState: i ? jo(i.cardViewState) : {}
2723
- }, c = i ? Go(i.transientContexts) : void 0;
2724
- return {
2725
- runtimeValues: a,
2726
- controlOverrides: s,
2727
- ...c != null && c.length ? { transientContexts: c } : {}
2728
- };
2729
- }
2730
- function Hl(e, t) {
2731
- const { controlContractOverrides: n, cardId: o } = t;
2732
- if (!n || (n.controlDefinitions !== void 0 && (e.controls = n.controlDefinitions), typeof o != "string" || o.trim().length === 0))
2733
- return e;
2734
- const r = ae(e, o);
2735
- return r && (n.cardControlDefinitions !== void 0 && (r.controls = n.cardControlDefinitions), n.controlBindings !== void 0 && (r.controlBindings = n.controlBindings)), e;
2736
- }
2737
- const $s = ["bySheetId", "byCardId", "byDocumentSectionId"];
2738
- function Qs(e, t) {
2739
- const n = N(e);
2740
- let o = !1;
2741
- const r = (s) => {
2742
- if (!s) return s;
2743
- const a = Object.entries(s).filter(([c, l]) => {
2744
- var u;
2745
- if (l.status !== "set" || l.value.kind !== "filter") return !0;
2746
- const d = (u = n.findFilterInput({ inputId: c })) == null ? void 0 : u.input.filter;
2747
- return !d || Ue(d, l.value.filterValue) ? !0 : (o = !0, !1);
2748
- });
2749
- return Object.fromEntries(a);
2750
- }, i = {
2751
- ...t,
2752
- ...t.shared ? { shared: r(t.shared) } : {}
2753
- };
2754
- for (const s of $s) {
2755
- const a = t[s];
2756
- a && (i[s] = Object.fromEntries(
2757
- Object.entries(a).map(([c, l]) => [c, r(l) ?? {}])
2758
- ));
2759
- }
2760
- return o ? i : t;
2761
- }
2762
- function Js(e) {
2763
- var t, n;
2764
- return ((n = (t = e.sheets) == null ? void 0 : t[0]) == null ? void 0 : n.id) ?? null;
2765
- }
2766
- function de(e, t) {
2767
- var n;
2768
- return !!t && !!((n = e.sheets) != null && n.some((o) => o.id === t));
2769
- }
2770
- function Ul(e) {
2771
- const { dashboard: t, host: n, calendar: o } = e, r = co(t, n.filterValues, {
2772
- calendar: o
2773
- }).slots, i = n.controlValues, s = de(t, n.selectedSheetId) ? n.selectedSheetId : Js(t);
2774
- return {
2775
- hostInputValues: r,
2776
- controlOverrides: i,
2777
- selectedSheetId: s,
2778
- hostSelectedSheetId: n.selectedSheetId ?? null,
2779
- materializedInputs: e.materializeInputs === !1 ? {} : at(
2780
- t,
2781
- {
2782
- adHocFilterValues: [],
2783
- controlOverrides: i,
2784
- dashboardInputValues: r
2785
- },
2786
- o
2787
- )
2788
- };
2789
- }
2790
- function jn(e) {
2791
- const t = /* @__PURE__ */ new Map(), n = /* @__PURE__ */ new Set(), o = /* @__PURE__ */ new Map();
2792
- for (const r of Qe(e))
2793
- r.kind === "filter" && r.filter ? t.set(r.id, r.filter) : r.kind === "control" && n.add(r.id), r.compatibility && o.set(r.id, r.compatibility);
2794
- return { filterInputs: t, controlInputIds: n, compatibility: o };
2795
- }
2796
- function zn(e, t) {
2797
- const n = en(t);
2798
- if (!n) return;
2799
- const o = ae(e, n);
2800
- return o ? Ho(o, e) ? "applies" : "not-eligible" : "removed";
2801
- }
2802
- function $l(e, t) {
2803
- const n = zn(e, t);
2804
- return n ? n === "applies" : Qe(e).some(
2805
- (o) => o.id === t
2806
- );
2807
- }
2808
- function Gn(e, t, n, o) {
2809
- if (!n) return {};
2810
- const r = new Set((e.sheets ?? []).map((l) => l.id)), i = new Set(
2811
- Q(e).map(({ card: l }) => l.id)
2812
- ), s = N(e), a = (l) => {
2813
- var u;
2814
- if (!l) return;
2815
- const d = {};
2816
- for (const [f, p] of Object.entries(l)) {
2817
- const g = t.filterInputs.has(f) || t.controlInputIds.has(f) ? f : ((u = s.findFilterInput({ inputId: f })) == null ? void 0 : u.input.id) ?? f;
2818
- if (g !== f && l[g]) continue;
2819
- const m = zn(e, g);
2820
- if (m) {
2821
- if (m !== "applies") {
2822
- o.push({
2823
- kind: "setting-no-longer-applies",
2824
- target: "selection",
2825
- id: g,
2826
- reason: m
2827
- });
2828
- continue;
2829
- }
2830
- d[g] = p;
2831
- continue;
2832
- }
2833
- const y = t.filterInputs.get(g);
2834
- if (!y && !t.controlInputIds.has(g)) {
2835
- o.push({
2836
- kind: "setting-no-longer-applies",
2837
- target: "input",
2838
- id: g,
2839
- reason: "removed"
2840
- });
2841
- continue;
2842
- }
2843
- if (y && p.status === "set" && p.value.kind === "filter" && !Ue(y, p.value.filterValue)) {
2844
- o.push({
2845
- kind: "setting-no-longer-applies",
2846
- target: "input",
2847
- id: g,
2848
- reason: "incompatible"
2849
- });
2850
- continue;
2851
- }
2852
- d[g] = p;
2853
- }
2854
- return Object.keys(d).length ? d : void 0;
2855
- }, c = (l, d) => {
2856
- if (!l) return;
2857
- const u = {};
2858
- for (const [f, p] of Object.entries(l)) {
2859
- if (!d(f)) {
2860
- for (const m of Object.keys(p))
2861
- o.push({
2862
- kind: "setting-no-longer-applies",
2863
- target: "input",
2864
- id: m,
2865
- reason: "removed"
2866
- });
2867
- continue;
2868
- }
2869
- const g = a(p);
2870
- g && (u[f] = g);
2871
- }
2872
- return u;
2873
- };
2874
- return Ve({
2875
- shared: a(n.shared),
2876
- bySheetId: c(n.bySheetId, (l) => r.has(l)),
2877
- byCardId: c(n.byCardId, (l) => i.has(l))
2878
- // Document sections are not viewer state.
2879
- });
2880
- }
2881
- function _(e, t, n, o = {}) {
2882
- const r = new Map(
2883
- Q(e).map(({ card: s }) => [s.id, s])
2884
- ), i = {};
2885
- for (const [s, a] of Object.entries(t ?? {})) {
2886
- const c = r.get(s);
2887
- if (c && cn(c)) {
2888
- wr(a) || (i[s] = a);
2889
- continue;
2890
- }
2891
- if (c && o.sessionSorts && Or(c)) {
2892
- a.sort && (i[s] = { sort: a.sort });
2893
- continue;
2894
- }
2895
- n == null || n.push({
2896
- kind: "setting-no-longer-applies",
2897
- target: "card",
2898
- id: s,
2899
- reason: ae(e, s) ? "not-eligible" : "removed"
2900
- });
2901
- }
2902
- return i;
2903
- }
2904
- function Ws(e, t, n) {
2905
- if (t) {
2906
- if (de(e, t)) return t;
2907
- n.push({
2908
- kind: "setting-no-longer-applies",
2909
- target: "sheet",
2910
- id: t,
2911
- reason: "removed"
2912
- });
2913
- }
2914
- }
2915
- const lt = (e, t) => ke(e ?? null, t ?? null);
2916
- function Hn(e) {
2917
- return {
2918
- adHocFilterValues: e.adHocFilterValues,
2919
- controlOverrides: e.controlOverrides,
2920
- dashboardInputValues: e.dashboardInputValues,
2921
- ...e.inlineFilterValuesMap ? { inlineFilterValuesMap: e.inlineFilterValuesMap } : {},
2922
- selectedSheetId: e.selectedSheetId,
2923
- tableSettings: e.tableSettings
2924
- };
2925
- }
2926
- function me(e, t) {
2927
- return {
2928
- adHocFilterValues: [],
2929
- controlOverrides: e.controlOverrides,
2930
- dashboardInputValues: e.hostInputValues,
2931
- selectedSheetId: e.selectedSheetId,
2932
- tableSettings: t
2933
- };
2934
- }
2935
- function Un(e, t) {
2936
- const n = t.dashboardInputValues === e.baseline.hostInputValues && !t.inlineFilterValuesMap && !t.adHocFilterValues.length && t.controlOverrides === e.baseline.controlOverrides;
2937
- return {
2938
- selectedSheetId: t.selectedSheetId,
2939
- // Overlay: the bookmark's values on the baseline's runtime values.
2940
- inputs: n ? e.baseline.materializedInputs : at(e.dashboard, t, e.calendar),
2941
- tableSettings: t.tableSettings
2942
- };
2943
- }
2944
- function $(e, t) {
2945
- const n = Hn(t), o = t.restore ?? n;
2946
- return {
2947
- ...n,
2948
- appliedBookmarkId: t.appliedBookmarkId,
2949
- rememberedWrites: t.rememberedWrites ?? [],
2950
- notices: t.notices ?? [],
2951
- opened: Un(e, o),
2952
- restore: o
2953
- };
2954
- }
2955
- function At(e, t, n, o) {
2956
- const { dashboard: r, baseline: i } = e, s = [], a = fn(t.state, Ze), c = a.ok ? a.value : {};
2957
- for (const g of a.ok ? a.issues : [])
2958
- s.push(Ys(g));
2959
- const l = jn(r), d = Nn(
2960
- l.compatibility,
2961
- Gn(r, l, c.inputs, s)
2962
- ), u = Ws(r, c.selectedSheetId, s) ?? i.selectedSheetId, f = _(
2963
- r,
2964
- c.tableSettings,
2965
- s
2966
- ), p = _(
2967
- r,
2968
- n,
2969
- void 0
2970
- );
2971
- return $(e, {
2972
- appliedBookmarkId: t.id,
2973
- // A bookmark opens without ad-hoc values, as today (P4a-02 f).
2974
- adHocFilterValues: [],
2975
- controlOverrides: Ln(
2976
- r,
2977
- i.controlOverrides,
2978
- d.controlValues
2979
- ),
2980
- // Overlay, never replacement: the bookmark's slots over the host's.
2981
- dashboardInputValues: $e(
2982
- i.hostInputValues,
2983
- d.runtime
2984
- ),
2985
- ...$n(
2986
- Hs(
2987
- st(r, e.calendar),
2988
- d.inlineFilterValues
2989
- )
2990
- ),
2991
- selectedSheetId: u,
2992
- tableSettings: o.writeRemembered ? { ...p, ...f } : (
2993
- // A default bookmark on load: remembered settings per card win.
2994
- { ...f, ...p }
2995
- ),
2996
- rememberedWrites: o.writeRemembered ? Object.entries(f).filter(
2997
- ([g, m]) => !lt(p[g], m)
2998
- ).map(([g, m]) => ({
2999
- kind: "set",
3000
- cardId: g,
3001
- settings: m
3002
- })) : [],
3003
- notices: s
3004
- });
3005
- }
3006
- function Ys(e) {
3007
- return {
3008
- kind: "setting-no-longer-applies",
3009
- target: e.target,
3010
- id: e.id,
3011
- reason: "invalid"
3012
- };
3013
- }
3014
- function $n(e) {
3015
- return e ? { inlineFilterValuesMap: e } : {};
3016
- }
3017
- function Et(e, t, n) {
3018
- const { dashboard: o, baseline: r } = e;
3019
- return {
3020
- // A reload in place keeps ad-hoc values, as today (P4a-02 f), unless the
3021
- // template now defines a filter with that id.
3022
- adHocFilterValues: t.adHocFilterValues.filter(
3023
- (i) => !N(o).findFilterInput({ filterId: i.filterId })
3024
- ),
3025
- // A host's new control defaults are the baseline's, not the viewer's.
3026
- controlOverrides: n.controlsChanged ? r.controlOverrides : t.controlOverrides,
3027
- // Live slots stay, except a filter value this template no longer accepts:
3028
- // that filter loads its new default, as the old list did. The resolver
3029
- // ignores slots this template no longer has.
3030
- dashboardInputValues: Qs(
3031
- o,
3032
- t.dashboardInputValues
3033
- ),
3034
- ...$n(
3035
- Us(
3036
- o,
3037
- st(o, e.calendar),
3038
- t.inlineFilterValuesMap ?? {}
3039
- )
3040
- ),
3041
- selectedSheetId: !n.sheetChanged && de(o, t.selectedSheetId) ? t.selectedSheetId : r.selectedSheetId,
3042
- tableSettings: _(
3043
- o,
3044
- t.tableSettings,
3045
- void 0,
3046
- { sessionSorts: !0 }
3047
- )
3048
- };
3049
- }
3050
- function Ql(e) {
3051
- const { dashboard: t, baseline: n, event: o } = e, r = e.rememberedTableSettings;
3052
- switch (o.kind) {
3053
- case "initial-load":
3054
- return o.defaultBookmark ? At(e, o.defaultBookmark, r, {
3055
- writeRemembered: !1
3056
- }) : $(e, {
3057
- appliedBookmarkId: null,
3058
- ...me(
3059
- n,
3060
- _(t, r, void 0, {
3061
- sessionSorts: o.captured
3062
- })
3063
- )
3064
- });
3065
- case "refetch": {
3066
- const { live: i } = o, s = i.applied, a = {
3067
- sheetChanged: !!i.previousBaseline && i.previousBaseline.hostSelectedSheetId !== n.hostSelectedSheetId,
3068
- controlsChanged: !!i.previousBaseline && !ke(
3069
- i.previousBaseline.controlOverrides ?? null,
3070
- n.controlOverrides ?? null
3071
- )
3072
- }, c = Et(
3073
- e,
3074
- {
3075
- adHocFilterValues: i.adHocFilterValues,
3076
- controlOverrides: i.controlValues ?? n.controlOverrides,
3077
- dashboardInputValues: i.dashboardInputValues,
3078
- inlineFilterValuesMap: i.inlineFilterValuesMap,
3079
- selectedSheetId: i.selectedSheetId,
3080
- tableSettings: i.tableSettings
3081
- },
3082
- a
3083
- ), l = s ? Et(e, s.restore, a) : me(
3084
- n,
3085
- _(t, r, void 0)
3086
- );
3087
- return $(e, {
3088
- appliedBookmarkId: (s == null ? void 0 : s.appliedBookmarkId) ?? null,
3089
- ...c,
3090
- notices: (s == null ? void 0 : s.notices) ?? [],
3091
- restore: l
3092
- });
3093
- }
3094
- case "open-bookmark":
3095
- return At(e, o.bookmark, r, {
3096
- writeRemembered: !0
3097
- });
3098
- case "open-default-view":
3099
- return $(e, {
3100
- appliedBookmarkId: null,
3101
- ...me(
3102
- n,
3103
- _(t, r, void 0)
3104
- )
3105
- });
3106
- case "reset-to-default-view":
3107
- return $(e, {
3108
- appliedBookmarkId: null,
3109
- ...me(n, {}),
3110
- rememberedWrites: [{ kind: "clear-all" }]
3111
- });
3112
- case "discard-changes": {
3113
- const { restore: i } = o.applied, s = _(
3114
- t,
3115
- i.tableSettings,
3116
- void 0,
3117
- { sessionSorts: !0 }
3118
- ), a = _(t, s, void 0), c = _(t, r, void 0), l = [];
3119
- for (const d of /* @__PURE__ */ new Set([
3120
- ...Object.keys(c),
3121
- ...Object.keys(a)
3122
- ])) {
3123
- if (lt(c[d], a[d])) continue;
3124
- const u = a[d];
3125
- l.push(
3126
- u ? { kind: "set", cardId: d, settings: u } : { kind: "clear", cardId: d }
3127
- );
3128
- }
3129
- return $(e, {
3130
- appliedBookmarkId: o.applied.appliedBookmarkId,
3131
- ...i,
3132
- selectedSheetId: de(t, i.selectedSheetId) ? i.selectedSheetId : n.selectedSheetId,
3133
- tableSettings: s,
3134
- rememberedWrites: l,
3135
- notices: o.applied.notices,
3136
- restore: i
3137
- });
3138
- }
3139
- }
3140
- }
3141
- function Jl(e) {
3142
- const { dashboard: t, calendar: n } = e, o = e.hostControlValues, r = {
3143
- ...e.baseline,
3144
- controlOverrides: o,
3145
- materializedInputs: at(
3146
- t,
3147
- {
3148
- adHocFilterValues: [],
3149
- controlOverrides: o,
3150
- dashboardInputValues: e.baseline.hostInputValues
3151
- },
3152
- n
3153
- )
3154
- };
3155
- let i = o;
3156
- if (e.appliedBookmark) {
3157
- const c = fn(
3158
- e.appliedBookmark.state,
3159
- Ze
3160
- ), l = jn(t), d = Nn(
3161
- l.compatibility,
3162
- Gn(
3163
- t,
3164
- l,
3165
- c.ok ? c.value.inputs : void 0,
3166
- []
3167
- )
3168
- ).controlValues;
3169
- i = Ln(t, o, d);
3170
- }
3171
- const s = e.applied;
3172
- if (!s) return { baseline: r, controlOverrides: i, applied: null };
3173
- const a = { ...s.restore, controlOverrides: i };
3174
- return {
3175
- baseline: r,
3176
- controlOverrides: i,
3177
- applied: {
3178
- ...s,
3179
- controlOverrides: i,
3180
- restore: a,
3181
- opened: Un({ dashboard: t, baseline: r, calendar: n }, a)
3182
- }
3183
- };
3184
- }
3185
- function Wl(e, t, n) {
3186
- const o = Hn(n.values);
3187
- return {
3188
- ...o,
3189
- appliedBookmarkId: t,
3190
- rememberedWrites: [],
3191
- notices: e.notices,
3192
- opened: n.snapshot,
3193
- restore: o
3194
- };
3195
- }
3196
- const _t = (e) => JSON.stringify([e.scope, e.target, e.inputId]);
3197
- function pe(e) {
3198
- return !e || e.status === "cleared" && !e.comparisonSelection;
3199
- }
3200
- function Qn(e, t) {
3201
- const n = new Map(
3202
- re(e).map((i) => [_t(i), i])
3203
- ), o = new Map(
3204
- re(t).map((i) => [_t(i), i])
3205
- ), r = {};
3206
- for (const [i, s] of o) {
3207
- const a = n.get(i);
3208
- a && ke(a.slot, s.slot) || pe(s.slot) && pe(a == null ? void 0 : a.slot) || De(
3209
- r,
3210
- s,
3211
- pe(s.slot) ? { status: "cleared" } : s.slot
3212
- );
3213
- }
3214
- for (const [i, s] of n)
3215
- o.has(i) || pe(s.slot) || De(r, s, { status: "cleared" });
3216
- return Ve(r);
3217
- }
3218
- function Yl(e) {
3219
- const { dashboard: t, baseline: n, current: o } = e, r = Qn(n.materializedInputs, o.inputs), i = _(
3220
- t,
3221
- o.tableSettings,
3222
- void 0
3223
- ), s = o.selectedSheetId && o.selectedSheetId !== n.selectedSheetId && de(t, o.selectedSheetId) ? o.selectedSheetId : void 0;
3224
- return {
3225
- version: Ze,
3226
- ...s ? { selectedSheetId: s } : {},
3227
- ...re(r).length ? { inputs: r } : {},
3228
- ...Object.keys(i).length ? { tableSettings: i } : {}
3229
- };
3230
- }
3231
- function Zs(e) {
3232
- const t = /* @__PURE__ */ new Map();
3233
- for (const n of Qe(e))
3234
- n.label && t.set(n.id, n.label);
3235
- return t;
3236
- }
3237
- function Xs(e, t, n) {
3238
- var r, i;
3239
- const o = en(n);
3240
- if (o) {
3241
- const s = (i = (r = ae(e, o)) == null ? void 0 : r.title) == null ? void 0 : i.trim();
3242
- return s ? `Selection in ${s}` : "Selection";
3243
- }
3244
- return t.get(n) ?? n;
3245
- }
3246
- function Zl(e) {
3247
- var l, d;
3248
- const { dashboard: t, opened: n, current: o } = e, r = [], i = Zs(t), s = /* @__PURE__ */ new Set();
3249
- for (const u of re(
3250
- Qn(n.inputs, o.inputs)
3251
- ))
3252
- s.has(u.inputId) || (s.add(u.inputId), r.push({
3253
- target: "input",
3254
- inputId: u.inputId,
3255
- label: Xs(t, i, u.inputId)
3256
- }));
3257
- (n.selectedSheetId ?? null) !== (o.selectedSheetId ?? null) && r.push({ target: "sheet" });
3258
- const a = _(
3259
- t,
3260
- n.tableSettings,
3261
- void 0
3262
- ), c = _(
3263
- t,
3264
- o.tableSettings,
3265
- void 0
3266
- );
3267
- for (const u of /* @__PURE__ */ new Set([
3268
- ...Object.keys(a),
3269
- ...Object.keys(c)
3270
- ]))
3271
- lt(a[u], c[u]) || r.push({
3272
- target: "table",
3273
- cardId: u,
3274
- cardTitle: ((d = (l = ae(t, u)) == null ? void 0 : l.title) == null ? void 0 : d.trim()) || "Table"
3275
- });
3276
- return r;
3277
- }
3278
- function Rt(e) {
3279
- const t = ne(e.filter);
3280
- return {
3281
- inputId: e.inputId,
3282
- filterId: e.filterId,
3283
- label: e.label,
3284
- selection: e.selection,
3285
- owner: t ? { kind: "global_date" } : {
3286
- kind: "field_date",
3287
- filterId: e.filterId,
3288
- label: e.label
3289
- }
3290
- };
3291
- }
3292
- function ea(e) {
3293
- var r, i;
3294
- if ((r = e.card.sql) != null && r.trim())
3295
- return {
3296
- inputs: e.inputs,
3297
- fieldCandidates: [],
3298
- resolution: { status: "none" }
3299
- };
3300
- const t = e.inputs.filter((s) => !ne(s.filter)).map((s) => ({
3301
- input: s,
3302
- resolution: Uo({
3303
- filter: s.filter,
3304
- filterValue: s.filterValue,
3305
- effectiveFilterValue: s.effectiveFilterValue,
3306
- mappedFilterValue: s.mappedFilterValue,
3307
- temporalBinding: e.temporalBinding,
3308
- card: e.card
3309
- })
3310
- }));
3311
- if (!e.temporalBinding)
3312
- return { inputs: e.inputs, fieldCandidates: t, resolution: { status: "none" } };
3313
- const n = e.inputs.find(
3314
- (s) => ne(s.filter)
3315
- );
3316
- if (n && ((i = n.filterValue) == null ? void 0 : i.filterId) === n.filterId && n.effectiveFilterValue.filterId === n.filterId && $o(n.effectiveFilterValue))
3317
- return {
3318
- inputs: e.inputs,
3319
- fieldCandidates: t,
3320
- resolution: {
3321
- status: "resolved",
3322
- resolvedOwner: Rt(n)
3323
- }
3324
- };
3325
- const o = t.filter(
3326
- (s) => s.resolution.status === "eligible"
3327
- );
3328
- return o.length === 1 ? {
3329
- inputs: e.inputs,
3330
- fieldCandidates: t,
3331
- resolution: {
3332
- status: "resolved",
3333
- resolvedOwner: Rt(o[0].input)
3334
- }
3335
- } : o.length > 1 ? {
3336
- inputs: e.inputs,
3337
- fieldCandidates: t,
3338
- resolution: {
3339
- status: "ambiguous",
3340
- candidateInputIds: o.map(
3341
- (s) => s.input.inputId
3342
- )
3343
- }
3344
- } : { inputs: e.inputs, fieldCandidates: t, resolution: { status: "none" } };
3345
- }
3346
- function Xl(e) {
3347
- var n, o;
3348
- const t = {
3349
- ownerCardCount: 0,
3350
- matchingCardCount: 0,
3351
- globalPrecedenceCardCount: 0,
3352
- ambiguousCardCount: 0,
3353
- authorControlledCardCount: 0
3354
- };
3355
- for (const r of e.targets) {
3356
- const i = r.plan.fieldCandidates.find(
3357
- (a) => a.input.inputId === e.inputId
3358
- );
3359
- if (!i || i.resolution.status !== "eligible") continue;
3360
- t.matchingCardCount += 1;
3361
- const { resolution: s } = r.plan;
3362
- s.status === "resolved" && s.resolvedOwner.inputId === e.inputId ? t.ownerCardCount += 1 : s.status === "resolved" && s.resolvedOwner.owner.kind === "global_date" ? t.globalPrecedenceCardCount += 1 : s.status === "ambiguous" && s.candidateInputIds.includes(e.inputId) && (t.ambiguousCardCount += 1), (((n = r.card.preferences) == null ? void 0 : n.inheritGlobalComparison) === !1 || (((o = r.card.config) == null ? void 0 : o.metricColumns) || []).some(
3363
- (a) => a.comparison !== void 0
3364
- )) && (t.authorControlledCardCount += 1);
3365
- }
3366
- return t;
3367
- }
3368
- const ta = /* @__PURE__ */ new Set([
3369
- "between",
3370
- "not between",
3371
- "=",
3372
- "!=",
3373
- ">",
3374
- ">=",
3375
- "<",
3376
- "<=",
3377
- "is null",
3378
- "is not null"
3379
- ]), na = /^(\d{4}-\d{2}-\d{2})T/, oa = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}(?::\d{2}(?:\.\d{1,9})?)?(?:Z|[+-]\d{2}:\d{2})$/;
3380
- function ct(e) {
3381
- return ta.has(e);
3382
- }
3383
- function ra(e, t) {
3384
- if (e instanceof Date)
3385
- return Number.isNaN(e.getTime()) ? e : t ? vt(e, t, "yyyy-MM-dd") : e.toISOString().slice(0, 10);
3386
- if (typeof e != "string")
3387
- return e;
3388
- const n = e.trim();
3389
- if (t && oa.test(n)) {
3390
- const r = new Date(n);
3391
- if (!Number.isNaN(r.getTime()))
3392
- return vt(r, t, "yyyy-MM-dd");
3393
- }
3394
- const o = na.exec(n);
3395
- return o ? o[1] : e;
3396
- }
3397
- function Jn(e, t) {
3398
- return Array.isArray(e) ? e.map(
3399
- (n) => ra(n, t)
3400
- ) : e;
3401
- }
3402
- function Wn(e) {
3403
- return typeof e.allowMinutePrecision == "boolean" ? e.allowMinutePrecision : Je(
3404
- e.dashboard,
3405
- e.semanticExecutionPayload
3406
- ).allEligibleTargetsAreDateTime;
3407
- }
3408
- function Yn(e) {
3409
- const {
3410
- globalDateFilter: t,
3411
- globalDateFilterValue: n,
3412
- timezone: o,
3413
- allowMinutePrecision: r = !1
3414
- } = e;
3415
- if (!t || !n)
3416
- return;
3417
- if (!ct(n.operation))
3418
- return {
3419
- ...n,
3420
- filterId: t.id
3421
- };
3422
- const i = n, s = i.temporalPrecision === "minute" || ye(i.relativeMeta) === "minute", a = !r && s, c = i.operation === "is null" || i.operation === "is not null" ? [] : a ? Jn(i.values, o) : i.values, l = r || ye(i.relativeMeta) !== "minute" ? i.relativeMeta : void 0, d = r && i.temporalPrecision === "minute" ? i.temporalPrecision : void 0, {
3423
- relativeMeta: u,
3424
- temporalPrecision: f,
3425
- values: p,
3426
- ...g
3427
- } = n;
3428
- return {
3429
- ...g,
3430
- filterId: t.id,
3431
- values: c,
3432
- ...l ? { relativeMeta: l } : {},
3433
- ...d ? { temporalPrecision: d } : {}
3434
- };
3435
- }
3436
- function ia(e) {
3437
- const t = W(e.filters);
3438
- if (!t)
3439
- return e.filterValues;
3440
- const n = Wn(e);
3441
- return e.filterValues.map((o) => o.filterId !== t.id ? o : Yn({
3442
- globalDateFilter: t,
3443
- globalDateFilterValue: o,
3444
- timezone: e.timezone,
3445
- allowMinutePrecision: n
3446
- }) || o);
3447
- }
3448
- function Zn(e) {
3449
- const {
3450
- globalDateFilter: t,
3451
- globalDateFilterValue: n,
3452
- resolvedPrimaryDateField: o,
3453
- semanticContext: r,
3454
- timezone: i,
3455
- allowMinutePrecision: s = !1
3456
- } = e;
3457
- if (!t || !n || !o || !ct(n.operation))
3458
- return null;
3459
- const a = n, c = Qo(
3460
- o.dataType
3461
- ), l = s && c, d = a.temporalPrecision === "minute" || ye(a.relativeMeta) === "minute", u = l && a.temporalPrecision === "minute" ? a.temporalPrecision : void 0, f = l || ye(a.relativeMeta) !== "minute" ? a.relativeMeta : void 0, p = !l && d;
3462
- return {
3463
- filterId: t.id,
3464
- dateOwner: "global_date",
3465
- name: o.qualifiedFieldName || o.name,
3466
- operation: a.operation,
3467
- valueType: "date",
3468
- values: a.operation === "is null" || a.operation === "is not null" ? [] : p ? Jn(
3469
- a.values,
3470
- i
3471
- ) : a.values,
3472
- dataType: o.dataType || "date",
3473
- // The exact type travels with the filter, so the server formats the predicate for
3474
- // the column's storage type (it read it from `dataType` before 2.1 split the two).
3475
- ...o.nativeDataType ? { nativeDataType: o.nativeDataType } : {},
3476
- fieldMeta: {
3477
- name: o.name,
3478
- qualifiedFieldName: o.qualifiedFieldName,
3479
- qualifiedEntityName: o.qualifiedEntityName,
3480
- entityId: o.entityId,
3481
- entityName: o.entityName,
3482
- entityType: o.entityType,
3483
- dataType: o.dataType,
3484
- ...o.nativeDataType ? { nativeDataType: o.nativeDataType } : {},
3485
- role: "groupby",
3486
- ...t != null && t.title ? { label: t.title } : {}
3487
- },
3488
- ...r ? { semanticContext: r } : {},
3489
- ...f ? { relativeMeta: f } : {},
3490
- ...u ? { temporalPrecision: u } : {}
3491
- };
3492
- }
3493
- function z(e) {
3494
- return typeof e == "string" ? e.trim() : "";
3495
- }
3496
- function sa(e) {
3497
- var t;
3498
- return (((t = e.semanticContext) == null ? void 0 : t.selectedEntities) || []).filter((n) => typeof n == "object" && n !== null).filter((n) => n.type === "dataset").map((n) => {
3499
- var o;
3500
- return {
3501
- domainId: z(n.domainId) || z((o = e.semanticContext) == null ? void 0 : o.semanticDomainId),
3502
- datasetName: z(n.name),
3503
- selectedEntityId: z(n.id)
3504
- };
3505
- }).filter((n) => n.domainId && n.datasetName);
3506
- }
3507
- function aa(e) {
3508
- var c, l, d, u, f;
3509
- if (ne(e) || (c = e.sql) != null && c.trim())
3510
- return null;
3511
- const t = sa(e), n = z((l = e.semanticContext) == null ? void 0 : l.semanticDomainId), o = z((d = e.fieldMeta) == null ? void 0 : d.entityId), r = z((u = e.fieldMeta) == null ? void 0 : u.entityName), i = z((f = e.fieldMeta) == null ? void 0 : f.entityType) === "dataset", s = t.find(
3512
- (p) => o && p.selectedEntityId === o
3513
- );
3514
- if (s)
3515
- return s;
3516
- const a = t.find(
3517
- (p) => r && p.datasetName === r && (!n || p.domainId === n)
3518
- );
3519
- return a || (t.length === 1 ? t[0] : i && r && n ? {
3520
- domainId: n,
3521
- datasetName: r
3522
- } : null);
3523
- }
3524
- function la(e) {
3525
- var r, i;
3526
- const { filter: t, semanticExecutionPayload: n } = e;
3527
- if (!n)
3528
- return null;
3529
- const o = aa(t);
3530
- return o && ((i = (r = n.domainsById[o.domainId]) == null ? void 0 : r.datasetsByName[o.datasetName]) == null ? void 0 : i.primaryDateField) || null;
3531
- }
3532
- function Xn(e) {
3533
- const t = W(e.filters);
3534
- return t ? e.filterValues.filter(
3535
- (n) => n.filterId !== t.id
3536
- ) : e.filterValues;
3537
- }
3538
- function ec(e) {
3539
- const t = W(e.filters), n = Xn({
3540
- filters: e.filters,
3541
- filterValues: e.filterValues
3542
- });
3543
- if (!t || ne(e.filter))
3544
- return n;
3545
- const o = e.filterValues.find(
3546
- (s) => s.filterId === t.id
3547
- ), r = la({
3548
- filter: e.filter,
3549
- semanticExecutionPayload: e.semanticExecutionPayload
3550
- }), i = Zn({
3551
- globalDateFilter: t,
3552
- globalDateFilterValue: o,
3553
- resolvedPrimaryDateField: r || void 0,
3554
- semanticContext: e.filter.semanticContext,
3555
- timezone: e.timezone,
3556
- allowMinutePrecision: e.allowMinutePrecision
3557
- });
3558
- return i ? [i, ...n] : n;
3559
- }
3560
- function ca(e) {
3561
- var d;
3562
- const t = W(e.filters), n = t ? e.cardFilterValues.find(
3563
- (u) => u.filterId === t.id
3564
- ) : void 0, o = t ? e.cardFilterValues.filter(
3565
- (u) => u.filterId !== t.id
3566
- ) : e.cardFilterValues, r = e.resolvedPrimaryDateField ?? $t({
3567
- card: e.card,
3568
- cardConfig: e.cardConfig,
3569
- resolvedFields: e.resolvedFields,
3570
- semanticExecutionPayload: e.semanticExecutionPayload
3571
- }), i = Zn({
3572
- globalDateFilter: t,
3573
- globalDateFilterValue: n,
3574
- resolvedPrimaryDateField: r || void 0,
3575
- timezone: e.timezone,
3576
- allowMinutePrecision: e.allowMinutePrecision
3577
- }), s = i ? [i, ...o] : o, a = new Map(
3578
- s.map((u) => [
3579
- u.filterId,
3580
- u
3581
- ])
3582
- ), c = ((d = e.dateComparisonInputs) == null ? void 0 : d.flatMap((u) => {
3583
- var p;
3584
- const f = a.get(
3585
- u.filterId
3586
- );
3587
- return f ? [{
3588
- ...u,
3589
- effectiveFilterValue: f,
3590
- mappedFilterValue: (p = e.mappedFilterValuesByInputId) == null ? void 0 : p.get(u.inputId)
3591
- }] : [];
3592
- })) || [], l = ea({
3593
- inputs: c,
3594
- temporalBinding: r,
3595
- card: e.card
3596
- });
3597
- return {
3598
- cardFilterValues: s,
3599
- resolvedPrimaryDateField: r,
3600
- dateComparisonPlan: l
3601
- };
3602
- }
3603
- function tc(e) {
3604
- const t = W(e.filters), n = Wn(e), o = t ? e.filterValues.find(
3605
- (s) => s.filterId === t.id
3606
- ) : void 0, r = Xn(e);
3607
- return !t || !o || !ct(o.operation) ? r : [
3608
- {
3609
- ...Yn({
3610
- globalDateFilter: t,
3611
- globalDateFilterValue: o,
3612
- timezone: e.timezone,
3613
- allowMinutePrecision: n
3614
- }) || o,
3615
- filterId: t.id,
3616
- name: t.title || t.column
3617
- },
3618
- ...r
3619
- ];
3620
- }
3621
- class da extends Error {
3622
- }
3623
- function nc(e, t) {
3624
- const n = new Map((e ? Q(e) : []).map(({ card: o }) => [o.id, o]));
3625
- return t && n.set(t.id, t), [...n.values()].flatMap((o) => {
3626
- const r = Ge(o);
3627
- return r.status === "ready" ? Ps(r.config.spec, o.controlBindings) : [];
3628
- });
3629
- }
3630
- function ua(e, t, n) {
3631
- const o = Jo(e);
3632
- if (!o) throw new Error("Matrix card definition is required.");
3633
- const r = n && ks({
3634
- ...n,
3635
- spec: o.spec,
3636
- catalog: t.map((d) => ({ ...d, id: d.resolvedField.id }))
3637
- }), i = r ? { ...o, spec: r.spec } : o, s = Wo(t), a = Yo(t), c = (d) => {
3638
- const u = a(d, i.spec.source);
3639
- if (!(!u && d.derivedField)) {
3640
- if (!u) throw new da(`Matrix field metadata is unavailable: ${d.name}`);
3641
- return { ...u, ...d.derivedField ? { derivedField: d.derivedField } : {} };
3642
- }
3643
- }, l = {
3644
- rows: i.spec.rows.flatMap((d) => {
3645
- const u = c(d.field);
3646
- return u ? [{ ...u, id: d.id, granularity: d.grain, role: "groupby" }] : [];
3647
- }),
3648
- columns: i.spec.columns.flatMap((d) => {
3649
- const u = c(d.field);
3650
- return u ? [{ ...u, id: d.id, granularity: d.grain, role: "pivotby" }] : [];
3651
- }),
3652
- // Aggregate-stage expressions have no source-column filter target. They stay
3653
- // authoritative in matrix.spec, including all dependencies and controls.
3654
- metrics: i.spec.measures.flatMap((d) => {
3655
- if (d.kind !== "aggregate" || d.field.name === "*") return [];
3656
- const u = c(d.field);
3657
- return u ? [{ ...u, id: d.id, aggregate: d.aggregate, role: "metric" }] : [];
3658
- })
3659
- };
3660
- return { config: i, fields: l, resolveField: s };
3661
- }
3662
- function fa(e) {
3663
- const t = e.filter(Boolean);
3664
- if (t.length !== 0)
3665
- return t.length === 1 ? t[0] : {
3666
- id: Qt(),
3667
- logicalOperator: "AND",
3668
- negate: !1,
3669
- conditions: [],
3670
- groups: t
3671
- };
3672
- }
3673
- function ma(e) {
3674
- if (!e) return;
3675
- const t = (n) => ({
3676
- logicalOperator: n.logicalOperator,
3677
- negate: n.negate,
3678
- conditions: n.conditions.map((o) => ({
3679
- field: o.field.id,
3680
- operator: o.operator,
3681
- value: o.value,
3682
- temporalBucket: o.temporalBucket,
3683
- rawTemporal: o.rawTemporal,
3684
- // The run-time markers decide what runs, so they belong in the key.
3685
- relativeMeta: o.relativeMeta,
3686
- latestValue: o.latestValue,
3687
- viewerZoom: o.viewerZoom
3688
- })),
3689
- groups: n.groups.map(t)
3690
- });
3691
- return JSON.stringify(t(e));
3692
- }
3693
- function pa(e, t, n = {}) {
3694
- const o = e.metricColumns || [];
3695
- if (o.length === 0) return e;
3696
- const r = Zo.includes(
3697
- t
3698
- ), i = Xo.includes(
3699
- t
3700
- ), s = (l) => {
3701
- var d;
3702
- return (d = l.parameters) != null && d.windowTransform ? {
3703
- ...l,
3704
- parameters: {
3705
- ...l.parameters,
3706
- windowTransform: void 0
3707
- }
3708
- } : l;
3709
- };
3710
- let a = !1;
3711
- const c = o.map(
3712
- (l) => {
3713
- var f;
3714
- const d = Br(l);
3715
- if (d === "none")
3716
- return l;
3717
- let u = l;
3718
- return (f = u.parameters) != null && f.windowTransform && (a = !0, u = s(u)), n.keepsPeriodComparison && d !== "target" ? u : r ? d === "target" && !i ? (a = !0, {
3719
- ...u,
3720
- comparison: void 0
3721
- }) : u : (a = !0, { ...u, comparison: void 0 });
3722
- }
3723
- );
3724
- return a ? {
3725
- ...e,
3726
- metricColumns: c
3727
- } : e;
3728
- }
3729
- function oc(e, t = {}) {
3730
- return eo(to(e, t));
3731
- }
3732
- function eo(e) {
3733
- const t = [e.drill, e.selections, e.zoom];
3734
- return e.authored ? Gr(e.authored, t, Qt()) : fa(t);
3735
- }
3736
- function to(e, t = {}) {
3737
- return {
3738
- authored: t.includeAuthoredFilters === !1 ? void 0 : er(e),
3739
- drill: Bs(t.drill, e.id),
3740
- selections: Hr(t.selections ?? []),
3741
- ...t.zoom ? { zoom: t.zoom } : {}
3742
- };
3743
- }
3744
- function ga(e, t, n) {
3745
- const o = ws(e, t);
3746
- return ze(e) ? pa(
3747
- { ...o, filters: n },
3748
- e.type,
3749
- // A data variable's card keeps its own period comparison (P3b-03).
3750
- { keepsPeriodComparison: Ar(e) }
3751
- ) : o;
3752
- }
3753
- function ya(e) {
3754
- const t = tr(e);
3755
- return {
3756
- contextMode: t,
3757
- shouldApplyDashboardFilters: !t || t === "full"
3758
- };
3759
- }
3760
- function ba(e) {
3761
- const t = e.dashboardControls || [], n = e.card.controls || [], o = /* @__PURE__ */ new Set([
3762
- ...t.map((r) => r.id),
3763
- ...n.map((r) => r.id)
3764
- ]);
3765
- return no(
3766
- e.card,
3767
- {
3768
- controlValues: Jt({
3769
- relevantControlIds: o,
3770
- dashboardValues: e.dashboardControlValues,
3771
- cardValues: e.cardControlValues
3772
- }),
3773
- controlDefinitions: t,
3774
- cardControlDefinitions: n,
3775
- controlBindings: e.card.controlBindings || []
3776
- },
3777
- e.presentationControlIds
3778
- );
3779
- }
3780
- function no(e, t, n) {
3781
- const r = t.controlBindings.filter(
3782
- (f) => !Te(f)
3783
- ), i = new Set(
3784
- Xe({
3785
- sql: e.sql,
3786
- controlBindings: r
3787
- })
3788
- ), s = new Set(
3789
- [...n].filter(
3790
- (f) => !i.has(f)
3791
- )
3792
- ), a = t.controlDefinitions.filter(
3793
- (f) => !s.has(f.id)
3794
- ), c = t.cardControlDefinitions.filter(
3795
- (f) => !s.has(f.id)
3796
- ), l = /* @__PURE__ */ new Set([
3797
- ...a.map((f) => f.id),
3798
- ...c.map((f) => f.id)
3799
- ]), d = r.filter(
3800
- (f) => l.has(f.controlId)
3801
- );
3802
- return {
3803
- controlValues: Jt({
3804
- relevantControlIds: l,
3805
- dashboardValues: t.controlValues
3806
- }),
3807
- controlDefinitions: a,
3808
- cardControlDefinitions: c,
3809
- controlBindings: d
3810
- };
3811
- }
3812
- function ha(e, t) {
3813
- return !!t && e.endsWith(t);
3814
- }
3815
- function oo(e, t) {
3816
- return (e ?? []).filter(
3817
- (n) => ha(n.filterId, t)
3818
- );
3819
- }
3820
- function ro(e, t, n) {
3821
- var o;
3822
- if (t)
3823
- return {
3824
- selection: t,
3825
- ...((o = e.preferences) == null ? void 0 : o.inheritGlobalComparison) === !1 ? { inheritGlobalComparison: !1 } : {},
3826
- ...n ? { owner: n } : {}
3827
- };
3828
- }
3829
- function Ca(e) {
3830
- if (e.resolution.status === "resolved")
3831
- return ro(
3832
- e.card,
3833
- e.resolution.resolvedOwner.selection,
3834
- e.resolution.resolvedOwner.owner
3835
- );
3836
- }
3837
- function Ia(e) {
3838
- return `Set ${e.join(", ")} to run this card.`;
3839
- }
3840
- function va({
3841
- dashboardInputContext: e,
3842
- shouldApplyDashboardFilters: t
3843
- }) {
3844
- if (t)
3845
- return e.activeFilters;
3846
- const n = new Set(
3847
- e.inputs.flatMap(
3848
- (o) => o.kind === "filter" && mn(o) ? [o.filter.id] : []
3849
- )
3850
- );
3851
- return e.activeFilters.filter(
3852
- (o) => n.has(o.filterId)
3853
- );
3854
- }
3855
- function Fa({
3856
- dashboardInputFilterValues: e,
3857
- adHocFilterValues: t
3858
- }) {
3859
- const n = [...e], o = new Set(
3860
- n.map((r) => r.filterId)
3861
- );
3862
- for (const r of t)
3863
- o.has(r.filterId) || (n.push(r), o.add(r.filterId));
3864
- return n;
3865
- }
3866
- function Se(e, t) {
3867
- const n = t.shouldApplyDashboardFilters ? oo(t.adHocFilterValues, t.selectedSheetId) : [], o = t.selectionFilterValues ?? [];
3868
- if (!t.dashboardInputContext)
3869
- return {
3870
- status: "ready",
3871
- filterValues: [...n, ...t.inlineFilterValues, ...o],
3872
- mappingDispositions: []
3873
- };
3874
- const r = t.dashboardInputContext.inputs.filter(
3875
- (u) => u.kind === "filter" && !!u.application
3876
- ), i = new Set(
3877
- r.map((u) => u.filter.id)
3878
- ), s = new Set(
3879
- t.dashboardInputContext.inputs.flatMap(
3880
- (u) => {
3881
- var f;
3882
- return u.kind === "filter" && ((f = u.compatibility) == null ? void 0 : f.source) === "cardInlineFilter" ? [u.filter.id] : [];
3883
- }
3884
- )
3885
- ), a = va({
3886
- dashboardInputContext: t.dashboardInputContext,
3887
- shouldApplyDashboardFilters: t.shouldApplyDashboardFilters
3888
- }).filter((u) => !i.has(u.filterId)), c = a.filter(
3889
- (u) => !s.has(u.filterId)
3890
- ), l = a.filter(
3891
- (u) => s.has(u.filterId)
3892
- ), d = nr({
3893
- card: e,
3894
- inputs: r,
3895
- resolvedInputs: t.dashboardInputContext.resolvedInputs,
3896
- activeFilterValues: t.dashboardInputContext.activeFilters,
3897
- shouldApplyDashboardFilters: t.shouldApplyDashboardFilters
3898
- });
3899
- return d.status === "blocked" ? {
3900
- status: "blocked",
3901
- mappingDispositions: d.dispositions
3902
- } : {
3903
- status: "ready",
3904
- filterValues: [
3905
- ...Fa({
3906
- dashboardInputFilterValues: [
3907
- ...c,
3908
- ...d.filterValues
3909
- ],
3910
- adHocFilterValues: n
3911
- }),
3912
- ...l,
3913
- ...o
3914
- ],
3915
- mappingDispositions: d.dispositions
3916
- };
3917
- }
3918
- function Da(e, t) {
3919
- const n = e.dashboardInputContext;
3920
- if (!n) return [];
3921
- const o = new Set(
3922
- t.flatMap(
3923
- (i) => i.status === "skip" && (i.reason === "explicitlyExcluded" || i.reason === "outsideScope") ? [i.inputId] : []
3924
- )
3925
- ), r = new Map(n.inputs.map((i) => [i.id, i]));
3926
- return n.resolvedInputs.flatMap((i) => {
3927
- if (!i.missingRequiredValue) return [];
3928
- const s = r.get(i.id);
3929
- return s ? s.kind === "filter" && (!e.shouldApplyDashboardFilters && !mn(s) || o.has(s.id)) ? [] : [i.label] : [];
3930
- });
3931
- }
3932
- function Sa({
3933
- card: e,
3934
- cardConfig: t,
3935
- input: n,
3936
- resolvedPrimaryDateField: o,
3937
- resolvedFields: r,
3938
- semanticExecutionPayload: i,
3939
- timezone: s,
3940
- allowMinutePrecision: a
3941
- }) {
3942
- var m;
3943
- const c = n.dashboardInputContext ? n.dashboardInputContext.inputs.flatMap(
3944
- (y) => y.kind === "filter" ? [y.filter] : []
3945
- ) : [], l = Se(e, n), d = Da(
3946
- n,
3947
- l.mappingDispositions
3948
- );
3949
- if (d.length)
3950
- return {
3951
- status: "blocked",
3952
- cardId: e.id,
3953
- reason: "requiredInput",
3954
- mappingDispositions: l.mappingDispositions,
3955
- missingRequiredLabels: d
3956
- };
3957
- if (l.status === "blocked")
3958
- return {
3959
- status: "blocked",
3960
- cardId: e.id,
3961
- reason: "mapping",
3962
- mappingDispositions: l.mappingDispositions,
3963
- missingRequiredLabels: []
3964
- };
3965
- const u = ca({
3966
- card: e,
3967
- cardConfig: t,
3968
- filters: c,
3969
- cardFilterValues: l.filterValues,
3970
- resolvedPrimaryDateField: o,
3971
- resolvedFields: r,
3972
- semanticExecutionPayload: i,
3973
- timezone: s,
3974
- allowMinutePrecision: a,
3975
- dateComparisonInputs: n.dateComparisonInputs,
3976
- mappedFilterValuesByInputId: new Map(
3977
- l.mappingDispositions.flatMap(
3978
- (y) => y.status === "apply" ? [[y.inputId, y.filterValue]] : []
3979
- )
3980
- )
3981
- }), f = W(c), p = !!(f && u.cardFilterValues.some(
3982
- (y) => y.filterId === f.id
3983
- )), g = u.resolvedPrimaryDateField && !((m = e.sql) != null && m.trim()) ? u.dateComparisonPlan.inputs.length ? Ca({
3984
- card: e,
3985
- resolution: u.dateComparisonPlan.resolution
3986
- }) : p ? ro(
3987
- e,
3988
- n.globalDateComparisonSelection
3989
- ) : void 0 : void 0;
3990
- return {
3991
- status: "ready",
3992
- ...u,
3993
- queryFilterDefinitions: c,
3994
- globalDateComparison: g,
3995
- mappingDispositions: l.mappingDispositions
3996
- };
3997
- }
3998
- function Ta({
3999
- card: e,
4000
- dashboard: t,
4001
- transientContexts: n,
4002
- cardViewState: o,
4003
- viewerTableSettings: r,
4004
- adHocFilterValues: i,
4005
- selectedSheetId: s,
4006
- inlineFilterValuesMap: a,
4007
- dashboardControls: c,
4008
- dashboardControlValues: l,
4009
- cardControlValuesMap: d,
4010
- dashboardInputContext: u,
4011
- includeAuthoredFilters: f
4012
- }) {
4013
- var q, L, G;
4014
- const p = kn(t);
4015
- for (const j of e.controlBindings || [])
4016
- Te(j) && p.add(j.controlId);
4017
- const { shouldApplyDashboardFilters: g } = ya(n), m = u != null && u.inputs.length ? u : void 0, y = ((u == null ? void 0 : u.selections) ?? []).filter(
4018
- (j) => j.status === "apply"
4019
- ), b = to(e, {
4020
- includeAuthoredFilters: f,
4021
- selections: y,
4022
- drill: o == null ? void 0 : o.drill
4023
- }), I = {
4024
- adHocFilterValues: i || [],
4025
- selectedSheetId: s,
4026
- inlineFilterValues: (a == null ? void 0 : a[e.id]) || [],
4027
- // Outside the input-context gate: a dashboard whose only input is a
4028
- // click still sends them.
4029
- selectionFilterValues: y.flatMap((j) => j.filterValues),
4030
- shouldApplyDashboardFilters: g,
4031
- ...m ? {
4032
- dashboardInputContext: {
4033
- inputs: m.inputs,
4034
- resolvedInputs: m.resolvedInputs,
4035
- activeFilters: m.activeFilters
4036
- }
4037
- } : {},
4038
- ...m != null && m.globalDateComparisonSelection ? {
4039
- globalDateComparisonSelection: m.globalDateComparisonSelection
4040
- } : {},
4041
- ...m != null && m.dateComparisonInputs ? {
4042
- dateComparisonInputs: m.dateComparisonInputs
4043
- } : {}
4044
- }, v = Se(e, I), M = {
4045
- filterValues: v.status === "ready" ? v.filterValues : [],
4046
- selectionFilters: b.selections
4047
- }, C = Bt(M), w = Ks(o == null ? void 0 : o.zoom, (q = e.config) == null ? void 0 : q.groupByColumns, C), B = w ? { ...b, zoom: w.filterGroup } : b, T = w ? Bt({ ...M, zoom: w.zoom }) : C, D = eo(B), V = f === !1 ? Pe(D, !0) : D, O = ga(
4048
- e,
4049
- o == null ? void 0 : o.drill,
4050
- V
4051
- ), x = _s(O, o == null ? void 0 : o.grainPick, {
4052
- currentFingerprint: T,
4053
- drillActive: (((L = o == null ? void 0 : o.drill) == null ? void 0 : L.steps.length) ?? 0) > 0
4054
- }), S = bs({ ...e, config: x }, r) ?? x, k = Sn(S, {
4055
- cardType: e.type,
4056
- dataSource: e.dataSource,
4057
- temporalResultOwner: Wt({
4058
- hasExecutableConfig: Me(S, e.type),
4059
- sql: e.sql,
4060
- normalizedPython: He(e.python || "")
4061
- })
4062
- }) || S, A = ma(V) || "", E = m ? no(
4063
- e,
4064
- {
4065
- controlValues: m.controlValues,
4066
- controlDefinitions: m.controlDefinitions,
4067
- cardControlDefinitions: m.cardControlDefinitions,
4068
- controlBindings: m.controlBindings
4069
- },
4070
- p
4071
- ) : ba({
4072
- card: e,
4073
- presentationControlIds: p,
4074
- dashboardControls: c,
4075
- dashboardControlValues: l,
4076
- cardControlValues: d == null ? void 0 : d[e.id]
4077
- });
4078
- return {
4079
- filterCompilationInput: I,
4080
- ...E,
4081
- resolvedFilters: V,
4082
- resolvedFilterParts: B,
4083
- drillSteps: ((G = o == null ? void 0 : o.drill) == null ? void 0 : G.steps) ?? or,
4084
- dateContextKey: T,
4085
- zoomContextKey: C,
4086
- ...w ? { activeZoom: w.zoom } : {},
4087
- finalConfig: S,
4088
- queryRelevantConfig: k,
4089
- finalFiltersKey: A
4090
- };
4091
- }
4092
- function io(e, t, n) {
4093
- const o = Sa({
4094
- resolvedFields: t.resolvedDateFields,
4095
- ...n,
4096
- card: e,
4097
- cardConfig: t.queryRelevantConfig,
4098
- input: t.filterCompilationInput
4099
- });
4100
- if (o.status === "blocked") return o;
4101
- const { filterCompilationInput: r, ...i } = t;
4102
- return { status: "ready", queryContext: {
4103
- ...i,
4104
- cardFilterValues: o.cardFilterValues,
4105
- queryFilterDefinitions: o.queryFilterDefinitions,
4106
- resolvedPrimaryDateField: o.resolvedPrimaryDateField,
4107
- globalDateComparison: o.globalDateComparison,
4108
- globalDateComparisonSelection: r.globalDateComparisonSelection,
4109
- dateComparisonInputs: r.dateComparisonInputs
4110
- }, compiledFilters: o };
4111
- }
4112
- function Ma(e, t, n) {
4113
- const o = rr(e), r = io(e, t, {
4114
- resolvedPrimaryDateField: n.resolvedPrimaryDateField,
4115
- timezone: n.calendarContext.tz,
4116
- allowMinutePrecision: n.allowGlobalDateMinutePrecision
4117
- });
4118
- if (r.status === "blocked")
4119
- return { ...r, tableConfig: o };
4120
- const { compiledFilters: i } = r, {
4121
- cardFilterValues: s,
4122
- resolvedPrimaryDateField: a,
4123
- globalDateComparison: c
4124
- } = i, { queryKey: l, queryInputIdentity: d, paginationConfig: u } = rs(
4125
- e,
4126
- r.queryContext,
4127
- n.calendarContext,
4128
- { resolvePaginationConfig: n.resolvePaginationConfig }
4129
- ), f = t.queryRelevantConfig, p = He(e.python || ""), g = Wt({
4130
- hasExecutableConfig: Me(f, e.type),
4131
- sql: e.sql,
4132
- normalizedPython: p
4133
- });
4134
- return {
4135
- status: "ready",
4136
- queryKey: l,
4137
- queryInputIdentity: d,
4138
- paginationConfig: u,
4139
- tableConfig: o,
4140
- compiledFilters: i,
4141
- requestPayloadBase: {
4142
- cardId: e.id,
4143
- sql: (e == null ? void 0 : e.sql) || "",
4144
- python: p,
4145
- resultOwner: g,
4146
- active_filters: s,
4147
- controlValues: t.controlValues,
4148
- controlDefinitions: t.controlDefinitions,
4149
- cardControlDefinitions: t.cardControlDefinitions,
4150
- controlBindings: t.controlBindings,
4151
- cache_config: n.globalCacheConfig,
4152
- queryConfig: e.queryConfig,
4153
- tableConfig: o,
4154
- cardType: e.type,
4155
- cardTitle: e.title || "",
4156
- cardConfig: f,
4157
- cardDataSource: e.dataSource,
4158
- resolvedPrimaryDateField: a || void 0,
4159
- calendarContext: n.calendarContext,
4160
- ...c ? { globalDateComparison: c } : {},
4161
- ...t.sqlRowLimit ? { sqlRowLimit: t.sqlRowLimit } : {}
4162
- }
4163
- };
4164
- }
4165
- const Kt = [], Va = [], ka = {};
4166
- function rc(e, t) {
4167
- return {
4168
- sheetId: e.sheetId,
4169
- sectionId: e.sectionId,
4170
- documentFilterValues: e.documentFilterValues ?? Kt,
4171
- documentControlDefinitions: e.documentControlDefinitions ?? Va,
4172
- documentControlValues: e.documentControlValues ?? ka,
4173
- editorFilterValues: t ?? Kt
4174
- };
4175
- }
4176
- function Pa({
4177
- card: e,
4178
- dashboard: t,
4179
- runtime: n,
4180
- dashboardRuntimeValues: o,
4181
- calendar: r
4182
- }) {
4183
- const i = Yt({
4184
- dashboard: t,
4185
- dashboardInputValues: o.dashboardInputValues,
4186
- transientContexts: void 0
4187
- }) ? We({
4188
- transientContexts: void 0,
4189
- dashboard: t,
4190
- sheetId: n.sheetId,
4191
- sheetKind: "document",
4192
- sectionId: n.sectionId,
4193
- card: e,
4194
- runtimeValues: {
4195
- ...o,
4196
- dashboardInputValues: n.documentDashboardInputValues || o.dashboardInputValues
4197
- },
4198
- calendar: r
4199
- }) : void 0, s = i && (i.inputs.length > 0 || i.selections.length > 0) ? i : void 0, a = !!(i != null && i.inputs.length), c = [
4200
- ...n.editorFilterValues || [],
4201
- ...n.documentFilterValues
4202
- ];
4203
- return {
4204
- card: a ? e : xa(
4205
- e,
4206
- n.documentControlDefinitions
4207
- ),
4208
- dashboard: t,
4209
- transientContexts: void 0,
4210
- // Document section cards do not drill.
4211
- cardViewState: void 0,
4212
- // Document section cards are not viewer-customizable tables.
4213
- viewerTableSettings: void 0,
4214
- adHocFilterValues: [],
4215
- inlineFilterValuesMap: !a && c.length ? { [e.id]: c } : {},
4216
- dashboardControls: [],
4217
- dashboardControlValues: {},
4218
- cardControlValuesMap: !a && Object.keys(n.documentControlValues).length > 0 ? { [e.id]: n.documentControlValues } : {},
4219
- dashboardInputContext: s
4220
- };
4221
- }
4222
- function xa(e, t) {
4223
- if (t.length === 0)
4224
- return e;
4225
- const n = /* @__PURE__ */ new Map();
4226
- for (const o of e.controls || [])
4227
- n.set(o.id, o);
4228
- for (const o of t)
4229
- n.set(o.id, o);
4230
- return {
4231
- ...e,
4232
- controls: Array.from(n.values())
4233
- };
4234
- }
4235
- function ic({
4236
- card: e,
4237
- place: t,
4238
- source: n
4239
- }) {
4240
- const o = je(e, t, n);
4241
- return {
4242
- card: o.card,
4243
- context: o.context,
4244
- inputContext: o.inputContext
4245
- };
4246
- }
4247
- function wa(e, t, n) {
4248
- return {
4249
- calendarContext: n ?? Nr,
4250
- allowGlobalDateMinutePrecision: Je(
4251
- e,
4252
- t
4253
- ).allEligibleTargetsAreDateTime,
4254
- semanticExecutionPayload: t,
4255
- globalCacheConfig: e.globalCacheConfig
4256
- };
4257
- }
4258
- function sc(e, t) {
4259
- return lo(
4260
- e,
4261
- t,
4262
- t.allowGlobalDateMinutePrecision
4263
- );
4264
- }
4265
- function Oa(e, t, n = {}) {
4266
- const o = ao(e, t);
4267
- return {
4268
- ...Ma(e.card, e.context, {
4269
- resolvedPrimaryDateField: o,
4270
- calendarContext: t.calendarContext,
4271
- allowGlobalDateMinutePrecision: t.allowGlobalDateMinutePrecision,
4272
- globalCacheConfig: t.globalCacheConfig,
4273
- resolvePaginationConfig: n.resolvePaginationConfig
4274
- }),
4275
- resolvedPrimaryDateField: o
4276
- };
4277
- }
4278
- function Ba({
4279
- card: e,
4280
- place: t,
4281
- source: n,
4282
- semanticExecutionPayload: o,
4283
- matrixCatalog: r,
4284
- withRequest: i = !1
4285
- }) {
4286
- var m, y;
4287
- const { dashboard: s } = n, a = e.id, c = (b, I) => {
4288
- var M;
4289
- let v;
4290
- try {
4291
- const C = Ge(b);
4292
- if (C.status === "invalid") throw C.error;
4293
- const w = je(
4294
- b,
4295
- I,
4296
- n,
4297
- C.status === "absent"
4298
- );
4299
- if (v = w.context, C.status === "absent")
4300
- return { status: "ready", value: { assembled: w } };
4301
- if (!r)
4302
- return {
4303
- status: "blocked",
4304
- reason: "metadata",
4305
- message: "Matrix field metadata is required.",
4306
- context: v
4307
- };
4308
- const B = xs(C.config.spec, v), T = r.filter(
4309
- (k) => k.field.source && B.some(
4310
- (A) => _e(A, k.field.source)
4311
- )
4312
- ), D = ua(b, T, v), { params: V } = w, O = V.dashboardInputContext;
4313
- D.config = {
4314
- ...D.config,
4315
- presentation: zi(
4316
- b,
4317
- D.config,
4318
- {
4319
- controls: O ? [
4320
- ...O.controlDefinitions,
4321
- ...O.cardControlDefinitions
4322
- ] : [
4323
- ...V.dashboardControls ?? s.controls ?? [],
4324
- ...V.card.controls ?? []
4325
- ],
4326
- values: (O == null ? void 0 : O.controlValues) ?? {
4327
- ...V.dashboardControlValues,
4328
- ...(M = V.cardControlValuesMap) == null ? void 0 : M[b.id]
4329
- }
4330
- },
4331
- T
4332
- )
4333
- };
4334
- const x = {
4335
- ...b,
4336
- config: { matrix: D.config }
4337
- }, S = je(x, I, n, !1);
4338
- return {
4339
- status: "ready",
4340
- value: {
4341
- assembled: {
4342
- card: x,
4343
- context: { ...S.context, resolvedDateFields: D.fields },
4344
- inputContext: S.inputContext
4345
- },
4346
- matrix: D
4347
- }
4348
- };
4349
- } catch (C) {
4350
- return {
4351
- status: "blocked",
4352
- reason: "configuration",
4353
- message: C instanceof Error ? C.message : "Card configuration is invalid.",
4354
- context: v
4355
- };
4356
- }
4357
- }, l = c(e, t);
4358
- if (l.status === "blocked")
4359
- return {
4360
- status: "blocked",
4361
- cardId: a,
4362
- mappingDispositions: [],
4363
- reason: l.reason,
4364
- missingRequiredLabels: [],
4365
- message: l.message
4366
- };
4367
- const { assembled: d, matrix: u } = l.value, f = wa(
4368
- s,
4369
- o,
4370
- n.calendar
4371
- ), p = d.context.filterCompilationInput, g = sr(s);
4372
- try {
4373
- const b = Se(d.card, p), I = u && g && b.status === "ready" && b.filterValues.some((w) => w.filterId === g.id);
4374
- let v = f.allowGlobalDateMinutePrecision;
4375
- if (I) {
4376
- const w = (m = p.dashboardInputContext) == null ? void 0 : m.inputs.find(
4377
- (S) => S.kind === "filter" && S.filter.id === g.id
4378
- ), T = ar(s, g).filter(
4379
- ({ card: S, sheet: k }) => !w || Er(w, {
4380
- cardId: S.id,
4381
- sheetId: k.id,
4382
- sheetKind: Zt(k) ? "document" : "dashboard"
4383
- })
4384
- ).map(({ card: S, sheet: k }) => ({
4385
- card: S,
4386
- value: S.id === a ? l : c(S, { kind: "sheet", sheetId: k.id })
4387
- })), D = new Map(
4388
- T.map(({ card: S, value: k }) => [
4389
- S.id,
4390
- k.status === "ready" ? k.value.assembled.card : null
4391
- ])
4392
- ), V = new Map(
4393
- T.map(({ card: S, value: k }) => {
4394
- var A;
4395
- return [
4396
- S.id,
4397
- k.status === "ready" ? (A = k.value.matrix) == null ? void 0 : A.fields : void 0
4398
- ];
4399
- })
4400
- ), O = T.flatMap(
4401
- ({ card: S, value: k }) => {
4402
- const A = S.id, E = k.status === "ready" ? k.value.assembled.context : k.context;
4403
- if (!E) return [A];
4404
- const q = k.status === "ready" ? k.value.assembled.card : S;
4405
- try {
4406
- const L = Se(
4407
- q,
4408
- E.filterCompilationInput
4409
- );
4410
- return L.status === "blocked" || L.filterValues.some((G) => G.filterId === g.id) ? [A] : [];
4411
- } catch {
4412
- return D.set(A, null), [A];
4413
- }
4414
- }
4415
- ), x = Je(
4416
- s,
4417
- o,
4418
- g,
4419
- D,
4420
- V,
4421
- O
4422
- );
4423
- if ((y = x.unresolvedCardIds) != null && y.length)
4424
- return {
4425
- status: "blocked",
4426
- cardId: a,
4427
- mappingDispositions: [],
4428
- reason: "coverage",
4429
- missingRequiredLabels: [],
4430
- message: `Date precision requires field metadata and valid inputs for: ${x.unresolvedCardIds.join(", ")}.`
4431
- };
4432
- v = x.allEligibleTargetsAreDateTime;
4433
- }
4434
- const M = lo(d, f, v);
4435
- if (M.status === "blocked")
4436
- return {
4437
- status: "blocked",
4438
- cardId: M.cardId,
4439
- mappingDispositions: M.mappingDispositions,
4440
- reason: M.reason,
4441
- missingRequiredLabels: M.missingRequiredLabels,
4442
- ...M.reason === "requiredInput" ? { message: Ia(M.missingRequiredLabels) } : {},
4443
- ...M.resolvedPrimaryDateField ? { resolvedPrimaryDateField: M.resolvedPrimaryDateField } : {}
4444
- };
4445
- const C = i && !u ? Oa(d, f) : void 0;
4446
- return {
4447
- ...M,
4448
- ...u ? { matrix: u } : {},
4449
- // The whole request a card runs with: the contract's payload and its
4450
- // extras (server pagination, table totals) from the one extras owner,
4451
- // on the first page a new viewer opens (ledger P3-78).
4452
- ...(C == null ? void 0 : C.status) === "ready" ? {
4453
- request: {
4454
- ...C.requestPayloadBase,
4455
- ...Ss({
4456
- card: d.card,
4457
- finalConfig: d.context.finalConfig,
4458
- documentSection: t.kind === "documentSection" ? {} : void 0,
4459
- page: Ds(d.card)
4460
- })
4461
- }
4462
- } : {}
4463
- };
4464
- } catch (b) {
4465
- return {
4466
- status: "blocked",
4467
- cardId: a,
4468
- mappingDispositions: [],
4469
- reason: "configuration",
4470
- missingRequiredLabels: [],
4471
- message: b instanceof Error ? b.message : "Card filter configuration is invalid."
4472
- };
4473
- }
4474
- }
4475
- function Aa(e) {
4476
- const t = e.editor ? {
4477
- ...e.inlineFilterValuesMap,
4478
- ...Object.fromEntries(
4479
- Object.entries(e.editor.inlineFilterValuesMap).filter(
4480
- (n) => n[1] !== void 0
4481
- )
4482
- )
4483
- } : e.inlineFilterValuesMap;
4484
- return {
4485
- dashboardInputValues: e.dashboardInputValues,
4486
- adHocFilterValues: e.adHocFilterValues,
4487
- controlValues: e.controlValues,
4488
- inlineFilterValuesMap: t,
4489
- cardControlValuesMap: e.cardControlValuesMap
4490
- };
4491
- }
4492
- function je(e, t, n, o) {
4493
- var l, d;
4494
- const { dashboard: r } = n, i = Aa(n), s = t.kind === "documentSection" ? {
4495
- ...Pa({
4496
- card: e,
4497
- dashboard: r,
4498
- runtime: t.section,
4499
- dashboardRuntimeValues: i,
4500
- calendar: n.calendar
4501
- }),
4502
- selectedSheetId: t.section.sheetId,
4503
- includeAuthoredFilters: o
4504
- } : Ea(e, t.sheetId, n, i, o), a = Ta(s), c = (l = e.config) == null ? void 0 : l.rowLimit;
4505
- return (d = e.sql) != null && d.trim() && c && so(r, e.id) && (a.sqlRowLimit = c), {
4506
- card: s.card,
4507
- params: s,
4508
- context: a,
4509
- inputContext: s.dashboardInputContext
4510
- };
4511
- }
4512
- function so(e, t) {
4513
- return (e.variables ?? []).some((n) => n.id === t);
4514
- }
4515
- function Ea(e, t, n, o, r) {
4516
- var l, d, u;
4517
- const { dashboard: i } = n, s = so(i, e.id), a = s ? void 0 : n.transientContexts, c = Yt({
4518
- dashboard: i,
4519
- dashboardInputValues: o.dashboardInputValues,
4520
- transientContexts: a
4521
- }) ? We({
4522
- transientContexts: a,
4523
- dashboard: i,
4524
- sheetId: t,
4525
- card: e,
4526
- runtimeValues: o,
4527
- calendar: n.calendar
4528
- }) : void 0;
4529
- return {
4530
- card: e,
4531
- dashboard: i,
4532
- transientContexts: a,
4533
- // The editor previews the card without a viewer's zoom (chart date zoom
4534
- // DZ-D1): it shows the dashboard's dates, and its save never sees one.
4535
- cardViewState: s ? void 0 : n.editor ? ir((l = n.cardViewStates) == null ? void 0 : l[e.id], null) : (d = n.cardViewStates) == null ? void 0 : d[e.id],
4536
- viewerTableSettings: n.editor || s || (u = n.viewerTableSettings) == null ? void 0 : u[e.id],
4537
- adHocFilterValues: s ? [] : o.adHocFilterValues,
4538
- selectedSheetId: t,
4539
- inlineFilterValuesMap: o.inlineFilterValuesMap,
4540
- dashboardControls: i.controls,
4541
- dashboardControlValues: o.controlValues,
4542
- cardControlValuesMap: o.cardControlValuesMap,
4543
- // Keep a selection-only context so the query has one resolved-input contract.
4544
- dashboardInputContext: c && (c.inputs.length > 0 || c.selections.length > 0) ? c : void 0,
4545
- includeAuthoredFilters: r
4546
- };
4547
- }
4548
- function ao({ card: e, context: t }, n) {
4549
- return $t({
4550
- card: e,
4551
- cardConfig: t.queryRelevantConfig,
4552
- resolvedFields: t.resolvedDateFields,
4553
- semanticExecutionPayload: n.semanticExecutionPayload
4554
- });
4555
- }
4556
- function lo(e, t, n) {
4557
- const { card: o } = e, r = ao(e, t), i = io(o, e.context, {
4558
- resolvedPrimaryDateField: r,
4559
- timezone: t.calendarContext.tz,
4560
- allowMinutePrecision: n
4561
- });
4562
- return i.status === "blocked" ? { ...i, card: o, resolvedPrimaryDateField: r } : {
4563
- status: "ready",
4564
- card: o,
4565
- queryContext: i.queryContext,
4566
- compiledFilters: i.compiledFilters,
4567
- resolvedPrimaryDateField: r
4568
- };
4569
- }
4570
- function ac({
4571
- dashboard: e,
4572
- dashboardInputValues: t,
4573
- adHocFilterValues: n,
4574
- calendar: o,
4575
- selectedSheetId: r,
4576
- sheetSelection: i = "current",
4577
- dashboardControlValues: s,
4578
- cardControlValuesMap: a,
4579
- semanticExecutionPayload: c,
4580
- timezone: l
4581
- }) {
4582
- const d = e ? [...lr(e)] : void 0, u = r ?? null, f = (I) => {
4583
- var v;
4584
- return e ? Ka({
4585
- dashboard: e,
4586
- runtimeValues: { dashboardInputValues: t },
4587
- adHocFilterValues: n,
4588
- sheetId: I,
4589
- sheetKind: Zt(
4590
- (v = e.sheets) == null ? void 0 : v.find((M) => M.id === I)
4591
- ) ? "document" : "dashboard",
4592
- calendar: o
4593
- }) : [];
4594
- }, p = i === "all" ? Array.from(
4595
- new Map(
4596
- ((e == null ? void 0 : e.sheets) || []).flatMap(
4597
- (I) => f(I.id).map(
4598
- (v) => [v.filterId, v]
4599
- )
4600
- )
4601
- ).values()
4602
- ) : f(u), g = {
4603
- ...s || {}
4604
- }, m = i === "all" ? Q({ sheets: (e == null ? void 0 : e.sheets) || [] }) : u ? Q({ sheets: (e == null ? void 0 : e.sheets) || [] }).filter(
4605
- (I) => I.sheet.id === u
4606
- ) : [];
4607
- for (const I of m)
4608
- Object.assign(g, (a == null ? void 0 : a[I.card.id]) || {});
4609
- const y = cr({
4610
- filterDefinitions: d,
4611
- filterValues: p
4612
- }), b = ia({
4613
- filters: d,
4614
- filterValues: y,
4615
- dashboard: e,
4616
- semanticExecutionPayload: c,
4617
- timezone: l
4618
- });
4619
- return {
4620
- selectedSheetId: u,
4621
- filterValues: b,
4622
- controlValues: g
4623
- };
4624
- }
4625
- function lc({
4626
- dashboard: e,
4627
- cardId: t,
4628
- transientContexts: n,
4629
- cardViewStates: o,
4630
- viewerTableSettings: r,
4631
- semanticExecutionPayload: i,
4632
- adHocFilterValues: s,
4633
- inlineFilterValuesMap: a,
4634
- dashboardControlValues: c,
4635
- cardControlValuesMap: l,
4636
- dashboardInputValues: d,
4637
- calendar: u,
4638
- matrixCatalog: f,
4639
- cardOverride: p,
4640
- sheetId: g,
4641
- documentSection: m,
4642
- editor: y,
4643
- withRequest: b
4644
- }) {
4645
- var M;
4646
- if (!e)
4647
- return null;
4648
- p && !Ft(e, t) && g && (e = { ...e, sheets: (M = e.sheets) == null ? void 0 : M.map((C) => C.id === g ? { ...C, cards: [...C.cards ?? [], p] } : C) });
4649
- const I = Ft(e, t);
4650
- if (!I)
4651
- return null;
4652
- const v = Ba({
4653
- card: p ?? I.card,
4654
- place: m ? { kind: "documentSection", section: m } : { kind: "sheet", sheetId: I.sheet.id },
4655
- source: {
4656
- dashboard: e,
4657
- adHocFilterValues: s,
4658
- controlValues: c,
4659
- inlineFilterValuesMap: a,
4660
- cardControlValuesMap: l ? Object.fromEntries(
4661
- Object.entries(l).filter(
4662
- (C) => C[1] !== void 0
4663
- )
4664
- ) : void 0,
4665
- dashboardInputValues: d,
4666
- transientContexts: n,
4667
- cardViewStates: o,
4668
- viewerTableSettings: r,
4669
- calendar: u,
4670
- ...y ? { editor: y } : {}
4671
- },
4672
- semanticExecutionPayload: i,
4673
- matrixCatalog: f,
4674
- withRequest: b
4675
- });
4676
- return v.status === "blocked" ? v : {
4677
- status: "ready",
4678
- card: p ?? I.card,
4679
- sheetId: I.sheet.id,
4680
- queryContext: v.queryContext,
4681
- compiledFilters: v.compiledFilters,
4682
- resolvedPrimaryDateField: v.resolvedPrimaryDateField,
4683
- ...v.matrix ? { matrix: v.matrix } : {},
4684
- ...v.request ? { request: v.request } : {}
4685
- };
4686
- }
4687
- function _a(e, t, n) {
4688
- const o = t === "date" && "relativeMeta" in e ? Fr(e.relativeMeta) : void 0;
4689
- if (!o) return { values: e.values };
4690
- const r = mr(o, n ?? void 0), i = e.operation === "between" || e.operation === "not between";
4691
- return {
4692
- values: r && i ? r : e.values,
4693
- relativeMeta: o,
4694
- ..."temporalPrecision" in e && e.temporalPrecision === "minute" ? { temporalPrecision: "minute" } : {}
4695
- };
4696
- }
4697
- function Ra(e, t, n) {
4698
- const o = t, r = ur(e);
4699
- return fr({
4700
- definition: e,
4701
- sourceValue: o,
4702
- value: {
4703
- filterId: o.filterId,
4704
- name: e.column,
4705
- operation: o.operation ?? e.operation,
4706
- valueType: r,
4707
- dataType: e.dataType,
4708
- fieldMeta: e.fieldMeta,
4709
- semanticContext: e.semanticContext,
4710
- ..._a(o, r, n)
4711
- }
4712
- });
4713
- }
4714
- function co(e, t, n) {
4715
- const o = N(e);
4716
- let r = {};
4717
- const i = [], s = [];
4718
- for (const a of t ?? []) {
4719
- if (qr(a.filterId)) {
4720
- s.push(a.filterId);
4721
- continue;
4722
- }
4723
- const c = o.findFilterInput({ filterId: a.filterId }), l = c == null ? void 0 : c.input;
4724
- if (l || i.push(a), !l || l.runtimeScope === "perCard" || l.runtimeScope === "perDocumentSection") {
4725
- s.push(a.filterId);
4726
- continue;
4727
- }
4728
- const d = dr(
4729
- Ra(l.filter, a, n.calendar)
4730
- );
4731
- if (d) {
4732
- if (l.runtimeScope === "shared") {
4733
- r = Ct(r, l, {}, d);
4734
- continue;
4735
- }
4736
- for (const u of pn(e).values())
4737
- gn(l, u) && (r = Ct(
4738
- r,
4739
- l,
4740
- { sheetId: u.sheetId },
4741
- d
4742
- ));
4743
- }
4744
- }
4745
- return { slots: r, adHocFilterValues: i, droppedFilterIds: s };
4746
- }
4747
- function Ka(e) {
4748
- const { dashboard: t, sheetId: n } = e, o = [];
4749
- if (n)
4750
- for (const { input: r } of pr(t, n, e.sheetKind)) {
4751
- const i = gr({
4752
- dashboard: t,
4753
- input: r,
4754
- runtimeValues: { dashboardInputValues: e.runtimeValues.dashboardInputValues },
4755
- target: { sheetId: n },
4756
- calendar: e.calendar
4757
- });
4758
- i.kind === "filter" && i.filterValue && o.push(i.filterValue);
4759
- }
4760
- return [...o, ...oo(e.adHocFilterValues, n)];
4761
- }
4762
- function cc(e, t) {
4763
- switch (t.runtimeScope) {
4764
- case "shared":
4765
- return [{}];
4766
- case "perSheet":
4767
- return [...pn(e).values()].filter((n) => gn(t, n)).map((n) => ({ sheetId: n.sheetId }));
4768
- case "perCard": {
4769
- const n = N(e);
4770
- return [
4771
- ...n.reachedCards({ inputId: t.id }).map((o) => ({ sheetId: o.sheetId, cardId: o.cardId })),
4772
- // A variable holds a value at each place it is used (DV-D35).
4773
- ...n.reachedVariables({ inputId: t.id }).flatMap(
4774
- (o) => o.places.map((r) => ({ sheetId: r.sheetId, cardId: o.variableId }))
4775
- )
4776
- ];
4777
- }
4778
- case "perDocumentSection": {
4779
- const n = /* @__PURE__ */ new Map();
4780
- for (const o of N(e).reachedCards({ inputId: t.id }))
4781
- o.kind === "documentSectionCard" && n.set(o.sectionId, { sheetId: o.sheetId, sectionId: o.sectionId });
4782
- return [...n.values()];
4783
- }
4784
- default:
4785
- return [];
4786
- }
4787
- }
4788
- function qt(e) {
4789
- var t;
4790
- return [
4791
- ...e.cards ?? [],
4792
- ...(e.frames ?? []).flatMap((n) => n.cards),
4793
- ...(((t = e.document) == null ? void 0 : t.sections) ?? []).flatMap(
4794
- (n) => yn(n)
4795
- )
4796
- ];
4797
- }
4798
- function qa(e, t) {
4799
- var n, o;
4800
- return {
4801
- sheetId: e.id,
4802
- cardId: t.id,
4803
- sheetKind: e.kind ?? "dashboard",
4804
- sectionId: (o = (n = e.document) == null ? void 0 : n.sections.find(
4805
- (r) => yn(r).some(({ id: i }) => i === t.id)
4806
- )) == null ? void 0 : o.id
4807
- };
4808
- }
4809
- function Na(e, t, n, o) {
4810
- var l, d, u;
4811
- const r = {}, i = (l = e.preferences) == null ? void 0 : l.textVisualOptions;
4812
- if (!i) return r;
4813
- const s = We({
4814
- // Authoring: carried drill context never applies to a dashboard being edited.
4815
- transientContexts: void 0,
4816
- dashboard: n,
4817
- ...qa(o, t),
4818
- card: t,
4819
- runtimeValues: {},
4820
- // Aliases only: no input value is read.
4821
- calendar: null
4822
- }), a = (f) => {
4823
- if (f.source !== "dashboardInputAlias") return f;
4824
- const p = s.variablesByName[f.variableName], g = p ? {
4825
- source: "input",
4826
- inputId: p.id,
4827
- export: f.export ?? "label"
4828
- } : f;
4829
- return p && (r[f.variableName] = g), g;
4830
- }, c = (f) => {
4831
- Object.assign(f, on(f, (p) => a(p))), f.type === "link" && [...f.children, ...Array.isArray(f.url) ? f.url : []].forEach((p) => c(p)), f.type === "when" && [...f.then ?? [], ...f.else ?? []].forEach(c);
4832
- };
4833
- return (d = i.content) == null || d.forEach((f) => {
4834
- f.type === "variable" && (f.ref = a(f.ref));
4835
- }), (u = i.richContent) == null || u.blocks.forEach((f) => {
4836
- f.type === "list" ? f.items.forEach((p) => p.forEach(c)) : f.children.forEach(c);
4837
- }), r;
4838
- }
4839
- function La(e, t) {
4840
- var i;
4841
- const n = qt(e);
4842
- if (!n.some((s) => {
4843
- var a;
4844
- return (a = s.preferences) == null ? void 0 : a.textVisualOptions;
4845
- }))
4846
- return e;
4847
- const o = Ce(e), r = qt(o);
4848
- for (let s = 0; s < r.length; s++) {
4849
- const a = Na(
4850
- r[s],
4851
- n[s],
4852
- t,
4853
- e
4854
- );
4855
- (i = e.frames) != null && i.some(
4856
- (c) => c.visualId && c.cards.some((l) => l.id === r[s].id)
4857
- ) && (r[s].linkedReferenceOverrides = ci(
4858
- r[s].linkedReferenceOverrides,
4859
- { inputAliases: a }
4860
- ));
4861
- }
4862
- return o;
4863
- }
4864
- function ja(e) {
4865
- var n;
4866
- const t = (n = e.sheets) == null ? void 0 : n.map(
4867
- (o) => La(o, e)
4868
- );
4869
- return t && t.some((o, r) => o !== e.sheets[r]) ? { ...e, sheets: t } : e;
4870
- }
4871
- function za(e) {
4872
- const t = N(e);
4873
- return t.issues.length === 0 && !t.needsUpgrade ? e : t.issues.length ? t.toStoredDashboard() : N(
4874
- ja(e)
4875
- ).toStoredDashboard();
4876
- }
4877
- export {
4878
- Jr as $,
4879
- co as A,
4880
- Ka as B,
4881
- cc as C,
4882
- ha as D,
4883
- oo as E,
4884
- ci as F,
4885
- dl as G,
4886
- hi as H,
4887
- ks as I,
4888
- wt as J,
4889
- Pl as K,
4890
- di as L,
4891
- Ml as M,
4892
- Ri as N,
4893
- _i as O,
4894
- Ai as P,
4895
- Cl as Q,
4896
- Vn as R,
4897
- qe as S,
4898
- pl as T,
4899
- Ni as U,
4900
- J as V,
4901
- Sl as W,
4902
- ji as X,
4903
- Tl as Y,
4904
- it as Z,
4905
- rt as _,
4906
- Xs as a,
4907
- zl as a$,
4908
- Il as a0,
4909
- Dl as a1,
4910
- Ki as a2,
4911
- bl as a3,
4912
- sc as a4,
4913
- wa as a5,
4914
- qt as a6,
4915
- qa as a7,
4916
- Na as a8,
4917
- La as a9,
4918
- ql as aA,
4919
- Nl as aB,
4920
- ce as aC,
4921
- In as aD,
4922
- ml as aE,
4923
- fl as aF,
4924
- yl as aG,
4925
- Ba as aH,
4926
- Di as aI,
4927
- gl as aJ,
4928
- nc as aK,
4929
- bn as aL,
4930
- vl as aM,
4931
- ec as aN,
4932
- Ll as aO,
4933
- qs as aP,
4934
- Xl as aQ,
4935
- Yn as aR,
4936
- Se as aS,
4937
- hl as aT,
4938
- da as aU,
4939
- Zn as aV,
4940
- Xe as aW,
4941
- Fl as aX,
4942
- wl as aY,
4943
- Cs as aZ,
4944
- re as a_,
4945
- is as aa,
4946
- Wl as ab,
4947
- Ql as ac,
4948
- Kn as ad,
4949
- Jl as ae,
4950
- Qi as af,
4951
- Ia as ag,
4952
- ac as ah,
4953
- ga as ai,
4954
- oc as aj,
4955
- ic as ak,
4956
- vs as al,
4957
- Fs as am,
4958
- Oa as an,
4959
- Ol as ao,
4960
- Bl as ap,
4961
- Ss as aq,
4962
- Le as ar,
4963
- Is as as,
4964
- Ts as at,
4965
- Al as au,
4966
- rc as av,
4967
- tc as aw,
4968
- _l as ax,
4969
- Kl as ay,
4970
- Rl as az,
4971
- Vl as b,
4972
- Zl as b0,
4973
- Yl as b1,
4974
- rs as c,
4975
- ya as d,
4976
- ai as e,
4977
- xl as f,
4978
- El as g,
4979
- $l as h,
4980
- kl as i,
4981
- Hl as j,
4982
- Ce as k,
4983
- Zs as l,
4984
- lc as m,
4985
- Ul as n,
4986
- at as o,
4987
- jl as p,
4988
- Ra as q,
4989
- Gl as r,
4990
- Ps as s,
4991
- xs as t,
4992
- ui as u,
4993
- pi as v,
4994
- Cn as w,
4995
- ul as x,
4996
- yi as y,
4997
- za as z
4998
- };