@augmentd-labs/canvas-web 2.26.24 → 2.26.25
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/{FiltersApplet-CcYMBq-Q.js → FiltersApplet--yXjHZqs.js} +1 -1
- package/dist/assets/{HomeFab-D2pLJ9oc.js → HomeFab-3cymOU3P.js} +1 -1
- package/dist/assets/{LensApplet-DibGKbKC.js → LensApplet-5NHmz9TL.js} +1 -1
- package/dist/assets/{NotesApplet-DJp9Wuwt.js → NotesApplet-bIqcBzpg.js} +1 -1
- package/dist/assets/{_agentId_--jQP7aTv.js → _agentId_-BpZvdICK.js} +0 -0
- package/dist/assets/_contextId_-tiUa7oY9.js +1 -0
- package/dist/assets/_workspaceName_-BJ7uXLLN.js +1 -0
- package/dist/assets/{about-DVlaoa-W.js → about-Dn6r3v8E.js} +1 -1
- package/dist/assets/{add-Bq99uA2R.js → add-BTCF4qRT.js} +1 -1
- package/dist/assets/{agents-CRnO7j5E.js → agents-CO1AV00y.js} +1 -1
- package/dist/assets/{appearance-BAH_8zeF.js → appearance-BoZKRJ6u.js} +1 -1
- package/dist/assets/{apps-EwUooEtp.js → apps-B9-IBy2A.js} +1 -1
- package/dist/assets/content-app-view-acLgdhQ9.js +1 -0
- package/dist/assets/{home-Dc60CSIJ.js → home-BZ2OLB0t.js} +1 -1
- package/dist/assets/index-4M1qLU_S.js +16 -0
- package/dist/assets/{key-bindings-Bqkl5tDH.js → key-bindings-CwUENuYh.js} +1 -1
- package/dist/assets/{registry-DIfZf6LB.js → registry-Ct1xWTs8.js} +2 -2
- package/dist/assets/{settings-DqHAUBU4.js → settings-CDsVas7f.js} +1 -1
- package/dist/assets/{settings-BeN2UmZL.js → settings-CuK0olLh.js} +1 -1
- package/dist/assets/{settings-CzxxI2yw.js → settings-Df2eiuZ1.js} +1 -1
- package/dist/assets/{settings-Dl1FnW9g.js → settings-udxCpn5y.js} +1 -1
- package/dist/assets/{share-target-BWFFRO5O.js → share-target-DEadau7S.js} +1 -1
- package/dist/assets/{shared-B5Pvz8wr.js → shared-De1-Pxac.js} +1 -1
- package/dist/assets/{useAgentModels-CYDYTjgG.js → useAgentModels-CUwa_SHA.js} +1 -1
- package/dist/assets/{workspaces-B9gcHMCE.js → workspaces-DyWI__ok.js} +1 -1
- package/dist/index.html +2 -2
- package/dist/sw.js +1 -1
- package/package.json +2 -2
- package/dist/assets/_contextId_-D6nNA8hC.js +0 -1
- package/dist/assets/_workspaceName_-DfHnlgVg.js +0 -1
- package/dist/assets/content-app-view-BF-k-5Y7.js +0 -1
- package/dist/assets/index-D5Q9EUVc.js +0 -16
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{o as e}from"./rolldown-runtime-C0FnF6B9.js";import{l as t,u as n}from"./code-editor-BOIngd5F.js";import{_ as r,g as i,h as a}from"./chunk-62JRHF6Z-vspAGgtK.js";import{Br as o,Hr as s,L as c,fn as l}from"./ui-Byg1cZDr.js";import{t as u}from"./utils-2pl1SbIp.js";import{t as d}from"./button-SgR3GVvV.js";import{c as f,t as p}from"./api-CA6WiiYM.js";import{t as m}from"./socket-CtH3EU9m.js";import{n as h}from"./use-toast-BlLDqSUO.js";import{Bt as ee,Ht as g,Jt as _,K as te,Nt as ne,O as re,S as v,Sn as ie,T as ae,Yt as y,Z as oe,at as se,b as ce,bt as le,d as ue,dt as de,gt as fe,hn as b,it as pe,o as me,q as he,sn as x,v as ge,vt as _e}from"./workspace-CrSpR4xf.js";import{n as ve,r as ye}from"./use-canvas-pins-CbAxLLTU.js";import{u as be}from"./ObjectPropertiesCard-BIBMvx_i.js";import{h as xe,i as S,r as Se}from"./document-list-Dsf1DVEx.js";import{n as Ce}from"./use-toolbox-Ck_cLGgf.js";import{i as we}from"./color-DFEH4BfK.js";import{t as Te}from"./geo-CZfs0E-x.js";import{c as Ee}from"./backend-sync-progress-pZrhQPk3.js";import{a as De,i as Oe,n as ke,o as Ae}from"./workspace-BydSRtST.js";import{n as je,r as Me,t as Ne}from"./url-params-n7kU_WZ-.js";import{i as Pe}from"./use-menu-BiJ8N7sS.js";import{n as Fe}from"./last-path-BbXWC3b3.js";import{t as Ie}from"./workspace-area-menu-CP5OWZNX.js";import{t as Le}from"./workspace-content-gate-9okuA7J7.js";import{t as Re}from"./form-panel-C34lByEH.js";import{a as ze,i as Be,n as Ve,o as He,r as Ue,s as We,t as Ge}from"./content-app-view-BF-k-5Y7.js";import{i as Ke,o as qe,r as Je}from"./query-debug-CrPsUwT-.js";var C=`session.open`,Ye=`session.set`,Xe=`session.ids`,Ze=`session.materialize`,Qe=`session.close`,w=`session.delta`,T=e(n(),1),E=t();function $e({workspaceId:e,workspaceName:t}){let[n,r]=(0,T.useState)([]),[i,a]=(0,T.useState)(new Set),o=t=>`${e}:${t.address}:${t.resyncStartedAt||``}`;(0,T.useEffect)(()=>{let t=!1,n=!1,i=!1,a=0,o=new Map,s=new Map,c=(e,t)=>{let n=e.filter(e=>e.address!==t.backend);if(!t.resyncing)return n;let r=e.find(e=>e.address===t.backend)||s.get(t.backend);return[...n,{address:t.backend,config:r?.config,resyncStartedAt:r?.resyncStartedAt||new Date().toISOString(),progress:t.progress??r?.progress}]},l=async()=>{if(n){i=!0;return}n=!0;let u=a;try{let n=await le(e);if(!t){s=new Map(n.map(e=>[e.address,e]));let e=n.filter(e=>e.resyncing);for(let t of o.values())t.version>u&&(e=c(e,t.event));r(e)}}catch{}finally{n=!1,i&&!t&&(i=!1,l())}},u=t=>{t.workspaceId!==e||!t.backend||typeof t.resyncing!=`boolean`||(o.set(t.backend,{version:++a,event:t}),r(e=>c(e,t)))},d=t=>{t.workspaceId===e&&l()};l();let f=m.on(`connect`,l);return m.on(`backend.resync.changed`,u),m.on(`backend.changed`,d),window.addEventListener(`focus`,l),()=>{t=!0,f?.(),m.off(`backend.resync.changed`,u),m.off(`backend.changed`,d),window.removeEventListener(`focus`,l)}},[e]);let s=n.filter(e=>!i.has(o(e)));return s.length?(0,E.jsxs)(`aside`,{"aria-label":`Storage scans for ${t}`,className:`absolute bottom-5 right-5 z-50 w-72 max-w-[calc(100vw-2.5rem)] rounded-lg border bg-popover/95 p-3 text-popover-foreground shadow-lg backdrop-blur`,children:[(0,E.jsxs)(`div`,{role:`status`,className:`mb-2 flex items-center gap-2 text-sm font-medium`,children:[(0,E.jsx)(l,{"aria-hidden":`true`,className:`h-4 w-4 animate-spin`}),(0,E.jsxs)(`span`,{className:`min-w-0 flex-1`,children:[(0,E.jsx)(`span`,{className:`block`,children:`Scanning storage`}),(0,E.jsx)(`span`,{className:`block truncate text-xs font-normal text-muted-foreground`,title:t,children:t})]}),(0,E.jsx)(`button`,{type:`button`,"aria-label":`Hide scan progress for ${t}`,title:`Hide progress; scanning continues`,className:`rounded p-1 hover:bg-muted focus-visible:outline focus-visible:outline-2`,onClick:()=>a(e=>new Set([...e,...s.map(o)])),children:(0,E.jsx)(c,{"aria-hidden":`true`,className:`h-4 w-4`})})]}),(0,E.jsx)(`div`,{className:`max-h-48 space-y-3 overflow-y-auto`,children:s.map(e=>{let{scanned:t=0,total:n=null}=e.progress||{},r=n&&n>0?Math.min(100,Math.round(t/n*100)):null,i=typeof e.config?.label==`string`?e.config.label:e.address;return(0,E.jsxs)(`div`,{children:[(0,E.jsxs)(`div`,{className:`flex items-center justify-between gap-3 text-xs`,children:[(0,E.jsx)(`span`,{className:`truncate`,children:i}),(0,E.jsx)(`span`,{className:`shrink-0 text-muted-foreground`,children:n===null?`${t} files`:`${t} / ${n}`})]}),(0,E.jsx)(`div`,{role:`progressbar`,"aria-label":`Scanning ${i}`,"aria-valuemin":0,"aria-valuemax":100,"aria-valuenow":r??void 0,className:`mt-1.5 h-1 overflow-hidden rounded-full bg-muted`,children:(0,E.jsx)(`div`,{className:`h-full rounded-full bg-primary ${r===null?`animate-pulse`:`transition-all`}`,style:{width:r===null?`35%`:`${r}%`}})})]},e.address)})})]}):null}var et=e=>e&&typeof e==`object`&&!Array.isArray(e)?e:null;function tt(e){return`/${e}`.replace(/\/+/g,`/`).replace(/\/$/,``)||`/`}function nt(e,t,n){if(e==null)return[];if(Array.isArray(e))return e.flatMap(e=>nt(e,t,n));if(typeof e==`string`)return[{tree:null,kind:t,path:tt(e)}];let r=et(e);if(!r)return[];let i=r.tree??r.treeId,a=typeof i==`string`?n.get(i)??null:null;return[].concat(r.paths??r.path??`/`).filter(e=>typeof e==`string`).map(e=>({tree:a,kind:t,path:tt(e)}))}function D(e){let t=[],n=e=>{let n=Number(e);Number.isSafeInteger(n)&&n>0&&t.push(n)};return Array.isArray(e.ids)&&e.ids.forEach(n),Array.isArray(e.documentIds)&&e.documentIds.forEach(n),e.id!=null&&n(e.id),e.documentId!=null&&n(e.documentId),t}function rt(e){let t=new Map;for(let n of e)t.set(n.id,n.name),t.set(n.name,n.name);return t}function it(e,t,n=new Map){let r=et(t);if(!r)return{targets:[],ids:[],unknown:!0};if(e.startsWith(`tree.`)){let e=typeof r.treeName==`string`?r.treeName:null,t=r.treeType===`directory`||r.treeType===`context`?r.treeType:null,n=r.contextSpec??r.path;return typeof n==`string`?{targets:[{tree:e,kind:t,path:tt(n)}],ids:D(r),unknown:!1}:{targets:[],ids:[],unknown:!0}}let i=[...nt(r.context,`context`,n),...nt(r.directory,`directory`,n)],a=et(r.changed);a&&i.push(...nt(a.context,`context`,n),...nt(a.directory,`directory`,n));let o=D(r);if(i.length)return{targets:i,ids:o,unknown:!1};let s=r.reason===`content`||r.reason===`relations`;return e.startsWith(`document.updated`)&&s&&o.length?{targets:[],ids:o,unknown:!1}:{targets:[],ids:o,unknown:!0}}function O(e,t){return e===t||e===`/`||t===`/`||e.startsWith(`${t}/`)||t.startsWith(`${e}/`)}function at(e,t){if(e.kind&&e.kind!==t.kind||e.tree&&e.tree!==t.tree)return!1;if(t.kind===`context`){let n=e=>tt(e).split(`/`).filter(Boolean).map(e=>e.normalize(`NFKC`).trim().replace(/\s+/g,` `).replace(/[^\p{L}\p{N}\p{M} .+_@-]/gu,`_`).replace(/_+/g,`_`).toLowerCase()||`_`),r=new Set(n(e.path)),i=n(t.path);return r.size===0||i.length===0||i.some(e=>r.has(e))}return O(e.path,t.path)}function ot(e){return it(`tree.refresh`,{treeName:e?.treeName,path:e?.path||`/`})}function st(e,t,n){if(e.unknown||e.targets.length&&(t.wholeWorkspace||e.targets.some(e=>at(e,t))))return!0;if(e.ids.length&&n){let t=n instanceof Set?n:new Set(n);if(e.ids.some(e=>t.has(e)))return!0}return!1}function ct(e,t,n={}){return m.request(C,{workspace:e,specs:t,opts:n})}function lt(e,t,n){return m.request(Ye,{sessionId:e,label:t,spec:n})}function ut(e){return m.request(Xe,{sessionId:e})}function k(e,t={}){return m.request(Ze,{sessionId:e,...t})}function dt(e){return m.request(Qe,{sessionId:e})}function ft(e){return m.on(w,e)}var pt=100;function mt({workspaceRef:e,specs:t,opts:n,enabled:r=!0}){let[i,a]=(0,T.useState)([]),[o,s]=(0,T.useState)(0),[c,l]=(0,T.useState)(null),[u,d]=(0,T.useState)(null),f=(0,T.useRef)([]),p=(0,T.useRef)(new Map),h=(0,T.useRef)(null),ee=(0,T.useRef)(null),g=(0,T.useRef)(null),_=(0,T.useRef)({}),te=(0,T.useRef)(null),ne=(0,T.useMemo)(()=>JSON.stringify(t),[t]),re=(0,T.useMemo)(()=>JSON.stringify(n??{}),[n]),v=(0,T.useCallback)(()=>{let e=p.current;a(f.current.map(t=>e.get(t)).filter(Boolean))},[]),ie=(0,T.useCallback)(async e=>{let t=ee.current;if(!t||e.length===0)return[];let n=[];for(let r=0;r<e.length;r+=pt){let i=e.slice(r,r+pt),a=await pe(t,`/`,[],{ids:i,scope:`workspace`,limit:i.length});n.push(...a.payload||[])}return n},[]),ae=(0,T.useCallback)(async(e,t,n)=>{if(t.length>0){let e=new Set(t);f.current=f.current.filter(t=>!e.has(t));for(let t of e)p.current.delete(t)}let r=e.filter(e=>!p.current.has(e)),i=new Set(f.current);for(let t of e)i.has(t)||(f.current.push(t),i.add(t));if(n!==null&&s(n),v(),r.length===0)return;let a=await ie(r);for(let e of a)p.current.set(e.id,e);let o=new Set(a.map(e=>e.id)),c=r.filter(e=>!o.has(e));if(c.length>0){let e=new Set(c);f.current=f.current.filter(t=>!e.has(t))}v()},[ie,v]),y=(0,T.useCallback)(async(e,t)=>{let n=e??[],r=new Set(n);f.current=f.current.filter(e=>r.has(e));for(let e of p.current.keys())r.has(e)||p.current.delete(e);let i=new Set(f.current),a=n.filter(e=>!i.has(e));await ae(a,[],t)},[ae]);(0,T.useEffect)(()=>{if(ee.current=e??null,!r||!e)return;let t=!1,n=null,i=async()=>{try{let r=await ct(e,JSON.parse(ne),JSON.parse(re));if(t){dt(r.sessionId).catch(()=>{});return}n=r.sessionId,h.current=r.sessionId,l(r.sessionId),d(null),f.current=[],p.current=new Map,await y(r.ids,r.count)}catch(e){if(t)return;d(e instanceof Error?e.message:`Failed to open query session`),l(null),h.current=null}};i();let o=m.on(`connect`,()=>{i()});return()=>{t=!0,o?.();let e=n??h.current;e&&dt(e).catch(()=>{}),h.current=null,f.current=[],p.current=new Map,l(null),a([]),s(0)}},[e,ne,re,r]),(0,T.useEffect)(()=>{if(!c)return;let e=ft(e=>{if(e.sessionId===c){if(g.current!==null){te.current?.(g.current,_.current);return}e.ids===void 0?ae(e.added??[],e.removed??[],e.count):y(e.ids,e.count)}});return()=>{e?.()}},[c,ae,y]);let oe=(0,T.useCallback)(async()=>{let e=h.current;if(e)try{let t=await ut(e);await y(t.ids,t.count)}catch{}},[y]),se=(0,T.useCallback)(async(e,t)=>{let n=h.current;if(!n)throw Error(`No open query session`);let r=await lt(n,e,t);if(g.current!==null){await te.current?.(g.current,_.current);return}await y(r.ids,r.count)},[y]),ce=(0,T.useCallback)(async(e,t={})=>{let n=h.current;if(!n)throw Error(`No open query session`);if(g.current=e,_.current=t,e===null){await oe();return}let r=await k(n,{match:e,...t});for(let e of r.documents)p.current.set(e.id,e);f.current=r.ids,s(r.totalCount),v()},[v,oe]);(0,T.useEffect)(()=>{te.current=ce},[ce]);let le=(0,T.useCallback)(async(e,t,n={})=>{let r=h.current;if(!r)throw Error(`No open query session`);let i=await k(r,{match:t,limit:n.limit??100,...n.mode?{mode:n.mode}:{}});for(let e of i.documents)p.current.set(e.id,e);let a=await lt(r,e,{ids:i.ids});return await y(a.ids,a.count),i.ids},[y]);return{documents:i,count:o,ready:c!==null,error:u,setCue:se,resync:oe,rank:ce,rankAndPin:le}}function ht({data:e,className:t}){let[n,r]=(0,T.useState)(!0),{rows:i,gapIndex:a,span:c}=(0,T.useMemo)(()=>{let t=[...e.distances].sort((e,t)=>e.distance-t.distance),n=[];for(let e=1;e<t.length;e++)n.push(t[e].distance-t[e-1].distance);let r=n.length?[...n].sort((e,t)=>e-t)[Math.floor(n.length/2)]:0,i=-1,a=0;for(let e=0;e<n.length;e++)n[e]>a&&(a=n[e],i=e+1);let o=i>0&&a>=Math.max(r*4,1e-6),s=t[0]?.distance??0,c=t[t.length-1]?.distance??0;return{rows:t,gapIndex:o?i:-1,span:{first:s,last:c,biggest:a,median:r}}},[e.distances]);if(i.length===0)return(0,E.jsxs)(`div`,{className:u(`rounded-md border border-dashed border-border px-3 py-2 text-xs text-muted-foreground`,t),children:[`Query debug: no image distances for “`,e.query,`”. The dense side returned nothing: either no photos are embedded in this scope, or the image space is not ready.`]});let l=a>0?i[a].distance:null;return(0,E.jsxs)(`div`,{className:u(`rounded-md border border-border bg-muted/30 text-xs`,t),children:[(0,E.jsxs)(`button`,{type:`button`,onClick:()=>r(e=>!e),className:`flex w-full items-center gap-1.5 px-3 py-2 text-left font-medium`,children:[n?(0,E.jsx)(s,{className:`h-3.5 w-3.5`}):(0,E.jsx)(o,{className:`h-3.5 w-3.5`}),`Query debug`,(0,E.jsxs)(`span`,{className:`font-normal text-muted-foreground`,children:[`: image distances for “`,e.query,`” (`,i.length,` nearest, unfloored)`]})]}),n&&(0,E.jsxs)(`div`,{className:`space-y-2 border-t border-border px-3 py-2`,children:[(0,E.jsxs)(`p`,{className:`text-[11px] text-muted-foreground`,children:[`Best-first cosine distance (0 = identical). Scroll to where the photos stop being relevant and set the image relevance floor just above that value in Settings → Database → Search tuning.`,l===null?(0,E.jsxs)(E.Fragment,{children:[` `,(0,E.jsx)(`span`,{className:`text-amber-600 dark:text-amber-500`,children:`No boundary in this window`}),`; the distances step evenly (typical Δ`,c.median.toFixed(4),`), so there is nothing here to set a floor from. Relevance probably ends further down the list than this window reaches, or the model is not separating this query at all.`]}):(0,E.jsxs)(E.Fragment,{children:[` A jump at `,(0,E.jsx)(`span`,{className:`font-mono`,children:l.toFixed(4)}),` (Δ`,c.biggest.toFixed(4),`, vs typical Δ`,c.median.toFixed(4),`) stands out (a likely boundary).`]})]}),(0,E.jsx)(`div`,{className:`max-h-56 overflow-y-auto`,children:(0,E.jsx)(`table`,{className:`w-full font-mono text-[11px]`,children:(0,E.jsx)(`tbody`,{children:i.map((e,t)=>(0,E.jsxs)(`tr`,{className:u(`border-b border-border/40 last:border-0`,t===a&&`border-t-2 border-t-amber-500/70`),children:[(0,E.jsx)(`td`,{className:`py-0.5 pr-3 text-muted-foreground`,children:t+1}),(0,E.jsxs)(`td`,{className:`py-0.5 pr-3`,children:[`#`,e.id]}),(0,E.jsx)(`td`,{className:`py-0.5 tabular-nums`,children:e.distance.toFixed(4)}),t===a&&(0,E.jsx)(`td`,{className:`py-0.5 pl-2 font-sans text-[10px] text-amber-600 dark:text-amber-500`,children:`← biggest gap`})]},e.id))})})}),(0,E.jsxs)(`p`,{className:`text-[11px] text-muted-foreground`,children:[`Range `,c.first.toFixed(4),` – `,c.last.toFixed(4),` (spread `,(c.last-c.first).toFixed(4),`) over `,i.length,` rows. Absolute values shift with the model and are not comparable across models. After a re-embed every floor has to be picked again. A spread this narrow relative to the range means ranking is doing the work, not distance.`]})]})]})}function gt(e,t){if(!e)return[];let n=t.split(`/`).filter(Boolean),r=e;for(let e of n)if(r=r?.children?.find(t=>t.name===e)??null,!r)return[];let i=n.length?`/${n.join(`/`)}`:``,a=(r.children??[]).filter(e=>e.type!==`canvas`).map(e=>({name:e.name,path:`${i}/${e.name}`,label:e.label,color:e.color,childCount:e.children?.length??0})).sort((e,t)=>(e.label||e.name).localeCompare(t.label||t.name,void 0,{numeric:!0,sensitivity:`base`}));return n.length>0&&a.unshift({name:`..`,path:n.length>1?`/${n.slice(0,-1).join(`/`)}`:`/`,isParent:!0}),a}var A=new Map;function _t(e,t,n){return`${e}\0${t}\0${n}`}function vt(e,t,n,r,i,a,o=``,s=``,c=`path`){return`${_t(e,t,n)}\0${r}\0${i}\0${a}\0${o}\0${s}\0${c}`}function j(e,t,n){let r=_t(e,t,n);for(let e of A.keys())e.startsWith(r)&&A.delete(e)}function yt(e,t){let n=`${e}\0`;for(let[e,r]of A){if(!e.startsWith(n))continue;let[,i,a,,,,,,o=`path`]=e.split(`\0`);st(t,{tree:i,kind:b(i),path:a,wholeWorkspace:o.startsWith(`workspace`)},r.documents.map(e=>Number(e.id)))&&A.delete(e)}}function bt(e,t){yt(t?.workspaceName??e,ot(t))}function xt(){let{workspaceName:e}=r();return e?(0,E.jsx)(Le,{workspaceName:e,children:(0,E.jsx)(M,{})}):null}function M(){let{workspaceName:e,treeName:t}=r(),n=a(),o=i(),{showToast:s,showProgress:c}=h(),l=new URLSearchParams(n.search),Le=(()=>{let e=l.getAll(`q`).map(e=>e.trim()).filter(Boolean);if(e.length>0)return e;let t=(l.get(`search`)||``).trim();return t?[t]:[]})(),[C,Ye]=(0,T.useState)(null),[Xe,Ze]=(0,T.useState)(!0),[Qe,w]=(0,T.useState)([]),[et,tt]=(0,T.useState)(!1),[nt,D]=(0,T.useState)(0),O=Je(),[at,ct]=(0,T.useState)(null),[lt,ut]=(0,T.useState)(O);lt!==O&&(ut(O),O||ct(null));let[k,dt]=(0,T.useState)(`path`),[ft,pt]=(0,T.useState)(!1),[_t,xt]=(0,T.useState)(null),[M,St]=(0,T.useState)(null),[wt,Tt]=(0,T.useState)(``),[Et,Dt]=(0,T.useState)(!1),[Ot,kt]=(0,T.useState)(!1),[At,jt]=(0,T.useState)(!1),[N,Mt]=(0,T.useState)(null),[P,F]=(0,T.useState)(1),[I,Nt]=(0,T.useState)(50),[L,Pt]=(0,T.useState)(Le),[Ft,It]=(0,T.useState)(null),{state:R,saveFilters:Lt,setSort:Rt,setAccentColor:zt,setMapDocuments:Bt}=Ce(),Vt=R.filters.features.allOf,z=R.filters.features.anyOf,Ht=R.filters.features.noneOf,Ut=Oe(R.filters.timeline),Wt=De(R.filters.geo),Gt=Ae(R.filters.lens,R.filters.geo.includeUnlocated),B=R.filters.lens.ids,Kt=[...Ut,...Wt,...Gt],qt=R.filters.sort??ke,Jt=JSON.stringify({a:Vt,b:z,c:Ht,d:Kt,i:B,s:qt}),Yt=JSON.stringify({a:Vt,b:z,c:Ht,d:Kt,s:qt}),V=je(n.pathname).path,H=t??`context`,U=H===`backends`,[Xt,Zt]=(0,T.useState)([]);(0,T.useEffect)(()=>{!U||!e||le(e).then(Zt).catch(()=>Zt([]))},[U,e]);let Qt=U?me(V,Xt):null,[$t,en]=(0,T.useState)(!1),tn=`${H}\0${V}`,[nn,rn]=(0,T.useState)(tn);nn!==tn&&(rn(tn),en(!1));let W=l.get(`layer`)===`1`,G=l.get(`layerId`)||null,[K,an]=(0,T.useState)(null),[q,on]=(0,T.useState)(null),sn=(0,T.useRef)(null);(0,T.useEffect)(()=>{sn.current=q},[q]);let[cn,ln]=(0,T.useState)(`left`),[un,dn]=(0,T.useState)([]),{openM1Drawer:fn,openM2Drawer:pn,goBack:mn}=Pe(),[hn,gn]=(0,T.useState)([]),J=(0,T.useMemo)(()=>{if(!K||V===`/`||W)return null;let e=V.split(`/`).filter(Boolean),t=K;for(let n of e)if(t=t?.children?.find(e=>e.name===n)??null,!t)return null;return t},[K,V,W]),Y=J?.type===`canvas`?`canvas`:null,_n=(0,T.useRef)(null);(0,T.useEffect)(()=>{!e||!K||W||_n.current===`${e}/${H}`&&(V!==`/`&&!J||Fe(e,H,V))},[e,K,W,V,J,H]);let vn=(0,T.useMemo)(()=>W||k===`workspace`||L.length>0||b(H)!==`directory`?[]:gt(K,V),[K,V,H,W,k,L]),yn=W?null:V===`/`?K:J,X=xe(),bn=`${H}\0${V}`,[xn,Sn]=(0,T.useState)(null),Cn=xn?.key===bn?xn.views:He(yn?.metadata),wn=X?.pinned&&X.view?[X.view,...Cn.filter(e=>e.id!==X.view.id)]:Cn,Tn=X?.pinned&&X.view?X.view.id:xn?.key===bn?xn.activeId:wn[0]?.id??Be.id,Z=wn.find(e=>e.id===Tn)??wn[0]??Be;(0,T.useEffect)(()=>{X?.selectView(Z)},[Z,X]);let En=U?void 0:X?.schema??ze(Z),Dn=En?[...Vt,En]:Vt,On=e=>{let t=wn.find(t=>t.id===e);t&&X?.selectView(t),F(1),dn([]),Sn({key:bn,views:wn,activeId:e})},kn=(t,n)=>{n&&n!==Tn&&(F(1),dn([]));let r=t.find(e=>e.id===(n??Tn));r&&X?.selectView(r),Sn({key:bn,views:t,activeId:n??Tn}),ie(e,V,{metadata:{...yn?.metadata??{},views:t}},H).catch(()=>{s({title:`View not saved`,description:`Could not persist views to the layer`,variant:`destructive`})})},An=Y===`canvas`&&typeof J?.querySpec?.query==`string`?J.querySpec.query:``,jn=Y===`canvas`?{label:J?.label,description:J?.description,color:J?.color}:null,{isPinned:Mn,pin:Nn,unpin:Pn,pins:Fn}=ve(),In=C?.name,Q=(0,T.useMemo)(()=>In&&Y===`canvas`&&!W?{workspaceName:In,treeName:H,path:V}:null,[In,Y,W,H,V]),Ln=Q?Mn(Q):!1,Rn=J?.id,zn=J?.label,Bn=(0,T.useCallback)(async()=>{if(Q)try{let e=Fn.find(e=>e.workspaceName===Q.workspaceName&&e.treeName===Q.treeName&&e.path===Q.path);e?await Pn(e.id):await Nn({...Q,layerId:Rn,label:zn})}catch(e){console.error(`Failed to update home pins:`,e)}},[Q,Fn,Nn,Pn,Rn,zn]),Vn=e?`${e}://${V===`/`?``:V.replace(/^\//,``)}`:``,Hn=we(C?.color)||null;(0,T.useEffect)(()=>(zt(Hn),()=>zt(null)),[Hn,zt]);let Un=(0,T.useCallback)(async t=>{let n=B;if(t?.anyOf?.length&&z.length&&(n=((await he(e,V,H,{limit:0,anyOf:z,ids:B,applyCanvasSpec:!1})).payload||[]).map(e=>e.id),!n.length))return{payload:[],count:0,totalCount:0};let r=await he(e,V,H,{limit:t?.limit,offset:t?.offset,page:t?.page,sortBy:t?.sortBy,order:t?.order,allOf:[...Vt,...t?.allOf??[]],anyOf:t?.anyOf?.length?t.anyOf:z,noneOf:Ht,filters:Kt,ids:n,queries:[...L,...t?.queries??[],...t?.q?[t.q]:[]],applyCanvasSpec:!1});return{payload:r.payload||[],count:r.count??void 0,totalCount:r.totalCount??void 0}},[e,V,H,Jt,L]);(0,T.useEffect)(()=>{e&&(async()=>{Ze(!0);try{let t=await p.get(`${f.workspaces}/${e}`),n;n=t&&`workspace`in t?t.workspace:t,Ye(n)}catch(t){let n=t instanceof Error?t.message:`Failed to fetch workspace ${e}`;s({title:`Error`,description:n,variant:`destructive`}),Ye(null)}finally{Ze(!1)}})()},[e,s]),(0,T.useEffect)(()=>{let e=e=>{let t=e.detail?.workspace;t&&Ye(e=>e&&(t===e.name||t===e.id)&&e.status!==`active`?{...e,status:`active`}:e)};return window.addEventListener(`workspace:autostarted`,e),()=>window.removeEventListener(`workspace:autostarted`,e)},[]);let Wn=(B?.length??0)>0&&!W&&!($t&&Qt)&&L.length<=1,{documents:Gn,count:Kn,ready:qn,setCue:Jn,resync:Yn,rank:Xn}=mt({workspaceRef:e,specs:(0,T.useMemo)(()=>{let e={features:{allOf:Dn,anyOf:z,noneOf:Ht},filters:Kt};return k!==`workspace`&&(b(H)===`directory`?e.directory={tree:H,path:V}:e.context=V),[{label:`scope`,spec:e}]},[Yt,V,H,k,En]),opts:(0,T.useMemo)(()=>({mode:`live`,debounceMs:150}),[]),enabled:Wn}),Zn=Wn&&qn,Qn=(0,T.useRef)(!1);(0,T.useEffect)(()=>{Qn.current=Zn},[Zn]);let $n=L.length===1?L[0].trim():``;(0,T.useEffect)(()=>{qn&&Xn($n?{text:$n}:null,{limit:I,offset:(P-1)*I}).catch(()=>{})},[qn,$n,I,P,Xn]);let er=(B??[]).join(`,`);(0,T.useEffect)(()=>{qn&&Jn(`lens`,{ids:B??[]}).catch(()=>{})},[qn,er,Jn,B]);let tr=Zn?Gn:Qe,nr=Zn?Kn:nt,rr=(0,T.useRef)(new Set);(0,T.useEffect)(()=>{rr.current=new Set(tr.map(e=>Number(e.id)))},[tr]);let ir=R.geoSelection;(0,T.useEffect)(()=>{Bt(tr,C?.name??null)},[tr,C?.name,Bt]),(0,T.useEffect)(()=>()=>Bt([]),[Bt]);let ar=(0,T.useMemo)(()=>ir?tr.filter(e=>Te(e,ir,R.filters.geo.includeUnlocated)):tr,[tr,ir,R.filters.geo.includeUnlocated]),or=ue(V,Dn,{treeName:H,treeType:b(H),scope:k,queries:L,anyOf:z,noneOf:Ht,filters:Kt,ids:B,layerId:W&&G?G:void 0}),sr=JSON.stringify([e,or]),[cr,lr]=(0,T.useState)(``),[ur,dr]=(0,T.useState)(!1),fr=(0,T.useRef)(!1),pr=et||ur||cr!==sr||Zn||!!ir,mr=(0,T.useRef)(0),hr=(0,T.useRef)(null);(0,T.useEffect)(()=>()=>{mr.current++,hr.current=null},[]);let gr=(0,T.useRef)(``),$=(0,T.useCallback)(async t=>{if(!e)return;if(Ee(H,V)){mr.current++,hr.current=null,gr.current=``,w([]),D(0),tt(!1);return}if(Qn.current)return;let n=`${$t&&Qt?`${k}:unfiled`:k}:${En??``}`,r=(B?.length??0)>0,i=vt(e,H,V,P,I,L.join(`␟`),Yt,W&&G?G:``,n),a=r&&i===gr.current;gr.current=i;let o=vt(e,H,V,P,I,L.join(`␟`),Jt,W&&G?G:``,n),c=`${o}\0${O}`;if(t?.silent&&hr.current?.key===c){hr.current.refreshPending=!0;return}let l=++mr.current,u=t?.silent||r||O?void 0:A.get(o);u&&(w(u.documents),D(u.totalCount),lr(sr),tt(!1)),(t?.silent??(a||!!u))||tt(!0);let d={key:c,refreshPending:!1};hr.current=d;try{let t;t=$t&&Qt?await _e(e,Qt.driver,Qt.address,{linked:!1,limit:I,offset:(P-1)*I}):W&&G&&k!==`workspace`?await se(e,H,G,{limit:I,page:P,queries:L,allOf:Dn,anyOf:z,noneOf:Ht,filters:Kt,ids:B,sortBy:qt.sortBy||void 0,order:qt.order}):await pe(e,V,Dn,{limit:I,page:P,treeName:H,treeType:H===`directory`||H===`backends`?`directory`:`context`,queries:L,anyOf:z,noneOf:Ht,filters:Kt,ids:B,sortBy:qt.sortBy||void 0,order:qt.order,scope:k,debug:O&&L.length>0,debugLimit:200});let n=t.payload||[],i=t.totalCount||t.count||0;if(!r&&!d.refreshPending&&A.set(o,{documents:n,totalCount:i}),l!==mr.current)return;let s=t.debug,c=s?.imageDistances??s?.distances??null;ct(c?{query:L[L.length-1]??``,distances:c}:null),w(a?e=>e.length===n.length&&e.every((e,t)=>e.id===n[t].id)?e:n:n),D(i),lr(sr)}catch(e){if(l!==mr.current)return;let t=e instanceof Error?e.message:`Failed to fetch documents`;s({title:`Error`,description:t,variant:`destructive`}),w([]),D(0)}finally{hr.current===d&&(hr.current=null),l===mr.current&&tt(!1),l===mr.current&&d.refreshPending&&$({silent:!0})}},[e,V,H,G,W,P,I,C?.status,L,Jt,k,$t,O,En]);(0,T.useEffect)(()=>{$()},[$]),(0,T.useEffect)(()=>{let t=t=>{let n=t.detail;!n||n.workspaceName!==e||(on({treeName:n.treeName||`context`,path:Me(n.path||`/`)}),ln(`left`))};return window.addEventListener(`workspace:open-to-side`,t),()=>window.removeEventListener(`workspace:open-to-side`,t)},[e,H,V]),(0,T.useEffect)(()=>{let t=t=>{let n=t.detail;if(!(n?.workspaceName&&n.workspaceName!==e)&&(e&&bt(e,n),st(ot(n),{tree:H,kind:b(H),path:V,wholeWorkspace:k===`workspace`}))){if(e&&j(e,H,V),Qn.current){Yn();return}$({silent:!0})}};return window.addEventListener(`workspace:documents:refresh`,t),()=>window.removeEventListener(`workspace:documents:refresh`,t)},[$,e,V,H,k,Yn]);let _r=C?.name,vr=C?.id;(0,T.useEffect)(()=>{if(!e||!_r&&!vr)return;let t=[_r,vr].filter(Boolean).map(e=>`workspace:${e}`),n=()=>t.forEach(e=>m.emit(`subscribe`,{channel:e}));n();let r=m.on(`connect`,n),i=new Map,a=!1,o=()=>{ne(e).then(e=>{a||(i=rt(e))}).catch(()=>{})};o();let s=null,c=0,l=!1,u=null,d=()=>{if(s=null,c=Date.now(),u){let{treeName:t,path:n}=u;u=null,window.dispatchEvent(new CustomEvent(`workspace:documents:refresh`,{detail:{workspaceName:e,treeName:t,path:n}}))}if(l){if(l=!1,Qn.current){Yn();return}$({silent:!0})}},f=t=>n=>{(t.startsWith(`tree.created`)||t.startsWith(`tree.renamed`))&&o();let r=it(t,n,i);yt(e,r);let a={tree:H,kind:b(H),path:V,wholeWorkspace:k===`workspace`},f=sn.current;f&&st(r,{tree:f.treeName,kind:b(f.treeName),path:f.path})&&(u=f),st(r,a,rr.current)&&(l=!0),!(!l&&!u)&&(s||=setTimeout(d,Math.max(200,c+1500-Date.now())))},p=[`document.inserted`,`document.inserted.batch`,`document.updated`,`document.removed`,`document.deleted`,`document.removed.batch`,`document.deleted.batch`,`document.linked`,`document.unlinked`,`document.linked.batch`,`document.unlinked.batch`,`tree.document.inserted`,`tree.document.inserted.batch`,`tree.document.removed`,`tree.document.removed.batch`,`tree.document.deleted`,`tree.document.deleted.batch`,`tree.layer.merged`,`tree.layer.subtracted`,`tree.created`,`tree.renamed`].map(e=>[e,f(e)]);return p.forEach(([e,t])=>m.on(e,t)),()=>{a=!0,s&&clearTimeout(s),r?.(),p.forEach(([e,t])=>m.off(e,t))}},[e,vr,_r,H,V,k,$,Yn]);let yr=`${V}\0${H}\0${G??``}\0${k}`,[br,xr]=(0,T.useState)(yr);br!==yr&&(xr(yr),F(1),It(null));let Sr=`${V}\0${H}\0${G??``}`,[Cr,wr]=(0,T.useState)(Sr);Cr!==Sr&&(wr(Sr),dt(`path`));let Tr=(e,t)=>{let n=e===`/`?`canvas`:e.split(`/`).pop()||`canvas`;Tt(n),St({parentPath:e,captureView:t})},Er=l.get(`createCanvas`)===`1`,[Dr,Or]=(0,T.useState)(!1);Dr!==Er&&(Or(Er),Er&&Tr(V,!1)),(0,T.useEffect)(()=>{if(!Er)return;let e=new URLSearchParams(n.search);e.delete(`createCanvas`);let t=e.toString();o(`${n.pathname}${t?`?${t}`:``}${n.hash}`,{replace:!0})},[Er,V]);let kr=(0,T.useCallback)(e=>{let t=new URLSearchParams(n.search);t.delete(`q`),t.delete(`search`);for(let n of e)t.append(`q`,n);let r=t.toString();o(`${n.pathname}${r?`?${r}`:``}${n.hash}`)},[n.pathname,n.search,n.hash,o]),Ar=JSON.stringify([l.has(`q`),...Le]),[jr,Mr]=(0,T.useState)(Ar);jr!==Ar&&(Mr(Ar),Pt(Le),F(1));let Nr=`${Ar}\0${Y??``}\0${An}\0${V}\0${Ft??``}`,[Pr,Fr]=(0,T.useState)(Nr);Pr!==Nr&&(Fr(Nr),l.has(`q`)||Le.length>0||Y!==`canvas`||Ft===V||(Pt(An?[An]:[]),F(1)));let Ir=(0,T.useCallback)(e=>{let t=e.trim();t&&(It(null),Pt(e=>{if(e.includes(t))return e;let n=[...e,t];return kr(n),F(1),n}))},[kr,It,Pt,F]),Lr=(0,T.useCallback)(e=>{Pt(t=>{let n=e<0?[]:t.filter((t,n)=>n!==e);return n.length===0&&It(V),kr(n),F(1),n})},[kr,V,It,Pt,F]),Rr=L.join(` `).trim(),zr=!!R.activeContextType&&(R.isDirty||Rr!==(Y===`canvas`?An:R.savedSearchQuery||``));!e&&K!==null&&an(null),(0,T.useEffect)(()=>{let t=!1;if(!e)return;let n=0,r=!1,i=(i=!1)=>{let a=++n;i&&fe(e,H),te(e,H).then(i=>{!t&&a===n&&(r=!0,_n.current=`${e}/${H}`,an(i))}).catch(()=>{!t&&a===n&&!r&&an(null)})};i(!1);let a=t=>{let n=t.detail;n?.workspaceName&&n.workspaceName!==e||n?.treeName&&n.treeName!==H||i(!n?.cacheInvalidated)};window.addEventListener(`workspace:tree:refresh`,a);let o=S(e,vr);return()=>{t=!0,o(),window.removeEventListener(`workspace:tree:refresh`,a)}},[e,H,vr]),!(e&&Y===`canvas`&&!W)&&N!==null&&Mt(null),(0,T.useEffect)(()=>{let t=!1;if(!(!e||Y!==`canvas`||W))return oe(e,V,H).then(e=>{t||Mt(e)}).catch(()=>{t||Mt(null)}),()=>{t=!0}},[e,V,H,Y,W]);let Br=async()=>{if(C){pt(!0);try{let t=await x(e||C.id);Ye(t),s({title:`Success`,description:`Workspace started successfully`}),window.dispatchEvent(new CustomEvent(`workspaces:refresh`))}catch(e){let t=e instanceof Error?e.message:`Failed to start workspace`;s({title:`Error`,description:t,variant:`destructive`})}finally{pt(!1)}}},Vr=async t=>{if(!C)return;let n=c({title:`Removing…`,description:`Document from "${V}"`});try{await _(e||C.id,[t],V,[],H,Yr,{trashIfOrphaned:!0}),j(e||C.id,H,V),w(e=>e.filter(e=>e.id!==t)),D(e=>Math.max(0,e-1)),n.done({title:`Success`,description:`Document removed from workspace path.`})}catch(e){n.fail({title:`Error`,description:e instanceof Error?e.message:`Failed to remove document`,variant:`destructive`})}},Hr=async t=>{if(!C)return;let n=c({title:`Deleting…`,description:`Document from "${V}"`});try{await ae(e||C.id,[t],V,[],H,Yr),j(e||C.id,H,V),w(e=>e.filter(e=>e.id!==t)),D(e=>Math.max(0,e-1)),n.done({title:`Success`,description:`Document deleted.`})}catch(e){n.fail({title:`Error`,description:e instanceof Error?e.message:`Failed to delete document`,variant:`destructive`})}},Ur=async t=>{if(!C)return;let n=c({title:`Removing…`,description:`${t.length} document(s) from "${V}"`});try{await _(e||C.id,t,V,[],H,Yr,{trashIfOrphaned:!0}),j(e||C.id,H,V),w(e=>e.filter(e=>!t.includes(e.id))),D(e=>Math.max(0,e-t.length)),n.done({title:`Success`,description:`${t.length} document(s) removed.`})}catch(e){n.fail({title:`Error`,description:e instanceof Error?e.message:`Failed to remove documents`,variant:`destructive`})}},Wr=async t=>{if(!C)return;let n=c({title:`Deleting…`,description:`${t.length} document(s)`});try{await ae(e||C.id,t,V,[],H,Yr),j(e||C.id,H,V),w(e=>e.filter(e=>!t.includes(e.id))),D(e=>Math.max(0,e-t.length)),n.done({title:`Success`,description:`${t.length} document(s) deleted.`})}catch(e){n.fail({title:`Error`,description:e instanceof Error?e.message:`Failed to delete documents`,variant:`destructive`})}},Gr=async t=>{if(!C)return;let n=c({title:`Destroying…`,description:`Document and its backend copies`});try{let r=await re(e||C.id,[t]);if(r.failed?.length){n.fail({title:`Error`,description:r.failed[0].reason,variant:`destructive`});return}w(e=>e.filter(e=>e.id!==t)),D(e=>Math.max(0,e-1)),n.done({title:`Destroyed`,description:`Document removed from all backends.`})}catch(e){n.fail({title:`Error`,description:e instanceof Error?e.message:`Failed to destroy document`,variant:`destructive`})}},Kr=async t=>{if(!C)return;let n=c({title:`Destroying…`,description:`${t.length} document(s) and their backend copies`});try{let r=await re(e||C.id,t),i=new Set(r.successful?.filter(e=>e.docDeleted).map(e=>e.id)??[]);w(e=>e.filter(e=>!i.has(e.id))),D(e=>Math.max(0,e-i.size));let a=[r.successful?.length?`${r.successful.length} destroyed`:null,r.failed?.length?`${r.failed.length} failed`:null].filter(Boolean).join(`, `);r.failed?.length?n.fail({title:`Destroy incomplete`,description:a,variant:`destructive`}):n.done({title:`Destroyed`,description:a||`No documents destroyed`})}catch(e){n.fail({title:`Error`,description:e instanceof Error?e.message:`Failed to destroy documents`,variant:`destructive`})}},qr=e=>{xt({documentIds:e,operation:`copy`,sourcePath:V,sourceTreeName:H}),window.dispatchEvent(new CustomEvent(`documents:clipboard`,{detail:{documentIds:e,operation:`copy`}})),s({title:`Copied`,description:`${e.length} document(s) copied to clipboard`})},Jr=e=>{xt({documentIds:e,operation:`cut`,sourcePath:V,sourceTreeName:H}),window.dispatchEvent(new CustomEvent(`documents:clipboard`,{detail:{documentIds:e,operation:`cut`}})),s({title:`Cut`,description:`${e.length} document(s) cut to clipboard`})},Yr=b(H),Xr=async(t,n,r={})=>{if(!e)return!1;let i=r.targetTreeName??H,a=r.targetTreeType??Yr,o=r.move??_t?.operation===`cut`,s=c({title:o?`Moving…`:`Pasting…`,description:`${n.length} document(s) → "${t}"`});try{let c=await ee(e,t,n,i,a);if(c){j(e,i,t);let a=r.sourceTreeName||_t?.sourceTreeName,c=r.sourcePath||_t?.sourcePath;if((r.move??_t?.operation===`cut`)&&c&&a){let t=b(a);await _(e,n,c,[],a,t),j(e,a,c),window.dispatchEvent(new CustomEvent(`workspace:documents:refresh`,{detail:{workspaceName:e,path:c,treeName:a}}))}s.done({title:`Success`,description:`${n.length} document(s) ${o?`moved`:`pasted`} to "${t}"`}),xt(null),window.dispatchEvent(new CustomEvent(`documents:clipboard`,{detail:null}));let l=performance.now();await $(),console.info(`[paste] list refresh ${Math.round(performance.now()-l)} ms`),window.dispatchEvent(new CustomEvent(`workspace:documents:refresh`,{detail:{workspaceName:e,path:t,treeName:i}}))}else s.done();return c}catch(e){return s.fail({title:`Error`,description:e instanceof Error?e.message:`Failed to paste documents`,variant:`destructive`}),!1}},Zr=async(t,n)=>{if(!e)return!1;try{let r=(await de(e,n,t,H,Yr)).length>0;return r&&(Se(e,H,n),s({title:`Success`,description:`Imported ${t.length} document(s) to "${n}"`})),r}catch(e){return s({title:`Error`,description:e instanceof Error?e.message:`Failed to import documents`,variant:`destructive`}),!1}},Qr=async()=>{if(!C||nr===0||pr||fr.current||window.prompt(`Type PURGE to permanently delete all ${nr} matching documents across all pages.`)!==`PURGE`)return;fr.current=!0,dr(!0);let t=c({title:`Purging…`,description:`${nr} matching document(s)`});try{let n=await g(e||C.id,or,nr);n.deleted===n.requested?t.done({title:`Success`,description:`${n.deleted} document(s) purged.`}):t.fail({title:`Purge incomplete`,description:`${n.deleted} of ${n.requested} document(s) purged. Refresh and review the remaining results before retrying.`})}catch(e){t.fail({title:`Error`,description:e instanceof Error?e.message:`Failed to purge documents`,variant:`destructive`})}finally{j(e||C.id,H,V),await $({silent:!0}),fr.current=!1,dr(!1)}},$r=()=>Tr(V,!0),ei=async()=>{if(!(!e||!M||!wt.trim())){Dt(!0);try{let t=wt.trim(),n=M.parentPath,r=n===`/`?`/${t}`:`${n}/${t}`,i={...R.filters,features:{...R.filters.features,allOf:Dn}};await ce(e,r,H,M.captureView?{metadata:{toolbox:i},querySpec:{features:i.features,filters:[...Oe(R.filters.timeline),...De(R.filters.geo)],query:Rr||void 0,sort:R.filters.sort?.sortBy?R.filters.sort:null}}:{}),St(null),fe(e,H);try{let t=await te(e,H,{force:!0});an(t)}catch{}window.dispatchEvent(new CustomEvent(`workspace:tree:refresh`,{detail:{workspaceName:e}})),o(Ne(e,r,H))}catch(e){s({title:`Error`,description:e instanceof Error?e.message:`Failed to create canvas`,variant:`destructive`})}finally{Dt(!1)}}},ti=async()=>{if(!(!e||Y!==`canvas`)){kt(!0);try{let t=N||await ge(e,V,H);Mt(t);let n=`${window.location.origin}${t.url}`;await navigator.clipboard?.writeText(n),s({title:`Public canvas link copied`,description:n})}catch(e){s({title:`Error`,description:e instanceof Error?e.message:`Failed to share canvas`,variant:`destructive`})}finally{kt(!1)}}},ni=async()=>{if(N){kt(!0);try{await v(N.code),Mt(null),window.dispatchEvent(new CustomEvent(`workspace:tree:refresh`,{detail:{workspaceName:e,treeName:H}})),s({title:`Canvas unshared`,description:`The public link no longer works.`})}catch(e){s({title:`Error`,description:e instanceof Error?e.message:`Failed to unshare canvas`,variant:`destructive`})}finally{kt(!1)}}},ri=async()=>{if(!e||Y!==`canvas`||V===`/`)return;let t=jn?.label||V.split(`/`).pop()||`canvas`,n=N?` Its public link will stop working.`:``;if(window.confirm(`Delete canvas "${t}"? This cannot be undone.${n}`)){jt(!0);try{if(N)await v(N.code),Mt(null);else if(J?.locked){s({title:`Canvas is locked`,description:`Unlock it before deleting.`,variant:`destructive`});return}await y(e,V,!1,H);let n=V.split(`/`).filter(Boolean);n.pop();let r=n.length?`/${n.join(`/`)}`:`/`;window.dispatchEvent(new CustomEvent(`workspace:tree:refresh`,{detail:{workspaceName:e,treeName:H}})),o(Ne(e,r,H)),s({title:`Canvas deleted`,description:`"${t}" was removed.`})}catch(e){s({title:`Error`,description:e instanceof Error?e.message:`Failed to delete canvas`,variant:`destructive`})}finally{jt(!1)}}},ii=(0,T.useCallback)(async t=>{if(!e||!q)return;let n={treeName:H,path:V},r=cn===`left`?n:q,i=cn===`left`?q:n,a=cn===`left`?un:hn;if(a.length===0){s({title:`Nothing selected`,description:`Tick documents in the focused pane first.`});return}let o=b(i.treeName),l=c({title:t?`Moving…`:`Copying…`,description:`${a.length} document(s) → "${i.path}"`});try{if(!await ee(e,i.path,a,i.treeName,o)){l.done();return}if(j(e,i.treeName,i.path),t){let t=b(r.treeName);await _(e,a,r.path,[],r.treeName,t),j(e,r.treeName,r.path)}[r,i].forEach(t=>window.dispatchEvent(new CustomEvent(`workspace:documents:refresh`,{detail:{workspaceName:e,path:t.path,treeName:t.treeName}}))),l.done({title:t?`Moved`:`Copied`,description:`${a.length} document(s) → "${i.path}"`})}catch(e){l.fail({title:`Error`,description:e instanceof Error?e.message:`Transfer failed`,variant:`destructive`})}},[e,q,cn,H,V,un,hn,s,c]);if((0,T.useEffect)(()=>{if(!q)return;let e=e=>{if(e.key!==`F5`&&e.key!==`F6`)return;let t=e.target;t.tagName!==`INPUT`&&t.tagName!==`TEXTAREA`&&(e.preventDefault(),ii(e.key===`F6`))};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[q,ii]),Xe)return(0,E.jsx)(`div`,{className:`flex items-center justify-center h-full`,children:(0,E.jsxs)(`div`,{className:`text-center space-y-2`,children:[(0,E.jsx)(`div`,{className:`animate-spin rounded-full h-8 w-8 border-b-2 border-primary mx-auto`}),(0,E.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`Loading workspace...`})]})});if(!C)return(0,E.jsx)(`div`,{className:`flex items-center justify-center h-full text-muted-foreground`,children:`Workspace not found.`});let ai=Y===`canvas`&&!W&&!!J,oi=!ai&&!U&&yn?(0,E.jsx)(Ue,{views:wn,activeId:Tn,onSelect:On,onSave:kn,accentColor:we(C.color),onOpenToSide:e=>{on({treeName:H,path:V,viewId:e}),ln(`right`)}}):void 0,si=Qt||C.status!==`active`?(0,E.jsxs)(E.Fragment,{children:[Qt&&(0,E.jsx)(`button`,{type:`button`,onClick:()=>{en(!$t),F(1)},"aria-pressed":$t,className:u(`min-h-10 rounded-md border px-2 text-xs`,$t&&`bg-warning/15 text-warning`),children:`Unfiled only`}),C.status!==`active`&&(0,E.jsx)(`button`,{type:`button`,onClick:Br,disabled:ft,className:`min-h-10 rounded-md border px-2 text-xs`,children:ft?`Starting…`:`Start`})]}):void 0,ci=Ee(H,V)?V===`/Trash`?(0,E.jsx)(`div`,{className:`h-full overflow-auto p-4`,children:(0,E.jsx)(Ke,{workspaceName:e||C.id})}):(0,E.jsx)(qe,{workspace:e||C.id,path:V,onNavigate:t=>o(Ne(e,t,`backends`))},e):(0,E.jsx)(We,{navigationTabs:oi,navigationActions:si,onBack:mn,accentColor:we(C.color),urlType:W?b(H)===`directory`?`${H}-layer`:`context-layer`:Y===`canvas`?`canvas`:b(H)===`directory`?H:`context`,urlDisplay:Vn,contextPath:V,treeName:H,workspaceId:e||C.id,workspaceLabel:C.label||C.name,workspaceIcon:C.icon,documentSchema:En,documents:ar,isLoading:et,totalCount:nr,currentPage:P,pageSize:I,onPageChange:F,onPageSizeChange:e=>{Nt(e),F(1)},onRemoveDocument:V===`/`?void 0:Vr,onDeleteDocument:Hr,onDestroyDocument:Gr,onRemoveDocuments:V===`/`?void 0:Ur,onDeleteDocuments:Wr,onDestroyDocuments:Kr,onCopyDocuments:qr,onCutDocuments:Jr,onPasteDocuments:U?void 0:Xr,onImportDocuments:U?void 0:Zr,onSelectionChange:dn,onBrowseTree:()=>pn(`workspaces`,`detail`,e??null),onBrowseWorkspaces:()=>fn(`workspaces`),onNavigatePath:t=>o(Ne(e,t,H)),folders:vn,onOpenFolder:t=>o(Ne(e,Me(t),H)),scope:k,onScopeChange:dt,pastedDocumentIds:_t?.documentIds,linkTree:K,onPurgeDocuments:U?void 0:Qr,disablePurgeDocuments:pr,canvasInfo:jn??void 0,isCanvasPinned:Ln,onTogglePinCanvas:Q?Bn:void 0,onSaveAsCanvas:K&&Y!==`canvas`&&!W&&!U?$r:void 0,onShareCanvas:Y===`canvas`&&!W?ti:void 0,onUnshareCanvas:N?ni:void 0,onDeleteCanvas:Y===`canvas`&&!W?ri:void 0,isSharingCanvas:Ot,isDeletingCanvas:At,isCanvasShared:!!N,isCanvasLocked:!!J?.locked,backendSearchQueries:L,onBackendSearch:Ir,serverSort:R.filters.sort,onServerSortChange:Rt,onRemoveBackendQuery:Lr,canSaveChanges:zr,isSavingChanges:R.isSaving,onSaveChanges:Lt,contentBanner:O&&at?(0,E.jsx)(ht,{data:at,className:`mb-3`}):null,children:ai&&J?(0,E.jsx)(ye,{workspaceId:e||C.id,treeName:H,path:V,layerId:J.id,querySpec:J.querySpec,metadata:J.metadata,isLocked:!!J.locked,fetchDocuments:R.isDirty?Un:void 0}):!U&&Z.kind===`columns`?(0,E.jsx)(Ve,{documents:ar,workspaceId:e||C.id,columns:Z.columns??[],onColumnsChange:e=>kn(wn.map(t=>t.id===Z.id?{...t,columns:e}:t))}):!U&&Z.kind===`app`&&Z.app&&Z.app!==`notes`?(0,E.jsx)(Ge,{app:Z.app,workspaceId:e||C.id,treeName:H,path:V}):null});return(0,E.jsxs)(Ie,{workspaceId:e||C.id,treeName:H,path:V,headerOnly:!0,className:`relative flex flex-col h-full min-h-0`,children:[(0,E.jsx)($e,{workspaceId:C.id,workspaceName:C.label||C.name},C.id),Ee(H,V)&&(0,E.jsx)(be,{workspace:C.label||C.name,workspaceIcon:C.icon,tree:H,path:V,onBack:mn,onBrowseTree:()=>pn(`workspaces`,`detail`,e||C.id),onBrowseWorkspaces:()=>fn(`workspaces`),onNavigatePath:t=>o(Ne(e,t,H)),accentColor:we(C.color)}),M&&(0,E.jsx)(`div`,{className:`shrink-0 px-2 pt-2`,children:(0,E.jsx)(Re,{title:`New canvas`,onClose:()=>St(null),children:(0,E.jsxs)(`form`,{onSubmit:e=>{e.preventDefault(),ei()},className:`space-y-4`,children:[(0,E.jsxs)(`div`,{className:`grid gap-4 md:grid-cols-2`,children:[(0,E.jsxs)(`div`,{children:[(0,E.jsx)(`label`,{htmlFor:`canvas-name`,className:`mb-1 block text-sm font-medium`,children:`Name`}),(0,E.jsx)(`input`,{id:`canvas-name`,className:`w-full rounded-md border bg-background px-3 py-2 text-sm focus:outline-none focus:ring-1 focus:ring-primary`,placeholder:`Canvas name…`,value:wt,onChange:e=>Tt(e.target.value),onKeyDown:e=>{e.key===`Escape`&&St(null)},autoFocus:!0})]}),(0,E.jsxs)(`div`,{children:[(0,E.jsx)(`span`,{className:`mb-1 block text-sm font-medium`,children:`Parent path`}),(0,E.jsx)(`div`,{className:`flex h-10 items-center rounded-md bg-muted px-3 font-mono text-sm text-muted-foreground`,children:M.parentPath===`/`?`/`:M.parentPath})]})]}),(0,E.jsxs)(`label`,{className:`flex items-start gap-2 text-sm`,children:[(0,E.jsx)(`input`,{type:`checkbox`,className:`mt-0.5`,checked:M.captureView,onChange:e=>St({...M,captureView:e.target.checked})}),(0,E.jsxs)(`span`,{children:[`Capture the current view`,(0,E.jsx)(`span`,{className:`block text-xs text-muted-foreground`,children:`Freezes the active filters, search and sort into the canvas.`})]})]}),(0,E.jsxs)(`div`,{className:`flex gap-2`,children:[(0,E.jsx)(d,{type:`submit`,disabled:!wt.trim()||Et,children:Et?`Creating…`:`Create canvas`}),(0,E.jsx)(d,{type:`button`,variant:`outline`,onClick:()=>St(null),children:`Cancel`})]})]})})}),(0,E.jsxs)(`div`,{"data-canvas-panes":!0,className:`flex-1 min-h-0 flex gap-2`,children:[(0,E.jsx)(`div`,{"data-canvas-pane":!0,className:u(`flex-1 min-w-0 bg-background overflow-hidden`,q&&(cn===`left`?`ring-2 ring-primary`:`ring-1 ring-primary/20`)),onMouseDown:e=>{e.target.closest(`button,input,textarea,select,a`)||ln(`left`)},children:ci}),q&&e&&(0,E.jsx)(Ct,{workspaceName:e,workspaceLabel:C.label||C.name,workspaceIcon:C.icon,pane:q,isFocused:cn===`right`,clipboard:_t,setClipboard:xt,onFocus:()=>ln(`right`),onSelectionChange:gn,onNavigate:e=>on(t=>t&&{...t,path:e,viewId:void 0}),onClose:()=>{on(null),ln(`left`),gn([])}})]})]})}function St(e,t){if(!e||t===`/`)return e;let n=e;for(let e of t.split(`/`).filter(Boolean))if(n=n?.children?.find(t=>t.name===e)??null,!n)return null;return n}function Ct({workspaceName:e,workspaceLabel:t,workspaceIcon:n,pane:r,isFocused:i=!1,clipboard:a,setClipboard:o,onFocus:s,onSelectionChange:c,onNavigate:l,onClose:d}){let{openM1Drawer:f,openM2Drawer:p}=Pe(),{showToast:m,showProgress:g}=h(),[ne,v]=(0,T.useState)(null),[ie,y]=(0,T.useState)([]),[oe,se]=(0,T.useState)(!1),[ce,le]=(0,T.useState)(0),[ue,de]=(0,T.useState)(1),[me,he]=(0,T.useState)(50),x=b(r.treeName),ge=St(ne,r.path),_e=ge?.type===`canvas`,ve=(0,T.useMemo)(()=>x===`directory`?gt(ne,r.path):[],[ne,r.path,x]),ye=r.viewId?He(ge?.metadata).find(e=>e.id===r.viewId)??null:null,be=`${e}://${r.path===`/`?``:r.path.replace(/^\//,``)}`,xe=ze(ye),S=(0,T.useCallback)(async()=>{if(Ee(r.treeName,r.path)){y([]),le(0),se(!1);return}let t=vt(e,r.treeName,r.path,ue,me,``,xe??``),n=A.get(t);if(n){y(n.documents),le(n.totalCount);return}se(!0);try{let n=await pe(e,r.path,xe?[xe]:[],{limit:me,page:ue,treeName:r.treeName,treeType:x}),i=n.payload||[],a=n.totalCount||n.count||0;y(i),le(a),A.set(t,{documents:i,totalCount:a})}catch(e){m({title:`Error`,description:e instanceof Error?e.message:`Failed to fetch side pane documents`,variant:`destructive`}),y([]),le(0)}finally{se(!1)}},[e,r.path,r.treeName,x,me,ue,m,xe]);(0,T.useEffect)(()=>{let t=!1,n=0,i=!1,a=(a=!1)=>{let o=++n;a&&fe(e,r.treeName),te(e,r.treeName).then(e=>{!t&&o===n&&(i=!0,v(e))}).catch(()=>{!t&&o===n&&!i&&v(null)})};a(!1);let o=t=>{let n=t.detail;n?.workspaceName&&n.workspaceName!==e||n?.treeName&&n.treeName!==r.treeName||a(!n?.cacheInvalidated)};return window.addEventListener(`workspace:tree:refresh`,o),()=>{t=!0,window.removeEventListener(`workspace:tree:refresh`,o)}},[e,r.treeName]),(0,T.useEffect)(()=>{S()},[S]),(0,T.useEffect)(()=>{let t=t=>{let n=t.detail;n?.workspaceName&&n.workspaceName!==e||(bt(e,n),st(ot(n),{tree:r.treeName,kind:b(r.treeName),path:r.path})&&(j(e,r.treeName,r.path),S()))};return window.addEventListener(`workspace:documents:refresh`,t),()=>window.removeEventListener(`workspace:documents:refresh`,t)},[S,e,r.treeName,r.path]);let Se=(0,T.useCallback)(async(t,n,i={})=>{let s=i.targetTreeName??r.treeName,c=i.targetTreeType??x,l=i.move??a?.operation===`cut`,u=g({title:l?`Moving…`:`Pasting…`,description:`${n.length} document(s) → "${t}"`});try{let r=await ee(e,t,n,s,c);if(r){j(e,s,t);let r=i.sourcePath||a?.sourcePath,c=i.sourceTreeName||a?.sourceTreeName;if((i.move??a?.operation===`cut`)&&r&&c){let t=b(c);await _(e,n,r,[],c,t),j(e,c,r),window.dispatchEvent(new CustomEvent(`workspace:documents:refresh`,{detail:{workspaceName:e,path:r,treeName:c}}))}u.done({title:`Success`,description:`${n.length} document(s) ${l?`moved`:`pasted`} to "${t}"`}),o(null),await S(),window.dispatchEvent(new CustomEvent(`workspace:documents:refresh`,{detail:{workspaceName:e,path:t,treeName:s}}))}else u.done();return r}catch(e){return u.fail({title:`Error`,description:e instanceof Error?e.message:`Failed to paste documents`,variant:`destructive`}),!1}},[e,r.treeName,x,S,g,a,o]),Ce=(0,T.useCallback)(()=>{j(e,r.treeName,r.path),S()},[e,r.treeName,r.path,S]),we=(0,T.useCallback)(async t=>{let n=g({title:`Removing…`,description:`${t.length} document(s) from "${r.path}"`});try{await _(e,t,r.path,[],r.treeName,x),Ce(),n.done({title:`Removed`,description:`${t.length} document(s) removed from "${r.path}"`})}catch(e){n.fail({title:`Error`,description:e instanceof Error?e.message:`Failed to remove documents`,variant:`destructive`})}},[e,r.path,r.treeName,x,Ce,g]),Te=(0,T.useCallback)(async t=>{let n=g({title:`Deleting…`,description:`${t.length} document(s)`});try{await ae(e,t,r.path,[],r.treeName,x),Ce(),n.done({title:`Deleted`,description:`${t.length} document(s) deleted.`})}catch(e){n.fail({title:`Error`,description:e instanceof Error?e.message:`Failed to delete documents`,variant:`destructive`})}},[e,r.path,r.treeName,x,Ce,g]),De=(0,T.useCallback)(async t=>{let n=g({title:`Destroying…`,description:`${t.length} document(s) and their backend copies`});try{let r=await re(e,t);if(r.failed?.length&&!r.successful?.length){n.fail({title:`Error`,description:r.failed[0].reason,variant:`destructive`});return}Ce();let i=`${r.successful?.length??0} document(s) destroyed${r.failed?.length?` · ${r.failed.length} failed`:``}.`;r.failed?.length?n.fail({title:`Destroy incomplete`,description:i,variant:`destructive`}):n.done({title:`Destroyed`,description:i})}catch(e){n.fail({title:`Error`,description:e instanceof Error?e.message:`Failed to destroy documents`,variant:`destructive`})}},[e,Ce,g]);return(0,E.jsxs)(`div`,{className:u(`relative flex-1 min-w-0 rounded-(--sheet-radius) border bg-background overflow-hidden`,i?`ring-2 ring-primary`:`ring-1 ring-primary/20`),onMouseDown:e=>{e.target.closest(`button,input,textarea,select,a`)||s()},children:[d&&(0,E.jsx)(`button`,{type:`button`,onClick:d,className:`absolute right-2 top-2 z-10 px-2 py-1 text-xs rounded-md border bg-background/90 hover:bg-accent`,children:`Close`}),Ee(r.treeName,r.path)?r.path===`/Trash`?(0,E.jsx)(`div`,{className:`h-full overflow-auto p-4`,children:(0,E.jsx)(Ke,{workspaceName:e})}):(0,E.jsx)(qe,{workspace:e,path:r.path,onNavigate:l||(()=>{})}):(0,E.jsx)(We,{frameContent:!1,onBrowseWorkspaces:()=>f(`workspaces`),onBrowseTree:()=>p(`workspaces`,`detail`,e),urlType:_e?`canvas`:x===`directory`?r.treeName:`context`,urlDisplay:be,contextPath:r.path,treeName:r.treeName,workspaceId:e,workspaceLabel:t,workspaceIcon:n,documentSchema:xe,documents:ie,isLoading:oe,totalCount:ce,currentPage:ue,pageSize:me,onPageChange:de,onPageSizeChange:e=>{he(e),de(1)},onRemoveDocument:r.path===`/`?void 0:e=>we([e]),onRemoveDocuments:r.path===`/`?void 0:we,onDeleteDocument:e=>Te([e]),onDeleteDocuments:Te,onDestroyDocument:e=>De([e]),onDestroyDocuments:De,onCopyDocuments:e=>{o({documentIds:e,operation:`copy`,sourcePath:r.path,sourceTreeName:r.treeName}),window.dispatchEvent(new CustomEvent(`documents:clipboard`,{detail:{documentIds:e,operation:`copy`}}))},onCutDocuments:e=>{o({documentIds:e,operation:`cut`,sourcePath:r.path,sourceTreeName:r.treeName}),window.dispatchEvent(new CustomEvent(`documents:clipboard`,{detail:{documentIds:e,operation:`cut`}}))},onPasteDocuments:r.treeName===`backends`?void 0:Se,onSelectionChange:c,pastedDocumentIds:a?.documentIds,linkTree:ne,folders:ve,onOpenFolder:l,onNavigatePath:l,canvasInfo:_e?{label:ge?.label,description:ge?.description,color:ge?.color}:void 0,children:ye?.kind===`columns`?(0,E.jsx)(Ve,{documents:ie,workspaceId:e,columns:ye.columns??[],onColumnsChange:()=>{},readOnly:!0}):ye?.kind===`app`&&ye.app&&ye.app!==`notes`?(0,E.jsx)(Ge,{app:ye.app,workspaceId:e,treeName:r.treeName,path:r.path}):null})]})}export{xt as default};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{o as e}from"./rolldown-runtime-C0FnF6B9.js";import{l as t,u as n}from"./code-editor-BOIngd5F.js";import{Br as r,Ct as i,G as a,It as o,L as s,Lt as c,Nt as l,St as u,Tr as d,Ut as f,X as p,Yr as m,ct as h,it as g,mn as _,mt as v,ti as y,tt as b,vn as x,yn as S}from"./ui-Byg1cZDr.js";import{t as C}from"./utils-2pl1SbIp.js";import{An as w,Vn as T,q as E}from"./workspace-CrSpR4xf.js";import{t as D}from"./TodosWidget-CxiqmDuJ.js";import{d as O,o as k,u as ee}from"./ObjectPropertiesCard-BIBMvx_i.js";import{h as te,s as ne,t as re,u as ie}from"./document-list-Dsf1DVEx.js";import{n as ae}from"./use-toolbox-Ck_cLGgf.js";import{t as oe}from"./useToastHelpers-CRrpIIdY.js";import{n as A}from"./color-DFEH4BfK.js";import{t as se}from"./DocumentIcon-x299QNu_.js";import{t as ce}from"./registry-DIfZf6LB.js";import{t as le}from"./FileForm-CqJpRbXv.js";import{t as ue}from"./applet-target-C_gBgU-Z.js";var j=e(n(),1),M=t();function de({target:e,children:t}){let[n,r]=(0,j.useState)([]),i=(0,j.useRef)(!1),[a,o]=(0,j.useState)(!1),[s,c]=(0,j.useState)(!1),[l,u]=(0,j.useState)(null),{showErrorToast:d}=oe();return(0,M.jsxs)(`div`,{className:`relative flex flex-col h-full min-h-0 bg-background ${a?`ring-2 ring-inset ring-primary`:``}`,onDragOverCapture:t=>{s||!e||!Array.from(t.dataTransfer.types).includes(`Files`)||(t.preventDefault(),t.stopPropagation(),t.dataTransfer.dropEffect=i.current?`none`:`copy`,o(!i.current))},onDragLeaveCapture:e=>{e.currentTarget.contains(e.relatedTarget)||o(!1)},onDropCapture:t=>{if(s||!e||!Array.from(t.dataTransfer.types).includes(`Files`))return;if(t.preventDefault(),t.stopPropagation(),o(!1),i.current){d(`Wait for the current upload to finish`);return}let n=Array.from(t.dataTransfer.files);if(!n.length){d(`Drop files rather than folders`);return}r(n),u(e),c(!0)},children:[t,a&&(0,M.jsxs)(`div`,{className:`pointer-events-none absolute inset-0 z-30 flex items-center justify-center bg-background/80 text-sm font-medium`,children:[`Drop files to upload to `,e?.mode===`workspace`?e.path:`this context`]}),s&&(0,M.jsxs)(ie,{label:`Import files`,onClose:()=>{i.current||c(!1)},children:[(0,M.jsx)(`h2`,{className:`border-b px-4 py-3 text-sm font-medium`,children:`Import files`}),(0,M.jsx)(le,{target:l,initialFiles:n,onClose:()=>c(!1),onBusyChange:e=>{i.current=e}})]})]})}function fe({navigationTabs:e,navigationActions:t,onBack:n,accentColor:r,frameContent:s=!0,urlType:l,urlDisplay:u,contextPath:d,treeName:f,workspaceId:m,workspaceLabel:h,workspaceIcon:g,documentSchema:_,documents:b,isLoading:x,totalCount:C,currentPage:w,pageSize:T,onPageChange:E,onPageSizeChange:D,onRemoveDocument:ne,onDeleteDocument:ie,onDestroyDocument:oe,onRemoveDocuments:A,onDeleteDocuments:se,onDestroyDocuments:ce,onCopyDocuments:le,onCutDocuments:ue,onPasteDocuments:fe,onImportDocuments:N,onSelectionChange:pe,pastedDocumentIds:P,onPurgeDocuments:me,disablePurgeDocuments:he,canvasInfo:F,isCanvasPinned:I,onTogglePinCanvas:L,onSaveAsCanvas:R,onShareCanvas:z,onUnshareCanvas:B,onDeleteCanvas:V,isSharingCanvas:H,isDeletingCanvas:U,isCanvasShared:W,isCanvasLocked:ge,backendSearchQueries:_e,onBackendSearch:G,onRemoveBackendQuery:K,serverSort:ve,onServerSortChange:ye,scope:be,onScopeChange:xe,canSaveChanges:Se,isSavingChanges:q,onSaveChanges:J,onBrowseWorkspaces:Ce,onBrowseTree:we,onNavigatePath:Te,linkTree:Ee,children:Y,contentBanner:De,folders:Oe,onOpenFolder:ke}){let Ae=l===`canvas`,X=te(),{state:je,toggleView:Me,hasActiveFilters:Ne,openAddPicker:Pe}=ae(),Z=k(),[Fe,Q]=(0,j.useState)(``),$=JSON.stringify([m,f,d,_]),[Ie,Le]=(0,j.useState)($);Ie!==$&&(Le($),Q(``));let Re=(0,M.jsxs)(M.Fragment,{children:[t,R&&(0,M.jsx)(`button`,{type:`button`,onClick:R,title:`Save as canvas`,"aria-label":`Save as canvas`,className:`flex h-control-sm w-control-sm shrink-0 items-center justify-center rounded-md border text-muted-foreground hover:bg-accent touch-target`,children:(0,M.jsx)(y,{className:`h-4 w-4`})})]});return(0,M.jsxs)(de,{target:N&&m?{mode:`workspace`,workspaceName:m,path:d,treeName:f||`context`,treeType:f===`directory`?`directory`:`context`}:null,children:[e&&!X&&(0,M.jsx)(O,{accentColor:r,children:e}),(0,M.jsxs)(`div`,{className:`canvas-surface-body${s&&!X?` is-framed`:``}`,children:[(0,M.jsx)(ee,{workspaceIcon:g,workspace:h||m||u.split(`://`)[0]||`Workspace`,actions:X&&e?(0,M.jsxs)(`details`,{className:`relative shrink-0`,"aria-label":`Canvas views`,children:[(0,M.jsx)(`summary`,{className:`cursor-pointer rounded-md border px-2 py-1 text-xs`,title:`Choose or manage content views`,children:`Views`}),(0,M.jsx)(`div`,{className:`absolute right-0 top-full z-30 mt-2 min-w-64 max-w-[80vw] rounded-md border bg-background p-2 shadow-lg`,children:e})]}):void 0,tree:f?`${f}${l.endsWith(`-layer`)?`:layer`:``}`:l.replace(`-layer`,``),path:d,accentColor:r,onBack:Z.location?Z.location.section===`view`?Z.close:()=>Z.update?.({section:`view`}):n,section:Z.location?`document/${Z.location.documentId}/${Z.location.section}`:void 0,onSection:Z.location?()=>Z.update?.({section:`view`}):void 0,onBrowseWorkspaces:Ce,onBrowseTree:we,onNavigatePath:Te,onFilter:()=>Me(`tools`),filtersActive:Ne,filtersOpen:je.t1Open&&je.t1View===`tools`,onAdd:e=>Pe({modal:e.shiftKey,fresh:!0}),search:G||!Y?{workspaceId:m,queries:_e||[],onSearch:G??Q,localOnly:!G,onRemoveQuery:K,scope:be,onScopeChange:xe}:void 0,onDraftChange:Y?void 0:Q}),Ae&&F?(0,M.jsx)(M.Fragment,{children:(0,M.jsxs)(`div`,{className:`flex items-center gap-3 px-4 py-2.5 border-b bg-muted/20 shrink-0 min-w-0`,children:[F.color&&(0,M.jsx)(`div`,{className:`w-1 h-6 rounded-full shrink-0`,style:{backgroundColor:F.color}}),(0,M.jsx)(S,{className:`w-4 h-4 shrink-0 text-primary`}),(0,M.jsxs)(`div`,{className:`flex flex-col min-w-0 flex-1`,children:[(0,M.jsx)(`span`,{className:`text-lg font-semibold leading-tight truncate`,children:F.label||u.split(`://`)[1]||`Canvas`}),F.description&&(0,M.jsx)(`span`,{className:`text-xs text-muted-foreground truncate leading-tight`,children:F.description})]}),Se&&J&&(0,M.jsxs)(`button`,{type:`button`,onClick:J,disabled:q,className:`shrink-0 flex items-center gap-1.5 px-2.5 py-1 text-xs border rounded-md hover:bg-accent transition-colors text-muted-foreground hover:text-foreground disabled:opacity-50`,title:`Save filters`,children:[(0,M.jsx)(i,{className:`w-3 h-3`}),(0,M.jsx)(`span`,{className:`hidden sm:inline`,children:q?`Saving...`:`Save filters`})]}),L&&(0,M.jsxs)(`button`,{type:`button`,onClick:L,"aria-pressed":!!I,className:`shrink-0 flex items-center gap-1.5 px-2.5 py-1 text-xs border rounded-md hover:bg-accent transition-colors text-muted-foreground hover:text-foreground`,title:I?`Unpin from home`:`Pin to home`,children:[I?(0,M.jsx)(c,{className:`w-3 h-3`}):(0,M.jsx)(o,{className:`w-3 h-3`}),(0,M.jsx)(`span`,{className:`hidden sm:inline`,children:I?`Unpin`:`Pin`})]}),z&&(0,M.jsxs)(`button`,{type:`button`,onClick:z,disabled:H||U,className:`shrink-0 flex items-center gap-1.5 px-2.5 py-1 text-xs border rounded-md hover:bg-accent transition-colors text-muted-foreground hover:text-foreground disabled:opacity-50`,title:W?`Copy public link`:`Share canvas`,children:[(0,M.jsx)(v,{className:`w-3 h-3`}),(0,M.jsx)(`span`,{className:`hidden sm:inline`,children:H?`Sharing...`:W?`Copy link`:`Share`})]}),W&&B&&(0,M.jsxs)(`button`,{type:`button`,onClick:B,disabled:H||U,className:`shrink-0 flex items-center gap-1.5 px-2.5 py-1 text-xs border rounded-md hover:bg-destructive/10 transition-colors text-muted-foreground hover:text-destructive disabled:opacity-50`,children:[(0,M.jsx)(a,{className:`w-3 h-3`}),(0,M.jsx)(`span`,{className:`hidden sm:inline`,children:`Unshare`})]}),V&&(0,M.jsxs)(`button`,{type:`button`,onClick:V,disabled:U||ge&&!W,title:ge&&!W?`Unlock this canvas before deleting it`:`Delete canvas`,className:`shrink-0 flex items-center gap-1.5 px-2.5 py-1 text-xs border rounded-md hover:bg-destructive/10 transition-colors text-muted-foreground hover:text-destructive disabled:opacity-50`,children:[(0,M.jsx)(p,{className:`w-3 h-3`}),(0,M.jsx)(`span`,{className:`hidden sm:inline`,children:U?`Deleting…`:`Delete`})]})]})}):null,Y&&(R||t)&&(0,M.jsx)(`div`,{className:`flex items-center gap-2 border-b px-3 py-1`,children:Re}),(0,M.jsxs)(`div`,{className:`flex-1 min-h-0 overflow-y-auto`,children:[De,Y||(0,M.jsx)(re,{readingPane:!0,externalSearchQuery:Fe,toolbarActions:Re,documents:_?b.filter(e=>e.schema===_):b,isLoading:x,folders:_?void 0:Oe,onOpenFolder:ke,contextPath:d,treeName:f,workspaceId:m,totalCount:C,viewMode:_?`card`:`table`,allowViewToggle:!0,currentPage:w,pageSize:T,onPageChange:E,onPageSizeChange:D,onRemoveDocument:ne,onDeleteDocument:ie,onDestroyDocument:oe,onRemoveDocuments:A,onDeleteDocuments:se,onDestroyDocuments:ce,onCopyDocuments:le,onCutDocuments:ue,onPasteDocuments:fe,onImportDocuments:N,onSelectionChange:pe,pastedDocumentIds:P,onPurgeDocuments:_?void 0:me,disablePurgeDocuments:he,backendSearchQueries:_e,onBackendSearch:G,serverSort:ve,onServerSortChange:ye,onRemoveBackendQuery:K,scope:be,onScopeChange:xe,canSaveChanges:!Ae&&Se,isSavingChanges:q,onSaveChanges:J,linkTree:Ee},_??`documents`)]})]})]})}var N=[{id:`todos`,label:`Todo list`},{id:`todo-app`,label:`Todo App`},{id:`notes`,label:`Notes list`},{id:`notes-app`,label:`Notes App`},{id:`sketch`,label:`Sketch`},{id:`terminal`,label:`Terminal`}];function pe(e){return e?.kind===`app`&&e.app===`notes`?`data/schema/note`:void 0}var P={id:`default`,name:`All`,kind:`documents`};function me(){return[{id:`emails`,label:`Emails`,schemas:[`data/schema/message`]},{id:`todos`,label:`Todos`,schemas:[`data/schema/task`]},{id:`notes`,label:`Notes`,schemas:[`data/schema/note`]},{id:`links`,label:`Links`,schemas:[`data/schema/tab`,`data/schema/link`]},{id:`files`,label:`Files`,schemas:[`data/schema/file`]}]}function he(e){let t=e?.views;if(!Array.isArray(t))return[P];let n=t.filter(e=>{let t=e;return!t||typeof t.id!=`string`||typeof t.name!=`string`?!1:t.kind===`documents`||t.kind===`columns`||t.kind===`app`&&(N.some(e=>e.id===t.app)||t.app===`filters`||t.app===`lens`)});return n.length>0?n:[P]}var F={todos:_,"todo-app":_,notes:b,"notes-app":b,filters:h,sketch:g,Brush:m,terminal:g,lens:u};function I({views:e,activeId:t,onSelect:n,onSave:r,readOnly:i=!1,className:a,accentColor:o,onOpenToSide:c}){let[u,p]=(0,j.useState)(null),[m,h]=(0,j.useState)(``),[g,_]=(0,j.useState)(!1),[v,y]=(0,j.useState)(null),[b,S]=(0,j.useState)(null),w=(0,j.useRef)(null);(0,j.useEffect)(()=>{let e=w.current;if(!e)return;let t=t=>{if(t.ctrlKey||e.scrollWidth<=e.clientWidth)return;let n=Math.abs(t.deltaX)>Math.abs(t.deltaY)?t.deltaX:t.deltaY,r=t.deltaMode===1?16:t.deltaMode===2?e.clientWidth:1;t.preventDefault(),e.scrollLeft+=n*r};return e.addEventListener(`wheel`,t,{passive:!1}),()=>e.removeEventListener(`wheel`,t)},[]),(0,j.useEffect)(()=>{w.current?.querySelector(`[aria-pressed="true"], input`)?.scrollIntoView({block:`nearest`,inline:`nearest`})},[t,u]);let T=()=>{y(null),S(null)},E=()=>{if(v&&b&&v!==b.id){let t=e.find(e=>e.id===v),n=e.filter(e=>e.id!==v),i=n.findIndex(e=>e.id===b.id);t&&i>=0&&(n.splice(b.before?i:i+1,0,t),n.some((t,n)=>t.id!==e[n].id)&&r(n))}T()},D=()=>{if(!u)return;let t=m.trim();t&&r(e.map(e=>e.id===u?{...e,name:t}:e)),p(null)},O=(t,n)=>{_(!1);let i=`view-${Date.now().toString(36)}`,a=t===`columns`?`Board`:t===`app`?N.find(e=>e.id===n)?.label??`App`:`List`,o=t===`columns`?{id:i,name:a,kind:t,columns:me()}:t===`app`?{id:i,name:a,kind:t,app:n}:{id:i,name:a,kind:t};r([...e,o],i),p(i),h(a)},k=n=>{let i=e.filter(e=>e.id!==n);r(i.length>0?i:[P],n===t?i[0]?.id??P.id:void 0)};return(0,M.jsxs)(`div`,{className:C(`relative flex h-full min-w-0 items-end`,a),children:[(0,M.jsx)(`div`,{ref:w,className:`flex min-w-0 items-end gap-0.5 overflow-x-auto overscroll-x-contain pt-1 [scrollbar-width:none]`,children:e.map(r=>{let a=r.id===t,l=r.kind===`columns`?d:r.kind===`app`&&r.app?F[r.app]:x;return u===r.id?(0,M.jsx)(`input`,{autoFocus:!0,"aria-label":`Tab name`,value:m,onChange:e=>h(e.target.value),onBlur:D,onKeyDown:e=>{e.key===`Enter`&&D(),e.key===`Escape`&&p(null)},className:C(`relative h-[2.3rem] w-28 shrink-0 rounded-t-[.5rem] border-0 px-3 pb-1 text-xs outline-none ring-0`,a?C(`z-[2] bg-background font-medium`,o?A(o):`text-foreground`):`bg-muted text-muted-foreground`),style:{backgroundColor:a?o:void 0}},r.id):(0,M.jsxs)(`button`,{type:`button`,"aria-pressed":a,onClick:()=>n(r.id),onDoubleClick:()=>{i||(p(r.id),h(r.name))},title:i?r.name:`${r.name}: double-click to rename, drag to reorder`,draggable:!i,onDragStart:e=>{e.dataTransfer.setData(`text/plain`,r.name),e.dataTransfer.effectAllowed=`move`,y(r.id)},onDragOver:e=>{if(!v||v===r.id)return;e.preventDefault(),e.dataTransfer.dropEffect=`move`;let t=e.currentTarget.getBoundingClientRect(),n=e.clientX<t.left+t.width/2;S(e=>e?.id===r.id&&e.before===n?e:{id:r.id,before:n})},onDrop:e=>{e.preventDefault(),E()},onDragEnd:T,className:C(`group relative flex h-[2.3rem] shrink-0 items-center gap-1.5 rounded-t-[.5rem] border-0 px-3 pb-1 text-xs transition-colors`,a?C(`z-[2] bg-background font-medium`,o?A(o):`text-foreground`):`bg-muted text-muted-foreground hover:bg-accent hover:text-foreground`,v===r.id&&`opacity-50`),style:{backgroundColor:a?o:void 0,boxShadow:b?.id===r.id?`inset ${b.before?`2px`:`-2px`} 0 0 var(--primary)`:void 0},children:[(0,M.jsx)(l,{className:`h-3 w-3 shrink-0`}),(0,M.jsx)(`span`,{className:`max-w-32 truncate`,children:r.name}),c&&(0,M.jsx)(f,{className:`h-3 w-3 shrink-0 opacity-0 transition-opacity hover:opacity-100 group-hover:opacity-60`,"aria-label":`Open to the side`,onClick:e=>{e.stopPropagation(),c(r.id)}}),!i&&e.length>1&&(0,M.jsx)(s,{className:C(`h-3 w-3 shrink-0 transition-opacity hover:text-destructive`,a?`opacity-60 hover:opacity-100`:`opacity-0 group-hover:opacity-100`),onClick:e=>{e.stopPropagation(),k(r.id)}})]},r.id)})}),!i&&(g?(0,M.jsxs)(`span`,{className:`absolute left-0 top-full z-30 flex w-full min-w-64 flex-wrap items-center gap-2 rounded-b-xl border bg-card p-2 shadow-lg`,children:[(0,M.jsxs)(`button`,{type:`button`,onClick:()=>O(`documents`),className:`flex h-10 items-center gap-1.5 rounded-md border px-2 text-xs text-muted-foreground hover:bg-accent/50 hover:text-foreground`,children:[(0,M.jsx)(x,{className:`h-3 w-3`}),` List`]}),(0,M.jsxs)(`button`,{type:`button`,onClick:()=>O(`columns`),className:`flex h-10 items-center gap-1.5 rounded-md border px-2 text-xs text-muted-foreground hover:bg-accent/50 hover:text-foreground`,children:[(0,M.jsx)(d,{className:`h-3 w-3`}),` Board`]}),N.map(e=>{let t=F[e.id];return(0,M.jsxs)(`button`,{type:`button`,onClick:()=>O(`app`,e.id),className:`flex h-10 items-center gap-1.5 rounded-md border px-2 text-xs text-muted-foreground hover:bg-accent/50 hover:text-foreground`,children:[(0,M.jsx)(t,{className:`h-3 w-3`}),` `,e.label]},e.id)}),(0,M.jsx)(`button`,{type:`button`,onClick:()=>_(!1),className:`p-1 text-muted-foreground hover:text-foreground`,"aria-label":`Cancel`,children:(0,M.jsx)(s,{className:`h-3 w-3`})})]}):(0,M.jsx)(`button`,{type:`button`,onClick:()=>_(!0),title:`Add view`,"aria-label":`Add view`,className:`relative ml-1 flex h-[2.3rem] w-10 shrink-0 items-center justify-center rounded-md pb-1 text-muted-foreground hover:bg-accent/50 hover:text-foreground`,children:(0,M.jsx)(l,{className:`h-3.5 w-3.5`})}))]})}var L=[{id:`emails`,label:`Emails`,schemas:[`data/schema/message`]},{id:`todos`,label:`Todos`,schemas:[`data/schema/task`]},{id:`notes`,label:`Notes`,schemas:[`data/schema/note`]},{id:`links`,label:`Links`,schemas:[`data/schema/tab`,`data/schema/link`]},{id:`files`,label:`Files`,schemas:[`data/schema/file`]}];function R(e,t){return t.some(t=>e.schema===t||e.schema.startsWith(`${t}/`))}function z({documents:e,workspaceId:t,columns:n,onColumnsChange:i,readOnly:a=!1}){let[o,c]=(0,j.useState)(null),[u,d]=(0,j.useState)(!1),[f,p]=(0,j.useState)({}),[m,h]=(0,j.useState)({}),g=(0,j.useRef)(null),[_,v]=(0,j.useState)(!1),y=(0,j.useCallback)(()=>{let e=g.current;e&&v(e.scrollWidth-e.clientWidth-e.scrollLeft>8)},[]);(0,j.useEffect)(()=>{let e=g.current;if(!e)return;let t=new ResizeObserver(()=>y());return t.observe(e),()=>t.disconnect()},[y]);let b=(e,t)=>{e.preventDefault();let r=e.currentTarget.parentElement;if(!r)return;let a=e.clientX,o=r.getBoundingClientRect().width,s=o,c=e=>{s=Math.min(900,Math.max(220,o+e.clientX-a)),h(e=>({...e,[t]:s}))},l=()=>{window.removeEventListener(`pointermove`,c),window.removeEventListener(`pointerup`,l),i(n.map(e=>e.id===t?{...e,width:Math.round(s)}:e))};window.addEventListener(`pointermove`,c),window.addEventListener(`pointerup`,l)},x=e=>{h(t=>{let n={...t};return delete n[e],n}),i(n.map(t=>t.id===e?{...t,width:void 0}:t))},S=e=>{let t=f[e];if(t===void 0)return;let r=n.find(t=>t.id===e);r&&(r.filter||``)!==t&&i(n.map(n=>n.id===e?{...n,filter:t||void 0}:n))},C=L.filter(e=>!n.some(t=>t.id===e.id));return(0,M.jsxs)(`div`,{className:`relative h-full`,children:[(0,M.jsx)(`div`,{ref:g,onScroll:y,className:`flex h-full snap-x snap-mandatory gap-3 overflow-x-auto overscroll-x-contain p-2`,"data-testid":`schema-columns-board`,children:n.map(t=>{let r=(f[t.id]??t.filter??``).toLowerCase(),o=e.filter(e=>R(e,t.schemas)).filter(e=>{if(!r)return!0;let t=w(e);return`${t.title}\n${t.preview}\n${t.subtitle}`.toLowerCase().includes(r)}),l=m[t.id]??t.width;return(0,M.jsxs)(`div`,{className:`relative flex h-full min-h-0 min-w-0 shrink-0 grow-0 basis-full snap-start flex-col rounded-(--card-radius) border bg-muted/20 ${l?`sm:basis-[var(--col-w)]`:`sm:basis-[48%] lg:basis-[32%] xl:basis-[24%]`}`,style:l?{"--col-w":`${l}px`}:void 0,children:[!a&&(0,M.jsx)(`div`,{onPointerDown:e=>b(e,t.id),onDoubleClick:()=>x(t.id),title:`Drag to resize; double-click to reset`,className:`absolute right-0 inset-y-0 z-10 w-2 cursor-col-resize touch-none rounded-r-lg transition-colors hover:bg-primary/25 active:bg-primary/40 max-sm:hidden`}),(0,M.jsxs)(`div`,{className:`flex items-center gap-2 px-3 pb-1 pt-2.5 max-sm:pr-10`,children:[(0,M.jsx)(`span`,{className:`truncate text-sm font-medium`,children:t.label}),(0,M.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:o.length}),(0,M.jsx)(`span`,{className:`flex-1`}),!a&&(0,M.jsx)(`button`,{type:`button`,onClick:()=>i(n.filter(e=>e.id!==t.id)),title:`Remove column`,className:`rounded-sm p-0.5 text-muted-foreground hover:text-destructive`,children:(0,M.jsx)(s,{className:`h-3.5 w-3.5`})})]}),(0,M.jsx)(`div`,{className:`px-3 pb-2`,children:(0,M.jsx)(`input`,{value:f[t.id]??t.filter??``,onChange:e=>p(n=>({...n,[t.id]:e.target.value})),onBlur:()=>S(t.id),onKeyDown:e=>{e.key===`Enter`&&S(t.id)},placeholder:`Filter…`,readOnly:a,className:`h-7 w-full rounded-md border border-input bg-background px-2 text-xs placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring`})}),(0,M.jsxs)(`div`,{className:`flex-1 space-y-1.5 overflow-y-auto px-2 pb-2`,children:[o.map(e=>{let t=w(e);return(0,M.jsxs)(`button`,{type:`button`,onClick:()=>c(e),className:`w-full min-w-0 rounded-md border bg-card px-2.5 py-2 text-left transition-colors hover:bg-accent/50`,children:[(0,M.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,M.jsx)(se,{document:e,size:3.5}),(0,M.jsx)(`span`,{className:`truncate text-xs font-medium`,title:t.title,children:t.title})]}),t.preview&&(0,M.jsx)(`p`,{className:`mt-1 line-clamp-2 break-words text-[11px] leading-snug text-muted-foreground`,children:t.preview}),(0,M.jsx)(`p`,{className:`mt-1 text-[10px] text-muted-foreground/70`,children:new Date(e.updatedAt||e.createdAt).toLocaleDateString()})]},e.id)}),o.length===0&&(0,M.jsx)(`p`,{className:`px-2 py-3 text-center text-xs text-muted-foreground/60`,children:`Empty`})]})]},t.id)})}),(!a&&C.length>0||_)&&(0,M.jsxs)(`div`,{className:`pointer-events-none absolute inset-y-0 right-0 z-20 flex w-7 flex-col items-end bg-gradient-to-l from-background via-background/60 to-transparent py-2`,children:[!a&&C.length>0&&(0,M.jsxs)(`div`,{className:`pointer-events-auto relative`,children:[(0,M.jsx)(`button`,{type:`button`,onClick:()=>d(e=>!e),title:`Add column`,"aria-label":`Add column`,className:`flex h-7 w-6 items-center justify-center rounded-l-md border border-r-0 bg-background text-muted-foreground shadow-elevation-1 hover:bg-accent hover:text-foreground`,children:(0,M.jsx)(l,{className:`h-3.5 w-3.5`})}),u&&(0,M.jsxs)(`div`,{className:`absolute right-0 top-8 w-44 rounded-lg border bg-background p-2 shadow-elevation-2`,children:[(0,M.jsx)(`p`,{className:`px-2 pb-1 text-[10px] uppercase tracking-wide text-muted-foreground`,children:`Add column`}),C.map(e=>(0,M.jsx)(`button`,{type:`button`,onClick:()=>{d(!1),i([...n,{...e}])},className:`w-full rounded-md px-2 py-1.5 text-left text-xs text-muted-foreground hover:bg-accent/50 hover:text-foreground`,children:e.label},e.id)),(0,M.jsx)(`button`,{type:`button`,onClick:()=>d(!1),className:`mt-1 w-full rounded-md px-2 py-1.5 text-left text-xs text-muted-foreground/60 hover:bg-accent/50`,children:`Cancel`})]})]}),_&&(0,M.jsx)(r,{className:`my-auto h-4 w-4 self-center text-muted-foreground/70`,"aria-label":`More columns`})]}),(0,M.jsx)(ne,{document:o,isOpen:o!==null,onClose:()=>c(null),workspaceId:t})]})}function B(e,t,n,r,i){let a=`${e}\0${t}\0${n}\0${r}\0${i??``}`,[o,s]=(0,j.useState)(0),[c,l]=(0,j.useState)(null);(0,j.useEffect)(()=>{let o=!1;return E(e,n,t,{limit:200,allOf:[r],...i?{sortBy:i,order:`asc`}:{}}).then(e=>{o||l({key:a,docs:e.payload||[]})}).catch(()=>{o||l({key:a,docs:[]})}),()=>{o=!0}},[a,o]);let u=c?.key===a?c.docs:[],d=c?.key!==a;return(0,j.useEffect)(()=>{let e=()=>s(e=>e+1);return window.addEventListener(`workspace:documents:refresh`,e),()=>window.removeEventListener(`workspace:documents:refresh`,e)},[]),{docs:u,isLoading:d,refresh:(0,j.useCallback)(()=>s(e=>e+1),[])}}function V({workspaceId:e,treeName:t,path:n}){let{docs:r,isLoading:i,refresh:a}=B(e,t,n,T,`tasks`),[o,s]=(0,j.useState)(!1),c=o?r.filter(e=>e.data?.status!==`completed`):r,l=r.filter(e=>{let t=e.data?.status;return t!==`completed`&&t!==`cancelled`}).length;return(0,M.jsxs)(`div`,{className:`mx-auto flex h-full w-full max-w-3xl flex-col p-4`,children:[(0,M.jsxs)(`div`,{className:`mb-2 flex shrink-0 items-center justify-between gap-2`,children:[(0,M.jsxs)(`span`,{className:`text-xs text-muted-foreground`,children:[l,` open`]}),(0,M.jsxs)(`label`,{className:`flex cursor-pointer items-center gap-1.5 text-xs text-muted-foreground`,children:[(0,M.jsx)(`input`,{type:`checkbox`,checked:o,onChange:e=>s(e.target.checked)}),`hide done`]})]}),(0,M.jsx)(`div`,{className:`min-h-0 flex-1 space-y-1 overflow-y-auto`,children:i?(0,M.jsx)(`p`,{className:`py-4 text-sm text-muted-foreground`,children:`Loading…`}):c.length===0?(0,M.jsx)(`p`,{className:`py-4 text-sm text-muted-foreground`,children:`No todos here.`}):c.map(t=>(0,M.jsx)(D,{doc:t,workspaceId:e,readOnly:!1,onChanged:a},t.id))})]})}function H({app:e,contextId:t,...n}){let r=t&&e!==`lens`?{mode:`context`,contextId:t}:{mode:`workspace`,workspaceName:n.workspaceId,treeName:n.treeName,path:n.path,treeType:n.treeName===`directory`||n.treeName===`backends`?`directory`:`context`},i=e===`todo-app`?`todo`:e===`notes-app`?`notes`:e,a=ce.find(e=>e.id===i);return(0,M.jsx)(ue,{target:r,children:e===`todos`?(0,M.jsx)(V,{...n}):a?(0,M.jsx)(a.Component,{}):null})}export{pe as a,P as i,z as n,he as o,I as r,fe as s,H as t};
|