react-semaphor 0.1.368 → 0.1.369
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/analytics-protocol/index.cjs +1 -1
- package/dist/analytics-protocol/index.js +1 -1
- package/dist/brand-studio/index.cjs +5 -5
- package/dist/brand-studio/index.js +24 -23
- package/dist/chunks/{braces-Cc86y9Ov.js → braces-C3-w6xDL.js} +1 -1
- package/dist/chunks/{braces-CXvY9MwQ.js → braces-C8QqW4wu.js} +1 -1
- package/dist/chunks/{calendar-preferences-dialog-BOFlzOJg.js → calendar-preferences-dialog-6q51A6XC.js} +3 -3
- package/dist/chunks/{calendar-preferences-dialog-ZzwfJv2J.js → calendar-preferences-dialog-CUGzkNcE.js} +1 -1
- package/dist/chunks/{chevrons-up-down-CUZL1zaU.js → chevrons-up-down-CnCSGY02.js} +1 -1
- package/dist/chunks/{chevrons-up-down-qQMadOWA.js → chevrons-up-down-DSvLu4Ye.js} +1 -1
- package/dist/chunks/{dashboard-briefing-launcher-9-PCYMjR.js → dashboard-briefing-launcher-BEZnvIla.js} +1 -1
- package/dist/chunks/{dashboard-briefing-launcher-D2lBFqAd.js → dashboard-briefing-launcher-ptERmNJr.js} +176 -177
- package/dist/chunks/{dashboard-controls-D4bUHAjX.js → dashboard-controls-CGt6_hMf.js} +11 -11
- package/dist/chunks/{dashboard-controls-BIk094Ah.js → dashboard-controls-CqKC5oEk.js} +77 -77
- package/dist/chunks/{dashboard-json-DImOf512.js → dashboard-json-6SgPm_QW.js} +13 -14
- package/dist/chunks/dashboard-json-CYSbOdmE.js +1 -0
- package/dist/chunks/{edit-dashboard-visual-DTxkV6Fl.js → edit-dashboard-visual-ByQx_M2i.js} +8 -9
- package/dist/chunks/{edit-dashboard-visual-BHKlcqQR.js → edit-dashboard-visual-w6hKbjlw.js} +1 -1
- package/dist/chunks/index-BtqYNH_S.js +1361 -0
- package/dist/chunks/{index-BVEIk-rB.js → index-CPyEi9gS.js} +72498 -76193
- package/dist/chunks/{palette-DPuAc82h.js → palette-D-f4-82S.js} +1 -1
- package/dist/chunks/{palette-C1k347Tb.js → palette-DUGktM-M.js} +1 -1
- package/dist/chunks/{resource-management-panel-BeHceP2D.js → resource-management-panel-Bf8-3eUf.js} +1 -1
- package/dist/chunks/{resource-management-panel-BOfbSf48.js → resource-management-panel-mJ84NxzC.js} +152 -152
- package/dist/chunks/save-D3YYinDz.js +6 -0
- package/dist/chunks/save-kkBEBeLg.js +21 -0
- package/dist/chunks/{switch-xcWLtWs0.js → switch-Dkx2qEOr.js} +758 -776
- package/dist/chunks/{switch-C0S63HAv.js → switch-fIkmwzUt.js} +27 -32
- package/dist/chunks/{use-create-flow-overlay-state-B5FygfQL.js → use-create-flow-overlay-state-BfoXDDrd.js} +190 -189
- package/dist/chunks/use-create-flow-overlay-state-c6rCm36x.js +26 -0
- package/dist/chunks/{use-visual-utils-DxDE8S8M.js → use-visual-utils-C_c-aiqi.js} +1 -1
- package/dist/chunks/{use-visual-utils-CszWnFBW.js → use-visual-utils-NN0e3fBP.js} +13 -13
- package/dist/chunks/validation-Dsf7PydY.js +1 -0
- package/dist/chunks/validation-nOPr0mTk.js +803 -0
- package/dist/chunks/{validators-L0xEXtjf.js → validators-CVuWOHYv.js} +225 -158
- package/dist/chunks/validators-oc8qtP4q.js +1 -0
- package/dist/dashboard/index.cjs +1 -1
- package/dist/dashboard/index.js +1 -1
- package/dist/dashboard-authoring/index.cjs +1 -1
- package/dist/dashboard-authoring/index.js +1 -1
- package/dist/data-app-builder/index.cjs +51 -1
- package/dist/data-app-builder/index.js +3666 -2
- package/dist/data-app-sdk/index.cjs +1 -1
- package/dist/data-app-sdk/index.js +589 -388
- package/dist/data-app-sdk-validation/index.cjs +1 -1
- package/dist/data-app-sdk-validation/index.js +4 -4
- package/dist/index.cjs +1 -1
- package/dist/index.js +14 -14
- package/dist/surfboard/index.cjs +1 -1
- package/dist/surfboard/index.js +2 -2
- package/dist/types/analytics-protocol.d.ts +21 -1
- package/dist/types/dashboard-assistant.d.ts +21 -1
- package/dist/types/dashboard-authoring.d.ts +11 -1
- package/dist/types/data-app-builder.d.ts +11 -1
- package/dist/types/data-app-sdk-validation.d.ts +107 -23
- package/dist/types/data-app-sdk.d.ts +168 -35
- package/dist/types/main.d.ts +11 -1
- package/package.json +1 -1
- package/dist/chunks/dashboard-json-Bo1kX6W1.js +0 -1
- package/dist/chunks/index-HjDeEytV.js +0 -1411
- package/dist/chunks/use-create-flow-overlay-state-DOXTbTcQ.js +0 -26
- package/dist/chunks/validation-CrUjNWby.js +0 -689
- package/dist/chunks/validation-DGl8wnTt.js +0 -1
- package/dist/chunks/validators-Dq5X4mp0.js +0 -1
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";const s=require("./switch-fIkmwzUt.js"),v=require("react"),p=require("./index-BtqYNH_S.js"),e=require("react/jsx-runtime");require("./index-BxM99sFL.js");const re=require("./use-visual-utils-C_c-aiqi.js"),he=require("./save-D3YYinDz.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 Ne=s.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 ge=s.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 be=s.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 De=s.createLucideIcon("Rows3",[["rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",key:"afitv7"}],["path",{d:"M21 9H3",key:"1338ky"}],["path",{d:"M21 15H3",key:"9uk58r"}]]);/**
|
|
22
|
+
* @license lucide-react v0.453.0 - ISC
|
|
23
|
+
*
|
|
24
|
+
* This source code is licensed under the ISC license.
|
|
25
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
26
|
+
*/const Ee=s.createLucideIcon("SendHorizontal",[["path",{d:"M3.714 3.048a.498.498 0 0 0-.683.627l2.843 7.627a2 2 0 0 1 0 1.396l-2.842 7.627a.498.498 0 0 0 .682.627l18-8.5a.5.5 0 0 0 0-.904z",key:"117uat"}],["path",{d:"M6 12h16",key:"s4cdu5"}]]);function we(){const l=s.useEditorStore(h=>h.card.dataSource),{setSelectedConnectionId:a,setSelectedDatabaseName:i,setSelectedSchemaName:d,setSelectedTableName:x,setSelectedDatamodelId:u}=s.useEditorActions();v.useEffect(()=>{var D;if(!l)return;const{tableName:h,schemaName:y,databaseName:g,connectionId:j}=p.extractTableMetadata(l),b=(D=l.selectedEntities)==null?void 0:D[0],C=(b==null?void 0:b.type)==="model"&&"id"in b?b.id:"";a(j||""),i(g||""),d(y||""),x(h||""),u(C)},[l,a,i,d,x,u])}function ae(){var g,j;const l=s.useEditorStore(b=>b.card),a=s.useEditorStore(b=>b.frame),i=v.useMemo(()=>p.findCustomVisualConfigCard(a,l),[a,l]),{manifest:d}=p.useCustomVisual(((g=i==null?void 0:i.customCardPreferences)==null?void 0:g.url)||""),x=v.useMemo(()=>{var b;return(b=d==null?void 0:d.visuals)==null?void 0:b.find(m=>{var C;return m.name===((C=i==null?void 0:i.customCardPreferences)==null?void 0:C.componentName)})},[d,(j=i==null?void 0:i.customCardPreferences)==null?void 0:j.componentName]),u=p.resolveMultiInputType(i,x),h=v.useMemo(()=>p.getCustomVisualInputCards({frame:a,configCard:i,isMultiInputVisual:u==="multiple"}),[a,i,u]),y=v.useMemo(()=>{const b=h.findIndex(m=>(m==null?void 0:m.id)===l.id);return b<0?-1:p.getSlotIndexForCard(l,b)},[h,l]);return v.useMemo(()=>!i||u!=="multiple"||y<0?l.type:p.getEffectiveCardTypeForSlot(l,y,x==null?void 0:x.slots)??l.type,[i,u,y,l,x==null?void 0:x.slots])}function Ve({type:l,isLinked:a,className:i,showLabel:d=!1,showLocal:x=!1}){const u=s.useDashboardStore(E=>E.selectedFrameId),h=p.useManagementStore(E=>E.selectedVisual),y=s.useEditorStore(E=>E.frame);let g;if(l)g=l;else if(a!==void 0)g=a?"linked":"library";else if(!!!(y!=null&&y.visualId||h!=null&&h.id)&&u)g="local";else if(h&&!u)g="library";else if(y!=null&&y.visualId&&u)g="linked";else if(h!=null&&h.id&&u)g="library";else return null;if(g==="local"&&!x)return null;const j={local:"border-slate-200/70 bg-slate-50/80 text-slate-700 shadow-sm hover:bg-slate-100/80 dark:border-slate-700 dark:bg-slate-900/70 dark:text-slate-200 dark:hover:bg-slate-800/80",linked:"border-purple-200/70 bg-gradient-to-r from-purple-50/50 to-purple-100/30 text-purple-900 shadow-sm hover:from-purple-100/60 hover:to-purple-100/50 hover:shadow-md dark:border-purple-800/50 dark:from-purple-950/40 dark:to-purple-900/30 dark:text-purple-100 dark:hover:from-purple-950/60 dark:hover:to-purple-900/50",library:"border-blue-200/70 bg-gradient-to-r from-blue-50/50 to-blue-100/30 text-blue-900 shadow-sm hover:from-blue-100/60 hover:to-blue-100/50 hover:shadow-md dark:border-blue-800/50 dark:from-blue-950/40 dark:to-blue-900/30 dark:text-blue-100 dark:hover:from-blue-950/60 dark:hover:to-blue-900/50"},b={local:"Local to this dashboard: Changes made here only affect this dashboard copy.",linked:"Linked to library: Changes made here update the library visual and all linked instances.",library:"Library visual: Share and reuse this visual across multiple dashboards."},m={local:"border-slate-200 bg-slate-50 text-slate-900 dark:border-slate-700 dark:bg-slate-900 dark:text-slate-100",linked:"border-purple-200 bg-purple-50 text-purple-900 dark:border-purple-800 dark:bg-purple-950 dark:text-purple-100",library:"border-blue-200 bg-blue-50 text-blue-900 dark:border-blue-800 dark:bg-blue-950 dark:text-blue-100"},C={local:"fill-slate-50 dark:fill-slate-900",linked:"fill-purple-50 dark:fill-purple-950",library:"fill-blue-50 dark:fill-blue-950"},D={local:e.jsx("span",{className:"h-2 w-2 rounded-full bg-current/70"}),linked:e.jsx(be,{className:"h-3.5 w-3.5"}),library:e.jsx(ge,{className:"h-3.5 w-3.5"})},N={local:"Local",linked:"Linked",library:"Library"};return e.jsx(s.TooltipProvider,{children:e.jsxs(s.Tooltip,{delayDuration:300,children:[e.jsx(s.TooltipTrigger,{asChild:!0,children:e.jsxs(p.Badge,{variant:"outline",className:s.cn("cursor-help select-none transition-all",j[g],i),children:[D[g],d&&e.jsx("span",{className:"ml-1 text-xs font-medium leading-none",children:N[g]})]})}),e.jsxs(s.TooltipContent,{side:"bottom",className:s.cn("max-w-xs",m[g]),children:[e.jsx(s.TooltipArrow,{className:C[g]}),e.jsx("p",{children:b[g]})]})]})})}function Te(l,a){return{...l,sql:"",python:"",config:void 0,customCfg:"",preferences:{},interactionConfig:void 0,linkedInteractionTargetOverrides:void 0,dynamicCardPreferences:void 0,customCardPreferences:a?l.customCardPreferences:void 0,visualizationMode:"builtin",type:a?l.type:"bar"}}function le(l){const a=s.getDynamicFrameSaveIssue(l);return a?(p.ue.error(a),!1):!0}function Ie({className:l,variant:a="outline"}){const i=s.useEditorStore(u=>u.onSave),{getUpdatedFrame:d}=re.useVisualUtils();function x(){const u=d();le(u)&&(i==null||i(u))}return e.jsxs(s.Button,{onClick:x,className:l,size:"xs",variant:a,children:[e.jsx(s.Check,{className:"h-3.5 w-3.5"}),"Accept"]})}function Le({className:l,variant:a="default"}){const i=p.useQueryClient(),[d,x]=v.useState(!1),u=s.useDashboardStore(C=>C.actions.setIsDashboardPanelOpen),{setIsVisualEditing:h}=s.useDashboardActions(),{getUpdatedFrame:y}=re.useVisualUtils(),g=p.useSelectedVisual(),j=s.useEditorStore(C=>C.frame),b=p.useUpdateVisualMutation(),m=()=>{const C=y();if(!le(C))return;const D=(j==null?void 0:j.visualId)||(g==null?void 0:g.id);if(!D){p.ue.error("No visual to save");return}x(!0),b.mutate({visualId:D,data:{frameObject:C}},{onSuccess:()=>{x(!1),u(!0),p.ue.success("Visual updated successfully"),i.invalidateQueries({queryKey:["resource-by-id","visual",D],exact:!0})},onError:()=>{x(!1),p.ue.error("Failed to update visual")}})};return e.jsx(s.Button,{onClick:m,className:l,size:"xs",variant:a,children:d?e.jsxs(e.Fragment,{children:[e.jsx(s.LoaderCircle,{className:"h-3.5 w-3.5 animate-spin"}),"Saving"]}):e.jsxs(e.Fragment,{children:[e.jsx(he.Save,{className:"h-3.5 w-3.5"}),"Save to Library"]})})}function Fe({className:l}){const a=p.useQueryClient(),[i,d]=v.useState(!1),x=p.useSelectedVisual(),u=s.useEditorStore(N=>N.frame),h=s.useDashboardStore(N=>N.selectedSheetId),y=s.useDashboardStore(N=>N.dashboard),{updateFrame:g,setIsVisualEditing:j}=s.useDashboardActions(),{getUpdatedFrame:b}=re.useVisualUtils(),m=p.useUpdateVisualMutation(),C=p.useResolveExistingFrameSemanticExecutionPayload(),D=async()=>{if(!h){p.ue.error("No sheet selected");return}const N=(u==null?void 0:u.visualId)||(x==null?void 0:x.id);if(!N){p.ue.error("No visual to update");return}d(!0);try{const E=b();if(!le(E)){d(!1);return}const F={...E,visualId:N},Q=p.findDashboardFrameById(y,F.id),U=await C(F,{previousFrame:Q});await m.mutateAsync({visualId:N,data:{frameObject:E}}),g(h,F,{semanticExecutionPayload:U}),a.invalidateQueries({queryKey:["visuals"]}),a.invalidateQueries({queryKey:["visual",N]}),p.ue.success("Saved to library and applied locally"),setTimeout(()=>{j(!1)},300)}catch(E){console.error("Failed to save and apply:",E),p.ue.error(E instanceof Error?E.message:"Failed to save and apply changes")}finally{d(!1)}};return e.jsx(s.Button,{onClick:D,className:l,size:"xs",variant:"default",disabled:i,children:i?e.jsxs(e.Fragment,{children:[e.jsx(s.LoaderCircle,{className:"h-3.5 w-3.5 animate-spin"}),"Saving..."]}):e.jsxs(e.Fragment,{children:[e.jsx(he.Save,{className:"h-3.5 w-3.5"}),"Save & Apply"]})})}function _e({className:l}){const{setTempQueryData:a,setSqlGen:i}=s.useEditorActions(),d=p.useQueryClient(),x=s.useEditorStore(m=>m.tempQueryData),u=s.useEditorStore(m=>m.onClose),h=s.useEditorStore(m=>m.card),y=ae(),g=v.useMemo(()=>y!==h.type?{...h,type:y}:h,[h,y]),{queryKey:j}=p.useEditorCardQuery(g);function b(){if(x){const{queryKey:m,queryData:C}=x;m&&C&&d.setQueryData(m,C)}i({}),u==null||u()}return e.jsxs(s.Button,{onClick:b,className:l,size:"xs",variant:"outline",children:[e.jsx(s.X,{className:"h-3.5 w-3.5"}),"Close"]})}function Be({label:l="Clear",variant:a="secondary",className:i}={}){const{setTempQueryData:d}=s.useEditorActions(),x=p.useQueryClient(),u=s.useEditorStore(q=>q.tempQueryData),h=s.useEditorStore(q=>q.card),y=ae(),g=v.useMemo(()=>y!==h.type?{...h,type:y}:h,[h,y]),{queryKey:j}=p.useEditorCardQuery(g),{setCardSql:b,setSqlGen:m,setCardPython:C,setCardCustomCfg:D,setCardPreferences:N,clearQueryConfig:E,setCardConfig:F,setCardType:Q,setFrame:U,setCard:X,setActiveTabCardId:P}=s.useEditorActions();function W(){var Y,G,L,H;const q=x.getQueryData(j);u!=null&&u.queryData||d({queryKey:j,queryData:q}),x.setQueryData(j,null),x.removeQueries({queryKey:j,exact:!0}),b(""),m({}),E(),F(void 0),C(""),D(""),N({});const r=s.useEditorStore.getState().frame,T=s.useEditorStore.getState().card,I=p.findCustomVisualConfigCard(r,T),A=((Y=I==null?void 0:I.customCardPreferences)==null?void 0:Y.visualType)==="multiple"||!!((G=I==null?void 0:I.customCardPreferences)!=null&&G.dataInputCardIds)||(((L=I==null?void 0:I.customCardPreferences)==null?void 0:L.minInputs)||0)>1||(((H=I==null?void 0:I.customCardPreferences)==null?void 0:H.maxInputs)||0)>1,M=Te(T,A);U({...r,cards:r.cards.map(O=>O.id===M.id?M:O)}),P(M.id),X(M),A||Q("bar")}return e.jsxs(s.Button,{onClick:W,className:i,size:"xs",variant:a,children:[e.jsx(s.X,{className:"h-3.5 w-3.5"}),l]})}function ye(l){const{control:a,onChange:i}=l;return e.jsxs("div",{className:"flex flex-col gap-1.5",children:[e.jsx(s.Label,{className:"text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground",children:"Label"}),e.jsx(s.Input,{size:"xs",value:a.label,placeholder:"Control label",onChange:d=>i(d.target.value)})]})}function qe(l){const{currentStep:a,labels:i}=l;return e.jsx("div",{className:"sticky top-0 z-10 -mx-1 border-b border-border/60 bg-background/95 px-1 pb-2.5 pt-1 backdrop-blur supports-[backdrop-filter]:bg-background/85",children:e.jsx("div",{className:"flex flex-wrap items-center gap-2 sm:gap-2.5",children:i.map((d,x)=>{const u=x+1,h=u===a,y=u<a;return e.jsxs(v.Fragment,{children:[e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("span",{className:s.cn("flex h-5 w-5 items-center justify-center rounded-full border text-[10px] font-medium tabular-nums",h?"border-foreground bg-foreground text-background":y?"border-foreground/30 bg-foreground/10 text-foreground":"border-border/60 bg-background text-muted-foreground"),children:u}),e.jsx("span",{className:s.cn("text-[12px]",h?"font-medium text-foreground":"text-muted-foreground"),children:d})]}),x<i.length-1?e.jsx("span",{className:"h-px w-4 bg-border/60 sm:w-6","aria-hidden":"true"}):null]},d)})})})}function J(l){const{secondary:a,tertiary:i,primary:d}=l;return e.jsxs("div",{className:"sticky bottom-0 z-10 -mx-1 flex justify-end gap-2 border-t bg-background/95 px-1 pb-1 pt-3 backdrop-blur supports-[backdrop-filter]:bg-background/85",children:[a,i,d]})}function Ae(l){const{control:a,scope:i,detail:d}=l;return e.jsxs("div",{className:"flex items-start gap-2.5 rounded-control border border-border/60 bg-muted/30 px-3 py-2.5",children:[e.jsx(p.CircleCheck,{className:"mt-0.5 h-3.5 w-3.5 shrink-0 text-foreground"}),e.jsxs("div",{className:"min-w-0 space-y-0.5",children:[e.jsx("div",{className:"text-[13px] font-medium text-foreground",children:a.label}),e.jsxs("div",{className:"text-[12px] text-muted-foreground",children:[s.getFriendlyTypeOption(a.type).label," ·"," ",s.getControlOptionPreview(a)," ·"," ",s.getPlacementLabel(i,a.placement)]}),d?e.jsx("div",{className:"text-[12px] text-muted-foreground",children:d}):null]})]})}function me(l){const{control:a,defaultValue:i,availableFieldChoices:d,availableMetricChoices:x,previewControlDefinitions:u,previewControlValues:h,onControlChange:y,onLabelChange:g,onDefaultValueChange:j,onBack:b,onNext:m,nextDisabled:C}=l;return e.jsxs("div",{className:"space-y-3",children:[e.jsx(ye,{control:a,onChange:g}),e.jsx(p.ControlDefinitionOptionsEditor,{control:a,availableFieldChoices:d,availableMetricChoices:x,previewControlDefinitions:u,previewControlValues:h,controlLifecycle:"create",onChange:y}),e.jsx(p.ControlDefaultValueEditor,{control:a,value:i,onChange:j,allowNoDefault:!0,allowCardDefault:!0,hint:"This is the value viewers will see first.",previewControlDefinitions:u,previewControlValues:h}),e.jsx(J,{secondary:e.jsx(s.Button,{type:"button",variant:"outline",size:"xs",onClick:b,children:"Back"}),primary:e.jsx(s.Button,{type:"button",size:"xs",onClick:m,disabled:C,children:"Next"})})]})}const Me=new Set(["grain_selector","aggregation_selector","field_selector","metric_selector"]);function xe(l){const{text:a,ariaLabel:i}=l,[d,x]=v.useState(!1);return e.jsxs("button",{type:"button","aria-label":i,onClick:async()=>{try{await navigator.clipboard.writeText(a),x(!0),setTimeout(()=>x(!1),1200)}catch(u){console.error("Failed to copy",u)}},className:"group flex w-full items-center justify-between gap-2 rounded-control bg-muted/40 px-2 py-1 text-left transition-colors hover:bg-muted/60 focus-visible:bg-muted/60 focus-visible:outline-none",children:[e.jsx("code",{className:"min-w-0 truncate font-mono text-[12px] text-foreground",children:a}),e.jsx("span",{className:"shrink-0 text-[11px] text-muted-foreground opacity-0 transition-opacity group-hover:opacity-100",children:d?"Copied":"Click to copy"})]})}function fe(l){const{control:a,scope:i,createdReference:d,explorerContent:x,sqlDescription:u,summaryDetail:h,onBack:y,onCancel:g,onDone:j}=l,b=Me.has(a.type),m=d.match(/\[\[param\.(.+?)\]\]/),C=m?`{{ param('${m[1]}') }}`:"";return e.jsxs("div",{className:"space-y-4",children:[e.jsx(Ae,{control:a,scope:i,detail:h}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("p",{className:"text-[13px] font-medium text-foreground",children:"How cards use this control"}),e.jsxs("div",{className:"divide-y divide-border/60 overflow-hidden rounded-control border border-border/60",children:[b?e.jsxs("div",{className:"space-y-1 px-3 py-2.5",children:[e.jsx("p",{className:"text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground",children:"Explorer cards"}),e.jsx("div",{className:"text-[12px] text-muted-foreground",children:x})]}):null,e.jsxs("div",{className:"space-y-1.5 px-3 py-2.5",children:[e.jsx("p",{className:"text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground",children:"SQL cards"}),e.jsx(xe,{text:d,ariaLabel:"Copy SQL control reference"}),C?e.jsx(xe,{text:C,ariaLabel:"Copy Jinja control reference"}):null,e.jsxs("p",{className:"text-[12px] text-muted-foreground",children:[u," ",e.jsx("a",{href:"https://docs.semaphor.cloud/docs/concepts/template-expressions",target:"_blank",rel:"noreferrer",className:"underline underline-offset-2 hover:text-foreground",children:"Template expressions docs"}),"."]})]})]})]}),e.jsx(J,{secondary:e.jsx(s.Button,{type:"button",variant:"outline",size:"xs",onClick:y,children:"Back"}),tertiary:e.jsx(s.Button,{type:"button",variant:"outline",size:"xs",onClick:g,children:"Cancel"}),primary:e.jsx(s.Button,{type:"button",size:"xs",onClick:j,children:"Done"})})]})}function Oe(l){const a=s.createBlankControl(l.scope,l.existingControls,l.reservedIds),i=l.type===a.type?{...a,label:s.DEFAULT_LABEL_BY_TYPE[l.type]}:{...s.applyControlTypeChange({controls:[{...a,label:s.DEFAULT_LABEL_BY_TYPE[l.type]}],controlId:a.id,nextType:l.type}).controls[0],label:s.DEFAULT_LABEL_BY_TYPE[l.type]};return{step:2,control:i,defaultValue:s.getDefaultValueForType(i,void 0)}}function ze({scope:l,controls:a,reservedControlIds:i,defaultValues:d,onChange:x,emptyMessage:u,initialCreateFlow:h=!1,usageByControlId:y,availableFieldChoices:g,availableMetricChoices:j,structuralParticipants:b,structuralParticipantIdsByControlId:m,card:C,allowedControlTypes:D,onCreateFlowActiveChange:N,onCreateFlowComplete:E}){const F=v.useMemo(()=>new Set(i||[]),[i]),Q=s.getPlacementOptionsForScope(l),U=s.getDefaultPlacement(l),[X,P]=v.useState(null),[W,q]=v.useState(null),[r,T]=v.useState(()=>h?{step:1,control:s.createBlankControl(l,a,Array.from(F))}:null),I=v.useRef({}),A=v.useRef(void 0),M=v.useRef(h),Y=v.useMemo(()=>{const t=s.getFriendlyControlTypeOptions({scope:l,card:C});if(!D)return t;const o=new Set(D);return t.filter(n=>o.has(n.value))},[D,C,l]),G=v.useCallback(t=>{const o=s.getFriendlyControlTypeOptions({scope:l,card:C,includeType:D?void 0:t});if(!D)return o;const n=new Set(D);return o.filter(c=>n.has(c.value))},[D,C,l]),L=v.useCallback(t=>l==="dashboard"&&(t==="field_selector"||t==="metric_selector"),[l]),H=v.useMemo(()=>r?s.getEligibleParticipantsForStructuralControl(b||[],r.control.type):[],[r,b]),O=v.useMemo(()=>{if(!r)return{fields:g||[],metrics:j||[]};if(!L(r.control.type))return{fields:g||[],metrics:j||[]};const t=r.selectedCardIds||[],o=s.getCompatibleStructuralChoiceCatalog({controlType:r.control.type,participants:b||[],selectedCardIds:t});return{fields:r.control.type==="field_selector"?o.choices.map(n=>({option:n,target:o.fieldTargetMap[n.value]})):[],metrics:r.control.type==="metric_selector"?o.choices.map(n=>({option:n,target:o.metricTargetMap[n.value]})):[]}},[g,j,r,L,b]);v.useEffect(()=>{N==null||N(!!r)},[r,N]),v.useEffect(()=>{const t=h&&!M.current;M.current=h,t&&(T({step:1,control:s.createBlankControl(l,a,Array.from(F))}),q(null),P(null))},[a,h,F,l]);const ve=t=>{if(!L(t.type))return{fields:g||[],metrics:j||[]};const o=(m==null?void 0:m[t.id])||[];if(o.length===0)return{fields:g||[],metrics:j||[]};const n=s.getCompatibleStructuralChoiceCatalog({controlType:t.type,participants:b||[],selectedCardIds:o});return{fields:t.type==="field_selector"?n.choices.map(c=>({option:c,target:n.fieldTargetMap[c.value]})):[],metrics:t.type==="metric_selector"?n.choices.map(c=>({option:c,target:n.metricTargetMap[c.value]})):[]}},ne=t=>{if(!L(t.control.type))return{nextControl:t.control,cardBindingsById:void 0};const o=(m==null?void 0:m[t.control.id])||[],n=s.getCompatibleStructuralChoiceCatalog({controlType:t.control.type,participants:b||[],selectedCardIds:t.nextSelectedCardIds}),c=s.reconcileStructuralControlChoices({control:t.control,choices:n.choices}),S=Object.fromEntries(o.filter(k=>!t.nextSelectedCardIds.includes(k)).map(k=>[k,void 0]));return t.nextSelectedCardIds.length>0&&c.source.kind==="manual"&&c.source.options.length>0&&Object.assign(S,s.buildStructuralControlBindingsForParticipants({control:c,participants:b||[],selectedCardIds:t.nextSelectedCardIds})),{nextControl:c,cardBindingsById:S}},B=v.useCallback((t,o=d,n={type:"update"})=>{const c=t.map(S=>(s.resolveAuthoringControlDefaultValue({control:S,defaultValues:o}),s.syncSqlQueryControlExecutionRequirement(S)));x(c,o,n)},[d,x]),K=(t,o)=>{const n=a.find(V=>V.id===t);let c=a.map(V=>V.id!==t?V:o(V));const S=c.find(V=>V.id===t);let k,f;if(S&&l==="dashboard"&&(S.type==="field_selector"||S.type==="metric_selector")){const V=(m==null?void 0:m[S.id])||[],R=ne({control:S,nextSelectedCardIds:V});c=c.map(z=>z.id===t?R.nextControl:z),k=R.cardBindingsById,f=[S.id]}else if(n&&l==="dashboard"&&(n.type==="field_selector"||n.type==="metric_selector")){const V=(m==null?void 0:m[n.id])||[];k=Object.fromEntries(V.map(R=>[R,void 0])),f=[n.id]}const w=c.find(V=>V.id===t);let _=d;if(n&&w){const V=s.resolveAuthoringControlDefaultValue({control:n,defaultValues:d});n.source.kind==="manual"&&w.source.kind==="sql_query"&&(I.current[t]=V);const R=V===void 0&&n.source.kind==="sql_query"&&w.source.kind==="manual"?I.current[t]:V,z=s.getNextEditedControlDefaultValue({previousControl:n,nextControl:w,currentDefaultValue:R});w.source.kind==="manual"&&(I.current[t]=z),d&&(_={...d},z===void 0?delete _[t]:_[t]=z),c=c.map(pe=>pe.id===t?{...w,defaultValue:z}:pe)}B(c,_,{type:"update",cardBindingsById:k,affectedBindingControlIds:f})},Ce=(t,o)=>{if(!o.trim())return;const n=p.normalizeDashboardInputVariableName(o);if(n===t||F.has(n)||a.some(k=>k.id===n&&k.id!==t))return;const c=a.map(k=>k.id===t?{...k,id:n}:k);if(!d){B(c,void 0,{type:"rename",oldId:t,newId:n});return}const S={...d};Object.prototype.hasOwnProperty.call(S,t)&&(S[n]=S[t],delete S[t]),B(c,S,{type:"rename",oldId:t,newId:n})},je=t=>{const o=a.filter(c=>c.id!==t);if(!d){B(o,void 0,{type:"remove",controlId:t});return}const n={...d};delete n[t],B(o,n,{type:"remove",controlId:t})},Se=v.useCallback(()=>{A.current=void 0,T({step:1,control:s.createBlankControl(l,a,Array.from(F))}),q(null),P(null)},[a,F,l]),$=t=>{T(o=>o&&(()=>{const n=t(o.control);o.control.source.kind==="manual"&&n.source.kind==="sql_query"&&(A.current=o.defaultValue);const c=o.defaultValue===void 0&&o.control.source.kind==="sql_query"&&n.source.kind==="manual"?A.current:o.defaultValue,S=s.getNextEditedControlDefaultValue({previousControl:o.control,nextControl:n,currentDefaultValue:c});return n.source.kind==="manual"&&(A.current=S),{...o,control:n,defaultValue:S}})())},oe=t=>{T(o=>o&&(o.control.source.kind==="manual"&&(A.current=t),{...o,defaultValue:t}))},Z=(()=>{if(!r)return!1;if(r.step===2&&L(r.control.type))return(r.selectedCardIds||[]).length>0;if(r.step!==2&&r.step!==3||!r.control.label.trim())return!1;const o=r.control.source.kind==="sql_query"?r.control:s.ensureManualSource(r.control);if(o.source.kind==="manual"&&(s.needsManualOptions(o)&&o.source.options.length===0||o.source.options.some(c=>c.label.trim().length===0||c.value.trim().length===0)))return!1;if(o.source.kind==="sql_query"){const{connectionId:n,sql:c,valueColumn:S}=o.source;return n.trim().length>0&&c.trim().length>0&&S.trim().length>0}return s.hasConcreteDefaultValue(s.getDefaultValueForType(o,r.defaultValue))})(),ie=()=>{var k;if(!r)return;const t=s.ensureManualSource(r.control),o=s.deriveUniqueControlId({label:t.label,fallbackId:t.id,existingControls:a,reservedIds:Array.from(F)}),n={...t,id:o},c=l==="dashboard"&&(n.type==="field_selector"||n.type==="metric_selector")&&((k=r.selectedCardIds)!=null&&k.length)?s.buildStructuralControlBindingsForParticipants({control:n,participants:b||[],selectedCardIds:r.selectedCardIds}):void 0,S=s.getDefaultValueForType(n,r.defaultValue);T({step:l==="dashboard"&&(n.type==="field_selector"||n.type==="metric_selector")?4:3,control:n,defaultValue:S,createdControlId:o,selectedCardIds:r.selectedCardIds,cardBindingsById:c})},ee=v.useCallback(()=>{T(null)},[]),de=v.useCallback(()=>{if(!(r!=null&&r.createdControlId)){T(null);return}const t=r.control,o=r.createdControlId,n=s.getDefaultValueForType(t,r.defaultValue);if(d){const c={...d};n===void 0?delete c[o]:c[o]=n,B([...a,{...t,defaultValue:n}],c,{type:"add",cardBindingsById:r.cardBindingsById})}else B([...a,{...t,defaultValue:n}],void 0,{type:"add",cardBindingsById:r.cardBindingsById});q(o),T(null),E==null||E()},[a,r,d,B,E]),ke=r?L(r.control.type)?["Choose type","Select cards","Configure","Finish"]:["Choose type","Configure","Finish"]:[],ce=r!=null&&r.createdControlId?`[[param.${r.createdControlId}]]`:r?`[[param.${s.slugifyControlValue(r.control.label)||r.control.id}]]`:"",te=s.buildAuthoringPreviewControlValues({controls:a,defaultValues:d}),se=r?[...a,r.control]:a,ue=r?s.buildAuthoringPreviewControlValues({controls:se,defaultValues:d,overrides:[{controlId:r.control.id,value:r.defaultValue}]}):te;return e.jsxs("div",{className:"space-y-4",children:[r?e.jsxs("div",{className:"space-y-4 pb-1",children:[e.jsx(qe,{currentStep:r.step,labels:ke}),r.step===1&&(()=>{const t=new Set(["grain_selector","aggregation_selector","field_selector","metric_selector"]),o=new Set(["date","text"]),n=Y.filter(k=>!t.has(k.value)&&!o.has(k.value)),c=Y.filter(k=>t.has(k.value)),S=k=>e.jsxs("button",{type:"button",className:"rounded-control border border-border/60 bg-background px-3 py-2.5 text-left transition-colors hover:bg-muted/40 focus-visible:bg-muted/40 focus-visible:outline-none",onClick:()=>T(Oe({scope:l,existingControls:a,reservedIds:Array.from(F),type:k.value})),children:[e.jsx("div",{className:"text-[13px] font-medium text-foreground",children:k.label}),e.jsx("p",{className:"mt-0.5 text-[12px] text-muted-foreground",children:k.description})]},k.value);return e.jsxs("div",{className:"space-y-4",children:[l==="card"&&(C==null?void 0:C.sql)==null?e.jsx("p",{className:"text-[12px] text-muted-foreground",children:"Explorer cards support displayed metric, group by field, aggregation, and time grain controls here."}):null,n.length>0&&e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("p",{className:"text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground",children:"Input controls"}),e.jsx("div",{className:"grid gap-1.5 sm:grid-cols-2",children:n.map(S)})]}),c.length>0&&e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("p",{className:"text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground",children:"Data-driven controls"}),e.jsx("div",{className:"grid gap-1.5 sm:grid-cols-2",children:c.map(S)})]}),e.jsx(J,{secondary:e.jsx(s.Button,{type:"button",variant:"outline",size:"xs",onClick:ee,children:"Back to controls"})})]})})(),r.step===2&&L(r.control.type)&&e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"space-y-3",children:[e.jsx(ye,{control:r.control,onChange:t=>$(o=>({...o,label:t}))}),e.jsx("p",{className:"text-[12px] text-muted-foreground",children:"Choose which cards should respond to this shared control."})]}),H.length===0?e.jsx("div",{className:"rounded-control border border-border/60 bg-muted/30 px-3 py-2.5 text-[12px] text-muted-foreground",children:"No eligible cards are available yet. Add compatible metrics or group-by fields to cards first."}):e.jsx("div",{className:"space-y-1 rounded-control border border-border/60 bg-background p-2",children:H.map(t=>{const o=(r.selectedCardIds||[]).includes(t.cardId);return e.jsxs("label",{className:"flex items-start gap-2 rounded-control px-1.5 py-1 text-[13px] hover:bg-muted/40",children:[e.jsx(p.Checkbox,{checked:o,onCheckedChange:n=>T(c=>c&&{...c,selectedCardIds:n===!0?[...c.selectedCardIds||[],t.cardId]:(c.selectedCardIds||[]).filter(S=>S!==t.cardId)})}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"font-medium text-foreground",children:t.title}),e.jsx("div",{className:"text-[12px] text-muted-foreground",children:r.control.type==="field_selector"?`${t.fieldChoices.length} compatible group-by fields`:`${t.metricChoices.length} compatible metrics`})]})]},t.cardId)})}),e.jsx(J,{secondary:e.jsx(s.Button,{type:"button",variant:"outline",size:"xs",onClick:()=>T(t=>t&&{...t,step:1,selectedCardIds:[]}),children:"Back"}),primary:e.jsx(s.Button,{type:"button",size:"xs",onClick:()=>T(t=>t&&{...t,step:3}),disabled:!Z,children:"Next"})})]}),r.step===2&&!L(r.control.type)&&e.jsx(me,{control:r.control,defaultValue:r.defaultValue,availableFieldChoices:O.fields,availableMetricChoices:O.metrics,previewControlDefinitions:se,previewControlValues:ue,onControlChange:t=>$(()=>t),onLabelChange:t=>$(o=>({...o,label:t})),onDefaultValueChange:oe,onBack:()=>T(t=>t&&{...t,step:1}),onNext:ie,nextDisabled:!Z}),r.step===3&&L(r.control.type)&&e.jsx(me,{control:r.control,defaultValue:r.defaultValue,availableFieldChoices:O.fields,availableMetricChoices:O.metrics,previewControlDefinitions:se,previewControlValues:ue,onControlChange:t=>$(()=>t),onLabelChange:t=>$(o=>({...o,label:t})),onDefaultValueChange:oe,onBack:()=>T(t=>t&&{...t,step:2}),onNext:ie,nextDisabled:!Z}),r.step===3&&!L(r.control.type)&&e.jsx(fe,{control:r.control,scope:l,createdReference:ce,explorerContent:e.jsxs(e.Fragment,{children:["Open the card and use"," ",e.jsx("span",{className:"font-medium text-foreground",children:"Settings → Controls"})," ","to choose what this control changes."]}),sqlDescription:"Reference this control directly in the SQL editor.",onBack:()=>T(t=>t&&{...t,step:2}),onCancel:ee,onDone:de}),r.step===4&&L(r.control.type)&&e.jsx(fe,{control:r.control,scope:l,createdReference:ce,summaryDetail:e.jsxs(e.Fragment,{children:["Used by ",(r.selectedCardIds||[]).length," selected card",(r.selectedCardIds||[]).length===1?"":"s"]}),explorerContent:e.jsx(e.Fragment,{children:"Selected cards have been set up to respond to this control automatically."}),sqlDescription:"SQL cards can still reference this control directly in the SQL editor.",onBack:()=>T(t=>t&&{...t,step:3}),onCancel:ee,onDone:de})]}):null,!r&&a.length===0?e.jsx("div",{className:"rounded-md border border-dashed p-3 text-sm text-muted-foreground",children:u}):null,!r&&a.map(t=>{const o=ve(t),n=y==null?void 0:y[t.id],c=s.resolveAuthoringControlDefaultValue({control:t,defaultValues:d}),S=W===t.id,k="inline-flex shrink-0 items-center rounded-[4px] border border-border/60 bg-muted/40 px-1.5 py-0.5 text-[11px] font-medium text-muted-foreground";return e.jsxs("div",{className:"rounded-control border border-border/60",children:[e.jsxs("div",{className:"flex items-center gap-2 px-3 py-2.5",children:[e.jsxs("button",{type:"button",className:"flex min-w-0 flex-1 items-start gap-2 rounded-control text-left focus:outline-none focus-visible:bg-muted/40",onClick:()=>q(f=>f===t.id?null:t.id),children:[S?e.jsx(s.ChevronDown,{className:"mt-0.5 h-3.5 w-3.5 shrink-0 text-muted-foreground"}):e.jsx(p.ChevronRight,{className:"mt-0.5 h-3.5 w-3.5 shrink-0 text-muted-foreground"}),e.jsxs("div",{className:"min-w-0",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-1.5",children:[e.jsx("span",{className:"truncate text-[13px] font-medium text-foreground",children:t.label||"Untitled control"}),e.jsx("span",{className:k,children:s.getFriendlyTypeOption(t.type).label}),e.jsx("span",{className:k,children:s.getPlacementLabel(l,t.placement)})]}),e.jsxs("div",{className:"mt-0.5 text-[12px] text-muted-foreground",children:[s.getControlOptionPreview(t),n!=null&&n.status?` · ${n.status}`:""]})]})]}),e.jsx(s.Button,{type:"button",size:"xs",variant:"ghost",className:"h-7 w-7 shrink-0 p-0 text-muted-foreground",onClick:()=>je(t.id),"aria-label":`Remove ${t.label}`,children:e.jsx(p.Trash2,{className:"h-3.5 w-3.5"})})]}),S&&e.jsxs("div",{className:"space-y-4 border-t border-border/60 px-3 py-3",children:[e.jsxs("div",{className:"grid gap-3 md:grid-cols-3",children:[e.jsxs("div",{className:"flex flex-col gap-1.5",children:[e.jsx(s.Label,{className:"text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground",children:"Label"}),e.jsx(s.Input,{size:"xs",value:t.label,placeholder:"Control label",onChange:f=>K(t.id,w=>({...w,label:f.target.value}))})]}),e.jsxs("div",{className:"flex flex-col gap-1.5",children:[e.jsx(s.Label,{className:"text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground",children:"Type"}),e.jsxs(s.Select,{value:t.type,onValueChange:f=>{const w=s.applyControlTypeChange({controls:a,controlId:t.id,nextType:f,defaultValues:d});B(w.controls,w.defaultValues)},children:[e.jsx(s.SelectTrigger,{size:"xs",children:e.jsx(s.SelectValue,{})}),e.jsx(s.SelectContent,{children:G(t.type).map(f=>e.jsx(s.SelectItem,{value:f.value,children:f.label},f.value))})]})]}),e.jsxs("div",{className:"flex flex-col gap-1.5",children:[e.jsx(s.Label,{className:"text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground",children:"Show in"}),e.jsxs(s.Select,{value:t.placement||U,onValueChange:f=>K(t.id,w=>({...w,placement:f})),children:[e.jsx(s.SelectTrigger,{size:"xs",children:e.jsx(s.SelectValue,{})}),e.jsx(s.SelectContent,{children:Q.map(f=>e.jsx(s.SelectItem,{value:f.value,children:f.label},f.value))})]})]})]}),L(t.type)?e.jsx(p.StructuralParticipantSelector,{type:t.type,participants:s.getEligibleParticipantsForStructuralControl(b||[],t.type).map(f=>({cardId:f.cardId,title:f.title,choiceCount:t.type==="field_selector"?f.fieldChoices.length:f.metricChoices.length})),selectedCardIds:(m==null?void 0:m[t.id])||[],onChange:f=>{const w=ne({control:t,nextSelectedCardIds:f}),_=a.map(V=>V.id===t.id?w.nextControl:V);B(_,d,{type:"update",cardBindingsById:w.cardBindingsById})}}):null,e.jsx(p.ControlDefinitionOptionsEditor,{control:t,availableFieldChoices:o.fields,availableMetricChoices:o.metrics,previewControlDefinitions:a,previewControlValues:te,controlLifecycle:"edit",onChange:f=>K(t.id,()=>f)}),t.initialValueStrategy==="saved_default"&&e.jsx(p.ControlDefaultValueEditor,{control:t,value:c,allowNoDefault:!0,allowCardDefault:!0,previewControlDefinitions:a,previewControlValues:te,onChange:f=>{const w=a.map(_=>_.id===t.id?{..._,defaultValue:f}:_);if(t.source.kind==="manual"&&(I.current[t.id]=f),d){const _={...d};f===void 0?delete _[t.id]:_[t.id]=f,B(w,_);return}B(w,void 0)}}),e.jsxs(p.Collapsible,{open:X===t.id,onOpenChange:f=>P(f?t.id:null),children:[e.jsx(p.CollapsibleTrigger,{asChild:!0,children:e.jsxs(s.Button,{type:"button",variant:"ghost",size:"xs",className:"-ml-2 gap-1 text-muted-foreground hover:text-foreground",children:[X===t.id?e.jsx(s.ChevronDown,{className:"h-3.5 w-3.5"}):e.jsx(p.ChevronRight,{className:"h-3.5 w-3.5"}),"Advanced"]})}),e.jsxs(p.CollapsibleContent,{className:"space-y-3 pt-2",children:[e.jsxs("div",{className:"grid gap-3 md:grid-cols-2",children:[e.jsxs("div",{className:"flex flex-col gap-1.5",children:[e.jsx(s.Label,{className:"text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground",children:"Variable name"}),e.jsx(p.ControlIdInput,{controlId:t.id,onCommit:f=>Ce(t.id,f)},t.id)]}),e.jsxs("div",{className:"flex flex-col gap-1.5",children:[e.jsx(s.Label,{className:"text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground",children:"Initial value"}),e.jsxs(s.Select,{value:t.initialValueStrategy,onValueChange:f=>K(t.id,w=>({...w,initialValueStrategy:f})),children:[e.jsx(s.SelectTrigger,{size:"xs",children:e.jsx(s.SelectValue,{})}),e.jsx(s.SelectContent,{children:s.INITIAL_VALUE_STRATEGY_OPTIONS.map(f=>e.jsx(s.SelectItem,{value:f.value,children:f.label},f.value))})]})]})]}),e.jsx(p.ControlVisibilitySettings,{control:t,onChange:f=>K(t.id,()=>f)})]})]})]})]},t.id)}),!r&&e.jsxs(s.Button,{type:"button",variant:"outline",size:"xs",onClick:Se,children:[e.jsx(p.Plus,{className:"h-3.5 w-3.5"}),"Add control"]})]})}function Re(l){const{open:a,onOpenChange:i,initialCreateFlowActive:d=!1,dismissMode:x="passive"}=l,u=a!==void 0,[h,y]=v.useState(!1),[g,j]=v.useState(d),b=u?a:h,m=v.useCallback(N=>{!N&&g&&x==="passive"||(u||y(N),N||j(!1),i==null||i(N))},[u,g,x,i]),C=v.useCallback(()=>{u||y(!1),j(!1),i==null||i(!1)},[u,i]);v.useEffect(()=>{b||j(!1)},[b]);const D=v.useCallback(N=>{g&&N.preventDefault()},[g]);return{forceClose:C,handleOpenChange:m,isCreateFlowActive:g,preventPassiveDismissDuringCreate:D,resolvedOpen:b,setIsCreateFlowActive:j}}exports.CircleX=Ne;exports.ControlDefinitionListEditor=ze;exports.EditorAcceptButton=Ie;exports.EditorCancelButton=_e;exports.EditorClearButton=Be;exports.Library=ge;exports.Link2=be;exports.Rows3=De;exports.SendHorizontal=Ee;exports.VisualBadge=Ve;exports.VisualSaveAndApplyButton=Fe;exports.VisualSaveButton=Le;exports.useCreateFlowOverlayState=Re;exports.useEffectiveEditorCardType=ae;exports.useSyncLegacyEditorState=we;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";const u=require("./index-
|
|
1
|
+
"use strict";const u=require("./index-BtqYNH_S.js"),f=require("./switch-fIkmwzUt.js"),S=require("react");function K(e){const[a,s]=S.useState(null),[r,t]=S.useState(null),o=u.useEnsureReactGlobals();return S.useEffect(()=>{if(!e||e.trim()===""){s(null),t(null);return}if(!o)return;(async()=>{try{if(!e.startsWith("http://")&&!e.startsWith("https://"))throw new Error(`Invalid URL format: ${e}`);try{new URL(e)}catch{throw new Error(`Invalid URL: ${e}`)}const i=`${e.endsWith("/")?e:`${e}/`}index.js`;try{if(!(await fetch(i,{method:"HEAD"})).ok)throw new Error(`Module not found at ${i}`)}catch{}const m=await import(i);if(typeof m.useChartStore!="function")throw new Error("useChartStore is not a function");s(()=>m.useChartStore),t(null)}catch(n){const i=n instanceof Error?n.message:"Unknown error";console.error("Failed to load remote chart store:",i),t(i),s(null)}})()},[e,o]),a}function X(e,a){if(e.length===0)return"";const s=e.find(r=>{var t,o;return((t=r.customCardPreferences)==null?void 0:t.visualType)==="multiple"||!!((o=r.customCardPreferences)!=null&&o.dataInputCardIds)});if(s)return s.id;if(a){const r=e.find(t=>t.id===a);if(r){const t=r.tabTitle;if(t=="All__Header")return e[0].id;if(t&&t.endsWith("__Header")){const l=t.split("__")[0],n=e.find(i=>i.tabTitle===l);return n?n.id:e[0].id}return a}}return e[0].id}const A=new Set;function Y(e){return A.add(e),()=>{A.delete(e)}}function z(){A.forEach(e=>{e()})}const Z=e=>{if(!e||!("detailTableBackup"in e))return e;const{detailTableBackup:a,...s}=e;return s};async function B(e,a,s,r){if(!a||!s)throw new Error("Missing auth token or visual ID");const t=["resource-by-id","visual",s],o=r.getQueryData(t);if(o)return console.log("Using cached visual data for:",s),{data:o,fromCache:!0};console.log("Fetching visual data from network for:",s);const l=u.ue.loading("Loading visual...",{position:"top-center"});try{const n=await fetch(`${e}/management/v1/visuals/${s}`,{headers:{Authorization:`Bearer ${a}`}});if(!n.ok)throw new Error("Failed to load visual");const i=await n.json();return r.setQueryData(t,i),u.ue.dismiss(l),{data:i,fromCache:!1}}catch(n){throw u.ue.dismiss(l),n}}function H(e){if(typeof e=="string")return JSON.parse(e);if(typeof e=="object")return e;throw new Error("Invalid frame object format")}function ee(e,a){var o,l;const s=(e==null?void 0:e.frameObject)??((o=e==null?void 0:e.visual)==null?void 0:o.frameObject);if(!s)return!1;const r=H(s);if(!(r!=null&&r.cards)||r.cards.length===0)return!1;const t=(l=r.cards)==null?void 0:l.find(n=>n.id===r.activeCardId);return t?(u.setupEditorWithCard({...a,frame:r,card:t,visualId:(e==null?void 0:e.id)||r.visualId}),!0):!1}function te(){const e=f.useEditorStore(r=>{var t;return((t=r.card.customCardPreferences)==null?void 0:t.url)||""}),a=K(e);return{getUpdatedFrame:S.useCallback(()=>{var b;z();const{frame:r,card:t,isDevMode:o,isShowingVisual:l,selectedSchemaName:n,selectedDatamodelId:i,selectedDatabaseName:m,selectedTableName:p,selectedConnectionId:y}=f.useEditorStore.getState(),I=t.sql,U=(b=a==null?void 0:a.getState())==null?void 0:b.settings,V=f.buildSavedEditorCard(t,{isDevMode:o,cardSql:I,isShowingVisual:l,selectedSchemaName:n,selectedDatamodelId:i,selectedDatabaseName:m,selectedTableName:p,selectedConnectionId:y,remoteChartSettings:U,stripConfig:Z}),g=r.cards.map(E=>E.id===t.id?V:E);return{...r,cards:g,activeCardId:X(g,r.activeCardId)}},[a])}}function re(){const{authToken:e,tokenProps:a}=u.useSemaphorContext(),s=u.useQueryClient(),r=u.useAddFrameWithFreshSemanticExecutionPayload(),t=u.useSelectedVisual(),{selectVisual:o}=u.useManagementActions(),{setFrame:l,setCard:n,setIsDevMode:i,initializeModeDrafts:m,setActiveTabCardId:p,updateDataSource:y,setQueryResultColumns:I,setSelectedConnectionId:U,setSelectedDatabaseName:V,setSelectedSchemaName:g,setSelectedTableName:b,setSelectedDatamodelId:E,setFilterValues:P,setInlineFilterValuesMap:M,setApplyFilters:k,clearEditorContext:L}=f.useEditorActions(),{setIsDashboardEditing:v,setIsVisualEditing:T,setSelectedFrameId:j,clearSelectedFrameId:N,setIsDashboardPanelOpen:R}=f.useDashboardActions(),w=f.useDashboardStore(c=>c.selectedSheetId),W=f.useDashboardStore(c=>c.selectedFrameId),$=f.useDashboardStore(c=>c.dashboard),_=f.useDashboardStore(c=>c.filterValues),x=f.useDashboardStore(c=>c.inlineFilterValuesMap),F=u.useVisualById((t==null?void 0:t.id)||"",{enabled:!!(t!=null&&t.id)&&!!(e!=null&&e.accessToken)}),Q=S.useCallback(async c=>{try{o(c),N(),L();const{data:h,fromCache:D}=await B(a.apiServiceUrl,(e==null?void 0:e.accessToken)||"",c.id,s);if(!ee(h,{setFrame:l,setCard:n,setIsDevMode:i,initializeModeDrafts:m,setActiveTabCardId:p,updateDataSource:y,setQueryResultColumns:I,setSelectedConnectionId:U,setSelectedDatabaseName:V,setSelectedSchemaName:g,setSelectedTableName:b,setSelectedDatamodelId:E,setFilterValues:P,setInlineFilterValuesMap:M,setApplyFilters:k,setIsDashboardEditing:v,setIsVisualEditing:T,dashboard:$,selectedSheetId:w,selectedFrameId:W,filterValues:_,inlineFilterValuesMap:x}))throw new Error("Failed to setup editor with visual data");return{success:!0,fromCache:D}}catch(h){return console.error("Error editing visual:",h),{success:!1,error:"Failed to load visual for editing"}}},[e==null?void 0:e.accessToken,a.apiServiceUrl,s,o,l,n,v,T,i,m,p,y,I,U,V,g,b,E,P,M,k,L,N,$,w,W,_,x]),G=S.useCallback(async c=>{var D;const h=d=>(u.ue.error(d),{success:!1,error:d});try{if(o(c),!w)return h("No sheet selected. Please select a sheet first.");const{data:d,fromCache:J}=await B(a.apiServiceUrl,(e==null?void 0:e.accessToken)||"",c.id,s),O=(d==null?void 0:d.frameObject)??((D=d==null?void 0:d.visual)==null?void 0:D.frameObject);if(!O)return h("Visual has no frame data");const C=H(O);if(!(C!=null&&C.cards)||C.cards.length===0)return h("Visual frame is malformed");const q={...u.cloneLinkedFrameWithSourceMapping(C),visualId:c.id};return await r(w,q,"end"),v(!0),j(q.id),R(!1),{success:!0,fromCache:J}}catch(d){return console.error("Error adding visual:",d),h(d instanceof Error?d.message:"Failed to add visual to dashboard")}},[e==null?void 0:e.accessToken,a.apiServiceUrl,s,o,w,v,j,R,r]);return{visual:F.data,isLoading:F.isLoading,isError:F.isError,error:F.error,handleEditLibraryVisual:Q,handleAddLibraryVisual:G,getUpdatedFrame:te().getUpdatedFrame,refetch:F.refetch}}exports.flushPendingEditorDrafts=z;exports.registerPendingEditorDraftFlusher=Y;exports.useVisualUtils=re;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { H as ne, E as ie, u as b, G as H, I as ce } from "./switch-
|
|
1
|
+
import { ac as X, u as Y, ad as Z, ae as ee, af as te, ag as re, ah as se, ai as ae, o as V, aj as oe } from "./index-CPyEi9gS.js";
|
|
2
|
+
import { H as ne, E as ie, u as b, G as H, I as ce } from "./switch-Dkx2qEOr.js";
|
|
3
3
|
import { useState as z, useEffect as de, useCallback as A } from "react";
|
|
4
4
|
function le(e) {
|
|
5
5
|
const [a, s] = z(null), [r, t] = z(null), o = X();
|
|
@@ -194,12 +194,12 @@ function be() {
|
|
|
194
194
|
setSelectedDatamodelId: g,
|
|
195
195
|
setFilterValues: P,
|
|
196
196
|
setInlineFilterValuesMap: j,
|
|
197
|
-
setApplyFilters:
|
|
198
|
-
clearEditorContext:
|
|
197
|
+
setApplyFilters: D,
|
|
198
|
+
clearEditorContext: L
|
|
199
199
|
} = ne(), {
|
|
200
200
|
setIsDashboardEditing: U,
|
|
201
|
-
setIsVisualEditing:
|
|
202
|
-
setSelectedFrameId:
|
|
201
|
+
setIsVisualEditing: T,
|
|
202
|
+
setSelectedFrameId: k,
|
|
203
203
|
clearSelectedFrameId: N,
|
|
204
204
|
setIsDashboardPanelOpen: W
|
|
205
205
|
} = ie(), E = b((c) => c.selectedSheetId), $ = b((c) => c.selectedFrameId), R = b((c) => c.dashboard), x = b((c) => c.filterValues), O = b(
|
|
@@ -209,7 +209,7 @@ function be() {
|
|
|
209
209
|
}), G = A(
|
|
210
210
|
async (c) => {
|
|
211
211
|
try {
|
|
212
|
-
o(c), N(),
|
|
212
|
+
o(c), N(), L();
|
|
213
213
|
const { data: u, fromCache: v } = await Q(
|
|
214
214
|
a.apiServiceUrl,
|
|
215
215
|
(e == null ? void 0 : e.accessToken) || "",
|
|
@@ -231,9 +231,9 @@ function be() {
|
|
|
231
231
|
setSelectedDatamodelId: g,
|
|
232
232
|
setFilterValues: P,
|
|
233
233
|
setInlineFilterValuesMap: j,
|
|
234
|
-
setApplyFilters:
|
|
234
|
+
setApplyFilters: D,
|
|
235
235
|
setIsDashboardEditing: U,
|
|
236
|
-
setIsVisualEditing:
|
|
236
|
+
setIsVisualEditing: T,
|
|
237
237
|
dashboard: R,
|
|
238
238
|
selectedSheetId: E,
|
|
239
239
|
selectedFrameId: $,
|
|
@@ -254,7 +254,7 @@ function be() {
|
|
|
254
254
|
l,
|
|
255
255
|
n,
|
|
256
256
|
U,
|
|
257
|
-
|
|
257
|
+
T,
|
|
258
258
|
i,
|
|
259
259
|
f,
|
|
260
260
|
h,
|
|
@@ -267,8 +267,8 @@ function be() {
|
|
|
267
267
|
g,
|
|
268
268
|
P,
|
|
269
269
|
j,
|
|
270
|
-
k,
|
|
271
270
|
D,
|
|
271
|
+
L,
|
|
272
272
|
N,
|
|
273
273
|
R,
|
|
274
274
|
E,
|
|
@@ -303,7 +303,7 @@ function be() {
|
|
|
303
303
|
E,
|
|
304
304
|
B,
|
|
305
305
|
"end"
|
|
306
|
-
), U(!0),
|
|
306
|
+
), U(!0), k(B.id), W(!1), { success: !0, fromCache: K };
|
|
307
307
|
} catch (d) {
|
|
308
308
|
return console.error("Error adding visual:", d), u(
|
|
309
309
|
d instanceof Error ? d.message : "Failed to add visual to dashboard"
|
|
@@ -317,7 +317,7 @@ function be() {
|
|
|
317
317
|
o,
|
|
318
318
|
E,
|
|
319
319
|
U,
|
|
320
|
-
|
|
320
|
+
k,
|
|
321
321
|
W,
|
|
322
322
|
r
|
|
323
323
|
]
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";const w=require("./validators-oc8qtP4q.js"),u=require("./source-identity-C-xaeE_I.js");function v(e){var t;const r=j(e);return{version:1,kind:"metric",id:e.id,label:e.label,source:S(e),metrics:r,primaryMetric:Q(e,r),dateField:e.dateField?a(e.dateField,"date"):void 0,timeGrain:e.timeGrain,dimensions:(t=e.dimensions)==null?void 0:t.map(o=>a(o,"dimension")),comparison:Z(e.comparison),orderBy:e.orderBy?{field:a(e.orderBy.field),direction:e.orderBy.direction}:void 0,inputs:p(e.inputs),limit:e.limit}}function M(e){var t;return{...v(e),...e.timeWindow?{timeWindow:e.timeWindow}:{},...(t=e.filters)!=null&&t.length?{filters:e.filters}:{},...e.analysis?{analysis:e.analysis}:{}}}function D(e){return{...e.chartTitle?{chartTitle:e.chartTitle}:{},...e.chartType?{chartType:e.chartType}:{},...e.driverMode?{driverMode:e.driverMode}:{},...e.includePopulation!==void 0?{includePopulation:e.includePopulation}:{},...e.calendarContext?{calendarContext:e.calendarContext}:{}}}function Q(e,r){if(!e.primaryMetric)return r[0]||{name:"",role:"measure"};const t=a(e.primaryMetric,"measure"),o=V(t,r),i=o.length===1?o[0]:void 0;return i?_(t,i):t}function j(e){const r=[];for(const t of e.metrics.map(o=>a(o,"measure"))){if(!t.name)continue;const o=r.findIndex(i=>K(i,t));if(o===-1){r.push(t);continue}r[o]=_(r[o],t)}return r}function K(e,r){return u.semaphorFieldRefsMatch(e,r)&&f(e)===f(r)}function E(e,r){return f(r)===f(e)}function N(e,r){return r.name!==e.name||e.source&&!u.semaphorFieldRefsMatch(r,e)?!1:E(e,r)}function V(e,r){const t=r.filter(o=>N(e,o));return e.aggregate!==void 0,t}function f(e){return(e.aggregate||"SUM").toUpperCase()}function _(e,r){if(e.aggregate&&r.aggregate&&e.aggregate!==r.aggregate)throw new Error(`Metric "${e.name}" was requested with conflicting aggregate semantics: ${e.aggregate} and ${r.aggregate}.`);return{...u.preferSemaphorFieldRefMetadata(e,r),aggregate:e.aggregate||r.aggregate}}function C(e){var t;if("sort"in e)throw new Error("semaphor.records supports orderBy for a single deterministic sort. Multiple sort clauses are not supported by the analytics protocol yet.");if(!Y(e))throw new Error("semaphor.records needs at least one field.");const r=W(e.fields);return{version:1,kind:"records",id:e.id,label:e.label,source:S(e),fields:r,dateField:e.dateField?a(e.dateField,"date"):void 0,timeGrain:e.timeGrain,...e.timeWindow?{timeWindow:e.timeWindow}:{},...(t=e.filters)!=null&&t.length?{filters:e.filters}:{},orderBy:e.orderBy?{field:a(e.orderBy.field),direction:e.orderBy.direction}:void 0,inputs:p(e.inputs),limit:e.limit,...e.pagination?{pagination:e.pagination}:{}}}function W(e){return e.map(r=>{const t=a(r);if(!t.role)throw new Error(`semaphor.records field "${t.name}" needs an explicit role.`);return t})}function R(e){return{version:1,kind:"inputOptions",id:e.id,label:e.label,source:S(e),field:a(e.field,"dimension"),search:e.search,limit:e.limit}}function $(e){var r;return{version:1,kind:"sql",id:e.id,label:e.label,source:e.source,sql:e.sql,...e.defaultParameters?{defaultParameters:e.defaultParameters}:{},...e.pythonCode?{pythonCode:e.pythonCode}:{},...(r=e.fields)!=null&&r.length?{fields:e.fields.map(t=>a(t))}:{},inputs:p(e.inputs),limit:e.limit,...e.pagination?{pagination:e.pagination}:{},rationale:e.rationale}}function T(e){if("toAnalyticsInput"in e){const n=e.toAnalyticsInput();return{inputId:n.inputId,kind:n.kind,...n.controlRole?{controlRole:n.controlRole}:{},...n.operator?{operator:n.operator}:{},...n.field?{field:n.field}:{}}}if("id"in e){const n=I(e);return{inputId:n.inputId,kind:n.kind,...n.controlRole?{controlRole:n.controlRole}:{},...n.operator?{operator:n.operator}:{},...n.field?{field:n.field}:{}}}const r="kind"in e?e.kind:void 0,t="operator"in e?F(e.operator,e.inputId):void 0,o="controlRole"in e?e.controlRole:"role"in e?e.role:void 0,i=U(o)?o:void 0;return{inputId:e.inputId,...r?{kind:r}:{},...i?{controlRole:i}:{},...t?{operator:t}:{},...e.field?{field:e.field}:{}}}function U(e){return e==="grain"||e==="metric"||e==="dimension"||e==="aggregation"||e==="sqlParam"}function G(e){const r=p(e);return r.length>0?r:void 0}function P(e){return(e||[]).map(X)}function L(e){return P(e).filter(r=>r.isActive)}function I(e){if(e.kind==="filter"){const r=F(e.operator,e.id);return{inputId:e.id,kind:e.kind,label:e.label,field:a(e.field,"dimension"),operator:r||"in"}}return{inputId:e.id,kind:e.kind,label:e.label,controlRole:e.role}}function J(e=[]){return e.map(r=>typeof r=="object"?r:{label:String(r),value:r})}function h(e){return e==null?!1:Array.isArray(e)?e.length>0:typeof e=="string"?e.trim().length>0:!0}function X(e){if("toAnalyticsInput"in e)return e.toAnalyticsInput();if("kind"in e&&"isActive"in e)return e;if("id"in e){const r=I(e),t=Object.prototype.hasOwnProperty.call(e,"value")?e.value:e.defaultValue;return{inputId:r.inputId,kind:r.kind,label:r.label,...r.field?{field:r.field}:{},...r.operator?{operator:r.operator}:{},...r.controlRole?{controlRole:r.controlRole}:{},value:t,isActive:h(t)}}return{...e,kind:"filter",isActive:h(e.value),value:e.value}}function S(e){return e.source}function Y(e){var r;return!!((r=e.fields)!=null&&r.length)}function a(e,r){return{...e,role:e.role||r}}function p(e){return(e||[]).map(T)}function Z(e){if(e)return e}function F(e,r){if(e===void 0)return;const t=w.normalizeSemaphorInputOperator(e);if(!t)throw new Error(`useSemaphorInput "${r}" uses unsupported filter operator "${e}".`);return t}function H(e,r={}){const t=r.pathPrefix||"analysisOptions";if(e===void 0)return{ok:!0};if(!e||typeof e!="object"||Array.isArray(e))return s(t,"Data App analysis options must be an object.");const o=e,i={};if(o.chartTitle!==void 0){if(typeof o.chartTitle!="string")return s(`${t}.chartTitle`,'Data App analysis option "chartTitle" must be a string.');i.chartTitle=o.chartTitle}if(o.chartType!==void 0){if(typeof o.chartType!="string")return s(`${t}.chartType`,'Data App analysis option "chartType" must be a string.');i.chartType=o.chartType}if(o.driverMode!==void 0){if(!te(o.driverMode))return s(`${t}.driverMode`,'Data App analysis option "driverMode" must be absolute_delta, largest_negative, largest_positive, positive_and_negative, or all.');i.driverMode=o.driverMode}if(o.includePopulation!==void 0){if(typeof o.includePopulation!="boolean")return s(`${t}.includePopulation`,'Data App analysis option "includePopulation" must be a boolean.');i.includePopulation=o.includePopulation}if(o.calendarContext!==void 0){const n=oe(o.calendarContext,{pathPrefix:`${t}.calendarContext`,validateTimezone:r.validateTimezone});if(!n.ok)return n;i.calendarContext=n.calendarContext}return{ok:!0,analysisOptions:i}}function ee(e){const r=e.queries.map((i,n)=>re(i,n,{fieldCatalogs:e.fieldCatalogs||[],requireFieldCatalog:!!e.requireFieldCatalog,validateTimezone:e.validateTimezone})),t=r.flatMap(i=>i.diagnostics),o=r.map(i=>i.executionResult);return{ok:t.every(i=>i.severity!=="error"),diagnostics:t,queries:r,intents:r.flatMap(i=>i.intent?[i.intent]:[]),executionResults:o}}function re(e,r,t){const o=`queries.${r}`;try{const i=ne(e),n=he(e,i),d=w.validateSemaphorAnalyticsIntent(i),l=[...ce({querySpec:e,queryId:n,intent:i,pathPrefix:o}),...d.errors.map(y=>q(y,{queryHook:e.queryHook,queryId:n,pathPrefix:o,severity:"error",intent:i})),...d.warnings.map(y=>q(y,{queryHook:e.queryHook,queryId:n,pathPrefix:o,severity:"warning",intent:i})),...se({querySpec:e,queryId:n,intent:i,pathPrefix:o,fieldCatalogs:t.fieldCatalogs,requireFieldCatalog:t.requireFieldCatalog}),...ue({querySpec:e,queryId:n,intent:i,pathPrefix:o,validateTimezone:t.validateTimezone})],c=ye(d,l);return{queryHook:e.queryHook,queryId:n,intent:i,diagnostics:l,executionResult:b({intent:i,validation:c,diagnostics:l})}}catch(i){const n={severity:"error",code:"invalid_query_spec",message:i instanceof Error?i.message:String(i),path:o,queryHook:e.queryHook,queryId:O(e.spec)},d=B([n]);return{queryHook:e.queryHook,queryId:n.queryId,diagnostics:[n],executionResult:b({validation:d,diagnostics:[n]})}}}function s(e,r){return{ok:!1,issues:[{code:"invalid_analysis_option",message:r,path:e}]}}function x(e){return!!(e&&typeof e=="object"&&!Array.isArray(e))}function te(e){return e==="absolute_delta"||e==="largest_negative"||e==="largest_positive"||e==="positive_and_negative"||e==="all"}function ie(e){return e.trim().length>0&&!Number.isNaN(Date.parse(e))}function oe(e,r){var c;if(!e||typeof e!="object"||Array.isArray(e))return s(r.pathPrefix,'Data App analysis option "calendarContext" must be an object.');const t=e,o=t.tz,i=t.weekStart,n=t.anchor,d=n&&typeof n=="object"&&!Array.isArray(n)?n.iso:void 0,l=typeof o=="string"?((c=r.validateTimezone)==null?void 0:c.call(r,o))??o:null;return l?typeof i!="number"||!Number.isInteger(i)||i<0||i>6?s(`${r.pathPrefix}.weekStart`,'Data App analysis option "calendarContext.weekStart" must be an integer from 0 to 6.'):n!=="now"&&!(typeof d=="string"&&ie(d))?s(`${r.pathPrefix}.anchor`,'Data App analysis option "calendarContext.anchor" must be "now" or an object with a valid iso string.'):{ok:!0,calendarContext:{tz:l,weekStart:i,anchor:n}}:s(`${r.pathPrefix}.tz`,'Data App analysis option "calendarContext.tz" must be a valid timezone string.')}function ne(e){return ae(e.spec)}function ae(e){if(!x(e))throw new Error("useSemaphorQuery spec must be an object.");if(e.queryKind==="metric")return v(e);if(e.queryKind==="analysis")return M(e);if(e.queryKind==="records")return C(e);if(e.queryKind==="sql")return $(e);if(e.queryKind==="inputOptions")return R(e);throw new Error("useSemaphorQuery spec.queryKind must be metric, analysis, records, inputOptions, or sql.")}function se(e){if(e.intent.kind==="sql")return[];if(e.fieldCatalogs.length===0&&!e.requireFieldCatalog)return[];const r=me(e.fieldCatalogs,e.intent.source);return r?[...de({...e,catalog:r}),...le({...e,catalog:r})]:[{severity:"error",code:"invalid_source_ref",message:`Source ref for ${e.querySpec.queryHook} does not match a visible Semaphor source.`,path:`${e.pathPrefix}.spec.source`,queryHook:e.querySpec.queryHook,queryId:e.queryId,intentId:e.intent.id,source:e.intent.source}]}function de(e){return fe(e.intent).flatMap(({field:r,path:t})=>z(e.catalog,r,e.intent.source)?[]:[{severity:"error",code:"missing_field",message:`Field "${r.name}" is not visible on the selected Semaphor source.`,path:`${e.pathPrefix}.${t}`,queryHook:e.querySpec.queryHook,queryId:e.queryId,intentId:e.intent.id,source:m(r,e.intent.source),field:r}])}function le(e){return("inputs"in e.intent?e.intent.inputs||[]:[]).flatMap((t,o)=>{if(!t.field)return[];const i=m(t.field,e.intent.source);return u.semaphorSourcesReferToSameDataset(i,e.intent.source)?z(e.catalog,t.field,e.intent.source)?[]:[{severity:"error",code:"missing_field",message:`Input "${t.inputId}" references field "${t.field.name}", which is not visible on the selected Semaphor source.`,path:`${e.pathPrefix}.spec.inputs.${o}.field`,queryHook:e.querySpec.queryHook,queryId:e.queryId,intentId:e.intent.id,source:i,field:t.field}]:[{severity:"error",code:"unsupported_input_filter_composition",message:`Input "${t.inputId}" filters a different Semaphor source than the query. Cross-source Data App inputs are not supported yet.`,path:`${e.pathPrefix}.spec.inputs.${o}.field`,queryHook:e.querySpec.queryHook,queryId:e.queryId,intentId:e.intent.id,source:i,field:t.field}]})}function ue(e){if(e.querySpec.spec.queryKind!=="analysis")return[];const r=H(e.querySpec.spec,{pathPrefix:`${e.pathPrefix}.spec`,validateTimezone:e.validateTimezone});return r.ok?[]:r.issues.map(t=>({severity:"error",code:t.code,message:t.message,path:t.path,queryHook:e.querySpec.queryHook,queryId:e.queryId,intentId:e.intent.id,source:e.intent.source}))}function ce(e){return e.querySpec.spec.queryKind!=="sql"?[]:x(e.querySpec.spec)?Object.prototype.hasOwnProperty.call(e.querySpec.spec,"parameters")?[{severity:"error",code:"deprecated_sql_parameters",message:"semaphor.sql uses defaultParameters for static SQL param(...) fallback values. The legacy parameters field is not supported.",path:`${e.pathPrefix}.spec.parameters`,queryHook:e.querySpec.queryHook,queryId:e.queryId,intentId:e.intent.id}]:[]:[]}function fe(e){return e.kind==="metric"?[...e.metrics.map((r,t)=>({field:r,path:`spec.metrics.${t}`})),...e.primaryMetric?[{field:e.primaryMetric,path:"spec.primaryMetric"}]:[],...e.dateField?[{field:e.dateField,path:"spec.dateField"}]:[],...(e.dimensions||[]).map((r,t)=>({field:r,path:`spec.dimensions.${t}`})),...e.orderBy?[{field:e.orderBy.field,path:"spec.orderBy.field"}]:[],...(e.filters||[]).map((r,t)=>({field:r.field,path:`spec.filters.${t}.field`}))]:e.kind==="records"?[...e.fields.map((r,t)=>({field:r,path:`spec.fields.${t}`})),...e.dateField?[{field:e.dateField,path:"spec.dateField"}]:[],...e.orderBy?[{field:e.orderBy.field,path:"spec.orderBy.field"}]:[],...(e.filters||[]).map((r,t)=>({field:r.field,path:`spec.filters.${t}.field`}))]:e.kind==="inputOptions"?[{field:e.field,path:"spec.field"}]:[]}function me(e,r){return e.find(t=>g(t,r))}function z(e,r,t){const o=m(r,t);if(g(e,o))return e.fields.find(i=>pe(i,r)&&g(e,m(i,e.source)))}function g(e,r){return[e.source,...e.sourceAliases||[]].some(t=>u.semaphorSourcesReferToSameDataset(t,r))}function m(e,r){return e.source||r}function pe(e,r){return!!(e.name&&r.name&&e.name===r.name)}function q(e,r){return{severity:r.severity,code:e.code||"invalid_analytics_intent",message:e.message,path:e.path?`${r.pathPrefix}.spec.${e.path}`:r.pathPrefix,queryHook:r.queryHook,queryId:r.queryId,intentId:r.intent.id,source:r.intent.source}}function ye(e,r){const t=B(r);return{ok:t.ok&&e.ok,errors:A([...e.errors,...t.errors]),warnings:A([...e.warnings,...t.warnings]),repairHints:[...e.repairHints,...t.repairHints]}}function B(e){const r=e.filter(o=>o.severity==="error").map(k),t=e.filter(o=>o.severity==="warning").map(k);return{ok:r.length===0,errors:r,warnings:t,repairHints:r.map(o=>{var i,n;return{code:o.code,message:o.message,fieldRole:o.fieldRole,invalidField:(i=o.repairHint)==null?void 0:i.invalidField,recommendedNextStep:((n=o.repairHint)==null?void 0:n.recommendedNextStep)||"Update the Data App SDK query spec to use visible Semaphor source and field refs."}})}}function k(e){var r;return{code:e.code,message:e.message,path:e.path,fieldRole:e.code==="invalid_source_ref"?"source":void 0,repairHint:{code:e.code,message:e.message,invalidField:(r=e.field)==null?void 0:r.name,fieldRole:e.code==="invalid_source_ref"?"source":void 0,recommendedNextStep:e.code==="unsupported_input_filter_composition"?"Use an input field from the same Semaphor source as the query, or split the query into separate source-scoped queries.":"Update the query spec to use a visible Semaphor source and field ref."}}}function A(e){const r=new Set;return e.filter(t=>{const o=`${t.code}:${t.path||""}:${t.message}`;return r.has(o)?!1:(r.add(o),!0)})}function b(e){var t,o;const r=e.diagnostics.filter(i=>i.severity==="error");return{intentId:(t=e.intent)==null?void 0:t.id,status:r.length?"failed":"answered",resultShape:(o=e.intent)==null?void 0:o.kind,intent:e.intent,validation:e.validation,coverage:{answeredObligations:r.length?[]:["query_spec_validation"],missingObligations:r.length?["query_spec_validation"]:[],warnings:e.validation.warnings},missingFields:r.filter(i=>i.code==="missing_field").flatMap(i=>{var n;return(n=i.field)!=null&&n.name?[i.field.name]:[]}),warnings:e.diagnostics.filter(i=>i.severity==="warning").map(i=>i.message),metadata:{validationKind:"data_app_sdk_query_spec"}}}function he(e,r){return r.id||O(e.spec)}function O(e){if(!e||typeof e!="object"||!("id"in e))return;const r=e.id;return typeof r=="string"&&r.trim()?r:void 0}exports.hasSemaphorInputValue=h;exports.normalizeSemaphorAnalysisQueryOptions=H;exports.normalizeSemaphorInputOptions=J;exports.toSemaphorActiveInputSnapshots=L;exports.toSemaphorAnalysisIntent=M;exports.toSemaphorAnalysisQueryOptions=D;exports.toSemaphorInputBinding=T;exports.toSemaphorInputBindings=G;exports.toSemaphorInputOptionsIntent=R;exports.toSemaphorInputSnapshots=P;exports.toSemaphorInputSpec=I;exports.toSemaphorMetricIntent=v;exports.toSemaphorRecordsIntent=C;exports.toSemaphorSqlIntent=$;exports.validateSemaphorDataAppQuerySpecs=ee;
|