react-semaphor 0.0.3931 → 0.0.3932
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/chunks/{index-Cy2kCpij.js → index-BEZAy8Jv.js} +25 -25
- package/dist/chunks/{index-CRljNFAF.js → index-CanpZidr.js} +13732 -13732
- package/dist/dashboard/index.cjs +1 -1
- package/dist/dashboard/index.js +1 -1
- package/dist/index.cjs +2 -2
- package/dist/index.js +3 -3
- package/package.json +1 -1
package/dist/dashboard/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("../chunks/index-
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("../chunks/index-BEZAy8Jv.js");exports.Dashboard=e.Dashboard;
|
package/dist/dashboard/index.js
CHANGED
package/dist/index.cjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const s=require("./chunks/index-
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const s=require("./chunks/index-BEZAy8Jv.js"),e=require("react/jsx-runtime"),C=require("react");require("react-dom");function gs(t){const n=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(t){for(const a in t)if(a!=="default"){const r=Object.getOwnPropertyDescriptor(t,a);Object.defineProperty(n,a,r.get?r:{enumerable:!0,get:()=>t[a]})}}return n.default=t,Object.freeze(n)}const de=gs(C);/**
|
|
2
2
|
* @license lucide-react v0.453.0 - ISC
|
|
3
3
|
*
|
|
4
4
|
* This source code is licensed under the ISC license.
|
|
@@ -254,4 +254,4 @@
|
|
|
254
254
|
${y}
|
|
255
255
|
|
|
256
256
|
`;_(I)}function X(){return e.jsxs(e.Fragment,{children:[i&&e.jsx("div",{className:"relative flex w-1/3 min-w-0 grow overflow-hidden text-xs",role:"editor-filter-container",children:e.jsx("div",{className:"mt-2 w-[99%]",children:e.jsx(yt,{jsonString:JSON.stringify(b,null,2)})})}),b&&b.length>0&&e.jsx(s.Button,{variant:"ghost",onClick:()=>c(!i),className:"absolute bottom-0 right-6 size-7 p-1",children:i?e.jsx(s.X,{className:"size-3.5 text-muted-foreground"}):e.jsx(s.Filter,{className:"size-3.5 text-muted-foreground"})})]})}function le(){return e.jsxs(s.ResizablePanelGroup,{className:"flex grow pb-1",direction:"vertical",role:"editor-resizable-group",children:[e.jsxs(s.ResizablePanel,{id:"1",order:1,defaultSize:r?20:100,className:"relative flex grow",children:[e.jsx("div",{id:"sql-container",className:"relative flex w-[99%]",children:e.jsx(jt,{})}),r&&e.jsx("code",{className:"absolute right-6 top-3 text-xs text-muted-foreground/70",children:"sql"})]}),r&&e.jsxs(e.Fragment,{children:[e.jsx(s.ResizableHandle,{withHandle:!0,className:"border"}),e.jsxs(s.ResizablePanel,{id:"2",order:2,defaultSize:80,className:"relative flex grow",children:[e.jsx("div",{id:"python-container",className:"relative flex w-[99%] pt-0",children:e.jsx(bt,{})}),e.jsx("code",{className:"absolute right-6 top-3 text-xs text-muted-foreground/70",children:"python"})]})]})]})}const ne=(L==null?void 0:L.message)||((re=M==null?void 0:M.error)==null?void 0:re.message);return e.jsxs("section",{role:"editor-section",className:"flex grow flex-col justify-end",children:[e.jsxs("div",{className:"relative flex grow justify-between overflow-y-scroll",children:[le(),X()]}),e.jsxs("div",{role:"editor-controls",className:"item-center flex flex-wrap justify-between gap-2 px-6 py-4",children:[e.jsxs("div",{className:"flex grow items-center gap-2",children:[e.jsxs(s.Button,{title:"Shift + Enter",disabled:G||J,onClick:()=>{W()},className:"shrink-0",size:"sm",children:[G||J?e.jsx(pe,{className:"mr-2 h-4 w-4 animate-spin"}):e.jsx(s.Play,{className:"mr-2 h-4 w-4"}),"Run"]}),e.jsx(ct,{sql:M==null?void 0:M.sql,error:ne,onClick:U}),e.jsxs(s.Button,{onClick:H,className:"",size:"sm",variant:"secondary",children:[e.jsx(Es,{className:"mr-2 size-4"}),"Clear"]}),e.jsx(s.Toggle,{pressed:r,onPressedChange:I=>o(I),className:"",size:"sm",children:e.jsx(gt,{className:"size-4 text-foreground/70"})}),e.jsx("button",{disabled:g,onClick:()=>{k(),m(!0)},className:"h-9 w-full cursor-text px-3 text-left text-sm text-muted-foreground",children:g?"":"Type your question..."})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs(s.Button,{onClick:se,className:"w-full",size:"sm",variant:"secondary",children:[e.jsx(s.Cross2Icon,{className:"mr-2 size-4"}),"Close"]}),e.jsxs(s.Button,{onClick:Y,size:"sm",variant:"secondary",children:[e.jsx(s.Check,{className:"mr-2 size-4 font-bold text-green-600"}),"Accept"]})]})]})]})}function Ct({data:t}){var c;const[n,a]=C.useState([]),o=Object.keys(t[0]).map(l=>({accessorKey:l,header:({column:d})=>{const x=d.getIsSorted();return e.jsx("div",{className:"flex gap-2",children:e.jsxs("div",{className:"flex cursor-pointer items-center",onClick:()=>d.toggleSorting(d.getIsSorted()==="asc"),children:[l,x==="asc"?e.jsx(s.TriangleUpIcon,{className:"ml-2 h-5 w-5"}):x==="desc"?e.jsx(s.TriangleDownIcon,{className:"ml-2 h-5 w-5"}):null]})})}})),i=s.useReactTable({data:t,columns:o,getCoreRowModel:s.getCoreRowModel(),getPaginationRowModel:s.getPaginationRowModel(),onSortingChange:a,getSortedRowModel:s.getSortedRowModel(),manualPagination:!0,state:{sorting:n}});return e.jsx("div",{className:"font-mono text-xs text-foreground/95",children:e.jsxs("table",{className:"w-full",children:[e.jsx(s.TableHeader,{children:i.getHeaderGroups().map(l=>e.jsx(s.TableRow,{children:l.headers.map(d=>e.jsx(s.TableHead,{className:"sticky top-0 h-11 bg-muted font-semibold",children:d.isPlaceholder?null:s.flexRender(d.column.columnDef.header,d.getContext())},d.id))},l.id))}),e.jsx(s.TableBody,{children:(c=i.getRowModel().rows)!=null&&c.length?i.getRowModel().rows.map(l=>e.jsx(s.TableRow,{className:"whitespace-nowrap py-2","data-state":l.getIsSelected()&&"selected",children:l.getVisibleCells().map(d=>e.jsx(s.TableCell,{className:"py-3",children:s.flexRender(d.column.columnDef.cell,d.getContext())},d.id))},l.id)):e.jsx(s.TableRow,{children:e.jsx(s.TableCell,{colSpan:o.length,className:"h-24 text-center",children:"No results."})})})]})})}function vt({card:t}){var E,v,D,T,z,q,V,_,m,A,B;const[n,a]=C.useState(!1),[r,o]=C.useState([]),{authToken:i}=s.useSemaphorContext(),c=s.getTokenParams(i==null?void 0:i.accessToken),l=s.useDashboardStore(O=>O.themeStyle),d={colors:((v=(E=l==null?void 0:l.chart)==null?void 0:E.dataset)==null?void 0:v.backgroundColor)||[]};(D=t.customCardPreferences)!=null&&D.inputData;const{getCard:x}=s.useCustomVisual(((T=t.customCardPreferences)==null?void 0:T.url)||""),h=((z=t.customCardPreferences)==null?void 0:z.visualType)||"single",p=s.useEditorStore(O=>O.frame),{setCustomCardPreferences:f}=s.useEditorActions(),{data:u}=s.useDashboardCardQuery(t),g=C.useCallback((O,P)=>{o(S=>({...S,[O]:P}))},[]);if(!((q=t.customCardPreferences)!=null&&q.componentName))return null;const j=x((V=t.customCardPreferences)==null?void 0:V.componentName);function y(O){a(O)}const b=Object.keys(((_=t.customCardPreferences)==null?void 0:_.dataInputCardIds)||{}).map(O=>{var N,R,M;const P=(R=(N=t.customCardPreferences)==null?void 0:N.dataInputCardIds)==null?void 0:R[O].cardId,S=(M=p==null?void 0:p.cards)==null?void 0:M.find(G=>G.id===P);return S||null});return e.jsx("div",{className:"semaphor-custom mb-3 flex grow basis-0 flex-col space-y-2 overflow-y-auto",children:e.jsxs(C.Suspense,{fallback:e.jsx(e.Fragment,{}),children:[j&&h==="single"&&e.jsx(j,{params:c,theme:d,settings:(m=t.customCardPreferences)==null?void 0:m.settings,onDataChange:g,data:(u==null?void 0:u.records)||[]}),j&&h==="multiple"&&e.jsxs(e.Fragment,{children:[Object.keys(((A=t.customCardPreferences)==null?void 0:A.dataInputCardIds)||{}).map(O=>{var N,R,M;const P=(R=(N=t.customCardPreferences)==null?void 0:N.dataInputCardIds)==null?void 0:R[O].cardId,S=(M=p==null?void 0:p.cards)==null?void 0:M.find(G=>G.id===P);if(S)return e.jsx(s.MultiInputEmptyRenderer,{onLoadingStatus:y,onDataChange:g,dataInputIndex:O,card:S},S.id+O)}),e.jsx("div",{className:"flex flex-col gap-2",children:e.jsx(j,{theme:d,onDataChange:g,settings:b.map(O=>{var P;return(P=O==null?void 0:O.customCardPreferences)==null?void 0:P.settings}),data:b.map(O=>O!=null&&O.id?r==null?void 0:r[O.id]:[])})})]})]},(B=t.customCardPreferences)==null?void 0:B.componentName)})}function os({className:t,...n}){var y;const a=s.useEditorStore(b=>b.card),r=((y=a.customCardPreferences)==null?void 0:y.showCardHeader)??!0,o=s.useEditorStore(b=>b.frame),i=s.useDashboardStore(b=>b.dashboard.filters);s.useEditorStore(b=>b.actions.setRunSql);const{updateFilter:c}=s.useDashboardActions(),l=i==null?void 0:i.find(b=>b.id===o.filterId),{data:d,isLoading:x,isFetching:h}=s.useDashboardCardQuery(a),{setCard:p}=s.useEditorActions(),{data:f}=s.useTopoJson(a);if(!a.id)return null;let u;d!=null&&d.records&&(d==null?void 0:d.records.length)>0&&(u=s.createChartConfig({data:d==null?void 0:d.records,cardType:a.type,cfg:a.cfg,customCfg:a.customCfg,preferences:a.preferences,topoJson:f}));function g(b){return e.jsx(vt,{card:b})}function j(){var b;if(d!=null&&d.records&&(d==null?void 0:d.records.length)===0&&!x&&!h)return e.jsxs("div",{className:"flex h-full flex-col items-center justify-center gap-2",children:[e.jsx(s.TreePalm,{className:"size-8 text-muted-foreground"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"No records to display"})]});if(a.type==="custom")return g(a);if(!["table","custom"].includes(a.type)&&u)return e.jsx(s.ChartJsVisual,{cfg:u},JSON.stringify(u)+JSON.stringify(a.preferences)+((b=a==null?void 0:a.preferences)==null?void 0:b.customVisualCode));if(a.type==="table"&&(d!=null&&d.records)&&(d==null?void 0:d.records.length)>0)return e.jsxs(s.ScrollArea,{className:"relative mb-2 flex h-full min-h-0 w-full flex-1 grow basis-0",children:[e.jsx(s.TableVisual,{card:a,data:d==null?void 0:d.records}),e.jsx(s.ScrollBar,{orientation:"horizontal"})]})}return e.jsxs(s.Card,{role:"editor-visual-card",className:s.cn("relative flex h-full flex-col rounded-none",t),...n,children:[r&&e.jsxs(s.CardHeader,{className:"flex flex-row items-start justify-between py-4",children:[e.jsxs("div",{children:[e.jsx(s.Editable,{text:a.title,onSave:b=>p({...a,title:b}),children:e.jsx("div",{className:"flex items-center gap-5",children:e.jsx(s.CardTitle,{className:"text-base",children:a.title||"Edit title..."})})},a.title),e.jsx(s.Editable,{text:a.description||"",onSave:b=>p({...a,description:b}),children:e.jsx(s.CardDescription,{children:a.description||"Edit description..."})},a.description)]}),l&&e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(s.Editable,{className:"my-1",text:l.title||l.column,onSave:b=>c({...l,title:b}),children:e.jsx(s.Label,{children:l.title})}),e.jsx(s.FilterComponent,{filter:l})]})]}),e.jsx(s.CardContent,{className:"flex grow flex-col",children:j()})]})}const Re=({language:t,value:n,onChange:a,readonly:r})=>e.jsx(s.Ft,{className:"h-full w-full overflow-hidden text-xs",theme:"default",options:{minimap:{enabled:!1},wordWrap:"on",scrollbar:{verticalScrollbarSize:0,horizontalScrollbarSize:0},fontSize:12,lineHeight:16,renderLineHighlight:"none",readOnly:r},defaultLanguage:t,value:n,onChange:a}),Nt=()=>e.jsxs(s.DialogHeader,{children:[e.jsx("div",{className:"flex items-center gap-2",children:e.jsx(s.DialogTitle,{children:"Customize Card"})}),e.jsxs(s.DialogDescription,{children:["See the configuration options and documentation",e.jsx("a",{target:"_blank",className:"ml-1 text-blue-500 underline",href:"https://www.chartjs.org/docs/latest/samples/bar/vertical.html",children:"here."})]})]}),wt=({customCode:t,customConfig:n,onConfigChange:a,onCodeChange:r})=>e.jsxs(s.Tabs,{defaultValue:"final-config",className:"flex w-1/2 flex-col",children:[e.jsxs(s.TabsList,{className:"justify-start rounded-sm rounded-b-none border border-b-0",children:[e.jsx(s.TabsTrigger,{value:"final-config",children:"Config"}),e.jsx(s.TabsTrigger,{value:"custom-code",children:"Custom Code"})]}),e.jsx(s.TabsContent,{value:"final-config",className:"mt-0 grow rounded-b border border-t-0",children:e.jsx(Re,{language:"json",value:n,onChange:a})}),e.jsx(s.TabsContent,{value:"custom-code",className:"mt-0 grow rounded-b border border-t-0",children:e.jsx(Re,{language:"javascript",value:t,onChange:r})})]}),kt=({error:t,hasCustomConfig:n,onReset:a,onApply:r,onClose:o})=>e.jsxs(s.DialogFooter,{className:"flex items-center",children:[e.jsx(s.Label,{className:"mr-2 text-red-500",children:t}),e.jsx(s.Button,{disabled:!n,onClick:a,variant:"outline",children:"Reset"}),e.jsx(s.Button,{onClick:r,variant:"outline",children:"Apply"}),e.jsx(s.Button,{onClick:o,variant:"outline",children:"Close"})]});function Et(){const[t,n]=C.useState(!1),[a,r]=C.useState(""),[o,i]=C.useState(""),[c,l]=C.useState(""),[d,x]=C.useState(""),h=s.useEditorStore(v=>v.card),p=s.useEditorStore(v=>v.card.customCfg),{data:f}=s.useDashboardCardQuery(h),{data:u}=s.useTopoJson(h),{setCardCustomCfg:g,setCustomVisualCode:j}=s.useEditorActions(),y=v=>{var D,T;return JSON.stringify({...v,data:{...v.data,datasets:(T=(D=v.data)==null?void 0:D.datasets)==null?void 0:T.map(z=>({...z,data:[]}))}},null,2)},b=()=>{var D,T;if(!((D=f==null?void 0:f.records)!=null&&D.length))return;const v=s.createChartConfig({data:f.records,cardType:h.type,cfg:h.cfg,preferences:h.preferences,topoJson:u});if(v){r(y(v)),l(((T=h.preferences)==null?void 0:T.customVisualCode)||"");const z=s.merge(v,p);i(y(z))}},E=()=>{try{if(c&&j(c),o){const v=JSON.parse(o),D=s.getObjectDiff(JSON.parse(a),v);g(D),x("")}}catch{x("Invalid JSON configuration")}};return e.jsxs(s.Dialog,{open:t,onOpenChange:n,children:[e.jsx(s.DialogTrigger,{asChild:!0,children:e.jsx(s.IconButton,{tooltip:"Customize Visual",onClick:b,className:p?"text-green-600 hover:text-green-700":"",children:e.jsx(s.Settings,{className:"h-4 w-4"})})}),e.jsxs(s.DialogContent,{className:"max-h-[70vh] min-h-[70vh] overflow-auto sm:min-w-[900px] lg:min-w-[1200px]",children:[e.jsx(Nt,{}),e.jsxs("div",{className:"flex grow gap-2",children:[e.jsx(s.ErrorBoundary,{FallbackComponent:s.FallbackEditorCard,children:e.jsx(os,{className:"w-1/2 rounded shadow-none"})}),e.jsx(wt,{customCode:c,customConfig:o,onConfigChange:v=>i(v??""),onCodeChange:v=>l(v??"")})]}),e.jsx(kt,{error:d,hasCustomConfig:!!p,onReset:()=>{i(a),g(null)},onApply:E,onClose:()=>n(!1)})]})]})}function is(t){return ue({attr:{viewBox:"0 0 256 256",fill:"currentColor"},child:[{tag:"path",attr:{d:"M128,24A104,104,0,1,0,232,128,104.11,104.11,0,0,0,128,24Zm87.63,96H191.48A64.1,64.1,0,0,0,136,64.52V40.37A88.13,88.13,0,0,1,215.63,120ZM120,120H80.68A48.09,48.09,0,0,1,120,80.68Zm0,16v39.32A48.09,48.09,0,0,1,80.68,136Zm16,0h39.32A48.09,48.09,0,0,1,136,175.32Zm0-16V80.68A48.09,48.09,0,0,1,175.32,120ZM120,40.37V64.52A64.1,64.1,0,0,0,64.52,120H40.37A88.13,88.13,0,0,1,120,40.37ZM40.37,136H64.52A64.1,64.1,0,0,0,120,191.48v24.15A88.13,88.13,0,0,1,40.37,136ZM136,215.63V191.48A64.1,64.1,0,0,0,191.48,136h24.15A88.13,88.13,0,0,1,136,215.63Z"},child:[]}]})(t)}function It(t){return ue({attr:{viewBox:"0 0 256 256",fill:"currentColor"},child:[{tag:"path",attr:{d:"M48,180c0,11,7.18,20,16,20a14.24,14.24,0,0,0,10.22-4.66A8,8,0,0,1,85.78,206.4,30.06,30.06,0,0,1,64,216c-17.65,0-32-16.15-32-36s14.35-36,32-36a30.06,30.06,0,0,1,21.78,9.6,8,8,0,0,1-11.56,11.06A14.24,14.24,0,0,0,64,160C55.18,160,48,169,48,180Zm79.6-8.69c-4-1.16-8.14-2.35-10.45-3.84-1.25-.81-1.23-1-1.12-1.9a4.57,4.57,0,0,1,2-3.67c4.6-3.12,15.34-1.73,19.82-.56A8,8,0,0,0,142,145.86c-2.12-.55-21-5.22-32.84,2.76a20.58,20.58,0,0,0-9,14.95c-2,15.88,13.65,20.41,23,23.11,12.06,3.49,13.12,4.92,12.78,7.59-.31,2.41-1.26,3.34-2.14,3.93-4.6,3.06-15.17,1.56-19.55.36A8,8,0,0,0,109.94,214a61.34,61.34,0,0,0,15.19,2c5.82,0,12.3-1,17.49-4.46a20.82,20.82,0,0,0,9.19-15.23C154,179,137.49,174.17,127.6,171.31Zm83.09-26.84a8,8,0,0,0-10.23,4.84L188,184.21l-12.47-34.9a8,8,0,0,0-15.07,5.38l20,56a8,8,0,0,0,15.07,0l20-56A8,8,0,0,0,210.69,144.47ZM216,88v24a8,8,0,0,1-16,0V96H152a8,8,0,0,1-8-8V40H56v72a8,8,0,0,1-16,0V40A16,16,0,0,1,56,24h96a8,8,0,0,1,5.66,2.34l56,56A8,8,0,0,1,216,88Zm-27.31-8L160,51.31V80Z"},child:[]}]})(t)}function ls(t){return ue({attr:{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"},child:[{tag:"path",attr:{d:"M6 16m-3 0a3 3 0 1 0 6 0a3 3 0 1 0 -6 0"},child:[]},{tag:"path",attr:{d:"M16 19m-2 0a2 2 0 1 0 4 0a2 2 0 1 0 -4 0"},child:[]},{tag:"path",attr:{d:"M14.5 7.5m-4.5 0a4.5 4.5 0 1 0 9 0a4.5 4.5 0 1 0 -9 0"},child:[]}]})(t)}function cs(t){return ue({attr:{viewBox:"0 0 24 24"},child:[{tag:"path",attr:{fill:"none",d:"M0 0h24v24H0z"},child:[]},{tag:"path",attr:{d:"m2 19.99 7.5-7.51 4 4 7.09-7.97L22 9.92l-8.5 9.56-4-4-6 6.01-1.5-1.5zm1.5-4.5 6-6.01 4 4L22 3.92l-1.41-1.41-7.09 7.97-4-4L2 13.99l1.5 1.5z"},child:[]}]})(t)}function ds(t){return ue({attr:{version:"1.2",baseProfile:"tiny",viewBox:"0 0 24 24"},child:[{tag:"path",attr:{d:"M4 18c-.552 0-1-.448-1-1v-6.382l-.553.276c-.495.248-1.095.046-1.342-.447-.247-.494-.046-1.094.448-1.342l2-1c.31-.155.678-.139.973.044.294.183.474.504.474.851v8c0 .552-.448 1-1 1zM13 18h-5c-.404 0-.769-.244-.924-.617-.155-.374-.069-.804.217-1.09l4-4c.254-.254.394-.591.394-.95 0-.358-.14-.695-.394-.949-.508-.508-1.39-.508-1.9.001-.253.252-.393.589-.393.948 0 .552-.448 1-1 1s-1-.448-1-1c0-.894.348-1.733.98-2.364 1.265-1.263 3.464-1.263 4.727.001.632.631.979 1.471.979 2.363 0 .893-.348 1.733-.979 2.364l-2.293 2.293h2.586c.552 0 1 .448 1 1s-.448 1-1 1zM20.955 12.377c.338-.457.545-1.016.545-1.627 0-1.517-1.234-2.75-2.75-2.75-1.031 0-1.966.569-2.44 1.484-.254.49-.063 1.094.428 1.348.49.254 1.094.062 1.348-.428.128-.249.383-.404.664-.404.414 0 .75.336.75.75s-.336.75-.75.75c-.552 0-1 .448-1 1s.448 1 1 1c.689 0 1.25.561 1.25 1.25s-.561 1.25-1.25 1.25-1.25-.561-1.25-1.25c0-.552-.448-1-1-1s-1 .448-1 1c0 1.792 1.458 3.25 3.25 3.25s3.25-1.458 3.25-3.25c0-.939-.406-1.779-1.045-2.373z"},child:[]}]})(t)}function us(t){const[n,a]=C.useState(null);return n}function hs(){const{authToken:t}=s.useSemaphorContext(),{data:n,isLoading:a,isFetching:r,isError:o}=s.useQuery({queryKey:["plugins",t==null?void 0:t.accessToken],queryFn:()=>s.getPlugins(t==null?void 0:t.accessToken)});return{data:n,isLoading:a,isFetching:r,isError:o}}function Dt({onChartTypeChange:t}){const[n,a]=C.useState([]),{data:r}=hs();return C.useEffect(()=>{(async()=>{var i;if(r){const l=(await Promise.all((i=r==null?void 0:r.plugins)==null?void 0:i.map(async d=>(await s.loadManifest(d.value)).visuals.map(p=>({name:p.name,icon:p.icon,url:d.value}))))).flat();a(l)}})()},[r]),n.length===0?null:e.jsxs(e.Fragment,{children:[e.jsx(s.Separator,{className:"my-2"}),e.jsx("div",{className:"grid grid-cols-4 place-items-center",children:n.map((o,i)=>e.jsx(Tt,{text:o.name,onClick:()=>t("custom",o),icon:o.icon},o.url+o.name+i))})]})}const Tt=({text:t,icon:n,onClick:a})=>{const r=us(),o=t.charAt(0).toUpperCase();return e.jsx(s.Button,{onClick:a,title:t,variant:"ghost",children:r?e.jsx(r,{className:"h-4 w-4"}):o})};function At(){var h,p;const[t,n]=C.useState(!1),a=s.useEditorStore(f=>f.card),r=a.type,{setCardType:o,setCardPreferences:i,setChartOrientation:c}=s.useEditorStore(f=>f.actions),{setCardCustomCfg:l,setCustomCardPreferences:d}=s.useEditorActions();function x(f,u){l(null),i({}),o(f),u&&d({type:"component",visualType:"single",url:u.url,componentName:u.name,icon:u.icon}),n(!1)}return e.jsxs(s.Popover,{open:t,onOpenChange:n,children:[e.jsx(s.PopoverTrigger,{asChild:!0,children:e.jsx(s.Button,{size:"sm",variant:"ghost",children:e.jsx(Lt,{className:"size-4",chartType:r,customIcon:(h=a.customCardPreferences)==null?void 0:h.icon,componentName:(p=a.customCardPreferences)==null?void 0:p.componentName})})}),e.jsxs(s.PopoverContent,{className:"w-50",children:[e.jsxs("div",{className:"grid grid-cols-4 place-items-center",children:[e.jsx(s.Button,{onClick:()=>x("bar"),className:"font-normal",variant:"ghost",children:e.jsx(we,{className:"size-5"})}),e.jsx(s.Button,{onClick:()=>x("line"),variant:"ghost",children:e.jsx(ke,{className:"size-5"})}),e.jsx(s.Button,{onClick:()=>x("stackedBar"),variant:"ghost",children:e.jsx(Be,{className:"size-5"})}),e.jsx(s.Button,{onClick:()=>x("stackedLine"),variant:"ghost",children:e.jsx(cs,{className:"size-5",strokeWidth:0})}),e.jsx(s.Button,{onClick:()=>x("scatter"),variant:"ghost",children:e.jsx(He,{className:"size-5"})}),e.jsx(s.Button,{onClick:()=>x("bubble"),variant:"ghost",children:e.jsx(ls,{className:"size-5"})}),e.jsx(s.Button,{onClick:()=>x("pie"),variant:"ghost",children:e.jsx(_e,{className:"size-5"})}),e.jsx(s.Button,{onClick:()=>x("doughnut"),variant:"ghost",children:e.jsx(Ge,{className:"size-5"})}),e.jsx(s.Button,{onClick:()=>x("radar"),variant:"ghost",children:e.jsx(Qe,{className:"size-5"})}),e.jsx(s.Button,{onClick:()=>x("polarArea"),variant:"ghost",children:e.jsx(is,{className:"size-6"})}),e.jsx(s.Button,{onClick:()=>x("pyramid"),variant:"ghost",children:e.jsx(Ke,{className:"size-5"})}),e.jsx(s.Button,{onClick:()=>x("range"),variant:"ghost",children:e.jsx(Pe,{className:"size-5"})}),e.jsx(s.Button,{onClick:()=>x("table"),variant:"ghost",children:e.jsx(s.Table2,{className:"size-5"})}),e.jsx(s.Button,{onClick:()=>x("kpi"),variant:"ghost",children:e.jsx(ds,{className:"size-6"})}),e.jsx(s.Button,{onClick:()=>x("text"),variant:"ghost",children:e.jsx(bs,{className:"size-5"})}),e.jsx(s.Button,{onClick:()=>x("map"),variant:"ghost",children:e.jsx(Ue,{className:"size-5"})}),e.jsx(s.Button,{onClick:()=>x("custom"),variant:"ghost",children:e.jsx(We,{className:"size-5"})})]}),e.jsx(Dt,{onChartTypeChange:x})]})]})}function Lt({chartType:t,className:n,customIcon:a,componentName:r}){const o=us();switch(t){case"bar":return e.jsx(we,{className:n});case"line":return e.jsx(ke,{className:n});case"pie":return e.jsx(_e,{className:n});case"radar":return e.jsx(Qe,{className:n});case"scatter":return e.jsx(He,{className:n});case"bubble":return e.jsx(ls,{className:n});case"doughnut":return e.jsx(Ge,{className:n});case"stackedBar":return e.jsx(Be,{className:n});case"stackedLine":return e.jsx(cs,{className:n});case"polarArea":return e.jsx(is,{className:n});case"pyramid":return e.jsx(Ke,{className:n});case"range":return e.jsx(Pe,{className:n});case"kpi":return e.jsx(ds,{className:n});case"text":return e.jsx(Xe,{className:n});case"map":return e.jsx(Ue,{className:n});case"custom":return a&&o?e.jsx(o,{className:n}):r?r==null?void 0:r.charAt(0).toUpperCase():e.jsx(We,{className:n});default:return e.jsx(s.Table2,{className:n})}}const ge="focus-visible:ring-0 focus-visible:ring-ring focus-visible:ring-offset-0";function Ve(t,n){var r,o,i;const a=s.getNumberAxis(t,n);return((i=(o=(r=t==null?void 0:t.chartOptions)==null?void 0:r.scales)==null?void 0:o[a])==null?void 0:i.type)||"linear"}function Ot(){var N,R,M,G,J,K;const[t,n]=C.useState(!1),a=s.useEditorStore(F=>{var L;return(L=F.card)==null?void 0:L.preferences}),r=s.useEditorStore(F=>{var L;return(L=F.card)==null?void 0:L.cfg}),o=s.getNumberAxis(a,r),[i,c]=C.useState(Ve(a)),[l,d]=C.useState(((M=(R=(N=a==null?void 0:a.chartOptions)==null?void 0:N.scales)==null?void 0:R[o])==null?void 0:M.min)||""),[x,h]=C.useState(((K=(J=(G=a==null?void 0:a.chartOptions)==null?void 0:G.scales)==null?void 0:J[o])==null?void 0:K.max)||""),[p,f]=C.useState(l||x?"custom":"auto"),[u,g]=C.useState(""),[j,y]=C.useState(0),[b,E]=C.useState(""),[v,D]=C.useState(""),[T,z]=C.useState(""),q=s.useEditorStore(F=>F.actions.setCardPreferences),{updateCardInFrame:V}=s.useEditorActions(),_=s.useEditorStore(F=>F.card),m=s.useEditorStore(F=>{var L;return(L=F.card)==null?void 0:L.type}),A=["pie","doughnut","polarArea"].includes(m);C.useEffect(()=>{var F,L,Q,W,k,H,$,Y,se,U,X,le,ne,re;c(Ve(a)),d(((Q=(L=(F=a==null?void 0:a.chartOptions)==null?void 0:F.scales)==null?void 0:L[o])==null?void 0:Q.min)===0?0:""),h(((H=(k=(W=a==null?void 0:a.chartOptions)==null?void 0:W.scales)==null?void 0:k[o])==null?void 0:H.max)||""),g(((U=(se=(Y=($=a==null?void 0:a.chartOptions)==null?void 0:$.scales)==null?void 0:Y[o])==null?void 0:se.ticks)==null?void 0:U.stepSize)||""),y(((X=a==null?void 0:a.numberAxisFormat)==null?void 0:X.decimalPlaces)||0),E(((le=a==null?void 0:a.numberAxisFormat)==null?void 0:le.suffix)||""),D(((ne=a==null?void 0:a.numberAxisFormat)==null?void 0:ne.currency)||""),z(((re=a==null?void 0:a.numberAxisFormat)==null?void 0:re.locale)||"")},[t,a,o]);function B(F,L){return L===""||/^[0-9\b]+$/.test(L)?Number(L):Number(F)}function O(){const F=[...new Set(s.LOCALE_CURRENCY_PAIRS.map(L=>L.currency))];return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"grid grid-cols-6 items-center gap-2",children:[e.jsx(s.Label,{className:"col-span-2 hover:cursor-pointer hover:underline",htmlFor:"currency",children:e.jsx("a",{target:"_blank",href:"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat",children:"Currency"})}),e.jsxs(s.Select,{value:v||"none",onValueChange:L=>D(L==="none"?"":L),children:[e.jsx(s.SelectTrigger,{className:"col-span-2 h-8 w-full focus:ring-1 focus:ring-offset-0",children:e.jsx(s.SelectValue,{})}),e.jsx(s.SelectContent,{children:e.jsxs(s.SelectGroup,{children:[e.jsx(s.SelectLabel,{children:"Currency"}),e.jsx(s.SelectItem,{value:"none",children:"None"}),F.map(L=>e.jsx(s.SelectItem,{value:L,children:L},L))]})})]}),e.jsxs(s.Select,{value:T,onValueChange:L=>z(L),children:[e.jsx(s.SelectTrigger,{className:"col-span-2 h-8 w-full focus:ring-1 focus:ring-offset-0",children:e.jsx(s.SelectValue,{})}),e.jsx(s.SelectContent,{children:e.jsxs(s.SelectGroup,{children:[e.jsx(s.SelectLabel,{children:"Locale"}),s.LOCALE_CURRENCY_PAIRS.map(L=>e.jsx(s.SelectItem,{value:L.locale,children:L.locale},L.locale))]})})]})]}),e.jsxs("div",{className:"grid grid-cols-9 items-center gap-2",children:[e.jsx(s.Label,{className:"col-span-3",htmlFor:"format",children:"Decimals"}),e.jsx(s.Input,{value:j,onChange:L=>y(Number(L.target.value)),id:"format",className:`col-span-6 h-8 w-full tracking-wide ${ge}`})]})]})}function P(){return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"grid grid-cols-3 items-center gap-2",children:[e.jsx(s.Label,{htmlFor:"range",children:"Range"}),e.jsx(s.Input,{id:"min",value:l,onChange:F=>d(L=>B(L,F.target.value)),className:`col-span-1 h-8 w-full ${ge}`}),e.jsx(s.Input,{value:x,onChange:F=>h(L=>B(L,F.target.value)),id:"max",className:`col-span-1 h-8 w-full ${ge}`})]}),e.jsxs("div",{className:"grid grid-cols-3 items-center gap-2",children:[e.jsx(s.Label,{htmlFor:"step-size",children:"Step Size"}),e.jsx(s.Input,{value:u,onChange:F=>g(L=>B(L,F.target.value)),id:"step-size",className:`col-span-1 h-8 w-full ${ge}`})]})]})}function S(){var W;let F={};p==="custom"&&(F={min:l,max:x,ticks:{stepSize:u}});const L={...a||{},chartOptions:{...a==null?void 0:a.chartOptions,scales:{...(W=a==null?void 0:a.chartOptions)==null?void 0:W.scales,[o]:{type:i,...i==="linear"?F:{}}}},numberAxisFormat:{decimalPlaces:j,suffix:b,currency:v,locale:T}};console.log(L),q(L);const Q={..._,preferences:L};V(Q)}return e.jsxs(s.Popover,{onOpenChange:F=>n(F),children:[e.jsx(s.PopoverTrigger,{asChild:!0,children:e.jsx(s.IconButton,{tooltip:"Scale Options",children:e.jsx(Gs,{className:"size-4 rotate-45"})})}),e.jsx(s.PopoverContent,{align:"center",className:"max-w-65",children:e.jsxs("div",{className:"grid gap-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx("h4",{className:"font-medium leading-none",children:"Scale Options"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Set the scale for the number axis"})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsxs("div",{className:"grid grid-cols-3 items-center gap-2",children:[e.jsx(s.Label,{htmlFor:"scale",children:"Type"}),e.jsxs(s.Select,{disabled:A,value:i,onValueChange:F=>c(F),children:[e.jsx(s.SelectTrigger,{className:"col-span-2 h-8 w-full focus:ring-1 focus:ring-offset-0",children:e.jsx(s.SelectValue,{})}),e.jsx(s.SelectContent,{id:"type",children:e.jsxs(s.SelectGroup,{children:[e.jsx(s.SelectLabel,{children:"Option"}),e.jsx(s.SelectItem,{value:"linear",children:"Linear"}),e.jsx(s.SelectItem,{value:"logarithmic",children:"Logarithmic"})]})})]})]}),i=="linear"&&e.jsxs("div",{className:"grid grid-cols-3 items-center gap-2 py-1",children:[e.jsx(s.Label,{htmlFor:"scale-option",children:"Setup"}),e.jsxs(s.RadioGroup,{disabled:A,id:"scale-option",value:p,onValueChange:F=>f(F),className:"col-span-2 flex gap-3",defaultValue:"x",children:[e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(s.RadioGroupItem,{value:"auto",id:"r1"}),e.jsx("label",{className:"text-sm",htmlFor:"r1",children:"Auto"})]}),e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(s.RadioGroupItem,{value:"custom",id:"r2"}),e.jsx("label",{className:"text-sm",htmlFor:"r2",children:"Custom"})]})]})]}),p==="custom"&&i=="linear"&&P(),O(),e.jsx(s.SelectSeparator,{}),e.jsx("div",{className:"grid grid-cols-3",children:e.jsx(s.Button,{onClick:S,variant:"secondary",className:"col-span-1 col-start-3 h-8 w-full",children:"Apply"})})]})]})})]})}function Mt(){const t=s.useEditorStore(l=>{var d,x,h,p;return(p=(h=(x=(d=l.card.preferences)==null?void 0:d.chartOptions)==null?void 0:x.plugins)==null?void 0:h.legend)==null?void 0:p.position}),n=s.useEditorStore(l=>{var d,x,h,p;return(p=(h=(x=(d=l.card.preferences)==null?void 0:d.chartOptions)==null?void 0:x.plugins)==null?void 0:h.legend)==null?void 0:p.align}),a=s.useEditorStore(l=>{var d,x,h,p;return(p=(h=(x=(d=l.card.preferences)==null?void 0:d.chartOptions)==null?void 0:x.plugins)==null?void 0:h.legend)==null?void 0:p.display}),{setLegendOptions:r}=s.useEditorActions(),o=l=>{r({display:l,position:t,align:n})},i=l=>{r({display:a,position:l,align:n})},c=l=>{r({display:a,position:t,align:l})};return e.jsxs(s.Popover,{children:[e.jsx(s.PopoverTrigger,{asChild:!0,children:e.jsx(s.IconButton,{tooltip:"Legend Settings",children:e.jsx(zs,{className:"size-4"})})}),e.jsx(s.PopoverContent,{className:"w-72",children:e.jsxs("div",{className:"grid gap-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx("h4",{className:"font-medium leading-none",children:"Legend Options"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Set the legend options for the chart."})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsxs("div",{className:"grid grid-cols-3 items-center gap-4",children:[e.jsx(s.Label,{htmlFor:"displayLegend",children:"Display"}),e.jsx("div",{className:"col-span-2 flex h-8 items-center",children:e.jsx(s.SmallSwitch,{checked:a,onCheckedChange:o,defaultChecked:!0,id:"displayLegend"})})]}),e.jsxs("div",{className:"grid grid-cols-3 items-center gap-4",children:[e.jsx(s.Label,{htmlFor:"position",children:"Position"}),e.jsxs(s.Select,{value:t,onValueChange:i,children:[e.jsx(s.SelectTrigger,{className:"col-span-2 h-8 focus:ring-1 focus:ring-offset-0",children:e.jsx(s.SelectValue,{placeholder:"Select Position"})}),e.jsxs(s.SelectContent,{children:[e.jsx(s.SelectItem,{value:"top",children:"Top"}),e.jsx(s.SelectItem,{value:"left",children:"Left"}),e.jsx(s.SelectItem,{value:"bottom",children:"Bottom"}),e.jsx(s.SelectItem,{value:"right",children:"Right"})]})]})]}),e.jsxs("div",{className:"grid grid-cols-3 items-center gap-4",children:[e.jsx(s.Label,{htmlFor:"align",children:"Align"}),e.jsxs(s.Select,{value:n,onValueChange:c,children:[e.jsx(s.SelectTrigger,{className:"col-span-2 h-8 focus:ring-1 focus:ring-offset-0",children:e.jsx(s.SelectValue,{placeholder:"Select Alignment"})}),e.jsxs(s.SelectContent,{children:[e.jsx(s.SelectItem,{value:"start",children:"Start"}),e.jsx(s.SelectItem,{value:"center",children:"Center"}),e.jsx(s.SelectItem,{value:"end",children:"End"})]})]})]})]})]})})]})}function zt(){const t=s.useEditorStore(c=>c.card),n=s.useEditorStore(c=>c.isShowingVisual),a=s.useEditorStore(c=>{var l,d;return(d=(l=c.card)==null?void 0:l.preferences)==null?void 0:d.chartOptions}),r=s.getChartGridStyle(a),{setChartGrid:o}=s.useEditorActions();function i(){const c=["xy","none","x","y"],d=(c.indexOf(r)+1)%c.length;o(c[d])}return n?e.jsxs("div",{"data-info":"visual-settings",className:"flex items-center",children:[!["kpi","text","custom","table"].includes(t.type)&&e.jsxs(e.Fragment,{children:[e.jsx(Ot,{}),e.jsx(Mt,{})]}),!["pie","doughnut","radar","polarArea","table","custom","kpi","text","map"].includes(t.type)&&e.jsxs(s.IconButton,{tooltip:"Grid Style",onClick:i,children:[(r==="xy"||!r)&&e.jsx(As,{className:"size-4"}),r==="x"&&e.jsx(Ns,{className:"size-4"}),r==="y"&&e.jsx(Hs,{className:"size-4"}),r==="none"&&e.jsx(Js,{className:"size-4"})]})]}):null}function qe(){var P;const t=s.useEditorStore(S=>S.frame),n=s.useEditorStore(S=>S.card),a=s.useEditorStore(S=>S.isShowingVisual),r=s.useEditorStore(S=>S.isSqlRunning),o=s.useEditorStore(S=>S.pythonStdOut),i=s.useEditorStore(S=>{var N;return(N=S.card.preferences)==null?void 0:N.chartOptions});s.useEditorStore(S=>S.actions.setRunSql),s.getChartGridStyle(i);const{setFrame:c,setCard:l,updateCardInFrame:d,setActiveTabCardId:x,runAssistant:h,setChartGrid:p}=s.useEditorActions(),{data:f,isLoading:u,isFetching:g,error:j}=s.useDashboardCardQuery(n);if(!n)return e.jsx(e.Fragment,{children:"No Active Card"});function y(){const S={connectionId:n.connectionId,id:s.v4(),title:"Title",description:"Description",preferences:{onClickFilter:[{columnIndex:0,expression:""}]},type:"bar",sql:"",data:[]};b(S)}function b(S){const N={...t,cards:[...t.cards,S],activeCardId:S.id};c(N),x(S.id)}function E(){const S={...n,id:s.v4(),title:`${n.title} Copy`,tabTitle:`${n.tabTitle||n.title} Copy`};b(S)}function v(S){const N=t.cards.filter(G=>G.id!==S),R=N[0],M={...t,cards:N,activeCardId:R.id};c(M),x(R.id),l(R)}function D(S){x(S)}const T=(S,N)=>{console.log("handleDragStart",N),S.dataTransfer.setData("tabIndex",N.toString())},z=S=>{S.preventDefault()},q=(S,N)=>{const R=S.dataTransfer.getData("tabIndex");if(R===N.toString())return;const M=Array.from(t.cards),[G]=M.splice(parseInt(R),1);M.splice(N,0,G),c({...t,cards:M})};function V(S,N){return S.cards.length===1&&(N.displayTab===!0||N.displayTab===void 0)||S.activeCardId!==N.id&&(N.displayTab===!0||N.displayTab===void 0)?null:e.jsx("div",{onClick:()=>{const R=N.displayTab===void 0?!1:!N.displayTab;l({...N,displayTab:R}),d({...N,displayTab:R})},children:N.displayTab===!0||N.displayTab===void 0?e.jsx(s.Eye,{className:"mr-2 size-3.5 text-muted-foreground hover:text-foreground"}):e.jsx(Is,{className:"mr-2 size-3.5 text-muted-foreground hover:text-foreground"})})}function _(){return e.jsxs(s.Tabs,{onValueChange:D,value:t.activeCardId,className:"flex grow flex-col",children:[t.cards.map(S=>e.jsx(s.TabsContent,{className:"mt-0 grow",value:S.id,children:m()},S.id)),e.jsx(s.TabsList,{className:"group mx-6 justify-between overflow-x-auto",children:e.jsxs("div",{className:"flex items-center",children:[t.cards.map((S,N)=>e.jsx(s.Editable,{text:S.tabTitle||S.title,onSave:R=>{l({...n,tabTitle:R}),d({...n,tabTitle:R})},children:e.jsxs(s.TabsTrigger,{draggable:!0,onDragStart:R=>T(R,N),onDragOver:z,onDrop:R=>q(R,N),className:"",value:S.id,children:[V(t,S),S.tabTitle||S.title,t.activeCardId===S.id&&t.cards.length>1&&e.jsx(s.X,{className:"ml-2 size-3.5 text-muted-foreground hover:text-foreground",onClick:()=>v(S.id)})]})},S.id)),e.jsx(s.Button,{className:"ml-1 h-8 px-2 hover:bg-muted-foreground/50",variant:"outline",onClick:y,children:e.jsx(s.Plus,{className:"h-4 w-4"})}),e.jsx(s.Button,{className:"invisible ml-1 h-8 px-2 hover:bg-muted-foreground/50 group-hover:visible",variant:"outline",onClick:E,children:e.jsx(ws,{className:"h-4 w-4"})})]})})]})}function m(){return n.type==="kpi"?e.jsx("div",{className:"flex h-full items-center justify-center",children:e.jsx("div",{className:"w-1/2 rounded-md border",children:e.jsx(s.KPICard,{card:n,data:f==null?void 0:f.records})})}):n.type==="text"?e.jsx("div",{className:"flex h-full items-center justify-center",children:e.jsx("div",{className:"w-1/2 rounded-md border",children:e.jsx(s.ScrollArea,{className:"mx-3 my-6 h-[300px] overflow-y-auto break-words px-3",children:e.jsx(s.TextCard,{isLoading:r,card:n,data:f==null?void 0:f.records})})})}):e.jsx(s.ErrorBoundary,{FallbackComponent:s.FallbackEditorCard,children:e.jsx(os,{className:"grow border-none shadow-none"})})}function A(){const S=JSON.stringify(f==null?void 0:f.records,null,2),N=new Blob([S],{type:"application/json"}),R=URL.createObjectURL(N),M=document.createElement("a");M.href=R,M.download=`${n.title}.json`,M.click()}function B(){const N=[Object.keys(f==null?void 0:f.records.reduce((J,K)=>({...J,...K}),{})).join(","),...((f==null?void 0:f.records)||[]).map(J=>Object.values(J).join(","))].join(`
|
|
257
|
-
`),R=new Blob([N],{type:"text/csv"}),M=URL.createObjectURL(R),G=document.createElement("a");G.href=M,G.download=`${n.title}.csv`,G.click()}function O(){const S=`Can you get the documentation for ${n.type} chart?`;h(S)}return e.jsxs("div",{className:"relative flex h-full flex-col py-3",children:[(u||g)&&e.jsx("div",{className:"absolute bottom-0 left-0 right-0 top-0 z-50 m-auto flex h-10 w-10 items-center justify-center rounded-md bg-muted",children:e.jsx(pe,{className:"h-8 w-8 animate-spin text-muted-foreground"})}),e.jsxs("div",{className:"mb-0 flex min-h-10 items-center justify-end gap-2 px-6",children:[a&&e.jsxs("div",{className:"flex grow items-center",children:[e.jsx(At,{}),e.jsx(s.IconButton,{tooltip:"Visual Docs",onClick:O,children:e.jsx(js,{className:"size-4"})}),!["table","custom"].includes(n.type)&&e.jsx(Et,{})]}),!a&&e.jsxs("div",{className:"flex grow items-center gap-1",children:[e.jsx(s.Button,{className:"h-7 w-fit px-1 font-mono text-xs text-muted-foreground/70",variant:"ghost",size:"icon",onClick:B,children:e.jsx(It,{className:"size-4"})}),e.jsx(s.Button,{className:"h-7 w-fit px-1 font-mono text-xs text-muted-foreground/70",variant:"ghost",size:"icon",onClick:A,children:e.jsx(Ds,{strokeWidth:1.5,className:"size-4"})}),e.jsx(s.CopyButton,{text:JSON.stringify(f==null?void 0:f.records,null,2),className:"h-7 w-fit px-1 font-mono text-xs text-muted-foreground/70"})]}),e.jsx(zt,{}),e.jsx(Rt,{})]}),a?_():e.jsxs(s.ResizablePanelGroup,{className:"px-6",direction:"horizontal",children:[o&&e.jsxs(e.Fragment,{children:[e.jsx(s.ResizablePanel,{id:"1",order:1,defaultSize:30,minSize:10,className:"relative flex h-full min-h-0 w-full flex-1 basis-0",children:o&&e.jsx(Ft,{})}),e.jsx(s.ResizableHandle,{})]}),e.jsx(s.ResizablePanel,{id:"2",order:2,minSize:10,className:"relative flex h-full min-h-0 w-full flex-1 basis-0",children:e.jsxs(s.ScrollArea,{className:"relative flex h-full min-h-0 w-full flex-1 basis-0",children:[(f==null?void 0:f.records)&&(f==null?void 0:f.records.length)>0&&e.jsx(Ct,{data:(f==null?void 0:f.records)||[]}),(j||(f==null?void 0:f.error))&&e.jsx("span",{className:"font-mono text-xs",children:(j==null?void 0:j.message)||((P=f==null?void 0:f.error)==null?void 0:P.message)}),e.jsx(s.ScrollBar,{orientation:"horizontal"})]})})]})]})}function Ft(){const t=s.useEditorStore(a=>a.pythonStdOut);if(!t)return null;const n=t.replace(/\n/g,"<br>");return e.jsxs("div",{className:"relative flex w-full flex-col border-r",children:[e.jsx("div",{className:"sticky top-0 flex max-h-11 min-h-11 grow items-center border-b bg-muted px-3 font-mono text-xs font-semibold text-foreground/70",children:"Python Output"}),e.jsxs(s.ScrollArea,{className:"overflow-y-auto px-2 pt-1 font-mono text-xs text-foreground/90",children:[e.jsx("div",{dangerouslySetInnerHTML:{__html:n}}),e.jsx(s.ScrollBar,{orientation:"horizontal"})]})]})}function Rt(){const t=s.useEditorStore(a=>a.isShowingVisual),n=s.useEditorStore(a=>a.actions.setIsShowingVisual);return e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(s.Label,{htmlFor:"visualize",children:"Chart"}),e.jsx(s.SmallSwitch,{checked:t,onCheckedChange:()=>n(!t),id:"visualize",className:"data-[state=checked]:bg-foreground/50"})]})}function Vt({options:t,value:n,onValueChange:a}){return e.jsx(s.RadioGroup,{value:n,onValueChange:a,className:"flex gap-4",defaultValue:t[0].value,children:t.map(r=>e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(s.RadioGroupItem,{value:r.value,id:r.value}),e.jsx("label",{className:"text-sm",htmlFor:r.value,children:r.label})]},r.value))})}function te({label:t,options:n,value:a,onValueChange:r,className:o}){return e.jsxs(s.Select,{value:a,onValueChange:r,children:[e.jsx(s.SelectTrigger,{className:s.cn("w-full focus:ring-0 focus:ring-offset-0",o),children:e.jsx(s.SelectValue,{placeholder:t})}),e.jsx(s.SelectContent,{children:e.jsxs(s.SelectGroup,{children:[e.jsx(s.SelectLabel,{children:t}),n.map(i=>e.jsx(s.SelectItem,{value:i.value,children:i.label},i.value))]})})]})}function xe({children:t,summary:n,open:a,className:r}){return e.jsxs("details",{open:a,className:s.cn("space-y-4 [&_summary>svg]:open:-rotate-180",r),children:[e.jsxs("summary",{className:"flex cursor-pointer list-none items-center justify-between gap-4",children:[e.jsx(s.Label,{children:n}),e.jsx(s.ChevronUp,{className:"h-4 w-4"})]}),e.jsx("div",{className:"transition-all ease-in-out",children:t})]})}function qt(){var j,y;const t=s.useEditorStore(b=>b.card.customCardPreferences),{data:n}=hs(),a=(n==null?void 0:n.plugins)||[],r=s.useEditorStore(b=>b.card),o=s.useEditorStore(b=>b.frame),i=(t==null?void 0:t.visualType)||"single",{setCustomCardPreferences:c}=s.useEditorActions(),{components:l,manifest:d}=s.useCustomVisual((t==null?void 0:t.url)||""),x=(j=d==null?void 0:d.visuals)==null?void 0:j.find(b=>b.name===(t==null?void 0:t.componentName));function h(b,E){if(!t)return;const D={...(t==null?void 0:t.dataInputCardIds)||{},[b]:{cardId:E,hookRef:null}};c({...t,dataInputCardIds:D})}function p(b){var v,D;const E=(v=o==null?void 0:o.cards)==null?void 0:v.filter(T=>{var z;return((z=T==null?void 0:T.customCardPreferences)==null?void 0:z.visualType)!=="multiple"}).map(T=>({value:T.id,label:T.tabTitle||T.title}));return e.jsx("div",{className:"space-y-2",children:(D=b==null?void 0:b.dataInputs)==null?void 0:D.map((T,z)=>{var q,V;return e.jsxs("div",{className:"grid grid-cols-10 gap-2",children:[e.jsx("div",{className:"col-span-4 flex items-center",children:T}),e.jsx(te,{className:"col-span-6 h-8 w-full justify-between",label:"",options:E||[],value:((V=(q=t==null?void 0:t.dataInputCardIds)==null?void 0:q[z])==null?void 0:V.cardId)||"",onValueChange:_=>h(z,_)})]},z+Math.random())})})}function f(b,E,v=[]){var D,T;return t?b==="input"?e.jsx(s.Input,{className:`h-8 w-full ${s.removeRing}`,value:((D=t==null?void 0:t.settings)==null?void 0:D[E])||"",onChange:z=>{c({...t,settings:{...t==null?void 0:t.settings,[E]:z.target.value}})}},E):b==="select"?e.jsx(te,{className:"h-8 w-full",label:"",options:v,value:((T=t==null?void 0:t.settings)==null?void 0:T[E])||"",onValueChange:z=>{c({...t,settings:{...t==null?void 0:t.settings,[E]:z}})}}):null:null}function u(b){const E=Object.entries((b==null?void 0:b.settings)||{});return e.jsx("div",{className:"space-y-3",children:E.map(([v,D])=>e.jsxs("div",{className:"space-y-2",children:[e.jsx(s.Label,{children:D.title}),f(D.ui,v,D.options)]},v))})}function g(b){t&&c({...t,visualType:b,componentName:""})}return e.jsxs("div",{className:"p-6",children:[e.jsx(xe,{summary:"Plugin Settings",children:e.jsx("div",{className:"space-y-4 text-sm",children:e.jsxs("div",{className:"space-y-4 text-sm",children:[e.jsx("div",{className:"space-y-2",children:e.jsx("div",{className:"px-2",children:e.jsx(te,{className:"h-8 w-full",label:"",options:a,value:(t==null?void 0:t.url)||"",onValueChange:b=>c({...t||{url:"",componentName:""},url:b})})})}),((t==null?void 0:t.type)==="component"||(t==null?void 0:t.type)===void 0)&&e.jsx(Vt,{options:[{value:"single",label:"Single Visual"},{value:"multiple",label:"Multi-Visual"}],value:i,onValueChange:g}),((t==null?void 0:t.type)==="component"||(t==null?void 0:t.type)===void 0)&&t&&e.jsx(e.Fragment,{children:e.jsxs("div",{className:"space-y-2",children:[e.jsx(s.Label,{children:"Component"}),e.jsx("div",{className:"space-y-2 px-2",children:l&&e.jsx(te,{className:"h-8 w-full",label:"",options:(l==null?void 0:l.filter(b=>b.type===i).map(b=>({value:b.name,label:b.name})))||[],value:t.componentName,onValueChange:b=>{console.log("changing value",b),c({...t,componentName:b})}})})]})})]})})}),e.jsx(s.Separator,{className:"my-4"}),((y=r==null?void 0:r.customCardPreferences)==null?void 0:y.componentName)&&e.jsxs(xe,{summary:"Component Settings",children:[x&&x.dataInputs&&e.jsxs("div",{className:"space-y-3",children:[e.jsx(s.Label,{children:"Input Mapping"}),e.jsx("div",{className:"px-2",children:p(x)})]}),x&&x.settings&&e.jsx("div",{className:"space-y-3",children:e.jsx("div",{className:"px-2",children:u(x)})})]})]})}function ie(){const[t,n]=C.useState([]);s.useEditorStore(h=>h.card.cfg);const a=s.useEditorStore(h=>h.card.preferences),{setCardCfg:r,setFilterOnClickColumnIndex:o,setCardPreferences:i}=s.useEditorStore(h=>h.actions),c=s.useEditorStore(h=>h.queryResultColumns);s.useEditorStore(h=>{var p;return(p=h.card.preferences)==null?void 0:p.filterOnClickColumnIndex}),C.useEffect(()=>{c&&n(new Array(c.length).fill(!1))},[c]);function l(h,p){var f,u;p?a!=null&&a.onClickFilter&&((f=a==null?void 0:a.onClickFilter)==null?void 0:f.length)>0?i({...a,onClickFilter:[...a.onClickFilter,{columnIndex:h,expression:""}]}):i({...a,onClickFilter:[{columnIndex:h,expression:""}]}):(i({...a,onClickFilter:(u=a==null?void 0:a.onClickFilter)==null?void 0:u.filter(g=>g.columnIndex!==h)}),n(g=>{const j=[...g];return j[h]=!1,j}))}function d(h,p){var u;const f=(u=a==null?void 0:a.onClickFilter)==null?void 0:u.map(g=>g.columnIndex===h?{...g,expression:p.target.value}:g);i({...a,onClickFilter:f})}function x(h){var p,f,u,g;if(t!=null&&t[h]||(f=(p=a==null?void 0:a.onClickFilter)==null?void 0:p.find(j=>j.columnIndex===h))!=null&&f.expression)return e.jsx(s.Input,{value:(g=(u=a==null?void 0:a.onClickFilter)==null?void 0:u.find(j=>j.columnIndex===h))==null?void 0:g.expression,onChange:j=>d(h,j),type:"text",className:"h-9 w-full font-mono text-xs focus-visible:ring-0 focus-visible:ring-ring focus-visible:ring-offset-0",placeholder:"Expression"})}return e.jsxs("div",{className:"space-y-2",children:[e.jsx(s.Label,{children:"On Click"}),c==null?void 0:c.map((h,p)=>{var f,u;return e.jsx("div",{className:"xbg-red-100 group flex items-center justify-between space-y-2",children:e.jsxs("div",{className:"grow",children:[e.jsxs("div",{className:"flex items-center space-x-2 py-2",children:[e.jsx(s.Checkbox,{checked:!!((f=a==null?void 0:a.onClickFilter)!=null&&f.find(g=>g.columnIndex===p)),onCheckedChange:g=>l(p,g)}),e.jsx("label",{className:"text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70",children:h}),e.jsx("div",{className:"flex items-center gap-2",children:((u=a==null?void 0:a.onClickFilter)==null?void 0:u.find(g=>g.columnIndex===p))&&e.jsx(s.Pencil,{onClick:()=>{n(g=>{const j=[...g];return j[p]=!g[p],j})},className:"invisible size-3 cursor-pointer text-gray-400 group-hover:visible"})})]}),x(p)]})},h)})]})}function Se(){var c,l,d;const t=s.useEditorStore(x=>x.card.preferences),n=s.useEditorStore(x=>x.card.cfg),{setCardCfg:a,setCardPreferences:r,setChartOrientation:o}=s.useEditorStore(x=>x.actions);(c=n==null?void 0:n.options)!=null&&c.indexAxis;function i(x){o(x)}return e.jsxs(s.RadioGroup,{value:((l=t==null?void 0:t.chartOptions)==null?void 0:l.indexAxis)||((d=n==null?void 0:n.options)==null?void 0:d.indexAxis)||"x",onValueChange:i,className:"flex gap-3",defaultValue:"x",children:[e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(s.RadioGroupItem,{value:"x",id:"r1"}),e.jsx("label",{className:"text-sm",htmlFor:"r1",children:"Vertical"})]}),e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(s.RadioGroupItem,{value:"y",id:"r2"}),e.jsx("label",{className:"text-sm",htmlFor:"r2",children:"Horizontal"})]})]})}function Bt({idx:t}){var l;const n=s.useEditorStore(d=>{var x;return(x=d.card)==null?void 0:x.preferences}),a=s.useEditorStore(d=>{var x;return(x=d.card.preferences)==null?void 0:x.datasetOptions}),r=s.useEditorStore(d=>d.actions.setCardPreferences),o=(l=n==null?void 0:n.chartOptions)==null?void 0:l.indexAxis,i=a==null?void 0:a.find(d=>d.idx===t);function c(d,x){(d==="end"||d==="start")&&s.getContrastColor(s.getCanvasBackgroundColor());const h={display:d!=="none",align:d,anchor:d,clamp:!0};if(!i)r({...n,datasetOptions:[...a||[],{idx:x,datalabels:h}]});else{const p={...i};p.datalabels=h;const f=a==null?void 0:a.map(u=>u.idx===x?p:u);r({...n,datasetOptions:f})}}return e.jsxs(s.Popover,{children:[e.jsx(s.PopoverTrigger,{children:e.jsx(Ws,{className:"invisible size-4 rotate-[135deg] cursor-pointer text-muted-foreground hover:text-foreground group-hover:visible"})}),e.jsx(s.PopoverContent,{className:"w-fit p-1",children:e.jsxs("div",{className:"flex gap-1",children:[e.jsx(s.Button,{onClick:()=>c("none",t),size:"sm",variant:"secondary",className:"h-7 p-1 text-xs font-normal",children:e.jsx(s.X,{className:"size-4"})}),e.jsx(s.Button,{onClick:()=>c("start",t),size:"sm",variant:"secondary",className:"h-7 p-1 text-xs font-normal",children:e.jsx(Fs,{className:s.cn("h-4 w-4",{"rotate-90":o==="y"})})}),e.jsx(s.Button,{onClick:()=>c("center",t),size:"sm",variant:"secondary",className:"h-7 p-1 text-xs font-normal",children:e.jsx(Vs,{className:s.cn("h-4 w-4",{"rotate-90":o==="y"})})}),e.jsx(s.Button,{onClick:()=>c("end",t),size:"sm",variant:"secondary",className:"h-7 p-1 text-xs font-normal",children:e.jsx(Rs,{className:s.cn("h-4 w-4",{"rotate-90":o==="y"})})})]})})]})}function ms(){const t=s.useEditorStore(x=>x.card),n=s.useEditorStore(x=>{var h,p,f;return(f=(p=(h=x==null?void 0:x.card)==null?void 0:h.preferences)==null?void 0:p.chartOptions)==null?void 0:f.indexAxis}),{data:a}=s.useDashboardCardQuery(t),r=n==="y"?"Y axis":"X axis",o=n==="y"?"X axis":"Y axis",{keys:i,metricKeys:c,dimensionKeys:l}=s.getKeys((a==null?void 0:a.records)||[]);let d=c;if(["stackedBar","stackedLine"].includes(t.type)){const x=s.pivotData({dataArray:(a==null?void 0:a.records)||[],groupKey:l[0],pivotKey:l[1],valueKey:d[0]}),{metricKeys:h}=s.getKeys(x);d=h}return i.length===0?null:e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(s.Label,{children:r}),e.jsx("div",{className:"my-1 space-y-1",children:e.jsx("div",{className:"rounded-md bg-muted/70 px-3 py-2 hover:bg-muted",children:e.jsx("p",{title:l[0],children:xs(l[0])})})})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(s.Label,{children:o}),e.jsx("div",{className:"my-1 max-h-[125px] space-y-1 overflow-y-auto",children:d.map((x,h)=>e.jsx(Pt,{col:x,idx:h},x))})]})]})}function xs(t,n=30){return t.length>n?t.slice(0,n)+"...":t}function Pt({col:t,idx:n}){const a=s.useEditorStore(l=>{var d;return(d=l.card)==null?void 0:d.preferences}),r=s.useEditorStore(l=>{var d;return(d=l.card.preferences)==null?void 0:d.datasetOptions}),o=r==null?void 0:r.find(l=>l.idx===n),{setCardPreferences:i}=s.useEditorStore(l=>l.actions);function c(l){if(!o)i({...a,datasetOptions:[...r||[],{idx:n,type:l==="area"?"line":l,fill:l==="area"?"origin":""}]});else{const d={...o};d.type=l==="area"?"line":l,d.fill=l==="area"?"origin":"";const x=r==null?void 0:r.map(h=>h.idx===n?d:h);i({...a,datasetOptions:x})}}return e.jsxs("div",{className:"group flex items-center justify-between gap-5 rounded-md bg-muted/70 px-3 py-2 hover:bg-muted",children:[e.jsx("p",{title:t,children:xs(t)}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(we,{onClick:()=>c("bar"),className:"invisible size-4 cursor-pointer text-muted-foreground hover:text-foreground group-hover:visible"}),e.jsx(ke,{onClick:()=>c("line"),className:"invisible size-4 cursor-pointer text-muted-foreground hover:text-foreground group-hover:visible"}),e.jsx(Cs,{onClick:()=>c("area"),className:"invisible size-4 cursor-pointer text-muted-foreground hover:text-foreground group-hover:visible"}),e.jsx(Bt,{idx:n})]})]})}function ps(){const t=s.useEditorStore(u=>u.selectedConnectionId),n=s.useEditorStore(u=>u.selectedDatamodelId),a=s.useEditorStore(u=>u.selectedDatabaseName),r=s.useEditorStore(u=>u.selectedSchemaName),o=s.useEditorStore(u=>u.selectedTableName),i=s.useDashboardStore(u=>u.dashboard.filters)||[],c=s.useDashboardStore(u=>u.actions.addFilter),l=s.useDashboardStore(u=>u.actions.removeFilter),{removeFilterValues:d}=s.useDashboardActions(),{modelItems:x,tableName:h,connectionType:p}=ae();function f(u,g="dashboard"){var q;const j=s.fmt(u.column_name),y=s.fmt(a||""),b=s.fmt(r||""),E=s.fmt(h);let v=s.getQualifiedTableName(b,E,p),D=`${v}.${j}`;const T=(q=x==null?void 0:x.find(V=>V.id===n))==null?void 0:q.name;n&&n!=="none"&&(D=`${s.DATAMODEL_NAMESPCACE}.${T}.${j}`,v=`${s.DATAMODEL_NAMESPCACE}.${T}`);const z=i==null?void 0:i.find(V=>V.column===D&&V.table===E&&(V.database===y||V.database===a));if(z)d(z.id),l(z.id);else{const V=s.v4();return h==="api"&&t?(c({location:g,id:V,column:D,title:u.column_name,dataType:u.data_type,table:"api",database:"",connectionId:t,operation:"in",sql:s.getDefaultFilterSql(u.data_type,v,j)}),V):(c({id:V,location:g,column:D,title:u.column_name,dataType:u.data_type,table:o||"",database:a||"",connectionId:t||"",operation:"in",sql:s.getDefaultFilterSql(u.data_type,v,j)}),V)}}return{assignFilter:f}}function he(){const t=s.useDashboardStore(l=>l.dashboard.filters),n=s.useEditorStore(l=>l.frame),{setFrame:a}=s.useEditorActions(),{columns:r}=ae(),{assignFilter:o}=ps();function i(l){const d=o(l,"frame");a({...n,filterId:d})}const c=t==null?void 0:t.find(l=>l.id===n.filterId);return e.jsxs("div",{className:"space-y-3",children:[e.jsx(s.Label,{children:"Card Filter"}),e.jsx(_t,{onSelect:i,columns:r}),c&&e.jsx(s.FilterHeader,{filter:c})]})}function _t({columns:t,onSelect:n}){var c;const[a,r]=de.useState(!1),[o,i]=de.useState("");return e.jsxs(s.Popover,{open:a,onOpenChange:r,children:[e.jsx(s.PopoverTrigger,{asChild:!0,children:e.jsxs(s.Button,{size:"sm",variant:"outline",role:"combobox","aria-expanded":a,className:"w-full justify-between font-normal",children:[o?(c=t.find(l=>l.column_name===o))==null?void 0:c.column_name:"Select Column...",e.jsx(s.CaretSortIcon,{className:"ml-2 h-4 w-4 shrink-0 opacity-50"})]})}),e.jsx(s.PopoverContent,{className:"w-[200px] p-0",children:e.jsxs(s.Command,{children:[e.jsx(s.CommandInput,{placeholder:"Search column",className:"h-9"}),e.jsxs(s.CommandList,{children:[e.jsx(s.CommandEmpty,{children:"No framework found."}),e.jsx(s.CommandGroup,{children:t.map(l=>e.jsxs(s.CommandItem,{value:l.column_name,onSelect:d=>{const x=d===o?"":d;i(x),r(!1),x&&n(l)},children:[l.column_name,e.jsx(s.CheckIcon,{className:s.cn("ml-auto h-4 w-4",o===l.column_name?"opacity-100":"opacity-0")})]},l.column_name))})]})]})})]})}function Ht({cardType:t}){return e.jsx("div",{className:"space-y-6 px-6 py-2",children:e.jsxs(s.Accordion,{defaultValue:["item-2"],type:"multiple",children:[e.jsxs(s.AccordionItem,{value:"item-1",children:[e.jsx(s.AccordionTrigger,{children:`${s.titleCase(t)} Chart`}),e.jsxs(s.AccordionContent,{className:"space-y-4 font-mono text-xs",children:[e.jsx("div",{className:"rounded bg-muted px-2 py-1 text-xs",children:"SELECT x-axis, y-axis-1, y-axis-2,... FROM table"}),e.jsxs("ul",{className:"ml-6 list-disc text-xs [&>li]:mt-2",children:[e.jsx("li",{children:"x-axis - category"}),e.jsx("li",{children:"y-axis1 - number"}),e.jsx("li",{children:"y-axis2 - number"})]}),e.jsxs("div",{children:["See ",e.jsx("a",{target:"_blank",onClick:n=>n.stopPropagation(),className:"text-blue-700",href:"https://docs.semaphor.cloud/docs/charts/bar-line-area",children:"example"})," in the docs."]})]})]}),e.jsxs(s.AccordionItem,{value:"item-2",children:[e.jsx(s.AccordionTrigger,{children:"Settings"}),e.jsxs(s.AccordionContent,{className:"space-y-4 px-2",children:[e.jsx(Se,{}),e.jsx(ms,{})]})]}),e.jsxs(s.AccordionItem,{value:"item-3",children:[e.jsx(s.AccordionTrigger,{children:"Filters"}),e.jsxs(s.AccordionContent,{className:"space-y-4 px-2",children:[e.jsx(ie,{}),e.jsx(he,{})]})]})]})})}function Ie(){var o,i,c;const t=s.useEditorStore(l=>l.card.cfg),n=s.useEditorStore(l=>l.actions.setCardCfg),a=s.useEditorStore(l=>l.card.type);function r(l){var h;const d={datalabels:{display:l!=="none",align:l,anchor:l,clamp:!0}},x={...t,options:{...t==null?void 0:t.options,plugins:{...(h=t==null?void 0:t.options)==null?void 0:h.plugins,...d}}};n(x),console.log(l)}return e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"font-medium",children:"Data Labels"}),e.jsxs(s.Select,{value:(c=(i=(o=t==null?void 0:t.options)==null?void 0:o.plugins)==null?void 0:i.datalabels)==null?void 0:c.anchor,onValueChange:r,defaultValue:"none",children:[e.jsx(s.SelectTrigger,{className:"h-8 w-full focus:ring-1 focus:ring-offset-0",children:e.jsx(s.SelectValue,{placeholder:"Select position"})}),e.jsx(s.SelectContent,{children:e.jsxs(s.SelectGroup,{children:[e.jsx(s.SelectLabel,{children:"Data Labels"}),e.jsx(s.SelectItem,{value:"none",children:"None"}),a!=="pyramid"&&e.jsx(s.SelectItem,{value:"start",children:"Start"}),e.jsx(s.SelectItem,{value:"center",children:"Center"}),a!=="pyramid"&&e.jsx(s.SelectItem,{value:"end",children:"End"})]})})]})]})}function Gt({cardType:t}){function n(a){return e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"rounded bg-muted px-2 py-1 text-xs",children:a==="bubble"?"SELECT label, [group], x-axis, y-axis, radius FROM table":"SELECT label, [group], x-axis, y-axis FROM table"}),e.jsxs("ul",{className:"ml-6 list-disc text-xs [&>li]:mt-2",children:[e.jsx("li",{children:"label - category"}),e.jsx("li",{children:"group (optional) - category"}),e.jsx("li",{children:"x-axis - number"}),e.jsx("li",{children:"y-axis - number"}),a==="bubble"&&e.jsx("li",{children:"radius - number"})]}),e.jsxs("div",{children:["See ",e.jsx("a",{target:"_blank",onClick:i=>i.stopPropagation(),className:"text-blue-700",href:"https://docs.semaphor.cloud/docs/charts/bubble",children:"example"})," in the docs."]})]})}return e.jsx("div",{className:"space-y-6 px-6 py-2",children:e.jsxs(s.Accordion,{defaultValue:["item-2"],type:"multiple",children:[e.jsxs(s.AccordionItem,{value:"item-1",children:[e.jsx(s.AccordionTrigger,{children:`${s.titleCase(t)} Chart`}),e.jsx(s.AccordionContent,{className:"space-y-4 font-mono text-xs",children:n(t)})]}),e.jsxs(s.AccordionItem,{value:"item-2",children:[e.jsx(s.AccordionTrigger,{children:"Settings"}),e.jsx(s.AccordionContent,{className:"px-2",children:e.jsx(Ie,{})})]}),e.jsxs(s.AccordionItem,{value:"item-3",children:[e.jsx(s.AccordionTrigger,{children:"Filters"}),e.jsxs(s.AccordionContent,{className:"space-y-4 px-2",children:[e.jsx(ie,{}),e.jsx(he,{})]})]})]})})}const $t={datasets:[{type:"line",label:"Sum_sales",data:[]},{type:"bar",label:"Sum_profit",data:[]}]},Ut={datasets:[{fill:"origin",type:"line",label:"Sum_sales",data:[]}]};function Qt(){const t=s.useEditorStore(n=>n.card.type);return e.jsxs("div",{className:"space-y-6 p-6",children:[e.jsx(s.Accordion,{className:" ",type:"single",collapsible:!0,children:Jt(t)}),e.jsx("section",{className:"",children:["line","bar"].includes(t)&&e.jsx(Se,{})}),!["kpi"].includes(t)&&e.jsxs("div",{className:"space-y-4",children:[e.jsx(Ie,{}),e.jsx(ie,{}),e.jsx(he,{})]})]})}function Jt(t){if(["line","bar"].includes(t))return e.jsxs(e.Fragment,{children:[e.jsxs(s.AccordionItem,{value:"item-1",children:[e.jsx(s.AccordionTrigger,{className:"font-normal",children:e.jsx("p",{children:"Chart Query"})}),e.jsxs(s.AccordionContent,{className:" ",children:[e.jsx("div",{className:"rounded bg-muted px-2 py-1 font-mono text-xs font-semibold",children:"SELECT x-axis, y-axis-1, y-axis-2, y-axis-3,... FROM table"}),e.jsxs("ul",{className:"my-6 ml-6 list-disc text-xs font-normal [&>li]:mt-2",children:[e.jsx("li",{children:"X-axis - Category (ex. city)"}),e.jsx("li",{children:"Y-axis - Number (ex. population)"})]})]})]}),e.jsxs(s.AccordionItem,{value:"item-2",children:[e.jsx(s.AccordionTrigger,{className:"font-normal",children:"Mixed Chart"}),e.jsxs(s.AccordionContent,{className:"space-y-2 text-xs",children:[e.jsxs("p",{children:["Click ",e.jsx("b",{children:"Customize"})," and change the `type` property in the dataset."]}),e.jsx("pre",{children:JSON.stringify($t,null,2)})]})]}),e.jsxs(s.AccordionItem,{value:"item-3",children:[e.jsx(s.AccordionTrigger,{className:"font-normal",children:"Area Chart"}),e.jsxs(s.AccordionContent,{className:"space-y-2 text-xs",children:[e.jsxs("p",{children:["Click ",e.jsx("b",{children:"Customize"})," and add `fill` property to the dataset. See",e.jsx("a",{className:"mx-1 text-blue-500 hover:underline",href:"https://www.chartjs.org/docs/latest/samples/area/line-boundaries.html",target:"_blank",children:"docs"}),"for more options."]}),e.jsx("pre",{children:JSON.stringify(Ut,null,2)})]})]})]});if(t==="bubble")return e.jsx(e.Fragment,{children:e.jsxs(s.AccordionItem,{value:"item-1",children:[e.jsx(s.AccordionTrigger,{className:"font-normal",children:e.jsxs("p",{children:["How to create a ",e.jsx("span",{children:t})," chart query?"]})}),e.jsxs(s.AccordionContent,{className:" ",children:[e.jsx("div",{className:"rounded bg-muted px-2 py-1 font-mono text-xs font-semibold",children:"SELECT label, x-axis, y-axis, radius FROM table"}),e.jsxs("ul",{className:"my-6 ml-6 list-disc text-xs font-normal [&>li]:mt-2",children:[e.jsx("li",{children:"Label - Category (ex. city)"}),e.jsx("li",{children:"Bubble Group (opt) - Category (ex. state)"}),e.jsx("li",{children:"X-axis - Number (ex. avg. age)"}),e.jsx("li",{children:"Y-axis - Number (ex. avg. weight)"}),e.jsx("li",{children:"Radius - Number (ex. population)"})]})]})]})});if(t==="scatter")return e.jsx(e.Fragment,{children:e.jsxs(s.AccordionItem,{value:"item-1",children:[e.jsx(s.AccordionTrigger,{className:"font-normal",children:e.jsxs("p",{children:["How to create a ",e.jsx("span",{children:t})," chart query?"]})}),e.jsxs(s.AccordionContent,{className:" ",children:[e.jsx("div",{className:"rounded bg-muted px-2 py-1 font-mono text-xs font-semibold",children:"SELECT label, x-axis, y-axis FROM table"}),e.jsxs("ul",{className:"my-6 ml-6 list-disc text-xs font-normal [&>li]:mt-2",children:[e.jsx("li",{children:"Label - Category (ex. city)"}),e.jsx("li",{children:"Group (opt) - Category (ex. state)"}),e.jsx("li",{children:"X-axis - Number (ex. avg. age)"}),e.jsx("li",{children:"Y-axis - Number (ex. avg. weight)"})]})]})]})});if(["pie","doughnut","polarArea"].includes(t))return e.jsx(e.Fragment,{children:e.jsxs(s.AccordionItem,{value:"item-1",children:[e.jsx(s.AccordionTrigger,{className:"font-normal",children:e.jsxs("p",{children:[e.jsx("span",{children:t==="polarArea"?"Polar":t.charAt(0).toUpperCase()+t.slice(1)})," ","chart query"]})}),e.jsxs(s.AccordionContent,{className:" ",children:[e.jsx("div",{className:"rounded bg-muted px-2 py-1 font-mono text-xs font-semibold",children:"SELECT label, measure FROM table"}),e.jsxs("ul",{className:"my-6 ml-6 list-disc text-xs font-normal [&>li]:mt-2",children:[e.jsx("li",{children:"Label - Category (ex. city)"}),e.jsx("li",{children:"Measure - Number (ex. population)"})]})]})]})})}function Wt(){var d,x,h,p,f;const t=s.useEditorStore(u=>u.card.preferences),n=s.useEditorStore(u=>u.actions.setCardPreferences),a=s.useEditorStore(u=>u.actions.setNumberFormat);s.useEditorStore(u=>{var g,j;return(j=(g=u.card.preferences)==null?void 0:g.formatNumber)==null?void 0:j.decimalPlaces});const r=s.useEditorStore(u=>{var g,j;return(j=(g=u.card.preferences)==null?void 0:g.formatNumber)==null?void 0:j.locale}),o=s.useEditorStore(u=>{var g,j;return(j=(g=u.card.preferences)==null?void 0:g.formatNumber)==null?void 0:j.currency});s.useEditorStore(u=>u.actions.setFilterOnClickField);const i=s.useEditorStore(u=>{var g,j;return(j=(g=u.card.preferences)==null?void 0:g.formatNumber)==null?void 0:j.colorRanges})||[],c=s.useEditorStore(u=>u.actions.setColorRanges),l=[...new Set(s.LOCALE_CURRENCY_PAIRS.map(u=>u.currency))];return e.jsxs("div",{children:[e.jsxs("div",{className:"mb-3 flex items-center gap-2",children:[e.jsx(s.Checkbox,{checked:!!((d=t==null?void 0:t.formatNumber)!=null&&d.enabled),onCheckedChange:u=>{n({...t,formatNumber:{...t==null?void 0:t.formatNumber,enabled:u}})}}),e.jsx(s.Label,{children:"Format Number"})]}),((x=t==null?void 0:t.formatNumber)==null?void 0:x.enabled)===!0&&e.jsxs("div",{className:"flex flex-col gap-2",children:[e.jsx("div",{children:e.jsxs("div",{className:"space-y-4 p-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("div",{className:"w-full space-y-1",children:[e.jsx(s.Label,{children:"Locale"}),e.jsxs(s.Select,{value:r||"none",onValueChange:u=>{var g,j,y;return a(((g=t==null?void 0:t.formatNumber)==null?void 0:g.decimalPlaces)||0,((j=t==null?void 0:t.formatNumber)==null?void 0:j.currency)||"",u,((y=t==null?void 0:t.formatNumber)==null?void 0:y.suffix)||"")},children:[e.jsx(s.SelectTrigger,{className:"col-span-6 h-8 w-full focus:ring-1 focus:ring-offset-0",children:e.jsx(s.SelectValue,{})}),e.jsx(s.SelectContent,{children:e.jsxs(s.SelectGroup,{children:[e.jsx(s.SelectLabel,{children:"Format"}),e.jsx(s.SelectItem,{value:"none",children:"None"},"none"),s.LOCALE_CURRENCY_PAIRS.map(u=>e.jsx(s.SelectItem,{value:u.locale,children:u.locale},u.locale))]})})]})]}),e.jsxs("div",{className:"w-full space-y-1",children:[e.jsx(s.Label,{children:"Currency"}),e.jsxs(s.Select,{value:o||"none",onValueChange:u=>{var g,j,y;console.log("currency",u),a(((g=t==null?void 0:t.formatNumber)==null?void 0:g.decimalPlaces)||0,u==="none"?"":u,((j=t==null?void 0:t.formatNumber)==null?void 0:j.locale)||"",((y=t==null?void 0:t.formatNumber)==null?void 0:y.suffix)||"")},children:[e.jsx(s.SelectTrigger,{className:"col-span-6 h-8 w-full focus:ring-1 focus:ring-offset-0",children:e.jsx(s.SelectValue,{})}),e.jsx(s.SelectContent,{children:e.jsxs(s.SelectGroup,{children:[e.jsx(s.SelectLabel,{children:"Currency"}),e.jsx(s.SelectItem,{value:"none",children:"None"},"none"),l.map(u=>e.jsx(s.SelectItem,{value:u,children:u},u))]})})]})]})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsxs("div",{className:"w-full space-y-1",children:[e.jsx(s.Label,{children:"Decimals"}),e.jsxs(s.Select,{value:((p=(h=t==null?void 0:t.formatNumber)==null?void 0:h.decimalPlaces)==null?void 0:p.toString())||"0",onValueChange:u=>{var g,j,y;return a(Number(u),((g=t==null?void 0:t.formatNumber)==null?void 0:g.currency)||"",((j=t==null?void 0:t.formatNumber)==null?void 0:j.locale)||"",((y=t==null?void 0:t.formatNumber)==null?void 0:y.suffix)||"")},children:[e.jsx(s.SelectTrigger,{className:"col-span-3 h-8 w-full focus:ring-1 focus:ring-offset-0",children:e.jsx(s.SelectValue,{})}),e.jsx(s.SelectContent,{children:["0","1","2","3","4"].map(u=>e.jsx(s.SelectItem,{value:u,children:u},u))})]})]}),e.jsxs("div",{className:"w-full space-y-1",children:[e.jsx(s.Label,{children:"Suffix"}),e.jsx(s.Input,{value:((f=t==null?void 0:t.formatNumber)==null?void 0:f.suffix)||"",className:"h-8 font-mono text-xs focus-visible:ring-0 focus-visible:ring-ring focus-visible:ring-offset-0",placeholder:"K, M, B, %",onChange:u=>{var g,j,y;return a(((g=t==null?void 0:t.formatNumber)==null?void 0:g.decimalPlaces)||0,((j=t==null?void 0:t.formatNumber)==null?void 0:j.currency)||"",((y=t==null?void 0:t.formatNumber)==null?void 0:y.locale)||"",u.target.value)}})]})]})]})}),e.jsx(s.Separator,{className:"my-3"}),e.jsx(s.ColorFormat,{colorRanges:i,setColorRanges:c})]})]})}function Kt(){return e.jsxs("div",{className:"space-y-6 px-6 py-2",children:[e.jsx(s.Accordion,{type:"single",collapsible:!0,children:e.jsxs(s.AccordionItem,{value:"item-1",children:[e.jsx(s.AccordionTrigger,{className:"",children:"KPI Query"}),e.jsxs(s.AccordionContent,{className:"font-mono",children:[e.jsx("div",{className:"rounded bg-muted px-2 py-1 font-mono text-xs",children:"SELECT current, previous FROM table"}),e.jsxs("ul",{className:"my-6 ml-6 list-disc text-xs [&>li]:mt-2",children:[e.jsx("li",{children:"current - number"}),e.jsx("li",{children:"previous - number"})]}),e.jsxs("div",{children:["See ",e.jsx("a",{target:"_blank",onClick:t=>t.stopPropagation(),className:"text-blue-700",href:"https://docs.semaphor.cloud/docs/charts/kpi",children:"example"})," in the docs."]})]})]})}),e.jsx("section",{className:"",children:e.jsx(Wt,{})}),e.jsx("div",{}),e.jsx("div",{})]})}const Xt=[{label:"Mercator",value:"mercator"},{label:"Azimuthal Equidistant",value:"azimuthalEquidistant"},{label:"Gnomonic",value:"gnomonic"},{label:"Orthographic",value:"orthographic"},{label:"Stereographic",value:"stereographic"},{label:"Equal Earth",value:"equalEarth"},{label:"Albers",value:"albers"},{label:"Albers USA",value:"albersUsa"},{label:"Conic Conformal",value:"conicConformal"},{label:"Conic Equal Area",value:"conicEqualArea"},{label:"Conic Equidistant",value:"conicEquidistant"},{label:"Equirectangular",value:"equirectangular"},{label:"Transverse Mercator",value:"transverseMercator"},{label:"Natural Earth 1",value:"naturalEarth1"}],Zt=["blues","brBG","buGn","buPu","cividis","cool","cubehelixDefault","gnBu","greens","greys","inferno","magma","orRd","oranges","pRGn","piYG","plasma","puBu","puBuGn","puOr","puRd","purples","rainbow","rdBu","rdGy","rdPu","rdYlBu","rdYlGn","reds","sinebow","spectral","turbo","viridis","warm","ylGn","ylGnBu","ylOrBr","ylOrRd"],Yt=Zt.map(t=>({label:t,value:t}));function ea(){var d,x,h,p,f,u,g,j,y,b,E,v,D,T,z,q,V,_;const t=s.useEditorStore(m=>m.card),n=(x=(d=t==null?void 0:t.preferences)==null?void 0:d.mapVisualOptions)==null?void 0:x.topoJsonUrl,[a,r]=C.useState(((p=(h=t==null?void 0:t.preferences)==null?void 0:h.mapVisualOptions)==null?void 0:p.customTopoJsonUrl)||""),{setCardPreferences:o}=s.useEditorActions(),{data:i}=s.useTopoJson(t),c=Object.keys((i==null?void 0:i.objects)||{}).map(m=>({label:m,value:m}))||[],l=[{label:"US States 10m",value:"https://unpkg.com/us-atlas/states-10m.json"},{label:"Countries 50m",value:"https://unpkg.com/world-atlas/countries-50m.json"},{label:"Custom",value:"custom"}];return e.jsxs("div",{className:"p-6",children:[e.jsx(xe,{summary:"Map Chart",children:e.jsx("p",{className:"rounded-md bg-muted p-2 font-mono text-xs",children:"SELECT country, value FROM table"})}),e.jsx(s.Separator,{className:"my-4"}),e.jsx(xe,{open:!0,summary:"Settings",children:e.jsxs("div",{className:"space-y-3 px-2",children:[e.jsx(te,{className:"h-9",options:l,onValueChange:m=>{console.log("value",m),o({...t.preferences,mapVisualOptions:{topoJsonUrl:m}})},value:n||"",label:"Select Map"}),n==="custom"&&e.jsx(s.Input,{onChange:m=>{r(m.target.value)},onBlur:()=>{var m;console.log("onBlur",a),o({...t.preferences,mapVisualOptions:{...(m=t.preferences)==null?void 0:m.mapVisualOptions,customTopoJsonUrl:a}})},value:a,className:`h-9 w-full ${s.removeRing}`,placeholder:"Custom URL"}),i&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx(s.Label,{children:"Map Object"}),e.jsx(te,{className:"h-9",options:c,value:((u=(f=t.preferences)==null?void 0:f.mapVisualOptions)==null?void 0:u.objectKey)||"",label:"Map Object",onValueChange:m=>{var A;o({...t.preferences,mapVisualOptions:{...(A=t.preferences)==null?void 0:A.mapVisualOptions,objectKey:m}})}})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(s.Label,{children:"Projection"}),e.jsx(te,{className:"h-9",options:Xt,value:((j=(g=t.preferences)==null?void 0:g.mapVisualOptions)==null?void 0:j.projection)||"",label:"Projection",onValueChange:m=>{var A;o({...t.preferences,mapVisualOptions:{...(A=t.preferences)==null?void 0:A.mapVisualOptions,projection:m}})}})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(s.Label,{children:"Colors"}),e.jsx(te,{className:"h-9",options:Yt,value:((b=(y=t.preferences)==null?void 0:y.mapVisualOptions)==null?void 0:b.colorScale)||"",label:"Select Color Scale",onValueChange:m=>{var A;o({...t.preferences,mapVisualOptions:{...(A=t.preferences)==null?void 0:A.mapVisualOptions,colorScale:m}})}})]})]})]})}),e.jsx(s.Separator,{className:"my-4"}),e.jsx(xe,{className:"",summary:"Scale Options",children:e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(s.Input,{className:`h-9 w-full ${s.removeRing}`,type:"number",step:.1,value:((v=(E=t.preferences)==null?void 0:E.mapVisualOptions)==null?void 0:v.projectionScale)||1,onChange:m=>{var A;o({...t.preferences,mapVisualOptions:{...(A=t.preferences)==null?void 0:A.mapVisualOptions,projectionScale:Number(m.target.value)}})}}),e.jsx(s.Label,{children:"X"}),e.jsx(s.Input,{className:`h-9 w-full ${s.removeRing}`,type:"number",step:10,value:((z=(T=(D=t.preferences)==null?void 0:D.mapVisualOptions)==null?void 0:T.projectionOffset)==null?void 0:z[0])||0,onChange:m=>{var A,B,O,P;o({...t.preferences,mapVisualOptions:{...(A=t.preferences)==null?void 0:A.mapVisualOptions,projectionOffset:[Number(m.target.value),((P=(O=(B=t.preferences)==null?void 0:B.mapVisualOptions)==null?void 0:O.projectionOffset)==null?void 0:P[1])||0]}})}}),e.jsx(s.Label,{children:"Y"}),e.jsx(s.Input,{className:`h-9 w-full ${s.removeRing}`,type:"number",step:10,value:((_=(V=(q=t.preferences)==null?void 0:q.mapVisualOptions)==null?void 0:V.projectionOffset)==null?void 0:_[1])||0,onChange:m=>{var A,B,O,P;o({...t.preferences,mapVisualOptions:{...(A=t.preferences)==null?void 0:A.mapVisualOptions,projectionOffset:[((P=(O=(B=t.preferences)==null?void 0:B.mapVisualOptions)==null?void 0:O.projectionOffset)==null?void 0:P[0])||0,Number(m.target.value)]}})}})]})}),e.jsx(s.Separator,{className:"my-4"}),e.jsx(ie,{})]})}function sa(){var r;const t=s.useEditorStore(o=>o.card.preferences),{setCardPreferences:n}=s.useEditorStore(o=>o.actions);function a(o){n({...t,textVisualOptions:{...t==null?void 0:t.textVisualOptions,isDynamicText:o==="dynamic"}})}return e.jsxs(s.RadioGroup,{value:(r=t==null?void 0:t.textVisualOptions)!=null&&r.isDynamicText?"dynamic":"static",onValueChange:a,className:"flex gap-3",defaultValue:"x",children:[e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(s.RadioGroupItem,{value:"static",id:"r1"}),e.jsx("label",{className:"text-sm",htmlFor:"r1",children:"Static"})]}),e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(s.RadioGroupItem,{value:"dynamic",id:"r2"}),e.jsx("label",{className:"text-sm",htmlFor:"r2",children:"Dynamic"})]})]})}function je({cardType:t,docContent:n,suffix:a="Chart"}){return e.jsx("div",{className:"space-y-6 px-6 py-2",children:e.jsxs(s.Accordion,{defaultValue:["item-2"],type:"multiple",children:[e.jsxs(s.AccordionItem,{value:"item-1",children:[e.jsx(s.AccordionTrigger,{children:`${s.titleCase(t)} ${a}`}),e.jsx(s.AccordionContent,{children:n||e.jsxs("div",{className:"space-y-4 font-mono text-xs",children:[e.jsx("div",{className:"rounded bg-muted px-2 py-1 text-xs",children:"SELECT label, measure FROM table"}),e.jsxs("ul",{className:"ml-6 list-disc text-xs [&>li]:mt-2",children:[e.jsx("li",{children:"label - category"}),e.jsx("li",{children:"measure - number"})]}),e.jsxs("div",{children:["See ",e.jsx("a",{target:"_blank",onClick:r=>r.stopPropagation(),className:"text-blue-700",href:"https://docs.semaphor.cloud/docs/charts/pie-donut-polar",children:"example"})," in the docs."]})]})})]}),e.jsxs(s.AccordionItem,{value:"item-2",children:[e.jsx(s.AccordionTrigger,{children:"Settings"}),e.jsxs(s.AccordionContent,{className:"space-y-4 px-2",children:[t==="range"&&e.jsx(Se,{}),t!=="text"&&e.jsx(Ie,{}),t==="text"&&e.jsx(sa,{})]})]}),!["range","text"].includes(t)&&e.jsxs(s.AccordionItem,{value:"item-3",children:[e.jsx(s.AccordionTrigger,{children:"Filters"}),e.jsxs(s.AccordionContent,{className:"space-y-4 px-2",children:[e.jsx(ie,{}),e.jsx(he,{})]})]})]})})}function ta(){const t=s.useEditorStore(r=>{var o,i;return(i=(o=r==null?void 0:r.card)==null?void 0:o.preferences)==null?void 0:i.sortChart}),{setSortChart:n}=s.useEditorActions();function a(){return e.jsxs("div",{className:"space-y-2",children:[e.jsx(s.Label,{children:"Sort"}),e.jsx(te,{className:"h-8",label:"Sort Chart",options:[{label:"None",value:"none"},{label:"ASC",value:"asc"},{label:"DESC",value:"desc"}],value:t||"none",onValueChange:r=>{n(r)}})]})}return e.jsx("div",{className:"space-y-6 px-6 py-2",children:e.jsxs(s.Accordion,{defaultValue:["item-2"],type:"multiple",children:[e.jsxs(s.AccordionItem,{value:"item-1",children:[e.jsx(s.AccordionTrigger,{children:"Stacked Chart"}),e.jsxs(s.AccordionContent,{className:"space-y-4 font-mono text-xs",children:[e.jsx("div",{className:"rounded bg-muted px-2 py-1 text-xs",children:"SELECT x-axis, stack-by, y-axis FROM table"}),e.jsxs("ul",{className:"ml-6 list-disc text-xs [&>li]:mt-2",children:[e.jsx("li",{children:"x-axis - category"}),e.jsx("li",{children:"stack by - category"}),e.jsx("li",{children:"y-axis - number"})]}),e.jsxs("div",{children:["See ",e.jsx("a",{target:"_blank",onClick:r=>r.stopPropagation(),className:"text-blue-700",href:"https://docs.semaphor.cloud/docs/charts/stacked",children:"example"})," in the docs."]})]})]}),e.jsxs(s.AccordionItem,{value:"item-2",children:[e.jsx(s.AccordionTrigger,{children:"Settings"}),e.jsxs(s.AccordionContent,{className:"space-y-4 px-2",children:[e.jsx(Se,{}),a(),e.jsx(ms,{})]})]}),e.jsxs(s.AccordionItem,{value:"item-3",children:[e.jsx(s.AccordionTrigger,{children:"Filters"}),e.jsxs(s.AccordionContent,{className:"space-y-4 px-2",children:[e.jsx(ie,{}),e.jsx(he,{})]})]})]})})}function aa({cardType:t="table"}){console.log("cardType",t);const n=s.useEditorStore(o=>{var i;return(i=o.card)==null?void 0:i.preferences}),a=s.useEditorStore(o=>o.actions.setCardPreferences),r=o=>{a({...n,allowDownload:o})};return e.jsxs("div",{className:"space-y-6 px-6 py-2",children:[e.jsx(s.Accordion,{defaultValue:["item-3"],type:"multiple",children:e.jsxs(s.AccordionItem,{value:"item-3",children:[e.jsx(s.AccordionTrigger,{children:"Filters"}),e.jsxs(s.AccordionContent,{className:"space-y-4 px-2",children:[e.jsx(ie,{}),e.jsx(he,{})]})]})}),e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(s.Checkbox,{onCheckedChange:r,id:"allow-download"}),e.jsx("label",{htmlFor:"allow-download",className:"text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70",children:"Allow Download"})]})]})}const na=e.jsxs("div",{className:"space-y-4 font-mono text-xs",children:[e.jsx("div",{className:"rounded bg-muted px-2 py-1 text-xs",children:"SELECT dimension, cohort, metric FROM table"}),e.jsxs("div",{children:["See ",e.jsx("a",{target:"_blank",onClick:t=>t.stopPropagation(),className:"text-blue-700",href:"https://docs.semaphor.cloud/docs/charts/tornado",children:"example"})," in the docs."]})]}),ra=e.jsxs("div",{className:"space-y-4 font-mono text-xs",children:[e.jsx("div",{className:"rounded bg-muted px-2 py-1 text-xs",children:"SELECT y-axis, label, range-from, range-to, range-value FROM table"}),e.jsxs("div",{children:["See ",e.jsx("a",{target:"_blank",onClick:t=>t.stopPropagation(),className:"text-blue-700",href:"https://docs.semaphor.cloud/docs/charts/range",children:"example"})," in the docs."]})]}),oa=e.jsxs("div",{className:"space-y-4 font-mono text-xs",children:[e.jsx("div",{className:"rounded bg-muted px-2 py-1 text-xs",children:"SELECT text FROM table limit 1"}),e.jsxs("div",{children:["See ",e.jsx("a",{target:"_blank",onClick:t=>t.stopPropagation(),className:"text-blue-700",href:"https://docs.semaphor.cloud/docs/charts/text",children:"example"})," in the docs."]})]});function ia(){const t=s.useEditorStore(a=>a.card.type);function n(a){switch(a){case"stackedBar":case"stackedLine":return e.jsx(ta,{});case"pyramid":return e.jsx(je,{docContent:na,cardType:a});case"kpi":return e.jsx(Kt,{});case"line":case"bar":return e.jsx(Ht,{cardType:a});case"range":return e.jsx(je,{docContent:ra,cardType:a});case"pie":case"doughnut":case"polarArea":case"radar":return e.jsx(je,{cardType:a});case"bubble":case"scatter":return e.jsx(Gt,{cardType:a});case"table":return e.jsx(aa,{cardType:a});case"text":return e.jsx(je,{docContent:oa,cardType:a,suffix:"Visual"});case"map":return e.jsx(ea,{});case"custom":return e.jsx(qt,{});default:return e.jsx(Qt,{})}}return e.jsxs(s.ScrollArea,{className:"h-full w-full text-sm",children:[n(t),e.jsx(s.ScrollBar,{orientation:"horizontal"})]})}function la(){const t=C.useRef(null),n=s.useEditorStore(r=>r.isShowingVisual),a=s.useEditorStore(r=>r.showAIDialog);return C.useEffect(()=>{var r,o;a?(r=t.current)==null||r.resize(0):(o=t.current)==null||o.resize(25)},[a]),e.jsxs(s.ResizablePanelGroup,{direction:"vertical",className:"min-h-[250px] min-w-full max-w-lg",children:[e.jsx(s.ResizablePanel,{role:"query-section",className:"flex",minSize:20,defaultSize:40,children:e.jsx(St,{})}),e.jsx(s.ResizableHandle,{withHandle:!0,className:"border"}),e.jsx(s.ResizablePanel,{className:"pb-1",role:"visual-section",minSize:0,defaultSize:60,children:n?e.jsxs(s.ResizablePanelGroup,{direction:"horizontal",children:[e.jsx(e.Fragment,{children:e.jsx(s.ResizablePanel,{ref:t,className:"flex",defaultSize:25,maxSize:30,children:e.jsx(ia,{})})}),!a&&e.jsx(s.ResizableHandle,{className:"border"}),e.jsx(s.ResizablePanel,{minSize:40,defaultSize:75,maxSize:100,children:e.jsx(qe,{})})]}):e.jsx(qe,{})})]})}const ca=!1,da=[{title:"Write a query for",subtitle:"orders over last 3 months"},{title:"Create a bar chart for",subtitle:"sales by product category"}];function ua(){const t=C.useRef(null),n=C.useRef(null),a=s.useEditorStore(N=>N.showAIDialog),r=C.useRef(a),[o,i]=C.useState(!1),[c,l]=C.useState(ca),[d,x]=C.useState(!1),h=s.useEditorStore(N=>N.actions.setCardSql),p=s.useEditorStore(N=>N.actions.setRunSql),{setShowAIDialog:f}=s.useEditorActions(),{messages:u,setMessages:g,reload:j,input:y,setInput:b,isLoading:E,handleAddCurrentTableToScope:v,removeFromCurrentSelections:D,currentAssitantScope:T,setCurrentAssitantScope:z,handleInputChange:q,handleSubmit:V,stop:_,chatStatus:m,toolStatus:A,llmUsage:B}=rs();C.useEffect(()=>{const N=r.current?"smooth":"auto";r.current=a;const R=setTimeout(()=>{var M;t.current&&(t.current.scroll({top:t.current.scrollHeight,behavior:N}),(M=n.current)==null||M.focus())},50);return()=>clearTimeout(R)},[u,a]);function O(N){h(N),p(!0)}function P(){return e.jsxs(s.DropdownMenu,{children:[e.jsx(s.DropdownMenuTrigger,{asChild:!0,children:e.jsx(s.Button,{className:"h-7 p-2",size:"sm",variant:"ghost",children:e.jsx($e,{className:"size-3.5 text-muted-foreground/70 hover:text-muted-foreground"})})}),e.jsxs(s.DropdownMenuContent,{align:"end",children:[e.jsx(s.DropdownMenuLabel,{children:"Options"}),e.jsx(s.DropdownMenuSeparator,{}),e.jsx(s.DropdownMenuCheckboxItem,{checked:o,onCheckedChange:i,children:"Token Usage"}),e.jsx(s.DropdownMenuCheckboxItem,{checked:c,onCheckedChange:l,children:"Tool Invocations"}),e.jsx(s.DropdownMenuCheckboxItem,{checked:d,onCheckedChange:x,children:"System Message"})]})]})}const S=(y==null?void 0:y.length)===0&&(u==null?void 0:u.filter(N=>N.role==="user").length)===0;return e.jsxs("div",{"data-content":"assistant",className:"flex h-full w-full flex-col justify-between gap-2 px-6 py-4",children:[e.jsxs("div",{"data-contet":"header-section",className:"flex items-start justify-between gap-2",children:[e.jsxs("div",{"data-content":"header",children:[e.jsx("div",{className:"text-lg font-semibold",children:"Assistant"}),T&&T.length>0&&e.jsxs("div",{className:"mt-2 flex flex-wrap items-center gap-2",children:[e.jsx("span",{className:"text-xs text-muted-foreground",children:"Context:"}),T==null?void 0:T.map((N,R)=>e.jsxs("div",{className:"flex items-center gap-2 rounded-md border border-border bg-muted px-2 py-1 text-xs",children:[s.getFormattedTableNameForQuery({schemaName:N.schemaName||"",tableName:N.tableName||"",modelName:N.datamodelName||"",connectionType:N.connectionType||""}),e.jsx("button",{onClick:()=>{D(N)},children:e.jsx(s.X,{className:"size-3 text-muted-foreground hover:text-foreground"})})]},R))]}),(T==null?void 0:T.length)===0&&e.jsxs("div",{className:"mt-2 flex items-center gap-2",children:[e.jsx("span",{className:"text-xs text-muted-foreground",children:"Context: None"}),e.jsxs(s.Button,{className:"h-6 text-xs",size:"sm",variant:"secondary",onClick:v,children:[e.jsx(s.Plus,{className:"mr-2 size-3"}),"Current Table"]})]})]}),e.jsxs("div",{"data-content":"actions",className:"flex items-center",children:[P(),e.jsx(s.Button,{className:"h-7 p-2",size:"sm",variant:"ghost",onClick:()=>{g([]),z([]),j()},children:e.jsx(s.RefreshCcw,{className:"size-3.5 text-muted-foreground"})}),e.jsx(s.Button,{className:"h-7 p-2",size:"sm",variant:"ghost",onClick:()=>{f(!1)},children:e.jsx(s.X,{className:"size-4"})})]})]}),e.jsx(s.CustomScrollArea,{ref:t,className:"flex w-full grow basis-0",children:e.jsxs("div",{className:"space-y-4 py-2 pr-3","data-content":"messages",children:[e.jsx(s.PrintMessages,{messages:u,showTools:c,handleRun:O,showSystemMessage:d}),e.jsx(s.ChatStatus,{status:s.getStatus(m,A),isLoading:E})]})}),S&&e.jsx(s.Placeholders,{placeholders:da}),e.jsx(s.ChatInput,{stop:_,ref:n,setInput:b,input:y,handleInputChange:q,handleSubmit:V,isLoading:E}),B&&o&&e.jsx("div",{className:"flex h-8 items-center justify-between",children:e.jsxs("div",{className:"text-xs text-muted-foreground",children:["Usage: ",B.promptTokens," prompt tokens,"," ",B.completionTokens," completion tokens,"," ",B.totalTokens," total tokens"]})})]})}function ha({authToken:t,onSave:n,onClose:a}){const r=C.useRef(null);s.useDashboardStore(p=>p.themeStyle);const o=s.useEditorStore(p=>p.actions.setOnSave),i=s.useEditorStore(p=>p.actions.setOnClose),c=s.useDashboardStore(p=>p.actions.setAuthToken),l=s.useEditorStore(p=>p.showAIDialog),{setShowAIDialog:d}=s.useEditorActions();C.useEffect(()=>{n&&o(n),a&&i(a)},[n,o,a,i]),C.useEffect(()=>{t&&t.accessToken&&c(t)},[t,c]),C.useEffect(()=>{var p,f;l?((p=r.current)==null||p.resize(40),d(!0)):(d(!1),(f=r.current)==null||f.resize(0))},[l,d]);function x(p){p<1?d(!1):l||d(!0)}function h(){return e.jsxs(s.ResizablePanelGroup,{"data-content":"editor-main",className:"grow",direction:"horizontal",children:[e.jsx(s.ResizablePanel,{className:"min-w-[510px] rounded-none border-x-[1px]",children:e.jsx(la,{})}),e.jsx(s.ResizableHandle,{}),e.jsx(s.ResizablePanel,{ref:r,onResize:x,defaultSize:0,children:e.jsx(ua,{})})]})}return e.jsx(s.ErrorBoundary,{FallbackComponent:s.Fallback,children:e.jsxs("section",{className:"flex h-full grow","data-content":"editor-panel",children:[e.jsx(ss,{}),h()]})})}function ma(){s.useDashboardStore(c=>c.selectedCardId);const t=s.useDashboardStore(c=>c.selectedSheetId),{setIsVisualEditing:n}=s.useDashboardStore(c=>c.actions),a=s.useDashboardStore(c=>c.isVisualEditing),r=s.useDashboardStore(c=>c.actions.updateFrame);function o(c){t&&(r(t,c),n(!1))}function i(){n(!1)}return e.jsx("div",{role:"editor-container",className:s.cn("flex grow",{"max-h-0 overflow-hidden":!a}),children:e.jsx(ha,{onSave:o,onClose:i})})}function xa(){const t=s.useEditorStore(i=>i.selectedDatabaseName),n=s.useEditorStore(i=>i.selectedTableName),a=s.useDashboardStore(i=>i.dashboard.filters)||[],{columns:r}=ae(),{assignFilter:o}=ps();return e.jsx(s.ScrollArea,{className:"flex-1 basis-0 flex-col px-3",children:r==null?void 0:r.map(i=>{const c=a==null?void 0:a.find(l=>l.column===s.fmt(i.column_name)&&l.table===n&&l.database===t);return e.jsx("div",{onClick:()=>o(i),className:s.cn("group flex cursor-pointer items-center justify-between border border-dashed border-background px-3 py-[6px] text-sm transition-colors hover:bg-muted/50",{"bg-muted":c}),children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(es,{column:i}),e.jsx("span",{children:i.column_name})]})},i.column_name)})})}function pa(){s.useDashboardStore(n=>n.showFilters);const t=s.useDashboardStore(n=>n.actions.setShowFilters);return e.jsxs("section",{className:"relative flex min-w-[320px] grow flex-col border-l px-1",children:[e.jsxs("div",{className:"mt-4 flex items-center justify-between gap-2 px-3",children:[e.jsx(s.Label,{className:"px-2 text-lg",children:"Filters"}),e.jsx(s.Button,{onClick:()=>t(!1),className:"h-7 w-7 p-0",variant:"ghost",children:e.jsx(s.Cross2Icon,{})})]}),e.jsx("div",{className:"flex grow",children:e.jsx(ss,{ColumnsComponent:()=>e.jsx(xa,{})})})]})}function fa(){const t=s.useDashboardStore(r=>r.dashboard.filters),n=s.useDashboardStore(r=>r.theme),a=t==null?void 0:t.filter(r=>r.hide);return a!=null&&a.length?e.jsx("div",{className:s.cn("mb-1 flex items-center gap-2 border-y px-0.5 pb-0.5",{"bg-[repeating-linear-gradient(45deg,_#ffffff_0_3px,_#f3f3f3_3px_6px)]":n==="light","bg-[repeating-linear-gradient(45deg,_#18171d_0_3px,_#272729_3px_6px)]":n==="dark"}),children:a==null?void 0:a.map(r=>e.jsxs("div",{className:"flex min-w-[250px] max-w-fit flex-col gap-1 p-2",children:[e.jsx(s.FilterHeader,{filter:r}),e.jsx(s.FilterComponent,{filter:r})]},r.id))}):null}function ga(){const t=s.useDashboardStore(r=>r.showFilters),n=s.useDashboardStore(r=>r.isVisualEditing),a=s.useDashboardStore(r=>r.isDashboardEditing);return e.jsxs("div",{role:"dashboard-plus-main",className:s.cn("",{"max-h-0 overflow-hidden":n,"flex grow overflow-auto":!n}),children:[e.jsxs("section",{className:"flex grow flex-col",children:[a&&e.jsx(fa,{}),e.jsx(s.DashboardTabs,{})]}),t&&e.jsx("div",{role:"filter-aside-container",className:"flex",children:e.jsx(pa,{})})]})}function ja(){const t=s.useDashboardStore(o=>o.dashboard),n=s.useDashboardStore(o=>o.actions.setDashboard),a=s.useDashboardStore(o=>o.showDashboardJSON),r=s.useDashboardStore(o=>o.actions.setShowDashboardJSON);return e.jsxs("div",{className:s.cn("relative p-2",{hidden:!a}),children:[e.jsxs(s.Button,{variant:"secondary",size:"sm",className:"absolute right-2 top-2 z-10 h-8",onClick:()=>r(!1),children:[e.jsx(s.X,{className:"mr-2 h-4 w-4"}),"Close"]}),e.jsx(s.de,{onChange:o=>{if(o)try{JSON.parse(o),n(JSON.parse(o))}catch{}},defaultLanguage:"json",className:"h-[550px] overflow-y-auto",value:JSON.stringify(t,null,2),options:{minimap:{enabled:!1},glyphMargin:!1,wordWrap:"on",scrollbar:{verticalScrollbarSize:0,horizontalScrollbarSize:0},fontSize:12,renderLineHighlight:"none"}})]})}function ba({showControls:t=!1,showFooter:n=!0,...a}){return e.jsx(s.ErrorBoundary,{FallbackComponent:s.Fallback,children:e.jsxs(s.SemaphorContextProvider,{dashboardProps:a,children:[e.jsx(s.$e,{}),e.jsxs(s.UXProvider,{children:[e.jsx(ja,{}),e.jsxs(s.DashboardPanel,{...a,children:[t&&e.jsx(nt,{}),e.jsx(ma,{}),e.jsx(ga,{})]})]})]})})}exports.Dashboard=s.Dashboard;exports.DashboardWC=s.DashboardWC;exports.SemaphorDataProvider=s.SemaphorQueryClient;exports.SemaphorQueryClient=s.SemaphorQueryClient;exports.createSqlGenConfig=s.createSqlGenConfig;exports.fmt=s.fmt;exports.getColumnDataType=s.getColumnDataType;exports.getFilterValueType=s.getFilterValueType;exports.getFormattedTableNameForQuery=s.getFormattedTableNameForQuery;exports.getQualifiedTableName=s.getQualifiedTableName;exports.getSql=s.getSql;exports.invalidateToken=s.invalidateToken;exports.isBooleanDataType=s.isBooleanDataType;exports.isColumnInSqlGen=s.isColumnInSqlGen;exports.isDateDataType=s.isDateDataType;exports.isNumberDataType=s.isNumberDataType;exports.isTextDataType=s.isTextDataType;exports.resolveDataType=s.resolveDataType;exports.resolveDatamodelName=s.resolveDatamodelName;exports.useCard=s.useCard;exports.useDashboardActions=s.useDashboardActions;exports.useDashboardStore=s.useDashboardStore;exports.useDateFilterHook=s.useDateFilterHook;exports.useEditorActions=s.useEditorActions;exports.useEditorStore=s.useEditorStore;exports.useTextFilterHook=s.useTextFilterHook;exports.SelectComponent=ce;exports.Surfboard=ba;exports.cleanCard=Ze;exports.downloadPdf=Ye;exports.getDashbaordStateWithoutData=Ee;exports.useEditorAside=ae;
|
|
257
|
+
`),R=new Blob([N],{type:"text/csv"}),M=URL.createObjectURL(R),G=document.createElement("a");G.href=M,G.download=`${n.title}.csv`,G.click()}function O(){const S=`Can you get the documentation for ${n.type} chart?`;h(S)}return e.jsxs("div",{className:"relative flex h-full flex-col py-3",children:[(u||g)&&e.jsx("div",{className:"absolute bottom-0 left-0 right-0 top-0 z-50 m-auto flex h-10 w-10 items-center justify-center rounded-md bg-muted",children:e.jsx(pe,{className:"h-8 w-8 animate-spin text-muted-foreground"})}),e.jsxs("div",{className:"mb-0 flex min-h-10 items-center justify-end gap-2 px-6",children:[a&&e.jsxs("div",{className:"flex grow items-center",children:[e.jsx(At,{}),e.jsx(s.IconButton,{tooltip:"Visual Docs",onClick:O,children:e.jsx(js,{className:"size-4"})}),!["table","custom"].includes(n.type)&&e.jsx(Et,{})]}),!a&&e.jsxs("div",{className:"flex grow items-center gap-1",children:[e.jsx(s.Button,{className:"h-7 w-fit px-1 font-mono text-xs text-muted-foreground/70",variant:"ghost",size:"icon",onClick:B,children:e.jsx(It,{className:"size-4"})}),e.jsx(s.Button,{className:"h-7 w-fit px-1 font-mono text-xs text-muted-foreground/70",variant:"ghost",size:"icon",onClick:A,children:e.jsx(Ds,{strokeWidth:1.5,className:"size-4"})}),e.jsx(s.CopyButton,{text:JSON.stringify(f==null?void 0:f.records,null,2),className:"h-7 w-fit px-1 font-mono text-xs text-muted-foreground/70"})]}),e.jsx(zt,{}),e.jsx(Rt,{})]}),a?_():e.jsxs(s.ResizablePanelGroup,{className:"px-6",direction:"horizontal",children:[o&&e.jsxs(e.Fragment,{children:[e.jsx(s.ResizablePanel,{id:"1",order:1,defaultSize:30,minSize:10,className:"relative flex h-full min-h-0 w-full flex-1 basis-0",children:o&&e.jsx(Ft,{})}),e.jsx(s.ResizableHandle,{})]}),e.jsx(s.ResizablePanel,{id:"2",order:2,minSize:10,className:"relative flex h-full min-h-0 w-full flex-1 basis-0",children:e.jsxs(s.ScrollArea,{className:"relative flex h-full min-h-0 w-full flex-1 basis-0",children:[(f==null?void 0:f.records)&&(f==null?void 0:f.records.length)>0&&e.jsx(Ct,{data:(f==null?void 0:f.records)||[]}),(j||(f==null?void 0:f.error))&&e.jsx("span",{className:"font-mono text-xs",children:(j==null?void 0:j.message)||((P=f==null?void 0:f.error)==null?void 0:P.message)}),e.jsx(s.ScrollBar,{orientation:"horizontal"})]})})]})]})}function Ft(){const t=s.useEditorStore(a=>a.pythonStdOut);if(!t)return null;const n=t.replace(/\n/g,"<br>");return e.jsxs("div",{className:"relative flex w-full flex-col border-r",children:[e.jsx("div",{className:"sticky top-0 flex max-h-11 min-h-11 grow items-center border-b bg-muted px-3 font-mono text-xs font-semibold text-foreground/70",children:"Python Output"}),e.jsxs(s.ScrollArea,{className:"overflow-y-auto px-2 pt-1 font-mono text-xs text-foreground/90",children:[e.jsx("div",{dangerouslySetInnerHTML:{__html:n}}),e.jsx(s.ScrollBar,{orientation:"horizontal"})]})]})}function Rt(){const t=s.useEditorStore(a=>a.isShowingVisual),n=s.useEditorStore(a=>a.actions.setIsShowingVisual);return e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(s.Label,{htmlFor:"visualize",children:"Chart"}),e.jsx(s.SmallSwitch,{checked:t,onCheckedChange:()=>n(!t),id:"visualize",className:"data-[state=checked]:bg-foreground/50"})]})}function Vt({options:t,value:n,onValueChange:a}){return e.jsx(s.RadioGroup,{value:n,onValueChange:a,className:"flex gap-4",defaultValue:t[0].value,children:t.map(r=>e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(s.RadioGroupItem,{value:r.value,id:r.value}),e.jsx("label",{className:"text-sm",htmlFor:r.value,children:r.label})]},r.value))})}function te({label:t,options:n,value:a,onValueChange:r,className:o}){return e.jsxs(s.Select,{value:a,onValueChange:r,children:[e.jsx(s.SelectTrigger,{className:s.cn("w-full focus:ring-0 focus:ring-offset-0",o),children:e.jsx(s.SelectValue,{placeholder:t})}),e.jsx(s.SelectContent,{children:e.jsxs(s.SelectGroup,{children:[e.jsx(s.SelectLabel,{children:t}),n.map(i=>e.jsx(s.SelectItem,{value:i.value,children:i.label},i.value))]})})]})}function xe({children:t,summary:n,open:a,className:r}){return e.jsxs("details",{open:a,className:s.cn("space-y-4 [&_summary>svg]:open:-rotate-180",r),children:[e.jsxs("summary",{className:"flex cursor-pointer list-none items-center justify-between gap-4",children:[e.jsx(s.Label,{children:n}),e.jsx(s.ChevronUp,{className:"h-4 w-4"})]}),e.jsx("div",{className:"transition-all ease-in-out",children:t})]})}function qt(){var j,y;const t=s.useEditorStore(b=>b.card.customCardPreferences),{data:n}=hs(),a=(n==null?void 0:n.plugins)||[],r=s.useEditorStore(b=>b.card),o=s.useEditorStore(b=>b.frame),i=(t==null?void 0:t.visualType)||"single",{setCustomCardPreferences:c}=s.useEditorActions(),{components:l,manifest:d}=s.useCustomVisual((t==null?void 0:t.url)||""),x=(j=d==null?void 0:d.visuals)==null?void 0:j.find(b=>b.name===(t==null?void 0:t.componentName));function h(b,E){if(!t)return;const D={...(t==null?void 0:t.dataInputCardIds)||{},[b]:{cardId:E,hookRef:null}};c({...t,dataInputCardIds:D})}function p(b){var v,D;const E=(v=o==null?void 0:o.cards)==null?void 0:v.filter(T=>{var z;return((z=T==null?void 0:T.customCardPreferences)==null?void 0:z.visualType)!=="multiple"}).map(T=>({value:T.id,label:T.tabTitle||T.title}));return e.jsx("div",{className:"space-y-2",children:(D=b==null?void 0:b.dataInputs)==null?void 0:D.map((T,z)=>{var q,V;return e.jsxs("div",{className:"grid grid-cols-10 gap-2",children:[e.jsx("div",{className:"col-span-4 flex items-center",children:T}),e.jsx(te,{className:"col-span-6 h-8 w-full justify-between",label:"",options:E||[],value:((V=(q=t==null?void 0:t.dataInputCardIds)==null?void 0:q[z])==null?void 0:V.cardId)||"",onValueChange:_=>h(z,_)})]},z+Math.random())})})}function f(b,E,v=[]){var D,T;return t?b==="input"?e.jsx(s.Input,{className:`h-8 w-full ${s.removeRing}`,value:((D=t==null?void 0:t.settings)==null?void 0:D[E])||"",onChange:z=>{c({...t,settings:{...t==null?void 0:t.settings,[E]:z.target.value}})}},E):b==="select"?e.jsx(te,{className:"h-8 w-full",label:"",options:v,value:((T=t==null?void 0:t.settings)==null?void 0:T[E])||"",onValueChange:z=>{c({...t,settings:{...t==null?void 0:t.settings,[E]:z}})}}):null:null}function u(b){const E=Object.entries((b==null?void 0:b.settings)||{});return e.jsx("div",{className:"space-y-3",children:E.map(([v,D])=>e.jsxs("div",{className:"space-y-2",children:[e.jsx(s.Label,{children:D.title}),f(D.ui,v,D.options)]},v))})}function g(b){t&&c({...t,visualType:b,componentName:""})}return e.jsxs("div",{className:"p-6",children:[e.jsx(xe,{summary:"Plugin Settings",children:e.jsx("div",{className:"space-y-4 text-sm",children:e.jsxs("div",{className:"space-y-4 text-sm",children:[e.jsx("div",{className:"space-y-2",children:e.jsx("div",{className:"px-2",children:e.jsx(te,{className:"h-8 w-full",label:"",options:a,value:(t==null?void 0:t.url)||"",onValueChange:b=>c({...t||{url:"",componentName:""},url:b})})})}),((t==null?void 0:t.type)==="component"||(t==null?void 0:t.type)===void 0)&&e.jsx(Vt,{options:[{value:"single",label:"Single Visual"},{value:"multiple",label:"Multi-Visual"}],value:i,onValueChange:g}),((t==null?void 0:t.type)==="component"||(t==null?void 0:t.type)===void 0)&&t&&e.jsx(e.Fragment,{children:e.jsxs("div",{className:"space-y-2",children:[e.jsx(s.Label,{children:"Component"}),e.jsx("div",{className:"space-y-2 px-2",children:l&&e.jsx(te,{className:"h-8 w-full",label:"",options:(l==null?void 0:l.filter(b=>b.type===i).map(b=>({value:b.name,label:b.name})))||[],value:t.componentName,onValueChange:b=>{console.log("changing value",b),c({...t,componentName:b})}})})]})})]})})}),e.jsx(s.Separator,{className:"my-4"}),((y=r==null?void 0:r.customCardPreferences)==null?void 0:y.componentName)&&e.jsxs(xe,{summary:"Component Settings",children:[x&&x.dataInputs&&e.jsxs("div",{className:"space-y-3",children:[e.jsx(s.Label,{children:"Input Mapping"}),e.jsx("div",{className:"px-2",children:p(x)})]}),x&&x.settings&&e.jsx("div",{className:"space-y-3",children:e.jsx("div",{className:"px-2",children:u(x)})})]})]})}function ie(){const[t,n]=C.useState([]);s.useEditorStore(h=>h.card.cfg);const a=s.useEditorStore(h=>h.card.preferences),{setCardCfg:r,setFilterOnClickColumnIndex:o,setCardPreferences:i}=s.useEditorStore(h=>h.actions),c=s.useEditorStore(h=>h.queryResultColumns);s.useEditorStore(h=>{var p;return(p=h.card.preferences)==null?void 0:p.filterOnClickColumnIndex}),C.useEffect(()=>{c&&n(new Array(c.length).fill(!1))},[c]);function l(h,p){var f,u;p?a!=null&&a.onClickFilter&&((f=a==null?void 0:a.onClickFilter)==null?void 0:f.length)>0?i({...a,onClickFilter:[...a.onClickFilter,{columnIndex:h,expression:""}]}):i({...a,onClickFilter:[{columnIndex:h,expression:""}]}):(i({...a,onClickFilter:(u=a==null?void 0:a.onClickFilter)==null?void 0:u.filter(g=>g.columnIndex!==h)}),n(g=>{const j=[...g];return j[h]=!1,j}))}function d(h,p){var u;const f=(u=a==null?void 0:a.onClickFilter)==null?void 0:u.map(g=>g.columnIndex===h?{...g,expression:p.target.value}:g);i({...a,onClickFilter:f})}function x(h){var p,f,u,g;if(t!=null&&t[h]||(f=(p=a==null?void 0:a.onClickFilter)==null?void 0:p.find(j=>j.columnIndex===h))!=null&&f.expression)return e.jsx(s.Input,{value:(g=(u=a==null?void 0:a.onClickFilter)==null?void 0:u.find(j=>j.columnIndex===h))==null?void 0:g.expression,onChange:j=>d(h,j),type:"text",className:"h-9 w-full font-mono text-xs focus-visible:ring-0 focus-visible:ring-ring focus-visible:ring-offset-0",placeholder:"Expression"})}return e.jsxs("div",{className:"space-y-2",children:[e.jsx(s.Label,{children:"On Click"}),c==null?void 0:c.map((h,p)=>{var f,u;return e.jsx("div",{className:"xbg-red-100 group flex items-center justify-between space-y-2",children:e.jsxs("div",{className:"grow",children:[e.jsxs("div",{className:"flex items-center space-x-2 py-2",children:[e.jsx(s.Checkbox,{checked:!!((f=a==null?void 0:a.onClickFilter)!=null&&f.find(g=>g.columnIndex===p)),onCheckedChange:g=>l(p,g)}),e.jsx("label",{className:"text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70",children:h}),e.jsx("div",{className:"flex items-center gap-2",children:((u=a==null?void 0:a.onClickFilter)==null?void 0:u.find(g=>g.columnIndex===p))&&e.jsx(s.Pencil,{onClick:()=>{n(g=>{const j=[...g];return j[p]=!g[p],j})},className:"invisible size-3 cursor-pointer text-gray-400 group-hover:visible"})})]}),x(p)]})},h)})]})}function Se(){var c,l,d;const t=s.useEditorStore(x=>x.card.preferences),n=s.useEditorStore(x=>x.card.cfg),{setCardCfg:a,setCardPreferences:r,setChartOrientation:o}=s.useEditorStore(x=>x.actions);(c=n==null?void 0:n.options)!=null&&c.indexAxis;function i(x){o(x)}return e.jsxs(s.RadioGroup,{value:((l=t==null?void 0:t.chartOptions)==null?void 0:l.indexAxis)||((d=n==null?void 0:n.options)==null?void 0:d.indexAxis)||"x",onValueChange:i,className:"flex gap-3",defaultValue:"x",children:[e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(s.RadioGroupItem,{value:"x",id:"r1"}),e.jsx("label",{className:"text-sm",htmlFor:"r1",children:"Vertical"})]}),e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(s.RadioGroupItem,{value:"y",id:"r2"}),e.jsx("label",{className:"text-sm",htmlFor:"r2",children:"Horizontal"})]})]})}function Bt({idx:t}){var l;const n=s.useEditorStore(d=>{var x;return(x=d.card)==null?void 0:x.preferences}),a=s.useEditorStore(d=>{var x;return(x=d.card.preferences)==null?void 0:x.datasetOptions}),r=s.useEditorStore(d=>d.actions.setCardPreferences),o=(l=n==null?void 0:n.chartOptions)==null?void 0:l.indexAxis,i=a==null?void 0:a.find(d=>d.idx===t);function c(d,x){(d==="end"||d==="start")&&s.getContrastColor(s.getCanvasBackgroundColor());const h={display:d!=="none",align:d,anchor:d,clamp:!0};if(!i)r({...n,datasetOptions:[...a||[],{idx:x,datalabels:h}]});else{const p={...i};p.datalabels=h;const f=a==null?void 0:a.map(u=>u.idx===x?p:u);r({...n,datasetOptions:f})}}return e.jsxs(s.Popover,{children:[e.jsx(s.PopoverTrigger,{children:e.jsx(Ws,{className:"invisible size-4 rotate-[135deg] cursor-pointer text-muted-foreground hover:text-foreground group-hover:visible"})}),e.jsx(s.PopoverContent,{className:"w-fit p-1",children:e.jsxs("div",{className:"flex gap-1",children:[e.jsx(s.Button,{onClick:()=>c("none",t),size:"sm",variant:"secondary",className:"h-7 p-1 text-xs font-normal",children:e.jsx(s.X,{className:"size-4"})}),e.jsx(s.Button,{onClick:()=>c("start",t),size:"sm",variant:"secondary",className:"h-7 p-1 text-xs font-normal",children:e.jsx(Fs,{className:s.cn("h-4 w-4",{"rotate-90":o==="y"})})}),e.jsx(s.Button,{onClick:()=>c("center",t),size:"sm",variant:"secondary",className:"h-7 p-1 text-xs font-normal",children:e.jsx(Vs,{className:s.cn("h-4 w-4",{"rotate-90":o==="y"})})}),e.jsx(s.Button,{onClick:()=>c("end",t),size:"sm",variant:"secondary",className:"h-7 p-1 text-xs font-normal",children:e.jsx(Rs,{className:s.cn("h-4 w-4",{"rotate-90":o==="y"})})})]})})]})}function ms(){const t=s.useEditorStore(x=>x.card),n=s.useEditorStore(x=>{var h,p,f;return(f=(p=(h=x==null?void 0:x.card)==null?void 0:h.preferences)==null?void 0:p.chartOptions)==null?void 0:f.indexAxis}),{data:a}=s.useDashboardCardQuery(t),r=n==="y"?"Y axis":"X axis",o=n==="y"?"X axis":"Y axis",{keys:i,metricKeys:c,dimensionKeys:l}=s.getKeys((a==null?void 0:a.records)||[]);let d=c;if(["stackedBar","stackedLine"].includes(t.type)){const x=s.pivotData({dataArray:(a==null?void 0:a.records)||[],groupKey:l[0],pivotKey:l[1],valueKey:d[0]}),{metricKeys:h}=s.getKeys(x);d=h}return i.length===0?null:e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(s.Label,{children:r}),e.jsx("div",{className:"my-1 space-y-1",children:e.jsx("div",{className:"rounded-md bg-muted/70 px-3 py-2 hover:bg-muted",children:e.jsx("p",{title:l[0],children:xs(l[0])})})})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(s.Label,{children:o}),e.jsx("div",{className:"my-1 max-h-[125px] space-y-1 overflow-y-auto",children:d.map((x,h)=>e.jsx(Pt,{col:x,idx:h},x))})]})]})}function xs(t,n=30){return t.length>n?t.slice(0,n)+"...":t}function Pt({col:t,idx:n}){const a=s.useEditorStore(l=>{var d;return(d=l.card)==null?void 0:d.preferences}),r=s.useEditorStore(l=>{var d;return(d=l.card.preferences)==null?void 0:d.datasetOptions}),o=r==null?void 0:r.find(l=>l.idx===n),{setCardPreferences:i}=s.useEditorStore(l=>l.actions);function c(l){if(!o)i({...a,datasetOptions:[...r||[],{idx:n,type:l==="area"?"line":l,fill:l==="area"?"origin":""}]});else{const d={...o};d.type=l==="area"?"line":l,d.fill=l==="area"?"origin":"";const x=r==null?void 0:r.map(h=>h.idx===n?d:h);i({...a,datasetOptions:x})}}return e.jsxs("div",{className:"group flex items-center justify-between gap-5 rounded-md bg-muted/70 px-3 py-2 hover:bg-muted",children:[e.jsx("p",{title:t,children:xs(t)}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(we,{onClick:()=>c("bar"),className:"invisible size-4 cursor-pointer text-muted-foreground hover:text-foreground group-hover:visible"}),e.jsx(ke,{onClick:()=>c("line"),className:"invisible size-4 cursor-pointer text-muted-foreground hover:text-foreground group-hover:visible"}),e.jsx(Cs,{onClick:()=>c("area"),className:"invisible size-4 cursor-pointer text-muted-foreground hover:text-foreground group-hover:visible"}),e.jsx(Bt,{idx:n})]})]})}function ps(){const t=s.useEditorStore(u=>u.selectedConnectionId),n=s.useEditorStore(u=>u.selectedDatamodelId),a=s.useEditorStore(u=>u.selectedDatabaseName),r=s.useEditorStore(u=>u.selectedSchemaName),o=s.useEditorStore(u=>u.selectedTableName),i=s.useDashboardStore(u=>u.dashboard.filters)||[],c=s.useDashboardStore(u=>u.actions.addFilter),l=s.useDashboardStore(u=>u.actions.removeFilter),{removeFilterValues:d}=s.useDashboardActions(),{modelItems:x,tableName:h,connectionType:p}=ae();function f(u,g="dashboard"){var q;const j=s.fmt(u.column_name),y=s.fmt(a||""),b=s.fmt(r||""),E=s.fmt(h);let v=s.getQualifiedTableName(b,E,p),D=`${v}.${j}`;const T=(q=x==null?void 0:x.find(V=>V.id===n))==null?void 0:q.name;n&&n!=="none"&&(D=`${s.DATAMODEL_NAMESPCACE}.${T}.${j}`,v=`${s.DATAMODEL_NAMESPCACE}.${T}`);const z=i==null?void 0:i.find(V=>V.column===D&&V.table===E&&(V.database===y||V.database===a));if(z)d(z.id),l(z.id);else{const V=s.v4();return h==="api"&&t?(c({location:g,id:V,column:D,title:u.column_name,dataType:u.data_type,table:"api",database:"",connectionId:t,operation:"in",sql:s.getDefaultFilterSql(u.data_type,v,j)}),V):(c({id:V,location:g,column:D,title:u.column_name,dataType:u.data_type,table:o||"",database:a||"",connectionId:t||"",operation:"in",sql:s.getDefaultFilterSql(u.data_type,v,j)}),V)}}return{assignFilter:f}}function he(){const t=s.useDashboardStore(l=>l.dashboard.filters),n=s.useEditorStore(l=>l.frame),{setFrame:a}=s.useEditorActions(),{columns:r}=ae(),{assignFilter:o}=ps();function i(l){const d=o(l,"frame");a({...n,filterId:d})}const c=t==null?void 0:t.find(l=>l.id===n.filterId);return e.jsxs("div",{className:"space-y-3",children:[e.jsx(s.Label,{children:"Card Filter"}),e.jsx(_t,{onSelect:i,columns:r}),c&&e.jsx(s.FilterHeader,{filter:c})]})}function _t({columns:t,onSelect:n}){var c;const[a,r]=de.useState(!1),[o,i]=de.useState("");return e.jsxs(s.Popover,{open:a,onOpenChange:r,children:[e.jsx(s.PopoverTrigger,{asChild:!0,children:e.jsxs(s.Button,{size:"sm",variant:"outline",role:"combobox","aria-expanded":a,className:"w-full justify-between font-normal",children:[o?(c=t.find(l=>l.column_name===o))==null?void 0:c.column_name:"Select Column...",e.jsx(s.CaretSortIcon,{className:"ml-2 h-4 w-4 shrink-0 opacity-50"})]})}),e.jsx(s.PopoverContent,{className:"w-[200px] p-0",children:e.jsxs(s.Command,{children:[e.jsx(s.CommandInput,{placeholder:"Search column",className:"h-9"}),e.jsxs(s.CommandList,{children:[e.jsx(s.CommandEmpty,{children:"No framework found."}),e.jsx(s.CommandGroup,{children:t.map(l=>e.jsxs(s.CommandItem,{value:l.column_name,onSelect:d=>{const x=d===o?"":d;i(x),r(!1),x&&n(l)},children:[l.column_name,e.jsx(s.CheckIcon,{className:s.cn("ml-auto h-4 w-4",o===l.column_name?"opacity-100":"opacity-0")})]},l.column_name))})]})]})})]})}function Ht({cardType:t}){return e.jsx("div",{className:"space-y-6 px-6 py-2",children:e.jsxs(s.Accordion,{defaultValue:["item-2"],type:"multiple",children:[e.jsxs(s.AccordionItem,{value:"item-1",children:[e.jsx(s.AccordionTrigger,{children:`${s.titleCase(t)} Chart`}),e.jsxs(s.AccordionContent,{className:"space-y-4 font-mono text-xs",children:[e.jsx("div",{className:"rounded bg-muted px-2 py-1 text-xs",children:"SELECT x-axis, y-axis-1, y-axis-2,... FROM table"}),e.jsxs("ul",{className:"ml-6 list-disc text-xs [&>li]:mt-2",children:[e.jsx("li",{children:"x-axis - category"}),e.jsx("li",{children:"y-axis1 - number"}),e.jsx("li",{children:"y-axis2 - number"})]}),e.jsxs("div",{children:["See ",e.jsx("a",{target:"_blank",onClick:n=>n.stopPropagation(),className:"text-blue-700",href:"https://docs.semaphor.cloud/docs/charts/bar-line-area",children:"example"})," in the docs."]})]})]}),e.jsxs(s.AccordionItem,{value:"item-2",children:[e.jsx(s.AccordionTrigger,{children:"Settings"}),e.jsxs(s.AccordionContent,{className:"space-y-4 px-2",children:[e.jsx(Se,{}),e.jsx(ms,{})]})]}),e.jsxs(s.AccordionItem,{value:"item-3",children:[e.jsx(s.AccordionTrigger,{children:"Filters"}),e.jsxs(s.AccordionContent,{className:"space-y-4 px-2",children:[e.jsx(ie,{}),e.jsx(he,{})]})]})]})})}function Ie(){var o,i,c;const t=s.useEditorStore(l=>l.card.cfg),n=s.useEditorStore(l=>l.actions.setCardCfg),a=s.useEditorStore(l=>l.card.type);function r(l){var h;const d={datalabels:{display:l!=="none",align:l,anchor:l,clamp:!0}},x={...t,options:{...t==null?void 0:t.options,plugins:{...(h=t==null?void 0:t.options)==null?void 0:h.plugins,...d}}};n(x),console.log(l)}return e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"font-medium",children:"Data Labels"}),e.jsxs(s.Select,{value:(c=(i=(o=t==null?void 0:t.options)==null?void 0:o.plugins)==null?void 0:i.datalabels)==null?void 0:c.anchor,onValueChange:r,defaultValue:"none",children:[e.jsx(s.SelectTrigger,{className:"h-8 w-full focus:ring-1 focus:ring-offset-0",children:e.jsx(s.SelectValue,{placeholder:"Select position"})}),e.jsx(s.SelectContent,{children:e.jsxs(s.SelectGroup,{children:[e.jsx(s.SelectLabel,{children:"Data Labels"}),e.jsx(s.SelectItem,{value:"none",children:"None"}),a!=="pyramid"&&e.jsx(s.SelectItem,{value:"start",children:"Start"}),e.jsx(s.SelectItem,{value:"center",children:"Center"}),a!=="pyramid"&&e.jsx(s.SelectItem,{value:"end",children:"End"})]})})]})]})}function Gt({cardType:t}){function n(a){return e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"rounded bg-muted px-2 py-1 text-xs",children:a==="bubble"?"SELECT label, [group], x-axis, y-axis, radius FROM table":"SELECT label, [group], x-axis, y-axis FROM table"}),e.jsxs("ul",{className:"ml-6 list-disc text-xs [&>li]:mt-2",children:[e.jsx("li",{children:"label - category"}),e.jsx("li",{children:"group (optional) - category"}),e.jsx("li",{children:"x-axis - number"}),e.jsx("li",{children:"y-axis - number"}),a==="bubble"&&e.jsx("li",{children:"radius - number"})]}),e.jsxs("div",{children:["See ",e.jsx("a",{target:"_blank",onClick:i=>i.stopPropagation(),className:"text-blue-700",href:"https://docs.semaphor.cloud/docs/charts/bubble",children:"example"})," in the docs."]})]})}return e.jsx("div",{className:"space-y-6 px-6 py-2",children:e.jsxs(s.Accordion,{defaultValue:["item-2"],type:"multiple",children:[e.jsxs(s.AccordionItem,{value:"item-1",children:[e.jsx(s.AccordionTrigger,{children:`${s.titleCase(t)} Chart`}),e.jsx(s.AccordionContent,{className:"space-y-4 font-mono text-xs",children:n(t)})]}),e.jsxs(s.AccordionItem,{value:"item-2",children:[e.jsx(s.AccordionTrigger,{children:"Settings"}),e.jsx(s.AccordionContent,{className:"px-2",children:e.jsx(Ie,{})})]}),e.jsxs(s.AccordionItem,{value:"item-3",children:[e.jsx(s.AccordionTrigger,{children:"Filters"}),e.jsxs(s.AccordionContent,{className:"space-y-4 px-2",children:[e.jsx(ie,{}),e.jsx(he,{})]})]})]})})}const $t={datasets:[{type:"line",label:"Sum_sales",data:[]},{type:"bar",label:"Sum_profit",data:[]}]},Ut={datasets:[{fill:"origin",type:"line",label:"Sum_sales",data:[]}]};function Qt(){const t=s.useEditorStore(n=>n.card.type);return e.jsxs("div",{className:"space-y-6 p-6",children:[e.jsx(s.Accordion,{className:" ",type:"single",collapsible:!0,children:Jt(t)}),e.jsx("section",{className:"",children:["line","bar"].includes(t)&&e.jsx(Se,{})}),!["kpi"].includes(t)&&e.jsxs("div",{className:"space-y-4",children:[e.jsx(Ie,{}),e.jsx(ie,{}),e.jsx(he,{})]})]})}function Jt(t){if(["line","bar"].includes(t))return e.jsxs(e.Fragment,{children:[e.jsxs(s.AccordionItem,{value:"item-1",children:[e.jsx(s.AccordionTrigger,{className:"font-normal",children:e.jsx("p",{children:"Chart Query"})}),e.jsxs(s.AccordionContent,{className:" ",children:[e.jsx("div",{className:"rounded bg-muted px-2 py-1 font-mono text-xs font-semibold",children:"SELECT x-axis, y-axis-1, y-axis-2, y-axis-3,... FROM table"}),e.jsxs("ul",{className:"my-6 ml-6 list-disc text-xs font-normal [&>li]:mt-2",children:[e.jsx("li",{children:"X-axis - Category (ex. city)"}),e.jsx("li",{children:"Y-axis - Number (ex. population)"})]})]})]}),e.jsxs(s.AccordionItem,{value:"item-2",children:[e.jsx(s.AccordionTrigger,{className:"font-normal",children:"Mixed Chart"}),e.jsxs(s.AccordionContent,{className:"space-y-2 text-xs",children:[e.jsxs("p",{children:["Click ",e.jsx("b",{children:"Customize"})," and change the `type` property in the dataset."]}),e.jsx("pre",{children:JSON.stringify($t,null,2)})]})]}),e.jsxs(s.AccordionItem,{value:"item-3",children:[e.jsx(s.AccordionTrigger,{className:"font-normal",children:"Area Chart"}),e.jsxs(s.AccordionContent,{className:"space-y-2 text-xs",children:[e.jsxs("p",{children:["Click ",e.jsx("b",{children:"Customize"})," and add `fill` property to the dataset. See",e.jsx("a",{className:"mx-1 text-blue-500 hover:underline",href:"https://www.chartjs.org/docs/latest/samples/area/line-boundaries.html",target:"_blank",children:"docs"}),"for more options."]}),e.jsx("pre",{children:JSON.stringify(Ut,null,2)})]})]})]});if(t==="bubble")return e.jsx(e.Fragment,{children:e.jsxs(s.AccordionItem,{value:"item-1",children:[e.jsx(s.AccordionTrigger,{className:"font-normal",children:e.jsxs("p",{children:["How to create a ",e.jsx("span",{children:t})," chart query?"]})}),e.jsxs(s.AccordionContent,{className:" ",children:[e.jsx("div",{className:"rounded bg-muted px-2 py-1 font-mono text-xs font-semibold",children:"SELECT label, x-axis, y-axis, radius FROM table"}),e.jsxs("ul",{className:"my-6 ml-6 list-disc text-xs font-normal [&>li]:mt-2",children:[e.jsx("li",{children:"Label - Category (ex. city)"}),e.jsx("li",{children:"Bubble Group (opt) - Category (ex. state)"}),e.jsx("li",{children:"X-axis - Number (ex. avg. age)"}),e.jsx("li",{children:"Y-axis - Number (ex. avg. weight)"}),e.jsx("li",{children:"Radius - Number (ex. population)"})]})]})]})});if(t==="scatter")return e.jsx(e.Fragment,{children:e.jsxs(s.AccordionItem,{value:"item-1",children:[e.jsx(s.AccordionTrigger,{className:"font-normal",children:e.jsxs("p",{children:["How to create a ",e.jsx("span",{children:t})," chart query?"]})}),e.jsxs(s.AccordionContent,{className:" ",children:[e.jsx("div",{className:"rounded bg-muted px-2 py-1 font-mono text-xs font-semibold",children:"SELECT label, x-axis, y-axis FROM table"}),e.jsxs("ul",{className:"my-6 ml-6 list-disc text-xs font-normal [&>li]:mt-2",children:[e.jsx("li",{children:"Label - Category (ex. city)"}),e.jsx("li",{children:"Group (opt) - Category (ex. state)"}),e.jsx("li",{children:"X-axis - Number (ex. avg. age)"}),e.jsx("li",{children:"Y-axis - Number (ex. avg. weight)"})]})]})]})});if(["pie","doughnut","polarArea"].includes(t))return e.jsx(e.Fragment,{children:e.jsxs(s.AccordionItem,{value:"item-1",children:[e.jsx(s.AccordionTrigger,{className:"font-normal",children:e.jsxs("p",{children:[e.jsx("span",{children:t==="polarArea"?"Polar":t.charAt(0).toUpperCase()+t.slice(1)})," ","chart query"]})}),e.jsxs(s.AccordionContent,{className:" ",children:[e.jsx("div",{className:"rounded bg-muted px-2 py-1 font-mono text-xs font-semibold",children:"SELECT label, measure FROM table"}),e.jsxs("ul",{className:"my-6 ml-6 list-disc text-xs font-normal [&>li]:mt-2",children:[e.jsx("li",{children:"Label - Category (ex. city)"}),e.jsx("li",{children:"Measure - Number (ex. population)"})]})]})]})})}function Wt(){var d,x,h,p,f;const t=s.useEditorStore(u=>u.card.preferences),n=s.useEditorStore(u=>u.actions.setCardPreferences),a=s.useEditorStore(u=>u.actions.setNumberFormat);s.useEditorStore(u=>{var g,j;return(j=(g=u.card.preferences)==null?void 0:g.formatNumber)==null?void 0:j.decimalPlaces});const r=s.useEditorStore(u=>{var g,j;return(j=(g=u.card.preferences)==null?void 0:g.formatNumber)==null?void 0:j.locale}),o=s.useEditorStore(u=>{var g,j;return(j=(g=u.card.preferences)==null?void 0:g.formatNumber)==null?void 0:j.currency});s.useEditorStore(u=>u.actions.setFilterOnClickField);const i=s.useEditorStore(u=>{var g,j;return(j=(g=u.card.preferences)==null?void 0:g.formatNumber)==null?void 0:j.colorRanges})||[],c=s.useEditorStore(u=>u.actions.setColorRanges),l=[...new Set(s.LOCALE_CURRENCY_PAIRS.map(u=>u.currency))];return e.jsxs("div",{children:[e.jsxs("div",{className:"mb-3 flex items-center gap-2",children:[e.jsx(s.Checkbox,{checked:!!((d=t==null?void 0:t.formatNumber)!=null&&d.enabled),onCheckedChange:u=>{n({...t,formatNumber:{...t==null?void 0:t.formatNumber,enabled:u}})}}),e.jsx(s.Label,{children:"Format Number"})]}),((x=t==null?void 0:t.formatNumber)==null?void 0:x.enabled)===!0&&e.jsxs("div",{className:"flex flex-col gap-2",children:[e.jsx("div",{children:e.jsxs("div",{className:"space-y-4 p-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("div",{className:"w-full space-y-1",children:[e.jsx(s.Label,{children:"Locale"}),e.jsxs(s.Select,{value:r||"none",onValueChange:u=>{var g,j,y;return a(((g=t==null?void 0:t.formatNumber)==null?void 0:g.decimalPlaces)||0,((j=t==null?void 0:t.formatNumber)==null?void 0:j.currency)||"",u,((y=t==null?void 0:t.formatNumber)==null?void 0:y.suffix)||"")},children:[e.jsx(s.SelectTrigger,{className:"col-span-6 h-8 w-full focus:ring-1 focus:ring-offset-0",children:e.jsx(s.SelectValue,{})}),e.jsx(s.SelectContent,{children:e.jsxs(s.SelectGroup,{children:[e.jsx(s.SelectLabel,{children:"Format"}),e.jsx(s.SelectItem,{value:"none",children:"None"},"none"),s.LOCALE_CURRENCY_PAIRS.map(u=>e.jsx(s.SelectItem,{value:u.locale,children:u.locale},u.locale))]})})]})]}),e.jsxs("div",{className:"w-full space-y-1",children:[e.jsx(s.Label,{children:"Currency"}),e.jsxs(s.Select,{value:o||"none",onValueChange:u=>{var g,j,y;console.log("currency",u),a(((g=t==null?void 0:t.formatNumber)==null?void 0:g.decimalPlaces)||0,u==="none"?"":u,((j=t==null?void 0:t.formatNumber)==null?void 0:j.locale)||"",((y=t==null?void 0:t.formatNumber)==null?void 0:y.suffix)||"")},children:[e.jsx(s.SelectTrigger,{className:"col-span-6 h-8 w-full focus:ring-1 focus:ring-offset-0",children:e.jsx(s.SelectValue,{})}),e.jsx(s.SelectContent,{children:e.jsxs(s.SelectGroup,{children:[e.jsx(s.SelectLabel,{children:"Currency"}),e.jsx(s.SelectItem,{value:"none",children:"None"},"none"),l.map(u=>e.jsx(s.SelectItem,{value:u,children:u},u))]})})]})]})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsxs("div",{className:"w-full space-y-1",children:[e.jsx(s.Label,{children:"Decimals"}),e.jsxs(s.Select,{value:((p=(h=t==null?void 0:t.formatNumber)==null?void 0:h.decimalPlaces)==null?void 0:p.toString())||"0",onValueChange:u=>{var g,j,y;return a(Number(u),((g=t==null?void 0:t.formatNumber)==null?void 0:g.currency)||"",((j=t==null?void 0:t.formatNumber)==null?void 0:j.locale)||"",((y=t==null?void 0:t.formatNumber)==null?void 0:y.suffix)||"")},children:[e.jsx(s.SelectTrigger,{className:"col-span-3 h-8 w-full focus:ring-1 focus:ring-offset-0",children:e.jsx(s.SelectValue,{})}),e.jsx(s.SelectContent,{children:["0","1","2","3","4"].map(u=>e.jsx(s.SelectItem,{value:u,children:u},u))})]})]}),e.jsxs("div",{className:"w-full space-y-1",children:[e.jsx(s.Label,{children:"Suffix"}),e.jsx(s.Input,{value:((f=t==null?void 0:t.formatNumber)==null?void 0:f.suffix)||"",className:"h-8 font-mono text-xs focus-visible:ring-0 focus-visible:ring-ring focus-visible:ring-offset-0",placeholder:"K, M, B, %",onChange:u=>{var g,j,y;return a(((g=t==null?void 0:t.formatNumber)==null?void 0:g.decimalPlaces)||0,((j=t==null?void 0:t.formatNumber)==null?void 0:j.currency)||"",((y=t==null?void 0:t.formatNumber)==null?void 0:y.locale)||"",u.target.value)}})]})]})]})}),e.jsx(s.Separator,{className:"my-3"}),e.jsx(s.ColorFormat,{colorRanges:i,setColorRanges:c})]})]})}function Kt(){return e.jsxs("div",{className:"space-y-6 px-6 py-2",children:[e.jsx(s.Accordion,{type:"single",collapsible:!0,children:e.jsxs(s.AccordionItem,{value:"item-1",children:[e.jsx(s.AccordionTrigger,{className:"",children:"KPI Query"}),e.jsxs(s.AccordionContent,{className:"font-mono",children:[e.jsx("div",{className:"rounded bg-muted px-2 py-1 font-mono text-xs",children:"SELECT current, previous FROM table"}),e.jsxs("ul",{className:"my-6 ml-6 list-disc text-xs [&>li]:mt-2",children:[e.jsx("li",{children:"current - number"}),e.jsx("li",{children:"previous - number"})]}),e.jsxs("div",{children:["See ",e.jsx("a",{target:"_blank",onClick:t=>t.stopPropagation(),className:"text-blue-700",href:"https://docs.semaphor.cloud/docs/charts/kpi",children:"example"})," in the docs."]})]})]})}),e.jsx("section",{className:"",children:e.jsx(Wt,{})}),e.jsx("div",{}),e.jsx("div",{})]})}const Xt=[{label:"Mercator",value:"mercator"},{label:"Azimuthal Equidistant",value:"azimuthalEquidistant"},{label:"Gnomonic",value:"gnomonic"},{label:"Orthographic",value:"orthographic"},{label:"Stereographic",value:"stereographic"},{label:"Equal Earth",value:"equalEarth"},{label:"Albers",value:"albers"},{label:"Albers USA",value:"albersUsa"},{label:"Conic Conformal",value:"conicConformal"},{label:"Conic Equal Area",value:"conicEqualArea"},{label:"Conic Equidistant",value:"conicEquidistant"},{label:"Equirectangular",value:"equirectangular"},{label:"Transverse Mercator",value:"transverseMercator"},{label:"Natural Earth 1",value:"naturalEarth1"}],Zt=["blues","brBG","buGn","buPu","cividis","cool","cubehelixDefault","gnBu","greens","greys","inferno","magma","orRd","oranges","pRGn","piYG","plasma","puBu","puBuGn","puOr","puRd","purples","rainbow","rdBu","rdGy","rdPu","rdYlBu","rdYlGn","reds","sinebow","spectral","turbo","viridis","warm","ylGn","ylGnBu","ylOrBr","ylOrRd"],Yt=Zt.map(t=>({label:t,value:t}));function ea(){var d,x,h,p,f,u,g,j,y,b,E,v,D,T,z,q,V,_;const t=s.useEditorStore(m=>m.card),n=(x=(d=t==null?void 0:t.preferences)==null?void 0:d.mapVisualOptions)==null?void 0:x.topoJsonUrl,[a,r]=C.useState(((p=(h=t==null?void 0:t.preferences)==null?void 0:h.mapVisualOptions)==null?void 0:p.customTopoJsonUrl)||""),{setCardPreferences:o}=s.useEditorActions(),{data:i}=s.useTopoJson(t),c=Object.keys((i==null?void 0:i.objects)||{}).map(m=>({label:m,value:m}))||[],l=[{label:"US States 10m",value:"https://unpkg.com/us-atlas/states-10m.json"},{label:"Countries 50m",value:"https://unpkg.com/world-atlas/countries-50m.json"},{label:"Custom",value:"custom"}];return e.jsxs("div",{className:"p-6",children:[e.jsx(xe,{summary:"Map Chart",children:e.jsx("p",{className:"rounded-md bg-muted p-2 font-mono text-xs",children:"SELECT country, value FROM table"})}),e.jsx(s.Separator,{className:"my-4"}),e.jsx(xe,{open:!0,summary:"Settings",children:e.jsxs("div",{className:"space-y-3 px-2",children:[e.jsx(te,{className:"h-9",options:l,onValueChange:m=>{console.log("value",m),o({...t.preferences,mapVisualOptions:{topoJsonUrl:m}})},value:n||"",label:"Select Map"}),n==="custom"&&e.jsx(s.Input,{onChange:m=>{r(m.target.value)},onBlur:()=>{var m;console.log("onBlur",a),o({...t.preferences,mapVisualOptions:{...(m=t.preferences)==null?void 0:m.mapVisualOptions,customTopoJsonUrl:a}})},value:a,className:`h-9 w-full ${s.removeRing}`,placeholder:"Custom URL"}),i&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx(s.Label,{children:"Map Object"}),e.jsx(te,{className:"h-9",options:c,value:((u=(f=t.preferences)==null?void 0:f.mapVisualOptions)==null?void 0:u.objectKey)||"",label:"Map Object",onValueChange:m=>{var A;o({...t.preferences,mapVisualOptions:{...(A=t.preferences)==null?void 0:A.mapVisualOptions,objectKey:m}})}})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(s.Label,{children:"Projection"}),e.jsx(te,{className:"h-9",options:Xt,value:((j=(g=t.preferences)==null?void 0:g.mapVisualOptions)==null?void 0:j.projection)||"",label:"Projection",onValueChange:m=>{var A;o({...t.preferences,mapVisualOptions:{...(A=t.preferences)==null?void 0:A.mapVisualOptions,projection:m}})}})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(s.Label,{children:"Colors"}),e.jsx(te,{className:"h-9",options:Yt,value:((b=(y=t.preferences)==null?void 0:y.mapVisualOptions)==null?void 0:b.colorScale)||"",label:"Select Color Scale",onValueChange:m=>{var A;o({...t.preferences,mapVisualOptions:{...(A=t.preferences)==null?void 0:A.mapVisualOptions,colorScale:m}})}})]})]})]})}),e.jsx(s.Separator,{className:"my-4"}),e.jsx(xe,{className:"",summary:"Scale Options",children:e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(s.Input,{className:`h-9 w-full ${s.removeRing}`,type:"number",step:.1,value:((v=(E=t.preferences)==null?void 0:E.mapVisualOptions)==null?void 0:v.projectionScale)||1,onChange:m=>{var A;o({...t.preferences,mapVisualOptions:{...(A=t.preferences)==null?void 0:A.mapVisualOptions,projectionScale:Number(m.target.value)}})}}),e.jsx(s.Label,{children:"X"}),e.jsx(s.Input,{className:`h-9 w-full ${s.removeRing}`,type:"number",step:10,value:((z=(T=(D=t.preferences)==null?void 0:D.mapVisualOptions)==null?void 0:T.projectionOffset)==null?void 0:z[0])||0,onChange:m=>{var A,B,O,P;o({...t.preferences,mapVisualOptions:{...(A=t.preferences)==null?void 0:A.mapVisualOptions,projectionOffset:[Number(m.target.value),((P=(O=(B=t.preferences)==null?void 0:B.mapVisualOptions)==null?void 0:O.projectionOffset)==null?void 0:P[1])||0]}})}}),e.jsx(s.Label,{children:"Y"}),e.jsx(s.Input,{className:`h-9 w-full ${s.removeRing}`,type:"number",step:10,value:((_=(V=(q=t.preferences)==null?void 0:q.mapVisualOptions)==null?void 0:V.projectionOffset)==null?void 0:_[1])||0,onChange:m=>{var A,B,O,P;o({...t.preferences,mapVisualOptions:{...(A=t.preferences)==null?void 0:A.mapVisualOptions,projectionOffset:[((P=(O=(B=t.preferences)==null?void 0:B.mapVisualOptions)==null?void 0:O.projectionOffset)==null?void 0:P[0])||0,Number(m.target.value)]}})}})]})}),e.jsx(s.Separator,{className:"my-4"}),e.jsx(ie,{})]})}function sa(){var r;const t=s.useEditorStore(o=>o.card.preferences),{setCardPreferences:n}=s.useEditorStore(o=>o.actions);function a(o){n({...t,textVisualOptions:{...t==null?void 0:t.textVisualOptions,isDynamicText:o==="dynamic"}})}return e.jsxs(s.RadioGroup,{value:(r=t==null?void 0:t.textVisualOptions)!=null&&r.isDynamicText?"dynamic":"static",onValueChange:a,className:"flex gap-3",defaultValue:"x",children:[e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(s.RadioGroupItem,{value:"static",id:"r1"}),e.jsx("label",{className:"text-sm",htmlFor:"r1",children:"Static"})]}),e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(s.RadioGroupItem,{value:"dynamic",id:"r2"}),e.jsx("label",{className:"text-sm",htmlFor:"r2",children:"Dynamic"})]})]})}function je({cardType:t,docContent:n,suffix:a="Chart"}){return e.jsx("div",{className:"space-y-6 px-6 py-2",children:e.jsxs(s.Accordion,{defaultValue:["item-2"],type:"multiple",children:[e.jsxs(s.AccordionItem,{value:"item-1",children:[e.jsx(s.AccordionTrigger,{children:`${s.titleCase(t)} ${a}`}),e.jsx(s.AccordionContent,{children:n||e.jsxs("div",{className:"space-y-4 font-mono text-xs",children:[e.jsx("div",{className:"rounded bg-muted px-2 py-1 text-xs",children:"SELECT label, measure FROM table"}),e.jsxs("ul",{className:"ml-6 list-disc text-xs [&>li]:mt-2",children:[e.jsx("li",{children:"label - category"}),e.jsx("li",{children:"measure - number"})]}),e.jsxs("div",{children:["See ",e.jsx("a",{target:"_blank",onClick:r=>r.stopPropagation(),className:"text-blue-700",href:"https://docs.semaphor.cloud/docs/charts/pie-donut-polar",children:"example"})," in the docs."]})]})})]}),e.jsxs(s.AccordionItem,{value:"item-2",children:[e.jsx(s.AccordionTrigger,{children:"Settings"}),e.jsxs(s.AccordionContent,{className:"space-y-4 px-2",children:[t==="range"&&e.jsx(Se,{}),t!=="text"&&e.jsx(Ie,{}),t==="text"&&e.jsx(sa,{})]})]}),!["range","text"].includes(t)&&e.jsxs(s.AccordionItem,{value:"item-3",children:[e.jsx(s.AccordionTrigger,{children:"Filters"}),e.jsxs(s.AccordionContent,{className:"space-y-4 px-2",children:[e.jsx(ie,{}),e.jsx(he,{})]})]})]})})}function ta(){const t=s.useEditorStore(r=>{var o,i;return(i=(o=r==null?void 0:r.card)==null?void 0:o.preferences)==null?void 0:i.sortChart}),{setSortChart:n}=s.useEditorActions();function a(){return e.jsxs("div",{className:"space-y-2",children:[e.jsx(s.Label,{children:"Sort"}),e.jsx(te,{className:"h-8",label:"Sort Chart",options:[{label:"None",value:"none"},{label:"ASC",value:"asc"},{label:"DESC",value:"desc"}],value:t||"none",onValueChange:r=>{n(r)}})]})}return e.jsx("div",{className:"space-y-6 px-6 py-2",children:e.jsxs(s.Accordion,{defaultValue:["item-2"],type:"multiple",children:[e.jsxs(s.AccordionItem,{value:"item-1",children:[e.jsx(s.AccordionTrigger,{children:"Stacked Chart"}),e.jsxs(s.AccordionContent,{className:"space-y-4 font-mono text-xs",children:[e.jsx("div",{className:"rounded bg-muted px-2 py-1 text-xs",children:"SELECT x-axis, stack-by, y-axis FROM table"}),e.jsxs("ul",{className:"ml-6 list-disc text-xs [&>li]:mt-2",children:[e.jsx("li",{children:"x-axis - category"}),e.jsx("li",{children:"stack by - category"}),e.jsx("li",{children:"y-axis - number"})]}),e.jsxs("div",{children:["See ",e.jsx("a",{target:"_blank",onClick:r=>r.stopPropagation(),className:"text-blue-700",href:"https://docs.semaphor.cloud/docs/charts/stacked",children:"example"})," in the docs."]})]})]}),e.jsxs(s.AccordionItem,{value:"item-2",children:[e.jsx(s.AccordionTrigger,{children:"Settings"}),e.jsxs(s.AccordionContent,{className:"space-y-4 px-2",children:[e.jsx(Se,{}),a(),e.jsx(ms,{})]})]}),e.jsxs(s.AccordionItem,{value:"item-3",children:[e.jsx(s.AccordionTrigger,{children:"Filters"}),e.jsxs(s.AccordionContent,{className:"space-y-4 px-2",children:[e.jsx(ie,{}),e.jsx(he,{})]})]})]})})}function aa({cardType:t="table"}){console.log("cardType",t);const n=s.useEditorStore(o=>{var i;return(i=o.card)==null?void 0:i.preferences}),a=s.useEditorStore(o=>o.actions.setCardPreferences),r=o=>{a({...n,allowDownload:o})};return e.jsxs("div",{className:"space-y-6 px-6 py-2",children:[e.jsx(s.Accordion,{defaultValue:["item-3"],type:"multiple",children:e.jsxs(s.AccordionItem,{value:"item-3",children:[e.jsx(s.AccordionTrigger,{children:"Filters"}),e.jsxs(s.AccordionContent,{className:"space-y-4 px-2",children:[e.jsx(ie,{}),e.jsx(he,{})]})]})}),e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(s.Checkbox,{onCheckedChange:r,id:"allow-download"}),e.jsx("label",{htmlFor:"allow-download",className:"text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70",children:"Allow Download"})]})]})}const na=e.jsxs("div",{className:"space-y-4 font-mono text-xs",children:[e.jsx("div",{className:"rounded bg-muted px-2 py-1 text-xs",children:"SELECT dimension, cohort, metric FROM table"}),e.jsxs("div",{children:["See ",e.jsx("a",{target:"_blank",onClick:t=>t.stopPropagation(),className:"text-blue-700",href:"https://docs.semaphor.cloud/docs/charts/tornado",children:"example"})," in the docs."]})]}),ra=e.jsxs("div",{className:"space-y-4 font-mono text-xs",children:[e.jsx("div",{className:"rounded bg-muted px-2 py-1 text-xs",children:"SELECT y-axis, label, range-from, range-to, range-value FROM table"}),e.jsxs("div",{children:["See ",e.jsx("a",{target:"_blank",onClick:t=>t.stopPropagation(),className:"text-blue-700",href:"https://docs.semaphor.cloud/docs/charts/range",children:"example"})," in the docs."]})]}),oa=e.jsxs("div",{className:"space-y-4 font-mono text-xs",children:[e.jsx("div",{className:"rounded bg-muted px-2 py-1 text-xs",children:"SELECT text FROM table limit 1"}),e.jsxs("div",{children:["See ",e.jsx("a",{target:"_blank",onClick:t=>t.stopPropagation(),className:"text-blue-700",href:"https://docs.semaphor.cloud/docs/charts/text",children:"example"})," in the docs."]})]});function ia(){const t=s.useEditorStore(a=>a.card.type);function n(a){switch(a){case"stackedBar":case"stackedLine":return e.jsx(ta,{});case"pyramid":return e.jsx(je,{docContent:na,cardType:a});case"kpi":return e.jsx(Kt,{});case"line":case"bar":return e.jsx(Ht,{cardType:a});case"range":return e.jsx(je,{docContent:ra,cardType:a});case"pie":case"doughnut":case"polarArea":case"radar":return e.jsx(je,{cardType:a});case"bubble":case"scatter":return e.jsx(Gt,{cardType:a});case"table":return e.jsx(aa,{cardType:a});case"text":return e.jsx(je,{docContent:oa,cardType:a,suffix:"Visual"});case"map":return e.jsx(ea,{});case"custom":return e.jsx(qt,{});default:return e.jsx(Qt,{})}}return e.jsxs(s.ScrollArea,{className:"h-full w-full text-sm",children:[n(t),e.jsx(s.ScrollBar,{orientation:"horizontal"})]})}function la(){const t=C.useRef(null),n=s.useEditorStore(r=>r.isShowingVisual),a=s.useEditorStore(r=>r.showAIDialog);return C.useEffect(()=>{var r,o;a?(r=t.current)==null||r.resize(0):(o=t.current)==null||o.resize(25)},[a]),e.jsxs(s.ResizablePanelGroup,{direction:"vertical",className:"min-h-[250px] min-w-full max-w-lg",children:[e.jsx(s.ResizablePanel,{role:"query-section",className:"flex",minSize:20,defaultSize:40,children:e.jsx(St,{})}),e.jsx(s.ResizableHandle,{withHandle:!0,className:"border"}),e.jsx(s.ResizablePanel,{className:"pb-1",role:"visual-section",minSize:0,defaultSize:60,children:n&&!a?e.jsxs(s.ResizablePanelGroup,{direction:"horizontal",children:[e.jsx(e.Fragment,{children:e.jsx(s.ResizablePanel,{ref:t,className:"flex",defaultSize:25,maxSize:30,children:e.jsx(ia,{})})}),!a&&e.jsx(s.ResizableHandle,{className:"border"}),e.jsx(s.ResizablePanel,{minSize:40,defaultSize:75,maxSize:100,children:e.jsx(qe,{})})]}):e.jsx(qe,{})})]})}const ca=!1,da=[{title:"Write a query for",subtitle:"orders over last 3 months"},{title:"Create a bar chart for",subtitle:"sales by product category"}];function ua(){const t=C.useRef(null),n=C.useRef(null),a=s.useEditorStore(N=>N.showAIDialog),r=C.useRef(a),[o,i]=C.useState(!1),[c,l]=C.useState(ca),[d,x]=C.useState(!1),h=s.useEditorStore(N=>N.actions.setCardSql),p=s.useEditorStore(N=>N.actions.setRunSql),{setShowAIDialog:f}=s.useEditorActions(),{messages:u,setMessages:g,reload:j,input:y,setInput:b,isLoading:E,handleAddCurrentTableToScope:v,removeFromCurrentSelections:D,currentAssitantScope:T,setCurrentAssitantScope:z,handleInputChange:q,handleSubmit:V,stop:_,chatStatus:m,toolStatus:A,llmUsage:B}=rs();C.useEffect(()=>{const N=r.current?"smooth":"auto";r.current=a;const R=setTimeout(()=>{var M;t.current&&(t.current.scroll({top:t.current.scrollHeight,behavior:N}),(M=n.current)==null||M.focus())},50);return()=>clearTimeout(R)},[u,a]);function O(N){h(N),p(!0)}function P(){return e.jsxs(s.DropdownMenu,{children:[e.jsx(s.DropdownMenuTrigger,{asChild:!0,children:e.jsx(s.Button,{className:"h-7 p-2",size:"sm",variant:"ghost",children:e.jsx($e,{className:"size-3.5 text-muted-foreground/70 hover:text-muted-foreground"})})}),e.jsxs(s.DropdownMenuContent,{align:"end",children:[e.jsx(s.DropdownMenuLabel,{children:"Options"}),e.jsx(s.DropdownMenuSeparator,{}),e.jsx(s.DropdownMenuCheckboxItem,{checked:o,onCheckedChange:i,children:"Token Usage"}),e.jsx(s.DropdownMenuCheckboxItem,{checked:c,onCheckedChange:l,children:"Tool Invocations"}),e.jsx(s.DropdownMenuCheckboxItem,{checked:d,onCheckedChange:x,children:"System Message"})]})]})}const S=(y==null?void 0:y.length)===0&&(u==null?void 0:u.filter(N=>N.role==="user").length)===0;return e.jsxs("div",{"data-content":"assistant",className:"flex h-full w-full flex-col justify-between gap-2 px-6 py-4",children:[e.jsxs("div",{"data-contet":"header-section",className:"flex items-start justify-between gap-2",children:[e.jsxs("div",{"data-content":"header",children:[e.jsx("div",{className:"text-lg font-semibold",children:"Assistant"}),T&&T.length>0&&e.jsxs("div",{className:"mt-2 flex flex-wrap items-center gap-2",children:[e.jsx("span",{className:"text-xs text-muted-foreground",children:"Context:"}),T==null?void 0:T.map((N,R)=>e.jsxs("div",{className:"flex items-center gap-2 rounded-md border border-border bg-muted px-2 py-1 text-xs",children:[s.getFormattedTableNameForQuery({schemaName:N.schemaName||"",tableName:N.tableName||"",modelName:N.datamodelName||"",connectionType:N.connectionType||""}),e.jsx("button",{onClick:()=>{D(N)},children:e.jsx(s.X,{className:"size-3 text-muted-foreground hover:text-foreground"})})]},R))]}),(T==null?void 0:T.length)===0&&e.jsxs("div",{className:"mt-2 flex items-center gap-2",children:[e.jsx("span",{className:"text-xs text-muted-foreground",children:"Context: None"}),e.jsxs(s.Button,{className:"h-6 text-xs",size:"sm",variant:"secondary",onClick:v,children:[e.jsx(s.Plus,{className:"mr-2 size-3"}),"Current Table"]})]})]}),e.jsxs("div",{"data-content":"actions",className:"flex items-center",children:[P(),e.jsx(s.Button,{className:"h-7 p-2",size:"sm",variant:"ghost",onClick:()=>{g([]),z([]),j()},children:e.jsx(s.RefreshCcw,{className:"size-3.5 text-muted-foreground"})}),e.jsx(s.Button,{className:"h-7 p-2",size:"sm",variant:"ghost",onClick:()=>{f(!1)},children:e.jsx(s.X,{className:"size-4"})})]})]}),e.jsx(s.CustomScrollArea,{ref:t,className:"flex w-full grow basis-0",children:e.jsxs("div",{className:"space-y-4 py-2 pr-3","data-content":"messages",children:[e.jsx(s.PrintMessages,{messages:u,showTools:c,handleRun:O,showSystemMessage:d}),e.jsx(s.ChatStatus,{status:s.getStatus(m,A),isLoading:E})]})}),S&&e.jsx(s.Placeholders,{placeholders:da}),e.jsx(s.ChatInput,{stop:_,ref:n,setInput:b,input:y,handleInputChange:q,handleSubmit:V,isLoading:E}),B&&o&&e.jsx("div",{className:"flex h-8 items-center justify-between",children:e.jsxs("div",{className:"text-xs text-muted-foreground",children:["Usage: ",B.promptTokens," prompt tokens,"," ",B.completionTokens," completion tokens,"," ",B.totalTokens," total tokens"]})})]})}function ha({authToken:t,onSave:n,onClose:a}){const r=C.useRef(null);s.useDashboardStore(p=>p.themeStyle);const o=s.useEditorStore(p=>p.actions.setOnSave),i=s.useEditorStore(p=>p.actions.setOnClose),c=s.useDashboardStore(p=>p.actions.setAuthToken),l=s.useEditorStore(p=>p.showAIDialog),{setShowAIDialog:d}=s.useEditorActions();C.useEffect(()=>{n&&o(n),a&&i(a)},[n,o,a,i]),C.useEffect(()=>{t&&t.accessToken&&c(t)},[t,c]),C.useEffect(()=>{var p,f;l?((p=r.current)==null||p.resize(40),d(!0)):(d(!1),(f=r.current)==null||f.resize(0))},[l,d]);function x(p){p<1?d(!1):l||d(!0)}function h(){return e.jsxs(s.ResizablePanelGroup,{"data-content":"editor-main",className:"grow",direction:"horizontal",children:[e.jsx(s.ResizablePanel,{className:"min-w-[510px] rounded-none border-x-[1px]",children:e.jsx(la,{})}),e.jsx(s.ResizableHandle,{}),e.jsx(s.ResizablePanel,{ref:r,onResize:x,defaultSize:0,children:e.jsx(ua,{})})]})}return e.jsx(s.ErrorBoundary,{FallbackComponent:s.Fallback,children:e.jsxs("section",{className:"flex h-full grow","data-content":"editor-panel",children:[e.jsx(ss,{}),h()]})})}function ma(){s.useDashboardStore(c=>c.selectedCardId);const t=s.useDashboardStore(c=>c.selectedSheetId),{setIsVisualEditing:n}=s.useDashboardStore(c=>c.actions),a=s.useDashboardStore(c=>c.isVisualEditing),r=s.useDashboardStore(c=>c.actions.updateFrame);function o(c){t&&(r(t,c),n(!1))}function i(){n(!1)}return e.jsx("div",{role:"editor-container",className:s.cn("flex grow",{"max-h-0 overflow-hidden":!a}),children:e.jsx(ha,{onSave:o,onClose:i})})}function xa(){const t=s.useEditorStore(i=>i.selectedDatabaseName),n=s.useEditorStore(i=>i.selectedTableName),a=s.useDashboardStore(i=>i.dashboard.filters)||[],{columns:r}=ae(),{assignFilter:o}=ps();return e.jsx(s.ScrollArea,{className:"flex-1 basis-0 flex-col px-3",children:r==null?void 0:r.map(i=>{const c=a==null?void 0:a.find(l=>l.column===s.fmt(i.column_name)&&l.table===n&&l.database===t);return e.jsx("div",{onClick:()=>o(i),className:s.cn("group flex cursor-pointer items-center justify-between border border-dashed border-background px-3 py-[6px] text-sm transition-colors hover:bg-muted/50",{"bg-muted":c}),children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(es,{column:i}),e.jsx("span",{children:i.column_name})]})},i.column_name)})})}function pa(){s.useDashboardStore(n=>n.showFilters);const t=s.useDashboardStore(n=>n.actions.setShowFilters);return e.jsxs("section",{className:"relative flex min-w-[320px] grow flex-col border-l px-1",children:[e.jsxs("div",{className:"mt-4 flex items-center justify-between gap-2 px-3",children:[e.jsx(s.Label,{className:"px-2 text-lg",children:"Filters"}),e.jsx(s.Button,{onClick:()=>t(!1),className:"h-7 w-7 p-0",variant:"ghost",children:e.jsx(s.Cross2Icon,{})})]}),e.jsx("div",{className:"flex grow",children:e.jsx(ss,{ColumnsComponent:()=>e.jsx(xa,{})})})]})}function fa(){const t=s.useDashboardStore(r=>r.dashboard.filters),n=s.useDashboardStore(r=>r.theme),a=t==null?void 0:t.filter(r=>r.hide);return a!=null&&a.length?e.jsx("div",{className:s.cn("mb-1 flex items-center gap-2 border-y px-0.5 pb-0.5",{"bg-[repeating-linear-gradient(45deg,_#ffffff_0_3px,_#f3f3f3_3px_6px)]":n==="light","bg-[repeating-linear-gradient(45deg,_#18171d_0_3px,_#272729_3px_6px)]":n==="dark"}),children:a==null?void 0:a.map(r=>e.jsxs("div",{className:"flex min-w-[250px] max-w-fit flex-col gap-1 p-2",children:[e.jsx(s.FilterHeader,{filter:r}),e.jsx(s.FilterComponent,{filter:r})]},r.id))}):null}function ga(){const t=s.useDashboardStore(r=>r.showFilters),n=s.useDashboardStore(r=>r.isVisualEditing),a=s.useDashboardStore(r=>r.isDashboardEditing);return e.jsxs("div",{role:"dashboard-plus-main",className:s.cn("",{"max-h-0 overflow-hidden":n,"flex grow overflow-auto":!n}),children:[e.jsxs("section",{className:"flex grow flex-col",children:[a&&e.jsx(fa,{}),e.jsx(s.DashboardTabs,{})]}),t&&e.jsx("div",{role:"filter-aside-container",className:"flex",children:e.jsx(pa,{})})]})}function ja(){const t=s.useDashboardStore(o=>o.dashboard),n=s.useDashboardStore(o=>o.actions.setDashboard),a=s.useDashboardStore(o=>o.showDashboardJSON),r=s.useDashboardStore(o=>o.actions.setShowDashboardJSON);return e.jsxs("div",{className:s.cn("relative p-2",{hidden:!a}),children:[e.jsxs(s.Button,{variant:"secondary",size:"sm",className:"absolute right-2 top-2 z-10 h-8",onClick:()=>r(!1),children:[e.jsx(s.X,{className:"mr-2 h-4 w-4"}),"Close"]}),e.jsx(s.de,{onChange:o=>{if(o)try{JSON.parse(o),n(JSON.parse(o))}catch{}},defaultLanguage:"json",className:"h-[550px] overflow-y-auto",value:JSON.stringify(t,null,2),options:{minimap:{enabled:!1},glyphMargin:!1,wordWrap:"on",scrollbar:{verticalScrollbarSize:0,horizontalScrollbarSize:0},fontSize:12,renderLineHighlight:"none"}})]})}function ba({showControls:t=!1,showFooter:n=!0,...a}){return e.jsx(s.ErrorBoundary,{FallbackComponent:s.Fallback,children:e.jsxs(s.SemaphorContextProvider,{dashboardProps:a,children:[e.jsx(s.$e,{}),e.jsxs(s.UXProvider,{children:[e.jsx(ja,{}),e.jsxs(s.DashboardPanel,{...a,children:[t&&e.jsx(nt,{}),e.jsx(ma,{}),e.jsx(ga,{})]})]})]})})}exports.Dashboard=s.Dashboard;exports.DashboardWC=s.DashboardWC;exports.SemaphorDataProvider=s.SemaphorQueryClient;exports.SemaphorQueryClient=s.SemaphorQueryClient;exports.createSqlGenConfig=s.createSqlGenConfig;exports.fmt=s.fmt;exports.getColumnDataType=s.getColumnDataType;exports.getFilterValueType=s.getFilterValueType;exports.getFormattedTableNameForQuery=s.getFormattedTableNameForQuery;exports.getQualifiedTableName=s.getQualifiedTableName;exports.getSql=s.getSql;exports.invalidateToken=s.invalidateToken;exports.isBooleanDataType=s.isBooleanDataType;exports.isColumnInSqlGen=s.isColumnInSqlGen;exports.isDateDataType=s.isDateDataType;exports.isNumberDataType=s.isNumberDataType;exports.isTextDataType=s.isTextDataType;exports.resolveDataType=s.resolveDataType;exports.resolveDatamodelName=s.resolveDatamodelName;exports.useCard=s.useCard;exports.useDashboardActions=s.useDashboardActions;exports.useDashboardStore=s.useDashboardStore;exports.useDateFilterHook=s.useDateFilterHook;exports.useEditorActions=s.useEditorActions;exports.useEditorStore=s.useEditorStore;exports.useTextFilterHook=s.useTextFilterHook;exports.SelectComponent=ce;exports.Surfboard=ba;exports.cleanCard=Ze;exports.downloadPdf=Ye;exports.getDashbaordStateWithoutData=Ee;exports.useEditorAside=ae;
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { c as R, p as Tt, u as D, a as st, b as Me, d as ta, e as aa, B as L, P as lt, f as na, g as sa, h as la, i as ra, L as U, I as he, j as ia, k as oa, l as ca, m as da, n as ua, o as ha, q as Nn, r as Gt, s as Y, C as ft, t as Cn, v as h, w as Sn, x as wn, y as ma, F as pa, z as et, A as dt, E as Ge, G as Be, H as kn, J as Ue, K as fa, M as ga, N as Je, O as ya, Q as ba, R as xa, S as va, T as Na, U as Ca, V as On, W as Sa, X as me, Y as pe, Z as fe, _ as ge, $ as we, a0 as Se, a1 as Q, a2 as zt, a3 as wa, a4 as ka, a5 as Oa, a6 as Ia, a7 as Ma, a8 as Ne, a9 as In, aa as Mn, ab as Da, ac as Dn, ad as Tn, ae as zn, af as Ta, ag as Ie, ah as Ln, ai as Pe, aj as ut, ak as wt, al as Le, am as _e, an as ke, ao as An, ap as Fn, aq as Vn, ar as Ve, as as se, at as za, au as En, av as gt, aw as qn, ax as Rn, ay as jn, az as Bt, aA as _n, aB as Hn, aC as Pn, aD as kt, aE as $n, aF as $e, aG as tt, aH as xe, aI as at, aJ as Gn, aK as Bn, aL as Un, aM as Jn, aN as Ct, aO as Wn, aP as Ut, aQ as Kn, aR as Jt, aS as Qn, aT as Zn, aU as Xn, aV as Yn, aW as La, aX as es, aY as Lt, aZ as Aa, a_ as ts, a$ as as, b0 as ct, b1 as ns, b2 as ss, b3 as Fa, b4 as ls, b5 as rs, b6 as is, b7 as os, b8 as cs, b9 as yt, ba as Va, bb as ds, bc as Ea, bd as qa, be as Ot, bf as It, bg as us, bh as hs, bi as ms, bj as Ra, bk as bt, bl as Fe, bm as ps, bn as ht, bo as ja, bp as _a, bq as fs, br as gs, bs as ys, bt as bs, bu as xs, bv as Xe, bw as At, bx as vs, by as Ns, bz as Cs, bA as Ss, bB as Wt, bC as Kt, bD as Ha, bE as ws, bF as ks, bG as Ee, bH as ee, bI as te, bJ as Ft, bK as ae, bL as Os, bM as Is, bN as Ms, bO as Ds, bP as Ts, bQ as zs, bR as Ls, bS as As, bT as St, bU as Pa, bV as Fs, bW as Vs, bX as Es, bY as qs, bZ as Rs, b_ as js } from "./chunks/index-
|
|
2
|
-
import { D as Zr, c3 as Xr, c1 as Yr, c1 as ei, c5 as ti, c4 as ai, c6 as ni, c2 as si, b$ as li, c0 as ri } from "./chunks/index-
|
|
1
|
+
import { c as R, p as Tt, u as D, a as st, b as Me, d as ta, e as aa, B as L, P as lt, f as na, g as sa, h as la, i as ra, L as U, I as he, j as ia, k as oa, l as ca, m as da, n as ua, o as ha, q as Nn, r as Gt, s as Y, C as ft, t as Cn, v as h, w as Sn, x as wn, y as ma, F as pa, z as et, A as dt, E as Ge, G as Be, H as kn, J as Ue, K as fa, M as ga, N as Je, O as ya, Q as ba, R as xa, S as va, T as Na, U as Ca, V as On, W as Sa, X as me, Y as pe, Z as fe, _ as ge, $ as we, a0 as Se, a1 as Q, a2 as zt, a3 as wa, a4 as ka, a5 as Oa, a6 as Ia, a7 as Ma, a8 as Ne, a9 as In, aa as Mn, ab as Da, ac as Dn, ad as Tn, ae as zn, af as Ta, ag as Ie, ah as Ln, ai as Pe, aj as ut, ak as wt, al as Le, am as _e, an as ke, ao as An, ap as Fn, aq as Vn, ar as Ve, as as se, at as za, au as En, av as gt, aw as qn, ax as Rn, ay as jn, az as Bt, aA as _n, aB as Hn, aC as Pn, aD as kt, aE as $n, aF as $e, aG as tt, aH as xe, aI as at, aJ as Gn, aK as Bn, aL as Un, aM as Jn, aN as Ct, aO as Wn, aP as Ut, aQ as Kn, aR as Jt, aS as Qn, aT as Zn, aU as Xn, aV as Yn, aW as La, aX as es, aY as Lt, aZ as Aa, a_ as ts, a$ as as, b0 as ct, b1 as ns, b2 as ss, b3 as Fa, b4 as ls, b5 as rs, b6 as is, b7 as os, b8 as cs, b9 as yt, ba as Va, bb as ds, bc as Ea, bd as qa, be as Ot, bf as It, bg as us, bh as hs, bi as ms, bj as Ra, bk as bt, bl as Fe, bm as ps, bn as ht, bo as ja, bp as _a, bq as fs, br as gs, bs as ys, bt as bs, bu as xs, bv as Xe, bw as At, bx as vs, by as Ns, bz as Cs, bA as Ss, bB as Wt, bC as Kt, bD as Ha, bE as ws, bF as ks, bG as Ee, bH as ee, bI as te, bJ as Ft, bK as ae, bL as Os, bM as Is, bN as Ms, bO as Ds, bP as Ts, bQ as zs, bR as Ls, bS as As, bT as St, bU as Pa, bV as Fs, bW as Vs, bX as Es, bY as qs, bZ as Rs, b_ as js } from "./chunks/index-CanpZidr.js";
|
|
2
|
+
import { D as Zr, c3 as Xr, c1 as Yr, c1 as ei, c5 as ti, c4 as ai, c6 as ni, c2 as si, b$ as li, c0 as ri } from "./chunks/index-CanpZidr.js";
|
|
3
3
|
import { jsxs as n, jsx as e, Fragment as ne } from "react/jsx-runtime";
|
|
4
4
|
import * as He from "react";
|
|
5
5
|
import Oe, { useState as P, useMemo as Mt, useEffect as ie, useRef as Ae, useCallback as $a, Suspense as _s } from "react";
|
|
@@ -5942,7 +5942,7 @@ function Ar() {
|
|
|
5942
5942
|
role: "visual-section",
|
|
5943
5943
|
minSize: 0,
|
|
5944
5944
|
defaultSize: 60,
|
|
5945
|
-
children: s ? /* @__PURE__ */ n(tt, { direction: "horizontal", children: [
|
|
5945
|
+
children: s && !a ? /* @__PURE__ */ n(tt, { direction: "horizontal", children: [
|
|
5946
5946
|
/* @__PURE__ */ e(ne, { children: /* @__PURE__ */ e(
|
|
5947
5947
|
xe,
|
|
5948
5948
|
{
|