@augmentd-labs/canvas-web 2.26.21 → 2.26.22
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/{DocumentBodyEditor-CE2S2X6g.js → DocumentBodyEditor-8DNmOBS0.js} +1 -1
- package/dist/assets/{DocumentIcon-BS10SIP6.js → DocumentIcon-x299QNu_.js} +1 -1
- package/dist/assets/{EditorOverlay-BUToR_av.js → EditorOverlay-Cv1MaTok.js} +1 -1
- package/dist/assets/{FileForm-BxTixeDm.js → FileForm-DhQhVnoi.js} +1 -1
- package/dist/assets/{FiltersApplet-DNYAQP5F.js → FiltersApplet-gbu4I1fK.js} +1 -1
- package/dist/assets/{HomeFab-CpTZdNyY.js → HomeFab-CXaEEzXy.js} +2 -2
- package/dist/assets/{IdentityFields-C2MPM-Ab.js → IdentityFields-OPEWPlZs.js} +1 -1
- package/dist/assets/{LensApplet-CRa1j2WP.js → LensApplet-FifF2RUs.js} +1 -1
- package/dist/assets/LinkToCard-nR7Lal_o.js +1 -0
- package/dist/assets/{MarkdownEditor-7OqSDr7E.js → MarkdownEditor-CNY-VmKb.js} +2 -2
- package/dist/assets/{MessageComposerDialog-DzLhkHyh.js → MessageComposerDialog-gbD0Gu_b.js} +1 -1
- package/dist/assets/{NextShell-D9gvlKY2.js → NextShell-BIYs9fCL.js} +1 -1
- package/dist/assets/{NotesApplet-CFK86JYj.js → NotesApplet-D94iQKg6.js} +1 -1
- package/dist/assets/ObjectPropertiesCard-ChvWbOpZ.js +8 -0
- package/dist/assets/{ObjectPropertiesCard-C3jt40tM.css → ObjectPropertiesCard-JArcZXXv.css} +1 -1
- package/dist/assets/{PathPickerField-cVs5sZuG.js → PathPickerField-DBe7jykL.js} +1 -1
- package/dist/assets/{PickDocumentsCard-BlicxMqC.js → PickDocumentsCard-Bo224P4q.js} +1 -1
- package/dist/assets/{SketchApplet-D8mkYmK9.js → SketchApplet-ADVOnSLI.js} +1 -1
- package/dist/assets/{SketchEditor-zMrm1npg.js → SketchEditor-CkgRysCG.js} +5 -5
- package/dist/assets/{TerminalApplet-BO2HRp0z.js → TerminalApplet-CkO4uaE3.js} +1 -1
- package/dist/assets/{TextDocumentEditor-7V4aFL8i.js → TextDocumentEditor-COvsHJXH.js} +1 -1
- package/dist/assets/{TodosApplet-swdaBT-2.js → TodosApplet-Bpf1OIH4.js} +1 -1
- package/dist/assets/{TodosWidget-BXF8fYer.js → TodosWidget-BIYqPXUp.js} +1 -1
- package/dist/assets/{UploadProgressList-B2xCVzFR.js → UploadProgressList-BXJr87lI.js} +1 -1
- package/dist/assets/{_agentId_-CHdTYJFu.js → _agentId_-wN8YJoTZ.js} +0 -0
- package/dist/assets/{_contextId_-m9zn5qav.js → _contextId_-CoJraYnP.js} +1 -1
- package/dist/assets/{_workspaceName_-D0z9E9Uy.js → _workspaceName_-CXuIfG46.js} +1 -1
- package/dist/assets/{about-pl0DXTEt.js → about-CT6Ghfkb.js} +1 -1
- package/dist/assets/{add-B30V-yHb.js → add-BzgCpo5S.js} +1 -1
- package/dist/assets/{agents-Bc7_wscP.js → agents-DIJpWCkc.js} +1 -1
- package/dist/assets/{agents-ClK3Y2x0.js → agents-DlLq0q2s.js} +1 -1
- package/dist/assets/{alert-dialog-DIA-tAP5.js → alert-dialog-izlVMXfa.js} +1 -1
- package/dist/assets/{api-tokens-O5iFESo0.js → api-tokens-DDH7LMJ7.js} +1 -1
- package/dist/assets/{appearance-DLo_2WH0.js → appearance-D1EpKWaK.js} +1 -1
- package/dist/assets/{applet-target-DnTa2VAT.js → applet-target-ChiiXVdC.js} +1 -1
- package/dist/assets/{apps-DzFFo5D0.js → apps-DX8oWukQ.js} +1 -1
- package/dist/assets/{auth-CUdpxbLV.js → auth-HZNJB4wv.js} +1 -1
- package/dist/assets/backend-sync-progress-BeI9mDEX.js +7 -0
- package/dist/assets/{button-Bv4zA1qr.js → button-SgR3GVvV.js} +1 -1
- package/dist/assets/content-app-view-DS6Nrz6M.js +1 -0
- package/dist/assets/{context-D_K4g9SQ.js → context-mfIOB8dN.js} +1 -1
- package/dist/assets/{contexts-CgydYDn-2.js → contexts-CRWqFXzJ2.js} +1 -1
- package/dist/assets/{contexts-B6d6Axza.js → contexts-Ef3fHwv6.js} +1 -1
- package/dist/assets/{date-time-picker-BZaA3M9_.js → date-time-picker-B6mkWt-g.js} +1 -1
- package/dist/assets/{devices-D3-_UWM0.js → devices-C3gLuNDv.js} +1 -1
- package/dist/assets/{document-BG_mODBn.js → document-CX543Kcz.js} +1 -1
- package/dist/assets/document-list-SsF3jmuq.js +2 -0
- package/dist/assets/{embedding-m8SZH4oN.js → embedding-BHnBCyUx.js} +1 -1
- package/dist/assets/{embedding-Cjrxh6MN.js → embedding-CEGjemkq.js} +1 -1
- package/dist/assets/{form-panel-Dz96K7Lv.js → form-panel-C34lByEH.js} +1 -1
- package/dist/assets/{home-C5IxNq_5.js → home-3vhobmCu.js} +1 -1
- package/dist/assets/index-CiBgHujl.js +16 -0
- package/dist/assets/{inferd-config-editor-DagMmwW4.js → inferd-config-editor-BHUUFArV.js} +1 -1
- package/dist/assets/{key-bindings-DomR6ZNC.js → key-bindings-BNeY-GEg.js} +1 -1
- package/dist/assets/{label-CNoJOoe0.js → label-Dn4gCMcc.js} +1 -1
- package/dist/assets/{lazy-editor-Cbva8Pe2.js → lazy-editor-BSRnneOo.js} +2 -2
- package/dist/assets/{logs-CdbfY8_H.js → logs-Czn2sPeP.js} +1 -1
- package/dist/assets/{offline-BjMpUv3N.js → offline-CsRyFUg7.js} +1 -1
- package/dist/assets/{page-header-GtTr9Ff_.js → page-header-DkOHw0g-.js} +1 -1
- package/dist/assets/{public-share-DT9Tgn_Y.js → public-share-DXxVwHKT.js} +1 -1
- package/dist/assets/{query-debug-tVbB_8Z6.js → query-debug-BUUG3jpK.js} +1 -1
- package/dist/assets/{registry-BgnkvPjl.js → registry-DTWAywyJ.js} +2 -2
- package/dist/assets/{remotes-DR_iJClb.js → remotes-CdEU1Y5l.js} +1 -1
- package/dist/assets/{roles-DERIgujv.js → roles-BYHLwWCD.js} +1 -1
- package/dist/assets/roles-BpVWTMmp.js +2 -0
- package/dist/assets/settings-DH3ZiQLR.js +14 -0
- package/dist/assets/{settings-DhoHM9AU.js → settings-DNhy58i9.js} +1 -1
- package/dist/assets/{settings-BXOyceZ3.js → settings-DjnFAqIe.js} +1 -1
- package/dist/assets/{settings-B4LC1yCH.js → settings-jWfP7CP8.js} +1 -1
- package/dist/assets/{share-target-CpjVaYVl.js → share-target-CgHlnZLH.js} +1 -1
- package/dist/assets/{shared-B824Ibpc.js → shared-BMoiShd9.js} +1 -1
- package/dist/assets/{shared-1dpCuibu.js → shared-D2uRUNdC.js} +1 -1
- package/dist/assets/sketch-lazy-pbG2cCpW.js +2 -0
- package/dist/assets/{subtree-transfer-dialog-B7s4r78T.js → subtree-transfer-dialog-ChBI5llU.js} +1 -1
- package/dist/assets/{text-documents-D_zDMyhB.js → text-documents-BvDFBVnC.js} +1 -1
- package/dist/assets/ui-Byg1cZDr.js +41 -0
- package/dist/assets/{use-applet-docs-Cry2SFsG.js → use-applet-docs-o5NAUFBk.js} +1 -1
- package/dist/assets/{use-applet-target-mkjQujx6.js → use-applet-target-cO-FiyPQ.js} +1 -1
- package/dist/assets/{use-canvas-pins-CZBfEB5E.js → use-canvas-pins-Bth_Q--t.js} +2 -2
- package/dist/assets/{use-menu-BVkqNEIx.js → use-menu-BiJ8N7sS.js} +1 -1
- package/dist/assets/use-settings-back-CQauYjQ4.js +1 -0
- package/dist/assets/{use-sortable-data-DYIDDI8c.js → use-sortable-data-BW_0sXBs.js} +1 -1
- package/dist/assets/{use-workspace-identity-BVpGHkZq.js → use-workspace-identity-mgaofjsD.js} +1 -1
- package/dist/assets/{useAddTarget-CVRPElxz.js → useAddTarget-DUjaZdBQ.js} +1 -1
- package/dist/assets/{useAgentModels-ndLotMWH.js → useAgentModels-Sa4N8WFd.js} +1 -1
- package/dist/assets/{useDocumentThumbnail-C_rq2rXs.js → useDocumentThumbnail-DYLCC63L.js} +1 -1
- package/dist/assets/{useEditNoteFields-Bigs9ZG8.js → useEditNoteFields-zHEWwDfB.js} +1 -1
- package/dist/assets/{users-C9N-O1QA.js → users-CKz9kOoR.js} +1 -1
- package/dist/assets/{workspace-CJ1PWQ29.js → workspace-DvxC7pw1.js} +1 -1
- package/dist/assets/{workspace-area-menu-Ba_9bGKs.js → workspace-area-menu-UamvRNfd.js} +1 -1
- package/dist/assets/{workspace-content-gate-D8bzGD9i.js → workspace-content-gate-Be4tLYiB.js} +1 -1
- package/dist/assets/{workspace-import-form-D5JA8gzx.js → workspace-import-form-BRwc_oVg.js} +1 -1
- package/dist/assets/{workspaces-Dx5_N57M.js → workspaces-Da_hUIj3.js} +1 -1
- package/dist/assets/{workspaces-BBgdfAM_.js → workspaces-gQY1mczH.js} +1 -1
- package/dist/index.html +36 -36
- package/dist/sw.js +1 -1
- package/package.json +2 -2
- package/dist/assets/LinkToCard-BZwwE-Dv.js +0 -1
- package/dist/assets/ObjectPropertiesCard-DDcRLpsW.js +0 -8
- package/dist/assets/backend-sync-progress-DWR42uQV.js +0 -7
- package/dist/assets/content-app-view-BUi8HG1r.js +0 -1
- package/dist/assets/document-list-BiogH4tf.js +0 -2
- package/dist/assets/index-DtZS4JJ4.js +0 -16
- package/dist/assets/roles-DswT1Lv0.js +0 -2
- package/dist/assets/settings-CUzf6xEQ.js +0 -14
- package/dist/assets/sketch-lazy-Q58-vPF-.js +0 -2
- package/dist/assets/ui-BSqPn1LJ.js +0 -41
- package/dist/assets/use-settings-back-Dk-DJEUO.js +0 -1
|
@@ -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-7V4aFL8i.js","assets/rolldown-runtime-C0FnF6B9.js","assets/code-editor-BOIngd5F.js","assets/ui-BSqPn1LJ.js","assets/react-BHzhHVTZ.js","assets/button-Bv4zA1qr.js","assets/utils-BxVxyehK.js","assets/utils-2pl1SbIp.js","assets/workspace-CJ1PWQ29.js","assets/input-BOtCd4HP.js","assets/api-CA6WiiYM.js","assets/alert-dialog-DIA-tAP5.js","assets/text-documents-D_zDMyhB.js","assets/public-share-DT9Tgn_Y.js","assets/blobs-WiXP9QRi.js","assets/useToastHelpers-CRrpIIdY.js","assets/use-toast-BlLDqSUO.js","assets/note-save-status-DPz4VzL6.js","assets/useEditNoteFields-Bigs9ZG8.js","assets/tags-YamdPoBK.js","assets/DocumentBodyEditor-CE2S2X6g.js","assets/lazy-editor-Cbva8Pe2.js","assets/EditorOverlay-BUToR_av.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{An as o,Bt as s,Cr as c,Dn as l,Dt as u,Er as d,Et as f,Ft as p,Gn as m,Hr as h,J as g,Jr as _,Kr as v,L as y,Lt as b,Mn as x,Mt as S,Qt as C,Rn as w,Rt as T,Tr as E,Un as D,Vn as O,X as k,Xr as A,an as j,ci as M,ct as ee,dn as N,er as P,fr as F,gr as I,hn as L,in as R,ir as te,mt as z,nt as B,on as V,qr as H,sr as ne,tr as U,ui as re,ur as ie,vr as W,yt as ae}from"./ui-BSqPn1LJ.js";import{t as G}from"./utils-2pl1SbIp.js";import{t as K}from"./button-Bv4zA1qr.js";import{t as oe}from"./input-BOtCd4HP.js";import{t as q}from"./label-CNoJOoe0.js";import{l as se}from"./api-CA6WiiYM.js";import{_ as J,g as ce,o as le,t as ue}from"./LinkToCard-BZwwE-Dv.js";import{At as de,Gn as fe,In as Y,J as pe,Jn as me,Kn as he,N as ge,O as _e,On as ve,P as ye,Pn as be,Rn as xe,Un as Se,Vn as Ce,X as we,Y as Te,Yt as Ee,_ as De,bt as Oe,c as ke,i as Ae,nt as je,qn as Me,s as Ne,u as Pe,vn as Fe,wn as Ie}from"./workspace-CJ1PWQ29.js";import{r as Le,t as Re}from"./use-mobile-Db-vWu9Y.js";import{a as ze,c as Be,i as Ve,n as He,o as Ue,r as We,s as Ge,t as Ke}from"./IdentityFields-C2MPM-Ab.js";import{i as qe,r as Je}from"./public-share-DT9Tgn_Y.js";import{a as Ye,i as Xe,n as Ze,o as Qe,r as $e,s as et,t as tt}from"./text-documents-D_zDMyhB.js";import{t as nt}from"./useDocumentThumbnail-C_rq2rXs.js";import{t as rt}from"./markdown-view-BBBZtNSR.js";import{n as it,t as at}from"./tags-YamdPoBK.js";import{n as ot,t as st}from"./relation-events-CKio19hE.js";import{a as ct,i as lt,r as ut,s as dt}from"./date-time-picker-BZaA3M9_.js";import{t as ft}from"./sanitize-DrVcFY1Q.js";import{t as pt}from"./useEscapeClose-DR_xKT_k.js";import{t as X}from"./useToastHelpers-CRrpIIdY.js";import"./layer-style-Byl5LNFR.js";import{t as mt}from"./DocumentIcon-BS10SIP6.js";import{r as ht,s as gt,t as _t}from"./MessageComposerDialog-DzLhkHyh.js";import{n as vt}from"./LinkToSidePanel-eCy3nW4R.js";import{t as yt}from"./note-save-status-DPz4VzL6.js";import{t as bt}from"./useEditNoteFields-Bigs9ZG8.js";import{t as xt}from"./DocumentBodyEditor-CE2S2X6g.js";import{n as St}from"./use-document-modal-PG8bQyIB.js";import{t as Ct}from"./sketch-lazy-Q58-vPF-.js";import{r as wt}from"./geo-CZfs0E-x.js";var Z=e(n(),1);function Tt(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 Et({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=ce(e),u=Tt(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 Dt=1,Ot=8,kt=320,At=28,jt=2.5,Mt={scale:1,x:0,y:0};function Nt({src:e,alt:t,className:n=``,onZoomChange:r}){let i=(0,Z.useRef)(null),a=(0,Z.useRef)(null),[o,s]=(0,Z.useState)(Mt),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(Mt)),(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(Ot,Math.max(Dt,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 jt;let n=Math.max(e.clientWidth/t.offsetWidth,e.clientHeight/t.offsetHeight),r=Math.max(t.naturalWidth/t.offsetWidth,t.naturalHeight/t.offsetHeight)||Ot;return Math.min(Ot,Math.max(jt,Math.min(Math.max(n,jt),r)))},[]),b=(0,Z.useCallback)((e,t)=>{o.scale>1.001?s(Mt):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<kt&&Math.hypot(e.clientX-n.x,e.clientY-n.y)<At){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<=Dt?s(Mt):v(Math.min(Ot,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<kt)&&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 Pt(){return!/android|iphone|ipad|mobile/i.test(navigator.userAgent)&&navigator.pdfViewerEnabled!==!1}var Ft=40,It=1600;function Lt({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,Ft),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,It*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>Ft})}})().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 `,Ft,` pages. Download the file for the full document.`]})]})}function Rt({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]),Pt()||!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)(Lt,{blob:e,filename:n})})}function zt({workspaceId:e,document:t}){let{download:n}=Je(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)(I,{className:`h-3.5 w-3.5`}),r?`Preparing…`:`Download`]})}var Bt=1600;function Vt({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 Ht({workspaceId:e,document:t,className:n=``}){let r=(0,Z.useContext)(Be),i=Re(),a=Le(`(pointer: coarse)`),{blobUrl:o,error:s,loading:c}=nt(e,t.id,Bt,{version:t.checksumArray?.[0]??null}),{fetchBlob:l}=Je(e),u=Y(t)||`document-${t.id}`,[d,f]=(0,Z.useState)(!1);return(0,Q.jsx)(Vt,{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)(Nt,{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)(I,{className:`h-3.5 w-3.5`}),d?`Preparing…`:`Download original`]})]})})}function Ut({workspaceId:e,document:t,className:n=``}){let{src:r,error:i,loading:a}=et(e,t.id);return(0,Q.jsx)(Vt,{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)(zt,{workspaceId:e,document:t})]})})}function Wt({workspaceId:e,document:t,className:n=``}){let{src:r,error:i,loading:a}=et(e,t.id),[o,s]=(0,Z.useState)(!1);return(0,Q.jsx)(Vt,{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)(zt,{workspaceId:e,document:t})]})})}function Gt({workspaceId:e,document:t,className:n=``}){let{blobUrl:r,blob:i,error:a,loading:o}=Qe(e,t.id,{typeHint:`application/pdf`}),s=Y(t)||`document-${t.id}`;return(0,Q.jsx)(Vt,{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)(Rt,{blob:i,blobUrl:r,filename:s,className:`min-h-0 flex-1`}),(0,Q.jsx)(`div`,{children:(0,Q.jsx)(zt,{workspaceId:e,document:t})})]})})}function Kt({workspaceId:e,document:t,className:n=``}){let{text:r,error:i,loading:a}=Qe(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 qt({workspaceId:e,document:t,className:n=``}){let r=t.schema===Se,{text:i,error:a,loading:o}=Qe(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)(rt,{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)(rt,{content:i,className:`markdown-doc px-4 py-3`})})}function Jt({document:e,className:t=``}){let n=String(e.data?.url??e.data?.uri??``),r=me(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 Yt({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(`${se}/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)(F,{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)(I,{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)(Rt,{blob:c,blobUrl:s,filename:d,className:`min-h-[300px] flex-1`})]})}function Xt(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 Zt(e){try{return new URL(e).hostname.replace(/^www\./,``)}catch{return e}}function Qt({document:e,className:t=``}){let n=e.data||{},r=String(n.url??n.uri??``),i=String(n.title??n.label??``)||Zt(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)(O,{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:Zt(r)}),(0,Q.jsx)(`div`,{className:`mt-1 truncate font-mono text-[11px] text-muted-foreground/70`,children:r})]}),(0,Q.jsx)(F,{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 $t(e){return e.data||{}}var en={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 tn(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 nn(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 rn(e,t,n){let r=n===`completed`,i={...t.data||{},status:n,completed:r};r?i.completedAt=new Date().toISOString():delete i.completedAt,await Ie(e,{id:t.id,schema:t.schema,schemaVersion:t.schemaVersion,data:i}),window.dispatchEvent(new CustomEvent(`workspace:documents:refresh`))}function an({document:e,workspaceId:t,className:n=``}){let r=$t(e),i=qe()!=null,[a,o]=(0,Z.useState)(!1),{replicating:s,label:c}=ve(e),l=r.status===`completed`,u=r.status??`pending`,d=tn(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 rn(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)(N,{className:`h-3 w-3 animate-spin`}):l&&(0,Q.jsx)(h,{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 ${en[u]}`,children:ut[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)(v,{className:`h-3 w-3`}),nn(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)(P,{className:`h-3 w-3`}),`P`,r.priority]})]}),r.description&&(0,Q.jsx)(rt,{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)(N,{className:`h-3 w-3 animate-spin`}),c]})]})]})})}function on(e,t){let{fetchBlob:n}=Je(e),r=qe(),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 sn(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=>sn(e)).filter(Boolean).join(`, `):``}function cn(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 ln(e,t,n){let r=0;ft.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=ft.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{ft.removeHook(`afterSanitizeAttributes`)}}function un(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 dn(e){return(0,Q.jsx)(fn,{...e},`${e.workspaceId}:${e.document.id}`)}function fn({workspaceId:e,document:t,className:n=``}){let{fetchBlob:r,download:i}=Je(e),a=t.data||{},s=Array.isArray(a.attachments)?a.attachments:[],{body:c,bodyHtml:l,loading:u,error:d}=on(e,t),[f,p]=(0,Z.useState)(null),[m,h]=(0,Z.useState)(!1),[g,_]=(0,Z.useState)(!1),[v,y]=(0,Z.useState)(0),[b,S]=(0,Z.useState)(null);(0,Z.useEffect)(()=>{if(!l||m)return;let e=!1,n=[],i=s.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 un(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}=ln(l,r,g);n.push(i),p(i),y(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,l,m,g]);let C=typeof a.date==`string`?new Date(a.date).toLocaleString():null,w=s.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:`}),` `,sn(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:`}),` `,sn(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})]})]}),l&&(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)(E,{className:`mr-1.5 h-3.5 w-3.5`}):(0,Q.jsx)(te,{className:`mr-1.5 h-3.5 w-3.5`}),m?`HTML`:`Plain text`]}),!m&&v>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)(x,{className:`mr-1.5 h-3.5 w-3.5`}):(0,Q.jsx)(o,{className:`mr-1.5 h-3.5 w-3.5`}),g?`Hide remote images`:`Show remote images (${v})`]})]})]})}),(b||d)&&(0,Q.jsx)(`p`,{className:`text-sm text-destructive`,children:b||d}),u?(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&&l?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:c||`(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)(te,{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:cn(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)(I,{className:`h-3 w-3`}),` Download`]})]},e.url||t))]})]})}function pn({attachment:e,workspaceId:t,document:n}){let{download:r}=Je(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}=Qe(t,n.id,{url:e.url,typeHint:i,enabled:!o&&!!e.url}),{src:u,error:d,loading:f}=et(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 mn(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)(pn,{...e,attachment:t},t.url||n))]})}var hn={email:V,phone:b,sms:C,chat:C,slack:C,matrix:C,web:O,url:O},gn={person:`Person`,organization:`Organization`,service:`Service`,bot:`Bot`},_n=e=>Array.isArray(e)?e:[];function vn(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 yn({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 bn({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)(B,{className:`h-3 w-3 shrink-0 fill-current text-data-5`,"aria-label":`Primary`})]})}function xn({document:e,className:t}){let n=e.data??{},r=_n(n.identifiers),i=_n(n.channels),a=_n(n.organizations),o=_n(n.links),s=_n(n.tags),c=String(n.displayName||``).trim(),l=Me(e.schema,Ce),u=String(n.primaryEmail||``).trim(),d=n.name&&typeof n.name==`object`?n.name:{},f=[d.prefix,d.given,d.middle,d.family,d.suffix].map(e=>String(e||``).trim()).filter(Boolean).join(` `),p=i.some(e=>e.kind===`email`&&e.value===u);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:c||`Identity ${e.id}`}),(0,Q.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2 text-xs text-muted-foreground`,children:[l&&(0,Q.jsx)(`span`,{className:`rounded-full bg-muted px-2 py-0.5`,children:gn[l]||l}),f&&f!==c&&(0,Q.jsx)(`span`,{children:f}),String(n.timezone||``)&&(0,Q.jsx)(`span`,{children:String(n.timezone)}),String(n.locale||``)&&(0,Q.jsx)(`span`,{children:String(n.locale)})]})]}),u&&!p&&(0,Q.jsx)(yn,{title:`Primary email`,count:1,children:(0,Q.jsx)(bn,{icon:V,primary:!0,children:(0,Q.jsx)(`a`,{href:`mailto:${u}`,className:`hover:underline`,children:u})})}),(0,Q.jsx)(yn,{title:`Channels`,count:i.length,children:i.map((e,t)=>{let n=String(e.kind||``).toLowerCase(),r=String(e.value||``),i=vn(n,r),a=hn[n]||C;return(0,Q.jsxs)(bn,{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)(yn,{title:`Identifiers`,count:r.length,children:r.map((e,t)=>(0,Q.jsxs)(bn,{icon:U,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)(yn,{title:`Organizations`,count:a.length,children:a.map((e,t)=>(0,Q.jsxs)(bn,{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)(yn,{title:`Links`,count:o.length,children:o.map((e,t)=>(0,Q.jsxs)(bn,{icon:L,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}`))}),s.length>0&&(0,Q.jsx)(`div`,{className:`flex flex-wrap gap-1.5`,children:s.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 Sn({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 Cn(e){let t=e.schema;if(t===`data/schema/note`)return qt;if(t===`data/schema/drawing`)return Ht;if(t===`data/schema/task`)return an;if(t===`data/schema/message/email`)return dn;if(t===`data/schema/message`)return mn;if(t===`data/schema/identity`||t.startsWith(`data/schema/identity/`))return xn;if(t===`data/schema/tab`||t===`data/schema/link`){let t=String(e.data?.url??e.data?.uri??``);return me(t)?Jt:Xt(t)?Yt:Qt}if(t!==`data/schema/file`)return null;let n=String(e.metadata?.contentType||``);switch(he(n,Y(e))){case`image`:return Ht;case`audio`:return Ut;case`video`:return Wt;case`pdf`:return Gt;case`markdown`:return qt;case`text`:return Kt;default:return Sn}}function wn({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)(ae,{size:17})}),r&&(0,Q.jsx)(Et,{workspaceId:r,inputRef:c,onChange:t})]})}function Tn({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)=>(0,Q.jsxs)(`span`,{className:`canvas-search-query`,children:[(0,Q.jsx)(ae,{size:12,"aria-hidden":`true`}),(0,Q.jsx)(`span`,{title:e,children:e}),t&&(0,Q.jsx)(`button`,{type:`button`,onClick:()=>t(n),"aria-label":`Remove search: ${e}`,children:(0,Q.jsx)(y,{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 En({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 Dn({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:_,onDraftChange:v,tabs:b,accentColor:x,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),M=JSON.stringify([e,n,i,a]),[N,P]=(0,Z.useState)(M);N!==M&&(P(M),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,M,o]);let F=()=>{j.current=!0,T(!1),v?.(``)},I=w?F:s??l,L=le(i,e).slice(1),R=(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${b?` has-tabs`:``}`,style:x?{borderTopColor:x}:void 0,children:[b&&(0,Q.jsx)(En,{accentColor:x,children:b}),(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)(re,{size:19})}),(0,Q.jsxs)(`div`,{className:`canvas-address-field`,onDoubleClick:e=>{_&&!e.target.closest(`button`)&&T(!0)},onKeyDown:e=>{e.key===`Escape`&&w&&(e.preventDefault(),e.stopPropagation(),F())},children:[w&&_?(0,Q.jsx)(wn,{inputRef:k,workspaceId:_.localOnly?void 0:_.workspaceId,onSearch:_.onSearch,onDraftChange:v,clearOnSubmit:!_.localOnly,showSubmitButton:!1,label:_.queries.length?`Refine search…`:`Search documents…`}):(0,Q.jsxs)(Q.Fragment,{children:[R((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&&_&&T(!0)},children:[n&&R(`[${n}]`,`canvas-address-tree`,l,`Browse tree: ${n}`),R(`:/`,`canvas-address-root`,u?()=>u(`/`):void 0,`Go to tree root`),L.map((e,t)=>(0,Q.jsxs)(`span`,{className:`canvas-address-segment`,children:[t>0&&(0,Q.jsx)(`span`,{"aria-hidden":`true`,children:`/`}),R(e.label,``,u?()=>u(e.path):void 0,e.path,!a&&t===L.length-1)]},e.path)),a&&(0,Q.jsxs)(`span`,{className:`canvas-address-segment`,children:[(0,Q.jsx)(`span`,{"aria-hidden":`true`,children:L.length?`/`:``}),R(a,``,d,a)]}),o&&R(`#${o}`,`canvas-address-section`,f,o,!0)]})]}),_&&(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)(ae,{size:17}),_.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)(ee,{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)(S,{size:21})}),C]}),w&&_&&(0,Q.jsxs)(`div`,{className:`canvas-search-dropdown`,children:[(0,Q.jsxs)(`div`,{className:`canvas-search-heading`,children:[(0,Q.jsx)(`span`,{children:_.localOnly?`Filter documents on this page`:v?`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:F,"aria-label":`Close search`,children:(0,Q.jsx)(y,{size:16})})]}),(0,Q.jsx)(Tn,{..._})]}),!w&&_&&_.queries.length>0&&(0,Q.jsx)(`div`,{className:`px-3 pb-2`,children:(0,Q.jsx)(Tn,{queries:_.queries,onRemoveQuery:_.onRemoveQuery})})]})}function On({workspaceId:e,document:t,className:n}){let r=Cn(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 kn({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 ht(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;ht(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(st,i),()=>{n=!1,window.removeEventListener(`workspace:documents:refresh`,i),window.removeEventListener(st,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=be(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?[be(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)(On,{workspaceId:e,document:r})]},r.id)}),c&&(0,Q.jsx)(_t,{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 An(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 jn=e(i(),1),Mn=[{mode:`copy`,label:`Copy to`,icon:(0,Q.jsx)(c,{className:`h-3.5 w-3.5`})},{mode:`move`,label:`Move to`,icon:(0,Q.jsx)(M,{className:`h-3.5 w-3.5`})},{mode:`delete`,label:`Delete from`,icon:(0,Q.jsx)(k,{className:`h-3.5 w-3.5`})}],Nn=[{value:`rename`,label:`Rename mine (file-1.ext)`},{value:`overwrite`,label:`Overwrite the existing file`},{value:`error`,label:`Skip the document`}],Pn=`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 Fn(e){return e.driver===`cacache`?W:e.config?.remote===!0?d:w}function In({workspaceId:e,documentCount:t,initialMode:n=`copy`,defaultFilename:r=``,onConfirm:i,onClose:a,saving:o=!1,sizeClassName:s,deleteFrom:l,progress:u,stopping:d=!1,onStop:f}){let{showErrorToast:p}=X(),[h,_]=(0,Z.useState)(!1);pt(a,!o&&!h);let[v,b]=(0,Z.useState)(n),[x,S]=(0,Z.useState)(null),[C,T]=(0,Z.useState)(null),[E,D]=(0,Z.useState)(()=>new Set(n===`delete`&&l?[l.backend]:[])),[O,A]=(0,Z.useState)(!1),[j,ee]=(0,Z.useState)(``),[N,P]=(0,Z.useState)(r),[F,I]=(0,Z.useState)(`rename`);(0,Z.useEffect)(()=>{let t=!1;return Oe(e).then(e=>{if(t)return;S(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));D(e=>new Set([...e].filter(e=>n.has(e))))}).catch(e=>{t||T(e instanceof Error?e.message:String(e))}),()=>{t=!0}},[e]);let L=v===`move`,R=e=>e.enabled===!1?`disabled`:e.config?.readOnly===!0?`read-only`:e.config?.supported===!1?`unsupported`:null,te=(0,Z.useMemo)(()=>(x||[]).filter(e=>!R(e)).map(e=>e.address),[x,v]),z=e=>{b(e),D(t=>{let n=(x||[]).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)})},B=e=>{D(t=>{if(L)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})},V=(0,Z.useMemo)(()=>(x||[]).filter(e=>E.has(e.address)&&ke(e)),[x,E]),H=v!==`delete`&&V.length>0,ne=e=>{let t=Ne(e,x||[]),n=t&&x?.find(e=>e.address===t.address);return!!n&&!R(n)&&v!==`delete`&&!o},U=async(t,n)=>{let r=Ne(t,x||[]);if(!r||!ne(t))throw Error(`Choose a writable file backend folder`);await Ae(e,r.driver,r.address,[[r.key,n].filter(Boolean).join(`/`)])},re=e=>{_(!1);let t=Pe(e[0]||``,x||[]),n=t?(x||[]).find(e=>e.address===t.address):null;if(!t||!n){p(`Pick a folder inside a storage backend`);return}if(R(n)){p(`${n.address} is ${R(n)}`);return}if(!ke(n)){p(`${n.address} does not keep folders — objects are stored by content`);return}ee(t.key),D(e=>L?new Set([t.address]):new Set([...e,t.address]))},ie=async()=>{E.size===0||o||await i([...E],v,{keepDocument:O,folder:H?j.trim():``,filename:H&&t===1?N.trim():``,onConflict:F})},W=t,ae=W===1?``:`s`,q=v===`delete`?`Delete ${W} document${ae} from…`:`${v===`move`?`Move`:`Copy`} ${W} document${ae} to…`,se=v===`delete`?`Delete from`:v===`move`?`Move to`:`Copy to`,ce=E.size===0?se.split(` `)[0]:`${se} ${E.size} backend${E.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)(w,{className:`h-4 w-4`}),q]}),(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)(y,{className:`h-4 w-4`})})]}),(0,Q.jsx)(`div`,{className:`flex shrink-0 items-center gap-1 border-b px-2 pt-2`,children:Mn.map(({mode:e,label:t,icon:n})=>(0,Q.jsxs)(`button`,{type:`button`,onClick:()=>z(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:[C&&(0,Q.jsx)(`p`,{className:`px-2 py-1.5 text-xs text-destructive`,children:C}),!x&&!C&&(0,Q.jsx)(`div`,{className:`px-2 py-3 text-xs text-muted-foreground`,children:`Loading backends…`}),x?.length===0&&(0,Q.jsx)(`p`,{className:`px-2 py-1.5 text-xs text-muted-foreground`,children:`No storage backends configured.`}),x?.map(e=>{let t=Fn(e),n=R(e),r=E.has(e.address),i=e.config?.remote===!0;return(0,Q.jsxs)(`div`,{onClick:()=>!n&&!o&&B(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:L?`radio`:`checkbox`,checked:r,disabled:!!n||o,onChange:()=>B(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:O,onChange:e=>A(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.`})]})]}),H&&(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 `,V.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)(oe,{id:`backend-transfer-folder`,value:j,onChange:e=>ee(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:()=>_(!0),disabled:o,"aria-label":`Browse backend folders`,title:`Browse…`,children:(0,Q.jsx)(m,{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)(oe,{id:`backend-transfer-filename`,value:N,onChange:e=>P(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:Pn,value:F,onChange:e=>I(e.target.value),disabled:o,children:Nn.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&&u&&(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:[d?`Stopping after current file`:`Processing`,` · `,u.completed,`/`,u.total]}),f&&(0,Q.jsx)(K,{size:`sm`,variant:`outline`,onClick:f,disabled:d,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:[E.size,` backend`,E.size===1?``:`s`,` selected`]}),(0,Q.jsx)(K,{size:`sm`,variant:v===`delete`?`destructive`:`default`,onClick:ie,disabled:E.size===0||o,children:o?(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(J,{className:`mr-1.5 h-3.5 w-3.5`}),`Working…`]}):(0,Q.jsxs)(Q.Fragment,{children:[v===`delete`?(0,Q.jsx)(k,{className:`mr-1 h-3.5 w-3.5`}):v===`move`?(0,Q.jsx)(M,{className:`mr-1 h-3.5 w-3.5`}):(0,Q.jsx)(c,{className:`mr-1 h-3.5 w-3.5`}),ce]})})]}),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)(g,{className:`mt-0.5 h-3.5 w-3.5 shrink-0 text-destructive`}),(0,Q.jsx)(`span`,{children:l&&E.has(l.backend)?`Deletes selected files in ${l.backend}/${l.folder}. Copies in other folders are kept.${E.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.`})]}),h&&(0,Q.jsx)(vt,{onClose:()=>_(!1),children:(0,Q.jsx)(ue,{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:ne,create:U},onConfirm:re,onClose:()=>_(!1)})})]})}var Ln={exif:`from the photo's EXIF`,device:`from the device at capture`,manual:`placed by hand`};function Rn(e){let t=`${e.lat.toFixed(5)}, ${e.lon.toFixed(5)}`,n=e.source?Ln[e.source]:null;return[t,e.accuracy==null?null:`±${e.accuracy} m`,n].filter(Boolean).join(` · `)}function zn({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)(j,{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?Rn(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)(R,{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)(k,{className:`h-3.5 w-3.5`})})]})]}),r&&(0,Q.jsx)(Ue,{initial:e,onPick:e=>t({lat:e.lat,lon:e.lon,source:`manual`}),onClose:()=>i(!1)})]})}function Bn(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 Vn(e){return Bn(e.schema)||Xe(e)}function Hn(e){return e===`data/schema/link`?{urlKey:`uri`,titleKey:`label`}:e===`data/schema/tab`?{urlKey:`url`,titleKey:`title`}:{urlKey:null,titleKey:`title`}}async function Un(e,t,n){try{let r=new Set(n.map(e=>e.identityId).filter(Boolean)),i=await we(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 Ee(e,t,`member-of`,n)}catch(e){console.error(`Failed to sync organization relations`,e)}}function Wn({document:e,workspaceId:t,onClose:n}){let{showSuccessToast:r,showErrorToast:i}=X(),a=Bn(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===Se,d=Xe(e),f=$e(e)??`markdown`,p=d&&Ye(e),m=e.schema===fe,h=e.schema===`data/schema/identity`||e.schema.startsWith(`data/schema/identity/`),{urlKey:g,titleKey:_}=Hn(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?ct(String(e.data.dueDate)):dt()),M=Ve(We(e)),[ee,N]=(0,Z.useState)(String(e.comment??``)),P=e.metadata?.geo??null,[F,I]=(0,Z.useState)(P),L=e.features??e.metadata?.features,[R,te]=(0,Z.useState)(at(L).length?at(L):e.data?.tags??[]),z=bt(e,t,u),{title:B,content:V,comment:H,tags:ne,geo:U,setTitle:re,setContent:ie,setComment:W,setTags:ae,setGeo:G}=u?z:{title:b,content:S,comment:ee,tags:R,geo:F,setTitle:x,setContent:C,setComment:N,setTags:te,setGeo:I},se=JSON.stringify(U??null)!==JSON.stringify(P??null),J=Qe(t,e.id,{mode:`text`,enabled:d&&!p,maxTextLength:Ze,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),ie(J.text));let[pe,me]=(0,Z.useState)([]),[he,ge]=(0,Z.useState)(!1),{replicating:_e,mirror:ye}=ve(e);(0,Z.useEffect)(()=>{let e=!1;return de(t).then(t=>{e||me(t)}).catch(()=>{}),()=>{e=!0}},[t]);let be=!g||(()=>{try{return new URL(v.trim()),!0}catch{return!1}})(),xe=!he&&l&&(d?!p&&J.text!=null&&!J.loading:a?h?M.displayName.trim().length>0&&M.emailValid:m?B.trim().length>0:u?z.canSave:be:!0),we=async()=>{ge(!0);let c=[...(L||[]).filter(e=>!e.startsWith(`tag/`)),...it(ne)];try{if(u){await z.save(),n();return}if(d){let i=await tt(t,e,V,{comment:H.trim(),metadata:{features:c,...o?{filename:s.trim()}:{},...se?{geo:U}:{}}});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:H.trim(),metadata:{features:c,...o?{filename:s.trim()}:{}}};if(h){let{type:t,...n}=e.data??{};i.schema=`${Ce}/${M.values.type}`,i.data={...n,...He(M.values)}}else if(m)i.data={...e.data,...lt({title:B,description:w,status:E,priority:O,due:A})};else if(a){let t=ne.map(e=>e.trim()).filter(Boolean),n;u?n={...B.trim()?{title:B.trim()}:{},content:V}:(n={...e.data},g&&(n[g]=v.trim()),B.trim()?n[_]=B.trim():delete n[_],n.tags=t),i.data=n}se&&(i.metadata={...i.metadata??{},geo:U}),await Ie(t,i),h&&(await Un(t,e.id,M.values.organizations),ot()),r(`Document updated`),window.dispatchEvent(new CustomEvent(`workspace:documents:refresh`)),n()}catch(e){i(e instanceof Error?e.message:`Failed to update document`)}finally{ge(!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)(oe,{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)(oe,{id:`edit-url`,value:v,onChange:e=>y(e.target.value),placeholder:`https://example.com`,className:`font-mono text-xs`}),v.trim()&&!be&&(0,Q.jsx)(`p`,{className:`text-xs text-destructive`,children:`Enter a valid URL, e.g. https://example.com`})]}),a&&h&&(0,Q.jsx)(Ke,{idPrefix:`edit-identity`,workspaceName:t,...M,emailValid:M.emailValid}),a&&m&&(0,Q.jsx)(ze,{idPrefix:`edit-todo`,title:B,setTitle:re,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)(oe,{id:`edit-title`,value:B,onChange:e=>re(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)(xt,{kind:u?`markdown`:f,value:V,onChange:ie,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)(Ge,{tags:ne,onChange:ae,suggestions:pe})]}),(0,Q.jsx)(zn,{value:U,onChange:G}),(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:H,onChange:e=>W(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)(yt,{...z,onRetry:z.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:he,children:u?`Close`:`Cancel`}),(0,Q.jsx)(K,{size:`sm`,onClick:we,disabled:!xe,children:he?_e?`Replicating to ${ye.label}…`:`Saving…`:`Save changes`})]})]})}var Gn=(0,Z.createContext)(null),Kn={entry:null,open:()=>{},close:()=>{}};function qn(){return(0,Z.useContext)(Gn)??Kn}var Jn=`main`,Yn=(0,Z.createContext)(null);function Xn(){return(0,Z.useContext)(Yn)}var Zn=50;function Qn({relation:e,workspaceId:t,direction:n,onRemove:r,removing:i}){let{open:a}=St(),o=qn(),s=Xn(),c=n===`out`?e.to:e.from,l=e.document??null,u=l?be(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 je(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)(M,{className:`h-3.5 w-3.5 shrink-0 text-muted-foreground`}):(0,Q.jsx)(re,{className:`h-3.5 w-3.5 shrink-0 text-muted-foreground`}),l?(0,Q.jsx)(mt,{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)(k,{className:`h-3.5 w-3.5`})})]})}function $n({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),y=(0,Z.useCallback)(()=>{v.current++},[]),b=(0,Z.useCallback)(async()=>{let n=++v.current;try{let r=await we(t,e.id,{offset:m*Zn,limit:Zn,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)/Zn)-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]),x=`${t}:${e.id}`,[C,w]=(0,Z.useState)(x);x!==C&&(w(x),a(null),s(null),h(0),_(1)),(0,Z.useEffect)(()=>{async function e(){await b()}return e(),window.addEventListener(st,e),()=>{y(),window.removeEventListener(st,e)}},[b,y]);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 Ee(t,e.id,i.p,o,a),n(`Relation removed`),ot()}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)(S,{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)(Qn,{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)(vt,{onClose:()=>{u||l(!1)},children:(0,Q.jsx)(ue,{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),ot()}catch(e){r(e instanceof Error?e.message:`Failed to create relation`)}finally{d(!1)}}})})]})}var er=(0,Z.lazy)(()=>a(()=>import(`./TextDocumentEditor-7V4aFL8i.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]))),tr={reply:`Reply`,replyAll:`Reply all`,forward:`Forward`},nr={reply:f,replyAll:u,forward:D};function rr({document:e,workspaceId:t,initialEdit:n=!1,onChanged:r}){let i=qe()!=null,{showErrorToast:a,showSuccessToast:o}=X(),[c,l]=(0,Z.useState)(!1),u=e.data?.url||e.data?.uri,d=e.schema!==`data/schema/file`&&typeof u==`string`&&/^https?:\/\//i.test(u),[f,p]=(0,Z.useState)(!1),m=[`data/schema/message`,`data/schema/message/email`].includes(e.schema),[h,g]=(0,Z.useState)(null),v=e.schema===`data/schema/message/email`,y=!i&&(v||[`slack`,`whatsapp`].includes(String(e.data?.platform))),b=v?[`reply`,`replyAll`,`forward`]:[`reply`],x=e=>g(t=>t===e?null:e),S=!i,[C,w]=(0,Z.useState)(n&&!i),E=e.schema===xe,[D,O]=(0,Z.useState)(!1),k=e.schema===`data/schema/note`||Xe(e),[A,j]=(0,Z.useState)(!1),M=`${t}:${e.id}:${n}:${i}`,[ee,N]=(0,Z.useState)(M);M!==ee&&(N(M),w(n&&!i),g(null),p(!1),O(!1),j(!1));let P=t=>{if(!S||!Vn(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 C&&S?(0,Q.jsx)(Wn,{document:e,workspaceId:t,onClose:e=>{w(!1),r?.(e)}}):(0,Q.jsxs)(`div`,{className:`flex h-full min-h-0 flex-col gap-3`,children:[S&&(0,Q.jsxs)(`div`,{className:`flex shrink-0 justify-end gap-2`,children:[m&&(0,Q.jsx)(K,{size:`sm`,variant:f?`secondary`:`outline`,onClick:()=>p(!f),children:f?`Show message`:`View thread`}),y&&b.map(e=>{let t=nr[e];return(0,Q.jsxs)(K,{size:`sm`,variant:h===e?`secondary`:`outline`,onClick:()=>x(e),children:[(0,Q.jsx)(t,{className:`mr-1.5 h-3.5 w-3.5`}),tr[e]]},e)}),d&&(0,Q.jsxs)(K,{variant:`outline`,size:`sm`,disabled:c,onClick:async()=>{l(!0);try{await ye(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{l(!1)}},children:[(0,Q.jsx)(I,{className:`mr-1 h-3 w-3`}),c?`Downloading…`:`Download to workspace`]}),e.schema===`data/schema/file`&&(0,Q.jsxs)(K,{variant:`outline`,size:`sm`,onClick:()=>ge(t,e.id,Y(e)||`document-${e.id}`).catch(e=>a(e instanceof Error?e.message:String(e))),children:[(0,Q.jsx)(I,{className:`mr-1 h-3 w-3`}),` Download`]}),E&&(0,Q.jsxs)(K,{variant:`outline`,size:`sm`,onClick:()=>O(!0),children:[(0,Q.jsx)(_,{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)(s,{className:`mr-1 h-3 w-3`}),` Open editor`]}),(0,Q.jsxs)(K,{variant:`outline`,size:`sm`,onClick:()=>w(!0),children:[(0,Q.jsx)(T,{className:`mr-1 h-3 w-3`}),` Edit`]})]}),D&&S&&(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)(Ct,{doc:e,workspaceName:t,onSaved:()=>{O(!1),r?.()},onClose:()=>O(!1),onDetails:()=>{O(!1),w(!0)}})}),A&&S&&(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)(er,{doc:e,workspaceName:t,onSaved:e=>{j(!1),r?.(e)},onClose:()=>j(!1),onDetails:()=>{j(!1),w(!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(),w(!0))},children:[f&&!i?(0,Q.jsx)(kn,{workspaceId:t,documentId:Number(e.id)},`${t}:${e.id}`):(0,Q.jsx)(On,{workspaceId:t,document:e}),h&&y&&(0,Q.jsx)(_t,{workspaceId:t,replyToDocumentId:Number(e.id),mode:h,originalSubject:v&&typeof e.data?.subject==`string`?e.data.subject:void 0,onClose:()=>g(null)},`${e.id}:${h}`)]}),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 ir=e=>e?new Date(e).toLocaleDateString(`en-US`,{year:`numeric`,month:`long`,day:`numeric`,hour:`2-digit`,minute:`2-digit`,second:`2-digit`}):`—`,ar=e=>!Number.isFinite(e)||!e?null:e>=1?`${e}s`:`1/${Math.round(1/e)}s`;function or({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`,ar(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`,ir(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 sr({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:ir(e.createdAt)})]}),(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`span`,{className:`font-medium`,children:`Updated:`}),(0,Q.jsx)(`span`,{className:`ml-2`,children:ir(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)(or,{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}=dr(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 cr({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)(c,{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 lr({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 Te(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)($n,{document:e,workspaceId:t})]}):(0,Q.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`Loading memberships...`})}function ur(e){return e===`stored`?W:e===`workspace-file`?w:e===`imap`?V:e===`readonly`?O:ne}function dr(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 fr({document:e,workspaceId:t,onChanged:n}){let{showSuccessToast:r,showErrorToast:i}=X(),[a,o]=(0,Z.useState)(null),[s,l]=(0,Z.useState)(null),[u,d]=(0,Z.useState)(null),[f,p]=(0,Z.useState)(null),[m,h]=(0,Z.useState)(null),[g,_]=(0,Z.useState)(!1),v=`${t}:${e.id}`,[y,b]=(0,Z.useState)(v);v!==y&&(b(v),o(null),l(null),p(null));let x=()=>{pe(t,e.id).then(o).catch(e=>l(e instanceof Error?e.message:String(e)))};(0,Z.useEffect)(()=>{let n=!1;return pe(t,e.id).then(e=>{n||o(e)}).catch(e=>{n||l(e instanceof Error?e.message:String(e))}),()=>{n=!0}},[v]);let S=async(a,o)=>{d(a),p(null);try{let i=await _e(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?.(),x()}catch(e){i(e instanceof Error?e.message:String(e))}finally{d(null)}},C=async(a,o,s)=>{_(!0);try{let i=await Fe(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(An(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`)),h(null),n?.(),x()}catch(e){i(e instanceof Error?e.message:String(e))}finally{_(!1)}},w=e=>{if((a?.length??0)<=1){p(e.url);return}window.confirm(`Remove this copy from the backend?\n\n${e.url}`)&&S(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 T=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`})]}),T?(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:()=>h(`copy`),title:`Copy the file data to another storage backend (keeps the existing copies)`,children:[(0,Q.jsx)(c,{className:`mr-1 h-3.5 w-3.5`}),` Copy to…`]}),(0,Q.jsxs)(K,{variant:`outline`,size:`sm`,onClick:()=>h(`move`),title:`Move the file data to another storage backend (source released once the copy is durable)`,children:[(0,Q.jsx)(M,{className:`mr-1 h-3.5 w-3.5`}),` Move to…`]})]}),a.map(n=>{let r=ur(n.kind),{backend:a,key:o}=dr(n.url),s=u===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:()=>ge(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)(I,{className:`h-3.5 w-3.5`})}),(0,Q.jsx)(`button`,{onClick:()=>w(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)(k,{className:`h-3.5 w-3.5`})})]})]}),f===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 S(n.url,!1),children:`Also remove index entry`}),(0,Q.jsx)(K,{variant:`outline`,size:`sm`,disabled:s,onClick:()=>void S(n.url,!0),children:`Keep index entry (no bytes)`}),(0,Q.jsx)(K,{variant:`ghost`,size:`sm`,onClick:()=>p(null),children:`Cancel`})]})]})]},n.url)}),m&&(0,jn.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)(In,{workspaceId:t,documentCount:1,initialMode:m,defaultFilename:E,saving:g,onConfirm:C,onClose:()=>{g||h(null)}})}),window.document.body)]})}var pr=(0,Z.lazy)(()=>a(()=>import(`./LocationTab-DAtqAQ3l.js`),__vite__mapDeps([25,3,4,26,27]))),mr=[{id:`view`,label:`View`,icon:ie},{id:`location`,label:`Location`,icon:j},{id:`metadata`,label:`Metadata`,icon:l},{id:`json`,label:`JSON`,icon:A},{id:`synapses`,label:`Synapses`,icon:z},{id:`backends`,label:`Backends`,icon:W}];function hr({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=qe()!=null,d=wt(e),f=mr.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)(gt,{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)(Dn,{...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)(rr,{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)(pr,{lat:d.lat,lon:d.lon})}),v===`metadata`&&(0,Q.jsx)(sr,{document:e,workspaceId:t}),v===`json`&&(0,Q.jsx)(cr,{document:e,workspaceId:t}),v===`synapses`&&!u&&(0,Q.jsx)(lr,{document:e,workspaceId:t}),v===`backends`&&!u&&(0,Q.jsx)(fr,{document:e,workspaceId:t,onChanged:i})]})})]})}export{$t as _,Gn as a,Et as b,In as c,En as d,Cn as f,rn as g,tn as h,Xn as i,An as l,nn as m,Yn as n,qn as o,en as p,Jn as r,zn as s,hr as t,Dn as u,Ht as v,Nt as y};
|
|
@@ -1,7 +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{An as r,Ct as i,Gn as a,L as o,Mr as s,Mt as c,Q as l,Qr as u,Rn as d,Rt as f,Vr as ee,X as p,Xr as m,Y as h,Z as te,ci as ne,dn as g,gr as _,ni as re,on as v,qn as ie,st as ae}from"./ui-BSqPn1LJ.js";import{t as y}from"./utils-2pl1SbIp.js";import{t as b}from"./button-Bv4zA1qr.js";import{t as x}from"./input-BOtCd4HP.js";import{c as oe,t as S}from"./api-CA6WiiYM.js";import{t as C}from"./socket-CtH3EU9m.js";import{n as se}from"./use-toast-BlLDqSUO.js";import{t as ce}from"./LinkToCard-BZwwE-Dv.js";import{W as le,bt as ue,gn as de,gt as fe,hn as w}from"./workspace-CJ1PWQ29.js";import{i as pe}from"./MessageComposerDialog-DzLhkHyh.js";import{n as me}from"./LinkToSidePanel-eCy3nW4R.js";import{t as he}from"./PathPickerField-cVs5sZuG.js";var T=e(n(),1);function E(e){return`/workspaces/${e}/hooks`}async function D(e){return await S.get(E(e))||[]}async function O(e,t){return(await S.get(`${E(e)}/${t}`))?.content??``}async function k(e,t,n){await S.put(`${E(e)}/${t}`,{content:n})}async function A(e,t){await S.delete(`${E(e)}/${t}`)}var ge=[`example-`,`disabled-`,`_`];function j(e){let t=e.lastIndexOf(`/`);return{dir:t===-1?``:e.slice(0,t+1),base:t===-1?e:e.slice(t+1)}}function M(e){return ge.find(t=>e.startsWith(t))??null}function _e(e){return M(j(e).base)===null}function ve(e){return j(e).base.startsWith(`example-`)}function ye(e){let{dir:t,base:n}=j(e),r=M(n);return t+(r?n.slice(r.length):`disabled-${n}`)}async function be(e,t,n){if(_e(t)===n)return t;let r=ye(t);return await k(e,r,await O(e,t)),await A(e,t),r}function xe(e){let t={};for(let n of e){let e;e=n.path.includes(`/`)?n.path.split(`/`)[0]:/^(?:example-|disabled-|_)?rules\.json$/.test(n.path)?`rules`:n.path.replace(/\.js$/,``),(t[e]||=[]).push(n)}return t}function Se(e){let t=e.when?.event;return Array.isArray(t)?t.map(String):t?[String(t)]:[]}function Ce(e){let t=e.when?.eventPathExact??e.when?.pathExact??e.when?.path;return Array.isArray(t)?t.map(String):typeof t==`string`?[t]:[]}function we(e){let t=String(e||``).split(`/`).filter(Boolean);return t[0]===`workspace`&&t.length>=2?{backend:`workspace:${t[1]}`,rel:t.slice(2).join(`/`)}:t[0]===`device`?t.length>=3?{backend:t[2],rel:t.slice(3).join(`/`)}:null:t.length>=2?{backend:t[1],rel:t.slice(2).join(`/`)}:null}function Te(e){let t=new URLSearchParams;return e.kind&&e.kind!==`mirror`&&t.set(`addRuleKind`,e.kind),e.path&&t.set(`addRulePath`,e.path),e.target&&t.set(`addRuleTarget`,e.target),e.storeTo&&t.set(`addRuleStoreTo`,e.storeTo),e.storeFolder&&t.set(`addRuleStoreFolder`,e.storeFolder),t}function Ee(e){return String(e||``).replace(/^[a-z]+:/i,``).split(`/`).filter(Boolean).join(`/`)}var N=`rules.json`;async function De(e){try{let t=await O(e,N),n=JSON.parse(t||`{}`);return Array.isArray(n.rules)?n.rules:[]}catch{return[]}}async function Oe(e,t){await k(e,N,JSON.stringify({$schema:`canvas.hook-rules/v1`,rules:t},null,2)+`
|
|
2
|
-
`)}async function ke(e,t={}){let n=new URLSearchParams;t.status&&n.set(`status`,t.status),t.handler&&n.set(`handler`,t.handler),t.limit&&n.set(`limit`,String(t.limit));let r=n.toString();return await S.get(`${E(e)}/pending${r?`?${r}`:``}`)||[]}async function Ae(e,t){return await S.post(`${E(e)}/pending/decisions`,t)}async function je(e,t){return await S.get(`${E(e)}/runs/${encodeURIComponent(t)}`)}async function Me(e,t={}){let n=new URLSearchParams;t.limit&&n.set(`limit`,String(t.limit)),t.handler&&n.set(`handler`,t.handler),t.event&&n.set(`event`,t.event),t.failed&&n.set(`failed`,`true`);let r=n.toString();return await S.get(`${E(e)}/runs${r?`?${r}`:``}`)||[]}var P=1e4,Ne=`canvas.hooks.backfillLimit`;function Pe(e){let t=Math.floor(Number(e));return!Number.isFinite(t)||t<1?500:Math.min(t,P)}function Fe(){try{let e=localStorage.getItem(Ne);return e?Pe(e):500}catch{return 500}}function Ie(e){let t=Pe(e);try{localStorage.setItem(Ne,String(t))}catch{}return t}function Le(e){if(e.includes(`/`)){let t=e.split(`/`)[0];return t===`lib`||t===`rules`?null:t}return e.endsWith(`.js`)?e.replace(/\.js$/,``).replace(/^(?:example-|disabled-|_)/,``):null}async function Re(e,t){return await S.post(`${E(e)}/backfill`,t)}function ze(e,t){return S.post(`${E(e)}/backfill/jobs`,t)}function F(e,t){return S.get(`${E(e)}/backfill/jobs/${t}`)}function Be(e,t){return S.delete(`${E(e)}/backfill/jobs/${t}`)}function Ve(e){return S.get(`${E(e)}/backfill/jobs`)}async function I(e,t){return await S.post(`${E(e)}/run`,t)}async function L(e,t){return await S.post(`${E(e)}/runs/${t}/replay`,{})}async function He(e){return await S.get(`${E(e)}/meta`)}async function Ue(e,t){return await S.post(`${E(e)}/generate`,t)}async function We(e,t){let n=await O(e,N),r=JSON.parse(n),i=Array.isArray(r)?r:r?.rules;if(!Array.isArray(i))throw Error(`The workspace rules file is invalid. Fix it in Rules before adding a rule.`);let a=(Array.isArray(t)?t:[t]).filter(e=>!i.some(t=>t.id===e.id));if(!a.length)return;let o=Array.isArray(r)?[...i,...a]:{...r,rules:[...i,...a]};await k(e,N,JSON.stringify(o,null,2)+`
|
|
3
|
-
`)}var Ge=We;function Ke(e,t,n,r=new Date){let i=e=>String(e).padStart(2,`0`),a={YYYY:String(r.getFullYear()),YY:i(r.getFullYear()%100),MM:i(r.getMonth()+1),DD:i(r.getDate()),HH:i(r.getHours()),mm:i(r.getMinutes()),ss:i(r.getSeconds())},o=e=>e.replace(/\{\{\s*([A-Za-z]+)\s*\}\}/g,(e,t)=>a[t]??e),s=e=>e.split(/[\\/]+/).filter(e=>e&&e!==`.`&&e!==`..`).join(`/`),c=[e,s(o(t.trim()))].filter(Boolean).join(`/`),l=s(o(n.trim()));return{root:c,added:l,result:[c,l,`<attachment filename>`].filter(Boolean).join(`/`),date:`${a.YYYY}-${a.MM}-${a.DD}`}}var R=`Applying rules to existing documents…`,z=new Map;function B(e){return`${e.ruleIds.length>1?`Rule ${e.ruleIndex+1}/${e.ruleIds.length}: `:``}${e.processed}${e.total===null?``:` / ${e.total}`} documents · ${e.applied} applied`}function qe(e,t){let n=`${t.checked} checked, ${t.applied} applied${t.skipped?`, ${t.skipped} already there`:``}`;t.status===`cancelled`?e.done({title:`Cancelled`,description:n}):t.status===`failed`?e.fail({title:`Stopped before finishing`,description:`${n}: ${t.error}. The rule stays enabled; rerun it from Rules to finish.`,variant:`destructive`}):t.failed?e.done({title:`Finished with errors`,description:`${n}, ${t.failed} failed. Details in the rule’s run log.`,variant:`destructive`}):e.done({title:`Rule applied`,description:n})}function V(e,t,n){let r=z.get(n.id);if(r)return r;let i=new Promise(r=>{let i={channel:`workspace:${t}`},a=e({title:R,description:B(n),action:{label:`Cancel`,onClick:()=>{a.update({title:`Cancelling…`,description:B(n)}),Be(t,n.id).catch(()=>a.update({title:R,description:`Could not cancel. Try again.`}))}}}),o=()=>{u?.(),C.off(`job.progress`,c),C.off(`job.finished`,c),r()},s=e=>{if(e.status===`running`)return a.update({title:R,description:B(e)});qe(a,e),window.dispatchEvent(new CustomEvent(`workspace:documents:refresh`)),window.dispatchEvent(new CustomEvent(`workspace:tree:refresh`)),o()},c=e=>{let t=e?.job;t?.id===n.id&&s(t)},l=()=>{C.emit(`subscribe`,i),F(t,n.id).then(s,()=>{})},u=C.on(`connect`,l);C.on(`job.progress`,c),C.on(`job.finished`,c),l()});return z.set(n.id,i),i.finally(()=>z.delete(n.id)),i}async function Je(e,t,n){let r;try{r=await ze(t,{ruleIds:n,limit:Fe()})}catch(t){e({title:R}).fail({title:`Could not start`,description:`${t instanceof Error?t.message:String(t)}. The rule stays enabled; rerun it from Rules.`,variant:`destructive`});return}return V(e,t,r)}async function Ye(e,t){let n=await Ve(t).catch(()=>[]);for(let r of n)r.status===`running`&&V(e,t,r)}function H(e){return`/workspaces/${e}/scripts`}async function Xe(e){return await S.get(H(e))||[]}async function Ze(e,t){return(await S.get(`${H(e)}/${t}`))?.content??``}async function Qe(e,t,n){await S.put(`${H(e)}/${t}`,{content:n})}async function $e(e,t){await S.delete(`${H(e)}/${t}`)}var U=t(),et=[{value:``,label:`any item`},{value:`email`,label:`an email`},{value:`message`,label:`a message`},{value:`tab`,label:`a browser tab / link`},{value:`note`,label:`a note`},{value:`file`,label:`a file`},{value:`todo`,label:`a todo / task`}],tt=[{value:`document.inserted`,label:`is added`,hint:`Fires when the item is created or uploaded.`},{value:`document.updated`,label:`is updated`,hint:`Fires on every edit of the item.`},{value:`document.linked`,label:`is filed into a folder`,hint:`Fires when the item is (re)filed into a tree path — the usual pair with "is added" for folder rules.`},{value:`document.unlinked`,label:`is removed from a folder`,hint:`Fires when the item leaves a tree path.`}],nt=[{key:`toExact`,label:`recipient (To/Cc) is`,hint:`accounting@example.com`},{key:`fromExact`,label:`email sender is`,hint:`person@example.com`},{key:`senderExact`,label:`message sender is`,hint:`Sender ID`},{key:`sender`,label:`message sender contains`,hint:`Sender ID or name`},{key:`senderRegex`,label:`message sender matches regex`,hint:`Sender ID or name pattern`},{key:`body`,label:`body / text contains`,hint:`Words in the email preview or message text`},{key:`bodyRegex`,label:`body / text matches regex`,hint:`invoice\\s+\\d+`},{key:`threadExact`,label:`thread is`,hint:`Thread ID`},{key:`channelExact`,label:`channel / conversation is`,hint:`Channel or conversation ID`},{key:`platformExact`,label:`platform is`,hint:`slack, whatsapp, teams`},{key:`pathExact`,label:`is directly in the folder`,hint:`Current folder membership`},{key:`eventPathExact`,label:`is inserted / linked directly into`,hint:`Exact event destination, e.g. ctx:/foo/bar/baz. Descendant inserts do not match.`},{key:`path`,label:`is under the folder`,hint:`/projects/canvas/UI or backends:/workspace/home/foo`},{key:`mime`,label:`file type is`,hint:`image/*, application/pdf`},{key:`from`,label:`sender contains`,hint:`boss@company.tld`},{key:`to`,label:`recipient (To/Cc) contains`,hint:`invoice@my-company.tld`},{key:`subject`,label:`subject contains`,hint:`invoice`},{key:`fromRegex`,label:`sender matches regex`,hint:`@(acme|example)\\.com$`},{key:`toRegex`,label:`recipient (To/Cc) matches regex`,hint:`^(billing|accounts)@`},{key:`subjectRegex`,label:`subject matches regex`,hint:`^invoice\\s+\\d+`},{key:`urlRegex`,label:`URL matches regex`,hint:`/(invoice|receipt)/`},{key:`urlHost`,label:`website is`,hint:`youtube.com`},{key:`urlContains`,label:`URL contains`,hint:`/watch?v=`},{key:`attachment`,label:`has an attachment of type`,hint:`application/pdf, or * for any`}],rt=new Set([`toExact`,`fromExact`,`senderExact`,`threadExact`,`channelExact`,`platformExact`]),it=e=>rt.has(e)?e.replace(/Exact$/,``):e.replace(/Regex$/,``),at=[{key:`sendFile`,label:`Send file(s) via a channel`,icon:v,tone:`text-blue-600 dark:text-blue-400 bg-blue-500/10`},{key:`extractAttachments`,label:`Extract email attachments to a folder`,icon:v,tone:`text-amber-600 dark:text-amber-400 bg-amber-500/10`},{key:`moveMessage`,label:`Move the email to a mail folder`,icon:v,tone:`text-teal-600 dark:text-teal-400 bg-teal-500/10`},{key:`store`,label:`Copy/Move file(s) to a storage backend`,icon:d,tone:`text-sky-600 dark:text-sky-400 bg-sky-500/10`},{key:`download`,label:`download what the link points at`,icon:_,tone:`text-rose-600 dark:text-rose-400 bg-rose-500/10`},{key:`link`,label:`file it into a folder`,icon:ie,tone:`text-emerald-600 dark:text-emerald-400 bg-emerald-500/10`},{key:`unlink`,label:`remove it from a folder`,icon:ie,tone:`text-amber-600 dark:text-amber-400 bg-amber-500/10`},{key:`tag`,label:`add tags`,icon:l,tone:`text-violet-600 dark:text-violet-400 bg-violet-500/10`},{key:`unstore`,label:`delete the file from a storage backend`,icon:h,tone:`text-amber-600 dark:text-amber-400 bg-amber-500/10`},{key:`notify`,label:`Send me a notification`,icon:re,tone:`text-pink-600 dark:text-pink-400 bg-pink-500/10`},{key:`agent`,label:`ask an agent`,icon:u,tone:`text-indigo-600 dark:text-indigo-400 bg-indigo-500/10`},{key:`script`,label:`run a script`,icon:te,tone:`text-slate-600 dark:text-slate-300 bg-slate-500/10`},{key:`delete`,label:`delete it from Canvas`,icon:p,tone:`text-destructive bg-destructive/10`},{key:`destroy`,label:`delete it everywhere`,icon:p,tone:`text-destructive bg-destructive/10`}],ot=e=>at.find(t=>t.key===e)||at[1],st=`{{title}}{{ext}}`,W=`{{YYYY}}/{{MM}}/{{YYYY}}{{MM}}{{DD}}_{{HH}}{{mm}}{{ss}}{{ext}}`,G=[{value:`auto`,label:`whatever it is (auto)`,hint:`arXiv → the PDF · YouTube, Vimeo, TikTok… → the video · image / video / PDF links → the file · anything else → the page.`},{value:`image`,label:`the file itself (image, PDF, …)`,hint:`Fetches the bytes the URL serves.`},{value:`video`,label:`the video (yt-dlp)`,hint:`Best video + audio, merged. Needs yt-dlp on the server.`},{value:`arxiv`,label:`the arXiv paper (PDF)`,hint:`Works for abs/ and pdf/ links.`},{value:`page`,label:`the page with its images & styles`,hint:`One page, offline-readable (wget --page-requisites).`},{value:`website`,label:`the whole website (mirror)`,hint:`Follows links on the same site up to the chosen depth.`}],ct=[{value:`keep`,label:`keep the original file name`},{value:`title`,label:`use the item title as file name`},{value:`dated`,label:`photo style: 2024/07/20240714_183012.jpg`},{value:`custom`,label:`custom template…`}],K=e=>({sendDriver:`imap`,sendSource:`document`,sendSubject:`{{file.name}}`,sendMessage:``,kind:e,a:``,b:``,recursive:!1,storeFrom:``,storeFolder:``,storeName:`keep`,storeMode:`copy`,storeConflict:`rename`,attachmentMime:`application/pdf`,attachmentName:``,attachmentPath:`{{YYYY}}/{{MM}}`,includeInline:!1,dlKind:`auto`,dlDepth:`2`,dlTags:``,keepLast:!0,notePath:``,noteTitle:``,filePath:``,fileBackend:`home`,fileInsert:``,notifyReply:!1}),q={id:null,description:``,events:[`document.inserted`],schema:``,cascade:!1,approval:!1,conditions:[],actions:[K(`link`)]},lt=e=>e.split(`|`).map(e=>e.trim()).filter(Boolean);function ut(e){return e.toLowerCase().replace(/[^a-z0-9]+/g,`-`).replace(/^-+|-+$/g,``)||`rule-${Math.random().toString(36).slice(2,7)}`}var J=e=>e.split(`,`).map(e=>e.trim()).filter(Boolean),dt=[{id:`send-invoices`,title:`Send invoice PDFs to accounting`,icon:v,tone:`text-blue-600 dark:text-blue-400 bg-blue-500/10`,blurb:`Send matching PDF attachments to your accounting firm’s ingestion email, or to a Slack / WhatsApp conversation. Keep the original email and files.`,build:()=>({...q,description:`Send invoice PDFs to accounting`,schema:`email`,conditions:[{field:`toExact`,value:``}],actions:[{...K(`sendFile`),sendSource:`attachments`,sendSubject:`Invoice: {{file.name}}`}]})},{id:`attachments`,title:`File PDF email attachments by month`,icon:v,tone:`text-amber-600 dark:text-amber-400 bg-amber-500/10`,blurb:`Choose a recipient and extract PDF attachments into Accounting / year / month, using the email date. Add a subject or filename filter to narrow it to invoices.`,build:()=>({...q,description:`File accounting PDF attachments by month`,schema:`email`,conditions:[{field:`toExact`,value:``}],actions:[{...K(`extractAttachments`),a:`workspace:home`,storeFolder:`Accounting`}]})},{id:`store`,title:`Copy/Move file(s) to a storage backend`,icon:d,tone:`text-sky-600 dark:text-sky-400 bg-sky-500/10`,blurb:`Uploads land in the managed blob store. Pick a folder in Canvas and a folder on a storage backend — copy or move matching files and optionally recreate their sub-folder paths.`,build:({backend:e})=>({...q,description:`Copy/Move file(s) to a storage backend`,schema:`file`,events:[`document.inserted`,`document.linked`],conditions:[{field:`path`,value:``}],actions:[{...K(`store`),a:e,recursive:!0}]})},{id:`photos`,title:`Sort photos by date`,icon:r,tone:`text-emerald-600 dark:text-emerald-400 bg-emerald-500/10`,blurb:`Images filed into a folder are stored as Photos / 2024 / 07 / 20240714_183012.jpg — by the time the photo was taken (EXIF), not uploaded.`,build:({backend:e})=>({...q,description:`Sort photos by date`,schema:`file`,events:[`document.inserted`,`document.linked`],conditions:[{field:`path`,value:``},{field:`mime`,value:`image/*`}],actions:[{...K(`store`),a:e,storeFolder:`Photos`,storeName:`dated`}]})},{id:`mirror`,title:`Mirror a storage folder`,icon:ie,tone:`text-violet-600 dark:text-violet-400 bg-violet-500/10`,blurb:`Everything that appears under a folder of a storage backend shows up 1:1 in the Directory tree.`,build:()=>({...q,description:`Mirror a storage folder`,events:[`document.inserted`,`document.linked`],conditions:[{field:`path`,value:`backends:/workspace/home/`}],actions:[{...K(`link`),a:`dir:/`,recursive:!0}]})},{id:`mail`,title:`File mail from a sender`,icon:v,tone:`text-amber-600 dark:text-amber-400 bg-amber-500/10`,blurb:`Emails from a person or domain are filed into a folder and you get a notification.`,build:()=>({...q,description:`Mail from …`,schema:`email`,conditions:[{field:`from`,value:``}],actions:[{...K(`link`),a:`/work/urgent`},{...K(`notify`),a:`New mail from {{doc.data.from}}: {{doc.data.subject}}`}]})},{id:`download`,title:`Download what links point at`,icon:_,tone:`text-rose-600 dark:text-rose-400 bg-rose-500/10`,blurb:`Bookmarks filed into a folder are fetched for real — images, videos (yt-dlp), arXiv papers, a page or a whole website — saved to a folder and filed next to the link.`,build:({backend:e})=>({...q,description:`Download what links point at`,schema:`tab`,events:[`document.inserted`,`document.linked`],conditions:[{field:`path`,value:``}],actions:[{...K(`download`),a:e,storeFolder:`Downloads`,recursive:!0}]})},{id:`agent`,title:`Ask an agent`,icon:u,tone:`text-indigo-600 dark:text-indigo-400 bg-indigo-500/10`,blurb:`Hand new items to an agent with a prompt; save its reply as a note or get it as a notification.`,build:()=>({...q,description:`Summarize new items`,actions:[{...K(`agent`),b:`Read document #{{doc.id}} in full with canvas_get, then summarize it in three bullet points.`,notifyReply:!0}]})},{id:`blank`,title:`Start from scratch`,icon:ae,tone:`text-muted-foreground bg-muted`,blurb:`An empty rule: choose what it reacts to, add conditions and actions.`,build:()=>({...q})}];function Y(e){let t=e.filter(e=>[`path`,`pathExact`,`eventPathExact`].includes(e.field));if(t.length!==1||t[0].field!==`eventPathExact`)return null;let n=lt(t[0].value);return n.length===1&&/^(ctx|context):\//.test(n[0])?n[0].replace(/^(ctx|context):/,``).replace(/\/+$/,``)||`/`:null}function ft(e){if(Y(e)!==null)return!0;let t=e.filter(e=>[`path`,`pathExact`,`eventPathExact`].includes(e.field)).flatMap(e=>lt(e.value));return t.length>0&&t.every(e=>/^(dir|directory|backends):\//.test(e))}function pt(e,t,n){let r=e=>e.replace(/\\/g,`/`).split(`/`).filter(e=>e&&e!==`.`&&e!==`..`).join(`/`),i=`${n?.treePath?`backends:${n.treePath}`:e.a}/${r(e.storeFolder.trim())}`.replace(/\/+$/,``),a=Y(t),o=e.recursive?a===null?`<sub-folders>`:r(a):``;return{root:i,recreated:o,result:[i,o,e.storeName===`keep`?`<original filename>`:e.storeName===`title`?`<title>.<ext>`:e.storeName===`dated`?W:e.b||`<filename>`].filter(Boolean).join(`/`)}}function mt(e,t=[]){let n={event:e.events.length===1?e.events[0]:e.events};e.schema&&(n.schema=e.schema);let r={},i={};for(let t of e.conditions){let e=t.field.endsWith(`Regex`),n=rt.has(t.field),a=e||n?t.value.trim()?[t.value]:[]:lt(t.value);if(e&&a.length)try{new RegExp(t.value,`i`)}catch{throw Error(`Invalid regular expression for ${nt.find(e=>e.key===t.field)?.label}: ${t.value}`)}if(!a.length)throw Error(`Enter a value for ${nt.find(e=>e.key===t.field)?.label||t.field}, or remove that condition.`);if(t.field===`urlHost`||t.field===`urlContains`||t.field===`urlRegex`){let e=t.field===`urlHost`?`host`:t.field===`urlRegex`?`regex`:`contains`,n=i[e],r=[...Array.isArray(n)?n:n==null?[]:[n],...a];i[e]=r.length===1?r[0]:r}else(r[it(t.field)]||=[]).push(...e?a.map(e=>({regex:e})):n?a.map(e=>({equals:e})):a)}for(let[e,t]of Object.entries(r))t?.length&&(n[e]=t.length===1?t[0]:t);Object.keys(i).length&&(n.url=i);let a=e=>{let t={};return e.notePath.trim()&&(t.note={path:e.notePath.trim(),...e.noteTitle.trim()?{title:e.noteTitle.trim()}:{}}),e.filePath.trim()&&(t.file={path:e.filePath.trim(),...e.fileBackend===`data`?{backend:`data`}:{},...e.fileInsert.trim()?{insert:e.fileInsert.trim()}:{}}),e.notifyReply&&(t.notify=!0),Object.keys(t).length?t:null},o=[];for(let n of e.actions){let r=n.a.trim(),i=n.b.trim(),s=n.recursive?{recursive:!0}:{};if(n.kind===`sendFile`){if(!r)throw Error(`Choose a sending account for the file.`);if(!i)throw Error(n.sendDriver===`imap`?`Enter the destination email address.`:`Enter a configured destination conversation.`);if(![`imap`,`slack`,`whatsapp`].includes(n.sendDriver))throw Error(`Choose email, Slack or WhatsApp.`);if(![`document`,`attachments`,`download`].includes(n.sendSource))throw Error(`Choose which files to send.`);if(n.sendSource===`download`&&!o.some(e=>e.action===`download`))throw Error(`Add a Download action before sending its files.`);let e=J(n.attachmentMime);if(n.sendSource===`attachments`&&(!e.length||e.some(e=>!/^(\*|[a-z0-9!#$&^_.+-]+\/(\*|[a-z0-9!#$&^_.+-]+)|\*\/\*)$/i.test(e))))throw Error(`Enter attachment MIME types, such as application/pdf.`);if(n.sendDriver===`whatsapp`&&n.sendMessage.length>1024)throw Error(`WhatsApp file captions must be at most 1,024 characters.`);o.push({action:`sendFile`,source:n.sendSource,driver:n.sendDriver,address:r,...n.sendDriver===`imap`?{to:J(i),subject:n.sendSubject}:{target:i},...n.sendMessage?{message:n.sendMessage}:{},...n.sendSource===`attachments`?{mime:e.length===1?e[0]:e,...n.attachmentName.trim()?{filename:n.attachmentName.trim()}:{},...n.includeInline?{includeInline:!0}:{}}:{}})}if(n.kind===`link`&&r&&o.push({action:`link`,paths:J(r),...s,...i?{tags:J(i)}:{}}),n.kind===`unlink`&&r&&o.push({action:`unlink`,paths:J(r),...s}),n.kind===`tag`&&r&&o.push({action:`tag`,tags:J(r)}),n.kind===`moveMessage`){if(!r)throw Error(`Enter the mail folder to move the email to, such as INBOX/Accounting/{{YYYY}}/Expenses.`);o.push({action:`moveMessage`,folder:r})}if(n.kind===`store`&&r){if(n.storeMode===`move`&&!n.storeFrom.trim())throw Error(`Choose the source backend whose copy should be moved.`);if(n.recursive&&!ft(e.conditions))throw Error(`Choose a Directory/Backends source path, or one exact Context insertion path, to recreate the path.`);if(n.recursive&&t.find(e=>e.address===r)?.capabilities?.paths!==!0)throw Error(`This destination has not reported support for folder paths. Choose a supported backend or turn off path recreation.`);let a=n.storeFolder.trim().replace(/^\/+|\/+$/g,``),c=n.storeName===`title`?st:n.storeName===`dated`?W:n.storeName===`custom`?i:``;o.push({action:`store`,to:r,...n.storeFrom.trim()?{from:n.storeFrom.trim()}:{},mode:n.storeMode,...a?{folder:a}:{},...s,...n.recursive&&Y(e.conditions)!==null?{pathMode:`full`}:{},...c?{key:c}:{},onConflict:n.storeConflict})}if(n.kind===`extractAttachments`){if(!r)throw Error(`Choose a destination backend for the attachments.`);if(t.find(e=>e.address===r)?.capabilities?.paths!==!0)throw Error(`Choose an attachment destination with support for folder paths.`);let e=J(n.attachmentMime);if(!e.length||e.some(e=>!/^(\*|[a-z0-9!#$&^_.+-]+\/(\*|[a-z0-9!#$&^_.+-]+)|\*\/\*)$/i.test(e)))throw Error(`Enter attachment MIME types, such as application/pdf or image/*. Use * for all attachments.`);if(![`rename`,`error`].includes(n.storeConflict))throw Error(`Choose rename or skip for attachment filename conflicts.`);o.push({action:`extractAttachments`,to:r,mime:e.length===1?e[0]:e,...n.storeFolder.trim()?{folder:n.storeFolder.trim()}:{},...n.attachmentPath.trim()?{subfolder:n.attachmentPath.trim()}:{},...n.attachmentName.trim()?{filename:n.attachmentName.trim()}:{},...n.includeInline?{includeInline:!0}:{},onConflict:n.storeConflict})}if(n.kind===`download`){let e=n.storeFolder.trim().replace(/^\/+|\/+$/g,``),t=Number(n.dlDepth);o.push({action:`download`,to:r||`workspace:home`,...e?{folder:e}:{},...s,...n.dlKind===`auto`?{}:{kind:n.dlKind},...i?{insert:J(i)}:{},...n.dlTags.trim()?{tags:J(n.dlTags)}:{},...n.dlKind===`website`&&Number.isFinite(t)&&t>0&&t!==2?{depth:t}:{}})}if(n.kind===`unstore`&&r&&o.push({action:`unstore`,from:r,...i?{ifOn:i}:{},...n.keepLast?{}:{keepLast:!1}}),n.kind===`notify`&&r&&o.push({action:`notify`,message:r}),n.kind===`delete`&&o.push({action:`delete`}),n.kind===`destroy`&&o.push({action:`destroy`}),n.kind===`agent`&&r&&i){let e=a(n);o.push({action:`agent`,slug:r,prompt:i,...e?{output:e}:{}})}if(n.kind===`script`&&r){let e=a(n);o.push({action:`script`,path:r,...e?{output:e}:{}})}}return{id:e.id||ut(e.description),enabled:!0,...e.description?{description:e.description}:{},...e.cascade?{cascade:!0}:{},...e.approval?{approval:!0}:{},...e.editable?.length?{editable:e.editable}:{},...e.ttl===void 0?{}:{ttl:e.ttl},when:n,then:o}}function ht(e){let{event:t,schema:n,from:r,to:i,subject:a,body:o,sender:s,thread:c,channel:l,platform:u,path:d,pathExact:f,eventPathExact:ee,mime:p,url:m,attachment:h,...te}=e.when;if(Object.keys(te).length>0)return null;let ne=Array.isArray(t)?t:[t];if(!ne.length||!ne.every(e=>typeof e==`string`&&tt.some(t=>t.value===e))||n!==void 0&&typeof n!=`string`)return null;let g=[],_=(e,t)=>{let n=Array.isArray(t)?t:[t];if(e.endsWith(`Regex`)){if(!n.every(e=>typeof e==`string`))return!1;for(let t of n)g.push({field:e,value:t})}else if(rt.has(e))for(let t of n){if(!t||typeof t!=`object`||Object.keys(t).length!==1||typeof t.equals!=`string`)return!1;g.push({field:e,value:t.equals})}else if([`from`,`to`,`subject`,`body`,`sender`].includes(e))for(let t of n)if(typeof t==`string`)g.push({field:e,value:t});else if([`from`,`to`,`sender`].includes(e)&&t&&typeof t==`object`&&Object.keys(t).length===1&&typeof t.equals==`string`)g.push({field:`${e}Exact`,value:t.equals});else if(t&&typeof t==`object`&&Object.keys(t).length===1&&typeof t.regex==`string`)g.push({field:`${e}Regex`,value:t.regex});else return!1;else{if(!n.every(e=>typeof e==`string`))return!1;g.push({field:e,value:n.join(` | `)})}return!0};if(d!==void 0&&!_(`path`,d)||f!==void 0&&!_(`pathExact`,f)||ee!==void 0&&!_(`eventPathExact`,ee)||p!==void 0&&!_(`mime`,p)||r!==void 0&&!_(`from`,r)||i!==void 0&&!_(`to`,i)||a!==void 0&&!_(`subject`,a)||o!==void 0&&!_(`body`,o)||s!==void 0&&!_(`sender`,s)||c!==void 0&&!_(`threadExact`,c)||l!==void 0&&!_(`channelExact`,l)||u!==void 0&&!_(`platformExact`,u)||h!==void 0&&!_(`attachment`,h))return null;if(m!==void 0){if(typeof m==`string`)g.push({field:`urlContains`,value:m});else if(m&&typeof m==`object`){let e=m;if(Object.keys(e).filter(e=>e!==`host`&&e!==`contains`&&e!==`regex`).length||e.host!==void 0&&!_(`urlHost`,e.host)||e.contains!==void 0&&!_(`urlContains`,e.contains)||e.regex!==void 0&&!_(`urlRegex`,e.regex))return null}else return null}let re=e=>{let t=e.output&&typeof e.output==`object`?e.output:{};if(Object.keys(t).filter(e=>e!==`note`&&e!==`file`&&e!==`notify`).length)return null;let n=t.note&&typeof t.note==`object`?t.note:{},r=t.file&&typeof t.file==`object`?t.file:{};return Object.keys(r).filter(e=>e!==`path`&&e!==`backend`&&e!==`insert`).length?null:{notePath:typeof n.path==`string`?n.path:``,noteTitle:typeof n.title==`string`?n.title:``,filePath:typeof r.path==`string`?r.path:``,fileBackend:r.backend===`data`?`data`:`home`,fileInsert:typeof r.insert==`string`?r.insert:``,notifyReply:t.notify===!0}},v=[];for(let t of e.then||[]){if(t.approval!==void 0)return null;if(t.action===`link`&&Array.isArray(t.paths))v.push({...K(`link`),a:t.paths.join(`, `),b:Array.isArray(t.tags)?t.tags.join(`, `):``,recursive:t.recursive===!0});else if(t.action===`unlink`&&Array.isArray(t.paths))v.push({...K(`unlink`),a:t.paths.join(`, `),recursive:t.recursive===!0});else if(t.action===`tag`&&Array.isArray(t.tags))v.push({...K(`tag`),a:t.tags.join(`, `)});else if(t.action===`moveMessage`){if(Object.keys(t).some(e=>e!==`action`&&e!==`folder`)||typeof t.folder!=`string`)return null;v.push({...K(`moveMessage`),a:t.folder})}else if(t.action===`notify`&&typeof t.message==`string`)v.push({...K(`notify`),a:t.message});else if(t.action===`store`&&typeof t.to==`string`){if(t.pathMode!==void 0&&(t.pathMode!==`full`||t.recursive!==!0||Y(g)===null)||t.recursive===!0&&Y(g)!==null&&t.pathMode!==`full`||t.folder!==void 0&&typeof t.folder!=`string`||t.key!==void 0&&typeof t.key!=`string`)return null;let e=typeof t.key==`string`?t.key:``;v.push({...K(`store`),a:t.to,b:e===st||e===W?``:e,storeFolder:typeof t.folder==`string`?t.folder:``,recursive:t.recursive===!0,storeName:e?e===st?`title`:e===W?`dated`:`custom`:`keep`,storeFrom:typeof t.from==`string`?t.from:Array.isArray(t.from)?String(t.from[0]??``):``,storeMode:t.mode===`move`?`move`:`copy`,storeConflict:t.onConflict===`error`||t.onConflict===`overwrite`?t.onConflict:`rename`})}else if(t.action===`sendFile`){let e=new Set([`action`,`source`,`driver`,`address`,`to`,`target`,`subject`,`message`,`mime`,`filename`,`includeInline`]);if(Object.keys(t).some(t=>!e.has(t))||![`imap`,`slack`,`whatsapp`].includes(String(t.driver))||typeof t.address!=`string`||t.source!==void 0&&![`document`,`attachments`,`download`].includes(String(t.source))||[`target`,`subject`,`message`,`filename`].some(e=>t[e]!==void 0&&typeof t[e]!=`string`)||t.includeInline!==void 0&&typeof t.includeInline!=`boolean`)return null;let n=Array.isArray(t.to)?t.to:t.to===void 0?[]:[t.to],r=Array.isArray(t.mime)?t.mime:[t.mime??`*`];if(!n.every(e=>typeof e==`string`)||!r.every(e=>typeof e==`string`)||(t.driver===`imap`?t.target!==void 0:t.to!==void 0||t.subject!==void 0))return null;v.push({...K(`sendFile`),a:t.address,b:t.driver===`imap`?n.join(`, `):String(t.target||``),sendDriver:t.driver,sendSource:t.source||`document`,sendSubject:String(t.subject??`{{file.name}}`),sendMessage:String(t.message||``),attachmentMime:r.join(`, `),attachmentName:String(t.filename||``),includeInline:t.includeInline===!0})}else if(t.action===`extractAttachments`){let e=new Set([`action`,`to`,`folder`,`subfolder`,`mime`,`filename`,`includeInline`,`onConflict`]);if(Object.keys(t).some(t=>!e.has(t))||typeof t.to!=`string`||[`folder`,`subfolder`,`filename`].some(e=>t[e]!==void 0&&typeof t[e]!=`string`)||t.includeInline!==void 0&&typeof t.includeInline!=`boolean`||t.onConflict!==void 0&&t.onConflict!==`rename`&&t.onConflict!==`error`)return null;let n=Array.isArray(t.mime)?t.mime:[t.mime??`*`];if(!n.every(e=>typeof e==`string`))return null;v.push({...K(`extractAttachments`),a:t.to,storeFolder:typeof t.folder==`string`?t.folder:``,attachmentPath:typeof t.subfolder==`string`?t.subfolder:``,attachmentMime:n.join(`, `),attachmentName:typeof t.filename==`string`?t.filename:``,includeInline:t.includeInline===!0,storeConflict:t.onConflict===`error`?`error`:`rename`})}else if(t.action===`download`){let e=new Set([`action`,`to`,`folder`,`recursive`,`kind`,`insert`,`tags`,`depth`]);if(Object.keys(t).some(t=>!e.has(t)))return null;let n=typeof t.kind==`string`?t.kind:`auto`;if(!G.some(e=>e.value===n))return null;let r=Array.isArray(t.insert)?t.insert:typeof t.insert==`string`?[t.insert]:[];if(!r.every(e=>typeof e==`string`))return null;v.push({...K(`download`),a:typeof t.to==`string`?t.to:`workspace:home`,b:r.join(`, `),storeFolder:typeof t.folder==`string`?t.folder:``,recursive:t.recursive===!0,dlKind:n,dlDepth:typeof t.depth==`number`?String(t.depth):`2`,dlTags:Array.isArray(t.tags)?t.tags.join(`, `):``})}else if(t.action===`unstore`&&(typeof t.from==`string`||Array.isArray(t.from))){let e=e=>Array.isArray(e)?String(e[0]??``):typeof e==`string`?e:``;v.push({...K(`unstore`),a:e(t.from),b:e(t.ifOn),keepLast:t.keepLast!==!1})}else if(t.action===`delete`)v.push(K(`delete`));else if(t.action===`destroy`)v.push(K(`destroy`));else if(t.action===`agent`&&typeof t.slug==`string`&&typeof t.prompt==`string`){let e=re(t);if(!e)return null;v.push({...K(`agent`),a:t.slug,b:t.prompt,...e})}else if(t.action===`script`&&typeof t.path==`string`){let e=re(t);if(!e)return null;v.push({...K(`script`),a:t.path,...e})}else return null}return{id:e.id,description:e.description||``,events:ne,schema:typeof n==`string`?n:``,cascade:e.cascade===!0,approval:e.approval===!0,...e.editable?.length?{editable:e.editable}:{},...e.ttl===void 0?{}:{ttl:e.ttl},conditions:g,actions:v.length?v:[K(`link`)]}}var gt=(e,t)=>t.find(t=>t.value===e)?.label?.replace(/\s\(\d+\)$/,``)||(e?String(e).replace(/^data\/schema\//,``):`any item`);function _t(e,t=et){let n=e.when,r=Se(e).map(e=>tt.find(t=>t.value===e)?.label||e).join(` or `),i=[`When ${gt(n.schema,t)} ${r}`],a=e=>Array.isArray(e)?e.join(` or `):typeof e==`object`&&e?JSON.stringify(e):String(e),o={path:`under`,pathExact:`directly in`,eventPathExact:`inserted / linked directly into`,mime:`type`,from:`from`,to:`to`,subject:`subject`,body:`body / text`,sender:`sender`,thread:`thread`,channel:`conversation`,platform:`platform`,url:`url`,attachment:`attachment`};for(let e of Object.keys(o))n[e]!==void 0&&i.push(`${o[e]} ${a(n[e])}`);return i.join(` · `)}function vt(e){let t=e.output||{},n=t.note||{},r=t.file||{};return[n.path?`reply → note ${n.path}`:``,r.path?`reply → file ${r.backend===`data`?`data:`:`home/`}${r.path}${r.insert?` (indexed at ${r.insert})`:``}`:``,t.notify?`reply → notify`:``].filter(Boolean).join(`, `)}function yt(e){if(e.action===`link`)return`file into ${e.paths?.join(`, `)}${e.recursive===!0?` (sub-folders kept)`:``}`;if(e.action===`unlink`)return`remove from ${e.paths?.join(`, `)}${e.recursive===!0?` (sub-folders kept)`:``}`;if(e.action===`tag`)return`tag ${e.tags?.join(`, `)}`;if(e.action===`store`){let t=typeof e.folder==`string`&&e.folder?`/${e.folder}`:``,n=e.key===st?`, named by title`:e.key===W?`, by date`:typeof e.key==`string`&&e.key?`, as ${e.key}`:``;return`${e.mode===`move`?`move`:`copy`} the file to ${e.to}${t}${e.recursive===!0?e.pathMode===`full`?` (full directory path recreated)`:` (sub-folder path recreated)`:``}${n}`}if(e.action===`extractAttachments`){let t=[e.to,e.folder,e.subfolder].filter(Boolean).join(`/`);return`extract ${Array.isArray(e.mime)?e.mime.join(`, `):e.mime||`all`} attachments to ${t}${e.filename?` (filename contains ${e.filename})`:``}`}if(e.action===`moveMessage`)return`move the email to mail folder ${e.folder}`;if(e.action===`download`){let t=G.find(t=>t.value===(e.kind||`auto`)),n=typeof e.folder==`string`&&e.folder?`/${e.folder}`:``,r=Array.isArray(e.insert)&&e.insert.length?`, filed at ${e.insert.join(`, `)}`:`, filed next to the link`;return`download ${t?.value===`auto`?`the link (auto-detected)`:t?.label||e.kind} to ${e.to||`workspace:home`}${n}${e.recursive===!0?` (sub-folders kept)`:``}${r}`}if(e.action===`unstore`)return`delete the file from ${Array.isArray(e.from)?e.from.join(`, `):e.from}${e.ifOn?` once it is on ${Array.isArray(e.ifOn)?e.ifOn.join(`, `):e.ifOn}`:``}`;if(e.action===`sendFile`)return`send ${e.source===`attachments`?`matching attachments`:e.source===`download`?`downloaded files`:`the file`} via ${e.driver===`imap`?`email`:e.driver} to ${Array.isArray(e.to)?e.to.join(`, `):e.to||e.target||`…`}`;if(e.action===`notify`)return`send me a notification`;if(e.action===`delete`)return`delete from Canvas (keeps stored files/mail)`;if(e.action===`destroy`)return`⚠ delete everywhere (index + storage)`;if(e.action===`agent`){let t=vt(e);return`ask agent "${e.slug}"${t?` (${t})`:``}`}if(e.action===`script`){let t=vt(e);return`run ${e.path}${t?` (${t})`:``}`}return e.action}function bt(e){return(e.then||[]).map(yt).join(` · `)||`(no actions)`}function xt(e){return Ce(e).length>0&&(e.then||[]).length>0&&(e.then||[]).every(e=>e.action===`link`||e.action===`unlink`||e.action===`store`||e.action===`unstore`)}function St(e){let t={};for(let n of e){if(n.handlerType!==`rule`)continue;let e=t[n.handler]||={count:0,errors:0,last:n};e.count++,n.status===`error`&&e.errors++,n.ts>e.last.ts&&(e.last=n)}return t}function Ct(e){let t=Date.now()-new Date(e).getTime();if(!Number.isFinite(t)||t<0)return``;let n=Math.floor(t/6e4);if(n<1)return`just now`;if(n<60)return`${n}m ago`;let r=Math.floor(n/60);return r<48?`${r}h ago`:`${Math.floor(r/24)}d ago`}function wt(e){return e.some(e=>e.address===`workspace:home`)?`workspace:home`:e.find(e=>e.address!==`workspace:data`)?.address||e[0]?.address||``}function Tt(e){if(e.kind===`document`&&e.rule)return{...ht(e.rule)||q,id:null};if(e.kind===`download`){let t=e.path?` filed under ${e.path.replace(/^(ctx|dir):/,``)}`:``;return{...q,description:`Download links${t}`,schema:`tab`,events:[`document.inserted`,`document.linked`],conditions:[{field:`path`,value:e.path||``}],actions:[{...K(`download`),a:e.storeTo||``,storeFolder:e.storeFolder||`Downloads`,recursive:!0}]}}if(e.kind===`store`){let t=e.path||``,n=/^(?:(?:ctx|context):)?\//.test(t),r=[{field:n?`eventPathExact`:`path`,value:n&&t.startsWith(`/`)?`ctx:${t}`:t}],i=e.path?`${n?` inserted / linked directly into`:` filed under`} ${e.path.replace(/^(ctx|context|dir|directory):/,``)}`:``;return{...q,description:e.storeTo?`Copy files${i} to ${e.storeTo}${e.storeFolder?`/${e.storeFolder}`:``}`:`Copy files${i} to a storage backend`,schema:`file`,events:[`document.inserted`,`document.linked`],conditions:r,actions:[{...K(`store`),a:e.storeTo||``,storeFolder:e.storeFolder||``,recursive:ft(r)}]}}return{...q,description:`Mirror ${e.path} into ${e.target}`,events:[`document.inserted`,`document.linked`],conditions:[{field:`path`,value:e.path||``}],actions:[{...K(`link`),a:e.target||`dir:/`,recursive:!0}]}}var X=`h-10 w-full rounded-md border bg-background px-3 text-sm outline-none focus:ring-2 focus:ring-ring disabled:opacity-50`,Z=`h-10 text-sm`;function Q({label:e,hint:t,children:n,className:r}){return(0,U.jsxs)(`label`,{className:y(`flex min-w-0 flex-col gap-1.5`,r),children:[(0,U.jsx)(`span`,{className:`text-sm font-medium`,children:e}),n,t&&(0,U.jsx)(`span`,{className:`text-xs leading-relaxed text-muted-foreground`,children:t})]})}function $({checked:e,onChange:t,label:n,hint:r,disabled:i}){return(0,U.jsxs)(`button`,{type:`button`,role:`switch`,"aria-checked":e,disabled:i,onClick:()=>t(!e),className:y(`flex w-full items-start gap-3 rounded-lg border p-3 text-left transition-colors hover:bg-accent/40 disabled:cursor-not-allowed disabled:opacity-50`,e&&`border-primary/40 bg-primary/5`),children:[(0,U.jsx)(`span`,{className:y(`mt-0.5 inline-flex h-5 w-9 shrink-0 items-center rounded-full p-0.5 transition-colors`,e?`bg-primary`:`bg-muted-foreground/30`),children:(0,U.jsx)(`span`,{className:y(`h-4 w-4 rounded-full bg-background shadow transition-transform`,e&&`translate-x-4`)})}),(0,U.jsxs)(`span`,{className:`min-w-0`,children:[(0,U.jsx)(`span`,{className:`block text-sm font-medium`,children:n}),r&&(0,U.jsx)(`span`,{className:`block text-xs leading-relaxed text-muted-foreground`,children:r})]})]})}function Et({value:e,options:t,onChange:n}){return(0,U.jsx)(`div`,{className:`inline-flex h-10 rounded-md border bg-background p-1`,children:t.map(t=>(0,U.jsx)(`button`,{type:`button`,onClick:()=>n(t.value),className:y(`rounded px-3 text-sm transition-colors`,e===t.value?`bg-primary text-primary-foreground shadow-sm`:`text-muted-foreground hover:text-foreground`),children:t.label},t.value))})}function Dt({active:e,onClick:t,children:n,title:r}){return(0,U.jsx)(`button`,{type:`button`,title:r,onClick:t,"aria-pressed":e,className:y(`h-9 rounded-full border px-3.5 text-sm transition-colors`,e?`border-primary bg-primary/10 font-medium text-foreground`:`text-muted-foreground hover:bg-accent hover:text-foreground`),children:n})}function Ot({step:e,title:t,hint:n}){return(0,U.jsxs)(`div`,{className:`flex items-start gap-3`,children:[(0,U.jsx)(`span`,{className:`mt-0.5 flex h-7 w-7 shrink-0 items-center justify-center rounded-full bg-primary/10 text-sm font-semibold text-primary`,children:e}),(0,U.jsxs)(`div`,{children:[(0,U.jsx)(`h3`,{className:`text-base font-semibold leading-7`,children:t}),n&&(0,U.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:n})]})]})}function kt({icon:e,tone:t,size:n=`md`}){return(0,U.jsx)(`span`,{className:y(`inline-flex shrink-0 items-center justify-center rounded-xl`,n===`lg`?`h-12 w-12`:`h-10 w-10`,t),children:(0,U.jsx)(e,{className:n===`lg`?`h-6 w-6`:`h-5 w-5`})})}function At({workspaceId:e,onOpenJson:t,onShowRuns:n,backfillLimit:r,prefill:l,onPrefillConsumed:u,createOnly:d=!1,onCreated:h,onCancel:te}){let{showToast:_,showProgress:re}=se(),[v,oe]=(0,T.useState)([]),[S,C]=(0,T.useState)({}),le=e=>{Me(e,{limit:500}).then(e=>C(St(e))).catch(()=>C({}))},[de,fe]=(0,T.useState)(!0),[w,E]=(0,T.useState)(null),[D,O]=(0,T.useState)(!1),[k,A]=(0,T.useState)(!1),[ge,j]=(0,T.useState)([]),[M,_e]=(0,T.useState)([]),[ve,ye]=(0,T.useState)([]),[be,xe]=(0,T.useState)(``),Se=(0,T.useRef)(null),[Te,Ee]=(0,T.useState)(e);e!==Te&&(Ee(e),fe(!0)),(0,T.useEffect)(()=>{De(e).then(e=>oe(e)).finally(()=>fe(!1)),le(e)},[e]);let[N,ke]=(0,T.useState)(null);l!==N&&(ke(l),l&&(E(Tt(l)),O(!1))),(0,T.useEffect)(()=>{l&&u?.()},[l,u]),(0,T.useEffect)(()=>{Xe(e).then(e=>j(e.map(e=>e.path))).catch(()=>j([]))},[e]),(0,T.useEffect)(()=>{let t=!1;return pe(e).then(e=>{t||(ye([...new Map(e.map(e=>[`${e.driver}:${e.address}`,e])).values()]),xe(``))}).catch(()=>{t||(ye([]),xe(`Sending accounts could not be loaded.`))}),()=>{t=!0}},[e]),(0,T.useEffect)(()=>{ue(e).then(e=>{let t=e.filter(e=>e.kind===`storage`&&e.enabled!==!1&&e.config?.supported!==!1&&e.config?.readOnly!==!0&&e.capabilities?.write!==!1);_e(t);let n=wt(t);n&&E(e=>e&&e.actions.some(e=>(e.kind===`store`||e.kind===`download`)&&!e.a)?{...e,actions:e.actions.map(e=>(e.kind===`store`||e.kind===`download`)&&!e.a?{...e,a:n}:e)}:e)}).catch(()=>_e([]))},[e]);let[Ae,je]=(0,T.useState)(et);(0,T.useEffect)(()=>{He(e).then(e=>{e.schemas?.length&&je([{value:``,label:`any item`},...e.schemas.map(e=>({value:e.id,label:`${e.name} (${e.count})`}))])}).catch(()=>{})},[e]);let P=async(t,n)=>{A(!0);try{return await Oe(e,t),oe(t),_({title:n,description:`rules.json updated (committed to workspace git)`}),!0}catch(e){return _({title:`Error`,description:e instanceof Error?e.message:`Failed to save rules`,variant:`destructive`}),!1}finally{A(!1)}},Ne=async()=>{if(!w||de||k)return;let t;try{t=mt(w,M)}catch(e){_({title:`Invalid rule`,description:e instanceof Error?e.message:`Check the rule conditions and actions`,variant:`destructive`});return}if(!t.then.length){_({title:`Add an action`,description:`Pick at least one "then" action and fill in its fields.`,variant:`destructive`});return}if(d){t.id=`${t.id}-${Math.random().toString(36).slice(2,10)}`,A(!0);try{await We(e,t),_({title:`Rule created`,description:`The rule will run for matching new items.`}),h?.()}catch(e){_({title:`Could not create rule`,description:e instanceof Error?e.message:`Failed to save rule`,variant:`destructive`})}finally{A(!1)}return}!w.id&&v.some(e=>e.id===t.id)&&(t.id=`${t.id}-${Math.random().toString(36).slice(2,10)}`);let n=w.id?v.map(e=>e.id===w.id?{...t,enabled:e.enabled!==!1}:e):[...v,t];await P(n,w.id?`Rule updated`:`Rule created`)&&(E(null),h?.())},Pe=e=>P(v.map(t=>t.id===e?{...t,enabled:t.enabled===!1}:t),`Rule toggled`),Fe=e=>{confirm(`Delete rule "${e}"?`)&&P(v.filter(t=>t.id!==e),`Rule deleted`)},[Ie,Le]=(0,T.useState)(null),ze=async t=>{Le(t);try{let n=await Re(e,{ruleId:t,dryRun:!0,limit:r}),i=n.results.filter(e=>e.matched).length;if(!i){_({title:`Apply to existing items`,description:`No matches among ${n.processed} existing documents (conditions evaluate against each document's current tree placements). Raise the batch size in the toolbar to cover more.`});return}if(!confirm(`Rule "${t}" matches ${i} of the first ${n.processed} of ${n.total??n.processed} existing documents. Run its actions on all of them now?`))return;await Je(re,e,[t])}catch(e){_({title:`Backfill failed`,description:e instanceof Error?e.message:`Unknown error`,variant:`destructive`})}finally{Le(null),le(e)}},F=(e,t)=>E(n=>n&&{...n,[e]:t}),Be=e=>{E(e.build({backend:wt(M)})),O(!1),requestAnimationFrame(()=>Se.current?.scrollIntoView({behavior:`smooth`,block:`start`}))},Ve=e=>{let n=ht(e);n?(E(n),O(!1),requestAnimationFrame(()=>Se.current?.scrollIntoView({behavior:`smooth`,block:`start`}))):t?.()},[I,L]=(0,T.useState)(null),Ue=(e,t)=>t.treeType===`context`?e:t.treeName===`directory`?`dir:${e}`:`${t.treeName}:${e}`,Ge=(e,t)=>{if(!I||!w||!e.length){L(null);return}if(I.target===`storeFolder`){let t=we(e[0]);F(`actions`,w.actions.map((e,n)=>n===I.index?{...e,storeFolder:t?.rel||``,...t?.backend&&M.some(e=>e.address===t.backend)?{a:t.backend}:{}}:e))}else if(I.target===`condition`){let n=e.map(e=>Ue(e,t)),r=t.treeType===`context`&&w.actions.some(e=>e.kind===`store`);F(`conditions`,w.conditions.map((e,t)=>t===I.index?{...e,...r?{field:`eventPathExact`}:{},value:n.join(` | `)}:e))}else{let n=e.map(e=>Ue(e,t));F(`actions`,w.actions.map((e,t)=>t===I.index?e.kind===`download`?{...e,b:n.join(`, `)}:{...e,a:n.join(`, `)}:e))}L(null)},R=(e,t,n=`Browse…`)=>(0,U.jsxs)(b,{type:`button`,size:`sm`,variant:`outline`,className:`h-10 shrink-0 px-3`,title:n,onClick:()=>L({target:e,index:t}),children:[(0,U.jsx)(a,{className:`h-4 w-4 sm:mr-1.5`}),(0,U.jsx)(`span`,{className:`hidden sm:inline`,children:`Browse`})]}),z=ft(w?.conditions||[]),B=!!w?.conditions.some(e=>[`path`,`pathExact`,`eventPathExact`].includes(e.field)&&e.value.trim()),qe=e=>`${e.address}${e.address===`workspace:data`?` — managed blob store (default)`:e.address===`workspace:home`?` — workspace home folder`:e.driver?` — ${e.driver}`:``}`,V=(e,t,n,r=`workspace:home`)=>M.length?(0,U.jsxs)(`select`,{className:X,value:e,onChange:e=>t(e.target.value),children:[(0,U.jsx)(`option`,{value:``,children:n}),M.map(e=>(0,U.jsx)(`option`,{value:e.address,children:qe(e)},e.address)),e&&!M.some(t=>t.address===e)&&(0,U.jsx)(`option`,{value:e,children:e})]}):(0,U.jsx)(x,{className:y(Z,`font-mono`),placeholder:r,value:e,onChange:e=>t(e.target.value)}),Ye=v.filter(xt),H=v.filter(e=>!xt(e)),Ze=({rule:e})=>{let t=e.enabled!==!1,r=ht(e)!==null,i=S[e.id],a=ot(e.then?.[0]?.action||`link`),o=Ce(e);return(0,U.jsxs)(`div`,{className:y(`rule-card rounded-xl border bg-card p-4 transition-opacity`,!t&&`opacity-60`),children:[(0,U.jsx)(kt,{icon:a.icon,tone:a.tone}),(0,U.jsxs)(`div`,{className:`rule-card-content min-w-0 space-y-1.5`,children:[(0,U.jsxs)(`div`,{className:`flex flex-wrap items-center gap-x-2 gap-y-1`,children:[(0,U.jsx)(`h3`,{className:`text-base font-semibold leading-6`,children:e.description||e.id}),e.approval===!0&&(0,U.jsx)(`span`,{className:`rounded-full bg-warning/15 px-2 py-0.5 text-xs font-medium text-warning`,children:`needs approval`}),e.cascade===!0&&(0,U.jsx)(`span`,{className:`rounded-full bg-muted px-2 py-0.5 text-xs text-muted-foreground`,children:`incl. automation-created`}),!r&&(0,U.jsx)(`span`,{className:`rounded-full bg-muted px-2 py-0.5 text-xs text-muted-foreground`,title:`This rule uses matchers the builder cannot show; edit it as JSON.`,children:`JSON only`})]}),(0,U.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:_t(e,Ae)}),(0,U.jsxs)(`p`,{className:`flex items-start gap-1.5 text-sm`,children:[(0,U.jsx)(ne,{className:`mt-1 h-3.5 w-3.5 shrink-0 text-muted-foreground`}),(0,U.jsx)(`span`,{children:bt(e)})]}),o.length>0&&(0,U.jsx)(`p`,{className:`truncate font-mono text-xs text-muted-foreground`,title:o.join(` | `),children:o.join(` | `)}),(0,U.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:i?(0,U.jsxs)(`button`,{type:`button`,className:y(`text-left underline-offset-2 hover:underline`,i.last.status===`error`&&`text-destructive`,!n&&`cursor-default hover:no-underline`),title:n?`Show this rule's run log`:i.last.error||i.last.skipReason||``,onClick:()=>n?.(e.id),children:[`ran `,i.count,`×`,i.errors?` (${i.errors} failed)`:``,` · last `,i.last.status,` `,Ct(i.last.ts)]}):`not run yet`})]}),(0,U.jsxs)(`div`,{className:`rule-card-actions`,children:[(0,U.jsx)(`button`,{type:`button`,role:`switch`,"aria-checked":t,disabled:k,title:t?`Enabled — click to pause`:`Paused — click to enable`,onClick:()=>Pe(e.id),className:y(`mr-1 inline-flex h-6 w-11 items-center rounded-full p-0.5 transition-colors`,t?`bg-primary`:`bg-muted-foreground/30`),children:(0,U.jsx)(`span`,{className:y(`h-5 w-5 rounded-full bg-background shadow transition-transform`,t&&`translate-x-5`)})}),(0,U.jsxs)(b,{size:`sm`,variant:`ghost`,className:`h-9 px-2.5`,title:e.when.eventPathExact===void 0?`Apply this rule to existing items (dry-run first)`:`Requires an original insert/link event. Current folder membership cannot reconstruct its destination.`,disabled:Ie!==null||e.when.eventPathExact!==void 0,onClick:()=>ze(e.id),children:[Ie===e.id?(0,U.jsx)(g,{className:`h-4 w-4 animate-spin`}):(0,U.jsx)(s,{className:`h-4 w-4`}),(0,U.jsx)(`span`,{className:`rule-card-action-label ml-1.5`,children:`Apply`})]}),(0,U.jsxs)(b,{size:`sm`,variant:`ghost`,className:`h-9 px-2.5`,title:r?`Edit rule`:`Edit as JSON`,onClick:()=>Ve(e),children:[r?(0,U.jsx)(f,{className:`h-4 w-4`}):(0,U.jsx)(m,{className:`h-4 w-4`}),(0,U.jsx)(`span`,{className:`rule-card-action-label ml-1.5`,children:`Edit`})]}),(0,U.jsx)(b,{size:`sm`,variant:`ghost`,className:`h-9 px-2.5 text-destructive hover:text-destructive`,title:`Delete rule`,onClick:()=>Fe(e.id),children:(0,U.jsx)(p,{className:`h-4 w-4`})})]})]})},Qe=(0,U.jsxs)(`div`,{className:`space-y-3`,children:[(0,U.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,U.jsx)(`h3`,{className:`text-base font-semibold`,children:`What should happen automatically?`}),D&&(0,U.jsxs)(b,{size:`sm`,variant:`ghost`,onClick:()=>O(!1),children:[(0,U.jsx)(o,{className:`mr-1 h-4 w-4`}),` Close`]})]}),(0,U.jsx)(`div`,{className:`grid min-w-0 grid-cols-[repeat(auto-fill,minmax(min(100%,17rem),1fr))] gap-3`,children:dt.map(e=>(0,U.jsxs)(`button`,{type:`button`,onClick:()=>Be(e),className:`flex min-w-0 items-start gap-3 rounded-xl border bg-card p-4 text-left transition-colors hover:border-primary/50 hover:bg-accent/40`,children:[(0,U.jsx)(kt,{icon:e.icon,tone:e.tone,size:`lg`}),(0,U.jsxs)(`span`,{className:`min-w-0`,children:[(0,U.jsx)(`span`,{className:`block text-base font-semibold leading-6`,children:e.title}),(0,U.jsx)(`span`,{className:`mt-1 block break-words text-sm leading-relaxed text-muted-foreground`,children:e.blurb})]})]},e.id))})]});return(0,U.jsxs)(`div`,{className:`rule-builder min-w-0 space-y-5`,children:[!d&&(0,U.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-3`,children:[(0,U.jsxs)(`div`,{className:`min-w-0 flex-[1_1_20rem]`,children:[(0,U.jsx)(`h2`,{className:`text-lg font-semibold`,children:`Rules`}),(0,U.jsxs)(`p`,{className:`text-sm text-muted-foreground`,children:[`Rules run automatically as items arrive or get filed — no code needed. Stored in`,` `,(0,U.jsx)(`span`,{className:`font-mono`,children:`rules.json`}),` in the workspace git.`]})]}),(0,U.jsxs)(`div`,{className:`flex shrink-0 gap-2`,children:[t&&(0,U.jsxs)(b,{variant:`ghost`,onClick:t,title:`Edit rules.json directly`,children:[(0,U.jsx)(m,{className:`mr-1.5 h-4 w-4`}),` JSON`]}),(0,U.jsxs)(b,{onClick:()=>{E(null),O(!0)},disabled:D,children:[(0,U.jsx)(c,{className:`mr-1.5 h-4 w-4`}),` New rule`]})]})]}),D&&!w&&Qe,w&&(0,U.jsxs)(`div`,{ref:Se,className:`scroll-mt-4 space-y-6 rounded-xl border bg-card p-4 sm:p-6`,children:[(0,U.jsxs)(`div`,{className:`flex items-center justify-between gap-3`,children:[(0,U.jsx)(`h3`,{className:`text-lg font-semibold`,children:w.id?`Edit rule`:`New rule`}),(0,U.jsxs)(b,{variant:`ghost`,size:`sm`,onClick:()=>E(null),children:[(0,U.jsx)(o,{className:`mr-1 h-4 w-4`}),` Cancel`]})]}),(0,U.jsx)(Q,{label:`Name`,hint:`Shown in the list and the run log.`,children:(0,U.jsx)(x,{className:`h-11 text-base`,placeholder:`Keep UI designs in Projects/Canvas/UI`,value:w.description,onChange:e=>F(`description`,e.target.value)})}),(0,U.jsxs)(`section`,{className:`space-y-4`,children:[(0,U.jsx)(Ot,{step:1,title:`When…`,hint:`What the rule reacts to. All conditions must match; repeat a condition for either/or.`}),(0,U.jsxs)(`div`,{className:`grid gap-4 sm:grid-cols-[minmax(0,220px)_1fr]`,children:[(0,U.jsx)(Q,{label:`Item`,children:(0,U.jsxs)(`select`,{className:X,value:w.schema,onChange:e=>F(`schema`,e.target.value),children:[Ae.map(e=>(0,U.jsx)(`option`,{value:e.value,children:e.label},e.value)),w.schema&&!Ae.some(e=>e.value===w.schema)&&(0,U.jsx)(`option`,{value:w.schema,children:w.schema.replace(/^data\/schema\//,``)})]})}),(0,U.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,U.jsxs)(`span`,{className:`text-sm font-medium`,children:[`Event `,(0,U.jsx)(`span`,{className:`font-normal text-muted-foreground`,children:`(any of)`})]}),(0,U.jsx)(`div`,{className:`flex flex-wrap gap-2`,children:tt.map(e=>{let t=w.events.includes(e.value);return(0,U.jsx)(Dt,{active:t,title:e.hint,onClick:()=>{let n=t?w.events.filter(t=>t!==e.value):[...w.events,e.value];n.length&&F(`events`,n)},children:e.label},e.value)})})]})]}),w.conditions.length>0&&(0,U.jsx)(`div`,{className:`space-y-2`,children:w.conditions.map((e,t)=>{let n=nt.find(t=>t.key===e.field);return(0,U.jsxs)(`div`,{className:`grid grid-cols-[2.25rem_1fr_auto] items-center gap-2 sm:grid-cols-[2.25rem_minmax(0,240px)_1fr_auto]`,children:[(0,U.jsx)(`span`,{className:`text-xs font-medium uppercase tracking-wide text-muted-foreground`,title:`Same condition again = either may match (OR); different conditions must all match (AND)`,children:w.conditions.slice(0,t).some(t=>it(t.field)===it(e.field))?`or`:`and`}),(0,U.jsx)(`select`,{className:X,value:e.field,onChange:e=>F(`conditions`,w.conditions.map((n,r)=>r===t?{...n,field:e.target.value}:n)),children:nt.map(e=>(0,U.jsx)(`option`,{value:e.key,children:e.label},e.key))}),(0,U.jsxs)(`div`,{className:`order-4 col-span-3 flex gap-2 sm:order-3 sm:col-span-1`,children:[(0,U.jsx)(x,{className:y(Z,`font-mono`),placeholder:n?.hint,value:e.value,onChange:e=>F(`conditions`,w.conditions.map((n,r)=>r===t?{...n,value:e.target.value}:n))}),[`path`,`pathExact`,`eventPathExact`].includes(e.field)&&R(`condition`,t,`Browse the workspace trees`)]}),(0,U.jsx)(b,{size:`sm`,variant:`ghost`,className:`order-3 h-10 w-10 p-0 text-muted-foreground sm:order-4`,title:`Remove condition`,onClick:()=>F(`conditions`,w.conditions.filter((e,n)=>n!==t)),children:(0,U.jsx)(o,{className:`h-4 w-4`})})]},t)})}),(0,U.jsxs)(`div`,{className:`flex flex-wrap items-center gap-3`,children:[(0,U.jsxs)(b,{size:`sm`,variant:`outline`,onClick:()=>F(`conditions`,[...w.conditions,{field:w.schema===`email`?`from`:`path`,value:``}]),children:[(0,U.jsx)(c,{className:`mr-1 h-4 w-4`}),` Add condition`]}),(0,U.jsxs)(`span`,{className:`text-xs text-muted-foreground`,children:[`Contains matches literal text. Regex is case-insensitive: enter the pattern without /…/ delimiters; | stays part of the expression. For other filters, separate alternatives with `,(0,U.jsx)(`span`,{className:`font-mono`,children:`|`}),`, e.g. `,(0,U.jsx)(`span`,{className:`font-mono`,children:`image/* | video/*`}),`.`]})]})]}),(0,U.jsxs)(`section`,{className:`space-y-4`,children:[(0,U.jsx)(Ot,{step:2,title:`Then…`,hint:`Actions run in order. The item keeps its id, tags and folders unless an action says otherwise.`}),w.actions.map((t,n)=>{let r=e=>F(`actions`,w.actions.map((t,r)=>r===n?{...t,...e}:t)),i=M.find(e=>e.address===t.a),a=i?.capabilities?.paths===!0,s=z&&a,c=ot(t.kind),l=n=>(0,U.jsxs)(`div`,{className:`space-y-3 rounded-lg border border-dashed p-3`,children:[(0,U.jsxs)(`p`,{className:`text-sm font-medium`,children:[`What to do with the `,n]}),(0,U.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[(0,U.jsx)(Q,{label:`Save as a note at`,hint:`Context path by default, dir:/path for the directory tree.`,children:(0,U.jsx)(he,{inputClassName:Z,placeholder:`/notes/summaries (optional)`,value:t.notePath,onChange:e=>r({notePath:e}),fixedWorkspaceName:e,pickerTitle:`Save note under…`,onPickTarget:(e,t)=>r({notePath:t.treeType===`directory`?`dir:${e}`:e})})}),t.notePath.trim()&&(0,U.jsx)(Q,{label:`Note title`,children:(0,U.jsx)(x,{className:Z,placeholder:`Summary: {{doc.data.subject}}`,value:t.noteTitle,onChange:e=>r({noteTitle:e.target.value})})}),(0,U.jsx)(Q,{label:`Save as a file at`,hint:`Relative path under the workspace home folder or in the data blob store.`,children:(0,U.jsx)(x,{className:y(Z,`font-mono`),placeholder:`logs/agent.log (optional)`,value:t.filePath,onChange:e=>r({filePath:e.target.value})})}),t.filePath.trim()&&(0,U.jsxs)(U.Fragment,{children:[(0,U.jsx)(Q,{label:`File lives in`,children:(0,U.jsxs)(`select`,{className:X,value:t.fileBackend,onChange:e=>r({fileBackend:e.target.value}),children:[(0,U.jsx)(`option`,{value:`home`,children:`the workspace home folder`}),(0,U.jsx)(`option`,{value:`data`,children:`the data blob store`})]})}),(0,U.jsx)(Q,{label:`Also file the saved file under`,hint:`Index it as a document at this tree path.`,children:(0,U.jsx)(he,{inputClassName:Z,placeholder:`/path (optional)`,value:t.fileInsert,onChange:e=>r({fileInsert:e}),fixedWorkspaceName:e,tabs:[`context`],pickerTitle:`File under…`,onPickTarget:e=>r({fileInsert:e})})})]})]}),(0,U.jsx)($,{checked:t.notifyReply,onChange:e=>r({notifyReply:e}),label:`Send me a notification with the result`})]}),u=Y(w.conditions),d=t.kind===`store`&&t.a&&(!t.recursive||s)?pt(t,w.conditions,i):null,f=t.kind===`extractAttachments`&&t.a?Ke(t.a,t.storeFolder,t.attachmentPath):null;return(0,U.jsxs)(`div`,{className:`space-y-4 rounded-xl border bg-background p-4`,children:[(0,U.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,U.jsx)(kt,{icon:c.icon,tone:c.tone}),(0,U.jsx)(`select`,{className:y(X,`flex-1 font-medium`),value:t.kind,onChange:e=>r(K(e.target.value)),children:at.map(e=>(0,U.jsx)(`option`,{value:e.key,children:e.label},e.key))}),(0,U.jsx)(b,{size:`sm`,variant:`ghost`,className:`h-10 w-10 shrink-0 p-0 text-muted-foreground`,title:`Remove action`,disabled:w.actions.length===1,onClick:()=>F(`actions`,w.actions.filter((e,t)=>t!==n)),children:(0,U.jsx)(o,{className:`h-4 w-4`})})]}),(t.kind===`link`||t.kind===`unlink`)&&(0,U.jsxs)(`div`,{className:`space-y-3`,children:[(0,U.jsx)(Q,{label:t.kind===`link`?`Folder(s)`:`Remove from folder(s)`,hint:`Context-tree path by default; dir:/path for the directory tree. Comma-separate several.`,children:(0,U.jsxs)(`div`,{className:`flex gap-2`,children:[(0,U.jsx)(x,{className:y(Z,`font-mono`),placeholder:t.kind===`link`?`/work/urgent or dir:/projects/x`:`/inbox or dir:/staging`,value:t.a,onChange:e=>r({a:e.target.value})}),R(`action`,n)]})}),t.kind===`link`&&(0,U.jsx)(Q,{label:`Tags`,hint:`Optional, comma-separated.`,children:(0,U.jsx)(x,{className:y(Z,`font-mono`),placeholder:`custom/design, ui`,value:t.b,onChange:e=>r({b:e.target.value})})}),(0,U.jsx)($,{checked:t.recursive,onChange:e=>r({recursive:e}),label:`Recreate sub-folder path in destination`,hint:B?`The part of the item's path below the "is under the folder" prefix is appended to the target: …/foo/a/b → target/a/b.`:`Needs an "is under the folder" condition to know where sub-folders start.`,disabled:!B})]}),t.kind===`moveMessage`&&(0,U.jsxs)(`div`,{className:`space-y-2`,children:[(0,U.jsx)(Q,{label:`Mail folder`,hint:`The folder on the email's own IMAP account, with / between levels (works for servers that use . too). {{YYYY}}, {{MM}}, {{DD}} = the email's date.`,children:(0,U.jsx)(x,{className:y(Z,`font-mono`),placeholder:`INBOX/Accounting/{{YYYY}}/Expenses`,value:t.a,onChange:e=>r({a:e.target.value})})}),(0,U.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`Moves the message on the mail server, like dragging it in a mail client. Put this after Extract attachments so the files are copied first. The folder must already exist on the server; subscribe to it in the mailbox settings to see the moved mail in Canvas.`})]}),t.kind===`tag`&&(0,U.jsx)(Q,{label:`Tags`,hint:`Comma-separated.`,children:(0,U.jsx)(x,{className:y(Z,`font-mono`),placeholder:`urgent, follow-up`,value:t.a,onChange:e=>r({a:e.target.value})})}),t.kind===`store`&&(0,U.jsxs)(`div`,{className:`space-y-4`,children:[(0,U.jsxs)(`div`,{className:`grid gap-4 sm:grid-cols-2`,children:[(0,U.jsx)(Q,{label:`Storage backend`,hint:`Where the file's bytes should live. Only writable backends are listed.`,children:V(t.a,e=>r({a:e}),`pick a backend…`)}),(0,U.jsx)(Q,{label:`Destination root folder`,hint:`Choose the folder beneath which the path will be recreated. Leave empty to use the backend root.`,children:(0,U.jsxs)(`div`,{className:`flex gap-2`,children:[(0,U.jsx)(x,{className:y(Z,`font-mono`),placeholder:`Projects/Canvas/UI`,value:t.storeFolder,onChange:e=>r({storeFolder:e.target.value})}),R(`storeFolder`,n,`Browse storage backends`)]})}),(0,U.jsx)(Q,{label:`File name`,children:(0,U.jsx)(`select`,{className:X,value:t.storeName,onChange:e=>r({storeName:e.target.value}),children:ct.map(e=>(0,U.jsx)(`option`,{value:e.value,children:e.label},e.value))})}),(0,U.jsx)(Q,{label:`Move or copy`,hint:t.storeMode===`move`?`Remove only the selected source copy after the destination is safely stored.`:`Preserve every existing copy.`,children:(0,U.jsx)(Et,{value:t.storeMode,onChange:e=>r({storeMode:e}),options:[{value:`copy`,label:`Copy`},{value:`move`,label:`Move`}]})}),t.storeMode===`move`&&(0,U.jsx)(Q,{className:`sm:col-span-2`,label:`Move bytes from (required)`,hint:`Context membership does not identify a source copy. If the file is absent here, nothing is moved. Multiple locations on this backend make the move ambiguous; use copy.`,children:V(t.storeFrom,e=>r({storeFrom:e}),`choose a source backend…`,`workspace:data`)}),t.storeName===`custom`&&(0,U.jsx)(Q,{className:`sm:col-span-2`,label:`Name template`,hint:`Tokens: {{YYYY}} {{MM}} {{DD}} {{HH}} {{mm}} {{ss}} (photo capture time when present), {{ext}} {{basename}} {{filename}} {{title}} {{id}}, plus {{doc.…}} fields. Slashes create sub-folders.`,children:(0,U.jsx)(x,{className:y(Z,`font-mono`),placeholder:`{{YYYY}}-{{MM}}-{{DD}} {{title}}{{ext}}`,value:t.b,onChange:e=>r({b:e.target.value})})})]}),(0,U.jsx)($,{checked:t.recursive,onChange:e=>r({recursive:e}),label:u===null?`Recreate sub-folder path in destination`:`Recreate directory path in destination`,hint:a?z?u===null?`The path below the source folder is appended beneath the destination root: …/UI/mobile → Root/mobile. Missing destination folders are created.`:`Only inserts or links directly into ctx:${u} trigger this rule. Its full path is appended beneath the destination root; descendant inserts do not match.`:`For Context, choose one folder with “is inserted / linked directly into”. Directory and Backends sources can include sub-folders.`:`Choose a destination that reports support for folder paths. Content-addressed blob stores cannot recreate sub-folder paths.`,disabled:!s&&!t.recursive}),d&&(0,U.jsxs)(`div`,{className:`space-y-1.5 rounded-lg bg-muted/60 px-3 py-3 text-sm`,"aria-live":`polite`,children:[(0,U.jsx)(`p`,{className:`font-medium`,children:`Destination preview`}),(0,U.jsxs)(`p`,{className:`text-xs text-muted-foreground`,children:[`Root folder: `,(0,U.jsxs)(`span`,{className:`break-all font-mono`,children:[d.root,`/`]})]}),t.recursive&&(0,U.jsxs)(`p`,{className:`text-xs text-muted-foreground`,children:[`Path added beneath it: `,(0,U.jsxs)(`span`,{className:`break-all font-mono`,children:[d.recreated||`(root)`,`/`]})]}),(0,U.jsx)(`p`,{className:`break-all font-mono`,children:d.result})]}),(0,U.jsxs)(`details`,{className:`group rounded-lg border`,children:[(0,U.jsxs)(`summary`,{className:`flex cursor-pointer select-none items-center gap-2 px-3 py-2 text-sm font-medium`,children:[(0,U.jsx)(ee,{className:`h-4 w-4 transition-transform group-open:rotate-180`}),` More options`]}),(0,U.jsxs)(`div`,{className:`grid gap-4 border-t p-3 sm:grid-cols-2`,children:[t.storeMode===`copy`&&(0,U.jsx)(Q,{label:`Copy bytes from`,hint:`Optional source restriction. Default: any readable copy outside the destination backend.`,children:V(t.storeFrom,e=>r({storeFrom:e}),`any readable source`,`workspace:data (optional)`)}),(0,U.jsx)(Q,{label:`If the name is already taken`,children:(0,U.jsxs)(`select`,{className:X,value:t.storeConflict,onChange:e=>r({storeConflict:e.target.value}),children:[(0,U.jsx)(`option`,{value:`rename`,children:`add -1, -2, … to the name`}),(0,U.jsx)(`option`,{value:`error`,children:`skip the file`}),(0,U.jsx)(`option`,{value:`overwrite`,children:`overwrite the existing file`})]})})]})]}),(0,U.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`The item keeps its id and virtual tree memberships. A move removes the chosen physical source location from the backend tree.`})]}),t.kind===`extractAttachments`&&(0,U.jsxs)(`div`,{className:`space-y-4`,children:[(0,U.jsxs)(`div`,{className:`grid gap-4 sm:grid-cols-2`,children:[(0,U.jsx)(Q,{label:`Attachment types`,hint:`MIME types, comma-separated. application/pdf for PDFs, image/* for images, or * for all.`,children:(0,U.jsx)(x,{className:y(Z,`font-mono`),placeholder:`application/pdf`,value:t.attachmentMime,onChange:e=>r({attachmentMime:e.target.value})})}),(0,U.jsx)(Q,{label:`Attachment filename contains`,hint:`Optional: invoice, faktura, or another literal filename fragment. Every selected attachment must also match its type.`,children:(0,U.jsx)(x,{className:Z,placeholder:`Any matching filename`,value:t.attachmentName,onChange:e=>r({attachmentName:e.target.value})})}),(0,U.jsx)(Q,{label:`Storage backend`,hint:`Choose a writable backend that supports folder paths.`,children:V(t.a,e=>r({a:e}),`pick a backend…`)}),(0,U.jsx)(Q,{label:`Destination root folder`,hint:`Choose the folder beneath which date subfolders will be created. Leave empty to use the backend root.`,children:(0,U.jsxs)(`div`,{className:`flex gap-2`,children:[(0,U.jsx)(x,{className:y(Z,`font-mono`),placeholder:`Accounting`,value:t.storeFolder,onChange:e=>r({storeFolder:e.target.value})}),R(`storeFolder`,n,`Browse storage backends`)]})}),(0,U.jsx)(Q,{label:`Sub-folder path template`,hint:`Appended beneath the root folder. {{YYYY}} = year, {{MM}} = month, {{DD}} = day of the email. Leave empty to file directly in the root folder.`,children:(0,U.jsx)(x,{className:y(Z,`font-mono`),placeholder:`No subfolders`,value:t.attachmentPath,onChange:e=>r({attachmentPath:e.target.value})})}),(0,U.jsx)(Q,{label:`If the attachment name is already taken`,children:(0,U.jsxs)(`select`,{className:X,value:t.storeConflict,onChange:e=>r({storeConflict:e.target.value}),children:[(0,U.jsx)(`option`,{value:`rename`,children:`add -1, -2, … to the name`}),(0,U.jsx)(`option`,{value:`error`,children:`skip the file and report the conflict`})]})})]}),!a&&(0,U.jsx)(`p`,{className:`text-sm text-amber-700 dark:text-amber-400`,children:`This destination has not reported support for folder paths. Select a supported backend before saving.`}),f&&(0,U.jsxs)(`div`,{className:`space-y-1.5 rounded-lg bg-muted/60 px-3 py-3 text-sm`,"aria-live":`polite`,children:[(0,U.jsx)(`p`,{className:`font-medium`,children:`Destination preview`}),(0,U.jsxs)(`p`,{className:`text-xs text-muted-foreground`,children:[`Example email dated `,f.date,`. Each email supplies its own date.`]}),(0,U.jsxs)(`p`,{className:`text-xs text-muted-foreground`,children:[`Root folder: `,(0,U.jsxs)(`span`,{className:`break-all font-mono`,children:[f.root,`/`]})]}),(0,U.jsxs)(`p`,{className:`text-xs text-muted-foreground`,children:[`Path added beneath it: `,(0,U.jsx)(`span`,{className:`break-all font-mono`,children:f.added?`${f.added}/`:`(none)`})]}),(0,U.jsx)(`p`,{className:`break-all font-mono`,children:f.result})]}),(0,U.jsx)($,{checked:t.includeInline,onChange:e=>r({includeInline:e}),label:`Include inline attachments`,hint:`Off by default, so signature images and embedded resources are excluded.`}),(0,U.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`Copies matching attachments and keeps the email and its original files. Missing folders are created on the backend. Dates use the email's sent date (received/content date, then creation date if absent), in the server's timezone. This does not read the invoice date from the PDF.`}),(0,U.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`Use Apply on the saved rule to process existing mail within the selected batch size. Add a subject or attachment filename condition if you need to distinguish invoices from other PDFs.`})]}),t.kind===`download`&&(0,U.jsxs)(`div`,{className:`space-y-4`,children:[(0,U.jsxs)(`div`,{className:`grid gap-4 sm:grid-cols-2`,children:[(0,U.jsx)(Q,{label:`Download`,hint:G.find(e=>e.value===t.dlKind)?.hint,children:(0,U.jsx)(`select`,{className:X,value:t.dlKind,onChange:e=>r({dlKind:e.target.value}),children:G.map(e=>(0,U.jsx)(`option`,{value:e.value,children:e.label},e.value))})}),t.dlKind===`website`?(0,U.jsx)(Q,{label:`Mirror depth`,hint:`How many link hops to follow on the same site (1–5).`,children:(0,U.jsx)(x,{type:`number`,min:1,max:5,className:y(Z,`sm:max-w-32`),value:t.dlDepth,onChange:e=>r({dlDepth:e.target.value})})}):(0,U.jsx)(`div`,{className:`hidden sm:block`}),(0,U.jsx)(Q,{label:`Storage backend`,hint:`Where the downloaded file's bytes should live.`,children:V(t.a,e=>r({a:e}),`workspace:home (default)`)}),(0,U.jsx)(Q,{label:`Folder on that backend`,hint:`Relative to the backend root.`,children:(0,U.jsxs)(`div`,{className:`flex gap-2`,children:[(0,U.jsx)(x,{className:y(Z,`font-mono`),placeholder:`Downloads`,value:t.storeFolder,onChange:e=>r({storeFolder:e.target.value})}),R(`storeFolder`,n,`Browse storage backends`)]})}),(0,U.jsx)(Q,{label:`File the download under`,hint:`Leave empty to file it in the same folder(s) as the link. Comma-separate several.`,children:(0,U.jsxs)(`div`,{className:`flex gap-2`,children:[(0,U.jsx)(x,{className:y(Z,`font-mono`),placeholder:`same folders as the link`,value:t.b,onChange:e=>r({b:e.target.value})}),R(`action`,n)]})}),(0,U.jsx)(Q,{label:`Tags for the download`,hint:`Optional, comma-separated.`,children:(0,U.jsx)(x,{className:y(Z,`font-mono`),placeholder:`downloaded, custom/paper`,value:t.dlTags,onChange:e=>r({dlTags:e.target.value})})})]}),(0,U.jsx)($,{checked:t.recursive,onChange:e=>r({recursive:e}),label:`Recreate sub-folder path in destination`,hint:B?`A link filed under …/folder/a/b is downloaded into Folder/a/b.`:`Add an "is under the folder" condition to mirror sub-folders.`,disabled:!B}),(0,U.jsxs)(`p`,{className:`text-xs text-muted-foreground`,children:[`The link stays as it is; the download becomes a new file item next to it. Each link is downloaded once per rule. Videos need `,(0,U.jsx)(`span`,{className:`font-mono`,children:`yt-dlp`}),`, pages and websites `,(0,U.jsx)(`span`,{className:`font-mono`,children:`wget`}),` on the server.`]})]}),t.kind===`unstore`&&(0,U.jsxs)(`div`,{className:`space-y-4`,children:[(0,U.jsxs)(`div`,{className:`grid gap-4 sm:grid-cols-2`,children:[(0,U.jsx)(Q,{label:`Delete the file from`,children:V(t.a,e=>r({a:e}),`pick a backend…`,`workspace:data`)}),(0,U.jsx)(Q,{label:`…but only once it is also on`,hint:`Safety: the copy is dropped only after another backend holds the file.`,children:V(t.b,e=>r({b:e}),`anywhere else`,`workspace:home (optional)`)})]}),(0,U.jsx)($,{checked:t.keepLast,onChange:e=>r({keepLast:e}),label:`Never delete the last copy`,hint:`Off means the rule may delete the only remaining copy of a file. Leave it on unless you mean exactly that.`}),(0,U.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`Deletes the stored bytes on that backend only — copies elsewhere and the item itself are kept.`})]}),t.kind===`sendFile`&&(0,U.jsxs)(`div`,{className:`space-y-4`,children:[(0,U.jsx)(Q,{label:`Files to send`,children:(0,U.jsxs)(`select`,{className:X,value:t.sendSource,onChange:e=>r({sendSource:e.target.value}),children:[(0,U.jsx)(`option`,{value:`document`,children:`The file that triggered this rule`}),(0,U.jsx)(`option`,{value:`attachments`,children:`Matching attachments from the email`}),(0,U.jsx)(`option`,{value:`download`,children:`Files from an earlier Download action`})]})}),t.sendSource===`attachments`&&(0,U.jsxs)(`div`,{className:`grid gap-4 sm:grid-cols-2`,children:[(0,U.jsx)(Q,{label:`Attachment types`,hint:`application/pdf for invoices; * for all files.`,children:(0,U.jsx)(x,{className:Z,value:t.attachmentMime,onChange:e=>r({attachmentMime:e.target.value})})}),(0,U.jsx)(Q,{label:`Attachment filename contains`,hint:`Optional literal filename fragment.`,children:(0,U.jsx)(x,{className:Z,placeholder:`invoice`,value:t.attachmentName,onChange:e=>r({attachmentName:e.target.value})})})]}),t.sendSource===`attachments`&&(0,U.jsx)($,{checked:t.includeInline,onChange:e=>r({includeInline:e}),label:`Include inline attachments`,hint:`Signature images are excluded by default.`}),(0,U.jsx)(Q,{label:`Sending account`,hint:`Enable sending for the account in Connected services.`,children:(0,U.jsxs)(`select`,{className:X,value:t.a?`${t.sendDriver}:${t.a}`:``,onChange:e=>{let t=ve.find(t=>`${t.driver}:${t.address}`===e.target.value);t&&r({a:t.address,sendDriver:t.driver,b:``})},children:[(0,U.jsx)(`option`,{value:``,disabled:!0,children:`Choose email, WhatsApp or Slack…`}),t.a&&!ve.some(e=>e.driver===t.sendDriver&&e.address===t.a)&&(0,U.jsxs)(`option`,{value:`${t.sendDriver}:${t.a}`,disabled:!0,children:[t.sendDriver,`: `,t.a,` (unavailable)`]}),ve.map(e=>(0,U.jsxs)(`option`,{value:`${e.driver}:${e.address}`,disabled:!e.canSend,children:[e.driver===`imap`?`Email (SMTP)`:e.driver===`whatsapp`?`WhatsApp`:`Slack`,` · `,e.from||e.address,e.canSend?``:` — sending disabled`]},`${e.driver}:${e.address}`))]})}),be&&(0,U.jsx)(`p`,{className:`text-xs text-destructive`,role:`status`,children:be}),(0,U.jsx)(Q,{label:t.sendDriver===`imap`?`Destination email address`:`Destination conversation`,hint:t.sendDriver===`imap`?`The accounting ingestion address; separate multiple recipients with commas.`:t.sendDriver===`slack`?`A configured Slack channel ID or name. The account needs files:write permission.`:`A configured WhatsApp chat ID, e.g. 421…@s.whatsapp.net or …@g.us.`,children:(0,U.jsx)(x,{className:Z,value:t.b,placeholder:t.sendDriver===`imap`?`invoices@accounting-firm.example`:t.sendDriver===`slack`?`C0123456789`:`421…@s.whatsapp.net`,onChange:e=>r({b:e.target.value})})}),t.sendDriver===`imap`&&(0,U.jsx)(Q,{label:`Email subject`,hint:`{{file.name}} inserts the attachment filename.`,children:(0,U.jsx)(x,{className:Z,value:t.sendSubject,onChange:e=>r({sendSubject:e.target.value})})}),(0,U.jsx)(Q,{label:t.sendDriver===`imap`?`Email body (optional)`:`Message / caption (optional)`,hint:`Templates: {{file.name}}, {{doc.data.subject}}, {{doc.data.title}}.`,children:(0,U.jsx)(`textarea`,{className:`min-h-20 w-full rounded-md border bg-background p-3 text-sm`,value:t.sendMessage,onChange:e=>r({sendMessage:e.target.value})})}),(0,U.jsxs)(`div`,{className:`rounded-lg border bg-muted/30 p-3 text-sm`,"aria-label":`File delivery preview`,children:[t.sendSource===`attachments`?`Each matching email attachment`:t.sendSource===`download`?`Each downloaded file`:`The triggering file`,` → `,t.sendDriver===`imap`?`email attachment`:t.sendDriver===`slack`?`Slack file upload`:`WhatsApp document`,` → `,t.b||`choose a destination`]}),(0,U.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`Sends each file in a separate message and keeps the original. Maximum 18 MB per file. Replaying this rule does not resend the same file version to the same destination. Unconfirmed deliveries are recorded for review, not retried automatically.`}),t.sendSource===`document`&&(0,U.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`For files created by another automation, enable this rule’s option to also run on automation events.`})]}),t.kind===`notify`&&(0,U.jsx)(Q,{label:`Notification`,hint:`Notifies you through your bound channel, or in Canvas. Templates: {{doc.data.subject}}, {{doc.data.from}}, {{doc.data.title}}…`,children:(0,U.jsx)(x,{className:Z,placeholder:`New mail from {{doc.data.from}}: {{doc.data.subject}}`,value:t.a,onChange:e=>r({a:e.target.value})})}),t.kind===`delete`&&(0,U.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`Removes the item from the Canvas index. Files, blobs and mail on storage backends stay untouched.`}),t.kind===`destroy`&&(0,U.jsx)(`p`,{className:`rounded-lg border border-destructive/40 bg-destructive/5 p-3 text-sm text-destructive`,children:`⚠ Irreversible: deletes the stored bytes too (blobs, workspace files, mail on the server), then removes the item from the index.`}),t.kind===`agent`&&(0,U.jsxs)(`div`,{className:`space-y-3`,children:[(0,U.jsx)(Q,{label:`Agent`,hint:`The agent's slug.`,children:(0,U.jsx)(x,{className:y(Z,`font-mono sm:max-w-xs`),placeholder:`assistant`,value:t.a,onChange:e=>r({a:e.target.value})})}),(0,U.jsx)(Q,{label:`Prompt`,hint:`Templates use indexed fields: {{doc.id}}, {{doc.data.subject}}, {{doc.data.bodyPreview}} (emails), {{doc.data.url}}… Ask the agent to use canvas_get for full email content. Objects are inserted as JSON.`,children:(0,U.jsx)(`textarea`,{className:`min-h-28 w-full rounded-md border bg-background p-3 text-sm outline-none focus:ring-2 focus:ring-ring`,placeholder:`Read email #{{doc.id}} in full with canvas_get and summarize it in plain markdown.
|
|
4
|
-
|
|
5
|
-
Subject: {{doc.data.subject}}
|
|
6
|
-
Preview: {{doc.data.bodyPreview}}`,value:t.b,onChange:e=>r({b:e.target.value})})}),l(`reply`)]}),t.kind===`script`&&(0,U.jsxs)(`div`,{className:`space-y-3`,children:[(0,U.jsx)(Q,{label:`Script`,hint:`From the Scripts section of this workspace.`,children:ge.length?(0,U.jsxs)(`select`,{className:y(X,`font-mono sm:max-w-md`),value:t.a,onChange:e=>r({a:e.target.value}),children:[(0,U.jsx)(`option`,{value:``,children:`pick a script…`}),ge.map(e=>(0,U.jsx)(`option`,{value:`scripts/${e}`,children:e},e))]}):(0,U.jsx)(x,{className:y(Z,`font-mono sm:max-w-md`),placeholder:`scripts/my-script.sh`,value:t.a,onChange:e=>r({a:e.target.value})})}),l(`output`)]})]},n)}),(0,U.jsxs)(b,{size:`sm`,variant:`outline`,onClick:()=>F(`actions`,[...w.actions,K(`tag`)]),children:[(0,U.jsx)(c,{className:`mr-1 h-4 w-4`}),` Add another action`]})]}),(0,U.jsxs)(`section`,{className:`space-y-3`,children:[(0,U.jsx)(Ot,{step:3,title:`Options`}),(0,U.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[(0,U.jsx)($,{checked:w.approval,onChange:e=>F(`approval`,e),label:`Ask me before running`,hint:`Actions are held in the Pending queue for review — approve (optionally amended) or decline — instead of running automatically.`}),(0,U.jsx)($,{checked:w.cascade,onChange:e=>F(`cascade`,e),label:`Also react to items created by automation`,hint:`Off by default so rules, hooks and agents cannot trigger each other in a loop. A server-side depth limit still stops runaway chains.`})]})]}),(0,U.jsxs)(`div`,{className:`flex flex-wrap gap-2 border-t pt-4`,children:[(0,U.jsxs)(b,{className:`h-10 px-5`,onClick:Ne,disabled:k||de,children:[k?(0,U.jsx)(g,{className:`mr-1.5 h-4 w-4 animate-spin`}):(0,U.jsx)(i,{className:`mr-1.5 h-4 w-4`}),` `,w.id?`Save changes`:`Create rule`]}),(0,U.jsx)(b,{className:`h-10`,variant:`outline`,onClick:()=>{E(null),te?.()},children:`Cancel`})]})]}),I&&(0,U.jsx)(me,{onClose:()=>L(null),children:(0,U.jsx)(ce,{sizeClassName:`h-full w-[380px] max-w-[90vw] max-md:w-full`,fixedWorkspaceName:e,multiple:I.target!==`storeFolder`&&!(I.target===`condition`&&w?.actions.some(e=>e.kind===`store`)),tabs:I.target===`condition`?[`context`,`directory`,`backends`]:I.target===`storeFolder`?[`backends`]:[`context`,`directory`],title:I.target===`condition`?`Choose source folder…`:I.target===`storeFolder`?`Store files under…`:`File into…`,confirmLabel:I.target===`storeFolder`?`Use folder`:`Use path`,onConfirm:Ge,onClose:()=>L(null)})}),!d&&(de?(0,U.jsx)(`p`,{className:`rounded-xl border p-6 text-center text-sm text-muted-foreground`,children:`Loading…`}):v.length===0?!D&&!w&&(0,U.jsxs)(`div`,{className:`space-y-4`,children:[(0,U.jsxs)(`div`,{className:`rounded-xl border border-dashed p-6 text-center`,children:[(0,U.jsx)(`p`,{className:`text-base font-medium`,children:`No rules yet`}),(0,U.jsx)(`p`,{className:`mt-1 text-sm text-muted-foreground`,children:`Pick a starting point below, or right-click a folder in the tree and choose “Create rule…”.`})]}),Qe]}):(0,U.jsxs)(`div`,{className:`space-y-6`,children:[Ye.length>0&&(0,U.jsxs)(`section`,{className:`space-y-3`,children:[(0,U.jsxs)(`div`,{className:`flex flex-wrap items-baseline gap-x-2 gap-y-1 text-sm text-muted-foreground`,children:[(0,U.jsxs)(`h3`,{className:`flex items-center gap-2 font-semibold uppercase tracking-wide`,children:[(0,U.jsx)(ie,{className:`h-4 w-4 shrink-0`}),` Folder & storage rules`]}),(0,U.jsx)(`p`,{children:`Right-click a folder in the tree to add one`})]}),(0,U.jsx)(`div`,{className:`space-y-3`,children:Ye.map(e=>(0,U.jsx)(Ze,{rule:e},e.id))})]}),H.length>0&&(0,U.jsxs)(`section`,{className:`space-y-3`,children:[Ye.length>0&&(0,U.jsxs)(`h3`,{className:`flex items-center gap-2 text-sm font-semibold uppercase tracking-wide text-muted-foreground`,children:[(0,U.jsx)(ae,{className:`h-4 w-4`}),` Other rules`]}),(0,U.jsx)(`div`,{className:`space-y-3`,children:H.map(e=>(0,U.jsx)(Ze,{rule:e},e.id))})]})]}))]})}function jt(e,t){let n=t.split(`/`).filter(Boolean);if(e!==`backends`||n[0]!==`Trash`)return null;try{return{backend:n[1]?decodeURIComponent(n[1]):null,prefix:n.slice(2).join(`/`)}}catch{return null}}function Mt(e,t=``){return`/Trash${e?`/${encodeURIComponent(e)}`:``}${t?`/${t}`:``}`}function Nt(e,t=``){let n=new Map,r=[],i=t?`${t}/`:``;for(let t of e){if(!t.key.startsWith(i))continue;let e=t.key.slice(i.length);if(!e)continue;let a=e.indexOf(`/`);if(a>=0){let r=e.slice(0,a),o=i+r,s=n.get(o)??{id:`folder:${o}`,name:r,key:o,directory:!0,navigable:!0,items:[]};s.items.push(t),n.set(o,s)}else r.push({id:t.id,name:e,key:t.key,directory:t.type===`directory`,navigable:!1,items:[t]})}return[...n.values(),...r].sort((e,t)=>Number(t.directory)-Number(e.directory)||e.name.localeCompare(t.name)||t.items[0].deletedAt-e.items[0].deletedAt||e.id.localeCompare(t.id))}var Pt=(e,t)=>`${oe.workspaces}/${encodeURIComponent(e)}/backends/file/${encodeURIComponent(t)}/trash`;async function Ft(e,t){let n=[],r=new Set,i=null,a=null;do{let o=new URLSearchParams({limit:`1000`,...i?{cursor:i}:{}}),s=await S.get(`${Pt(e,t)}?${o}`);if(n.push(...s.items),a=s.retention?.days??null,i=s.cursor,i&&r.has(i))throw Error(`Trash listing returned a repeated cursor`);i&&r.add(i)}while(i);return{items:n,days:a}}function It(e,t,n){return Rt(e,t,n,`restore`)}function Lt(e,t,n){return Rt(e,t,n,`discard`)}async function Rt(e,t,n,r){let i=[...new Set(n)],a=[];try{for(let n=0;n<i.length;n+=100){let o=await S.post(`${Pt(e,t)}/${r}`,{ids:i.slice(n,n+100)});a.push(...o.results)}return a}finally{fe(e,`backends`),window.dispatchEvent(new CustomEvent(`workspace:tree:refresh`,{detail:{workspaceName:e,treeName:`backends`}})),window.dispatchEvent(new CustomEvent(`workspace:documents:refresh`,{detail:{workspaceName:e}})),window.dispatchEvent(new CustomEvent(`workspace:trash:refresh`,{detail:{workspaceName:e,backend:t}}))}}async function zt(e,t){let n=jt(`backends`,t);if(!n?.backend)return;let{items:r}=await Ft(e,n.backend),i=r.filter(e=>!n.prefix||e.key===n.prefix||e.key.startsWith(`${n.prefix}/`)).sort((e,t)=>t.deletedAt-e.deletedAt),a=await It(e,n.backend,i.map(e=>e.id)),o=a.filter(e=>!e.ok);if(o.length)throw Error(`${a.length-o.length} restored; ${o.length} remain in Trash. Existing paths were kept.`)}function Bt(e,t){if(!t.length)return!1;let n=[...new Set(t.map(e=>e.key))],r=n.slice(0,5).join(`
|
|
7
|
-
`)+(n.length>5?`\n…and ${n.length-5} more paths`:``);return window.confirm(`Permanently delete ${t.length} Trash item(s) from ${e}?\n\n${r}\n\nDeleted folders include all their contents. This cannot be undone. Files currently at the original paths are kept.`)}async function Vt(e,t){let n=jt(`backends`,t);if(!n?.backend)return;let{items:r}=await Ft(e,n.backend),i=r.filter(e=>!n.prefix||e.key===n.prefix||e.key.startsWith(`${n.prefix}/`));if(!Bt(n.backend,i))return;let a=await Lt(e,n.backend,i.map(e=>e.id)),o=a.filter(e=>!e.ok);if(o.length)throw Error(`${a.length-o.length} deleted; ${o.length} remain in Trash. ${o[0].message||o[0].reason||`Please retry.`}`)}var Ht=new Map;function Ut(e,t,n,r,i,a){let o=JSON.stringify([t,n,r,a]),s=Ht.get(o);if(s)return s;let c=(async()=>{let o=e({title:`Resyncing…`,description:r});try{for(a?await de(t,n,r,a):await w(t,n,r);;){let e=await le(t,n,r);i?.(e);let s=a?e.containers?.find(e=>e.name===a):void 0;if(a?s?.status!==`syncing`:!e.resyncing&&e.status!==`syncing`){let i=s?s.lastError:e.lastError;if(i)throw Error(i);o.done({title:e.resyncCancelledAt?`Resync stopped`:`Resync complete`,description:`${r}${n!==`imap`&&e.progress?` · ${e.progress.scanned} files scanned`:``}`}),window.dispatchEvent(new CustomEvent(`workspace:documents:refresh`,{detail:{workspaceName:t,treeName:`backends`}}));return}let c=n===`imap`?void 0:e.progress;o.update({title:`Resyncing…`,description:`${r}${c?` · ${c.scanned}${c.total==null?``:` / ${c.total}`} files scanned`:``}`}),await new Promise(e=>setTimeout(e,2e3))}}catch(e){throw o.fail({title:`Resync needs attention`,description:`${r}: ${e instanceof Error?e.message:String(e)}`,variant:`destructive`}),e}})();return Ht.set(o,c),c.finally(()=>{Ht.get(o)===c&&Ht.delete(o)}).catch(()=>{}),c}export{je as A,I as B,Ee as C,O as D,Fe as E,D as F,Ie as H,ke as I,Me as L,Le as M,ve as N,He as O,_e as P,L as R,Ae as S,Ue as T,be as U,k as V,we as W,Je as _,Ft as a,Re as b,jt as c,At as d,$e as f,Ye as g,Qe as h,Vt as i,xe as j,De as k,Mt as l,Xe as m,Bt as n,It as o,Ze as p,Lt as r,zt as s,Ut as t,Nt as u,P as v,A as w,Pe as x,Ge as y,Te as z};
|
|
@@ -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{Ct as r,Ft as i,G as a,Ht as o,It as s,Jr as c,L as l,Mt as u,St as d,X as f,_n as p,ct as m,ei as h,it as g,mt as _,pn as v,tt as y,vn as b,wr as x,zr as S}from"./ui-BSqPn1LJ.js";import{t as C}from"./utils-2pl1SbIp.js";import{Gn as w,Pn as T,q as E}from"./workspace-CJ1PWQ29.js";import{t as D}from"./TodosWidget-BXF8fYer.js";import{d as O,o as ee,u as te}from"./ObjectPropertiesCard-DDcRLpsW.js";import{h as ne,s as re,t as ie,u as k}from"./document-list-BiogH4tf.js";import{n as ae}from"./use-toolbox-Ck_cLGgf.js";import{t as oe}from"./useToastHelpers-CRrpIIdY.js";import{n as A}from"./color-DFEH4BfK.js";import{t as se}from"./DocumentIcon-BS10SIP6.js";import{t as ce}from"./registry-BgnkvPjl.js";import{t as le}from"./FileForm-BxTixeDm.js";import{t as j}from"./applet-target-DnTa2VAT.js";var M=e(n(),1),N=t();function ue({target:e,children:t}){let[n,r]=(0,M.useState)([]),i=(0,M.useRef)(!1),[a,o]=(0,M.useState)(!1),[s,c]=(0,M.useState)(!1),[l,u]=(0,M.useState)(null),{showErrorToast:d}=oe();return(0,N.jsxs)(`div`,{className:`relative flex flex-col h-full min-h-0 bg-background ${a?`ring-2 ring-inset ring-primary`:``}`,onDragOverCapture:t=>{s||!e||!Array.from(t.dataTransfer.types).includes(`Files`)||(t.preventDefault(),t.stopPropagation(),t.dataTransfer.dropEffect=i.current?`none`:`copy`,o(!i.current))},onDragLeaveCapture:e=>{e.currentTarget.contains(e.relatedTarget)||o(!1)},onDropCapture:t=>{if(s||!e||!Array.from(t.dataTransfer.types).includes(`Files`))return;if(t.preventDefault(),t.stopPropagation(),o(!1),i.current){d(`Wait for the current upload to finish`);return}let n=Array.from(t.dataTransfer.files);if(!n.length){d(`Drop files rather than folders`);return}r(n),u(e),c(!0)},children:[t,a&&(0,N.jsxs)(`div`,{className:`pointer-events-none absolute inset-0 z-30 flex items-center justify-center bg-background/80 text-sm font-medium`,children:[`Drop files to upload to `,e?.mode===`workspace`?e.path:`this context`]}),s&&(0,N.jsxs)(k,{label:`Import files`,onClose:()=>{i.current||c(!1)},children:[(0,N.jsx)(`h2`,{className:`border-b px-4 py-3 text-sm font-medium`,children:`Import files`}),(0,N.jsx)(le,{target:l,initialFiles:n,onClose:()=>c(!1),onBusyChange:e=>{i.current=e}})]})]})}function de({navigationTabs:e,navigationActions:t,onBack:n,accentColor:o,frameContent:c=!0,urlType:l,urlDisplay:u,contextPath:d,treeName:p,workspaceId:m,workspaceLabel:g,workspaceIcon:v,documentSchema:y,documents:x,isLoading:S,totalCount:C,currentPage:w,pageSize:T,onPageChange:E,onPageSizeChange:D,onRemoveDocument:re,onDeleteDocument:k,onDestroyDocument:oe,onRemoveDocuments:A,onDeleteDocuments:se,onDestroyDocuments:ce,onCopyDocuments:le,onCutDocuments:j,onPasteDocuments:de,onImportDocuments:P,onSelectionChange:fe,pastedDocumentIds:F,onPurgeDocuments:pe,disablePurgeDocuments:me,canvasInfo:I,isCanvasPinned:L,onTogglePinCanvas:R,onSaveAsCanvas:z,onShareCanvas:B,onUnshareCanvas:V,onDeleteCanvas:H,isSharingCanvas:U,isDeletingCanvas:W,isCanvasShared:G,isCanvasLocked:he,backendSearchQueries:ge,onBackendSearch:K,onRemoveBackendQuery:_e,serverSort:ve,onServerSortChange:ye,scope:be,onScopeChange:xe,canSaveChanges:Se,isSavingChanges:q,onSaveChanges:J,onBrowseWorkspaces:Ce,onBrowseTree:we,onNavigatePath:Te,linkTree:Ee,children:Y,contentBanner:De,folders:Oe,onOpenFolder:ke}){let Ae=l===`canvas`,X=ne(),{state:je,toggleView:Me,hasActiveFilters:Ne,openAddPicker:Pe}=ae(),Z=ee(),[Fe,Q]=(0,M.useState)(``),$=JSON.stringify([m,p,d,y]),[Ie,Le]=(0,M.useState)($);Ie!==$&&(Le($),Q(``));let Re=(0,N.jsxs)(N.Fragment,{children:[t,z&&(0,N.jsx)(`button`,{type:`button`,onClick:z,title:`Save as canvas`,"aria-label":`Save as canvas`,className:`flex h-control-sm w-control-sm shrink-0 items-center justify-center rounded-md border text-muted-foreground hover:bg-accent touch-target`,children:(0,N.jsx)(h,{className:`h-4 w-4`})})]});return(0,N.jsxs)(ue,{target:P&&m?{mode:`workspace`,workspaceName:m,path:d,treeName:p||`context`,treeType:p===`directory`?`directory`:`context`}:null,children:[e&&!X&&(0,N.jsx)(O,{accentColor:o,children:e}),(0,N.jsxs)(`div`,{className:`canvas-surface-body${c&&!X?` is-framed`:``}`,children:[(0,N.jsx)(te,{workspaceIcon:v,workspace:g||m||u.split(`://`)[0]||`Workspace`,actions:X&&e?(0,N.jsxs)(`details`,{className:`relative shrink-0`,"aria-label":`Canvas views`,children:[(0,N.jsx)(`summary`,{className:`cursor-pointer rounded-md border px-2 py-1 text-xs`,title:`Choose or manage content views`,children:`Views`}),(0,N.jsx)(`div`,{className:`absolute right-0 top-full z-30 mt-2 min-w-64 max-w-[80vw] rounded-md border bg-background p-2 shadow-lg`,children:e})]}):void 0,tree:p?`${p}${l.endsWith(`-layer`)?`:layer`:``}`:l.replace(`-layer`,``),path:d,accentColor:o,onBack:Z.location?Z.location.section===`view`?Z.close:()=>Z.update?.({section:`view`}):n,section:Z.location?`document/${Z.location.documentId}/${Z.location.section}`:void 0,onSection:Z.location?()=>Z.update?.({section:`view`}):void 0,onBrowseWorkspaces:Ce,onBrowseTree:we,onNavigatePath:Te,onFilter:()=>Me(`tools`),filtersActive:Ne,filtersOpen:je.t1Open&&je.t1View===`tools`,onAdd:e=>Pe({modal:e.shiftKey,fresh:!0}),search:K||!Y?{workspaceId:m,queries:ge||[],onSearch:K??Q,localOnly:!K,onRemoveQuery:_e,scope:be,onScopeChange:xe}:void 0,onDraftChange:Y?void 0:Q}),Ae&&I?(0,N.jsx)(N.Fragment,{children:(0,N.jsxs)(`div`,{className:`flex items-center gap-3 px-4 py-2.5 border-b bg-muted/20 shrink-0 min-w-0`,children:[I.color&&(0,N.jsx)(`div`,{className:`w-1 h-6 rounded-full shrink-0`,style:{backgroundColor:I.color}}),(0,N.jsx)(b,{className:`w-4 h-4 shrink-0 text-primary`}),(0,N.jsxs)(`div`,{className:`flex flex-col min-w-0 flex-1`,children:[(0,N.jsx)(`span`,{className:`text-lg font-semibold leading-tight truncate`,children:I.label||u.split(`://`)[1]||`Canvas`}),I.description&&(0,N.jsx)(`span`,{className:`text-xs text-muted-foreground truncate leading-tight`,children:I.description})]}),Se&&J&&(0,N.jsxs)(`button`,{type:`button`,onClick:J,disabled:q,className:`shrink-0 flex items-center gap-1.5 px-2.5 py-1 text-xs border rounded-md hover:bg-accent transition-colors text-muted-foreground hover:text-foreground disabled:opacity-50`,title:`Save filters`,children:[(0,N.jsx)(r,{className:`w-3 h-3`}),(0,N.jsx)(`span`,{className:`hidden sm:inline`,children:q?`Saving...`:`Save filters`})]}),R&&(0,N.jsxs)(`button`,{type:`button`,onClick:R,"aria-pressed":!!L,className:`shrink-0 flex items-center gap-1.5 px-2.5 py-1 text-xs border rounded-md hover:bg-accent transition-colors text-muted-foreground hover:text-foreground`,title:L?`Unpin from home`:`Pin to home`,children:[L?(0,N.jsx)(s,{className:`w-3 h-3`}):(0,N.jsx)(i,{className:`w-3 h-3`}),(0,N.jsx)(`span`,{className:`hidden sm:inline`,children:L?`Unpin`:`Pin`})]}),B&&(0,N.jsxs)(`button`,{type:`button`,onClick:B,disabled:U||W,className:`shrink-0 flex items-center gap-1.5 px-2.5 py-1 text-xs border rounded-md hover:bg-accent transition-colors text-muted-foreground hover:text-foreground disabled:opacity-50`,title:G?`Copy public link`:`Share canvas`,children:[(0,N.jsx)(_,{className:`w-3 h-3`}),(0,N.jsx)(`span`,{className:`hidden sm:inline`,children:U?`Sharing...`:G?`Copy link`:`Share`})]}),G&&V&&(0,N.jsxs)(`button`,{type:`button`,onClick:V,disabled:U||W,className:`shrink-0 flex items-center gap-1.5 px-2.5 py-1 text-xs border rounded-md hover:bg-destructive/10 transition-colors text-muted-foreground hover:text-destructive disabled:opacity-50`,children:[(0,N.jsx)(a,{className:`w-3 h-3`}),(0,N.jsx)(`span`,{className:`hidden sm:inline`,children:`Unshare`})]}),H&&(0,N.jsxs)(`button`,{type:`button`,onClick:H,disabled:W||he&&!G,title:he&&!G?`Unlock this canvas before deleting it`:`Delete canvas`,className:`shrink-0 flex items-center gap-1.5 px-2.5 py-1 text-xs border rounded-md hover:bg-destructive/10 transition-colors text-muted-foreground hover:text-destructive disabled:opacity-50`,children:[(0,N.jsx)(f,{className:`w-3 h-3`}),(0,N.jsx)(`span`,{className:`hidden sm:inline`,children:W?`Deleting…`:`Delete`})]})]})}):null,Y&&(z||t)&&(0,N.jsx)(`div`,{className:`flex items-center gap-2 border-b px-3 py-1`,children:Re}),(0,N.jsxs)(`div`,{className:`flex-1 min-h-0 overflow-y-auto`,children:[De,Y||(0,N.jsx)(ie,{readingPane:!0,externalSearchQuery:Fe,toolbarActions:Re,documents:y?x.filter(e=>e.schema===y):x,isLoading:S,folders:y?void 0:Oe,onOpenFolder:ke,contextPath:d,treeName:p,workspaceId:m,totalCount:C,viewMode:y?`card`:`table`,allowViewToggle:!0,currentPage:w,pageSize:T,onPageChange:E,onPageSizeChange:D,onRemoveDocument:re,onDeleteDocument:k,onDestroyDocument:oe,onRemoveDocuments:A,onDeleteDocuments:se,onDestroyDocuments:ce,onCopyDocuments:le,onCutDocuments:j,onPasteDocuments:de,onImportDocuments:P,onSelectionChange:fe,pastedDocumentIds:F,onPurgeDocuments:y?void 0:pe,disablePurgeDocuments:me,backendSearchQueries:ge,onBackendSearch:K,serverSort:ve,onServerSortChange:ye,onRemoveBackendQuery:_e,scope:be,onScopeChange:xe,canSaveChanges:!Ae&&Se,isSavingChanges:q,onSaveChanges:J,linkTree:Ee},y??`documents`)]})]})]})}var P=[{id:`todos`,label:`Todo list`},{id:`todo-app`,label:`Todo App`},{id:`notes`,label:`Notes list`},{id:`notes-app`,label:`Notes App`},{id:`sketch`,label:`Sketch`},{id:`terminal`,label:`Terminal`}];function fe(e){return e?.kind===`app`&&e.app===`notes`?`data/schema/note`:void 0}var F={id:`default`,name:`All`,kind:`documents`};function pe(){return[{id:`emails`,label:`Emails`,schemas:[`data/schema/message`]},{id:`todos`,label:`Todos`,schemas:[`data/schema/task`]},{id:`notes`,label:`Notes`,schemas:[`data/schema/note`]},{id:`links`,label:`Links`,schemas:[`data/schema/tab`,`data/schema/link`]},{id:`files`,label:`Files`,schemas:[`data/schema/file`]}]}function me(e){let t=e?.views;if(!Array.isArray(t))return[F];let n=t.filter(e=>{let t=e;return!t||typeof t.id!=`string`||typeof t.name!=`string`?!1:t.kind===`documents`||t.kind===`columns`||t.kind===`app`&&(P.some(e=>e.id===t.app)||t.app===`filters`||t.app===`lens`)});return n.length>0?n:[F]}var I={todos:v,"todo-app":v,notes:y,"notes-app":y,filters:m,sketch:g,Brush:c,terminal:g,lens:d};function L({views:e,activeId:t,onSelect:n,onSave:r,readOnly:i=!1,className:a,accentColor:s,onOpenToSide:c}){let[d,f]=(0,M.useState)(null),[m,h]=(0,M.useState)(``),[g,_]=(0,M.useState)(!1),[v,y]=(0,M.useState)(null),[b,S]=(0,M.useState)(null),w=(0,M.useRef)(null);(0,M.useEffect)(()=>{let e=w.current;if(!e)return;let t=t=>{if(t.ctrlKey||e.scrollWidth<=e.clientWidth)return;let n=Math.abs(t.deltaX)>Math.abs(t.deltaY)?t.deltaX:t.deltaY,r=t.deltaMode===1?16:t.deltaMode===2?e.clientWidth:1;t.preventDefault(),e.scrollLeft+=n*r};return e.addEventListener(`wheel`,t,{passive:!1}),()=>e.removeEventListener(`wheel`,t)},[]),(0,M.useEffect)(()=>{w.current?.querySelector(`[aria-pressed="true"], input`)?.scrollIntoView({block:`nearest`,inline:`nearest`})},[t,d]);let T=()=>{y(null),S(null)},E=()=>{if(v&&b&&v!==b.id){let t=e.find(e=>e.id===v),n=e.filter(e=>e.id!==v),i=n.findIndex(e=>e.id===b.id);t&&i>=0&&(n.splice(b.before?i:i+1,0,t),n.some((t,n)=>t.id!==e[n].id)&&r(n))}T()},D=()=>{if(!d)return;let t=m.trim();t&&r(e.map(e=>e.id===d?{...e,name:t}:e)),f(null)},O=(t,n)=>{_(!1);let i=`view-${Date.now().toString(36)}`,a=t===`columns`?`Board`:t===`app`?P.find(e=>e.id===n)?.label??`App`:`List`,o=t===`columns`?{id:i,name:a,kind:t,columns:pe()}:t===`app`?{id:i,name:a,kind:t,app:n}:{id:i,name:a,kind:t};r([...e,o],i),f(i),h(a)},ee=n=>{let i=e.filter(e=>e.id!==n);r(i.length>0?i:[F],n===t?i[0]?.id??F.id:void 0)};return(0,N.jsxs)(`div`,{className:C(`relative flex h-full min-w-0 items-end`,a),children:[(0,N.jsx)(`div`,{ref:w,className:`flex min-w-0 items-end gap-0.5 overflow-x-auto overscroll-x-contain pt-1 [scrollbar-width:none]`,children:e.map(r=>{let a=r.id===t,u=r.kind===`columns`?x:r.kind===`app`&&r.app?I[r.app]:p;return d===r.id?(0,N.jsx)(`input`,{autoFocus:!0,"aria-label":`Tab name`,value:m,onChange:e=>h(e.target.value),onBlur:D,onKeyDown:e=>{e.key===`Enter`&&D(),e.key===`Escape`&&f(null)},className:C(`relative h-[2.3rem] w-28 shrink-0 rounded-t-[.5rem] border-0 px-3 pb-1 text-xs outline-none ring-0`,a?C(`z-[2] bg-background font-medium`,s?A(s):`text-foreground`):`bg-muted text-muted-foreground`),style:{backgroundColor:a?s:void 0}},r.id):(0,N.jsxs)(`button`,{type:`button`,"aria-pressed":a,onClick:()=>n(r.id),onDoubleClick:()=>{i||(f(r.id),h(r.name))},title:i?r.name:`${r.name}: double-click to rename, drag to reorder`,draggable:!i,onDragStart:e=>{e.dataTransfer.setData(`text/plain`,r.name),e.dataTransfer.effectAllowed=`move`,y(r.id)},onDragOver:e=>{if(!v||v===r.id)return;e.preventDefault(),e.dataTransfer.dropEffect=`move`;let t=e.currentTarget.getBoundingClientRect(),n=e.clientX<t.left+t.width/2;S(e=>e?.id===r.id&&e.before===n?e:{id:r.id,before:n})},onDrop:e=>{e.preventDefault(),E()},onDragEnd:T,className:C(`group relative flex h-[2.3rem] shrink-0 items-center gap-1.5 rounded-t-[.5rem] border-0 px-3 pb-1 text-xs transition-colors`,a?C(`z-[2] bg-background font-medium`,s?A(s):`text-foreground`):`bg-muted text-muted-foreground hover:bg-accent hover:text-foreground`,v===r.id&&`opacity-50`),style:{backgroundColor:a?s:void 0,boxShadow:b?.id===r.id?`inset ${b.before?`2px`:`-2px`} 0 0 var(--primary)`:void 0},children:[(0,N.jsx)(u,{className:`h-3 w-3 shrink-0`}),(0,N.jsx)(`span`,{className:`max-w-32 truncate`,children:r.name}),c&&(0,N.jsx)(o,{className:`h-3 w-3 shrink-0 opacity-0 transition-opacity hover:opacity-100 group-hover:opacity-60`,"aria-label":`Open to the side`,onClick:e=>{e.stopPropagation(),c(r.id)}}),!i&&e.length>1&&(0,N.jsx)(l,{className:C(`h-3 w-3 shrink-0 transition-opacity hover:text-destructive`,a?`opacity-60 hover:opacity-100`:`opacity-0 group-hover:opacity-100`),onClick:e=>{e.stopPropagation(),ee(r.id)}})]},r.id)})}),!i&&(g?(0,N.jsxs)(`span`,{className:`absolute left-0 top-full z-30 flex w-full min-w-64 flex-wrap items-center gap-2 rounded-b-xl border bg-card p-2 shadow-lg`,children:[(0,N.jsxs)(`button`,{type:`button`,onClick:()=>O(`documents`),className:`flex h-10 items-center gap-1.5 rounded-md border px-2 text-xs text-muted-foreground hover:bg-accent/50 hover:text-foreground`,children:[(0,N.jsx)(p,{className:`h-3 w-3`}),` List`]}),(0,N.jsxs)(`button`,{type:`button`,onClick:()=>O(`columns`),className:`flex h-10 items-center gap-1.5 rounded-md border px-2 text-xs text-muted-foreground hover:bg-accent/50 hover:text-foreground`,children:[(0,N.jsx)(x,{className:`h-3 w-3`}),` Board`]}),P.map(e=>{let t=I[e.id];return(0,N.jsxs)(`button`,{type:`button`,onClick:()=>O(`app`,e.id),className:`flex h-10 items-center gap-1.5 rounded-md border px-2 text-xs text-muted-foreground hover:bg-accent/50 hover:text-foreground`,children:[(0,N.jsx)(t,{className:`h-3 w-3`}),` `,e.label]},e.id)}),(0,N.jsx)(`button`,{type:`button`,onClick:()=>_(!1),className:`p-1 text-muted-foreground hover:text-foreground`,"aria-label":`Cancel`,children:(0,N.jsx)(l,{className:`h-3 w-3`})})]}):(0,N.jsx)(`button`,{type:`button`,onClick:()=>_(!0),title:`Add view`,"aria-label":`Add view`,className:`relative ml-1 flex h-[2.3rem] w-10 shrink-0 items-center justify-center rounded-md pb-1 text-muted-foreground hover:bg-accent/50 hover:text-foreground`,children:(0,N.jsx)(u,{className:`h-3.5 w-3.5`})}))]})}var R=[{id:`emails`,label:`Emails`,schemas:[`data/schema/message`]},{id:`todos`,label:`Todos`,schemas:[`data/schema/task`]},{id:`notes`,label:`Notes`,schemas:[`data/schema/note`]},{id:`links`,label:`Links`,schemas:[`data/schema/tab`,`data/schema/link`]},{id:`files`,label:`Files`,schemas:[`data/schema/file`]}];function z(e,t){return t.some(t=>e.schema===t||e.schema.startsWith(`${t}/`))}function B({documents:e,workspaceId:t,columns:n,onColumnsChange:r,readOnly:i=!1}){let[a,o]=(0,M.useState)(null),[s,c]=(0,M.useState)(!1),[d,f]=(0,M.useState)({}),[p,m]=(0,M.useState)({}),h=(0,M.useRef)(null),[g,_]=(0,M.useState)(!1),v=(0,M.useCallback)(()=>{let e=h.current;e&&_(e.scrollWidth-e.clientWidth-e.scrollLeft>8)},[]);(0,M.useEffect)(()=>{let e=h.current;if(!e)return;let t=new ResizeObserver(()=>v());return t.observe(e),()=>t.disconnect()},[v]);let y=(e,t)=>{e.preventDefault();let i=e.currentTarget.parentElement;if(!i)return;let a=e.clientX,o=i.getBoundingClientRect().width,s=o,c=e=>{s=Math.min(900,Math.max(220,o+e.clientX-a)),m(e=>({...e,[t]:s}))},l=()=>{window.removeEventListener(`pointermove`,c),window.removeEventListener(`pointerup`,l),r(n.map(e=>e.id===t?{...e,width:Math.round(s)}:e))};window.addEventListener(`pointermove`,c),window.addEventListener(`pointerup`,l)},b=e=>{m(t=>{let n={...t};return delete n[e],n}),r(n.map(t=>t.id===e?{...t,width:void 0}:t))},x=e=>{let t=d[e];if(t===void 0)return;let i=n.find(t=>t.id===e);i&&(i.filter||``)!==t&&r(n.map(n=>n.id===e?{...n,filter:t||void 0}:n))},C=R.filter(e=>!n.some(t=>t.id===e.id));return(0,N.jsxs)(`div`,{className:`relative h-full`,children:[(0,N.jsx)(`div`,{ref:h,onScroll:v,className:`flex h-full snap-x snap-mandatory gap-3 overflow-x-auto overscroll-x-contain p-2`,"data-testid":`schema-columns-board`,children:n.map(t=>{let a=(d[t.id]??t.filter??``).toLowerCase(),s=e.filter(e=>z(e,t.schemas)).filter(e=>{if(!a)return!0;let t=T(e);return`${t.title}\n${t.preview}\n${t.subtitle}`.toLowerCase().includes(a)}),c=p[t.id]??t.width;return(0,N.jsxs)(`div`,{className:`relative flex h-full min-h-0 min-w-0 shrink-0 grow-0 basis-full snap-start flex-col rounded-(--card-radius) border bg-muted/20 ${c?`sm:basis-[var(--col-w)]`:`sm:basis-[48%] lg:basis-[32%] xl:basis-[24%]`}`,style:c?{"--col-w":`${c}px`}:void 0,children:[!i&&(0,N.jsx)(`div`,{onPointerDown:e=>y(e,t.id),onDoubleClick:()=>b(t.id),title:`Drag to resize; double-click to reset`,className:`absolute right-0 inset-y-0 z-10 w-2 cursor-col-resize touch-none rounded-r-lg transition-colors hover:bg-primary/25 active:bg-primary/40 max-sm:hidden`}),(0,N.jsxs)(`div`,{className:`flex items-center gap-2 px-3 pb-1 pt-2.5 max-sm:pr-10`,children:[(0,N.jsx)(`span`,{className:`truncate text-sm font-medium`,children:t.label}),(0,N.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:s.length}),(0,N.jsx)(`span`,{className:`flex-1`}),!i&&(0,N.jsx)(`button`,{type:`button`,onClick:()=>r(n.filter(e=>e.id!==t.id)),title:`Remove column`,className:`rounded-sm p-0.5 text-muted-foreground hover:text-destructive`,children:(0,N.jsx)(l,{className:`h-3.5 w-3.5`})})]}),(0,N.jsx)(`div`,{className:`px-3 pb-2`,children:(0,N.jsx)(`input`,{value:d[t.id]??t.filter??``,onChange:e=>f(n=>({...n,[t.id]:e.target.value})),onBlur:()=>x(t.id),onKeyDown:e=>{e.key===`Enter`&&x(t.id)},placeholder:`Filter…`,readOnly:i,className:`h-7 w-full rounded-md border border-input bg-background px-2 text-xs placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring`})}),(0,N.jsxs)(`div`,{className:`flex-1 space-y-1.5 overflow-y-auto px-2 pb-2`,children:[s.map(e=>{let t=T(e);return(0,N.jsxs)(`button`,{type:`button`,onClick:()=>o(e),className:`w-full min-w-0 rounded-md border bg-card px-2.5 py-2 text-left transition-colors hover:bg-accent/50`,children:[(0,N.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,N.jsx)(se,{document:e,size:3.5}),(0,N.jsx)(`span`,{className:`truncate text-xs font-medium`,title:t.title,children:t.title})]}),t.preview&&(0,N.jsx)(`p`,{className:`mt-1 line-clamp-2 break-words text-[11px] leading-snug text-muted-foreground`,children:t.preview}),(0,N.jsx)(`p`,{className:`mt-1 text-[10px] text-muted-foreground/70`,children:new Date(e.updatedAt||e.createdAt).toLocaleDateString()})]},e.id)}),s.length===0&&(0,N.jsx)(`p`,{className:`px-2 py-3 text-center text-xs text-muted-foreground/60`,children:`Empty`})]})]},t.id)})}),(!i&&C.length>0||g)&&(0,N.jsxs)(`div`,{className:`pointer-events-none absolute inset-y-0 right-0 z-20 flex w-7 flex-col items-end bg-gradient-to-l from-background via-background/60 to-transparent py-2`,children:[!i&&C.length>0&&(0,N.jsxs)(`div`,{className:`pointer-events-auto relative`,children:[(0,N.jsx)(`button`,{type:`button`,onClick:()=>c(e=>!e),title:`Add column`,"aria-label":`Add column`,className:`flex h-7 w-6 items-center justify-center rounded-l-md border border-r-0 bg-background text-muted-foreground shadow-elevation-1 hover:bg-accent hover:text-foreground`,children:(0,N.jsx)(u,{className:`h-3.5 w-3.5`})}),s&&(0,N.jsxs)(`div`,{className:`absolute right-0 top-8 w-44 rounded-lg border bg-background p-2 shadow-elevation-2`,children:[(0,N.jsx)(`p`,{className:`px-2 pb-1 text-[10px] uppercase tracking-wide text-muted-foreground`,children:`Add column`}),C.map(e=>(0,N.jsx)(`button`,{type:`button`,onClick:()=>{c(!1),r([...n,{...e}])},className:`w-full rounded-md px-2 py-1.5 text-left text-xs text-muted-foreground hover:bg-accent/50 hover:text-foreground`,children:e.label},e.id)),(0,N.jsx)(`button`,{type:`button`,onClick:()=>c(!1),className:`mt-1 w-full rounded-md px-2 py-1.5 text-left text-xs text-muted-foreground/60 hover:bg-accent/50`,children:`Cancel`})]})]}),g&&(0,N.jsx)(S,{className:`my-auto h-4 w-4 self-center text-muted-foreground/70`,"aria-label":`More columns`})]}),(0,N.jsx)(re,{document:a,isOpen:a!==null,onClose:()=>o(null),workspaceId:t})]})}function V(e,t,n,r,i){let a=`${e}\0${t}\0${n}\0${r}\0${i??``}`,[o,s]=(0,M.useState)(0),[c,l]=(0,M.useState)(null);(0,M.useEffect)(()=>{let o=!1;return E(e,n,t,{limit:200,allOf:[r],...i?{sortBy:i,order:`asc`}:{}}).then(e=>{o||l({key:a,docs:e.payload||[]})}).catch(()=>{o||l({key:a,docs:[]})}),()=>{o=!0}},[a,o]);let u=c?.key===a?c.docs:[],d=c?.key!==a;return(0,M.useEffect)(()=>{let e=()=>s(e=>e+1);return window.addEventListener(`workspace:documents:refresh`,e),()=>window.removeEventListener(`workspace:documents:refresh`,e)},[]),{docs:u,isLoading:d,refresh:(0,M.useCallback)(()=>s(e=>e+1),[])}}function H({workspaceId:e,treeName:t,path:n}){let{docs:r,isLoading:i,refresh:a}=V(e,t,n,w,`tasks`),[o,s]=(0,M.useState)(!1),c=o?r.filter(e=>e.data?.status!==`completed`):r,l=r.filter(e=>{let t=e.data?.status;return t!==`completed`&&t!==`cancelled`}).length;return(0,N.jsxs)(`div`,{className:`mx-auto flex h-full w-full max-w-3xl flex-col p-4`,children:[(0,N.jsxs)(`div`,{className:`mb-2 flex shrink-0 items-center justify-between gap-2`,children:[(0,N.jsxs)(`span`,{className:`text-xs text-muted-foreground`,children:[l,` open`]}),(0,N.jsxs)(`label`,{className:`flex cursor-pointer items-center gap-1.5 text-xs text-muted-foreground`,children:[(0,N.jsx)(`input`,{type:`checkbox`,checked:o,onChange:e=>s(e.target.checked)}),`hide done`]})]}),(0,N.jsx)(`div`,{className:`min-h-0 flex-1 space-y-1 overflow-y-auto`,children:i?(0,N.jsx)(`p`,{className:`py-4 text-sm text-muted-foreground`,children:`Loading…`}):c.length===0?(0,N.jsx)(`p`,{className:`py-4 text-sm text-muted-foreground`,children:`No todos here.`}):c.map(t=>(0,N.jsx)(D,{doc:t,workspaceId:e,readOnly:!1,onChanged:a},t.id))})]})}function U({app:e,contextId:t,...n}){let r=t&&e!==`lens`?{mode:`context`,contextId:t}:{mode:`workspace`,workspaceName:n.workspaceId,treeName:n.treeName,path:n.path,treeType:n.treeName===`directory`||n.treeName===`backends`?`directory`:`context`},i=e===`todo-app`?`todo`:e===`notes-app`?`notes`:e,a=ce.find(e=>e.id===i);return(0,N.jsx)(j,{target:r,children:e===`todos`?(0,N.jsx)(H,{...n}):a?(0,N.jsx)(a.Component,{}):null})}export{fe as a,F as i,B as n,me as o,L as r,de as s,U as t};
|