react-semaphor 0.1.295 → 0.1.296

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 (40) hide show
  1. package/dist/chunks/{braces-BdoTYzuj.js → braces-BNXseceK.js} +1 -1
  2. package/dist/chunks/{braces-DWldEFn5.js → braces-DVrX_3Q_.js} +1 -1
  3. package/dist/chunks/dashboard-controls-CKKZcVA5.js +2219 -0
  4. package/dist/chunks/dashboard-controls-DS2xJxHU.js +47 -0
  5. package/dist/chunks/dashboard-filter-controls-button-nqfmscB7.js +11 -0
  6. package/dist/chunks/{dashboard-filter-controls-button-XwenlcXw.js → dashboard-filter-controls-button-xPaIlNHP.js} +501 -495
  7. package/dist/chunks/{dashboard-json-CU55qPXj.js → dashboard-json-cuj9vYY9.js} +1 -1
  8. package/dist/chunks/{dashboard-json-V6m6lJ_c.js → dashboard-json-ovQyHWw6.js} +1 -1
  9. package/dist/chunks/{dashboard-summary-settings-dialog-DRLPzp1P.js → dashboard-summary-settings-dialog-BUg3Qyhh.js} +1 -1
  10. package/dist/chunks/{dashboard-summary-settings-dialog-0CIiWsKc.js → dashboard-summary-settings-dialog-DF076HeJ.js} +1 -1
  11. package/dist/chunks/{edit-dashboard-visual-8ha6EM_g.js → edit-dashboard-visual-32TAM00c.js} +5331 -5303
  12. package/dist/chunks/edit-dashboard-visual-BtiMcO-L.js +183 -0
  13. package/dist/chunks/{index-14M0TnH6.js → index-BDeJH9hO.js} +103265 -88338
  14. package/dist/chunks/index-Dbrs96G8.js +1533 -0
  15. package/dist/chunks/{resource-management-panel-CcDAn86l.js → resource-management-panel-2qcXsKwg.js} +2 -2
  16. package/dist/chunks/{resource-management-panel-BL5-5ouC.js → resource-management-panel-C4qoxy_g.js} +31 -30
  17. package/dist/chunks/use-create-flow-overlay-state-BMD3YRzU.js +21 -0
  18. package/dist/chunks/{use-create-flow-overlay-state-D3PxfjYv.js → use-create-flow-overlay-state-CHeppRNE.js} +572 -568
  19. package/dist/chunks/{use-visual-utils-CdIOq4nt.js → use-visual-utils-BIHLaVwh.js} +70 -68
  20. package/dist/chunks/use-visual-utils-dOYWf6nM.js +1 -0
  21. package/dist/dashboard/index.cjs +1 -1
  22. package/dist/dashboard/index.js +1 -1
  23. package/dist/index.cjs +1 -1
  24. package/dist/index.js +113 -112
  25. package/dist/style.css +1 -1
  26. package/dist/surfboard/index.cjs +1 -1
  27. package/dist/surfboard/index.js +2 -2
  28. package/dist/types/dashboard.d.ts +235 -1
  29. package/dist/types/main.d.ts +288 -1
  30. package/dist/types/shared.d.ts +204 -1
  31. package/dist/types/surfboard.d.ts +235 -1
  32. package/dist/types/types.d.ts +235 -1
  33. package/package.json +7 -1
  34. package/dist/chunks/dashboard-controls-B3lrnI_r.js +0 -47
  35. package/dist/chunks/dashboard-controls-D7U6E1sB.js +0 -2014
  36. package/dist/chunks/dashboard-filter-controls-button-D0AsV28-.js +0 -11
  37. package/dist/chunks/edit-dashboard-visual-sSLAkmgf.js +0 -183
  38. package/dist/chunks/index-Ze8VskG1.js +0 -1435
  39. package/dist/chunks/use-create-flow-overlay-state-BbQVNDCj.js +0 -21
  40. package/dist/chunks/use-visual-utils-kh8p2QFm.js +0 -1
