react-semaphor 0.1.560 → 0.1.561

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 (107) hide show
  1. package/dist/analytics-protocol/index.js +353 -349
  2. package/dist/assistant-context/index.js +1 -1
  3. package/dist/assistant-protocol/index.js +5 -5
  4. package/dist/brand-studio/index.js +9 -9
  5. package/dist/briefings/index.js +5 -5
  6. package/dist/chunks/{analytics-base-schemas-CHLxsPfX.js → analytics-base-schemas-CB3oFAXk.js} +199 -171
  7. package/dist/chunks/{assistant-chat-Bu2fFm_I.js → assistant-chat-DiVHY3Hw.js} +27 -28
  8. package/dist/chunks/bookmark-impact-CR09dpkn.js +75 -0
  9. package/dist/chunks/bookmark-state-BusLpkb7.js +743 -0
  10. package/dist/chunks/{braces-Da41xfUd.js → braces-u8VorWJc.js} +1 -1
  11. package/dist/chunks/{comparison-window-caption-4FNkMrzE.js → comparison-window-caption-DDsIWJYT.js} +108 -108
  12. package/dist/chunks/{context-BgPDzLHZ.js → context-TUjw9eqr.js} +1 -1
  13. package/dist/chunks/{custom-visual-inputs-Dz-enUNR.js → custom-visual-inputs-DfolidZ9.js} +1 -1
  14. package/dist/chunks/{dashboard-_MeBuy67.js → dashboard-BRdZBPqr.js} +1 -1
  15. package/dist/chunks/{dashboard-briefing-launcher-CEi4Pr_v.js → dashboard-briefing-launcher-CgvTLndW.js} +161 -162
  16. package/dist/chunks/{dashboard-controls-Bi7fyG-4.js → dashboard-controls-B4vfSzTF.js} +881 -945
  17. package/dist/chunks/{dashboard-json-B1mU_OMa.js → dashboard-json-Y3MF59g7.js} +5 -5
  18. package/dist/chunks/document-dashboard-inputs-CvBbFTUA.js +1718 -0
  19. package/dist/chunks/{edit-dashboard-visual-0CJN31Y3.js → edit-dashboard-visual-DwjZcxj-.js} +6112 -6146
  20. package/dist/chunks/{filter-reach-copy-BF4w4kI2.js → filter-reach-copy-bijwf_-b.js} +1250 -1392
  21. package/dist/chunks/{filter-value-text-CRC-K_l_.js → filter-value-text-DFnhwuEW.js} +3 -3
  22. package/dist/chunks/global-date-filter-utils-BXgCpvQM.js +15142 -0
  23. package/dist/chunks/{index-DtHidOPV.js → index-ClwbY3BL.js} +197 -198
  24. package/dist/chunks/{layout-grid-BvsH4RY2.js → layout-grid-CtvCBfOm.js} +1 -1
  25. package/dist/chunks/{list-filter-Dg0otx5E.js → list-filter-BklYgciR.js} +1 -1
  26. package/dist/chunks/{matrix-analytical-definition-CM18W8w6.js → matrix-analytical-definition-pU51-JmY.js} +4 -4
  27. package/dist/chunks/{matrix-card-HPskLaPy.js → matrix-card-CUorIB7Q.js} +3 -3
  28. package/dist/chunks/{matrix-member-presentation-Bbrfrke4.js → matrix-member-presentation-Df5UgCGN.js} +1 -1
  29. package/dist/chunks/{matrix-operation-contract-WPv4R-H_.js → matrix-operation-contract-BSiGEXVC.js} +255 -248
  30. package/dist/chunks/{metric-comparison-ljMKYZKa.js → metric-comparison-95aC0uEO.js} +6 -6
  31. package/dist/chunks/{model-change-Ccn1zaxl.js → model-change-B5wQhg5G.js} +1 -1
  32. package/dist/chunks/{palette-Bsh376zO.js → palette-DTnMhipt.js} +1 -1
  33. package/dist/chunks/pivot-result-contract-expectations-Bo-86vwS.js +56 -0
  34. package/dist/chunks/{pivot-result-identity-vS9TSh4f.js → pivot-result-identity-olvXJoB9.js} +1 -1
  35. package/dist/chunks/{report-preferences-dialog-BV8L0SeS.js → report-preferences-dialog-C2YUIwKG.js} +14 -14
  36. package/dist/chunks/{report-runtime-context-BZQh9ywy.js → report-runtime-context-DoIUr3MP.js} +2 -2
  37. package/dist/chunks/resolve-dashboard-input-context-q_iiNXE1.js +6503 -0
  38. package/dist/chunks/{save-B5EAsgQF.js → save-DH4RyrnG.js} +1 -1
  39. package/dist/chunks/{saved-dashboard-context-n2Wn11cV.js → saved-dashboard-context-8jqfI7hI.js} +12 -12
  40. package/dist/chunks/{selection-reducer-D0YnaAD9.js → selection-reducer-CV7K4FI6.js} +1 -1
  41. package/dist/chunks/{semaphor-ready-indicator-XLBLOJ2V.js → semaphor-ready-indicator-E2XWyibu.js} +30253 -31076
  42. package/dist/chunks/{shelf-drop-preview-context-DHMa54a-.js → shelf-drop-preview-context-C29EUzDp.js} +7 -7
  43. package/dist/chunks/{source-entity-resolution-dUG5VWRm.js → source-entity-resolution-BXI3nQ5Z.js} +1 -1
  44. package/dist/chunks/{switch-ByxH4M7t.js → switch-balDSHc7.js} +3 -3
  45. package/dist/chunks/{table-export-sheet-C_GdeTYU.js → table-export-sheet-CK8tvh4d.js} +1 -1
  46. package/dist/chunks/temporal-input-presentation-B77JsAzU.js +5002 -0
  47. package/dist/chunks/{token-types-CQtXUVMy.js → token-types-DhYH5YKb.js} +1 -1
  48. package/dist/chunks/{upload-wbR-NVzq.js → upload-Ufj8vjyn.js} +1 -1
  49. package/dist/chunks/{use-create-flow-overlay-state-CEBaLOKC.js → use-create-flow-overlay-state-9WsnzEO5.js} +6 -6
  50. package/dist/chunks/{validators-CXTneCA4.js → validators-BtaCFIEB.js} +37 -37
  51. package/dist/chunks/{zoned-wall-clock-B1n_WjW3.js → zoned-wall-clock-CGLVI40Q.js} +1 -1
  52. package/dist/dashboard/index.js +2 -2
  53. package/dist/dashboard-authoring/index.js +2400 -1856
  54. package/dist/data-app-sdk/index.js +20 -20
  55. package/dist/data-app-sdk-adapters/index.js +3 -3
  56. package/dist/data-app-sdk-validation/index.js +10 -10
  57. package/dist/format-utils/index.js +257 -256
  58. package/dist/index.js +214 -215
  59. package/dist/report-runtime-context/index.js +2 -2
  60. package/dist/style.css +1 -1
  61. package/dist/surfboard/index.js +2 -2
  62. package/dist/types/components/dashboard/summary-number-formatter.d.ts +6 -0
  63. package/dist/types/index.js +50 -51
  64. package/dist/types/lib/formatters/kpi-number-formatter.d.ts +41 -0
  65. package/dist/types/lib/stores/editor-store.d.ts +9 -1
  66. package/dist/types/lib/stores/table-actions.d.ts +0 -2
  67. package/dist/types/shared/analytics-protocol/analytics-base-schemas.d.ts +10 -0
  68. package/dist/types/shared/analytics-protocol/measure-aggregation-profile.d.ts +12 -0
  69. package/dist/types/shared/dashboard-authoring/card-settings/apply-card-settings.d.ts +11 -0
  70. package/dist/types/shared/dashboard-authoring/card-settings/card-display-write.d.ts +52 -0
  71. package/dist/types/shared/dashboard-authoring/card-settings/card-kinds.d.ts +14 -0
  72. package/dist/types/shared/dashboard-authoring/card-settings/carry-column-settings.d.ts +3 -0
  73. package/dist/types/shared/dashboard-authoring/card-settings/column-format-write.d.ts +8 -0
  74. package/dist/types/shared/dashboard-authoring/card-settings/column-names.d.ts +51 -0
  75. package/dist/types/shared/dashboard-authoring/card-settings/column-sources.d.ts +14 -0
  76. package/dist/types/shared/dashboard-authoring/card-settings/confirm-class.d.ts +9 -0
  77. package/dist/types/shared/dashboard-authoring/card-settings/highlight-inputs.d.ts +19 -0
  78. package/dist/types/shared/dashboard-authoring/card-settings/index.d.ts +15 -0
  79. package/dist/types/shared/dashboard-authoring/card-settings/inputs.d.ts +102 -0
  80. package/dist/types/shared/dashboard-authoring/card-settings/read-card-settings.d.ts +10 -0
  81. package/dist/types/shared/dashboard-authoring/card-settings/resolve-card-highlights.d.ts +14 -0
  82. package/dist/types/shared/dashboard-authoring/card-settings/resolve-card-settings.d.ts +59 -0
  83. package/dist/types/shared/dashboard-authoring/card-settings/resolved.d.ts +40 -0
  84. package/dist/types/shared/dashboard-authoring/card-settings/views.d.ts +28 -0
  85. package/dist/types/shared/dashboard-authoring/changes/card-query-part.d.ts +6 -0
  86. package/dist/types/shared/dashboard-authoring/changes/card-types.d.ts +32 -0
  87. package/dist/types/shared/dashboard-authoring/changes/dashboard-change.d.ts +539 -22
  88. package/dist/types/shared/dashboard-authoring/changes/diagnostics.d.ts +27 -8
  89. package/dist/types/shared/dashboard-authoring/changes/resolve-dashboard-changes.d.ts +25 -1
  90. package/dist/types/shared/dashboard-authoring/conditional-formatting/kpi.d.ts +1 -8
  91. package/dist/types/shared/dashboard-authoring/conditional-formatting/schema.d.ts +10 -10
  92. package/dist/types/shared/dashboard-authoring/index.d.ts +3 -0
  93. package/dist/types/shared/dashboard-authoring/kpi-figure.d.ts +123 -0
  94. package/dist/types/shared/dashboard-authoring/operations/operation-types.d.ts +21 -1
  95. package/dist/types/shared/dashboard-authoring/outline/outline-dashboard.d.ts +10 -4
  96. package/dist/types/shared/dashboard-viewer/bookmark-impact.d.ts +33 -0
  97. package/dist/types/shared/format-utils/formatters/matrix-formatter.d.ts +8 -1
  98. package/dist/types/shared/format-utils/raw-temporal.d.ts +16 -0
  99. package/package.json +2 -2
  100. package/dist/chunks/bookmark-state-BFY9oNmr.js +0 -111
  101. package/dist/chunks/document-dashboard-inputs-CkWfDB8c.js +0 -3010
  102. package/dist/chunks/global-date-filter-utils-D8365uPH.js +0 -12889
  103. package/dist/chunks/pivot-result-contract-expectations-Bl5suy4-.js +0 -1832
  104. package/dist/chunks/raw-temporal-presentation-BHm7s-hz.js +0 -540
  105. package/dist/chunks/resolve-dashboard-input-context-CAMiWvyR.js +0 -5280
  106. package/dist/chunks/table-settings-Imz0FgWi.js +0 -637
  107. package/dist/chunks/temporal-input-presentation-uvNK_tM0.js +0 -3228
