react-semaphor 0.1.603 → 0.1.604

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (167) hide show
  1. package/dist/activity/index.js +1 -73
  2. package/dist/analytics-protocol/index.js +1 -1491
  3. package/dist/appearance/index.js +1 -12
  4. package/dist/appearance-runtime/index.js +1 -5
  5. package/dist/assistant-context/index.js +1 -11
  6. package/dist/assistant-protocol/index.js +1 -152
  7. package/dist/brand-studio/index.js +4 -1594
  8. package/dist/briefings/index.js +1 -70
  9. package/dist/chunks/add-to-dashboard-DeHEBEqG.js +12 -0
  10. package/dist/chunks/analytics-base-schemas-BREc5WGv.js +1 -0
  11. package/dist/chunks/appearance-context-BqBZrijL.js +1 -0
  12. package/dist/chunks/appearance-runtime-provider-DmbCrOOG.js +1 -0
  13. package/dist/chunks/applied-constraints-CinevlKD.js +1 -0
  14. package/dist/chunks/assistant-chat-CjYrwVDa.js +56 -0
  15. package/dist/chunks/attribution-BEFSsbNn.js +1 -0
  16. package/dist/chunks/availability-3AIOf6Z-.js +1 -0
  17. package/dist/chunks/bookmark-impact-C89zBLq3.js +1 -0
  18. package/dist/chunks/bookmark-state-69YYnRql.js +1 -0
  19. package/dist/chunks/brand-DCaZyRt6.js +1 -0
  20. package/dist/chunks/card-filter-builder-CTp6RAz1.js +17 -0
  21. package/dist/chunks/column-bands-DwxbZ6UI.js +1 -0
  22. package/dist/chunks/comparison-window-caption-C312mn3s.js +1 -0
  23. package/dist/chunks/context-ALdccLHw.js +2 -0
  24. package/dist/chunks/conversation-JMK2kyTK.js +1 -0
  25. package/dist/chunks/dashboard-BX28ld6s.js +1 -0
  26. package/dist/chunks/dashboard-briefing-launcher-qo7GH4EO.js +37 -0
  27. package/dist/chunks/dashboard-controls-DhRjB7MA.js +42 -0
  28. package/dist/chunks/dashboard-json-9cHzhSjC.js +1 -0
  29. package/dist/chunks/dates-D-KP8G-z.js +1 -0
  30. package/dist/chunks/edit-DEAK0UZo.js +1 -0
  31. package/dist/chunks/edit-dashboard-visual-Duq_QkB_.js +93 -0
  32. package/dist/chunks/export-file-format-B-wQNHIn.js +4 -0
  33. package/dist/chunks/filter-line-CwQrqORc.js +1 -0
  34. package/dist/chunks/filter-reach-preview-gixPFlZj.js +1 -0
  35. package/dist/chunks/filter-value-text-B3tXakhd.js +1 -0
  36. package/dist/chunks/index-B-VF1ogs.js +1 -0
  37. package/dist/chunks/index-BE1DfxNs.js +1 -0
  38. package/dist/chunks/index-DViPGDFj.js +1 -0
  39. package/dist/chunks/layout-grid-BWtlgw0T.js +6 -0
  40. package/dist/chunks/matrix-analytical-definition-CtFqWyCK.js +1 -0
  41. package/dist/chunks/matrix-member-presentation-Q0MCJ-YK.js +1 -0
  42. package/dist/chunks/matrix-operation-contract-D1RC1bfi.js +1 -0
  43. package/dist/chunks/metric-comparison-DEZYXROZ.js +1 -0
  44. package/dist/chunks/normalize-dashboard-for-dirty-check-ILKfqgL3.js +1 -0
  45. package/dist/chunks/paintbrush-BjS3SbrH.js +6 -0
  46. package/dist/chunks/palette-BzC-CGOc.js +6 -0
  47. package/dist/chunks/pickers-DuBrUht0.js +1 -0
  48. package/dist/chunks/pivot-result-contract-expectations-DTQAgr4n.js +1 -0
  49. package/dist/chunks/pivot-result-identity-DTNCB--h.js +1 -0
  50. package/dist/chunks/raw-temporal-value-DeyEhL0S.js +1 -0
  51. package/dist/chunks/rendered-file-BbvwaU6z.js +1 -0
  52. package/dist/chunks/report-preferences-dialog-B_gUmCzG.js +1 -0
  53. package/dist/chunks/report-runtime-context-BWzIHCKK.js +1 -0
  54. package/dist/chunks/resolve-dashboard-input-context-B-TtRqxu.js +8 -0
  55. package/dist/chunks/resolver-AN9ChBfZ.js +1 -0
  56. package/dist/chunks/save-DdFUZcbi.js +6 -0
  57. package/dist/chunks/saved-dashboard-context-BAJ5tWiq.js +1 -0
  58. package/dist/chunks/schema-MC0cQSAb.js +4 -0
  59. package/dist/chunks/selection-filter-compiler-CCoCD25M.js +1 -0
  60. package/dist/chunks/semaphor-ready-indicator-DzjorP3t.js +999 -0
  61. package/dist/chunks/set-DuJfGkbY.js +1 -0
  62. package/dist/chunks/shelf-drop-preview-context-BlLJ5RsT.js +6 -0
  63. package/dist/chunks/stored-dashboard-Ctcpkllg.js +1 -0
  64. package/dist/chunks/style-sheet-parts-BRGt9O05.js +178 -0
  65. package/dist/chunks/table-export-sheet-rC5pKmXg.js +2 -0
  66. package/dist/chunks/token-types-Bj9iMy0w.js +1 -0
  67. package/dist/chunks/validators-CqV3Yka1.js +1 -0
  68. package/dist/chunks/variable-draft-DJrfUyhv.js +1 -0
  69. package/dist/chunks/visual-choice-DgEFfkE-.js +1 -0
  70. package/dist/dashboard/index.js +1 -7
  71. package/dist/dashboard-authoring/index.js +1 -4614
  72. package/dist/format-utils/index.js +1 -425
  73. package/dist/index.js +1 -554
  74. package/dist/layouts/index.js +1 -7
  75. package/dist/live-channel/index.js +1 -124
  76. package/dist/pdf-export-policy/index.js +1 -92
  77. package/dist/pdf-table-layout/index.js +1 -993
  78. package/dist/report-runtime-context/index.js +1 -9
  79. package/dist/shared/index.js +1 -6
  80. package/dist/style.css +1 -1
  81. package/dist/surfboard/index.js +1 -9
  82. package/dist/types/index.js +1 -88
  83. package/dist/types/lib/filter-values/build-card-filter-definition.d.ts +32 -0
  84. package/dist/types/lib/query-context/dashboard-filter-mapping-resolution.d.ts +9 -0
  85. package/dist/types/lib/stores/explorer-actions.d.ts +7 -6
  86. package/dist/types/lib/types/semantic-types.d.ts +6 -10
  87. package/dist/types/lib/utils/field-state-calculator.d.ts +7 -19
  88. package/dist/types/shared/dashboard-authoring/calculations/definition.d.ts +13 -0
  89. package/dist/types/shared/dashboard-authoring/card-data-source/card-base.d.ts +125 -0
  90. package/dist/types/shared/dashboard-authoring/card-data-source/card-field-folders.d.ts +55 -0
  91. package/dist/types/shared/dashboard-authoring/card-data-source/card-joins.d.ts +114 -0
  92. package/dist/types/shared/dashboard-authoring/card-data-source/card-prune.d.ts +12 -0
  93. package/dist/types/shared/dashboard-authoring/card-data-source/filter-field-catalog.d.ts +60 -0
  94. package/dist/types/shared/dashboard-authoring/card-data-source/filter-field-folders.d.ts +132 -0
  95. package/dist/types/shared/dashboard-authoring/card-data-source/index.d.ts +7 -0
  96. package/dist/types/shared/dashboard-authoring/card-data-source/join-reach.d.ts +42 -0
  97. package/dist/types/shared/dashboard-authoring/card-field-places.d.ts +28 -0
  98. package/dist/types/shared/dashboard-authoring/field-folders/field-folders.d.ts +115 -0
  99. package/dist/types/shared/dashboard-authoring/field-folders/index.d.ts +1 -0
  100. package/dist/types/shared/dashboard-authoring/filter-reach-decision.d.ts +11 -0
  101. package/dist/types/shared/dashboard-authoring/index.d.ts +6 -1
  102. package/dist/types/shared/dashboard-authoring/outline/outline-filters.d.ts +2 -0
  103. package/dist/types/shared/dashboard-authoring/see-records/result.d.ts +7 -22
  104. package/dist/usage-events/index.js +1 -285
  105. package/dist/value-format-preferences/index.js +1 -635
  106. package/package.json +4 -1
  107. package/dist/chunks/add-to-dashboard-CFF-wFU-.js +0 -291
  108. package/dist/chunks/analytics-base-schemas-DsUh5Q3C.js +0 -680
  109. package/dist/chunks/appearance-context-BwBp25ZG.js +0 -162
  110. package/dist/chunks/appearance-runtime-provider-BRHYELkC.js +0 -80
  111. package/dist/chunks/applied-constraints-DU-wndZ7.js +0 -47
  112. package/dist/chunks/assistant-chat-B6hNQI1t.js +0 -6115
  113. package/dist/chunks/attribution-BvoKvhcj.js +0 -32
  114. package/dist/chunks/availability-Bp5Gfu1I.js +0 -44
  115. package/dist/chunks/bookmark-impact-Ba2PLcGp.js +0 -76
  116. package/dist/chunks/bookmark-state-n7AaNzR_.js +0 -1667
  117. package/dist/chunks/brand-BoUV0iHF.js +0 -54
  118. package/dist/chunks/card-filter-builder-Y22HizVx.js +0 -4069
  119. package/dist/chunks/column-bands-RdM-kjDe.js +0 -47
  120. package/dist/chunks/comparison-window-caption-Ck2TIbnR.js +0 -741
  121. package/dist/chunks/context-UCQ7sere.js +0 -369
  122. package/dist/chunks/conversation-sQiWYUOb.js +0 -16
  123. package/dist/chunks/dashboard-BghI99oY.js +0 -14
  124. package/dist/chunks/dashboard-briefing-launcher-DtBAnGiH.js +0 -4875
  125. package/dist/chunks/dashboard-controls-CtFXlyjV.js +0 -2290
  126. package/dist/chunks/dashboard-json-DfGBUtCd.js +0 -66
  127. package/dist/chunks/dates-BnrXF4bb.js +0 -185
  128. package/dist/chunks/edit-9df1zOWe.js +0 -226
  129. package/dist/chunks/edit-dashboard-visual-oxt3x1wb.js +0 -18397
  130. package/dist/chunks/export-file-format-C-tJsxsf.js +0 -111
  131. package/dist/chunks/filter-line-Cy5YYqRL.js +0 -703
  132. package/dist/chunks/filter-reach-copy-CE_ZX147.js +0 -5111
  133. package/dist/chunks/filter-value-text-fWvSDwkl.js +0 -153
  134. package/dist/chunks/index-BVKzKl5d.js +0 -90
  135. package/dist/chunks/index-CV_Kzou0.js +0 -595
  136. package/dist/chunks/index-D5rxbtS4.js +0 -2795
  137. package/dist/chunks/layout-grid-9LndRoLa.js +0 -16
  138. package/dist/chunks/matrix-analytical-definition-CCp48UCw.js +0 -1233
  139. package/dist/chunks/matrix-member-presentation-zNehruXR.js +0 -391
  140. package/dist/chunks/matrix-operation-contract-DPBj69D8.js +0 -1413
  141. package/dist/chunks/metric-comparison-B0FR-Q8I.js +0 -600
  142. package/dist/chunks/normalize-dashboard-for-dirty-check-XKgH3GFX.js +0 -119
  143. package/dist/chunks/paintbrush-58FQYY-y.js +0 -27
  144. package/dist/chunks/palette-Be62Tkoa.js +0 -23
  145. package/dist/chunks/pickers-DkqmtnTL.js +0 -2403
  146. package/dist/chunks/pivot-result-contract-expectations-BYqAmG9n.js +0 -5092
  147. package/dist/chunks/pivot-result-identity-CAP4--iq.js +0 -77
  148. package/dist/chunks/raw-temporal-value-Dg_MTFF7.js +0 -3778
  149. package/dist/chunks/rendered-file-D8xEuVVx.js +0 -108
  150. package/dist/chunks/report-preferences-dialog-uJp9GBTM.js +0 -1651
  151. package/dist/chunks/report-runtime-context-c77_KF9v.js +0 -388
  152. package/dist/chunks/resolve-dashboard-input-context-Rtl1ffmE.js +0 -25324
  153. package/dist/chunks/resolver-DG_tfEpt.js +0 -156
  154. package/dist/chunks/save-C5A0JnEV.js +0 -21
  155. package/dist/chunks/saved-dashboard-context-tcyTU8jm.js +0 -618
  156. package/dist/chunks/schema-C9NPiIru.js +0 -2568
  157. package/dist/chunks/selection-filter-compiler-DNijjI5y.js +0 -150
  158. package/dist/chunks/semaphor-ready-indicator-FBvunj6S.js +0 -145603
  159. package/dist/chunks/shelf-drop-preview-context-QKStrcK9.js +0 -2466
  160. package/dist/chunks/stored-dashboard-CHozcAY9.js +0 -4075
  161. package/dist/chunks/style-sheet-parts-CDCG-8Ej.js +0 -8681
  162. package/dist/chunks/table-export-sheet-ZFIvs6Sj.js +0 -949
  163. package/dist/chunks/token-types-XbM6QByy.js +0 -8
  164. package/dist/chunks/upload-H15d7uHK.js +0 -15
  165. package/dist/chunks/validators-Baf3VIf5.js +0 -3686
  166. package/dist/chunks/variable-draft-C2y8Jp6Z.js +0 -242
  167. package/dist/chunks/visual-choice-DDfHfHvY.js +0 -172
