react-semaphor 0.1.606 → 0.1.608
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/dist/analytics-protocol/index.js +1 -1
- package/dist/appearance-runtime/index.js +1 -1
- package/dist/assistant-context/index.js +1 -1
- package/dist/assistant-protocol/index.js +1 -1
- package/dist/brand-studio/index.js +2 -2
- package/dist/briefings/index.js +1 -1
- package/dist/chunks/add-to-dashboard-Bu3M9DpP.js +12 -0
- package/dist/chunks/appearance-provider-BBYTKSjL.js +613 -0
- package/dist/chunks/appearance-runtime-provider-De2VZS4F.js +1 -0
- package/dist/chunks/assistant-chat-x3NCrm5n.js +53 -0
- package/dist/chunks/attachment-filter-line-ClTS4GvQ.js +1 -0
- package/dist/chunks/{bookmark-impact-BW30cm5E.js → bookmark-impact-xCmo8x3V.js} +1 -1
- package/dist/chunks/bookmark-state-BmbBu1th.js +1 -0
- package/dist/chunks/{brand-CL5xDiFH.js → brand-3m_qSMyC.js} +1 -1
- package/dist/chunks/card-filter-builder-CM3SZ4kO.js +11 -0
- package/dist/chunks/check-input-C7S2sNzB.js +151 -0
- package/dist/chunks/{comparison-window-caption-tguyN24S.js → comparison-window-caption-WzGsqv4n.js} +1 -1
- package/dist/chunks/compiler-XErOfUUx.js +1 -0
- package/dist/chunks/context-Cwj8Axgd.js +2 -0
- package/dist/chunks/currency-presentation-binding-s4PlA3Wu.js +1 -0
- package/dist/chunks/custom-visual-inputs-CUtxCe4T.js +1 -0
- package/dist/chunks/custom-visual-write-CH-k-4HE.js +1 -0
- package/dist/chunks/{dashboard-Cyhj9EOl.js → dashboard-BwuurlUI.js} +1 -1
- package/dist/chunks/{dashboard-briefing-launcher-CyOFddmD.js → dashboard-briefing-launcher-CX7mCnPi.js} +5 -5
- package/dist/chunks/{dashboard-controls-DpADfhr0.js → dashboard-controls-Bwjy9G1i.js} +8 -8
- package/dist/chunks/{dashboard-json-4xMChR2q.js → dashboard-json-B9lK28i0.js} +1 -1
- package/dist/chunks/dashboard-temporal-snapshot-CcndP6CF.js +1 -0
- package/dist/chunks/edit-dashboard-visual-BF3mfrWf.js +103 -0
- package/dist/chunks/{filter-line-WwUV5JzN.js → filter-line-W-qQAjke.js} +1 -1
- package/dist/chunks/filter-reach-preview-DSH_k8AJ.js +1 -0
- package/dist/chunks/{filter-value-text-DqTHe_vu.js → filter-value-text-DQwYZHz0.js} +1 -1
- package/dist/chunks/kpi-trend-rule-DDbguInc.js +1 -0
- package/dist/chunks/{layout-grid-Dtsioq4h.js → layout-grid-Bx0jBVXj.js} +1 -1
- package/dist/chunks/matrix-analytical-definition-jn075ooo.js +1 -0
- package/dist/chunks/{matrix-member-presentation-vVAv-aqg.js → matrix-member-presentation-Chz6uGYz.js} +1 -1
- package/dist/chunks/matrix-operation-contract-DceN49RX.js +1 -0
- package/dist/chunks/metric-formatting-DILSVxLq.js +1 -0
- package/dist/chunks/{numeric-range-options-C8tr-Bls.js → numeric-range-options-Drc1EZ6H.js} +1 -1
- package/dist/chunks/{palette-565cA0nh.js → palette-CZJ4ZCY9.js} +1 -1
- package/dist/chunks/pivot-result-contract-expectations-D_ane7I2.js +1 -0
- package/dist/chunks/{pivot-result-identity-B0eWVMXg.js → pivot-result-identity-DRhVJMsF.js} +1 -1
- package/dist/chunks/{raw-temporal-value-BHQ-ldpW.js → raw-temporal-value-B4Md6Xfb.js} +1 -1
- package/dist/chunks/report-preferences-dialog-EQNoTych.js +1 -0
- package/dist/chunks/{report-runtime-context-Cd1b5pku.js → report-runtime-context-CkxgMKr6.js} +1 -1
- package/dist/chunks/resolve-dashboard-input-context-B5yUS9ZM.js +8 -0
- package/dist/chunks/sandbox-host-WJXxpvz7.js +197 -0
- package/dist/chunks/saved-dashboard-context-DQlA4Mg0.js +1 -0
- package/dist/chunks/{selection-filter-compiler-kYsRugss.js → selection-filter-compiler-BxtEEB6Z.js} +1 -1
- package/dist/chunks/semaphor-ready-indicator-Cq3C2SNo.js +622 -0
- package/dist/chunks/set-wWdhgHSh.js +1 -0
- package/dist/chunks/slider-C4jUvJtd.js +599 -0
- package/dist/chunks/stored-dashboard-1x0q2cNx.js +1 -0
- package/dist/chunks/table-cell-text-DFHUGeG6.js +1 -0
- package/dist/chunks/{table-export-sheet-xaczzWZF.js → table-export-sheet-CthBUHu4.js} +1 -1
- package/dist/chunks/{token-types-1vzMWjI-.js → token-types-BM0mpZce.js} +1 -1
- package/dist/chunks/{validators-Dg2kyF4_.js → validators-U8IL8djK.js} +1 -1
- package/dist/chunks/{variable-draft-CRbSYdB6.js → variable-draft-CwX-b6Fs.js} +1 -1
- package/dist/dashboard/index.js +1 -1
- package/dist/dashboard-authoring/index.js +1 -1
- package/dist/extensions/index.js +1 -0
- package/dist/format-utils/index.js +1 -1
- package/dist/index.js +1 -1
- package/dist/report-runtime-context/index.js +1 -1
- package/dist/style.css +1 -1
- package/dist/surfboard/index.js +1 -1
- package/dist/types/components/assistant/assistant-store.d.ts +19 -0
- package/dist/types/components/assistant/use-assistant.d.ts +4 -0
- package/dist/types/components/visual/data-table/hooks/use-data-table-logic.d.ts +2 -3
- package/dist/types/components/visual/data-table/table-cell-text.d.ts +93 -0
- package/dist/types/components/visual/data-table/types/data-table.d.ts +0 -1
- package/dist/types/extensions.d.ts +2 -0
- package/dist/types/index.js +1 -1
- package/dist/types/lib/charts/types.d.ts +3 -1
- package/dist/types/lib/dashboard/semantic-dataset-references.d.ts +0 -2
- package/dist/types/lib/matrix-table/matrix-card-adapter.d.ts +12 -12
- package/dist/types/lib/matrix-table/matrix-delivery.d.ts +25 -25
- package/dist/types/lib/stores/dashboard-store.d.ts +33 -2
- package/dist/types/lib/stores/editor-store.d.ts +8 -0
- package/dist/types/lib/types/common-types.d.ts +3 -0
- package/dist/types/lib/utils/card-definition.d.ts +12 -12
- package/dist/types/lib/utils/card-type-change.d.ts +9 -0
- package/dist/types/shared/analytics-protocol/analytics-base-schemas.d.ts +6 -6
- package/dist/types/shared/analytics-protocol/execution-input-schemas.d.ts +10 -10
- package/dist/types/shared/analytics-protocol/matrix-definition-contract.d.ts +248 -248
- package/dist/types/shared/analytics-protocol/matrix-operation-contract.d.ts +10 -10
- package/dist/types/shared/analytics-protocol/matrix-operation-request.d.ts +8 -8
- package/dist/types/shared/analytics-protocol/matrix-window-contract.d.ts +2 -2
- package/dist/types/shared/assistant-protocol/context.d.ts +26 -26
- package/dist/types/shared/assistant-protocol/parts.d.ts +4 -0
- package/dist/types/shared/assistant-protocol/request.d.ts +2 -1
- package/dist/types/shared/dashboard-authoring/card-data-source/card-base.d.ts +16 -6
- package/dist/types/shared/dashboard-authoring/card-settings/custom-visual-write.d.ts +50 -0
- package/dist/types/shared/dashboard-authoring/card-settings/index.d.ts +1 -0
- package/dist/types/shared/dashboard-authoring/changes/card-query-part.d.ts +1 -0
- package/dist/types/shared/dashboard-authoring/changes/card-types.d.ts +2 -2
- package/dist/types/shared/dashboard-authoring/changes/custom-visual-change.d.ts +57 -0
- package/dist/types/shared/dashboard-authoring/changes/dashboard-change.d.ts +61 -54
- package/dist/types/shared/dashboard-authoring/changes/diagnostics.d.ts +5 -1
- package/dist/types/shared/dashboard-authoring/changes/read-card-query.d.ts +5 -1
- package/dist/types/shared/dashboard-authoring/changes/resolve-dashboard-changes.d.ts +10 -0
- package/dist/types/shared/dashboard-authoring/conditional-formatting/schema.d.ts +60 -60
- package/dist/types/shared/dashboard-authoring/control-execution-contract.d.ts +4 -4
- package/dist/types/shared/dashboard-authoring/matrix-delivery.d.ts +48 -48
- package/dist/types/shared/dashboard-authoring/operations/operation-sentences.d.ts +8 -2
- package/dist/types/shared/dashboard-authoring/operations/operation-types.d.ts +11 -0
- package/dist/types/shared/dashboard-authoring/outline/outline-dashboard.d.ts +7 -0
- package/dist/types/shared/dashboard-authoring/table-sheet-shape.d.ts +8 -0
- package/dist/types/shared/extensions/check-audits.d.ts +30 -0
- package/dist/types/shared/extensions/check-findings.d.ts +46 -0
- package/dist/types/shared/extensions/check-input.d.ts +23 -0
- package/dist/types/shared/extensions/check-renders.d.ts +44 -0
- package/dist/types/shared/extensions/check-runner.d.ts +19 -0
- package/dist/types/shared/extensions/index.d.ts +17 -0
- package/dist/types/shared/extensions/read-document.d.ts +18 -0
- package/dist/types/shared/extensions/sandbox-host.d.ts +63 -0
- package/dist/types/shared/extensions/saved-refs.d.ts +33 -0
- package/dist/types/shared/extensions/script-policy.d.ts +11 -0
- package/dist/types/shared/extensions/types.d.ts +186 -0
- package/dist/types/shared/extensions/visual-contract.d.ts +38 -0
- package/dist/types/shared/extensions/visual-payload.d.ts +75 -0
- package/dist/types/shared/extensions/visual-theme.d.ts +21 -0
- package/dist/types/shared/format-utils/formatters/number-formatter.d.ts +13 -6
- package/dist/types/shared/format-utils/matrix-continuation.d.ts +2 -2
- package/dist/types/shared/format-utils/matrix-export-presentation.d.ts +24 -24
- package/dist/types/shared/usage-events/details.d.ts +4 -4
- package/dist/types/shared/usage-events/envelope.d.ts +2 -2
- package/dist/usage-events/index.js +1 -1
- package/package.json +7 -2
- package/dist/chunks/add-to-dashboard-CEmZUf9o.js +0 -12
- package/dist/chunks/appearance-provider-fIhJSX6y.js +0 -613
- package/dist/chunks/appearance-runtime-provider-Bx8H-moR.js +0 -1
- package/dist/chunks/assistant-chat-SBKSrrEA.js +0 -51
- package/dist/chunks/attachment-filter-line-C_zHMhGh.js +0 -1
- package/dist/chunks/bookmark-state-DScd31KT.js +0 -1
- package/dist/chunks/card-filter-builder-CzScSOQY.js +0 -11
- package/dist/chunks/context-CntvtZwC.js +0 -2
- package/dist/chunks/dashboard-temporal-snapshot-w3SMiPKj.js +0 -1
- package/dist/chunks/edit-dashboard-visual-DlvY7au4.js +0 -73
- package/dist/chunks/filter-reach-preview-DAEIyrEG.js +0 -1
- package/dist/chunks/kpi-trend-rule-N1Xkwe_u.js +0 -1
- package/dist/chunks/matrix-analytical-definition-5T-2euHZ.js +0 -1
- package/dist/chunks/matrix-operation-contract-CWvcEsQ0.js +0 -1
- package/dist/chunks/pivot-result-contract-expectations-BNWhS8mv.js +0 -1
- package/dist/chunks/report-preferences-dialog-B2ZGPS9t.js +0 -1
- package/dist/chunks/resolve-dashboard-input-context-SlAAe4GF.js +0 -8
- package/dist/chunks/saved-dashboard-context-Bc2SVDr-.js +0 -1
- package/dist/chunks/semaphor-ready-indicator-Bj-cjkz-.js +0 -612
- package/dist/chunks/set-CACXVM2A.js +0 -1
- package/dist/chunks/slider-CWze9OEM.js +0 -4
- package/dist/chunks/stored-dashboard-CcNdU-mG.js +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{f as Le,l as H,k as qe,aE as je}from"./validators-U8IL8djK.js";import{z as f}from"zod";import{n as Be,D as Ue,l as be,q as ze,r as U,ab as z,a as We,z as Qe,Z as Ye,L as Ge}from"./matrix-operation-contract-DceN49RX.js";import"./analytics-base-schemas-DMFrDqn_.js";import{a as D}from"./applied-constraints-CinevlKD.js";import{r as Je}from"./pivot-result-identity-DRhVJMsF.js";const ae=8,ie=6,P=Object.freeze([]);function He(e){switch(e.type){case"table":case"chart":return e.card?[e.card]:P;case"kpi":return Array.isArray(e.cards)?e.cards:P;default:return P;}}function Xe(e,t){switch(e.type){case"table":case"chart":{if(!e.card)return e;const n=t(e.card);return n===e.card?e:{...e,card:n};}case"kpi":{if(!Array.isArray(e.cards))return e;const n=e.cards.map(t);return n.every((r,s)=>r===e.cards[s])?e:{...e,cards:n};}default:return e;}}function V(e){var n;const t=[];for(const r of e.sheets||[]){const s=r.id;for(const a of r.cards||[])t.push({kind:"sheetCard",sheetId:s,cardId:a.id,card:a});for(const a of r.frames||[])for(const i of a.cards||[])t.push({kind:"frameCard",sheetId:s,frameId:a.id,cardId:i.id,card:i});for(const a of((n=r.document)==null?void 0:n.sections)||[])for(const i of He(a))t.push({kind:"documentSectionCard",sheetId:s,sectionId:a.id,cardId:i.id,card:i});}return t;}function rn(e,t,n){let r=!1;const s=Ze(e,i=>i.id!==n.id?i:(r=!0,i===n?i:n));if(r||!t)return s;const a=(s.sheets||[]).map(i=>i.id===t&&i.kind!=="document"?{...i,cards:[...(i.cards??[]),n]}:i);return{...s,sheets:a};}function Ze(e,t){const n=(s,a)=>{const i=s.map(o=>t(o,a(o)));return i.every((o,c)=>o===s[c])?s:i;},r=(e.sheets||[]).map(s=>{var m,I,y;const a=s.id,i=s.cards&&n(s.cards,l=>({kind:"sheetCard",sheetId:a,cardId:l.id,card:l})),o=(m=s.frames)==null?void 0:m.map(l=>{if(!l.cards)return l;const h=n(l.cards,C=>({kind:"frameCard",sheetId:a,frameId:l.id,cardId:C.id,card:C}));return h===l.cards?l:{...l,cards:h};}),c=(y=(I=s.document)==null?void 0:I.sections)==null?void 0:y.map(l=>Xe(l,h=>t(h,{kind:"documentSectionCard",sheetId:a,sectionId:l.id,cardId:h.id,card:h}))),u=!!o&&o.some((l,h)=>l!==s.frames[h]),d=!!c&&c.some((l,h)=>l!==s.document.sections[h]);return i===s.cards&&!u&&!d?s:{...s,...(i===s.cards?{}:{cards:i}),...(u?{frames:o}:{}),...(d?{document:{...s.document,sections:c}}:{})};});return r.every((s,a)=>s===e.sheets[a])?e:{...e,sheets:r};}function L(e){return!!e&&typeof e=="object"&&!Array.isArray(e);}function sn(e){if(!L(e))return[{path:"",message:"must be an object."}];const t=[];e.title!==void 0&&typeof e.title!="string"&&t.push({path:"title",message:"must be a string."});const n=e.cards;if(!Array.isArray(n))t.push({path:"cards",message:"must be an array of KPI cards."});else{(n.length<1||n.length>ae)&&t.push({path:"cards",message:`must hold 1 to ${ae} KPI cards.`});const s=/* @__PURE__ */new Set();n.forEach((a,i)=>{if(!L(a)){t.push({path:`cards[${i}]`,message:"must be a card."});return;}typeof a.id!="string"||!a.id?t.push({path:`cards[${i}].id`,message:"must be a non-empty string."}):s.has(a.id)?t.push({path:`cards[${i}].id`,message:`duplicates card id '${a.id}'.`}):s.add(a.id),a.type!=="kpi"&&t.push({path:`cards[${i}].type`,message:"must be 'kpi'."});});}const r=e.kpi;return L(r)?(r.layout!=="tiles"&&r.layout!=="lines"?t.push({path:"kpi.layout",message:"must be 'tiles' or 'lines'."}):r.layout==="tiles"&&Array.isArray(n)&&n.length>ie&&t.push({path:"kpi.layout",message:`must be 'lines' for more than ${ie} KPI cards.`}),r.columns!==void 0&&r.columns!==1&&r.columns!==2&&t.push({path:"kpi.columns",message:"must be 1 or 2."})):t.push({path:"kpi",message:"must be an object."}),t;}const Se="dashboardInput";function oe(e){return e==="label"||e==="value"||e==="start"||e==="end"||e==="range";}function et(e){return e==="generatedAt"||e==="pageNumber"||e==="pageCount";}function v(e){if(!e||typeof e!="object"||Array.isArray(e))return;const t=e;if(t.source==="input"||t.source===Se)return typeof t.inputId=="string"&&oe(t.export)?{source:"input",inputId:t.inputId,export:t.export}:void 0;if(t.source==="dashboardInputAlias")return typeof t.variableName!="string"||t.export!==void 0&&!oe(t.export)?void 0:{source:"dashboardInputAlias",variableName:t.variableName,...(t.export?{export:t.export}:{})};if(t.source==="documentMeta")return et(t.key)?{source:"documentMeta",key:t.key}:void 0;if(t.source==="data")return typeof t.variableId=="string"&&typeof t.export=="string"?{source:"data",variableId:t.variableId,export:t.export}:void 0;}function an(e,t){const n=v(e),r=v(t);return!n||!r?JSON.stringify(e)===JSON.stringify(t):[.../* @__PURE__ */new Set([...Object.keys(n),...Object.keys(r)])].every(a=>n[a]===r[a]);}function tt(e){return R(e)?e.type==="variable"?e.ref===void 0?[]:[e.ref]:e.type==="when"&&R(e.test)&&e.test.ref!==void 0?[e.test.ref]:[]:[];}function nt(e,t){if(!R(e))return e;if(e.type==="variable"&&e.ref!==void 0){const n=t(e.ref);return n===e.ref?e:{...e,ref:n};}if(e.type==="when"&&R(e.test)&&e.test.ref!==void 0){const n=t(e.test.ref);return n===e.test.ref?e:{...e,test:{...e.test,ref:n}};}return e;}function R(e){return!!e&&typeof e=="object"&&!Array.isArray(e);}function ce(e){return!!e&&typeof e=="object"&&e.source===Se;}function on(e){return W(e);}function W(e){if(!e||typeof e!="object")return e;if(Array.isArray(e)){let a=!1;const i=e.map(o=>{const c=W(o);return c!==o&&(a=!0),c;});return a?i:e;}const t=e;let n;const r=(a,i)=>{i!==t[a]&&(n??(n={...t}),n[a]=i);},s=nt(t,a=>ce(a)?v(a)??a:a);if(s!==t&&(s.ref!==t.ref&&r("ref",s.ref),s.test!==t.test&&r("test",s.test)),t.inputAliases&&typeof t.inputAliases=="object"){const a=t.inputAliases;let i=!1;const o=Object.fromEntries(Object.entries(a).map(([c,u])=>ce(u)?(i=!0,[c,v(u)??u]):[c,u]));i&&r("inputAliases",o);}for(const[a,i]of Object.entries(t))a==="ref"&&t.type==="variable"||a==="test"&&t.type==="when"||a==="inputAliases"||r(a,W(i));return n??e;}function cn(e){return b(e);}function b(e){const t=[];for(const n of Array.isArray(e)?e:[])if(!(!n||typeof n!="object")){for(const r of tt(n)){const s=v(r);s&&t.push(s);}n.type==="link"&&t.push(...b(n.children),...b(Array.isArray(n.url)?n.url:[])),n.type==="when"&&t.push(...b(n.then),...b(n.else));}return t;}function rt(e){var r;const t=(r=e.preferences)==null?void 0:r.textVisualOptions,n=t==null?void 0:t.richContent;return n&&Array.isArray(n.blocks)?n.blocks.flatMap(s=>(s==null?void 0:s.type)==="list"?(Array.isArray(s.items)?s.items:[]).flatMap(a=>b(a)):b(s==null?void 0:s.children)):b(t==null?void 0:t.content);}function Ce(e,t){var s;const n=[],r={kind:"document",sheetId:e};for(const a of["header","footer"])for(const i of((s=t[a])==null?void 0:s.blocks)??[])if(i.type==="text")for(const o of b(i.content))n.push({ref:o,place:r,where:{kind:a,blockId:i.id}});for(const a of t.sections??[])if(a.type==="text")for(const i of b(a.content))n.push({ref:i,place:r,where:{kind:"section",sectionId:a.id}});return n;}const ue=/* @__PURE__ */new WeakMap();function ge(e){const t=ue.get(e);if(t)return t;const n=[];for(const r of e.sheets??[]){if(r.kind==="document"){r.document&&n.push(...Ce(r.id,r.document));continue;}const s={kind:"sheet",sheetId:r.id},a=[...(r.cards??[]),...(r.frames??[]).flatMap(i=>i.cards??[])];for(const i of a)if(i.type==="text")for(const o of rt(i))n.push({ref:o,place:s,where:{kind:"card",cardId:i.id}});}return ue.set(e,n),n;}function ke(e,t){return e.kind===t.kind&&e.sheetId===t.sheetId;}function we(e,t){const n=ge(e);return t?n.filter(r=>ke(r.place,t)):[...n];}function st(e,t){const n=[];for(const{ref:r,place:s}of ge(e))r.source!=="data"||r.variableId!==t||n.some(a=>ke(a,s))||n.push(s);return n;}function un(e,t){const n=/* @__PURE__ */new Set();for(const{ref:r}of we(e,t))r.source==="data"&&n.add(r.variableId);return[...n];}function dn(e,t){const n=Ce("",e).filter(({ref:r})=>r.source==="input"&&r.inputId===t);return{header:n.some(({where:r})=>r.kind==="header"),footer:n.some(({where:r})=>r.kind==="footer"),textSections:new Set(n.flatMap(({where:r})=>r.kind==="section"?[r.sectionId]:[])).size};}function Ae(e,t){const n=st(e,t);return n.length?n.map(r=>({sheetId:r.sheetId,cardId:t,sheetKind:r.kind==="document"?"document":"dashboard"})):(e.sheets??[]).filter(r=>r.kind!=="document").map(r=>({sheetId:r.id,cardId:t,sheetKind:"dashboard"}));}function g(e,t){var r;if(!ct(e,t))return!1;const n=e.scope;switch(n.kind){case"allSheets":return((r=n.sheetKinds)!=null&&r.length?t.sheetKind?n.sheetKinds.includes(t.sheetKind):!1:!!t.sheetId||!!t.cardId)&&!ot(n.exceptSheetIds,t)&&!fe(n.exceptCardIds,t);case"sheets":return!!t.sheetId&&n.sheetIds.includes(t.sheetId)&&!fe(n.exceptCardIds,t);case"cards":return!!t.cardId&&n.cardIds.includes(t.cardId);case"documentSections":return!!t.sheetId&&!!t.sectionId&&n.sheetId===t.sheetId&&n.sectionIds.includes(t.sectionId);default:return!1;}}function ln(e,t){if(g(e,{sheetId:t.sheetId,sheetKind:t.sheetKind}))return!0;switch(e.scope.kind){case"cards":for(const n of[...t.cardIds,...(t.variableIds??[])])if(g(e,{sheetId:t.sheetId,cardId:n,sheetKind:t.sheetKind}))return!0;return!1;case"documentSections":return t.sheetKind==="document"&&e.scope.sheetId===t.sheetId;default:return!1;}}const de=/* @__PURE__ */new WeakMap();function at(e){const t=de.get(e);if(t)return t;const n=/* @__PURE__ */new Map();for(const a of V(e)){const i=n.get(a.sheetId)??/* @__PURE__ */new Set();i.add(a.cardId),n.set(a.sheetId,i);}const r=/* @__PURE__ */new Map();for(const{ref:a,place:i}of we(e)){if(a.source!=="data")continue;const o=r.get(i.sheetId)??/* @__PURE__ */new Set();o.add(a.variableId),r.set(i.sheetId,o);}const s=/* @__PURE__ */new Map();for(const a of e.sheets??[])s.set(a.id,{sheetId:a.id,sheetKind:a.kind==="document"?"document":"dashboard",cardIds:n.get(a.id)??/* @__PURE__ */new Set(),variableIds:r.get(a.id)??/* @__PURE__ */new Set()});return de.set(e,s),s;}function fn(e,t){var s,a;const n=/* @__PURE__ */new Set(),r=at(e);for(const i of r.values())g(t,{sheetId:i.sheetId,sheetKind:i.sheetKind})&&n.add(`sheet:${i.sheetId}`);for(const i of V(e))g(t,{sheetId:i.sheetId,cardId:i.cardId,...(i.kind==="documentSectionCard"?{sectionId:i.sectionId}:{}),sheetKind:((s=r.get(i.sheetId))==null?void 0:s.sheetKind)??"dashboard"})&&n.add(`card:${i.cardId}`);for(const i of e.variables??[])Ae(e,i.id).some(o=>g(t,o))&&n.add(`card:${i.id}`);for(const i of e.sheets??[])if(i.kind==="document")for(const o of((a=i.document)==null?void 0:a.sections)??[])g(t,{sheetId:i.id,sectionId:o.id,sheetKind:"document"})&&n.add(`section:${o.id}`);return n;}function mn(e){return e.kind==="filter"&&e.scope.kind==="cards";}function pn(e,t){var a,i,o;const n=c=>{var u,d;return le(c,t.removedSheetIds,t.renamedSheetIds,!1,(u=t.copiedTab)==null?void 0:u.sheetIds,(d=t.copiedTab)==null?void 0:d.mode);},r=c=>{var u,d;return le(c,t.removedCardIds,t.renamedCardIds,t.keepOnlyRenamedCardIds===!0,(u=t.copiedTab)==null?void 0:u.cardIds,(d=t.copiedTab)==null?void 0:d.mode);};let s;switch(e.kind){case"allSheets":s={...e,...(e.exceptSheetIds?{exceptSheetIds:n(e.exceptSheetIds)}:{}),...(e.exceptCardIds?{exceptCardIds:r(e.exceptCardIds)}:{})};break;case"sheets":s={...e,sheetIds:n(e.sheetIds),...(e.exceptCardIds?{exceptCardIds:r(e.exceptCardIds)}:{})};break;case"cards":s={...e,cardIds:r(e.cardIds)};break;case"documentSections":{if((a=t.removedSheetIds)!=null&&a.has(e.sheetId)){s={...e,sectionIds:[]};break;}const c={...e,sheetId:((i=t.renamedSheetIds)==null?void 0:i.get(e.sheetId))??e.sheetId,sectionIds:(o=t.renamedSectionIds)!=null&&o.size?e.sectionIds.map(d=>t.renamedSectionIds.get(d)??d):e.sectionIds},u=t.copiedTab;s=(u==null?void 0:u.mode)==="replace"&&u.sheetIds.has(c.sheetId)?{...c,sheetId:u.sheetIds.get(c.sheetId),sectionIds:c.sectionIds.map(d=>u.sectionIds.get(d)??d)}:c;break;}default:return e;}return it(e,s)?e:s;}function le(e,t,n,r,s,a){let i=e;return t!=null&&t.size&&(i=i.filter(o=>!t.has(o))),r&&(i=i.filter(o=>n==null?void 0:n.has(o))),n!=null&&n.size&&(i=i.map(o=>n.get(o)??o)),s!=null&&s.size&&(i=a==="extend"?[.../* @__PURE__ */new Set([...i,...i.flatMap(o=>s.has(o)?[s.get(o)]:[])])]:i.map(o=>s.get(o)??o)),i;}function it(e,t){return JSON.stringify(e)===JSON.stringify(t);}function ot(e,t){return!!t.sheetId&&!!(e!=null&&e.includes(t.sheetId));}function fe(e,t){return!!t.cardId&&!!(e!=null&&e.includes(t.cardId));}function ct(e,t){return t.sheetKind!=="document"||!e.compatibility||e.compatibility.source==="documentInput"?!0:e.compatibility.source==="cardInlineFilter"||e.compatibility.source==="cardControl"?!!t.cardId&&e.compatibility.cardId===t.cardId:!1;}function hn(e,t,n){switch(e.kind){case"sheets":return e.sheetIds.length>0&&e.sheetIds.every(r=>r===t);case"cards":return e.cardIds.length>0&&e.cardIds.every(r=>n.has(r));case"documentSections":return e.sheetId===t;case"allSheets":return!1;}}function yn(e){return e.kind==="sheets"&&e.sheetIds.length===0||e.kind==="cards"&&e.cardIds.length===0;}function ut(e){return e.kind==="allSheets"||e.kind==="sheets"?e.exceptCardIds??[]:[];}function In(e){return e.kind==="allSheets"?e.exceptSheetIds??[]:[];}function bn(e,t){var a;if(e.kind!=="allSheets"&&e.kind!=="sheets"||!((a=e.exceptCardIds)!=null&&a.includes(t)))return e;const n=e.exceptCardIds.filter(i=>i!==t),{exceptCardIds:r,...s}=e;return n.length?{...s,exceptCardIds:n}:s;}function Sn(e,t,n){var o;if(t.kind!=="allSheets"&&t.kind!=="sheets")return t;const r=ut(e),s=e.kind==="sheets"?e.sheetIds.filter(c=>n.has(c)):e.kind==="allSheets"&&me(e)?[...n].filter(c=>{var u;return!((u=e.exceptSheetIds)!=null&&u.includes(c));}):[],a=[...n].filter(c=>!s.includes(c));if(t.kind==="sheets")return{...t,sheetIds:[.../* @__PURE__ */new Set([...t.sheetIds,...s])],...(r.length?{exceptCardIds:[...r]}:{})};const i=e.kind==="allSheets"?((o=e.exceptSheetIds)==null?void 0:o.filter(c=>n.has(c)))??[]:[];return{kind:"allSheets",...(e.kind==="allSheets"&&me(e)?{...(e.sheetKinds?{sheetKinds:e.sheetKinds}:{}),...(i.length?{exceptSheetIds:i}:{})}:s.length?{sheetKinds:["dashboard","document"],...(a.length?{exceptSheetIds:a}:{})}:{}),...(r.length?{exceptCardIds:[...r]}:{})};}function me(e){var t;return e.kind==="allSheets"&&(!((t=e.sheetKinds)!=null&&t.length)||e.sheetKinds.includes("document"));}function Cn(e,t){switch(e.kind){case"allSheets":case"sheets":{const n=e.exceptCardIds??[];return n.includes(t)?e:{...e,exceptCardIds:[...n,t]};}case"cards":return{...e,cardIds:e.cardIds.filter(n=>n!==t)};case"documentSections":return;}}const _={includeMetricFilterDatasets:!0,preferQualifiedIdentity:!1};function Q(e){if(!e)return;if(e.kind==="semantic")return{entityName:e.datasetName,entityId:e.datasetId,label:e.label};const t=[e.databaseName,e.schemaName,e.tableName].filter(n=>!!(n&&n.trim())).join(".");return{entityName:e.tableName,qualifiedEntityName:t.includes(".")?t:void 0,label:e.label};}function dt(e){var n;const t=Q(e.source);return t?`${(n=e.source)==null?void 0:n.kind}:${t.qualifiedEntityName||t.entityName}`:"";}function lt(e){return[e.id,e.qualifiedEntityName,e.entityId,e.entityName,e.qualifiedFieldName,e.name,dt(e)].join("|");}function ft(e){return[e.entityName,e.qualifiedEntityName||"",e.entityId||""].join("|");}function gn(e){return e.entityName||e.qualifiedEntityName||"";}function mt(e){var t,n;return!!(e.expression||e.derivedField||(n=(t=e.calculatedFormula)==null?void 0:t.inputFields)!=null&&n.length);}function pt(e){return Le(e)?!0:e.entityName||e.qualifiedEntityName?!1:!e.source||mt(e);}function N(e,t){const n=ft(t);e.found.has(n)||e.found.set(n,t);}function T(e,t){var d,m,I;if(!e)return;const n=lt(e);if(t.visitedFields.has(n))return;t.visitedFields.add(n);const r=pt(e);if(!r){const y=!e.entityName&&!e.qualifiedEntityName?Q(e.source):void 0;N(t,y||{entityName:e.entityName||"",entityId:e.entityId,qualifiedEntityName:e.qualifiedEntityName,label:e.source&&e.source.kind==="semantic"?e.source.label:void 0});}t.includeMetricFilterDatasets&&"parameters"in e&&(d=e.parameters)!=null&&d.filters&&X(e.parameters.filters,t);const s=(m=e.calculatedFormula)==null?void 0:m.inputFields,a=!!(s&&s.length>0);a&&s.forEach(y=>T(y,t));let i=!1,o=!1;const c=a||(I=e.derivedField)==null?void 0:I.inputs;if(c&&Object.keys(c).length>0)for(const y of Object.values(c)){const l=y.field.source;if(!l){a||(o=!0);continue;}if(l.kind==="sql"){o=!0;continue;}if(l.kind==="semantic")N(t,{entityName:l.datasetName,entityId:l.datasetId,label:l.label});else{const h=[l.databaseName,l.schemaName,l.tableName].filter(C=>!!(C&&C.trim())).join(".");N(t,{entityName:l.tableName,qualifiedEntityName:h.includes(".")?h:void 0,label:l.label});}i=!0;}const u=r&&!a&&!(c&&Object.keys(c).length>0)?Q(e.source):void 0;(u!=null&&u.entityName||u!=null&&u.qualifiedEntityName)&&(N(t,u),i=!0),o&&(t.complete=!1),r&&!a&&!i&&(t.complete=!1);}function X(e,t){if(e&&!t.visitedGroups.has(e.id)){t.visitedGroups.add(e.id);for(const n of e.conditions||[])T(n.field,t);for(const n of e.groups||[])X(n,t);}}function $(e,t=/* @__PURE__ */new Set(),n=/* @__PURE__ */new Set()){return{found:/* @__PURE__ */new Map(),complete:!0,visitedFields:t,visitedGroups:n,includeMetricFilterDatasets:e};}function Z(e,t){var r;const n=(r=e.qualifiedEntityName)!=null&&r.includes(".")?e.qualifiedEntityName:void 0;return t==="qualifiedOnly"?n:t==="preferQualified"?n||e.entityName||void 0:e.entityName||void 0;}function kn(e){const t=$(!1);return T(e,t),{datasets:Array.from(t.found.values()),complete:t.complete};}function ve(e,t,n=/* @__PURE__ */new Set(),r=/* @__PURE__ */new Set(),s=_){const a={..._,...s},i=$(a.includeMetricFilterDatasets,n,r);T(e,i),i.found.forEach(o=>{const c=Z(o,a.preferQualifiedIdentity?"preferQualified":"name");c&&t.add(c);});}function wn(e,t){ve(e,t,/* @__PURE__ */new Set(),/* @__PURE__ */new Set(),{preferQualifiedIdentity:!0});}function An(e,t,n=/* @__PURE__ */new Set(),r=/* @__PURE__ */new Set()){const s=$(!0,n,r);T(e,s),s.found.forEach(a=>{const i=Z(a,"qualifiedOnly");i&&t.add(i);});}function vn(e,t,n=/* @__PURE__ */new Set(),r=/* @__PURE__ */new Set()){ve(e,t,n,r,{includeMetricFilterDatasets:!1});}function Tn(e,t,n=/* @__PURE__ */new Set(),r=/* @__PURE__ */new Set(),s=_){const a={..._,...s},i=$(a.includeMetricFilterDatasets,n,r);X(e,i),i.found.forEach(o=>{const c=Z(o,a.preferQualifiedIdentity?"preferQualified":"name");c&&t.add(c);});}function En(e,t){return t!=null&&t[e]?t[e]:(e.includes(".")?e.slice(e.lastIndexOf(".")+1):e).replace(/[_-]+/g," ").replace(/([a-z])([A-Z])/g,"$1 $2").replace(/\s+/g," ").trim().replace(/\b\w/g,r=>r.toUpperCase());}const Kn={database:null,schema:null,table:null},Nn="__card_default__",ht=6;function On(e){if(!(e===void 0||!Number.isFinite(e))&&Number.isInteger(e))return Math.max(0,Math.min(ht,e));}function Te(e){var t;return((t=e==null?void 0:e.comparison)==null?void 0:t.mode)==="explicit"?be(e.comparison.spec):void 0;}function yt(e){const t=Te(e);return t?Be(t):"none";}function Dn(e){const t=Te(e);return(t==null?void 0:t.kind)==="target"?t.targetValue:void 0;}function Mn(e){return(e==null?void 0:e.semanticComparisonPolarity)||(e==null?void 0:e.comparisonPolarity)||Ue;}function ee(e,t){const n=Object.entries(e||{}).filter(([a,i])=>i.output.outputId===a);if(!t.name)return;const r=U({...t,name:t.name}),s=n.filter(([,a])=>a.output.metricAlias===r);return s.length===1?s[0][1]:void 0;}function xn(e,t){const n=ee(e,t);return{comparisonKind:(n==null?void 0:n.type)??yt(t),metadata:n};}function Rn(e){return(e==null?void 0:e.showComparison)??ze.showComparison;}function _n(e){const t=/* @__PURE__ */new Set(),n=/* @__PURE__ */new Set(),r=/* @__PURE__ */new Set(),s=/* @__PURE__ */new Set(),a=/* @__PURE__ */new Set(),i=/* @__PURE__ */new Set(),o=/* @__PURE__ */new Map();return Object.entries(e||{}).forEach(([c,u])=>{const d=u.output;d.outputId===c&&(t.add(d.currentColumnKey),n.add(d.currentColumnKey),d.availability.status==="available"&&(d.comparisonColumnKey&&(r.add(d.comparisonColumnKey),o.set(d.comparisonColumnKey,{metricName:u.displayName||d.metricId,comparisonLabel:u.displayLabel||"Comparison"})),d.deltaColumnKey&&(t.add(d.deltaColumnKey),s.add(d.deltaColumnKey)),d.percentChangeColumnKey&&(t.add(d.percentChangeColumnKey),a.add(d.percentChangeColumnKey)),d.ratioColumnKey&&(t.add(d.ratioColumnKey),i.add(d.ratioColumnKey)),d.rowStatusColumnKey&&(t.add(d.rowStatusColumnKey),n.add(d.rowStatusColumnKey)),d.currentBucketColumnKey&&(t.add(d.currentBucketColumnKey),n.add(d.currentBucketColumnKey)),d.comparisonSourceBucketColumnKey&&(t.add(d.comparisonSourceBucketColumnKey),n.add(d.comparisonSourceBucketColumnKey))));}),{internalKeys:t,bookkeepingKeys:n,comparisonColumnKeys:r,deltaColumnKeys:s,percentChangeColumnKeys:a,ratioColumnKeys:i,comparisonSeriesLabels:o};}const It="SEMAPHOR_CALCULATED_FIELD";function te(e,t,n){if(n&&(t==="groupby"||t==="pivotby"))return n;if(t==="metric"&&e.name==="*"&&!e.expression)return e.alias||"count";if(e.alias)return e.alias;const r=e.entityName&&e.entityName!==It?e.entityName:void 0;if(e.role==="metric"){let s=e.aggregate||"metric";if(e.expression){const a=e.expression.match(/^(COUNT|SUM|AVG|MIN|MAX|MEDIAN|DISTINCT)\s*\(/i);s=a?a[1].toLowerCase():"expr";}else s=s.toLowerCase();return r&&r!==e.name?`${r}_${e.name}_${s}`:`${e.name}_${s}`;}return r&&r!==e.name?`${r}_${e.name}`:e.name;}function Ee(e){return te(e,"detail");}function bt(e){const t=e.label;return t&&e.labelCount===1&&(t===e.rawKey||!e.rawKeys.has(t))?t:e.rawKey;}function Fn(e){const t=[...(e.groupByColumns??[]).map(o=>({field:o,role:"groupby"})),...(e.metricColumns??[]).map(o=>({field:o,role:"metric"})),...(e.pivotByColumns??[]).map(o=>({field:o,role:"pivotby"})),...(e.detailColumns??[]).map(o=>({field:o,role:"detail"}))],n=Ke(e.detailColumns??[]),r=new Map((e.detailColumns??[]).map((o,c)=>[o,c])),s=new Map(t.map(({field:o,role:c})=>[o,c==="detail"?n[r.get(o)]:te(o,c)])),a=new Set(s.values()),i=/* @__PURE__ */new Map();for(const{field:o}of t)o.label&&i.set(o.label,(i.get(o.label)??0)+1);return new Map(t.map(({field:o})=>[o,bt({label:o.label,labelCount:o.label?i.get(o.label)??0:0,rawKey:s.get(o),rawKeys:a})]));}function Ke(e){const t=e.map(s=>Ee(s)),n=new Set(t),r=/* @__PURE__ */new Map();return t.forEach((s,a)=>{r.has(s)||r.set(s,a);}),t.map((s,a)=>{if(r.get(s)===a)return s;let i=2;for(;n.has(`${s}_${i}`);)i+=1;return n.add(`${s}_${i}`),`${s}_${i}`;});}function Vn(e){const t=e.detailColumns;if(!t||t.length<2)return e;const n=Ke(t);let r=!1;const s=t.map((a,i)=>Ee(a)===n[i]?a:(r=!0,{...a,alias:n[i]}));return r?{...e,detailColumns:s}:e;}const Ne="text",F=100,St=10,S="value",Oe=["previous","change","percentChange"];function Ct(e){return Oe.includes(e);}const gt=["up","down","flat"];function $n(e,t,n){const{signWords:r,absolute:s,percent:a,...i}=t??{};return e!=="change"&&e!=="percentChange"?i:{...i,...((n==null?void 0:n.signWords)===void 0?{signWords:gt}:{}),...((n==null?void 0:n.absolute)===void 0?{absolute:!0}:{}),...(e==="percentChange"&&(n==null?void 0:n.percent)===void 0?{percent:!0}:{})};}function ne(e){var r,s,a,i;if(e.get.kind!=="aggregate"||(r=e.query.sql)!=null&&r.trim())return;const t=(i=(a=(s=e.query.config)==null?void 0:s.metricColumns)==null?void 0:a[0])==null?void 0:i.comparison;if((t==null?void 0:t.mode)!=="explicit")return;const n=be(t.spec);return n.kind==="shift"?n:void 0;}function pe(e,t){if(t==="preview"&&e.get.kind!=="aggregate")return F+1;switch(e.get.kind){case"only":return 2;case"list":return F+1;default:return 1;}}const he={answer:/* @__PURE__ */new WeakMap(),preview:/* @__PURE__ */new WeakMap()};function kt(e,t="answer"){var a;const n=he[t].get(e);if(n)return n;const{query:r}=e,s={id:e.id,title:e.name,type:Ne,respondsToSelections:!1,dataVariableId:e.id,...(r.connectionId?{connectionId:r.connectionId}:{}),...(r.dataSource?{dataSource:r.dataSource}:{}),...(r.calculatedFields?{calculatedFields:r.calculatedFields}:{}),...((a=r.sql)!=null&&a.trim()?{sql:r.sql,config:{rowLimit:pe(e,t)}}:{config:{...r.config,rowLimit:pe(e,t)}})};return he[t].set(e,s),s;}function Pn(e){return e.type===Ne&&typeof e.dataVariableId=="string"&&e.dataVariableId.length>0;}function Ln(e,t,n){var r;if(n===S&&(r=e.query.sql)!=null&&r.trim()){const s=Object.keys(t)[0];return s===void 0?void 0:t[s];}return n in t?t[n]:void 0;}function Y(e){const t=H(e);return t==="string"||t==="unknown"?"text":t;}function wt(e){return typeof e=="number"?"number":typeof e=="boolean"?"boolean":"text";}function At(e,t,n,r){var i,o;const s=Je(r,e.id,t);return[s==null?void 0:s.outputKey,s==null?void 0:s.rawKey,t==="metric"?((o=(i=r==null?void 0:r.byMetricAlias)==null?void 0:i[U(e)])==null?void 0:o.outputKey)??U(e):void 0,te(e,t==="metric"?"metric":"groupby"),e.label,e.name].find(c=>!!c&&n.has(c));}function qn(e,t){var r;if(e.get.kind==="aggregate")return ne(e)?[S,...Oe]:[S];if(e.get.kind==="list")return[S];if((r=e.query.sql)!=null&&r.trim())return[...(t??[])];const n=e.query.config;return vt([...((n==null?void 0:n.groupByColumns)??[]).map(s=>s.name),...((n==null?void 0:n.metricColumns)??[]).map(s=>s.name)]);}function jn(e,t){var a,i,o,c;if(e.get.kind==="list")return"list";if((a=e.query.sql)!=null&&a.trim())return;const n=e.query.config,r=(u,d)=>{if(!u)return;const m=d==="metric"?z(u):u.dataType;return H(m)==="unknown"?void 0:Y(m);};if(e.get.kind==="aggregate")return Ct(t)&&ne(e)?"number":t===S?r((i=n==null?void 0:n.metricColumns)==null?void 0:i[0],"metric"):void 0;const s=(o=n==null?void 0:n.groupByColumns)==null?void 0:o.find(u=>u.name===t);return s?r(s,"groupby"):r((c=n==null?void 0:n.metricColumns)==null?void 0:c.find(u=>u.name===t),"metric");}function vt(e){return[...new Set(e)];}function Tt(e,t,n){var l,h,C;const r=t[0]??{},s=new Set((l=n.columns)!=null&&l.length?n.columns.map(p=>p.key):Object.keys(r)),a=new Map((n.columns??[]).map(p=>[p.key,p.dataType])),i=(p,k)=>a.has(p)?Y(a.get(p)):k!==void 0?Y(k):wt(r[p]);if((h=e.query.sql)!=null&&h.trim())return[...s].map(p=>({part:p,key:p,type:i(p,void 0)}));const o=e.query.config??{},c=[],u=s.size===1?[...s][0]:void 0,d=e.get.kind==="aggregate"||e.get.kind==="list",m=(p,k,se)=>{if(c.some(Pe=>Pe.part===se))return;const K=At(p,k,s,n.columnKeyMap)??(d?u:void 0);if(!K)return;const $e=k==="metric"?i(K,z(p)):i(K,p.dataType);c.push({part:se,key:K,type:$e});},I=o.metricColumns??[];if(e.get.kind==="aggregate"){const p=I[0]?(C=ee(n.comparisonMetadata,I[0]))==null?void 0:C.output.currentColumnKey:void 0;return p&&s.has(p)?c.push({part:S,key:p,type:i(p,z(I[0]))}):I[0]&&m(I[0],"metric",S),c;}const y=o.groupByColumns??[];if(e.get.kind==="list")return y[0]&&m(y[0],"groupby",S),c;for(const p of y)m(p,"groupby",p.name);for(const p of I)m(p,"metric",p.name);return c;}function G(e,t){return e==null?{value:null,type:t}:typeof e=="number"||typeof e=="boolean"||typeof e=="string"?{value:e,type:t}:e instanceof Date?{value:e.toISOString(),type:t}:{value:JSON.stringify(e),type:t};}function w(e){return!!e&&typeof e=="object"&&!Array.isArray(e);}function Bn(e){if(!w(e))return{};const t=w(e.data)?e.data:e,n=D(e).length?D(e):D(t),r=w(t.metadata)?t.metadata:void 0;return{...(t.records!==void 0?{records:t.records}:{}),...(Array.isArray(t.columns)?{columns:t.columns}:{}),...(w(t.columnKeyMap)?{columnKeyMap:t.columnKeyMap}:{}),...(n.length?{filterReach:n}:{}),...(r&&w(r.comparisonMetadata)?{comparisonMetadata:r.comparisonMetadata}:{}),...(typeof t.error=="string"&&t.error?{error:t.error}:{})};}function Un(e,t,n="answer"){var d;const r=(Array.isArray(t.records)?t.records:[]).filter(m=>!!m&&typeof m=="object"),s=D(t),a=n==="preview"?{matched:r.length>F?"beyondCap":r.length}:{};if(!r.length)return{status:"none",why:"noRows",filterReach:s,...a};const i=Tt(e,r,t);if(e.get.kind==="list"){const m=i[0],I=r.length>F,y=m?r.map(h=>G(h[m.key],m.type)).filter(h=>h.value!==null):[];if(!y.length&&!I)return{status:"none",why:"noRows",filterReach:s,...a};const l=Math.max(1,e.get.limit??St);return{status:"listed",items:y.slice(0,l),more:I?"beyondCap":Math.max(0,y.length-l),filterReach:s,...a};}if(e.get.kind==="only"&&r.length>1)return{status:"none",why:"moreThanOne",filterReach:s,...a};const o=r[0],c=Object.fromEntries(i.map(m=>[m.part,G(o[m.key],m.type)]));if(e.get.kind==="aggregate"&&((d=c[S])==null?void 0:d.value)==null)return{status:"none",why:"noRows",filterReach:s,...a};const u=ne(e)?Et(e,o,t):void 0;return{status:"answered",parts:u&&"parts"in u?{...c,...u.parts}:c,filterReach:s,...(u&&"unavailable"in u?{comparisonUnavailable:u.unavailable}:{}),...a};}function Et(e,t,n){var o,c;const r=(c=(o=e.query.config)==null?void 0:o.metricColumns)==null?void 0:c[0],s=r?ee(n.comparisonMetadata,r):void 0,a=s==null?void 0:s.output;if(!a||a.availability.status!=="available"||!a.comparisonColumnKey)return{unavailable:(a==null?void 0:a.availability.status)==="unavailable"?a.availability.reason:"temporal_binding_missing"};const i=u=>{const d=t[u],m=typeof d=="string"&&d.trim()!==""?Number(d):d;return G(typeof m=="number"&&!Number.isFinite(m)?null:m,"number");};return{parts:{previous:i(a.comparisonColumnKey),change:i(a.deltaColumnKey??""),percentChange:i(a.percentChangeColumnKey??"")}};}const ye=/* @__PURE__ */new WeakMap();function re(e){const t=ye.get(e);if(t)return t;const n=new Map((e.sheets??[]).map(a=>[a.id,a.kind==="document"?"document":"dashboard"])),r=[...V(e).map(a=>({kind:"card",id:a.cardId,card:a.card,sheetId:a.sheetId,sheetKind:n.get(a.sheetId)??"dashboard",...(a.kind==="documentSectionCard"?{sectionId:a.sectionId}:{})})),...(e.variables??[]).map(a=>({kind:"variable",id:a.id,variable:a,card:kt(a)}))],s={targets:r,byId:new Map(r.map(a=>[a.id,a]))};return ye.set(e,s),s;}function Kt(e){return re(e).targets;}function zn(e,t){return re(e).byId.get(t);}function Nt(e,t){return re(e).byId.has(t);}function Ot(e,t){return t.kind==="card"?[{sheetId:t.sheetId,cardId:t.id,sheetKind:t.sheetKind,...(t.sectionId?{sectionId:t.sectionId}:{})}]:Ae(e,t.id);}function Dt(e,t,n){return Ot(e,n).some(r=>g(t,r));}function Wn(e,t){return Kt(e).filter(n=>n.kind==="variable"&&Dt(e,t,n));}const Mt=["new","edit","delete","create","update","remove"];function De(e,t){return(e.sheets||[]).flatMap(n=>V({sheets:[n]}).filter(t).map(r=>({card:r.card,sheet:n,...(r.kind==="frameCard"&&{frameId:r.frameId}),...(r.kind==="documentSectionCard"&&{sectionId:r.sectionId})})));}function E(e){return De(e,t=>t.kind!=="documentSectionCard");}function Qn(e){return[...E(e),...De(e,t=>t.kind==="documentSectionCard")];}function Yn(e){return E(e).map(t=>t.card);}function Gn(e,t,n){return n&&t===n?!0:!Nt(e,t);}function Jn(e){return!e||e.trim().length===0?{isValid:!1,error:"Card ID cannot be empty"}:e.length<3?{isValid:!1,error:"Card ID must be at least 3 characters"}:e.length>50?{isValid:!1,error:"Card ID must be less than 50 characters"}:/^[a-zA-Z0-9-_]+$/.test(e)?/^[a-zA-Z0-9]/.test(e)?Mt.includes(e.toLowerCase())?{isValid:!1,error:`"${e}" is a reserved keyword and cannot be used`}:{isValid:!0}:{isValid:!1,error:"Card ID must start with a letter or number"}:{isValid:!1,error:"Card ID can only contain letters, numbers, hyphens, and underscores"};}function Hn(e,t){var n;return(n=xt(e,t))==null?void 0:n.card;}function xt(e,t){for(const n of E(e))if(n.card.id===t)return n;}function Xn(e,t){for(const n of e.sheets||[])for(const r of n.frames||[])for(const s of r.cards||[])if(s.id===t)return{card:s,sheet:n};}const J={bookmarksPerViewerPerDashboard:20,bookmarkNameMaxChars:100,columnLabelMaxChars:120,columnWidthMaxPx:4e3,tableSettingsMaxBytes:65536,rememberedTableSettingsMaxBytes:262144,bookmarkStateMaxBytes:65536},Me=1;function Zn(e){return new TextEncoder().encode(JSON.stringify(e??null)).length;}function Rt(e){const t=encodeURIComponent;switch(e.kind){case"dimension":return`dim:${e.role}:${t(e.fieldId)}`;case"metric":return`metric:${t(e.metricId)}:${t(e.metricAlias)}`;case"result":return`result:${t(e.key)}`;}}function O(e){if(e)try{return decodeURIComponent(e);}catch{return;}}function _t(e){if(typeof e!="string")return;const t=e.split(":");let n;if(t[0]==="dim"&&t.length===3){const r=t[1],s=O(t[2]);(r==="detail"||r==="groupby")&&s&&(n={kind:"dimension",role:r,fieldId:s});}else if(t[0]==="metric"&&t.length===3){const r=O(t[1]),s=O(t[2]);r&&s&&(n={kind:"metric",metricId:r,metricAlias:s});}else if(t[0]==="result"&&t.length===2){const r=O(t[1]);r&&(n={kind:"result",key:r});}return n&&Rt(n)===e?n:void 0;}function M(e){return typeof e=="string"&&_t(e)!==void 0;}const q=f.array(f.string()).max(2e3),Ft=f.object({order:q.optional(),hidden:q.optional(),labels:f.record(f.string(),f.string().max(J.columnLabelMaxChars)).optional(),sort:f.array(f.object({columnId:f.string(),direction:f.enum(["asc","desc"])}).strict()).max(2e3).optional(),widths:f.record(f.string(),f.number().int().min(1).max(J.columnWidthMaxPx)).optional(),pinned:q.optional()}).strict();function x(e){const t=/* @__PURE__ */new Set(),n=[];for(const r of e)!M(r)||t.has(r)||(t.add(r),n.push(r));return n;}function er(e){if(!Array.isArray(e))return;const t=x(e.filter(n=>typeof n=="string"));return t.length?t:void 0;}function xe(e){if(!e)return;const t=e.order?x(e.order):void 0,n=e.hidden?x(e.hidden):void 0,r=Object.entries(e.labels??{}).flatMap(([u,d])=>{const m=typeof d=="string"?d.trim():"";return M(u)&&m?[[u,m.slice(0,J.columnLabelMaxChars)]]:[];}),s=/* @__PURE__ */new Set(),a=e.sort?e.sort.filter(u=>!M(u.columnId)||s.has(u.columnId)?!1:(s.add(u.columnId),!0)):void 0,i=Object.entries(e.widths??{}).filter(([u])=>M(u)),o=e.pinned?x(e.pinned):void 0,c={};return t!=null&&t.length&&(c.order=t),n!=null&&n.length&&(c.hidden=n),r.length&&(c.labels=Object.fromEntries(r)),a&&(c.sort=a.map(({columnId:u,direction:d})=>({columnId:u,direction:d}))),i.length&&(c.widths=Object.fromEntries(i)),o&&(c.pinned=o),Object.keys(c).length?c:void 0;}function tr(e){var t,n;return!!((t=e==null?void 0:e.order)!=null&&t.length)||!!((n=e==null?void 0:e.hidden)!=null&&n.length)||Object.keys((e==null?void 0:e.labels)??{}).length>0||Object.keys((e==null?void 0:e.widths)??{}).length>0||(e==null?void 0:e.pinned)!==void 0;}function Re(e){return xe(e)===void 0;}function _e(e,t){if(t!==Me)return{ok:!1,error:`Unsupported table settings version ${t}.`};const n=Ft.safeParse(e);return n.success?{ok:!0,value:xe(n.data)??{}}:{ok:!1,error:"Table settings are invalid."};}function nr(e,t,n){if(!e||typeof e!="object"||Array.isArray(e))return{};const r={};for(const[s,a]of Object.entries(e)){if(!n.has(s))continue;const i=_e(a,t);i.ok&&!Re(i.value)&&(r[s]=i.value);}return r;}const Vt=/* @__PURE__ */new Set(["table","detailTable"]);function Fe(e){return Vt.has(e.type);}function $t(e){var t,n;return Fe(e)&&((n=(t=e.preferences)==null?void 0:t.tablePrefs)==null?void 0:n.allowViewerColumnCustomization)!==!1;}function rr(e){return new Set(E(e).filter(({card:t})=>Fe(t)).map(({card:t})=>t.id));}function sr(e){return new Set(E(e).filter(({card:t})=>$t(t)).map(({card:t})=>t.id));}const Pt={date:/* @__PURE__ */new Set(["between","not between","=","!=",">",">=","<","<=","is null","is not null"]),number:/* @__PURE__ */new Set(["between","not between","=","!=",">",">=","<","<=","in","not in","is null","is not null"]),string:/* @__PURE__ */new Set(["=","!=","in","not in","like","not like","is null","is not null"]),boolean:/* @__PURE__ */new Set(["=","!=","in","not in","is null","is not null"])};function Lt(e){const t=H(e);return t==="number"||t==="boolean"?t:t==="date"||t==="datetime"?"date":"string";}function ar(e,t){return typeof t!="string"?!1:Pt[Lt(e)].has(t);}const qt=/* @__PURE__ */new Set(["=",">","<",">=","<=","!=","in","not in","like","not like","between","not between","is null","is not null"]);function jt(e,t){return t==="number"?typeof e=="number"&&Number.isFinite(e):t==="boolean"?typeof e=="boolean":t==="date"?e instanceof Date||typeof e=="string"&&e.trim().length>0:typeof e=="string"||typeof e=="number"||typeof e=="boolean";}function Bt(e,t,n,r){const s=qe(e.relativeMeta);if(s&&We(s).dataAnchored){r.push(`${n}.relativeMeta counts back from the latest data; a dashboard filter's dates run to now. Use a period counted back from today.`);return;}if(s&&!je(String(e.operation),s)){r.push(`${n}.relativeMeta runs only under between, not between, before, after, on or before, or on or after.`);return;}Ut(e.operation,e.values,t,`${n}.values`,r);}function Ut(e,t,n,r,s){if(e==="is null"||e==="is not null"){t.length!==0&&s.push(`${r} must be empty for null filter operations.`);return;}if(e==="between"||e==="not between"){if(t.length!==2){s.push(`${r} must contain exactly two values for between operations.`);return;}}else if(e==="in"||e==="not in"){if(t.length===0){s.push(`${r} must contain at least one value for set operations.`);return;}}else if(t.length!==1){s.push(`${r} must contain exactly one value for '${String(e)}' operations.`);return;}for(const a of t)if(!jt(a,n)){s.push(`${r} contains a value that is incompatible with valueType '${n}'.`);return;}}const j=1,ir=["PRIVATE","TEAM","DASHBOARD"],zt=f.object({filterId:f.string().min(1),name:f.string(),operation:f.string(),valueType:f.enum(["string","number","date","boolean"]),values:f.array(f.unknown())}).passthrough().superRefine((e,t)=>{const n=[];qt.has(e.operation)?Bt(e,e.valueType,"filterValue",n):n.push("filterValue.operation must be a valid filter operation.");for(const r of n)t.addIssue({code:"custom",message:r});}),B=f.unknown().superRefine((e,t)=>{for(const n of Qe(e).errors)t.addIssue({code:"custom",message:n.message});}),Wt=f.discriminatedUnion("kind",[f.object({kind:f.literal("filter"),filterValue:zt}).strict(),f.object({kind:f.literal("control"),value:f.unknown()}).strict(),f.object({kind:f.literal("selection"),selection:Ye}).strict()]),Qt=f.union([f.object({status:f.literal("set"),value:Wt,comparisonSelection:B.optional()}).strict(),f.object({status:f.literal("cleared"),comparisonSelection:B.optional()}).strict(),f.object({comparisonSelection:B}).strict()]),Ve=["bySheetId","byCardId","byDocumentSectionId"],Yt=/* @__PURE__ */new Set(["version","selectedSheetId","inputs","tableSettings"]),Gt=/* @__PURE__ */new Set(["shared",...Ve]),A=e=>!!e&&typeof e=="object"&&!Array.isArray(e);function Ie(e,t,n){if(e===void 0)return;if(!A(e)){t.push({target:"input",id:n});return;}const r={};for(const[s,a]of Object.entries(e)){const i=s?Qt.safeParse(a):void 0;i!=null&&i.success?r[s]=i.data:t.push({target:Ge(s)?"selection":"input",id:s});}return Object.keys(r).length?r:void 0;}function Jt(e,t){if(t!==j)return{ok:!1,error:`Unsupported bookmark version ${t}.`};if(!A(e)||e.version!==j)return{ok:!1,error:"The bookmark state is invalid."};const n=[],r=Object.keys(e).filter(o=>!Yt.has(o));let s;typeof e.selectedSheetId=="string"&&e.selectedSheetId?s=e.selectedSheetId:e.selectedSheetId!==void 0&&n.push({target:"sheet",id:String(e.selectedSheetId)});const a={};if(A(e.inputs)){r.push(...Object.keys(e.inputs).filter(c=>!Gt.has(c)).map(c=>`inputs.${c}`));const o=Ie(e.inputs.shared,n,"shared");o&&(a.shared=o);for(const c of Ve){const u=e.inputs[c];if(u===void 0)continue;if(!A(u)){n.push({target:"input",id:c});continue;}const d={};for(const[m,I]of Object.entries(u)){const y=Ie(I,n,`${c}.${m}`);y&&(d[m]=y);}Object.keys(d).length&&(a[c]=d);}}else e.inputs!==void 0&&r.push("inputs");const i={};if(A(e.tableSettings))for(const[o,c]of Object.entries(e.tableSettings)){const u=o?_e(c,Me):void 0;u!=null&&u.ok?Re(u.value)||(i[o]=u.value):n.push({target:"card",id:o});}else e.tableSettings!==void 0&&r.push("tableSettings");return{ok:!0,value:{version:j,...(s?{selectedSheetId:s}:{}),...(Object.keys(a).length?{inputs:a}:{}),...(Object.keys(i).length?{tableSettings:i}:{})},issues:n,unknownKeys:r};}function or(e,t){const n=Jt(e,t);return n.ok?n.issues.some(r=>r.target==="card")?{ok:!1,error:"The bookmark table settings are invalid."}:n.issues.length||n.unknownKeys.length?{ok:!1,error:"The bookmark state is invalid."}:{ok:!0,value:n.value}:n;}export{Ee as $,Hn as A,j as B,Nn as C,Yn as D,Kn as E,Fn as F,He as G,_n as H,Ze as I,V as J,g as K,mn as L,zn as M,On as N,un as O,xt as P,Kt as Q,ut as R,In as S,me as T,at as U,J as V,ln as W,we as X,Sn as Y,qn as Z,te as _,gn as a,bt as a0,Ke as a1,Vn as a2,ae as a3,ie as a4,Xe as a5,rn as a6,sn as a7,fn as a8,pn as a9,Wn as aA,Lt as aB,ar as aC,qt as aD,Bt as aE,on as aF,nt as aG,v as aH,E as aI,yt as aJ,ee as aK,Mn as aL,xn as aM,Dn as aN,Rn as aO,oe as aP,Qn as aQ,et as aR,Gn as aS,Jn as aT,Xn as aU,an as aV,hn as aa,yn as ab,bn as ac,Cn as ad,Ne as ae,F as af,St as ag,S as ah,Oe as ai,Ct as aj,gt as ak,$n as al,ne as am,kt as an,Pn as ao,Ln as ap,jn as aq,Bn as ar,Un as as,cn as at,st as au,dn as av,Ae as aw,Nt as ax,Ot as ay,Dt as az,wn as b,ve as c,Q as d,An as e,vn as f,Tn as g,En as h,Jt as i,Me as j,_t as k,xe as l,Zn as m,er as n,tr as o,or as p,Re as q,kn as r,_e as s,Rt as t,nr as u,Fe as v,$t as w,rr as x,sr as y,ir as z};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{A as P}from"./schema-O1Y3WTGF.js";import{D as A,d as S,a as f,s as v,w as D,A as _,r as b,b as g}from"./resolver-CjsW8Rz0.js";import{n as h}from"./index-bkP6SnYu.js";import{c as y,a as R,d as k,r as E}from"./filter-reach-preview-
|
|
1
|
+
import{A as P}from"./schema-O1Y3WTGF.js";import{D as A,d as S,a as f,s as v,w as D,A as _,r as b,b as g}from"./resolver-CjsW8Rz0.js";import{n as h}from"./index-bkP6SnYu.js";import{c as y,a as R,d as k,r as E}from"./filter-reach-preview-DSH_k8AJ.js";const p=["light","dark"],O=/* @__PURE__ */new Set(["canvas","chartColors"]);function H(o){const s=y(o.edit);if(s)return{ok:!1,refusal:s};const r=o.spec?h(o.spec).spec:null,e=r??{version:P},i=R(C(e),o.edit,o.mode);let a={...(e.schemes??{})};for(const c of p){let t=a[c]??{};for(const d of A){t=S(t,f[d]);const l=v(i,d,c);l!==void 0&&(t=D(t,f[d],l));}for(const{alias:d,canonical:l}of _)A.some(u=>B(f[u],l))&&(t=S(t,d));a={...a,[c]:t};}const n=h({...e,schemes:a}).spec,m=c=>{const t=g({organizationAppearance:c});return{light:E(t,"light"),dark:E(t,"dark")};};return{ok:!0,spec:n,sentences:k({edit:o.edit,before:m(r),after:m(n),resetAll:"Resets the brand's dashboard style to the defaults"})};}function C(o){var r;const s={};for(const e of A)for(const i of p){const a=b((r=o.schemes)==null?void 0:r[i],f[e]);if(a===void 0)continue;const n=e==="cardBorder"?a===0?"off":"on":a;O.has(e)?s[e]={...s[e],[i]:n}:s[e]??(s[e]=n);}return s;}function B(o,s){return o.join(".")===s.join(".");}export{H as e};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import{c as pt,u as Bt,F as pe,an as Ut,ao as Wt,ap as Kt,aq as Qt,ar as Ht,as as Yt,at as Xt,B,au as Jt,d as ge,ac as Xe,af as mt,av as re,a2 as be,a4 as le,a5 as ie,a6 as oe,a7 as de,a8 as ee,aa as Ve,aw as Pt,ax as Zt,ay as ft,az as Je,aA as ea,aB as ta,aC as ce,P as ht,b as gt,X as bt,e as xt,aD as vt,aE as aa,aF as ra,aG as na,aH as sa,aI as la,ag as ia,ab as oa,aJ as yt}from"./appearance-provider-BBYTKSjL.js";import{jsx as e,jsxs as c,Fragment as me}from"react/jsx-runtime";import{n as U,aD as da,aE as fe,aF as Pe,aG as Ze,aH as Oe,aI as Ae,aJ as ca,aK as ua,aL as et,aM as pa,aN as ma,aO as he,aP as fa,aQ as tt,aR as Nt,aS as Ct,aT as wt,aU as St,aV as ha,aW as ga,aX as at,aY as ba,aZ as rt,a_ as xa,a$ as va,b0 as ya,b1 as Na,b2 as Ee,e as xe,b3 as nt,b4 as Ca,b5 as Fe,b6 as wa,b7 as Sa,b8 as ka,b9 as Da,ba as Ta}from"./resolve-dashboard-input-context-B5yUS9ZM.js";import{k as kt,r as La,aE as Dt,aF as Tt}from"./validators-U8IL8djK.js";import{a as Lt}from"./matrix-operation-contract-DceN49RX.js";import"./analytics-base-schemas-DMFrDqn_.js";import"../value-format-preferences/index.js";import{u as Oa,as as st,at as Aa,au as Ot,av as At,aw as Ea,ax as Fa,ay as Ia,az as $a,aA as Va,aB as _a,aC as lt,aD as _e,aE as se,aF as Re,aG as ze,aH as Ge,aI as Ra,aJ as ve,aK as ye,aL as Ne,aM as Ce,aN as Et,aO as Ft,aP as za}from"./semaphor-ready-indicator-Cq3C2SNo.js";import*as we from"react";import{useMemo as Z,useState as te,useRef as Ie,useCallback as P,useEffect as Me,Fragment as Ga}from"react";import{r as Ma,m as qa}from"./raw-temporal-value-B4Md6Xfb.js";/**
|
|
2
|
+
* @license lucide-react v0.453.0 - ISC
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the ISC license.
|
|
5
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
6
|
+
*/const xr=pt("FilterX",[["path",{d:"M13.013 3H2l8 9.46V19l4 2v-8.54l.9-1.055",key:"1fi1da"}],["path",{d:"m22 3-5 5",key:"12jva0"}],["path",{d:"m17 3 5 5",key:"k36vhe"}]]);/**
|
|
7
|
+
* @license lucide-react v0.453.0 - ISC
|
|
8
|
+
*
|
|
9
|
+
* This source code is licensed under the ISC license.
|
|
10
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
11
|
+
*/const ja=pt("Library",[["path",{d:"m16 6 4 14",key:"ji33uf"}],["path",{d:"M12 6v14",key:"1n7gus"}],["path",{d:"M8 8v12",key:"1gg7y9"}],["path",{d:"M4 4v16",key:"6qkkli"}]]);function vr({type:t,isLinked:r,className:s,showLabel:i=!1,showLocal:F=!1}){const h=Bt(O=>O.selectedFrameId),k=Oa(O=>O.selectedVisual),b=pe(O=>O.frame);let m;if(t)m=t;else if(r!==void 0)m=r?"linked":"library";else if(!!!(b!=null&&b.visualId||k!=null&&k.id)&&h)m="local";else if(k&&!h)m="library";else if(b!=null&&b.visualId&&h)m="linked";else if(k!=null&&k.id&&h)m="library";else return null;if(m==="local"&&!F)return null;const x={local:"border-slate-200/70 bg-slate-50/80 text-slate-700 shadow-sm hover:bg-slate-100/80 dark:border-slate-700 dark:bg-slate-900/70 dark:text-slate-200 dark:hover:bg-slate-800/80",linked:"border-purple-200/70 bg-gradient-to-r from-purple-50/50 to-purple-100/30 text-purple-900 shadow-sm hover:from-purple-100/60 hover:to-purple-100/50 hover:shadow-md dark:border-purple-800/50 dark:from-purple-950/40 dark:to-purple-900/30 dark:text-purple-100 dark:hover:from-purple-950/60 dark:hover:to-purple-900/50",library:"border-blue-200/70 bg-gradient-to-r from-blue-50/50 to-blue-100/30 text-blue-900 shadow-sm hover:from-blue-100/60 hover:to-blue-100/50 hover:shadow-md dark:border-blue-800/50 dark:from-blue-950/40 dark:to-blue-900/30 dark:text-blue-100 dark:hover:from-blue-950/60 dark:hover:to-blue-900/50"},L={local:"Local to this dashboard: Changes made here only affect this dashboard copy.",linked:"Linked to library: Changes made here update the library visual and all linked instances.",library:"Library visual: Share and reuse this visual across multiple dashboards."},N={local:"border-slate-200 bg-slate-50 text-slate-900 dark:border-slate-700 dark:bg-slate-900 dark:text-slate-100",linked:"border-purple-200 bg-purple-50 text-purple-900 dark:border-purple-800 dark:bg-purple-950 dark:text-purple-100",library:"border-blue-200 bg-blue-50 text-blue-900 dark:border-blue-800 dark:bg-blue-950 dark:text-blue-100"},I={local:"fill-slate-50 dark:fill-slate-900",linked:"fill-purple-50 dark:fill-purple-950",library:"fill-blue-50 dark:fill-blue-950"},S={local:/* @__PURE__ */e("span",{className:"h-2 w-2 rounded-full bg-current/70"}),linked:/* @__PURE__ */e(Xt,{className:"h-3.5 w-3.5"}),library:/* @__PURE__ */e(ja,{className:"h-3.5 w-3.5"})},y={local:"Local",linked:"Linked",library:"Library"};return/* @__PURE__ */e(Ut,{children:/* @__PURE__ */c(Wt,{delayDuration:300,children:[/* @__PURE__ */e(Kt,{asChild:!0,children:/* @__PURE__ */c(Qt,{variant:"outline",className:U("cursor-help select-none transition-all",x[m],s),children:[S[m],i&&/* @__PURE__ */e("span",{className:"ml-1 text-xs font-medium leading-none",children:y[m]})]})}),/* @__PURE__ */c(Ht,{side:"bottom",className:U("max-w-xs",N[m]),children:[/* @__PURE__ */e(Yt,{className:I[m]}),/* @__PURE__ */e("p",{children:L[m]})]})]})});}function It(t){const{control:r,onChange:s}=t;return/* @__PURE__ */c("div",{className:"flex flex-col gap-1.5",children:[/* @__PURE__ */e(re,{className:"text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground",children:"Label"}),/* @__PURE__ */e(be,{size:"xs",value:r.label,placeholder:"Control label",onChange:i=>s(i.target.value)})]});}function Ba(t){const{currentStep:r,labels:s}=t;return/* @__PURE__ */e("div",{className:"sticky top-0 z-10 -mx-1 border-b border-border/60 bg-background/95 px-1 pb-2.5 pt-1 backdrop-blur supports-[backdrop-filter]:bg-background/85",children:/* @__PURE__ */e("div",{className:"flex flex-wrap items-center gap-2 sm:gap-2.5",children:s.map((i,F)=>{const h=F+1,k=h===r,b=h<r;return/* @__PURE__ */c(Ga,{children:[/* @__PURE__ */c("div",{className:"flex items-center gap-1.5",children:[/* @__PURE__ */e("span",{className:U("flex h-5 w-5 items-center justify-center rounded-full border text-[10px] font-medium tabular-nums",k?"border-foreground bg-foreground text-background":b?"border-foreground/30 bg-foreground/10 text-foreground":"border-border/60 bg-background text-muted-foreground"),children:h}),/* @__PURE__ */e("span",{className:U("text-[12px]",k?"font-medium text-foreground":"text-muted-foreground"),children:i})]}),F<s.length-1?/* @__PURE__ */e("span",{className:"h-px w-4 bg-border/60 sm:w-6","aria-hidden":"true"}):null]},i);})})});}function Se(t){const{secondary:r,tertiary:s,primary:i}=t;return/* @__PURE__ */c("div",{className:"sticky bottom-0 z-10 -mx-1 flex justify-end gap-2 border-t bg-background/95 px-1 pb-1 pt-3 backdrop-blur supports-[backdrop-filter]:bg-background/85",children:[r,s,i]});}function Ua(t){const{control:r,scope:s,detail:i}=t;return/* @__PURE__ */c("div",{className:"flex items-start gap-2.5 rounded-control border border-border/60 bg-muted/30 px-3 py-2.5",children:[/* @__PURE__ */e(Pt,{className:"mt-0.5 h-3.5 w-3.5 shrink-0 text-foreground"}),/* @__PURE__ */c("div",{className:"min-w-0 space-y-0.5",children:[/* @__PURE__ */e("div",{className:"text-[13px] font-medium text-foreground",children:r.label}),/* @__PURE__ */c("div",{className:"text-[12px] text-muted-foreground",children:[Nt(r.type).label," ·"," ",wt(r)," ·"," ",Ct(s,r.placement)]}),i?/* @__PURE__ */e("div",{className:"text-[12px] text-muted-foreground",children:i}):null]})]});}function it(t){const{control:r,defaultValue:s,availableFieldChoices:i,availableMetricChoices:F,previewControlDefinitions:h,previewControlValues:k,onControlChange:b,onLabelChange:m,onDefaultValueChange:x,onBack:L,onNext:N,nextDisabled:I}=t;return/* @__PURE__ */c("div",{className:"space-y-3",children:[/* @__PURE__ */e(It,{control:r,onChange:m}),/* @__PURE__ */e(Ot,{control:r,availableFieldChoices:i,availableMetricChoices:F,previewControlDefinitions:h,previewControlValues:k,controlLifecycle:"create",onChange:b}),/* @__PURE__ */e(At,{control:r,value:s,onChange:x,allowNoDefault:!0,allowCardDefault:!0,hint:"This is the value viewers will see first.",previewControlDefinitions:h,previewControlValues:k}),/* @__PURE__ */e(Se,{secondary:/* @__PURE__ */e(B,{type:"button",variant:"outline",size:"xs",onClick:L,children:"Back"}),primary:/* @__PURE__ */e(B,{type:"button",size:"xs",onClick:N,disabled:I,children:"Next"})})]});}const Wa=/* @__PURE__ */new Set(["grain_selector","aggregation_selector","field_selector","metric_selector"]);function ot(t){const{text:r,ariaLabel:s}=t,[i,F]=te(!1);return/* @__PURE__ */c("button",{type:"button","aria-label":s,onClick:async()=>{try{await navigator.clipboard.writeText(r),F(!0),setTimeout(()=>F(!1),1200);}catch(h){console.error("Failed to copy",h);}},className:"group flex w-full items-center justify-between gap-2 rounded-control bg-muted/40 px-2 py-1 text-left transition-colors hover:bg-muted/60 focus-visible:bg-muted/60 focus-visible:outline-none",children:[/* @__PURE__ */e("code",{className:"min-w-0 truncate font-mono text-[12px] text-foreground",children:r}),/* @__PURE__ */e("span",{className:"shrink-0 text-[11px] text-muted-foreground opacity-0 transition-opacity group-hover:opacity-100",children:i?"Copied":"Click to copy"})]});}function dt(t){const{control:r,scope:s,createdReference:i,explorerContent:F,sqlDescription:h,summaryDetail:k,onBack:b,onCancel:m,onDone:x}=t,L=Wa.has(r.type),N=i.match(/\[\[param\.(.+?)\]\]/),I=N?`{{ param('${N[1]}') }}`:"";return/* @__PURE__ */c("div",{className:"space-y-4",children:[/* @__PURE__ */e(Ua,{control:r,scope:s,detail:k}),/* @__PURE__ */c("div",{className:"space-y-2",children:[/* @__PURE__ */e("p",{className:"text-[13px] font-medium text-foreground",children:"How cards use this control"}),/* @__PURE__ */c("div",{className:"divide-y divide-border/60 overflow-hidden rounded-control border border-border/60",children:[L?/* @__PURE__ */c("div",{className:"space-y-1 px-3 py-2.5",children:[/* @__PURE__ */e("p",{className:"text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground",children:"Explorer cards"}),/* @__PURE__ */e("div",{className:"text-[12px] text-muted-foreground",children:F})]}):null,/* @__PURE__ */c("div",{className:"space-y-1.5 px-3 py-2.5",children:[/* @__PURE__ */e("p",{className:"text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground",children:"SQL cards"}),/* @__PURE__ */e(ot,{text:i,ariaLabel:"Copy SQL control reference"}),I?/* @__PURE__ */e(ot,{text:I,ariaLabel:"Copy Jinja control reference"}):null,/* @__PURE__ */c("p",{className:"text-[12px] text-muted-foreground",children:[h," ",/* @__PURE__ */e("a",{href:"https://docs.semaphor.cloud/docs/concepts/template-expressions",target:"_blank",rel:"noreferrer",className:"underline underline-offset-2 hover:text-foreground",children:"Template expressions docs"}),"."]})]})]})]}),/* @__PURE__ */e(Se,{secondary:/* @__PURE__ */e(B,{type:"button",variant:"outline",size:"xs",onClick:b,children:"Back"}),tertiary:/* @__PURE__ */e(B,{type:"button",variant:"outline",size:"xs",onClick:m,children:"Cancel"}),primary:/* @__PURE__ */e(B,{type:"button",size:"xs",onClick:x,children:"Done"})})]});}function Ka(t){const r=fe(t.scope,t.existingControls,t.reservedIds),s=t.type===r.type?{...r,label:Ee[t.type]}:{...St({controls:[{...r,label:Ee[t.type]}],controlId:r.id,nextType:t.type}).controls[0],label:Ee[t.type]};return{step:2,control:s,defaultValue:he(s,void 0)};}function yr({scope:t,controls:r,reservedControlIds:s,defaultValues:i,onChange:F,emptyMessage:h,initialCreateFlow:k=!1,usageByControlId:b,availableFieldChoices:m,availableMetricChoices:x,structuralParticipants:L,structuralParticipantIdsByControlId:N,card:I,allowedControlTypes:S,onCreateFlowActiveChange:y,onCreateFlowComplete:O}){const z=Z(()=>new Set(s||[]),[s]),$=ha(t),X=da(t),[D,T]=te(null),[Q,Y]=te(null),[n,g]=te(()=>k?{step:1,control:fe(t,r,Array.from(z))}:null),C=Ie({}),f=Ie(void 0),d=Ie(k),l=Z(()=>{const a=Pe({scope:t,card:I});if(!S)return a;const u=new Set(S);return a.filter(o=>u.has(o.value));},[S,I,t]),V=P(a=>{const u=Pe({scope:t,card:I,includeType:S?void 0:a});if(!S)return u;const o=new Set(S);return u.filter(v=>o.has(v.value));},[S,I,t]),p=P(a=>t==="dashboard"&&(a==="field_selector"||a==="metric_selector"),[t]),K=Z(()=>n?Ze(L||[],n.control.type):[],[n,L]),A=Z(()=>{if(!n)return{fields:m||[],metrics:x||[]};if(!p(n.control.type))return{fields:m||[],metrics:x||[]};const a=n.selectedCardIds||[],u=Oe({controlType:n.control.type,participants:L||[],selectedCardIds:a});return{fields:n.control.type==="field_selector"?u.choices.map(o=>({option:o,target:u.fieldTargetMap[o.value]})):[],metrics:n.control.type==="metric_selector"?u.choices.map(o=>({option:o,target:u.metricTargetMap[o.value]})):[]};},[m,x,n,p,L]);Me(()=>{y==null||y(!!n);},[n,y]),Me(()=>{const a=k&&!d.current;d.current=k,a&&(g({step:1,control:fe(t,r,Array.from(z))}),Y(null),T(null));},[r,k,z,t]);const R=a=>{if(!p(a.type))return{fields:m||[],metrics:x||[]};const u=(N==null?void 0:N[a.id])||[];if(u.length===0)return{fields:m||[],metrics:x||[]};const o=Oe({controlType:a.type,participants:L||[],selectedCardIds:u});return{fields:a.type==="field_selector"?o.choices.map(v=>({option:v,target:o.fieldTargetMap[v.value]})):[],metrics:a.type==="metric_selector"?o.choices.map(v=>({option:v,target:o.metricTargetMap[v.value]})):[]};},q=a=>{if(!p(a.control.type))return{nextControl:a.control,cardBindingsById:void 0};const u=(N==null?void 0:N[a.control.id])||[],o=Oe({controlType:a.control.type,participants:L||[],selectedCardIds:a.nextSelectedCardIds}),v=ya({control:a.control,choices:o.choices}),E=Object.fromEntries(u.filter(_=>!a.nextSelectedCardIds.includes(_)).map(_=>[_,void 0]));return a.nextSelectedCardIds.length>0&&v.source.kind==="manual"&&v.source.options.length>0&&Object.assign(E,rt({control:v,participants:L||[],selectedCardIds:a.nextSelectedCardIds,matrixTargetIds:a.matrixTargetIds})),{nextControl:v,cardBindingsById:E};},j=P((a,u=i,o={type:"update"})=>{const v=a.map(E=>(Ae({control:E,defaultValues:u}),ca(E)));F(v,u,o);},[i,F]),H=(a,u)=>{const o=r.find(M=>M.id===a);let v=r.map(M=>M.id!==a?M:u(M));const E=v.find(M=>M.id===a);let _,w;if(E&&(!o||xa({control:o},{control:E}))&&t==="dashboard"&&(E.type==="field_selector"||E.type==="metric_selector")){const M=(N==null?void 0:N[E.id])||[],ne=q({control:E,nextSelectedCardIds:M});v=v.map(ae=>ae.id===a?ne.nextControl:ae),_=ne.cardBindingsById,w=[E.id];}else if(o&&(!E||!va(E.type))&&t==="dashboard"&&(o.type==="field_selector"||o.type==="metric_selector")){const M=(N==null?void 0:N[o.id])||[];_=Object.fromEntries(M.map(ne=>[ne,void 0])),w=[o.id];}const G=v.find(M=>M.id===a);let W=i;if(o&&G){const M=Ae({control:o,defaultValues:i});o.source.kind==="manual"&&G.source.kind==="sql_query"&&(C.current[a]=M);const ne=M===void 0&&o.source.kind==="sql_query"&&G.source.kind==="manual"?C.current[a]:M,ae=at({previousControl:o,nextControl:G,currentDefaultValue:ne});G.source.kind==="manual"&&(C.current[a]=ae),i&&(W={...i},ae===void 0?delete W[a]:W[a]=ae),v=v.map(Ye=>Ye.id===a?{...G,defaultValue:ae}:Ye);}j(v,W,{type:"update",cardBindingsById:_,affectedBindingControlIds:w});},J=(a,u)=>{if(!u.trim())return;const o=Na(u);if(o===a||z.has(o)||r.some(_=>_.id===o&&_.id!==a))return;const v=r.map(_=>_.id===a?{..._,id:o}:_);if(!i){j(v,void 0,{type:"rename",oldId:a,newId:o});return;}const E={...i};Object.prototype.hasOwnProperty.call(E,a)&&(E[o]=E[a],delete E[a]),j(v,E,{type:"rename",oldId:a,newId:o});},Mt=a=>{const u=r.filter(v=>v.id!==a);if(!i){j(u,void 0,{type:"remove",controlId:a});return;}const o={...i};delete o[a],j(u,o,{type:"remove",controlId:a});},qt=P(()=>{f.current=void 0,g({step:1,control:fe(t,r,Array.from(z))}),Y(null),T(null);},[r,z,t]),ue=a=>{g(u=>u&&(()=>{const o=a(u.control);u.control.source.kind==="manual"&&o.source.kind==="sql_query"&&(f.current=u.defaultValue);const v=u.defaultValue===void 0&&u.control.source.kind==="sql_query"&&o.source.kind==="manual"?f.current:u.defaultValue,E=at({previousControl:u.control,nextControl:o,currentDefaultValue:v});return o.source.kind==="manual"&&(f.current=E),{...u,control:o,defaultValue:E};})());},Ue=a=>{g(u=>u&&(u.control.source.kind==="manual"&&(f.current=a),{...u,defaultValue:a}));},ke=(()=>{if(!n)return!1;if(n.step===2&&p(n.control.type))return(n.selectedCardIds||[]).length>0&&ua({participants:L||[],selectedCardIds:n.selectedCardIds||[],control:n.control,selected:n.matrixTargetIds});if(n.step!==2&&n.step!==3||!n.control.label.trim())return!1;const u=n.control.source.kind==="sql_query"?n.control:et(n.control);if(u.source.kind==="manual"&&(pa(u)&&u.source.options.length===0||u.source.options.some(v=>v.label.trim().length===0||v.value.trim().length===0)))return!1;if(u.source.kind==="sql_query"){const{connectionId:o,sql:v,valueColumn:E}=u.source;return o.trim().length>0&&v.trim().length>0&&E.trim().length>0;}return ma(he(u,n.defaultValue));})(),We=()=>{var _;if(!n)return;const a=et(n.control),u=ba({label:a.label,fallbackId:a.id,existingControls:r,reservedIds:Array.from(z)}),o={...a,id:u},v=t==="dashboard"&&(o.type==="field_selector"||o.type==="metric_selector")&&(_=n.selectedCardIds)!=null&&_.length?rt({control:o,participants:L||[],selectedCardIds:n.selectedCardIds,matrixTargetIds:n.matrixTargetIds}):void 0,E=he(o,n.defaultValue);g({step:t==="dashboard"&&(o.type==="field_selector"||o.type==="metric_selector")?4:3,control:o,defaultValue:E,createdControlId:u,selectedCardIds:n.selectedCardIds,matrixTargetIds:n.matrixTargetIds,cardBindingsById:v});},De=P(()=>{g(null);},[]),Ke=P(()=>{if(!(n!=null&&n.createdControlId)){g(null);return;}const a=n.control,u=n.createdControlId,o=he(a,n.defaultValue);if(i){const v={...i};o===void 0?delete v[u]:v[u]=o,j([...r,{...a,defaultValue:o}],v,{type:"add",cardBindingsById:n.cardBindingsById});}else j([...r,{...a,defaultValue:o}],void 0,{type:"add",cardBindingsById:n.cardBindingsById});Y(u),g(null),O==null||O();},[r,n,i,j,O]),jt=n?p(n.control.type)?["Choose type","Select cards","Configure","Finish"]:["Choose type","Configure","Finish"]:[],Qe=n!=null&&n.createdControlId?`[[param.${n.createdControlId}]]`:n?`[[param.${fa(n.control.label)||n.control.id}]]`:"",Te=tt({controls:r,defaultValues:i}),Le=n?[...r,n.control]:r,He=n?tt({controls:Le,defaultValues:i,overrides:[{controlId:n.control.id,value:n.defaultValue}]}):Te;return/* @__PURE__ */c("div",{className:"space-y-4",children:[n?/* @__PURE__ */c("div",{className:"space-y-4 pb-1",children:[/* @__PURE__ */e(Ba,{currentStep:n.step,labels:jt}),n.step===1&&(()=>{const a=/* @__PURE__ */new Set(["grain_selector","aggregation_selector","field_selector","metric_selector"]),u=/* @__PURE__ */new Set(["date","text"]),o=l.filter(_=>!a.has(_.value)&&!u.has(_.value)),v=l.filter(_=>a.has(_.value)),E=_=>/* @__PURE__ */c("button",{type:"button",className:"rounded-control border border-border/60 bg-background px-3 py-2.5 text-left transition-colors hover:bg-muted/40 focus-visible:bg-muted/40 focus-visible:outline-none",onClick:()=>g(Ka({scope:t,existingControls:r,reservedIds:Array.from(z),type:_.value})),children:[/* @__PURE__ */e("div",{className:"text-[13px] font-medium text-foreground",children:_.label}),/* @__PURE__ */e("p",{className:"mt-0.5 text-[12px] text-muted-foreground",children:_.description})]},_.value);return/* @__PURE__ */c("div",{className:"space-y-4",children:[t==="card"&&(I==null?void 0:I.sql)==null?/* @__PURE__ */e("p",{className:"text-[12px] text-muted-foreground",children:"Explorer cards support displayed metric, group by field, aggregation, and time grain controls here."}):null,o.length>0&&/* @__PURE__ */c("div",{className:"space-y-1.5",children:[/* @__PURE__ */e("p",{className:"text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground",children:"Input controls"}),/* @__PURE__ */e("div",{className:"grid gap-1.5 sm:grid-cols-2",children:o.map(E)})]}),v.length>0&&/* @__PURE__ */c("div",{className:"space-y-1.5",children:[/* @__PURE__ */e("p",{className:"text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground",children:"Data-driven controls"}),/* @__PURE__ */e("div",{className:"grid gap-1.5 sm:grid-cols-2",children:v.map(E)})]}),/* @__PURE__ */e(Se,{secondary:/* @__PURE__ */e(B,{type:"button",variant:"outline",size:"xs",onClick:De,children:"Back to controls"})})]});})(),n.step===2&&p(n.control.type)&&/* @__PURE__ */c("div",{className:"space-y-3",children:[/* @__PURE__ */c("div",{className:"space-y-3",children:[/* @__PURE__ */e(It,{control:n.control,onChange:a=>ue(u=>({...u,label:a}))}),/* @__PURE__ */e("p",{className:"text-[12px] text-muted-foreground",children:"Choose which cards should respond to this shared control."})]}),K.length===0?/* @__PURE__ */e("div",{className:"rounded-control border border-border/60 bg-muted/30 px-3 py-2.5 text-[12px] text-muted-foreground",children:"No eligible cards are available yet. Add compatible metrics or group-by fields to cards first."}):/* @__PURE__ */e("div",{className:"space-y-1 rounded-control border border-border/60 bg-background p-2",children:K.map(a=>{const u=(n.selectedCardIds||[]).includes(a.cardId);return/* @__PURE__ */c("label",{className:"flex items-start gap-2 rounded-control px-1.5 py-1 text-[13px] hover:bg-muted/40",children:[/* @__PURE__ */e(Jt,{checked:u,onCheckedChange:o=>g(v=>v&&{...v,selectedCardIds:o===!0?[...(v.selectedCardIds||[]),a.cardId]:(v.selectedCardIds||[]).filter(E=>E!==a.cardId)})}),/* @__PURE__ */c("div",{className:"min-w-0",children:[/* @__PURE__ */e("div",{className:"font-medium text-foreground",children:a.title}),/* @__PURE__ */e("div",{className:"text-[12px] text-muted-foreground",children:n.control.type==="field_selector"?`${a.fieldChoices.length} compatible group-by fields`:`${a.metricChoices.length} compatible metrics`})]})]},a.cardId);})}),/* @__PURE__ */e(st,{participants:K,selectedCardIds:n.selectedCardIds||[],control:n.control,selected:n.matrixTargetIds,onChange:(a,u)=>g(o=>o&&{...o,matrixTargetIds:{...o.matrixTargetIds,[a]:u}})}),/* @__PURE__ */e(Se,{secondary:/* @__PURE__ */e(B,{type:"button",variant:"outline",size:"xs",onClick:()=>g(a=>a&&{...a,step:1,selectedCardIds:[]}),children:"Back"}),primary:/* @__PURE__ */e(B,{type:"button",size:"xs",onClick:()=>g(a=>a&&{...a,step:3}),disabled:!ke,children:"Next"})})]}),n.step===2&&!p(n.control.type)&&/* @__PURE__ */e(it,{control:n.control,defaultValue:n.defaultValue,availableFieldChoices:A.fields,availableMetricChoices:A.metrics,previewControlDefinitions:Le,previewControlValues:He,onControlChange:a=>ue(()=>a),onLabelChange:a=>ue(u=>({...u,label:a})),onDefaultValueChange:Ue,onBack:()=>g(a=>a&&{...a,step:1}),onNext:We,nextDisabled:!ke}),n.step===3&&p(n.control.type)&&/* @__PURE__ */e(it,{control:n.control,defaultValue:n.defaultValue,availableFieldChoices:A.fields,availableMetricChoices:A.metrics,previewControlDefinitions:Le,previewControlValues:He,onControlChange:a=>ue(()=>a),onLabelChange:a=>ue(u=>({...u,label:a})),onDefaultValueChange:Ue,onBack:()=>g(a=>a&&{...a,step:2}),onNext:We,nextDisabled:!ke}),n.step===3&&!p(n.control.type)&&/* @__PURE__ */e(dt,{control:n.control,scope:t,createdReference:Qe,explorerContent:/* @__PURE__ */c(me,{children:["Open the card and use"," ",/* @__PURE__ */e("span",{className:"font-medium text-foreground",children:"Settings → Controls"})," ","to choose what this control changes."]}),sqlDescription:"Reference this control directly in the SQL editor.",onBack:()=>g(a=>a&&{...a,step:2}),onCancel:De,onDone:Ke}),n.step===4&&p(n.control.type)&&/* @__PURE__ */e(dt,{control:n.control,scope:t,createdReference:Qe,summaryDetail:/* @__PURE__ */c(me,{children:["Used by ",(n.selectedCardIds||[]).length," selected card",(n.selectedCardIds||[]).length===1?"":"s"]}),explorerContent:/* @__PURE__ */e(me,{children:"Selected cards have been set up to respond to this control automatically."}),sqlDescription:"SQL cards can still reference this control directly in the SQL editor.",onBack:()=>g(a=>a&&{...a,step:3}),onCancel:De,onDone:Ke})]}):null,!n&&r.length===0?/* @__PURE__ */e("div",{className:"rounded-md border border-dashed p-3 text-sm text-muted-foreground",children:h}):null,!n&&r.map(a=>{const u=R(a),o=b==null?void 0:b[a.id],v=Ae({control:a,defaultValues:i}),E=Q===a.id,_="inline-flex shrink-0 items-center rounded-[4px] border border-border/60 bg-muted/40 px-1.5 py-0.5 text-[11px] font-medium text-muted-foreground";return/* @__PURE__ */c("div",{className:"rounded-control border border-border/60",children:[/* @__PURE__ */c("div",{className:"flex items-center gap-2 px-3 py-2.5",children:[/* @__PURE__ */c("button",{type:"button",className:"flex min-w-0 flex-1 items-start gap-2 rounded-control text-left focus:outline-none focus-visible:bg-muted/40",onClick:()=>Y(w=>w===a.id?null:a.id),children:[E?/* @__PURE__ */e(ge,{className:"mt-0.5 h-3.5 w-3.5 shrink-0 text-muted-foreground"}):/* @__PURE__ */e(Xe,{className:"mt-0.5 h-3.5 w-3.5 shrink-0 text-muted-foreground"}),/* @__PURE__ */c("div",{className:"min-w-0",children:[/* @__PURE__ */c("div",{className:"flex flex-wrap items-center gap-1.5",children:[/* @__PURE__ */e("span",{className:"truncate text-[13px] font-medium text-foreground",children:a.label||"Untitled control"}),/* @__PURE__ */e("span",{className:_,children:Nt(a.type).label}),/* @__PURE__ */e("span",{className:_,children:Ct(t,a.placement)})]}),/* @__PURE__ */c("div",{className:"mt-0.5 text-[12px] text-muted-foreground",children:[wt(a),o!=null&&o.status?` · ${o.status}`:""]})]})]}),/* @__PURE__ */e(B,{type:"button",size:"xs",variant:"ghost",className:"h-7 w-7 shrink-0 p-0 text-muted-foreground",onClick:()=>Mt(a.id),"aria-label":`Remove ${a.label}`,children:/* @__PURE__ */e(mt,{className:"h-3.5 w-3.5"})})]}),E&&/* @__PURE__ */c("div",{className:"space-y-4 border-t border-border/60 px-3 py-3",children:[/* @__PURE__ */c("div",{className:"grid gap-3 md:grid-cols-3",children:[/* @__PURE__ */c("div",{className:"flex flex-col gap-1.5",children:[/* @__PURE__ */e(re,{className:"text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground",children:"Label"}),/* @__PURE__ */e(be,{size:"xs",value:a.label,placeholder:"Control label",onChange:w=>H(a.id,G=>({...G,label:w.target.value}))})]}),/* @__PURE__ */c("div",{className:"flex flex-col gap-1.5",children:[/* @__PURE__ */e(re,{className:"text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground",children:"Type"}),/* @__PURE__ */c(le,{value:a.type,onValueChange:w=>{const G=St({controls:r,controlId:a.id,nextType:w,defaultValues:i});j(G.controls,G.defaultValues);},children:[/* @__PURE__ */e(ie,{size:"xs",children:/* @__PURE__ */e(oe,{})}),/* @__PURE__ */e(de,{children:V(a.type).map(w=>/* @__PURE__ */e(ee,{value:w.value,children:w.label},w.value))})]})]}),/* @__PURE__ */c("div",{className:"flex flex-col gap-1.5",children:[/* @__PURE__ */e(re,{className:"text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground",children:"Show in"}),/* @__PURE__ */c(le,{value:a.placement||X,onValueChange:w=>H(a.id,G=>({...G,placement:w})),children:[/* @__PURE__ */e(ie,{size:"xs",children:/* @__PURE__ */e(oe,{})}),/* @__PURE__ */e(de,{children:$.map(w=>/* @__PURE__ */e(ee,{value:w.value,children:w.label},w.value))})]})]})]}),p(a.type)?/* @__PURE__ */c(me,{children:[/* @__PURE__ */e(Aa,{type:a.type,participants:Ze(L||[],a.type).map(w=>({cardId:w.cardId,title:w.title,choiceCount:a.type==="field_selector"?w.fieldChoices.length:w.metricChoices.length})),selectedCardIds:(N==null?void 0:N[a.id])||[],onChange:w=>{const G=q({control:a,nextSelectedCardIds:w}),W=r.map(M=>M.id===a.id?G.nextControl:M);j(W,i,{type:"update",cardBindingsById:G.cardBindingsById});}}),/* @__PURE__ */e(st,{participants:L||[],selectedCardIds:(N==null?void 0:N[a.id])||[],control:a,onChange:(w,G)=>{const W=q({control:a,nextSelectedCardIds:(N==null?void 0:N[a.id])||[],matrixTargetIds:{[w]:G}});j(r.map(M=>M.id===a.id?W.nextControl:M),i,{type:"update",cardBindingsById:W.cardBindingsById});}})]}):null,/* @__PURE__ */e(Ot,{control:a,availableFieldChoices:u.fields,availableMetricChoices:u.metrics,previewControlDefinitions:r,previewControlValues:Te,controlLifecycle:"edit",onChange:w=>H(a.id,()=>w)}),a.initialValueStrategy==="saved_default"&&/* @__PURE__ */e(At,{control:a,value:v,allowNoDefault:!0,allowCardDefault:!0,previewControlDefinitions:r,previewControlValues:Te,onChange:w=>{const G=r.map(W=>W.id===a.id?{...W,defaultValue:w}:W);if(a.source.kind==="manual"&&(C.current[a.id]=w),i){const W={...i};w===void 0?delete W[a.id]:W[a.id]=w,j(G,W);return;}j(G,void 0);}}),/* @__PURE__ */c(Ea,{open:D===a.id,onOpenChange:w=>T(w?a.id:null),children:[/* @__PURE__ */e(Fa,{asChild:!0,children:/* @__PURE__ */c(B,{type:"button",variant:"ghost",size:"xs",className:"-ml-2 gap-1 text-muted-foreground hover:text-foreground",children:[D===a.id?/* @__PURE__ */e(ge,{className:"h-3.5 w-3.5"}):/* @__PURE__ */e(Xe,{className:"h-3.5 w-3.5"}),"Advanced"]})}),/* @__PURE__ */c(Ia,{className:"space-y-3 pt-2",children:[/* @__PURE__ */c("div",{className:"grid gap-3 md:grid-cols-2",children:[/* @__PURE__ */c("div",{className:"flex flex-col gap-1.5",children:[/* @__PURE__ */e(re,{className:"text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground",children:"Variable name"}),/* @__PURE__ */e($a,{controlId:a.id,onCommit:w=>J(a.id,w)},a.id)]}),/* @__PURE__ */c("div",{className:"flex flex-col gap-1.5",children:[/* @__PURE__ */e(re,{className:"text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground",children:"Initial value"}),/* @__PURE__ */c(le,{value:a.initialValueStrategy,onValueChange:w=>H(a.id,G=>({...G,initialValueStrategy:w})),children:[/* @__PURE__ */e(ie,{size:"xs",children:/* @__PURE__ */e(oe,{})}),/* @__PURE__ */e(de,{children:ga.map(w=>/* @__PURE__ */e(ee,{value:w.value,children:w.label},w.value))})]})]})]}),/* @__PURE__ */e(Va,{control:a,onChange:w=>H(a.id,()=>w)})]})]})]})]},a.id);}),!n&&/* @__PURE__ */c(B,{type:"button",variant:"outline",size:"xs",onClick:qt,children:[/* @__PURE__ */e(Ve,{className:"h-3.5 w-3.5"}),"Add control"]})]});}function Nr(t){const{open:r,onOpenChange:s,initialCreateFlowActive:i=!1,dismissMode:F="passive"}=t,h=r!==void 0,[k,b]=te(!1),[m,x]=te(i),L=h?r:k,N=P(y=>{!y&&m&&F==="passive"||(h||b(y),y||x(!1),s==null||s(y));},[h,m,F,s]),I=P(()=>{h||b(!1),x(!1),s==null||s(!1);},[h,s]);Me(()=>{L||x(!1);},[L]);const S=P(y=>{m&&y.preventDefault();},[m]);return{forceClose:I,handleOpenChange:N,isCreateFlowActive:m,preventPassiveDismissDuringCreate:S,resolvedOpen:L,setIsCreateFlowActive:x};}function $t(t){const{relativeMeta:r,latestValue:s,...i}=t;return i;}function qe(t,r){const s=$t(t);return r.relativeMeta?{...s,value:r.value,relativeMeta:r.relativeMeta}:{...s,value:r.value};}function Qa(t,r){const s=r==="in"||r==="not in"||r==="between"||r==="not between"?[]:r==="isNull"||r==="isNotNull"?null:"";return qe({...t,operator:r},{value:s});}function Ha(t,r){const s=xe(r.dataType)==="date";return qe({...t,field:r,operator:s?"between":"="},{value:""});}function Ya({initialFilters:t,availableFields:r,onChange:s}={}){const[i,F]=te(t||{id:`group-${Date.now()}`,logicalOperator:"AND",negate:!1,conditions:[],groups:[]}),h=g=>{F(g),s==null||s(g);};pe(g=>g.card.dataSource);const{filterableFields:k,isLoading:b}=_a(),m=r||k||[],x={id:"default",qualifiedFieldName:"default",name:"default",dataType:"string",label:"Default",entityId:"default",entityName:"Default",entityType:"table"},L=g=>{const C=f=>{if(f.id===g){const d=m[0]||x,l=xe(d.dataType)==="date";return{...f,conditions:[...f.conditions,{id:`condition-${Date.now()}`,field:d,operator:l?"between":"=",value:l?[]:""}]};}return{...f,groups:f.groups.map(C)};};h(C(i));},N=g=>{const C=f=>{if(f.id===g){const d=m[0]||x,l=xe(d.dataType)==="date";return{...f,groups:[...f.groups,{id:`group-${Date.now()}`,logicalOperator:"AND",negate:!1,conditions:[{id:`condition-${Date.now()}`,field:d,operator:l?"between":"=",value:l?[]:""}],groups:[]}]};}return{...f,groups:f.groups.map(C)};};h(C(i));},I=(g,C)=>{const f=d=>d.id===g?{...d,conditions:d.conditions.filter(l=>l.id!==C)}:{...d,groups:d.groups.map(f)};h(f(i));},S=(g,C)=>{const f=d=>d.id===g?{...d,groups:d.groups.filter(l=>l.id!==C)}:{...d,groups:d.groups.map(f)};h(f(i));},y=(g,C,f)=>{const d=l=>l.id===g?{...l,conditions:l.conditions.map(V=>V.id===C?f(V):V)}:{...l,groups:l.groups.map(d)};h(d(i));},O=(g,C,f)=>y(g,C,d=>({...("value"in f||"operator"in f||"field"in f?$t(d):d),...f})),z=(g,C,f)=>y(g,C,()=>f),$=Zt(),X=(g,C)=>{const f=d=>d.id===g?{...d,logicalOperator:C}:{...d,groups:d.groups.map(f)};h(f(i));},D=(g,C)=>{const f=d=>d.id===g?{...d,negate:C}:{...d,groups:d.groups.map(f)};h(f(i));},T=(g,C,f)=>{const d=l=>l.id===g?{...l,conditions:lt(l.conditions,C,f)}:{...l,groups:l.groups.map(d)};h(d(i));},Q=(g,C,f)=>{const d=l=>l.id===g?{...l,groups:lt(l.groups,C,f)}:{...l,groups:l.groups.map(d)};h(d(i));},Y=g=>{if(!g||g.conditions.length===0&&g.groups.length===0)return"-- No filters defined";const C=d=>{let l="";typeof d.field=="object"?l=d.field.entityName?`${d.field.entityName}.${d.field.name}`:d.field.name:l=String(d.field);const V=d.operator;let p=d.value;if(d.latestValue&&V==="=")return`${l} = ${ft} /* the latest value each time the card runs */`;const K=kt(d.relativeMeta);if(K&&La(V)&&Dt(V,K)){const A=Ma(V,K),{label:R,range:q}=Je(K,{tz:($==null?void 0:$.tz)??"UTC",weekStart:($==null?void 0:$.weekStart)??1,anchor:($==null?void 0:$.anchor)??"now"}),j=A?qa(A):R;if(q){const[H]=Tt(V,[q.start,q.end]);return`${l} ${V} '${H.toISOString()}' /* ${j}: the date updates each time the card runs */`;}return`${l} ${V} ${j} /* the date follows your calendar each time the card runs */`;}if(K&&(V==="between"||V==="not between")){const A=V==="between"?"BETWEEN":"NOT BETWEEN",{label:R,range:q}=Je(K,{tz:($==null?void 0:$.tz)??"UTC",weekStart:($==null?void 0:$.weekStart)??1,anchor:($==null?void 0:$.anchor)??"now"});return q?`${l} ${A} '${q.start.toISOString()}' AND '${q.end.toISOString()}' /* ${R}: dates update each time the card runs */`:Lt(K).dataAnchored?`${l} ${A} ${R} /* dates count back from the latest data each time the card runs */`:`${l} ${A} ${R} /* dates follow your calendar each time the card runs */`;}if(d.field.dataType==="string"&&!["in","not in"].includes(d.operator))typeof p=="string"?p=`'${p}'`:Array.isArray(p)&&(p=`'${p.join(", ")}'`);else if(d.field.dataType==="date"||d.field.dataType==="datetime"||d.field.dataType==="timestamp"){if(d.operator==="between"&&Array.isArray(p)&&p.length===2){const A=p[0]?`'${p[0]}'`:"NULL",R=p[1]?`'${p[1]}'`:"NULL";return`${l} BETWEEN ${A} AND ${R}`;}else if((d.operator==="in"||d.operator==="not in")&&Array.isArray(p)){const A=p.map(R=>R?`'${R}'`:"NULL").join(", ");return`${l} ${V} (${A})`;}else typeof p=="string"||p instanceof Date?p=`'${p}'`:Array.isArray(p)&&p.length>0&&(p=`'${p[0]}'`);}else if(["in","not in"].includes(d.operator)){let A=[];Array.isArray(p)?A=p.map(R=>typeof R=="string"?`'${R}'`:String(R)):typeof p=="string"?A=p.split(",").map(R=>{const q=R.trim();return d.field.dataType==="string"?`'${q}'`:q;}):typeof p=="number"&&(A=[String(p)]),p=`(${A.join(", ")})`;}switch(V){case"contains":return typeof p=="string"?`${l} LIKE '%${p.replace(/'/g,"")}'`:`${l} LIKE '%${String(p)}'`;case"startsWith":return typeof p=="string"?`${l} LIKE '${p.replace(/'/g,"")}%'`:`${l} LIKE '${String(p)}%'`;case"endsWith":return typeof p=="string"?`${l} LIKE '%${p.replace(/'/g,"")}'`:`${l} LIKE '%${String(p)}'`;case"isNull":return`${l} IS NULL`;case"isNotNull":return`${l} IS NOT NULL`;default:return`${l} ${V} ${p}`;}},f=d=>{const l=d.conditions.map(C),V=d.groups.map(R=>f(R)),p=[...l,...V].filter(Boolean);if(p.length===0)return"";const K=p.join(` ${d.logicalOperator} `),A=p.length>1?`(${K})`:K;return d.negate?`NOT ${A}`:A;};return f(g);},n=i.conditions.length>0||i.groups.length>0;return{currentFilters:i,setCurrentFilters:h,availableFields:m,isLoading:b,addCondition:L,addGroup:N,removeCondition:I,removeGroup:S,updateConditionFields:O,replaceCondition:z,updateGroupOperator:X,updateGroupNegate:D,reorderConditions:T,reorderGroups:Q,generateSQLPreview:Y,hasAnyFilters:n};}function Vt(t,r){const s=pe(x=>x.card.dataSource),i=pe(x=>x.card.connectionId),F=pe(x=>x.selectedConnectionId),{dataSource:h,connectionId:k}=r?nt(r):nt({dataSource:s,connectionId:i},F),b=Z(()=>({id:`card-filter-option:${t.id}`,...Ca(t,{dataSource:h,connectionId:k})}),[k,h,t]),m=Z(()=>ea({filter:b}),[b]);return ta(b,{inputContext:m,currentSelectionPolicy:"exclude"});}function Xa({field:t,source:r,selected:s,onChange:i,placeholder:F="Select values…",className:h}){const[k,b]=we.useState(!1),m=Vt(t,r),x=we.useMemo(()=>new Set(s.map(S=>ce(S))),[s]),L=S=>{var y,O;return((O=(y=m.allRecords.find(z=>ce(z.value)===ce(S)))==null?void 0:y.label)==null?void 0:O.toString())??S;},N=S=>{i(s.filter(y=>y!==S));},I=S=>{b(S),!S&&m.query&&m.setQuery("");};return/* @__PURE__ */e("div",{className:U("w-full",h),children:/* @__PURE__ */c(ht,{open:k,onOpenChange:I,modal:!0,children:[/* @__PURE__ */e(gt,{asChild:!0,children:/* @__PURE__ */c(B,{variant:"outline",size:"xs",role:"combobox","aria-expanded":k,className:"h-auto min-h-7 w-full justify-between gap-1.5 px-2 py-0.5 font-normal",children:[/* @__PURE__ */e("div",{className:"flex min-w-0 flex-1 flex-wrap gap-1",children:s.length>0?s.map(S=>{const y=L(S);return(/* @__PURE__ */c("span",{className:"inline-flex max-w-full items-center gap-1 rounded-[4px] border border-border/70 bg-muted/40 px-1.5 py-0.5 text-[11px] leading-[14px] text-foreground",children:[/* @__PURE__ */e("span",{className:"truncate",children:y}),/* @__PURE__ */e("span",{role:"button",tabIndex:0,"aria-label":`Remove ${y}`,className:"shrink-0 rounded-[2px] text-muted-foreground outline-none hover:text-foreground focus-visible:ring-1 focus-visible:ring-ring",onKeyDown:O=>{O.key==="Enter"&&N(S);},onMouseDown:O=>{O.preventDefault(),O.stopPropagation();},onClick:O=>{O.stopPropagation(),N(S);},children:/* @__PURE__ */e(bt,{className:"h-3 w-3"})})]},S));}):/* @__PURE__ */e("span",{className:"truncate text-muted-foreground",children:F})}),/* @__PURE__ */e(ge,{className:"h-3.5 w-3.5 shrink-0 opacity-50"})]})}),/* @__PURE__ */e(xt,{className:"w-[var(--radix-popover-trigger-width)] min-w-[240px] rounded-control p-1.5",align:"start",onOpenAutoFocus:S=>{var y,O;S.preventDefault(),(O=(y=S.currentTarget)==null?void 0:y.querySelector('input[type="text"]'))==null||O.focus();},children:/* @__PURE__ */e(vt,{records:m.displayRecords,selectedIdentities:x,onToggle:S=>{const y=String(S.value);s.includes(y)?N(y):i([...s,y]);},browse:m,searchPlaceholder:`Search ${(t.label||t.name).toLowerCase()}`,listLabel:t.label||t.name,density:"compact"})})]})});}function Ja({field:t,source:r,value:s,onChange:i,placeholder:F="Select value…",className:h}){var I,S;const[k,b]=we.useState(!1),m=Vt(t,r),x=we.useMemo(()=>new Set(s?[ce(s)]:[]),[s]),L=s?((S=(I=m.allRecords.find(y=>ce(y.value)===ce(s)))==null?void 0:I.label)==null?void 0:S.toString())??s:"",N=y=>{b(y),!y&&m.query&&m.setQuery("");};return/* @__PURE__ */c(ht,{open:k,onOpenChange:N,modal:!0,children:[/* @__PURE__ */e(gt,{asChild:!0,children:/* @__PURE__ */c(B,{variant:"outline",size:"xs",role:"combobox","aria-expanded":k,className:U("min-w-0 flex-1 justify-between gap-1.5 px-2 font-normal",h),children:[/* @__PURE__ */e("span",{className:U("truncate",!s&&"text-muted-foreground"),children:s?L:F}),/* @__PURE__ */e(ge,{className:"h-3.5 w-3.5 shrink-0 opacity-50"})]})}),/* @__PURE__ */e(xt,{className:"w-[var(--radix-popover-trigger-width)] min-w-[240px] rounded-control p-1.5",align:"start",onOpenAutoFocus:y=>{var O,z;y.preventDefault(),(z=(O=y.currentTarget)==null?void 0:O.querySelector('input[type="text"]'))==null||z.focus();},children:/* @__PURE__ */e(vt,{records:m.displayRecords,selectedIdentities:x,onToggle:y=>{i(String(y.value)),N(!1);},selectionMode:"single",browse:m,searchPlaceholder:`Search ${(t.label||t.name).toLowerCase()}`,listLabel:t.label||t.name,density:"compact"})})]});}function Pa({value:t,operator:r,relativeMeta:s,latestValue:i,field:F,onChange:h,className:k}){const b=aa(),m=ra(),x=r==="between"||r==="not between",L=Dt(r),N=L?s:void 0,I=Z(()=>{if(!x||!s)return;const D=m(s);return{...D,tooltip:D.dates?void 0:Lt(s).dataAnchored?na:sa};},[x,s,m]),S=Z(()=>{if(x){if(I){const{range:D}=I;return D?{from:D.start,to:D.end}:void 0;}if(t&&Array.isArray(t)&&t.length===2){const D=Fe(t[0],b,"start"),T=Fe(t[1],b,"end");if(D&&T)return{from:D,to:T};}}},[t,x,I,b]),y=Z(()=>{if(!t||x||i)return;const D=Array.isArray(t)?t[0]:t;return Fe(D,b,"start");},[t,x,i,b]),O=D=>r==="<="||r===">"?ka(D,b):Da(D,b);return/* @__PURE__ */e(la,{value:x?S:void 0,selectionMode:x?"range":"single",singleValue:x?void 0:y,singleValueLabel:!x&&i?ft:void 0,onChange:D=>{if(D!=null&&D.from&&D.to){h({value:[D.from.toISOString(),D.to.toISOString()]});return;}h({value:[]});},onSingleChange:D=>{if(!D){h({value:""});return;}const T=O(D),Q=Sa(T,r,{timezone:b});h({value:typeof Q=="string"?Q:Q.toISOString()});},onRelativeSelect:L?(D,T)=>{if(!D.from||!D.to){h({value:x?[]:""});return;}const Q=Tt(r,[D.from.toISOString(),D.to.toISOString()]);h({value:Q.length===1?Q[0]:Q,relativeMeta:T});}:void 0,relativeValue:N,comparisonValue:!x&&L?r:void 0,relativePoints:!x&&L?{operator:r}:"none",relativeSummary:I,supplementalFooter:L?/* @__PURE__ */e("p",{className:"border-t border-border px-3 py-2 text-[11px] text-muted-foreground",children:"Presets and Relative update each time the card runs. Static dates stay fixed."}):void 0,timezone:b,enableTimePrecision:wa(F),staticTimeInputs:!1,showRelativeTab:L,className:U("min-w-0",k),buttonClassName:"h-7 text-[12px] [&>span]:text-[12px]",placeholder:"Select date…"});}const Za=t=>t.conditions.length>0||t.groups.length>0,je=["contains","startsWith","endsWith","like","not like"],er=["=","!=",">",">=","<","<=",...je,"in","not in","isNull","isNotNull"],tr=["=","!=",...je,"in","not in","isNull","isNotNull"],ar=["=","!=",">",">=","<","<=","in","not in","isNull","isNotNull"],rr=["=","!=","isNull","isNotNull"],nr=["between","=","!=","<","<=",">",">=","isNull","isNotNull"],sr={"=":"Equals","!=":"Not equals",">":"Greater than",">=":"Greater than or equal","<":"Less than","<=":"Less than or equal",contains:"Contains",startsWith:"Starts with",endsWith:"Ends with",like:"Like","not like":"Not like",in:"In","not in":"Not in",between:"Between",isNull:"Is null",isNotNull:"Is not null","not between":"Not between"};function $e(t){return sr[t]||Ta(t);}function lr(t){switch(t){case"string":return tr;case"number":return ar;case"boolean":return rr;case"date":return nr;default:return er;}}const _t="w-[68px] shrink-0",ct="group-data-[inline]/filters:w-auto group-data-[inline]/filters:min-w-0 group-data-[inline]/filters:flex-1 group-data-[inline]/filters:shrink",Be="text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground";function Rt({value:t,onValueChange:r,"aria-label":s}){return/* @__PURE__ */c(le,{value:t,onValueChange:i=>r(i),children:[/* @__PURE__ */e(ie,{size:"xs","aria-label":s,className:U(_t,"font-medium"),children:/* @__PURE__ */e(oe,{})}),/* @__PURE__ */c(de,{className:"min-w-[var(--radix-select-trigger-width)]",children:[/* @__PURE__ */e(ee,{value:"AND",className:"text-[12px] font-medium",children:"AND"}),/* @__PURE__ */e(ee,{value:"OR",className:"text-[12px] font-medium",children:"OR"})]})]});}function zt({condition:t,index:r,groupId:s,groupLogicalOperator:i,onRemoveCondition:F,onUpdateGroupOperator:h,availableFields:k,source:b,updateConditionFields:m,replaceCondition:x}){const{attributes:L,listeners:N,setNodeRef:I,transform:S,transition:y,isDragging:O}=Et({id:t.id}),z={transform:Ft.Transform.toString(S),transition:y},$=xe(t.field.dataType),X=t.operator==="isNull"||t.operator==="isNotNull",D=t.operator==="in"||t.operator==="not in";return/* @__PURE__ */c("div",{ref:I,style:z,className:U("flex items-center gap-2 rounded-control px-1.5 py-1 transition-colors hover:bg-muted/40",O&&"z-50 opacity-50"),children:[/* @__PURE__ */e("button",{type:"button",...L,...N,"aria-label":"Drag to reorder condition",className:"flex h-7 w-5 shrink-0 cursor-grab items-center justify-center rounded-control text-muted-foreground/60 hover:text-foreground focus-visible:outline-none active:cursor-grabbing",children:/* @__PURE__ */e(yt,{className:"h-3.5 w-3.5"})}),r>0?/* @__PURE__ */e(Rt,{value:i,onValueChange:T=>h(s,T),"aria-label":"Logical operator"}):/* @__PURE__ */e("span",{className:U(_t,"text-center",Be),children:"Where"}),/* @__PURE__ */e(za,{value:t.field,onValueChange:T=>{x(s,t.id,Ha(t,T));},availableFields:k,placeholder:"Select field",className:U("w-60 shrink-0",ct)}),/* @__PURE__ */c(le,{value:t.operator,onValueChange:T=>x(s,t.id,Qa(t,T)),children:[/* @__PURE__ */e(ie,{size:"xs","aria-label":"Operator",className:U("w-40 shrink-0",ct),children:/* @__PURE__ */e(oe,{children:t.operator?$e(t.operator):""})}),/* @__PURE__ */e(de,{children:lr($).map(T=>/* @__PURE__ */e(ee,{value:T,children:$e(T)},T))})]}),X?/* @__PURE__ */e("div",{className:"min-w-0 flex-1"}):$==="string"?D?/* @__PURE__ */e(Xa,{field:t.field,source:b,selected:Array.isArray(t.value)&&t.value.every(T=>typeof T=="string")?t.value:[],onChange:T=>m(s,t.id,{value:T}),placeholder:"Select values…",className:"min-w-0 flex-1"}):je.includes(t.operator)?/* @__PURE__ */e(be,{size:"xs",value:typeof t.value=="string"?t.value:"",onChange:T=>m(s,t.id,{value:T.target.value}),className:"min-w-0 flex-1",placeholder:`${$e(t.operator)}…`}):/* @__PURE__ */e(Ja,{field:t.field,source:b,value:typeof t.value=="string"?t.value:"",onChange:T=>m(s,t.id,{value:T}),placeholder:"Select value…",className:"min-w-0 flex-1"}):$==="boolean"?/* @__PURE__ */c(le,{value:typeof t.value=="boolean"?String(t.value):"",onValueChange:T=>m(s,t.id,{value:T==="true"}),children:[/* @__PURE__ */e(ie,{size:"xs",className:"min-w-0 flex-1",children:/* @__PURE__ */e(oe,{placeholder:"Select value…"})}),/* @__PURE__ */c(de,{children:[/* @__PURE__ */e(ee,{value:"true",children:"True"}),/* @__PURE__ */e(ee,{value:"false",children:"False"})]})]}):$==="date"?/* @__PURE__ */e(Pa,{value:t.value,operator:t.operator,relativeMeta:kt(t.relativeMeta),latestValue:t.latestValue===!0,field:t.field,onChange:T=>x(s,t.id,qe(t,T)),className:"min-w-0 flex-1"}):/* @__PURE__ */e(be,{size:"xs",value:typeof t.value=="string"||typeof t.value=="number"?t.value:"",onChange:T=>m(s,t.id,{value:T.target.value}),className:"min-w-0 flex-1",placeholder:D?"value1, value2, value3":"Value"}),/* @__PURE__ */e(B,{variant:"ghost",size:"xs","aria-label":"Remove condition",className:"h-7 w-7 shrink-0 p-0 text-muted-foreground hover:text-foreground",onClick:()=>F(s,t.id),children:/* @__PURE__ */e(bt,{className:"h-3.5 w-3.5"})})]});}const ut="group-data-[inline]/filters:h-auto group-data-[inline]/filters:gap-1 group-data-[inline]/filters:border-0 group-data-[inline]/filters:bg-transparent group-data-[inline]/filters:px-0 group-data-[inline]/filters:py-0.5 group-data-[inline]/filters:text-[11px] group-data-[inline]/filters:font-medium group-data-[inline]/filters:text-muted-foreground group-data-[inline]/filters:shadow-none group-data-[inline]/filters:underline-offset-2 group-data-[inline]/filters:hover:bg-transparent group-data-[inline]/filters:hover:text-foreground group-data-[inline]/filters:hover:underline";function Gt({onAddCondition:t,onAddGroup:r}){return/* @__PURE__ */c("div",{className:"mt-2 flex items-center gap-1.5 group-data-[inline]/filters:mt-1 group-data-[inline]/filters:gap-3",children:[/* @__PURE__ */c(B,{type:"button",size:"xs",variant:"outline",className:U("gap-1.5",ut),onClick:t,children:[/* @__PURE__ */e(Ve,{className:"h-3 w-3"}),"Add condition"]}),r&&/* @__PURE__ */c(B,{type:"button",size:"xs",variant:"ghost",className:U("gap-1.5 text-muted-foreground hover:text-foreground",ut),onClick:r,children:[/* @__PURE__ */e(Ve,{className:"h-3 w-3"}),"Add group"]})]});}function ir({group:t,depth:r,parentGroupId:s,onUpdateGroupOperator:i,onUpdateGroupNegate:F,onRemoveGroup:h,onRemoveCondition:k,onReorderConditions:b,onReorderGroups:m,onAddCondition:x,onAddGroup:L,availableFields:N,source:I,renderFilterGroup:S,updateConditionFields:y,replaceCondition:O}){const{attributes:z,listeners:$,setNodeRef:X,transform:D,transition:T,isDragging:Q}=Et({id:t.id}),Y={transform:Ft.Transform.toString(D),transition:T},n=C=>{const{active:f,over:d}=C;if(d&&f.id!==d.id){const l=t.conditions.findIndex(p=>p.id===f.id),V=t.conditions.findIndex(p=>p.id===d.id);l!==-1&&V!==-1&&b(t.id,l,V);}},g=C=>{const{active:f,over:d}=C;if(d&&f.id!==d.id&&s){const l=t.groups.findIndex(p=>p.id===f.id),V=t.groups.findIndex(p=>p.id===d.id);l!==-1&&V!==-1&&m(s,l,V);}};return/* @__PURE__ */c("div",{ref:X,style:Y,className:U(r>0&&"mt-2 overflow-hidden rounded-[6px] border border-border/60",Q&&"z-50 opacity-50"),children:[r>0&&/* @__PURE__ */c("div",{className:"flex items-center justify-between gap-2 border-b border-border/60 bg-muted/40 px-2 py-1",children:[/* @__PURE__ */c("div",{className:"flex items-center gap-1.5",children:[/* @__PURE__ */e("button",{type:"button",...z,...$,"aria-label":"Drag to reorder group",className:"flex h-7 w-5 shrink-0 cursor-grab items-center justify-center rounded-control text-muted-foreground/60 hover:text-foreground focus-visible:outline-none active:cursor-grabbing",children:/* @__PURE__ */e(yt,{className:"h-3.5 w-3.5"})}),/* @__PURE__ */e(B,{type:"button",variant:t.negate?"default":"outline",size:"xs","aria-pressed":t.negate,className:"px-2",onClick:()=>F(t.id,!t.negate),children:"NOT"}),/* @__PURE__ */e(Rt,{value:t.logicalOperator,onValueChange:C=>i(t.id,C),"aria-label":"Group logical operator"}),/* @__PURE__ */e("span",{className:Be,children:"Group"})]}),/* @__PURE__ */e(B,{type:"button",variant:"ghost",size:"xs","aria-label":"Remove group",className:"h-7 w-7 p-0 text-muted-foreground hover:text-foreground",onClick:()=>s&&h(s,t.id),children:/* @__PURE__ */e(mt,{className:"h-3.5 w-3.5"})})]}),/* @__PURE__ */c("div",{className:U(r>0&&"p-2"),children:[/* @__PURE__ */e(ve,{sensors:_e(se(Ge),se(ze,{coordinateGetter:Re})),collisionDetection:ye,onDragEnd:n,children:/* @__PURE__ */e(Ne,{items:t.conditions.map(C=>C.id),strategy:Ce,children:/* @__PURE__ */e("div",{className:"space-y-0.5",children:t.conditions.map((C,f)=>/* @__PURE__ */e(zt,{condition:C,index:f,groupId:t.id,groupLogicalOperator:t.logicalOperator,onRemoveCondition:k,onUpdateGroupOperator:i,availableFields:N,source:I,updateConditionFields:y,replaceCondition:O},C.id))})})}),/* @__PURE__ */e(ve,{sensors:_e(se(Ge),se(ze,{coordinateGetter:Re})),collisionDetection:ye,onDragEnd:g,children:/* @__PURE__ */e(Ne,{items:t.groups.map(C=>C.id),strategy:Ce,children:t.groups.map(C=>S(C,r+1,t.id))})}),t.conditions.length===0&&t.groups.length===0&&/* @__PURE__ */e("p",{className:"rounded-control border border-dashed border-border/60 px-3 py-2 text-center text-[11.5px] text-muted-foreground",children:"No conditions in this group."}),/* @__PURE__ */e(Gt,{onAddCondition:()=>x(t.id),onAddGroup:()=>L(t.id)})]})]});}function Cr({filters:t,availableFields:r,source:s,onSave:i,onClearAll:F,onCancel:h,onChange:k}){const b=k!==void 0,{currentFilters:m,availableFields:x,isLoading:L,addCondition:N,addGroup:I,removeCondition:S,removeGroup:y,updateConditionFields:O,replaceCondition:z,updateGroupOperator:$,updateGroupNegate:X,reorderConditions:D,reorderGroups:T,generateSQLPreview:Q,hasAnyFilters:Y}=Ya({initialFilters:t,availableFields:r,...(k?{onChange:l=>k(Za(l)?l:null)}:{})}),n=_e(se(Ge),se(ze,{coordinateGetter:Re})),[g,C]=te(!1),f=(l,V=0,p)=>{if(V===0){const K=l.conditions.length===0&&l.groups.length===0;return/* @__PURE__ */c("div",{children:[/* @__PURE__ */e(ve,{sensors:n,collisionDetection:ye,onDragEnd:A=>{const{active:R,over:q}=A;if(q&&R.id!==q.id){const j=l.conditions.findIndex(J=>J.id===R.id),H=l.conditions.findIndex(J=>J.id===q.id);j!==-1&&H!==-1&&D(l.id,j,H);}},children:/* @__PURE__ */e(Ne,{items:l.conditions.map(A=>A.id),strategy:Ce,children:/* @__PURE__ */e("div",{className:"space-y-0.5",children:l.conditions.map((A,R)=>/* @__PURE__ */e(zt,{condition:A,index:R,groupId:l.id,groupLogicalOperator:l.logicalOperator,onRemoveCondition:S,onUpdateGroupOperator:$,availableFields:x,source:s,updateConditionFields:O,replaceCondition:z},A.id))})})}),/* @__PURE__ */e(ve,{sensors:n,collisionDetection:ye,onDragEnd:A=>{const{active:R,over:q}=A;if(q&&R.id!==q.id){const j=l.groups.findIndex(J=>J.id===R.id),H=l.groups.findIndex(J=>J.id===q.id);j!==-1&&H!==-1&&T(l.id,j,H);}},children:/* @__PURE__ */e(Ne,{items:l.groups.map(A=>A.id),strategy:Ce,children:l.groups.map(A=>f(A,V+1,l.id))})}),K&&!b&&/* @__PURE__ */e("p",{className:"rounded-control border border-dashed border-border/60 px-3 py-2 text-center text-[11.5px] text-muted-foreground",children:"No filters yet. Add a condition to limit the rows this card shows."}),/* @__PURE__ */e(Gt,{onAddCondition:()=>N(l.id),onAddGroup:(b?l.conditions.length+l.groups.length>=2:g)?()=>I(l.id):void 0})]},l.id);}return/* @__PURE__ */e(ir,{group:l,depth:V,parentGroupId:p,onUpdateGroupOperator:$,onUpdateGroupNegate:X,onRemoveGroup:y,onRemoveCondition:S,onReorderConditions:D,onReorderGroups:T,onAddCondition:N,onAddGroup:I,availableFields:x,source:s,renderFilterGroup:f,updateConditionFields:O,replaceCondition:z},l.id);},d=Ra(t);return/* @__PURE__ */c("div",{className:U("group/filters",b?"flex flex-col":"flex min-h-0 flex-1 flex-col"),"data-inline":b||void 0,children:[/* @__PURE__ */c("div",{className:b?"":"min-h-0 flex-1 overflow-y-auto px-3 py-3",children:[L?/* @__PURE__ */c("div",{className:"flex items-center justify-center gap-2 py-6 text-[12px] text-muted-foreground",children:[/* @__PURE__ */e(ia,{className:"h-3.5 w-3.5 animate-spin"}),"Loading columns…"]}):f(m),!b&&/* @__PURE__ */c("div",{className:"mt-3 flex items-center gap-2 border-t border-border/60 pt-3",children:[/* @__PURE__ */e(oa,{size:"xs",id:"advanced-mode",checked:g,onCheckedChange:l=>C(l)}),/* @__PURE__ */e(re,{htmlFor:"advanced-mode",className:"text-[12px] font-normal leading-none text-foreground",children:"Advanced mode"}),/* @__PURE__ */e("span",{className:"text-[11px] text-muted-foreground",children:"Nest conditions in groups"})]}),Y&&!b&&/* @__PURE__ */c("div",{className:"mt-3 border-t border-border/60 pt-3",children:[/* @__PURE__ */e("div",{className:U("mb-1.5",Be),children:"Where clause"}),/* @__PURE__ */e("pre",{className:"overflow-x-auto whitespace-pre-wrap break-words rounded-[6px] border border-border bg-muted/40 px-3 py-2 font-mono text-[12px] leading-[1.55] text-foreground",children:Q(m)})]})]}),b?null:/* @__PURE__ */c("div",{className:"flex shrink-0 items-center justify-between gap-2 border-t border-border px-3 py-2.5",children:[/* @__PURE__ */e("div",{children:d>0&&/* @__PURE__ */e(B,{size:"xs",variant:"ghost",className:"text-muted-foreground hover:text-foreground",onClick:()=>F==null?void 0:F(),children:"Clear all"})}),/* @__PURE__ */c("div",{className:"flex items-center gap-1.5",children:[/* @__PURE__ */e(B,{size:"xs",variant:"ghost",onClick:()=>h==null?void 0:h(),children:"Cancel"}),/* @__PURE__ */e(B,{size:"xs",onClick:()=>i==null?void 0:i(Y?m:null),children:"Apply filters"})]})]})]});}export{yr as C,xr as F,ja as L,vr as V,Cr as a,Nr as u};
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
import{l as f}from"./validators-U8IL8djK.js";import{p}from"./resolve-dashboard-input-context-B5yUS9ZM.js";function w(e){var a;const r=e!=null&&e.fields.length?`
|
|
2
|
+
## Your card's fields
|
|
3
|
+
|
|
4
|
+
The card this visual draws has these fields, in order. Dimension slots take its dimensions in order, measure slots its measures; the author can reassign them.
|
|
5
|
+
|
|
6
|
+
${e.fields.map(t=>`- ${t.name} (${t.kind}, ${t.type})`).join(`
|
|
7
|
+
`)}
|
|
8
|
+
`:"",s=(a=e==null?void 0:e.current)!=null&&a.trim()?`
|
|
9
|
+
## The visual now
|
|
10
|
+
|
|
11
|
+
This is the visual the card draws now. Change it as I ask, and reply with the whole HTML document.
|
|
12
|
+
|
|
13
|
+
\`\`\`html
|
|
14
|
+
${e.current.trim()}
|
|
15
|
+
\`\`\`
|
|
16
|
+
`:"";return`${y}${r}${s}`;}function g(e){var a;if((a=e.sql)!=null&&a.trim()||!e.config)return[];const r=t=>{const o=f(t);return o==="number"?"number":o==="date"||o==="datetime"?"date":o==="boolean"?"boolean":"string";},s=t=>t.label||t.name||"";return[...(e.config.groupByColumns??[]).map(t=>({name:s(t),kind:"dimension",type:r(t.dataType)})),...(e.config.metricColumns??[]).map(t=>({name:s(t),kind:"measure",type:"number"}))].filter(t=>t.name);}function x(e){const r=(s,a)=>{switch(s.type){case"number":{const t=[1200,860,410][a];return{value:t,text:t.toLocaleString("en-US")};}case"date":return{value:["2026-01-01","2026-02-01","2026-03-01"][a],text:["Jan 2026","Feb 2026","Mar 2026"][a]};case"boolean":return{value:a!==1,text:a!==1?"true":"false"};default:return{value:`${s.name} ${String.fromCharCode(65+a)}`,text:`${s.name} ${String.fromCharCode(65+a)}`};}};return[0,1,2].map(s=>Object.fromEntries(e.map(a=>[a.name,r(a,s)])));}const y=`# Custom visual contract (version 2)
|
|
17
|
+
|
|
18
|
+
You are writing a custom visual for a card on an analytics dashboard. Return **one self-contained HTML document** and nothing else.
|
|
19
|
+
|
|
20
|
+
## Where it runs
|
|
21
|
+
|
|
22
|
+
- The dashboard runs your HTML in a sandboxed iframe sized to the card. You can't reach the page, its cookies or its APIs.
|
|
23
|
+
- **You never fetch data.** The dashboard runs the card's query, with its filters and permissions, and hands you the finished rows.
|
|
24
|
+
- No network access. Scripts may load only from ${p(e=>"`https://"+e+"`")}, with an exact version in the URL (for example \`https://cdn.jsdelivr.net/npm/echarts@5.5.1/dist/echarts.min.js\`). No other external files: no web fonts, no remote images.
|
|
25
|
+
- The whole document is at most 256 KB.
|
|
26
|
+
- A global \`semaphor\` object exists before your scripts run. Don't define it.
|
|
27
|
+
|
|
28
|
+
## 1. Declare your manifest
|
|
29
|
+
|
|
30
|
+
The first element in \`<head>\` must be your manifest:
|
|
31
|
+
|
|
32
|
+
\`\`\`html
|
|
33
|
+
<script type="application/json" id="semaphor-visual">
|
|
34
|
+
{
|
|
35
|
+
"name": "Bullet chart",
|
|
36
|
+
"contract": 2,
|
|
37
|
+
"minSize": { "width": 200, "height": 120 },
|
|
38
|
+
"slots": [
|
|
39
|
+
{ "id": "category", "label": "Category", "kind": "dimension" },
|
|
40
|
+
{ "id": "value", "label": "Value", "kind": "measure" },
|
|
41
|
+
{ "id": "target", "label": "Target", "kind": "measure", "optional": true }
|
|
42
|
+
],
|
|
43
|
+
"settings": {
|
|
44
|
+
"showLabels": { "label": "Show labels", "type": "boolean", "default": true },
|
|
45
|
+
"onTarget": { "label": "On target", "type": "color", "default": "positive" }
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
<\/script>
|
|
49
|
+
\`\`\`
|
|
50
|
+
|
|
51
|
+
- \`slots\` are what your visual draws. The card's dimensions fill your dimension slots and its measures fill your measure slots, in order; the author can reassign them. Your code reads only your slot ids, never column names.
|
|
52
|
+
- \`kind\` is \`dimension\` (something to group by: a name, a date) or \`measure\` (a number).
|
|
53
|
+
- An \`optional\` slot may be empty: it is then absent from \`fields\` and from every row.
|
|
54
|
+
- One slot of each kind may set \`"many": true\` to take every remaining field of that kind, for example a table's columns. Its fields arrive as \`id\`, \`id_2\`, \`id_3\`…
|
|
55
|
+
- Slot and setting ids start with a lowercase letter and use letters, digits or \`_\`.
|
|
56
|
+
- \`settings\` types: \`boolean\`, \`number\` (with \`min\`, \`max\`, \`step\`), \`string\`, \`select\` with \`"options": [{ "value": "a", "label": "A" }]\`, or \`color\`. Every setting has a \`default\`.
|
|
57
|
+
- A \`color\` setting's \`default\` is a theme colour name: \`palette-1\` … \`palette-8\`, \`primary\`, \`accent\`, \`positive\`, \`negative\`, \`warning\`, \`selection\`, \`fg\`, \`muted-fg\`. Use a \`#rrggbb\` default only when the author asked for that exact colour. The dashboard sends the setting to you as \`#rrggbb\`, resolved for the current brand and light or dark mode.
|
|
58
|
+
- \`minSize\` is the smallest size at which your visual is still useful.
|
|
59
|
+
|
|
60
|
+
## 2. Draw from the data you're given
|
|
61
|
+
|
|
62
|
+
\`\`\`js
|
|
63
|
+
semaphor.onData((payload) => { draw(payload); semaphor.ready(); });
|
|
64
|
+
\`\`\`
|
|
65
|
+
|
|
66
|
+
\`onData\` calls you now, and again whenever the data, settings, theme or size change. The payload:
|
|
67
|
+
|
|
68
|
+
\`\`\`json
|
|
69
|
+
{
|
|
70
|
+
"contract": 2,
|
|
71
|
+
"kind": "visual",
|
|
72
|
+
"fields": [
|
|
73
|
+
{ "id": "category", "slot": "category", "label": "Region", "type": "string", "kind": "dimension" },
|
|
74
|
+
{ "id": "value", "slot": "value", "label": "Revenue", "type": "number", "kind": "measure", "adds": true }
|
|
75
|
+
],
|
|
76
|
+
"rows": [
|
|
77
|
+
{ "category": { "value": "West", "text": "West" },
|
|
78
|
+
"value": { "value": 1234567, "text": "$1.23M" } }
|
|
79
|
+
],
|
|
80
|
+
"totals": {},
|
|
81
|
+
"truncated": false,
|
|
82
|
+
"settings": { "showLabels": true, "onTarget": "#16a34a" },
|
|
83
|
+
"size": { "width": 520, "height": 300 },
|
|
84
|
+
"locale": "en-US",
|
|
85
|
+
"printing": false
|
|
86
|
+
}
|
|
87
|
+
\`\`\`
|
|
88
|
+
|
|
89
|
+
- A measure's \`adds\` says whether its rows add up: \`true\` for a sum or a count, \`false\` for an average, a ratio, a distinct count or a running total, absent when unknown. **Never add rows of a measure whose \`adds\` is \`false\`**: show a message instead (for example "This visual adds the rows: use a sum or a count"), and use \`totals\` for an overall value.
|
|
90
|
+
- Every cell is \`{ value, text }\`. **Show \`text\` whenever a reader sees a value**: it is already formatted (currency, units, dates). Use \`value\` only to compute positions, sizes and order. Never format numbers or dates yourself.
|
|
91
|
+
- **Numbers you compute yourself** (a total, a share, an axis tick) are formatted by the dashboard too:
|
|
92
|
+
- \`semaphor.format("<fieldId>", number)\` formats a number the way that field is formatted, for example an axis tick \`semaphor.format("value", 2000000)\` → \`"$2M"\`.
|
|
93
|
+
- \`semaphor.formatPercent(0.256)\` → \`"25.6%"\`, written as the card's own numbers are.
|
|
94
|
+
- \`semaphor.formatDate(value, part)\` gives one part of a date: \`"month"\` (\`"Jan"\`), \`"monthLong"\` (\`"January"\`), \`"weekday"\` (\`"Mon"\`), \`"day"\` (\`"14"\`), \`"year"\` (\`"2026"\`) or \`"monthYear"\` (\`"Jan 2026"\`).
|
|
95
|
+
- These are synchronous; call them as often as you need.
|
|
96
|
+
- \`totals\` holds a measure's total when the card's result has one; it is often empty, so compute what you need and format it with \`semaphor.format\`.
|
|
97
|
+
- Use \`fields[i].label\` for axis titles, legends and tooltips.
|
|
98
|
+
- Rows arrive in the query's order; date dimensions arrive oldest first.
|
|
99
|
+
- A cell can be \`{ "value": null, "text": "" }\` (no value). Treat it as a gap.
|
|
100
|
+
- \`text\` is plain text, never HTML: insert it as text.
|
|
101
|
+
- \`type\` is \`string\`, \`number\`, \`date\` or \`boolean\`.
|
|
102
|
+
- \`rows\` may be empty: show a short, neutral empty message.
|
|
103
|
+
- \`truncated: true\` means the dashboard capped the rows. Say so in small text.
|
|
104
|
+
|
|
105
|
+
## 3. Use the theme, never your own colours
|
|
106
|
+
|
|
107
|
+
The dashboard's brand arrives as CSS variables on \`:root\`, updated live (for example when the reader switches to dark mode):
|
|
108
|
+
|
|
109
|
+
| Variable | Use |
|
|
110
|
+
| --- | --- |
|
|
111
|
+
| \`--sv-fg\`, \`--sv-muted-fg\` | Text, secondary text |
|
|
112
|
+
| \`--sv-bg\`, \`--sv-muted\`, \`--sv-border\` | Card surface, subtle fills, lines |
|
|
113
|
+
| \`--sv-primary\`, \`--sv-primary-fg\`, \`--sv-accent\` | Emphasis, text on emphasis, soft highlight |
|
|
114
|
+
| \`--sv-primary-text\` | Text in the primary colour (links) |
|
|
115
|
+
| \`--sv-positive\`, \`--sv-negative\`, \`--sv-warning\` | Good, bad, caution, as fills: marks, bars, dots |
|
|
116
|
+
| \`--sv-positive-text\`, \`--sv-negative-text\`, \`--sv-warning-text\` | The same as text |
|
|
117
|
+
| \`--sv-selection\` | A highlighted mark |
|
|
118
|
+
| \`--sv-palette-1\` … \`--sv-palette-8\`, \`--sv-palette-N-fg\` | Series colours, in order, and the text that reads on each |
|
|
119
|
+
| \`--sv-seq-1\` … \`--sv-seq-5\`, \`--sv-seq-N-fg\` | A sequential scale, light to strong, and the text that reads on each step |
|
|
120
|
+
| \`--sv-grid\`, \`--sv-axis\` | Gridlines, axis lines and ticks (lines only, never text) |
|
|
121
|
+
| \`--sv-axis-label\`, \`--sv-legend\` | Axis labels and tick text, legend text |
|
|
122
|
+
| \`--sv-halo\` | Outline behind text drawn over marks |
|
|
123
|
+
| \`--sv-font\`, \`--sv-font-size\` | Font family, base size |
|
|
124
|
+
| \`--sv-radius\`, \`--sv-bar-radius\` | Corner radius for surfaces, for bars |
|
|
125
|
+
|
|
126
|
+
- Every text variable is readable on the surface it names. Don't lower text opacity: use \`--sv-muted-fg\` for secondary text.
|
|
127
|
+
- Use these for **every** colour, font and radius. Series take the palette in order. Shade by amount with the sequential scale only.
|
|
128
|
+
- **Never write a colour into your code.** When the author wants a specific colour, add a \`color\` setting and draw with \`payload.settings.<id>\`.
|
|
129
|
+
- The body is transparent over the card's own surface. Don't paint a background on \`body\`.
|
|
130
|
+
- For a JavaScript or canvas library, read the same values from \`semaphor.theme\`: \`{ mode, palette, paletteFg, sequential, sequentialFg, font: { family, size }, colors: { fg, mutedFg, bg, muted, border, primary, primaryFg, accent, positive, negative, warning, selection }, grid, axis, axisLabel, legend, halo, radius }\`. Ready-made themes: \`semaphor.theme.echarts()\`, \`semaphor.theme.vegaLite()\` and \`semaphor.theme.chartjs()\`.
|
|
131
|
+
- \`semaphor.onTheme((theme) => …)\` fires when the theme changes; \`onData\` also fires then, so redrawing in \`onData\` is enough.
|
|
132
|
+
|
|
133
|
+
## 4. Fit the card at any size
|
|
134
|
+
|
|
135
|
+
The author resizes the card freely. Each resize sends a new payload with the new \`size\`.
|
|
136
|
+
|
|
137
|
+
- Fill the iframe: \`html, body { width: 100%; height: 100%; margin: 0; overflow: hidden; }\`. Redraw from \`payload.size\` on every payload.
|
|
138
|
+
- **Never overflow.** No scrollbars, nothing cut off at an edge, no text on top of other text.
|
|
139
|
+
- **As space shrinks, simplify in this order:** tighten padding; use fewer axis ticks and shorter labels (end long names with "…"); move the legend, then hide it; hide value labels; show only the rows that fit plus a small "+N more"; at the very smallest, show only the headline.
|
|
140
|
+
- **As space grows, use it.** Scale marks to fill the card.
|
|
141
|
+
- Keep text at \`--sv-font-size\`, or a little smaller in tight spots, and never below 10px.
|
|
142
|
+
- When \`semaphor.printing\` is \`true\`, the card prints at its size and nothing can scroll; turn animations off.
|
|
143
|
+
|
|
144
|
+
## 5. Tell the dashboard what happened
|
|
145
|
+
|
|
146
|
+
- \`semaphor.ready()\`: call it after each payload has fully rendered, the empty state included. Exports and PDFs wait for it. With a canvas library, call it from the library's "render finished" event as \`semaphor.ready(payload)\`, passing the payload that render drew, so an earlier render finishing late never counts for a newer one.
|
|
147
|
+
- \`semaphor.error("message")\`: only for problems you can't draw around. The card then shows its data as a table.
|
|
148
|
+
- If the visual throws, never calls \`ready\`, or draws nothing, the card shows its data as a table instead.
|
|
149
|
+
- Give an SVG a \`role="img"\` and an \`aria-label\`.
|
|
150
|
+
- Show no product names, logos or AI wording.
|
|
151
|
+
`;function k(e,r){var o,l,d,h;const s=g(e),a=[...(((o=e.config)==null?void 0:o.groupByColumns)??[]),...(((l=e.config)==null?void 0:l.metricColumns)??[])],t=Object.fromEntries(Object.entries(((d=e.customVisual)==null?void 0:d.slots)??{}).flatMap(([u,i])=>{if(!i)return[];if("column"in i)return[[u,i.column]];const n=a.find(c=>c.id===i.fieldId),m=(n==null?void 0:n.label)||(n==null?void 0:n.name);return m?[[u,m]]:[];}));return{html:r,fields:s,...(Object.keys(t).length?{slots:t}:{}),...((h=e.customVisual)!=null&&h.settings?{settings:{...e.customVisual.settings}}:{})};}function T(e){return JSON.stringify([e.html,e.fields,e.slots??null,e.settings??null]);}export{T as a,g as c,k as e,x as s,w as v};
|
package/dist/chunks/{comparison-window-caption-tguyN24S.js → comparison-window-caption-WzGsqv4n.js}
RENAMED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{aR as x,i as M,k as m,n as S,an as w,ap as _,aS as c,aT as f}from"./pivot-result-contract-expectations-D_ane7I2.js";import{readPdfCapacityFacts as A,PDF_SAFETY_LIMIT_EXCEEDED as P,PDF_CAPACITY as l,PDF_NUMBER_COLUMN_TOO_WIDE as p,getUtf8ByteLength as I,FAST_PDF_POLICY as U,isPdfCapacityRefusalCode as L}from"../pdf-export-policy/index.js";import{w as R}from"./raw-temporal-value-B4Md6Xfb.js";function N(t,e,r){const a={...e,locale:e.locale??r};if(a.type==="number")return m(t,a);const{prefix:n,suffix:o,...s}=a;return`${n??""}${m(t,{...s,negativeStyle:a.type==="currency"?a.negativeStyle:"minus"})}${o??""}`;}function D(t,e,r){return t===null?{value:t,text:null}:!e||!M(e)&&e.type!=="duration"?{value:t,text:m(t,{type:"number",locale:r})}:e.type==="duration"?{value:t,text:S(t,{inputUnit:e.inputUnit,outputStyle:e.outputStyle,largestUnit:e.largestUnit,smallestUnit:e.smallestUnit,maxUnits:e.maxUnits,prefix:e.prefix,suffix:e.suffix,negativeInParentheses:e.negativeStyle==="parentheses"})}:{value:t,text:N(t,e,r)};}function F(t,e,r,a){return t===null?{value:t,text:null}:a==="percent"?{value:t,text:m(t,{type:"percent",locale:r,minimumFractionDigits:e,maximumFractionDigits:e,percentValueMode:"fraction"})}:{value:t,text:m(t,{type:"number",locale:r,minimumFractionDigits:e,maximumFractionDigits:e,suffix:"×"})};}function C(t,e){if(t===void 0)return e;if(!Number.isInteger(t)||t<0||t>6)throw new RangeError("Comparison precision must be an integer from 0 to 6.");return t;}function Y(t,e){const r={mode:e.displayMode,current:D(t.currentValue,e.metricFormat,e.locale),comparison:D(t.comparisonValue,e.metricFormat,e.locale)};return(e.displayMode==="difference"||e.displayMode==="both")&&(r.difference=D(t.delta,x(e.metricFormat),e.locale)),(e.displayMode==="percent_change"||e.displayMode==="both")&&(r.percentChange=F(t.percentChange,C(e.precision,1),e.locale,"percent")),e.displayMode==="ratio"&&(r.ratio=F(t.ratio,C(e.precision,2),e.locale,"ratio")),r;}const i=t=>t.toLocaleString("en-US"),h=t=>`${i(Math.ceil(t/1048576))} MB`,$="export the data as CSV or Excel";function H(t){const e=A(t.facts),r=t.dataExport?`Add a filter to narrow it, or ${$}.`:"Add a filter to narrow it, then export again.";switch(t.code){case"PDF_ROW_LIMIT_EXCEEDED":{const a=t.subject??"This table",n=e.rowLimit??l.maxTableRows;return e.rowCount!==void 0?`${a} has ${i(e.rowCount)} rows. A PDF holds up to ${i(n)} rows per table. ${r}`:`${a} has more than ${i(n)} rows, the most a PDF holds per table. ${r}`;}case"PDF_PAGE_LIMIT_EXCEEDED":{const a=t.subject??"This PDF",n=e.pageLimit??l.maxPages;return e.pageCount!==void 0?`${a} is ${i(e.pageCount)} pages. A PDF holds up to ${i(n)}. ${r}`:`${a} is longer than ${i(n)} pages, the most a PDF holds. ${r}`;}case"PDF_SIZE_LIMIT_EXCEEDED":{const a=t.subject??"This PDF",n=e.byteLimit??l.maxFileBytes;return e.bytes!==void 0?`${a} is ${h(e.bytes)}. A PDF file holds up to ${h(n)}. ${r}`:`${a} is larger than ${h(n)}, the most a PDF file holds. ${r}`;}case"PDF_CAPTURE_TOO_TALL":return`${t.subject??"This dashboard"} is too long to print as one PDF. Print one sheet or fewer cards${t.dataExport?`, or ${$}`:""}.`;case p:return`A number in this table is too wide for its column in a PDF. Use landscape or fewer columns${t.dataExport?`, or ${$}`:""}.`;case P:return`This PDF is over what a PDF holds: ${i(l.maxTableRows)} rows per table, ${i(l.maxPages)} pages and ${h(l.maxFileBytes)}. ${r}`;}}class O extends Error{constructor(e,r=P){super(e),this.code=r;}}function j(t){return L(t)||t===P||t===p;}function T(t){if(!t||typeof t!="object")return;const{error:e,message:r,detail:a}=t;for(const n of[e,r,a])if(typeof n=="string"&&n.trim())return n.trim();}async function k(t){const e=`PDF request failed: ${t.status} ${t.statusText}`.trim(),r=t.headers.get("content-type")||"";try{if(r.includes("application/json")){const n=await t.json(),o=typeof n.code=="string"?n.code:typeof n.errorCode=="string"?n.errorCode:void 0;return{message:T(n)||e,code:o};}const a=await t.text();if(!a.trim())return{message:e};try{const n=JSON.parse(a),o=typeof n.code=="string"?n.code:typeof n.errorCode=="string"?n.errorCode:void 0;return{message:T(n)||a.trim(),code:o};}catch{return{message:a.trim()};}}catch{return{message:e};}}async function W(t){if(!t.token)throw new Error("Missing auth token for PDF export");if(I(t.serializedPayload)>U.maxRequestBytes)throw new Error("Fast-path PDF request exceeds the structured body limit");const e=await(t.fetchImpl??fetch)(t.url,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${t.token}`},body:t.serializedPayload,signal:t.signal});if(!e.ok){const a=await k(e);throw j(a.code)?new O(a.message,a.code):new Error(a.message);}const r=await e.json();if(r!=null&&r.error)throw new Error(r.error);if(typeof(r==null?void 0:r.url)!="string"||!r.url.trim())throw new Error("Fast-path PDF response missing download URL");return r;}function J(t,e,r){const a=e.from>t.start?e.from:t.start,n=e.to&&e.to<t.end?e.to:t.end,s=a<=r&&n>r?"running":a>t.start?"start":n<t.end?"end":void 0;return{start:a,end:n,...(s?{partial:s}:{})};}function K(t,e,r){switch(e){case"running":return`${t} (so far)`;case"start":return r?`${t} (from ${r.start})`:`${t} (partial)`;case"end":return r?`${t} (to ${r.end})`:`${t} (partial)`;default:return t;}}function Q(t,e,r){const a=Date.parse(t.startInclusive),n=Date.parse(t.endExclusive);if(!Number.isFinite(a)||!Number.isFinite(n))return;if(e.granularity==="hour"||e.granularity==="minute"||e.granularity==="second"){const y=u=>{try{return new Intl.DateTimeFormat((r==null?void 0:r.locale)??"en-US",{timeStyle:(r==null?void 0:r.dateTime.timeStyle)??"short",timeZone:e.calendar.tz}).format(new Date(u));}catch{return new Date(u).toISOString();}};return{start:y(a),end:y(n)};}const o={kind:"temporal_bucket",granularity:"day",calendar:e.calendar};let s;try{s=w({metadata:o,locale:(r==null?void 0:r.locale)??"en-US",...(r?{styles:{dateStyle:r.dateStyle,dateTime:r.dateTime}}:{})});}catch{s=void 0;}const d=y=>{const u=R(new Date(y),e.calendar.tz),g=`${String(u.year).padStart(4,"0")}-${String(u.month).padStart(2,"0")}-${String(u.day).padStart(2,"0")}`;try{return s?_({value:g,metadata:o,format:s.format}):g;}catch{return g;}};return{start:d(a),end:d(n-1)};}const B=/* @__PURE__ */new Set(["day","week","month","quarter","year"]);function v(t,e){try{const r=f(t),a=c(r,e,"yyyy-MM-dd");if(c(r,e,"HH:mm:ss.SSS")!=="00:00:00.000")return{date:a,time:c(r,e,"h:mm a")};const[n,o,s]=a.split("-").map(Number),d=new Date(Date.UTC(n,o-1,s));return d.setUTCDate(d.getUTCDate()-1),{date:c(d,"UTC","yyyy-MM-dd")};}catch{return;}}function b(t,e,r){const a=v(t.end,e);if(a)return{start:c(f(t.start),e,r?"MMM d":"MMM d, yyyy"),endDate:c(f(`${a.date}T00:00:00Z`),"UTC","MMM d, yyyy"),...(a.time?{endTime:a.time}:{})};}function E(t){return!!(t&&B.has(t));}function z(t,e,r,a=!1){if(E(r))try{const o=b(t,e,!1);if(o&&o.start===o.endDate)return o.endTime?`${o.endDate} until ${o.endTime}`:o.endDate;}catch{}const n=V(t,e,r,a);return`${n.start} – ${n.end}`;}function V(t,e,r,a=!1){try{if(E(r)){const n=b(t,e,a);if(n)return{start:n.start,end:n.endTime?`${n.endDate}, ${n.endTime}`:n.endDate};}if(r==="second"||r==="minute"||r==="hour"){const n=a?"MMM d, h:mm a":"MMM d, yyyy, h:mm a";return{start:c(f(t.start),e,n),end:`before ${c(f(t.end),e,n)}`};}}catch{}return{start:t.start,end:`before ${t.end}`};}export{O as P,Y as a,W as b,J as c,K as d,Q as e,z as f,V as g,j as i,H as p,k as r};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{S as g,c as S,a as E}from"./schema-O1Y3WTGF.js";const R={background:"--semaphor-background",foreground:"--semaphor-foreground",muted:"--semaphor-muted",mutedForeground:"--semaphor-muted-foreground",border:"--semaphor-border",input:"--semaphor-input",primary:"--semaphor-primary",primaryForeground:"--semaphor-primary-foreground",accent:"--semaphor-accent",accentForeground:"--semaphor-accent-foreground",selection:"--semaphor-selection",card:"--semaphor-card",cardForeground:"--semaphor-card-foreground",positive:"--semaphor-positive",negative:"--semaphor-negative",warning:"--semaphor-warning",info:"--semaphor-info",destructive:"--semaphor-destructive",destructiveForeground:"--semaphor-destructive-foreground",link:"--semaphor-link"},C={light:{"--semaphor-code-string":"158 64% 22%","--semaphor-code-number":"158 64% 22%","--semaphor-code-boolean":"158 64% 22%","--semaphor-code-fn":"217 91% 40%","--semaphor-code-keyword":"263 70% 42%"},dark:{"--semaphor-code-string":"158 64% 52%","--semaphor-code-number":"158 64% 52%","--semaphor-code-boolean":"158 64% 52%","--semaphor-code-fn":"213 94% 68%","--semaphor-code-keyword":"264 89% 74%"}};function w(o){var d,c,s,i;const e=o.defaults??g,n=o.mode??x(o.spec.mode,o.systemMode),r=F(o.spec.schemes[n]??e.schemes[n]),t=((d=r.tokens)==null?void 0:d.color)??{},m={...C[n]};for(const[f,u]of Object.entries(R)){const a=t[f];if(!a)continue;const h=S(a);if(!h)throw new Error(`Invalid compiled appearance color for ${f}`);m[u]=h;}P(m,(c=r.tokens)==null?void 0:c.radius),T(m,(s=r.tokens)==null?void 0:s.typography);const p=k(r,e.schemes[n],n);return{mode:n,scheme:r,cssVariables:m,colorValues:t,chartPalette:p.palette,chartTheme:p,table:(i=r.components)==null?void 0:i.table};}const _={light:{background:"#fff",title:"#000",body:"#000",footer:"#999",border:"rgb(128,131,139)",cornerRadius:4},dark:{background:"#000",title:"#fff",body:"#fff",footer:"#999",border:"rgb(128,131,139)",cornerRadius:2}},b=2;function k(o,e,n){var d,c,s,i,f,u,a;const r=(d=o.components)==null?void 0:d.chart,t=(c=o.tokens)==null?void 0:c.typography,m=(s=e.tokens)==null?void 0:s.typography,p=(t==null?void 0:t.baseFontSize)??(m==null?void 0:m.baseFontSize)??14;return{mode:n,palette:(r==null?void 0:r.palette)??((f=(i=e.components)==null?void 0:i.chart)==null?void 0:f.palette)??E,font:{family:(t==null?void 0:t.fontFamily)??(m==null?void 0:m.fontFamily)??"",size:p-b},gridColor:r==null?void 0:r.gridColor,axisColor:(r==null?void 0:r.axisColor)??(r==null?void 0:r.foreground),legendColor:r==null?void 0:r.foreground,tooltip:_[n],barRadius:(r==null?void 0:r.barRadius)??((a=(u=e.components)==null?void 0:u.chart)==null?void 0:a.barRadius)??0};}function T(o,e){e!=null&&e.fontFamily&&(o["--semaphor-font-family"]=e.fontFamily),e!=null&&e.headingFontFamily&&(o["--semaphor-heading-font-family"]=e.headingFontFamily),e!=null&&e.monoFontFamily&&(o["--semaphor-mono-font-family"]=e.monoFontFamily),(e==null?void 0:e.baseFontSize)!==void 0&&(o["--semaphor-font-size"]=`${e.baseFontSize}px`);}function P(o,e){o["--semaphor-brand"]=o["--semaphor-primary"]??o["--semaphor-foreground"],o["--semaphor-secondary"]=o["--semaphor-accent"]??o["--semaphor-muted"],o["--semaphor-secondary-foreground"]=o["--semaphor-accent-foreground"]??o["--semaphor-foreground"],o["--semaphor-popover"]=o["--semaphor-card"]??o["--semaphor-background"],o["--semaphor-popover-foreground"]=o["--semaphor-card-foreground"]??o["--semaphor-foreground"],o["--semaphor-ring"]=o["--semaphor-primary"]??o["--semaphor-foreground"];const n=A((e==null?void 0:e.control)??5),r=A((e==null?void 0:e.card)??(e==null?void 0:e.control)??5);o["--semaphor-radius"]=n,o["--semaphor-control-radius"]=n,o["--semaphor-card-radius"]=r;}const l={none:"none",subtle:"0 1px 2px 0 rgb(0 0 0 / 0.05)",raised:"0 1px 3px 0 rgb(0 0 0 / 0.1), 0 1px 2px -1px rgb(0 0 0 / 0.1)"};function F(o,e,n){return typeof o=="string"?(e==="shadow"||n==="shadow")&&o in l?l[o]:o:typeof o!="object"||o===null||Array.isArray(o)?o:Object.fromEntries(Object.entries(o).map(([r,t])=>[r,F(t,r,e)]));}function A(o){return`${Number((o/16).toFixed(4))}rem`;}function x(o,e="light"){return o==="system"?e:o;}export{l as A,w as c};
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
var T=Object.defineProperty;var q=(e,a,i)=>a in e?T(e,a,{enumerable:!0,configurable:!0,writable:!0,value:i}):e[a]=i;var b=(e,a,i)=>q(e,typeof a!="symbol"?a+"":a,i);import{z as t}from"zod";import{s as k}from"./analytics-base-schemas-DMFrDqn_.js";const J=1;function z(e){return e.inEditor?"Editor changes":"Dashboard changes";}const G=["assistant_unavailable","context_invalid","context_too_large","conversation_not_found","conversation_full","turn_in_progress","daily_limit_reached","budget_exhausted","not_permitted","no_data_found","model_unavailable"];function _(e){return`You've used ${e===void 0?"today's questions":`today's ${e} questions`}. They reset tomorrow. To keep going, contact your administrator.`;}function Y(e,a={}){return e==="daily_limit_reached"?_(a.dailyLimit):$[e];}const $={assistant_unavailable:"The assistant is not available here.",context_invalid:"Something on this page changed. Try again.",context_too_large:"There is too much on this page to send with your question. Ask about one card, or clear some filters.",conversation_not_found:"This conversation has ended. Start a new one.",conversation_full:"This conversation is full. Start a new one.",turn_in_progress:"Still answering your last question.",daily_limit_reached:_(),budget_exhausted:"This question needed more steps than one answer allows. Try asking for less at once.",not_permitted:"You do not have access to the data this needs.",no_data_found:"No data matched this question.",model_unavailable:"The assistant could not answer right now. Try again."},A={messageChars:4e3,contextBytes:48*1024,requestBytes:128*1024,openDashboardBytes:2*1024*1024,summaryCards:30,otherSheets:50,activeInputs:50,inputValues:50,addedSources:50,cardFields:60,taggedFields:5,cardFilters:40,cardControls:40,drillSteps:10,sqlChars:2e4,sqlParameters:40,idChars:200,labelChars:500,textChars:4e3,turnsPerConversation:40,conversationBytes:1024*1024,toolCallsPerTurn:12,secondsPerTurn:120,artifactRecords:200,conversationTtlSeconds:24*60*60};function H(e){return new TextEncoder().encode(JSON.stringify(e)).length;}function X(e,a){if(e.length<=a)return e;const i=n=>` [${n} more characters not shown]`,s=a-i(e.length).length;return`${e.slice(0,s)}${i(e.length-s)}`;}class K extends Error{constructor(i){super($.context_too_large);b(this,"code","context_too_large");this.bytes=i,this.name="AssistantContextTooLargeError";}}const j=1,E=["dashboard","editor","none"],r=A,p=t.string().min(1).max(r.idChars),h=t.string().max(r.labelChars),u=t.string().max(r.textChars),g=t.number().int().positive(),y=t.string().min(1).max(100),S=t.object({id:p,title:h}).strict(),N=t.object({inputId:p,label:h,value:t.discriminatedUnion("kind",[t.object({kind:t.literal("set"),text:u,omittedValues:g.optional(),notApplied:t.literal("opened_from_another_dashboard").optional(),fingerprint:y}).strict(),t.object({kind:t.literal("varies")}).strict()]),globalDate:t.literal(!0).optional()}).strict(),v={id:p,title:h,visualType:t.string().max(100),source:k.optional()},F=t.object(v).strict(),I=e=>t.object(Object.fromEntries(e.map(a=>[a,g.optional()]))).strict().optional(),L=t.object({role:t.enum(["row","column","measure","detail"]),label:h,name:h,aggregate:t.string().max(40).optional(),granularity:t.string().max(40).optional()}).strict(),x=t.discriminatedUnion("status",[t.object({status:t.literal("described"),fields:t.array(L).max(r.cardFields),filters:t.array(t.object({origin:t.enum(["dashboard_input","card_input","card","drill","selection"]),text:u,omittedValues:g.optional()}).strict()).max(r.cardFilters),controls:t.array(t.object({label:h,valueText:u}).strict()).max(r.cardControls),drillPath:t.array(u).max(r.drillSteps),sql:t.object({text:t.string().max(r.sqlChars),parameters:t.array(t.object({name:h,valueText:u}).strict()).max(r.sqlParameters)}).strict().optional(),comparisons:t.array(u).max(r.cardFields).optional(),omitted:I(["fields","filters","controls","drillSteps","sqlParameters","comparisons"])}).strict(),t.object({status:t.literal("not_described"),reason:t.enum(["matrix","custom_visual","python","snapshot_blocked","snapshot_pending"]),message:u.optional()}).strict()]),R=t.object({...v,fingerprint:y,description:x}).strict(),ee=t.object({version:t.literal(j),surface:t.enum(E),dashboard:t.object({id:p,title:h,unsavedEdits:t.boolean()}).strict().optional(),sheet:S.optional(),otherSheets:t.array(S).max(r.otherSheets),activeInputs:t.array(N).max(r.activeInputs),cards:t.array(F).max(r.summaryCards),selectedCard:R.optional(),editing:t.object({mode:t.enum(["visual","sql"])}).strict().optional(),omitted:I(["otherSheets","activeInputs","cards"]),timeZone:t.string().min(1).max(100)}).strict().superRefine((e,a)=>{e.surface!=="none"&&!e.dashboard&&a.addIssue({code:t.ZodIssueCode.custom,path:["dashboard"],message:`required on the ${e.surface} surface`}),e.selectedCard&&e.surface==="none"&&a.addIssue({code:t.ZodIssueCode.custom,path:["selectedCard"],message:"only on the dashboard and editor surfaces"}),e.surface==="editor"!=!!e.editing&&a.addIssue({code:t.ZodIssueCode.custom,path:["editing"],message:"required on the editor surface, and only there"});});function te(e,a){if(!e)return[];const i=[];e.surface!==a.surface&&i.push({kind:"surface_changed",from:e.surface,to:a.surface}),e.sheet&&a.sheet&&e.sheet.id!==a.sheet.id&&i.push({kind:"sheet_changed",fromSheetId:e.sheet.id,toSheetId:a.sheet.id});const s=e.selectedCard,n=a.selectedCard;(s==null?void 0:s.id)!==(n==null?void 0:n.id)?i.push({kind:"selection_changed",...(s?{fromCardId:s.id}:{}),...(n?{toCardId:n.id}:{})}):s&&n&&s.fingerprint!==n.fingerprint&&i.push({kind:"card_changed",cardId:n.id});const d=O(e.activeInputs??[],a.activeInputs);return d.length>0&&i.push({kind:"inputs_changed",inputIds:d}),i;}function O(e,a){const i=o=>o?o.value.kind==="set"?o.value.fingerprint:"varies":void 0,s=new Map(e.map(o=>[o.inputId,o])),n=new Map(a.map(o=>[o.inputId,o]));return[.../* @__PURE__ */new Set([...s.keys(),...n.keys()])].filter(o=>i(s.get(o))!==i(n.get(o)));}function se(e,a,i){var n,d,o;const s=[];if(e.surface==="none"||!e.dashboard)s.push("The user is not looking at a dashboard. Answer from the sources they added; if none fit, find the data with the discovery tools or ask which data to use.");else{const c=e.surface==="editor"?"editing a visual on":"looking at";s.push(`The user is ${c} the dashboard ${l(e.dashboard.title)} (id ${e.dashboard.id})${e.dashboard.unsavedEdits?", which has unsaved edits":""}.`),e.sheet&&s.push(`Current sheet: ${l(e.sheet.title)} (id ${e.sheet.id}).`),e.otherSheets.length>0&&s.push(`Other sheets: ${e.otherSheets.map(C=>l(C.title)).join(", ")}${m((n=e.omitted)==null?void 0:n.otherSheets,"sheets")}.`);}if(e.activeInputs.length>0){s.push("","Dashboard inputs with a value (which of them a card applies is in that card's description when the user asks about it):");for(const c of e.activeInputs)s.push(`- ${B(c)}`);(d=e.omitted)!=null&&d.activeInputs&&s.push(`- ${e.omitted.activeInputs} more inputs are not listed.`);}if(e.cards.length>0){s.push("","Cards on this sheet:");for(const c of e.cards)s.push(`- ${f(c)}`);(o=e.omitted)!=null&&o.cards&&s.push(`- ${e.omitted.cards} more cards are not listed.`);}if(e.selectedCard&&s.push("",...Q(e.selectedCard,e.editing)),i.length>0){s.push("","Sources the user added:");for(const c of i)s.push(`- ${w(c)}`);}if(a.length>0){s.push("","Since the last question:");for(const c of a)s.push(`- ${V(c,e)}`);}return s.push("",`The user's time zone is ${e.timeZone}.`),s.join(`
|
|
2
|
+
`);}function P(e){const a=[e.name,e.aggregate,e.granularity?`by ${e.granularity}`:void 0].filter(Boolean);return`${e.role} ${l(e.label)} (${a.join(", ")})`;}function l(e){return JSON.stringify(e);}function m(e,a){return e?`, and ${e} more ${a}`:"";}function f(e){return`${l(e.title)} (card id ${e.id}, ${e.visualType})${e.source?` from ${w(e.source)}`:""}`;}function B(e){const{value:a}=e;return a.kind==="varies"?`${l(e.label)}: differs by card; ask about a card to see its value`:a.notApplied?`${a.text} (not applied in this view: it was opened from another dashboard without this dashboard's own filters)`:`${a.text}${e.globalDate?", applied to each card's own date field, on cards that have one":""}`;}const D={matrix:"it is a Matrix card",custom_visual:"it is a custom visual",python:"it is computed with Python",snapshot_blocked:"the dashboard could not compile it",snapshot_pending:"it was still loading when the question was sent"},M={dashboard_input:"dashboard input",card_input:"the card's own input",card:"the card's own filter",drill:"drill",selection:"selection on another card"};function Q(e,a){var d;const i=a?[`The user is editing the visual ${f(e)} in ${a.mode==="sql"?"SQL":"visual"} mode. What follows is their draft as it is on screen, which may not be saved: fromCard on this card runs the draft, and its rows are the draft's, not the saved card's. When you may change the dashboard, a card.update on this card lands in their draft (and only this card can change); otherwise explain the steps in the editor or write SQL for them to paste.`]:[`The user is asking about the card ${f(e)}.`],s=e.description;if(s.status==="not_described")return i.push(`How this card is built is not available to you: ${D[s.reason]}${s.message?` (${s.message})`:""}. Answer with the tools, and say that you could not read the card's definition.`),i;const n=s.omitted??{};if(i.push(a?"What the draft runs, as the editor compiled it:":"What the card runs, as the dashboard compiled it:"),s.fields.length>0){const o=s.fields.map(P);i.push(`- Fields: ${o.join("; ")}${m(n.fields,"fields not listed")}.`);}else i.push("- Fields: none.");if(s.filters.length>0){i.push("- Filters, all applied together:");for(const o of s.filters)i.push(` - ${M[o.origin]}: ${o.text}`);n.filters&&i.push(` - ${n.filters} more filters are not listed.`);}else i.push("- Filters: none.");if(s.drillPath.length>0&&i.push(`- Drilled into: ${s.drillPath.join(", then ")}${m(n.drillSteps,"steps")}.`),s.controls.length>0){i.push("- Controls:");for(const o of s.controls)i.push(` - ${l(o.label)}: ${o.valueText}`);n.controls&&i.push(` - ${n.controls} more controls are not listed.`);}if(s.sql&&(i.push("- SQL:","```sql",s.sql.text,"```"),s.sql.parameters.length>0&&i.push(`- SQL parameters: ${s.sql.parameters.map(o=>`${o.name} = ${o.valueText}`).join("; ")}${m(n.sqlParameters,"parameters")}.`)),(d=s.comparisons)!=null&&d.length){i.push("- Comparisons (the windows are known only once a query runs):");for(const o of s.comparisons)i.push(` - ${o}`);n.comparisons&&i.push(` - ${n.comparisons} more comparisons are not listed.`);}return i.push("This lists the card's fields, filters, drill path, controls, SQL and comparisons; it does not include the card's sorting, row limit or calculated-field formulas. A query you build yourself can differ from the card."),i;}function w(e){switch(e.kind){case"semantic":return`dataset ${l(e.label??e.datasetName)} (domainId ${e.domainId}, datasetName ${e.datasetName})`;case"physical":return`table ${[e.databaseName,e.schemaName,e.tableName].filter(Boolean).join(".")} (connectionId ${e.connectionId})`;case"sql":return`SQL on ${e.label?l(e.label):"a connection"} (connectionId ${e.connectionId})`;}}function V(e,a){var i;switch(e.kind){case"surface_changed":return`the user moved from the ${e.from} view to the ${e.to} view.`;case"sheet_changed":return`the user switched sheets (now ${l(((i=a.sheet)==null?void 0:i.title)??e.toSheetId)}).`;case"selection_changed":return e.toCardId?`the user is now asking about card ${e.toCardId}.`:"the user is no longer asking about a specific card.";case"card_changed":return`card ${e.cardId} now runs differently (its fields, filters, controls or SQL changed).`;case"inputs_changed":return`these dashboard inputs changed: ${e.inputIds.map(n=>{const d=a.activeInputs.find(o=>o.inputId===n);return d?l(d.label):`input ${n} (now cleared)`;}).join(", ")}.`;}}export{A,ee as a,L as b,H as c,K as d,j as e,X as f,E as g,te as h,P as i,w as j,J as k,G as l,_ as m,Y as n,$ as o,z as p,se as r};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{u as G,w as S,x as Q,y as X,z as _,A as $,B as H,C as Y}from"./resolve-dashboard-input-context-B5yUS9ZM.js";import{canonicalizeSupportedCurrencyCode as K}from"../value-format-preferences/index.js";import{D as Z}from"./bookmark-state-BmbBu1th.js";import{l as v}from"./validators-U8IL8djK.js";import"./matrix-operation-contract-DceN49RX.js";import"./analytics-base-schemas-DMFrDqn_.js";import{b,r as U,aI as W,i as ee,aJ as ne}from"./pivot-result-contract-expectations-D_ane7I2.js";const P=/\[\[\s*param\.([A-Za-z0-9_.-]+)\s*\]\]/g,B=/\bparam\s*\(\s*(['"])([^'"]+)\1/g;function re(e){const n=[];let t=0;for(;t<e.length;){const r=e.indexOf("{{",t),o=e.indexOf("{%",t);let a=-1,i="";if(r===-1?(a=o,i="%}"):o===-1||r<o?(a=r,i="}}"):(a=o,i="%}"),a===-1)break;const c=e.indexOf(i,a+2);if(c===-1){t=a+2;continue;}n.push(e.slice(a+2,c)),t=c+2;}return n;}function A(e){var r,o;if(!e)return[];const n=/* @__PURE__ */new Set();let t;for(P.lastIndex=0;(t=P.exec(e))!==null;){const a=(r=t[1])==null?void 0:r.trim();a&&n.add(a);}for(const a of re(e))for(B.lastIndex=0;(t=B.exec(a))!==null;){const i=(o=t[2])==null?void 0:o.trim();i&&n.add(i);}return Array.from(n);}function O(e){const n=/* @__PURE__ */new Set(),t=/* @__PURE__ */new Map();for(const r of e.controlBindings||[])n.add(r.controlId),r.target==="sql_param"&&t.set(r.paramId,r.controlId);for(const r of A(e.sql))n.add(t.get(r)??r);return Array.from(n);}function Ie(e){const n=/* @__PURE__ */new Map(),t=/* @__PURE__ */new Map();for(const r of e.controlBindings||[])r.target==="sql_param"&&t.set(r.paramId,r.controlId);for(const r of A(e.sql))n.set(r,{paramId:r,controlId:t.get(r)??r});return Array.from(n.values());}function C(e){return(e==null?void 0:e.type)==="number"||(e==null?void 0:e.type)==="currency";}function te(e){return(e==null?void 0:e.type)==="number";}function oe(e){var t;if(!te(e))return!1;const n=(t=e==null?void 0:e.numberFormat)==null?void 0:t.style;return n===void 0||n==="decimal"||n==="currency";}function ie(e,n){const t=n==null?void 0:n.type;if(t&&t!=="none"&&t!=="number")return{currencyBindable:!1};const r=t==="number"?n!=null&&n.numberFormat?Q(n.numberFormat,{preserveOmittedProperties:!0}):{type:"number"}:void 0,o=b(e.format,{preserveOmittedProperties:!0}),a=v(e.dataType)==="number"?{type:"number"}:void 0,c=(n==null?void 0:n.inheritMetricFormat)===!1||!!(n!=null&&n.numberFormat)&&(n==null?void 0:n.inheritMetricFormat)!==!0?r:o||a||r;return{authoredFormat:c,currencyBindable:C(c)};}function ae(e,n){const t=b(n.format,{preserveOmittedProperties:!0}),r=v(n.dataType)==="number"?{type:"number"}:void 0,o=t||r;return{authoredFormat:o,source:t?"semantic":r?"inferred":void 0,currencyBindable:C(o)};}function k(e,n={}){var u,d,l;const t=n.column??((u=G(e))==null?void 0:u.value);if((t==null?void 0:t.kind)==="sqlKpiValue"){const m=n.resultColumnKey?{kind:"column",columnKey:n.resultColumnKey}:void 0,f=b(U({card:e,column:{kind:"sqlKpiValue"},surface:"kpiValue"}).format,{preserveOmittedProperties:!0});return{target:m,authoredFormat:f,...(f?{source:"stored"}:{}),currencyBindable:!!m&&C(f)};}const r=t?(l=(d=e.config)==null?void 0:d.metricColumns)==null?void 0:l.find(m=>m.id===t.fieldId):void 0,o=r!=null&&r.id?{kind:"metric",metricId:r.id}:void 0,a=b(r==null?void 0:r.format,{preserveOmittedProperties:!0}),i=v(r==null?void 0:r.dataType)==="number"?{type:"number"}:void 0,c=a||i;return{target:o,authoredFormat:c,...(a?{source:"stored"}:i?{source:"inferred"}:{}),currencyBindable:S(e.type)&&!!o&&C(c)};}function q(e,n,t){var o;const r=t(e,n);return((o=e.derivedField)==null?void 0:o.format)??(r==null?void 0:r.format)??(r==null?void 0:r.resolvedField.format);}function N(e,n,t){return e.kind==="calculated"?e.definition.format:q(e.field,n,t);}function Fe(e,n){const t=_(n),r=(o,a)=>Object.fromEntries(o.flatMap(i=>{const c=a(i);return c?[[i.id,c]]:[];}));return{measureFormats:r(e.measures,o=>N(o,e.source,t)),levelFormats:r([...e.rows,...e.columns],o=>q(o.field,e.source,t))};}function R(e,n=[]){const t=X(e);if(t.status!=="ready")return[];const{spec:r,presentation:o}=t.config,a=_(n);return r.measures.map(i=>{var y;const c=i.kind==="aggregate"?a(i.field,r.source):void 0,u=W(o.measureFormats[i.id],N(i,r.source,a)),d=i.kind==="calculated"?i.definition.dataType:["MIN","MAX"].includes(i.aggregate)?((y=i.field.derivedField)==null?void 0:y.dataType)??(c==null?void 0:c.resolvedField.dataType)??i.field.dataType:"number",l=v(d)==="number",m=i.kind==="calculated"||!!(c||i.field.derivedField||i.field.name==="*"),f=u&&ee(u)?u:!u&&l&&m?{type:"number"}:void 0;return{measureId:i.id,label:ne(i,o),canonical:f};});}function ce(e){var n,t;return e.type==="detailTable"?((n=e.config)==null?void 0:n.detailColumns)||[]:((t=e.config)==null?void 0:t.metricColumns)||[];}function se(e){return new Set(Z(e).flatMap(n=>(n.controlBindings||[]).filter($).map(t=>t.controlId)));}function ue(e,n){const t=[n.id,n.alias,n.label,n.name,n.qualifiedFieldName].filter(a=>!!a);for(const a of t)if(e[a])return e[a];const r=new Set(t.map(a=>a.trim().toLowerCase())),o=Object.entries(e).find(([a])=>r.has(a.trim().toLowerCase()));return o==null?void 0:o[1];}function h(e){return[...new Map(e.map(n=>[p(n),n])).values()];}function de(e,n=[],t){var x;const r=!!((x=e.sql)!=null&&x.trim()),o=S(e.type),a=r&&o&&e.type!=="kpi"&&e.type!=="matrixTable",i=ce(e),c=H(e),u=!r&&e.type==="kpi"?i.map(s=>k(e,{column:{kind:"field",fieldId:s.id}})):[],d=!r&&e.type==="matrixTable"?R(e,t):[],l=(r?[]:i).map(s=>({kind:"metric",metricId:s.id})),m=d.map(s=>({kind:"matrix_measure",measureId:s.measureId})),f=d.filter(s=>{var F,M;return((F=s.canonical)==null?void 0:F.type)==="number"||((M=s.canonical)==null?void 0:M.type)==="currency";}).map(s=>({kind:"matrix_measure",measureId:s.measureId})),y=e.type==="matrixTable"?[]:e.type==="kpi"?u.filter(s=>s.currencyBindable).flatMap(s=>s.target?[s.target]:[]):(r||!o?[]:i).filter(s=>(Y(e.type)?ie(s,ue(c,s)):ae(e,s)).currencyBindable).map(s=>({kind:"metric",metricId:s.id})),g=[...new Set(n)],L=(a?g:[]).map(s=>({kind:"column",columnKey:s})),z=(a?g:[]).filter(s=>oe(c[s])).map(s=>({kind:"column",columnKey:s})),T=(r&&e.type==="kpi"?g.slice(0,1):[]).map(s=>({kind:"column",columnKey:s})),I=r&&e.type==="kpi"?k(e,{resultColumnKey:g[0]}):void 0,J=o&&I!=null&&I.currencyBindable?T:[];return{knownTargets:h([...(e.type==="matrixTable"?m:l),...L,...T]),eligibleTargets:h([...y,...f,...z,...J])};}function ke(e,n){const t=k(e,{resultColumnKey:n});return t.currencyBindable?t.target:void 0;}function Te(e){var n;return(n=e.card.sql)!=null&&n.trim()?{kind:"column",columnKey:e.columnKey}:e.metricId?{kind:"metric",metricId:e.metricId}:void 0;}function p(e){return e.kind==="metric"?`metric:${e.metricId}`:e.kind==="column"?`column:${e.columnKey}`:`matrix_measure:${e.measureId}`;}function le(e){if(!e||typeof e!="object"||Array.isArray(e))return;const n=e;if(n.kind==="metric"&&typeof n.metricId=="string"&&n.metricId.trim())return{kind:"metric",metricId:n.metricId};if(n.kind==="column"&&typeof n.columnKey=="string"&&n.columnKey.trim())return{kind:"column",columnKey:n.columnKey};if(n.kind==="matrix_measure"&&typeof n.measureId=="string"&&n.measureId.trim())return{kind:"matrix_measure",measureId:n.measureId};}function w(e){const n=K(e);return typeof e=="string"&&e===n?n:void 0;}function E(e){if(e.type!=="enum"||e.source.kind!=="manual")return{diagnostic:"invalid_control_type"};const n=e.source.options.map(t=>w(t.value));if(n.length===0||n.some(t=>!t))return{diagnostic:"invalid_currency_option"};if(e.requiredAtExecution){const t=e.initialValueStrategy==="saved_default"?w(e.defaultValue):void 0;if(!t||!n.includes(t))return{diagnostic:"invalid_control_default"};}return{control:e,currencies:n};}function xe(e){return"control"in E(e);}function j(e){const n=se(e.dashboard);if(n.size===0)return{definitions:e.definitions||[],values:e.values||{}};const t=new Set([...n].filter(r=>!e.referencedControlIds.has(r)));return{definitions:(e.definitions||[]).filter(r=>!t.has(r.id)),values:Object.fromEntries(Object.entries(e.values||{}).filter(([r])=>!t.has(r)))};}function Me(e){return j({...e,referencedControlIds:new Set(O({sql:e.filterSql,controlBindings:[]}))});}function Pe(e){var n;return j({...e,referencedControlIds:new Set(O({sql:(n=e.source)==null?void 0:n.sql,controlBindings:[]}))});}function D(e){return{knownKeys:new Set(e.knownTargets.map(p)),eligibleKeys:new Set(e.eligibleTargets.map(p)),controlsById:new Map((e.controls||[]).map(n=>[n.id,n]))};}function V(e,n){if(!e||typeof e!="object"||e.target!=="presentation_currency")return{};const t=e,r=typeof t.controlId=="string"&&t.controlId.trim()?t.controlId:void 0;if(!r)return{diagnostic:{code:"invalid_binding_shape"}};const o=le(t.presentationTarget);if(!o)return{diagnostic:{code:"missing_target",controlId:r}};const a=p(o);if(!n.knownKeys.has(a))return{diagnostic:{code:"stale_target",controlId:r}};if(!n.eligibleKeys.has(a))return{diagnostic:{code:"inapplicable_target",controlId:r}};const i=n.controlsById.get(r);if(!i)return{diagnostic:{code:"missing_control",controlId:r}};const c=E(i);return"diagnostic"in c?{diagnostic:{code:c.diagnostic,controlId:r}}:{binding:{controlId:r,presentationTarget:o,control:c.control,currencies:c.currencies}};}function Be(e){const n=D(e);return(e.bindings||[]).flatMap(t=>{const r=V(t,n);return"diagnostic"in r?[r.diagnostic]:[];});}function me(e){var o;const n=[],t=p(e.target),r=D(e);for(const a of e.bindings||[]){const i=V(a,r);if("diagnostic"in i){n.push(i.diagnostic);continue;}const c=i.binding;if(!c||p(c.presentationTarget)!==t)continue;const d=K((o=e.values)==null?void 0:o[c.control.id]);if(!(!d||!c.currencies.includes(d)))return{currency:d,diagnostics:n};}return{diagnostics:n};}function he(e,n,t,r){const o={...e,config:{...e.config,matrix:n}},a=de(o,[],r),i=R(o,r),c={...n.presentation.measureFormats};for(const u of i){const d={kind:"matrix_measure",measureId:u.measureId},{currency:l}=me({...t,...a,bindings:e.controlBindings,target:d});if(!l||!u.canonical)continue;const{locale:m,...f}=u.canonical;c[u.measureId]={...f,type:"currency",currency:l};}return{...n.presentation,measureFormats:c};}export{ie as a,R as b,k as c,de as d,Ie as e,p as f,Te as g,te as h,me as i,O as j,se as k,he as l,xe as m,Be as n,ce as o,A as p,Me as q,ae as r,ke as s,Pe as t,Fe as u};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{v as F}from"./resolve-dashboard-input-context-B5yUS9ZM.js";function h(e){if(!(e!=null&&e.expectedType))return"table";const r=Array.isArray(e.expectedType)?e.expectedType[0]:e.expectedType;return M(r)?r:"table";}const E=["bar","horizontalBar","line","area","stackedArea","combo","pie","doughnut","radar","polarArea","bubble","scatter","stackedBar","stackedLine","table","detailTable","kpi","pyramid","tornado","range","text","funnel","bullet","heatmap","treemap","custom"];function M(e){return E.includes(e);}function x(e){const r=e.position;if(typeof r=="number")return r;if(typeof r=="string"){const t=r.match(/\d+/);if(t){const n=Number(t[0]);if(!Number.isNaN(n))return n;}}return Number.POSITIVE_INFINITY;}function m(e){if(typeof e=="number")return{kind:"number",start:e,end:e};if(typeof e=="string"){const r=e.match(/^(\d+)$/);if(r){const s=Number(r[1]);return{kind:"number",start:s,end:s};}const t=e.match(/^(\d+)-(\d+)$/);if(t){const s=Number(t[1]),d=Number(t[2]);return{kind:"range",start:s,end:d};}const n=e.match(/^(\d+)\+$/);if(n)return{kind:"dynamic",start:Number(n[1]),end:Number.POSITIVE_INFINITY};}return null;}function k(e){return!e||e.length===0?void 0:[...e].sort((t,n)=>x(t)-x(n))[0];}function N(e,r){if(!e||e.length===0)return;const t=[],n=[],s=[];e.forEach(i=>{const u=m(i.position);u&&(u.kind==="number"?t.push(i):u.kind==="range"?n.push(i):u.kind==="dynamic"&&s.push(i));});const d=t.find(i=>{const u=m(i.position);return(u==null?void 0:u.kind)==="number"&&u.start===r;});if(d)return d;const p=n.sort((i,u)=>x(i)-x(u)).find(i=>{const u=m(i.position);return(u==null?void 0:u.kind)==="range"&&r>=u.start&&r<=u.end;});if(p)return p;const a=s.map(i=>({slot:i,parsed:m(i.position)})).filter(i=>{var u;return((u=i.parsed)==null?void 0:u.kind)==="dynamic";}).sort((i,u)=>{var o,f;return(((o=i.parsed)==null?void 0:o.start)??0)-(((f=u.parsed)==null?void 0:f.start)??0);}).filter(i=>{var u;return r>=(((u=i.parsed)==null?void 0:u.start)??0);}).sort((i,u)=>{var o,f;return(((o=u.parsed)==null?void 0:o.start)??0)-(((f=i.parsed)==null?void 0:f.start)??0);})[0];return a==null?void 0:a.slot;}function A(e,r){const t=N(e,r);if(t)return h(t);}function V(e,r){var n;const t=(n=e==null?void 0:e.customCardPreferences)==null?void 0:n.slotIndex;return typeof t=="number"?t:r;}function S(e,r){var t;if(!((t=e==null?void 0:e.customCardPreferences)!=null&&t.url))return!1;if(e.type==="custom"||e.customCardPreferences.visualType==="multiple"||e.customCardPreferences.dataInputCardIds||(e.customCardPreferences.minInputs||0)>1||(e.customCardPreferences.maxInputs||0)>1)return!0;if(r&&r.length>1){const n=r.filter(s=>{var d;return typeof((d=s.customCardPreferences)==null?void 0:d.slotIndex)=="number";});if(n.length>1&&n.some(s=>s.id!==e.id))return!0;}return!1;}function O(e){const r=[];let t=-1;e.forEach((n,s)=>{const d=V(n,s);d>t&&(t=d),r[d]=n??null;});for(let n=0;n<=t;n+=1)n in r||(r[n]=null);return r;}function $(e){return e.map((r,t)=>!r.customCardPreferences||r.customCardPreferences.slotIndex===t?r:{...r,customCardPreferences:{...r.customCardPreferences,slotIndex:t}});}function v(e){const r=k(e);if(r)return h(r);}function R(e,r,t){if(!e)return;const n=A(t,r);return e.type==="custom"&&n?n:e.type;}function Y(e,r,t){var T;const n={dataSource:t.dataSource,connectionId:t.connectionId},s={type:"component",visualType:"multiple",url:r.url,componentName:r.name,icon:r.icon,pluginChartType:r.chartType,minInputs:r.minInputs,maxInputs:r.maxInputs},d=r.minInputs||1,p=e.map(c=>({slot:c,parsed:m(c.position)})).filter(c=>c.parsed!==null).reduce((c,l)=>{const g=l.parsed.end;return Number.isFinite(g)?Math.max(c,g):c;},-1),b=Math.max(d,p+1),a=k(e),i=a?x(a):0;let u=!1;const o=[];for(let c=0;c<b;c+=1){const l=N(e,c),g=h(l),I=!u&&c===i,P=c,C={...n,id:F(),title:(I?a==null?void 0:a.label:l==null?void 0:l.label)||`Tab ${c+1}`,tabTitle:(I?a==null?void 0:a.label:l==null?void 0:l.label)||`Tab ${c+1}`,description:(I?a==null?void 0:a.description:l==null?void 0:l.description)||"",type:g,sql:"",preferences:{onClickFilter:[{columnIndex:0,expression:""}]},...(I&&{customCardPreferences:{...s,slotIndex:P}}),...(!I&&{customCardPreferences:{slotIndex:P}})};I&&(u=!0),o.push(C);}if(!u&&o.length>0){const c=((T=o[0].customCardPreferences)==null?void 0:T.slotIndex)??0;o[0]={...o[0],type:o[0].type,customCardPreferences:{...s,slotIndex:c}};}const f=o.findIndex(c=>{var l;return!!((l=c.customCardPreferences)!=null&&l.url);});if(f>0){const[c]=o.splice(f,1);o.unshift(c);}return o;}function _({frame:e,configCard:r,isMultiInputVisual:t}){var s;if(!t||!r)return e.cards;const n=(s=r.customCardPreferences)==null?void 0:s.dataInputCardIds;return n?Object.keys(n).sort((d,y)=>Number(d)-Number(y)).map(d=>{var p;const y=(p=n[d])==null?void 0:p.cardId;return e.cards.find(b=>b.id===y)||null;}):e.cards;}function j(e,r){return r&&S(r,e.cards)?r:e.cards.find(t=>S(t,e.cards))||null;}function q(e,r){var s,d;if(!e)return null;const t=r==null?void 0:r.visualType;if(t)return t;if(r!=null&&r.slots&&r.slots.length>0||((r==null?void 0:r.minInputs)||0)>1||((r==null?void 0:r.maxInputs)||0)>1||((r==null?void 0:r.dataInputs)||[]).length>1)return"multiple";const n=(s=e.customCardPreferences)==null?void 0:s.visualType;return n||((d=e.customCardPreferences)!=null&&d.dataInputCardIds?"multiple":null);}function w(e){return e.visualType==="multiple"||e.slots&&e.slots.length>0||(e.minInputs||0)>1||(e.maxInputs||0)>1||(e.dataInputs||[]).length>1?"multiple":"single";}function z(e){return Array.isArray(e)?{records:e}:e;}export{V as a,O as b,R as c,w as d,Y as e,j as f,_ as g,N as h,S as i,$ as j,h as k,v as l,z as n,q as r};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{r as j,k as x,m as $}from"./resolve-dashboard-input-context-B5yUS9ZM.js";function I(s,t,n={}){var u,m,g;if(t.clear){if(t.html!==void 0||t.slots||t.settings)return d("Start over takes the visual off the card; send its new code as a separate change.","customVisual","Send clear alone.");if(!s.customVisual&&s.type==="customVisual")return{ok:!0,card:s,manifest:void 0};const{customVisual:l,...a}=s;return{ok:!0,card:{...a,type:"customVisual"},manifest:void 0};}const i=s.customVisual??{};let e=i,r=n.manifest;if(t.html!==void 0){const l=j(t.html,{kind:"visual"});if(!l.ok&&!n.keepUnreadable){const a=l.findings.filter(o=>o.severity==="error");return{ok:!1,problem:{code:"invalid_change",message:a.map(o=>o.message).join(" ")||"The visual is invalid.",path:"html",fix:((u=a.find(o=>o.fix))==null?void 0:u.fix)??"Fix the HTML against the contract (semaphor_get_extension_contract) and send it again.",details:{reason:"custom_visual_invalid",findings:l.findings}}};}if(r=l.ok?l.manifest:void 0,t.html!==((m=i.draft)==null?void 0:m.html)){const{version:a,draft:o,...f}=e;e={...f,draft:{html:t.html}};}r&&(e=O(e,r));}if((t.slots&&Object.keys(t.slots).length||t.settings&&Object.keys(t.settings).length)&&!r)return d("This visual's slots and settings can't be read, so they can't be changed.","customVisual","Send the visual's html with the change, or change it in the editor.");if(t.slots){for(const a of Object.keys(t.slots))if(!r.slots.some(o=>o.id===a))return d(`This visual has no slot "${a}"; it has ${p(r.slots.map(o=>o.id))}.`,`slots.${a}`,"Name one of its slots.",r.slots.map(o=>o.id));const l=k(e.slots,t.slots,_);l!==e.slots&&(e=h(e,"slots",l));}if(t.settings){const l={};for(const[o,f]of Object.entries(t.settings)){const c=(g=r.settings)==null?void 0:g[o];if(!c){const v=Object.keys(r.settings??{});return d(v.length?`This visual has no setting "${o}"; it has ${p(v)}.`:`This visual has no settings, so "${o}" can't be set.`,`settings.${o}`,"Name one of its settings.",v);}if(f===null||f===c.default){l[o]=null;continue;}const b=y(c,f);if(b)return d(`"${c.label}" ${b}.`,`settings.${o}`,"Send a value the setting takes.",V(c));l[o]=f;}const a=k(e.settings,l,(o,f)=>o===f);a!==e.settings&&(e=h(e,"settings",a));}return e===i&&s.type==="customVisual"?{ok:!0,card:s,manifest:r}:{ok:!0,card:{...s,type:"customVisual",customVisual:e},manifest:r};}function d(s,t,n,i){return{ok:!1,problem:{code:"invalid_change",message:s,path:t,fix:n,...(i!=null&&i.length?{allowed:i}:{})}};}function O(s,t){let n=s;if(s.slots){const i=Object.fromEntries(Object.entries(s.slots).filter(([e])=>t.slots.some(r=>r.id===e)));Object.keys(i).length!==Object.keys(s.slots).length&&(n=h(n,"slots",i));}if(s.settings){const i=Object.fromEntries(Object.entries(s.settings).filter(([e,r])=>{var m;const u=(m=t.settings)==null?void 0:m[e];return u&&r!==u.default&&!y(u,r);}));Object.keys(i).length!==Object.keys(s.settings).length&&(n=h(n,"settings",i));}return n;}function y(s,t){switch(s.type){case"boolean":return typeof t=="boolean"?void 0:"is on or off (true or false)";case"number":return typeof t!="number"||!Number.isFinite(t)?"takes a number":s.min!==void 0&&t<s.min?`is at least ${s.min}`:s.max!==void 0&&t>s.max?`is at most ${s.max}`:void 0;case"string":return typeof t!="string"?"takes text":s.maxLength!==void 0&&t.length>s.maxLength?`takes at most ${s.maxLength} characters`:void 0;case"select":return typeof t=="string"&&s.options.some(n=>n.value===t)?void 0:`is one of ${p(s.options.map(n=>n.value))}`;case"color":return typeof t=="string"&&(x(t)||$(t))?void 0:"takes a theme colour (palette-1 to palette-8, primary, positive…) or a hex colour";}}function V(s){if(s.type==="select")return s.options.map(t=>t.value);if(s.type==="boolean")return["true","false"];}function p(s){const t=s.map(n=>`"${n}"`);return t.length<=1?t[0]??"none":`${t.slice(0,-1).join(", ")} and ${t[t.length-1]}`;}function k(s,t,n){let i=s;for(const[e,r]of Object.entries(t)){const u=i==null?void 0:i[e];if(r===null){if(u===void 0)continue;const{[e]:m,...g}=i;i=g;}else(u===void 0||!n(u,r))&&(i={...i,[e]:r});}return i;}function h(s,t,n){const{[t]:i,...e}=s;return n&&Object.keys(n).length?{...e,[t]:n}:e;}function _(s,t){return"fieldId"in s?"fieldId"in t&&s.fieldId===t.fieldId:"column"in t&&s.column===t.column;}export{I as w};
|