react-semaphor 0.1.376 → 0.1.377

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 (60) hide show
  1. package/dist/analytics-protocol/index.cjs +1 -1
  2. package/dist/analytics-protocol/index.js +47 -43
  3. package/dist/brand-studio/index.cjs +4 -4
  4. package/dist/brand-studio/index.js +10 -8
  5. package/dist/chunks/braces-C2uBgj3t.js +6 -0
  6. package/dist/chunks/braces-CkXyWzRh.js +23 -0
  7. package/dist/chunks/{calendar-preferences-dialog-B6fsethx.js → calendar-preferences-dialog-C55VOTIy.js} +6 -5
  8. package/dist/chunks/calendar-preferences-dialog-DAukJOaP.js +1 -0
  9. package/dist/chunks/catalog-field-grounding-BGW0hnB9.js +1 -0
  10. package/dist/chunks/catalog-field-grounding-DHXEI7cW.js +199 -0
  11. package/dist/chunks/{chevrons-up-down-lahj6tQy.js → chevrons-up-down-BnzChFLU.js} +1 -1
  12. package/dist/chunks/{chevrons-up-down-D2fZD4N_.js → chevrons-up-down-W0nzHzx0.js} +1 -1
  13. package/dist/chunks/{dashboard-briefing-launcher-BKCRO7Qw.js → dashboard-briefing-launcher-CUyeiL_T.js} +3153 -2392
  14. package/dist/chunks/dashboard-briefing-launcher-DMKfG_z3.js +111 -0
  15. package/dist/chunks/dashboard-controls-B4hxFc3Q.js +2279 -0
  16. package/dist/chunks/dashboard-controls-D4vI0wvU.js +52 -0
  17. package/dist/chunks/dashboard-json-DQnm6daE.js +1 -0
  18. package/dist/chunks/{dashboard-json-QT0T2ad_.js → dashboard-json-pl1_mFqJ.js} +14 -13
  19. package/dist/chunks/{edit-dashboard-visual-kNoMQRmH.js → edit-dashboard-visual-CF4aSsav.js} +1489 -1488
  20. package/dist/chunks/{edit-dashboard-visual-DNzPgXMh.js → edit-dashboard-visual-CjTXY51a.js} +1 -1
  21. package/dist/chunks/{index-CPpqPJba.js → index-B2kPleRS.js} +4 -4
  22. package/dist/chunks/{index-DX_0OcRv.js → index-Bn866BBY.js} +67 -67
  23. package/dist/chunks/layout-grid-BFmJ7vmH.js +16 -0
  24. package/dist/chunks/layout-grid-CTOW9oTg.js +6 -0
  25. package/dist/chunks/{palette-BcHHAmOU.js → palette-DrhPeer-.js} +1 -1
  26. package/dist/chunks/{palette-2HWSR5wb.js → palette-OFaniMPn.js} +1 -1
  27. package/dist/chunks/{save-MoF1T13_.js → save-BxWBiQv1.js} +1 -1
  28. package/dist/chunks/{save-B-YfAPhu.js → save-Dh6gSC4x.js} +1 -1
  29. package/dist/chunks/{switch-DmE_MY3L.js → switch-C-fGjxjY.js} +1 -1
  30. package/dist/chunks/{switch-CmHP5dT7.js → switch-D5xopzFD.js} +1 -1
  31. package/dist/chunks/{use-create-flow-overlay-state-BLPQgGuz.js → use-create-flow-overlay-state-Dg2ffpCE.js} +2 -2
  32. package/dist/chunks/{use-create-flow-overlay-state-D_Ntx-_C.js → use-create-flow-overlay-state-DrKP0jWE.js} +113 -112
  33. package/dist/chunks/{validation-1V7bWmYw.js → validation-BHFaWDU-.js} +1 -1
  34. package/dist/chunks/{validation-DlrTIf1N.js → validation-bMedDBOo.js} +1 -1
  35. package/dist/dashboard/index.cjs +1 -1
  36. package/dist/dashboard/index.js +1 -1
  37. package/dist/dashboard-authoring/index.cjs +1 -1
  38. package/dist/dashboard-authoring/index.js +1 -1
  39. package/dist/data-app-builder/index.cjs +1 -1
  40. package/dist/data-app-builder/index.js +3 -3
  41. package/dist/data-app-sdk/index.cjs +1 -1
  42. package/dist/data-app-sdk/index.js +22 -21
  43. package/dist/data-app-sdk-validation/index.cjs +1 -1
  44. package/dist/data-app-sdk-validation/index.js +2 -2
  45. package/dist/index.cjs +1 -1
  46. package/dist/index.js +127 -125
  47. package/dist/surfboard/index.cjs +1 -1
  48. package/dist/surfboard/index.js +2 -2
  49. package/dist/types/analytics-protocol.d.ts +84 -0
  50. package/dist/types/main.d.ts +7 -0
  51. package/package.json +1 -1
  52. package/dist/chunks/calendar-preferences-dialog-Dh1b0ytN.js +0 -1
  53. package/dist/chunks/catalog-field-grounding-DoEBOXQd.js +0 -100
  54. package/dist/chunks/catalog-field-grounding-Du6mKDcF.js +0 -1
  55. package/dist/chunks/dashboard-briefing-launcher-Gv1cwT0I.js +0 -111
  56. package/dist/chunks/dashboard-controls-BDJZarV7.js +0 -52
  57. package/dist/chunks/dashboard-controls-CchLBVDv.js +0 -3037
  58. package/dist/chunks/dashboard-json-ZhIEMXN0.js +0 -1
  59. package/dist/chunks/layout-grid-BOTLt36V.js +0 -36
  60. package/dist/chunks/layout-grid-CS6BSCJF.js +0 -11
