react-semaphor 0.1.285 → 0.1.286

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (31) hide show
  1. package/dist/chunks/{dashboard-controls-B8f_BKTb.js → dashboard-controls-ItYogy_p.js} +4 -4
  2. package/dist/chunks/{dashboard-controls-DSwmmI8w.js → dashboard-controls-L0PZjJCt.js} +318 -341
  3. package/dist/chunks/{dashboard-filter-controls-button-BqmNXVoa.js → dashboard-filter-controls-button-BBM66Kjx.js} +476 -442
  4. package/dist/chunks/dashboard-filter-controls-button-C0aCuD2T.js +11 -0
  5. package/dist/chunks/{dashboard-json-qT21EDMm.js → dashboard-json-BQ-vAiN1.js} +1 -1
  6. package/dist/chunks/{dashboard-json-D0H5w5WI.js → dashboard-json-DVGKEKGc.js} +1 -1
  7. package/dist/chunks/{dashboard-summary-settings-dialog-BRI5dAfz.js → dashboard-summary-settings-dialog-DlXqW4ur.js} +1 -1
  8. package/dist/chunks/{dashboard-summary-settings-dialog-Mq8T35Qv.js → dashboard-summary-settings-dialog-jRhWndnZ.js} +1 -1
  9. package/dist/chunks/{edit-dashboard-visual-DLpQykTX.js → edit-dashboard-visual-BFIX635s.js} +2 -2
  10. package/dist/chunks/{edit-dashboard-visual-gSIS7RGI.js → edit-dashboard-visual-DOyPqIRy.js} +4 -4
  11. package/dist/chunks/{index-Celt_oJr.js → index-5fuOmhsI.js} +170 -170
  12. package/dist/chunks/{index-r_DA-pny.js → index-BJLFSwZr.js} +10190 -10214
  13. package/dist/chunks/resource-management-panel-DMIhpLZ1.js +933 -0
  14. package/dist/chunks/resource-management-panel-DPJ6MzLA.js +6 -0
  15. package/dist/chunks/{use-create-flow-overlay-state-C1xhazfY.js → use-create-flow-overlay-state-BU00QaON.js} +142 -145
  16. package/dist/chunks/use-create-flow-overlay-state-CvuLpw1f.js +21 -0
  17. package/dist/chunks/{use-visual-utils-CWcTBBvd.js → use-visual-utils-DUV4E_sx.js} +1 -1
  18. package/dist/chunks/{use-visual-utils-CqL5PNOR.js → use-visual-utils-DlwYqcbg.js} +1 -1
  19. package/dist/dashboard/index.cjs +1 -1
  20. package/dist/dashboard/index.js +1 -1
  21. package/dist/index.cjs +1 -1
  22. package/dist/index.js +5 -5
  23. package/dist/style.css +1 -1
  24. package/dist/surfboard/index.cjs +1 -1
  25. package/dist/surfboard/index.js +2 -2
  26. package/dist/types/main.d.ts +18 -2
  27. package/package.json +1 -1
  28. package/dist/chunks/dashboard-filter-controls-button-DXKJ-0iV.js +0 -11
  29. package/dist/chunks/resource-management-panel-Brj3iNyX.js +0 -6
  30. package/dist/chunks/resource-management-panel-DXLca9OX.js +0 -920
  31. package/dist/chunks/use-create-flow-overlay-state-DVyd9L7O.js +0 -21
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const a=require("../chunks/index-Celt_oJr.js"),e=require("../types/index.cjs"),r=require("../chunks/dashboard-summary-settings-dialog-Mq8T35Qv.js");exports.Surfboard=a.DashboardPlus;exports.CONTROL_CARD_DEFAULT_VALUE=e.CONTROL_CARD_DEFAULT_VALUE;exports.EMPTY_SELECTION=e.EMPTY_SELECTION;exports.CalendarPreferencesDialog=r.CalendarPreferencesDialog;exports.DashboardSummarySettingsDialog=r.DashboardSummarySettingsDialog;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const a=require("../chunks/index-5fuOmhsI.js"),e=require("../types/index.cjs"),r=require("../chunks/dashboard-summary-settings-dialog-jRhWndnZ.js");exports.Surfboard=a.DashboardPlus;exports.CONTROL_CARD_DEFAULT_VALUE=e.CONTROL_CARD_DEFAULT_VALUE;exports.EMPTY_SELECTION=e.EMPTY_SELECTION;exports.CalendarPreferencesDialog=r.CalendarPreferencesDialog;exports.DashboardSummarySettingsDialog=r.DashboardSummarySettingsDialog;
@@ -1,6 +1,6 @@
1
- import { a as o } from "../chunks/index-r_DA-pny.js";
1
+ import { a as o } from "../chunks/index-BJLFSwZr.js";
2
2
  import { CONTROL_CARD_DEFAULT_VALUE as s, EMPTY_SELECTION as D } from "../types/index.js";
3
- import { C as m, D as t } from "../chunks/dashboard-summary-settings-dialog-BRI5dAfz.js";
3
+ import { C as m, D as t } from "../chunks/dashboard-summary-settings-dialog-DlXqW4ur.js";
4
4
  export {
5
5
  s as CONTROL_CARD_DEFAULT_VALUE,
6
6
  m as CalendarPreferencesDialog,
@@ -304,11 +304,26 @@ declare type AddFrameOptions = {
304
304
  copyLayoutFromFrameId?: string;
305
305
  };
306
306
 
307
- export declare function AdvancedModeToggle({ className, switchClassName, }: AdvancedModeToggleProps): JSX.Element | null;
307
+ /**
308
+ * Segmented control that flips the editor between Drag-and-drop and SQL
309
+ * modes. Replaces the earlier single-switch toggle — two labeled buttons
310
+ * read more clearly than a toggle whose state requires translating an
311
+ * icon.
312
+ *
313
+ * Layout matches the Filter split-button: a bordered shell with two
314
+ * ghost-button segments inside. The active segment gets a muted fill;
315
+ * the inactive segment is transparent so the surface behind shows
316
+ * through.
317
+ */
318
+ export declare function AdvancedModeToggle({ className }: AdvancedModeToggleProps): JSX.Element | null;
308
319
 
309
320
  declare interface AdvancedModeToggleProps {
321
+ /** @deprecated Kept for API compatibility; the segmented control
322
+ * handles its own layout. */
310
323
  className?: string;
324
+ /** @deprecated The old DevModeSwitch prop has no analogue here. */
311
325
  labelClassName?: string;
326
+ /** @deprecated The old DevModeSwitch prop has no analogue here. */
312
327
  switchClassName?: string;
313
328
  }
314
329
 
@@ -5440,9 +5455,10 @@ export declare type VisualDisplayPreferences = {
5440
5455
  };
5441
5456
  };
5442
5457
 
5443
- export declare function VisualEditingControls({ className, }: VisualEditingControlsProps): JSX.Element;
5458
+ export declare function VisualEditingControls(_props?: VisualEditingControlsProps): JSX.Element;
5444
5459
 
5445
5460
  declare interface VisualEditingControlsProps {
5461
+ /** @deprecated Buttons self-size via `size="xs"`; prop is ignored. */
5446
5462
  className?: string;
5447
5463
  }
5448
5464
 
package/package.json CHANGED
@@ -5,7 +5,7 @@
5
5
  "email": "support@semaphor.cloud"
6
6
  },
7
7
  "license": "MIT",
8
- "version": "0.1.285",
8
+ "version": "0.1.286",
9
9
  "description": "Fully interactive and customizable dashboards for your apps.",
