@augmentd-labs/canvas-web 2.26.33 → 2.26.34
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/assets/{CalendarApplet-CG6XE01c.js → CalendarApplet-CVcB6nT5.js} +1 -1
- package/dist/assets/{FiltersApplet-Bh-Ti230.js → FiltersApplet-B3UrkkQk.js} +1 -1
- package/dist/assets/{HomeFab-DjDhl9Kx.js → HomeFab-D83jf0To.js} +1 -1
- package/dist/assets/{LensApplet-CTRYyg4u.js → LensApplet-BvgmmKLC.js} +1 -1
- package/dist/assets/{NotesApplet-DShxjAo_.js → NotesApplet-BJwWkYe_.js} +1 -1
- package/dist/assets/{ObjectPropertiesCard-CFZ_LqzX.js → ObjectPropertiesCard-B9gkyowI.js} +3 -3
- package/dist/assets/{ObjectPropertiesCard-JArcZXXv.css → ObjectPropertiesCard-Docu7O5V.css} +1 -1
- package/dist/assets/{TodosWidget-CX4lgk-9.js → TodosWidget-DdN3vJfS.js} +1 -1
- package/dist/assets/{_agentId_-D9i9ZJWV.js → _agentId_-Ctolhe8r.js} +0 -0
- package/dist/assets/{_contextId_-C6KmQgsY.js → _contextId_-Cj78rDep.js} +1 -1
- package/dist/assets/{_workspaceName_-DOmVjYen.js → _workspaceName_-CU9Y7Zvt.js} +1 -1
- package/dist/assets/{about-BzJi5UDC.js → about-OY_bpfUf.js} +1 -1
- package/dist/assets/{add-DJ45m1Gq.js → add-D7ysLgO3.js} +1 -1
- package/dist/assets/{agents-mnY8dZIT.js → agents-DgJX7Rbh.js} +1 -1
- package/dist/assets/{appearance-CRoFdA6E.js → appearance-D3YShC7g.js} +1 -1
- package/dist/assets/{apps-4xGIx_KA.js → apps-CJ5g43ts.js} +1 -1
- package/dist/assets/{content-app-view-3BCpYf7m.js → content-app-view-CH0wMWqu.js} +1 -1
- package/dist/assets/{document-Ds_P5v-f.js → document-CdrNjy0Z.js} +1 -1
- package/dist/assets/{document-list-CwStaizB.js → document-list-BX13fcRu.js} +1 -1
- package/dist/assets/{home-DB-ohpoi.js → home-BYUM64nU.js} +1 -1
- package/dist/assets/index-CJapDuPp.js +16 -0
- package/dist/assets/{index-XDD8pFI_.css → index-lwdPSalm.css} +1 -1
- package/dist/assets/{key-bindings-BYwqkLkk.js → key-bindings-BhC3zpgE.js} +1 -1
- package/dist/assets/{registry-CtnhH0si.js → registry-C7aVPPMW.js} +2 -2
- package/dist/assets/{settings-Id06aU1g.js → settings-HUPOeACw.js} +1 -1
- package/dist/assets/{settings-BjieBx_W.js → settings-_xaqx07q.js} +1 -1
- package/dist/assets/{settings-BGCP2DRw.js → settings-e2lvFtNs.js} +1 -1
- package/dist/assets/{settings-DAwqsOhZ.js → settings-j7fHuCH-.js} +1 -1
- package/dist/assets/{share-target-BhCMpdxU.js → share-target-BNWYelcQ.js} +1 -1
- package/dist/assets/{shared-Dnd9GFGT.js → shared-td0TEahe.js} +1 -1
- package/dist/assets/{use-canvas-pins-D-zi5fqQ.js → use-canvas-pins-BfT9xMi5.js} +1 -1
- package/dist/assets/{useAgentModels-CTCpJy1M.js → useAgentModels-C9Qu2rhq.js} +1 -1
- package/dist/assets/{workspace-area-menu-DtsodEXC.js → workspace-area-menu-DEyR7-bZ.js} +1 -1
- package/dist/assets/{workspaces-BzAZpTMK.js → workspaces-BryjR7k9.js} +1 -1
- package/dist/index.html +9 -9
- package/dist/sw.js +1 -1
- package/package.json +2 -2
- package/dist/assets/index-BG5J93SO.js +0 -16
|
@@ -1,8 +1,8 @@
|
|
|
1
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-rgHsbLCL.js","assets/rolldown-runtime-C0FnF6B9.js","assets/code-editor-BOIngd5F.js","assets/ui-76Hw0NU_.js","assets/react-BHzhHVTZ.js","assets/button-Bum-POPT.js","assets/utils-BxVxyehK.js","assets/utils-2pl1SbIp.js","assets/workspace-46EFyEKZ.js","assets/input-BOtCd4HP.js","assets/api-CA6WiiYM.js","assets/alert-dialog-CShuAcnP.js","assets/text-documents-CFW8MWES.js","assets/public-share-D2S8DEsv.js","assets/blobs-WiXP9QRi.js","assets/useToastHelpers-CRrpIIdY.js","assets/use-toast-BlLDqSUO.js","assets/note-save-status-DPz4VzL6.js","assets/useEditNoteFields-CKYMBf8V.js","assets/tags-YamdPoBK.js","assets/DocumentBodyEditor-DRFQgBNB.js","assets/lazy-editor-Bdm5JEXv.js","assets/EditorOverlay-DpQKmxkR.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{Bn as o,Bt as s,Dr as c,Dt as l,Et as u,Gn as d,Ht as f,J as p,Jr as m,L as h,Lt as g,Mn as _,Or as v,Pn as y,Pt as b,Qr as x,Tr as S,Un as C,Wr as w,X as T,Xr as E,Yr as D,_n as O,br as k,cn as A,ct as j,en as M,fi as ee,fr as N,jt as P,kn as te,lr as F,mr as I,mt as ne,nr as L,nt as R,on as z,or as B,pn as V,qn as re,rr as H,sn as ie,ui as ae,vr as U,yt as W,zt as oe}from"./ui-76Hw0NU_.js";import{t as G}from"./utils-2pl1SbIp.js";import{t as K}from"./button-Bum-POPT.js";import{t as se}from"./input-BOtCd4HP.js";import{t as q}from"./label-DJc8-3CQ.js";import{l as J}from"./api-CA6WiiYM.js";import{_ as ce,g as le,o as ue,t as de}from"./LinkToCard-VXpoeMDH.js";import{An as fe,Bn as pe,D as me,Gn as he,Hn as ge,J as _e,M as ve,Mn as Y,N as ye,Pn as be,Rn as xe,Un as Se,Wn as Ce,Wt as we,Y as Te,g as Ee,kt as De,l as Oe,o as ke,pn as Ae,q as je,r as Me,s as Ne,tt as Pe,vn as Fe,wn as Ie,yt as Le}from"./workspace-46EFyEKZ.js";import{r as Re,t as ze}from"./use-mobile-Db-vWu9Y.js";import{a as Be,c as Ve,i as He,n as Ue,o as We,r as Ge,s as Ke,t as qe}from"./IdentityFields-CEDxU-Hd.js";import{i as Je,r as Ye}from"./public-share-D2S8DEsv.js";import{a as Xe,i as Ze,n as Qe,o as $e,r as et,s as tt,t as nt}from"./text-documents-CFW8MWES.js";import{t as rt}from"./useDocumentThumbnail-Bs2Ju0eb.js";import{t as it}from"./markdown-view-BBBZtNSR.js";import{n as at,t as ot}from"./tags-YamdPoBK.js";import{n as st,t as ct}from"./relation-events-CKio19hE.js";import{a as lt,i as ut,r as dt,s as ft}from"./date-time-picker-Bzu8H_Oa.js";import{t as pt}from"./sanitize-DrVcFY1Q.js";import{t as mt}from"./useEscapeClose-DR_xKT_k.js";import{t as X}from"./useToastHelpers-CRrpIIdY.js";import"./layer-style-Byl5LNFR.js";import{t as ht}from"./DocumentIcon-ByDAILhm.js";import{r as gt,s as _t,t as vt}from"./MessageComposerDialog-BKGlI7jO.js";import{n as yt}from"./LinkToSidePanel-eCy3nW4R.js";import{t as bt}from"./note-save-status-DPz4VzL6.js";import{t as xt}from"./useEditNoteFields-CKYMBf8V.js";import{t as St}from"./DocumentBodyEditor-DRFQgBNB.js";import{n as Ct}from"./use-document-modal-PG8bQyIB.js";import{t as wt}from"./sketch-lazy-BOFTGGTA.js";import{r as Tt}from"./geo-CZfs0E-x.js";var Z=e(n(),1);function Et(e,t){let n=/(^|\s)(!?)@([a-z-]*)$/i.exec(e);if(!n)return null;let r=n[3].toLowerCase();return{before:e.slice(0,n.index)+n[1]+n[2],predicates:t.filter(e=>e.startsWith(r))}}var Q=t();function Dt({workspaceId:e,inputRef:t,onChange:n}){let[r,i]=(0,Z.useState)(``),[a,o]=(0,Z.useState)(!1),[s,c]=(0,Z.useState)(0),l=le(e),u=Et(r,l.predicates),d=!!e&&a&&u!==null,f=u?.predicates??[],p=(0,Z.useId)(),m=Math.min(s,Math.max(0,f.length-1));(0,Z.useEffect)(()=>{d&&document.getElementById(`${p}-${m}`)?.scrollIntoView({block:`nearest`})},[p,m,d,f.length]);let h=e=>{let r=t.current;if(!r||!u)return;let a=`${u.before}@${e}: `;r.value=a,n?.(a),i(a),o(!1),r.focus()};return(0,Z.useEffect)(()=>{let e=t.current;if(!e)return;let n=()=>{i(e.value),c(0),o(!0)},r=()=>o(!1),a=e=>{!d||e.isComposing||(e.key===`Escape`?(e.preventDefault(),e.stopPropagation(),o(!1)):f.length&&[`ArrowDown`,`ArrowUp`,`Enter`,`Tab`].includes(e.key)&&(e.preventDefault(),e.stopPropagation(),e.key===`ArrowDown`?c((m+1)%f.length):e.key===`ArrowUp`?c((m+f.length-1)%f.length):h(f[m])))};return e.addEventListener(`input`,n),e.addEventListener(`focus`,n),e.addEventListener(`blur`,r),e.addEventListener(`keydown`,a),e.setAttribute(`role`,`combobox`),e.setAttribute(`aria-autocomplete`,`list`),e.setAttribute(`aria-expanded`,String(d)),d?e.setAttribute(`aria-controls`,p):e.removeAttribute(`aria-controls`),d&&f.length?e.setAttribute(`aria-activedescendant`,`${p}-${m}`):e.removeAttribute(`aria-activedescendant`),()=>{e.removeEventListener(`input`,n),e.removeEventListener(`focus`,n),e.removeEventListener(`blur`,r),e.removeEventListener(`keydown`,a);for(let t of[`role`,`aria-autocomplete`,`aria-expanded`,`aria-controls`,`aria-activedescendant`])e.removeAttribute(t)}}),d?(0,Q.jsxs)(`div`,{className:`absolute left-0 right-0 top-full z-50 mt-1 max-h-64 overflow-y-auto rounded-md border bg-popover p-1 text-popover-foreground shadow-lg`,children:[(0,Q.jsx)(`div`,{id:p,role:`listbox`,"aria-label":`Relation predicates`,children:f.map((e,t)=>(0,Q.jsxs)(`button`,{id:`${p}-${t}`,type:`button`,role:`option`,"aria-selected":t===m,className:`block w-full rounded px-3 py-2 text-left text-sm font-mono ${t===m?`bg-accent text-accent-foreground`:`hover:bg-accent`}`,onMouseDown:e=>e.preventDefault(),onClick:()=>h(e),children:[`@`,e,`:`]},e))}),!f.length&&(0,Q.jsx)(`p`,{role:`status`,className:`px-3 py-2 text-sm text-muted-foreground`,children:l.loading?`Loading relations…`:l.error?`Unable to load relation predicates.`:`No matching predicates.`})]}):null}var Ot=1,kt=8,At=320,jt=28,Mt=2.5,Nt={scale:1,x:0,y:0};function Pt({src:e,alt:t,className:n=``,onZoomChange:r}){let i=(0,Z.useRef)(null),a=(0,Z.useRef)(null),[o,s]=(0,Z.useState)(Nt),c=(0,Z.useRef)(new Map),l=(0,Z.useRef)(null),u=(0,Z.useRef)(null),d=(0,Z.useRef)(!1),f=(0,Z.useRef)(null),[p,m]=(0,Z.useState)(!1),[h,g]=(0,Z.useState)(e);h!==e&&(g(e),s(Nt)),(0,Z.useEffect)(()=>{r?.(o.scale>1.001)},[o.scale,r]);let _=(0,Z.useCallback)(e=>{let t=i.current,n=a.current;if(!t||!n)return e;let r=Math.min(kt,Math.max(Ot,e.scale)),o=Math.max(0,(n.offsetWidth*r-t.clientWidth)/2),s=Math.max(0,(n.offsetHeight*r-t.clientHeight)/2);return{scale:r,x:Math.min(o,Math.max(-o,e.x)),y:Math.min(s,Math.max(-s,e.y))}},[]),v=(0,Z.useCallback)((e,t,n)=>{let r=i.current;if(!r)return;let a=r.getBoundingClientRect(),o=t-a.left-a.width/2,c=n-a.top-a.height/2;s(t=>{let n=e/t.scale;return _({scale:e,x:o-(o-t.x)*n,y:c-(c-t.y)*n})})},[_]),y=(0,Z.useCallback)(()=>{let e=i.current,t=a.current;if(!e||!t||!t.offsetWidth||!t.offsetHeight)return Mt;let n=Math.max(e.clientWidth/t.offsetWidth,e.clientHeight/t.offsetHeight),r=Math.max(t.naturalWidth/t.offsetWidth,t.naturalHeight/t.offsetHeight)||kt;return Math.min(kt,Math.max(Mt,Math.min(Math.max(n,Mt),r)))},[]),b=(0,Z.useCallback)((e,t)=>{o.scale>1.001?s(Nt):v(y(),e,t)},[o.scale,v,y]),x=e=>{if(c.current.set(e.pointerId,{x:e.clientX,y:e.clientY}),d.current=!1,c.current.size===2){let[e,t]=[...c.current.values()];l.current={dist:Math.hypot(e.x-t.x,e.y-t.y),scale:o.scale,cx:(e.x+t.x)/2,cy:(e.y+t.y)/2}}e.currentTarget.setPointerCapture(e.pointerId)},S=e=>{let t=c.current.get(e.pointerId);if(!t)return;if(c.current.set(e.pointerId,{x:e.clientX,y:e.clientY}),c.current.size>=2&&l.current){let[e,t]=[...c.current.values()],n=Math.hypot(e.x-t.x,e.y-t.y);l.current.dist>0&&(d.current=!0,m(!0),v(l.current.scale*(n/l.current.dist),l.current.cx,l.current.cy));return}if(o.scale<=1.001)return;let n=e.clientX-t.x,r=e.clientY-t.y;(Math.abs(n)>1||Math.abs(r)>1)&&(d.current=!0,m(!0)),s(e=>_({...e,x:e.x+n,y:e.y+r}))},C=e=>{if(c.current.delete(e.pointerId),c.current.size<2&&(l.current=null),c.current.size===0&&m(!1),d.current){u.current=null;return}let t=e.timeStamp,n=u.current;if(n&&t-n.t<At&&Math.hypot(e.clientX-n.x,e.clientY-n.y)<jt){u.current=null,f.current=t,b(e.clientX,e.clientY);return}u.current={t,x:e.clientX,y:e.clientY}},w=e=>{e.preventDefault();let t=o.scale*(e.deltaY<0?1.15:1/1.15);t<=Ot?s(Nt):v(Math.min(kt,t),e.clientX,e.clientY)},T=o.scale>1.001;return(0,Q.jsx)(`div`,{ref:i,className:`relative flex h-full w-full items-center justify-center overflow-hidden`,style:{touchAction:`none`,cursor:T?`grab`:`zoom-in`},onPointerDown:x,onPointerMove:S,onPointerUp:C,onPointerCancel:e=>{c.current.delete(e.pointerId),l.current=null,u.current=null,d.current=!0,c.current.size===0&&m(!1)},onWheel:w,onDoubleClick:e=>{e.preventDefault(),e.stopPropagation(),!(f.current!==null&&e.timeStamp-f.current<At)&&b(e.clientX,e.clientY)},children:(0,Q.jsx)(`img`,{ref:a,src:e,alt:t,draggable:!1,className:n,style:{transform:`translate3d(${o.x}px, ${o.y}px, 0) scale(${o.scale})`,transformOrigin:`center center`,transition:p?`none`:`transform var(--duration-normal) ease-out`,willChange:`transform`}})})}function Ft(){return!/android|iphone|ipad|mobile/i.test(navigator.userAgent)&&navigator.pdfViewerEnabled!==!1}var It=40,Lt=1600;function Rt({blob:e,filename:t}){let n=(0,Z.useRef)(null),[r,i]=(0,Z.useState)({error:null,pages:0,truncated:!1});return(0,Z.useEffect)(()=>{let r=n.current;if(!r)return;let o=!1,s=null;return(async()=>{let n=await a(()=>import(`./pdf-Ciz5_WNq.js`),__vite__mapDeps([0,1])),c=(await a(async()=>{let{default:e}=await import(`./pdf.worker.min-C8Ts8bNu.js`);return{default:e}},[])).default;n.GlobalWorkerOptions.workerSrc=c;let l=await e.arrayBuffer();if(o)return;let u=n.getDocument({data:l});s=()=>{u.destroy()};let d=await u.promise;if(o)return;let f=Math.min(d.numPages,It),p=r.clientWidth||600,m=window.devicePixelRatio||1;for(let e=1;e<=f;e++){if(o)return;let n=await d.getPage(e),a=n.getViewport({scale:1}),s=Math.min(p*m,Lt*m)/a.width,c=n.getViewport({scale:s}),l=document.createElement(`canvas`);if(l.width=c.width,l.height=c.height,l.style.width=`100%`,l.style.height=`auto`,l.className=`rounded border bg-white`,l.setAttribute(`aria-label`,`${t}, page ${e}`),await n.render({canvas:l,viewport:c}).promise,n.cleanup(),o)return;r.appendChild(l),i({error:null,pages:e,truncated:d.numPages>It})}})().catch(e=>{o||i(t=>({...t,error:e instanceof Error?e.message:String(e)}))}),()=>{o=!0,s?.(),r.replaceChildren()}},[e,t]),(0,Q.jsxs)(`div`,{className:`space-y-2`,children:[r.error&&(0,Q.jsxs)(`p`,{className:`text-sm text-destructive`,children:[`Could not render PDF: `,r.error]}),!r.error&&r.pages===0&&(0,Q.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`Rendering PDF…`}),(0,Q.jsx)(`div`,{ref:n,className:`space-y-2`}),r.truncated&&(0,Q.jsxs)(`p`,{className:`text-xs text-muted-foreground`,children:[`Showing the first `,It,` pages. Download the file for the full document.`]})]})}function zt({blob:e,blobUrl:t,filename:n,className:r=``}){let i=(0,Z.useMemo)(()=>e&&e.type!==`application/pdf`?URL.createObjectURL(e.slice(0,e.size,`application/pdf`)):null,[e]);return(0,Z.useEffect)(()=>()=>{i&&URL.revokeObjectURL(i)},[i]),Ft()||!e?(0,Q.jsx)(`div`,{className:`min-h-[300px] ${r}`,children:(0,Q.jsx)(`iframe`,{src:i??t,className:`h-full min-h-[300px] w-full rounded border`,title:n})}):(0,Q.jsx)(`div`,{className:`max-h-viewport-pane overflow-y-auto ${r}`,children:(0,Q.jsx)(Rt,{blob:e,filename:n})})}function Bt({workspaceId:e,document:t}){let{download:n}=Ye(e),[r,i]=(0,Z.useState)(!1),a=Y(t)||`document-${t.id}`;return(0,Q.jsxs)(`button`,{type:`button`,onClick:async()=>{i(!0);try{await n(t.id,a)}finally{i(!1)}},disabled:r,className:`inline-flex items-center gap-1.5 rounded-md border px-2.5 py-1 text-xs text-muted-foreground transition-colors hover:bg-accent hover:text-foreground disabled:opacity-50`,children:[(0,Q.jsx)(U,{className:`h-3.5 w-3.5`}),r?`Preparing…`:`Download`]})}var Vt=1600;function Ht({error:e,loading:t,children:n}){return e?(0,Q.jsx)(`p`,{className:`text-sm text-destructive`,children:e}):t?(0,Q.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`Loading preview...`}):(0,Q.jsx)(Q.Fragment,{children:n})}function Ut({workspaceId:e,document:t,className:n=``}){let r=(0,Z.useContext)(Ve),i=ze(),a=Re(`(pointer: coarse)`),{blobUrl:o,error:s,loading:c}=rt(e,t.id,Vt,{version:t.checksumArray?.[0]??null}),{fetchBlob:l}=Ye(e),u=Y(t)||`document-${t.id}`,[d,f]=(0,Z.useState)(!1);return(0,Q.jsx)(Ht,{error:s,loading:c,children:o&&(0,Q.jsxs)(`div`,{className:`flex h-full min-h-0 flex-col gap-2 ${n}`,children:[i||a?(0,Q.jsx)(`div`,{className:`min-h-0 flex-1`,children:(0,Q.jsx)(Pt,{src:o,alt:u,className:`max-h-full max-w-full object-contain`})}):(0,Q.jsx)(`img`,{src:o,alt:u,draggable:!1,onDoubleClick:r?e=>{e.preventDefault(),e.stopPropagation(),r()}:void 0,title:r?`Double-click to maximize or restore`:void 0,className:`min-h-0 w-full flex-1 object-contain ${r?`cursor-zoom-in`:``}`}),(0,Q.jsxs)(`button`,{type:`button`,onClick:async()=>{f(!0);try{let{blob:e}=await l(t.id),n=URL.createObjectURL(e),r=window.document.createElement(`a`);r.href=n,r.download=u,window.document.body.appendChild(r),r.click(),r.remove(),setTimeout(()=>URL.revokeObjectURL(n),3e4)}finally{f(!1)}},disabled:d,className:`inline-flex shrink-0 self-start items-center gap-1.5 rounded-md border px-2.5 py-1 text-xs text-muted-foreground transition-colors hover:bg-accent hover:text-foreground disabled:opacity-50`,children:[(0,Q.jsx)(U,{className:`h-3.5 w-3.5`}),d?`Preparing…`:`Download original`]})]})})}function Wt({workspaceId:e,document:t,className:n=``}){let{src:r,error:i,loading:a}=tt(e,t.id);return(0,Q.jsx)(Ht,{error:i,loading:a,children:r&&(0,Q.jsxs)(`div`,{className:`space-y-2 ${n}`,children:[(0,Q.jsx)(`audio`,{src:r,controls:!0,preload:`metadata`,className:`w-full`}),(0,Q.jsx)(Bt,{workspaceId:e,document:t})]})})}function Gt({workspaceId:e,document:t,className:n=``}){let{src:r,error:i,loading:a}=tt(e,t.id),[o,s]=(0,Z.useState)(!1);return(0,Q.jsx)(Ht,{error:i,loading:a,children:r&&(0,Q.jsxs)(`div`,{className:`space-y-2 ${n}`,children:[(0,Q.jsx)(`video`,{src:r,controls:!0,playsInline:!0,preload:`metadata`,onError:()=>s(!0),className:`max-h-viewport-pane w-full rounded border`}),o&&(0,Q.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`This video can’t be played inline in your browser. Download it to view.`}),(0,Q.jsx)(Bt,{workspaceId:e,document:t})]})})}function Kt({workspaceId:e,document:t,className:n=``}){let{blobUrl:r,blob:i,error:a,loading:o}=$e(e,t.id,{typeHint:`application/pdf`}),s=Y(t)||`document-${t.id}`;return(0,Q.jsx)(Ht,{error:a,loading:o,children:r&&(0,Q.jsxs)(`div`,{className:`flex h-full min-h-0 flex-col gap-2 ${n}`,children:[(0,Q.jsx)(zt,{blob:i,blobUrl:r,filename:s,className:`min-h-0 flex-1`}),(0,Q.jsx)(`div`,{children:(0,Q.jsx)(Bt,{workspaceId:e,document:t})})]})})}function qt({workspaceId:e,document:t,className:n=``}){let{text:r,error:i,loading:a}=$e(e,t.id,{mode:`text`,version:t.checksumArray?.[0]});return i?(0,Q.jsx)(`p`,{className:`text-sm text-destructive`,children:i}):a||r==null?(0,Q.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`Loading...`}):(0,Q.jsx)(`pre`,{className:`bg-muted p-3 rounded text-xs overflow-auto max-h-viewport-pane whitespace-pre-wrap ${n}`,children:r})}function Jt({workspaceId:e,document:t,className:n=``}){let r=t.schema===pe,{text:i,error:a,loading:o}=$e(e,t.id,{mode:`text`,enabled:!r,version:t.checksumArray?.[0]});return r?(0,Q.jsxs)(`div`,{className:`markdown-note space-y-3 ${n}`,children:[t.data?.title?(0,Q.jsx)(`h3`,{className:`text-lg font-semibold`,children:String(t.data.title)}):null,(0,Q.jsx)(`div`,{className:`markdown-document-frame rounded-md border border-input bg-transparent`,children:(0,Q.jsx)(it,{content:String(t.data?.content??``),className:`markdown-doc px-4 py-3`})})]}):a?(0,Q.jsx)(`p`,{className:`text-sm text-destructive`,children:a}):o||i==null?(0,Q.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`Loading...`}):(0,Q.jsx)(`div`,{className:`markdown-document-frame rounded-md border border-input bg-transparent overflow-auto max-h-viewport-pane ${n}`,children:(0,Q.jsx)(it,{content:i,className:`markdown-doc px-4 py-3`})})}function Yt({document:e,className:t=``}){let n=String(e.data?.url??e.data?.uri??``),r=he(n);return r?(0,Q.jsx)(`div`,{className:`aspect-video w-full ${t}`,children:(0,Q.jsx)(`iframe`,{src:`https://www.youtube-nocookie.com/embed/${encodeURIComponent(r)}`,title:String(e.data?.title??e.data?.label??`YouTube video`),className:`h-full w-full rounded border`,allow:`accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture`,allowFullScreen:!0})}):null}function Xt({document:e,className:t=``}){let n=String(e.data?.url??e.data?.uri??``),[r,i]=(0,Z.useState)({blobUrl:null,blob:null,failed:!1,loading:!0}),[a,o]=(0,Z.useState)(n);n!==a&&(o(n),i({blobUrl:null,blob:null,failed:!1,loading:!0})),(0,Z.useEffect)(()=>{let e=!1,t=null,r=async e=>{if(!e.ok)throw Error(`HTTP ${e.status}`);let t=await e.blob();return new Blob([t],{type:`application/pdf`})},a=()=>{let e=localStorage.getItem(`authToken`);return fetch(`${J}/proxy/pdf?url=${encodeURIComponent(n)}`,{headers:e?{Authorization:`Bearer ${e}`}:{}})};return fetch(n).then(r).catch(()=>a().then(r)).then(n=>{e||(t=URL.createObjectURL(n),i({blobUrl:t,blob:n,failed:!1,loading:!1}))}).catch(()=>{e||i({blobUrl:null,blob:null,failed:!0,loading:!1})}),()=>{e=!0,t&&URL.revokeObjectURL(t)}},[n]);let{blobUrl:s,blob:c,failed:l,loading:u}=r,d=(()=>{try{let e=decodeURIComponent(new URL(n).pathname.split(`/`).filter(Boolean).pop()??``)||`document`;return/\.pdf$/i.test(e)?e:`${e}.pdf`}catch{return`document.pdf`}})();return(0,Q.jsxs)(`div`,{className:`flex h-full min-h-0 flex-col gap-2 ${t}`,children:[(0,Q.jsxs)(`div`,{className:`flex shrink-0 flex-wrap items-center gap-3`,children:[(0,Q.jsxs)(`a`,{href:n,target:`_blank`,rel:`noopener noreferrer`,className:`inline-flex items-center gap-1 text-xs text-primary hover:underline`,children:[(0,Q.jsx)(I,{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)(U,{className:`h-3.5 w-3.5`}),` Download`]})]}),u&&(0,Q.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`Loading PDF…`}),l&&(0,Q.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`Inline preview unavailable (direct fetch and server proxy both failed). Use the link above.`}),s&&(0,Q.jsx)(zt,{blob:c,blobUrl:s,filename:d,className:`min-h-[300px] flex-1`})]})}function Zt(e){if(!e)return!1;try{let t=new URL(e);return!!(/\.pdf$/i.test(t.pathname)||t.hostname.endsWith(`arxiv.org`)&&t.pathname.startsWith(`/pdf/`))}catch{return!1}}function Qt(e){try{return new URL(e).hostname.replace(/^www\./,``)}catch{return e}}function $t({document:e,className:t=``}){let n=e.data||{},r=String(n.url??n.uri??``),i=String(n.title??n.label??``)||Qt(r),a=typeof n.favIconUrl==`string`?n.favIconUrl:``,o=n.pinned===!0,s=typeof n.timestamp==`string`?n.timestamp:null,[c,l]=(0,Z.useState)(!1);return(0,Q.jsxs)(`div`,{className:`space-y-3 ${t}`,children:[(0,Q.jsxs)(`a`,{href:r,target:`_blank`,rel:`noopener noreferrer`,className:`group flex items-start gap-3 rounded-lg border bg-card p-3 transition-colors hover:bg-accent/40`,children:[(0,Q.jsx)(`div`,{className:`mt-0.5 flex h-9 w-9 shrink-0 items-center justify-center overflow-hidden rounded bg-muted`,children:a&&!c?(0,Q.jsx)(`img`,{src:a,alt:``,className:`h-5 w-5`,onError:()=>l(!0)}):(0,Q.jsx)(C,{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)(g,{className:`h-3 w-3 shrink-0 fill-warning text-warning`})]}),(0,Q.jsx)(`div`,{className:`mt-0.5 truncate text-xs text-muted-foreground`,children:Qt(r)}),(0,Q.jsx)(`div`,{className:`mt-1 truncate font-mono text-[11px] text-muted-foreground/70`,children:r})]}),(0,Q.jsx)(I,{className:`mt-1 h-4 w-4 shrink-0 text-muted-foreground reveal-on-hover`})]}),s&&(0,Q.jsxs)(`p`,{className:`text-xs text-muted-foreground`,children:[`Saved `,new Date(s).toLocaleString()]})]})}function en(e){return e.data||{}}var tn={pending:`bg-muted text-muted-foreground`,"in-progress":`bg-info/15 text-info dark:text-info`,completed:`bg-success/15 text-success dark:text-success`,cancelled:`bg-muted text-muted-foreground line-through`};function nn(e){if(!e.dueDate||e.status===`completed`||e.status===`cancelled`)return!1;let t=new Date(e.dueDate).getTime();return Number.isFinite(t)&&t<Date.now()}function rn(e){if(!e)return``;let t=new Date(e);return Number.isNaN(t.getTime())?``:t.toLocaleString(void 0,{month:`short`,day:`numeric`,hour:`2-digit`,minute:`2-digit`})}async function an(e,t,n){let r=n===`completed`,i={...t.data||{},status:n,completed:r};r?i.completedAt=new Date().toISOString():delete i.completedAt,await Fe(e,{id:t.id,schema:t.schema,schemaVersion:t.schemaVersion,data:i}),window.dispatchEvent(new CustomEvent(`workspace:documents:refresh`))}function on({document:e,workspaceId:t,className:n=``}){let r=en(e),i=Je()!=null,[a,o]=(0,Z.useState)(!1),{replicating:s,label:c}=Ie(e),l=r.status===`completed`,u=r.status??`pending`,d=nn(r);return(0,Q.jsx)(`div`,{className:`space-y-3 ${n}`,children:(0,Q.jsxs)(`div`,{className:`relative flex items-start gap-3 rounded-lg border bg-card p-3 transition-opacity ${s?`opacity-60`:``}`,children:[(0,Q.jsx)(`button`,{type:`button`,onClick:async()=>{if(!(i||a)){o(!0);try{await an(t,e,l?`pending`:`completed`)}catch{}finally{o(!1)}}},disabled:i||a||s,"aria-pressed":l,title:l?`Mark not done`:`Mark done`,className:`mt-0.5 flex h-5 w-5 shrink-0 items-center justify-center rounded border transition-colors ${l?`border-success bg-success text-success-foreground`:`border-input hover:border-success`} ${i?`cursor-default opacity-70`:``}`,children:a?(0,Q.jsx)(V,{className:`h-3 w-3 animate-spin`}):l&&(0,Q.jsx)(w,{className:`h-3.5 w-3.5`})}),(0,Q.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,Q.jsx)(`div`,{className:`font-medium leading-tight ${l?`text-muted-foreground line-through`:``}`,children:r.title||`Todo ${e.id}`}),(0,Q.jsxs)(`div`,{className:`mt-1.5 flex flex-wrap items-center gap-2 text-xs`,children:[(0,Q.jsx)(`span`,{className:`rounded-full px-2 py-0.5 ${tn[u]}`,children:dt[u]}),r.dueDate&&(0,Q.jsxs)(`span`,{className:`inline-flex items-center gap-1 ${d?`font-medium text-destructive`:`text-muted-foreground`}`,children:[(0,Q.jsx)(m,{className:`h-3 w-3`}),rn(r.dueDate),d?` · overdue`:``]}),typeof r.priority==`number`&&(0,Q.jsxs)(`span`,{className:`inline-flex items-center gap-1 text-muted-foreground`,children:[(0,Q.jsx)(L,{className:`h-3 w-3`}),`P`,r.priority]})]}),r.description&&(0,Q.jsx)(it,{content:String(r.description),className:`mt-2 text-sm text-muted-foreground`}),s&&(0,Q.jsxs)(`div`,{className:`mt-2 inline-flex items-center gap-1.5 text-xs text-muted-foreground`,role:`status`,children:[(0,Q.jsx)(V,{className:`h-3 w-3 animate-spin`}),c]})]})]})})}function sn(e,t){let{fetchBlob:n}=Ye(e),r=Je(),i=t.checksumArray?.[0]||t.updatedAt||``,a=JSON.stringify([e,r,t.id,i]),o=typeof t.data?.body==`string`?t.data.body:null,s=typeof t.data?.bodyHtml==`string`?t.data.bodyHtml:null,c=o!==null||s!==null,[l,u]=(0,Z.useState)(null);return(0,Z.useEffect)(()=>{if(c)return;let e=new AbortController;return n(t.id,{format:`email`,version:i,signal:e.signal}).then(async({blob:t})=>{let n=JSON.parse(await t.text());if(typeof n.body!=`string`||n.bodyHtml!=null&&typeof n.bodyHtml!=`string`)throw Error(`Invalid email content response`);e.signal.aborted||u({key:a,body:n.body,bodyHtml:n.bodyHtml||null,error:null})}).catch(t=>{e.signal.aborted||u({key:a,body:``,bodyHtml:null,error:t instanceof Error?t.message:String(t)})}),()=>e.abort()},[a,c,n,t.id,i]),c?{body:o||``,bodyHtml:s,loading:!1,error:null}:l?.key===a?{...l,loading:!1}:{body:``,bodyHtml:null,loading:!0,error:null}}function cn(e){return e?typeof e==`string`?e:e.name&&e.address?`${e.name} <${e.address}>`:e.address||e.name||``:``}function $(e){return e?(Array.isArray(e)?e:[e]).map(e=>cn(e)).filter(Boolean).join(`, `):``}function ln(e){if(!Number.isFinite(e))return``;let t=Number(e);return t<1024?`${t} B`:t<1048576?`${(t/1024).toFixed(1)} KB`:`${(t/1024/1024).toFixed(1)} MB`}function un(e,t,n){let r=0;pt.addHook(`afterSanitizeAttributes`,e=>{if(e.tagName===`IMG`){let i=e.getAttribute(`src`)||``,a=i.toLowerCase();if(a.startsWith(`cid:`)){let n=i.slice(4).replace(/^<|>$/g,``),r=t.get(n)||t.get(`<${n}>`);r?e.setAttribute(`src`,r):e.removeAttribute(`src`)}else(a.startsWith(`http:`)||a.startsWith(`https:`)||a.startsWith(`//`))&&(r++,n?e.setAttribute(`src`,i.replace(/^http:/i,`https:`).replace(/^\/\//,`https://`)):e.removeAttribute(`src`))}e.tagName===`A`&&(e.setAttribute(`target`,`_blank`),e.setAttribute(`rel`,`noopener noreferrer`))});try{let t=pt.sanitize(e,{FORBID_TAGS:[`script`,`iframe`,`object`,`embed`,`form`,`base`,`link`,`meta`],FORBID_ATTR:[`srcset`]}),i=`<!doctype html><html><head>
|
|
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{Bn as o,Bt as s,Dr as c,Dt as l,Et as u,Gn as d,Ht as f,J as p,Jr as m,L as h,Lt as g,Mn as _,Or as v,Pn as y,Pt as b,Qr as x,Tr as S,Un as C,Wr as w,X as T,Xr as E,Yr as D,_n as O,br as k,cn as A,ct as j,en as M,fi as ee,fr as N,jt as P,kn as F,lr as I,mr as L,mt as te,nr as ne,nt as R,on as z,or as B,pn as V,qn as re,rr as ie,sn as ae,ui as H,vr as U,yt as W,zt as oe}from"./ui-76Hw0NU_.js";import{t as G}from"./utils-2pl1SbIp.js";import{t as K}from"./button-Bum-POPT.js";import{t as se}from"./input-BOtCd4HP.js";import{t as q}from"./label-DJc8-3CQ.js";import{l as J}from"./api-CA6WiiYM.js";import{_ as ce,g as le,o as ue,t as de}from"./LinkToCard-VXpoeMDH.js";import{An as fe,Bn as pe,D as me,Gn as he,Hn as ge,J as _e,M as ve,Mn as Y,N as ye,Pn as be,Rn as xe,Un as Se,Wn as Ce,Wt as we,Y as Te,g as Ee,kt as De,l as Oe,o as ke,pn as Ae,q as je,r as Me,s as Ne,tt as Pe,vn as Fe,wn as Ie,yt as Le}from"./workspace-46EFyEKZ.js";import{r as Re,t as ze}from"./use-mobile-Db-vWu9Y.js";import{a as Be,c as Ve,i as He,n as Ue,o as We,r as Ge,s as Ke,t as qe}from"./IdentityFields-CEDxU-Hd.js";import{i as Je,r as Ye}from"./public-share-D2S8DEsv.js";import{a as Xe,i as Ze,n as Qe,o as $e,r as et,s as tt,t as nt}from"./text-documents-CFW8MWES.js";import{t as rt}from"./useDocumentThumbnail-Bs2Ju0eb.js";import{t as it}from"./markdown-view-BBBZtNSR.js";import{n as at,t as ot}from"./tags-YamdPoBK.js";import{n as st,t as ct}from"./relation-events-CKio19hE.js";import{a as lt,i as ut,r as dt,s as ft}from"./date-time-picker-Bzu8H_Oa.js";import{t as pt}from"./sanitize-DrVcFY1Q.js";import{t as mt}from"./useEscapeClose-DR_xKT_k.js";import{t as X}from"./useToastHelpers-CRrpIIdY.js";import"./layer-style-Byl5LNFR.js";import{t as ht}from"./DocumentIcon-ByDAILhm.js";import{r as gt,s as _t,t as vt}from"./MessageComposerDialog-BKGlI7jO.js";import{n as yt}from"./LinkToSidePanel-eCy3nW4R.js";import{t as bt}from"./note-save-status-DPz4VzL6.js";import{t as xt}from"./useEditNoteFields-CKYMBf8V.js";import{t as St}from"./DocumentBodyEditor-DRFQgBNB.js";import{n as Ct}from"./use-document-modal-PG8bQyIB.js";import{t as wt}from"./sketch-lazy-BOFTGGTA.js";import{r as Tt}from"./geo-CZfs0E-x.js";var Z=e(n(),1);function Et(e,t){let n=/(^|\s)(!?)@([a-z-]*)$/i.exec(e);if(!n)return null;let r=n[3].toLowerCase();return{before:e.slice(0,n.index)+n[1]+n[2],predicates:t.filter(e=>e.startsWith(r))}}var Q=t();function Dt({workspaceId:e,inputRef:t,onChange:n}){let[r,i]=(0,Z.useState)(``),[a,o]=(0,Z.useState)(!1),[s,c]=(0,Z.useState)(0),l=le(e),u=Et(r,l.predicates),d=!!e&&a&&u!==null,f=u?.predicates??[],p=(0,Z.useId)(),m=Math.min(s,Math.max(0,f.length-1));(0,Z.useEffect)(()=>{d&&document.getElementById(`${p}-${m}`)?.scrollIntoView({block:`nearest`})},[p,m,d,f.length]);let h=e=>{let r=t.current;if(!r||!u)return;let a=`${u.before}@${e}: `;r.value=a,n?.(a),i(a),o(!1),r.focus()};return(0,Z.useEffect)(()=>{let e=t.current;if(!e)return;let n=()=>{i(e.value),c(0),o(!0)},r=()=>o(!1),a=e=>{!d||e.isComposing||(e.key===`Escape`?(e.preventDefault(),e.stopPropagation(),o(!1)):f.length&&[`ArrowDown`,`ArrowUp`,`Enter`,`Tab`].includes(e.key)&&(e.preventDefault(),e.stopPropagation(),e.key===`ArrowDown`?c((m+1)%f.length):e.key===`ArrowUp`?c((m+f.length-1)%f.length):h(f[m])))};return e.addEventListener(`input`,n),e.addEventListener(`focus`,n),e.addEventListener(`blur`,r),e.addEventListener(`keydown`,a),e.setAttribute(`role`,`combobox`),e.setAttribute(`aria-autocomplete`,`list`),e.setAttribute(`aria-expanded`,String(d)),d?e.setAttribute(`aria-controls`,p):e.removeAttribute(`aria-controls`),d&&f.length?e.setAttribute(`aria-activedescendant`,`${p}-${m}`):e.removeAttribute(`aria-activedescendant`),()=>{e.removeEventListener(`input`,n),e.removeEventListener(`focus`,n),e.removeEventListener(`blur`,r),e.removeEventListener(`keydown`,a);for(let t of[`role`,`aria-autocomplete`,`aria-expanded`,`aria-controls`,`aria-activedescendant`])e.removeAttribute(t)}}),d?(0,Q.jsxs)(`div`,{className:`absolute left-0 right-0 top-full z-50 mt-1 max-h-64 overflow-y-auto rounded-md border bg-popover p-1 text-popover-foreground shadow-lg`,children:[(0,Q.jsx)(`div`,{id:p,role:`listbox`,"aria-label":`Relation predicates`,children:f.map((e,t)=>(0,Q.jsxs)(`button`,{id:`${p}-${t}`,type:`button`,role:`option`,"aria-selected":t===m,className:`block w-full rounded px-3 py-2 text-left text-sm font-mono ${t===m?`bg-accent text-accent-foreground`:`hover:bg-accent`}`,onMouseDown:e=>e.preventDefault(),onClick:()=>h(e),children:[`@`,e,`:`]},e))}),!f.length&&(0,Q.jsx)(`p`,{role:`status`,className:`px-3 py-2 text-sm text-muted-foreground`,children:l.loading?`Loading relations…`:l.error?`Unable to load relation predicates.`:`No matching predicates.`})]}):null}var Ot=1,kt=8,At=320,jt=28,Mt=2.5,Nt={scale:1,x:0,y:0};function Pt({src:e,alt:t,className:n=``,onZoomChange:r}){let i=(0,Z.useRef)(null),a=(0,Z.useRef)(null),[o,s]=(0,Z.useState)(Nt),c=(0,Z.useRef)(new Map),l=(0,Z.useRef)(null),u=(0,Z.useRef)(null),d=(0,Z.useRef)(!1),f=(0,Z.useRef)(null),[p,m]=(0,Z.useState)(!1),[h,g]=(0,Z.useState)(e);h!==e&&(g(e),s(Nt)),(0,Z.useEffect)(()=>{r?.(o.scale>1.001)},[o.scale,r]);let _=(0,Z.useCallback)(e=>{let t=i.current,n=a.current;if(!t||!n)return e;let r=Math.min(kt,Math.max(Ot,e.scale)),o=Math.max(0,(n.offsetWidth*r-t.clientWidth)/2),s=Math.max(0,(n.offsetHeight*r-t.clientHeight)/2);return{scale:r,x:Math.min(o,Math.max(-o,e.x)),y:Math.min(s,Math.max(-s,e.y))}},[]),v=(0,Z.useCallback)((e,t,n)=>{let r=i.current;if(!r)return;let a=r.getBoundingClientRect(),o=t-a.left-a.width/2,c=n-a.top-a.height/2;s(t=>{let n=e/t.scale;return _({scale:e,x:o-(o-t.x)*n,y:c-(c-t.y)*n})})},[_]),y=(0,Z.useCallback)(()=>{let e=i.current,t=a.current;if(!e||!t||!t.offsetWidth||!t.offsetHeight)return Mt;let n=Math.max(e.clientWidth/t.offsetWidth,e.clientHeight/t.offsetHeight),r=Math.max(t.naturalWidth/t.offsetWidth,t.naturalHeight/t.offsetHeight)||kt;return Math.min(kt,Math.max(Mt,Math.min(Math.max(n,Mt),r)))},[]),b=(0,Z.useCallback)((e,t)=>{o.scale>1.001?s(Nt):v(y(),e,t)},[o.scale,v,y]),x=e=>{if(c.current.set(e.pointerId,{x:e.clientX,y:e.clientY}),d.current=!1,c.current.size===2){let[e,t]=[...c.current.values()];l.current={dist:Math.hypot(e.x-t.x,e.y-t.y),scale:o.scale,cx:(e.x+t.x)/2,cy:(e.y+t.y)/2}}e.currentTarget.setPointerCapture(e.pointerId)},S=e=>{let t=c.current.get(e.pointerId);if(!t)return;if(c.current.set(e.pointerId,{x:e.clientX,y:e.clientY}),c.current.size>=2&&l.current){let[e,t]=[...c.current.values()],n=Math.hypot(e.x-t.x,e.y-t.y);l.current.dist>0&&(d.current=!0,m(!0),v(l.current.scale*(n/l.current.dist),l.current.cx,l.current.cy));return}if(o.scale<=1.001)return;let n=e.clientX-t.x,r=e.clientY-t.y;(Math.abs(n)>1||Math.abs(r)>1)&&(d.current=!0,m(!0)),s(e=>_({...e,x:e.x+n,y:e.y+r}))},C=e=>{if(c.current.delete(e.pointerId),c.current.size<2&&(l.current=null),c.current.size===0&&m(!1),d.current){u.current=null;return}let t=e.timeStamp,n=u.current;if(n&&t-n.t<At&&Math.hypot(e.clientX-n.x,e.clientY-n.y)<jt){u.current=null,f.current=t,b(e.clientX,e.clientY);return}u.current={t,x:e.clientX,y:e.clientY}},w=e=>{e.preventDefault();let t=o.scale*(e.deltaY<0?1.15:1/1.15);t<=Ot?s(Nt):v(Math.min(kt,t),e.clientX,e.clientY)},T=o.scale>1.001;return(0,Q.jsx)(`div`,{ref:i,className:`relative flex h-full w-full items-center justify-center overflow-hidden`,style:{touchAction:`none`,cursor:T?`grab`:`zoom-in`},onPointerDown:x,onPointerMove:S,onPointerUp:C,onPointerCancel:e=>{c.current.delete(e.pointerId),l.current=null,u.current=null,d.current=!0,c.current.size===0&&m(!1)},onWheel:w,onDoubleClick:e=>{e.preventDefault(),e.stopPropagation(),!(f.current!==null&&e.timeStamp-f.current<At)&&b(e.clientX,e.clientY)},children:(0,Q.jsx)(`img`,{ref:a,src:e,alt:t,draggable:!1,className:n,style:{transform:`translate3d(${o.x}px, ${o.y}px, 0) scale(${o.scale})`,transformOrigin:`center center`,transition:p?`none`:`transform var(--duration-normal) ease-out`,willChange:`transform`}})})}function Ft(){return!/android|iphone|ipad|mobile/i.test(navigator.userAgent)&&navigator.pdfViewerEnabled!==!1}var It=40,Lt=1600;function Rt({blob:e,filename:t}){let n=(0,Z.useRef)(null),[r,i]=(0,Z.useState)({error:null,pages:0,truncated:!1});return(0,Z.useEffect)(()=>{let r=n.current;if(!r)return;let o=!1,s=null;return(async()=>{let n=await a(()=>import(`./pdf-Ciz5_WNq.js`),__vite__mapDeps([0,1])),c=(await a(async()=>{let{default:e}=await import(`./pdf.worker.min-C8Ts8bNu.js`);return{default:e}},[])).default;n.GlobalWorkerOptions.workerSrc=c;let l=await e.arrayBuffer();if(o)return;let u=n.getDocument({data:l});s=()=>{u.destroy()};let d=await u.promise;if(o)return;let f=Math.min(d.numPages,It),p=r.clientWidth||600,m=window.devicePixelRatio||1;for(let e=1;e<=f;e++){if(o)return;let n=await d.getPage(e),a=n.getViewport({scale:1}),s=Math.min(p*m,Lt*m)/a.width,c=n.getViewport({scale:s}),l=document.createElement(`canvas`);if(l.width=c.width,l.height=c.height,l.style.width=`100%`,l.style.height=`auto`,l.className=`rounded border bg-white`,l.setAttribute(`aria-label`,`${t}, page ${e}`),await n.render({canvas:l,viewport:c}).promise,n.cleanup(),o)return;r.appendChild(l),i({error:null,pages:e,truncated:d.numPages>It})}})().catch(e=>{o||i(t=>({...t,error:e instanceof Error?e.message:String(e)}))}),()=>{o=!0,s?.(),r.replaceChildren()}},[e,t]),(0,Q.jsxs)(`div`,{className:`space-y-2`,children:[r.error&&(0,Q.jsxs)(`p`,{className:`text-sm text-destructive`,children:[`Could not render PDF: `,r.error]}),!r.error&&r.pages===0&&(0,Q.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`Rendering PDF…`}),(0,Q.jsx)(`div`,{ref:n,className:`space-y-2`}),r.truncated&&(0,Q.jsxs)(`p`,{className:`text-xs text-muted-foreground`,children:[`Showing the first `,It,` pages. Download the file for the full document.`]})]})}function zt({blob:e,blobUrl:t,filename:n,className:r=``}){let i=(0,Z.useMemo)(()=>e&&e.type!==`application/pdf`?URL.createObjectURL(e.slice(0,e.size,`application/pdf`)):null,[e]);return(0,Z.useEffect)(()=>()=>{i&&URL.revokeObjectURL(i)},[i]),Ft()||!e?(0,Q.jsx)(`div`,{className:`min-h-[300px] ${r}`,children:(0,Q.jsx)(`iframe`,{src:i??t,className:`h-full min-h-[300px] w-full rounded border`,title:n})}):(0,Q.jsx)(`div`,{className:`max-h-viewport-pane overflow-y-auto ${r}`,children:(0,Q.jsx)(Rt,{blob:e,filename:n})})}function Bt({workspaceId:e,document:t}){let{download:n}=Ye(e),[r,i]=(0,Z.useState)(!1),a=Y(t)||`document-${t.id}`;return(0,Q.jsxs)(`button`,{type:`button`,onClick:async()=>{i(!0);try{await n(t.id,a)}finally{i(!1)}},disabled:r,className:`inline-flex items-center gap-1.5 rounded-md border px-2.5 py-1 text-xs text-muted-foreground transition-colors hover:bg-accent hover:text-foreground disabled:opacity-50`,children:[(0,Q.jsx)(U,{className:`h-3.5 w-3.5`}),r?`Preparing…`:`Download`]})}var Vt=1600;function Ht({error:e,loading:t,children:n}){return e?(0,Q.jsx)(`p`,{className:`text-sm text-destructive`,children:e}):t?(0,Q.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`Loading preview...`}):(0,Q.jsx)(Q.Fragment,{children:n})}function Ut({workspaceId:e,document:t,className:n=``}){let r=(0,Z.useContext)(Ve),i=ze(),a=Re(`(pointer: coarse)`),{blobUrl:o,error:s,loading:c}=rt(e,t.id,Vt,{version:t.checksumArray?.[0]??null}),{fetchBlob:l}=Ye(e),u=Y(t)||`document-${t.id}`,[d,f]=(0,Z.useState)(!1);return(0,Q.jsx)(Ht,{error:s,loading:c,children:o&&(0,Q.jsxs)(`div`,{className:`flex h-full min-h-0 flex-col gap-2 ${n}`,children:[i||a?(0,Q.jsx)(`div`,{className:`min-h-0 flex-1`,children:(0,Q.jsx)(Pt,{src:o,alt:u,className:`max-h-full max-w-full object-contain`})}):(0,Q.jsx)(`img`,{src:o,alt:u,draggable:!1,onDoubleClick:r?e=>{e.preventDefault(),e.stopPropagation(),r()}:void 0,title:r?`Double-click to maximize or restore`:void 0,className:`min-h-0 w-full flex-1 object-contain ${r?`cursor-zoom-in`:``}`}),(0,Q.jsxs)(`button`,{type:`button`,onClick:async()=>{f(!0);try{let{blob:e}=await l(t.id),n=URL.createObjectURL(e),r=window.document.createElement(`a`);r.href=n,r.download=u,window.document.body.appendChild(r),r.click(),r.remove(),setTimeout(()=>URL.revokeObjectURL(n),3e4)}finally{f(!1)}},disabled:d,className:`inline-flex shrink-0 self-start items-center gap-1.5 rounded-md border px-2.5 py-1 text-xs text-muted-foreground transition-colors hover:bg-accent hover:text-foreground disabled:opacity-50`,children:[(0,Q.jsx)(U,{className:`h-3.5 w-3.5`}),d?`Preparing…`:`Download original`]})]})})}function Wt({workspaceId:e,document:t,className:n=``}){let{src:r,error:i,loading:a}=tt(e,t.id);return(0,Q.jsx)(Ht,{error:i,loading:a,children:r&&(0,Q.jsxs)(`div`,{className:`space-y-2 ${n}`,children:[(0,Q.jsx)(`audio`,{src:r,controls:!0,preload:`metadata`,className:`w-full`}),(0,Q.jsx)(Bt,{workspaceId:e,document:t})]})})}function Gt({workspaceId:e,document:t,className:n=``}){let{src:r,error:i,loading:a}=tt(e,t.id),[o,s]=(0,Z.useState)(!1);return(0,Q.jsx)(Ht,{error:i,loading:a,children:r&&(0,Q.jsxs)(`div`,{className:`space-y-2 ${n}`,children:[(0,Q.jsx)(`video`,{src:r,controls:!0,playsInline:!0,preload:`metadata`,onError:()=>s(!0),className:`max-h-viewport-pane w-full rounded border`}),o&&(0,Q.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`This video can’t be played inline in your browser. Download it to view.`}),(0,Q.jsx)(Bt,{workspaceId:e,document:t})]})})}function Kt({workspaceId:e,document:t,className:n=``}){let{blobUrl:r,blob:i,error:a,loading:o}=$e(e,t.id,{typeHint:`application/pdf`}),s=Y(t)||`document-${t.id}`;return(0,Q.jsx)(Ht,{error:a,loading:o,children:r&&(0,Q.jsxs)(`div`,{className:`flex h-full min-h-0 flex-col gap-2 ${n}`,children:[(0,Q.jsx)(zt,{blob:i,blobUrl:r,filename:s,className:`min-h-0 flex-1`}),(0,Q.jsx)(`div`,{children:(0,Q.jsx)(Bt,{workspaceId:e,document:t})})]})})}function qt({workspaceId:e,document:t,className:n=``}){let{text:r,error:i,loading:a}=$e(e,t.id,{mode:`text`,version:t.checksumArray?.[0]});return i?(0,Q.jsx)(`p`,{className:`text-sm text-destructive`,children:i}):a||r==null?(0,Q.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`Loading...`}):(0,Q.jsx)(`pre`,{className:`bg-muted p-3 rounded text-xs overflow-auto max-h-viewport-pane whitespace-pre-wrap ${n}`,children:r})}function Jt({workspaceId:e,document:t,className:n=``}){let r=t.schema===pe,{text:i,error:a,loading:o}=$e(e,t.id,{mode:`text`,enabled:!r,version:t.checksumArray?.[0]});return r?(0,Q.jsxs)(`div`,{className:`markdown-note space-y-3 ${n}`,children:[t.data?.title?(0,Q.jsx)(`h3`,{className:`text-lg font-semibold`,children:String(t.data.title)}):null,(0,Q.jsx)(`div`,{className:`markdown-document-frame rounded-md border border-input bg-transparent`,children:(0,Q.jsx)(it,{content:String(t.data?.content??``),className:`markdown-doc px-4 py-3`})})]}):a?(0,Q.jsx)(`p`,{className:`text-sm text-destructive`,children:a}):o||i==null?(0,Q.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`Loading...`}):(0,Q.jsx)(`div`,{className:`markdown-document-frame rounded-md border border-input bg-transparent overflow-auto max-h-viewport-pane ${n}`,children:(0,Q.jsx)(it,{content:i,className:`markdown-doc px-4 py-3`})})}function Yt({document:e,className:t=``}){let n=String(e.data?.url??e.data?.uri??``),r=he(n);return r?(0,Q.jsx)(`div`,{className:`aspect-video w-full ${t}`,children:(0,Q.jsx)(`iframe`,{src:`https://www.youtube-nocookie.com/embed/${encodeURIComponent(r)}`,title:String(e.data?.title??e.data?.label??`YouTube video`),className:`h-full w-full rounded border`,allow:`accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture`,allowFullScreen:!0})}):null}function Xt({document:e,className:t=``}){let n=String(e.data?.url??e.data?.uri??``),[r,i]=(0,Z.useState)({blobUrl:null,blob:null,failed:!1,loading:!0}),[a,o]=(0,Z.useState)(n);n!==a&&(o(n),i({blobUrl:null,blob:null,failed:!1,loading:!0})),(0,Z.useEffect)(()=>{let e=!1,t=null,r=async e=>{if(!e.ok)throw Error(`HTTP ${e.status}`);let t=await e.blob();return new Blob([t],{type:`application/pdf`})},a=()=>{let e=localStorage.getItem(`authToken`);return fetch(`${J}/proxy/pdf?url=${encodeURIComponent(n)}`,{headers:e?{Authorization:`Bearer ${e}`}:{}})};return fetch(n).then(r).catch(()=>a().then(r)).then(n=>{e||(t=URL.createObjectURL(n),i({blobUrl:t,blob:n,failed:!1,loading:!1}))}).catch(()=>{e||i({blobUrl:null,blob:null,failed:!0,loading:!1})}),()=>{e=!0,t&&URL.revokeObjectURL(t)}},[n]);let{blobUrl:s,blob:c,failed:l,loading:u}=r,d=(()=>{try{let e=decodeURIComponent(new URL(n).pathname.split(`/`).filter(Boolean).pop()??``)||`document`;return/\.pdf$/i.test(e)?e:`${e}.pdf`}catch{return`document.pdf`}})();return(0,Q.jsxs)(`div`,{className:`flex h-full min-h-0 flex-col gap-2 ${t}`,children:[(0,Q.jsxs)(`div`,{className:`flex shrink-0 flex-wrap items-center gap-3`,children:[(0,Q.jsxs)(`a`,{href:n,target:`_blank`,rel:`noopener noreferrer`,className:`inline-flex items-center gap-1 text-xs text-primary hover:underline`,children:[(0,Q.jsx)(L,{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)(U,{className:`h-3.5 w-3.5`}),` Download`]})]}),u&&(0,Q.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`Loading PDF…`}),l&&(0,Q.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`Inline preview unavailable (direct fetch and server proxy both failed). Use the link above.`}),s&&(0,Q.jsx)(zt,{blob:c,blobUrl:s,filename:d,className:`min-h-[300px] flex-1`})]})}function Zt(e){if(!e)return!1;try{let t=new URL(e);return!!(/\.pdf$/i.test(t.pathname)||t.hostname.endsWith(`arxiv.org`)&&t.pathname.startsWith(`/pdf/`))}catch{return!1}}function Qt(e){try{return new URL(e).hostname.replace(/^www\./,``)}catch{return e}}function $t({document:e,className:t=``}){let n=e.data||{},r=String(n.url??n.uri??``),i=String(n.title??n.label??``)||Qt(r),a=typeof n.favIconUrl==`string`?n.favIconUrl:``,o=n.pinned===!0,s=typeof n.timestamp==`string`?n.timestamp:null,[c,l]=(0,Z.useState)(!1);return(0,Q.jsxs)(`div`,{className:`space-y-3 ${t}`,children:[(0,Q.jsxs)(`a`,{href:r,target:`_blank`,rel:`noopener noreferrer`,className:`group flex items-start gap-3 rounded-lg border bg-card p-3 transition-colors hover:bg-accent/40`,children:[(0,Q.jsx)(`div`,{className:`mt-0.5 flex h-9 w-9 shrink-0 items-center justify-center overflow-hidden rounded bg-muted`,children:a&&!c?(0,Q.jsx)(`img`,{src:a,alt:``,className:`h-5 w-5`,onError:()=>l(!0)}):(0,Q.jsx)(C,{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)(g,{className:`h-3 w-3 shrink-0 fill-warning text-warning`})]}),(0,Q.jsx)(`div`,{className:`mt-0.5 truncate text-xs text-muted-foreground`,children:Qt(r)}),(0,Q.jsx)(`div`,{className:`mt-1 truncate font-mono text-[11px] text-muted-foreground/70`,children:r})]}),(0,Q.jsx)(L,{className:`mt-1 h-4 w-4 shrink-0 text-muted-foreground reveal-on-hover`})]}),s&&(0,Q.jsxs)(`p`,{className:`text-xs text-muted-foreground`,children:[`Saved `,new Date(s).toLocaleString()]})]})}function en(e){return e.data||{}}var tn={pending:`bg-muted text-muted-foreground`,"in-progress":`bg-info/15 text-info dark:text-info`,completed:`bg-success/15 text-success dark:text-success`,cancelled:`bg-muted text-muted-foreground line-through`};function nn(e){if(!e.dueDate||e.status===`completed`||e.status===`cancelled`)return!1;let t=new Date(e.dueDate).getTime();return Number.isFinite(t)&&t<Date.now()}function rn(e){if(!e)return``;let t=new Date(e);return Number.isNaN(t.getTime())?``:t.toLocaleString(void 0,{month:`short`,day:`numeric`,hour:`2-digit`,minute:`2-digit`})}async function an(e,t,n){let r=n===`completed`,i={...t.data||{},status:n,completed:r};r?i.completedAt=new Date().toISOString():delete i.completedAt,await Fe(e,{id:t.id,schema:t.schema,schemaVersion:t.schemaVersion,data:i}),window.dispatchEvent(new CustomEvent(`workspace:documents:refresh`))}function on({document:e,workspaceId:t,className:n=``}){let r=en(e),i=Je()!=null,[a,o]=(0,Z.useState)(!1),{replicating:s,label:c}=Ie(e),l=r.status===`completed`,u=r.status??`pending`,d=nn(r);return(0,Q.jsx)(`div`,{className:`space-y-3 ${n}`,children:(0,Q.jsxs)(`div`,{className:`relative flex items-start gap-3 rounded-lg border bg-card p-3 transition-opacity ${s?`opacity-60`:``}`,children:[(0,Q.jsx)(`button`,{type:`button`,onClick:async()=>{if(!(i||a)){o(!0);try{await an(t,e,l?`pending`:`completed`)}catch{}finally{o(!1)}}},disabled:i||a||s,"aria-pressed":l,title:l?`Mark not done`:`Mark done`,className:`mt-0.5 flex h-5 w-5 shrink-0 items-center justify-center rounded border transition-colors ${l?`border-success bg-success text-success-foreground`:`border-input hover:border-success`} ${i?`cursor-default opacity-70`:``}`,children:a?(0,Q.jsx)(V,{className:`h-3 w-3 animate-spin`}):l&&(0,Q.jsx)(w,{className:`h-3.5 w-3.5`})}),(0,Q.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,Q.jsx)(`div`,{className:`font-medium leading-tight ${l?`text-muted-foreground line-through`:``}`,children:r.title||`Todo ${e.id}`}),(0,Q.jsxs)(`div`,{className:`mt-1.5 flex flex-wrap items-center gap-2 text-xs`,children:[(0,Q.jsx)(`span`,{className:`rounded-full px-2 py-0.5 ${tn[u]}`,children:dt[u]}),r.dueDate&&(0,Q.jsxs)(`span`,{className:`inline-flex items-center gap-1 ${d?`font-medium text-destructive`:`text-muted-foreground`}`,children:[(0,Q.jsx)(m,{className:`h-3 w-3`}),rn(r.dueDate),d?` · overdue`:``]}),typeof r.priority==`number`&&(0,Q.jsxs)(`span`,{className:`inline-flex items-center gap-1 text-muted-foreground`,children:[(0,Q.jsx)(ne,{className:`h-3 w-3`}),`P`,r.priority]})]}),r.description&&(0,Q.jsx)(it,{content:String(r.description),className:`mt-2 text-sm text-muted-foreground`}),s&&(0,Q.jsxs)(`div`,{className:`mt-2 inline-flex items-center gap-1.5 text-xs text-muted-foreground`,role:`status`,children:[(0,Q.jsx)(V,{className:`h-3 w-3 animate-spin`}),c]})]})]})})}function sn(e,t){let{fetchBlob:n}=Ye(e),r=Je(),i=t.checksumArray?.[0]||t.updatedAt||``,a=JSON.stringify([e,r,t.id,i]),o=typeof t.data?.body==`string`?t.data.body:null,s=typeof t.data?.bodyHtml==`string`?t.data.bodyHtml:null,c=o!==null||s!==null,[l,u]=(0,Z.useState)(null);return(0,Z.useEffect)(()=>{if(c)return;let e=new AbortController;return n(t.id,{format:`email`,version:i,signal:e.signal}).then(async({blob:t})=>{let n=JSON.parse(await t.text());if(typeof n.body!=`string`||n.bodyHtml!=null&&typeof n.bodyHtml!=`string`)throw Error(`Invalid email content response`);e.signal.aborted||u({key:a,body:n.body,bodyHtml:n.bodyHtml||null,error:null})}).catch(t=>{e.signal.aborted||u({key:a,body:``,bodyHtml:null,error:t instanceof Error?t.message:String(t)})}),()=>e.abort()},[a,c,n,t.id,i]),c?{body:o||``,bodyHtml:s,loading:!1,error:null}:l?.key===a?{...l,loading:!1}:{body:``,bodyHtml:null,loading:!0,error:null}}function cn(e){return e?typeof e==`string`?e:e.name&&e.address?`${e.name} <${e.address}>`:e.address||e.name||``:``}function $(e){return e?(Array.isArray(e)?e:[e]).map(e=>cn(e)).filter(Boolean).join(`, `):``}function ln(e){if(!Number.isFinite(e))return``;let t=Number(e);return t<1024?`${t} B`:t<1048576?`${(t/1024).toFixed(1)} KB`:`${(t/1024/1024).toFixed(1)} MB`}function un(e,t,n){let r=0;pt.addHook(`afterSanitizeAttributes`,e=>{if(e.tagName===`IMG`){let i=e.getAttribute(`src`)||``,a=i.toLowerCase();if(a.startsWith(`cid:`)){let n=i.slice(4).replace(/^<|>$/g,``),r=t.get(n)||t.get(`<${n}>`);r?e.setAttribute(`src`,r):e.removeAttribute(`src`)}else(a.startsWith(`http:`)||a.startsWith(`https:`)||a.startsWith(`//`))&&(r++,n?e.setAttribute(`src`,i.replace(/^http:/i,`https:`).replace(/^\/\//,`https://`)):e.removeAttribute(`src`))}e.tagName===`A`&&(e.setAttribute(`target`,`_blank`),e.setAttribute(`rel`,`noopener noreferrer`))});try{let t=pt.sanitize(e,{FORBID_TAGS:[`script`,`iframe`,`object`,`embed`,`form`,`base`,`link`,`meta`],FORBID_ATTR:[`srcset`]}),i=`<!doctype html><html><head>
|
|
3
3
|
<meta charset="utf-8">
|
|
4
4
|
<meta name="viewport" content="width=device-width,initial-scale=1">
|
|
5
5
|
<meta http-equiv="Content-Security-Policy" content="${`default-src 'none'; img-src data:${n?` https:`:``}; style-src 'unsafe-inline'`}">
|
|
6
6
|
<style>html{overflow:auto}body{margin:12px;font:14px/1.5 system-ui,sans-serif;color:#1a1a1a;background:#fff}@media(max-width:480px){body{margin:8px}}</style>
|
|
7
|
-
</head><body>${t}</body></html>`;return{url:URL.createObjectURL(new Blob([i],{type:`text/html;charset=utf-8`})),remoteCount:r}}finally{pt.removeHook(`afterSanitizeAttributes`)}}function dn(e){return new Promise((t,n)=>{let r=new FileReader;r.onload=()=>t(String(r.result)),r.onerror=()=>n(r.error),r.readAsDataURL(e)})}function fn(e){return(0,Q.jsx)(pn,{...e},`${e.workspaceId}:${e.document.id}`)}function pn({workspaceId:e,document:t,className:n=``}){let{fetchBlob:r,download:i}=Ye(e),a=t.data||{},o=Array.isArray(a.attachments)?a.attachments:[],{body:s,bodyHtml:l,loading:u,error:d}=sn(e,t),[f,p]=(0,Z.useState)(null),[m,h]=(0,Z.useState)(!1),[g,v]=(0,Z.useState)(!1),[b,x]=(0,Z.useState)(0),[S,C]=(0,Z.useState)(null);(0,Z.useEffect)(()=>{if(!l||m)return;let e=!1,n=[],i=o.filter(e=>e.contentId&&e.url);return Promise.all(i.slice(0,20).map(async e=>{try{let{blob:n}=await r(t.id,{url:e.url}),i=await dn(n);return[String(e.contentId).replace(/^<|>$/g,``),i]}catch{return null}})).then(t=>{if(e)return;let r=new Map(t.filter(Boolean)),{url:i,remoteCount:a}=un(l,r,g);n.push(i),p(i),x(a)}).catch(t=>{e||C(String(t instanceof Error?t.message:t))}),()=>{e=!0,n.forEach(e=>URL.revokeObjectURL(e)),p(null)}},[e,t.id,l,m,g]);let w=typeof a.date==`string`?new Date(a.date).toLocaleString():null,T=o.filter(e=>!e.isInline||!e.contentId),E=async e=>{if(e.url)try{await i(t.id,e.filename||`attachment`,{url:e.url})}catch(e){C(e instanceof Error?e.message:String(e))}};return(0,Q.jsxs)(`div`,{className:`flex h-full min-h-0 min-w-0 flex-col gap-3 ${n}`,children:[(0,Q.jsx)(`div`,{className:`shrink-0 rounded-md border bg-muted/30 p-2 text-sm sm:p-3`,children:(0,Q.jsxs)(`div`,{className:`flex flex-wrap items-start justify-between gap-2 sm:gap-3`,children:[(0,Q.jsxs)(`div`,{className:`min-w-0 flex-1 basis-64 space-y-1`,children:[(0,Q.jsx)(`div`,{className:`truncate text-base font-semibold`,children:String(a.subject??`(no subject)`)}),(0,Q.jsxs)(`details`,{className:`sm:hidden`,children:[(0,Q.jsxs)(`summary`,{className:`cursor-pointer text-xs`,children:[(0,Q.jsx)(`span`,{className:`inline-block max-w-[85%] truncate align-bottom`,children:typeof a.from==`object`&&a.from?a.from.name||a.from.address:String(a.from||`Unknown sender`)}),(0,Q.jsx)(`span`,{className:`ml-2 text-muted-foreground`,children:`Details`})]}),(0,Q.jsxs)(`div`,{className:`mt-2 space-y-1 break-words text-xs`,children:[(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`span`,{className:`text-muted-foreground`,children:`From:`}),` `,cn(a.from)]}),$(a.to)&&(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`span`,{className:`text-muted-foreground`,children:`To:`}),` `,$(a.to)]}),$(a.cc)&&(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`span`,{className:`text-muted-foreground`,children:`Cc:`}),` `,$(a.cc)]}),w&&(0,Q.jsx)(`div`,{className:`text-xs text-muted-foreground`,children:w})]})]}),(0,Q.jsxs)(`div`,{className:`hidden space-y-1 break-words sm:block`,children:[(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`span`,{className:`text-muted-foreground`,children:`From:`}),` `,cn(a.from)]}),$(a.to)&&(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`span`,{className:`text-muted-foreground`,children:`To:`}),` `,$(a.to)]}),$(a.cc)&&(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`span`,{className:`text-muted-foreground`,children:`Cc:`}),` `,$(a.cc)]}),w&&(0,Q.jsx)(`div`,{className:`text-xs text-muted-foreground`,children:w})]})]}),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)(c,{className:`mr-1.5 h-3.5 w-3.5`}):(0,Q.jsx)(B,{className:`mr-1.5 h-3.5 w-3.5`}),m?`HTML`:`Plain text`]}),!m&&b>0&&(0,Q.jsxs)(K,{size:`sm`,variant:g?`secondary`:`outline`,onClick:()=>v(!g),title:`Remote images can reveal your IP/read status to the sender`,children:[g?(0,Q.jsx)(y,{className:`mr-1.5 h-3.5 w-3.5`}):(0,Q.jsx)(_,{className:`mr-1.5 h-3.5 w-3.5`}),g?`Hide remote images`:`Show remote images (${b})`]})]})]})}),(S||d)&&(0,Q.jsx)(`p`,{className:`text-sm text-destructive`,children:S||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:s||`(empty body)`}),T.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 (`,T.length,`)`]}),T.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)(B,{className:`h-4 w-4 shrink-0 text-muted-foreground`}),(0,Q.jsx)(`span`,{className:`truncate`,children:e.filename||`attachment`}),(0,Q.jsx)(`span`,{className:`shrink-0 text-xs text-muted-foreground`,children:ln(e.size)})]}),e.url&&(0,Q.jsxs)(`button`,{onClick:()=>E(e),className:`inline-flex shrink-0 items-center gap-1 text-xs text-primary hover:underline`,children:[(0,Q.jsx)(U,{className:`h-3 w-3`}),` Download`]})]},e.url||t))]})]})}function mn({attachment:e,workspaceId:t,document:n}){let{download:r}=Ye(t),i=e.mimeType||e.contentType||``,a=e.name||e.filename||`Attachment`,o=i.startsWith(`audio/`)||i.startsWith(`video/`),{blobUrl:s,error:c,loading:l}=$e(t,n.id,{url:e.url,typeHint:i,enabled:!o&&!!e.url}),{src:u,error:d,loading:f}=tt(t,n.id,{url:e.url,enabled:o&&!!e.url}),[p,m]=(0,Z.useState)(!1),[h,g]=(0,Z.useState)(``),_=o?d:c;return(0,Q.jsxs)(`div`,{className:`space-y-2 rounded border p-2`,children:[_&&(0,Q.jsx)(`p`,{className:`text-xs text-destructive`,children:_}),(o?f:l)&&(0,Q.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`Loading attachment…`}),!o&&s&&i.startsWith(`image/`)&&(0,Q.jsx)(`img`,{src:s,alt:a,className:`max-h-96 max-w-full rounded object-contain`}),o&&u&&(i.startsWith(`video/`)?(0,Q.jsx)(`video`,{controls:!0,playsInline:!0,preload:`metadata`,src:u,onError:()=>m(!0),className:`max-h-96 w-full rounded`},u):(0,Q.jsx)(`audio`,{controls:!0,preload:`metadata`,src:u,onError:()=>m(!0),className:`w-full`},u)),p&&(0,Q.jsx)(`p`,{role:`alert`,className:`text-xs text-destructive`,children:`This media could not be played in your browser. Download it to play in another app.`}),h&&(0,Q.jsx)(`p`,{role:`alert`,className:`text-xs text-destructive`,children:h}),e.url&&(0,Q.jsxs)(`button`,{className:`text-sm text-primary underline`,onClick:()=>{r(n.id,a,{url:e.url}).catch(()=>g(`Attachment could not be downloaded.`))},children:[`Download `,a]})]})}function hn(e){let t=e.document.data,n=t.sender,r=t.channel,i=Array.isArray(t.attachments)?t.attachments:[],a=t.timestamp?new Date(String(t.timestamp)):null;return(0,Q.jsxs)(`article`,{className:`space-y-4 p-3 ${e.className||``}`,children:[(0,Q.jsxs)(`header`,{className:`space-y-1 border-b pb-3`,children:[(0,Q.jsx)(`p`,{className:`font-medium`,children:n?.name||n?.displayName||n?.username||n?.id||`Unknown sender`}),(0,Q.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:[r?.name||r?.id,String(t.platform||``),a&&!Number.isNaN(a.getTime())?a.toLocaleString():``].filter(Boolean).join(` · `)})]}),(0,Q.jsx)(`p`,{className:`whitespace-pre-wrap break-words text-sm`,children:String(t.text||`(No text)`)}),!!t.mediaError&&(0,Q.jsx)(`p`,{className:`text-xs text-destructive`,children:String(t.mediaError)}),i.map((t,n)=>(0,Q.jsx)(mn,{...e,attachment:t},t.url||n))]})}var gn={email:A,phone:oe,sms:M,chat:M,slack:M,matrix:M,web:C,url:C},_n={person:`Person`,organization:`Organization`,service:`Service`,bot:`Bot`},vn=e=>Array.isArray(e)?e:[];function yn(e,t){return t?e===`email`?`mailto:${t}`:e===`phone`||e===`sms`?`tel:${t.replace(/[^\d+]/g,``)}`:/^https?:\/\//i.test(t)?t:null:null}function bn({title:e,count:t,children:n}){return t===0?null:(0,Q.jsxs)(`div`,{className:`space-y-1`,children:[(0,Q.jsx)(`p`,{className:`text-xs font-medium text-muted-foreground`,children:e}),(0,Q.jsx)(`div`,{className:`space-y-1`,children:n})]})}function xn({icon:e,primary:t,children:n,title:r}){return(0,Q.jsxs)(`div`,{className:`flex min-w-0 items-center gap-2 rounded-md border bg-card px-2.5 py-1.5 text-sm`,title:r,children:[(0,Q.jsx)(e,{className:`h-3.5 w-3.5 shrink-0 text-muted-foreground`}),(0,Q.jsx)(`div`,{className:`min-w-0 flex-1 truncate`,children:n}),t&&(0,Q.jsx)(R,{className:`h-3 w-3 shrink-0 fill-current text-data-5`,"aria-label":`Primary`})]})}function Sn({document:e,className:t}){let n=e.data??{},r=vn(n.identifiers),i=vn(n.channels),a=vn(n.organizations),o=vn(n.links),s=vn(n.tags),c=String(n.displayName||``).trim(),l=Ce(e.schema,xe),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:_n[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)(bn,{title:`Primary email`,count:1,children:(0,Q.jsx)(xn,{icon:A,primary:!0,children:(0,Q.jsx)(`a`,{href:`mailto:${u}`,className:`hover:underline`,children:u})})}),(0,Q.jsx)(bn,{title:`Channels`,count:i.length,children:i.map((e,t)=>{let n=String(e.kind||``).toLowerCase(),r=String(e.value||``),i=yn(n,r),a=gn[n]||M;return(0,Q.jsxs)(xn,{icon:a,primary:e.primary,title:e.platform||n,children:[i?(0,Q.jsx)(`a`,{href:i,className:`hover:underline`,target:i.startsWith(`http`)?`_blank`:void 0,rel:`noopener noreferrer`,children:r}):r,e.label&&(0,Q.jsx)(`span`,{className:`ml-2 text-xs text-muted-foreground`,children:e.label})]},`${n}:${r}:${t}`)})}),(0,Q.jsx)(bn,{title:`Identifiers`,count:r.length,children:r.map((e,t)=>(0,Q.jsxs)(xn,{icon:H,primary:e.primary,children:[(0,Q.jsx)(`span`,{className:`font-mono text-xs`,children:e.identifier}),(0,Q.jsx)(`span`,{className:`ml-2 text-xs text-muted-foreground`,children:[e.type,e.provider].filter(Boolean).join(` · `)})]},`${e.type}:${e.identifier}:${t}`))}),(0,Q.jsx)(bn,{title:`Organizations`,count:a.length,children:a.map((e,t)=>(0,Q.jsxs)(xn,{icon:D,children:[e.name,e.role&&(0,Q.jsx)(`span`,{className:`ml-2 text-xs text-muted-foreground`,children:e.role})]},`${e.name}:${t}`))}),(0,Q.jsx)(bn,{title:`Links`,count:o.length,children:o.map((e,t)=>(0,Q.jsxs)(xn,{icon:O,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 Cn({document:e}){let t=String(e.metadata?.contentType||`application/octet-stream`);return(0,Q.jsxs)(`p`,{className:`text-sm text-muted-foreground`,children:[`No inline preview available for `,(0,Q.jsx)(`span`,{className:`font-mono`,children:t}),`. Use Download.`]})}function wn(e){let t=e.schema;if(t===`data/schema/note`)return Jt;if(t===`data/schema/drawing`)return Ut;if(t===`data/schema/task`)return on;if(t===`data/schema/message/email`)return fn;if(t===`data/schema/message`)return hn;if(t===`data/schema/identity`||t.startsWith(`data/schema/identity/`))return Sn;if(t===`data/schema/tab`||t===`data/schema/link`){let t=String(e.data?.url??e.data?.uri??``);return he(t)?Yt:Zt(t)?Xt:$t}if(t!==`data/schema/file`)return null;let n=String(e.metadata?.contentType||``);switch(Se(n,Y(e))){case`image`:return Ut;case`audio`:return Wt;case`video`:return Gt;case`pdf`:return Kt;case`markdown`:return Jt;case`text`:return qt;default:return Cn}}function Tn({onSearch:e,onDraftChange:t,inputRef:n,workspaceId:r,label:i=`Search documents`,clearOnSubmit:a=!0,showSubmitButton:o=!0}){let s=(0,Z.useRef)(null),c=n??s;return(0,Q.jsxs)(`form`,{className:`canvas-search-input`,role:`search`,onSubmit:n=>{n.preventDefault();let r=n.currentTarget.elements.namedItem(`query`),i=r.value.trim();i&&(e(i),a&&(r.value=``,t?.(``)))},children:[(0,Q.jsx)(`input`,{ref:c,name:`query`,type:`search`,"aria-label":i,placeholder:i,autoComplete:`off`,enterKeyHint:`search`,onChange:e=>t?.(e.target.value),onKeyDown:e=>{e.key===`Enter`&&e.nativeEvent.isComposing&&e.preventDefault()}}),o&&(0,Q.jsx)(`button`,{type:`submit`,className:`canvas-nav-button`,"aria-label":`Run search`,title:`Run search`,children:(0,Q.jsx)(W,{size:17})}),r&&(0,Q.jsx)(Dt,{workspaceId:r,inputRef:c,onChange:t})]})}function En({queries:e,onRemoveQuery:t,scope:n=`path`,onScopeChange:r}){return(0,Q.jsxs)(`div`,{className:`canvas-search-options`,children:[r&&(0,Q.jsxs)(`div`,{className:`canvas-search-scopes`,"aria-label":`Search scope`,children:[(0,Q.jsx)(`span`,{children:`Search in`}),(0,Q.jsx)(`button`,{type:`button`,"aria-pressed":n===`path`,onClick:()=>r(`path`),children:`This path`}),(0,Q.jsx)(`button`,{type:`button`,"aria-pressed":n===`workspace`,onClick:()=>r(`workspace`),children:`Workspace`})]}),e.length>0&&(0,Q.jsxs)(`div`,{className:`canvas-search-queries`,"aria-label":`Active searches`,children:[e.map((e,n)=>{let r=/"[^"]+/.test(e);return(0,Q.jsxs)(`span`,{className:r?`canvas-search-query canvas-search-query-exact`:`canvas-search-query`,children:[r?(0,Q.jsx)(P,{size:12,"aria-hidden":`true`}):(0,Q.jsx)(W,{size:12,"aria-hidden":`true`}),(0,Q.jsx)(`span`,{title:r?`${e} (exact phrase)`:e,children:e}),t&&(0,Q.jsx)(`button`,{type:`button`,onClick:()=>t(n),"aria-label":`Remove search: ${e}`,children:(0,Q.jsx)(h,{size:14})})]},`${e}-${n}`)}),t&&e.length>1&&(0,Q.jsx)(`button`,{type:`button`,onClick:()=>t(-1),className:`canvas-search-clear`,children:`Clear all`})]})]})}function Dn({children:e,accentColor:t}){return(0,Q.jsxs)(`div`,{className:`canvas-navigation-tabs`,children:[(0,Q.jsx)(`span`,{"aria-hidden":`true`,className:`canvas-tab-divider`,style:t?{backgroundColor:t}:void 0}),e]})}function On({workspace:e,workspaceIcon:t,tree:n,path:i,document:a,section:o,onBack:s,onBrowseWorkspaces:c,onBrowseTree:l,onNavigatePath:u,onDocument:d,onSection:f,onFilter:p,filtersActive:m,filtersOpen:g,onAdd:_,search:v,onDraftChange:y,tabs:x,accentColor:S,actions:C}){let[w,T]=(0,Z.useState)(!1),[E,D]=(0,Z.useState)(!1),O=(0,Z.useRef)(null),k=(0,Z.useRef)(null),A=(0,Z.useRef)(null),M=(0,Z.useRef)(!1),N=JSON.stringify([e,n,i,a]),[P,te]=(0,Z.useState)(N);P!==N&&(te(N),T(!1)),(0,Z.useEffect)(()=>{w?k.current?.focus():(O.current&&(O.current.scrollLeft=O.current.scrollWidth,D(O.current.scrollLeft>1)),M.current&&=(A.current?.focus(),!1))},[w,N,o]);let F=()=>{M.current=!0,T(!1),y?.(``)},I=w?F:s??l,ne=ue(i,e).slice(1),L=(e,t,n,r,i=!1)=>n?(0,Q.jsx)(`button`,{type:`button`,className:t,onClick:n,title:r,"aria-current":i?`location`:void 0,children:e}):(0,Q.jsx)(`span`,{className:`canvas-address-label ${t}`,title:r,"aria-current":i?`location`:void 0,children:e});return(0,Q.jsxs)(`header`,{className:`canvas-navigation${x?` has-tabs`:``}`,style:S?{borderTopColor:S}:void 0,children:[x&&(0,Q.jsx)(Dn,{accentColor:S,children:x}),(0,Q.jsxs)(`div`,{className:`canvas-address-row`,children:[(0,Q.jsx)(`button`,{type:`button`,className:`canvas-nav-button`,"aria-label":w?`Back to address`:`Back to previous view`,title:w?`Back to address`:`Back to previous view`,disabled:!w&&!s&&!l,onClick:I,children:(0,Q.jsx)(ee,{size:19})}),(0,Q.jsxs)(`div`,{className:`canvas-address-field`,onDoubleClick:e=>{v&&!e.target.closest(`button`)&&T(!0)},onKeyDown:e=>{e.key===`Escape`&&w&&(e.preventDefault(),e.stopPropagation(),F())},children:[w&&v?(0,Q.jsx)(Tn,{inputRef:k,workspaceId:v.localOnly?void 0:v.workspaceId,onSearch:v.onSearch,onDraftChange:y,clearOnSubmit:!v.localOnly,showSubmitButton:!1,label:v.queries.length?`Refine search…`:`Search documents…`}):(0,Q.jsxs)(Q.Fragment,{children:[L((0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(r,{icon:t||`ph:stack-fill`,className:`h-4 w-4 shrink-0`,"aria-hidden":`true`}),(0,Q.jsx)(`span`,{className:`truncate`,children:e})]}),`canvas-address-workspace`,c,`Browse workspaces`),(0,Q.jsxs)(`div`,{ref:O,className:`canvas-address-crumbs${E?` is-scrolled`:``}`,onScroll:e=>D(e.currentTarget.scrollLeft>1),role:`navigation`,"aria-label":`Canvas address`,tabIndex:0,onKeyDown:e=>{e.key===`Enter`&&e.target===e.currentTarget&&v&&T(!0)},children:[n&&L(`[${n}]`,`canvas-address-tree`,l,`Browse tree: ${n}`),L(`:/`,`canvas-address-root`,u?()=>u(`/`):void 0,`Go to tree root`),ne.map((e,t)=>(0,Q.jsxs)(`span`,{className:`canvas-address-segment`,children:[t>0&&(0,Q.jsx)(`span`,{"aria-hidden":`true`,children:`/`}),L(e.label,``,u?()=>u(e.path):void 0,e.path,!a&&t===ne.length-1)]},e.path)),a&&(0,Q.jsxs)(`span`,{className:`canvas-address-segment`,children:[(0,Q.jsx)(`span`,{"aria-hidden":`true`,children:ne.length?`/`:``}),L(a,``,d,a)]}),o&&L(`#${o}`,`canvas-address-section`,f,o,!0)]})]}),v&&(0,Q.jsxs)(`button`,{ref:A,type:`button`,className:`canvas-nav-button canvas-address-search`,onClick:()=>{w?k.current?.form?.requestSubmit():T(!0)},"aria-label":w?`Run search`:`Search this canvas`,"aria-expanded":w,title:w?`Run search`:`Search this canvas`,children:[(0,Q.jsx)(W,{size:17}),v.queries.length>0&&(0,Q.jsx)(`span`,{className:`canvas-nav-dot`})]})]}),p&&(0,Q.jsxs)(`button`,{type:`button`,className:`canvas-nav-button canvas-filter-button`,onClick:p,"aria-label":m?`Filters active`:`Filters`,"aria-expanded":!!g,"data-active":!!m,title:m?`Filters active`:`Filters`,children:[(0,Q.jsx)(j,{size:19}),m&&(0,Q.jsx)(`span`,{className:`canvas-nav-dot`})]}),_&&(0,Q.jsx)(`button`,{type:`button`,className:`canvas-nav-button canvas-add-button`,onClick:_,"aria-label":`Add here`,title:`Add here`,children:(0,Q.jsx)(b,{size:21})}),C]}),w&&v&&(0,Q.jsxs)(`div`,{className:`canvas-search-dropdown`,children:[(0,Q.jsxs)(`div`,{className:`canvas-search-heading`,children:[(0,Q.jsx)(`span`,{children:v.localOnly?`Filter documents on this page`:y?`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)(h,{size:16})})]}),(0,Q.jsx)(En,{...v})]}),!w&&v&&v.queries.length>0&&(0,Q.jsx)(`div`,{className:`px-3 pb-2`,children:(0,Q.jsx)(En,{queries:v.queries,onRemoveQuery:v.onRemoveQuery})})]})}function kn({workspaceId:e,document:t,className:n}){let r=wn(t);return r?(0,Q.jsx)(r,{workspaceId:e,document:t,className:n}):(0,Q.jsx)(`pre`,{className:`overflow-auto p-2 text-xs`,children:JSON.stringify(t.data,null,2)})}function An({workspaceId:e,documentId:t}){let[n,r]=(0,Z.useState)(null),[i,a]=(0,Z.useState)(``),[o,s]=(0,Z.useState)({}),[c,l]=(0,Z.useState)(null),u=(0,Z.useCallback)(async()=>{try{let n=await gt(e,t);r(n),a(``)}catch(e){a(e instanceof Error?e.message:`Could not load thread`)}},[e,t]);return(0,Z.useEffect)(()=>{let n=!0;gt(e,t).then(e=>{n&&(r(e),a(``))}).catch(e=>{n&&a(e instanceof Error?e.message:`Could not load thread`)});let i=()=>{u()};return window.addEventListener(`workspace:documents:refresh`,i),window.addEventListener(ct,i),()=>{n=!1,window.removeEventListener(`workspace:documents:refresh`,i),window.removeEventListener(ct,i)}},[e,t,u]),i?(0,Q.jsxs)(`div`,{className:`p-3`,children:[(0,Q.jsx)(`p`,{role:`alert`,className:`text-sm text-destructive`,children:i}),(0,Q.jsx)(K,{variant:`outline`,size:`sm`,onClick:()=>void u(),children:`Retry`})]}):!n||n.documentId!==t?(0,Q.jsx)(`p`,{className:`p-3 text-sm text-muted-foreground`,children:`Loading thread…`}):(0,Q.jsxs)(`section`,{"aria-label":`Message thread`,className:`space-y-3 p-2`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,Q.jsxs)(`h3`,{className:`text-sm font-medium`,children:[`Thread · `,n.documents.length,` message`,n.documents.length===1?``:`s`]}),(0,Q.jsx)(K,{size:`sm`,variant:`outline`,onClick:()=>void u(),children:`Refresh`})]}),n.documents.length===1&&(0,Q.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`No linked replies have been indexed. Other messages in this conversation are separate from this reply thread.`}),n.truncated&&(0,Q.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`Showing up to 200 linked messages.`}),n.documents.map(r=>{let i=fe(r),a=r.schema===`data/schema/message/email`,c=a||[`slack`,`whatsapp`].includes(String(r.data.platform)),u=r.data.timestamp||r.data.date,d=u?new Date(String(u)):null,f=(n.parents[r.id]||[]).flatMap(e=>{let t=n.documents.find(t=>Number(t.id)===e);return t?[fe(t).title]:[]}),p=o[Number(r.id)]??Number(r.id)===t;return(0,Q.jsxs)(`details`,{open:p,onToggle:e=>{let t=e.currentTarget.open;s(e=>e[Number(r.id)]===t?e:{...e,[Number(r.id)]:t})},className:`rounded-lg border bg-card`,children:[(0,Q.jsxs)(`summary`,{className:`cursor-pointer space-y-1 p-3 text-sm`,children:[(0,Q.jsx)(`span`,{className:`font-medium`,children:i.title}),(0,Q.jsxs)(`span`,{className:`block text-xs text-muted-foreground`,children:[i.subtitle,d&&!Number.isNaN(d.getTime())?` · ${d.toLocaleString()}`:``]}),f.length>0&&(0,Q.jsxs)(`span`,{className:`block text-xs text-muted-foreground`,children:[`Reply to `,f.join(`, `)]})]}),p&&c&&(0,Q.jsx)(`div`,{className:`flex flex-wrap gap-2 px-3 pb-2`,children:(a?[`reply`,`replyAll`,`forward`]:[`reply`]).map(e=>(0,Q.jsx)(K,{variant:`outline`,size:`sm`,onClick:()=>l({document:r,mode:e}),children:e===`replyAll`?`Reply all`:e===`forward`?`Forward`:`Reply`},e))}),p&&(0,Q.jsx)(kn,{workspaceId:e,document:r})]},r.id)}),c&&(0,Q.jsx)(vt,{workspaceId:e,replyToDocumentId:Number(c.document.id),mode:c.mode,originalSubject:typeof c.document.data.subject==`string`?c.document.data.subject:void 0,onClose:()=>l(null)},`${c.document.id}:${c.mode}`)]})}function jn(e,t){return e.slice(0,3).map(e=>{let n=t.get(e.id),r=e.reason===`not-found`?`Source missing from the storage index. Resync the source backend and retry.`:e.reason===`not found`?`Document no longer exists in this workspace. Refresh the list and select it again.`:e.reason;return`${n?`${n} (ID ${e.id})`:`Document ${e.id}`}: ${r}`}).join(`
|
|
8
|
-
`)+(e.length>3?`\n…and ${e.length-3} more failed file${e.length===4?``:`s`}.`:``)}var Mn=e(i(),1),Nn=[{mode:`copy`,label:`Copy to`,icon:(0,Q.jsx)(S,{className:`h-3.5 w-3.5`})},{mode:`move`,label:`Move to`,icon:(0,Q.jsx)(ae,{className:`h-3.5 w-3.5`})},{mode:`delete`,label:`Delete from`,icon:(0,Q.jsx)(T,{className:`h-3.5 w-3.5`})}],Pn=[{value:`rename`,label:`Rename mine (file-1.ext)`},{value:`overwrite`,label:`Overwrite the existing file`},{value:`error`,label:`Skip the document`}],Fn=`h-9 w-full rounded-md border bg-background px-2 text-xs outline-none focus:ring-2 focus:ring-ring disabled:opacity-50`;function In(e){return e.driver===`cacache`?k:e.config?.remote===!0?v:o}function Ln({workspaceId:e,documentCount:t,initialMode:n=`copy`,defaultFilename:r=``,onConfirm:i,onClose:a,saving:s=!1,sizeClassName:c,deleteFrom:l,progress:u,stopping:d=!1,onStop:f}){let{showErrorToast:m}=X(),[g,_]=(0,Z.useState)(!1);mt(a,!s&&!g);let[v,y]=(0,Z.useState)(n),[b,x]=(0,Z.useState)(null),[C,w]=(0,Z.useState)(null),[E,D]=(0,Z.useState)(()=>new Set(n===`delete`&&l?[l.backend]:[])),[O,k]=(0,Z.useState)(!1),[A,j]=(0,Z.useState)(``),[M,ee]=(0,Z.useState)(r),[N,P]=(0,Z.useState)(`rename`);(0,Z.useEffect)(()=>{let t=!1;return Le(e).then(e=>{if(t)return;x(e.filter(e=>e.kind===`storage`));let n=new Set(e.filter(e=>e.kind===`storage`&&e.enabled!==!1&&e.config?.readOnly!==!0&&e.config?.supported!==!1).map(e=>e.address));D(e=>new Set([...e].filter(e=>n.has(e))))}).catch(e=>{t||w(e instanceof Error?e.message:String(e))}),()=>{t=!0}},[e]);let te=v===`move`,F=e=>e.enabled===!1?`disabled`:e.config?.readOnly===!0?`read-only`:e.config?.supported===!1?`unsupported`:null,I=(0,Z.useMemo)(()=>(b||[]).filter(e=>!F(e)).map(e=>e.address),[b,v]),ne=e=>{y(e),D(t=>{let n=(b||[]).filter(e=>e.enabled!==!1&&e.config?.readOnly!==!0&&e.config?.supported!==!1).map(e=>e.address),r=[...t].filter(e=>n.includes(e));return new Set(e===`move`?r.slice(0,1):r)})},L=e=>{D(t=>{if(te)return t.has(e)?new Set:new Set([e]);let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},R=(0,Z.useMemo)(()=>(b||[]).filter(e=>E.has(e.address)&&Ne(e)),[b,E]),z=v!==`delete`&&R.length>0,B=e=>{let t=ke(e,b||[]),n=t&&b?.find(e=>e.address===t.address);return!!n&&!F(n)&&v!==`delete`&&!s},V=async(t,n)=>{let r=ke(t,b||[]);if(!r||!B(t))throw Error(`Choose a writable file backend folder`);await Me(e,r.driver,r.address,[[r.key,n].filter(Boolean).join(`/`)])},H=e=>{_(!1);let t=Oe(e[0]||``,b||[]),n=t?(b||[]).find(e=>e.address===t.address):null;if(!t||!n){m(`Pick a folder inside a storage backend`);return}if(F(n)){m(`${n.address} is ${F(n)}`);return}if(!Ne(n)){m(`${n.address} does not keep folders — objects are stored by content`);return}j(t.key),D(e=>te?new Set([t.address]):new Set([...e,t.address]))},ie=async()=>{E.size===0||s||await i([...E],v,{keepDocument:O,folder:z?A.trim():``,filename:z&&t===1?M.trim():``,onConflict:N})},U=t,W=U===1?``:`s`,oe=v===`delete`?`Delete ${U} document${W} from…`:`${v===`move`?`Move`:`Copy`} ${U} document${W} to…`,q=v===`delete`?`Delete from`:v===`move`?`Move to`:`Copy to`,J=E.size===0?q.split(` `)[0]:`${q} ${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`,c||`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)(o,{className:`h-4 w-4`}),oe]}),(0,Q.jsx)(`button`,{type:`button`,onClick:a,disabled:s,className:`text-muted-foreground transition-colors hover:text-foreground disabled:opacity-40`,"aria-label":`Close`,children:(0,Q.jsx)(h,{className:`h-4 w-4`})})]}),(0,Q.jsx)(`div`,{className:`flex shrink-0 items-center gap-1 border-b px-2 pt-2`,children:Nn.map(({mode:e,label:t,icon:n})=>(0,Q.jsxs)(`button`,{type:`button`,onClick:()=>ne(e),disabled:s,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}),!b&&!C&&(0,Q.jsx)(`div`,{className:`px-2 py-3 text-xs text-muted-foreground`,children:`Loading backends…`}),b?.length===0&&(0,Q.jsx)(`p`,{className:`px-2 py-1.5 text-xs text-muted-foreground`,children:`No storage backends configured.`}),b?.map(e=>{let t=In(e),n=F(e),r=E.has(e.address),i=e.config?.remote===!0;return(0,Q.jsxs)(`div`,{onClick:()=>!n&&!s&&L(e.address),className:G(`group relative flex min-h-10 items-center gap-2 rounded-md px-3 py-2 text-sm shadow-elevation-1 transition-all select-none`,`before:absolute before:left-0 before:top-0 before:bottom-0 before:w-1.5 before:transition-colors`,n?`cursor-not-allowed bg-muted/40 opacity-60 before:bg-transparent`:`cursor-pointer hover:shadow`,!n&&r?v===`delete`?`bg-destructive/[0.08] hover:bg-destructive/[0.12] before:bg-destructive`:`bg-primary/[0.08] hover:bg-primary/[0.12] before:bg-primary`:n?``:`bg-card hover:bg-primary/[0.04] before:bg-transparent`),title:e.address,children:[(0,Q.jsx)(`input`,{type:te?`radio`:`checkbox`,checked:r,disabled:!!n||s,onChange:()=>L(e.address),onClick:e=>e.stopPropagation(),className:`h-4 w-4 shrink-0 accent-primary`,"aria-label":e.address}),(0,Q.jsx)(t,{className:`h-4 w-4 shrink-0 text-muted-foreground`}),(0,Q.jsxs)(`span`,{className:`min-w-0 flex-1`,children:[(0,Q.jsx)(`span`,{className:`block truncate font-medium`,children:e.config?.label||e.address}),(0,Q.jsxs)(`span`,{className:`block truncate font-mono text-[10px] text-muted-foreground`,children:[e.driver,` · `,e.address]})]}),i&&(0,Q.jsx)(`span`,{className:`shrink-0 rounded bg-info-subtle px-1.5 py-0.5 text-[10px] uppercase text-muted-foreground`,title:`Network mount${e.config?.transport?` (${e.config.transport})`:``} — transfers cross the network`,children:e.config?.transport||`remote`}),n&&(0,Q.jsx)(`span`,{className:`shrink-0 rounded bg-muted px-1.5 py-0.5 text-[10px] uppercase text-muted-foreground`,children:n})]},`${e.driver}/${e.address}`)}),v===`delete`&&(0,Q.jsxs)(`label`,{className:`mt-3 flex cursor-pointer items-start gap-2 rounded-md border border-destructive/30 bg-destructive/5 px-3 py-2 text-xs`,children:[(0,Q.jsx)(`input`,{type:`checkbox`,checked:O,onChange:e=>k(e.target.checked),disabled:s,className:`mt-0.5 h-3.5 w-3.5 accent-destructive`}),(0,Q.jsxs)(`span`,{children:[`Keep the index entry when its `,(0,Q.jsx)(`strong`,{children:`last`}),` copy is deleted.`,(0,Q.jsx)(`span`,{className:`block text-muted-foreground`,children:`Otherwise the document moves to workspace Trash once no locations remain.`})]})]}),z&&(0,Q.jsxs)(`div`,{className:`mt-3 space-y-2 rounded-md border px-3 py-2`,children:[(0,Q.jsxs)(`p`,{className:`text-xs font-medium`,children:[`Destination on `,R.map(e=>e.config?.label||e.address).join(`, `)]}),(0,Q.jsxs)(`div`,{className:`space-y-1`,children:[(0,Q.jsx)(`label`,{htmlFor:`backend-transfer-folder`,className:`text-[11px] text-muted-foreground`,children:`Folder (relative to the backend root)`}),(0,Q.jsxs)(`div`,{className:`flex gap-1.5`,children:[(0,Q.jsx)(se,{id:`backend-transfer-folder`,value:A,onChange:e=>j(e.target.value),placeholder:`/`,disabled:s,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:s,"aria-label":`Browse backend folders`,title:`Browse…`,children:(0,Q.jsx)(re,{className:`h-4 w-4`})})]})]}),t===1?(0,Q.jsxs)(`div`,{className:`space-y-1`,children:[(0,Q.jsx)(`label`,{htmlFor:`backend-transfer-filename`,className:`text-[11px] text-muted-foreground`,children:`File name`}),(0,Q.jsx)(se,{id:`backend-transfer-filename`,value:M,onChange:e=>ee(e.target.value),placeholder:r||`keeps the document's own name`,disabled:s,className:`h-9 font-mono text-xs`})]}):(0,Q.jsx)(`p`,{className:`text-[11px] text-muted-foreground`,children:`Each document keeps its own file name and extension.`}),(0,Q.jsxs)(`div`,{className:`space-y-1`,children:[(0,Q.jsx)(`label`,{htmlFor:`backend-transfer-conflict`,className:`text-[11px] text-muted-foreground`,children:`If a different file already has that name`}),(0,Q.jsx)(`select`,{id:`backend-transfer-conflict`,className:Fn,value:N,onChange:e=>P(e.target.value),disabled:s,children:Pn.map(e=>(0,Q.jsx)(`option`,{value:e.value,children:e.label},e.value))})]})]}),v===`move`&&I.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.`})]}),s&&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||s,children:s?(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(ce,{className:`mr-1.5 h-3.5 w-3.5`}),`Working…`]}):(0,Q.jsxs)(Q.Fragment,{children:[v===`delete`?(0,Q.jsx)(T,{className:`mr-1 h-3.5 w-3.5`}):v===`move`?(0,Q.jsx)(ae,{className:`mr-1 h-3.5 w-3.5`}):(0,Q.jsx)(S,{className:`mr-1 h-3.5 w-3.5`}),J]})})]}),v===`delete`&&(0,Q.jsxs)(`div`,{className:`flex items-start gap-2 border-t bg-destructive/5 px-4 py-2 text-[11px] text-muted-foreground`,children:[(0,Q.jsx)(p,{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.`})]}),g&&(0,Q.jsx)(yt,{onClose:()=>_(!1),children:(0,Q.jsx)(de,{sizeClassName:`h-full w-[380px] max-w-[90vw] max-md:w-full`,multiple:!1,tabs:[`backends`],fixedWorkspaceName:e,title:`Pick a destination folder…`,confirmLabel:`Use folder`,backendFolderCreation:{canCreate:B,create:V},onConfirm:H,onClose:()=>_(!1)})})]})}var Rn={exif:`from the photo's EXIF`,device:`from the device at capture`,manual:`placed by hand`};function zn(e){let t=`${e.lat.toFixed(5)}, ${e.lon.toFixed(5)}`,n=e.source?Rn[e.source]:null;return[t,e.accuracy==null?null:`±${e.accuracy} m`,n].filter(Boolean).join(` · `)}function Bn({value:e,onChange:t,idPrefix:n=`edit-geo`}){let[r,i]=(0,Z.useState)(!1);return(0,Q.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Q.jsx)(q,{htmlFor:`${n}-action`,children:`Location`}),(0,Q.jsxs)(`div`,{className:`flex items-center justify-between gap-3`,children:[(0,Q.jsxs)(`span`,{className:`flex min-w-0 items-center gap-2 text-xs`,children:[(0,Q.jsx)(ie,{className:e?`h-4 w-4 shrink-0 text-info`:`h-4 w-4 shrink-0 text-muted-foreground`}),(0,Q.jsx)(`span`,{className:e?`truncate tabular-nums`:`truncate text-muted-foreground`,children:e?zn(e):`No location on this document`})]}),(0,Q.jsxs)(`span`,{className:`flex shrink-0 items-center gap-1`,children:[(0,Q.jsxs)(`button`,{id:`${n}-action`,type:`button`,onClick:()=>i(!0),className:`inline-flex items-center gap-1.5 rounded-md border border-border px-2 py-1 text-xs text-muted-foreground transition-colors hover:bg-muted hover:text-foreground`,children:[(0,Q.jsx)(z,{className:`h-3.5 w-3.5`}),e?`Move pin`:`Set on map`]}),e&&(0,Q.jsx)(`button`,{type:`button`,onClick:()=>t(null),"aria-label":`Remove location`,title:`Remove location`,className:`rounded p-1 text-muted-foreground hover:bg-muted hover:text-foreground`,children:(0,Q.jsx)(T,{className:`h-3.5 w-3.5`})})]})]}),r&&(0,Q.jsx)(We,{initial:e,onPick:e=>t({lat:e.lat,lon:e.lon,source:`manual`}),onClose:()=>i(!1)})]})}function Vn(e){return e===`data/schema/note`||e===`data/schema/link`||e===`data/schema/tab`||e===`data/schema/task`||e===`data/schema/drawing`||e===`data/schema/identity`||e.startsWith(`data/schema/identity/`)}function Hn(e){return Vn(e.schema)||Ze(e)}function Un(e){return e===`data/schema/link`?{urlKey:`uri`,titleKey:`label`}:e===`data/schema/tab`?{urlKey:`url`,titleKey:`title`}:{urlKey:null,titleKey:`title`}}async function Wn(e,t,n){try{let r=new Set(n.map(e=>e.identityId).filter(Boolean)),i=await Te(e,t,{resolve:!1}),a=new Set(i.outgoing.filter(e=>e.p===`member-of`).map(e=>e.to));for(let n of r)a.has(n)||await Ee(e,t,`member-of`,[n]);for(let n of a)r.has(n)||await we(e,t,`member-of`,n)}catch(e){console.error(`Failed to sync organization relations`,e)}}function Gn({document:e,workspaceId:t,onClose:n}){let{showSuccessToast:r,showErrorToast:i}=X(),a=Vn(e.schema),o=e.schema===`data/schema/file`,[s,c]=(0,Z.useState)(()=>Y(e)),l=!o||!!s.trim()&&!/[\\/]/.test(s)&&!Array.from(s).some(e=>e.charCodeAt(0)<32)&&s!==`.`&&s!==`..`,u=e.schema===pe,d=Ze(e),f=et(e)??`markdown`,p=d&&Xe(e),m=e.schema===ge,h=e.schema===`data/schema/identity`||e.schema.startsWith(`data/schema/identity/`),{urlKey:g,titleKey:_}=Un(e.schema),[v,y]=(0,Z.useState)(g?String(e.data?.[g]??``):``),[b,x]=(0,Z.useState)(String(e.data?.[_]??``)),[S,C]=(0,Z.useState)(String(e.data?.content??``)),[w,T]=(0,Z.useState)(String(e.data?.description??``)),[E,D]=(0,Z.useState)(e.data?.status??`pending`),[O,k]=(0,Z.useState)(typeof e.data?.priority==`number`?e.data.priority:``),[A,j]=(0,Z.useState)(e.data?.dueDate?lt(String(e.data.dueDate)):ft()),M=He(Ge(e)),[ee,N]=(0,Z.useState)(String(e.comment??``)),P=e.metadata?.geo??null,[te,F]=(0,Z.useState)(P),I=e.features??e.metadata?.features,[ne,L]=(0,Z.useState)(ot(I).length?ot(I):e.data?.tags??[]),R=xt(e,t,u),{title:z,content:B,comment:V,tags:re,geo:H,setTitle:ie,setContent:ae,setComment:U,setTags:W,setGeo:oe}=u?R:{title:b,content:S,comment:ee,tags:ne,geo:te,setTitle:x,setContent:C,setComment:N,setTags:L,setGeo:F},G=JSON.stringify(H??null)!==JSON.stringify(P??null),J=$e(t,e.id,{mode:`text`,enabled:d&&!p,maxTextLength:Qe,version:e.checksumArray?.[0]??null}),[ce,le]=(0,Z.useState)(null),ue=`${e.id}:${e.checksumArray?.[0]??``}`;d&&J.text!=null&&ce!==ue&&(le(ue),ae(J.text));let[de,fe]=(0,Z.useState)([]),[me,he]=(0,Z.useState)(!1),{replicating:_e,mirror:ve}=Ie(e);(0,Z.useEffect)(()=>{let e=!1;return De(t).then(t=>{e||fe(t)}).catch(()=>{}),()=>{e=!0}},[t]);let ye=!g||(()=>{try{return new URL(v.trim()),!0}catch{return!1}})(),be=!me&&l&&(d?!p&&J.text!=null&&!J.loading:a?h?M.displayName.trim().length>0&&M.emailValid:m?z.trim().length>0:u?R.canSave:ye:!0),Se=async()=>{he(!0);let c=[...(I||[]).filter(e=>!e.startsWith(`tag/`)),...at(re)];try{if(u){await R.save(),n();return}if(d){let i=await nt(t,e,B,{comment:V.trim(),metadata:{features:c,...o?{filename:s.trim()}:{},...G?{geo:H}:{}}});r(`Document updated`),window.dispatchEvent(new CustomEvent(`workspace:documents:refresh`)),n(i);return}let i={id:e.id,schema:e.schema,schemaVersion:e.schemaVersion,comment:V.trim(),metadata:{features:c,...o?{filename:s.trim()}:{}}};if(h){let{type:t,...n}=e.data??{};i.schema=`${xe}/${M.values.type}`,i.data={...n,...Ue(M.values)}}else if(m)i.data={...e.data,...ut({title:z,description:w,status:E,priority:O,due:A})};else if(a){let t=re.map(e=>e.trim()).filter(Boolean),n;u?n={...z.trim()?{title:z.trim()}:{},content:B}:(n={...e.data},g&&(n[g]=v.trim()),z.trim()?n[_]=z.trim():delete n[_],n.tags=t),i.data=n}G&&(i.metadata={...i.metadata??{},geo:H}),await Fe(t,i),h&&(await Wn(t,e.id,M.values.organizations),st()),r(`Document updated`),window.dispatchEvent(new CustomEvent(`workspace:documents:refresh`)),n()}catch(e){i(e instanceof Error?e.message:`Failed to update document`)}finally{he(!1)}};return(0,Q.jsxs)(`div`,{className:`flex flex-col gap-4`,children:[o&&(0,Q.jsxs)(`div`,{className:`space-y-2`,children:[(0,Q.jsx)(q,{htmlFor:`file-name`,children:`File name`}),(0,Q.jsx)(se,{id:`file-name`,value:s,onChange:e=>c(e.target.value)}),(0,Q.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`Changes the object’s name; storage locations stay the same.`})]}),a&&g&&(0,Q.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Q.jsx)(q,{htmlFor:`edit-url`,children:`URL`}),(0,Q.jsx)(se,{id:`edit-url`,value:v,onChange:e=>y(e.target.value),placeholder:`https://example.com`,className:`font-mono text-xs`}),v.trim()&&!ye&&(0,Q.jsx)(`p`,{className:`text-xs text-destructive`,children:`Enter a valid URL, e.g. https://example.com`})]}),a&&h&&(0,Q.jsx)(qe,{idPrefix:`edit-identity`,workspaceName:t,...M,emailValid:M.emailValid}),a&&m&&(0,Q.jsx)(Be,{idPrefix:`edit-todo`,title:z,setTitle:ie,description:w,setDescription:T,status:E,setStatus:D,priority:O,setPriority:k,due:A,setDue:j}),a&&!m&&!h&&(0,Q.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Q.jsx)(q,{htmlFor:`edit-title`,children:`Title`}),(0,Q.jsx)(se,{id:`edit-title`,value:z,onChange:e=>ie(e.target.value),placeholder:u?`Optional; defaults to today's date`:`Optional display title`})]}),(u||d)&&(0,Q.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Q.jsx)(q,{children:`Body`}),p?(0,Q.jsxs)(`p`,{className:`text-xs text-muted-foreground`,children:[`This file is too large to edit here (`,`>`,1e3,` kB) — download it instead.`]}):d&&J.error?(0,Q.jsx)(`p`,{className:`text-xs text-destructive`,children:J.error}):d&&J.text==null?(0,Q.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`Loading content…`}):(0,Q.jsx)(St,{kind:u?`markdown`:f,value:B,onChange:ae,placeholder:u?`Write your note…`:void 0})]}),(0,Q.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Q.jsx)(q,{children:`Tags`}),(0,Q.jsx)(Ke,{tags:re,onChange:W,suggestions:de})]}),(0,Q.jsx)(Bn,{value:H,onChange:oe}),(0,Q.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Q.jsx)(q,{htmlFor:`edit-comment`,children:`Comment`}),(0,Q.jsx)(`textarea`,{id:`edit-comment`,value:V,onChange:e=>U(e.target.value),rows:3,placeholder:`Add context you can't infer from the content, e.g. “sofa from the cozmo bar in Košice”`,className:`flex w-full rounded-md border border-input bg-transparent px-3 py-2 text-sm shadow-elevation-1 transition-colors placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-50`})]}),u&&(0,Q.jsx)(bt,{...R,onRetry:R.save}),(0,Q.jsxs)(`div`,{className:`flex justify-end gap-2 pt-2`,children:[(0,Q.jsx)(K,{variant:`outline`,size:`sm`,onClick:()=>n(),disabled:me,children:u?`Close`:`Cancel`}),(0,Q.jsx)(K,{size:`sm`,onClick:Se,disabled:!be,children:me?_e?`Replicating to ${ve.label}…`:`Saving…`:`Save changes`})]})]})}var Kn=(0,Z.createContext)(null),qn={entry:null,open:()=>{},close:()=>{}};function Jn(){return(0,Z.useContext)(Kn)??qn}var Yn=`main`,Xn=(0,Z.createContext)(null);function Zn(){return(0,Z.useContext)(Xn)}var Qn=50;function $n({relation:e,workspaceId:t,direction:n,onRemove:r,removing:i}){let{open:a}=Ct(),o=Jn(),s=Zn(),c=n===`out`?e.to:e.from,l=e.document??null,u=l?fe(l).title:``,[d,f]=(0,Z.useState)(!1),{showErrorToast:p}=X(),m=async()=>{if(!(c==null||!l)){f(!0);try{let n=e.preview?await Pe(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)(ae,{className:`h-3.5 w-3.5 shrink-0 text-muted-foreground`}):(0,Q.jsx)(ee,{className:`h-3.5 w-3.5 shrink-0 text-muted-foreground`}),l?(0,Q.jsx)(ht,{document:l,size:3.5}):null,l?(0,Q.jsx)(`button`,{type:`button`,onClick:()=>void m(),disabled:d,className:`min-w-0 flex-1 truncate text-left hover:underline`,title:u,children:u}):(0,Q.jsxs)(`span`,{className:`min-w-0 flex-1 truncate italic text-muted-foreground`,children:[`Document `,c,` (not available)`]}),(0,Q.jsxs)(`span`,{className:`shrink-0 font-mono text-[10px] text-muted-foreground`,children:[`#`,c]}),!h&&(0,Q.jsx)(`span`,{className:`shrink-0 rounded-full bg-muted px-1.5 py-0.5 text-[10px] text-muted-foreground`,title:`Derived by ${e.meta?.src}`,children:e.meta?.src}),h&&(0,Q.jsx)(`button`,{type:`button`,onClick:r,disabled:i,className:`shrink-0 rounded p-1 text-muted-foreground opacity-0 transition-opacity hover:bg-destructive/10 hover:text-destructive group-hover:opacity-100 disabled:opacity-40`,title:`Remove relation`,"aria-label":`Remove relation`,children:(0,Q.jsx)(T,{className:`h-3.5 w-3.5`})})]})}function er({document:e,workspaceId:t}){let{showSuccessToast:n,showErrorToast:r}=X(),[i,a]=(0,Z.useState)(null),[o,s]=(0,Z.useState)(null),[c,l]=(0,Z.useState)(!1),[u,d]=(0,Z.useState)(!1),[f,p]=(0,Z.useState)(null),[m,h]=(0,Z.useState)(0),[g,_]=(0,Z.useState)(1),v=(0,Z.useRef)(0),y=(0,Z.useCallback)(()=>{v.current++},[]),x=(0,Z.useCallback)(async()=>{let n=++v.current;try{let r=await Te(t,e.id,{offset:m*Qn,limit:Qn,summary:!0});if(n!==v.current)return;let i=Math.max(0,Math.ceil(Math.max(r.outgoingCount??r.outgoing.length,r.incomingCount??r.incoming.length)/Qn)-1);if(_(i+1),m>i){h(i);return}a(r),s(null)}catch(e){if(n!==v.current)return;s(e instanceof Error?e.message:String(e))}},[t,e.id,m]),S=`${t}:${e.id}`,[C,w]=(0,Z.useState)(S);S!==C&&(w(S),a(null),s(null),h(0),_(1)),(0,Z.useEffect)(()=>{async function e(){await x()}return e(),window.addEventListener(ct,e),()=>{y(),window.removeEventListener(ct,e)}},[x,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 we(t,e.id,i.p,o,a),n(`Relation removed`),st()}catch(e){r(e instanceof Error?e.message:`Failed to remove relation`)}finally{p(null)}},E=[{dir:`out`,title:`Points at`,hint:`this document as the subject`,entries:i?.outgoing??[]},{dir:`in`,title:`Pointed at by`,hint:`this document as the object`,entries:i?.incoming??[]}],D=e=>{a(null),h(e)};return(0,Q.jsxs)(`div`,{children:[(0,Q.jsxs)(`div`,{className:`mb-2 flex items-center justify-between gap-2`,children:[(0,Q.jsx)(`h3`,{className:`font-semibold`,children:`Documents`}),(0,Q.jsxs)(K,{variant:`outline`,size:`sm`,onClick:()=>l(!0),children:[(0,Q.jsx)(b,{className:`mr-1 h-3 w-3`}),` Add relation`]})]}),o?(0,Q.jsx)(`p`,{className:`text-sm text-destructive`,children:o}):i?E.every(e=>e.entries.length===0)?(0,Q.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`No related documents.`}):(0,Q.jsx)(`div`,{className:`space-y-4`,children:E.filter(e=>e.entries.length>0).map(({dir:e,title:n,hint:r,entries:i})=>(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`p`,{className:`mb-1 text-xs font-medium text-muted-foreground`,title:r,children:n}),Array.from(new Set(i.map(e=>e.p))).map(n=>(0,Q.jsxs)(`div`,{className:`mb-2`,children:[(0,Q.jsx)(`p`,{className:`px-2 font-mono text-[11px] text-muted-foreground`,children:n}),i.filter(e=>e.p===n).map(n=>{let r=e===`out`?n.to:n.from,i=`${e}:${n.p}:${r}`;return(0,Q.jsx)($n,{relation:n,workspaceId:t,direction:e,removing:f===i,onRemove:()=>void T(n,e)},i)})]},n))]},e))}):(0,Q.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`Loading relations…`}),(g>1||m>0)&&(0,Q.jsxs)(`div`,{className:`mt-3 flex items-center justify-between gap-2 text-xs text-muted-foreground`,children:[(0,Q.jsx)(K,{variant:`outline`,size:`sm`,disabled:m===0,onClick:()=>D(m-1),children:`Previous`}),(0,Q.jsxs)(`span`,{children:[`Page `,m+1,` of `,g]}),(0,Q.jsx)(K,{variant:`outline`,size:`sm`,disabled:!i||m+1>=g,onClick:()=>D(m+1),children:`Next`})]}),c&&(0,Q.jsx)(yt,{onClose:()=>{u||l(!1)},children:(0,Q.jsx)(de,{sizeClassName:`h-full w-[380px] max-w-[90vw] max-md:w-full`,title:`Relate to…`,tabs:[`relations`],fixedWorkspaceName:t,documentCount:1,saving:u,relationPredicates:i?.predicates,relationExcludeIds:new Set([e.id]),onClose:()=>l(!1),onConfirm:()=>{},onConfirmRelation:async({predicate:i,direction:a,targetIds:o})=>{d(!0);try{await Ee(t,e.id,i,o,a),n(`Related to ${o.length} document${o.length===1?``:`s`}`),l(!1),st()}catch(e){r(e instanceof Error?e.message:`Failed to create relation`)}finally{d(!1)}}})})]})}var tr=(0,Z.lazy)(()=>a(()=>import(`./TextDocumentEditor-rgHsbLCL.js`),__vite__mapDeps([2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,1,24]))),nr={reply:`Reply`,replyAll:`Reply all`,forward:`Forward`},rr={reply:u,replyAll:l,forward:d};function ir({document:e,workspaceId:t,initialEdit:n=!1,onChanged:r}){let i=Je()!=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),[p,m]=(0,Z.useState)(!1),h=[`data/schema/message`,`data/schema/message/email`].includes(e.schema),[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=>_(t=>t===e?null:e),S=!i,[C,w]=(0,Z.useState)(n&&!i),T=e.schema===be,[D,O]=(0,Z.useState)(!1),k=e.schema===`data/schema/note`||Ze(e),[A,j]=(0,Z.useState)(!1),M=`${t}:${e.id}:${n}:${i}`,[ee,N]=(0,Z.useState)(M);M!==ee&&(N(M),w(n&&!i),_(null),m(!1),O(!1),j(!1));let P=t=>{if(!S||!Hn(e)||t.defaultPrevented)return!1;let n=t.target;return n instanceof Element&&t.currentTarget.contains(n)&&!n.closest(`a, button, input, textarea, select, label, summary, audio, video, [role="button"], [role="checkbox"], [contenteditable]:not([contenteditable="false"])`)};return C&&S?(0,Q.jsx)(Gn,{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:[h&&(0,Q.jsx)(K,{size:`sm`,variant:p?`secondary`:`outline`,onClick:()=>m(!p),children:p?`Show message`:`View thread`}),y&&b.map(e=>{let t=rr[e];return(0,Q.jsxs)(K,{size:`sm`,variant:g===e?`secondary`:`outline`,onClick:()=>x(e),children:[(0,Q.jsx)(t,{className:`mr-1.5 h-3.5 w-3.5`}),nr[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)(U,{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:()=>ve(t,e.id,Y(e)||`document-${e.id}`).catch(e=>a(e instanceof Error?e.message:String(e))),children:[(0,Q.jsx)(U,{className:`mr-1 h-3 w-3`}),` Download`]}),T&&(0,Q.jsxs)(K,{variant:`outline`,size:`sm`,onClick:()=>O(!0),children:[(0,Q.jsx)(E,{className:`mr-1 h-3 w-3`}),` Edit sketch`]}),k&&(0,Q.jsxs)(K,{variant:`outline`,size:`sm`,onClick:()=>j(!0),children:[(0,Q.jsx)(f,{className:`mr-1 h-3 w-3`}),` Open editor`]}),(0,Q.jsxs)(K,{variant:`outline`,size:`sm`,onClick:()=>w(!0),children:[(0,Q.jsx)(s,{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)(wt,{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)(tr,{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:[p&&!i?(0,Q.jsx)(An,{workspaceId:t,documentId:Number(e.id)},`${t}:${e.id}`):(0,Q.jsx)(kn,{workspaceId:t,document:e}),g&&y&&(0,Q.jsx)(vt,{workspaceId:t,replyToDocumentId:Number(e.id),mode:g,originalSubject:v&&typeof e.data?.subject==`string`?e.data.subject:void 0,onClose:()=>_(null)},`${e.id}:${g}`)]}),e.comment?.trim()&&(0,Q.jsxs)(`div`,{className:`shrink-0 rounded-md border border-border bg-muted/40 px-3 py-2`,children:[(0,Q.jsx)(`p`,{className:`text-xs font-medium text-muted-foreground mb-0.5`,children:`Comment`}),(0,Q.jsx)(`p`,{className:`text-sm whitespace-pre-wrap`,children:e.comment})]})]})}var ar=e=>e?new Date(e).toLocaleDateString(`en-US`,{year:`numeric`,month:`long`,day:`numeric`,hour:`2-digit`,minute:`2-digit`,second:`2-digit`}):`—`,or=e=>!Number.isFinite(e)||!e?null:e>=1?`${e}s`:`1/${Math.round(1/e)}s`;function sr({meta:e}){let{geo:t,exif:n,dimensions:r}=e;if(!t&&!n&&!r)return null;let i=(e,t)=>t==null||t===``?null:(0,Q.jsxs)(`div`,{children:[(0,Q.jsxs)(`span`,{className:`font-medium`,children:[e,`:`]}),(0,Q.jsx)(`span`,{className:`ml-2`,children:t})]});return(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`h3`,{className:`font-semibold mb-3`,children:`Photo`}),(0,Q.jsxs)(`div`,{className:`grid gap-3 text-sm`,children:[r&&i(`Dimensions`,r.width&&r.height?`${r.width} × ${r.height}`:null),n&&i(`Camera`,[n.make,n.model].filter(Boolean).join(` `)),n&&i(`Lens`,n.lensModel),n&&i(`Aperture`,Number.isFinite(n.fNumber)?`ƒ/${n.fNumber}`:null),n&&i(`Shutter`,or(n.exposureTime)),n&&i(`ISO`,Number.isFinite(n.iso)?n.iso:null),n&&i(`Focal length`,Number.isFinite(n.focalLength)?`${n.focalLength} mm`:null),n&&i(`Captured`,ar(n.capturedAt)),t&&Number.isFinite(t.lat)&&Number.isFinite(t.lon)&&i(`Location`,(0,Q.jsxs)(`a`,{href:`https://www.openstreetmap.org/?mlat=${t.lat}&mlon=${t.lon}#map=15/${t.lat}/${t.lon}`,target:`_blank`,rel:`noopener noreferrer`,className:`text-primary underline underline-offset-2`,children:[t.lat.toFixed(5),`, `,t.lon.toFixed(5),Number.isFinite(t.alt)?` · ${Math.round(t.alt)} m`:``]}))]})]})}function cr({document:e}){let t=e.metadata;return(0,Q.jsxs)(`div`,{className:`space-y-6`,children:[(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`h3`,{className:`font-semibold mb-3`,children:`Basic Information`}),(0,Q.jsxs)(`div`,{className:`grid gap-3 text-sm`,children:[(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`span`,{className:`font-medium`,children:`ID:`}),(0,Q.jsx)(`span`,{className:`ml-2 font-mono`,children:e.id})]}),(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`span`,{className:`font-medium`,children:`Schema:`}),(0,Q.jsx)(`span`,{className:`ml-2 font-mono`,children:e.schema})]}),(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`span`,{className:`font-medium`,children:`Schema Version:`}),(0,Q.jsx)(`span`,{className:`ml-2`,children:e.schemaVersion})]}),(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`span`,{className:`font-medium`,children:`Created:`}),(0,Q.jsx)(`span`,{className:`ml-2`,children:ar(e.createdAt)})]}),(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`span`,{className:`font-medium`,children:`Updated:`}),(0,Q.jsx)(`span`,{className:`ml-2`,children:ar(e.updatedAt)})]})]})]}),(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`h3`,{className:`font-semibold mb-3`,children:`Metadata`}),(0,Q.jsxs)(`div`,{className:`grid gap-3 text-sm`,children:[(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`span`,{className:`font-medium`,children:`Content Type:`}),(0,Q.jsx)(`span`,{className:`ml-2`,children:e.metadata?.contentType??`—`})]}),(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`span`,{className:`font-medium`,children:`Content Encoding:`}),(0,Q.jsx)(`span`,{className:`ml-2`,children:e.metadata?.contentEncoding??`—`})]}),Number.isFinite(e.metadata?.size)&&(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`span`,{className:`font-medium`,children:`Size:`}),(0,Q.jsxs)(`span`,{className:`ml-2`,children:[e.metadata?.size,` bytes`]})]})]})]}),(0,Q.jsx)(sr,{meta:t}),Array.isArray(e.locations)&&e.locations.length>0&&(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`h3`,{className:`font-semibold mb-3`,children:`Locations`}),(0,Q.jsx)(`div`,{className:`space-y-2`,children:e.locations.map((e,t)=>{let{backend:n,key:r}=fr(e.url);return(0,Q.jsxs)(`div`,{className:`flex items-baseline gap-2 text-sm font-mono`,children:[(0,Q.jsx)(`span`,{className:`font-medium shrink-0`,children:n}),e.status&&e.status!==`available`&&(0,Q.jsx)(`span`,{className:`shrink-0 rounded border px-1 text-xs`,title:e.statusChangedAt,children:e.status===`deleted`?`Deleted`:`Not found`}),r&&(0,Q.jsx)(`span`,{className:`break-all text-muted-foreground`,children:r})]},t)})})]}),Array.isArray(e.checksumArray)&&e.checksumArray.length>0&&(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`h3`,{className:`font-semibold mb-3`,children:`Checksums`}),(0,Q.jsx)(`div`,{className:`space-y-2`,children:e.checksumArray.map((e,t)=>{let[n,r]=e.split(`/`);return(0,Q.jsxs)(`div`,{className:`flex items-center gap-2 text-sm font-mono`,children:[(0,Q.jsxs)(`span`,{className:`font-medium`,children:[n,`:`]}),(0,Q.jsx)(`span`,{className:`break-all text-muted-foreground`,children:r})]},t)})})]}),e.indexOptions&&(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`h3`,{className:`font-semibold mb-3`,children:`Index Options`}),(0,Q.jsxs)(`div`,{className:`space-y-3 text-sm`,children:[(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`span`,{className:`font-medium`,children:`FTS Search Fields:`}),(0,Q.jsx)(`div`,{className:`ml-2 mt-1`,children:(e.indexOptions.ftsSearchFields??[]).map((e,t)=>(0,Q.jsx)(`span`,{className:`mb-1 mr-2 inline-block rounded bg-muted px-2 py-1 text-xs`,children:e},t))})]}),(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`span`,{className:`font-medium`,children:`Vector Embedding Fields:`}),(0,Q.jsx)(`div`,{className:`ml-2 mt-1`,children:(e.indexOptions.vectorEmbeddingFields??[]).map((e,t)=>(0,Q.jsx)(`span`,{className:`mb-1 mr-2 inline-block rounded bg-muted px-2 py-1 text-xs`,children:e},t))})]})]})]})]})}function lr({document:e}){let{showSuccessToast:t,showErrorToast:n}=X(),r=JSON.stringify(e,null,2);return(0,Q.jsxs)(`div`,{className:`space-y-2`,children:[(0,Q.jsx)(`div`,{className:`flex justify-end`,children:(0,Q.jsxs)(K,{variant:`outline`,size:`sm`,onClick:async()=>{try{await navigator.clipboard.writeText(r),t(`Copied to clipboard`)}catch{n(`Copy failed`)}},children:[(0,Q.jsx)(S,{className:`mr-1 h-3 w-3`}),` Copy to clipboard`]})}),(0,Q.jsx)(`pre`,{className:`overflow-x-auto rounded-lg bg-muted p-4 text-xs`,children:r})]})}function ur({document:e,workspaceId:t}){let[n,r]=(0,Z.useState)(null),[i,a]=(0,Z.useState)(null),o=`${t}:${e.id}`,[s,c]=(0,Z.useState)(o);return o!==s&&(c(o),r(null),a(null)),(0,Z.useEffect)(()=>{let n=!1;return _e(t,e.id).then(e=>{n||r(e)}).catch(e=>{n||a(e instanceof Error?e.message:String(e))}),()=>{n=!0}},[o]),i?(0,Q.jsx)(`p`,{className:`text-sm text-destructive`,children:i}):n?(0,Q.jsxs)(`div`,{className:`space-y-6`,children:[[{title:`Context tree`,type:`context`},{title:`Directory tree`,type:`directory`}].map(({title:e,type:t})=>{let r=n.filter(e=>e.type===t),i=r.flatMap(e=>e.paths.map(t=>({tree:e.tree,path:t})));return(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`h3`,{className:`mb-3 font-semibold`,children:e}),i.length===0?(0,Q.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`No placements.`}):(0,Q.jsx)(`div`,{className:`space-y-1`,children:i.map(({tree:e,path:t},n)=>(0,Q.jsxs)(`div`,{className:`flex items-center gap-2 text-sm`,children:[(0,Q.jsx)(`span`,{className:`break-all font-mono text-xs`,children:t}),r.length>1&&(0,Q.jsxs)(`span`,{className:`shrink-0 text-xs text-muted-foreground`,children:[`(`,e,`)`]})]},`${e}:${t}:${n}`))})]},t)}),(0,Q.jsx)(er,{document:e,workspaceId:t})]}):(0,Q.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`Loading memberships...`})}function dr(e){return e===`stored`?k:e===`workspace-file`?o:e===`imap`?A:e===`readonly`?C:F}function fr(e){let t=e.match(/^([a-z][a-z0-9+.-]*):\/\/([^/]*)\/?(.*)$/i);return t?{backend:`${t[1]}://${t[2]}`,key:t[3]}:{backend:e,key:``}}function pr({document:e,workspaceId:t,onChanged:n}){let{showSuccessToast:r,showErrorToast:i}=X(),[a,o]=(0,Z.useState)(null),[s,c]=(0,Z.useState)(null),[l,u]=(0,Z.useState)(null),[d,f]=(0,Z.useState)(null),[p,m]=(0,Z.useState)(null),[h,g]=(0,Z.useState)(!1),_=`${t}:${e.id}`,[v,y]=(0,Z.useState)(_);_!==v&&(y(_),o(null),c(null),f(null));let b=()=>{je(t,e.id).then(o).catch(e=>c(e instanceof Error?e.message:String(e)))};(0,Z.useEffect)(()=>{let n=!1;return je(t,e.id).then(e=>{n||o(e)}).catch(e=>{n||c(e instanceof Error?e.message:String(e))}),()=>{n=!0}},[_]);let x=async(a,o)=>{u(a),f(null);try{let i=await me(t,[e.id],{urls:[a],...o===void 0?{}:{keepDocument:o}}),s=i.successful[0];if(!s)throw Error(i.failed[0]?.reason||`Destroy failed`);s.docDeleted?r(`Removed from backend; document removed from index`):s.deleted.includes(a)?r(`Removed from backend`):r(`Reference dropped (backend is read-only)`),window.dispatchEvent(new CustomEvent(`workspace:documents:refresh`)),n?.(),b()}catch(e){i(e instanceof Error?e.message:String(e))}finally{u(null)}},C=async(a,o,s)=>{g(!0);try{let i=await Ae(t,[e.id],{to:a,mode:o,keepDocument:s.keepDocument,folder:s.folder,filename:s.filename,onConflict:s.onConflict}),c=i.successful[0];if(!c)throw Error(jn(i.failed,new Map([[e.id,Y(e)||`Document ${e.id}`]]))||`Transfer failed`);let l=c.transfers?.flatMap(e=>e.state===`unchanged`?[]:[e.backend])??[],u=a.join(`, `);o===`delete`?r(`Deleted from ${u}`):l.length===0?r(`Nothing to do — already on ${u}`):r(`${o===`move`?`Moved to`:`Copied to`} ${l.join(`, `)}${c.transfers?.some(e=>e.state===`pending`)?` (pending sync)`:``}`),window.dispatchEvent(new CustomEvent(`workspace:documents:refresh`)),m(null),n?.(),b()}catch(e){i(e instanceof Error?e.message:String(e))}finally{g(!1)}},w=e=>{if((a?.length??0)<=1){f(e.url);return}window.confirm(`Remove this copy from the backend?\n\n${e.url}`)&&x(e.url)};if(s)return(0,Q.jsx)(`p`,{className:`text-sm text-destructive`,children:s});if(!a)return(0,Q.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`Loading locations...`});let E=a.length===0,D=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)(k,{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`})]}),E?(0,Q.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`No byte locations; this object lives only in the workspace database, so there is no file data to copy or move.`}):(0,Q.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,Q.jsxs)(K,{variant:`outline`,size:`sm`,onClick:()=>m(`copy`),title:`Copy the file data to another storage backend (keeps the existing copies)`,children:[(0,Q.jsx)(S,{className:`mr-1 h-3.5 w-3.5`}),` Copy to…`]}),(0,Q.jsxs)(K,{variant:`outline`,size:`sm`,onClick:()=>m(`move`),title:`Move the file data to another storage backend (source released once the copy is durable)`,children:[(0,Q.jsx)(ae,{className:`mr-1 h-3.5 w-3.5`}),` Move to…`]})]}),a.map(n=>{let r=dr(n.kind),{backend:a,key:o}=fr(n.url),s=l===n.url;return(0,Q.jsxs)(`div`,{className:`space-y-2 rounded border px-3 py-2 text-sm`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,Q.jsxs)(`span`,{className:`inline-flex min-w-0 items-center gap-2`,children:[(0,Q.jsx)(r,{className:`h-4 w-4 shrink-0 text-muted-foreground`}),(0,Q.jsx)(`span`,{className:`shrink-0 font-mono text-xs`,children:n.backend||a}),(0,Q.jsx)(`span`,{className:`truncate font-mono text-xs text-muted-foreground`,title:n.url,children:o||n.url})]}),(0,Q.jsxs)(`span`,{className:`flex shrink-0 items-center gap-2`,children:[(0,Q.jsx)(`span`,{className:`rounded px-1.5 py-0.5 text-[10px] uppercase ${n.deletable?`bg-muted text-muted-foreground`:`bg-warning/15 text-warning`}`,children:n.deletable?n.kind:`read-only`}),(0,Q.jsx)(`button`,{onClick:()=>ve(t,e.id,D||`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)(U,{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)(T,{className:`h-3.5 w-3.5`})})]})]}),d===n.url&&(0,Q.jsxs)(`div`,{className:`space-y-2 rounded border border-destructive/40 bg-destructive/5 p-2`,children:[(0,Q.jsxs)(`p`,{className:`text-xs`,children:[`This is the object's `,(0,Q.jsx)(`strong`,{children:`last`}),` location. Remove the bytes from the backend and…`]}),(0,Q.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[(0,Q.jsx)(K,{variant:`destructive`,size:`sm`,disabled:s,onClick:()=>void x(n.url,!1),children:`Also remove index entry`}),(0,Q.jsx)(K,{variant:`outline`,size:`sm`,disabled:s,onClick:()=>void x(n.url,!0),children:`Keep index entry (no bytes)`}),(0,Q.jsx)(K,{variant:`ghost`,size:`sm`,onClick:()=>f(null),children:`Cancel`})]})]})]},n.url)}),p&&(0,Mn.createPortal)((0,Q.jsx)(`div`,{className:`fixed inset-0 z-picker flex items-center justify-center bg-scrim p-4 max-md:p-2`,children:(0,Q.jsx)(Ln,{workspaceId:t,documentCount:1,initialMode:p,defaultFilename:D,saving:h,onConfirm:C,onClose:()=>{h||m(null)}})}),window.document.body)]})}var mr=(0,Z.lazy)(()=>a(()=>import(`./LocationTab-DAtqAQ3l.js`),__vite__mapDeps([25,3,4,26,27]))),hr=[{id:`view`,label:`View`,icon:N},{id:`location`,label:`Location`,icon:ie},{id:`metadata`,label:`Metadata`,icon:te},{id:`json`,label:`JSON`,icon:x},{id:`synapses`,label:`Synapses`,icon:ne},{id:`backends`,label:`Backends`,icon:k}];function gr({document:e,workspaceId:t,initialTab:n=`view`,initialEdit:r=!1,onChanged:i,className:a=``,compact:o=!1,navigation:s,tabActions:c,onTabChange:l}){let u=Je()!=null,d=Tt(e),f=hr.filter(e=>(e.id!==`location`||d!==null)&&(!u||![`synapses`,`backends`].includes(e.id))),[p,m]=(0,Z.useState)(n),h=`${e.id}:${n}`,[g,_]=(0,Z.useState)(h);h!==g&&(_(h),m(n));let v=f.some(e=>e.id===p)?p:`view`,y=e=>{m(e),l?.(e)},b=o&&!!c&&!s,x=(0,Q.jsx)(`div`,{className:G(b&&`document-detail-header shrink-0 border-b-[3px] bg-muted`),children:(0,Q.jsxs)(`div`,{className:G(`flex min-w-0 items-center`,b&&`mx-auto h-[calc(3rem-4px)] w-full max-w-[var(--document-reading-width,100%)] gap-1 pl-2 pr-2 sm:pl-4`),children:[(0,Q.jsx)(_t,{tabs:f,active:v,onChange:y,className:G(`min-w-0 flex-1 px-1`,b&&`h-full border-b-0 px-0 max-sm:gap-0 max-sm:[&>button]:px-2.5`),iconOnly:o}),c]})});return(0,Q.jsxs)(`div`,{className:`flex h-full min-h-0 flex-col ${a}`,children:[s?(0,Q.jsx)(On,{...s,tabs:x,section:v,onDocument:()=>y(`view`),onSection:()=>y(`view`),onBack:v===`view`?s.onBack:()=>y(`view`)}):x,(0,Q.jsx)(`div`,{className:`min-h-0 flex-1 overflow-y-auto`,children:(0,Q.jsxs)(`div`,{className:`mx-auto h-full w-full max-w-[var(--document-reading-width,100%)] p-4`,children:[v===`view`&&(0,Q.jsx)(ir,{document:e,workspaceId:t,initialEdit:r&&!u,onChanged:i}),v===`location`&&d&&(0,Q.jsx)(Z.Suspense,{fallback:(0,Q.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`Loading map…`}),children:(0,Q.jsx)(mr,{lat:d.lat,lon:d.lon})}),v===`metadata`&&(0,Q.jsx)(cr,{document:e,workspaceId:t}),v===`json`&&(0,Q.jsx)(lr,{document:e,workspaceId:t}),v===`synapses`&&!u&&(0,Q.jsx)(ur,{document:e,workspaceId:t}),v===`backends`&&!u&&(0,Q.jsx)(pr,{document:e,workspaceId:t,onChanged:i})]})})]})}export{en as _,Kn as a,Dt as b,Ln as c,Dn as d,wn as f,an as g,nn as h,Zn as i,jn as l,rn as m,Xn as n,Jn as o,tn as p,Yn as r,Bn as s,gr as t,On as u,Ut as v,Pt as y};
|
|
7
|
+
</head><body>${t}</body></html>`;return{url:URL.createObjectURL(new Blob([i],{type:`text/html;charset=utf-8`})),remoteCount:r}}finally{pt.removeHook(`afterSanitizeAttributes`)}}function dn(e){return new Promise((t,n)=>{let r=new FileReader;r.onload=()=>t(String(r.result)),r.onerror=()=>n(r.error),r.readAsDataURL(e)})}function fn(e){return(0,Q.jsx)(pn,{...e},`${e.workspaceId}:${e.document.id}`)}function pn({workspaceId:e,document:t,className:n=``}){let{fetchBlob:r,download:i}=Ye(e),a=t.data||{},o=Array.isArray(a.attachments)?a.attachments:[],{body:s,bodyHtml:l,loading:u,error:d}=sn(e,t),[f,p]=(0,Z.useState)(null),[m,h]=(0,Z.useState)(!1),[g,v]=(0,Z.useState)(!1),[b,x]=(0,Z.useState)(0),[S,C]=(0,Z.useState)(null);(0,Z.useEffect)(()=>{if(!l||m)return;let e=!1,n=[],i=o.filter(e=>e.contentId&&e.url);return Promise.all(i.slice(0,20).map(async e=>{try{let{blob:n}=await r(t.id,{url:e.url}),i=await dn(n);return[String(e.contentId).replace(/^<|>$/g,``),i]}catch{return null}})).then(t=>{if(e)return;let r=new Map(t.filter(Boolean)),{url:i,remoteCount:a}=un(l,r,g);n.push(i),p(i),x(a)}).catch(t=>{e||C(String(t instanceof Error?t.message:t))}),()=>{e=!0,n.forEach(e=>URL.revokeObjectURL(e)),p(null)}},[e,t.id,l,m,g]);let w=typeof a.date==`string`?new Date(a.date).toLocaleString():null,T=o.filter(e=>!e.isInline||!e.contentId),E=async e=>{if(e.url)try{await i(t.id,e.filename||`attachment`,{url:e.url})}catch(e){C(e instanceof Error?e.message:String(e))}};return(0,Q.jsxs)(`div`,{className:`flex h-full min-h-0 min-w-0 flex-col gap-3 ${n}`,children:[(0,Q.jsx)(`div`,{className:`shrink-0 rounded-md border bg-muted/30 p-2 text-sm sm:p-3`,children:(0,Q.jsxs)(`div`,{className:`flex flex-wrap items-start justify-between gap-2 sm:gap-3`,children:[(0,Q.jsxs)(`div`,{className:`min-w-0 flex-1 basis-64 space-y-1`,children:[(0,Q.jsx)(`div`,{className:`truncate text-base font-semibold`,children:String(a.subject??`(no subject)`)}),(0,Q.jsxs)(`details`,{className:`sm:hidden`,children:[(0,Q.jsxs)(`summary`,{className:`cursor-pointer text-xs`,children:[(0,Q.jsx)(`span`,{className:`inline-block max-w-[85%] truncate align-bottom`,children:typeof a.from==`object`&&a.from?a.from.name||a.from.address:String(a.from||`Unknown sender`)}),(0,Q.jsx)(`span`,{className:`ml-2 text-muted-foreground`,children:`Details`})]}),(0,Q.jsxs)(`div`,{className:`mt-2 space-y-1 break-words text-xs`,children:[(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`span`,{className:`text-muted-foreground`,children:`From:`}),` `,cn(a.from)]}),$(a.to)&&(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`span`,{className:`text-muted-foreground`,children:`To:`}),` `,$(a.to)]}),$(a.cc)&&(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`span`,{className:`text-muted-foreground`,children:`Cc:`}),` `,$(a.cc)]}),w&&(0,Q.jsx)(`div`,{className:`text-xs text-muted-foreground`,children:w})]})]}),(0,Q.jsxs)(`div`,{className:`hidden space-y-1 break-words sm:block`,children:[(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`span`,{className:`text-muted-foreground`,children:`From:`}),` `,cn(a.from)]}),$(a.to)&&(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`span`,{className:`text-muted-foreground`,children:`To:`}),` `,$(a.to)]}),$(a.cc)&&(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`span`,{className:`text-muted-foreground`,children:`Cc:`}),` `,$(a.cc)]}),w&&(0,Q.jsx)(`div`,{className:`text-xs text-muted-foreground`,children:w})]})]}),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)(c,{className:`mr-1.5 h-3.5 w-3.5`}):(0,Q.jsx)(B,{className:`mr-1.5 h-3.5 w-3.5`}),m?`HTML`:`Plain text`]}),!m&&b>0&&(0,Q.jsxs)(K,{size:`sm`,variant:g?`secondary`:`outline`,onClick:()=>v(!g),title:`Remote images can reveal your IP/read status to the sender`,children:[g?(0,Q.jsx)(y,{className:`mr-1.5 h-3.5 w-3.5`}):(0,Q.jsx)(_,{className:`mr-1.5 h-3.5 w-3.5`}),g?`Hide remote images`:`Show remote images (${b})`]})]})]})}),(S||d)&&(0,Q.jsx)(`p`,{className:`text-sm text-destructive`,children:S||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:s||`(empty body)`}),T.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 (`,T.length,`)`]}),T.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)(B,{className:`h-4 w-4 shrink-0 text-muted-foreground`}),(0,Q.jsx)(`span`,{className:`truncate`,children:e.filename||`attachment`}),(0,Q.jsx)(`span`,{className:`shrink-0 text-xs text-muted-foreground`,children:ln(e.size)})]}),e.url&&(0,Q.jsxs)(`button`,{onClick:()=>E(e),className:`inline-flex shrink-0 items-center gap-1 text-xs text-primary hover:underline`,children:[(0,Q.jsx)(U,{className:`h-3 w-3`}),` Download`]})]},e.url||t))]})]})}function mn({attachment:e,workspaceId:t,document:n}){let{download:r}=Ye(t),i=e.mimeType||e.contentType||``,a=e.name||e.filename||`Attachment`,o=i.startsWith(`audio/`)||i.startsWith(`video/`),{blobUrl:s,error:c,loading:l}=$e(t,n.id,{url:e.url,typeHint:i,enabled:!o&&!!e.url}),{src:u,error:d,loading:f}=tt(t,n.id,{url:e.url,enabled:o&&!!e.url}),[p,m]=(0,Z.useState)(!1),[h,g]=(0,Z.useState)(``),_=o?d:c;return(0,Q.jsxs)(`div`,{className:`space-y-2 rounded border p-2`,children:[_&&(0,Q.jsx)(`p`,{className:`text-xs text-destructive`,children:_}),(o?f:l)&&(0,Q.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`Loading attachment…`}),!o&&s&&i.startsWith(`image/`)&&(0,Q.jsx)(`img`,{src:s,alt:a,className:`max-h-96 max-w-full rounded object-contain`}),o&&u&&(i.startsWith(`video/`)?(0,Q.jsx)(`video`,{controls:!0,playsInline:!0,preload:`metadata`,src:u,onError:()=>m(!0),className:`max-h-96 w-full rounded`},u):(0,Q.jsx)(`audio`,{controls:!0,preload:`metadata`,src:u,onError:()=>m(!0),className:`w-full`},u)),p&&(0,Q.jsx)(`p`,{role:`alert`,className:`text-xs text-destructive`,children:`This media could not be played in your browser. Download it to play in another app.`}),h&&(0,Q.jsx)(`p`,{role:`alert`,className:`text-xs text-destructive`,children:h}),e.url&&(0,Q.jsxs)(`button`,{className:`text-sm text-primary underline`,onClick:()=>{r(n.id,a,{url:e.url}).catch(()=>g(`Attachment could not be downloaded.`))},children:[`Download `,a]})]})}function hn(e){let t=e.document.data,n=t.sender,r=t.channel,i=Array.isArray(t.attachments)?t.attachments:[],a=t.timestamp?new Date(String(t.timestamp)):null;return(0,Q.jsxs)(`article`,{className:`space-y-4 p-3 ${e.className||``}`,children:[(0,Q.jsxs)(`header`,{className:`space-y-1 border-b pb-3`,children:[(0,Q.jsx)(`p`,{className:`font-medium`,children:n?.name||n?.displayName||n?.username||n?.id||`Unknown sender`}),(0,Q.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:[r?.name||r?.id,String(t.platform||``),a&&!Number.isNaN(a.getTime())?a.toLocaleString():``].filter(Boolean).join(` · `)})]}),(0,Q.jsx)(`p`,{className:`whitespace-pre-wrap break-words text-sm`,children:String(t.text||`(No text)`)}),!!t.mediaError&&(0,Q.jsx)(`p`,{className:`text-xs text-destructive`,children:String(t.mediaError)}),i.map((t,n)=>(0,Q.jsx)(mn,{...e,attachment:t},t.url||n))]})}var gn={email:A,phone:oe,sms:M,chat:M,slack:M,matrix:M,web:C,url:C},_n={person:`Person`,organization:`Organization`,service:`Service`,bot:`Bot`},vn=e=>Array.isArray(e)?e:[];function yn(e,t){return t?e===`email`?`mailto:${t}`:e===`phone`||e===`sms`?`tel:${t.replace(/[^\d+]/g,``)}`:/^https?:\/\//i.test(t)?t:null:null}function bn({title:e,count:t,children:n}){return t===0?null:(0,Q.jsxs)(`div`,{className:`space-y-1`,children:[(0,Q.jsx)(`p`,{className:`text-xs font-medium text-muted-foreground`,children:e}),(0,Q.jsx)(`div`,{className:`space-y-1`,children:n})]})}function xn({icon:e,primary:t,children:n,title:r}){return(0,Q.jsxs)(`div`,{className:`flex min-w-0 items-center gap-2 rounded-md border bg-card px-2.5 py-1.5 text-sm`,title:r,children:[(0,Q.jsx)(e,{className:`h-3.5 w-3.5 shrink-0 text-muted-foreground`}),(0,Q.jsx)(`div`,{className:`min-w-0 flex-1 truncate`,children:n}),t&&(0,Q.jsx)(R,{className:`h-3 w-3 shrink-0 fill-current text-data-5`,"aria-label":`Primary`})]})}function Sn({document:e,className:t}){let n=e.data??{},r=vn(n.identifiers),i=vn(n.channels),a=vn(n.organizations),o=vn(n.links),s=vn(n.tags),c=String(n.displayName||``).trim(),l=Ce(e.schema,xe),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:_n[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)(bn,{title:`Primary email`,count:1,children:(0,Q.jsx)(xn,{icon:A,primary:!0,children:(0,Q.jsx)(`a`,{href:`mailto:${u}`,className:`hover:underline`,children:u})})}),(0,Q.jsx)(bn,{title:`Channels`,count:i.length,children:i.map((e,t)=>{let n=String(e.kind||``).toLowerCase(),r=String(e.value||``),i=yn(n,r),a=gn[n]||M;return(0,Q.jsxs)(xn,{icon:a,primary:e.primary,title:e.platform||n,children:[i?(0,Q.jsx)(`a`,{href:i,className:`hover:underline`,target:i.startsWith(`http`)?`_blank`:void 0,rel:`noopener noreferrer`,children:r}):r,e.label&&(0,Q.jsx)(`span`,{className:`ml-2 text-xs text-muted-foreground`,children:e.label})]},`${n}:${r}:${t}`)})}),(0,Q.jsx)(bn,{title:`Identifiers`,count:r.length,children:r.map((e,t)=>(0,Q.jsxs)(xn,{icon:ie,primary:e.primary,children:[(0,Q.jsx)(`span`,{className:`font-mono text-xs`,children:e.identifier}),(0,Q.jsx)(`span`,{className:`ml-2 text-xs text-muted-foreground`,children:[e.type,e.provider].filter(Boolean).join(` · `)})]},`${e.type}:${e.identifier}:${t}`))}),(0,Q.jsx)(bn,{title:`Organizations`,count:a.length,children:a.map((e,t)=>(0,Q.jsxs)(xn,{icon:D,children:[e.name,e.role&&(0,Q.jsx)(`span`,{className:`ml-2 text-xs text-muted-foreground`,children:e.role})]},`${e.name}:${t}`))}),(0,Q.jsx)(bn,{title:`Links`,count:o.length,children:o.map((e,t)=>(0,Q.jsxs)(xn,{icon:O,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 Cn({document:e}){let t=String(e.metadata?.contentType||`application/octet-stream`);return(0,Q.jsxs)(`p`,{className:`text-sm text-muted-foreground`,children:[`No inline preview available for `,(0,Q.jsx)(`span`,{className:`font-mono`,children:t}),`. Use Download.`]})}function wn(e){let t=e.schema;if(t===`data/schema/note`)return Jt;if(t===`data/schema/drawing`)return Ut;if(t===`data/schema/task`)return on;if(t===`data/schema/message/email`)return fn;if(t===`data/schema/message`)return hn;if(t===`data/schema/identity`||t.startsWith(`data/schema/identity/`))return Sn;if(t===`data/schema/tab`||t===`data/schema/link`){let t=String(e.data?.url??e.data?.uri??``);return he(t)?Yt:Zt(t)?Xt:$t}if(t!==`data/schema/file`)return null;let n=String(e.metadata?.contentType||``);switch(Se(n,Y(e))){case`image`:return Ut;case`audio`:return Wt;case`video`:return Gt;case`pdf`:return Kt;case`markdown`:return Jt;case`text`:return qt;default:return Cn}}function Tn({onSearch:e,onDraftChange:t,inputRef:n,workspaceId:r,label:i=`Search documents`,clearOnSubmit:a=!0,showSubmitButton:o=!0}){let s=(0,Z.useRef)(null),c=n??s;return(0,Q.jsxs)(`form`,{className:`canvas-search-input`,role:`search`,onSubmit:n=>{n.preventDefault();let r=n.currentTarget.elements.namedItem(`query`),i=r.value.trim();i&&(e(i),a&&(r.value=``,t?.(``)))},children:[(0,Q.jsx)(`input`,{ref:c,name:`query`,type:`search`,"aria-label":i,placeholder:i,autoComplete:`off`,enterKeyHint:`search`,onChange:e=>t?.(e.target.value),onKeyDown:e=>{e.key===`Enter`&&e.nativeEvent.isComposing&&e.preventDefault()}}),o&&(0,Q.jsx)(`button`,{type:`submit`,className:`canvas-nav-button`,"aria-label":`Run search`,title:`Run search`,children:(0,Q.jsx)(W,{size:17})}),r&&(0,Q.jsx)(Dt,{workspaceId:r,inputRef:c,onChange:t})]})}function En({queries:e,onRemoveQuery:t,scope:n=`path`,onScopeChange:r}){return(0,Q.jsxs)(`div`,{className:`canvas-search-options`,children:[r&&(0,Q.jsxs)(`div`,{className:`canvas-search-scopes`,"aria-label":`Search scope`,children:[(0,Q.jsx)(`span`,{children:`Search in`}),(0,Q.jsx)(`button`,{type:`button`,"aria-pressed":n===`path`,onClick:()=>r(`path`),children:`This path`}),(0,Q.jsx)(`button`,{type:`button`,"aria-pressed":n===`workspace`,onClick:()=>r(`workspace`),children:`Workspace`})]}),e.length>0&&(0,Q.jsxs)(`div`,{className:`canvas-search-queries`,"aria-label":`Active searches`,children:[e.map((e,n)=>{let r=/"[^"]+/.test(e);return(0,Q.jsxs)(`span`,{className:r?`canvas-search-query canvas-search-query-exact`:`canvas-search-query`,children:[r?(0,Q.jsx)(P,{size:12,"aria-hidden":`true`}):(0,Q.jsx)(W,{size:12,"aria-hidden":`true`}),(0,Q.jsx)(`span`,{title:r?`${e} (exact phrase)`:e,children:e}),t&&(0,Q.jsx)(`button`,{type:`button`,onClick:()=>t(n),"aria-label":`Remove search: ${e}`,children:(0,Q.jsx)(h,{size:14})})]},`${e}-${n}`)}),t&&e.length>1&&(0,Q.jsx)(`button`,{type:`button`,onClick:()=>t(-1),className:`canvas-search-clear`,children:`Clear all`})]})]})}function Dn({children:e,accentColor:t}){return(0,Q.jsxs)(`div`,{className:`canvas-navigation-tabs`,children:[(0,Q.jsx)(`span`,{"aria-hidden":`true`,className:`canvas-tab-divider`,style:t?{backgroundColor:t}:void 0}),e]})}function On({workspace:e,workspaceIcon:t,tree:n,path:i,document:a,section:o,onBack:s,onBrowseWorkspaces:c,onBrowseTree:l,onNavigatePath:u,onDocument:d,onSection:f,onFilter:p,filtersActive:m,filtersOpen:g,onAdd:_,search:v,onDraftChange:y,tabs:x,accentColor:S,actions:C}){let w=ze(),[T,E]=(0,Z.useState)(!1),[D,O]=(0,Z.useState)(!1),k=(0,Z.useRef)(null),A=(0,Z.useRef)(null),M=(0,Z.useRef)(null),N=(0,Z.useRef)(!1),P=JSON.stringify([e,n,i,a]),[F,I]=(0,Z.useState)(P);F!==P&&(I(P),E(!1)),(0,Z.useEffect)(()=>{T?A.current?.focus():(k.current&&(k.current.scrollLeft=k.current.scrollWidth,O(k.current.scrollLeft>1)),N.current&&=(M.current?.focus(),!1))},[T,P,o]);let L=()=>{N.current=!0,E(!1),y?.(``)},te=w&&!!l,ne=T?L:te?l:s??l,R=T?`Back to address`:te?`Back to tree`:`Back to previous view`,z=ue(i,e).slice(1),B=(e,t,n,r,i=!1)=>n?(0,Q.jsx)(`button`,{type:`button`,className:t,onClick:n,title:r,"aria-current":i?`location`:void 0,children:e}):(0,Q.jsx)(`span`,{className:`canvas-address-label ${t}`,title:r,"aria-current":i?`location`:void 0,children:e});return(0,Q.jsxs)(`header`,{className:`canvas-navigation${x?` has-tabs`:``}`,style:S?{borderTopColor:S}:void 0,children:[x&&(0,Q.jsx)(Dn,{accentColor:S,children:x}),(0,Q.jsxs)(`div`,{className:`canvas-address-row`,children:[(0,Q.jsx)(`button`,{type:`button`,className:`canvas-nav-button`,"aria-label":R,title:R,disabled:!T&&!s&&!l,onClick:ne,children:te&&!T?(0,Q.jsx)(re,{size:19}):(0,Q.jsx)(ee,{size:19})}),(0,Q.jsxs)(`div`,{className:`canvas-address-field`,onDoubleClick:e=>{v&&!e.target.closest(`button`)&&E(!0)},onKeyDown:e=>{e.key===`Escape`&&T&&(e.preventDefault(),e.stopPropagation(),L())},children:[T&&v?(0,Q.jsx)(Tn,{inputRef:A,workspaceId:v.localOnly?void 0:v.workspaceId,onSearch:v.onSearch,onDraftChange:y,clearOnSubmit:!v.localOnly,showSubmitButton:!1,label:v.queries.length?`Refine search…`:`Search documents…`}):(0,Q.jsx)(Q.Fragment,{children:(0,Q.jsxs)(`div`,{ref:k,className:`canvas-address-crumbs${D?` is-scrolled`:``}`,onScroll:e=>O(e.currentTarget.scrollLeft>1),role:`navigation`,"aria-label":`Canvas address`,tabIndex:0,onKeyDown:e=>{e.key===`Enter`&&e.target===e.currentTarget&&v&&E(!0)},children:[B((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`),n&&B(`[${n}]`,`canvas-address-tree`,l,`Browse tree: ${n}`),B(`:/`,`canvas-address-root`,u?()=>u(`/`):void 0,`Go to tree root`),z.map((e,t)=>(0,Q.jsxs)(`span`,{className:`canvas-address-segment`,children:[t>0&&(0,Q.jsx)(`span`,{"aria-hidden":`true`,children:`/`}),B(e.label,``,u?()=>u(e.path):void 0,e.path,!a&&t===z.length-1)]},e.path)),a&&(0,Q.jsxs)(`span`,{className:`canvas-address-segment`,children:[(0,Q.jsx)(`span`,{"aria-hidden":`true`,children:z.length?`/`:``}),B(a,``,d,a)]}),o&&B(`#${o}`,`canvas-address-section`,f,o,!0)]})}),v&&(0,Q.jsxs)(`button`,{ref:M,type:`button`,className:`canvas-nav-button canvas-address-search`,onClick:()=>{T?A.current?.form?.requestSubmit():E(!0)},"aria-label":T?`Run search`:`Search this canvas`,"aria-expanded":T,title:T?`Run search`:`Search this canvas`,children:[(0,Q.jsx)(W,{size:17}),v.queries.length>0&&(0,Q.jsx)(`span`,{className:`canvas-nav-dot`})]})]}),p&&(0,Q.jsxs)(`button`,{type:`button`,className:`canvas-nav-button canvas-filter-button`,onClick:p,"aria-label":m?`Filters active`:`Filters`,"aria-expanded":!!g,"data-active":!!m,title:m?`Filters active`:`Filters`,children:[(0,Q.jsx)(j,{size:19}),m&&(0,Q.jsx)(`span`,{className:`canvas-nav-dot`})]}),_&&(0,Q.jsx)(`button`,{type:`button`,className:`canvas-nav-button canvas-add-button`,onClick:_,"aria-label":`Add here`,title:`Add here`,children:(0,Q.jsx)(b,{size:21})}),C]}),T&&v&&(0,Q.jsxs)(`div`,{className:`canvas-search-dropdown`,children:[(0,Q.jsxs)(`div`,{className:`canvas-search-heading`,children:[(0,Q.jsx)(`span`,{children:v.localOnly?`Filter documents on this page`:y?`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:L,"aria-label":`Close search`,children:(0,Q.jsx)(h,{size:16})})]}),(0,Q.jsx)(En,{...v})]}),!T&&v&&v.queries.length>0&&(0,Q.jsx)(`div`,{className:`px-3 pb-2`,children:(0,Q.jsx)(En,{queries:v.queries,onRemoveQuery:v.onRemoveQuery})})]})}function kn({workspaceId:e,document:t,className:n}){let r=wn(t);return r?(0,Q.jsx)(r,{workspaceId:e,document:t,className:n}):(0,Q.jsx)(`pre`,{className:`overflow-auto p-2 text-xs`,children:JSON.stringify(t.data,null,2)})}function An({workspaceId:e,documentId:t}){let[n,r]=(0,Z.useState)(null),[i,a]=(0,Z.useState)(``),[o,s]=(0,Z.useState)({}),[c,l]=(0,Z.useState)(null),u=(0,Z.useCallback)(async()=>{try{let n=await gt(e,t);r(n),a(``)}catch(e){a(e instanceof Error?e.message:`Could not load thread`)}},[e,t]);return(0,Z.useEffect)(()=>{let n=!0;gt(e,t).then(e=>{n&&(r(e),a(``))}).catch(e=>{n&&a(e instanceof Error?e.message:`Could not load thread`)});let i=()=>{u()};return window.addEventListener(`workspace:documents:refresh`,i),window.addEventListener(ct,i),()=>{n=!1,window.removeEventListener(`workspace:documents:refresh`,i),window.removeEventListener(ct,i)}},[e,t,u]),i?(0,Q.jsxs)(`div`,{className:`p-3`,children:[(0,Q.jsx)(`p`,{role:`alert`,className:`text-sm text-destructive`,children:i}),(0,Q.jsx)(K,{variant:`outline`,size:`sm`,onClick:()=>void u(),children:`Retry`})]}):!n||n.documentId!==t?(0,Q.jsx)(`p`,{className:`p-3 text-sm text-muted-foreground`,children:`Loading thread…`}):(0,Q.jsxs)(`section`,{"aria-label":`Message thread`,className:`space-y-3 p-2`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,Q.jsxs)(`h3`,{className:`text-sm font-medium`,children:[`Thread · `,n.documents.length,` message`,n.documents.length===1?``:`s`]}),(0,Q.jsx)(K,{size:`sm`,variant:`outline`,onClick:()=>void u(),children:`Refresh`})]}),n.documents.length===1&&(0,Q.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`No linked replies have been indexed. Other messages in this conversation are separate from this reply thread.`}),n.truncated&&(0,Q.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`Showing up to 200 linked messages.`}),n.documents.map(r=>{let i=fe(r),a=r.schema===`data/schema/message/email`,c=a||[`slack`,`whatsapp`].includes(String(r.data.platform)),u=r.data.timestamp||r.data.date,d=u?new Date(String(u)):null,f=(n.parents[r.id]||[]).flatMap(e=>{let t=n.documents.find(t=>Number(t.id)===e);return t?[fe(t).title]:[]}),p=o[Number(r.id)]??Number(r.id)===t;return(0,Q.jsxs)(`details`,{open:p,onToggle:e=>{let t=e.currentTarget.open;s(e=>e[Number(r.id)]===t?e:{...e,[Number(r.id)]:t})},className:`rounded-lg border bg-card`,children:[(0,Q.jsxs)(`summary`,{className:`cursor-pointer space-y-1 p-3 text-sm`,children:[(0,Q.jsx)(`span`,{className:`font-medium`,children:i.title}),(0,Q.jsxs)(`span`,{className:`block text-xs text-muted-foreground`,children:[i.subtitle,d&&!Number.isNaN(d.getTime())?` · ${d.toLocaleString()}`:``]}),f.length>0&&(0,Q.jsxs)(`span`,{className:`block text-xs text-muted-foreground`,children:[`Reply to `,f.join(`, `)]})]}),p&&c&&(0,Q.jsx)(`div`,{className:`flex flex-wrap gap-2 px-3 pb-2`,children:(a?[`reply`,`replyAll`,`forward`]:[`reply`]).map(e=>(0,Q.jsx)(K,{variant:`outline`,size:`sm`,onClick:()=>l({document:r,mode:e}),children:e===`replyAll`?`Reply all`:e===`forward`?`Forward`:`Reply`},e))}),p&&(0,Q.jsx)(kn,{workspaceId:e,document:r})]},r.id)}),c&&(0,Q.jsx)(vt,{workspaceId:e,replyToDocumentId:Number(c.document.id),mode:c.mode,originalSubject:typeof c.document.data.subject==`string`?c.document.data.subject:void 0,onClose:()=>l(null)},`${c.document.id}:${c.mode}`)]})}function jn(e,t){return e.slice(0,3).map(e=>{let n=t.get(e.id),r=e.reason===`not-found`?`Source missing from the storage index. Resync the source backend and retry.`:e.reason===`not found`?`Document no longer exists in this workspace. Refresh the list and select it again.`:e.reason;return`${n?`${n} (ID ${e.id})`:`Document ${e.id}`}: ${r}`}).join(`
|
|
8
|
+
`)+(e.length>3?`\n…and ${e.length-3} more failed file${e.length===4?``:`s`}.`:``)}var Mn=e(i(),1),Nn=[{mode:`copy`,label:`Copy to`,icon:(0,Q.jsx)(S,{className:`h-3.5 w-3.5`})},{mode:`move`,label:`Move to`,icon:(0,Q.jsx)(H,{className:`h-3.5 w-3.5`})},{mode:`delete`,label:`Delete from`,icon:(0,Q.jsx)(T,{className:`h-3.5 w-3.5`})}],Pn=[{value:`rename`,label:`Rename mine (file-1.ext)`},{value:`overwrite`,label:`Overwrite the existing file`},{value:`error`,label:`Skip the document`}],Fn=`h-9 w-full rounded-md border bg-background px-2 text-xs outline-none focus:ring-2 focus:ring-ring disabled:opacity-50`;function In(e){return e.driver===`cacache`?k:e.config?.remote===!0?v:o}function Ln({workspaceId:e,documentCount:t,initialMode:n=`copy`,defaultFilename:r=``,onConfirm:i,onClose:a,saving:s=!1,sizeClassName:c,deleteFrom:l,progress:u,stopping:d=!1,onStop:f}){let{showErrorToast:m}=X(),[g,_]=(0,Z.useState)(!1);mt(a,!s&&!g);let[v,y]=(0,Z.useState)(n),[b,x]=(0,Z.useState)(null),[C,w]=(0,Z.useState)(null),[E,D]=(0,Z.useState)(()=>new Set(n===`delete`&&l?[l.backend]:[])),[O,k]=(0,Z.useState)(!1),[A,j]=(0,Z.useState)(``),[M,ee]=(0,Z.useState)(r),[N,P]=(0,Z.useState)(`rename`);(0,Z.useEffect)(()=>{let t=!1;return Le(e).then(e=>{if(t)return;x(e.filter(e=>e.kind===`storage`));let n=new Set(e.filter(e=>e.kind===`storage`&&e.enabled!==!1&&e.config?.readOnly!==!0&&e.config?.supported!==!1).map(e=>e.address));D(e=>new Set([...e].filter(e=>n.has(e))))}).catch(e=>{t||w(e instanceof Error?e.message:String(e))}),()=>{t=!0}},[e]);let F=v===`move`,I=e=>e.enabled===!1?`disabled`:e.config?.readOnly===!0?`read-only`:e.config?.supported===!1?`unsupported`:null,L=(0,Z.useMemo)(()=>(b||[]).filter(e=>!I(e)).map(e=>e.address),[b,v]),te=e=>{y(e),D(t=>{let n=(b||[]).filter(e=>e.enabled!==!1&&e.config?.readOnly!==!0&&e.config?.supported!==!1).map(e=>e.address),r=[...t].filter(e=>n.includes(e));return new Set(e===`move`?r.slice(0,1):r)})},ne=e=>{D(t=>{if(F)return t.has(e)?new Set:new Set([e]);let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},R=(0,Z.useMemo)(()=>(b||[]).filter(e=>E.has(e.address)&&Ne(e)),[b,E]),z=v!==`delete`&&R.length>0,B=e=>{let t=ke(e,b||[]),n=t&&b?.find(e=>e.address===t.address);return!!n&&!I(n)&&v!==`delete`&&!s},V=async(t,n)=>{let r=ke(t,b||[]);if(!r||!B(t))throw Error(`Choose a writable file backend folder`);await Me(e,r.driver,r.address,[[r.key,n].filter(Boolean).join(`/`)])},ie=e=>{_(!1);let t=Oe(e[0]||``,b||[]),n=t?(b||[]).find(e=>e.address===t.address):null;if(!t||!n){m(`Pick a folder inside a storage backend`);return}if(I(n)){m(`${n.address} is ${I(n)}`);return}if(!Ne(n)){m(`${n.address} does not keep folders — objects are stored by content`);return}j(t.key),D(e=>F?new Set([t.address]):new Set([...e,t.address]))},ae=async()=>{E.size===0||s||await i([...E],v,{keepDocument:O,folder:z?A.trim():``,filename:z&&t===1?M.trim():``,onConflict:N})},U=t,W=U===1?``:`s`,oe=v===`delete`?`Delete ${U} document${W} from…`:`${v===`move`?`Move`:`Copy`} ${U} document${W} to…`,q=v===`delete`?`Delete from`:v===`move`?`Move to`:`Copy to`,J=E.size===0?q.split(` `)[0]:`${q} ${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`,c||`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)(o,{className:`h-4 w-4`}),oe]}),(0,Q.jsx)(`button`,{type:`button`,onClick:a,disabled:s,className:`text-muted-foreground transition-colors hover:text-foreground disabled:opacity-40`,"aria-label":`Close`,children:(0,Q.jsx)(h,{className:`h-4 w-4`})})]}),(0,Q.jsx)(`div`,{className:`flex shrink-0 items-center gap-1 border-b px-2 pt-2`,children:Nn.map(({mode:e,label:t,icon:n})=>(0,Q.jsxs)(`button`,{type:`button`,onClick:()=>te(e),disabled:s,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}),!b&&!C&&(0,Q.jsx)(`div`,{className:`px-2 py-3 text-xs text-muted-foreground`,children:`Loading backends…`}),b?.length===0&&(0,Q.jsx)(`p`,{className:`px-2 py-1.5 text-xs text-muted-foreground`,children:`No storage backends configured.`}),b?.map(e=>{let t=In(e),n=I(e),r=E.has(e.address),i=e.config?.remote===!0;return(0,Q.jsxs)(`div`,{onClick:()=>!n&&!s&&ne(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:F?`radio`:`checkbox`,checked:r,disabled:!!n||s,onChange:()=>ne(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=>k(e.target.checked),disabled:s,className:`mt-0.5 h-3.5 w-3.5 accent-destructive`}),(0,Q.jsxs)(`span`,{children:[`Keep the index entry when its `,(0,Q.jsx)(`strong`,{children:`last`}),` copy is deleted.`,(0,Q.jsx)(`span`,{className:`block text-muted-foreground`,children:`Otherwise the document moves to workspace Trash once no locations remain.`})]})]}),z&&(0,Q.jsxs)(`div`,{className:`mt-3 space-y-2 rounded-md border px-3 py-2`,children:[(0,Q.jsxs)(`p`,{className:`text-xs font-medium`,children:[`Destination on `,R.map(e=>e.config?.label||e.address).join(`, `)]}),(0,Q.jsxs)(`div`,{className:`space-y-1`,children:[(0,Q.jsx)(`label`,{htmlFor:`backend-transfer-folder`,className:`text-[11px] text-muted-foreground`,children:`Folder (relative to the backend root)`}),(0,Q.jsxs)(`div`,{className:`flex gap-1.5`,children:[(0,Q.jsx)(se,{id:`backend-transfer-folder`,value:A,onChange:e=>j(e.target.value),placeholder:`/`,disabled:s,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:s,"aria-label":`Browse backend folders`,title:`Browse…`,children:(0,Q.jsx)(re,{className:`h-4 w-4`})})]})]}),t===1?(0,Q.jsxs)(`div`,{className:`space-y-1`,children:[(0,Q.jsx)(`label`,{htmlFor:`backend-transfer-filename`,className:`text-[11px] text-muted-foreground`,children:`File name`}),(0,Q.jsx)(se,{id:`backend-transfer-filename`,value:M,onChange:e=>ee(e.target.value),placeholder:r||`keeps the document's own name`,disabled:s,className:`h-9 font-mono text-xs`})]}):(0,Q.jsx)(`p`,{className:`text-[11px] text-muted-foreground`,children:`Each document keeps its own file name and extension.`}),(0,Q.jsxs)(`div`,{className:`space-y-1`,children:[(0,Q.jsx)(`label`,{htmlFor:`backend-transfer-conflict`,className:`text-[11px] text-muted-foreground`,children:`If a different file already has that name`}),(0,Q.jsx)(`select`,{id:`backend-transfer-conflict`,className:Fn,value:N,onChange:e=>P(e.target.value),disabled:s,children:Pn.map(e=>(0,Q.jsx)(`option`,{value:e.value,children:e.label},e.value))})]})]}),v===`move`&&L.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.`})]}),s&&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:ae,disabled:E.size===0||s,children:s?(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(ce,{className:`mr-1.5 h-3.5 w-3.5`}),`Working…`]}):(0,Q.jsxs)(Q.Fragment,{children:[v===`delete`?(0,Q.jsx)(T,{className:`mr-1 h-3.5 w-3.5`}):v===`move`?(0,Q.jsx)(H,{className:`mr-1 h-3.5 w-3.5`}):(0,Q.jsx)(S,{className:`mr-1 h-3.5 w-3.5`}),J]})})]}),v===`delete`&&(0,Q.jsxs)(`div`,{className:`flex items-start gap-2 border-t bg-destructive/5 px-4 py-2 text-[11px] text-muted-foreground`,children:[(0,Q.jsx)(p,{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.`})]}),g&&(0,Q.jsx)(yt,{onClose:()=>_(!1),children:(0,Q.jsx)(de,{sizeClassName:`h-full w-[380px] max-w-[90vw] max-md:w-full`,multiple:!1,tabs:[`backends`],fixedWorkspaceName:e,title:`Pick a destination folder…`,confirmLabel:`Use folder`,backendFolderCreation:{canCreate:B,create:V},onConfirm:ie,onClose:()=>_(!1)})})]})}var Rn={exif:`from the photo's EXIF`,device:`from the device at capture`,manual:`placed by hand`};function zn(e){let t=`${e.lat.toFixed(5)}, ${e.lon.toFixed(5)}`,n=e.source?Rn[e.source]:null;return[t,e.accuracy==null?null:`±${e.accuracy} m`,n].filter(Boolean).join(` · `)}function Bn({value:e,onChange:t,idPrefix:n=`edit-geo`}){let[r,i]=(0,Z.useState)(!1);return(0,Q.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Q.jsx)(q,{htmlFor:`${n}-action`,children:`Location`}),(0,Q.jsxs)(`div`,{className:`flex items-center justify-between gap-3`,children:[(0,Q.jsxs)(`span`,{className:`flex min-w-0 items-center gap-2 text-xs`,children:[(0,Q.jsx)(ae,{className:e?`h-4 w-4 shrink-0 text-info`:`h-4 w-4 shrink-0 text-muted-foreground`}),(0,Q.jsx)(`span`,{className:e?`truncate tabular-nums`:`truncate text-muted-foreground`,children:e?zn(e):`No location on this document`})]}),(0,Q.jsxs)(`span`,{className:`flex shrink-0 items-center gap-1`,children:[(0,Q.jsxs)(`button`,{id:`${n}-action`,type:`button`,onClick:()=>i(!0),className:`inline-flex items-center gap-1.5 rounded-md border border-border px-2 py-1 text-xs text-muted-foreground transition-colors hover:bg-muted hover:text-foreground`,children:[(0,Q.jsx)(z,{className:`h-3.5 w-3.5`}),e?`Move pin`:`Set on map`]}),e&&(0,Q.jsx)(`button`,{type:`button`,onClick:()=>t(null),"aria-label":`Remove location`,title:`Remove location`,className:`rounded p-1 text-muted-foreground hover:bg-muted hover:text-foreground`,children:(0,Q.jsx)(T,{className:`h-3.5 w-3.5`})})]})]}),r&&(0,Q.jsx)(We,{initial:e,onPick:e=>t({lat:e.lat,lon:e.lon,source:`manual`}),onClose:()=>i(!1)})]})}function Vn(e){return e===`data/schema/note`||e===`data/schema/link`||e===`data/schema/tab`||e===`data/schema/task`||e===`data/schema/drawing`||e===`data/schema/identity`||e.startsWith(`data/schema/identity/`)}function Hn(e){return Vn(e.schema)||Ze(e)}function Un(e){return e===`data/schema/link`?{urlKey:`uri`,titleKey:`label`}:e===`data/schema/tab`?{urlKey:`url`,titleKey:`title`}:{urlKey:null,titleKey:`title`}}async function Wn(e,t,n){try{let r=new Set(n.map(e=>e.identityId).filter(Boolean)),i=await Te(e,t,{resolve:!1}),a=new Set(i.outgoing.filter(e=>e.p===`member-of`).map(e=>e.to));for(let n of r)a.has(n)||await Ee(e,t,`member-of`,[n]);for(let n of a)r.has(n)||await we(e,t,`member-of`,n)}catch(e){console.error(`Failed to sync organization relations`,e)}}function Gn({document:e,workspaceId:t,onClose:n}){let{showSuccessToast:r,showErrorToast:i}=X(),a=Vn(e.schema),o=e.schema===`data/schema/file`,[s,c]=(0,Z.useState)(()=>Y(e)),l=!o||!!s.trim()&&!/[\\/]/.test(s)&&!Array.from(s).some(e=>e.charCodeAt(0)<32)&&s!==`.`&&s!==`..`,u=e.schema===pe,d=Ze(e),f=et(e)??`markdown`,p=d&&Xe(e),m=e.schema===ge,h=e.schema===`data/schema/identity`||e.schema.startsWith(`data/schema/identity/`),{urlKey:g,titleKey:_}=Un(e.schema),[v,y]=(0,Z.useState)(g?String(e.data?.[g]??``):``),[b,x]=(0,Z.useState)(String(e.data?.[_]??``)),[S,C]=(0,Z.useState)(String(e.data?.content??``)),[w,T]=(0,Z.useState)(String(e.data?.description??``)),[E,D]=(0,Z.useState)(e.data?.status??`pending`),[O,k]=(0,Z.useState)(typeof e.data?.priority==`number`?e.data.priority:``),[A,j]=(0,Z.useState)(e.data?.dueDate?lt(String(e.data.dueDate)):ft()),M=He(Ge(e)),[ee,N]=(0,Z.useState)(String(e.comment??``)),P=e.metadata?.geo??null,[F,I]=(0,Z.useState)(P),L=e.features??e.metadata?.features,[te,ne]=(0,Z.useState)(ot(L).length?ot(L):e.data?.tags??[]),R=xt(e,t,u),{title:z,content:B,comment:V,tags:re,geo:ie,setTitle:ae,setContent:H,setComment:U,setTags:W,setGeo:oe}=u?R:{title:b,content:S,comment:ee,tags:te,geo:F,setTitle:x,setContent:C,setComment:N,setTags:ne,setGeo:I},G=JSON.stringify(ie??null)!==JSON.stringify(P??null),J=$e(t,e.id,{mode:`text`,enabled:d&&!p,maxTextLength:Qe,version:e.checksumArray?.[0]??null}),[ce,le]=(0,Z.useState)(null),ue=`${e.id}:${e.checksumArray?.[0]??``}`;d&&J.text!=null&&ce!==ue&&(le(ue),H(J.text));let[de,fe]=(0,Z.useState)([]),[me,he]=(0,Z.useState)(!1),{replicating:_e,mirror:ve}=Ie(e);(0,Z.useEffect)(()=>{let e=!1;return De(t).then(t=>{e||fe(t)}).catch(()=>{}),()=>{e=!0}},[t]);let ye=!g||(()=>{try{return new URL(v.trim()),!0}catch{return!1}})(),be=!me&&l&&(d?!p&&J.text!=null&&!J.loading:a?h?M.displayName.trim().length>0&&M.emailValid:m?z.trim().length>0:u?R.canSave:ye:!0),Se=async()=>{he(!0);let c=[...(L||[]).filter(e=>!e.startsWith(`tag/`)),...at(re)];try{if(u){await R.save(),n();return}if(d){let i=await nt(t,e,B,{comment:V.trim(),metadata:{features:c,...o?{filename:s.trim()}:{},...G?{geo:ie}:{}}});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:V.trim(),metadata:{features:c,...o?{filename:s.trim()}:{}}};if(h){let{type:t,...n}=e.data??{};i.schema=`${xe}/${M.values.type}`,i.data={...n,...Ue(M.values)}}else if(m)i.data={...e.data,...ut({title:z,description:w,status:E,priority:O,due:A})};else if(a){let t=re.map(e=>e.trim()).filter(Boolean),n;u?n={...z.trim()?{title:z.trim()}:{},content:B}:(n={...e.data},g&&(n[g]=v.trim()),z.trim()?n[_]=z.trim():delete n[_],n.tags=t),i.data=n}G&&(i.metadata={...i.metadata??{},geo:ie}),await Fe(t,i),h&&(await Wn(t,e.id,M.values.organizations),st()),r(`Document updated`),window.dispatchEvent(new CustomEvent(`workspace:documents:refresh`)),n()}catch(e){i(e instanceof Error?e.message:`Failed to update document`)}finally{he(!1)}};return(0,Q.jsxs)(`div`,{className:`flex flex-col gap-4`,children:[o&&(0,Q.jsxs)(`div`,{className:`space-y-2`,children:[(0,Q.jsx)(q,{htmlFor:`file-name`,children:`File name`}),(0,Q.jsx)(se,{id:`file-name`,value:s,onChange:e=>c(e.target.value)}),(0,Q.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`Changes the object’s name; storage locations stay the same.`})]}),a&&g&&(0,Q.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Q.jsx)(q,{htmlFor:`edit-url`,children:`URL`}),(0,Q.jsx)(se,{id:`edit-url`,value:v,onChange:e=>y(e.target.value),placeholder:`https://example.com`,className:`font-mono text-xs`}),v.trim()&&!ye&&(0,Q.jsx)(`p`,{className:`text-xs text-destructive`,children:`Enter a valid URL, e.g. https://example.com`})]}),a&&h&&(0,Q.jsx)(qe,{idPrefix:`edit-identity`,workspaceName:t,...M,emailValid:M.emailValid}),a&&m&&(0,Q.jsx)(Be,{idPrefix:`edit-todo`,title:z,setTitle:ae,description:w,setDescription:T,status:E,setStatus:D,priority:O,setPriority:k,due:A,setDue:j}),a&&!m&&!h&&(0,Q.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Q.jsx)(q,{htmlFor:`edit-title`,children:`Title`}),(0,Q.jsx)(se,{id:`edit-title`,value:z,onChange:e=>ae(e.target.value),placeholder:u?`Optional; defaults to today's date`:`Optional display title`})]}),(u||d)&&(0,Q.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Q.jsx)(q,{children:`Body`}),p?(0,Q.jsxs)(`p`,{className:`text-xs text-muted-foreground`,children:[`This file is too large to edit here (`,`>`,1e3,` kB) — download it instead.`]}):d&&J.error?(0,Q.jsx)(`p`,{className:`text-xs text-destructive`,children:J.error}):d&&J.text==null?(0,Q.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`Loading content…`}):(0,Q.jsx)(St,{kind:u?`markdown`:f,value:B,onChange:H,placeholder:u?`Write your note…`:void 0})]}),(0,Q.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Q.jsx)(q,{children:`Tags`}),(0,Q.jsx)(Ke,{tags:re,onChange:W,suggestions:de})]}),(0,Q.jsx)(Bn,{value:ie,onChange:oe}),(0,Q.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Q.jsx)(q,{htmlFor:`edit-comment`,children:`Comment`}),(0,Q.jsx)(`textarea`,{id:`edit-comment`,value:V,onChange:e=>U(e.target.value),rows:3,placeholder:`Add context you can't infer from the content, e.g. “sofa from the cozmo bar in Košice”`,className:`flex w-full rounded-md border border-input bg-transparent px-3 py-2 text-sm shadow-elevation-1 transition-colors placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-50`})]}),u&&(0,Q.jsx)(bt,{...R,onRetry:R.save}),(0,Q.jsxs)(`div`,{className:`flex justify-end gap-2 pt-2`,children:[(0,Q.jsx)(K,{variant:`outline`,size:`sm`,onClick:()=>n(),disabled:me,children:u?`Close`:`Cancel`}),(0,Q.jsx)(K,{size:`sm`,onClick:Se,disabled:!be,children:me?_e?`Replicating to ${ve.label}…`:`Saving…`:`Save changes`})]})]})}var Kn=(0,Z.createContext)(null),qn={entry:null,open:()=>{},close:()=>{}};function Jn(){return(0,Z.useContext)(Kn)??qn}var Yn=`main`,Xn=(0,Z.createContext)(null);function Zn(){return(0,Z.useContext)(Xn)}var Qn=50;function $n({relation:e,workspaceId:t,direction:n,onRemove:r,removing:i}){let{open:a}=Ct(),o=Jn(),s=Zn(),c=n===`out`?e.to:e.from,l=e.document??null,u=l?fe(l).title:``,[d,f]=(0,Z.useState)(!1),{showErrorToast:p}=X(),m=async()=>{if(!(c==null||!l)){f(!0);try{let n=e.preview?await Pe(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)(H,{className:`h-3.5 w-3.5 shrink-0 text-muted-foreground`}):(0,Q.jsx)(ee,{className:`h-3.5 w-3.5 shrink-0 text-muted-foreground`}),l?(0,Q.jsx)(ht,{document:l,size:3.5}):null,l?(0,Q.jsx)(`button`,{type:`button`,onClick:()=>void m(),disabled:d,className:`min-w-0 flex-1 truncate text-left hover:underline`,title:u,children:u}):(0,Q.jsxs)(`span`,{className:`min-w-0 flex-1 truncate italic text-muted-foreground`,children:[`Document `,c,` (not available)`]}),(0,Q.jsxs)(`span`,{className:`shrink-0 font-mono text-[10px] text-muted-foreground`,children:[`#`,c]}),!h&&(0,Q.jsx)(`span`,{className:`shrink-0 rounded-full bg-muted px-1.5 py-0.5 text-[10px] text-muted-foreground`,title:`Derived by ${e.meta?.src}`,children:e.meta?.src}),h&&(0,Q.jsx)(`button`,{type:`button`,onClick:r,disabled:i,className:`shrink-0 rounded p-1 text-muted-foreground opacity-0 transition-opacity hover:bg-destructive/10 hover:text-destructive group-hover:opacity-100 disabled:opacity-40`,title:`Remove relation`,"aria-label":`Remove relation`,children:(0,Q.jsx)(T,{className:`h-3.5 w-3.5`})})]})}function er({document:e,workspaceId:t}){let{showSuccessToast:n,showErrorToast:r}=X(),[i,a]=(0,Z.useState)(null),[o,s]=(0,Z.useState)(null),[c,l]=(0,Z.useState)(!1),[u,d]=(0,Z.useState)(!1),[f,p]=(0,Z.useState)(null),[m,h]=(0,Z.useState)(0),[g,_]=(0,Z.useState)(1),v=(0,Z.useRef)(0),y=(0,Z.useCallback)(()=>{v.current++},[]),x=(0,Z.useCallback)(async()=>{let n=++v.current;try{let r=await Te(t,e.id,{offset:m*Qn,limit:Qn,summary:!0});if(n!==v.current)return;let i=Math.max(0,Math.ceil(Math.max(r.outgoingCount??r.outgoing.length,r.incomingCount??r.incoming.length)/Qn)-1);if(_(i+1),m>i){h(i);return}a(r),s(null)}catch(e){if(n!==v.current)return;s(e instanceof Error?e.message:String(e))}},[t,e.id,m]),S=`${t}:${e.id}`,[C,w]=(0,Z.useState)(S);S!==C&&(w(S),a(null),s(null),h(0),_(1)),(0,Z.useEffect)(()=>{async function e(){await x()}return e(),window.addEventListener(ct,e),()=>{y(),window.removeEventListener(ct,e)}},[x,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 we(t,e.id,i.p,o,a),n(`Relation removed`),st()}catch(e){r(e instanceof Error?e.message:`Failed to remove relation`)}finally{p(null)}},E=[{dir:`out`,title:`Points at`,hint:`this document as the subject`,entries:i?.outgoing??[]},{dir:`in`,title:`Pointed at by`,hint:`this document as the object`,entries:i?.incoming??[]}],D=e=>{a(null),h(e)};return(0,Q.jsxs)(`div`,{children:[(0,Q.jsxs)(`div`,{className:`mb-2 flex items-center justify-between gap-2`,children:[(0,Q.jsx)(`h3`,{className:`font-semibold`,children:`Documents`}),(0,Q.jsxs)(K,{variant:`outline`,size:`sm`,onClick:()=>l(!0),children:[(0,Q.jsx)(b,{className:`mr-1 h-3 w-3`}),` Add relation`]})]}),o?(0,Q.jsx)(`p`,{className:`text-sm text-destructive`,children:o}):i?E.every(e=>e.entries.length===0)?(0,Q.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`No related documents.`}):(0,Q.jsx)(`div`,{className:`space-y-4`,children:E.filter(e=>e.entries.length>0).map(({dir:e,title:n,hint:r,entries:i})=>(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`p`,{className:`mb-1 text-xs font-medium text-muted-foreground`,title:r,children:n}),Array.from(new Set(i.map(e=>e.p))).map(n=>(0,Q.jsxs)(`div`,{className:`mb-2`,children:[(0,Q.jsx)(`p`,{className:`px-2 font-mono text-[11px] text-muted-foreground`,children:n}),i.filter(e=>e.p===n).map(n=>{let r=e===`out`?n.to:n.from,i=`${e}:${n.p}:${r}`;return(0,Q.jsx)($n,{relation:n,workspaceId:t,direction:e,removing:f===i,onRemove:()=>void T(n,e)},i)})]},n))]},e))}):(0,Q.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`Loading relations…`}),(g>1||m>0)&&(0,Q.jsxs)(`div`,{className:`mt-3 flex items-center justify-between gap-2 text-xs text-muted-foreground`,children:[(0,Q.jsx)(K,{variant:`outline`,size:`sm`,disabled:m===0,onClick:()=>D(m-1),children:`Previous`}),(0,Q.jsxs)(`span`,{children:[`Page `,m+1,` of `,g]}),(0,Q.jsx)(K,{variant:`outline`,size:`sm`,disabled:!i||m+1>=g,onClick:()=>D(m+1),children:`Next`})]}),c&&(0,Q.jsx)(yt,{onClose:()=>{u||l(!1)},children:(0,Q.jsx)(de,{sizeClassName:`h-full w-[380px] max-w-[90vw] max-md:w-full`,title:`Relate to…`,tabs:[`relations`],fixedWorkspaceName:t,documentCount:1,saving:u,relationPredicates:i?.predicates,relationExcludeIds:new Set([e.id]),onClose:()=>l(!1),onConfirm:()=>{},onConfirmRelation:async({predicate:i,direction:a,targetIds:o})=>{d(!0);try{await Ee(t,e.id,i,o,a),n(`Related to ${o.length} document${o.length===1?``:`s`}`),l(!1),st()}catch(e){r(e instanceof Error?e.message:`Failed to create relation`)}finally{d(!1)}}})})]})}var tr=(0,Z.lazy)(()=>a(()=>import(`./TextDocumentEditor-rgHsbLCL.js`),__vite__mapDeps([2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,1,24]))),nr={reply:`Reply`,replyAll:`Reply all`,forward:`Forward`},rr={reply:u,replyAll:l,forward:d};function ir({document:e,workspaceId:t,initialEdit:n=!1,onChanged:r}){let i=Je()!=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),[p,m]=(0,Z.useState)(!1),h=[`data/schema/message`,`data/schema/message/email`].includes(e.schema),[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=>_(t=>t===e?null:e),S=!i,[C,w]=(0,Z.useState)(n&&!i),T=e.schema===be,[D,O]=(0,Z.useState)(!1),k=e.schema===`data/schema/note`||Ze(e),[A,j]=(0,Z.useState)(!1),M=`${t}:${e.id}:${n}:${i}`,[ee,N]=(0,Z.useState)(M);M!==ee&&(N(M),w(n&&!i),_(null),m(!1),O(!1),j(!1));let P=t=>{if(!S||!Hn(e)||t.defaultPrevented)return!1;let n=t.target;return n instanceof Element&&t.currentTarget.contains(n)&&!n.closest(`a, button, input, textarea, select, label, summary, audio, video, [role="button"], [role="checkbox"], [contenteditable]:not([contenteditable="false"])`)};return C&&S?(0,Q.jsx)(Gn,{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:[h&&(0,Q.jsx)(K,{size:`sm`,variant:p?`secondary`:`outline`,onClick:()=>m(!p),children:p?`Show message`:`View thread`}),y&&b.map(e=>{let t=rr[e];return(0,Q.jsxs)(K,{size:`sm`,variant:g===e?`secondary`:`outline`,onClick:()=>x(e),children:[(0,Q.jsx)(t,{className:`mr-1.5 h-3.5 w-3.5`}),nr[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)(U,{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:()=>ve(t,e.id,Y(e)||`document-${e.id}`).catch(e=>a(e instanceof Error?e.message:String(e))),children:[(0,Q.jsx)(U,{className:`mr-1 h-3 w-3`}),` Download`]}),T&&(0,Q.jsxs)(K,{variant:`outline`,size:`sm`,onClick:()=>O(!0),children:[(0,Q.jsx)(E,{className:`mr-1 h-3 w-3`}),` Edit sketch`]}),k&&(0,Q.jsxs)(K,{variant:`outline`,size:`sm`,onClick:()=>j(!0),children:[(0,Q.jsx)(f,{className:`mr-1 h-3 w-3`}),` Open editor`]}),(0,Q.jsxs)(K,{variant:`outline`,size:`sm`,onClick:()=>w(!0),children:[(0,Q.jsx)(s,{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)(wt,{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)(tr,{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:[p&&!i?(0,Q.jsx)(An,{workspaceId:t,documentId:Number(e.id)},`${t}:${e.id}`):(0,Q.jsx)(kn,{workspaceId:t,document:e}),g&&y&&(0,Q.jsx)(vt,{workspaceId:t,replyToDocumentId:Number(e.id),mode:g,originalSubject:v&&typeof e.data?.subject==`string`?e.data.subject:void 0,onClose:()=>_(null)},`${e.id}:${g}`)]}),e.comment?.trim()&&(0,Q.jsxs)(`div`,{className:`shrink-0 rounded-md border border-border bg-muted/40 px-3 py-2`,children:[(0,Q.jsx)(`p`,{className:`text-xs font-medium text-muted-foreground mb-0.5`,children:`Comment`}),(0,Q.jsx)(`p`,{className:`text-sm whitespace-pre-wrap`,children:e.comment})]})]})}var ar=e=>e?new Date(e).toLocaleDateString(`en-US`,{year:`numeric`,month:`long`,day:`numeric`,hour:`2-digit`,minute:`2-digit`,second:`2-digit`}):`—`,or=e=>!Number.isFinite(e)||!e?null:e>=1?`${e}s`:`1/${Math.round(1/e)}s`;function sr({meta:e}){let{geo:t,exif:n,dimensions:r}=e;if(!t&&!n&&!r)return null;let i=(e,t)=>t==null||t===``?null:(0,Q.jsxs)(`div`,{children:[(0,Q.jsxs)(`span`,{className:`font-medium`,children:[e,`:`]}),(0,Q.jsx)(`span`,{className:`ml-2`,children:t})]});return(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`h3`,{className:`font-semibold mb-3`,children:`Photo`}),(0,Q.jsxs)(`div`,{className:`grid gap-3 text-sm`,children:[r&&i(`Dimensions`,r.width&&r.height?`${r.width} × ${r.height}`:null),n&&i(`Camera`,[n.make,n.model].filter(Boolean).join(` `)),n&&i(`Lens`,n.lensModel),n&&i(`Aperture`,Number.isFinite(n.fNumber)?`ƒ/${n.fNumber}`:null),n&&i(`Shutter`,or(n.exposureTime)),n&&i(`ISO`,Number.isFinite(n.iso)?n.iso:null),n&&i(`Focal length`,Number.isFinite(n.focalLength)?`${n.focalLength} mm`:null),n&&i(`Captured`,ar(n.capturedAt)),t&&Number.isFinite(t.lat)&&Number.isFinite(t.lon)&&i(`Location`,(0,Q.jsxs)(`a`,{href:`https://www.openstreetmap.org/?mlat=${t.lat}&mlon=${t.lon}#map=15/${t.lat}/${t.lon}`,target:`_blank`,rel:`noopener noreferrer`,className:`text-primary underline underline-offset-2`,children:[t.lat.toFixed(5),`, `,t.lon.toFixed(5),Number.isFinite(t.alt)?` · ${Math.round(t.alt)} m`:``]}))]})]})}function cr({document:e}){let t=e.metadata;return(0,Q.jsxs)(`div`,{className:`space-y-6`,children:[(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`h3`,{className:`font-semibold mb-3`,children:`Basic Information`}),(0,Q.jsxs)(`div`,{className:`grid gap-3 text-sm`,children:[(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`span`,{className:`font-medium`,children:`ID:`}),(0,Q.jsx)(`span`,{className:`ml-2 font-mono`,children:e.id})]}),(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`span`,{className:`font-medium`,children:`Schema:`}),(0,Q.jsx)(`span`,{className:`ml-2 font-mono`,children:e.schema})]}),(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`span`,{className:`font-medium`,children:`Schema Version:`}),(0,Q.jsx)(`span`,{className:`ml-2`,children:e.schemaVersion})]}),(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`span`,{className:`font-medium`,children:`Created:`}),(0,Q.jsx)(`span`,{className:`ml-2`,children:ar(e.createdAt)})]}),(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`span`,{className:`font-medium`,children:`Updated:`}),(0,Q.jsx)(`span`,{className:`ml-2`,children:ar(e.updatedAt)})]})]})]}),(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`h3`,{className:`font-semibold mb-3`,children:`Metadata`}),(0,Q.jsxs)(`div`,{className:`grid gap-3 text-sm`,children:[(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`span`,{className:`font-medium`,children:`Content Type:`}),(0,Q.jsx)(`span`,{className:`ml-2`,children:e.metadata?.contentType??`—`})]}),(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`span`,{className:`font-medium`,children:`Content Encoding:`}),(0,Q.jsx)(`span`,{className:`ml-2`,children:e.metadata?.contentEncoding??`—`})]}),Number.isFinite(e.metadata?.size)&&(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`span`,{className:`font-medium`,children:`Size:`}),(0,Q.jsxs)(`span`,{className:`ml-2`,children:[e.metadata?.size,` bytes`]})]})]})]}),(0,Q.jsx)(sr,{meta:t}),Array.isArray(e.locations)&&e.locations.length>0&&(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`h3`,{className:`font-semibold mb-3`,children:`Locations`}),(0,Q.jsx)(`div`,{className:`space-y-2`,children:e.locations.map((e,t)=>{let{backend:n,key:r}=fr(e.url);return(0,Q.jsxs)(`div`,{className:`flex items-baseline gap-2 text-sm font-mono`,children:[(0,Q.jsx)(`span`,{className:`font-medium shrink-0`,children:n}),e.status&&e.status!==`available`&&(0,Q.jsx)(`span`,{className:`shrink-0 rounded border px-1 text-xs`,title:e.statusChangedAt,children:e.status===`deleted`?`Deleted`:`Not found`}),r&&(0,Q.jsx)(`span`,{className:`break-all text-muted-foreground`,children:r})]},t)})})]}),Array.isArray(e.checksumArray)&&e.checksumArray.length>0&&(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`h3`,{className:`font-semibold mb-3`,children:`Checksums`}),(0,Q.jsx)(`div`,{className:`space-y-2`,children:e.checksumArray.map((e,t)=>{let[n,r]=e.split(`/`);return(0,Q.jsxs)(`div`,{className:`flex items-center gap-2 text-sm font-mono`,children:[(0,Q.jsxs)(`span`,{className:`font-medium`,children:[n,`:`]}),(0,Q.jsx)(`span`,{className:`break-all text-muted-foreground`,children:r})]},t)})})]}),e.indexOptions&&(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`h3`,{className:`font-semibold mb-3`,children:`Index Options`}),(0,Q.jsxs)(`div`,{className:`space-y-3 text-sm`,children:[(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`span`,{className:`font-medium`,children:`FTS Search Fields:`}),(0,Q.jsx)(`div`,{className:`ml-2 mt-1`,children:(e.indexOptions.ftsSearchFields??[]).map((e,t)=>(0,Q.jsx)(`span`,{className:`mb-1 mr-2 inline-block rounded bg-muted px-2 py-1 text-xs`,children:e},t))})]}),(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`span`,{className:`font-medium`,children:`Vector Embedding Fields:`}),(0,Q.jsx)(`div`,{className:`ml-2 mt-1`,children:(e.indexOptions.vectorEmbeddingFields??[]).map((e,t)=>(0,Q.jsx)(`span`,{className:`mb-1 mr-2 inline-block rounded bg-muted px-2 py-1 text-xs`,children:e},t))})]})]})]})]})}function lr({document:e}){let{showSuccessToast:t,showErrorToast:n}=X(),r=JSON.stringify(e,null,2);return(0,Q.jsxs)(`div`,{className:`space-y-2`,children:[(0,Q.jsx)(`div`,{className:`flex justify-end`,children:(0,Q.jsxs)(K,{variant:`outline`,size:`sm`,onClick:async()=>{try{await navigator.clipboard.writeText(r),t(`Copied to clipboard`)}catch{n(`Copy failed`)}},children:[(0,Q.jsx)(S,{className:`mr-1 h-3 w-3`}),` Copy to clipboard`]})}),(0,Q.jsx)(`pre`,{className:`overflow-x-auto rounded-lg bg-muted p-4 text-xs`,children:r})]})}function ur({document:e,workspaceId:t}){let[n,r]=(0,Z.useState)(null),[i,a]=(0,Z.useState)(null),o=`${t}:${e.id}`,[s,c]=(0,Z.useState)(o);return o!==s&&(c(o),r(null),a(null)),(0,Z.useEffect)(()=>{let n=!1;return _e(t,e.id).then(e=>{n||r(e)}).catch(e=>{n||a(e instanceof Error?e.message:String(e))}),()=>{n=!0}},[o]),i?(0,Q.jsx)(`p`,{className:`text-sm text-destructive`,children:i}):n?(0,Q.jsxs)(`div`,{className:`space-y-6`,children:[[{title:`Context tree`,type:`context`},{title:`Directory tree`,type:`directory`}].map(({title:e,type:t})=>{let r=n.filter(e=>e.type===t),i=r.flatMap(e=>e.paths.map(t=>({tree:e.tree,path:t})));return(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`h3`,{className:`mb-3 font-semibold`,children:e}),i.length===0?(0,Q.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`No placements.`}):(0,Q.jsx)(`div`,{className:`space-y-1`,children:i.map(({tree:e,path:t},n)=>(0,Q.jsxs)(`div`,{className:`flex items-center gap-2 text-sm`,children:[(0,Q.jsx)(`span`,{className:`break-all font-mono text-xs`,children:t}),r.length>1&&(0,Q.jsxs)(`span`,{className:`shrink-0 text-xs text-muted-foreground`,children:[`(`,e,`)`]})]},`${e}:${t}:${n}`))})]},t)}),(0,Q.jsx)(er,{document:e,workspaceId:t})]}):(0,Q.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`Loading memberships...`})}function dr(e){return e===`stored`?k:e===`workspace-file`?o:e===`imap`?A:e===`readonly`?C:I}function fr(e){let t=e.match(/^([a-z][a-z0-9+.-]*):\/\/([^/]*)\/?(.*)$/i);return t?{backend:`${t[1]}://${t[2]}`,key:t[3]}:{backend:e,key:``}}function pr({document:e,workspaceId:t,onChanged:n}){let{showSuccessToast:r,showErrorToast:i}=X(),[a,o]=(0,Z.useState)(null),[s,c]=(0,Z.useState)(null),[l,u]=(0,Z.useState)(null),[d,f]=(0,Z.useState)(null),[p,m]=(0,Z.useState)(null),[h,g]=(0,Z.useState)(!1),_=`${t}:${e.id}`,[v,y]=(0,Z.useState)(_);_!==v&&(y(_),o(null),c(null),f(null));let b=()=>{je(t,e.id).then(o).catch(e=>c(e instanceof Error?e.message:String(e)))};(0,Z.useEffect)(()=>{let n=!1;return je(t,e.id).then(e=>{n||o(e)}).catch(e=>{n||c(e instanceof Error?e.message:String(e))}),()=>{n=!0}},[_]);let x=async(a,o)=>{u(a),f(null);try{let i=await me(t,[e.id],{urls:[a],...o===void 0?{}:{keepDocument:o}}),s=i.successful[0];if(!s)throw Error(i.failed[0]?.reason||`Destroy failed`);s.docDeleted?r(`Removed from backend; document removed from index`):s.deleted.includes(a)?r(`Removed from backend`):r(`Reference dropped (backend is read-only)`),window.dispatchEvent(new CustomEvent(`workspace:documents:refresh`)),n?.(),b()}catch(e){i(e instanceof Error?e.message:String(e))}finally{u(null)}},C=async(a,o,s)=>{g(!0);try{let i=await Ae(t,[e.id],{to:a,mode:o,keepDocument:s.keepDocument,folder:s.folder,filename:s.filename,onConflict:s.onConflict}),c=i.successful[0];if(!c)throw Error(jn(i.failed,new Map([[e.id,Y(e)||`Document ${e.id}`]]))||`Transfer failed`);let l=c.transfers?.flatMap(e=>e.state===`unchanged`?[]:[e.backend])??[],u=a.join(`, `);o===`delete`?r(`Deleted from ${u}`):l.length===0?r(`Nothing to do — already on ${u}`):r(`${o===`move`?`Moved to`:`Copied to`} ${l.join(`, `)}${c.transfers?.some(e=>e.state===`pending`)?` (pending sync)`:``}`),window.dispatchEvent(new CustomEvent(`workspace:documents:refresh`)),m(null),n?.(),b()}catch(e){i(e instanceof Error?e.message:String(e))}finally{g(!1)}},w=e=>{if((a?.length??0)<=1){f(e.url);return}window.confirm(`Remove this copy from the backend?\n\n${e.url}`)&&x(e.url)};if(s)return(0,Q.jsx)(`p`,{className:`text-sm text-destructive`,children:s});if(!a)return(0,Q.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`Loading locations...`});let E=a.length===0,D=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)(k,{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`})]}),E?(0,Q.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`No byte locations; this object lives only in the workspace database, so there is no file data to copy or move.`}):(0,Q.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,Q.jsxs)(K,{variant:`outline`,size:`sm`,onClick:()=>m(`copy`),title:`Copy the file data to another storage backend (keeps the existing copies)`,children:[(0,Q.jsx)(S,{className:`mr-1 h-3.5 w-3.5`}),` Copy to…`]}),(0,Q.jsxs)(K,{variant:`outline`,size:`sm`,onClick:()=>m(`move`),title:`Move the file data to another storage backend (source released once the copy is durable)`,children:[(0,Q.jsx)(H,{className:`mr-1 h-3.5 w-3.5`}),` Move to…`]})]}),a.map(n=>{let r=dr(n.kind),{backend:a,key:o}=fr(n.url),s=l===n.url;return(0,Q.jsxs)(`div`,{className:`space-y-2 rounded border px-3 py-2 text-sm`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,Q.jsxs)(`span`,{className:`inline-flex min-w-0 items-center gap-2`,children:[(0,Q.jsx)(r,{className:`h-4 w-4 shrink-0 text-muted-foreground`}),(0,Q.jsx)(`span`,{className:`shrink-0 font-mono text-xs`,children:n.backend||a}),(0,Q.jsx)(`span`,{className:`truncate font-mono text-xs text-muted-foreground`,title:n.url,children:o||n.url})]}),(0,Q.jsxs)(`span`,{className:`flex shrink-0 items-center gap-2`,children:[(0,Q.jsx)(`span`,{className:`rounded px-1.5 py-0.5 text-[10px] uppercase ${n.deletable?`bg-muted text-muted-foreground`:`bg-warning/15 text-warning`}`,children:n.deletable?n.kind:`read-only`}),(0,Q.jsx)(`button`,{onClick:()=>ve(t,e.id,D||`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)(U,{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)(T,{className:`h-3.5 w-3.5`})})]})]}),d===n.url&&(0,Q.jsxs)(`div`,{className:`space-y-2 rounded border border-destructive/40 bg-destructive/5 p-2`,children:[(0,Q.jsxs)(`p`,{className:`text-xs`,children:[`This is the object's `,(0,Q.jsx)(`strong`,{children:`last`}),` location. Remove the bytes from the backend and…`]}),(0,Q.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[(0,Q.jsx)(K,{variant:`destructive`,size:`sm`,disabled:s,onClick:()=>void x(n.url,!1),children:`Also remove index entry`}),(0,Q.jsx)(K,{variant:`outline`,size:`sm`,disabled:s,onClick:()=>void x(n.url,!0),children:`Keep index entry (no bytes)`}),(0,Q.jsx)(K,{variant:`ghost`,size:`sm`,onClick:()=>f(null),children:`Cancel`})]})]})]},n.url)}),p&&(0,Mn.createPortal)((0,Q.jsx)(`div`,{className:`fixed inset-0 z-picker flex items-center justify-center bg-scrim p-4 max-md:p-2`,children:(0,Q.jsx)(Ln,{workspaceId:t,documentCount:1,initialMode:p,defaultFilename:D,saving:h,onConfirm:C,onClose:()=>{h||m(null)}})}),window.document.body)]})}var mr=(0,Z.lazy)(()=>a(()=>import(`./LocationTab-DAtqAQ3l.js`),__vite__mapDeps([25,3,4,26,27]))),hr=[{id:`view`,label:`View`,icon:N},{id:`location`,label:`Location`,icon:ae},{id:`metadata`,label:`Metadata`,icon:F},{id:`json`,label:`JSON`,icon:x},{id:`synapses`,label:`Synapses`,icon:te},{id:`backends`,label:`Backends`,icon:k}];function gr({document:e,workspaceId:t,initialTab:n=`view`,initialEdit:r=!1,onChanged:i,className:a=``,compact:o=!1,navigation:s,tabActions:c,onTabChange:l}){let u=Je()!=null,d=Tt(e),f=hr.filter(e=>(e.id!==`location`||d!==null)&&(!u||![`synapses`,`backends`].includes(e.id))),[p,m]=(0,Z.useState)(n),h=`${e.id}:${n}`,[g,_]=(0,Z.useState)(h);h!==g&&(_(h),m(n));let v=f.some(e=>e.id===p)?p:`view`,y=e=>{m(e),l?.(e)},b=o&&!!c&&!s,x=(0,Q.jsx)(`div`,{className:G(b&&`document-detail-header shrink-0 border-b-[3px] bg-muted`),children:(0,Q.jsxs)(`div`,{className:G(`flex min-w-0 items-center`,b&&`mx-auto h-[calc(3rem-4px)] w-full max-w-[var(--document-reading-width,100%)] gap-1 pl-2 pr-2 sm:pl-4`),children:[(0,Q.jsx)(_t,{tabs:f,active:v,onChange:y,className:G(`min-w-0 flex-1 px-1`,b&&`h-full border-b-0 px-0 max-sm:gap-0 max-sm:[&>button]:px-2.5`),iconOnly:o}),c]})});return(0,Q.jsxs)(`div`,{className:`flex h-full min-h-0 flex-col ${a}`,children:[s?(0,Q.jsx)(On,{...s,tabs:x,section:v,onDocument:()=>y(`view`),onSection:()=>y(`view`),onBack:v===`view`?s.onBack:()=>y(`view`)}):x,(0,Q.jsx)(`div`,{className:`min-h-0 flex-1 overflow-y-auto`,children:(0,Q.jsxs)(`div`,{className:`mx-auto h-full w-full max-w-[var(--document-reading-width,100%)] p-4`,children:[v===`view`&&(0,Q.jsx)(ir,{document:e,workspaceId:t,initialEdit:r&&!u,onChanged:i}),v===`location`&&d&&(0,Q.jsx)(Z.Suspense,{fallback:(0,Q.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`Loading map…`}),children:(0,Q.jsx)(mr,{lat:d.lat,lon:d.lon})}),v===`metadata`&&(0,Q.jsx)(cr,{document:e,workspaceId:t}),v===`json`&&(0,Q.jsx)(lr,{document:e,workspaceId:t}),v===`synapses`&&!u&&(0,Q.jsx)(ur,{document:e,workspaceId:t}),v===`backends`&&!u&&(0,Q.jsx)(pr,{document:e,workspaceId:t,onChanged:i})]})})]})}export{en as _,Kn as a,Dt as b,Ln as c,Dn as d,wn as f,an as g,nn as h,Zn as i,jn as l,rn as m,Xn as n,Jn as o,tn as p,Yn as r,Bn as s,gr as t,On as u,Ut as v,Pt as y};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
.canvas-navigation{border-top:2px solid var(--border);border-bottom:1px solid var(--border);background:var(--background);flex-shrink:0;min-width:0}.canvas-navigation.has-tabs{border-top:0}.canvas-navigation-tabs{background:var(--background);flex-direction:column;flex-shrink:0;justify-content:flex-end;height:3rem;padding:0 8px;display:flex;position:relative}.canvas-tab-divider{z-index:1;inset-inline:0;background:var(--border);pointer-events:none;height:4px;position:absolute;bottom:0}.canvas-surface-body{background:var(--background);flex-direction:column;flex:1;min-width:0;min-height:0;display:flex;overflow:hidden}.canvas-surface-body>.canvas-navigation{border-top:0}@media (width>=640px){.canvas-surface-body.is-framed{border:1px solid var(--border);border-radius:var(--sheet-radius);margin:8px}}.canvas-address-row{align-items:center;gap:4px;min-width:0;padding:6px;display:flex}.canvas-nav-button{width:44px;height:44px;color:var(--muted-foreground);cursor:pointer;border-radius:10px;flex:0 0 44px;justify-content:center;align-items:center;display:inline-flex;position:relative}.canvas-nav-button:hover{background:var(--accent);color:var(--foreground)}.canvas-nav-button:focus-visible,.canvas-address-crumbs:focus-visible,.canvas-address-crumbs button:focus-visible{outline:2px solid var(--ring);outline-offset:-2px}.canvas-nav-button:disabled{opacity:.35;cursor:default}.canvas-address-field{border:1px solid var(--border);background:var(--muted);border-radius:12px;flex:1;min-width:0;display:flex}.canvas-address-field:focus-within{border-color:var(--ring)}.canvas-address-crumbs{scrollbar-width:none;white-space:nowrap;overscroll-behavior-x:contain;flex:1;align-items:center;min-width:0;padding-left:8px;font-size:13px;display:flex;overflow-x:auto}.canvas-address-crumbs::-webkit-scrollbar{display:none}.canvas-address-crumbs button,.canvas-address-label{cursor:pointer;border-radius:4px;flex-shrink:0;min-height:44px;padding:0 4px}.canvas-address-crumbs button:hover{color:var(--foreground);text-underline-offset:4px;text-decoration:underline}.canvas-address-label{align-items:center;display:inline-flex}.canvas-address-workspace{white-space:nowrap;cursor:pointer;flex:none;align-items:center;gap:6px;max-width:120px;min-height:44px;padding:0 4px 0 10px;font-size:13px;font-weight:600;display:inline-flex}.canvas-address-workspace:hover{text-decoration:underline}.canvas-address-crumbs.is-scrolled{-webkit-mask-image:linear-gradient(90deg,#0000,#000 12px);mask-image:linear-gradient(90deg,#0000,#000 12px)}@media (width<=639px){.canvas-address-workspace{max-width:90px}}.canvas-address-tree,.canvas-address-root{color:var(--muted-foreground);font-family:monospace}.canvas-address-segment{flex-shrink:0;align-items:center;gap:2px;display:flex}.canvas-address-segment>span{color:var(--muted-foreground)}.canvas-address-segment button{text-overflow:ellipsis;max-width:160px;overflow:hidden}.canvas-address-section{color:var(--primary)}.canvas-address-search{border-radius:0 11px 11px 0}.canvas-add-button{color:var(--primary-foreground);border-radius:50%}.canvas-add-button:before{content:"";background:var(--primary);border-radius:50%;position:absolute;inset:6px}.canvas-add-button>svg{width:18px;height:18px;position:relative}.canvas-add-button:hover{color:var(--primary-foreground);background:0 0}.canvas-add-button:hover:before{opacity:.85}.canvas-filter-button[data-active=true]{background:var(--accent);color:var(--foreground)}.canvas-nav-dot{background:var(--primary);border-radius:50%;width:5px;height:5px;position:absolute;top:7px;right:7px}.canvas-search-input{flex:1;align-items:center;min-width:0;display:flex;position:relative}.canvas-search-input input{background:0 0;outline:none;flex:1;width:100%;min-width:0;height:44px;padding:0 10px;font-size:16px}.canvas-search-dropdown{padding:0 12px 10px}.canvas-search-heading{color:var(--muted-foreground);justify-content:space-between;align-items:center;gap:8px;font-size:11px;display:flex}.canvas-search-heading .canvas-nav-button{height:36px}.canvas-search-options{flex-direction:column;gap:8px;display:flex}.canvas-search-scopes{flex-wrap:wrap;align-items:center;gap:6px;font-size:12px;display:flex}.canvas-search-scopes>span{color:var(--muted-foreground);margin-right:3px}.canvas-search-scopes button{border:1px solid var(--border);cursor:pointer;border-radius:8px;min-height:40px;padding:0 12px}.canvas-search-scopes button[aria-pressed=true]{background:var(--foreground);color:var(--background);border-color:var(--foreground)}.canvas-search-queries{flex-wrap:wrap;gap:6px;display:flex}.canvas-search-query{border:1px solid var(--border);background:var(--muted);border-radius:8px;align-items:center;gap:6px;max-width:100%;padding-left:8px;font-size:12px;display:inline-flex}.canvas-search-query-exact{border-style:dashed}.canvas-search-query>span{text-overflow:ellipsis;white-space:nowrap;min-width:0;overflow:hidden}.canvas-search-query button{cursor:pointer;justify-content:center;align-items:center;min-width:40px;min-height:40px;display:flex}.canvas-search-clear{padding:8px;font-size:12px;text-decoration:underline}@media (width>=640px){.canvas-address-row{gap:6px;padding:8px 10px}}
|
|
1
|
+
.canvas-navigation{border-top:2px solid var(--border);border-bottom:1px solid var(--border);background:var(--background);flex-shrink:0;min-width:0}.canvas-navigation.has-tabs{border-top:0}.canvas-navigation-tabs{background:var(--background);flex-direction:column;flex-shrink:0;justify-content:flex-end;height:3rem;padding:0 8px;display:flex;position:relative}.canvas-tab-divider{z-index:1;inset-inline:0;background:var(--border);pointer-events:none;height:4px;position:absolute;bottom:0}.canvas-surface-body{background:var(--background);flex-direction:column;flex:1;min-width:0;min-height:0;display:flex;overflow:hidden}.canvas-surface-body>.canvas-navigation{border-top:0}@media (width>=640px){.canvas-surface-body.is-framed{border:1px solid var(--border);border-radius:var(--sheet-radius);margin:8px}}.canvas-address-row{align-items:center;gap:4px;min-width:0;padding:6px;display:flex}.canvas-nav-button{width:44px;height:44px;color:var(--muted-foreground);cursor:pointer;border-radius:10px;flex:0 0 44px;justify-content:center;align-items:center;display:inline-flex;position:relative}.canvas-nav-button:hover{background:var(--accent);color:var(--foreground)}.canvas-nav-button:focus-visible,.canvas-address-crumbs:focus-visible,.canvas-address-crumbs button:focus-visible{outline:2px solid var(--ring);outline-offset:-2px}.canvas-nav-button:disabled{opacity:.35;cursor:default}.canvas-address-field{border:1px solid var(--border);background:var(--muted);border-radius:12px;flex:1;min-width:0;display:flex}.canvas-address-field:focus-within{border-color:var(--ring)}.canvas-address-crumbs{scrollbar-width:none;white-space:nowrap;overscroll-behavior-x:contain;flex:1;align-items:center;min-width:0;padding-left:8px;font-size:13px;display:flex;overflow-x:auto}.canvas-address-crumbs::-webkit-scrollbar{display:none}.canvas-address-crumbs button,.canvas-address-label{cursor:pointer;border-radius:4px;flex-shrink:0;min-height:44px;padding:0 4px}.canvas-address-crumbs button:hover{color:var(--foreground);text-underline-offset:4px;text-decoration:underline}.canvas-address-label{align-items:center;display:inline-flex}.canvas-address-workspace{white-space:nowrap;cursor:pointer;flex:none;align-items:center;gap:6px;max-width:120px;min-height:44px;padding:0 4px 0 10px;font-size:13px;font-weight:600;display:inline-flex}.canvas-address-workspace:hover{text-decoration:underline}.canvas-address-crumbs.is-scrolled{-webkit-mask-image:linear-gradient(90deg,#0000,#000 12px);mask-image:linear-gradient(90deg,#0000,#000 12px)}@media (width<=639px){.canvas-address-workspace{max-width:90px}}.canvas-address-tree,.canvas-address-root{color:var(--muted-foreground);font-family:monospace}.canvas-address-segment{flex-shrink:0;align-items:center;gap:2px;display:flex}.canvas-address-segment>span{color:var(--muted-foreground)}.canvas-address-segment button{text-overflow:ellipsis;max-width:160px;overflow:hidden}.canvas-address-section{color:var(--primary)}.canvas-address-search{border-radius:0 11px 11px 0}.canvas-add-button{color:var(--primary-foreground);border-radius:50%}.canvas-add-button:before{content:"";background:var(--primary);border-radius:50%;position:absolute;inset:6px}.canvas-add-button>svg{width:18px;height:18px;position:relative}.canvas-add-button:hover{color:var(--primary-foreground);background:0 0}.canvas-add-button:hover:before{opacity:.85}.canvas-filter-button[data-active=true]{background:var(--accent);color:var(--foreground)}.canvas-nav-dot{background:var(--primary);border-radius:50%;width:5px;height:5px;position:absolute;top:7px;right:7px}.canvas-search-input{flex:1;align-items:center;min-width:0;display:flex;position:relative}.canvas-search-input input{background:0 0;outline:none;flex:1;width:100%;min-width:0;height:44px;padding:0 10px;font-size:16px}.canvas-search-dropdown{padding:0 12px 10px}.canvas-search-heading{color:var(--muted-foreground);justify-content:space-between;align-items:center;gap:8px;font-size:11px;display:flex}.canvas-search-heading .canvas-nav-button{height:36px}.canvas-search-options{flex-direction:column;gap:8px;display:flex}.canvas-search-scopes{flex-wrap:wrap;align-items:center;gap:6px;font-size:12px;display:flex}.canvas-search-scopes>span{color:var(--muted-foreground);margin-right:3px}.canvas-search-scopes button{border:1px solid var(--border);cursor:pointer;border-radius:8px;min-height:40px;padding:0 12px}.canvas-search-scopes button[aria-pressed=true]{background:var(--foreground);color:var(--background);border-color:var(--foreground)}.canvas-search-queries{flex-wrap:wrap;gap:6px;display:flex}.canvas-search-query{border:1px solid var(--border);background:var(--muted);border-radius:8px;align-items:center;gap:6px;max-width:100%;padding-left:8px;font-size:12px;display:inline-flex}.canvas-search-query-exact{border-style:dashed}.canvas-search-query>span{text-overflow:ellipsis;white-space:nowrap;min-width:0;overflow:hidden}.canvas-search-query button{cursor:pointer;justify-content:center;align-items:center;min-width:40px;min-height:40px;display:flex}.canvas-search-clear{padding:8px;font-size:12px;text-decoration:underline}@media (width>=640px){.canvas-address-row{gap:6px;padding:8px 10px}}@media (width<=767px){.canvas-address-row{gap:2px;padding:4px 2px}.canvas-address-crumbs{touch-action:pan-x}.canvas-address-crumbs .canvas-address-workspace{max-width:none;padding-left:4px}.canvas-address-segment button{max-width:none}}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{o as e}from"./rolldown-runtime-C0FnF6B9.js";import{l as t,u as n}from"./code-editor-BOIngd5F.js";import{Jr as r,Wr as i,hn as a,nr as o,pn as s}from"./ui-76Hw0NU_.js";import{Hn as c,wn as l}from"./workspace-46EFyEKZ.js";import{_ as u,g as d,h as f,m as p,p as m}from"./ObjectPropertiesCard-
|
|
1
|
+
import{o as e}from"./rolldown-runtime-C0FnF6B9.js";import{l as t,u as n}from"./code-editor-BOIngd5F.js";import{Jr as r,Wr as i,hn as a,nr as o,pn as s}from"./ui-76Hw0NU_.js";import{Hn as c,wn as l}from"./workspace-46EFyEKZ.js";import{_ as u,g as d,h as f,m as p,p as m}from"./ObjectPropertiesCard-B9gkyowI.js";import{r as h}from"./date-time-picker-Bzu8H_Oa.js";import{n as g}from"./use-document-modal-PG8bQyIB.js";var _=e(n(),1),v=new Map;function y(e){v.set(e.type,e)}function b(e){return v.get(e)}function x(){return[...v.values()]}var S=450,C=10;function w(e,t){let{open:n}=g(),r=(0,_.useRef)(null),i=(0,_.useRef)(null),a=(0,_.useRef)(!1),o=()=>{e&&n(e,t)},s=()=>{r.current&&=(clearTimeout(r.current),null)};return{activationProps:{role:`button`,tabIndex:0,onClick:()=>{if(a.current){a.current=!1;return}o()},onKeyDown:e=>{(e.key===`Enter`||e.key===` `)&&(e.preventDefault(),o())},onContextMenu:e=>{e.preventDefault(),o()},onPointerDown:e=>{e.pointerType===`touch`&&(i.current={x:e.clientX,y:e.clientY},a.current=!1,s(),r.current=setTimeout(()=>{a.current=!0,o()},S))},onPointerMove:e=>{i.current&&Math.hypot(e.clientX-i.current.x,e.clientY-i.current.y)>C&&s()},onPointerUp:s,onPointerCancel:s,onPointerLeave:s},stopRowActivation:e=>e.stopPropagation()}}var T=t(),E=`data/schema/task`;function D({doc:e,workspaceId:t,readOnly:n,onChanged:a}){let c=u(e),[g,v]=(0,_.useState)(!1),{replicating:y,label:b}=l(e),x=c.status===`completed`,S=c.status??`pending`,C=f(c),{activationProps:E,stopRowActivation:D}=w(e,t),O=async()=>{if(!(n||g)){v(!0);try{await d(t,e,x?`pending`:`completed`),a()}catch{}finally{v(!1)}}};return(0,T.jsxs)(`div`,{...E,title:`Open details`,className:`canvas-no-drag flex cursor-pointer items-start gap-2.5 rounded-md border bg-card px-2.5 py-2 transition-colors hover:bg-accent/50 focus:outline-none focus-visible:ring-2 focus-visible:ring-ring ${y?`opacity-60`:``}`,children:[(0,T.jsx)(`button`,{type:`button`,onClick:e=>{D(e),O()},disabled:n||g||y,"aria-pressed":x,title:x?`Mark not done`:`Mark done`,className:`canvas-no-drag mt-0.5 flex h-4 w-4 shrink-0 items-center justify-center rounded border transition-colors ${x?`border-success bg-success text-success-foreground`:`border-input hover:border-success`} ${n?`cursor-default opacity-70`:``}`,children:g?(0,T.jsx)(s,{className:`h-2.5 w-2.5 animate-spin`}):x&&(0,T.jsx)(i,{className:`h-3 w-3`})}),(0,T.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,T.jsx)(`div`,{className:`truncate text-sm ${x?`text-muted-foreground line-through`:``}`,children:c.title||`Todo ${e.id}`}),(0,T.jsxs)(`div`,{className:`mt-0.5 flex flex-wrap items-center gap-1.5 text-[11px]`,children:[(0,T.jsx)(`span`,{className:`rounded-full px-1.5 py-0.5 ${m[S]}`,children:h[S]}),c.dueDate&&(0,T.jsxs)(`span`,{className:`inline-flex items-center gap-0.5 ${C?`font-medium text-destructive`:`text-muted-foreground`}`,children:[(0,T.jsx)(r,{className:`h-3 w-3`}),p(c.dueDate)]}),typeof c.priority==`number`&&(0,T.jsxs)(`span`,{className:`inline-flex items-center gap-0.5 text-muted-foreground`,children:[(0,T.jsx)(o,{className:`h-3 w-3`}),`P`,c.priority]}),y&&(0,T.jsxs)(`span`,{className:`inline-flex items-center gap-1 text-muted-foreground`,role:`status`,children:[(0,T.jsx)(s,{className:`h-3 w-3 animate-spin`}),b]})]})]})]})}function O({config:e,setConfig:t,canvas:n}){let r=typeof e.pageSize==`number`?e.pageSize:50,[i,a]=(0,_.useState)([]),[o,s]=(0,_.useState)(!0),[l,d]=(0,_.useState)(0),f=n.interactive===!1,p=n.readOnly!==!0,[m,h]=(0,_.useState)(e.hideDone===!0),g=p?e.hideDone===!0:m,v=n=>{p?t({...e,hideDone:n}):h(n)};(0,_.useEffect)(()=>{let e=!1;return(async()=>{s(!0);try{let t=await n.fetchDocuments({limit:r,allOf:[E],sortBy:`tasks`,order:`asc`});if(e)return;a((t.payload||[]).filter(e=>e.schema===c))}catch{e||a([])}finally{e||s(!1)}})(),()=>{e=!0}},[n,r,l]),(0,_.useEffect)(()=>{let e=()=>d(e=>e+1);return window.addEventListener(`workspace:documents:refresh`,e),()=>window.removeEventListener(`workspace:documents:refresh`,e)},[]);let y=(0,_.useCallback)(()=>d(e=>e+1),[]),b=g?i.filter(e=>u(e).status!==`completed`):i,x=i.filter(e=>{let t=u(e).status;return t!==`completed`&&t!==`cancelled`}).length;return(0,T.jsxs)(`div`,{className:`flex h-full flex-col`,children:[(0,T.jsxs)(`div`,{className:`canvas-no-drag flex items-center justify-between gap-2 border-b px-1 pb-2`,children:[(0,T.jsxs)(`span`,{className:`text-xs text-muted-foreground`,children:[x,` open`]}),(0,T.jsxs)(`label`,{className:`flex items-center gap-1.5 text-xs text-muted-foreground`,children:[(0,T.jsx)(`input`,{type:`checkbox`,checked:g,onChange:e=>v(e.target.checked),className:`h-3 w-3`}),`Hide done`]})]}),(0,T.jsx)(`div`,{className:`flex-1 space-y-1.5 overflow-y-auto p-1`,children:o&&i.length===0?(0,T.jsx)(`div`,{className:`p-3 text-sm text-muted-foreground`,children:`Loading todos…`}):b.length===0?(0,T.jsx)(`div`,{className:`p-3 text-sm text-muted-foreground`,children:`No todos in this canvas' context.`}):b.map(e=>(0,T.jsx)(D,{doc:e,workspaceId:n.workspaceId,readOnly:f,onChanged:y},e.id))})]})}y({type:`todos`,name:`Todos`,icon:a,defaultSize:{w:4,h:6,minW:3,minH:3},mobileHeight:.6,defaultConfig:{pageSize:50,hideDone:!1},component:O});export{y as a,x as i,w as n,b as r,D as t};
|
|
Binary file
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{o as e}from"./rolldown-runtime-C0FnF6B9.js";import{l as t,u as n}from"./code-editor-BOIngd5F.js";import{_ as r,g as i,h as a}from"./chunk-62JRHF6Z-vspAGgtK.js";import{t as o}from"./socket-CtH3EU9m.js";import{n as s}from"./use-toast-BlLDqSUO.js";import{o as c,s as l}from"./LinkToCard-VXpoeMDH.js";import{G as u,Sn as d,V as ee,bn as te,zt as ne}from"./workspace-46EFyEKZ.js";import{r as re}from"./document-list-CwStaizB.js";import{n as ie}from"./use-toolbox-Ck_cLGgf.js";import{E as ae,_ as oe,a as se,b as ce,i as le,l as ue,o as de}from"./context-BGgz0Y_q.js";import{i as fe}from"./color-DFEH4BfK.js";import{t as pe}from"./geo-CZfs0E-x.js";import{a as me,i as he,o as ge}from"./workspace-BydSRtST.js";import{i as _e}from"./use-menu-CaiLyPdw.js";import{a as ve,c as ye,i as be,l as xe,n as Se,o as Ce,r as we,s as Te,t as Ee}from"./content-app-view-3BCpYf7m.js";import{t as De}from"./use-workspace-identity-KxY9injc.js";var f=e(n(),1),p=t();function Oe(e,t){if(!e||!t)return`/`;let n=`${t}://`;if(!e.startsWith(n))return`/`;let r=e.slice(n.length).replace(/^\/+/,``).replace(/\/+$/,``);return r?`/${r}`:`/`}function m(){let{contextId:e}=r(),t=a(),n=i(),m=new URLSearchParams(t.search).get(`ownerId`)||void 0,h=(0,f.useMemo)(()=>{let e=new URLSearchParams(t.search),n=e.getAll(`q`).map(e=>e.trim()).filter(Boolean),r=(e.get(`search`)||``).trim();return n.length?n:r?[r]:[]},[t.search]),{showToast:g,showProgress:ke}=s(),{state:_,saveFilters:Ae,setSort:je,setAccentColor:v,setMapDocuments:y}=ie(),{openM1Drawer:Me,openM2Drawer:Ne,goBack:Pe}=_e(),b=_.filters.features.allOf,Fe=_.filters.features.anyOf,Ie=_.filters.features.noneOf,Le=[...he(_.filters.timeline),...me(_.filters.geo),...ge(_.filters.lens,_.filters.geo.includeUnlocated)],x=JSON.stringify({a:b,b:Fe,c:Ie,d:Le,ids:_.filters.lens.ids,sort:_.filters.sort,geoSelection:_.geoSelection,includeUnlocated:_.filters.geo.includeUnlocated}),S=(0,f.useMemo)(()=>JSON.parse(x),[x]),[C,w]=(0,f.useState)(null),[Re,ze]=(0,f.useState)(!0),[Be,Ve]=(0,f.useState)(null),[T,E]=(0,f.useState)([]),[He,Ue]=(0,f.useState)(!1),[We,D]=(0,f.useState)(0),[Ge,Ke]=(0,f.useState)([]),[O,k]=(0,f.useState)(1),[A,qe]=(0,f.useState)(50),[j,M]=(0,f.useState)(h),[N,P]=(0,f.useState)(!1),[F,Je]=(0,f.useState)(null),[I,Ye]=(0,f.useState)(!1),L=(0,f.useRef)(!1),R=F?.id===C?.id&&F?.url===C?.url?F?.path:null,Xe=new URLSearchParams(t.search).get(`layer`),z=!!m,Ze=De(z?void 0:C?.workspaceName||C?.workspaceId),B=C?Oe(C.url,C.workspaceName):`/`,Qe=Xe?`context-layer`:`context`,V=!_.liveEnabled&&typeof C?.metadata?.toolboxSearchQuery==`string`?C.metadata.toolboxSearchQuery:``,H=z?null:C?.workspaceName??null,[$e,et]=(0,f.useState)(null);(0,f.useEffect)(()=>{if(!H)return;let e=!1;return u(H,d).then(t=>{e||et({key:H,tree:t})}).catch(()=>{e||et({key:H,tree:null})}),()=>{e=!0}},[H]);let U=H&&$e?.key===H?$e.tree:null,W=!Xe&&!z&&U?B===`/`?U:ee(U,B):null,G=`${C?.workspaceName??``}\0${B}`,[K,tt]=(0,f.useState)(null),q=K?.key===G?K.views:Ce(W?.metadata),J=K?.key===G?K.activeId:q[0]?.id??be.id,Y=q.find(e=>e.id===J)??q[0]??be,X=ve(Y);xe(ye({workspace:C?.workspaceName||C?.workspaceId||null,treeNameOrId:_.activeTreeName,path:B,contextId:e??null,scope:`context`},{..._.filters,features:{..._.filters.features,allOf:X?[...b,X]:b}},_.geoSelection,j));let nt=e=>{k(1),tt({key:G,views:q,activeId:e})},rt=(e,t)=>{t&&t!==J&&k(1),tt({key:G,views:e,activeId:t??J}),C?.workspaceName&&te(C.workspaceName,B,{metadata:{...W?.metadata??{},views:e}},d).catch(()=>{g({title:`View not saved`,description:`Could not persist views to the layer`,variant:`destructive`})})},Z=(0,f.useRef)(null);(0,f.useEffect)(()=>()=>Z.current?.abort(),[]);let Q=(0,f.useCallback)(async()=>{if(!e)return;Z.current?.abort();let t=new AbortController;Z.current=t,Ue(!0);try{let n=await de(e,X?[...S.a,X]:S.a,S.d,{...S.sort,geoSelection:S.geoSelection,includeUnlocated:S.includeUnlocated,ids:S.ids,signal:t.signal,limit:A,page:O,queries:j.length?j:void 0,anyOf:S.b,noneOf:S.c,applyContextSpec:!1},m);if(t.signal.aborted)return;E(n),D(n.totalCount||n.count||n.length)}catch(e){if(t.signal.aborted)return;g({title:`Error`,description:e instanceof Error?e.message:`Failed to fetch documents`,variant:`destructive`}),E([]),D(0)}finally{t.signal.aborted||Ue(!1)}},[e,O,A,m,j,S,g,X]),it=(0,f.useCallback)(async()=>{if(e){ze(!0);try{let t=z?await se(e,m):await se(e);if(!t)throw Error(`No context data received.`);let n=t.workspace,r=t.workspaceId||(typeof n==`string`?n:n?.id)||``,i=t.workspaceName||(typeof n==`string`?n:n?.name)||``;w({id:t.id,userId:t.userId,url:t.url,baseUrl:t.baseUrl||null,path:t.path||null,pathArray:t.pathArray||[],workspaceId:r,workspaceName:i,acl:t.acl||{},createdAt:t.createdAt,updatedAt:t.updatedAt,locked:t.locked||!1,serverContextArray:t.serverContextArray||[],clientContextArray:t.clientContextArray||[],contextBitmapArray:t.contextBitmapArray||[],featureBitmapArray:t.featureBitmapArray||[],filterArray:t.filterArray||[],pendingUrl:t.pendingUrl||null,description:t.description||null,metadata:t.metadata||{},name:t.name??null,color:t.color??null,icon:t.icon??null}),Ve(null)}catch(t){let n=t instanceof Error?t.message:`Failed to fetch context ${e}`;Ve(n),w(null),g({title:`Error`,description:n,variant:`destructive`})}ze(!1)}},[e,m,z,g]);(0,f.useEffect)(()=>{it()},[it]);let at=fe(C?.color)||null;(0,f.useEffect)(()=>(v(at),()=>v(null)),[at,v]);let ot=_.geoSelection,st=C?.workspaceName||C?.workspaceId||null;(0,f.useEffect)(()=>{y(T,st)},[T,st,y]),(0,f.useEffect)(()=>()=>y([]),[y]);let ct=(0,f.useMemo)(()=>ot?T.filter(e=>pe(e,ot,_.filters.geo.includeUnlocated)):T,[T,ot,_.filters.geo.includeUnlocated]),lt=C?.id,ut=C?.url;(0,f.useEffect)(()=>{lt&&Q()},[lt,ut,Q]),(0,f.useEffect)(()=>{let e=()=>Q();return window.addEventListener(`workspace:documents:refresh`,e),()=>window.removeEventListener(`workspace:documents:refresh`,e)},[Q]);let[dt,ft]=(0,f.useState)(x);dt!==x&&(ft(x),k(1));let[pt,mt]=(0,f.useState)(e);pt!==e&&(mt(e),k(1),P(!1));let[ht,gt]=(0,f.useState)(h);ht!==h&&(gt(h),M(h),k(1));let[_t,vt]=(0,f.useState)({urlSearchQueries:h,ignoreSavedSearch:N,savedContextSearchQuery:V});(_t.urlSearchQueries!==h||_t.ignoreSavedSearch!==N||_t.savedContextSearchQuery!==V)&&(vt({urlSearchQueries:h,ignoreSavedSearch:N,savedContextSearchQuery:V}),!new URLSearchParams(t.search).has(`q`)&&!h.length&&!N&&(M(V?[V]:[]),k(1)));let $=(0,f.useCallback)(e=>{let r=new URLSearchParams(t.search);r.delete(`q`),r.delete(`search`);for(let t of e)r.append(`q`,t);let i=r.toString();n(`${t.pathname}${i?`?${i}`:``}${t.hash}`)},[t.pathname,t.search,t.hash,n]),yt=(0,f.useCallback)(e=>{let t=e.trim();if(!t)return;P(!1);let n=j.includes(t)?j:[...j,t];M(n),$(n)},[j,$]),bt=(0,f.useCallback)(e=>{let t=e<0?[]:j.filter((t,n)=>n!==e);t.length===0&&P(!0),M(t),$(t)},[j,$]),xt=(j[0]||``).trim(),St=!!_.activeContextType&&(_.isDirty||xt!==(_.savedSearchQuery||V||``));(0,f.useEffect)(()=>{if(!e)return;let t=`context:${m?`${m}/`:``}${e}`,n=()=>o.emit(`subscribe`,{channel:t}),r=()=>o.emit(`unsubscribe`,{channel:t}),i=o.on(`connect`,n);n();let a=new Map,s=(t,n)=>{let r=Date.now(),i=`${t}:${n?.id||n?.contextId||e}`;return(a.get(i)||0)+1e3>r?!1:(a.set(i,r),!0)},c=t=>{let n=t,r=n?.context||n;(r?.id===e||r?.contextId===e)&&s(`ctx:updated`,r)&&(w(e=>e?{...e,...r}:null),r.url&&Q())},l=t=>{let n=t,r=n?.id||n?.contextId||n?.context?.id,i=n?.url||n?.context?.url;r===e&&typeof i==`string`&&s(`ctx:url`,n)&&(w(e=>e?{...e,url:i}:null),Q())},u=t=>{let n=t;(n?.contextId||n?.id||n?.context?.id)===e&&s(`doc:changed`,n)&&Q()},d=[[`context.updated`,c],[`context:updated`,c],[`context.url.set`,l],[`context:url:set`,l],[`document.inserted`,u],[`document.updated`,u],[`document.removed`,u],[`document.removed.batch`,u],[`document.linked`,u],[`document.unlinked`,u],[`document.linked.batch`,u],[`document.unlinked.batch`,u],[`document.deleted`,u],[`document.deleted.batch`,u]];return d.forEach(([e,t])=>o.on(e,t)),()=>{i(),r(),d.forEach(([e,t])=>o.off(e,t))}},[e,m,Q]);let Ct=async e=>{if(C)try{await ce(C.id,[e],m,B),E(t=>t.filter(t=>t.id!==e)),D(e=>Math.max(0,e-1)),g({title:`Success`,description:`Document removed from context.`})}catch(e){g({title:`Error`,description:e instanceof Error?e.message:`Failed to remove document`,variant:`destructive`})}},wt=async e=>{if(C)try{await le(C.id,[e],m,B),E(t=>t.filter(t=>t.id!==e)),D(e=>Math.max(0,e-1)),g({title:`Success`,description:`Document deleted.`})}catch(e){g({title:`Error`,description:e instanceof Error?e.message:`Failed to delete document`,variant:`destructive`})}},Tt=async e=>{if(C)try{await ce(C.id,e,m,B),E(t=>t.filter(t=>!e.includes(t.id))),D(t=>Math.max(0,t-e.length)),g({title:`Success`,description:`${e.length} document(s) removed.`})}catch(e){g({title:`Error`,description:e instanceof Error?e.message:`Failed to remove documents`,variant:`destructive`})}},Et=async e=>{if(C)try{await le(C.id,e,m,B),E(t=>t.filter(t=>!e.includes(t.id))),D(t=>Math.max(0,t-e.length)),g({title:`Success`,description:`${e.length} document(s) deleted.`})}catch(e){g({title:`Error`,description:e instanceof Error?e.message:`Failed to delete documents`,variant:`destructive`})}},Dt=e=>{Ke(e),g({title:`Copied`,description:`${e.length} document(s) copied to clipboard`})},Ot=async(e,t,n={})=>{if(!C)return!1;let r=ke({title:`Pasting…`,description:`${t.length} document(s) → "${e}"`});try{let i=n.targetTreeName&&!z?await ne(C.workspaceName||C.workspaceId,e,t,n.targetTreeName,n.targetTreeType):await oe(C.id,e,t,m);return r.done(i?{title:`Success`,description:`${t.length} document(s) pasted to "${e}"`}:void 0),i&&(Ke([]),await Q()),i}catch(e){return r.fail({title:`Error`,description:e instanceof Error?e.message:`Failed to paste documents`,variant:`destructive`}),!1}},kt=async(e,t)=>{if(!C)return!1;try{let n=await ue(C.workspaceId,t,e);return n&&(re(C.workspaceName||C.workspaceId,`context`,t),g({title:`Success`,description:`Imported ${e.length} document(s) to "${t}"`})),n}catch(e){return g({title:`Error`,description:e instanceof Error?e.message:`Failed to import documents`,variant:`destructive`}),!1}},At=async()=>{if(!C||!R||z||L.current)return;let e={id:C.id,url:C.url,path:R};L.current=!0,Ye(!0);try{let t=await ae(e.id,`${C.workspaceName}://${e.path.replace(/^\/+/,``)}`);w(n=>n?.id===e.id&&n.url===e.url?{...n,url:t.url,path:e.path}:n),Je(null),k(1),window.dispatchEvent(new CustomEvent(`contexts:refresh`,{detail:{contextId:e.id}})),g({title:`Saved`,description:`Context path updated`})}catch(e){g({title:`Error`,description:e instanceof Error?e.message:`Could not update context path`,variant:`destructive`})}finally{L.current=!1,Ye(!1)}};if(Re)return(0,p.jsx)(`div`,{className:`flex items-center justify-center h-full`,children:(0,p.jsxs)(`div`,{className:`text-center space-y-2`,children:[(0,p.jsx)(`div`,{className:`animate-spin rounded-full h-8 w-8 border-b-2 border-primary mx-auto`}),(0,p.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`Loading context...`})]})});if(Be&&!C)return(0,p.jsxs)(`div`,{className:`flex items-center justify-center h-full text-destructive`,children:[`Error: `,Be]});if(!C)return(0,p.jsx)(`div`,{className:`flex items-center justify-center h-full text-muted-foreground`,children:`Context not found.`});let jt=fe(C.color);return(0,p.jsx)(`div`,{className:`flex flex-col h-full min-h-0`,children:(0,p.jsx)(Te,{onBack:Pe,accentColor:jt,navigationTabs:W?(0,p.jsx)(we,{views:q,activeId:J,onSelect:nt,onSave:rt,accentColor:jt}):void 0,workspaceLabel:Ze?.label||C.workspaceName||C.workspaceId,workspaceIcon:Ze?.icon,treeName:d,urlType:Qe,urlDisplay:C.url,contextPath:B,workspaceId:C.workspaceName||C.workspaceId,documentSchema:X,linkTree:U,documents:ct,isLoading:He,totalCount:We,currentPage:O,pageSize:A,onPageChange:k,onPageSizeChange:e=>{qe(e),k(1)},onRemoveDocument:B===`/`?void 0:Ct,onDeleteDocument:wt,onRemoveDocuments:B===`/`?void 0:Tt,onDeleteDocuments:Et,onCopyDocuments:Dt,onPasteDocuments:Ot,onImportDocuments:z?void 0:kt,pastedDocumentIds:Ge,backendSearchQueries:j,onBackendSearch:yt,serverSort:_.filters.sort,onServerSortChange:je,onRemoveBackendQuery:bt,canSaveChanges:St,isSavingChanges:_.isSaving,onSaveChanges:Ae,onBrowseTree:!z&&e?()=>Ne(`contexts`,`detail`,e):void 0,onBrowseWorkspaces:()=>Me(`workspaces`),onNavigatePath:z?void 0:e=>{L.current||Je({id:C.id,url:C.url,path:e})},contentBanner:R?(0,p.jsxs)(`div`,{className:`border-b bg-warning/10 px-4 py-2`,role:`status`,children:[(0,p.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`Set this context to the selected path? Contents stay at the current path until you apply it.`}),(0,p.jsxs)(`div`,{className:`flex min-w-0 items-center gap-2`,children:[(0,p.jsx)(l,{items:c(R,C.workspaceName),label:`Selected context path`}),(0,p.jsx)(`button`,{type:`button`,disabled:I,onClick:()=>void At(),className:`shrink-0 rounded border px-3 py-1 text-sm hover:bg-accent disabled:opacity-50`,children:I?`Setting…`:`Set`}),(0,p.jsx)(`button`,{type:`button`,disabled:I,onClick:()=>Je(null),className:`shrink-0 rounded px-2 py-1 text-sm hover:bg-accent disabled:opacity-50`,children:`Cancel`})]})]}):void 0,children:Y.kind===`columns`?(0,p.jsx)(Se,{documents:ct,workspaceId:C.workspaceName||C.workspaceId,columns:Y.columns??[],onColumnsChange:e=>rt(q.map(t=>t.id===Y.id?{...t,columns:e}:t))}):Y.kind===`app`&&Y.app&&Y.app!==`notes`?(0,p.jsx)(Ee,{app:Y.app,contextId:e,workspaceId:C.workspaceName||C.workspaceId,treeName:d,path:B}):null})})}export{m as default};
|
|
1
|
+
import{o as e}from"./rolldown-runtime-C0FnF6B9.js";import{l as t,u as n}from"./code-editor-BOIngd5F.js";import{_ as r,g as i,h as a}from"./chunk-62JRHF6Z-vspAGgtK.js";import{t as o}from"./socket-CtH3EU9m.js";import{n as s}from"./use-toast-BlLDqSUO.js";import{o as c,s as l}from"./LinkToCard-VXpoeMDH.js";import{G as u,Sn as d,V as ee,bn as te,zt as ne}from"./workspace-46EFyEKZ.js";import{r as re}from"./document-list-BX13fcRu.js";import{n as ie}from"./use-toolbox-Ck_cLGgf.js";import{E as ae,_ as oe,a as se,b as ce,i as le,l as ue,o as de}from"./context-BGgz0Y_q.js";import{i as fe}from"./color-DFEH4BfK.js";import{t as pe}from"./geo-CZfs0E-x.js";import{a as me,i as he,o as ge}from"./workspace-BydSRtST.js";import{i as _e}from"./use-menu-CaiLyPdw.js";import{a as ve,c as ye,i as be,l as xe,n as Se,o as Ce,r as we,s as Te,t as Ee}from"./content-app-view-CH0wMWqu.js";import{t as De}from"./use-workspace-identity-KxY9injc.js";var f=e(n(),1),p=t();function Oe(e,t){if(!e||!t)return`/`;let n=`${t}://`;if(!e.startsWith(n))return`/`;let r=e.slice(n.length).replace(/^\/+/,``).replace(/\/+$/,``);return r?`/${r}`:`/`}function m(){let{contextId:e}=r(),t=a(),n=i(),m=new URLSearchParams(t.search).get(`ownerId`)||void 0,h=(0,f.useMemo)(()=>{let e=new URLSearchParams(t.search),n=e.getAll(`q`).map(e=>e.trim()).filter(Boolean),r=(e.get(`search`)||``).trim();return n.length?n:r?[r]:[]},[t.search]),{showToast:g,showProgress:ke}=s(),{state:_,saveFilters:Ae,setSort:je,setAccentColor:v,setMapDocuments:y}=ie(),{openM1Drawer:Me,openM2Drawer:Ne,goBack:Pe}=_e(),b=_.filters.features.allOf,Fe=_.filters.features.anyOf,Ie=_.filters.features.noneOf,Le=[...he(_.filters.timeline),...me(_.filters.geo),...ge(_.filters.lens,_.filters.geo.includeUnlocated)],x=JSON.stringify({a:b,b:Fe,c:Ie,d:Le,ids:_.filters.lens.ids,sort:_.filters.sort,geoSelection:_.geoSelection,includeUnlocated:_.filters.geo.includeUnlocated}),S=(0,f.useMemo)(()=>JSON.parse(x),[x]),[C,w]=(0,f.useState)(null),[Re,ze]=(0,f.useState)(!0),[Be,Ve]=(0,f.useState)(null),[T,E]=(0,f.useState)([]),[He,Ue]=(0,f.useState)(!1),[We,D]=(0,f.useState)(0),[Ge,Ke]=(0,f.useState)([]),[O,k]=(0,f.useState)(1),[A,qe]=(0,f.useState)(50),[j,M]=(0,f.useState)(h),[N,P]=(0,f.useState)(!1),[F,Je]=(0,f.useState)(null),[I,Ye]=(0,f.useState)(!1),L=(0,f.useRef)(!1),R=F?.id===C?.id&&F?.url===C?.url?F?.path:null,Xe=new URLSearchParams(t.search).get(`layer`),z=!!m,Ze=De(z?void 0:C?.workspaceName||C?.workspaceId),B=C?Oe(C.url,C.workspaceName):`/`,Qe=Xe?`context-layer`:`context`,V=!_.liveEnabled&&typeof C?.metadata?.toolboxSearchQuery==`string`?C.metadata.toolboxSearchQuery:``,H=z?null:C?.workspaceName??null,[$e,et]=(0,f.useState)(null);(0,f.useEffect)(()=>{if(!H)return;let e=!1;return u(H,d).then(t=>{e||et({key:H,tree:t})}).catch(()=>{e||et({key:H,tree:null})}),()=>{e=!0}},[H]);let U=H&&$e?.key===H?$e.tree:null,W=!Xe&&!z&&U?B===`/`?U:ee(U,B):null,G=`${C?.workspaceName??``}\0${B}`,[K,tt]=(0,f.useState)(null),q=K?.key===G?K.views:Ce(W?.metadata),J=K?.key===G?K.activeId:q[0]?.id??be.id,Y=q.find(e=>e.id===J)??q[0]??be,X=ve(Y);xe(ye({workspace:C?.workspaceName||C?.workspaceId||null,treeNameOrId:_.activeTreeName,path:B,contextId:e??null,scope:`context`},{..._.filters,features:{..._.filters.features,allOf:X?[...b,X]:b}},_.geoSelection,j));let nt=e=>{k(1),tt({key:G,views:q,activeId:e})},rt=(e,t)=>{t&&t!==J&&k(1),tt({key:G,views:e,activeId:t??J}),C?.workspaceName&&te(C.workspaceName,B,{metadata:{...W?.metadata??{},views:e}},d).catch(()=>{g({title:`View not saved`,description:`Could not persist views to the layer`,variant:`destructive`})})},Z=(0,f.useRef)(null);(0,f.useEffect)(()=>()=>Z.current?.abort(),[]);let Q=(0,f.useCallback)(async()=>{if(!e)return;Z.current?.abort();let t=new AbortController;Z.current=t,Ue(!0);try{let n=await de(e,X?[...S.a,X]:S.a,S.d,{...S.sort,geoSelection:S.geoSelection,includeUnlocated:S.includeUnlocated,ids:S.ids,signal:t.signal,limit:A,page:O,queries:j.length?j:void 0,anyOf:S.b,noneOf:S.c,applyContextSpec:!1},m);if(t.signal.aborted)return;E(n),D(n.totalCount||n.count||n.length)}catch(e){if(t.signal.aborted)return;g({title:`Error`,description:e instanceof Error?e.message:`Failed to fetch documents`,variant:`destructive`}),E([]),D(0)}finally{t.signal.aborted||Ue(!1)}},[e,O,A,m,j,S,g,X]),it=(0,f.useCallback)(async()=>{if(e){ze(!0);try{let t=z?await se(e,m):await se(e);if(!t)throw Error(`No context data received.`);let n=t.workspace,r=t.workspaceId||(typeof n==`string`?n:n?.id)||``,i=t.workspaceName||(typeof n==`string`?n:n?.name)||``;w({id:t.id,userId:t.userId,url:t.url,baseUrl:t.baseUrl||null,path:t.path||null,pathArray:t.pathArray||[],workspaceId:r,workspaceName:i,acl:t.acl||{},createdAt:t.createdAt,updatedAt:t.updatedAt,locked:t.locked||!1,serverContextArray:t.serverContextArray||[],clientContextArray:t.clientContextArray||[],contextBitmapArray:t.contextBitmapArray||[],featureBitmapArray:t.featureBitmapArray||[],filterArray:t.filterArray||[],pendingUrl:t.pendingUrl||null,description:t.description||null,metadata:t.metadata||{},name:t.name??null,color:t.color??null,icon:t.icon??null}),Ve(null)}catch(t){let n=t instanceof Error?t.message:`Failed to fetch context ${e}`;Ve(n),w(null),g({title:`Error`,description:n,variant:`destructive`})}ze(!1)}},[e,m,z,g]);(0,f.useEffect)(()=>{it()},[it]);let at=fe(C?.color)||null;(0,f.useEffect)(()=>(v(at),()=>v(null)),[at,v]);let ot=_.geoSelection,st=C?.workspaceName||C?.workspaceId||null;(0,f.useEffect)(()=>{y(T,st)},[T,st,y]),(0,f.useEffect)(()=>()=>y([]),[y]);let ct=(0,f.useMemo)(()=>ot?T.filter(e=>pe(e,ot,_.filters.geo.includeUnlocated)):T,[T,ot,_.filters.geo.includeUnlocated]),lt=C?.id,ut=C?.url;(0,f.useEffect)(()=>{lt&&Q()},[lt,ut,Q]),(0,f.useEffect)(()=>{let e=()=>Q();return window.addEventListener(`workspace:documents:refresh`,e),()=>window.removeEventListener(`workspace:documents:refresh`,e)},[Q]);let[dt,ft]=(0,f.useState)(x);dt!==x&&(ft(x),k(1));let[pt,mt]=(0,f.useState)(e);pt!==e&&(mt(e),k(1),P(!1));let[ht,gt]=(0,f.useState)(h);ht!==h&&(gt(h),M(h),k(1));let[_t,vt]=(0,f.useState)({urlSearchQueries:h,ignoreSavedSearch:N,savedContextSearchQuery:V});(_t.urlSearchQueries!==h||_t.ignoreSavedSearch!==N||_t.savedContextSearchQuery!==V)&&(vt({urlSearchQueries:h,ignoreSavedSearch:N,savedContextSearchQuery:V}),!new URLSearchParams(t.search).has(`q`)&&!h.length&&!N&&(M(V?[V]:[]),k(1)));let $=(0,f.useCallback)(e=>{let r=new URLSearchParams(t.search);r.delete(`q`),r.delete(`search`);for(let t of e)r.append(`q`,t);let i=r.toString();n(`${t.pathname}${i?`?${i}`:``}${t.hash}`)},[t.pathname,t.search,t.hash,n]),yt=(0,f.useCallback)(e=>{let t=e.trim();if(!t)return;P(!1);let n=j.includes(t)?j:[...j,t];M(n),$(n)},[j,$]),bt=(0,f.useCallback)(e=>{let t=e<0?[]:j.filter((t,n)=>n!==e);t.length===0&&P(!0),M(t),$(t)},[j,$]),xt=(j[0]||``).trim(),St=!!_.activeContextType&&(_.isDirty||xt!==(_.savedSearchQuery||V||``));(0,f.useEffect)(()=>{if(!e)return;let t=`context:${m?`${m}/`:``}${e}`,n=()=>o.emit(`subscribe`,{channel:t}),r=()=>o.emit(`unsubscribe`,{channel:t}),i=o.on(`connect`,n);n();let a=new Map,s=(t,n)=>{let r=Date.now(),i=`${t}:${n?.id||n?.contextId||e}`;return(a.get(i)||0)+1e3>r?!1:(a.set(i,r),!0)},c=t=>{let n=t,r=n?.context||n;(r?.id===e||r?.contextId===e)&&s(`ctx:updated`,r)&&(w(e=>e?{...e,...r}:null),r.url&&Q())},l=t=>{let n=t,r=n?.id||n?.contextId||n?.context?.id,i=n?.url||n?.context?.url;r===e&&typeof i==`string`&&s(`ctx:url`,n)&&(w(e=>e?{...e,url:i}:null),Q())},u=t=>{let n=t;(n?.contextId||n?.id||n?.context?.id)===e&&s(`doc:changed`,n)&&Q()},d=[[`context.updated`,c],[`context:updated`,c],[`context.url.set`,l],[`context:url:set`,l],[`document.inserted`,u],[`document.updated`,u],[`document.removed`,u],[`document.removed.batch`,u],[`document.linked`,u],[`document.unlinked`,u],[`document.linked.batch`,u],[`document.unlinked.batch`,u],[`document.deleted`,u],[`document.deleted.batch`,u]];return d.forEach(([e,t])=>o.on(e,t)),()=>{i(),r(),d.forEach(([e,t])=>o.off(e,t))}},[e,m,Q]);let Ct=async e=>{if(C)try{await ce(C.id,[e],m,B),E(t=>t.filter(t=>t.id!==e)),D(e=>Math.max(0,e-1)),g({title:`Success`,description:`Document removed from context.`})}catch(e){g({title:`Error`,description:e instanceof Error?e.message:`Failed to remove document`,variant:`destructive`})}},wt=async e=>{if(C)try{await le(C.id,[e],m,B),E(t=>t.filter(t=>t.id!==e)),D(e=>Math.max(0,e-1)),g({title:`Success`,description:`Document deleted.`})}catch(e){g({title:`Error`,description:e instanceof Error?e.message:`Failed to delete document`,variant:`destructive`})}},Tt=async e=>{if(C)try{await ce(C.id,e,m,B),E(t=>t.filter(t=>!e.includes(t.id))),D(t=>Math.max(0,t-e.length)),g({title:`Success`,description:`${e.length} document(s) removed.`})}catch(e){g({title:`Error`,description:e instanceof Error?e.message:`Failed to remove documents`,variant:`destructive`})}},Et=async e=>{if(C)try{await le(C.id,e,m,B),E(t=>t.filter(t=>!e.includes(t.id))),D(t=>Math.max(0,t-e.length)),g({title:`Success`,description:`${e.length} document(s) deleted.`})}catch(e){g({title:`Error`,description:e instanceof Error?e.message:`Failed to delete documents`,variant:`destructive`})}},Dt=e=>{Ke(e),g({title:`Copied`,description:`${e.length} document(s) copied to clipboard`})},Ot=async(e,t,n={})=>{if(!C)return!1;let r=ke({title:`Pasting…`,description:`${t.length} document(s) → "${e}"`});try{let i=n.targetTreeName&&!z?await ne(C.workspaceName||C.workspaceId,e,t,n.targetTreeName,n.targetTreeType):await oe(C.id,e,t,m);return r.done(i?{title:`Success`,description:`${t.length} document(s) pasted to "${e}"`}:void 0),i&&(Ke([]),await Q()),i}catch(e){return r.fail({title:`Error`,description:e instanceof Error?e.message:`Failed to paste documents`,variant:`destructive`}),!1}},kt=async(e,t)=>{if(!C)return!1;try{let n=await ue(C.workspaceId,t,e);return n&&(re(C.workspaceName||C.workspaceId,`context`,t),g({title:`Success`,description:`Imported ${e.length} document(s) to "${t}"`})),n}catch(e){return g({title:`Error`,description:e instanceof Error?e.message:`Failed to import documents`,variant:`destructive`}),!1}},At=async()=>{if(!C||!R||z||L.current)return;let e={id:C.id,url:C.url,path:R};L.current=!0,Ye(!0);try{let t=await ae(e.id,`${C.workspaceName}://${e.path.replace(/^\/+/,``)}`);w(n=>n?.id===e.id&&n.url===e.url?{...n,url:t.url,path:e.path}:n),Je(null),k(1),window.dispatchEvent(new CustomEvent(`contexts:refresh`,{detail:{contextId:e.id}})),g({title:`Saved`,description:`Context path updated`})}catch(e){g({title:`Error`,description:e instanceof Error?e.message:`Could not update context path`,variant:`destructive`})}finally{L.current=!1,Ye(!1)}};if(Re)return(0,p.jsx)(`div`,{className:`flex items-center justify-center h-full`,children:(0,p.jsxs)(`div`,{className:`text-center space-y-2`,children:[(0,p.jsx)(`div`,{className:`animate-spin rounded-full h-8 w-8 border-b-2 border-primary mx-auto`}),(0,p.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`Loading context...`})]})});if(Be&&!C)return(0,p.jsxs)(`div`,{className:`flex items-center justify-center h-full text-destructive`,children:[`Error: `,Be]});if(!C)return(0,p.jsx)(`div`,{className:`flex items-center justify-center h-full text-muted-foreground`,children:`Context not found.`});let jt=fe(C.color);return(0,p.jsx)(`div`,{className:`flex flex-col h-full min-h-0`,children:(0,p.jsx)(Te,{onBack:Pe,accentColor:jt,navigationTabs:W?(0,p.jsx)(we,{views:q,activeId:J,onSelect:nt,onSave:rt,accentColor:jt}):void 0,workspaceLabel:Ze?.label||C.workspaceName||C.workspaceId,workspaceIcon:Ze?.icon,treeName:d,urlType:Qe,urlDisplay:C.url,contextPath:B,workspaceId:C.workspaceName||C.workspaceId,documentSchema:X,linkTree:U,documents:ct,isLoading:He,totalCount:We,currentPage:O,pageSize:A,onPageChange:k,onPageSizeChange:e=>{qe(e),k(1)},onRemoveDocument:B===`/`?void 0:Ct,onDeleteDocument:wt,onRemoveDocuments:B===`/`?void 0:Tt,onDeleteDocuments:Et,onCopyDocuments:Dt,onPasteDocuments:Ot,onImportDocuments:z?void 0:kt,pastedDocumentIds:Ge,backendSearchQueries:j,onBackendSearch:yt,serverSort:_.filters.sort,onServerSortChange:je,onRemoveBackendQuery:bt,canSaveChanges:St,isSavingChanges:_.isSaving,onSaveChanges:Ae,onBrowseTree:!z&&e?()=>Ne(`contexts`,`detail`,e):void 0,onBrowseWorkspaces:()=>Me(`workspaces`),onNavigatePath:z?void 0:e=>{L.current||Je({id:C.id,url:C.url,path:e})},contentBanner:R?(0,p.jsxs)(`div`,{className:`border-b bg-warning/10 px-4 py-2`,role:`status`,children:[(0,p.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`Set this context to the selected path? Contents stay at the current path until you apply it.`}),(0,p.jsxs)(`div`,{className:`flex min-w-0 items-center gap-2`,children:[(0,p.jsx)(l,{items:c(R,C.workspaceName),label:`Selected context path`}),(0,p.jsx)(`button`,{type:`button`,disabled:I,onClick:()=>void At(),className:`shrink-0 rounded border px-3 py-1 text-sm hover:bg-accent disabled:opacity-50`,children:I?`Setting…`:`Set`}),(0,p.jsx)(`button`,{type:`button`,disabled:I,onClick:()=>Je(null),className:`shrink-0 rounded px-2 py-1 text-sm hover:bg-accent disabled:opacity-50`,children:`Cancel`})]})]}):void 0,children:Y.kind===`columns`?(0,p.jsx)(Se,{documents:ct,workspaceId:C.workspaceName||C.workspaceId,columns:Y.columns??[],onColumnsChange:e=>rt(q.map(t=>t.id===Y.id?{...t,columns:e}:t))}):Y.kind===`app`&&Y.app&&Y.app!==`notes`?(0,p.jsx)(Ee,{app:Y.app,contextId:e,workspaceId:C.workspaceName||C.workspaceId,treeName:d,path:B}):null})})}export{m as default};
|