@@ -1,1667 +0,0 @@
1
- import { a6 as J, f as Le, k as qe, aE as je } from "./validators-Baf3VIf5.js";
2
- import { z as f } from "zod";
3
- import { Q as j, E as Be, q as Ue } from "./matrix-operation-contract-DPBj69D8.js";
4
- import { c as ze, D as We, b as be, e as Qe, r as B, a as Ye, k as Ge } from "./metric-comparison-B0FR-Q8I.js";
5
- import "./analytics-base-schemas-DsUh5Q3C.js";
6
- import { a as D } from "./applied-constraints-DU-wndZ7.js";
7
- import { r as Je } from "./pivot-result-identity-CAP4--iq.js";
8
- const se = 8, ae = 6, $ = Object.freeze([]);
9
- function He(e) {
10
- switch (e.type) {
11
- case "table":
12
- case "chart":
13
- return e.card ? [e.card] : $;
14
- case "kpi":
15
- return Array.isArray(e.cards) ? e.cards : $;
16
- default:
17
- return $;
18
- }
19
- }
20
- function Xe(e, t) {
21
- switch (e.type) {
22
- case "table":
23
- case "chart": {
24
- if (!e.card) return e;
25
- const n = t(e.card);
26
- return n === e.card ? e : { ...e, card: n };
27
- }
28
- case "kpi": {
29
- if (!Array.isArray(e.cards)) return e;
30
- const n = e.cards.map(t);
31
- return n.every((r, s) => r === e.cards[s]) ? e : { ...e, cards: n };
32
- }
33
- default:
34
- return e;
35
- }
36
- }
37
- function F(e) {
38
- var n;
39
- const t = [];
40
- for (const r of e.sheets || []) {
41
- const s = r.id;
42
- for (const a of r.cards || [])
43
- t.push({ kind: "sheetCard", sheetId: s, cardId: a.id, card: a });
44
- for (const a of r.frames || [])
45
- for (const i of a.cards || [])
46
- t.push({
47
- kind: "frameCard",
48
- sheetId: s,
49
- frameId: a.id,
50
- cardId: i.id,
51
- card: i
52
- });
53
- for (const a of ((n = r.document) == null ? void 0 : n.sections) || [])
54
- for (const i of He(a))
55
- t.push({
56
- kind: "documentSectionCard",
57
- sheetId: s,
58
- sectionId: a.id,
59
- cardId: i.id,
60
- card: i
61
- });
62
- }
63
- return t;
64
- }
65
- function sn(e, t, n) {
66
- let r = !1;
67
- const s = Ze(e, (i) => i.id !== n.id ? i : (r = !0, i === n ? i : n));
68
- if (r || !t) return s;
69
- const a = (s.sheets || []).map(
70
- (i) => i.id === t && i.kind !== "document" ? { ...i, cards: [...i.cards ?? [], n] } : i
71
- );
72
- return { ...s, sheets: a };
73
- }
74
- function Ze(e, t) {
75
- const n = (s, a) => {
76
- const i = s.map((o) => t(o, a(o)));
77
- return i.every((o, c) => o === s[c]) ? s : i;
78
- }, r = (e.sheets || []).map((s) => {
79
- var m, I, y;
80
- const a = s.id, i = s.cards && n(s.cards, (l) => ({ kind: "sheetCard", sheetId: a, cardId: l.id, card: l })), o = (m = s.frames) == null ? void 0 : m.map((l) => {
81
- if (!l.cards) return l;
82
- const h = n(l.cards, (C) => ({ kind: "frameCard", sheetId: a, frameId: l.id, cardId: C.id, card: C }));
83
- return h === l.cards ? l : { ...l, cards: h };
84
- }), c = (y = (I = s.document) == null ? void 0 : I.sections) == null ? void 0 : y.map(
85
- (l) => Xe(l, (h) => t(h, { kind: "documentSectionCard", sheetId: a, sectionId: l.id, cardId: h.id, card: h }))
86
- ), u = !!o && o.some((l, h) => l !== s.frames[h]), d = !!c && c.some((l, h) => l !== s.document.sections[h]);
87
- return i === s.cards && !u && !d ? s : {
88
- ...s,
89
- ...i === s.cards ? {} : { cards: i },
90
- ...u ? { frames: o } : {},
91
- ...d ? { document: { ...s.document, sections: c } } : {}
92
- };
93
- });
94
- return r.every((s, a) => s === e.sheets[a]) ? e : { ...e, sheets: r };
95
- }
96
- function P(e) {
97
- return !!e && typeof e == "object" && !Array.isArray(e);
98
- }
99
- function an(e) {
100
- if (!P(e))
101
- return [{ path: "", message: "must be an object." }];
102
- const t = [];
103
- e.title !== void 0 && typeof e.title != "string" && t.push({ path: "title", message: "must be a string." });
104
- const n = e.cards;
105
- if (!Array.isArray(n))
106
- t.push({ path: "cards", message: "must be an array of KPI cards." });
107
- else {
108
- (n.length < 1 || n.length > se) && t.push({
109
- path: "cards",
110
- message: `must hold 1 to ${se} KPI cards.`
111
- });
112
- const s = /* @__PURE__ */ new Set();
113
- n.forEach((a, i) => {
114
- if (!P(a)) {
115
- t.push({ path: `cards[${i}]`, message: "must be a card." });
116
- return;
117
- }
118
- typeof a.id != "string" || !a.id ? t.push({
119
- path: `cards[${i}].id`,
120
- message: "must be a non-empty string."
121
- }) : s.has(a.id) ? t.push({
122
- path: `cards[${i}].id`,
123
- message: `duplicates card id '${a.id}'.`
124
- }) : s.add(a.id), a.type !== "kpi" && t.push({ path: `cards[${i}].type`, message: "must be 'kpi'." });
125
- });
126
- }
127
- const r = e.kpi;
128
- return P(r) ? (r.layout !== "tiles" && r.layout !== "lines" ? t.push({
129
- path: "kpi.layout",
130
- message: "must be 'tiles' or 'lines'."
131
- }) : r.layout === "tiles" && Array.isArray(n) && n.length > ae && t.push({
132
- path: "kpi.layout",
133
- message: `must be 'lines' for more than ${ae} KPI cards.`
134
- }), r.columns !== void 0 && r.columns !== 1 && r.columns !== 2 && t.push({ path: "kpi.columns", message: "must be 1 or 2." })) : t.push({ path: "kpi", message: "must be an object." }), t;
135
- }
136
- const Se = "dashboardInput";
137
- function ie(e) {
138
- return e === "label" || e === "value" || e === "start" || e === "end" || e === "range";
139
- }
140
- function et(e) {
141
- return e === "generatedAt" || e === "pageNumber" || e === "pageCount";
142
- }
143
- function v(e) {
144
- if (!e || typeof e != "object" || Array.isArray(e)) return;
145
- const t = e;
146
- if (t.source === "input" || t.source === Se)
147
- return typeof t.inputId == "string" && ie(t.export) ? { source: "input", inputId: t.inputId, export: t.export } : void 0;
148
- if (t.source === "dashboardInputAlias")
149
- return typeof t.variableName != "string" || t.export !== void 0 && !ie(t.export) ? void 0 : {
150
- source: "dashboardInputAlias",
151
- variableName: t.variableName,
152
- ...t.export ? { export: t.export } : {}
153
- };
154
- if (t.source === "documentMeta")
155
- return et(t.key) ? { source: "documentMeta", key: t.key } : void 0;
156
- if (t.source === "data")
157
- return typeof t.variableId == "string" && typeof t.export == "string" ? { source: "data", variableId: t.variableId, export: t.export } : void 0;
158
- }
159
- function on(e, t) {
160
- const n = v(e), r = v(t);
161
- return !n || !r ? JSON.stringify(e) === JSON.stringify(t) : [.../* @__PURE__ */ new Set([...Object.keys(n), ...Object.keys(r)])].every((a) => n[a] === r[a]);
162
- }
163
- function tt(e) {
164
- return x(e) ? e.type === "variable" ? e.ref === void 0 ? [] : [e.ref] : e.type === "when" && x(e.test) && e.test.ref !== void 0 ? [e.test.ref] : [] : [];
165
- }
166
- function nt(e, t) {
167
- if (!x(e)) return e;
168
- if (e.type === "variable" && e.ref !== void 0) {
169
- const n = t(e.ref);
170
- return n === e.ref ? e : { ...e, ref: n };
171
- }
172
- if (e.type === "when" && x(e.test) && e.test.ref !== void 0) {
173
- const n = t(e.test.ref);
174
- return n === e.test.ref ? e : { ...e, test: { ...e.test, ref: n } };
175
- }
176
- return e;
177
- }
178
- function x(e) {
179
- return !!e && typeof e == "object" && !Array.isArray(e);
180
- }
181
- function oe(e) {
182
- return !!e && typeof e == "object" && e.source === Se;
183
- }
184
- function cn(e) {
185
- return U(e);
186
- }
187
- function U(e) {
188
- if (!e || typeof e != "object") return e;
189
- if (Array.isArray(e)) {
190
- let a = !1;
191
- const i = e.map((o) => {
192
- const c = U(o);
193
- return c !== o && (a = !0), c;
194
- });
195
- return a ? i : e;
196
- }
197
- const t = e;
198
- let n;
199
- const r = (a, i) => {
200
- i !== t[a] && (n ?? (n = { ...t }), n[a] = i);
201
- }, s = nt(
202
- t,
203
- (a) => oe(a) ? v(a) ?? a : a
204
- );
205
- if (s !== t && (s.ref !== t.ref && r("ref", s.ref), s.test !== t.test && r("test", s.test)), t.inputAliases && typeof t.inputAliases == "object") {
206
- const a = t.inputAliases;
207
- let i = !1;
208
- const o = Object.fromEntries(
209
- Object.entries(a).map(([c, u]) => oe(u) ? (i = !0, [c, v(u) ?? u]) : [c, u])
210
- );
211
- i && r("inputAliases", o);
212
- }
213
- for (const [a, i] of Object.entries(t))
214
- a === "ref" && t.type === "variable" || a === "test" && t.type === "when" || a === "inputAliases" || r(a, U(i));
215
- return n ?? e;
216
- }
217
- function un(e) {
218
- return b(e);
219
- }
220
- function b(e) {
221
- const t = [];
222
- for (const n of Array.isArray(e) ? e : [])
223
- if (!(!n || typeof n != "object")) {
224
- for (const r of tt(n)) {
225
- const s = v(r);
226
- s && t.push(s);
227
- }
228
- n.type === "link" && t.push(...b(n.children), ...b(Array.isArray(n.url) ? n.url : [])), n.type === "when" && t.push(...b(n.then), ...b(n.else));
229
- }
230
- return t;
231
- }
232
- function rt(e) {
233
- var r;
234
- const t = (r = e.preferences) == null ? void 0 : r.textVisualOptions, n = t == null ? void 0 : t.richContent;
235
- return n && Array.isArray(n.blocks) ? n.blocks.flatMap(
236
- (s) => (s == null ? void 0 : s.type) === "list" ? (Array.isArray(s.items) ? s.items : []).flatMap((a) => b(a)) : b(s == null ? void 0 : s.children)
237
- ) : b(t == null ? void 0 : t.content);
238
- }
239
- function Ce(e, t) {
240
- var s;
241
- const n = [], r = { kind: "document", sheetId: e };
242
- for (const a of ["header", "footer"])
243
- for (const i of ((s = t[a]) == null ? void 0 : s.blocks) ?? [])
244
- if (i.type === "text")
245
- for (const o of b(i.content))
246
- n.push({ ref: o, place: r, where: { kind: a, blockId: i.id } });
247
- for (const a of t.sections ?? [])
248
- if (a.type === "text")
249
- for (const i of b(a.content))
250
- n.push({ ref: i, place: r, where: { kind: "section", sectionId: a.id } });
251
- return n;
252
- }
253
- const ce = /* @__PURE__ */ new WeakMap();
254
- function ge(e) {
255
- const t = ce.get(e);
256
- if (t) return t;
257
- const n = [];
258
- for (const r of e.sheets ?? []) {
259
- if (r.kind === "document") {
260
- r.document && n.push(...Ce(r.id, r.document));
261
- continue;
262
- }
263
- const s = { kind: "sheet", sheetId: r.id }, a = [...r.cards ?? [], ...(r.frames ?? []).flatMap((i) => i.cards ?? [])];
264
- for (const i of a)
265
- if (i.type === "text")
266
- for (const o of rt(i))
267
- n.push({ ref: o, place: s, where: { kind: "card", cardId: i.id } });
268
- }
269
- return ce.set(e, n), n;
270
- }
271
- function ke(e, t) {
272
- return e.kind === t.kind && e.sheetId === t.sheetId;
273
- }
274
- function we(e, t) {
275
- const n = ge(e);
276
- return t ? n.filter((r) => ke(r.place, t)) : [...n];
277
- }
278
- function st(e, t) {
279
- const n = [];
280
- for (const { ref: r, place: s } of ge(e))
281
- r.source !== "data" || r.variableId !== t || n.some((a) => ke(a, s)) || n.push(s);
282
- return n;
283
- }
284
- function dn(e, t) {
285
- const n = /* @__PURE__ */ new Set();
286
- for (const { ref: r } of we(e, t))
287
- r.source === "data" && n.add(r.variableId);
288
- return [...n];
289
- }
290
- function ln(e, t) {
291
- const n = Ce("", e).filter(
292
- ({ ref: r }) => r.source === "input" && r.inputId === t
293
- );
294
- return {
295
- header: n.some(({ where: r }) => r.kind === "header"),
296
- footer: n.some(({ where: r }) => r.kind === "footer"),
297
- textSections: new Set(
298
- n.flatMap(({ where: r }) => r.kind === "section" ? [r.sectionId] : [])
299
- ).size
300
- };
301
- }
302
- function Ae(e, t) {
303
- const n = st(e, t);
304
- return n.length ? n.map((r) => ({
305
- sheetId: r.sheetId,
306
- cardId: t,
307
- sheetKind: r.kind === "document" ? "document" : "dashboard"
308
- })) : (e.sheets ?? []).filter((r) => r.kind !== "document").map((r) => ({ sheetId: r.id, cardId: t, sheetKind: "dashboard" }));
309
- }
310
- function g(e, t) {
311
- var r;
312
- if (!ct(e, t))
313
- return !1;
314
- const n = e.scope;
315
- switch (n.kind) {
316
- case "allSheets":
317
- return ((r = n.sheetKinds) != null && r.length ? t.sheetKind ? n.sheetKinds.includes(t.sheetKind) : !1 : !!t.sheetId || !!t.cardId) && !ot(n.exceptSheetIds, t) && !le(n.exceptCardIds, t);
318
- case "sheets":
319
- return !!t.sheetId && n.sheetIds.includes(t.sheetId) && !le(n.exceptCardIds, t);
320
- case "cards":
321
- return !!t.cardId && n.cardIds.includes(t.cardId);
322
- case "documentSections":
323
- return !!t.sheetId && !!t.sectionId && n.sheetId === t.sheetId && n.sectionIds.includes(t.sectionId);
324
- default:
325
- return !1;
326
- }
327
- }
328
- function fn(e, t) {
329
- if (g(e, {
330
- sheetId: t.sheetId,
331
- sheetKind: t.sheetKind
332
- }))
333
- return !0;
334
- switch (e.scope.kind) {
335
- case "cards":
336
- for (const n of [...t.cardIds, ...t.variableIds ?? []])
337
- if (g(e, {
338
- sheetId: t.sheetId,
339
- cardId: n,
340
- sheetKind: t.sheetKind
341
- }))
342
- return !0;
343
- return !1;
344
- case "documentSections":
345
- return t.sheetKind === "document" && e.scope.sheetId === t.sheetId;
346
- default:
347
- return !1;
348
- }
349
- }
350
- const ue = /* @__PURE__ */ new WeakMap();
351
- function at(e) {
352
- const t = ue.get(e);
353
- if (t) return t;
354
- const n = /* @__PURE__ */ new Map();
355
- for (const a of F(e)) {
356
- const i = n.get(a.sheetId) ?? /* @__PURE__ */ new Set();
357
- i.add(a.cardId), n.set(a.sheetId, i);
358
- }
359
- const r = /* @__PURE__ */ new Map();
360
- for (const { ref: a, place: i } of we(e)) {
361
- if (a.source !== "data") continue;
362
- const o = r.get(i.sheetId) ?? /* @__PURE__ */ new Set();
363
- o.add(a.variableId), r.set(i.sheetId, o);
364
- }
365
- const s = /* @__PURE__ */ new Map();
366
- for (const a of e.sheets ?? [])
367
- s.set(a.id, {
368
- sheetId: a.id,
369
- sheetKind: a.kind === "document" ? "document" : "dashboard",
370
- cardIds: n.get(a.id) ?? /* @__PURE__ */ new Set(),
371
- variableIds: r.get(a.id) ?? /* @__PURE__ */ new Set()
372
- });
373
- return ue.set(e, s), s;
374
- }
375
- function mn(e, t) {
376
- var s, a;
377
- const n = /* @__PURE__ */ new Set(), r = at(e);
378
- for (const i of r.values())
379
- g(t, {
380
- sheetId: i.sheetId,
381
- sheetKind: i.sheetKind
382
- }) && n.add(`sheet:${i.sheetId}`);
383
- for (const i of F(e))
384
- g(t, {
385
- sheetId: i.sheetId,
386
- cardId: i.cardId,
387
- ...i.kind === "documentSectionCard" ? { sectionId: i.sectionId } : {},
388
- sheetKind: ((s = r.get(i.sheetId)) == null ? void 0 : s.sheetKind) ?? "dashboard"
389
- }) && n.add(`card:${i.cardId}`);
390
- for (const i of e.variables ?? [])
391
- Ae(e, i.id).some(
392
- (o) => g(t, o)
393
- ) && n.add(`card:${i.id}`);
394
- for (const i of e.sheets ?? [])
395
- if (i.kind === "document")
396
- for (const o of ((a = i.document) == null ? void 0 : a.sections) ?? [])
397
- g(t, {
398
- sheetId: i.id,
399
- sectionId: o.id,
400
- sheetKind: "document"
401
- }) && n.add(`section:${o.id}`);
402
- return n;
403
- }
404
- function pn(e) {
405
- return e.kind === "filter" && e.scope.kind === "cards";
406
- }
407
- function hn(e, t) {
408
- var a, i, o;
409
- const n = (c) => {
410
- var u, d;
411
- return de(c, t.removedSheetIds, t.renamedSheetIds, !1, (u = t.copiedTab) == null ? void 0 : u.sheetIds, (d = t.copiedTab) == null ? void 0 : d.mode);
412
- }, r = (c) => {
413
- var u, d;
414
- return de(
415
- c,
416
- t.removedCardIds,
417
- t.renamedCardIds,
418
- t.keepOnlyRenamedCardIds === !0,
419
- (u = t.copiedTab) == null ? void 0 : u.cardIds,
420
- (d = t.copiedTab) == null ? void 0 : d.mode
421
- );
422
- };
423
- let s;
424
- switch (e.kind) {
425
- case "allSheets":
426
- s = {
427
- ...e,
428
- ...e.exceptSheetIds ? { exceptSheetIds: n(e.exceptSheetIds) } : {},
429
- ...e.exceptCardIds ? { exceptCardIds: r(e.exceptCardIds) } : {}
430
- };
431
- break;
432
- case "sheets":
433
- s = {
434
- ...e,
435
- sheetIds: n(e.sheetIds),
436
- ...e.exceptCardIds ? { exceptCardIds: r(e.exceptCardIds) } : {}
437
- };
438
- break;
439
- case "cards":
440
- s = { ...e, cardIds: r(e.cardIds) };
441
- break;
442
- case "documentSections": {
443
- if ((a = t.removedSheetIds) != null && a.has(e.sheetId)) {
444
- s = { ...e, sectionIds: [] };
445
- break;
446
- }
447
- const c = {
448
- ...e,
449
- sheetId: ((i = t.renamedSheetIds) == null ? void 0 : i.get(e.sheetId)) ?? e.sheetId,
450
- sectionIds: (o = t.renamedSectionIds) != null && o.size ? e.sectionIds.map((d) => t.renamedSectionIds.get(d) ?? d) : e.sectionIds
451
- }, u = t.copiedTab;
452
- s = (u == null ? void 0 : u.mode) === "replace" && u.sheetIds.has(c.sheetId) ? {
453
- ...c,
454
- sheetId: u.sheetIds.get(c.sheetId),
455
- sectionIds: c.sectionIds.map((d) => u.sectionIds.get(d) ?? d)
456
- } : c;
457
- break;
458
- }
459
- default:
460
- return e;
461
- }
462
- return it(e, s) ? e : s;
463
- }
464
- function de(e, t, n, r, s, a) {
465
- let i = e;
466
- return t != null && t.size && (i = i.filter((o) => !t.has(o))), r && (i = i.filter((o) => n == null ? void 0 : n.has(o))), n != null && n.size && (i = i.map((o) => n.get(o) ?? o)), s != null && s.size && (i = a === "extend" ? [.../* @__PURE__ */ new Set([...i, ...i.flatMap((o) => s.has(o) ? [s.get(o)] : [])])] : i.map((o) => s.get(o) ?? o)), i;
467
- }
468
- function it(e, t) {
469
- return JSON.stringify(e) === JSON.stringify(t);
470
- }
471
- function ot(e, t) {
472
- return !!t.sheetId && !!(e != null && e.includes(t.sheetId));
473
- }
474
- function le(e, t) {
475
- return !!t.cardId && !!(e != null && e.includes(t.cardId));
476
- }
477
- function ct(e, t) {
478
- return t.sheetKind !== "document" || !e.compatibility || e.compatibility.source === "documentInput" ? !0 : e.compatibility.source === "cardInlineFilter" || e.compatibility.source === "cardControl" ? !!t.cardId && e.compatibility.cardId === t.cardId : !1;
479
- }
480
- function yn(e, t, n) {
481
- switch (e.kind) {
482
- case "sheets":
483
- return e.sheetIds.length > 0 && e.sheetIds.every((r) => r === t);
484
- case "cards":
485
- return e.cardIds.length > 0 && e.cardIds.every((r) => n.has(r));
486
- case "documentSections":
487
- return e.sheetId === t;
488
- case "allSheets":
489
- return !1;
490
- }
491
- }
492
- function In(e) {
493
- return e.kind === "sheets" && e.sheetIds.length === 0 || e.kind === "cards" && e.cardIds.length === 0;
494
- }
495
- function ut(e) {
496
- return e.kind === "allSheets" || e.kind === "sheets" ? e.exceptCardIds ?? [] : [];
497
- }
498
- function bn(e) {
499
- return e.kind === "allSheets" ? e.exceptSheetIds ?? [] : [];
500
- }
501
- function Sn(e, t) {
502
- var a;
503
- if (e.kind !== "allSheets" && e.kind !== "sheets" || !((a = e.exceptCardIds) != null && a.includes(t))) return e;
504
- const n = e.exceptCardIds.filter((i) => i !== t), { exceptCardIds: r, ...s } = e;
505
- return n.length ? { ...s, exceptCardIds: n } : s;
506
- }
507
- function Cn(e, t, n) {
508
- var o;
509
- if (t.kind !== "allSheets" && t.kind !== "sheets") return t;
510
- const r = ut(e), s = e.kind === "sheets" ? e.sheetIds.filter((c) => n.has(c)) : e.kind === "allSheets" && fe(e) ? [...n].filter((c) => {
511
- var u;
512
- return !((u = e.exceptSheetIds) != null && u.includes(c));
513
- }) : [], a = [...n].filter((c) => !s.includes(c));
514
- if (t.kind === "sheets")
515
- return {
516
- ...t,
517
- sheetIds: [.../* @__PURE__ */ new Set([...t.sheetIds, ...s])],
518
- ...r.length ? { exceptCardIds: [...r] } : {}
519
- };
520
- const i = e.kind === "allSheets" ? ((o = e.exceptSheetIds) == null ? void 0 : o.filter((c) => n.has(c))) ?? [] : [];
521
- return {
522
- kind: "allSheets",
523
- ...e.kind === "allSheets" && fe(e) ? {
524
- ...e.sheetKinds ? { sheetKinds: e.sheetKinds } : {},
525
- ...i.length ? { exceptSheetIds: i } : {}
526
- } : s.length ? {
527
- sheetKinds: ["dashboard", "document"],
528
- ...a.length ? { exceptSheetIds: a } : {}
529
- } : {},
530
- ...r.length ? { exceptCardIds: [...r] } : {}
531
- };
532
- }
533
- function fe(e) {
534
- var t;
535
- return e.kind === "allSheets" && (!((t = e.sheetKinds) != null && t.length) || e.sheetKinds.includes("document"));
536
- }
537
- function gn(e, t) {
538
- switch (e.kind) {
539
- case "allSheets":
540
- case "sheets": {
541
- const n = e.exceptCardIds ?? [];
542
- return n.includes(t) ? e : { ...e, exceptCardIds: [...n, t] };
543
- }
544
- case "cards":
545
- return { ...e, cardIds: e.cardIds.filter((n) => n !== t) };
546
- case "documentSections":
547
- return;
548
- }
549
- }
550
- const dt = 6;
551
- function kn(e) {
552
- if (!(e === void 0 || !Number.isFinite(e)) && Number.isInteger(e))
553
- return Math.max(0, Math.min(dt, e));
554
- }
555
- function ve(e) {
556
- var t;
557
- return ((t = e == null ? void 0 : e.comparison) == null ? void 0 : t.mode) === "explicit" ? be(e.comparison.spec) : void 0;
558
- }
559
- function lt(e) {
560
- const t = ve(e);
561
- return t ? ze(t) : "none";
562
- }
563
- function wn(e) {
564
- const t = ve(e);
565
- return (t == null ? void 0 : t.kind) === "target" ? t.targetValue : void 0;
566
- }
567
- function An(e) {
568
- return (e == null ? void 0 : e.semanticComparisonPolarity) || (e == null ? void 0 : e.comparisonPolarity) || We;
569
- }
570
- function H(e, t) {
571
- const n = Object.entries(e || {}).filter(
572
- ([a, i]) => i.output.outputId === a
573
- );
574
- if (!t.name) return;
575
- const r = B({
576
- ...t,
577
- name: t.name
578
- }), s = n.filter(
579
- ([, a]) => a.output.metricAlias === r
580
- );
581
- return s.length === 1 ? s[0][1] : void 0;
582
- }
583
- function vn(e, t) {
584
- const n = H(e, t);
585
- return {
586
- comparisonKind: (n == null ? void 0 : n.type) ?? lt(t),
587
- metadata: n
588
- };
589
- }
590
- function Tn(e) {
591
- return (e == null ? void 0 : e.showComparison) ?? Qe.showComparison;
592
- }
593
- function En(e) {
594
- const t = /* @__PURE__ */ new Set(), n = /* @__PURE__ */ new Set(), r = /* @__PURE__ */ new Set(), s = /* @__PURE__ */ new Set(), a = /* @__PURE__ */ new Set(), i = /* @__PURE__ */ new Set(), o = /* @__PURE__ */ new Map();
595
- return Object.entries(e || {}).forEach(([c, u]) => {
596
- const d = u.output;
597
- d.outputId === c && (t.add(d.currentColumnKey), n.add(d.currentColumnKey), d.availability.status === "available" && (d.comparisonColumnKey && (r.add(d.comparisonColumnKey), o.set(
598
- d.comparisonColumnKey,
599
- {
600
- metricName: u.displayName || d.metricId,
601
- comparisonLabel: u.displayLabel || "Comparison"
602
- }
603
- )), d.deltaColumnKey && (t.add(d.deltaColumnKey), s.add(d.deltaColumnKey)), d.percentChangeColumnKey && (t.add(d.percentChangeColumnKey), a.add(d.percentChangeColumnKey)), d.ratioColumnKey && (t.add(d.ratioColumnKey), i.add(d.ratioColumnKey)), d.rowStatusColumnKey && (t.add(d.rowStatusColumnKey), n.add(d.rowStatusColumnKey)), d.currentBucketColumnKey && (t.add(d.currentBucketColumnKey), n.add(d.currentBucketColumnKey)), d.comparisonSourceBucketColumnKey && (t.add(d.comparisonSourceBucketColumnKey), n.add(d.comparisonSourceBucketColumnKey))));
604
- }), {
605
- internalKeys: t,
606
- bookkeepingKeys: n,
607
- comparisonColumnKeys: r,
608
- deltaColumnKeys: s,
609
- percentChangeColumnKeys: a,
610
- ratioColumnKeys: i,
611
- comparisonSeriesLabels: o
612
- };
613
- }
614
- const ft = "SEMAPHOR_CALCULATED_FIELD";
615
- function X(e, t, n) {
616
- if (n && (t === "groupby" || t === "pivotby"))
617
- return n;
618
- if (t === "metric" && e.name === "*" && !e.expression)
619
- return e.alias || "count";
620
- if (e.alias) return e.alias;
621
- const r = e.entityName && e.entityName !== ft ? e.entityName : void 0;
622
- if (e.role === "metric") {
623
- let s = e.aggregate || "metric";
624
- if (e.expression) {
625
- const a = e.expression.match(
626
- /^(COUNT|SUM|AVG|MIN|MAX|MEDIAN|DISTINCT)\s*\(/i
627
- );
628
- s = a ? a[1].toLowerCase() : "expr";
629
- } else
630
- s = s.toLowerCase();
631
- return r && r !== e.name ? `${r}_${e.name}_${s}` : `${e.name}_${s}`;
632
- }
633
- return r && r !== e.name ? `${r}_${e.name}` : e.name;
634
- }
635
- function Te(e) {
636
- return X(e, "detail");
637
- }
638
- function mt(e) {
639
- const t = e.label;
640
- return t && e.labelCount === 1 && (t === e.rawKey || !e.rawKeys.has(t)) ? t : e.rawKey;
641
- }
642
- function Kn(e) {
643
- const t = [
644
- ...(e.groupByColumns ?? []).map((o) => ({ field: o, role: "groupby" })),
645
- ...(e.metricColumns ?? []).map((o) => ({ field: o, role: "metric" })),
646
- ...(e.pivotByColumns ?? []).map((o) => ({ field: o, role: "pivotby" })),
647
- ...(e.detailColumns ?? []).map((o) => ({ field: o, role: "detail" }))
648
- ], n = Ee(e.detailColumns ?? []), r = new Map((e.detailColumns ?? []).map((o, c) => [o, c])), s = new Map(
649
- t.map(({ field: o, role: c }) => [
650
- o,
651
- c === "detail" ? n[r.get(o)] : X(o, c)
652
- ])
653
- ), a = new Set(s.values()), i = /* @__PURE__ */ new Map();
654
- for (const { field: o } of t)
655
- o.label && i.set(o.label, (i.get(o.label) ?? 0) + 1);
656
- return new Map(
657
- t.map(({ field: o }) => [
658
- o,
659
- mt({
660
- label: o.label,
661
- labelCount: o.label ? i.get(o.label) ?? 0 : 0,
662
- rawKey: s.get(o),
663
- rawKeys: a
664
- })
665
- ])
666
- );
667
- }
668
- function Ee(e) {
669
- const t = e.map((s) => Te(s)), n = new Set(t), r = /* @__PURE__ */ new Map();
670
- return t.forEach((s, a) => {
671
- r.has(s) || r.set(s, a);
672
- }), t.map((s, a) => {
673
- if (r.get(s) === a) return s;
674
- let i = 2;
675
- for (; n.has(`${s}_${i}`); ) i += 1;
676
- return n.add(`${s}_${i}`), `${s}_${i}`;
677
- });
678
- }
679
- function Nn(e) {
680
- const t = e.detailColumns;
681
- if (!t || t.length < 2) return e;
682
- const n = Ee(t);
683
- let r = !1;
684
- const s = t.map((a, i) => Te(a) === n[i] ? a : (r = !0, { ...a, alias: n[i] }));
685
- return r ? { ...e, detailColumns: s } : e;
686
- }
687
- const Ke = "text", R = 100, pt = 10, S = "value", Ne = ["previous", "change", "percentChange"];
688
- function ht(e) {
689
- return Ne.includes(e);
690
- }
691
- const yt = ["up", "down", "flat"];
692
- function On(e, t, n) {
693
- const { signWords: r, absolute: s, percent: a, ...i } = t ?? {};
694
- return e !== "change" && e !== "percentChange" ? i : {
695
- ...i,
696
- ...(n == null ? void 0 : n.signWords) === void 0 ? { signWords: yt } : {},
697
- ...(n == null ? void 0 : n.absolute) === void 0 ? { absolute: !0 } : {},
698
- ...e === "percentChange" && (n == null ? void 0 : n.percent) === void 0 ? { percent: !0 } : {}
699
- };
700
- }
701
- function Z(e) {
702
- var r, s, a, i;
703
- if (e.get.kind !== "aggregate" || (r = e.query.sql) != null && r.trim()) return;
704
- const t = (i = (a = (s = e.query.config) == null ? void 0 : s.metricColumns) == null ? void 0 : a[0]) == null ? void 0 : i.comparison;
705
- if ((t == null ? void 0 : t.mode) !== "explicit") return;
706
- const n = be(t.spec);
707
- return n.kind === "shift" ? n : void 0;
708
- }
709
- function me(e, t) {
710
- if (t === "preview" && e.get.kind !== "aggregate")
711
- return R + 1;
712
- switch (e.get.kind) {
713
- case "only":
714
- return 2;
715
- case "list":
716
- return R + 1;
717
- default:
718
- return 1;
719
- }
720
- }
721
- const pe = {
722
- answer: /* @__PURE__ */ new WeakMap(),
723
- preview: /* @__PURE__ */ new WeakMap()
724
- };
725
- function It(e, t = "answer") {
726
- var a;
727
- const n = pe[t].get(e);
728
- if (n) return n;
729
- const { query: r } = e, s = {
730
- id: e.id,
731
- title: e.name,
732
- type: Ke,
733
- respondsToSelections: !1,
734
- // The viewer's dashboard comparison never changes a variable: its own
735
- // measure says whether it compares (P3b-03); the request builder gives a
736
- // variable no Date filter comparison (compare-with CW-D22).
737
- dataVariableId: e.id,
738
- ...r.connectionId ? { connectionId: r.connectionId } : {},
739
- ...r.dataSource ? { dataSource: r.dataSource } : {},
740
- ...r.calculatedFields ? { calculatedFields: r.calculatedFields } : {},
741
- ...(a = r.sql) != null && a.trim() ? { sql: r.sql, config: { rowLimit: me(e, t) } } : { config: { ...r.config, rowLimit: me(e, t) } }
742
- };
743
- return pe[t].set(e, s), s;
744
- }
745
- function Dn(e) {
746
- return e.type === Ke && typeof e.dataVariableId == "string" && e.dataVariableId.length > 0;
747
- }
748
- function Mn(e, t, n) {
749
- var r;
750
- if (n === S && ((r = e.query.sql) != null && r.trim())) {
751
- const s = Object.keys(t)[0];
752
- return s === void 0 ? void 0 : t[s];
753
- }
754
- return n in t ? t[n] : void 0;
755
- }
756
- function z(e) {
757
- const t = J(e);
758
- return t === "string" || t === "unknown" ? "text" : t;
759
- }
760
- function bt(e) {
761
- return typeof e == "number" ? "number" : typeof e == "boolean" ? "boolean" : "text";
762
- }
763
- function St(e, t, n, r) {
764
- var i, o;
765
- const s = Je(r, e.id, t);
766
- return [
767
- s == null ? void 0 : s.outputKey,
768
- s == null ? void 0 : s.rawKey,
769
- t === "metric" ? ((o = (i = r == null ? void 0 : r.byMetricAlias) == null ? void 0 : i[B(e)]) == null ? void 0 : o.outputKey) ?? B(e) : void 0,
770
- X(e, t === "metric" ? "metric" : "groupby"),
771
- e.label,
772
- e.name
773
- ].find((c) => !!c && n.has(c));
774
- }
775
- function xn(e, t) {
776
- var r;
777
- if (e.get.kind === "aggregate")
778
- return Z(e) ? [S, ...Ne] : [S];
779
- if (e.get.kind === "list") return [S];
780
- if ((r = e.query.sql) != null && r.trim()) return [...t ?? []];
781
- const n = e.query.config;
782
- return Ct([
783
- ...((n == null ? void 0 : n.groupByColumns) ?? []).map((s) => s.name),
784
- ...((n == null ? void 0 : n.metricColumns) ?? []).map((s) => s.name)
785
- ]);
786
- }
787
- function Rn(e, t) {
788
- var a, i, o, c;
789
- if (e.get.kind === "list") return "list";
790
- if ((a = e.query.sql) != null && a.trim()) return;
791
- const n = e.query.config, r = (u, d) => {
792
- if (!u) return;
793
- const m = d === "metric" ? j(u) : u.dataType;
794
- return J(m) === "unknown" ? void 0 : z(m);
795
- };
796
- if (e.get.kind === "aggregate")
797
- return ht(t) && Z(e) ? "number" : t === S ? r((i = n == null ? void 0 : n.metricColumns) == null ? void 0 : i[0], "metric") : void 0;
798
- const s = (o = n == null ? void 0 : n.groupByColumns) == null ? void 0 : o.find((u) => u.name === t);
799
- return s ? r(s, "groupby") : r((c = n == null ? void 0 : n.metricColumns) == null ? void 0 : c.find((u) => u.name === t), "metric");
800
- }
801
- function Ct(e) {
802
- return [...new Set(e)];
803
- }
804
- function gt(e, t, n) {
805
- var l, h, C;
806
- const r = t[0] ?? {}, s = new Set(
807
- (l = n.columns) != null && l.length ? n.columns.map((p) => p.key) : Object.keys(r)
808
- ), a = new Map(
809
- (n.columns ?? []).map((p) => [p.key, p.dataType])
810
- ), i = (p, k) => a.has(p) ? z(a.get(p)) : k !== void 0 ? z(k) : bt(r[p]);
811
- if ((h = e.query.sql) != null && h.trim())
812
- return [...s].map((p) => ({ part: p, key: p, type: i(p, void 0) }));
813
- const o = e.query.config ?? {}, c = [], u = s.size === 1 ? [...s][0] : void 0, d = e.get.kind === "aggregate" || e.get.kind === "list", m = (p, k, re) => {
814
- if (c.some((Pe) => Pe.part === re)) return;
815
- const K = St(p, k, s, n.columnKeyMap) ?? (d ? u : void 0);
816
- if (!K) return;
817
- const $e = k === "metric" ? i(K, j(p)) : i(K, p.dataType);
818
- c.push({ part: re, key: K, type: $e });
819
- }, I = o.metricColumns ?? [];
820
- if (e.get.kind === "aggregate") {
821
- const p = I[0] ? (C = H(n.comparisonMetadata, I[0])) == null ? void 0 : C.output.currentColumnKey : void 0;
822
- return p && s.has(p) ? c.push({ part: S, key: p, type: i(p, j(I[0])) }) : I[0] && m(I[0], "metric", S), c;
823
- }
824
- const y = o.groupByColumns ?? [];
825
- if (e.get.kind === "list")
826
- return y[0] && m(y[0], "groupby", S), c;
827
- for (const p of y) m(p, "groupby", p.name);
828
- for (const p of I) m(p, "metric", p.name);
829
- return c;
830
- }
831
- function W(e, t) {
832
- return e == null ? { value: null, type: t } : typeof e == "number" || typeof e == "boolean" || typeof e == "string" ? { value: e, type: t } : e instanceof Date ? { value: e.toISOString(), type: t } : { value: JSON.stringify(e), type: t };
833
- }
834
- function w(e) {
835
- return !!e && typeof e == "object" && !Array.isArray(e);
836
- }
837
- function _n(e) {
838
- if (!w(e)) return {};
839
- const t = w(e.data) ? e.data : e, n = D(e).length ? D(e) : D(t), r = w(t.metadata) ? t.metadata : void 0;
840
- return {
841
- ...t.records !== void 0 ? { records: t.records } : {},
842
- ...Array.isArray(t.columns) ? { columns: t.columns } : {},
843
- ...w(t.columnKeyMap) ? { columnKeyMap: t.columnKeyMap } : {},
844
- ...n.length ? { filterReach: n } : {},
845
- ...r && w(r.comparisonMetadata) ? { comparisonMetadata: r.comparisonMetadata } : {},
846
- ...typeof t.error == "string" && t.error ? { error: t.error } : {}
847
- };
848
- }
849
- function Fn(e, t, n = "answer") {
850
- var d;
851
- const r = (Array.isArray(t.records) ? t.records : []).filter(
852
- (m) => !!m && typeof m == "object"
853
- ), s = D(t), a = n === "preview" ? { matched: r.length > R ? "beyondCap" : r.length } : {};
854
- if (!r.length) return { status: "none", why: "noRows", filterReach: s, ...a };
855
- const i = gt(e, r, t);
856
- if (e.get.kind === "list") {
857
- const m = i[0], I = r.length > R, y = m ? r.map((h) => W(h[m.key], m.type)).filter((h) => h.value !== null) : [];
858
- if (!y.length && !I) return { status: "none", why: "noRows", filterReach: s, ...a };
859
- const l = Math.max(1, e.get.limit ?? pt);
860
- return {
861
- status: "listed",
862
- items: y.slice(0, l),
863
- more: I ? "beyondCap" : Math.max(0, y.length - l),
864
- filterReach: s,
865
- ...a
866
- };
867
- }
868
- if (e.get.kind === "only" && r.length > 1)
869
- return { status: "none", why: "moreThanOne", filterReach: s, ...a };
870
- const o = r[0], c = Object.fromEntries(
871
- i.map((m) => [m.part, W(o[m.key], m.type)])
872
- );
873
- if (e.get.kind === "aggregate" && ((d = c[S]) == null ? void 0 : d.value) == null)
874
- return { status: "none", why: "noRows", filterReach: s, ...a };
875
- const u = Z(e) ? kt(e, o, t) : void 0;
876
- return {
877
- status: "answered",
878
- parts: u && "parts" in u ? { ...c, ...u.parts } : c,
879
- filterReach: s,
880
- ...u && "unavailable" in u ? { comparisonUnavailable: u.unavailable } : {},
881
- ...a
882
- };
883
- }
884
- function kt(e, t, n) {
885
- var o, c;
886
- const r = (c = (o = e.query.config) == null ? void 0 : o.metricColumns) == null ? void 0 : c[0], s = r ? H(n.comparisonMetadata, r) : void 0, a = s == null ? void 0 : s.output;
887
- if (!a || a.availability.status !== "available" || !a.comparisonColumnKey)
888
- return { unavailable: (a == null ? void 0 : a.availability.status) === "unavailable" ? a.availability.reason : "temporal_binding_missing" };
889
- const i = (u) => {
890
- const d = t[u], m = typeof d == "string" && d.trim() !== "" ? Number(d) : d;
891
- return W(typeof m == "number" && !Number.isFinite(m) ? null : m, "number");
892
- };
893
- return {
894
- parts: {
895
- previous: i(a.comparisonColumnKey),
896
- change: i(a.deltaColumnKey ?? ""),
897
- percentChange: i(a.percentChangeColumnKey ?? "")
898
- }
899
- };
900
- }
901
- const he = /* @__PURE__ */ new WeakMap();
902
- function ee(e) {
903
- const t = he.get(e);
904
- if (t) return t;
905
- const n = new Map(
906
- (e.sheets ?? []).map(
907
- (a) => [a.id, a.kind === "document" ? "document" : "dashboard"]
908
- )
909
- ), r = [
910
- ...F(e).map(
911
- (a) => ({
912
- kind: "card",
913
- id: a.cardId,
914
- card: a.card,
915
- sheetId: a.sheetId,
916
- sheetKind: n.get(a.sheetId) ?? "dashboard",
917
- ...a.kind === "documentSectionCard" ? { sectionId: a.sectionId } : {}
918
- })
919
- ),
920
- ...(e.variables ?? []).map(
921
- (a) => ({
922
- kind: "variable",
923
- id: a.id,
924
- variable: a,
925
- card: It(a)
926
- })
927
- )
928
- ], s = { targets: r, byId: new Map(r.map((a) => [a.id, a])) };
929
- return he.set(e, s), s;
930
- }
931
- function wt(e) {
932
- return ee(e).targets;
933
- }
934
- function Vn(e, t) {
935
- return ee(e).byId.get(t);
936
- }
937
- function At(e, t) {
938
- return ee(e).byId.has(t);
939
- }
940
- function vt(e, t) {
941
- return t.kind === "card" ? [
942
- {
943
- sheetId: t.sheetId,
944
- cardId: t.id,
945
- sheetKind: t.sheetKind,
946
- ...t.sectionId ? { sectionId: t.sectionId } : {}
947
- }
948
- ] : Ae(e, t.id);
949
- }
950
- function Tt(e, t, n) {
951
- return vt(e, n).some(
952
- (r) => g(t, r)
953
- );
954
- }
955
- function $n(e, t) {
956
- return wt(e).filter(
957
- (n) => n.kind === "variable" && Tt(e, t, n)
958
- );
959
- }
960
- const Et = ["new", "edit", "delete", "create", "update", "remove"];
961
- function Oe(e, t) {
962
- return (e.sheets || []).flatMap(
963
- (n) => F({ sheets: [n] }).filter(t).map((r) => ({
964
- card: r.card,
965
- sheet: n,
966
- ...r.kind === "frameCard" && { frameId: r.frameId },
967
- ...r.kind === "documentSectionCard" && {
968
- sectionId: r.sectionId
969
- }
970
- }))
971
- );
972
- }
973
- function T(e) {
974
- return Oe(e, (t) => t.kind !== "documentSectionCard");
975
- }
976
- function Pn(e) {
977
- return [
978
- ...T(e),
979
- ...Oe(e, (t) => t.kind === "documentSectionCard")
980
- ];
981
- }
982
- function Ln(e) {
983
- return T(e).map((t) => t.card);
984
- }
985
- function qn(e, t, n) {
986
- return n && t === n ? !0 : !At(e, t);
987
- }
988
- function jn(e) {
989
- return !e || e.trim().length === 0 ? { isValid: !1, error: "Card ID cannot be empty" } : e.length < 3 ? { isValid: !1, error: "Card ID must be at least 3 characters" } : e.length > 50 ? { isValid: !1, error: "Card ID must be less than 50 characters" } : /^[a-zA-Z0-9-_]+$/.test(e) ? /^[a-zA-Z0-9]/.test(e) ? Et.includes(e.toLowerCase()) ? {
990
- isValid: !1,
991
- error: `"${e}" is a reserved keyword and cannot be used`
992
- } : { isValid: !0 } : {
993
- isValid: !1,
994
- error: "Card ID must start with a letter or number"
995
- } : {
996
- isValid: !1,
997
- error: "Card ID can only contain letters, numbers, hyphens, and underscores"
998
- };
999
- }
1000
- function Bn(e, t) {
1001
- var n;
1002
- return (n = Kt(e, t)) == null ? void 0 : n.card;
1003
- }
1004
- function Kt(e, t) {
1005
- for (const n of T(e))
1006
- if (n.card.id === t)
1007
- return n;
1008
- }
1009
- function Un(e, t) {
1010
- for (const n of e.sheets || [])
1011
- for (const r of n.frames || [])
1012
- for (const s of r.cards || [])
1013
- if (s.id === t)
1014
- return { card: s, sheet: n };
1015
- }
1016
- const _ = {
1017
- includeMetricFilterDatasets: !0,
1018
- preferQualifiedIdentity: !1
1019
- };
1020
- function Q(e) {
1021
- if (!e) return;
1022
- if (e.kind === "semantic")
1023
- return { entityName: e.datasetName, entityId: e.datasetId, label: e.label };
1024
- const t = [e.databaseName, e.schemaName, e.tableName].filter((n) => !!(n && n.trim())).join(".");
1025
- return {
1026
- entityName: e.tableName,
1027
- qualifiedEntityName: t.includes(".") ? t : void 0,
1028
- label: e.label
1029
- };
1030
- }
1031
- function Nt(e) {
1032
- var n;
1033
- const t = Q(e.source);
1034
- return t ? `${(n = e.source) == null ? void 0 : n.kind}:${t.qualifiedEntityName || t.entityName}` : "";
1035
- }
1036
- function Ot(e) {
1037
- return [
1038
- e.id,
1039
- e.qualifiedEntityName,
1040
- e.entityId,
1041
- e.entityName,
1042
- e.qualifiedFieldName,
1043
- e.name,
1044
- // Source-only fields from different datasets can otherwise share a key
1045
- // and the second dataset would be silently dropped.
1046
- Nt(e)
1047
- ].join("|");
1048
- }
1049
- function Dt(e) {
1050
- return [e.entityName, e.qualifiedEntityName || "", e.entityId || ""].join("|");
1051
- }
1052
- function zn(e) {
1053
- return e.entityName || e.qualifiedEntityName || "";
1054
- }
1055
- function Mt(e) {
1056
- var t, n;
1057
- return !!(e.expression || e.derivedField || (n = (t = e.calculatedFormula) == null ? void 0 : t.inputFields) != null && n.length);
1058
- }
1059
- function xt(e) {
1060
- return Le(e) ? !0 : e.entityName || e.qualifiedEntityName ? !1 : !e.source || Mt(e);
1061
- }
1062
- function N(e, t) {
1063
- const n = Dt(t);
1064
- e.found.has(n) || e.found.set(n, t);
1065
- }
1066
- function E(e, t) {
1067
- var d, m, I;
1068
- if (!e) return;
1069
- const n = Ot(e);
1070
- if (t.visitedFields.has(n)) return;
1071
- t.visitedFields.add(n);
1072
- const r = xt(e);
1073
- if (!r) {
1074
- const y = !e.entityName && !e.qualifiedEntityName ? Q(e.source) : void 0;
1075
- N(
1076
- t,
1077
- y || {
1078
- // May be empty for qualified-only metadata; identity then comes from
1079
- // `qualifiedEntityName` (see `identityFor` and the calculator).
1080
- entityName: e.entityName || "",
1081
- entityId: e.entityId,
1082
- qualifiedEntityName: e.qualifiedEntityName,
1083
- label: e.source && e.source.kind === "semantic" ? e.source.label : void 0
1084
- }
1085
- );
1086
- }
1087
- t.includeMetricFilterDatasets && "parameters" in e && ((d = e.parameters) != null && d.filters) && te(e.parameters.filters, t);
1088
- const s = (m = e.calculatedFormula) == null ? void 0 : m.inputFields, a = !!(s && s.length > 0);
1089
- a && s.forEach((y) => E(y, t));
1090
- let i = !1, o = !1;
1091
- const c = a || (I = e.derivedField) == null ? void 0 : I.inputs;
1092
- if (c && Object.keys(c).length > 0)
1093
- for (const y of Object.values(c)) {
1094
- const l = y.field.source;
1095
- if (!l) {
1096
- a || (o = !0);
1097
- continue;
1098
- }
1099
- if (l.kind === "sql") {
1100
- o = !0;
1101
- continue;
1102
- }
1103
- if (l.kind === "semantic")
1104
- N(t, {
1105
- entityName: l.datasetName,
1106
- entityId: l.datasetId,
1107
- label: l.label
1108
- });
1109
- else {
1110
- const h = [l.databaseName, l.schemaName, l.tableName].filter((C) => !!(C && C.trim())).join(".");
1111
- N(t, {
1112
- entityName: l.tableName,
1113
- qualifiedEntityName: h.includes(".") ? h : void 0,
1114
- label: l.label
1115
- });
1116
- }
1117
- i = !0;
1118
- }
1119
- const u = r && !a && !(c && Object.keys(c).length > 0) ? Q(e.source) : void 0;
1120
- (u != null && u.entityName || u != null && u.qualifiedEntityName) && (N(t, u), i = !0), o && (t.complete = !1), r && !a && !i && (t.complete = !1);
1121
- }
1122
- function te(e, t) {
1123
- if (e && !t.visitedGroups.has(e.id)) {
1124
- t.visitedGroups.add(e.id);
1125
- for (const n of e.conditions || [])
1126
- E(n.field, t);
1127
- for (const n of e.groups || [])
1128
- te(n, t);
1129
- }
1130
- }
1131
- function V(e, t = /* @__PURE__ */ new Set(), n = /* @__PURE__ */ new Set()) {
1132
- return {
1133
- found: /* @__PURE__ */ new Map(),
1134
- complete: !0,
1135
- visitedFields: t,
1136
- visitedGroups: n,
1137
- includeMetricFilterDatasets: e
1138
- };
1139
- }
1140
- function ne(e, t) {
1141
- var r;
1142
- const n = (r = e.qualifiedEntityName) != null && r.includes(".") ? e.qualifiedEntityName : void 0;
1143
- return t === "qualifiedOnly" ? n : t === "preferQualified" ? n || e.entityName || void 0 : e.entityName || void 0;
1144
- }
1145
- function Wn(e) {
1146
- const t = V(!1);
1147
- return E(e, t), { datasets: Array.from(t.found.values()), complete: t.complete };
1148
- }
1149
- function De(e, t, n = /* @__PURE__ */ new Set(), r = /* @__PURE__ */ new Set(), s = _) {
1150
- const a = { ..._, ...s }, i = V(a.includeMetricFilterDatasets, n, r);
1151
- E(e, i), i.found.forEach((o) => {
1152
- const c = ne(o, a.preferQualifiedIdentity ? "preferQualified" : "name");
1153
- c && t.add(c);
1154
- });
1155
- }
1156
- function Qn(e, t) {
1157
- De(e, t, /* @__PURE__ */ new Set(), /* @__PURE__ */ new Set(), {
1158
- preferQualifiedIdentity: !0
1159
- });
1160
- }
1161
- function Yn(e, t, n = /* @__PURE__ */ new Set(), r = /* @__PURE__ */ new Set()) {
1162
- const s = V(!0, n, r);
1163
- E(e, s), s.found.forEach((a) => {
1164
- const i = ne(a, "qualifiedOnly");
1165
- i && t.add(i);
1166
- });
1167
- }
1168
- function Gn(e, t, n = /* @__PURE__ */ new Set(), r = /* @__PURE__ */ new Set()) {
1169
- De(e, t, n, r, {
1170
- includeMetricFilterDatasets: !1
1171
- });
1172
- }
1173
- function Jn(e, t, n = /* @__PURE__ */ new Set(), r = /* @__PURE__ */ new Set(), s = _) {
1174
- const a = { ..._, ...s }, i = V(a.includeMetricFilterDatasets, n, r);
1175
- te(e, i), i.found.forEach((o) => {
1176
- const c = ne(o, a.preferQualifiedIdentity ? "preferQualified" : "name");
1177
- c && t.add(c);
1178
- });
1179
- }
1180
- function Hn(e, t) {
1181
- return t != null && t[e] ? t[e] : (e.includes(".") ? e.slice(e.lastIndexOf(".") + 1) : e).replace(/[_-]+/g, " ").replace(/([a-z])([A-Z])/g, "$1 $2").replace(/\s+/g, " ").trim().replace(/\b\w/g, (r) => r.toUpperCase());
1182
- }
1183
- const Xn = {
1184
- database: null,
1185
- schema: null,
1186
- table: null
1187
- }, Zn = "__card_default__", Y = {
1188
- bookmarksPerViewerPerDashboard: 20,
1189
- bookmarkNameMaxChars: 100,
1190
- columnLabelMaxChars: 120,
1191
- columnWidthMaxPx: 4e3,
1192
- tableSettingsMaxBytes: 65536,
1193
- rememberedTableSettingsMaxBytes: 262144,
1194
- bookmarkStateMaxBytes: 65536
1195
- }, Me = 1;
1196
- function er(e) {
1197
- return new TextEncoder().encode(JSON.stringify(e ?? null)).length;
1198
- }
1199
- function Rt(e) {
1200
- const t = encodeURIComponent;
1201
- switch (e.kind) {
1202
- case "dimension":
1203
- return `dim:${e.role}:${t(e.fieldId)}`;
1204
- case "metric":
1205
- return `metric:${t(e.metricId)}:${t(
1206
- e.metricAlias
1207
- )}`;
1208
- case "result":
1209
- return `result:${t(e.key)}`;
1210
- }
1211
- }
1212
- function O(e) {
1213
- if (e)
1214
- try {
1215
- return decodeURIComponent(e);
1216
- } catch {
1217
- return;
1218
- }
1219
- }
1220
- function _t(e) {
1221
- if (typeof e != "string") return;
1222
- const t = e.split(":");
1223
- let n;
1224
- if (t[0] === "dim" && t.length === 3) {
1225
- const r = t[1], s = O(t[2]);
1226
- (r === "detail" || r === "groupby") && s && (n = { kind: "dimension", role: r, fieldId: s });
1227
- } else if (t[0] === "metric" && t.length === 3) {
1228
- const r = O(t[1]), s = O(t[2]);
1229
- r && s && (n = { kind: "metric", metricId: r, metricAlias: s });
1230
- } else if (t[0] === "result" && t.length === 2) {
1231
- const r = O(t[1]);
1232
- r && (n = { kind: "result", key: r });
1233
- }
1234
- return n && Rt(n) === e ? n : void 0;
1235
- }
1236
- function M(e) {
1237
- return typeof e == "string" && _t(e) !== void 0;
1238
- }
1239
- const ye = f.array(f.string()).max(2e3), Ft = f.object({
1240
- order: ye.optional(),
1241
- hidden: ye.optional(),
1242
- labels: f.record(f.string(), f.string().max(Y.columnLabelMaxChars)).optional(),
1243
- sort: f.array(
1244
- f.object({
1245
- columnId: f.string(),
1246
- direction: f.enum(["asc", "desc"])
1247
- }).strict()
1248
- ).max(2e3).optional(),
1249
- widths: f.record(
1250
- f.string(),
1251
- f.number().int().min(1).max(Y.columnWidthMaxPx)
1252
- ).optional()
1253
- }).strict();
1254
- function G(e) {
1255
- const t = /* @__PURE__ */ new Set(), n = [];
1256
- for (const r of e)
1257
- !M(r) || t.has(r) || (t.add(r), n.push(r));
1258
- return n;
1259
- }
1260
- function tr(e) {
1261
- if (!Array.isArray(e)) return;
1262
- const t = G(
1263
- e.filter((n) => typeof n == "string")
1264
- );
1265
- return t.length ? t : void 0;
1266
- }
1267
- function xe(e) {
1268
- if (!e) return;
1269
- const t = e.order ? G(e.order) : void 0, n = e.hidden ? G(e.hidden) : void 0, r = Object.entries(e.labels ?? {}).flatMap(
1270
- ([c, u]) => {
1271
- const d = typeof u == "string" ? u.trim() : "";
1272
- return M(c) && d ? [
1273
- [
1274
- c,
1275
- d.slice(0, Y.columnLabelMaxChars)
1276
- ]
1277
- ] : [];
1278
- }
1279
- ), s = /* @__PURE__ */ new Set(), a = e.sort ? e.sort.filter((c) => !M(c.columnId) || s.has(c.columnId) ? !1 : (s.add(c.columnId), !0)) : void 0, i = Object.entries(e.widths ?? {}).filter(
1280
- ([c]) => M(c)
1281
- ), o = {};
1282
- return t != null && t.length && (o.order = t), n != null && n.length && (o.hidden = n), r.length && (o.labels = Object.fromEntries(r)), a && (o.sort = a.map(({ columnId: c, direction: u }) => ({
1283
- columnId: c,
1284
- direction: u
1285
- }))), i.length && (o.widths = Object.fromEntries(i)), Object.keys(o).length ? o : void 0;
1286
- }
1287
- function nr(e) {
1288
- var t, n;
1289
- return !!((t = e == null ? void 0 : e.order) != null && t.length) || !!((n = e == null ? void 0 : e.hidden) != null && n.length) || Object.keys((e == null ? void 0 : e.labels) ?? {}).length > 0 || Object.keys((e == null ? void 0 : e.widths) ?? {}).length > 0;
1290
- }
1291
- function Re(e) {
1292
- return xe(e) === void 0;
1293
- }
1294
- function _e(e, t) {
1295
- if (t !== Me)
1296
- return {
1297
- ok: !1,
1298
- error: `Unsupported table settings version ${t}.`
1299
- };
1300
- const n = Ft.safeParse(e);
1301
- return n.success ? {
1302
- ok: !0,
1303
- value: xe(n.data) ?? {}
1304
- } : { ok: !1, error: "Table settings are invalid." };
1305
- }
1306
- function rr(e, t, n) {
1307
- if (!e || typeof e != "object" || Array.isArray(e)) return {};
1308
- const r = {};
1309
- for (const [s, a] of Object.entries(
1310
- e
1311
- )) {
1312
- if (!n.has(s)) continue;
1313
- const i = _e(a, t);
1314
- i.ok && !Re(i.value) && (r[s] = i.value);
1315
- }
1316
- return r;
1317
- }
1318
- const Vt = /* @__PURE__ */ new Set([
1319
- "table",
1320
- "detailTable"
1321
- ]);
1322
- function Fe(e) {
1323
- return Vt.has(e.type);
1324
- }
1325
- function $t(e) {
1326
- var t, n;
1327
- return Fe(e) && ((n = (t = e.preferences) == null ? void 0 : t.tablePrefs) == null ? void 0 : n.allowViewerColumnCustomization) !== !1;
1328
- }
1329
- function sr(e) {
1330
- return new Set(
1331
- T(e).filter(({ card: t }) => Fe(t)).map(({ card: t }) => t.id)
1332
- );
1333
- }
1334
- function ar(e) {
1335
- return new Set(
1336
- T(e).filter(({ card: t }) => $t(t)).map(({ card: t }) => t.id)
1337
- );
1338
- }
1339
- const Pt = {
1340
- date: /* @__PURE__ */ new Set([
1341
- "between",
1342
- "not between",
1343
- "=",
1344
- "!=",
1345
- ">",
1346
- ">=",
1347
- "<",
1348
- "<=",
1349
- "is null",
1350
- "is not null"
1351
- ]),
1352
- number: /* @__PURE__ */ new Set([
1353
- "between",
1354
- "not between",
1355
- "=",
1356
- "!=",
1357
- ">",
1358
- ">=",
1359
- "<",
1360
- "<=",
1361
- "in",
1362
- "not in",
1363
- "is null",
1364
- "is not null"
1365
- ]),
1366
- string: /* @__PURE__ */ new Set([
1367
- "=",
1368
- "!=",
1369
- "in",
1370
- "not in",
1371
- "like",
1372
- "not like",
1373
- "is null",
1374
- "is not null"
1375
- ]),
1376
- boolean: /* @__PURE__ */ new Set(["=", "!=", "in", "not in", "is null", "is not null"])
1377
- };
1378
- function Lt(e) {
1379
- const t = J(e);
1380
- return t === "number" || t === "boolean" ? t : t === "date" || t === "datetime" ? "date" : "string";
1381
- }
1382
- function ir(e, t) {
1383
- return typeof t != "string" ? !1 : Pt[Lt(e)].has(t);
1384
- }
1385
- const qt = /* @__PURE__ */ new Set([
1386
- "=",
1387
- ">",
1388
- "<",
1389
- ">=",
1390
- "<=",
1391
- "!=",
1392
- "in",
1393
- "not in",
1394
- "like",
1395
- "not like",
1396
- "between",
1397
- "not between",
1398
- "is null",
1399
- "is not null"
1400
- ]);
1401
- function jt(e, t) {
1402
- return t === "number" ? typeof e == "number" && Number.isFinite(e) : t === "boolean" ? typeof e == "boolean" : t === "date" ? e instanceof Date || typeof e == "string" && e.trim().length > 0 : typeof e == "string" || typeof e == "number" || typeof e == "boolean";
1403
- }
1404
- function Bt(e, t, n, r) {
1405
- const s = qe(e.relativeMeta);
1406
- if (s && Ye(s).dataAnchored) {
1407
- r.push(
1408
- `${n}.relativeMeta counts back from the latest data; a dashboard filter's dates run to now. Use a period counted back from today.`
1409
- );
1410
- return;
1411
- }
1412
- if (s && !je(String(e.operation), s)) {
1413
- r.push(
1414
- `${n}.relativeMeta runs only under between, not between, before, after, on or before, or on or after.`
1415
- );
1416
- return;
1417
- }
1418
- Ut(e.operation, e.values, t, `${n}.values`, r);
1419
- }
1420
- function Ut(e, t, n, r, s) {
1421
- if (e === "is null" || e === "is not null") {
1422
- t.length !== 0 && s.push(`${r} must be empty for null filter operations.`);
1423
- return;
1424
- }
1425
- if (e === "between" || e === "not between") {
1426
- if (t.length !== 2) {
1427
- s.push(
1428
- `${r} must contain exactly two values for between operations.`
1429
- );
1430
- return;
1431
- }
1432
- } else if (e === "in" || e === "not in") {
1433
- if (t.length === 0) {
1434
- s.push(
1435
- `${r} must contain at least one value for set operations.`
1436
- );
1437
- return;
1438
- }
1439
- } else if (t.length !== 1) {
1440
- s.push(
1441
- `${r} must contain exactly one value for '${String(e)}' operations.`
1442
- );
1443
- return;
1444
- }
1445
- for (const a of t)
1446
- if (!jt(a, n)) {
1447
- s.push(
1448
- `${r} contains a value that is incompatible with valueType '${n}'.`
1449
- );
1450
- return;
1451
- }
1452
- }
1453
- const L = 1, or = ["PRIVATE", "TEAM", "DASHBOARD"], zt = f.object({
1454
- filterId: f.string().min(1),
1455
- name: f.string(),
1456
- operation: f.string(),
1457
- valueType: f.enum(["string", "number", "date", "boolean"]),
1458
- values: f.array(f.unknown())
1459
- }).passthrough().superRefine((e, t) => {
1460
- const n = [];
1461
- qt.has(e.operation) ? Bt(e, e.valueType, "filterValue", n) : n.push("filterValue.operation must be a valid filter operation.");
1462
- for (const r of n) t.addIssue({ code: "custom", message: r });
1463
- }), q = f.unknown().superRefine((e, t) => {
1464
- for (const n of Ge(e).errors)
1465
- t.addIssue({ code: "custom", message: n.message });
1466
- }), Wt = f.discriminatedUnion("kind", [
1467
- f.object({ kind: f.literal("filter"), filterValue: zt }).strict(),
1468
- f.object({ kind: f.literal("control"), value: f.unknown() }).strict(),
1469
- f.object({
1470
- kind: f.literal("selection"),
1471
- selection: Be
1472
- }).strict()
1473
- ]), Qt = f.union([
1474
- f.object({
1475
- status: f.literal("set"),
1476
- value: Wt,
1477
- comparisonSelection: q.optional()
1478
- }).strict(),
1479
- f.object({
1480
- status: f.literal("cleared"),
1481
- comparisonSelection: q.optional()
1482
- }).strict(),
1483
- f.object({ comparisonSelection: q }).strict()
1484
- ]), Ve = ["bySheetId", "byCardId", "byDocumentSectionId"], Yt = /* @__PURE__ */ new Set(["version", "selectedSheetId", "inputs", "tableSettings"]), Gt = /* @__PURE__ */ new Set(["shared", ...Ve]), A = (e) => !!e && typeof e == "object" && !Array.isArray(e);
1485
- function Ie(e, t, n) {
1486
- if (e === void 0) return;
1487
- if (!A(e)) {
1488
- t.push({ target: "input", id: n });
1489
- return;
1490
- }
1491
- const r = {};
1492
- for (const [s, a] of Object.entries(e)) {
1493
- const i = s ? Qt.safeParse(a) : void 0;
1494
- i != null && i.success ? r[s] = i.data : t.push({
1495
- target: Ue(s) ? "selection" : "input",
1496
- id: s
1497
- });
1498
- }
1499
- return Object.keys(r).length ? r : void 0;
1500
- }
1501
- function Jt(e, t) {
1502
- if (t !== L)
1503
- return { ok: !1, error: `Unsupported bookmark version ${t}.` };
1504
- if (!A(e) || e.version !== L)
1505
- return { ok: !1, error: "The bookmark state is invalid." };
1506
- const n = [], r = Object.keys(e).filter((o) => !Yt.has(o));
1507
- let s;
1508
- typeof e.selectedSheetId == "string" && e.selectedSheetId ? s = e.selectedSheetId : e.selectedSheetId !== void 0 && n.push({ target: "sheet", id: String(e.selectedSheetId) });
1509
- const a = {};
1510
- if (A(e.inputs)) {
1511
- r.push(
1512
- ...Object.keys(e.inputs).filter((c) => !Gt.has(c)).map((c) => `inputs.${c}`)
1513
- );
1514
- const o = Ie(e.inputs.shared, n, "shared");
1515
- o && (a.shared = o);
1516
- for (const c of Ve) {
1517
- const u = e.inputs[c];
1518
- if (u === void 0) continue;
1519
- if (!A(u)) {
1520
- n.push({ target: "input", id: c });
1521
- continue;
1522
- }
1523
- const d = {};
1524
- for (const [m, I] of Object.entries(u)) {
1525
- const y = Ie(I, n, `${c}.${m}`);
1526
- y && (d[m] = y);
1527
- }
1528
- Object.keys(d).length && (a[c] = d);
1529
- }
1530
- } else e.inputs !== void 0 && r.push("inputs");
1531
- const i = {};
1532
- if (A(e.tableSettings))
1533
- for (const [o, c] of Object.entries(e.tableSettings)) {
1534
- const u = o ? _e(c, Me) : void 0;
1535
- u != null && u.ok ? Re(u.value) || (i[o] = u.value) : n.push({ target: "card", id: o });
1536
- }
1537
- else e.tableSettings !== void 0 && r.push("tableSettings");
1538
- return {
1539
- ok: !0,
1540
- value: {
1541
- version: L,
1542
- ...s ? { selectedSheetId: s } : {},
1543
- ...Object.keys(a).length ? { inputs: a } : {},
1544
- ...Object.keys(i).length ? { tableSettings: i } : {}
1545
- },
1546
- issues: n,
1547
- unknownKeys: r
1548
- };
1549
- }
1550
- function cr(e, t) {
1551
- const n = Jt(e, t);
1552
- return n.ok ? n.issues.some((r) => r.target === "card") ? { ok: !1, error: "The bookmark table settings are invalid." } : n.issues.length || n.unknownKeys.length ? { ok: !1, error: "The bookmark state is invalid." } : { ok: !0, value: n.value } : n;
1553
- }
1554
- export {
1555
- Nn as $,
1556
- Bn as A,
1557
- L as B,
1558
- Zn as C,
1559
- F as D,
1560
- Xn as E,
1561
- Vn as F,
1562
- dn as G,
1563
- g as H,
1564
- pn as I,
1565
- Kn as J,
1566
- He as K,
1567
- Kt as L,
1568
- wt as M,
1569
- ut as N,
1570
- bn as O,
1571
- fe as P,
1572
- at as Q,
1573
- fn as R,
1574
- we as S,
1575
- Cn as T,
1576
- xn as U,
1577
- Y as V,
1578
- kn as W,
1579
- X,
1580
- Te as Y,
1581
- mt as Z,
1582
- Ee as _,
1583
- zn as a,
1584
- se as a0,
1585
- ae as a1,
1586
- Xe as a2,
1587
- sn as a3,
1588
- Ze as a4,
1589
- an as a5,
1590
- mn as a6,
1591
- hn as a7,
1592
- yn as a8,
1593
- In as a9,
1594
- ir as aA,
1595
- qt as aB,
1596
- Bt as aC,
1597
- Ln as aD,
1598
- cn as aE,
1599
- nt as aF,
1600
- v as aG,
1601
- T as aH,
1602
- lt as aI,
1603
- H as aJ,
1604
- An as aK,
1605
- ie as aL,
1606
- vn as aM,
1607
- wn as aN,
1608
- En as aO,
1609
- Tn as aP,
1610
- Pn as aQ,
1611
- et as aR,
1612
- qn as aS,
1613
- jn as aT,
1614
- Un as aU,
1615
- on as aV,
1616
- Sn as aa,
1617
- gn as ab,
1618
- Ke as ac,
1619
- R as ad,
1620
- pt as ae,
1621
- S as af,
1622
- Ne as ag,
1623
- ht as ah,
1624
- yt as ai,
1625
- On as aj,
1626
- Z as ak,
1627
- It as al,
1628
- Dn as am,
1629
- Mn as an,
1630
- Rn as ao,
1631
- _n as ap,
1632
- Fn as aq,
1633
- un as ar,
1634
- st as as,
1635
- ln as at,
1636
- Ae as au,
1637
- At as av,
1638
- vt as aw,
1639
- Tt as ax,
1640
- $n as ay,
1641
- Lt as az,
1642
- Qn as b,
1643
- De as c,
1644
- Q as d,
1645
- Yn as e,
1646
- Gn as f,
1647
- Jn as g,
1648
- Hn as h,
1649
- Jt as i,
1650
- Me as j,
1651
- _t as k,
1652
- xe as l,
1653
- er as m,
1654
- tr as n,
1655
- nr as o,
1656
- cr as p,
1657
- Re as q,
1658
- Wn as r,
1659
- _e as s,
1660
- Rt as t,
1661
- rr as u,
1662
- Fe as v,
1663
- $t as w,
1664
- sr as x,
1665
- ar as y,
1666
- or as z
1667
- };