10
10
  "keywords": [
11
11
  "react",
@@ -1,11 +0,0 @@
1
- "use strict";const v=require("react"),e=require("./index-Celt_oJr.js"),t=require("react/jsx-runtime"),I=require("./use-create-flow-overlay-state-DVyd9L7O.js"),k=require("./use-visual-utils-CWcTBBvd.js"),L=require("./date-formatter-CqXdM6JO.js");/**
2
- * @license lucide-react v0.453.0 - ISC
3
- *
4
- * This source code is licensed under the ISC license.
5
- * See the LICENSE file in the root directory of this source tree.
6
- */const T=e.createLucideIcon("FileDown",[["path",{d:"M15 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V7Z",key:"1rqfz7"}],["path",{d:"M14 2v4a2 2 0 0 0 2 2h4",key:"tnqrlb"}],["path",{d:"M12 18v-6",key:"17g6i2"}],["path",{d:"m9 15 3 3 3-3",key:"1npd3o"}]]);/**
7
- * @license lucide-react v0.453.0 - ISC
8
- *
9
- * This source code is licensed under the ISC license.
10
- * See the LICENSE file in the root directory of this source tree.
11
- */const P=e.createLucideIcon("FilterX",[["path",{d:"M13.013 3H2l8 9.46V19l4 2v-8.54l.9-1.055",key:"1fi1da"}],["path",{d:"m22 3-5 5",key:"12jva0"}],["path",{d:"m17 3 5 5",key:"k36vhe"}]]),V=1e4,z=15e3,O=3e4,R=3e4,$=12e4,M=2*60*60*1e3;function H(s){const r=Date.now()-s.getTime();return r<R?V:r<$?z:O}function q(){const{authToken:s,tokenProps:r}=e.useSemaphorContext(),p=e.useExportStore(m=>m.activeExports),[c,d]=v.useState(typeof document<"u"?!document.hidden:!0),u=v.useRef(null),n=v.useRef(!1),l=v.useRef(void 0),h=r==null?void 0:r.apiServiceUrl,o=s==null?void 0:s.accessToken,f=v.useCallback(()=>{const m=e.useExportStore.getState().activeExports;return Array.from(m.values()).filter(C=>e.isExportInProgress(C.status))},[]);v.useEffect(()=>{if(typeof document>"u")return;const m=()=>{d(!document.hidden)};return document.addEventListener("visibilitychange",m),()=>{document.removeEventListener("visibilitychange",m)}},[]);const b=v.useCallback(async()=>{if(!h||!o){n.current=!1;return}const m=f();if(m.length===0){n.current=!1;return}const C=Date.now(),D=m.filter(a=>C-a.startedAt.getTime()>M);if(D.length>0){const{updateExport:a}=e.useExportStore.getState().actions;for(const i of D)a(i.id,{status:"failed",error:"Export timed out. Please try again or contact support.",lastUpdatedAt:new Date})}const x=m.filter(a=>C-a.startedAt.getTime()<=M);if(x.length===0){n.current=!1;return}const j=await Promise.allSettled(x.map(async a=>{try{const i=await e.getExportStatus(h,o,a.id);let g;if(i.status==="completed")try{g=await e.getDownloadUrl(h,o,a.id)}catch(A){console.error(`[useExportPolling] Failed to get download URL for ${a.id}:`,A)}return{id:a.id,status:i.status,progress:i.progress,completedChunks:i.completedChunks,completedAt:i.completedAt?new Date(i.completedAt):void 0,lastUpdatedAt:new Date,fileSize:i.fileSize,error:i.error,downloadUrl:g}}catch(i){return console.error(`[useExportPolling] Failed to poll export ${a.id}:`,i),null}})),{updateExport:N}=e.useExportStore.getState().actions;for(const a of j)a.status==="fulfilled"&&a.value&&N(a.value.id,a.value);const w=f();if(w.length>0&&!document.hidden){const a=w.reduce((g,A)=>A.startedAt<g?A.startedAt:g,w[0].startedAt),i=H(a);u.current&&clearTimeout(u.current),u.current=setTimeout(()=>{var g;(g=l.current)==null||g.call(l)},i)}else n.current=!1},[h,o,f]);return v.useEffect(()=>{l.current=b},[b]),v.useEffect(()=>{var C;f().length>0&&c&&!n.current&&(n.current=!0,(C=l.current)==null||C.call(l))},[p,c,f]),v.useEffect(()=>{var C;const m=f();c&&m.length>0&&!n.current&&(n.current=!0,(C=l.current)==null||C.call(l))},[c,f]),v.useEffect(()=>{!c&&u.current&&(clearTimeout(u.current),u.current=null,n.current=!1)},[c]),v.useEffect(()=>()=>{u.current&&(clearTimeout(u.current),u.current=null)},[]),{isPolling:n.current,isTabVisible:c,inProgressCount:f().length}}function _(){const{authToken:s,tokenProps:r}=e.useSemaphorContext(),p=e.useExportStore(l=>l.activeExports),{addExport:c}=e.useExportActions(),d=v.useRef(!1),u=r==null?void 0:r.apiServiceUrl,n=s==null?void 0:s.accessToken;v.useEffect(()=>{if(d.current||!u||!n)return;(async()=>{try{const{exports:h}=await e.getExports(u,n,{status:["pending","processing","chunking","compacting","completed","failed"],limit:20});for(const o of h){if(p.has(o.id))continue;const f=o.totalChunks?Math.round(o.completedChunks/o.totalChunks*100):0;let b;if(o.status==="completed")try{b=await e.getDownloadUrl(u,n,o.id)}catch(C){console.error(`[useExportRecovery] Failed to get download URL for ${o.id}:`,C)}const m={id:o.id,status:o.status,progress:f,title:X(o),totalRows:o.totalRows,totalChunks:o.totalChunks,completedChunks:o.completedChunks,startedAt:new Date(o.createdAt),lastUpdatedAt:new Date,completedAt:o.completedAt?new Date(o.completedAt):void 0,fileSize:o.fileSize,error:o.error,expiresAt:new Date(o.expiresAt),downloadUrl:b};c(m)}d.current=!0}catch(h){console.error("[useExportRecovery] Failed to recover exports:",h),d.current=!0}})()},[u,n,c,p])}function X(s){return s.title?s.title:e.isExportInProgress(s.status)?"Export in progress...":s.status==="completed"?"Export completed":s.status==="failed"?"Export failed":"Export"}function G({open:s,onOpenChange:r,isLibraryVisual:p,currentVisualName:c,isSaving:d=!1,destinationMode:u="both",onConfirm:n}){const[l,h]=v.useState(p&&c?`Copy of ${c}`:c||""),[o,f]=v.useState("");v.useEffect(()=>{s&&(h(p&&c?`Copy of ${c}`:c||""),f(""))},[s,p,c]);const b=!!l.trim(),m=u==="local"?{saveToLibrary:!1,saveToCurrentDashboard:!0,badgeType:"local",description:"Creates a local copy on the current dashboard.",actionLabel:"Add to Dashboard (Local)"}:u==="library"?{saveToLibrary:!0,saveToCurrentDashboard:!1,badgeType:"library",description:"Creates a reusable visual in Visual Library.",actionLabel:"Save as Library Visual"}:{saveToLibrary:!0,saveToCurrentDashboard:!0,badgeType:"linked",description:"Creates a new library visual and adds a linked copy to this dashboard.",actionLabel:"Save Copy as Linked Visual"},C=()=>{!b||d||n({name:l.trim(),description:o.trim()||void 0,saveToLibrary:m.saveToLibrary,saveToCurrentDashboard:m.saveToCurrentDashboard})};return t.jsx(e.Dialog,{open:s,onOpenChange:r,children:t.jsxs(e.DialogContent,{className:"sm:max-w-[500px]",children:[t.jsxs(e.DialogHeader,{children:[t.jsxs(e.DialogTitle,{className:"flex items-center gap-2",children:[t.jsx("span",{children:"Save Visual As"}),m.badgeType!=="local"&&t.jsx(I.VisualBadge,{type:m.badgeType,showLabel:!0,className:"px-2 py-0.5"})]}),t.jsx(e.DialogDescription,{children:m.description})]}),t.jsxs("div",{className:"grid gap-4 py-4",children:[t.jsxs("div",{className:"grid gap-2",children:[t.jsx(e.Label,{htmlFor:"name",children:"Name"}),t.jsx(e.Input,{id:"name",value:l,onChange:D=>h(D.target.value),placeholder:"Enter visual name",disabled:d})]}),t.jsxs("div",{className:"grid gap-2",children:[t.jsx(e.Label,{htmlFor:"description",children:"Description (optional)"}),t.jsx(e.Textarea,{id:"description",value:o,onChange:D=>f(D.target.value),placeholder:"Enter visual description",rows:3,disabled:d})]})]}),t.jsxs(e.DialogFooter,{children:[t.jsx(e.Button,{variant:"outline",onClick:()=>r(!1),disabled:d,children:"Cancel"}),t.jsxs(e.Button,{onClick:C,disabled:!b||d,children:[d&&t.jsx(e.LoaderCircle,{className:"mr-2 h-4 w-4 animate-spin"}),m.actionLabel]})]})]})})}function K(){const[s,r]=v.useState(!1),[p,c]=v.useState(!1),[d,u]=v.useState(null),n=e.useEditorStore(i=>i.frame),l=e.useEditorStore(i=>i.card),h=e.useSelectedVisual(),o=e.useDashboardStore(i=>i.selectedSheetId),f=e.useDashboardStore(i=>i.actions.setIsDashboardPanelOpen),{getUpdatedFrame:b}=k.useVisualUtils(),{selectVisual:m}=e.useManagementActions(),{addFrame:C,setSelectedFrameId:D,setIsVisualEditing:x}=e.useDashboardActions(),j=!!(n!=null&&n.visualId),N=(()=>{var i,g;return((i=n==null?void 0:n.cards)==null?void 0:i.length)===1&&((g=n.cards[0])!=null&&g.title)?n.cards[0].title:h!=null&&h.title?h.title:(l==null?void 0:l.title)||"Untitled Visual"})(),w=e.useCreateVisualWithFrame(i=>{if(i!=null&&i.id){if(m(i),p&&d&&o){const g={...d,id:e.v4(),visualId:i.id};C(o,g,"end"),D(g.id),c(!1),u(null),x(!1)}f(!0),r(!1)}});return{saveAsDialogOpen:s,setSaveAsDialogOpen:r,handleSaveAs:async i=>{if(!o){e.ue.error("No sheet selected");return}const g=b(),A=e.getDynamicFrameSaveIssue(g);if(A){e.ue.error(A);return}const E=g.cards.length===1?{...g,cards:g.cards.map(y=>({...y,title:i.name}))}:g;if(i.saveToLibrary){c(i.saveToCurrentDashboard),u(E);const y={title:i.name,description:i.description,frameObject:E,isPrivate:!1};w.mutate(y)}else if(i.saveToCurrentDashboard){const y={...E,id:e.v4(),visualId:void 0};C(o,y,"end"),D(y.id),e.ue.success("Visual saved to dashboard"),r(!1),x(!1)}},isLibraryVisual:j,currentVisualName:N,isSaving:w.isPending}}function W({className:s}){const r=e.useEditorStore(S=>S.frame),p=e.useManagementStore(S=>S.selectedVisual),c=e.useDashboardStore(S=>S.selectedFrameId),d=e.useDashboardStore(S=>S.selectedSheetId),{setIsVisualEditing:u,updateFrame:n}=e.useDashboardActions(),[l,h]=v.useState(!1),[o,f]=v.useState("both"),b=!!(r!=null&&r.visualId||p!=null&&p.id),m=!!(r!=null&&r.visualId&&c),C=b&&!m,{saveAsDialogOpen:D,setSaveAsDialogOpen:x,handleSaveAs:j,isLibraryVisual:N,currentVisualName:w,isSaving:a}=K(),{getUpdatedFrame:i}=k.useVisualUtils(),g=()=>{if(!d){e.ue.error("No sheet selected");return}if(l)return;h(!0);const S=i(),E=e.getDynamicFrameSaveIssue(S);if(E){h(!1),e.ue.error(E);return}const y={...S,visualId:void 0};n(d,y),setTimeout(()=>{h(!1),e.ue.success("Changes applied. Visual is now local to this dashboard"),u(!1)},300)},A=S=>{f(S),x(!0)};return t.jsxs(t.Fragment,{children:[t.jsxs("div",{className:"inline-flex items-center overflow-hidden rounded-md border border-input",children:[!b&&t.jsx(I.EditorAcceptButton,{className:e.cn(s,"rounded-none border-0"),variant:"default"}),b&&C&&t.jsx(I.VisualSaveButton,{className:e.cn(s,"rounded-none border-0"),variant:"default"}),b&&m&&t.jsx(I.VisualSaveAndApplyButton,{className:e.cn(s,"rounded-none border-0")}),t.jsxs(e.DropdownMenu,{modal:!1,children:[t.jsx(e.DropdownMenuTrigger,{className:"h-8",asChild:!0,children:t.jsx(e.Button,{variant:"default",size:"sm",className:e.cn(s,"w-8 rounded-none border-0 border-l border-primary-foreground/30 px-2"),"aria-label":"Open visual save options",disabled:a||l,children:t.jsx(e.ChevronDown,{className:"h-4 w-4"})})}),t.jsxs(e.DropdownMenuContent,{align:"end",children:[m&&t.jsxs(t.Fragment,{children:[t.jsxs(e.DropdownMenuItem,{onClick:g,disabled:l,children:[t.jsx(e.Check,{className:"mr-2 h-4 w-4"}),l?"Applying...":"Apply Locally"]}),t.jsx(e.DropdownMenuSeparator,{})]}),t.jsxs(e.DropdownMenuItem,{onClick:()=>A("local"),disabled:a,children:[t.jsx(e.Plus,{className:"mr-2 h-4 w-4"}),"Add to Dashboard (Local)"]}),t.jsxs(e.DropdownMenuItem,{onClick:()=>A("library"),disabled:a,children:[t.jsx(I.Library,{className:"mr-2 h-4 w-4"}),"Save as Library Visual"]}),t.jsxs(e.DropdownMenuItem,{onClick:()=>A("both"),disabled:a,children:[t.jsx(I.Link2,{className:"mr-2 h-4 w-4"}),"Save Copy as Linked Visual"]})]})]})]}),t.jsx(I.EditorCancelButton,{className:s}),t.jsx(G,{open:D,onOpenChange:S=>{a||x(S)},isLibraryVisual:N,currentVisualName:w,isSaving:a,destinationMode:o,onConfirm:j})]})}function Q({className:s,switchClassName:r}){const p=e.useEditorStore(l=>l.isDevMode),c=e.useDashboardStore(l=>l.isVisualEditing),{setIsDevMode:d}=e.useEditorActions(),{config:u}=v.useContext(e.SemaphorContext).tokenProps,n=(u==null?void 0:u.showAdvancedMode)!==!1;return!c||!n?null:t.jsxs("div",{className:e.cn("flex items-center space-x-2",s),children:[t.jsx(e.DevModeSwitch,{className:e.cn("",r),checked:p,onCheckedChange:()=>d(!p),id:"advanced-mode",icon:t.jsx(e.CodeXml,{className:"h-4 w-4"}),tooltip:"Advanced Mode"}),t.jsx("label",{htmlFor:"advanced-mode",className:"sr-only",children:"Advanced Mode"})]})}function Y({open:s,onOpenChange:r,onSave:p,onDiscard:c,isSaving:d,title:u="Unsaved changes",description:n="You have unsaved changes to this dashboard. What would you like to do?",cancelLabel:l="Cancel",discardLabel:h="Discard",saveLabel:o="Save"}){const f=b=>{!b&&d||r(b)};return t.jsx(e.AlertDialog,{open:s,onOpenChange:f,children:t.jsxs(e.AlertDialogContent,{children:[t.jsxs(e.AlertDialogHeader,{children:[t.jsx(e.AlertDialogTitle,{children:u}),t.jsx(e.AlertDialogDescription,{children:n})]}),t.jsxs(e.AlertDialogFooter,{children:[t.jsx(e.Button,{type:"button",size:"xs",onClick:c,disabled:d,variant:"ghost",className:"mr-auto text-muted-foreground hover:bg-destructive/10 hover:text-destructive focus-visible:bg-destructive/10 focus-visible:text-destructive",children:h}),t.jsx(e.AlertDialogCancel,{disabled:d,children:l}),t.jsx(e.Button,{type:"button",size:"xs",onClick:p,disabled:d,children:d?t.jsxs(t.Fragment,{children:[t.jsx(e.LoaderCircle,{className:"mr-2 h-3.5 w-3.5 animate-spin"}),"Saving..."]}):o})]})]})})}function Z(s,r,p,c){v.useEffect(()=>{s&&!p&&r&&c(e.cloneDeep(r))},[s,p,r,c])}function U({export:s,onRemove:r}){const p=()=>{s.downloadUrl&&window.open(s.downloadUrl,"_blank")},c=l=>{l.stopPropagation(),r==null||r(s.id)},d=()=>{switch(s.status){case"completed":return t.jsx(e.CircleCheck,{className:"mt-0.5 h-5 w-5 shrink-0 text-green-600"});case"failed":return t.jsx(I.CircleX,{className:"mt-0.5 h-5 w-5 shrink-0 text-destructive"});default:return t.jsx(e.LoaderCircle,{className:"text-foreground-muted mt-0.5 h-5 w-5 shrink-0 animate-spin"})}},u=e.isExportInProgress(s.status),n=(()=>{switch(s.status){case"pending":return"Queued...";case"processing":return"Processing...";case"chunking":return"Processing...";case"compacting":return"Finalizing...";default:return"Processing..."}})();return t.jsxs("div",{className:"group p-4 transition-colors hover:bg-muted/50",children:[t.jsxs("div",{className:"mb-2 flex items-start justify-between gap-3",children:[t.jsxs("div",{className:"flex min-w-0 flex-1 items-start gap-3",children:[d(),t.jsxs("div",{className:"min-w-0 flex-1",children:[t.jsx("h4",{className:"mb-1 truncate text-sm font-medium",children:s.title}),s.status==="completed"&&t.jsxs("div",{className:"flex items-center gap-2 text-xs text-muted-foreground",children:[t.jsxs("span",{children:[s.totalRows.toLocaleString()," rows"]}),s.fileSize&&t.jsxs(t.Fragment,{children:[t.jsx("span",{children:"•"}),t.jsx("span",{children:e.formatFileSize(s.fileSize)})]})]}),u&&t.jsx("div",{className:"text-xs text-muted-foreground",children:n}),s.status==="failed"&&t.jsx("div",{className:"line-clamp-2 text-xs text-destructive",children:s.error||"Export failed"})]})]}),t.jsx(e.Button,{variant:"ghost",size:"icon",className:"h-6 w-6 shrink-0 opacity-0 transition-opacity group-hover:opacity-100",onClick:c,"aria-label":"Remove notification",children:t.jsx(e.X,{className:"h-4 w-4"})})]}),t.jsxs("div",{className:"ml-8",children:[s.status==="completed"&&t.jsxs("div",{className:"flex items-center justify-between",children:[t.jsx("span",{className:"text-xs text-muted-foreground",children:L.formatDistanceToNow(s.startedAt,{addSuffix:!0})}),s.downloadUrl&&t.jsxs(e.Button,{size:"sm",variant:"outline",className:"h-8 bg-transparent",onClick:p,children:[t.jsx(e.Download,{className:"mr-1.5 h-3.5 w-3.5"}),"Download"]})]}),u&&t.jsxs("div",{children:[t.jsx(e.Progress,{value:s.progress,className:"h-1.5"}),t.jsxs("span",{className:"mt-1 block text-xs text-muted-foreground",children:[s.progress,"% complete"]})]}),s.status==="failed"&&t.jsx("span",{className:"text-xs text-muted-foreground",children:L.formatDistanceToNow(s.startedAt,{addSuffix:!0})})]})]})}function B(){const{authToken:s,tokenProps:r}=e.useSemaphorContext(),p=e.useExportStore(x=>x.activeExports),{clearCompleted:c,removeExport:d,updateExport:u}=e.useExportActions(),[n,l]=v.useState(!1),[h,o]=v.useState(!1),f=Array.from(p.values()).sort((x,j)=>j.startedAt.getTime()-x.startedAt.getTime()),b=f.some(x=>x.status==="completed"||x.status==="failed"),m=v.useCallback(async()=>{const x=r==null?void 0:r.apiServiceUrl,j=s==null?void 0:s.accessToken;if(!(!x||!j)){l(!0);try{const N=Array.from(p.values());await Promise.all(N.map(async w=>{try{const a=await e.getExportStatus(x,j,w.id);let i;if(a.status==="completed")try{i=await e.getDownloadUrl(x,j,w.id)}catch(g){console.error(`Failed to get download URL for ${w.id}:`,g)}u(w.id,{status:a.status,progress:a.progress,completedChunks:a.completedChunks,completedAt:a.completedAt?new Date(a.completedAt):void 0,lastUpdatedAt:new Date,fileSize:a.fileSize,error:a.error,downloadUrl:i})}catch(a){console.error(`Failed to refresh export ${w.id}:`,a)}}))}finally{l(!1)}}},[p,s==null?void 0:s.accessToken,r==null?void 0:r.apiServiceUrl,u]),C=v.useCallback(async()=>{const x=r==null?void 0:r.apiServiceUrl,j=s==null?void 0:s.accessToken;if(!x||!j){c();return}o(!0);try{const N=f.filter(a=>a.status==="completed"||a.status==="failed"),w=await Promise.allSettled(N.map(async a=>(await e.cancelExport(x,j,a.id),a.id)));for(const a of w)a.status==="fulfilled"?d(a.value):console.error("Failed to delete export:",a.reason)}finally{o(!1)}},[f,r==null?void 0:r.apiServiceUrl,s==null?void 0:s.accessToken,c,d]),D=v.useCallback(async x=>{const j=r==null?void 0:r.apiServiceUrl,N=s==null?void 0:s.accessToken;if(j&&N)try{await e.cancelExport(j,N,x),d(x);return}catch(w){console.error(`Failed to cancel export ${x}:`,w)}d(x)},[r==null?void 0:r.apiServiceUrl,s==null?void 0:s.accessToken,d]);return f.length===0?t.jsxs("div",{className:"p-6 text-center",children:[t.jsx(T,{className:"mx-auto mb-2 h-8 w-8 text-muted-foreground"}),t.jsx("p",{className:"text-sm text-muted-foreground",children:"No active exports"}),t.jsx("p",{className:"mt-1 text-xs text-muted-foreground",children:"Large exports will appear here"})]}):t.jsxs("div",{className:"flex flex-col",children:[t.jsxs("div",{className:"flex items-center justify-between border-b px-4 py-3",children:[t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx(T,{className:"h-5 w-5 text-muted-foreground"}),t.jsx("h4",{className:"font-semibold",children:"Exports"})]}),t.jsxs("div",{className:"flex items-center gap-1",children:[t.jsx(e.Button,{variant:"ghost",size:"sm",className:"h-7 w-7 p-0",onClick:m,disabled:n,title:"Refresh status",children:t.jsx(e.RefreshCw,{className:`h-4 w-4 ${n?"animate-spin":""}`})}),b&&t.jsx(e.Button,{variant:"ghost",size:"sm",className:"h-7 px-2 text-sm",onClick:C,disabled:h,children:h?"Clearing...":"Clear all"})]})]}),t.jsx("div",{className:"max-h-[350px] overflow-y-auto",children:t.jsx("div",{className:"divide-y",children:f.map(x=>t.jsx(U,{export:x,onRemove:D},x.id))})})]})}function J({variant:s}){const r=e.useExportStore(h=>h.activeExports),p=e.useInProgressExportsCount(),c=r.size>0,d=Array.from(r.values()).some(h=>h.status==="completed"||h.status==="failed"),n=p>0?p>9?"9+":String(p):null,l=c;return t.jsxs(e.Popover,{children:[t.jsx(e.PopoverTrigger,{asChild:!0,children:t.jsxs(e.Button,{variant:s??"ghost",size:"icon",className:"relative h-8 w-8","aria-label":"Export notifications",children:[t.jsx(e.Bell,{className:"h-4 w-4"}),l&&t.jsx("span",{className:`absolute flex items-center justify-center rounded-full bg-primary text-primary-foreground ${n?"-right-0.5 -top-0.5 h-4 min-w-4 px-0.5 text-[10px] font-semibold":"right-0.5 top-0.5 h-2 w-2"}`,children:n})]})}),t.jsx(e.PopoverContent,{className:"w-80 p-0",align:"end",sideOffset:8,children:t.jsx(B,{})})]})}function ee(s){if(s)return{renamed:s.type==="rename"?{oldId:s.oldId,newId:s.newId}:void 0,removedControlId:s.type==="remove"?s.controlId:void 0,cardBindingsById:s.type==="add"||s.type==="update"?s.cardBindingsById:void 0,affectedBindingControlIds:s.type==="add"||s.type==="update"?s.affectedBindingControlIds:void 0}}function te({open:s,onOpenChange:r,trigger:p,showTrigger:c=!0,initialMode:d="manage"}){const u=d==="create",{forceClose:n,handleOpenChange:l,isCreateFlowActive:h,preventPassiveDismissDuringCreate:o,resolvedOpen:f,setIsCreateFlowActive:b}=I.useCreateFlowOverlayState({open:s,onOpenChange:r,initialCreateFlowActive:d==="create",dismissMode:c?"passive":"explicit-only"}),m=e.useDashboardStore(E=>E.dashboard),{setDashboardControlsModel:C}=e.useDashboardActions(),{participants:D}=e.useDashboardStructuralParticipants(e.getDashboardCards(m)),x=Array.from(new Map(D.flatMap(E=>E.fieldChoices.map(y=>{var F;return[y.value,{option:y,target:(F=E.fieldTargetMap)==null?void 0:F[y.value]}]}))).values()),j=Array.from(new Map(D.flatMap(E=>E.metricChoices.map(y=>{var F;return[y.value,{option:y,target:(F=E.metricTargetMap)==null?void 0:F[y.value]}]}))).values()),N=e.collectDashboardControlIds({...m||{},controls:[]}),w=e.buildDashboardStructuralParticipantIdsByControlId(m),a=(E,y,F)=>{C(E,y,ee(F))},i=v.useCallback(()=>{if(u){n();return}b(!1)},[u,n,b]),g=t.jsx(I.ControlDefinitionListEditor,{scope:"dashboard",controls:m.controls||[],reservedControlIds:N,defaultValues:m.defaultControlValues||{},usageByControlId:e.buildDashboardControlUsageById(m),availableFieldChoices:x,availableMetricChoices:j,structuralParticipants:D,structuralParticipantIdsByControlId:w,initialCreateFlow:d==="create",onCreateFlowActiveChange:b,onCreateFlowComplete:i,onChange:a,emptyMessage:"No dashboard controls yet."}),A=h?"Add dashboard control":"Dashboard Controls",S=t.jsxs(t.Fragment,{children:[t.jsxs("div",{className:"space-y-1",children:[t.jsx("h4",{className:"text-sm font-medium",children:"Dashboard Controls"}),t.jsx("p",{className:"text-xs text-muted-foreground",children:"Add shared controls viewers can use across the dashboard. Each card can decide how to respond to the same control."})]}),g]});return c?t.jsxs(e.Popover,{open:f,onOpenChange:l,children:[t.jsx(e.PopoverTrigger,{asChild:!0,children:p||t.jsxs(e.Button,{variant:"outline",className:"h-7 px-2",size:"sm",children:[t.jsx(e.SlidersHorizontal,{className:"mr-2 h-4 w-4"}),"Controls"]})}),t.jsx(e.PopoverContent,{className:"w-[620px] max-w-[95vw] space-y-4",align:"end",onEscapeKeyDown:o,onPointerDownOutside:o,children:S})]}):t.jsx(e.Dialog,{open:f,onOpenChange:l,children:t.jsxs(e.DialogContent,{className:"flex max-h-[88vh] flex-col overflow-hidden sm:max-w-[600px]",onEscapeKeyDown:o,onPointerDownOutside:o,children:[t.jsxs(e.DialogHeader,{className:h?"space-y-0":void 0,children:[t.jsx(e.DialogTitle,{className:"text-[15px]",children:A}),t.jsx(e.DialogDescription,{className:h?"sr-only":"text-[13px]",children:h?"Configure and add a shared dashboard control.":"Add shared controls viewers can use across the dashboard. Each card can decide how to respond to the same control."})]}),t.jsx("div",{className:"min-h-0 overflow-y-auto pr-1",children:g})]})})}function se({showFilters:s,onToggleFilters:r,onAddFilter:p,onAddControl:c,onManageControls:d,size:u="default",className:n,primaryButtonClassName:l,secondaryButtonClassName:h,dropdownContentClassName:o}){const f=u==="toolbar";return t.jsxs("div",{className:e.cn("relative inline-flex items-stretch overflow-visible rounded-md border border-input bg-background shadow-none",n),children:[t.jsxs(e.Button,{variant:"ghost",className:e.cn(f?"h-8":"h-7","rounded-none border-0 bg-transparent pl-3 pr-2 shadow-none hover:bg-accent/50",l),onClick:r,size:"sm",children:[s?t.jsx(P,{className:"mr-2 h-4 w-4"}):t.jsx(e.Filter,{className:"mr-2 h-4 w-4"}),"Filter"]}),t.jsxs(e.DropdownMenu,{children:[t.jsx(e.DropdownMenuTrigger,{asChild:!0,children:t.jsx(e.Button,{className:e.cn(f?"h-8 w-8":"h-7 w-8","rounded-none border-0 bg-transparent px-1 shadow-none hover:bg-accent/50",h),variant:"ghost",size:"sm","aria-label":"Filter and control actions",children:t.jsx(e.ChevronDown,{className:"h-4 w-4"})})}),t.jsxs(e.DropdownMenuContent,{align:"start",className:e.cn("rounded-xl border border-border/60 p-1 shadow-sm",o),children:[t.jsxs(e.DropdownMenuItem,{onSelect:p,children:[t.jsx(e.Filter,{className:"mr-2 h-4 w-4"}),"Add filter"]}),t.jsxs(e.DropdownMenuItem,{onSelect:c,children:[t.jsx(e.SlidersHorizontal,{className:"mr-2 h-4 w-4"}),"Add control"]}),t.jsxs(e.DropdownMenuItem,{onSelect:d,children:[t.jsx(e.Pencil,{className:"mr-2 h-4 w-4"}),"Manage controls"]})]})]})]})}exports.AdvancedModeToggle=Q;exports.DashboardControlsSettings=te;exports.DashboardFilterControlsButton=se;exports.ExportNotificationItem=U;exports.ExportNotificationList=B;exports.NotificationBell=J;exports.UnsavedChangesAlert=Y;exports.VisualEditingControls=W;exports.useExportPolling=q;exports.useExportRecovery=_;exports.usePristineSnapshotInitializer=Z;
@@ -1,6 +0,0 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),t=require("./index-Celt_oJr.js"),h=require("react"),re=require("./use-visual-utils-CWcTBBvd.js");/**
2
- * @license lucide-react v0.453.0 - ISC
3
- *
4
- * This source code is licensed under the ISC license.
5
- * See the LICENSE file in the root directory of this source tree.
6
- */const ie=t.createLucideIcon("FolderOpen",[["path",{d:"m6 14 1.5-2.9A2 2 0 0 1 9.24 10H20a2 2 0 0 1 1.94 2.5l-1.54 6a2 2 0 0 1-1.95 1.5H4a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h3.9a2 2 0 0 1 1.69.9l.81 1.2a2 2 0 0 0 1.67.9H18a2 2 0 0 1 2 2v2",key:"usdka0"}]]);function ae(s,g={}){const{enabled:x=!0,eventType:d="mousedown"}=g,i=h.useRef(null);return h.useEffect(()=>{const m=j=>{const o=j.target;i.current&&i.current.contains(o)||o instanceof Element&&(o.closest("[data-radix-popper-content-wrapper]")||o.closest("[data-radix-select-content]")||o.closest("[data-radix-popover-content]")||o.closest("[data-radix-dropdown-menu-content]")||o.closest("[data-radix-tooltip-content]")||o.closest('[role="listbox"]')||o.closest('[role="option"]')||o.closest('[role="combobox"]'))||o instanceof Element&&o.hasAttribute("data-radix-")||s()};return x&&document.addEventListener(d,m),()=>{document.removeEventListener(d,m)}},[s,x,d]),i}function ne(){return e.jsx("div",{className:"space-y-1.5 py-1",children:[...Array(5)].map((s,g)=>e.jsxs("div",{className:"flex animate-pulse items-start gap-3 rounded-xl border border-transparent px-2.5 py-2.5",children:[e.jsx("div",{className:"mt-0.5 h-4 w-4 flex-shrink-0 rounded bg-muted/60"}),e.jsxs("div",{className:"flex-1 space-y-1.5",children:[e.jsx("div",{className:"h-4 w-3/5 rounded bg-muted/60"}),e.jsx("div",{className:"h-3 w-4/5 rounded bg-muted/40"})]})]},g))})}const de=s=>{const g=t.useDashboardStore(i=>i.isVisualEditing),x=t.useDashboardStore(i=>i.selectedFrameId),d=t.useEditorStore(i=>i.frame);return!!(g&&x&&(d==null?void 0:d.visualId)===s)};function le({visual:s,isDeleting:g,isDuplicating:x,onAddVisual:d,onOpenVisual:i,onEditDetails:m,onDeleteClick:j,onDuplicateVisual:o,onShareVisual:D,formatDate:N}){var O,T,U,P;const{selectVisual:p}=t.useManagementActions(),c=t.useIsVisualSelected(s.id),u=de(s.id),A=t.useDashboardStore(a=>a.isVisualEditing),{isConsoleMode:R}=t.useDashboardPreferences(),b=h.useRef(null),[C,S]=h.useState(!1),[E,L]=h.useState(!1);h.useEffect(()=>{x?(S(!0),L(!0)):E&&(S(!1),L(!1))},[x,E]),h.useEffect(()=>{u&&b.current&&b.current.scrollIntoView({behavior:"smooth",block:"center"})},[u]);const y=()=>{p(s),i==null||i(s)},v=a=>{a.currentTarget===a.target&&(a.key==="Enter"||a.key===" ")&&(a.preventDefault(),y())};return e.jsxs("div",{ref:b,className:t.cn("group flex cursor-pointer items-start gap-2 rounded-xl border border-transparent px-2.5 py-2.5 transition-[background-color,border-color,box-shadow] hover:border-border/50 hover:bg-muted/35 focus-within:ring-2 focus-within:ring-inset focus-within:ring-ring/40",u?"border-primary/30 bg-primary/10":c&&"border-border/60 bg-muted/50"),onClick:y,children:[e.jsxs("div",{role:"button",tabIndex:0,className:"min-w-0 flex-1 cursor-pointer focus-visible:outline-none",onKeyDown:v,children:[e.jsx("p",{className:"truncate text-sm font-medium text-foreground",title:s.title||"Untitled Visual",children:s.title||"Untitled Visual"}),e.jsx("p",{className:"truncate text-xs text-muted-foreground",title:s.description||"No description",children:(O=s.description)!=null&&O.trim()?s.description:"No description"})]}),e.jsx("div",{className:t.cn("flex flex-shrink-0 items-center gap-1 transition-opacity",c||u||C?"pointer-events-auto opacity-100":"pointer-events-none opacity-0 group-hover:pointer-events-auto group-hover:opacity-100 group-focus-within:pointer-events-auto group-focus-within:opacity-100"),onClick:a=>a.stopPropagation(),children:e.jsxs("div",{className:"inline-flex items-center overflow-hidden rounded-lg border border-border/60 bg-background/95 shadow-sm",children:[e.jsxs(t.Button,{size:"sm",variant:"ghost",className:"h-7 gap-1 rounded-none border-0 px-2 text-xs font-medium shadow-none hover:bg-muted/50",disabled:A,onClick:a=>{a.stopPropagation(),d(s)},"aria-label":`Add ${s.title||"visual"}`,children:[e.jsx(t.Plus,{className:"h-3.5 w-3.5"}),"Add"]}),e.jsxs(t.DropdownMenu,{modal:!1,open:C,onOpenChange:S,children:[e.jsx(t.DropdownMenuTrigger,{asChild:!0,children:e.jsx(t.Button,{size:"sm",variant:"ghost",className:"h-7 w-7 rounded-none border-0 border-l border-border/60 p-0 shadow-none hover:bg-muted/50","aria-label":"Open visual actions",children:e.jsx(t.EllipsisVertical,{className:"h-3 w-3"})})}),e.jsxs(t.DropdownMenuContent,{align:"end",className:"z-[51] w-44 rounded-xl border border-border/60 p-1 shadow-sm",children:[e.jsxs(t.DropdownMenuItem,{onClick:a=>{a.stopPropagation(),d(s)},disabled:A,children:[e.jsx(t.Plus,{className:"mr-2 h-3 w-3"}),"Add"]}),e.jsxs(t.DropdownMenuItem,{onClick:a=>{a.stopPropagation(),i==null||i(s)},children:[e.jsx(ie,{className:"mr-2 h-3 w-3"}),"Open"]}),e.jsxs(t.DropdownMenuItem,{onClick:a=>{a.preventDefault(),a.stopPropagation(),o(s.id)},disabled:x,children:[x?e.jsx(t.LoaderCircle,{className:"mr-2 h-3 w-3 animate-spin"}):e.jsx(t.Copy,{className:"mr-2 h-3 w-3"}),x?"Duplicating...":"Duplicate"]}),s.ownership.isOwner&&e.jsxs(e.Fragment,{children:[e.jsxs(t.DropdownMenuItem,{onClick:a=>{a.stopPropagation(),m==null||m(s)},children:[e.jsx(t.PenLine,{className:"mr-2 h-3 w-3"}),"Edit details"]}),e.jsxs(t.DropdownMenuItem,{onClick:a=>{a.stopPropagation(),D(s)},children:[e.jsx(t.Users,{className:"mr-2 h-3 w-3"}),"Share"]}),e.jsx(t.DropdownMenuSeparator,{}),e.jsxs(t.DropdownMenuItem,{onClick:a=>{a.stopPropagation(),j(s)},className:"text-destructive",disabled:g,children:[e.jsx(t.Trash2,{className:"mr-2 h-3 w-3"}),g?"Deleting...":"Delete"]})]}),e.jsx(t.DropdownMenuSeparator,{}),e.jsxs("div",{className:"space-y-1 px-2 py-2 text-xs text-muted-foreground",children:[(((T=s.ownership.createdBy)==null?void 0:T.type)==="tenant"||((U=s.ownership.createdBy)==null?void 0:U.type)==="organization"&&R)&&e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx(t.User,{className:"h-3 w-3"}),e.jsx("span",{children:((P=s.ownership.createdBy)==null?void 0:P.name)||"Unknown"})]}),e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx(t.Calendar,{className:"h-3 w-3"}),e.jsx("span",{children:N(s.lastModified)})]})]})]})]})]})})]})}function ce({searchQuery:s}){const[g,x]=h.useState(!1),[d,i]=h.useState(null),[m,j]=h.useState(!1),[o,D]=h.useState(null),[N,p]=h.useState(null),[c,u]=h.useState(null),{handleEditLibraryVisual:A,handleAddLibraryVisual:R}=re.useVisualUtils(),{resources:b,isLoading:C,isError:S,updateResource:E,deleteResource:L,duplicateResource:y,isDeleting:v}=t.useVisualManagement(()=>{j(!1),D(null)}),O=b.filter(n=>{var M,l;return((M=n==null?void 0:n.title)==null?void 0:M.toLowerCase().includes(s.toLowerCase()))||((l=n==null?void 0:n.description)==null?void 0:l.toLowerCase().includes(s.toLowerCase()))}),T=n=>new Date(n).toLocaleDateString("en-US",{month:"short",day:"numeric",year:"numeric"}),U=n=>{D(n),j(!0)},P=()=>{o&&L(o.id)},{startUpdating:a,stopUpdating:_,isUpdating:F}=t.useResourceUpdateState(),V=(n,M,l)=>{var X;const B=Object.fromEntries(Object.entries(M).filter(([,I])=>I!==void 0));if(Object.keys(B).length===0){(X=l==null?void 0:l.onSuccess)==null||X.call(l);return}const w=Object.keys(B),H=w.length===1?w[0]:void 0;a(n,H),E({resourceId:n,data:B},{onSuccess:()=>{var I;_(n,H),(I=l==null?void 0:l.onSuccess)==null||I.call(l)},onError:()=>{var I;_(n,H),(I=l==null?void 0:l.onError)==null||I.call(l)}})},G=n=>{p(n),y(n,{onSettled:()=>p(null)})},z=n=>{A(n)},W=n=>{R(n)},Y=n=>{i(n),x(!0)},$=n=>{u(n)},J=()=>{u(null)},Q=({title:n,description:M})=>{if(!c)return;const l={};n!==c.title&&(l.title=n),(c.description||"")!==M&&(l.description=M),V(c.id,l,{onSuccess:()=>{u(null)}})};return C?e.jsx(ne,{}):S?e.jsx(t.ScrollArea,{className:"w-full flex-1 pr-2",children:e.jsxs("div",{className:"rounded-xl border border-dashed border-border/60 bg-muted/20 px-4 py-8 text-center text-muted-foreground",children:[e.jsx("p",{className:"text-sm text-destructive",children:"Failed to load visuals"}),e.jsx(t.Button,{variant:"outline",size:"sm",className:"mt-2",onClick:()=>window.location.reload(),children:"Retry"})]})}):e.jsxs("div",{className:"flex h-full flex-1 flex-col",children:[e.jsx("div",{className:"flex flex-1 basis-0 flex-col gap-1.5 overflow-y-auto px-0.5",children:O.length===0?e.jsxs("div",{className:"rounded-xl border border-dashed border-border/60 bg-muted/20 px-4 py-8 text-center",children:[e.jsx("div",{className:"mb-3",children:e.jsx(t.Grid3x3,{className:"mx-auto h-12 w-12 text-muted-foreground/50"})}),e.jsx("h3",{className:"mb-1 font-medium text-foreground",children:s?"No visuals found":"No visuals yet"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:s?"Try adjusting your search":'Click "New" above to add your first visual'})]}):O.map(n=>e.jsx(le,{visual:n,onAddVisual:W,onOpenVisual:z,onEditDetails:$,onDeleteClick:U,onDuplicateVisual:G,onShareVisual:Y,isDeleting:v,isDuplicating:N===n.id,formatDate:T},n.id))}),g&&d&&e.jsx(t.ShareDialog,{resource:d,resourceType:t.ResourceType.VISUAL,onClose:()=>{x(!1),i(null)}}),c&&e.jsx(t.ResourceEditDialog,{open:!!c,resourceLabel:"Visual",initialTitle:c.title||"",initialDescription:c.description||"",onClose:J,onSave:Q,isSaving:F(c.id)}),e.jsx(t.AlertDialog,{open:m,onOpenChange:n=>{!n&&v||(j(n),n||D(null))},children:e.jsxs(t.AlertDialogContent,{children:[e.jsxs(t.AlertDialogHeader,{children:[e.jsx(t.AlertDialogTitle,{children:"Delete Visual"}),e.jsxs(t.AlertDialogDescription,{children:['Are you sure you want to delete "',o==null?void 0:o.title,'"? This action cannot be undone.']})]}),e.jsxs(t.AlertDialogFooter,{children:[e.jsx(t.AlertDialogCancel,{disabled:v,children:"Cancel"}),e.jsxs(t.AlertDialogAction,{onClick:n=>{n.preventDefault(),n.stopPropagation(),P()},className:"bg-destructive text-destructive-foreground hover:bg-destructive/90",disabled:v,children:[v?e.jsx(t.LoaderCircle,{className:"mr-2 h-3.5 w-3.5 animate-spin"}):e.jsx(t.Trash2,{className:"mr-2 h-3.5 w-3.5"}),v?"Deleting...":"Delete"]})]})]})})]})}function ue({dashboard:s,isDeleting:g,isDuplicating:x,onLoadDashboard:d,onEditDetails:i,onDeleteClick:m,onDuplicateDashboard:j,onShareDashboard:o,formatDate:D,onDashboardItemClick:N}){var E,L;const{selectDashboard:p}=t.useManagementActions(),c=t.useIsDashboardSelected(s.id),{userContext:u,isLoading:A}=t.useCurrentUserInfo(),R=((E=u==null?void 0:u.permissions)==null?void 0:E.canEdit)??!1,b=A||!R,C=()=>{p(s),d(s.id),N==null||N(s.id)},S=y=>{y.currentTarget===y.target&&(y.key==="Enter"||y.key===" ")&&(y.preventDefault(),C())};return e.jsxs("div",{className:t.cn("group flex cursor-pointer items-start gap-2 rounded-xl border border-transparent px-2.5 py-2.5 transition-[background-color,border-color,box-shadow] hover:border-border/50 hover:bg-muted/35 focus-within:ring-2 focus-within:ring-inset focus-within:ring-ring/40",c&&"border-border/60 bg-muted/50"),onClick:C,children:[e.jsxs("div",{role:"button",tabIndex:0,className:"min-w-0 flex-1 cursor-pointer focus-visible:outline-none",onKeyDown:S,children:[e.jsx("p",{className:"truncate text-sm font-medium text-foreground",title:s.title||"Untitled Dashboard",children:s.title||"Untitled Dashboard"}),e.jsx("p",{className:"truncate text-xs text-muted-foreground",title:s.description||"No description",children:(L=s.description)!=null&&L.trim()?s.description:"No description"})]}),e.jsx("div",{className:t.cn("flex-shrink-0 transition-opacity",c?"opacity-100":"opacity-0 group-hover:opacity-100 group-focus-within:opacity-100"),children:e.jsx(t.DashboardActionsMenu,{dashboard:s,isDeleting:g,isDuplicating:x,shouldHideActions:b,onEditDetails:i,onDeleteClick:m,onDuplicateDashboard:j,onShareDashboard:o,formatDate:D})})]})}function he({onRetry:s}){return e.jsx(t.ScrollArea,{className:"w-full flex-1 pr-2",children:e.jsxs("div",{className:"rounded-xl border border-dashed border-border/60 bg-muted/20 px-4 py-8 text-center text-muted-foreground",children:[e.jsx("p",{className:"text-sm text-destructive",children:"Failed to load dashboards"}),e.jsx(t.Button,{variant:"outline",size:"sm",className:"mt-2",onClick:s,children:"Retry"})]})})}function me(s){var ee;const{searchQuery:g,onLoadDashboard:x,onEditDashboard:d,onDashboardItemClick:i}=s,[m,j]=h.useState(!1),[o,D]=h.useState(null),[N,p]=h.useState(!1),[c,u]=h.useState(null),[A,R]=h.useState(null),[b,C]=h.useState(null),S=t.useManagementStore(r=>r.lastSelectedDashboard),E=t.useManagementStore(r=>r.selectedDashboard),L=t.useManagementStore(r=>r.actions.selectDashboard),y=t.useManagementStore(r=>r.actions.clearSelectedDashboard),{tokenProps:v,id:O}=t.useSemaphorContext(),{resources:T,isLoading:U,isError:P,updateResource:a,deleteResource:_,duplicateResource:F,isDeleting:V}=t.useDashboardManagement(()=>{p(!1);const r=c==null?void 0:c.id;u(null),(E==null?void 0:E.id)===r&&(!(v!=null&&v.dashboard_id)&&!O?y():S&&S.id!==r&&L(S))}),{userContext:G}=t.useCurrentUserInfo(),z=((ee=G==null?void 0:G.permissions)==null?void 0:ee.canCreateDashboard)??!1,W=T.filter(r=>{var K,f;return((K=r==null?void 0:r.title)==null?void 0:K.toLowerCase().includes(g.toLowerCase()))||((f=r==null?void 0:r.description)==null?void 0:f.toLowerCase().includes(g.toLowerCase()))}),Y=r=>new Date(r).toLocaleDateString("en-US",{month:"short",day:"numeric",year:"numeric"}),$=r=>{x==null||x(r)},J=r=>{u(r),p(!0)},Q=()=>{c&&_(c.id)},n=r=>{R(r),F(r,{onSettled:()=>R(null)})},{startUpdating:M,stopUpdating:l,isUpdating:B}=t.useResourceUpdateState(),w=(r,K,f)=>{var se;const Z=Object.fromEntries(Object.entries(K).filter(([,q])=>q!==void 0));if(Object.keys(Z).length===0){(se=f==null?void 0:f.onSuccess)==null||se.call(f);return}const te=Object.keys(Z),k=te.length===1?te[0]:void 0;M(r,k),a({resourceId:r,data:Z},{onSuccess:()=>{var q;l(r,k),(q=f==null?void 0:f.onSuccess)==null||q.call(f)},onError:()=>{var q;l(r,k),(q=f==null?void 0:f.onError)==null||q.call(f)}})},H=r=>{D(r),j(!0)},X=r=>{d==null||d(r.id),C(r)},I=()=>{C(null)},oe=({title:r,description:K})=>{if(!b)return;const f={};r!==b.title&&(f.title=r),(b.description||"")!==K&&(f.description=K),w(b.id,f,{onSuccess:()=>{C(null)}})};return U?e.jsx(ne,{}):P?e.jsx(he,{onRetry:()=>window.location.reload()}):e.jsxs("div",{className:"flex h-full flex-1 flex-col",children:[e.jsx("div",{className:"flex flex-1 basis-0 flex-col gap-1.5 overflow-y-auto px-0.5",children:W.length===0?e.jsxs("div",{className:"rounded-xl border border-dashed border-border/60 bg-muted/20 px-4 py-8 text-center",children:[e.jsx("div",{className:"mb-3",children:e.jsx(t.ChartColumn,{className:"mx-auto h-12 w-12 text-muted-foreground/50"})}),e.jsx("h3",{className:"mb-1 font-medium text-foreground",children:g?"No dashboards found":"No dashboards yet"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:g?"Try adjusting your search":z?'Click "New" above to add your first dashboard':"No dashboards have been shared with you yet"})]}):W.map(r=>e.jsx(ue,{dashboard:r,isDeleting:V,isDuplicating:A===r.id,onLoadDashboard:$,onEditDetails:X,onDeleteClick:J,onDuplicateDashboard:n,onShareDashboard:H,formatDate:Y,onDashboardItemClick:i},r.id))}),m&&o&&e.jsx(t.ShareDialog,{resource:o,resourceType:t.ResourceType.DASHBOARD,onClose:()=>{j(!1),D(null)}}),e.jsx(t.AlertDialog,{open:N,onOpenChange:r=>{!r&&V||(p(r),r||u(null))},children:e.jsxs(t.AlertDialogContent,{children:[e.jsxs(t.AlertDialogHeader,{children:[e.jsx(t.AlertDialogTitle,{children:"Delete Dashboard"}),e.jsxs(t.AlertDialogDescription,{children:['Are you sure you want to delete "',c==null?void 0:c.title,'"? This action cannot be undone.']})]}),e.jsxs(t.AlertDialogFooter,{children:[e.jsx(t.AlertDialogCancel,{disabled:V,children:"Cancel"}),e.jsxs(t.AlertDialogAction,{onClick:r=>{r.preventDefault(),r.stopPropagation(),Q()},className:"bg-destructive text-destructive-foreground hover:bg-destructive/90",disabled:V,children:[V?e.jsx(t.LoaderCircle,{className:"mr-2 h-3.5 w-3.5 animate-spin"}):e.jsx(t.Trash2,{className:"mr-2 h-3.5 w-3.5"}),V?"Deleting...":"Delete"]})]})]})}),b&&e.jsx(t.ResourceEditDialog,{open:!!b,resourceLabel:"Dashboard",initialTitle:b.title||"",initialDescription:b.description||"",onClose:I,onSave:oe,isSaving:B(b.id)})]})}function pe({open:s,onOpenChange:g,onSubmit:x,isCreating:d}){const[i,m]=h.useState(""),[j,o]=h.useState("");h.useEffect(()=>{s||(m(""),o(""))},[s]);const D=()=>{i.trim()&&x({title:i,description:j})},N=p=>{g(p)};return e.jsx(t.Dialog,{open:s,onOpenChange:N,children:e.jsxs(t.DialogContent,{children:[e.jsxs(t.DialogHeader,{children:[e.jsx(t.DialogTitle,{children:"Create New Visual"}),e.jsx(t.DialogDescription,{children:"Add a new visual to your library. You can configure it after creation."})]}),e.jsxs("div",{className:"space-y-4 py-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(t.Label,{htmlFor:"title",children:"Visual Title"}),e.jsx(t.Input,{id:"title",placeholder:"Enter visual title...",value:i,onChange:p=>m(p.target.value),disabled:d,onKeyDown:p=>{p.key==="Enter"&&!p.shiftKey&&(p.preventDefault(),D())}})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(t.Label,{htmlFor:"description",children:"Description (optional)"}),e.jsx(t.Input,{id:"description",placeholder:"Enter visual description...",value:j,onChange:p=>o(p.target.value),disabled:d})]})]}),e.jsxs(t.DialogFooter,{children:[e.jsx(t.Button,{variant:"outline",onClick:()=>N(!1),disabled:d,children:"Cancel"}),e.jsx(t.Button,{onClick:D,disabled:!i.trim()||d,children:d?e.jsxs(e.Fragment,{children:[e.jsx(t.LoaderCircle,{className:"mr-2 h-4 w-4 animate-spin"}),"Creating..."]}):"Create Visual"})]})]})})}function xe({isOpen:s,onClose:g,className:x,onDashboardItemClick:d,variant:i="inline"}){var l,B;const m=t.useDashboardStore(w=>w.isDashboardEditing),[j,o]=h.useState(!1),[D,N]=h.useState(""),[p,c]=h.useState(!1),{currentUser:u,userContext:A}=t.useCurrentUserInfo(),R=((l=A==null?void 0:A.permissions)==null?void 0:l.canCreateDashboard)??!1,{onCreateSuccess:b}=t.useDashboardCreation({onDashboardSelect:d}),{selectVisual:C}=t.useManagementActions(),{handleEditLibraryVisual:S}=re.useVisualUtils(),{createResource:E,isCreating:L,refetch:y}=t.useDashboardManagement(),{createResource:v,isCreating:O}=t.useVisualManagement(void 0,w=>{o(!1),w&&(C(w),S(w))}),T=i==="overlay",U=m?"New Visual":"New",P=m?"New Visual":"New Dashboard",a=m?"Search visuals...":"Search dashboards...",_=m?"Collapse visuals panel":"Collapse dashboard panel",F=((u==null?void 0:u.name)??"").trim(),V=((u==null?void 0:u.email)??"").trim(),z=F&&F.toLowerCase()!=="undefined"?F:V||"Current user",W=((B=z.charAt(0))==null?void 0:B.toUpperCase())||"?",Y=V&&V.toLowerCase()!=="undefined"?V:"",$=ae(g,{enabled:s&&T}),J=t.cn("flex h-full flex-col border-r border-border/60 bg-background",T?t.cn("absolute inset-y-0 left-0 z-[51] w-60 overflow-hidden shadow-lg transition-transform duration-300 ease-in-out",s?"translate-x-0":"pointer-events-none -translate-x-full"):"w-full max-w-[17rem] min-w-[11rem] overflow-hidden",x),Q=w=>{},n=w=>{console.log("Editing dashboard:",w)},M=w=>{E(w,{onSuccess:H=>{o(!1),b(H,y)}})};return e.jsx(e.Fragment,{children:(!T||s)&&e.jsxs("div",{ref:$,className:J,children:[e.jsxs("div",{className:"border-b border-border/60 bg-background",children:[e.jsxs("div",{className:"flex items-center justify-between px-3 py-2",children:[e.jsx("div",{className:"flex items-center gap-2",children:e.jsx("h2",{className:"whitespace-nowrap text-sm font-semibold",children:m?"Visuals":"Dashboards"})}),e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx(t.Button,{size:"sm",variant:"ghost",onClick:()=>c(!p),className:"h-8 w-8 rounded-md p-0 text-muted-foreground hover:bg-muted/50 hover:text-foreground","aria-label":p?"Hide search":"Show search",children:e.jsx(t.Search,{className:"h-3.5 w-3.5"})}),(m||R)&&e.jsxs(t.Button,{size:"sm",variant:"secondary",className:"h-8 gap-1.5 whitespace-nowrap rounded-md border border-border/60 bg-muted/30 px-2 text-xs font-medium hover:bg-muted/55",onClick:()=>o(!0),"aria-label":P,children:[e.jsx(t.Plus,{className:"h-3.5 w-3.5"}),U]}),e.jsx(t.Button,{size:"sm",variant:"outline",className:"h-8 w-8 rounded-md border-border/60 bg-background p-0.5 text-muted-foreground hover:bg-muted/35 hover:text-foreground",onClick:g,"aria-label":_,children:e.jsx(t.PanelLeft,{className:"h-3.5 w-3.5"})})]})]}),p&&e.jsx("div",{className:"border-t border-border/50 bg-muted/20 px-3 pb-3 pt-2",children:e.jsx(t.Input,{placeholder:a,value:D,onChange:w=>N(w.target.value),className:"h-9 border-border/60 bg-background text-sm focus-visible:border-ring/40 focus-visible:ring-0 focus-visible:ring-offset-0",autoFocus:!0})})]}),e.jsx("div",{className:"flex flex-1 flex-col overflow-auto px-2.5 py-2.5",children:m?e.jsx(ce,{searchQuery:D}):e.jsx(me,{searchQuery:D,onLoadDashboard:Q,onEditDashboard:n,onDashboardItemClick:d})}),u&&e.jsx(t.TooltipProvider,{children:e.jsx("div",{className:"border-t border-border/60 bg-muted/20 px-3 py-2.5",children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs(t.Tooltip,{children:[e.jsx(t.TooltipTrigger,{asChild:!0,children:e.jsx("div",{className:"flex h-7 w-7 cursor-default items-center justify-center rounded-full bg-primary/10",children:e.jsx("span",{className:"text-xs font-medium text-primary",children:W})})}),e.jsx(t.TooltipContent,{side:"top",className:"max-w-xs",children:e.jsxs("div",{className:"space-y-1",children:[e.jsx("div",{className:"font-medium",children:z}),Y&&e.jsx("div",{className:"text-xs text-muted-foreground",children:Y}),u.role&&e.jsxs("div",{className:"text-xs text-muted-foreground",children:["Role: ",t.toTitleCase(u.role.replace(/_/g," "))]})]})})]}),e.jsx("span",{className:"truncate text-xs font-medium text-muted-foreground",children:z})]})})}),m?e.jsx(pe,{open:j,onOpenChange:o,onSubmit:v,isCreating:O}):e.jsx(t.CreateDashboardDialog,{open:j,onOpenChange:o,onSubmit:M,isCreating:L})]})})}exports.ResourceManagementPanel=xe;