@@ -1,4 +1,4 @@
1
- "use strict";const s=require("./switch-CmHP5dT7.js"),C=require("react"),m=require("./index-CPpqPJba.js"),e=require("react/jsx-runtime");require("./index-BxM99sFL.js");const Se=require("./save-MoF1T13_.js");/**
1
+ "use strict";const s=require("./switch-D5xopzFD.js"),C=require("react"),m=require("./index-B2kPleRS.js"),e=require("react/jsx-runtime");require("./index-BxM99sFL.js");require("./catalog-field-grounding-BGW0hnB9.js");const Se=require("./save-BxWBiQv1.js");/**
2
2
  * @license lucide-react v0.453.0 - ISC
3
3
  *
4
4
  * This source code is licensed under the ISC license.
@@ -18,4 +18,4 @@
18
18
  *
19
19
  * This source code is licensed under the ISC license.
20
20
  * See the LICENSE file in the root directory of this source tree.
21
- */const Ie=s.createLucideIcon("SendHorizontal",[["path",{d:"M3.714 3.048a.498.498 0 0 0-.683.627l2.843 7.627a2 2 0 0 1 0 1.396l-2.842 7.627a.498.498 0 0 0 .682.627l18-8.5a.5.5 0 0 0 0-.904z",key:"117uat"}],["path",{d:"M6 12h16",key:"s4cdu5"}]]);function Ve(){const r=s.useEditorStore(f=>f.card.dataSource),{setSelectedConnectionId:a,setSelectedDatabaseName:o,setSelectedSchemaName:n,setSelectedTableName:i,setSelectedDatamodelId:c}=s.useEditorActions();C.useEffect(()=>{var w;if(!r)return;const{tableName:f,schemaName:h,databaseName:p,connectionId:v}=m.extractTableMetadata(r),g=(w=r.selectedEntities)==null?void 0:w[0],S=(g==null?void 0:g.type)==="model"&&"id"in g?g.id:"";a(v||""),o(p||""),n(h||""),i(f||""),c(S)},[r,a,o,n,i,c])}const ce=new Set;function Te(r){return ce.add(r),()=>{ce.delete(r)}}function Ne(){ce.forEach(r=>{r()})}function ue(){var p,v;const r=s.useEditorStore(g=>g.card),a=s.useEditorStore(g=>g.frame),o=C.useMemo(()=>m.findCustomVisualConfigCard(a,r),[a,r]),{manifest:n}=m.useCustomVisual(((p=o==null?void 0:o.customCardPreferences)==null?void 0:p.url)||""),i=C.useMemo(()=>{var g;return(g=n==null?void 0:n.visuals)==null?void 0:g.find(x=>{var S;return x.name===((S=o==null?void 0:o.customCardPreferences)==null?void 0:S.componentName)})},[n,(v=o==null?void 0:o.customCardPreferences)==null?void 0:v.componentName]),c=m.resolveMultiInputType(o,i),f=C.useMemo(()=>m.getCustomVisualInputCards({frame:a,configCard:o,isMultiInputVisual:c==="multiple"}),[a,o,c]),h=C.useMemo(()=>{const g=f.findIndex(x=>(x==null?void 0:x.id)===r.id);return g<0?-1:m.getSlotIndexForCard(r,g)},[f,r]);return C.useMemo(()=>!o||c!=="multiple"||h<0?r.type:m.getEffectiveCardTypeForSlot(r,h,i==null?void 0:i.slots)??r.type,[o,c,h,r,i==null?void 0:i.slots])}function Le(r){const[a,o]=C.useState(null),[n,i]=C.useState(null),c=m.useEnsureReactGlobals();return C.useEffect(()=>{if(!r||r.trim()===""){o(null),i(null);return}if(!c)return;(async()=>{try{if(!r.startsWith("http://")&&!r.startsWith("https://"))throw new Error(`Invalid URL format: ${r}`);try{new URL(r)}catch{throw new Error(`Invalid URL: ${r}`)}const p=`${r.endsWith("/")?r:`${r}/`}index.js`;try{if(!(await fetch(p,{method:"HEAD"})).ok)throw new Error(`Module not found at ${p}`)}catch{}const v=await import(p);if(typeof v.useChartStore!="function")throw new Error("useChartStore is not a function");o(()=>v.useChartStore),i(null)}catch(h){const p=h instanceof Error?h.message:"Unknown error";console.error("Failed to load remote chart store:",p),i(p),o(null)}})()},[r,c]),a}function Ae(r,a){if(r.length===0)return"";const o=r.find(n=>{var i,c;return((i=n.customCardPreferences)==null?void 0:i.visualType)==="multiple"||!!((c=n.customCardPreferences)!=null&&c.dataInputCardIds)});if(o)return o.id;if(a){const n=r.find(i=>i.id===a);if(n){const i=n.tabTitle;if(i=="All__Header")return r[0].id;if(i&&i.endsWith("__Header")){const f=i.split("__")[0],h=r.find(p=>p.tabTitle===f);return h?h.id:r[0].id}return a}}return r[0].id}const _e=r=>{if(!r||!("detailTableBackup"in r))return r;const{detailTableBackup:a,...o}=r;return o};async function be(r,a,o,n,i="Opening library visual..."){if(!a||!o)throw new Error("Missing auth token or visual ID");const c=["resource-by-id","visual",o],f=n.getQueryData(c);if(f)return console.log("Using cached visual data for:",o),{data:f,fromCache:!0};console.log("Fetching visual data from network for:",o);const h=m.ue.loading(i,{position:"top-center"});try{const p=await fetch(`${r}/management/v1/visuals/${o}`,{headers:{Authorization:`Bearer ${a}`}});if(!p.ok)throw new Error("Failed to load visual");const v=await p.json();return n.setQueryData(c,v),m.ue.dismiss(h),{data:v,fromCache:!1}}catch(p){throw m.ue.dismiss(h),p}}function Ee(r){if(typeof r=="string")return JSON.parse(r);if(typeof r=="object")return r;throw new Error("Invalid frame object format")}function Be(r,a){var c,f;const o=(r==null?void 0:r.frameObject)??((c=r==null?void 0:r.visual)==null?void 0:c.frameObject);if(!o)return!1;const n=Ee(o);if(!(n!=null&&n.cards)||n.cards.length===0)return!1;const i=(f=n.cards)==null?void 0:f.find(h=>h.id===n.activeCardId);return i?(m.setupEditorWithCard({...a,frame:n,card:i,visualId:(r==null?void 0:r.id)||n.visualId}),!0):!1}function Me(){const r=s.useEditorStore(n=>{var i;return((i=n.card.customCardPreferences)==null?void 0:i.url)||""}),a=Le(r);return{getUpdatedFrame:C.useCallback(()=>{var V;Ne();const{frame:n,card:i,isDevMode:c,isShowingVisual:f,selectedSchemaName:h,selectedDatamodelId:p,selectedDatabaseName:v,selectedTableName:g,selectedConnectionId:x}=s.useEditorStore.getState(),S=i.sql,w=(V=a==null?void 0:a.getState())==null?void 0:V.settings,k=s.buildSavedEditorCard(i,{isDevMode:c,cardSql:S,isShowingVisual:f,selectedSchemaName:h,selectedDatamodelId:p,selectedDatabaseName:v,selectedTableName:g,selectedConnectionId:x,remoteChartSettings:w,stripConfig:_e}),E=n.cards.map(U=>U.id===i.id?k:U);return{...n,cards:E,activeCardId:Ae(E,n.activeCardId)}},[a])}}function se(){const{authToken:r,tokenProps:a}=m.useSemaphorContext(),o=m.useQueryClient(),n=m.useAddFrameWithFreshSemanticExecutionPayload(),i=m.useSelectedVisual(),{selectVisual:c}=m.useManagementActions(),{setFrame:f,setCard:h,setIsDevMode:p,initializeModeDrafts:v,setActiveTabCardId:g,updateDataSource:x,setQueryResultColumns:S,setSelectedConnectionId:w,setSelectedDatabaseName:k,setSelectedSchemaName:E,setSelectedTableName:V,setSelectedDatamodelId:U,setFilterValues:H,setInlineFilterValuesMap:W,setApplyFilters:Y,clearEditorContext:J}=s.useEditorActions(),{setIsDashboardEditing:M,setIsVisualEditing:l,setSelectedFrameId:D,clearSelectedFrameId:T}=s.useDashboardActions(),q=s.useDashboardStore(A=>A.selectedSheetId),Q=s.useDashboardStore(A=>A.selectedFrameId),K=s.useDashboardStore(A=>A.dashboard),G=s.useDashboardStore(A=>A.filterValues),_=s.useDashboardStore(A=>A.inlineFilterValuesMap),z=m.useVisualById((i==null?void 0:i.id)||"",{enabled:!!(i!=null&&i.id)&&!!(r!=null&&r.accessToken)}),$=C.useCallback(async A=>{try{c(A),T(),J();const{data:F,fromCache:P}=await be(a.apiServiceUrl,(r==null?void 0:r.accessToken)||"",A.id,o,"Opening library visual...");if(!Be(F,{setFrame:f,setCard:h,setIsDevMode:p,initializeModeDrafts:v,setActiveTabCardId:g,updateDataSource:x,setQueryResultColumns:S,setSelectedConnectionId:w,setSelectedDatabaseName:k,setSelectedSchemaName:E,setSelectedTableName:V,setSelectedDatamodelId:U,setFilterValues:H,setInlineFilterValuesMap:W,setApplyFilters:Y,setIsDashboardEditing:M,setIsVisualEditing:l,dashboard:K,selectedSheetId:q,selectedFrameId:Q,filterValues:G,inlineFilterValuesMap:_}))throw new Error("Failed to setup editor with visual data");return{success:!0,fromCache:P}}catch(F){return console.error("Error editing visual:",F),{success:!1,error:"Failed to load visual for editing"}}},[r==null?void 0:r.accessToken,a.apiServiceUrl,o,c,f,h,M,l,p,v,g,x,S,w,k,E,V,U,H,W,Y,J,T,K,q,Q,G,_]),ae=C.useCallback(async A=>{var P;const F=B=>(m.ue.error(B),{success:!1,error:B});try{if(c(A),!q)return F("No sheet selected. Please select a sheet first.");const{data:B,fromCache:ne}=await be(a.apiServiceUrl,(r==null?void 0:r.accessToken)||"",A.id,o,"Adding visual to dashboard..."),te=(B==null?void 0:B.frameObject)??((P=B==null?void 0:B.visual)==null?void 0:P.frameObject);if(!te)return F("Visual has no frame data");const R=Ee(te);if(!(R!=null&&R.cards)||R.cards.length===0)return F("Visual frame is malformed");const ee={...m.cloneLinkedFrameWithSourceMapping(R),visualId:A.id};return await n(q,ee,"end"),M(!0),D(ee.id),{success:!0,fromCache:ne}}catch(B){return console.error("Error adding visual:",B),F(B instanceof Error?B.message:"Failed to add visual to dashboard")}},[r==null?void 0:r.accessToken,a.apiServiceUrl,o,c,q,M,D,n]);return{visual:z.data,isLoading:z.isLoading,isError:z.isError,error:z.error,handleEditLibraryVisual:$,handleAddLibraryVisual:ae,getUpdatedFrame:Me().getUpdatedFrame,refetch:z.refetch}}function qe({type:r,isLinked:a,className:o,showLabel:n=!1,showLocal:i=!1}){const c=s.useDashboardStore(E=>E.selectedFrameId),f=m.useManagementStore(E=>E.selectedVisual),h=s.useEditorStore(E=>E.frame);let p;if(r)p=r;else if(a!==void 0)p=a?"linked":"library";else if(!!!(h!=null&&h.visualId||f!=null&&f.id)&&c)p="local";else if(f&&!c)p="library";else if(h!=null&&h.visualId&&c)p="linked";else if(f!=null&&f.id&&c)p="library";else return null;if(p==="local"&&!i)return null;const v={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"},g={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."},x={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"},S={local:"fill-slate-50 dark:fill-slate-900",linked:"fill-purple-50 dark:fill-purple-950",library:"fill-blue-50 dark:fill-blue-950"},w={local:e.jsx("span",{className:"h-2 w-2 rounded-full bg-current/70"}),linked:e.jsx(ke,{className:"h-3.5 w-3.5"}),library:e.jsx(je,{className:"h-3.5 w-3.5"})},k={local:"Local",linked:"Linked",library:"Library"};return e.jsx(s.TooltipProvider,{children:e.jsxs(s.Tooltip,{delayDuration:300,children:[e.jsx(s.TooltipTrigger,{asChild:!0,children:e.jsxs(m.Badge,{variant:"outline",className:s.cn("cursor-help select-none transition-all",v[p],o),children:[w[p],n&&e.jsx("span",{className:"ml-1 text-xs font-medium leading-none",children:k[p]})]})}),e.jsxs(s.TooltipContent,{side:"bottom",className:s.cn("max-w-xs",x[p]),children:[e.jsx(s.TooltipArrow,{className:S[p]}),e.jsx("p",{children:g[p]})]})]})})}function Oe(r,a){return{...r,sql:"",python:"",config:void 0,customCfg:"",preferences:{},interactionConfig:void 0,linkedInteractionTargetOverrides:void 0,dynamicCardPreferences:void 0,customCardPreferences:a?r.customCardPreferences:void 0,visualizationMode:"builtin",type:a?r.type:"bar"}}function pe(r){const a=s.getDynamicFrameSaveIssue(r);return a?(m.ue.error(a),!1):!0}function Ue({className:r,variant:a="outline"}){const o=s.useEditorStore(c=>c.onSave),{getUpdatedFrame:n}=se();function i(){const c=n();pe(c)&&(o==null||o(c))}return e.jsxs(s.Button,{onClick:i,className:r,size:"xs",variant:a,children:[e.jsx(s.Check,{className:"h-3.5 w-3.5"}),"Accept"]})}function ze({className:r,variant:a="default"}){const o=m.useQueryClient(),[n,i]=C.useState(!1),{setIsVisualEditing:c}=s.useDashboardActions(),{getUpdatedFrame:f}=se(),h=m.useSelectedVisual(),p=s.useEditorStore(x=>x.frame),v=m.useUpdateVisualMutation(),g=()=>{const x=f();if(!pe(x))return;const S=(p==null?void 0:p.visualId)||(h==null?void 0:h.id);if(!S){m.ue.error("No visual to save");return}i(!0),v.mutate({visualId:S,data:{frameObject:x}},{onSuccess:()=>{i(!1),m.ue.success("Visual updated successfully"),o.invalidateQueries({queryKey:["resource-by-id","visual",S],exact:!0})},onError:()=>{i(!1),m.ue.error("Failed to update visual")}})};return e.jsx(s.Button,{onClick:g,className:r,size:"xs",variant:a,children:n?e.jsxs(e.Fragment,{children:[e.jsx(s.LoaderCircle,{className:"h-3.5 w-3.5 animate-spin"}),"Saving"]}):e.jsxs(e.Fragment,{children:[e.jsx(Se.Save,{className:"h-3.5 w-3.5"}),"Save to Library"]})})}function Re({className:r}){const a=m.useQueryClient(),[o,n]=C.useState(!1),i=m.useSelectedVisual(),c=s.useEditorStore(k=>k.frame),f=s.useDashboardStore(k=>k.selectedSheetId),h=s.useDashboardStore(k=>k.dashboard),{updateFrame:p,setIsVisualEditing:v}=s.useDashboardActions(),{getUpdatedFrame:g}=se(),x=m.useUpdateVisualMutation(),S=m.useResolveExistingFrameSemanticExecutionPayload(),w=async()=>{if(!f){m.ue.error("No sheet selected");return}const k=(c==null?void 0:c.visualId)||(i==null?void 0:i.id);if(!k){m.ue.error("No visual to update");return}n(!0);try{const E=g();if(!pe(E)){n(!1);return}const V={...E,visualId:k},U=m.findDashboardFrameById(h,V.id),H=await S(V,{previousFrame:U});await x.mutateAsync({visualId:k,data:{frameObject:E}}),p(f,V,{semanticExecutionPayload:H}),a.invalidateQueries({queryKey:["visuals"]}),a.invalidateQueries({queryKey:["visual",k]}),m.ue.success("Saved to library and applied locally"),setTimeout(()=>{v(!1)},300)}catch(E){console.error("Failed to save and apply:",E),m.ue.error(E instanceof Error?E.message:"Failed to save and apply changes")}finally{n(!1)}};return e.jsx(s.Button,{onClick:w,className:r,size:"xs",variant:"default",disabled:o,children:o?e.jsxs(e.Fragment,{children:[e.jsx(s.LoaderCircle,{className:"h-3.5 w-3.5 animate-spin"}),"Saving..."]}):e.jsxs(e.Fragment,{children:[e.jsx(Se.Save,{className:"h-3.5 w-3.5"}),"Save & Apply"]})})}function Qe({className:r}){const{setTempQueryData:a,setSqlGen:o}=s.useEditorActions(),n=m.useQueryClient(),i=s.useEditorStore(x=>x.tempQueryData),c=s.useEditorStore(x=>x.onClose),f=s.useEditorStore(x=>x.card),h=ue(),p=C.useMemo(()=>h!==f.type?{...f,type:h}:f,[f,h]),{queryKey:v}=m.useEditorCardQuery(p);function g(){if(i){const{queryKey:x,queryData:S}=i;x&&S&&n.setQueryData(x,S)}o({}),c==null||c()}return e.jsxs(s.Button,{onClick:g,className:r,size:"xs",variant:"outline",children:[e.jsx(s.X,{className:"h-3.5 w-3.5"}),"Close"]})}function Pe({label:r="Clear",variant:a="secondary",className:o}={}){const{setTempQueryData:n}=s.useEditorActions(),i=m.useQueryClient(),c=s.useEditorStore(M=>M.tempQueryData),f=s.useEditorStore(M=>M.card),h=ue(),p=C.useMemo(()=>h!==f.type?{...f,type:h}:f,[f,h]),{queryKey:v}=m.useEditorCardQuery(p),{setCardSql:g,setSqlGen:x,setCardPython:S,setCardCustomCfg:w,setCardPreferences:k,clearQueryConfig:E,setCardConfig:V,setCardType:U,setFrame:H,setCard:W,setActiveTabCardId:Y}=s.useEditorActions();function J(){var K,G,_,z;const M=i.getQueryData(v);c!=null&&c.queryData||n({queryKey:v,queryData:M}),i.setQueryData(v,null),i.removeQueries({queryKey:v,exact:!0}),g(""),x({}),E(),V(void 0),S(""),w(""),k({});const l=s.useEditorStore.getState().frame,D=s.useEditorStore.getState().card,T=m.findCustomVisualConfigCard(l,D),q=((K=T==null?void 0:T.customCardPreferences)==null?void 0:K.visualType)==="multiple"||!!((G=T==null?void 0:T.customCardPreferences)!=null&&G.dataInputCardIds)||(((_=T==null?void 0:T.customCardPreferences)==null?void 0:_.minInputs)||0)>1||(((z=T==null?void 0:T.customCardPreferences)==null?void 0:z.maxInputs)||0)>1,Q=Oe(D,q);H({...l,cards:l.cards.map($=>$.id===Q.id?Q:$)}),Y(Q.id),W(Q),q||U("bar")}return e.jsxs(s.Button,{onClick:J,className:o,size:"xs",variant:a,children:[e.jsx(s.X,{className:"h-3.5 w-3.5"}),r]})}function we(r){const{control:a,onChange:o}=r;return e.jsxs("div",{className:"flex flex-col gap-1.5",children:[e.jsx(s.Label,{className:"text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground",children:"Label"}),e.jsx(s.Input,{size:"xs",value:a.label,placeholder:"Control label",onChange:n=>o(n.target.value)})]})}function $e(r){const{currentStep:a,labels:o}=r;return e.jsx("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:e.jsx("div",{className:"flex flex-wrap items-center gap-2 sm:gap-2.5",children:o.map((n,i)=>{const c=i+1,f=c===a,h=c<a;return e.jsxs(C.Fragment,{children:[e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("span",{className:s.cn("flex h-5 w-5 items-center justify-center rounded-full border text-[10px] font-medium tabular-nums",f?"border-foreground bg-foreground text-background":h?"border-foreground/30 bg-foreground/10 text-foreground":"border-border/60 bg-background text-muted-foreground"),children:c}),e.jsx("span",{className:s.cn("text-[12px]",f?"font-medium text-foreground":"text-muted-foreground"),children:n})]}),i<o.length-1?e.jsx("span",{className:"h-px w-4 bg-border/60 sm:w-6","aria-hidden":"true"}):null]},n)})})})}function re(r){const{secondary:a,tertiary:o,primary:n}=r;return e.jsxs("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:[a,o,n]})}function He(r){const{control:a,scope:o,detail:n}=r;return e.jsxs("div",{className:"flex items-start gap-2.5 rounded-control border border-border/60 bg-muted/30 px-3 py-2.5",children:[e.jsx(m.CircleCheck,{className:"mt-0.5 h-3.5 w-3.5 shrink-0 text-foreground"}),e.jsxs("div",{className:"min-w-0 space-y-0.5",children:[e.jsx("div",{className:"text-[13px] font-medium text-foreground",children:a.label}),e.jsxs("div",{className:"text-[12px] text-muted-foreground",children:[s.getFriendlyTypeOption(a.type).label," ·"," ",s.getControlOptionPreview(a)," ·"," ",s.getPlacementLabel(o,a.placement)]}),n?e.jsx("div",{className:"text-[12px] text-muted-foreground",children:n}):null]})]})}function ye(r){const{control:a,defaultValue:o,availableFieldChoices:n,availableMetricChoices:i,previewControlDefinitions:c,previewControlValues:f,onControlChange:h,onLabelChange:p,onDefaultValueChange:v,onBack:g,onNext:x,nextDisabled:S}=r;return e.jsxs("div",{className:"space-y-3",children:[e.jsx(we,{control:a,onChange:p}),e.jsx(m.ControlDefinitionOptionsEditor,{control:a,availableFieldChoices:n,availableMetricChoices:i,previewControlDefinitions:c,previewControlValues:f,controlLifecycle:"create",onChange:h}),e.jsx(m.ControlDefaultValueEditor,{control:a,value:o,onChange:v,allowNoDefault:!0,allowCardDefault:!0,hint:"This is the value viewers will see first.",previewControlDefinitions:c,previewControlValues:f}),e.jsx(re,{secondary:e.jsx(s.Button,{type:"button",variant:"outline",size:"xs",onClick:g,children:"Back"}),primary:e.jsx(s.Button,{type:"button",size:"xs",onClick:x,disabled:S,children:"Next"})})]})}const Ye=new Set(["grain_selector","aggregation_selector","field_selector","metric_selector"]);function ve(r){const{text:a,ariaLabel:o}=r,[n,i]=C.useState(!1);return e.jsxs("button",{type:"button","aria-label":o,onClick:async()=>{try{await navigator.clipboard.writeText(a),i(!0),setTimeout(()=>i(!1),1200)}catch(c){console.error("Failed to copy",c)}},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:[e.jsx("code",{className:"min-w-0 truncate font-mono text-[12px] text-foreground",children:a}),e.jsx("span",{className:"shrink-0 text-[11px] text-muted-foreground opacity-0 transition-opacity group-hover:opacity-100",children:n?"Copied":"Click to copy"})]})}function Ce(r){const{control:a,scope:o,createdReference:n,explorerContent:i,sqlDescription:c,summaryDetail:f,onBack:h,onCancel:p,onDone:v}=r,g=Ye.has(a.type),x=n.match(/\[\[param\.(.+?)\]\]/),S=x?`{{ param('${x[1]}') }}`:"";return e.jsxs("div",{className:"space-y-4",children:[e.jsx(He,{control:a,scope:o,detail:f}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("p",{className:"text-[13px] font-medium text-foreground",children:"How cards use this control"}),e.jsxs("div",{className:"divide-y divide-border/60 overflow-hidden rounded-control border border-border/60",children:[g?e.jsxs("div",{className:"space-y-1 px-3 py-2.5",children:[e.jsx("p",{className:"text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground",children:"Explorer cards"}),e.jsx("div",{className:"text-[12px] text-muted-foreground",children:i})]}):null,e.jsxs("div",{className:"space-y-1.5 px-3 py-2.5",children:[e.jsx("p",{className:"text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground",children:"SQL cards"}),e.jsx(ve,{text:n,ariaLabel:"Copy SQL control reference"}),S?e.jsx(ve,{text:S,ariaLabel:"Copy Jinja control reference"}):null,e.jsxs("p",{className:"text-[12px] text-muted-foreground",children:[c," ",e.jsx("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"}),"."]})]})]})]}),e.jsx(re,{secondary:e.jsx(s.Button,{type:"button",variant:"outline",size:"xs",onClick:h,children:"Back"}),tertiary:e.jsx(s.Button,{type:"button",variant:"outline",size:"xs",onClick:p,children:"Cancel"}),primary:e.jsx(s.Button,{type:"button",size:"xs",onClick:v,children:"Done"})})]})}function Ke(r){const a=s.createBlankControl(r.scope,r.existingControls,r.reservedIds),o=r.type===a.type?{...a,label:s.DEFAULT_LABEL_BY_TYPE[r.type]}:{...s.applyControlTypeChange({controls:[{...a,label:s.DEFAULT_LABEL_BY_TYPE[r.type]}],controlId:a.id,nextType:r.type}).controls[0],label:s.DEFAULT_LABEL_BY_TYPE[r.type]};return{step:2,control:o,defaultValue:s.getDefaultValueForType(o,void 0)}}function We({scope:r,controls:a,reservedControlIds:o,defaultValues:n,onChange:i,emptyMessage:c,initialCreateFlow:f=!1,usageByControlId:h,availableFieldChoices:p,availableMetricChoices:v,structuralParticipants:g,structuralParticipantIdsByControlId:x,card:S,allowedControlTypes:w,onCreateFlowActiveChange:k,onCreateFlowComplete:E}){const V=C.useMemo(()=>new Set(o||[]),[o]),U=s.getPlacementOptionsForScope(r),H=s.getDefaultPlacement(r),[W,Y]=C.useState(null),[J,M]=C.useState(null),[l,D]=C.useState(()=>f?{step:1,control:s.createBlankControl(r,a,Array.from(V))}:null),T=C.useRef({}),q=C.useRef(void 0),Q=C.useRef(f),K=C.useMemo(()=>{const t=s.getFriendlyControlTypeOptions({scope:r,card:S});if(!w)return t;const u=new Set(w);return t.filter(d=>u.has(d.value))},[w,S,r]),G=C.useCallback(t=>{const u=s.getFriendlyControlTypeOptions({scope:r,card:S,includeType:w?void 0:t});if(!w)return u;const d=new Set(w);return u.filter(b=>d.has(b.value))},[w,S,r]),_=C.useCallback(t=>r==="dashboard"&&(t==="field_selector"||t==="metric_selector"),[r]),z=C.useMemo(()=>l?s.getEligibleParticipantsForStructuralControl(g||[],l.control.type):[],[l,g]),$=C.useMemo(()=>{if(!l)return{fields:p||[],metrics:v||[]};if(!_(l.control.type))return{fields:p||[],metrics:v||[]};const t=l.selectedCardIds||[],u=s.getCompatibleStructuralChoiceCatalog({controlType:l.control.type,participants:g||[],selectedCardIds:t});return{fields:l.control.type==="field_selector"?u.choices.map(d=>({option:d,target:u.fieldTargetMap[d.value]})):[],metrics:l.control.type==="metric_selector"?u.choices.map(d=>({option:d,target:u.metricTargetMap[d.value]})):[]}},[p,v,l,_,g]);C.useEffect(()=>{k==null||k(!!l)},[l,k]),C.useEffect(()=>{const t=f&&!Q.current;Q.current=f,t&&(D({step:1,control:s.createBlankControl(r,a,Array.from(V))}),M(null),Y(null))},[a,f,V,r]);const ae=t=>{if(!_(t.type))return{fields:p||[],metrics:v||[]};const u=(x==null?void 0:x[t.id])||[];if(u.length===0)return{fields:p||[],metrics:v||[]};const d=s.getCompatibleStructuralChoiceCatalog({controlType:t.type,participants:g||[],selectedCardIds:u});return{fields:t.type==="field_selector"?d.choices.map(b=>({option:b,target:d.fieldTargetMap[b.value]})):[],metrics:t.type==="metric_selector"?d.choices.map(b=>({option:b,target:d.metricTargetMap[b.value]})):[]}},A=t=>{if(!_(t.control.type))return{nextControl:t.control,cardBindingsById:void 0};const u=(x==null?void 0:x[t.control.id])||[],d=s.getCompatibleStructuralChoiceCatalog({controlType:t.control.type,participants:g||[],selectedCardIds:t.nextSelectedCardIds}),b=s.reconcileStructuralControlChoices({control:t.control,choices:d.choices}),j=Object.fromEntries(u.filter(N=>!t.nextSelectedCardIds.includes(N)).map(N=>[N,void 0]));return t.nextSelectedCardIds.length>0&&b.source.kind==="manual"&&b.source.options.length>0&&Object.assign(j,s.buildStructuralControlBindingsForParticipants({control:b,participants:g||[],selectedCardIds:t.nextSelectedCardIds})),{nextControl:b,cardBindingsById:j}},F=C.useCallback((t,u=n,d={type:"update"})=>{const b=t.map(j=>(s.resolveAuthoringControlDefaultValue({control:j,defaultValues:u}),s.syncSqlQueryControlExecutionRequirement(j)));i(b,u,d)},[n,i]),P=(t,u)=>{const d=a.find(L=>L.id===t);let b=a.map(L=>L.id!==t?L:u(L));const j=b.find(L=>L.id===t);let N,y;if(j&&r==="dashboard"&&(j.type==="field_selector"||j.type==="metric_selector")){const L=(x==null?void 0:x[j.id])||[],Z=A({control:j,nextSelectedCardIds:L});b=b.map(X=>X.id===t?Z.nextControl:X),N=Z.cardBindingsById,y=[j.id]}else if(d&&r==="dashboard"&&(d.type==="field_selector"||d.type==="metric_selector")){const L=(x==null?void 0:x[d.id])||[];N=Object.fromEntries(L.map(Z=>[Z,void 0])),y=[d.id]}const I=b.find(L=>L.id===t);let O=n;if(d&&I){const L=s.resolveAuthoringControlDefaultValue({control:d,defaultValues:n});d.source.kind==="manual"&&I.source.kind==="sql_query"&&(T.current[t]=L);const Z=L===void 0&&d.source.kind==="sql_query"&&I.source.kind==="manual"?T.current[t]:L,X=s.getNextEditedControlDefaultValue({previousControl:d,nextControl:I,currentDefaultValue:Z});I.source.kind==="manual"&&(T.current[t]=X),n&&(O={...n},X===void 0?delete O[t]:O[t]=X),b=b.map(ge=>ge.id===t?{...I,defaultValue:X}:ge)}F(b,O,{type:"update",cardBindingsById:N,affectedBindingControlIds:y})},B=(t,u)=>{if(!u.trim())return;const d=m.normalizeDashboardInputVariableName(u);if(d===t||V.has(d)||a.some(N=>N.id===d&&N.id!==t))return;const b=a.map(N=>N.id===t?{...N,id:d}:N);if(!n){F(b,void 0,{type:"rename",oldId:t,newId:d});return}const j={...n};Object.prototype.hasOwnProperty.call(j,t)&&(j[d]=j[t],delete j[t]),F(b,j,{type:"rename",oldId:t,newId:d})},ne=t=>{const u=a.filter(b=>b.id!==t);if(!n){F(u,void 0,{type:"remove",controlId:t});return}const d={...n};delete d[t],F(u,d,{type:"remove",controlId:t})},te=C.useCallback(()=>{q.current=void 0,D({step:1,control:s.createBlankControl(r,a,Array.from(V))}),M(null),Y(null)},[a,V,r]),R=t=>{D(u=>u&&(()=>{const d=t(u.control);u.control.source.kind==="manual"&&d.source.kind==="sql_query"&&(q.current=u.defaultValue);const b=u.defaultValue===void 0&&u.control.source.kind==="sql_query"&&d.source.kind==="manual"?q.current:u.defaultValue,j=s.getNextEditedControlDefaultValue({previousControl:u.control,nextControl:d,currentDefaultValue:b});return d.source.kind==="manual"&&(q.current=j),{...u,control:d,defaultValue:j}})())},ee=t=>{D(u=>u&&(u.control.source.kind==="manual"&&(q.current=t),{...u,defaultValue:t}))},oe=(()=>{if(!l)return!1;if(l.step===2&&_(l.control.type))return(l.selectedCardIds||[]).length>0;if(l.step!==2&&l.step!==3||!l.control.label.trim())return!1;const u=l.control.source.kind==="sql_query"?l.control:s.ensureManualSource(l.control);if(u.source.kind==="manual"&&(s.needsManualOptions(u)&&u.source.options.length===0||u.source.options.some(b=>b.label.trim().length===0||b.value.trim().length===0)))return!1;if(u.source.kind==="sql_query"){const{connectionId:d,sql:b,valueColumn:j}=u.source;return d.trim().length>0&&b.trim().length>0&&j.trim().length>0}return s.hasConcreteDefaultValue(s.getDefaultValueForType(u,l.defaultValue))})(),me=()=>{var N;if(!l)return;const t=s.ensureManualSource(l.control),u=s.deriveUniqueControlId({label:t.label,fallbackId:t.id,existingControls:a,reservedIds:Array.from(V)}),d={...t,id:u},b=r==="dashboard"&&(d.type==="field_selector"||d.type==="metric_selector")&&((N=l.selectedCardIds)!=null&&N.length)?s.buildStructuralControlBindingsForParticipants({control:d,participants:g||[],selectedCardIds:l.selectedCardIds}):void 0,j=s.getDefaultValueForType(d,l.defaultValue);D({step:r==="dashboard"&&(d.type==="field_selector"||d.type==="metric_selector")?4:3,control:d,defaultValue:j,createdControlId:u,selectedCardIds:l.selectedCardIds,cardBindingsById:b})},le=C.useCallback(()=>{D(null)},[]),fe=C.useCallback(()=>{if(!(l!=null&&l.createdControlId)){D(null);return}const t=l.control,u=l.createdControlId,d=s.getDefaultValueForType(t,l.defaultValue);if(n){const b={...n};d===void 0?delete b[u]:b[u]=d,F([...a,{...t,defaultValue:d}],b,{type:"add",cardBindingsById:l.cardBindingsById})}else F([...a,{...t,defaultValue:d}],void 0,{type:"add",cardBindingsById:l.cardBindingsById});M(u),D(null),E==null||E()},[a,l,n,F,E]),De=l?_(l.control.type)?["Choose type","Select cards","Configure","Finish"]:["Choose type","Configure","Finish"]:[],he=l!=null&&l.createdControlId?`[[param.${l.createdControlId}]]`:l?`[[param.${s.slugifyControlValue(l.control.label)||l.control.id}]]`:"",ie=s.buildAuthoringPreviewControlValues({controls:a,defaultValues:n}),de=l?[...a,l.control]:a,xe=l?s.buildAuthoringPreviewControlValues({controls:de,defaultValues:n,overrides:[{controlId:l.control.id,value:l.defaultValue}]}):ie;return e.jsxs("div",{className:"space-y-4",children:[l?e.jsxs("div",{className:"space-y-4 pb-1",children:[e.jsx($e,{currentStep:l.step,labels:De}),l.step===1&&(()=>{const t=new Set(["grain_selector","aggregation_selector","field_selector","metric_selector"]),u=new Set(["date","text"]),d=K.filter(N=>!t.has(N.value)&&!u.has(N.value)),b=K.filter(N=>t.has(N.value)),j=N=>e.jsxs("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:()=>D(Ke({scope:r,existingControls:a,reservedIds:Array.from(V),type:N.value})),children:[e.jsx("div",{className:"text-[13px] font-medium text-foreground",children:N.label}),e.jsx("p",{className:"mt-0.5 text-[12px] text-muted-foreground",children:N.description})]},N.value);return e.jsxs("div",{className:"space-y-4",children:[r==="card"&&(S==null?void 0:S.sql)==null?e.jsx("p",{className:"text-[12px] text-muted-foreground",children:"Explorer cards support displayed metric, group by field, aggregation, and time grain controls here."}):null,d.length>0&&e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("p",{className:"text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground",children:"Input controls"}),e.jsx("div",{className:"grid gap-1.5 sm:grid-cols-2",children:d.map(j)})]}),b.length>0&&e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("p",{className:"text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground",children:"Data-driven controls"}),e.jsx("div",{className:"grid gap-1.5 sm:grid-cols-2",children:b.map(j)})]}),e.jsx(re,{secondary:e.jsx(s.Button,{type:"button",variant:"outline",size:"xs",onClick:le,children:"Back to controls"})})]})})(),l.step===2&&_(l.control.type)&&e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"space-y-3",children:[e.jsx(we,{control:l.control,onChange:t=>R(u=>({...u,label:t}))}),e.jsx("p",{className:"text-[12px] text-muted-foreground",children:"Choose which cards should respond to this shared control."})]}),z.length===0?e.jsx("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."}):e.jsx("div",{className:"space-y-1 rounded-control border border-border/60 bg-background p-2",children:z.map(t=>{const u=(l.selectedCardIds||[]).includes(t.cardId);return e.jsxs("label",{className:"flex items-start gap-2 rounded-control px-1.5 py-1 text-[13px] hover:bg-muted/40",children:[e.jsx(m.Checkbox,{checked:u,onCheckedChange:d=>D(b=>b&&{...b,selectedCardIds:d===!0?[...b.selectedCardIds||[],t.cardId]:(b.selectedCardIds||[]).filter(j=>j!==t.cardId)})}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"font-medium text-foreground",children:t.title}),e.jsx("div",{className:"text-[12px] text-muted-foreground",children:l.control.type==="field_selector"?`${t.fieldChoices.length} compatible group-by fields`:`${t.metricChoices.length} compatible metrics`})]})]},t.cardId)})}),e.jsx(re,{secondary:e.jsx(s.Button,{type:"button",variant:"outline",size:"xs",onClick:()=>D(t=>t&&{...t,step:1,selectedCardIds:[]}),children:"Back"}),primary:e.jsx(s.Button,{type:"button",size:"xs",onClick:()=>D(t=>t&&{...t,step:3}),disabled:!oe,children:"Next"})})]}),l.step===2&&!_(l.control.type)&&e.jsx(ye,{control:l.control,defaultValue:l.defaultValue,availableFieldChoices:$.fields,availableMetricChoices:$.metrics,previewControlDefinitions:de,previewControlValues:xe,onControlChange:t=>R(()=>t),onLabelChange:t=>R(u=>({...u,label:t})),onDefaultValueChange:ee,onBack:()=>D(t=>t&&{...t,step:1}),onNext:me,nextDisabled:!oe}),l.step===3&&_(l.control.type)&&e.jsx(ye,{control:l.control,defaultValue:l.defaultValue,availableFieldChoices:$.fields,availableMetricChoices:$.metrics,previewControlDefinitions:de,previewControlValues:xe,onControlChange:t=>R(()=>t),onLabelChange:t=>R(u=>({...u,label:t})),onDefaultValueChange:ee,onBack:()=>D(t=>t&&{...t,step:2}),onNext:me,nextDisabled:!oe}),l.step===3&&!_(l.control.type)&&e.jsx(Ce,{control:l.control,scope:r,createdReference:he,explorerContent:e.jsxs(e.Fragment,{children:["Open the card and use"," ",e.jsx("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:()=>D(t=>t&&{...t,step:2}),onCancel:le,onDone:fe}),l.step===4&&_(l.control.type)&&e.jsx(Ce,{control:l.control,scope:r,createdReference:he,summaryDetail:e.jsxs(e.Fragment,{children:["Used by ",(l.selectedCardIds||[]).length," selected card",(l.selectedCardIds||[]).length===1?"":"s"]}),explorerContent:e.jsx(e.Fragment,{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:()=>D(t=>t&&{...t,step:3}),onCancel:le,onDone:fe})]}):null,!l&&a.length===0?e.jsx("div",{className:"rounded-md border border-dashed p-3 text-sm text-muted-foreground",children:c}):null,!l&&a.map(t=>{const u=ae(t),d=h==null?void 0:h[t.id],b=s.resolveAuthoringControlDefaultValue({control:t,defaultValues:n}),j=J===t.id,N="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 e.jsxs("div",{className:"rounded-control border border-border/60",children:[e.jsxs("div",{className:"flex items-center gap-2 px-3 py-2.5",children:[e.jsxs("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:()=>M(y=>y===t.id?null:t.id),children:[j?e.jsx(s.ChevronDown,{className:"mt-0.5 h-3.5 w-3.5 shrink-0 text-muted-foreground"}):e.jsx(m.ChevronRight,{className:"mt-0.5 h-3.5 w-3.5 shrink-0 text-muted-foreground"}),e.jsxs("div",{className:"min-w-0",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-1.5",children:[e.jsx("span",{className:"truncate text-[13px] font-medium text-foreground",children:t.label||"Untitled control"}),e.jsx("span",{className:N,children:s.getFriendlyTypeOption(t.type).label}),e.jsx("span",{className:N,children:s.getPlacementLabel(r,t.placement)})]}),e.jsxs("div",{className:"mt-0.5 text-[12px] text-muted-foreground",children:[s.getControlOptionPreview(t),d!=null&&d.status?` · ${d.status}`:""]})]})]}),e.jsx(s.Button,{type:"button",size:"xs",variant:"ghost",className:"h-7 w-7 shrink-0 p-0 text-muted-foreground",onClick:()=>ne(t.id),"aria-label":`Remove ${t.label}`,children:e.jsx(m.Trash2,{className:"h-3.5 w-3.5"})})]}),j&&e.jsxs("div",{className:"space-y-4 border-t border-border/60 px-3 py-3",children:[e.jsxs("div",{className:"grid gap-3 md:grid-cols-3",children:[e.jsxs("div",{className:"flex flex-col gap-1.5",children:[e.jsx(s.Label,{className:"text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground",children:"Label"}),e.jsx(s.Input,{size:"xs",value:t.label,placeholder:"Control label",onChange:y=>P(t.id,I=>({...I,label:y.target.value}))})]}),e.jsxs("div",{className:"flex flex-col gap-1.5",children:[e.jsx(s.Label,{className:"text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground",children:"Type"}),e.jsxs(s.Select,{value:t.type,onValueChange:y=>{const I=s.applyControlTypeChange({controls:a,controlId:t.id,nextType:y,defaultValues:n});F(I.controls,I.defaultValues)},children:[e.jsx(s.SelectTrigger,{size:"xs",children:e.jsx(s.SelectValue,{})}),e.jsx(s.SelectContent,{children:G(t.type).map(y=>e.jsx(s.SelectItem,{value:y.value,children:y.label},y.value))})]})]}),e.jsxs("div",{className:"flex flex-col gap-1.5",children:[e.jsx(s.Label,{className:"text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground",children:"Show in"}),e.jsxs(s.Select,{value:t.placement||H,onValueChange:y=>P(t.id,I=>({...I,placement:y})),children:[e.jsx(s.SelectTrigger,{size:"xs",children:e.jsx(s.SelectValue,{})}),e.jsx(s.SelectContent,{children:U.map(y=>e.jsx(s.SelectItem,{value:y.value,children:y.label},y.value))})]})]})]}),_(t.type)?e.jsx(m.StructuralParticipantSelector,{type:t.type,participants:s.getEligibleParticipantsForStructuralControl(g||[],t.type).map(y=>({cardId:y.cardId,title:y.title,choiceCount:t.type==="field_selector"?y.fieldChoices.length:y.metricChoices.length})),selectedCardIds:(x==null?void 0:x[t.id])||[],onChange:y=>{const I=A({control:t,nextSelectedCardIds:y}),O=a.map(L=>L.id===t.id?I.nextControl:L);F(O,n,{type:"update",cardBindingsById:I.cardBindingsById})}}):null,e.jsx(m.ControlDefinitionOptionsEditor,{control:t,availableFieldChoices:u.fields,availableMetricChoices:u.metrics,previewControlDefinitions:a,previewControlValues:ie,controlLifecycle:"edit",onChange:y=>P(t.id,()=>y)}),t.initialValueStrategy==="saved_default"&&e.jsx(m.ControlDefaultValueEditor,{control:t,value:b,allowNoDefault:!0,allowCardDefault:!0,previewControlDefinitions:a,previewControlValues:ie,onChange:y=>{const I=a.map(O=>O.id===t.id?{...O,defaultValue:y}:O);if(t.source.kind==="manual"&&(T.current[t.id]=y),n){const O={...n};y===void 0?delete O[t.id]:O[t.id]=y,F(I,O);return}F(I,void 0)}}),e.jsxs(m.Collapsible,{open:W===t.id,onOpenChange:y=>Y(y?t.id:null),children:[e.jsx(m.CollapsibleTrigger,{asChild:!0,children:e.jsxs(s.Button,{type:"button",variant:"ghost",size:"xs",className:"-ml-2 gap-1 text-muted-foreground hover:text-foreground",children:[W===t.id?e.jsx(s.ChevronDown,{className:"h-3.5 w-3.5"}):e.jsx(m.ChevronRight,{className:"h-3.5 w-3.5"}),"Advanced"]})}),e.jsxs(m.CollapsibleContent,{className:"space-y-3 pt-2",children:[e.jsxs("div",{className:"grid gap-3 md:grid-cols-2",children:[e.jsxs("div",{className:"flex flex-col gap-1.5",children:[e.jsx(s.Label,{className:"text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground",children:"Variable name"}),e.jsx(m.ControlIdInput,{controlId:t.id,onCommit:y=>B(t.id,y)},t.id)]}),e.jsxs("div",{className:"flex flex-col gap-1.5",children:[e.jsx(s.Label,{className:"text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground",children:"Initial value"}),e.jsxs(s.Select,{value:t.initialValueStrategy,onValueChange:y=>P(t.id,I=>({...I,initialValueStrategy:y})),children:[e.jsx(s.SelectTrigger,{size:"xs",children:e.jsx(s.SelectValue,{})}),e.jsx(s.SelectContent,{children:s.INITIAL_VALUE_STRATEGY_OPTIONS.map(y=>e.jsx(s.SelectItem,{value:y.value,children:y.label},y.value))})]})]})]}),e.jsx(m.ControlVisibilitySettings,{control:t,onChange:y=>P(t.id,()=>y)})]})]})]})]},t.id)}),!l&&e.jsxs(s.Button,{type:"button",variant:"outline",size:"xs",onClick:te,children:[e.jsx(m.Plus,{className:"h-3.5 w-3.5"}),"Add control"]})]})}function Ge(r){const{open:a,onOpenChange:o,initialCreateFlowActive:n=!1,dismissMode:i="passive"}=r,c=a!==void 0,[f,h]=C.useState(!1),[p,v]=C.useState(n),g=c?a:f,x=C.useCallback(k=>{!k&&p&&i==="passive"||(c||h(k),k||v(!1),o==null||o(k))},[c,p,i,o]),S=C.useCallback(()=>{c||h(!1),v(!1),o==null||o(!1)},[c,o]);C.useEffect(()=>{g||v(!1)},[g]);const w=C.useCallback(k=>{p&&k.preventDefault()},[p]);return{forceClose:S,handleOpenChange:x,isCreateFlowActive:p,preventPassiveDismissDuringCreate:w,resolvedOpen:g,setIsCreateFlowActive:v}}exports.ControlDefinitionListEditor=We;exports.EditorAcceptButton=Ue;exports.EditorCancelButton=Qe;exports.EditorClearButton=Pe;exports.Library=je;exports.Link2=ke;exports.Rows3=Fe;exports.SendHorizontal=Ie;exports.VisualBadge=qe;exports.VisualSaveAndApplyButton=Re;exports.VisualSaveButton=ze;exports.flushPendingEditorDrafts=Ne;exports.registerPendingEditorDraftFlusher=Te;exports.useCreateFlowOverlayState=Ge;exports.useEffectiveEditorCardType=ue;exports.useSyncLegacyEditorState=Ve;exports.useVisualUtils=se;
21
+ */const Ie=s.createLucideIcon("SendHorizontal",[["path",{d:"M3.714 3.048a.498.498 0 0 0-.683.627l2.843 7.627a2 2 0 0 1 0 1.396l-2.842 7.627a.498.498 0 0 0 .682.627l18-8.5a.5.5 0 0 0 0-.904z",key:"117uat"}],["path",{d:"M6 12h16",key:"s4cdu5"}]]);function Ve(r){const[a,o]=C.useState(null),[n,i]=C.useState(null),c=m.useEnsureReactGlobals();return C.useEffect(()=>{if(!r||r.trim()===""){o(null),i(null);return}if(!c)return;(async()=>{try{if(!r.startsWith("http://")&&!r.startsWith("https://"))throw new Error(`Invalid URL format: ${r}`);try{new URL(r)}catch{throw new Error(`Invalid URL: ${r}`)}const p=`${r.endsWith("/")?r:`${r}/`}index.js`;try{if(!(await fetch(p,{method:"HEAD"})).ok)throw new Error(`Module not found at ${p}`)}catch{}const v=await import(p);if(typeof v.useChartStore!="function")throw new Error("useChartStore is not a function");o(()=>v.useChartStore),i(null)}catch(h){const p=h instanceof Error?h.message:"Unknown error";console.error("Failed to load remote chart store:",p),i(p),o(null)}})()},[r,c]),a}function Te(r,a){if(r.length===0)return"";const o=r.find(n=>{var i,c;return((i=n.customCardPreferences)==null?void 0:i.visualType)==="multiple"||!!((c=n.customCardPreferences)!=null&&c.dataInputCardIds)});if(o)return o.id;if(a){const n=r.find(i=>i.id===a);if(n){const i=n.tabTitle;if(i=="All__Header")return r[0].id;if(i&&i.endsWith("__Header")){const f=i.split("__")[0],h=r.find(p=>p.tabTitle===f);return h?h.id:r[0].id}return a}}return r[0].id}const ce=new Set;function Le(r){return ce.add(r),()=>{ce.delete(r)}}function Ne(){ce.forEach(r=>{r()})}const Ae=r=>{if(!r||!("detailTableBackup"in r))return r;const{detailTableBackup:a,...o}=r;return o};async function be(r,a,o,n,i="Opening library visual..."){if(!a||!o)throw new Error("Missing auth token or visual ID");const c=["resource-by-id","visual",o],f=n.getQueryData(c);if(f)return console.log("Using cached visual data for:",o),{data:f,fromCache:!0};console.log("Fetching visual data from network for:",o);const h=m.ue.loading(i,{position:"top-center"});try{const p=await fetch(`${r}/management/v1/visuals/${o}`,{headers:{Authorization:`Bearer ${a}`}});if(!p.ok)throw new Error("Failed to load visual");const v=await p.json();return n.setQueryData(c,v),m.ue.dismiss(h),{data:v,fromCache:!1}}catch(p){throw m.ue.dismiss(h),p}}function Ee(r){if(typeof r=="string")return JSON.parse(r);if(typeof r=="object")return r;throw new Error("Invalid frame object format")}function _e(r,a){var c,f;const o=(r==null?void 0:r.frameObject)??((c=r==null?void 0:r.visual)==null?void 0:c.frameObject);if(!o)return!1;const n=Ee(o);if(!(n!=null&&n.cards)||n.cards.length===0)return!1;const i=(f=n.cards)==null?void 0:f.find(h=>h.id===n.activeCardId);return i?(m.setupEditorWithCard({...a,frame:n,card:i,visualId:(r==null?void 0:r.id)||n.visualId}),!0):!1}function Be(){const r=s.useEditorStore(n=>{var i;return((i=n.card.customCardPreferences)==null?void 0:i.url)||""}),a=Ve(r);return{getUpdatedFrame:C.useCallback(()=>{var V;Ne();const{frame:n,card:i,isDevMode:c,isShowingVisual:f,selectedSchemaName:h,selectedDatamodelId:p,selectedDatabaseName:v,selectedTableName:g,selectedConnectionId:x}=s.useEditorStore.getState(),S=i.sql,w=(V=a==null?void 0:a.getState())==null?void 0:V.settings,k=s.buildSavedEditorCard(i,{isDevMode:c,cardSql:S,isShowingVisual:f,selectedSchemaName:h,selectedDatamodelId:p,selectedDatabaseName:v,selectedTableName:g,selectedConnectionId:x,remoteChartSettings:w,stripConfig:Ae}),E=n.cards.map(U=>U.id===i.id?k:U);return{...n,cards:E,activeCardId:Te(E,n.activeCardId)}},[a])}}function se(){const{authToken:r,tokenProps:a}=m.useSemaphorContext(),o=m.useQueryClient(),n=m.useAddFrameWithFreshSemanticExecutionPayload(),i=m.useSelectedVisual(),{selectVisual:c}=m.useManagementActions(),{setFrame:f,setCard:h,setIsDevMode:p,initializeModeDrafts:v,setActiveTabCardId:g,updateDataSource:x,setQueryResultColumns:S,setSelectedConnectionId:w,setSelectedDatabaseName:k,setSelectedSchemaName:E,setSelectedTableName:V,setSelectedDatamodelId:U,setFilterValues:H,setInlineFilterValuesMap:W,setApplyFilters:Y,clearEditorContext:J}=s.useEditorActions(),{setIsDashboardEditing:M,setIsVisualEditing:l,setSelectedFrameId:D,clearSelectedFrameId:T}=s.useDashboardActions(),q=s.useDashboardStore(A=>A.selectedSheetId),Q=s.useDashboardStore(A=>A.selectedFrameId),K=s.useDashboardStore(A=>A.dashboard),G=s.useDashboardStore(A=>A.filterValues),_=s.useDashboardStore(A=>A.inlineFilterValuesMap),z=m.useVisualById((i==null?void 0:i.id)||"",{enabled:!!(i!=null&&i.id)&&!!(r!=null&&r.accessToken)}),$=C.useCallback(async A=>{try{c(A),T(),J();const{data:F,fromCache:P}=await be(a.apiServiceUrl,(r==null?void 0:r.accessToken)||"",A.id,o,"Opening library visual...");if(!_e(F,{setFrame:f,setCard:h,setIsDevMode:p,initializeModeDrafts:v,setActiveTabCardId:g,updateDataSource:x,setQueryResultColumns:S,setSelectedConnectionId:w,setSelectedDatabaseName:k,setSelectedSchemaName:E,setSelectedTableName:V,setSelectedDatamodelId:U,setFilterValues:H,setInlineFilterValuesMap:W,setApplyFilters:Y,setIsDashboardEditing:M,setIsVisualEditing:l,dashboard:K,selectedSheetId:q,selectedFrameId:Q,filterValues:G,inlineFilterValuesMap:_}))throw new Error("Failed to setup editor with visual data");return{success:!0,fromCache:P}}catch(F){return console.error("Error editing visual:",F),{success:!1,error:"Failed to load visual for editing"}}},[r==null?void 0:r.accessToken,a.apiServiceUrl,o,c,f,h,M,l,p,v,g,x,S,w,k,E,V,U,H,W,Y,J,T,K,q,Q,G,_]),ae=C.useCallback(async A=>{var P;const F=B=>(m.ue.error(B),{success:!1,error:B});try{if(c(A),!q)return F("No sheet selected. Please select a sheet first.");const{data:B,fromCache:ne}=await be(a.apiServiceUrl,(r==null?void 0:r.accessToken)||"",A.id,o,"Adding visual to dashboard..."),te=(B==null?void 0:B.frameObject)??((P=B==null?void 0:B.visual)==null?void 0:P.frameObject);if(!te)return F("Visual has no frame data");const R=Ee(te);if(!(R!=null&&R.cards)||R.cards.length===0)return F("Visual frame is malformed");const ee={...m.cloneLinkedFrameWithSourceMapping(R),visualId:A.id};return await n(q,ee,"end"),M(!0),D(ee.id),{success:!0,fromCache:ne}}catch(B){return console.error("Error adding visual:",B),F(B instanceof Error?B.message:"Failed to add visual to dashboard")}},[r==null?void 0:r.accessToken,a.apiServiceUrl,o,c,q,M,D,n]);return{visual:z.data,isLoading:z.isLoading,isError:z.isError,error:z.error,handleEditLibraryVisual:$,handleAddLibraryVisual:ae,getUpdatedFrame:Be().getUpdatedFrame,refetch:z.refetch}}function Me(){const r=s.useEditorStore(f=>f.card.dataSource),{setSelectedConnectionId:a,setSelectedDatabaseName:o,setSelectedSchemaName:n,setSelectedTableName:i,setSelectedDatamodelId:c}=s.useEditorActions();C.useEffect(()=>{var w;if(!r)return;const{tableName:f,schemaName:h,databaseName:p,connectionId:v}=m.extractTableMetadata(r),g=(w=r.selectedEntities)==null?void 0:w[0],S=(g==null?void 0:g.type)==="model"&&"id"in g?g.id:"";a(v||""),o(p||""),n(h||""),i(f||""),c(S)},[r,a,o,n,i,c])}function ue(){var p,v;const r=s.useEditorStore(g=>g.card),a=s.useEditorStore(g=>g.frame),o=C.useMemo(()=>m.findCustomVisualConfigCard(a,r),[a,r]),{manifest:n}=m.useCustomVisual(((p=o==null?void 0:o.customCardPreferences)==null?void 0:p.url)||""),i=C.useMemo(()=>{var g;return(g=n==null?void 0:n.visuals)==null?void 0:g.find(x=>{var S;return x.name===((S=o==null?void 0:o.customCardPreferences)==null?void 0:S.componentName)})},[n,(v=o==null?void 0:o.customCardPreferences)==null?void 0:v.componentName]),c=m.resolveMultiInputType(o,i),f=C.useMemo(()=>m.getCustomVisualInputCards({frame:a,configCard:o,isMultiInputVisual:c==="multiple"}),[a,o,c]),h=C.useMemo(()=>{const g=f.findIndex(x=>(x==null?void 0:x.id)===r.id);return g<0?-1:m.getSlotIndexForCard(r,g)},[f,r]);return C.useMemo(()=>!o||c!=="multiple"||h<0?r.type:m.getEffectiveCardTypeForSlot(r,h,i==null?void 0:i.slots)??r.type,[o,c,h,r,i==null?void 0:i.slots])}function qe({type:r,isLinked:a,className:o,showLabel:n=!1,showLocal:i=!1}){const c=s.useDashboardStore(E=>E.selectedFrameId),f=m.useManagementStore(E=>E.selectedVisual),h=s.useEditorStore(E=>E.frame);let p;if(r)p=r;else if(a!==void 0)p=a?"linked":"library";else if(!!!(h!=null&&h.visualId||f!=null&&f.id)&&c)p="local";else if(f&&!c)p="library";else if(h!=null&&h.visualId&&c)p="linked";else if(f!=null&&f.id&&c)p="library";else return null;if(p==="local"&&!i)return null;const v={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"},g={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."},x={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"},S={local:"fill-slate-50 dark:fill-slate-900",linked:"fill-purple-50 dark:fill-purple-950",library:"fill-blue-50 dark:fill-blue-950"},w={local:e.jsx("span",{className:"h-2 w-2 rounded-full bg-current/70"}),linked:e.jsx(ke,{className:"h-3.5 w-3.5"}),library:e.jsx(je,{className:"h-3.5 w-3.5"})},k={local:"Local",linked:"Linked",library:"Library"};return e.jsx(s.TooltipProvider,{children:e.jsxs(s.Tooltip,{delayDuration:300,children:[e.jsx(s.TooltipTrigger,{asChild:!0,children:e.jsxs(m.Badge,{variant:"outline",className:s.cn("cursor-help select-none transition-all",v[p],o),children:[w[p],n&&e.jsx("span",{className:"ml-1 text-xs font-medium leading-none",children:k[p]})]})}),e.jsxs(s.TooltipContent,{side:"bottom",className:s.cn("max-w-xs",x[p]),children:[e.jsx(s.TooltipArrow,{className:S[p]}),e.jsx("p",{children:g[p]})]})]})})}function Oe(r,a){return{...r,sql:"",python:"",config:void 0,customCfg:"",preferences:{},interactionConfig:void 0,linkedInteractionTargetOverrides:void 0,dynamicCardPreferences:void 0,customCardPreferences:a?r.customCardPreferences:void 0,visualizationMode:"builtin",type:a?r.type:"bar"}}function pe(r){const a=s.getDynamicFrameSaveIssue(r);return a?(m.ue.error(a),!1):!0}function Ue({className:r,variant:a="outline"}){const o=s.useEditorStore(c=>c.onSave),{getUpdatedFrame:n}=se();function i(){const c=n();pe(c)&&(o==null||o(c))}return e.jsxs(s.Button,{onClick:i,className:r,size:"xs",variant:a,children:[e.jsx(s.Check,{className:"h-3.5 w-3.5"}),"Accept"]})}function ze({className:r,variant:a="default"}){const o=m.useQueryClient(),[n,i]=C.useState(!1),{setIsVisualEditing:c}=s.useDashboardActions(),{getUpdatedFrame:f}=se(),h=m.useSelectedVisual(),p=s.useEditorStore(x=>x.frame),v=m.useUpdateVisualMutation(),g=()=>{const x=f();if(!pe(x))return;const S=(p==null?void 0:p.visualId)||(h==null?void 0:h.id);if(!S){m.ue.error("No visual to save");return}i(!0),v.mutate({visualId:S,data:{frameObject:x}},{onSuccess:()=>{i(!1),m.ue.success("Visual updated successfully"),o.invalidateQueries({queryKey:["resource-by-id","visual",S],exact:!0})},onError:()=>{i(!1),m.ue.error("Failed to update visual")}})};return e.jsx(s.Button,{onClick:g,className:r,size:"xs",variant:a,children:n?e.jsxs(e.Fragment,{children:[e.jsx(s.LoaderCircle,{className:"h-3.5 w-3.5 animate-spin"}),"Saving"]}):e.jsxs(e.Fragment,{children:[e.jsx(Se.Save,{className:"h-3.5 w-3.5"}),"Save to Library"]})})}function Re({className:r}){const a=m.useQueryClient(),[o,n]=C.useState(!1),i=m.useSelectedVisual(),c=s.useEditorStore(k=>k.frame),f=s.useDashboardStore(k=>k.selectedSheetId),h=s.useDashboardStore(k=>k.dashboard),{updateFrame:p,setIsVisualEditing:v}=s.useDashboardActions(),{getUpdatedFrame:g}=se(),x=m.useUpdateVisualMutation(),S=m.useResolveExistingFrameSemanticExecutionPayload(),w=async()=>{if(!f){m.ue.error("No sheet selected");return}const k=(c==null?void 0:c.visualId)||(i==null?void 0:i.id);if(!k){m.ue.error("No visual to update");return}n(!0);try{const E=g();if(!pe(E)){n(!1);return}const V={...E,visualId:k},U=m.findDashboardFrameById(h,V.id),H=await S(V,{previousFrame:U});await x.mutateAsync({visualId:k,data:{frameObject:E}}),p(f,V,{semanticExecutionPayload:H}),a.invalidateQueries({queryKey:["visuals"]}),a.invalidateQueries({queryKey:["visual",k]}),m.ue.success("Saved to library and applied locally"),setTimeout(()=>{v(!1)},300)}catch(E){console.error("Failed to save and apply:",E),m.ue.error(E instanceof Error?E.message:"Failed to save and apply changes")}finally{n(!1)}};return e.jsx(s.Button,{onClick:w,className:r,size:"xs",variant:"default",disabled:o,children:o?e.jsxs(e.Fragment,{children:[e.jsx(s.LoaderCircle,{className:"h-3.5 w-3.5 animate-spin"}),"Saving..."]}):e.jsxs(e.Fragment,{children:[e.jsx(Se.Save,{className:"h-3.5 w-3.5"}),"Save & Apply"]})})}function Qe({className:r}){const{setTempQueryData:a,setSqlGen:o}=s.useEditorActions(),n=m.useQueryClient(),i=s.useEditorStore(x=>x.tempQueryData),c=s.useEditorStore(x=>x.onClose),f=s.useEditorStore(x=>x.card),h=ue(),p=C.useMemo(()=>h!==f.type?{...f,type:h}:f,[f,h]),{queryKey:v}=m.useEditorCardQuery(p);function g(){if(i){const{queryKey:x,queryData:S}=i;x&&S&&n.setQueryData(x,S)}o({}),c==null||c()}return e.jsxs(s.Button,{onClick:g,className:r,size:"xs",variant:"outline",children:[e.jsx(s.X,{className:"h-3.5 w-3.5"}),"Close"]})}function Pe({label:r="Clear",variant:a="secondary",className:o}={}){const{setTempQueryData:n}=s.useEditorActions(),i=m.useQueryClient(),c=s.useEditorStore(M=>M.tempQueryData),f=s.useEditorStore(M=>M.card),h=ue(),p=C.useMemo(()=>h!==f.type?{...f,type:h}:f,[f,h]),{queryKey:v}=m.useEditorCardQuery(p),{setCardSql:g,setSqlGen:x,setCardPython:S,setCardCustomCfg:w,setCardPreferences:k,clearQueryConfig:E,setCardConfig:V,setCardType:U,setFrame:H,setCard:W,setActiveTabCardId:Y}=s.useEditorActions();function J(){var K,G,_,z;const M=i.getQueryData(v);c!=null&&c.queryData||n({queryKey:v,queryData:M}),i.setQueryData(v,null),i.removeQueries({queryKey:v,exact:!0}),g(""),x({}),E(),V(void 0),S(""),w(""),k({});const l=s.useEditorStore.getState().frame,D=s.useEditorStore.getState().card,T=m.findCustomVisualConfigCard(l,D),q=((K=T==null?void 0:T.customCardPreferences)==null?void 0:K.visualType)==="multiple"||!!((G=T==null?void 0:T.customCardPreferences)!=null&&G.dataInputCardIds)||(((_=T==null?void 0:T.customCardPreferences)==null?void 0:_.minInputs)||0)>1||(((z=T==null?void 0:T.customCardPreferences)==null?void 0:z.maxInputs)||0)>1,Q=Oe(D,q);H({...l,cards:l.cards.map($=>$.id===Q.id?Q:$)}),Y(Q.id),W(Q),q||U("bar")}return e.jsxs(s.Button,{onClick:J,className:o,size:"xs",variant:a,children:[e.jsx(s.X,{className:"h-3.5 w-3.5"}),r]})}function we(r){const{control:a,onChange:o}=r;return e.jsxs("div",{className:"flex flex-col gap-1.5",children:[e.jsx(s.Label,{className:"text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground",children:"Label"}),e.jsx(s.Input,{size:"xs",value:a.label,placeholder:"Control label",onChange:n=>o(n.target.value)})]})}function $e(r){const{currentStep:a,labels:o}=r;return e.jsx("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:e.jsx("div",{className:"flex flex-wrap items-center gap-2 sm:gap-2.5",children:o.map((n,i)=>{const c=i+1,f=c===a,h=c<a;return e.jsxs(C.Fragment,{children:[e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("span",{className:s.cn("flex h-5 w-5 items-center justify-center rounded-full border text-[10px] font-medium tabular-nums",f?"border-foreground bg-foreground text-background":h?"border-foreground/30 bg-foreground/10 text-foreground":"border-border/60 bg-background text-muted-foreground"),children:c}),e.jsx("span",{className:s.cn("text-[12px]",f?"font-medium text-foreground":"text-muted-foreground"),children:n})]}),i<o.length-1?e.jsx("span",{className:"h-px w-4 bg-border/60 sm:w-6","aria-hidden":"true"}):null]},n)})})})}function re(r){const{secondary:a,tertiary:o,primary:n}=r;return e.jsxs("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:[a,o,n]})}function He(r){const{control:a,scope:o,detail:n}=r;return e.jsxs("div",{className:"flex items-start gap-2.5 rounded-control border border-border/60 bg-muted/30 px-3 py-2.5",children:[e.jsx(m.CircleCheck,{className:"mt-0.5 h-3.5 w-3.5 shrink-0 text-foreground"}),e.jsxs("div",{className:"min-w-0 space-y-0.5",children:[e.jsx("div",{className:"text-[13px] font-medium text-foreground",children:a.label}),e.jsxs("div",{className:"text-[12px] text-muted-foreground",children:[s.getFriendlyTypeOption(a.type).label," ·"," ",s.getControlOptionPreview(a)," ·"," ",s.getPlacementLabel(o,a.placement)]}),n?e.jsx("div",{className:"text-[12px] text-muted-foreground",children:n}):null]})]})}function ye(r){const{control:a,defaultValue:o,availableFieldChoices:n,availableMetricChoices:i,previewControlDefinitions:c,previewControlValues:f,onControlChange:h,onLabelChange:p,onDefaultValueChange:v,onBack:g,onNext:x,nextDisabled:S}=r;return e.jsxs("div",{className:"space-y-3",children:[e.jsx(we,{control:a,onChange:p}),e.jsx(m.ControlDefinitionOptionsEditor,{control:a,availableFieldChoices:n,availableMetricChoices:i,previewControlDefinitions:c,previewControlValues:f,controlLifecycle:"create",onChange:h}),e.jsx(m.ControlDefaultValueEditor,{control:a,value:o,onChange:v,allowNoDefault:!0,allowCardDefault:!0,hint:"This is the value viewers will see first.",previewControlDefinitions:c,previewControlValues:f}),e.jsx(re,{secondary:e.jsx(s.Button,{type:"button",variant:"outline",size:"xs",onClick:g,children:"Back"}),primary:e.jsx(s.Button,{type:"button",size:"xs",onClick:x,disabled:S,children:"Next"})})]})}const Ye=new Set(["grain_selector","aggregation_selector","field_selector","metric_selector"]);function ve(r){const{text:a,ariaLabel:o}=r,[n,i]=C.useState(!1);return e.jsxs("button",{type:"button","aria-label":o,onClick:async()=>{try{await navigator.clipboard.writeText(a),i(!0),setTimeout(()=>i(!1),1200)}catch(c){console.error("Failed to copy",c)}},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:[e.jsx("code",{className:"min-w-0 truncate font-mono text-[12px] text-foreground",children:a}),e.jsx("span",{className:"shrink-0 text-[11px] text-muted-foreground opacity-0 transition-opacity group-hover:opacity-100",children:n?"Copied":"Click to copy"})]})}function Ce(r){const{control:a,scope:o,createdReference:n,explorerContent:i,sqlDescription:c,summaryDetail:f,onBack:h,onCancel:p,onDone:v}=r,g=Ye.has(a.type),x=n.match(/\[\[param\.(.+?)\]\]/),S=x?`{{ param('${x[1]}') }}`:"";return e.jsxs("div",{className:"space-y-4",children:[e.jsx(He,{control:a,scope:o,detail:f}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("p",{className:"text-[13px] font-medium text-foreground",children:"How cards use this control"}),e.jsxs("div",{className:"divide-y divide-border/60 overflow-hidden rounded-control border border-border/60",children:[g?e.jsxs("div",{className:"space-y-1 px-3 py-2.5",children:[e.jsx("p",{className:"text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground",children:"Explorer cards"}),e.jsx("div",{className:"text-[12px] text-muted-foreground",children:i})]}):null,e.jsxs("div",{className:"space-y-1.5 px-3 py-2.5",children:[e.jsx("p",{className:"text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground",children:"SQL cards"}),e.jsx(ve,{text:n,ariaLabel:"Copy SQL control reference"}),S?e.jsx(ve,{text:S,ariaLabel:"Copy Jinja control reference"}):null,e.jsxs("p",{className:"text-[12px] text-muted-foreground",children:[c," ",e.jsx("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"}),"."]})]})]})]}),e.jsx(re,{secondary:e.jsx(s.Button,{type:"button",variant:"outline",size:"xs",onClick:h,children:"Back"}),tertiary:e.jsx(s.Button,{type:"button",variant:"outline",size:"xs",onClick:p,children:"Cancel"}),primary:e.jsx(s.Button,{type:"button",size:"xs",onClick:v,children:"Done"})})]})}function Ke(r){const a=s.createBlankControl(r.scope,r.existingControls,r.reservedIds),o=r.type===a.type?{...a,label:s.DEFAULT_LABEL_BY_TYPE[r.type]}:{...s.applyControlTypeChange({controls:[{...a,label:s.DEFAULT_LABEL_BY_TYPE[r.type]}],controlId:a.id,nextType:r.type}).controls[0],label:s.DEFAULT_LABEL_BY_TYPE[r.type]};return{step:2,control:o,defaultValue:s.getDefaultValueForType(o,void 0)}}function We({scope:r,controls:a,reservedControlIds:o,defaultValues:n,onChange:i,emptyMessage:c,initialCreateFlow:f=!1,usageByControlId:h,availableFieldChoices:p,availableMetricChoices:v,structuralParticipants:g,structuralParticipantIdsByControlId:x,card:S,allowedControlTypes:w,onCreateFlowActiveChange:k,onCreateFlowComplete:E}){const V=C.useMemo(()=>new Set(o||[]),[o]),U=s.getPlacementOptionsForScope(r),H=s.getDefaultPlacement(r),[W,Y]=C.useState(null),[J,M]=C.useState(null),[l,D]=C.useState(()=>f?{step:1,control:s.createBlankControl(r,a,Array.from(V))}:null),T=C.useRef({}),q=C.useRef(void 0),Q=C.useRef(f),K=C.useMemo(()=>{const t=s.getFriendlyControlTypeOptions({scope:r,card:S});if(!w)return t;const u=new Set(w);return t.filter(d=>u.has(d.value))},[w,S,r]),G=C.useCallback(t=>{const u=s.getFriendlyControlTypeOptions({scope:r,card:S,includeType:w?void 0:t});if(!w)return u;const d=new Set(w);return u.filter(b=>d.has(b.value))},[w,S,r]),_=C.useCallback(t=>r==="dashboard"&&(t==="field_selector"||t==="metric_selector"),[r]),z=C.useMemo(()=>l?s.getEligibleParticipantsForStructuralControl(g||[],l.control.type):[],[l,g]),$=C.useMemo(()=>{if(!l)return{fields:p||[],metrics:v||[]};if(!_(l.control.type))return{fields:p||[],metrics:v||[]};const t=l.selectedCardIds||[],u=s.getCompatibleStructuralChoiceCatalog({controlType:l.control.type,participants:g||[],selectedCardIds:t});return{fields:l.control.type==="field_selector"?u.choices.map(d=>({option:d,target:u.fieldTargetMap[d.value]})):[],metrics:l.control.type==="metric_selector"?u.choices.map(d=>({option:d,target:u.metricTargetMap[d.value]})):[]}},[p,v,l,_,g]);C.useEffect(()=>{k==null||k(!!l)},[l,k]),C.useEffect(()=>{const t=f&&!Q.current;Q.current=f,t&&(D({step:1,control:s.createBlankControl(r,a,Array.from(V))}),M(null),Y(null))},[a,f,V,r]);const ae=t=>{if(!_(t.type))return{fields:p||[],metrics:v||[]};const u=(x==null?void 0:x[t.id])||[];if(u.length===0)return{fields:p||[],metrics:v||[]};const d=s.getCompatibleStructuralChoiceCatalog({controlType:t.type,participants:g||[],selectedCardIds:u});return{fields:t.type==="field_selector"?d.choices.map(b=>({option:b,target:d.fieldTargetMap[b.value]})):[],metrics:t.type==="metric_selector"?d.choices.map(b=>({option:b,target:d.metricTargetMap[b.value]})):[]}},A=t=>{if(!_(t.control.type))return{nextControl:t.control,cardBindingsById:void 0};const u=(x==null?void 0:x[t.control.id])||[],d=s.getCompatibleStructuralChoiceCatalog({controlType:t.control.type,participants:g||[],selectedCardIds:t.nextSelectedCardIds}),b=s.reconcileStructuralControlChoices({control:t.control,choices:d.choices}),j=Object.fromEntries(u.filter(N=>!t.nextSelectedCardIds.includes(N)).map(N=>[N,void 0]));return t.nextSelectedCardIds.length>0&&b.source.kind==="manual"&&b.source.options.length>0&&Object.assign(j,s.buildStructuralControlBindingsForParticipants({control:b,participants:g||[],selectedCardIds:t.nextSelectedCardIds})),{nextControl:b,cardBindingsById:j}},F=C.useCallback((t,u=n,d={type:"update"})=>{const b=t.map(j=>(s.resolveAuthoringControlDefaultValue({control:j,defaultValues:u}),s.syncSqlQueryControlExecutionRequirement(j)));i(b,u,d)},[n,i]),P=(t,u)=>{const d=a.find(L=>L.id===t);let b=a.map(L=>L.id!==t?L:u(L));const j=b.find(L=>L.id===t);let N,y;if(j&&r==="dashboard"&&(j.type==="field_selector"||j.type==="metric_selector")){const L=(x==null?void 0:x[j.id])||[],Z=A({control:j,nextSelectedCardIds:L});b=b.map(X=>X.id===t?Z.nextControl:X),N=Z.cardBindingsById,y=[j.id]}else if(d&&r==="dashboard"&&(d.type==="field_selector"||d.type==="metric_selector")){const L=(x==null?void 0:x[d.id])||[];N=Object.fromEntries(L.map(Z=>[Z,void 0])),y=[d.id]}const I=b.find(L=>L.id===t);let O=n;if(d&&I){const L=s.resolveAuthoringControlDefaultValue({control:d,defaultValues:n});d.source.kind==="manual"&&I.source.kind==="sql_query"&&(T.current[t]=L);const Z=L===void 0&&d.source.kind==="sql_query"&&I.source.kind==="manual"?T.current[t]:L,X=s.getNextEditedControlDefaultValue({previousControl:d,nextControl:I,currentDefaultValue:Z});I.source.kind==="manual"&&(T.current[t]=X),n&&(O={...n},X===void 0?delete O[t]:O[t]=X),b=b.map(ge=>ge.id===t?{...I,defaultValue:X}:ge)}F(b,O,{type:"update",cardBindingsById:N,affectedBindingControlIds:y})},B=(t,u)=>{if(!u.trim())return;const d=m.normalizeDashboardInputVariableName(u);if(d===t||V.has(d)||a.some(N=>N.id===d&&N.id!==t))return;const b=a.map(N=>N.id===t?{...N,id:d}:N);if(!n){F(b,void 0,{type:"rename",oldId:t,newId:d});return}const j={...n};Object.prototype.hasOwnProperty.call(j,t)&&(j[d]=j[t],delete j[t]),F(b,j,{type:"rename",oldId:t,newId:d})},ne=t=>{const u=a.filter(b=>b.id!==t);if(!n){F(u,void 0,{type:"remove",controlId:t});return}const d={...n};delete d[t],F(u,d,{type:"remove",controlId:t})},te=C.useCallback(()=>{q.current=void 0,D({step:1,control:s.createBlankControl(r,a,Array.from(V))}),M(null),Y(null)},[a,V,r]),R=t=>{D(u=>u&&(()=>{const d=t(u.control);u.control.source.kind==="manual"&&d.source.kind==="sql_query"&&(q.current=u.defaultValue);const b=u.defaultValue===void 0&&u.control.source.kind==="sql_query"&&d.source.kind==="manual"?q.current:u.defaultValue,j=s.getNextEditedControlDefaultValue({previousControl:u.control,nextControl:d,currentDefaultValue:b});return d.source.kind==="manual"&&(q.current=j),{...u,control:d,defaultValue:j}})())},ee=t=>{D(u=>u&&(u.control.source.kind==="manual"&&(q.current=t),{...u,defaultValue:t}))},oe=(()=>{if(!l)return!1;if(l.step===2&&_(l.control.type))return(l.selectedCardIds||[]).length>0;if(l.step!==2&&l.step!==3||!l.control.label.trim())return!1;const u=l.control.source.kind==="sql_query"?l.control:s.ensureManualSource(l.control);if(u.source.kind==="manual"&&(s.needsManualOptions(u)&&u.source.options.length===0||u.source.options.some(b=>b.label.trim().length===0||b.value.trim().length===0)))return!1;if(u.source.kind==="sql_query"){const{connectionId:d,sql:b,valueColumn:j}=u.source;return d.trim().length>0&&b.trim().length>0&&j.trim().length>0}return s.hasConcreteDefaultValue(s.getDefaultValueForType(u,l.defaultValue))})(),me=()=>{var N;if(!l)return;const t=s.ensureManualSource(l.control),u=s.deriveUniqueControlId({label:t.label,fallbackId:t.id,existingControls:a,reservedIds:Array.from(V)}),d={...t,id:u},b=r==="dashboard"&&(d.type==="field_selector"||d.type==="metric_selector")&&((N=l.selectedCardIds)!=null&&N.length)?s.buildStructuralControlBindingsForParticipants({control:d,participants:g||[],selectedCardIds:l.selectedCardIds}):void 0,j=s.getDefaultValueForType(d,l.defaultValue);D({step:r==="dashboard"&&(d.type==="field_selector"||d.type==="metric_selector")?4:3,control:d,defaultValue:j,createdControlId:u,selectedCardIds:l.selectedCardIds,cardBindingsById:b})},le=C.useCallback(()=>{D(null)},[]),fe=C.useCallback(()=>{if(!(l!=null&&l.createdControlId)){D(null);return}const t=l.control,u=l.createdControlId,d=s.getDefaultValueForType(t,l.defaultValue);if(n){const b={...n};d===void 0?delete b[u]:b[u]=d,F([...a,{...t,defaultValue:d}],b,{type:"add",cardBindingsById:l.cardBindingsById})}else F([...a,{...t,defaultValue:d}],void 0,{type:"add",cardBindingsById:l.cardBindingsById});M(u),D(null),E==null||E()},[a,l,n,F,E]),De=l?_(l.control.type)?["Choose type","Select cards","Configure","Finish"]:["Choose type","Configure","Finish"]:[],he=l!=null&&l.createdControlId?`[[param.${l.createdControlId}]]`:l?`[[param.${s.slugifyControlValue(l.control.label)||l.control.id}]]`:"",ie=s.buildAuthoringPreviewControlValues({controls:a,defaultValues:n}),de=l?[...a,l.control]:a,xe=l?s.buildAuthoringPreviewControlValues({controls:de,defaultValues:n,overrides:[{controlId:l.control.id,value:l.defaultValue}]}):ie;return e.jsxs("div",{className:"space-y-4",children:[l?e.jsxs("div",{className:"space-y-4 pb-1",children:[e.jsx($e,{currentStep:l.step,labels:De}),l.step===1&&(()=>{const t=new Set(["grain_selector","aggregation_selector","field_selector","metric_selector"]),u=new Set(["date","text"]),d=K.filter(N=>!t.has(N.value)&&!u.has(N.value)),b=K.filter(N=>t.has(N.value)),j=N=>e.jsxs("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:()=>D(Ke({scope:r,existingControls:a,reservedIds:Array.from(V),type:N.value})),children:[e.jsx("div",{className:"text-[13px] font-medium text-foreground",children:N.label}),e.jsx("p",{className:"mt-0.5 text-[12px] text-muted-foreground",children:N.description})]},N.value);return e.jsxs("div",{className:"space-y-4",children:[r==="card"&&(S==null?void 0:S.sql)==null?e.jsx("p",{className:"text-[12px] text-muted-foreground",children:"Explorer cards support displayed metric, group by field, aggregation, and time grain controls here."}):null,d.length>0&&e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("p",{className:"text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground",children:"Input controls"}),e.jsx("div",{className:"grid gap-1.5 sm:grid-cols-2",children:d.map(j)})]}),b.length>0&&e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("p",{className:"text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground",children:"Data-driven controls"}),e.jsx("div",{className:"grid gap-1.5 sm:grid-cols-2",children:b.map(j)})]}),e.jsx(re,{secondary:e.jsx(s.Button,{type:"button",variant:"outline",size:"xs",onClick:le,children:"Back to controls"})})]})})(),l.step===2&&_(l.control.type)&&e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"space-y-3",children:[e.jsx(we,{control:l.control,onChange:t=>R(u=>({...u,label:t}))}),e.jsx("p",{className:"text-[12px] text-muted-foreground",children:"Choose which cards should respond to this shared control."})]}),z.length===0?e.jsx("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."}):e.jsx("div",{className:"space-y-1 rounded-control border border-border/60 bg-background p-2",children:z.map(t=>{const u=(l.selectedCardIds||[]).includes(t.cardId);return e.jsxs("label",{className:"flex items-start gap-2 rounded-control px-1.5 py-1 text-[13px] hover:bg-muted/40",children:[e.jsx(m.Checkbox,{checked:u,onCheckedChange:d=>D(b=>b&&{...b,selectedCardIds:d===!0?[...b.selectedCardIds||[],t.cardId]:(b.selectedCardIds||[]).filter(j=>j!==t.cardId)})}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"font-medium text-foreground",children:t.title}),e.jsx("div",{className:"text-[12px] text-muted-foreground",children:l.control.type==="field_selector"?`${t.fieldChoices.length} compatible group-by fields`:`${t.metricChoices.length} compatible metrics`})]})]},t.cardId)})}),e.jsx(re,{secondary:e.jsx(s.Button,{type:"button",variant:"outline",size:"xs",onClick:()=>D(t=>t&&{...t,step:1,selectedCardIds:[]}),children:"Back"}),primary:e.jsx(s.Button,{type:"button",size:"xs",onClick:()=>D(t=>t&&{...t,step:3}),disabled:!oe,children:"Next"})})]}),l.step===2&&!_(l.control.type)&&e.jsx(ye,{control:l.control,defaultValue:l.defaultValue,availableFieldChoices:$.fields,availableMetricChoices:$.metrics,previewControlDefinitions:de,previewControlValues:xe,onControlChange:t=>R(()=>t),onLabelChange:t=>R(u=>({...u,label:t})),onDefaultValueChange:ee,onBack:()=>D(t=>t&&{...t,step:1}),onNext:me,nextDisabled:!oe}),l.step===3&&_(l.control.type)&&e.jsx(ye,{control:l.control,defaultValue:l.defaultValue,availableFieldChoices:$.fields,availableMetricChoices:$.metrics,previewControlDefinitions:de,previewControlValues:xe,onControlChange:t=>R(()=>t),onLabelChange:t=>R(u=>({...u,label:t})),onDefaultValueChange:ee,onBack:()=>D(t=>t&&{...t,step:2}),onNext:me,nextDisabled:!oe}),l.step===3&&!_(l.control.type)&&e.jsx(Ce,{control:l.control,scope:r,createdReference:he,explorerContent:e.jsxs(e.Fragment,{children:["Open the card and use"," ",e.jsx("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:()=>D(t=>t&&{...t,step:2}),onCancel:le,onDone:fe}),l.step===4&&_(l.control.type)&&e.jsx(Ce,{control:l.control,scope:r,createdReference:he,summaryDetail:e.jsxs(e.Fragment,{children:["Used by ",(l.selectedCardIds||[]).length," selected card",(l.selectedCardIds||[]).length===1?"":"s"]}),explorerContent:e.jsx(e.Fragment,{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:()=>D(t=>t&&{...t,step:3}),onCancel:le,onDone:fe})]}):null,!l&&a.length===0?e.jsx("div",{className:"rounded-md border border-dashed p-3 text-sm text-muted-foreground",children:c}):null,!l&&a.map(t=>{const u=ae(t),d=h==null?void 0:h[t.id],b=s.resolveAuthoringControlDefaultValue({control:t,defaultValues:n}),j=J===t.id,N="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 e.jsxs("div",{className:"rounded-control border border-border/60",children:[e.jsxs("div",{className:"flex items-center gap-2 px-3 py-2.5",children:[e.jsxs("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:()=>M(y=>y===t.id?null:t.id),children:[j?e.jsx(s.ChevronDown,{className:"mt-0.5 h-3.5 w-3.5 shrink-0 text-muted-foreground"}):e.jsx(m.ChevronRight,{className:"mt-0.5 h-3.5 w-3.5 shrink-0 text-muted-foreground"}),e.jsxs("div",{className:"min-w-0",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-1.5",children:[e.jsx("span",{className:"truncate text-[13px] font-medium text-foreground",children:t.label||"Untitled control"}),e.jsx("span",{className:N,children:s.getFriendlyTypeOption(t.type).label}),e.jsx("span",{className:N,children:s.getPlacementLabel(r,t.placement)})]}),e.jsxs("div",{className:"mt-0.5 text-[12px] text-muted-foreground",children:[s.getControlOptionPreview(t),d!=null&&d.status?` · ${d.status}`:""]})]})]}),e.jsx(s.Button,{type:"button",size:"xs",variant:"ghost",className:"h-7 w-7 shrink-0 p-0 text-muted-foreground",onClick:()=>ne(t.id),"aria-label":`Remove ${t.label}`,children:e.jsx(m.Trash2,{className:"h-3.5 w-3.5"})})]}),j&&e.jsxs("div",{className:"space-y-4 border-t border-border/60 px-3 py-3",children:[e.jsxs("div",{className:"grid gap-3 md:grid-cols-3",children:[e.jsxs("div",{className:"flex flex-col gap-1.5",children:[e.jsx(s.Label,{className:"text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground",children:"Label"}),e.jsx(s.Input,{size:"xs",value:t.label,placeholder:"Control label",onChange:y=>P(t.id,I=>({...I,label:y.target.value}))})]}),e.jsxs("div",{className:"flex flex-col gap-1.5",children:[e.jsx(s.Label,{className:"text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground",children:"Type"}),e.jsxs(s.Select,{value:t.type,onValueChange:y=>{const I=s.applyControlTypeChange({controls:a,controlId:t.id,nextType:y,defaultValues:n});F(I.controls,I.defaultValues)},children:[e.jsx(s.SelectTrigger,{size:"xs",children:e.jsx(s.SelectValue,{})}),e.jsx(s.SelectContent,{children:G(t.type).map(y=>e.jsx(s.SelectItem,{value:y.value,children:y.label},y.value))})]})]}),e.jsxs("div",{className:"flex flex-col gap-1.5",children:[e.jsx(s.Label,{className:"text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground",children:"Show in"}),e.jsxs(s.Select,{value:t.placement||H,onValueChange:y=>P(t.id,I=>({...I,placement:y})),children:[e.jsx(s.SelectTrigger,{size:"xs",children:e.jsx(s.SelectValue,{})}),e.jsx(s.SelectContent,{children:U.map(y=>e.jsx(s.SelectItem,{value:y.value,children:y.label},y.value))})]})]})]}),_(t.type)?e.jsx(m.StructuralParticipantSelector,{type:t.type,participants:s.getEligibleParticipantsForStructuralControl(g||[],t.type).map(y=>({cardId:y.cardId,title:y.title,choiceCount:t.type==="field_selector"?y.fieldChoices.length:y.metricChoices.length})),selectedCardIds:(x==null?void 0:x[t.id])||[],onChange:y=>{const I=A({control:t,nextSelectedCardIds:y}),O=a.map(L=>L.id===t.id?I.nextControl:L);F(O,n,{type:"update",cardBindingsById:I.cardBindingsById})}}):null,e.jsx(m.ControlDefinitionOptionsEditor,{control:t,availableFieldChoices:u.fields,availableMetricChoices:u.metrics,previewControlDefinitions:a,previewControlValues:ie,controlLifecycle:"edit",onChange:y=>P(t.id,()=>y)}),t.initialValueStrategy==="saved_default"&&e.jsx(m.ControlDefaultValueEditor,{control:t,value:b,allowNoDefault:!0,allowCardDefault:!0,previewControlDefinitions:a,previewControlValues:ie,onChange:y=>{const I=a.map(O=>O.id===t.id?{...O,defaultValue:y}:O);if(t.source.kind==="manual"&&(T.current[t.id]=y),n){const O={...n};y===void 0?delete O[t.id]:O[t.id]=y,F(I,O);return}F(I,void 0)}}),e.jsxs(m.Collapsible,{open:W===t.id,onOpenChange:y=>Y(y?t.id:null),children:[e.jsx(m.CollapsibleTrigger,{asChild:!0,children:e.jsxs(s.Button,{type:"button",variant:"ghost",size:"xs",className:"-ml-2 gap-1 text-muted-foreground hover:text-foreground",children:[W===t.id?e.jsx(s.ChevronDown,{className:"h-3.5 w-3.5"}):e.jsx(m.ChevronRight,{className:"h-3.5 w-3.5"}),"Advanced"]})}),e.jsxs(m.CollapsibleContent,{className:"space-y-3 pt-2",children:[e.jsxs("div",{className:"grid gap-3 md:grid-cols-2",children:[e.jsxs("div",{className:"flex flex-col gap-1.5",children:[e.jsx(s.Label,{className:"text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground",children:"Variable name"}),e.jsx(m.ControlIdInput,{controlId:t.id,onCommit:y=>B(t.id,y)},t.id)]}),e.jsxs("div",{className:"flex flex-col gap-1.5",children:[e.jsx(s.Label,{className:"text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground",children:"Initial value"}),e.jsxs(s.Select,{value:t.initialValueStrategy,onValueChange:y=>P(t.id,I=>({...I,initialValueStrategy:y})),children:[e.jsx(s.SelectTrigger,{size:"xs",children:e.jsx(s.SelectValue,{})}),e.jsx(s.SelectContent,{children:s.INITIAL_VALUE_STRATEGY_OPTIONS.map(y=>e.jsx(s.SelectItem,{value:y.value,children:y.label},y.value))})]})]})]}),e.jsx(m.ControlVisibilitySettings,{control:t,onChange:y=>P(t.id,()=>y)})]})]})]})]},t.id)}),!l&&e.jsxs(s.Button,{type:"button",variant:"outline",size:"xs",onClick:te,children:[e.jsx(m.Plus,{className:"h-3.5 w-3.5"}),"Add control"]})]})}function Ge(r){const{open:a,onOpenChange:o,initialCreateFlowActive:n=!1,dismissMode:i="passive"}=r,c=a!==void 0,[f,h]=C.useState(!1),[p,v]=C.useState(n),g=c?a:f,x=C.useCallback(k=>{!k&&p&&i==="passive"||(c||h(k),k||v(!1),o==null||o(k))},[c,p,i,o]),S=C.useCallback(()=>{c||h(!1),v(!1),o==null||o(!1)},[c,o]);C.useEffect(()=>{g||v(!1)},[g]);const w=C.useCallback(k=>{p&&k.preventDefault()},[p]);return{forceClose:S,handleOpenChange:x,isCreateFlowActive:p,preventPassiveDismissDuringCreate:w,resolvedOpen:g,setIsCreateFlowActive:v}}exports.ControlDefinitionListEditor=We;exports.EditorAcceptButton=Ue;exports.EditorCancelButton=Qe;exports.EditorClearButton=Pe;exports.Library=je;exports.Link2=ke;exports.Rows3=Fe;exports.SendHorizontal=Ie;exports.VisualBadge=qe;exports.VisualSaveAndApplyButton=Re;exports.VisualSaveButton=ze;exports.flushPendingEditorDrafts=Ne;exports.registerPendingEditorDraftFlusher=Le;exports.useCreateFlowOverlayState=Ge;exports.useEffectiveEditorCardType=ue;exports.useSyncLegacyEditorState=Me;exports.useVisualUtils=se;
@@ -1,9 +1,10 @@
1
- import { c as ge, G as M, H as ie, E as Le, u as Z, a7 as bt, W as yt, Y as vt, Z as xt, a as fe, $ as Ct, a8 as kt, B as q, e as St, X as et, f as tt, a9 as Nt, aa as wt, ab as pe, ac as je, ad as Qe, ae as Se, af as Ne, ag as Dt, ah as $e, ai as Et, aj as It, ak as me, al as Ft, am as Pe, g as He, an as at, ao as rt, ap as st, L as oe, a0 as nt, a1 as we, a2 as De, a3 as Ee, a4 as Ie, a5 as Fe, aq as ot, ar as Vt, as as Tt, at as We, au as _t, av as Ke, aw as Lt, ax as Ve } from "./switch-DmE_MY3L.js";
2
- import { useEffect as de, useMemo as P, useState as K, useCallback as R, useRef as Te, Fragment as At } from "react";
3
- import { aC as qt, aD as lt, aE as Mt, aF as Ot, aG as zt, aH as Ut, aI as Rt, aJ as Bt, u as jt, aK as ce, aL as Qt, aM as Ae, aN as $t, aO as Pt, aP as Ht, o as B, aQ as Wt, x as Kt, aR as Yt, aS as it, aT as dt, aU as Gt, aV as Jt, aW as Xt, ax as Ye, aX as Zt, aY as ea, aZ as ct, a_ as ut, a$ as ta, b0 as aa, b1 as ra, b2 as sa, b3 as na, aq as oa, b4 as la, b5 as ia } from "./index-DX_0OcRv.js";
1
+ import { c as ge, H as ie, E as Le, u as Z, G as M, a7 as bt, W as yt, Y as vt, Z as xt, a as fe, $ as Ct, a8 as kt, B as q, e as St, X as et, f as tt, a9 as Nt, aa as wt, ab as pe, ac as je, ad as Qe, ae as Se, af as Ne, ag as Dt, ah as $e, ai as Et, aj as It, ak as me, al as Ft, am as Pe, g as He, an as at, ao as rt, ap as st, L as oe, a0 as nt, a1 as we, a2 as De, a3 as Ee, a4 as Ie, a5 as Fe, aq as ot, ar as Vt, as as Tt, at as We, au as _t, av as Ke, aw as Lt, ax as Ve } from "./switch-C-fGjxjY.js";
2
+ import { useState as K, useEffect as de, useCallback as R, useMemo as P, useRef as Te, Fragment as At } from "react";
3
+ import { aC as qt, u as Mt, aD as ce, aE as Ot, aF as Ae, aG as zt, aH as Ut, aI as Rt, o as B, aJ as Bt, aK as jt, aL as lt, aM as Qt, aN as $t, aO as Pt, aP as Ht, aQ as Wt, x as Kt, aR as Yt, aS as it, aT as dt, aU as Gt, aV as Jt, aW as Xt, ax as Ye, aX as Zt, aY as ea, aZ as ct, a_ as ut, a$ as ta, b0 as aa, b1 as ra, b2 as sa, b3 as na, aq as oa, b4 as la, b5 as ia } from "./index-Bn866BBY.js";
4
4
  import { jsx as a, jsxs as m, Fragment as re } from "react/jsx-runtime";
