@augmentd-labs/canvas-web 2.26.23 → 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.
Files changed (76) hide show
  1. package/dist/assets/{FileForm-DhQhVnoi.js → FileForm-CqJpRbXv.js} +1 -1
  2. package/dist/assets/{FiltersApplet-BAe-Eq0e.js → FiltersApplet--yXjHZqs.js} +1 -1
  3. package/dist/assets/{HomeFab-BXSAtndH.js → HomeFab-3cymOU3P.js} +1 -1
  4. package/dist/assets/{IdentityFields-OPEWPlZs.js → IdentityFields-Bti7ojF3.js} +1 -1
  5. package/dist/assets/{LensApplet-DuADvEm5.js → LensApplet-5NHmz9TL.js} +1 -1
  6. package/dist/assets/LinkToCard-5dg0jvSY.js +1 -0
  7. package/dist/assets/{NextShell-BIYs9fCL.js → NextShell-UX4Efo0u.js} +1 -1
  8. package/dist/assets/{NotesApplet-BmLjXx7V.js → NotesApplet-bIqcBzpg.js} +1 -1
  9. package/dist/assets/{ObjectPropertiesCard-ChvWbOpZ.js → ObjectPropertiesCard-BIBMvx_i.js} +4 -4
  10. package/dist/assets/{PathPickerField-DBe7jykL.js → PathPickerField-fZazwxCN.js} +1 -1
  11. package/dist/assets/{PickDocumentsCard-Bo224P4q.js → PickDocumentsCard-DamtV7fN.js} +1 -1
  12. package/dist/assets/{SketchApplet-ADVOnSLI.js → SketchApplet-DDIg411i.js} +1 -1
  13. package/dist/assets/{SketchEditor-CkgRysCG.js → SketchEditor-CKPPuZt3.js} +1 -1
  14. package/dist/assets/{TerminalApplet-CkO4uaE3.js → TerminalApplet-wGJG1PPc.js} +1 -1
  15. package/dist/assets/{TextDocumentEditor-COvsHJXH.js → TextDocumentEditor-CRre32cj.js} +1 -1
  16. package/dist/assets/{TodosApplet-Bpf1OIH4.js → TodosApplet-CleBd4uU.js} +1 -1
  17. package/dist/assets/{TodosWidget-BIYqPXUp.js → TodosWidget-CxiqmDuJ.js} +1 -1
  18. package/dist/assets/{UploadProgressList-BXJr87lI.js → UploadProgressList-DRJzjy6A.js} +1 -1
  19. package/dist/assets/{_agentId_-Bquq_bl1.js → _agentId_-BpZvdICK.js} +0 -0
  20. package/dist/assets/_contextId_-tiUa7oY9.js +1 -0
  21. package/dist/assets/_workspaceName_-BJ7uXLLN.js +1 -0
  22. package/dist/assets/{about-DpILEqyH.js → about-Dn6r3v8E.js} +1 -1
  23. package/dist/assets/{add-BHkmOOkO.js → add-BTCF4qRT.js} +1 -1
  24. package/dist/assets/{agents-lo0DGGKV.js → agents-CO1AV00y.js} +1 -1
  25. package/dist/assets/{appearance-5Vx17gl4.js → appearance-BoZKRJ6u.js} +1 -1
  26. package/dist/assets/{applet-target-ChiiXVdC.js → applet-target-C_gBgU-Z.js} +1 -1
  27. package/dist/assets/{apps-Ci03cFZm.js → apps-B9-IBy2A.js} +1 -1
  28. package/dist/assets/{backend-sync-progress-H4Zch25P.js → backend-sync-progress-pZrhQPk3.js} +3 -3
  29. package/dist/assets/content-app-view-acLgdhQ9.js +1 -0
  30. package/dist/assets/{context-mfIOB8dN.js → context-DQoZFMDQ.js} +1 -1
  31. package/dist/assets/{contexts-CRWqFXzJ2.js → contexts-CvMtPd1N2.js} +1 -1
  32. package/dist/assets/{date-time-picker-B6mkWt-g.js → date-time-picker-DebNUTx3.js} +1 -1
  33. package/dist/assets/{document-CX543Kcz.js → document-DOp6AbOi.js} +1 -1
  34. package/dist/assets/document-list-Dsf1DVEx.js +2 -0
  35. package/dist/assets/{home-Dus2Lg1o.js → home-BZ2OLB0t.js} +1 -1
  36. package/dist/assets/index-4M1qLU_S.js +16 -0
  37. package/dist/assets/{key-bindings-C1Zk8f6z.js → key-bindings-CwUENuYh.js} +1 -1
  38. package/dist/assets/{offline-CsRyFUg7.js → offline-COOUcZsG.js} +1 -1
  39. package/dist/assets/{public-share-DXxVwHKT.js → public-share-g_wBd6BW.js} +1 -1
  40. package/dist/assets/{query-debug-YfWOzM6h.js → query-debug-CrPsUwT-.js} +1 -1
  41. package/dist/assets/{registry-J0TPxyW8.js → registry-Ct1xWTs8.js} +2 -2
  42. package/dist/assets/{roles-BYHLwWCD.js → roles-Bo9GZdOk.js} +1 -1
  43. package/dist/assets/settings-CDsVas7f.js +14 -0
  44. package/dist/assets/{settings-DLbaI3my.js → settings-CuK0olLh.js} +1 -1
  45. package/dist/assets/{settings-D089lyYg.js → settings-Df2eiuZ1.js} +1 -1
  46. package/dist/assets/{settings-B8BgCI2q.js → settings-udxCpn5y.js} +1 -1
  47. package/dist/assets/{share-target-CMIiAOIz.js → share-target-DEadau7S.js} +1 -1
  48. package/dist/assets/{shared-D2uRUNdC.js → shared-BQZGA3ph.js} +1 -1
  49. package/dist/assets/{shared-B6YGbqUJ.js → shared-De1-Pxac.js} +1 -1
  50. package/dist/assets/{sketch-lazy-pbG2cCpW.js → sketch-lazy-C4pjV1WK.js} +2 -2
  51. package/dist/assets/{text-documents-BvDFBVnC.js → text-documents-0P9jkIpu.js} +2 -2
  52. package/dist/assets/{use-applet-docs-o5NAUFBk.js → use-applet-docs-D5eXpITp.js} +1 -1
  53. package/dist/assets/{use-applet-target-cO-FiyPQ.js → use-applet-target-gXPvZGgx.js} +1 -1
  54. package/dist/assets/use-canvas-pins-CbAxLLTU.js +3 -0
  55. package/dist/assets/{use-workspace-identity-mgaofjsD.js → use-workspace-identity-BCrrvfeE.js} +1 -1
  56. package/dist/assets/{useAddTarget-DUjaZdBQ.js → useAddTarget-CqnDU0Om.js} +1 -1
  57. package/dist/assets/{useAgentModels-Cxb5NyCI.js → useAgentModels-CUwa_SHA.js} +1 -1
  58. package/dist/assets/{useDocumentThumbnail-DYLCC63L.js → useDocumentThumbnail-DunxmU1A.js} +1 -1
  59. package/dist/assets/{useEditNoteFields-zHEWwDfB.js → useEditNoteFields-BehI0vog.js} +1 -1
  60. package/dist/assets/workspace-CrSpR4xf.js +1 -0
  61. package/dist/assets/{workspace-area-menu-Dg3hXKR3.js → workspace-area-menu-CP5OWZNX.js} +1 -1
  62. package/dist/assets/{workspace-content-gate-Be4tLYiB.js → workspace-content-gate-9okuA7J7.js} +1 -1
  63. package/dist/assets/{workspace-import-form-BRwc_oVg.js → workspace-import-form-aR-DwHf6.js} +1 -1
  64. package/dist/assets/{workspaces-BOYcqiRy.js → workspaces-DyWI__ok.js} +1 -1
  65. package/dist/index.html +25 -25
  66. package/dist/sw.js +1 -1
  67. package/package.json +2 -2
  68. package/dist/assets/LinkToCard-nR7Lal_o.js +0 -1
  69. package/dist/assets/_contextId_-DndAgEMz.js +0 -1
  70. package/dist/assets/_workspaceName_-C_tzeHUf.js +0 -1
  71. package/dist/assets/content-app-view-BFluU_u6.js +0 -1
  72. package/dist/assets/document-list-rh4ittZx.js +0 -2
  73. package/dist/assets/index-Tx_qtD_m.js +0 -16
  74. package/dist/assets/settings-Ba8Od_Uj.js +0 -14
  75. package/dist/assets/use-canvas-pins-6vnfChWd.js +0 -3
  76. package/dist/assets/workspace-DvxC7pw1.js +0 -1
