react-semaphor 0.1.443 → 0.1.445
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.
- package/CHANGELOG.md +7 -0
- package/dist/analytics-protocol/index.cjs +1 -1
- package/dist/analytics-protocol/index.js +123 -107
- package/dist/appearance/index.cjs +1 -1
- package/dist/brand-studio/index.cjs +2 -2
- package/dist/brand-studio/index.js +5 -4
- package/dist/briefings/index.cjs +1 -1
- package/dist/briefings/index.js +526 -457
- package/dist/chunks/analyze-result-contract-BHb7sUUW.cjs +1 -0
- package/dist/chunks/analyze-result-contract-DUv3QnMl.js +29 -0
- package/dist/chunks/{braces-CbO-aIwH.js → braces-BKimshER.cjs} +1 -1
- package/dist/chunks/{code-editor-BpADiIlq.js → code-editor-B4gTfvc5.js} +6800 -6560
- package/dist/chunks/code-editor-BYVorgOf.cjs +138 -0
- package/dist/chunks/common-types-CQ6SHfLk.cjs +1 -0
- package/dist/chunks/{common-types-ClkOI-3O.js → common-types-DFsDdpH7.js} +22 -21
- package/dist/chunks/dashboard-CAiwJW3L.cjs +1397 -0
- package/dist/chunks/{dashboard-briefing-launcher-C60n8LqW.js → dashboard-briefing-launcher-2SLNOaTg.js} +26 -24
- package/dist/chunks/{dashboard-briefing-launcher-BYMLjZxG.js → dashboard-briefing-launcher-CHwjpUYz.cjs} +2 -2
- package/dist/chunks/{dashboard-controls-ti9Rcel2.js → dashboard-controls-BfL14aqO.js} +11 -9
- package/dist/chunks/{dashboard-controls-BH_fZYDU.js → dashboard-controls-BgGTg4yw.cjs} +2 -2
- package/dist/chunks/dashboard-date-comparison-definition-DZq0htjG.cjs +1 -0
- package/dist/chunks/dashboard-json-BOv8tCa9.cjs +1 -0
- package/dist/chunks/{dashboard-json-Bturr634.js → dashboard-json-BZwq3EcS.js} +14 -12
- package/dist/chunks/{dashboard-Bd1Quco-.js → dashboard-u61yfU6u.js} +50081 -47351
- package/dist/chunks/edit-dashboard-visual-BdVCH0DJ.cjs +182 -0
- package/dist/chunks/{edit-dashboard-visual-DglMds57.js → edit-dashboard-visual-njLPYip3.js} +6825 -6656
- package/dist/chunks/{editor-action-buttons-CRi0fhVW.js → editor-action-buttons-BhLX5Q6m.js} +24 -23
- package/dist/chunks/{editor-action-buttons-Cxo7_tNG.js → editor-action-buttons-CBVMFipA.cjs} +1 -1
- package/dist/chunks/{index-D7KJindZ.js → format-types-CSv0V7mm.cjs} +1 -1
- package/dist/chunks/{index-CnujJ3fa.js → format-types-CZH5w1lo.js} +23 -17
- package/dist/chunks/{layout-grid-B08pP7v6.js → layout-grid-3-HWzEwU.cjs} +1 -1
- package/dist/chunks/{metric-comparison-CPoDx56y.js → metric-comparison-BJ_Qu1ZF.js} +1 -1
- package/dist/chunks/metric-comparison-CUAJ8n4y.cjs +1 -0
- package/dist/chunks/{palette-C0yjT5Tv.js → palette-DW_l7Jr0.cjs} +1 -1
- package/dist/chunks/pivot-result-identity-B6QCWOSi.js +94 -0
- package/dist/chunks/pivot-result-identity-CDLRT-YG.cjs +1 -0
- package/dist/chunks/pivot-result-lifecycle-BM3Pl-D1.js +914 -0
- package/dist/chunks/pivot-result-lifecycle-DPc0ANwk.cjs +4 -0
- package/dist/chunks/presentation-execution-BTV-Q43g.cjs +1 -0
- package/dist/chunks/presentation-execution-CGlb7YZ6.js +637 -0
- package/dist/chunks/{report-preferences-dialog-TtwdAuNn.js → report-preferences-dialog-D_NJu2wU.js} +7 -6
- package/dist/chunks/report-preferences-dialog-r8QzOSFb.cjs +1 -0
- package/dist/chunks/report-runtime-context-C8LZFsqV.cjs +1 -0
- package/dist/chunks/report-runtime-context-Qzn11HQe.js +387 -0
- package/dist/chunks/{save-Xdc4pnys.js → save-4_uMnE6s.cjs} +1 -1
- package/dist/chunks/{search-Dcud9ajy.js → search-6ZmeMq55.cjs} +1 -1
- package/dist/chunks/temporal-bucket-BnPxGrAi.js +446 -0
- package/dist/chunks/temporal-bucket-authoring-BUZMuVca.js +205 -0
- package/dist/chunks/temporal-bucket-authoring-CPTwHzvs.cjs +1 -0
- package/dist/chunks/temporal-bucket-contract-B2bJ1oe4.js +108 -0
- package/dist/chunks/temporal-bucket-contract-ChDBWX8I.cjs +1 -0
- package/dist/chunks/temporal-bucket-pMnV-4Nj.cjs +1 -0
- package/dist/chunks/{comparison-document-migration-Dj6xZMCb.js → temporal-result-owner-Cb27SSG9.js} +152 -123
- package/dist/chunks/temporal-result-owner-f6-i65Fb.cjs +1 -0
- package/dist/chunks/token-types-BdQ8kHBm.cjs +1 -0
- package/dist/chunks/token-types-DLo91nOf.js +8 -0
- package/dist/chunks/{update-policy-DnF_74zC.js → update-policy-BxvYMYz0.cjs} +1 -1
- package/dist/chunks/{update-policy-De2NswtM.js → update-policy-eg59mQqv.js} +1 -1
- package/dist/chunks/validators-9D4KBqKD.cjs +1 -0
- package/dist/chunks/validators-wZ2WlNHc.js +4640 -0
- package/dist/dashboard/index.cjs +1 -1
- package/dist/dashboard/index.js +2 -2
- package/dist/dashboard-authoring/index.cjs +3 -3
- package/dist/dashboard-authoring/index.js +136 -126
- package/dist/data-app-builder/index.cjs +1 -1
- package/dist/data-app-builder/index.js +2 -2
- package/dist/data-app-codegen/index.cjs +1 -1
- package/dist/data-app-codegen/index.js +2 -2
- package/dist/data-app-codegen-node/index.cjs +1 -1
- package/dist/data-app-codegen-node/index.js +3 -3
- package/dist/data-app-sdk/index.cjs +2 -2
- package/dist/data-app-sdk/index.js +34 -35
- package/dist/data-app-sdk-adapters/index.cjs +1 -1
- package/dist/data-app-sdk-adapters/index.js +5 -5
- package/dist/data-app-sdk-validation/index.cjs +1 -1
- package/dist/data-app-sdk-validation/index.js +9 -10
- package/dist/format-utils/index.cjs +3 -3
- package/dist/format-utils/index.js +155 -176
- package/dist/index.cjs +1 -1
- package/dist/index.js +180 -174
- package/dist/report-runtime-context/index.cjs +1 -1
- package/dist/report-runtime-context/index.js +7 -392
- package/dist/shared/index.cjs +1 -1
- package/dist/style.css +1 -1
- package/dist/surfboard/index.cjs +1 -1
- package/dist/surfboard/index.js +3 -3
- package/dist/types/analytics-protocol.d.ts +257 -48
- package/dist/types/briefings.d.ts +138 -50
- package/dist/types/dashboard-assistant.d.ts +207 -52
- package/dist/types/dashboard-authoring.d.ts +182 -50
- package/dist/types/dashboard.d.ts +290 -48
- package/dist/types/data-app-builder.d.ts +48 -42
- package/dist/types/data-app-codegen-node.d.ts +50 -44
- package/dist/types/data-app-codegen.d.ts +50 -44
- package/dist/types/data-app-sdk-adapters.d.ts +48 -42
- package/dist/types/data-app-sdk-validation.d.ts +81 -43
- package/dist/types/data-app-sdk.d.ts +83 -45
- package/dist/types/format-utils.d.ts +645 -67
- package/dist/types/index.cjs +1 -1
- package/dist/types/index.js +19 -19
- package/dist/types/main.d.ts +298 -94
- package/dist/types/report-runtime-context.d.ts +3 -0
- package/dist/types/shared.d.ts +116 -41
- package/dist/types/surfboard.d.ts +290 -48
- package/dist/types/types.d.ts +455 -65
- package/package.json +3 -1
- package/dist/chunks/analyze-result-contract-BswhsmWT.js +0 -1
- package/dist/chunks/analyze-result-contract-CfOBEwaC.js +0 -1998
- package/dist/chunks/code-editor-M7HTUhdF.js +0 -138
- package/dist/chunks/common-types-C73-Ud1-.js +0 -1
- package/dist/chunks/comparison-document-migration-DbU_BTxR.js +0 -1
- package/dist/chunks/csv-utils-BZDvO2Fw.js +0 -376
- package/dist/chunks/csv-utils-Co0WxHke.js +0 -4
- package/dist/chunks/dashboard-cB3xmTNn.js +0 -1402
- package/dist/chunks/dashboard-date-comparison-definition-DGZr3m-b.js +0 -1
- package/dist/chunks/dashboard-json-Dw_55vSZ.js +0 -1
- package/dist/chunks/edit-dashboard-visual-BUc3NBQ4.js +0 -182
- package/dist/chunks/metric-comparison-DVy3fll_.js +0 -1
- package/dist/chunks/numeric-presentation-BJs5lSar.js +0 -517
- package/dist/chunks/numeric-presentation-Dlb-Dk4c.js +0 -1
- package/dist/chunks/report-preferences-dialog-CCvFqH4Q.js +0 -1
- package/dist/chunks/source-identity-5OPV4gvg.js +0 -92
- package/dist/chunks/source-identity-Cbo2LOHQ.js +0 -1
- package/dist/chunks/validators-B2vUAqTf.js +0 -1
- package/dist/chunks/validators-Bce_J7Vd.js +0 -2448
- /package/dist/chunks/{card-config-utils-15sRtebL.js → card-config-utils-15sRtebL.cjs} +0 -0
- /package/dist/chunks/{catalog-field-grounding-Bnx-3tE0.js → catalog-field-grounding-Bnx-3tE0.cjs} +0 -0
- /package/dist/chunks/{dashboard-input-contract-DV3cshjz.js → dashboard-input-contract-DV3cshjz.cjs} +0 -0
- /package/dist/chunks/{index-Dpm_VET4.js → index-Dpm_VET4.cjs} +0 -0
- /package/dist/chunks/{index-jSrCwPQz.js → index-jSrCwPQz.cjs} +0 -0
- /package/dist/chunks/{normalize-dashboard-for-dirty-check-BXRUMVb2.js → normalize-dashboard-for-dirty-check-BXRUMVb2.cjs} +0 -0
- /package/dist/chunks/{operators-DrTQsJXv.js → operators-DrTQsJXv.cjs} +0 -0
- /package/dist/chunks/{use-debounced-dirty-check-XHSwAefL.js → use-debounced-dirty-check-XHSwAefL.cjs} +0 -0
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";const g=require("./validators-B2vUAqTf.js"),b="higher_is_better",C={displayMode:"difference",showComparison:!0,indicatorStyle:"arrow_badge",showColor:!0,conditionalLabel:!1};function w(o){return g.parseSemaphorIsoInstant(o)!==null}function $(o){var i,e,s,t;if(((i=o.metricComparison)==null?void 0:i.mode)!=="off"){if(((e=o.metricComparison)==null?void 0:e.mode)==="explicit")return{source:"explicit",spec:o.metricComparison.spec};if(!((o.inheritGlobalComparison??((s=o.globalDateComparison)==null?void 0:s.inheritGlobalComparison))===!1||((t=o.globalDateComparison)==null?void 0:t.selection.mode)!=="period"))return{source:"inherited",spec:o.globalDateComparison.selection.spec,...o.globalDateComparison.owner?{owner:o.globalDateComparison.owner}:{}}}}function h(o){if(o.alias)return o.alias;const i=o.entityName&&o.entityName!=="SEMAPHOR_CALCULATED_FIELD"?o.entityName:void 0,e=i&&i!==o.name?`${i}_`:"";if(o.role!=="metric")return`${e}${o.name}`;let s=o.aggregate||"metric";if(o.expression){const t=o.expression.match(/^(COUNT|SUM|AVG|MIN|MAX|MEDIAN|DISTINCT)\s*\(/i);s=t?t[1].toLowerCase():"expr"}else s=s.toLowerCase();return`${e}${o.name}_${s}`}function n(o,i,e){return e?{code:o,message:i,path:e}:{code:o,message:i}}function p(o){return!!o&&typeof o=="object"&&!Array.isArray(o)}function a(o,i,e,s){Object.keys(o).forEach(t=>{i.includes(t)||s.push(n("invalid_comparison_spec",`Comparison kind does not accept field "${t}".`,`${e}.${t}`))})}function f(o,i,e){o.alignment!==void 0&&o.alignment!=="calendar"&&o.alignment!=="weekday"&&e.push(n("invalid_comparison_spec",'Comparison alignment must be "calendar" or "weekday".',`${i}.alignment`)),o.toDate!==void 0&&typeof o.toDate!="boolean"&&e.push(n("invalid_comparison_spec","Comparison toDate must be a boolean.",`${i}.toDate`))}function _(o,i,e){o!==void 0&&(typeof o!="number"||!Number.isSafeInteger(o)||o<=0)&&e.push(n("invalid_comparison_spec","Comparison offset must be a positive safe integer.",i))}function d(o,i="comparison"){const e=[];return p(o)?(o.kind==="previous_period"?(a(o,["kind","offsetPeriods","alignment","toDate"],i,e),_(o.offsetPeriods,`${i}.offsetPeriods`,e),f(o,i,e)):o.kind==="previous_year"?(a(o,["kind","offsetYears","alignment","toDate"],i,e),_(o.offsetYears,`${i}.offsetYears`,e),f(o,i,e)):o.kind==="target"?(a(o,["kind","targetValue"],i,e),(typeof o.targetValue!="number"||!Number.isFinite(o.targetValue))&&e.push(n("invalid_comparison_spec","Target comparison requires a finite targetValue.",`${i}.targetValue`))):e.push(n("invalid_comparison_spec","Comparison kind must be previous_period, previous_year, or target.",`${i}.kind`)),{ok:e.length===0,errors:e,warnings:[]}):{ok:!1,errors:[n("invalid_comparison_spec","Comparison spec must be an object.",i)],warnings:[]}}function D(o,i="comparison"){if(!p(o))return{ok:!1,errors:[n("invalid_comparison_config","Comparison config must be an object.",i)],warnings:[]};const e=[];return o.mode==="off"?a(o,["mode"],i,e):o.mode==="explicit"?(a(o,["mode","spec"],i,e),e.push(...d(o.spec,`${i}.spec`).errors)):e.push(n("invalid_comparison_config","Comparison mode must be off or explicit.",`${i}.mode`)),{ok:e.length===0,errors:e,warnings:[]}}function u(o,i="comparisonSelection"){if(!p(o))return{ok:!1,errors:[n("invalid_global_date_comparison","Global Date comparison selection must be an object.",i)],warnings:[]};const e=[];if(o.mode==="off")a(o,["mode"],i,e);else if(o.mode==="period"){a(o,["mode","spec"],i,e);const s=d(o.spec,`${i}.spec`);e.push(...s.errors),p(o.spec)&&o.spec.kind==="target"&&e.push(n("invalid_global_date_comparison","Global Date comparison supports previous_period or previous_year, not target.",`${i}.spec.kind`))}else e.push(n("invalid_global_date_comparison","Global Date comparison mode must be off or period.",`${i}.mode`));return{ok:e.length===0,errors:e,warnings:[]}}function I(o,i="globalDateComparison"){if(!p(o))return{ok:!1,errors:[n("invalid_global_date_comparison","Global Date comparison context must be an object.",i)],warnings:[]};const e=[];return a(o,["selection","inheritGlobalComparison","owner","referenceTime"],i,e),e.push(...u(o.selection,`${i}.selection`).errors),o.inheritGlobalComparison!==void 0&&o.inheritGlobalComparison!==!1&&e.push(n("invalid_global_date_comparison","inheritGlobalComparison may only be false when present.",`${i}.inheritGlobalComparison`)),o.owner!==void 0&&(p(o.owner)?o.owner.kind==="global_date"?a(o.owner,["kind"],`${i}.owner`,e):o.owner.kind==="field_date"?(a(o.owner,["kind","filterId","label"],`${i}.owner`,e),(typeof o.owner.filterId!="string"||!o.owner.filterId.trim())&&e.push(n("invalid_global_date_comparison","Field Date comparison owner requires a non-empty filterId.",`${i}.owner.filterId`)),(typeof o.owner.label!="string"||!o.owner.label.trim())&&e.push(n("invalid_global_date_comparison","Field Date comparison owner requires a non-empty label.",`${i}.owner.label`))):e.push(n("invalid_global_date_comparison","Comparison owner kind must be global_date or field_date.",`${i}.owner.kind`)):e.push(n("invalid_global_date_comparison","Comparison owner must be an object.",`${i}.owner`))),o.referenceTime!==void 0&&(typeof o.referenceTime!="string"||!w(o.referenceTime))&&e.push(n("invalid_global_date_comparison","referenceTime must be a valid ISO date-time string when present.",`${i}.referenceTime`)),{ok:e.length===0,errors:e,warnings:[]}}function M(o,i="comparisonPolarity"){return o==="higher_is_better"||o==="lower_is_better"||o==="neutral"?{ok:!0,errors:[],warnings:[]}:{ok:!1,errors:[n("invalid_comparison_polarity","Comparison polarity must be higher_is_better, lower_is_better, or neutral.",i)],warnings:[]}}function S(o,i="comparisonPresentation"){if(!p(o))return{ok:!1,errors:[n("invalid_comparison_presentation","Comparison presentation must be an object.",i)],warnings:[]};const e=[],s=["displayMode","showComparison","precision","indicatorStyle","showColor","position","conditionalLabel","labelName","conditionalLabels","colors"];return Object.keys(o).forEach(r=>{s.includes(r)||e.push(n("invalid_comparison_presentation",`Comparison presentation does not accept field "${r}".`,`${i}.${r}`))}),[["displayMode",["difference","percent_change","both","ratio"]],["indicatorStyle",["arrow_badge","arrow","badge","none"]],["position",["left","right","top"]]].forEach(([r,l])=>{o[r]!==void 0&&!l.includes(o[r])&&e.push(n("invalid_comparison_presentation",`Comparison presentation ${r} is invalid.`,`${i}.${r}`))}),["showComparison","showColor","conditionalLabel"].forEach(r=>{o[r]!==void 0&&typeof o[r]!="boolean"&&e.push(n("invalid_comparison_presentation",`Comparison presentation ${r} must be a boolean.`,`${i}.${r}`))}),o.precision!==void 0&&(typeof o.precision!="number"||!Number.isInteger(o.precision)||o.precision<0||o.precision>6)&&e.push(n("invalid_comparison_presentation","Comparison presentation precision must be an integer from 0 through 6.",`${i}.precision`)),o.labelName!==void 0&&typeof o.labelName!="string"&&e.push(n("invalid_comparison_presentation","Comparison presentation labelName must be a string.",`${i}.labelName`)),["conditionalLabels","colors"].forEach(r=>{const l=o[r];if(l!==void 0){if(!p(l)){e.push(n("invalid_comparison_presentation",`Comparison presentation ${r} must be an object.`,`${i}.${r}`));return}Object.keys(l).forEach(c=>{["increase","decrease","neutral"].includes(c)||e.push(n("invalid_comparison_presentation",`Comparison presentation ${r} does not accept field "${c}".`,`${i}.${r}.${c}`))}),Object.entries(l).forEach(([c,m])=>{m!==void 0&&typeof m!="string"&&e.push(n("invalid_comparison_presentation",`Comparison presentation ${r}.${c} must be a string.`,`${i}.${r}.${c}`))})}}),{ok:e.length===0,errors:e,warnings:[]}}function N(o){return o===null?"unknown":o>0?"increase":o<0?"decrease":"no_change"}function T(o,i){return o==="unknown"||o==="no_change"||i==="neutral"?"neutral":i==="higher_is_better"&&o==="increase"||i==="lower_is_better"&&o==="decrease"?"favorable":"unfavorable"}function y(o){const{currentValue:i,comparisonValue:e,polarity:s=b}=o,r=i!==null&&e!==null?i-e:null,l=r!==null&&e!==null&&e!==0?r/Math.abs(e):null,c=i!==null&&e!==null&&e!==0?i/e:null,m=N(r);return{status:e===null?"insufficient_history":"available",currentValue:i,comparisonValue:e,delta:r,percentChange:l,ratio:c,direction:m,sentiment:T(m,s)}}exports.COMPARISON_PRESENTATION_DEFAULTS=C;exports.DEFAULT_METRIC_COMPARISON_POLARITY=b;exports.evaluateMetricComparison=y;exports.resolveMetricComparisonRequest=$;exports.resolveMetricResultAlias=h;exports.validateComparisonPresentationSpec=S;exports.validateGlobalDateComparisonContext=I;exports.validateGlobalDateComparisonSelection=u;exports.validateMetricComparisonConfig=D;exports.validateMetricComparisonPolarity=M;exports.validateMetricComparisonSpec=d;
|
|
@@ -1,517 +0,0 @@
|
|
|
1
|
-
import { canonicalizeSupportedLocale as I, canonicalizeSupportedCurrencyCode as o } from "../value-format-preferences/index.js";
|
|
2
|
-
import { parseReportRuntimeContext as K } from "../report-runtime-context/index.js";
|
|
3
|
-
function F(r) {
|
|
4
|
-
if (!r) return !1;
|
|
5
|
-
const e = r.toLowerCase().replace("_", "-");
|
|
6
|
-
return e === "en-in" || e.startsWith("en-in-");
|
|
7
|
-
}
|
|
8
|
-
function $(r, e) {
|
|
9
|
-
const c = Math.abs(r);
|
|
10
|
-
return c >= 1e12 ? { divisor: 1e12, suffix: "T" } : c >= 1e9 ? { divisor: 1e9, suffix: "B" } : F(e) && c >= 1e7 ? { divisor: 1e7, suffix: "Cr" } : c >= 1e6 ? { divisor: 1e6, suffix: "M" } : F(e) && c >= 1e5 ? { divisor: 1e5, suffix: "L" } : c >= 1e3 ? { divisor: 1e3, suffix: "K" } : { divisor: 1, suffix: "" };
|
|
11
|
-
}
|
|
12
|
-
function v(r, e) {
|
|
13
|
-
try {
|
|
14
|
-
const c = h(e);
|
|
15
|
-
return $(r, c);
|
|
16
|
-
} catch {
|
|
17
|
-
return $(r, "en-US");
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
function G(r) {
|
|
21
|
-
try {
|
|
22
|
-
return new Intl.NumberFormat(r), !0;
|
|
23
|
-
} catch {
|
|
24
|
-
return !1;
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
function h(r) {
|
|
28
|
-
return r && G(r) ? r : "en-US";
|
|
29
|
-
}
|
|
30
|
-
function D(r, e) {
|
|
31
|
-
if (r == null || isNaN(r))
|
|
32
|
-
return "";
|
|
33
|
-
const c = h(e == null ? void 0 : e.locale);
|
|
34
|
-
let i = r;
|
|
35
|
-
if (e != null && e.multiplyBy && (i *= e.multiplyBy), e != null && e.useSuffix) {
|
|
36
|
-
const { divisor: a, suffix: s } = v(i, c);
|
|
37
|
-
i = i / a;
|
|
38
|
-
const m = new Intl.NumberFormat(c, {
|
|
39
|
-
minimumFractionDigits: (e == null ? void 0 : e.minimumFractionDigits) ?? 0,
|
|
40
|
-
maximumFractionDigits: (e == null ? void 0 : e.maximumFractionDigits) ?? 2,
|
|
41
|
-
useGrouping: (e == null ? void 0 : e.useGrouping) ?? !0
|
|
42
|
-
}).format(i);
|
|
43
|
-
return `${(e == null ? void 0 : e.prefix) ?? ""}${m}${s}${(e == null ? void 0 : e.suffix) ?? ""}`;
|
|
44
|
-
}
|
|
45
|
-
const t = new Intl.NumberFormat(c, {
|
|
46
|
-
minimumFractionDigits: (e == null ? void 0 : e.minimumFractionDigits) ?? 0,
|
|
47
|
-
maximumFractionDigits: (e == null ? void 0 : e.maximumFractionDigits) ?? 2,
|
|
48
|
-
useGrouping: (e == null ? void 0 : e.useGrouping) ?? !0
|
|
49
|
-
}).format(i);
|
|
50
|
-
if (e != null && e.negativeInParentheses && i < 0) {
|
|
51
|
-
const a = t.replace("-", "");
|
|
52
|
-
return `(${(e == null ? void 0 : e.prefix) ?? ""}${a}${(e == null ? void 0 : e.suffix) ?? ""})`;
|
|
53
|
-
}
|
|
54
|
-
return `${(e == null ? void 0 : e.prefix) ?? ""}${t}${(e == null ? void 0 : e.suffix) ?? ""}`;
|
|
55
|
-
}
|
|
56
|
-
function k(r, e) {
|
|
57
|
-
if (r == null || isNaN(r))
|
|
58
|
-
return "";
|
|
59
|
-
const c = h(e == null ? void 0 : e.locale), i = (e == null ? void 0 : e.currency) || "USD", t = r < 0, a = !!(e != null && e.negativeInParentheses && t), s = a ? Math.abs(r) : r;
|
|
60
|
-
try {
|
|
61
|
-
if (e != null && e.useSuffix) {
|
|
62
|
-
const { divisor: l, suffix: d } = v(s, c), u = s / l, y = `${new Intl.NumberFormat(c, {
|
|
63
|
-
style: "currency",
|
|
64
|
-
currency: i,
|
|
65
|
-
minimumFractionDigits: (e == null ? void 0 : e.minimumFractionDigits) ?? 0,
|
|
66
|
-
maximumFractionDigits: (e == null ? void 0 : e.maximumFractionDigits) ?? 2,
|
|
67
|
-
useGrouping: (e == null ? void 0 : e.useGrouping) ?? !0
|
|
68
|
-
}).format(u)}${d}`;
|
|
69
|
-
return a ? `(${y})` : y;
|
|
70
|
-
}
|
|
71
|
-
const m = new Intl.NumberFormat(c, {
|
|
72
|
-
style: "currency",
|
|
73
|
-
currency: i,
|
|
74
|
-
minimumFractionDigits: (e == null ? void 0 : e.minimumFractionDigits) ?? 0,
|
|
75
|
-
maximumFractionDigits: (e == null ? void 0 : e.maximumFractionDigits) ?? 2,
|
|
76
|
-
useGrouping: (e == null ? void 0 : e.useGrouping) ?? !0
|
|
77
|
-
}).format(s);
|
|
78
|
-
return a ? `(${m})` : m;
|
|
79
|
-
} catch {
|
|
80
|
-
const m = Math.abs(r), l = e != null && e.useSuffix ? v(m, c) : { divisor: 1, suffix: "" }, d = D(
|
|
81
|
-
m / l.divisor,
|
|
82
|
-
{
|
|
83
|
-
locale: c,
|
|
84
|
-
minimumFractionDigits: (e == null ? void 0 : e.minimumFractionDigits) ?? 0,
|
|
85
|
-
maximumFractionDigits: (e == null ? void 0 : e.maximumFractionDigits) ?? 2,
|
|
86
|
-
useGrouping: (e == null ? void 0 : e.useGrouping) ?? !0
|
|
87
|
-
}
|
|
88
|
-
), u = `${i} ${d}${l.suffix}`;
|
|
89
|
-
return t ? e != null && e.negativeInParentheses ? `(${u})` : `-${u}` : u;
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
function S(r, e) {
|
|
93
|
-
if (r == null || isNaN(r))
|
|
94
|
-
return "";
|
|
95
|
-
const c = h(e == null ? void 0 : e.locale), t = (e == null ? void 0 : e.alreadyPercent) ?? (e == null ? void 0 : e.percentValueMode) === "whole" ? r / 100 : r;
|
|
96
|
-
return new Intl.NumberFormat(c, {
|
|
97
|
-
style: "percent",
|
|
98
|
-
minimumFractionDigits: (e == null ? void 0 : e.minimumFractionDigits) ?? 0,
|
|
99
|
-
maximumFractionDigits: (e == null ? void 0 : e.maximumFractionDigits) ?? 2,
|
|
100
|
-
useGrouping: (e == null ? void 0 : e.useGrouping) ?? !0
|
|
101
|
-
}).format(t);
|
|
102
|
-
}
|
|
103
|
-
function C(r, e) {
|
|
104
|
-
if (r == null || isNaN(r))
|
|
105
|
-
return "";
|
|
106
|
-
const c = h(e == null ? void 0 : e.locale);
|
|
107
|
-
return new Intl.NumberFormat(c, {
|
|
108
|
-
notation: "scientific",
|
|
109
|
-
minimumFractionDigits: (e == null ? void 0 : e.minimumFractionDigits) ?? 0,
|
|
110
|
-
maximumFractionDigits: (e == null ? void 0 : e.maximumFractionDigits) ?? 2
|
|
111
|
-
}).format(r);
|
|
112
|
-
}
|
|
113
|
-
function P(r, e) {
|
|
114
|
-
if (r == null || Number.isNaN(r))
|
|
115
|
-
return "";
|
|
116
|
-
const c = e.scale === void 0 ? r : r * e.scale, i = e.negativeStyle === "parentheses" && c < 0, t = i ? Math.abs(c) : c, a = {
|
|
117
|
-
style: e.type === "number" ? "decimal" : e.type,
|
|
118
|
-
locale: e.locale,
|
|
119
|
-
currency: e.currency,
|
|
120
|
-
minimumFractionDigits: e.minimumFractionDigits,
|
|
121
|
-
maximumFractionDigits: e.maximumFractionDigits,
|
|
122
|
-
useGrouping: e.useGrouping,
|
|
123
|
-
percentValueMode: e.percentValueMode,
|
|
124
|
-
useSuffix: e.compact
|
|
125
|
-
};
|
|
126
|
-
let s;
|
|
127
|
-
switch (e.type) {
|
|
128
|
-
case "currency":
|
|
129
|
-
s = k(t, a);
|
|
130
|
-
break;
|
|
131
|
-
case "percent":
|
|
132
|
-
s = S(t, a);
|
|
133
|
-
break;
|
|
134
|
-
case "scientific":
|
|
135
|
-
s = C(t, a);
|
|
136
|
-
break;
|
|
137
|
-
default:
|
|
138
|
-
s = D(t, a);
|
|
139
|
-
break;
|
|
140
|
-
}
|
|
141
|
-
const m = `${e.prefix ?? ""}${s}${e.suffix ?? ""}`;
|
|
142
|
-
return i ? `(${m})` : m;
|
|
143
|
-
}
|
|
144
|
-
function L(r, e, c = "en-US") {
|
|
145
|
-
if (r == null || isNaN(r))
|
|
146
|
-
return "";
|
|
147
|
-
const i = h((e == null ? void 0 : e.locale) || c), t = (e == null ? void 0 : e.style) || "decimal", a = t === "decimal" ? "number" : t;
|
|
148
|
-
return a === "currency" && new Intl.NumberFormat(i, {
|
|
149
|
-
style: "currency",
|
|
150
|
-
currency: (e == null ? void 0 : e.currency) || "USD"
|
|
151
|
-
}), P(r, {
|
|
152
|
-
type: a,
|
|
153
|
-
locale: i,
|
|
154
|
-
currency: a === "currency" ? (e == null ? void 0 : e.currency) || "USD" : void 0,
|
|
155
|
-
minimumFractionDigits: (e == null ? void 0 : e.minimumFractionDigits) ?? 0,
|
|
156
|
-
maximumFractionDigits: (e == null ? void 0 : e.maximumFractionDigits) ?? 2,
|
|
157
|
-
useGrouping: (e == null ? void 0 : e.useGrouping) ?? !0,
|
|
158
|
-
percentValueMode: a === "percent" ? (e == null ? void 0 : e.percentValueMode) ?? "whole" : void 0,
|
|
159
|
-
scale: e == null ? void 0 : e.scale,
|
|
160
|
-
compact: e == null ? void 0 : e.compact,
|
|
161
|
-
negativeStyle: e == null ? void 0 : e.negativeStyle,
|
|
162
|
-
prefix: e == null ? void 0 : e.prefix,
|
|
163
|
-
suffix: e == null ? void 0 : e.suffix
|
|
164
|
-
});
|
|
165
|
-
}
|
|
166
|
-
function T(r, e, c) {
|
|
167
|
-
const i = {
|
|
168
|
-
style: e === "currency" ? "currency" : e === "percent" ? "percent" : "decimal",
|
|
169
|
-
locale: c == null ? void 0 : c.locale,
|
|
170
|
-
currency: c == null ? void 0 : c.currency,
|
|
171
|
-
minimumFractionDigits: c == null ? void 0 : c.decimalPlaces,
|
|
172
|
-
maximumFractionDigits: c == null ? void 0 : c.decimalPlaces,
|
|
173
|
-
useSuffix: c == null ? void 0 : c.useSuffix,
|
|
174
|
-
prefix: c == null ? void 0 : c.prefix,
|
|
175
|
-
suffix: c == null ? void 0 : c.suffix,
|
|
176
|
-
negativeInParentheses: c == null ? void 0 : c.negativeInParentheses,
|
|
177
|
-
multiplyBy: c == null ? void 0 : c.multiplyBy
|
|
178
|
-
};
|
|
179
|
-
switch (e) {
|
|
180
|
-
case "currency":
|
|
181
|
-
return k(r, i);
|
|
182
|
-
case "percent":
|
|
183
|
-
return S(r, i);
|
|
184
|
-
case "scientific":
|
|
185
|
-
return C(r, i);
|
|
186
|
-
default:
|
|
187
|
-
return D(r, i);
|
|
188
|
-
}
|
|
189
|
-
}
|
|
190
|
-
const V = [
|
|
191
|
-
"type",
|
|
192
|
-
"locale",
|
|
193
|
-
"minimumFractionDigits",
|
|
194
|
-
"maximumFractionDigits",
|
|
195
|
-
"useGrouping",
|
|
196
|
-
"prefix",
|
|
197
|
-
"suffix",
|
|
198
|
-
"negativeStyle",
|
|
199
|
-
"compact",
|
|
200
|
-
"scale",
|
|
201
|
-
"currency",
|
|
202
|
-
"percentValueMode"
|
|
203
|
-
];
|
|
204
|
-
function x(r) {
|
|
205
|
-
if (r === null || typeof r != "object" || Array.isArray(r))
|
|
206
|
-
return !1;
|
|
207
|
-
const e = Object.getPrototypeOf(r);
|
|
208
|
-
return e === null || e === Object.prototype;
|
|
209
|
-
}
|
|
210
|
-
function b(r) {
|
|
211
|
-
if (!x(r))
|
|
212
|
-
return {
|
|
213
|
-
ok: !1,
|
|
214
|
-
issues: [{ path: "$", message: "Numeric format must be an object." }]
|
|
215
|
-
};
|
|
216
|
-
const e = [], c = new Set(V);
|
|
217
|
-
Object.keys(r).filter((a) => !c.has(a)).forEach(
|
|
218
|
-
(a) => e.push({ path: a, message: `Unknown property "${a}".` })
|
|
219
|
-
), r.type !== "number" && r.type !== "currency" && r.type !== "percent" && r.type !== "scientific" && e.push({
|
|
220
|
-
path: "type",
|
|
221
|
-
message: "Expected number, currency, percent, or scientific."
|
|
222
|
-
});
|
|
223
|
-
const i = r.locale === void 0 ? void 0 : I(r.locale);
|
|
224
|
-
r.locale !== void 0 && !i && e.push({ path: "locale", message: "Expected a supported BCP 47 locale." });
|
|
225
|
-
const t = r.currency === void 0 ? void 0 : o(r.currency);
|
|
226
|
-
r.currency !== void 0 && !t && e.push({
|
|
227
|
-
path: "currency",
|
|
228
|
-
message: "Expected a supported ISO 4217 currency code."
|
|
229
|
-
});
|
|
230
|
-
for (const a of ["minimumFractionDigits", "maximumFractionDigits"]) {
|
|
231
|
-
const s = r[a];
|
|
232
|
-
s !== void 0 && (!Number.isInteger(s) || typeof s != "number" || s < 0 || s > 20) && e.push({
|
|
233
|
-
path: a,
|
|
234
|
-
message: "Expected an integer from 0 to 20."
|
|
235
|
-
});
|
|
236
|
-
}
|
|
237
|
-
typeof r.minimumFractionDigits == "number" && typeof r.maximumFractionDigits == "number" && r.minimumFractionDigits > r.maximumFractionDigits && e.push({
|
|
238
|
-
path: "maximumFractionDigits",
|
|
239
|
-
message: "Must be greater than or equal to minimumFractionDigits."
|
|
240
|
-
});
|
|
241
|
-
for (const a of ["useGrouping", "compact"])
|
|
242
|
-
r[a] !== void 0 && typeof r[a] != "boolean" && e.push({ path: a, message: "Expected a boolean." });
|
|
243
|
-
for (const a of ["prefix", "suffix"])
|
|
244
|
-
r[a] !== void 0 && typeof r[a] != "string" && e.push({ path: a, message: "Expected a string." });
|
|
245
|
-
return r.negativeStyle !== void 0 && r.negativeStyle !== "minus" && r.negativeStyle !== "parentheses" && e.push({
|
|
246
|
-
path: "negativeStyle",
|
|
247
|
-
message: "Expected minus or parentheses."
|
|
248
|
-
}), r.percentValueMode !== void 0 && r.percentValueMode !== "fraction" && r.percentValueMode !== "whole" && e.push({
|
|
249
|
-
path: "percentValueMode",
|
|
250
|
-
message: "Expected fraction or whole."
|
|
251
|
-
}), r.scale !== void 0 && (typeof r.scale != "number" || !Number.isFinite(r.scale)) && e.push({ path: "scale", message: "Expected a finite number." }), e.length > 0 ? { ok: !1, issues: e } : {
|
|
252
|
-
ok: !0,
|
|
253
|
-
value: {
|
|
254
|
-
type: r.type,
|
|
255
|
-
...i ? { locale: i } : {},
|
|
256
|
-
...r.minimumFractionDigits !== void 0 ? { minimumFractionDigits: r.minimumFractionDigits } : {},
|
|
257
|
-
...r.maximumFractionDigits !== void 0 ? { maximumFractionDigits: r.maximumFractionDigits } : {},
|
|
258
|
-
...r.useGrouping !== void 0 ? { useGrouping: r.useGrouping } : {},
|
|
259
|
-
...r.prefix !== void 0 ? { prefix: r.prefix } : {},
|
|
260
|
-
...r.suffix !== void 0 ? { suffix: r.suffix } : {},
|
|
261
|
-
...r.negativeStyle !== void 0 ? {
|
|
262
|
-
negativeStyle: r.negativeStyle
|
|
263
|
-
} : {},
|
|
264
|
-
...r.compact !== void 0 ? { compact: r.compact } : {},
|
|
265
|
-
...r.scale !== void 0 ? { scale: r.scale } : {},
|
|
266
|
-
...t ? { currency: t } : {},
|
|
267
|
-
...r.percentValueMode !== void 0 ? {
|
|
268
|
-
percentValueMode: r.percentValueMode
|
|
269
|
-
} : {}
|
|
270
|
-
}
|
|
271
|
-
};
|
|
272
|
-
}
|
|
273
|
-
function j(r) {
|
|
274
|
-
const e = b(r);
|
|
275
|
-
if (!e.ok)
|
|
276
|
-
return e;
|
|
277
|
-
const c = [];
|
|
278
|
-
return e.value.locale || c.push({
|
|
279
|
-
path: "locale",
|
|
280
|
-
message: "Resolved numeric formats require an explicit locale."
|
|
281
|
-
}), e.value.minimumFractionDigits === void 0 && c.push({
|
|
282
|
-
path: "minimumFractionDigits",
|
|
283
|
-
message: "Resolved numeric formats require minimumFractionDigits."
|
|
284
|
-
}), e.value.maximumFractionDigits === void 0 && c.push({
|
|
285
|
-
path: "maximumFractionDigits",
|
|
286
|
-
message: "Resolved numeric formats require maximumFractionDigits."
|
|
287
|
-
}), e.value.type === "currency" && !e.value.currency && c.push({
|
|
288
|
-
path: "currency",
|
|
289
|
-
message: "Resolved currency formats require an explicit currency."
|
|
290
|
-
}), c.length > 0 ? { ok: !1, issues: c } : e;
|
|
291
|
-
}
|
|
292
|
-
function O(r) {
|
|
293
|
-
if (!Array.isArray(r))
|
|
294
|
-
throw new Error("resolvedNumericFormats must be an array");
|
|
295
|
-
const e = /* @__PURE__ */ new Set();
|
|
296
|
-
return r.map((c, i) => {
|
|
297
|
-
var w;
|
|
298
|
-
if (!x(c))
|
|
299
|
-
throw new Error(`resolvedNumericFormats.${i} must be an object`);
|
|
300
|
-
const t = /* @__PURE__ */ new Set(["scope", "target", "format"]), a = Object.keys(c).find(
|
|
301
|
-
(f) => !t.has(f)
|
|
302
|
-
);
|
|
303
|
-
if (a)
|
|
304
|
-
throw new Error(
|
|
305
|
-
`resolvedNumericFormats.${i} contains unknown property "${a}"`
|
|
306
|
-
);
|
|
307
|
-
if (!x(c.scope))
|
|
308
|
-
throw new Error(`resolvedNumericFormats.${i}.scope must be an object`);
|
|
309
|
-
const s = /* @__PURE__ */ new Set(["dashboardId", "cardId", "attachmentIndex"]), m = Object.keys(c.scope).find(
|
|
310
|
-
(f) => !s.has(f)
|
|
311
|
-
);
|
|
312
|
-
if (m)
|
|
313
|
-
throw new Error(
|
|
314
|
-
`resolvedNumericFormats.${i}.scope contains unknown property "${m}"`
|
|
315
|
-
);
|
|
316
|
-
const l = typeof c.scope.dashboardId == "string" ? c.scope.dashboardId.trim() : "";
|
|
317
|
-
if (!l)
|
|
318
|
-
throw new Error(
|
|
319
|
-
`resolvedNumericFormats.${i}.scope.dashboardId is required`
|
|
320
|
-
);
|
|
321
|
-
if (c.scope.cardId !== void 0 && (typeof c.scope.cardId != "string" || !c.scope.cardId.trim()))
|
|
322
|
-
throw new Error(
|
|
323
|
-
`resolvedNumericFormats.${i}.scope.cardId must be a non-empty string`
|
|
324
|
-
);
|
|
325
|
-
const d = typeof c.scope.cardId == "string" ? c.scope.cardId.trim() : void 0, u = c.scope.attachmentIndex;
|
|
326
|
-
if (u !== void 0 && (!Number.isInteger(u) || typeof u != "number" || u < 0))
|
|
327
|
-
throw new Error(
|
|
328
|
-
`resolvedNumericFormats.${i}.scope.attachmentIndex must be a non-negative integer`
|
|
329
|
-
);
|
|
330
|
-
if (!x(c.target))
|
|
331
|
-
throw new Error(`resolvedNumericFormats.${i}.target must be an object`);
|
|
332
|
-
let n;
|
|
333
|
-
if (c.target.kind === "metric" && typeof c.target.metricId == "string" && c.target.metricId.trim()) {
|
|
334
|
-
const f = Object.keys(c.target).find(
|
|
335
|
-
(g) => g !== "kind" && g !== "metricId"
|
|
336
|
-
);
|
|
337
|
-
if (f)
|
|
338
|
-
throw new Error(
|
|
339
|
-
`resolvedNumericFormats.${i}.target contains unknown property "${f}"`
|
|
340
|
-
);
|
|
341
|
-
n = { kind: "metric", metricId: c.target.metricId.trim() };
|
|
342
|
-
} else if (c.target.kind === "column" && typeof c.target.columnKey == "string" && c.target.columnKey.trim()) {
|
|
343
|
-
const f = Object.keys(c.target).find(
|
|
344
|
-
(g) => g !== "kind" && g !== "columnKey"
|
|
345
|
-
);
|
|
346
|
-
if (f)
|
|
347
|
-
throw new Error(
|
|
348
|
-
`resolvedNumericFormats.${i}.target contains unknown property "${f}"`
|
|
349
|
-
);
|
|
350
|
-
n = { kind: "column", columnKey: c.target.columnKey.trim() };
|
|
351
|
-
} else if (c.target.kind === "matrix_measure" && typeof c.target.measureId == "string" && c.target.measureId.trim()) {
|
|
352
|
-
const f = Object.keys(c.target).find(
|
|
353
|
-
(g) => g !== "kind" && g !== "measureId"
|
|
354
|
-
);
|
|
355
|
-
if (f)
|
|
356
|
-
throw new Error(
|
|
357
|
-
`resolvedNumericFormats.${i}.target contains unknown property "${f}"`
|
|
358
|
-
);
|
|
359
|
-
n = {
|
|
360
|
-
kind: "matrix_measure",
|
|
361
|
-
measureId: c.target.measureId.trim()
|
|
362
|
-
};
|
|
363
|
-
} else
|
|
364
|
-
throw new Error(
|
|
365
|
-
`resolvedNumericFormats.${i}.target is not a valid structured target`
|
|
366
|
-
);
|
|
367
|
-
const y = j(c.format);
|
|
368
|
-
if (!y.ok)
|
|
369
|
-
throw new Error(
|
|
370
|
-
`resolvedNumericFormats.${i}.format is invalid: ${((w = y.issues[0]) == null ? void 0 : w.message) ?? "invalid value"}`
|
|
371
|
-
);
|
|
372
|
-
const M = n.kind === "metric" ? n.metricId : n.kind === "column" ? n.columnKey : n.measureId, N = JSON.stringify([
|
|
373
|
-
l,
|
|
374
|
-
d ?? null,
|
|
375
|
-
u ?? null,
|
|
376
|
-
n.kind,
|
|
377
|
-
M
|
|
378
|
-
]);
|
|
379
|
-
if (e.has(N))
|
|
380
|
-
throw new Error(
|
|
381
|
-
`resolvedNumericFormats.${i} duplicates a scoped presentation target`
|
|
382
|
-
);
|
|
383
|
-
return e.add(N), {
|
|
384
|
-
scope: {
|
|
385
|
-
dashboardId: l,
|
|
386
|
-
...d ? { cardId: d } : {},
|
|
387
|
-
...typeof u == "number" ? { attachmentIndex: u } : {}
|
|
388
|
-
},
|
|
389
|
-
target: n,
|
|
390
|
-
format: y.value
|
|
391
|
-
};
|
|
392
|
-
});
|
|
393
|
-
}
|
|
394
|
-
function q(r) {
|
|
395
|
-
var i;
|
|
396
|
-
const e = /* @__PURE__ */ new Set();
|
|
397
|
-
if (r.entries.forEach((t, a) => {
|
|
398
|
-
if (t.scope.attachmentIndex !== void 0)
|
|
399
|
-
throw new Error(
|
|
400
|
-
`resolvedNumericFormats.${a}.scope.attachmentIndex is not valid for a card export`
|
|
401
|
-
);
|
|
402
|
-
if (t.scope.dashboardId !== r.expectedScope.dashboardId || t.scope.cardId !== r.expectedScope.cardId)
|
|
403
|
-
throw new Error(
|
|
404
|
-
`resolvedNumericFormats.${a}.scope must match the executing dashboard/card`
|
|
405
|
-
);
|
|
406
|
-
if (t.target.kind !== "column")
|
|
407
|
-
throw new Error(
|
|
408
|
-
`resolvedNumericFormats.${a}.target must identify an export column`
|
|
409
|
-
);
|
|
410
|
-
if (e.has(t.target.columnKey))
|
|
411
|
-
throw new Error(
|
|
412
|
-
`resolvedNumericFormats.${a} duplicates export column "${t.target.columnKey}"`
|
|
413
|
-
);
|
|
414
|
-
e.add(t.target.columnKey);
|
|
415
|
-
}), !r.useFormattedValues)
|
|
416
|
-
return;
|
|
417
|
-
if (!((i = r.visibleColumns) != null && i.length))
|
|
418
|
-
throw new Error(
|
|
419
|
-
"visibleColumns must identify every formatted export column"
|
|
420
|
-
);
|
|
421
|
-
const c = r.visibleColumns.find(
|
|
422
|
-
(t) => !e.has(t)
|
|
423
|
-
);
|
|
424
|
-
if (c)
|
|
425
|
-
throw new Error(
|
|
426
|
-
`resolvedNumericFormats is missing visible export column "${c}"`
|
|
427
|
-
);
|
|
428
|
-
}
|
|
429
|
-
function A(r) {
|
|
430
|
-
if (!x(r))
|
|
431
|
-
throw new Error("numeric presentation execution snapshot must be an object");
|
|
432
|
-
const e = /* @__PURE__ */ new Set(["reportContext", "resolvedNumericFormats"]), c = Object.keys(r).find((t) => !e.has(t));
|
|
433
|
-
if (c)
|
|
434
|
-
throw new Error(
|
|
435
|
-
`numeric presentation execution snapshot contains unknown property "${c}"`
|
|
436
|
-
);
|
|
437
|
-
const i = K(r.reportContext);
|
|
438
|
-
if (!i.ok) {
|
|
439
|
-
const t = i.issues[0];
|
|
440
|
-
throw new Error(
|
|
441
|
-
`numeric presentation execution snapshot reportContext is invalid: ${t != null && t.path && t.path !== "$" ? `${t.path}: ` : ""}${(t == null ? void 0 : t.message) ?? "invalid value"}`
|
|
442
|
-
);
|
|
443
|
-
}
|
|
444
|
-
return {
|
|
445
|
-
reportContext: i.value,
|
|
446
|
-
resolvedNumericFormats: O(
|
|
447
|
-
r.resolvedNumericFormats
|
|
448
|
-
)
|
|
449
|
-
};
|
|
450
|
-
}
|
|
451
|
-
function E(r, e) {
|
|
452
|
-
const c = new Intl.NumberFormat(r, {
|
|
453
|
-
style: "currency",
|
|
454
|
-
currency: e
|
|
455
|
-
}).resolvedOptions();
|
|
456
|
-
return {
|
|
457
|
-
minimumFractionDigits: c.minimumFractionDigits,
|
|
458
|
-
maximumFractionDigits: c.maximumFractionDigits
|
|
459
|
-
};
|
|
460
|
-
}
|
|
461
|
-
function R(r) {
|
|
462
|
-
if (r.minimumFractionDigits !== void 0 || r.maximumFractionDigits !== void 0) {
|
|
463
|
-
const c = r.minimumFractionDigits ?? 0;
|
|
464
|
-
return {
|
|
465
|
-
minimumFractionDigits: c,
|
|
466
|
-
maximumFractionDigits: r.maximumFractionDigits ?? Math.max(c, 2)
|
|
467
|
-
};
|
|
468
|
-
}
|
|
469
|
-
const e = r.type === "percent" ? 1 : r.type === "scientific" ? 2 : 0;
|
|
470
|
-
return {
|
|
471
|
-
minimumFractionDigits: e,
|
|
472
|
-
maximumFractionDigits: e
|
|
473
|
-
};
|
|
474
|
-
}
|
|
475
|
-
function W(r, e, c) {
|
|
476
|
-
const i = I(r.locale) ?? e.locale, t = r.type === "number" || r.type === "currency" ? o(c) : void 0;
|
|
477
|
-
if (!(r.type === "currency" || t !== void 0))
|
|
478
|
-
return {
|
|
479
|
-
...r,
|
|
480
|
-
locale: i,
|
|
481
|
-
...R(r)
|
|
482
|
-
};
|
|
483
|
-
const s = t ?? o(r.currency) ?? e.defaultCurrency, m = E(
|
|
484
|
-
i,
|
|
485
|
-
s
|
|
486
|
-
), l = m.minimumFractionDigits ?? 0, d = m.maximumFractionDigits ?? l, u = r.minimumFractionDigits ?? Math.min(
|
|
487
|
-
l,
|
|
488
|
-
r.maximumFractionDigits ?? l
|
|
489
|
-
), n = r.maximumFractionDigits ?? Math.max(
|
|
490
|
-
u,
|
|
491
|
-
d
|
|
492
|
-
);
|
|
493
|
-
return {
|
|
494
|
-
...r,
|
|
495
|
-
type: "currency",
|
|
496
|
-
locale: i,
|
|
497
|
-
currency: s,
|
|
498
|
-
minimumFractionDigits: u,
|
|
499
|
-
maximumFractionDigits: n
|
|
500
|
-
};
|
|
501
|
-
}
|
|
502
|
-
export {
|
|
503
|
-
P as a,
|
|
504
|
-
k as b,
|
|
505
|
-
D as c,
|
|
506
|
-
T as d,
|
|
507
|
-
S as e,
|
|
508
|
-
L as f,
|
|
509
|
-
C as g,
|
|
510
|
-
A as h,
|
|
511
|
-
O as i,
|
|
512
|
-
j,
|
|
513
|
-
W as k,
|
|
514
|
-
b as p,
|
|
515
|
-
E as r,
|
|
516
|
-
q as v
|
|
517
|
-
};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";const h=require("../value-format-preferences/index.cjs"),b=require("../report-runtime-context/index.cjs");function S(r){if(!r)return!1;const e=r.toLowerCase().replace("_","-");return e==="en-in"||e.startsWith("en-in-")}function k(r,e){const c=Math.abs(r);return c>=1e12?{divisor:1e12,suffix:"T"}:c>=1e9?{divisor:1e9,suffix:"B"}:S(e)&&c>=1e7?{divisor:1e7,suffix:"Cr"}:c>=1e6?{divisor:1e6,suffix:"M"}:S(e)&&c>=1e5?{divisor:1e5,suffix:"L"}:c>=1e3?{divisor:1e3,suffix:"K"}:{divisor:1,suffix:""}}function D(r,e){try{const c=y(e);return k(r,c)}catch{return k(r,"en-US")}}function E(r){try{return new Intl.NumberFormat(r),!0}catch{return!1}}function y(r){return r&&E(r)?r:"en-US"}function v(r,e){if(r==null||isNaN(r))return"";const c=y(e==null?void 0:e.locale);let i=r;if(e!=null&&e.multiplyBy&&(i*=e.multiplyBy),e!=null&&e.useSuffix){const{divisor:a,suffix:u}=D(i,c);i=i/a;const s=new Intl.NumberFormat(c,{minimumFractionDigits:(e==null?void 0:e.minimumFractionDigits)??0,maximumFractionDigits:(e==null?void 0:e.maximumFractionDigits)??2,useGrouping:(e==null?void 0:e.useGrouping)??!0}).format(i);return`${(e==null?void 0:e.prefix)??""}${s}${u}${(e==null?void 0:e.suffix)??""}`}const t=new Intl.NumberFormat(c,{minimumFractionDigits:(e==null?void 0:e.minimumFractionDigits)??0,maximumFractionDigits:(e==null?void 0:e.maximumFractionDigits)??2,useGrouping:(e==null?void 0:e.useGrouping)??!0}).format(i);if(e!=null&&e.negativeInParentheses&&i<0){const a=t.replace("-","");return`(${(e==null?void 0:e.prefix)??""}${a}${(e==null?void 0:e.suffix)??""})`}return`${(e==null?void 0:e.prefix)??""}${t}${(e==null?void 0:e.suffix)??""}`}function N(r,e){if(r==null||isNaN(r))return"";const c=y(e==null?void 0:e.locale),i=(e==null?void 0:e.currency)||"USD",t=r<0,a=!!(e!=null&&e.negativeInParentheses&&t),u=a?Math.abs(r):r;try{if(e!=null&&e.useSuffix){const{divisor:l,suffix:d}=D(u,c),m=u/l,o=`${new Intl.NumberFormat(c,{style:"currency",currency:i,minimumFractionDigits:(e==null?void 0:e.minimumFractionDigits)??0,maximumFractionDigits:(e==null?void 0:e.maximumFractionDigits)??2,useGrouping:(e==null?void 0:e.useGrouping)??!0}).format(m)}${d}`;return a?`(${o})`:o}const s=new Intl.NumberFormat(c,{style:"currency",currency:i,minimumFractionDigits:(e==null?void 0:e.minimumFractionDigits)??0,maximumFractionDigits:(e==null?void 0:e.maximumFractionDigits)??2,useGrouping:(e==null?void 0:e.useGrouping)??!0}).format(u);return a?`(${s})`:s}catch{const s=Math.abs(r),l=e!=null&&e.useSuffix?D(s,c):{divisor:1,suffix:""},d=v(s/l.divisor,{locale:c,minimumFractionDigits:(e==null?void 0:e.minimumFractionDigits)??0,maximumFractionDigits:(e==null?void 0:e.maximumFractionDigits)??2,useGrouping:(e==null?void 0:e.useGrouping)??!0}),m=`${i} ${d}${l.suffix}`;return t?e!=null&&e.negativeInParentheses?`(${m})`:`-${m}`:m}}function F(r,e){if(r==null||isNaN(r))return"";const c=y(e==null?void 0:e.locale),t=(e==null?void 0:e.alreadyPercent)??(e==null?void 0:e.percentValueMode)==="whole"?r/100:r;return new Intl.NumberFormat(c,{style:"percent",minimumFractionDigits:(e==null?void 0:e.minimumFractionDigits)??0,maximumFractionDigits:(e==null?void 0:e.maximumFractionDigits)??2,useGrouping:(e==null?void 0:e.useGrouping)??!0}).format(t)}function w(r,e){if(r==null||isNaN(r))return"";const c=y(e==null?void 0:e.locale);return new Intl.NumberFormat(c,{notation:"scientific",minimumFractionDigits:(e==null?void 0:e.minimumFractionDigits)??0,maximumFractionDigits:(e==null?void 0:e.maximumFractionDigits)??2}).format(r)}function C(r,e){if(r==null||Number.isNaN(r))return"";const c=e.scale===void 0?r:r*e.scale,i=e.negativeStyle==="parentheses"&&c<0,t=i?Math.abs(c):c,a={style:e.type==="number"?"decimal":e.type,locale:e.locale,currency:e.currency,minimumFractionDigits:e.minimumFractionDigits,maximumFractionDigits:e.maximumFractionDigits,useGrouping:e.useGrouping,percentValueMode:e.percentValueMode,useSuffix:e.compact};let u;switch(e.type){case"currency":u=N(t,a);break;case"percent":u=F(t,a);break;case"scientific":u=w(t,a);break;default:u=v(t,a);break}const s=`${e.prefix??""}${u}${e.suffix??""}`;return i?`(${s})`:s}function j(r,e,c="en-US"){if(r==null||isNaN(r))return"";const i=y((e==null?void 0:e.locale)||c),t=(e==null?void 0:e.style)||"decimal",a=t==="decimal"?"number":t;return a==="currency"&&new Intl.NumberFormat(i,{style:"currency",currency:(e==null?void 0:e.currency)||"USD"}),C(r,{type:a,locale:i,currency:a==="currency"?(e==null?void 0:e.currency)||"USD":void 0,minimumFractionDigits:(e==null?void 0:e.minimumFractionDigits)??0,maximumFractionDigits:(e==null?void 0:e.maximumFractionDigits)??2,useGrouping:(e==null?void 0:e.useGrouping)??!0,percentValueMode:a==="percent"?(e==null?void 0:e.percentValueMode)??"whole":void 0,scale:e==null?void 0:e.scale,compact:e==null?void 0:e.compact,negativeStyle:e==null?void 0:e.negativeStyle,prefix:e==null?void 0:e.prefix,suffix:e==null?void 0:e.suffix})}function O(r,e,c){const i={style:e==="currency"?"currency":e==="percent"?"percent":"decimal",locale:c==null?void 0:c.locale,currency:c==null?void 0:c.currency,minimumFractionDigits:c==null?void 0:c.decimalPlaces,maximumFractionDigits:c==null?void 0:c.decimalPlaces,useSuffix:c==null?void 0:c.useSuffix,prefix:c==null?void 0:c.prefix,suffix:c==null?void 0:c.suffix,negativeInParentheses:c==null?void 0:c.negativeInParentheses,multiplyBy:c==null?void 0:c.multiplyBy};switch(e){case"currency":return N(r,i);case"percent":return F(r,i);case"scientific":return w(r,i);default:return v(r,i)}}const R=["type","locale","minimumFractionDigits","maximumFractionDigits","useGrouping","prefix","suffix","negativeStyle","compact","scale","currency","percentValueMode"];function x(r){if(r===null||typeof r!="object"||Array.isArray(r))return!1;const e=Object.getPrototypeOf(r);return e===null||e===Object.prototype}function M(r){if(!x(r))return{ok:!1,issues:[{path:"$",message:"Numeric format must be an object."}]};const e=[],c=new Set(R);Object.keys(r).filter(a=>!c.has(a)).forEach(a=>e.push({path:a,message:`Unknown property "${a}".`})),r.type!=="number"&&r.type!=="currency"&&r.type!=="percent"&&r.type!=="scientific"&&e.push({path:"type",message:"Expected number, currency, percent, or scientific."});const i=r.locale===void 0?void 0:h.canonicalizeSupportedLocale(r.locale);r.locale!==void 0&&!i&&e.push({path:"locale",message:"Expected a supported BCP 47 locale."});const t=r.currency===void 0?void 0:h.canonicalizeSupportedCurrencyCode(r.currency);r.currency!==void 0&&!t&&e.push({path:"currency",message:"Expected a supported ISO 4217 currency code."});for(const a of["minimumFractionDigits","maximumFractionDigits"]){const u=r[a];u!==void 0&&(!Number.isInteger(u)||typeof u!="number"||u<0||u>20)&&e.push({path:a,message:"Expected an integer from 0 to 20."})}typeof r.minimumFractionDigits=="number"&&typeof r.maximumFractionDigits=="number"&&r.minimumFractionDigits>r.maximumFractionDigits&&e.push({path:"maximumFractionDigits",message:"Must be greater than or equal to minimumFractionDigits."});for(const a of["useGrouping","compact"])r[a]!==void 0&&typeof r[a]!="boolean"&&e.push({path:a,message:"Expected a boolean."});for(const a of["prefix","suffix"])r[a]!==void 0&&typeof r[a]!="string"&&e.push({path:a,message:"Expected a string."});return r.negativeStyle!==void 0&&r.negativeStyle!=="minus"&&r.negativeStyle!=="parentheses"&&e.push({path:"negativeStyle",message:"Expected minus or parentheses."}),r.percentValueMode!==void 0&&r.percentValueMode!=="fraction"&&r.percentValueMode!=="whole"&&e.push({path:"percentValueMode",message:"Expected fraction or whole."}),r.scale!==void 0&&(typeof r.scale!="number"||!Number.isFinite(r.scale))&&e.push({path:"scale",message:"Expected a finite number."}),e.length>0?{ok:!1,issues:e}:{ok:!0,value:{type:r.type,...i?{locale:i}:{},...r.minimumFractionDigits!==void 0?{minimumFractionDigits:r.minimumFractionDigits}:{},...r.maximumFractionDigits!==void 0?{maximumFractionDigits:r.maximumFractionDigits}:{},...r.useGrouping!==void 0?{useGrouping:r.useGrouping}:{},...r.prefix!==void 0?{prefix:r.prefix}:{},...r.suffix!==void 0?{suffix:r.suffix}:{},...r.negativeStyle!==void 0?{negativeStyle:r.negativeStyle}:{},...r.compact!==void 0?{compact:r.compact}:{},...r.scale!==void 0?{scale:r.scale}:{},...t?{currency:t}:{},...r.percentValueMode!==void 0?{percentValueMode:r.percentValueMode}:{}}}}function P(r){const e=M(r);if(!e.ok)return e;const c=[];return e.value.locale||c.push({path:"locale",message:"Resolved numeric formats require an explicit locale."}),e.value.minimumFractionDigits===void 0&&c.push({path:"minimumFractionDigits",message:"Resolved numeric formats require minimumFractionDigits."}),e.value.maximumFractionDigits===void 0&&c.push({path:"maximumFractionDigits",message:"Resolved numeric formats require maximumFractionDigits."}),e.value.type==="currency"&&!e.value.currency&&c.push({path:"currency",message:"Resolved currency formats require an explicit currency."}),c.length>0?{ok:!1,issues:c}:e}function K(r){if(!Array.isArray(r))throw new Error("resolvedNumericFormats must be an array");const e=new Set;return r.map((c,i)=>{var I;if(!x(c))throw new Error(`resolvedNumericFormats.${i} must be an object`);const t=new Set(["scope","target","format"]),a=Object.keys(c).find(f=>!t.has(f));if(a)throw new Error(`resolvedNumericFormats.${i} contains unknown property "${a}"`);if(!x(c.scope))throw new Error(`resolvedNumericFormats.${i}.scope must be an object`);const u=new Set(["dashboardId","cardId","attachmentIndex"]),s=Object.keys(c.scope).find(f=>!u.has(f));if(s)throw new Error(`resolvedNumericFormats.${i}.scope contains unknown property "${s}"`);const l=typeof c.scope.dashboardId=="string"?c.scope.dashboardId.trim():"";if(!l)throw new Error(`resolvedNumericFormats.${i}.scope.dashboardId is required`);if(c.scope.cardId!==void 0&&(typeof c.scope.cardId!="string"||!c.scope.cardId.trim()))throw new Error(`resolvedNumericFormats.${i}.scope.cardId must be a non-empty string`);const d=typeof c.scope.cardId=="string"?c.scope.cardId.trim():void 0,m=c.scope.attachmentIndex;if(m!==void 0&&(!Number.isInteger(m)||typeof m!="number"||m<0))throw new Error(`resolvedNumericFormats.${i}.scope.attachmentIndex must be a non-negative integer`);if(!x(c.target))throw new Error(`resolvedNumericFormats.${i}.target must be an object`);let n;if(c.target.kind==="metric"&&typeof c.target.metricId=="string"&&c.target.metricId.trim()){const f=Object.keys(c.target).find(g=>g!=="kind"&&g!=="metricId");if(f)throw new Error(`resolvedNumericFormats.${i}.target contains unknown property "${f}"`);n={kind:"metric",metricId:c.target.metricId.trim()}}else if(c.target.kind==="column"&&typeof c.target.columnKey=="string"&&c.target.columnKey.trim()){const f=Object.keys(c.target).find(g=>g!=="kind"&&g!=="columnKey");if(f)throw new Error(`resolvedNumericFormats.${i}.target contains unknown property "${f}"`);n={kind:"column",columnKey:c.target.columnKey.trim()}}else if(c.target.kind==="matrix_measure"&&typeof c.target.measureId=="string"&&c.target.measureId.trim()){const f=Object.keys(c.target).find(g=>g!=="kind"&&g!=="measureId");if(f)throw new Error(`resolvedNumericFormats.${i}.target contains unknown property "${f}"`);n={kind:"matrix_measure",measureId:c.target.measureId.trim()}}else throw new Error(`resolvedNumericFormats.${i}.target is not a valid structured target`);const o=P(c.format);if(!o.ok)throw new Error(`resolvedNumericFormats.${i}.format is invalid: ${((I=o.issues[0])==null?void 0:I.message)??"invalid value"}`);const V=n.kind==="metric"?n.metricId:n.kind==="column"?n.columnKey:n.measureId,$=JSON.stringify([l,d??null,m??null,n.kind,V]);if(e.has($))throw new Error(`resolvedNumericFormats.${i} duplicates a scoped presentation target`);return e.add($),{scope:{dashboardId:l,...d?{cardId:d}:{},...typeof m=="number"?{attachmentIndex:m}:{}},target:n,format:o.value}})}function B(r){var i;const e=new Set;if(r.entries.forEach((t,a)=>{if(t.scope.attachmentIndex!==void 0)throw new Error(`resolvedNumericFormats.${a}.scope.attachmentIndex is not valid for a card export`);if(t.scope.dashboardId!==r.expectedScope.dashboardId||t.scope.cardId!==r.expectedScope.cardId)throw new Error(`resolvedNumericFormats.${a}.scope must match the executing dashboard/card`);if(t.target.kind!=="column")throw new Error(`resolvedNumericFormats.${a}.target must identify an export column`);if(e.has(t.target.columnKey))throw new Error(`resolvedNumericFormats.${a} duplicates export column "${t.target.columnKey}"`);e.add(t.target.columnKey)}),!r.useFormattedValues)return;if(!((i=r.visibleColumns)!=null&&i.length))throw new Error("visibleColumns must identify every formatted export column");const c=r.visibleColumns.find(t=>!e.has(t));if(c)throw new Error(`resolvedNumericFormats is missing visible export column "${c}"`)}function q(r){if(!x(r))throw new Error("numeric presentation execution snapshot must be an object");const e=new Set(["reportContext","resolvedNumericFormats"]),c=Object.keys(r).find(t=>!e.has(t));if(c)throw new Error(`numeric presentation execution snapshot contains unknown property "${c}"`);const i=b.parseReportRuntimeContext(r.reportContext);if(!i.ok){const t=i.issues[0];throw new Error(`numeric presentation execution snapshot reportContext is invalid: ${t!=null&&t.path&&t.path!=="$"?`${t.path}: `:""}${(t==null?void 0:t.message)??"invalid value"}`)}return{reportContext:i.value,resolvedNumericFormats:K(r.resolvedNumericFormats)}}function G(r,e){const c=new Intl.NumberFormat(r,{style:"currency",currency:e}).resolvedOptions();return{minimumFractionDigits:c.minimumFractionDigits,maximumFractionDigits:c.maximumFractionDigits}}function L(r){if(r.minimumFractionDigits!==void 0||r.maximumFractionDigits!==void 0){const c=r.minimumFractionDigits??0;return{minimumFractionDigits:c,maximumFractionDigits:r.maximumFractionDigits??Math.max(c,2)}}const e=r.type==="percent"?1:r.type==="scientific"?2:0;return{minimumFractionDigits:e,maximumFractionDigits:e}}function U(r,e,c){const i=h.canonicalizeSupportedLocale(r.locale)??e.locale,t=r.type==="number"||r.type==="currency"?h.canonicalizeSupportedCurrencyCode(c):void 0;if(!(r.type==="currency"||t!==void 0))return{...r,locale:i,...L(r)};const u=t??h.canonicalizeSupportedCurrencyCode(r.currency)??e.defaultCurrency,s=G(i,u),l=s.minimumFractionDigits??0,d=s.maximumFractionDigits??l,m=r.minimumFractionDigits??Math.min(l,r.maximumFractionDigits??l),n=r.maximumFractionDigits??Math.max(m,d);return{...r,type:"currency",locale:i,currency:u,minimumFractionDigits:m,maximumFractionDigits:n}}exports.formatCurrency=N;exports.formatNumber=v;exports.formatNumberCustom=O;exports.formatNumberWithColumnSettings=j;exports.formatNumericCanonical=C;exports.formatPercent=F;exports.formatScientific=w;exports.parseNumericCanonicalFormat=M;exports.parseNumericPresentationExecutionSnapshot=q;exports.parseNumericPresentationSnapshotEntries=K;exports.parseResolvedNumericCanonicalFormat=P;exports.resolveCurrencyFractionDigits=G;exports.resolveNumericPresentation=U;exports.validateCardExportNumericPresentationSnapshot=B;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";const e=require("react/jsx-runtime"),l=require("react"),n=require("./dashboard-cB3xmTNn.js"),o=require("./code-editor-M7HTUhdF.js"),V=require("../report-runtime-context/index.cjs");require("./index-jSrCwPQz.js");require("./analyze-result-contract-BswhsmWT.js");const D=require("../value-format-preferences/index.cjs");function M(s={}){const{authToken:i,tokenProps:a}=n.useSemaphorContext(),p=o.useDashboardStore(C=>C.actions.applyResolvedCalendarPreferences),d=s.enabled??!0,c=(i==null?void 0:i.accessToken)??null,m=(a==null?void 0:a.apiServiceUrl)??null,[v,b]=l.useState(!1),[g,j]=l.useState(!1),[y,k]=l.useState(!1),[T,f]=l.useState(null),[N,P]=l.useState(null),h=l.useRef(c);h.current=c,l.useEffect(()=>{P(null),f(null),b(!1),j(!1),k(!1)},[c]);const w=l.useCallback(async C=>{const r=V.parseCalendarPreferencesResponse(await C.json());if(!r.ok)throw new Error("Calendar preferences response is invalid");return r.value},[]),S=l.useCallback(async()=>{if(!d||!c||!m)return;const C=c;b(!0),f(null);try{const r=await fetch(`${m}/v1/user-preferences/calendar`,{method:"GET",headers:{Authorization:`Bearer ${c}`}});if(!r.ok){const x=await r.json().catch(()=>({}));throw new Error(x.error||"Failed to fetch preferences")}const t=await w(r);h.current===C&&P(t)}catch(r){h.current===C&&f(r instanceof Error?r.message:"Unknown error")}finally{h.current===C&&b(!1)}},[c,m,d,w]);l.useEffect(()=>{d&&S()},[d,S]);const E=l.useCallback(async C=>{if(!c||!m)return f("Not authenticated"),!1;const r=c;j(!0),f(null);try{const t=await fetch(`${m}/v1/user-preferences/calendar`,{method:"PATCH",headers:{"Content-Type":"application/json",Authorization:`Bearer ${c}`},body:JSON.stringify(C)});if(!t.ok){const z=await t.json().catch(()=>({}));throw new Error(z.error||"Failed to update preferences")}const x=await w(t);return h.current!==r?!1:(P(x),p(x.resolved,x.sources),!0)}catch(t){return h.current===r&&f(t instanceof Error?t.message:"Unknown error"),!1}finally{h.current===r&&j(!1)}},[c,m,p,w]),A=l.useCallback(async()=>{if(!c||!m)return f("Not authenticated"),!1;const C=c;k(!0),f(null);try{const r=await fetch(`${m}/v1/user-preferences/calendar`,{method:"DELETE",headers:{Authorization:`Bearer ${c}`}});if(!r.ok){const x=await r.json().catch(()=>({}));throw new Error(x.error||"Failed to clear preferences")}const t=await w(r);return h.current!==C?!1:(P(t),p(t.resolved,t.sources),!0)}catch(r){return h.current===C&&f(r instanceof Error?r.message:"Unknown error"),!1}finally{h.current===C&&k(!1)}},[c,m,p,w]);return{preferences:N,isLoading:v,isSaving:g,isClearing:y,error:T,updatePreferences:E,clearPreferences:A,refetch:S}}const F=[{value:"America/New_York",label:"Eastern Time (US & Canada)"},{value:"America/Chicago",label:"Central Time (US & Canada)"},{value:"America/Denver",label:"Mountain Time (US & Canada)"},{value:"America/Los_Angeles",label:"Pacific Time (US & Canada)"},{value:"America/Phoenix",label:"Arizona"},{value:"America/Anchorage",label:"Alaska"},{value:"Pacific/Honolulu",label:"Hawaii"},{value:"Europe/London",label:"London"},{value:"Europe/Paris",label:"Paris, Berlin, Rome"},{value:"Asia/Tokyo",label:"Tokyo"},{value:"Asia/Shanghai",label:"Beijing, Shanghai"},{value:"Asia/Kolkata",label:"Mumbai, New Delhi"},{value:"Australia/Sydney",label:"Sydney"},{value:"UTC",label:"UTC"}],I=[{value:0,label:"Sunday"},{value:1,label:"Monday"},{value:6,label:"Saturday"}],R="text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground";function _(){try{const s=Intl;if(s.supportedValuesOf)return s.supportedValuesOf("timeZone")}catch{}return F.map(s=>s.value)}function G(s){if(!s)return"default";if(s.tz!==s.weekStart)return"inherited";switch(s.tz){case"viewer_tenant":return"tenant";case"viewer_organization":return"organization";case"system_default":return"system";case"session_initial":return"embedded";default:return"default"}}function U(s){const i=F.find(a=>a.value===s);return i?i.label:s}function W(s){const i=I.find(a=>a.value===s);return i?i.label:String(s)}function H({active:s,onClose:i}){const{preferences:a,isLoading:p,isSaving:d,isClearing:c,updatePreferences:m,clearPreferences:v}=M({enabled:s}),b=n.useCalendarContext(),g=(a==null?void 0:a.resolved.tz)||(b==null?void 0:b.tz)||"UTC",j=(a==null?void 0:a.resolved.weekStart)??(b==null?void 0:b.weekStart)??1,[y,k]=l.useState((a==null?void 0:a.stored)===null),[T,f]=l.useState(!1),[N,P]=l.useState(g),[h,w]=l.useState(j),[S,E]=l.useState(!1),A=l.useMemo(()=>_(),[]),C=l.useMemo(()=>A.filter(u=>!F.some($=>$.value===u)),[A]),r=l.useMemo(()=>U(N),[N]),t=a!=null&&a.inherited?U(a.inherited.tz):"UTC",x=a!=null&&a.inherited?W(a.inherited.weekStart):"Monday",z=G(a==null?void 0:a.inheritedSources);l.useEffect(()=>{if(!s){f(!1);return}T||(a&&k(a.stored===null),P(g),w(j))},[s,T,a,g,j]);const B=async()=>{if(p){n.ue.error("Preferences are still loading. Please try again.");return}y?await v()?(n.ue.success("Now using default settings."),i()):n.ue.error("Failed to save preferences. Please try again."):await m({tz:N,weekStart:h})?(n.ue.success("Preferences saved."),i()):n.ue.error("Failed to save preferences. Please try again.")},q=()=>{i()},L=d||c,O=L||p;return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"space-y-4 py-1",children:[e.jsxs(n.RadioGroup,{value:y?"defaults":"custom",onValueChange:u=>{f(!0),k(u==="defaults")},className:"space-y-0.5",children:[e.jsxs("label",{htmlFor:"mode-defaults",className:o.cn("flex cursor-pointer items-start gap-2 rounded-control px-2 py-1.5 hover:bg-muted/50",y&&"bg-muted/50"),onClick:()=>{f(!0),k(!0)},children:[e.jsx(n.RadioGroupItem,{value:"defaults",id:"mode-defaults",className:"mt-0.5"}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("p",{className:"text-[13px] font-medium text-foreground",children:["Use ",z," defaults"]}),e.jsxs("p",{className:"text-[12px] text-muted-foreground",children:[t,", week starts ",x]})]})]}),e.jsxs("label",{htmlFor:"mode-custom",className:o.cn("flex cursor-pointer items-start gap-2 rounded-control px-2 py-1.5 hover:bg-muted/50",!y&&"bg-muted/50"),onClick:()=>{f(!0),k(!1)},children:[e.jsx(n.RadioGroupItem,{value:"custom",id:"mode-custom",className:"mt-0.5"}),e.jsx("p",{className:"flex-1 text-[13px] font-medium text-foreground",children:"Use custom settings"})]})]}),e.jsxs("div",{className:o.cn("space-y-4 border-t border-border/60 pt-4 transition-opacity",y&&"pointer-events-none opacity-50"),children:[e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(o.Label,{className:R,children:"Timezone"}),e.jsxs(o.Popover,{open:S,onOpenChange:E,modal:!0,children:[e.jsx(o.PopoverTrigger,{asChild:!0,children:e.jsxs(o.Button,{variant:"outline",size:"xs",role:"combobox","aria-expanded":S,className:"w-full justify-between text-[12px] font-normal",disabled:y,children:[e.jsx("span",{className:"truncate",children:r}),e.jsx(n.ChevronsUpDown,{className:"ml-2 h-3.5 w-3.5 shrink-0 opacity-50"})]})}),e.jsx(o.PopoverContent,{className:"z-50 w-[--radix-popover-trigger-width] p-0",align:"start",children:e.jsxs(n.Command,{className:"overflow-visible",children:[e.jsx(n.CommandInput,{placeholder:"Search timezones…"}),e.jsxs(n.CommandList,{children:[e.jsx(n.CommandEmpty,{children:"No timezone found."}),e.jsx(n.CommandGroup,{heading:"Common",children:F.map(u=>e.jsxs(n.CommandItem,{value:`${u.value} ${u.label}`,onSelect:()=>{f(!0),P(u.value),E(!1)},children:[e.jsx(o.Check,{className:o.cn("h-3.5 w-3.5",N===u.value?"opacity-100":"opacity-0")}),e.jsx("span",{className:"flex-1",children:u.label}),e.jsx("span",{className:"text-[11px] text-muted-foreground",children:u.value})]},u.value))}),e.jsx(n.CommandSeparator,{}),e.jsx(n.CommandGroup,{heading:"All timezones",children:C.map(u=>e.jsxs(n.CommandItem,{value:u,onSelect:()=>{f(!0),P(u),E(!1)},children:[e.jsx(o.Check,{className:o.cn("h-3.5 w-3.5",N===u?"opacity-100":"opacity-0")}),u]},u))})]})]})})]})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(o.Label,{className:R,children:"Week starts on"}),e.jsx(n.RadioGroup,{value:String(h),onValueChange:u=>{f(!0),w(Number(u))},className:"flex gap-4",disabled:y,children:I.map(u=>e.jsxs("label",{htmlFor:`week-start-${u.value}`,className:o.cn("flex cursor-pointer items-center gap-2 text-[13px]",y&&"cursor-not-allowed"),children:[e.jsx(n.RadioGroupItem,{value:String(u.value),id:`week-start-${u.value}`,disabled:y}),u.label]},u.value))})]})]})]}),e.jsxs(n.DialogFooter,{children:[e.jsx(o.Button,{variant:"outline",size:"xs",onClick:q,disabled:L,children:"Cancel"}),e.jsx(o.Button,{size:"xs",onClick:B,disabled:O,children:L?e.jsxs(e.Fragment,{children:[e.jsx(o.LoaderCircle,{className:"h-3.5 w-3.5 animate-spin"}),"Saving…"]}):"Save"})]})]})}function K(s={}){const{authToken:i,tokenProps:a}=n.useSemaphorContext(),p=o.useDashboardStore(r=>r.actions.applyResolvedValueFormatPreferences),d=s.enabled??!0,c=(i==null?void 0:i.accessToken)??null,m=(a==null?void 0:a.apiServiceUrl)??null,v=l.useRef(c);v.current=c;const[b,g]=l.useState(null),[j,y]=l.useState(!1),[k,T]=l.useState(!1),[f,N]=l.useState(!1),[P,h]=l.useState(null);l.useEffect(()=>{g(null),h(null),y(!1),T(!1),N(!1)},[c]);const w=l.useCallback(async r=>{const t=D.parseValueFormatPreferencesResponse(await r.json());if(!t.ok)throw new Error("Value format preferences response is invalid");return t.value},[]),S=l.useCallback(async(r,t)=>{if(!c||!m)throw new Error("Not authenticated");const x=await fetch(`${m}/v1/user-preferences/value-format`,{method:r,headers:{Authorization:`Bearer ${c}`,...t?{"Content-Type":"application/json"}:{}},body:t?JSON.stringify(t):void 0});if(!x.ok){const z=await x.json().catch(()=>({}));throw new Error(z.error||"Failed to update preferences")}return w(x)},[c,m,w]),E=l.useCallback(async()=>{if(!d||!c||!m)return;const r=c;y(!0),h(null);try{const t=await S("GET");v.current===r&&g(t)}catch(t){v.current===r&&h(t instanceof Error?t.message:"Unknown error")}finally{v.current===r&&y(!1)}},[c,m,d,S]);l.useEffect(()=>{d&&E()},[d,E]);const A=l.useCallback(async r=>{const t=c;T(!0),h(null);try{const x=await S("PATCH",r);return v.current!==t?!1:(g(x),p(x.resolved,x.sources),!0)}catch(x){return v.current===t&&h(x instanceof Error?x.message:"Unknown error"),!1}finally{v.current===t&&T(!1)}},[c,p,S]),C=l.useCallback(async()=>{const r=c;N(!0),h(null);try{const t=await S("DELETE");return v.current!==r?!1:(g(t),p(t.resolved,t.sources),!0)}catch(t){return v.current===r&&h(t instanceof Error?t.message:"Unknown error"),!1}finally{v.current===r&&N(!1)}},[c,p,S]);return{preferences:b,isLoading:j,isSaving:k,isClearing:f,error:P,updatePreferences:A,clearPreferences:C,refetch:E}}function J({active:s,onClose:i}){var v,b;const{preferences:a,isLoading:p,isSaving:d,updatePreferences:c}=K({enabled:s});if(!s)return null;if(!a)return e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"py-2",children:e.jsx("div",{className:"flex min-h-36 items-center justify-center text-[12px] text-muted-foreground",children:p?"Loading preferences…":"Preferences unavailable."})}),e.jsxs(n.DialogFooter,{className:"justify-between sm:justify-between",children:[e.jsx(o.Button,{variant:"ghost",size:"xs",disabled:!0,children:"Reset locale and currency"}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(o.Button,{variant:"outline",size:"xs",onClick:i,children:"Cancel"}),e.jsx(o.Button,{size:"xs",disabled:!0,children:"Save"})]})]})]});const m=[((v=a.stored)==null?void 0:v.locale)??"",((b=a.stored)==null?void 0:b.defaultCurrency)??""].join(":");return e.jsx(Z,{preferences:a,isSaving:d,updatePreferences:c,onClose:i},m)}function Z({preferences:s,isSaving:i,updatePreferences:a,onClose:p}){const[d,c]=l.useState(()=>{var g,j;return{locale:(g=s.stored)==null?void 0:g.locale,defaultCurrency:(j=s.stored)==null?void 0:j.defaultCurrency}}),m=(d.locale===void 0||D.canonicalizeSupportedLocale(d.locale)!==void 0)&&(d.defaultCurrency===void 0||D.canonicalizeSupportedCurrencyCode(d.defaultCurrency)!==void 0),v=async()=>{var T,f;const g={},j=[];d.locale!==void 0?g.locale=d.locale:((T=s.stored)==null?void 0:T.locale)!==void 0&&j.push("locale"),d.defaultCurrency!==void 0?g.defaultCurrency=d.defaultCurrency:((f=s.stored)==null?void 0:f.defaultCurrency)!==void 0&&j.push("defaultCurrency");const y={...Object.keys(g).length>0?{set:g}:{},...j.length>0?{clear:j}:{}};(Object.keys(y).length===0?!0:await a(y))?(n.ue.success("Display format preferences saved."),p()):n.ue.error("Failed to save preferences. Please try again.")},b=async()=>{await a({clear:["locale","defaultCurrency"]})?(n.ue.success("Locale and currency preferences reset."),p()):n.ue.error("Failed to reset locale and currency preferences. Please try again.")};return e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"py-2",children:e.jsx(n.DisplayFormatPreferencesFields,{value:d,inherited:s.inherited,inheritedSources:s.inheritedSources,onChange:c,disabled:i})}),e.jsxs(n.DialogFooter,{className:"justify-between sm:justify-between",children:[e.jsx(o.Button,{variant:"ghost",size:"xs",onClick:b,disabled:i||s.stored===null,children:"Reset locale and currency"}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(o.Button,{variant:"outline",size:"xs",onClick:p,disabled:i,children:"Cancel"}),e.jsx(o.Button,{size:"xs",onClick:v,disabled:i||!m,children:i?e.jsxs(e.Fragment,{children:[e.jsx(o.LoaderCircle,{className:"h-3.5 w-3.5 animate-spin"}),"Saving…"]}):"Save"})]})]})]})}function Y({open:s,onOpenChange:i}){const[a,p]=l.useState("display"),d=()=>i(!1);return e.jsx(n.Dialog,{open:s,onOpenChange:i,children:e.jsxs(n.DialogContent,{className:"rounded-control border-border/60 sm:max-w-[440px] sm:rounded-control",children:[e.jsxs(n.DialogHeader,{children:[e.jsx(n.DialogTitle,{className:"text-[15px]",children:"Report preferences"}),e.jsx(n.DialogDescription,{className:"text-[13px] leading-5",children:"Set how values and Calendar periods appear for you."})]}),e.jsxs(o.Tabs,{value:a,onValueChange:p,children:[e.jsxs(o.TabsList,{variant:"underline",className:"w-full justify-start",children:[e.jsx(o.TabsTrigger,{value:"display",children:"Display formats"}),e.jsx(o.TabsTrigger,{value:"calendar",children:"Calendar"})]}),e.jsx(o.TabsContent,{value:"display",children:e.jsx(J,{active:s&&a==="display",onClose:d})}),e.jsx(o.TabsContent,{value:"calendar",children:e.jsx(H,{active:s&&a==="calendar",onClose:d})})]})]})})}exports.ReportPreferencesDialog=Y;
|