5
5
  import "./index-CuHybtft.js";
6
- import { S as pt } from "./save-B-YfAPhu.js";
6
+ import "./catalog-field-grounding-DHXEI7cW.js";
7
+ import { S as pt } from "./save-Dh6gSC4x.js";
7
8
  /**
8
9
  * @license lucide-react v0.453.0 - ISC
9
10
  *
@@ -33,7 +34,7 @@ const ca = ge("Link2", [
33
34
  * This source code is licensed under the ISC license.
34
35
  * See the LICENSE file in the root directory of this source tree.
35
36
  */
36
- const Ia = ge("Rows3", [
37
+ const Fa = ge("Rows3", [
37
38
  ["rect", { width: "18", height: "18", x: "3", y: "3", rx: "2", key: "afitv7" }],
38
39
  ["path", { d: "M21 9H3", key: "1338ky" }],
39
40
  ["path", { d: "M21 15H3", key: "9uk58r" }]
@@ -44,7 +45,7 @@ const Ia = ge("Rows3", [
44
45
  * This source code is licensed under the ISC license.
45
46
  * See the LICENSE file in the root directory of this source tree.
46
47
  */
47
- const Fa = ge("SendHorizontal", [
48
+ const Va = ge("SendHorizontal", [
48
49
  [
49
50
  "path",
50
51
  {
@@ -54,78 +55,8 @@ const Fa = ge("SendHorizontal", [
54
55
  ],
55
56
  ["path", { d: "M6 12h16", key: "s4cdu5" }]
56
57
  ]);
57
- function Va() {
58
- const t = M((p) => p.card.dataSource), {
59
- setSelectedConnectionId: r,
60
- setSelectedDatabaseName: n,
61
- setSelectedSchemaName: s,
62
- setSelectedTableName: l,
63
- setSelectedDatamodelId: d
64
- } = ie();
65
- de(() => {
66
- var w;
67
- if (!t) return;
68
- const { tableName: p, schemaName: f, databaseName: u, connectionId: v } = qt(t), b = (w = t.selectedEntities) == null ? void 0 : w[0], x = (b == null ? void 0 : b.type) === "model" && "id" in b ? b.id : "";
69
- r(v || ""), n(u || ""), s(f || ""), l(p || ""), d(x);
70
- }, [
71
- t,
72
- r,
73
- n,
74
- s,
75
- l,
76
- d
77
- ]);
78
- }
79
- const _e = /* @__PURE__ */ new Set();
80
- function Ta(t) {
81
- return _e.add(t), () => {
82
- _e.delete(t);
83
- };
84
- }
85
- function ua() {
86
- _e.forEach((t) => {
87
- t();
88
- });
89
- }
90
- function mt() {
91
- var u, v;
92
- const t = M((b) => b.card), r = M((b) => b.frame), n = P(
93
- () => lt(r, t),
94
- [r, t]
95
- ), { manifest: s } = Mt(
96
- ((u = n == null ? void 0 : n.customCardPreferences) == null ? void 0 : u.url) || ""
97
- ), l = P(
98
- () => {
99
- var b;
100
- return (b = s == null ? void 0 : s.visuals) == null ? void 0 : b.find(
101
- (h) => {
102
- var x;
103
- return h.name === ((x = n == null ? void 0 : n.customCardPreferences) == null ? void 0 : x.componentName);
104
- }
105
- );
106
- },
107
- [s, (v = n == null ? void 0 : n.customCardPreferences) == null ? void 0 : v.componentName]
108
- ), d = Ot(n, l), p = P(
109
- () => zt({
110
- frame: r,
111
- configCard: n,
112
- isMultiInputVisual: d === "multiple"
113
- }),
114
- [r, n, d]
115
- ), f = P(() => {
116
- const b = p.findIndex(
117
- (h) => (h == null ? void 0 : h.id) === t.id
118
- );
119
- return b < 0 ? -1 : Ut(t, b);
120
- }, [p, t]);
121
- return P(() => !n || d !== "multiple" || f < 0 ? t.type : Rt(
122
- t,
123
- f,
124
- l == null ? void 0 : l.slots
125
- ) ?? t.type, [n, d, f, t, l == null ? void 0 : l.slots]);
126
- }
127
- function pa(t) {
128
- const [r, n] = K(null), [s, l] = K(null), d = Bt();
58
+ function ua(t) {
59
+ const [r, n] = K(null), [s, l] = K(null), d = qt();
129
60
  return de(() => {
130
61
  if (!t || t.trim() === "") {
131
62
  n(null), l(null);
@@ -163,7 +94,7 @@ function pa(t) {
163
94
  })();
164
95
  }, [t, d]), r;
165
96
  }
166
- function ma(t, r) {
97
+ function pa(t, r) {
167
98
  if (t.length === 0)
168
99
  return "";
169
100
  const n = t.find(
@@ -191,6 +122,17 @@ function ma(t, r) {
191
122
  }
192
123
  return t[0].id;
193
124
  }
125
+ const _e = /* @__PURE__ */ new Set();
126
+ function Ta(t) {
127
+ return _e.add(t), () => {
128
+ _e.delete(t);
129
+ };
130
+ }
131
+ function ma() {
132
+ _e.forEach((t) => {
133
+ t();
134
+ });
135
+ }
194
136
  const fa = (t) => {
195
137
  if (!t || !("detailTableBackup" in t))
196
138
  return t;
@@ -224,7 +166,7 @@ async function Ge(t, r, n, s, l = "Opening library visual...") {
224
166
  throw B.dismiss(f), u;
225
167
  }
226
168
  }
227
- function ft(t) {
169
+ function mt(t) {
228
170
  if (typeof t == "string")
229
171
  return JSON.parse(t);
230
172
  if (typeof t == "object")
@@ -236,13 +178,13 @@ function ha(t, r) {
236
178
  const n = (t == null ? void 0 : t.frameObject) ?? ((d = t == null ? void 0 : t.visual) == null ? void 0 : d.frameObject);
237
179
  if (!n)
238
180
  return !1;
239
- const s = ft(n);
181
+ const s = mt(n);
240
182
  if (!(s != null && s.cards) || s.cards.length === 0)
241
183
  return !1;
242
184
  const l = (p = s.cards) == null ? void 0 : p.find(
243
185
  (f) => f.id === s.activeCardId
244
186
  );
245
- return l ? (Wt({
187
+ return l ? (Bt({
246
188
  ...r,
247
189
  frame: s,
248
190
  card: l,
@@ -255,10 +197,10 @@ function ga() {
255
197
  var l;
256
198
  return ((l = s.card.customCardPreferences) == null ? void 0 : l.url) || "";
257
199
  }
258
- ), r = pa(t);
200
+ ), r = ua(t);
259
201
  return { getUpdatedFrame: R(() => {
260
202
  var F;
261
- ua();
203
+ ma();
262
204
  const {
263
205
  frame: s,
264
206
  card: l,
@@ -286,12 +228,12 @@ function ga() {
286
228
  return {
287
229
  ...s,
288
230
  cards: N,
289
- activeCardId: ma(N, s.activeCardId)
231
+ activeCardId: pa(N, s.activeCardId)
290
232
  };
291
233
  }, [r]) };
292
234
  }
293
235
  function qe() {
294
- const { authToken: t, tokenProps: r } = jt(), n = ce(), s = Qt(), l = Ae(), { selectVisual: d } = $t(), {
236
+ const { authToken: t, tokenProps: r } = Mt(), n = ce(), s = Ot(), l = Ae(), { selectVisual: d } = zt(), {
295
237
  setFrame: p,
296
238
  setCard: f,
297
239
  setIsDevMode: u,
@@ -315,7 +257,7 @@ function qe() {
315
257
  clearSelectedFrameId: V
316
258
  } = Le(), z = Z((_) => _.selectedSheetId), H = Z((_) => _.selectedFrameId), X = Z((_) => _.dashboard), te = Z((_) => _.filterValues), L = Z(
317
259
  (_) => _.inlineFilterValuesMap
318
- ), Q = Pt((l == null ? void 0 : l.id) || "", {
260
+ ), Q = Ut((l == null ? void 0 : l.id) || "", {
319
261
  enabled: !!(l != null && l.id) && !!(t != null && t.accessToken)
320
262
  }), Y = R(
321
263
  async (_) => {
@@ -404,11 +346,11 @@ function qe() {
404
346
  ), ue = (A == null ? void 0 : A.frameObject) ?? ((W = A == null ? void 0 : A.visual) == null ? void 0 : W.frameObject);
405
347
  if (!ue)
406
348
  return E("Visual has no frame data");
407
- const $ = ft(ue);
349
+ const $ = mt(ue);
408
350
  if (!($ != null && $.cards) || $.cards.length === 0)
409
351
  return E("Visual frame is malformed");
410
352
  const le = {
411
- ...Ht($),
353
+ ...Rt($),
412
354
  visualId: _.id
413
355
  // Link this frame to the library visual
414
356
  };
@@ -445,7 +387,66 @@ function qe() {
445
387
  refetch: Q.refetch
446
388
  };
447
389
  }
448
- function _a({
390
+ function _a() {
391
+ const t = M((p) => p.card.dataSource), {
392
+ setSelectedConnectionId: r,
393
+ setSelectedDatabaseName: n,
394
+ setSelectedSchemaName: s,
395
+ setSelectedTableName: l,
396
+ setSelectedDatamodelId: d
397
+ } = ie();
398
+ de(() => {
399
+ var w;
400
+ if (!t) return;
401
+ const { tableName: p, schemaName: f, databaseName: u, connectionId: v } = jt(t), b = (w = t.selectedEntities) == null ? void 0 : w[0], x = (b == null ? void 0 : b.type) === "model" && "id" in b ? b.id : "";
402
+ r(v || ""), n(u || ""), s(f || ""), l(p || ""), d(x);
403
+ }, [
404
+ t,
405
+ r,
406
+ n,
407
+ s,
408
+ l,
409
+ d
410
+ ]);
411
+ }
412
+ function ft() {
413
+ var u, v;
414
+ const t = M((b) => b.card), r = M((b) => b.frame), n = P(
415
+ () => lt(r, t),
416
+ [r, t]
417
+ ), { manifest: s } = Qt(
418
+ ((u = n == null ? void 0 : n.customCardPreferences) == null ? void 0 : u.url) || ""
419
+ ), l = P(
420
+ () => {
421
+ var b;
422
+ return (b = s == null ? void 0 : s.visuals) == null ? void 0 : b.find(
423
+ (h) => {
424
+ var x;
425
+ return h.name === ((x = n == null ? void 0 : n.customCardPreferences) == null ? void 0 : x.componentName);
426
+ }
427
+ );
428
+ },
429
+ [s, (v = n == null ? void 0 : n.customCardPreferences) == null ? void 0 : v.componentName]
430
+ ), d = $t(n, l), p = P(
431
+ () => Pt({
432
+ frame: r,
433
+ configCard: n,
434
+ isMultiInputVisual: d === "multiple"
435
+ }),
436
+ [r, n, d]
437
+ ), f = P(() => {
438
+ const b = p.findIndex(
439
+ (h) => (h == null ? void 0 : h.id) === t.id
440
+ );
441
+ return b < 0 ? -1 : Ht(t, b);
442
+ }, [p, t]);
443
+ return P(() => !n || d !== "multiple" || f < 0 ? t.type : Wt(
444
+ t,
445
+ f,
446
+ l == null ? void 0 : l.slots
447
+ ) ?? t.type, [n, d, f, t, l == null ? void 0 : l.slots]);
448
+ }
449
+ function La({
449
450
  type: t,
450
451
  isLinked: r,
451
452
  className: n,
@@ -544,7 +545,7 @@ function Me(t) {
544
545
  const r = Nt(t);
545
546
  return r ? (B.error(r), !1) : !0;
546
547
  }
547
- function La({
548
+ function Aa({
548
549
  className: t,
549
550
  variant: r = "outline"
550
551
  }) {
@@ -567,7 +568,7 @@ function La({
567
568
  }
568
569
  );
569
570
  }
570
- function Aa({
571
+ function qa({
571
572
  className: t,
572
573
  variant: r = "default"
573
574
  }) {
@@ -617,7 +618,7 @@ function Aa({
617
618
  }
618
619
  );
619
620
  }
620
- function qa({
621
+ function Ma({
621
622
  className: t
622
623
  }) {
623
624
  const r = ce(), [n, s] = K(!1), l = Ae(), d = M((k) => k.frame), p = Z((k) => k.selectedSheetId), f = Z((k) => k.dashboard), { updateFrame: u, setIsVisualEditing: v } = Le(), { getUpdatedFrame: b } = qe(), h = dt(), x = Gt();
@@ -680,8 +681,8 @@ function qa({
680
681
  }
681
682
  );
682
683
  }
683
- function Ma({ className: t }) {
684
- const { setTempQueryData: r, setSqlGen: n } = ie(), s = ce(), l = M((h) => h.tempQueryData), d = M((h) => h.onClose), p = M((h) => h.card), f = mt(), u = P(() => f !== p.type ? { ...p, type: f } : p, [p, f]), { queryKey: v } = it(u);
684
+ function Oa({ className: t }) {
685
+ const { setTempQueryData: r, setSqlGen: n } = ie(), s = ce(), l = M((h) => h.tempQueryData), d = M((h) => h.onClose), p = M((h) => h.card), f = ft(), u = P(() => f !== p.type ? { ...p, type: f } : p, [p, f]), { queryKey: v } = it(u);
685
686
  function b() {
686
687
  if (l) {
687
688
  const { queryKey: h, queryData: x } = l;
@@ -703,12 +704,12 @@ function Ma({ className: t }) {
703
704
  }
704
705
  );
705
706
  }
706
- function Oa({
707
+ function za({
707
708
  label: t = "Clear",
708
709
  variant: r = "secondary",
709
710
  className: n
710
711
  } = {}) {
711
- const { setTempQueryData: s } = ie(), l = ce(), d = M((O) => O.tempQueryData), p = M((O) => O.card), f = mt(), u = P(() => f !== p.type ? { ...p, type: f } : p, [p, f]), { queryKey: v } = it(u), {
712
+ const { setTempQueryData: s } = ie(), l = ce(), d = M((O) => O.tempQueryData), p = M((O) => O.card), f = ft(), u = P(() => f !== p.type ? { ...p, type: f } : p, [p, f]), { queryKey: v } = it(u), {
712
713
  setCardSql: b,
713
714
  setSqlGen: h,
714
715
  setCardPython: x,
@@ -1016,7 +1017,7 @@ function Ca(t) {
1016
1017
  defaultValue: me(n, void 0)
1017
1018
  };
1018
1019
  }
1019
- function za({
1020
+ function Ua({
1020
1021
  scope: t,
1021
1022
  controls: r,
1022
1023
  reservedControlIds: n,
@@ -1912,7 +1913,7 @@ function za({
1912
1913
  )
1913
1914
  ] });
1914
1915
  }
1915
- function Ua(t) {
1916
+ function Ra(t) {
1916
1917
  const {
1917
1918
  open: r,
1918
1919
  onOpenChange: n,
@@ -1947,21 +1948,21 @@ function Ua(t) {
1947
1948
  };
1948
1949
  }
1949
1950
  export {
1950
- za as C,
1951
- La as E,
1951
+ Ua as C,
1952
+ Aa as E,
1952
1953
  da as L,
1953
- Ia as R,
1954
- Fa as S,
1955
- _a as V,
1956
- Ma as a,
1957
- Aa as b,
1958
- qa as c,
1954
+ Fa as R,
1955
+ Va as S,
1956
+ La as V,
1957
+ Oa as a,
1958
+ qa as b,
1959
+ Ma as c,
1959
1960
  ca as d,
1960
- Ua as e,
1961
- Va as f,
1962
- mt as g,
1963
- ua as h,
1964
- Oa as i,
1961
+ Ra as e,
1962
+ _a as f,
1963
+ ft as g,
1964
+ ma as h,
1965
+ za as i,
1965
1966
  Ta as r,
1966
1967
  qe as u
1967
1968
  };