@@ -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{ct as r,lt as i,ut as a}from"./index-Tx_qtD_m.js";import{n as o}from"./page-header-DkOHw0g-.js";import{t as s}from"./use-settings-back-CQauYjQ4.js";var c=e(n(),1),l=t();function u(){let[e,t]=(0,c.useState)(i),[n,u]=(0,c.useState)(``),d=e=>{if(e.previousTree&&e.previousTree===e.nextTree){u(`Choose a different shortcut: that combination is already assigned.`);return}try{a(e),t(e),u(`Saved on this device.`)}catch{u(`Could not save shortcuts in this browser.`)}};return(0,l.jsxs)(`div`,{className:`mx-auto max-w-4xl`,children:[(0,l.jsx)(o,{className:`mb-6`,title:`Key bindings`,onBack:s(),description:`Web UI shortcuts, saved on this device and available offline.`}),(0,l.jsxs)(`section`,{className:`space-y-4 rounded-lg border p-4`,children:[(0,l.jsx)(`h2`,{className:`font-medium`,children:`Tree navigation`}),(0,l.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`Cycle the open workspace menu’s tabs in their displayed order, including Pins and Layers. Swipe left for next or right for previous over the tab bar. Shortcuts pause while typing or using a dialog.`}),[`previousTree`,`nextTree`].map(t=>(0,l.jsxs)(`div`,{className:`flex flex-wrap items-center gap-3`,children:[(0,l.jsx)(`label`,{htmlFor:t,className:`min-w-32 text-sm`,children:t===`previousTree`?`Previous tree`:`Next tree`}),(0,l.jsxs)(`select`,{id:t,className:`rounded-md border bg-background p-2 text-sm`,value:e[t].split(`+`).slice(0,-1).join(`+`),onChange:n=>d({...e,[t]:n.target.value?`${n.target.value}+${e[t].slice(-1)||r[t].slice(-1)}`:``}),children:[(0,l.jsx)(`option`,{value:``,children:`Disabled`}),[`Alt`,`Alt+Shift`,`Ctrl+Shift`,`Meta+Shift`].map(e=>(0,l.jsx)(`option`,{value:e,children:e},e))]}),(0,l.jsx)(`select`,{"aria-label":`${t===`previousTree`?`Previous`:`Next`} tree key`,disabled:!e[t],className:`rounded-md border bg-background p-2 text-sm disabled:opacity-50`,value:e[t].slice(-1)||r[t].slice(-1),onChange:n=>d({...e,[t]:`${e[t].split(`+`).slice(0,-1).join(`+`)}+${n.target.value}`}),children:`ABCDEFGHIJKLMNOPQRSTUVWXYZ`.split(``).map(e=>(0,l.jsx)(`option`,{value:e,children:e},e))})]},t)),(0,l.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`Browsers and operating systems may reserve combinations. Choose another if a shortcut does not reach Canvas. Letters refer to physical keyboard positions (Q/W on a US keyboard); Meta is Command on Mac.`}),(0,l.jsx)(`button`,{type:`button`,className:`rounded-md border px-3 py-2 text-sm hover:bg-accent`,onClick:()=>d({...r}),children:`Restore defaults`}),(0,l.jsx)(`p`,{role:`status`,className:`text-sm`,children:n})]})]})}export{u 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{ct as r,lt as i,ut as a}from"./index-4M1qLU_S.js";import{n as o}from"./page-header-DkOHw0g-.js";import{t as s}from"./use-settings-back-CQauYjQ4.js";var c=e(n(),1),l=t();function u(){let[e,t]=(0,c.useState)(i),[n,u]=(0,c.useState)(``),d=e=>{if(e.previousTree&&e.previousTree===e.nextTree){u(`Choose a different shortcut: that combination is already assigned.`);return}try{a(e),t(e),u(`Saved on this device.`)}catch{u(`Could not save shortcuts in this browser.`)}};return(0,l.jsxs)(`div`,{className:`mx-auto max-w-4xl`,children:[(0,l.jsx)(o,{className:`mb-6`,title:`Key bindings`,onBack:s(),description:`Web UI shortcuts, saved on this device and available offline.`}),(0,l.jsxs)(`section`,{className:`space-y-4 rounded-lg border p-4`,children:[(0,l.jsx)(`h2`,{className:`font-medium`,children:`Tree navigation`}),(0,l.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`Cycle the open workspace menu’s tabs in their displayed order, including Pins and Layers. Swipe left for next or right for previous over the tab bar. Shortcuts pause while typing or using a dialog.`}),[`previousTree`,`nextTree`].map(t=>(0,l.jsxs)(`div`,{className:`flex flex-wrap items-center gap-3`,children:[(0,l.jsx)(`label`,{htmlFor:t,className:`min-w-32 text-sm`,children:t===`previousTree`?`Previous tree`:`Next tree`}),(0,l.jsxs)(`select`,{id:t,className:`rounded-md border bg-background p-2 text-sm`,value:e[t].split(`+`).slice(0,-1).join(`+`),onChange:n=>d({...e,[t]:n.target.value?`${n.target.value}+${e[t].slice(-1)||r[t].slice(-1)}`:``}),children:[(0,l.jsx)(`option`,{value:``,children:`Disabled`}),[`Alt`,`Alt+Shift`,`Ctrl+Shift`,`Meta+Shift`].map(e=>(0,l.jsx)(`option`,{value:e,children:e},e))]}),(0,l.jsx)(`select`,{"aria-label":`${t===`previousTree`?`Previous`:`Next`} tree key`,disabled:!e[t],className:`rounded-md border bg-background p-2 text-sm disabled:opacity-50`,value:e[t].slice(-1)||r[t].slice(-1),onChange:n=>d({...e,[t]:`${e[t].split(`+`).slice(0,-1).join(`+`)}+${n.target.value}`}),children:`ABCDEFGHIJKLMNOPQRSTUVWXYZ`.split(``).map(e=>(0,l.jsx)(`option`,{value:e,children:e},e))})]},t)),(0,l.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`Browsers and operating systems may reserve combinations. Choose another if a shortcut does not reach Canvas. Letters refer to physical keyboard positions (Q/W on a US keyboard); Meta is Command on Mac.`}),(0,l.jsx)(`button`,{type:`button`,className:`rounded-md border px-3 py-2 text-sm hover:bg-accent`,onClick:()=>d({...r}),children:`Restore defaults`}),(0,l.jsx)(`p`,{role:`status`,className:`text-sm`,children:n})]})]})}export{u as default};
@@ -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{Bn as r,It as i,L as a,Ot as o,Ur as s,X as c,fn as l,ii as u}from"./ui-Byg1cZDr.js";import{t as d}from"./utils-2pl1SbIp.js";import{t as f}from"./button-SgR3GVvV.js";import{c as p}from"./api-CA6WiiYM.js";import{t as m}from"./LinkToCard-nR7Lal_o.js";import{B as h,Pt as g,it as _,z as v}from"./workspace-DvxC7pw1.js";import{t as y}from"./useToastHelpers-CRrpIIdY.js";import{n as b}from"./LinkToSidePanel-eCy3nW4R.js";import{n as x}from"./page-header-DkOHw0g-.js";import{t as S}from"./use-settings-back-CQauYjQ4.js";var C=e(n(),1),w=`offline-content-v1`,T=`offline-api-v1`,E=1073741824,D={enabled:!1,budgetBytes:4*E,excludedWorkspaces:[]},O=1e3;function k(e){return(e.startsWith(`/`)?e:`/${e}`).replace(/\/+$/,``)||`/`}function A(e,t,n){return`${e}:${t}:${k(n)}`}var j=`canvas-offline`,M=2,N=null;function P(){return N||(N=new Promise((e,t)=>{let n=indexedDB.open(j,M);n.onupgradeneeded=e=>{let t=n.result;if(t.objectStoreNames.contains(`config`)||t.createObjectStore(`config`),t.objectStoreNames.contains(`entries`)||t.createObjectStore(`entries`,{keyPath:`url`}),e.oldVersion>=1&&t.objectStoreNames.contains(`pins`)){t.deleteObjectStore(`pins`);let e=n.transaction.objectStore(`entries`).openCursor();e.onsuccess=()=>{let t=e.result;if(!t)return;let n=t.value;n.pinned&&t.update({...n,pinned:!1}),t.continue()}}t.objectStoreNames.contains(`scopes`)||t.createObjectStore(`scopes`,{keyPath:`id`})},n.onsuccess=()=>{n.result.onversionchange=()=>{n.result.close(),N=null},e(n.result)},n.onerror=()=>{N=null,t(n.error)}}),N)}function F(e){return new Promise((t,n)=>{e.oncomplete=()=>t(),e.onerror=()=>n(e.error),e.onabort=()=>n(e.error)})}function I(e){return new Promise((t,n)=>{e.onsuccess=()=>t(e.result),e.onerror=()=>n(e.error)})}async function L(e,t){return I((await P()).transaction(e).objectStore(e).get(t))}async function R(e){return I((await P()).transaction(e).objectStore(e).getAll())}async function z(e,t,n){let r=(await P()).transaction(e,`readwrite`);return r.objectStore(e).put(t,n),F(r)}async function B(e,t){let n=(await P()).transaction(e,`readwrite`);return n.objectStore(e).delete(t),F(n)}async function V(e){let t=(await P()).transaction(e,`readwrite`);return t.objectStore(e).clear(),F(t)}async function H(){try{let e=await L(`config`,`settings`);return e?{...D,...e}:D}catch{return D}}async function U(e){await z(`config`,e,`settings`)}async function W(e,t){let n=(await P()).transaction(`entries`,`readwrite`),r=n.objectStore(`entries`);for(let n of e){let e=r.get(n);e.onsuccess=()=>{let i=e.result;i?r.put({...i,pinned:t}):t&&r.put({url:n,kind:`content`,size:0,lastAccess:Date.now(),pinned:t})}}return F(n)}async function ee(e){let t=await R(`entries`),n=t.filter(e=>e.kind===`api`).sort((e,t)=>e.lastAccess-t.lastAccess),r=n.slice(0,Math.max(0,n.length-O)),i=t.filter(e=>e.kind===`content`),a=i.reduce((e,t)=>e+t.size,0),o=i.filter(e=>!e.pinned).sort((e,t)=>e.lastAccess-t.lastAccess),s=[];for(let t of o){if(a<=e)break;s.push(t),a-=t.size}if(!r.length&&!s.length)return;let[c,l]=await Promise.all([caches.open(T),caches.open(w)]);await Promise.all([...r.map(async e=>{await c.delete(e.url),await B(`entries`,e.url)}),...s.map(async e=>{await l.delete(e.url),await B(`entries`,e.url)})])}async function te(){let e=await R(`entries`),t=e.filter(e=>e.kind===`content`);return{contentBytes:t.reduce((e,t)=>e+t.size,0),contentCount:t.length,pinnedBytes:t.filter(e=>e.pinned).reduce((e,t)=>e+t.size,0),apiCount:e.length-t.length}}async function ne(){await Promise.all([caches.delete(w),caches.delete(T)]),await V(`entries`),await V(`scopes`)}async function re(){return R(`scopes`)}async function ie(e){return L(`scopes`,e)}async function G(e){await z(`scopes`,e)}async function K(e){let t=await L(`scopes`,e);await B(`scopes`,e),t?.urls.length&&await q(t.urls)}async function q(e){let t=await R(`scopes`),n=new Set(t.flatMap(e=>e.urls)),r=e.filter(e=>!n.has(e));r.length&&await W(r,!1)}var J=3,ae=`data/schema/file`,Y=128;async function oe({workspaceRef:e,path:t,treeName:n,treeType:r},i){let a=await H();if(!a.enabled)throw Error(`Enable the offline cache first`);if(a.excludedWorkspaces.includes(e))throw Error(`Workspace "${e}" is excluded from offline caching`);let o=A(e,n,t),s=k(t),c=await ie(o),l=((await _(e,s,[],{limit:1e4,treeName:n,treeType:r})).payload??[]).filter(e=>e.schema===ae),u=[],d=0,f=0,m=!1,g=l.length;i?.({done:f,total:g,bytes:d});let y=0;await Promise.all(Array.from({length:Math.min(J,l.length)},async()=>{for(;y<l.length;){let t=l[y++];if(d>=a.budgetBytes*.9){m=!0;return}try{let{blob:n}=await v(e,t.id);d+=n.size,u.push(`${p.workspaces}/${e}/documents/${t.id}/content`);try{await h(e,t.id,Y),u.push(`${p.workspaces}/${e}/documents/${t.id}/thumbnail?size=${Y}`)}catch{}}catch{}f+=1,i?.({done:f,total:g,bytes:d})}})),await W(u,!0);let b={id:o,workspaceRef:e,treeName:n,treeType:r,path:s,urls:u,bytes:d,warmedAt:Date.now(),...m?{truncated:!0}:{}};if(await G(b),c){let e=new Set(u),t=c.urls.filter(t=>!e.has(t));t.length&&await q(t)}return b}var X=t(),Z=[{label:`1 GB`,bytes:1*E},{label:`2 GB`,bytes:2*E},{label:`4 GB`,bytes:4*E},{label:`8 GB`,bytes:8*E}];function Q(e){return e<1048576?`${(e/1024).toFixed(0)} KB`:e<1073741824?`${(e/1048576).toFixed(1)} MB`:`${(e/E).toFixed(2)} GB`}function se(){navigator.serviceWorker?.controller?.postMessage({type:`OFFLINE_SETTINGS_CHANGED`})}function ce(){let{showSuccessToast:e,showErrorToast:t}=y(),[n,p]=(0,C.useState)(null),[h,_]=(0,C.useState)(null),[v,x]=(0,C.useState)(null),[S,w]=(0,C.useState)([]),[T,E]=(0,C.useState)([]),[D,O]=(0,C.useState)({}),[k,j]=(0,C.useState)(!1),[M,N]=(0,C.useState)(!1),P=(0,C.useCallback)(()=>{H().then(p).catch(()=>{}),te().then(_).catch(()=>{}),re().then(e=>E(e.sort((e,t)=>e.id.localeCompare(t.id)))).catch(()=>{}),navigator.storage?.persisted?.().then(x).catch(()=>{})},[]);(0,C.useEffect)(()=>{P(),g().then(e=>w(e.map(e=>e.name).filter(Boolean).sort())).catch(()=>{})},[P]);let F=async e=>{p(e),await U(e),se(),e.enabled&&navigator.storage?.persist?.().then(x).catch(()=>{}),ee(e.budgetBytes).then(P).catch(()=>{})},I=e=>{if(!n)return;let t=n.excludedWorkspaces.includes(e)?n.excludedWorkspaces.filter(t=>t!==e):[...n.excludedWorkspaces,e];F({...n,excludedWorkspaces:t})},L=async()=>{j(!0);try{await ne(),e(`Offline cache cleared`),P()}catch(e){t(e instanceof Error?e.message:`Failed to clear cache`)}finally{j(!1)}},R=async n=>{let r=A(n.workspaceRef,n.treeName,n.path);O(e=>({...e,[r]:{done:0,total:0,bytes:0}}));try{let t=await oe(n,e=>O(t=>({...t,[r]:e})));e(t.truncated?`Pinned ${Q(t.bytes)} — stopped at the size budget`:`Pinned ${t.workspaceRef}:/${t.path} (${Q(t.bytes)})`)}catch(e){t(e instanceof Error?e.message:`Failed to pin`)}finally{O(e=>{let{[r]:t,...n}=e;return n}),P()}},z=(e,t)=>{N(!1);for(let n of e)R({workspaceRef:t.workspaceName,path:n,treeName:t.treeName,treeType:t.treeType})},B=e=>({workspaceRef:e.workspaceRef,path:e.path,treeName:e.treeName||`context`,treeType:e.treeType||`context`}),V=async e=>{await K(e),P()};return n?(0,X.jsxs)(`div`,{className:`space-y-8`,children:[(0,X.jsxs)(`section`,{children:[(0,X.jsx)($,{title:`Offline cache`,description:`Keep documents you open (and scopes you pin) readable without a connection. Cached on this device only; least-recently-used files are evicted when the size budget fills. Video streaming is not cached.`}),(0,X.jsxs)(`div`,{className:`flex flex-col gap-4`,children:[(0,X.jsxs)(`button`,{type:`button`,onClick:()=>F({...n,enabled:!n.enabled}),"aria-pressed":n.enabled,className:d(`focus-ring flex items-center gap-3 rounded-lg border p-4 text-left transition-colors`,n.enabled?`border-primary bg-accent`:`border-input hover:bg-muted/40`),children:[(0,X.jsx)(r,{className:`h-5 w-5 shrink-0 text-muted-foreground`}),(0,X.jsxs)(`span`,{className:`flex-1`,children:[(0,X.jsx)(`span`,{className:`block text-sm font-medium`,children:n.enabled?`Enabled`:`Disabled`}),(0,X.jsx)(`span`,{className:`block text-xs text-muted-foreground`,children:n.enabled?v===!1?`Storage is not persistent — the browser may still evict the cache under disk pressure`:`Documents are cached as you browse`:`Nothing is cached for offline use`})]}),n.enabled&&(0,X.jsx)(s,{className:`h-4 w-4 shrink-0 text-primary`})]}),n.enabled&&(0,X.jsxs)(X.Fragment,{children:[(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`p`,{className:`mb-2 text-sm font-medium`,children:`Size budget`}),(0,X.jsx)(`div`,{className:`flex flex-wrap gap-2`,children:Z.map(e=>(0,X.jsx)(f,{variant:n.budgetBytes===e.bytes?`default`:`outline`,size:`sm`,onClick:()=>F({...n,budgetBytes:e.bytes}),children:e.label},e.bytes))})]}),h&&(0,X.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,X.jsxs)(`div`,{className:`flex items-baseline justify-between text-sm`,children:[(0,X.jsxs)(`span`,{children:[Q(h.contentBytes),` of `,Q(n.budgetBytes),` used`]}),(0,X.jsxs)(`span`,{className:`text-xs text-muted-foreground`,children:[h.contentCount,` file(s)`,h.pinnedBytes>0?`, ${Q(h.pinnedBytes)} pinned`:``]})]}),(0,X.jsx)(`div`,{className:`h-2 w-full overflow-hidden rounded-full bg-muted`,children:(0,X.jsx)(`div`,{className:`h-full rounded-full bg-primary`,style:{width:`${Math.min(100,h.contentBytes/n.budgetBytes*100)}%`}})})]}),(0,X.jsx)(`div`,{children:(0,X.jsxs)(f,{variant:`outline`,size:`sm`,onClick:L,disabled:k,children:[k?(0,X.jsx)(l,{className:`mr-1.5 h-3.5 w-3.5 animate-spin`}):(0,X.jsx)(c,{className:`mr-1.5 h-3.5 w-3.5`}),`Clear offline cache`]})})]})]})]}),n.enabled&&(0,X.jsxs)(X.Fragment,{children:[(0,X.jsxs)(`section`,{children:[(0,X.jsx)($,{title:`Pinned scopes`,description:`A pinned scope — a workspace, or one of its tree paths — is downloaded up front and never evicted. Scopes resolve fresh on every re-warm, so moved contexts and reorganized trees are picked up; documents that left a scope return to normal eviction.`}),(0,X.jsx)(`div`,{className:`mb-3`,children:(0,X.jsxs)(f,{size:`sm`,onClick:()=>N(!0),disabled:!!Object.keys(D).length,children:[(0,X.jsx)(i,{className:`mr-1.5 h-3.5 w-3.5`}),`Pin a path…`]})}),(0,X.jsxs)(`ul`,{className:`space-y-1`,children:[T.map(e=>{let t=D[e.id];return(0,X.jsxs)(`li`,{className:`flex items-center gap-3 rounded-md border border-input px-3 py-2 text-sm`,children:[(0,X.jsxs)(`span`,{className:`flex-1 truncate font-mono text-xs sm:text-sm`,children:[e.workspaceRef,`://`,e.path.replace(/^\//,``),e.treeName&&e.treeName!==`context`&&(0,X.jsx)(`span`,{className:`ml-1.5 rounded bg-muted px-1 py-0.5 font-sans text-[10px] text-muted-foreground`,children:e.treeName})]}),t?(0,X.jsxs)(`span`,{className:`flex items-center gap-2 text-xs text-muted-foreground`,children:[(0,X.jsx)(l,{className:`h-3.5 w-3.5 animate-spin`}),t.total>0?`${t.done}/${t.total} · ${Q(t.bytes)}`:`listing…`]}):(0,X.jsxs)(X.Fragment,{children:[(0,X.jsxs)(`span`,{className:`text-xs text-muted-foreground`,children:[Q(e.bytes),e.truncated?` (partial)`:``]}),(0,X.jsx)(f,{variant:`ghost`,size:`sm`,onClick:()=>R(B(e)),"aria-label":`Re-warm ${e.id}`,title:`Re-warm: re-resolve the scope and download anything new`,children:(0,X.jsx)(o,{className:`h-3.5 w-3.5`})}),(0,X.jsx)(f,{variant:`ghost`,size:`sm`,onClick:()=>V(e.id),"aria-label":`Unpin ${e.id}`,children:(0,X.jsx)(a,{className:`h-3.5 w-3.5`})})]})]},e.id)}),T.length===0&&(0,X.jsx)(`li`,{className:`rounded-md border border-dashed border-input px-3 py-4 text-center text-sm text-muted-foreground`,children:`Nothing pinned — everything relies on browse-caching and LRU`})]})]}),(0,X.jsxs)(`section`,{children:[(0,X.jsx)($,{title:`Workspace caching`,description:`Excluded workspaces are never cached — not even as you browse — and are not served from cache.`}),(0,X.jsx)(`ul`,{className:`space-y-1`,children:S.map(e=>{let t=n.excludedWorkspaces.includes(e);return(0,X.jsxs)(`li`,{className:`flex items-center gap-3 rounded-md border border-input px-3 py-2 text-sm`,children:[(0,X.jsx)(`span`,{className:d(`flex-1 truncate`,t&&`text-muted-foreground line-through`),children:e}),t&&(0,X.jsx)(u,{className:`h-3.5 w-3.5 text-muted-foreground`}),(0,X.jsx)(f,{variant:t?`outline`:`ghost`,size:`sm`,onClick:()=>I(e),children:t?`Include`:`Exclude`})]},e)})})]})]}),M&&(0,X.jsx)(b,{onClose:()=>N(!1),children:(0,X.jsx)(m,{sizeClassName:`h-full w-[380px] max-w-[90vw] max-md:w-full`,multiple:!1,tabs:[`context`,`directory`],title:`Pin for offline…`,confirmLabel:`Pin path`,onConfirm:z,onClose:()=>N(!1)})})]}):null}function $({title:e,description:t}){return(0,X.jsxs)(`div`,{className:`mb-4`,children:[(0,X.jsx)(`h2`,{className:`text-base font-semibold`,children:e}),(0,X.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:t})]})}function le(){return(0,X.jsxs)(`div`,{className:`mx-auto max-w-4xl`,children:[(0,X.jsx)(x,{className:`mb-6`,title:`Offline`,onBack:S(),description:`Per-device offline cache: browse notes, files, photos and saved websites without a connection.`}),(0,X.jsx)(ce,{})]})}export{le 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{Bn as r,It as i,L as a,Ot as o,Ur as s,X as c,fn as l,ii as u}from"./ui-Byg1cZDr.js";import{t as d}from"./utils-2pl1SbIp.js";import{t as f}from"./button-SgR3GVvV.js";import{c as p}from"./api-CA6WiiYM.js";import{t as m}from"./LinkToCard-5dg0jvSY.js";import{B as h,Pt as g,it as _,z as v}from"./workspace-CrSpR4xf.js";import{t as y}from"./useToastHelpers-CRrpIIdY.js";import{n as b}from"./LinkToSidePanel-eCy3nW4R.js";import{n as x}from"./page-header-DkOHw0g-.js";import{t as S}from"./use-settings-back-CQauYjQ4.js";var C=e(n(),1),w=`offline-content-v1`,T=`offline-api-v1`,E=1073741824,D={enabled:!1,budgetBytes:4*E,excludedWorkspaces:[]},O=1e3;function k(e){return(e.startsWith(`/`)?e:`/${e}`).replace(/\/+$/,``)||`/`}function A(e,t,n){return`${e}:${t}:${k(n)}`}var j=`canvas-offline`,M=2,N=null;function P(){return N||(N=new Promise((e,t)=>{let n=indexedDB.open(j,M);n.onupgradeneeded=e=>{let t=n.result;if(t.objectStoreNames.contains(`config`)||t.createObjectStore(`config`),t.objectStoreNames.contains(`entries`)||t.createObjectStore(`entries`,{keyPath:`url`}),e.oldVersion>=1&&t.objectStoreNames.contains(`pins`)){t.deleteObjectStore(`pins`);let e=n.transaction.objectStore(`entries`).openCursor();e.onsuccess=()=>{let t=e.result;if(!t)return;let n=t.value;n.pinned&&t.update({...n,pinned:!1}),t.continue()}}t.objectStoreNames.contains(`scopes`)||t.createObjectStore(`scopes`,{keyPath:`id`})},n.onsuccess=()=>{n.result.onversionchange=()=>{n.result.close(),N=null},e(n.result)},n.onerror=()=>{N=null,t(n.error)}}),N)}function F(e){return new Promise((t,n)=>{e.oncomplete=()=>t(),e.onerror=()=>n(e.error),e.onabort=()=>n(e.error)})}function I(e){return new Promise((t,n)=>{e.onsuccess=()=>t(e.result),e.onerror=()=>n(e.error)})}async function L(e,t){return I((await P()).transaction(e).objectStore(e).get(t))}async function R(e){return I((await P()).transaction(e).objectStore(e).getAll())}async function z(e,t,n){let r=(await P()).transaction(e,`readwrite`);return r.objectStore(e).put(t,n),F(r)}async function B(e,t){let n=(await P()).transaction(e,`readwrite`);return n.objectStore(e).delete(t),F(n)}async function V(e){let t=(await P()).transaction(e,`readwrite`);return t.objectStore(e).clear(),F(t)}async function H(){try{let e=await L(`config`,`settings`);return e?{...D,...e}:D}catch{return D}}async function U(e){await z(`config`,e,`settings`)}async function W(e,t){let n=(await P()).transaction(`entries`,`readwrite`),r=n.objectStore(`entries`);for(let n of e){let e=r.get(n);e.onsuccess=()=>{let i=e.result;i?r.put({...i,pinned:t}):t&&r.put({url:n,kind:`content`,size:0,lastAccess:Date.now(),pinned:t})}}return F(n)}async function ee(e){let t=await R(`entries`),n=t.filter(e=>e.kind===`api`).sort((e,t)=>e.lastAccess-t.lastAccess),r=n.slice(0,Math.max(0,n.length-O)),i=t.filter(e=>e.kind===`content`),a=i.reduce((e,t)=>e+t.size,0),o=i.filter(e=>!e.pinned).sort((e,t)=>e.lastAccess-t.lastAccess),s=[];for(let t of o){if(a<=e)break;s.push(t),a-=t.size}if(!r.length&&!s.length)return;let[c,l]=await Promise.all([caches.open(T),caches.open(w)]);await Promise.all([...r.map(async e=>{await c.delete(e.url),await B(`entries`,e.url)}),...s.map(async e=>{await l.delete(e.url),await B(`entries`,e.url)})])}async function te(){let e=await R(`entries`),t=e.filter(e=>e.kind===`content`);return{contentBytes:t.reduce((e,t)=>e+t.size,0),contentCount:t.length,pinnedBytes:t.filter(e=>e.pinned).reduce((e,t)=>e+t.size,0),apiCount:e.length-t.length}}async function ne(){await Promise.all([caches.delete(w),caches.delete(T)]),await V(`entries`),await V(`scopes`)}async function re(){return R(`scopes`)}async function ie(e){return L(`scopes`,e)}async function G(e){await z(`scopes`,e)}async function K(e){let t=await L(`scopes`,e);await B(`scopes`,e),t?.urls.length&&await q(t.urls)}async function q(e){let t=await R(`scopes`),n=new Set(t.flatMap(e=>e.urls)),r=e.filter(e=>!n.has(e));r.length&&await W(r,!1)}var J=3,ae=`data/schema/file`,Y=128;async function oe({workspaceRef:e,path:t,treeName:n,treeType:r},i){let a=await H();if(!a.enabled)throw Error(`Enable the offline cache first`);if(a.excludedWorkspaces.includes(e))throw Error(`Workspace "${e}" is excluded from offline caching`);let o=A(e,n,t),s=k(t),c=await ie(o),l=((await _(e,s,[],{limit:1e4,treeName:n,treeType:r})).payload??[]).filter(e=>e.schema===ae),u=[],d=0,f=0,m=!1,g=l.length;i?.({done:f,total:g,bytes:d});let y=0;await Promise.all(Array.from({length:Math.min(J,l.length)},async()=>{for(;y<l.length;){let t=l[y++];if(d>=a.budgetBytes*.9){m=!0;return}try{let{blob:n}=await v(e,t.id);d+=n.size,u.push(`${p.workspaces}/${e}/documents/${t.id}/content`);try{await h(e,t.id,Y),u.push(`${p.workspaces}/${e}/documents/${t.id}/thumbnail?size=${Y}`)}catch{}}catch{}f+=1,i?.({done:f,total:g,bytes:d})}})),await W(u,!0);let b={id:o,workspaceRef:e,treeName:n,treeType:r,path:s,urls:u,bytes:d,warmedAt:Date.now(),...m?{truncated:!0}:{}};if(await G(b),c){let e=new Set(u),t=c.urls.filter(t=>!e.has(t));t.length&&await q(t)}return b}var X=t(),Z=[{label:`1 GB`,bytes:1*E},{label:`2 GB`,bytes:2*E},{label:`4 GB`,bytes:4*E},{label:`8 GB`,bytes:8*E}];function Q(e){return e<1048576?`${(e/1024).toFixed(0)} KB`:e<1073741824?`${(e/1048576).toFixed(1)} MB`:`${(e/E).toFixed(2)} GB`}function se(){navigator.serviceWorker?.controller?.postMessage({type:`OFFLINE_SETTINGS_CHANGED`})}function ce(){let{showSuccessToast:e,showErrorToast:t}=y(),[n,p]=(0,C.useState)(null),[h,_]=(0,C.useState)(null),[v,x]=(0,C.useState)(null),[S,w]=(0,C.useState)([]),[T,E]=(0,C.useState)([]),[D,O]=(0,C.useState)({}),[k,j]=(0,C.useState)(!1),[M,N]=(0,C.useState)(!1),P=(0,C.useCallback)(()=>{H().then(p).catch(()=>{}),te().then(_).catch(()=>{}),re().then(e=>E(e.sort((e,t)=>e.id.localeCompare(t.id)))).catch(()=>{}),navigator.storage?.persisted?.().then(x).catch(()=>{})},[]);(0,C.useEffect)(()=>{P(),g().then(e=>w(e.map(e=>e.name).filter(Boolean).sort())).catch(()=>{})},[P]);let F=async e=>{p(e),await U(e),se(),e.enabled&&navigator.storage?.persist?.().then(x).catch(()=>{}),ee(e.budgetBytes).then(P).catch(()=>{})},I=e=>{if(!n)return;let t=n.excludedWorkspaces.includes(e)?n.excludedWorkspaces.filter(t=>t!==e):[...n.excludedWorkspaces,e];F({...n,excludedWorkspaces:t})},L=async()=>{j(!0);try{await ne(),e(`Offline cache cleared`),P()}catch(e){t(e instanceof Error?e.message:`Failed to clear cache`)}finally{j(!1)}},R=async n=>{let r=A(n.workspaceRef,n.treeName,n.path);O(e=>({...e,[r]:{done:0,total:0,bytes:0}}));try{let t=await oe(n,e=>O(t=>({...t,[r]:e})));e(t.truncated?`Pinned ${Q(t.bytes)} — stopped at the size budget`:`Pinned ${t.workspaceRef}:/${t.path} (${Q(t.bytes)})`)}catch(e){t(e instanceof Error?e.message:`Failed to pin`)}finally{O(e=>{let{[r]:t,...n}=e;return n}),P()}},z=(e,t)=>{N(!1);for(let n of e)R({workspaceRef:t.workspaceName,path:n,treeName:t.treeName,treeType:t.treeType})},B=e=>({workspaceRef:e.workspaceRef,path:e.path,treeName:e.treeName||`context`,treeType:e.treeType||`context`}),V=async e=>{await K(e),P()};return n?(0,X.jsxs)(`div`,{className:`space-y-8`,children:[(0,X.jsxs)(`section`,{children:[(0,X.jsx)($,{title:`Offline cache`,description:`Keep documents you open (and scopes you pin) readable without a connection. Cached on this device only; least-recently-used files are evicted when the size budget fills. Video streaming is not cached.`}),(0,X.jsxs)(`div`,{className:`flex flex-col gap-4`,children:[(0,X.jsxs)(`button`,{type:`button`,onClick:()=>F({...n,enabled:!n.enabled}),"aria-pressed":n.enabled,className:d(`focus-ring flex items-center gap-3 rounded-lg border p-4 text-left transition-colors`,n.enabled?`border-primary bg-accent`:`border-input hover:bg-muted/40`),children:[(0,X.jsx)(r,{className:`h-5 w-5 shrink-0 text-muted-foreground`}),(0,X.jsxs)(`span`,{className:`flex-1`,children:[(0,X.jsx)(`span`,{className:`block text-sm font-medium`,children:n.enabled?`Enabled`:`Disabled`}),(0,X.jsx)(`span`,{className:`block text-xs text-muted-foreground`,children:n.enabled?v===!1?`Storage is not persistent — the browser may still evict the cache under disk pressure`:`Documents are cached as you browse`:`Nothing is cached for offline use`})]}),n.enabled&&(0,X.jsx)(s,{className:`h-4 w-4 shrink-0 text-primary`})]}),n.enabled&&(0,X.jsxs)(X.Fragment,{children:[(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`p`,{className:`mb-2 text-sm font-medium`,children:`Size budget`}),(0,X.jsx)(`div`,{className:`flex flex-wrap gap-2`,children:Z.map(e=>(0,X.jsx)(f,{variant:n.budgetBytes===e.bytes?`default`:`outline`,size:`sm`,onClick:()=>F({...n,budgetBytes:e.bytes}),children:e.label},e.bytes))})]}),h&&(0,X.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,X.jsxs)(`div`,{className:`flex items-baseline justify-between text-sm`,children:[(0,X.jsxs)(`span`,{children:[Q(h.contentBytes),` of `,Q(n.budgetBytes),` used`]}),(0,X.jsxs)(`span`,{className:`text-xs text-muted-foreground`,children:[h.contentCount,` file(s)`,h.pinnedBytes>0?`, ${Q(h.pinnedBytes)} pinned`:``]})]}),(0,X.jsx)(`div`,{className:`h-2 w-full overflow-hidden rounded-full bg-muted`,children:(0,X.jsx)(`div`,{className:`h-full rounded-full bg-primary`,style:{width:`${Math.min(100,h.contentBytes/n.budgetBytes*100)}%`}})})]}),(0,X.jsx)(`div`,{children:(0,X.jsxs)(f,{variant:`outline`,size:`sm`,onClick:L,disabled:k,children:[k?(0,X.jsx)(l,{className:`mr-1.5 h-3.5 w-3.5 animate-spin`}):(0,X.jsx)(c,{className:`mr-1.5 h-3.5 w-3.5`}),`Clear offline cache`]})})]})]})]}),n.enabled&&(0,X.jsxs)(X.Fragment,{children:[(0,X.jsxs)(`section`,{children:[(0,X.jsx)($,{title:`Pinned scopes`,description:`A pinned scope — a workspace, or one of its tree paths — is downloaded up front and never evicted. Scopes resolve fresh on every re-warm, so moved contexts and reorganized trees are picked up; documents that left a scope return to normal eviction.`}),(0,X.jsx)(`div`,{className:`mb-3`,children:(0,X.jsxs)(f,{size:`sm`,onClick:()=>N(!0),disabled:!!Object.keys(D).length,children:[(0,X.jsx)(i,{className:`mr-1.5 h-3.5 w-3.5`}),`Pin a path…`]})}),(0,X.jsxs)(`ul`,{className:`space-y-1`,children:[T.map(e=>{let t=D[e.id];return(0,X.jsxs)(`li`,{className:`flex items-center gap-3 rounded-md border border-input px-3 py-2 text-sm`,children:[(0,X.jsxs)(`span`,{className:`flex-1 truncate font-mono text-xs sm:text-sm`,children:[e.workspaceRef,`://`,e.path.replace(/^\//,``),e.treeName&&e.treeName!==`context`&&(0,X.jsx)(`span`,{className:`ml-1.5 rounded bg-muted px-1 py-0.5 font-sans text-[10px] text-muted-foreground`,children:e.treeName})]}),t?(0,X.jsxs)(`span`,{className:`flex items-center gap-2 text-xs text-muted-foreground`,children:[(0,X.jsx)(l,{className:`h-3.5 w-3.5 animate-spin`}),t.total>0?`${t.done}/${t.total} · ${Q(t.bytes)}`:`listing…`]}):(0,X.jsxs)(X.Fragment,{children:[(0,X.jsxs)(`span`,{className:`text-xs text-muted-foreground`,children:[Q(e.bytes),e.truncated?` (partial)`:``]}),(0,X.jsx)(f,{variant:`ghost`,size:`sm`,onClick:()=>R(B(e)),"aria-label":`Re-warm ${e.id}`,title:`Re-warm: re-resolve the scope and download anything new`,children:(0,X.jsx)(o,{className:`h-3.5 w-3.5`})}),(0,X.jsx)(f,{variant:`ghost`,size:`sm`,onClick:()=>V(e.id),"aria-label":`Unpin ${e.id}`,children:(0,X.jsx)(a,{className:`h-3.5 w-3.5`})})]})]},e.id)}),T.length===0&&(0,X.jsx)(`li`,{className:`rounded-md border border-dashed border-input px-3 py-4 text-center text-sm text-muted-foreground`,children:`Nothing pinned — everything relies on browse-caching and LRU`})]})]}),(0,X.jsxs)(`section`,{children:[(0,X.jsx)($,{title:`Workspace caching`,description:`Excluded workspaces are never cached — not even as you browse — and are not served from cache.`}),(0,X.jsx)(`ul`,{className:`space-y-1`,children:S.map(e=>{let t=n.excludedWorkspaces.includes(e);return(0,X.jsxs)(`li`,{className:`flex items-center gap-3 rounded-md border border-input px-3 py-2 text-sm`,children:[(0,X.jsx)(`span`,{className:d(`flex-1 truncate`,t&&`text-muted-foreground line-through`),children:e}),t&&(0,X.jsx)(u,{className:`h-3.5 w-3.5 text-muted-foreground`}),(0,X.jsx)(f,{variant:t?`outline`:`ghost`,size:`sm`,onClick:()=>I(e),children:t?`Include`:`Exclude`})]},e)})})]})]}),M&&(0,X.jsx)(b,{onClose:()=>N(!1),children:(0,X.jsx)(m,{sizeClassName:`h-full w-[380px] max-w-[90vw] max-md:w-full`,multiple:!1,tabs:[`context`,`directory`],title:`Pin for offline…`,confirmLabel:`Pin path`,onConfirm:z,onClose:()=>N(!1)})})]}):null}function $({title:e,description:t}){return(0,X.jsxs)(`div`,{className:`mb-4`,children:[(0,X.jsx)(`h2`,{className:`text-base font-semibold`,children:e}),(0,X.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:t})]})}function le(){return(0,X.jsxs)(`div`,{className:`mx-auto max-w-4xl`,children:[(0,X.jsx)(x,{className:`mb-6`,title:`Offline`,onBack:S(),description:`Per-device offline cache: browse notes, files, photos and saved websites without a connection.`}),(0,X.jsx)(ce,{})]})}export{le as default};
@@ -1 +1 @@
1
- import{o as e}from"./rolldown-runtime-C0FnF6B9.js";import{u as t}from"./code-editor-BOIngd5F.js";import{l as n}from"./api-CA6WiiYM.js";import{B as r,M as i,N as a,rn as o,z as s}from"./workspace-DvxC7pw1.js";var c=e(t(),1),l=(0,c.createContext)(null);function u(){return(0,c.useContext)(l)}function d(e,t,r={}){let i=new URLSearchParams;r.download&&i.set(`download`,`1`),r.url&&i.set(`url`,r.url),r.format&&i.set(`format`,r.format),r.version&&i.set(`v`,r.version);let a=i.toString();return`${n}/pub/c/${encodeURIComponent(e)}/documents/${t}/content${a?`?${a}`:``}`}async function f(e,t,r=256){let i=await fetch(`${n}/pub/c/${encodeURIComponent(e)}/documents/${t}/thumbnail?size=${r}`);if(!i.ok)throw Error(`HTTP ${i.status}`);let a=i.headers.get(`content-type`)||`image/webp`;return{blob:await i.blob(),mime:a}}async function p(e,t,n={}){let r=await fetch(d(e,t,n),{signal:n.signal});if(!r.ok)throw Error(`HTTP ${r.status}`);let i=r.headers.get(`content-type`)||`application/octet-stream`;return{blob:await r.blob(),mime:i}}async function m(e,t,n,r={}){let{blob:i}=await p(e,t,{...r}),a=URL.createObjectURL(i),o=document.createElement(`a`);o.href=a,o.download=n,document.body.appendChild(o),o.click(),o.remove(),setTimeout(()=>URL.revokeObjectURL(a),3e4)}function h(e){let t=u();return(0,c.useMemo)(()=>({isPublic:t!=null,fetchBlob:(n,r={})=>t?p(t,n,r):s(e,n,r),fetchThumbnail:(n,i=256,a)=>t?f(t,n,i):r(e,n,i,a),download:(n,r,i={})=>t?m(t,n,r,i):a(e,n,r,i),streamUrl:(n,r={})=>t?d(t,n,r):i(e,n,r),mintTicket:n=>t?Promise.resolve(!0):o(e,n)}),[e,t])}export{u as i,d as n,h as r,l as t};
1
+ import{o as e}from"./rolldown-runtime-C0FnF6B9.js";import{u as t}from"./code-editor-BOIngd5F.js";import{l as n}from"./api-CA6WiiYM.js";import{$t as r,B as i,M as a,N as o,z as s}from"./workspace-CrSpR4xf.js";var c=e(t(),1),l=(0,c.createContext)(null);function u(){return(0,c.useContext)(l)}function d(e,t,r={}){let i=new URLSearchParams;r.download&&i.set(`download`,`1`),r.url&&i.set(`url`,r.url),r.format&&i.set(`format`,r.format),r.version&&i.set(`v`,r.version);let a=i.toString();return`${n}/pub/c/${encodeURIComponent(e)}/documents/${t}/content${a?`?${a}`:``}`}async function f(e,t,r=256){let i=await fetch(`${n}/pub/c/${encodeURIComponent(e)}/documents/${t}/thumbnail?size=${r}`);if(!i.ok)throw Error(`HTTP ${i.status}`);let a=i.headers.get(`content-type`)||`image/webp`;return{blob:await i.blob(),mime:a}}async function p(e,t,n={}){let r=await fetch(d(e,t,n),{signal:n.signal});if(!r.ok)throw Error(`HTTP ${r.status}`);let i=r.headers.get(`content-type`)||`application/octet-stream`;return{blob:await r.blob(),mime:i}}async function m(e,t,n,r={}){let{blob:i}=await p(e,t,{...r}),a=URL.createObjectURL(i),o=document.createElement(`a`);o.href=a,o.download=n,document.body.appendChild(o),o.click(),o.remove(),setTimeout(()=>URL.revokeObjectURL(a),3e4)}function h(e){let t=u();return(0,c.useMemo)(()=>({isPublic:t!=null,fetchBlob:(n,r={})=>t?p(t,n,r):s(e,n,r),fetchThumbnail:(n,r=256,a)=>t?f(t,n,r):i(e,n,r,a),download:(n,r,i={})=>t?m(t,n,r,i):o(e,n,r,i),streamUrl:(n,r={})=>t?d(t,n,r):a(e,n,r),mintTicket:n=>t?Promise.resolve(!0):r(e,n)}),[e,t])}export{u as i,d as n,h as r,l as t};
@@ -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{Gn as r,Ot as i,Tt as a,X as o,hr as s,ir as c}from"./ui-Byg1cZDr.js";import{t as l}from"./button-SgR3GVvV.js";import{t as u}from"./input-BOtCd4HP.js";import{t as d}from"./api-CA6WiiYM.js";import{n as f}from"./use-toast-BlLDqSUO.js";import{h as p,o as m,s as h}from"./LinkToCard-nR7Lal_o.js";import{$ as g,I as _,Pn as v,Sn as y,St as b,bt as x,gt as S,in as C}from"./workspace-DvxC7pw1.js";import{a as w,c as T,l as E,n as D,o as O,r as k,u as A}from"./backend-sync-progress-H4Zch25P.js";import{t as j}from"./workspace-access-C9nZlBBZ.js";var M=e(n(),1),N={membership:`keep`,propagation:`never`,targets:[],acceptPropagatedDeletions:!1},P=e=>`/workspaces/${encodeURIComponent(e)}/trash/operations`,F=(e,t)=>d.get(`${P(e)}?${new URLSearchParams(Object.entries(t).map(([e,t])=>[e,String(t)]))}`),I=(e,t,n,r={})=>d.post(`${P(e)}/${n}`,{ids:t,...r}),L=(e,t,n,r)=>d.patch(`/workspaces/${encodeURIComponent(e)}/backends/imap/${encodeURIComponent(t)}/containers/${encodeURIComponent(n)}`,{removalPolicy:r}),R=t();function z(e){let t=T(`backends`,e.path)?.backend;return(0,R.jsx)(B,{...e},JSON.stringify([e.workspace,t]))}function B({workspace:e,path:t,onNavigate:n}){let l=T(`backends`,t),u=l.backend,d=l.prefix,[f,g]=(0,M.useState)(null),[_,v]=(0,M.useState)(null),y=(0,M.useRef)(!1),[b,S]=(0,M.useState)(null),[C,j]=(0,M.useState)(null),[N,P]=(0,M.useState)(0),[F,I]=(0,M.useState)(new Set),[L,z]=(0,M.useState)(null),B=(0,M.useCallback)(()=>P(e=>e+1),[]),[V,H]=(0,M.useState)(t);V!==t&&(H(t),I(new Set),z(null),j(null),S(null));let U=f?.revision!==N,W=U?[]:f.items,G=U?[]:f.backends,K=f?.days;(0,M.useEffect)(()=>{let t=!1;return(u?w(e,u).then(e=>({...e,backends:[]})):x(e).then(e=>({items:[],days:null,backends:e.filter(e=>e.driver===`file`&&e.enabled!==!1)}))).then(e=>{t||g({...e,revision:N,error:null})}).catch(e=>{t||g({revision:N,items:[],backends:[],days:null,error:e instanceof Error?e.message:String(e)})}),()=>{t=!0}},[e,u,N]),(0,M.useEffect)(()=>{let t=null,n=n=>{let r=n.detail;r?.workspaceName&&r.workspaceName!==e||r?.treeName&&r.treeName!==`backends`||(t||=setTimeout(()=>{t=null,B()},500))};return window.addEventListener(`workspace:trash:refresh`,n),window.addEventListener(`workspace:tree:refresh`,n),()=>{window.removeEventListener(`workspace:trash:refresh`,n),window.removeEventListener(`workspace:tree:refresh`,n),t&&clearTimeout(t)}},[e,B]);let q=A(W,d),J=async(t,n)=>{if(!(!u||y.current||U||!n.length)&&!(t===`discard`&&!D(u,n))){y.current=!0,v(t),S(null),j(null),z(null);try{let r=await(t===`restore`?O:k)(e,u,[...n].sort((e,t)=>t.deletedAt-e.deletedAt).map(e=>e.id)),i=r.filter(e=>!e.ok);j(`${r.length-i.length} item(s) ${t===`restore`?`restored to their original paths`:`permanently deleted`}.`),i.length&&S(`${i.length} item(s) remain in Trash. ${i.slice(0,3).map(e=>`${e.key||`Item`}: ${e.reason===`precondition-failed`||e.reason===`target-exists`?`original path is occupied`:e.message||e.reason}`).join(`; `)}`),I(new Set)}catch(e){S(e instanceof Error?e.message:String(e))}finally{y.current=!1,v(null),B()}}},Y=(e,t,n)=>z({x:e,y:t,row:n});return(0,R.jsxs)(`section`,{className:`flex h-full min-h-0 flex-col bg-background`,"aria-label":`Backend Trash`,children:[(0,R.jsxs)(`div`,{className:`flex min-w-0 flex-wrap items-center gap-2 border-b px-4 py-3`,children:[(0,R.jsx)(o,{className:`h-4 w-4 shrink-0 text-muted-foreground`}),(0,R.jsx)(h,{items:m(t,e).map((e,t)=>t===2&&u?{...e,label:u}:e),onNavigate:n,className:`basis-48`}),(0,R.jsxs)(`div`,{className:`ml-auto flex max-w-full flex-wrap items-center gap-2`,children:[F.size>0&&(0,R.jsxs)(R.Fragment,{children:[(0,R.jsxs)(`button`,{className:`flex items-center gap-1 rounded border px-2 py-1 text-sm disabled:opacity-50`,disabled:!!_||U,onClick:()=>void J(`restore`,q.filter(e=>F.has(e.id)).flatMap(e=>e.items)),children:[(0,R.jsx)(a,{className:`h-3.5 w-3.5`}),`Restore selected`]}),(0,R.jsxs)(`button`,{className:`flex items-center gap-1 rounded border px-2 py-1 text-sm text-destructive disabled:opacity-50`,disabled:!!_||U,onClick:()=>void J(`discard`,q.filter(e=>F.has(e.id)).flatMap(e=>e.items)),children:[(0,R.jsx)(o,{className:`h-3.5 w-3.5`}),`Delete selected`]})]}),u&&q.length>0&&(0,R.jsxs)(`button`,{className:`flex items-center gap-1 rounded border px-2 py-1 text-sm text-destructive disabled:opacity-50`,disabled:!!_||U,onClick:()=>void J(`discard`,q.flatMap(e=>e.items)),children:[(0,R.jsx)(o,{className:`h-3.5 w-3.5`}),d?`Empty this folder`:`Empty Trash`]}),(0,R.jsx)(`button`,{title:`Refresh Trash`,"aria-label":`Refresh Trash`,className:`rounded p-2 hover:bg-accent`,disabled:!!_||U,onClick:B,children:(0,R.jsx)(i,{className:`h-4 w-4 ${U?`animate-spin`:``}`})})]})]}),(0,R.jsxs)(`div`,{className:`border-b px-4 py-2 text-xs text-muted-foreground`,children:[`Restore files and folders to their original paths. Existing files are kept.`,K?` Deleted items are kept for ${K} days.`:``]}),C&&(0,R.jsx)(`p`,{role:`status`,className:`px-4 py-2 text-sm`,children:C}),(b||f?.error)&&(0,R.jsx)(`p`,{role:`alert`,className:`px-4 py-2 text-sm text-destructive`,children:b||f?.error}),_&&(0,R.jsx)(`p`,{role:`status`,className:`px-4 py-2 text-sm`,children:_===`restore`?`Restoring…`:`Deleting permanently…`}),(0,R.jsx)(`div`,{className:`min-h-0 flex-1 overflow-auto p-3`,children:U?(0,R.jsx)(`p`,{className:`p-4 text-sm text-muted-foreground`,children:`Loading Trash…`}):u?q.length===0?(0,R.jsx)(`p`,{className:`p-4 text-sm text-muted-foreground`,children:`This Trash folder is empty.`}):(0,R.jsxs)(`table`,{className:`w-full text-left text-sm`,children:[(0,R.jsx)(`thead`,{className:`border-b text-xs text-muted-foreground`,children:(0,R.jsxs)(`tr`,{children:[(0,R.jsx)(`th`,{className:`w-8 p-2`,children:(0,R.jsx)(`input`,{type:`checkbox`,"aria-label":`Select all visible items`,checked:q.length>0&&q.every(e=>F.has(e.id)),onChange:e=>I(e.target.checked?new Set(q.map(e=>e.id)):new Set)})}),(0,R.jsx)(`th`,{className:`p-2`,children:`Name`}),(0,R.jsx)(`th`,{className:`p-2 max-sm:hidden`,children:`Original path`}),(0,R.jsx)(`th`,{className:`p-2 max-md:hidden`,children:`Deleted`}),(0,R.jsx)(`th`,{className:`p-2`,children:(0,R.jsx)(`span`,{className:`sr-only`,children:`Actions`})})]})}),(0,R.jsx)(`tbody`,{children:q.map(e=>(0,R.jsxs)(`tr`,{className:`border-b border-border/50 hover:bg-accent/50`,onContextMenu:t=>{t.preventDefault(),Y(t.clientX,t.clientY,e)},onDoubleClick:()=>e.navigable&&n(E(u,e.key)),children:[(0,R.jsx)(`td`,{className:`p-2`,children:(0,R.jsx)(`input`,{type:`checkbox`,"aria-label":`Select ${e.name}`,checked:F.has(e.id),disabled:!!_,onChange:t=>I(n=>{let r=new Set(n);return t.target.checked?r.add(e.id):r.delete(e.id),r})})}),(0,R.jsx)(`td`,{className:`p-2`,children:(0,R.jsxs)(`button`,{className:`flex items-center gap-2 text-left`,onClick:()=>e.navigable&&n(E(u,e.key)),children:[e.directory?(0,R.jsx)(r,{className:`h-4 w-4 shrink-0`}):(0,R.jsx)(c,{className:`h-4 w-4 shrink-0`}),(0,R.jsxs)(`span`,{children:[e.name,e.navigable&&(0,R.jsxs)(`span`,{className:`ml-2 text-xs text-muted-foreground`,children:[e.items.length,` items`]})]})]})}),(0,R.jsx)(`td`,{className:`p-2 text-xs text-muted-foreground max-sm:hidden`,children:e.key}),(0,R.jsx)(`td`,{className:`p-2 text-xs text-muted-foreground max-md:hidden`,children:new Date(e.items.reduce((e,t)=>Math.max(e,t.deletedAt),0)).toLocaleString()}),(0,R.jsx)(`td`,{className:`p-2 text-right`,children:(0,R.jsx)(`button`,{title:`Actions for ${e.name}`,"aria-label":`Actions for ${e.name}`,disabled:!!_,className:`rounded p-2 hover:bg-accent`,onClick:t=>Y(t.clientX,t.clientY,e),children:(0,R.jsx)(s,{className:`h-4 w-4`})})})]},e.id))})]}):(0,R.jsxs)(`div`,{className:`grid gap-2 sm:grid-cols-2 lg:grid-cols-3`,children:[G.map(e=>(0,R.jsxs)(`button`,{onClick:()=>n(E(e.address)),className:`flex items-center gap-3 rounded-lg border p-4 text-left hover:bg-accent`,children:[(0,R.jsx)(o,{className:`h-6 w-6 text-muted-foreground`}),(0,R.jsxs)(`span`,{children:[(0,R.jsx)(`span`,{className:`block text-sm font-medium`,children:e.label||e.address}),(0,R.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:e.address})]})]},e.address)),!G.length&&(0,R.jsx)(`p`,{className:`p-4 text-sm text-muted-foreground`,children:`No file backends are available.`})]})}),L&&(0,R.jsxs)(p,{x:L.x,y:L.y,onClose:()=>z(null),className:`min-w-44 rounded-md border bg-popover p-1 shadow-elevation-3`,children:[L.row.navigable&&(0,R.jsxs)(`button`,{className:`flex w-full items-center gap-2 rounded px-3 py-2 text-sm hover:bg-accent`,onClick:()=>{n(E(u,L.row.key)),z(null)},children:[(0,R.jsx)(r,{className:`h-4 w-4`}),`Open folder`]}),(0,R.jsxs)(`button`,{disabled:!!_,className:`flex w-full items-center gap-2 rounded px-3 py-2 text-sm hover:bg-accent disabled:opacity-50`,onClick:()=>void J(`restore`,L.row.items),children:[(0,R.jsx)(a,{className:`h-4 w-4`}),`Restore `,L.row.directory?`folder`:`file`]}),(0,R.jsxs)(`button`,{disabled:!!_||U,className:`flex w-full items-center gap-2 rounded px-3 py-2 text-sm text-destructive hover:bg-destructive/10 disabled:opacity-50`,onClick:()=>void J(`discard`,L.row.items),children:[(0,R.jsx)(o,{className:`h-4 w-4`}),`Delete permanently`]})]})]})}function V({value:e,backends:t,source:n,onSave:r,destination:i=!0}){let[a,o]=(0,M.useState)({...N,...e}),[s,c]=(0,M.useState)(!1),[u,d]=(0,M.useState)(``),f=`rounded border bg-background px-2 py-1.5 text-xs w-full`,p=async()=>{c(!0),d(``);try{await r(a),d(`Removal policy saved.`)}catch(e){d(e instanceof Error?e.message:`Could not save policy`)}finally{c(!1)}};return(0,R.jsxs)(`details`,{className:`border-t pt-3 text-xs`,children:[(0,R.jsx)(`summary`,{className:`cursor-pointer font-medium`,children:`Source removals and Trash`}),(0,R.jsxs)(`div`,{className:`mt-3 space-y-3`,children:[(0,R.jsx)(`p`,{className:`text-muted-foreground`,children:`A completed scan removes missing locations from the backend tree. Items with no remaining locations go to Trash until you purge them.`}),(0,R.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[(0,R.jsxs)(`label`,{className:`space-y-1 block`,children:[`When an item disappears from this source`,(0,R.jsxs)(`select`,{className:f,value:a.membership,disabled:s,onChange:e=>o({...a,membership:e.target.value}),children:[(0,R.jsx)(`option`,{value:`keep`,children:`Keep in managed trees`}),(0,R.jsx)(`option`,{value:`review`,children:`Review removal in Trash`}),(0,R.jsx)(`option`,{value:`trash`,children:`Move to Trash automatically`})]})]}),(0,R.jsxs)(`label`,{className:`space-y-1 block`,children:[`Remove tracked copies from other backends`,(0,R.jsxs)(`select`,{className:f,value:a.propagation,disabled:s,onChange:e=>o({...a,propagation:e.target.value}),children:[(0,R.jsx)(`option`,{value:`never`,children:`Never`}),(0,R.jsx)(`option`,{value:`review`,children:`Review in Trash`}),(0,R.jsx)(`option`,{value:`automatic`,children:`Automatically, retaining recovery copies`})]})]})]}),a.propagation!==`never`&&(0,R.jsxs)(`fieldset`,{className:`space-y-2`,children:[(0,R.jsx)(`legend`,{className:`mb-1 font-medium`,children:`Destinations`}),(0,R.jsxs)(`label`,{className:`flex items-center gap-2`,children:[(0,R.jsx)(`input`,{type:`checkbox`,checked:a.targets===`all`,disabled:s,onChange:e=>o({...a,targets:e.target.checked?`all`:[]})}),`All eligible backends`]}),a.targets!==`all`&&t.filter(e=>e.address!==n&&e.kind===`storage`).map(e=>(0,R.jsxs)(`label`,{className:`flex items-center gap-2`,children:[(0,R.jsx)(`input`,{type:`checkbox`,disabled:s||e.config?.propagatedRemovalSupported!==!0,checked:a.targets.includes(e.address),onChange:t=>o({...a,targets:t.target.checked?[...a.targets,e.address]:a.targets.filter(t=>t!==e.address)})}),String(e.config?.label||e.address),e.config?.propagatedRemovalSupported===!0?!e.config?.removalPolicy?.acceptPropagatedDeletions&&` · protected`:` · recovery removal unavailable`]},e.address)),(0,R.jsx)(`p`,{className:`text-muted-foreground`,children:`Only tracked, Canvas-owned copies are eligible. Protected destinations refuse propagated deletion. Recovery removal currently supports filesystem and workspace blob storage; remote destinations remain protected.`})]}),i&&(0,R.jsxs)(`label`,{className:`flex items-center gap-2`,children:[(0,R.jsx)(`input`,{type:`checkbox`,disabled:s,checked:a.acceptPropagatedDeletions,onChange:e=>o({...a,acceptPropagatedDeletions:e.target.checked})}),`Accept propagated deletions on this backend`]}),(0,R.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,R.jsx)(l,{size:`sm`,variant:`outline`,disabled:s,onClick:()=>void p(),children:s?`Saving…`:`Save removal policy`}),(0,R.jsx)(`span`,{role:`status`,children:u})]})]})]})}function H({workspaceName:e,canWrite:t}){let{showToast:n}=f(),[r,s]=(0,M.useState)([]),[c,u]=(0,M.useState)(!1),[d,p]=(0,M.useState)([]),[m,h]=(0,M.useState)(!1),g=(0,M.useCallback)(async()=>{u(!0);try{s(await b(e))}catch(e){n({title:`Error`,description:e instanceof Error?e.message:`Failed to load the trash`,variant:`destructive`})}finally{u(!1)}},[e]);(0,M.useEffect)(()=>{g()},[g]);let y=(0,M.useCallback)(e=>d.includes(e),[d]),x=async(e,t)=>{p(t=>[...t,...e]);try{await t()}finally{p(t=>t.filter(t=>!e.includes(t)))}},S=t=>x([t.id],async()=>{try{let r=await C(e,[t.id]);r.failed?.length?n({title:`Not restored`,description:r.failed[0]?.error||`No restore target recorded`,variant:`destructive`}):(n({title:`Restored`,description:`Document put back where it was.`}),s(e=>e.filter(e=>e.id!==t.id)))}catch(e){n({title:`Error`,description:e instanceof Error?e.message:`Failed to restore`,variant:`destructive`})}}),w=t=>x([t.id],async()=>{try{let r=await _(e,[t.id]);if(r.failed?.length)throw Error(`The item could not be purged. Refresh and retry.`);n({title:`Cleared from Trash`,description:r.preserved?.length?`Existing backend copies remain indexed.`:`Document permanently deleted.`}),s(e=>e.filter(e=>e.id!==t.id))}catch(e){n({title:`Error`,description:e instanceof Error?e.message:`Failed to delete`,variant:`destructive`})}}),T=async()=>{if(!m){h(!0);return}h(!1);try{let t=await _(e);n({title:`Trash emptied`,description:`${t.destroyed?.length??0} document(s) purged. ${t.preserved?.length??0} item(s) cleared with backend copies preserved.`}),await g()}catch(e){n({title:`Error`,description:e instanceof Error?e.message:`Failed to empty the trash`,variant:`destructive`})}},E=(0,M.useMemo)(()=>r.map(e=>{let t=v(e),n=(e.trashed?.placements??[]).flatMap(e=>e.paths.map(t=>`${e.tree}:${t}`));return{document:e,title:t.title,origin:n,trashedAt:e.trashed?.trashedAt||null}}),[r]);return(0,R.jsxs)(`div`,{className:`space-y-4`,children:[(0,R.jsxs)(`div`,{className:`flex flex-col gap-2 sm:flex-row sm:items-start sm:justify-between sm:gap-4`,children:[(0,R.jsxs)(`div`,{children:[(0,R.jsx)(`h2`,{className:`text-sm font-medium`,children:`Managed-tree items`}),(0,R.jsx)(`p`,{className:`text-xs text-muted-foreground mt-1 max-w-2xl`,children:`Restore managed-tree placements or permanently purge these items. Pending removals require separate approval. Backend copies are managed below.`})]}),(0,R.jsxs)(`div`,{className:`flex shrink-0 items-center gap-2 max-sm:flex-wrap`,children:[(0,R.jsxs)(l,{variant:`outline`,size:`sm`,onClick:()=>g(),disabled:c,children:[(0,R.jsx)(i,{className:`mr-2 h-3.5 w-3.5 ${c?`animate-spin`:``}`}),`Refresh`]}),(0,R.jsxs)(l,{variant:m?`destructive`:`outline`,size:`sm`,onClick:T,onBlur:()=>h(!1),disabled:!t||r.length===0,children:[(0,R.jsx)(o,{className:`mr-2 h-3.5 w-3.5`}),m?`Click again to delete everything`:`Empty trash`]})]})]}),c&&r.length===0&&(0,R.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`Loading…`}),!c&&r.length===0&&(0,R.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`The trash is empty.`}),E.length>0&&(0,R.jsx)(`div`,{className:`border rounded-md divide-y`,children:E.map(({document:e,title:n,origin:r,trashedAt:i})=>(0,R.jsxs)(`div`,{className:`flex items-center gap-3 px-3 py-2`,children:[(0,R.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,R.jsx)(`div`,{className:`truncate text-sm`,children:n}),(0,R.jsxs)(`div`,{className:`truncate text-xs text-muted-foreground`,children:[r.length>0?`from ${r.join(`, `)}`:`no recorded origin`,i?` · ${new Date(i).toLocaleString()}`:``]})]}),(0,R.jsxs)(l,{variant:`outline`,size:`sm`,onClick:()=>S(e),disabled:!t||y(e.id)||r.length===0,title:r.length===0?`Nothing recorded to restore to`:`Put it back where it was`,children:[(0,R.jsx)(a,{className:`mr-2 h-3.5 w-3.5`}),`Restore placements`]}),(0,R.jsx)(l,{variant:`ghost`,size:`sm`,onClick:()=>w(e),disabled:!t||y(e.id),title:`Delete permanently`,children:(0,R.jsx)(o,{className:`h-3.5 w-3.5`})})]},e.id))})]})}function U({workspaceName:e}){return(0,R.jsx)(W,{workspaceName:e},e)}function W({workspaceName:e}){let[t,n]=(0,M.useState)(`pending`),[r,a]=(0,M.useState)(``),[o,s]=(0,M.useState)(``),[c,d]=(0,M.useState)(0),[f,p]=(0,M.useState)(0),[m,h]=(0,M.useState)(null),[_,v]=(0,M.useState)(``),[b,C]=(0,M.useState)(!1),[w,T]=(0,M.useState)(new Set),[E,D]=(0,M.useState)({}),[O,k]=(0,M.useState)(`/Trash`),[A,P]=(0,M.useState)([]),[B,U]=(0,M.useState)({write:!1,admin:!1});(0,M.useEffect)(()=>{let t=!0;return g(e).then(e=>{let n=e.remote?.permissions||e.access?.permissions||(typeof e.sharedVia==`object`?e.sharedVia?.permissions:[])||[],r=j(e);t&&U({admin:r,write:r||n.includes(`write`)})}).catch(()=>{}),()=>{t=!1}},[e]);let[W,G]=(0,M.useState)(null);(0,M.useEffect)(()=>{let t=!0;return x(e).then(e=>{t&&P(e)}).catch(()=>{}),()=>{t=!1}},[e]),(0,M.useEffect)(()=>{let n=!1,i=()=>F(e,{view:t,search:r,...o?{backend:o}:{},offset:c}).then(e=>{n||(h(e),v(``))}).catch(e=>{n||v(e instanceof Error?e.message:`Could not load Trash`)});i();let a=setInterval(()=>{b||i()},5e3);return()=>{n=!0,clearInterval(a)}},[e,t,r,o,c,f,b]);let K=m?.operations||[],q=()=>{T(new Set),p(e=>e+1)},J=()=>{S(e),window.dispatchEvent(new CustomEvent(`workspace:tree:refresh`,{detail:{workspaceName:e}})),window.dispatchEvent(new CustomEvent(`workspace:trash:refresh`,{detail:{workspaceName:e}}))},Y=async(t,n=[...w])=>{if(!(!n.length||b)&&!(t===`purge`&&!window.confirm(`Permanently delete retained recovery copies for ${n.length} operation(s)?`))){C(!0),v(``);try{let r=(t===`approve`?(await Promise.all(n.map(n=>I(e,[n],t,E[n])))).flatMap(e=>e.results):(await I(e,n,t)).results).filter(e=>!e.ok||e.operation?.state===`failed`);r.length&&v(r.map(e=>e.error||e.operation?.error||`A destination could not be changed. Expand the item for details.`).join(` `)),J(),q()}catch(e){v(e instanceof Error?e.message:`Trash action failed`)}finally{C(!1)}}},X=e=>{n(e),d(0),h(null),T(new Set),D({})};return(0,R.jsxs)(`div`,{className:`space-y-4`,children:[(0,R.jsxs)(`div`,{children:[(0,R.jsx)(`h2`,{className:`text-base font-semibold`,children:`Workspace Trash`}),(0,R.jsx)(`p`,{className:`text-xs text-muted-foreground mt-1`,children:`Review source removals, recover items, and see what automatic policies changed.`})]}),(0,R.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,role:`tablist`,"aria-label":`Trash views`,children:[[[`pending`,`Pending removal`],[`trashed`,`In Trash`],[`activity`,`Activity`]].map(([e,n])=>(0,R.jsx)(l,{role:`tab`,"aria-selected":t===e,size:`sm`,variant:t===e?`default`:`outline`,onClick:()=>X(e),children:n},e)),(0,R.jsxs)(l,{size:`sm`,variant:`ghost`,className:`ml-auto`,onClick:q,disabled:b,children:[(0,R.jsx)(i,{className:`mr-2 h-3.5 w-3.5`}),`Refresh`]})]}),t===`trashed`&&(0,R.jsxs)(R.Fragment,{children:[(0,R.jsx)(H,{workspaceName:e,canWrite:B.write},f),(0,R.jsxs)(`details`,{className:`rounded border p-3`,children:[(0,R.jsx)(`summary`,{className:`cursor-pointer text-sm font-medium`,children:`Browse backend recovery copies`}),(0,R.jsx)(`div`,{className:`mt-3 min-h-48`,children:(0,R.jsx)(z,{workspace:e,path:O,onNavigate:k})})]})]}),(0,R.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[(0,R.jsx)(u,{"aria-label":`Filter Trash items`,placeholder:`Filter by item or path…`,className:`max-w-xs`,value:r,onChange:e=>{a(e.target.value),h(null),d(0),T(new Set)}}),(0,R.jsx)(u,{"aria-label":`Filter by backend`,placeholder:`Backend name…`,className:`max-w-56`,value:o,onChange:e=>{s(e.target.value),h(null),d(0),T(new Set)}}),w.size>0&&(0,R.jsxs)(`div`,{className:`flex items-center gap-2 text-xs`,children:[(0,R.jsxs)(`span`,{children:[w.size,` selected`]}),t===`pending`&&(0,R.jsxs)(R.Fragment,{children:[(0,R.jsx)(l,{size:`sm`,disabled:b,onClick:()=>void Y(`approve`),children:`Approve selected`}),(0,R.jsx)(l,{size:`sm`,variant:`outline`,disabled:b,onClick:()=>void Y(`keep`),children:`Keep selected`}),(0,R.jsx)(l,{size:`sm`,variant:`outline`,disabled:b,onClick:()=>void Y(`retry`),children:`Retry`})]}),t===`trashed`&&(0,R.jsxs)(R.Fragment,{children:[(0,R.jsx)(l,{size:`sm`,variant:`outline`,disabled:b,onClick:()=>void Y(`restore`),children:`Restore copies`}),(0,R.jsx)(l,{size:`sm`,variant:`destructive`,disabled:b,onClick:()=>void Y(`purge`),children:`Purge copies`})]})]})]}),W&&(0,R.jsxs)(`div`,{className:`rounded border p-3 space-y-2`,children:[(0,R.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,R.jsxs)(`p`,{className:`text-sm font-medium`,children:[`Removal policy · `,W.source.account||W.source.backend,W.source.folder?` / ${W.source.folder}`:``]}),(0,R.jsx)(l,{size:`sm`,variant:`ghost`,onClick:()=>G(null),children:`Close`})]}),(0,R.jsx)(V,{source:W.source.backend,backends:A,destination:!1,value:{...N,...A.find(e=>e.address===W.source.backend)?.config?.removalPolicy,membership:E[W.id]?.membership??W.membership!==`keep`?`review`:`keep`,propagation:W.targets.length?`review`:`never`,targets:[...new Set(W.targets.filter(e=>!E[W.id]||E[W.id].targets.includes(JSON.stringify([e.backend,e.key]))).map(e=>e.backend))]},onSave:async t=>{W.source.driver===`imap`?await L(e,W.source.account,W.source.folder,t):await y(e,W.source.driver,W.source.backend,{removalPolicy:t}),P(await x(e))}},W.id)]}),_&&(0,R.jsx)(`p`,{role:`alert`,className:`text-sm text-destructive`,children:_}),(0,R.jsxs)(`div`,{className:`overflow-x-auto rounded border`,children:[(0,R.jsxs)(`table`,{className:`w-full text-left text-xs`,children:[(0,R.jsx)(`thead`,{className:`bg-muted`,children:(0,R.jsxs)(`tr`,{children:[(0,R.jsx)(`th`,{className:`p-3 w-8`,children:(0,R.jsx)(`input`,{type:`checkbox`,"aria-label":`Select visible operations`,disabled:!B.write||b||!K.length||t===`activity`,checked:K.length>0&&K.every(e=>w.has(e.id)),onChange:e=>T(e.target.checked?new Set(K.map(e=>e.id)):new Set)})}),(0,R.jsx)(`th`,{className:`p-3`,children:`Item and affected copies`}),(0,R.jsx)(`th`,{className:`p-3`,children:`Source`}),(0,R.jsx)(`th`,{className:`p-3`,children:`Status`}),(0,R.jsx)(`th`,{className:`p-3`,children:`Detected`})]})}),(0,R.jsx)(`tbody`,{children:K.map(e=>{let n=E[e.id]||{targets:e.targets.filter(e=>e.state!==`kept`).map(e=>JSON.stringify([e.backend,e.key])),membership:e.membership!==`keep`};return(0,R.jsxs)(`tr`,{className:`border-t align-top`,children:[(0,R.jsx)(`td`,{className:`p-3`,children:(0,R.jsx)(`input`,{type:`checkbox`,"aria-label":`Select ${e.title}`,disabled:!B.write||b||t===`activity`,checked:w.has(e.id),onChange:t=>T(n=>{let r=new Set(n);return t.target.checked?r.add(e.id):r.delete(e.id),r})})}),(0,R.jsx)(`td`,{className:`p-3 min-w-64`,children:(0,R.jsxs)(`details`,{children:[(0,R.jsx)(`summary`,{className:`cursor-pointer font-medium`,children:e.title}),(0,R.jsxs)(`div`,{className:`mt-2 space-y-2 text-muted-foreground`,children:[(0,R.jsx)(`p`,{children:e.orphan?`No remaining byte locations. Restore placements only unless recovery bytes are available.`:`${e.remainingLocations.length} remaining location(s) when detected.`}),e.placements.map(e=>(0,R.jsxs)(`p`,{children:[e.tree,`: `,e.paths.join(`, `)]},e.tree)),e.membership!==`keep`&&(0,R.jsxs)(`label`,{className:`flex items-center gap-2`,children:[(0,R.jsx)(`input`,{type:`checkbox`,checked:n.membership,disabled:b||t!==`pending`||e.membershipApplied,onChange:t=>D({...E,[e.id]:{...n,membership:t.target.checked}})}),e.membershipApplied?`Managed placements moved to Trash`:`Move managed placements to Trash`]}),e.targets.map(r=>{let i=JSON.stringify([r.backend,r.key]);return(0,R.jsxs)(`label`,{className:`flex items-start gap-2`,children:[(0,R.jsx)(`input`,{type:`checkbox`,disabled:b||t!==`pending`||!!r.trashId,checked:n.targets.includes(i),onChange:t=>D({...E,[e.id]:{...n,targets:t.target.checked?[...n.targets,i]:n.targets.filter(e=>e!==i)}})}),(0,R.jsxs)(`span`,{className:`break-all`,children:[r.backend,`:`,r.key,` · `,r.state,r.error&&(0,R.jsx)(`span`,{className:`block text-destructive`,children:r.error})]})]},i)}),(0,R.jsx)(l,{size:`sm`,variant:`outline`,disabled:!B.admin,onClick:()=>G(e),children:`Use these choices as a source policy`}),e.remainingLocations.map(e=>(0,R.jsx)(`p`,{className:`break-all`,children:e.url},e.url))]})]})}),(0,R.jsxs)(`td`,{className:`p-3 break-all`,children:[e.source.account||e.source.backend,e.source.folder&&(0,R.jsx)(`span`,{className:`block text-muted-foreground`,children:e.source.folder})]}),(0,R.jsxs)(`td`,{className:`p-3`,children:[e.state,e.error&&(0,R.jsx)(`p`,{className:`mt-1 max-w-xs text-destructive`,children:e.error})]}),(0,R.jsx)(`td`,{className:`p-3 whitespace-nowrap text-muted-foreground`,children:new Date(e.createdAt).toLocaleString()})]},e.id)})})]}),!K.length&&(0,R.jsx)(`p`,{className:`p-5 text-center text-sm text-muted-foreground`,children:m?`No matching operations.`:`Loading…`})]}),(0,R.jsxs)(`div`,{className:`flex items-center justify-between text-xs text-muted-foreground`,children:[(0,R.jsxs)(`span`,{children:[m?.total??0,` operation(s)`]}),(0,R.jsxs)(`div`,{className:`flex gap-2`,children:[(0,R.jsx)(l,{size:`sm`,variant:`outline`,disabled:!c||b,onClick:()=>{d(Math.max(0,c-200)),T(new Set)},children:`Previous`}),(0,R.jsx)(l,{size:`sm`,variant:`outline`,disabled:c+K.length>=(m?.total??0)||b,onClick:()=>{d(c+200),T(new Set)},children:`Next`})]})]})]})}var G=`canvas:query-debug`,K=`canvas:query-debug-changed`;function q(){try{return localStorage.getItem(G)===`1`}catch{return!1}}function J(e){try{e?localStorage.setItem(G,`1`):localStorage.removeItem(G)}catch{}window.dispatchEvent(new CustomEvent(K,{detail:e}))}function Y(){let[e,t]=(0,M.useState)(q);return(0,M.useEffect)(()=>{let e=()=>t(q());return window.addEventListener(K,e),window.addEventListener(`storage`,e),()=>{window.removeEventListener(K,e),window.removeEventListener(`storage`,e)}},[]),e}export{V as a,U as i,J as n,z as o,Y as r,L as s,q as t};
1
+ import{o as e}from"./rolldown-runtime-C0FnF6B9.js";import{l as t,u as n}from"./code-editor-BOIngd5F.js";import{Gn as r,Ot as i,Tt as a,X as o,hr as s,ir as c}from"./ui-Byg1cZDr.js";import{t as l}from"./button-SgR3GVvV.js";import{t as u}from"./input-BOtCd4HP.js";import{t as d}from"./api-CA6WiiYM.js";import{n as f}from"./use-toast-BlLDqSUO.js";import{h as p,o as m,s as h}from"./LinkToCard-5dg0jvSY.js";import{$ as g,An as _,I as v,St as y,bt as b,en as x,gt as S,vn as C}from"./workspace-CrSpR4xf.js";import{a as w,c as T,l as E,n as D,o as O,r as k,u as A}from"./backend-sync-progress-pZrhQPk3.js";import{t as j}from"./workspace-access-C9nZlBBZ.js";var M=e(n(),1),N={membership:`keep`,propagation:`never`,targets:[],acceptPropagatedDeletions:!1},P=e=>`/workspaces/${encodeURIComponent(e)}/trash/operations`,F=(e,t)=>d.get(`${P(e)}?${new URLSearchParams(Object.entries(t).map(([e,t])=>[e,String(t)]))}`),I=(e,t,n,r={})=>d.post(`${P(e)}/${n}`,{ids:t,...r}),L=(e,t,n,r)=>d.patch(`/workspaces/${encodeURIComponent(e)}/backends/imap/${encodeURIComponent(t)}/containers/${encodeURIComponent(n)}`,{removalPolicy:r}),R=t();function z(e){let t=T(`backends`,e.path)?.backend;return(0,R.jsx)(B,{...e},JSON.stringify([e.workspace,t]))}function B({workspace:e,path:t,onNavigate:n}){let l=T(`backends`,t),u=l.backend,d=l.prefix,[f,g]=(0,M.useState)(null),[_,v]=(0,M.useState)(null),y=(0,M.useRef)(!1),[x,S]=(0,M.useState)(null),[C,j]=(0,M.useState)(null),[N,P]=(0,M.useState)(0),[F,I]=(0,M.useState)(new Set),[L,z]=(0,M.useState)(null),B=(0,M.useCallback)(()=>P(e=>e+1),[]),[V,H]=(0,M.useState)(t);V!==t&&(H(t),I(new Set),z(null),j(null),S(null));let U=f?.revision!==N,W=U?[]:f.items,G=U?[]:f.backends,K=f?.days;(0,M.useEffect)(()=>{let t=!1;return(u?w(e,u).then(e=>({...e,backends:[]})):b(e).then(e=>({items:[],days:null,backends:e.filter(e=>e.driver===`file`&&e.enabled!==!1)}))).then(e=>{t||g({...e,revision:N,error:null})}).catch(e=>{t||g({revision:N,items:[],backends:[],days:null,error:e instanceof Error?e.message:String(e)})}),()=>{t=!0}},[e,u,N]),(0,M.useEffect)(()=>{let t=null,n=n=>{let r=n.detail;r?.workspaceName&&r.workspaceName!==e||r?.treeName&&r.treeName!==`backends`||(t||=setTimeout(()=>{t=null,B()},500))};return window.addEventListener(`workspace:trash:refresh`,n),window.addEventListener(`workspace:tree:refresh`,n),()=>{window.removeEventListener(`workspace:trash:refresh`,n),window.removeEventListener(`workspace:tree:refresh`,n),t&&clearTimeout(t)}},[e,B]);let q=A(W,d),J=async(t,n)=>{if(!(!u||y.current||U||!n.length)&&!(t===`discard`&&!D(u,n))){y.current=!0,v(t),S(null),j(null),z(null);try{let r=await(t===`restore`?O:k)(e,u,[...n].sort((e,t)=>t.deletedAt-e.deletedAt).map(e=>e.id)),i=r.filter(e=>!e.ok);j(`${r.length-i.length} item(s) ${t===`restore`?`restored to their original paths`:`permanently deleted`}.`),i.length&&S(`${i.length} item(s) remain in Trash. ${i.slice(0,3).map(e=>`${e.key||`Item`}: ${e.reason===`precondition-failed`||e.reason===`target-exists`?`original path is occupied`:e.message||e.reason}`).join(`; `)}`),I(new Set)}catch(e){S(e instanceof Error?e.message:String(e))}finally{y.current=!1,v(null),B()}}},Y=(e,t,n)=>z({x:e,y:t,row:n});return(0,R.jsxs)(`section`,{className:`flex h-full min-h-0 flex-col bg-background`,"aria-label":`Backend Trash`,children:[(0,R.jsxs)(`div`,{className:`flex min-w-0 flex-wrap items-center gap-2 border-b px-4 py-3`,children:[(0,R.jsx)(o,{className:`h-4 w-4 shrink-0 text-muted-foreground`}),(0,R.jsx)(h,{items:m(t,e).map((e,t)=>t===2&&u?{...e,label:u}:e),onNavigate:n,className:`basis-48`}),(0,R.jsxs)(`div`,{className:`ml-auto flex max-w-full flex-wrap items-center gap-2`,children:[F.size>0&&(0,R.jsxs)(R.Fragment,{children:[(0,R.jsxs)(`button`,{className:`flex items-center gap-1 rounded border px-2 py-1 text-sm disabled:opacity-50`,disabled:!!_||U,onClick:()=>void J(`restore`,q.filter(e=>F.has(e.id)).flatMap(e=>e.items)),children:[(0,R.jsx)(a,{className:`h-3.5 w-3.5`}),`Restore selected`]}),(0,R.jsxs)(`button`,{className:`flex items-center gap-1 rounded border px-2 py-1 text-sm text-destructive disabled:opacity-50`,disabled:!!_||U,onClick:()=>void J(`discard`,q.filter(e=>F.has(e.id)).flatMap(e=>e.items)),children:[(0,R.jsx)(o,{className:`h-3.5 w-3.5`}),`Delete selected`]})]}),u&&q.length>0&&(0,R.jsxs)(`button`,{className:`flex items-center gap-1 rounded border px-2 py-1 text-sm text-destructive disabled:opacity-50`,disabled:!!_||U,onClick:()=>void J(`discard`,q.flatMap(e=>e.items)),children:[(0,R.jsx)(o,{className:`h-3.5 w-3.5`}),d?`Empty this folder`:`Empty Trash`]}),(0,R.jsx)(`button`,{title:`Refresh Trash`,"aria-label":`Refresh Trash`,className:`rounded p-2 hover:bg-accent`,disabled:!!_||U,onClick:B,children:(0,R.jsx)(i,{className:`h-4 w-4 ${U?`animate-spin`:``}`})})]})]}),(0,R.jsxs)(`div`,{className:`border-b px-4 py-2 text-xs text-muted-foreground`,children:[`Restore files and folders to their original paths. Existing files are kept.`,K?` Deleted items are kept for ${K} days.`:``]}),C&&(0,R.jsx)(`p`,{role:`status`,className:`px-4 py-2 text-sm`,children:C}),(x||f?.error)&&(0,R.jsx)(`p`,{role:`alert`,className:`px-4 py-2 text-sm text-destructive`,children:x||f?.error}),_&&(0,R.jsx)(`p`,{role:`status`,className:`px-4 py-2 text-sm`,children:_===`restore`?`Restoring…`:`Deleting permanently…`}),(0,R.jsx)(`div`,{className:`min-h-0 flex-1 overflow-auto p-3`,children:U?(0,R.jsx)(`p`,{className:`p-4 text-sm text-muted-foreground`,children:`Loading Trash…`}):u?q.length===0?(0,R.jsx)(`p`,{className:`p-4 text-sm text-muted-foreground`,children:`This Trash folder is empty.`}):(0,R.jsxs)(`table`,{className:`w-full text-left text-sm`,children:[(0,R.jsx)(`thead`,{className:`border-b text-xs text-muted-foreground`,children:(0,R.jsxs)(`tr`,{children:[(0,R.jsx)(`th`,{className:`w-8 p-2`,children:(0,R.jsx)(`input`,{type:`checkbox`,"aria-label":`Select all visible items`,checked:q.length>0&&q.every(e=>F.has(e.id)),onChange:e=>I(e.target.checked?new Set(q.map(e=>e.id)):new Set)})}),(0,R.jsx)(`th`,{className:`p-2`,children:`Name`}),(0,R.jsx)(`th`,{className:`p-2 max-sm:hidden`,children:`Original path`}),(0,R.jsx)(`th`,{className:`p-2 max-md:hidden`,children:`Deleted`}),(0,R.jsx)(`th`,{className:`p-2`,children:(0,R.jsx)(`span`,{className:`sr-only`,children:`Actions`})})]})}),(0,R.jsx)(`tbody`,{children:q.map(e=>(0,R.jsxs)(`tr`,{className:`border-b border-border/50 hover:bg-accent/50`,onContextMenu:t=>{t.preventDefault(),Y(t.clientX,t.clientY,e)},onDoubleClick:()=>e.navigable&&n(E(u,e.key)),children:[(0,R.jsx)(`td`,{className:`p-2`,children:(0,R.jsx)(`input`,{type:`checkbox`,"aria-label":`Select ${e.name}`,checked:F.has(e.id),disabled:!!_,onChange:t=>I(n=>{let r=new Set(n);return t.target.checked?r.add(e.id):r.delete(e.id),r})})}),(0,R.jsx)(`td`,{className:`p-2`,children:(0,R.jsxs)(`button`,{className:`flex items-center gap-2 text-left`,onClick:()=>e.navigable&&n(E(u,e.key)),children:[e.directory?(0,R.jsx)(r,{className:`h-4 w-4 shrink-0`}):(0,R.jsx)(c,{className:`h-4 w-4 shrink-0`}),(0,R.jsxs)(`span`,{children:[e.name,e.navigable&&(0,R.jsxs)(`span`,{className:`ml-2 text-xs text-muted-foreground`,children:[e.items.length,` items`]})]})]})}),(0,R.jsx)(`td`,{className:`p-2 text-xs text-muted-foreground max-sm:hidden`,children:e.key}),(0,R.jsx)(`td`,{className:`p-2 text-xs text-muted-foreground max-md:hidden`,children:new Date(e.items.reduce((e,t)=>Math.max(e,t.deletedAt),0)).toLocaleString()}),(0,R.jsx)(`td`,{className:`p-2 text-right`,children:(0,R.jsx)(`button`,{title:`Actions for ${e.name}`,"aria-label":`Actions for ${e.name}`,disabled:!!_,className:`rounded p-2 hover:bg-accent`,onClick:t=>Y(t.clientX,t.clientY,e),children:(0,R.jsx)(s,{className:`h-4 w-4`})})})]},e.id))})]}):(0,R.jsxs)(`div`,{className:`grid gap-2 sm:grid-cols-2 lg:grid-cols-3`,children:[G.map(e=>(0,R.jsxs)(`button`,{onClick:()=>n(E(e.address)),className:`flex items-center gap-3 rounded-lg border p-4 text-left hover:bg-accent`,children:[(0,R.jsx)(o,{className:`h-6 w-6 text-muted-foreground`}),(0,R.jsxs)(`span`,{children:[(0,R.jsx)(`span`,{className:`block text-sm font-medium`,children:e.label||e.address}),(0,R.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:e.address})]})]},e.address)),!G.length&&(0,R.jsx)(`p`,{className:`p-4 text-sm text-muted-foreground`,children:`No file backends are available.`})]})}),L&&(0,R.jsxs)(p,{x:L.x,y:L.y,onClose:()=>z(null),className:`min-w-44 rounded-md border bg-popover p-1 shadow-elevation-3`,children:[L.row.navigable&&(0,R.jsxs)(`button`,{className:`flex w-full items-center gap-2 rounded px-3 py-2 text-sm hover:bg-accent`,onClick:()=>{n(E(u,L.row.key)),z(null)},children:[(0,R.jsx)(r,{className:`h-4 w-4`}),`Open folder`]}),(0,R.jsxs)(`button`,{disabled:!!_,className:`flex w-full items-center gap-2 rounded px-3 py-2 text-sm hover:bg-accent disabled:opacity-50`,onClick:()=>void J(`restore`,L.row.items),children:[(0,R.jsx)(a,{className:`h-4 w-4`}),`Restore `,L.row.directory?`folder`:`file`]}),(0,R.jsxs)(`button`,{disabled:!!_||U,className:`flex w-full items-center gap-2 rounded px-3 py-2 text-sm text-destructive hover:bg-destructive/10 disabled:opacity-50`,onClick:()=>void J(`discard`,L.row.items),children:[(0,R.jsx)(o,{className:`h-4 w-4`}),`Delete permanently`]})]})]})}function V({value:e,backends:t,source:n,onSave:r,destination:i=!0}){let[a,o]=(0,M.useState)({...N,...e}),[s,c]=(0,M.useState)(!1),[u,d]=(0,M.useState)(``),f=`rounded border bg-background px-2 py-1.5 text-xs w-full`,p=async()=>{c(!0),d(``);try{await r(a),d(`Removal policy saved.`)}catch(e){d(e instanceof Error?e.message:`Could not save policy`)}finally{c(!1)}};return(0,R.jsxs)(`details`,{className:`border-t pt-3 text-xs`,children:[(0,R.jsx)(`summary`,{className:`cursor-pointer font-medium`,children:`Source removals and Trash`}),(0,R.jsxs)(`div`,{className:`mt-3 space-y-3`,children:[(0,R.jsx)(`p`,{className:`text-muted-foreground`,children:`A completed scan removes missing locations from the backend tree. Items with no remaining locations go to Trash until you purge them.`}),(0,R.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[(0,R.jsxs)(`label`,{className:`space-y-1 block`,children:[`When an item disappears from this source`,(0,R.jsxs)(`select`,{className:f,value:a.membership,disabled:s,onChange:e=>o({...a,membership:e.target.value}),children:[(0,R.jsx)(`option`,{value:`keep`,children:`Keep in managed trees`}),(0,R.jsx)(`option`,{value:`review`,children:`Review removal in Trash`}),(0,R.jsx)(`option`,{value:`trash`,children:`Move to Trash automatically`})]})]}),(0,R.jsxs)(`label`,{className:`space-y-1 block`,children:[`Remove tracked copies from other backends`,(0,R.jsxs)(`select`,{className:f,value:a.propagation,disabled:s,onChange:e=>o({...a,propagation:e.target.value}),children:[(0,R.jsx)(`option`,{value:`never`,children:`Never`}),(0,R.jsx)(`option`,{value:`review`,children:`Review in Trash`}),(0,R.jsx)(`option`,{value:`automatic`,children:`Automatically, retaining recovery copies`})]})]})]}),a.propagation!==`never`&&(0,R.jsxs)(`fieldset`,{className:`space-y-2`,children:[(0,R.jsx)(`legend`,{className:`mb-1 font-medium`,children:`Destinations`}),(0,R.jsxs)(`label`,{className:`flex items-center gap-2`,children:[(0,R.jsx)(`input`,{type:`checkbox`,checked:a.targets===`all`,disabled:s,onChange:e=>o({...a,targets:e.target.checked?`all`:[]})}),`All eligible backends`]}),a.targets!==`all`&&t.filter(e=>e.address!==n&&e.kind===`storage`).map(e=>(0,R.jsxs)(`label`,{className:`flex items-center gap-2`,children:[(0,R.jsx)(`input`,{type:`checkbox`,disabled:s||e.config?.propagatedRemovalSupported!==!0,checked:a.targets.includes(e.address),onChange:t=>o({...a,targets:t.target.checked?[...a.targets,e.address]:a.targets.filter(t=>t!==e.address)})}),String(e.config?.label||e.address),e.config?.propagatedRemovalSupported===!0?!e.config?.removalPolicy?.acceptPropagatedDeletions&&` · protected`:` · recovery removal unavailable`]},e.address)),(0,R.jsx)(`p`,{className:`text-muted-foreground`,children:`Only tracked, Canvas-owned copies are eligible. Protected destinations refuse propagated deletion. Recovery removal currently supports filesystem and workspace blob storage; remote destinations remain protected.`})]}),i&&(0,R.jsxs)(`label`,{className:`flex items-center gap-2`,children:[(0,R.jsx)(`input`,{type:`checkbox`,disabled:s,checked:a.acceptPropagatedDeletions,onChange:e=>o({...a,acceptPropagatedDeletions:e.target.checked})}),`Accept propagated deletions on this backend`]}),(0,R.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,R.jsx)(l,{size:`sm`,variant:`outline`,disabled:s,onClick:()=>void p(),children:s?`Saving…`:`Save removal policy`}),(0,R.jsx)(`span`,{role:`status`,children:u})]})]})]})}function H({workspaceName:e,canWrite:t}){let{showToast:n}=f(),[r,s]=(0,M.useState)([]),[c,u]=(0,M.useState)(!1),[d,p]=(0,M.useState)([]),[m,h]=(0,M.useState)(!1),g=(0,M.useCallback)(async()=>{u(!0);try{s(await y(e))}catch(e){n({title:`Error`,description:e instanceof Error?e.message:`Failed to load the trash`,variant:`destructive`})}finally{u(!1)}},[e]);(0,M.useEffect)(()=>{g()},[g]);let b=(0,M.useCallback)(e=>d.includes(e),[d]),S=async(e,t)=>{p(t=>[...t,...e]);try{await t()}finally{p(t=>t.filter(t=>!e.includes(t)))}},C=t=>S([t.id],async()=>{try{let r=await x(e,[t.id]);r.failed?.length?n({title:`Not restored`,description:r.failed[0]?.error||`No restore target recorded`,variant:`destructive`}):(n({title:`Restored`,description:`Document put back where it was.`}),s(e=>e.filter(e=>e.id!==t.id)))}catch(e){n({title:`Error`,description:e instanceof Error?e.message:`Failed to restore`,variant:`destructive`})}}),w=t=>S([t.id],async()=>{try{let r=await v(e,[t.id]);if(r.failed?.length)throw Error(`The item could not be purged. Refresh and retry.`);n({title:`Cleared from Trash`,description:r.preserved?.length?`Existing backend copies remain indexed.`:`Document permanently deleted.`}),s(e=>e.filter(e=>e.id!==t.id))}catch(e){n({title:`Error`,description:e instanceof Error?e.message:`Failed to delete`,variant:`destructive`})}}),T=async()=>{if(!m){h(!0);return}h(!1);try{let t=await v(e);n({title:`Trash emptied`,description:`${t.destroyed?.length??0} document(s) purged. ${t.preserved?.length??0} item(s) cleared with backend copies preserved.`}),await g()}catch(e){n({title:`Error`,description:e instanceof Error?e.message:`Failed to empty the trash`,variant:`destructive`})}},E=(0,M.useMemo)(()=>r.map(e=>{let t=_(e),n=(e.trashed?.placements??[]).flatMap(e=>e.paths.map(t=>`${e.tree}:${t}`));return{document:e,title:t.title,origin:n,trashedAt:e.trashed?.trashedAt||null}}),[r]);return(0,R.jsxs)(`div`,{className:`space-y-4`,children:[(0,R.jsxs)(`div`,{className:`flex flex-col gap-2 sm:flex-row sm:items-start sm:justify-between sm:gap-4`,children:[(0,R.jsxs)(`div`,{children:[(0,R.jsx)(`h2`,{className:`text-sm font-medium`,children:`Managed-tree items`}),(0,R.jsx)(`p`,{className:`text-xs text-muted-foreground mt-1 max-w-2xl`,children:`Restore managed-tree placements or permanently purge these items. Pending removals require separate approval. Backend copies are managed below.`})]}),(0,R.jsxs)(`div`,{className:`flex shrink-0 items-center gap-2 max-sm:flex-wrap`,children:[(0,R.jsxs)(l,{variant:`outline`,size:`sm`,onClick:()=>g(),disabled:c,children:[(0,R.jsx)(i,{className:`mr-2 h-3.5 w-3.5 ${c?`animate-spin`:``}`}),`Refresh`]}),(0,R.jsxs)(l,{variant:m?`destructive`:`outline`,size:`sm`,onClick:T,onBlur:()=>h(!1),disabled:!t||r.length===0,children:[(0,R.jsx)(o,{className:`mr-2 h-3.5 w-3.5`}),m?`Click again to delete everything`:`Empty trash`]})]})]}),c&&r.length===0&&(0,R.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`Loading…`}),!c&&r.length===0&&(0,R.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`The trash is empty.`}),E.length>0&&(0,R.jsx)(`div`,{className:`border rounded-md divide-y`,children:E.map(({document:e,title:n,origin:r,trashedAt:i})=>(0,R.jsxs)(`div`,{className:`flex items-center gap-3 px-3 py-2`,children:[(0,R.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,R.jsx)(`div`,{className:`truncate text-sm`,children:n}),(0,R.jsxs)(`div`,{className:`truncate text-xs text-muted-foreground`,children:[r.length>0?`from ${r.join(`, `)}`:`no recorded origin`,i?` · ${new Date(i).toLocaleString()}`:``]})]}),(0,R.jsxs)(l,{variant:`outline`,size:`sm`,onClick:()=>C(e),disabled:!t||b(e.id)||r.length===0,title:r.length===0?`Nothing recorded to restore to`:`Put it back where it was`,children:[(0,R.jsx)(a,{className:`mr-2 h-3.5 w-3.5`}),`Restore placements`]}),(0,R.jsx)(l,{variant:`ghost`,size:`sm`,onClick:()=>w(e),disabled:!t||b(e.id),title:`Delete permanently`,children:(0,R.jsx)(o,{className:`h-3.5 w-3.5`})})]},e.id))})]})}function U({workspaceName:e}){return(0,R.jsx)(W,{workspaceName:e},e)}function W({workspaceName:e}){let[t,n]=(0,M.useState)(`pending`),[r,a]=(0,M.useState)(``),[o,s]=(0,M.useState)(``),[c,d]=(0,M.useState)(0),[f,p]=(0,M.useState)(0),[m,h]=(0,M.useState)(null),[_,v]=(0,M.useState)(``),[y,x]=(0,M.useState)(!1),[w,T]=(0,M.useState)(new Set),[E,D]=(0,M.useState)({}),[O,k]=(0,M.useState)(`/Trash`),[A,P]=(0,M.useState)([]),[B,U]=(0,M.useState)({write:!1,admin:!1});(0,M.useEffect)(()=>{let t=!0;return g(e).then(e=>{let n=e.remote?.permissions||e.access?.permissions||(typeof e.sharedVia==`object`?e.sharedVia?.permissions:[])||[],r=j(e);t&&U({admin:r,write:r||n.includes(`write`)})}).catch(()=>{}),()=>{t=!1}},[e]);let[W,G]=(0,M.useState)(null);(0,M.useEffect)(()=>{let t=!0;return b(e).then(e=>{t&&P(e)}).catch(()=>{}),()=>{t=!1}},[e]),(0,M.useEffect)(()=>{let n=!1,i=()=>F(e,{view:t,search:r,...o?{backend:o}:{},offset:c}).then(e=>{n||(h(e),v(``))}).catch(e=>{n||v(e instanceof Error?e.message:`Could not load Trash`)});i();let a=setInterval(()=>{y||i()},5e3);return()=>{n=!0,clearInterval(a)}},[e,t,r,o,c,f,y]);let K=m?.operations||[],q=()=>{T(new Set),p(e=>e+1)},J=()=>{S(e),window.dispatchEvent(new CustomEvent(`workspace:tree:refresh`,{detail:{workspaceName:e}})),window.dispatchEvent(new CustomEvent(`workspace:trash:refresh`,{detail:{workspaceName:e}}))},Y=async(t,n=[...w])=>{if(!(!n.length||y)&&!(t===`purge`&&!window.confirm(`Permanently delete retained recovery copies for ${n.length} operation(s)?`))){x(!0),v(``);try{let r=(t===`approve`?(await Promise.all(n.map(n=>I(e,[n],t,E[n])))).flatMap(e=>e.results):(await I(e,n,t)).results).filter(e=>!e.ok||e.operation?.state===`failed`);r.length&&v(r.map(e=>e.error||e.operation?.error||`A destination could not be changed. Expand the item for details.`).join(` `)),J(),q()}catch(e){v(e instanceof Error?e.message:`Trash action failed`)}finally{x(!1)}}},X=e=>{n(e),d(0),h(null),T(new Set),D({})};return(0,R.jsxs)(`div`,{className:`space-y-4`,children:[(0,R.jsxs)(`div`,{children:[(0,R.jsx)(`h2`,{className:`text-base font-semibold`,children:`Workspace Trash`}),(0,R.jsx)(`p`,{className:`text-xs text-muted-foreground mt-1`,children:`Review source removals, recover items, and see what automatic policies changed.`})]}),(0,R.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,role:`tablist`,"aria-label":`Trash views`,children:[[[`pending`,`Pending removal`],[`trashed`,`In Trash`],[`activity`,`Activity`]].map(([e,n])=>(0,R.jsx)(l,{role:`tab`,"aria-selected":t===e,size:`sm`,variant:t===e?`default`:`outline`,onClick:()=>X(e),children:n},e)),(0,R.jsxs)(l,{size:`sm`,variant:`ghost`,className:`ml-auto`,onClick:q,disabled:y,children:[(0,R.jsx)(i,{className:`mr-2 h-3.5 w-3.5`}),`Refresh`]})]}),t===`trashed`&&(0,R.jsxs)(R.Fragment,{children:[(0,R.jsx)(H,{workspaceName:e,canWrite:B.write},f),(0,R.jsxs)(`details`,{className:`rounded border p-3`,children:[(0,R.jsx)(`summary`,{className:`cursor-pointer text-sm font-medium`,children:`Browse backend recovery copies`}),(0,R.jsx)(`div`,{className:`mt-3 min-h-48`,children:(0,R.jsx)(z,{workspace:e,path:O,onNavigate:k})})]})]}),(0,R.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[(0,R.jsx)(u,{"aria-label":`Filter Trash items`,placeholder:`Filter by item or path…`,className:`max-w-xs`,value:r,onChange:e=>{a(e.target.value),h(null),d(0),T(new Set)}}),(0,R.jsx)(u,{"aria-label":`Filter by backend`,placeholder:`Backend name…`,className:`max-w-56`,value:o,onChange:e=>{s(e.target.value),h(null),d(0),T(new Set)}}),w.size>0&&(0,R.jsxs)(`div`,{className:`flex items-center gap-2 text-xs`,children:[(0,R.jsxs)(`span`,{children:[w.size,` selected`]}),t===`pending`&&(0,R.jsxs)(R.Fragment,{children:[(0,R.jsx)(l,{size:`sm`,disabled:y,onClick:()=>void Y(`approve`),children:`Approve selected`}),(0,R.jsx)(l,{size:`sm`,variant:`outline`,disabled:y,onClick:()=>void Y(`keep`),children:`Keep selected`}),(0,R.jsx)(l,{size:`sm`,variant:`outline`,disabled:y,onClick:()=>void Y(`retry`),children:`Retry`})]}),t===`trashed`&&(0,R.jsxs)(R.Fragment,{children:[(0,R.jsx)(l,{size:`sm`,variant:`outline`,disabled:y,onClick:()=>void Y(`restore`),children:`Restore copies`}),(0,R.jsx)(l,{size:`sm`,variant:`destructive`,disabled:y,onClick:()=>void Y(`purge`),children:`Purge copies`})]})]})]}),W&&(0,R.jsxs)(`div`,{className:`rounded border p-3 space-y-2`,children:[(0,R.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,R.jsxs)(`p`,{className:`text-sm font-medium`,children:[`Removal policy · `,W.source.account||W.source.backend,W.source.folder?` / ${W.source.folder}`:``]}),(0,R.jsx)(l,{size:`sm`,variant:`ghost`,onClick:()=>G(null),children:`Close`})]}),(0,R.jsx)(V,{source:W.source.backend,backends:A,destination:!1,value:{...N,...A.find(e=>e.address===W.source.backend)?.config?.removalPolicy,membership:E[W.id]?.membership??W.membership!==`keep`?`review`:`keep`,propagation:W.targets.length?`review`:`never`,targets:[...new Set(W.targets.filter(e=>!E[W.id]||E[W.id].targets.includes(JSON.stringify([e.backend,e.key]))).map(e=>e.backend))]},onSave:async t=>{W.source.driver===`imap`?await L(e,W.source.account,W.source.folder,t):await C(e,W.source.driver,W.source.backend,{removalPolicy:t}),P(await b(e))}},W.id)]}),_&&(0,R.jsx)(`p`,{role:`alert`,className:`text-sm text-destructive`,children:_}),(0,R.jsxs)(`div`,{className:`overflow-x-auto rounded border`,children:[(0,R.jsxs)(`table`,{className:`w-full text-left text-xs`,children:[(0,R.jsx)(`thead`,{className:`bg-muted`,children:(0,R.jsxs)(`tr`,{children:[(0,R.jsx)(`th`,{className:`p-3 w-8`,children:(0,R.jsx)(`input`,{type:`checkbox`,"aria-label":`Select visible operations`,disabled:!B.write||y||!K.length||t===`activity`,checked:K.length>0&&K.every(e=>w.has(e.id)),onChange:e=>T(e.target.checked?new Set(K.map(e=>e.id)):new Set)})}),(0,R.jsx)(`th`,{className:`p-3`,children:`Item and affected copies`}),(0,R.jsx)(`th`,{className:`p-3`,children:`Source`}),(0,R.jsx)(`th`,{className:`p-3`,children:`Status`}),(0,R.jsx)(`th`,{className:`p-3`,children:`Detected`})]})}),(0,R.jsx)(`tbody`,{children:K.map(e=>{let n=E[e.id]||{targets:e.targets.filter(e=>e.state!==`kept`).map(e=>JSON.stringify([e.backend,e.key])),membership:e.membership!==`keep`};return(0,R.jsxs)(`tr`,{className:`border-t align-top`,children:[(0,R.jsx)(`td`,{className:`p-3`,children:(0,R.jsx)(`input`,{type:`checkbox`,"aria-label":`Select ${e.title}`,disabled:!B.write||y||t===`activity`,checked:w.has(e.id),onChange:t=>T(n=>{let r=new Set(n);return t.target.checked?r.add(e.id):r.delete(e.id),r})})}),(0,R.jsx)(`td`,{className:`p-3 min-w-64`,children:(0,R.jsxs)(`details`,{children:[(0,R.jsx)(`summary`,{className:`cursor-pointer font-medium`,children:e.title}),(0,R.jsxs)(`div`,{className:`mt-2 space-y-2 text-muted-foreground`,children:[(0,R.jsx)(`p`,{children:e.orphan?`No remaining byte locations. Restore placements only unless recovery bytes are available.`:`${e.remainingLocations.length} remaining location(s) when detected.`}),e.placements.map(e=>(0,R.jsxs)(`p`,{children:[e.tree,`: `,e.paths.join(`, `)]},e.tree)),e.membership!==`keep`&&(0,R.jsxs)(`label`,{className:`flex items-center gap-2`,children:[(0,R.jsx)(`input`,{type:`checkbox`,checked:n.membership,disabled:y||t!==`pending`||e.membershipApplied,onChange:t=>D({...E,[e.id]:{...n,membership:t.target.checked}})}),e.membershipApplied?`Managed placements moved to Trash`:`Move managed placements to Trash`]}),e.targets.map(r=>{let i=JSON.stringify([r.backend,r.key]);return(0,R.jsxs)(`label`,{className:`flex items-start gap-2`,children:[(0,R.jsx)(`input`,{type:`checkbox`,disabled:y||t!==`pending`||!!r.trashId,checked:n.targets.includes(i),onChange:t=>D({...E,[e.id]:{...n,targets:t.target.checked?[...n.targets,i]:n.targets.filter(e=>e!==i)}})}),(0,R.jsxs)(`span`,{className:`break-all`,children:[r.backend,`:`,r.key,` · `,r.state,r.error&&(0,R.jsx)(`span`,{className:`block text-destructive`,children:r.error})]})]},i)}),(0,R.jsx)(l,{size:`sm`,variant:`outline`,disabled:!B.admin,onClick:()=>G(e),children:`Use these choices as a source policy`}),e.remainingLocations.map(e=>(0,R.jsx)(`p`,{className:`break-all`,children:e.url},e.url))]})]})}),(0,R.jsxs)(`td`,{className:`p-3 break-all`,children:[e.source.account||e.source.backend,e.source.folder&&(0,R.jsx)(`span`,{className:`block text-muted-foreground`,children:e.source.folder})]}),(0,R.jsxs)(`td`,{className:`p-3`,children:[e.state,e.error&&(0,R.jsx)(`p`,{className:`mt-1 max-w-xs text-destructive`,children:e.error})]}),(0,R.jsx)(`td`,{className:`p-3 whitespace-nowrap text-muted-foreground`,children:new Date(e.createdAt).toLocaleString()})]},e.id)})})]}),!K.length&&(0,R.jsx)(`p`,{className:`p-5 text-center text-sm text-muted-foreground`,children:m?`No matching operations.`:`Loading…`})]}),(0,R.jsxs)(`div`,{className:`flex items-center justify-between text-xs text-muted-foreground`,children:[(0,R.jsxs)(`span`,{children:[m?.total??0,` operation(s)`]}),(0,R.jsxs)(`div`,{className:`flex gap-2`,children:[(0,R.jsx)(l,{size:`sm`,variant:`outline`,disabled:!c||y,onClick:()=>{d(Math.max(0,c-200)),T(new Set)},children:`Previous`}),(0,R.jsx)(l,{size:`sm`,variant:`outline`,disabled:c+K.length>=(m?.total??0)||y,onClick:()=>{d(c+200),T(new Set)},children:`Next`})]})]})]})}var G=`canvas:query-debug`,K=`canvas:query-debug-changed`;function q(){try{return localStorage.getItem(G)===`1`}catch{return!1}}function J(e){try{e?localStorage.setItem(G,`1`):localStorage.removeItem(G)}catch{}window.dispatchEvent(new CustomEvent(K,{detail:e}))}function Y(){let[e,t]=(0,M.useState)(q);return(0,M.useEffect)(()=>{let e=()=>t(q());return window.addEventListener(K,e),window.addEventListener(`storage`,e),()=>{window.removeEventListener(K,e),window.removeEventListener(`storage`,e)}},[]),e}export{V as a,U as i,J as n,z as o,Y as r,L as s,q as t};
@@ -1,2 +1,2 @@
1
- const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/TerminalApplet-CkO4uaE3.js","assets/rolldown-runtime-C0FnF6B9.js","assets/code-editor-BOIngd5F.js","assets/ui-Byg1cZDr.js","assets/react-BHzhHVTZ.js","assets/use-applet-target-cO-FiyPQ.js","assets/workspace-DvxC7pw1.js","assets/button-SgR3GVvV.js","assets/utils-BxVxyehK.js","assets/utils-2pl1SbIp.js","assets/input-BOtCd4HP.js","assets/api-CA6WiiYM.js","assets/alert-dialog-izlVMXfa.js","assets/use-toolbox-Ck_cLGgf.js","assets/TerminalApplet-BrP-ENHg.css","assets/NotesApplet-BmLjXx7V.js","assets/useAddTarget-DUjaZdBQ.js","assets/context-mfIOB8dN.js","assets/note-save-status-DPz4VzL6.js","assets/useEditNoteFields-zHEWwDfB.js","assets/tags-YamdPoBK.js","assets/index-Tx_qtD_m.js","assets/preload-helper-Czpn1I53.js","assets/chunk-62JRHF6Z-vspAGgtK.js","assets/label-Dn4gCMcc.js","assets/socket-hM4c-ZSl.js","assets/socket-CtH3EU9m.js","assets/auth-Bx9fAZmz.js","assets/use-toast-BlLDqSUO.js","assets/LinkToCard-nR7Lal_o.js","assets/useEscapeClose-DR_xKT_k.js","assets/useToastHelpers-CRrpIIdY.js","assets/layer-style-Byl5LNFR.js","assets/color-DFEH4BfK.js","assets/DocumentIcon-x299QNu_.js","assets/use-canvas-pins-6vnfChWd.js","assets/TodosWidget-BIYqPXUp.js","assets/ObjectPropertiesCard-ChvWbOpZ.js","assets/use-mobile-Db-vWu9Y.js","assets/IdentityFields-OPEWPlZs.js","assets/date-time-picker-B6mkWt-g.js","assets/relation-events-CKio19hE.js","assets/map-BxCwdK0d.js","assets/map-BcsP_QXj.css","assets/public-share-DXxVwHKT.js","assets/text-documents-BvDFBVnC.js","assets/blobs-WiXP9QRi.js","assets/useDocumentThumbnail-DYLCC63L.js","assets/markdown-view-BBBZtNSR.js","assets/sanitize-DrVcFY1Q.js","assets/MessageComposerDialog-gbD0Gu_b.js","assets/markdown-it-DRESbtwK.js","assets/punycode.es6-ZbLrB_Dn.js","assets/lazy-editor-BSRnneOo.js","assets/LinkToSidePanel-eCy3nW4R.js","assets/DocumentBodyEditor-8DNmOBS0.js","assets/use-document-modal-PG8bQyIB.js","assets/sketch-lazy-pbG2cCpW.js","assets/geo-CZfs0E-x.js","assets/ObjectPropertiesCard-JArcZXXv.css","assets/document-list-rh4ittZx.js","assets/document-open-mode-DoImW-xs.js","assets/PickDocumentsCard-Bo224P4q.js","assets/backend-sync-progress-H4Zch25P.js","assets/PathPickerField-DBe7jykL.js","assets/backend-sync-progress-DU-e9TWi.css","assets/workspace-access-C9nZlBBZ.js","assets/search-COMZIxA7.js","assets/use-sortable-data-BW_0sXBs.js","assets/workspace-BydSRtST.js","assets/document-list-DAYdk5vh.css","assets/url-params-n7kU_WZ-.js","assets/use-canvas-pins-C57Vbkrq.css","assets/use-menu-BiJ8N7sS.js","assets/last-path-BbXWC3b3.js","assets/workspace-area-menu-Dg3hXKR3.js","assets/workspace-content-gate-Be4tLYiB.js","assets/UploadProgressList-BXJr87lI.js","assets/sha256-65KIjGvZ.js","assets/FileForm-DhQhVnoi.js","assets/use-theme-DaxpiICf.js","assets/index-D7EoeBID.css","assets/shared-D2uRUNdC.js","assets/use-applet-docs-o5NAUFBk.js","assets/TodosApplet-Bpf1OIH4.js","assets/LensApplet-DuADvEm5.js","assets/FiltersApplet-BAe-Eq0e.js","assets/SketchApplet-ADVOnSLI.js"])))=>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}from"./preload-helper-Czpn1I53.js";import{St as i,Yr as a,ct as o,it as s,mn as c,tt as l}from"./ui-Byg1cZDr.js";var u=e(n(),1),d=t();function f(e){let t=(0,u.lazy)(e);return function(e){return(0,d.jsx)(u.Suspense,{fallback:(0,d.jsx)(`p`,{className:`p-4 text-sm text-muted-foreground`,role:`status`,children:`Opening app…`}),children:(0,d.jsx)(t,{...e})})}}var p=f(()=>r(()=>import(`./TerminalApplet-CkO4uaE3.js`).then(e=>({default:e.TerminalApplet})),__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14]))),m=f(()=>r(()=>import(`./NotesApplet-BmLjXx7V.js`).then(e=>({default:e.NotesApplet})),__vite__mapDeps([15,1,2,3,4,9,8,6,7,10,11,12,16,13,17,18,19,20,5,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83]))),h=f(()=>r(()=>import(`./TodosApplet-Bpf1OIH4.js`).then(e=>({default:e.TodosApplet})),__vite__mapDeps([84,1,2,3,4,9,8,6,7,10,11,12,16,13,17,40,20,41,5,82,29,30,31,28,32,33,34,54,83]))),g=f(()=>r(()=>import(`./LensApplet-DuADvEm5.js`).then(e=>({default:e.LensApplet})),__vite__mapDeps([85,1,2,3,4,9,8,6,7,10,11,12,47,44,34,56,5,13,21,22,23,24,25,26,27,28,29,30,31,32,33,35,36,37,38,39,20,16,17,40,41,42,43,45,46,48,49,50,51,52,53,54,18,19,55,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81]))),_=f(()=>r(()=>import(`./FiltersApplet-BAe-Eq0e.js`).then(e=>({default:e.FiltersApplet})),__vite__mapDeps([86,1,2,26,11,25,13,5,6,4,7,3,8,9,10,12,21,22,23,24,27,28,29,30,31,32,33,34,35,36,37,38,39,20,16,17,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,18,19,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81]))),v=f(()=>r(()=>import(`./SketchApplet-ADVOnSLI.js`).then(e=>({default:e.SketchApplet})),__vite__mapDeps([87,1,2,3,4,7,8,9,6,10,11,12,47,44,31,28,57,22,5,13,83,17]))),y=[{id:`terminal`,category:`utilities`,label:`Terminal`,icon:s,modes:[`context`],description:`Shell sessions for this context`,Component:p},{id:`filters`,category:`utilities`,label:`Filters`,icon:o,modes:[`context`,`global`],description:`Search and filter a workspace or a live context`,Component:_},{id:`notes`,category:`productivity`,label:`Notes`,icon:l,modes:[`context`],description:`All notes in the current context, editable in place`,Component:m},{id:`todo`,category:`productivity`,label:`Todos`,icon:c,modes:[`context`],description:`Todos in the current context, done items hidden by default`,Component:h},{id:`sketch`,category:`creative`,label:`Sketch`,icon:a,modes:[`context`],description:`Quick-sketch into the current context; tap a sketch to keep editing`,Component:v},{id:`lens`,category:`media`,label:`Lens`,icon:i,modes:[`context`],description:`Point a camera at things; matching documents surface live`,Component:g}];function b(e){return y.filter(t=>t.modes.includes(e))}export{b as n,y as t};
1
+ const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/TerminalApplet-wGJG1PPc.js","assets/rolldown-runtime-C0FnF6B9.js","assets/code-editor-BOIngd5F.js","assets/ui-Byg1cZDr.js","assets/react-BHzhHVTZ.js","assets/use-applet-target-gXPvZGgx.js","assets/workspace-CrSpR4xf.js","assets/button-SgR3GVvV.js","assets/utils-BxVxyehK.js","assets/utils-2pl1SbIp.js","assets/input-BOtCd4HP.js","assets/api-CA6WiiYM.js","assets/alert-dialog-izlVMXfa.js","assets/use-toolbox-Ck_cLGgf.js","assets/TerminalApplet-BrP-ENHg.css","assets/NotesApplet-bIqcBzpg.js","assets/useAddTarget-CqnDU0Om.js","assets/context-DQoZFMDQ.js","assets/note-save-status-DPz4VzL6.js","assets/useEditNoteFields-BehI0vog.js","assets/tags-YamdPoBK.js","assets/index-4M1qLU_S.js","assets/preload-helper-Czpn1I53.js","assets/chunk-62JRHF6Z-vspAGgtK.js","assets/label-Dn4gCMcc.js","assets/socket-hM4c-ZSl.js","assets/socket-CtH3EU9m.js","assets/auth-Bx9fAZmz.js","assets/use-toast-BlLDqSUO.js","assets/LinkToCard-5dg0jvSY.js","assets/useEscapeClose-DR_xKT_k.js","assets/useToastHelpers-CRrpIIdY.js","assets/layer-style-Byl5LNFR.js","assets/color-DFEH4BfK.js","assets/DocumentIcon-x299QNu_.js","assets/use-canvas-pins-CbAxLLTU.js","assets/TodosWidget-CxiqmDuJ.js","assets/ObjectPropertiesCard-BIBMvx_i.js","assets/use-mobile-Db-vWu9Y.js","assets/IdentityFields-Bti7ojF3.js","assets/date-time-picker-DebNUTx3.js","assets/relation-events-CKio19hE.js","assets/map-BxCwdK0d.js","assets/map-BcsP_QXj.css","assets/public-share-g_wBd6BW.js","assets/text-documents-0P9jkIpu.js","assets/blobs-WiXP9QRi.js","assets/useDocumentThumbnail-DunxmU1A.js","assets/markdown-view-BBBZtNSR.js","assets/sanitize-DrVcFY1Q.js","assets/MessageComposerDialog-gbD0Gu_b.js","assets/markdown-it-DRESbtwK.js","assets/punycode.es6-ZbLrB_Dn.js","assets/lazy-editor-BSRnneOo.js","assets/LinkToSidePanel-eCy3nW4R.js","assets/DocumentBodyEditor-8DNmOBS0.js","assets/use-document-modal-PG8bQyIB.js","assets/sketch-lazy-C4pjV1WK.js","assets/geo-CZfs0E-x.js","assets/ObjectPropertiesCard-JArcZXXv.css","assets/document-list-Dsf1DVEx.js","assets/document-open-mode-DoImW-xs.js","assets/PickDocumentsCard-DamtV7fN.js","assets/backend-sync-progress-pZrhQPk3.js","assets/PathPickerField-fZazwxCN.js","assets/backend-sync-progress-DU-e9TWi.css","assets/workspace-access-C9nZlBBZ.js","assets/search-COMZIxA7.js","assets/use-sortable-data-BW_0sXBs.js","assets/workspace-BydSRtST.js","assets/document-list-DAYdk5vh.css","assets/url-params-n7kU_WZ-.js","assets/use-canvas-pins-C57Vbkrq.css","assets/use-menu-BiJ8N7sS.js","assets/last-path-BbXWC3b3.js","assets/workspace-area-menu-CP5OWZNX.js","assets/workspace-content-gate-9okuA7J7.js","assets/UploadProgressList-DRJzjy6A.js","assets/sha256-65KIjGvZ.js","assets/FileForm-CqJpRbXv.js","assets/use-theme-DaxpiICf.js","assets/index-D7EoeBID.css","assets/shared-BQZGA3ph.js","assets/use-applet-docs-D5eXpITp.js","assets/TodosApplet-CleBd4uU.js","assets/LensApplet-5NHmz9TL.js","assets/FiltersApplet--yXjHZqs.js","assets/SketchApplet-DDIg411i.js"])))=>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}from"./preload-helper-Czpn1I53.js";import{St as i,Yr as a,ct as o,it as s,mn as c,tt as l}from"./ui-Byg1cZDr.js";var u=e(n(),1),d=t();function f(e){let t=(0,u.lazy)(e);return function(e){return(0,d.jsx)(u.Suspense,{fallback:(0,d.jsx)(`p`,{className:`p-4 text-sm text-muted-foreground`,role:`status`,children:`Opening app…`}),children:(0,d.jsx)(t,{...e})})}}var p=f(()=>r(()=>import(`./TerminalApplet-wGJG1PPc.js`).then(e=>({default:e.TerminalApplet})),__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14]))),m=f(()=>r(()=>import(`./NotesApplet-bIqcBzpg.js`).then(e=>({default:e.NotesApplet})),__vite__mapDeps([15,1,2,3,4,9,8,6,7,10,11,12,16,13,17,18,19,20,5,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83]))),h=f(()=>r(()=>import(`./TodosApplet-CleBd4uU.js`).then(e=>({default:e.TodosApplet})),__vite__mapDeps([84,1,2,3,4,9,8,6,7,10,11,12,16,13,17,40,20,41,5,82,29,30,31,28,32,33,34,54,83]))),g=f(()=>r(()=>import(`./LensApplet-5NHmz9TL.js`).then(e=>({default:e.LensApplet})),__vite__mapDeps([85,1,2,3,4,9,8,6,7,10,11,12,47,44,34,56,5,13,21,22,23,24,25,26,27,28,29,30,31,32,33,35,36,37,38,39,20,16,17,40,41,42,43,45,46,48,49,50,51,52,53,54,18,19,55,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81]))),_=f(()=>r(()=>import(`./FiltersApplet--yXjHZqs.js`).then(e=>({default:e.FiltersApplet})),__vite__mapDeps([86,1,2,26,11,25,13,5,6,4,7,3,8,9,10,12,21,22,23,24,27,28,29,30,31,32,33,34,35,36,37,38,39,20,16,17,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,18,19,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81]))),v=f(()=>r(()=>import(`./SketchApplet-DDIg411i.js`).then(e=>({default:e.SketchApplet})),__vite__mapDeps([87,1,2,3,4,7,8,9,6,10,11,12,47,44,31,28,57,22,5,13,83,17]))),y=[{id:`terminal`,category:`utilities`,label:`Terminal`,icon:s,modes:[`context`],description:`Shell sessions for this context`,Component:p},{id:`filters`,category:`utilities`,label:`Filters`,icon:o,modes:[`context`,`global`],description:`Search and filter a workspace or a live context`,Component:_},{id:`notes`,category:`productivity`,label:`Notes`,icon:l,modes:[`context`],description:`All notes in the current context, editable in place`,Component:m},{id:`todo`,category:`productivity`,label:`Todos`,icon:c,modes:[`context`],description:`Todos in the current context, done items hidden by default`,Component:h},{id:`sketch`,category:`creative`,label:`Sketch`,icon:a,modes:[`context`],description:`Quick-sketch into the current context; tap a sketch to keep editing`,Component:v},{id:`lens`,category:`media`,label:`Lens`,icon:i,modes:[`context`],description:`Point a camera at things; matching documents surface live`,Component:g}];function b(e){return y.filter(t=>t.modes.includes(e))}export{b as n,y as t};
@@ -1,2 +1,2 @@
1
- import{o as e}from"./rolldown-runtime-C0FnF6B9.js";import{l as t,u as n}from"./code-editor-BOIngd5F.js";import{Fr as r,Ft as i,Ir as a,Nt as o,Or as s,_t as c,ar as l,jr as u,rt as d,vi as f,wt as p}from"./ui-Byg1cZDr.js";import{t as m}from"./button-SgR3GVvV.js";import{t as h}from"./input-BOtCd4HP.js";import{i as g}from"./auth-Bx9fAZmz.js";import{n as _}from"./use-toast-BlLDqSUO.js";import{Pt as v}from"./workspace-DvxC7pw1.js";import{t as y}from"./useEscapeClose-DR_xKT_k.js";import{n as b}from"./page-header-DkOHw0g-.js";import{t as x}from"./role-C5I0Plgn.js";import{t as S}from"./form-panel-C34lByEH.js";import{t as C}from"./use-create-panel-DhSNIGtr.js";var w=e(n(),1),T=t();function E({status:e}){let t={running:{icon:r,color:`text-success`,bg:`bg-success-subtle`,label:`Running`},stopped:{icon:u,color:`text-muted-foreground`,bg:`bg-muted`,label:`Stopped`},starting:{icon:s,color:`text-info`,bg:`bg-info-subtle`,label:`Starting`},stopping:{icon:s,color:`text-warning`,bg:`bg-warning-subtle`,label:`Stopping`},error:{icon:a,color:`text-destructive`,bg:`bg-destructive-subtle`,label:`Error`},created:{icon:f,color:`text-muted-foreground`,bg:`bg-muted`,label:`Created`},configured:{icon:f,color:`text-info`,bg:`bg-info-subtle`,label:`Configured`},removed:{icon:u,color:`text-destructive`,bg:`bg-destructive-subtle`,label:`Removed`}},n=t[e]||t.created,i=n.icon;return(0,T.jsxs)(`span`,{className:`inline-flex items-center gap-1 px-2 py-1 rounded text-xs font-medium ${n.bg} ${n.color}`,children:[(0,T.jsx)(i,{className:`w-3 h-3`}),n.label]})}function D(){let[e,t]=(0,w.useState)([]),[n,r]=(0,w.useState)(!0),[a,u]=(0,w.useState)(null),[f,D]=(0,w.useState)(null);y(()=>D(null),f!==null);let[O,k]=C(),[A,j]=(0,w.useState)([]),[M,N]=(0,w.useState)([]),[P,F]=(0,w.useState)(``),[I,L]=(0,w.useState)(``),[R,z]=(0,w.useState)(``),[B,V]=(0,w.useState)(!1),{showToast:H}=_(),U=g(),W=(0,w.useCallback)(async()=>{try{r(!0);let e=await x.listRoles({type:`workspace`,userId:U?.id});t(e),u(null)}catch(e){let t=e instanceof Error?e.message:`Failed to fetch roles`;u(t)}finally{r(!1)}},[U?.id]);(0,w.useEffect)(()=>{let e=()=>W();e();let t=setInterval(e,3e4);return()=>clearInterval(t)},[W]),(0,w.useEffect)(()=>{O&&(x.listTemplates().then(e=>{let t=e.filter(e=>e.type===`workspace`);j(t),F(e=>e||t[0]?.id||``)}).catch(()=>j([])),v().then(e=>{N(e),z(t=>t||e[0]?.id||``)}).catch(()=>N([])))},[O]);let G=async e=>{if(e.preventDefault(),!(!P||!I.trim()||!R)){V(!0);try{let e=await x.createRole({template:P,name:I.trim(),type:`workspace`,userId:U?.id,workspaceId:R});L(``),k(!1),await W(),H({title:`Created`,description:`Role "${e.name}" created`})}catch(e){H({title:`Error`,description:e instanceof Error?e.message:`Failed to create role`,variant:`destructive`})}finally{V(!1)}}},K=async e=>{try{await x.startRole(e.id),H({title:`Success`,description:`Role "${e.name}" started successfully`}),W()}catch(e){let t=e instanceof Error?e.message:`Failed to start role`;H({title:`Error`,description:t,variant:`destructive`})}},q=async e=>{try{await x.stopRole(e.id),H({title:`Success`,description:`Role "${e.name}" stopped successfully`}),W()}catch(e){let t=e instanceof Error?e.message:`Failed to stop role`;H({title:`Error`,description:t,variant:`destructive`})}},J=async e=>{try{await x.restartRole(e.id),H({title:`Success`,description:`Role "${e.name}" restarted successfully`}),W()}catch(e){let t=e instanceof Error?e.message:`Failed to restart role`;H({title:`Error`,description:t,variant:`destructive`})}},Y=async e=>{try{let t=await x.getRoleLogs(e.id,100);D({role:e,logs:t})}catch(e){let t=e instanceof Error?e.message:`Failed to fetch logs`;H({title:`Error`,description:t,variant:`destructive`})}};return(0,T.jsxs)(`div`,{className:`space-y-6`,children:[(0,T.jsx)(b,{title:`My Roles`,description:`Manage your workspace roles and services`,actions:(0,T.jsxs)(T.Fragment,{children:[!O&&(0,T.jsxs)(m,{onClick:()=>k(!0),children:[(0,T.jsx)(o,{className:`mr-2 h-4 w-4`}),`Create Role`]}),(0,T.jsxs)(m,{onClick:W,variant:`outline`,children:[(0,T.jsx)(p,{className:`mr-2 h-4 w-4`}),`Refresh`]})]})}),O&&(0,T.jsx)(S,{title:`Create New Role`,onClose:()=>k(!1),children:(0,T.jsxs)(`form`,{onSubmit:G,className:`space-y-4`,children:[(0,T.jsxs)(`div`,{className:`grid gap-4 md:grid-cols-2`,children:[(0,T.jsxs)(`div`,{children:[(0,T.jsx)(`label`,{htmlFor:`role-template`,className:`mb-1 block text-sm font-medium`,children:`Template`}),(0,T.jsxs)(`select`,{id:`role-template`,className:`w-full rounded-md border border-border bg-background px-3 py-2`,value:P,onChange:e=>F(e.target.value),disabled:B||A.length===0,children:[A.length===0&&(0,T.jsx)(`option`,{value:``,children:`No workspace templates available`}),A.map(e=>(0,T.jsxs)(`option`,{value:e.id,children:[e.name,` - `,e.description]},e.id))]})]}),(0,T.jsxs)(`div`,{children:[(0,T.jsx)(`label`,{htmlFor:`role-name`,className:`mb-1 block text-sm font-medium`,children:`Role Name`}),(0,T.jsx)(h,{id:`role-name`,value:I,onChange:e=>L(e.target.value),placeholder:`e.g., canvas-sshd`,disabled:B})]})]}),(0,T.jsxs)(`div`,{children:[(0,T.jsx)(`label`,{htmlFor:`role-workspace`,className:`mb-1 block text-sm font-medium`,children:`Workspace`}),(0,T.jsxs)(`select`,{id:`role-workspace`,className:`w-full rounded-md border border-border bg-background px-3 py-2`,value:R,onChange:e=>z(e.target.value),disabled:B||M.length===0,children:[M.length===0&&(0,T.jsx)(`option`,{value:``,children:`No workspaces available. Create one first.`}),M.map(e=>(0,T.jsx)(`option`,{value:e.id,children:e.label||e.name},e.id))]})]}),(0,T.jsxs)(m,{type:`submit`,disabled:B||!P||!I.trim()||!R,children:[(0,T.jsx)(o,{className:`mr-2 h-4 w-4`}),B?`Creating…`:`Create Role`]})]})}),n?(0,T.jsx)(`div`,{className:`text-center py-8`,children:`Loading roles...`}):a?(0,T.jsx)(`div`,{className:`text-center py-8 text-destructive`,children:a}):e.length===0?(0,T.jsxs)(`div`,{className:`text-center py-12 border rounded-lg`,children:[(0,T.jsx)(c,{className:`w-12 h-12 mx-auto text-muted-foreground mb-4`}),(0,T.jsx)(`p`,{className:`text-muted-foreground`,children:`You don't have any workspace roles yet`}),(0,T.jsx)(`p`,{className:`text-sm text-muted-foreground mt-2`,children:`Contact your administrator to set up roles for your workspaces`})]}):(0,T.jsx)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4`,children:e.map(e=>(0,T.jsxs)(`div`,{className:`border rounded-lg p-6 space-y-4 hover:shadow-elevation-2 transition-shadow`,children:[(0,T.jsxs)(`div`,{className:`flex items-start justify-between`,children:[(0,T.jsxs)(`div`,{className:`flex-1`,children:[(0,T.jsx)(`h3`,{className:`font-semibold text-lg`,children:e.name}),(0,T.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:e.template})]}),(0,T.jsx)(E,{status:e.status})]}),e.container&&(0,T.jsx)(`div`,{className:`text-xs text-muted-foreground`,children:(0,T.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,T.jsx)(c,{className:`w-3 h-3`}),(0,T.jsx)(`span`,{className:`truncate`,children:e.container.name})]})}),(0,T.jsxs)(`div`,{className:`flex gap-2 pt-2`,children:[e.status===`stopped`||e.status===`created`?(0,T.jsxs)(m,{size:`sm`,variant:`outline`,onClick:()=>K(e),className:`flex-1`,children:[(0,T.jsx)(i,{className:`w-4 h-4 mr-2`}),`Start`]}):e.status===`running`?(0,T.jsxs)(T.Fragment,{children:[(0,T.jsxs)(m,{size:`sm`,variant:`outline`,onClick:()=>q(e),className:`flex-1`,children:[(0,T.jsx)(d,{className:`w-4 h-4 mr-2`}),`Stop`]}),(0,T.jsxs)(m,{size:`sm`,variant:`outline`,onClick:()=>J(e),className:`flex-1`,children:[(0,T.jsx)(p,{className:`w-4 h-4 mr-2`}),`Restart`]})]}):(0,T.jsxs)(m,{size:`sm`,variant:`outline`,disabled:!0,className:`flex-1`,children:[(0,T.jsx)(s,{className:`w-4 h-4 mr-2`}),e.status]}),(0,T.jsx)(m,{size:`sm`,variant:`outline`,onClick:()=>Y(e),title:`View Logs`,children:(0,T.jsx)(l,{className:`w-4 h-4`})})]})]},e.id))}),(0,T.jsxs)(`div`,{className:`border-t pt-6`,children:[(0,T.jsx)(`h2`,{className:`text-lg font-semibold mb-4`,children:`Global Services`}),(0,T.jsxs)(`div`,{className:`text-sm text-muted-foreground space-y-2`,children:[(0,T.jsx)(`p`,{children:`Global roles are server-wide services managed by your administrator. These include services like SSH access, storage, and other shared infrastructure.`}),(0,T.jsx)(`p`,{children:`To check the status of global services, contact your system administrator.`})]})]}),f&&(0,T.jsx)(`div`,{className:`fixed inset-0 bg-scrim flex items-center justify-center z-50`,children:(0,T.jsxs)(`div`,{className:`bg-background rounded-lg shadow-elevation-3 max-w-4xl w-full mx-4 max-h-viewport-modal flex flex-col`,children:[(0,T.jsxs)(`div`,{className:`p-6 border-b`,children:[(0,T.jsxs)(`h2`,{className:`text-xl font-bold`,children:[f.role.name,` - Logs`]}),(0,T.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:f.role.template})]}),(0,T.jsx)(`div`,{className:`flex-1 overflow-y-auto p-6`,children:(0,T.jsx)(`div`,{"data-scheme":`dark`,className:`bg-background text-success p-4 rounded font-mono text-xs overflow-x-auto`,children:f.logs.length===0?(0,T.jsx)(`div`,{className:`text-muted-foreground`,children:`No logs available`}):(0,T.jsx)(`pre`,{children:f.logs.join(`
1
+ import{o as e}from"./rolldown-runtime-C0FnF6B9.js";import{l as t,u as n}from"./code-editor-BOIngd5F.js";import{Fr as r,Ft as i,Ir as a,Nt as o,Or as s,_t as c,ar as l,jr as u,rt as d,vi as f,wt as p}from"./ui-Byg1cZDr.js";import{t as m}from"./button-SgR3GVvV.js";import{t as h}from"./input-BOtCd4HP.js";import{i as g}from"./auth-Bx9fAZmz.js";import{n as _}from"./use-toast-BlLDqSUO.js";import{Pt as v}from"./workspace-CrSpR4xf.js";import{t as y}from"./useEscapeClose-DR_xKT_k.js";import{n as b}from"./page-header-DkOHw0g-.js";import{t as x}from"./role-C5I0Plgn.js";import{t as S}from"./form-panel-C34lByEH.js";import{t as C}from"./use-create-panel-DhSNIGtr.js";var w=e(n(),1),T=t();function E({status:e}){let t={running:{icon:r,color:`text-success`,bg:`bg-success-subtle`,label:`Running`},stopped:{icon:u,color:`text-muted-foreground`,bg:`bg-muted`,label:`Stopped`},starting:{icon:s,color:`text-info`,bg:`bg-info-subtle`,label:`Starting`},stopping:{icon:s,color:`text-warning`,bg:`bg-warning-subtle`,label:`Stopping`},error:{icon:a,color:`text-destructive`,bg:`bg-destructive-subtle`,label:`Error`},created:{icon:f,color:`text-muted-foreground`,bg:`bg-muted`,label:`Created`},configured:{icon:f,color:`text-info`,bg:`bg-info-subtle`,label:`Configured`},removed:{icon:u,color:`text-destructive`,bg:`bg-destructive-subtle`,label:`Removed`}},n=t[e]||t.created,i=n.icon;return(0,T.jsxs)(`span`,{className:`inline-flex items-center gap-1 px-2 py-1 rounded text-xs font-medium ${n.bg} ${n.color}`,children:[(0,T.jsx)(i,{className:`w-3 h-3`}),n.label]})}function D(){let[e,t]=(0,w.useState)([]),[n,r]=(0,w.useState)(!0),[a,u]=(0,w.useState)(null),[f,D]=(0,w.useState)(null);y(()=>D(null),f!==null);let[O,k]=C(),[A,j]=(0,w.useState)([]),[M,N]=(0,w.useState)([]),[P,F]=(0,w.useState)(``),[I,L]=(0,w.useState)(``),[R,z]=(0,w.useState)(``),[B,V]=(0,w.useState)(!1),{showToast:H}=_(),U=g(),W=(0,w.useCallback)(async()=>{try{r(!0);let e=await x.listRoles({type:`workspace`,userId:U?.id});t(e),u(null)}catch(e){let t=e instanceof Error?e.message:`Failed to fetch roles`;u(t)}finally{r(!1)}},[U?.id]);(0,w.useEffect)(()=>{let e=()=>W();e();let t=setInterval(e,3e4);return()=>clearInterval(t)},[W]),(0,w.useEffect)(()=>{O&&(x.listTemplates().then(e=>{let t=e.filter(e=>e.type===`workspace`);j(t),F(e=>e||t[0]?.id||``)}).catch(()=>j([])),v().then(e=>{N(e),z(t=>t||e[0]?.id||``)}).catch(()=>N([])))},[O]);let G=async e=>{if(e.preventDefault(),!(!P||!I.trim()||!R)){V(!0);try{let e=await x.createRole({template:P,name:I.trim(),type:`workspace`,userId:U?.id,workspaceId:R});L(``),k(!1),await W(),H({title:`Created`,description:`Role "${e.name}" created`})}catch(e){H({title:`Error`,description:e instanceof Error?e.message:`Failed to create role`,variant:`destructive`})}finally{V(!1)}}},K=async e=>{try{await x.startRole(e.id),H({title:`Success`,description:`Role "${e.name}" started successfully`}),W()}catch(e){let t=e instanceof Error?e.message:`Failed to start role`;H({title:`Error`,description:t,variant:`destructive`})}},q=async e=>{try{await x.stopRole(e.id),H({title:`Success`,description:`Role "${e.name}" stopped successfully`}),W()}catch(e){let t=e instanceof Error?e.message:`Failed to stop role`;H({title:`Error`,description:t,variant:`destructive`})}},J=async e=>{try{await x.restartRole(e.id),H({title:`Success`,description:`Role "${e.name}" restarted successfully`}),W()}catch(e){let t=e instanceof Error?e.message:`Failed to restart role`;H({title:`Error`,description:t,variant:`destructive`})}},Y=async e=>{try{let t=await x.getRoleLogs(e.id,100);D({role:e,logs:t})}catch(e){let t=e instanceof Error?e.message:`Failed to fetch logs`;H({title:`Error`,description:t,variant:`destructive`})}};return(0,T.jsxs)(`div`,{className:`space-y-6`,children:[(0,T.jsx)(b,{title:`My Roles`,description:`Manage your workspace roles and services`,actions:(0,T.jsxs)(T.Fragment,{children:[!O&&(0,T.jsxs)(m,{onClick:()=>k(!0),children:[(0,T.jsx)(o,{className:`mr-2 h-4 w-4`}),`Create Role`]}),(0,T.jsxs)(m,{onClick:W,variant:`outline`,children:[(0,T.jsx)(p,{className:`mr-2 h-4 w-4`}),`Refresh`]})]})}),O&&(0,T.jsx)(S,{title:`Create New Role`,onClose:()=>k(!1),children:(0,T.jsxs)(`form`,{onSubmit:G,className:`space-y-4`,children:[(0,T.jsxs)(`div`,{className:`grid gap-4 md:grid-cols-2`,children:[(0,T.jsxs)(`div`,{children:[(0,T.jsx)(`label`,{htmlFor:`role-template`,className:`mb-1 block text-sm font-medium`,children:`Template`}),(0,T.jsxs)(`select`,{id:`role-template`,className:`w-full rounded-md border border-border bg-background px-3 py-2`,value:P,onChange:e=>F(e.target.value),disabled:B||A.length===0,children:[A.length===0&&(0,T.jsx)(`option`,{value:``,children:`No workspace templates available`}),A.map(e=>(0,T.jsxs)(`option`,{value:e.id,children:[e.name,` - `,e.description]},e.id))]})]}),(0,T.jsxs)(`div`,{children:[(0,T.jsx)(`label`,{htmlFor:`role-name`,className:`mb-1 block text-sm font-medium`,children:`Role Name`}),(0,T.jsx)(h,{id:`role-name`,value:I,onChange:e=>L(e.target.value),placeholder:`e.g., canvas-sshd`,disabled:B})]})]}),(0,T.jsxs)(`div`,{children:[(0,T.jsx)(`label`,{htmlFor:`role-workspace`,className:`mb-1 block text-sm font-medium`,children:`Workspace`}),(0,T.jsxs)(`select`,{id:`role-workspace`,className:`w-full rounded-md border border-border bg-background px-3 py-2`,value:R,onChange:e=>z(e.target.value),disabled:B||M.length===0,children:[M.length===0&&(0,T.jsx)(`option`,{value:``,children:`No workspaces available. Create one first.`}),M.map(e=>(0,T.jsx)(`option`,{value:e.id,children:e.label||e.name},e.id))]})]}),(0,T.jsxs)(m,{type:`submit`,disabled:B||!P||!I.trim()||!R,children:[(0,T.jsx)(o,{className:`mr-2 h-4 w-4`}),B?`Creating…`:`Create Role`]})]})}),n?(0,T.jsx)(`div`,{className:`text-center py-8`,children:`Loading roles...`}):a?(0,T.jsx)(`div`,{className:`text-center py-8 text-destructive`,children:a}):e.length===0?(0,T.jsxs)(`div`,{className:`text-center py-12 border rounded-lg`,children:[(0,T.jsx)(c,{className:`w-12 h-12 mx-auto text-muted-foreground mb-4`}),(0,T.jsx)(`p`,{className:`text-muted-foreground`,children:`You don't have any workspace roles yet`}),(0,T.jsx)(`p`,{className:`text-sm text-muted-foreground mt-2`,children:`Contact your administrator to set up roles for your workspaces`})]}):(0,T.jsx)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4`,children:e.map(e=>(0,T.jsxs)(`div`,{className:`border rounded-lg p-6 space-y-4 hover:shadow-elevation-2 transition-shadow`,children:[(0,T.jsxs)(`div`,{className:`flex items-start justify-between`,children:[(0,T.jsxs)(`div`,{className:`flex-1`,children:[(0,T.jsx)(`h3`,{className:`font-semibold text-lg`,children:e.name}),(0,T.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:e.template})]}),(0,T.jsx)(E,{status:e.status})]}),e.container&&(0,T.jsx)(`div`,{className:`text-xs text-muted-foreground`,children:(0,T.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,T.jsx)(c,{className:`w-3 h-3`}),(0,T.jsx)(`span`,{className:`truncate`,children:e.container.name})]})}),(0,T.jsxs)(`div`,{className:`flex gap-2 pt-2`,children:[e.status===`stopped`||e.status===`created`?(0,T.jsxs)(m,{size:`sm`,variant:`outline`,onClick:()=>K(e),className:`flex-1`,children:[(0,T.jsx)(i,{className:`w-4 h-4 mr-2`}),`Start`]}):e.status===`running`?(0,T.jsxs)(T.Fragment,{children:[(0,T.jsxs)(m,{size:`sm`,variant:`outline`,onClick:()=>q(e),className:`flex-1`,children:[(0,T.jsx)(d,{className:`w-4 h-4 mr-2`}),`Stop`]}),(0,T.jsxs)(m,{size:`sm`,variant:`outline`,onClick:()=>J(e),className:`flex-1`,children:[(0,T.jsx)(p,{className:`w-4 h-4 mr-2`}),`Restart`]})]}):(0,T.jsxs)(m,{size:`sm`,variant:`outline`,disabled:!0,className:`flex-1`,children:[(0,T.jsx)(s,{className:`w-4 h-4 mr-2`}),e.status]}),(0,T.jsx)(m,{size:`sm`,variant:`outline`,onClick:()=>Y(e),title:`View Logs`,children:(0,T.jsx)(l,{className:`w-4 h-4`})})]})]},e.id))}),(0,T.jsxs)(`div`,{className:`border-t pt-6`,children:[(0,T.jsx)(`h2`,{className:`text-lg font-semibold mb-4`,children:`Global Services`}),(0,T.jsxs)(`div`,{className:`text-sm text-muted-foreground space-y-2`,children:[(0,T.jsx)(`p`,{children:`Global roles are server-wide services managed by your administrator. These include services like SSH access, storage, and other shared infrastructure.`}),(0,T.jsx)(`p`,{children:`To check the status of global services, contact your system administrator.`})]})]}),f&&(0,T.jsx)(`div`,{className:`fixed inset-0 bg-scrim flex items-center justify-center z-50`,children:(0,T.jsxs)(`div`,{className:`bg-background rounded-lg shadow-elevation-3 max-w-4xl w-full mx-4 max-h-viewport-modal flex flex-col`,children:[(0,T.jsxs)(`div`,{className:`p-6 border-b`,children:[(0,T.jsxs)(`h2`,{className:`text-xl font-bold`,children:[f.role.name,` - Logs`]}),(0,T.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:f.role.template})]}),(0,T.jsx)(`div`,{className:`flex-1 overflow-y-auto p-6`,children:(0,T.jsx)(`div`,{"data-scheme":`dark`,className:`bg-background text-success p-4 rounded font-mono text-xs overflow-x-auto`,children:f.logs.length===0?(0,T.jsx)(`div`,{className:`text-muted-foreground`,children:`No logs available`}):(0,T.jsx)(`pre`,{children:f.logs.join(`
2
2
  `)})})}),(0,T.jsx)(`div`,{className:`p-4 border-t flex justify-end`,children:(0,T.jsx)(m,{onClick:()=>D(null),children:`Close`})})]})})]})}export{D as default};