react-semaphor 0.1.352 → 0.1.354

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (33) hide show
  1. package/dist/chunks/{calendar-preferences-dialog-BP6VCs24.js → calendar-preferences-dialog-BlF7tQVO.js} +1 -1
  2. package/dist/chunks/{calendar-preferences-dialog-DqB0gRKY.js → calendar-preferences-dialog-C89peE7b.js} +1 -1
  3. package/dist/chunks/contracts-CoCOpd_i.js +11 -0
  4. package/dist/chunks/contracts-CtB2VONT.js +1 -0
  5. package/dist/chunks/{dashboard-briefing-launcher-DxLotfPa.js → dashboard-briefing-launcher-CzTXDvdU.js} +1 -1
  6. package/dist/chunks/{dashboard-briefing-launcher-CE8bNT8E.js → dashboard-briefing-launcher-thntGohY.js} +3 -3
  7. package/dist/chunks/{dashboard-controls-B00gdNuz.js → dashboard-controls-DyPZNfmg.js} +3 -3
  8. package/dist/chunks/{dashboard-controls-DiRVwF2s.js → dashboard-controls-Pbm2gZA5.js} +1 -1
  9. package/dist/chunks/{dashboard-json-qKWjSofT.js → dashboard-json-B2qFCVuf.js} +1 -1
  10. package/dist/chunks/{dashboard-json-BvdoNEjb.js → dashboard-json-sLdO-LC1.js} +1 -1
  11. package/dist/chunks/{edit-dashboard-visual-B25Pk-Hr.js → edit-dashboard-visual-BTTIog61.js} +3 -3
  12. package/dist/chunks/{edit-dashboard-visual-ChpvAgup.js → edit-dashboard-visual-j17SdtRC.js} +1 -1
  13. package/dist/chunks/{index-D14U5QOC.js → index-Dh4zmLqk.js} +21309 -21093
  14. package/dist/chunks/{index-DYHvr2To.js → index-o6tGBWww.js} +206 -206
  15. package/dist/chunks/{resource-management-panel-BOW5JCor.js → resource-management-panel-CgQRI6g7.js} +2 -2
  16. package/dist/chunks/{resource-management-panel-ChEmFjoR.js → resource-management-panel-wn2UAr-d.js} +1 -1
  17. package/dist/chunks/{use-create-flow-overlay-state-CZk4rrrw.js → use-create-flow-overlay-state-CATp6oTj.js} +1 -1
  18. package/dist/chunks/{use-create-flow-overlay-state-C5jxnrOJ.js → use-create-flow-overlay-state-CVwvTfpo.js} +2 -2
  19. package/dist/chunks/{use-visual-utils-DHBV770y.js → use-visual-utils-BVmHziAk.js} +1 -1
  20. package/dist/chunks/{use-visual-utils-ika7wXDI.js → use-visual-utils-YXOTwvaX.js} +1 -1
  21. package/dist/dashboard/index.cjs +1 -1
  22. package/dist/dashboard/index.js +1 -1
  23. package/dist/dashboard-authoring/index.cjs +3 -3
  24. package/dist/dashboard-authoring/index.js +484 -440
  25. package/dist/data-app-builder/index.cjs +1 -1
  26. package/dist/data-app-builder/index.js +1 -1
  27. package/dist/index.cjs +1 -1
  28. package/dist/index.js +5 -5
  29. package/dist/style.css +1 -1
  30. package/dist/surfboard/index.cjs +1 -1
  31. package/dist/surfboard/index.js +2 -2
  32. package/dist/types/dashboard-authoring.d.ts +1 -1
  33. package/package.json +1 -1
@@ -1,9 +1,9 @@
1
1
  import { jsx as e, jsxs as n, Fragment as oe } from "react/jsx-runtime";
2
2
  import { c as He, u as se, G as Ge, a as Z, B as O, f as te, N as be, V as $e, L as ie, a2 as de, X as ke, Z as We, _ as Xe, $ as Ye, a1 as Ze, az as Je } from "./switch-21kU-tcj.js";
3
3
  import Qe, { useState as b, useEffect as ee, useRef as qe } from "react";
4
- import { ah as ue, aL as et, aM as tt, aI as ce, aN as nt, aO as at, aP as st, aQ as it, aR as Y, aS as ot, aT as rt, aU as lt, aV as xe, az as he, aW as dt, aX as ct, aY as Ne, aZ as we, a_ as ut, J as ye, A as Ce, a$ as ve, b0 as Se, b1 as Ee, b2 as Ve, b3 as Le, b4 as Ae, b5 as Oe, b6 as Te, b7 as Re, b8 as ht, b9 as pe, ba as pt, y as ae, u as mt, bb as Ue, c as Ie, d as ze, e as Me, f as Pe, g as Fe, bc as ft, o as je, bd as gt, be as De, bf as xt } from "./index-D14U5QOC.js";
4
+ import { ah as ue, aL as et, aM as tt, aI as ce, aN as nt, aO as at, aP as st, aQ as it, aR as Y, aS as ot, aT as rt, aU as lt, aV as xe, az as he, aW as dt, aX as ct, aY as Ne, aZ as we, a_ as ut, J as ye, A as Ce, a$ as ve, b0 as Se, b1 as Ee, b2 as Ve, b3 as Le, b4 as Ae, b5 as Oe, b6 as Te, b7 as Re, b8 as ht, b9 as pe, ba as pt, y as ae, u as mt, bb as Ue, c as Ie, d as ze, e as Me, f as Pe, g as Fe, bc as ft, o as je, bd as gt, be as De, bf as xt } from "./index-Dh4zmLqk.js";
5
5
  import "./index-CuHybtft.js";