@@ -1,3010 +0,0 @@
1
- import { dd as vt, de as Se, df as M, dg as R, dh as Fe, d as W, di as yt, dj as Dt, dk as St, dl as Ft, dm as Vt, dn as Ve, dp as kt, dq as ne, dr as Y, ds as oe, dt as Mt, a0 as se, i as j, du as Tt, dv as Ot, dw as z, dx as ie, dy as $, dz as ke, dA as xt, dB as wt, dC as Pt, v as Me, dD as Et, dE as Rt, dF as Bt, cb as Te, dG as Oe, Z as xe, dH as we, n as Pe, b as Ee, dI as qt, bF as At, a2 as Nt, aw as Re, bE as Be, dJ as zt, bq as jt, a7 as qe, a6 as _t, dK as Ae } from "./global-date-filter-utils-D8365uPH.js";
2
- import { R as Gt, r as re, Z as Lt, _ as Ht, $ as Kt, a0 as Qt, a1 as $t, l as ae, a2 as Ut, J as Ne, a3 as Wt, S as Yt, y as Zt, a4 as Jt, a5 as Xt, a6 as en, a7 as tn, a8 as nn, a9 as on, aa as sn, O as rn, ab as an, c as ln, ac as ze, ad as dn, ae as cn, z as un, af as fn, K as pn, ag as je, ah as mn, ai as In } from "./resolve-dashboard-input-context-CAMiWvyR.js";
3
- import { aC as bn } from "./validators-CXTneCA4.js";
4
- import { d as le } from "./matrix-operation-contract-WPv4R-H_.js";
5
- import "./analytics-base-schemas-CHLxsPfX.js";
6
- import "zod";
7
- import "./index-CuHybtft.js";
8
- import "../value-format-preferences/index.js";
9
- import "./_commonjsHelpers-DimLPMtv.js";
10
- import "./temporal-input-presentation-uvNK_tM0.js";
11
- import { J as hn, x as de, K as B, I as X, q as gn, j as Cn, o as vn, L as G, A as yn } from "./table-settings-Imz0FgWi.js";
12
- import "./index-CJW5BdWT.js";
13
- import { r as _e, B as ce } from "./bookmark-state-BFY9oNmr.js";
14
- import { s as he } from "./pivot-result-contract-expectations-Bl5suy4-.js";
15
- import { r as Dn, i as Ge } from "./matrix-card-HPskLaPy.js";
16
- import { D as Sn } from "./report-runtime-context-BZQh9ywy.js";
17
- import { c as Fn } from "./selection-filter-compiler-BKXmyLrS.js";
18
- function ue(e, t) {
19
- const n = {};
20
- for (const o of hn(e)) {
21
- if (!o.inlineFilters || o.inlineFilters.length === 0)
22
- continue;
23
- const s = [];
24
- for (const i of o.inlineFilters) {
25
- const r = vt(i, t);
26
- r && s.push(r);
27
- }
28
- s.length > 0 && (n[o.id] = s);
29
- }
30
- return n;
31
- }
32
- const Vn = [];
33
- function kn(e) {
34
- return e.label || e.name;
35
- }
36
- function ns(e, t, n) {
37
- const o = e == null ? void 0 : e.drill;
38
- return {
39
- ...e,
40
- drill: {
41
- // A dynamic drill carries no hierarchy and keeps the one already walked.
42
- hierarchyId: n ?? (o == null ? void 0 : o.hierarchyId),
43
- steps: [...(o == null ? void 0 : o.steps) ?? [], t]
44
- }
45
- };
46
- }
47
- function os(e) {
48
- const t = e == null ? void 0 : e.drill;
49
- if (!e || !(t != null && t.steps.length)) return e;
50
- const { drill: n, ...o } = e, s = t.steps.slice(0, -1);
51
- return s.length > 0 ? { ...o, drill: { ...t, steps: s } } : Object.keys(o).length > 0 ? o : void 0;
52
- }
53
- function E(e) {
54
- return typeof e == "object" && e !== null && !Array.isArray(e);
55
- }
56
- function Mn(e) {
57
- if (!E(e)) return !1;
58
- const { toField: t, conditions: n } = e;
59
- return E(t) && typeof t.name == "string" && Array.isArray(n) && n.every(
60
- (o) => E(o) && E(o.field) && typeof o.field.name == "string"
61
- );
62
- }
63
- function Tn(e) {
64
- if (!E(e)) return {};
65
- const t = {};
66
- for (const [n, o] of Object.entries(e)) {
67
- if (!E(o) || !E(o.drill)) continue;
68
- const { steps: s, hierarchyId: i } = o.drill;
69
- !Array.isArray(s) || s.length === 0 || s.every(Mn) && (t[n] = {
70
- drill: {
71
- ...typeof i == "string" ? { hierarchyId: i } : {},
72
- steps: s.map((r) => ({
73
- ...r,
74
- label: typeof r.label == "string" && r.label ? r.label : kn(r.toField)
75
- }))
76
- }
77
- });
78
- }
79
- return t;
80
- }
81
- function On(e, t) {
82
- const n = Object.entries(e ?? {}).filter(
83
- ([o, s]) => {
84
- var i;
85
- return (((i = s.drill) == null ? void 0 : i.steps.length) ?? 0) > 0 && (!t || t.has(o));
86
- }
87
- );
88
- return n.length > 0 ? Object.fromEntries(n) : void 0;
89
- }
90
- function xn(e, t) {
91
- return {
92
- id: t,
93
- field: e.field,
94
- operator: e.operator,
95
- value: e.value,
96
- label: e.label,
97
- temporalBucket: e.temporalBucket
98
- };
99
- }
100
- function wn(e, t) {
101
- return Se(e) ? Pn(e, t) : e.config ?? {};
102
- }
103
- function Pn(e, t) {
104
- var o;
105
- const n = (o = t == null ? void 0 : t.steps[t.steps.length - 1]) == null ? void 0 : o.toField;
106
- return n ? Gt(e.config ?? {}, n, {
107
- sortPolicy: "retargetDimensionSort"
108
- }) : e.config ?? {};
109
- }
110
- function En(e, t) {
111
- const n = (e == null ? void 0 : e.steps) ?? [];
112
- if (n.length !== 0)
113
- return {
114
- id: `${t}-drill-root`,
115
- logicalOperator: "AND",
116
- negate: !1,
117
- conditions: [],
118
- groups: n.map((o, s) => ({
119
- id: `breadcrumb-${s}`,
120
- logicalOperator: "OR",
121
- negate: !1,
122
- conditions: [],
123
- groups: [
124
- {
125
- id: `breadcrumb-${s}-group-0`,
126
- logicalOperator: "AND",
127
- negate: !1,
128
- conditions: o.conditions.map(
129
- (i) => xn(
130
- i,
131
- `${i.field.id}-${i.value}`
132
- )
133
- ),
134
- groups: []
135
- }
136
- ]
137
- }))
138
- };
139
- }
140
- function Le(e) {
141
- const t = He(e);
142
- return t.status === "unresolved" ? {} : t.values;
143
- }
144
- function ss(e) {
145
- const t = He(e);
146
- return t.status === "unresolved" ? t : { status: "resolved", uncaptured: t.cleared };
147
- }
148
- function He({
149
- dashboard: e,
150
- dashboardInputValues: t,
151
- sheetId: n,
152
- cardId: o
153
- }) {
154
- let s = M(
155
- t || {}
156
- );
157
- const i = [], r = Bn({
158
- dashboard: e,
159
- sheetId: n,
160
- cardId: o
161
- });
162
- if (r.status === "unresolved")
163
- return { status: "unresolved" };
164
- s = Rn({
165
- dashboardInputValues: s,
166
- savedSheetId: n,
167
- cardId: o,
168
- targets: r.targets
169
- });
170
- for (const a of r.targets) {
171
- const c = Qt(
172
- $t({
173
- dashboard: e,
174
- card: a.card
175
- }).allInputs
176
- ).filter(
177
- (d) => St(d, a) && W(d, a)
178
- );
179
- for (const d of c) {
180
- const l = Ft(
181
- s,
182
- d,
183
- a
184
- ), u = Fe(
185
- d,
186
- l
187
- );
188
- if (u && u !== l && (s = R(
189
- s,
190
- d,
191
- a,
192
- u
193
- )), !u || u.status === void 0) {
194
- s = R(
195
- s,
196
- d,
197
- a,
198
- {
199
- status: "cleared",
200
- comparisonSelection: u == null ? void 0 : u.comparisonSelection
201
- }
202
- ), i.push({
203
- input: d,
204
- target: {
205
- sheetId: a.sheetId,
206
- cardId: a.cardId,
207
- sectionId: a.sectionId
208
- }
209
- });
210
- continue;
211
- }
212
- u.status === "set" && Vt(d) && !u.comparisonSelection && (s = R(
213
- s,
214
- d,
215
- a,
216
- {
217
- ...u,
218
- comparisonSelection: { mode: "off" }
219
- }
220
- ));
221
- }
222
- }
223
- return {
224
- status: "resolved",
225
- values: M(s),
226
- cleared: i
227
- };
228
- }
229
- function Rn({
230
- dashboardInputValues: e,
231
- savedSheetId: t,
232
- cardId: n,
233
- targets: o
234
- }) {
235
- var c, d, l, u;
236
- const s = {}, i = new Set(
237
- o.flatMap((f) => f.sheetId ? [f.sheetId] : [])
238
- ), r = new Set(
239
- o.flatMap((f) => f.cardId ? [f.cardId] : [])
240
- ), a = new Set(
241
- o.flatMap((f) => f.sectionId ? [f.sectionId] : [])
242
- );
243
- if (e.shared && (s.shared = { ...e.shared }), n) {
244
- const f = o[0], p = (t ? (c = e.bySheetId) == null ? void 0 : c[t] : void 0) ?? (f.sheetId ? (d = e.bySheetId) == null ? void 0 : d[f.sheetId] : void 0);
245
- f.sheetId && p && (s.bySheetId = {
246
- [f.sheetId]: { ...p }
247
- });
248
- const m = f.cardId ? (l = e.byCardId) == null ? void 0 : l[f.cardId] : void 0;
249
- f.cardId && m && (s.byCardId = {
250
- [f.cardId]: { ...m }
251
- });
252
- const I = Object.entries(
253
- e.byDocumentSectionId || {}
254
- ), b = (f.sectionId ? (u = e.byDocumentSectionId) == null ? void 0 : u[f.sectionId] : void 0) ?? (I.length === 1 ? I[0][1] : void 0);
255
- return f.sectionId && b && (s.byDocumentSectionId = {
256
- [f.sectionId]: { ...b }
257
- }), M(s);
258
- }
259
- return s.bySheetId = Z(
260
- e.bySheetId,
261
- i
262
- ), s.byCardId = Z(
263
- e.byCardId,
264
- r
265
- ), s.byDocumentSectionId = Z(
266
- e.byDocumentSectionId,
267
- a
268
- ), M(s);
269
- }
270
- function Z(e, t) {
271
- if (!e) return;
272
- const n = Object.entries(e).filter(
273
- ([o]) => t.has(o)
274
- );
275
- return n.length > 0 ? Object.fromEntries(
276
- n.map(([o, s]) => [
277
- o,
278
- { ...s }
279
- ])
280
- ) : void 0;
281
- }
282
- function Bn({
283
- dashboard: e,
284
- sheetId: t,
285
- cardId: n
286
- }) {
287
- var r;
288
- if (n) {
289
- const a = qn(e, n);
290
- return a ? {
291
- status: "resolved",
292
- targets: [a]
293
- } : { status: "unresolved", targetKind: "card" };
294
- }
295
- const o = (e.sheets || []).filter(
296
- (a) => !t || a.id === t
297
- );
298
- if (t && o.length === 0)
299
- return { status: "unresolved", targetKind: "sheet" };
300
- const s = o.map(
301
- (a) => ({
302
- sheetId: a.id,
303
- sheetKind: a.kind || "dashboard"
304
- })
305
- ), i = new Set(o.map((a) => a.id));
306
- for (const a of B(e))
307
- i.has(a.sheet.id) && s.push({
308
- sheetId: a.sheet.id,
309
- cardId: a.card.id,
310
- card: a.card,
311
- sheetKind: a.sheet.kind || "dashboard"
312
- });
313
- for (const a of o)
314
- if (a.kind === "document")
315
- for (const c of ((r = a.document) == null ? void 0 : r.sections) || []) {
316
- const d = de(c);
317
- d.length === 0 && s.push({
318
- sheetId: a.id,
319
- sectionId: c.id,
320
- sheetKind: "document"
321
- });
322
- for (const l of d)
323
- s.push({
324
- sheetId: a.id,
325
- sectionId: c.id,
326
- cardId: l.id,
327
- card: l,
328
- sheetKind: "document"
329
- });
330
- }
331
- return {
332
- status: "resolved",
333
- targets: s.length > 0 ? s : [{}]
334
- };
335
- }
336
- function qn(e, t) {
337
- var o;
338
- const n = X(e, t);
339
- if (n)
340
- return {
341
- sheetId: n.sheet.id,
342
- cardId: n.card.id,
343
- card: n.card,
344
- sheetKind: n.sheet.kind || "dashboard"
345
- };
346
- for (const s of e.sheets || [])
347
- if (s.kind === "document")
348
- for (const i of ((o = s.document) == null ? void 0 : o.sections) || []) {
349
- const r = de(i).find(
350
- (a) => a.id === t
351
- );
352
- if (r)
353
- return {
354
- sheetId: s.id,
355
- sectionId: i.id,
356
- cardId: r.id,
357
- card: r,
358
- sheetKind: "document"
359
- };
360
- }
361
- }
362
- function is({
363
- dashboardInputValues: e,
364
- dashboard: t,
365
- filterValues: n,
366
- sheetId: o,
367
- cardId: s,
368
- sectionId: i,
369
- sheetKind: r
370
- }) {
371
- var d, l, u;
372
- if (!((d = t.inputs) != null && d.length))
373
- return e;
374
- const a = new Map(
375
- n.map((f) => [f.filterId, f])
376
- );
377
- let c = e || {};
378
- for (const f of t.inputs) {
379
- if (f.kind !== "filter" || !W(f, {
380
- sheetId: o,
381
- cardId: s,
382
- sectionId: i,
383
- sheetKind: r
384
- }))
385
- continue;
386
- const p = ((l = f.filter) == null ? void 0 : l.id) || ((u = f.filterReference) == null ? void 0 : u.filterId);
387
- if (!p) continue;
388
- const m = a.get(p), I = m ? yt(m) : void 0, b = (I == null ? void 0 : I.status) === "set" ? I : { status: "cleared" };
389
- c = Dt(
390
- c,
391
- f,
392
- { sheetId: o, cardId: s, sectionId: i },
393
- b
394
- );
395
- }
396
- return c;
397
- }
398
- function N({
399
- dashboard: e,
400
- sheetId: t,
401
- card: n,
402
- sectionId: o,
403
- sheetKind: s,
404
- mode: i,
405
- runtimeValues: r,
406
- transientContexts: a,
407
- generatedAt: c,
408
- calendar: d
409
- }) {
410
- const l = Ln({
411
- dashboard: e,
412
- sheetId: t,
413
- card: n,
414
- sectionId: o,
415
- sheetKind: s,
416
- runtimeValues: r,
417
- calendar: d
418
- });
419
- return {
420
- context: l,
421
- snapshot: {
422
- ...t ? { sheetId: t } : {},
423
- ...n != null && n.id ? { cardId: n.id } : {},
424
- mode: i,
425
- dashboardInputValues: _n(
426
- Gn({
427
- inputs: l.inputs,
428
- context: l,
429
- sheetId: t,
430
- cardId: n == null ? void 0 : n.id,
431
- sectionId: o
432
- }),
433
- r.dashboardInputValues
434
- ),
435
- ...Ke(r.cardViewState, {
436
- cardId: n == null ? void 0 : n.id,
437
- sheetKind: s
438
- }),
439
- ...Qe(a, { sheetKind: s }),
440
- generatedAt: c,
441
- timezone: d == null ? void 0 : d.tz
442
- }
443
- };
444
- }
445
- function An({
446
- sheetIds: e,
447
- sheetKind: t = "dashboard",
448
- ...n
449
- }) {
450
- var a;
451
- const o = e.map(
452
- (c) => N({
453
- ...n,
454
- sheetId: c,
455
- sheetKind: t
456
- })
457
- ), s = e.flatMap(
458
- (c) => Nn(n.dashboard, c).map(
459
- (d) => N({
460
- ...n,
461
- sheetId: c,
462
- card: d,
463
- sheetKind: t
464
- })
465
- )
466
- ), i = o[0] || s[0] || N({
467
- ...n,
468
- sheetKind: t
469
- }), r = $e(
470
- ...o.map(
471
- (c) => c.snapshot.dashboardInputValues
472
- ),
473
- ...s.map(
474
- (c) => c.snapshot.dashboardInputValues
475
- )
476
- );
477
- return {
478
- context: i.context,
479
- snapshot: {
480
- ...e.length === 1 ? { sheetId: e[0] } : {},
481
- mode: n.mode,
482
- dashboardInputValues: r,
483
- ...Ke(n.runtimeValues.cardViewState, { sheetKind: t }),
484
- ...Qe(n.transientContexts, { sheetKind: t }),
485
- generatedAt: n.generatedAt,
486
- timezone: (a = n.calendar) == null ? void 0 : a.tz
487
- }
488
- };
489
- }
490
- function Nn(e, t) {
491
- var r;
492
- const n = (r = e.sheets) == null ? void 0 : r.find((a) => a.id === t), o = [], s = /* @__PURE__ */ new Set(), i = (a) => {
493
- !(a != null && a.id) || s.has(a.id) || (s.add(a.id), o.push(a));
494
- };
495
- for (const a of (n == null ? void 0 : n.cards) || [])
496
- i(a);
497
- for (const a of (n == null ? void 0 : n.frames) || [])
498
- for (const c of (a == null ? void 0 : a.cards) || [])
499
- i(c);
500
- return o;
501
- }
502
- function zn({
503
- sectionIds: e,
504
- ...t
505
- }) {
506
- const n = N(t), o = e.map(
507
- (i) => N({
508
- ...t,
509
- sectionId: i
510
- })
511
- ), s = jn(
512
- t.dashboard,
513
- t.sheetId,
514
- e
515
- ).map(
516
- ({ sectionId: i, card: r }) => N({
517
- ...t,
518
- sectionId: i,
519
- card: r
520
- })
521
- );
522
- return {
523
- ...n,
524
- snapshot: {
525
- ...n.snapshot,
526
- dashboardInputValues: $e(
527
- n.snapshot.dashboardInputValues,
528
- ...o.map(
529
- (i) => i.snapshot.dashboardInputValues
530
- ),
531
- ...s.map(
532
- (i) => i.snapshot.dashboardInputValues
533
- )
534
- )
535
- }
536
- };
537
- }
538
- function jn(e, t, n) {
539
- var i, r;
540
- const o = new Set(n), s = (i = e.sheets) == null ? void 0 : i.find((a) => a.id === t);
541
- return (((r = s == null ? void 0 : s.document) == null ? void 0 : r.sections) || []).flatMap(
542
- (a) => a.id && o.has(a.id) ? de(a).map((c) => ({
543
- sectionId: a.id,
544
- card: c
545
- })) : []
546
- );
547
- }
548
- function _n(e, t) {
549
- let n = e;
550
- for (const o of Object.keys((t == null ? void 0 : t.shared) ?? {})) {
551
- const s = le(o), i = s ? Lt(t, s) : void 0;
552
- !s || !i || (n = R(
553
- n,
554
- Kt(s),
555
- Ht,
556
- { status: "set", value: { kind: "selection", selection: i } }
557
- ));
558
- }
559
- return n;
560
- }
561
- function Ke(e, t) {
562
- if (t.sheetKind === "document") return {};
563
- const n = On(
564
- e,
565
- t.cardId ? /* @__PURE__ */ new Set([t.cardId]) : void 0
566
- );
567
- return n ? { cardViewState: n } : {};
568
- }
569
- function Qe(e, t) {
570
- return t.sheetKind === "document" || !(e != null && e.length) ? {} : { transientContexts: [...e] };
571
- }
572
- function Gn({
573
- inputs: e,
574
- context: t,
575
- sheetId: n,
576
- cardId: o,
577
- sectionId: s
578
- }) {
579
- const i = new Map(
580
- t.resolvedInputs.map((a) => [
581
- a.id,
582
- a
583
- ])
584
- );
585
- let r = {};
586
- for (const a of e) {
587
- const c = i.get(a.id), d = Fe(a, c == null ? void 0 : c.slot) || { status: "cleared" };
588
- r = R(
589
- r,
590
- a,
591
- { sheetId: n, cardId: o, sectionId: s },
592
- d
593
- );
594
- }
595
- return M(r);
596
- }
597
- function Ln({
598
- dashboard: e,
599
- sheetId: t,
600
- card: n,
601
- sectionId: o,
602
- sheetKind: s,
603
- runtimeValues: i,
604
- calendar: r
605
- }) {
606
- return re({
607
- // See `carryTransientContexts`: the snapshot's values are the dashboard's
608
- // own, and carried contexts travel beside them.
609
- transientContexts: void 0,
610
- dashboard: e,
611
- sheetId: t,
612
- card: n,
613
- sectionId: o,
614
- sheetKind: s,
615
- runtimeValues: i,
616
- calendar: r
617
- });
618
- }
619
- function $e(...e) {
620
- const t = {};
621
- for (const n of e)
622
- n.shared && (t.shared = {
623
- ...t.shared,
624
- ...n.shared
625
- }), J(t, "bySheetId", n.bySheetId), J(t, "byCardId", n.byCardId), J(
626
- t,
627
- "byDocumentSectionId",
628
- n.byDocumentSectionId
629
- );
630
- return M(t);
631
- }
632
- function J(e, t, n) {
633
- if (n) {
634
- e[t] || (e[t] = {});
635
- for (const [o, s] of Object.entries(n))
636
- e[t][o] = {
637
- ...e[t][o],
638
- ...s
639
- };
640
- }
641
- }
642
- function _(e) {
643
- const t = M(e ?? {}), n = [];
644
- for (const [o, s] of Object.entries(t.shared ?? {}))
645
- n.push({ scope: "shared", target: null, inputId: o, slot: s });
646
- for (const o of ["bySheetId", "byCardId"])
647
- for (const [s, i] of Object.entries(t[o] ?? {}))
648
- for (const [r, a] of Object.entries(i))
649
- n.push({ scope: o, target: s, inputId: r, slot: a });
650
- return n;
651
- }
652
- function U(e, t, n) {
653
- const o = e;
654
- if (t.scope === "shared") {
655
- o.shared = { ...o.shared, [t.inputId]: n };
656
- return;
657
- }
658
- const s = { ...o[t.scope] ?? {} };
659
- s[t.target] = { ...s[t.target], [t.inputId]: n }, o[t.scope] = s;
660
- }
661
- function Ue(e, t, n) {
662
- const o = Ve(
663
- e,
664
- t.controlOverrides,
665
- { hasExplicitRuntimeOverrides: t.controlOverrides !== void 0 }
666
- );
667
- return {
668
- adHocFilterValues: [...t.adHocFilterValues],
669
- controlValues: o.dashboardControlValues,
670
- cardControlValuesMap: o.cardControlValuesMap,
671
- dashboardInputValues: t.dashboardInputValues,
672
- inlineFilterValuesMap: t.inlineFilterValuesMap ?? ue(e, n)
673
- };
674
- }
675
- function fe(e, t, n) {
676
- return We(
677
- e,
678
- Ue(e, t, n),
679
- n
680
- );
681
- }
682
- function rs(e, t, n) {
683
- return We(e, t, n);
684
- }
685
- function We(e, t, n) {
686
- const o = e.sheets ?? [], s = o.filter((a) => (a.kind ?? "dashboard") === "dashboard").map((a) => a.id), i = o.filter((a) => a.kind === "document"), r = s.length ? An({
687
- dashboard: e,
688
- sheetIds: s,
689
- mode: "dashboard",
690
- runtimeValues: t,
691
- transientContexts: void 0,
692
- calendar: n ?? null
693
- }).snapshot.dashboardInputValues : {};
694
- return i.reduce(
695
- (a, c) => {
696
- var d;
697
- return oe(
698
- a,
699
- zn({
700
- dashboard: e,
701
- sheetId: c.id,
702
- sheetKind: "document",
703
- mode: "document",
704
- sectionIds: (((d = c.document) == null ? void 0 : d.sections) ?? []).map(
705
- (l) => l.id
706
- ),
707
- runtimeValues: t,
708
- transientContexts: void 0,
709
- calendar: n ?? null
710
- }).snapshot.dashboardInputValues
711
- );
712
- },
713
- r
714
- );
715
- }
716
- function Ye(e, t) {
717
- const n = {}, o = {}, s = /* @__PURE__ */ new Map();
718
- for (const i of _(t)) {
719
- const r = e.get(i.inputId), { slot: a } = i, c = () => a.status === "set" && a.value.kind === "filter" ? a.value.filterValue : a.status === "cleared" ? null : void 0;
720
- if ((r == null ? void 0 : r.source) === "cardInlineFilter") {
721
- const d = c();
722
- if (d !== void 0) {
723
- const l = s.get(r.cardId) ?? /* @__PURE__ */ new Map();
724
- l.set(r.filterId, d), s.set(r.cardId, l);
725
- }
726
- } else if ((r == null ? void 0 : r.source) === "dashboardControl" || (r == null ? void 0 : r.source) === "cardControl")
727
- a.status === "set" && a.value.kind === "control" ? o[r.controlId] = a.value.value : a.status === "cleared" && (o[r.controlId] = void 0);
728
- else {
729
- U(n, i, a);
730
- continue;
731
- }
732
- a.comparisonSelection && U(n, i, {
733
- comparisonSelection: a.comparisonSelection
734
- });
735
- }
736
- return {
737
- runtime: M(n),
738
- controlValues: o,
739
- inlineFilterValues: s
740
- };
741
- }
742
- function Hn(e, t) {
743
- if (!t.size) return [...e];
744
- const n = e.filter((s) => !t.has(s.filterId)), o = [...t.values()].filter(
745
- (s) => s !== null
746
- );
747
- return Mt(n, o);
748
- }
749
- function Ze(e, t, n) {
750
- if (!Object.keys(n).length) return t;
751
- const o = Ve(
752
- e,
753
- t,
754
- { hasExplicitRuntimeOverrides: t !== void 0 }
755
- );
756
- return {
757
- ...kt({
758
- dashboardValues: o.dashboardControlValues,
759
- cardValuesMap: o.cardControlValuesMap
760
- }),
761
- ...n
762
- };
763
- }
764
- function Kn(e, t) {
765
- if (!t.size) return;
766
- const n = Object.fromEntries(
767
- Object.entries(e).map(([o, s]) => [o, [...s]])
768
- );
769
- for (const [o, s] of t)
770
- n[o] = Hn(n[o] ?? [], s);
771
- return n;
772
- }
773
- function Qn(e, t, n) {
774
- const o = new Map(
775
- B(e).map(({ card: r }) => [
776
- r.id,
777
- new Map((r.inlineFilters ?? []).map((a) => [a.id, a]))
778
- ])
779
- );
780
- let s = !1;
781
- const i = Object.fromEntries(
782
- Object.entries(t).map(([r, a]) => [r, [...a]])
783
- );
784
- for (const [r, a] of Object.entries(n)) {
785
- const c = o.get(r), d = (a ?? []).filter((l) => {
786
- const u = c == null ? void 0 : c.get(l.filterId);
787
- return u ? ne(u, l) : !1;
788
- });
789
- Y(d, i[r] ?? []) || (s = !0), i[r] = d;
790
- }
791
- return s ? i : void 0;
792
- }
793
- const $n = ["bySheetId", "byCardId", "byDocumentSectionId"];
794
- function Un(e, t) {
795
- const n = se(e);
796
- let o = !1;
797
- const s = (r) => {
798
- if (!r) return r;
799
- const a = Object.entries(r).filter(([c, d]) => {
800
- var u;
801
- if (d.status !== "set" || d.value.kind !== "filter") return !0;
802
- const l = (u = n.findFilterInput({ inputId: c })) == null ? void 0 : u.input.filter;
803
- return !l || ne(l, d.value.filterValue) ? !0 : (o = !0, !1);
804
- });
805
- return Object.fromEntries(a);
806
- }, i = {
807
- ...t,
808
- ...t.shared ? { shared: s(t.shared) } : {}
809
- };
810
- for (const r of $n) {
811
- const a = t[r];
812
- a && (i[r] = Object.fromEntries(
813
- Object.entries(a).map(([c, d]) => [c, s(d) ?? {}])
814
- ));
815
- }
816
- return o ? i : t;
817
- }
818
- function Wn(e) {
819
- var t, n;
820
- return ((n = (t = e.sheets) == null ? void 0 : t[0]) == null ? void 0 : n.id) ?? null;
821
- }
822
- function L(e, t) {
823
- var n;
824
- return !!t && !!((n = e.sheets) != null && n.some((o) => o.id === t));
825
- }
826
- function as(e) {
827
- const { dashboard: t, host: n, calendar: o } = e, s = Ne(t, n.filterValues, {
828
- calendar: o
829
- }).slots, i = n.controlValues, r = L(t, n.selectedSheetId) ? n.selectedSheetId : Wn(t);
830
- return {
831
- hostInputValues: s,
832
- controlOverrides: i,
833
- selectedSheetId: r,
834
- hostSelectedSheetId: n.selectedSheetId ?? null,
835
- materializedInputs: e.materializeInputs === !1 ? {} : fe(
836
- t,
837
- {
838
- adHocFilterValues: [],
839
- controlOverrides: i,
840
- dashboardInputValues: s
841
- },
842
- o
843
- )
844
- };
845
- }
846
- function Je(e) {
847
- const t = /* @__PURE__ */ new Map(), n = /* @__PURE__ */ new Set(), o = /* @__PURE__ */ new Map();
848
- for (const s of ae(e))
849
- s.kind === "filter" && s.filter ? t.set(s.id, s.filter) : s.kind === "control" && n.add(s.id), s.compatibility && o.set(s.id, s.compatibility);
850
- return { filterInputs: t, controlInputIds: n, compatibility: o };
851
- }
852
- function Xe(e, t) {
853
- const n = le(t);
854
- if (!n) return;
855
- const o = G(e, n);
856
- return o ? Ut(o, e) ? "applies" : "not-eligible" : "removed";
857
- }
858
- function ls(e, t) {
859
- const n = Xe(e, t);
860
- return n ? n === "applies" : ae(e).some(
861
- (o) => o.id === t
862
- );
863
- }
864
- function et(e, t, n, o) {
865
- if (!n) return {};
866
- const s = new Set((e.sheets ?? []).map((d) => d.id)), i = new Set(
867
- B(e).map(({ card: d }) => d.id)
868
- ), r = se(e), a = (d) => {
869
- var u;
870
- if (!d) return;
871
- const l = {};
872
- for (const [f, p] of Object.entries(d)) {
873
- const m = t.filterInputs.has(f) || t.controlInputIds.has(f) ? f : ((u = r.findFilterInput({ inputId: f })) == null ? void 0 : u.input.id) ?? f;
874
- if (m !== f && d[m]) continue;
875
- const I = Xe(e, m);
876
- if (I) {
877
- if (I !== "applies") {
878
- o.push({
879
- kind: "setting-no-longer-applies",
880
- target: "selection",
881
- id: m,
882
- reason: I
883
- });
884
- continue;
885
- }
886
- l[m] = p;
887
- continue;
888
- }
889
- const b = t.filterInputs.get(m);
890
- if (!b && !t.controlInputIds.has(m)) {
891
- o.push({
892
- kind: "setting-no-longer-applies",
893
- target: "input",
894
- id: m,
895
- reason: "removed"
896
- });
897
- continue;
898
- }
899
- if (b && p.status === "set" && p.value.kind === "filter" && !ne(b, p.value.filterValue)) {
900
- o.push({
901
- kind: "setting-no-longer-applies",
902
- target: "input",
903
- id: m,
904
- reason: "incompatible"
905
- });
906
- continue;
907
- }
908
- l[m] = p;
909
- }
910
- return Object.keys(l).length ? l : void 0;
911
- }, c = (d, l) => {
912
- if (!d) return;
913
- const u = {};
914
- for (const [f, p] of Object.entries(d)) {
915
- if (!l(f)) {
916
- for (const I of Object.keys(p))
917
- o.push({
918
- kind: "setting-no-longer-applies",
919
- target: "input",
920
- id: I,
921
- reason: "removed"
922
- });
923
- continue;
924
- }
925
- const m = a(p);
926
- m && (u[f] = m);
927
- }
928
- return u;
929
- };
930
- return M({
931
- shared: a(n.shared),
932
- bySheetId: c(n.bySheetId, (d) => s.has(d)),
933
- byCardId: c(n.byCardId, (d) => i.has(d))
934
- // Document sections are not viewer state.
935
- });
936
- }
937
- function V(e, t, n, o = {}) {
938
- const s = new Map(
939
- B(e).map(({ card: r }) => [r.id, r])
940
- ), i = {};
941
- for (const [r, a] of Object.entries(t ?? {})) {
942
- const c = s.get(r);
943
- if (c && gn(c)) {
944
- Cn(a) || (i[r] = a);
945
- continue;
946
- }
947
- if (c && o.sessionSorts && vn(c)) {
948
- a.sort && (i[r] = { sort: a.sort });
949
- continue;
950
- }
951
- n == null || n.push({
952
- kind: "setting-no-longer-applies",
953
- target: "card",
954
- id: r,
955
- reason: G(e, r) ? "not-eligible" : "removed"
956
- });
957
- }
958
- return i;
959
- }
960
- function Yn(e, t, n) {
961
- if (t) {
962
- if (L(e, t)) return t;
963
- n.push({
964
- kind: "setting-no-longer-applies",
965
- target: "sheet",
966
- id: t,
967
- reason: "removed"
968
- });
969
- }
970
- }
971
- const pe = (e, t) => Y(e ?? null, t ?? null);
972
- function tt(e) {
973
- return {
974
- adHocFilterValues: e.adHocFilterValues,
975
- controlOverrides: e.controlOverrides,
976
- dashboardInputValues: e.dashboardInputValues,
977
- ...e.inlineFilterValuesMap ? { inlineFilterValuesMap: e.inlineFilterValuesMap } : {},
978
- selectedSheetId: e.selectedSheetId,
979
- tableSettings: e.tableSettings
980
- };
981
- }
982
- function K(e, t) {
983
- return {
984
- adHocFilterValues: [],
985
- controlOverrides: e.controlOverrides,
986
- dashboardInputValues: e.hostInputValues,
987
- selectedSheetId: e.selectedSheetId,
988
- tableSettings: t
989
- };
990
- }
991
- function nt(e, t) {
992
- const n = t.dashboardInputValues === e.baseline.hostInputValues && !t.inlineFilterValuesMap && !t.adHocFilterValues.length && t.controlOverrides === e.baseline.controlOverrides;
993
- return {
994
- selectedSheetId: t.selectedSheetId,
995
- // Overlay: the bookmark's values on the baseline's runtime values.
996
- inputs: n ? e.baseline.materializedInputs : fe(e.dashboard, t, e.calendar),
997
- tableSettings: t.tableSettings
998
- };
999
- }
1000
- function A(e, t) {
1001
- const n = tt(t), o = t.restore ?? n;
1002
- return {
1003
- ...n,
1004
- appliedBookmarkId: t.appliedBookmarkId,
1005
- rememberedWrites: t.rememberedWrites ?? [],
1006
- notices: t.notices ?? [],
1007
- opened: nt(e, o),
1008
- restore: o
1009
- };
1010
- }
1011
- function ge(e, t, n, o) {
1012
- const { dashboard: s, baseline: i } = e, r = [], a = _e(t.state, ce), c = a.ok ? a.value : {};
1013
- for (const m of a.ok ? a.issues : [])
1014
- r.push(Zn(m));
1015
- const d = Je(s), l = Ye(
1016
- d.compatibility,
1017
- et(s, d, c.inputs, r)
1018
- ), u = Yn(s, c.selectedSheetId, r) ?? i.selectedSheetId, f = V(
1019
- s,
1020
- c.tableSettings,
1021
- r
1022
- ), p = V(
1023
- s,
1024
- n,
1025
- void 0
1026
- );
1027
- return A(e, {
1028
- appliedBookmarkId: t.id,
1029
- // A bookmark opens without ad-hoc values, as today (P4a-02 f).
1030
- adHocFilterValues: [],
1031
- controlOverrides: Ze(
1032
- s,
1033
- i.controlOverrides,
1034
- l.controlValues
1035
- ),
1036
- // Overlay, never replacement: the bookmark's slots over the host's.
1037
- dashboardInputValues: oe(
1038
- i.hostInputValues,
1039
- l.runtime
1040
- ),
1041
- ...ot(
1042
- Kn(
1043
- ue(s, e.calendar),
1044
- l.inlineFilterValues
1045
- )
1046
- ),
1047
- selectedSheetId: u,
1048
- tableSettings: o.writeRemembered ? { ...p, ...f } : (
1049
- // A default bookmark on load: remembered settings per card win.
1050
- { ...f, ...p }
1051
- ),
1052
- rememberedWrites: o.writeRemembered ? Object.entries(f).filter(
1053
- ([m, I]) => !pe(p[m], I)
1054
- ).map(([m, I]) => ({
1055
- kind: "set",
1056
- cardId: m,
1057
- settings: I
1058
- })) : [],
1059
- notices: r
1060
- });
1061
- }
1062
- function Zn(e) {
1063
- return {
1064
- kind: "setting-no-longer-applies",
1065
- target: e.target,
1066
- id: e.id,
1067
- reason: "invalid"
1068
- };
1069
- }
1070
- function ot(e) {
1071
- return e ? { inlineFilterValuesMap: e } : {};
1072
- }
1073
- function Ce(e, t, n) {
1074
- const { dashboard: o, baseline: s } = e;
1075
- return {
1076
- // A reload in place keeps ad-hoc values, as today (P4a-02 f), unless the
1077
- // template now defines a filter with that id.
1078
- adHocFilterValues: t.adHocFilterValues.filter(
1079
- (i) => !se(o).findFilterInput({ filterId: i.filterId })
1080
- ),
1081
- // A host's new control defaults are the baseline's, not the viewer's.
1082
- controlOverrides: n.controlsChanged ? s.controlOverrides : t.controlOverrides,
1083
- // Live slots stay, except a filter value this template no longer accepts:
1084
- // that filter loads its new default, as the old list did. The resolver
1085
- // ignores slots this template no longer has.
1086
- dashboardInputValues: Un(
1087
- o,
1088
- t.dashboardInputValues
1089
- ),
1090
- ...ot(
1091
- Qn(
1092
- o,
1093
- ue(o, e.calendar),
1094
- t.inlineFilterValuesMap ?? {}
1095
- )
1096
- ),
1097
- selectedSheetId: !n.sheetChanged && L(o, t.selectedSheetId) ? t.selectedSheetId : s.selectedSheetId,
1098
- tableSettings: V(
1099
- o,
1100
- t.tableSettings,
1101
- void 0,
1102
- { sessionSorts: !0 }
1103
- )
1104
- };
1105
- }
1106
- function ds(e) {
1107
- const { dashboard: t, baseline: n, event: o } = e, s = e.rememberedTableSettings;
1108
- switch (o.kind) {
1109
- case "initial-load":
1110
- return o.defaultBookmark ? ge(e, o.defaultBookmark, s, {
1111
- writeRemembered: !1
1112
- }) : A(e, {
1113
- appliedBookmarkId: null,
1114
- ...K(
1115
- n,
1116
- V(t, s, void 0, {
1117
- sessionSorts: o.captured
1118
- })
1119
- )
1120
- });
1121
- case "refetch": {
1122
- const { live: i } = o, r = i.applied, a = {
1123
- sheetChanged: !!i.previousBaseline && i.previousBaseline.hostSelectedSheetId !== n.hostSelectedSheetId,
1124
- controlsChanged: !!i.previousBaseline && !Y(
1125
- i.previousBaseline.controlOverrides ?? null,
1126
- n.controlOverrides ?? null
1127
- )
1128
- }, c = Ce(
1129
- e,
1130
- {
1131
- adHocFilterValues: i.adHocFilterValues,
1132
- controlOverrides: i.controlValues ?? n.controlOverrides,
1133
- dashboardInputValues: i.dashboardInputValues,
1134
- inlineFilterValuesMap: i.inlineFilterValuesMap,
1135
- selectedSheetId: i.selectedSheetId,
1136
- tableSettings: i.tableSettings
1137
- },
1138
- a
1139
- ), d = r ? Ce(e, r.restore, a) : K(
1140
- n,
1141
- V(t, s, void 0)
1142
- );
1143
- return A(e, {
1144
- appliedBookmarkId: (r == null ? void 0 : r.appliedBookmarkId) ?? null,
1145
- ...c,
1146
- notices: (r == null ? void 0 : r.notices) ?? [],
1147
- restore: d
1148
- });
1149
- }
1150
- case "open-bookmark":
1151
- return ge(e, o.bookmark, s, {
1152
- writeRemembered: !0
1153
- });
1154
- case "open-default-view":
1155
- return A(e, {
1156
- appliedBookmarkId: null,
1157
- ...K(
1158
- n,
1159
- V(t, s, void 0)
1160
- )
1161
- });
1162
- case "reset-to-default-view":
1163
- return A(e, {
1164
- appliedBookmarkId: null,
1165
- ...K(n, {}),
1166
- rememberedWrites: [{ kind: "clear-all" }]
1167
- });
1168
- case "discard-changes": {
1169
- const { restore: i } = o.applied, r = V(
1170
- t,
1171
- i.tableSettings,
1172
- void 0,
1173
- { sessionSorts: !0 }
1174
- ), a = V(t, r, void 0), c = V(t, s, void 0), d = [];
1175
- for (const l of /* @__PURE__ */ new Set([
1176
- ...Object.keys(c),
1177
- ...Object.keys(a)
1178
- ])) {
1179
- if (pe(c[l], a[l])) continue;
1180
- const u = a[l];
1181
- d.push(
1182
- u ? { kind: "set", cardId: l, settings: u } : { kind: "clear", cardId: l }
1183
- );
1184
- }
1185
- return A(e, {
1186
- appliedBookmarkId: o.applied.appliedBookmarkId,
1187
- ...i,
1188
- selectedSheetId: L(t, i.selectedSheetId) ? i.selectedSheetId : n.selectedSheetId,
1189
- tableSettings: r,
1190
- rememberedWrites: d,
1191
- notices: o.applied.notices,
1192
- restore: i
1193
- });
1194
- }
1195
- }
1196
- }
1197
- function cs(e) {
1198
- const { dashboard: t, calendar: n } = e, o = e.hostControlValues, s = {
1199
- ...e.baseline,
1200
- controlOverrides: o,
1201
- materializedInputs: fe(
1202
- t,
1203
- {
1204
- adHocFilterValues: [],
1205
- controlOverrides: o,
1206
- dashboardInputValues: e.baseline.hostInputValues
1207
- },
1208
- n
1209
- )
1210
- };
1211
- let i = o;
1212
- if (e.appliedBookmark) {
1213
- const c = _e(
1214
- e.appliedBookmark.state,
1215
- ce
1216
- ), d = Je(t), l = Ye(
1217
- d.compatibility,
1218
- et(
1219
- t,
1220
- d,
1221
- c.ok ? c.value.inputs : void 0,
1222
- []
1223
- )
1224
- ).controlValues;
1225
- i = Ze(t, o, l);
1226
- }
1227
- const r = e.applied;
1228
- if (!r) return { baseline: s, controlOverrides: i, applied: null };
1229
- const a = { ...r.restore, controlOverrides: i };
1230
- return {
1231
- baseline: s,
1232
- controlOverrides: i,
1233
- applied: {
1234
- ...r,
1235
- controlOverrides: i,
1236
- restore: a,
1237
- opened: nt({ dashboard: t, baseline: s, calendar: n }, a)
1238
- }
1239
- };
1240
- }
1241
- function us(e, t, n) {
1242
- const o = tt(n.values);
1243
- return {
1244
- ...o,
1245
- appliedBookmarkId: t,
1246
- rememberedWrites: [],
1247
- notices: e.notices,
1248
- opened: n.snapshot,
1249
- restore: o
1250
- };
1251
- }
1252
- const ve = (e) => JSON.stringify([e.scope, e.target, e.inputId]);
1253
- function Q(e) {
1254
- return !e || e.status === "cleared" && !e.comparisonSelection;
1255
- }
1256
- function st(e, t) {
1257
- const n = new Map(
1258
- _(e).map((i) => [ve(i), i])
1259
- ), o = new Map(
1260
- _(t).map((i) => [ve(i), i])
1261
- ), s = {};
1262
- for (const [i, r] of o) {
1263
- const a = n.get(i);
1264
- a && Y(a.slot, r.slot) || Q(r.slot) && Q(a == null ? void 0 : a.slot) || U(
1265
- s,
1266
- r,
1267
- Q(r.slot) ? { status: "cleared" } : r.slot
1268
- );
1269
- }
1270
- for (const [i, r] of n)
1271
- o.has(i) || Q(r.slot) || U(s, r, { status: "cleared" });
1272
- return M(s);
1273
- }
1274
- function fs(e) {
1275
- const { dashboard: t, baseline: n, current: o } = e, s = st(n.materializedInputs, o.inputs), i = V(
1276
- t,
1277
- o.tableSettings,
1278
- void 0
1279
- ), r = o.selectedSheetId && o.selectedSheetId !== n.selectedSheetId && L(t, o.selectedSheetId) ? o.selectedSheetId : void 0;
1280
- return {
1281
- version: ce,
1282
- ...r ? { selectedSheetId: r } : {},
1283
- ..._(s).length ? { inputs: s } : {},
1284
- ...Object.keys(i).length ? { tableSettings: i } : {}
1285
- };
1286
- }
1287
- function Jn(e) {
1288
- const t = /* @__PURE__ */ new Map();
1289
- for (const n of ae(e))
1290
- n.label && t.set(n.id, n.label);
1291
- return t;
1292
- }
1293
- function Xn(e, t, n) {
1294
- var s, i;
1295
- const o = le(n);
1296
- if (o) {
1297
- const r = (i = (s = G(e, o)) == null ? void 0 : s.title) == null ? void 0 : i.trim();
1298
- return r ? `Selection in ${r}` : "Selection";
1299
- }
1300
- return t.get(n) ?? n;
1301
- }
1302
- function ps(e) {
1303
- var d, l;
1304
- const { dashboard: t, opened: n, current: o } = e, s = [], i = Jn(t), r = /* @__PURE__ */ new Set();
1305
- for (const u of _(
1306
- st(n.inputs, o.inputs)
1307
- ))
1308
- r.has(u.inputId) || (r.add(u.inputId), s.push({
1309
- target: "input",
1310
- inputId: u.inputId,
1311
- label: Xn(t, i, u.inputId)
1312
- }));
1313
- (n.selectedSheetId ?? null) !== (o.selectedSheetId ?? null) && s.push({ target: "sheet" });
1314
- const a = V(
1315
- t,
1316
- n.tableSettings,
1317
- void 0
1318
- ), c = V(
1319
- t,
1320
- o.tableSettings,
1321
- void 0
1322
- );
1323
- for (const u of /* @__PURE__ */ new Set([
1324
- ...Object.keys(a),
1325
- ...Object.keys(c)
1326
- ]))
1327
- pe(a[u], c[u]) || s.push({
1328
- target: "table",
1329
- cardId: u,
1330
- cardTitle: ((l = (d = G(t, u)) == null ? void 0 : d.title) == null ? void 0 : l.trim()) || "Table"
1331
- });
1332
- return s;
1333
- }
1334
- function ms(e, t) {
1335
- const { controlContractOverrides: n, cardId: o } = t;
1336
- if (!n || (n.controlDefinitions !== void 0 && (e.controls = n.controlDefinitions), typeof o != "string" || o.trim().length === 0))
1337
- return e;
1338
- const s = G(e, o);
1339
- return s && (n.cardControlDefinitions !== void 0 && (s.controls = n.cardControlDefinitions), n.controlBindings !== void 0 && (s.controlBindings = n.controlBindings)), e;
1340
- }
1341
- function Is(e) {
1342
- const { dashboard: t, capture: n, calendar: o } = e, s = Ne(t, n.filterValues, {
1343
- calendar: o
1344
- }), i = n.dashboardInputExecutionSnapshot, r = n.controlValues, a = {
1345
- ...Ue(
1346
- t,
1347
- {
1348
- adHocFilterValues: s.adHocFilterValues,
1349
- controlOverrides: r,
1350
- // The snapshot replays exactly over the listed values.
1351
- dashboardInputValues: i ? oe(
1352
- s.slots,
1353
- Le({
1354
- dashboard: t,
1355
- dashboardInputValues: i.dashboardInputValues,
1356
- sheetId: i.sheetId,
1357
- cardId: i.cardId
1358
- })
1359
- ) : s.slots
1360
- },
1361
- o
1362
- ),
1363
- cardViewState: i ? Tn(i.cardViewState) : {}
1364
- }, c = i ? Wt(i.transientContexts) : void 0;
1365
- return {
1366
- runtimeValues: a,
1367
- controlOverrides: r,
1368
- ...c != null && c.length ? { transientContexts: c } : {}
1369
- };
1370
- }
1371
- function ye(e) {
1372
- const t = j(e.filter);
1373
- return {
1374
- inputId: e.inputId,
1375
- filterId: e.filterId,
1376
- label: e.label,
1377
- selection: e.selection,
1378
- owner: t ? { kind: "global_date" } : {
1379
- kind: "field_date",
1380
- filterId: e.filterId,
1381
- label: e.label
1382
- }
1383
- };
1384
- }
1385
- function eo(e) {
1386
- var s, i;
1387
- if ((s = e.card.sql) != null && s.trim())
1388
- return {
1389
- inputs: e.inputs,
1390
- fieldCandidates: [],
1391
- resolution: { status: "none" }
1392
- };
1393
- const t = e.inputs.filter((r) => !j(r.filter)).map((r) => ({
1394
- input: r,
1395
- resolution: Tt({
1396
- filter: r.filter,
1397
- filterValue: r.filterValue,
1398
- effectiveFilterValue: r.effectiveFilterValue,
1399
- mappedFilterValue: r.mappedFilterValue,
1400
- temporalBinding: e.temporalBinding,
1401
- card: e.card
1402
- })
1403
- }));
1404
- if (!e.temporalBinding)
1405
- return { inputs: e.inputs, fieldCandidates: t, resolution: { status: "none" } };
1406
- const n = e.inputs.find(
1407
- (r) => j(r.filter)
1408
- );
1409
- if (n && ((i = n.filterValue) == null ? void 0 : i.filterId) === n.filterId && n.effectiveFilterValue.filterId === n.filterId && Ot(n.effectiveFilterValue))
1410
- return {
1411
- inputs: e.inputs,
1412
- fieldCandidates: t,
1413
- resolution: {
1414
- status: "resolved",
1415
- resolvedOwner: ye(n)
1416
- }
1417
- };
1418
- const o = t.filter(
1419
- (r) => r.resolution.status === "eligible"
1420
- );
1421
- return o.length === 1 ? {
1422
- inputs: e.inputs,
1423
- fieldCandidates: t,
1424
- resolution: {
1425
- status: "resolved",
1426
- resolvedOwner: ye(o[0].input)
1427
- }
1428
- } : o.length > 1 ? {
1429
- inputs: e.inputs,
1430
- fieldCandidates: t,
1431
- resolution: {
1432
- status: "ambiguous",
1433
- candidateInputIds: o.map(
1434
- (r) => r.input.inputId
1435
- )
1436
- }
1437
- } : { inputs: e.inputs, fieldCandidates: t, resolution: { status: "none" } };
1438
- }
1439
- function bs(e) {
1440
- var n, o;
1441
- const t = {
1442
- ownerCardCount: 0,
1443
- matchingCardCount: 0,
1444
- globalPrecedenceCardCount: 0,
1445
- ambiguousCardCount: 0,
1446
- authorControlledCardCount: 0
1447
- };
1448
- for (const s of e.targets) {
1449
- const i = s.plan.fieldCandidates.find(
1450
- (a) => a.input.inputId === e.inputId
1451
- );
1452
- if (!i || i.resolution.status !== "eligible") continue;
1453
- t.matchingCardCount += 1;
1454
- const { resolution: r } = s.plan;
1455
- r.status === "resolved" && r.resolvedOwner.inputId === e.inputId ? t.ownerCardCount += 1 : r.status === "resolved" && r.resolvedOwner.owner.kind === "global_date" ? t.globalPrecedenceCardCount += 1 : r.status === "ambiguous" && r.candidateInputIds.includes(e.inputId) && (t.ambiguousCardCount += 1), (((n = s.card.preferences) == null ? void 0 : n.inheritGlobalComparison) === !1 || (((o = s.card.config) == null ? void 0 : o.metricColumns) || []).some(
1456
- (a) => a.comparison !== void 0
1457
- )) && (t.authorControlledCardCount += 1);
1458
- }
1459
- return t;
1460
- }
1461
- const to = /* @__PURE__ */ new Set([
1462
- "between",
1463
- "not between",
1464
- "=",
1465
- "!=",
1466
- ">",
1467
- ">=",
1468
- "<",
1469
- "<=",
1470
- "is null",
1471
- "is not null"
1472
- ]), no = /^(\d{4}-\d{2}-\d{2})T/, oo = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}(?::\d{2}(?:\.\d{1,9})?)?(?:Z|[+-]\d{2}:\d{2})$/;
1473
- function me(e) {
1474
- return to.has(e);
1475
- }
1476
- function so(e, t) {
1477
- if (e instanceof Date)
1478
- return Number.isNaN(e.getTime()) ? e : t ? he(e, t, "yyyy-MM-dd") : e.toISOString().slice(0, 10);
1479
- if (typeof e != "string")
1480
- return e;
1481
- const n = e.trim();
1482
- if (t && oo.test(n)) {
1483
- const s = new Date(n);
1484
- if (!Number.isNaN(s.getTime()))
1485
- return he(s, t, "yyyy-MM-dd");
1486
- }
1487
- const o = no.exec(n);
1488
- return o ? o[1] : e;
1489
- }
1490
- function it(e, t) {
1491
- return Array.isArray(e) ? e.map(
1492
- (n) => so(n, t)
1493
- ) : e;
1494
- }
1495
- function rt(e) {
1496
- return typeof e.allowMinutePrecision == "boolean" ? e.allowMinutePrecision : ie(
1497
- e.dashboard,
1498
- e.semanticExecutionPayload
1499
- ).allEligibleTargetsAreDateTime;
1500
- }
1501
- function at(e) {
1502
- const {
1503
- globalDateFilter: t,
1504
- globalDateFilterValue: n,
1505
- timezone: o,
1506
- allowMinutePrecision: s = !1
1507
- } = e;
1508
- if (!t || !n)
1509
- return;
1510
- if (!me(n.operation))
1511
- return {
1512
- ...n,
1513
- filterId: t.id
1514
- };
1515
- const i = n, r = i.temporalPrecision === "minute" || $(i.relativeMeta), a = !s && r, c = i.operation === "is null" || i.operation === "is not null" ? [] : a ? it(i.values, o) : i.values, d = s || !$(i.relativeMeta) ? i.relativeMeta : void 0, l = s && i.temporalPrecision === "minute" ? i.temporalPrecision : void 0, {
1516
- relativeMeta: u,
1517
- temporalPrecision: f,
1518
- values: p,
1519
- ...m
1520
- } = n;
1521
- return {
1522
- ...m,
1523
- filterId: t.id,
1524
- values: c,
1525
- ...d ? { relativeMeta: d } : {},
1526
- ...l ? { temporalPrecision: l } : {}
1527
- };
1528
- }
1529
- function io(e) {
1530
- const t = z(e.filters);
1531
- if (!t)
1532
- return e.filterValues;
1533
- const n = rt(e);
1534
- return e.filterValues.map((o) => o.filterId !== t.id ? o : at({
1535
- globalDateFilter: t,
1536
- globalDateFilterValue: o,
1537
- timezone: e.timezone,
1538
- allowMinutePrecision: n
1539
- }) || o);
1540
- }
1541
- function lt(e) {
1542
- const {
1543
- globalDateFilter: t,
1544
- globalDateFilterValue: n,
1545
- resolvedPrimaryDateField: o,
1546
- semanticContext: s,
1547
- timezone: i,
1548
- allowMinutePrecision: r = !1
1549
- } = e;
1550
- if (!t || !n || !o || !me(n.operation))
1551
- return null;
1552
- const a = n, c = xt(
1553
- o.dataType
1554
- ), d = r && c, l = a.temporalPrecision === "minute" || $(a.relativeMeta), u = d && a.temporalPrecision === "minute" ? a.temporalPrecision : void 0, f = d || !$(a.relativeMeta) ? a.relativeMeta : void 0, p = !d && l;
1555
- return {
1556
- filterId: t.id,
1557
- dateOwner: "global_date",
1558
- name: o.qualifiedFieldName || o.name,
1559
- operation: a.operation,
1560
- valueType: "date",
1561
- values: a.operation === "is null" || a.operation === "is not null" ? [] : p ? it(
1562
- a.values,
1563
- i
1564
- ) : a.values,
1565
- dataType: o.dataType || "date",
1566
- // The exact type travels with the filter, so the server formats the predicate for
1567
- // the column's storage type (it read it from `dataType` before 2.1 split the two).
1568
- ...o.nativeDataType ? { nativeDataType: o.nativeDataType } : {},
1569
- fieldMeta: {
1570
- name: o.name,
1571
- qualifiedFieldName: o.qualifiedFieldName,
1572
- qualifiedEntityName: o.qualifiedEntityName,
1573
- entityId: o.entityId,
1574
- entityName: o.entityName,
1575
- entityType: o.entityType,
1576
- dataType: o.dataType,
1577
- ...o.nativeDataType ? { nativeDataType: o.nativeDataType } : {},
1578
- role: "groupby",
1579
- ...t != null && t.title ? { label: t.title } : {}
1580
- },
1581
- ...s ? { semanticContext: s } : {},
1582
- ...f ? { relativeMeta: f } : {},
1583
- ...u ? { temporalPrecision: u } : {}
1584
- };
1585
- }
1586
- function w(e) {
1587
- return typeof e == "string" ? e.trim() : "";
1588
- }
1589
- function ro(e) {
1590
- var t;
1591
- return (((t = e.semanticContext) == null ? void 0 : t.selectedEntities) || []).filter((n) => typeof n == "object" && n !== null).filter((n) => n.type === "dataset").map((n) => {
1592
- var o;
1593
- return {
1594
- domainId: w(n.domainId) || w((o = e.semanticContext) == null ? void 0 : o.semanticDomainId),
1595
- datasetName: w(n.name),
1596
- selectedEntityId: w(n.id)
1597
- };
1598
- }).filter((n) => n.domainId && n.datasetName);
1599
- }
1600
- function ao(e) {
1601
- var c, d, l, u, f;
1602
- if (j(e) || (c = e.sql) != null && c.trim())
1603
- return null;
1604
- const t = ro(e), n = w((d = e.semanticContext) == null ? void 0 : d.semanticDomainId), o = w((l = e.fieldMeta) == null ? void 0 : l.entityId), s = w((u = e.fieldMeta) == null ? void 0 : u.entityName), i = w((f = e.fieldMeta) == null ? void 0 : f.entityType) === "dataset", r = t.find(
1605
- (p) => o && p.selectedEntityId === o
1606
- );
1607
- if (r)
1608
- return r;
1609
- const a = t.find(
1610
- (p) => s && p.datasetName === s && (!n || p.domainId === n)
1611
- );
1612
- return a || (t.length === 1 ? t[0] : i && s && n ? {
1613
- domainId: n,
1614
- datasetName: s
1615
- } : null);
1616
- }
1617
- function lo(e) {
1618
- var s, i;
1619
- const { filter: t, semanticExecutionPayload: n } = e;
1620
- if (!n)
1621
- return null;
1622
- const o = ao(t);
1623
- return o && ((i = (s = n.domainsById[o.domainId]) == null ? void 0 : s.datasetsByName[o.datasetName]) == null ? void 0 : i.primaryDateField) || null;
1624
- }
1625
- function dt(e) {
1626
- const t = z(e.filters);
1627
- return t ? e.filterValues.filter(
1628
- (n) => n.filterId !== t.id
1629
- ) : e.filterValues;
1630
- }
1631
- function hs(e) {
1632
- const t = z(e.filters), n = dt({
1633
- filters: e.filters,
1634
- filterValues: e.filterValues
1635
- });
1636
- if (!t || j(e.filter))
1637
- return n;
1638
- const o = e.filterValues.find(
1639
- (r) => r.filterId === t.id
1640
- ), s = lo({
1641
- filter: e.filter,
1642
- semanticExecutionPayload: e.semanticExecutionPayload
1643
- }), i = lt({
1644
- globalDateFilter: t,
1645
- globalDateFilterValue: o,
1646
- resolvedPrimaryDateField: s || void 0,
1647
- semanticContext: e.filter.semanticContext,
1648
- timezone: e.timezone,
1649
- allowMinutePrecision: e.allowMinutePrecision
1650
- });
1651
- return i ? [i, ...n] : n;
1652
- }
1653
- function co(e) {
1654
- var l;
1655
- const t = z(e.filters), n = t ? e.cardFilterValues.find(
1656
- (u) => u.filterId === t.id
1657
- ) : void 0, o = t ? e.cardFilterValues.filter(
1658
- (u) => u.filterId !== t.id
1659
- ) : e.cardFilterValues, s = e.resolvedPrimaryDateField ?? ke({
1660
- card: e.card,
1661
- cardConfig: e.cardConfig,
1662
- resolvedFields: e.resolvedFields,
1663
- semanticExecutionPayload: e.semanticExecutionPayload
1664
- }), i = lt({
1665
- globalDateFilter: t,
1666
- globalDateFilterValue: n,
1667
- resolvedPrimaryDateField: s || void 0,
1668
- timezone: e.timezone,
1669
- allowMinutePrecision: e.allowMinutePrecision
1670
- }), r = i ? [i, ...o] : o, a = new Map(
1671
- r.map((u) => [
1672
- u.filterId,
1673
- u
1674
- ])
1675
- ), c = ((l = e.dateComparisonInputs) == null ? void 0 : l.flatMap((u) => {
1676
- var p;
1677
- const f = a.get(
1678
- u.filterId
1679
- );
1680
- return f ? [{
1681
- ...u,
1682
- effectiveFilterValue: f,
1683
- mappedFilterValue: (p = e.mappedFilterValuesByInputId) == null ? void 0 : p.get(u.inputId)
1684
- }] : [];
1685
- })) || [], d = eo({
1686
- inputs: c,
1687
- temporalBinding: s,
1688
- card: e.card
1689
- });
1690
- return {
1691
- cardFilterValues: r,
1692
- resolvedPrimaryDateField: s,
1693
- dateComparisonPlan: d
1694
- };
1695
- }
1696
- function gs(e) {
1697
- const t = z(e.filters), n = rt(e), o = t ? e.filterValues.find(
1698
- (r) => r.filterId === t.id
1699
- ) : void 0, s = dt(e);
1700
- return !t || !o || !me(o.operation) ? s : [
1701
- {
1702
- ...at({
1703
- globalDateFilter: t,
1704
- globalDateFilterValue: o,
1705
- timezone: e.timezone,
1706
- allowMinutePrecision: n
1707
- }) || o,
1708
- filterId: t.id,
1709
- name: t.title || t.column
1710
- },
1711
- ...s
1712
- ];
1713
- }
1714
- class uo extends Error {
1715
- }
1716
- function Cs(e, t) {
1717
- const n = new Map((e ? B(e) : []).map(({ card: o }) => [o.id, o]));
1718
- return t && n.set(t.id, t), [...n.values()].flatMap((o) => {
1719
- const s = Ge(o);
1720
- return s.status === "ready" ? Zt(s.config.spec, o.controlBindings) : [];
1721
- });
1722
- }
1723
- function fo(e, t, n) {
1724
- const o = Dn(e);
1725
- if (!o) throw new Error("Matrix card definition is required.");
1726
- const s = n && Yt({
1727
- ...n,
1728
- spec: o.spec,
1729
- catalog: t.map((l) => ({ ...l, id: l.resolvedField.id }))
1730
- }), i = s ? { ...o, spec: s.spec } : o, r = wt(t), a = Pt(t), c = (l) => {
1731
- const u = a(l, i.spec.source);
1732
- if (!(!u && l.derivedField)) {
1733
- if (!u) throw new uo(`Matrix field metadata is unavailable: ${l.name}`);
1734
- return { ...u, ...l.derivedField ? { derivedField: l.derivedField } : {} };
1735
- }
1736
- }, d = {
1737
- rows: i.spec.rows.flatMap((l) => {
1738
- const u = c(l.field);
1739
- return u ? [{ ...u, id: l.id, granularity: l.grain, role: "groupby" }] : [];
1740
- }),
1741
- columns: i.spec.columns.flatMap((l) => {
1742
- const u = c(l.field);
1743
- return u ? [{ ...u, id: l.id, granularity: l.grain, role: "pivotby" }] : [];
1744
- }),
1745
- // Aggregate-stage expressions have no source-column filter target. They stay
1746
- // authoritative in matrix.spec, including all dependencies and controls.
1747
- metrics: i.spec.measures.flatMap((l) => {
1748
- if (l.kind !== "aggregate" || l.field.name === "*") return [];
1749
- const u = c(l.field);
1750
- return u ? [{ ...u, id: l.id, aggregate: l.aggregate, role: "metric" }] : [];
1751
- })
1752
- };
1753
- return { config: i, fields: d, resolveField: r };
1754
- }
1755
- function po(e) {
1756
- const t = e.filter(Boolean);
1757
- if (t.length !== 0)
1758
- return t.length === 1 ? t[0] : {
1759
- id: Me(),
1760
- logicalOperator: "AND",
1761
- negate: !1,
1762
- conditions: [],
1763
- groups: t
1764
- };
1765
- }
1766
- function mo(e) {
1767
- if (!e) return;
1768
- const t = (n) => ({
1769
- logicalOperator: n.logicalOperator,
1770
- negate: n.negate,
1771
- conditions: n.conditions.map((o) => ({
1772
- field: o.field.id,
1773
- operator: o.operator,
1774
- value: o.value,
1775
- temporalBucket: o.temporalBucket,
1776
- // The run-time markers decide what runs, so they belong in the key.
1777
- relativeMeta: o.relativeMeta,
1778
- latestValue: o.latestValue
1779
- })),
1780
- groups: n.groups.map(t)
1781
- });
1782
- return JSON.stringify(t(e));
1783
- }
1784
- function Io(e, t) {
1785
- const n = e.metricColumns || [];
1786
- if (n.length === 0) return e;
1787
- const o = Et.includes(
1788
- t
1789
- ), s = Rt.includes(
1790
- t
1791
- ), i = (c) => {
1792
- var d;
1793
- return (d = c.parameters) != null && d.windowTransform ? {
1794
- ...c,
1795
- parameters: {
1796
- ...c.parameters,
1797
- windowTransform: void 0
1798
- }
1799
- } : c;
1800
- };
1801
- let r = !1;
1802
- const a = n.map(
1803
- (c) => {
1804
- var u;
1805
- const d = Jt(c);
1806
- if (d === "none")
1807
- return c;
1808
- let l = c;
1809
- return (u = l.parameters) != null && u.windowTransform && (r = !0, l = i(l)), o ? d === "target" && !s ? (r = !0, {
1810
- ...l,
1811
- comparison: void 0
1812
- }) : l : (r = !0, { ...l, comparison: void 0 });
1813
- }
1814
- );
1815
- return r ? {
1816
- ...e,
1817
- metricColumns: a
1818
- } : e;
1819
- }
1820
- function vs(e, t = {}) {
1821
- return ct(ut(e, t));
1822
- }
1823
- function ct(e) {
1824
- return po([e.authored, e.drill, e.selections]);
1825
- }
1826
- function ut(e, t = {}) {
1827
- return {
1828
- authored: t.includeAuthoredFilters === !1 ? void 0 : Bt(e),
1829
- drill: En(t.drill, e.id),
1830
- selections: Fn(t.selections ?? [])
1831
- };
1832
- }
1833
- function bo(e, t, n) {
1834
- const o = wn(e, t);
1835
- return Se(e) ? Io(
1836
- { ...o, filters: n },
1837
- e.type
1838
- ) : o;
1839
- }
1840
- function ho(e) {
1841
- const t = Xt(e);
1842
- return {
1843
- contextMode: t,
1844
- shouldApplyDashboardFilters: !t || t === "full"
1845
- };
1846
- }
1847
- function go(e) {
1848
- const t = e.dashboardControls || [], n = e.card.controls || [], o = /* @__PURE__ */ new Set([
1849
- ...t.map((s) => s.id),
1850
- ...n.map((s) => s.id)
1851
- ]);
1852
- return ft(
1853
- e.card,
1854
- {
1855
- controlValues: Oe({
1856
- relevantControlIds: o,
1857
- dashboardValues: e.dashboardControlValues,
1858
- cardValues: e.cardControlValues
1859
- }),
1860
- controlDefinitions: t,
1861
- cardControlDefinitions: n,
1862
- controlBindings: e.card.controlBindings || []
1863
- },
1864
- e.presentationControlIds
1865
- );
1866
- }
1867
- function ft(e, t, n) {
1868
- const s = t.controlBindings.filter(
1869
- (f) => !Te(f)
1870
- ), i = new Set(
1871
- en({
1872
- sql: e.sql,
1873
- controlBindings: s
1874
- })
1875
- ), r = new Set(
1876
- [...n].filter(
1877
- (f) => !i.has(f)
1878
- )
1879
- ), a = t.controlDefinitions.filter(
1880
- (f) => !r.has(f.id)
1881
- ), c = t.cardControlDefinitions.filter(
1882
- (f) => !r.has(f.id)
1883
- ), d = /* @__PURE__ */ new Set([
1884
- ...a.map((f) => f.id),
1885
- ...c.map((f) => f.id)
1886
- ]), l = s.filter(
1887
- (f) => d.has(f.controlId)
1888
- );
1889
- return {
1890
- controlValues: Oe({
1891
- relevantControlIds: d,
1892
- dashboardValues: t.controlValues
1893
- }),
1894
- controlDefinitions: a,
1895
- cardControlDefinitions: c,
1896
- controlBindings: l
1897
- };
1898
- }
1899
- function Co({
1900
- card: e,
1901
- dashboard: t,
1902
- transientContexts: n,
1903
- cardViewState: o,
1904
- viewerTableSettings: s,
1905
- adHocFilterValues: i,
1906
- selectedSheetId: r,
1907
- inlineFilterValuesMap: a,
1908
- dashboardControls: c,
1909
- dashboardControlValues: d,
1910
- cardControlValuesMap: l,
1911
- dashboardInputContext: u,
1912
- includeAuthoredFilters: f
1913
- }) {
1914
- var T;
1915
- const p = tn(t);
1916
- for (const F of e.controlBindings || [])
1917
- Te(F) && p.add(F.controlId);
1918
- const { shouldApplyDashboardFilters: m } = ho(n), I = u != null && u.inputs.length ? u : void 0, b = ut(e, {
1919
- includeAuthoredFilters: f,
1920
- // Blocked and skipped conditions are already projected away, so a
1921
- // selection can only ever narrow this card on its own fields. Carried
1922
- // selections are among them.
1923
- selections: ((u == null ? void 0 : u.selections) ?? []).filter(
1924
- (F) => F.status === "apply"
1925
- ),
1926
- drill: o == null ? void 0 : o.drill
1927
- }), y = ct(b), g = f === !1 ? nn(y, !0) : y, h = bo(
1928
- e,
1929
- o == null ? void 0 : o.drill,
1930
- g
1931
- ), v = on({ ...e, config: h }, s) ?? h, C = sn(v, {
1932
- cardType: e.type,
1933
- dataSource: e.dataSource,
1934
- temporalResultOwner: xe({
1935
- hasExecutableConfig: we(v, e.type),
1936
- sql: e.sql,
1937
- normalizedPython: Pe(e.python || "")
1938
- })
1939
- }) || v, k = mo(g) || "", H = I ? ft(
1940
- e,
1941
- {
1942
- controlValues: I.controlValues,
1943
- controlDefinitions: I.controlDefinitions,
1944
- cardControlDefinitions: I.cardControlDefinitions,
1945
- controlBindings: I.controlBindings
1946
- },
1947
- p
1948
- ) : go({
1949
- card: e,
1950
- presentationControlIds: p,
1951
- dashboardControls: c,
1952
- dashboardControlValues: d,
1953
- cardControlValues: l == null ? void 0 : l[e.id]
1954
- });
1955
- return {
1956
- filterCompilationInput: {
1957
- adHocFilterValues: i || [],
1958
- selectedSheetId: r,
1959
- inlineFilterValues: (a == null ? void 0 : a[e.id]) || [],
1960
- shouldApplyDashboardFilters: m,
1961
- ...I ? {
1962
- dashboardInputContext: {
1963
- inputs: I.inputs,
1964
- resolvedInputs: I.resolvedInputs,
1965
- activeFilters: I.activeFilters
1966
- }
1967
- } : {},
1968
- ...I != null && I.globalDateComparisonSelection ? {
1969
- globalDateComparisonSelection: I.globalDateComparisonSelection
1970
- } : {},
1971
- ...I != null && I.dateComparisonInputs ? {
1972
- dateComparisonInputs: I.dateComparisonInputs
1973
- } : {}
1974
- },
1975
- ...H,
1976
- resolvedFilters: g,
1977
- resolvedFilterParts: b,
1978
- drillSteps: ((T = o == null ? void 0 : o.drill) == null ? void 0 : T.steps) ?? Vn,
1979
- finalConfig: v,
1980
- queryRelevantConfig: C,
1981
- finalFiltersKey: k
1982
- };
1983
- }
1984
- function pt(e, t, n) {
1985
- var o;
1986
- if (t)
1987
- return {
1988
- selection: t,
1989
- ...((o = e.preferences) == null ? void 0 : o.inheritGlobalComparison) === !1 ? { inheritGlobalComparison: !1 } : {},
1990
- ...n ? { owner: n } : {}
1991
- };
1992
- }
1993
- function vo(e) {
1994
- if (e.resolution.status === "resolved")
1995
- return pt(
1996
- e.card,
1997
- e.resolution.resolvedOwner.selection,
1998
- e.resolution.resolvedOwner.owner
1999
- );
2000
- }
2001
- function yo(e) {
2002
- return `Set ${e.join(", ")} to run this card.`;
2003
- }
2004
- function Do({
2005
- dashboardInputContext: e,
2006
- shouldApplyDashboardFilters: t
2007
- }) {
2008
- if (t)
2009
- return e.activeFilters;
2010
- const n = new Set(
2011
- e.inputs.flatMap(
2012
- (o) => o.kind === "filter" && Ee(o) ? [o.filter.id] : []
2013
- )
2014
- );
2015
- return e.activeFilters.filter(
2016
- (o) => n.has(o.filterId)
2017
- );
2018
- }
2019
- function So({
2020
- dashboardInputFilterValues: e,
2021
- adHocFilterValues: t
2022
- }) {
2023
- const n = [...e], o = new Set(
2024
- n.map((s) => s.filterId)
2025
- );
2026
- for (const s of t)
2027
- o.has(s.filterId) || (n.push(s), o.add(s.filterId));
2028
- return n;
2029
- }
2030
- function ee(e, t) {
2031
- const n = t.shouldApplyDashboardFilters ? rn(t.adHocFilterValues, t.selectedSheetId) : [];
2032
- if (!t.dashboardInputContext)
2033
- return {
2034
- status: "ready",
2035
- filterValues: [...n, ...t.inlineFilterValues],
2036
- mappingDispositions: []
2037
- };
2038
- const o = t.dashboardInputContext.inputs.filter(
2039
- (l) => l.kind === "filter" && !!l.application
2040
- ), s = new Set(
2041
- o.map((l) => l.filter.id)
2042
- ), i = new Set(
2043
- t.dashboardInputContext.inputs.flatMap(
2044
- (l) => {
2045
- var u;
2046
- return l.kind === "filter" && ((u = l.compatibility) == null ? void 0 : u.source) === "cardInlineFilter" ? [l.filter.id] : [];
2047
- }
2048
- )
2049
- ), r = Do({
2050
- dashboardInputContext: t.dashboardInputContext,
2051
- shouldApplyDashboardFilters: t.shouldApplyDashboardFilters
2052
- }).filter((l) => !s.has(l.filterId)), a = r.filter(
2053
- (l) => !i.has(l.filterId)
2054
- ), c = r.filter(
2055
- (l) => i.has(l.filterId)
2056
- ), d = an({
2057
- card: e,
2058
- inputs: o,
2059
- resolvedInputs: t.dashboardInputContext.resolvedInputs,
2060
- activeFilterValues: t.dashboardInputContext.activeFilters,
2061
- shouldApplyDashboardFilters: t.shouldApplyDashboardFilters
2062
- });
2063
- return d.status === "blocked" ? {
2064
- status: "blocked",
2065
- mappingDispositions: d.dispositions
2066
- } : {
2067
- status: "ready",
2068
- filterValues: [
2069
- ...So({
2070
- dashboardInputFilterValues: [
2071
- ...a,
2072
- ...d.filterValues
2073
- ],
2074
- adHocFilterValues: n
2075
- }),
2076
- ...c
2077
- ],
2078
- mappingDispositions: d.dispositions
2079
- };
2080
- }
2081
- function Fo(e, t) {
2082
- const n = e.dashboardInputContext;
2083
- if (!n) return [];
2084
- const o = new Set(
2085
- t.flatMap(
2086
- (i) => i.status === "skip" && (i.reason === "explicitlyExcluded" || i.reason === "outsideScope") ? [i.inputId] : []
2087
- )
2088
- ), s = new Map(n.inputs.map((i) => [i.id, i]));
2089
- return n.resolvedInputs.flatMap((i) => {
2090
- if (!i.missingRequiredValue) return [];
2091
- const r = s.get(i.id);
2092
- return r ? r.kind === "filter" && (!e.shouldApplyDashboardFilters && !Ee(r) || o.has(r.id)) ? [] : [i.label] : [];
2093
- });
2094
- }
2095
- function Vo({
2096
- card: e,
2097
- cardConfig: t,
2098
- input: n,
2099
- resolvedPrimaryDateField: o,
2100
- resolvedFields: s,
2101
- semanticExecutionPayload: i,
2102
- timezone: r,
2103
- allowMinutePrecision: a
2104
- }) {
2105
- var I;
2106
- const c = n.dashboardInputContext ? n.dashboardInputContext.inputs.flatMap(
2107
- (b) => b.kind === "filter" ? [b.filter] : []
2108
- ) : [], d = ee(e, n), l = Fo(
2109
- n,
2110
- d.mappingDispositions
2111
- );
2112
- if (l.length)
2113
- return {
2114
- status: "blocked",
2115
- cardId: e.id,
2116
- reason: "requiredInput",
2117
- mappingDispositions: d.mappingDispositions,
2118
- missingRequiredLabels: l
2119
- };
2120
- if (d.status === "blocked")
2121
- return {
2122
- status: "blocked",
2123
- cardId: e.id,
2124
- reason: "mapping",
2125
- mappingDispositions: d.mappingDispositions,
2126
- missingRequiredLabels: []
2127
- };
2128
- const u = co({
2129
- card: e,
2130
- cardConfig: t,
2131
- filters: c,
2132
- cardFilterValues: d.filterValues,
2133
- resolvedPrimaryDateField: o,
2134
- resolvedFields: s,
2135
- semanticExecutionPayload: i,
2136
- timezone: r,
2137
- allowMinutePrecision: a,
2138
- dateComparisonInputs: n.dateComparisonInputs,
2139
- mappedFilterValuesByInputId: new Map(
2140
- d.mappingDispositions.flatMap(
2141
- (b) => b.status === "apply" ? [[b.inputId, b.filterValue]] : []
2142
- )
2143
- )
2144
- }), f = z(c), p = !!(f && u.cardFilterValues.some(
2145
- (b) => b.filterId === f.id
2146
- )), m = u.resolvedPrimaryDateField && !((I = e.sql) != null && I.trim()) ? u.dateComparisonPlan.inputs.length ? vo({
2147
- card: e,
2148
- resolution: u.dateComparisonPlan.resolution
2149
- }) : p ? pt(
2150
- e,
2151
- n.globalDateComparisonSelection
2152
- ) : void 0 : void 0;
2153
- return {
2154
- status: "ready",
2155
- ...u,
2156
- queryFilterDefinitions: c,
2157
- globalDateComparison: m,
2158
- mappingDispositions: d.mappingDispositions
2159
- };
2160
- }
2161
- function mt(e, t, n) {
2162
- const o = Vo({
2163
- resolvedFields: t.resolvedDateFields,
2164
- ...n,
2165
- card: e,
2166
- cardConfig: t.queryRelevantConfig,
2167
- input: t.filterCompilationInput
2168
- });
2169
- if (o.status === "blocked") return o;
2170
- const { filterCompilationInput: s, ...i } = t;
2171
- return { status: "ready", queryContext: {
2172
- ...i,
2173
- cardFilterValues: o.cardFilterValues,
2174
- queryFilterDefinitions: o.queryFilterDefinitions,
2175
- resolvedPrimaryDateField: o.resolvedPrimaryDateField,
2176
- globalDateComparison: o.globalDateComparison,
2177
- globalDateComparisonSelection: s.globalDateComparisonSelection,
2178
- dateComparisonInputs: s.dateComparisonInputs
2179
- }, compiledFilters: o };
2180
- }
2181
- function ko(e, t, n) {
2182
- const o = qt(e), s = mt(e, t, {
2183
- resolvedPrimaryDateField: n.resolvedPrimaryDateField,
2184
- timezone: n.calendarContext.tz,
2185
- allowMinutePrecision: n.allowGlobalDateMinutePrecision
2186
- });
2187
- if (s.status === "blocked")
2188
- return { ...s, tableConfig: o };
2189
- const { compiledFilters: i } = s, {
2190
- cardFilterValues: r,
2191
- resolvedPrimaryDateField: a,
2192
- globalDateComparison: c
2193
- } = i, { queryKey: d, queryInputIdentity: l, paginationConfig: u } = ln(
2194
- e,
2195
- s.queryContext,
2196
- n.calendarContext,
2197
- { resolvePaginationConfig: n.resolvePaginationConfig }
2198
- ), f = t.queryRelevantConfig, p = Pe(e.python || ""), m = xe({
2199
- hasExecutableConfig: we(f, e.type),
2200
- sql: e.sql,
2201
- normalizedPython: p
2202
- });
2203
- return {
2204
- status: "ready",
2205
- queryKey: d,
2206
- queryInputIdentity: l,
2207
- paginationConfig: u,
2208
- tableConfig: o,
2209
- compiledFilters: i,
2210
- requestPayloadBase: {
2211
- cardId: e.id,
2212
- sql: (e == null ? void 0 : e.sql) || "",
2213
- python: p,
2214
- resultOwner: m,
2215
- active_filters: r,
2216
- controlValues: t.controlValues,
2217
- controlDefinitions: t.controlDefinitions,
2218
- cardControlDefinitions: t.cardControlDefinitions,
2219
- controlBindings: t.controlBindings,
2220
- cache_config: n.globalCacheConfig,
2221
- queryConfig: e.queryConfig,
2222
- tableConfig: o,
2223
- cardType: e.type,
2224
- cardTitle: e.title || "",
2225
- cardConfig: f,
2226
- cardDataSource: e.dataSource,
2227
- resolvedPrimaryDateField: a || void 0,
2228
- calendarContext: n.calendarContext,
2229
- ...c ? { globalDateComparison: c } : {}
2230
- }
2231
- };
2232
- }
2233
- const De = [], Mo = [], To = {};
2234
- function ys(e, t) {
2235
- return {
2236
- sheetId: e.sheetId,
2237
- sectionId: e.sectionId,
2238
- documentFilterValues: e.documentFilterValues ?? De,
2239
- documentControlDefinitions: e.documentControlDefinitions ?? Mo,
2240
- documentControlValues: e.documentControlValues ?? To,
2241
- editorFilterValues: t ?? De
2242
- };
2243
- }
2244
- function Oo({
2245
- card: e,
2246
- dashboard: t,
2247
- runtime: n,
2248
- dashboardRuntimeValues: o,
2249
- calendar: s
2250
- }) {
2251
- const i = ze({
2252
- dashboard: t,
2253
- dashboardInputValues: o.dashboardInputValues,
2254
- transientContexts: void 0
2255
- }) ? re({
2256
- transientContexts: void 0,
2257
- dashboard: t,
2258
- sheetId: n.sheetId,
2259
- sheetKind: "document",
2260
- sectionId: n.sectionId,
2261
- card: e,
2262
- runtimeValues: {
2263
- ...o,
2264
- dashboardInputValues: n.documentDashboardInputValues || o.dashboardInputValues
2265
- },
2266
- calendar: s
2267
- }) : void 0, r = i && (i.inputs.length > 0 || i.selections.length > 0) ? i : void 0, a = !!(i != null && i.inputs.length), c = [
2268
- ...n.editorFilterValues || [],
2269
- ...n.documentFilterValues
2270
- ];
2271
- return {
2272
- card: a ? e : xo(
2273
- e,
2274
- n.documentControlDefinitions
2275
- ),
2276
- dashboard: t,
2277
- transientContexts: void 0,
2278
- // Document section cards do not drill.
2279
- cardViewState: void 0,
2280
- // Document section cards are not viewer-customizable tables.
2281
- viewerTableSettings: void 0,
2282
- adHocFilterValues: [],
2283
- inlineFilterValuesMap: !a && c.length ? { [e.id]: c } : {},
2284
- dashboardControls: [],
2285
- dashboardControlValues: {},
2286
- cardControlValuesMap: !a && Object.keys(n.documentControlValues).length > 0 ? { [e.id]: n.documentControlValues } : {},
2287
- dashboardInputContext: r
2288
- };
2289
- }
2290
- function xo(e, t) {
2291
- if (t.length === 0)
2292
- return e;
2293
- const n = /* @__PURE__ */ new Map();
2294
- for (const o of e.controls || [])
2295
- n.set(o.id, o);
2296
- for (const o of t)
2297
- n.set(o.id, o);
2298
- return {
2299
- ...e,
2300
- controls: Array.from(n.values())
2301
- };
2302
- }
2303
- function Ds({
2304
- card: e,
2305
- place: t,
2306
- source: n
2307
- }) {
2308
- const o = te(e, t, n);
2309
- return {
2310
- card: o.card,
2311
- context: o.context,
2312
- inputContext: o.inputContext
2313
- };
2314
- }
2315
- function wo(e, t, n) {
2316
- return {
2317
- calendarContext: n ?? Sn,
2318
- allowGlobalDateMinutePrecision: ie(
2319
- e,
2320
- t
2321
- ).allEligibleTargetsAreDateTime,
2322
- semanticExecutionPayload: t,
2323
- globalCacheConfig: e.globalCacheConfig
2324
- };
2325
- }
2326
- function Ss(e, t) {
2327
- return bt(
2328
- e,
2329
- t,
2330
- t.allowGlobalDateMinutePrecision
2331
- );
2332
- }
2333
- function Po(e, t, n = {}) {
2334
- const o = It(e, t);
2335
- return {
2336
- ...ko(e.card, e.context, {
2337
- resolvedPrimaryDateField: o,
2338
- calendarContext: t.calendarContext,
2339
- allowGlobalDateMinutePrecision: t.allowGlobalDateMinutePrecision,
2340
- globalCacheConfig: t.globalCacheConfig,
2341
- resolvePaginationConfig: n.resolvePaginationConfig
2342
- }),
2343
- resolvedPrimaryDateField: o
2344
- };
2345
- }
2346
- function Eo({
2347
- card: e,
2348
- place: t,
2349
- source: n,
2350
- semanticExecutionPayload: o,
2351
- matrixCatalog: s,
2352
- withRequest: i = !1
2353
- }) {
2354
- var I, b;
2355
- const { dashboard: r } = n, a = e.id, c = (y, g) => {
2356
- var v;
2357
- let h;
2358
- try {
2359
- const C = Ge(y);
2360
- if (C.status === "invalid") throw C.error;
2361
- const k = te(
2362
- y,
2363
- g,
2364
- n,
2365
- C.status === "absent"
2366
- );
2367
- if (h = k.context, C.status === "absent")
2368
- return { status: "ready", value: { assembled: k } };
2369
- if (!s)
2370
- return {
2371
- status: "blocked",
2372
- reason: "metadata",
2373
- message: "Matrix field metadata is required.",
2374
- context: h
2375
- };
2376
- const H = un(C.config.spec, h), T = s.filter(
2377
- (D) => D.field.source && H.some(
2378
- (O) => bn(O, D.field.source)
2379
- )
2380
- ), F = fo(y, T, h), { params: P } = k, x = P.dashboardInputContext;
2381
- F.config = {
2382
- ...F.config,
2383
- presentation: fn(
2384
- y,
2385
- F.config,
2386
- {
2387
- controls: x ? [
2388
- ...x.controlDefinitions,
2389
- ...x.cardControlDefinitions
2390
- ] : [
2391
- ...P.dashboardControls ?? r.controls ?? [],
2392
- ...P.card.controls ?? []
2393
- ],
2394
- values: (x == null ? void 0 : x.controlValues) ?? {
2395
- ...P.dashboardControlValues,
2396
- ...(v = P.cardControlValuesMap) == null ? void 0 : v[y.id]
2397
- }
2398
- },
2399
- T
2400
- )
2401
- };
2402
- const q = {
2403
- ...y,
2404
- config: { matrix: F.config }
2405
- }, S = te(q, g, n, !1);
2406
- return {
2407
- status: "ready",
2408
- value: {
2409
- assembled: {
2410
- card: q,
2411
- context: { ...S.context, resolvedDateFields: F.fields },
2412
- inputContext: S.inputContext
2413
- },
2414
- matrix: F
2415
- }
2416
- };
2417
- } catch (C) {
2418
- return {
2419
- status: "blocked",
2420
- reason: "configuration",
2421
- message: C instanceof Error ? C.message : "Card configuration is invalid.",
2422
- context: h
2423
- };
2424
- }
2425
- }, d = c(e, t);
2426
- if (d.status === "blocked")
2427
- return {
2428
- status: "blocked",
2429
- cardId: a,
2430
- mappingDispositions: [],
2431
- reason: d.reason,
2432
- missingRequiredLabels: [],
2433
- message: d.message
2434
- };
2435
- const { assembled: l, matrix: u } = d.value, f = wo(
2436
- r,
2437
- o,
2438
- n.calendar
2439
- ), p = l.context.filterCompilationInput, m = At(r);
2440
- try {
2441
- const y = ee(l.card, p), g = u && m && y.status === "ready" && y.filterValues.some((k) => k.filterId === m.id);
2442
- let h = f.allowGlobalDateMinutePrecision;
2443
- if (g) {
2444
- const k = (I = p.dashboardInputContext) == null ? void 0 : I.inputs.find(
2445
- (S) => S.kind === "filter" && S.filter.id === m.id
2446
- ), T = Nt(r, m).filter(
2447
- ({ card: S, sheet: D }) => !k || W(k, {
2448
- cardId: S.id,
2449
- sheetId: D.id,
2450
- sheetKind: Re(D) ? "document" : "dashboard"
2451
- })
2452
- ).map(({ card: S, sheet: D }) => ({
2453
- card: S,
2454
- value: S.id === a ? d : c(S, { kind: "sheet", sheetId: D.id })
2455
- })), F = new Map(
2456
- T.map(({ card: S, value: D }) => [
2457
- S.id,
2458
- D.status === "ready" ? D.value.assembled.card : null
2459
- ])
2460
- ), P = new Map(
2461
- T.map(({ card: S, value: D }) => {
2462
- var O;
2463
- return [
2464
- S.id,
2465
- D.status === "ready" ? (O = D.value.matrix) == null ? void 0 : O.fields : void 0
2466
- ];
2467
- })
2468
- ), x = T.flatMap(
2469
- ({ card: S, value: D }) => {
2470
- const O = S.id, Ie = D.status === "ready" ? D.value.assembled.context : D.context;
2471
- if (!Ie) return [O];
2472
- const gt = D.status === "ready" ? D.value.assembled.card : S;
2473
- try {
2474
- const be = ee(
2475
- gt,
2476
- Ie.filterCompilationInput
2477
- );
2478
- return be.status === "blocked" || be.filterValues.some((Ct) => Ct.filterId === m.id) ? [O] : [];
2479
- } catch {
2480
- return F.set(O, null), [O];
2481
- }
2482
- }
2483
- ), q = ie(
2484
- r,
2485
- o,
2486
- m,
2487
- F,
2488
- P,
2489
- x
2490
- );
2491
- if ((b = q.unresolvedCardIds) != null && b.length)
2492
- return {
2493
- status: "blocked",
2494
- cardId: a,
2495
- mappingDispositions: [],
2496
- reason: "coverage",
2497
- missingRequiredLabels: [],
2498
- message: `Date precision requires field metadata and valid inputs for: ${q.unresolvedCardIds.join(", ")}.`
2499
- };
2500
- h = q.allEligibleTargetsAreDateTime;
2501
- }
2502
- const v = bt(l, f, h);
2503
- if (v.status === "blocked")
2504
- return {
2505
- status: "blocked",
2506
- cardId: v.cardId,
2507
- mappingDispositions: v.mappingDispositions,
2508
- reason: v.reason,
2509
- missingRequiredLabels: v.missingRequiredLabels,
2510
- ...v.reason === "requiredInput" ? { message: yo(v.missingRequiredLabels) } : {}
2511
- };
2512
- const C = i && !u ? Po(l, f) : void 0;
2513
- return {
2514
- ...v,
2515
- ...u ? { matrix: u } : {},
2516
- // The whole request a card runs with: the contract's payload and its
2517
- // extras (server pagination, table totals) from the one extras owner,
2518
- // on the first page a new viewer opens (ledger P3-78).
2519
- ...(C == null ? void 0 : C.status) === "ready" ? {
2520
- request: {
2521
- ...C.requestPayloadBase,
2522
- ...dn({
2523
- card: l.card,
2524
- finalConfig: l.context.finalConfig,
2525
- documentSection: t.kind === "documentSection" ? {} : void 0,
2526
- page: cn(l.card)
2527
- })
2528
- }
2529
- } : {}
2530
- };
2531
- } catch (y) {
2532
- return {
2533
- status: "blocked",
2534
- cardId: a,
2535
- mappingDispositions: [],
2536
- reason: "configuration",
2537
- missingRequiredLabels: [],
2538
- message: y instanceof Error ? y.message : "Card filter configuration is invalid."
2539
- };
2540
- }
2541
- }
2542
- function Ro(e) {
2543
- const t = e.editor ? {
2544
- ...e.inlineFilterValuesMap,
2545
- ...Object.fromEntries(
2546
- Object.entries(e.editor.inlineFilterValuesMap).filter(
2547
- (n) => n[1] !== void 0
2548
- )
2549
- )
2550
- } : e.inlineFilterValuesMap;
2551
- return {
2552
- dashboardInputValues: e.dashboardInputValues,
2553
- adHocFilterValues: e.adHocFilterValues,
2554
- controlValues: e.controlValues,
2555
- inlineFilterValuesMap: t,
2556
- cardControlValuesMap: e.cardControlValuesMap
2557
- };
2558
- }
2559
- function te(e, t, n, o) {
2560
- const { dashboard: s } = n, i = Ro(n), r = t.kind === "documentSection" ? {
2561
- ...Oo({
2562
- card: e,
2563
- dashboard: s,
2564
- runtime: t.section,
2565
- dashboardRuntimeValues: i,
2566
- calendar: n.calendar
2567
- }),
2568
- selectedSheetId: t.section.sheetId,
2569
- includeAuthoredFilters: o
2570
- } : Bo(e, t.sheetId, n, i, o);
2571
- return {
2572
- card: r.card,
2573
- params: r,
2574
- context: Co(r),
2575
- inputContext: r.dashboardInputContext
2576
- };
2577
- }
2578
- function Bo(e, t, n, o, s) {
2579
- var c, d;
2580
- const { dashboard: i, transientContexts: r } = n, a = ze({
2581
- dashboard: i,
2582
- dashboardInputValues: o.dashboardInputValues,
2583
- transientContexts: r
2584
- }) ? re({
2585
- transientContexts: r,
2586
- dashboard: i,
2587
- sheetId: t,
2588
- card: e,
2589
- runtimeValues: o,
2590
- calendar: n.calendar
2591
- }) : void 0;
2592
- return {
2593
- card: e,
2594
- dashboard: i,
2595
- transientContexts: r,
2596
- cardViewState: (c = n.cardViewStates) == null ? void 0 : c[e.id],
2597
- viewerTableSettings: n.editor || (d = n.viewerTableSettings) == null ? void 0 : d[e.id],
2598
- adHocFilterValues: o.adHocFilterValues,
2599
- selectedSheetId: t,
2600
- inlineFilterValuesMap: o.inlineFilterValuesMap,
2601
- dashboardControls: i.controls,
2602
- dashboardControlValues: o.controlValues,
2603
- cardControlValuesMap: o.cardControlValuesMap,
2604
- // Keep a selection-only context so the query has one resolved-input contract.
2605
- dashboardInputContext: a && (a.inputs.length > 0 || a.selections.length > 0) ? a : void 0,
2606
- includeAuthoredFilters: s
2607
- };
2608
- }
2609
- function It({ card: e, context: t }, n) {
2610
- return ke({
2611
- card: e,
2612
- cardConfig: t.queryRelevantConfig,
2613
- resolvedFields: t.resolvedDateFields,
2614
- semanticExecutionPayload: n.semanticExecutionPayload
2615
- });
2616
- }
2617
- function bt(e, t, n) {
2618
- const { card: o } = e, s = It(e, t), i = mt(o, e.context, {
2619
- resolvedPrimaryDateField: s,
2620
- timezone: t.calendarContext.tz,
2621
- allowMinutePrecision: n
2622
- });
2623
- return i.status === "blocked" ? { ...i, card: o, resolvedPrimaryDateField: s } : {
2624
- status: "ready",
2625
- card: o,
2626
- queryContext: i.queryContext,
2627
- compiledFilters: i.compiledFilters,
2628
- resolvedPrimaryDateField: s
2629
- };
2630
- }
2631
- function Fs({
2632
- dashboard: e,
2633
- dashboardInputValues: t,
2634
- adHocFilterValues: n,
2635
- calendar: o,
2636
- selectedSheetId: s,
2637
- sheetSelection: i = "current",
2638
- dashboardControlValues: r,
2639
- cardControlValuesMap: a,
2640
- semanticExecutionPayload: c,
2641
- timezone: d
2642
- }) {
2643
- const l = e ? [...Be(e)] : void 0, u = s ?? null, f = (g) => {
2644
- var h;
2645
- return e ? pn({
2646
- dashboard: e,
2647
- runtimeValues: { dashboardInputValues: t },
2648
- adHocFilterValues: n,
2649
- sheetId: g,
2650
- sheetKind: Re(
2651
- (h = e.sheets) == null ? void 0 : h.find((v) => v.id === g)
2652
- ) ? "document" : "dashboard",
2653
- calendar: o
2654
- }) : [];
2655
- }, p = i === "all" ? Array.from(
2656
- new Map(
2657
- ((e == null ? void 0 : e.sheets) || []).flatMap(
2658
- (g) => f(g.id).map(
2659
- (h) => [h.filterId, h]
2660
- )
2661
- )
2662
- ).values()
2663
- ) : f(u), m = {
2664
- ...r || {}
2665
- }, I = i === "all" ? B({ sheets: (e == null ? void 0 : e.sheets) || [] }) : u ? B({ sheets: (e == null ? void 0 : e.sheets) || [] }).filter(
2666
- (g) => g.sheet.id === u
2667
- ) : [];
2668
- for (const g of I)
2669
- Object.assign(m, (a == null ? void 0 : a[g.card.id]) || {});
2670
- const b = zt({
2671
- filterDefinitions: l,
2672
- filterValues: p
2673
- }), y = io({
2674
- filters: l,
2675
- filterValues: b,
2676
- dashboard: e,
2677
- semanticExecutionPayload: c,
2678
- timezone: d
2679
- });
2680
- return {
2681
- selectedSheetId: u,
2682
- filterValues: y,
2683
- controlValues: m
2684
- };
2685
- }
2686
- function Vs({
2687
- dashboard: e,
2688
- cardId: t,
2689
- transientContexts: n,
2690
- cardViewStates: o,
2691
- viewerTableSettings: s,
2692
- semanticExecutionPayload: i,
2693
- adHocFilterValues: r,
2694
- inlineFilterValuesMap: a,
2695
- dashboardControlValues: c,
2696
- cardControlValuesMap: d,
2697
- dashboardInputValues: l,
2698
- calendar: u,
2699
- matrixCatalog: f,
2700
- cardOverride: p,
2701
- sheetId: m,
2702
- documentSection: I,
2703
- editor: b,
2704
- withRequest: y
2705
- }) {
2706
- var v;
2707
- if (!e)
2708
- return null;
2709
- p && !X(e, t) && m && (e = { ...e, sheets: (v = e.sheets) == null ? void 0 : v.map((C) => C.id === m ? { ...C, cards: [...C.cards ?? [], p] } : C) });
2710
- const g = X(e, t);
2711
- if (!g)
2712
- return null;
2713
- const h = Eo({
2714
- card: p ?? g.card,
2715
- place: I ? { kind: "documentSection", section: I } : { kind: "sheet", sheetId: g.sheet.id },
2716
- source: {
2717
- dashboard: e,
2718
- adHocFilterValues: r,
2719
- controlValues: c,
2720
- inlineFilterValuesMap: a,
2721
- cardControlValuesMap: d ? Object.fromEntries(
2722
- Object.entries(d).filter(
2723
- (C) => C[1] !== void 0
2724
- )
2725
- ) : void 0,
2726
- dashboardInputValues: l,
2727
- transientContexts: n,
2728
- cardViewStates: o,
2729
- viewerTableSettings: s,
2730
- calendar: u,
2731
- ...b ? { editor: b } : {}
2732
- },
2733
- semanticExecutionPayload: i,
2734
- matrixCatalog: f,
2735
- withRequest: y
2736
- });
2737
- return h.status === "blocked" ? h : {
2738
- status: "ready",
2739
- card: p ?? g.card,
2740
- sheetId: g.sheet.id,
2741
- queryContext: h.queryContext,
2742
- ...h.matrix ? { matrix: h.matrix } : {},
2743
- ...h.request ? { request: h.request } : {}
2744
- };
2745
- }
2746
- function qo(e, t) {
2747
- const n = jt({
2748
- inputs: e.inputs,
2749
- dashboardFilters: [...Be(e)]
2750
- }), o = ht(e, t);
2751
- return n.filter(
2752
- (s) => W(s, { sheetId: t, sheetKind: "document" }) || s.kind === "filter" && (s.runtimeScope === "shared" || s.runtimeScope === "perSheet") && qe(s, o)
2753
- );
2754
- }
2755
- function ht(e, t) {
2756
- return {
2757
- ..._t(e).get(t) ?? {
2758
- sheetId: t,
2759
- cardIds: /* @__PURE__ */ new Set()
2760
- },
2761
- sheetKind: "document"
2762
- };
2763
- }
2764
- function ks(e, t) {
2765
- const n = ht(e, t);
2766
- return (e.inputs || []).some(
2767
- (o) => qe(o, n)
2768
- );
2769
- }
2770
- function Ao(e) {
2771
- const t = {
2772
- id: e.id,
2773
- label: e.label,
2774
- variableName: e.variableName,
2775
- requiredAtExecution: !!e.requiredAtExecution,
2776
- documentPlacement: "input_bar",
2777
- description: e.description
2778
- };
2779
- return e.kind === "filter" ? {
2780
- ...t,
2781
- kind: "filter",
2782
- filter: e.filter,
2783
- exports: e.exports
2784
- } : {
2785
- ...t,
2786
- kind: "control",
2787
- control: e.control,
2788
- exports: e.exports
2789
- };
2790
- }
2791
- function Ms({
2792
- control: e,
2793
- existingInputs: t,
2794
- sheetId: n,
2795
- inputId: o
2796
- }) {
2797
- const s = Ae(
2798
- e.id || e.label,
2799
- t
2800
- ), i = e.id === s ? e : { ...e, id: s };
2801
- return {
2802
- id: o || Me(),
2803
- kind: "control",
2804
- label: i.label,
2805
- variableName: s,
2806
- requiredAtExecution: i.requiredAtExecution,
2807
- scope: { kind: "sheets", sheetIds: [n] },
2808
- runtimeScope: "perSheet",
2809
- presentation: { placement: "toolbar" },
2810
- control: i,
2811
- exports: je(i)
2812
- };
2813
- }
2814
- function Ts({
2815
- input: e,
2816
- allInputs: t,
2817
- label: n,
2818
- variableName: o
2819
- }) {
2820
- const s = (n == null ? void 0 : n.trim()) || e.label, i = o === void 0 ? e.variableName : Ae(
2821
- o,
2822
- t.filter((a) => a.id !== e.id)
2823
- );
2824
- if (e.kind === "filter") {
2825
- if (!e.filter)
2826
- throw new Error(
2827
- `Referenced dashboard input '${e.id}' cannot be edited as a document input.`
2828
- );
2829
- const a = {
2830
- ...e.filter,
2831
- title: s,
2832
- variableName: i
2833
- };
2834
- return {
2835
- ...e,
2836
- label: s,
2837
- variableName: i,
2838
- filter: a,
2839
- exports: mn(a)
2840
- };
2841
- }
2842
- const r = {
2843
- ...e.control,
2844
- id: i,
2845
- label: s
2846
- };
2847
- return {
2848
- ...e,
2849
- label: s,
2850
- variableName: i,
2851
- requiredAtExecution: r.requiredAtExecution,
2852
- control: r,
2853
- exports: je(r)
2854
- };
2855
- }
2856
- function Os(e, t, n) {
2857
- return !t || !n || t === n ? e : {
2858
- ...e,
2859
- sections: e.sections.map(
2860
- (o) => yn(
2861
- o,
2862
- (s) => No(s, t, n)
2863
- )
2864
- )
2865
- };
2866
- }
2867
- function No(e, t, n) {
2868
- var i;
2869
- const o = `[[param.${t}]]`, s = `[[param.${n}]]`;
2870
- return {
2871
- ...e,
2872
- ...(i = e.sql) != null && i.includes(o) ? { sql: e.sql.split(o).join(s) } : {},
2873
- ...e.controls ? {
2874
- controls: e.controls.map(
2875
- (r) => r.id === t ? { ...r, id: n } : r
2876
- )
2877
- } : {},
2878
- ...e.controlBindings ? {
2879
- controlBindings: e.controlBindings.map((r) => ({
2880
- ...r,
2881
- controlId: r.controlId === t ? n : r.controlId,
2882
- ...r.target === "sql_param" && r.paramId === t ? { paramId: n } : {}
2883
- }))
2884
- } : {}
2885
- };
2886
- }
2887
- function xs(e, t) {
2888
- return e.kind === "filter" && In(
2889
- Ao(e),
2890
- t
2891
- );
2892
- }
2893
- function ws(e) {
2894
- var n;
2895
- const t = {};
2896
- for (const o of e)
2897
- o.kind === "filter" && (t[o.id] = ((n = o.slot) == null ? void 0 : n.status) === "cleared" ? void 0 : o.filterValue);
2898
- return t;
2899
- }
2900
- function Ps(e) {
2901
- var n;
2902
- const t = {};
2903
- for (const o of e)
2904
- o.kind === "control" && ((n = o.slot) == null ? void 0 : n.status) === "set" && (t[o.id] = o.controlValue);
2905
- return t;
2906
- }
2907
- function Es({
2908
- dashboard: e,
2909
- sheetId: t,
2910
- filterValuesByInputId: n,
2911
- controlValuesByInputId: o
2912
- }) {
2913
- const s = qo(e, t);
2914
- let i = {};
2915
- for (const r of s) {
2916
- if (r.kind === "filter" && n && Object.prototype.hasOwnProperty.call(n, r.id)) {
2917
- const a = n[r.id];
2918
- i = R(
2919
- i,
2920
- r,
2921
- { sheetId: t },
2922
- a ? {
2923
- status: "set",
2924
- value: {
2925
- kind: "filter",
2926
- filterValue: a
2927
- }
2928
- } : { status: "cleared" }
2929
- );
2930
- }
2931
- if (r.kind === "control" && o && Object.prototype.hasOwnProperty.call(o, r.id)) {
2932
- const a = o[r.id];
2933
- i = R(
2934
- i,
2935
- r,
2936
- { sheetId: t },
2937
- a === void 0 ? { status: "cleared" } : {
2938
- status: "set",
2939
- value: {
2940
- kind: "control",
2941
- value: a
2942
- }
2943
- }
2944
- );
2945
- }
2946
- }
2947
- return Le({
2948
- dashboard: e,
2949
- dashboardInputValues: i,
2950
- sheetId: t
2951
- });
2952
- }
2953
- export {
2954
- ps as $,
2955
- N as A,
2956
- On as B,
2957
- bo as C,
2958
- vs as D,
2959
- Ds as E,
2960
- Po as F,
2961
- ys as G,
2962
- gs as H,
2963
- Eo as I,
2964
- kn as J,
2965
- Cs as K,
2966
- hs as L,
2967
- bs as M,
2968
- at as N,
2969
- ee as O,
2970
- uo as P,
2971
- lt as Q,
2972
- Vn as R,
2973
- Ao as S,
2974
- xs as T,
2975
- Ts as U,
2976
- Os as V,
2977
- Es as W,
2978
- ws as X,
2979
- Ps as Y,
2980
- _ as Z,
2981
- rs as _,
2982
- ms as a,
2983
- fs as a0,
2984
- ks as a1,
2985
- Is as b,
2986
- as as c,
2987
- Vs as d,
2988
- Xn as e,
2989
- Ms as f,
2990
- qo as g,
2991
- ls as h,
2992
- Ss as i,
2993
- wo as j,
2994
- ds as k,
2995
- Jn as l,
2996
- us as m,
2997
- Ue as n,
2998
- cs as o,
2999
- os as p,
3000
- ns as q,
3001
- ho as r,
3002
- zn as s,
3003
- An as t,
3004
- ss as u,
3005
- Tn as v,
3006
- Le as w,
3007
- is as x,
3008
- yo as y,
3009
- Fs as z
3010
- };