react-semaphor 0.1.544 → 0.1.546

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 (179) hide show
  1. package/dist/analytics-protocol/index.js +405 -441
  2. package/dist/assistant-context/index.js +1 -1
  3. package/dist/assistant-protocol/index.js +100 -76
  4. package/dist/brand-studio/index.js +5 -5
  5. package/dist/briefings/index.js +55 -52
  6. package/dist/chunks/{class-utils-Df1OVOT1.js → _commonjsHelpers-DimLPMtv.js} +124 -98
  7. package/dist/chunks/{add-to-dashboard-BuAqfA2Y.js → add-to-dashboard-BQRAAnc3.js} +55 -33
  8. package/dist/chunks/{analytics-base-schemas-BFAoRlkU.js → analytics-base-schemas-BKs3flFS.js} +2 -2
  9. package/dist/chunks/{assistant-chat-BNLkCDml.js → assistant-chat-BPXhulAx.js} +2792 -2562
  10. package/dist/chunks/{bookmark-state-CXw7lZ50.js → bookmark-state-C4vetoa0.js} +7 -8
  11. package/dist/chunks/column-catalog-BYnochWQ.js +3363 -0
  12. package/dist/chunks/comparison-window-caption-C2xF-eWw.js +1433 -0
  13. package/dist/chunks/{context-ClREvqCZ.js → context-BerEBuFR.js} +11 -6
  14. package/dist/chunks/custom-visual-inputs-CkJW9pBS.js +295 -0
  15. package/dist/chunks/{dashboard-g5a4DKWq.js → dashboard-C3CoKbGY.js} +1 -1
  16. package/dist/chunks/dashboard-briefing-launcher-Be4h-7My.js +3734 -0
  17. package/dist/chunks/dashboard-controls-bxPrlSyp.js +2307 -0
  18. package/dist/chunks/{dashboard-json-7qT9jmfL.js → dashboard-json-BrjxIiRt.js} +6 -6
  19. package/dist/chunks/document-dashboard-inputs-CRVHpIHp.js +3010 -0
  20. package/dist/chunks/{edit-dashboard-visual-BfJwnRIZ.js → edit-dashboard-visual-DYYYDjY6.js} +5986 -6063
  21. package/dist/chunks/{filter-value-text-CYsVYPuD.js → filter-value-text-Ddf55Ku1.js} +8 -8
  22. package/dist/chunks/global-date-filter-utils-9d6m9-FE.js +11859 -0
  23. package/dist/chunks/index-CtoK1Lgu.js +586 -0
  24. package/dist/chunks/{index-DkAyQvC6.js → index-DkQkMKa1.js} +385 -339
  25. package/dist/chunks/list-filter-DsaTbM3J.js +15 -0
  26. package/dist/chunks/matrix-analytical-definition-B9vW-osb.js +717 -0
  27. package/dist/chunks/{matrix-card-DjwWcCo8.js → matrix-card-LiMEipvq.js} +3 -3
  28. package/dist/chunks/{matrix-formatter-CxJLkztA.js → matrix-formatter-DWEeC0_c.js} +55 -55
  29. package/dist/chunks/{matrix-member-presentation-CQGdVks6.js → matrix-member-presentation-DqzG-UhQ.js} +1 -1
  30. package/dist/chunks/{matrix-operation-contract-8OIO4gob.js → matrix-operation-contract-D6vYkZK4.js} +72 -72
  31. package/dist/chunks/{metric-comparison-DEwi9uc2.js → metric-comparison-zpGw4lD6.js} +2 -2
  32. package/dist/chunks/normalize-dashboard-for-dirty-check-XKgH3GFX.js +119 -0
  33. package/dist/chunks/{pivot-header-presentation-DHcx1XGQ.js → pivot-header-presentation-CQnIDtUv.js} +1 -1
  34. package/dist/chunks/{pivot-result-identity-DJhXXcns.js → pivot-result-identity-C-Q1j1Wb.js} +1 -1
  35. package/dist/chunks/{pivot-result-lifecycle-DM4CyGKs.js → pivot-result-lifecycle-pwq3b7LC.js} +571 -380
  36. package/dist/chunks/{raw-temporal-contract-C51YG48G.js → raw-temporal-contract-WuXA8jBP.js} +1 -1
  37. package/dist/chunks/{raw-temporal-presentation-CLiVi90c.js → raw-temporal-presentation-CBzrDOjM.js} +8 -8
  38. package/dist/chunks/rendered-file-D8xEuVVx.js +108 -0
  39. package/dist/chunks/{report-preferences-dialog-Df7VpRVW.js → report-preferences-dialog-4QEZWe5U.js} +637 -610
  40. package/dist/chunks/{report-runtime-context-Dq8XyODK.js → report-runtime-context-hWiTCzFV.js} +2 -2
  41. package/dist/chunks/resolve-dashboard-input-context-UpK_LBpL.js +5677 -0
  42. package/dist/chunks/{saved-dashboard-context-B-mQ--nV.js → saved-dashboard-context-D_I3Lxk0.js} +184 -212
  43. package/dist/chunks/selection-filter-compiler-BKXmyLrS.js +79 -0
  44. package/dist/chunks/{selection-reducer-Dj_8xD69.js → selection-reducer-CJzkTZio.js} +15 -15
  45. package/dist/chunks/{semaphor-ready-indicator-DDAxk8us.js → semaphor-ready-indicator-4zpRHE-X.js} +56832 -59068
  46. package/dist/chunks/{shelf-drop-preview-context-BSRPwaED.js → shelf-drop-preview-context-Cfw7TRAx.js} +890 -871
  47. package/dist/chunks/{source-entity-resolution-BYn9giz3.js → source-entity-resolution-BIGRvtbG.js} +13 -13
  48. package/dist/chunks/{switch-C3jLxlG0.js → switch-CEBOR4n7.js} +47 -48
  49. package/dist/chunks/{table-export-sheet-CPfGAQ9X.js → table-export-sheet-4X9mAG3V.js} +1 -1
  50. package/dist/chunks/table-settings-CunhoDUi.js +605 -0
  51. package/dist/chunks/{temporal-bucket-D7NBrrtL.js → temporal-bucket-CQOSbv9-.js} +26 -26
  52. package/dist/chunks/{token-types-DBbZVQsm.js → token-types-BMqRmT-C.js} +1 -1
  53. package/dist/chunks/{use-create-flow-overlay-state-BxzFviM-.js → use-create-flow-overlay-state-DZBZiiD-.js} +83 -83
  54. package/dist/chunks/{validators-DMHTpf7a.js → validators-C-aOQlTB.js} +713 -658
  55. package/dist/dashboard/index.js +2 -2
  56. package/dist/dashboard-authoring/index.js +1800 -1135
  57. package/dist/data-app-sdk/index.js +6 -6
  58. package/dist/data-app-sdk-adapters/index.js +3 -3
  59. package/dist/data-app-sdk-validation/index.js +14 -14
  60. package/dist/format-utils/index.js +198 -187
  61. package/dist/index.js +359 -325
  62. package/dist/layouts/index.js +5 -242
  63. package/dist/report-runtime-context/index.js +2 -2
  64. package/dist/shared/index.js +4 -5
  65. package/dist/style.css +1 -1
  66. package/dist/surfboard/index.js +2 -2
  67. package/dist/types/briefings/attachment-outcomes.d.ts +1 -1
  68. package/dist/types/briefings/attachments.d.ts +33 -6
  69. package/dist/types/briefings/index.d.ts +6 -5
  70. package/dist/types/components/index.d.ts +2 -0
  71. package/dist/types/components/surfboard/arrange-layout-button.d.ts +8 -0
  72. package/dist/types/components/surfboard/filter/types.d.ts +0 -14
  73. package/dist/types/components/surfboard/screen-size-preview-button.d.ts +7 -0
  74. package/dist/types/index.js +6 -6
  75. package/dist/types/lib/charts/table-chart-types.d.ts +4 -0
  76. package/dist/types/lib/charts/types.d.ts +2 -2
  77. package/dist/types/lib/dashboard-inputs/dashboard-filter-mapping-authoring.d.ts +68 -82
  78. package/dist/types/lib/dashboard-inputs/dashboard-input-target-context.d.ts +0 -8
  79. package/dist/types/lib/dashboard-inputs/dashboard-input-values.d.ts +41 -1
  80. package/dist/types/lib/dashboard-inputs/filter-settings.d.ts +201 -0
  81. package/dist/types/lib/dashboard-inputs/prepare-loaded-dashboard.d.ts +15 -0
  82. package/dist/types/lib/dashboard-inputs/resolve-dashboard-input-context.d.ts +7 -2
  83. package/dist/types/lib/dashboard-inputs/resolve-selection-input.d.ts +1 -1
  84. package/dist/types/lib/dashboard-viewer/captured-runtime-values.d.ts +40 -0
  85. package/dist/types/lib/dashboard-viewer/compatibility-input-storage.d.ts +16 -16
  86. package/dist/types/lib/dashboard-viewer/viewer-state.d.ts +11 -9
  87. package/dist/types/lib/download-pdf.d.ts +75 -1
  88. package/dist/types/lib/hooks/use-date-filter.d.ts +5 -0
  89. package/dist/types/lib/hooks/use-text-filter.d.ts +5 -0
  90. package/dist/types/lib/matrix-table/matrix-delivery-policy.d.ts +5 -4
  91. package/dist/types/lib/matrix-table/matrix-editor.d.ts +52 -0
  92. package/dist/types/lib/query-context/assemble-card-query.d.ts +158 -0
  93. package/dist/types/lib/query-context/build-card-query-context.d.ts +3 -3
  94. package/dist/types/lib/query-context/build-dashboard-card-query-contract.d.ts +15 -6
  95. package/dist/types/lib/query-context/build-dashboard-execution-snapshot.d.ts +11 -13
  96. package/dist/types/lib/query-context/compile-dashboard-card-filters.d.ts +22 -12
  97. package/dist/types/lib/query-context/dashboard-filter-mapping-resolution.d.ts +69 -0
  98. package/dist/types/lib/stores/dashboard-store.d.ts +159 -56
  99. package/dist/types/lib/stores/editor-store.d.ts +0 -3
  100. package/dist/types/lib/types/common-types.d.ts +29 -6
  101. package/dist/types/lib/types/explorer-types.d.ts +10 -0
  102. package/dist/types/lib/types/semantic-types.d.ts +84 -0
  103. package/dist/types/lib/utils/build-saved-editor-card.d.ts +20 -0
  104. package/dist/types/lib/utils/card-type-change.d.ts +16 -0
  105. package/dist/types/lib/utils/field-availability-context.d.ts +25 -0
  106. package/dist/types/lib/utils/field-placement.d.ts +96 -0
  107. package/dist/types/lib/utils/field-state-calculator.d.ts +161 -0
  108. package/dist/types/lib/utils/qualified-entity-name.d.ts +2 -0
  109. package/dist/types/shared/analytics-protocol/field-provenance.d.ts +89 -0
  110. package/dist/types/shared/analytics-protocol/index.d.ts +2 -0
  111. package/dist/types/shared/analytics-protocol/query-policies.d.ts +52 -0
  112. package/dist/types/shared/analytics-protocol/time-window-schema.d.ts +1 -1
  113. package/dist/types/shared/analytics-protocol/time-window.d.ts +40 -1
  114. package/dist/types/shared/assistant-context/saved-dashboard-context.d.ts +8 -12
  115. package/dist/types/shared/assistant-protocol/answer-text.d.ts +20 -0
  116. package/dist/types/shared/assistant-protocol/context.d.ts +21 -21
  117. package/dist/types/shared/assistant-protocol/index.d.ts +1 -0
  118. package/dist/types/shared/assistant-protocol/limits.d.ts +6 -1
  119. package/dist/types/shared/assistant-protocol/parts.d.ts +43 -3
  120. package/dist/types/shared/assistant-protocol/request.d.ts +14 -2
  121. package/dist/types/shared/dashboard-authoring/calculated-field-identity.d.ts +3 -0
  122. package/dist/types/shared/dashboard-authoring/changes/card-query-part.d.ts +487 -0
  123. package/dist/types/shared/dashboard-authoring/changes/card-types.d.ts +34 -0
  124. package/dist/types/shared/dashboard-authoring/changes/dashboard-change.d.ts +7886 -0
  125. package/dist/types/shared/dashboard-authoring/changes/diagnostics.d.ts +43 -0
  126. package/dist/types/shared/dashboard-authoring/changes/read-card-query.d.ts +54 -0
  127. package/dist/types/shared/dashboard-authoring/changes/resolve-dashboard-changes.d.ts +89 -0
  128. package/dist/types/shared/dashboard-authoring/column-catalog.d.ts +32 -0
  129. package/dist/types/shared/dashboard-authoring/contracts.d.ts +0 -55
  130. package/dist/types/shared/dashboard-authoring/control-execution-contract.d.ts +16 -6
  131. package/dist/types/shared/dashboard-authoring/dashboard-card-source-index.d.ts +9 -1
  132. package/dist/types/shared/dashboard-authoring/dashboard-filter-mapping-contract.d.ts +7 -0
  133. package/dist/types/shared/dashboard-authoring/dashboard-input-scope.d.ts +118 -0
  134. package/dist/types/shared/dashboard-authoring/filter-applicability.d.ts +75 -0
  135. package/dist/types/shared/dashboard-authoring/filter-model/ad-hoc-filter-values.d.ts +10 -0
  136. package/dist/types/shared/dashboard-authoring/filter-model/filter-definitions.d.ts +29 -0
  137. package/dist/types/shared/dashboard-authoring/filter-model/filter-values.d.ts +58 -0
  138. package/dist/types/shared/dashboard-authoring/filter-model/index.d.ts +7 -0
  139. package/dist/types/shared/dashboard-authoring/filter-model/prototype-document-inputs.d.ts +15 -0
  140. package/dist/types/shared/dashboard-authoring/filter-model/read-dashboard-filter-model.d.ts +78 -0
  141. package/dist/types/shared/dashboard-authoring/filter-model/stored-dashboard.d.ts +18 -0
  142. package/dist/types/shared/dashboard-authoring/filter-model/toolbar-filter-reach.d.ts +23 -0
  143. package/dist/types/shared/dashboard-authoring/index.d.ts +20 -2
  144. package/dist/types/shared/dashboard-authoring/operations/apply-dashboard-operations.d.ts +10 -37
  145. package/dist/types/shared/dashboard-authoring/operations/operation-types.d.ts +189 -0
  146. package/dist/types/shared/dashboard-authoring/outline/outline-dashboard.d.ts +94 -0
  147. package/dist/types/shared/dashboard-authoring/outline/outline-filters.d.ts +78 -0
  148. package/dist/types/shared/dashboard-authoring/validators.d.ts +1 -2
  149. package/dist/types/shared/format-utils/exporters/index.d.ts +2 -0
  150. package/dist/types/shared/format-utils/exporters/rendered-file.d.ts +106 -0
  151. package/dist/types/shared/layouts/engine/grid.d.ts +25 -0
  152. package/dist/types/shared/layouts/engine/index.d.ts +4 -0
  153. package/dist/types/shared/layouts/engine/sheet-layout.d.ts +7 -0
  154. package/dist/types/shared/layouts/engine/types.d.ts +125 -0
  155. package/dist/types/shared/layouts/index.d.ts +1 -2
  156. package/package.json +2 -2
  157. package/dist/chunks/_commonjsHelpers-BkfeUUK-.js +0 -28
  158. package/dist/chunks/apply-dashboard-operations-Bz4n1Lq6.js +0 -2260
  159. package/dist/chunks/calendar-day-equality-BmJAWduY.js +0 -460
  160. package/dist/chunks/comparison-window-caption-BTkrN3W4.js +0 -1623
  161. package/dist/chunks/custom-visual-inputs-DUtpYZOk.js +0 -323
  162. package/dist/chunks/dashboard-briefing-launcher-DQ_8O_e2.js +0 -3725
  163. package/dist/chunks/dashboard-controls-8RyBTQUO.js +0 -2315
  164. package/dist/chunks/dashboard-filter-value-compatibility-CwQ_iSNb.js +0 -108
  165. package/dist/chunks/document-dashboard-inputs-BC6p-ESg.js +0 -8087
  166. package/dist/chunks/document-sheet-utils-Duo9uLoH.js +0 -3619
  167. package/dist/chunks/matrix-analytical-definition-C7Gb0e12.js +0 -117
  168. package/dist/chunks/normalize-dashboard-for-dirty-check-Bk3VYv_q.js +0 -67
  169. package/dist/chunks/numeric-presentation-DESvLiu9.js +0 -5227
  170. package/dist/chunks/sort-target-MT1WK1vX.js +0 -29
  171. package/dist/chunks/stable-serialize-CfqXeiBP.js +0 -6
  172. package/dist/chunks/table-settings-CLZocegs.js +0 -501
  173. package/dist/chunks/use-debounced-dirty-check-BwAbnX_5.js +0 -59
  174. package/dist/types/lib/dashboard-inputs/dashboard-filter-mapping-storage-transition.d.ts +0 -88
  175. package/dist/types/lib/dashboard-inputs/dashboard-input-scope.d.ts +0 -10
  176. package/dist/types/shared/dashboard-authoring/change-compiler.d.ts +0 -7
  177. package/dist/types/shared/dashboard-authoring/layout-compiler.d.ts +0 -2
  178. package/dist/types/shared/layouts/create-frame-layouts.d.ts +0 -27
  179. package/dist/types/shared/layouts/frame-layouts.d.ts +0 -23