6
- import { u as Be } from "./use-visual-utils-DHBV770y.js";
6
+ import { u as Be } from "./use-visual-utils-BVmHziAk.js";
7
7
  /**
8
8
  * @license lucide-react v0.453.0 - ISC
9
9
  *
@@ -1,4 +1,4 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),o=require("./switch-C0S63HAv.js"),x=require("react"),t=require("./index-DYHvr2To.js");require("./index-BxM99sFL.js");const oe=require("./use-visual-utils-ika7wXDI.js");/**
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),o=require("./switch-C0S63HAv.js"),x=require("react"),t=require("./index-o6tGBWww.js");require("./index-BxM99sFL.js");const oe=require("./use-visual-utils-YXOTwvaX.js");/**
2
2
  * @license lucide-react v0.453.0 - ISC
3
3
  *
4
4
  * This source code is licensed under the ISC license.
@@ -1,4 +1,4 @@
1
- "use strict";const s=require("./switch-C0S63HAv.js"),v=require("react"),p=require("./index-DYHvr2To.js"),e=require("react/jsx-runtime");require("./index-BxM99sFL.js");const re=require("./use-visual-utils-ika7wXDI.js");/**
1
+ "use strict";const s=require("./switch-C0S63HAv.js"),v=require("react"),p=require("./index-o6tGBWww.js"),e=require("react/jsx-runtime");require("./index-BxM99sFL.js");const re=require("./use-visual-utils-YXOTwvaX.js");/**
2
2
  * @license lucide-react v0.453.0 - ISC
3
3
  *
4
4
  * This source code is licensed under the ISC license.
@@ -1,9 +1,9 @@
1
1
  import { c as te, G as L, H as ne, u as oe, Z as ft, _ as ht, $ as gt, a as ie, a1 as bt, a9 as yt, B as V, e as xt, X as Ke, E as Pe, f as Ye, S as Ge, aa as vt, ab as Ct, ac as se, ad as Ae, ae as ze, af as be, ag as ye, ah as kt, ai as Me, aj as Nt, ak as St, al as le, am as Dt, an as Oe, g as Be, ao as Xe, ap as Je, aq as Ze, L as P, a2 as We, a3 as xe, a4 as ve, a5 as Ce, a6 as ke, a7 as Ne, ar as et, as as wt, at as It, au as Re, av as Et, aw as Qe, ax as Tt, ay as Se } from "./switch-21kU-tcj.js";
2
2
  import { useEffect as de, useMemo as z, useState as Q, useRef as De, useCallback as O, Fragment as Vt } from "react";
3
- import { al as _t, am as tt, an as qt, ao as Ft, ap as Lt, aq as At, ar as zt, y as Mt, as as Ot, ae as ue, at, ag as rt, au as st, av as Bt, p as R, aw as Rt, ax as Qt, ay as je, az as jt, aA as Ut, aB as lt, aC as nt, aD as Ht, aE as $t, aF as Kt, aG as Pt, aH as Yt, aI as Gt, aJ as Xt, aK as Jt } from "./index-D14U5QOC.js";
3
+ import { al as _t, am as tt, an as qt, ao as Ft, ap as Lt, aq as At, ar as zt, y as Mt, as as Ot, ae as ue, at, ag as rt, au as st, av as Bt, p as R, aw as Rt, ax as Qt, ay as je, az as jt, aA as Ut, aB as lt, aC as nt, aD as Ht, aE as $t, aF as Kt, aG as Pt, aH as Yt, aI as Gt, aJ as Xt, aK as Jt } from "./index-Dh4zmLqk.js";
4
4
  import { jsx as t, jsxs as d, Fragment as $ } from "react/jsx-runtime";
5
5
  import "./index-CuHybtft.js";
6
- import { u as we } from "./use-visual-utils-DHBV770y.js";
6
+ import { u as we } from "./use-visual-utils-BVmHziAk.js";
7
7
  /**
8
8
  * @license lucide-react v0.453.0 - ISC
9
9
  *
@@ -1,4 +1,4 @@
1
- import { ad as X, u as Y, ae as Z, af as ee, ag as te, ah as re, ai as se, aj as ae, p as V, ak as oe } from "./index-D14U5QOC.js";
1
+ import { ad as X, u as Y, ae as Z, af as ee, ag as te, ah as re, ai as se, aj as ae, p as V, ak as oe } from "./index-Dh4zmLqk.js";
2
2
  import { H as ne, E as ie, u as b, G as H, I as ce } from "./switch-21kU-tcj.js";
3
3
  import { useState as z, useEffect as de, useCallback as A } from "react";
4
4
  function le(e) {
@@ -1 +1 @@
1
- "use strict";const u=require("./index-DYHvr2To.js"),f=require("./switch-C0S63HAv.js"),S=require("react");function K(e){const[a,s]=S.useState(null),[r,t]=S.useState(null),o=u.useEnsureReactGlobals();return S.useEffect(()=>{if(!e||e.trim()===""){s(null),t(null);return}if(!o)return;(async()=>{try{if(!e.startsWith("http://")&&!e.startsWith("https://"))throw new Error(`Invalid URL format: ${e}`);try{new URL(e)}catch{throw new Error(`Invalid URL: ${e}`)}const i=`${e.endsWith("/")?e:`${e}/`}index.js`;try{if(!(await fetch(i,{method:"HEAD"})).ok)throw new Error(`Module not found at ${i}`)}catch{}const m=await import(i);if(typeof m.useChartStore!="function")throw new Error("useChartStore is not a function");s(()=>m.useChartStore),t(null)}catch(n){const i=n instanceof Error?n.message:"Unknown error";console.error("Failed to load remote chart store:",i),t(i),s(null)}})()},[e,o]),a}function X(e,a){if(e.length===0)return"";const s=e.find(r=>{var t,o;return((t=r.customCardPreferences)==null?void 0:t.visualType)==="multiple"||!!((o=r.customCardPreferences)!=null&&o.dataInputCardIds)});if(s)return s.id;if(a){const r=e.find(t=>t.id===a);if(r){const t=r.tabTitle;if(t=="All__Header")return e[0].id;if(t&&t.endsWith("__Header")){const l=t.split("__")[0],n=e.find(i=>i.tabTitle===l);return n?n.id:e[0].id}return a}}return e[0].id}const A=new Set;function Y(e){return A.add(e),()=>{A.delete(e)}}function z(){A.forEach(e=>{e()})}const Z=e=>{if(!e||!("detailTableBackup"in e))return e;const{detailTableBackup:a,...s}=e;return s};async function B(e,a,s,r){if(!a||!s)throw new Error("Missing auth token or visual ID");const t=["resource-by-id","visual",s],o=r.getQueryData(t);if(o)return console.log("Using cached visual data for:",s),{data:o,fromCache:!0};console.log("Fetching visual data from network for:",s);const l=u.ue.loading("Loading visual...",{position:"top-center"});try{const n=await fetch(`${e}/management/v1/visuals/${s}`,{headers:{Authorization:`Bearer ${a}`}});if(!n.ok)throw new Error("Failed to load visual");const i=await n.json();return r.setQueryData(t,i),u.ue.dismiss(l),{data:i,fromCache:!1}}catch(n){throw u.ue.dismiss(l),n}}function H(e){if(typeof e=="string")return JSON.parse(e);if(typeof e=="object")return e;throw new Error("Invalid frame object format")}function ee(e,a){var o,l;const s=(e==null?void 0:e.frameObject)??((o=e==null?void 0:e.visual)==null?void 0:o.frameObject);if(!s)return!1;const r=H(s);if(!(r!=null&&r.cards)||r.cards.length===0)return!1;const t=(l=r.cards)==null?void 0:l.find(n=>n.id===r.activeCardId);return t?(u.setupEditorWithCard({...a,frame:r,card:t,visualId:(e==null?void 0:e.id)||r.visualId}),!0):!1}function te(){const e=f.useEditorStore(r=>{var t;return((t=r.card.customCardPreferences)==null?void 0:t.url)||""}),a=K(e);return{getUpdatedFrame:S.useCallback(()=>{var b;z();const{frame:r,card:t,isDevMode:o,isShowingVisual:l,selectedSchemaName:n,selectedDatamodelId:i,selectedDatabaseName:m,selectedTableName:p,selectedConnectionId:y}=f.useEditorStore.getState(),I=t.sql,U=(b=a==null?void 0:a.getState())==null?void 0:b.settings,V=f.buildSavedEditorCard(t,{isDevMode:o,cardSql:I,isShowingVisual:l,selectedSchemaName:n,selectedDatamodelId:i,selectedDatabaseName:m,selectedTableName:p,selectedConnectionId:y,remoteChartSettings:U,stripConfig:Z}),g=r.cards.map(E=>E.id===t.id?V:E);return{...r,cards:g,activeCardId:X(g,r.activeCardId)}},[a])}}function re(){const{authToken:e,tokenProps:a}=u.useSemaphorContext(),s=u.useQueryClient(),r=u.useAddFrameWithFreshSemanticExecutionPayload(),t=u.useSelectedVisual(),{selectVisual:o}=u.useManagementActions(),{setFrame:l,setCard:n,setIsDevMode:i,initializeModeDrafts:m,setActiveTabCardId:p,updateDataSource:y,setQueryResultColumns:I,setSelectedConnectionId:U,setSelectedDatabaseName:V,setSelectedSchemaName:g,setSelectedTableName:b,setSelectedDatamodelId:E,setFilterValues:P,setInlineFilterValuesMap:M,setApplyFilters:k,clearEditorContext:L}=f.useEditorActions(),{setIsDashboardEditing:v,setIsVisualEditing:T,setSelectedFrameId:j,clearSelectedFrameId:N,setIsDashboardPanelOpen:R}=f.useDashboardActions(),w=f.useDashboardStore(c=>c.selectedSheetId),W=f.useDashboardStore(c=>c.selectedFrameId),$=f.useDashboardStore(c=>c.dashboard),_=f.useDashboardStore(c=>c.filterValues),x=f.useDashboardStore(c=>c.inlineFilterValuesMap),F=u.useVisualById((t==null?void 0:t.id)||"",{enabled:!!(t!=null&&t.id)&&!!(e!=null&&e.accessToken)}),Q=S.useCallback(async c=>{try{o(c),N(),L();const{data:h,fromCache:D}=await B(a.apiServiceUrl,(e==null?void 0:e.accessToken)||"",c.id,s);if(!ee(h,{setFrame:l,setCard:n,setIsDevMode:i,initializeModeDrafts:m,setActiveTabCardId:p,updateDataSource:y,setQueryResultColumns:I,setSelectedConnectionId:U,setSelectedDatabaseName:V,setSelectedSchemaName:g,setSelectedTableName:b,setSelectedDatamodelId:E,setFilterValues:P,setInlineFilterValuesMap:M,setApplyFilters:k,setIsDashboardEditing:v,setIsVisualEditing:T,dashboard:$,selectedSheetId:w,selectedFrameId:W,filterValues:_,inlineFilterValuesMap:x}))throw new Error("Failed to setup editor with visual data");return{success:!0,fromCache:D}}catch(h){return console.error("Error editing visual:",h),{success:!1,error:"Failed to load visual for editing"}}},[e==null?void 0:e.accessToken,a.apiServiceUrl,s,o,l,n,v,T,i,m,p,y,I,U,V,g,b,E,P,M,k,L,N,$,w,W,_,x]),G=S.useCallback(async c=>{var D;const h=d=>(u.ue.error(d),{success:!1,error:d});try{if(o(c),!w)return h("No sheet selected. Please select a sheet first.");const{data:d,fromCache:J}=await B(a.apiServiceUrl,(e==null?void 0:e.accessToken)||"",c.id,s),O=(d==null?void 0:d.frameObject)??((D=d==null?void 0:d.visual)==null?void 0:D.frameObject);if(!O)return h("Visual has no frame data");const C=H(O);if(!(C!=null&&C.cards)||C.cards.length===0)return h("Visual frame is malformed");const q={...u.cloneLinkedFrameWithSourceMapping(C),visualId:c.id};return await r(w,q,"end"),v(!0),j(q.id),R(!1),{success:!0,fromCache:J}}catch(d){return console.error("Error adding visual:",d),h(d instanceof Error?d.message:"Failed to add visual to dashboard")}},[e==null?void 0:e.accessToken,a.apiServiceUrl,s,o,w,v,j,R,r]);return{visual:F.data,isLoading:F.isLoading,isError:F.isError,error:F.error,handleEditLibraryVisual:Q,handleAddLibraryVisual:G,getUpdatedFrame:te().getUpdatedFrame,refetch:F.refetch}}exports.flushPendingEditorDrafts=z;exports.registerPendingEditorDraftFlusher=Y;exports.useVisualUtils=re;
1
+ "use strict";const u=require("./index-o6tGBWww.js"),f=require("./switch-C0S63HAv.js"),S=require("react");function K(e){const[a,s]=S.useState(null),[r,t]=S.useState(null),o=u.useEnsureReactGlobals();return S.useEffect(()=>{if(!e||e.trim()===""){s(null),t(null);return}if(!o)return;(async()=>{try{if(!e.startsWith("http://")&&!e.startsWith("https://"))throw new Error(`Invalid URL format: ${e}`);try{new URL(e)}catch{throw new Error(`Invalid URL: ${e}`)}const i=`${e.endsWith("/")?e:`${e}/`}index.js`;try{if(!(await fetch(i,{method:"HEAD"})).ok)throw new Error(`Module not found at ${i}`)}catch{}const m=await import(i);if(typeof m.useChartStore!="function")throw new Error("useChartStore is not a function");s(()=>m.useChartStore),t(null)}catch(n){const i=n instanceof Error?n.message:"Unknown error";console.error("Failed to load remote chart store:",i),t(i),s(null)}})()},[e,o]),a}function X(e,a){if(e.length===0)return"";const s=e.find(r=>{var t,o;return((t=r.customCardPreferences)==null?void 0:t.visualType)==="multiple"||!!((o=r.customCardPreferences)!=null&&o.dataInputCardIds)});if(s)return s.id;if(a){const r=e.find(t=>t.id===a);if(r){const t=r.tabTitle;if(t=="All__Header")return e[0].id;if(t&&t.endsWith("__Header")){const l=t.split("__")[0],n=e.find(i=>i.tabTitle===l);return n?n.id:e[0].id}return a}}return e[0].id}const A=new Set;function Y(e){return A.add(e),()=>{A.delete(e)}}function z(){A.forEach(e=>{e()})}const Z=e=>{if(!e||!("detailTableBackup"in e))return e;const{detailTableBackup:a,...s}=e;return s};async function B(e,a,s,r){if(!a||!s)throw new Error("Missing auth token or visual ID");const t=["resource-by-id","visual",s],o=r.getQueryData(t);if(o)return console.log("Using cached visual data for:",s),{data:o,fromCache:!0};console.log("Fetching visual data from network for:",s);const l=u.ue.loading("Loading visual...",{position:"top-center"});try{const n=await fetch(`${e}/management/v1/visuals/${s}`,{headers:{Authorization:`Bearer ${a}`}});if(!n.ok)throw new Error("Failed to load visual");const i=await n.json();return r.setQueryData(t,i),u.ue.dismiss(l),{data:i,fromCache:!1}}catch(n){throw u.ue.dismiss(l),n}}function H(e){if(typeof e=="string")return JSON.parse(e);if(typeof e=="object")return e;throw new Error("Invalid frame object format")}function ee(e,a){var o,l;const s=(e==null?void 0:e.frameObject)??((o=e==null?void 0:e.visual)==null?void 0:o.frameObject);if(!s)return!1;const r=H(s);if(!(r!=null&&r.cards)||r.cards.length===0)return!1;const t=(l=r.cards)==null?void 0:l.find(n=>n.id===r.activeCardId);return t?(u.setupEditorWithCard({...a,frame:r,card:t,visualId:(e==null?void 0:e.id)||r.visualId}),!0):!1}function te(){const e=f.useEditorStore(r=>{var t;return((t=r.card.customCardPreferences)==null?void 0:t.url)||""}),a=K(e);return{getUpdatedFrame:S.useCallback(()=>{var b;z();const{frame:r,card:t,isDevMode:o,isShowingVisual:l,selectedSchemaName:n,selectedDatamodelId:i,selectedDatabaseName:m,selectedTableName:p,selectedConnectionId:y}=f.useEditorStore.getState(),I=t.sql,U=(b=a==null?void 0:a.getState())==null?void 0:b.settings,V=f.buildSavedEditorCard(t,{isDevMode:o,cardSql:I,isShowingVisual:l,selectedSchemaName:n,selectedDatamodelId:i,selectedDatabaseName:m,selectedTableName:p,selectedConnectionId:y,remoteChartSettings:U,stripConfig:Z}),g=r.cards.map(E=>E.id===t.id?V:E);return{...r,cards:g,activeCardId:X(g,r.activeCardId)}},[a])}}function re(){const{authToken:e,tokenProps:a}=u.useSemaphorContext(),s=u.useQueryClient(),r=u.useAddFrameWithFreshSemanticExecutionPayload(),t=u.useSelectedVisual(),{selectVisual:o}=u.useManagementActions(),{setFrame:l,setCard:n,setIsDevMode:i,initializeModeDrafts:m,setActiveTabCardId:p,updateDataSource:y,setQueryResultColumns:I,setSelectedConnectionId:U,setSelectedDatabaseName:V,setSelectedSchemaName:g,setSelectedTableName:b,setSelectedDatamodelId:E,setFilterValues:P,setInlineFilterValuesMap:M,setApplyFilters:k,clearEditorContext:L}=f.useEditorActions(),{setIsDashboardEditing:v,setIsVisualEditing:T,setSelectedFrameId:j,clearSelectedFrameId:N,setIsDashboardPanelOpen:R}=f.useDashboardActions(),w=f.useDashboardStore(c=>c.selectedSheetId),W=f.useDashboardStore(c=>c.selectedFrameId),$=f.useDashboardStore(c=>c.dashboard),_=f.useDashboardStore(c=>c.filterValues),x=f.useDashboardStore(c=>c.inlineFilterValuesMap),F=u.useVisualById((t==null?void 0:t.id)||"",{enabled:!!(t!=null&&t.id)&&!!(e!=null&&e.accessToken)}),Q=S.useCallback(async c=>{try{o(c),N(),L();const{data:h,fromCache:D}=await B(a.apiServiceUrl,(e==null?void 0:e.accessToken)||"",c.id,s);if(!ee(h,{setFrame:l,setCard:n,setIsDevMode:i,initializeModeDrafts:m,setActiveTabCardId:p,updateDataSource:y,setQueryResultColumns:I,setSelectedConnectionId:U,setSelectedDatabaseName:V,setSelectedSchemaName:g,setSelectedTableName:b,setSelectedDatamodelId:E,setFilterValues:P,setInlineFilterValuesMap:M,setApplyFilters:k,setIsDashboardEditing:v,setIsVisualEditing:T,dashboard:$,selectedSheetId:w,selectedFrameId:W,filterValues:_,inlineFilterValuesMap:x}))throw new Error("Failed to setup editor with visual data");return{success:!0,fromCache:D}}catch(h){return console.error("Error editing visual:",h),{success:!1,error:"Failed to load visual for editing"}}},[e==null?void 0:e.accessToken,a.apiServiceUrl,s,o,l,n,v,T,i,m,p,y,I,U,V,g,b,E,P,M,k,L,N,$,w,W,_,x]),G=S.useCallback(async c=>{var D;const h=d=>(u.ue.error(d),{success:!1,error:d});try{if(o(c),!w)return h("No sheet selected. Please select a sheet first.");const{data:d,fromCache:J}=await B(a.apiServiceUrl,(e==null?void 0:e.accessToken)||"",c.id,s),O=(d==null?void 0:d.frameObject)??((D=d==null?void 0:d.visual)==null?void 0:D.frameObject);if(!O)return h("Visual has no frame data");const C=H(O);if(!(C!=null&&C.cards)||C.cards.length===0)return h("Visual frame is malformed");const q={...u.cloneLinkedFrameWithSourceMapping(C),visualId:c.id};return await r(w,q,"end"),v(!0),j(q.id),R(!1),{success:!0,fromCache:J}}catch(d){return console.error("Error adding visual:",d),h(d instanceof Error?d.message:"Failed to add visual to dashboard")}},[e==null?void 0:e.accessToken,a.apiServiceUrl,s,o,w,v,j,R,r]);return{visual:F.data,isLoading:F.isLoading,isError:F.isError,error:F.error,handleEditLibraryVisual:Q,handleAddLibraryVisual:G,getUpdatedFrame:te().getUpdatedFrame,refetch:F.refetch}}exports.flushPendingEditorDrafts=z;exports.registerPendingEditorDraftFlusher=Y;exports.useVisualUtils=re;
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const o=require("../chunks/index-DYHvr2To.js"),e=require("../chunks/common-types-C73-Ud1-.js");exports.Dashboard=o.Dashboard;exports.CONTROL_CARD_DEFAULT_VALUE=e.CONTROL_CARD_DEFAULT_VALUE;exports.EMPTY_SELECTION=e.EMPTY_SELECTION;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const o=require("../chunks/index-o6tGBWww.js"),e=require("../chunks/common-types-C73-Ud1-.js");exports.Dashboard=o.Dashboard;exports.CONTROL_CARD_DEFAULT_VALUE=e.CONTROL_CARD_DEFAULT_VALUE;exports.EMPTY_SELECTION=e.EMPTY_SELECTION;
@@ -1,4 +1,4 @@
1
- import { D as o } from "../chunks/index-D14U5QOC.js";
1
+ import { D as o } from "../chunks/index-Dh4zmLqk.js";
2
2
  import { C as s, E as C } from "../chunks/common-types-4bjoIgvm.js";
3
3
  export {
4
4
  s as CONTROL_CARD_DEFAULT_VALUE,
@@ -1,3 +1,3 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const M=require("../chunks/source-identity-C-xaeE_I.js"),G=require("../chunks/validators-Cu_w8ZEP.js"),we=require("../chunks/catalog-field-grounding-Du6mKDcF.js"),ae=["lg","md","sm","xs","xxs"],T=10;function _(e){return e&&typeof e=="object"?e:null}function v(e){return typeof e=="string"?e:null}function ie(e){var t,n,r;return!!(e&&typeof e=="object")&&(((t=_(e))==null?void 0:t.kind)==="semantic"||((n=_(e))==null?void 0:n.kind)==="physical"||((r=_(e))==null?void 0:r.kind)==="sql")}function N(e){return ie(e)?e.kind==="semantic"?!!(e.domainId&&e.datasetName):e.kind==="physical"?!!(e.connectionId&&e.tableName):!1:!1}function ve(e){return M.semaphorSourceIdentityKey(e)}function K(e,t){return M.semaphorSourcesReferToSameDataset(e,t)}function oe(e,t){return M.preferSemaphorSourceMetadata(e,t)}function $(e){const t=[];for(const n of e){const r=t.findIndex(a=>K(a,n));r===-1?t.push(n):t[r]=oe(t[r],n)}return t}function De(e){return $(e)[0]}function H(e,t){return e.kind!=="semantic"||e.connectionId||(t==null?void 0:t.kind)!=="semantic"||!M.semaphorSourcesReferToSameDataset(e,t)||!t.connectionId?e:{...e,connectionId:t.connectionId}}function W(e){return N(e)?e:void 0}function re(e,t){if(!(e.kind!=="semantic"||e.connectionId))return t.find(n=>(n==null?void 0:n.kind)==="semantic"&&M.semaphorSourcesReferToSameDataset(e,n)&&!!n.connectionId)}function w(e,t){const n=W(e==null?void 0:e.source);return n?H(n,t):void 0}function se({explicitSource:e,field:t,defaultSource:n,fallbackSources:r}){const a=[n,...r||[]],i=W(e),o=i?H(i,re(i,a)):void 0;if(o)return o;if(e!==void 0)return;const d=w(t,n),s=d?H(d,re(d,a)):void 0;if(s)return s;if((t==null?void 0:t.source)===void 0)return W(n)}function Ae(e,t){if(!(e!=null&&e.name)||!(t!=null&&t.name)||e.name!==t.name)return!1;const n=w(e),r=w(t);return!n||!r?!0:K(n,r)}function A(e){var t;return v((t=_(e))==null?void 0:t.kind)}function de(e){var t,n;return A(e)!=="semantic"?null:((n=v((t=_(e))==null?void 0:t.domainId))==null?void 0:n.trim())||null}function Ce(e){var t;return A(e)!=="semantic"?null:v((t=_(e))==null?void 0:t.datasetName)}function ke(e){var t;return A(e)!=="semantic"?null:v((t=_(e))==null?void 0:t.datasetId)}function xe(e){var t;return A(e)!=="physical"?null:v((t=_(e))==null?void 0:t.connectionId)}function Fe(e){var t;return A(e)!=="physical"?null:v((t=_(e))==null?void 0:t.tableName)}function Te(e){var t;return A(e)!=="physical"?"":v((t=_(e))==null?void 0:t.databaseName)||""}function $e(e){var t;return A(e)!=="physical"?"":v((t=_(e))==null?void 0:t.schemaName)||""}function ce(e){if(e.analyticsIntent&&typeof e.analyticsIntent=="object"&&"source"in e.analyticsIntent)return e.analyticsIntent.source}function le({datasets:e,requireAtLeastOne:t}){if(t&&e.length<1)return{ok:!1,issue:"invalid_dataset_count"};if(e.length<=1)return{ok:!0};const n=e.map(de),r=new Set(n.filter(Boolean));return n.some(a=>!a)||r.size!==1?{ok:!1,issue:"invalid_multi_dataset_scope"}:{ok:!0}}function z(e,t){if(!t)return!1;if(t.kind==="semantic"){const n=ke(e);return de(e)===t.domainId?n&&t.datasetId?n===t.datasetId:Ce(e)===t.datasetName:!1}return t.kind==="physical"?xe(e)===t.connectionId&&Fe(e)===t.tableName&&Te(e)===(t.databaseName||"")&&$e(e)===(t.schemaName||""):!1}function Me(e,t){return e.find(n=>z(n,t))}function f(e,t,n){return n?{code:e,message:t,cardId:n}:{code:e,message:t}}function B(e){const t=new Set;for(const n of e){if(t.has(n))return n;t.add(n)}return null}function ue({card:e,datasets:t,errors:n}){if(e.type==="text")return;const r=ce(e);if(!r){if(t.length<=1)return;n.push(f("missing_card_analytics_source","Multi-dataset dashboard cards must include analytics intent with a source so the materializer can choose the correct dataset.",e.id));return}t.some(a=>z(a,r))||n.push(f("invalid_card_analytics_source","Dashboard cards with an explicit analytics source must use one of the selected datasets.",e.id))}function V(e){return e.map(t=>t==null?void 0:t.source).filter(t=>!!t)}function L(e){return Array.isArray(e)?e.filter(t=>!!(t&&typeof t=="object")):[]}function Ne(e){return Array.isArray(e)?e.filter(t=>!!(t&&typeof t=="object")):[]}function Pe(e){var n;if(!e)return[];const t=[e.source];return e.kind==="metric"?t.push(...V([...L(e.metrics),e.primaryMetric,e.dateField,...L(e.dimensions),...Ne(e.filters).map(r=>r.field)])):e.kind==="records"?t.push(...V([...L(e.fields),e.dateField,(n=e.orderBy)==null?void 0:n.field])):e.kind==="inputOptions"?t.push(...V([e.field])):e.kind==="sql"&&t.push(...V(e.fields||[])),t}function fe({card:e,datasets:t,errors:n}){if(e.type!=="text"){for(const r of Pe(e.analyticsIntent))if(r&&!t.some(a=>z(a,r))){n.push(f("invalid_card_query_source","Dashboard card query field references must use one of the selected datasets.",e.id));return}}}function pe({card:e,errors:t}){if(e.type==="text"||!e.analyticsIntent)return;const n=G.validateSemaphorAnalyticsIntent(e.analyticsIntent);if(!n.ok)for(const r of n.errors)t.push(f(r.code,r.path?`${r.path}: ${r.message}`:r.message,e.id))}function he({datasets:e,errors:t,requireAtLeastOne:n}){const r=le({datasets:e,requireAtLeastOne:n});if(!r.ok){if(r.issue==="invalid_dataset_count"){t.push(f("invalid_dataset_count","Dashboard authoring requires at least one selected dataset."));return}t.push(f("invalid_multi_dataset_scope","Multi-dataset dashboard authoring is limited to semantic datasets from one domain."))}}function me(e){var p,S;const t=[];if(!e||typeof e!="object")return{ok:!1,errors:[f("invalid_plan","Dashboard plan must be a structured object.")],warnings:[]};const n=e,r=[...n.warnings||[]];n.version!==1&&t.push(f("invalid_version","Dashboard plan version must be 1.")),(p=n.title)!=null&&p.trim()||t.push(f("missing_title","Dashboard plan needs a title."));const a=Array.isArray(n.datasets)?n.datasets:[],i=Array.isArray(n.sheets)?n.sheets:[];he({datasets:a,errors:t,requireAtLeastOne:!0}),i.length!==1&&t.push(f("invalid_sheet_count","MVP dashboard authoring creates exactly one dashboard sheet."));const o=i[0];o&&o.kind!=="dashboard"&&t.push(f("invalid_sheet_kind",'Generated sheet must use kind "dashboard".'));const d=(o==null?void 0:o.cards)||[];d.length>T&&t.push(f("too_many_cards",`Generated dashboards can contain at most ${T} cards.`));const s=B(d.map(l=>l.id));s&&t.push(f("duplicate_card_id",`Duplicate generated card id: ${s}.`));const u=B(d.map(l=>l.frameId));u&&t.push(f("duplicate_frame_id",`Duplicate generated frame id: ${u}.`));for(const l of d)(S=l.title)!=null&&S.trim()||t.push(f("missing_card_title","Card title is required.",l.id)),l.type==="custom"&&t.push(f("custom_visual_out_of_scope","Whole-dashboard authoring supports built-in visual types only.",l.id)),l.type!=="text"&&!l.analyticsIntent&&r.push(f("missing_analytics_intent","Non-text card has no analytics intent and may be skipped by the app layer.",l.id)),ue({card:l,datasets:a,errors:t}),pe({card:l,errors:t}),fe({card:l,datasets:a,errors:t});const h=Array.isArray(n.filterInputs)?n.filterInputs:[],b=h.map(l=>l.id),y=B(b);y&&t.push(f("duplicate_input_id",`Duplicate dashboard input id: ${y}.`));const c=h.map(l=>l.variableName).filter(Boolean)||[],g=B(c);g&&t.push(f("duplicate_input_variable",`Duplicate dashboard input variable name: ${g}.`));const D=Array.isArray(n.calculatedFields)?n.calculatedFields:[];for(const l of D)l.scope==="domain"&&l.reuseOnly!==!0&&t.push(f("domain_calculated_field_create_out_of_scope",`Creating domain calculated field "${l.name}" is outside MVP.`));return{ok:t.length===0,errors:t,warnings:r}}function ge(e){var o;const t=[];if(!e||typeof e!="object")return{ok:!1,errors:[f("invalid_change_plan","Dashboard change plan must be a structured object.")],warnings:[]};const n=e,r=[...n.warnings||[]];n.version!==1&&t.push(f("invalid_version","Dashboard change plan version must be 1.")),(o=n.dashboardId)!=null&&o.trim()||t.push(f("missing_dashboard_id","Dashboard change plan needs a dashboard id."));const a=Array.isArray(n.datasets)?n.datasets:[],i=Array.isArray(n.operations)?n.operations:[];he({datasets:a,errors:t,requireAtLeastOne:!1});for(const d of i){if(d.kind==="unsupported"){r.push(f("unsupported_operation",d.reason||d.requestedAction));continue}d.kind==="addCard"&&d.card.type==="custom"&&t.push(f("custom_visual_out_of_scope","Whole-dashboard authoring supports built-in visual types only.",d.card.id)),d.kind==="addCard"&&(ue({card:d.card,datasets:a,errors:t}),pe({card:d.card,errors:t}),fe({card:d.card,datasets:a,errors:t})),d.kind==="addCalculatedField"&&d.field.scope==="domain"&&d.field.reuseOnly!==!0&&t.push(f("domain_calculated_field_create_out_of_scope",`Creating domain calculated field "${d.field.name}" is outside MVP.`))}return{ok:t.length===0,errors:t,warnings:r}}const Re={lg:48,md:36,sm:24,xs:12,xxs:6};function Be(e,t){let n=0,r=0,a=0;return e.map(i=>{const o=Math.min(i.w,t);n>0&&n+o>t&&(n=0,r+=a,a=0);const d={i:i.frameId,x:n,y:r,w:o,h:i.h,minW:Math.min(i.minW,t),minH:i.minH,static:!1};return n+=o,a=Math.max(a,i.h),d})}function Ve(e){const t=[...e].sort((s,u)=>s.priority-u.priority),n=t.filter(s=>s.role==="kpi"),r=t.filter(s=>s.role==="chart"),a=t.filter(s=>s.role==="table"),i=t.filter(s=>s.role==="text"),o=i.slice(0,1),d=i.slice(o.length);return{kpis:n,introText:o,charts:r,tables:a,supportingText:d}}function ze(e,t,n){return t==="xxs"||t==="xs"?n:t==="sm"?Math.min(12,n):t==="md"?e<=1||e===2?18:12:e<=1||e===2?24:e===3?16:12}function Oe(e,t,n,r){return n==="xxs"||n==="xs"||n==="sm"||n==="md"||t===1||t%2===1&&e===0?r:r/2}function qe(e){const{item:t,band:n,index:r,bandCount:a,breakpoint:i,columns:o}=e;return n==="kpi"?{...t,band:n,w:ze(a,i,o),h:15,minW:Math.min(6,o),minH:12}:n==="table"?{...t,band:n,w:o,h:i==="xxs"||i==="xs"?34:38,minW:Math.min(12,o),minH:18}:n==="introText"?{...t,band:n,w:o,h:i==="xxs"||i==="xs"?12:10,minW:Math.min(12,o),minH:8}:n==="supportingText"?{...t,band:n,w:i==="lg"?o/2:o,h:i==="xxs"||i==="xs"?12:10,minW:Math.min(12,o),minH:8}:{...t,band:n,w:Oe(r,a,i,o),h:i==="xxs"||i==="xs"?28:30,minW:Math.min(12,o),minH:16}}function k(e,t,n,r){return e.map((a,i)=>qe({item:a,band:t,index:i,bandCount:e.length,breakpoint:n,columns:r}))}function O(e){const t=Ve(e);return Object.fromEntries(ae.map(n=>{const r=Re[n],a=[...k(t.introText,"introText",n,r),...k(t.kpis,"kpi",n,r),...k(t.charts,"chart",n,r),...k(t.tables,"table",n,r),...k(t.supportingText,"supportingText",n,r)];return[n,Be(a,r)]}))}function Le(e){const t=we.normalizeAnalyticsCatalogDataType(e);return t==="datetime"?"date":t==="unknown"?"string":t}function je(e){return!!(e&&typeof e=="object"&&!Array.isArray(e))}function Ee(e){return je(e)&&typeof e.filterId=="string"&&typeof e.operation=="string"&&Array.isArray(e.values)}function He(e){return e.filter(t=>typeof t=="string"||typeof t=="number")}function We(e){return e.filter(t=>t instanceof Date||typeof t=="string")}function U(e,t){if(t===void 0)return;const n=Le(e.dataType),r=e.operation||"in";if(Ee(t))return{...t,filterId:e.id,name:t.name||e.column,valueType:n,dataType:e.dataType,fieldMeta:e.fieldMeta,semanticContext:e.semanticContext};if(r==="is null"||r==="is not null")return{filterId:e.id,name:e.column,operation:r,valueType:n,values:[],dataType:e.dataType,fieldMeta:e.fieldMeta,semanticContext:e.semanticContext};const a=Array.isArray(t)?t:[t],i=n==="date"?We(a):He(a);if(i.length!==0&&!((r==="between"||r==="not between")&&i.length<2))return{filterId:e.id,name:e.column,operation:r,valueType:n,values:i,dataType:e.dataType,fieldMeta:e.fieldMeta,semanticContext:e.semanticContext}}function Ge(e,t,n){return n?{code:e,message:t,cardId:n}:{code:e,message:t}}function Ke(e,t,n){const r=(t||[]).filter(a=>a.scope==="card"&&a.targetCardId===n).map(a=>a.field).filter(Boolean);return r.length===0?e:{...e,calculatedFields:[...e.calculatedFields||[],...r]}}function Ue(e){const t={};return{inputs:(e.filterInputs||[]).map((r,a)=>{const i=U(r.filter,r.defaultValue);return i&&(t.shared??(t.shared={}),t.shared[r.id]={status:"set",value:{kind:"filter",filterValue:i}}),{id:r.id,kind:"filter",label:r.label,variableName:r.variableName,scope:r.scope||{kind:"allSheets",sheetKinds:["dashboard"]},runtimeScope:"shared",presentation:{placement:"toolbar",order:a},exports:["label","value","start","end","range"],filter:r.filter}}),defaultInputValues:t.shared&&Object.keys(t.shared).length>0?t:void 0}}function Xe(e){var b,y;const t=me(e.plan);if(!t.ok)throw new Error(t.errors.map(c=>c.message).join(`
2
- `)||"Dashboard plan is invalid.");const n=e.plan.sheets[0],r=[...t.warnings],a=[],i=new Map(e.cardArtifacts.map(c=>[c.planCardId,c])),o=[];for(const c of n.cards){const g=i.get(c.id);if(!g){const p=Ge("missing_card_artifact",`Card "${c.title}" was skipped because no generated artifact was supplied.`,c.id);a.push(p);continue}r.push(...g.warnings||[]);const D=Ke(g.card,e.plan.calculatedFields,c.id);o.push({id:c.frameId,cards:[D],activeCardId:D.id})}if(o.length===0)throw new Error("Dashboard plan did not produce any persistable cards.");const{inputs:d,defaultInputValues:s}=Ue(e.plan),u=O(n.cards.filter(c=>o.some(g=>g.id===c.frameId)).map(c=>({frameId:c.frameId,priority:c.priority,role:c.role})));return{dashboard:{id:e.dashboardId,title:e.plan.title,description:e.plan.description||"",sheets:[{id:n.id,kind:"dashboard",title:n.title,description:n.description,frames:o,layouts:u,calculatedFields:(b=e.plan.calculatedFields)==null?void 0:b.filter(c=>c.scope==="sheet"&&c.field).map(c=>c.field)}],calculatedFields:(y=e.plan.calculatedFields)==null?void 0:y.filter(c=>c.scope==="dashboard"&&c.field).map(c=>c.field),inputs:d,...s?{defaultInputValues:s}:{}},warnings:r,skippedOperations:a}}function C(e,t,n){return n?{code:e,message:t,cardId:n}:{code:e,message:t}}function Je(e){return JSON.parse(JSON.stringify(e))}function Qe(e){var t;return(t=e.sheets)==null?void 0:t.find(n=>(n.kind||"dashboard")==="dashboard")}function j(e,t){var n;for(const r of e.sheets||[])for(const a of r.frames||[]){const i=(n=a.cards)==null?void 0:n.find(o=>o.id===t);if(i)return{sheet:r,frame:a,card:i}}return null}function be(e){var n,r;const t=(r=(n=e.cards)==null?void 0:n[0])==null?void 0:r.type;return t==="kpi"?"kpi":t==="table"||t==="detailTable"||t==="pivotTable"?"table":t==="text"?"text":"chart"}function Ye(e){var t;return new Map((((t=e.layouts)==null?void 0:t.lg)||[]).map((n,r)=>[n.i,r]))}function Ie(e,t=new Map){const n=Ye(e),r=Math.max(n.size,t.size),a=(e.frames||[]).map((i,o)=>({frameId:i.id,role:be(i),priority:t.get(i.id)??n.get(i.id)??r+o}));e.layouts=O(a)}function Ze(e){return Object.values(e.layouts||{}).some(t=>t.length>0)}function et(e,t){if(!Ze(e)){Ie(e);return}const n=O([{frameId:t.id,role:be(t),priority:0}]);e.layouts??(e.layouts={});for(const[r,a]of Object.entries(n)){const i=e.layouts[r]||[];if(i.some(s=>s.i===t.id))continue;const o=a[0];if(!o)continue;const d=i.reduce((s,u)=>Math.max(s,u.y+u.h),0);e.layouts[r]=[...i,{...o,y:d}]}}function tt(e,t){var r;const n=U(t.filter,t.defaultValue);n&&(e.defaultInputValues??(e.defaultInputValues={}),(r=e.defaultInputValues).shared??(r.shared={}),e.defaultInputValues.shared[t.id]={status:"set",value:{kind:"filter",filterValue:n}})}function nt(e){var d;const t=ge(e.changePlan);if(!t.ok)throw new Error(t.errors.map(s=>s.message).join(`
3
- `)||"Dashboard change plan is invalid.");const n=Je(e.dashboard),r=[...t.warnings],a=[],i=new Map(e.cardArtifacts.map(s=>[s.planCardId,s])),o=Qe(n);if(!o)throw new Error("Dashboard has no editable dashboard sheet.");o.frames??(o.frames=[]);for(const s of e.changePlan.operations)switch(s.kind){case"addCard":{if((o.frames||[]).reduce((y,c)=>{var g;return y+(((g=c.cards)==null?void 0:g.length)||0)},0)>=T){a.push(C("generated_card_limit_reached",`MVP AI refinement is capped at ${T} cards.`,s.card.id));break}const h=i.get(s.card.id);if(!h){a.push(C("missing_card_artifact",`Card "${s.card.title}" was skipped because no generated artifact was supplied.`,s.card.id));break}const b={id:s.card.frameId,cards:[h.card],activeCardId:h.card.id};o.frames.push(b),et(o,b);break}case"addFilterInput":{n.inputs??(n.inputs=[]);const u={id:s.input.id,kind:"filter",label:s.input.label,variableName:s.input.variableName,scope:s.input.scope||{kind:"allSheets",sheetKinds:["dashboard"]},runtimeScope:"shared",presentation:{placement:"toolbar",order:n.inputs.length},exports:["label","value","start","end","range"],filter:s.input.filter};n.inputs.push(u),tt(n,s.input);break}case"addCalculatedField":{if(s.field.scope==="dashboard"&&s.field.field)n.calculatedFields??(n.calculatedFields=[]),n.calculatedFields.push(s.field.field);else if(s.field.scope==="sheet"&&s.field.field)o.calculatedFields??(o.calculatedFields=[]),o.calculatedFields.push(s.field.field);else if(s.field.scope==="card"&&s.field.field){const u=s.field.targetCardId?j(n,s.field.targetCardId):null;u?((d=u.card).calculatedFields??(d.calculatedFields=[]),u.card.calculatedFields.push(s.field.field)):a.push(C("missing_calculated_field_target",`Calculated field "${s.field.name}" needs a valid target card.`))}break}case"renameCard":{const u=j(n,s.cardId);if(!u){a.push(C("card_not_found",`Card "${s.cardId}" could not be renamed because it was not found.`,s.cardId));break}u.card.title=s.title,s.description!==void 0&&(u.card.description=s.description);break}case"reorderCards":{const u=new Map;for(let h=0;h<s.cardIds.length;h+=1){const b=s.cardIds[h],y=j(n,b);y&&u.set(y.frame.id,h)}Ie(o,u);break}case"reuseCalculatedField":r.push(C("reused_calculated_field",`Calculated field "${s.fieldId}" is reused by reference.`));break;case"unsupported":a.push(C("unsupported_operation",s.reason||s.requestedAction));break}return{dashboard:n,warnings:r,skippedOperations:a}}function I(e,t,n){return n?{code:e,message:t,cardId:n}:{code:e,message:t}}function F(e,t){return e.trim().toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-+|-+$/g,"")||t}function ye(e,t){if(!t.has(e))return t.add(e),e;let n=2,r=`${e}-${n}`;for(;t.has(r);)n+=1,r=`${e}-${n}`;return t.add(r),r}function P(e){return!!(e&&typeof e=="object")}function _e(e){return Array.isArray(e.inputs)?e.inputs.filter(t=>P(t)&&typeof t.id=="string"):[]}function X(e){return Array.isArray(e.sections)?e.sections.filter(t=>P(t)):[]}function J(e){return Array.isArray(e.views)?e.views.filter(t=>P(t)):[]}function x(e){if(!Array.isArray(e))return[];const t=[];for(const n of e){const r=w(n);r&&t.push(r)}return t}function rt(e){var r;if(!e)return[];const t=[];if(N(e.source)&&t.push(e.source),e.kind==="metric"){t.push(...x(e.metrics));const a=w(e.dateField);a&&t.push(a),t.push(...x(e.dimensions)),t.push(...x((r=e.filters)==null?void 0:r.map(i=>i.field)))}else if(e.kind==="records"){const a=w(e.dateField);a&&t.push(a),t.push(...x(e.fields))}else if(e.kind==="inputOptions"){const a=w(e.field);a&&t.push(a)}else e.kind==="sql"&&t.push(...x(e.fields));const n="inputs"in e&&Array.isArray(e.inputs)?e.inputs:[];for(const a of n){const i=w(a.field);i&&t.push(i)}return t}function at(e){const t=[];for(const n of _e(e)){const r=w(n.field);r&&t.push(r)}for(const n of X(e))for(const r of J(n))t.push(...rt(r.analytics));return t}function it(e){var n;const t=[];for(const r of X(e))for(const a of J(r))N((n=a.analytics)==null?void 0:n.source)&&t.push(a.analytics.source);return t}function ot(e,t){const n=$(e).filter(N);if(n.length===0)return t.push(I("missing_materializable_dataset","No semantic or physical source could be converted into the current dashboard authoring dataset reference.")),[];const r=n.every(i=>i.kind==="semantic"),a=Array.from(new Set(n.filter(i=>i.kind==="semantic").map(i=>i.domainId)));return n.length>1&&(!r||a.length!==1)?(t.push(I("multiple_datasets_out_of_scope","The dashboard authoring compiler supports multiple datasets only within one semantic domain; using the first source and deferring the rest.")),[n[0]]):n}function st(e,t){const n=X(e),r=_e(e),a=$(at(e)),i=$(it(e));return{sections:n,inputs:r,sources:a,primarySources:i,defaultSource:i.length===1?i[0]:void 0,datasets:ot(a,t)}}function dt(e){return e&&G.validateSemaphorAnalyticsIntent(e).ok?e:void 0}function ct(e){var t;switch((t=e.presentation)==null?void 0:t.kind){case"kpi":return"kpi";case"lineChart":return"line";case"barChart":return"bar";case"areaChart":return"area";case"table":return"table";case"text":return"text";default:return null}}function lt(e){var t,n,r;return((t=e.presentation)==null?void 0:t.kind)==="kpi"?"kpi":((n=e.presentation)==null?void 0:n.kind)==="table"?"table":((r=e.presentation)==null?void 0:r.kind)==="text"?"text":"chart"}function ut(e){switch(e){case"not_in":return"not in";case"not_between":return"not between";case"contains":return"like";default:return e||"in"}}function ft(e){return P(e.field)?e.field.dataType==="datetime"?"date":e.field.dataType||"string":"string"}function pt(e){if(!(!e||e.kind!=="physical"))return[e.databaseName,e.schemaName,e.tableName].filter(Boolean).join(".")}function ht(e,t,n,r,a,i){if(e.kind!=="filter")return i.push(I("control_inputs_deferred",`Control input "${e.label}" is represented in the protocol but not yet materialized by the dashboard authoring adapter.`)),null;if(!P(e.field)||typeof e.field.name!="string")return i.push(I("filter_requires_field",`Filter "${e.label||e.id}" needs a field before the dashboard compiler can materialize it.`)),null;const o=se({explicitSource:void 0,field:e.field,defaultSource:t,fallbackSources:n}),d=(o==null?void 0:o.kind)==="semantic"||(o==null?void 0:o.kind)==="physical"?o.connectionId:void 0;if(!d)return i.push(I("filter_requires_connection_id",`Filter "${e.label}" needs a source connectionId before the dashboard compiler can materialize it.`)),null;const h={id:`filter-${ye(F(e.id,e.field.name),a)}`,variableName:e.id,connectionId:d,title:e.label,column:e.field.name,dataType:ft(e),qualifiedTableName:pt(o),sql:"",operation:ut(e.operator),type:e.multi===!1?"single":"multiple",location:"dashboard",displayMode:"toolbar",fieldMeta:(o==null?void 0:o.kind)==="semantic"?{name:e.field.name,qualifiedFieldName:e.field.name,dataType:e.field.dataType,role:e.field.role==="measure"?"metric":"groupby"}:void 0,semanticContext:(o==null?void 0:o.kind)==="semantic"?{semanticDomainId:o.domainId,connectionId:o.connectionId}:void 0};return{id:e.id,label:e.label,variableName:e.id,scope:r,filter:h,defaultValue:U(h,e.defaultValue)}}function E(e){const t=[],n=[];for(const r of e.viewIds){const a=e.viewIdToCardId.get(r);a?t.push(a):n.push(r)}return n.length>0&&e.warnings.push(I("input_scope_view_not_found",`Filter "${e.inputLabel}" referenced unknown view ids: ${n.join(", ")}.`)),Array.from(new Set(t))}function mt(e){var r,a;if(!e.protocolScope){const i=Array.from(new Set(e.boundCardIds));return i.length>0&&i.length<e.allCardIds.length?{kind:"cards",cardIds:i}:void 0}if(e.protocolScope.level==="dashboard"){if(!((r=e.protocolScope.excludeViewIds)!=null&&r.length))return;const i=new Set(E({inputLabel:e.inputLabel,viewIds:e.protocolScope.excludeViewIds,viewIdToCardId:e.viewIdToCardId,warnings:e.warnings}));return{kind:"cards",cardIds:e.allCardIds.filter(o=>!i.has(o))}}if(e.protocolScope.level==="view"){const i=E({inputLabel:e.inputLabel,viewIds:e.protocolScope.viewIds,viewIdToCardId:e.viewIdToCardId,warnings:e.warnings});return i.length===0?(e.warnings.push(I("input_scope_has_no_materialized_cards",`Filter "${e.inputLabel}" was deferred because its view scope does not match any materialized cards.`)),null):{kind:"cards",cardIds:i}}const t=e.sectionIdToCardIds.get(e.protocolScope.sectionId)||[];if(t.length===0)return e.warnings.push(I("input_scope_section_not_found",`Filter "${e.inputLabel}" was deferred because section "${e.protocolScope.sectionId}" does not match any materialized cards.`)),null;if(!((a=e.protocolScope.excludeViewIds)!=null&&a.length))return{kind:"cards",cardIds:t};const n=new Set(E({inputLabel:e.inputLabel,viewIds:e.protocolScope.excludeViewIds,viewIdToCardId:e.viewIdToCardId,warnings:e.warnings}));return{kind:"cards",cardIds:t.filter(i=>!n.has(i))}}function gt(e){var c,g,D;const t=[],n=G.validateSemaphorDashboardIntent(e);for(const p of n.warnings)t.push(I(p.code,p.message));for(const p of n.errors)t.push(I(p.code,p.message));const r=st(e,t),a=[],i=new Map,o=new Map,d=new Map,s=new Set,u=new Set;let h=0;for(const[p,S]of r.sections.entries()){const l=typeof S.title=="string"?S.title:`Section ${p+1}`,Q=S.id||F(l,`section-${p+1}`);o.set(Q,[]);for(const[Y,m]of J(S).entries()){const Z=ct(m),q=F(m.id||`${l}-${m.title||`View ${Y+1}`}`,`card-${p+1}-${Y+1}`);if(!Z){t.push(I("unsupported_presentation",`Dashboard presentation "${((c=m.presentation)==null?void 0:c.kind)||"unknown"}" is not supported by the dashboard authoring adapter.`,`card-${q}`));continue}if(((g=m.analytics)==null?void 0:g.kind)==="sql"){t.push(I("sql_intent_deferred","SQL analytics intent is valid protocol, but the current dashboard authoring adapter only materializes semantic and physical config-card intents.",`card-${q}`));continue}const ee=ye(q,s),R=`card-${ee}`;m.id&&i.set(m.id,R),(D=o.get(Q))==null||D.push(R);const Se=m.analytics&&"inputs"in m.analytics?m.analytics.inputs:void 0;for(const te of Se||[]){const ne=d.get(te.inputId)||[];ne.push(R),d.set(te.inputId,ne)}a.push({id:R,frameId:`frame-${ee}`,title:m.title,description:m.description,type:Z,role:lt(m),priority:h,section:l,analyticsIntent:dt(m.analytics),text:m.text}),h+=1}}const b=r.inputs.map(p=>{const S=mt({protocolScope:p.scope,inputLabel:p.label,allCardIds:a.map(l=>l.id),boundCardIds:d.get(p.id)||[],viewIdToCardId:i,sectionIdToCardIds:o,warnings:t});return S===null?null:ht(p,r.defaultSource,r.sources,S,u,t)}).filter(p=>!!p);return{plan:{version:1,id:`plan-${F(e.title,"dashboard")}`,title:e.title,description:e.description,datasets:r.datasets,sheets:[{id:`sheet-${F(e.title,"dashboard")}`,title:e.title,description:e.description,kind:"dashboard",cards:a}],filterInputs:b.length?b:void 0,warnings:t.length?t:void 0,unresolvedRequests:n.ok?void 0:n.errors.map(p=>p.message)},warnings:t}}exports.DASHBOARD_AUTHORING_BREAKPOINTS=ae;exports.DASHBOARD_AUTHORING_MAX_GENERATED_CARDS=T;exports.applyDashboardChangePlan=nt;exports.compileDashboardFromPlan=Xe;exports.compileResponsiveDashboardLayouts=O;exports.dashboardAuthoringDatasetMatchesSource=z;exports.dashboardAuthoringFieldsReferToSameTarget=Ae;exports.dashboardAuthoringSourceFromField=w;exports.dashboardAuthoringSourceKey=ve;exports.dashboardAuthoringSourcesReferToSameDataset=K;exports.dashboardPlanFromSemaphorDashboardIntent=gt;exports.findDashboardAuthoringDatasetForSource=Me;exports.getDashboardAuthoringCardSource=ce;exports.isMaterializableDashboardAuthoringSource=N;exports.isSemaphorSourceRef=ie;exports.mergeDashboardAuthoringSources=$;exports.preferDashboardAuthoringSourceMetadata=oe;exports.preferredDashboardAuthoringSource=De;exports.resolveDashboardAuthoringSource=se;exports.validateDashboardAuthoringDatasetScope=le;exports.validateDashboardChangePlan=ge;exports.validateDashboardPlan=me;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const v=require("../chunks/contracts-CtB2VONT.js"),N=require("../chunks/source-identity-C-xaeE_I.js"),U=require("../chunks/validators-Cu_w8ZEP.js"),we=require("../chunks/catalog-field-grounding-Du6mKDcF.js");function _(e){return e&&typeof e=="object"?e:null}function D(e){return typeof e=="string"?e:null}function ie(e){var t,r,n;return!!(e&&typeof e=="object")&&(((t=_(e))==null?void 0:t.kind)==="semantic"||((r=_(e))==null?void 0:r.kind)==="physical"||((n=_(e))==null?void 0:n.kind)==="sql")}function M(e){return ie(e)?e.kind==="semantic"?!!(e.domainId&&e.datasetName):e.kind==="physical"?!!(e.connectionId&&e.tableName):!1:!1}function De(e){return N.semaphorSourceIdentityKey(e)}function K(e,t){return N.semaphorSourcesReferToSameDataset(e,t)}function oe(e,t){return N.preferSemaphorSourceMetadata(e,t)}function R(e){const t=[];for(const r of e){const n=t.findIndex(i=>K(i,r));n===-1?t.push(r):t[n]=oe(t[n],r)}return t}function ve(e){return R(e)[0]}function j(e,t){return e.kind!=="semantic"||e.connectionId||(t==null?void 0:t.kind)!=="semantic"||!N.semaphorSourcesReferToSameDataset(e,t)||!t.connectionId?e:{...e,connectionId:t.connectionId}}function G(e){return M(e)?e:void 0}function ae(e,t){if(!(e.kind!=="semantic"||e.connectionId))return t.find(r=>(r==null?void 0:r.kind)==="semantic"&&N.semaphorSourcesReferToSameDataset(e,r)&&!!r.connectionId)}function S(e,t){const r=G(e==null?void 0:e.source);return r?j(r,t):void 0}function se({explicitSource:e,field:t,defaultSource:r,fallbackSources:n}){const i=[r,...n||[]],a=G(e),o=a?j(a,ae(a,i)):void 0;if(o)return o;if(e!==void 0)return;const d=S(t,r),s=d?j(d,ae(d,i)):void 0;if(s)return s;if((t==null?void 0:t.source)===void 0)return G(r)}function Ce(e,t){if(!(e!=null&&e.name)||!(t!=null&&t.name)||e.name!==t.name)return!1;const r=S(e),n=S(t);return!r||!n?!0:K(r,n)}function C(e){var t;return D((t=_(e))==null?void 0:t.kind)}function de(e){var t,r;return C(e)!=="semantic"?null:((r=D((t=_(e))==null?void 0:t.domainId))==null?void 0:r.trim())||null}function ke(e){var t;return C(e)!=="semantic"?null:D((t=_(e))==null?void 0:t.datasetName)}function xe(e){var t;return C(e)!=="semantic"?null:D((t=_(e))==null?void 0:t.datasetId)}function Te(e){var t;return C(e)!=="physical"?null:D((t=_(e))==null?void 0:t.connectionId)}function Fe(e){var t;return C(e)!=="physical"?null:D((t=_(e))==null?void 0:t.tableName)}function Re(e){var t;return C(e)!=="physical"?"":D((t=_(e))==null?void 0:t.databaseName)||""}function Ne(e){var t;return C(e)!=="physical"?"":D((t=_(e))==null?void 0:t.schemaName)||""}function ce(e){if(e.analyticsIntent&&typeof e.analyticsIntent=="object"&&"source"in e.analyticsIntent)return e.analyticsIntent.source}function le({datasets:e,requireAtLeastOne:t}){if(t&&e.length<1)return{ok:!1,issue:"invalid_dataset_count"};if(e.length<=1)return{ok:!0};const r=e.map(de),n=new Set(r.filter(Boolean));return r.some(i=>!i)||n.size!==1?{ok:!1,issue:"invalid_multi_dataset_scope"}:{ok:!0}}function E(e,t){if(!t)return!1;if(t.kind==="semantic"){const r=xe(e);return de(e)===t.domainId?r&&t.datasetId?r===t.datasetId:ke(e)===t.datasetName:!1}return t.kind==="physical"?Te(e)===t.connectionId&&Fe(e)===t.tableName&&Re(e)===(t.databaseName||"")&&Ne(e)===(t.schemaName||""):!1}function Me(e,t){return e.find(r=>E(r,t))}function p(e,t,r){return r?{code:e,message:t,cardId:r}:{code:e,message:t}}function O(e){const t=new Set;for(const r of e){if(t.has(r))return r;t.add(r)}return null}function ue({card:e,datasets:t,errors:r}){if(e.type==="text")return;const n=ce(e);if(!n){if(t.length<=1)return;r.push(p("missing_card_analytics_source","Multi-dataset dashboard cards must include analytics intent with a source so the materializer can choose the correct dataset.",e.id));return}t.some(i=>E(i,n))||r.push(p("invalid_card_analytics_source","Dashboard cards with an explicit analytics source must use one of the selected datasets.",e.id))}function P(e){return e.map(t=>t==null?void 0:t.source).filter(t=>!!t)}function V(e){return Array.isArray(e)?e.filter(t=>!!(t&&typeof t=="object")):[]}function $e(e){return Array.isArray(e)?e.filter(t=>!!(t&&typeof t=="object")):[]}function Be(e){var r;if(!e)return[];const t=[e.source];return e.kind==="metric"?t.push(...P([...V(e.metrics),e.primaryMetric,e.dateField,...V(e.dimensions),...$e(e.filters).map(n=>n.field)])):e.kind==="records"?t.push(...P([...V(e.fields),e.dateField,(r=e.orderBy)==null?void 0:r.field])):e.kind==="inputOptions"?t.push(...P([e.field])):e.kind==="sql"&&t.push(...P(e.fields||[])),t}function fe({card:e,datasets:t,errors:r}){if(e.type!=="text"){for(const n of Be(e.analyticsIntent))if(n&&!t.some(i=>E(i,n))){r.push(p("invalid_card_query_source","Dashboard card query field references must use one of the selected datasets.",e.id));return}}}function pe({card:e,errors:t}){if(e.type==="text"||!e.analyticsIntent)return;const r=U.validateSemaphorAnalyticsIntent(e.analyticsIntent);if(!r.ok)for(const n of r.errors)t.push(p(n.code,n.path?`${n.path}: ${n.message}`:n.message,e.id))}function he({datasets:e,errors:t,requireAtLeastOne:r}){const n=le({datasets:e,requireAtLeastOne:r});if(!n.ok){if(n.issue==="invalid_dataset_count"){t.push(p("invalid_dataset_count","Dashboard authoring requires at least one selected dataset."));return}t.push(p("invalid_multi_dataset_scope","Multi-dataset dashboard authoring is limited to semantic datasets from one domain."))}}function me(e){var f,g;const t=[];if(!e||typeof e!="object")return{ok:!1,errors:[p("invalid_plan","Dashboard plan must be a structured object.")],warnings:[]};const r=e,n=[...r.warnings||[]];r.version!==1&&t.push(p("invalid_version","Dashboard plan version must be 1.")),(f=r.title)!=null&&f.trim()||t.push(p("missing_title","Dashboard plan needs a title."));const i=Array.isArray(r.datasets)?r.datasets:[],a=Array.isArray(r.sheets)?r.sheets:[];he({datasets:i,errors:t,requireAtLeastOne:!0}),a.length!==1&&t.push(p("invalid_sheet_count","MVP dashboard authoring creates exactly one dashboard sheet."));const o=a[0];o&&o.kind!=="dashboard"&&t.push(p("invalid_sheet_kind",'Generated sheet must use kind "dashboard".'));const d=(o==null?void 0:o.cards)||[];d.length>v.DASHBOARD_AUTHORING_MAX_GENERATED_CARDS&&t.push(p("too_many_cards",`Generated dashboards can contain at most ${v.DASHBOARD_AUTHORING_MAX_GENERATED_CARDS} cards.`));const s=O(d.map(l=>l.id));s&&t.push(p("duplicate_card_id",`Duplicate generated card id: ${s}.`));const u=O(d.map(l=>l.frameId));u&&t.push(p("duplicate_frame_id",`Duplicate generated frame id: ${u}.`));for(const l of d)(g=l.title)!=null&&g.trim()||t.push(p("missing_card_title","Card title is required.",l.id)),l.type==="custom"&&t.push(p("custom_visual_out_of_scope","Whole-dashboard authoring supports built-in visual types only.",l.id)),l.type!=="text"&&!l.analyticsIntent&&n.push(p("missing_analytics_intent","Non-text card has no analytics intent and may be skipped by the app layer.",l.id)),ue({card:l,datasets:i,errors:t}),pe({card:l,errors:t}),fe({card:l,datasets:i,errors:t});const h=Array.isArray(r.filterInputs)?r.filterInputs:[],I=h.map(l=>l.id),A=O(I);A&&t.push(p("duplicate_input_id",`Duplicate dashboard input id: ${A}.`));const w=h.map(l=>l.variableName).filter(Boolean)||[],y=O(w);y&&t.push(p("duplicate_input_variable",`Duplicate dashboard input variable name: ${y}.`));const c=Array.isArray(r.calculatedFields)?r.calculatedFields:[];for(const l of c)l.scope==="domain"&&l.reuseOnly!==!0&&t.push(p("domain_calculated_field_create_out_of_scope",`Creating domain calculated field "${l.name}" is outside MVP.`));return{ok:t.length===0,errors:t,warnings:n}}function ge(e){var o;const t=[];if(!e||typeof e!="object")return{ok:!1,errors:[p("invalid_change_plan","Dashboard change plan must be a structured object.")],warnings:[]};const r=e,n=[...r.warnings||[]];r.version!==1&&t.push(p("invalid_version","Dashboard change plan version must be 1.")),(o=r.dashboardId)!=null&&o.trim()||t.push(p("missing_dashboard_id","Dashboard change plan needs a dashboard id."));const i=Array.isArray(r.datasets)?r.datasets:[],a=Array.isArray(r.operations)?r.operations:[];he({datasets:i,errors:t,requireAtLeastOne:!1});for(const d of a){if(d.kind==="unsupported"){n.push(p("unsupported_operation",d.reason||d.requestedAction));continue}d.kind==="addCard"&&d.card.type==="custom"&&t.push(p("custom_visual_out_of_scope","Whole-dashboard authoring supports built-in visual types only.",d.card.id)),d.kind==="addCard"&&(ue({card:d.card,datasets:i,errors:t}),pe({card:d.card,errors:t}),fe({card:d.card,datasets:i,errors:t})),d.kind==="addCalculatedField"&&d.field.scope==="domain"&&d.field.reuseOnly!==!0&&t.push(p("domain_calculated_field_create_out_of_scope",`Creating domain calculated field "${d.field.name}" is outside MVP.`))}return{ok:t.length===0,errors:t,warnings:n}}const Oe={lg:48,md:36,sm:24,xs:12,xxs:6};function Pe(e,t){let r=0,n=0,i=0;return e.map(a=>{const o=Math.min(a.w,t);r>0&&r+o>t&&(r=0,n+=i,i=0);const d={i:a.frameId,x:r,y:n,w:o,h:a.h,minW:Math.min(a.minW,t),minH:a.minH,static:!1};return r+=o,i=Math.max(i,a.h),d})}function Ee(e){const t=[...e].sort((s,u)=>s.priority-u.priority),r=t.filter(s=>s.role==="kpi"),n=t.filter(s=>s.role==="chart"),i=t.filter(s=>s.role==="table"),a=t.filter(s=>s.role==="text"),o=a.slice(0,1),d=a.slice(o.length);return{kpis:r,introText:o,charts:n,tables:i,supportingText:d}}function qe(e,t,r){return t==="xxs"||t==="xs"?r:t==="sm"?Math.min(12,r):t==="md"?e<=1||e===2?18:12:e<=1||e===2?24:e===3?16:12}function ze(e,t,r,n){return r==="xxs"||r==="xs"||r==="sm"||r==="md"||t===1||t%2===1&&e===0?n:n/2}function Ve(e){const{item:t,band:r,index:n,bandCount:i,breakpoint:a,columns:o}=e;return r==="kpi"?{...t,band:r,w:qe(i,a,o),h:15,minW:Math.min(6,o),minH:12}:r==="table"?{...t,band:r,w:o,h:a==="xxs"||a==="xs"?34:38,minW:Math.min(12,o),minH:18}:r==="introText"?{...t,band:r,w:o,h:a==="xxs"||a==="xs"?12:10,minW:Math.min(12,o),minH:8}:r==="supportingText"?{...t,band:r,w:a==="lg"?o/2:o,h:a==="xxs"||a==="xs"?12:10,minW:Math.min(12,o),minH:8}:{...t,band:r,w:ze(n,i,a,o),h:a==="xxs"||a==="xs"?28:30,minW:Math.min(12,o),minH:16}}function x(e,t,r,n){return e.map((i,a)=>Ve({item:i,band:t,index:a,bandCount:e.length,breakpoint:r,columns:n}))}function q(e){const t=Ee(e);return Object.fromEntries(v.DASHBOARD_AUTHORING_BREAKPOINTS.map(r=>{const n=Oe[r],i=[...x(t.introText,"introText",r,n),...x(t.kpis,"kpi",r,n),...x(t.charts,"chart",r,n),...x(t.tables,"table",r,n),...x(t.supportingText,"supportingText",r,n)];return[r,Pe(i,n)]}))}function He(e){const t=we.normalizeAnalyticsCatalogDataType(e);return t==="datetime"?"date":t==="unknown"?"string":t}function Le(e){return!!(e&&typeof e=="object"&&!Array.isArray(e))}function je(e){return Le(e)&&typeof e.filterId=="string"&&typeof e.operation=="string"&&Array.isArray(e.values)}function Ge(e){return e.filter(t=>typeof t=="string"||typeof t=="number")}function We(e){return e.filter(t=>t instanceof Date||typeof t=="string")}function X(e,t){if(t===void 0)return;const r=He(e.dataType),n=e.operation||"in";if(je(t))return{...t,filterId:e.id,name:t.name||e.column,valueType:r,dataType:e.dataType,fieldMeta:e.fieldMeta,semanticContext:e.semanticContext};if(n==="is null"||n==="is not null")return{filterId:e.id,name:e.column,operation:n,valueType:r,values:[],dataType:e.dataType,fieldMeta:e.fieldMeta,semanticContext:e.semanticContext};const i=Array.isArray(t)?t:[t],a=r==="date"?We(i):Ge(i);if(a.length!==0&&!((n==="between"||n==="not between")&&a.length<2))return{filterId:e.id,name:e.column,operation:n,valueType:r,values:a,dataType:e.dataType,fieldMeta:e.fieldMeta,semanticContext:e.semanticContext}}function be(e,t,r){return r?{code:e,message:t,cardId:r}:{code:e,message:t}}function Ue(e,t,r){const n=(t||[]).filter(i=>i.scope==="card"&&i.targetCardId===r).map(i=>i.field).filter(Boolean);return n.length===0?e:{...e,calculatedFields:[...e.calculatedFields||[],...n]}}function W(e,t){return Array.from(new Set((e||[]).map(r=>t.get(r)).filter(r=>!!r)))}function Ke(e,t){if((e==null?void 0:e.kind)!=="cards")return e;const r=W(e.cardIds,t);return r.length>0?{...e,cardIds:r}:null}function Xe(e,t){return!e.applyToCardIds&&!e.excludeCardIds?e:{...e,...e.applyToCardIds?{applyToCardIds:W(e.applyToCardIds,t)}:{},...e.excludeCardIds?{excludeCardIds:W(e.excludeCardIds,t)}:{}}}function Je(e,t){const r={},n=[];return{inputs:(e.filterInputs||[]).flatMap((a,o)=>{const d=Ke(a.scope,t);if(d===null)return n.push(be("filter_input_scope_empty",`Filter input "${a.label}" was skipped because all scoped cards were skipped during query validation.`)),[];const s=X(a.filter,a.defaultValue);return s&&(r.shared??(r.shared={}),r.shared[a.id]={status:"set",value:{kind:"filter",filterValue:s}}),[{id:a.id,kind:"filter",label:a.label,variableName:a.variableName,scope:d||{kind:"allSheets",sheetKinds:["dashboard"]},runtimeScope:"shared",presentation:{placement:"toolbar",order:o},exports:["label","value","start","end","range"],filter:Xe(a.filter,t)}]}),warnings:n,defaultInputValues:r.shared&&Object.keys(r.shared).length>0?r:void 0}}function Qe(e){var w,y;const t=me(e.plan);if(!t.ok)throw new Error(t.errors.map(c=>c.message).join(`
2
+ `)||"Dashboard plan is invalid.");const r=e.plan.sheets[0],n=[...t.warnings],i=[],a=new Map(e.cardArtifacts.map(c=>[c.planCardId,c])),o=new Map(e.cardArtifacts.map(c=>[c.planCardId,c.card.id])),d=[];for(const c of r.cards){const f=a.get(c.id);if(!f){const l=be("missing_card_artifact",`Card "${c.title}" was skipped because no generated artifact was supplied.`,c.id);i.push(l);continue}n.push(...f.warnings||[]);const g=Ue(f.card,e.plan.calculatedFields,c.id);d.push({id:c.frameId,cards:[g],activeCardId:g.id})}if(d.length===0)throw new Error("Dashboard plan did not produce any persistable cards.");const{inputs:s,defaultInputValues:u,warnings:h}=Je(e.plan,o);n.push(...h);const I=q(r.cards.filter(c=>d.some(f=>f.id===c.frameId)).map(c=>({frameId:c.frameId,priority:c.priority,role:c.role})));return{dashboard:{id:e.dashboardId,title:e.plan.title,description:e.plan.description||"",sheets:[{id:r.id,kind:"dashboard",title:r.title,description:r.description,frames:d,layouts:I,calculatedFields:(w=e.plan.calculatedFields)==null?void 0:w.filter(c=>c.scope==="sheet"&&c.field).map(c=>c.field)}],calculatedFields:(y=e.plan.calculatedFields)==null?void 0:y.filter(c=>c.scope==="dashboard"&&c.field).map(c=>c.field),inputs:s,...u?{defaultInputValues:u}:{}},warnings:n,skippedOperations:i}}function k(e,t,r){return r?{code:e,message:t,cardId:r}:{code:e,message:t}}function Ye(e){return JSON.parse(JSON.stringify(e))}function Ze(e){var t;return(t=e.sheets)==null?void 0:t.find(r=>(r.kind||"dashboard")==="dashboard")}function H(e,t){var r;for(const n of e.sheets||[])for(const i of n.frames||[]){const a=(r=i.cards)==null?void 0:r.find(o=>o.id===t);if(a)return{sheet:n,frame:i,card:a}}return null}function Ie(e){var r,n;const t=(n=(r=e.cards)==null?void 0:r[0])==null?void 0:n.type;return t==="kpi"?"kpi":t==="table"||t==="detailTable"||t==="pivotTable"?"table":t==="text"?"text":"chart"}function et(e){var t;return new Map((((t=e.layouts)==null?void 0:t.lg)||[]).map((r,n)=>[r.i,n]))}function ye(e,t=new Map){const r=et(e),n=Math.max(r.size,t.size),i=(e.frames||[]).map((a,o)=>({frameId:a.id,role:Ie(a),priority:t.get(a.id)??r.get(a.id)??n+o}));e.layouts=q(i)}function tt(e){return Object.values(e.layouts||{}).some(t=>t.length>0)}function rt(e,t){if(!tt(e)){ye(e);return}const r=q([{frameId:t.id,role:Ie(t),priority:0}]);e.layouts??(e.layouts={});for(const[n,i]of Object.entries(r)){const a=e.layouts[n]||[];if(a.some(s=>s.i===t.id))continue;const o=i[0];if(!o)continue;const d=a.reduce((s,u)=>Math.max(s,u.y+u.h),0);e.layouts[n]=[...a,{...o,y:d}]}}function nt(e,t){var n;const r=X(t.filter,t.defaultValue);r&&(e.defaultInputValues??(e.defaultInputValues={}),(n=e.defaultInputValues).shared??(n.shared={}),e.defaultInputValues.shared[t.id]={status:"set",value:{kind:"filter",filterValue:r}})}function at(e){var d;const t=ge(e.changePlan);if(!t.ok)throw new Error(t.errors.map(s=>s.message).join(`
3
+ `)||"Dashboard change plan is invalid.");const r=Ye(e.dashboard),n=[...t.warnings],i=[],a=new Map(e.cardArtifacts.map(s=>[s.planCardId,s])),o=Ze(r);if(!o)throw new Error("Dashboard has no editable dashboard sheet.");o.frames??(o.frames=[]);for(const s of e.changePlan.operations)switch(s.kind){case"addCard":{if((o.frames||[]).reduce((A,w)=>{var y;return A+(((y=w.cards)==null?void 0:y.length)||0)},0)>=v.DASHBOARD_AUTHORING_MAX_GENERATED_CARDS){i.push(k("generated_card_limit_reached",`AI refinement is capped at ${v.DASHBOARD_AUTHORING_MAX_GENERATED_CARDS} cards.`,s.card.id));break}const h=a.get(s.card.id);if(!h){i.push(k("missing_card_artifact",`Card "${s.card.title}" was skipped because no generated artifact was supplied.`,s.card.id));break}const I={id:s.card.frameId,cards:[h.card],activeCardId:h.card.id};o.frames.push(I),rt(o,I);break}case"addFilterInput":{r.inputs??(r.inputs=[]);const u={id:s.input.id,kind:"filter",label:s.input.label,variableName:s.input.variableName,scope:s.input.scope||{kind:"allSheets",sheetKinds:["dashboard"]},runtimeScope:"shared",presentation:{placement:"toolbar",order:r.inputs.length},exports:["label","value","start","end","range"],filter:s.input.filter};r.inputs.push(u),nt(r,s.input);break}case"addCalculatedField":{if(s.field.scope==="dashboard"&&s.field.field)r.calculatedFields??(r.calculatedFields=[]),r.calculatedFields.push(s.field.field);else if(s.field.scope==="sheet"&&s.field.field)o.calculatedFields??(o.calculatedFields=[]),o.calculatedFields.push(s.field.field);else if(s.field.scope==="card"&&s.field.field){const u=s.field.targetCardId?H(r,s.field.targetCardId):null;u?((d=u.card).calculatedFields??(d.calculatedFields=[]),u.card.calculatedFields.push(s.field.field)):i.push(k("missing_calculated_field_target",`Calculated field "${s.field.name}" needs a valid target card.`))}break}case"renameCard":{const u=H(r,s.cardId);if(!u){i.push(k("card_not_found",`Card "${s.cardId}" could not be renamed because it was not found.`,s.cardId));break}u.card.title=s.title,s.description!==void 0&&(u.card.description=s.description);break}case"reorderCards":{const u=new Map;for(let h=0;h<s.cardIds.length;h+=1){const I=s.cardIds[h],A=H(r,I);A&&u.set(A.frame.id,h)}ye(o,u);break}case"reuseCalculatedField":n.push(k("reused_calculated_field",`Calculated field "${s.fieldId}" is reused by reference.`));break;case"unsupported":i.push(k("unsupported_operation",s.reason||s.requestedAction));break}return{dashboard:r,warnings:n,skippedOperations:i}}function b(e,t,r){return r?{code:e,message:t,cardId:r}:{code:e,message:t}}function F(e,t){return e.trim().toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-+|-+$/g,"")||t}function _e(e,t){if(!t.has(e))return t.add(e),e;let r=2,n=`${e}-${r}`;for(;t.has(n);)r+=1,n=`${e}-${r}`;return t.add(n),n}function $(e){return!!(e&&typeof e=="object")}function Se(e){return Array.isArray(e.inputs)?e.inputs.filter(t=>$(t)&&typeof t.id=="string"):[]}function J(e){return Array.isArray(e.sections)?e.sections.filter(t=>$(t)):[]}function Q(e){return Array.isArray(e.views)?e.views.filter(t=>$(t)):[]}function T(e){if(!Array.isArray(e))return[];const t=[];for(const r of e){const n=S(r);n&&t.push(n)}return t}function it(e){var n;if(!e)return[];const t=[];if(M(e.source)&&t.push(e.source),e.kind==="metric"){t.push(...T(e.metrics));const i=S(e.dateField);i&&t.push(i),t.push(...T(e.dimensions)),t.push(...T((n=e.filters)==null?void 0:n.map(a=>a.field)))}else if(e.kind==="records"){const i=S(e.dateField);i&&t.push(i),t.push(...T(e.fields))}else if(e.kind==="inputOptions"){const i=S(e.field);i&&t.push(i)}else e.kind==="sql"&&t.push(...T(e.fields));const r="inputs"in e&&Array.isArray(e.inputs)?e.inputs:[];for(const i of r){const a=S(i.field);a&&t.push(a)}return t}function ot(e){const t=[];for(const r of Se(e)){const n=S(r.field);n&&t.push(n)}for(const r of J(e))for(const n of Q(r))t.push(...it(n.analytics));return t}function st(e){var r;const t=[];for(const n of J(e))for(const i of Q(n))M((r=i.analytics)==null?void 0:r.source)&&t.push(i.analytics.source);return t}function dt(e,t){const r=R(e).filter(M);if(r.length===0)return t.push(b("missing_materializable_dataset","No semantic or physical source could be converted into the current dashboard authoring dataset reference.")),[];const n=r.every(a=>a.kind==="semantic"),i=Array.from(new Set(r.filter(a=>a.kind==="semantic").map(a=>a.domainId)));return r.length>1&&(!n||i.length!==1)?(t.push(b("multiple_datasets_out_of_scope","The dashboard authoring compiler supports multiple datasets only within one semantic domain; using the first source and deferring the rest.")),[r[0]]):r}function ct(e,t){const r=J(e),n=Se(e),i=R(ot(e)),a=R(st(e));return{sections:r,inputs:n,sources:i,primarySources:a,defaultSource:a.length===1?a[0]:void 0,datasets:dt(i,t)}}function lt(e){return e&&U.validateSemaphorAnalyticsIntent(e).ok?e:void 0}function ut(e){var t;switch((t=e.presentation)==null?void 0:t.kind){case"kpi":return"kpi";case"lineChart":return"line";case"barChart":return"bar";case"areaChart":return"area";case"table":return"table";case"text":return"text";default:return null}}function ft(e){var t,r,n;return((t=e.presentation)==null?void 0:t.kind)==="kpi"?"kpi":((r=e.presentation)==null?void 0:r.kind)==="table"?"table":((n=e.presentation)==null?void 0:n.kind)==="text"?"text":"chart"}function pt(e){switch(e){case"not_in":return"not in";case"not_between":return"not between";case"contains":return"like";default:return e||"in"}}function ht(e){return $(e.field)?e.field.dataType==="datetime"?"date":e.field.dataType||"string":"string"}function mt(e){if(!(!e||e.kind!=="physical"))return[e.databaseName,e.schemaName,e.tableName].filter(Boolean).join(".")}function gt(e,t,r,n,i,a){if(e.kind!=="filter")return a.push(b("control_inputs_deferred",`Control input "${e.label}" is represented in the protocol but not yet materialized by the dashboard authoring adapter.`)),null;if(!$(e.field)||typeof e.field.name!="string")return a.push(b("filter_requires_field",`Filter "${e.label||e.id}" needs a field before the dashboard compiler can materialize it.`)),null;const o=se({explicitSource:void 0,field:e.field,defaultSource:t,fallbackSources:r}),d=(o==null?void 0:o.kind)==="semantic"||(o==null?void 0:o.kind)==="physical"?o.connectionId:void 0;if(!d)return a.push(b("filter_requires_connection_id",`Filter "${e.label}" needs a source connectionId before the dashboard compiler can materialize it.`)),null;const h={id:`filter-${_e(F(e.id,e.field.name),i)}`,variableName:e.id,connectionId:d,title:e.label,column:e.field.name,dataType:ht(e),qualifiedTableName:mt(o),sql:"",operation:pt(e.operator),type:e.multi===!1?"single":"multiple",location:"dashboard",displayMode:"toolbar",fieldMeta:(o==null?void 0:o.kind)==="semantic"?{name:e.field.name,qualifiedFieldName:e.field.name,dataType:e.field.dataType,role:e.field.role==="measure"?"metric":"groupby"}:void 0,semanticContext:(o==null?void 0:o.kind)==="semantic"?{semanticDomainId:o.domainId,connectionId:o.connectionId}:void 0};return{id:e.id,label:e.label,variableName:e.id,scope:n,filter:h,defaultValue:X(h,e.defaultValue)}}function L(e){const t=[],r=[];for(const n of e.viewIds){const i=e.viewIdToCardId.get(n);i?t.push(i):r.push(n)}return r.length>0&&e.warnings.push(b("input_scope_view_not_found",`Filter "${e.inputLabel}" referenced unknown view ids: ${r.join(", ")}.`)),Array.from(new Set(t))}function bt(e){var n,i;if(!e.protocolScope){const a=Array.from(new Set(e.boundCardIds));return a.length>0&&a.length<e.allCardIds.length?{kind:"cards",cardIds:a}:void 0}if(e.protocolScope.level==="dashboard"){if(!((n=e.protocolScope.excludeViewIds)!=null&&n.length))return;const a=new Set(L({inputLabel:e.inputLabel,viewIds:e.protocolScope.excludeViewIds,viewIdToCardId:e.viewIdToCardId,warnings:e.warnings}));return{kind:"cards",cardIds:e.allCardIds.filter(o=>!a.has(o))}}if(e.protocolScope.level==="view"){const a=L({inputLabel:e.inputLabel,viewIds:e.protocolScope.viewIds,viewIdToCardId:e.viewIdToCardId,warnings:e.warnings});return a.length===0?(e.warnings.push(b("input_scope_has_no_materialized_cards",`Filter "${e.inputLabel}" was deferred because its view scope does not match any materialized cards.`)),null):{kind:"cards",cardIds:a}}const t=e.sectionIdToCardIds.get(e.protocolScope.sectionId)||[];if(t.length===0)return e.warnings.push(b("input_scope_section_not_found",`Filter "${e.inputLabel}" was deferred because section "${e.protocolScope.sectionId}" does not match any materialized cards.`)),null;if(!((i=e.protocolScope.excludeViewIds)!=null&&i.length))return{kind:"cards",cardIds:t};const r=new Set(L({inputLabel:e.inputLabel,viewIds:e.protocolScope.excludeViewIds,viewIdToCardId:e.viewIdToCardId,warnings:e.warnings}));return{kind:"cards",cardIds:t.filter(a=>!r.has(a))}}function It(e){var w,y,c;const t=[],r=U.validateSemaphorDashboardIntent(e);for(const f of r.warnings)t.push(b(f.code,f.message));for(const f of r.errors)t.push(b(f.code,f.message));const n=ct(e,t),i=[],a=new Map,o=new Map,d=new Map,s=new Set,u=new Set;let h=0;for(const[f,g]of n.sections.entries()){const l=typeof g.title=="string"?g.title:`Section ${f+1}`,Y=g.id||F(l,`section-${f+1}`);o.set(Y,[]);for(const[Z,m]of Q(g).entries()){const ee=ut(m),z=F(m.id||`${l}-${m.title||`View ${Z+1}`}`,`card-${f+1}-${Z+1}`);if(!ee){t.push(b("unsupported_presentation",`Dashboard presentation "${((w=m.presentation)==null?void 0:w.kind)||"unknown"}" is not supported by the dashboard authoring adapter.`,`card-${z}`));continue}if(((y=m.analytics)==null?void 0:y.kind)==="sql"){t.push(b("sql_intent_deferred","SQL analytics intent is valid protocol, but the current dashboard authoring adapter only materializes semantic and physical config-card intents.",`card-${z}`));continue}const te=_e(z,s),B=`card-${te}`;m.id&&a.set(m.id,B),(c=o.get(Y))==null||c.push(B);const Ae=m.analytics&&"inputs"in m.analytics?m.analytics.inputs:void 0;for(const re of Ae||[]){const ne=d.get(re.inputId)||[];ne.push(B),d.set(re.inputId,ne)}i.push({id:B,frameId:`frame-${te}`,title:m.title,description:m.description,type:ee,role:ft(m),priority:h,section:l,analyticsIntent:lt(m.analytics),text:m.text}),h+=1}}const I=n.inputs.map(f=>{const g=bt({protocolScope:f.scope,inputLabel:f.label,allCardIds:i.map(l=>l.id),boundCardIds:d.get(f.id)||[],viewIdToCardId:a,sectionIdToCardIds:o,warnings:t});return g===null?null:gt(f,n.defaultSource,n.sources,g,u,t)}).filter(f=>!!f);return{plan:{version:1,id:`plan-${F(e.title,"dashboard")}`,title:e.title,description:e.description,datasets:n.datasets,sheets:[{id:`sheet-${F(e.title,"dashboard")}`,title:e.title,description:e.description,kind:"dashboard",cards:i}],filterInputs:I.length?I:void 0,warnings:t.length?t:void 0,unresolvedRequests:r.ok?void 0:r.errors.map(f=>f.message)},warnings:t}}exports.DASHBOARD_AUTHORING_BREAKPOINTS=v.DASHBOARD_AUTHORING_BREAKPOINTS;exports.DASHBOARD_AUTHORING_MAX_GENERATED_CARDS=v.DASHBOARD_AUTHORING_MAX_GENERATED_CARDS;exports.applyDashboardChangePlan=at;exports.compileDashboardFromPlan=Qe;exports.compileResponsiveDashboardLayouts=q;exports.dashboardAuthoringDatasetMatchesSource=E;exports.dashboardAuthoringFieldsReferToSameTarget=Ce;exports.dashboardAuthoringSourceFromField=S;exports.dashboardAuthoringSourceKey=De;exports.dashboardAuthoringSourcesReferToSameDataset=K;exports.dashboardPlanFromSemaphorDashboardIntent=It;exports.findDashboardAuthoringDatasetForSource=Me;exports.getDashboardAuthoringCardSource=ce;exports.isMaterializableDashboardAuthoringSource=M;exports.isSemaphorSourceRef=ie;exports.mergeDashboardAuthoringSources=R;exports.preferDashboardAuthoringSourceMetadata=oe;exports.preferredDashboardAuthoringSource=ve;exports.resolveDashboardAuthoringSource=se;exports.validateDashboardAuthoringDatasetScope=le;exports.validateDashboardChangePlan=ge;exports.validateDashboardPlan=me;