@augmentd-labs/canvas-web 2.26.27 → 2.26.29
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/assets/CalendarApplet-CXG7O1QW.js +1 -0
- package/dist/assets/{DocumentBodyEditor-8DNmOBS0.js → DocumentBodyEditor-DRFQgBNB.js} +1 -1
- package/dist/assets/{DocumentIcon-x299QNu_.js → DocumentIcon-ByDAILhm.js} +1 -1
- package/dist/assets/{EditorOverlay-Cv1MaTok.js → EditorOverlay-DpQKmxkR.js} +1 -1
- package/dist/assets/{FileForm-CqJpRbXv.js → FileForm-B6eFRKG-.js} +1 -1
- package/dist/assets/{FiltersApplet-C-WD5XT9.js → FiltersApplet-C6-D-MEW.js} +1 -1
- package/dist/assets/{HomeFab-CzKEIYDk.js → HomeFab-DZbi60PC.js} +2 -2
- package/dist/assets/{IdentityFields-Bti7ojF3.js → IdentityFields-CEDxU-Hd.js} +1 -1
- package/dist/assets/{LensApplet-BCJXNx84.js → LensApplet-B9OaePzA.js} +1 -1
- package/dist/assets/LinkToCard-VXpoeMDH.js +1 -0
- package/dist/assets/{MarkdownEditor-CNY-VmKb.js → MarkdownEditor-Dnyez7VT.js} +2 -2
- package/dist/assets/{MessageComposerDialog-gbD0Gu_b.js → MessageComposerDialog-BKGlI7jO.js} +1 -1
- package/dist/assets/{NextShell-UX4Efo0u.js → NextShell-BvKyH2Oj.js} +1 -1
- package/dist/assets/{NotesApplet-CvPyt7xB.js → NotesApplet-BM7ksdXl.js} +1 -1
- package/dist/assets/ObjectPropertiesCard-CFZ_LqzX.js +8 -0
- package/dist/assets/{PathPickerField-fZazwxCN.js → PathPickerField-B58yeJGw.js} +1 -1
- package/dist/assets/PickDocumentsCard-B72XNYh3.js +1 -0
- package/dist/assets/{SketchApplet-DDIg411i.js → SketchApplet-BHee4eKG.js} +1 -1
- package/dist/assets/{SketchEditor-CKPPuZt3.js → SketchEditor-Knj-HA0P.js} +1 -1
- package/dist/assets/{TerminalApplet-wGJG1PPc.js → TerminalApplet-Djk4l1Jm.js} +1 -1
- package/dist/assets/{TextDocumentEditor-CRre32cj.js → TextDocumentEditor-rgHsbLCL.js} +1 -1
- package/dist/assets/{TodosApplet-CleBd4uU.js → TodosApplet-DZVcRHmh.js} +1 -1
- package/dist/assets/{TodosWidget-CxiqmDuJ.js → TodosWidget-CX4lgk-9.js} +1 -1
- package/dist/assets/{UploadProgressList-DRJzjy6A.js → UploadProgressList-CHQ-Kn-e.js} +1 -1
- package/dist/assets/{_agentId_-BXYnpAWp.js → _agentId_-CweMTe-q.js} +0 -0
- package/dist/assets/_contextId_-HAAoVKBa.js +1 -0
- package/dist/assets/_workspaceName_-D79RwRsV.js +1 -0
- package/dist/assets/{about-DrgIxiPQ.js → about-dr4T4ju8.js} +1 -1
- package/dist/assets/{add-CPkuZwMW.js → add-fha_SoND.js} +1 -1
- package/dist/assets/agents-CZgEe18J.js +1 -0
- package/dist/assets/{agents-DlLq0q2s.js → agents-DEJU4O1Z.js} +1 -1
- package/dist/assets/{alert-dialog-izlVMXfa.js → alert-dialog-CShuAcnP.js} +1 -1
- package/dist/assets/{api-tokens-DDH7LMJ7.js → api-tokens-CmHhwd58.js} +1 -1
- package/dist/assets/{appearance-DRBtL9nd.js → appearance-SqhMHD_S.js} +1 -1
- package/dist/assets/{applet-target-C_gBgU-Z.js → applet-target-Bl9Je1N-.js} +1 -1
- package/dist/assets/apps-stCO1N5r.js +1 -0
- package/dist/assets/{auth-HZNJB4wv.js → auth-_bmIEN02.js} +1 -1
- package/dist/assets/backend-sync-progress-DyvV8N9D.js +7 -0
- package/dist/assets/{button-SgR3GVvV.js → button-Bum-POPT.js} +1 -1
- package/dist/assets/content-app-view-CotdPc2q.js +1 -0
- package/dist/assets/{context-DQoZFMDQ.js → context-BGgz0Y_q.js} +1 -1
- package/dist/assets/{contexts-CvMtPd1N2.js → contexts-CwGdjtXy2.js} +1 -1
- package/dist/assets/{contexts-Ef3fHwv6.js → contexts-Dtl9oERX.js} +1 -1
- package/dist/assets/{date-time-picker-DebNUTx3.js → date-time-picker-Bzu8H_Oa.js} +1 -1
- package/dist/assets/{devices-C3gLuNDv.js → devices-CmVlYbam.js} +1 -1
- package/dist/assets/{document-DOp6AbOi.js → document-Ds_P5v-f.js} +1 -1
- package/dist/assets/document-list-Cq4rdquK.js +2 -0
- package/dist/assets/{embedding-B5JiUA9X.js → embedding-2EjzoVFT.js} +1 -1
- package/dist/assets/{embedding-B7cWrpy0.js → embedding-BqI3l5RB.js} +1 -1
- package/dist/assets/{form-panel-C34lByEH.js → form-panel-DZj3WZ3z.js} +1 -1
- package/dist/assets/{home-C6aXJsmf.js → home-w5SlrNH7.js} +1 -1
- package/dist/assets/index-DGCnvWMM.js +16 -0
- package/dist/assets/index-XDD8pFI_.css +2 -0
- package/dist/assets/{inferd-config-editor--MDmN_7w.js → inferd-config-editor-CyDCQJRs.js} +1 -1
- package/dist/assets/{key-bindings-BDktmxOD.js → key-bindings-5HbdLjsz.js} +1 -1
- package/dist/assets/{label-Dn4gCMcc.js → label-DJc8-3CQ.js} +1 -1
- package/dist/assets/{lazy-editor-BSRnneOo.js → lazy-editor-Bdm5JEXv.js} +2 -2
- package/dist/assets/{logs-Czn2sPeP.js → logs-DUeiDqCX.js} +1 -1
- package/dist/assets/{offline-COOUcZsG.js → offline-yfQ63Zr7.js} +1 -1
- package/dist/assets/{page-header-DkOHw0g-.js → page-header-BoCaZiqu.js} +1 -1
- package/dist/assets/{public-share-g_wBd6BW.js → public-share-D2S8DEsv.js} +1 -1
- package/dist/assets/{query-debug-CrPsUwT-.js → query-debug-B3pFyO8g.js} +1 -1
- package/dist/assets/registry-BRI7e6jw.js +2 -0
- package/dist/assets/{remotes-CdEU1Y5l.js → remotes-BjjlqN_M.js} +1 -1
- package/dist/assets/{roles-BpVWTMmp.js → roles-BHJYWaBs.js} +1 -1
- package/dist/assets/{roles-Bo9GZdOk.js → roles-CuqCEPC7.js} +1 -1
- package/dist/assets/{settings-TQmRYAGg.js → settings-Btb3SUu6.js} +1 -1
- package/dist/assets/{settings-DJyvE-wf.js → settings-D55sWdd2.js} +1 -1
- package/dist/assets/{settings-Be_a2PGC.js → settings-UMBkdMdX.js} +1 -1
- package/dist/assets/settings-y5FovQxO.js +16 -0
- package/dist/assets/{share-target-BDbVdgTo.js → share-target-5HoF3Y5a.js} +1 -1
- package/dist/assets/{shared-BbAavKdN.js → shared-B24deTOM.js} +1 -1
- package/dist/assets/{shared-BQZGA3ph.js → shared-C-uHNNY8.js} +1 -1
- package/dist/assets/sketch-lazy-BOFTGGTA.js +2 -0
- package/dist/assets/{subtree-transfer-dialog-ChBI5llU.js → subtree-transfer-dialog-BN9xBB9n.js} +1 -1
- package/dist/assets/{text-documents-0P9jkIpu.js → text-documents-CFW8MWES.js} +2 -2
- package/dist/assets/ui-76Hw0NU_.js +41 -0
- package/dist/assets/{use-applet-docs-D5eXpITp.js → use-applet-docs-DBshA7yq.js} +1 -1
- package/dist/assets/use-applet-target-DmIdCxa_.js +1 -0
- package/dist/assets/use-canvas-pins-BZMaPpb7.js +3 -0
- package/dist/assets/{use-menu-BiJ8N7sS.js → use-menu-CaiLyPdw.js} +1 -1
- package/dist/assets/use-settings-back-DE0SPb7h.js +1 -0
- package/dist/assets/{use-sortable-data-BW_0sXBs.js → use-sortable-data-W2inLcb5.js} +1 -1
- package/dist/assets/{use-workspace-identity-BCrrvfeE.js → use-workspace-identity-KxY9injc.js} +1 -1
- package/dist/assets/useAddTarget-D4ra50Am.js +1 -0
- package/dist/assets/{useAgentModels-PQVPjrQu.js → useAgentModels-vTfsjAwS.js} +1 -1
- package/dist/assets/{useDocumentThumbnail-DunxmU1A.js → useDocumentThumbnail-Bs2Ju0eb.js} +1 -1
- package/dist/assets/{useEditNoteFields-BehI0vog.js → useEditNoteFields-CKYMBf8V.js} +1 -1
- package/dist/assets/{users-CKz9kOoR.js → users-DInwKAxz.js} +1 -1
- package/dist/assets/workspace-46EFyEKZ.js +1 -0
- package/dist/assets/{workspace-area-menu-C0-X-FpD.js → workspace-area-menu-COdiU0Xn.js} +1 -1
- package/dist/assets/{workspace-content-gate-9okuA7J7.js → workspace-content-gate-CGZmT2kw.js} +1 -1
- package/dist/assets/{workspace-import-form-aR-DwHf6.js → workspace-import-form-Bu1nlv8u.js} +1 -1
- package/dist/assets/workspaces-BBq3LOwy.js +1 -0
- package/dist/assets/{workspaces-Da_hUIj3.js → workspaces-p959p9BR.js} +1 -1
- package/dist/index.html +36 -36
- package/dist/sw.js +1 -1
- package/package.json +2 -2
- package/dist/assets/LinkToCard-5dg0jvSY.js +0 -1
- package/dist/assets/ObjectPropertiesCard-BIBMvx_i.js +0 -8
- package/dist/assets/PickDocumentsCard-DamtV7fN.js +0 -1
- package/dist/assets/_contextId_-BEC7o1ya.js +0 -1
- package/dist/assets/_workspaceName_-5rSLTtJT.js +0 -1
- package/dist/assets/agents-jmTwCDAu.js +0 -1
- package/dist/assets/apps-CqFFzo_Z.js +0 -1
- package/dist/assets/backend-sync-progress-pZrhQPk3.js +0 -7
- package/dist/assets/content-app-view-y5TmcjuO.js +0 -1
- package/dist/assets/document-list-DKOU9Kcc.js +0 -2
- package/dist/assets/index-B-PM5mzp.css +0 -2
- package/dist/assets/index-CyEIU2rL.js +0 -16
- package/dist/assets/registry-ZMLdscra.js +0 -2
- package/dist/assets/settings-VF2v3Ya5.js +0 -14
- package/dist/assets/sketch-lazy-C4pjV1WK.js +0 -2
- package/dist/assets/ui-Byg1cZDr.js +0 -41
- package/dist/assets/use-applet-target-gXPvZGgx.js +0 -1
- package/dist/assets/use-canvas-pins-BvN6Gw6f.js +0 -3
- package/dist/assets/use-settings-back-CQauYjQ4.js +0 -1
- package/dist/assets/useAddTarget-CqnDU0Om.js +0 -1
- package/dist/assets/workspace-CrSpR4xf.js +0 -1
- package/dist/assets/workspaces-BGbHBVHs.js +0 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@augmentd-labs/canvas-web",
|
|
3
|
-
"version": "2.26.
|
|
3
|
+
"version": "2.26.29",
|
|
4
4
|
"description": "Canvas web UI (prebuilt dist)",
|
|
5
5
|
"license": "AGPL-3.0-or-later",
|
|
6
6
|
"author": "Jozef Melich <me@idnc.sk>",
|
|
@@ -12,5 +12,5 @@
|
|
|
12
12
|
"dist",
|
|
13
13
|
"NOTICE"
|
|
14
14
|
],
|
|
15
|
-
"canvasRev": "
|
|
15
|
+
"canvasRev": "bfd908d"
|
|
16
16
|
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{o as e}from"./rolldown-runtime-C0FnF6B9.js";import{l as t,u as n}from"./code-editor-BOIngd5F.js";import{_t as r,yt as i}from"./react-BHzhHVTZ.js";import{Br as a,Cr as o,Hr as s,It as c,Kn as l,L as u,Un as d,Xn as f,_n as p,mt as m,yt as h,zn as g}from"./ui-Byg1cZDr.js";import{t as _}from"./utils-2pl1SbIp.js";import{t as v}from"./button-SgR3GVvV.js";import{An as y,K as ee,Ot as b,Pt as x,Q as te,gt as S,ht as C,it as ne,q as re,t as ie}from"./workspace-CrSpR4xf.js";import{t as w}from"./useEscapeClose-DR_xKT_k.js";import{t as ae}from"./useToastHelpers-CRrpIIdY.js";import{s as T}from"./layer-style-Byl5LNFR.js";import{i as E}from"./color-DFEH4BfK.js";import{t as oe}from"./DocumentIcon-x299QNu_.js";var D=e(n(),1),O=t();function k({className:e=`h-5 w-5`,...t}){return(0,O.jsxs)(`svg`,{className:`animate-spin ${e}`,xmlns:`http://www.w3.org/2000/svg`,fill:`none`,viewBox:`0 0 24 24`,...t,children:[(0,O.jsx)(`circle`,{className:`opacity-25`,cx:`12`,cy:`12`,r:`10`,stroke:`currentColor`,strokeWidth:`4`}),(0,O.jsx)(`path`,{className:`opacity-75`,fill:`currentColor`,d:`M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z`})]})}var A=e(i(),1);function j(e){let[t,n]=(0,D.useState)(null);(0,D.useEffect)(()=>{if(!e)return;let t=!1;return te(e).then(r=>{t||n({workspaceId:e,predicates:r,error:!1})},()=>{t||n({workspaceId:e,predicates:[],error:!0})}),()=>{t=!0}},[e]);let r=t?.workspaceId===e?t:null;return{predicates:r?.predicates??[],error:r?.error??!1,loading:!!e&&!r}}function M({x:e,y:t,onClose:n,className:r,children:i}){let a=(0,D.useRef)(null),[o,s]=(0,D.useState)({x:e,y:t});return w(n),(0,D.useLayoutEffect)(()=>{let n=a.current;if(!n)return;let{width:r,height:i}=n.getBoundingClientRect();s({x:Math.max(8,Math.min(e,window.innerWidth-r-8)),y:Math.max(8,Math.min(t,window.innerHeight-i-8))})},[e,t]),(0,A.createPortal)((0,O.jsxs)(O.Fragment,{children:[(0,O.jsx)(`div`,{className:`fixed inset-0 z-menu-scrim`,onClick:n,onContextMenu:e=>{e.preventDefault(),n()}}),(0,O.jsx)(`div`,{ref:a,style:{left:o.x,top:o.y},className:_(`fixed z-menu max-h-viewport-modal overflow-y-auto`,r,`bg-popover text-popover-foreground`),children:i})]}),document.body)}var N=typeof navigator<`u`&&/Mac|iPhone|iPad/.test(navigator.platform||navigator.userAgent),P={Delete:`Del`,Backspace:`⌫`,Enter:`↵`,ArrowUp:`↑`,ArrowDown:`↓`};function F(e){let t=e.split(`+`),n=t.pop()||``,r=P[n]||(n.length===1?n.toUpperCase():n);if(N){let e={Mod:`⌘`,Shift:`⇧`,Alt:`⌥`,Ctrl:`⌃`};return[...[`Ctrl`,`Alt`,`Shift`,`Mod`].filter(e=>t.includes(e)).map(t=>e[t]),r].join(``)}return[...t.map(e=>e===`Mod`?`Ctrl`:e),r].join(`+`)}function se(e,t){let n=t.split(`+`),r=n.pop()||``;return(N?e.metaKey:e.ctrlKey)!==n.includes(`Mod`)||e.shiftKey!==n.includes(`Shift`)||e.altKey!==n.includes(`Alt`)||N&&e.ctrlKey!==n.includes(`Ctrl`)?!1:r.length===1?e.key.toLowerCase()===r.toLowerCase():e.key===r}function I(e){if(e?.closest?.(`input, textarea, select, [contenteditable="true"], [role="dialog"], [role="menu"]`))return!0;let t=typeof window<`u`?window.getSelection():null;return!!t&&!t.isCollapsed&&t.toString().length>0}function L(e,t){if(e.defaultPrevented||e.nativeEvent.isComposing||I(e.target))return!1;let n=t.find(t=>t.shortcut&&!t.disabled&&se(e,t.shortcut));return n?(e.preventDefault(),e.stopPropagation(),n.run({shiftKey:e.shiftKey}),!0):!1}function R(e){return e.key===`ContextMenu`||e.key===`F10`&&e.shiftKey}function ce(){return typeof window<`u`&&window.matchMedia(`(max-width: 767px)`).matches}function z(e,t=`below`){let n=e.getBoundingClientRect();return t===`below`?{x:n.left,y:n.bottom+4}:{x:n.left+Math.min(24,n.width/2),y:n.top+Math.min(24,n.height/2)}}function B(e){let t=[];for(let n of e){let e=t[t.length-1];e&&(e[0].group??``)===(n.group??``)?e.push(n):t.push([n])}return t}function le(e,t,n){t(),setTimeout(()=>{e.run({shiftKey:n})},0)}function ue({anchor:e,items:t,onClose:n,label:r}){let i=(0,D.useRef)(null);return(0,D.useEffect)(()=>{let e=document.activeElement;return i.current?.querySelector(`[role="menuitem"]:not([aria-disabled="true"])`)?.focus(),()=>{e?.isConnected&&e.focus({preventScroll:!0})}},[]),(0,O.jsx)(M,{x:e.x,y:e.y,onClose:n,className:`min-w-[200px] rounded-lg border bg-popover text-popover-foreground py-1 shadow-elevation-3`,children:(0,O.jsx)(`div`,{ref:i,role:`menu`,"aria-label":r,onKeyDown:e=>{let t=Array.from(i.current?.querySelectorAll(`[role="menuitem"]:not([aria-disabled="true"])`)??[]);if(t.length===0)return;let r=t.indexOf(document.activeElement),a=e=>t[(e+t.length)%t.length]?.focus();switch(e.key){case`ArrowDown`:e.preventDefault(),a(r+1);return;case`ArrowUp`:e.preventDefault(),a(r<0?-1:r-1);return;case`Home`:e.preventDefault(),a(0);return;case`End`:e.preventDefault(),a(-1);return;case`Tab`:e.preventDefault(),n();return}if(e.key.length===1&&!e.ctrlKey&&!e.metaKey&&!e.altKey){let n=e.key.toLowerCase(),i=[...t.slice(r+1),...t.slice(0,r+1)].find(e=>e.textContent?.trim().toLowerCase().startsWith(n));i&&(e.preventDefault(),i.focus())}},onContextMenu:e=>e.preventDefault(),children:B(t).map((e,t)=>(0,O.jsxs)(D.Fragment,{children:[t>0&&(0,O.jsx)(`div`,{role:`separator`,className:`my-1 h-px bg-border`}),e[0].groupLabel&&(0,O.jsx)(`div`,{className:`px-3 py-1 text-[10px] font-medium uppercase tracking-wide text-muted-foreground`,children:e[0].groupLabel}),e.map(e=>{let t=e.icon;return(0,O.jsxs)(`button`,{type:`button`,role:`menuitem`,tabIndex:-1,"aria-disabled":e.disabled||void 0,title:e.hint,onClick:t=>{e.disabled||le(e,n,t.shiftKey)},className:_(`flex w-full items-center gap-2 px-3 py-1.5 text-left text-sm outline-none`,e.disabled?`cursor-default opacity-50`:e.destructive?`text-destructive hover:bg-destructive hover:text-destructive-foreground focus:bg-destructive focus:text-destructive-foreground`:`hover:bg-muted focus:bg-muted`),children:[t?(0,O.jsx)(t,{className:`h-3.5 w-3.5 shrink-0`}):(0,O.jsx)(`span`,{className:`w-3.5 shrink-0`}),(0,O.jsx)(`span`,{className:`flex-1 truncate`,children:e.label}),e.shortcut&&(0,O.jsx)(`kbd`,{className:`ml-4 shrink-0 font-sans text-[11px] text-muted-foreground`,children:F(e.shortcut)})]},e.id)})]},`${e[0].group??``}:${t}`))})})}function V({items:e,onClose:t,header:n}){w(t);let r=`flex w-full items-center gap-3 rounded-xl border bg-card px-4 py-3.5 text-base font-medium transition-transform active:scale-[.98]`;return(0,A.createPortal)((0,O.jsxs)(`div`,{role:`dialog`,"aria-modal":`true`,className:`fixed inset-0 z-fullscreen flex flex-col bg-popover text-popover-foreground animate-in slide-in-from-bottom-10 fade-in duration-normal`,onClick:t,onContextMenu:e=>e.preventDefault(),children:[(0,O.jsxs)(`div`,{className:`flex shrink-0 items-start gap-3 border-b p-4`,onClick:e=>e.stopPropagation(),children:[(0,O.jsx)(`div`,{className:`min-w-0 flex-1`,children:n}),(0,O.jsx)(`button`,{type:`button`,onClick:t,className:`rounded-sm p-2 hover:bg-muted`,title:`Close`,"aria-label":`Close`,children:(0,O.jsx)(u,{className:`h-5 w-5`})})]}),(0,O.jsx)(`div`,{className:`min-h-4 flex-1`}),(0,O.jsxs)(`div`,{className:`max-h-[75vh] shrink-0 space-y-2 overflow-y-auto px-4 pt-2`,style:{paddingBottom:`calc(var(--safe-bottom) + 1.25rem)`},onClick:e=>e.stopPropagation(),children:[B(e).map((e,n)=>(0,O.jsxs)(`div`,{className:_(`space-y-2`,n>0&&`pt-2`),children:[e[0].groupLabel&&(0,O.jsx)(`div`,{className:`px-1 text-[11px] font-medium uppercase tracking-wide text-muted-foreground`,children:e[0].groupLabel}),e.map(e=>{let n=e.icon;return(0,O.jsxs)(`button`,{type:`button`,disabled:e.disabled,onClick:n=>le(e,t,n.shiftKey),className:_(r,e.destructive&&`border-destructive/30 text-destructive`,e.disabled&&`opacity-50`),children:[n&&(0,O.jsx)(n,{className:_(`h-5 w-5 shrink-0`,!e.destructive&&`text-muted-foreground`)}),e.label]},e.id)})]},`${e[0].group??``}:${n}`)),(0,O.jsx)(`button`,{type:`button`,onClick:t,className:`${r} justify-center bg-muted`,children:`Cancel`})]})]}),window.document.body)}function de({anchor:e,items:t,onClose:n,label:r,header:i}){return t.length===0?null:ce()?(0,O.jsx)(V,{items:t,onClose:n,header:i??(r&&(0,O.jsx)(`div`,{className:`truncate text-base font-semibold`,children:r}))}):(0,O.jsx)(ue,{anchor:e,items:t,onClose:n,label:r})}function H({items:e,onNavigate:t,disabled:n,className:r,label:i=`Tree path`}){let a=(0,D.useRef)(null),o=e[e.length-1]?.path;return(0,D.useEffect)(()=>{let e=a.current;e&&(e.scrollLeft=e.scrollWidth)},[o]),(0,O.jsx)(`nav`,{"aria-label":i,className:_(`min-w-0 flex-1`,r),children:(0,O.jsx)(`ol`,{ref:a,className:`flex min-w-0 items-center gap-1 overflow-x-auto py-0.5 text-sm`,children:e.map((r,i)=>{let a=i===e.length-1,o=_(`block max-w-56 truncate rounded px-1.5 py-1`,a?`font-medium text-foreground`:`text-muted-foreground`);return(0,O.jsxs)(`li`,{className:`flex shrink-0 items-center gap-1`,children:[i>0&&(0,O.jsx)(`span`,{"aria-hidden":`true`,className:`text-muted-foreground/60`,children:`/`}),t&&!a?(0,O.jsx)(`button`,{type:`button`,title:r.path===`/`?`${r.label} (root)`:r.path,disabled:n,onClick:()=>t(r.path),className:_(o,`hover:bg-accent hover:text-foreground hover:underline focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring disabled:opacity-50`),children:r.label}):(0,O.jsx)(`span`,{title:r.path===`/`?r.label:r.path,"aria-current":a?`location`:void 0,className:o,children:r.label})]},r.path)})})})}function U(e,t){let n=e.split(`/`).filter(Boolean);return[{label:t,path:`/`},...n.map((e,t)=>({label:e,path:`/${n.slice(0,t+1).join(`/`)}`}))]}var fe={context:(0,O.jsx)(d,{className:`h-3.5 w-3.5`}),directory:(0,O.jsx)(l,{className:`h-3.5 w-3.5`}),backends:(0,O.jsx)(g,{className:`h-3.5 w-3.5`}),relations:(0,O.jsx)(m,{className:`h-3.5 w-3.5`})},pe={context:`Context tree`,directory:`Directory tree`,backends:`Backends tree`,relations:`Relations`};function W(e,t){return e===`/`?`/${t}`:`${e}/${t}`}function me(e,t){let n=(0,D.useRef)(null),r=(0,D.useRef)(!1),i=()=>{n.current&&=(clearTimeout(n.current),null)},a=e=>t=>{if(r.current){r.current=!1;return}t.detail>1||e()};return t?{guardClick:a,handlers:{onContextMenu:n=>{n.preventDefault(),n.stopPropagation(),t({clientX:n.clientX,clientY:n.clientY,path:e})},onPointerDown:a=>{if(a.pointerType!==`touch`)return;let{clientX:o,clientY:s}=a;i(),n.current=setTimeout(()=>{r.current=!0,t({clientX:o,clientY:s,path:e})},500)},onPointerUp:i,onPointerLeave:i,onPointerMove:i}}:{handlers:{},guardClick:a}}function he(e,t,n){let r=W(t,e.name);return r.toLowerCase().includes(n)||(e.label||``).toLowerCase().includes(n)?!0:e.children?.some(e=>he(e,r,n))??!1}var G=200;function ge({onConfirm:e,onCancel:t,busy:n}){let[r,i]=(0,D.useState)(``);return(0,O.jsxs)(`div`,{className:`flex min-h-11 items-center gap-2 rounded-(--card-radius) bg-card px-3 py-2.5 text-sm shadow-elevation-1`,children:[(0,O.jsx)(o,{className:`h-4 w-4 shrink-0 text-muted-foreground`}),(0,O.jsx)(`input`,{type:`text`,value:r,onChange:e=>i(e.target.value),onKeyDown:n=>{n.key===`Enter`&&r.trim()&&e(r.trim()),n.key===`Escape`&&t()},onBlur:()=>{n||t()},placeholder:`New folder name…`,autoFocus:!0,disabled:n,className:`w-full flex-1 bg-transparent text-sm outline-none placeholder:text-muted-foreground`}),n&&(0,O.jsx)(`span`,{className:`shrink-0 text-xs text-muted-foreground`,children:`Creating…`})]})}function _e({node:e,parentPath:t,query:n,selected:i,onToggle:o,onActivate:c,onRowMenu:l,createParent:u,onCreateConfirm:d,onCreateCancel:f,creating:p}){let m=W(t,e.name),h=!!e.children?.length,[g,v]=(0,D.useState)(!1),{handlers:y,guardClick:ee}=me(m,l);if(n&&!he(e,t,n))return null;let b=u===m,x=g||n.length>0||b,te=i.has(m),S=e.type===`canvas`,C=T(e);return(0,O.jsxs)(`div`,{children:[(0,O.jsxs)(`div`,{className:_(`group relative flex min-h-11 items-center gap-2 rounded-md px-3 py-2.5 cursor-pointer transition-all select-none text-sm shadow-elevation-1 hover:shadow`,`before:absolute before:left-0 before:top-0 before:bottom-0 before:w-1.5 before:transition-colors`,te?`bg-primary/[0.08] hover:bg-primary/[0.12] before:bg-primary`:`bg-card hover:bg-primary/[0.04] before:bg-transparent`),onClick:ee(()=>o(m)),onDoubleClick:e=>{e.ctrlKey||e.metaKey||e.shiftKey||e.altKey||e.target.closest(`button,input,textarea,select,a,[contenteditable="true"]`)||(e.preventDefault(),e.stopPropagation(),h?v(e=>!e):c?.(m))},title:m,...y,children:[(0,O.jsx)(`button`,{type:`button`,"aria-label":`${x?`Collapse`:`Expand`} ${e.label||e.name}`,"aria-expanded":h?x:void 0,disabled:!h,className:_(`shrink-0 text-muted-foreground hover:text-foreground`,!h&&`invisible`),onClick:e=>{e.stopPropagation(),e.detail<=1&&v(e=>!e)},children:x?(0,O.jsx)(s,{className:`w-4 h-4`}):(0,O.jsx)(a,{className:`w-4 h-4`})}),(0,O.jsx)(r,{icon:C.icon||(S?`ph:squares-four-fill`:`ph:folder-fill`),width:16,height:16,color:E(C.color),className:_(`shrink-0`,!E(C.color)&&(S?`text-primary`:`text-muted-foreground`))}),(0,O.jsx)(`span`,{className:`flex-1 truncate font-medium`,title:e.description||void 0,children:e.label||e.name})]}),x&&h||b?(0,O.jsxs)(`div`,{className:`ml-[22px] mt-1.5 space-y-1.5`,children:[b&&d&&f&&(0,O.jsx)(ge,{busy:p,onConfirm:e=>{v(!0),d(m,e)},onCancel:f}),x&&e.children?.map(e=>(0,O.jsx)(_e,{node:e,parentPath:m,query:n,selected:i,onToggle:o,onActivate:c,onRowMenu:l,createParent:u,onCreateConfirm:d,onCreateCancel:f,creating:p},e.id||e.name))]}):null]})}function ve({workspaces:e,loading:t,onPick:n}){return t&&e.length===0?(0,O.jsx)(`div`,{className:`px-2 py-3 text-xs text-muted-foreground`,children:`Loading…`}):e.length===0?(0,O.jsx)(`div`,{className:`px-2 py-3 text-xs text-muted-foreground`,children:`No workspaces found`}):(0,O.jsx)(`div`,{className:`space-y-1.5`,children:e.map(e=>{let t=E(e.color);return(0,O.jsxs)(`div`,{onClick:()=>n(e.name),className:`group relative flex cursor-pointer items-center gap-2 rounded-(--card-radius) bg-card px-3 py-2.5 shadow-elevation-1 transition-all hover:bg-accent/50 hover:shadow`,style:{borderRight:`6px solid ${t||`transparent`}`},children:[(0,O.jsx)(r,{icon:e.icon||`ph:stack-fill`,width:18,height:18,color:t,className:_(`shrink-0`,!t&&`text-muted-foreground`)}),(0,O.jsx)(`span`,{className:`flex-1 truncate text-sm font-medium`,children:e.label||e.name}),(0,O.jsx)(a,{className:`h-4 w-4 shrink-0 text-muted-foreground`})]},e.id||e.name)})})}function ye({workspaceName:e,treeTab:t,onTreeTabChange:n,selectedDocIds:r,onToggleDoc:i,onNavigate:o,excludeDocumentIds:c}){let[l,d]=(0,D.useState)(`folder`),[f,p]=(0,D.useState)(``),m=f.trim().toLowerCase(),[g,v]=(0,D.useState)(`/`),[b,x]=(0,D.useState)(null),[te,S]=(0,D.useState)(!1),[C,w]=(0,D.useState)([]),[ae,T]=(0,D.useState)(!1),[E,k]=(0,D.useState)(``),[A,j]=(0,D.useState)(``),[M,N]=(0,D.useState)(t),P=n?t:M,F=e=>{v(`/`),d(`folder`),k(``),j(``),o?.(`/`),n?n(e):N(e)},[se,I]=(0,D.useState)(P);P!==se&&(I(P),v(`/`),d(`folder`)),(0,D.useEffect)(()=>{let e=setTimeout(()=>j(E.trim()),300);return()=>clearTimeout(e)},[E]),(0,D.useEffect)(()=>{let t=!1;async function n(){S(!0);try{let n=await ee(e,P);t||x(n)}catch{t||x(null)}finally{t||S(!1)}}return n(),()=>{t=!0}},[e,P]),(0,D.useEffect)(()=>{if(l!==`documents`)return;let t=!1,n=P===`directory`?`directory`:ie,r=P===`context`?`context`:`directory`;async function i(){T(!0);try{let i=A?await ne(e,g,[],{treeName:n,treeType:r,q:A,limit:G}):await re(e,g,n,{limit:G});t||w(i.payload||[])}catch{t||w([])}finally{t||T(!1)}}return i(),()=>{t=!0}},[e,P,g,l,A]);let L=e=>{v(e),o?.(e)},R=c?.size?C.filter(e=>!c.has(e.id)):C;return l===`folder`?(0,O.jsxs)(`div`,{className:`flex min-h-0 flex-1 flex-col`,children:[(0,O.jsxs)(`div`,{className:`shrink-0 space-y-2 border-b bg-muted/30 px-3 py-2`,children:[!n&&(0,O.jsx)(`div`,{className:`flex items-center gap-1 rounded-md border border-input p-0.5`,children:[`context`,`directory`].map(e=>(0,O.jsxs)(`button`,{type:`button`,onClick:()=>F(e),className:_(`flex flex-1 items-center justify-center gap-1.5 rounded px-2 py-1 text-xs transition-colors`,P===e?`bg-primary text-primary-foreground`:`text-muted-foreground hover:bg-muted hover:text-foreground`),title:`Browse the ${pe[e].toLowerCase()}`,children:[fe[e],(0,O.jsx)(`span`,{className:`font-mono`,children:e===`directory`?`dir://`:`ctx://`})]},e))}),(0,O.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,O.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:`Step 1 of 2 · Pick a folder`}),(0,O.jsxs)(`button`,{type:`button`,onClick:()=>d(`documents`),className:`inline-flex items-center gap-1 rounded-md bg-primary px-2.5 py-1 text-xs font-medium text-primary-foreground transition-opacity hover:opacity-90`,children:[`Next `,(0,O.jsx)(a,{className:`h-3.5 w-3.5`})]})]}),(0,O.jsx)(H,{items:U(g,e),onNavigate:L,label:`Folder path`}),(0,O.jsxs)(`div`,{className:`relative`,children:[(0,O.jsx)(h,{className:`pointer-events-none absolute left-2.5 top-1/2 h-3.5 w-3.5 -translate-y-1/2 text-muted-foreground`}),(0,O.jsx)(`input`,{type:`text`,placeholder:`Filter folders…`,value:f,onChange:e=>p(e.target.value),className:`w-full rounded-md border border-input bg-background py-1.5 pl-8 pr-3 text-xs placeholder:text-muted-foreground focus:outline-none focus:ring-2 focus:ring-ring`})]})]}),(0,O.jsx)(`div`,{className:`min-h-0 flex-1 space-y-1.5 overflow-y-auto p-3`,children:te?(0,O.jsx)(`div`,{className:`px-2 py-3 text-xs text-muted-foreground`,children:`Loading…`}):(0,O.jsxs)(O.Fragment,{children:[(0,O.jsxs)(`div`,{className:_(`group relative flex min-h-11 items-center gap-2 rounded-md px-3 py-2.5 cursor-pointer transition-all select-none text-sm shadow-elevation-1 hover:shadow`,`before:absolute before:left-0 before:top-0 before:bottom-0 before:w-1.5 before:transition-colors`,g===`/`?`bg-primary/[0.08] hover:bg-primary/[0.12] before:bg-primary`:`bg-card hover:bg-primary/[0.04] before:bg-transparent`),onClick:()=>L(`/`),onDoubleClick:()=>{L(`/`),d(`documents`)},title:`/`,children:[(0,O.jsx)(s,{className:`w-4 h-4 shrink-0 text-muted-foreground`}),(0,O.jsx)(`span`,{className:`flex-1 truncate font-medium`,children:`/`})]}),(0,O.jsx)(`div`,{className:`ml-[22px] space-y-1.5`,children:b?.children?.length?b.children.map(e=>(0,O.jsx)(_e,{node:e,parentPath:`/`,query:m,selected:new Set([g]),onToggle:L,onActivate:e=>{L(e),d(`documents`)}},e.id||e.name)):(0,O.jsx)(`p`,{className:`px-2 py-1.5 text-xs text-muted-foreground`,children:`Empty tree`})})]})})]}):(0,O.jsxs)(`div`,{className:`flex min-h-0 flex-1 flex-col`,children:[(0,O.jsxs)(`div`,{className:`shrink-0 space-y-2 border-b bg-muted/30 px-3 py-2`,children:[(0,O.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,O.jsxs)(`button`,{type:`button`,onClick:()=>d(`folder`),className:`inline-flex min-w-0 items-center gap-1 rounded-md px-1.5 py-1 text-xs text-muted-foreground transition-colors hover:bg-muted hover:text-foreground`,title:`Back to folders`,children:[(0,O.jsx)(a,{className:`h-3.5 w-3.5 shrink-0 rotate-180`}),(0,O.jsx)(`span`,{children:`Folders`})]}),(0,O.jsx)(`span`,{className:`ml-auto shrink-0 text-xs text-muted-foreground`,children:`Step 2 of 2 · Pick a document`})]}),(0,O.jsxs)(`div`,{className:`flex min-w-0 items-center gap-2`,children:[(0,O.jsxs)(`span`,{className:`shrink-0 font-mono text-xs text-muted-foreground`,children:[`[`,P,`]`]}),(0,O.jsx)(H,{items:U(g,e),onNavigate:L,label:`Document folder path`})]}),(0,O.jsxs)(`div`,{className:`relative`,children:[(0,O.jsx)(h,{className:`pointer-events-none absolute left-2.5 top-1/2 h-3.5 w-3.5 -translate-y-1/2 text-muted-foreground`}),(0,O.jsx)(`input`,{type:`text`,placeholder:`Search documents in this folder…`,value:E,onChange:e=>k(e.target.value),className:`w-full rounded-md border border-input bg-background py-1.5 pl-8 pr-7 text-xs placeholder:text-muted-foreground focus:outline-none focus:ring-2 focus:ring-ring`}),E&&(0,O.jsx)(`button`,{type:`button`,onClick:()=>k(``),className:`absolute right-2 top-1/2 -translate-y-1/2 text-muted-foreground hover:text-foreground`,"aria-label":`Clear document search`,children:(0,O.jsx)(u,{className:`h-3.5 w-3.5`})})]})]}),(0,O.jsx)(`div`,{className:`min-h-0 flex-1 space-y-1 overflow-y-auto p-3`,children:ae?(0,O.jsx)(`div`,{className:`px-2 py-3 text-xs text-muted-foreground`,children:`Loading documents…`}):R.length===0?(0,O.jsx)(`div`,{className:`px-2 py-3 text-xs text-muted-foreground`,children:A?`No documents match “${A}” here.`:`No documents in this folder.`}):R.map(e=>{let t=y(e),n=r.has(e.id);return(0,O.jsxs)(`div`,{onClick:()=>i(e.id),className:_(`flex min-h-9 items-center gap-2 rounded-md px-3 py-1.5 cursor-pointer transition-all select-none text-sm`,n?`bg-primary/[0.08] hover:bg-primary/[0.12]`:`hover:bg-primary/[0.04]`),children:[(0,O.jsx)(`input`,{type:`checkbox`,checked:n,onChange:()=>i(e.id),className:`shrink-0`,onClick:e=>e.stopPropagation()}),(0,O.jsx)(oe,{document:e,size:3.5}),(0,O.jsx)(`span`,{className:`flex-1 truncate`,children:t.title})]},e.id)})})]})}function be({onClose:e,onConfirm:t,documentCount:n,fixedWorkspaceName:r,excludeWorkspace:i,multiple:o=!0,saving:l=!1,savingContent:d,sizeClassName:m,tabs:g=[`context`,`directory`],initialTab:y,title:te,confirmLabel:ne,backendFolderCreation:re,onConfirmRelation:T,relationWorkspaceName:E,relationPredicates:oe,relationExcludeIds:A}){let[M,N]=(0,D.useState)(r?`tree`:`workspace`),[P,F]=(0,D.useState)([]),[se,I]=(0,D.useState)(!r),[L,R]=(0,D.useState)(r??null),ce=y&&g.includes(y)?y:g.includes(`context`)||g.includes(`directory`)?`pins`:g[0]??`context`,[z,B]=(0,D.useState)(ce),le=j(g.includes(`relations`)&&!oe?E??L:null),V=oe??le.predicates,[de,H]=(0,D.useState)(``),U=V.includes(de)?de:V[0]??``,[W,he]=(0,D.useState)(`out`),[G,be]=(0,D.useState)(new Set),[xe,Se]=(0,D.useState)(null),[K,Ce]=(0,D.useState)(`context`),[we,Te]=(0,D.useState)(!1),Ee=z===`pins`?K:z;(0,D.useEffect)(()=>{if(!L)return;let e=!1;return b(L).then(t=>{e||Se(t)}).catch(()=>{e||Te(!0)}),()=>{e=!0}},[L]);let q=z===`relations`,[De,Oe]=(0,D.useState)(null),[ke,Ae]=(0,D.useState)(!1),[J,Y]=(0,D.useState)(new Set),[je,Me]=(0,D.useState)(``),Ne=je.trim().toLowerCase(),{showErrorToast:Pe}=ae(),[X,Fe]=(0,D.useState)(null),[Ie,Z]=(0,D.useState)(null),[Q,Le]=(0,D.useState)(!1);w(e,!l&&!Q);let Re=me(`/`,e=>Fe(e)),ze=e=>!l&&(z===`backends`?re?.canCreate(e)===!0:z!==`pins`&&z!==`relations`),Be=async(e,t)=>{let n=t.trim().replace(/^\/+|\/+$/g,``);if(!(!n||!L||Q||!ze(e))){Le(!0);try{let t=`${e===`/`?``:e}/${n}`,r=z===`context`?ie:z;z===`backends`?await re.create(e,n):await C(L,t,!0,r),S(L,r),window.dispatchEvent(new CustomEvent(`workspace:tree:refresh`,{detail:{workspaceName:L,treeName:r,cacheInvalidated:!0}}));let i=await ee(L,z);Oe(i),Y(e=>o?new Set([...e,t]):new Set([t])),Me(``),Z(null)}catch(e){Pe(e instanceof Error?e.message:`Failed to create folder`)}finally{Le(!1)}}},[Ve,He]=(0,D.useState)(r);r!==Ve&&(He(r),r||I(!0)),(0,D.useEffect)(()=>{r||x().then(e=>F(e.filter(e=>e.id!==i&&e.name!==i))).catch(()=>F([])).finally(()=>I(!1))},[r,i]),(0,D.useEffect)(()=>{if(!L||z===`relations`||z===`pins`)return;let e=!1,t=0;async function n(n=!1){let r=++t;n||Ae(!0);try{let n=await ee(L,z);!e&&r===t&&Oe(n)}catch{!e&&r===t&&!n&&Oe(null)}finally{!e&&r===t&&Ae(!1)}}let r=e=>{let t=e.detail;t?.workspaceName&&t.workspaceName!==L||t?.treeName&&t.treeName!==z||(t?.cacheInvalidated||S(L,z),n(!0))};return window.addEventListener(`workspace:tree:refresh`,r),n(),()=>{e=!0,window.removeEventListener(`workspace:tree:refresh`,r)}},[L,z]);let Ue=e=>{e!==L&&(Se(null),Te(!1)),B(ce),R(e),Y(new Set),be(new Set),N(`tree`)},We=e=>{be(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},Ge=e=>{if(!o){Y(new Set([e]));return}Y(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},Ke=q?!!U&&G.size>0&&!!T:J.size>0,qe=async()=>{if(!(!L||l||!Ke)){if(q){await T?.({predicate:U,direction:W,targetIds:Array.from(G)},{workspaceName:E??L});return}await t(Array.from(J),{workspaceName:L,treeName:Ee===`context`?ie:Ee,treeType:Ee===`context`?`context`:`directory`})}},$=n??1;return l&&d?(0,O.jsx)(`div`,{className:_(`flex flex-col overflow-hidden rounded-(--panel-radius) border bg-card shadow-elevation-4`,m||`h-viewport-card max-h-full w-[min(380px,90vw)] max-md:h-full max-md:w-full max-md:shadow-elevation-5`),children:d}):(0,O.jsxs)(`div`,{className:_(`flex flex-col overflow-hidden rounded-(--panel-radius) border bg-card shadow-elevation-4`,m||`h-viewport-card max-h-full w-[min(380px,90vw)] max-md:h-full max-md:w-full max-md:shadow-elevation-5`),children:[(0,O.jsxs)(`div`,{className:`flex h-12 shrink-0 items-center justify-between border-b px-4`,children:[(0,O.jsxs)(`span`,{className:`flex items-center gap-2 text-sm font-medium`,children:[(0,O.jsx)(p,{className:`h-4 w-4`}),te??(M===`workspace`?`Link to…`:q?`Relate ${$} document${$===1?``:`s`} to…`:`Link ${$} document${$===1?``:`s`} to…`)]}),(0,O.jsx)(`button`,{type:`button`,onClick:e,disabled:l||Q,className:`text-muted-foreground transition-colors hover:text-foreground disabled:opacity-40`,"aria-label":`Close`,children:(0,O.jsx)(u,{className:`h-4 w-4`})})]}),(0,O.jsx)(`div`,{className:`flex-1 overflow-hidden`,children:(0,O.jsxs)(`div`,{className:`grid h-full w-[200%] grid-cols-2 transition-transform duration-normal`,style:{transform:M===`workspace`?`translateX(0)`:`translateX(-50%)`},children:[(0,O.jsx)(`div`,{className:`flex min-w-0 flex-col overflow-y-auto p-2`,children:(0,O.jsx)(ve,{workspaces:P,loading:se,onPick:Ue})}),(0,O.jsxs)(`div`,{className:`flex min-w-0 flex-col overflow-hidden`,children:[(0,O.jsxs)(`div`,{className:`flex shrink-0 items-center gap-1 overflow-x-auto border-b px-2 pt-2`,children:[!r&&(0,O.jsx)(`button`,{type:`button`,disabled:Q,onClick:()=>N(`workspace`),className:`mr-1 rounded p-1.5 text-muted-foreground hover:bg-muted hover:text-foreground touch-target`,"aria-label":`Back to workspaces`,children:(0,O.jsx)(a,{className:`h-4 w-4 rotate-180`})}),(g.includes(`context`)||g.includes(`directory`))&&(0,O.jsxs)(`button`,{type:`button`,disabled:Q,onClick:()=>{B(`pins`),Y(new Set),Z(null)},className:_(`flex shrink-0 items-center gap-1.5 border-b-2 px-3 py-2 text-xs`,z===`pins`?`border-primary`:`border-transparent text-muted-foreground`),children:[(0,O.jsx)(c,{className:`h-3.5 w-3.5`}),`Pins`]}),g.map(e=>(0,O.jsxs)(`button`,{type:`button`,disabled:Q,onClick:()=>{B(e),Y(new Set),Z(null)},className:_(`flex shrink-0 items-center gap-1.5 rounded-t-md border-b-2 px-3 py-2 text-xs font-medium transition-colors`,z===e?`border-primary text-foreground`:`border-transparent text-muted-foreground hover:text-foreground`),children:[fe[e],pe[e]]},e))]}),!q&&(0,O.jsx)(`div`,{className:`shrink-0 border-b p-2`,children:(0,O.jsxs)(`div`,{className:`relative`,children:[(0,O.jsx)(h,{className:`pointer-events-none absolute left-2.5 top-1/2 h-4 w-4 -translate-y-1/2 text-muted-foreground`}),(0,O.jsx)(`input`,{type:`text`,placeholder:`Search paths…`,value:je,onChange:e=>Me(e.target.value),className:`w-full rounded-md border border-input bg-background py-2 pl-9 pr-3 text-sm placeholder:text-muted-foreground focus:outline-none focus:ring-2 focus:ring-ring`})]})}),q&&(0,O.jsxs)(`div`,{className:`shrink-0 space-y-2 border-b bg-primary/[0.04] px-3 py-2`,children:[(0,O.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,O.jsx)(`label`,{htmlFor:`relation-predicate`,className:`shrink-0 text-xs text-muted-foreground`,children:`Predicate`}),(0,O.jsx)(`select`,{id:`relation-predicate`,value:U,onChange:e=>H(e.target.value),className:`min-w-0 flex-1 rounded-md border border-input bg-background px-2 py-1.5 text-xs focus:outline-none focus:ring-2 focus:ring-ring`,children:V.map(e=>(0,O.jsx)(`option`,{value:e,children:e},e))})]}),(0,O.jsx)(`div`,{className:`flex items-center gap-1`,children:[{dir:`out`,label:`This → picked`,hint:`the ${$===1?`document`:`documents`} you started from ${U} the picked one(s)`},{dir:`in`,label:`Picked → this`,hint:`the picked document(s) ${U} the ${$===1?`one`:`ones`} you started from`}].map(({dir:e,label:t,hint:n})=>(0,O.jsx)(`button`,{type:`button`,title:n,onClick:()=>he(e),className:_(`flex-1 rounded-md border px-2 py-1.5 text-xs transition-colors`,W===e?`border-primary bg-primary text-primary-foreground`:`border-input hover:bg-accent`),children:t},e))})]}),!q&&o&&(0,O.jsxs)(`div`,{className:`flex h-10 shrink-0 items-center gap-1.5 overflow-x-auto border-b bg-primary/[0.04] px-3`,children:[!J.size&&(0,O.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:`Selected folders appear here`}),Array.from(J).map(e=>(0,O.jsxs)(`span`,{className:`inline-flex max-w-full shrink-0 items-center gap-1 rounded-full bg-primary px-2 py-0.5 text-xs text-primary-foreground`,children:[(0,O.jsx)(`span`,{className:`truncate`,title:e,children:e}),(0,O.jsx)(`button`,{type:`button`,onClick:()=>Ge(e),className:`shrink-0 rounded-full hover:bg-primary-foreground/20`,"aria-label":`Remove ${e}`,children:(0,O.jsx)(u,{className:`h-3 w-3`})})]},e))]}),q&&(E??L)&&(0,O.jsx)(ye,{workspaceName:E??L,treeTab:`context`,selectedDocIds:G,onToggleDoc:We,excludeDocumentIds:A}),z===`pins`&&(0,O.jsxs)(`div`,{className:`min-h-0 flex-1 overflow-y-auto p-3 space-y-2`,children:[!xe&&!we&&(0,O.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`Loading pins…`}),we&&(0,O.jsx)(`p`,{className:`text-xs text-destructive`,children:`Could not load pins. You can still browse the trees.`}),!we&&xe?.length===0&&(0,O.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`No pinned paths yet. Choose a path from a tree.`}),xe?.filter(e=>e.resolvable!==!1&&g.includes(e.tree===`context`?`context`:e.tree)&&`${e.label??e.name??``} ${e.path}`.toLowerCase().includes(Ne)).map(e=>{let t=e.tree===`context`?`context`:e.tree;return(0,O.jsxs)(`button`,{type:`button`,"aria-pressed":K===t&&J.has(e.path),className:_(`w-full rounded-md border p-3 text-left text-sm hover:bg-muted`,K===t&&J.has(e.path)&&`border-primary bg-primary/10`),onClick:()=>{K===t?Ge(e.path):(Ce(t),Y(new Set([e.path])))},children:[(0,O.jsxs)(`span`,{className:`flex items-center gap-2`,children:[(0,O.jsx)(c,{className:`h-3.5 w-3.5`}),e.label||e.name||e.path]}),(0,O.jsxs)(`span`,{className:`block truncate text-xs text-muted-foreground`,children:[t,` · `,e.path]})]},e.id)})]}),(0,O.jsx)(`div`,{className:_(`min-h-0 flex-1 space-y-1.5 overflow-y-auto p-3`,(q||z===`pins`)&&`hidden`),children:ke?(0,O.jsx)(`div`,{className:`px-2 py-3 text-xs text-muted-foreground`,children:`Loading…`}):(0,O.jsxs)(O.Fragment,{children:[(0,O.jsxs)(`div`,{className:_(`group relative flex min-h-11 items-center gap-2 rounded-md px-3 py-2.5 cursor-pointer transition-all select-none text-sm shadow-elevation-1 hover:shadow`,`before:absolute before:left-0 before:top-0 before:bottom-0 before:w-1.5 before:transition-colors`,J.has(`/`)?`bg-primary/[0.08] hover:bg-primary/[0.12] before:bg-primary`:`bg-card hover:bg-primary/[0.04] before:bg-transparent`),onClick:Re.guardClick(()=>Ge(`/`)),title:`/`,...ze(`/`)?Re.handlers:{},children:[(0,O.jsx)(s,{className:`w-4 h-4 shrink-0 text-muted-foreground`}),(0,O.jsx)(`span`,{className:`flex-1 truncate font-medium`,children:`/`})]}),(0,O.jsxs)(`div`,{className:`ml-[22px] space-y-1.5`,children:[Ie===`/`&&(0,O.jsx)(ge,{busy:Q,onConfirm:e=>Be(`/`,e),onCancel:()=>Z(null)}),De?.children?.length?De.children.map(e=>(0,O.jsx)(_e,{node:e,parentPath:`/`,query:Ne,selected:J,onToggle:Ge,onRowMenu:e=>{ze(e.path)&&Fe(e)},createParent:Ie,onCreateConfirm:Be,onCreateCancel:()=>Z(null),creating:Q},e.id||e.name)):Ie===`/`?null:(0,O.jsx)(`p`,{className:`px-2 py-1.5 text-xs text-muted-foreground`,children:`Empty tree`})]})]})})]})]})}),M===`tree`&&(0,O.jsxs)(`div`,{className:`flex shrink-0 items-center justify-between border-t px-4 py-3`,children:[(0,O.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:q?`${G.size} document${G.size===1?``:`s`} selected`:`${J.size} path${J.size===1?``:`s`} selected`}),(0,O.jsx)(v,{size:`sm`,onClick:qe,disabled:!Ke||l||Q,children:l?(0,O.jsxs)(O.Fragment,{children:[(0,O.jsx)(k,{className:`mr-1.5 h-3.5 w-3.5`}),q?`Relating…`:`Linking…`]}):(0,O.jsxs)(O.Fragment,{children:[(0,O.jsx)(p,{className:`mr-1 h-3.5 w-3.5`}),q?`Relate`:ne??`Link`]})})]}),X&&(0,O.jsx)(ue,{anchor:{x:X.clientX,y:X.clientY},onClose:()=>Fe(null),items:[{id:`new-folder`,label:`New folder in ${X.path}`,icon:f,run:()=>Z(X.path)}]})]})}export{k as _,pe as a,de as c,F as d,R as f,j as g,M as h,fe as i,z as l,se as m,ye as n,U as o,I as p,ve as r,H as s,be as t,L as u};
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/pdf-Ciz5_WNq.js","assets/preload-helper-Czpn1I53.js","assets/TextDocumentEditor-CRre32cj.js","assets/rolldown-runtime-C0FnF6B9.js","assets/code-editor-BOIngd5F.js","assets/ui-Byg1cZDr.js","assets/react-BHzhHVTZ.js","assets/button-SgR3GVvV.js","assets/utils-BxVxyehK.js","assets/utils-2pl1SbIp.js","assets/workspace-CrSpR4xf.js","assets/input-BOtCd4HP.js","assets/api-CA6WiiYM.js","assets/alert-dialog-izlVMXfa.js","assets/text-documents-0P9jkIpu.js","assets/public-share-g_wBd6BW.js","assets/blobs-WiXP9QRi.js","assets/useToastHelpers-CRrpIIdY.js","assets/use-toast-BlLDqSUO.js","assets/note-save-status-DPz4VzL6.js","assets/useEditNoteFields-BehI0vog.js","assets/tags-YamdPoBK.js","assets/DocumentBodyEditor-8DNmOBS0.js","assets/lazy-editor-BSRnneOo.js","assets/EditorOverlay-Cv1MaTok.js","assets/LocationTab-DAtqAQ3l.js","assets/map-BxCwdK0d.js","assets/map-BcsP_QXj.css"])))=>i.map(i=>d[i]);
|
|
2
|
-
import{o as e}from"./rolldown-runtime-C0FnF6B9.js";import{l as t,u as n}from"./code-editor-BOIngd5F.js";import{_t as r,yt as i}from"./react-BHzhHVTZ.js";import{t as a}from"./preload-helper-Czpn1I53.js";import{$t as o,At as s,Dr as c,Dt as l,Er as u,Et as d,Hn as f,It as p,J as m,Jr as h,Kn as g,L as _,Nn as v,Nt as y,On as b,Rt as x,Ur as S,Vt as C,Wn as w,X as T,Yr as E,Zr as D,_r as O,an as k,ar as A,cr as j,ct as M,di as ee,dr as N,fn as P,gn as F,jn as te,li as I,mt as ne,nr as L,nt as R,on as z,pr as B,qr as re,sn as V,tr as H,wr as U,yr as W,yt as ie,zn as ae,zt as oe}from"./ui-Byg1cZDr.js";import{t as G}from"./utils-2pl1SbIp.js";import{t as K}from"./button-SgR3GVvV.js";import{t as se}from"./input-BOtCd4HP.js";import{t as q}from"./label-Dn4gCMcc.js";import{l as J}from"./api-CA6WiiYM.js";import{_ as ce,g as le,o as ue,t as de}from"./LinkToCard-5dg0jvSY.js";import{An as fe,At as pe,Gt as me,Hn as he,J as ge,Ln as _e,Mn as Y,N as ve,O as ye,P as be,Pn as xe,Un as Se,Vn as Ce,Wn as we,X as Te,Y as Ee,_ as De,bn as Oe,bt as ke,c as Ae,i as je,mn as Me,nt as Ne,s as Pe,u as Fe,wn as Ie,zn as Le}from"./workspace-CrSpR4xf.js";import{r as Re,t as ze}from"./use-mobile-Db-vWu9Y.js";import{a as Be,c as Ve,i as He,n as Ue,o as We,r as Ge,s as Ke,t as qe}from"./IdentityFields-Bti7ojF3.js";import{i as Je,r as Ye}from"./public-share-g_wBd6BW.js";import{a as Xe,i as Ze,n as Qe,o as $e,r as et,s as tt,t as nt}from"./text-documents-0P9jkIpu.js";import{t as rt}from"./useDocumentThumbnail-DunxmU1A.js";import{t as it}from"./markdown-view-BBBZtNSR.js";import{n as at,t as ot}from"./tags-YamdPoBK.js";import{n as st,t as ct}from"./relation-events-CKio19hE.js";import{a as lt,i as ut,r as dt,s as ft}from"./date-time-picker-DebNUTx3.js";import{t as pt}from"./sanitize-DrVcFY1Q.js";import{t as mt}from"./useEscapeClose-DR_xKT_k.js";import{t as X}from"./useToastHelpers-CRrpIIdY.js";import"./layer-style-Byl5LNFR.js";import{t as ht}from"./DocumentIcon-x299QNu_.js";import{r as gt,s as _t,t as vt}from"./MessageComposerDialog-gbD0Gu_b.js";import{n as yt}from"./LinkToSidePanel-eCy3nW4R.js";import{t as bt}from"./note-save-status-DPz4VzL6.js";import{t as xt}from"./useEditNoteFields-BehI0vog.js";import{t as St}from"./DocumentBodyEditor-8DNmOBS0.js";import{n as Ct}from"./use-document-modal-PG8bQyIB.js";import{t as wt}from"./sketch-lazy-C4pjV1WK.js";import{r as Tt}from"./geo-CZfs0E-x.js";var Z=e(n(),1);function Et(e,t){let n=/(^|\s)(!?)@([a-z-]*)$/i.exec(e);if(!n)return null;let r=n[3].toLowerCase();return{before:e.slice(0,n.index)+n[1]+n[2],predicates:t.filter(e=>e.startsWith(r))}}var Q=t();function Dt({workspaceId:e,inputRef:t,onChange:n}){let[r,i]=(0,Z.useState)(``),[a,o]=(0,Z.useState)(!1),[s,c]=(0,Z.useState)(0),l=le(e),u=Et(r,l.predicates),d=!!e&&a&&u!==null,f=u?.predicates??[],p=(0,Z.useId)(),m=Math.min(s,Math.max(0,f.length-1));(0,Z.useEffect)(()=>{d&&document.getElementById(`${p}-${m}`)?.scrollIntoView({block:`nearest`})},[p,m,d,f.length]);let h=e=>{let r=t.current;if(!r||!u)return;let a=`${u.before}@${e}: `;r.value=a,n?.(a),i(a),o(!1),r.focus()};return(0,Z.useEffect)(()=>{let e=t.current;if(!e)return;let n=()=>{i(e.value),c(0),o(!0)},r=()=>o(!1),a=e=>{!d||e.isComposing||(e.key===`Escape`?(e.preventDefault(),e.stopPropagation(),o(!1)):f.length&&[`ArrowDown`,`ArrowUp`,`Enter`,`Tab`].includes(e.key)&&(e.preventDefault(),e.stopPropagation(),e.key===`ArrowDown`?c((m+1)%f.length):e.key===`ArrowUp`?c((m+f.length-1)%f.length):h(f[m])))};return e.addEventListener(`input`,n),e.addEventListener(`focus`,n),e.addEventListener(`blur`,r),e.addEventListener(`keydown`,a),e.setAttribute(`role`,`combobox`),e.setAttribute(`aria-autocomplete`,`list`),e.setAttribute(`aria-expanded`,String(d)),d?e.setAttribute(`aria-controls`,p):e.removeAttribute(`aria-controls`),d&&f.length?e.setAttribute(`aria-activedescendant`,`${p}-${m}`):e.removeAttribute(`aria-activedescendant`),()=>{e.removeEventListener(`input`,n),e.removeEventListener(`focus`,n),e.removeEventListener(`blur`,r),e.removeEventListener(`keydown`,a);for(let t of[`role`,`aria-autocomplete`,`aria-expanded`,`aria-controls`,`aria-activedescendant`])e.removeAttribute(t)}}),d?(0,Q.jsxs)(`div`,{className:`absolute left-0 right-0 top-full z-50 mt-1 max-h-64 overflow-y-auto rounded-md border bg-popover p-1 text-popover-foreground shadow-lg`,children:[(0,Q.jsx)(`div`,{id:p,role:`listbox`,"aria-label":`Relation predicates`,children:f.map((e,t)=>(0,Q.jsxs)(`button`,{id:`${p}-${t}`,type:`button`,role:`option`,"aria-selected":t===m,className:`block w-full rounded px-3 py-2 text-left text-sm font-mono ${t===m?`bg-accent text-accent-foreground`:`hover:bg-accent`}`,onMouseDown:e=>e.preventDefault(),onClick:()=>h(e),children:[`@`,e,`:`]},e))}),!f.length&&(0,Q.jsx)(`p`,{role:`status`,className:`px-3 py-2 text-sm text-muted-foreground`,children:l.loading?`Loading relations…`:l.error?`Unable to load relation predicates.`:`No matching predicates.`})]}):null}var Ot=1,kt=8,At=320,jt=28,Mt=2.5,Nt={scale:1,x:0,y:0};function Pt({src:e,alt:t,className:n=``,onZoomChange:r}){let i=(0,Z.useRef)(null),a=(0,Z.useRef)(null),[o,s]=(0,Z.useState)(Nt),c=(0,Z.useRef)(new Map),l=(0,Z.useRef)(null),u=(0,Z.useRef)(null),d=(0,Z.useRef)(!1),f=(0,Z.useRef)(null),[p,m]=(0,Z.useState)(!1),[h,g]=(0,Z.useState)(e);h!==e&&(g(e),s(Nt)),(0,Z.useEffect)(()=>{r?.(o.scale>1.001)},[o.scale,r]);let _=(0,Z.useCallback)(e=>{let t=i.current,n=a.current;if(!t||!n)return e;let r=Math.min(kt,Math.max(Ot,e.scale)),o=Math.max(0,(n.offsetWidth*r-t.clientWidth)/2),s=Math.max(0,(n.offsetHeight*r-t.clientHeight)/2);return{scale:r,x:Math.min(o,Math.max(-o,e.x)),y:Math.min(s,Math.max(-s,e.y))}},[]),v=(0,Z.useCallback)((e,t,n)=>{let r=i.current;if(!r)return;let a=r.getBoundingClientRect(),o=t-a.left-a.width/2,c=n-a.top-a.height/2;s(t=>{let n=e/t.scale;return _({scale:e,x:o-(o-t.x)*n,y:c-(c-t.y)*n})})},[_]),y=(0,Z.useCallback)(()=>{let e=i.current,t=a.current;if(!e||!t||!t.offsetWidth||!t.offsetHeight)return Mt;let n=Math.max(e.clientWidth/t.offsetWidth,e.clientHeight/t.offsetHeight),r=Math.max(t.naturalWidth/t.offsetWidth,t.naturalHeight/t.offsetHeight)||kt;return Math.min(kt,Math.max(Mt,Math.min(Math.max(n,Mt),r)))},[]),b=(0,Z.useCallback)((e,t)=>{o.scale>1.001?s(Nt):v(y(),e,t)},[o.scale,v,y]),x=e=>{if(c.current.set(e.pointerId,{x:e.clientX,y:e.clientY}),d.current=!1,c.current.size===2){let[e,t]=[...c.current.values()];l.current={dist:Math.hypot(e.x-t.x,e.y-t.y),scale:o.scale,cx:(e.x+t.x)/2,cy:(e.y+t.y)/2}}e.currentTarget.setPointerCapture(e.pointerId)},S=e=>{let t=c.current.get(e.pointerId);if(!t)return;if(c.current.set(e.pointerId,{x:e.clientX,y:e.clientY}),c.current.size>=2&&l.current){let[e,t]=[...c.current.values()],n=Math.hypot(e.x-t.x,e.y-t.y);l.current.dist>0&&(d.current=!0,m(!0),v(l.current.scale*(n/l.current.dist),l.current.cx,l.current.cy));return}if(o.scale<=1.001)return;let n=e.clientX-t.x,r=e.clientY-t.y;(Math.abs(n)>1||Math.abs(r)>1)&&(d.current=!0,m(!0)),s(e=>_({...e,x:e.x+n,y:e.y+r}))},C=e=>{if(c.current.delete(e.pointerId),c.current.size<2&&(l.current=null),c.current.size===0&&m(!1),d.current){u.current=null;return}let t=e.timeStamp,n=u.current;if(n&&t-n.t<At&&Math.hypot(e.clientX-n.x,e.clientY-n.y)<jt){u.current=null,f.current=t,b(e.clientX,e.clientY);return}u.current={t,x:e.clientX,y:e.clientY}},w=e=>{e.preventDefault();let t=o.scale*(e.deltaY<0?1.15:1/1.15);t<=Ot?s(Nt):v(Math.min(kt,t),e.clientX,e.clientY)},T=o.scale>1.001;return(0,Q.jsx)(`div`,{ref:i,className:`relative flex h-full w-full items-center justify-center overflow-hidden`,style:{touchAction:`none`,cursor:T?`grab`:`zoom-in`},onPointerDown:x,onPointerMove:S,onPointerUp:C,onPointerCancel:e=>{c.current.delete(e.pointerId),l.current=null,u.current=null,d.current=!0,c.current.size===0&&m(!1)},onWheel:w,onDoubleClick:e=>{e.preventDefault(),e.stopPropagation(),!(f.current!==null&&e.timeStamp-f.current<At)&&b(e.clientX,e.clientY)},children:(0,Q.jsx)(`img`,{ref:a,src:e,alt:t,draggable:!1,className:n,style:{transform:`translate3d(${o.x}px, ${o.y}px, 0) scale(${o.scale})`,transformOrigin:`center center`,transition:p?`none`:`transform var(--duration-normal) ease-out`,willChange:`transform`}})})}function Ft(){return!/android|iphone|ipad|mobile/i.test(navigator.userAgent)&&navigator.pdfViewerEnabled!==!1}var It=40,Lt=1600;function Rt({blob:e,filename:t}){let n=(0,Z.useRef)(null),[r,i]=(0,Z.useState)({error:null,pages:0,truncated:!1});return(0,Z.useEffect)(()=>{let r=n.current;if(!r)return;let o=!1,s=null;return(async()=>{let n=await a(()=>import(`./pdf-Ciz5_WNq.js`),__vite__mapDeps([0,1])),c=(await a(async()=>{let{default:e}=await import(`./pdf.worker.min-C8Ts8bNu.js`);return{default:e}},[])).default;n.GlobalWorkerOptions.workerSrc=c;let l=await e.arrayBuffer();if(o)return;let u=n.getDocument({data:l});s=()=>{u.destroy()};let d=await u.promise;if(o)return;let f=Math.min(d.numPages,It),p=r.clientWidth||600,m=window.devicePixelRatio||1;for(let e=1;e<=f;e++){if(o)return;let n=await d.getPage(e),a=n.getViewport({scale:1}),s=Math.min(p*m,Lt*m)/a.width,c=n.getViewport({scale:s}),l=document.createElement(`canvas`);if(l.width=c.width,l.height=c.height,l.style.width=`100%`,l.style.height=`auto`,l.className=`rounded border bg-white`,l.setAttribute(`aria-label`,`${t}, page ${e}`),await n.render({canvas:l,viewport:c}).promise,n.cleanup(),o)return;r.appendChild(l),i({error:null,pages:e,truncated:d.numPages>It})}})().catch(e=>{o||i(t=>({...t,error:e instanceof Error?e.message:String(e)}))}),()=>{o=!0,s?.(),r.replaceChildren()}},[e,t]),(0,Q.jsxs)(`div`,{className:`space-y-2`,children:[r.error&&(0,Q.jsxs)(`p`,{className:`text-sm text-destructive`,children:[`Could not render PDF: `,r.error]}),!r.error&&r.pages===0&&(0,Q.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`Rendering PDF…`}),(0,Q.jsx)(`div`,{ref:n,className:`space-y-2`}),r.truncated&&(0,Q.jsxs)(`p`,{className:`text-xs text-muted-foreground`,children:[`Showing the first `,It,` pages. Download the file for the full document.`]})]})}function zt({blob:e,blobUrl:t,filename:n,className:r=``}){let i=(0,Z.useMemo)(()=>e&&e.type!==`application/pdf`?URL.createObjectURL(e.slice(0,e.size,`application/pdf`)):null,[e]);return(0,Z.useEffect)(()=>()=>{i&&URL.revokeObjectURL(i)},[i]),Ft()||!e?(0,Q.jsx)(`div`,{className:`min-h-[300px] ${r}`,children:(0,Q.jsx)(`iframe`,{src:i??t,className:`h-full min-h-[300px] w-full rounded border`,title:n})}):(0,Q.jsx)(`div`,{className:`max-h-viewport-pane overflow-y-auto ${r}`,children:(0,Q.jsx)(Rt,{blob:e,filename:n})})}function Bt({workspaceId:e,document:t}){let{download:n}=Ye(e),[r,i]=(0,Z.useState)(!1),a=Y(t)||`document-${t.id}`;return(0,Q.jsxs)(`button`,{type:`button`,onClick:async()=>{i(!0);try{await n(t.id,a)}finally{i(!1)}},disabled:r,className:`inline-flex items-center gap-1.5 rounded-md border px-2.5 py-1 text-xs text-muted-foreground transition-colors hover:bg-accent hover:text-foreground disabled:opacity-50`,children:[(0,Q.jsx)(O,{className:`h-3.5 w-3.5`}),r?`Preparing…`:`Download`]})}var Vt=1600;function Ht({error:e,loading:t,children:n}){return e?(0,Q.jsx)(`p`,{className:`text-sm text-destructive`,children:e}):t?(0,Q.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`Loading preview...`}):(0,Q.jsx)(Q.Fragment,{children:n})}function Ut({workspaceId:e,document:t,className:n=``}){let r=(0,Z.useContext)(Ve),i=ze(),a=Re(`(pointer: coarse)`),{blobUrl:o,error:s,loading:c}=rt(e,t.id,Vt,{version:t.checksumArray?.[0]??null}),{fetchBlob:l}=Ye(e),u=Y(t)||`document-${t.id}`,[d,f]=(0,Z.useState)(!1);return(0,Q.jsx)(Ht,{error:s,loading:c,children:o&&(0,Q.jsxs)(`div`,{className:`flex h-full min-h-0 flex-col gap-2 ${n}`,children:[i||a?(0,Q.jsx)(`div`,{className:`min-h-0 flex-1`,children:(0,Q.jsx)(Pt,{src:o,alt:u,className:`max-h-full max-w-full object-contain`})}):(0,Q.jsx)(`img`,{src:o,alt:u,draggable:!1,onDoubleClick:r?e=>{e.preventDefault(),e.stopPropagation(),r()}:void 0,title:r?`Double-click to maximize or restore`:void 0,className:`min-h-0 w-full flex-1 object-contain ${r?`cursor-zoom-in`:``}`}),(0,Q.jsxs)(`button`,{type:`button`,onClick:async()=>{f(!0);try{let{blob:e}=await l(t.id),n=URL.createObjectURL(e),r=window.document.createElement(`a`);r.href=n,r.download=u,window.document.body.appendChild(r),r.click(),r.remove(),setTimeout(()=>URL.revokeObjectURL(n),3e4)}finally{f(!1)}},disabled:d,className:`inline-flex shrink-0 self-start items-center gap-1.5 rounded-md border px-2.5 py-1 text-xs text-muted-foreground transition-colors hover:bg-accent hover:text-foreground disabled:opacity-50`,children:[(0,Q.jsx)(O,{className:`h-3.5 w-3.5`}),d?`Preparing…`:`Download original`]})]})})}function Wt({workspaceId:e,document:t,className:n=``}){let{src:r,error:i,loading:a}=tt(e,t.id);return(0,Q.jsx)(Ht,{error:i,loading:a,children:r&&(0,Q.jsxs)(`div`,{className:`space-y-2 ${n}`,children:[(0,Q.jsx)(`audio`,{src:r,controls:!0,preload:`metadata`,className:`w-full`}),(0,Q.jsx)(Bt,{workspaceId:e,document:t})]})})}function Gt({workspaceId:e,document:t,className:n=``}){let{src:r,error:i,loading:a}=tt(e,t.id),[o,s]=(0,Z.useState)(!1);return(0,Q.jsx)(Ht,{error:i,loading:a,children:r&&(0,Q.jsxs)(`div`,{className:`space-y-2 ${n}`,children:[(0,Q.jsx)(`video`,{src:r,controls:!0,playsInline:!0,preload:`metadata`,onError:()=>s(!0),className:`max-h-viewport-pane w-full rounded border`}),o&&(0,Q.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`This video can’t be played inline in your browser. Download it to view.`}),(0,Q.jsx)(Bt,{workspaceId:e,document:t})]})})}function Kt({workspaceId:e,document:t,className:n=``}){let{blobUrl:r,blob:i,error:a,loading:o}=$e(e,t.id,{typeHint:`application/pdf`}),s=Y(t)||`document-${t.id}`;return(0,Q.jsx)(Ht,{error:a,loading:o,children:r&&(0,Q.jsxs)(`div`,{className:`flex h-full min-h-0 flex-col gap-2 ${n}`,children:[(0,Q.jsx)(zt,{blob:i,blobUrl:r,filename:s,className:`min-h-0 flex-1`}),(0,Q.jsx)(`div`,{children:(0,Q.jsx)(Bt,{workspaceId:e,document:t})})]})})}function qt({workspaceId:e,document:t,className:n=``}){let{text:r,error:i,loading:a}=$e(e,t.id,{mode:`text`,version:t.checksumArray?.[0]});return i?(0,Q.jsx)(`p`,{className:`text-sm text-destructive`,children:i}):a||r==null?(0,Q.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`Loading...`}):(0,Q.jsx)(`pre`,{className:`bg-muted p-3 rounded text-xs overflow-auto max-h-viewport-pane whitespace-pre-wrap ${n}`,children:r})}function Jt({workspaceId:e,document:t,className:n=``}){let r=t.schema===Le,{text:i,error:a,loading:o}=$e(e,t.id,{mode:`text`,enabled:!r,version:t.checksumArray?.[0]});return r?(0,Q.jsxs)(`div`,{className:`markdown-note space-y-3 ${n}`,children:[t.data?.title?(0,Q.jsx)(`h3`,{className:`text-lg font-semibold`,children:String(t.data.title)}):null,(0,Q.jsx)(`div`,{className:`markdown-document-frame rounded-md border border-input bg-transparent`,children:(0,Q.jsx)(it,{content:String(t.data?.content??``),className:`markdown-doc px-4 py-3`})})]}):a?(0,Q.jsx)(`p`,{className:`text-sm text-destructive`,children:a}):o||i==null?(0,Q.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`Loading...`}):(0,Q.jsx)(`div`,{className:`markdown-document-frame rounded-md border border-input bg-transparent overflow-auto max-h-viewport-pane ${n}`,children:(0,Q.jsx)(it,{content:i,className:`markdown-doc px-4 py-3`})})}function Yt({document:e,className:t=``}){let n=String(e.data?.url??e.data?.uri??``),r=we(n);return r?(0,Q.jsx)(`div`,{className:`aspect-video w-full ${t}`,children:(0,Q.jsx)(`iframe`,{src:`https://www.youtube-nocookie.com/embed/${encodeURIComponent(r)}`,title:String(e.data?.title??e.data?.label??`YouTube video`),className:`h-full w-full rounded border`,allow:`accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture`,allowFullScreen:!0})}):null}function Xt({document:e,className:t=``}){let n=String(e.data?.url??e.data?.uri??``),[r,i]=(0,Z.useState)({blobUrl:null,blob:null,failed:!1,loading:!0}),[a,o]=(0,Z.useState)(n);n!==a&&(o(n),i({blobUrl:null,blob:null,failed:!1,loading:!0})),(0,Z.useEffect)(()=>{let e=!1,t=null,r=async e=>{if(!e.ok)throw Error(`HTTP ${e.status}`);let t=await e.blob();return new Blob([t],{type:`application/pdf`})},a=()=>{let e=localStorage.getItem(`authToken`);return fetch(`${J}/proxy/pdf?url=${encodeURIComponent(n)}`,{headers:e?{Authorization:`Bearer ${e}`}:{}})};return fetch(n).then(r).catch(()=>a().then(r)).then(n=>{e||(t=URL.createObjectURL(n),i({blobUrl:t,blob:n,failed:!1,loading:!1}))}).catch(()=>{e||i({blobUrl:null,blob:null,failed:!0,loading:!1})}),()=>{e=!0,t&&URL.revokeObjectURL(t)}},[n]);let{blobUrl:s,blob:c,failed:l,loading:u}=r,d=(()=>{try{let e=decodeURIComponent(new URL(n).pathname.split(`/`).filter(Boolean).pop()??``)||`document`;return/\.pdf$/i.test(e)?e:`${e}.pdf`}catch{return`document.pdf`}})();return(0,Q.jsxs)(`div`,{className:`flex h-full min-h-0 flex-col gap-2 ${t}`,children:[(0,Q.jsxs)(`div`,{className:`flex shrink-0 flex-wrap items-center gap-3`,children:[(0,Q.jsxs)(`a`,{href:n,target:`_blank`,rel:`noopener noreferrer`,className:`inline-flex items-center gap-1 text-xs text-primary hover:underline`,children:[(0,Q.jsx)(B,{className:`h-3 w-3`}),` `,n]}),c&&(0,Q.jsxs)(`button`,{type:`button`,onClick:()=>{if(!c)return;let e=URL.createObjectURL(c),t=window.document.createElement(`a`);t.href=e,t.download=d,window.document.body.appendChild(t),t.click(),t.remove(),setTimeout(()=>URL.revokeObjectURL(e),3e4)},className:`inline-flex items-center gap-1.5 rounded-md border px-2.5 py-1 text-xs text-muted-foreground transition-colors hover:bg-accent hover:text-foreground`,children:[(0,Q.jsx)(O,{className:`h-3.5 w-3.5`}),` Download`]})]}),u&&(0,Q.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`Loading PDF…`}),l&&(0,Q.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`Inline preview unavailable (direct fetch and server proxy both failed). Use the link above.`}),s&&(0,Q.jsx)(zt,{blob:c,blobUrl:s,filename:d,className:`min-h-[300px] flex-1`})]})}function Zt(e){if(!e)return!1;try{let t=new URL(e);return!!(/\.pdf$/i.test(t.pathname)||t.hostname.endsWith(`arxiv.org`)&&t.pathname.startsWith(`/pdf/`))}catch{return!1}}function Qt(e){try{return new URL(e).hostname.replace(/^www\./,``)}catch{return e}}function $t({document:e,className:t=``}){let n=e.data||{},r=String(n.url??n.uri??``),i=String(n.title??n.label??``)||Qt(r),a=typeof n.favIconUrl==`string`?n.favIconUrl:``,o=n.pinned===!0,s=typeof n.timestamp==`string`?n.timestamp:null,[c,l]=(0,Z.useState)(!1);return(0,Q.jsxs)(`div`,{className:`space-y-3 ${t}`,children:[(0,Q.jsxs)(`a`,{href:r,target:`_blank`,rel:`noopener noreferrer`,className:`group flex items-start gap-3 rounded-lg border bg-card p-3 transition-colors hover:bg-accent/40`,children:[(0,Q.jsx)(`div`,{className:`mt-0.5 flex h-9 w-9 shrink-0 items-center justify-center overflow-hidden rounded bg-muted`,children:a&&!c?(0,Q.jsx)(`img`,{src:a,alt:``,className:`h-5 w-5`,onError:()=>l(!0)}):(0,Q.jsx)(f,{className:`h-4 w-4 text-muted-foreground`})}),(0,Q.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,Q.jsx)(`span`,{className:`truncate font-medium leading-tight`,children:i}),o&&(0,Q.jsx)(p,{className:`h-3 w-3 shrink-0 fill-warning text-warning`})]}),(0,Q.jsx)(`div`,{className:`mt-0.5 truncate text-xs text-muted-foreground`,children:Qt(r)}),(0,Q.jsx)(`div`,{className:`mt-1 truncate font-mono text-[11px] text-muted-foreground/70`,children:r})]}),(0,Q.jsx)(B,{className:`mt-1 h-4 w-4 shrink-0 text-muted-foreground reveal-on-hover`})]}),s&&(0,Q.jsxs)(`p`,{className:`text-xs text-muted-foreground`,children:[`Saved `,new Date(s).toLocaleString()]})]})}function en(e){return e.data||{}}var tn={pending:`bg-muted text-muted-foreground`,"in-progress":`bg-info/15 text-info dark:text-info`,completed:`bg-success/15 text-success dark:text-success`,cancelled:`bg-muted text-muted-foreground line-through`};function nn(e){if(!e.dueDate||e.status===`completed`||e.status===`cancelled`)return!1;let t=new Date(e.dueDate).getTime();return Number.isFinite(t)&&t<Date.now()}function rn(e){if(!e)return``;let t=new Date(e);return Number.isNaN(t.getTime())?``:t.toLocaleString(void 0,{month:`short`,day:`numeric`,hour:`2-digit`,minute:`2-digit`})}async function an(e,t,n){let r=n===`completed`,i={...t.data||{},status:n,completed:r};r?i.completedAt=new Date().toISOString():delete i.completedAt,await Oe(e,{id:t.id,schema:t.schema,schemaVersion:t.schemaVersion,data:i}),window.dispatchEvent(new CustomEvent(`workspace:documents:refresh`))}function on({document:e,workspaceId:t,className:n=``}){let r=en(e),i=Je()!=null,[a,o]=(0,Z.useState)(!1),{replicating:s,label:c}=Ie(e),l=r.status===`completed`,u=r.status??`pending`,d=nn(r);return(0,Q.jsx)(`div`,{className:`space-y-3 ${n}`,children:(0,Q.jsxs)(`div`,{className:`relative flex items-start gap-3 rounded-lg border bg-card p-3 transition-opacity ${s?`opacity-60`:``}`,children:[(0,Q.jsx)(`button`,{type:`button`,onClick:async()=>{if(!(i||a)){o(!0);try{await an(t,e,l?`pending`:`completed`)}catch{}finally{o(!1)}}},disabled:i||a||s,"aria-pressed":l,title:l?`Mark not done`:`Mark done`,className:`mt-0.5 flex h-5 w-5 shrink-0 items-center justify-center rounded border transition-colors ${l?`border-success bg-success text-success-foreground`:`border-input hover:border-success`} ${i?`cursor-default opacity-70`:``}`,children:a?(0,Q.jsx)(P,{className:`h-3 w-3 animate-spin`}):l&&(0,Q.jsx)(S,{className:`h-3.5 w-3.5`})}),(0,Q.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,Q.jsx)(`div`,{className:`font-medium leading-tight ${l?`text-muted-foreground line-through`:``}`,children:r.title||`Todo ${e.id}`}),(0,Q.jsxs)(`div`,{className:`mt-1.5 flex flex-wrap items-center gap-2 text-xs`,children:[(0,Q.jsx)(`span`,{className:`rounded-full px-2 py-0.5 ${tn[u]}`,children:dt[u]}),r.dueDate&&(0,Q.jsxs)(`span`,{className:`inline-flex items-center gap-1 ${d?`font-medium text-destructive`:`text-muted-foreground`}`,children:[(0,Q.jsx)(re,{className:`h-3 w-3`}),rn(r.dueDate),d?` · overdue`:``]}),typeof r.priority==`number`&&(0,Q.jsxs)(`span`,{className:`inline-flex items-center gap-1 text-muted-foreground`,children:[(0,Q.jsx)(H,{className:`h-3 w-3`}),`P`,r.priority]})]}),r.description&&(0,Q.jsx)(it,{content:String(r.description),className:`mt-2 text-sm text-muted-foreground`}),s&&(0,Q.jsxs)(`div`,{className:`mt-2 inline-flex items-center gap-1.5 text-xs text-muted-foreground`,role:`status`,children:[(0,Q.jsx)(P,{className:`h-3 w-3 animate-spin`}),c]})]})]})})}function sn(e,t){let{fetchBlob:n}=Ye(e),r=Je(),i=t.checksumArray?.[0]||t.updatedAt||``,a=JSON.stringify([e,r,t.id,i]),o=typeof t.data?.body==`string`?t.data.body:null,s=typeof t.data?.bodyHtml==`string`?t.data.bodyHtml:null,c=o!==null||s!==null,[l,u]=(0,Z.useState)(null);return(0,Z.useEffect)(()=>{if(c)return;let e=new AbortController;return n(t.id,{format:`email`,version:i,signal:e.signal}).then(async({blob:t})=>{let n=JSON.parse(await t.text());if(typeof n.body!=`string`||n.bodyHtml!=null&&typeof n.bodyHtml!=`string`)throw Error(`Invalid email content response`);e.signal.aborted||u({key:a,body:n.body,bodyHtml:n.bodyHtml||null,error:null})}).catch(t=>{e.signal.aborted||u({key:a,body:``,bodyHtml:null,error:t instanceof Error?t.message:String(t)})}),()=>e.abort()},[a,c,n,t.id,i]),c?{body:o||``,bodyHtml:s,loading:!1,error:null}:l?.key===a?{...l,loading:!1}:{body:``,bodyHtml:null,loading:!0,error:null}}function cn(e){return e?typeof e==`string`?e:e.name&&e.address?`${e.name} <${e.address}>`:e.address||e.name||``:``}function $(e){return e?(Array.isArray(e)?e:[e]).map(e=>cn(e)).filter(Boolean).join(`, `):``}function ln(e){if(!Number.isFinite(e))return``;let t=Number(e);return t<1024?`${t} B`:t<1048576?`${(t/1024).toFixed(1)} KB`:`${(t/1024/1024).toFixed(1)} MB`}function un(e,t,n){let r=0;pt.addHook(`afterSanitizeAttributes`,e=>{if(e.tagName===`IMG`){let i=e.getAttribute(`src`)||``,a=i.toLowerCase();if(a.startsWith(`cid:`)){let n=i.slice(4).replace(/^<|>$/g,``),r=t.get(n)||t.get(`<${n}>`);r?e.setAttribute(`src`,r):e.removeAttribute(`src`)}else(a.startsWith(`http:`)||a.startsWith(`https:`)||a.startsWith(`//`))&&(r++,n?e.setAttribute(`src`,i.replace(/^http:/i,`https:`).replace(/^\/\//,`https://`)):e.removeAttribute(`src`))}e.tagName===`A`&&(e.setAttribute(`target`,`_blank`),e.setAttribute(`rel`,`noopener noreferrer`))});try{let t=pt.sanitize(e,{FORBID_TAGS:[`script`,`iframe`,`object`,`embed`,`form`,`base`,`link`,`meta`],FORBID_ATTR:[`srcset`]}),i=`<!doctype html><html><head>
|
|
3
|
-
<meta charset="utf-8">
|
|
4
|
-
<meta name="viewport" content="width=device-width,initial-scale=1">
|
|
5
|
-
<meta http-equiv="Content-Security-Policy" content="${`default-src 'none'; img-src data:${n?` https:`:``}; style-src 'unsafe-inline'`}">
|
|
6
|
-
<style>html{overflow:auto}body{margin:12px;font:14px/1.5 system-ui,sans-serif;color:#1a1a1a;background:#fff}@media(max-width:480px){body{margin:8px}}</style>
|
|
7
|
-
</head><body>${t}</body></html>`;return{url:URL.createObjectURL(new Blob([i],{type:`text/html;charset=utf-8`})),remoteCount:r}}finally{pt.removeHook(`afterSanitizeAttributes`)}}function dn(e){return new Promise((t,n)=>{let r=new FileReader;r.onload=()=>t(String(r.result)),r.onerror=()=>n(r.error),r.readAsDataURL(e)})}function fn(e){return(0,Q.jsx)(pn,{...e},`${e.workspaceId}:${e.document.id}`)}function pn({workspaceId:e,document:t,className:n=``}){let{fetchBlob:r,download:i}=Ye(e),a=t.data||{},o=Array.isArray(a.attachments)?a.attachments:[],{body:s,bodyHtml:c,loading:l,error:d}=sn(e,t),[f,p]=(0,Z.useState)(null),[m,h]=(0,Z.useState)(!1),[g,_]=(0,Z.useState)(!1),[y,b]=(0,Z.useState)(0),[x,S]=(0,Z.useState)(null);(0,Z.useEffect)(()=>{if(!c||m)return;let e=!1,n=[],i=o.filter(e=>e.contentId&&e.url);return Promise.all(i.slice(0,20).map(async e=>{try{let{blob:n}=await r(t.id,{url:e.url}),i=await dn(n);return[String(e.contentId).replace(/^<|>$/g,``),i]}catch{return null}})).then(t=>{if(e)return;let r=new Map(t.filter(Boolean)),{url:i,remoteCount:a}=un(c,r,g);n.push(i),p(i),b(a)}).catch(t=>{e||S(String(t instanceof Error?t.message:t))}),()=>{e=!0,n.forEach(e=>URL.revokeObjectURL(e)),p(null)}},[e,t.id,c,m,g]);let C=typeof a.date==`string`?new Date(a.date).toLocaleString():null,w=o.filter(e=>!e.isInline||!e.contentId),T=async e=>{if(e.url)try{await i(t.id,e.filename||`attachment`,{url:e.url})}catch(e){S(e instanceof Error?e.message:String(e))}};return(0,Q.jsxs)(`div`,{className:`flex h-full min-h-0 min-w-0 flex-col gap-3 ${n}`,children:[(0,Q.jsx)(`div`,{className:`shrink-0 rounded-md border bg-muted/30 p-2 text-sm sm:p-3`,children:(0,Q.jsxs)(`div`,{className:`flex flex-wrap items-start justify-between gap-2 sm:gap-3`,children:[(0,Q.jsxs)(`div`,{className:`min-w-0 flex-1 basis-64 space-y-1`,children:[(0,Q.jsx)(`div`,{className:`truncate text-base font-semibold`,children:String(a.subject??`(no subject)`)}),(0,Q.jsxs)(`details`,{className:`sm:hidden`,children:[(0,Q.jsxs)(`summary`,{className:`cursor-pointer text-xs`,children:[(0,Q.jsx)(`span`,{className:`inline-block max-w-[85%] truncate align-bottom`,children:typeof a.from==`object`&&a.from?a.from.name||a.from.address:String(a.from||`Unknown sender`)}),(0,Q.jsx)(`span`,{className:`ml-2 text-muted-foreground`,children:`Details`})]}),(0,Q.jsxs)(`div`,{className:`mt-2 space-y-1 break-words text-xs`,children:[(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`span`,{className:`text-muted-foreground`,children:`From:`}),` `,cn(a.from)]}),$(a.to)&&(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`span`,{className:`text-muted-foreground`,children:`To:`}),` `,$(a.to)]}),$(a.cc)&&(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`span`,{className:`text-muted-foreground`,children:`Cc:`}),` `,$(a.cc)]}),C&&(0,Q.jsx)(`div`,{className:`text-xs text-muted-foreground`,children:C})]})]}),(0,Q.jsxs)(`div`,{className:`hidden space-y-1 break-words sm:block`,children:[(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`span`,{className:`text-muted-foreground`,children:`From:`}),` `,cn(a.from)]}),$(a.to)&&(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`span`,{className:`text-muted-foreground`,children:`To:`}),` `,$(a.to)]}),$(a.cc)&&(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`span`,{className:`text-muted-foreground`,children:`Cc:`}),` `,$(a.cc)]}),C&&(0,Q.jsx)(`div`,{className:`text-xs text-muted-foreground`,children:C})]})]}),c&&(0,Q.jsxs)(`div`,{className:`flex max-w-full flex-wrap gap-2`,children:[(0,Q.jsxs)(K,{size:`sm`,variant:`outline`,onClick:()=>h(!m),children:[m?(0,Q.jsx)(u,{className:`mr-1.5 h-3.5 w-3.5`}):(0,Q.jsx)(A,{className:`mr-1.5 h-3.5 w-3.5`}),m?`HTML`:`Plain text`]}),!m&&y>0&&(0,Q.jsxs)(K,{size:`sm`,variant:g?`secondary`:`outline`,onClick:()=>_(!g),title:`Remote images can reveal your IP/read status to the sender`,children:[g?(0,Q.jsx)(v,{className:`mr-1.5 h-3.5 w-3.5`}):(0,Q.jsx)(te,{className:`mr-1.5 h-3.5 w-3.5`}),g?`Hide remote images`:`Show remote images (${y})`]})]})]})}),(x||d)&&(0,Q.jsx)(`p`,{className:`text-sm text-destructive`,children:x||d}),l?(0,Q.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`Loading message…`}):d?(0,Q.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:String(a.bodyPreview||`Message content could not be loaded.`)}):!m&&c?f?(0,Q.jsx)(`iframe`,{src:f,sandbox:``,title:String(a.subject??`email`),className:`min-h-[12rem] w-full flex-1 rounded border bg-white`}):(0,Q.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`Rendering...`}):(0,Q.jsx)(`pre`,{className:`min-h-[12rem] flex-1 overflow-auto whitespace-pre-wrap rounded bg-muted p-3 text-sm`,children:s||`(empty body)`}),w.length>0&&(0,Q.jsxs)(`div`,{className:`shrink-0 space-y-1`,children:[(0,Q.jsxs)(`div`,{className:`text-xs font-medium text-muted-foreground`,children:[`Attachments (`,w.length,`)`]}),w.map((e,t)=>(0,Q.jsxs)(`div`,{className:`flex items-center justify-between gap-2 rounded border px-2 py-1.5 text-sm`,children:[(0,Q.jsxs)(`span`,{className:`inline-flex min-w-0 items-center gap-2`,children:[(0,Q.jsx)(A,{className:`h-4 w-4 shrink-0 text-muted-foreground`}),(0,Q.jsx)(`span`,{className:`truncate`,children:e.filename||`attachment`}),(0,Q.jsx)(`span`,{className:`shrink-0 text-xs text-muted-foreground`,children:ln(e.size)})]}),e.url&&(0,Q.jsxs)(`button`,{onClick:()=>T(e),className:`inline-flex shrink-0 items-center gap-1 text-xs text-primary hover:underline`,children:[(0,Q.jsx)(O,{className:`h-3 w-3`}),` Download`]})]},e.url||t))]})]})}function mn({attachment:e,workspaceId:t,document:n}){let{download:r}=Ye(t),i=e.mimeType||e.contentType||``,a=e.name||e.filename||`Attachment`,o=i.startsWith(`audio/`)||i.startsWith(`video/`),{blobUrl:s,error:c,loading:l}=$e(t,n.id,{url:e.url,typeHint:i,enabled:!o&&!!e.url}),{src:u,error:d,loading:f}=tt(t,n.id,{url:e.url,enabled:o&&!!e.url}),[p,m]=(0,Z.useState)(!1),[h,g]=(0,Z.useState)(``),_=o?d:c;return(0,Q.jsxs)(`div`,{className:`space-y-2 rounded border p-2`,children:[_&&(0,Q.jsx)(`p`,{className:`text-xs text-destructive`,children:_}),(o?f:l)&&(0,Q.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`Loading attachment…`}),!o&&s&&i.startsWith(`image/`)&&(0,Q.jsx)(`img`,{src:s,alt:a,className:`max-h-96 max-w-full rounded object-contain`}),o&&u&&(i.startsWith(`video/`)?(0,Q.jsx)(`video`,{controls:!0,playsInline:!0,preload:`metadata`,src:u,onError:()=>m(!0),className:`max-h-96 w-full rounded`},u):(0,Q.jsx)(`audio`,{controls:!0,preload:`metadata`,src:u,onError:()=>m(!0),className:`w-full`},u)),p&&(0,Q.jsx)(`p`,{role:`alert`,className:`text-xs text-destructive`,children:`This media could not be played in your browser. Download it to play in another app.`}),h&&(0,Q.jsx)(`p`,{role:`alert`,className:`text-xs text-destructive`,children:h}),e.url&&(0,Q.jsxs)(`button`,{className:`text-sm text-primary underline`,onClick:()=>{r(n.id,a,{url:e.url}).catch(()=>g(`Attachment could not be downloaded.`))},children:[`Download `,a]})]})}function hn(e){let t=e.document.data,n=t.sender,r=t.channel,i=Array.isArray(t.attachments)?t.attachments:[],a=t.timestamp?new Date(String(t.timestamp)):null;return(0,Q.jsxs)(`article`,{className:`space-y-4 p-3 ${e.className||``}`,children:[(0,Q.jsxs)(`header`,{className:`space-y-1 border-b pb-3`,children:[(0,Q.jsx)(`p`,{className:`font-medium`,children:n?.name||n?.displayName||n?.username||n?.id||`Unknown sender`}),(0,Q.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:[r?.name||r?.id,String(t.platform||``),a&&!Number.isNaN(a.getTime())?a.toLocaleString():``].filter(Boolean).join(` · `)})]}),(0,Q.jsx)(`p`,{className:`whitespace-pre-wrap break-words text-sm`,children:String(t.text||`(No text)`)}),!!t.mediaError&&(0,Q.jsx)(`p`,{className:`text-xs text-destructive`,children:String(t.mediaError)}),i.map((t,n)=>(0,Q.jsx)(mn,{...e,attachment:t},t.url||n))]})}var gn={email:V,phone:x,sms:o,chat:o,slack:o,matrix:o,web:f,url:f},_n={person:`Person`,organization:`Organization`,service:`Service`,bot:`Bot`},vn=e=>Array.isArray(e)?e:[];function yn(e,t){return t?e===`email`?`mailto:${t}`:e===`phone`||e===`sms`?`tel:${t.replace(/[^\d+]/g,``)}`:/^https?:\/\//i.test(t)?t:null:null}function bn({title:e,count:t,children:n}){return t===0?null:(0,Q.jsxs)(`div`,{className:`space-y-1`,children:[(0,Q.jsx)(`p`,{className:`text-xs font-medium text-muted-foreground`,children:e}),(0,Q.jsx)(`div`,{className:`space-y-1`,children:n})]})}function xn({icon:e,primary:t,children:n,title:r}){return(0,Q.jsxs)(`div`,{className:`flex min-w-0 items-center gap-2 rounded-md border bg-card px-2.5 py-1.5 text-sm`,title:r,children:[(0,Q.jsx)(e,{className:`h-3.5 w-3.5 shrink-0 text-muted-foreground`}),(0,Q.jsx)(`div`,{className:`min-w-0 flex-1 truncate`,children:n}),t&&(0,Q.jsx)(R,{className:`h-3 w-3 shrink-0 fill-current text-data-5`,"aria-label":`Primary`})]})}function Sn({document:e,className:t}){let n=e.data??{},r=vn(n.identifiers),i=vn(n.channels),a=vn(n.organizations),s=vn(n.links),c=vn(n.tags),l=String(n.displayName||``).trim(),u=Se(e.schema,_e),d=String(n.primaryEmail||``).trim(),f=n.name&&typeof n.name==`object`?n.name:{},p=[f.prefix,f.given,f.middle,f.family,f.suffix].map(e=>String(e||``).trim()).filter(Boolean).join(` `),m=i.some(e=>e.kind===`email`&&e.value===d);return(0,Q.jsxs)(`div`,{className:G(`space-y-4`,t),children:[(0,Q.jsxs)(`div`,{className:`space-y-1`,children:[(0,Q.jsx)(`h2`,{className:`text-lg font-semibold`,children:l||`Identity ${e.id}`}),(0,Q.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2 text-xs text-muted-foreground`,children:[u&&(0,Q.jsx)(`span`,{className:`rounded-full bg-muted px-2 py-0.5`,children:_n[u]||u}),p&&p!==l&&(0,Q.jsx)(`span`,{children:p}),String(n.timezone||``)&&(0,Q.jsx)(`span`,{children:String(n.timezone)}),String(n.locale||``)&&(0,Q.jsx)(`span`,{children:String(n.locale)})]})]}),d&&!m&&(0,Q.jsx)(bn,{title:`Primary email`,count:1,children:(0,Q.jsx)(xn,{icon:V,primary:!0,children:(0,Q.jsx)(`a`,{href:`mailto:${d}`,className:`hover:underline`,children:d})})}),(0,Q.jsx)(bn,{title:`Channels`,count:i.length,children:i.map((e,t)=>{let n=String(e.kind||``).toLowerCase(),r=String(e.value||``),i=yn(n,r),a=gn[n]||o;return(0,Q.jsxs)(xn,{icon:a,primary:e.primary,title:e.platform||n,children:[i?(0,Q.jsx)(`a`,{href:i,className:`hover:underline`,target:i.startsWith(`http`)?`_blank`:void 0,rel:`noopener noreferrer`,children:r}):r,e.label&&(0,Q.jsx)(`span`,{className:`ml-2 text-xs text-muted-foreground`,children:e.label})]},`${n}:${r}:${t}`)})}),(0,Q.jsx)(bn,{title:`Identifiers`,count:r.length,children:r.map((e,t)=>(0,Q.jsxs)(xn,{icon:L,primary:e.primary,children:[(0,Q.jsx)(`span`,{className:`font-mono text-xs`,children:e.identifier}),(0,Q.jsx)(`span`,{className:`ml-2 text-xs text-muted-foreground`,children:[e.type,e.provider].filter(Boolean).join(` · `)})]},`${e.type}:${e.identifier}:${t}`))}),(0,Q.jsx)(bn,{title:`Organizations`,count:a.length,children:a.map((e,t)=>(0,Q.jsxs)(xn,{icon:h,children:[e.name,e.role&&(0,Q.jsx)(`span`,{className:`ml-2 text-xs text-muted-foreground`,children:e.role})]},`${e.name}:${t}`))}),(0,Q.jsx)(bn,{title:`Links`,count:s.length,children:s.map((e,t)=>(0,Q.jsxs)(xn,{icon:F,children:[(0,Q.jsx)(`span`,{className:`font-mono text-xs`,children:e.target}),e.type&&(0,Q.jsx)(`span`,{className:`ml-2 text-xs text-muted-foreground`,children:e.type})]},`${e.type}:${e.target}:${t}`))}),c.length>0&&(0,Q.jsx)(`div`,{className:`flex flex-wrap gap-1.5`,children:c.map(e=>(0,Q.jsx)(`span`,{className:`rounded-full bg-muted px-2 py-0.5 text-xs text-muted-foreground`,children:e},e))})]})}function Cn({document:e}){let t=String(e.metadata?.contentType||`application/octet-stream`);return(0,Q.jsxs)(`p`,{className:`text-sm text-muted-foreground`,children:[`No inline preview available for `,(0,Q.jsx)(`span`,{className:`font-mono`,children:t}),`. Use Download.`]})}function wn(e){let t=e.schema;if(t===`data/schema/note`)return Jt;if(t===`data/schema/drawing`)return Ut;if(t===`data/schema/task`)return on;if(t===`data/schema/message/email`)return fn;if(t===`data/schema/message`)return hn;if(t===`data/schema/identity`||t.startsWith(`data/schema/identity/`))return Sn;if(t===`data/schema/tab`||t===`data/schema/link`){let t=String(e.data?.url??e.data?.uri??``);return we(t)?Yt:Zt(t)?Xt:$t}if(t!==`data/schema/file`)return null;let n=String(e.metadata?.contentType||``);switch(he(n,Y(e))){case`image`:return Ut;case`audio`:return Wt;case`video`:return Gt;case`pdf`:return Kt;case`markdown`:return Jt;case`text`:return qt;default:return Cn}}function Tn({onSearch:e,onDraftChange:t,inputRef:n,workspaceId:r,label:i=`Search documents`,clearOnSubmit:a=!0,showSubmitButton:o=!0}){let s=(0,Z.useRef)(null),c=n??s;return(0,Q.jsxs)(`form`,{className:`canvas-search-input`,role:`search`,onSubmit:n=>{n.preventDefault();let r=n.currentTarget.elements.namedItem(`query`),i=r.value.trim();i&&(e(i),a&&(r.value=``,t?.(``)))},children:[(0,Q.jsx)(`input`,{ref:c,name:`query`,type:`search`,"aria-label":i,placeholder:i,autoComplete:`off`,enterKeyHint:`search`,onChange:e=>t?.(e.target.value),onKeyDown:e=>{e.key===`Enter`&&e.nativeEvent.isComposing&&e.preventDefault()}}),o&&(0,Q.jsx)(`button`,{type:`submit`,className:`canvas-nav-button`,"aria-label":`Run search`,title:`Run search`,children:(0,Q.jsx)(ie,{size:17})}),r&&(0,Q.jsx)(Dt,{workspaceId:r,inputRef:c,onChange:t})]})}function En({queries:e,onRemoveQuery:t,scope:n=`path`,onScopeChange:r}){return(0,Q.jsxs)(`div`,{className:`canvas-search-options`,children:[r&&(0,Q.jsxs)(`div`,{className:`canvas-search-scopes`,"aria-label":`Search scope`,children:[(0,Q.jsx)(`span`,{children:`Search in`}),(0,Q.jsx)(`button`,{type:`button`,"aria-pressed":n===`path`,onClick:()=>r(`path`),children:`This path`}),(0,Q.jsx)(`button`,{type:`button`,"aria-pressed":n===`workspace`,onClick:()=>r(`workspace`),children:`Workspace`})]}),e.length>0&&(0,Q.jsxs)(`div`,{className:`canvas-search-queries`,"aria-label":`Active searches`,children:[e.map((e,n)=>{let r=/"[^"]+/.test(e);return(0,Q.jsxs)(`span`,{className:r?`canvas-search-query canvas-search-query-exact`:`canvas-search-query`,children:[r?(0,Q.jsx)(s,{size:12,"aria-hidden":`true`}):(0,Q.jsx)(ie,{size:12,"aria-hidden":`true`}),(0,Q.jsx)(`span`,{title:r?`${e} (exact phrase)`:e,children:e}),t&&(0,Q.jsx)(`button`,{type:`button`,onClick:()=>t(n),"aria-label":`Remove search: ${e}`,children:(0,Q.jsx)(_,{size:14})})]},`${e}-${n}`)}),t&&e.length>1&&(0,Q.jsx)(`button`,{type:`button`,onClick:()=>t(-1),className:`canvas-search-clear`,children:`Clear all`})]})]})}function Dn({children:e,accentColor:t}){return(0,Q.jsxs)(`div`,{className:`canvas-navigation-tabs`,children:[(0,Q.jsx)(`span`,{"aria-hidden":`true`,className:`canvas-tab-divider`,style:t?{backgroundColor:t}:void 0}),e]})}function On({workspace:e,workspaceIcon:t,tree:n,path:i,document:a,section:o,onBack:s,onBrowseWorkspaces:c,onBrowseTree:l,onNavigatePath:u,onDocument:d,onSection:f,onFilter:p,filtersActive:m,filtersOpen:h,onAdd:g,search:v,onDraftChange:b,tabs:x,accentColor:S,actions:C}){let[w,T]=(0,Z.useState)(!1),[E,D]=(0,Z.useState)(!1),O=(0,Z.useRef)(null),k=(0,Z.useRef)(null),A=(0,Z.useRef)(null),j=(0,Z.useRef)(!1),N=JSON.stringify([e,n,i,a]),[P,F]=(0,Z.useState)(N);P!==N&&(F(N),T(!1)),(0,Z.useEffect)(()=>{w?k.current?.focus():(O.current&&(O.current.scrollLeft=O.current.scrollWidth,D(O.current.scrollLeft>1)),j.current&&=(A.current?.focus(),!1))},[w,N,o]);let te=()=>{j.current=!0,T(!1),b?.(``)},I=w?te:s??l,ne=ue(i,e).slice(1),L=(e,t,n,r,i=!1)=>n?(0,Q.jsx)(`button`,{type:`button`,className:t,onClick:n,title:r,"aria-current":i?`location`:void 0,children:e}):(0,Q.jsx)(`span`,{className:`canvas-address-label ${t}`,title:r,"aria-current":i?`location`:void 0,children:e});return(0,Q.jsxs)(`header`,{className:`canvas-navigation${x?` has-tabs`:``}`,style:S?{borderTopColor:S}:void 0,children:[x&&(0,Q.jsx)(Dn,{accentColor:S,children:x}),(0,Q.jsxs)(`div`,{className:`canvas-address-row`,children:[(0,Q.jsx)(`button`,{type:`button`,className:`canvas-nav-button`,"aria-label":w?`Back to address`:`Back to previous view`,title:w?`Back to address`:`Back to previous view`,disabled:!w&&!s&&!l,onClick:I,children:(0,Q.jsx)(ee,{size:19})}),(0,Q.jsxs)(`div`,{className:`canvas-address-field`,onDoubleClick:e=>{v&&!e.target.closest(`button`)&&T(!0)},onKeyDown:e=>{e.key===`Escape`&&w&&(e.preventDefault(),e.stopPropagation(),te())},children:[w&&v?(0,Q.jsx)(Tn,{inputRef:k,workspaceId:v.localOnly?void 0:v.workspaceId,onSearch:v.onSearch,onDraftChange:b,clearOnSubmit:!v.localOnly,showSubmitButton:!1,label:v.queries.length?`Refine search…`:`Search documents…`}):(0,Q.jsxs)(Q.Fragment,{children:[L((0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(r,{icon:t||`ph:stack-fill`,className:`h-4 w-4 shrink-0`,"aria-hidden":`true`}),(0,Q.jsx)(`span`,{className:`truncate`,children:e})]}),`canvas-address-workspace`,c,`Browse workspaces`),(0,Q.jsxs)(`div`,{ref:O,className:`canvas-address-crumbs${E?` is-scrolled`:``}`,onScroll:e=>D(e.currentTarget.scrollLeft>1),role:`navigation`,"aria-label":`Canvas address`,tabIndex:0,onKeyDown:e=>{e.key===`Enter`&&e.target===e.currentTarget&&v&&T(!0)},children:[n&&L(`[${n}]`,`canvas-address-tree`,l,`Browse tree: ${n}`),L(`:/`,`canvas-address-root`,u?()=>u(`/`):void 0,`Go to tree root`),ne.map((e,t)=>(0,Q.jsxs)(`span`,{className:`canvas-address-segment`,children:[t>0&&(0,Q.jsx)(`span`,{"aria-hidden":`true`,children:`/`}),L(e.label,``,u?()=>u(e.path):void 0,e.path,!a&&t===ne.length-1)]},e.path)),a&&(0,Q.jsxs)(`span`,{className:`canvas-address-segment`,children:[(0,Q.jsx)(`span`,{"aria-hidden":`true`,children:ne.length?`/`:``}),L(a,``,d,a)]}),o&&L(`#${o}`,`canvas-address-section`,f,o,!0)]})]}),v&&(0,Q.jsxs)(`button`,{ref:A,type:`button`,className:`canvas-nav-button canvas-address-search`,onClick:()=>{w?k.current?.form?.requestSubmit():T(!0)},"aria-label":w?`Run search`:`Search this canvas`,"aria-expanded":w,title:w?`Run search`:`Search this canvas`,children:[(0,Q.jsx)(ie,{size:17}),v.queries.length>0&&(0,Q.jsx)(`span`,{className:`canvas-nav-dot`})]})]}),p&&(0,Q.jsxs)(`button`,{type:`button`,className:`canvas-nav-button canvas-filter-button`,onClick:p,"aria-label":m?`Filters active`:`Filters`,"aria-expanded":!!h,"data-active":!!m,title:m?`Filters active`:`Filters`,children:[(0,Q.jsx)(M,{size:19}),m&&(0,Q.jsx)(`span`,{className:`canvas-nav-dot`})]}),g&&(0,Q.jsx)(`button`,{type:`button`,className:`canvas-nav-button canvas-add-button`,onClick:g,"aria-label":`Add here`,title:`Add here`,children:(0,Q.jsx)(y,{size:21})}),C]}),w&&v&&(0,Q.jsxs)(`div`,{className:`canvas-search-dropdown`,children:[(0,Q.jsxs)(`div`,{className:`canvas-search-heading`,children:[(0,Q.jsx)(`span`,{children:v.localOnly?`Filter documents on this page`:b?`Type to filter this page · Enter to search all results`:`Search text or an exact ID, e.g. @id:123`}),(0,Q.jsx)(`button`,{type:`button`,className:`canvas-nav-button`,onClick:te,"aria-label":`Close search`,children:(0,Q.jsx)(_,{size:16})})]}),(0,Q.jsx)(En,{...v})]}),!w&&v&&v.queries.length>0&&(0,Q.jsx)(`div`,{className:`px-3 pb-2`,children:(0,Q.jsx)(En,{queries:v.queries,onRemoveQuery:v.onRemoveQuery})})]})}function kn({workspaceId:e,document:t,className:n}){let r=wn(t);return r?(0,Q.jsx)(r,{workspaceId:e,document:t,className:n}):(0,Q.jsx)(`pre`,{className:`overflow-auto p-2 text-xs`,children:JSON.stringify(t.data,null,2)})}function An({workspaceId:e,documentId:t}){let[n,r]=(0,Z.useState)(null),[i,a]=(0,Z.useState)(``),[o,s]=(0,Z.useState)({}),[c,l]=(0,Z.useState)(null),u=(0,Z.useCallback)(async()=>{try{let n=await gt(e,t);r(n),a(``)}catch(e){a(e instanceof Error?e.message:`Could not load thread`)}},[e,t]);return(0,Z.useEffect)(()=>{let n=!0;gt(e,t).then(e=>{n&&(r(e),a(``))}).catch(e=>{n&&a(e instanceof Error?e.message:`Could not load thread`)});let i=()=>{u()};return window.addEventListener(`workspace:documents:refresh`,i),window.addEventListener(ct,i),()=>{n=!1,window.removeEventListener(`workspace:documents:refresh`,i),window.removeEventListener(ct,i)}},[e,t,u]),i?(0,Q.jsxs)(`div`,{className:`p-3`,children:[(0,Q.jsx)(`p`,{role:`alert`,className:`text-sm text-destructive`,children:i}),(0,Q.jsx)(K,{variant:`outline`,size:`sm`,onClick:()=>void u(),children:`Retry`})]}):!n||n.documentId!==t?(0,Q.jsx)(`p`,{className:`p-3 text-sm text-muted-foreground`,children:`Loading thread…`}):(0,Q.jsxs)(`section`,{"aria-label":`Message thread`,className:`space-y-3 p-2`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,Q.jsxs)(`h3`,{className:`text-sm font-medium`,children:[`Thread · `,n.documents.length,` message`,n.documents.length===1?``:`s`]}),(0,Q.jsx)(K,{size:`sm`,variant:`outline`,onClick:()=>void u(),children:`Refresh`})]}),n.documents.length===1&&(0,Q.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`No linked replies have been indexed. Other messages in this conversation are separate from this reply thread.`}),n.truncated&&(0,Q.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`Showing up to 200 linked messages.`}),n.documents.map(r=>{let i=fe(r),a=r.schema===`data/schema/message/email`,c=a||[`slack`,`whatsapp`].includes(String(r.data.platform)),u=r.data.timestamp||r.data.date,d=u?new Date(String(u)):null,f=(n.parents[r.id]||[]).flatMap(e=>{let t=n.documents.find(t=>Number(t.id)===e);return t?[fe(t).title]:[]}),p=o[Number(r.id)]??Number(r.id)===t;return(0,Q.jsxs)(`details`,{open:p,onToggle:e=>{let t=e.currentTarget.open;s(e=>e[Number(r.id)]===t?e:{...e,[Number(r.id)]:t})},className:`rounded-lg border bg-card`,children:[(0,Q.jsxs)(`summary`,{className:`cursor-pointer space-y-1 p-3 text-sm`,children:[(0,Q.jsx)(`span`,{className:`font-medium`,children:i.title}),(0,Q.jsxs)(`span`,{className:`block text-xs text-muted-foreground`,children:[i.subtitle,d&&!Number.isNaN(d.getTime())?` · ${d.toLocaleString()}`:``]}),f.length>0&&(0,Q.jsxs)(`span`,{className:`block text-xs text-muted-foreground`,children:[`Reply to `,f.join(`, `)]})]}),p&&c&&(0,Q.jsx)(`div`,{className:`flex flex-wrap gap-2 px-3 pb-2`,children:(a?[`reply`,`replyAll`,`forward`]:[`reply`]).map(e=>(0,Q.jsx)(K,{variant:`outline`,size:`sm`,onClick:()=>l({document:r,mode:e}),children:e===`replyAll`?`Reply all`:e===`forward`?`Forward`:`Reply`},e))}),p&&(0,Q.jsx)(kn,{workspaceId:e,document:r})]},r.id)}),c&&(0,Q.jsx)(vt,{workspaceId:e,replyToDocumentId:Number(c.document.id),mode:c.mode,originalSubject:typeof c.document.data.subject==`string`?c.document.data.subject:void 0,onClose:()=>l(null)},`${c.document.id}:${c.mode}`)]})}function jn(e,t){return e.slice(0,3).map(e=>{let n=t.get(e.id),r=e.reason===`not-found`?`Source missing from the storage index. Resync the source backend and retry.`:e.reason===`not found`?`Document no longer exists in this workspace. Refresh the list and select it again.`:e.reason;return`${n?`${n} (ID ${e.id})`:`Document ${e.id}`}: ${r}`}).join(`
|
|
8
|
-
`)+(e.length>3?`\n…and ${e.length-3} more failed file${e.length===4?``:`s`}.`:``)}var Mn=e(i(),1),Nn=[{mode:`copy`,label:`Copy to`,icon:(0,Q.jsx)(U,{className:`h-3.5 w-3.5`})},{mode:`move`,label:`Move to`,icon:(0,Q.jsx)(I,{className:`h-3.5 w-3.5`})},{mode:`delete`,label:`Delete from`,icon:(0,Q.jsx)(T,{className:`h-3.5 w-3.5`})}],Pn=[{value:`rename`,label:`Rename mine (file-1.ext)`},{value:`overwrite`,label:`Overwrite the existing file`},{value:`error`,label:`Skip the document`}],Fn=`h-9 w-full rounded-md border bg-background px-2 text-xs outline-none focus:ring-2 focus:ring-ring disabled:opacity-50`;function In(e){return e.driver===`cacache`?W:e.config?.remote===!0?c:ae}function Ln({workspaceId:e,documentCount:t,initialMode:n=`copy`,defaultFilename:r=``,onConfirm:i,onClose:a,saving:o=!1,sizeClassName:s,deleteFrom:c,progress:l,stopping:u=!1,onStop:d}){let{showErrorToast:f}=X(),[p,h]=(0,Z.useState)(!1);mt(a,!o&&!p);let[v,y]=(0,Z.useState)(n),[b,x]=(0,Z.useState)(null),[S,C]=(0,Z.useState)(null),[w,E]=(0,Z.useState)(()=>new Set(n===`delete`&&c?[c.backend]:[])),[D,O]=(0,Z.useState)(!1),[k,A]=(0,Z.useState)(``),[j,M]=(0,Z.useState)(r),[ee,N]=(0,Z.useState)(`rename`);(0,Z.useEffect)(()=>{let t=!1;return ke(e).then(e=>{if(t)return;x(e.filter(e=>e.kind===`storage`));let n=new Set(e.filter(e=>e.kind===`storage`&&e.enabled!==!1&&e.config?.readOnly!==!0&&e.config?.supported!==!1).map(e=>e.address));E(e=>new Set([...e].filter(e=>n.has(e))))}).catch(e=>{t||C(e instanceof Error?e.message:String(e))}),()=>{t=!0}},[e]);let P=v===`move`,F=e=>e.enabled===!1?`disabled`:e.config?.readOnly===!0?`read-only`:e.config?.supported===!1?`unsupported`:null,te=(0,Z.useMemo)(()=>(b||[]).filter(e=>!F(e)).map(e=>e.address),[b,v]),ne=e=>{y(e),E(t=>{let n=(b||[]).filter(e=>e.enabled!==!1&&e.config?.readOnly!==!0&&e.config?.supported!==!1).map(e=>e.address),r=[...t].filter(e=>n.includes(e));return new Set(e===`move`?r.slice(0,1):r)})},L=e=>{E(t=>{if(P)return t.has(e)?new Set:new Set([e]);let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},R=(0,Z.useMemo)(()=>(b||[]).filter(e=>w.has(e.address)&&Ae(e)),[b,w]),z=v!==`delete`&&R.length>0,B=e=>{let t=Pe(e,b||[]),n=t&&b?.find(e=>e.address===t.address);return!!n&&!F(n)&&v!==`delete`&&!o},re=async(t,n)=>{let r=Pe(t,b||[]);if(!r||!B(t))throw Error(`Choose a writable file backend folder`);await je(e,r.driver,r.address,[[r.key,n].filter(Boolean).join(`/`)])},V=e=>{h(!1);let t=Fe(e[0]||``,b||[]),n=t?(b||[]).find(e=>e.address===t.address):null;if(!t||!n){f(`Pick a folder inside a storage backend`);return}if(F(n)){f(`${n.address} is ${F(n)}`);return}if(!Ae(n)){f(`${n.address} does not keep folders — objects are stored by content`);return}A(t.key),E(e=>P?new Set([t.address]):new Set([...e,t.address]))},H=async()=>{w.size===0||o||await i([...w],v,{keepDocument:D,folder:z?k.trim():``,filename:z&&t===1?j.trim():``,onConflict:ee})},W=t,ie=W===1?``:`s`,oe=v===`delete`?`Delete ${W} document${ie} from…`:`${v===`move`?`Move`:`Copy`} ${W} document${ie} to…`,q=v===`delete`?`Delete from`:v===`move`?`Move to`:`Copy to`,J=w.size===0?q.split(` `)[0]:`${q} ${w.size} backend${w.size===1?``:`s`}`;return(0,Q.jsxs)(`div`,{className:G(`flex flex-col overflow-hidden rounded-(--panel-radius) border bg-card shadow-elevation-4`,s||`max-h-viewport-card w-[min(420px,90vw)] max-md:h-full max-md:w-full max-md:shadow-elevation-5`),children:[(0,Q.jsxs)(`div`,{className:`flex h-12 shrink-0 items-center justify-between border-b px-4`,children:[(0,Q.jsxs)(`span`,{className:`flex items-center gap-2 text-sm font-medium`,children:[(0,Q.jsx)(ae,{className:`h-4 w-4`}),oe]}),(0,Q.jsx)(`button`,{type:`button`,onClick:a,disabled:o,className:`text-muted-foreground transition-colors hover:text-foreground disabled:opacity-40`,"aria-label":`Close`,children:(0,Q.jsx)(_,{className:`h-4 w-4`})})]}),(0,Q.jsx)(`div`,{className:`flex shrink-0 items-center gap-1 border-b px-2 pt-2`,children:Nn.map(({mode:e,label:t,icon:n})=>(0,Q.jsxs)(`button`,{type:`button`,onClick:()=>ne(e),disabled:o,className:G(`flex items-center gap-1.5 rounded-t-md border-b-2 px-3 py-2 text-xs font-medium transition-colors disabled:opacity-50`,v===e?e===`delete`?`border-destructive text-destructive`:`border-primary text-foreground`:`border-transparent text-muted-foreground hover:text-foreground`),children:[n,t]},e))}),(0,Q.jsxs)(`div`,{className:`min-h-0 flex-1 space-y-1.5 overflow-y-auto p-3`,children:[S&&(0,Q.jsx)(`p`,{className:`px-2 py-1.5 text-xs text-destructive`,children:S}),!b&&!S&&(0,Q.jsx)(`div`,{className:`px-2 py-3 text-xs text-muted-foreground`,children:`Loading backends…`}),b?.length===0&&(0,Q.jsx)(`p`,{className:`px-2 py-1.5 text-xs text-muted-foreground`,children:`No storage backends configured.`}),b?.map(e=>{let t=In(e),n=F(e),r=w.has(e.address),i=e.config?.remote===!0;return(0,Q.jsxs)(`div`,{onClick:()=>!n&&!o&&L(e.address),className:G(`group relative flex min-h-10 items-center gap-2 rounded-md px-3 py-2 text-sm shadow-elevation-1 transition-all select-none`,`before:absolute before:left-0 before:top-0 before:bottom-0 before:w-1.5 before:transition-colors`,n?`cursor-not-allowed bg-muted/40 opacity-60 before:bg-transparent`:`cursor-pointer hover:shadow`,!n&&r?v===`delete`?`bg-destructive/[0.08] hover:bg-destructive/[0.12] before:bg-destructive`:`bg-primary/[0.08] hover:bg-primary/[0.12] before:bg-primary`:n?``:`bg-card hover:bg-primary/[0.04] before:bg-transparent`),title:e.address,children:[(0,Q.jsx)(`input`,{type:P?`radio`:`checkbox`,checked:r,disabled:!!n||o,onChange:()=>L(e.address),onClick:e=>e.stopPropagation(),className:`h-4 w-4 shrink-0 accent-primary`,"aria-label":e.address}),(0,Q.jsx)(t,{className:`h-4 w-4 shrink-0 text-muted-foreground`}),(0,Q.jsxs)(`span`,{className:`min-w-0 flex-1`,children:[(0,Q.jsx)(`span`,{className:`block truncate font-medium`,children:e.config?.label||e.address}),(0,Q.jsxs)(`span`,{className:`block truncate font-mono text-[10px] text-muted-foreground`,children:[e.driver,` · `,e.address]})]}),i&&(0,Q.jsx)(`span`,{className:`shrink-0 rounded bg-info-subtle px-1.5 py-0.5 text-[10px] uppercase text-muted-foreground`,title:`Network mount${e.config?.transport?` (${e.config.transport})`:``} — transfers cross the network`,children:e.config?.transport||`remote`}),n&&(0,Q.jsx)(`span`,{className:`shrink-0 rounded bg-muted px-1.5 py-0.5 text-[10px] uppercase text-muted-foreground`,children:n})]},`${e.driver}/${e.address}`)}),v===`delete`&&(0,Q.jsxs)(`label`,{className:`mt-3 flex cursor-pointer items-start gap-2 rounded-md border border-destructive/30 bg-destructive/5 px-3 py-2 text-xs`,children:[(0,Q.jsx)(`input`,{type:`checkbox`,checked:D,onChange:e=>O(e.target.checked),disabled:o,className:`mt-0.5 h-3.5 w-3.5 accent-destructive`}),(0,Q.jsxs)(`span`,{children:[`Keep the index entry when its `,(0,Q.jsx)(`strong`,{children:`last`}),` copy is deleted.`,(0,Q.jsx)(`span`,{className:`block text-muted-foreground`,children:`Otherwise the document moves to workspace Trash once no locations remain.`})]})]}),z&&(0,Q.jsxs)(`div`,{className:`mt-3 space-y-2 rounded-md border px-3 py-2`,children:[(0,Q.jsxs)(`p`,{className:`text-xs font-medium`,children:[`Destination on `,R.map(e=>e.config?.label||e.address).join(`, `)]}),(0,Q.jsxs)(`div`,{className:`space-y-1`,children:[(0,Q.jsx)(`label`,{htmlFor:`backend-transfer-folder`,className:`text-[11px] text-muted-foreground`,children:`Folder (relative to the backend root)`}),(0,Q.jsxs)(`div`,{className:`flex gap-1.5`,children:[(0,Q.jsx)(se,{id:`backend-transfer-folder`,value:k,onChange:e=>A(e.target.value),placeholder:`/`,disabled:o,className:`h-9 font-mono text-xs`}),(0,Q.jsx)(K,{type:`button`,variant:`outline`,size:`icon`,className:`h-9 w-9 shrink-0`,onClick:()=>h(!0),disabled:o,"aria-label":`Browse backend folders`,title:`Browse…`,children:(0,Q.jsx)(g,{className:`h-4 w-4`})})]})]}),t===1?(0,Q.jsxs)(`div`,{className:`space-y-1`,children:[(0,Q.jsx)(`label`,{htmlFor:`backend-transfer-filename`,className:`text-[11px] text-muted-foreground`,children:`File name`}),(0,Q.jsx)(se,{id:`backend-transfer-filename`,value:j,onChange:e=>M(e.target.value),placeholder:r||`keeps the document's own name`,disabled:o,className:`h-9 font-mono text-xs`})]}):(0,Q.jsx)(`p`,{className:`text-[11px] text-muted-foreground`,children:`Each document keeps its own file name and extension.`}),(0,Q.jsxs)(`div`,{className:`space-y-1`,children:[(0,Q.jsx)(`label`,{htmlFor:`backend-transfer-conflict`,className:`text-[11px] text-muted-foreground`,children:`If a different file already has that name`}),(0,Q.jsx)(`select`,{id:`backend-transfer-conflict`,className:Fn,value:ee,onChange:e=>N(e.target.value),disabled:o,children:Pn.map(e=>(0,Q.jsx)(`option`,{value:e.value,children:e.label},e.value))})]})]}),v===`move`&&te.length>0&&(0,Q.jsx)(`p`,{className:`px-1 pt-2 text-[11px] text-muted-foreground`,children:`The source copy is released only once the destination write is durable.`})]}),o&&l&&(0,Q.jsxs)(`div`,{role:`status`,className:`flex items-center justify-between gap-2 border-t px-4 py-2 text-xs`,children:[(0,Q.jsxs)(`span`,{children:[u?`Stopping after current file`:`Processing`,` · `,l.completed,`/`,l.total]}),d&&(0,Q.jsx)(K,{size:`sm`,variant:`outline`,onClick:d,disabled:u,children:`Stop`})]}),(0,Q.jsxs)(`div`,{className:`flex shrink-0 items-center justify-between gap-2 border-t px-4 py-3`,children:[(0,Q.jsxs)(`span`,{className:`text-xs text-muted-foreground`,children:[w.size,` backend`,w.size===1?``:`s`,` selected`]}),(0,Q.jsx)(K,{size:`sm`,variant:v===`delete`?`destructive`:`default`,onClick:H,disabled:w.size===0||o,children:o?(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(ce,{className:`mr-1.5 h-3.5 w-3.5`}),`Working…`]}):(0,Q.jsxs)(Q.Fragment,{children:[v===`delete`?(0,Q.jsx)(T,{className:`mr-1 h-3.5 w-3.5`}):v===`move`?(0,Q.jsx)(I,{className:`mr-1 h-3.5 w-3.5`}):(0,Q.jsx)(U,{className:`mr-1 h-3.5 w-3.5`}),J]})})]}),v===`delete`&&(0,Q.jsxs)(`div`,{className:`flex items-start gap-2 border-t bg-destructive/5 px-4 py-2 text-[11px] text-muted-foreground`,children:[(0,Q.jsx)(m,{className:`mt-0.5 h-3.5 w-3.5 shrink-0 text-destructive`}),(0,Q.jsx)(`span`,{children:c&&w.has(c.backend)?`Deletes selected files in ${c.backend}/${c.folder}. Copies in other folders are kept.${w.size>1?` Other selected backends are also targeted.`:` Copies on other backends are kept.`}`:`Deletes the file data from the selected backends. Copies on other backends are untouched.`})]}),p&&(0,Q.jsx)(yt,{onClose:()=>h(!1),children:(0,Q.jsx)(de,{sizeClassName:`h-full w-[380px] max-w-[90vw] max-md:w-full`,multiple:!1,tabs:[`backends`],fixedWorkspaceName:e,title:`Pick a destination folder…`,confirmLabel:`Use folder`,backendFolderCreation:{canCreate:B,create:re},onConfirm:V,onClose:()=>h(!1)})})]})}var Rn={exif:`from the photo's EXIF`,device:`from the device at capture`,manual:`placed by hand`};function zn(e){let t=`${e.lat.toFixed(5)}, ${e.lon.toFixed(5)}`,n=e.source?Rn[e.source]:null;return[t,e.accuracy==null?null:`±${e.accuracy} m`,n].filter(Boolean).join(` · `)}function Bn({value:e,onChange:t,idPrefix:n=`edit-geo`}){let[r,i]=(0,Z.useState)(!1);return(0,Q.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Q.jsx)(q,{htmlFor:`${n}-action`,children:`Location`}),(0,Q.jsxs)(`div`,{className:`flex items-center justify-between gap-3`,children:[(0,Q.jsxs)(`span`,{className:`flex min-w-0 items-center gap-2 text-xs`,children:[(0,Q.jsx)(z,{className:e?`h-4 w-4 shrink-0 text-info`:`h-4 w-4 shrink-0 text-muted-foreground`}),(0,Q.jsx)(`span`,{className:e?`truncate tabular-nums`:`truncate text-muted-foreground`,children:e?zn(e):`No location on this document`})]}),(0,Q.jsxs)(`span`,{className:`flex shrink-0 items-center gap-1`,children:[(0,Q.jsxs)(`button`,{id:`${n}-action`,type:`button`,onClick:()=>i(!0),className:`inline-flex items-center gap-1.5 rounded-md border border-border px-2 py-1 text-xs text-muted-foreground transition-colors hover:bg-muted hover:text-foreground`,children:[(0,Q.jsx)(k,{className:`h-3.5 w-3.5`}),e?`Move pin`:`Set on map`]}),e&&(0,Q.jsx)(`button`,{type:`button`,onClick:()=>t(null),"aria-label":`Remove location`,title:`Remove location`,className:`rounded p-1 text-muted-foreground hover:bg-muted hover:text-foreground`,children:(0,Q.jsx)(T,{className:`h-3.5 w-3.5`})})]})]}),r&&(0,Q.jsx)(We,{initial:e,onPick:e=>t({lat:e.lat,lon:e.lon,source:`manual`}),onClose:()=>i(!1)})]})}function Vn(e){return e===`data/schema/note`||e===`data/schema/link`||e===`data/schema/tab`||e===`data/schema/task`||e===`data/schema/drawing`||e===`data/schema/identity`||e.startsWith(`data/schema/identity/`)}function Hn(e){return Vn(e.schema)||Ze(e)}function Un(e){return e===`data/schema/link`?{urlKey:`uri`,titleKey:`label`}:e===`data/schema/tab`?{urlKey:`url`,titleKey:`title`}:{urlKey:null,titleKey:`title`}}async function Wn(e,t,n){try{let r=new Set(n.map(e=>e.identityId).filter(Boolean)),i=await Te(e,t,{resolve:!1}),a=new Set(i.outgoing.filter(e=>e.p===`member-of`).map(e=>e.to));for(let n of r)a.has(n)||await De(e,t,`member-of`,[n]);for(let n of a)r.has(n)||await me(e,t,`member-of`,n)}catch(e){console.error(`Failed to sync organization relations`,e)}}function Gn({document:e,workspaceId:t,onClose:n}){let{showSuccessToast:r,showErrorToast:i}=X(),a=Vn(e.schema),o=e.schema===`data/schema/file`,[s,c]=(0,Z.useState)(()=>Y(e)),l=!o||!!s.trim()&&!/[\\/]/.test(s)&&!Array.from(s).some(e=>e.charCodeAt(0)<32)&&s!==`.`&&s!==`..`,u=e.schema===Le,d=Ze(e),f=et(e)??`markdown`,p=d&&Xe(e),m=e.schema===Ce,h=e.schema===`data/schema/identity`||e.schema.startsWith(`data/schema/identity/`),{urlKey:g,titleKey:_}=Un(e.schema),[v,y]=(0,Z.useState)(g?String(e.data?.[g]??``):``),[b,x]=(0,Z.useState)(String(e.data?.[_]??``)),[S,C]=(0,Z.useState)(String(e.data?.content??``)),[w,T]=(0,Z.useState)(String(e.data?.description??``)),[E,D]=(0,Z.useState)(e.data?.status??`pending`),[O,k]=(0,Z.useState)(typeof e.data?.priority==`number`?e.data.priority:``),[A,j]=(0,Z.useState)(e.data?.dueDate?lt(String(e.data.dueDate)):ft()),M=He(Ge(e)),[ee,N]=(0,Z.useState)(String(e.comment??``)),P=e.metadata?.geo??null,[F,te]=(0,Z.useState)(P),I=e.features??e.metadata?.features,[ne,L]=(0,Z.useState)(ot(I).length?ot(I):e.data?.tags??[]),R=xt(e,t,u),{title:z,content:B,comment:re,tags:V,geo:H,setTitle:U,setContent:W,setComment:ie,setTags:ae,setGeo:oe}=u?R:{title:b,content:S,comment:ee,tags:ne,geo:F,setTitle:x,setContent:C,setComment:N,setTags:L,setGeo:te},G=JSON.stringify(H??null)!==JSON.stringify(P??null),J=$e(t,e.id,{mode:`text`,enabled:d&&!p,maxTextLength:Qe,version:e.checksumArray?.[0]??null}),[ce,le]=(0,Z.useState)(null),ue=`${e.id}:${e.checksumArray?.[0]??``}`;d&&J.text!=null&&ce!==ue&&(le(ue),W(J.text));let[de,fe]=(0,Z.useState)([]),[me,he]=(0,Z.useState)(!1),{replicating:ge,mirror:ve}=Ie(e);(0,Z.useEffect)(()=>{let e=!1;return pe(t).then(t=>{e||fe(t)}).catch(()=>{}),()=>{e=!0}},[t]);let ye=!g||(()=>{try{return new URL(v.trim()),!0}catch{return!1}})(),be=!me&&l&&(d?!p&&J.text!=null&&!J.loading:a?h?M.displayName.trim().length>0&&M.emailValid:m?z.trim().length>0:u?R.canSave:ye:!0),xe=async()=>{he(!0);let c=[...(I||[]).filter(e=>!e.startsWith(`tag/`)),...at(V)];try{if(u){await R.save(),n();return}if(d){let i=await nt(t,e,B,{comment:re.trim(),metadata:{features:c,...o?{filename:s.trim()}:{},...G?{geo:H}:{}}});r(`Document updated`),window.dispatchEvent(new CustomEvent(`workspace:documents:refresh`)),n(i);return}let i={id:e.id,schema:e.schema,schemaVersion:e.schemaVersion,comment:re.trim(),metadata:{features:c,...o?{filename:s.trim()}:{}}};if(h){let{type:t,...n}=e.data??{};i.schema=`${_e}/${M.values.type}`,i.data={...n,...Ue(M.values)}}else if(m)i.data={...e.data,...ut({title:z,description:w,status:E,priority:O,due:A})};else if(a){let t=V.map(e=>e.trim()).filter(Boolean),n;u?n={...z.trim()?{title:z.trim()}:{},content:B}:(n={...e.data},g&&(n[g]=v.trim()),z.trim()?n[_]=z.trim():delete n[_],n.tags=t),i.data=n}G&&(i.metadata={...i.metadata??{},geo:H}),await Oe(t,i),h&&(await Wn(t,e.id,M.values.organizations),st()),r(`Document updated`),window.dispatchEvent(new CustomEvent(`workspace:documents:refresh`)),n()}catch(e){i(e instanceof Error?e.message:`Failed to update document`)}finally{he(!1)}};return(0,Q.jsxs)(`div`,{className:`flex flex-col gap-4`,children:[o&&(0,Q.jsxs)(`div`,{className:`space-y-2`,children:[(0,Q.jsx)(q,{htmlFor:`file-name`,children:`File name`}),(0,Q.jsx)(se,{id:`file-name`,value:s,onChange:e=>c(e.target.value)}),(0,Q.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`Changes the object’s name; storage locations stay the same.`})]}),a&&g&&(0,Q.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Q.jsx)(q,{htmlFor:`edit-url`,children:`URL`}),(0,Q.jsx)(se,{id:`edit-url`,value:v,onChange:e=>y(e.target.value),placeholder:`https://example.com`,className:`font-mono text-xs`}),v.trim()&&!ye&&(0,Q.jsx)(`p`,{className:`text-xs text-destructive`,children:`Enter a valid URL, e.g. https://example.com`})]}),a&&h&&(0,Q.jsx)(qe,{idPrefix:`edit-identity`,workspaceName:t,...M,emailValid:M.emailValid}),a&&m&&(0,Q.jsx)(Be,{idPrefix:`edit-todo`,title:z,setTitle:U,description:w,setDescription:T,status:E,setStatus:D,priority:O,setPriority:k,due:A,setDue:j}),a&&!m&&!h&&(0,Q.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Q.jsx)(q,{htmlFor:`edit-title`,children:`Title`}),(0,Q.jsx)(se,{id:`edit-title`,value:z,onChange:e=>U(e.target.value),placeholder:u?`Optional; defaults to today's date`:`Optional display title`})]}),(u||d)&&(0,Q.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Q.jsx)(q,{children:`Body`}),p?(0,Q.jsxs)(`p`,{className:`text-xs text-muted-foreground`,children:[`This file is too large to edit here (`,`>`,1e3,` kB) — download it instead.`]}):d&&J.error?(0,Q.jsx)(`p`,{className:`text-xs text-destructive`,children:J.error}):d&&J.text==null?(0,Q.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`Loading content…`}):(0,Q.jsx)(St,{kind:u?`markdown`:f,value:B,onChange:W,placeholder:u?`Write your note…`:void 0})]}),(0,Q.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Q.jsx)(q,{children:`Tags`}),(0,Q.jsx)(Ke,{tags:V,onChange:ae,suggestions:de})]}),(0,Q.jsx)(Bn,{value:H,onChange:oe}),(0,Q.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Q.jsx)(q,{htmlFor:`edit-comment`,children:`Comment`}),(0,Q.jsx)(`textarea`,{id:`edit-comment`,value:re,onChange:e=>ie(e.target.value),rows:3,placeholder:`Add context you can't infer from the content, e.g. “sofa from the cozmo bar in Košice”`,className:`flex w-full rounded-md border border-input bg-transparent px-3 py-2 text-sm shadow-elevation-1 transition-colors placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-50`})]}),u&&(0,Q.jsx)(bt,{...R,onRetry:R.save}),(0,Q.jsxs)(`div`,{className:`flex justify-end gap-2 pt-2`,children:[(0,Q.jsx)(K,{variant:`outline`,size:`sm`,onClick:()=>n(),disabled:me,children:u?`Close`:`Cancel`}),(0,Q.jsx)(K,{size:`sm`,onClick:xe,disabled:!be,children:me?ge?`Replicating to ${ve.label}…`:`Saving…`:`Save changes`})]})]})}var Kn=(0,Z.createContext)(null),qn={entry:null,open:()=>{},close:()=>{}};function Jn(){return(0,Z.useContext)(Kn)??qn}var Yn=`main`,Xn=(0,Z.createContext)(null);function Zn(){return(0,Z.useContext)(Xn)}var Qn=50;function $n({relation:e,workspaceId:t,direction:n,onRemove:r,removing:i}){let{open:a}=Ct(),o=Jn(),s=Zn(),c=n===`out`?e.to:e.from,l=e.document??null,u=l?fe(l).title:``,[d,f]=(0,Z.useState)(!1),{showErrorToast:p}=X(),m=async()=>{if(!(c==null||!l)){f(!0);try{let n=e.preview?await Ne(t,c):l;s?o.open(n,t):a(n,t)}catch(e){p(e instanceof Error?e.message:`Failed to open document`)}finally{f(!1)}}},h=!e.meta||e.meta.src===`doc`;return(0,Q.jsxs)(`div`,{className:`group flex items-center gap-2 rounded-md px-2 py-1.5 text-sm hover:bg-muted/60`,children:[n===`out`?(0,Q.jsx)(I,{className:`h-3.5 w-3.5 shrink-0 text-muted-foreground`}):(0,Q.jsx)(ee,{className:`h-3.5 w-3.5 shrink-0 text-muted-foreground`}),l?(0,Q.jsx)(ht,{document:l,size:3.5}):null,l?(0,Q.jsx)(`button`,{type:`button`,onClick:()=>void m(),disabled:d,className:`min-w-0 flex-1 truncate text-left hover:underline`,title:u,children:u}):(0,Q.jsxs)(`span`,{className:`min-w-0 flex-1 truncate italic text-muted-foreground`,children:[`Document `,c,` (not available)`]}),(0,Q.jsxs)(`span`,{className:`shrink-0 font-mono text-[10px] text-muted-foreground`,children:[`#`,c]}),!h&&(0,Q.jsx)(`span`,{className:`shrink-0 rounded-full bg-muted px-1.5 py-0.5 text-[10px] text-muted-foreground`,title:`Derived by ${e.meta?.src}`,children:e.meta?.src}),h&&(0,Q.jsx)(`button`,{type:`button`,onClick:r,disabled:i,className:`shrink-0 rounded p-1 text-muted-foreground opacity-0 transition-opacity hover:bg-destructive/10 hover:text-destructive group-hover:opacity-100 disabled:opacity-40`,title:`Remove relation`,"aria-label":`Remove relation`,children:(0,Q.jsx)(T,{className:`h-3.5 w-3.5`})})]})}function er({document:e,workspaceId:t}){let{showSuccessToast:n,showErrorToast:r}=X(),[i,a]=(0,Z.useState)(null),[o,s]=(0,Z.useState)(null),[c,l]=(0,Z.useState)(!1),[u,d]=(0,Z.useState)(!1),[f,p]=(0,Z.useState)(null),[m,h]=(0,Z.useState)(0),[g,_]=(0,Z.useState)(1),v=(0,Z.useRef)(0),b=(0,Z.useCallback)(()=>{v.current++},[]),x=(0,Z.useCallback)(async()=>{let n=++v.current;try{let r=await Te(t,e.id,{offset:m*Qn,limit:Qn,summary:!0});if(n!==v.current)return;let i=Math.max(0,Math.ceil(Math.max(r.outgoingCount??r.outgoing.length,r.incomingCount??r.incoming.length)/Qn)-1);if(_(i+1),m>i){h(i);return}a(r),s(null)}catch(e){if(n!==v.current)return;s(e instanceof Error?e.message:String(e))}},[t,e.id,m]),S=`${t}:${e.id}`,[C,w]=(0,Z.useState)(S);S!==C&&(w(S),a(null),s(null),h(0),_(1)),(0,Z.useEffect)(()=>{async function e(){await x()}return e(),window.addEventListener(ct,e),()=>{b(),window.removeEventListener(ct,e)}},[x,b]);let T=async(i,a)=>{let o=a===`out`?i.to:i.from;if(o==null)return;let s=`${a}:${i.p}:${o}`;p(s);try{await me(t,e.id,i.p,o,a),n(`Relation removed`),st()}catch(e){r(e instanceof Error?e.message:`Failed to remove relation`)}finally{p(null)}},E=[{dir:`out`,title:`Points at`,hint:`this document as the subject`,entries:i?.outgoing??[]},{dir:`in`,title:`Pointed at by`,hint:`this document as the object`,entries:i?.incoming??[]}],D=e=>{a(null),h(e)};return(0,Q.jsxs)(`div`,{children:[(0,Q.jsxs)(`div`,{className:`mb-2 flex items-center justify-between gap-2`,children:[(0,Q.jsx)(`h3`,{className:`font-semibold`,children:`Documents`}),(0,Q.jsxs)(K,{variant:`outline`,size:`sm`,onClick:()=>l(!0),children:[(0,Q.jsx)(y,{className:`mr-1 h-3 w-3`}),` Add relation`]})]}),o?(0,Q.jsx)(`p`,{className:`text-sm text-destructive`,children:o}):i?E.every(e=>e.entries.length===0)?(0,Q.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`No related documents.`}):(0,Q.jsx)(`div`,{className:`space-y-4`,children:E.filter(e=>e.entries.length>0).map(({dir:e,title:n,hint:r,entries:i})=>(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`p`,{className:`mb-1 text-xs font-medium text-muted-foreground`,title:r,children:n}),Array.from(new Set(i.map(e=>e.p))).map(n=>(0,Q.jsxs)(`div`,{className:`mb-2`,children:[(0,Q.jsx)(`p`,{className:`px-2 font-mono text-[11px] text-muted-foreground`,children:n}),i.filter(e=>e.p===n).map(n=>{let r=e===`out`?n.to:n.from,i=`${e}:${n.p}:${r}`;return(0,Q.jsx)($n,{relation:n,workspaceId:t,direction:e,removing:f===i,onRemove:()=>void T(n,e)},i)})]},n))]},e))}):(0,Q.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`Loading relations…`}),(g>1||m>0)&&(0,Q.jsxs)(`div`,{className:`mt-3 flex items-center justify-between gap-2 text-xs text-muted-foreground`,children:[(0,Q.jsx)(K,{variant:`outline`,size:`sm`,disabled:m===0,onClick:()=>D(m-1),children:`Previous`}),(0,Q.jsxs)(`span`,{children:[`Page `,m+1,` of `,g]}),(0,Q.jsx)(K,{variant:`outline`,size:`sm`,disabled:!i||m+1>=g,onClick:()=>D(m+1),children:`Next`})]}),c&&(0,Q.jsx)(yt,{onClose:()=>{u||l(!1)},children:(0,Q.jsx)(de,{sizeClassName:`h-full w-[380px] max-w-[90vw] max-md:w-full`,title:`Relate to…`,tabs:[`relations`],fixedWorkspaceName:t,documentCount:1,saving:u,relationPredicates:i?.predicates,relationExcludeIds:new Set([e.id]),onClose:()=>l(!1),onConfirm:()=>{},onConfirmRelation:async({predicate:i,direction:a,targetIds:o})=>{d(!0);try{await De(t,e.id,i,o,a),n(`Related to ${o.length} document${o.length===1?``:`s`}`),l(!1),st()}catch(e){r(e instanceof Error?e.message:`Failed to create relation`)}finally{d(!1)}}})})]})}var tr=(0,Z.lazy)(()=>a(()=>import(`./TextDocumentEditor-CRre32cj.js`),__vite__mapDeps([2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,1,24]))),nr={reply:`Reply`,replyAll:`Reply all`,forward:`Forward`},rr={reply:d,replyAll:l,forward:w};function ir({document:e,workspaceId:t,initialEdit:n=!1,onChanged:r}){let i=Je()!=null,{showErrorToast:a,showSuccessToast:o}=X(),[s,c]=(0,Z.useState)(!1),l=e.data?.url||e.data?.uri,u=e.schema!==`data/schema/file`&&typeof l==`string`&&/^https?:\/\//i.test(l),[d,f]=(0,Z.useState)(!1),p=[`data/schema/message`,`data/schema/message/email`].includes(e.schema),[m,h]=(0,Z.useState)(null),g=e.schema===`data/schema/message/email`,_=!i&&(g||[`slack`,`whatsapp`].includes(String(e.data?.platform))),v=g?[`reply`,`replyAll`,`forward`]:[`reply`],y=e=>h(t=>t===e?null:e),b=!i,[x,S]=(0,Z.useState)(n&&!i),w=e.schema===xe,[T,D]=(0,Z.useState)(!1),k=e.schema===`data/schema/note`||Ze(e),[A,j]=(0,Z.useState)(!1),M=`${t}:${e.id}:${n}:${i}`,[ee,N]=(0,Z.useState)(M);M!==ee&&(N(M),S(n&&!i),h(null),f(!1),D(!1),j(!1));let P=t=>{if(!b||!Hn(e)||t.defaultPrevented)return!1;let n=t.target;return n instanceof Element&&t.currentTarget.contains(n)&&!n.closest(`a, button, input, textarea, select, label, summary, audio, video, [role="button"], [role="checkbox"], [contenteditable]:not([contenteditable="false"])`)};return x&&b?(0,Q.jsx)(Gn,{document:e,workspaceId:t,onClose:e=>{S(!1),r?.(e)}}):(0,Q.jsxs)(`div`,{className:`flex h-full min-h-0 flex-col gap-3`,children:[b&&(0,Q.jsxs)(`div`,{className:`flex shrink-0 justify-end gap-2`,children:[p&&(0,Q.jsx)(K,{size:`sm`,variant:d?`secondary`:`outline`,onClick:()=>f(!d),children:d?`Show message`:`View thread`}),_&&v.map(e=>{let t=rr[e];return(0,Q.jsxs)(K,{size:`sm`,variant:m===e?`secondary`:`outline`,onClick:()=>y(e),children:[(0,Q.jsx)(t,{className:`mr-1.5 h-3.5 w-3.5`}),nr[e]]},e)}),u&&(0,Q.jsxs)(K,{variant:`outline`,size:`sm`,disabled:s,onClick:async()=>{c(!0);try{await be(t,e.id),window.dispatchEvent(new CustomEvent(`workspace:documents:refresh`)),r?.(),o(`File saved to workspace; the original link is preserved`)}catch(e){a(e instanceof Error?e.message:String(e))}finally{c(!1)}},children:[(0,Q.jsx)(O,{className:`mr-1 h-3 w-3`}),s?`Downloading…`:`Download to workspace`]}),e.schema===`data/schema/file`&&(0,Q.jsxs)(K,{variant:`outline`,size:`sm`,onClick:()=>ve(t,e.id,Y(e)||`document-${e.id}`).catch(e=>a(e instanceof Error?e.message:String(e))),children:[(0,Q.jsx)(O,{className:`mr-1 h-3 w-3`}),` Download`]}),w&&(0,Q.jsxs)(K,{variant:`outline`,size:`sm`,onClick:()=>D(!0),children:[(0,Q.jsx)(E,{className:`mr-1 h-3 w-3`}),` Edit sketch`]}),k&&(0,Q.jsxs)(K,{variant:`outline`,size:`sm`,onClick:()=>j(!0),children:[(0,Q.jsx)(C,{className:`mr-1 h-3 w-3`}),` Open editor`]}),(0,Q.jsxs)(K,{variant:`outline`,size:`sm`,onClick:()=>S(!0),children:[(0,Q.jsx)(oe,{className:`mr-1 h-3 w-3`}),` Edit`]})]}),T&&b&&(0,Q.jsx)(Z.Suspense,{fallback:(0,Q.jsx)(`div`,{className:`fixed inset-0 z-fullscreen flex items-center justify-center bg-background surface-glass`,children:(0,Q.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`Loading sketch editor…`})}),children:(0,Q.jsx)(wt,{doc:e,workspaceName:t,onSaved:()=>{D(!1),r?.()},onClose:()=>D(!1),onDetails:()=>{D(!1),S(!0)}})}),A&&b&&(0,Q.jsx)(Z.Suspense,{fallback:(0,Q.jsx)(`div`,{className:`fixed inset-0 z-fullscreen flex items-center justify-center bg-background surface-glass`,children:(0,Q.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`Loading editor…`})}),children:(0,Q.jsx)(tr,{doc:e,workspaceName:t,onSaved:e=>{j(!1),r?.(e)},onClose:()=>j(!1),onDetails:()=>{j(!1),S(!0)}})}),(0,Q.jsxs)(`div`,{className:`min-h-0 flex-1 overflow-auto`,onMouseDownCapture:e=>{e.button===0&&e.detail>1&&P(e)&&e.preventDefault()},onDoubleClickCapture:e=>{P(e)&&(e.preventDefault(),e.stopPropagation(),e.currentTarget.ownerDocument.getSelection()?.removeAllRanges(),S(!0))},children:[d&&!i?(0,Q.jsx)(An,{workspaceId:t,documentId:Number(e.id)},`${t}:${e.id}`):(0,Q.jsx)(kn,{workspaceId:t,document:e}),m&&_&&(0,Q.jsx)(vt,{workspaceId:t,replyToDocumentId:Number(e.id),mode:m,originalSubject:g&&typeof e.data?.subject==`string`?e.data.subject:void 0,onClose:()=>h(null)},`${e.id}:${m}`)]}),e.comment?.trim()&&(0,Q.jsxs)(`div`,{className:`shrink-0 rounded-md border border-border bg-muted/40 px-3 py-2`,children:[(0,Q.jsx)(`p`,{className:`text-xs font-medium text-muted-foreground mb-0.5`,children:`Comment`}),(0,Q.jsx)(`p`,{className:`text-sm whitespace-pre-wrap`,children:e.comment})]})]})}var ar=e=>e?new Date(e).toLocaleDateString(`en-US`,{year:`numeric`,month:`long`,day:`numeric`,hour:`2-digit`,minute:`2-digit`,second:`2-digit`}):`—`,or=e=>!Number.isFinite(e)||!e?null:e>=1?`${e}s`:`1/${Math.round(1/e)}s`;function sr({meta:e}){let{geo:t,exif:n,dimensions:r}=e;if(!t&&!n&&!r)return null;let i=(e,t)=>t==null||t===``?null:(0,Q.jsxs)(`div`,{children:[(0,Q.jsxs)(`span`,{className:`font-medium`,children:[e,`:`]}),(0,Q.jsx)(`span`,{className:`ml-2`,children:t})]});return(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`h3`,{className:`font-semibold mb-3`,children:`Photo`}),(0,Q.jsxs)(`div`,{className:`grid gap-3 text-sm`,children:[r&&i(`Dimensions`,r.width&&r.height?`${r.width} × ${r.height}`:null),n&&i(`Camera`,[n.make,n.model].filter(Boolean).join(` `)),n&&i(`Lens`,n.lensModel),n&&i(`Aperture`,Number.isFinite(n.fNumber)?`ƒ/${n.fNumber}`:null),n&&i(`Shutter`,or(n.exposureTime)),n&&i(`ISO`,Number.isFinite(n.iso)?n.iso:null),n&&i(`Focal length`,Number.isFinite(n.focalLength)?`${n.focalLength} mm`:null),n&&i(`Captured`,ar(n.capturedAt)),t&&Number.isFinite(t.lat)&&Number.isFinite(t.lon)&&i(`Location`,(0,Q.jsxs)(`a`,{href:`https://www.openstreetmap.org/?mlat=${t.lat}&mlon=${t.lon}#map=15/${t.lat}/${t.lon}`,target:`_blank`,rel:`noopener noreferrer`,className:`text-primary underline underline-offset-2`,children:[t.lat.toFixed(5),`, `,t.lon.toFixed(5),Number.isFinite(t.alt)?` · ${Math.round(t.alt)} m`:``]}))]})]})}function cr({document:e}){let t=e.metadata;return(0,Q.jsxs)(`div`,{className:`space-y-6`,children:[(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`h3`,{className:`font-semibold mb-3`,children:`Basic Information`}),(0,Q.jsxs)(`div`,{className:`grid gap-3 text-sm`,children:[(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`span`,{className:`font-medium`,children:`ID:`}),(0,Q.jsx)(`span`,{className:`ml-2 font-mono`,children:e.id})]}),(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`span`,{className:`font-medium`,children:`Schema:`}),(0,Q.jsx)(`span`,{className:`ml-2 font-mono`,children:e.schema})]}),(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`span`,{className:`font-medium`,children:`Schema Version:`}),(0,Q.jsx)(`span`,{className:`ml-2`,children:e.schemaVersion})]}),(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`span`,{className:`font-medium`,children:`Created:`}),(0,Q.jsx)(`span`,{className:`ml-2`,children:ar(e.createdAt)})]}),(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`span`,{className:`font-medium`,children:`Updated:`}),(0,Q.jsx)(`span`,{className:`ml-2`,children:ar(e.updatedAt)})]})]})]}),(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`h3`,{className:`font-semibold mb-3`,children:`Metadata`}),(0,Q.jsxs)(`div`,{className:`grid gap-3 text-sm`,children:[(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`span`,{className:`font-medium`,children:`Content Type:`}),(0,Q.jsx)(`span`,{className:`ml-2`,children:e.metadata?.contentType??`—`})]}),(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`span`,{className:`font-medium`,children:`Content Encoding:`}),(0,Q.jsx)(`span`,{className:`ml-2`,children:e.metadata?.contentEncoding??`—`})]}),Number.isFinite(e.metadata?.size)&&(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`span`,{className:`font-medium`,children:`Size:`}),(0,Q.jsxs)(`span`,{className:`ml-2`,children:[e.metadata?.size,` bytes`]})]})]})]}),(0,Q.jsx)(sr,{meta:t}),Array.isArray(e.locations)&&e.locations.length>0&&(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`h3`,{className:`font-semibold mb-3`,children:`Locations`}),(0,Q.jsx)(`div`,{className:`space-y-2`,children:e.locations.map((e,t)=>{let{backend:n,key:r}=fr(e.url);return(0,Q.jsxs)(`div`,{className:`flex items-baseline gap-2 text-sm font-mono`,children:[(0,Q.jsx)(`span`,{className:`font-medium shrink-0`,children:n}),e.status&&e.status!==`available`&&(0,Q.jsx)(`span`,{className:`shrink-0 rounded border px-1 text-xs`,title:e.statusChangedAt,children:e.status===`deleted`?`Deleted`:`Not found`}),r&&(0,Q.jsx)(`span`,{className:`break-all text-muted-foreground`,children:r})]},t)})})]}),Array.isArray(e.checksumArray)&&e.checksumArray.length>0&&(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`h3`,{className:`font-semibold mb-3`,children:`Checksums`}),(0,Q.jsx)(`div`,{className:`space-y-2`,children:e.checksumArray.map((e,t)=>{let[n,r]=e.split(`/`);return(0,Q.jsxs)(`div`,{className:`flex items-center gap-2 text-sm font-mono`,children:[(0,Q.jsxs)(`span`,{className:`font-medium`,children:[n,`:`]}),(0,Q.jsx)(`span`,{className:`break-all text-muted-foreground`,children:r})]},t)})})]}),e.indexOptions&&(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`h3`,{className:`font-semibold mb-3`,children:`Index Options`}),(0,Q.jsxs)(`div`,{className:`space-y-3 text-sm`,children:[(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`span`,{className:`font-medium`,children:`FTS Search Fields:`}),(0,Q.jsx)(`div`,{className:`ml-2 mt-1`,children:(e.indexOptions.ftsSearchFields??[]).map((e,t)=>(0,Q.jsx)(`span`,{className:`mb-1 mr-2 inline-block rounded bg-muted px-2 py-1 text-xs`,children:e},t))})]}),(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`span`,{className:`font-medium`,children:`Vector Embedding Fields:`}),(0,Q.jsx)(`div`,{className:`ml-2 mt-1`,children:(e.indexOptions.vectorEmbeddingFields??[]).map((e,t)=>(0,Q.jsx)(`span`,{className:`mb-1 mr-2 inline-block rounded bg-muted px-2 py-1 text-xs`,children:e},t))})]})]})]})]})}function lr({document:e}){let{showSuccessToast:t,showErrorToast:n}=X(),r=JSON.stringify(e,null,2);return(0,Q.jsxs)(`div`,{className:`space-y-2`,children:[(0,Q.jsx)(`div`,{className:`flex justify-end`,children:(0,Q.jsxs)(K,{variant:`outline`,size:`sm`,onClick:async()=>{try{await navigator.clipboard.writeText(r),t(`Copied to clipboard`)}catch{n(`Copy failed`)}},children:[(0,Q.jsx)(U,{className:`mr-1 h-3 w-3`}),` Copy to clipboard`]})}),(0,Q.jsx)(`pre`,{className:`overflow-x-auto rounded-lg bg-muted p-4 text-xs`,children:r})]})}function ur({document:e,workspaceId:t}){let[n,r]=(0,Z.useState)(null),[i,a]=(0,Z.useState)(null),o=`${t}:${e.id}`,[s,c]=(0,Z.useState)(o);return o!==s&&(c(o),r(null),a(null)),(0,Z.useEffect)(()=>{let n=!1;return Ee(t,e.id).then(e=>{n||r(e)}).catch(e=>{n||a(e instanceof Error?e.message:String(e))}),()=>{n=!0}},[o]),i?(0,Q.jsx)(`p`,{className:`text-sm text-destructive`,children:i}):n?(0,Q.jsxs)(`div`,{className:`space-y-6`,children:[[{title:`Context tree`,type:`context`},{title:`Directory tree`,type:`directory`}].map(({title:e,type:t})=>{let r=n.filter(e=>e.type===t),i=r.flatMap(e=>e.paths.map(t=>({tree:e.tree,path:t})));return(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`h3`,{className:`mb-3 font-semibold`,children:e}),i.length===0?(0,Q.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`No placements.`}):(0,Q.jsx)(`div`,{className:`space-y-1`,children:i.map(({tree:e,path:t},n)=>(0,Q.jsxs)(`div`,{className:`flex items-center gap-2 text-sm`,children:[(0,Q.jsx)(`span`,{className:`break-all font-mono text-xs`,children:t}),r.length>1&&(0,Q.jsxs)(`span`,{className:`shrink-0 text-xs text-muted-foreground`,children:[`(`,e,`)`]})]},`${e}:${t}:${n}`))})]},t)}),(0,Q.jsx)(er,{document:e,workspaceId:t})]}):(0,Q.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`Loading memberships...`})}function dr(e){return e===`stored`?W:e===`workspace-file`?ae:e===`imap`?V:e===`readonly`?f:j}function fr(e){let t=e.match(/^([a-z][a-z0-9+.-]*):\/\/([^/]*)\/?(.*)$/i);return t?{backend:`${t[1]}://${t[2]}`,key:t[3]}:{backend:e,key:``}}function pr({document:e,workspaceId:t,onChanged:n}){let{showSuccessToast:r,showErrorToast:i}=X(),[a,o]=(0,Z.useState)(null),[s,c]=(0,Z.useState)(null),[l,u]=(0,Z.useState)(null),[d,f]=(0,Z.useState)(null),[p,m]=(0,Z.useState)(null),[h,g]=(0,Z.useState)(!1),_=`${t}:${e.id}`,[v,y]=(0,Z.useState)(_);_!==v&&(y(_),o(null),c(null),f(null));let b=()=>{ge(t,e.id).then(o).catch(e=>c(e instanceof Error?e.message:String(e)))};(0,Z.useEffect)(()=>{let n=!1;return ge(t,e.id).then(e=>{n||o(e)}).catch(e=>{n||c(e instanceof Error?e.message:String(e))}),()=>{n=!0}},[_]);let x=async(a,o)=>{u(a),f(null);try{let i=await ye(t,[e.id],{urls:[a],...o===void 0?{}:{keepDocument:o}}),s=i.successful[0];if(!s)throw Error(i.failed[0]?.reason||`Destroy failed`);s.docDeleted?r(`Removed from backend; document removed from index`):s.deleted.includes(a)?r(`Removed from backend`):r(`Reference dropped (backend is read-only)`),window.dispatchEvent(new CustomEvent(`workspace:documents:refresh`)),n?.(),b()}catch(e){i(e instanceof Error?e.message:String(e))}finally{u(null)}},S=async(a,o,s)=>{g(!0);try{let i=await Me(t,[e.id],{to:a,mode:o,keepDocument:s.keepDocument,folder:s.folder,filename:s.filename,onConflict:s.onConflict}),c=i.successful[0];if(!c)throw Error(jn(i.failed,new Map([[e.id,Y(e)||`Document ${e.id}`]]))||`Transfer failed`);let l=c.transfers?.flatMap(e=>e.state===`unchanged`?[]:[e.backend])??[],u=a.join(`, `);o===`delete`?r(`Deleted from ${u}`):l.length===0?r(`Nothing to do — already on ${u}`):r(`${o===`move`?`Moved to`:`Copied to`} ${l.join(`, `)}${c.transfers?.some(e=>e.state===`pending`)?` (pending sync)`:``}`),window.dispatchEvent(new CustomEvent(`workspace:documents:refresh`)),m(null),n?.(),b()}catch(e){i(e instanceof Error?e.message:String(e))}finally{g(!1)}},C=e=>{if((a?.length??0)<=1){f(e.url);return}window.confirm(`Remove this copy from the backend?\n\n${e.url}`)&&x(e.url)};if(s)return(0,Q.jsx)(`p`,{className:`text-sm text-destructive`,children:s});if(!a)return(0,Q.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`Loading locations...`});let w=a.length===0,E=Y(e);return(0,Q.jsxs)(`div`,{className:`space-y-3`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center justify-between gap-2 rounded border px-3 py-2 text-sm`,children:[(0,Q.jsxs)(`span`,{className:`inline-flex min-w-0 items-center gap-2`,children:[(0,Q.jsx)(W,{className:`h-4 w-4 shrink-0 text-muted-foreground`}),(0,Q.jsx)(`span`,{className:`font-mono text-xs`,children:`workspace:db`}),(0,Q.jsxs)(`span`,{className:`truncate text-xs text-muted-foreground`,children:[`index entry (id `,e.id,`)`]})]}),(0,Q.jsx)(`span`,{className:`shrink-0 rounded bg-muted px-1.5 py-0.5 text-[10px] uppercase text-muted-foreground`,children:`json`})]}),w?(0,Q.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`No byte locations; this object lives only in the workspace database, so there is no file data to copy or move.`}):(0,Q.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,Q.jsxs)(K,{variant:`outline`,size:`sm`,onClick:()=>m(`copy`),title:`Copy the file data to another storage backend (keeps the existing copies)`,children:[(0,Q.jsx)(U,{className:`mr-1 h-3.5 w-3.5`}),` Copy to…`]}),(0,Q.jsxs)(K,{variant:`outline`,size:`sm`,onClick:()=>m(`move`),title:`Move the file data to another storage backend (source released once the copy is durable)`,children:[(0,Q.jsx)(I,{className:`mr-1 h-3.5 w-3.5`}),` Move to…`]})]}),a.map(n=>{let r=dr(n.kind),{backend:a,key:o}=fr(n.url),s=l===n.url;return(0,Q.jsxs)(`div`,{className:`space-y-2 rounded border px-3 py-2 text-sm`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,Q.jsxs)(`span`,{className:`inline-flex min-w-0 items-center gap-2`,children:[(0,Q.jsx)(r,{className:`h-4 w-4 shrink-0 text-muted-foreground`}),(0,Q.jsx)(`span`,{className:`shrink-0 font-mono text-xs`,children:n.backend||a}),(0,Q.jsx)(`span`,{className:`truncate font-mono text-xs text-muted-foreground`,title:n.url,children:o||n.url})]}),(0,Q.jsxs)(`span`,{className:`flex shrink-0 items-center gap-2`,children:[(0,Q.jsx)(`span`,{className:`rounded px-1.5 py-0.5 text-[10px] uppercase ${n.deletable?`bg-muted text-muted-foreground`:`bg-warning/15 text-warning`}`,children:n.deletable?n.kind:`read-only`}),(0,Q.jsx)(`button`,{onClick:()=>ve(t,e.id,E||`document-${e.id}`,{url:n.url}).catch(e=>i(e instanceof Error?e.message:String(e))),className:`text-muted-foreground hover:text-foreground`,title:`Download this copy`,children:(0,Q.jsx)(O,{className:`h-3.5 w-3.5`})}),(0,Q.jsx)(`button`,{onClick:()=>C(n),disabled:s,className:`text-muted-foreground hover:text-destructive disabled:opacity-50`,title:n.deletable?`Remove from backend`:`Drop reference (bytes stay; backend is read-only)`,children:(0,Q.jsx)(T,{className:`h-3.5 w-3.5`})})]})]}),d===n.url&&(0,Q.jsxs)(`div`,{className:`space-y-2 rounded border border-destructive/40 bg-destructive/5 p-2`,children:[(0,Q.jsxs)(`p`,{className:`text-xs`,children:[`This is the object's `,(0,Q.jsx)(`strong`,{children:`last`}),` location. Remove the bytes from the backend and…`]}),(0,Q.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[(0,Q.jsx)(K,{variant:`destructive`,size:`sm`,disabled:s,onClick:()=>void x(n.url,!1),children:`Also remove index entry`}),(0,Q.jsx)(K,{variant:`outline`,size:`sm`,disabled:s,onClick:()=>void x(n.url,!0),children:`Keep index entry (no bytes)`}),(0,Q.jsx)(K,{variant:`ghost`,size:`sm`,onClick:()=>f(null),children:`Cancel`})]})]})]},n.url)}),p&&(0,Mn.createPortal)((0,Q.jsx)(`div`,{className:`fixed inset-0 z-picker flex items-center justify-center bg-scrim p-4 max-md:p-2`,children:(0,Q.jsx)(Ln,{workspaceId:t,documentCount:1,initialMode:p,defaultFilename:E,saving:h,onConfirm:S,onClose:()=>{h||m(null)}})}),window.document.body)]})}var mr=(0,Z.lazy)(()=>a(()=>import(`./LocationTab-DAtqAQ3l.js`),__vite__mapDeps([25,3,4,26,27]))),hr=[{id:`view`,label:`View`,icon:N},{id:`location`,label:`Location`,icon:z},{id:`metadata`,label:`Metadata`,icon:b},{id:`json`,label:`JSON`,icon:D},{id:`synapses`,label:`Synapses`,icon:ne},{id:`backends`,label:`Backends`,icon:W}];function gr({document:e,workspaceId:t,initialTab:n=`view`,initialEdit:r=!1,onChanged:i,className:a=``,compact:o=!1,navigation:s,tabActions:c,onTabChange:l}){let u=Je()!=null,d=Tt(e),f=hr.filter(e=>(e.id!==`location`||d!==null)&&(!u||![`synapses`,`backends`].includes(e.id))),[p,m]=(0,Z.useState)(n),h=`${e.id}:${n}`,[g,_]=(0,Z.useState)(h);h!==g&&(_(h),m(n));let v=f.some(e=>e.id===p)?p:`view`,y=e=>{m(e),l?.(e)},b=o&&!!c&&!s,x=(0,Q.jsx)(`div`,{className:G(b&&`document-detail-header shrink-0 border-b-[3px] bg-muted`),children:(0,Q.jsxs)(`div`,{className:G(`flex min-w-0 items-center`,b&&`mx-auto h-[calc(3rem-4px)] w-full max-w-[var(--document-reading-width,100%)] gap-1 pl-2 pr-2 sm:pl-4`),children:[(0,Q.jsx)(_t,{tabs:f,active:v,onChange:y,className:G(`min-w-0 flex-1 px-1`,b&&`h-full border-b-0 px-0 max-sm:gap-0 max-sm:[&>button]:px-2.5`),iconOnly:o}),c]})});return(0,Q.jsxs)(`div`,{className:`flex h-full min-h-0 flex-col ${a}`,children:[s?(0,Q.jsx)(On,{...s,tabs:x,section:v,onDocument:()=>y(`view`),onSection:()=>y(`view`),onBack:v===`view`?s.onBack:()=>y(`view`)}):x,(0,Q.jsx)(`div`,{className:`min-h-0 flex-1 overflow-y-auto`,children:(0,Q.jsxs)(`div`,{className:`mx-auto h-full w-full max-w-[var(--document-reading-width,100%)] p-4`,children:[v===`view`&&(0,Q.jsx)(ir,{document:e,workspaceId:t,initialEdit:r&&!u,onChanged:i}),v===`location`&&d&&(0,Q.jsx)(Z.Suspense,{fallback:(0,Q.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`Loading map…`}),children:(0,Q.jsx)(mr,{lat:d.lat,lon:d.lon})}),v===`metadata`&&(0,Q.jsx)(cr,{document:e,workspaceId:t}),v===`json`&&(0,Q.jsx)(lr,{document:e,workspaceId:t}),v===`synapses`&&!u&&(0,Q.jsx)(ur,{document:e,workspaceId:t}),v===`backends`&&!u&&(0,Q.jsx)(pr,{document:e,workspaceId:t,onChanged:i})]})})]})}export{en as _,Kn as a,Dt as b,Ln as c,Dn as d,wn as f,an as g,nn as h,Zn as i,jn as l,rn as m,Xn as n,Jn as o,tn as p,Yn as r,Bn as s,gr as t,On as u,Ut as v,Pt as y};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{o as e}from"./rolldown-runtime-C0FnF6B9.js";import{l as t,u as n}from"./code-editor-BOIngd5F.js";import{yt as r}from"./react-BHzhHVTZ.js";import{g as i}from"./chunk-62JRHF6Z-vspAGgtK.js";import{Br as a,L as o,Zt as s,_n as c,in as l,sr as u,wt as d}from"./ui-Byg1cZDr.js";import{t as f}from"./utils-2pl1SbIp.js";import{t as p}from"./button-SgR3GVvV.js";import{_ as m,a as h,i as g,n as _,r as v,t as y}from"./LinkToCard-5dg0jvSY.js";import{Bt as b,Pt as x,_ as S,t as C}from"./workspace-CrSpR4xf.js";import{t as w}from"./use-mobile-Db-vWu9Y.js";import{c as T}from"./IdentityFields-Bti7ojF3.js";import{n as E}from"./relation-events-CKio19hE.js";import{t as D}from"./useEscapeClose-DR_xKT_k.js";import{t as O}from"./useToastHelpers-CRrpIIdY.js";var k=e(n(),1);function A(e){let t=`/workspaces/${encodeURIComponent(e.workspaceName)}`,n=e.path.replace(/^\/+/,``).split(`/`).map(encodeURIComponent).join(`/`);return e.treeName===`context`?`${t}/path/${n}`:`${t}/trees/${encodeURIComponent(e.treeName)}/path/${n}`}var j=e(r(),1),M=t();function N({title:e,icon:t,onClose:n,onSave:r,navigateAfterSave:a=!1,canSave:u=!1,saving:m=!1,saveProgress:h,successMessage:g=`Saved`,lockedWorkspaceName:_,fillParent:v=!1,fullWidthContent:x=!1,relationSubjectId:C,frame:N,children:P,maximized:ee,onMaximizedChange:F}){let te=i(),[ne,re]=(0,k.useState)(`portrait`),[ie,ae]=(0,k.useState)(!1),I=ee??ie,L=e=>{ae(e),F?.(e)},[R,z]=(0,k.useState)(!1),[oe,B]=(0,k.useState)(!1),[se,V]=(0,k.useState)(!1),H=m||se;D(()=>z(!1),R&&!H),D(()=>L(!1),I&&!R);let U=(0,k.useRef)(null),W=w(),{showSuccessToast:G,showErrorToast:K}=O(),q=W&&!v&&!I,[ce,le]=(0,k.useState)(!1),J=!v&&!I&&!N&&!ce;(0,k.useEffect)(()=>{R&&U.current?.scrollIntoView({behavior:`smooth`,inline:`end`,block:`nearest`})},[R]);let ue=async(e,t)=>{if(!(!r||H)){V(!0);try{let i=await r({...t,path:e[0]}),o=e.slice(1);i.length&&o.length&&await Promise.all(o.map(e=>b(t.workspaceName,e,i,t.treeName,t.treeType))),G(g),n?.(),a&&te(A({...t,path:e[0]}),{replace:!0})}catch(e){K(e instanceof Error?e.message:`Failed to save`)}finally{V(!1)}}},Y=async e=>{if(!(!C||!_||e.targetIds.length===0)){B(!0);try{await S(_,C,e.predicate,e.targetIds,e.direction),G(`Created ${e.targetIds.length} relation${e.targetIds.length===1?``:`s`}`),E(),z(!1)}catch(e){K(e instanceof Error?e.message:`Failed to create relations`)}finally{B(!1)}}},de=I?R?{flex:`1 1 auto`,minWidth:0,height:`100%`}:{width:`100%`,height:`100%`}:v?{height:`100%`,flexShrink:0}:q?void 0:ne===`portrait`?{aspectRatio:`0.707 / 1`,height:`calc(var(--viewport-h) * 0.85)`,width:`auto`,maxWidth:`min(90vw, 100%)`,flexShrink:0}:{aspectRatio:`1 / 0.707`,width:`min(90vw, 900px)`,maxWidth:`100%`,height:`auto`,maxHeight:`calc(var(--viewport-h) * 0.85)`,flexShrink:0},X=!!(C&&_),Z=r&&R&&(0,M.jsx)(y,{onClose:()=>z(!1),onConfirm:ue,fixedWorkspaceName:_,saving:H||oe,savingContent:h,tabs:X?[`context`,`directory`,`relations`]:[`context`,`directory`],onConfirmRelation:X?Y:void 0,relationWorkspaceName:_,relationExcludeIds:X?new Set([C]):void 0,sizeClassName:N?`h-full max-h-full w-full min-w-0 rounded-none border-0 shadow-none`:v?`h-full max-h-full w-[min(380px,90vw)] max-md:h-full max-md:w-full max-md:shadow-elevation-5`:void 0}),Q=(0,M.jsxs)(`div`,{className:`flex shrink-0 items-center gap-1`,children:[!v&&(0,M.jsx)(`button`,{type:`button`,onClick:()=>re(e=>e===`portrait`?`landscape`:`portrait`),className:`rounded p-1.5 text-muted-foreground transition-colors hover:bg-muted hover:text-foreground max-md:hidden touch-target`,"aria-label":`Toggle orientation`,title:`Toggle orientation`,children:(0,M.jsx)(d,{className:`h-4 w-4`})}),r&&(typeof P==`function`?(0,M.jsx)(`button`,{type:`button`,onClick:()=>z(!0),disabled:!u||H,className:`flex h-8 w-8 items-center justify-center rounded text-muted-foreground transition-colors hover:bg-muted hover:text-foreground disabled:opacity-40 touch-target`,"aria-label":H?`Saving…`:`Add relations / Link to…`,title:`Add relations / Link to…`,children:(0,M.jsx)(c,{className:`h-4 w-4`})}):(0,M.jsx)(p,{size:`sm`,variant:`outline`,onClick:()=>z(!0),disabled:!u||H,children:H?`Saving…`:`Save / Link to…`})),(0,M.jsx)(`button`,{type:`button`,onClick:()=>N&&!I?N.onToggleExpanded():L(!I),className:f(`rounded p-1.5 text-muted-foreground transition-colors hover:bg-muted hover:text-foreground`,typeof P==`function`&&`flex h-8 w-8 items-center justify-center`,!I&&!N&&`max-md:hidden`),"aria-label":N&&!I?N.expanded?`Card size`:`Expand to full width`:I?`Restore`:`Maximize`,title:N&&!I?N.expanded?`Card size`:`Expand to full width`:I?`Restore`:`Maximize`,children:I||N?.expanded?(0,M.jsx)(s,{className:`h-4 w-4`}):(0,M.jsx)(l,{className:`h-4 w-4`})}),n&&(0,M.jsx)(`button`,{type:`button`,onClick:n,disabled:H,className:f(`rounded p-1.5 text-muted-foreground transition-colors hover:bg-muted hover:text-foreground disabled:opacity-40 touch-target`,typeof P==`function`&&`flex h-8 w-8 items-center justify-center`),"aria-label":`Close`,children:(0,M.jsx)(o,{className:`h-4 w-4`})})]}),$=(0,M.jsxs)(`div`,{style:{...N&&!I?{width:`100%`,height:`100%`,minWidth:0}:de,"--document-reading-width":I&&!x?`48rem`:`100%`},onAnimationEnd:e=>{J&&e.target===e.currentTarget&&le(!0)},className:f(`flex flex-col overflow-hidden`,N&&!I?`strip-document-card`:`rounded-(--card-radius) border bg-card shadow-elevation-4 transition-[width,height]`,v&&!I&&!N&&`w-full`,q&&`fixed inset-2 z-40 shadow-elevation-5`,J&&`animate-card-in`),children:[typeof P!=`function`&&(0,M.jsxs)(`div`,{className:`flex h-12 shrink-0 items-center justify-between gap-2 border-b px-4`,children:[(0,M.jsxs)(`span`,{className:`flex min-w-0 items-center gap-2 truncate text-sm font-medium`,children:[(0,M.jsx)(t,{className:`h-4 w-4 shrink-0`}),(0,M.jsx)(`span`,{className:`truncate`,children:e})]}),Q]}),(0,M.jsx)(T.Provider,{value:()=>L(!I),children:(0,M.jsx)(`div`,{className:f(`min-h-0 flex-1 overflow-y-auto`,I&&!x&&typeof P!=`function`&&`mx-auto w-full max-w-3xl`),children:N&&Z?Z:typeof P==`function`?P(Q):P})})]});return I?(0,j.createPortal)((0,M.jsxs)(`div`,{className:`fixed inset-0 z-picker flex items-center justify-center gap-4 bg-scrim p-4 max-md:p-2`,children:[$,Z&&(0,M.jsx)(`div`,{className:`flex max-md:absolute max-md:inset-2 max-md:z-10`,children:Z})]}),document.body):(0,M.jsxs)(M.Fragment,{children:[$,!N&&Z&&(0,M.jsxs)(M.Fragment,{children:[(0,M.jsx)(`div`,{className:`fixed inset-0 z-card bg-scrim animate-fade-in md:hidden`,onClick:()=>!H&&z(!1),"aria-hidden":!0}),(0,M.jsx)(`div`,{ref:U,className:`relative shrink-0 md:z-panel md:ml-2 md:pr-2 max-md:fixed max-md:bottom-2 max-md:left-2 max-md:right-2 max-md:top-2 max-md:z-card-overlay max-md:animate-fade-in`,children:Z})]})]})}function P({onClose:e,onConfirm:t,fixedWorkspaceName:n,saving:r=!1,sizeClassName:i}){let[s,c]=(0,k.useState)(n?`browse`:`workspace`),[l,d]=(0,k.useState)([]),[y,b]=(0,k.useState)(!n),[S,w]=(0,k.useState)(n??null),[T,E]=(0,k.useState)(`context`),[D,O]=(0,k.useState)(new Set),[A,j]=(0,k.useState)(n);return n!==A&&(j(n),n||b(!0)),(0,k.useEffect)(()=>{n||x().then(d).catch(()=>d([])).finally(()=>b(!1))},[n]),(0,M.jsxs)(`div`,{className:f(`flex flex-col overflow-hidden rounded-(--panel-radius) border bg-card shadow-elevation-4`,i||`h-viewport-card max-h-full w-[min(420px,90vw)] max-md:h-full max-md:w-full max-md:shadow-elevation-5`),children:[(0,M.jsxs)(`div`,{className:`flex h-12 shrink-0 items-center justify-between border-b px-4`,children:[(0,M.jsxs)(`span`,{className:`flex items-center gap-2 text-sm font-medium`,children:[(0,M.jsx)(u,{className:`h-4 w-4`}),s===`workspace`?`Add existing documents…`:`Pick documents…`]}),(0,M.jsx)(`button`,{type:`button`,onClick:e,disabled:r,className:`text-muted-foreground transition-colors hover:text-foreground disabled:opacity-40`,"aria-label":`Close`,children:(0,M.jsx)(o,{className:`h-4 w-4`})})]}),(0,M.jsx)(`div`,{className:`flex-1 overflow-hidden`,children:(0,M.jsxs)(`div`,{className:`grid h-full w-[200%] grid-cols-2 transition-transform duration-normal`,style:{transform:s===`workspace`?`translateX(0)`:`translateX(-50%)`},children:[(0,M.jsx)(`div`,{className:`flex min-w-0 flex-col overflow-y-auto p-2`,children:(0,M.jsx)(v,{workspaces:l,loading:y,onPick:e=>{w(e),O(new Set),c(`browse`)}})}),(0,M.jsxs)(`div`,{className:`flex min-w-0 flex-col overflow-hidden`,children:[(0,M.jsxs)(`div`,{className:`flex shrink-0 items-center gap-1 border-b px-2 pt-2`,children:[!n&&(0,M.jsx)(`button`,{type:`button`,onClick:()=>c(`workspace`),className:`mr-1 rounded p-1.5 text-muted-foreground hover:bg-muted hover:text-foreground touch-target`,"aria-label":`Back to workspaces`,children:(0,M.jsx)(a,{className:`h-4 w-4 rotate-180`})}),[`context`,`directory`].map(e=>(0,M.jsxs)(`button`,{type:`button`,onClick:()=>{E(e),O(new Set)},className:f(`flex items-center gap-1.5 rounded-t-md border-b-2 px-3 py-2 text-xs font-medium transition-colors`,T===e?`border-primary text-foreground`:`border-transparent text-muted-foreground hover:text-foreground`),children:[g[e],h[e]]},e))]}),S&&(0,M.jsx)(_,{workspaceName:S,treeTab:T,onTreeTabChange:E,selectedDocIds:D,onToggleDoc:e=>{O(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},onNavigate:()=>O(new Set)})]})]})}),s===`browse`&&(0,M.jsxs)(`div`,{className:`flex shrink-0 items-center justify-between border-t px-4 py-3`,children:[(0,M.jsxs)(`span`,{className:`text-xs text-muted-foreground`,children:[D.size,` document`,D.size===1?``:`s`,` selected`]}),(0,M.jsx)(p,{size:`sm`,onClick:async()=>{!S||D.size===0||r||await t(Array.from(D),{workspaceName:S,treeName:T===`directory`?`directory`:C,treeType:T})},disabled:D.size===0||r,children:r?(0,M.jsxs)(M.Fragment,{children:[(0,M.jsx)(m,{className:`mr-1.5 h-3.5 w-3.5`}),`Adding…`]}):(0,M.jsxs)(M.Fragment,{children:[(0,M.jsx)(u,{className:`mr-1 h-3.5 w-3.5`}),`Add`]})})]})]})}export{N as n,P as t};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{o as e}from"./rolldown-runtime-C0FnF6B9.js";import{l as t,u as n}from"./code-editor-BOIngd5F.js";import{_ as r,g as i,h as a}from"./chunk-62JRHF6Z-vspAGgtK.js";import{t as o}from"./socket-CtH3EU9m.js";import{n as s}from"./use-toast-BlLDqSUO.js";import{o as c,s as l}from"./LinkToCard-5dg0jvSY.js";import{Bt as u,H as d,K as ee,Sn as te,t as f}from"./workspace-CrSpR4xf.js";import{r as ne}from"./document-list-DKOU9Kcc.js";import{n as re}from"./use-toolbox-Ck_cLGgf.js";import{E as ie,_ as ae,a as oe,b as se,i as ce,l as le,o as ue}from"./context-DQoZFMDQ.js";import{i as de}from"./color-DFEH4BfK.js";import{t as fe}from"./geo-CZfs0E-x.js";import{a as pe,i as me,o as he}from"./workspace-BydSRtST.js";import{i as ge}from"./use-menu-BiJ8N7sS.js";import{a as _e,c as ve,i as ye,l as be,n as xe,o as Se,r as Ce,s as we,t as Te}from"./content-app-view-y5TmcjuO.js";import{t as Ee}from"./use-workspace-identity-BCrrvfeE.js";var p=e(n(),1),m=t();function De(e,t){if(!e||!t)return`/`;let n=`${t}://`;if(!e.startsWith(n))return`/`;let r=e.slice(n.length).replace(/^\/+/,``).replace(/\/+$/,``);return r?`/${r}`:`/`}function h(){let{contextId:e}=r(),t=a(),n=i(),h=new URLSearchParams(t.search).get(`ownerId`)||void 0,g=(0,p.useMemo)(()=>{let e=new URLSearchParams(t.search),n=e.getAll(`q`).map(e=>e.trim()).filter(Boolean),r=(e.get(`search`)||``).trim();return n.length?n:r?[r]:[]},[t.search]),{showToast:_,showProgress:Oe}=s(),{state:v,saveFilters:ke,setSort:Ae,setAccentColor:y,setMapDocuments:b}=re(),{openM1Drawer:je,openM2Drawer:Me,goBack:Ne}=ge(),x=v.filters.features.allOf,Pe=v.filters.features.anyOf,Fe=v.filters.features.noneOf,Ie=[...me(v.filters.timeline),...pe(v.filters.geo),...he(v.filters.lens,v.filters.geo.includeUnlocated)],S=JSON.stringify({a:x,b:Pe,c:Fe,d:Ie,ids:v.filters.lens.ids,sort:v.filters.sort,geoSelection:v.geoSelection,includeUnlocated:v.filters.geo.includeUnlocated}),C=(0,p.useMemo)(()=>JSON.parse(S),[S]),[w,T]=(0,p.useState)(null),[Le,Re]=(0,p.useState)(!0),[ze,Be]=(0,p.useState)(null),[E,D]=(0,p.useState)([]),[Ve,He]=(0,p.useState)(!1),[Ue,O]=(0,p.useState)(0),[We,Ge]=(0,p.useState)([]),[k,A]=(0,p.useState)(1),[j,Ke]=(0,p.useState)(50),[M,N]=(0,p.useState)(g),[P,F]=(0,p.useState)(!1),[I,L]=(0,p.useState)(null),[R,qe]=(0,p.useState)(!1),z=(0,p.useRef)(!1),B=I?.id===w?.id&&I?.url===w?.url?I?.path:null,Je=new URLSearchParams(t.search).get(`layer`),V=!!h,Ye=Ee(V?void 0:w?.workspaceName||w?.workspaceId),H=w?De(w.url,w.workspaceName):`/`,Xe=Je?`context-layer`:`context`,U=!v.liveEnabled&&typeof w?.metadata?.toolboxSearchQuery==`string`?w.metadata.toolboxSearchQuery:``,W=V?null:w?.workspaceName??null,[Ze,Qe]=(0,p.useState)(null);(0,p.useEffect)(()=>{if(!W)return;let e=!1;return ee(W,f).then(t=>{e||Qe({key:W,tree:t})}).catch(()=>{e||Qe({key:W,tree:null})}),()=>{e=!0}},[W]);let G=W&&Ze?.key===W?Ze.tree:null,$e=!Je&&!V&&G?H===`/`?G:d(G,H):null,K=`${w?.workspaceName??``}\0${H}`,[q,et]=(0,p.useState)(null),J=q?.key===K?q.views:Se($e?.metadata),Y=q?.key===K?q.activeId:J[0]?.id??ye.id,X=J.find(e=>e.id===Y)??J[0]??ye,Z=_e(X);be(ve({workspace:w?.workspaceName||w?.workspaceId||null,treeNameOrId:v.activeTreeName,path:H,contextId:e??null,scope:`context`},{...v.filters,features:{...v.filters.features,allOf:Z?[...x,Z]:x}},v.geoSelection,M));let tt=e=>{A(1),et({key:K,views:J,activeId:e})},nt=(e,t)=>{t&&t!==Y&&A(1),et({key:K,views:e,activeId:t??Y}),w?.workspaceName&&te(w.workspaceName,H,{metadata:{...$e?.metadata??{},views:e}},f).catch(()=>{_({title:`View not saved`,description:`Could not persist views to the layer`,variant:`destructive`})})},rt=(0,p.useRef)(null);(0,p.useEffect)(()=>()=>rt.current?.abort(),[]);let Q=(0,p.useCallback)(async()=>{if(!e)return;rt.current?.abort();let t=new AbortController;rt.current=t,He(!0);try{let n=await ue(e,Z?[...C.a,Z]:C.a,C.d,{...C.sort,geoSelection:C.geoSelection,includeUnlocated:C.includeUnlocated,ids:C.ids,signal:t.signal,limit:j,page:k,queries:M.length?M:void 0,anyOf:C.b,noneOf:C.c,applyContextSpec:!1},h);if(t.signal.aborted)return;D(n),O(n.totalCount||n.count||n.length)}catch(e){if(t.signal.aborted)return;_({title:`Error`,description:e instanceof Error?e.message:`Failed to fetch documents`,variant:`destructive`}),D([]),O(0)}finally{t.signal.aborted||He(!1)}},[e,k,j,h,M,C,_,Z]),it=(0,p.useCallback)(async()=>{if(e){Re(!0);try{let t=V?await oe(e,h):await oe(e);if(!t)throw Error(`No context data received.`);let n=t.workspace,r=t.workspaceId||(typeof n==`string`?n:n?.id)||``,i=t.workspaceName||(typeof n==`string`?n:n?.name)||``;T({id:t.id,userId:t.userId,url:t.url,baseUrl:t.baseUrl||null,path:t.path||null,pathArray:t.pathArray||[],workspaceId:r,workspaceName:i,acl:t.acl||{},createdAt:t.createdAt,updatedAt:t.updatedAt,locked:t.locked||!1,serverContextArray:t.serverContextArray||[],clientContextArray:t.clientContextArray||[],contextBitmapArray:t.contextBitmapArray||[],featureBitmapArray:t.featureBitmapArray||[],filterArray:t.filterArray||[],pendingUrl:t.pendingUrl||null,description:t.description||null,metadata:t.metadata||{},name:t.name??null,color:t.color??null,icon:t.icon??null}),Be(null)}catch(t){let n=t instanceof Error?t.message:`Failed to fetch context ${e}`;Be(n),T(null),_({title:`Error`,description:n,variant:`destructive`})}Re(!1)}},[e,h,V,_]);(0,p.useEffect)(()=>{it()},[it]);let at=de(w?.color)||null;(0,p.useEffect)(()=>(y(at),()=>y(null)),[at,y]);let ot=v.geoSelection,st=w?.workspaceName||w?.workspaceId||null;(0,p.useEffect)(()=>{b(E,st)},[E,st,b]),(0,p.useEffect)(()=>()=>b([]),[b]);let ct=(0,p.useMemo)(()=>ot?E.filter(e=>fe(e,ot,v.filters.geo.includeUnlocated)):E,[E,ot,v.filters.geo.includeUnlocated]),lt=w?.id,ut=w?.url;(0,p.useEffect)(()=>{lt&&Q()},[lt,ut,Q]),(0,p.useEffect)(()=>{let e=()=>Q();return window.addEventListener(`workspace:documents:refresh`,e),()=>window.removeEventListener(`workspace:documents:refresh`,e)},[Q]);let[dt,ft]=(0,p.useState)(S);dt!==S&&(ft(S),A(1));let[pt,mt]=(0,p.useState)(e);pt!==e&&(mt(e),A(1),F(!1));let[ht,gt]=(0,p.useState)(g);ht!==g&&(gt(g),N(g),A(1));let[_t,vt]=(0,p.useState)({urlSearchQueries:g,ignoreSavedSearch:P,savedContextSearchQuery:U});(_t.urlSearchQueries!==g||_t.ignoreSavedSearch!==P||_t.savedContextSearchQuery!==U)&&(vt({urlSearchQueries:g,ignoreSavedSearch:P,savedContextSearchQuery:U}),!new URLSearchParams(t.search).has(`q`)&&!g.length&&!P&&(N(U?[U]:[]),A(1)));let $=(0,p.useCallback)(e=>{let r=new URLSearchParams(t.search);r.delete(`q`),r.delete(`search`);for(let t of e)r.append(`q`,t);let i=r.toString();n(`${t.pathname}${i?`?${i}`:``}${t.hash}`)},[t.pathname,t.search,t.hash,n]),yt=(0,p.useCallback)(e=>{let t=e.trim();if(!t)return;F(!1);let n=M.includes(t)?M:[...M,t];N(n),$(n)},[M,$]),bt=(0,p.useCallback)(e=>{let t=e<0?[]:M.filter((t,n)=>n!==e);t.length===0&&F(!0),N(t),$(t)},[M,$]),xt=(M[0]||``).trim(),St=!!v.activeContextType&&(v.isDirty||xt!==(v.savedSearchQuery||U||``));(0,p.useEffect)(()=>{if(!e)return;let t=`context:${h?`${h}/`:``}${e}`,n=()=>o.emit(`subscribe`,{channel:t}),r=()=>o.emit(`unsubscribe`,{channel:t}),i=o.on(`connect`,n);n();let a=new Map,s=(t,n)=>{let r=Date.now(),i=`${t}:${n?.id||n?.contextId||e}`;return(a.get(i)||0)+1e3>r?!1:(a.set(i,r),!0)},c=t=>{let n=t,r=n?.context||n;(r?.id===e||r?.contextId===e)&&s(`ctx:updated`,r)&&(T(e=>e?{...e,...r}:null),r.url&&Q())},l=t=>{let n=t,r=n?.id||n?.contextId||n?.context?.id,i=n?.url||n?.context?.url;r===e&&typeof i==`string`&&s(`ctx:url`,n)&&(T(e=>e?{...e,url:i}:null),Q())},u=t=>{let n=t;(n?.contextId||n?.id||n?.context?.id)===e&&s(`doc:changed`,n)&&Q()},d=[[`context.updated`,c],[`context:updated`,c],[`context.url.set`,l],[`context:url:set`,l],[`document.inserted`,u],[`document.updated`,u],[`document.removed`,u],[`document.removed.batch`,u],[`document.linked`,u],[`document.unlinked`,u],[`document.linked.batch`,u],[`document.unlinked.batch`,u],[`document.deleted`,u],[`document.deleted.batch`,u]];return d.forEach(([e,t])=>o.on(e,t)),()=>{i(),r(),d.forEach(([e,t])=>o.off(e,t))}},[e,h,Q]);let Ct=async e=>{if(w)try{await se(w.id,[e],h,H),D(t=>t.filter(t=>t.id!==e)),O(e=>Math.max(0,e-1)),_({title:`Success`,description:`Document removed from context.`})}catch(e){_({title:`Error`,description:e instanceof Error?e.message:`Failed to remove document`,variant:`destructive`})}},wt=async e=>{if(w)try{await ce(w.id,[e],h,H),D(t=>t.filter(t=>t.id!==e)),O(e=>Math.max(0,e-1)),_({title:`Success`,description:`Document deleted.`})}catch(e){_({title:`Error`,description:e instanceof Error?e.message:`Failed to delete document`,variant:`destructive`})}},Tt=async e=>{if(w)try{await se(w.id,e,h,H),D(t=>t.filter(t=>!e.includes(t.id))),O(t=>Math.max(0,t-e.length)),_({title:`Success`,description:`${e.length} document(s) removed.`})}catch(e){_({title:`Error`,description:e instanceof Error?e.message:`Failed to remove documents`,variant:`destructive`})}},Et=async e=>{if(w)try{await ce(w.id,e,h,H),D(t=>t.filter(t=>!e.includes(t.id))),O(t=>Math.max(0,t-e.length)),_({title:`Success`,description:`${e.length} document(s) deleted.`})}catch(e){_({title:`Error`,description:e instanceof Error?e.message:`Failed to delete documents`,variant:`destructive`})}},Dt=e=>{Ge(e),_({title:`Copied`,description:`${e.length} document(s) copied to clipboard`})},Ot=async(e,t,n={})=>{if(!w)return!1;let r=Oe({title:`Pasting…`,description:`${t.length} document(s) → "${e}"`});try{let i=n.targetTreeName&&!V?await u(w.workspaceName||w.workspaceId,e,t,n.targetTreeName,n.targetTreeType):await ae(w.id,e,t,h);return r.done(i?{title:`Success`,description:`${t.length} document(s) pasted to "${e}"`}:void 0),i&&(Ge([]),await Q()),i}catch(e){return r.fail({title:`Error`,description:e instanceof Error?e.message:`Failed to paste documents`,variant:`destructive`}),!1}},kt=async(e,t)=>{if(!w)return!1;try{let n=await le(w.workspaceId,t,e);return n&&(ne(w.workspaceName||w.workspaceId,`context`,t),_({title:`Success`,description:`Imported ${e.length} document(s) to "${t}"`})),n}catch(e){return _({title:`Error`,description:e instanceof Error?e.message:`Failed to import documents`,variant:`destructive`}),!1}},At=async()=>{if(!w||!B||V||z.current)return;let e={id:w.id,url:w.url,path:B};z.current=!0,qe(!0);try{let t=await ie(e.id,`${w.workspaceName}://${e.path.replace(/^\/+/,``)}`);T(n=>n?.id===e.id&&n.url===e.url?{...n,url:t.url,path:e.path}:n),L(null),A(1),window.dispatchEvent(new CustomEvent(`contexts:refresh`,{detail:{contextId:e.id}})),_({title:`Saved`,description:`Context path updated`})}catch(e){_({title:`Error`,description:e instanceof Error?e.message:`Could not update context path`,variant:`destructive`})}finally{z.current=!1,qe(!1)}};if(Le)return(0,m.jsx)(`div`,{className:`flex items-center justify-center h-full`,children:(0,m.jsxs)(`div`,{className:`text-center space-y-2`,children:[(0,m.jsx)(`div`,{className:`animate-spin rounded-full h-8 w-8 border-b-2 border-primary mx-auto`}),(0,m.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`Loading context...`})]})});if(ze&&!w)return(0,m.jsxs)(`div`,{className:`flex items-center justify-center h-full text-destructive`,children:[`Error: `,ze]});if(!w)return(0,m.jsx)(`div`,{className:`flex items-center justify-center h-full text-muted-foreground`,children:`Context not found.`});let jt=de(w.color);return(0,m.jsx)(`div`,{className:`flex flex-col h-full min-h-0`,children:(0,m.jsx)(we,{onBack:Ne,accentColor:jt,navigationTabs:$e?(0,m.jsx)(Ce,{views:J,activeId:Y,onSelect:tt,onSave:nt,accentColor:jt}):void 0,workspaceLabel:Ye?.label||w.workspaceName||w.workspaceId,workspaceIcon:Ye?.icon,treeName:f,urlType:Xe,urlDisplay:w.url,contextPath:H,workspaceId:w.workspaceName||w.workspaceId,documentSchema:Z,linkTree:G,documents:ct,isLoading:Ve,totalCount:Ue,currentPage:k,pageSize:j,onPageChange:A,onPageSizeChange:e=>{Ke(e),A(1)},onRemoveDocument:H===`/`?void 0:Ct,onDeleteDocument:wt,onRemoveDocuments:H===`/`?void 0:Tt,onDeleteDocuments:Et,onCopyDocuments:Dt,onPasteDocuments:Ot,onImportDocuments:V?void 0:kt,pastedDocumentIds:We,backendSearchQueries:M,onBackendSearch:yt,serverSort:v.filters.sort,onServerSortChange:Ae,onRemoveBackendQuery:bt,canSaveChanges:St,isSavingChanges:v.isSaving,onSaveChanges:ke,onBrowseTree:!V&&e?()=>Me(`contexts`,`detail`,e):void 0,onBrowseWorkspaces:()=>je(`workspaces`),onNavigatePath:V?void 0:e=>{z.current||L({id:w.id,url:w.url,path:e})},contentBanner:B?(0,m.jsxs)(`div`,{className:`border-b bg-warning/10 px-4 py-2`,role:`status`,children:[(0,m.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`Set this context to the selected path? Contents stay at the current path until you apply it.`}),(0,m.jsxs)(`div`,{className:`flex min-w-0 items-center gap-2`,children:[(0,m.jsx)(l,{items:c(B,w.workspaceName),label:`Selected context path`}),(0,m.jsx)(`button`,{type:`button`,disabled:R,onClick:()=>void At(),className:`shrink-0 rounded border px-3 py-1 text-sm hover:bg-accent disabled:opacity-50`,children:R?`Setting…`:`Set`}),(0,m.jsx)(`button`,{type:`button`,disabled:R,onClick:()=>L(null),className:`shrink-0 rounded px-2 py-1 text-sm hover:bg-accent disabled:opacity-50`,children:`Cancel`})]})]}):void 0,children:X.kind===`columns`?(0,m.jsx)(xe,{documents:ct,workspaceId:w.workspaceName||w.workspaceId,columns:X.columns??[],onColumnsChange:e=>nt(J.map(t=>t.id===X.id?{...t,columns:e}:t))}):X.kind===`app`&&X.app&&X.app!==`notes`?(0,m.jsx)(Te,{app:X.app,contextId:e,workspaceId:w.workspaceName||w.workspaceId,treeName:f,path:H}):null})})}export{h as default};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{o as e}from"./rolldown-runtime-C0FnF6B9.js";import{l as t,u as n}from"./code-editor-BOIngd5F.js";import{_ as r,g as i,h as a}from"./chunk-62JRHF6Z-vspAGgtK.js";import{Br as o,Hr as s,L as c,fn as l}from"./ui-Byg1cZDr.js";import{t as u}from"./utils-2pl1SbIp.js";import{t as d}from"./button-SgR3GVvV.js";import{c as f,t as p}from"./api-CA6WiiYM.js";import{t as m}from"./socket-CtH3EU9m.js";import{n as h}from"./use-toast-BlLDqSUO.js";import{Bt as ee,Ht as g,Jt as _,K as te,Nt as ne,O as re,S as v,Sn as ie,T as ae,Yt as y,Z as oe,at as se,b as ce,bt as le,d as ue,dt as de,gt as fe,hn as b,it as pe,o as me,q as he,sn as x,v as ge,vt as _e}from"./workspace-CrSpR4xf.js";import{n as ve,r as ye}from"./use-canvas-pins-BvN6Gw6f.js";import{u as be}from"./ObjectPropertiesCard-BIBMvx_i.js";import{h as xe,i as S,r as Se}from"./document-list-DKOU9Kcc.js";import{n as Ce}from"./use-toolbox-Ck_cLGgf.js";import{i as we}from"./color-DFEH4BfK.js";import{t as Te}from"./geo-CZfs0E-x.js";import{c as Ee}from"./backend-sync-progress-pZrhQPk3.js";import{a as De,i as Oe,n as ke,o as Ae}from"./workspace-BydSRtST.js";import{n as je,r as Me,t as Ne}from"./url-params-n7kU_WZ-.js";import{i as Pe}from"./use-menu-BiJ8N7sS.js";import{n as Fe}from"./last-path-BbXWC3b3.js";import{t as Ie}from"./workspace-area-menu-C0-X-FpD.js";import{t as Le}from"./workspace-content-gate-9okuA7J7.js";import{t as Re}from"./form-panel-C34lByEH.js";import{a as ze,c as Be,i as Ve,l as He,n as Ue,o as We,r as Ge,s as Ke,t as qe}from"./content-app-view-y5TmcjuO.js";import{i as Je,o as Ye,r as Xe}from"./query-debug-CrPsUwT-.js";var C=`session.open`,Ze=`session.set`,Qe=`session.ids`,$e=`session.materialize`,et=`session.close`,w=`session.delta`,T=e(n(),1),E=t();function tt({workspaceId:e,workspaceName:t}){let[n,r]=(0,T.useState)([]),[i,a]=(0,T.useState)(new Set),o=t=>`${e}:${t.address}:${t.resyncStartedAt||``}`;(0,T.useEffect)(()=>{let t=!1,n=!1,i=!1,a=0,o=new Map,s=new Map,c=(e,t)=>{let n=e.filter(e=>e.address!==t.backend);if(!t.resyncing)return n;let r=e.find(e=>e.address===t.backend)||s.get(t.backend);return[...n,{address:t.backend,config:r?.config,resyncStartedAt:r?.resyncStartedAt||new Date().toISOString(),progress:t.progress??r?.progress}]},l=async()=>{if(n){i=!0;return}n=!0;let u=a;try{let n=await le(e);if(!t){s=new Map(n.map(e=>[e.address,e]));let e=n.filter(e=>e.resyncing);for(let t of o.values())t.version>u&&(e=c(e,t.event));r(e)}}catch{}finally{n=!1,i&&!t&&(i=!1,l())}},u=t=>{t.workspaceId!==e||!t.backend||typeof t.resyncing!=`boolean`||(o.set(t.backend,{version:++a,event:t}),r(e=>c(e,t)))},d=t=>{t.workspaceId===e&&l()};l();let f=m.on(`connect`,l);return m.on(`backend.resync.changed`,u),m.on(`backend.changed`,d),window.addEventListener(`focus`,l),()=>{t=!0,f?.(),m.off(`backend.resync.changed`,u),m.off(`backend.changed`,d),window.removeEventListener(`focus`,l)}},[e]);let s=n.filter(e=>!i.has(o(e)));return s.length?(0,E.jsxs)(`aside`,{"aria-label":`Storage scans for ${t}`,className:`absolute bottom-5 right-5 z-50 w-72 max-w-[calc(100vw-2.5rem)] rounded-lg border bg-popover/95 p-3 text-popover-foreground shadow-lg backdrop-blur`,children:[(0,E.jsxs)(`div`,{role:`status`,className:`mb-2 flex items-center gap-2 text-sm font-medium`,children:[(0,E.jsx)(l,{"aria-hidden":`true`,className:`h-4 w-4 animate-spin`}),(0,E.jsxs)(`span`,{className:`min-w-0 flex-1`,children:[(0,E.jsx)(`span`,{className:`block`,children:`Scanning storage`}),(0,E.jsx)(`span`,{className:`block truncate text-xs font-normal text-muted-foreground`,title:t,children:t})]}),(0,E.jsx)(`button`,{type:`button`,"aria-label":`Hide scan progress for ${t}`,title:`Hide progress; scanning continues`,className:`rounded p-1 hover:bg-muted focus-visible:outline focus-visible:outline-2`,onClick:()=>a(e=>new Set([...e,...s.map(o)])),children:(0,E.jsx)(c,{"aria-hidden":`true`,className:`h-4 w-4`})})]}),(0,E.jsx)(`div`,{className:`max-h-48 space-y-3 overflow-y-auto`,children:s.map(e=>{let{scanned:t=0,total:n=null}=e.progress||{},r=n&&n>0?Math.min(100,Math.round(t/n*100)):null,i=typeof e.config?.label==`string`?e.config.label:e.address;return(0,E.jsxs)(`div`,{children:[(0,E.jsxs)(`div`,{className:`flex items-center justify-between gap-3 text-xs`,children:[(0,E.jsx)(`span`,{className:`truncate`,children:i}),(0,E.jsx)(`span`,{className:`shrink-0 text-muted-foreground`,children:n===null?`${t} files`:`${t} / ${n}`})]}),(0,E.jsx)(`div`,{role:`progressbar`,"aria-label":`Scanning ${i}`,"aria-valuemin":0,"aria-valuemax":100,"aria-valuenow":r??void 0,className:`mt-1.5 h-1 overflow-hidden rounded-full bg-muted`,children:(0,E.jsx)(`div`,{className:`h-full rounded-full bg-primary ${r===null?`animate-pulse`:`transition-all`}`,style:{width:r===null?`35%`:`${r}%`}})})]},e.address)})})]}):null}var nt=e=>e&&typeof e==`object`&&!Array.isArray(e)?e:null;function D(e){return`/${e}`.replace(/\/+/g,`/`).replace(/\/$/,``)||`/`}function rt(e,t,n){if(e==null)return[];if(Array.isArray(e))return e.flatMap(e=>rt(e,t,n));if(typeof e==`string`)return[{tree:null,kind:t,path:D(e)}];let r=nt(e);if(!r)return[];let i=r.tree??r.treeId,a=typeof i==`string`?n.get(i)??null:null;return[].concat(r.paths??r.path??`/`).filter(e=>typeof e==`string`).map(e=>({tree:a,kind:t,path:D(e)}))}function O(e){let t=[],n=e=>{let n=Number(e);Number.isSafeInteger(n)&&n>0&&t.push(n)};return Array.isArray(e.ids)&&e.ids.forEach(n),Array.isArray(e.documentIds)&&e.documentIds.forEach(n),e.id!=null&&n(e.id),e.documentId!=null&&n(e.documentId),t}function it(e){let t=new Map;for(let n of e)t.set(n.id,n.name),t.set(n.name,n.name);return t}function at(e,t,n=new Map){let r=nt(t);if(!r)return{targets:[],ids:[],unknown:!0};if(e.startsWith(`tree.`)){let e=typeof r.treeName==`string`?r.treeName:null,t=r.treeType===`directory`||r.treeType===`context`?r.treeType:null,n=r.contextSpec??r.path;return typeof n==`string`?{targets:[{tree:e,kind:t,path:D(n)}],ids:O(r),unknown:!1}:{targets:[],ids:[],unknown:!0}}let i=[...rt(r.context,`context`,n),...rt(r.directory,`directory`,n)],a=nt(r.changed);a&&i.push(...rt(a.context,`context`,n),...rt(a.directory,`directory`,n));let o=O(r);if(i.length)return{targets:i,ids:o,unknown:!1};let s=r.reason===`content`||r.reason===`relations`;return e.startsWith(`document.updated`)&&s&&o.length?{targets:[],ids:o,unknown:!1}:{targets:[],ids:o,unknown:!0}}function k(e,t){return e===t||e===`/`||t===`/`||e.startsWith(`${t}/`)||t.startsWith(`${e}/`)}function ot(e,t){if(e.kind&&e.kind!==t.kind||e.tree&&e.tree!==t.tree)return!1;if(t.kind===`context`){let n=e=>D(e).split(`/`).filter(Boolean).map(e=>e.normalize(`NFKC`).trim().replace(/\s+/g,` `).replace(/[^\p{L}\p{N}\p{M} .+_@-]/gu,`_`).replace(/_+/g,`_`).toLowerCase()||`_`),r=new Set(n(e.path)),i=n(t.path);return r.size===0||i.length===0||i.some(e=>r.has(e))}return k(e.path,t.path)}function st(e){return at(`tree.refresh`,{treeName:e?.treeName,path:e?.path||`/`})}function ct(e,t,n){if(e.unknown||e.targets.length&&(t.wholeWorkspace||e.targets.some(e=>ot(e,t))))return!0;if(e.ids.length&&n){let t=n instanceof Set?n:new Set(n);if(e.ids.some(e=>t.has(e)))return!0}return!1}function lt(e,t,n={}){return m.request(C,{workspace:e,specs:t,opts:n})}function ut(e,t,n){return m.request(Ze,{sessionId:e,label:t,spec:n})}function dt(e){return m.request(Qe,{sessionId:e})}function A(e,t={}){return m.request($e,{sessionId:e,...t})}function ft(e){return m.request(et,{sessionId:e})}function pt(e){return m.on(w,e)}var mt=100;function ht({workspaceRef:e,specs:t,opts:n,enabled:r=!0}){let[i,a]=(0,T.useState)([]),[o,s]=(0,T.useState)(0),[c,l]=(0,T.useState)(null),[u,d]=(0,T.useState)(null),f=(0,T.useRef)([]),p=(0,T.useRef)(new Map),h=(0,T.useRef)(null),ee=(0,T.useRef)(null),g=(0,T.useRef)(null),_=(0,T.useRef)({}),te=(0,T.useRef)(null),ne=(0,T.useMemo)(()=>JSON.stringify(t),[t]),re=(0,T.useMemo)(()=>JSON.stringify(n??{}),[n]),v=(0,T.useCallback)(()=>{let e=p.current;a(f.current.map(t=>e.get(t)).filter(Boolean))},[]),ie=(0,T.useCallback)(async e=>{let t=ee.current;if(!t||e.length===0)return[];let n=[];for(let r=0;r<e.length;r+=mt){let i=e.slice(r,r+mt),a=await pe(t,`/`,[],{ids:i,scope:`workspace`,limit:i.length});n.push(...a.payload||[])}return n},[]),ae=(0,T.useCallback)(async(e,t,n)=>{if(t.length>0){let e=new Set(t);f.current=f.current.filter(t=>!e.has(t));for(let t of e)p.current.delete(t)}let r=e.filter(e=>!p.current.has(e)),i=new Set(f.current);for(let t of e)i.has(t)||(f.current.push(t),i.add(t));if(n!==null&&s(n),v(),r.length===0)return;let a=await ie(r);for(let e of a)p.current.set(e.id,e);let o=new Set(a.map(e=>e.id)),c=r.filter(e=>!o.has(e));if(c.length>0){let e=new Set(c);f.current=f.current.filter(t=>!e.has(t))}v()},[ie,v]),y=(0,T.useCallback)(async(e,t)=>{let n=e??[],r=new Set(n);f.current=f.current.filter(e=>r.has(e));for(let e of p.current.keys())r.has(e)||p.current.delete(e);let i=new Set(f.current),a=n.filter(e=>!i.has(e));await ae(a,[],t)},[ae]);(0,T.useEffect)(()=>{if(ee.current=e??null,!r||!e)return;let t=!1,n=null,i=async()=>{try{let r=await lt(e,JSON.parse(ne),JSON.parse(re));if(t){ft(r.sessionId).catch(()=>{});return}n=r.sessionId,h.current=r.sessionId,l(r.sessionId),d(null),f.current=[],p.current=new Map,await y(r.ids,r.count)}catch(e){if(t)return;d(e instanceof Error?e.message:`Failed to open query session`),l(null),h.current=null}};i();let o=m.on(`connect`,()=>{i()});return()=>{t=!0,o?.();let e=n??h.current;e&&ft(e).catch(()=>{}),h.current=null,f.current=[],p.current=new Map,l(null),a([]),s(0)}},[e,ne,re,r]),(0,T.useEffect)(()=>{if(!c)return;let e=pt(e=>{if(e.sessionId===c){if(g.current!==null){te.current?.(g.current,_.current);return}e.ids===void 0?ae(e.added??[],e.removed??[],e.count):y(e.ids,e.count)}});return()=>{e?.()}},[c,ae,y]);let oe=(0,T.useCallback)(async()=>{let e=h.current;if(e)try{let t=await dt(e);await y(t.ids,t.count)}catch{}},[y]),se=(0,T.useCallback)(async(e,t)=>{let n=h.current;if(!n)throw Error(`No open query session`);let r=await ut(n,e,t);if(g.current!==null){await te.current?.(g.current,_.current);return}await y(r.ids,r.count)},[y]),ce=(0,T.useCallback)(async(e,t={})=>{let n=h.current;if(!n)throw Error(`No open query session`);if(g.current=e,_.current=t,e===null){await oe();return}let r=await A(n,{match:e,...t});for(let e of r.documents)p.current.set(e.id,e);f.current=r.ids,s(r.totalCount),v()},[v,oe]);(0,T.useEffect)(()=>{te.current=ce},[ce]);let le=(0,T.useCallback)(async(e,t,n={})=>{let r=h.current;if(!r)throw Error(`No open query session`);let i=await A(r,{match:t,limit:n.limit??100,...n.mode?{mode:n.mode}:{}});for(let e of i.documents)p.current.set(e.id,e);let a=await ut(r,e,{ids:i.ids});return await y(a.ids,a.count),i.ids},[y]);return{documents:i,count:o,ready:c!==null,error:u,setCue:se,resync:oe,rank:ce,rankAndPin:le}}function gt({data:e,className:t}){let[n,r]=(0,T.useState)(!0),{rows:i,gapIndex:a,span:c}=(0,T.useMemo)(()=>{let t=[...e.distances].sort((e,t)=>e.distance-t.distance),n=[];for(let e=1;e<t.length;e++)n.push(t[e].distance-t[e-1].distance);let r=n.length?[...n].sort((e,t)=>e-t)[Math.floor(n.length/2)]:0,i=-1,a=0;for(let e=0;e<n.length;e++)n[e]>a&&(a=n[e],i=e+1);let o=i>0&&a>=Math.max(r*4,1e-6),s=t[0]?.distance??0,c=t[t.length-1]?.distance??0;return{rows:t,gapIndex:o?i:-1,span:{first:s,last:c,biggest:a,median:r}}},[e.distances]);if(i.length===0)return(0,E.jsxs)(`div`,{className:u(`rounded-md border border-dashed border-border px-3 py-2 text-xs text-muted-foreground`,t),children:[`Query debug: no image distances for “`,e.query,`”. The dense side returned nothing: either no photos are embedded in this scope, or the image space is not ready.`]});let l=a>0?i[a].distance:null;return(0,E.jsxs)(`div`,{className:u(`rounded-md border border-border bg-muted/30 text-xs`,t),children:[(0,E.jsxs)(`button`,{type:`button`,onClick:()=>r(e=>!e),className:`flex w-full items-center gap-1.5 px-3 py-2 text-left font-medium`,children:[n?(0,E.jsx)(s,{className:`h-3.5 w-3.5`}):(0,E.jsx)(o,{className:`h-3.5 w-3.5`}),`Query debug`,(0,E.jsxs)(`span`,{className:`font-normal text-muted-foreground`,children:[`: image distances for “`,e.query,`” (`,i.length,` nearest, unfloored)`]})]}),n&&(0,E.jsxs)(`div`,{className:`space-y-2 border-t border-border px-3 py-2`,children:[(0,E.jsxs)(`p`,{className:`text-[11px] text-muted-foreground`,children:[`Best-first cosine distance (0 = identical). Scroll to where the photos stop being relevant and set the image relevance floor just above that value in Settings → Database → Search tuning.`,l===null?(0,E.jsxs)(E.Fragment,{children:[` `,(0,E.jsx)(`span`,{className:`text-amber-600 dark:text-amber-500`,children:`No boundary in this window`}),`; the distances step evenly (typical Δ`,c.median.toFixed(4),`), so there is nothing here to set a floor from. Relevance probably ends further down the list than this window reaches, or the model is not separating this query at all.`]}):(0,E.jsxs)(E.Fragment,{children:[` A jump at `,(0,E.jsx)(`span`,{className:`font-mono`,children:l.toFixed(4)}),` (Δ`,c.biggest.toFixed(4),`, vs typical Δ`,c.median.toFixed(4),`) stands out (a likely boundary).`]})]}),(0,E.jsx)(`div`,{className:`max-h-56 overflow-y-auto`,children:(0,E.jsx)(`table`,{className:`w-full font-mono text-[11px]`,children:(0,E.jsx)(`tbody`,{children:i.map((e,t)=>(0,E.jsxs)(`tr`,{className:u(`border-b border-border/40 last:border-0`,t===a&&`border-t-2 border-t-amber-500/70`),children:[(0,E.jsx)(`td`,{className:`py-0.5 pr-3 text-muted-foreground`,children:t+1}),(0,E.jsxs)(`td`,{className:`py-0.5 pr-3`,children:[`#`,e.id]}),(0,E.jsx)(`td`,{className:`py-0.5 tabular-nums`,children:e.distance.toFixed(4)}),t===a&&(0,E.jsx)(`td`,{className:`py-0.5 pl-2 font-sans text-[10px] text-amber-600 dark:text-amber-500`,children:`← biggest gap`})]},e.id))})})}),(0,E.jsxs)(`p`,{className:`text-[11px] text-muted-foreground`,children:[`Range `,c.first.toFixed(4),` – `,c.last.toFixed(4),` (spread `,(c.last-c.first).toFixed(4),`) over `,i.length,` rows. Absolute values shift with the model and are not comparable across models. After a re-embed every floor has to be picked again. A spread this narrow relative to the range means ranking is doing the work, not distance.`]})]})]})}function _t(e,t){if(!e)return[];let n=t.split(`/`).filter(Boolean),r=e;for(let e of n)if(r=r?.children?.find(t=>t.name===e)??null,!r)return[];let i=n.length?`/${n.join(`/`)}`:``,a=(r.children??[]).filter(e=>e.type!==`canvas`).map(e=>({name:e.name,path:`${i}/${e.name}`,label:e.label,color:e.color,childCount:e.children?.length??0})).sort((e,t)=>(e.label||e.name).localeCompare(t.label||t.name,void 0,{numeric:!0,sensitivity:`base`}));return n.length>0&&a.unshift({name:`..`,path:n.length>1?`/${n.slice(0,-1).join(`/`)}`:`/`,isParent:!0}),a}var vt=new Map;function yt(e,t,n){return`${e}\0${t}\0${n}`}function bt(e,t,n,r,i,a,o=``,s=``,c=`path`){return`${yt(e,t,n)}\0${r}\0${i}\0${a}\0${o}\0${s}\0${c}`}function j(e,t,n){let r=yt(e,t,n);for(let e of vt.keys())e.startsWith(r)&&vt.delete(e)}function xt(e,t){let n=`${e}\0`;for(let[e,r]of vt){if(!e.startsWith(n))continue;let[,i,a,,,,,,o=`path`]=e.split(`\0`);ct(t,{tree:i,kind:b(i),path:a,wholeWorkspace:o.startsWith(`workspace`)},r.documents.map(e=>Number(e.id)))&&vt.delete(e)}}function St(e,t){xt(t?.workspaceName??e,st(t))}function Ct(){let{workspaceName:e}=r();return e?(0,E.jsx)(Le,{workspaceName:e,children:(0,E.jsx)(M,{})}):null}function M(){let{workspaceName:e,treeName:t}=r(),n=a(),o=i(),{showToast:s,showProgress:c}=h(),l=new URLSearchParams(n.search),Le=(()=>{let e=l.getAll(`q`).map(e=>e.trim()).filter(Boolean);if(e.length>0)return e;let t=(l.get(`search`)||``).trim();return t?[t]:[]})(),[C,Ze]=(0,T.useState)(null),[Qe,$e]=(0,T.useState)(!0),[et,w]=(0,T.useState)([]),[nt,D]=(0,T.useState)(!1),[rt,O]=(0,T.useState)(0),k=Xe(),[ot,lt]=(0,T.useState)(null),[ut,dt]=(0,T.useState)(k);ut!==k&&(dt(k),k||lt(null));let[A,ft]=(0,T.useState)(`path`),[pt,mt]=(0,T.useState)(!1),[yt,Ct]=(0,T.useState)(null),[M,wt]=(0,T.useState)(null),[Et,Dt]=(0,T.useState)(``),[Ot,kt]=(0,T.useState)(!1),[At,jt]=(0,T.useState)(!1),[Mt,Nt]=(0,T.useState)(!1),[N,Pt]=(0,T.useState)(null),[P,F]=(0,T.useState)(1),[I,Ft]=(0,T.useState)(50),[L,It]=(0,T.useState)(Le),[Lt,Rt]=(0,T.useState)(null),{state:R,saveFilters:zt,setSort:Bt,setAccentColor:Vt,setMapDocuments:Ht}=Ce(),Ut=R.filters.features.allOf,z=R.filters.features.anyOf,Wt=R.filters.features.noneOf,Gt=Oe(R.filters.timeline),Kt=De(R.filters.geo),qt=Ae(R.filters.lens,R.filters.geo.includeUnlocated),B=R.filters.lens.ids,Jt=[...Gt,...Kt,...qt],Yt=R.filters.sort??ke,Xt=JSON.stringify({a:Ut,b:z,c:Wt,d:Jt,i:B,s:Yt}),Zt=JSON.stringify({a:Ut,b:z,c:Wt,d:Jt,s:Yt}),V=je(n.pathname).path,H=t??`context`,U=H===`backends`,[Qt,$t]=(0,T.useState)([]);(0,T.useEffect)(()=>{!U||!e||le(e).then($t).catch(()=>$t([]))},[U,e]);let en=U?me(V,Qt):null,[tn,nn]=(0,T.useState)(!1),rn=`${H}\0${V}`,[an,on]=(0,T.useState)(rn);an!==rn&&(on(rn),nn(!1));let W=l.get(`layer`)===`1`,G=l.get(`layerId`)||null,[K,sn]=(0,T.useState)(null),[q,cn]=(0,T.useState)(null),ln=(0,T.useRef)(null);(0,T.useEffect)(()=>{ln.current=q},[q]);let[un,dn]=(0,T.useState)(`left`),[fn,pn]=(0,T.useState)([]),{openM1Drawer:mn,openM2Drawer:hn,goBack:gn}=Pe(),[_n,vn]=(0,T.useState)([]),J=(0,T.useMemo)(()=>{if(!K||V===`/`||W)return null;let e=V.split(`/`).filter(Boolean),t=K;for(let n of e)if(t=t?.children?.find(e=>e.name===n)??null,!t)return null;return t},[K,V,W]),Y=J?.type===`canvas`?`canvas`:null,yn=(0,T.useRef)(null);(0,T.useEffect)(()=>{!e||!K||W||yn.current===`${e}/${H}`&&(V!==`/`&&!J||Fe(e,H,V))},[e,K,W,V,J,H]);let bn=(0,T.useMemo)(()=>W||A===`workspace`||L.length>0||b(H)!==`directory`?[]:_t(K,V),[K,V,H,W,A,L]),xn=W?null:V===`/`?K:J,X=xe(),Sn=`${H}\0${V}`,[Cn,wn]=(0,T.useState)(null),Tn=Cn?.key===Sn?Cn.views:We(xn?.metadata),En=X?.pinned&&X.view?[X.view,...Tn.filter(e=>e.id!==X.view.id)]:Tn,Dn=X?.pinned&&X.view?X.view.id:Cn?.key===Sn?Cn.activeId:En[0]?.id??Ve.id,Z=En.find(e=>e.id===Dn)??En[0]??Ve;(0,T.useEffect)(()=>{X?.selectView(Z)},[Z,X]);let On=U?void 0:X?.schema??ze(Z),kn=On?[...Ut,On]:Ut;He(Be({workspace:e??null,treeNameOrId:H,treeType:b(H),path:V,scope:A===`workspace`?`workspace`:W?`layer`:`path`,layerId:W?G:void 0,unfiledOnly:tn},{...R.filters,features:{...R.filters.features,allOf:kn}},R.geoSelection,L));let An=e=>{let t=En.find(t=>t.id===e);t&&X?.selectView(t),F(1),pn([]),wn({key:Sn,views:En,activeId:e})},jn=(t,n)=>{n&&n!==Dn&&(F(1),pn([]));let r=t.find(e=>e.id===(n??Dn));r&&X?.selectView(r),wn({key:Sn,views:t,activeId:n??Dn}),ie(e,V,{metadata:{...xn?.metadata??{},views:t}},H).catch(()=>{s({title:`View not saved`,description:`Could not persist views to the layer`,variant:`destructive`})})},Mn=Y===`canvas`&&typeof J?.querySpec?.query==`string`?J.querySpec.query:``,Nn=Y===`canvas`?{label:J?.label,description:J?.description,color:J?.color}:null,{isPinned:Pn,pin:Fn,unpin:In,pins:Ln}=ve(),Rn=C?.name,Q=(0,T.useMemo)(()=>Rn&&Y===`canvas`&&!W?{workspaceName:Rn,treeName:H,path:V}:null,[Rn,Y,W,H,V]),zn=Q?Pn(Q):!1,Bn=J?.id,Vn=J?.label,Hn=(0,T.useCallback)(async()=>{if(Q)try{let e=Ln.find(e=>e.workspaceName===Q.workspaceName&&e.treeName===Q.treeName&&e.path===Q.path);e?await In(e.id):await Fn({...Q,layerId:Bn,label:Vn})}catch(e){console.error(`Failed to update home pins:`,e)}},[Q,Ln,Fn,In,Bn,Vn]),Un=e?`${e}://${V===`/`?``:V.replace(/^\//,``)}`:``,Wn=we(C?.color)||null;(0,T.useEffect)(()=>(Vt(Wn),()=>Vt(null)),[Wn,Vt]);let Gn=(0,T.useCallback)(async t=>{let n=B;if(t?.anyOf?.length&&z.length&&(n=((await he(e,V,H,{limit:0,anyOf:z,ids:B,applyCanvasSpec:!1})).payload||[]).map(e=>e.id),!n.length))return{payload:[],count:0,totalCount:0};let r=await he(e,V,H,{limit:t?.limit,offset:t?.offset,page:t?.page,sortBy:t?.sortBy,order:t?.order,allOf:[...Ut,...t?.allOf??[]],anyOf:t?.anyOf?.length?t.anyOf:z,noneOf:Wt,filters:Jt,ids:n,queries:[...L,...t?.queries??[],...t?.q?[t.q]:[]],applyCanvasSpec:!1});return{payload:r.payload||[],count:r.count??void 0,totalCount:r.totalCount??void 0}},[e,V,H,Xt,L]);(0,T.useEffect)(()=>{e&&(async()=>{$e(!0);try{let t=await p.get(`${f.workspaces}/${e}`),n;n=t&&`workspace`in t?t.workspace:t,Ze(n)}catch(t){let n=t instanceof Error?t.message:`Failed to fetch workspace ${e}`;s({title:`Error`,description:n,variant:`destructive`}),Ze(null)}finally{$e(!1)}})()},[e,s]),(0,T.useEffect)(()=>{let e=e=>{let t=e.detail?.workspace;t&&Ze(e=>e&&(t===e.name||t===e.id)&&e.status!==`active`?{...e,status:`active`}:e)};return window.addEventListener(`workspace:autostarted`,e),()=>window.removeEventListener(`workspace:autostarted`,e)},[]);let Kn=(B?.length??0)>0&&!W&&!(tn&&en)&&L.length<=1,{documents:qn,count:Jn,ready:Yn,setCue:Xn,resync:Zn,rank:Qn}=ht({workspaceRef:e,specs:(0,T.useMemo)(()=>{let e={features:{allOf:kn,anyOf:z,noneOf:Wt},filters:Jt};return A!==`workspace`&&(b(H)===`directory`?e.directory={tree:H,path:V}:e.context=V),[{label:`scope`,spec:e}]},[Zt,V,H,A,On]),opts:(0,T.useMemo)(()=>({mode:`live`,debounceMs:150}),[]),enabled:Kn}),$n=Kn&&Yn,er=(0,T.useRef)(!1);(0,T.useEffect)(()=>{er.current=$n},[$n]);let tr=L.length===1?L[0].trim():``;(0,T.useEffect)(()=>{Yn&&Qn(tr?{text:tr}:null,{limit:I,offset:(P-1)*I}).catch(()=>{})},[Yn,tr,I,P,Qn]);let nr=(B??[]).join(`,`);(0,T.useEffect)(()=>{Yn&&Xn(`lens`,{ids:B??[]}).catch(()=>{})},[Yn,nr,Xn,B]);let rr=$n?qn:et,ir=$n?Jn:rt,ar=(0,T.useRef)(new Set);(0,T.useEffect)(()=>{ar.current=new Set(rr.map(e=>Number(e.id)))},[rr]);let or=R.geoSelection;(0,T.useEffect)(()=>{Ht(rr,C?.name??null)},[rr,C?.name,Ht]),(0,T.useEffect)(()=>()=>Ht([]),[Ht]);let sr=(0,T.useMemo)(()=>or?rr.filter(e=>Te(e,or,R.filters.geo.includeUnlocated)):rr,[rr,or,R.filters.geo.includeUnlocated]),cr=ue(V,kn,{treeName:H,treeType:b(H),scope:A,queries:L,anyOf:z,noneOf:Wt,filters:Jt,ids:B,layerId:W&&G?G:void 0}),lr=JSON.stringify([e,cr]),[ur,dr]=(0,T.useState)(``),[fr,pr]=(0,T.useState)(!1),mr=(0,T.useRef)(!1),hr=nt||fr||ur!==lr||$n||!!or,gr=(0,T.useRef)(0),_r=(0,T.useRef)(null);(0,T.useEffect)(()=>()=>{gr.current++,_r.current=null},[]);let vr=(0,T.useRef)(``),$=(0,T.useCallback)(async t=>{if(!e)return;if(Ee(H,V)){gr.current++,_r.current=null,vr.current=``,w([]),O(0),D(!1);return}if(er.current)return;let n=`${tn&&en?`${A}:unfiled`:A}:${On??``}`,r=(B?.length??0)>0,i=bt(e,H,V,P,I,L.join(`␟`),Zt,W&&G?G:``,n),a=r&&i===vr.current;vr.current=i;let o=bt(e,H,V,P,I,L.join(`␟`),Xt,W&&G?G:``,n),c=`${o}\0${k}`;if(t?.silent&&_r.current?.key===c){_r.current.refreshPending=!0;return}let l=++gr.current,u=t?.silent||r||k?void 0:vt.get(o);u&&(w(u.documents),O(u.totalCount),dr(lr),D(!1)),(t?.silent??(a||!!u))||D(!0);let d={key:c,refreshPending:!1};_r.current=d;try{let t;t=tn&&en?await _e(e,en.driver,en.address,{linked:!1,limit:I,offset:(P-1)*I}):W&&G&&A!==`workspace`?await se(e,H,G,{limit:I,page:P,queries:L,allOf:kn,anyOf:z,noneOf:Wt,filters:Jt,ids:B,sortBy:Yt.sortBy||void 0,order:Yt.order}):await pe(e,V,kn,{limit:I,page:P,treeName:H,treeType:H===`directory`||H===`backends`?`directory`:`context`,queries:L,anyOf:z,noneOf:Wt,filters:Jt,ids:B,sortBy:Yt.sortBy||void 0,order:Yt.order,scope:A,debug:k&&L.length>0,debugLimit:200});let n=t.payload||[],i=t.totalCount||t.count||0;if(!r&&!d.refreshPending&&vt.set(o,{documents:n,totalCount:i}),l!==gr.current)return;let s=t.debug,c=s?.imageDistances??s?.distances??null;lt(c?{query:L[L.length-1]??``,distances:c}:null),w(a?e=>e.length===n.length&&e.every((e,t)=>e.id===n[t].id)?e:n:n),O(i),dr(lr)}catch(e){if(l!==gr.current)return;let t=e instanceof Error?e.message:`Failed to fetch documents`;s({title:`Error`,description:t,variant:`destructive`}),w([]),O(0)}finally{_r.current===d&&(_r.current=null),l===gr.current&&D(!1),l===gr.current&&d.refreshPending&&$({silent:!0})}},[e,V,H,G,W,P,I,C?.status,L,Xt,A,tn,k,On]);(0,T.useEffect)(()=>{$()},[$]),(0,T.useEffect)(()=>{let t=t=>{let n=t.detail;!n||n.workspaceName!==e||(cn({treeName:n.treeName||`context`,path:Me(n.path||`/`)}),dn(`left`))};return window.addEventListener(`workspace:open-to-side`,t),()=>window.removeEventListener(`workspace:open-to-side`,t)},[e,H,V]),(0,T.useEffect)(()=>{let t=t=>{let n=t.detail;if(!(n?.workspaceName&&n.workspaceName!==e)&&(e&&St(e,n),ct(st(n),{tree:H,kind:b(H),path:V,wholeWorkspace:A===`workspace`}))){if(e&&j(e,H,V),er.current){Zn();return}$({silent:!0})}};return window.addEventListener(`workspace:documents:refresh`,t),()=>window.removeEventListener(`workspace:documents:refresh`,t)},[$,e,V,H,A,Zn]);let yr=C?.name,br=C?.id;(0,T.useEffect)(()=>{if(!e||!yr&&!br)return;let t=[yr,br].filter(Boolean).map(e=>`workspace:${e}`),n=()=>t.forEach(e=>m.emit(`subscribe`,{channel:e}));n();let r=m.on(`connect`,n),i=new Map,a=!1,o=()=>{ne(e).then(e=>{a||(i=it(e))}).catch(()=>{})};o();let s=null,c=0,l=!1,u=null,d=()=>{if(s=null,c=Date.now(),u){let{treeName:t,path:n}=u;u=null,window.dispatchEvent(new CustomEvent(`workspace:documents:refresh`,{detail:{workspaceName:e,treeName:t,path:n}}))}if(l){if(l=!1,er.current){Zn();return}$({silent:!0})}},f=t=>n=>{(t.startsWith(`tree.created`)||t.startsWith(`tree.renamed`))&&o();let r=at(t,n,i);xt(e,r);let a={tree:H,kind:b(H),path:V,wholeWorkspace:A===`workspace`},f=ln.current;f&&ct(r,{tree:f.treeName,kind:b(f.treeName),path:f.path})&&(u=f),ct(r,a,ar.current)&&(l=!0),!(!l&&!u)&&(s||=setTimeout(d,Math.max(200,c+1500-Date.now())))},p=[`document.inserted`,`document.inserted.batch`,`document.updated`,`document.removed`,`document.deleted`,`document.removed.batch`,`document.deleted.batch`,`document.linked`,`document.unlinked`,`document.linked.batch`,`document.unlinked.batch`,`tree.document.inserted`,`tree.document.inserted.batch`,`tree.document.removed`,`tree.document.removed.batch`,`tree.document.deleted`,`tree.document.deleted.batch`,`tree.layer.merged`,`tree.layer.subtracted`,`tree.created`,`tree.renamed`].map(e=>[e,f(e)]);return p.forEach(([e,t])=>m.on(e,t)),()=>{a=!0,s&&clearTimeout(s),r?.(),p.forEach(([e,t])=>m.off(e,t))}},[e,br,yr,H,V,A,$,Zn]);let xr=`${V}\0${H}\0${G??``}\0${A}`,[Sr,Cr]=(0,T.useState)(xr);Sr!==xr&&(Cr(xr),F(1),Rt(null));let wr=`${V}\0${H}\0${G??``}`,[Tr,Er]=(0,T.useState)(wr);Tr!==wr&&(Er(wr),ft(`path`));let Dr=(e,t)=>{let n=e===`/`?`canvas`:e.split(`/`).pop()||`canvas`;Dt(n),wt({parentPath:e,captureView:t})},Or=l.get(`createCanvas`)===`1`,[kr,Ar]=(0,T.useState)(!1);kr!==Or&&(Ar(Or),Or&&Dr(V,!1)),(0,T.useEffect)(()=>{if(!Or)return;let e=new URLSearchParams(n.search);e.delete(`createCanvas`);let t=e.toString();o(`${n.pathname}${t?`?${t}`:``}${n.hash}`,{replace:!0})},[Or,V]);let jr=(0,T.useCallback)(e=>{let t=new URLSearchParams(n.search);t.delete(`q`),t.delete(`search`);for(let n of e)t.append(`q`,n);let r=t.toString();o(`${n.pathname}${r?`?${r}`:``}${n.hash}`)},[n.pathname,n.search,n.hash,o]),Mr=JSON.stringify([l.has(`q`),...Le]),[Nr,Pr]=(0,T.useState)(Mr);Nr!==Mr&&(Pr(Mr),It(Le),F(1));let Fr=`${Mr}\0${Y??``}\0${Mn}\0${V}\0${Lt??``}`,[Ir,Lr]=(0,T.useState)(Fr);Ir!==Fr&&(Lr(Fr),l.has(`q`)||Le.length>0||Y!==`canvas`||Lt===V||(It(Mn?[Mn]:[]),F(1)));let Rr=(0,T.useCallback)(e=>{let t=e.trim();t&&(Rt(null),It(e=>{if(e.includes(t))return e;let n=[...e,t];return jr(n),F(1),n}))},[jr,Rt,It,F]),zr=(0,T.useCallback)(e=>{It(t=>{let n=e<0?[]:t.filter((t,n)=>n!==e);return n.length===0&&Rt(V),jr(n),F(1),n})},[jr,V,Rt,It,F]),Br=L.join(` `).trim(),Vr=!!R.activeContextType&&(R.isDirty||Br!==(Y===`canvas`?Mn:R.savedSearchQuery||``));!e&&K!==null&&sn(null),(0,T.useEffect)(()=>{let t=!1;if(!e)return;let n=0,r=!1,i=(i=!1)=>{let a=++n;i&&fe(e,H),te(e,H).then(i=>{!t&&a===n&&(r=!0,yn.current=`${e}/${H}`,sn(i))}).catch(()=>{!t&&a===n&&!r&&sn(null)})};i(!1);let a=t=>{let n=t.detail;n?.workspaceName&&n.workspaceName!==e||n?.treeName&&n.treeName!==H||i(!n?.cacheInvalidated)};window.addEventListener(`workspace:tree:refresh`,a);let o=S(e,br);return()=>{t=!0,o(),window.removeEventListener(`workspace:tree:refresh`,a)}},[e,H,br]),!(e&&Y===`canvas`&&!W)&&N!==null&&Pt(null),(0,T.useEffect)(()=>{let t=!1;if(!(!e||Y!==`canvas`||W))return oe(e,V,H).then(e=>{t||Pt(e)}).catch(()=>{t||Pt(null)}),()=>{t=!0}},[e,V,H,Y,W]);let Hr=async()=>{if(C){mt(!0);try{let t=await x(e||C.id);Ze(t),s({title:`Success`,description:`Workspace started successfully`}),window.dispatchEvent(new CustomEvent(`workspaces:refresh`))}catch(e){let t=e instanceof Error?e.message:`Failed to start workspace`;s({title:`Error`,description:t,variant:`destructive`})}finally{mt(!1)}}},Ur=async t=>{if(!C)return;let n=c({title:`Removing…`,description:`Document from "${V}"`});try{await _(e||C.id,[t],V,[],H,Zr,{trashIfOrphaned:!0}),j(e||C.id,H,V),w(e=>e.filter(e=>e.id!==t)),O(e=>Math.max(0,e-1)),n.done({title:`Success`,description:`Document removed from workspace path.`})}catch(e){n.fail({title:`Error`,description:e instanceof Error?e.message:`Failed to remove document`,variant:`destructive`})}},Wr=async t=>{if(!C)return;let n=c({title:`Deleting…`,description:`Document from "${V}"`});try{await ae(e||C.id,[t],V,[],H,Zr),j(e||C.id,H,V),w(e=>e.filter(e=>e.id!==t)),O(e=>Math.max(0,e-1)),n.done({title:`Success`,description:`Document deleted.`})}catch(e){n.fail({title:`Error`,description:e instanceof Error?e.message:`Failed to delete document`,variant:`destructive`})}},Gr=async t=>{if(!C)return;let n=c({title:`Removing…`,description:`${t.length} document(s) from "${V}"`});try{await _(e||C.id,t,V,[],H,Zr,{trashIfOrphaned:!0}),j(e||C.id,H,V),w(e=>e.filter(e=>!t.includes(e.id))),O(e=>Math.max(0,e-t.length)),n.done({title:`Success`,description:`${t.length} document(s) removed.`})}catch(e){n.fail({title:`Error`,description:e instanceof Error?e.message:`Failed to remove documents`,variant:`destructive`})}},Kr=async t=>{if(!C)return;let n=c({title:`Deleting…`,description:`${t.length} document(s)`});try{await ae(e||C.id,t,V,[],H,Zr),j(e||C.id,H,V),w(e=>e.filter(e=>!t.includes(e.id))),O(e=>Math.max(0,e-t.length)),n.done({title:`Success`,description:`${t.length} document(s) deleted.`})}catch(e){n.fail({title:`Error`,description:e instanceof Error?e.message:`Failed to delete documents`,variant:`destructive`})}},qr=async t=>{if(!C)return;let n=c({title:`Destroying…`,description:`Document and its backend copies`});try{let r=await re(e||C.id,[t]);if(r.failed?.length){n.fail({title:`Error`,description:r.failed[0].reason,variant:`destructive`});return}w(e=>e.filter(e=>e.id!==t)),O(e=>Math.max(0,e-1)),n.done({title:`Destroyed`,description:`Document removed from all backends.`})}catch(e){n.fail({title:`Error`,description:e instanceof Error?e.message:`Failed to destroy document`,variant:`destructive`})}},Jr=async t=>{if(!C)return;let n=c({title:`Destroying…`,description:`${t.length} document(s) and their backend copies`});try{let r=await re(e||C.id,t),i=new Set(r.successful?.filter(e=>e.docDeleted).map(e=>e.id)??[]);w(e=>e.filter(e=>!i.has(e.id))),O(e=>Math.max(0,e-i.size));let a=[r.successful?.length?`${r.successful.length} destroyed`:null,r.failed?.length?`${r.failed.length} failed`:null].filter(Boolean).join(`, `);r.failed?.length?n.fail({title:`Destroy incomplete`,description:a,variant:`destructive`}):n.done({title:`Destroyed`,description:a||`No documents destroyed`})}catch(e){n.fail({title:`Error`,description:e instanceof Error?e.message:`Failed to destroy documents`,variant:`destructive`})}},Yr=e=>{Ct({documentIds:e,operation:`copy`,sourcePath:V,sourceTreeName:H}),window.dispatchEvent(new CustomEvent(`documents:clipboard`,{detail:{documentIds:e,operation:`copy`}})),s({title:`Copied`,description:`${e.length} document(s) copied to clipboard`})},Xr=e=>{Ct({documentIds:e,operation:`cut`,sourcePath:V,sourceTreeName:H}),window.dispatchEvent(new CustomEvent(`documents:clipboard`,{detail:{documentIds:e,operation:`cut`}})),s({title:`Cut`,description:`${e.length} document(s) cut to clipboard`})},Zr=b(H),Qr=async(t,n,r={})=>{if(!e)return!1;let i=r.targetTreeName??H,a=r.targetTreeType??Zr,o=r.move??yt?.operation===`cut`,s=c({title:o?`Moving…`:`Pasting…`,description:`${n.length} document(s) → "${t}"`});try{let c=await ee(e,t,n,i,a);if(c){j(e,i,t);let a=r.sourceTreeName||yt?.sourceTreeName,c=r.sourcePath||yt?.sourcePath;if((r.move??yt?.operation===`cut`)&&c&&a){let t=b(a);await _(e,n,c,[],a,t),j(e,a,c),window.dispatchEvent(new CustomEvent(`workspace:documents:refresh`,{detail:{workspaceName:e,path:c,treeName:a}}))}s.done({title:`Success`,description:`${n.length} document(s) ${o?`moved`:`pasted`} to "${t}"`}),Ct(null),window.dispatchEvent(new CustomEvent(`documents:clipboard`,{detail:null}));let l=performance.now();await $(),console.info(`[paste] list refresh ${Math.round(performance.now()-l)} ms`),window.dispatchEvent(new CustomEvent(`workspace:documents:refresh`,{detail:{workspaceName:e,path:t,treeName:i}}))}else s.done();return c}catch(e){return s.fail({title:`Error`,description:e instanceof Error?e.message:`Failed to paste documents`,variant:`destructive`}),!1}},$r=async(t,n)=>{if(!e)return!1;try{let r=(await de(e,n,t,H,Zr)).length>0;return r&&(Se(e,H,n),s({title:`Success`,description:`Imported ${t.length} document(s) to "${n}"`})),r}catch(e){return s({title:`Error`,description:e instanceof Error?e.message:`Failed to import documents`,variant:`destructive`}),!1}},ei=async()=>{if(!C||ir===0||hr||mr.current||window.prompt(`Type PURGE to permanently delete all ${ir} matching documents across all pages.`)!==`PURGE`)return;mr.current=!0,pr(!0);let t=c({title:`Purging…`,description:`${ir} matching document(s)`});try{let n=await g(e||C.id,cr,ir);n.deleted===n.requested?t.done({title:`Success`,description:`${n.deleted} document(s) purged.`}):t.fail({title:`Purge incomplete`,description:`${n.deleted} of ${n.requested} document(s) purged. Refresh and review the remaining results before retrying.`})}catch(e){t.fail({title:`Error`,description:e instanceof Error?e.message:`Failed to purge documents`,variant:`destructive`})}finally{j(e||C.id,H,V),await $({silent:!0}),mr.current=!1,pr(!1)}},ti=()=>Dr(V,!0),ni=async()=>{if(!(!e||!M||!Et.trim())){kt(!0);try{let t=Et.trim(),n=M.parentPath,r=n===`/`?`/${t}`:`${n}/${t}`,i={...R.filters,features:{...R.filters.features,allOf:kn}};await ce(e,r,H,M.captureView?{metadata:{toolbox:i},querySpec:{features:i.features,filters:[...Oe(R.filters.timeline),...De(R.filters.geo)],query:Br||void 0,sort:R.filters.sort?.sortBy?R.filters.sort:null}}:{}),wt(null),fe(e,H);try{let t=await te(e,H,{force:!0});sn(t)}catch{}window.dispatchEvent(new CustomEvent(`workspace:tree:refresh`,{detail:{workspaceName:e}})),o(Ne(e,r,H))}catch(e){s({title:`Error`,description:e instanceof Error?e.message:`Failed to create canvas`,variant:`destructive`})}finally{kt(!1)}}},ri=async()=>{if(!(!e||Y!==`canvas`)){jt(!0);try{let t=N||await ge(e,V,H);Pt(t);let n=`${window.location.origin}${t.url}`;await navigator.clipboard?.writeText(n),s({title:`Public canvas link copied`,description:n})}catch(e){s({title:`Error`,description:e instanceof Error?e.message:`Failed to share canvas`,variant:`destructive`})}finally{jt(!1)}}},ii=async()=>{if(N){jt(!0);try{await v(N.code),Pt(null),window.dispatchEvent(new CustomEvent(`workspace:tree:refresh`,{detail:{workspaceName:e,treeName:H}})),s({title:`Canvas unshared`,description:`The public link no longer works.`})}catch(e){s({title:`Error`,description:e instanceof Error?e.message:`Failed to unshare canvas`,variant:`destructive`})}finally{jt(!1)}}},ai=async()=>{if(!e||Y!==`canvas`||V===`/`)return;let t=Nn?.label||V.split(`/`).pop()||`canvas`,n=N?` Its public link will stop working.`:``;if(window.confirm(`Delete canvas "${t}"? This cannot be undone.${n}`)){Nt(!0);try{if(N)await v(N.code),Pt(null);else if(J?.locked){s({title:`Canvas is locked`,description:`Unlock it before deleting.`,variant:`destructive`});return}await y(e,V,!1,H);let n=V.split(`/`).filter(Boolean);n.pop();let r=n.length?`/${n.join(`/`)}`:`/`;window.dispatchEvent(new CustomEvent(`workspace:tree:refresh`,{detail:{workspaceName:e,treeName:H}})),o(Ne(e,r,H)),s({title:`Canvas deleted`,description:`"${t}" was removed.`})}catch(e){s({title:`Error`,description:e instanceof Error?e.message:`Failed to delete canvas`,variant:`destructive`})}finally{Nt(!1)}}},oi=(0,T.useCallback)(async t=>{if(!e||!q)return;let n={treeName:H,path:V},r=un===`left`?n:q,i=un===`left`?q:n,a=un===`left`?fn:_n;if(a.length===0){s({title:`Nothing selected`,description:`Tick documents in the focused pane first.`});return}let o=b(i.treeName),l=c({title:t?`Moving…`:`Copying…`,description:`${a.length} document(s) → "${i.path}"`});try{if(!await ee(e,i.path,a,i.treeName,o)){l.done();return}if(j(e,i.treeName,i.path),t){let t=b(r.treeName);await _(e,a,r.path,[],r.treeName,t),j(e,r.treeName,r.path)}[r,i].forEach(t=>window.dispatchEvent(new CustomEvent(`workspace:documents:refresh`,{detail:{workspaceName:e,path:t.path,treeName:t.treeName}}))),l.done({title:t?`Moved`:`Copied`,description:`${a.length} document(s) → "${i.path}"`})}catch(e){l.fail({title:`Error`,description:e instanceof Error?e.message:`Transfer failed`,variant:`destructive`})}},[e,q,un,H,V,fn,_n,s,c]);if((0,T.useEffect)(()=>{if(!q)return;let e=e=>{if(e.key!==`F5`&&e.key!==`F6`)return;let t=e.target;t.tagName!==`INPUT`&&t.tagName!==`TEXTAREA`&&(e.preventDefault(),oi(e.key===`F6`))};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[q,oi]),Qe)return(0,E.jsx)(`div`,{className:`flex items-center justify-center h-full`,children:(0,E.jsxs)(`div`,{className:`text-center space-y-2`,children:[(0,E.jsx)(`div`,{className:`animate-spin rounded-full h-8 w-8 border-b-2 border-primary mx-auto`}),(0,E.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`Loading workspace...`})]})});if(!C)return(0,E.jsx)(`div`,{className:`flex items-center justify-center h-full text-muted-foreground`,children:`Workspace not found.`});let si=Y===`canvas`&&!W&&!!J,ci=!si&&!U&&xn?(0,E.jsx)(Ge,{views:En,activeId:Dn,onSelect:An,onSave:jn,accentColor:we(C.color),onOpenToSide:e=>{cn({treeName:H,path:V,viewId:e}),dn(`right`)}}):void 0,li=en||C.status!==`active`?(0,E.jsxs)(E.Fragment,{children:[en&&(0,E.jsx)(`button`,{type:`button`,onClick:()=>{nn(!tn),F(1)},"aria-pressed":tn,className:u(`min-h-10 rounded-md border px-2 text-xs`,tn&&`bg-warning/15 text-warning`),children:`Unfiled only`}),C.status!==`active`&&(0,E.jsx)(`button`,{type:`button`,onClick:Hr,disabled:pt,className:`min-h-10 rounded-md border px-2 text-xs`,children:pt?`Starting…`:`Start`})]}):void 0,ui=Ee(H,V)?V===`/Trash`?(0,E.jsx)(`div`,{className:`h-full overflow-auto p-4`,children:(0,E.jsx)(Je,{workspaceName:e||C.id})}):(0,E.jsx)(Ye,{workspace:e||C.id,path:V,onNavigate:t=>o(Ne(e,t,`backends`))},e):(0,E.jsx)(Ke,{navigationTabs:ci,navigationActions:li,onBack:gn,accentColor:we(C.color),urlType:W?b(H)===`directory`?`${H}-layer`:`context-layer`:Y===`canvas`?`canvas`:b(H)===`directory`?H:`context`,urlDisplay:Un,contextPath:V,treeName:H,workspaceId:e||C.id,workspaceLabel:C.label||C.name,workspaceIcon:C.icon,documentSchema:On,documents:sr,isLoading:nt,totalCount:ir,currentPage:P,pageSize:I,onPageChange:F,onPageSizeChange:e=>{Ft(e),F(1)},onRemoveDocument:V===`/`?void 0:Ur,onDeleteDocument:Wr,onDestroyDocument:qr,onRemoveDocuments:V===`/`?void 0:Gr,onDeleteDocuments:Kr,onDestroyDocuments:Jr,onCopyDocuments:Yr,onCutDocuments:Xr,onPasteDocuments:U?void 0:Qr,onImportDocuments:U?void 0:$r,onSelectionChange:pn,onBrowseTree:()=>hn(`workspaces`,`detail`,e??null),onBrowseWorkspaces:()=>mn(`workspaces`),onNavigatePath:t=>o(Ne(e,t,H)),folders:bn,onOpenFolder:t=>o(Ne(e,Me(t),H)),scope:A,onScopeChange:ft,pastedDocumentIds:yt?.documentIds,linkTree:K,onPurgeDocuments:U?void 0:ei,disablePurgeDocuments:hr,canvasInfo:Nn??void 0,isCanvasPinned:zn,onTogglePinCanvas:Q?Hn:void 0,onSaveAsCanvas:K&&Y!==`canvas`&&!W&&!U?ti:void 0,onShareCanvas:Y===`canvas`&&!W?ri:void 0,onUnshareCanvas:N?ii:void 0,onDeleteCanvas:Y===`canvas`&&!W?ai:void 0,isSharingCanvas:At,isDeletingCanvas:Mt,isCanvasShared:!!N,isCanvasLocked:!!J?.locked,backendSearchQueries:L,onBackendSearch:Rr,serverSort:R.filters.sort,onServerSortChange:Bt,onRemoveBackendQuery:zr,canSaveChanges:Vr,isSavingChanges:R.isSaving,onSaveChanges:zt,contentBanner:k&&ot?(0,E.jsx)(gt,{data:ot,className:`mb-3`}):null,children:si&&J?(0,E.jsx)(ye,{workspaceId:e||C.id,treeName:H,path:V,layerId:J.id,querySpec:J.querySpec,metadata:J.metadata,isLocked:!!J.locked,fetchDocuments:R.isDirty?Gn:void 0}):!U&&Z.kind===`columns`?(0,E.jsx)(Ue,{documents:sr,workspaceId:e||C.id,columns:Z.columns??[],onColumnsChange:e=>jn(En.map(t=>t.id===Z.id?{...t,columns:e}:t))}):!U&&Z.kind===`app`&&Z.app&&Z.app!==`notes`?(0,E.jsx)(qe,{app:Z.app,workspaceId:e||C.id,treeName:H,path:V}):null});return(0,E.jsxs)(Ie,{workspaceId:e||C.id,treeName:H,path:V,headerOnly:!0,className:`relative flex flex-col h-full min-h-0`,children:[(0,E.jsx)(tt,{workspaceId:C.id,workspaceName:C.label||C.name},C.id),Ee(H,V)&&(0,E.jsx)(be,{workspace:C.label||C.name,workspaceIcon:C.icon,tree:H,path:V,onBack:gn,onBrowseTree:()=>hn(`workspaces`,`detail`,e||C.id),onBrowseWorkspaces:()=>mn(`workspaces`),onNavigatePath:t=>o(Ne(e,t,H)),accentColor:we(C.color)}),M&&(0,E.jsx)(`div`,{className:`shrink-0 px-2 pt-2`,children:(0,E.jsx)(Re,{title:`New canvas`,onClose:()=>wt(null),children:(0,E.jsxs)(`form`,{onSubmit:e=>{e.preventDefault(),ni()},className:`space-y-4`,children:[(0,E.jsxs)(`div`,{className:`grid gap-4 md:grid-cols-2`,children:[(0,E.jsxs)(`div`,{children:[(0,E.jsx)(`label`,{htmlFor:`canvas-name`,className:`mb-1 block text-sm font-medium`,children:`Name`}),(0,E.jsx)(`input`,{id:`canvas-name`,className:`w-full rounded-md border bg-background px-3 py-2 text-sm focus:outline-none focus:ring-1 focus:ring-primary`,placeholder:`Canvas name…`,value:Et,onChange:e=>Dt(e.target.value),onKeyDown:e=>{e.key===`Escape`&&wt(null)},autoFocus:!0})]}),(0,E.jsxs)(`div`,{children:[(0,E.jsx)(`span`,{className:`mb-1 block text-sm font-medium`,children:`Parent path`}),(0,E.jsx)(`div`,{className:`flex h-10 items-center rounded-md bg-muted px-3 font-mono text-sm text-muted-foreground`,children:M.parentPath===`/`?`/`:M.parentPath})]})]}),(0,E.jsxs)(`label`,{className:`flex items-start gap-2 text-sm`,children:[(0,E.jsx)(`input`,{type:`checkbox`,className:`mt-0.5`,checked:M.captureView,onChange:e=>wt({...M,captureView:e.target.checked})}),(0,E.jsxs)(`span`,{children:[`Capture the current view`,(0,E.jsx)(`span`,{className:`block text-xs text-muted-foreground`,children:`Freezes the active filters, search and sort into the canvas.`})]})]}),(0,E.jsxs)(`div`,{className:`flex gap-2`,children:[(0,E.jsx)(d,{type:`submit`,disabled:!Et.trim()||Ot,children:Ot?`Creating…`:`Create canvas`}),(0,E.jsx)(d,{type:`button`,variant:`outline`,onClick:()=>wt(null),children:`Cancel`})]})]})})}),(0,E.jsxs)(`div`,{"data-canvas-panes":!0,className:`flex-1 min-h-0 flex gap-2`,children:[(0,E.jsx)(`div`,{"data-canvas-pane":!0,className:u(`flex-1 min-w-0 bg-background overflow-hidden`,q&&(un===`left`?`ring-2 ring-primary`:`ring-1 ring-primary/20`)),onMouseDown:e=>{e.target.closest(`button,input,textarea,select,a`)||dn(`left`)},children:ui}),q&&e&&(0,E.jsx)(Tt,{workspaceName:e,workspaceLabel:C.label||C.name,workspaceIcon:C.icon,pane:q,isFocused:un===`right`,clipboard:yt,setClipboard:Ct,onFocus:()=>dn(`right`),onSelectionChange:vn,onNavigate:e=>cn(t=>t&&{...t,path:e,viewId:void 0}),onClose:()=>{cn(null),dn(`left`),vn([])}})]})]})}function wt(e,t){if(!e||t===`/`)return e;let n=e;for(let e of t.split(`/`).filter(Boolean))if(n=n?.children?.find(t=>t.name===e)??null,!n)return null;return n}function Tt({workspaceName:e,workspaceLabel:t,workspaceIcon:n,pane:r,isFocused:i=!1,clipboard:a,setClipboard:o,onFocus:s,onSelectionChange:c,onNavigate:l,onClose:d}){let{openM1Drawer:f,openM2Drawer:p}=Pe(),{showToast:m,showProgress:g}=h(),[ne,v]=(0,T.useState)(null),[ie,y]=(0,T.useState)([]),[oe,se]=(0,T.useState)(!1),[ce,le]=(0,T.useState)(0),[ue,de]=(0,T.useState)(1),[me,he]=(0,T.useState)(50),x=b(r.treeName),ge=wt(ne,r.path),_e=ge?.type===`canvas`,ve=(0,T.useMemo)(()=>x===`directory`?_t(ne,r.path):[],[ne,r.path,x]),ye=r.viewId?We(ge?.metadata).find(e=>e.id===r.viewId)??null:null,be=`${e}://${r.path===`/`?``:r.path.replace(/^\//,``)}`,xe=ze(ye),S=(0,T.useCallback)(async()=>{if(Ee(r.treeName,r.path)){y([]),le(0),se(!1);return}let t=bt(e,r.treeName,r.path,ue,me,``,xe??``),n=vt.get(t);if(n){y(n.documents),le(n.totalCount);return}se(!0);try{let n=await pe(e,r.path,xe?[xe]:[],{limit:me,page:ue,treeName:r.treeName,treeType:x}),i=n.payload||[],a=n.totalCount||n.count||0;y(i),le(a),vt.set(t,{documents:i,totalCount:a})}catch(e){m({title:`Error`,description:e instanceof Error?e.message:`Failed to fetch side pane documents`,variant:`destructive`}),y([]),le(0)}finally{se(!1)}},[e,r.path,r.treeName,x,me,ue,m,xe]);(0,T.useEffect)(()=>{let t=!1,n=0,i=!1,a=(a=!1)=>{let o=++n;a&&fe(e,r.treeName),te(e,r.treeName).then(e=>{!t&&o===n&&(i=!0,v(e))}).catch(()=>{!t&&o===n&&!i&&v(null)})};a(!1);let o=t=>{let n=t.detail;n?.workspaceName&&n.workspaceName!==e||n?.treeName&&n.treeName!==r.treeName||a(!n?.cacheInvalidated)};return window.addEventListener(`workspace:tree:refresh`,o),()=>{t=!0,window.removeEventListener(`workspace:tree:refresh`,o)}},[e,r.treeName]),(0,T.useEffect)(()=>{S()},[S]),(0,T.useEffect)(()=>{let t=t=>{let n=t.detail;n?.workspaceName&&n.workspaceName!==e||(St(e,n),ct(st(n),{tree:r.treeName,kind:b(r.treeName),path:r.path})&&(j(e,r.treeName,r.path),S()))};return window.addEventListener(`workspace:documents:refresh`,t),()=>window.removeEventListener(`workspace:documents:refresh`,t)},[S,e,r.treeName,r.path]);let Se=(0,T.useCallback)(async(t,n,i={})=>{let s=i.targetTreeName??r.treeName,c=i.targetTreeType??x,l=i.move??a?.operation===`cut`,u=g({title:l?`Moving…`:`Pasting…`,description:`${n.length} document(s) → "${t}"`});try{let r=await ee(e,t,n,s,c);if(r){j(e,s,t);let r=i.sourcePath||a?.sourcePath,c=i.sourceTreeName||a?.sourceTreeName;if((i.move??a?.operation===`cut`)&&r&&c){let t=b(c);await _(e,n,r,[],c,t),j(e,c,r),window.dispatchEvent(new CustomEvent(`workspace:documents:refresh`,{detail:{workspaceName:e,path:r,treeName:c}}))}u.done({title:`Success`,description:`${n.length} document(s) ${l?`moved`:`pasted`} to "${t}"`}),o(null),await S(),window.dispatchEvent(new CustomEvent(`workspace:documents:refresh`,{detail:{workspaceName:e,path:t,treeName:s}}))}else u.done();return r}catch(e){return u.fail({title:`Error`,description:e instanceof Error?e.message:`Failed to paste documents`,variant:`destructive`}),!1}},[e,r.treeName,x,S,g,a,o]),Ce=(0,T.useCallback)(()=>{j(e,r.treeName,r.path),S()},[e,r.treeName,r.path,S]),we=(0,T.useCallback)(async t=>{let n=g({title:`Removing…`,description:`${t.length} document(s) from "${r.path}"`});try{await _(e,t,r.path,[],r.treeName,x),Ce(),n.done({title:`Removed`,description:`${t.length} document(s) removed from "${r.path}"`})}catch(e){n.fail({title:`Error`,description:e instanceof Error?e.message:`Failed to remove documents`,variant:`destructive`})}},[e,r.path,r.treeName,x,Ce,g]),Te=(0,T.useCallback)(async t=>{let n=g({title:`Deleting…`,description:`${t.length} document(s)`});try{await ae(e,t,r.path,[],r.treeName,x),Ce(),n.done({title:`Deleted`,description:`${t.length} document(s) deleted.`})}catch(e){n.fail({title:`Error`,description:e instanceof Error?e.message:`Failed to delete documents`,variant:`destructive`})}},[e,r.path,r.treeName,x,Ce,g]),De=(0,T.useCallback)(async t=>{let n=g({title:`Destroying…`,description:`${t.length} document(s) and their backend copies`});try{let r=await re(e,t);if(r.failed?.length&&!r.successful?.length){n.fail({title:`Error`,description:r.failed[0].reason,variant:`destructive`});return}Ce();let i=`${r.successful?.length??0} document(s) destroyed${r.failed?.length?` · ${r.failed.length} failed`:``}.`;r.failed?.length?n.fail({title:`Destroy incomplete`,description:i,variant:`destructive`}):n.done({title:`Destroyed`,description:i})}catch(e){n.fail({title:`Error`,description:e instanceof Error?e.message:`Failed to destroy documents`,variant:`destructive`})}},[e,Ce,g]);return(0,E.jsxs)(`div`,{className:u(`relative flex-1 min-w-0 rounded-(--sheet-radius) border bg-background overflow-hidden`,i?`ring-2 ring-primary`:`ring-1 ring-primary/20`),onMouseDown:e=>{e.target.closest(`button,input,textarea,select,a`)||s()},children:[d&&(0,E.jsx)(`button`,{type:`button`,onClick:d,className:`absolute right-2 top-2 z-10 px-2 py-1 text-xs rounded-md border bg-background/90 hover:bg-accent`,children:`Close`}),Ee(r.treeName,r.path)?r.path===`/Trash`?(0,E.jsx)(`div`,{className:`h-full overflow-auto p-4`,children:(0,E.jsx)(Je,{workspaceName:e})}):(0,E.jsx)(Ye,{workspace:e,path:r.path,onNavigate:l||(()=>{})}):(0,E.jsx)(Ke,{frameContent:!1,onBrowseWorkspaces:()=>f(`workspaces`),onBrowseTree:()=>p(`workspaces`,`detail`,e),urlType:_e?`canvas`:x===`directory`?r.treeName:`context`,urlDisplay:be,contextPath:r.path,treeName:r.treeName,workspaceId:e,workspaceLabel:t,workspaceIcon:n,documentSchema:xe,documents:ie,isLoading:oe,totalCount:ce,currentPage:ue,pageSize:me,onPageChange:de,onPageSizeChange:e=>{he(e),de(1)},onRemoveDocument:r.path===`/`?void 0:e=>we([e]),onRemoveDocuments:r.path===`/`?void 0:we,onDeleteDocument:e=>Te([e]),onDeleteDocuments:Te,onDestroyDocument:e=>De([e]),onDestroyDocuments:De,onCopyDocuments:e=>{o({documentIds:e,operation:`copy`,sourcePath:r.path,sourceTreeName:r.treeName}),window.dispatchEvent(new CustomEvent(`documents:clipboard`,{detail:{documentIds:e,operation:`copy`}}))},onCutDocuments:e=>{o({documentIds:e,operation:`cut`,sourcePath:r.path,sourceTreeName:r.treeName}),window.dispatchEvent(new CustomEvent(`documents:clipboard`,{detail:{documentIds:e,operation:`cut`}}))},onPasteDocuments:r.treeName===`backends`?void 0:Se,onSelectionChange:c,pastedDocumentIds:a?.documentIds,linkTree:ne,folders:ve,onOpenFolder:l,onNavigatePath:l,canvasInfo:_e?{label:ge?.label,description:ge?.description,color:ge?.color}:void 0,children:ye?.kind===`columns`?(0,E.jsx)(Ue,{documents:ie,workspaceId:e,columns:ye.columns??[],onColumnsChange:()=>{},readOnly:!0}):ye?.kind===`app`&&ye.app&&ye.app!==`notes`?(0,E.jsx)(qe,{app:ye.app,workspaceId:e,treeName:r.treeName,path:r.path}):null})]})}export{Ct as default};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{o as e}from"./rolldown-runtime-C0FnF6B9.js";import{l as t,u as n}from"./code-editor-BOIngd5F.js";import{g as r}from"./chunk-62JRHF6Z-vspAGgtK.js";import{Ft as i,I as a,Nt as o,Xr as s,nn as c,rt as l,xr as u}from"./ui-Byg1cZDr.js";import{t as d}from"./button-SgR3GVvV.js";import{t as f}from"./input-BOtCd4HP.js";import{n as p}from"./use-toast-BlLDqSUO.js";import{t as m}from"./color-DFEH4BfK.js";import{$ as h,Dt as g,I as _,et as v,q as y}from"./index-CyEIU2rL.js";import{n as b}from"./page-header-DkOHw0g-.js";import{n as ee,r as x,t as te}from"./useAgentModels-PQVPjrQu.js";import{t as ne}from"./form-panel-C34lByEH.js";import{t as re}from"./use-create-panel-DhSNIGtr.js";import{n as ie,t as ae}from"./useSocketSubscription-ifW-vnlb.js";var S=e(n(),1),C=t();function w({agent:e,onStart:t,onStop:n,onEnter:r}){let[o,f]=(0,S.useState)(!1),p=async()=>{f(!0);try{await t(e.name)}finally{f(!1)}},m=async()=>{f(!0);try{await n(e.name)}finally{f(!1)}},h=()=>{switch(e.status){case`active`:return(0,C.jsx)(u,{className:`h-4 w-4 text-success`});case`inactive`:return(0,C.jsx)(u,{className:`h-4 w-4 text-warning`});case`error`:return(0,C.jsx)(u,{className:`h-4 w-4 text-destructive`});default:return(0,C.jsx)(u,{className:`h-4 w-4 text-muted-foreground`})}},g=()=>{switch(e.llmProvider){case`anthropic`:return(0,C.jsx)(s,{className:`h-4 w-4 text-warning`});case`openai`:return(0,C.jsx)(s,{className:`h-4 w-4 text-success`});case`ollama`:return(0,C.jsx)(a,{className:`h-4 w-4 text-info`});default:return(0,C.jsx)(s,{className:`h-4 w-4 text-muted-foreground`})}},_=()=>{switch(e.status){case`active`:return`text-success bg-success-subtle border-success`;case`inactive`:return`text-warning bg-warning-subtle border-warning`;case`error`:return`text-destructive bg-destructive-subtle border-destructive`;case`available`:return`text-info bg-info-subtle border-info`;default:return`text-foreground bg-muted border-border`}},v=e.status===`available`||e.status===`inactive`,y=e.status===`active`;return(0,C.jsxs)(`div`,{className:`border rounded-lg p-4 space-y-4 hover:shadow-elevation-2 transition-shadow bg-card`,children:[(0,C.jsxs)(`div`,{className:`flex items-start justify-between`,children:[(0,C.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,C.jsxs)(`div`,{className:`flex items-center gap-2 mb-1`,children:[g(),(0,C.jsx)(`h3`,{className:`text-lg font-semibold truncate`,children:e.label||e.name}),e.color&&(0,C.jsx)(`div`,{className:`w-4 h-4 rounded border flex-shrink-0`,style:{backgroundColor:e.color},title:`Color: ${e.color}`})]}),(0,C.jsx)(`p`,{className:`text-sm text-muted-foreground font-mono`,children:e.name}),e.description&&(0,C.jsx)(`p`,{className:`text-sm text-muted-foreground mt-1 line-clamp-2`,children:e.description})]}),(0,C.jsxs)(`div`,{className:`flex items-center gap-2 flex-shrink-0`,children:[h(),(0,C.jsx)(`span`,{className:`px-2 py-1 rounded-full text-xs font-medium border ${_()}`,children:e.status})]})]}),(0,C.jsxs)(`div`,{className:`grid grid-cols-2 gap-4 text-sm`,children:[(0,C.jsxs)(`div`,{children:[(0,C.jsx)(`span`,{className:`text-muted-foreground`,children:`Provider:`}),(0,C.jsx)(`div`,{className:`font-medium capitalize`,children:e.llmProvider})]}),(0,C.jsxs)(`div`,{children:[(0,C.jsx)(`span`,{className:`text-muted-foreground`,children:`Model:`}),(0,C.jsx)(`div`,{className:`font-mono text-xs`,children:e.model})]}),(0,C.jsxs)(`div`,{children:[(0,C.jsx)(`span`,{className:`text-muted-foreground`,children:`Created:`}),(0,C.jsx)(`div`,{children:new Date(e.createdAt).toLocaleDateString()})]}),(0,C.jsxs)(`div`,{children:[(0,C.jsx)(`span`,{className:`text-muted-foreground`,children:`Last Access:`}),(0,C.jsx)(`div`,{children:e.lastAccessed?new Date(e.lastAccessed).toLocaleDateString():`Never`})]})]}),e.config.mcp?.servers&&e.config.mcp.servers.length>0&&(0,C.jsxs)(`div`,{className:`text-sm`,children:[(0,C.jsx)(`span`,{className:`text-muted-foreground`,children:`MCP Servers:`}),(0,C.jsx)(`div`,{className:`flex flex-wrap gap-1 mt-1`,children:e.config.mcp.servers.map((e,t)=>(0,C.jsx)(`span`,{className:`px-2 py-1 bg-secondary text-secondary-foreground rounded text-xs`,children:e.name},t))})]}),(0,C.jsxs)(`div`,{className:`flex gap-2 pt-2 border-t`,children:[v&&(0,C.jsxs)(d,{onClick:p,disabled:o,size:`sm`,variant:`outline`,className:`flex-1`,children:[(0,C.jsx)(i,{className:`mr-2 h-4 w-4`}),`Start`]}),y&&(0,C.jsxs)(d,{onClick:m,disabled:o,size:`sm`,variant:`outline`,className:`flex-1`,children:[(0,C.jsx)(l,{className:`mr-2 h-4 w-4`}),`Stop`]}),(0,C.jsxs)(d,{onClick:()=>r(e.name),size:`sm`,className:`flex-1`,children:[(0,C.jsx)(c,{className:`mr-2 h-4 w-4`}),`Chat`]})]})]})}function T(){let e={anthropic:`https://api.anthropic.com`,openai:`https://api.openai.com/v1`,ollama:`http://localhost:11434/v1`},t={anthropic:`claude-3-5-sonnet-20241022`,openai:`gpt-4o`,ollama:`qwen2.5-coder:latest`},[n,i]=(0,S.useState)([]),[a,s]=(0,S.useState)(!0),[c,l]=(0,S.useState)(null),[u,T]=(0,S.useState)(``),[E,D]=(0,S.useState)(``),[O,k]=(0,S.useState)(m()),[A,j]=(0,S.useState)(``),[M,oe]=(0,S.useState)(`anthropic`),[N,P]=(0,S.useState)(t.anthropic),[F,I]=(0,S.useState)({apiKey:``,baseUrl:e.anthropic,maxTokens:4096,temperature:.7,topP:1,frequencyPenalty:0,presencePenalty:0,numCtx:4096}),L=te(M,F.apiKey,F.baseUrl),R=L.models.find(e=>e.id===N),[z,B]=(0,S.useState)(``),[V,H]=(0,S.useState)(``),[U,W]=(0,S.useState)(``),[G,K]=(0,S.useState)(``),[q,J]=(0,S.useState)(!1),Y=g(),[X,Z]=re(),{showToast:Q}=p(),se=r(),$=ie();ae($,`agent`,{"agent:status:changed":e=>{i(t=>t.map(t=>t.id===e.agentId?{...t,status:e.status,isActive:e.isActive}:t))},"agent:created":e=>{i(t=>[...t,e.agent])},"agent:deleted":e=>{i(t=>t.filter(t=>t.id!==e.agentId))}});let ce=n=>{oe(n),P(t[n]),I({apiKey:``,baseUrl:e[n],maxTokens:4096,temperature:.7,topP:1,frequencyPenalty:0,presencePenalty:0,numCtx:4096})};(0,S.useEffect)(()=>((async()=>{try{s(!0);let e=await y();i(e),l(null)}catch(e){console.error(`Agent fetch error:`,e);let t=`Failed to fetch agents`;if(e instanceof Error)t=e.message;else if(typeof e==`object`&&e){let n=e;t=n.message||n.error||n.payload?.message||n.payload?.error||n.statusText||`Failed to fetch agents`}l(t),Q({title:`Error`,description:t,variant:`destructive`})}finally{s(!1)}})(),()=>{}),[$,Q]);let le=async t=>{if(t.preventDefault(),u.trim()){J(!0);try{let t=G.trim()||x(z,V,U),n={name:u,label:A||u,description:E||void 0,color:O,llmProvider:M,model:N,apiKey:F.apiKey.trim()||void 0,baseUrl:F.baseUrl.trim()||void 0,config:{type:M,model:N,identity:{role:z.trim()||void 0,identity:V.trim()||void 0,instructions:U.trim()||void 0},prompts:t?{system:t}:void 0,connectors:{[M]:{maxTokens:F.maxTokens,...M===`anthropic`?{}:{temperature:F.temperature},topP:F.topP,frequencyPenalty:F.frequencyPenalty,presencePenalty:F.presencePenalty,...M===`ollama`?{numCtx:F.numCtx}:{}}}},mcp:{enabled:!0,servers:[{name:`weather`,command:`node`,args:[`src/managers/agent/mcp-servers/weather.js`]}]}},r=await _(n);i(e=>[...e,r]),T(``),D(``),k(m()),j(``),K(``),B(``),H(``),W(``),I({apiKey:``,baseUrl:e[M],maxTokens:4096,temperature:.7,topP:1,frequencyPenalty:0,presencePenalty:0,numCtx:4096}),Q({title:`Success`,description:`Agent '${r.label||r.name}' created.`}),Z(!1)}catch(e){console.error(`Agent creation error:`,e);let t=`Failed to create agent`;if(e instanceof Error)t=e.message;else if(typeof e==`object`&&e){let n=e;t=n.message||n.error||n.payload?.message||n.payload?.error||n.statusText||`Failed to create agent`}Q({title:`Error`,description:t,variant:`destructive`})}finally{J(!1)}}},ue=async e=>{try{let t=await h(e);i(e=>e.map(e=>e.name===t.name?t:e)),Q({title:`Success`,description:`Agent '${t.label||t.name}' started.`})}catch(e){console.error(`Agent start error:`,e);let t=`Failed to start agent`;if(e instanceof Error)t=e.message;else if(typeof e==`object`&&e){let n=e;t=n.message||n.error||n.payload?.message||n.payload?.error||n.statusText||`Failed to start agent`}Q({title:`Error`,description:t,variant:`destructive`})}},de=async e=>{try{await v(e),i(t=>t.map(t=>t.name===e?{...t,status:`inactive`,isActive:!1}:t)),Q({title:`Success`,description:`Agent '${e}' stopped.`})}catch(e){console.error(`Agent stop error:`,e);let t=`Failed to stop agent`;if(e instanceof Error)t=e.message;else if(typeof e==`object`&&e){let n=e;t=n.message||n.error||n.payload?.message||n.payload?.error||n.statusText||`Failed to stop agent`}Q({title:`Error`,description:t,variant:`destructive`})}},fe=e=>{se(`/agents/${e}`)};return(0,C.jsxs)(`div`,{className:`space-y-6`,children:[(0,C.jsx)(b,{title:`AI Agents`,description:`Create and manage your AI agents with multiple LLM providers`,actions:!Y.local&&!X&&(0,C.jsxs)(d,{onClick:()=>Z(!0),className:`max-sm:h-9 max-sm:w-9 max-sm:p-0`,"aria-label":`Create agent`,title:`Create agent`,children:[(0,C.jsx)(o,{className:`h-4 w-4 sm:mr-2`}),(0,C.jsx)(`span`,{className:`max-sm:hidden`,children:`Create Agent`})]})}),!Y.local&&X&&(0,C.jsx)(ne,{title:`Create New Agent`,onClose:()=>Z(!1),children:(0,C.jsxs)(`form`,{onSubmit:le,className:`space-y-4`,children:[(0,C.jsxs)(`div`,{className:`grid gap-4 md:grid-cols-2`,children:[(0,C.jsx)(f,{value:u,onChange:e=>T(e.target.value),placeholder:`Agent Name (e.g., 'my-assistant')`,disabled:q}),(0,C.jsx)(f,{value:A,onChange:e=>j(e.target.value),placeholder:`Agent Label (display name, optional)`,disabled:q})]}),(0,C.jsx)(f,{value:E,onChange:e=>D(e.target.value),placeholder:`Description (optional)`,disabled:q}),(0,C.jsxs)(`div`,{className:`grid gap-4 md:grid-cols-2`,children:[(0,C.jsxs)(`div`,{children:[(0,C.jsx)(`label`,{htmlFor:`agent-provider`,className:`text-sm font-medium`,children:`LLM Provider`}),(0,C.jsxs)(`select`,{id:`agent-provider`,value:M,onChange:e=>ce(e.target.value),className:`w-full mt-1 px-3 py-2 border border-input bg-background rounded-md text-sm focus:outline-none focus:ring-2 focus:ring-ring`,disabled:q,children:[(0,C.jsx)(`option`,{value:`anthropic`,children:`Anthropic Claude`}),(0,C.jsx)(`option`,{value:`openai`,children:`OpenAI GPT`}),(0,C.jsx)(`option`,{value:`ollama`,children:`Ollama (Local)`})]})]}),(0,C.jsxs)(`div`,{children:[(0,C.jsx)(`label`,{htmlFor:`agent-model`,className:`text-sm font-medium`,children:`Model`}),(0,C.jsx)(ee,{id:`agent-model`,value:N,onChange:(e,t)=>{P(e),t?.maxTokens&&I(e=>({...e,maxTokens:t.maxTokens}))},...L,disabled:q})]})]}),(0,C.jsxs)(`div`,{className:`space-y-4`,children:[(0,C.jsx)(`h3`,{className:`text-lg font-medium`,children:`Persona`}),(0,C.jsxs)(`div`,{children:[(0,C.jsx)(`label`,{htmlFor:`agent-role`,className:`text-sm font-medium`,children:`Role`}),(0,C.jsx)(f,{id:`agent-role`,value:z,onChange:e=>B(e.target.value),placeholder:`e.g. Software Engineer`,disabled:q})]}),(0,C.jsxs)(`div`,{children:[(0,C.jsx)(`label`,{htmlFor:`agent-identity`,className:`text-sm font-medium`,children:`Identity`}),(0,C.jsx)(`textarea`,{id:`agent-identity`,value:V,onChange:e=>H(e.target.value),placeholder:`Who this agent is…`,disabled:q,className:`w-full mt-1 px-3 py-2 border border-input bg-background rounded-md text-sm min-h-[80px] resize-y`})]}),(0,C.jsxs)(`div`,{children:[(0,C.jsx)(`label`,{htmlFor:`agent-instructions`,className:`text-sm font-medium`,children:`Instructions`}),(0,C.jsx)(`textarea`,{id:`agent-instructions`,value:U,onChange:e=>W(e.target.value),placeholder:`Behavioral instructions…`,disabled:q,className:`w-full mt-1 px-3 py-2 border border-input bg-background rounded-md text-sm min-h-[80px] resize-y`})]})]}),(0,C.jsxs)(`div`,{children:[(0,C.jsx)(`label`,{htmlFor:`system-prompt`,className:`text-sm font-medium`,children:`System Prompt (Optional Override)`}),(0,C.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`Built from Role, Identity and Instructions unless you enter an override.`}),(0,C.jsx)(`textarea`,{id:`system-prompt`,value:G,onChange:e=>K(e.target.value),placeholder:x(z,V,U)||`System prompt sent to the LLM…`,className:`w-full mt-1 px-3 py-2 border border-input bg-background rounded-md text-sm focus:outline-none focus:ring-2 focus:ring-ring min-h-[80px] resize-y`,disabled:q})]}),(0,C.jsxs)(`div`,{className:`grid gap-4 md:grid-cols-2`,children:[(0,C.jsxs)(`div`,{children:[(0,C.jsx)(`label`,{htmlFor:`api-key`,className:`text-sm font-medium`,children:`API Key (Optional)`}),(0,C.jsx)(f,{id:`api-key`,type:`password`,value:F.apiKey,onChange:e=>I(t=>({...t,apiKey:e.target.value})),placeholder:`Enter your API key`,disabled:q})]}),(0,C.jsxs)(`div`,{children:[(0,C.jsx)(`label`,{htmlFor:`baseUrl`,className:`text-sm font-medium`,children:`Base URL (Optional)`}),(0,C.jsx)(f,{id:`baseUrl`,value:F.baseUrl,onChange:e=>I(t=>({...t,baseUrl:e.target.value})),placeholder:e[M],disabled:q})]})]}),(0,C.jsxs)(`div`,{className:`space-y-4`,children:[(0,C.jsx)(`h3`,{className:`text-lg font-medium`,children:`LLM Parameters`}),(0,C.jsxs)(`div`,{className:`grid gap-4 md:grid-cols-2 lg:grid-cols-4`,children:[(0,C.jsxs)(`div`,{children:[(0,C.jsx)(`label`,{htmlFor:`max-tokens`,className:`text-sm font-medium`,children:`Max Output Tokens`}),(0,C.jsx)(f,{id:`max-tokens`,type:`number`,min:`1`,max:R?.maxTokens,value:F.maxTokens,onChange:e=>I(t=>({...t,maxTokens:parseInt(e.target.value)||4096})),disabled:q})]}),M!==`anthropic`&&(0,C.jsxs)(`div`,{children:[(0,C.jsx)(`label`,{htmlFor:`temperature`,className:`text-sm font-medium`,children:`Temperature`}),(0,C.jsx)(f,{id:`temperature`,type:`number`,min:`0`,max:`2`,step:`0.1`,value:F.temperature,onChange:e=>I(t=>({...t,temperature:Number.isNaN(e.target.valueAsNumber)?.7:e.target.valueAsNumber})),disabled:q})]}),(0,C.jsxs)(`div`,{children:[(0,C.jsx)(`label`,{htmlFor:`top-p`,className:`text-sm font-medium`,children:`Top P`}),(0,C.jsx)(f,{id:`top-p`,type:`number`,min:`0`,max:`1`,step:`0.1`,value:F.topP,onChange:e=>I(t=>({...t,topP:Number.isNaN(e.target.valueAsNumber)?1:e.target.valueAsNumber})),disabled:q})]}),M===`ollama`&&(0,C.jsxs)(`div`,{children:[(0,C.jsx)(`label`,{htmlFor:`num-ctx`,className:`text-sm font-medium`,children:`Context Length`}),(0,C.jsx)(f,{id:`num-ctx`,type:`number`,min:`1024`,max:R?.contextWindow,value:F.numCtx,onChange:e=>I(t=>({...t,numCtx:parseInt(e.target.value)||4096})),disabled:q})]})]}),M!==`ollama`&&(0,C.jsxs)(`div`,{className:`grid gap-4 md:grid-cols-2`,children:[(0,C.jsxs)(`div`,{children:[(0,C.jsx)(`label`,{htmlFor:`frequency-penalty`,className:`text-sm font-medium`,children:`Frequency Penalty`}),(0,C.jsx)(f,{id:`frequency-penalty`,type:`number`,min:`-2`,max:`2`,step:`0.1`,value:F.frequencyPenalty,onChange:e=>I(t=>({...t,frequencyPenalty:parseFloat(e.target.value)||0})),disabled:q})]}),(0,C.jsxs)(`div`,{children:[(0,C.jsx)(`label`,{htmlFor:`presence-penalty`,className:`text-sm font-medium`,children:`Presence Penalty`}),(0,C.jsx)(f,{id:`presence-penalty`,type:`number`,min:`-2`,max:`2`,step:`0.1`,value:F.presencePenalty,onChange:e=>I(t=>({...t,presencePenalty:parseFloat(e.target.value)||0})),disabled:q})]})]})]}),(0,C.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,C.jsx)(`label`,{htmlFor:`agent-color`,className:`text-sm font-medium`,children:`Agent Color`}),(0,C.jsx)(f,{id:`agent-color`,type:`color`,value:O,onChange:e=>k(e.target.value),className:`h-10 w-16 p-1`,disabled:q}),(0,C.jsx)(d,{type:`button`,variant:`outline`,size:`sm`,onClick:()=>k(m()),disabled:q,children:`Randomize`})]}),(0,C.jsxs)(d,{type:`submit`,disabled:q||!u.trim(),children:[(0,C.jsx)(o,{className:`mr-2 h-4 w-4`}),`Create Agent`]})]})}),(0,C.jsxs)(`div`,{className:`space-y-4`,children:[(0,C.jsx)(`h2`,{className:`text-xl font-semibold`,children:`Your Agents`}),a&&(0,C.jsx)(`p`,{className:`text-center text-muted-foreground`,children:`Loading agents...`}),c&&(0,C.jsx)(`div`,{className:`text-center text-destructive`,children:(0,C.jsx)(`p`,{children:c})}),!a&&!c&&n.length===0&&(0,C.jsx)(`p`,{className:`text-center text-muted-foreground`,children:`No agents found`}),n.length>0&&(0,C.jsx)(`div`,{className:`grid gap-4`,children:n.map(e=>(0,C.jsx)(w,{agent:e,onStart:ue,onStop:de,onEnter:fe},e.id))})]})]})}export{T as default};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{o as e}from"./rolldown-runtime-C0FnF6B9.js";import{l as t,u as n}from"./code-editor-BOIngd5F.js";import{_ as r,r as i,v as a}from"./chunk-62JRHF6Z-vspAGgtK.js";import{t as o}from"./utils-2pl1SbIp.js";import{Pt as s}from"./workspace-CrSpR4xf.js";import{p as c}from"./context-DQoZFMDQ.js";import{t as l}from"./registry-ZMLdscra.js";import{t as u}from"./applet-target-C_gBgU-Z.js";var d=e(n(),1),f=t(),p=`universe`;function m(){let{appletId:e}=r(),[t,n]=a(),m=l.find(t=>t.id===e),h=t.get(`context`),g=t.get(`workspace`)||p,_=t.get(`path`)||`/`,v=t.get(`tree`)||`context`,y=t.get(`add`)===`1`,b=(0,d.useMemo)(()=>h?{mode:`context`,contextId:h}:{mode:`workspace`,workspaceName:g,path:_,treeName:v,treeType:v===`directory`?`directory`:`context`},[h,g,_,v]),[x,S]=(0,d.useState)([]),[C,w]=(0,d.useState)([]);(0,d.useEffect)(()=>{s().then(S).catch(()=>S([])),c().then(w).catch(()=>w([]))},[]);let[T,E]=(0,d.useState)(_),[D,O]=(0,d.useState)(_);D!==_&&(O(_),E(_));let k=e=>{let r=new URLSearchParams(t);r.delete(`add`);for(let[t,n]of Object.entries(e))n===null?r.delete(t):r.set(t,n);n(r,{replace:!0})};if(!m)return(0,f.jsxs)(`div`,{className:`flex h-full min-h-0 flex-col items-center justify-center gap-3 surface-desk`,children:[(0,f.jsxs)(`p`,{className:`text-sm text-muted-foreground`,children:[`Unknown app`,e?` "${e}"`:``,`.`]}),(0,f.jsx)(`div`,{className:`flex gap-2`,children:l.map(e=>(0,f.jsx)(i,{to:`/apps/${e.id}`,className:`rounded-md border border-border px-3 py-1.5 text-sm hover:bg-muted`,children:e.label},e.id))})]});let A=h?`context`:`path`;return(0,f.jsxs)(`div`,{className:`flex h-full min-h-0 flex-col surface-desk p-shell gap-shell`,children:[(0,f.jsxs)(`div`,{className:`flex shrink-0 flex-wrap items-center gap-2 rounded-xl border bg-card px-3 py-2 shadow-elevation-2`,children:[(0,f.jsx)(m.icon,{className:`h-4 w-4 text-muted-foreground`}),(0,f.jsx)(`span`,{className:`text-sm font-semibold`,children:m.label}),(0,f.jsx)(`div`,{className:`ml-2 flex overflow-hidden rounded-md border border-border`,children:[`path`,`context`].map(e=>(0,f.jsx)(`button`,{type:`button`,onClick:()=>{e!==A&&k(e===`path`?{context:null}:{context:C[0]?.id??``,workspace:null,path:null,tree:null})},className:o(`px-2.5 py-1 text-xs capitalize transition-colors`,A===e?`bg-foreground text-background`:`text-muted-foreground hover:bg-muted hover:text-foreground`),children:e},e))}),A===`path`?(0,f.jsxs)(f.Fragment,{children:[(0,f.jsxs)(`select`,{value:g,onChange:e=>k({workspace:e.target.value,path:`/`}),className:`h-7 rounded-md border border-input bg-transparent px-1.5 text-xs`,"aria-label":`Workspace`,children:[!x.some(e=>e.name===g)&&(0,f.jsx)(`option`,{value:g,children:g}),x.map(e=>(0,f.jsx)(`option`,{value:e.name,children:e.label||e.name},e.id))]}),(0,f.jsx)(`input`,{value:T,onChange:e=>E(e.target.value),onBlur:()=>{let e=T.trim()||`/`;e!==_&&k({path:e})},onKeyDown:e=>{e.key===`Enter`&&e.target.blur()},spellCheck:!1,placeholder:`/`,className:`h-7 w-40 rounded-md border border-input bg-transparent px-2 text-xs outline-none focus-visible:ring-1 focus-visible:ring-ring`,"aria-label":`Path`})]}):(0,f.jsxs)(`select`,{value:h??``,onChange:e=>k({context:e.target.value}),className:`h-7 max-w-56 rounded-md border border-input bg-transparent px-1.5 text-xs`,"aria-label":`Context`,children:[!h&&(0,f.jsx)(`option`,{value:``,children:`Pick a context…`}),C.map(e=>(0,f.jsxs)(`option`,{value:e.id,children:[e.id,e.url?` (${e.url})`:``]},e.id))]}),(0,f.jsx)(`div`,{className:`grow`})]}),(0,f.jsx)(`div`,{className:`flex min-h-0 flex-1 flex-col overflow-hidden rounded-xl border bg-card shadow-elevation-2`,children:A===`context`&&!h?(0,f.jsxs)(`div`,{className:`flex h-full items-center justify-center p-6 text-center text-sm text-muted-foreground`,children:[`Pick a context above to bind `,m.label,` to it.`]}):(0,f.jsx)(u,{target:b,children:(0,f.jsx)(m.Component,{autoAdd:y},JSON.stringify(b))})})]})}export{m as default};
|