react-semaphor 0.1.267 → 0.1.268

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 (35) hide show
  1. package/dist/chunks/{dashboard-controls-d8j31cnQ.js → dashboard-controls-D9FGH-ux.js} +108 -108
  2. package/dist/chunks/{dashboard-controls-BRv37g5w.js → dashboard-controls-DVZnpRK5.js} +1 -1
  3. package/dist/chunks/dashboard-filter-controls-button-CcrX4Kjv.js +11 -0
  4. package/dist/chunks/{dashboard-filter-controls-button-BOs9T2hG.js → dashboard-filter-controls-button-DdI-qlYl.js} +209 -199
  5. package/dist/chunks/{dashboard-json-DjNS3G-C.js → dashboard-json-1s8UpQRT.js} +1 -1
  6. package/dist/chunks/{dashboard-json-CnEYIbNI.js → dashboard-json-B9t11hsc.js} +1 -1
  7. package/dist/chunks/{dashboard-summary-settings-dialog-DOVwh8Cc.js → dashboard-summary-settings-dialog-BXJnm_OC.js} +1 -1
  8. package/dist/chunks/{dashboard-summary-settings-dialog-CrBOuggE.js → dashboard-summary-settings-dialog-BruCXCaN.js} +1 -1
  9. package/dist/chunks/{edit-dashboard-visual-D4UMcS6R.js → edit-dashboard-visual-C4HfjuuW.js} +7447 -6972
  10. package/dist/chunks/edit-dashboard-visual-DrdskRgR.js +193 -0
  11. package/dist/chunks/{index-D5jdzvu3.js → index-BrLm4rYX.js} +35935 -34785
  12. package/dist/chunks/{index-C2i6CRUk.js → index-DTw8TJ-8.js} +523 -326
  13. package/dist/chunks/{resource-management-panel-3XD0FrTD.js → resource-management-panel-C7hHyHwo.js} +16 -16
  14. package/dist/chunks/{resource-management-panel-ZK4SWoad.js → resource-management-panel-CLZBF-Dw.js} +1 -1
  15. package/dist/chunks/{use-create-flow-overlay-state-Bb83NOgW.js → use-create-flow-overlay-state-BrRL7vBF.js} +589 -591
  16. package/dist/chunks/use-create-flow-overlay-state-C6B_dReH.js +21 -0
  17. package/dist/chunks/{use-visual-utils-Bj7eAUMG.js → use-visual-utils-1cXtOxvS.js} +111 -123
  18. package/dist/chunks/use-visual-utils-CLCzIgCj.js +1 -0
  19. package/dist/dashboard/index.cjs +1 -1
  20. package/dist/dashboard/index.js +1 -1
  21. package/dist/index.cjs +1 -1
  22. package/dist/index.js +5 -5
  23. package/dist/style.css +1 -1
  24. package/dist/surfboard/index.cjs +1 -1
  25. package/dist/surfboard/index.js +2 -2
  26. package/dist/types/dashboard.d.ts +38 -0
  27. package/dist/types/main.d.ts +40 -0
  28. package/dist/types/shared.d.ts +38 -0
  29. package/dist/types/surfboard.d.ts +38 -0
  30. package/dist/types/types.d.ts +38 -0
  31. package/package.json +1 -1
  32. package/dist/chunks/dashboard-filter-controls-button-DKRyKRsP.js +0 -11
  33. package/dist/chunks/edit-dashboard-visual-D6RokBEF.js +0 -188
  34. package/dist/chunks/use-create-flow-overlay-state-Cmt64wFE.js +0 -21
  35. package/dist/chunks/use-visual-utils-Bdwejpa1.js +0 -1