@@ -0,0 +1,3363 @@
1
+ import { ai as ri, aj as ai, ak as oi, al as dt, am as si, an as k, ao as ft, ap as li, aq as ci, ar as De, as as ui, at as mt, au as di, av as fi, aw as mi, ax as pi, ay as yi, az as gi, aA as pt, aB as bi, aC as hi, aD as vi, aE as be, aF as Fi, aG as Ci, aH as Ii, b as xi, aI as Si, w as Mi, aJ as Di, aK as Ti } from "./resolve-dashboard-input-context-UpK_LBpL.js";
2
+ import { ab as yt, f as wi, e as Pi, a8 as gt, am as Oi, v as Ai } from "./validators-C-aOQlTB.js";
3
+ import "./matrix-operation-contract-D6vYkZK4.js";
4
+ import { r as Ni, C as Ei } from "./metric-comparison-zpGw4lD6.js";
5
+ import "./analytics-base-schemas-BKs3flFS.js";
6
+ import "zod";
7
+ import { q as Vi } from "./pivot-result-lifecycle-pwq3b7LC.js";
8
+ import { f as H } from "./matrix-formatter-DWEeC0_c.js";
9
+ import { b as bt, m as _i, h as Ri, d as Ce, e as Bi, i as B, u as E, R as Ki, v as ki, r as Li, z as qi } from "./temporal-bucket-CQOSbv9-.js";
10
+ import "../value-format-preferences/index.js";
11
+ import { K as zi, w as fe } from "./table-settings-CunhoDUi.js";
12
+ import { df as ht, dm as vt, dn as $i, dp as ji, cJ as Te, dq as Ui, cK as Ue, dr as N, ar as Hi, ds as Ft, dt as we, du as Gi, dv as Wi, dw as He, dx as Qi, dy as Ge, dz as Ji, dA as Yi, Q as Ct, dB as It, dC as xt, v as St, dD as We, X as q, dE as Pe, cU as Qe, cW as Oe, cR as Je, dF as Ye, di as Xi, b4 as Ae, dG as Zi, dH as en, dI as tn, cO as U, b7 as Xe, dJ as nn, a1 as Mt, a2 as Dt, d as rn, dK as L, b9 as an, dL as on, ba as sn, az as Tt, dM as ln, dN as cn, dO as un, dP as dn, b as wt, dh as fn, cN as mn, dQ as pn, c$ as Ie, dR as yn, dS as he, c1 as Pt, dT as Ze, dU as gn, bB as bn, c4 as et, c3 as hn, dV as vn } from "./global-date-filter-utils-9d6m9-FE.js";
13
+ import { r as Fn } from "./pivot-result-identity-C-Q1j1Wb.js";
14
+ import { g as Cn } from "./_commonjsHelpers-DimLPMtv.js";
15
+ import { e as In, d as xn } from "./raw-temporal-presentation-CBzrDOjM.js";
16
+ import "./index-CtoK1Lgu.js";
17
+ import "./index-CuHybtft.js";
18
+ import { i as Sn } from "./source-entity-resolution-BIGRvtbG.js";
19
+ import { R as Mn } from "./matrix-analytical-definition-B9vW-osb.js";
20
+ const _a = 15, Dn = /\{\{-?\s*filters\s*\|\s*where\s*-?\}\}/i, Tn = /\{\{-?\s*filters\s*\|\s*and\s*-?\}\}/i, wn = /\bwhere\b/i;
21
+ function Pn(e) {
22
+ return e != null && e.trim() ? Dn.test(e) || Tn.test(e) : !1;
23
+ }
24
+ function Ra(e) {
25
+ return !(e != null && e.trim()) || Pn(e) ? null : wn.test(e) ? {
26
+ helper: "{{ filters | and }}",
27
+ description: "For queries with an existing WHERE clause."
28
+ } : {
29
+ helper: "{{ filters | where }}",
30
+ description: "For queries without a WHERE clause."
31
+ };
32
+ }
33
+ const tt = [10, 20, 50, 100, 500, 1e3], On = 50;
34
+ function An(e) {
35
+ return e && e > 0 ? e : On;
36
+ }
37
+ function Ba(e) {
38
+ const t = An(e), i = [...tt];
39
+ return tt.includes(
40
+ t
41
+ ) || (i.push(t), i.sort((n, r) => n - r)), i;
42
+ }
43
+ function Ka(e) {
44
+ var t, i;
45
+ return !!((e.type === "table" || e.type === "detailTable") && e.sql && !ht(e.config) && !((i = (t = e.preferences) == null ? void 0 : t.tablePrefs) != null && i.forceClientPagination));
46
+ }
47
+ function Nn(e, t) {
48
+ var n, r, a, o;
49
+ if (t === "table-print")
50
+ return "disabled";
51
+ if ((r = (n = e.preferences) == null ? void 0 : n.tablePrefs) != null && r.forceClientPagination)
52
+ return "client";
53
+ const i = ht(e.config);
54
+ return e.sql && !i ? (o = (a = e.preferences) == null ? void 0 : a.tablePrefs) != null && o.enableDevModePagination ? "server" : "client" : i && ri(e) ? "server" : "client";
55
+ }
56
+ const Ot = Object.freeze({}), ka = {
57
+ access: "session-only",
58
+ printMode: !1,
59
+ baseline: null,
60
+ applied: null,
61
+ appliedBookmark: null,
62
+ tableSettings: Ot,
63
+ notices: []
64
+ };
65
+ function La(e) {
66
+ return !e.viewer.printMode && e.viewer.access !== "session-only" && !!e.viewer.baseline && !!e.viewerStateClient && !e.isDashboardEditing;
67
+ }
68
+ function En(e) {
69
+ return e.isDashboardEditing ? Ot : e.viewer.tableSettings;
70
+ }
71
+ function Vn(e, t) {
72
+ return En(e)[t];
73
+ }
74
+ function qa(e, t, i) {
75
+ if (!(i.isEditorPreview || e.isDashboardEditing) && zi(e.dashboard, t))
76
+ return { settings: Vn(e, t) };
77
+ }
78
+ function _n(e) {
79
+ var t;
80
+ return ai({
81
+ card: e.card,
82
+ paginationMode: Nn(e.card) === "server" ? "server" : "client",
83
+ result: {
84
+ keys: e.keys ?? oi(e.records),
85
+ rows: e.records,
86
+ columns: e.resultColumns,
87
+ columnKeyMap: e.columnKeyMap,
88
+ comparisonMetadata: e.comparisonMetadata
89
+ },
90
+ settings: (t = e.viewerTable) == null ? void 0 : t.settings,
91
+ projection: "export"
92
+ });
93
+ }
94
+ const za = (e) => {
95
+ e = e.replace("#", "");
96
+ const t = Number.parseInt(e.substr(0, 2), 16), i = Number.parseInt(e.substr(2, 2), 16), n = Number.parseInt(e.substr(4, 2), 16);
97
+ return (0.299 * t + 0.587 * i + 0.114 * n) / 255 > 0.5 ? "#000000" : "#ffffff";
98
+ }, Rn = () => ({
99
+ urlTemplate: "{value}",
100
+ // Default: use cell value as-is
101
+ labelType: "value",
102
+ // Default: show cell value as label
103
+ staticLabel: "",
104
+ labelColumn: "",
105
+ openInNewTab: !0
106
+ // Default: open in new tab (current behavior)
107
+ }), Ne = () => ({
108
+ type: "none",
109
+ inheritMetricFormat: !0,
110
+ textAlign: "left",
111
+ width: 150,
112
+ // Default width in pixels
113
+ minWidth: 50,
114
+ maxWidth: 500,
115
+ textOverflow: "ellipsis",
116
+ textWrap: "default",
117
+ numberFormat: {
118
+ style: "decimal",
119
+ currency: "USD",
120
+ locale: "en-US",
121
+ minimumFractionDigits: 0,
122
+ maximumFractionDigits: 2,
123
+ useGrouping: !0,
124
+ percentValueMode: "whole",
125
+ showDataBar: !1,
126
+ showHeatmap: !1,
127
+ dataBarColor: "#3b82f6",
128
+ // Default blue color
129
+ dataBarMinValue: void 0,
130
+ dataBarMaxValue: void 0
131
+ },
132
+ dateFormat: {
133
+ format: "MM/dd/yyyy",
134
+ useCustomFormat: !1,
135
+ customFormat: "yyyy-MM-dd'T'HH:mm:ss",
136
+ useRelativeTime: !1,
137
+ timezone: "auto",
138
+ // Default to auto (use context or browser timezone for display)
139
+ sourceTimezone: "auto"
140
+ // Default to auto (use explicit timezone if present, otherwise assume UTC)
141
+ },
142
+ linkFormat: Rn(),
143
+ colorRanges: []
144
+ });
145
+ function $a(e, t, i, n) {
146
+ return t && t !== "auto" ? t : i;
147
+ }
148
+ const ja = (e) => !e || e === "auto" ? "local time" : {
149
+ "America/New_York": "Eastern Time",
150
+ "America/Chicago": "Central Time",
151
+ "America/Denver": "Mountain Time",
152
+ "America/Los_Angeles": "Pacific Time",
153
+ "Europe/London": "London Time",
154
+ "Europe/Paris": "Central European Time",
155
+ "Asia/Tokyo": "Japan Time",
156
+ "Asia/Shanghai": "China Time",
157
+ UTC: "UTC"
158
+ }[e] || e;
159
+ function Bn(e) {
160
+ const t = H(e == null ? void 0 : e.format);
161
+ return !!(t && bt(t));
162
+ }
163
+ function xe(e, t) {
164
+ var o, s;
165
+ if (!(e != null && e.config) || e.type === "matrixTable" || (o = e.sql) != null && o.trim() || (s = e.python) != null && s.trim())
166
+ return;
167
+ const i = e.type === "detailTable" ? (e.config.detailColumns || []).map((l) => ({
168
+ field: l,
169
+ role: "detail"
170
+ })) : [
171
+ ...(e.type === "table" ? e.config.detailColumns || [] : []).map(
172
+ (l) => ({ field: l, role: "detail" })
173
+ ),
174
+ ...(e.config.metricColumns || []).map((l) => ({
175
+ field: l,
176
+ role: "metric"
177
+ })),
178
+ ...(e.config.groupByColumns || []).map((l) => ({
179
+ field: l,
180
+ role: "groupby"
181
+ }))
182
+ ], n = t.fieldRole ? i.filter((l) => l.role === t.fieldRole) : i, r = (l) => l.length === 1 ? l[0].field : void 0;
183
+ if (t.fieldId)
184
+ return r(
185
+ n.filter(
186
+ ({ field: l, role: c }) => l.id === t.fieldId && (!t.fieldRole || c === t.fieldRole)
187
+ )
188
+ );
189
+ if (t.metricId)
190
+ return r(
191
+ n.filter(
192
+ ({ field: l, role: c }) => c === (e.type === "detailTable" ? "detail" : "metric") && l.id === t.metricId
193
+ )
194
+ );
195
+ if (t.columnKeyMap) {
196
+ const l = [
197
+ t.columnId,
198
+ t.metricAlias,
199
+ ...t.columnIds || []
200
+ ].filter((f) => f !== void 0), c = n.map((f) => {
201
+ var d, y;
202
+ return {
203
+ ...f,
204
+ bindings: [
205
+ Fn(
206
+ t.columnKeyMap,
207
+ f.field.id,
208
+ f.role
209
+ ),
210
+ f.role === "metric" && f.field.alias ? (y = (d = t.columnKeyMap) == null ? void 0 : d.byMetricAlias) == null ? void 0 : y[f.field.alias] : void 0
211
+ ]
212
+ };
213
+ }), u = c.filter(
214
+ (f) => f.bindings.some(
215
+ (d) => (d == null ? void 0 : d.outputKey) !== void 0 && l.includes(d.outputKey)
216
+ )
217
+ );
218
+ return u.length ? r(u) : r(
219
+ c.filter(
220
+ (f) => f.bindings.some(
221
+ (d) => (d == null ? void 0 : d.rawKey) !== void 0 && l.includes(d.rawKey)
222
+ )
223
+ )
224
+ );
225
+ }
226
+ const a = (l) => l == null ? void 0 : l.trim().toLowerCase();
227
+ return r(
228
+ n.filter(
229
+ ({ field: l }) => [t.columnId, t.metricAlias, ...t.columnIds || []].some(
230
+ (c) => c !== void 0 && [
231
+ l.id,
232
+ l.alias,
233
+ l.name,
234
+ l.qualifiedFieldName,
235
+ l.label
236
+ ].some(
237
+ (u) => u !== void 0 && a(u) === a(c)
238
+ )
239
+ )
240
+ )
241
+ );
242
+ }
243
+ function Kn(e, t, i) {
244
+ return xe(e, {
245
+ fieldId: t.id,
246
+ fieldRole: "groupby"
247
+ }) ?? xe(
248
+ e,
249
+ i ? {
250
+ columnIds: [t.alias, t.name, t.id].filter(
251
+ (n) => !!n
252
+ ),
253
+ columnKeyMap: i,
254
+ fieldRole: "groupby"
255
+ } : { fieldId: t.id, fieldRole: "groupby" }
256
+ );
257
+ }
258
+ function Ua(e, t, i) {
259
+ return e.map((n) => {
260
+ const r = Kn(
261
+ t,
262
+ n,
263
+ i
264
+ );
265
+ if (!r) return n;
266
+ const { format: a, ...o } = n;
267
+ return {
268
+ ...o,
269
+ ...r.label ? { label: r.label } : {},
270
+ ...r.format !== void 0 ? { format: r.format } : {}
271
+ };
272
+ });
273
+ }
274
+ function At(e, t) {
275
+ const i = typeof e.decimalPlaces == "number", n = typeof e.minimumFractionDigits == "number" ? e.minimumFractionDigits : i ? e.decimalPlaces : t.min, r = typeof e.maximumFractionDigits == "number" ? e.maximumFractionDigits : i ? e.decimalPlaces : t.max;
276
+ return {
277
+ minimumFractionDigits: n,
278
+ maximumFractionDigits: Math.max(n, r)
279
+ };
280
+ }
281
+ function ce(e, t) {
282
+ const i = At(e, t), n = typeof e.suffix == "string" && e.suffix.length > 0;
283
+ return {
284
+ style: "decimal",
285
+ locale: e.locale,
286
+ currency: e.currency,
287
+ minimumFractionDigits: i.minimumFractionDigits,
288
+ maximumFractionDigits: i.maximumFractionDigits,
289
+ useGrouping: e.useGrouping,
290
+ // Preserve legacy behavior: explicit custom suffix should not trigger compacting.
291
+ useSuffix: !!(e.useSuffix && !n),
292
+ prefix: e.prefix,
293
+ suffix: e.suffix,
294
+ negativeInParentheses: e.negativeInParentheses,
295
+ multiplyBy: e.multiplyBy,
296
+ percentValueMode: e.percentValueMode
297
+ };
298
+ }
299
+ function Nt(e, t = "auto", i = {}) {
300
+ switch (t === "auto" && (t = $n(e, i)), t) {
301
+ case "number":
302
+ return Et(e, i);
303
+ case "currency":
304
+ return Vt(e, i);
305
+ case "percent":
306
+ return kn(e, i);
307
+ case "date":
308
+ return Ln(e, i);
309
+ case "scientific":
310
+ return qn(e, i);
311
+ case "duration":
312
+ return zn(e, i);
313
+ default:
314
+ return String(e);
315
+ }
316
+ }
317
+ function Et(e, t = {}) {
318
+ return e < 0 && !!t.prefix && !t.negativeInParentheses ? `-${Ce(
319
+ Math.abs(e),
320
+ ce(t, {
321
+ min: 0,
322
+ max: 0
323
+ })
324
+ )}` : Ce(
325
+ e,
326
+ ce(t, {
327
+ min: 0,
328
+ max: 0
329
+ })
330
+ );
331
+ }
332
+ function Vt(e, t = {}) {
333
+ return Bi(e, {
334
+ ...ce(t, {
335
+ min: 2,
336
+ max: 2
337
+ }),
338
+ style: "currency",
339
+ currency: t.currency || "USD"
340
+ });
341
+ }
342
+ function kn(e, t = {}) {
343
+ const i = At(t, { min: 1, max: 1 }), r = typeof t.multiplyBy == "number" && Number.isFinite(t.multiplyBy) ? t.multiplyBy : t.percentValueMode === "whole" ? 1 : 100, a = e * r;
344
+ return Ce(a, {
345
+ locale: t.locale,
346
+ minimumFractionDigits: i.minimumFractionDigits,
347
+ maximumFractionDigits: i.maximumFractionDigits,
348
+ useGrouping: t.useGrouping,
349
+ prefix: t.prefix,
350
+ suffix: t.suffix || "%",
351
+ negativeInParentheses: t.negativeInParentheses,
352
+ useSuffix: !1
353
+ });
354
+ }
355
+ function Ln(e, t = {}) {
356
+ const { locale: i = "en-US" } = t;
357
+ try {
358
+ const n = new Date(e);
359
+ return isNaN(n.getTime()) ? String(e) : new Intl.DateTimeFormat(i, {
360
+ dateStyle: "short"
361
+ }).format(n);
362
+ } catch {
363
+ return String(e);
364
+ }
365
+ }
366
+ function qn(e, t = {}) {
367
+ return Ri(
368
+ e,
369
+ ce(t, { min: 2, max: 2 })
370
+ );
371
+ }
372
+ function zn(e, t = {}) {
373
+ return _i(e, {
374
+ inputUnit: t.durationInputUnit,
375
+ outputStyle: t.durationDisplayStyle,
376
+ largestUnit: t.durationLargestUnit,
377
+ smallestUnit: t.durationSmallestUnit,
378
+ maxUnits: t.durationMaxUnits,
379
+ prefix: t.prefix,
380
+ suffix: t.suffix,
381
+ negativeInParentheses: t.negativeInParentheses
382
+ });
383
+ }
384
+ function $n(e, t) {
385
+ return t.currency ? "currency" : typeof e == "string" && !isNaN(Date.parse(e)) ? "date" : "number";
386
+ }
387
+ function Ha(e, t = {}) {
388
+ return (i) => Nt(i, e, t);
389
+ }
390
+ function jn({
391
+ number: e,
392
+ decimalPlaces: t = 0,
393
+ useSuffix: i = !1,
394
+ customSuffix: n = "",
395
+ currency: r = "",
396
+ locale: a = "en-US"
397
+ }) {
398
+ if (r) {
399
+ const o = Vt(e, {
400
+ currency: r,
401
+ decimalPlaces: t,
402
+ locale: a,
403
+ useSuffix: i && !n
404
+ });
405
+ return i && n ? `${o}${n}` : o;
406
+ }
407
+ return Et(e, {
408
+ decimalPlaces: t,
409
+ useSuffix: i && !n,
410
+ suffix: n,
411
+ locale: a
412
+ });
413
+ }
414
+ var Un = function e(t, i) {
415
+ if (t === i) return !0;
416
+ if (t && i && typeof t == "object" && typeof i == "object") {
417
+ if (t.constructor !== i.constructor) return !1;
418
+ var n, r, a;
419
+ if (Array.isArray(t)) {
420
+ if (n = t.length, n != i.length) return !1;
421
+ for (r = n; r-- !== 0; )
422
+ if (!e(t[r], i[r])) return !1;
423
+ return !0;
424
+ }
425
+ if (t.constructor === RegExp) return t.source === i.source && t.flags === i.flags;
426
+ if (t.valueOf !== Object.prototype.valueOf) return t.valueOf() === i.valueOf();
427
+ if (t.toString !== Object.prototype.toString) return t.toString() === i.toString();
428
+ if (a = Object.keys(t), n = a.length, n !== Object.keys(i).length) return !1;
429
+ for (r = n; r-- !== 0; )
430
+ if (!Object.prototype.hasOwnProperty.call(i, a[r])) return !1;
431
+ for (r = n; r-- !== 0; ) {
432
+ var o = a[r];
433
+ if (!(o === "_owner" && t.$$typeof) && !e(t[o], i[o]))
434
+ return !1;
435
+ }
436
+ return !0;
437
+ }
438
+ return t !== t && i !== i;
439
+ };
440
+ const ue = /* @__PURE__ */ Cn(Un);
441
+ function Hn(e) {
442
+ if (typeof e == "number")
443
+ return Number.isFinite(e);
444
+ if (typeof e != "string")
445
+ return !1;
446
+ const t = e.trim().replace(/,/g, "");
447
+ return t !== "" && Number.isFinite(Number(t));
448
+ }
449
+ function Gn(e) {
450
+ if (!(e != null && e.length))
451
+ return [];
452
+ const t = /* @__PURE__ */ new Set();
453
+ return e.forEach((i) => {
454
+ Object.keys(i).forEach((n) => t.add(n));
455
+ }), [...t];
456
+ }
457
+ function Wn(e) {
458
+ return Gn(e).filter(
459
+ (i) => e == null ? void 0 : e.some((n) => Hn(n[i]))
460
+ );
461
+ }
462
+ function Ee(e, t) {
463
+ var i;
464
+ if (t.id)
465
+ return (i = e.sql) != null && i.trim() ? { kind: "column", columnKey: t.id } : { kind: "metric", metricId: t.id };
466
+ }
467
+ function _t(e) {
468
+ const t = e.context.preferences;
469
+ if (!t)
470
+ return e.authoredFormat;
471
+ const i = Ee(e.card, e.metric);
472
+ return E(
473
+ e.authoredFormat,
474
+ t,
475
+ i ? e.context.resolveBoundCurrency(i) : void 0
476
+ );
477
+ }
478
+ function Qn(e) {
479
+ var a, o, s;
480
+ const t = (s = (o = (a = e.card.preferences) == null ? void 0 : a.tablePrefs) == null ? void 0 : o.columnSettingsMap) == null ? void 0 : s[e.columnKey], i = (t == null ? void 0 : t.type) === "number" ? si(
481
+ { dataType: "number", format: void 0 },
482
+ t
483
+ ) : void 0, n = i == null ? void 0 : i.authoredFormat, r = B(n) ? _t({
484
+ card: e.card,
485
+ metric: {
486
+ id: e.columnKey
487
+ },
488
+ context: e.context,
489
+ authoredFormat: n
490
+ }) : void 0;
491
+ return {
492
+ id: e.columnKey,
493
+ name: e.columnKey,
494
+ label: e.columnKey,
495
+ alias: e.columnKey,
496
+ dataType: "number",
497
+ role: "metric",
498
+ format: r
499
+ };
500
+ }
501
+ function Ga(e) {
502
+ var r, a;
503
+ const t = new Set(
504
+ Wn(e.records)
505
+ ), i = new Set(
506
+ e.renderedMetricKeys || e.resultKeys
507
+ ), n = ((a = (r = e.card.preferences) == null ? void 0 : r.tablePrefs) == null ? void 0 : a.columnSettingsMap) || {};
508
+ return e.resultKeys.filter(
509
+ (o) => {
510
+ var s;
511
+ return i.has(o) && (t.has(o) || ((s = n[o]) == null ? void 0 : s.type) === "number");
512
+ }
513
+ );
514
+ }
515
+ function Wa(e) {
516
+ var a, o;
517
+ const { card: t, context: i } = e;
518
+ if (!(i != null && i.preferences) || !vt(t.type))
519
+ return t;
520
+ const n = i.preferences, r = (a = t.sql) != null && a.trim() ? e.resultMetricKeys.map(
521
+ (s) => Qn({
522
+ card: t,
523
+ columnKey: s,
524
+ context: i
525
+ })
526
+ ) : (((o = t.config) == null ? void 0 : o.metricColumns) || []).map((s) => {
527
+ const l = dt(t, s), c = l.authoredFormat;
528
+ if (!B(c))
529
+ return s;
530
+ const u = Ee(t, s), f = u ? i.resolveBoundCurrency(u) : void 0;
531
+ return l.source === "inferred" && !f ? s : {
532
+ ...s,
533
+ format: l.source === "inferred" ? E(
534
+ c,
535
+ n,
536
+ f
537
+ ) : _t({
538
+ card: t,
539
+ metric: s,
540
+ context: i,
541
+ authoredFormat: c
542
+ })
543
+ };
544
+ });
545
+ return {
546
+ ...t,
547
+ config: {
548
+ ...t.config || {},
549
+ metricColumns: r
550
+ }
551
+ };
552
+ }
553
+ function me(e) {
554
+ var l;
555
+ const { card: t, context: i, formatOptions: n } = e, r = i == null ? void 0 : i.preferences;
556
+ if (!t || !r || !vt(t.type))
557
+ return n;
558
+ if (!n) {
559
+ const c = e.metrics.filter(
560
+ (f) => !!f
561
+ ), u = c.some(
562
+ (f) => B(f.format)
563
+ );
564
+ return c.length < 2 || !u ? n : k(
565
+ E({ type: "number" }, r),
566
+ { preserveOmittedProperties: !0 }
567
+ );
568
+ }
569
+ if ((l = t.sql) != null && l.trim()) {
570
+ const c = e.metrics.filter(
571
+ (f) => !!f
572
+ ), u = c.filter(
573
+ (f) => B(f.format)
574
+ );
575
+ if (u.length === 0)
576
+ return n;
577
+ if (u.length !== c.length)
578
+ return k(
579
+ E({ type: "number" }, r),
580
+ { preserveOmittedProperties: !0 }
581
+ );
582
+ }
583
+ const a = ft(n, {
584
+ preserveOmittedProperties: !0
585
+ });
586
+ if (!B(a))
587
+ return n;
588
+ const o = e.metrics.flatMap((c) => {
589
+ if (!c)
590
+ return [];
591
+ const u = Ee(t, c);
592
+ return [
593
+ E(
594
+ a,
595
+ r,
596
+ u ? i.resolveBoundCurrency(u) : void 0
597
+ )
598
+ ];
599
+ });
600
+ if (o.length === 0)
601
+ return k(
602
+ E(a, r),
603
+ { preserveOmittedProperties: !0 }
604
+ );
605
+ const [s] = o;
606
+ if (o.some((c) => !ue(c, s))) {
607
+ const c = E(
608
+ {
609
+ ...a,
610
+ type: "number",
611
+ currency: void 0
612
+ },
613
+ r
614
+ );
615
+ return k(c, {
616
+ preserveOmittedProperties: !0
617
+ });
618
+ }
619
+ return k(s, {
620
+ preserveOmittedProperties: !0
621
+ });
622
+ }
623
+ const Jn = /* @__PURE__ */ new Set([
624
+ "horizontalBar",
625
+ "tornado",
626
+ "pyramid",
627
+ "range"
628
+ ]), Yn = /* @__PURE__ */ new Set([
629
+ "tornado",
630
+ "pyramid",
631
+ "range"
632
+ ]), Xn = /* @__PURE__ */ new Set([
633
+ "tornado",
634
+ "pyramid",
635
+ "range"
636
+ ]);
637
+ function Zn(e) {
638
+ const { chartType: t, resultKeys: i, config: n } = e, r = 1 + (n != null && n.enableGrouping && (n.groupKey || i[1]) ? 1 : 0), a = i.slice(r), o = (n == null ? void 0 : n.xMetricKey) ?? a[0], s = (n == null ? void 0 : n.yMetricKey) ?? a[1] ?? a[0], l = t === "bubble" ? (n == null ? void 0 : n.radiusMetricKey) ?? a[2] ?? a[1] ?? a[0] : void 0, c = new Set(i);
639
+ return [o, s, l].filter((u) => !!u).filter((u) => c.has(u));
640
+ }
641
+ function Qa(e) {
642
+ const { chartType: t, resultKeys: i, preferences: n } = e;
643
+ return t === "scatter" || t === "bubble" ? [
644
+ ...new Set(
645
+ Zn({
646
+ chartType: t,
647
+ resultKeys: i,
648
+ config: n == null ? void 0 : n.bubbleScatterConfig
649
+ })
650
+ )
651
+ ] : Xn.has(t || "") ? i.slice(2) : i.length === 1 ? [i[0]] : i.slice(1);
652
+ }
653
+ function re(e, t) {
654
+ var i;
655
+ return ((i = t == null ? void 0 : t.chartOptions) == null ? void 0 : i.indexAxis) === "y" || Jn.has(e || "") ? "x" : "y";
656
+ }
657
+ function Ja(e, t) {
658
+ return re(e, t) === "x";
659
+ }
660
+ function er(e, t) {
661
+ return re(e, t) === "y" ? t == null ? void 0 : t.yAxisConfig : (t == null ? void 0 : t.xAxisConfig) || (Yn.has(e || "") ? t == null ? void 0 : t.yAxisConfig : void 0);
662
+ }
663
+ function te(e) {
664
+ return e ? Object.entries(e).some(([t, i]) => i == null || i === "" ? !1 : t === "type" ? i !== "auto" : !0) : !1;
665
+ }
666
+ function Rt(e) {
667
+ if (e)
668
+ return e.alias || e.label || e.name;
669
+ }
670
+ function Se(e, t) {
671
+ var n;
672
+ return (((n = e == null ? void 0 : e.config) == null ? void 0 : n.metricColumns) || []).find((r) => {
673
+ const a = Rt(r);
674
+ return t.metricId && r.id === t.metricId || t.metricAlias && a === t.metricAlias || t.metricAlias && r.alias === t.metricAlias || t.columnId && a === t.columnId || t.columnId && r.alias === t.columnId || t.columnId && r.label === t.columnId || t.columnId && r.name === t.columnId;
675
+ });
676
+ }
677
+ function ae(e, t) {
678
+ var n, r;
679
+ const i = xe(e, t);
680
+ if (!(i && ((r = (n = e == null ? void 0 : e.config) == null ? void 0 : n.groupByColumns) != null && r.includes(i)) && !Bn(i)))
681
+ return i;
682
+ }
683
+ function tr(e) {
684
+ return !!e && !(e != null && e.format) && yt(e == null ? void 0 : e.dataType) === "number";
685
+ }
686
+ const ir = {
687
+ style: "decimal",
688
+ showDataBar: !1,
689
+ dataBarColor: "#3b82f6"
690
+ };
691
+ function Bt(e) {
692
+ if (!e)
693
+ return;
694
+ const t = Ne();
695
+ return {
696
+ ...t,
697
+ ...e,
698
+ inheritMetricFormat: e.numberFormat ? e.inheritMetricFormat : e.inheritMetricFormat ?? t.inheritMetricFormat,
699
+ numberFormat: {
700
+ ...ir,
701
+ ...e.numberFormat
702
+ },
703
+ dateFormat: {
704
+ ...t.dateFormat,
705
+ ...e.dateFormat
706
+ },
707
+ linkFormat: {
708
+ ...t.linkFormat,
709
+ ...e.linkFormat
710
+ }
711
+ };
712
+ }
713
+ function Ya(e) {
714
+ return Object.fromEntries(
715
+ Object.entries(e || {}).map(([t, i]) => [
716
+ t,
717
+ Bt(i)
718
+ ])
719
+ );
720
+ }
721
+ function se(e) {
722
+ return !!(e && typeof e == "object" && !Array.isArray(e) && Object.getPrototypeOf(e) === Object.prototype);
723
+ }
724
+ function Kt(e, t, i) {
725
+ if (!se(i))
726
+ return i;
727
+ const n = se(e) ? e : {}, r = se(t) ? t : {}, a = {};
728
+ for (const o of Object.keys(i)) {
729
+ const s = i[o];
730
+ if (s === void 0)
731
+ continue;
732
+ const l = Object.prototype.hasOwnProperty.call(
733
+ n,
734
+ o
735
+ ), c = r[o];
736
+ if (l && ue(s, c)) {
737
+ a[o] = n[o];
738
+ continue;
739
+ }
740
+ if (!l && ue(s, c))
741
+ continue;
742
+ const u = Kt(
743
+ n[o],
744
+ c,
745
+ s
746
+ );
747
+ se(u) && Object.keys(u).length === 0 && !l || (a[o] = u);
748
+ }
749
+ return a;
750
+ }
751
+ function nr(e) {
752
+ let t = Kt(
753
+ e.persisted,
754
+ e.baseline,
755
+ e.next
756
+ );
757
+ if (e.enforceDeclaredSqlTemporalFormat && e.next.type === "date" && !e.next.dateFormat.useRelativeTime && e.next.dateFormat.useCustomFormat) {
758
+ const i = e.next.dateFormat.customFormat;
759
+ if (!(i != null && i.trim()))
760
+ throw new Ki(
761
+ "invalid_raw_temporal_format",
762
+ "Custom table date formatting requires a non-empty pattern."
763
+ );
764
+ ki({
765
+ dialect: "date_fns",
766
+ pattern: i,
767
+ valueKind: e.rawTemporalValueKind
768
+ }), t = {
769
+ ...t,
770
+ dateFormat: {
771
+ ...t.dateFormat,
772
+ useCustomFormat: !0,
773
+ customFormat: i
774
+ }
775
+ };
776
+ }
777
+ return e.next.type === "number" && !ue(e.next.numberFormat, e.baseline.numberFormat) && t.numberFormat ? {
778
+ ...t,
779
+ type: "number",
780
+ inheritMetricFormat: e.next.inheritMetricFormat ?? !1
781
+ } : e.next.type === "number" && e.baseline.inheritMetricFormat === !0 && e.next.inheritMetricFormat === !1 ? {
782
+ ...t,
783
+ type: "number",
784
+ inheritMetricFormat: !1
785
+ } : e.forcePersistDateType && e.next.type === "date" ? {
786
+ ...t,
787
+ type: "date"
788
+ } : t;
789
+ }
790
+ function Xa(e) {
791
+ return e.reset ? rr(e.persisted, e.columnId) : {
792
+ ...e.persisted,
793
+ [e.columnId]: nr({
794
+ persisted: e.persisted[e.columnId],
795
+ baseline: e.baseline,
796
+ next: e.next,
797
+ forcePersistDateType: e.forcePersistDateType,
798
+ enforceDeclaredSqlTemporalFormat: e.enforceDeclaredSqlTemporalFormat,
799
+ rawTemporalValueKind: e.rawTemporalValueKind
800
+ })
801
+ };
802
+ }
803
+ function rr(e, t) {
804
+ if (!(t in e))
805
+ return e;
806
+ const i = { ...e };
807
+ return delete i[t], i;
808
+ }
809
+ function ar(e, t) {
810
+ const i = e || Ne(), n = !t;
811
+ return {
812
+ ...i,
813
+ type: "number",
814
+ textAlign: i.type === "none" ? "right" : i.textAlign,
815
+ numberFormat: {
816
+ style: "decimal",
817
+ minimumFractionDigits: n ? i.numberFormat.minimumFractionDigits : void 0,
818
+ maximumFractionDigits: n ? i.numberFormat.maximumFractionDigits : void 0,
819
+ useGrouping: i.numberFormat.useGrouping,
820
+ showDataBar: i.numberFormat.showDataBar,
821
+ showHeatmap: i.numberFormat.showHeatmap,
822
+ dataBarColor: i.numberFormat.dataBarColor,
823
+ dataBarMinValue: i.numberFormat.dataBarMinValue,
824
+ dataBarMaxValue: i.numberFormat.dataBarMaxValue
825
+ }
826
+ };
827
+ }
828
+ function ve(e) {
829
+ if (e)
830
+ return e.trim().toLowerCase();
831
+ }
832
+ const kt = /\s*(?:\((?:previous|last year|start|target|comparison)\)|δ)\s*$/i;
833
+ function or(e) {
834
+ const t = e == null ? void 0 : e.trim();
835
+ return t ? t.replace(kt, "").trim() || t : void 0;
836
+ }
837
+ function sr(e) {
838
+ const t = e == null ? void 0 : e.trim();
839
+ return t ? kt.test(t) : !1;
840
+ }
841
+ function lr(e, t) {
842
+ return t.metricAlias ? e.find(
843
+ (i) => Ni(i) === t.metricAlias
844
+ ) : t.metricId ? e.find((i) => i.id === t.metricId) : void 0;
845
+ }
846
+ function cr(e) {
847
+ var h;
848
+ const {
849
+ card: t,
850
+ metricId: i,
851
+ metricAlias: n,
852
+ datasetIndex: r,
853
+ datasetLabel: a,
854
+ metricKey: o
855
+ } = e, s = ((h = t == null ? void 0 : t.config) == null ? void 0 : h.metricColumns) || [];
856
+ if (n || i)
857
+ return lr(s, {
858
+ metricAlias: n,
859
+ metricId: i
860
+ });
861
+ const l = [o, a], c = l.some(
862
+ (m) => sr(m)
863
+ ), u = l.filter(
864
+ (m) => !!m
865
+ );
866
+ for (const m of u) {
867
+ const g = Se(t, {
868
+ columnId: m,
869
+ metricAlias: m
870
+ });
871
+ if (g)
872
+ return g;
873
+ }
874
+ const f = u.map((m) => ve(m)).filter((m) => !!m), d = u.map((m) => or(m)).filter((m) => !!m);
875
+ for (const m of d) {
876
+ const g = Se(t, {
877
+ columnId: m,
878
+ metricAlias: m
879
+ });
880
+ if (g)
881
+ return g;
882
+ }
883
+ if (s.length === 1)
884
+ return s[0];
885
+ if (!c && typeof r == "number" && r >= 0 && r < s.length)
886
+ return s[r];
887
+ const y = d.map((m) => ve(m)).filter((m) => !!m), v = [
888
+ ...f,
889
+ ...y
890
+ ];
891
+ if (v.length !== 0)
892
+ return s.find((m) => {
893
+ const g = [
894
+ m.alias,
895
+ m.label,
896
+ m.name,
897
+ Rt(m)
898
+ ].map((C) => ve(C)).filter((C) => !!C);
899
+ return v.some(
900
+ (C) => g.includes(C)
901
+ );
902
+ });
903
+ }
904
+ function ur(e) {
905
+ const t = H(e == null ? void 0 : e.format);
906
+ return k(t);
907
+ }
908
+ function it(e, t) {
909
+ if (t)
910
+ return Se(e, {
911
+ columnId: t,
912
+ metricAlias: t
913
+ });
914
+ }
915
+ function nt(e) {
916
+ const t = ft(e);
917
+ if (t)
918
+ return JSON.stringify(t);
919
+ }
920
+ function dr(e, t) {
921
+ const i = nt(e), n = nt(t);
922
+ return !!(i && n && i === n);
923
+ }
924
+ function fr(e) {
925
+ if (e.length === 0)
926
+ return;
927
+ const t = e.map(
928
+ (o) => ur(o)
929
+ );
930
+ if (!t.every(
931
+ (o) => te(o)
932
+ ))
933
+ return;
934
+ const n = t, [r] = n;
935
+ return n.every(
936
+ (o) => dr(r, o)
937
+ ) ? r : void 0;
938
+ }
939
+ function mr(e) {
940
+ const t = e.formatMode || e.legacyMode;
941
+ return t === "override" ? "override" : t === "inherit" ? "inherit" : e.legacyMode && e.legacyMode !== "auto" && e.legacyMode !== "inherit" && e.legacyMode !== "override" || te(e.formatOptions) ? "override" : "inherit";
942
+ }
943
+ function pe(e) {
944
+ const t = mr({
945
+ formatMode: e.formatMode,
946
+ legacyMode: e.legacyMode,
947
+ formatOptions: e.overrideFormatOptions
948
+ });
949
+ if (t === "override" && te(e.overrideFormatOptions))
950
+ return {
951
+ formatOptions: e.overrideFormatOptions || void 0,
952
+ source: "override"
953
+ };
954
+ if (t === "override" && e.legacyMode === "none")
955
+ return {
956
+ formatOptions: void 0,
957
+ source: "override",
958
+ rawValue: !0
959
+ };
960
+ const i = fr(
961
+ e.metrics || []
962
+ );
963
+ if (te(i))
964
+ return {
965
+ formatOptions: i,
966
+ source: "metric"
967
+ };
968
+ const n = Fr(e.preferences);
969
+ return te(n) ? {
970
+ formatOptions: n,
971
+ source: "legacy"
972
+ } : {
973
+ formatOptions: void 0,
974
+ source: "auto"
975
+ };
976
+ }
977
+ function Lt(e) {
978
+ var l, c, u;
979
+ const { card: t, chartType: i, axis: n, preferences: r } = e, a = ((l = t == null ? void 0 : t.config) == null ? void 0 : l.metricColumns) || [], o = (r == null ? void 0 : r.datasetOptions) || [];
980
+ if (!a.length)
981
+ return [];
982
+ if (i === "combo")
983
+ return n === "x" ? [] : a.filter((f, d) => {
984
+ const y = o.find((h) => h.idx === d);
985
+ return ((y == null ? void 0 : y.yAxisId) === "y2" ? "y2" : "y") === n;
986
+ });
987
+ if (i === "bubble" || i === "scatter") {
988
+ if (n === "y2")
989
+ return [];
990
+ const f = it(
991
+ t,
992
+ (c = r == null ? void 0 : r.bubbleScatterConfig) == null ? void 0 : c.xMetricKey
993
+ ) || a[0], d = it(
994
+ t,
995
+ (u = r == null ? void 0 : r.bubbleScatterConfig) == null ? void 0 : u.yMetricKey
996
+ ) || a[1] || a[0];
997
+ return n === "x" ? f ? [f] : [] : d ? [d] : [];
998
+ }
999
+ const s = re(i, r);
1000
+ return i === "radar" ? n === "y" ? a : [] : n !== s ? [] : a;
1001
+ }
1002
+ function Ve(e) {
1003
+ const { card: t, chartType: i, axis: n, preferences: r, axisConfig: a } = e, o = Lt({
1004
+ card: t,
1005
+ chartType: i,
1006
+ axis: n,
1007
+ preferences: r
1008
+ }), s = pe({
1009
+ formatMode: a == null ? void 0 : a.formatMode,
1010
+ overrideFormatOptions: a == null ? void 0 : a.formatOptions,
1011
+ metrics: o,
1012
+ preferences: r
1013
+ });
1014
+ return {
1015
+ ...s,
1016
+ formatOptions: me({
1017
+ card: t,
1018
+ metrics: o,
1019
+ formatOptions: s.formatOptions,
1020
+ context: e.numericPresentation
1021
+ })
1022
+ };
1023
+ }
1024
+ function qt(e, t) {
1025
+ if (!e && (!t || t === "auto" || t === "none"))
1026
+ return;
1027
+ const i = {
1028
+ ...e || {}
1029
+ };
1030
+ return t && t !== "auto" && t !== "none" && !i.type && (i.type = t), i;
1031
+ }
1032
+ function pr(e) {
1033
+ const { preferences: t, metric: i } = e, n = t == null ? void 0 : t.tooltipConfig, r = pe({
1034
+ formatMode: n == null ? void 0 : n.formatMode,
1035
+ legacyMode: n == null ? void 0 : n.mode,
1036
+ overrideFormatOptions: n == null ? void 0 : n.formatOptions,
1037
+ metrics: i ? [i] : [],
1038
+ preferences: t
1039
+ });
1040
+ return {
1041
+ ...r,
1042
+ formatOptions: me({
1043
+ card: e.card,
1044
+ metrics: e.metric ? [e.metric] : [],
1045
+ formatOptions: r.formatOptions,
1046
+ context: e.numericPresentation
1047
+ })
1048
+ };
1049
+ }
1050
+ function _e(e, t, i) {
1051
+ return t === re(i, e) ? er(i, e) : t === "x" ? e == null ? void 0 : e.xAxisConfig : t === "y2" ? e == null ? void 0 : e.secondaryYAxisConfig : e == null ? void 0 : e.yAxisConfig;
1052
+ }
1053
+ function Re(e) {
1054
+ const { chartType: t, preferences: i } = e;
1055
+ return t === "bubble" || t === "scatter" ? "y" : re(t, i);
1056
+ }
1057
+ function zt(e) {
1058
+ switch (e) {
1059
+ case "pie":
1060
+ case "doughnut":
1061
+ case "polarArea":
1062
+ case "funnel":
1063
+ case "treemap":
1064
+ case "heatmap":
1065
+ return !1;
1066
+ default:
1067
+ return !0;
1068
+ }
1069
+ }
1070
+ function Za(e) {
1071
+ const { card: t, chartType: i, preferences: n, metric: r } = e, a = pr({
1072
+ card: t,
1073
+ preferences: n,
1074
+ metric: r,
1075
+ numericPresentation: e.numericPresentation
1076
+ });
1077
+ if (a.source === "override")
1078
+ return a;
1079
+ const o = e.axis || Re({ chartType: i, preferences: n }), s = Ve({
1080
+ card: t,
1081
+ chartType: i,
1082
+ axis: o,
1083
+ preferences: n,
1084
+ axisConfig: _e(n, o, i),
1085
+ numericPresentation: e.numericPresentation
1086
+ });
1087
+ return s.source === "override" ? s : a;
1088
+ }
1089
+ function eo(e) {
1090
+ const { card: t, chartType: i, preferences: n, dataLabelsConfig: r } = e, a = i || (t == null ? void 0 : t.type), o = Re({
1091
+ chartType: a,
1092
+ preferences: n
1093
+ }), s = Lt({
1094
+ card: t,
1095
+ chartType: a,
1096
+ axis: o,
1097
+ preferences: n
1098
+ }), l = pe({
1099
+ formatMode: r == null ? void 0 : r.formatMode,
1100
+ legacyMode: r == null ? void 0 : r.format,
1101
+ overrideFormatOptions: qt(
1102
+ r == null ? void 0 : r.formatOptions,
1103
+ r == null ? void 0 : r.format
1104
+ ),
1105
+ metrics: s,
1106
+ preferences: n
1107
+ }), c = {
1108
+ ...l,
1109
+ formatOptions: me({
1110
+ card: t,
1111
+ metrics: s,
1112
+ formatOptions: l.formatOptions,
1113
+ context: e.numericPresentation
1114
+ })
1115
+ };
1116
+ if (c.source === "override" || !zt(a))
1117
+ return c;
1118
+ const u = Ve({
1119
+ card: t,
1120
+ chartType: a,
1121
+ axis: o,
1122
+ preferences: n,
1123
+ axisConfig: _e(
1124
+ n,
1125
+ o,
1126
+ a
1127
+ ),
1128
+ numericPresentation: e.numericPresentation
1129
+ });
1130
+ return u.source === "override" ? u : c;
1131
+ }
1132
+ function yr(e) {
1133
+ const { preferences: t, dataLabelsConfig: i, metric: n } = e, r = pe({
1134
+ formatMode: i == null ? void 0 : i.formatMode,
1135
+ legacyMode: i == null ? void 0 : i.format,
1136
+ overrideFormatOptions: qt(
1137
+ i == null ? void 0 : i.formatOptions,
1138
+ i == null ? void 0 : i.format
1139
+ ),
1140
+ metrics: n ? [n] : [],
1141
+ preferences: t
1142
+ });
1143
+ return {
1144
+ ...r,
1145
+ formatOptions: me({
1146
+ card: e.card,
1147
+ metrics: e.metric ? [e.metric] : [],
1148
+ formatOptions: r.formatOptions,
1149
+ context: e.numericPresentation
1150
+ })
1151
+ };
1152
+ }
1153
+ function to(e) {
1154
+ var o, s;
1155
+ const t = cr({
1156
+ card: e.card,
1157
+ metricId: e.metricId,
1158
+ metricAlias: e.metricAlias,
1159
+ datasetIndex: e.datasetIndex,
1160
+ datasetLabel: e.datasetLabel,
1161
+ metricKey: e.metricKey
1162
+ }), i = yr({
1163
+ card: e.card,
1164
+ preferences: e.preferences,
1165
+ dataLabelsConfig: e.dataLabelsConfig,
1166
+ metric: t,
1167
+ numericPresentation: e.numericPresentation
1168
+ });
1169
+ if (i.source === "override")
1170
+ return i;
1171
+ const n = (o = e.card) == null ? void 0 : o.type;
1172
+ if (!zt(n))
1173
+ return i;
1174
+ let r = Re({
1175
+ chartType: n,
1176
+ preferences: e.preferences
1177
+ });
1178
+ if (n === "combo" && typeof e.datasetIndex == "number") {
1179
+ const c = (((s = e.preferences) == null ? void 0 : s.datasetOptions) || []).find(
1180
+ (u) => u.idx === e.datasetIndex
1181
+ );
1182
+ r = (c == null ? void 0 : c.yAxisId) === "y2" ? "y2" : "y";
1183
+ }
1184
+ const a = Ve({
1185
+ card: e.card,
1186
+ chartType: n,
1187
+ axis: r,
1188
+ preferences: e.preferences,
1189
+ axisConfig: _e(
1190
+ e.preferences,
1191
+ r,
1192
+ n
1193
+ ),
1194
+ numericPresentation: e.numericPresentation
1195
+ });
1196
+ return a.source === "override" ? a : i;
1197
+ }
1198
+ function io(e) {
1199
+ return (e == null ? void 0 : e.rawValue) === !0;
1200
+ }
1201
+ function gr(e) {
1202
+ const t = e == null ? void 0 : e.numberFormat;
1203
+ if (!t)
1204
+ return;
1205
+ if (t.style === "duration")
1206
+ return k(De(t), {
1207
+ preserveOmittedProperties: !0
1208
+ });
1209
+ const i = t.style === "currency" ? "currency" : t.style === "percent" ? "percent" : t.style === "scientific" ? "scientific" : "number", n = t.minimumFractionDigits, r = t.maximumFractionDigits;
1210
+ return {
1211
+ type: i,
1212
+ currency: i === "currency" ? t.currency : void 0,
1213
+ locale: t.locale,
1214
+ decimalPlaces: n === r ? r : void 0,
1215
+ minimumFractionDigits: n,
1216
+ maximumFractionDigits: r,
1217
+ useGrouping: t.useGrouping,
1218
+ percentValueMode: i === "percent" ? t.percentValueMode : void 0,
1219
+ multiplyBy: t.scale,
1220
+ useSuffix: t.compact,
1221
+ negativeInParentheses: t.negativeStyle === "parentheses",
1222
+ prefix: t.prefix,
1223
+ suffix: t.suffix
1224
+ };
1225
+ }
1226
+ function br(e, t, i = !1) {
1227
+ const n = i ? { preserveOmittedProperties: !0 } : void 0, r = H(e == null ? void 0 : e.format, n), a = mt(
1228
+ r,
1229
+ n
1230
+ );
1231
+ if (!a)
1232
+ return;
1233
+ const o = t || Ne(), s = i ? {
1234
+ showDataBar: o.numberFormat.showDataBar,
1235
+ showHeatmap: o.numberFormat.showHeatmap,
1236
+ dataBarColor: o.numberFormat.dataBarColor,
1237
+ dataBarMinValue: o.numberFormat.dataBarMinValue,
1238
+ dataBarMaxValue: o.numberFormat.dataBarMaxValue
1239
+ } : o.numberFormat, l = o.type && o.type !== "none";
1240
+ return {
1241
+ ...o,
1242
+ type: l ? o.type : "number",
1243
+ inheritMetricFormat: o.inheritMetricFormat ?? !0,
1244
+ textAlign: l ? o.textAlign : "right",
1245
+ numberFormat: {
1246
+ ...s,
1247
+ ...a,
1248
+ showDataBar: s.showDataBar,
1249
+ showHeatmap: s.showHeatmap,
1250
+ dataBarColor: s.dataBarColor,
1251
+ dataBarMinValue: s.dataBarMinValue,
1252
+ dataBarMaxValue: s.dataBarMaxValue
1253
+ }
1254
+ };
1255
+ }
1256
+ function $t(e) {
1257
+ var b, I, _, O;
1258
+ const {
1259
+ card: t,
1260
+ columnId: i,
1261
+ persistedSettings: n,
1262
+ resolvedSettings: r,
1263
+ fallbackSettings: a,
1264
+ metricId: o,
1265
+ metricAlias: s,
1266
+ fieldId: l,
1267
+ fieldRole: c,
1268
+ columnKeyMap: u,
1269
+ valueFormatPreferences: f,
1270
+ boundCurrency: d,
1271
+ preserveOmittedProperties: y
1272
+ } = e, v = n ?? ((_ = (I = (b = t == null ? void 0 : t.preferences) == null ? void 0 : b.tablePrefs) == null ? void 0 : I.columnSettingsMap) == null ? void 0 : _[i]), h = !((O = t == null ? void 0 : t.sql) != null && O.trim()) || li(v), m = h ? f : null, g = h ? d : void 0, C = ci(
1273
+ v == null ? void 0 : v.numberFormat
1274
+ ), D = r ?? Bt(v);
1275
+ if (D && D.inheritMetricFormat !== !0)
1276
+ return rt(
1277
+ D,
1278
+ m,
1279
+ g,
1280
+ {
1281
+ preserveHistoricalPersistedPrecision: C
1282
+ }
1283
+ );
1284
+ const w = ae(t, {
1285
+ columnId: i,
1286
+ metricId: o,
1287
+ metricAlias: s,
1288
+ columnKeyMap: u,
1289
+ fieldId: l,
1290
+ fieldRole: c
1291
+ }), S = br(
1292
+ w,
1293
+ D || a,
1294
+ y ?? !!f
1295
+ ), V = !S && m && tr(w) ? ar(
1296
+ D || a,
1297
+ g
1298
+ ) : void 0;
1299
+ return rt(
1300
+ S || V || D || a,
1301
+ m,
1302
+ g,
1303
+ {
1304
+ preserveHistoricalPersistedPrecision: !!(D && C && !S && !V)
1305
+ }
1306
+ );
1307
+ }
1308
+ function rt(e, t, i, n) {
1309
+ if (!e || e.type !== "number" || !t)
1310
+ return e;
1311
+ const r = e.numberFormat, a = r ? n != null && n.preserveHistoricalPersistedPrecision ? ui(r) : De(r, {
1312
+ preserveOmittedProperties: !0
1313
+ }) : { type: "number" };
1314
+ if (!a || !B(a))
1315
+ return e;
1316
+ const o = E(
1317
+ a,
1318
+ t,
1319
+ i
1320
+ ), s = mt(o, {
1321
+ preserveOmittedProperties: !0
1322
+ });
1323
+ return s ? {
1324
+ ...e,
1325
+ numberFormat: {
1326
+ ...r,
1327
+ ...s,
1328
+ showDataBar: (r == null ? void 0 : r.showDataBar) ?? s.showDataBar,
1329
+ showHeatmap: r == null ? void 0 : r.showHeatmap,
1330
+ dataBarColor: (r == null ? void 0 : r.dataBarColor) ?? s.dataBarColor,
1331
+ dataBarMinValue: r == null ? void 0 : r.dataBarMinValue,
1332
+ dataBarMaxValue: r == null ? void 0 : r.dataBarMaxValue
1333
+ }
1334
+ } : e;
1335
+ }
1336
+ function de(e) {
1337
+ if (!e.valueFormatPreferences)
1338
+ return;
1339
+ const t = $t(e);
1340
+ if (!t || t.type !== "number")
1341
+ return;
1342
+ const i = De(t.numberFormat, {
1343
+ preserveOmittedProperties: !0
1344
+ });
1345
+ if (!(!i || !bt(i)))
1346
+ return i;
1347
+ }
1348
+ function hr(e) {
1349
+ var n, r;
1350
+ if (!e.presentation.preferences)
1351
+ return;
1352
+ const t = ae(e.card, {
1353
+ columnId: e.columnId,
1354
+ metricId: e.metricId,
1355
+ metricAlias: e.metricAlias,
1356
+ columnKeyMap: e.columnKeyMap
1357
+ });
1358
+ if (e.comparisonValueKind === "percent_change" || e.comparisonValueKind === "ratio") {
1359
+ const a = de({
1360
+ card: e.card,
1361
+ columnId: e.columnId,
1362
+ persistedSettings: e.persistedSettings,
1363
+ resolvedSettings: e.resolvedSettings,
1364
+ fallbackSettings: e.fallbackSettings,
1365
+ metricId: e.metricId,
1366
+ columnKeyMap: e.columnKeyMap,
1367
+ metricAlias: e.metricAlias ?? (t == null ? void 0 : t.alias),
1368
+ valueFormatPreferences: e.presentation.preferences
1369
+ }), o = mi(e.comparisonPrecision) ?? (B(a) ? a.maximumFractionDigits : void 0) ?? (e.comparisonValueKind === "percent_change" ? 1 : 2);
1370
+ return e.comparisonValueKind === "percent_change" ? {
1371
+ type: "percent",
1372
+ locale: e.presentation.preferences.locale,
1373
+ percentValueMode: "fraction",
1374
+ minimumFractionDigits: o,
1375
+ maximumFractionDigits: o
1376
+ } : {
1377
+ type: "number",
1378
+ locale: e.presentation.preferences.locale,
1379
+ minimumFractionDigits: o,
1380
+ maximumFractionDigits: o,
1381
+ suffix: "×"
1382
+ };
1383
+ }
1384
+ const i = pi({
1385
+ card: e.card,
1386
+ columnKey: e.columnId,
1387
+ metricId: e.metricId ?? (t && !((r = (n = e.card.config) == null ? void 0 : n.groupByColumns) != null && r.includes(t)) ? t.id : void 0)
1388
+ });
1389
+ return de({
1390
+ card: e.card,
1391
+ columnId: e.columnId,
1392
+ persistedSettings: e.persistedSettings,
1393
+ resolvedSettings: e.resolvedSettings,
1394
+ fallbackSettings: e.fallbackSettings,
1395
+ metricId: e.metricId,
1396
+ columnKeyMap: e.columnKeyMap,
1397
+ metricAlias: e.metricAlias ?? (t == null ? void 0 : t.alias),
1398
+ valueFormatPreferences: e.presentation.preferences,
1399
+ boundCurrency: i ? e.presentation.resolveBoundCurrency(i) : void 0
1400
+ });
1401
+ }
1402
+ function vr(e) {
1403
+ var s, l, c, u, f, d, y;
1404
+ if (e.card.type === "matrixTable" && e.target.kind === "matrix_measure") {
1405
+ const v = e.target, h = yi(e.card, e.matrixCatalog).find(
1406
+ (g) => g.measureId === v.measureId
1407
+ ), m = h == null ? void 0 : h.canonical;
1408
+ return m && (m.type === "number" || m.type === "currency") ? E(
1409
+ m,
1410
+ e.valueFormatPreferences,
1411
+ e.boundCurrency
1412
+ ) : void 0;
1413
+ }
1414
+ if (e.target.kind === "matrix_measure")
1415
+ return;
1416
+ if (e.card.type === "kpi") {
1417
+ const v = e.target.kind === "metric" ? e.target.metricId : void 0, h = v ? ((l = (s = e.card.config) == null ? void 0 : s.metricColumns) == null ? void 0 : l.findIndex(
1418
+ (C) => C.id === v
1419
+ )) ?? -1 : 0;
1420
+ if (h < 0)
1421
+ return;
1422
+ const m = gi(e.card, {
1423
+ metricIndex: h,
1424
+ resultColumnKey: e.target.kind === "column" ? e.target.columnKey : void 0
1425
+ }), g = m.authoredFormat;
1426
+ return m.currencyBindable && g && B(g) ? E(
1427
+ g,
1428
+ e.valueFormatPreferences,
1429
+ e.boundCurrency
1430
+ ) : void 0;
1431
+ }
1432
+ if (!((c = e.card.sql) != null && c.trim()) && !$i(e.card.type) && e.target.kind === "metric") {
1433
+ const v = e.target.metricId, h = (f = (u = e.card.config) == null ? void 0 : u.metricColumns) == null ? void 0 : f.find(
1434
+ (C) => C.id === v
1435
+ );
1436
+ if (!h)
1437
+ return;
1438
+ const m = dt(
1439
+ e.card,
1440
+ h
1441
+ ), g = m.authoredFormat;
1442
+ return m.currencyBindable && g && B(g) ? E(
1443
+ g,
1444
+ e.valueFormatPreferences,
1445
+ e.boundCurrency
1446
+ ) : void 0;
1447
+ }
1448
+ const i = ((y = (d = e.card.preferences) == null ? void 0 : d.tablePrefs) == null ? void 0 : y.columnSettingsMap) || {}, n = e.target.kind === "metric" ? e.target.metricId : void 0, r = e.target.kind === "column" ? [e.target.columnKey] : [
1449
+ ...e.resultColumnKeys || [],
1450
+ ...Object.keys(i),
1451
+ e.target.metricId
1452
+ ], a = e.target.kind === "column" ? e.target.columnKey : r.find(
1453
+ (v) => {
1454
+ var h;
1455
+ return ((h = ae(e.card, {
1456
+ columnId: v
1457
+ })) == null ? void 0 : h.id) === n;
1458
+ }
1459
+ ) || n, o = de({
1460
+ card: e.card,
1461
+ columnId: a,
1462
+ metricId: n,
1463
+ persistedSettings: i[a],
1464
+ valueFormatPreferences: e.valueFormatPreferences,
1465
+ boundCurrency: e.boundCurrency
1466
+ });
1467
+ return B(o) ? o : void 0;
1468
+ }
1469
+ function no(e) {
1470
+ var i, n, r, a, o, s;
1471
+ const t = e.persistedSettings ?? ((a = (r = (n = (i = e.card) == null ? void 0 : i.preferences) == null ? void 0 : n.tablePrefs) == null ? void 0 : r.columnSettingsMap) == null ? void 0 : a[e.columnId]);
1472
+ if (!t && !e.resolvedSettings || (t == null ? void 0 : t.inheritMetricFormat) === !0 || ((o = e.resolvedSettings) == null ? void 0 : o.inheritMetricFormat) === !0) {
1473
+ const l = H(
1474
+ (s = ae(e.card, {
1475
+ columnId: e.columnId,
1476
+ metricId: e.metricId,
1477
+ metricAlias: e.metricAlias,
1478
+ columnKeyMap: e.columnKeyMap
1479
+ })) == null ? void 0 : s.format,
1480
+ { preserveOmittedProperties: !0 }
1481
+ );
1482
+ if ((l == null ? void 0 : l.type) === "date" || (l == null ? void 0 : l.type) === "duration")
1483
+ return k(l, {
1484
+ preserveOmittedProperties: !0
1485
+ });
1486
+ }
1487
+ return gr(
1488
+ $t({
1489
+ ...e,
1490
+ persistedSettings: t
1491
+ })
1492
+ );
1493
+ }
1494
+ function Fr(e) {
1495
+ var v, h, m, g, C, D, w;
1496
+ const t = (v = e == null ? void 0 : e.formatNumber) == null ? void 0 : v.enabled, i = typeof t == "string" ? t.trim().toLowerCase() !== "false" : t !== !1, n = di(e == null ? void 0 : e.numberAxisFormat) || (i ? fi(e == null ? void 0 : e.formatNumber) : void 0), r = k(n);
1497
+ if (!r || !r.type || r.type === "auto")
1498
+ return r;
1499
+ const a = (h = e == null ? void 0 : e.numberAxisFormat) == null ? void 0 : h.decimalPlaces, o = i ? (m = e == null ? void 0 : e.formatNumber) == null ? void 0 : m.decimalPlaces : void 0, s = typeof a == "number" ? a : typeof o == "number" ? o : void 0, l = (g = e == null ? void 0 : e.numberAxisFormat) == null ? void 0 : g.minimumFractionDigits, c = (C = e == null ? void 0 : e.numberAxisFormat) == null ? void 0 : C.maximumFractionDigits, u = i ? (D = e == null ? void 0 : e.formatNumber) == null ? void 0 : D.minimumFractionDigits : void 0, f = i ? (w = e == null ? void 0 : e.formatNumber) == null ? void 0 : w.maximumFractionDigits : void 0, d = typeof s == "number" ? s : typeof l == "number" ? l : typeof u == "number" ? u : 0, y = typeof s == "number" ? s : typeof c == "number" ? c : typeof f == "number" ? f : 0;
1500
+ return {
1501
+ ...r,
1502
+ decimalPlaces: d === y ? y : r.decimalPlaces,
1503
+ minimumFractionDigits: d,
1504
+ maximumFractionDigits: Math.max(
1505
+ d,
1506
+ y
1507
+ )
1508
+ };
1509
+ }
1510
+ function ro(e) {
1511
+ var r, a, o, s, l;
1512
+ const { value: t, formatOptions: i, preferences: n } = e;
1513
+ return i != null && i.type && i.type !== "auto" ? Nt(t, i.type, i) : jn({
1514
+ number: t,
1515
+ decimalPlaces: ((r = n == null ? void 0 : n.numberAxisFormat) == null ? void 0 : r.decimalPlaces) ?? 0,
1516
+ useSuffix: !!((a = n == null ? void 0 : n.numberAxisFormat) != null && a.suffix),
1517
+ customSuffix: ((o = n == null ? void 0 : n.numberAxisFormat) == null ? void 0 : o.suffix) || "",
1518
+ locale: ((s = n == null ? void 0 : n.numberAxisFormat) == null ? void 0 : s.locale) || "en-US",
1519
+ currency: ((l = n == null ? void 0 : n.numberAxisFormat) == null ? void 0 : l.currency) || ""
1520
+ });
1521
+ }
1522
+ function Cr(e) {
1523
+ return ji({
1524
+ ...e,
1525
+ activation: Te({
1526
+ card: e.card,
1527
+ cardConfig: e.cardConfig
1528
+ })
1529
+ });
1530
+ }
1531
+ function ao(e) {
1532
+ return Ui({
1533
+ activation: Te({
1534
+ card: e.card,
1535
+ cardConfig: e.cardConfig
1536
+ }),
1537
+ result: e.result,
1538
+ expectedResultOwner: e.expectedResultOwner
1539
+ });
1540
+ }
1541
+ function Ir(e) {
1542
+ var n, r;
1543
+ const t = pt(e.card, e.effectiveCardConfig), i = _n({
1544
+ card: t,
1545
+ records: e.rows,
1546
+ keys: e.rows.length === 0 ? e.resultKeys : void 0,
1547
+ columnKeyMap: e.result.columnKeyMap,
1548
+ resultColumns: e.result.resultColumns,
1549
+ comparisonMetadata: e.result.comparisonMetadata,
1550
+ viewerTable: e.file.viewerTable
1551
+ });
1552
+ return e.rows.length === 0 && !e.resultKeys || i.visibleKeys.length === 0 ? null : {
1553
+ view: i,
1554
+ formatOptions: {
1555
+ useFormattedValues: e.file.useFormattedValues,
1556
+ timezone: e.reportContext.calendar.tz,
1557
+ delimiter: e.file.delimiter,
1558
+ csvEncoding: e.file.csvEncoding,
1559
+ includeHeaders: e.file.includeHeaders,
1560
+ columnSettings: (r = (n = e.card.preferences) == null ? void 0 : n.tablePrefs) == null ? void 0 : r.columnSettingsMap,
1561
+ visibleColumns: [...i.visibleKeys],
1562
+ columnLabels: Object.fromEntries(i.visibleKeys.map((a) => [a, i.labels[a] ?? a]))
1563
+ }
1564
+ };
1565
+ }
1566
+ function xr(e) {
1567
+ var i;
1568
+ const t = (i = e.preferences) == null ? void 0 : i.comparisonPresentation;
1569
+ return {
1570
+ ...Ei,
1571
+ ...t,
1572
+ ...t != null && t.conditionalLabels ? { conditionalLabels: { ...t.conditionalLabels } } : {},
1573
+ ...t != null && t.colors ? { colors: { ...t.colors } } : {}
1574
+ };
1575
+ }
1576
+ function Sr(e) {
1577
+ var D, w, F, S, V;
1578
+ const t = pt(e.card, e.effectiveCardConfig), { cardId: i, ...n } = e.requestPayloadBase, r = e.formatOptions.visibleColumns ?? [], a = [
1579
+ ...r,
1580
+ ...Object.keys(e.formatOptions.columnSettings ?? {})
1581
+ ], o = bi(
1582
+ e.card,
1583
+ r,
1584
+ e.effectiveCardConfig
1585
+ ), s = hi(
1586
+ e.card,
1587
+ e.effectiveCardConfig,
1588
+ o
1589
+ ), l = vi(
1590
+ t,
1591
+ a
1592
+ ), c = new Set(
1593
+ l.eligibleTargets.map(be)
1594
+ ), u = (p) => c.has(be(p)) ? Ci({
1595
+ bindings: n.controlBindings,
1596
+ controls: [
1597
+ ...n.controlDefinitions ?? [],
1598
+ ...n.cardControlDefinitions ?? []
1599
+ ],
1600
+ values: n.controlValues,
1601
+ target: p,
1602
+ knownTargets: l.knownTargets,
1603
+ eligibleTargets: l.eligibleTargets
1604
+ }).currency : void 0, f = Fi({
1605
+ card: e.card,
1606
+ comparisonMetadata: e.comparisonMetadata,
1607
+ columnKeyMap: ((D = e.canonicalPivotResult) == null ? void 0 : D.columnKeyMap) ?? e.columnKeyMap
1608
+ }), d = Te({
1609
+ card: e.card,
1610
+ cardConfig: e.effectiveCardConfig
1611
+ });
1612
+ if (e.card.type === "pivotTable" && d && !e.canonicalPivotResult)
1613
+ throw new Error(
1614
+ "Canonical pivot export requires a parsed pivot result lifecycle."
1615
+ );
1616
+ const y = Cr({
1617
+ card: e.card,
1618
+ cardConfig: e.effectiveCardConfig,
1619
+ columns: ((w = e.canonicalPivotResult) == null ? void 0 : w.columns) ?? e.resultColumns,
1620
+ columnKeyMap: ((F = e.canonicalPivotResult) == null ? void 0 : F.columnKeyMap) ?? e.columnKeyMap,
1621
+ resultRowCount: e.totalRows,
1622
+ valueFormatPreferences: e.reportContext.valueFormat
1623
+ }), v = (d == null ? void 0 : d.fields) ?? [], h = new Map(
1624
+ v.map((p) => [
1625
+ `${p.role}:${p.id}`,
1626
+ p
1627
+ ])
1628
+ ), m = /* @__PURE__ */ new Map();
1629
+ if (e.card.type === "detailTable" && n.resultOwner === "config") {
1630
+ const p = e.resultColumns || [];
1631
+ if (p.filter(
1632
+ (I) => I.rawTemporal
1633
+ ).length > 0) {
1634
+ if (!e.columnKeyMap)
1635
+ throw new Error(
1636
+ "Canonical raw temporal export requires an authoritative columnKeyMap."
1637
+ );
1638
+ const I = In({
1639
+ cardType: e.card.type,
1640
+ resultOwner: n.resultOwner,
1641
+ effectiveCardConfig: e.effectiveCardConfig,
1642
+ result: {
1643
+ records: [],
1644
+ columns: p,
1645
+ columnKeyMap: e.columnKeyMap
1646
+ },
1647
+ preferences: e.reportContext.valueFormat,
1648
+ calendar: e.reportContext.calendar
1649
+ });
1650
+ if (I.kind === "invalid") throw I.error;
1651
+ if (I.kind === "loaded_empty" || I.kind === "loaded_valid")
1652
+ for (const [_, O] of I.presentation.byColumnKey)
1653
+ m.set(_, O.format);
1654
+ }
1655
+ } else if (n.resultOwner === "freeform" && n.sql.trim() && !n.python.trim())
1656
+ for (const [p, b] of Object.entries(
1657
+ ((V = (S = e.card.preferences) == null ? void 0 : S.tablePrefs) == null ? void 0 : V.columnSettingsMap) || {}
1658
+ )) {
1659
+ if (b.type !== "date") continue;
1660
+ const I = xn(b.dateFormat);
1661
+ I && m.set(
1662
+ p,
1663
+ Li({
1664
+ format: I,
1665
+ preferences: e.reportContext.valueFormat,
1666
+ calendar: e.reportContext.calendar
1667
+ })
1668
+ );
1669
+ }
1670
+ const g = [
1671
+ ...new Set(a)
1672
+ ].flatMap((p) => {
1673
+ var P, J, Y, X, Z, ee;
1674
+ if (y.byColumnKey.has(p) || m.has(p))
1675
+ return [];
1676
+ const b = f.columnPresentationOwners.get(p), I = (P = t.sql) != null && P.trim() ? void 0 : ae(t, {
1677
+ columnId: p,
1678
+ columnKeyMap: e.columnKeyMap,
1679
+ metricId: b == null ? void 0 : b.metricId,
1680
+ metricAlias: b == null ? void 0 : b.metricAlias
1681
+ }), _ = I ? { kind: "metric", metricId: I.id } : { kind: "column", columnKey: p }, O = c.has(
1682
+ be(_)
1683
+ ), W = u(_), R = (X = (Y = (J = t.preferences) == null ? void 0 : J.tablePrefs) == null ? void 0 : Y.columnSettingsMap) == null ? void 0 : X[p], j = {
1684
+ dashboardId: e.dashboardId,
1685
+ cardId: t.id
1686
+ }, K = { kind: "column", columnKey: p }, T = I && (!R || R.inheritMetricFormat === !0) ? H(I.format, {
1687
+ preserveOmittedProperties: !0
1688
+ }) : void 0;
1689
+ if ((T == null ? void 0 : T.type) === "date")
1690
+ return [
1691
+ {
1692
+ scope: j,
1693
+ target: K,
1694
+ format: {
1695
+ type: "date",
1696
+ locale: T.locale ?? e.reportContext.valueFormat.locale,
1697
+ ...T.pattern ? { pattern: T.pattern } : {},
1698
+ ...T.timezone ? { timezone: T.timezone } : {},
1699
+ ...T.sourceTimezone ? { sourceTimezone: T.sourceTimezone } : {}
1700
+ }
1701
+ }
1702
+ ];
1703
+ const A = (b ? hr({
1704
+ card: t,
1705
+ columnId: p,
1706
+ columnKeyMap: e.columnKeyMap,
1707
+ persistedSettings: R,
1708
+ metricId: b.metricId,
1709
+ metricAlias: b.metricAlias,
1710
+ comparisonValueKind: b.kind,
1711
+ comparisonPrecision: (ee = (Z = t.preferences) == null ? void 0 : Z.comparisonPresentation) == null ? void 0 : ee.precision,
1712
+ presentation: {
1713
+ preferences: e.reportContext.valueFormat,
1714
+ resolveBoundCurrency: u
1715
+ }
1716
+ }) : void 0) ?? (O ? vr({
1717
+ card: t,
1718
+ target: _,
1719
+ resultColumnKeys: a,
1720
+ valueFormatPreferences: e.reportContext.valueFormat,
1721
+ boundCurrency: W
1722
+ }) : void 0) ?? de({
1723
+ card: t,
1724
+ columnId: p,
1725
+ columnKeyMap: e.columnKeyMap,
1726
+ metricId: b == null ? void 0 : b.metricId,
1727
+ persistedSettings: R,
1728
+ valueFormatPreferences: e.reportContext.valueFormat
1729
+ }), Q = (A == null ? void 0 : A.type) === "duration" ? A : A ? E(
1730
+ A,
1731
+ e.reportContext.valueFormat,
1732
+ W
1733
+ ) : E(
1734
+ {
1735
+ type: "number",
1736
+ minimumFractionDigits: 0,
1737
+ maximumFractionDigits: 3
1738
+ },
1739
+ e.reportContext.valueFormat
1740
+ );
1741
+ return [
1742
+ Q.type === "duration" ? { scope: j, target: K, format: Q } : { scope: j, target: K, format: Q }
1743
+ ];
1744
+ });
1745
+ g.push(
1746
+ ...[...y.byColumnKey.values()].map((p) => {
1747
+ const b = h.get(
1748
+ `${p.role ?? "groupby"}:${p.fieldId}`
1749
+ );
1750
+ if (!b)
1751
+ throw new Error(
1752
+ `Unable to resolve temporal export field "${p.fieldId}".`
1753
+ );
1754
+ return {
1755
+ scope: {
1756
+ dashboardId: e.dashboardId,
1757
+ cardId: e.card.id
1758
+ },
1759
+ target: { kind: "column", columnKey: p.columnKey },
1760
+ format: Ue(
1761
+ b,
1762
+ {
1763
+ dateStyle: e.reportContext.valueFormat.dateStyle,
1764
+ dateTime: { ...e.reportContext.valueFormat.dateTime }
1765
+ },
1766
+ e.reportContext.valueFormat.locale
1767
+ )
1768
+ };
1769
+ })
1770
+ ), g.push(
1771
+ ...((d == null ? void 0 : d.fields) || []).flatMap(
1772
+ (p) => p.role === "pivotby" ? [
1773
+ {
1774
+ scope: {
1775
+ dashboardId: e.dashboardId,
1776
+ cardId: e.card.id
1777
+ },
1778
+ target: {
1779
+ kind: "field",
1780
+ fieldId: p.id,
1781
+ role: p.role
1782
+ },
1783
+ format: Ue(
1784
+ p,
1785
+ {
1786
+ dateStyle: e.reportContext.valueFormat.dateStyle,
1787
+ dateTime: { ...e.reportContext.valueFormat.dateTime }
1788
+ },
1789
+ e.reportContext.valueFormat.locale
1790
+ )
1791
+ }
1792
+ ] : []
1793
+ )
1794
+ ), g.push(
1795
+ ...[...m].map(([p, b]) => ({
1796
+ scope: { dashboardId: e.dashboardId, cardId: e.card.id },
1797
+ target: { kind: "column", columnKey: p },
1798
+ format: b
1799
+ }))
1800
+ );
1801
+ const C = Vi({
1802
+ reportContext: e.reportContext,
1803
+ resolvedFormats: g
1804
+ });
1805
+ return {
1806
+ formatOptions: {
1807
+ ...e.formatOptions,
1808
+ ...o ? { tableTotalsLabelColumnKey: o } : {},
1809
+ comparisonPresentation: xr(e.card),
1810
+ presentationExecutionSnapshot: C
1811
+ },
1812
+ ...s ? { tableTotalsRequest: s } : {}
1813
+ };
1814
+ }
1815
+ function Mr(e) {
1816
+ const t = xi(
1817
+ e.card,
1818
+ e.requestPayloadBase
1819
+ ), { cardId: i, ...n } = t.requestPayloadBase, r = Sr(e);
1820
+ return {
1821
+ type: "card",
1822
+ dashboardId: e.dashboardId,
1823
+ cardId: e.card.id,
1824
+ title: e.title,
1825
+ connection_id: t.connectionId,
1826
+ ...n,
1827
+ ...r.tableTotalsRequest ? { tableTotalsRequest: r.tableTotalsRequest } : {},
1828
+ totalRows: e.totalRows,
1829
+ format: e.format,
1830
+ formatOptions: r.formatOptions
1831
+ };
1832
+ }
1833
+ function oo(e) {
1834
+ const { card: t, result: i } = e;
1835
+ if (t.type !== "table" && t.type !== "detailTable")
1836
+ return { status: "refused", reason: "not_a_table" };
1837
+ if (Ii({ card: t, comparisonMetadata: i.comparisonMetadata }))
1838
+ return { status: "refused", reason: "comparison_metadata_missing" };
1839
+ const n = Ir({
1840
+ card: t,
1841
+ effectiveCardConfig: e.effectiveCardConfig,
1842
+ rows: e.rows,
1843
+ resultKeys: i.resultColumns.map((r) => r.key),
1844
+ result: i,
1845
+ reportContext: e.reportContext,
1846
+ file: e.file
1847
+ });
1848
+ return n ? {
1849
+ status: "ready",
1850
+ request: Mr({
1851
+ card: t,
1852
+ dashboardId: e.dashboardId,
1853
+ title: e.title,
1854
+ reportContext: e.reportContext,
1855
+ totalRows: i.totalRows,
1856
+ format: e.file.format,
1857
+ formatOptions: n.formatOptions,
1858
+ comparisonMetadata: i.comparisonMetadata,
1859
+ requestPayloadBase: e.query,
1860
+ resultColumns: [...i.resultColumns],
1861
+ columnKeyMap: i.columnKeyMap,
1862
+ effectiveCardConfig: e.effectiveCardConfig
1863
+ })
1864
+ } : { status: "refused", reason: "columns_unresolved" };
1865
+ }
1866
+ function Dr(e, t, i) {
1867
+ if (wi(
1868
+ Pi(t),
1869
+ e.aggregateOrigin
1870
+ ))
1871
+ return { aggregate: void 0, aggregateOrigin: void 0 };
1872
+ const n = i === "selection" && e.role === "metric" ? t.aggregate : void 0;
1873
+ return {
1874
+ aggregate: e.aggregate ?? n,
1875
+ aggregateOrigin: e.aggregate ? e.aggregateOrigin : n ? t.aggregateOrigin : void 0
1876
+ };
1877
+ }
1878
+ function Tr(e, t, i) {
1879
+ var n, r, a, o, s, l;
1880
+ if (i === "domain")
1881
+ return {
1882
+ filters: (n = t.parameters) == null ? void 0 : n.filters,
1883
+ windowTransform: (r = e.parameters) == null ? void 0 : r.windowTransform
1884
+ };
1885
+ if (!(!e.parameters && !t.parameters))
1886
+ return {
1887
+ filters: ((a = e.parameters) == null ? void 0 : a.filters) ?? ((o = t.parameters) == null ? void 0 : o.filters),
1888
+ windowTransform: ((s = e.parameters) == null ? void 0 : s.windowTransform) ?? ((l = t.parameters) == null ? void 0 : l.windowTransform)
1889
+ };
1890
+ }
1891
+ function so(e, t, i) {
1892
+ const n = e;
1893
+ return {
1894
+ id: e.id,
1895
+ role: e.role,
1896
+ // Result-column names belong to the selection's consumer (for example,
1897
+ // range bounds). They do not identify or redefine the catalog calculation.
1898
+ ...i === "selection" && e.alias ? { alias: e.alias } : {},
1899
+ granularity: e.granularity ?? t.granularity,
1900
+ dateFormat: e.dateFormat,
1901
+ customFormat: e.customFormat,
1902
+ semanticTemporalPresentation: t.semanticTemporalPresentation || e.semanticTemporalPresentation,
1903
+ ...Dr(e, t, i),
1904
+ ...e.role === "metric" ? {
1905
+ aliasTemplate: n.aliasTemplate,
1906
+ valueAliases: n.valueAliases,
1907
+ comparison: n.comparison,
1908
+ comparisonPolarity: n.comparisonPolarity,
1909
+ parameters: Tr(
1910
+ n,
1911
+ t,
1912
+ "domain"
1913
+ )
1914
+ } : {},
1915
+ ...wr(e)
1916
+ };
1917
+ }
1918
+ function wr(e) {
1919
+ const t = {
1920
+ ...e.labelOrigin === "override" ? { label: e.label, labelOrigin: e.labelOrigin } : {},
1921
+ ...e.formatOrigin === "override" ? { format: e.format, formatOrigin: e.formatOrigin } : {}
1922
+ };
1923
+ switch (e.role) {
1924
+ case "pivotby":
1925
+ return {
1926
+ ...t,
1927
+ memberOrder: e.memberOrder
1928
+ };
1929
+ case "sortby":
1930
+ return {
1931
+ ...t,
1932
+ direction: e.direction
1933
+ };
1934
+ case "detail":
1935
+ return {
1936
+ ...t,
1937
+ ...e.dateFormat !== void 0 ? { dateFormat: e.dateFormat } : {},
1938
+ ...e.customFormat !== void 0 ? { customFormat: e.customFormat } : {}
1939
+ };
1940
+ default:
1941
+ return t;
1942
+ }
1943
+ }
1944
+ const Pr = "table";
1945
+ function lo({ preferences: e, ...t }) {
1946
+ return {
1947
+ ...t,
1948
+ type: Pr,
1949
+ preferences: e ?? { onClickFilter: [{ columnIndex: 0, expression: "" }] },
1950
+ sql: "",
1951
+ data: []
1952
+ };
1953
+ }
1954
+ function Or(e, t) {
1955
+ const i = e.sheets ?? [], n = i.findIndex((o) => o.id === t.sheetId), r = i[n];
1956
+ if (!r)
1957
+ throw new N("sheet_not_found", `No sheet ${t.sheetId} on this dashboard.`);
1958
+ if (Hi(r))
1959
+ throw new N(
1960
+ "sheet_not_a_grid",
1961
+ "This sheet is a document: it has no grid to arrange.",
1962
+ "Arrange a grid sheet; Document sheets are laid out in the editor."
1963
+ );
1964
+ const a = Ft(r, { kind: "arrange", keepOrder: t.keepOrder === !0 });
1965
+ return {
1966
+ dashboard: { ...e, sheets: i.map((o, s) => s === n ? a : o) },
1967
+ clauses: [we.arranged(r.title || "the dashboard", t.keepOrder === !0, !(r.frames ?? []).length)]
1968
+ };
1969
+ }
1970
+ function Ar(e) {
1971
+ return !!(e && Object.prototype.hasOwnProperty.call(e, "calculatedFields"));
1972
+ }
1973
+ function z(...e) {
1974
+ return Gi(e.flatMap((t) => t || []));
1975
+ }
1976
+ function G(e, t) {
1977
+ return {
1978
+ ...e,
1979
+ fieldScope: t
1980
+ };
1981
+ }
1982
+ function Be(e) {
1983
+ return ((e == null ? void 0 : e.calculatedFields) || []).filter((t) => t.fieldScope === "sheet").map((t) => G(t, "sheet"));
1984
+ }
1985
+ function jt(e) {
1986
+ return ((e == null ? void 0 : e.calculatedFields) || []).filter((t) => !t.fieldScope).map((t) => G(t, "sheet"));
1987
+ }
1988
+ function Nr(e) {
1989
+ return e ? [
1990
+ ...(e.calculatedFields || []).filter(
1991
+ (t) => t.fieldScope === "dashboard"
1992
+ ),
1993
+ ...(e.frames || []).flatMap((t) => t.calculatedFields || [])
1994
+ ].map((t) => G(t, "dashboard")) : [];
1995
+ }
1996
+ function Er(e) {
1997
+ if (e !== void 0)
1998
+ return z(
1999
+ e.map((t) => G(t, "dashboard"))
2000
+ );
2001
+ }
2002
+ function co(e) {
2003
+ var n;
2004
+ const t = [], i = (e.sheets || []).map((r) => {
2005
+ var a;
2006
+ return t.push(...Nr(r)), {
2007
+ ...r,
2008
+ calculatedFields: z(
2009
+ Be(r),
2010
+ jt(r)
2011
+ ),
2012
+ frames: (a = r.frames) == null ? void 0 : a.map(
2013
+ (o) => o.calculatedFields === void 0 ? o : { ...o, calculatedFields: void 0 }
2014
+ )
2015
+ };
2016
+ });
2017
+ return {
2018
+ ...e,
2019
+ calculatedFields: Er(
2020
+ z(
2021
+ (n = e.calculatedFields) == null ? void 0 : n.map(
2022
+ (r) => G(r, "dashboard")
2023
+ ),
2024
+ t
2025
+ )
2026
+ ),
2027
+ sheets: i
2028
+ };
2029
+ }
2030
+ function at(e, t) {
2031
+ var r;
2032
+ if (!((r = e == null ? void 0 : e.frames) != null && r.length))
2033
+ return [];
2034
+ const i = t ? e.frames.find((a) => a.id === t) : void 0, n = e.frames.filter(
2035
+ (a) => !t || a.id !== t
2036
+ );
2037
+ return z(
2038
+ i == null ? void 0 : i.calculatedFields,
2039
+ ...n.map((a) => a.calculatedFields)
2040
+ );
2041
+ }
2042
+ function uo(e, t) {
2043
+ return e ? Be(e) : [];
2044
+ }
2045
+ function fo(e, t) {
2046
+ if (!e)
2047
+ return [];
2048
+ const i = Be(e), n = jt(e), r = z(
2049
+ i,
2050
+ n
2051
+ );
2052
+ return Ar(e) ? r.length === 0 ? [] : n.length === 0 ? r : z(
2053
+ r,
2054
+ at(e, t)
2055
+ ) : at(e, t);
2056
+ }
2057
+ function Vr(e) {
2058
+ if (e !== void 0)
2059
+ return z(
2060
+ e.map((t) => G(t, "sheet"))
2061
+ );
2062
+ }
2063
+ function mo(e) {
2064
+ const { field: t, sheetFields: i = [], dashboardFields: n = [] } = e, r = (s) => s.find(
2065
+ (l) => Wi(l, t, {
2066
+ allowComparableFallback: !0
2067
+ })
2068
+ );
2069
+ if (t.fieldScope === "sheet")
2070
+ return { scope: "sheet", matchedField: r(i) };
2071
+ if (t.fieldScope === "dashboard")
2072
+ return { scope: "dashboard", matchedField: r(n) };
2073
+ const a = r(i);
2074
+ if (a)
2075
+ return { scope: "sheet", matchedField: a };
2076
+ const o = r(n);
2077
+ return o ? { scope: "dashboard", matchedField: o } : { scope: "card" };
2078
+ }
2079
+ function _r(e, t) {
2080
+ var C, D, w;
2081
+ const i = (e.sheets ?? []).findIndex((F) => F.id === t.sheetId), n = (C = e.sheets) == null ? void 0 : C[i];
2082
+ if (!(n != null && n.frames))
2083
+ throw new N("sheet_not_found", `No sheet ${t.sheetId} with frames on this dashboard.`);
2084
+ const { frame: r } = t, a = n.frames.findIndex((F) => F.id === r.id);
2085
+ if (a === -1)
2086
+ throw new N("frame_not_found", `No frame ${r.id} on sheet ${t.sheetId}.`);
2087
+ const o = n.frames[a], s = He(n), l = (F) => F.calculatedFields === void 0 ? F : { ...F, calculatedFields: void 0 }, c = t.rewrittenFrames, u = c && c.length > 0 ? (() => {
2088
+ const F = c.map((S) => S.id === r.id ? r : S);
2089
+ return F.some((S) => S.id === r.id) ? F : [r, ...F];
2090
+ })() : [r], f = new Map(u.map((F) => [F.id, F])), d = Ft(n, { kind: "frame_updated", frame: r, resizeForNewKind: t.resizeLayouts });
2091
+ let y = /* @__PURE__ */ new Set();
2092
+ const v = Qi.produce(e, (F) => {
2093
+ const S = F.sheets[i];
2094
+ d.layouts !== n.layouts && (S.layouts = Ge(d.layouts)), d.customizedBreakpoints !== n.customizedBreakpoints && (S.customizedBreakpoints = d.customizedBreakpoints), t.sheetCalculatedFields !== void 0 && (S.calculatedFields = Vr(t.sheetCalculatedFields)), S.frames = S.frames.map((p) => {
2095
+ const b = f.get(p.id);
2096
+ return b ? Ge(l(b)) : p.calculatedFields === void 0 ? p : { ...p, calculatedFields: void 0 };
2097
+ });
2098
+ const V = He(S);
2099
+ y = new Set([...s].filter((p) => !V.has(p))), Ji(F, y), t.dashboardCalculatedFields && (F.calculatedFields = t.dashboardCalculatedFields);
2100
+ }), h = v.sheets[i].frames.find((F) => F.id === r.id), m = [
2101
+ ...y.size ? [{ kind: "cards_removed", cardIds: [...y] }] : [],
2102
+ { kind: "frame_committed", sheetId: t.sheetId, before: o, after: h }
2103
+ ], g = ((D = r.cards) == null ? void 0 : D.find((F) => F.id === r.activeCardId)) ?? ((w = r.cards) == null ? void 0 : w[0]);
2104
+ return { dashboard: v, runtimeEffects: m, clauses: [we.committed(g == null ? void 0 : g.title)] };
2105
+ }
2106
+ function Rr(e, t, i) {
2107
+ var a;
2108
+ if (!e || !t || t.customFilterPreferences) return;
2109
+ const n = t.defaultDateFilter;
2110
+ return (t.dateSelectionMode === "day" ? Zi(n) : t.dateSelectionMode === "months" && (en(n) || tn(n) && n.unit === "month" && (n.mode === "previous" || n.mode === "this" && !n.toDate && !n.boundary))) && ((a = U(t, i)) == null ? void 0 : a.valueType) === "date" ? !0 : void 0;
2111
+ }
2112
+ function po(e) {
2113
+ const t = e.createId ?? St, i = t(), n = Si({
2114
+ field: e.field,
2115
+ dataSource: e.dataSource,
2116
+ connectionId: e.connectionId,
2117
+ connectionType: e.connectionType,
2118
+ filterId: t()
2119
+ });
2120
+ return Br({
2121
+ filter: e.label ? { ...n, title: e.label } : n,
2122
+ label: e.label || e.field.label || e.field.name,
2123
+ scope: e.scope,
2124
+ existingInputs: e.existingInputs,
2125
+ createId: () => i
2126
+ });
2127
+ }
2128
+ function Br(e) {
2129
+ const t = e.createId ?? St, i = e.label || e.filter.title || e.filter.column || e.filter.id, n = Yi(i, [
2130
+ ...e.existingInputs
2131
+ ]), r = {
2132
+ ...Ct(e.filter),
2133
+ variableName: n
2134
+ };
2135
+ return {
2136
+ id: t(),
2137
+ kind: "filter",
2138
+ label: i,
2139
+ variableName: n,
2140
+ requiredAtExecution: !1,
2141
+ scope: e.scope,
2142
+ runtimeScope: "shared",
2143
+ presentation: xt(r),
2144
+ filter: r,
2145
+ exports: It(r)
2146
+ };
2147
+ }
2148
+ function Kr(e, t, i, n = { calendar: null }) {
2149
+ var J, Y, X, Z, ee, Le, qe, ze;
2150
+ const r = q(e), a = r.findFilterInput(t), o = (M, x) => ({
2151
+ ok: !1,
2152
+ issues: [
2153
+ {
2154
+ code: "invalidSettings",
2155
+ message: M,
2156
+ ref: t,
2157
+ ...a ? { inputId: a.input.id } : {},
2158
+ ...x ? { contractIssue: x } : {}
2159
+ }
2160
+ ]
2161
+ });
2162
+ if (!a)
2163
+ return {
2164
+ ok: !1,
2165
+ issues: [
2166
+ {
2167
+ code: "inputNotFound",
2168
+ ref: t,
2169
+ message: "This filter no longer exists on the dashboard."
2170
+ }
2171
+ ]
2172
+ };
2173
+ if (a.origin !== "embeddedInput")
2174
+ return o("This filter can not be edited here.");
2175
+ const s = a.input, l = s.filter;
2176
+ if (((J = i.mapping) == null ? void 0 : J.kind) === "save") {
2177
+ if (!i.mapping.draft.acceptance.ok)
2178
+ return { ok: !1, issues: i.mapping.draft.acceptance.issues };
2179
+ if (i.mapping.draft.inputId !== s.id)
2180
+ return o("The card mapping was prepared for another filter.");
2181
+ }
2182
+ const c = i.definition ? Ct(i.definition) : l;
2183
+ if (c.kind === "global-date" && i.scope && !kr(i.scope))
2184
+ return o("The Global Date filter applies to regular tabs only.");
2185
+ const u = (Y = n.calendar) == null ? void 0 : Y.tz, f = i.definition !== void 0, d = i.forceSelection !== void 0 || f ? Rr(
2186
+ i.forceSelection ?? s.forceSelection,
2187
+ c,
2188
+ u
2189
+ ) : s.forceSelection ? !0 : void 0, y = (Array.isArray(e.inputs) ? e.inputs : []).filter((M) => M.id !== s.id), v = i.variableName !== void 0 ? Xi(i.variableName, [
2190
+ ...y,
2191
+ ...r.inputs.filter((M) => M.input.id !== s.id).map((M) => M.input)
2192
+ ]) : s.variableName, h = f && (l.title || l.column) !== (c.title || c.column), m = i.label ?? (h ? c.title || c.column || c.id : void 0), g = f && l.hide !== c.hide, C = f && l.toolbarWidth !== c.toolbarWidth, D = (M) => {
2193
+ var $e, je;
2194
+ const x = { ...M };
2195
+ if (m !== void 0 && (x.label = m), i.variableName !== void 0 && (x.variableName = v), i.scope && (x.scope = i.scope), g || C) {
2196
+ const ge = xt(c);
2197
+ x.presentation = { ...M.presentation }, g && (x.presentation.placement = ge.placement), C && (ge.widthPx === void 0 ? delete x.presentation.widthPx : x.presentation.widthPx = ge.widthPx);
2198
+ }
2199
+ return (i.forceSelection !== void 0 || f) && (d ? x.forceSelection = d : delete x.forceSelection), i.requiredAtExecution !== void 0 && (i.requiredAtExecution ? x.requiredAtExecution = !0 : delete x.requiredAtExecution), Fe(x, "optionSource", i.optionSource), Fe(x, "optionDependencies", i.optionDependencies), Fe(x, "optionPopulation", i.optionPopulation), (($e = i.mapping) == null ? void 0 : $e.kind) === "save" && i.mapping.draft.acceptance.ok ? x.application = i.mapping.draft.acceptance.application : ((je = i.mapping) == null ? void 0 : je.kind) === "remove" && delete x.application, x;
2200
+ }, w = i.label !== void 0 && i.label !== s.label && i.label !== c.title ? i.label : void 0, F = f || i.variableName !== void 0 || w !== void 0, S = (M) => ({
2201
+ ...M,
2202
+ ...i.variableName !== void 0 ? { variableName: v } : {},
2203
+ ...w !== void 0 ? { title: w } : {}
2204
+ }), V = Array.isArray(e.inputs) ? [...e.inputs] : [], p = V.findIndex((M) => M.id === s.id), b = V[p];
2205
+ if (p < 0 || (b == null ? void 0 : b.kind) !== "filter" || !b.filter)
2206
+ return o("This filter can not be edited here.");
2207
+ const I = D(
2208
+ F ? {
2209
+ ...b,
2210
+ filter: S(c)
2211
+ } : b
2212
+ );
2213
+ f && (I.exports = It(c)), V[p] = I;
2214
+ const _ = Ae({
2215
+ inputs: [I],
2216
+ dashboardFilters: []
2217
+ });
2218
+ if (!_.ok)
2219
+ return o(
2220
+ ((X = _.issues[0]) == null ? void 0 : X.message) ?? "These settings could not be saved.",
2221
+ _.issues[0]
2222
+ );
2223
+ let O = { ...e, inputs: V };
2224
+ const W = q(O), R = W.findFilterInput({ filterId: c.id });
2225
+ if (!R)
2226
+ return o(
2227
+ ((Z = W.issues[0]) == null ? void 0 : Z.message) ?? "These settings could not be saved."
2228
+ );
2229
+ const j = i.variableName !== void 0 || i.scope !== void 0 ? Lr(O, R.input) : void 0;
2230
+ if (j)
2231
+ return o(
2232
+ `Another filter on the same cards is already named "${j}". Choose another name.`
2233
+ );
2234
+ const K = [], T = {
2235
+ id: R.input.id,
2236
+ runtimeScope: R.input.runtimeScope
2237
+ };
2238
+ let A = {
2239
+ defaultInputValues: O.defaultInputValues,
2240
+ dashboardInputValues: {}
2241
+ };
2242
+ const Q = ((ee = i.values) == null ? void 0 : ee.target) ?? {}, P = $r(
2243
+ l,
2244
+ c,
2245
+ {
2246
+ defaultValueChanged: (Le = i.values) == null ? void 0 : Le.defaultChanged,
2247
+ selectionIdentityChanged: (qe = i.values) == null ? void 0 : qe.selectionIdentityChanged,
2248
+ ...((ze = i.values) == null ? void 0 : ze.defaultComparisonSelection) !== void 0 ? {
2249
+ defaultComparisonChanged: !0,
2250
+ defaultComparisonSelection: i.values.defaultComparisonSelection ?? void 0
2251
+ } : {}
2252
+ },
2253
+ Q,
2254
+ n.calendar ?? void 0
2255
+ );
2256
+ if (P.defaultValueChanged || P.selectionIdentityChanged || P.defaultComparisonChanged) {
2257
+ const M = Ut({
2258
+ state: { ...A, dashboardInputValues: {} },
2259
+ input: T,
2260
+ settings: P
2261
+ });
2262
+ A = { ...A, defaultInputValues: M.defaultInputValues }, P.selectionIdentityChanged && K.push({
2263
+ kind: "clear",
2264
+ inputId: T.id,
2265
+ target: P.target
2266
+ }), P.defaultValueChanged && K.push({
2267
+ kind: "resetToDefault",
2268
+ inputId: T.id,
2269
+ target: P.target,
2270
+ ...P.defaultFilterValue ? { filterValue: P.defaultFilterValue } : {}
2271
+ }), P.defaultComparisonChanged && K.push({
2272
+ kind: "setDefaultComparison",
2273
+ inputId: T.id,
2274
+ target: P.target
2275
+ });
2276
+ }
2277
+ if (i.scope && R.input.runtimeScope !== "shared") {
2278
+ const M = qr(
2279
+ O,
2280
+ s,
2281
+ R.input,
2282
+ A.defaultInputValues
2283
+ );
2284
+ A = {
2285
+ ...A,
2286
+ defaultInputValues: M.defaultInputValues
2287
+ }, K.push(
2288
+ ...M.dropped.map((x) => ({
2289
+ kind: "dropTargetSlot",
2290
+ inputId: T.id,
2291
+ target: x
2292
+ }))
2293
+ );
2294
+ }
2295
+ return O = zr(O, A), {
2296
+ ok: !0,
2297
+ dashboard: O,
2298
+ inputId: R.input.id,
2299
+ valueEffects: K
2300
+ };
2301
+ }
2302
+ function yo(e) {
2303
+ let t = We({
2304
+ dashboard: e.before,
2305
+ runtimeValues: e.dashboardInputValues,
2306
+ calendar: e.calendar
2307
+ });
2308
+ const i = q(e.after), n = (r) => {
2309
+ var a;
2310
+ return (a = i.findFilterInput({ inputId: r })) == null ? void 0 : a.input;
2311
+ };
2312
+ for (const r of e.effects)
2313
+ switch (r.kind) {
2314
+ case "resetToDefault":
2315
+ case "clear":
2316
+ case "setDefaultComparison": {
2317
+ const a = n(r.inputId);
2318
+ if (!a) break;
2319
+ t = Ut({
2320
+ state: { dashboardInputValues: t },
2321
+ input: a,
2322
+ settings: {
2323
+ target: r.target,
2324
+ defaultValueChanged: r.kind === "resetToDefault",
2325
+ defaultFilterValue: r.kind === "resetToDefault" ? r.filterValue : void 0,
2326
+ selectionIdentityChanged: r.kind === "clear",
2327
+ defaultComparisonChanged: r.kind === "setDefaultComparison"
2328
+ }
2329
+ }).dashboardInputValues;
2330
+ break;
2331
+ }
2332
+ case "dropTargetSlot": {
2333
+ const a = n(r.inputId);
2334
+ if (!a) break;
2335
+ t = Pe(
2336
+ t,
2337
+ a,
2338
+ r.target
2339
+ );
2340
+ break;
2341
+ }
2342
+ }
2343
+ return We({
2344
+ dashboard: e.after,
2345
+ runtimeValues: t,
2346
+ calendar: e.calendar
2347
+ });
2348
+ }
2349
+ function kr(e) {
2350
+ var t;
2351
+ return e.kind !== "documentSections" && (e.kind !== "allSheets" || ((t = e.sheetKinds) == null ? void 0 : t.length) === 1 && e.sheetKinds[0] === "dashboard");
2352
+ }
2353
+ function Fe(e, t, i) {
2354
+ i !== void 0 && (i === null ? delete e[t] : e[t] = i);
2355
+ }
2356
+ function Lr(e, t) {
2357
+ const i = [
2358
+ ...q(e).inputs.map((r) => r.input),
2359
+ ...(Array.isArray(e.inputs) ? e.inputs : []).filter(
2360
+ (r) => r.kind === "control"
2361
+ )
2362
+ ].filter(
2363
+ (r) => r.id !== t.id && r.variableName === t.variableName
2364
+ );
2365
+ if (!i.length) return;
2366
+ const n = Xe(e, t);
2367
+ return i.some(
2368
+ (r) => [...Xe(e, r)].some(
2369
+ (a) => n.has(a)
2370
+ )
2371
+ ) ? t.variableName : void 0;
2372
+ }
2373
+ function qr(e, t, i, n) {
2374
+ var u, f;
2375
+ const r = [], a = Mt(e), o = (d) => ot(t, d, a), s = (d) => ot(i, d, a), l = [];
2376
+ if (i.runtimeScope === "perSheet")
2377
+ for (const d of a.values())
2378
+ l.push({ sheetId: d.sheetId, sheetKind: d.sheetKind });
2379
+ else if (i.runtimeScope === "perCard")
2380
+ for (const d of fe(e))
2381
+ l.push({
2382
+ sheetId: d.sheetId,
2383
+ cardId: d.cardId,
2384
+ sheetKind: (u = a.get(d.sheetId)) == null ? void 0 : u.sheetKind
2385
+ });
2386
+ else if (i.runtimeScope === "perDocumentSection")
2387
+ for (const d of e.sheets ?? [])
2388
+ for (const y of ((f = d.document) == null ? void 0 : f.sections) ?? [])
2389
+ l.push({
2390
+ sheetId: d.id,
2391
+ sectionId: y.id,
2392
+ sheetKind: "document"
2393
+ });
2394
+ let c = n;
2395
+ for (const d of l) {
2396
+ if (s(d)) continue;
2397
+ const y = !!(c && Oe(c, i, d));
2398
+ if (y && (c = Pe(c, i, d)), y || o(d)) {
2399
+ const { sheetKind: v, ...h } = d;
2400
+ r.push(h);
2401
+ }
2402
+ }
2403
+ return { defaultInputValues: c, dropped: r };
2404
+ }
2405
+ function ot(e, t, i) {
2406
+ if (e.runtimeScope === "perSheet" && t.sheetId && !t.cardId && !t.sectionId) {
2407
+ const n = i.get(t.sheetId);
2408
+ return n ? Dt(e, n) : !1;
2409
+ }
2410
+ return rn(e, t);
2411
+ }
2412
+ function zr(e, t) {
2413
+ const i = { ...e };
2414
+ return t.defaultInputValues && Object.keys(t.defaultInputValues).length ? i.defaultInputValues = t.defaultInputValues : e.defaultInputValues !== void 0 && delete i.defaultInputValues, i;
2415
+ }
2416
+ function $r(e, t, i, n, r) {
2417
+ const a = !!(i != null && i.defaultValueChanged || i != null && i.selectionIdentityChanged) || nn(e, t);
2418
+ return {
2419
+ ...i,
2420
+ target: (i == null ? void 0 : i.target) ?? n,
2421
+ defaultValueChanged: a,
2422
+ defaultFilterValue: a ? U(t, r) : void 0
2423
+ };
2424
+ }
2425
+ function Ut(e) {
2426
+ const { settings: t } = e;
2427
+ if (!t) return e.state;
2428
+ const i = e.input;
2429
+ let n = e.state.dashboardInputValues, r = e.state.defaultInputValues;
2430
+ if (t.selectionIdentityChanged && (n = Qe(
2431
+ n,
2432
+ i,
2433
+ t.target,
2434
+ { status: "cleared" }
2435
+ )), t.defaultValueChanged) {
2436
+ const a = Oe(
2437
+ r,
2438
+ i,
2439
+ t.target
2440
+ );
2441
+ let o = Pe(
2442
+ r || {},
2443
+ i,
2444
+ t.target
2445
+ );
2446
+ t.defaultFilterValue ? o = Je(
2447
+ o,
2448
+ i,
2449
+ t.target,
2450
+ {
2451
+ status: "set",
2452
+ value: {
2453
+ kind: "filter",
2454
+ filterValue: t.defaultFilterValue
2455
+ },
2456
+ ...a != null && a.comparisonSelection ? { comparisonSelection: a.comparisonSelection } : {}
2457
+ }
2458
+ ) : a != null && a.comparisonSelection && (o = Je(
2459
+ o,
2460
+ i,
2461
+ t.target,
2462
+ { comparisonSelection: a.comparisonSelection }
2463
+ )), r = Object.keys(o).length ? o : void 0, n = Qe(
2464
+ n,
2465
+ i,
2466
+ t.target,
2467
+ t.defaultFilterValue ? {
2468
+ status: "set",
2469
+ value: {
2470
+ kind: "filter",
2471
+ filterValue: t.defaultFilterValue
2472
+ }
2473
+ } : { status: "cleared" }
2474
+ );
2475
+ }
2476
+ return t.defaultComparisonChanged && (r = Ye(
2477
+ r || {},
2478
+ i,
2479
+ t.target,
2480
+ t.defaultComparisonSelection
2481
+ ), Object.keys(r).length || (r = void 0), n = Ye(
2482
+ n,
2483
+ i,
2484
+ t.target,
2485
+ void 0
2486
+ )), {
2487
+ ...e.state,
2488
+ dashboardInputValues: n,
2489
+ defaultInputValues: r
2490
+ };
2491
+ }
2492
+ const $ = (e) => Array.isArray(e.inputs) ? e.inputs : [];
2493
+ function ye(e, t) {
2494
+ const i = $(e).find((n) => n.id === t);
2495
+ if (!i || i.kind !== "filter")
2496
+ throw new N("filter_not_found", `No filter ${t} on this dashboard.`, "Read the outline again and use its filter ids.");
2497
+ return i;
2498
+ }
2499
+ function Ht(e, t) {
2500
+ var i;
2501
+ return (i = fe(e).find((n) => n.cardId === t)) == null ? void 0 : i.card.title;
2502
+ }
2503
+ function jr(e, t) {
2504
+ const i = q(e), n = i.findFilterInput({ inputId: t });
2505
+ return n ? i.reachedCards({ inputId: t }).filter((r) => ["bound", "automatic", "sql"].includes(Mi(n.input, r.card))).length : 0;
2506
+ }
2507
+ function Gt(e, t) {
2508
+ if (t.scope.kind === "allSheets") return "every sheet";
2509
+ if (t.scope.kind !== "sheets") return "its cards";
2510
+ const i = [...Mt(e).values()].filter((n) => Dt(t, n));
2511
+ return Tt(i.map((n) => {
2512
+ var r, a;
2513
+ return ((a = (r = e.sheets) == null ? void 0 : r.find((o) => o.id === n.sheetId)) == null ? void 0 : a.title) ?? n.sheetId;
2514
+ }));
2515
+ }
2516
+ const Wt = (e) => {
2517
+ var t;
2518
+ return ((t = e.filter) == null ? void 0 : t.type) === "single" ? "single select" : "multi select";
2519
+ };
2520
+ function Qt(e) {
2521
+ var t, i, n;
2522
+ if ((i = (t = e.filter) == null ? void 0 : t.defaultValues) != null && i.length) return `default ${e.filter.defaultValues.join(", ")}`;
2523
+ if ((n = e.filter) != null && n.defaultDateFilter) return "a default period";
2524
+ }
2525
+ function oe(e) {
2526
+ return we.plain("filter", e);
2527
+ }
2528
+ function Ur(e, t) {
2529
+ const { input: i } = t, n = $(e);
2530
+ if (n.some((s) => s.id === i.id))
2531
+ throw new N("filter_id_taken", `A filter with id ${i.id} is already on this dashboard.`);
2532
+ if (q(e).findFilterInput({ filterId: i.filter.id }))
2533
+ throw new N("filter_id_taken", `A filter definition with id ${i.filter.id} is already on this dashboard.`);
2534
+ const r = { ...e, inputs: [...n, i] }, a = jr(r, i.id), o = [Wt(i), Qt(i)].filter(Boolean).join(", ");
2535
+ return {
2536
+ dashboard: r,
2537
+ created: [
2538
+ {
2539
+ kind: "filter",
2540
+ id: i.id,
2541
+ title: i.label,
2542
+ ...t.changeIndex !== void 0 ? { changeIndex: t.changeIndex } : {}
2543
+ }
2544
+ ],
2545
+ clauses: [
2546
+ oe(
2547
+ `adds the filter ${L(i.label)} (${o}) to ${Gt(r, i)}; it filters ${a} card${a === 1 ? "" : "s"}`
2548
+ )
2549
+ ]
2550
+ };
2551
+ }
2552
+ function Hr(e, t, i) {
2553
+ const n = Kr(e, { inputId: t.filterId }, t.settings, {
2554
+ calendar: i.calendar
2555
+ });
2556
+ if (!n.ok) {
2557
+ const [o] = n.issues;
2558
+ throw new N(
2559
+ (o == null ? void 0 : o.code) === "inputNotFound" ? "filter_not_found" : "filter_invalid",
2560
+ (o == null ? void 0 : o.message) ?? "These filter settings could not be saved.",
2561
+ (o == null ? void 0 : o.code) === "inputNotFound" ? "Read the outline again and use its filter ids." : "Change the filter settings and propose again.",
2562
+ { issues: n.issues }
2563
+ );
2564
+ }
2565
+ const r = $(e).find((o) => o.id === n.inputId), a = $(n.dashboard).find((o) => o.id === n.inputId);
2566
+ return {
2567
+ dashboard: n.dashboard,
2568
+ runtimeEffects: [{ kind: "filter_value", effects: n.valueEffects }],
2569
+ clauses: [oe(`changes the filter ${L((r == null ? void 0 : r.label) ?? a.label)}: ${Gr(n.dashboard, r, a)}`)]
2570
+ };
2571
+ }
2572
+ function Gr(e, t, i) {
2573
+ var o, s, l, c, u, f;
2574
+ if (!t) return "updates its settings";
2575
+ const n = [];
2576
+ t.label !== i.label && n.push(`renames it ${L(i.label)}`), (((o = t.filter) == null ? void 0 : o.type) ?? "multiple") !== (((s = i.filter) == null ? void 0 : s.type) ?? "multiple") && n.push(`makes it ${Wt(i)}`);
2577
+ const r = JSON.stringify([((l = t.filter) == null ? void 0 : l.defaultValues) ?? null, ((c = t.filter) == null ? void 0 : c.defaultDateFilter) ?? null]), a = JSON.stringify([((u = i.filter) == null ? void 0 : u.defaultValues) ?? null, ((f = i.filter) == null ? void 0 : f.defaultDateFilter) ?? null]);
2578
+ if (r !== a) {
2579
+ const d = Qt(i);
2580
+ n.push(d ? `sets its ${d.replace(/^default /, "default to ").replace(/^a default period$/, "default period")}` : "removes its default");
2581
+ }
2582
+ return JSON.stringify(t.scope) !== JSON.stringify(i.scope) && n.push(`applies it to ${Gt(e, i)}`), n.length ? Tt(n) : "keeps its settings";
2583
+ }
2584
+ function Wr(e, t) {
2585
+ const i = ye(e, t);
2586
+ return {
2587
+ dashboard: {
2588
+ ...e,
2589
+ inputs: $(e).filter((r) => r.id !== t),
2590
+ defaultInputValues: on(e.defaultInputValues, t)
2591
+ },
2592
+ runtimeEffects: [{ kind: "input_removed", inputId: t }],
2593
+ clauses: [oe(`removes the filter ${L(i.label)}`)]
2594
+ };
2595
+ }
2596
+ function Qr(e, t, i) {
2597
+ var o;
2598
+ if (!fe(e).some((s) => s.cardId === i))
2599
+ throw new N("card_not_found", `No card ${i} on this dashboard.`, "Read the outline again and use its card ids.");
2600
+ const n = sn(t.scope, i);
2601
+ if (!n)
2602
+ throw new N(
2603
+ "filter_invalid",
2604
+ "This filter applies to Document sections, so it can't leave out one card.",
2605
+ "Change it in the editor."
2606
+ );
2607
+ const r = { ...t, scope: n }, a = Ae({ inputs: [r], dashboardFilters: [] });
2608
+ if (!a.ok)
2609
+ throw new N("filter_invalid", ((o = a.issues[0]) == null ? void 0 : o.message) ?? "This filter could not be saved.", "Change it in the editor.");
2610
+ return {
2611
+ ...e,
2612
+ inputs: $(e).map((s) => s.id === t.id ? r : s)
2613
+ };
2614
+ }
2615
+ function Jt(e, t, i, n, r) {
2616
+ var u, f;
2617
+ const a = ye(e, t);
2618
+ if (!fe(e).some((d) => d.cardId === i))
2619
+ throw new N("card_not_found", `No card ${i} on this dashboard.`, "Read the outline again and use its card ids.");
2620
+ const o = [...((u = a.application) == null ? void 0 : u.cards) ?? []], s = o.findIndex((d) => d.cardId === i);
2621
+ s >= 0 ? o[s] = n : o.push(n);
2622
+ const l = {
2623
+ ...a,
2624
+ ...r ? { scope: r } : {},
2625
+ application: { ...a.application ?? { kind: "cardMappings" }, cards: o }
2626
+ }, c = Ae({ inputs: [l], dashboardFilters: [] });
2627
+ if (!c.ok)
2628
+ throw new N(
2629
+ "filter_invalid",
2630
+ ((f = c.issues[0]) == null ? void 0 : f.message) ?? "This filter mapping could not be saved.",
2631
+ "Change the mapping and propose again."
2632
+ );
2633
+ return {
2634
+ ...e,
2635
+ inputs: $(e).map((d) => d.id === t ? l : d)
2636
+ };
2637
+ }
2638
+ function Jr(e, t) {
2639
+ const i = ye(e, t.filterId), n = { ...t.binding, kind: "bound", cardId: t.cardId }, r = an(i.scope, t.cardId), a = r !== i.scope;
2640
+ return {
2641
+ dashboard: Jt(e, t.filterId, t.cardId, n, a ? r : void 0),
2642
+ clauses: [
2643
+ oe(
2644
+ `makes ${L(i.label)} filter ${L(Ht(e, t.cardId))} by ${n.target.field.name}${a ? ", which it used to leave out" : ""}`
2645
+ )
2646
+ ]
2647
+ };
2648
+ }
2649
+ function Yr(e, t) {
2650
+ var r;
2651
+ const i = ye(e, t.filterId);
2652
+ return {
2653
+ dashboard: ((r = i.filter) == null ? void 0 : r.kind) === "global-date" ? Qr(e, i, t.cardId) : Jt(e, t.filterId, t.cardId, { kind: "excluded", cardId: t.cardId }),
2654
+ clauses: [oe(`stops ${L(i.label)} from filtering ${L(Ht(e, t.cardId))}`)]
2655
+ };
2656
+ }
2657
+ function go(e, t, i) {
2658
+ let n = e;
2659
+ const r = [], a = [], o = [];
2660
+ for (const [s, l] of t.entries()) {
2661
+ let c;
2662
+ try {
2663
+ c = Xr(n, l, i);
2664
+ } catch (u) {
2665
+ if (!(u instanceof N)) throw u;
2666
+ return {
2667
+ ok: !1,
2668
+ failedAt: {
2669
+ index: s,
2670
+ op: l.op,
2671
+ code: u.code,
2672
+ message: u.message,
2673
+ ...u.fix ? { fix: u.fix } : {},
2674
+ ...u.details ? { details: u.details } : {}
2675
+ }
2676
+ };
2677
+ }
2678
+ n = c.dashboard, r.push(...c.created ?? []), a.push(...c.runtimeEffects ?? []), o.push({ index: s, changeIndex: l.changeIndex, clauses: c.clauses });
2679
+ }
2680
+ return { ok: !0, dashboard: n, created: r, descriptions: Zr(o), runtimeEffects: a };
2681
+ }
2682
+ function Xr(e, t, i) {
2683
+ switch (t.op) {
2684
+ case "card.add":
2685
+ return un(e, t);
2686
+ case "card.remove":
2687
+ return cn(e, t.cardId);
2688
+ case "card.update":
2689
+ return ln(e, t.cardId, t.update);
2690
+ case "layout.arrange":
2691
+ return Or(e, t);
2692
+ case "frame.commit":
2693
+ return _r(e, t.commit);
2694
+ case "filter.add":
2695
+ return Ur(e, t);
2696
+ case "filter.update":
2697
+ return Hr(e, t, i);
2698
+ case "filter.remove":
2699
+ return Wr(e, t.filterId);
2700
+ case "filter.bind":
2701
+ return Jr(e, t);
2702
+ case "filter.exclude":
2703
+ return Yr(e, t);
2704
+ }
2705
+ }
2706
+ function Zr(e) {
2707
+ const t = [];
2708
+ for (const i of e) {
2709
+ const n = i.changeIndex === void 0 ? void 0 : t.find((r) => r.changeIndex === i.changeIndex);
2710
+ if (n) {
2711
+ n.operations.push(i.index), n.clauses.push(...i.clauses);
2712
+ continue;
2713
+ }
2714
+ t.push({
2715
+ ...i.changeIndex !== void 0 ? { changeIndex: i.changeIndex } : {},
2716
+ operations: [i.index],
2717
+ sentence: "",
2718
+ clauses: [...i.clauses]
2719
+ });
2720
+ }
2721
+ return t.map(({ clauses: i, ...n }) => ({
2722
+ ...n,
2723
+ sentence: dn(ea(i))
2724
+ }));
2725
+ }
2726
+ function ea(e) {
2727
+ let t = !1;
2728
+ return e.filter((i) => i.kind !== "detached" ? !0 : t ? !1 : (t = !0, !0));
2729
+ }
2730
+ function st(e) {
2731
+ return Object.fromEntries(
2732
+ Object.entries(e).filter(
2733
+ (t) => typeof t[1] == "string" && t[1].length > 0
2734
+ )
2735
+ );
2736
+ }
2737
+ function ne(e) {
2738
+ return e.kind === "semantic" ? [
2739
+ e.kind,
2740
+ e.domainId,
2741
+ e.datasetId || "",
2742
+ e.datasetName || "",
2743
+ e.connectionId || ""
2744
+ ].join(":") : [
2745
+ e.kind,
2746
+ e.connectionId,
2747
+ e.databaseName || "",
2748
+ e.schemaName || "",
2749
+ e.tableName
2750
+ ].join(":");
2751
+ }
2752
+ function ta(e, t) {
2753
+ if (e.kind === "semantic")
2754
+ return {
2755
+ status: "ready",
2756
+ request: st({
2757
+ connection_id: e.connectionId,
2758
+ domain_id: e.domainId,
2759
+ dataset_id: Oi(e),
2760
+ dataset_name: e.datasetName
2761
+ })
2762
+ };
2763
+ const i = Sn({
2764
+ source: e,
2765
+ capabilities: t
2766
+ });
2767
+ return i.kind === "incompatible_capabilities" ? {
2768
+ status: "unavailable",
2769
+ message: "Connection capabilities are unavailable for field metadata."
2770
+ } : i.kind === "missing_coordinates" ? {
2771
+ status: "unavailable",
2772
+ message: `Source is missing required field-metadata coordinates: ${i.missing.join(", ")}.`
2773
+ } : {
2774
+ status: "ready",
2775
+ request: st({
2776
+ connection_id: e.connectionId,
2777
+ datamodel_id: "",
2778
+ database_name: i.coordinates.databaseName,
2779
+ schema_name: i.coordinates.schemaName,
2780
+ table_name: i.coordinates.tableName
2781
+ })
2782
+ };
2783
+ }
2784
+ function bo(e, t = /* @__PURE__ */ new Map()) {
2785
+ const i = /* @__PURE__ */ new Map();
2786
+ for (const { card: n } of e) {
2787
+ const r = wt(n), a = r.kind === "config" ? r.executableSources : r.kind === "sql" ? r.pinnedCatalogSources.map((o) => o.source) : [];
2788
+ for (const o of a) {
2789
+ const s = ne(o);
2790
+ if (!i.has(s)) {
2791
+ const l = ta(
2792
+ o,
2793
+ o.connectionId ? t.get(o.connectionId) : void 0
2794
+ );
2795
+ i.set(s, {
2796
+ key: s,
2797
+ source: o,
2798
+ ...l
2799
+ });
2800
+ }
2801
+ }
2802
+ }
2803
+ return Array.from(i.values());
2804
+ }
2805
+ function ia(e, t) {
2806
+ if (e.kind !== "semantic" || !e.connectionId) return;
2807
+ const i = (t.qualifiedEntityName || "").split(".").map((r) => r.trim()).filter(Boolean), n = i.at(-1);
2808
+ if (n)
2809
+ return {
2810
+ kind: "physical",
2811
+ connectionId: e.connectionId,
2812
+ tableName: n,
2813
+ ...i.length > 1 ? { schemaName: i.at(-2) } : {},
2814
+ ...i.length > 2 ? { databaseName: i.at(-3) } : {}
2815
+ };
2816
+ }
2817
+ function le(e, t) {
2818
+ let i = e.get(t);
2819
+ return i || (i = { fields: /* @__PURE__ */ new Map(), fieldConflicts: /* @__PURE__ */ new Set() }, e.set(t, i)), i;
2820
+ }
2821
+ function Yt(e, t) {
2822
+ e.sourceLabel === void 0 ? e.sourceLabel = t : e.sourceLabel !== t && (e.sourceLabelConflict = !0);
2823
+ }
2824
+ function Me(e, t, i) {
2825
+ for (const n of t) {
2826
+ const r = n == null ? void 0 : n.trim();
2827
+ if (!r) continue;
2828
+ const a = gt(r), o = e.fields.get(a);
2829
+ o === void 0 ? e.fields.set(a, i) : o !== i && e.fieldConflicts.add(a);
2830
+ }
2831
+ }
2832
+ function Xt(e, t) {
2833
+ t.sourceLabel && Yt(e, t.sourceLabel), t.sourceLabelConflict && (e.sourceLabelConflict = !0);
2834
+ for (const [i, n] of t.fields)
2835
+ Me(e, [i], n);
2836
+ for (const i of t.fieldConflicts ?? [])
2837
+ e.fieldConflicts.add(i);
2838
+ }
2839
+ function Zt(e) {
2840
+ return e.kind === "semantic" && (e.label || e.datasetName || "").trim() || void 0;
2841
+ }
2842
+ function ho(e, t) {
2843
+ var n, r;
2844
+ const i = /* @__PURE__ */ new Map();
2845
+ for (const [a, o] of e) {
2846
+ if (o.status !== "ready") continue;
2847
+ const s = t == null ? void 0 : t.get(a), l = s ? Zt(s) : void 0;
2848
+ for (const c of o.columns) {
2849
+ const u = (n = c.column_name) == null ? void 0 : n.trim(), f = (r = c.label) == null ? void 0 : r.trim(), d = s ? ia(s, c) : void 0;
2850
+ d && l && Yt(
2851
+ le(i, ne(d)),
2852
+ l
2853
+ ), !(!u || !f || f === u) && (Me(
2854
+ le(i, a),
2855
+ [u, c.sourceField],
2856
+ f
2857
+ ), d && Me(
2858
+ le(i, ne(d)),
2859
+ [c.sourceField, u],
2860
+ f
2861
+ ));
2862
+ }
2863
+ }
2864
+ return i;
2865
+ }
2866
+ function vo(...e) {
2867
+ const t = /* @__PURE__ */ new Map();
2868
+ for (const i of e)
2869
+ for (const [n, r] of i ?? [])
2870
+ Xt(le(t, n), r);
2871
+ return t;
2872
+ }
2873
+ function Ke(e) {
2874
+ return [e.databaseName, e.schemaName, e.tableName].filter(Boolean).join(".");
2875
+ }
2876
+ function na(e) {
2877
+ return e.split(":").slice(2).filter(Boolean).join(".");
2878
+ }
2879
+ function ei(e, t) {
2880
+ const i = ne(t), n = e.get(i);
2881
+ if (t.kind !== "physical") return n;
2882
+ const r = `physical:${t.connectionId}:`, a = Ke(t), o = {
2883
+ fields: /* @__PURE__ */ new Map(),
2884
+ fieldConflicts: /* @__PURE__ */ new Set()
2885
+ };
2886
+ let s = !1;
2887
+ for (const [l, c] of e)
2888
+ l.startsWith(r) && (l !== i && !Mn(a, na(l)) || (Xt(o, c), s = !0));
2889
+ return s ? o : void 0;
2890
+ }
2891
+ function ra(e, t) {
2892
+ var r;
2893
+ if (!e) return;
2894
+ const i = gt(t.name), n = ei(e, t.source);
2895
+ return n && !((r = n.fieldConflicts) != null && r.has(i)) ? n.fields.get(i) : void 0;
2896
+ }
2897
+ function aa(e, t) {
2898
+ if (t.kind === "semantic")
2899
+ return Zt(t) || t.datasetId || "Dataset";
2900
+ const i = e ? ei(e, t) : void 0;
2901
+ return i != null && i.sourceLabel && !i.sourceLabelConflict ? i.sourceLabel : Ke(t);
2902
+ }
2903
+ function Fo(e, t) {
2904
+ const i = ra(e, t);
2905
+ return {
2906
+ name: t.name,
2907
+ ...i ? { label: i } : {},
2908
+ entityName: aa(e, t.source),
2909
+ ...t.source.kind === "physical" ? { qualifiedEntityName: Ke(t.source) } : {},
2910
+ dataType: t.dataType
2911
+ };
2912
+ }
2913
+ function oa(e, t) {
2914
+ var r, a;
2915
+ const i = (r = t.column_name) == null ? void 0 : r.trim(), n = yt(t.data_type);
2916
+ if (!(!i || n === "unknown"))
2917
+ return {
2918
+ kind: "field",
2919
+ field: {
2920
+ name: i,
2921
+ source: { ...e },
2922
+ dataType: n,
2923
+ ...(a = t.sourceField) != null && a.trim() ? { sourceField: t.sourceField.trim() } : {}
2924
+ }
2925
+ };
2926
+ }
2927
+ function Co(e) {
2928
+ const t = {};
2929
+ for (const { card: i } of e.cards) {
2930
+ const n = wt(i), r = n.kind === "config" ? n.executableSources : n.kind === "sql" ? n.pinnedCatalogSources.map((s) => s.source) : [];
2931
+ if (!r.length) continue;
2932
+ const a = [];
2933
+ let o;
2934
+ for (const s of r) {
2935
+ const l = e.metadataBySourceKey.get(
2936
+ ne(s)
2937
+ );
2938
+ if (!l || l.status === "unavailable") {
2939
+ o = (l == null ? void 0 : l.status) === "unavailable" ? l.message : "Field metadata is not available yet.";
2940
+ break;
2941
+ }
2942
+ for (const c of l.columns) {
2943
+ const u = oa(s, c);
2944
+ u && a.push(u);
2945
+ }
2946
+ }
2947
+ t[i.id] = o ? { status: "metadataUnavailable", message: o } : { status: "ready", targets: a };
2948
+ }
2949
+ return t;
2950
+ }
2951
+ function Io(e) {
2952
+ const { dashboard: t, target: i, calendar: n } = e, r = ii(i), a = ti(t, i, n);
2953
+ return {
2954
+ value: a,
2955
+ mode: Di(
2956
+ Ti(a == null ? void 0 : a.operation) ? a.operation : r.operation
2957
+ )
2958
+ };
2959
+ }
2960
+ function ti(e, t, i) {
2961
+ var n;
2962
+ switch (t.kind) {
2963
+ case "dashboardInput": {
2964
+ const r = mn({
2965
+ dashboard: e,
2966
+ input: t.input,
2967
+ target: t.scope,
2968
+ calendar: i
2969
+ });
2970
+ return (r == null ? void 0 : r.status) === "set" && r.value.kind === "filter" ? r.value.filterValue : void 0;
2971
+ }
2972
+ case "dashboardFilter": {
2973
+ const r = (n = e.defaultFilterValues) == null ? void 0 : n.find(
2974
+ (a) => a.filterId === t.filter.id
2975
+ );
2976
+ return r ? fn({
2977
+ filterDefinitions: [t.filter],
2978
+ filterValues: [r]
2979
+ })[0] : U(t.filter, i);
2980
+ }
2981
+ case "definition":
2982
+ return U(t.filter, i);
2983
+ }
2984
+ }
2985
+ function ii(e) {
2986
+ return e.kind === "dashboardInput" ? e.input.filter : e.filter;
2987
+ }
2988
+ function xo(e) {
2989
+ var a;
2990
+ const { dashboard: t, filter: i, input: n, scope: r } = e;
2991
+ return n && (t.inputs || []).some((o) => o.id === n.id) ? { kind: "dashboardInput", input: n, scope: r } : ((a = q(t).findFilterInput({ filterId: i.id })) == null ? void 0 : a.origin) === "toolbarFilter" ? { kind: "dashboardFilter", filter: i } : { kind: "definition", filter: i };
2992
+ }
2993
+ function So(e) {
2994
+ const { dashboard: t, target: i, calendar: n } = e, r = ii(i), a = pn(r), o = sa(t, i);
2995
+ if (!o) return a;
2996
+ if (o === "cleared")
2997
+ return {
2998
+ operation: r.operation,
2999
+ defaultValues: void 0,
3000
+ defaultDateFilter: void 0
3001
+ };
3002
+ const s = ti(t, i, n);
3003
+ if (!s || la(s, U(r, n)))
3004
+ return a;
3005
+ if (s.valueType === "date") {
3006
+ const l = Ai(
3007
+ "relativeMeta" in s ? s.relativeMeta : void 0
3008
+ ) ?? ca(r, s, n);
3009
+ return l ? {
3010
+ operation: s.operation,
3011
+ defaultValues: r.defaultValues,
3012
+ defaultDateFilter: l
3013
+ } : a;
3014
+ }
3015
+ return {
3016
+ operation: s.operation,
3017
+ defaultValues: s.values,
3018
+ defaultDateFilter: r.defaultDateFilter
3019
+ };
3020
+ }
3021
+ function sa(e, t) {
3022
+ var i;
3023
+ if (t.kind === "dashboardInput") {
3024
+ const n = Oe(
3025
+ e.defaultInputValues,
3026
+ t.input,
3027
+ t.scope
3028
+ );
3029
+ return (n == null ? void 0 : n.status) === "set" || (n == null ? void 0 : n.status) === "cleared" ? n.status : void 0;
3030
+ }
3031
+ if (t.kind === "dashboardFilter")
3032
+ return (i = e.defaultFilterValues) != null && i.some(
3033
+ (n) => n.filterId === t.filter.id
3034
+ ) ? "set" : void 0;
3035
+ }
3036
+ function la(e, t) {
3037
+ return !!(t && e.operation === t.operation && Ie(lt(e), lt(t)) && Ie(
3038
+ "relativeMeta" in e ? e.relativeMeta : void 0,
3039
+ "relativeMeta" in t ? t.relativeMeta : void 0
3040
+ ));
3041
+ }
3042
+ function lt(e) {
3043
+ return e.values.map(
3044
+ (t) => t instanceof Date ? t.getTime() : t
3045
+ );
3046
+ }
3047
+ function ca(e, t, i) {
3048
+ const n = yn(i == null ? void 0 : i.tz), r = he(t.values[0], n);
3049
+ if (!r) return;
3050
+ const [a, o, s] = new Intl.DateTimeFormat("en-CA", {
3051
+ timeZone: n,
3052
+ year: "numeric",
3053
+ month: "2-digit",
3054
+ day: "2-digit"
3055
+ }).format(r).split("-").map(Number), l = [
3056
+ {
3057
+ mode: "fixed",
3058
+ unit: "day",
3059
+ date: `${a}-${String(o).padStart(2, "0")}-${String(s).padStart(2, "0")}`
3060
+ },
3061
+ { mode: "fixed", unit: "month", year: a, month: o - 1 }
3062
+ ], c = t.values.map(
3063
+ (u) => {
3064
+ var f;
3065
+ return (f = he(u, n)) == null ? void 0 : f.getTime();
3066
+ }
3067
+ );
3068
+ return l.find((u) => {
3069
+ const f = U(
3070
+ { ...e, defaultDateFilter: u },
3071
+ i
3072
+ );
3073
+ return (f == null ? void 0 : f.operation) === t.operation && Ie(
3074
+ f.values.map(
3075
+ (d) => {
3076
+ var y;
3077
+ return (y = he(d, n)) == null ? void 0 : y.getTime();
3078
+ }
3079
+ ),
3080
+ c
3081
+ );
3082
+ });
3083
+ }
3084
+ function ua(e) {
3085
+ const t = H(e.format);
3086
+ if ((t == null ? void 0 : t.type) === "temporal_bucket") {
3087
+ if (!e.granularity) return {};
3088
+ const i = qi(
3089
+ t,
3090
+ e.granularity
3091
+ );
3092
+ return i ? {
3093
+ granularity: e.granularity,
3094
+ semanticTemporalPresentation: {
3095
+ granularity: e.granularity,
3096
+ format: i
3097
+ }
3098
+ } : {};
3099
+ }
3100
+ return {
3101
+ ...e.granularity ? { granularity: e.granularity } : {},
3102
+ ...t ? { format: t } : {}
3103
+ };
3104
+ }
3105
+ function da(e, t) {
3106
+ var r, a;
3107
+ const i = ((r = e.nativeDataType) == null ? void 0 : r.trim()) || ((a = e.native_data_type) == null ? void 0 : a.trim());
3108
+ return i || ((e.dataTypeProvenance || t) === "physical" ? e.data_type : void 0);
3109
+ }
3110
+ function ni(e) {
3111
+ const t = (e.label ?? "").trim();
3112
+ return t ? e.derivedLabel === void 0 ? !0 : t !== e.derivedLabel.trim() : !1;
3113
+ }
3114
+ function ke(e) {
3115
+ return ni(e) ? e.label.trim() : e.name || (e.label ?? "").trim();
3116
+ }
3117
+ function ct(e) {
3118
+ return ke(e).toLowerCase().trim();
3119
+ }
3120
+ function fa(e, t) {
3121
+ return ct(e).localeCompare(ct(t), void 0, {
3122
+ numeric: !0,
3123
+ sensitivity: "base"
3124
+ });
3125
+ }
3126
+ function ie(e) {
3127
+ return String(e ?? "").toLowerCase().replace(/[\s_\-.]+/g, "");
3128
+ }
3129
+ function Mo(e, t) {
3130
+ const i = ie(t);
3131
+ return i ? [
3132
+ ke(e),
3133
+ e.label,
3134
+ e.name,
3135
+ e.description,
3136
+ e.entityName,
3137
+ e.qualifiedEntityName,
3138
+ e.entityName && e.name ? `${e.entityName}.${e.name}` : "",
3139
+ e.dataType
3140
+ ].some(
3141
+ (r) => !!r && ie(r).includes(i)
3142
+ ) : !0;
3143
+ }
3144
+ function ut(e, t) {
3145
+ const i = ie(t);
3146
+ if (!i) return 0;
3147
+ const n = ie(ke(e));
3148
+ return n.startsWith(i) ? 0 : n.includes(i) ? 1 : [e.label, e.name].filter(Boolean).map(ie).some((a) => a.includes(i)) ? 2 : 3;
3149
+ }
3150
+ function Do(e, t, i) {
3151
+ return ut(e, i) - ut(t, i) || fa(e, t);
3152
+ }
3153
+ function ma(e, t) {
3154
+ var a;
3155
+ const i = e.type === "dataset" ? (a = t.find((o) => o.entityName)) == null ? void 0 : a.entityName : void 0, n = i || e.name, r = Ze(
3156
+ e.type === "dataset" && i ? { ...e, name: i } : e
3157
+ );
3158
+ return {
3159
+ entityId: e.id || e.name,
3160
+ entityType: e.type,
3161
+ entityName: n,
3162
+ label: e.label,
3163
+ description: e.description,
3164
+ qualifiedEntityName: r,
3165
+ columns: t.map((o) => {
3166
+ var y;
3167
+ const s = e.type === "dataset" ? o.entityName || n : e.name, l = o.qualifiedEntityName || (e.type === "dataset" && s ? Ze({ ...e, name: s }) : r), c = da(
3168
+ o,
3169
+ e.type === "dataset" ? "semantic" : "physical"
3170
+ ), u = (y = o.label) != null && y.trim() ? o.label : void 0, f = u ? void 0 : gn(o.column_name);
3171
+ return {
3172
+ id: bn(s, o.column_name),
3173
+ name: o.column_name,
3174
+ qualifiedFieldName: o.qualifiedFieldName || o.column_name,
3175
+ dataType: o.data_type,
3176
+ ...c ? { nativeDataType: c } : {},
3177
+ label: u ?? f ?? o.column_name,
3178
+ ...f !== void 0 ? { derivedLabel: f } : {},
3179
+ description: o.description || "",
3180
+ qualifiedEntityName: l,
3181
+ entityId: o.entityId || e.id || e.id || s,
3182
+ entityName: s,
3183
+ entityType: o.entityType || e.type,
3184
+ role: o.role,
3185
+ expression: o.expression,
3186
+ calculatedFormula: o.calculatedFormula,
3187
+ calculationRepresentation: o.calculationRepresentation,
3188
+ derivedField: o.derivedField,
3189
+ fieldScope: o.fieldScope,
3190
+ source: o.source,
3191
+ sourceField: o.sourceField,
3192
+ calculatedFieldOrigin: o.calculatedFieldOrigin,
3193
+ aggregateOrigin: o.aggregateOrigin,
3194
+ labelOrigin: o.labelOrigin,
3195
+ formatOrigin: o.formatOrigin,
3196
+ ...ua(o),
3197
+ aggregate: o.aggregate
3198
+ };
3199
+ })
3200
+ };
3201
+ }
3202
+ function pa(e) {
3203
+ return e.map((t) => ({
3204
+ ...t,
3205
+ id: Pt({ ...t }),
3206
+ fieldScope: "domain"
3207
+ }));
3208
+ }
3209
+ function ya(e) {
3210
+ return e.flatMap(
3211
+ (t) => t.columns.map((i) => {
3212
+ const n = ni(i) ? i.label : void 0, r = n ? void 0 : i.derivedLabel ?? vn(i.name), a = n ?? r ?? i.name;
3213
+ return {
3214
+ ...i,
3215
+ id: i.id || `${t.entityId}-${i.name}`,
3216
+ name: i.name,
3217
+ qualifiedFieldName: i.qualifiedFieldName || i.name,
3218
+ dataType: i.dataType,
3219
+ qualifiedEntityName: i.qualifiedEntityName || t.qualifiedEntityName,
3220
+ label: a,
3221
+ ...r !== void 0 ? { derivedLabel: r } : {},
3222
+ description: i.description,
3223
+ entityId: i.entityId || t.entityId,
3224
+ entityName: i.entityName || t.entityName,
3225
+ entityType: i.entityType || t.entityType
3226
+ };
3227
+ })
3228
+ );
3229
+ }
3230
+ function To(e) {
3231
+ const t = e.map((n) => ma(n.target, n.columns || [])).filter((n) => {
3232
+ var r;
3233
+ return ((r = n == null ? void 0 : n.columns) == null ? void 0 : r.length) > 0;
3234
+ }), i = pa(e.flatMap((n) => n.calculatedFields || []));
3235
+ if (i.length > 0) {
3236
+ const n = /* @__PURE__ */ new Map();
3237
+ i.forEach((r) => {
3238
+ const a = Pt(r);
3239
+ n.has(a) || n.set(a, r);
3240
+ }), t.unshift({
3241
+ entityId: hn,
3242
+ entityType: "dataset",
3243
+ entityName: et,
3244
+ label: "Calculated Fields",
3245
+ description: "Domain-level calculated metrics and dimensions",
3246
+ qualifiedEntityName: et,
3247
+ columns: Array.from(n.values())
3248
+ });
3249
+ }
3250
+ return { columnGroups: t, columns: ya(t) };
3251
+ }
3252
+ export {
3253
+ io as $,
3254
+ z as A,
3255
+ ue as B,
3256
+ Er as C,
3257
+ _a as D,
3258
+ Vr as E,
3259
+ co as F,
3260
+ yo as G,
3261
+ Vn as H,
3262
+ ka as I,
3263
+ Nn as J,
3264
+ En as K,
3265
+ $t as L,
3266
+ Kn as M,
3267
+ Pr as N,
3268
+ Bn as O,
3269
+ Ne as P,
3270
+ Ua as Q,
3271
+ $a as R,
3272
+ Ya as S,
3273
+ Bt as T,
3274
+ hr as U,
3275
+ ao as V,
3276
+ Ja as W,
3277
+ er as X,
3278
+ Ve as Y,
3279
+ Ha as Z,
3280
+ eo as _,
3281
+ go as a,
3282
+ to as a0,
3283
+ Nt as a1,
3284
+ cr as a2,
3285
+ Fr as a3,
3286
+ re as a4,
3287
+ Za as a5,
3288
+ no as a6,
3289
+ jn as a7,
3290
+ Zn as a8,
3291
+ pr as a9,
3292
+ Fo as aA,
3293
+ aa as aB,
3294
+ Ke as aC,
3295
+ bo as aD,
3296
+ Co as aE,
3297
+ ho as aF,
3298
+ ta as aG,
3299
+ da as aH,
3300
+ So as aI,
3301
+ xo as aJ,
3302
+ vo as aK,
3303
+ ra as aL,
3304
+ fo as aM,
3305
+ Ar as aN,
3306
+ lr as aO,
3307
+ Do as aP,
3308
+ ut as aQ,
3309
+ ua as aR,
3310
+ ie as aS,
3311
+ La as aT,
3312
+ yr as aa,
3313
+ ro as ab,
3314
+ Se as ac,
3315
+ ur as ad,
3316
+ Qa as ae,
3317
+ Ga as af,
3318
+ Wa as ag,
3319
+ Wn as ah,
3320
+ Gn as ai,
3321
+ Cr as aj,
3322
+ xe as ak,
3323
+ qa as al,
3324
+ An as am,
3325
+ Ba as an,
3326
+ Rn as ao,
3327
+ ja as ap,
3328
+ de as aq,
3329
+ ae as ar,
3330
+ Ka as as,
3331
+ Xa as at,
3332
+ rr as au,
3333
+ za as av,
3334
+ Rr as aw,
3335
+ ni as ax,
3336
+ Mo as ay,
3337
+ ne as az,
3338
+ po as b,
3339
+ lo as c,
3340
+ oa as d,
3341
+ Br as e,
3342
+ Kr as f,
3343
+ Ra as g,
3344
+ Pn as h,
3345
+ Ir as i,
3346
+ Sr as j,
3347
+ Mr as k,
3348
+ oo as l,
3349
+ Dr as m,
3350
+ Tr as n,
3351
+ so as o,
3352
+ wr as p,
3353
+ ma as q,
3354
+ Io as r,
3355
+ pa as s,
3356
+ ya as t,
3357
+ To as u,
3358
+ ke as v,
3359
+ vr as w,
3360
+ mr as x,
3361
+ mo as y,
3362
+ uo as z
3363
+ };