@@ -1,21 +0,0 @@
1
- "use strict";const t=require("./index-Ze8VskG1.js"),e=require("react/jsx-runtime"),v=require("react"),se=require("./use-visual-utils-kh8p2QFm.js");/**
2
- * @license lucide-react v0.453.0 - ISC
3
- *
4
- * This source code is licensed under the ISC license.
5
- * See the LICENSE file in the root directory of this source tree.
6
- */const je=t.createLucideIcon("CircleX",[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["path",{d:"m15 9-6 6",key:"1uzhvr"}],["path",{d:"m9 9 6 6",key:"z0biqf"}]]);/**
7
- * @license lucide-react v0.453.0 - ISC
8
- *
9
- * This source code is licensed under the ISC license.
10
- * See the LICENSE file in the root directory of this source tree.
11
- */const fe=t.createLucideIcon("Library",[["path",{d:"m16 6 4 14",key:"ji33uf"}],["path",{d:"M12 6v14",key:"1n7gus"}],["path",{d:"M8 8v12",key:"1gg7y9"}],["path",{d:"M4 4v16",key:"6qkkli"}]]);/**
12
- * @license lucide-react v0.453.0 - ISC
13
- *
14
- * This source code is licensed under the ISC license.
15
- * See the LICENSE file in the root directory of this source tree.
16
- */const he=t.createLucideIcon("Link2",[["path",{d:"M9 17H7A5 5 0 0 1 7 7h2",key:"8i5ue5"}],["path",{d:"M15 7h2a5 5 0 1 1 0 10h-2",key:"1b9ql8"}],["line",{x1:"8",x2:"16",y1:"12",y2:"12",key:"1jonct"}]]);/**
17
- * @license lucide-react v0.453.0 - ISC
18
- *
19
- * This source code is licensed under the ISC license.
20
- * See the LICENSE file in the root directory of this source tree.
21
- */const re=t.createLucideIcon("Save",[["path",{d:"M15.2 3a2 2 0 0 1 1.4.6l3.8 3.8a2 2 0 0 1 .6 1.4V19a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2z",key:"1c8476"}],["path",{d:"M17 21v-7a1 1 0 0 0-1-1H8a1 1 0 0 0-1 1v7",key:"1ydtos"}],["path",{d:"M7 3v4a1 1 0 0 0 1 1h7",key:"t51u73"}]]);function le(){var f,j;const a=t.useEditorStore(b=>b.card),l=t.useEditorStore(b=>b.frame),i=v.useMemo(()=>t.findCustomVisualConfigCard(l,a),[l,a]),{manifest:d}=t.useCustomVisual(((f=i==null?void 0:i.customCardPreferences)==null?void 0:f.url)||""),x=v.useMemo(()=>{var b;return(b=d==null?void 0:d.visuals)==null?void 0:b.find(p=>{var C;return p.name===((C=i==null?void 0:i.customCardPreferences)==null?void 0:C.componentName)})},[d,(j=i==null?void 0:i.customCardPreferences)==null?void 0:j.componentName]),u=t.resolveMultiInputType(i,x),h=v.useMemo(()=>t.getCustomVisualInputCards({frame:l,configCard:i,isMultiInputVisual:u==="multiple"}),[l,i,u]),y=v.useMemo(()=>{const b=h.findIndex(p=>(p==null?void 0:p.id)===a.id);return b<0?-1:t.getSlotIndexForCard(a,b)},[h,a]);return v.useMemo(()=>!i||u!=="multiple"||y<0?a.type:t.getEffectiveCardTypeForSlot(a,y,x==null?void 0:x.slots)??a.type,[i,u,y,a,x==null?void 0:x.slots])}function ke({type:a,isLinked:l,className:i,showLabel:d=!1,showLocal:x=!1}){const u=t.useDashboardStore(S=>S.selectedFrameId),h=t.useManagementStore(S=>S.selectedVisual),y=t.useEditorStore(S=>S.frame);let f;if(a)f=a;else if(l!==void 0)f=l?"linked":"library";else if(!!!(y!=null&&y.visualId||h!=null&&h.id)&&u)f="local";else if(h&&!u)f="library";else if(y!=null&&y.visualId&&u)f="linked";else if(h!=null&&h.id&&u)f="library";else return null;if(f==="local"&&!x)return null;const j={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"},b={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."},p={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"},C={local:"fill-slate-50 dark:fill-slate-900",linked:"fill-purple-50 dark:fill-purple-950",library:"fill-blue-50 dark:fill-blue-950"},T={local:e.jsx("span",{className:"h-2 w-2 rounded-full bg-current/70"}),linked:e.jsx(he,{className:"h-3.5 w-3.5"}),library:e.jsx(fe,{className:"h-3.5 w-3.5"})},k={local:"Local",linked:"Linked",library:"Library"};return e.jsx(t.TooltipProvider,{children:e.jsxs(t.Tooltip,{delayDuration:300,children:[e.jsx(t.TooltipTrigger,{asChild:!0,children:e.jsxs(t.Badge,{variant:"outline",className:t.cn("cursor-help select-none transition-all",j[f],i),children:[T[f],d&&e.jsx("span",{className:"ml-1 text-xs font-medium leading-none",children:k[f]})]})}),e.jsxs(t.TooltipContent,{side:"bottom",className:t.cn("max-w-xs",p[f]),children:[e.jsx(t.TooltipArrow,{className:C[f]}),e.jsx("p",{children:b[f]})]})]})})}function Se(a,l){return{...a,sql:"",python:"",config:void 0,customCfg:"",preferences:{},interactionConfig:void 0,linkedInteractionTargetOverrides:void 0,dynamicCardPreferences:void 0,customCardPreferences:l?a.customCardPreferences:void 0,visualizationMode:"builtin",type:l?a.type:"bar"}}function ae(a){const l=t.getDynamicFrameSaveIssue(a);return l?(t.ue.error(l),!1):!0}function Ne({className:a,variant:l="outline"}){const i=t.useEditorStore(u=>u.onSave),{getUpdatedFrame:d}=se.useVisualUtils();function x(){const u=d();ae(u)&&(i==null||i(u))}return e.jsxs(t.Button,{onClick:x,className:a,size:"xs",variant:l,children:[e.jsx(t.Check,{className:"h-3.5 w-3.5"}),"Accept"]})}function De({className:a,variant:l="default"}){const i=t.useQueryClient(),[d,x]=v.useState(!1),u=t.useDashboardStore(C=>C.actions.setIsDashboardPanelOpen),{setIsVisualEditing:h}=t.useDashboardActions(),{getUpdatedFrame:y}=se.useVisualUtils(),f=t.useSelectedVisual(),j=t.useEditorStore(C=>C.frame),b=t.useUpdateVisualMutation(),p=()=>{const C=y();if(!ae(C))return;const T=(j==null?void 0:j.visualId)||(f==null?void 0:f.id);if(!T){t.ue.error("No visual to save");return}x(!0),b.mutate({visualId:T,data:{frameObject:C}},{onSuccess:()=>{x(!1),u(!0),t.ue.success("Visual updated successfully"),i.invalidateQueries({queryKey:["resource-by-id","visual",T],exact:!0})},onError:()=>{x(!1),t.ue.error("Failed to update visual")}})};return e.jsx(t.Button,{onClick:p,className:a,size:"xs",variant:l,children:d?e.jsxs(e.Fragment,{children:[e.jsx(t.LoaderCircle,{className:"h-3.5 w-3.5 animate-spin"}),"Saving"]}):e.jsxs(e.Fragment,{children:[e.jsx(re,{className:"h-3.5 w-3.5"}),"Save to Library"]})})}function we({className:a}){const l=t.useQueryClient(),[i,d]=v.useState(!1),x=t.useSelectedVisual(),u=t.useEditorStore(k=>k.frame),h=t.useDashboardStore(k=>k.selectedSheetId),y=t.useDashboardStore(k=>k.dashboard),{updateFrame:f,setIsVisualEditing:j}=t.useDashboardActions(),{getUpdatedFrame:b}=se.useVisualUtils(),p=t.useUpdateVisualMutation(),C=t.useResolveExistingFrameSemanticExecutionPayload(),T=async()=>{if(!h){t.ue.error("No sheet selected");return}const k=(u==null?void 0:u.visualId)||(x==null?void 0:x.id);if(!k){t.ue.error("No visual to update");return}d(!0);try{const S=b();if(!ae(S)){d(!1);return}const B={...S,visualId:k},R=t.findDashboardFrameById(y,B.id),O=await C(B,{previousFrame:R});await p.mutateAsync({visualId:k,data:{frameObject:S}}),f(h,B,{semanticExecutionPayload:O}),l.invalidateQueries({queryKey:["visuals"]}),l.invalidateQueries({queryKey:["visual",k]}),t.ue.success("Saved to library and applied locally"),setTimeout(()=>{j(!1)},300)}catch(S){console.error("Failed to save and apply:",S),t.ue.error(S instanceof Error?S.message:"Failed to save and apply changes")}finally{d(!1)}};return e.jsx(t.Button,{onClick:T,className:a,size:"xs",variant:"default",disabled:i,children:i?e.jsxs(e.Fragment,{children:[e.jsx(t.LoaderCircle,{className:"h-3.5 w-3.5 animate-spin"}),"Saving..."]}):e.jsxs(e.Fragment,{children:[e.jsx(re,{className:"h-3.5 w-3.5"}),"Save & Apply"]})})}function Ee({className:a}){const{setTempQueryData:l,setSqlGen:i}=t.useEditorActions(),d=t.useQueryClient(),x=t.useEditorStore(p=>p.tempQueryData),u=t.useEditorStore(p=>p.onClose),h=t.useEditorStore(p=>p.card),y=le(),f=v.useMemo(()=>y!==h.type?{...h,type:y}:h,[h,y]),{queryKey:j}=t.useEditorCardQuery(f);function b(){if(x){const{queryKey:p,queryData:C}=x;p&&C&&d.setQueryData(p,C)}i({}),u==null||u()}return e.jsxs(t.Button,{onClick:b,className:a,size:"xs",variant:"outline",children:[e.jsx(t.X,{className:"h-3.5 w-3.5"}),"Close"]})}function Ve({label:a="Clear",variant:l="secondary",className:i}={}){const{setTempQueryData:d}=t.useEditorActions(),x=t.useQueryClient(),u=t.useEditorStore(r=>r.tempQueryData),h=t.useEditorStore(r=>r.card),y=le(),f=v.useMemo(()=>y!==h.type?{...h,type:y}:h,[h,y]),{queryKey:j}=t.useEditorCardQuery(f),{setCardSql:b,setSqlGen:p,setCardPython:C,setCardCustomCfg:T,setCardPreferences:k,clearQueryConfig:S,setCardConfig:B,setCardType:R,setFrame:O,setCard:U,setActiveTabCardId:J}=t.useEditorActions();function z(){var I,Y,A,H;const r=x.getQueryData(j);u!=null&&u.queryData||d({queryKey:j,queryData:r}),x.setQueryData(j,null),x.removeQueries({queryKey:j,exact:!0}),b(""),p({}),S(),B(void 0),C(""),T(""),k({});const D=t.useEditorStore.getState().frame,_=t.useEditorStore.getState().card,V=t.findCustomVisualConfigCard(D,_),P=((I=V==null?void 0:V.customCardPreferences)==null?void 0:I.visualType)==="multiple"||!!((Y=V==null?void 0:V.customCardPreferences)!=null&&Y.dataInputCardIds)||(((A=V==null?void 0:V.customCardPreferences)==null?void 0:A.minInputs)||0)>1||(((H=V==null?void 0:V.customCardPreferences)==null?void 0:H.maxInputs)||0)>1,q=Se(_,P);O({...D,cards:D.cards.map(K=>K.id===q.id?q:K)}),J(q.id),U(q),P||R("bar")}return e.jsxs(t.Button,{onClick:z,className:i,size:"xs",variant:l,children:[e.jsx(t.X,{className:"h-3.5 w-3.5"}),a]})}function ge(a){const{control:l,onChange:i}=a;return e.jsxs("div",{className:"flex flex-col gap-1.5",children:[e.jsx(t.Label,{className:"text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground",children:"Label"}),e.jsx(t.Input,{size:"xs",value:l.label,placeholder:"Control label",onChange:d=>i(d.target.value)})]})}function Te(a){const{currentStep:l,labels:i}=a;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:i.map((d,x)=>{const u=x+1,h=u===l,y=u<l;return e.jsxs(v.Fragment,{children:[e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("span",{className:t.cn("flex h-5 w-5 items-center justify-center rounded-full border text-[10px] font-medium tabular-nums",h?"border-foreground bg-foreground text-background":y?"border-foreground/30 bg-foreground/10 text-foreground":"border-border/60 bg-background text-muted-foreground"),children:u}),e.jsx("span",{className:t.cn("text-[12px]",h?"font-medium text-foreground":"text-muted-foreground"),children:d})]}),x<i.length-1?e.jsx("span",{className:"h-px w-4 bg-border/60 sm:w-6","aria-hidden":"true"}):null]},d)})})})}function G(a){const{secondary:l,tertiary:i,primary:d}=a;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:[l,i,d]})}function Ie(a){const{control:l,scope:i,detail:d}=a;return e.jsxs("div",{className:"flex items-start gap-2.5 rounded-[6px] border border-border/60 bg-muted/30 px-3 py-2.5",children:[e.jsx(t.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:l.label}),e.jsxs("div",{className:"text-[12px] text-muted-foreground",children:[t.getFriendlyTypeOption(l.type).label," ·"," ",t.getControlOptionPreview(l)," ·"," ",t.getPlacementLabel(i,l.placement)]}),d?e.jsx("div",{className:"text-[12px] text-muted-foreground",children:d}):null]})]})}function pe(a){const{control:l,defaultValue:i,availableFieldChoices:d,availableMetricChoices:x,previewControlDefinitions:u,previewControlValues:h,onControlChange:y,onLabelChange:f,onDefaultValueChange:j,onBack:b,onNext:p,nextDisabled:C}=a;return e.jsxs("div",{className:"space-y-3",children:[e.jsx(ge,{control:l,onChange:f}),e.jsx(t.ControlDefinitionOptionsEditor,{control:l,availableFieldChoices:d,availableMetricChoices:x,previewControlDefinitions:u,previewControlValues:h,controlLifecycle:"create",onChange:y}),e.jsx(t.ControlDefaultValueEditor,{control:l,value:i,onChange:j,allowNoDefault:!0,allowCardDefault:!0,hint:"This is the value viewers will see first.",previewControlDefinitions:u,previewControlValues:h}),e.jsx(G,{secondary:e.jsx(t.Button,{type:"button",variant:"outline",size:"xs",onClick:b,children:"Back"}),primary:e.jsx(t.Button,{type:"button",size:"xs",onClick:p,disabled:C,children:"Next"})})]})}const Fe=new Set(["grain_selector","aggregation_selector","field_selector","metric_selector"]);function me(a){const{text:l,ariaLabel:i}=a,[d,x]=v.useState(!1);return e.jsxs("button",{type:"button","aria-label":i,onClick:async()=>{try{await navigator.clipboard.writeText(l),x(!0),setTimeout(()=>x(!1),1200)}catch(u){console.error("Failed to copy",u)}},className:"group flex w-full items-center justify-between gap-2 rounded-[4px] 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:l}),e.jsx("span",{className:"shrink-0 text-[11px] text-muted-foreground opacity-0 transition-opacity group-hover:opacity-100",children:d?"Copied":"Click to copy"})]})}function xe(a){const{control:l,scope:i,createdReference:d,explorerContent:x,sqlDescription:u,summaryDetail:h,onBack:y,onCancel:f,onDone:j}=a,b=Fe.has(l.type),p=d.match(/\[\[param\.(.+?)\]\]/),C=p?`{{ param('${p[1]}') }}`:"";return e.jsxs("div",{className:"space-y-4",children:[e.jsx(Ie,{control:l,scope:i,detail:h}),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-[6px] border border-border/60",children:[b?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:x})]}):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(me,{text:d,ariaLabel:"Copy SQL control reference"}),C?e.jsx(me,{text:C,ariaLabel:"Copy Jinja control reference"}):null,e.jsxs("p",{className:"text-[12px] text-muted-foreground",children:[u," ",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(G,{secondary:e.jsx(t.Button,{type:"button",variant:"outline",size:"xs",onClick:y,children:"Back"}),tertiary:e.jsx(t.Button,{type:"button",variant:"outline",size:"xs",onClick:f,children:"Cancel"}),primary:e.jsx(t.Button,{type:"button",size:"xs",onClick:j,children:"Done"})})]})}function Le(a){const l=t.createBlankControl(a.scope,a.existingControls,a.reservedIds),i=a.type===l.type?{...l,label:t.DEFAULT_LABEL_BY_TYPE[a.type]}:{...t.applyControlTypeChange({controls:[{...l,label:t.DEFAULT_LABEL_BY_TYPE[a.type]}],controlId:l.id,nextType:a.type}).controls[0],label:t.DEFAULT_LABEL_BY_TYPE[a.type]};return{step:2,control:i,defaultValue:t.getDefaultValueForType(i,void 0)}}function Be({scope:a,controls:l,reservedControlIds:i,defaultValues:d,onChange:x,emptyMessage:u,initialCreateFlow:h=!1,usageByControlId:y,availableFieldChoices:f,availableMetricChoices:j,structuralParticipants:b,structuralParticipantIdsByControlId:p,card:C,onCreateFlowActiveChange:T,onCreateFlowComplete:k}){const S=v.useMemo(()=>new Set(i||[]),[i]),B=t.getPlacementOptionsForScope(a),R=t.getDefaultPlacement(a),[O,U]=v.useState(null),[J,z]=v.useState(null),[r,D]=v.useState(()=>h?{step:1,control:t.createBlankControl(a,l,Array.from(S))}:null),_=v.useRef({}),V=v.useRef(void 0),P=v.useRef(h),q=v.useMemo(()=>t.getFriendlyControlTypeOptions({scope:a,card:C}),[C,a]),I=v.useCallback(s=>a==="dashboard"&&(s==="field_selector"||s==="metric_selector"),[a]),Y=v.useMemo(()=>r?t.getEligibleParticipantsForStructuralControl(b||[],r.control.type):[],[r,b]),A=v.useMemo(()=>{if(!r)return{fields:f||[],metrics:j||[]};if(!I(r.control.type))return{fields:f||[],metrics:j||[]};const s=r.selectedCardIds||[],o=t.getCompatibleStructuralChoiceCatalog({controlType:r.control.type,participants:b||[],selectedCardIds:s});return{fields:r.control.type==="field_selector"?o.choices.map(n=>({option:n,target:o.fieldTargetMap[n.value]})):[],metrics:r.control.type==="metric_selector"?o.choices.map(n=>({option:n,target:o.metricTargetMap[n.value]})):[]}},[f,j,r,I,b]);v.useEffect(()=>{T==null||T(!!r)},[r,T]),v.useEffect(()=>{const s=h&&!P.current;P.current=h,s&&(D({step:1,control:t.createBlankControl(a,l,Array.from(S))}),z(null),U(null))},[l,h,S,a]);const H=s=>{if(!I(s.type))return{fields:f||[],metrics:j||[]};const o=(p==null?void 0:p[s.id])||[];if(o.length===0)return{fields:f||[],metrics:j||[]};const n=t.getCompatibleStructuralChoiceCatalog({controlType:s.type,participants:b||[],selectedCardIds:o});return{fields:s.type==="field_selector"?n.choices.map(c=>({option:c,target:n.fieldTargetMap[c.value]})):[],metrics:s.type==="metric_selector"?n.choices.map(c=>({option:c,target:n.metricTargetMap[c.value]})):[]}},K=s=>{if(!I(s.control.type))return{nextControl:s.control,cardBindingsById:void 0};const o=(p==null?void 0:p[s.control.id])||[],n=t.getCompatibleStructuralChoiceCatalog({controlType:s.control.type,participants:b||[],selectedCardIds:s.nextSelectedCardIds}),c=t.reconcileStructuralControlChoices({control:s.control,choices:n.choices}),g=Object.fromEntries(o.filter(w=>!s.nextSelectedCardIds.includes(w)).map(w=>[w,void 0]));return s.nextSelectedCardIds.length>0&&c.source.kind==="manual"&&c.source.options.length>0&&Object.assign(g,t.buildStructuralControlBindingsForParticipants({control:c,participants:b||[],selectedCardIds:s.nextSelectedCardIds})),{nextControl:c,cardBindingsById:g}},L=v.useCallback((s,o=d,n={type:"update"})=>{const c=s.map(g=>(t.resolveAuthoringControlDefaultValue({control:g,defaultValues:o}),t.syncSqlQueryControlExecutionRequirement(g)));x(c,o,n)},[d,x]),X=(s,o)=>{const n=l.find(E=>E.id===s);let c=l.map(E=>E.id!==s?E:o(E));const g=c.find(E=>E.id===s);let w,m;if(g&&a==="dashboard"&&(g.type==="field_selector"||g.type==="metric_selector")){const E=(p==null?void 0:p[g.id])||[],Q=K({control:g,nextSelectedCardIds:E});c=c.map(M=>M.id===s?Q.nextControl:M),w=Q.cardBindingsById,m=[g.id]}else if(n&&a==="dashboard"&&(n.type==="field_selector"||n.type==="metric_selector")){const E=(p==null?void 0:p[n.id])||[];w=Object.fromEntries(E.map(Q=>[Q,void 0])),m=[n.id]}const N=c.find(E=>E.id===s);let F=d;if(n&&N){const E=t.resolveAuthoringControlDefaultValue({control:n,defaultValues:d});n.source.kind==="manual"&&N.source.kind==="sql_query"&&(_.current[s]=E);const Q=E===void 0&&n.source.kind==="sql_query"&&N.source.kind==="manual"?_.current[s]:E,M=t.getNextEditedControlDefaultValue({previousControl:n,nextControl:N,currentDefaultValue:Q});N.source.kind==="manual"&&(_.current[s]=M),d&&(F={...d},M===void 0?delete F[s]:F[s]=M),c=c.map(ue=>ue.id===s?{...N,defaultValue:M}:ue)}L(c,F,{type:"update",cardBindingsById:w,affectedBindingControlIds:m})},be=(s,o)=>{const n=o.trim();if(n.length===0||n===s||S.has(n)||l.some(w=>w.id===n&&w.id!==s))return;const c=l.map(w=>w.id===s?{...w,id:n}:w);if(!d){L(c,void 0,{type:"rename",oldId:s,newId:n});return}const g={...d};Object.prototype.hasOwnProperty.call(g,s)&&(g[n]=g[s],delete g[s]),L(c,g,{type:"rename",oldId:s,newId:n})},ye=s=>{const o=l.filter(c=>c.id!==s);if(!d){L(o,void 0,{type:"remove",controlId:s});return}const n={...d};delete n[s],L(o,n,{type:"remove",controlId:s})},ve=v.useCallback(()=>{V.current=void 0,D({step:1,control:t.createBlankControl(a,l,Array.from(S))}),z(null),U(null)},[l,S,a]),$=s=>{D(o=>o&&(()=>{const n=s(o.control);o.control.source.kind==="manual"&&n.source.kind==="sql_query"&&(V.current=o.defaultValue);const c=o.defaultValue===void 0&&o.control.source.kind==="sql_query"&&n.source.kind==="manual"?V.current:o.defaultValue,g=t.getNextEditedControlDefaultValue({previousControl:o.control,nextControl:n,currentDefaultValue:c});return n.source.kind==="manual"&&(V.current=g),{...o,control:n,defaultValue:g}})())},ne=s=>{D(o=>o&&(o.control.source.kind==="manual"&&(V.current=s),{...o,defaultValue:s}))},W=(()=>{if(!r)return!1;if(r.step===2&&I(r.control.type))return(r.selectedCardIds||[]).length>0;if(r.step!==2&&r.step!==3||!r.control.label.trim())return!1;const o=r.control.source.kind==="sql_query"?r.control:t.ensureManualSource(r.control);if(o.source.kind==="manual"&&(t.needsManualOptions(o)&&o.source.options.length===0||o.source.options.some(c=>c.label.trim().length===0||c.value.trim().length===0)))return!1;if(o.source.kind==="sql_query"){const{connectionId:n,sql:c,valueColumn:g}=o.source;return n.trim().length>0&&c.trim().length>0&&g.trim().length>0}return t.hasConcreteDefaultValue(t.getDefaultValueForType(o,r.defaultValue))})(),oe=()=>{var w;if(!r)return;const s=t.ensureManualSource(r.control),o=t.deriveUniqueControlId({label:s.label,fallbackId:s.id,existingControls:l,reservedIds:Array.from(S)}),n={...s,id:o},c=a==="dashboard"&&(n.type==="field_selector"||n.type==="metric_selector")&&((w=r.selectedCardIds)!=null&&w.length)?t.buildStructuralControlBindingsForParticipants({control:n,participants:b||[],selectedCardIds:r.selectedCardIds}):void 0,g=t.getDefaultValueForType(n,r.defaultValue);D({step:a==="dashboard"&&(n.type==="field_selector"||n.type==="metric_selector")?4:3,control:n,defaultValue:g,createdControlId:o,selectedCardIds:r.selectedCardIds,cardBindingsById:c})},Z=v.useCallback(()=>{D(null)},[]),ie=v.useCallback(()=>{if(!(r!=null&&r.createdControlId)){D(null);return}const s=r.control,o=r.createdControlId,n=t.getDefaultValueForType(s,r.defaultValue);if(d){const c={...d};n===void 0?delete c[o]:c[o]=n,L([...l,{...s,defaultValue:n}],c,{type:"add",cardBindingsById:r.cardBindingsById})}else L([...l,{...s,defaultValue:n}],void 0,{type:"add",cardBindingsById:r.cardBindingsById});z(o),D(null),k==null||k()},[l,r,d,L,k]),Ce=r?I(r.control.type)?["Choose type","Select cards","Configure","Finish"]:["Choose type","Configure","Finish"]:[],de=r!=null&&r.createdControlId?`[[param.${r.createdControlId}]]`:r?`[[param.${t.slugifyControlValue(r.control.label)||r.control.id}]]`:"",ee=t.buildAuthoringPreviewControlValues({controls:l,defaultValues:d}),te=r?[...l,r.control]:l,ce=r?t.buildAuthoringPreviewControlValues({controls:te,defaultValues:d,overrides:[{controlId:r.control.id,value:r.defaultValue}]}):ee;return e.jsxs("div",{className:"space-y-4",children:[r?e.jsxs("div",{className:"space-y-4 pb-1",children:[e.jsx(Te,{currentStep:r.step,labels:Ce}),r.step===1&&(()=>{const s=new Set(["grain_selector","aggregation_selector","field_selector","metric_selector"]),o=q.filter(g=>!s.has(g.value)),n=q.filter(g=>s.has(g.value)),c=g=>e.jsxs("button",{type:"button",className:"rounded-[6px] 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(Le({scope:a,existingControls:l,reservedIds:Array.from(S),type:g.value})),children:[e.jsx("div",{className:"text-[13px] font-medium text-foreground",children:g.label}),e.jsx("p",{className:"mt-0.5 text-[12px] text-muted-foreground",children:g.description})]},g.value);return e.jsxs("div",{className:"space-y-4",children:[a==="card"&&(C==null?void 0:C.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,o.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:o.map(c)})]}),n.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:n.map(c)})]}),e.jsx(G,{secondary:e.jsx(t.Button,{type:"button",variant:"outline",size:"xs",onClick:Z,children:"Back to controls"})})]})})(),r.step===2&&I(r.control.type)&&e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"space-y-3",children:[e.jsx(ge,{control:r.control,onChange:s=>$(o=>({...o,label:s}))}),e.jsx("p",{className:"text-[12px] text-muted-foreground",children:"Choose which cards should respond to this shared control."})]}),Y.length===0?e.jsx("div",{className:"rounded-[6px] 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-[6px] border border-border/60 bg-background p-2",children:Y.map(s=>{const o=(r.selectedCardIds||[]).includes(s.cardId);return e.jsxs("label",{className:"flex items-start gap-2 rounded-[4px] px-1.5 py-1 text-[13px] hover:bg-muted/40",children:[e.jsx(t.Checkbox,{checked:o,onCheckedChange:n=>D(c=>c&&{...c,selectedCardIds:n===!0?[...c.selectedCardIds||[],s.cardId]:(c.selectedCardIds||[]).filter(g=>g!==s.cardId)})}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"font-medium text-foreground",children:s.title}),e.jsx("div",{className:"text-[12px] text-muted-foreground",children:r.control.type==="field_selector"?`${s.fieldChoices.length} compatible group-by fields`:`${s.metricChoices.length} compatible metrics`})]})]},s.cardId)})}),e.jsx(G,{secondary:e.jsx(t.Button,{type:"button",variant:"outline",size:"xs",onClick:()=>D(s=>s&&{...s,step:1,selectedCardIds:[]}),children:"Back"}),primary:e.jsx(t.Button,{type:"button",size:"xs",onClick:()=>D(s=>s&&{...s,step:3}),disabled:!W,children:"Next"})})]}),r.step===2&&!I(r.control.type)&&e.jsx(pe,{control:r.control,defaultValue:r.defaultValue,availableFieldChoices:A.fields,availableMetricChoices:A.metrics,previewControlDefinitions:te,previewControlValues:ce,onControlChange:s=>$(()=>s),onLabelChange:s=>$(o=>({...o,label:s})),onDefaultValueChange:ne,onBack:()=>D(s=>s&&{...s,step:1}),onNext:oe,nextDisabled:!W}),r.step===3&&I(r.control.type)&&e.jsx(pe,{control:r.control,defaultValue:r.defaultValue,availableFieldChoices:A.fields,availableMetricChoices:A.metrics,previewControlDefinitions:te,previewControlValues:ce,onControlChange:s=>$(()=>s),onLabelChange:s=>$(o=>({...o,label:s})),onDefaultValueChange:ne,onBack:()=>D(s=>s&&{...s,step:2}),onNext:oe,nextDisabled:!W}),r.step===3&&!I(r.control.type)&&e.jsx(xe,{control:r.control,scope:a,createdReference:de,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(s=>s&&{...s,step:2}),onCancel:Z,onDone:ie}),r.step===4&&I(r.control.type)&&e.jsx(xe,{control:r.control,scope:a,createdReference:de,summaryDetail:e.jsxs(e.Fragment,{children:["Used by ",(r.selectedCardIds||[]).length," ","selected card",(r.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(s=>s&&{...s,step:3}),onCancel:Z,onDone:ie})]}):null,!r&&l.length===0?e.jsx("div",{className:"rounded-md border border-dashed p-3 text-sm text-muted-foreground",children:u}):null,!r&&l.map(s=>{const o=H(s),n=y==null?void 0:y[s.id],c=t.resolveAuthoringControlDefaultValue({control:s,defaultValues:d}),g=J===s.id,w="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-[6px] 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-[4px] text-left focus:outline-none focus-visible:bg-muted/40",onClick:()=>z(m=>m===s.id?null:s.id),children:[g?e.jsx(t.ChevronDown,{className:"mt-0.5 h-3.5 w-3.5 shrink-0 text-muted-foreground"}):e.jsx(t.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:s.label||"Untitled control"}),e.jsx("span",{className:w,children:t.getFriendlyTypeOption(s.type).label}),e.jsx("span",{className:w,children:t.getPlacementLabel(a,s.placement)})]}),e.jsxs("div",{className:"mt-0.5 text-[12px] text-muted-foreground",children:[t.getControlOptionPreview(s),n!=null&&n.status?` · ${n.status}`:""]})]})]}),e.jsx(t.Button,{type:"button",size:"xs",variant:"ghost",className:"h-7 w-7 shrink-0 p-0 text-muted-foreground",onClick:()=>ye(s.id),"aria-label":`Remove ${s.label}`,children:e.jsx(t.Trash2,{className:"h-3.5 w-3.5"})})]}),g&&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(t.Label,{className:"text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground",children:"Label"}),e.jsx(t.Input,{size:"xs",value:s.label,placeholder:"Control label",onChange:m=>X(s.id,N=>({...N,label:m.target.value}))})]}),e.jsxs("div",{className:"flex flex-col gap-1.5",children:[e.jsx(t.Label,{className:"text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground",children:"Type"}),e.jsxs(t.Select,{value:s.type,onValueChange:m=>{const N=t.applyControlTypeChange({controls:l,controlId:s.id,nextType:m,defaultValues:d});L(N.controls,N.defaultValues)},children:[e.jsx(t.SelectTrigger,{size:"xs",children:e.jsx(t.SelectValue,{})}),e.jsx(t.SelectContent,{children:t.getFriendlyControlTypeOptions({scope:a,card:C,includeType:s.type}).map(m=>e.jsx(t.SelectItem,{value:m.value,children:m.label},m.value))})]})]}),e.jsxs("div",{className:"flex flex-col gap-1.5",children:[e.jsx(t.Label,{className:"text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground",children:"Show in"}),e.jsxs(t.Select,{value:s.placement||R,onValueChange:m=>X(s.id,N=>({...N,placement:m})),children:[e.jsx(t.SelectTrigger,{size:"xs",children:e.jsx(t.SelectValue,{})}),e.jsx(t.SelectContent,{children:B.map(m=>e.jsx(t.SelectItem,{value:m.value,children:m.label},m.value))})]})]})]}),I(s.type)?e.jsx(t.StructuralParticipantSelector,{type:s.type,participants:t.getEligibleParticipantsForStructuralControl(b||[],s.type).map(m=>({cardId:m.cardId,title:m.title,choiceCount:s.type==="field_selector"?m.fieldChoices.length:m.metricChoices.length})),selectedCardIds:(p==null?void 0:p[s.id])||[],onChange:m=>{const N=K({control:s,nextSelectedCardIds:m}),F=l.map(E=>E.id===s.id?N.nextControl:E);L(F,d,{type:"update",cardBindingsById:N.cardBindingsById})}}):null,e.jsx(t.ControlDefinitionOptionsEditor,{control:s,availableFieldChoices:o.fields,availableMetricChoices:o.metrics,previewControlDefinitions:l,previewControlValues:ee,controlLifecycle:"edit",onChange:m=>X(s.id,()=>m)}),s.initialValueStrategy==="saved_default"&&e.jsx(t.ControlDefaultValueEditor,{control:s,value:c,allowNoDefault:!0,allowCardDefault:!0,previewControlDefinitions:l,previewControlValues:ee,onChange:m=>{const N=l.map(F=>F.id===s.id?{...F,defaultValue:m}:F);if(s.source.kind==="manual"&&(_.current[s.id]=m),d){const F={...d};m===void 0?delete F[s.id]:F[s.id]=m,L(N,F);return}L(N,void 0)}}),e.jsxs(t.Collapsible,{open:O===s.id,onOpenChange:m=>U(m?s.id:null),children:[e.jsx(t.CollapsibleTrigger,{asChild:!0,children:e.jsxs(t.Button,{type:"button",variant:"ghost",size:"xs",className:"-ml-2 gap-1 text-muted-foreground hover:text-foreground",children:[O===s.id?e.jsx(t.ChevronDown,{className:"h-3.5 w-3.5"}):e.jsx(t.ChevronRight,{className:"h-3.5 w-3.5"}),"Advanced"]})}),e.jsxs(t.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(t.Label,{className:"text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground",children:"Control ID"}),e.jsx(t.ControlIdInput,{controlId:s.id,onCommit:m=>be(s.id,m)},s.id)]}),e.jsxs("div",{className:"flex flex-col gap-1.5",children:[e.jsx(t.Label,{className:"text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground",children:"Initial value"}),e.jsxs(t.Select,{value:s.initialValueStrategy,onValueChange:m=>X(s.id,N=>({...N,initialValueStrategy:m})),children:[e.jsx(t.SelectTrigger,{size:"xs",children:e.jsx(t.SelectValue,{})}),e.jsx(t.SelectContent,{children:t.INITIAL_VALUE_STRATEGY_OPTIONS.map(m=>e.jsx(t.SelectItem,{value:m.value,children:m.label},m.value))})]})]})]}),e.jsx(t.ControlVisibilitySettings,{control:s,onChange:m=>X(s.id,()=>m)})]})]})]})]},s.id)}),!r&&e.jsxs(t.Button,{type:"button",variant:"outline",size:"xs",onClick:ve,children:[e.jsx(t.Plus,{className:"h-3.5 w-3.5"}),"Add control"]})]})}function _e(a){const{open:l,onOpenChange:i,initialCreateFlowActive:d=!1,dismissMode:x="passive"}=a,u=l!==void 0,[h,y]=v.useState(!1),[f,j]=v.useState(d),b=u?l:h,p=v.useCallback(k=>{!k&&f&&x==="passive"||(u||y(k),k||j(!1),i==null||i(k))},[u,f,x,i]),C=v.useCallback(()=>{u||y(!1),j(!1),i==null||i(!1)},[u,i]);v.useEffect(()=>{b||j(!1)},[b]);const T=v.useCallback(k=>{f&&k.preventDefault()},[f]);return{forceClose:C,handleOpenChange:p,isCreateFlowActive:f,preventPassiveDismissDuringCreate:T,resolvedOpen:b,setIsCreateFlowActive:j}}exports.CircleX=je;exports.ControlDefinitionListEditor=Be;exports.EditorAcceptButton=Ne;exports.EditorCancelButton=Ee;exports.EditorClearButton=Ve;exports.Library=fe;exports.Link2=he;exports.Save=re;exports.VisualBadge=ke;exports.VisualSaveAndApplyButton=we;exports.VisualSaveButton=De;exports.useCreateFlowOverlayState=_e;exports.useEffectiveEditorCardType=le;
@@ -1 +0,0 @@
1
- "use strict";const a=require("./index-Ze8VskG1.js"),p=require("react");function G(e){const[o,s]=p.useState(null),[r,t]=p.useState(null),n=a.useEnsureReactGlobals();return p.useEffect(()=>{if(!e||e.trim()===""){s(null),t(null);return}if(!n)return;(async()=>{try{if(!e.startsWith("http://")&&!e.startsWith("https://"))throw new Error(`Invalid URL format: ${e}`);try{new URL(e)}catch{throw new Error(`Invalid URL: ${e}`)}const c=`${e.endsWith("/")?e:`${e}/`}index.js`;try{if(!(await fetch(c,{method:"HEAD"})).ok)throw new Error(`Module not found at ${c}`)}catch{}const h=await import(c);if(typeof h.useChartStore!="function")throw new Error("useChartStore is not a function");s(()=>h.useChartStore),t(null)}catch(i){const c=i instanceof Error?i.message:"Unknown error";console.error("Failed to load remote chart store:",c),t(c),s(null)}})()},[e,n]),o}function J(e,o){if(e.length===0)return"";const s=e.find(r=>{var t,n;return((t=r.customCardPreferences)==null?void 0:t.visualType)==="multiple"||!!((n=r.customCardPreferences)!=null&&n.dataInputCardIds)});if(s)return s.id;if(o){const r=e.find(t=>t.id===o);if(r){const t=r.tabTitle;if(t=="All__Header")return e[0].id;if(t&&t.endsWith("__Header")){const u=t.split("__")[0],i=e.find(c=>c.tabTitle===u);return i?i.id:e[0].id}return o}}return e[0].id}const D=new Set;function K(e){return D.add(e),()=>{D.delete(e)}}function B(){D.forEach(e=>{e()})}const X=e=>{if(!e||!("detailTableBackup"in e))return e;const{detailTableBackup:o,...s}=e;return s};async function x(e,o,s,r){if(!o||!s)throw new Error("Missing auth token or visual ID");const t=["resource-by-id","visual",s],n=r.getQueryData(t);if(n)return console.log("Using cached visual data for:",s),{data:n,fromCache:!0};console.log("Fetching visual data from network for:",s);const u=a.ue.loading("Loading visual...",{position:"top-center"});try{const i=await fetch(`${e}/management/v1/visuals/${s}`,{headers:{Authorization:`Bearer ${o}`}});if(!i.ok)throw new Error("Failed to load visual");const c=await i.json();return r.setQueryData(t,c),a.ue.dismiss(u),{data:c,fromCache:!1}}catch(i){throw a.ue.dismiss(u),i}}function q(e){if(typeof e=="string")return JSON.parse(e);if(typeof e=="object")return e;throw new Error("Invalid frame object format")}function Y(e,o){var n,u;const s=(e==null?void 0:e.frameObject)??((n=e==null?void 0:e.visual)==null?void 0:n.frameObject);if(!s)return!1;const r=q(s);if(!(r!=null&&r.cards)||r.cards.length===0)return!1;const t=(u=r.cards)==null?void 0:u.find(i=>i.id===r.activeCardId);return t?(a.setupEditorWithCard({...o,frame:r,card:t,visualId:(e==null?void 0:e.id)||r.visualId}),!0):!1}function Z(){const e=a.useEditorStore(r=>{var t;return((t=r.card.customCardPreferences)==null?void 0:t.url)||""}),o=G(e);return{getUpdatedFrame:p.useCallback(()=>{var g;B();const{frame:r,card:t,isDevMode:n,isShowingVisual:u,selectedSchemaName:i,selectedDatamodelId:c,selectedDatabaseName:h,selectedTableName:m,selectedConnectionId:C}=a.useEditorStore.getState(),y=t.sql,I=(g=o==null?void 0:o.getState())==null?void 0:g.settings,U=a.buildSavedEditorCard(t,{isDevMode:n,cardSql:y,isShowingVisual:u,selectedSchemaName:i,selectedDatamodelId:c,selectedDatabaseName:h,selectedTableName:m,selectedConnectionId:C,remoteChartSettings:I,stripConfig:X}),S=r.cards.map(b=>b.id===t.id?U:b);return{...r,cards:S,activeCardId:J(S,r.activeCardId)}},[o])}}function ee(){const{authToken:e,tokenProps:o}=a.useSemaphorContext(),s=a.useQueryClient(),r=a.useAddFrameWithFreshSemanticExecutionPayload(),t=a.useSelectedVisual(),{selectVisual:n}=a.useManagementActions(),{setFrame:u,setCard:i,setIsDevMode:c,initializeModeDrafts:h,setActiveTabCardId:m,updateDataSource:C,setQueryResultColumns:y,setSelectedConnectionId:I,setSelectedDatabaseName:U,setSelectedSchemaName:S,setSelectedTableName:g,setSelectedDatamodelId:b,setFilterValues:A,setInlineFilterValuesMap:P,setApplyFilters:M}=a.useEditorActions(),{setIsDashboardEditing:V,setIsVisualEditing:k,setSelectedFrameId:L,clearSelectedFrameId:T,setIsDashboardPanelOpen:j}=a.useDashboardActions(),E=a.useDashboardStore(d=>d.selectedSheetId),N=a.useDashboardStore(d=>d.selectedFrameId),R=a.useDashboardStore(d=>d.dashboard),W=a.useDashboardStore(d=>d.filterValues),$=a.useDashboardStore(d=>d.inlineFilterValuesMap),w=a.useVisualById((t==null?void 0:t.id)||"",{enabled:!!(t!=null&&t.id)&&!!(e!=null&&e.accessToken)}),z=p.useCallback(async d=>{try{n(d),T();const{data:f,fromCache:v}=await x(o.apiServiceUrl,(e==null?void 0:e.accessToken)||"",d.id,s);if(!Y(f,{setFrame:u,setCard:i,setIsDevMode:c,initializeModeDrafts:h,setActiveTabCardId:m,updateDataSource:C,setQueryResultColumns:y,setSelectedConnectionId:I,setSelectedDatabaseName:U,setSelectedSchemaName:S,setSelectedTableName:g,setSelectedDatamodelId:b,setFilterValues:A,setInlineFilterValuesMap:P,setApplyFilters:M,setIsDashboardEditing:V,setIsVisualEditing:k,dashboard:R,selectedSheetId:E,selectedFrameId:N,filterValues:W,inlineFilterValuesMap:$}))throw new Error("Failed to setup editor with visual data");return{success:!0,fromCache:v}}catch(f){return console.error("Error editing visual:",f),{success:!1,error:"Failed to load visual for editing"}}},[e==null?void 0:e.accessToken,o.apiServiceUrl,s,n,u,i,V,k,c,h,m,C,y,I,U,S,g,b,A,P,M,T,R,E,N,W,$]),H=p.useCallback(async d=>{var v;const f=l=>(a.ue.error(l),{success:!1,error:l});try{if(n(d),!E)return f("No sheet selected. Please select a sheet first.");const{data:l,fromCache:Q}=await x(o.apiServiceUrl,(e==null?void 0:e.accessToken)||"",d.id,s),O=(l==null?void 0:l.frameObject)??((v=l==null?void 0:l.visual)==null?void 0:v.frameObject);if(!O)return f("Visual has no frame data");const F=q(O);if(!(F!=null&&F.cards)||F.cards.length===0)return f("Visual frame is malformed");const _={...a.cloneLinkedFrameWithSourceMapping(F),visualId:d.id};return await r(E,_,"end"),V(!0),L(_.id),j(!1),{success:!0,fromCache:Q}}catch(l){return console.error("Error adding visual:",l),f(l instanceof Error?l.message:"Failed to add visual to dashboard")}},[e==null?void 0:e.accessToken,o.apiServiceUrl,s,n,E,V,L,j,r]);return{visual:w.data,isLoading:w.isLoading,isError:w.isError,error:w.error,handleEditLibraryVisual:z,handleAddLibraryVisual:H,getUpdatedFrame:Z().getUpdatedFrame,refetch:w.refetch}}exports.flushPendingEditorDrafts=B;exports.registerPendingEditorDraftFlusher=K;exports.useVisualUtils=ee;