react-semaphor 0.1.382 → 0.1.384
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/brand-studio/index.cjs +4 -4
- package/dist/brand-studio/index.js +27 -27
- package/dist/chunks/{braces-CP8BEzl3.js → braces--20GzUQh.js} +1 -1
- package/dist/chunks/{braces-CGi-YFZp.js → braces-C0Vh_Mft.js} +1 -1
- package/dist/chunks/{calendar-preferences-dialog-CV4xF2Tp.js → calendar-preferences-dialog-B-VsxhsA.js} +3 -3
- package/dist/chunks/calendar-preferences-dialog-DE67Z3oQ.js +1 -0
- package/dist/chunks/{dashboard-briefing-launcher-BT00MvGB.js → dashboard-briefing-launcher-BIj3X7b3.js} +107 -106
- package/dist/chunks/dashboard-briefing-launcher-Czx6BcXW.js +80 -0
- package/dist/chunks/dashboard-controls-BP-DcPFs.js +52 -0
- package/dist/chunks/{dashboard-controls-B6y7jkKO.js → dashboard-controls-BXxucM4f.js} +114 -113
- package/dist/chunks/dashboard-json-BNwshkK2.js +1 -0
- package/dist/chunks/{dashboard-json-CfIUG8k1.js → dashboard-json-C6oZuipD.js} +8 -8
- package/dist/chunks/edit-dashboard-visual-BAprin3J.js +178 -0
- package/dist/chunks/{edit-dashboard-visual-DMbf89xa.js → edit-dashboard-visual-CmfrI_L3.js} +1277 -1276
- package/dist/chunks/{index-CrKxP9uF.js → index-4W_ElSBJ.js} +219 -239
- package/dist/chunks/{index-BAsWLkZ8.js → index-icb12JV1.js} +879 -932
- package/dist/chunks/{layout-grid-jJQUqDN9.js → layout-grid-B7-klXiK.js} +1 -1
- package/dist/chunks/{layout-grid-BsKH3TgY.js → layout-grid-DV89AC9_.js} +1 -1
- package/dist/chunks/{palette-xU9Qt6bE.js → palette-5IwhMbSF.js} +1 -1
- package/dist/chunks/{palette-9zLPGlj2.js → palette-Dj-dgPYh.js} +1 -1
- package/dist/chunks/{save-DzciESDh.js → save-16C6YSW2.js} +1 -1
- package/dist/chunks/{save-8A_q6K4E.js → save-C5fwVdTF.js} +1 -1
- package/dist/chunks/search-0LmWwZzW.js +57 -0
- package/dist/chunks/search-Dq1Mbb03.js +21 -0
- package/dist/chunks/{switch-DArtNJZh.js → switch-DUdaHFZQ.js} +2332 -2419
- package/dist/chunks/{switch-k7kj6NRg.js → switch-bdJp0Bkw.js} +29 -54
- package/dist/chunks/use-create-flow-overlay-state-BIHKf_XK.js +21 -0
- package/dist/chunks/{use-create-flow-overlay-state-BdG1DiSx.js → use-create-flow-overlay-state-YvqCp6Zo.js} +74 -74
- package/dist/chunks/x-B_cx7LwM.js +26 -0
- package/dist/chunks/x-IdR_js6f.js +139 -0
- package/dist/dashboard/index.cjs +1 -1
- package/dist/dashboard/index.js +1 -1
- package/dist/data-app-builder/index.cjs +23 -23
- package/dist/data-app-builder/index.js +17 -15
- package/dist/data-app-sdk/index.cjs +68 -1
- package/dist/data-app-sdk/index.js +2876 -495
- 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/data-app-sdk.d.ts +148 -1
- package/package.json +1 -1
- package/dist/chunks/calendar-preferences-dialog-rDDobeLo.js +0 -1
- package/dist/chunks/dashboard-briefing-launcher-Dcbh-mjY.js +0 -80
- package/dist/chunks/dashboard-controls-CRqnPibB.js +0 -52
- package/dist/chunks/dashboard-json-DEQqRR1x.js +0 -1
- package/dist/chunks/edit-dashboard-visual-wDOcHak3.js +0 -178
- package/dist/chunks/index-BxM99sFL.js +0 -1
- package/dist/chunks/index-CuHybtft.js +0 -51
- package/dist/chunks/use-create-flow-overlay-state-ipeaE65_.js +0 -21
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";class o extends Error{}o.prototype.name="InvalidTokenError";function i(t){return decodeURIComponent(atob(t).replace(/(.)/g,(e,r)=>{let n=r.charCodeAt(0).toString(16).toUpperCase();return n.length<2&&(n="0"+n),"%"+n}))}function s(t){let e=t.replace(/-/g,"+").replace(/_/g,"/");switch(e.length%4){case 0:break;case 2:e+="==";break;case 3:e+="=";break;default:throw new Error("base64 string is not of the correct length")}try{return i(e)}catch{return atob(e)}}function d(t,e){if(typeof t!="string")throw new o("Invalid token specified: must be a string");e||(e={});const r=e.header===!0?0:1,n=t.split(".")[r];if(typeof n!="string")throw new o(`Invalid token specified: missing part #${r+1}`);let c;try{c=s(n)}catch(a){throw new o(`Invalid token specified: invalid base64 for part #${r+1} (${a.message})`)}try{return JSON.parse(c)}catch(a){throw new o(`Invalid token specified: invalid json for part #${r+1} (${a.message})`)}}exports.jwtDecode=d;
|
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
class o extends Error {
|
|
2
|
-
}
|
|
3
|
-
o.prototype.name = "InvalidTokenError";
|
|
4
|
-
function i(t) {
|
|
5
|
-
return decodeURIComponent(atob(t).replace(/(.)/g, (e, r) => {
|
|
6
|
-
let n = r.charCodeAt(0).toString(16).toUpperCase();
|
|
7
|
-
return n.length < 2 && (n = "0" + n), "%" + n;
|
|
8
|
-
}));
|
|
9
|
-
}
|
|
10
|
-
function s(t) {
|
|
11
|
-
let e = t.replace(/-/g, "+").replace(/_/g, "/");
|
|
12
|
-
switch (e.length % 4) {
|
|
13
|
-
case 0:
|
|
14
|
-
break;
|
|
15
|
-
case 2:
|
|
16
|
-
e += "==";
|
|
17
|
-
break;
|
|
18
|
-
case 3:
|
|
19
|
-
e += "=";
|
|
20
|
-
break;
|
|
21
|
-
default:
|
|
22
|
-
throw new Error("base64 string is not of the correct length");
|
|
23
|
-
}
|
|
24
|
-
try {
|
|
25
|
-
return i(e);
|
|
26
|
-
} catch {
|
|
27
|
-
return atob(e);
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
function d(t, e) {
|
|
31
|
-
if (typeof t != "string")
|
|
32
|
-
throw new o("Invalid token specified: must be a string");
|
|
33
|
-
e || (e = {});
|
|
34
|
-
const r = e.header === !0 ? 0 : 1, n = t.split(".")[r];
|
|
35
|
-
if (typeof n != "string")
|
|
36
|
-
throw new o(`Invalid token specified: missing part #${r + 1}`);
|
|
37
|
-
let c;
|
|
38
|
-
try {
|
|
39
|
-
c = s(n);
|
|
40
|
-
} catch (a) {
|
|
41
|
-
throw new o(`Invalid token specified: invalid base64 for part #${r + 1} (${a.message})`);
|
|
42
|
-
}
|
|
43
|
-
try {
|
|
44
|
-
return JSON.parse(c);
|
|
45
|
-
} catch (a) {
|
|
46
|
-
throw new o(`Invalid token specified: invalid json for part #${r + 1} (${a.message})`);
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
export {
|
|
50
|
-
d as j
|
|
51
|
-
};
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
"use strict";const s=require("./switch-k7kj6NRg.js"),C=require("react"),m=require("./index-CrKxP9uF.js"),e=require("react/jsx-runtime");require("./index-BxM99sFL.js");require("./analyze-result-contract-CtXfp3nv.js");const Se=require("./save-8A_q6K4E.js");/**
|
|
2
|
-
* @license lucide-react v0.453.0 - ISC
|
|
3
|
-
*
|
|
4
|
-
* This source code is licensed under the ISC license.
|
|
5
|
-
* See the LICENSE file in the root directory of this source tree.
|
|
6
|
-
*/const je=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"}]]);/**
|
|
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 ke=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"}]]);/**
|
|
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 Fe=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"}]]);/**
|
|
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 Ie=s.createLucideIcon("SendHorizontal",[["path",{d:"M3.714 3.048a.498.498 0 0 0-.683.627l2.843 7.627a2 2 0 0 1 0 1.396l-2.842 7.627a.498.498 0 0 0 .682.627l18-8.5a.5.5 0 0 0 0-.904z",key:"117uat"}],["path",{d:"M6 12h16",key:"s4cdu5"}]]);function Ve(r){const[a,o]=C.useState(null),[n,i]=C.useState(null),c=m.useEnsureReactGlobals();return C.useEffect(()=>{if(!r||r.trim()===""){o(null),i(null);return}if(!c)return;(async()=>{try{if(!r.startsWith("http://")&&!r.startsWith("https://"))throw new Error(`Invalid URL format: ${r}`);try{new URL(r)}catch{throw new Error(`Invalid URL: ${r}`)}const p=`${r.endsWith("/")?r:`${r}/`}index.js`;try{if(!(await fetch(p,{method:"HEAD"})).ok)throw new Error(`Module not found at ${p}`)}catch{}const v=await import(p);if(typeof v.useChartStore!="function")throw new Error("useChartStore is not a function");o(()=>v.useChartStore),i(null)}catch(h){const p=h instanceof Error?h.message:"Unknown error";console.error("Failed to load remote chart store:",p),i(p),o(null)}})()},[r,c]),a}function Te(r,a){if(r.length===0)return"";const o=r.find(n=>{var i,c;return((i=n.customCardPreferences)==null?void 0:i.visualType)==="multiple"||!!((c=n.customCardPreferences)!=null&&c.dataInputCardIds)});if(o)return o.id;if(a){const n=r.find(i=>i.id===a);if(n){const i=n.tabTitle;if(i=="All__Header")return r[0].id;if(i&&i.endsWith("__Header")){const f=i.split("__")[0],h=r.find(p=>p.tabTitle===f);return h?h.id:r[0].id}return a}}return r[0].id}const ce=new Set;function Le(r){return ce.add(r),()=>{ce.delete(r)}}function Ne(){ce.forEach(r=>{r()})}const Ae=r=>{if(!r||!("detailTableBackup"in r))return r;const{detailTableBackup:a,...o}=r;return o};async function be(r,a,o,n,i="Opening library visual..."){if(!a||!o)throw new Error("Missing auth token or visual ID");const c=["resource-by-id","visual",o],f=n.getQueryData(c);if(f)return console.log("Using cached visual data for:",o),{data:f,fromCache:!0};console.log("Fetching visual data from network for:",o);const h=m.ue.loading(i,{position:"top-center"});try{const p=await fetch(`${r}/management/v1/visuals/${o}`,{headers:{Authorization:`Bearer ${a}`}});if(!p.ok)throw new Error("Failed to load visual");const v=await p.json();return n.setQueryData(c,v),m.ue.dismiss(h),{data:v,fromCache:!1}}catch(p){throw m.ue.dismiss(h),p}}function Ee(r){if(typeof r=="string")return JSON.parse(r);if(typeof r=="object")return r;throw new Error("Invalid frame object format")}function _e(r,a){var c,f;const o=(r==null?void 0:r.frameObject)??((c=r==null?void 0:r.visual)==null?void 0:c.frameObject);if(!o)return!1;const n=Ee(o);if(!(n!=null&&n.cards)||n.cards.length===0)return!1;const i=(f=n.cards)==null?void 0:f.find(h=>h.id===n.activeCardId);return i?(m.setupEditorWithCard({...a,frame:n,card:i,visualId:(r==null?void 0:r.id)||n.visualId}),!0):!1}function Be(){const r=s.useEditorStore(n=>{var i;return((i=n.card.customCardPreferences)==null?void 0:i.url)||""}),a=Ve(r);return{getUpdatedFrame:C.useCallback(()=>{var V;Ne();const{frame:n,card:i,isDevMode:c,isShowingVisual:f,selectedSchemaName:h,selectedDatamodelId:p,selectedDatabaseName:v,selectedTableName:g,selectedConnectionId:x}=s.useEditorStore.getState(),S=i.sql,w=(V=a==null?void 0:a.getState())==null?void 0:V.settings,k=s.buildSavedEditorCard(i,{isDevMode:c,cardSql:S,isShowingVisual:f,selectedSchemaName:h,selectedDatamodelId:p,selectedDatabaseName:v,selectedTableName:g,selectedConnectionId:x,remoteChartSettings:w,stripConfig:Ae}),E=n.cards.map(U=>U.id===i.id?k:U);return{...n,cards:E,activeCardId:Te(E,n.activeCardId)}},[a])}}function se(){const{authToken:r,tokenProps:a}=m.useSemaphorContext(),o=m.useQueryClient(),n=m.useAddFrameWithFreshSemanticExecutionPayload(),i=m.useSelectedVisual(),{selectVisual:c}=m.useManagementActions(),{setFrame:f,setCard:h,setIsDevMode:p,initializeModeDrafts:v,setActiveTabCardId:g,updateDataSource:x,setQueryResultColumns:S,setSelectedConnectionId:w,setSelectedDatabaseName:k,setSelectedSchemaName:E,setSelectedTableName:V,setSelectedDatamodelId:U,setFilterValues:H,setInlineFilterValuesMap:W,setApplyFilters:Y,clearEditorContext:J}=s.useEditorActions(),{setIsDashboardEditing:M,setIsVisualEditing:l,setSelectedFrameId:D,clearSelectedFrameId:T}=s.useDashboardActions(),q=s.useDashboardStore(A=>A.selectedSheetId),Q=s.useDashboardStore(A=>A.selectedFrameId),K=s.useDashboardStore(A=>A.dashboard),G=s.useDashboardStore(A=>A.filterValues),_=s.useDashboardStore(A=>A.inlineFilterValuesMap),z=m.useVisualById((i==null?void 0:i.id)||"",{enabled:!!(i!=null&&i.id)&&!!(r!=null&&r.accessToken)}),$=C.useCallback(async A=>{try{c(A),T(),J();const{data:F,fromCache:P}=await be(a.apiServiceUrl,(r==null?void 0:r.accessToken)||"",A.id,o,"Opening library visual...");if(!_e(F,{setFrame:f,setCard:h,setIsDevMode:p,initializeModeDrafts:v,setActiveTabCardId:g,updateDataSource:x,setQueryResultColumns:S,setSelectedConnectionId:w,setSelectedDatabaseName:k,setSelectedSchemaName:E,setSelectedTableName:V,setSelectedDatamodelId:U,setFilterValues:H,setInlineFilterValuesMap:W,setApplyFilters:Y,setIsDashboardEditing:M,setIsVisualEditing:l,dashboard:K,selectedSheetId:q,selectedFrameId:Q,filterValues:G,inlineFilterValuesMap:_}))throw new Error("Failed to setup editor with visual data");return{success:!0,fromCache:P}}catch(F){return console.error("Error editing visual:",F),{success:!1,error:"Failed to load visual for editing"}}},[r==null?void 0:r.accessToken,a.apiServiceUrl,o,c,f,h,M,l,p,v,g,x,S,w,k,E,V,U,H,W,Y,J,T,K,q,Q,G,_]),ae=C.useCallback(async A=>{var P;const F=B=>(m.ue.error(B),{success:!1,error:B});try{if(c(A),!q)return F("No sheet selected. Please select a sheet first.");const{data:B,fromCache:ne}=await be(a.apiServiceUrl,(r==null?void 0:r.accessToken)||"",A.id,o,"Adding visual to dashboard..."),te=(B==null?void 0:B.frameObject)??((P=B==null?void 0:B.visual)==null?void 0:P.frameObject);if(!te)return F("Visual has no frame data");const R=Ee(te);if(!(R!=null&&R.cards)||R.cards.length===0)return F("Visual frame is malformed");const ee={...m.cloneLinkedFrameWithSourceMapping(R),visualId:A.id};return await n(q,ee,"end"),M(!0),D(ee.id),{success:!0,fromCache:ne}}catch(B){return console.error("Error adding visual:",B),F(B instanceof Error?B.message:"Failed to add visual to dashboard")}},[r==null?void 0:r.accessToken,a.apiServiceUrl,o,c,q,M,D,n]);return{visual:z.data,isLoading:z.isLoading,isError:z.isError,error:z.error,handleEditLibraryVisual:$,handleAddLibraryVisual:ae,getUpdatedFrame:Be().getUpdatedFrame,refetch:z.refetch}}function Me(){const r=s.useEditorStore(f=>f.card.dataSource),{setSelectedConnectionId:a,setSelectedDatabaseName:o,setSelectedSchemaName:n,setSelectedTableName:i,setSelectedDatamodelId:c}=s.useEditorActions();C.useEffect(()=>{var w;if(!r)return;const{tableName:f,schemaName:h,databaseName:p,connectionId:v}=m.extractTableMetadata(r),g=(w=r.selectedEntities)==null?void 0:w[0],S=(g==null?void 0:g.type)==="model"&&"id"in g?g.id:"";a(v||""),o(p||""),n(h||""),i(f||""),c(S)},[r,a,o,n,i,c])}function ue(){var p,v;const r=s.useEditorStore(g=>g.card),a=s.useEditorStore(g=>g.frame),o=C.useMemo(()=>m.findCustomVisualConfigCard(a,r),[a,r]),{manifest:n}=m.useCustomVisual(((p=o==null?void 0:o.customCardPreferences)==null?void 0:p.url)||""),i=C.useMemo(()=>{var g;return(g=n==null?void 0:n.visuals)==null?void 0:g.find(x=>{var S;return x.name===((S=o==null?void 0:o.customCardPreferences)==null?void 0:S.componentName)})},[n,(v=o==null?void 0:o.customCardPreferences)==null?void 0:v.componentName]),c=m.resolveMultiInputType(o,i),f=C.useMemo(()=>m.getCustomVisualInputCards({frame:a,configCard:o,isMultiInputVisual:c==="multiple"}),[a,o,c]),h=C.useMemo(()=>{const g=f.findIndex(x=>(x==null?void 0:x.id)===r.id);return g<0?-1:m.getSlotIndexForCard(r,g)},[f,r]);return C.useMemo(()=>!o||c!=="multiple"||h<0?r.type:m.getEffectiveCardTypeForSlot(r,h,i==null?void 0:i.slots)??r.type,[o,c,h,r,i==null?void 0:i.slots])}function qe({type:r,isLinked:a,className:o,showLabel:n=!1,showLocal:i=!1}){const c=s.useDashboardStore(E=>E.selectedFrameId),f=m.useManagementStore(E=>E.selectedVisual),h=s.useEditorStore(E=>E.frame);let p;if(r)p=r;else if(a!==void 0)p=a?"linked":"library";else if(!!!(h!=null&&h.visualId||f!=null&&f.id)&&c)p="local";else if(f&&!c)p="library";else if(h!=null&&h.visualId&&c)p="linked";else if(f!=null&&f.id&&c)p="library";else return null;if(p==="local"&&!i)return null;const v={local:"border-slate-200/70 bg-slate-50/80 text-slate-700 shadow-sm hover:bg-slate-100/80 dark:border-slate-700 dark:bg-slate-900/70 dark:text-slate-200 dark:hover:bg-slate-800/80",linked:"border-purple-200/70 bg-gradient-to-r from-purple-50/50 to-purple-100/30 text-purple-900 shadow-sm hover:from-purple-100/60 hover:to-purple-100/50 hover:shadow-md dark:border-purple-800/50 dark:from-purple-950/40 dark:to-purple-900/30 dark:text-purple-100 dark:hover:from-purple-950/60 dark:hover:to-purple-900/50",library:"border-blue-200/70 bg-gradient-to-r from-blue-50/50 to-blue-100/30 text-blue-900 shadow-sm hover:from-blue-100/60 hover:to-blue-100/50 hover:shadow-md dark:border-blue-800/50 dark:from-blue-950/40 dark:to-blue-900/30 dark:text-blue-100 dark:hover:from-blue-950/60 dark:hover:to-blue-900/50"},g={local:"Local to this dashboard: Changes made here only affect this dashboard copy.",linked:"Linked to library: Changes made here update the library visual and all linked instances.",library:"Library visual: Share and reuse this visual across multiple dashboards."},x={local:"border-slate-200 bg-slate-50 text-slate-900 dark:border-slate-700 dark:bg-slate-900 dark:text-slate-100",linked:"border-purple-200 bg-purple-50 text-purple-900 dark:border-purple-800 dark:bg-purple-950 dark:text-purple-100",library:"border-blue-200 bg-blue-50 text-blue-900 dark:border-blue-800 dark:bg-blue-950 dark:text-blue-100"},S={local:"fill-slate-50 dark:fill-slate-900",linked:"fill-purple-50 dark:fill-purple-950",library:"fill-blue-50 dark:fill-blue-950"},w={local:e.jsx("span",{className:"h-2 w-2 rounded-full bg-current/70"}),linked:e.jsx(ke,{className:"h-3.5 w-3.5"}),library:e.jsx(je,{className:"h-3.5 w-3.5"})},k={local:"Local",linked:"Linked",library:"Library"};return e.jsx(s.TooltipProvider,{children:e.jsxs(s.Tooltip,{delayDuration:300,children:[e.jsx(s.TooltipTrigger,{asChild:!0,children:e.jsxs(m.Badge,{variant:"outline",className:s.cn("cursor-help select-none transition-all",v[p],o),children:[w[p],n&&e.jsx("span",{className:"ml-1 text-xs font-medium leading-none",children:k[p]})]})}),e.jsxs(s.TooltipContent,{side:"bottom",className:s.cn("max-w-xs",x[p]),children:[e.jsx(s.TooltipArrow,{className:S[p]}),e.jsx("p",{children:g[p]})]})]})})}function Oe(r,a){return{...r,sql:"",python:"",config:void 0,customCfg:"",preferences:{},interactionConfig:void 0,linkedInteractionTargetOverrides:void 0,dynamicCardPreferences:void 0,customCardPreferences:a?r.customCardPreferences:void 0,visualizationMode:"builtin",type:a?r.type:"bar"}}function pe(r){const a=s.getDynamicFrameSaveIssue(r);return a?(m.ue.error(a),!1):!0}function Ue({className:r,variant:a="outline"}){const o=s.useEditorStore(c=>c.onSave),{getUpdatedFrame:n}=se();function i(){const c=n();pe(c)&&(o==null||o(c))}return e.jsxs(s.Button,{onClick:i,className:r,size:"xs",variant:a,children:[e.jsx(s.Check,{className:"h-3.5 w-3.5"}),"Accept"]})}function ze({className:r,variant:a="default"}){const o=m.useQueryClient(),[n,i]=C.useState(!1),{setIsVisualEditing:c}=s.useDashboardActions(),{getUpdatedFrame:f}=se(),h=m.useSelectedVisual(),p=s.useEditorStore(x=>x.frame),v=m.useUpdateVisualMutation(),g=()=>{const x=f();if(!pe(x))return;const S=(p==null?void 0:p.visualId)||(h==null?void 0:h.id);if(!S){m.ue.error("No visual to save");return}i(!0),v.mutate({visualId:S,data:{frameObject:x}},{onSuccess:()=>{i(!1),m.ue.success("Visual updated successfully"),o.invalidateQueries({queryKey:["resource-by-id","visual",S],exact:!0})},onError:()=>{i(!1),m.ue.error("Failed to update visual")}})};return e.jsx(s.Button,{onClick:g,className:r,size:"xs",variant:a,children:n?e.jsxs(e.Fragment,{children:[e.jsx(s.LoaderCircle,{className:"h-3.5 w-3.5 animate-spin"}),"Saving"]}):e.jsxs(e.Fragment,{children:[e.jsx(Se.Save,{className:"h-3.5 w-3.5"}),"Save to Library"]})})}function Re({className:r}){const a=m.useQueryClient(),[o,n]=C.useState(!1),i=m.useSelectedVisual(),c=s.useEditorStore(k=>k.frame),f=s.useDashboardStore(k=>k.selectedSheetId),h=s.useDashboardStore(k=>k.dashboard),{updateFrame:p,setIsVisualEditing:v}=s.useDashboardActions(),{getUpdatedFrame:g}=se(),x=m.useUpdateVisualMutation(),S=m.useResolveExistingFrameSemanticExecutionPayload(),w=async()=>{if(!f){m.ue.error("No sheet selected");return}const k=(c==null?void 0:c.visualId)||(i==null?void 0:i.id);if(!k){m.ue.error("No visual to update");return}n(!0);try{const E=g();if(!pe(E)){n(!1);return}const V={...E,visualId:k},U=m.findDashboardFrameById(h,V.id),H=await S(V,{previousFrame:U});await x.mutateAsync({visualId:k,data:{frameObject:E}}),p(f,V,{semanticExecutionPayload:H}),a.invalidateQueries({queryKey:["visuals"]}),a.invalidateQueries({queryKey:["visual",k]}),m.ue.success("Saved to library and applied locally"),setTimeout(()=>{v(!1)},300)}catch(E){console.error("Failed to save and apply:",E),m.ue.error(E instanceof Error?E.message:"Failed to save and apply changes")}finally{n(!1)}};return e.jsx(s.Button,{onClick:w,className:r,size:"xs",variant:"default",disabled:o,children:o?e.jsxs(e.Fragment,{children:[e.jsx(s.LoaderCircle,{className:"h-3.5 w-3.5 animate-spin"}),"Saving..."]}):e.jsxs(e.Fragment,{children:[e.jsx(Se.Save,{className:"h-3.5 w-3.5"}),"Save & Apply"]})})}function Qe({className:r}){const{setTempQueryData:a,setSqlGen:o}=s.useEditorActions(),n=m.useQueryClient(),i=s.useEditorStore(x=>x.tempQueryData),c=s.useEditorStore(x=>x.onClose),f=s.useEditorStore(x=>x.card),h=ue(),p=C.useMemo(()=>h!==f.type?{...f,type:h}:f,[f,h]),{queryKey:v}=m.useEditorCardQuery(p);function g(){if(i){const{queryKey:x,queryData:S}=i;x&&S&&n.setQueryData(x,S)}o({}),c==null||c()}return e.jsxs(s.Button,{onClick:g,className:r,size:"xs",variant:"outline",children:[e.jsx(s.X,{className:"h-3.5 w-3.5"}),"Close"]})}function Pe({label:r="Clear",variant:a="secondary",className:o}={}){const{setTempQueryData:n}=s.useEditorActions(),i=m.useQueryClient(),c=s.useEditorStore(M=>M.tempQueryData),f=s.useEditorStore(M=>M.card),h=ue(),p=C.useMemo(()=>h!==f.type?{...f,type:h}:f,[f,h]),{queryKey:v}=m.useEditorCardQuery(p),{setCardSql:g,setSqlGen:x,setCardPython:S,setCardCustomCfg:w,setCardPreferences:k,clearQueryConfig:E,setCardConfig:V,setCardType:U,setFrame:H,setCard:W,setActiveTabCardId:Y}=s.useEditorActions();function J(){var K,G,_,z;const M=i.getQueryData(v);c!=null&&c.queryData||n({queryKey:v,queryData:M}),i.setQueryData(v,null),i.removeQueries({queryKey:v,exact:!0}),g(""),x({}),E(),V(void 0),S(""),w(""),k({});const l=s.useEditorStore.getState().frame,D=s.useEditorStore.getState().card,T=m.findCustomVisualConfigCard(l,D),q=((K=T==null?void 0:T.customCardPreferences)==null?void 0:K.visualType)==="multiple"||!!((G=T==null?void 0:T.customCardPreferences)!=null&&G.dataInputCardIds)||(((_=T==null?void 0:T.customCardPreferences)==null?void 0:_.minInputs)||0)>1||(((z=T==null?void 0:T.customCardPreferences)==null?void 0:z.maxInputs)||0)>1,Q=Oe(D,q);H({...l,cards:l.cards.map($=>$.id===Q.id?Q:$)}),Y(Q.id),W(Q),q||U("bar")}return e.jsxs(s.Button,{onClick:J,className:o,size:"xs",variant:a,children:[e.jsx(s.X,{className:"h-3.5 w-3.5"}),r]})}function we(r){const{control:a,onChange:o}=r;return e.jsxs("div",{className:"flex flex-col gap-1.5",children:[e.jsx(s.Label,{className:"text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground",children:"Label"}),e.jsx(s.Input,{size:"xs",value:a.label,placeholder:"Control label",onChange:n=>o(n.target.value)})]})}function $e(r){const{currentStep:a,labels:o}=r;return e.jsx("div",{className:"sticky top-0 z-10 -mx-1 border-b border-border/60 bg-background/95 px-1 pb-2.5 pt-1 backdrop-blur supports-[backdrop-filter]:bg-background/85",children:e.jsx("div",{className:"flex flex-wrap items-center gap-2 sm:gap-2.5",children:o.map((n,i)=>{const c=i+1,f=c===a,h=c<a;return e.jsxs(C.Fragment,{children:[e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("span",{className:s.cn("flex h-5 w-5 items-center justify-center rounded-full border text-[10px] font-medium tabular-nums",f?"border-foreground bg-foreground text-background":h?"border-foreground/30 bg-foreground/10 text-foreground":"border-border/60 bg-background text-muted-foreground"),children:c}),e.jsx("span",{className:s.cn("text-[12px]",f?"font-medium text-foreground":"text-muted-foreground"),children:n})]}),i<o.length-1?e.jsx("span",{className:"h-px w-4 bg-border/60 sm:w-6","aria-hidden":"true"}):null]},n)})})})}function re(r){const{secondary:a,tertiary:o,primary:n}=r;return e.jsxs("div",{className:"sticky bottom-0 z-10 -mx-1 flex justify-end gap-2 border-t bg-background/95 px-1 pb-1 pt-3 backdrop-blur supports-[backdrop-filter]:bg-background/85",children:[a,o,n]})}function He(r){const{control:a,scope:o,detail:n}=r;return e.jsxs("div",{className:"flex items-start gap-2.5 rounded-control border border-border/60 bg-muted/30 px-3 py-2.5",children:[e.jsx(m.CircleCheck,{className:"mt-0.5 h-3.5 w-3.5 shrink-0 text-foreground"}),e.jsxs("div",{className:"min-w-0 space-y-0.5",children:[e.jsx("div",{className:"text-[13px] font-medium text-foreground",children:a.label}),e.jsxs("div",{className:"text-[12px] text-muted-foreground",children:[s.getFriendlyTypeOption(a.type).label," ·"," ",s.getControlOptionPreview(a)," ·"," ",s.getPlacementLabel(o,a.placement)]}),n?e.jsx("div",{className:"text-[12px] text-muted-foreground",children:n}):null]})]})}function ye(r){const{control:a,defaultValue:o,availableFieldChoices:n,availableMetricChoices:i,previewControlDefinitions:c,previewControlValues:f,onControlChange:h,onLabelChange:p,onDefaultValueChange:v,onBack:g,onNext:x,nextDisabled:S}=r;return e.jsxs("div",{className:"space-y-3",children:[e.jsx(we,{control:a,onChange:p}),e.jsx(m.ControlDefinitionOptionsEditor,{control:a,availableFieldChoices:n,availableMetricChoices:i,previewControlDefinitions:c,previewControlValues:f,controlLifecycle:"create",onChange:h}),e.jsx(m.ControlDefaultValueEditor,{control:a,value:o,onChange:v,allowNoDefault:!0,allowCardDefault:!0,hint:"This is the value viewers will see first.",previewControlDefinitions:c,previewControlValues:f}),e.jsx(re,{secondary:e.jsx(s.Button,{type:"button",variant:"outline",size:"xs",onClick:g,children:"Back"}),primary:e.jsx(s.Button,{type:"button",size:"xs",onClick:x,disabled:S,children:"Next"})})]})}const Ye=new Set(["grain_selector","aggregation_selector","field_selector","metric_selector"]);function ve(r){const{text:a,ariaLabel:o}=r,[n,i]=C.useState(!1);return e.jsxs("button",{type:"button","aria-label":o,onClick:async()=>{try{await navigator.clipboard.writeText(a),i(!0),setTimeout(()=>i(!1),1200)}catch(c){console.error("Failed to copy",c)}},className:"group flex w-full items-center justify-between gap-2 rounded-control bg-muted/40 px-2 py-1 text-left transition-colors hover:bg-muted/60 focus-visible:bg-muted/60 focus-visible:outline-none",children:[e.jsx("code",{className:"min-w-0 truncate font-mono text-[12px] text-foreground",children:a}),e.jsx("span",{className:"shrink-0 text-[11px] text-muted-foreground opacity-0 transition-opacity group-hover:opacity-100",children:n?"Copied":"Click to copy"})]})}function Ce(r){const{control:a,scope:o,createdReference:n,explorerContent:i,sqlDescription:c,summaryDetail:f,onBack:h,onCancel:p,onDone:v}=r,g=Ye.has(a.type),x=n.match(/\[\[param\.(.+?)\]\]/),S=x?`{{ param('${x[1]}') }}`:"";return e.jsxs("div",{className:"space-y-4",children:[e.jsx(He,{control:a,scope:o,detail:f}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("p",{className:"text-[13px] font-medium text-foreground",children:"How cards use this control"}),e.jsxs("div",{className:"divide-y divide-border/60 overflow-hidden rounded-control border border-border/60",children:[g?e.jsxs("div",{className:"space-y-1 px-3 py-2.5",children:[e.jsx("p",{className:"text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground",children:"Explorer cards"}),e.jsx("div",{className:"text-[12px] text-muted-foreground",children:i})]}):null,e.jsxs("div",{className:"space-y-1.5 px-3 py-2.5",children:[e.jsx("p",{className:"text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground",children:"SQL cards"}),e.jsx(ve,{text:n,ariaLabel:"Copy SQL control reference"}),S?e.jsx(ve,{text:S,ariaLabel:"Copy Jinja control reference"}):null,e.jsxs("p",{className:"text-[12px] text-muted-foreground",children:[c," ",e.jsx("a",{href:"https://docs.semaphor.cloud/docs/concepts/template-expressions",target:"_blank",rel:"noreferrer",className:"underline underline-offset-2 hover:text-foreground",children:"Template expressions docs"}),"."]})]})]})]}),e.jsx(re,{secondary:e.jsx(s.Button,{type:"button",variant:"outline",size:"xs",onClick:h,children:"Back"}),tertiary:e.jsx(s.Button,{type:"button",variant:"outline",size:"xs",onClick:p,children:"Cancel"}),primary:e.jsx(s.Button,{type:"button",size:"xs",onClick:v,children:"Done"})})]})}function Ke(r){const a=s.createBlankControl(r.scope,r.existingControls,r.reservedIds),o=r.type===a.type?{...a,label:s.DEFAULT_LABEL_BY_TYPE[r.type]}:{...s.applyControlTypeChange({controls:[{...a,label:s.DEFAULT_LABEL_BY_TYPE[r.type]}],controlId:a.id,nextType:r.type}).controls[0],label:s.DEFAULT_LABEL_BY_TYPE[r.type]};return{step:2,control:o,defaultValue:s.getDefaultValueForType(o,void 0)}}function We({scope:r,controls:a,reservedControlIds:o,defaultValues:n,onChange:i,emptyMessage:c,initialCreateFlow:f=!1,usageByControlId:h,availableFieldChoices:p,availableMetricChoices:v,structuralParticipants:g,structuralParticipantIdsByControlId:x,card:S,allowedControlTypes:w,onCreateFlowActiveChange:k,onCreateFlowComplete:E}){const V=C.useMemo(()=>new Set(o||[]),[o]),U=s.getPlacementOptionsForScope(r),H=s.getDefaultPlacement(r),[W,Y]=C.useState(null),[J,M]=C.useState(null),[l,D]=C.useState(()=>f?{step:1,control:s.createBlankControl(r,a,Array.from(V))}:null),T=C.useRef({}),q=C.useRef(void 0),Q=C.useRef(f),K=C.useMemo(()=>{const t=s.getFriendlyControlTypeOptions({scope:r,card:S});if(!w)return t;const u=new Set(w);return t.filter(d=>u.has(d.value))},[w,S,r]),G=C.useCallback(t=>{const u=s.getFriendlyControlTypeOptions({scope:r,card:S,includeType:w?void 0:t});if(!w)return u;const d=new Set(w);return u.filter(b=>d.has(b.value))},[w,S,r]),_=C.useCallback(t=>r==="dashboard"&&(t==="field_selector"||t==="metric_selector"),[r]),z=C.useMemo(()=>l?s.getEligibleParticipantsForStructuralControl(g||[],l.control.type):[],[l,g]),$=C.useMemo(()=>{if(!l)return{fields:p||[],metrics:v||[]};if(!_(l.control.type))return{fields:p||[],metrics:v||[]};const t=l.selectedCardIds||[],u=s.getCompatibleStructuralChoiceCatalog({controlType:l.control.type,participants:g||[],selectedCardIds:t});return{fields:l.control.type==="field_selector"?u.choices.map(d=>({option:d,target:u.fieldTargetMap[d.value]})):[],metrics:l.control.type==="metric_selector"?u.choices.map(d=>({option:d,target:u.metricTargetMap[d.value]})):[]}},[p,v,l,_,g]);C.useEffect(()=>{k==null||k(!!l)},[l,k]),C.useEffect(()=>{const t=f&&!Q.current;Q.current=f,t&&(D({step:1,control:s.createBlankControl(r,a,Array.from(V))}),M(null),Y(null))},[a,f,V,r]);const ae=t=>{if(!_(t.type))return{fields:p||[],metrics:v||[]};const u=(x==null?void 0:x[t.id])||[];if(u.length===0)return{fields:p||[],metrics:v||[]};const d=s.getCompatibleStructuralChoiceCatalog({controlType:t.type,participants:g||[],selectedCardIds:u});return{fields:t.type==="field_selector"?d.choices.map(b=>({option:b,target:d.fieldTargetMap[b.value]})):[],metrics:t.type==="metric_selector"?d.choices.map(b=>({option:b,target:d.metricTargetMap[b.value]})):[]}},A=t=>{if(!_(t.control.type))return{nextControl:t.control,cardBindingsById:void 0};const u=(x==null?void 0:x[t.control.id])||[],d=s.getCompatibleStructuralChoiceCatalog({controlType:t.control.type,participants:g||[],selectedCardIds:t.nextSelectedCardIds}),b=s.reconcileStructuralControlChoices({control:t.control,choices:d.choices}),j=Object.fromEntries(u.filter(N=>!t.nextSelectedCardIds.includes(N)).map(N=>[N,void 0]));return t.nextSelectedCardIds.length>0&&b.source.kind==="manual"&&b.source.options.length>0&&Object.assign(j,s.buildStructuralControlBindingsForParticipants({control:b,participants:g||[],selectedCardIds:t.nextSelectedCardIds})),{nextControl:b,cardBindingsById:j}},F=C.useCallback((t,u=n,d={type:"update"})=>{const b=t.map(j=>(s.resolveAuthoringControlDefaultValue({control:j,defaultValues:u}),s.syncSqlQueryControlExecutionRequirement(j)));i(b,u,d)},[n,i]),P=(t,u)=>{const d=a.find(L=>L.id===t);let b=a.map(L=>L.id!==t?L:u(L));const j=b.find(L=>L.id===t);let N,y;if(j&&r==="dashboard"&&(j.type==="field_selector"||j.type==="metric_selector")){const L=(x==null?void 0:x[j.id])||[],Z=A({control:j,nextSelectedCardIds:L});b=b.map(X=>X.id===t?Z.nextControl:X),N=Z.cardBindingsById,y=[j.id]}else if(d&&r==="dashboard"&&(d.type==="field_selector"||d.type==="metric_selector")){const L=(x==null?void 0:x[d.id])||[];N=Object.fromEntries(L.map(Z=>[Z,void 0])),y=[d.id]}const I=b.find(L=>L.id===t);let O=n;if(d&&I){const L=s.resolveAuthoringControlDefaultValue({control:d,defaultValues:n});d.source.kind==="manual"&&I.source.kind==="sql_query"&&(T.current[t]=L);const Z=L===void 0&&d.source.kind==="sql_query"&&I.source.kind==="manual"?T.current[t]:L,X=s.getNextEditedControlDefaultValue({previousControl:d,nextControl:I,currentDefaultValue:Z});I.source.kind==="manual"&&(T.current[t]=X),n&&(O={...n},X===void 0?delete O[t]:O[t]=X),b=b.map(ge=>ge.id===t?{...I,defaultValue:X}:ge)}F(b,O,{type:"update",cardBindingsById:N,affectedBindingControlIds:y})},B=(t,u)=>{if(!u.trim())return;const d=m.normalizeDashboardInputVariableName(u);if(d===t||V.has(d)||a.some(N=>N.id===d&&N.id!==t))return;const b=a.map(N=>N.id===t?{...N,id:d}:N);if(!n){F(b,void 0,{type:"rename",oldId:t,newId:d});return}const j={...n};Object.prototype.hasOwnProperty.call(j,t)&&(j[d]=j[t],delete j[t]),F(b,j,{type:"rename",oldId:t,newId:d})},ne=t=>{const u=a.filter(b=>b.id!==t);if(!n){F(u,void 0,{type:"remove",controlId:t});return}const d={...n};delete d[t],F(u,d,{type:"remove",controlId:t})},te=C.useCallback(()=>{q.current=void 0,D({step:1,control:s.createBlankControl(r,a,Array.from(V))}),M(null),Y(null)},[a,V,r]),R=t=>{D(u=>u&&(()=>{const d=t(u.control);u.control.source.kind==="manual"&&d.source.kind==="sql_query"&&(q.current=u.defaultValue);const b=u.defaultValue===void 0&&u.control.source.kind==="sql_query"&&d.source.kind==="manual"?q.current:u.defaultValue,j=s.getNextEditedControlDefaultValue({previousControl:u.control,nextControl:d,currentDefaultValue:b});return d.source.kind==="manual"&&(q.current=j),{...u,control:d,defaultValue:j}})())},ee=t=>{D(u=>u&&(u.control.source.kind==="manual"&&(q.current=t),{...u,defaultValue:t}))},oe=(()=>{if(!l)return!1;if(l.step===2&&_(l.control.type))return(l.selectedCardIds||[]).length>0;if(l.step!==2&&l.step!==3||!l.control.label.trim())return!1;const u=l.control.source.kind==="sql_query"?l.control:s.ensureManualSource(l.control);if(u.source.kind==="manual"&&(s.needsManualOptions(u)&&u.source.options.length===0||u.source.options.some(b=>b.label.trim().length===0||b.value.trim().length===0)))return!1;if(u.source.kind==="sql_query"){const{connectionId:d,sql:b,valueColumn:j}=u.source;return d.trim().length>0&&b.trim().length>0&&j.trim().length>0}return s.hasConcreteDefaultValue(s.getDefaultValueForType(u,l.defaultValue))})(),me=()=>{var N;if(!l)return;const t=s.ensureManualSource(l.control),u=s.deriveUniqueControlId({label:t.label,fallbackId:t.id,existingControls:a,reservedIds:Array.from(V)}),d={...t,id:u},b=r==="dashboard"&&(d.type==="field_selector"||d.type==="metric_selector")&&((N=l.selectedCardIds)!=null&&N.length)?s.buildStructuralControlBindingsForParticipants({control:d,participants:g||[],selectedCardIds:l.selectedCardIds}):void 0,j=s.getDefaultValueForType(d,l.defaultValue);D({step:r==="dashboard"&&(d.type==="field_selector"||d.type==="metric_selector")?4:3,control:d,defaultValue:j,createdControlId:u,selectedCardIds:l.selectedCardIds,cardBindingsById:b})},le=C.useCallback(()=>{D(null)},[]),fe=C.useCallback(()=>{if(!(l!=null&&l.createdControlId)){D(null);return}const t=l.control,u=l.createdControlId,d=s.getDefaultValueForType(t,l.defaultValue);if(n){const b={...n};d===void 0?delete b[u]:b[u]=d,F([...a,{...t,defaultValue:d}],b,{type:"add",cardBindingsById:l.cardBindingsById})}else F([...a,{...t,defaultValue:d}],void 0,{type:"add",cardBindingsById:l.cardBindingsById});M(u),D(null),E==null||E()},[a,l,n,F,E]),De=l?_(l.control.type)?["Choose type","Select cards","Configure","Finish"]:["Choose type","Configure","Finish"]:[],he=l!=null&&l.createdControlId?`[[param.${l.createdControlId}]]`:l?`[[param.${s.slugifyControlValue(l.control.label)||l.control.id}]]`:"",ie=s.buildAuthoringPreviewControlValues({controls:a,defaultValues:n}),de=l?[...a,l.control]:a,xe=l?s.buildAuthoringPreviewControlValues({controls:de,defaultValues:n,overrides:[{controlId:l.control.id,value:l.defaultValue}]}):ie;return e.jsxs("div",{className:"space-y-4",children:[l?e.jsxs("div",{className:"space-y-4 pb-1",children:[e.jsx($e,{currentStep:l.step,labels:De}),l.step===1&&(()=>{const t=new Set(["grain_selector","aggregation_selector","field_selector","metric_selector"]),u=new Set(["date","text"]),d=K.filter(N=>!t.has(N.value)&&!u.has(N.value)),b=K.filter(N=>t.has(N.value)),j=N=>e.jsxs("button",{type:"button",className:"rounded-control border border-border/60 bg-background px-3 py-2.5 text-left transition-colors hover:bg-muted/40 focus-visible:bg-muted/40 focus-visible:outline-none",onClick:()=>D(Ke({scope:r,existingControls:a,reservedIds:Array.from(V),type:N.value})),children:[e.jsx("div",{className:"text-[13px] font-medium text-foreground",children:N.label}),e.jsx("p",{className:"mt-0.5 text-[12px] text-muted-foreground",children:N.description})]},N.value);return e.jsxs("div",{className:"space-y-4",children:[r==="card"&&(S==null?void 0:S.sql)==null?e.jsx("p",{className:"text-[12px] text-muted-foreground",children:"Explorer cards support displayed metric, group by field, aggregation, and time grain controls here."}):null,d.length>0&&e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("p",{className:"text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground",children:"Input controls"}),e.jsx("div",{className:"grid gap-1.5 sm:grid-cols-2",children:d.map(j)})]}),b.length>0&&e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("p",{className:"text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground",children:"Data-driven controls"}),e.jsx("div",{className:"grid gap-1.5 sm:grid-cols-2",children:b.map(j)})]}),e.jsx(re,{secondary:e.jsx(s.Button,{type:"button",variant:"outline",size:"xs",onClick:le,children:"Back to controls"})})]})})(),l.step===2&&_(l.control.type)&&e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"space-y-3",children:[e.jsx(we,{control:l.control,onChange:t=>R(u=>({...u,label:t}))}),e.jsx("p",{className:"text-[12px] text-muted-foreground",children:"Choose which cards should respond to this shared control."})]}),z.length===0?e.jsx("div",{className:"rounded-control border border-border/60 bg-muted/30 px-3 py-2.5 text-[12px] text-muted-foreground",children:"No eligible cards are available yet. Add compatible metrics or group-by fields to cards first."}):e.jsx("div",{className:"space-y-1 rounded-control border border-border/60 bg-background p-2",children:z.map(t=>{const u=(l.selectedCardIds||[]).includes(t.cardId);return e.jsxs("label",{className:"flex items-start gap-2 rounded-control px-1.5 py-1 text-[13px] hover:bg-muted/40",children:[e.jsx(m.Checkbox,{checked:u,onCheckedChange:d=>D(b=>b&&{...b,selectedCardIds:d===!0?[...b.selectedCardIds||[],t.cardId]:(b.selectedCardIds||[]).filter(j=>j!==t.cardId)})}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"font-medium text-foreground",children:t.title}),e.jsx("div",{className:"text-[12px] text-muted-foreground",children:l.control.type==="field_selector"?`${t.fieldChoices.length} compatible group-by fields`:`${t.metricChoices.length} compatible metrics`})]})]},t.cardId)})}),e.jsx(re,{secondary:e.jsx(s.Button,{type:"button",variant:"outline",size:"xs",onClick:()=>D(t=>t&&{...t,step:1,selectedCardIds:[]}),children:"Back"}),primary:e.jsx(s.Button,{type:"button",size:"xs",onClick:()=>D(t=>t&&{...t,step:3}),disabled:!oe,children:"Next"})})]}),l.step===2&&!_(l.control.type)&&e.jsx(ye,{control:l.control,defaultValue:l.defaultValue,availableFieldChoices:$.fields,availableMetricChoices:$.metrics,previewControlDefinitions:de,previewControlValues:xe,onControlChange:t=>R(()=>t),onLabelChange:t=>R(u=>({...u,label:t})),onDefaultValueChange:ee,onBack:()=>D(t=>t&&{...t,step:1}),onNext:me,nextDisabled:!oe}),l.step===3&&_(l.control.type)&&e.jsx(ye,{control:l.control,defaultValue:l.defaultValue,availableFieldChoices:$.fields,availableMetricChoices:$.metrics,previewControlDefinitions:de,previewControlValues:xe,onControlChange:t=>R(()=>t),onLabelChange:t=>R(u=>({...u,label:t})),onDefaultValueChange:ee,onBack:()=>D(t=>t&&{...t,step:2}),onNext:me,nextDisabled:!oe}),l.step===3&&!_(l.control.type)&&e.jsx(Ce,{control:l.control,scope:r,createdReference:he,explorerContent:e.jsxs(e.Fragment,{children:["Open the card and use"," ",e.jsx("span",{className:"font-medium text-foreground",children:"Settings → Controls"})," ","to choose what this control changes."]}),sqlDescription:"Reference this control directly in the SQL editor.",onBack:()=>D(t=>t&&{...t,step:2}),onCancel:le,onDone:fe}),l.step===4&&_(l.control.type)&&e.jsx(Ce,{control:l.control,scope:r,createdReference:he,summaryDetail:e.jsxs(e.Fragment,{children:["Used by ",(l.selectedCardIds||[]).length," selected card",(l.selectedCardIds||[]).length===1?"":"s"]}),explorerContent:e.jsx(e.Fragment,{children:"Selected cards have been set up to respond to this control automatically."}),sqlDescription:"SQL cards can still reference this control directly in the SQL editor.",onBack:()=>D(t=>t&&{...t,step:3}),onCancel:le,onDone:fe})]}):null,!l&&a.length===0?e.jsx("div",{className:"rounded-md border border-dashed p-3 text-sm text-muted-foreground",children:c}):null,!l&&a.map(t=>{const u=ae(t),d=h==null?void 0:h[t.id],b=s.resolveAuthoringControlDefaultValue({control:t,defaultValues:n}),j=J===t.id,N="inline-flex shrink-0 items-center rounded-[4px] border border-border/60 bg-muted/40 px-1.5 py-0.5 text-[11px] font-medium text-muted-foreground";return e.jsxs("div",{className:"rounded-control border border-border/60",children:[e.jsxs("div",{className:"flex items-center gap-2 px-3 py-2.5",children:[e.jsxs("button",{type:"button",className:"flex min-w-0 flex-1 items-start gap-2 rounded-control text-left focus:outline-none focus-visible:bg-muted/40",onClick:()=>M(y=>y===t.id?null:t.id),children:[j?e.jsx(s.ChevronDown,{className:"mt-0.5 h-3.5 w-3.5 shrink-0 text-muted-foreground"}):e.jsx(m.ChevronRight,{className:"mt-0.5 h-3.5 w-3.5 shrink-0 text-muted-foreground"}),e.jsxs("div",{className:"min-w-0",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-1.5",children:[e.jsx("span",{className:"truncate text-[13px] font-medium text-foreground",children:t.label||"Untitled control"}),e.jsx("span",{className:N,children:s.getFriendlyTypeOption(t.type).label}),e.jsx("span",{className:N,children:s.getPlacementLabel(r,t.placement)})]}),e.jsxs("div",{className:"mt-0.5 text-[12px] text-muted-foreground",children:[s.getControlOptionPreview(t),d!=null&&d.status?` · ${d.status}`:""]})]})]}),e.jsx(s.Button,{type:"button",size:"xs",variant:"ghost",className:"h-7 w-7 shrink-0 p-0 text-muted-foreground",onClick:()=>ne(t.id),"aria-label":`Remove ${t.label}`,children:e.jsx(m.Trash2,{className:"h-3.5 w-3.5"})})]}),j&&e.jsxs("div",{className:"space-y-4 border-t border-border/60 px-3 py-3",children:[e.jsxs("div",{className:"grid gap-3 md:grid-cols-3",children:[e.jsxs("div",{className:"flex flex-col gap-1.5",children:[e.jsx(s.Label,{className:"text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground",children:"Label"}),e.jsx(s.Input,{size:"xs",value:t.label,placeholder:"Control label",onChange:y=>P(t.id,I=>({...I,label:y.target.value}))})]}),e.jsxs("div",{className:"flex flex-col gap-1.5",children:[e.jsx(s.Label,{className:"text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground",children:"Type"}),e.jsxs(s.Select,{value:t.type,onValueChange:y=>{const I=s.applyControlTypeChange({controls:a,controlId:t.id,nextType:y,defaultValues:n});F(I.controls,I.defaultValues)},children:[e.jsx(s.SelectTrigger,{size:"xs",children:e.jsx(s.SelectValue,{})}),e.jsx(s.SelectContent,{children:G(t.type).map(y=>e.jsx(s.SelectItem,{value:y.value,children:y.label},y.value))})]})]}),e.jsxs("div",{className:"flex flex-col gap-1.5",children:[e.jsx(s.Label,{className:"text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground",children:"Show in"}),e.jsxs(s.Select,{value:t.placement||H,onValueChange:y=>P(t.id,I=>({...I,placement:y})),children:[e.jsx(s.SelectTrigger,{size:"xs",children:e.jsx(s.SelectValue,{})}),e.jsx(s.SelectContent,{children:U.map(y=>e.jsx(s.SelectItem,{value:y.value,children:y.label},y.value))})]})]})]}),_(t.type)?e.jsx(m.StructuralParticipantSelector,{type:t.type,participants:s.getEligibleParticipantsForStructuralControl(g||[],t.type).map(y=>({cardId:y.cardId,title:y.title,choiceCount:t.type==="field_selector"?y.fieldChoices.length:y.metricChoices.length})),selectedCardIds:(x==null?void 0:x[t.id])||[],onChange:y=>{const I=A({control:t,nextSelectedCardIds:y}),O=a.map(L=>L.id===t.id?I.nextControl:L);F(O,n,{type:"update",cardBindingsById:I.cardBindingsById})}}):null,e.jsx(m.ControlDefinitionOptionsEditor,{control:t,availableFieldChoices:u.fields,availableMetricChoices:u.metrics,previewControlDefinitions:a,previewControlValues:ie,controlLifecycle:"edit",onChange:y=>P(t.id,()=>y)}),t.initialValueStrategy==="saved_default"&&e.jsx(m.ControlDefaultValueEditor,{control:t,value:b,allowNoDefault:!0,allowCardDefault:!0,previewControlDefinitions:a,previewControlValues:ie,onChange:y=>{const I=a.map(O=>O.id===t.id?{...O,defaultValue:y}:O);if(t.source.kind==="manual"&&(T.current[t.id]=y),n){const O={...n};y===void 0?delete O[t.id]:O[t.id]=y,F(I,O);return}F(I,void 0)}}),e.jsxs(m.Collapsible,{open:W===t.id,onOpenChange:y=>Y(y?t.id:null),children:[e.jsx(m.CollapsibleTrigger,{asChild:!0,children:e.jsxs(s.Button,{type:"button",variant:"ghost",size:"xs",className:"-ml-2 gap-1 text-muted-foreground hover:text-foreground",children:[W===t.id?e.jsx(s.ChevronDown,{className:"h-3.5 w-3.5"}):e.jsx(m.ChevronRight,{className:"h-3.5 w-3.5"}),"Advanced"]})}),e.jsxs(m.CollapsibleContent,{className:"space-y-3 pt-2",children:[e.jsxs("div",{className:"grid gap-3 md:grid-cols-2",children:[e.jsxs("div",{className:"flex flex-col gap-1.5",children:[e.jsx(s.Label,{className:"text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground",children:"Variable name"}),e.jsx(m.ControlIdInput,{controlId:t.id,onCommit:y=>B(t.id,y)},t.id)]}),e.jsxs("div",{className:"flex flex-col gap-1.5",children:[e.jsx(s.Label,{className:"text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground",children:"Initial value"}),e.jsxs(s.Select,{value:t.initialValueStrategy,onValueChange:y=>P(t.id,I=>({...I,initialValueStrategy:y})),children:[e.jsx(s.SelectTrigger,{size:"xs",children:e.jsx(s.SelectValue,{})}),e.jsx(s.SelectContent,{children:s.INITIAL_VALUE_STRATEGY_OPTIONS.map(y=>e.jsx(s.SelectItem,{value:y.value,children:y.label},y.value))})]})]})]}),e.jsx(m.ControlVisibilitySettings,{control:t,onChange:y=>P(t.id,()=>y)})]})]})]})]},t.id)}),!l&&e.jsxs(s.Button,{type:"button",variant:"outline",size:"xs",onClick:te,children:[e.jsx(m.Plus,{className:"h-3.5 w-3.5"}),"Add control"]})]})}function Ge(r){const{open:a,onOpenChange:o,initialCreateFlowActive:n=!1,dismissMode:i="passive"}=r,c=a!==void 0,[f,h]=C.useState(!1),[p,v]=C.useState(n),g=c?a:f,x=C.useCallback(k=>{!k&&p&&i==="passive"||(c||h(k),k||v(!1),o==null||o(k))},[c,p,i,o]),S=C.useCallback(()=>{c||h(!1),v(!1),o==null||o(!1)},[c,o]);C.useEffect(()=>{g||v(!1)},[g]);const w=C.useCallback(k=>{p&&k.preventDefault()},[p]);return{forceClose:S,handleOpenChange:x,isCreateFlowActive:p,preventPassiveDismissDuringCreate:w,resolvedOpen:g,setIsCreateFlowActive:v}}exports.ControlDefinitionListEditor=We;exports.EditorAcceptButton=Ue;exports.EditorCancelButton=Qe;exports.EditorClearButton=Pe;exports.Library=je;exports.Link2=ke;exports.Rows3=Fe;exports.SendHorizontal=Ie;exports.VisualBadge=qe;exports.VisualSaveAndApplyButton=Re;exports.VisualSaveButton=ze;exports.flushPendingEditorDrafts=Ne;exports.registerPendingEditorDraftFlusher=Le;exports.useCreateFlowOverlayState=Ge;exports.useEffectiveEditorCardType=ue;exports.useSyncLegacyEditorState=Me;exports.useVisualUtils=se;
|