@@ -0,0 +1,21 @@
1
+ "use strict";const e=require("./index-DTw8TJ-8.js"),t=require("react/jsx-runtime"),v=require("react"),G=require("./use-visual-utils-CLCzIgCj.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 xe=e.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 ie=e.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 de=e.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 W=e.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 J(){var p,C;const l=e.useEditorStore(b=>b.card),r=e.useEditorStore(b=>b.frame),n=v.useMemo(()=>e.findCustomVisualConfigCard(r,l),[r,l]),{manifest:d}=e.useCustomVisual(((p=n==null?void 0:n.customCardPreferences)==null?void 0:p.url)||""),u=v.useMemo(()=>{var b;return(b=d==null?void 0:d.visuals)==null?void 0:b.find(h=>{var y;return h.name===((y=n==null?void 0:n.customCardPreferences)==null?void 0:y.componentName)})},[d,(C=n==null?void 0:n.customCardPreferences)==null?void 0:C.componentName]),m=e.resolveMultiInputType(n,u),x=v.useMemo(()=>e.getCustomVisualInputCards({frame:r,configCard:n,isMultiInputVisual:m==="multiple"}),[r,n,m]),f=v.useMemo(()=>{const b=x.findIndex(h=>(h==null?void 0:h.id)===l.id);return b<0?-1:e.getSlotIndexForCard(l,b)},[x,l]);return v.useMemo(()=>!n||m!=="multiple"||f<0?l.type:e.getEffectiveCardTypeForSlot(l,f,u==null?void 0:u.slots)??l.type,[n,m,f,l,u==null?void 0:u.slots])}function he({type:l,isLinked:r,className:n,showLabel:d=!1,showLocal:u=!1}){const m=e.useDashboardStore(D=>D.selectedFrameId),x=e.useManagementStore(D=>D.selectedVisual),f=e.useEditorStore(D=>D.frame);let p;if(l)p=l;else if(r!==void 0)p=r?"linked":"library";else if(!!!(f!=null&&f.visualId||x!=null&&x.id)&&m)p="local";else if(x&&!m)p="library";else if(f!=null&&f.visualId&&m)p="linked";else if(x!=null&&x.id&&m)p="library";else return null;if(p==="local"&&!u)return null;const C={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."},h={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"},y={local:"fill-slate-50 dark:fill-slate-900",linked:"fill-purple-50 dark:fill-purple-950",library:"fill-blue-50 dark:fill-blue-950"},j={local:t.jsx("span",{className:"h-2 w-2 rounded-full bg-current/70"}),linked:t.jsx(de,{className:"h-3.5 w-3.5"}),library:t.jsx(ie,{className:"h-3.5 w-3.5"})},B={local:"Local",linked:"Linked",library:"Library"};return t.jsx(e.TooltipProvider,{children:t.jsxs(e.Tooltip,{delayDuration:300,children:[t.jsx(e.TooltipTrigger,{asChild:!0,children:t.jsxs(e.Badge,{variant:"outline",className:e.cn("cursor-help select-none transition-all",C[p],n),children:[j[p],d&&t.jsx("span",{className:"ml-1 text-xs font-medium leading-none",children:B[p]})]})}),t.jsxs(e.TooltipContent,{side:"bottom",className:e.cn("max-w-xs",h[p]),children:[t.jsx(e.TooltipArrow,{className:y[p]}),t.jsx("p",{children:b[p]})]})]})})}function fe(l,r){return{...l,sql:"",python:"",config:void 0,customCfg:"",preferences:{},interactionConfig:void 0,linkedInteractionTargetOverrides:void 0,dynamicCardPreferences:void 0,customCardPreferences:r?l.customCardPreferences:void 0,visualizationMode:"builtin",type:r?l.type:"bar"}}function Z(l){const r=e.getDynamicFrameSaveIssue(l);return r?(e.ue.error(r),!1):!0}function ye({className:l,variant:r="outline"}){const n=e.useEditorStore(m=>m.onSave),{getUpdatedFrame:d}=G.useVisualUtils();function u(){const m=d();Z(m)&&(n==null||n(m))}return t.jsxs(e.Button,{onClick:u,className:e.cn("h-8",l),size:"sm",variant:r,children:[t.jsx(e.Check,{className:"mr-2 size-4 font-bold"}),"Accept"]})}function be({className:l,variant:r="default"}){const n=e.useQueryClient(),[d,u]=v.useState(!1),m=e.useDashboardStore(y=>y.actions.setIsDashboardPanelOpen),{setIsVisualEditing:x}=e.useDashboardActions(),{getUpdatedFrame:f}=G.useVisualUtils(),p=e.useSelectedVisual(),C=e.useEditorStore(y=>y.frame),b=e.useUpdateVisualMutation(),h=()=>{const y=f();if(!Z(y))return;const j=(C==null?void 0:C.visualId)||(p==null?void 0:p.id);if(!j){e.ue.error("No visual to save");return}u(!0),b.mutate({visualId:j,data:{frameObject:y}},{onSuccess:()=>{u(!1),m(!0),e.ue.success("Visual updated successfully"),n.invalidateQueries({queryKey:["resource-by-id","visual",j],exact:!0})},onError:()=>{u(!1),e.ue.error("Failed to update visual")}})};return t.jsxs(e.Button,{onClick:h,className:e.cn("h-8",l),size:"sm",variant:r,children:[d&&t.jsxs(t.Fragment,{children:[t.jsx(e.LoaderCircle,{className:"mr-2 size-4 animate-spin font-bold"})," Saving"]}),!d&&t.jsxs(t.Fragment,{children:[t.jsx(W,{className:"mr-2 size-4 font-bold"}),"Save to Library"]})]})}function ge({className:l}){const r=e.useQueryClient(),[n,d]=v.useState(!1),u=e.useSelectedVisual(),m=e.useEditorStore(y=>y.frame),x=e.useDashboardStore(y=>y.selectedSheetId),{updateFrame:f,setIsVisualEditing:p}=e.useDashboardActions(),{getUpdatedFrame:C}=G.useVisualUtils(),b=e.useUpdateVisualMutation(),h=async()=>{if(!x){e.ue.error("No sheet selected");return}const y=(m==null?void 0:m.visualId)||(u==null?void 0:u.id);if(!y){e.ue.error("No visual to update");return}d(!0);try{const j=C();if(!Z(j)){d(!1);return}await b.mutateAsync({visualId:y,data:{frameObject:j}});const B={...j,visualId:y};f(x,B),r.invalidateQueries({queryKey:["visuals"]}),r.invalidateQueries({queryKey:["visual",y]}),e.ue.success("Saved to library and applied locally"),setTimeout(()=>{p(!1)},300)}catch(j){console.error("Failed to save and apply:",j),e.ue.error("Failed to save and apply changes")}finally{d(!1)}};return t.jsx(e.Button,{onClick:h,className:e.cn("h-8",l),size:"sm",variant:"default",disabled:n,children:n?t.jsxs(t.Fragment,{children:[t.jsx(e.LoaderCircle,{className:"mr-2 size-4 animate-spin font-bold"})," Saving..."]}):t.jsxs(t.Fragment,{children:[t.jsx(W,{className:"mr-2 size-4 font-bold"}),"Save & Apply"]})})}function ve({className:l}){const{setTempQueryData:r,setSqlGen:n}=e.useEditorActions(),d=e.useQueryClient(),u=e.useEditorStore(h=>h.tempQueryData),m=e.useEditorStore(h=>h.onClose),x=e.useEditorStore(h=>h.card),f=J(),p=v.useMemo(()=>f!==x.type?{...x,type:f}:x,[x,f]),{queryKey:C}=e.useDashboardCardQuery(p);function b(){if(u){const{queryKey:h,queryData:y}=u;h&&y&&d.setQueryData(h,y)}n({}),m==null||m()}return t.jsxs(e.Button,{onClick:b,className:e.cn("h-8",l),size:"sm",variant:"outline",children:[t.jsx(e.X,{className:"mr-2 size-4"}),"Close"]})}function Ce({label:l="Clear",variant:r="secondary",className:n}={}){const{setTempQueryData:d}=e.useEditorActions(),u=e.useQueryClient(),m=e.useEditorStore(a=>a.tempQueryData),x=e.useEditorStore(a=>a.card),f=J(),p=v.useMemo(()=>f!==x.type?{...x,type:f}:x,[x,f]),{queryKey:C}=e.useDashboardCardQuery(p),{setCardSql:b,setSqlGen:h,setCardPython:y,setCardCustomCfg:j,setCardPreferences:B,clearQueryConfig:D,setCardConfig:Y,setCardType:K,setFrame:z,setCard:q,setActiveTabCardId:P}=e.useEditorActions();function M(){var V,U,_,I;const a=u.getQueryData(C);m!=null&&m.queryData||d({queryKey:C,queryData:a}),u.setQueryData(C,null),u.removeQueries({queryKey:C,exact:!0}),b(""),h({}),D(),Y(void 0),y(""),j(""),B({});const N=e.useEditorStore.getState().frame,O=e.useEditorStore.getState().card,T=e.findCustomVisualConfigCard(N,O),E=((V=T==null?void 0:T.customCardPreferences)==null?void 0:V.visualType)==="multiple"||!!((U=T==null?void 0:T.customCardPreferences)!=null&&U.dataInputCardIds)||(((_=T==null?void 0:T.customCardPreferences)==null?void 0:_.minInputs)||0)>1||(((I=T==null?void 0:T.customCardPreferences)==null?void 0:I.maxInputs)||0)>1,F=fe(O,E);z({...N,cards:N.cards.map(L=>L.id===F.id?F:L)}),P(F.id),q(F),E||K("bar")}return t.jsxs(e.Button,{onClick:M,className:e.cn("h-8",n),size:"sm",variant:r,children:[t.jsx(e.X,{className:"mr-2 size-3.5"}),l]})}function oe(l){const{control:r,onChange:n}=l;return t.jsxs("div",{className:"space-y-1",children:[t.jsx(e.Label,{className:"text-xs",children:"Label"}),t.jsxs("div",{className:"relative",children:[t.jsx(e.Input,{className:"pr-40",value:r.label,placeholder:"Control label",onChange:d=>n(d.target.value)}),t.jsx(e.Badge,{variant:"outline",className:"pointer-events-none absolute right-3 top-1/2 -translate-y-1/2 text-xs",children:e.getFriendlyTypeOption(r.type).label})]})]})}function je(l){const{currentStep:r,labels:n}=l;return t.jsx("div",{className:"sticky top-0 z-10 -mx-1 border-b bg-background/95 px-1 pb-2 pt-1 backdrop-blur supports-[backdrop-filter]:bg-background/85",children:t.jsx("div",{className:"flex flex-wrap items-center gap-2 sm:gap-3",children:n.map((d,u)=>{const m=u+1,x=m===r,f=m<r;return t.jsxs(v.Fragment,{children:[t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx("span",{className:e.cn("flex h-7 w-7 items-center justify-center rounded-full border text-[11px] font-semibold",x?"border-primary bg-primary text-primary-foreground":f?"border-primary/25 bg-primary/10 text-primary":"border-border bg-muted/30 text-muted-foreground"),children:m}),t.jsx("span",{className:e.cn("text-xs font-medium",x?"text-foreground":"text-muted-foreground"),children:d})]}),u<n.length-1?t.jsx("span",{className:"h-px w-5 bg-border/80 sm:w-8","aria-hidden":"true"}):null]},d)})})})}function R(l){const{secondary:r,tertiary:n,primary:d}=l;return t.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:[r,n,d]})}function Se(l){const{control:r,scope:n,detail:d}=l;return t.jsxs("div",{className:"flex items-start gap-3 rounded-xl border border-border/40 bg-muted/20 p-3",children:[t.jsx(e.CircleCheck,{className:"mt-0.5 h-4 w-4 text-emerald-600"}),t.jsxs("div",{className:"space-y-1",children:[t.jsx("div",{className:"text-sm font-medium",children:r.label}),t.jsxs("div",{className:"text-xs text-muted-foreground",children:[e.getFriendlyTypeOption(r.type).label," ·"," ",e.getControlOptionPreview(r)," ·"," ",e.getPlacementLabel(n,r.placement)]}),d?t.jsx("div",{className:"text-xs text-muted-foreground",children:d}):null]})]})}function $(l){const{title:r,children:n,className:d}=l;return t.jsxs("div",{className:e.cn("space-y-1 rounded-xl border border-border/40 bg-muted/20 p-3",d),children:[t.jsx("div",{className:"text-xs font-medium uppercase tracking-wide text-muted-foreground",children:r}),n]})}function ke(l){const{createdReference:r,description:n}=l;return t.jsxs($,{title:"SQL cards",className:"space-y-2",children:[t.jsxs("div",{className:"flex items-center justify-between gap-2 rounded-md border border-border/30 bg-muted/40 px-3 py-2",children:[t.jsx("code",{className:"min-w-0 truncate text-xs",children:r}),t.jsx(e.CopyButton,{text:r,ariaLabel:"Copy SQL control reference"})]}),t.jsx("p",{className:"text-[11px] text-muted-foreground",children:n})]})}function re(l){const{control:r,defaultValue:n,availableFieldChoices:d,availableMetricChoices:u,onControlChange:m,onLabelChange:x,onDefaultValueChange:f,onBack:p,onNext:C,nextDisabled:b}=l;return t.jsxs("div",{className:"space-y-3",children:[t.jsx(oe,{control:r,onChange:x}),t.jsx(e.ControlDefinitionOptionsEditor,{control:r,availableFieldChoices:d,availableMetricChoices:u,onChange:m}),t.jsx(e.ControlDefaultValueEditor,{control:r,value:n,onChange:f,allowCardDefault:!0,hint:"This is the value viewers will see first."}),t.jsx(R,{secondary:t.jsx(e.Button,{type:"button",variant:"outline",onClick:p,children:"Back"}),primary:t.jsx(e.Button,{type:"button",onClick:C,disabled:b,children:"Next"})})]})}function ne(l){const{control:r,scope:n,createdReference:d,explorerContent:u,sqlDescription:m,summaryDetail:x,onBack:f,onCancel:p,onDone:C}=l;return t.jsxs("div",{className:"space-y-4",children:[t.jsx(Se,{control:r,scope:n,detail:x}),t.jsxs("div",{className:"space-y-2",children:[t.jsx("p",{className:"text-sm font-medium",children:"How cards use this control"}),u,t.jsx(ke,{createdReference:d,description:m})]}),t.jsx(R,{secondary:t.jsx(e.Button,{type:"button",variant:"outline",onClick:f,children:"Back"}),tertiary:t.jsx(e.Button,{type:"button",variant:"outline",onClick:p,children:"Cancel"}),primary:t.jsx(e.Button,{type:"button",onClick:C,children:"Done"})})]})}function Ne(l){const r=e.createBlankControl(l.scope,l.existingControls,l.reservedIds),n=l.type===r.type?{...r,label:e.DEFAULT_LABEL_BY_TYPE[l.type]}:{...e.applyControlTypeChange({controls:[{...r,label:e.DEFAULT_LABEL_BY_TYPE[l.type]}],controlId:r.id,nextType:l.type}).controls[0],label:e.DEFAULT_LABEL_BY_TYPE[l.type]};return{step:2,control:n,defaultValue:e.getDefaultValueForType(n,void 0)}}function De({scope:l,controls:r,reservedControlIds:n,defaultValues:d,onChange:u,emptyMessage:m,initialCreateFlow:x=!1,usageByControlId:f,availableFieldChoices:p,availableMetricChoices:C,structuralParticipants:b,structuralParticipantIdsByControlId:h,card:y,onCreateFlowActiveChange:j,onCreateFlowComplete:B}){const D=v.useMemo(()=>new Set(n||[]),[n]),Y=e.getPlacementOptionsForScope(l),K=e.getDefaultPlacement(l),[z,q]=v.useState(null),[P,M]=v.useState(null),[a,N]=v.useState(()=>x?{step:1,control:e.createBlankControl(l,r,Array.from(D))}:null),O=v.useRef(x),T=v.useMemo(()=>e.getFriendlyControlTypeOptions({scope:l,card:y}),[y,l]),E=v.useCallback(s=>l==="dashboard"&&(s==="field_selector"||s==="metric_selector"),[l]),F=v.useMemo(()=>a?e.getEligibleParticipantsForStructuralControl(b||[],a.control.type):[],[a,b]),V=v.useMemo(()=>{if(!a)return{fields:p||[],metrics:C||[]};if(!E(a.control.type))return{fields:p||[],metrics:C||[]};const s=a.selectedCardIds||[],c=e.getCompatibleStructuralChoiceCatalog({controlType:a.control.type,participants:b||[],selectedCardIds:s});return{fields:a.control.type==="field_selector"?c.choices.map(o=>({option:o,target:c.fieldTargetMap[o.value]})):[],metrics:a.control.type==="metric_selector"?c.choices.map(o=>({option:o,target:c.metricTargetMap[o.value]})):[]}},[p,C,a,E,b]);v.useEffect(()=>{j==null||j(!!a)},[a,j]),v.useEffect(()=>{const s=x&&!O.current;O.current=x,s&&(N({step:1,control:e.createBlankControl(l,r,Array.from(D))}),M(null),q(null))},[r,x,D,l]);const U=s=>{if(!E(s.type))return{fields:p||[],metrics:C||[]};const c=(h==null?void 0:h[s.id])||[];if(c.length===0)return{fields:p||[],metrics:C||[]};const o=e.getCompatibleStructuralChoiceCatalog({controlType:s.type,participants:b||[],selectedCardIds:c});return{fields:s.type==="field_selector"?o.choices.map(g=>({option:g,target:o.fieldTargetMap[g.value]})):[],metrics:s.type==="metric_selector"?o.choices.map(g=>({option:g,target:o.metricTargetMap[g.value]})):[]}},_=s=>{if(!E(s.control.type))return{nextControl:s.control,cardBindingsById:void 0};const c=(h==null?void 0:h[s.control.id])||[],o=e.getCompatibleStructuralChoiceCatalog({controlType:s.control.type,participants:b||[],selectedCardIds:s.nextSelectedCardIds}),g=e.reconcileStructuralControlChoices({control:s.control,choices:o.choices}),S=Object.fromEntries(c.filter(i=>!s.nextSelectedCardIds.includes(i)).map(i=>[i,void 0]));return s.nextSelectedCardIds.length>0&&g.source.kind==="manual"&&g.source.options.length>0&&Object.assign(S,e.buildStructuralControlBindingsForParticipants({control:g,participants:b||[],selectedCardIds:s.nextSelectedCardIds})),{nextControl:g,cardBindingsById:S}},I=v.useCallback((s,c=d,o={type:"update"})=>{u(s,c,o)},[d,u]),L=(s,c)=>{const o=r.find(w=>w.id===s);let g=r.map(w=>w.id!==s?w:c(w));const S=g.find(w=>w.id===s);let i,k;if(S&&l==="dashboard"&&(S.type==="field_selector"||S.type==="metric_selector")){const w=(h==null?void 0:h[S.id])||[],A=_({control:S,nextSelectedCardIds:w});g=g.map(le=>le.id===s?A.nextControl:le),i=A.cardBindingsById,k=[S.id]}else if(o&&l==="dashboard"&&(o.type==="field_selector"||o.type==="metric_selector")){const w=(h==null?void 0:h[o.id])||[];i=Object.fromEntries(w.map(A=>[A,void 0])),k=[o.id]}I(g,d,{type:"update",cardBindingsById:i,affectedBindingControlIds:k})},ce=(s,c)=>{const o=c.trim();if(o.length===0||o===s||D.has(o)||r.some(i=>i.id===o&&i.id!==s))return;const g=r.map(i=>i.id===s?{...i,id:o}:i);if(!d){I(g,void 0,{type:"rename",oldId:s,newId:o});return}const S={...d};Object.prototype.hasOwnProperty.call(S,s)&&(S[o]=S[s],delete S[s]),I(g,S,{type:"rename",oldId:s,newId:o})},ue=s=>{const c=r.filter(g=>g.id!==s);if(!d){I(c,void 0,{type:"remove",controlId:s});return}const o={...d};delete o[s],I(c,o,{type:"remove",controlId:s})},pe=v.useCallback(()=>{N({step:1,control:e.createBlankControl(l,r,Array.from(D))}),M(null),q(null)},[r,D,l]),Q=s=>{N(c=>c&&{...c,control:s(c.control)})},ee=s=>{N(c=>c&&{...c,defaultValue:s})},H=(()=>{if(!a)return!1;if(a.step===2&&E(a.control.type))return(a.selectedCardIds||[]).length>0;if(a.step!==2&&a.step!==3||!a.control.label.trim())return!1;const c=e.ensureManualSource(a.control);return c.source.kind==="manual"&&(e.needsManualOptions(c)&&c.source.options.length===0||c.source.options.some(g=>g.label.trim().length===0||g.value.trim().length===0))?!1:e.hasConcreteDefaultValue(e.getDefaultValueForType(c,a.defaultValue))})(),te=()=>{var i;if(!a)return;const s=e.ensureManualSource(a.control),c=e.deriveUniqueControlId({label:s.label,fallbackId:s.id,existingControls:r,reservedIds:Array.from(D)}),o={...s,id:c},g=l==="dashboard"&&(o.type==="field_selector"||o.type==="metric_selector")&&((i=a.selectedCardIds)!=null&&i.length)?e.buildStructuralControlBindingsForParticipants({control:o,participants:b||[],selectedCardIds:a.selectedCardIds}):void 0,S=e.getDefaultValueForType(o,a.defaultValue);N({step:l==="dashboard"&&(o.type==="field_selector"||o.type==="metric_selector")?4:3,control:o,defaultValue:S,createdControlId:c,selectedCardIds:a.selectedCardIds,cardBindingsById:g})},X=v.useCallback(()=>{N(null)},[]),se=v.useCallback(()=>{if(!(a!=null&&a.createdControlId)){N(null);return}const s=a.control,c=a.createdControlId,o=e.getDefaultValueForType(s,a.defaultValue);d?I([...r,s],{...d,[c]:o},{type:"add",cardBindingsById:a.cardBindingsById}):I([...r,{...s,defaultValue:o}],void 0,{type:"add",cardBindingsById:a.cardBindingsById}),M(c),N(null),B==null||B()},[r,a,d,I,B]),me=a?E(a.control.type)?["Choose type","Select cards","Configure","Finish"]:["Choose type","Configure","Finish"]:[],ae=a!=null&&a.createdControlId?`[[param.${a.createdControlId}]]`:a?`[[param.${e.slugifyControlValue(a.control.label)||a.control.id}]]`:"";return t.jsxs("div",{className:"space-y-4",children:[a?t.jsxs("div",{className:"space-y-4 pb-1",children:[t.jsx(je,{currentStep:a.step,labels:me}),a.step===1&&t.jsxs("div",{className:"space-y-4",children:[t.jsxs("div",{children:[t.jsx("p",{className:"text-sm font-medium",children:"What kind of input should viewers see?"}),t.jsx("p",{className:"text-xs text-muted-foreground",children:"Choose the viewer experience first. You can fine-tune the details next."}),l==="card"&&(y==null?void 0:y.sql)==null?t.jsx("p",{className:"mt-1 text-xs text-muted-foreground",children:"Explorer cards support displayed metric, group by field, aggregation, and time grain controls here."}):null]}),t.jsx("div",{className:"grid gap-3 sm:grid-cols-2",children:T.map(s=>t.jsxs("button",{type:"button",className:"rounded-xl border border-border/50 bg-muted/20 p-3 text-left transition-colors hover:border-border/70 hover:bg-muted/35",onClick:()=>N(Ne({scope:l,existingControls:r,reservedIds:Array.from(D),type:s.value})),children:[t.jsx("div",{className:"text-sm font-medium",children:s.label}),t.jsx("p",{className:"mt-1 text-xs text-muted-foreground",children:s.description})]},s.value))}),t.jsx(R,{secondary:t.jsx(e.Button,{type:"button",variant:"outline",onClick:X,children:"Back to controls"})})]}),a.step===2&&E(a.control.type)&&t.jsxs("div",{className:"space-y-3",children:[t.jsxs("div",{className:"space-y-3",children:[t.jsx(oe,{control:a.control,onChange:s=>Q(c=>({...c,label:s}))}),t.jsx("p",{className:"text-xs text-muted-foreground",children:"Choose which cards should respond to this shared control."})]}),F.length===0?t.jsx("div",{className:"rounded-xl bg-muted/20 p-3 text-xs text-muted-foreground",children:"No eligible cards are available yet. Add compatible metrics or group-by fields to cards first."}):t.jsx("div",{className:"space-y-2 rounded-xl bg-muted/20 p-3",children:F.map(s=>{const c=(a.selectedCardIds||[]).includes(s.cardId);return t.jsxs("label",{className:"flex items-start gap-2 text-sm",children:[t.jsx(e.Checkbox,{checked:c,onCheckedChange:o=>N(g=>g&&{...g,selectedCardIds:o===!0?[...g.selectedCardIds||[],s.cardId]:(g.selectedCardIds||[]).filter(S=>S!==s.cardId)})}),t.jsxs("div",{className:"min-w-0",children:[t.jsx("div",{className:"font-medium",children:s.title}),t.jsx("div",{className:"text-xs text-muted-foreground",children:a.control.type==="field_selector"?`${s.fieldChoices.length} compatible group-by fields`:`${s.metricChoices.length} compatible metrics`})]})]},s.cardId)})}),t.jsx(R,{secondary:t.jsx(e.Button,{type:"button",variant:"outline",onClick:()=>N(s=>s&&{...s,step:1,selectedCardIds:[]}),children:"Back"}),primary:t.jsx(e.Button,{type:"button",onClick:()=>N(s=>s&&{...s,step:3}),disabled:!H,children:"Next"})})]}),a.step===2&&!E(a.control.type)&&t.jsx(re,{control:a.control,defaultValue:a.defaultValue,availableFieldChoices:V.fields,availableMetricChoices:V.metrics,onControlChange:s=>Q(()=>s),onLabelChange:s=>Q(c=>({...c,label:s})),onDefaultValueChange:ee,onBack:()=>N(s=>s&&{...s,step:1}),onNext:te,nextDisabled:!H}),a.step===3&&E(a.control.type)&&t.jsx(re,{control:a.control,defaultValue:a.defaultValue,availableFieldChoices:V.fields,availableMetricChoices:V.metrics,onControlChange:s=>Q(()=>s),onLabelChange:s=>Q(c=>({...c,label:s})),onDefaultValueChange:ee,onBack:()=>N(s=>s&&{...s,step:2}),onNext:te,nextDisabled:!H}),a.step===3&&!E(a.control.type)&&t.jsx(ne,{control:a.control,scope:l,createdReference:ae,explorerContent:t.jsx($,{title:"Explorer cards",children:t.jsxs("p",{className:"text-sm",children:["Open the card and use"," ",t.jsx("span",{className:"font-medium",children:"Settings → Controls"})," ","to choose what this control changes."]})}),sqlDescription:"Reference this control directly in the SQL editor.",onBack:()=>N(s=>s&&{...s,step:2}),onCancel:X,onDone:se}),a.step===4&&E(a.control.type)&&t.jsx(ne,{control:a.control,scope:l,createdReference:ae,summaryDetail:t.jsxs(t.Fragment,{children:["Used by ",(a.selectedCardIds||[]).length," ","selected card",(a.selectedCardIds||[]).length===1?"":"s"]}),explorerContent:t.jsx($,{title:"Explorer cards",children:t.jsx("p",{className:"text-sm",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:()=>N(s=>s&&{...s,step:3}),onCancel:X,onDone:se})]}):null,!a&&r.length===0?t.jsx("div",{className:"rounded-md border border-dashed p-3 text-sm text-muted-foreground",children:m}):null,!a&&r.map(s=>{const c=U(s),o=f==null?void 0:f[s.id],g=d&&Object.prototype.hasOwnProperty.call(d,s.id)?d[s.id]:s.defaultValue,S=P===s.id;return t.jsxs("div",{className:"rounded-md border",children:[t.jsxs("div",{className:"flex items-center gap-2 px-3 py-3",children:[t.jsxs("button",{type:"button",className:"flex min-w-0 flex-1 items-start gap-2 text-left",onClick:()=>M(i=>i===s.id?null:s.id),children:[S?t.jsx(e.ChevronDown,{className:"mt-0.5 h-4 w-4 shrink-0 text-muted-foreground"}):t.jsx(e.ChevronRight,{className:"mt-0.5 h-4 w-4 shrink-0 text-muted-foreground"}),t.jsxs("div",{className:"min-w-0",children:[t.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[t.jsx("span",{className:"truncate text-sm font-medium",children:s.label||"Untitled control"}),t.jsx(e.Badge,{variant:"outline",className:"text-[11px]",children:e.getFriendlyTypeOption(s.type).label}),t.jsx(e.Badge,{variant:"secondary",className:"text-[11px]",children:e.getPlacementLabel(l,s.placement)})]}),t.jsxs("div",{className:"mt-1 text-xs text-muted-foreground",children:[e.getControlOptionPreview(s),o!=null&&o.status?` · ${o.status}`:""]})]})]}),t.jsx(e.Button,{type:"button",size:"icon",variant:"ghost",className:"h-8 w-8 shrink-0",onClick:()=>ue(s.id),"aria-label":`Remove ${s.label}`,children:t.jsx(e.Trash2,{className:"h-4 w-4"})})]}),S&&t.jsxs("div",{className:"space-y-4 border-t px-3 py-4",children:[o!=null&&o.helper?t.jsx("div",{className:"rounded-md bg-muted/30 px-3 py-2 text-xs text-muted-foreground",children:o.helper}):null,t.jsxs("div",{className:"grid gap-3 md:grid-cols-3",children:[t.jsxs("div",{className:"space-y-1.5",children:[t.jsx(e.Label,{className:"text-xs",children:"Label"}),t.jsx(e.Input,{value:s.label,placeholder:"Control label",onChange:i=>L(s.id,k=>({...k,label:i.target.value}))})]}),t.jsxs("div",{className:"space-y-1.5",children:[t.jsx(e.Label,{className:"text-xs",children:"Type"}),t.jsxs(e.Select,{value:s.type,onValueChange:i=>{const k=e.applyControlTypeChange({controls:r,controlId:s.id,nextType:i,defaultValues:d});I(k.controls,k.defaultValues)},children:[t.jsx(e.SelectTrigger,{children:t.jsx(e.SelectValue,{})}),t.jsx(e.SelectContent,{children:e.getFriendlyControlTypeOptions({scope:l,card:y,includeType:s.type}).map(i=>t.jsx(e.SelectItem,{value:i.value,children:i.label},i.value))})]})]}),t.jsxs("div",{className:"space-y-1.5",children:[t.jsx(e.Label,{className:"text-xs",children:"Show in"}),t.jsxs(e.Select,{value:s.placement||K,onValueChange:i=>L(s.id,k=>({...k,placement:i})),children:[t.jsx(e.SelectTrigger,{children:t.jsx(e.SelectValue,{})}),t.jsx(e.SelectContent,{children:Y.map(i=>t.jsx(e.SelectItem,{value:i.value,children:i.label},i.value))})]})]})]}),E(s.type)?t.jsx(e.StructuralParticipantSelector,{type:s.type,participants:e.getEligibleParticipantsForStructuralControl(b||[],s.type).map(i=>({cardId:i.cardId,title:i.title,choiceCount:s.type==="field_selector"?i.fieldChoices.length:i.metricChoices.length})),selectedCardIds:(h==null?void 0:h[s.id])||[],onChange:i=>{const k=_({control:s,nextSelectedCardIds:i}),w=r.map(A=>A.id===s.id?k.nextControl:A);I(w,d,{type:"update",cardBindingsById:k.cardBindingsById})}}):null,t.jsx(e.ControlDefinitionOptionsEditor,{control:s,availableFieldChoices:c.fields,availableMetricChoices:c.metrics,onChange:i=>L(s.id,()=>i)}),s.initialValueStrategy==="saved_default"&&t.jsx(e.ControlDefaultValueEditor,{control:s,value:g,allowNoDefault:!0,allowCardDefault:!0,onChange:i=>{if(d){const k={...d};i===void 0?delete k[s.id]:k[s.id]=i,I(r,k);return}L(s.id,k=>({...k,defaultValue:i}))}}),t.jsxs(e.Collapsible,{open:z===s.id,onOpenChange:i=>q(i?s.id:null),children:[t.jsx(e.CollapsibleTrigger,{asChild:!0,children:t.jsxs(e.Button,{type:"button",variant:"ghost",className:"h-auto px-0 text-xs text-muted-foreground hover:bg-transparent",children:[z===s.id?t.jsx(e.ChevronDown,{className:"mr-1 h-4 w-4"}):t.jsx(e.ChevronRight,{className:"mr-1 h-4 w-4"}),"Advanced"]})}),t.jsxs(e.CollapsibleContent,{className:"space-y-3 pt-2",children:[t.jsxs("div",{className:"grid gap-3 md:grid-cols-2",children:[t.jsxs("div",{className:"space-y-1.5",children:[t.jsx(e.Label,{className:"text-xs",children:"Control ID"}),t.jsx(e.ControlIdInput,{controlId:s.id,onCommit:i=>ce(s.id,i)},s.id)]}),t.jsxs("div",{className:"space-y-1.5",children:[t.jsx(e.Label,{className:"text-xs",children:"Initial value"}),t.jsxs(e.Select,{value:s.initialValueStrategy,onValueChange:i=>L(s.id,k=>({...k,initialValueStrategy:i})),children:[t.jsx(e.SelectTrigger,{children:t.jsx(e.SelectValue,{})}),t.jsx(e.SelectContent,{children:e.INITIAL_VALUE_STRATEGY_OPTIONS.map(i=>t.jsx(e.SelectItem,{value:i.value,children:i.label},i.value))})]}),t.jsx("p",{className:"text-[11px] text-muted-foreground",children:e.getInitialValueStrategyHint(s.initialValueStrategy)})]})]}),t.jsx(e.ControlVisibilitySettings,{control:s,onChange:i=>L(s.id,()=>i)})]})]})]})]},s.id)}),!a&&t.jsxs(e.Button,{type:"button",variant:"outline",size:"sm",onClick:pe,children:[t.jsx(e.Plus,{className:"mr-2 h-4 w-4"}),"Add control"]})]})}function Ee(l){const{open:r,onOpenChange:n,initialCreateFlowActive:d=!1}=l,u=r!==void 0,[m,x]=v.useState(!1),[f,p]=v.useState(d),C=u?r:m,b=v.useCallback(j=>{!j&&f||(u||x(j),j||p(!1),n==null||n(j))},[u,f,n]),h=v.useCallback(()=>{u||x(!1),p(!1),n==null||n(!1)},[u,n]);v.useEffect(()=>{C||p(!1)},[C]);const y=v.useCallback(j=>{f&&j.preventDefault()},[f]);return{forceClose:h,handleOpenChange:b,isCreateFlowActive:f,preventPassiveDismissDuringCreate:y,resolvedOpen:C,setIsCreateFlowActive:p}}exports.CircleX=xe;exports.ControlDefinitionListEditor=De;exports.EditorAcceptButton=ye;exports.EditorCancelButton=ve;exports.EditorClearButton=Ce;exports.Library=ie;exports.Link2=de;exports.Save=W;exports.VisualBadge=he;exports.VisualSaveAndApplyButton=ge;exports.VisualSaveButton=be;exports.useCreateFlowOverlayState=Ee;exports.useEffectiveEditorCardType=J;
@@ -1,24 +1,24 @@
1
- import { G as K, b as Y, H as X, J as Z, K as q, M as _, N as ee, u as U, O as te, Q as re, x as M, T as se, U as f } from "./index-D5jdzvu3.js";
2
- import { useState as H, useEffect as oe, useCallback as D } from "react";
3
- function ae(e) {
1
+ import { G as K, b as Y, H as X, J as Z, K as q, M as _, N as ee, u as F, O as te, Q as re, x as M, T as se, U as f, V as oe } from "./index-BrLm4rYX.js";
2
+ import { useState as H, useEffect as ae, useCallback as N } from "react";
3
+ function ne(e) {
4
4
  const a = e.toUpperCase().indexOf("WHERE"), t = e.toUpperCase().indexOf("GROUP BY"), r = e.toUpperCase().indexOf("LIMIT"), s = e.toUpperCase().indexOf("ORDER BY");
5
5
  let n = e.length;
6
6
  if (s !== -1 && (n = s), r !== -1 && r < n && (n = r), a !== -1) {
7
- const i = e.substring(0, a), o = e.substring(a);
8
- return `${i} {{ filters | where }} AND ${o.substring(
7
+ const c = e.substring(0, a), o = e.substring(a);
8
+ return `${c} {{ filters | where }} AND ${o.substring(
9
9
  6
10
10
  )}`;
11
11
  } else if (t !== -1) {
12
- const i = e.substring(0, t), o = e.substring(t);
13
- return `${i} {{ filters | where }} ${o}`;
12
+ const c = e.substring(0, t), o = e.substring(t);
13
+ return `${c} {{ filters | where }} ${o}`;
14
14
  } else {
15
- const i = e.substring(0, n), o = e.substring(n);
16
- return console.log("beforeClause", i), console.log("afterClause", o), o ? `${i} {{ filters | where }} ${o}` : `${i.replace(/;$/, "")} {{ filters | where }}`;
15
+ const c = e.substring(0, n), o = e.substring(n);
16
+ return console.log("beforeClause", c), console.log("afterClause", o), o ? `${c} {{ filters | where }} ${o}` : `${c.replace(/;$/, "")} {{ filters | where }}`;
17
17
  }
18
18
  }
19
- function ne(e) {
19
+ function ie(e) {
20
20
  const [a, t] = H(null), [r, s] = H(null), n = K();
21
- return oe(() => {
21
+ return ae(() => {
22
22
  if (!e || e.trim() === "") {
23
23
  t(null), s(null);
24
24
  return;
@@ -40,14 +40,14 @@ function ne(e) {
40
40
  throw new Error(`Module not found at ${d}`);
41
41
  } catch {
42
42
  }
43
- const m = await import(
43
+ const h = await import(
44
44
  /* @vite-ignore */
45
45
  /* webpackIgnore: true */
46
46
  d
47
47
  );
48
- if (typeof m.useChartStore != "function")
48
+ if (typeof h.useChartStore != "function")
49
49
  throw new Error("useChartStore is not a function");
50
- t(() => m.useChartStore), s(null);
50
+ t(() => h.useChartStore), s(null);
51
51
  } catch (o) {
52
52
  const d = o instanceof Error ? o.message : "Unknown error";
53
53
  console.error("Failed to load remote chart store:", d), s(d), t(null);
@@ -73,8 +73,8 @@ function ce(e, a) {
73
73
  if (s == "All__Header")
74
74
  return e[0].id;
75
75
  if (s && s.endsWith("__Header")) {
76
- const i = s.split("__")[0], o = e.find(
77
- (d) => d.tabTitle === i
76
+ const c = s.split("__")[0], o = e.find(
77
+ (d) => d.tabTitle === c
78
78
  );
79
79
  return o ? o.id : e[0].id;
80
80
  }
@@ -83,7 +83,7 @@ function ce(e, a) {
83
83
  }
84
84
  return e[0].id;
85
85
  }
86
- const ie = (e) => {
86
+ const de = (e) => {
87
87
  if (!e || !("detailTableBackup" in e))
88
88
  return e;
89
89
  const { detailTableBackup: a, ...t } = e;
@@ -96,7 +96,7 @@ async function Q(e, a, t, r) {
96
96
  if (n)
97
97
  return console.log("Using cached visual data for:", t), { data: n, fromCache: !0 };
98
98
  console.log("Fetching visual data from network for:", t);
99
- const i = M.loading("Loading visual...", {
99
+ const c = M.loading("Loading visual...", {
100
100
  position: "top-center"
101
101
  });
102
102
  try {
@@ -111,9 +111,9 @@ async function Q(e, a, t, r) {
111
111
  if (!o.ok)
112
112
  throw new Error("Failed to load visual");
113
113
  const d = await o.json();
114
- return r.setQueryData(s, d), M.dismiss(i), { data: d, fromCache: !1 };
114
+ return r.setQueryData(s, d), M.dismiss(c), { data: d, fromCache: !1 };
115
115
  } catch (o) {
116
- throw M.dismiss(i), o;
116
+ throw M.dismiss(c), o;
117
117
  }
118
118
  }
119
119
  function G(e) {
@@ -123,15 +123,15 @@ function G(e) {
123
123
  return e;
124
124
  throw new Error("Invalid frame object format");
125
125
  }
126
- function de(e, a) {
127
- var n, i;
126
+ function le(e, a) {
127
+ var n, c;
128
128
  const t = (e == null ? void 0 : e.frameObject) ?? ((n = e == null ? void 0 : e.visual) == null ? void 0 : n.frameObject);
129
129
  if (!t)
130
130
  return !1;
131
131
  const r = G(t);
132
132
  if (!(r != null && r.cards) || r.cards.length === 0)
133
133
  return !1;
134
- const s = (i = r.cards) == null ? void 0 : i.find(
134
+ const s = (c = r.cards) == null ? void 0 : c.find(
135
135
  (o) => o.id === r.activeCardId
136
136
  );
137
137
  return s ? (se({
@@ -141,47 +141,36 @@ function de(e, a) {
141
141
  visualId: (e == null ? void 0 : e.id) || r.visualId
142
142
  }), !0) : !1;
143
143
  }
144
- function le() {
144
+ function ue() {
145
145
  var g;
146
- const { setCardSql: e } = _(), a = f((c) => c.frame), t = f((c) => c.card), r = f((c) => c.isDevMode), s = ne(
146
+ const { setCardSql: e } = _(), a = f((i) => i.frame), t = f((i) => i.card), r = f((i) => i.isDevMode), s = ie(
147
147
  ((g = t.customCardPreferences) == null ? void 0 : g.url) || ""
148
148
  ), n = f(
149
- (c) => c.selectedSchemaName
150
- ), i = f(
151
- (c) => c.selectedDatamodelId
149
+ (i) => i.selectedSchemaName
150
+ ), c = f(
151
+ (i) => i.selectedDatamodelId
152
152
  ), o = f(
153
- (c) => c.selectedDatabaseName
154
- ), d = f((c) => c.selectedTableName), m = f(
155
- (c) => c.selectedConnectionId
156
- ), h = f((c) => c.isShowingVisual), p = t.sql;
157
- return { getUpdatedFrame: D(() => {
158
- var w;
159
- let c = p;
160
- p && !p.includes("{{") && (c = ae(p), e(c));
161
- const S = (w = s == null ? void 0 : s.getState()) == null ? void 0 : w.settings, v = {
162
- ...t,
163
- dataSource: t.dataSource || { mode: "directSource" },
164
- lastSelectedSchema: n,
165
- lastSelectedDatamodelId: i,
166
- lastSelectedDatabase: o,
167
- lastSelectedTable: d,
168
- connectionId: m,
169
- // Only save sql/python if in dev mode
170
- sql: r ? c : void 0,
171
- python: r ? t.python : void 0,
172
- // Only save config if in standard mode
173
- config: r ? void 0 : ie(t.config),
174
- customCfg: h ? t.customCfg : null,
175
- preferences: t.preferences,
176
- // Preserve all preferences including column sizing
177
- ...S && {
178
- customCardPreferences: {
179
- ...t.customCardPreferences,
180
- settings: S
181
- }
182
- }
183
- }, C = a.cards.map(
184
- (I) => I.id === t.id ? v : I
153
+ (i) => i.selectedDatabaseName
154
+ ), d = f((i) => i.selectedTableName), h = f(
155
+ (i) => i.selectedConnectionId
156
+ ), m = f((i) => i.isShowingVisual), p = t.sql;
157
+ return { getUpdatedFrame: N(() => {
158
+ var S;
159
+ let i = p;
160
+ p && !p.includes("{{") && (i = ne(p), e(i));
161
+ const U = (S = s == null ? void 0 : s.getState()) == null ? void 0 : S.settings, v = oe(t, {
162
+ isDevMode: r,
163
+ cardSql: i,
164
+ isShowingVisual: m,
165
+ selectedSchemaName: n,
166
+ selectedDatamodelId: c,
167
+ selectedDatabaseName: o,
168
+ selectedTableName: d,
169
+ selectedConnectionId: h,
170
+ remoteChartSettings: U,
171
+ stripConfig: de
172
+ }), C = a.cards.map(
173
+ (w) => w.id === t.id ? v : w
185
174
  );
186
175
  return {
187
176
  ...a,
@@ -192,12 +181,12 @@ function le() {
192
181
  t,
193
182
  a,
194
183
  r,
195
- h,
184
+ m,
196
185
  n,
197
- i,
186
+ c,
198
187
  o,
199
188
  d,
200
- m,
189
+ h,
201
190
  e,
202
191
  s,
203
192
  p
@@ -206,64 +195,64 @@ function le() {
206
195
  function me() {
207
196
  const { authToken: e, tokenProps: a } = Y(), t = X(), r = Z(), { selectVisual: s } = q(), {
208
197
  setFrame: n,
209
- setCard: i,
198
+ setCard: c,
210
199
  setIsDevMode: o,
211
200
  initializeModeDrafts: d,
212
- setActiveTabCardId: m,
213
- updateDataSource: h,
201
+ setActiveTabCardId: h,
202
+ updateDataSource: m,
214
203
  setQueryResultColumns: p,
215
204
  setSelectedConnectionId: $,
216
205
  setSelectedDatabaseName: g,
217
- setSelectedSchemaName: c,
218
- setSelectedTableName: S,
206
+ setSelectedSchemaName: i,
207
+ setSelectedTableName: U,
219
208
  setSelectedDatamodelId: v,
220
209
  setFilterValues: C,
221
- setInlineFilterValuesMap: w,
222
- setApplyFilters: I
210
+ setInlineFilterValuesMap: S,
211
+ setApplyFilters: w
223
212
  } = _(), {
224
213
  setIsDashboardEditing: V,
225
- setIsVisualEditing: N,
226
- setSelectedFrameId: O,
227
- clearSelectedFrameId: T,
228
- addFrame: x,
229
- setIsDashboardPanelOpen: A
230
- } = ee(), y = U((l) => l.selectedSheetId), B = U((l) => l.selectedFrameId), P = U((l) => l.dashboard), R = U((l) => l.filterValues), W = U(
214
+ setIsVisualEditing: O,
215
+ setSelectedFrameId: x,
216
+ clearSelectedFrameId: A,
217
+ addFrame: T,
218
+ setIsDashboardPanelOpen: B
219
+ } = ee(), I = F((l) => l.selectedSheetId), D = F((l) => l.selectedFrameId), R = F((l) => l.dashboard), W = F((l) => l.filterValues), L = F(
231
220
  (l) => l.inlineFilterValuesMap
232
- ), E = te((r == null ? void 0 : r.id) || "", {
221
+ ), y = te((r == null ? void 0 : r.id) || "", {
233
222
  enabled: !!(r != null && r.id) && !!(e != null && e.accessToken)
234
- }), z = D(
223
+ }), z = N(
235
224
  async (l) => {
236
225
  try {
237
- s(l), T();
226
+ s(l), A();
238
227
  const { data: b, fromCache: u } = await Q(
239
228
  a.apiServiceUrl,
240
229
  (e == null ? void 0 : e.accessToken) || "",
241
230
  l.id,
242
231
  t
243
232
  );
244
- if (!de(b, {
233
+ if (!le(b, {
245
234
  setFrame: n,
246
- setCard: i,
235
+ setCard: c,
247
236
  setIsDevMode: o,
248
237
  initializeModeDrafts: d,
249
- setActiveTabCardId: m,
250
- updateDataSource: h,
238
+ setActiveTabCardId: h,
239
+ updateDataSource: m,
251
240
  setQueryResultColumns: p,
252
241
  setSelectedConnectionId: $,
253
242
  setSelectedDatabaseName: g,
254
- setSelectedSchemaName: c,
255
- setSelectedTableName: S,
243
+ setSelectedSchemaName: i,
244
+ setSelectedTableName: U,
256
245
  setSelectedDatamodelId: v,
257
246
  setFilterValues: C,
258
- setInlineFilterValuesMap: w,
259
- setApplyFilters: I,
247
+ setInlineFilterValuesMap: S,
248
+ setApplyFilters: w,
260
249
  setIsDashboardEditing: V,
261
- setIsVisualEditing: N,
262
- dashboard: P,
263
- selectedSheetId: y,
264
- selectedFrameId: B,
265
- filterValues: R,
266
- inlineFilterValuesMap: W
250
+ setIsVisualEditing: O,
251
+ dashboard: R,
252
+ selectedSheetId: I,
253
+ selectedFrameId: D,
254
+ filterValues: W,
255
+ inlineFilterValuesMap: L
267
256
  }))
268
257
  throw new Error("Failed to setup editor with visual data");
269
258
  return { success: !0, fromCache: u };
@@ -277,39 +266,39 @@ function me() {
277
266
  t,
278
267
  s,
279
268
  n,
280
- i,
269
+ c,
281
270
  V,
282
- N,
271
+ O,
283
272
  o,
284
273
  d,
285
- m,
286
274
  h,
275
+ m,
287
276
  p,
288
277
  $,
289
278
  g,
290
- c,
291
- S,
279
+ i,
280
+ U,
292
281
  v,
293
282
  C,
283
+ S,
294
284
  w,
295
- I,
296
- T,
297
- P,
298
- y,
299
- B,
285
+ A,
300
286
  R,
301
- W
287
+ I,
288
+ D,
289
+ W,
290
+ L
302
291
  ]
303
- ), J = D(
292
+ ), J = N(
304
293
  async (l) => {
305
294
  var b;
306
295
  try {
307
- if (s(l), !y)
296
+ if (s(l), !I)
308
297
  return {
309
298
  success: !1,
310
299
  error: "No sheet selected. Please select a sheet first."
311
300
  };
312
- const { data: u, fromCache: L } = await Q(
301
+ const { data: u, fromCache: P } = await Q(
313
302
  a.apiServiceUrl,
314
303
  (e == null ? void 0 : e.accessToken) || "",
315
304
  l.id,
@@ -317,15 +306,15 @@ function me() {
317
306
  ), j = (u == null ? void 0 : u.frameObject) ?? ((b = u == null ? void 0 : u.visual) == null ? void 0 : b.frameObject);
318
307
  if (!j)
319
308
  return { success: !1, error: "Visual has no frame data" };
320
- const F = G(j);
321
- if (!(F != null && F.cards) || F.cards.length === 0)
309
+ const E = G(j);
310
+ if (!(E != null && E.cards) || E.cards.length === 0)
322
311
  return { success: !1, error: "Visual frame is malformed" };
323
312
  const k = {
324
- ...re(F),
313
+ ...re(E),
325
314
  visualId: l.id
326
315
  // Link this frame to the library visual
327
316
  };
328
- return x(y, k, "end"), V(!0), O(k.id), A(!1), { success: !0, fromCache: L };
317
+ return T(I, k, "end"), V(!0), x(k.id), B(!1), { success: !0, fromCache: P };
329
318
  } catch (u) {
330
319
  return console.error("Error adding visual:", u), { success: !1, error: "Failed to add visual to dashboard" };
331
320
  }
@@ -335,25 +324,24 @@ function me() {
335
324
  a.apiServiceUrl,
336
325
  t,
337
326
  s,
338
- y,
339
- x,
327
+ I,
328
+ T,
340
329
  V,
341
- O,
342
- A
330
+ x,
331
+ B
343
332
  ]
344
333
  );
345
334
  return {
346
- visual: E.data,
347
- isLoading: E.isLoading,
348
- isError: E.isError,
349
- error: E.error,
335
+ visual: y.data,
336
+ isLoading: y.isLoading,
337
+ isError: y.isError,
338
+ error: y.error,
350
339
  handleEditLibraryVisual: z,
351
340
  handleAddLibraryVisual: J,
352
- getUpdatedFrame: le().getUpdatedFrame,
353
- refetch: E.refetch
341
+ getUpdatedFrame: ue().getUpdatedFrame,
342
+ refetch: y.refetch
354
343
  };
355
344
  }
356
345
  export {
357
- me as a,
358
- ne as u
346
+ me as u
359
347
  };
@@ -0,0 +1 @@
1
+ "use strict";const o=require("./index-DTw8TJ-8.js"),S=require("react");function Q(e){const n=e.toUpperCase().indexOf("WHERE"),t=e.toUpperCase().indexOf("GROUP BY"),r=e.toUpperCase().indexOf("LIMIT"),s=e.toUpperCase().indexOf("ORDER BY");let i=e.length;if(s!==-1&&(i=s),r!==-1&&r<i&&(i=r),n!==-1){const d=e.substring(0,n),a=e.substring(n);return`${d} {{ filters | where }} AND ${a.substring(6)}`}else if(t!==-1){const d=e.substring(0,t),a=e.substring(t);return`${d} {{ filters | where }} ${a}`}else{const d=e.substring(0,i),a=e.substring(i);return console.log("beforeClause",d),console.log("afterClause",a),a?`${d} {{ filters | where }} ${a}`:`${d.replace(/;$/,"")} {{ filters | where }}`}}function z(e){const[n,t]=S.useState(null),[r,s]=S.useState(null),i=o.useEnsureReactGlobals();return S.useEffect(()=>{if(!e||e.trim()===""){t(null),s(null);return}if(!i)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 l=`${e.endsWith("/")?e:`${e}/`}index.js`;try{if(!(await fetch(l,{method:"HEAD"})).ok)throw new Error(`Module not found at ${l}`)}catch{}const h=await import(l);if(typeof h.useChartStore!="function")throw new Error("useChartStore is not a function");t(()=>h.useChartStore),s(null)}catch(a){const l=a instanceof Error?a.message:"Unknown error";console.error("Failed to load remote chart store:",l),s(l),t(null)}})()},[e,i]),n}function G(e,n){if(e.length===0)return"";const t=e.find(r=>{var s,i;return((s=r.customCardPreferences)==null?void 0:s.visualType)==="multiple"||!!((i=r.customCardPreferences)!=null&&i.dataInputCardIds)});if(t)return t.id;if(n){const r=e.find(s=>s.id===n);if(r){const s=r.tabTitle;if(s=="All__Header")return e[0].id;if(s&&s.endsWith("__Header")){const d=s.split("__")[0],a=e.find(l=>l.tabTitle===d);return a?a.id:e[0].id}return n}}return e[0].id}const Y=e=>{if(!e||!("detailTableBackup"in e))return e;const{detailTableBackup:n,...t}=e;return t};async function P(e,n,t,r){if(!n||!t)throw new Error("Missing auth token or visual ID");const s=["resource-by-id","visual",t],i=r.getQueryData(s);if(i)return console.log("Using cached visual data for:",t),{data:i,fromCache:!0};console.log("Fetching visual data from network for:",t);const d=o.ue.loading("Loading visual...",{position:"top-center"});try{const a=await fetch(`${e}/management/v1/visuals/${t}`,{headers:{Authorization:`Bearer ${n}`}});if(!a.ok)throw new Error("Failed to load visual");const l=await a.json();return r.setQueryData(s,l),o.ue.dismiss(d),{data:l,fromCache:!1}}catch(a){throw o.ue.dismiss(d),a}}function j(e){if(typeof e=="string")return JSON.parse(e);if(typeof e=="object")return e;throw new Error("Invalid frame object format")}function J(e,n){var i,d;const t=(e==null?void 0:e.frameObject)??((i=e==null?void 0:e.visual)==null?void 0:i.frameObject);if(!t)return!1;const r=j(t);if(!(r!=null&&r.cards)||r.cards.length===0)return!1;const s=(d=r.cards)==null?void 0:d.find(a=>a.id===r.activeCardId);return s?(o.setupEditorWithCard({...n,frame:r,card:s,visualId:(e==null?void 0:e.id)||r.visualId}),!0):!1}function K(){var g;const{setCardSql:e}=o.useEditorActions(),n=o.useEditorStore(c=>c.frame),t=o.useEditorStore(c=>c.card),r=o.useEditorStore(c=>c.isDevMode),s=z(((g=t.customCardPreferences)==null?void 0:g.url)||""),i=o.useEditorStore(c=>c.selectedSchemaName),d=o.useEditorStore(c=>c.selectedDatamodelId),a=o.useEditorStore(c=>c.selectedDatabaseName),l=o.useEditorStore(c=>c.selectedTableName),h=o.useEditorStore(c=>c.selectedConnectionId),m=o.useEditorStore(c=>c.isShowingVisual),p=t.sql;return{getUpdatedFrame:S.useCallback(()=>{var E;let c=p;p&&!p.includes("{{")&&(c=Q(p),e(c));const U=(E=s==null?void 0:s.getState())==null?void 0:E.settings,v=o.buildSavedEditorCard(t,{isDevMode:r,cardSql:c,isShowingVisual:m,selectedSchemaName:i,selectedDatamodelId:d,selectedDatabaseName:a,selectedTableName:l,selectedConnectionId:h,remoteChartSettings:U,stripConfig:Y}),C=n.cards.map(w=>w.id===t.id?v:w);return{...n,cards:C,activeCardId:G(C,n.activeCardId)}},[t,n,r,m,i,d,a,l,h,e,s,p])}}function X(){const{authToken:e,tokenProps:n}=o.useSemaphorContext(),t=o.useQueryClient(),r=o.useSelectedVisual(),{selectVisual:s}=o.useManagementActions(),{setFrame:i,setCard:d,setIsDevMode:a,initializeModeDrafts:l,setActiveTabCardId:h,updateDataSource:m,setQueryResultColumns:p,setSelectedConnectionId:$,setSelectedDatabaseName:g,setSelectedSchemaName:c,setSelectedTableName:U,setSelectedDatamodelId:v,setFilterValues:C,setInlineFilterValuesMap:E,setApplyFilters:w}=o.useEditorActions(),{setIsDashboardEditing:V,setIsVisualEditing:D,setSelectedFrameId:M,clearSelectedFrameId:A,addFrame:N,setIsDashboardPanelOpen:O}=o.useDashboardActions(),I=o.useDashboardStore(u=>u.selectedSheetId),R=o.useDashboardStore(u=>u.selectedFrameId),x=o.useDashboardStore(u=>u.dashboard),B=o.useDashboardStore(u=>u.filterValues),T=o.useDashboardStore(u=>u.inlineFilterValuesMap),y=o.useVisualById((r==null?void 0:r.id)||"",{enabled:!!(r!=null&&r.id)&&!!(e!=null&&e.accessToken)}),_=S.useCallback(async u=>{try{s(u),A();const{data:b,fromCache:f}=await P(n.apiServiceUrl,(e==null?void 0:e.accessToken)||"",u.id,t);if(!J(b,{setFrame:i,setCard:d,setIsDevMode:a,initializeModeDrafts:l,setActiveTabCardId:h,updateDataSource:m,setQueryResultColumns:p,setSelectedConnectionId:$,setSelectedDatabaseName:g,setSelectedSchemaName:c,setSelectedTableName:U,setSelectedDatamodelId:v,setFilterValues:C,setInlineFilterValuesMap:E,setApplyFilters:w,setIsDashboardEditing:V,setIsVisualEditing:D,dashboard:x,selectedSheetId:I,selectedFrameId:R,filterValues:B,inlineFilterValuesMap:T}))throw new Error("Failed to setup editor with visual data");return{success:!0,fromCache:f}}catch(b){return console.error("Error editing visual:",b),{success:!1,error:"Failed to load visual for editing"}}},[e==null?void 0:e.accessToken,n.apiServiceUrl,t,s,i,d,V,D,a,l,h,m,p,$,g,c,U,v,C,E,w,A,x,I,R,B,T]),H=S.useCallback(async u=>{var b;try{if(s(u),!I)return{success:!1,error:"No sheet selected. Please select a sheet first."};const{data:f,fromCache:W}=await P(n.apiServiceUrl,(e==null?void 0:e.accessToken)||"",u.id,t),k=(f==null?void 0:f.frameObject)??((b=f==null?void 0:f.visual)==null?void 0:b.frameObject);if(!k)return{success:!1,error:"Visual has no frame data"};const F=j(k);if(!(F!=null&&F.cards)||F.cards.length===0)return{success:!1,error:"Visual frame is malformed"};const L={...o.cloneLinkedFrameWithSourceMapping(F),visualId:u.id};return N(I,L,"end"),V(!0),M(L.id),O(!1),{success:!0,fromCache:W}}catch(f){return console.error("Error adding visual:",f),{success:!1,error:"Failed to add visual to dashboard"}}},[e==null?void 0:e.accessToken,n.apiServiceUrl,t,s,I,N,V,M,O]);return{visual:y.data,isLoading:y.isLoading,isError:y.isError,error:y.error,handleEditLibraryVisual:_,handleAddLibraryVisual:H,getUpdatedFrame:K().getUpdatedFrame,refetch:y.refetch}}exports.useVisualUtils=X;
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const r=require("../chunks/index-C2i6CRUk.js"),e=require("../types/index.cjs");exports.Dashboard=r.Dashboard;exports.CONTROL_CARD_DEFAULT_VALUE=e.CONTROL_CARD_DEFAULT_VALUE;exports.EMPTY_SELECTION=e.EMPTY_SELECTION;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const r=require("../chunks/index-DTw8TJ-8.js"),e=require("../types/index.cjs");exports.Dashboard=r.Dashboard;exports.CONTROL_CARD_DEFAULT_VALUE=e.CONTROL_CARD_DEFAULT_VALUE;exports.EMPTY_SELECTION=e.EMPTY_SELECTION;
@@ -1,4 +1,4 @@
1
- import { D as E } from "../chunks/index-D5jdzvu3.js";
1
+ import { D as E } from "../chunks/index-BrLm4rYX.js";
2
2
  import { CONTROL_CARD_DEFAULT_VALUE as L, EMPTY_SELECTION as T } from "../types/index.js";
3
3
  export {
4
4
  L as CONTROL_CARD_DEFAULT_VALUE,
package/dist/index.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./chunks/index-C2i6CRUk.js"),_=require("./types/index.cjs"),M=require("./chunks/dashboard-summary-settings-dialog-CrBOuggE.js"),t=require("react/jsx-runtime"),x=require("react"),O=require("./chunks/resource-management-panel-ZK4SWoad.js"),U=require("./chunks/use-debounced-dirty-check-XHSwAefL.js");require("react-dom");const A=require("./chunks/dashboard-filter-controls-button-DKRyKRsP.js"),L=require("./chunks/normalize-dashboard-for-dirty-check-BXRUMVb2.js");function z(s){const r=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(s){for(const n in s)if(n!=="default"){const o=Object.getOwnPropertyDescriptor(s,n);Object.defineProperty(r,n,o.get?o:{enumerable:!0,get:()=>s[n]})}}return r.default=s,Object.freeze(r)}const R=z(x);function Q(s){const{authToken:r,tokenProps:n}=e.useSemaphorContext();return e.useMutation({mutationFn:async o=>e.backtestAlert(n.apiServiceUrl,r.accessToken,s,o)})}function q(s){const{displayPreferences:r,cardId:n,...o}=s,l={...o,id:s.dashboardId};return t.jsx(e.ErrorBoundary,{FallbackComponent:e.Fallback,children:t.jsxs(e.SemaphorContextProvider,{dashboardProps:l,children:[t.jsx(e.SemaphorReadyIndicator,{componentType:"visual",componentId:s.cardId}),t.jsx(e.UXProvider,{children:t.jsx(e.DisplayPreferencesProvider,{displayPreferences:r,children:t.jsx(e.Container,{type:"visual",cardId:n,...l,children:t.jsx(V,{cardId:n})})})})]})})}function V({cardId:s}){const r=e.useDashboardStore(l=>{var c;return(c=l.dashboard)==null?void 0:c.sheets}),{card:n,frame:o}=x.useMemo(()=>{const l=r==null?void 0:r.flatMap(i=>i.frames),c=l==null?void 0:l.flatMap(i=>i==null?void 0:i.cards),u=c==null?void 0:c.find(i=>(i==null?void 0:i.id)===s),a=l==null?void 0:l.find(i=>{var m;return(m=i==null?void 0:i.cards)==null?void 0:m.find(f=>(f==null?void 0:f.id)===s)});return{card:u,frame:a}},[r,s]);return!n||!o?t.jsx(e.FallbackVisual,{error:new Error("Card not found"),resetErrorBoundary:()=>{},customerFacingMessage:`Card not found with ID: ${s}`}):t.jsx("main",{className:"flex h-full grow flex-col",children:t.jsx(e.ErrorBoundary,{FallbackComponent:({error:l,resetErrorBoundary:c})=>t.jsx(e.FallbackVisual,{error:l,resetErrorBoundary:c,customerFacingMessage:"Error creating visual. Please try again."}),children:t.jsx(e.DashboardCard,{card:n,frame:o})})})}function W({name:s,items:r,value:n,onChange:o,isLoading:l,isError:c,refetch:u,className:a,icon:i,showNone:m=!1}){const f=R.useRef(null),[D,C]=R.useState(!1),[b,j]=R.useState("100%"),y=m?[...r||[],{id:"none",name:"None"}]:r;R.useLayoutEffect(()=>{f.current&&j(f.current.offsetWidth)},[]);function I(){var h;return l?"Loading...":c?"Error":n?(h=r==null?void 0:r.find(S=>S.id===n))==null?void 0:h.name:`Select ${s}`}function T(h,S){o(S),C(!1)}return t.jsxs(e.Popover,{open:D,onOpenChange:C,children:[t.jsx(e.PopoverTrigger,{asChild:!0,children:t.jsxs(e.Button,{ref:f,variant:"outline",role:"combobox","aria-expanded":D,className:e.cn("flex h-9 w-full justify-between",a),children:[t.jsxs("div",{className:"flex items-center gap-2",children:[i&&t.jsx("div",{className:"mr-2",children:i}),t.jsx("span",{className:"max-w-[150px] overflow-hidden truncate text-ellipsis whitespace-nowrap",children:I()})]}),t.jsx(e.ChevronDown,{className:"size-4 opacity-50"})]})}),t.jsx(e.PopoverContent,{className:"w-full p-0",style:{minWidth:b},children:t.jsxs(e.Command,{children:[t.jsxs("div",{className:"flex h-9 items-center justify-between border-b pr-1",children:[t.jsx(e.CommandInput,{className:"h-9",placeholder:"Search..."}),t.jsx(e.IconButton,{className:"h-7",onClick:u,children:t.jsx(e.RefreshCw,{className:e.cn("size-3.5 opacity-50",l&&"animate-spin")})})]}),t.jsxs(e.CommandList,{children:[t.jsxs(e.CommandEmpty,{children:["No ",s==null?void 0:s.toLowerCase()," found."]}),t.jsx(e.CommandGroup,{children:y==null?void 0:y.map(h=>t.jsx(e.CommandItem,{className:"overflow-x-auto",value:h.name,onSelect:S=>T(S,h.id),children:t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx(e.Check,{className:e.cn("size-4",n===h.id?"opacity-100":"opacity-0")}),t.jsx("div",{title:h.name,children:h.name})]})},h.id))})]})]})})]})}function H({triggerButtonClassName:s,variant:r="ghost"}){const[n,o]=x.useState(!1),l=e.useDashboardStore(u=>{var a;return(a=u.dashboard)==null?void 0:a.id}),c=e.useDashboardStore(u=>{var a;return(a=u.dashboard)==null?void 0:a.title});return l?t.jsxs(t.Fragment,{children:[t.jsx(e.IconButton,{tooltip:"Schedule Dashboard",className:e.cn("h-7 p-2",s),buttonProps:{variant:r},onClick:()=>o(!0),children:t.jsx(e.Clock,{className:"size-4"})}),t.jsx(e.EmailScheduleDialog,{open:n,onOpenChange:o,dashboardId:l,dashboardName:c})]}):null}function $(s,r){x.useEffect(()=>(s&&r&&(window.__SEMAPHOR_PRINT_STATE__={...r}),()=>{s&&window.__SEMAPHOR_PRINT_STATE__&&delete window.__SEMAPHOR_PRINT_STATE__}),[s,r])}function P(s){if(!s)return"--";const r=new Date(s);return Number.isNaN(r.getTime())?"--":r.toLocaleString()}function G(s){var r;return((r=s.alertState)==null?void 0:r.currentState)==="FIRING"?"Signal surfaced":s.status==="ACTIVE"?"Watching":s.status==="PAUSED"?"Paused":s.status}function K({alertId:s,onBack:r}){var h,S,F,w;const{authToken:n,tokenProps:o}=e.useSemaphorContext(),{data:l,isLoading:c,refetch:u}=e.useAlertDetail(s),a=(l==null?void 0:l.alert)??null,[i,m]=x.useState([]),[f,D]=x.useState([]),[C,b]=x.useState(null),j=x.useCallback(async()=>{var g;const d=o==null?void 0:o.apiServiceUrl,p=n==null?void 0:n.accessToken;if(!d||!p||!s)return null;try{const v=await fetch(`${d}/v1/alerts/${s}/runs?limit=20`,{headers:{Authorization:`Bearer ${p}`}});if(v.ok){const E=await v.json(),N=Array.isArray(E.runs)?E.runs:[],k=C&&N.some(B=>B.id===C)?C:((g=N[0])==null?void 0:g.id)??null;return D(N),b(k),k}D([]),b(null)}catch{return D([]),b(null),null}return null},[s,n,C,o]),y=x.useCallback(async d=>{const p=o==null?void 0:o.apiServiceUrl,g=n==null?void 0:n.accessToken,v=d??C;if(!p||!g||!s||!v){m([]);return}try{const E=await fetch(`${p}/v1/alerts/${s}/runs/${v}/deliveries`,{headers:{Authorization:`Bearer ${g}`}});if(E.ok){const N=await E.json();m(Array.isArray(N.attempts)?N.attempts:[])}else m([])}catch{m([])}},[s,n,C,o]),I=x.useCallback(async()=>{await u();const d=await j();await y(d)},[y,j,u]);x.useEffect(()=>{j().catch(()=>{})},[j]),x.useEffect(()=>{y().catch(()=>{})},[y]);const T=x.useMemo(()=>{const d={};for(const p of i)d[p.channel]||(d[p.channel]=[]),d[p.channel].push(p);return d},[i]);return c?t.jsx("div",{className:"p-4 text-sm text-muted-foreground",children:"Loading signal detail..."}):a?t.jsxs("div",{className:"space-y-4 p-4",children:[t.jsxs("div",{className:"flex items-center justify-between gap-2",children:[t.jsxs("div",{className:"flex items-center gap-2",children:[r&&t.jsx(e.Button,{variant:"outline",size:"sm",onClick:r,children:"Back"}),t.jsx("h2",{className:"text-lg font-semibold",children:a.name}),t.jsx(e.Badge,{variant:a.status==="ACTIVE"?"default":"secondary",children:G(a)}),((h=a.alertState)==null?void 0:h.currentState)&&t.jsx(e.Badge,{variant:a.alertState.currentState==="FIRING"?"destructive":"outline",children:a.alertState.currentState==="FIRING"?"Signal surfaced":"Stable"})]}),t.jsx(e.Button,{variant:"outline",size:"sm",onClick:()=>void I(),children:"Refresh"})]}),a.description&&t.jsx("p",{className:"text-sm text-muted-foreground",children:a.description}),t.jsxs("div",{className:"rounded-md border bg-muted/30 p-4 text-sm",children:[t.jsx("p",{className:"font-medium",children:"What changed"}),t.jsx("p",{className:"mt-1 text-muted-foreground",children:"Review the latest signal activity, then investigate the underlying dashboard context if you need more detail."})]}),t.jsxs("div",{className:"rounded-md border bg-background p-4 space-y-2",children:[t.jsx("h3",{className:"text-sm font-semibold",children:"Signal Watch"}),t.jsxs("div",{className:"grid grid-cols-2 gap-2 text-sm",children:[t.jsxs("div",{children:[t.jsx("span",{className:"text-muted-foreground",children:"Watching for:"})," ",e.formatSignalCondition(a.jobConfig.operator,a.jobConfig.threshold)]}),t.jsxs("div",{children:[t.jsx("span",{className:"text-muted-foreground",children:"Severity:"})," ",a.jobConfig.severity]}),t.jsxs("div",{children:[t.jsx("span",{className:"text-muted-foreground",children:"Last Evaluated:"})," ",P((S=a.alertState)==null?void 0:S.lastEvaluatedAt)]}),t.jsxs("div",{children:[t.jsx("span",{className:"text-muted-foreground",children:"Last Surfaced:"})," ",P((F=a.alertState)==null?void 0:F.lastTriggeredAt)]})]})]}),((w=a.deliveryConfig)==null?void 0:w.channels)&&a.deliveryConfig.channels.length>0&&t.jsxs("div",{className:"rounded-md border bg-background p-4 space-y-2",children:[t.jsx("h3",{className:"text-sm font-semibold",children:"Where It Surfaces"}),t.jsx("div",{className:"flex flex-wrap gap-2",children:a.deliveryConfig.channels.map(d=>t.jsx(e.Badge,{variant:"outline",children:d},d))})]}),f.length>0&&t.jsxs("div",{className:"rounded-md border bg-background p-4 space-y-3",children:[t.jsx("h3",{className:"text-sm font-semibold",children:"Recent Delivery Activity"}),f.length>1&&t.jsx("div",{className:"flex flex-wrap gap-2",children:f.map(d=>t.jsx(e.Button,{variant:d.id===C?"default":"outline",size:"sm",onClick:()=>b(d.id),children:P(d.scheduledFor)},d.id))}),Object.keys(T).length===0?t.jsx("p",{className:"text-sm text-muted-foreground",children:"No delivery attempts were recorded for this run."}):Object.entries(T).map(([d,p])=>t.jsxs("div",{className:"space-y-1",children:[t.jsx("div",{className:"flex items-center gap-2",children:t.jsx(e.Badge,{variant:"secondary",className:"text-xs",children:d})}),t.jsx("div",{className:"overflow-hidden rounded border",children:t.jsxs("table",{className:"w-full text-xs",children:[t.jsx("thead",{className:"bg-muted/40",children:t.jsxs("tr",{children:[t.jsx("th",{className:"px-2 py-1 text-left font-medium",children:"Recipient"}),t.jsx("th",{className:"px-2 py-1 text-left font-medium",children:"Status"}),t.jsx("th",{className:"px-2 py-1 text-left font-medium",children:"Time"}),t.jsx("th",{className:"px-2 py-1 text-left font-medium",children:"Error"})]})}),t.jsx("tbody",{children:p.map(g=>t.jsxs("tr",{className:"border-t",children:[t.jsx("td",{className:"px-2 py-1",children:g.recipient}),t.jsx("td",{className:"px-2 py-1",children:t.jsx(e.Badge,{variant:g.status==="SENT"?"default":"destructive",className:"text-[10px]",children:g.status})}),t.jsx("td",{className:"px-2 py-1",children:P(g.createdAt)}),t.jsx("td",{className:"px-2 py-1 text-muted-foreground",children:g.error||"--"})]},g.id))})]})})]},d))]})]}):t.jsx("div",{className:"p-4 text-sm text-muted-foreground",children:"Signal not found."})}function Y(){var c,u;const{quotasQuery:s,usageQuery:r}=e.useAlertQuotas(),n=((c=s.data)==null?void 0:c.quotas)||[],o=((u=r.data)==null?void 0:u.usage)||[],l=new Map(o.map(a=>[a.tenantId||"org",a]));return t.jsxs("div",{className:"space-y-4 p-4",children:[t.jsxs("div",{className:"flex items-center justify-between",children:[t.jsx("h2",{className:"text-xl font-semibold",children:"Alert Quotas"}),t.jsx(e.Button,{variant:"outline",size:"sm",onClick:()=>{s.refetch(),r.refetch()},children:"Refresh"})]}),s.isLoading||r.isLoading?t.jsx("p",{className:"text-sm text-muted-foreground",children:"Loading quota usage..."}):null,t.jsx("div",{className:"overflow-hidden rounded-lg border",children:t.jsxs("table",{className:"w-full text-sm",children:[t.jsx("thead",{className:"bg-muted/40",children:t.jsxs("tr",{children:[t.jsx("th",{className:"px-3 py-2 text-left font-medium",children:"Tenant"}),t.jsx("th",{className:"px-3 py-2 text-left font-medium",children:"Active Alerts"}),t.jsx("th",{className:"px-3 py-2 text-left font-medium",children:"Max Active"}),t.jsx("th",{className:"px-3 py-2 text-left font-medium",children:"Min Cadence"}),t.jsx("th",{className:"px-3 py-2 text-left font-medium",children:"Max Context Sources"})]})}),t.jsx("tbody",{children:n.map(a=>{const i=a.tenantId||"org",m=l.get(i);return t.jsxs("tr",{className:"border-t",children:[t.jsx("td",{className:"px-3 py-2",children:i}),t.jsx("td",{className:"px-3 py-2",children:(m==null?void 0:m.activeAlerts)??0}),t.jsx("td",{className:"px-3 py-2",children:a.policy.maxActiveAlerts}),t.jsxs("td",{className:"px-3 py-2",children:[a.policy.minCadenceMinutes," min"]}),t.jsx("td",{className:"px-3 py-2",children:a.policy.maxContextSources})]},i)})})]})})]})}exports.AlertManagementPage=e.AlertManagementPage;exports.AlertWizardDialog=e.AlertWizardDialog;exports.AlertsApiError=e.AlertsApiError;exports.CALCULATED_FIELD_ENTITY_MARKER=e.CALCULATED_FIELD_ENTITY_MARKER;exports.CardAlertIndicator=e.CardAlertIndicator;exports.CardSummary=e.CardSummary;exports.DATE_FORMAT_VALUES=e.DATE_FORMAT_VALUES;exports.Dashboard=e.Dashboard;exports.DashboardExportDialog=e.DashboardExportDialog;exports.DashboardWC=e.DashboardWC;exports.EmailScheduleDialog=e.EmailScheduleDialog;exports.ExportError=e.ExportError;exports.PivotMarkerEnum=e.PivotMarkerEnum;exports.ResourceType=e.ResourceType;exports.SemaphorContextProvider=e.SemaphorContextProvider;exports.SemaphorDataProvider=e.SemaphorQueryClient;exports.SemaphorQueryClient=e.SemaphorQueryClient;exports.ShareDialog=e.ShareDialog;exports.SummaryCard=e.SummaryCard;exports.Surfboard=e.DashboardPlus;exports.backtestAlert=e.backtestAlert;exports.cancelExport=e.cancelExport;exports.cloneDeep=e.cloneDeep;exports.createAlert=e.createAlert;exports.createEmptyKpiConfig=e.createEmptyKpiConfig;exports.createExport=e.createExport;exports.createSqlGenConfig=e.createSqlGenConfig;exports.deleteAlert=e.deleteAlert;exports.downloadPdf=e.downloadPdf;exports.emitDashboardLoad=e.emitDashboardLoad;exports.emitDashboardUnload=e.emitDashboardUnload;exports.fmt=e.fmt;exports.formatFileSize=e.formatFileSize;exports.getAlert=e.getAlert;exports.getAlertContextSources=e.getAlertContextSources;exports.getAlertHistory=e.getAlertHistory;exports.getAlertQuotaUsage=e.getAlertQuotaUsage;exports.getAlertRunDeliveries=e.getAlertRunDeliveries;exports.getAlertRunSteps=e.getAlertRunSteps;exports.getAlertRuns=e.getAlertRuns;exports.getAlertState=e.getAlertState;exports.getColumnDataType=e.getColumnDataType;exports.getDownloadUrl=e.getDownloadUrl;exports.getExportStatus=e.getExportStatus;exports.getExports=e.getExports;exports.getFilterValueType=e.getFilterValueType;exports.getFormattedTableNameForQuery=e.getFormattedTableNameForQuery;exports.getQualifiedTableName=e.getQualifiedTableName;exports.getSql=e.getSql;exports.invalidateToken=e.invalidateToken;exports.isBooleanDataType=e.isBooleanDataType;exports.isCalculatedDimension=e.isCalculatedDimension;exports.isCalculatedField=e.isCalculatedField;exports.isCalculatedMetric=e.isCalculatedMetric;exports.isColumnInSqlGen=e.isColumnInSqlGen;exports.isDateDataType=e.isDateDataType;exports.isExportComplete=e.isExportComplete;exports.isExportInProgress=e.isExportInProgress;exports.isNumberDataType=e.isNumberDataType;exports.isTextDataType=e.isTextDataType;exports.listAlertQuotas=e.listAlertQuotas;exports.listAlerts=e.listAlerts;exports.previewAlertDeliverable=e.previewAlertDeliverable;exports.resolveDataType=e.resolveDataType;exports.resolveDatamodelName=e.resolveDatamodelName;exports.triggerAlertNow=e.triggerAlertNow;exports.updateAlert=e.updateAlert;exports.updateAlertContextSources=e.updateAlertContextSources;exports.updateAlertQuota=e.updateAlertQuota;exports.useActiveExports=e.useActiveExports;exports.useAddNewFrame=e.useAddNewFrame;exports.useAlertActions=e.useAlertActions;exports.useAlertDeliveries=e.useAlertDeliveries;exports.useAlertDetail=e.useAlertDetail;exports.useAlertDraft=e.useAlertDraft;exports.useAlertFilters=e.useAlertFilters;exports.useAlertHistory=e.useAlertHistory;exports.useAlertQuotas=e.useAlertQuotas;exports.useAlertRuns=e.useAlertRuns;exports.useAlertState=e.useAlertState;exports.useAlertStore=e.useAlertStore;exports.useAlertWizard=e.useAlertWizard;exports.useAlerts=e.useAlerts;exports.useAlertsBootstrap=e.useAlertsBootstrap;exports.useAlertsById=e.useAlertsById;exports.useAlertsForCard=e.useAlertsForCard;exports.useCard=e.useCard;exports.useCardAlertMap=e.useCardAlertMap;exports.useCardSummary=e.useCardSummary;exports.useCurrentActiveCard=e.useCurrentActiveCard;exports.useCurrentCardConfig=e.useCurrentCardConfig;exports.useCurrentSheetActiveCards=e.useCurrentSheetActiveCards;exports.useDashboardActions=e.useDashboardActions;exports.useDashboardById=e.useDashboardById;exports.useDashboardQuery=e.useDashboardQuery;exports.useDashboardStore=e.useDashboardStore;exports.useDashboardSummary=e.useDashboardSummary;exports.useDataColumns=e.useDataColumns;exports.useDateFilterHook=e.useDateFilterHook;exports.useEditorActions=e.useEditorActions;exports.useEditorAside=e.useEditorAside;exports.useEditorStore=e.useEditorStore;exports.useExportActions=e.useExportActions;exports.useExportStore=e.useExportStore;exports.useInProgressExportsCount=e.useInProgressExportsCount;exports.useManagementStore=e.useManagementStore;exports.useResourceManagement=e.useResourceManagement;exports.useSelectedAlertId=e.useSelectedAlertId;exports.useTextFilterHook=e.useTextFilterHook;exports.CONTROL_CARD_DEFAULT_VALUE=_.CONTROL_CARD_DEFAULT_VALUE;exports.DEFAULT_CALENDAR_CONTEXT=_.DEFAULT_CALENDAR_CONTEXT;exports.DEFAULT_SEMANTIC_DOMAIN_ACCESS=_.DEFAULT_SEMANTIC_DOMAIN_ACCESS;exports.EMPTY_SELECTION=_.EMPTY_SELECTION;exports.CalendarPreferencesDialog=M.CalendarPreferencesDialog;exports.DashboardSummarySettingsDialog=M.DashboardSummarySettingsDialog;exports.ResourceManagementPanel=O.ResourceManagementPanel;exports.useDebouncedDirtyCheck=U.useDebouncedDirtyCheck;exports.AdvancedModeToggle=A.AdvancedModeToggle;exports.DashboardControlsSettings=A.DashboardControlsSettings;exports.DashboardFilterControlsButton=A.DashboardFilterControlsButton;exports.ExportNotificationItem=A.ExportNotificationItem;exports.ExportNotificationList=A.ExportNotificationList;exports.NotificationBell=A.NotificationBell;exports.UnsavedChangesAlert=A.UnsavedChangesAlert;exports.VisualEditingControls=A.VisualEditingControls;exports.useExportPolling=A.useExportPolling;exports.useExportRecovery=A.useExportRecovery;exports.usePristineSnapshotInitializer=A.usePristineSnapshotInitializer;exports.normalizeDashboardForDirtyCheck=L.normalizeDashboardForDirtyCheck;exports.serializeDashboardForDirtyCheck=L.serializeDashboardForDirtyCheck;exports.AlertDetailPageEmbedded=K;exports.Combobox=W;exports.ScheduleDashboard=H;exports.TenantQuotaPage=Y;exports.Visual=q;exports.useAlertBacktest=Q;exports.useExposePrintState=$;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./chunks/index-DTw8TJ-8.js"),_=require("./types/index.cjs"),M=require("./chunks/dashboard-summary-settings-dialog-BruCXCaN.js"),t=require("react/jsx-runtime"),x=require("react"),O=require("./chunks/resource-management-panel-CLZBF-Dw.js"),U=require("./chunks/use-debounced-dirty-check-XHSwAefL.js");require("react-dom");const A=require("./chunks/dashboard-filter-controls-button-CcrX4Kjv.js"),L=require("./chunks/normalize-dashboard-for-dirty-check-BXRUMVb2.js");function z(s){const r=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(s){for(const n in s)if(n!=="default"){const o=Object.getOwnPropertyDescriptor(s,n);Object.defineProperty(r,n,o.get?o:{enumerable:!0,get:()=>s[n]})}}return r.default=s,Object.freeze(r)}const R=z(x);function Q(s){const{authToken:r,tokenProps:n}=e.useSemaphorContext();return e.useMutation({mutationFn:async o=>e.backtestAlert(n.apiServiceUrl,r.accessToken,s,o)})}function q(s){const{displayPreferences:r,cardId:n,...o}=s,l={...o,id:s.dashboardId};return t.jsx(e.ErrorBoundary,{FallbackComponent:e.Fallback,children:t.jsxs(e.SemaphorContextProvider,{dashboardProps:l,children:[t.jsx(e.SemaphorReadyIndicator,{componentType:"visual",componentId:s.cardId}),t.jsx(e.UXProvider,{children:t.jsx(e.DisplayPreferencesProvider,{displayPreferences:r,children:t.jsx(e.Container,{type:"visual",cardId:n,...l,children:t.jsx(V,{cardId:n})})})})]})})}function V({cardId:s}){const r=e.useDashboardStore(l=>{var c;return(c=l.dashboard)==null?void 0:c.sheets}),{card:n,frame:o}=x.useMemo(()=>{const l=r==null?void 0:r.flatMap(i=>i.frames),c=l==null?void 0:l.flatMap(i=>i==null?void 0:i.cards),u=c==null?void 0:c.find(i=>(i==null?void 0:i.id)===s),a=l==null?void 0:l.find(i=>{var m;return(m=i==null?void 0:i.cards)==null?void 0:m.find(f=>(f==null?void 0:f.id)===s)});return{card:u,frame:a}},[r,s]);return!n||!o?t.jsx(e.FallbackVisual,{error:new Error("Card not found"),resetErrorBoundary:()=>{},customerFacingMessage:`Card not found with ID: ${s}`}):t.jsx("main",{className:"flex h-full grow flex-col",children:t.jsx(e.ErrorBoundary,{FallbackComponent:({error:l,resetErrorBoundary:c})=>t.jsx(e.FallbackVisual,{error:l,resetErrorBoundary:c,customerFacingMessage:"Error creating visual. Please try again."}),children:t.jsx(e.DashboardCard,{card:n,frame:o})})})}function W({name:s,items:r,value:n,onChange:o,isLoading:l,isError:c,refetch:u,className:a,icon:i,showNone:m=!1}){const f=R.useRef(null),[D,C]=R.useState(!1),[b,j]=R.useState("100%"),y=m?[...r||[],{id:"none",name:"None"}]:r;R.useLayoutEffect(()=>{f.current&&j(f.current.offsetWidth)},[]);function I(){var h;return l?"Loading...":c?"Error":n?(h=r==null?void 0:r.find(S=>S.id===n))==null?void 0:h.name:`Select ${s}`}function T(h,S){o(S),C(!1)}return t.jsxs(e.Popover,{open:D,onOpenChange:C,children:[t.jsx(e.PopoverTrigger,{asChild:!0,children:t.jsxs(e.Button,{ref:f,variant:"outline",role:"combobox","aria-expanded":D,className:e.cn("flex h-9 w-full justify-between",a),children:[t.jsxs("div",{className:"flex items-center gap-2",children:[i&&t.jsx("div",{className:"mr-2",children:i}),t.jsx("span",{className:"max-w-[150px] overflow-hidden truncate text-ellipsis whitespace-nowrap",children:I()})]}),t.jsx(e.ChevronDown,{className:"size-4 opacity-50"})]})}),t.jsx(e.PopoverContent,{className:"w-full p-0",style:{minWidth:b},children:t.jsxs(e.Command,{children:[t.jsxs("div",{className:"flex h-9 items-center justify-between border-b pr-1",children:[t.jsx(e.CommandInput,{className:"h-9",placeholder:"Search..."}),t.jsx(e.IconButton,{className:"h-7",onClick:u,children:t.jsx(e.RefreshCw,{className:e.cn("size-3.5 opacity-50",l&&"animate-spin")})})]}),t.jsxs(e.CommandList,{children:[t.jsxs(e.CommandEmpty,{children:["No ",s==null?void 0:s.toLowerCase()," found."]}),t.jsx(e.CommandGroup,{children:y==null?void 0:y.map(h=>t.jsx(e.CommandItem,{className:"overflow-x-auto",value:h.name,onSelect:S=>T(S,h.id),children:t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx(e.Check,{className:e.cn("size-4",n===h.id?"opacity-100":"opacity-0")}),t.jsx("div",{title:h.name,children:h.name})]})},h.id))})]})]})})]})}function H({triggerButtonClassName:s,variant:r="ghost"}){const[n,o]=x.useState(!1),l=e.useDashboardStore(u=>{var a;return(a=u.dashboard)==null?void 0:a.id}),c=e.useDashboardStore(u=>{var a;return(a=u.dashboard)==null?void 0:a.title});return l?t.jsxs(t.Fragment,{children:[t.jsx(e.IconButton,{tooltip:"Schedule Dashboard",className:e.cn("h-7 p-2",s),buttonProps:{variant:r},onClick:()=>o(!0),children:t.jsx(e.Clock,{className:"size-4"})}),t.jsx(e.EmailScheduleDialog,{open:n,onOpenChange:o,dashboardId:l,dashboardName:c})]}):null}function $(s,r){x.useEffect(()=>(s&&r&&(window.__SEMAPHOR_PRINT_STATE__={...r}),()=>{s&&window.__SEMAPHOR_PRINT_STATE__&&delete window.__SEMAPHOR_PRINT_STATE__}),[s,r])}function P(s){if(!s)return"--";const r=new Date(s);return Number.isNaN(r.getTime())?"--":r.toLocaleString()}function G(s){var r;return((r=s.alertState)==null?void 0:r.currentState)==="FIRING"?"Signal surfaced":s.status==="ACTIVE"?"Watching":s.status==="PAUSED"?"Paused":s.status}function K({alertId:s,onBack:r}){var h,S,F,w;const{authToken:n,tokenProps:o}=e.useSemaphorContext(),{data:l,isLoading:c,refetch:u}=e.useAlertDetail(s),a=(l==null?void 0:l.alert)??null,[i,m]=x.useState([]),[f,D]=x.useState([]),[C,b]=x.useState(null),j=x.useCallback(async()=>{var g;const d=o==null?void 0:o.apiServiceUrl,p=n==null?void 0:n.accessToken;if(!d||!p||!s)return null;try{const v=await fetch(`${d}/v1/alerts/${s}/runs?limit=20`,{headers:{Authorization:`Bearer ${p}`}});if(v.ok){const E=await v.json(),N=Array.isArray(E.runs)?E.runs:[],k=C&&N.some(B=>B.id===C)?C:((g=N[0])==null?void 0:g.id)??null;return D(N),b(k),k}D([]),b(null)}catch{return D([]),b(null),null}return null},[s,n,C,o]),y=x.useCallback(async d=>{const p=o==null?void 0:o.apiServiceUrl,g=n==null?void 0:n.accessToken,v=d??C;if(!p||!g||!s||!v){m([]);return}try{const E=await fetch(`${p}/v1/alerts/${s}/runs/${v}/deliveries`,{headers:{Authorization:`Bearer ${g}`}});if(E.ok){const N=await E.json();m(Array.isArray(N.attempts)?N.attempts:[])}else m([])}catch{m([])}},[s,n,C,o]),I=x.useCallback(async()=>{await u();const d=await j();await y(d)},[y,j,u]);x.useEffect(()=>{j().catch(()=>{})},[j]),x.useEffect(()=>{y().catch(()=>{})},[y]);const T=x.useMemo(()=>{const d={};for(const p of i)d[p.channel]||(d[p.channel]=[]),d[p.channel].push(p);return d},[i]);return c?t.jsx("div",{className:"p-4 text-sm text-muted-foreground",children:"Loading signal detail..."}):a?t.jsxs("div",{className:"space-y-4 p-4",children:[t.jsxs("div",{className:"flex items-center justify-between gap-2",children:[t.jsxs("div",{className:"flex items-center gap-2",children:[r&&t.jsx(e.Button,{variant:"outline",size:"sm",onClick:r,children:"Back"}),t.jsx("h2",{className:"text-lg font-semibold",children:a.name}),t.jsx(e.Badge,{variant:a.status==="ACTIVE"?"default":"secondary",children:G(a)}),((h=a.alertState)==null?void 0:h.currentState)&&t.jsx(e.Badge,{variant:a.alertState.currentState==="FIRING"?"destructive":"outline",children:a.alertState.currentState==="FIRING"?"Signal surfaced":"Stable"})]}),t.jsx(e.Button,{variant:"outline",size:"sm",onClick:()=>void I(),children:"Refresh"})]}),a.description&&t.jsx("p",{className:"text-sm text-muted-foreground",children:a.description}),t.jsxs("div",{className:"rounded-md border bg-muted/30 p-4 text-sm",children:[t.jsx("p",{className:"font-medium",children:"What changed"}),t.jsx("p",{className:"mt-1 text-muted-foreground",children:"Review the latest signal activity, then investigate the underlying dashboard context if you need more detail."})]}),t.jsxs("div",{className:"rounded-md border bg-background p-4 space-y-2",children:[t.jsx("h3",{className:"text-sm font-semibold",children:"Signal Watch"}),t.jsxs("div",{className:"grid grid-cols-2 gap-2 text-sm",children:[t.jsxs("div",{children:[t.jsx("span",{className:"text-muted-foreground",children:"Watching for:"})," ",e.formatSignalCondition(a.jobConfig.operator,a.jobConfig.threshold)]}),t.jsxs("div",{children:[t.jsx("span",{className:"text-muted-foreground",children:"Severity:"})," ",a.jobConfig.severity]}),t.jsxs("div",{children:[t.jsx("span",{className:"text-muted-foreground",children:"Last Evaluated:"})," ",P((S=a.alertState)==null?void 0:S.lastEvaluatedAt)]}),t.jsxs("div",{children:[t.jsx("span",{className:"text-muted-foreground",children:"Last Surfaced:"})," ",P((F=a.alertState)==null?void 0:F.lastTriggeredAt)]})]})]}),((w=a.deliveryConfig)==null?void 0:w.channels)&&a.deliveryConfig.channels.length>0&&t.jsxs("div",{className:"rounded-md border bg-background p-4 space-y-2",children:[t.jsx("h3",{className:"text-sm font-semibold",children:"Where It Surfaces"}),t.jsx("div",{className:"flex flex-wrap gap-2",children:a.deliveryConfig.channels.map(d=>t.jsx(e.Badge,{variant:"outline",children:d},d))})]}),f.length>0&&t.jsxs("div",{className:"rounded-md border bg-background p-4 space-y-3",children:[t.jsx("h3",{className:"text-sm font-semibold",children:"Recent Delivery Activity"}),f.length>1&&t.jsx("div",{className:"flex flex-wrap gap-2",children:f.map(d=>t.jsx(e.Button,{variant:d.id===C?"default":"outline",size:"sm",onClick:()=>b(d.id),children:P(d.scheduledFor)},d.id))}),Object.keys(T).length===0?t.jsx("p",{className:"text-sm text-muted-foreground",children:"No delivery attempts were recorded for this run."}):Object.entries(T).map(([d,p])=>t.jsxs("div",{className:"space-y-1",children:[t.jsx("div",{className:"flex items-center gap-2",children:t.jsx(e.Badge,{variant:"secondary",className:"text-xs",children:d})}),t.jsx("div",{className:"overflow-hidden rounded border",children:t.jsxs("table",{className:"w-full text-xs",children:[t.jsx("thead",{className:"bg-muted/40",children:t.jsxs("tr",{children:[t.jsx("th",{className:"px-2 py-1 text-left font-medium",children:"Recipient"}),t.jsx("th",{className:"px-2 py-1 text-left font-medium",children:"Status"}),t.jsx("th",{className:"px-2 py-1 text-left font-medium",children:"Time"}),t.jsx("th",{className:"px-2 py-1 text-left font-medium",children:"Error"})]})}),t.jsx("tbody",{children:p.map(g=>t.jsxs("tr",{className:"border-t",children:[t.jsx("td",{className:"px-2 py-1",children:g.recipient}),t.jsx("td",{className:"px-2 py-1",children:t.jsx(e.Badge,{variant:g.status==="SENT"?"default":"destructive",className:"text-[10px]",children:g.status})}),t.jsx("td",{className:"px-2 py-1",children:P(g.createdAt)}),t.jsx("td",{className:"px-2 py-1 text-muted-foreground",children:g.error||"--"})]},g.id))})]})})]},d))]})]}):t.jsx("div",{className:"p-4 text-sm text-muted-foreground",children:"Signal not found."})}function Y(){var c,u;const{quotasQuery:s,usageQuery:r}=e.useAlertQuotas(),n=((c=s.data)==null?void 0:c.quotas)||[],o=((u=r.data)==null?void 0:u.usage)||[],l=new Map(o.map(a=>[a.tenantId||"org",a]));return t.jsxs("div",{className:"space-y-4 p-4",children:[t.jsxs("div",{className:"flex items-center justify-between",children:[t.jsx("h2",{className:"text-xl font-semibold",children:"Alert Quotas"}),t.jsx(e.Button,{variant:"outline",size:"sm",onClick:()=>{s.refetch(),r.refetch()},children:"Refresh"})]}),s.isLoading||r.isLoading?t.jsx("p",{className:"text-sm text-muted-foreground",children:"Loading quota usage..."}):null,t.jsx("div",{className:"overflow-hidden rounded-lg border",children:t.jsxs("table",{className:"w-full text-sm",children:[t.jsx("thead",{className:"bg-muted/40",children:t.jsxs("tr",{children:[t.jsx("th",{className:"px-3 py-2 text-left font-medium",children:"Tenant"}),t.jsx("th",{className:"px-3 py-2 text-left font-medium",children:"Active Alerts"}),t.jsx("th",{className:"px-3 py-2 text-left font-medium",children:"Max Active"}),t.jsx("th",{className:"px-3 py-2 text-left font-medium",children:"Min Cadence"}),t.jsx("th",{className:"px-3 py-2 text-left font-medium",children:"Max Context Sources"})]})}),t.jsx("tbody",{children:n.map(a=>{const i=a.tenantId||"org",m=l.get(i);return t.jsxs("tr",{className:"border-t",children:[t.jsx("td",{className:"px-3 py-2",children:i}),t.jsx("td",{className:"px-3 py-2",children:(m==null?void 0:m.activeAlerts)??0}),t.jsx("td",{className:"px-3 py-2",children:a.policy.maxActiveAlerts}),t.jsxs("td",{className:"px-3 py-2",children:[a.policy.minCadenceMinutes," min"]}),t.jsx("td",{className:"px-3 py-2",children:a.policy.maxContextSources})]},i)})})]})})]})}exports.AlertManagementPage=e.AlertManagementPage;exports.AlertWizardDialog=e.AlertWizardDialog;exports.AlertsApiError=e.AlertsApiError;exports.CALCULATED_FIELD_ENTITY_MARKER=e.CALCULATED_FIELD_ENTITY_MARKER;exports.CardAlertIndicator=e.CardAlertIndicator;exports.CardSummary=e.CardSummary;exports.DATE_FORMAT_VALUES=e.DATE_FORMAT_VALUES;exports.Dashboard=e.Dashboard;exports.DashboardExportDialog=e.DashboardExportDialog;exports.DashboardWC=e.DashboardWC;exports.EmailScheduleDialog=e.EmailScheduleDialog;exports.ExportError=e.ExportError;exports.PivotMarkerEnum=e.PivotMarkerEnum;exports.ResourceType=e.ResourceType;exports.SemaphorContextProvider=e.SemaphorContextProvider;exports.SemaphorDataProvider=e.SemaphorQueryClient;exports.SemaphorQueryClient=e.SemaphorQueryClient;exports.ShareDialog=e.ShareDialog;exports.SummaryCard=e.SummaryCard;exports.Surfboard=e.DashboardPlus;exports.backtestAlert=e.backtestAlert;exports.cancelExport=e.cancelExport;exports.cloneDeep=e.cloneDeep;exports.createAlert=e.createAlert;exports.createEmptyKpiConfig=e.createEmptyKpiConfig;exports.createExport=e.createExport;exports.createSqlGenConfig=e.createSqlGenConfig;exports.deleteAlert=e.deleteAlert;exports.downloadPdf=e.downloadPdf;exports.emitDashboardLoad=e.emitDashboardLoad;exports.emitDashboardUnload=e.emitDashboardUnload;exports.fmt=e.fmt;exports.formatFileSize=e.formatFileSize;exports.getAlert=e.getAlert;exports.getAlertContextSources=e.getAlertContextSources;exports.getAlertHistory=e.getAlertHistory;exports.getAlertQuotaUsage=e.getAlertQuotaUsage;exports.getAlertRunDeliveries=e.getAlertRunDeliveries;exports.getAlertRunSteps=e.getAlertRunSteps;exports.getAlertRuns=e.getAlertRuns;exports.getAlertState=e.getAlertState;exports.getColumnDataType=e.getColumnDataType;exports.getDownloadUrl=e.getDownloadUrl;exports.getExportStatus=e.getExportStatus;exports.getExports=e.getExports;exports.getFilterValueType=e.getFilterValueType;exports.getFormattedTableNameForQuery=e.getFormattedTableNameForQuery;exports.getQualifiedTableName=e.getQualifiedTableName;exports.getSql=e.getSql;exports.invalidateToken=e.invalidateToken;exports.isBooleanDataType=e.isBooleanDataType;exports.isCalculatedDimension=e.isCalculatedDimension;exports.isCalculatedField=e.isCalculatedField;exports.isCalculatedMetric=e.isCalculatedMetric;exports.isColumnInSqlGen=e.isColumnInSqlGen;exports.isDateDataType=e.isDateDataType;exports.isExportComplete=e.isExportComplete;exports.isExportInProgress=e.isExportInProgress;exports.isNumberDataType=e.isNumberDataType;exports.isTextDataType=e.isTextDataType;exports.listAlertQuotas=e.listAlertQuotas;exports.listAlerts=e.listAlerts;exports.previewAlertDeliverable=e.previewAlertDeliverable;exports.resolveDataType=e.resolveDataType;exports.resolveDatamodelName=e.resolveDatamodelName;exports.triggerAlertNow=e.triggerAlertNow;exports.updateAlert=e.updateAlert;exports.updateAlertContextSources=e.updateAlertContextSources;exports.updateAlertQuota=e.updateAlertQuota;exports.useActiveExports=e.useActiveExports;exports.useAddNewFrame=e.useAddNewFrame;exports.useAlertActions=e.useAlertActions;exports.useAlertDeliveries=e.useAlertDeliveries;exports.useAlertDetail=e.useAlertDetail;exports.useAlertDraft=e.useAlertDraft;exports.useAlertFilters=e.useAlertFilters;exports.useAlertHistory=e.useAlertHistory;exports.useAlertQuotas=e.useAlertQuotas;exports.useAlertRuns=e.useAlertRuns;exports.useAlertState=e.useAlertState;exports.useAlertStore=e.useAlertStore;exports.useAlertWizard=e.useAlertWizard;exports.useAlerts=e.useAlerts;exports.useAlertsBootstrap=e.useAlertsBootstrap;exports.useAlertsById=e.useAlertsById;exports.useAlertsForCard=e.useAlertsForCard;exports.useCard=e.useCard;exports.useCardAlertMap=e.useCardAlertMap;exports.useCardSummary=e.useCardSummary;exports.useCurrentActiveCard=e.useCurrentActiveCard;exports.useCurrentCardConfig=e.useCurrentCardConfig;exports.useCurrentSheetActiveCards=e.useCurrentSheetActiveCards;exports.useDashboardActions=e.useDashboardActions;exports.useDashboardById=e.useDashboardById;exports.useDashboardQuery=e.useDashboardQuery;exports.useDashboardStore=e.useDashboardStore;exports.useDashboardSummary=e.useDashboardSummary;exports.useDataColumns=e.useDataColumns;exports.useDateFilterHook=e.useDateFilterHook;exports.useEditorActions=e.useEditorActions;exports.useEditorAside=e.useEditorAside;exports.useEditorStore=e.useEditorStore;exports.useExportActions=e.useExportActions;exports.useExportStore=e.useExportStore;exports.useInProgressExportsCount=e.useInProgressExportsCount;exports.useManagementStore=e.useManagementStore;exports.useResourceManagement=e.useResourceManagement;exports.useSelectedAlertId=e.useSelectedAlertId;exports.useTextFilterHook=e.useTextFilterHook;exports.CONTROL_CARD_DEFAULT_VALUE=_.CONTROL_CARD_DEFAULT_VALUE;exports.DEFAULT_CALENDAR_CONTEXT=_.DEFAULT_CALENDAR_CONTEXT;exports.DEFAULT_SEMANTIC_DOMAIN_ACCESS=_.DEFAULT_SEMANTIC_DOMAIN_ACCESS;exports.EMPTY_SELECTION=_.EMPTY_SELECTION;exports.CalendarPreferencesDialog=M.CalendarPreferencesDialog;exports.DashboardSummarySettingsDialog=M.DashboardSummarySettingsDialog;exports.ResourceManagementPanel=O.ResourceManagementPanel;exports.useDebouncedDirtyCheck=U.useDebouncedDirtyCheck;exports.AdvancedModeToggle=A.AdvancedModeToggle;exports.DashboardControlsSettings=A.DashboardControlsSettings;exports.DashboardFilterControlsButton=A.DashboardFilterControlsButton;exports.ExportNotificationItem=A.ExportNotificationItem;exports.ExportNotificationList=A.ExportNotificationList;exports.NotificationBell=A.NotificationBell;exports.UnsavedChangesAlert=A.UnsavedChangesAlert;exports.VisualEditingControls=A.VisualEditingControls;exports.useExportPolling=A.useExportPolling;exports.useExportRecovery=A.useExportRecovery;exports.usePristineSnapshotInitializer=A.usePristineSnapshotInitializer;exports.normalizeDashboardForDirtyCheck=L.normalizeDashboardForDirtyCheck;exports.serializeDashboardForDirtyCheck=L.serializeDashboardForDirtyCheck;exports.AlertDetailPageEmbedded=K;exports.Combobox=W;exports.ScheduleDashboard=H;exports.TenantQuotaPage=Y;exports.Visual=q;exports.useAlertBacktest=Q;exports.useExposePrintState=$;