@augmentd-labs/canvas-web 2.26.43 → 2.26.45

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 (119) hide show
  1. package/dist/assets/CalendarApplet-CsyUmI2B.js +2 -0
  2. package/dist/assets/{DocumentBodyEditor-CVO5KPCs.js → DocumentBodyEditor-C8AEpqX3.js} +1 -1
  3. package/dist/assets/{DocumentIcon-9i1uCMQa.js → DocumentIcon-0ya9gycp.js} +1 -1
  4. package/dist/assets/{EditorOverlay-D5t3xg4w.js → EditorOverlay-DglJkHo3.js} +1 -1
  5. package/dist/assets/{FiltersApplet-gQ6jhX7q.js → FiltersApplet-CVnCAs-P.js} +1 -1
  6. package/dist/assets/HomeFab-iC5BF7LV.js +3 -0
  7. package/dist/assets/{IdentityFields-D-NCTUaE.js → IdentityFields-CB3Ap0bl.js} +1 -1
  8. package/dist/assets/{LensApplet-WFygUZx1.js → LensApplet-DA0ZWS1k.js} +1 -1
  9. package/dist/assets/LinkToCard-oi3wGP0a.js +1 -0
  10. package/dist/assets/{MarkdownEditor-DbpRWbO6.js → MarkdownEditor-bDoyR7l2.js} +2 -2
  11. package/dist/assets/{MessageComposerDialog-CdPp-3GR.js → MessageComposerDialog-CLrwtB76.js} +1 -1
  12. package/dist/assets/{NextShell-ull6WmMg.js → NextShell-DCWxD5TR.js} +1 -1
  13. package/dist/assets/{NotesApplet-D8cseekh.js → NotesApplet-BSJ-9RKl.js} +1 -1
  14. package/dist/assets/ObjectPropertiesCard-DesXRw-_.js +8 -0
  15. package/dist/assets/{PathPickerField-CW2yG2Yg.js → PathPickerField-CSIa7jSl.js} +1 -1
  16. package/dist/assets/PickDocumentsCard-DVdBxx3s.js +1 -0
  17. package/dist/assets/{SketchApplet-BKnhzTBA.js → SketchApplet--3uyqpmo.js} +1 -1
  18. package/dist/assets/{SketchEditor-DmGMcbU0.js → SketchEditor-CSA7dTyq.js} +2 -2
  19. package/dist/assets/{TerminalApplet-D7YxftqM.js → TerminalApplet-BZJx2ztD.js} +1 -1
  20. package/dist/assets/{TextDocumentEditor-BQnVD0dd.js → TextDocumentEditor-VYIF2XCX.js} +1 -1
  21. package/dist/assets/{TodosApplet-DU5VWc5i.js → TodosApplet-DY7JzeZS.js} +1 -1
  22. package/dist/assets/{TodosWidget-CNnfNk4L.js → TodosWidget-DGftEAbs.js} +1 -1
  23. package/dist/assets/{_agentId_-DVR-2m5A.js → _agentId_-BrzFDu8r.js} +0 -0
  24. package/dist/assets/{_contextId_-BofzZDP6.js → _contextId_-DS6b9Uml.js} +1 -1
  25. package/dist/assets/_workspaceName_-XRqfa4c6.js +1 -0
  26. package/dist/assets/{about-lxN3BXmR.js → about-hcdKJNm5.js} +1 -1
  27. package/dist/assets/{add-LFFQQgj3.js → add-CEBusWuu.js} +1 -1
  28. package/dist/assets/{agents-DxqAi3vk.js → agents-BfSFdg41.js} +1 -1
  29. package/dist/assets/{agents-DHexvztp.js → agents-wFp7Vh3p.js} +1 -1
  30. package/dist/assets/{alert-dialog-CFeuDt0T.js → alert-dialog-BKtaX1_a.js} +1 -1
  31. package/dist/assets/{api-tokens-drrVuCYc.js → api-tokens-Biqt5TnG.js} +1 -1
  32. package/dist/assets/{appearance-0-j0SAoe.js → appearance-D5BUjZm8.js} +1 -1
  33. package/dist/assets/{applet-target-pLdP-R76.js → applet-target-LvhUEvE5.js} +1 -1
  34. package/dist/assets/{apps-ylUU3K5c.js → apps-65YXCnzH.js} +1 -1
  35. package/dist/assets/{auth-PqttD05H.js → auth-BwxT5xRB.js} +1 -1
  36. package/dist/assets/{button-SeUZ_Pvi.js → button--VYZekMF.js} +1 -1
  37. package/dist/assets/{context-t3rdtGUB.js → context-DY40EDc6.js} +1 -1
  38. package/dist/assets/{contexts-DDJagU4j.js → contexts-BPO_Wb9W.js} +1 -1
  39. package/dist/assets/{contexts-Bq8LHUTK2.js → contexts-DBJ0_-AO2.js} +1 -1
  40. package/dist/assets/{date-time-picker-DCikruos.js → date-time-picker-p3vy4nst.js} +1 -1
  41. package/dist/assets/{devices-BwU9M8-W.js → devices-DZbbaWYU.js} +1 -1
  42. package/dist/assets/{document-Cr7GhnVd.js → document-Dv8NCUoM.js} +1 -1
  43. package/dist/assets/document-list-Bbbx-pTZ.js +3 -0
  44. package/dist/assets/document-paste-BuTC6S7_.js +1 -0
  45. package/dist/assets/{embedding-D-I_ygUZ.js → embedding-B9vSy_a9.js} +1 -1
  46. package/dist/assets/{embedding-BvXcVfij.js → embedding-M2hUmnk0.js} +1 -1
  47. package/dist/assets/{form-panel-3p-ncEVK.js → form-panel-CEbNKttr.js} +1 -1
  48. package/dist/assets/{home-CfYR15C5.js → home-vr8b8oR-.js} +1 -1
  49. package/dist/assets/index-CTvqbEB8.js +16 -0
  50. package/dist/assets/index-CoVFQpP3.css +2 -0
  51. package/dist/assets/{inferd-config-editor-B8x_XPOt.js → inferd-config-editor-Dpdj90iN.js} +1 -1
  52. package/dist/assets/{key-bindings-DAIw70SC.js → key-bindings-DmqvYSaF.js} +1 -1
  53. package/dist/assets/{label-BSTdjCWU.js → label-RuOXXC8t.js} +1 -1
  54. package/dist/assets/{lazy-editor-BUFAkTGl.js → lazy-editor-CShGeIep.js} +2 -2
  55. package/dist/assets/{logs-DjG8_wJ2.js → logs-7eSz9yjc.js} +1 -1
  56. package/dist/assets/{offline-ByoT6JJX.js → offline-C-Yvb6LA.js} +1 -1
  57. package/dist/assets/{page-header-DrDt1sQ2.js → page-header-NyYSXjfY.js} +1 -1
  58. package/dist/assets/{public-share-CXR25Q1X.js → public-share-0DqS7L2Q.js} +1 -1
  59. package/dist/assets/{query-debug-lD5vbJGi.js → query-debug-PEWbZsOP.js} +1 -1
  60. package/dist/assets/registry-g1SKt_fD.js +2 -0
  61. package/dist/assets/{remotes-RPGcw6fH.js → remotes-DqCLds8Q.js} +1 -1
  62. package/dist/assets/{roles-sb8vgjV_.js → roles-BwVDE1aQ.js} +1 -1
  63. package/dist/assets/{roles-p2cRajz-.js → roles-W7oJ5WMg.js} +1 -1
  64. package/dist/assets/rule-builder-CziPqpNe.js +6 -0
  65. package/dist/assets/settings-BIoSwdXv.js +16 -0
  66. package/dist/assets/{settings-C5cS_cw0.js → settings-BWCMmkjr.js} +1 -1
  67. package/dist/assets/{settings-Bojeuvgh.js → settings-CbMkpipO.js} +1 -1
  68. package/dist/assets/settings-XMhqrvTu.js +1 -0
  69. package/dist/assets/{share-target-PgtwhQo-.js → share-target-hDXdgW6o.js} +1 -1
  70. package/dist/assets/{shared-BLOuO2Is.js → shared-CLjTxih0.js} +1 -1
  71. package/dist/assets/{shared-fdwDs5-g.js → shared-DVlDThVA.js} +1 -1
  72. package/dist/assets/sketch-lazy-CtjOUfVz.js +2 -0
  73. package/dist/assets/{subtree-transfer-dialog-DQM5zfx2.js → subtree-transfer-dialog-DtE6JSUr.js} +1 -1
  74. package/dist/assets/{text-documents-Cdb3U63i.js → text-documents-wu6fzOuw.js} +2 -2
  75. package/dist/assets/tree-folders-IDoobsGN.js +1 -0
  76. package/dist/assets/ui-DEgHnkQu.js +41 -0
  77. package/dist/assets/{use-applet-docs-rimRHjID.js → use-applet-docs-C08GAUm3.js} +1 -1
  78. package/dist/assets/{use-applet-target-BygCSj5n.js → use-applet-target-BlpVWlnA.js} +1 -1
  79. package/dist/assets/{use-canvas-pins-Bmj8upH3.js → use-canvas-pins-q5Tncavk.js} +2 -2
  80. package/dist/assets/{use-menu-DIP1zh7I.js → use-menu-CKSpS96u.js} +1 -1
  81. package/dist/assets/use-settings-back-D_MM9diy.js +1 -0
  82. package/dist/assets/{use-sortable-data-BBKmqs79.js → use-sortable-data-D7zS2qCC.js} +1 -1
  83. package/dist/assets/{use-workspace-identity-CSkRwVyo.js → use-workspace-identity-XSv3dATQ.js} +1 -1
  84. package/dist/assets/{useAddTarget-DeRZWtGg.js → useAddTarget-BvuFR5pN.js} +1 -1
  85. package/dist/assets/{useAgentModels-DLjVm0T8.js → useAgentModels-CI9XT6yc.js} +1 -1
  86. package/dist/assets/{useDocumentThumbnail-Cj4UYyhC.js → useDocumentThumbnail-CZIaXkIi.js} +1 -1
  87. package/dist/assets/{useEditNoteFields-BT1ASu_q.js → useEditNoteFields-DsVKIHWm.js} +1 -1
  88. package/dist/assets/{users-DuVk-TEd.js → users-DzlbKZp6.js} +1 -1
  89. package/dist/assets/workspace-4hWrSEku.js +1 -0
  90. package/dist/assets/{workspace-content-gate-C54J9Man.js → workspace-content-gate-BlFdbi67.js} +1 -1
  91. package/dist/assets/{workspace-import-form-DTvV9jYt.js → workspace-import-form-CWs9ZTts.js} +1 -1
  92. package/dist/assets/{workspaces-CqHYstZv.js → workspaces-67v2hWrl.js} +1 -1
  93. package/dist/assets/workspaces-ByYQ6L3I.js +1 -0
  94. package/dist/index.html +36 -38
  95. package/dist/sw.js +1 -1
  96. package/package.json +2 -2
  97. package/dist/assets/CalendarApplet-JRMqt67k.js +0 -2
  98. package/dist/assets/FileForm-CDiVKvxq.js +0 -1
  99. package/dist/assets/HomeFab-Bp9cpmps.js +0 -3
  100. package/dist/assets/LinkToCard-CKVi4Nrg.js +0 -1
  101. package/dist/assets/ObjectPropertiesCard-D2lrTQqT.js +0 -8
  102. package/dist/assets/PickDocumentsCard-BWgc-A02.js +0 -1
  103. package/dist/assets/UploadProgressList-D2wEpa7t.js +0 -1
  104. package/dist/assets/_workspaceName_-Ds__P3h9.js +0 -1
  105. package/dist/assets/backend-sync-progress-Dp12uN4y.js +0 -6
  106. package/dist/assets/document-list-BLu9S0zR.js +0 -3
  107. package/dist/assets/index-BNP_llN_.js +0 -16
  108. package/dist/assets/index-CYvpxvg6.css +0 -2
  109. package/dist/assets/registry-H_3ckTyM.js +0 -2
  110. package/dist/assets/settings-COqQc1hP.js +0 -16
  111. package/dist/assets/settings-DziSEdYH.js +0 -1
  112. package/dist/assets/sketch-lazy-BY_ka1hw.js +0 -2
  113. package/dist/assets/tree-folders-Da9k9cbV.js +0 -1
  114. package/dist/assets/ui-CDoK3F3U.js +0 -41
  115. package/dist/assets/use-settings-back-DGmLAD63.js +0 -1
  116. package/dist/assets/workspace-C5V-ZCOE.js +0 -1
  117. package/dist/assets/workspace-area-menu-LLSySOlH.js +0 -1
  118. package/dist/assets/workspaces-DxvxX0wQ.js +0 -1
  119. /package/dist/assets/{backend-sync-progress-DU-e9TWi.css → rule-builder-DU-e9TWi.css} +0 -0
@@ -1 +0,0 @@
1
- import{o as e}from"./rolldown-runtime-C0FnF6B9.js";import{l as t,u as n}from"./code-editor-BOIngd5F.js";import{_t as r,yt as i}from"./react-BHzhHVTZ.js";import{Bn as a,L as o,Lt as s,Ur as ee,Vr as c,Wn as l,Zn as u,mt as d,qn as f,vn as p,wr as m,yt as h}from"./ui-CDoK3F3U.js";import{t as g}from"./utils-2pl1SbIp.js";import{t as _}from"./button-SeUZ_Pvi.js";import{Dn as v,G as te,Tt as y,W as b,X as x,jt as S,mt as C,nt as ne,pt as re,yn as ie}from"./workspace-C5V-ZCOE.js";import{t as w}from"./useEscapeClose-DR_xKT_k.js";import{t as ae}from"./useToastHelpers-CRrpIIdY.js";import{s as T}from"./layer-style-Byl5LNFR.js";import{i as E}from"./color-DFEH4BfK.js";import{t as oe}from"./DocumentIcon-9i1uCMQa.js";var D=e(n(),1),O=t();function k({className:e=`h-5 w-5`,...t}){return(0,O.jsxs)(`svg`,{className:`animate-spin ${e}`,xmlns:`http://www.w3.org/2000/svg`,fill:`none`,viewBox:`0 0 24 24`,...t,children:[(0,O.jsx)(`circle`,{className:`opacity-25`,cx:`12`,cy:`12`,r:`10`,stroke:`currentColor`,strokeWidth:`4`}),(0,O.jsx)(`path`,{className:`opacity-75`,fill:`currentColor`,d:`M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z`})]})}var A=e(i(),1);function j(e){let[t,n]=(0,D.useState)(null);(0,D.useEffect)(()=>{if(!e)return;let t=!1;return x(e).then(r=>{t||n({workspaceId:e,predicates:r,error:!1})},()=>{t||n({workspaceId:e,predicates:[],error:!0})}),()=>{t=!0}},[e]);let r=t?.workspaceId===e?t:null;return{predicates:r?.predicates??[],error:r?.error??!1,loading:!!e&&!r}}function M({x:e,y:t,onClose:n,className:r,children:i}){let a=(0,D.useRef)(null),[o,s]=(0,D.useState)({x:e,y:t});return w(n),(0,D.useLayoutEffect)(()=>{let n=a.current;if(!n)return;let{width:r,height:i}=n.getBoundingClientRect();s({x:Math.max(8,Math.min(e,window.innerWidth-r-8)),y:Math.max(8,Math.min(t,window.innerHeight-i-8))})},[e,t]),(0,A.createPortal)((0,O.jsxs)(O.Fragment,{children:[(0,O.jsx)(`div`,{className:`fixed inset-0 z-menu-scrim`,onClick:n,onContextMenu:e=>{e.preventDefault(),n()}}),(0,O.jsx)(`div`,{ref:a,style:{left:o.x,top:o.y},className:g(`fixed z-menu max-h-viewport-modal overflow-y-auto`,r,`bg-popover text-popover-foreground`),children:i})]}),document.body)}var N=typeof navigator<`u`&&/Mac|iPhone|iPad/.test(navigator.platform||navigator.userAgent),P={Delete:`Del`,Backspace:`⌫`,Enter:`↵`,ArrowUp:`↑`,ArrowDown:`↓`};function F(e){let t=e.split(`+`),n=t.pop()||``,r=P[n]||(n.length===1?n.toUpperCase():n);if(N){let e={Mod:`⌘`,Shift:`⇧`,Alt:`⌥`,Ctrl:`⌃`};return[...[`Ctrl`,`Alt`,`Shift`,`Mod`].filter(e=>t.includes(e)).map(t=>e[t]),r].join(``)}return[...t.map(e=>e===`Mod`?`Ctrl`:e),r].join(`+`)}function se(e,t){let n=t.split(`+`),r=n.pop()||``;return(N?e.metaKey:e.ctrlKey)!==n.includes(`Mod`)||e.shiftKey!==n.includes(`Shift`)||e.altKey!==n.includes(`Alt`)||N&&e.ctrlKey!==n.includes(`Ctrl`)?!1:r.length===1?e.key.toLowerCase()===r.toLowerCase():e.key===r}function I(e){if(e?.closest?.(`input, textarea, select, [contenteditable="true"], [role="dialog"], [role="menu"]`))return!0;let t=typeof window<`u`?window.getSelection():null;return!!t&&!t.isCollapsed&&t.toString().length>0}function L(e,t){if(e.defaultPrevented||e.nativeEvent.isComposing||I(e.target))return!1;let n=t.find(t=>t.shortcut&&!t.disabled&&se(e,t.shortcut));return n?(e.preventDefault(),e.stopPropagation(),n.run({shiftKey:e.shiftKey}),!0):!1}function R(e){return e.key===`ContextMenu`||e.key===`F10`&&e.shiftKey}function ce(){return typeof window<`u`&&window.matchMedia(`(max-width: 767px)`).matches}function z(e,t=`below`){let n=e.getBoundingClientRect();return t===`below`?{x:n.left,y:n.bottom+4}:{x:n.left+Math.min(24,n.width/2),y:n.top+Math.min(24,n.height/2)}}function B(e){let t=[];for(let n of e){let e=t[t.length-1];e&&(e[0].group??``)===(n.group??``)?e.push(n):t.push([n])}return t}function le(e,t,n){t(),setTimeout(()=>{e.run({shiftKey:n})},0)}function ue({anchor:e,items:t,onClose:n,label:r}){let i=(0,D.useRef)(null);return(0,D.useEffect)(()=>{let e=document.activeElement;return i.current?.querySelector(`[role="menuitem"]:not([aria-disabled="true"])`)?.focus(),()=>{e?.isConnected&&e.focus({preventScroll:!0})}},[]),(0,O.jsx)(M,{x:e.x,y:e.y,onClose:n,className:`min-w-[200px] rounded-lg border bg-popover text-popover-foreground py-1 shadow-elevation-3`,children:(0,O.jsx)(`div`,{ref:i,role:`menu`,"aria-label":r,onKeyDown:e=>{let t=Array.from(i.current?.querySelectorAll(`[role="menuitem"]:not([aria-disabled="true"])`)??[]);if(t.length===0)return;let r=t.indexOf(document.activeElement),a=e=>t[(e+t.length)%t.length]?.focus();switch(e.key){case`ArrowDown`:e.preventDefault(),a(r+1);return;case`ArrowUp`:e.preventDefault(),a(r<0?-1:r-1);return;case`Home`:e.preventDefault(),a(0);return;case`End`:e.preventDefault(),a(-1);return;case`Tab`:e.preventDefault(),n();return}if(e.key.length===1&&!e.ctrlKey&&!e.metaKey&&!e.altKey){let n=e.key.toLowerCase(),i=[...t.slice(r+1),...t.slice(0,r+1)].find(e=>e.textContent?.trim().toLowerCase().startsWith(n));i&&(e.preventDefault(),i.focus())}},onContextMenu:e=>e.preventDefault(),children:B(t).map((e,t)=>(0,O.jsxs)(D.Fragment,{children:[t>0&&(0,O.jsx)(`div`,{role:`separator`,className:`my-1 h-px bg-border`}),e[0].groupLabel&&(0,O.jsx)(`div`,{className:`px-3 py-1 text-[10px] font-medium uppercase tracking-wide text-muted-foreground`,children:e[0].groupLabel}),e.map(e=>{let t=e.icon;return(0,O.jsxs)(`button`,{type:`button`,role:`menuitem`,tabIndex:-1,"aria-disabled":e.disabled||void 0,title:e.hint,onClick:t=>{e.disabled||le(e,n,t.shiftKey)},className:g(`flex w-full items-center gap-2 px-3 py-1.5 text-left text-sm outline-none`,e.disabled?`cursor-default opacity-50`:e.destructive?`text-destructive hover:bg-destructive hover:text-destructive-foreground focus:bg-destructive focus:text-destructive-foreground`:`hover:bg-muted focus:bg-muted`),children:[t?(0,O.jsx)(t,{className:`h-3.5 w-3.5 shrink-0`}):(0,O.jsx)(`span`,{className:`w-3.5 shrink-0`}),(0,O.jsx)(`span`,{className:`flex-1 truncate`,children:e.label}),e.shortcut&&(0,O.jsx)(`kbd`,{className:`ml-4 shrink-0 font-sans text-[11px] text-muted-foreground`,children:F(e.shortcut)})]},e.id)})]},`${e[0].group??``}:${t}`))})})}function V({items:e,onClose:t,header:n}){w(t);let r=`flex w-full items-center gap-3 rounded-xl border bg-card px-4 py-3.5 text-base font-medium transition-transform active:scale-[.98]`;return(0,A.createPortal)((0,O.jsxs)(`div`,{role:`dialog`,"aria-modal":`true`,className:`fixed inset-0 z-fullscreen flex flex-col bg-popover text-popover-foreground animate-in slide-in-from-bottom-10 fade-in duration-normal`,onClick:t,onContextMenu:e=>e.preventDefault(),children:[(0,O.jsxs)(`div`,{className:`flex shrink-0 items-start gap-3 border-b p-4`,onClick:e=>e.stopPropagation(),children:[(0,O.jsx)(`div`,{className:`min-w-0 flex-1`,children:n}),(0,O.jsx)(`button`,{type:`button`,onClick:t,className:`rounded-sm p-2 hover:bg-muted`,title:`Close`,"aria-label":`Close`,children:(0,O.jsx)(o,{className:`h-5 w-5`})})]}),(0,O.jsx)(`div`,{className:`min-h-4 flex-1`}),(0,O.jsxs)(`div`,{className:`max-h-[75vh] shrink-0 space-y-2 overflow-y-auto px-4 pt-2`,style:{paddingBottom:`calc(var(--safe-bottom) + 1.25rem)`},onClick:e=>e.stopPropagation(),children:[B(e).map((e,n)=>(0,O.jsxs)(`div`,{className:g(`space-y-2`,n>0&&`pt-2`),children:[e[0].groupLabel&&(0,O.jsx)(`div`,{className:`px-1 text-[11px] font-medium uppercase tracking-wide text-muted-foreground`,children:e[0].groupLabel}),e.map(e=>{let n=e.icon;return(0,O.jsxs)(`button`,{type:`button`,disabled:e.disabled,onClick:n=>le(e,t,n.shiftKey),className:g(r,e.destructive&&`border-destructive/30 text-destructive`,e.disabled&&`opacity-50`),children:[n&&(0,O.jsx)(n,{className:g(`h-5 w-5 shrink-0`,!e.destructive&&`text-muted-foreground`)}),e.label]},e.id)})]},`${e[0].group??``}:${n}`)),(0,O.jsx)(`button`,{type:`button`,onClick:t,className:`${r} justify-center bg-muted`,children:`Cancel`})]})]}),window.document.body)}function de({anchor:e,items:t,onClose:n,label:r,header:i}){return t.length===0?null:ce()?(0,O.jsx)(V,{items:t,onClose:n,header:i??(r&&(0,O.jsx)(`div`,{className:`truncate text-base font-semibold`,children:r}))}):(0,O.jsx)(ue,{anchor:e,items:t,onClose:n,label:r})}function H({items:e,onNavigate:t,disabled:n,className:r,label:i=`Tree path`}){let a=(0,D.useRef)(null),o=e[e.length-1]?.path;return(0,D.useEffect)(()=>{let e=a.current;e&&(e.scrollLeft=e.scrollWidth)},[o]),(0,O.jsx)(`nav`,{"aria-label":i,className:g(`min-w-0 flex-1`,r),children:(0,O.jsx)(`ol`,{ref:a,className:`flex min-w-0 items-center gap-1 overflow-x-auto py-0.5 text-sm`,children:e.map((r,i)=>{let a=i===e.length-1,o=g(`block max-w-56 truncate rounded px-1.5 py-1`,a?`font-medium text-foreground`:`text-muted-foreground`);return(0,O.jsxs)(`li`,{className:`flex shrink-0 items-center gap-1`,children:[i>0&&(0,O.jsx)(`span`,{"aria-hidden":`true`,className:`text-muted-foreground/60`,children:`/`}),t&&!a?(0,O.jsx)(`button`,{type:`button`,title:r.path===`/`?`${r.label} (root)`:r.path,disabled:n,onClick:()=>t(r.path),className:g(o,`hover:bg-accent hover:text-foreground hover:underline focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring disabled:opacity-50`),children:r.label}):(0,O.jsx)(`span`,{title:r.path===`/`?r.label:r.path,"aria-current":a?`location`:void 0,className:o,children:r.label})]},r.path)})})})}function U(e,t){let n=e.split(`/`).filter(Boolean);return[{label:t,path:`/`},...n.map((e,t)=>({label:e,path:`/${n.slice(0,t+1).join(`/`)}`}))]}var fe={context:(0,O.jsx)(l,{className:`h-3.5 w-3.5`}),directory:(0,O.jsx)(f,{className:`h-3.5 w-3.5`}),backends:(0,O.jsx)(a,{className:`h-3.5 w-3.5`}),relations:(0,O.jsx)(d,{className:`h-3.5 w-3.5`})},pe={context:`Context tree`,directory:`Directory tree`,backends:`Backends tree`,relations:`Relations`};function W(e,t){return e===`/`?`/${t}`:`${e}/${t}`}function me(e,t){let n=(0,D.useRef)(null),r=(0,D.useRef)(!1),i=()=>{n.current&&=(clearTimeout(n.current),null)},a=e=>t=>{if(r.current){r.current=!1;return}t.detail>1||e()};return t?{guardClick:a,handlers:{onContextMenu:n=>{n.preventDefault(),n.stopPropagation(),t({clientX:n.clientX,clientY:n.clientY,path:e})},onPointerDown:a=>{if(a.pointerType!==`touch`)return;let{clientX:o,clientY:s}=a;i(),n.current=setTimeout(()=>{r.current=!0,t({clientX:o,clientY:s,path:e})},500)},onPointerUp:i,onPointerLeave:i,onPointerMove:i}}:{handlers:{},guardClick:a}}function he(e,t,n){let r=W(t,e.name);return r.toLowerCase().includes(n)||(e.label||``).toLowerCase().includes(n)?!0:e.children?.some(e=>he(e,r,n))??!1}var G=200;function ge({onConfirm:e,onCancel:t,busy:n}){let[r,i]=(0,D.useState)(``);return(0,O.jsxs)(`div`,{className:`flex min-h-11 items-center gap-2 rounded-(--card-radius) bg-card px-3 py-2.5 text-sm shadow-elevation-1`,children:[(0,O.jsx)(m,{className:`h-4 w-4 shrink-0 text-muted-foreground`}),(0,O.jsx)(`input`,{type:`text`,value:r,onChange:e=>i(e.target.value),onKeyDown:n=>{n.key===`Enter`&&r.trim()&&e(r.trim()),n.key===`Escape`&&t()},onBlur:()=>{n||t()},placeholder:`New folder name…`,autoFocus:!0,disabled:n,className:`w-full flex-1 bg-transparent text-sm outline-none placeholder:text-muted-foreground`}),n&&(0,O.jsx)(`span`,{className:`shrink-0 text-xs text-muted-foreground`,children:`Creating…`})]})}function _e({node:e,parentPath:t,query:n,selected:i,onToggle:a,onActivate:o,onRowMenu:s,createParent:l,onCreateConfirm:u,onCreateCancel:d,creating:f}){let p=W(t,e.name),m=!!e.children?.length,[h,_]=(0,D.useState)(!1),{handlers:v,guardClick:te}=me(p,s);if(n&&!he(e,t,n))return null;let y=l===p,b=h||n.length>0||y,x=i.has(p),S=e.type===`canvas`,C=T(e);return(0,O.jsxs)(`div`,{children:[(0,O.jsxs)(`div`,{className:g(`group relative flex min-h-11 items-center gap-2 rounded-md px-3 py-2.5 cursor-pointer transition-all select-none text-sm shadow-elevation-1 hover:shadow`,`before:absolute before:left-0 before:top-0 before:bottom-0 before:w-1.5 before:transition-colors`,x?`bg-primary/[0.08] hover:bg-primary/[0.12] before:bg-primary`:`bg-card hover:bg-primary/[0.04] before:bg-transparent`),onClick:te(()=>a(p)),onDoubleClick:e=>{e.ctrlKey||e.metaKey||e.shiftKey||e.altKey||e.target.closest(`button,input,textarea,select,a,[contenteditable="true"]`)||(e.preventDefault(),e.stopPropagation(),m?_(e=>!e):o?.(p))},title:p,...v,children:[(0,O.jsx)(`button`,{type:`button`,"aria-label":`${b?`Collapse`:`Expand`} ${e.label||e.name}`,"aria-expanded":m?b:void 0,disabled:!m,className:g(`shrink-0 text-muted-foreground hover:text-foreground`,!m&&`invisible`),onClick:e=>{e.stopPropagation(),e.detail<=1&&_(e=>!e)},children:b?(0,O.jsx)(ee,{className:`w-4 h-4`}):(0,O.jsx)(c,{className:`w-4 h-4`})}),(0,O.jsx)(r,{icon:C.icon||(S?`ph:squares-four-fill`:`ph:folder-fill`),width:16,height:16,color:E(C.color),className:g(`shrink-0`,!E(C.color)&&(S?`text-primary`:`text-muted-foreground`))}),(0,O.jsx)(`span`,{className:`flex-1 truncate font-medium`,title:e.description||void 0,children:e.label||e.name})]}),b&&m||y?(0,O.jsxs)(`div`,{className:`ml-[22px] mt-1.5 space-y-1.5`,children:[y&&u&&d&&(0,O.jsx)(ge,{busy:f,onConfirm:e=>{_(!0),u(p,e)},onCancel:d}),b&&e.children?.map(e=>(0,O.jsx)(_e,{node:e,parentPath:p,query:n,selected:i,onToggle:a,onActivate:o,onRowMenu:s,createParent:l,onCreateConfirm:u,onCreateCancel:d,creating:f},e.id||e.name))]}):null]})}function ve({workspaces:e,loading:t,onPick:n}){return t&&e.length===0?(0,O.jsx)(`div`,{className:`px-2 py-3 text-xs text-muted-foreground`,children:`Loading…`}):e.length===0?(0,O.jsx)(`div`,{className:`px-2 py-3 text-xs text-muted-foreground`,children:`No workspaces found`}):(0,O.jsx)(`div`,{className:`space-y-1.5`,children:e.map(e=>{let t=E(e.color);return(0,O.jsxs)(`div`,{onClick:()=>n(e.name),className:`group relative flex cursor-pointer items-center gap-2 rounded-(--card-radius) bg-card px-3 py-2.5 shadow-elevation-1 transition-all hover:bg-accent/50 hover:shadow`,style:{borderRight:`6px solid ${t||`transparent`}`},children:[(0,O.jsx)(r,{icon:e.icon||`ph:stack-fill`,width:18,height:18,color:t,className:g(`shrink-0`,!t&&`text-muted-foreground`)}),(0,O.jsx)(`span`,{className:`flex-1 truncate text-sm font-medium`,children:e.label||e.name}),(0,O.jsx)(c,{className:`h-4 w-4 shrink-0 text-muted-foreground`})]},e.id||e.name)})})}function ye({workspaceName:e,treeTab:t,onTreeTabChange:n,selectedDocIds:r,onToggleDoc:i,onNavigate:a,excludeDocumentIds:s}){let[l,u]=(0,D.useState)(`folder`),[d,f]=(0,D.useState)(``),p=d.trim().toLowerCase(),[m,_]=(0,D.useState)(`/`),[y,x]=(0,D.useState)(null),[S,C]=(0,D.useState)(!1),[re,w]=(0,D.useState)([]),[ae,T]=(0,D.useState)(!1),[E,k]=(0,D.useState)(``),[A,j]=(0,D.useState)(``),[M,N]=(0,D.useState)(t),P=n?t:M,F=e=>{_(`/`),u(`folder`),k(``),j(``),a?.(`/`),n?n(e):N(e)},[se,I]=(0,D.useState)(P);P!==se&&(I(P),_(`/`),u(`folder`)),(0,D.useEffect)(()=>{let e=setTimeout(()=>j(E.trim()),300);return()=>clearTimeout(e)},[E]),(0,D.useEffect)(()=>{let t=!1;async function n(){C(!0);try{let n=await b(e,P);t||x(n)}catch{t||x(null)}finally{t||C(!1)}}return n(),()=>{t=!0}},[e,P]),(0,D.useEffect)(()=>{if(l!==`documents`)return;let t=!1,n=P===`directory`?`directory`:ie,r=P===`context`?`context`:`directory`;async function i(){T(!0);try{let i=A?await ne(e,m,[],{treeName:n,treeType:r,q:A,limit:G}):await te(e,m,n,{limit:G});t||w(i.payload||[])}catch{t||w([])}finally{t||T(!1)}}return i(),()=>{t=!0}},[e,P,m,l,A]);let L=e=>{_(e),a?.(e)},R=s?.size?re.filter(e=>!s.has(e.id)):re;return l===`folder`?(0,O.jsxs)(`div`,{className:`flex min-h-0 flex-1 flex-col`,children:[(0,O.jsxs)(`div`,{className:`shrink-0 space-y-2 border-b bg-muted/30 px-3 py-2`,children:[!n&&(0,O.jsx)(`div`,{className:`flex items-center gap-1 rounded-md border border-input p-0.5`,children:[`context`,`directory`].map(e=>(0,O.jsxs)(`button`,{type:`button`,onClick:()=>F(e),className:g(`flex flex-1 items-center justify-center gap-1.5 rounded px-2 py-1 text-xs transition-colors`,P===e?`bg-primary text-primary-foreground`:`text-muted-foreground hover:bg-muted hover:text-foreground`),title:`Browse the ${pe[e].toLowerCase()}`,children:[fe[e],(0,O.jsx)(`span`,{className:`font-mono`,children:e===`directory`?`dir://`:`ctx://`})]},e))}),(0,O.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,O.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:`Step 1 of 2 · Pick a folder`}),(0,O.jsxs)(`button`,{type:`button`,onClick:()=>u(`documents`),className:`inline-flex items-center gap-1 rounded-md bg-primary px-2.5 py-1 text-xs font-medium text-primary-foreground transition-opacity hover:opacity-90`,children:[`Next `,(0,O.jsx)(c,{className:`h-3.5 w-3.5`})]})]}),(0,O.jsx)(H,{items:U(m,e),onNavigate:L,label:`Folder path`}),(0,O.jsxs)(`div`,{className:`relative`,children:[(0,O.jsx)(h,{className:`pointer-events-none absolute left-2.5 top-1/2 h-3.5 w-3.5 -translate-y-1/2 text-muted-foreground`}),(0,O.jsx)(`input`,{type:`text`,placeholder:`Filter folders…`,value:d,onChange:e=>f(e.target.value),className:`w-full rounded-md border border-input bg-background py-1.5 pl-8 pr-3 text-xs placeholder:text-muted-foreground focus:outline-none focus:ring-2 focus:ring-ring`})]})]}),(0,O.jsx)(`div`,{className:`min-h-0 flex-1 space-y-1.5 overflow-y-auto p-3`,children:S?(0,O.jsx)(`div`,{className:`px-2 py-3 text-xs text-muted-foreground`,children:`Loading…`}):(0,O.jsxs)(O.Fragment,{children:[(0,O.jsxs)(`div`,{className:g(`group relative flex min-h-11 items-center gap-2 rounded-md px-3 py-2.5 cursor-pointer transition-all select-none text-sm shadow-elevation-1 hover:shadow`,`before:absolute before:left-0 before:top-0 before:bottom-0 before:w-1.5 before:transition-colors`,m===`/`?`bg-primary/[0.08] hover:bg-primary/[0.12] before:bg-primary`:`bg-card hover:bg-primary/[0.04] before:bg-transparent`),onClick:()=>L(`/`),onDoubleClick:()=>{L(`/`),u(`documents`)},title:`/`,children:[(0,O.jsx)(ee,{className:`w-4 h-4 shrink-0 text-muted-foreground`}),(0,O.jsx)(`span`,{className:`flex-1 truncate font-medium`,children:`/`})]}),(0,O.jsx)(`div`,{className:`ml-[22px] space-y-1.5`,children:y?.children?.length?y.children.map(e=>(0,O.jsx)(_e,{node:e,parentPath:`/`,query:p,selected:new Set([m]),onToggle:L,onActivate:e=>{L(e),u(`documents`)}},e.id||e.name)):(0,O.jsx)(`p`,{className:`px-2 py-1.5 text-xs text-muted-foreground`,children:`Empty tree`})})]})})]}):(0,O.jsxs)(`div`,{className:`flex min-h-0 flex-1 flex-col`,children:[(0,O.jsxs)(`div`,{className:`shrink-0 space-y-2 border-b bg-muted/30 px-3 py-2`,children:[(0,O.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,O.jsxs)(`button`,{type:`button`,onClick:()=>u(`folder`),className:`inline-flex min-w-0 items-center gap-1 rounded-md px-1.5 py-1 text-xs text-muted-foreground transition-colors hover:bg-muted hover:text-foreground`,title:`Back to folders`,children:[(0,O.jsx)(c,{className:`h-3.5 w-3.5 shrink-0 rotate-180`}),(0,O.jsx)(`span`,{children:`Folders`})]}),(0,O.jsx)(`span`,{className:`ml-auto shrink-0 text-xs text-muted-foreground`,children:`Step 2 of 2 · Pick a document`})]}),(0,O.jsxs)(`div`,{className:`flex min-w-0 items-center gap-2`,children:[(0,O.jsxs)(`span`,{className:`shrink-0 font-mono text-xs text-muted-foreground`,children:[`[`,P,`]`]}),(0,O.jsx)(H,{items:U(m,e),onNavigate:L,label:`Document folder path`})]}),(0,O.jsxs)(`div`,{className:`relative`,children:[(0,O.jsx)(h,{className:`pointer-events-none absolute left-2.5 top-1/2 h-3.5 w-3.5 -translate-y-1/2 text-muted-foreground`}),(0,O.jsx)(`input`,{type:`text`,placeholder:`Search documents in this folder…`,value:E,onChange:e=>k(e.target.value),className:`w-full rounded-md border border-input bg-background py-1.5 pl-8 pr-7 text-xs placeholder:text-muted-foreground focus:outline-none focus:ring-2 focus:ring-ring`}),E&&(0,O.jsx)(`button`,{type:`button`,onClick:()=>k(``),className:`absolute right-2 top-1/2 -translate-y-1/2 text-muted-foreground hover:text-foreground`,"aria-label":`Clear document search`,children:(0,O.jsx)(o,{className:`h-3.5 w-3.5`})})]})]}),(0,O.jsx)(`div`,{className:`min-h-0 flex-1 space-y-1 overflow-y-auto p-3`,children:ae?(0,O.jsx)(`div`,{className:`px-2 py-3 text-xs text-muted-foreground`,children:`Loading documents…`}):R.length===0?(0,O.jsx)(`div`,{className:`px-2 py-3 text-xs text-muted-foreground`,children:A?`No documents match “${A}” here.`:`No documents in this folder.`}):R.map(e=>{let t=v(e),n=r.has(e.id);return(0,O.jsxs)(`div`,{onClick:()=>i(e.id),className:g(`flex min-h-9 items-center gap-2 rounded-md px-3 py-1.5 cursor-pointer transition-all select-none text-sm`,n?`bg-primary/[0.08] hover:bg-primary/[0.12]`:`hover:bg-primary/[0.04]`),children:[(0,O.jsx)(`input`,{type:`checkbox`,checked:n,onChange:()=>i(e.id),className:`shrink-0`,onClick:e=>e.stopPropagation()}),(0,O.jsx)(oe,{document:e,size:3.5}),(0,O.jsx)(`span`,{className:`flex-1 truncate`,children:t.title})]},e.id)})})]})}function be({onClose:e,onConfirm:t,documentCount:n,fixedWorkspaceName:r,excludeWorkspace:i,multiple:a=!0,saving:l=!1,savingContent:d,sizeClassName:f,tabs:m=[`context`,`directory`],initialTab:v,title:te,confirmLabel:x,backendFolderCreation:ne,onConfirmRelation:T,relationWorkspaceName:E,relationPredicates:oe,relationExcludeIds:A}){let[M,N]=(0,D.useState)(r?`tree`:`workspace`),[P,F]=(0,D.useState)([]),[se,I]=(0,D.useState)(!r),[L,R]=(0,D.useState)(r??null),ce=v&&m.includes(v)?v:m.includes(`context`)||m.includes(`directory`)?`pins`:m[0]??`context`,[z,B]=(0,D.useState)(ce),le=j(m.includes(`relations`)&&!oe?E??L:null),V=oe??le.predicates,[de,H]=(0,D.useState)(``),U=V.includes(de)?de:V[0]??``,[W,he]=(0,D.useState)(`out`),[G,be]=(0,D.useState)(new Set),[xe,Se]=(0,D.useState)(null),[K,Ce]=(0,D.useState)(`context`),[we,Te]=(0,D.useState)(!1),Ee=z===`pins`?K:z;(0,D.useEffect)(()=>{if(!L)return;let e=!1;return y(L).then(t=>{e||Se(t)}).catch(()=>{e||Te(!0)}),()=>{e=!0}},[L]);let q=z===`relations`,[De,Oe]=(0,D.useState)(null),[ke,Ae]=(0,D.useState)(!1),[J,Y]=(0,D.useState)(new Set),[je,Me]=(0,D.useState)(``),Ne=je.trim().toLowerCase(),{showErrorToast:Pe}=ae(),[X,Fe]=(0,D.useState)(null),[Ie,Z]=(0,D.useState)(null),[Q,Le]=(0,D.useState)(!1);w(e,!l&&!Q);let Re=me(`/`,e=>Fe(e)),ze=e=>!l&&(z===`backends`?ne?.canCreate(e)===!0:z!==`pins`&&z!==`relations`),Be=async(e,t)=>{let n=t.trim().replace(/^\/+|\/+$/g,``);if(!(!n||!L||Q||!ze(e))){Le(!0);try{let t=`${e===`/`?``:e}/${n}`,r=z===`context`?ie:z;z===`backends`?await ne.create(e,n):await re(L,t,!0,r),C(L,r),window.dispatchEvent(new CustomEvent(`workspace:tree:refresh`,{detail:{workspaceName:L,treeName:r,cacheInvalidated:!0}}));let i=await b(L,z);Oe(i),Y(e=>a?new Set([...e,t]):new Set([t])),Me(``),Z(null)}catch(e){Pe(e instanceof Error?e.message:`Failed to create folder`)}finally{Le(!1)}}},[Ve,He]=(0,D.useState)(r);r!==Ve&&(He(r),r||I(!0)),(0,D.useEffect)(()=>{r||S().then(e=>F(e.filter(e=>e.id!==i&&e.name!==i))).catch(()=>F([])).finally(()=>I(!1))},[r,i]),(0,D.useEffect)(()=>{if(!L||z===`relations`||z===`pins`)return;let e=!1,t=0;async function n(n=!1){let r=++t;n||Ae(!0);try{let n=await b(L,z);!e&&r===t&&Oe(n)}catch{!e&&r===t&&!n&&Oe(null)}finally{!e&&r===t&&Ae(!1)}}let r=e=>{let t=e.detail;t?.workspaceName&&t.workspaceName!==L||t?.treeName&&t.treeName!==z||(t?.cacheInvalidated||C(L,z),n(!0))};return window.addEventListener(`workspace:tree:refresh`,r),n(),()=>{e=!0,window.removeEventListener(`workspace:tree:refresh`,r)}},[L,z]);let Ue=e=>{e!==L&&(Se(null),Te(!1)),B(ce),R(e),Y(new Set),be(new Set),N(`tree`)},We=e=>{be(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},Ge=e=>{if(!a){Y(new Set([e]));return}Y(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},Ke=q?!!U&&G.size>0&&!!T:J.size>0,qe=async()=>{if(!(!L||l||!Ke)){if(q){await T?.({predicate:U,direction:W,targetIds:Array.from(G)},{workspaceName:E??L});return}await t(Array.from(J),{workspaceName:L,treeName:Ee===`context`?ie:Ee,treeType:Ee===`context`?`context`:`directory`})}},$=n??1;return l&&d?(0,O.jsx)(`div`,{className:g(`flex flex-col overflow-hidden rounded-(--panel-radius) border bg-card shadow-elevation-4`,f||`h-viewport-card max-h-full w-[min(380px,90vw)] max-md:h-full max-md:w-full max-md:shadow-elevation-5`),children:d}):(0,O.jsxs)(`div`,{className:g(`flex flex-col overflow-hidden rounded-(--panel-radius) border bg-card shadow-elevation-4`,f||`h-viewport-card max-h-full w-[min(380px,90vw)] max-md:h-full max-md:w-full max-md:shadow-elevation-5`),children:[(0,O.jsxs)(`div`,{className:`flex h-12 shrink-0 items-center justify-between border-b px-4`,children:[(0,O.jsxs)(`span`,{className:`flex items-center gap-2 text-sm font-medium`,children:[(0,O.jsx)(p,{className:`h-4 w-4`}),te??(M===`workspace`?`Link to…`:q?`Relate ${$} document${$===1?``:`s`} to…`:`Link ${$} document${$===1?``:`s`} to…`)]}),(0,O.jsx)(`button`,{type:`button`,onClick:e,disabled:l||Q,className:`text-muted-foreground transition-colors hover:text-foreground disabled:opacity-40`,"aria-label":`Close`,children:(0,O.jsx)(o,{className:`h-4 w-4`})})]}),(0,O.jsx)(`div`,{className:`flex-1 overflow-hidden`,children:(0,O.jsxs)(`div`,{className:`grid h-full w-[200%] grid-cols-2 transition-transform duration-normal`,style:{transform:M===`workspace`?`translateX(0)`:`translateX(-50%)`},children:[(0,O.jsx)(`div`,{className:`flex min-w-0 flex-col overflow-y-auto p-2`,children:(0,O.jsx)(ve,{workspaces:P,loading:se,onPick:Ue})}),(0,O.jsxs)(`div`,{className:`flex min-w-0 flex-col overflow-hidden`,children:[(0,O.jsxs)(`div`,{className:`flex shrink-0 items-center gap-1 overflow-x-auto border-b px-2 pt-2`,children:[!r&&(0,O.jsx)(`button`,{type:`button`,disabled:Q,onClick:()=>N(`workspace`),className:`mr-1 rounded p-1.5 text-muted-foreground hover:bg-muted hover:text-foreground touch-target`,"aria-label":`Back to workspaces`,children:(0,O.jsx)(c,{className:`h-4 w-4 rotate-180`})}),(m.includes(`context`)||m.includes(`directory`))&&(0,O.jsxs)(`button`,{type:`button`,disabled:Q,onClick:()=>{B(`pins`),Y(new Set),Z(null)},className:g(`flex shrink-0 items-center gap-1.5 border-b-2 px-3 py-2 text-xs`,z===`pins`?`border-primary`:`border-transparent text-muted-foreground`),children:[(0,O.jsx)(s,{className:`h-3.5 w-3.5`}),`Pins`]}),m.map(e=>(0,O.jsxs)(`button`,{type:`button`,disabled:Q,onClick:()=>{B(e),Y(new Set),Z(null)},className:g(`flex shrink-0 items-center gap-1.5 rounded-t-md border-b-2 px-3 py-2 text-xs font-medium transition-colors`,z===e?`border-primary text-foreground`:`border-transparent text-muted-foreground hover:text-foreground`),children:[fe[e],pe[e]]},e))]}),!q&&(0,O.jsx)(`div`,{className:`shrink-0 border-b p-2`,children:(0,O.jsxs)(`div`,{className:`relative`,children:[(0,O.jsx)(h,{className:`pointer-events-none absolute left-2.5 top-1/2 h-4 w-4 -translate-y-1/2 text-muted-foreground`}),(0,O.jsx)(`input`,{type:`text`,placeholder:`Search paths…`,value:je,onChange:e=>Me(e.target.value),className:`w-full rounded-md border border-input bg-background py-2 pl-9 pr-3 text-sm placeholder:text-muted-foreground focus:outline-none focus:ring-2 focus:ring-ring`})]})}),q&&(0,O.jsxs)(`div`,{className:`shrink-0 space-y-2 border-b bg-primary/[0.04] px-3 py-2`,children:[(0,O.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,O.jsx)(`label`,{htmlFor:`relation-predicate`,className:`shrink-0 text-xs text-muted-foreground`,children:`Predicate`}),(0,O.jsx)(`select`,{id:`relation-predicate`,value:U,onChange:e=>H(e.target.value),className:`min-w-0 flex-1 rounded-md border border-input bg-background px-2 py-1.5 text-xs focus:outline-none focus:ring-2 focus:ring-ring`,children:V.map(e=>(0,O.jsx)(`option`,{value:e,children:e},e))})]}),(0,O.jsx)(`div`,{className:`flex items-center gap-1`,children:[{dir:`out`,label:`This → picked`,hint:`the ${$===1?`document`:`documents`} you started from ${U} the picked one(s)`},{dir:`in`,label:`Picked → this`,hint:`the picked document(s) ${U} the ${$===1?`one`:`ones`} you started from`}].map(({dir:e,label:t,hint:n})=>(0,O.jsx)(`button`,{type:`button`,title:n,onClick:()=>he(e),className:g(`flex-1 rounded-md border px-2 py-1.5 text-xs transition-colors`,W===e?`border-primary bg-primary text-primary-foreground`:`border-input hover:bg-accent`),children:t},e))})]}),!q&&a&&(0,O.jsxs)(`div`,{className:`flex h-10 shrink-0 items-center gap-1.5 overflow-x-auto border-b bg-primary/[0.04] px-3`,children:[!J.size&&(0,O.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:`Selected folders appear here`}),Array.from(J).map(e=>(0,O.jsxs)(`span`,{className:`inline-flex max-w-full shrink-0 items-center gap-1 rounded-full bg-primary px-2 py-0.5 text-xs text-primary-foreground`,children:[(0,O.jsx)(`span`,{className:`truncate`,title:e,children:e}),(0,O.jsx)(`button`,{type:`button`,onClick:()=>Ge(e),className:`shrink-0 rounded-full hover:bg-primary-foreground/20`,"aria-label":`Remove ${e}`,children:(0,O.jsx)(o,{className:`h-3 w-3`})})]},e))]}),q&&(E??L)&&(0,O.jsx)(ye,{workspaceName:E??L,treeTab:`context`,selectedDocIds:G,onToggleDoc:We,excludeDocumentIds:A}),z===`pins`&&(0,O.jsxs)(`div`,{className:`min-h-0 flex-1 overflow-y-auto p-3 space-y-2`,children:[!xe&&!we&&(0,O.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`Loading pins…`}),we&&(0,O.jsx)(`p`,{className:`text-xs text-destructive`,children:`Could not load pins. You can still browse the trees.`}),!we&&xe?.length===0&&(0,O.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`No pinned paths yet. Choose a path from a tree.`}),xe?.filter(e=>e.resolvable!==!1&&m.includes(e.tree===`context`?`context`:e.tree)&&`${e.label??e.name??``} ${e.path}`.toLowerCase().includes(Ne)).map(e=>{let t=e.tree===`context`?`context`:e.tree;return(0,O.jsxs)(`button`,{type:`button`,"aria-pressed":K===t&&J.has(e.path),className:g(`w-full rounded-md border p-3 text-left text-sm hover:bg-muted`,K===t&&J.has(e.path)&&`border-primary bg-primary/10`),onClick:()=>{K===t?Ge(e.path):(Ce(t),Y(new Set([e.path])))},children:[(0,O.jsxs)(`span`,{className:`flex items-center gap-2`,children:[(0,O.jsx)(s,{className:`h-3.5 w-3.5`}),e.label||e.name||e.path]}),(0,O.jsxs)(`span`,{className:`block truncate text-xs text-muted-foreground`,children:[t,` · `,e.path]})]},e.id)})]}),(0,O.jsx)(`div`,{className:g(`min-h-0 flex-1 space-y-1.5 overflow-y-auto p-3`,(q||z===`pins`)&&`hidden`),children:ke?(0,O.jsx)(`div`,{className:`px-2 py-3 text-xs text-muted-foreground`,children:`Loading…`}):(0,O.jsxs)(O.Fragment,{children:[(0,O.jsxs)(`div`,{className:g(`group relative flex min-h-11 items-center gap-2 rounded-md px-3 py-2.5 cursor-pointer transition-all select-none text-sm shadow-elevation-1 hover:shadow`,`before:absolute before:left-0 before:top-0 before:bottom-0 before:w-1.5 before:transition-colors`,J.has(`/`)?`bg-primary/[0.08] hover:bg-primary/[0.12] before:bg-primary`:`bg-card hover:bg-primary/[0.04] before:bg-transparent`),onClick:Re.guardClick(()=>Ge(`/`)),title:`/`,...ze(`/`)?Re.handlers:{},children:[(0,O.jsx)(ee,{className:`w-4 h-4 shrink-0 text-muted-foreground`}),(0,O.jsx)(`span`,{className:`flex-1 truncate font-medium`,children:`/`})]}),(0,O.jsxs)(`div`,{className:`ml-[22px] space-y-1.5`,children:[Ie===`/`&&(0,O.jsx)(ge,{busy:Q,onConfirm:e=>Be(`/`,e),onCancel:()=>Z(null)}),De?.children?.length?De.children.map(e=>(0,O.jsx)(_e,{node:e,parentPath:`/`,query:Ne,selected:J,onToggle:Ge,onRowMenu:e=>{ze(e.path)&&Fe(e)},createParent:Ie,onCreateConfirm:Be,onCreateCancel:()=>Z(null),creating:Q},e.id||e.name)):Ie===`/`?null:(0,O.jsx)(`p`,{className:`px-2 py-1.5 text-xs text-muted-foreground`,children:`Empty tree`})]})]})})]})]})}),M===`tree`&&(0,O.jsxs)(`div`,{className:`flex shrink-0 items-center justify-between border-t px-4 py-3`,children:[(0,O.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:q?`${G.size} document${G.size===1?``:`s`} selected`:`${J.size} path${J.size===1?``:`s`} selected`}),(0,O.jsx)(_,{size:`sm`,onClick:qe,disabled:!Ke||l||Q,children:l?(0,O.jsxs)(O.Fragment,{children:[(0,O.jsx)(k,{className:`mr-1.5 h-3.5 w-3.5`}),q?`Relating…`:`Linking…`]}):(0,O.jsxs)(O.Fragment,{children:[(0,O.jsx)(p,{className:`mr-1 h-3.5 w-3.5`}),q?`Relate`:x??`Link`]})})]}),X&&(0,O.jsx)(ue,{anchor:{x:X.clientX,y:X.clientY},onClose:()=>Fe(null),items:[{id:`new-folder`,label:`New folder in ${X.path}`,icon:u,run:()=>Z(X.path)}]})]})}export{k as _,pe as a,de as c,F as d,R as f,j as g,M as h,fe as i,z as l,se as m,ye as n,U as o,I as p,ve as r,H as s,be as t,L as u};
@@ -1,8 +0,0 @@
1
- const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/pdf-Ciz5_WNq.js","assets/preload-helper-Czpn1I53.js","assets/TextDocumentEditor-BQnVD0dd.js","assets/rolldown-runtime-C0FnF6B9.js","assets/code-editor-BOIngd5F.js","assets/ui-CDoK3F3U.js","assets/react-BHzhHVTZ.js","assets/button-SeUZ_Pvi.js","assets/utils-BxVxyehK.js","assets/utils-2pl1SbIp.js","assets/workspace-C5V-ZCOE.js","assets/input-BOtCd4HP.js","assets/api-CA6WiiYM.js","assets/alert-dialog-CFeuDt0T.js","assets/text-documents-Cdb3U63i.js","assets/public-share-CXR25Q1X.js","assets/blobs-WiXP9QRi.js","assets/useToastHelpers-CRrpIIdY.js","assets/use-toast-BlLDqSUO.js","assets/note-save-status-DPz4VzL6.js","assets/useEditNoteFields-BT1ASu_q.js","assets/tags-YamdPoBK.js","assets/DocumentBodyEditor-CVO5KPCs.js","assets/lazy-editor-BUFAkTGl.js","assets/EditorOverlay-D5t3xg4w.js","assets/LocationTab-DAtqAQ3l.js","assets/map-BxCwdK0d.js","assets/map-BcsP_QXj.css"])))=>i.map(i=>d[i]);
2
- import{o as e}from"./rolldown-runtime-C0FnF6B9.js";import{l as t,u as n}from"./code-editor-BOIngd5F.js";import{_t as r,yt as i}from"./react-BHzhHVTZ.js";import{t as a}from"./preload-helper-Czpn1I53.js";import{$r as o,Bn as s,Bt as c,Dr as l,Dt as u,Et as d,Gn as f,Ht as p,It as m,J as h,L as g,Lt as _,Mn as v,Or as y,Pn as b,Pt as x,Tr as S,Un as C,Wr as w,X as T,Xr as E,Yr as D,Zr as O,_n as k,br as A,cn as j,ct as M,di as N,en as P,fr as F,jt as ee,kn as I,lr as L,mr as te,mt as ne,nr as R,nt as z,on as B,or as V,pi as re,pn as H,qn as ie,rr as ae,rt as oe,sn as se,vr as U,yt as W,zt as G}from"./ui-CDoK3F3U.js";import{t as K}from"./utils-2pl1SbIp.js";import{t as q}from"./button-SeUZ_Pvi.js";import{t as ce}from"./input-BOtCd4HP.js";import{t as J}from"./label-BSTdjCWU.js";import{l as le}from"./api-CA6WiiYM.js";import{_ as ue,g as de,o as fe,t as pe}from"./LinkToCard-CKVi4Nrg.js";import{Bn as me,D as he,Dn as ge,Dt as _e,Fn as ve,Hn as ye,Ht as be,J as xe,K as Se,Ln as Ce,M as we,N as Te,Vn as Ee,et as De,g as Oe,hn as ke,jn as Ae,kn as Y,l as je,o as Me,q as Ne,r as Pe,s as Fe,un as Ie,vt as Le,xn as Re,zn as ze}from"./workspace-C5V-ZCOE.js";import{r as Be,t as Ve}from"./use-mobile-Db-vWu9Y.js";import{a as He,c as Ue,i as We,n as Ge,o as Ke,r as qe,s as Je,t as Ye}from"./IdentityFields-D-NCTUaE.js";import{i as Xe,r as Ze}from"./public-share-CXR25Q1X.js";import{a as Qe,i as $e,n as et,o as tt,r as nt,s as rt,t as it}from"./text-documents-Cdb3U63i.js";import{t as at}from"./useDocumentThumbnail-Cj4UYyhC.js";import{t as ot}from"./markdown-view-BBBZtNSR.js";import{n as st,t as ct}from"./tags-YamdPoBK.js";import{n as lt,t as ut}from"./relation-events-CKio19hE.js";import{a as dt,c as ft,i as pt,o as mt}from"./date-time-picker-DCikruos.js";import{t as ht}from"./sanitize-DrVcFY1Q.js";import{t as gt}from"./useEscapeClose-DR_xKT_k.js";import{t as X}from"./useToastHelpers-CRrpIIdY.js";import"./layer-style-Byl5LNFR.js";import{t as _t}from"./DocumentIcon-9i1uCMQa.js";import{r as vt,s as yt,t as bt}from"./MessageComposerDialog-CdPp-3GR.js";import{n as xt}from"./LinkToSidePanel-eCy3nW4R.js";import{t as St}from"./note-save-status-DPz4VzL6.js";import{t as Ct}from"./useEditNoteFields-BT1ASu_q.js";import{t as wt}from"./DocumentBodyEditor-CVO5KPCs.js";import{n as Tt}from"./use-document-modal-PG8bQyIB.js";import{t as Et}from"./sketch-lazy-BY_ka1hw.js";import{r as Dt}from"./geo-CZfs0E-x.js";var Z=e(n(),1);function Ot(e,t){let n=/(^|\s)(!?)@([a-z-]*)$/i.exec(e);if(!n)return null;let r=n[3].toLowerCase();return{before:e.slice(0,n.index)+n[1]+n[2],predicates:t.filter(e=>e.startsWith(r))}}var Q=t();function kt({workspaceId:e,inputRef:t,onChange:n}){let[r,i]=(0,Z.useState)(``),[a,o]=(0,Z.useState)(!1),[s,c]=(0,Z.useState)(0),l=de(e),u=Ot(r,l.predicates),d=!!e&&a&&u!==null,f=u?.predicates??[],p=(0,Z.useId)(),m=Math.min(s,Math.max(0,f.length-1));(0,Z.useEffect)(()=>{d&&document.getElementById(`${p}-${m}`)?.scrollIntoView({block:`nearest`})},[p,m,d,f.length]);let h=e=>{let r=t.current;if(!r||!u)return;let a=`${u.before}@${e}: `;r.value=a,n?.(a),i(a),o(!1),r.focus()};return(0,Z.useEffect)(()=>{let e=t.current;if(!e)return;let n=()=>{i(e.value),c(0),o(!0)},r=()=>o(!1),a=e=>{!d||e.isComposing||(e.key===`Escape`?(e.preventDefault(),e.stopPropagation(),o(!1)):f.length&&[`ArrowDown`,`ArrowUp`,`Enter`,`Tab`].includes(e.key)&&(e.preventDefault(),e.stopPropagation(),e.key===`ArrowDown`?c((m+1)%f.length):e.key===`ArrowUp`?c((m+f.length-1)%f.length):h(f[m])))};return e.addEventListener(`input`,n),e.addEventListener(`focus`,n),e.addEventListener(`blur`,r),e.addEventListener(`keydown`,a),e.setAttribute(`role`,`combobox`),e.setAttribute(`aria-autocomplete`,`list`),e.setAttribute(`aria-expanded`,String(d)),d?e.setAttribute(`aria-controls`,p):e.removeAttribute(`aria-controls`),d&&f.length?e.setAttribute(`aria-activedescendant`,`${p}-${m}`):e.removeAttribute(`aria-activedescendant`),()=>{e.removeEventListener(`input`,n),e.removeEventListener(`focus`,n),e.removeEventListener(`blur`,r),e.removeEventListener(`keydown`,a);for(let t of[`role`,`aria-autocomplete`,`aria-expanded`,`aria-controls`,`aria-activedescendant`])e.removeAttribute(t)}}),d?(0,Q.jsxs)(`div`,{className:`absolute left-0 right-0 top-full z-50 mt-1 max-h-64 overflow-y-auto rounded-md border bg-popover p-1 text-popover-foreground shadow-lg`,children:[(0,Q.jsx)(`div`,{id:p,role:`listbox`,"aria-label":`Relation predicates`,children:f.map((e,t)=>(0,Q.jsxs)(`button`,{id:`${p}-${t}`,type:`button`,role:`option`,"aria-selected":t===m,className:`block w-full rounded px-3 py-2 text-left text-sm font-mono ${t===m?`bg-accent text-accent-foreground`:`hover:bg-accent`}`,onMouseDown:e=>e.preventDefault(),onClick:()=>h(e),children:[`@`,e,`:`]},e))}),!f.length&&(0,Q.jsx)(`p`,{role:`status`,className:`px-3 py-2 text-sm text-muted-foreground`,children:l.loading?`Loading relations…`:l.error?`Unable to load relation predicates.`:`No matching predicates.`})]}):null}var At=1,jt=8,Mt=320,Nt=28,Pt=2.5,Ft={scale:1,x:0,y:0};function It({src:e,alt:t,className:n=``,onZoomChange:r}){let i=(0,Z.useRef)(null),a=(0,Z.useRef)(null),[o,s]=(0,Z.useState)(Ft),c=(0,Z.useRef)(new Map),l=(0,Z.useRef)(null),u=(0,Z.useRef)(null),d=(0,Z.useRef)(!1),f=(0,Z.useRef)(null),[p,m]=(0,Z.useState)(!1),[h,g]=(0,Z.useState)(e);h!==e&&(g(e),s(Ft)),(0,Z.useEffect)(()=>{r?.(o.scale>1.001)},[o.scale,r]);let _=(0,Z.useCallback)(e=>{let t=i.current,n=a.current;if(!t||!n)return e;let r=Math.min(jt,Math.max(At,e.scale)),o=Math.max(0,(n.offsetWidth*r-t.clientWidth)/2),s=Math.max(0,(n.offsetHeight*r-t.clientHeight)/2);return{scale:r,x:Math.min(o,Math.max(-o,e.x)),y:Math.min(s,Math.max(-s,e.y))}},[]),v=(0,Z.useCallback)((e,t,n)=>{let r=i.current;if(!r)return;let a=r.getBoundingClientRect(),o=t-a.left-a.width/2,c=n-a.top-a.height/2;s(t=>{let n=e/t.scale;return _({scale:e,x:o-(o-t.x)*n,y:c-(c-t.y)*n})})},[_]),y=(0,Z.useCallback)(()=>{let e=i.current,t=a.current;if(!e||!t||!t.offsetWidth||!t.offsetHeight)return Pt;let n=Math.max(e.clientWidth/t.offsetWidth,e.clientHeight/t.offsetHeight),r=Math.max(t.naturalWidth/t.offsetWidth,t.naturalHeight/t.offsetHeight)||jt;return Math.min(jt,Math.max(Pt,Math.min(Math.max(n,Pt),r)))},[]),b=(0,Z.useCallback)((e,t)=>{o.scale>1.001?s(Ft):v(y(),e,t)},[o.scale,v,y]),x=e=>{if(c.current.set(e.pointerId,{x:e.clientX,y:e.clientY}),d.current=!1,c.current.size===2){let[e,t]=[...c.current.values()];l.current={dist:Math.hypot(e.x-t.x,e.y-t.y),scale:o.scale,cx:(e.x+t.x)/2,cy:(e.y+t.y)/2}}e.currentTarget.setPointerCapture(e.pointerId)},S=e=>{let t=c.current.get(e.pointerId);if(!t)return;if(c.current.set(e.pointerId,{x:e.clientX,y:e.clientY}),c.current.size>=2&&l.current){let[e,t]=[...c.current.values()],n=Math.hypot(e.x-t.x,e.y-t.y);l.current.dist>0&&(d.current=!0,m(!0),v(l.current.scale*(n/l.current.dist),l.current.cx,l.current.cy));return}if(o.scale<=1.001)return;let n=e.clientX-t.x,r=e.clientY-t.y;(Math.abs(n)>1||Math.abs(r)>1)&&(d.current=!0,m(!0)),s(e=>_({...e,x:e.x+n,y:e.y+r}))},C=e=>{if(c.current.delete(e.pointerId),c.current.size<2&&(l.current=null),c.current.size===0&&m(!1),d.current){u.current=null;return}let t=e.timeStamp,n=u.current;if(n&&t-n.t<Mt&&Math.hypot(e.clientX-n.x,e.clientY-n.y)<Nt){u.current=null,f.current=t,b(e.clientX,e.clientY);return}u.current={t,x:e.clientX,y:e.clientY}},w=e=>{e.preventDefault();let t=o.scale*(e.deltaY<0?1.15:1/1.15);t<=At?s(Ft):v(Math.min(jt,t),e.clientX,e.clientY)},T=o.scale>1.001;return(0,Q.jsx)(`div`,{ref:i,className:`relative flex h-full w-full items-center justify-center overflow-hidden`,style:{touchAction:`none`,cursor:T?`grab`:`zoom-in`},onPointerDown:x,onPointerMove:S,onPointerUp:C,onPointerCancel:e=>{c.current.delete(e.pointerId),l.current=null,u.current=null,d.current=!0,c.current.size===0&&m(!1)},onWheel:w,onDoubleClick:e=>{e.preventDefault(),e.stopPropagation(),!(f.current!==null&&e.timeStamp-f.current<Mt)&&b(e.clientX,e.clientY)},children:(0,Q.jsx)(`img`,{ref:a,src:e,alt:t,draggable:!1,className:n,style:{transform:`translate3d(${o.x}px, ${o.y}px, 0) scale(${o.scale})`,transformOrigin:`center center`,transition:p?`none`:`transform var(--duration-normal) ease-out`,willChange:`transform`}})})}function Lt(){return!/android|iphone|ipad|mobile/i.test(navigator.userAgent)&&navigator.pdfViewerEnabled!==!1}var Rt=40,zt=1600;function Bt({blob:e,filename:t}){let n=(0,Z.useRef)(null),[r,i]=(0,Z.useState)({error:null,pages:0,truncated:!1});return(0,Z.useEffect)(()=>{let r=n.current;if(!r)return;let o=!1,s=null;return(async()=>{let n=await a(()=>import(`./pdf-Ciz5_WNq.js`),__vite__mapDeps([0,1])),c=(await a(async()=>{let{default:e}=await import(`./pdf.worker.min-C8Ts8bNu.js`);return{default:e}},[])).default;n.GlobalWorkerOptions.workerSrc=c;let l=await e.arrayBuffer();if(o)return;let u=n.getDocument({data:l});s=()=>{u.destroy()};let d=await u.promise;if(o)return;let f=Math.min(d.numPages,Rt),p=r.clientWidth||600,m=window.devicePixelRatio||1;for(let e=1;e<=f;e++){if(o)return;let n=await d.getPage(e),a=n.getViewport({scale:1}),s=Math.min(p*m,zt*m)/a.width,c=n.getViewport({scale:s}),l=document.createElement(`canvas`);if(l.width=c.width,l.height=c.height,l.style.width=`100%`,l.style.height=`auto`,l.className=`rounded border bg-white`,l.setAttribute(`aria-label`,`${t}, page ${e}`),await n.render({canvas:l,viewport:c}).promise,n.cleanup(),o)return;r.appendChild(l),i({error:null,pages:e,truncated:d.numPages>Rt})}})().catch(e=>{o||i(t=>({...t,error:e instanceof Error?e.message:String(e)}))}),()=>{o=!0,s?.(),r.replaceChildren()}},[e,t]),(0,Q.jsxs)(`div`,{className:`space-y-2`,children:[r.error&&(0,Q.jsxs)(`p`,{className:`text-sm text-destructive`,children:[`Could not render PDF: `,r.error]}),!r.error&&r.pages===0&&(0,Q.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`Rendering PDF…`}),(0,Q.jsx)(`div`,{ref:n,className:`space-y-2`}),r.truncated&&(0,Q.jsxs)(`p`,{className:`text-xs text-muted-foreground`,children:[`Showing the first `,Rt,` pages. Download the file for the full document.`]})]})}function Vt({blob:e,blobUrl:t,filename:n,className:r=``}){let i=(0,Z.useMemo)(()=>e&&e.type!==`application/pdf`?URL.createObjectURL(e.slice(0,e.size,`application/pdf`)):null,[e]);return(0,Z.useEffect)(()=>()=>{i&&URL.revokeObjectURL(i)},[i]),Lt()||!e?(0,Q.jsx)(`div`,{className:`min-h-[300px] ${r}`,children:(0,Q.jsx)(`iframe`,{src:i??t,className:`h-full min-h-[300px] w-full rounded border`,title:n})}):(0,Q.jsx)(`div`,{className:`max-h-viewport-pane overflow-y-auto ${r}`,children:(0,Q.jsx)(Bt,{blob:e,filename:n})})}function Ht({workspaceId:e,document:t}){let{download:n}=Ze(e),[r,i]=(0,Z.useState)(!1),a=Y(t)||`document-${t.id}`;return(0,Q.jsxs)(`button`,{type:`button`,onClick:async()=>{i(!0);try{await n(t.id,a)}finally{i(!1)}},disabled:r,className:`inline-flex items-center gap-1.5 rounded-md border px-2.5 py-1 text-xs text-muted-foreground transition-colors hover:bg-accent hover:text-foreground disabled:opacity-50`,children:[(0,Q.jsx)(U,{className:`h-3.5 w-3.5`}),r?`Preparing…`:`Download`]})}var Ut=1600;function Wt({error:e,loading:t,children:n}){return e?(0,Q.jsx)(`p`,{className:`text-sm text-destructive`,children:e}):t?(0,Q.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`Loading preview...`}):(0,Q.jsx)(Q.Fragment,{children:n})}function Gt({workspaceId:e,document:t,className:n=``}){let r=(0,Z.useContext)(Ue),i=Ve(),a=Be(`(pointer: coarse)`),{blobUrl:o,error:s,loading:c}=at(e,t.id,Ut,{version:t.checksumArray?.[0]??null}),{fetchBlob:l}=Ze(e),u=Y(t)||`document-${t.id}`,[d,f]=(0,Z.useState)(!1);return(0,Q.jsx)(Wt,{error:s,loading:c,children:o&&(0,Q.jsxs)(`div`,{className:`flex h-full min-h-0 flex-col gap-2 ${n}`,children:[i||a?(0,Q.jsx)(`div`,{className:`min-h-0 flex-1`,children:(0,Q.jsx)(It,{src:o,alt:u,className:`max-h-full max-w-full object-contain`})}):(0,Q.jsx)(`img`,{src:o,alt:u,draggable:!1,onDoubleClick:r?e=>{e.preventDefault(),e.stopPropagation(),r()}:void 0,title:r?`Double-click to maximize or restore`:void 0,className:`min-h-0 w-full flex-1 object-contain ${r?`cursor-zoom-in`:``}`}),(0,Q.jsxs)(`button`,{type:`button`,onClick:async()=>{f(!0);try{let{blob:e}=await l(t.id),n=URL.createObjectURL(e),r=window.document.createElement(`a`);r.href=n,r.download=u,window.document.body.appendChild(r),r.click(),r.remove(),setTimeout(()=>URL.revokeObjectURL(n),3e4)}finally{f(!1)}},disabled:d,className:`inline-flex shrink-0 self-start items-center gap-1.5 rounded-md border px-2.5 py-1 text-xs text-muted-foreground transition-colors hover:bg-accent hover:text-foreground disabled:opacity-50`,children:[(0,Q.jsx)(U,{className:`h-3.5 w-3.5`}),d?`Preparing…`:`Download original`]})]})})}function Kt({workspaceId:e,document:t,className:n=``}){let{src:r,error:i,loading:a}=rt(e,t.id);return(0,Q.jsx)(Wt,{error:i,loading:a,children:r&&(0,Q.jsxs)(`div`,{className:`space-y-2 ${n}`,children:[(0,Q.jsx)(`audio`,{src:r,controls:!0,preload:`metadata`,className:`w-full`}),(0,Q.jsx)(Ht,{workspaceId:e,document:t})]})})}function qt({workspaceId:e,document:t,className:n=``}){let{src:r,error:i,loading:a}=rt(e,t.id),[o,s]=(0,Z.useState)(!1);return(0,Q.jsx)(Wt,{error:i,loading:a,children:r&&(0,Q.jsxs)(`div`,{className:`space-y-2 ${n}`,children:[(0,Q.jsx)(`video`,{src:r,controls:!0,playsInline:!0,preload:`metadata`,onError:()=>s(!0),className:`max-h-viewport-pane w-full rounded border`}),o&&(0,Q.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`This video can’t be played inline in your browser. Download it to view.`}),(0,Q.jsx)(Ht,{workspaceId:e,document:t})]})})}function Jt({workspaceId:e,document:t,className:n=``}){let{blobUrl:r,blob:i,error:a,loading:o}=tt(e,t.id,{typeHint:`application/pdf`}),s=Y(t)||`document-${t.id}`;return(0,Q.jsx)(Wt,{error:a,loading:o,children:r&&(0,Q.jsxs)(`div`,{className:`flex h-full min-h-0 flex-col gap-2 ${n}`,children:[(0,Q.jsx)(Vt,{blob:i,blobUrl:r,filename:s,className:`min-h-0 flex-1`}),(0,Q.jsx)(`div`,{children:(0,Q.jsx)(Ht,{workspaceId:e,document:t})})]})})}function Yt({workspaceId:e,document:t,className:n=``}){let{text:r,error:i,loading:a}=tt(e,t.id,{mode:`text`,version:t.checksumArray?.[0]});return i?(0,Q.jsx)(`p`,{className:`text-sm text-destructive`,children:i}):a||r==null?(0,Q.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`Loading...`}):(0,Q.jsx)(`pre`,{className:`bg-muted p-3 rounded text-xs overflow-auto max-h-viewport-pane whitespace-pre-wrap ${n}`,children:r})}function Xt({workspaceId:e,document:t,className:n=``}){let r=t.schema===Ce,{text:i,error:a,loading:o}=tt(e,t.id,{mode:`text`,enabled:!r,version:t.checksumArray?.[0]});return r?(0,Q.jsxs)(`div`,{className:`markdown-note space-y-3 ${n}`,children:[t.data?.title?(0,Q.jsx)(`h3`,{className:`text-lg font-semibold`,children:String(t.data.title)}):null,(0,Q.jsx)(`div`,{className:`markdown-document-frame rounded-md border border-input bg-transparent`,children:(0,Q.jsx)(ot,{content:String(t.data?.content??``),className:`markdown-doc px-4 py-3`})})]}):a?(0,Q.jsx)(`p`,{className:`text-sm text-destructive`,children:a}):o||i==null?(0,Q.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`Loading...`}):(0,Q.jsx)(`div`,{className:`markdown-document-frame rounded-md border border-input bg-transparent overflow-auto max-h-viewport-pane ${n}`,children:(0,Q.jsx)(ot,{content:i,className:`markdown-doc px-4 py-3`})})}function Zt({document:e,className:t=``}){let n=String(e.data?.url??e.data?.uri??``),r=ye(n);return r?(0,Q.jsx)(`div`,{className:`aspect-video w-full ${t}`,children:(0,Q.jsx)(`iframe`,{src:`https://www.youtube-nocookie.com/embed/${encodeURIComponent(r)}`,title:String(e.data?.title??e.data?.label??`YouTube video`),className:`h-full w-full rounded border`,allow:`accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture`,allowFullScreen:!0})}):null}function Qt({document:e,className:t=``}){let n=String(e.data?.url??e.data?.uri??``),[r,i]=(0,Z.useState)({blobUrl:null,blob:null,failed:!1,loading:!0}),[a,o]=(0,Z.useState)(n);n!==a&&(o(n),i({blobUrl:null,blob:null,failed:!1,loading:!0})),(0,Z.useEffect)(()=>{let e=!1,t=null,r=async e=>{if(!e.ok)throw Error(`HTTP ${e.status}`);let t=await e.blob();return new Blob([t],{type:`application/pdf`})},a=()=>{let e=localStorage.getItem(`authToken`);return fetch(`${le}/proxy/pdf?url=${encodeURIComponent(n)}`,{headers:e?{Authorization:`Bearer ${e}`}:{}})};return fetch(n).then(r).catch(()=>a().then(r)).then(n=>{e||(t=URL.createObjectURL(n),i({blobUrl:t,blob:n,failed:!1,loading:!1}))}).catch(()=>{e||i({blobUrl:null,blob:null,failed:!0,loading:!1})}),()=>{e=!0,t&&URL.revokeObjectURL(t)}},[n]);let{blobUrl:s,blob:c,failed:l,loading:u}=r,d=(()=>{try{let e=decodeURIComponent(new URL(n).pathname.split(`/`).filter(Boolean).pop()??``)||`document`;return/\.pdf$/i.test(e)?e:`${e}.pdf`}catch{return`document.pdf`}})();return(0,Q.jsxs)(`div`,{className:`flex h-full min-h-0 flex-col gap-2 ${t}`,children:[(0,Q.jsxs)(`div`,{className:`flex shrink-0 flex-wrap items-center gap-3`,children:[(0,Q.jsxs)(`a`,{href:n,target:`_blank`,rel:`noopener noreferrer`,className:`inline-flex items-center gap-1 text-xs text-primary hover:underline`,children:[(0,Q.jsx)(te,{className:`h-3 w-3`}),` `,n]}),c&&(0,Q.jsxs)(`button`,{type:`button`,onClick:()=>{if(!c)return;let e=URL.createObjectURL(c),t=window.document.createElement(`a`);t.href=e,t.download=d,window.document.body.appendChild(t),t.click(),t.remove(),setTimeout(()=>URL.revokeObjectURL(e),3e4)},className:`inline-flex items-center gap-1.5 rounded-md border px-2.5 py-1 text-xs text-muted-foreground transition-colors hover:bg-accent hover:text-foreground`,children:[(0,Q.jsx)(U,{className:`h-3.5 w-3.5`}),` Download`]})]}),u&&(0,Q.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`Loading PDF…`}),l&&(0,Q.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`Inline preview unavailable (direct fetch and server proxy both failed). Use the link above.`}),s&&(0,Q.jsx)(Vt,{blob:c,blobUrl:s,filename:d,className:`min-h-[300px] flex-1`})]})}function $t(e){if(!e)return!1;try{let t=new URL(e);return!!(/\.pdf$/i.test(t.pathname)||t.hostname.endsWith(`arxiv.org`)&&t.pathname.startsWith(`/pdf/`))}catch{return!1}}function en(e){try{return new URL(e).hostname.replace(/^www\./,``)}catch{return e}}function tn({document:e,className:t=``}){let n=e.data||{},r=String(n.url??n.uri??``),i=String(n.title??n.label??``)||en(r),a=typeof n.favIconUrl==`string`?n.favIconUrl:``,o=n.pinned===!0,s=typeof n.timestamp==`string`?n.timestamp:null,[c,l]=(0,Z.useState)(!1);return(0,Q.jsxs)(`div`,{className:`space-y-3 ${t}`,children:[(0,Q.jsxs)(`a`,{href:r,target:`_blank`,rel:`noopener noreferrer`,className:`group flex items-start gap-3 rounded-lg border bg-card p-3 transition-colors hover:bg-accent/40`,children:[(0,Q.jsx)(`div`,{className:`mt-0.5 flex h-9 w-9 shrink-0 items-center justify-center overflow-hidden rounded bg-muted`,children:a&&!c?(0,Q.jsx)(`img`,{src:a,alt:``,className:`h-5 w-5`,onError:()=>l(!0)}):(0,Q.jsx)(C,{className:`h-4 w-4 text-muted-foreground`})}),(0,Q.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,Q.jsx)(`span`,{className:`truncate font-medium leading-tight`,children:i}),o&&(0,Q.jsx)(_,{className:`h-3 w-3 shrink-0 fill-warning text-warning`})]}),(0,Q.jsx)(`div`,{className:`mt-0.5 truncate text-xs text-muted-foreground`,children:en(r)}),(0,Q.jsx)(`div`,{className:`mt-1 truncate font-mono text-[11px] text-muted-foreground/70`,children:r})]}),(0,Q.jsx)(te,{className:`mt-1 h-4 w-4 shrink-0 text-muted-foreground reveal-on-hover`})]}),s&&(0,Q.jsxs)(`p`,{className:`text-xs text-muted-foreground`,children:[`Saved `,new Date(s).toLocaleString()]})]})}function nn(e){return e.data||{}}var rn={pending:`bg-muted text-muted-foreground`,"in-progress":`bg-info/15 text-info dark:text-info`,completed:`bg-success/15 text-success dark:text-success`,cancelled:`bg-muted text-muted-foreground line-through`};function an(e){if(!e.dueDate||e.status===`completed`||e.status===`cancelled`)return!1;let t=new Date(e.dueDate).getTime();return Number.isFinite(t)&&t<Date.now()}function on(e){if(!e)return``;let t=new Date(e);return Number.isNaN(t.getTime())?``:t.toLocaleString(void 0,{month:`short`,day:`numeric`,hour:`2-digit`,minute:`2-digit`})}async function sn(e,t,n){let r=n===`completed`,i={...t.data||{},status:n,completed:r};r?i.completedAt=new Date().toISOString():delete i.completedAt,await ke(e,{id:t.id,schema:t.schema,schemaVersion:t.schemaVersion,data:i}),window.dispatchEvent(new CustomEvent(`workspace:documents:refresh`))}function cn({document:e,workspaceId:t,className:n=``}){let r=nn(e),i=Xe()!=null,[a,o]=(0,Z.useState)(!1),{replicating:s,label:c}=Re(e),l=r.status===`completed`,u=r.status??`pending`,d=an(r);return(0,Q.jsx)(`div`,{className:`space-y-3 ${n}`,children:(0,Q.jsxs)(`div`,{className:`relative flex items-start gap-3 rounded-lg border bg-card p-3 transition-opacity ${s?`opacity-60`:``}`,children:[(0,Q.jsx)(`button`,{type:`button`,onClick:async()=>{if(!(i||a)){o(!0);try{await sn(t,e,l?`pending`:`completed`)}catch{}finally{o(!1)}}},disabled:i||a||s,"aria-pressed":l,title:l?`Mark not done`:`Mark done`,className:`mt-0.5 flex h-5 w-5 shrink-0 items-center justify-center rounded border transition-colors ${l?`border-success bg-success text-success-foreground`:`border-input hover:border-success`} ${i?`cursor-default opacity-70`:``}`,children:a?(0,Q.jsx)(H,{className:`h-3 w-3 animate-spin`}):l&&(0,Q.jsx)(w,{className:`h-3.5 w-3.5`})}),(0,Q.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,Q.jsx)(`div`,{className:`font-medium leading-tight ${l?`text-muted-foreground line-through`:``}`,children:r.title||`Todo ${e.id}`}),(0,Q.jsxs)(`div`,{className:`mt-1.5 flex flex-wrap items-center gap-2 text-xs`,children:[(0,Q.jsx)(`span`,{className:`rounded-full px-2 py-0.5 ${rn[u]}`,children:pt[u]}),r.dueDate&&(0,Q.jsxs)(`span`,{className:`inline-flex items-center gap-1 ${d?`font-medium text-destructive`:`text-muted-foreground`}`,children:[(0,Q.jsx)(D,{className:`h-3 w-3`}),on(r.dueDate),d?` · overdue`:``]}),typeof r.priority==`number`&&(0,Q.jsxs)(`span`,{className:`inline-flex items-center gap-1 text-muted-foreground`,children:[(0,Q.jsx)(R,{className:`h-3 w-3`}),`P`,r.priority]})]}),r.description&&(0,Q.jsx)(ot,{content:String(r.description),className:`mt-2 text-sm text-muted-foreground`}),s&&(0,Q.jsxs)(`div`,{className:`mt-2 inline-flex items-center gap-1.5 text-xs text-muted-foreground`,role:`status`,children:[(0,Q.jsx)(H,{className:`h-3 w-3 animate-spin`}),c]})]})]})})}function ln(e,t){let{fetchBlob:n}=Ze(e),r=Xe(),i=t.checksumArray?.[0]||t.updatedAt||``,a=JSON.stringify([e,r,t.id,i]),o=typeof t.data?.body==`string`?t.data.body:null,s=typeof t.data?.bodyHtml==`string`?t.data.bodyHtml:null,c=o!==null||s!==null,[l,u]=(0,Z.useState)(null);return(0,Z.useEffect)(()=>{if(c)return;let e=new AbortController;return n(t.id,{format:`email`,version:i,signal:e.signal}).then(async({blob:t})=>{let n=JSON.parse(await t.text());if(typeof n.body!=`string`||n.bodyHtml!=null&&typeof n.bodyHtml!=`string`)throw Error(`Invalid email content response`);e.signal.aborted||u({key:a,body:n.body,bodyHtml:n.bodyHtml||null,error:null})}).catch(t=>{e.signal.aborted||u({key:a,body:``,bodyHtml:null,error:t instanceof Error?t.message:String(t)})}),()=>e.abort()},[a,c,n,t.id,i]),c?{body:o||``,bodyHtml:s,loading:!1,error:null}:l?.key===a?{...l,loading:!1}:{body:``,bodyHtml:null,loading:!0,error:null}}function un(e){return e?typeof e==`string`?e:e.name&&e.address?`${e.name} <${e.address}>`:e.address||e.name||``:``}function $(e){return e?(Array.isArray(e)?e:[e]).map(e=>un(e)).filter(Boolean).join(`, `):``}function dn(e){if(!Number.isFinite(e))return``;let t=Number(e);return t<1024?`${t} B`:t<1048576?`${(t/1024).toFixed(1)} KB`:`${(t/1024/1024).toFixed(1)} MB`}function fn(e,t,n){let r=0;ht.addHook(`afterSanitizeAttributes`,e=>{if(e.tagName===`IMG`){let i=e.getAttribute(`src`)||``,a=i.toLowerCase();if(a.startsWith(`cid:`)){let n=i.slice(4).replace(/^<|>$/g,``),r=t.get(n)||t.get(`<${n}>`);r?e.setAttribute(`src`,r):e.removeAttribute(`src`)}else(a.startsWith(`http:`)||a.startsWith(`https:`)||a.startsWith(`//`))&&(r++,n?e.setAttribute(`src`,i.replace(/^http:/i,`https:`).replace(/^\/\//,`https://`)):e.removeAttribute(`src`))}e.tagName===`A`&&(e.setAttribute(`target`,`_blank`),e.setAttribute(`rel`,`noopener noreferrer`))});try{let t=ht.sanitize(e,{FORBID_TAGS:[`script`,`iframe`,`object`,`embed`,`form`,`base`,`link`,`meta`],FORBID_ATTR:[`srcset`]}),i=`<!doctype html><html><head>
3
- <meta charset="utf-8">
4
- <meta name="viewport" content="width=device-width,initial-scale=1">
5
- <meta http-equiv="Content-Security-Policy" content="${`default-src 'none'; img-src data:${n?` https:`:``}; style-src 'unsafe-inline'`}">
6
- <style>html{overflow:auto}body{margin:12px;font:14px/1.5 system-ui,sans-serif;color:#1a1a1a;background:#fff}@media(max-width:480px){body{margin:8px}}</style>
7
- </head><body>${t}</body></html>`;return{url:URL.createObjectURL(new Blob([i],{type:`text/html;charset=utf-8`})),remoteCount:r}}finally{ht.removeHook(`afterSanitizeAttributes`)}}function pn(e){return new Promise((t,n)=>{let r=new FileReader;r.onload=()=>t(String(r.result)),r.onerror=()=>n(r.error),r.readAsDataURL(e)})}function mn(e){return(0,Q.jsx)(hn,{...e},`${e.workspaceId}:${e.document.id}`)}function hn({workspaceId:e,document:t,className:n=``}){let{fetchBlob:r,download:i}=Ze(e),a=t.data||{},o=Array.isArray(a.attachments)?a.attachments:[],{body:s,bodyHtml:c,loading:u,error:d}=ln(e,t),[f,p]=(0,Z.useState)(null),[m,h]=(0,Z.useState)(!1),[g,_]=(0,Z.useState)(!1),[y,x]=(0,Z.useState)(0),[S,C]=(0,Z.useState)(null);(0,Z.useEffect)(()=>{if(!c||m)return;let e=!1,n=[],i=o.filter(e=>e.contentId&&e.url);return Promise.all(i.slice(0,20).map(async e=>{try{let{blob:n}=await r(t.id,{url:e.url}),i=await pn(n);return[String(e.contentId).replace(/^<|>$/g,``),i]}catch{return null}})).then(t=>{if(e)return;let r=new Map(t.filter(Boolean)),{url:i,remoteCount:a}=fn(c,r,g);n.push(i),p(i),x(a)}).catch(t=>{e||C(String(t instanceof Error?t.message:t))}),()=>{e=!0,n.forEach(e=>URL.revokeObjectURL(e)),p(null)}},[e,t.id,c,m,g]);let w=typeof a.date==`string`?new Date(a.date).toLocaleString():null,T=o.filter(e=>!e.isInline||!e.contentId),E=async e=>{if(e.url)try{await i(t.id,e.filename||`attachment`,{url:e.url})}catch(e){C(e instanceof Error?e.message:String(e))}};return(0,Q.jsxs)(`div`,{className:`flex h-full min-h-0 min-w-0 flex-col gap-3 ${n}`,children:[(0,Q.jsx)(`div`,{className:`shrink-0 rounded-md border bg-muted/30 p-2 text-sm sm:p-3`,children:(0,Q.jsxs)(`div`,{className:`flex flex-wrap items-start justify-between gap-2 sm:gap-3`,children:[(0,Q.jsxs)(`div`,{className:`min-w-0 flex-1 basis-64 space-y-1`,children:[(0,Q.jsx)(`div`,{className:`truncate text-base font-semibold`,children:String(a.subject??`(no subject)`)}),(0,Q.jsxs)(`details`,{className:`sm:hidden`,children:[(0,Q.jsxs)(`summary`,{className:`cursor-pointer text-xs`,children:[(0,Q.jsx)(`span`,{className:`inline-block max-w-[85%] truncate align-bottom`,children:typeof a.from==`object`&&a.from?a.from.name||a.from.address:String(a.from||`Unknown sender`)}),(0,Q.jsx)(`span`,{className:`ml-2 text-muted-foreground`,children:`Details`})]}),(0,Q.jsxs)(`div`,{className:`mt-2 space-y-1 break-words text-xs`,children:[(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`span`,{className:`text-muted-foreground`,children:`From:`}),` `,un(a.from)]}),$(a.to)&&(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`span`,{className:`text-muted-foreground`,children:`To:`}),` `,$(a.to)]}),$(a.cc)&&(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`span`,{className:`text-muted-foreground`,children:`Cc:`}),` `,$(a.cc)]}),w&&(0,Q.jsx)(`div`,{className:`text-xs text-muted-foreground`,children:w})]})]}),(0,Q.jsxs)(`div`,{className:`hidden space-y-1 break-words sm:block`,children:[(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`span`,{className:`text-muted-foreground`,children:`From:`}),` `,un(a.from)]}),$(a.to)&&(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`span`,{className:`text-muted-foreground`,children:`To:`}),` `,$(a.to)]}),$(a.cc)&&(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`span`,{className:`text-muted-foreground`,children:`Cc:`}),` `,$(a.cc)]}),w&&(0,Q.jsx)(`div`,{className:`text-xs text-muted-foreground`,children:w})]})]}),c&&(0,Q.jsxs)(`div`,{className:`flex max-w-full flex-wrap gap-2`,children:[(0,Q.jsxs)(q,{size:`sm`,variant:`outline`,onClick:()=>h(!m),children:[m?(0,Q.jsx)(l,{className:`mr-1.5 h-3.5 w-3.5`}):(0,Q.jsx)(V,{className:`mr-1.5 h-3.5 w-3.5`}),m?`HTML`:`Plain text`]}),!m&&y>0&&(0,Q.jsxs)(q,{size:`sm`,variant:g?`secondary`:`outline`,onClick:()=>_(!g),title:`Remote images can reveal your IP/read status to the sender`,children:[g?(0,Q.jsx)(b,{className:`mr-1.5 h-3.5 w-3.5`}):(0,Q.jsx)(v,{className:`mr-1.5 h-3.5 w-3.5`}),g?`Hide remote images`:`Show remote images (${y})`]})]})]})}),(S||d)&&(0,Q.jsx)(`p`,{className:`text-sm text-destructive`,children:S||d}),u?(0,Q.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`Loading message…`}):d?(0,Q.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:String(a.bodyPreview||`Message content could not be loaded.`)}):!m&&c?f?(0,Q.jsx)(`iframe`,{src:f,sandbox:``,title:String(a.subject??`email`),className:`min-h-[12rem] w-full flex-1 rounded border bg-white`}):(0,Q.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`Rendering...`}):(0,Q.jsx)(`pre`,{className:`min-h-[12rem] flex-1 overflow-auto whitespace-pre-wrap rounded bg-muted p-3 text-sm`,children:s||`(empty body)`}),T.length>0&&(0,Q.jsxs)(`div`,{className:`shrink-0 space-y-1`,children:[(0,Q.jsxs)(`div`,{className:`text-xs font-medium text-muted-foreground`,children:[`Attachments (`,T.length,`)`]}),T.map((e,t)=>(0,Q.jsxs)(`div`,{className:`flex items-center justify-between gap-2 rounded border px-2 py-1.5 text-sm`,children:[(0,Q.jsxs)(`span`,{className:`inline-flex min-w-0 items-center gap-2`,children:[(0,Q.jsx)(V,{className:`h-4 w-4 shrink-0 text-muted-foreground`}),(0,Q.jsx)(`span`,{className:`truncate`,children:e.filename||`attachment`}),(0,Q.jsx)(`span`,{className:`shrink-0 text-xs text-muted-foreground`,children:dn(e.size)})]}),e.url&&(0,Q.jsxs)(`button`,{onClick:()=>E(e),className:`inline-flex shrink-0 items-center gap-1 text-xs text-primary hover:underline`,children:[(0,Q.jsx)(U,{className:`h-3 w-3`}),` Download`]})]},e.url||t))]})]})}var gn=5e5;function _n(e){let t=new DOMParser().parseFromString(e,`text/html`);for(let e of Array.from(t.querySelectorAll(`a[href]`)))(e.getAttribute(`href`)||``).startsWith(`#`)||(e.setAttribute(`target`,`_blank`),e.setAttribute(`rel`,`noopener noreferrer`));if(t.querySelectorAll(`base`).forEach(e=>e.remove()),!t.querySelector(`meta[charset]`)){let e=t.createElement(`meta`);e.setAttribute(`charset`,`utf-8`),t.head.prepend(e)}return`${t.doctype?`<!doctype ${t.doctype.name}>`:`<!doctype html>`}\n${t.documentElement.outerHTML}`}function vn(e){return(0,Q.jsx)(yn,{...e},`${e.workspaceId}:${e.document.id}`)}function yn({workspaceId:e,document:t,className:n=``}){let{blob:r,error:i,loading:a}=tt(e,t.id,{typeHint:`text/html`,version:t.checksumArray?.[0]??null}),[o,s]=(0,Z.useState)(null),[c,u]=(0,Z.useState)(null),[d,f]=(0,Z.useState)(!0),[p,h]=(0,Z.useState)(!1);if((0,Z.useEffect)(()=>{if(!r)return;let e=!1,t=null;return r.text().then(n=>{e||(s(n),t=URL.createObjectURL(new Blob([_n(n)],{type:`text/html;charset=utf-8`})),u(t))}),()=>{e=!0,t&&URL.revokeObjectURL(t),u(null)}},[r]),i)return(0,Q.jsx)(`p`,{className:`text-sm text-destructive`,children:i});if(a||!c)return(0,Q.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`Loading page...`});let g=`inline-flex items-center gap-1.5 rounded-md border px-2.5 py-1 text-xs text-muted-foreground transition-colors hover:bg-accent hover:text-foreground`;return(0,Q.jsxs)(`div`,{className:`flex h-full min-h-0 min-w-0 flex-col gap-2 ${n}`,children:[p?(0,Q.jsx)(`pre`,{className:`min-h-0 flex-1 overflow-auto whitespace-pre-wrap rounded bg-muted p-3 text-xs max-h-viewport-pane`,children:o&&o.length>gn?`${o.slice(0,gn)}\n…`:o}):(0,Q.jsx)(`iframe`,{src:c,title:t.data?.title?String(t.data.title):`HTML page`,sandbox:d?`allow-scripts allow-popups allow-popups-to-escape-sandbox`:`allow-popups allow-popups-to-escape-sandbox`,referrerPolicy:`no-referrer`,className:`min-h-[60vh] w-full flex-1 rounded-md border bg-white`},d?`scripts`:`static`),(0,Q.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[(0,Q.jsxs)(`button`,{type:`button`,className:g,onClick:()=>h(!p),children:[p?(0,Q.jsx)(F,{className:`h-3.5 w-3.5`}):(0,Q.jsx)(l,{className:`h-3.5 w-3.5`}),p?`Page`:`Source`]}),!p&&(0,Q.jsxs)(`button`,{type:`button`,className:g,onClick:()=>f(!d),title:`Page scripts run isolated from the app`,children:[d?(0,Q.jsx)(oe,{className:`h-3.5 w-3.5`}):(0,Q.jsx)(m,{className:`h-3.5 w-3.5`}),d?`Disable scripts`:`Enable scripts`]}),(0,Q.jsx)(Ht,{workspaceId:e,document:t})]})]})}function bn({attachment:e,workspaceId:t,document:n}){let{download:r}=Ze(t),i=e.mimeType||e.contentType||``,a=e.name||e.filename||`Attachment`,o=i.startsWith(`audio/`)||i.startsWith(`video/`),{blobUrl:s,error:c,loading:l}=tt(t,n.id,{url:e.url,typeHint:i,enabled:!o&&!!e.url}),{src:u,error:d,loading:f}=rt(t,n.id,{url:e.url,enabled:o&&!!e.url}),[p,m]=(0,Z.useState)(!1),[h,g]=(0,Z.useState)(``),_=o?d:c;return(0,Q.jsxs)(`div`,{className:`space-y-2 rounded border p-2`,children:[_&&(0,Q.jsx)(`p`,{className:`text-xs text-destructive`,children:_}),(o?f:l)&&(0,Q.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`Loading attachment…`}),!o&&s&&i.startsWith(`image/`)&&(0,Q.jsx)(`img`,{src:s,alt:a,className:`max-h-96 max-w-full rounded object-contain`}),o&&u&&(i.startsWith(`video/`)?(0,Q.jsx)(`video`,{controls:!0,playsInline:!0,preload:`metadata`,src:u,onError:()=>m(!0),className:`max-h-96 w-full rounded`},u):(0,Q.jsx)(`audio`,{controls:!0,preload:`metadata`,src:u,onError:()=>m(!0),className:`w-full`},u)),p&&(0,Q.jsx)(`p`,{role:`alert`,className:`text-xs text-destructive`,children:`This media could not be played in your browser. Download it to play in another app.`}),h&&(0,Q.jsx)(`p`,{role:`alert`,className:`text-xs text-destructive`,children:h}),e.url&&(0,Q.jsxs)(`button`,{className:`text-sm text-primary underline`,onClick:()=>{r(n.id,a,{url:e.url}).catch(()=>g(`Attachment could not be downloaded.`))},children:[`Download `,a]})]})}function xn(e){let t=e.document.data,n=t.sender,r=t.channel,i=Array.isArray(t.attachments)?t.attachments:[],a=t.timestamp?new Date(String(t.timestamp)):null;return(0,Q.jsxs)(`article`,{className:`space-y-4 p-3 ${e.className||``}`,children:[(0,Q.jsxs)(`header`,{className:`space-y-1 border-b pb-3`,children:[(0,Q.jsx)(`p`,{className:`font-medium`,children:n?.name||n?.displayName||n?.username||n?.id||`Unknown sender`}),(0,Q.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:[r?.name||r?.id,String(t.platform||``),a&&!Number.isNaN(a.getTime())?a.toLocaleString():``].filter(Boolean).join(` · `)})]}),(0,Q.jsx)(`p`,{className:`whitespace-pre-wrap break-words text-sm`,children:String(t.text||`(No text)`)}),!!t.mediaError&&(0,Q.jsx)(`p`,{className:`text-xs text-destructive`,children:String(t.mediaError)}),i.map((t,n)=>(0,Q.jsx)(bn,{...e,attachment:t},t.url||n))]})}var Sn={email:j,phone:G,sms:P,chat:P,slack:P,matrix:P,web:C,url:C},Cn={person:`Person`,organization:`Organization`,service:`Service`,bot:`Bot`},wn=e=>Array.isArray(e)?e:[];function Tn(e,t){return t?e===`email`?`mailto:${t}`:e===`phone`||e===`sms`?`tel:${t.replace(/[^\d+]/g,``)}`:/^https?:\/\//i.test(t)?t:null:null}function En({title:e,count:t,children:n}){return t===0?null:(0,Q.jsxs)(`div`,{className:`space-y-1`,children:[(0,Q.jsx)(`p`,{className:`text-xs font-medium text-muted-foreground`,children:e}),(0,Q.jsx)(`div`,{className:`space-y-1`,children:n})]})}function Dn({icon:e,primary:t,children:n,title:r}){return(0,Q.jsxs)(`div`,{className:`flex min-w-0 items-center gap-2 rounded-md border bg-card px-2.5 py-1.5 text-sm`,title:r,children:[(0,Q.jsx)(e,{className:`h-3.5 w-3.5 shrink-0 text-muted-foreground`}),(0,Q.jsx)(`div`,{className:`min-w-0 flex-1 truncate`,children:n}),t&&(0,Q.jsx)(z,{className:`h-3 w-3 shrink-0 fill-current text-data-5`,"aria-label":`Primary`})]})}function On({document:e,className:t}){let n=e.data??{},r=wn(n.identifiers),i=wn(n.channels),a=wn(n.organizations),o=wn(n.links),s=wn(n.tags),c=String(n.displayName||``).trim(),l=Ee(e.schema,ve),u=String(n.primaryEmail||``).trim(),d=n.name&&typeof n.name==`object`?n.name:{},f=[d.prefix,d.given,d.middle,d.family,d.suffix].map(e=>String(e||``).trim()).filter(Boolean).join(` `),p=i.some(e=>e.kind===`email`&&e.value===u);return(0,Q.jsxs)(`div`,{className:K(`space-y-4`,t),children:[(0,Q.jsxs)(`div`,{className:`space-y-1`,children:[(0,Q.jsx)(`h2`,{className:`text-lg font-semibold`,children:c||`Identity ${e.id}`}),(0,Q.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2 text-xs text-muted-foreground`,children:[l&&(0,Q.jsx)(`span`,{className:`rounded-full bg-muted px-2 py-0.5`,children:Cn[l]||l}),f&&f!==c&&(0,Q.jsx)(`span`,{children:f}),String(n.timezone||``)&&(0,Q.jsx)(`span`,{children:String(n.timezone)}),String(n.locale||``)&&(0,Q.jsx)(`span`,{children:String(n.locale)})]})]}),u&&!p&&(0,Q.jsx)(En,{title:`Primary email`,count:1,children:(0,Q.jsx)(Dn,{icon:j,primary:!0,children:(0,Q.jsx)(`a`,{href:`mailto:${u}`,className:`hover:underline`,children:u})})}),(0,Q.jsx)(En,{title:`Channels`,count:i.length,children:i.map((e,t)=>{let n=String(e.kind||``).toLowerCase(),r=String(e.value||``),i=Tn(n,r),a=Sn[n]||P;return(0,Q.jsxs)(Dn,{icon:a,primary:e.primary,title:e.platform||n,children:[i?(0,Q.jsx)(`a`,{href:i,className:`hover:underline`,target:i.startsWith(`http`)?`_blank`:void 0,rel:`noopener noreferrer`,children:r}):r,e.label&&(0,Q.jsx)(`span`,{className:`ml-2 text-xs text-muted-foreground`,children:e.label})]},`${n}:${r}:${t}`)})}),(0,Q.jsx)(En,{title:`Identifiers`,count:r.length,children:r.map((e,t)=>(0,Q.jsxs)(Dn,{icon:ae,primary:e.primary,children:[(0,Q.jsx)(`span`,{className:`font-mono text-xs`,children:e.identifier}),(0,Q.jsx)(`span`,{className:`ml-2 text-xs text-muted-foreground`,children:[e.type,e.provider].filter(Boolean).join(` · `)})]},`${e.type}:${e.identifier}:${t}`))}),(0,Q.jsx)(En,{title:`Organizations`,count:a.length,children:a.map((e,t)=>(0,Q.jsxs)(Dn,{icon:E,children:[e.name,e.role&&(0,Q.jsx)(`span`,{className:`ml-2 text-xs text-muted-foreground`,children:e.role})]},`${e.name}:${t}`))}),(0,Q.jsx)(En,{title:`Links`,count:o.length,children:o.map((e,t)=>(0,Q.jsxs)(Dn,{icon:k,children:[(0,Q.jsx)(`span`,{className:`font-mono text-xs`,children:e.target}),e.type&&(0,Q.jsx)(`span`,{className:`ml-2 text-xs text-muted-foreground`,children:e.type})]},`${e.type}:${e.target}:${t}`))}),s.length>0&&(0,Q.jsx)(`div`,{className:`flex flex-wrap gap-1.5`,children:s.map(e=>(0,Q.jsx)(`span`,{className:`rounded-full bg-muted px-2 py-0.5 text-xs text-muted-foreground`,children:e},e))})]})}function kn({document:e}){let t=String(e.metadata?.contentType||`application/octet-stream`);return(0,Q.jsxs)(`p`,{className:`text-sm text-muted-foreground`,children:[`No inline preview available for `,(0,Q.jsx)(`span`,{className:`font-mono`,children:t}),`. Use Download.`]})}function An(e){let t=e.schema;if(t===`data/schema/note`)return Xt;if(t===`data/schema/drawing`)return Gt;if(t===`data/schema/task`)return cn;if(t===`data/schema/message/email`)return mn;if(t===`data/schema/message`)return xn;if(t===`data/schema/identity`||t.startsWith(`data/schema/identity/`))return On;if(t===`data/schema/tab`||t===`data/schema/link`){let t=String(e.data?.url??e.data?.uri??``);return ye(t)?Zt:$t(t)?Qt:tn}if(t!==`data/schema/file`)return null;let n=String(e.metadata?.contentType||``);switch(me(n,Y(e))){case`image`:return Gt;case`audio`:return Kt;case`video`:return qt;case`pdf`:return Jt;case`html`:return vn;case`markdown`:return Xt;case`text`:return Yt;default:return kn}}function jn({onSearch:e,onDraftChange:t,inputRef:n,workspaceId:r,label:i=`Search documents`,clearOnSubmit:a=!0,showSubmitButton:o=!0}){let s=(0,Z.useRef)(null),c=n??s;return(0,Q.jsxs)(`form`,{className:`canvas-search-input`,role:`search`,onSubmit:n=>{n.preventDefault();let r=n.currentTarget.elements.namedItem(`query`),i=r.value.trim();i&&(e(i),a&&(r.value=``,t?.(``)))},children:[(0,Q.jsx)(`input`,{ref:c,name:`query`,type:`search`,"aria-label":i,placeholder:i,autoComplete:`off`,enterKeyHint:`search`,onChange:e=>t?.(e.target.value),onKeyDown:e=>{e.key===`Enter`&&e.nativeEvent.isComposing&&e.preventDefault()}}),o&&(0,Q.jsx)(`button`,{type:`submit`,className:`canvas-nav-button`,"aria-label":`Run search`,title:`Run search`,children:(0,Q.jsx)(W,{size:17})}),r&&(0,Q.jsx)(kt,{workspaceId:r,inputRef:c,onChange:t})]})}function Mn({queries:e,onRemoveQuery:t,scope:n=`path`,onScopeChange:r}){return(0,Q.jsxs)(`div`,{className:`canvas-search-options`,children:[r&&(0,Q.jsxs)(`div`,{className:`canvas-search-scopes`,"aria-label":`Search scope`,children:[(0,Q.jsx)(`span`,{children:`Search in`}),(0,Q.jsx)(`button`,{type:`button`,"aria-pressed":n===`path`,onClick:()=>r(`path`),children:`This path`}),(0,Q.jsx)(`button`,{type:`button`,"aria-pressed":n===`workspace`,onClick:()=>r(`workspace`),children:`Workspace`})]}),e.length>0&&(0,Q.jsxs)(`div`,{className:`canvas-search-queries`,"aria-label":`Active searches`,children:[e.map((e,n)=>{let r=/"[^"]+/.test(e);return(0,Q.jsxs)(`span`,{className:r?`canvas-search-query canvas-search-query-exact`:`canvas-search-query`,children:[r?(0,Q.jsx)(ee,{size:12,"aria-hidden":`true`}):(0,Q.jsx)(W,{size:12,"aria-hidden":`true`}),(0,Q.jsx)(`span`,{title:r?`${e} (exact phrase)`:e,children:e}),t&&(0,Q.jsx)(`button`,{type:`button`,onClick:()=>t(n),"aria-label":`Remove search: ${e}`,children:(0,Q.jsx)(g,{size:14})})]},`${e}-${n}`)}),t&&e.length>1&&(0,Q.jsx)(`button`,{type:`button`,onClick:()=>t(-1),className:`canvas-search-clear`,children:`Clear all`})]})]})}function Nn({children:e,accentColor:t}){return(0,Q.jsxs)(`div`,{className:`canvas-navigation-tabs`,children:[(0,Q.jsx)(`span`,{"aria-hidden":`true`,className:`canvas-tab-divider`,style:t?{backgroundColor:t}:void 0}),e]})}function Pn({workspace:e,workspaceIcon:t,tree:n,path:i,document:a,section:o,onBack:s,onBrowseWorkspaces:c,onBrowseTree:l,onNavigatePath:u,onDocument:d,onSection:f,onFilter:p,filtersActive:m,filtersOpen:h,onAdd:_,search:v,onDraftChange:y,tabs:b,accentColor:S,actions:C}){let w=Ve(),[T,E]=(0,Z.useState)(!1),[D,O]=(0,Z.useState)(!1),k=(0,Z.useRef)(null),A=(0,Z.useRef)(null),j=(0,Z.useRef)(null),N=(0,Z.useRef)(!1),P=JSON.stringify([e,n,i,a]),[F,ee]=(0,Z.useState)(P);F!==P&&(ee(P),E(!1)),(0,Z.useEffect)(()=>{T?A.current?.focus():(k.current&&(k.current.scrollLeft=k.current.scrollWidth,O(k.current.scrollLeft>1)),N.current&&=(j.current?.focus(),!1))},[T,P,o]);let I=()=>{N.current=!0,E(!1),y?.(``)},L=w&&!!l,te=T?I:L?l:s??l,ne=T?`Back to address`:L?`Back to tree`:`Back to previous view`,R=fe(i,e).slice(1),z=(e,t,n,r,i=!1)=>n?(0,Q.jsx)(`button`,{type:`button`,className:t,onClick:n,title:r,"aria-current":i?`location`:void 0,children:e}):(0,Q.jsx)(`span`,{className:`canvas-address-label ${t}`,title:r,"aria-current":i?`location`:void 0,children:e});return(0,Q.jsxs)(`header`,{className:`canvas-navigation${b?` has-tabs`:``}`,style:S?{borderTopColor:S}:void 0,children:[b&&(0,Q.jsx)(Nn,{accentColor:S,children:b}),(0,Q.jsxs)(`div`,{className:`canvas-address-row`,children:[(0,Q.jsx)(`button`,{type:`button`,className:`canvas-nav-button`,"aria-label":ne,title:ne,disabled:!T&&!s&&!l,onClick:te,children:L&&!T?(0,Q.jsx)(ie,{size:19}):(0,Q.jsx)(re,{size:19})}),(0,Q.jsxs)(`div`,{className:`canvas-address-field`,onDoubleClick:e=>{v&&!e.target.closest(`button`)&&E(!0)},onKeyDown:e=>{e.key===`Escape`&&T&&(e.preventDefault(),e.stopPropagation(),I())},children:[T&&v?(0,Q.jsx)(jn,{inputRef:A,workspaceId:v.localOnly?void 0:v.workspaceId,onSearch:v.onSearch,onDraftChange:y,clearOnSubmit:!v.localOnly,showSubmitButton:!1,label:v.queries.length?`Refine search…`:`Search documents…`}):(0,Q.jsx)(Q.Fragment,{children:(0,Q.jsxs)(`div`,{ref:k,className:`canvas-address-crumbs${D?` is-scrolled`:``}`,onScroll:e=>O(e.currentTarget.scrollLeft>1),role:`navigation`,"aria-label":`Canvas address`,tabIndex:0,onKeyDown:e=>{e.key===`Enter`&&e.target===e.currentTarget&&v&&E(!0)},children:[z((0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(r,{icon:t||`ph:stack-fill`,className:`h-4 w-4 shrink-0`,"aria-hidden":`true`}),(0,Q.jsx)(`span`,{className:`truncate`,children:e})]}),`canvas-address-workspace`,c,`Browse workspaces`),n&&z(`[${n}]`,`canvas-address-tree`,l,`Browse tree: ${n}`),z(`:/`,`canvas-address-root`,u?()=>u(`/`):void 0,`Go to tree root`),R.map((e,t)=>(0,Q.jsxs)(`span`,{className:`canvas-address-segment`,children:[t>0&&(0,Q.jsx)(`span`,{"aria-hidden":`true`,children:`/`}),z(e.label,``,u?()=>u(e.path):void 0,e.path,!a&&t===R.length-1)]},e.path)),a&&(0,Q.jsxs)(`span`,{className:`canvas-address-segment`,children:[(0,Q.jsx)(`span`,{"aria-hidden":`true`,children:R.length?`/`:``}),z(a,``,d,a)]}),o&&z(`#${o}`,`canvas-address-section`,f,o,!0)]})}),v&&(0,Q.jsxs)(`button`,{ref:j,type:`button`,className:`canvas-nav-button canvas-address-search`,onClick:()=>{T?A.current?.form?.requestSubmit():E(!0)},"aria-label":T?`Run search`:`Search this canvas`,"aria-expanded":T,title:T?`Run search`:`Search this canvas`,children:[(0,Q.jsx)(W,{size:17}),v.queries.length>0&&(0,Q.jsx)(`span`,{className:`canvas-nav-dot`})]})]}),p&&(0,Q.jsxs)(`button`,{type:`button`,className:`canvas-nav-button canvas-filter-button`,onClick:p,"aria-label":m?`Filters active`:`Filters`,"aria-expanded":!!h,"data-active":!!m,title:m?`Filters active`:`Filters`,children:[(0,Q.jsx)(M,{size:19}),m&&(0,Q.jsx)(`span`,{className:`canvas-nav-dot`})]}),_&&(0,Q.jsx)(`button`,{type:`button`,className:`canvas-nav-button canvas-add-button`,onClick:_,"aria-label":`Add here`,title:`Add here`,children:(0,Q.jsx)(x,{size:21})}),C]}),T&&v&&(0,Q.jsxs)(`div`,{className:`canvas-search-dropdown`,children:[(0,Q.jsxs)(`div`,{className:`canvas-search-heading`,children:[(0,Q.jsx)(`span`,{children:v.localOnly?`Filter documents on this page`:y?`Type to filter this page · Enter to search all results`:`Search text or an exact ID, e.g. @id:123`}),(0,Q.jsx)(`button`,{type:`button`,className:`canvas-nav-button`,onClick:I,"aria-label":`Close search`,children:(0,Q.jsx)(g,{size:16})})]}),(0,Q.jsx)(Mn,{...v})]}),!T&&v&&v.queries.length>0&&(0,Q.jsx)(`div`,{className:`px-3 pb-2`,children:(0,Q.jsx)(Mn,{queries:v.queries,onRemoveQuery:v.onRemoveQuery})})]})}function Fn({workspaceId:e,document:t,className:n}){let r=An(t);return r?(0,Q.jsx)(r,{workspaceId:e,document:t,className:n}):(0,Q.jsx)(`pre`,{className:`overflow-auto p-2 text-xs`,children:JSON.stringify(t.data,null,2)})}function In({workspaceId:e,documentId:t}){let[n,r]=(0,Z.useState)(null),[i,a]=(0,Z.useState)(``),[o,s]=(0,Z.useState)({}),[c,l]=(0,Z.useState)(null),u=(0,Z.useCallback)(async()=>{try{let n=await vt(e,t);r(n),a(``)}catch(e){a(e instanceof Error?e.message:`Could not load thread`)}},[e,t]);return(0,Z.useEffect)(()=>{let n=!0;vt(e,t).then(e=>{n&&(r(e),a(``))}).catch(e=>{n&&a(e instanceof Error?e.message:`Could not load thread`)});let i=()=>{u()};return window.addEventListener(`workspace:documents:refresh`,i),window.addEventListener(ut,i),()=>{n=!1,window.removeEventListener(`workspace:documents:refresh`,i),window.removeEventListener(ut,i)}},[e,t,u]),i?(0,Q.jsxs)(`div`,{className:`p-3`,children:[(0,Q.jsx)(`p`,{role:`alert`,className:`text-sm text-destructive`,children:i}),(0,Q.jsx)(q,{variant:`outline`,size:`sm`,onClick:()=>void u(),children:`Retry`})]}):!n||n.documentId!==t?(0,Q.jsx)(`p`,{className:`p-3 text-sm text-muted-foreground`,children:`Loading thread…`}):(0,Q.jsxs)(`section`,{"aria-label":`Message thread`,className:`space-y-3 p-2`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,Q.jsxs)(`h3`,{className:`text-sm font-medium`,children:[`Thread · `,n.documents.length,` message`,n.documents.length===1?``:`s`]}),(0,Q.jsx)(q,{size:`sm`,variant:`outline`,onClick:()=>void u(),children:`Refresh`})]}),n.documents.length===1&&(0,Q.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`No linked replies have been indexed. Other messages in this conversation are separate from this reply thread.`}),n.truncated&&(0,Q.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`Showing up to 200 linked messages.`}),n.documents.map(r=>{let i=ge(r),a=r.schema===`data/schema/message/email`,c=a||[`slack`,`whatsapp`].includes(String(r.data.platform)),u=r.data.timestamp||r.data.date,d=u?new Date(String(u)):null,f=(n.parents[r.id]||[]).flatMap(e=>{let t=n.documents.find(t=>Number(t.id)===e);return t?[ge(t).title]:[]}),p=o[Number(r.id)]??Number(r.id)===t;return(0,Q.jsxs)(`details`,{open:p,onToggle:e=>{let t=e.currentTarget.open;s(e=>e[Number(r.id)]===t?e:{...e,[Number(r.id)]:t})},className:`rounded-lg border bg-card`,children:[(0,Q.jsxs)(`summary`,{className:`cursor-pointer space-y-1 p-3 text-sm`,children:[(0,Q.jsx)(`span`,{className:`font-medium`,children:i.title}),(0,Q.jsxs)(`span`,{className:`block text-xs text-muted-foreground`,children:[i.subtitle,d&&!Number.isNaN(d.getTime())?` · ${d.toLocaleString()}`:``]}),f.length>0&&(0,Q.jsxs)(`span`,{className:`block text-xs text-muted-foreground`,children:[`Reply to `,f.join(`, `)]})]}),p&&c&&(0,Q.jsx)(`div`,{className:`flex flex-wrap gap-2 px-3 pb-2`,children:(a?[`reply`,`replyAll`,`forward`]:[`reply`]).map(e=>(0,Q.jsx)(q,{variant:`outline`,size:`sm`,onClick:()=>l({document:r,mode:e}),children:e===`replyAll`?`Reply all`:e===`forward`?`Forward`:`Reply`},e))}),p&&(0,Q.jsx)(Fn,{workspaceId:e,document:r})]},r.id)}),c&&(0,Q.jsx)(bt,{workspaceId:e,replyToDocumentId:Number(c.document.id),mode:c.mode,originalSubject:typeof c.document.data.subject==`string`?c.document.data.subject:void 0,onClose:()=>l(null)},`${c.document.id}:${c.mode}`)]})}function Ln(e,t){return e.slice(0,3).map(e=>{let n=t.get(e.id),r=e.reason===`not-found`?`Source missing from the storage index. Resync the source backend and retry.`:e.reason===`not found`?`Document no longer exists in this workspace. Refresh the list and select it again.`:e.reason;return`${n?`${n} (ID ${e.id})`:`Document ${e.id}`}: ${r}`}).join(`
8
- `)+(e.length>3?`\n…and ${e.length-3} more failed file${e.length===4?``:`s`}.`:``)}var Rn=e(i(),1),zn=[{mode:`copy`,label:`Copy to`,icon:(0,Q.jsx)(S,{className:`h-3.5 w-3.5`})},{mode:`move`,label:`Move to`,icon:(0,Q.jsx)(N,{className:`h-3.5 w-3.5`})},{mode:`delete`,label:`Delete from`,icon:(0,Q.jsx)(T,{className:`h-3.5 w-3.5`})}],Bn=[{value:`rename`,label:`Rename mine (file-1.ext)`},{value:`overwrite`,label:`Overwrite the existing file`},{value:`error`,label:`Skip the document`}],Vn=`h-9 w-full rounded-md border bg-background px-2 text-xs outline-none focus:ring-2 focus:ring-ring disabled:opacity-50`;function Hn(e){return e.driver===`cacache`?A:e.config?.remote===!0?y:s}function Un({workspaceId:e,documentCount:t,initialMode:n=`copy`,defaultFilename:r=``,onConfirm:i,onClose:a,saving:o=!1,sizeClassName:c,deleteFrom:l,progress:u,stopping:d=!1,onStop:f}){let{showErrorToast:p}=X(),[m,_]=(0,Z.useState)(!1);gt(a,!o&&!m);let[v,y]=(0,Z.useState)(n),[b,x]=(0,Z.useState)(null),[C,w]=(0,Z.useState)(null),[E,D]=(0,Z.useState)(()=>new Set(n===`delete`&&l?[l.backend]:[])),[O,k]=(0,Z.useState)(!1),[A,j]=(0,Z.useState)(``),[M,P]=(0,Z.useState)(r),[F,ee]=(0,Z.useState)(`rename`);(0,Z.useEffect)(()=>{let t=!1;return Le(e).then(e=>{if(t)return;x(e.filter(e=>e.kind===`storage`));let n=new Set(e.filter(e=>e.kind===`storage`&&e.enabled!==!1&&e.config?.readOnly!==!0&&e.config?.supported!==!1).map(e=>e.address));D(e=>new Set([...e].filter(e=>n.has(e))))}).catch(e=>{t||w(e instanceof Error?e.message:String(e))}),()=>{t=!0}},[e]);let I=v===`move`,L=e=>e.enabled===!1?`disabled`:e.config?.readOnly===!0?`read-only`:e.config?.supported===!1?`unsupported`:null,te=(0,Z.useMemo)(()=>(b||[]).filter(e=>!L(e)).map(e=>e.address),[b,v]),ne=e=>{y(e),D(t=>{let n=(b||[]).filter(e=>e.enabled!==!1&&e.config?.readOnly!==!0&&e.config?.supported!==!1).map(e=>e.address),r=[...t].filter(e=>n.includes(e));return new Set(e===`move`?r.slice(0,1):r)})},R=e=>{D(t=>{if(I)return t.has(e)?new Set:new Set([e]);let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},z=(0,Z.useMemo)(()=>(b||[]).filter(e=>E.has(e.address)&&Fe(e)),[b,E]),B=v!==`delete`&&z.length>0,V=e=>{let t=Me(e,b||[]),n=t&&b?.find(e=>e.address===t.address);return!!n&&!L(n)&&v!==`delete`&&!o},re=async(t,n)=>{let r=Me(t,b||[]);if(!r||!V(t))throw Error(`Choose a writable file backend folder`);await Pe(e,r.driver,r.address,[[r.key,n].filter(Boolean).join(`/`)])},H=e=>{_(!1);let t=je(e[0]||``,b||[]),n=t?(b||[]).find(e=>e.address===t.address):null;if(!t||!n){p(`Pick a folder inside a storage backend`);return}if(L(n)){p(`${n.address} is ${L(n)}`);return}if(!Fe(n)){p(`${n.address} does not keep folders — objects are stored by content`);return}j(t.key),D(e=>I?new Set([t.address]):new Set([...e,t.address]))},ae=async()=>{E.size===0||o||await i([...E],v,{keepDocument:O,folder:B?A.trim():``,filename:B&&t===1?M.trim():``,onConflict:F})},oe=t,se=oe===1?``:`s`,U=v===`delete`?`Delete ${oe} document${se} from…`:`${v===`move`?`Move`:`Copy`} ${oe} document${se} to…`,W=v===`delete`?`Delete from`:v===`move`?`Move to`:`Copy to`,G=E.size===0?W.split(` `)[0]:`${W} ${E.size} backend${E.size===1?``:`s`}`;return(0,Q.jsxs)(`div`,{className:K(`flex flex-col overflow-hidden rounded-(--panel-radius) border bg-card shadow-elevation-4`,c||`max-h-viewport-card w-[min(420px,90vw)] max-md:h-full max-md:w-full max-md:shadow-elevation-5`),children:[(0,Q.jsxs)(`div`,{className:`flex h-12 shrink-0 items-center justify-between border-b px-4`,children:[(0,Q.jsxs)(`span`,{className:`flex items-center gap-2 text-sm font-medium`,children:[(0,Q.jsx)(s,{className:`h-4 w-4`}),U]}),(0,Q.jsx)(`button`,{type:`button`,onClick:a,disabled:o,className:`text-muted-foreground transition-colors hover:text-foreground disabled:opacity-40`,"aria-label":`Close`,children:(0,Q.jsx)(g,{className:`h-4 w-4`})})]}),(0,Q.jsx)(`div`,{className:`flex shrink-0 items-center gap-1 border-b px-2 pt-2`,children:zn.map(({mode:e,label:t,icon:n})=>(0,Q.jsxs)(`button`,{type:`button`,onClick:()=>ne(e),disabled:o,className:K(`flex items-center gap-1.5 rounded-t-md border-b-2 px-3 py-2 text-xs font-medium transition-colors disabled:opacity-50`,v===e?e===`delete`?`border-destructive text-destructive`:`border-primary text-foreground`:`border-transparent text-muted-foreground hover:text-foreground`),children:[n,t]},e))}),(0,Q.jsxs)(`div`,{className:`min-h-0 flex-1 space-y-1.5 overflow-y-auto p-3`,children:[C&&(0,Q.jsx)(`p`,{className:`px-2 py-1.5 text-xs text-destructive`,children:C}),!b&&!C&&(0,Q.jsx)(`div`,{className:`px-2 py-3 text-xs text-muted-foreground`,children:`Loading backends…`}),b?.length===0&&(0,Q.jsx)(`p`,{className:`px-2 py-1.5 text-xs text-muted-foreground`,children:`No storage backends configured.`}),b?.map(e=>{let t=Hn(e),n=L(e),r=E.has(e.address),i=e.config?.remote===!0;return(0,Q.jsxs)(`div`,{onClick:()=>!n&&!o&&R(e.address),className:K(`group relative flex min-h-10 items-center gap-2 rounded-md px-3 py-2 text-sm shadow-elevation-1 transition-all select-none`,`before:absolute before:left-0 before:top-0 before:bottom-0 before:w-1.5 before:transition-colors`,n?`cursor-not-allowed bg-muted/40 opacity-60 before:bg-transparent`:`cursor-pointer hover:shadow`,!n&&r?v===`delete`?`bg-destructive/[0.08] hover:bg-destructive/[0.12] before:bg-destructive`:`bg-primary/[0.08] hover:bg-primary/[0.12] before:bg-primary`:n?``:`bg-card hover:bg-primary/[0.04] before:bg-transparent`),title:e.address,children:[(0,Q.jsx)(`input`,{type:I?`radio`:`checkbox`,checked:r,disabled:!!n||o,onChange:()=>R(e.address),onClick:e=>e.stopPropagation(),className:`h-4 w-4 shrink-0 accent-primary`,"aria-label":e.address}),(0,Q.jsx)(t,{className:`h-4 w-4 shrink-0 text-muted-foreground`}),(0,Q.jsxs)(`span`,{className:`min-w-0 flex-1`,children:[(0,Q.jsx)(`span`,{className:`block truncate font-medium`,children:e.config?.label||e.address}),(0,Q.jsxs)(`span`,{className:`block truncate font-mono text-[10px] text-muted-foreground`,children:[e.driver,` · `,e.address]})]}),i&&(0,Q.jsx)(`span`,{className:`shrink-0 rounded bg-info-subtle px-1.5 py-0.5 text-[10px] uppercase text-muted-foreground`,title:`Network mount${e.config?.transport?` (${e.config.transport})`:``} — transfers cross the network`,children:e.config?.transport||`remote`}),n&&(0,Q.jsx)(`span`,{className:`shrink-0 rounded bg-muted px-1.5 py-0.5 text-[10px] uppercase text-muted-foreground`,children:n})]},`${e.driver}/${e.address}`)}),v===`delete`&&(0,Q.jsxs)(`label`,{className:`mt-3 flex cursor-pointer items-start gap-2 rounded-md border border-destructive/30 bg-destructive/5 px-3 py-2 text-xs`,children:[(0,Q.jsx)(`input`,{type:`checkbox`,checked:O,onChange:e=>k(e.target.checked),disabled:o,className:`mt-0.5 h-3.5 w-3.5 accent-destructive`}),(0,Q.jsxs)(`span`,{children:[`Keep the index entry when its `,(0,Q.jsx)(`strong`,{children:`last`}),` copy is deleted.`,(0,Q.jsx)(`span`,{className:`block text-muted-foreground`,children:`Otherwise the document moves to workspace Trash once no locations remain.`})]})]}),B&&(0,Q.jsxs)(`div`,{className:`mt-3 space-y-2 rounded-md border px-3 py-2`,children:[(0,Q.jsxs)(`p`,{className:`text-xs font-medium`,children:[`Destination on `,z.map(e=>e.config?.label||e.address).join(`, `)]}),(0,Q.jsxs)(`div`,{className:`space-y-1`,children:[(0,Q.jsx)(`label`,{htmlFor:`backend-transfer-folder`,className:`text-[11px] text-muted-foreground`,children:`Folder (relative to the backend root)`}),(0,Q.jsxs)(`div`,{className:`flex gap-1.5`,children:[(0,Q.jsx)(ce,{id:`backend-transfer-folder`,value:A,onChange:e=>j(e.target.value),placeholder:`/`,disabled:o,className:`h-9 font-mono text-xs`}),(0,Q.jsx)(q,{type:`button`,variant:`outline`,size:`icon`,className:`h-9 w-9 shrink-0`,onClick:()=>_(!0),disabled:o,"aria-label":`Browse backend folders`,title:`Browse…`,children:(0,Q.jsx)(ie,{className:`h-4 w-4`})})]})]}),t===1?(0,Q.jsxs)(`div`,{className:`space-y-1`,children:[(0,Q.jsx)(`label`,{htmlFor:`backend-transfer-filename`,className:`text-[11px] text-muted-foreground`,children:`File name`}),(0,Q.jsx)(ce,{id:`backend-transfer-filename`,value:M,onChange:e=>P(e.target.value),placeholder:r||`keeps the document's own name`,disabled:o,className:`h-9 font-mono text-xs`})]}):(0,Q.jsx)(`p`,{className:`text-[11px] text-muted-foreground`,children:`Each document keeps its own file name and extension.`}),(0,Q.jsxs)(`div`,{className:`space-y-1`,children:[(0,Q.jsx)(`label`,{htmlFor:`backend-transfer-conflict`,className:`text-[11px] text-muted-foreground`,children:`If a different file already has that name`}),(0,Q.jsx)(`select`,{id:`backend-transfer-conflict`,className:Vn,value:F,onChange:e=>ee(e.target.value),disabled:o,children:Bn.map(e=>(0,Q.jsx)(`option`,{value:e.value,children:e.label},e.value))})]})]}),v===`move`&&te.length>0&&(0,Q.jsx)(`p`,{className:`px-1 pt-2 text-[11px] text-muted-foreground`,children:`The source copy is released only once the destination write is durable.`})]}),o&&u&&(0,Q.jsxs)(`div`,{role:`status`,className:`flex items-center justify-between gap-2 border-t px-4 py-2 text-xs`,children:[(0,Q.jsxs)(`span`,{children:[d?`Stopping after current file`:`Processing`,` · `,u.completed,`/`,u.total]}),f&&(0,Q.jsx)(q,{size:`sm`,variant:`outline`,onClick:f,disabled:d,children:`Stop`})]}),(0,Q.jsxs)(`div`,{className:`flex shrink-0 items-center justify-between gap-2 border-t px-4 py-3`,children:[(0,Q.jsxs)(`span`,{className:`text-xs text-muted-foreground`,children:[E.size,` backend`,E.size===1?``:`s`,` selected`]}),(0,Q.jsx)(q,{size:`sm`,variant:v===`delete`?`destructive`:`default`,onClick:ae,disabled:E.size===0||o,children:o?(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(ue,{className:`mr-1.5 h-3.5 w-3.5`}),`Working…`]}):(0,Q.jsxs)(Q.Fragment,{children:[v===`delete`?(0,Q.jsx)(T,{className:`mr-1 h-3.5 w-3.5`}):v===`move`?(0,Q.jsx)(N,{className:`mr-1 h-3.5 w-3.5`}):(0,Q.jsx)(S,{className:`mr-1 h-3.5 w-3.5`}),G]})})]}),v===`delete`&&(0,Q.jsxs)(`div`,{className:`flex items-start gap-2 border-t bg-destructive/5 px-4 py-2 text-[11px] text-muted-foreground`,children:[(0,Q.jsx)(h,{className:`mt-0.5 h-3.5 w-3.5 shrink-0 text-destructive`}),(0,Q.jsx)(`span`,{children:l&&E.has(l.backend)?`Deletes selected files in ${l.backend}/${l.folder}. Copies in other folders are kept.${E.size>1?` Other selected backends are also targeted.`:` Copies on other backends are kept.`}`:`Deletes the file data from the selected backends. Copies on other backends are untouched.`})]}),m&&(0,Q.jsx)(xt,{onClose:()=>_(!1),children:(0,Q.jsx)(pe,{sizeClassName:`h-full w-[380px] max-w-[90vw] max-md:w-full`,multiple:!1,tabs:[`backends`],fixedWorkspaceName:e,title:`Pick a destination folder…`,confirmLabel:`Use folder`,backendFolderCreation:{canCreate:V,create:re},onConfirm:H,onClose:()=>_(!1)})})]})}var Wn={exif:`from the photo's EXIF`,device:`from the device at capture`,manual:`placed by hand`};function Gn(e){let t=`${e.lat.toFixed(5)}, ${e.lon.toFixed(5)}`,n=e.source?Wn[e.source]:null;return[t,e.accuracy==null?null:`±${e.accuracy} m`,n].filter(Boolean).join(` · `)}function Kn({value:e,onChange:t,idPrefix:n=`edit-geo`}){let[r,i]=(0,Z.useState)(!1);return(0,Q.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Q.jsx)(J,{htmlFor:`${n}-action`,children:`Location`}),(0,Q.jsxs)(`div`,{className:`flex items-center justify-between gap-3`,children:[(0,Q.jsxs)(`span`,{className:`flex min-w-0 items-center gap-2 text-xs`,children:[(0,Q.jsx)(se,{className:e?`h-4 w-4 shrink-0 text-info`:`h-4 w-4 shrink-0 text-muted-foreground`}),(0,Q.jsx)(`span`,{className:e?`truncate tabular-nums`:`truncate text-muted-foreground`,children:e?Gn(e):`No location on this document`})]}),(0,Q.jsxs)(`span`,{className:`flex shrink-0 items-center gap-1`,children:[(0,Q.jsxs)(`button`,{id:`${n}-action`,type:`button`,onClick:()=>i(!0),className:`inline-flex items-center gap-1.5 rounded-md border border-border px-2 py-1 text-xs text-muted-foreground transition-colors hover:bg-muted hover:text-foreground`,children:[(0,Q.jsx)(B,{className:`h-3.5 w-3.5`}),e?`Move pin`:`Set on map`]}),e&&(0,Q.jsx)(`button`,{type:`button`,onClick:()=>t(null),"aria-label":`Remove location`,title:`Remove location`,className:`rounded p-1 text-muted-foreground hover:bg-muted hover:text-foreground`,children:(0,Q.jsx)(T,{className:`h-3.5 w-3.5`})})]})]}),r&&(0,Q.jsx)(Ke,{initial:e,onPick:e=>t({lat:e.lat,lon:e.lon,source:`manual`}),onClose:()=>i(!1)})]})}function qn(e){return e===`data/schema/note`||e===`data/schema/link`||e===`data/schema/tab`||e===`data/schema/task`||e===`data/schema/drawing`||e===`data/schema/identity`||e.startsWith(`data/schema/identity/`)}function Jn(e){return qn(e.schema)||$e(e)}function Yn(e){return e===`data/schema/link`?{urlKey:`uri`,titleKey:`label`}:e===`data/schema/tab`?{urlKey:`url`,titleKey:`title`}:{urlKey:null,titleKey:`title`}}async function Xn(e,t,n){try{let r=new Set(n.map(e=>e.identityId).filter(Boolean)),i=await xe(e,t,{resolve:!1}),a=new Set(i.outgoing.filter(e=>e.p===`member-of`).map(e=>e.to));for(let n of r)a.has(n)||await Oe(e,t,`member-of`,[n]);for(let n of a)r.has(n)||await be(e,t,`member-of`,n)}catch(e){console.error(`Failed to sync organization relations`,e)}}function Zn({document:e,workspaceId:t,onClose:n}){let{showSuccessToast:r,showErrorToast:i}=X(),a=qn(e.schema),o=e.schema===`data/schema/file`,[s,c]=(0,Z.useState)(()=>Y(e)),l=!o||!!s.trim()&&!/[\\/]/.test(s)&&!Array.from(s).some(e=>e.charCodeAt(0)<32)&&s!==`.`&&s!==`..`,u=e.schema===Ce,d=$e(e),f=nt(e)??`markdown`,p=d&&Qe(e),m=e.schema===ze,h=e.schema===`data/schema/identity`||e.schema.startsWith(`data/schema/identity/`),{urlKey:g,titleKey:_}=Yn(e.schema),[v,y]=(0,Z.useState)(g?String(e.data?.[g]??``):``),[b,x]=(0,Z.useState)(String(e.data?.[_]??``)),[S,C]=(0,Z.useState)(String(e.data?.content??``)),[w,T]=(0,Z.useState)(String(e.data?.description??``)),[E,D]=(0,Z.useState)(e.data?.status??`pending`),[O,k]=(0,Z.useState)(typeof e.data?.priority==`number`?e.data.priority:``),[A,j]=(0,Z.useState)(e.data?.dueDate?mt(String(e.data.dueDate)):ft()),M=We(qe(e)),[N,P]=(0,Z.useState)(String(e.comment??``)),F=e.metadata?.geo??null,[ee,I]=(0,Z.useState)(F),L=e.features??e.metadata?.features,[te,ne]=(0,Z.useState)(ct(L).length?ct(L):e.data?.tags??[]),R=Ct(e,t,u),{title:z,content:B,comment:V,tags:re,geo:H,setTitle:ie,setContent:ae,setComment:oe,setTags:se,setGeo:U}=u?R:{title:b,content:S,comment:N,tags:te,geo:ee,setTitle:x,setContent:C,setComment:P,setTags:ne,setGeo:I},W=JSON.stringify(H??null)!==JSON.stringify(F??null),G=tt(t,e.id,{mode:`text`,enabled:d&&!p,maxTextLength:et,version:e.checksumArray?.[0]??null}),[K,le]=(0,Z.useState)(null),ue=`${e.id}:${e.checksumArray?.[0]??``}`;d&&G.text!=null&&K!==ue&&(le(ue),ae(G.text));let[de,fe]=(0,Z.useState)([]),[pe,me]=(0,Z.useState)(!1),{replicating:he,mirror:ge}=Re(e);(0,Z.useEffect)(()=>{let e=!1;return _e(t).then(t=>{e||fe(t)}).catch(()=>{}),()=>{e=!0}},[t]);let ye=!g||(()=>{try{return new URL(v.trim()),!0}catch{return!1}})(),be=!pe&&l&&(d?!p&&G.text!=null&&!G.loading:a?h?M.displayName.trim().length>0&&M.emailValid:m?z.trim().length>0:u?R.canSave:ye:!0),xe=async()=>{me(!0);let c=[...(L||[]).filter(e=>!e.startsWith(`tag/`)),...st(re)];try{if(u){await R.save(),n();return}if(d){let i=await it(t,e,B,{comment:V.trim(),metadata:{features:c,...o?{filename:s.trim()}:{},...W?{geo:H}:{}}});r(`Document updated`),window.dispatchEvent(new CustomEvent(`workspace:documents:refresh`)),n(i);return}let i={id:e.id,schema:e.schema,schemaVersion:e.schemaVersion,comment:V.trim(),metadata:{features:c,...o?{filename:s.trim()}:{}}};if(h){let{type:t,...n}=e.data??{};i.schema=`${ve}/${M.values.type}`,i.data={...n,...Ge(M.values)}}else if(m)i.data={...e.data,...dt({title:z,description:w,status:E,priority:O,due:A})};else if(a){let t=re.map(e=>e.trim()).filter(Boolean),n;u?n={...z.trim()?{title:z.trim()}:{},content:B}:(n={...e.data},g&&(n[g]=v.trim()),z.trim()?n[_]=z.trim():delete n[_],n.tags=t),i.data=n}W&&(i.metadata={...i.metadata??{},geo:H}),await ke(t,i),h&&(await Xn(t,e.id,M.values.organizations),lt()),r(`Document updated`),window.dispatchEvent(new CustomEvent(`workspace:documents:refresh`)),n()}catch(e){i(e instanceof Error?e.message:`Failed to update document`)}finally{me(!1)}};return(0,Q.jsxs)(`div`,{className:`flex flex-col gap-4`,children:[o&&(0,Q.jsxs)(`div`,{className:`space-y-2`,children:[(0,Q.jsx)(J,{htmlFor:`file-name`,children:`File name`}),(0,Q.jsx)(ce,{id:`file-name`,value:s,onChange:e=>c(e.target.value)}),(0,Q.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`Changes the object’s name; storage locations stay the same.`})]}),a&&g&&(0,Q.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Q.jsx)(J,{htmlFor:`edit-url`,children:`URL`}),(0,Q.jsx)(ce,{id:`edit-url`,value:v,onChange:e=>y(e.target.value),placeholder:`https://example.com`,className:`font-mono text-xs`}),v.trim()&&!ye&&(0,Q.jsx)(`p`,{className:`text-xs text-destructive`,children:`Enter a valid URL, e.g. https://example.com`})]}),a&&h&&(0,Q.jsx)(Ye,{idPrefix:`edit-identity`,workspaceName:t,...M,emailValid:M.emailValid}),a&&m&&(0,Q.jsx)(He,{idPrefix:`edit-todo`,title:z,setTitle:ie,description:w,setDescription:T,status:E,setStatus:D,priority:O,setPriority:k,due:A,setDue:j}),a&&!m&&!h&&(0,Q.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Q.jsx)(J,{htmlFor:`edit-title`,children:`Title`}),(0,Q.jsx)(ce,{id:`edit-title`,value:z,onChange:e=>ie(e.target.value),placeholder:u?`Optional; defaults to today's date`:`Optional display title`})]}),(u||d)&&(0,Q.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Q.jsx)(J,{children:`Body`}),p?(0,Q.jsxs)(`p`,{className:`text-xs text-muted-foreground`,children:[`This file is too large to edit here (`,`>`,1e3,` kB) — download it instead.`]}):d&&G.error?(0,Q.jsx)(`p`,{className:`text-xs text-destructive`,children:G.error}):d&&G.text==null?(0,Q.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`Loading content…`}):(0,Q.jsx)(wt,{kind:u?`markdown`:f,value:B,onChange:ae,placeholder:u?`Write your note…`:void 0})]}),(0,Q.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Q.jsx)(J,{children:`Tags`}),(0,Q.jsx)(Je,{tags:re,onChange:se,suggestions:de})]}),(0,Q.jsx)(Kn,{value:H,onChange:U}),(0,Q.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Q.jsx)(J,{htmlFor:`edit-comment`,children:`Comment`}),(0,Q.jsx)(`textarea`,{id:`edit-comment`,value:V,onChange:e=>oe(e.target.value),rows:3,placeholder:`Add context you can't infer from the content, e.g. “sofa from the cozmo bar in Košice”`,className:`flex w-full rounded-md border border-input bg-transparent px-3 py-2 text-sm shadow-elevation-1 transition-colors placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-50`})]}),u&&(0,Q.jsx)(St,{...R,onRetry:R.save}),(0,Q.jsxs)(`div`,{className:`flex justify-end gap-2 pt-2`,children:[(0,Q.jsx)(q,{variant:`outline`,size:`sm`,onClick:()=>n(),disabled:pe,children:u?`Close`:`Cancel`}),(0,Q.jsx)(q,{size:`sm`,onClick:xe,disabled:!be,children:pe?he?`Replicating to ${ge.label}…`:`Saving…`:`Save changes`})]})]})}var Qn=(0,Z.createContext)(null),$n={entry:null,open:()=>{},close:()=>{}};function er(){return(0,Z.useContext)(Qn)??$n}var tr=`main`,nr=(0,Z.createContext)(null);function rr(){return(0,Z.useContext)(nr)}var ir=50;function ar({relation:e,workspaceId:t,direction:n,onRemove:r,removing:i}){let{open:a}=Tt(),o=er(),s=rr(),c=n===`out`?e.to:e.from,l=e.document??null,u=l?ge(l).title:``,[d,f]=(0,Z.useState)(!1),{showErrorToast:p}=X(),m=async()=>{if(!(c==null||!l)){f(!0);try{let n=e.preview?await De(t,c):l;s?o.open(n,t):a(n,t)}catch(e){p(e instanceof Error?e.message:`Failed to open document`)}finally{f(!1)}}},h=!e.meta||e.meta.src===`doc`;return(0,Q.jsxs)(`div`,{className:`group flex items-center gap-2 rounded-md px-2 py-1.5 text-sm hover:bg-muted/60`,children:[n===`out`?(0,Q.jsx)(N,{className:`h-3.5 w-3.5 shrink-0 text-muted-foreground`}):(0,Q.jsx)(re,{className:`h-3.5 w-3.5 shrink-0 text-muted-foreground`}),l?(0,Q.jsx)(_t,{document:l,size:3.5}):null,l?(0,Q.jsx)(`button`,{type:`button`,onClick:()=>void m(),disabled:d,className:`min-w-0 flex-1 truncate text-left hover:underline`,title:u,children:u}):(0,Q.jsxs)(`span`,{className:`min-w-0 flex-1 truncate italic text-muted-foreground`,children:[`Document `,c,` (not available)`]}),(0,Q.jsxs)(`span`,{className:`shrink-0 font-mono text-[10px] text-muted-foreground`,children:[`#`,c]}),!h&&(0,Q.jsx)(`span`,{className:`shrink-0 rounded-full bg-muted px-1.5 py-0.5 text-[10px] text-muted-foreground`,title:`Derived by ${e.meta?.src}`,children:e.meta?.src}),h&&(0,Q.jsx)(`button`,{type:`button`,onClick:r,disabled:i,className:`shrink-0 rounded p-1 text-muted-foreground opacity-0 transition-opacity hover:bg-destructive/10 hover:text-destructive group-hover:opacity-100 disabled:opacity-40`,title:`Remove relation`,"aria-label":`Remove relation`,children:(0,Q.jsx)(T,{className:`h-3.5 w-3.5`})})]})}function or({document:e,workspaceId:t}){let{showSuccessToast:n,showErrorToast:r}=X(),[i,a]=(0,Z.useState)(null),[o,s]=(0,Z.useState)(null),[c,l]=(0,Z.useState)(!1),[u,d]=(0,Z.useState)(!1),[f,p]=(0,Z.useState)(null),[m,h]=(0,Z.useState)(0),[g,_]=(0,Z.useState)(1),v=(0,Z.useRef)(0),y=(0,Z.useCallback)(()=>{v.current++},[]),b=(0,Z.useCallback)(async()=>{let n=++v.current;try{let r=await xe(t,e.id,{offset:m*ir,limit:ir,summary:!0});if(n!==v.current)return;let i=Math.max(0,Math.ceil(Math.max(r.outgoingCount??r.outgoing.length,r.incomingCount??r.incoming.length)/ir)-1);if(_(i+1),m>i){h(i);return}a(r),s(null)}catch(e){if(n!==v.current)return;s(e instanceof Error?e.message:String(e))}},[t,e.id,m]),S=`${t}:${e.id}`,[C,w]=(0,Z.useState)(S);S!==C&&(w(S),a(null),s(null),h(0),_(1)),(0,Z.useEffect)(()=>{async function e(){await b()}return e(),window.addEventListener(ut,e),()=>{y(),window.removeEventListener(ut,e)}},[b,y]);let T=async(i,a)=>{let o=a===`out`?i.to:i.from;if(o==null)return;let s=`${a}:${i.p}:${o}`;p(s);try{await be(t,e.id,i.p,o,a),n(`Relation removed`),lt()}catch(e){r(e instanceof Error?e.message:`Failed to remove relation`)}finally{p(null)}},E=[{dir:`out`,title:`Points at`,hint:`this document as the subject`,entries:i?.outgoing??[]},{dir:`in`,title:`Pointed at by`,hint:`this document as the object`,entries:i?.incoming??[]}],D=e=>{a(null),h(e)};return(0,Q.jsxs)(`div`,{children:[(0,Q.jsxs)(`div`,{className:`mb-2 flex items-center justify-between gap-2`,children:[(0,Q.jsx)(`h3`,{className:`font-semibold`,children:`Documents`}),(0,Q.jsxs)(q,{variant:`outline`,size:`sm`,onClick:()=>l(!0),children:[(0,Q.jsx)(x,{className:`mr-1 h-3 w-3`}),` Add relation`]})]}),o?(0,Q.jsx)(`p`,{className:`text-sm text-destructive`,children:o}):i?E.every(e=>e.entries.length===0)?(0,Q.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`No related documents.`}):(0,Q.jsx)(`div`,{className:`space-y-4`,children:E.filter(e=>e.entries.length>0).map(({dir:e,title:n,hint:r,entries:i})=>(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`p`,{className:`mb-1 text-xs font-medium text-muted-foreground`,title:r,children:n}),Array.from(new Set(i.map(e=>e.p))).map(n=>(0,Q.jsxs)(`div`,{className:`mb-2`,children:[(0,Q.jsx)(`p`,{className:`px-2 font-mono text-[11px] text-muted-foreground`,children:n}),i.filter(e=>e.p===n).map(n=>{let r=e===`out`?n.to:n.from,i=`${e}:${n.p}:${r}`;return(0,Q.jsx)(ar,{relation:n,workspaceId:t,direction:e,removing:f===i,onRemove:()=>void T(n,e)},i)})]},n))]},e))}):(0,Q.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`Loading relations…`}),(g>1||m>0)&&(0,Q.jsxs)(`div`,{className:`mt-3 flex items-center justify-between gap-2 text-xs text-muted-foreground`,children:[(0,Q.jsx)(q,{variant:`outline`,size:`sm`,disabled:m===0,onClick:()=>D(m-1),children:`Previous`}),(0,Q.jsxs)(`span`,{children:[`Page `,m+1,` of `,g]}),(0,Q.jsx)(q,{variant:`outline`,size:`sm`,disabled:!i||m+1>=g,onClick:()=>D(m+1),children:`Next`})]}),c&&(0,Q.jsx)(xt,{onClose:()=>{u||l(!1)},children:(0,Q.jsx)(pe,{sizeClassName:`h-full w-[380px] max-w-[90vw] max-md:w-full`,title:`Relate to…`,tabs:[`relations`],fixedWorkspaceName:t,documentCount:1,saving:u,relationPredicates:i?.predicates,relationExcludeIds:new Set([e.id]),onClose:()=>l(!1),onConfirm:()=>{},onConfirmRelation:async({predicate:i,direction:a,targetIds:o})=>{d(!0);try{await Oe(t,e.id,i,o,a),n(`Related to ${o.length} document${o.length===1?``:`s`}`),l(!1),lt()}catch(e){r(e instanceof Error?e.message:`Failed to create relation`)}finally{d(!1)}}})})]})}var sr=(0,Z.lazy)(()=>a(()=>import(`./TextDocumentEditor-BQnVD0dd.js`),__vite__mapDeps([2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,1,24]))),cr={reply:`Reply`,replyAll:`Reply all`,forward:`Forward`},lr={reply:d,replyAll:u,forward:f};function ur({document:e,workspaceId:t,initialEdit:n=!1,onChanged:r}){let i=Xe()!=null,{showErrorToast:a,showSuccessToast:o}=X(),[s,l]=(0,Z.useState)(!1),u=e.data?.url||e.data?.uri,d=e.schema!==`data/schema/file`&&typeof u==`string`&&/^https?:\/\//i.test(u),[f,m]=(0,Z.useState)(!1),h=[`data/schema/message`,`data/schema/message/email`].includes(e.schema),[g,_]=(0,Z.useState)(null),v=e.schema===`data/schema/message/email`,y=!i&&(v||[`slack`,`whatsapp`].includes(String(e.data?.platform))),b=v?[`reply`,`replyAll`,`forward`]:[`reply`],x=e=>_(t=>t===e?null:e),S=!i,[C,w]=(0,Z.useState)(n&&!i),T=e.schema===Ae,[E,D]=(0,Z.useState)(!1),k=e.schema===`data/schema/note`||$e(e),[A,j]=(0,Z.useState)(!1),M=`${t}:${e.id}:${n}:${i}`,[N,P]=(0,Z.useState)(M);M!==N&&(P(M),w(n&&!i),_(null),m(!1),D(!1),j(!1));let F=t=>{if(!S||!Jn(e)||t.defaultPrevented)return!1;let n=t.target;return n instanceof Element&&t.currentTarget.contains(n)&&!n.closest(`a, button, input, textarea, select, label, summary, audio, video, [role="button"], [role="checkbox"], [contenteditable]:not([contenteditable="false"])`)};return C&&S?(0,Q.jsx)(Zn,{document:e,workspaceId:t,onClose:e=>{w(!1),r?.(e)}}):(0,Q.jsxs)(`div`,{className:`flex h-full min-h-0 flex-col gap-3`,children:[S&&(0,Q.jsxs)(`div`,{className:`flex shrink-0 justify-end gap-2`,children:[h&&(0,Q.jsx)(q,{size:`sm`,variant:f?`secondary`:`outline`,onClick:()=>m(!f),children:f?`Show message`:`View thread`}),y&&b.map(e=>{let t=lr[e];return(0,Q.jsxs)(q,{size:`sm`,variant:g===e?`secondary`:`outline`,onClick:()=>x(e),children:[(0,Q.jsx)(t,{className:`mr-1.5 h-3.5 w-3.5`}),cr[e]]},e)}),d&&(0,Q.jsxs)(q,{variant:`outline`,size:`sm`,disabled:s,onClick:async()=>{l(!0);try{await Te(t,e.id),window.dispatchEvent(new CustomEvent(`workspace:documents:refresh`)),r?.(),o(`File saved to workspace; the original link is preserved`)}catch(e){a(e instanceof Error?e.message:String(e))}finally{l(!1)}},children:[(0,Q.jsx)(U,{className:`mr-1 h-3 w-3`}),s?`Downloading…`:`Download to workspace`]}),e.schema===`data/schema/file`&&(0,Q.jsxs)(q,{variant:`outline`,size:`sm`,onClick:()=>we(t,e.id,Y(e)||`document-${e.id}`).catch(e=>a(e instanceof Error?e.message:String(e))),children:[(0,Q.jsx)(U,{className:`mr-1 h-3 w-3`}),` Download`]}),T&&(0,Q.jsxs)(q,{variant:`outline`,size:`sm`,onClick:()=>D(!0),children:[(0,Q.jsx)(O,{className:`mr-1 h-3 w-3`}),` Edit sketch`]}),k&&(0,Q.jsxs)(q,{variant:`outline`,size:`sm`,onClick:()=>j(!0),children:[(0,Q.jsx)(p,{className:`mr-1 h-3 w-3`}),` Open editor`]}),(0,Q.jsxs)(q,{variant:`outline`,size:`sm`,onClick:()=>w(!0),children:[(0,Q.jsx)(c,{className:`mr-1 h-3 w-3`}),` Edit`]})]}),E&&S&&(0,Q.jsx)(Z.Suspense,{fallback:(0,Q.jsx)(`div`,{className:`fixed inset-0 z-fullscreen flex items-center justify-center bg-background surface-glass`,children:(0,Q.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`Loading sketch editor…`})}),children:(0,Q.jsx)(Et,{doc:e,workspaceName:t,onSaved:()=>{D(!1),r?.()},onClose:()=>D(!1),onDetails:()=>{D(!1),w(!0)}})}),A&&S&&(0,Q.jsx)(Z.Suspense,{fallback:(0,Q.jsx)(`div`,{className:`fixed inset-0 z-fullscreen flex items-center justify-center bg-background surface-glass`,children:(0,Q.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`Loading editor…`})}),children:(0,Q.jsx)(sr,{doc:e,workspaceName:t,onSaved:e=>{j(!1),r?.(e)},onClose:()=>j(!1),onDetails:()=>{j(!1),w(!0)}})}),(0,Q.jsxs)(`div`,{className:`min-h-0 flex-1 overflow-auto`,onMouseDownCapture:e=>{e.button===0&&e.detail>1&&F(e)&&e.preventDefault()},onDoubleClickCapture:e=>{F(e)&&(e.preventDefault(),e.stopPropagation(),e.currentTarget.ownerDocument.getSelection()?.removeAllRanges(),w(!0))},children:[f&&!i?(0,Q.jsx)(In,{workspaceId:t,documentId:Number(e.id)},`${t}:${e.id}`):(0,Q.jsx)(Fn,{workspaceId:t,document:e}),g&&y&&(0,Q.jsx)(bt,{workspaceId:t,replyToDocumentId:Number(e.id),mode:g,originalSubject:v&&typeof e.data?.subject==`string`?e.data.subject:void 0,onClose:()=>_(null)},`${e.id}:${g}`)]}),e.comment?.trim()&&(0,Q.jsxs)(`div`,{className:`shrink-0 rounded-md border border-border bg-muted/40 px-3 py-2`,children:[(0,Q.jsx)(`p`,{className:`text-xs font-medium text-muted-foreground mb-0.5`,children:`Comment`}),(0,Q.jsx)(`p`,{className:`text-sm whitespace-pre-wrap`,children:e.comment})]})]})}var dr=e=>e?new Date(e).toLocaleDateString(`en-US`,{year:`numeric`,month:`long`,day:`numeric`,hour:`2-digit`,minute:`2-digit`,second:`2-digit`}):`—`,fr=e=>!Number.isFinite(e)||!e?null:e>=1?`${e}s`:`1/${Math.round(1/e)}s`;function pr({meta:e}){let{geo:t,exif:n,dimensions:r}=e;if(!t&&!n&&!r)return null;let i=(e,t)=>t==null||t===``?null:(0,Q.jsxs)(`div`,{children:[(0,Q.jsxs)(`span`,{className:`font-medium`,children:[e,`:`]}),(0,Q.jsx)(`span`,{className:`ml-2`,children:t})]});return(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`h3`,{className:`font-semibold mb-3`,children:`Photo`}),(0,Q.jsxs)(`div`,{className:`grid gap-3 text-sm`,children:[r&&i(`Dimensions`,r.width&&r.height?`${r.width} × ${r.height}`:null),n&&i(`Camera`,[n.make,n.model].filter(Boolean).join(` `)),n&&i(`Lens`,n.lensModel),n&&i(`Aperture`,Number.isFinite(n.fNumber)?`ƒ/${n.fNumber}`:null),n&&i(`Shutter`,fr(n.exposureTime)),n&&i(`ISO`,Number.isFinite(n.iso)?n.iso:null),n&&i(`Focal length`,Number.isFinite(n.focalLength)?`${n.focalLength} mm`:null),n&&i(`Captured`,dr(n.capturedAt)),t&&Number.isFinite(t.lat)&&Number.isFinite(t.lon)&&i(`Location`,(0,Q.jsxs)(`a`,{href:`https://www.openstreetmap.org/?mlat=${t.lat}&mlon=${t.lon}#map=15/${t.lat}/${t.lon}`,target:`_blank`,rel:`noopener noreferrer`,className:`text-primary underline underline-offset-2`,children:[t.lat.toFixed(5),`, `,t.lon.toFixed(5),Number.isFinite(t.alt)?` · ${Math.round(t.alt)} m`:``]}))]})]})}function mr({document:e}){let t=e.metadata;return(0,Q.jsxs)(`div`,{className:`space-y-6`,children:[(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`h3`,{className:`font-semibold mb-3`,children:`Basic Information`}),(0,Q.jsxs)(`div`,{className:`grid gap-3 text-sm`,children:[(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`span`,{className:`font-medium`,children:`ID:`}),(0,Q.jsx)(`span`,{className:`ml-2 font-mono`,children:e.id})]}),(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`span`,{className:`font-medium`,children:`Schema:`}),(0,Q.jsx)(`span`,{className:`ml-2 font-mono`,children:e.schema})]}),(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`span`,{className:`font-medium`,children:`Schema Version:`}),(0,Q.jsx)(`span`,{className:`ml-2`,children:e.schemaVersion})]}),(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`span`,{className:`font-medium`,children:`Created:`}),(0,Q.jsx)(`span`,{className:`ml-2`,children:dr(e.createdAt)})]}),(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`span`,{className:`font-medium`,children:`Updated:`}),(0,Q.jsx)(`span`,{className:`ml-2`,children:dr(e.updatedAt)})]})]})]}),(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`h3`,{className:`font-semibold mb-3`,children:`Metadata`}),(0,Q.jsxs)(`div`,{className:`grid gap-3 text-sm`,children:[(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`span`,{className:`font-medium`,children:`Content Type:`}),(0,Q.jsx)(`span`,{className:`ml-2`,children:e.metadata?.contentType??`—`})]}),(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`span`,{className:`font-medium`,children:`Content Encoding:`}),(0,Q.jsx)(`span`,{className:`ml-2`,children:e.metadata?.contentEncoding??`—`})]}),Number.isFinite(e.metadata?.size)&&(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`span`,{className:`font-medium`,children:`Size:`}),(0,Q.jsxs)(`span`,{className:`ml-2`,children:[e.metadata?.size,` bytes`]})]})]})]}),(0,Q.jsx)(pr,{meta:t}),Array.isArray(e.locations)&&e.locations.length>0&&(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`h3`,{className:`font-semibold mb-3`,children:`Locations`}),(0,Q.jsx)(`div`,{className:`space-y-2`,children:e.locations.map((e,t)=>{let{backend:n,key:r}=vr(e.url);return(0,Q.jsxs)(`div`,{className:`flex items-baseline gap-2 text-sm font-mono`,children:[(0,Q.jsx)(`span`,{className:`font-medium shrink-0`,children:n}),e.status&&e.status!==`available`&&(0,Q.jsx)(`span`,{className:`shrink-0 rounded border px-1 text-xs`,title:e.statusChangedAt,children:e.status===`deleted`?`Deleted`:`Not found`}),r&&(0,Q.jsx)(`span`,{className:`break-all text-muted-foreground`,children:r})]},t)})})]}),Array.isArray(e.checksumArray)&&e.checksumArray.length>0&&(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`h3`,{className:`font-semibold mb-3`,children:`Checksums`}),(0,Q.jsx)(`div`,{className:`space-y-2`,children:e.checksumArray.map((e,t)=>{let[n,r]=e.split(`/`);return(0,Q.jsxs)(`div`,{className:`flex items-center gap-2 text-sm font-mono`,children:[(0,Q.jsxs)(`span`,{className:`font-medium`,children:[n,`:`]}),(0,Q.jsx)(`span`,{className:`break-all text-muted-foreground`,children:r})]},t)})})]}),e.indexOptions&&(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`h3`,{className:`font-semibold mb-3`,children:`Index Options`}),(0,Q.jsxs)(`div`,{className:`space-y-3 text-sm`,children:[(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`span`,{className:`font-medium`,children:`FTS Search Fields:`}),(0,Q.jsx)(`div`,{className:`ml-2 mt-1`,children:(e.indexOptions.ftsSearchFields??[]).map((e,t)=>(0,Q.jsx)(`span`,{className:`mb-1 mr-2 inline-block rounded bg-muted px-2 py-1 text-xs`,children:e},t))})]}),(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`span`,{className:`font-medium`,children:`Vector Embedding Fields:`}),(0,Q.jsx)(`div`,{className:`ml-2 mt-1`,children:(e.indexOptions.vectorEmbeddingFields??[]).map((e,t)=>(0,Q.jsx)(`span`,{className:`mb-1 mr-2 inline-block rounded bg-muted px-2 py-1 text-xs`,children:e},t))})]})]})]})]})}function hr({document:e}){let{showSuccessToast:t,showErrorToast:n}=X(),r=JSON.stringify(e,null,2);return(0,Q.jsxs)(`div`,{className:`space-y-2`,children:[(0,Q.jsx)(`div`,{className:`flex justify-end`,children:(0,Q.jsxs)(q,{variant:`outline`,size:`sm`,onClick:async()=>{try{await navigator.clipboard.writeText(r),t(`Copied to clipboard`)}catch{n(`Copy failed`)}},children:[(0,Q.jsx)(S,{className:`mr-1 h-3 w-3`}),` Copy to clipboard`]})}),(0,Q.jsx)(`pre`,{className:`overflow-x-auto rounded-lg bg-muted p-4 text-xs`,children:r})]})}function gr({document:e,workspaceId:t}){let[n,r]=(0,Z.useState)(null),[i,a]=(0,Z.useState)(null),o=`${t}:${e.id}`,[s,c]=(0,Z.useState)(o);return o!==s&&(c(o),r(null),a(null)),(0,Z.useEffect)(()=>{let n=!1;return Ne(t,e.id).then(e=>{n||r(e)}).catch(e=>{n||a(e instanceof Error?e.message:String(e))}),()=>{n=!0}},[o]),i?(0,Q.jsx)(`p`,{className:`text-sm text-destructive`,children:i}):n?(0,Q.jsxs)(`div`,{className:`space-y-6`,children:[[{title:`Context tree`,type:`context`},{title:`Directory tree`,type:`directory`}].map(({title:e,type:t})=>{let r=n.filter(e=>e.type===t),i=r.flatMap(e=>e.paths.map(t=>({tree:e.tree,path:t})));return(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`h3`,{className:`mb-3 font-semibold`,children:e}),i.length===0?(0,Q.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`No placements.`}):(0,Q.jsx)(`div`,{className:`space-y-1`,children:i.map(({tree:e,path:t},n)=>(0,Q.jsxs)(`div`,{className:`flex items-center gap-2 text-sm`,children:[(0,Q.jsx)(`span`,{className:`break-all font-mono text-xs`,children:t}),r.length>1&&(0,Q.jsxs)(`span`,{className:`shrink-0 text-xs text-muted-foreground`,children:[`(`,e,`)`]})]},`${e}:${t}:${n}`))})]},t)}),(0,Q.jsx)(or,{document:e,workspaceId:t})]}):(0,Q.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`Loading memberships...`})}function _r(e){return e===`stored`?A:e===`workspace-file`?s:e===`imap`?j:e===`readonly`?C:L}function vr(e){let t=e.match(/^([a-z][a-z0-9+.-]*):\/\/([^/]*)\/?(.*)$/i);return t?{backend:`${t[1]}://${t[2]}`,key:t[3]}:{backend:e,key:``}}function yr({document:e,workspaceId:t,onChanged:n}){let{showSuccessToast:r,showErrorToast:i}=X(),[a,o]=(0,Z.useState)(null),[s,c]=(0,Z.useState)(null),[l,u]=(0,Z.useState)(null),[d,f]=(0,Z.useState)(null),[p,m]=(0,Z.useState)(null),[h,g]=(0,Z.useState)(!1),_=`${t}:${e.id}`,[v,y]=(0,Z.useState)(_);_!==v&&(y(_),o(null),c(null),f(null));let b=()=>{Se(t,e.id).then(o).catch(e=>c(e instanceof Error?e.message:String(e)))};(0,Z.useEffect)(()=>{let n=!1;return Se(t,e.id).then(e=>{n||o(e)}).catch(e=>{n||c(e instanceof Error?e.message:String(e))}),()=>{n=!0}},[_]);let x=async(a,o)=>{u(a),f(null);try{let i=await he(t,[e.id],{urls:[a],...o===void 0?{}:{keepDocument:o}}),s=i.successful[0];if(!s)throw Error(i.failed[0]?.reason||`Destroy failed`);s.docDeleted?r(`Removed from backend; document removed from index`):s.deleted.includes(a)?r(`Removed from backend`):r(`Reference dropped (backend is read-only)`),window.dispatchEvent(new CustomEvent(`workspace:documents:refresh`)),n?.(),b()}catch(e){i(e instanceof Error?e.message:String(e))}finally{u(null)}},C=async(a,o,s)=>{g(!0);try{let i=await Ie(t,[e.id],{to:a,mode:o,keepDocument:s.keepDocument,folder:s.folder,filename:s.filename,onConflict:s.onConflict}),c=i.successful[0];if(!c)throw Error(Ln(i.failed,new Map([[e.id,Y(e)||`Document ${e.id}`]]))||`Transfer failed`);let l=c.transfers?.flatMap(e=>e.state===`unchanged`?[]:[e.backend])??[],u=a.join(`, `);o===`delete`?r(`Deleted from ${u}`):l.length===0?r(`Nothing to do — already on ${u}`):r(`${o===`move`?`Moved to`:`Copied to`} ${l.join(`, `)}${c.transfers?.some(e=>e.state===`pending`)?` (pending sync)`:``}`),window.dispatchEvent(new CustomEvent(`workspace:documents:refresh`)),m(null),n?.(),b()}catch(e){i(e instanceof Error?e.message:String(e))}finally{g(!1)}},w=e=>{if((a?.length??0)<=1){f(e.url);return}window.confirm(`Remove this copy from the backend?\n\n${e.url}`)&&x(e.url)};if(s)return(0,Q.jsx)(`p`,{className:`text-sm text-destructive`,children:s});if(!a)return(0,Q.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`Loading locations...`});let E=a.length===0,D=Y(e);return(0,Q.jsxs)(`div`,{className:`space-y-3`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center justify-between gap-2 rounded border px-3 py-2 text-sm`,children:[(0,Q.jsxs)(`span`,{className:`inline-flex min-w-0 items-center gap-2`,children:[(0,Q.jsx)(A,{className:`h-4 w-4 shrink-0 text-muted-foreground`}),(0,Q.jsx)(`span`,{className:`font-mono text-xs`,children:`workspace:db`}),(0,Q.jsxs)(`span`,{className:`truncate text-xs text-muted-foreground`,children:[`index entry (id `,e.id,`)`]})]}),(0,Q.jsx)(`span`,{className:`shrink-0 rounded bg-muted px-1.5 py-0.5 text-[10px] uppercase text-muted-foreground`,children:`json`})]}),E?(0,Q.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`No byte locations; this object lives only in the workspace database, so there is no file data to copy or move.`}):(0,Q.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,Q.jsxs)(q,{variant:`outline`,size:`sm`,onClick:()=>m(`copy`),title:`Copy the file data to another storage backend (keeps the existing copies)`,children:[(0,Q.jsx)(S,{className:`mr-1 h-3.5 w-3.5`}),` Copy to…`]}),(0,Q.jsxs)(q,{variant:`outline`,size:`sm`,onClick:()=>m(`move`),title:`Move the file data to another storage backend (source released once the copy is durable)`,children:[(0,Q.jsx)(N,{className:`mr-1 h-3.5 w-3.5`}),` Move to…`]})]}),a.map(n=>{let r=_r(n.kind),{backend:a,key:o}=vr(n.url),s=l===n.url;return(0,Q.jsxs)(`div`,{className:`space-y-2 rounded border px-3 py-2 text-sm`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,Q.jsxs)(`span`,{className:`inline-flex min-w-0 items-center gap-2`,children:[(0,Q.jsx)(r,{className:`h-4 w-4 shrink-0 text-muted-foreground`}),(0,Q.jsx)(`span`,{className:`shrink-0 font-mono text-xs`,children:n.backend||a}),(0,Q.jsx)(`span`,{className:`truncate font-mono text-xs text-muted-foreground`,title:n.url,children:o||n.url})]}),(0,Q.jsxs)(`span`,{className:`flex shrink-0 items-center gap-2`,children:[(0,Q.jsx)(`span`,{className:`rounded px-1.5 py-0.5 text-[10px] uppercase ${n.deletable?`bg-muted text-muted-foreground`:`bg-warning/15 text-warning`}`,children:n.deletable?n.kind:`read-only`}),(0,Q.jsx)(`button`,{onClick:()=>we(t,e.id,D||`document-${e.id}`,{url:n.url}).catch(e=>i(e instanceof Error?e.message:String(e))),className:`text-muted-foreground hover:text-foreground`,title:`Download this copy`,children:(0,Q.jsx)(U,{className:`h-3.5 w-3.5`})}),(0,Q.jsx)(`button`,{onClick:()=>w(n),disabled:s,className:`text-muted-foreground hover:text-destructive disabled:opacity-50`,title:n.deletable?`Remove from backend`:`Drop reference (bytes stay; backend is read-only)`,children:(0,Q.jsx)(T,{className:`h-3.5 w-3.5`})})]})]}),d===n.url&&(0,Q.jsxs)(`div`,{className:`space-y-2 rounded border border-destructive/40 bg-destructive/5 p-2`,children:[(0,Q.jsxs)(`p`,{className:`text-xs`,children:[`This is the object's `,(0,Q.jsx)(`strong`,{children:`last`}),` location. Remove the bytes from the backend and…`]}),(0,Q.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[(0,Q.jsx)(q,{variant:`destructive`,size:`sm`,disabled:s,onClick:()=>void x(n.url,!1),children:`Also remove index entry`}),(0,Q.jsx)(q,{variant:`outline`,size:`sm`,disabled:s,onClick:()=>void x(n.url,!0),children:`Keep index entry (no bytes)`}),(0,Q.jsx)(q,{variant:`ghost`,size:`sm`,onClick:()=>f(null),children:`Cancel`})]})]})]},n.url)}),p&&(0,Rn.createPortal)((0,Q.jsx)(`div`,{className:`fixed inset-0 z-picker flex items-center justify-center bg-scrim p-4 max-md:p-2`,children:(0,Q.jsx)(Un,{workspaceId:t,documentCount:1,initialMode:p,defaultFilename:D,saving:h,onConfirm:C,onClose:()=>{h||m(null)}})}),window.document.body)]})}var br=(0,Z.lazy)(()=>a(()=>import(`./LocationTab-DAtqAQ3l.js`),__vite__mapDeps([25,3,4,26,27]))),xr=[{id:`view`,label:`View`,icon:F},{id:`location`,label:`Location`,icon:se},{id:`metadata`,label:`Metadata`,icon:I},{id:`json`,label:`JSON`,icon:o},{id:`synapses`,label:`Synapses`,icon:ne},{id:`backends`,label:`Backends`,icon:A}];function Sr({document:e,workspaceId:t,initialTab:n=`view`,initialEdit:r=!1,onChanged:i,className:a=``,compact:o=!1,navigation:s,tabActions:c,onTabChange:l}){let u=Xe()!=null,d=Dt(e),f=xr.filter(e=>(e.id!==`location`||d!==null)&&(!u||![`synapses`,`backends`].includes(e.id))),[p,m]=(0,Z.useState)(n),h=`${e.id}:${n}`,[g,_]=(0,Z.useState)(h);h!==g&&(_(h),m(n));let v=f.some(e=>e.id===p)?p:`view`,y=e=>{m(e),l?.(e)},b=o&&!!c&&!s,x=(0,Q.jsx)(`div`,{className:K(b&&`document-detail-header shrink-0 border-b-[3px] bg-muted`),children:(0,Q.jsxs)(`div`,{className:K(`flex min-w-0 items-center`,b&&`mx-auto h-[calc(3rem-4px)] w-full max-w-[var(--document-reading-width,100%)] gap-1 pl-2 pr-2 sm:pl-4`),children:[(0,Q.jsx)(yt,{tabs:f,active:v,onChange:y,className:K(`min-w-0 flex-1 px-1`,b&&`h-full border-b-0 px-0 max-sm:gap-0 max-sm:[&>button]:px-2.5`),iconOnly:o}),c]})});return(0,Q.jsxs)(`div`,{className:`flex h-full min-h-0 flex-col ${a}`,children:[s?(0,Q.jsx)(Pn,{...s,tabs:x,section:v,onDocument:()=>y(`view`),onSection:()=>y(`view`),onBack:v===`view`?s.onBack:()=>y(`view`)}):x,(0,Q.jsx)(`div`,{className:`min-h-0 flex-1 overflow-y-auto`,children:(0,Q.jsxs)(`div`,{className:`mx-auto h-full w-full max-w-[var(--document-reading-width,100%)] p-4`,children:[v===`view`&&(0,Q.jsx)(ur,{document:e,workspaceId:t,initialEdit:r&&!u,onChanged:i}),v===`location`&&d&&(0,Q.jsx)(Z.Suspense,{fallback:(0,Q.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`Loading map…`}),children:(0,Q.jsx)(br,{lat:d.lat,lon:d.lon})}),v===`metadata`&&(0,Q.jsx)(mr,{document:e,workspaceId:t}),v===`json`&&(0,Q.jsx)(hr,{document:e,workspaceId:t}),v===`synapses`&&!u&&(0,Q.jsx)(gr,{document:e,workspaceId:t}),v===`backends`&&!u&&(0,Q.jsx)(yr,{document:e,workspaceId:t,onChanged:i})]})})]})}export{nn as _,Qn as a,kt as b,Un as c,Nn as d,An as f,sn as g,an as h,rr as i,Ln as l,on as m,nr as n,er as o,rn as p,tr as r,Kn as s,Sr as t,Pn as u,Gt as v,It as y};
@@ -1 +0,0 @@
1
- import{o as e}from"./rolldown-runtime-C0FnF6B9.js";import{l as t,u as n}from"./code-editor-BOIngd5F.js";import{yt as r}from"./react-BHzhHVTZ.js";import{g as i}from"./chunk-62JRHF6Z-vspAGgtK.js";import{L as a,Qt as o,Vr as s,an as c,cr as l,vn as u,wt as d}from"./ui-CDoK3F3U.js";import{t as f}from"./utils-2pl1SbIp.js";import{t as p}from"./button-SeUZ_Pvi.js";import{_ as m,a as h,i as g,n as _,r as v,t as y}from"./LinkToCard-CKVi4Nrg.js";import{Lt as b,g as x,jt as S,yn as C}from"./workspace-C5V-ZCOE.js";import{t as w}from"./use-mobile-Db-vWu9Y.js";import{c as T}from"./IdentityFields-D-NCTUaE.js";import{n as E}from"./relation-events-CKio19hE.js";import{t as D}from"./useEscapeClose-DR_xKT_k.js";import{t as O}from"./useToastHelpers-CRrpIIdY.js";var k=e(n(),1);function A(e){let t=`/workspaces/${encodeURIComponent(e.workspaceName)}`,n=e.path.replace(/^\/+/,``).split(`/`).map(encodeURIComponent).join(`/`);return e.treeName===`context`?`${t}/path/${n}`:`${t}/trees/${encodeURIComponent(e.treeName)}/path/${n}`}var j=e(r(),1),M=t();function N({title:e,icon:t,onClose:n,onSave:r,navigateAfterSave:s=!1,canSave:l=!1,saving:m=!1,saveProgress:h,successMessage:g=`Saved`,lockedWorkspaceName:_,fillParent:v=!1,fullWidthContent:S=!1,relationSubjectId:C,frame:N,children:P,maximized:ee,onMaximizedChange:F}){let te=i(),[ne,re]=(0,k.useState)(`portrait`),[ie,ae]=(0,k.useState)(!1),I=ee??ie,L=e=>{ae(e),F?.(e)},[R,z]=(0,k.useState)(!1),[oe,B]=(0,k.useState)(!1),[se,V]=(0,k.useState)(!1),H=m||se;D(()=>z(!1),R&&!H),D(()=>L(!1),I&&!R);let U=(0,k.useRef)(null),W=w(),{showSuccessToast:G,showErrorToast:K}=O(),q=W&&!v&&!I,[ce,le]=(0,k.useState)(!1),J=!v&&!I&&!N&&!ce;(0,k.useEffect)(()=>{R&&U.current?.scrollIntoView({behavior:`smooth`,inline:`end`,block:`nearest`})},[R]);let ue=async(e,t)=>{if(!(!r||H)){V(!0);try{let i=await r({...t,path:e[0]}),a=e.slice(1);i.length&&a.length&&await Promise.all(a.map(e=>b(t.workspaceName,e,i,t.treeName,t.treeType))),G(g),n?.(),s&&te(A({...t,path:e[0]}),{replace:!0})}catch(e){K(e instanceof Error?e.message:`Failed to save`)}finally{V(!1)}}},Y=async e=>{if(!(!C||!_||e.targetIds.length===0)){B(!0);try{await x(_,C,e.predicate,e.targetIds,e.direction),G(`Created ${e.targetIds.length} relation${e.targetIds.length===1?``:`s`}`),E(),z(!1)}catch(e){K(e instanceof Error?e.message:`Failed to create relations`)}finally{B(!1)}}},de=I?R?{flex:`1 1 auto`,minWidth:0,height:`100%`}:{width:`100%`,height:`100%`}:v?{height:`100%`,flexShrink:0}:q?void 0:ne===`portrait`?{aspectRatio:`0.707 / 1`,height:`calc(var(--viewport-h) * 0.85)`,width:`auto`,maxWidth:`min(90vw, 100%)`,flexShrink:0}:{aspectRatio:`1 / 0.707`,width:`min(90vw, 900px)`,maxWidth:`100%`,height:`auto`,maxHeight:`calc(var(--viewport-h) * 0.85)`,flexShrink:0},X=!!(C&&_),Z=r&&R&&(0,M.jsx)(y,{onClose:()=>z(!1),onConfirm:ue,fixedWorkspaceName:_,saving:H||oe,savingContent:h,tabs:X?[`context`,`directory`,`relations`]:[`context`,`directory`],onConfirmRelation:X?Y:void 0,relationWorkspaceName:_,relationExcludeIds:X?new Set([C]):void 0,sizeClassName:N?`h-full max-h-full w-full min-w-0 rounded-none border-0 shadow-none`:v?`h-full max-h-full w-[min(380px,90vw)] max-md:h-full max-md:w-full max-md:shadow-elevation-5`:void 0}),Q=(0,M.jsxs)(`div`,{className:`flex shrink-0 items-center gap-1`,children:[!v&&(0,M.jsx)(`button`,{type:`button`,onClick:()=>re(e=>e===`portrait`?`landscape`:`portrait`),className:`rounded p-1.5 text-muted-foreground transition-colors hover:bg-muted hover:text-foreground max-md:hidden touch-target`,"aria-label":`Toggle orientation`,title:`Toggle orientation`,children:(0,M.jsx)(d,{className:`h-4 w-4`})}),r&&(typeof P==`function`?(0,M.jsx)(`button`,{type:`button`,onClick:()=>z(!0),disabled:!l||H,className:`flex h-8 w-8 items-center justify-center rounded text-muted-foreground transition-colors hover:bg-muted hover:text-foreground disabled:opacity-40 touch-target`,"aria-label":H?`Saving…`:`Add relations / Link to…`,title:`Add relations / Link to…`,children:(0,M.jsx)(u,{className:`h-4 w-4`})}):(0,M.jsx)(p,{size:`sm`,variant:`outline`,onClick:()=>z(!0),disabled:!l||H,children:H?`Saving…`:`Save / Link to…`})),(0,M.jsx)(`button`,{type:`button`,onClick:()=>N&&!I?N.onToggleExpanded():L(!I),className:f(`rounded p-1.5 text-muted-foreground transition-colors hover:bg-muted hover:text-foreground`,typeof P==`function`&&`flex h-8 w-8 items-center justify-center`,!I&&!N&&`max-md:hidden`),"aria-label":N&&!I?N.expanded?`Card size`:`Expand to full width`:I?`Restore`:`Maximize`,title:N&&!I?N.expanded?`Card size`:`Expand to full width`:I?`Restore`:`Maximize`,children:I||N?.expanded?(0,M.jsx)(o,{className:`h-4 w-4`}):(0,M.jsx)(c,{className:`h-4 w-4`})}),n&&(0,M.jsx)(`button`,{type:`button`,onClick:n,disabled:H,className:f(`rounded p-1.5 text-muted-foreground transition-colors hover:bg-muted hover:text-foreground disabled:opacity-40 touch-target`,typeof P==`function`&&`flex h-8 w-8 items-center justify-center`),"aria-label":`Close`,children:(0,M.jsx)(a,{className:`h-4 w-4`})})]}),$=(0,M.jsxs)(`div`,{style:{...N&&!I?{width:`100%`,height:`100%`,minWidth:0}:de,"--document-reading-width":I&&!S?`48rem`:`100%`},onAnimationEnd:e=>{J&&e.target===e.currentTarget&&le(!0)},className:f(`flex flex-col overflow-hidden`,N&&!I?`strip-document-card`:`rounded-(--card-radius) border bg-card shadow-elevation-4 transition-[width,height]`,v&&!I&&!N&&`w-full`,q&&`fixed inset-2 z-40 shadow-elevation-5`,J&&`animate-card-in`),children:[typeof P!=`function`&&(0,M.jsxs)(`div`,{className:`flex h-12 shrink-0 items-center justify-between gap-2 border-b px-4`,children:[(0,M.jsxs)(`span`,{className:`flex min-w-0 items-center gap-2 truncate text-sm font-medium`,children:[(0,M.jsx)(t,{className:`h-4 w-4 shrink-0`}),(0,M.jsx)(`span`,{className:`truncate`,children:e})]}),Q]}),(0,M.jsx)(T.Provider,{value:()=>L(!I),children:(0,M.jsx)(`div`,{className:f(`min-h-0 flex-1 overflow-y-auto`,I&&!S&&typeof P!=`function`&&`mx-auto w-full max-w-3xl`),children:N&&Z?Z:typeof P==`function`?P(Q):P})})]});return I?(0,j.createPortal)((0,M.jsxs)(`div`,{className:`fixed inset-0 z-picker flex items-center justify-center gap-4 bg-scrim p-4 max-md:p-2`,children:[$,Z&&(0,M.jsx)(`div`,{className:`flex max-md:absolute max-md:inset-2 max-md:z-10`,children:Z})]}),document.body):(0,M.jsxs)(M.Fragment,{children:[$,!N&&Z&&(0,M.jsxs)(M.Fragment,{children:[(0,M.jsx)(`div`,{className:`fixed inset-0 z-card bg-scrim animate-fade-in md:hidden`,onClick:()=>!H&&z(!1),"aria-hidden":!0}),(0,M.jsx)(`div`,{ref:U,className:`relative shrink-0 md:z-panel md:ml-2 md:pr-2 max-md:fixed max-md:bottom-2 max-md:left-2 max-md:right-2 max-md:top-2 max-md:z-card-overlay max-md:animate-fade-in`,children:Z})]})]})}function P({onClose:e,onConfirm:t,fixedWorkspaceName:n,saving:r=!1,sizeClassName:i}){let[o,c]=(0,k.useState)(n?`browse`:`workspace`),[u,d]=(0,k.useState)([]),[y,b]=(0,k.useState)(!n),[x,w]=(0,k.useState)(n??null),[T,E]=(0,k.useState)(`context`),[D,O]=(0,k.useState)(new Set),[A,j]=(0,k.useState)(n);return n!==A&&(j(n),n||b(!0)),(0,k.useEffect)(()=>{n||S().then(d).catch(()=>d([])).finally(()=>b(!1))},[n]),(0,M.jsxs)(`div`,{className:f(`flex flex-col overflow-hidden rounded-(--panel-radius) border bg-card shadow-elevation-4`,i||`h-viewport-card max-h-full w-[min(420px,90vw)] max-md:h-full max-md:w-full max-md:shadow-elevation-5`),children:[(0,M.jsxs)(`div`,{className:`flex h-12 shrink-0 items-center justify-between border-b px-4`,children:[(0,M.jsxs)(`span`,{className:`flex items-center gap-2 text-sm font-medium`,children:[(0,M.jsx)(l,{className:`h-4 w-4`}),o===`workspace`?`Add existing documents…`:`Pick documents…`]}),(0,M.jsx)(`button`,{type:`button`,onClick:e,disabled:r,className:`text-muted-foreground transition-colors hover:text-foreground disabled:opacity-40`,"aria-label":`Close`,children:(0,M.jsx)(a,{className:`h-4 w-4`})})]}),(0,M.jsx)(`div`,{className:`flex-1 overflow-hidden`,children:(0,M.jsxs)(`div`,{className:`grid h-full w-[200%] grid-cols-2 transition-transform duration-normal`,style:{transform:o===`workspace`?`translateX(0)`:`translateX(-50%)`},children:[(0,M.jsx)(`div`,{className:`flex min-w-0 flex-col overflow-y-auto p-2`,children:(0,M.jsx)(v,{workspaces:u,loading:y,onPick:e=>{w(e),O(new Set),c(`browse`)}})}),(0,M.jsxs)(`div`,{className:`flex min-w-0 flex-col overflow-hidden`,children:[(0,M.jsxs)(`div`,{className:`flex shrink-0 items-center gap-1 border-b px-2 pt-2`,children:[!n&&(0,M.jsx)(`button`,{type:`button`,onClick:()=>c(`workspace`),className:`mr-1 rounded p-1.5 text-muted-foreground hover:bg-muted hover:text-foreground touch-target`,"aria-label":`Back to workspaces`,children:(0,M.jsx)(s,{className:`h-4 w-4 rotate-180`})}),[`context`,`directory`].map(e=>(0,M.jsxs)(`button`,{type:`button`,onClick:()=>{E(e),O(new Set)},className:f(`flex items-center gap-1.5 rounded-t-md border-b-2 px-3 py-2 text-xs font-medium transition-colors`,T===e?`border-primary text-foreground`:`border-transparent text-muted-foreground hover:text-foreground`),children:[g[e],h[e]]},e))]}),x&&(0,M.jsx)(_,{workspaceName:x,treeTab:T,onTreeTabChange:E,selectedDocIds:D,onToggleDoc:e=>{O(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},onNavigate:()=>O(new Set)})]})]})}),o===`browse`&&(0,M.jsxs)(`div`,{className:`flex shrink-0 items-center justify-between border-t px-4 py-3`,children:[(0,M.jsxs)(`span`,{className:`text-xs text-muted-foreground`,children:[D.size,` document`,D.size===1?``:`s`,` selected`]}),(0,M.jsx)(p,{size:`sm`,onClick:async()=>{!x||D.size===0||r||await t(Array.from(D),{workspaceName:x,treeName:T===`directory`?`directory`:C,treeType:T})},disabled:D.size===0||r,children:r?(0,M.jsxs)(M.Fragment,{children:[(0,M.jsx)(m,{className:`mr-1.5 h-3.5 w-3.5`}),`Adding…`]}):(0,M.jsxs)(M.Fragment,{children:[(0,M.jsx)(l,{className:`mr-1 h-3.5 w-3.5`}),`Add`]})})]})]})}export{N as n,P as t};
@@ -1 +0,0 @@
1
- import{o as e}from"./rolldown-runtime-C0FnF6B9.js";import{l as t,u as n}from"./code-editor-BOIngd5F.js";import{L as r,Lr as i,Wr as a,ar as o,on as s,pn as c,sn as l}from"./ui-CDoK3F3U.js";import{t as u}from"./utils-2pl1SbIp.js";import{t as d}from"./button-SeUZ_Pvi.js";import{t as f}from"./label-BSTdjCWU.js";import{Dt as p}from"./workspace-C5V-ZCOE.js";import{o as m,s as h}from"./IdentityFields-D-NCTUaE.js";import{n as g}from"./tags-YamdPoBK.js";import{a as _,i as v,l as y,o as b,r as x}from"./useAddTarget-DeRZWtGg.js";import{r as S}from"./relation-events-CKio19hE.js";import{a as C,n as w,r as T}from"./blobs-WiXP9QRi.js";import{t as E}from"./sha256-65KIjGvZ.js";var D=e(n(),1);function O(e){let[t,n]=(0,D.useState)(null);return(0,D.useEffect)(()=>{if(!e)return;let t=!1;return p(e).then(r=>{t||n({workspace:e,tags:r})}).catch(()=>{}),()=>{t=!0}},[e]),t&&t.workspace===e?t.tags:[]}var k=t();function A(e){if(e.manual){let t=`${e.manual.lat.toFixed(5)}, ${e.manual.lon.toFixed(5)}`;return e.manualLabel?`${e.manualLabel} · ${t}`:`Custom pin · ${t}`}if(!e.supported)return`Needs a secure (https) connection, or pick a point on the map`;if(e.permission===`denied`)return`Blocked. Allow location for this site, or pick a point on the map`;if(e.error)return e.error;if(e.busy)return`Getting your location…`;if(e.enabled&&e.fix){let{lat:t,lon:n,accuracy:r}=e.fix;return`${t.toFixed(5)}, ${n.toFixed(5)}${r==null?``:` · ±${r} m`}`}return e.enabled?`Location will be attached when you save`:`Attach where you are, or pick any point on the map`}function j({geotag:e,idPrefix:t=`geotag`}){let[n,i]=(0,D.useState)(!1),a=!e.supported||e.permission===`denied`,o=!e.manual&&(!e.supported||e.permission===`denied`||!!e.error);return(0,k.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,k.jsxs)(`div`,{className:`flex items-center justify-between gap-3`,children:[(0,k.jsxs)(`div`,{role:`switch`,"aria-checked":e.enabled,"aria-disabled":a,"aria-label":`Geotag this document`,"aria-describedby":`${t}-hint`,tabIndex:a?-1:0,onClick:()=>!a&&e.setEnabled(!e.enabled),onKeyDown:t=>{a||(t.key===` `||t.key===`Enter`)&&(t.preventDefault(),e.setEnabled(!e.enabled))},className:u(`flex flex-1 items-center justify-between gap-3 select-none outline-none rounded focus-visible:ring-2 focus-visible:ring-ring`,a?`cursor-not-allowed opacity-50`:`cursor-pointer`),children:[(0,k.jsxs)(`span`,{className:`flex items-center gap-2 text-sm text-foreground`,children:[e.busy?(0,k.jsx)(c,{className:`h-4 w-4 shrink-0 animate-spin text-muted-foreground`}):(0,k.jsx)(l,{className:u(`h-4 w-4 shrink-0`,e.enabled?`text-info`:`text-muted-foreground`)}),`Geotag`]}),(0,k.jsx)(`div`,{className:u(`relative h-5 w-10 shrink-0 rounded-full transition-colors`,e.enabled?`bg-info`:`bg-muted-foreground/30`),children:(0,k.jsx)(`div`,{className:u(`absolute top-[2px] h-4 w-4 rounded-full bg-background shadow-elevation-1 transition-transform`,e.enabled?`translate-x-[22px]`:`translate-x-[2px]`)})})]}),(0,k.jsxs)(`span`,{className:`flex shrink-0 items-center gap-1`,children:[(0,k.jsxs)(`button`,{type:`button`,onClick:()=>i(!0),title:`Pick a point on the map`,className:`inline-flex items-center gap-1.5 rounded-md border border-border px-2 py-1 text-xs text-muted-foreground transition-colors hover:bg-muted hover:text-foreground`,children:[(0,k.jsx)(s,{className:`h-3.5 w-3.5`}),e.manual?`Change pin`:`Pick on map`]}),e.manual&&(0,k.jsx)(`button`,{type:`button`,onClick:()=>e.setManual(null),"aria-label":`Remove custom pin`,title:`Remove custom pin`,className:`rounded p-1 text-muted-foreground hover:bg-muted hover:text-foreground`,children:(0,k.jsx)(r,{className:`h-3.5 w-3.5`})})]})]}),(0,k.jsx)(`p`,{id:`${t}-hint`,className:u(`text-xs`,o?`text-warning`:`text-muted-foreground`),children:A(e)}),n&&(0,k.jsx)(m,{initial:e.manual??e.fix??null,onPick:t=>e.setManual(t),onClose:()=>i(!1)})]})}var M=`data/schema/file`,N=`3.0`;function P(e){let[t,n]=(0,D.useState)([]),[r,i]=(0,D.useState)(``);return{tags:t,setTags:n,comment:r,setComment:i,suggestions:O(e),geotag:S()}}function F(e,t,n={}){let r=g(n.tags??[]),i=n.comment?.trim();return{schema:M,schemaVersion:N,data:{},checksumArray:[`sha256/${e.checksum}`],locations:[{url:e.url,metadata:{filename:t.name}}],...i?{comment:i}:{},metadata:{contentType:t.type,size:e.size,...r.length?{features:r}:{},...n.geo?{geo:n.geo}:{}}}}var I=`flex w-full rounded-md border border-input bg-transparent px-3 py-2 text-sm shadow-elevation-1 transition-colors placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring`;function L({fields:e,idPrefix:t=`file`,multiple:n=!1}){return(0,k.jsxs)(k.Fragment,{children:[(0,k.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,k.jsx)(f,{children:`Tags`}),(0,k.jsx)(h,{tags:e.tags,onChange:e.setTags,suggestions:e.suggestions})]}),(0,k.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,k.jsx)(f,{htmlFor:`${t}-comment`,children:`Comment`}),(0,k.jsx)(`textarea`,{id:`${t}-comment`,value:e.comment,onChange:t=>e.setComment(t.target.value),rows:3,placeholder:`Optional; searchable, and the only text a photo has`,className:I}),n&&e.tags.length+e.comment.trim().length>0&&(0,k.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`Applied to every file in this upload`})]}),(0,k.jsx)(j,{geotag:e.geotag,idPrefix:`${t}-geotag`})]})}var R=3;function z(e){return`${e.name}:${e.size}:${e.lastModified}`}function B(e=[]){let[t,n]=(0,D.useState)(()=>e.map(e=>({id:z(e),file:e,status:`queued`,progress:0}))),[r,i]=(0,D.useState)(!1),a=(0,D.useRef)(t),o=(0,D.useRef)(null),s=(0,D.useRef)(null);(0,D.useEffect)(()=>()=>s.current?.abort(),[]);let c=(0,D.useCallback)(e=>{a.current=e,n(e)},[]),l=(0,D.useCallback)((e,t)=>{let r=a.current.map(n=>n.id===e?{...n,...t}:n);a.current=r,n(r)},[]),u=(0,D.useCallback)(e=>{let t=new Set(a.current.map(e=>e.id)),n=e.filter(e=>!t.has(z(e))).map(e=>({id:z(e),file:e,status:`queued`,progress:0}));n.length&&c([...a.current,...n])},[c]),d=(0,D.useCallback)(e=>{c(a.current.filter(t=>t.id!==e))},[c]),f=(0,D.useCallback)(()=>{s.current?.abort(),s.current=null,c([]),i(!1)},[c]),p=(0,D.useCallback)(()=>{s.current?.abort()},[]);return{items:t,running:r,addFiles:u,removeItem:d,reset:f,start:(0,D.useCallback)(async(e,t)=>{if(!e)throw Error(`No active workspace or context to add to`);let{workspaceName:n,treeName:r,path:u}=await _(e),d=r===`backends`?await v(n,u):null,f=JSON.stringify([n,r,u]);o.current!==null&&o.current!==f&&c(a.current.map(({id:e,file:t})=>({id:e,file:t,status:`queued`,progress:0}))),o.current=f;let p=new AbortController;s.current=p,i(!0);let m=a.current.filter(e=>e.status!==`done`);for(let e of m)l(e.id,{status:`queued`,progress:0,error:void 0});try{if(d){let e=0;await Promise.all(Array.from({length:Math.min(R,m.length)},async()=>{for(;e<m.length&&!p.signal.aborted;){let t=m[e++];try{l(t.id,{status:`uploading`,progress:0,resumed:!1});let e=await T(n,{...d,key:y(d.key,t.file.name)},t.file,{signal:p.signal,onProgress:(e,n)=>l(t.id,{progress:n?e/n:0})});l(t.id,{status:`done`,progress:1,docId:e.docId??void 0})}catch(e){l(t.id,{status:`error`,error:e instanceof Error?e.message:`Upload failed`})}}}))}else{let r=new Map;for(let e of m){if(p.signal.aborted)throw new DOMException(`cancelled`,`AbortError`);if(!(e.file.size>=8388608)){l(e.id,{status:`hashing`});try{let t=await E(e.file,t=>l(e.id,{progress:t}));r.set(e.id,t),l(e.id,{status:`checking`,progress:0})}catch(t){l(e.id,{status:`error`,error:t instanceof Error?t.message:`Failed to read file`})}}}let i={};if(r.size)try{i=await w(n,[...new Set(r.values())])}catch{i={}}let a=m.filter(e=>r.has(e.id)||e.file.size>=8388608),o=0;await Promise.all(Array.from({length:Math.min(R,a.length)},async()=>{for(;o<a.length;){if(p.signal.aborted)return;let s=a[o++],c=r.get(s.id);try{let r=c?i[c]??null:null;r?l(s.id,{status:`linking`,progress:1,resumed:!0}):(l(s.id,{status:`uploading`,progress:0}),r=await C(n,s.file,{sha256:c,signal:p.signal,onProgress:(e,t)=>l(s.id,{progress:t?e/t:0})}),l(s.id,{status:`linking`,progress:1}));let a=await b(e,[t(r,s.file)],{refresh:!1});l(s.id,{status:`done`,docId:a[0]})}catch(e){let t=e instanceof DOMException&&e.name===`AbortError`;l(s.id,{status:`error`,error:t?`Cancelled`:e instanceof Error?e.message:`Upload failed`})}}}))}}finally{if(p.signal.aborted)for(let e of a.current)e.status!==`done`&&e.status!==`error`&&l(e.id,{status:`error`,error:`Cancelled`});i(!1),s.current===p&&(s.current=null),a.current.some(e=>e.status===`done`)&&x(e)}let h=a.current;return{done:h.filter(e=>e.status===`done`).length,resumed:h.filter(e=>e.status===`done`&&e.resumed).length,failed:h.filter(e=>e.status===`error`).length,total:h.length,docIds:h.flatMap(e=>e.status===`done`&&e.docId!=null?[e.docId]:[])}},[l,c]),cancel:p}}function V(e){return e<1024?`${e} B`:e<1048576?`${(e/1024).toFixed(1)} KB`:`${(e/1048576).toFixed(1)} MB`}function H(e){switch(e.status){case`hashing`:return`hashing`;case`checking`:return`checking`;case`uploading`:return`${Math.round(e.progress*100)}%`;case`linking`:return`saving`;case`done`:return e.resumed?`already uploaded`:`done`;case`error`:return e.error||`failed`;default:return V(e.file.size)}}function U({item:e}){switch(e.status){case`done`:return(0,k.jsx)(a,{className:`h-3.5 w-3.5 shrink-0 text-green-600 dark:text-green-500`});case`error`:return(0,k.jsx)(i,{className:`h-3.5 w-3.5 shrink-0 text-destructive`});case`queued`:return(0,k.jsx)(o,{className:`h-3.5 w-3.5 shrink-0 text-muted-foreground`});default:return(0,k.jsx)(c,{className:`h-3.5 w-3.5 shrink-0 animate-spin text-muted-foreground`})}}function W({item:e}){if(e.status===`queued`)return null;let t=e.status===`done`||e.status===`error`||e.status===`linking`?1:e.status===`checking`?0:e.progress;return(0,k.jsx)(`div`,{className:`h-1 w-full overflow-hidden rounded-full bg-muted`,children:(0,k.jsx)(`div`,{className:u(`h-full rounded-full transition-[width] duration-normal`,e.status===`error`?`bg-destructive`:e.status===`done`?`bg-green-600 dark:bg-green-500`:`bg-primary`),style:{width:`${Math.round(t*100)}%`}})})}function G({items:e,running:t,onRemove:n}){let i=e.filter(e=>e.status===`done`).length,a=e.filter(e=>e.status===`error`).length;return(0,k.jsx)(k.Fragment,{children:e.length>0&&(0,k.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,k.jsxs)(f,{children:[e.length,` file(s)`,i>0&&(0,k.jsxs)(`span`,{className:`ml-1 text-muted-foreground`,children:[`— `,i,` done`,a>0?`, ${a} failed`:``]})]}),(0,k.jsx)(`ul`,{className:`max-h-48 space-y-1 overflow-y-auto`,children:e.map(e=>(0,k.jsxs)(`li`,{className:`flex flex-col gap-1 rounded border border-input px-2 py-1 text-sm`,children:[(0,k.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,k.jsx)(U,{item:e}),(0,k.jsx)(`span`,{className:`flex-1 truncate`,title:e.file.name,children:e.file.name}),(0,k.jsx)(`span`,{className:u(`shrink-0 text-xs`,e.status===`error`?`text-destructive`:`text-muted-foreground`),title:e.status===`error`?e.error:void 0,children:H(e)}),!t&&e.status!==`done`&&(0,k.jsx)(`button`,{type:`button`,onClick:()=>n(e.id),className:`text-muted-foreground hover:text-foreground`,"aria-label":`Remove ${e.file.name}`,children:(0,k.jsx)(r,{className:`h-3.5 w-3.5`})})]}),(0,k.jsx)(W,{item:e})]},e.id))})]})})}function K({items:e,running:t,onCancel:n}){return(0,k.jsxs)(`div`,{className:`space-y-4 overflow-y-auto p-4`,children:[(0,k.jsx)(`h2`,{className:`text-sm font-medium`,children:`Uploading files`}),!t&&(0,k.jsx)(`p`,{role:`status`,className:`text-sm text-muted-foreground`,children:`Preparing / finishing upload…`}),(0,k.jsx)(G,{items:e,running:!0,onRemove:()=>{}}),(0,k.jsx)(d,{variant:`outline`,size:`sm`,disabled:!t,onClick:n,children:`Cancel upload`})]})}export{F as a,O as c,L as i,K as n,P as o,B as r,j as s,G as t};
@@ -1 +0,0 @@
1
- import{o as e}from"./rolldown-runtime-C0FnF6B9.js";import{l as t,u as n}from"./code-editor-BOIngd5F.js";import{_ as r,g as i,h as a}from"./chunk-62JRHF6Z-vspAGgtK.js";import{Kn as o,L as s,Tt as c,Ur as l,Vr as u,X as d,ar as f,gr as p,kt as m,pn as h}from"./ui-CDoK3F3U.js";import{t as g}from"./utils-2pl1SbIp.js";import{t as ee}from"./button-SeUZ_Pvi.js";import{c as _,t as te}from"./api-CA6WiiYM.js";import{t as v}from"./socket-CtH3EU9m.js";import{n as ne}from"./use-toast-BlLDqSUO.js";import{h as y,o as re,s as b}from"./LinkToCard-CKVi4Nrg.js";import{At as x,D as S,G as ie,Gt as C,Kt as w,Lt as ae,W as oe,Y as se,_ as T,_n as ce,a as le,bn as E,gt as D,lt as O,mt as ue,nt as de,rn as fe,rt as pe,u as me,vt as he,w as ge,x as _e,y as ve,zt as ye}from"./workspace-C5V-ZCOE.js";import{n as be,r as xe}from"./use-canvas-pins-Bmj8upH3.js";import{u as Se}from"./ObjectPropertiesCard-D2lrTQqT.js";import{a as Ce,c as k,d as we,f as A,i as Te,l as Ee,o as De,p as Oe,r as ke,w as Ae}from"./document-list-BLu9S0zR.js";import{n as je}from"./use-toolbox-Ck_cLGgf.js";import{i as Me}from"./color-DFEH4BfK.js";import{t as Ne}from"./geo-CZfs0E-x.js";import{a as Pe,i as Fe,n as Ie,o as Le}from"./workspace-BydSRtST.js";import{n as Re,r as ze,t as Be}from"./url-params-n7kU_WZ-.js";import{i as Ve}from"./use-menu-DIP1zh7I.js";import{n as He}from"./last-path-BbXWC3b3.js";import{t as Ue}from"./workspace-area-menu-LLSySOlH.js";import{t as We}from"./workspace-content-gate-C54J9Man.js";import{t as Ge}from"./form-panel-3p-ncEVK.js";import{a as Ke,c as qe,i as Je,l as Ye,n as Xe,o as Ze,r as Qe,s as $e,t as et,u as tt}from"./tree-folders-Da9k9cbV.js";import{i as nt,r as rt}from"./query-debug-lD5vbJGi.js";var j=`session.open`,it=`session.set`,at=`session.ids`,ot=`session.materialize`,st=`session.close`,ct=`session.delta`,M=e(n(),1),N=t();function lt(e){let t=we(`backends`,e.path)?.backend;return(0,N.jsx)(ut,{...e},JSON.stringify([e.workspace,t]))}function ut({workspace:e,path:t,onNavigate:n}){let r=we(`backends`,t),i=r.backend,a=r.prefix,[s,l]=(0,M.useState)(null),[u,h]=(0,M.useState)(null),g=(0,M.useRef)(!1),[ee,_]=(0,M.useState)(null),[te,v]=(0,M.useState)(null),[ne,x]=(0,M.useState)(0),[S,ie]=(0,M.useState)(new Set),[C,w]=(0,M.useState)(null),ae=(0,M.useCallback)(()=>x(e=>e+1),[]),[oe,se]=(0,M.useState)(t);oe!==t&&(se(t),ie(new Set),w(null),v(null),_(null));let T=s?.revision!==ne,ce=T?[]:s.items,le=T?[]:s.backends,E=s?.days;(0,M.useEffect)(()=>{let t=!1;return(i?k(e,i).then(e=>({...e,backends:[]})):he(e).then(e=>({items:[],days:null,backends:e.filter(e=>e.driver===`file`&&e.enabled!==!1)}))).then(e=>{t||l({...e,revision:ne,error:null})}).catch(e=>{t||l({revision:ne,items:[],backends:[],days:null,error:e instanceof Error?e.message:String(e)})}),()=>{t=!0}},[e,i,ne]),(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,ae()},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,ae]);let D=Oe(ce,a),O=async(t,n)=>{if(!(!i||g.current||T||!n.length)&&!(t===`discard`&&!Ce(i,n))){g.current=!0,h(t),_(null),v(null),w(null);try{let r=await(t===`restore`?Ee:De)(e,i,[...n].sort((e,t)=>t.deletedAt-e.deletedAt).map(e=>e.id)),a=r.filter(e=>!e.ok);v(`${r.length-a.length} item(s) ${t===`restore`?`restored to their original paths`:`permanently deleted`}.`),a.length&&_(`${a.length} item(s) remain in Trash. ${a.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(`; `)}`),ie(new Set)}catch(e){_(e instanceof Error?e.message:String(e))}finally{g.current=!1,h(null),ae()}}},ue=(e,t,n)=>w({x:e,y:t,row:n});return(0,N.jsxs)(`section`,{className:`flex h-full min-h-0 flex-col bg-background`,"aria-label":`Backend Trash`,children:[(0,N.jsxs)(`div`,{className:`flex min-w-0 flex-wrap items-center gap-2 border-b px-4 py-3`,children:[(0,N.jsx)(d,{className:`h-4 w-4 shrink-0 text-muted-foreground`}),(0,N.jsx)(b,{items:re(t,e).map((e,t)=>t===2&&i?{...e,label:i}:e),onNavigate:n,className:`basis-48`}),(0,N.jsxs)(`div`,{className:`ml-auto flex max-w-full flex-wrap items-center gap-2`,children:[S.size>0&&(0,N.jsxs)(N.Fragment,{children:[(0,N.jsxs)(`button`,{className:`flex items-center gap-1 rounded border px-2 py-1 text-sm disabled:opacity-50`,disabled:!!u||T,onClick:()=>void O(`restore`,D.filter(e=>S.has(e.id)).flatMap(e=>e.items)),children:[(0,N.jsx)(c,{className:`h-3.5 w-3.5`}),`Restore selected`]}),(0,N.jsxs)(`button`,{className:`flex items-center gap-1 rounded border px-2 py-1 text-sm text-destructive disabled:opacity-50`,disabled:!!u||T,onClick:()=>void O(`discard`,D.filter(e=>S.has(e.id)).flatMap(e=>e.items)),children:[(0,N.jsx)(d,{className:`h-3.5 w-3.5`}),`Delete selected`]})]}),i&&D.length>0&&(0,N.jsxs)(`button`,{className:`flex items-center gap-1 rounded border px-2 py-1 text-sm text-destructive disabled:opacity-50`,disabled:!!u||T,onClick:()=>void O(`discard`,D.flatMap(e=>e.items)),children:[(0,N.jsx)(d,{className:`h-3.5 w-3.5`}),a?`Empty this folder`:`Empty Trash`]}),(0,N.jsx)(`button`,{title:`Refresh Trash`,"aria-label":`Refresh Trash`,className:`rounded p-2 hover:bg-accent`,disabled:!!u||T,onClick:ae,children:(0,N.jsx)(m,{className:`h-4 w-4 ${T?`animate-spin`:``}`})})]})]}),(0,N.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.`,E?` Deleted items are kept for ${E} days.`:``]}),te&&(0,N.jsx)(`p`,{role:`status`,className:`px-4 py-2 text-sm`,children:te}),(ee||s?.error)&&(0,N.jsx)(`p`,{role:`alert`,className:`px-4 py-2 text-sm text-destructive`,children:ee||s?.error}),u&&(0,N.jsx)(`p`,{role:`status`,className:`px-4 py-2 text-sm`,children:u===`restore`?`Restoring…`:`Deleting permanently…`}),(0,N.jsx)(`div`,{className:`min-h-0 flex-1 overflow-auto p-3`,children:T?(0,N.jsx)(`p`,{className:`p-4 text-sm text-muted-foreground`,children:`Loading Trash…`}):i?D.length===0?(0,N.jsx)(`p`,{className:`p-4 text-sm text-muted-foreground`,children:`This Trash folder is empty.`}):(0,N.jsxs)(`table`,{className:`w-full text-left text-sm`,children:[(0,N.jsx)(`thead`,{className:`border-b text-xs text-muted-foreground`,children:(0,N.jsxs)(`tr`,{children:[(0,N.jsx)(`th`,{className:`w-8 p-2`,children:(0,N.jsx)(`input`,{type:`checkbox`,"aria-label":`Select all visible items`,checked:D.length>0&&D.every(e=>S.has(e.id)),onChange:e=>ie(e.target.checked?new Set(D.map(e=>e.id)):new Set)})}),(0,N.jsx)(`th`,{className:`p-2`,children:`Name`}),(0,N.jsx)(`th`,{className:`p-2 max-sm:hidden`,children:`Original path`}),(0,N.jsx)(`th`,{className:`p-2 max-md:hidden`,children:`Deleted`}),(0,N.jsx)(`th`,{className:`p-2`,children:(0,N.jsx)(`span`,{className:`sr-only`,children:`Actions`})})]})}),(0,N.jsx)(`tbody`,{children:D.map(e=>(0,N.jsxs)(`tr`,{className:`border-b border-border/50 hover:bg-accent/50`,onContextMenu:t=>{t.preventDefault(),ue(t.clientX,t.clientY,e)},onDoubleClick:()=>e.navigable&&n(A(i,e.key)),children:[(0,N.jsx)(`td`,{className:`p-2`,children:(0,N.jsx)(`input`,{type:`checkbox`,"aria-label":`Select ${e.name}`,checked:S.has(e.id),disabled:!!u,onChange:t=>ie(n=>{let r=new Set(n);return t.target.checked?r.add(e.id):r.delete(e.id),r})})}),(0,N.jsx)(`td`,{className:`p-2`,children:(0,N.jsxs)(`button`,{className:`flex items-center gap-2 text-left`,onClick:()=>e.navigable&&n(A(i,e.key)),children:[e.directory?(0,N.jsx)(o,{className:`h-4 w-4 shrink-0`}):(0,N.jsx)(f,{className:`h-4 w-4 shrink-0`}),(0,N.jsxs)(`span`,{children:[e.name,e.navigable&&(0,N.jsxs)(`span`,{className:`ml-2 text-xs text-muted-foreground`,children:[e.items.length,` items`]})]})]})}),(0,N.jsx)(`td`,{className:`p-2 text-xs text-muted-foreground max-sm:hidden`,children:e.key}),(0,N.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,N.jsx)(`td`,{className:`p-2 text-right`,children:(0,N.jsx)(`button`,{title:`Actions for ${e.name}`,"aria-label":`Actions for ${e.name}`,disabled:!!u,className:`rounded p-2 hover:bg-accent`,onClick:t=>ue(t.clientX,t.clientY,e),children:(0,N.jsx)(p,{className:`h-4 w-4`})})})]},e.id))})]}):(0,N.jsxs)(`div`,{className:`grid gap-2 sm:grid-cols-2 lg:grid-cols-3`,children:[le.map(e=>(0,N.jsxs)(`button`,{onClick:()=>n(A(e.address)),className:`flex items-center gap-3 rounded-lg border p-4 text-left hover:bg-accent`,children:[(0,N.jsx)(d,{className:`h-6 w-6 text-muted-foreground`}),(0,N.jsxs)(`span`,{children:[(0,N.jsx)(`span`,{className:`block text-sm font-medium`,children:e.label||e.address}),(0,N.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:e.address})]})]},e.address)),!le.length&&(0,N.jsx)(`p`,{className:`p-4 text-sm text-muted-foreground`,children:`No file backends are available.`})]})}),C&&(0,N.jsxs)(y,{x:C.x,y:C.y,onClose:()=>w(null),className:`min-w-44 rounded-md border bg-popover p-1 shadow-elevation-3`,children:[C.row.navigable&&(0,N.jsxs)(`button`,{className:`flex w-full items-center gap-2 rounded px-3 py-2 text-sm hover:bg-accent`,onClick:()=>{n(A(i,C.row.key)),w(null)},children:[(0,N.jsx)(o,{className:`h-4 w-4`}),`Open folder`]}),(0,N.jsxs)(`button`,{disabled:!!u,className:`flex w-full items-center gap-2 rounded px-3 py-2 text-sm hover:bg-accent disabled:opacity-50`,onClick:()=>void O(`restore`,C.row.items),children:[(0,N.jsx)(c,{className:`h-4 w-4`}),`Restore `,C.row.directory?`folder`:`file`]}),(0,N.jsxs)(`button`,{disabled:!!u||T,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 O(`discard`,C.row.items),children:[(0,N.jsx)(d,{className:`h-4 w-4`}),`Delete permanently`]})]})]})}function dt({workspaceId:e,workspaceName:t}){let[n,r]=(0,M.useState)([]),[i,a]=(0,M.useState)(new Set),o=t=>`${e}:${t.address}:${t.resyncStartedAt||``}`;(0,M.useEffect)(()=>{let t=!1,n=!1,i=!1,a=0,o=new Map,s=new Map,c=(e,t)=>{let n=e.filter(e=>e.address!==t.backend);if(!t.resyncing)return n;let r=e.find(e=>e.address===t.backend)||s.get(t.backend);return[...n,{address:t.backend,config:r?.config,resyncStartedAt:r?.resyncStartedAt||new Date().toISOString(),progress:t.progress??r?.progress}]},l=async()=>{if(n){i=!0;return}n=!0;let u=a;try{let n=await he(e);if(!t){s=new Map(n.map(e=>[e.address,e]));let e=n.filter(e=>e.resyncing);for(let t of o.values())t.version>u&&(e=c(e,t.event));r(e)}}catch{}finally{n=!1,i&&!t&&(i=!1,l())}},u=t=>{t.workspaceId!==e||!t.backend||typeof t.resyncing!=`boolean`||(o.set(t.backend,{version:++a,event:t}),r(e=>c(e,t)))},d=t=>{t.workspaceId===e&&l()};l();let f=v.on(`connect`,l);return v.on(`backend.resync.changed`,u),v.on(`backend.changed`,d),window.addEventListener(`focus`,l),()=>{t=!0,f?.(),v.off(`backend.resync.changed`,u),v.off(`backend.changed`,d),window.removeEventListener(`focus`,l)}},[e]);let c=n.filter(e=>!i.has(o(e)));return c.length?(0,N.jsxs)(`aside`,{"aria-label":`Storage scans for ${t}`,className:`absolute bottom-5 right-5 z-50 w-72 max-w-[calc(100vw-2.5rem)] rounded-lg border bg-popover/95 p-3 text-popover-foreground shadow-lg backdrop-blur`,children:[(0,N.jsxs)(`div`,{role:`status`,className:`mb-2 flex items-center gap-2 text-sm font-medium`,children:[(0,N.jsx)(h,{"aria-hidden":`true`,className:`h-4 w-4 animate-spin`}),(0,N.jsxs)(`span`,{className:`min-w-0 flex-1`,children:[(0,N.jsx)(`span`,{className:`block`,children:`Scanning storage`}),(0,N.jsx)(`span`,{className:`block truncate text-xs font-normal text-muted-foreground`,title:t,children:t})]}),(0,N.jsx)(`button`,{type:`button`,"aria-label":`Hide scan progress for ${t}`,title:`Hide progress; scanning continues`,className:`rounded p-1 hover:bg-muted focus-visible:outline focus-visible:outline-2`,onClick:()=>a(e=>new Set([...e,...c.map(o)])),children:(0,N.jsx)(s,{"aria-hidden":`true`,className:`h-4 w-4`})})]}),(0,N.jsx)(`div`,{className:`max-h-48 space-y-3 overflow-y-auto`,children:c.map(e=>{let{scanned:t=0,total:n=null}=e.progress||{},r=n&&n>0?Math.min(100,Math.round(t/n*100)):null,i=typeof e.config?.label==`string`?e.config.label:e.address;return(0,N.jsxs)(`div`,{children:[(0,N.jsxs)(`div`,{className:`flex items-center justify-between gap-3 text-xs`,children:[(0,N.jsx)(`span`,{className:`truncate`,children:i}),(0,N.jsx)(`span`,{className:`shrink-0 text-muted-foreground`,children:n===null?`${t} files`:`${t} / ${n}`})]}),(0,N.jsx)(`div`,{role:`progressbar`,"aria-label":`Scanning ${i}`,"aria-valuemin":0,"aria-valuemax":100,"aria-valuenow":r??void 0,className:`mt-1.5 h-1 overflow-hidden rounded-full bg-muted`,children:(0,N.jsx)(`div`,{className:`h-full rounded-full bg-primary ${r===null?`animate-pulse`:`transition-all`}`,style:{width:r===null?`35%`:`${r}%`}})})]},e.address)})})]}):null}var ft=e=>e&&typeof e==`object`&&!Array.isArray(e)?e:null;function pt(e){return`/${e}`.replace(/\/+/g,`/`).replace(/\/$/,``)||`/`}function mt(e,t,n){if(e==null)return[];if(Array.isArray(e))return e.flatMap(e=>mt(e,t,n));if(typeof e==`string`)return[{tree:null,kind:t,path:pt(e)}];let r=ft(e);if(!r)return[];let i=r.tree??r.treeId,a=typeof i==`string`?n.get(i)??null:null;return[].concat(r.paths??r.path??`/`).filter(e=>typeof e==`string`).map(e=>({tree:a,kind:t,path:pt(e)}))}function ht(e){let t=[],n=e=>{let n=Number(e);Number.isSafeInteger(n)&&n>0&&t.push(n)};return Array.isArray(e.ids)&&e.ids.forEach(n),Array.isArray(e.documentIds)&&e.documentIds.forEach(n),e.id!=null&&n(e.id),e.documentId!=null&&n(e.documentId),t}function gt(e){let t=new Map;for(let n of e)t.set(n.id,n.name),t.set(n.name,n.name);return t}function _t(e,t,n=new Map){let r=ft(t);if(!r)return{targets:[],ids:[],unknown:!0};if(e.startsWith(`tree.`)){let e=typeof r.treeName==`string`?r.treeName:null,t=r.treeType===`directory`||r.treeType===`context`?r.treeType:null,n=r.contextSpec??r.path;return typeof n==`string`?{targets:[{tree:e,kind:t,path:pt(n)}],ids:ht(r),unknown:!1}:{targets:[],ids:[],unknown:!0}}let i=[...mt(r.context,`context`,n),...mt(r.directory,`directory`,n)],a=ft(r.changed);a&&i.push(...mt(a.context,`context`,n),...mt(a.directory,`directory`,n));let o=ht(r);if(i.length)return{targets:i,ids:o,unknown:!1};let s=r.reason===`content`||r.reason===`relations`||r.reason===`moved`;return(e.startsWith(`document.updated`)||e.startsWith(`document.moved`))&&s&&o.length?{targets:[],ids:o,unknown:!1}:{targets:[],ids:o,unknown:!0}}function vt(e,t){return e===t||e===`/`||t===`/`||e.startsWith(`${t}/`)||t.startsWith(`${e}/`)}function yt(e,t){if(e.kind&&e.kind!==t.kind||e.tree&&e.tree!==t.tree)return!1;if(t.kind===`context`){let n=e=>pt(e).split(`/`).filter(Boolean).map(e=>e.normalize(`NFKC`).trim().replace(/\s+/g,` `).replace(/[^\p{L}\p{N}\p{M} .+_@-]/gu,`_`).replace(/_+/g,`_`).toLowerCase()||`_`),r=new Set(n(e.path)),i=n(t.path);return r.size===0||i.length===0||i.some(e=>r.has(e))}return vt(e.path,t.path)}function bt(e){return _t(`tree.refresh`,{treeName:e?.treeName,path:e?.path||`/`})}function xt(e,t,n){if(e.unknown||e.targets.length&&(t.wholeWorkspace||e.targets.some(e=>yt(e,t))))return!0;if(e.ids.length&&n){let t=n instanceof Set?n:new Set(n);if(e.ids.some(e=>t.has(e)))return!0}return!1}function St(e,t,n={}){return v.request(j,{workspace:e,specs:t,opts:n})}function Ct(e,t,n){return v.request(it,{sessionId:e,label:t,spec:n})}function wt(e){return v.request(at,{sessionId:e})}function P(e,t={}){return v.request(ot,{sessionId:e,...t})}function Tt(e){return v.request(st,{sessionId:e})}function F(e){return v.on(ct,e)}var I=100;function Et({workspaceRef:e,specs:t,opts:n,enabled:r=!0}){let[i,a]=(0,M.useState)([]),[o,s]=(0,M.useState)(0),[c,l]=(0,M.useState)(null),[u,d]=(0,M.useState)(null),f=(0,M.useRef)([]),p=(0,M.useRef)(new Map),m=(0,M.useRef)(null),h=(0,M.useRef)(null),g=(0,M.useRef)(null),ee=(0,M.useRef)({}),_=(0,M.useRef)(null),te=(0,M.useMemo)(()=>JSON.stringify(t),[t]),ne=(0,M.useMemo)(()=>JSON.stringify(n??{}),[n]),y=(0,M.useCallback)(()=>{let e=p.current;a(f.current.map(t=>e.get(t)).filter(Boolean))},[]),re=(0,M.useCallback)(async e=>{let t=h.current;if(!t||e.length===0)return[];let n=[];for(let r=0;r<e.length;r+=I){let i=e.slice(r,r+I),a=await de(t,`/`,[],{ids:i,scope:`workspace`,limit:i.length});n.push(...a.payload||[])}return n},[]),b=(0,M.useCallback)(async(e,t,n)=>{if(t.length>0){let e=new Set(t);f.current=f.current.filter(t=>!e.has(t));for(let t of e)p.current.delete(t)}let r=e.filter(e=>!p.current.has(e)),i=new Set(f.current);for(let t of e)i.has(t)||(f.current.push(t),i.add(t));if(n!==null&&s(n),y(),r.length===0)return;let a=await re(r);for(let e of a)p.current.set(e.id,e);let o=new Set(a.map(e=>e.id)),c=r.filter(e=>!o.has(e));if(c.length>0){let e=new Set(c);f.current=f.current.filter(t=>!e.has(t))}y()},[re,y]),x=(0,M.useCallback)(async(e,t)=>{let n=e??[],r=new Set(n);f.current=f.current.filter(e=>r.has(e));for(let e of p.current.keys())r.has(e)||p.current.delete(e);let i=new Set(f.current),a=n.filter(e=>!i.has(e));await b(a,[],t)},[b]);(0,M.useEffect)(()=>{if(h.current=e??null,!r||!e)return;let t=!1,n=null,i=async()=>{try{let r=await St(e,JSON.parse(te),JSON.parse(ne));if(t){Tt(r.sessionId).catch(()=>{});return}n=r.sessionId,m.current=r.sessionId,l(r.sessionId),d(null),f.current=[],p.current=new Map,await x(r.ids,r.count)}catch(e){if(t)return;d(e instanceof Error?e.message:`Failed to open query session`),l(null),m.current=null}};i();let o=v.on(`connect`,()=>{i()});return()=>{t=!0,o?.();let e=n??m.current;e&&Tt(e).catch(()=>{}),m.current=null,f.current=[],p.current=new Map,l(null),a([]),s(0)}},[e,te,ne,r]),(0,M.useEffect)(()=>{if(!c)return;let e=F(e=>{if(e.sessionId===c){if(g.current!==null){_.current?.(g.current,ee.current);return}e.ids===void 0?b(e.added??[],e.removed??[],e.count):x(e.ids,e.count)}});return()=>{e?.()}},[c,b,x]);let S=(0,M.useCallback)(async()=>{let e=m.current;if(e)try{let t=await wt(e);await x(t.ids,t.count)}catch{}},[x]),ie=(0,M.useCallback)(async(e,t)=>{let n=m.current;if(!n)throw Error(`No open query session`);let r=await Ct(n,e,t);if(g.current!==null){await _.current?.(g.current,ee.current);return}await x(r.ids,r.count)},[x]),C=(0,M.useCallback)(async(e,t={})=>{let n=m.current;if(!n)throw Error(`No open query session`);if(g.current=e,ee.current=t,e===null){await S();return}let r=await P(n,{match:e,...t});for(let e of r.documents)p.current.set(e.id,e);f.current=r.ids,s(r.totalCount),y()},[y,S]);(0,M.useEffect)(()=>{_.current=C},[C]);let w=(0,M.useCallback)(async(e,t,n={})=>{let r=m.current;if(!r)throw Error(`No open query session`);let i=await P(r,{match:t,limit:n.limit??100,...n.mode?{mode:n.mode}:{}});for(let e of i.documents)p.current.set(e.id,e);let a=await Ct(r,e,{ids:i.ids});return await x(a.ids,a.count),i.ids},[x]);return{documents:i,count:o,ready:c!==null,error:u,setCue:ie,resync:S,rank:C,rankAndPin:w}}function Dt({data:e,className:t}){let[n,r]=(0,M.useState)(!0),{rows:i,gapIndex:a,span:o}=(0,M.useMemo)(()=>{let t=[...e.distances].sort((e,t)=>e.distance-t.distance),n=[];for(let e=1;e<t.length;e++)n.push(t[e].distance-t[e-1].distance);let r=n.length?[...n].sort((e,t)=>e-t)[Math.floor(n.length/2)]:0,i=-1,a=0;for(let e=0;e<n.length;e++)n[e]>a&&(a=n[e],i=e+1);let o=i>0&&a>=Math.max(r*4,1e-6),s=t[0]?.distance??0,c=t[t.length-1]?.distance??0;return{rows:t,gapIndex:o?i:-1,span:{first:s,last:c,biggest:a,median:r}}},[e.distances]);if(i.length===0)return(0,N.jsxs)(`div`,{className:g(`rounded-md border border-dashed border-border px-3 py-2 text-xs text-muted-foreground`,t),children:[`Query debug: no image distances for “`,e.query,`”. The dense side returned nothing: either no photos are embedded in this scope, or the image space is not ready.`]});let s=a>0?i[a].distance:null;return(0,N.jsxs)(`div`,{className:g(`rounded-md border border-border bg-muted/30 text-xs`,t),children:[(0,N.jsxs)(`button`,{type:`button`,onClick:()=>r(e=>!e),className:`flex w-full items-center gap-1.5 px-3 py-2 text-left font-medium`,children:[n?(0,N.jsx)(l,{className:`h-3.5 w-3.5`}):(0,N.jsx)(u,{className:`h-3.5 w-3.5`}),`Query debug`,(0,N.jsxs)(`span`,{className:`font-normal text-muted-foreground`,children:[`: image distances for “`,e.query,`” (`,i.length,` nearest, unfloored)`]})]}),n&&(0,N.jsxs)(`div`,{className:`space-y-2 border-t border-border px-3 py-2`,children:[(0,N.jsxs)(`p`,{className:`text-[11px] text-muted-foreground`,children:[`Best-first cosine distance (0 = identical). Scroll to where the photos stop being relevant and set the image relevance floor just above that value in Settings → Database → Search tuning.`,s===null?(0,N.jsxs)(N.Fragment,{children:[` `,(0,N.jsx)(`span`,{className:`text-amber-600 dark:text-amber-500`,children:`No boundary in this window`}),`; the distances step evenly (typical Δ`,o.median.toFixed(4),`), so there is nothing here to set a floor from. Relevance probably ends further down the list than this window reaches, or the model is not separating this query at all.`]}):(0,N.jsxs)(N.Fragment,{children:[` A jump at `,(0,N.jsx)(`span`,{className:`font-mono`,children:s.toFixed(4)}),` (Δ`,o.biggest.toFixed(4),`, vs typical Δ`,o.median.toFixed(4),`) stands out (a likely boundary).`]})]}),(0,N.jsx)(`div`,{className:`max-h-56 overflow-y-auto`,children:(0,N.jsx)(`table`,{className:`w-full font-mono text-[11px]`,children:(0,N.jsx)(`tbody`,{children:i.map((e,t)=>(0,N.jsxs)(`tr`,{className:g(`border-b border-border/40 last:border-0`,t===a&&`border-t-2 border-t-amber-500/70`),children:[(0,N.jsx)(`td`,{className:`py-0.5 pr-3 text-muted-foreground`,children:t+1}),(0,N.jsxs)(`td`,{className:`py-0.5 pr-3`,children:[`#`,e.id]}),(0,N.jsx)(`td`,{className:`py-0.5 tabular-nums`,children:e.distance.toFixed(4)}),t===a&&(0,N.jsx)(`td`,{className:`py-0.5 pl-2 font-sans text-[10px] text-amber-600 dark:text-amber-500`,children:`← biggest gap`})]},e.id))})})}),(0,N.jsxs)(`p`,{className:`text-[11px] text-muted-foreground`,children:[`Range `,o.first.toFixed(4),` – `,o.last.toFixed(4),` (spread `,(o.last-o.first).toFixed(4),`) over `,i.length,` rows. Absolute values shift with the model and are not comparable across models. After a re-embed every floor has to be picked again. A spread this narrow relative to the range means ranking is doing the work, not distance.`]})]})]})}var Ot=new Map;function L(e,t,n){return`${e}\0${t}\0${n}`}function kt(e,t,n,r,i,a,o=``,s=``,c=`path`){return`${L(e,t,n)}\0${r}\0${i}\0${a}\0${o}\0${s}\0${c}`}function R(e,t,n){let r=L(e,t,n);for(let e of Ot.keys())e.startsWith(r)&&Ot.delete(e)}function At(e,t){let n=`${e}\0`;for(let[e,r]of Ot){if(!e.startsWith(n))continue;let[,i,a,,,,,,o=`path`]=e.split(`\0`);xt(t,{tree:i,kind:E(i),path:a,wholeWorkspace:o.startsWith(`workspace`)},r.documents.map(e=>Number(e.id)))&&Ot.delete(e)}}function jt(e,t){At(t?.workspaceName??e,bt(t))}function Mt(){let{workspaceName:e}=r();return e?(0,N.jsx)(We,{workspaceName:e,children:(0,N.jsx)(z,{})}):null}function z(){let{workspaceName:e,treeName:t}=r(),n=a(),o=i(),{showToast:s,showProgress:c}=ne(),l=new URLSearchParams(n.search),u=(()=>{let e=l.getAll(`q`).map(e=>e.trim()).filter(Boolean);if(e.length>0)return e;let t=(l.get(`search`)||``).trim();return t?[t]:[]})(),[d,f]=(0,M.useState)(null),[p,m]=(0,M.useState)(!0),[h,y]=(0,M.useState)([]),[re,b]=(0,M.useState)(!1),[Ce,k]=(0,M.useState)(0),A=rt(),[Ee,De]=(0,M.useState)(null),[Oe,We]=(0,M.useState)(A);Oe!==A&&(We(A),A||De(null));let[j,it]=(0,M.useState)(`path`),[at,ot]=(0,M.useState)(!1),[st,ct]=(0,M.useState)(null),[ut,ft]=(0,M.useState)(null),[pt,mt]=(0,M.useState)(``),[ht,vt]=(0,M.useState)(!1),[yt,St]=(0,M.useState)(!1),[Ct,wt]=(0,M.useState)(!1),[P,Tt]=(0,M.useState)(null),[F,I]=(0,M.useState)(1),[L,Mt]=(0,M.useState)(50),[z,Nt]=(0,M.useState)(u),[Ft,It]=(0,M.useState)(null),{state:B,saveFilters:Lt,setSort:Rt,setAccentColor:zt,setMapDocuments:Bt}=je(),Vt=B.filters.features.allOf,Ht=B.filters.features.anyOf,Ut=B.filters.features.noneOf,Wt=Fe(B.filters.timeline),Gt=Pe(B.filters.geo),Kt=Le(B.filters.lens,B.filters.geo.includeUnlocated),V=B.filters.lens.ids,qt=[...Wt,...Gt,...Kt],Jt=B.filters.sort??Ie,Yt=JSON.stringify({a:Vt,b:Ht,c:Ut,d:qt,i:V,s:Jt}),Xt=JSON.stringify({a:Vt,b:Ht,c:Ut,d:qt,s:Jt}),H=Re(n.pathname).path,U=t??`context`,W=U===`backends`,[Zt,Qt]=(0,M.useState)([]);(0,M.useEffect)(()=>{!W||!e||he(e).then(Qt).catch(()=>Qt([]))},[W,e]);let $t=W?le(H,Zt):null,[en,tn]=(0,M.useState)(!1),nn=`${U}\0${H}`,[rn,an]=(0,M.useState)(nn);rn!==nn&&(an(nn),tn(!1));let G=l.get(`layer`)===`1`,K=l.get(`layerId`)||null,[q,on]=(0,M.useState)(null),[J,sn]=(0,M.useState)(null),cn=(0,M.useRef)(null);(0,M.useEffect)(()=>{cn.current=J},[J]);let[ln,un]=(0,M.useState)(`left`),[dn,fn]=(0,M.useState)([]),{openM1Drawer:pn,openM2Drawer:mn,goBack:hn}=Ve(),[gn,_n]=(0,M.useState)([]),Y=(0,M.useMemo)(()=>{if(!q||H===`/`||G)return null;let e=H.split(`/`).filter(Boolean),t=q;for(let n of e)if(t=t?.children?.find(e=>e.name===n)??null,!t)return null;return t},[q,H,G]),X=Y?.type===`canvas`?`canvas`:null,vn=(0,M.useRef)(null);(0,M.useEffect)(()=>{!e||!q||G||vn.current===`${e}/${U}`&&(H!==`/`&&!Y||He(e,U,H))},[e,q,G,H,Y,U]);let yn=(0,M.useMemo)(()=>G||j===`workspace`||z.length>0?[]:et(q,H),[q,H,G,j,z]),bn=G?null:H===`/`?q:Y,Z=Ae(),xn=`${U}\0${H}`,[Sn,Cn]=(0,M.useState)(null),wn=Sn?.key===xn?Sn.views:$e(bn?.metadata),Tn=Z?.pinned&&Z.view?[Z.view,...wn.filter(e=>e.id!==Z.view.id)]:wn,En=Z?.pinned&&Z.view?Z.view.id:Sn?.key===xn?Sn.activeId:Tn[0]?.id??Ke.id,Q=Tn.find(e=>e.id===En)??Tn[0]??Ke;(0,M.useEffect)(()=>{Z?.selectView(Q)},[Q,Z]);let Dn=W?void 0:Z?.schema??Ze(Q),On=Dn?[...Vt,Dn]:Vt;tt(Ye({workspace:e??null,treeNameOrId:U,treeType:E(U),path:H,scope:j===`workspace`?`workspace`:G?`layer`:`path`,layerId:G?K:void 0,unfiledOnly:en},{...B.filters,features:{...B.filters.features,allOf:On}},B.geoSelection,z));let kn=e=>{let t=Tn.find(t=>t.id===e);t&&Z?.selectView(t),I(1),fn([]),Cn({key:xn,views:Tn,activeId:e})},An=(t,n)=>{n&&n!==En&&(I(1),fn([]));let r=t.find(e=>e.id===(n??En));r&&Z?.selectView(r),Cn({key:xn,views:t,activeId:n??En}),ce(e,H,{metadata:{...bn?.metadata??{},views:t}},U).catch(()=>{s({title:`View not saved`,description:`Could not persist views to the layer`,variant:`destructive`})})},jn=X===`canvas`&&typeof Y?.querySpec?.query==`string`?Y.querySpec.query:``,Mn=X===`canvas`?{label:Y?.label,description:Y?.description,color:Y?.color}:null,{isPinned:Nn,pin:Pn,unpin:Fn,pins:In}=be(),Ln=d?.name,$=(0,M.useMemo)(()=>Ln&&X===`canvas`&&!G?{workspaceName:Ln,treeName:U,path:H}:null,[Ln,X,G,U,H]),Rn=$?Nn($):!1,zn=Y?.id,Bn=Y?.label,Vn=(0,M.useCallback)(async()=>{if($)try{let e=In.find(e=>e.workspaceName===$.workspaceName&&e.treeName===$.treeName&&e.path===$.path);e?await Fn(e.id):await Pn({...$,layerId:zn,label:Bn})}catch(e){console.error(`Failed to update home pins:`,e)}},[$,In,Pn,Fn,zn,Bn]),Hn=e?`${e}://${H===`/`?``:H.replace(/^\//,``)}`:``,Un=Me(d?.color)||null;(0,M.useEffect)(()=>(zt(Un),()=>zt(null)),[Un,zt]);let Wn=(0,M.useCallback)(async t=>{let n=V;if(t?.anyOf?.length&&Ht.length&&(n=((await ie(e,H,U,{limit:0,anyOf:Ht,ids:V,applyCanvasSpec:!1})).payload||[]).map(e=>e.id),!n.length))return{payload:[],count:0,totalCount:0};let r=await ie(e,H,U,{limit:t?.limit,offset:t?.offset,page:t?.page,sortBy:t?.sortBy,order:t?.order,allOf:[...Vt,...t?.allOf??[]],anyOf:t?.anyOf?.length?t.anyOf:Ht,noneOf:Ut,filters:qt,ids:n,queries:[...z,...t?.queries??[],...t?.q?[t.q]:[]],applyCanvasSpec:!1});return{payload:r.payload||[],count:r.count??void 0,totalCount:r.totalCount??void 0}},[e,H,U,Yt,z]);(0,M.useEffect)(()=>{e&&(async()=>{m(!0);try{let t=await te.get(`${_.workspaces}/${e}`),n;n=t&&`workspace`in t?t.workspace:t,f(n)}catch(t){let n=t instanceof Error?t.message:`Failed to fetch workspace ${e}`;s({title:`Error`,description:n,variant:`destructive`}),f(null)}finally{m(!1)}})()},[e,s]),(0,M.useEffect)(()=>{let e=e=>{let t=e.detail?.workspace;t&&f(e=>e&&(t===e.name||t===e.id)&&e.status!==`active`?{...e,status:`active`}:e)};return window.addEventListener(`workspace:autostarted`,e),()=>window.removeEventListener(`workspace:autostarted`,e)},[]);let Gn=(V?.length??0)>0&&!G&&!(en&&$t)&&z.length<=1,{documents:Kn,count:qn,ready:Jn,setCue:Yn,resync:Xn,rank:Zn}=Et({workspaceRef:e,specs:(0,M.useMemo)(()=>{let e={features:{allOf:On,anyOf:Ht,noneOf:Ut},filters:qt};return j!==`workspace`&&(E(U)===`directory`?e.directory={tree:U,path:H}:e.context=H),[{label:`scope`,spec:e}]},[Xt,H,U,j,Dn]),opts:(0,M.useMemo)(()=>({mode:`live`,debounceMs:150}),[]),enabled:Gn}),Qn=Gn&&Jn,$n=(0,M.useRef)(!1);(0,M.useEffect)(()=>{$n.current=Qn},[Qn]);let er=z.length===1?z[0].trim():``;(0,M.useEffect)(()=>{Jn&&Zn(er?{text:er}:null,{limit:L,offset:(F-1)*L}).catch(()=>{})},[Jn,er,L,F,Zn]);let tr=(V??[]).join(`,`);(0,M.useEffect)(()=>{Jn&&Yn(`lens`,{ids:V??[]}).catch(()=>{})},[Jn,tr,Yn,V]);let nr=Qn?Kn:h,rr=Qn?qn:Ce,ir=(0,M.useRef)(new Set);(0,M.useEffect)(()=>{ir.current=new Set(nr.map(e=>Number(e.id)))},[nr]);let ar=B.geoSelection;(0,M.useEffect)(()=>{Bt(nr,d?.name??null)},[nr,d?.name,Bt]),(0,M.useEffect)(()=>()=>Bt([]),[Bt]);let or=(0,M.useMemo)(()=>ar?nr.filter(e=>Ne(e,ar,B.filters.geo.includeUnlocated)):nr,[nr,ar,B.filters.geo.includeUnlocated]),sr=me(H,On,{treeName:U,treeType:E(U),scope:j,queries:z,anyOf:Ht,noneOf:Ut,filters:qt,ids:V,layerId:G&&K?K:void 0}),cr=JSON.stringify([e,sr]),[lr,ur]=(0,M.useState)(``),[dr,fr]=(0,M.useState)(!1),pr=(0,M.useRef)(!1),mr=re||dr||lr!==cr||Qn||!!ar,hr=(0,M.useRef)(0),gr=(0,M.useRef)(null);(0,M.useEffect)(()=>()=>{hr.current++,gr.current=null},[]);let _r=(0,M.useRef)(``),vr=(0,M.useCallback)(async t=>{if(!e)return;if(we(U,H)){hr.current++,gr.current=null,_r.current=``,y([]),k(0),b(!1);return}if($n.current)return;let n=`${en&&$t?`${j}:unfiled`:j}:${Dn??``}`,r=(V?.length??0)>0,i=kt(e,U,H,F,L,z.join(`␟`),Xt,G&&K?K:``,n),a=r&&i===_r.current;_r.current=i;let o=kt(e,U,H,F,L,z.join(`␟`),Yt,G&&K?K:``,n),c=`${o}\0${A}`;if(t?.silent&&gr.current?.key===c){gr.current.refreshPending=!0;return}let l=++hr.current,u=t?.silent||r||A?void 0:Ot.get(o);u&&(y(u.documents),k(u.totalCount),ur(cr),b(!1)),(t?.silent??(a||!!u))||b(!0);let d={key:c,refreshPending:!1};gr.current=d;try{let t;if(en&&$t)t=await D(e,$t.driver,$t.address,{linked:!1,limit:L,offset:(F-1)*L});else if(G&&K&&j!==`workspace`)t=await pe(e,U,K,{limit:L,page:F,queries:z,allOf:On,anyOf:Ht,noneOf:Ut,filters:qt,ids:V,sortBy:Jt.sortBy||void 0,order:Jt.order});else{let n=E(U);t=await de(e,H,On,{limit:L,page:F,treeName:U,treeType:n,queries:z,anyOf:Ht,noneOf:Ut,filters:qt,ids:V,sortBy:Jt.sortBy||void 0,order:Jt.order,scope:j,debug:A&&z.length>0,debugLimit:200})}let n=t.payload||[],i=t.totalCount||t.count||0;if(!r&&!d.refreshPending&&Ot.set(o,{documents:n,totalCount:i}),l!==hr.current)return;let s=t.debug,c=s?.imageDistances??s?.distances??null;De(c?{query:z[z.length-1]??``,distances:c}:null),y(a?e=>e.length===n.length&&e.every((e,t)=>e.id===n[t].id)?e:n:n),k(i),ur(cr)}catch(e){if(l!==hr.current)return;let t=e instanceof Error?e.message:`Failed to fetch documents`;s({title:`Error`,description:t,variant:`destructive`}),y([]),k(0)}finally{gr.current===d&&(gr.current=null),l===hr.current&&b(!1),l===hr.current&&d.refreshPending&&vr({silent:!0})}},[e,H,U,K,G,F,L,d?.status,z,Yt,j,en,A,Dn]);(0,M.useEffect)(()=>{vr()},[vr]),(0,M.useEffect)(()=>{let t=t=>{let n=t.detail;!n||n.workspaceName!==e||(sn({treeName:n.treeName||`context`,path:ze(n.path||`/`)}),un(`left`))};return window.addEventListener(`workspace:open-to-side`,t),()=>window.removeEventListener(`workspace:open-to-side`,t)},[e,U,H]),(0,M.useEffect)(()=>{let t=t=>{let n=t.detail;if(!(n?.workspaceName&&n.workspaceName!==e)&&(e&&jt(e,n),xt(bt(n),{tree:U,kind:E(U),path:H,wholeWorkspace:j===`workspace`}))){if(e&&R(e,U,H),$n.current){Xn();return}vr({silent:!0})}};return window.addEventListener(`workspace:documents:refresh`,t),()=>window.removeEventListener(`workspace:documents:refresh`,t)},[vr,e,H,U,j,Xn]);let yr=d?.name,br=d?.id;(0,M.useEffect)(()=>{if(!e||!yr&&!br)return;let t=[yr,br].filter(Boolean).map(e=>`workspace:${e}`),n=()=>t.forEach(e=>v.emit(`subscribe`,{channel:e}));n();let r=v.on(`connect`,n),i=new Map,a=!1,o=()=>{x(e).then(e=>{a||(i=gt(e))}).catch(()=>{})};o();let s=null,c=0,l=!1,u=null,d=()=>{if(s=null,c=Date.now(),u){let{treeName:t,path:n}=u;u=null,window.dispatchEvent(new CustomEvent(`workspace:documents:refresh`,{detail:{workspaceName:e,treeName:t,path:n}}))}if(l){if(l=!1,$n.current){Xn();return}vr({silent:!0})}},f=t=>n=>{(t.startsWith(`tree.created`)||t.startsWith(`tree.renamed`))&&o();let r=_t(t,n,i);At(e,r);let a={tree:U,kind:E(U),path:H,wholeWorkspace:j===`workspace`},f=cn.current;f&&xt(r,{tree:f.treeName,kind:E(f.treeName),path:f.path})&&(u=f),xt(r,a,ir.current)&&(l=!0),!(!l&&!u)&&(s||=setTimeout(d,Math.max(200,c+1500-Date.now())))},p=[`document.inserted`,`document.inserted.batch`,`document.updated`,`document.moved`,`document.moved.batch`,`document.removed`,`document.deleted`,`document.removed.batch`,`document.deleted.batch`,`document.linked`,`document.unlinked`,`document.linked.batch`,`document.unlinked.batch`,`tree.document.inserted`,`tree.document.inserted.batch`,`tree.document.removed`,`tree.document.removed.batch`,`tree.document.deleted`,`tree.document.deleted.batch`,`tree.layer.merged`,`tree.layer.subtracted`,`tree.created`,`tree.renamed`].map(e=>[e,f(e)]);return p.forEach(([e,t])=>v.on(e,t)),()=>{a=!0,s&&clearTimeout(s),r?.(),p.forEach(([e,t])=>v.off(e,t))}},[e,br,yr,U,H,j,vr,Xn]);let xr=`${H}\0${U}\0${K??``}\0${j}`,[Sr,Cr]=(0,M.useState)(xr);Sr!==xr&&(Cr(xr),I(1),It(null));let wr=`${H}\0${U}\0${K??``}`,[Tr,Er]=(0,M.useState)(wr);Tr!==wr&&(Er(wr),it(`path`));let Dr=(e,t)=>{let n=e===`/`?`canvas`:e.split(`/`).pop()||`canvas`;mt(n),ft({parentPath:e,captureView:t})},Or=l.get(`createCanvas`)===`1`,[kr,Ar]=(0,M.useState)(!1);kr!==Or&&(Ar(Or),Or&&Dr(H,!1)),(0,M.useEffect)(()=>{if(!Or)return;let e=new URLSearchParams(n.search);e.delete(`createCanvas`);let t=e.toString();o(`${n.pathname}${t?`?${t}`:``}${n.hash}`,{replace:!0})},[Or,H]);let jr=(0,M.useCallback)(e=>{let t=new URLSearchParams(n.search);t.delete(`q`),t.delete(`search`);for(let n of e)t.append(`q`,n);let r=t.toString();o(`${n.pathname}${r?`?${r}`:``}${n.hash}`)},[n.pathname,n.search,n.hash,o]),Mr=JSON.stringify([l.has(`q`),...u]),[Nr,Pr]=(0,M.useState)(Mr);Nr!==Mr&&(Pr(Mr),Nt(u),I(1));let Fr=`${Mr}\0${X??``}\0${jn}\0${H}\0${Ft??``}`,[Ir,Lr]=(0,M.useState)(Fr);Ir!==Fr&&(Lr(Fr),l.has(`q`)||u.length>0||X!==`canvas`||Ft===H||(Nt(jn?[jn]:[]),I(1)));let Rr=(0,M.useCallback)(e=>{let t=e.trim();t&&(It(null),Nt(e=>{if(e.includes(t))return e;let n=[...e,t];return jr(n),I(1),n}))},[jr,It,Nt,I]),zr=(0,M.useCallback)(e=>{Nt(t=>{let n=e<0?[]:t.filter((t,n)=>n!==e);return n.length===0&&It(H),jr(n),I(1),n})},[jr,H,It,Nt,I]),Br=z.join(` `).trim(),Vr=!!B.activeContextType&&(B.isDirty||Br!==(X===`canvas`?jn:B.savedSearchQuery||``));!e&&q!==null&&on(null),(0,M.useEffect)(()=>{let t=!1;if(!e)return;let n=0,r=!1,i=(i=!1)=>{let a=++n;i&&ue(e,U),oe(e,U).then(i=>{!t&&a===n&&(r=!0,vn.current=`${e}/${U}`,on(i))}).catch(()=>{!t&&a===n&&!r&&on(null)})};i(!1);let a=t=>{let n=t.detail;n?.workspaceName&&n.workspaceName!==e||n?.treeName&&n.treeName!==U||i(!n?.cacheInvalidated)};window.addEventListener(`workspace:tree:refresh`,a);let o=Te(e,br);return()=>{t=!0,o(),window.removeEventListener(`workspace:tree:refresh`,a)}},[e,U,br]),!(e&&X===`canvas`&&!G)&&P!==null&&Tt(null),(0,M.useEffect)(()=>{let t=!1;if(!(!e||X!==`canvas`||G))return se(e,H,U).then(e=>{t||Tt(e)}).catch(()=>{t||Tt(null)}),()=>{t=!0}},[e,H,U,X,G]);let Hr=async()=>{if(d){ot(!0);try{let t=await fe(e||d.id);f(t),s({title:`Success`,description:`Workspace started successfully`}),window.dispatchEvent(new CustomEvent(`workspaces:refresh`))}catch(e){let t=e instanceof Error?e.message:`Failed to start workspace`;s({title:`Error`,description:t,variant:`destructive`})}finally{ot(!1)}}},Ur=async t=>{if(!d)return;let n=c({title:`Removing…`,description:`Document from "${H}"`});try{await C(e||d.id,[t],H,[],U,Zr,{trashIfOrphaned:!0}),R(e||d.id,U,H),y(e=>e.filter(e=>e.id!==t)),k(e=>Math.max(0,e-1)),n.done({title:`Success`,description:`Document removed from workspace path.`})}catch(e){n.fail({title:`Error`,description:e instanceof Error?e.message:`Failed to remove document`,variant:`destructive`})}},Wr=async t=>{if(!d)return;let n=c({title:`Deleting…`,description:`Document from "${H}"`});try{await ge(e||d.id,[t],H,[],U,Zr),R(e||d.id,U,H),y(e=>e.filter(e=>e.id!==t)),k(e=>Math.max(0,e-1)),n.done({title:`Success`,description:`Document deleted.`})}catch(e){n.fail({title:`Error`,description:e instanceof Error?e.message:`Failed to delete document`,variant:`destructive`})}},Gr=async t=>{if(!d)return;let n=c({title:`Removing…`,description:`${t.length} document(s) from "${H}"`});try{await C(e||d.id,t,H,[],U,Zr,{trashIfOrphaned:!0}),R(e||d.id,U,H),y(e=>e.filter(e=>!t.includes(e.id))),k(e=>Math.max(0,e-t.length)),n.done({title:`Success`,description:`${t.length} document(s) removed.`})}catch(e){n.fail({title:`Error`,description:e instanceof Error?e.message:`Failed to remove documents`,variant:`destructive`})}},Kr=async t=>{if(!d)return;let n=c({title:`Deleting…`,description:`${t.length} document(s)`});try{await ge(e||d.id,t,H,[],U,Zr),R(e||d.id,U,H),y(e=>e.filter(e=>!t.includes(e.id))),k(e=>Math.max(0,e-t.length)),n.done({title:`Success`,description:`${t.length} document(s) deleted.`})}catch(e){n.fail({title:`Error`,description:e instanceof Error?e.message:`Failed to delete documents`,variant:`destructive`})}},qr=async t=>{if(!d)return;let n=c({title:`Destroying…`,description:`Document and its backend copies`});try{let r=await S(e||d.id,[t]);if(r.failed?.length){n.fail({title:`Error`,description:r.failed[0].reason,variant:`destructive`});return}y(e=>e.filter(e=>e.id!==t)),k(e=>Math.max(0,e-1)),n.done({title:`Destroyed`,description:`Document removed from all backends.`})}catch(e){n.fail({title:`Error`,description:e instanceof Error?e.message:`Failed to destroy document`,variant:`destructive`})}},Jr=async t=>{if(!d)return;let n=c({title:`Destroying…`,description:`${t.length} document(s) and their backend copies`});try{let r=await S(e||d.id,t),i=new Set(r.successful?.filter(e=>e.docDeleted).map(e=>e.id)??[]);y(e=>e.filter(e=>!i.has(e.id))),k(e=>Math.max(0,e-i.size));let a=[r.successful?.length?`${r.successful.length} destroyed`:null,r.failed?.length?`${r.failed.length} failed`:null].filter(Boolean).join(`, `);r.failed?.length?n.fail({title:`Destroy incomplete`,description:a,variant:`destructive`}):n.done({title:`Destroyed`,description:a||`No documents destroyed`})}catch(e){n.fail({title:`Error`,description:e instanceof Error?e.message:`Failed to destroy documents`,variant:`destructive`})}},Yr=e=>{ct({documentIds:e,operation:`copy`,sourcePath:H,sourceTreeName:U}),window.dispatchEvent(new CustomEvent(`documents:clipboard`,{detail:{documentIds:e,operation:`copy`}})),s({title:`Copied`,description:`${e.length} document(s) copied to clipboard`})},Xr=e=>{ct({documentIds:e,operation:`cut`,sourcePath:H,sourceTreeName:U}),window.dispatchEvent(new CustomEvent(`documents:clipboard`,{detail:{documentIds:e,operation:`cut`}})),s({title:`Cut`,description:`${e.length} document(s) cut to clipboard`})},Zr=E(U),Qr=async(t,n,r={})=>{if(!e)return!1;let i=r.targetTreeName??U,a=r.targetTreeType??Zr,o=r.move??st?.operation===`cut`,s=c({title:o?`Moving…`:`Pasting…`,description:`${n.length} document(s) → "${t}"`});try{let c=await ae(e,t,n,i,a);if(c){R(e,i,t);let a=r.sourceTreeName||st?.sourceTreeName,c=r.sourcePath||st?.sourcePath;if((r.move??st?.operation===`cut`)&&c&&a){let t=E(a);await C(e,n,c,[],a,t),R(e,a,c),window.dispatchEvent(new CustomEvent(`workspace:documents:refresh`,{detail:{workspaceName:e,path:c,treeName:a}}))}s.done({title:`Success`,description:`${n.length} document(s) ${o?`moved`:`pasted`} to "${t}"`}),ct(null),window.dispatchEvent(new CustomEvent(`documents:clipboard`,{detail:null}));let l=performance.now();await vr(),console.info(`[paste] list refresh ${Math.round(performance.now()-l)} ms`),window.dispatchEvent(new CustomEvent(`workspace:documents:refresh`,{detail:{workspaceName:e,path:t,treeName:i}}))}else s.done();return c}catch(e){return s.fail({title:`Error`,description:e instanceof Error?e.message:`Failed to paste documents`,variant:`destructive`}),!1}},$r=async(t,n)=>{if(!e)return!1;try{let r=(await O(e,n,t,U,Zr)).length>0;return r&&(ke(e,U,n),s({title:`Success`,description:`Imported ${t.length} document(s) to "${n}"`})),r}catch(e){return s({title:`Error`,description:e instanceof Error?e.message:`Failed to import documents`,variant:`destructive`}),!1}},ei=async()=>{if(!d||rr===0||mr||pr.current||window.prompt(`Type PURGE to permanently delete all ${rr} matching documents across all pages.`)!==`PURGE`)return;pr.current=!0,fr(!0);let t=c({title:`Purging…`,description:`${rr} matching document(s)`});try{let n=await ye(e||d.id,sr,rr);n.deleted===n.requested?t.done({title:`Success`,description:`${n.deleted} document(s) purged.`}):t.fail({title:`Purge incomplete`,description:`${n.deleted} of ${n.requested} document(s) purged. Refresh and review the remaining results before retrying.`})}catch(e){t.fail({title:`Error`,description:e instanceof Error?e.message:`Failed to purge documents`,variant:`destructive`})}finally{R(e||d.id,U,H),await vr({silent:!0}),pr.current=!1,fr(!1)}},ti=()=>Dr(H,!0),ni=async()=>{if(!(!e||!ut||!pt.trim())){vt(!0);try{let t=pt.trim(),n=ut.parentPath,r=n===`/`?`/${t}`:`${n}/${t}`,i={...B.filters,features:{...B.filters.features,allOf:On}};await ve(e,r,U,ut.captureView?{metadata:{toolbox:i},querySpec:{features:i.features,filters:[...Fe(B.filters.timeline),...Pe(B.filters.geo)],query:Br||void 0,sort:B.filters.sort?.sortBy?B.filters.sort:null}}:{}),ft(null),ue(e,U);try{let t=await oe(e,U,{force:!0});on(t)}catch{}window.dispatchEvent(new CustomEvent(`workspace:tree:refresh`,{detail:{workspaceName:e}})),o(Be(e,r,U))}catch(e){s({title:`Error`,description:e instanceof Error?e.message:`Failed to create canvas`,variant:`destructive`})}finally{vt(!1)}}},ri=async()=>{if(!(!e||X!==`canvas`)){St(!0);try{let t=P||await T(e,H,U);Tt(t);let n=`${window.location.origin}${t.url}`;await navigator.clipboard?.writeText(n),s({title:`Public canvas link copied`,description:n})}catch(e){s({title:`Error`,description:e instanceof Error?e.message:`Failed to share canvas`,variant:`destructive`})}finally{St(!1)}}},ii=async()=>{if(P){St(!0);try{await _e(P.code),Tt(null),window.dispatchEvent(new CustomEvent(`workspace:tree:refresh`,{detail:{workspaceName:e,treeName:U}})),s({title:`Canvas unshared`,description:`The public link no longer works.`})}catch(e){s({title:`Error`,description:e instanceof Error?e.message:`Failed to unshare canvas`,variant:`destructive`})}finally{St(!1)}}},ai=async()=>{if(!e||X!==`canvas`||H===`/`)return;let t=Mn?.label||H.split(`/`).pop()||`canvas`,n=P?` Its public link will stop working.`:``;if(window.confirm(`Delete canvas "${t}"? This cannot be undone.${n}`)){wt(!0);try{if(P)await _e(P.code),Tt(null);else if(Y?.locked){s({title:`Canvas is locked`,description:`Unlock it before deleting.`,variant:`destructive`});return}await w(e,H,!1,U);let n=H.split(`/`).filter(Boolean);n.pop();let r=n.length?`/${n.join(`/`)}`:`/`;window.dispatchEvent(new CustomEvent(`workspace:tree:refresh`,{detail:{workspaceName:e,treeName:U}})),o(Be(e,r,U)),s({title:`Canvas deleted`,description:`"${t}" was removed.`})}catch(e){s({title:`Error`,description:e instanceof Error?e.message:`Failed to delete canvas`,variant:`destructive`})}finally{wt(!1)}}},oi=(0,M.useCallback)(async t=>{if(!e||!J)return;let n={treeName:U,path:H},r=ln===`left`?n:J,i=ln===`left`?J:n,a=ln===`left`?dn:gn;if(a.length===0){s({title:`Nothing selected`,description:`Tick documents in the focused pane first.`});return}let o=E(i.treeName),l=c({title:t?`Moving…`:`Copying…`,description:`${a.length} document(s) → "${i.path}"`});try{if(!await ae(e,i.path,a,i.treeName,o)){l.done();return}if(R(e,i.treeName,i.path),t){let t=E(r.treeName);await C(e,a,r.path,[],r.treeName,t),R(e,r.treeName,r.path)}[r,i].forEach(t=>window.dispatchEvent(new CustomEvent(`workspace:documents:refresh`,{detail:{workspaceName:e,path:t.path,treeName:t.treeName}}))),l.done({title:t?`Moved`:`Copied`,description:`${a.length} document(s) → "${i.path}"`})}catch(e){l.fail({title:`Error`,description:e instanceof Error?e.message:`Transfer failed`,variant:`destructive`})}},[e,J,ln,U,H,dn,gn,s,c]);if((0,M.useEffect)(()=>{if(!J)return;let e=e=>{if(e.key!==`F5`&&e.key!==`F6`)return;let t=e.target;t.tagName!==`INPUT`&&t.tagName!==`TEXTAREA`&&(e.preventDefault(),oi(e.key===`F6`))};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[J,oi]),p)return(0,N.jsx)(`div`,{className:`flex items-center justify-center h-full`,children:(0,N.jsxs)(`div`,{className:`text-center space-y-2`,children:[(0,N.jsx)(`div`,{className:`animate-spin rounded-full h-8 w-8 border-b-2 border-primary mx-auto`}),(0,N.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`Loading workspace...`})]})});if(!d)return(0,N.jsx)(`div`,{className:`flex items-center justify-center h-full text-muted-foreground`,children:`Workspace not found.`});let si=X===`canvas`&&!G&&!!Y,ci=!si&&!W&&bn?(0,N.jsx)(Je,{views:Tn,activeId:En,onSelect:kn,onSave:An,accentColor:Me(d.color),onOpenToSide:e=>{sn({treeName:U,path:H,viewId:e}),un(`right`)}}):void 0,li=$t||d.status!==`active`?(0,N.jsxs)(N.Fragment,{children:[$t&&(0,N.jsx)(`button`,{type:`button`,onClick:()=>{tn(!en),I(1)},"aria-pressed":en,className:g(`min-h-10 rounded-md border px-2 text-xs`,en&&`bg-warning/15 text-warning`),children:`Unfiled only`}),d.status!==`active`&&(0,N.jsx)(`button`,{type:`button`,onClick:Hr,disabled:at,className:`min-h-10 rounded-md border px-2 text-xs`,children:at?`Starting…`:`Start`})]}):void 0,ui=we(U,H)?H===`/Trash`?(0,N.jsx)(`div`,{className:`h-full overflow-auto p-4`,children:(0,N.jsx)(nt,{workspaceName:e||d.id})}):(0,N.jsx)(lt,{workspace:e||d.id,path:H,onNavigate:t=>o(Be(e,t,`backends`))},e):(0,N.jsx)(qe,{navigationTabs:ci,navigationActions:li,onBack:hn,accentColor:Me(d.color),urlType:G?E(U)===`directory`?`${U}-layer`:`context-layer`:X===`canvas`?`canvas`:E(U)===`directory`?U:`context`,urlDisplay:Hn,contextPath:H,treeName:U,workspaceId:e||d.id,workspaceLabel:d.label||d.name,workspaceIcon:d.icon,documentSchema:Dn,documents:or,isLoading:re,totalCount:rr,currentPage:F,pageSize:L,onPageChange:I,onPageSizeChange:e=>{Mt(e),I(1)},onRemoveDocument:H===`/`?void 0:Ur,onDeleteDocument:Wr,onDestroyDocument:qr,onRemoveDocuments:H===`/`?void 0:Gr,onDeleteDocuments:Kr,onDestroyDocuments:Jr,onCopyDocuments:Yr,onCutDocuments:Xr,onPasteDocuments:W?void 0:Qr,onImportDocuments:W?void 0:$r,onSelectionChange:fn,onBrowseTree:()=>mn(`workspaces`,`detail`,e??null),onBrowseWorkspaces:()=>pn(`workspaces`),onNavigatePath:t=>o(Be(e,t,U)),folders:yn,onOpenFolder:t=>o(Be(e,ze(t),U)),scope:j,onScopeChange:it,pastedDocumentIds:st?.documentIds,linkTree:q,onPurgeDocuments:W?void 0:ei,disablePurgeDocuments:mr,canvasInfo:Mn??void 0,isCanvasPinned:Rn,onTogglePinCanvas:$?Vn:void 0,onSaveAsCanvas:q&&X!==`canvas`&&!G&&!W?ti:void 0,onShareCanvas:X===`canvas`&&!G?ri:void 0,onUnshareCanvas:P?ii:void 0,onDeleteCanvas:X===`canvas`&&!G?ai:void 0,isSharingCanvas:yt,isDeletingCanvas:Ct,isCanvasShared:!!P,isCanvasLocked:!!Y?.locked,backendSearchQueries:z,onBackendSearch:Rr,serverSort:B.filters.sort,onServerSortChange:Rt,onRemoveBackendQuery:zr,canSaveChanges:Vr,isSavingChanges:B.isSaving,onSaveChanges:Lt,contentBanner:A&&Ee?(0,N.jsx)(Dt,{data:Ee,className:`mb-3`}):null,children:si&&Y?(0,N.jsx)(xe,{workspaceId:e||d.id,treeName:U,path:H,layerId:Y.id,querySpec:Y.querySpec,metadata:Y.metadata,isLocked:!!Y.locked,fetchDocuments:B.isDirty?Wn:void 0}):!W&&Q.kind===`columns`?(0,N.jsx)(Qe,{documents:or,workspaceId:e||d.id,columns:Q.columns??[],onColumnsChange:e=>An(Tn.map(t=>t.id===Q.id?{...t,columns:e}:t))}):!W&&Q.kind===`app`&&Q.app&&Q.app!==`notes`?(0,N.jsx)(Xe,{app:Q.app,workspaceId:e||d.id,treeName:U,path:H}):null});return(0,N.jsxs)(Ue,{workspaceId:e||d.id,treeName:U,path:H,headerOnly:!0,className:`relative flex flex-col h-full min-h-0`,children:[(0,N.jsx)(dt,{workspaceId:d.id,workspaceName:d.label||d.name},d.id),we(U,H)&&(0,N.jsx)(Se,{workspace:d.label||d.name,workspaceIcon:d.icon,tree:U,path:H,onBack:hn,onBrowseTree:()=>mn(`workspaces`,`detail`,e||d.id),onBrowseWorkspaces:()=>pn(`workspaces`),onNavigatePath:t=>o(Be(e,t,U)),accentColor:Me(d.color)}),ut&&(0,N.jsx)(`div`,{className:`shrink-0 px-2 pt-2`,children:(0,N.jsx)(Ge,{title:`New canvas`,onClose:()=>ft(null),children:(0,N.jsxs)(`form`,{onSubmit:e=>{e.preventDefault(),ni()},className:`space-y-4`,children:[(0,N.jsxs)(`div`,{className:`grid gap-4 md:grid-cols-2`,children:[(0,N.jsxs)(`div`,{children:[(0,N.jsx)(`label`,{htmlFor:`canvas-name`,className:`mb-1 block text-sm font-medium`,children:`Name`}),(0,N.jsx)(`input`,{id:`canvas-name`,className:`w-full rounded-md border bg-background px-3 py-2 text-sm focus:outline-none focus:ring-1 focus:ring-primary`,placeholder:`Canvas name…`,value:pt,onChange:e=>mt(e.target.value),onKeyDown:e=>{e.key===`Escape`&&ft(null)},autoFocus:!0})]}),(0,N.jsxs)(`div`,{children:[(0,N.jsx)(`span`,{className:`mb-1 block text-sm font-medium`,children:`Parent path`}),(0,N.jsx)(`div`,{className:`flex h-10 items-center rounded-md bg-muted px-3 font-mono text-sm text-muted-foreground`,children:ut.parentPath===`/`?`/`:ut.parentPath})]})]}),(0,N.jsxs)(`label`,{className:`flex items-start gap-2 text-sm`,children:[(0,N.jsx)(`input`,{type:`checkbox`,className:`mt-0.5`,checked:ut.captureView,onChange:e=>ft({...ut,captureView:e.target.checked})}),(0,N.jsxs)(`span`,{children:[`Capture the current view`,(0,N.jsx)(`span`,{className:`block text-xs text-muted-foreground`,children:`Freezes the active filters, search and sort into the canvas.`})]})]}),(0,N.jsxs)(`div`,{className:`flex gap-2`,children:[(0,N.jsx)(ee,{type:`submit`,disabled:!pt.trim()||ht,children:ht?`Creating…`:`Create canvas`}),(0,N.jsx)(ee,{type:`button`,variant:`outline`,onClick:()=>ft(null),children:`Cancel`})]})]})})}),(0,N.jsxs)(`div`,{"data-canvas-panes":!0,className:`flex-1 min-h-0 flex gap-2`,children:[(0,N.jsx)(`div`,{"data-canvas-pane":!0,className:g(`flex-1 min-w-0 bg-background overflow-hidden`,J&&(ln===`left`?`ring-2 ring-primary`:`ring-1 ring-primary/20`)),onMouseDown:e=>{e.target.closest(`button,input,textarea,select,a`)||un(`left`)},children:ui}),J&&e&&(0,N.jsx)(Pt,{workspaceName:e,workspaceLabel:d.label||d.name,workspaceIcon:d.icon,pane:J,isFocused:ln===`right`,clipboard:st,setClipboard:ct,onFocus:()=>un(`right`),onSelectionChange:_n,onNavigate:e=>sn(t=>t&&{...t,path:e,viewId:void 0}),onClose:()=>{sn(null),un(`left`),_n([])}})]})]})}function Nt(e,t){if(!e||t===`/`)return e;let n=e;for(let e of t.split(`/`).filter(Boolean))if(n=n?.children?.find(t=>t.name===e)??null,!n)return null;return n}function Pt({workspaceName:e,workspaceLabel:t,workspaceIcon:n,pane:r,isFocused:i=!1,clipboard:a,setClipboard:o,onFocus:s,onSelectionChange:c,onNavigate:l,onClose:u}){let{openM1Drawer:d,openM2Drawer:f}=Ve(),{showToast:p,showProgress:m}=ne(),[h,ee]=(0,M.useState)(null),[_,te]=(0,M.useState)([]),[v,y]=(0,M.useState)(!1),[re,b]=(0,M.useState)(0),[x,ie]=(0,M.useState)(1),[w,se]=(0,M.useState)(50),T=E(r.treeName),ce=Nt(h,r.path),le=ce?.type===`canvas`,D=(0,M.useMemo)(()=>et(h,r.path),[h,r.path]),O=r.viewId?$e(ce?.metadata).find(e=>e.id===r.viewId)??null:null,fe=`${e}://${r.path===`/`?``:r.path.replace(/^\//,``)}`,pe=Ze(O),me=(0,M.useCallback)(async()=>{if(we(r.treeName,r.path)){te([]),b(0),y(!1);return}let t=kt(e,r.treeName,r.path,x,w,``,pe??``),n=Ot.get(t);if(n){te(n.documents),b(n.totalCount);return}y(!0);try{let n=await de(e,r.path,pe?[pe]:[],{limit:w,page:x,treeName:r.treeName,treeType:T}),i=n.payload||[],a=n.totalCount||n.count||0;te(i),b(a),Ot.set(t,{documents:i,totalCount:a})}catch(e){p({title:`Error`,description:e instanceof Error?e.message:`Failed to fetch side pane documents`,variant:`destructive`}),te([]),b(0)}finally{y(!1)}},[e,r.path,r.treeName,T,w,x,p,pe]);(0,M.useEffect)(()=>{let t=!1,n=0,i=!1,a=(a=!1)=>{let o=++n;a&&ue(e,r.treeName),oe(e,r.treeName).then(e=>{!t&&o===n&&(i=!0,ee(e))}).catch(()=>{!t&&o===n&&!i&&ee(null)})};a(!1);let o=t=>{let n=t.detail;n?.workspaceName&&n.workspaceName!==e||n?.treeName&&n.treeName!==r.treeName||a(!n?.cacheInvalidated)};return window.addEventListener(`workspace:tree:refresh`,o),()=>{t=!0,window.removeEventListener(`workspace:tree:refresh`,o)}},[e,r.treeName]),(0,M.useEffect)(()=>{me()},[me]),(0,M.useEffect)(()=>{let t=t=>{let n=t.detail;n?.workspaceName&&n.workspaceName!==e||(jt(e,n),xt(bt(n),{tree:r.treeName,kind:E(r.treeName),path:r.path})&&(R(e,r.treeName,r.path),me()))};return window.addEventListener(`workspace:documents:refresh`,t),()=>window.removeEventListener(`workspace:documents:refresh`,t)},[me,e,r.treeName,r.path]);let he=(0,M.useCallback)(async(t,n,i={})=>{let s=i.targetTreeName??r.treeName,c=i.targetTreeType??T,l=i.move??a?.operation===`cut`,u=m({title:l?`Moving…`:`Pasting…`,description:`${n.length} document(s) → "${t}"`});try{let r=await ae(e,t,n,s,c);if(r){R(e,s,t);let r=i.sourcePath||a?.sourcePath,c=i.sourceTreeName||a?.sourceTreeName;if((i.move??a?.operation===`cut`)&&r&&c){let t=E(c);await C(e,n,r,[],c,t),R(e,c,r),window.dispatchEvent(new CustomEvent(`workspace:documents:refresh`,{detail:{workspaceName:e,path:r,treeName:c}}))}u.done({title:`Success`,description:`${n.length} document(s) ${l?`moved`:`pasted`} to "${t}"`}),o(null),await me(),window.dispatchEvent(new CustomEvent(`workspace:documents:refresh`,{detail:{workspaceName:e,path:t,treeName:s}}))}else u.done();return r}catch(e){return u.fail({title:`Error`,description:e instanceof Error?e.message:`Failed to paste documents`,variant:`destructive`}),!1}},[e,r.treeName,T,me,m,a,o]),_e=(0,M.useCallback)(()=>{R(e,r.treeName,r.path),me()},[e,r.treeName,r.path,me]),ve=(0,M.useCallback)(async t=>{let n=m({title:`Removing…`,description:`${t.length} document(s) from "${r.path}"`});try{await C(e,t,r.path,[],r.treeName,T),_e(),n.done({title:`Removed`,description:`${t.length} document(s) removed from "${r.path}"`})}catch(e){n.fail({title:`Error`,description:e instanceof Error?e.message:`Failed to remove documents`,variant:`destructive`})}},[e,r.path,r.treeName,T,_e,m]),ye=(0,M.useCallback)(async t=>{let n=m({title:`Deleting…`,description:`${t.length} document(s)`});try{await ge(e,t,r.path,[],r.treeName,T),_e(),n.done({title:`Deleted`,description:`${t.length} document(s) deleted.`})}catch(e){n.fail({title:`Error`,description:e instanceof Error?e.message:`Failed to delete documents`,variant:`destructive`})}},[e,r.path,r.treeName,T,_e,m]),be=(0,M.useCallback)(async t=>{let n=m({title:`Destroying…`,description:`${t.length} document(s) and their backend copies`});try{let r=await S(e,t);if(r.failed?.length&&!r.successful?.length){n.fail({title:`Error`,description:r.failed[0].reason,variant:`destructive`});return}_e();let i=`${r.successful?.length??0} document(s) destroyed${r.failed?.length?` · ${r.failed.length} failed`:``}.`;r.failed?.length?n.fail({title:`Destroy incomplete`,description:i,variant:`destructive`}):n.done({title:`Destroyed`,description:i})}catch(e){n.fail({title:`Error`,description:e instanceof Error?e.message:`Failed to destroy documents`,variant:`destructive`})}},[e,_e,m]);return(0,N.jsxs)(`div`,{className:g(`relative flex-1 min-w-0 rounded-(--sheet-radius) border bg-background overflow-hidden`,i?`ring-2 ring-primary`:`ring-1 ring-primary/20`),onMouseDown:e=>{e.target.closest(`button,input,textarea,select,a`)||s()},children:[u&&(0,N.jsx)(`button`,{type:`button`,onClick:u,className:`absolute right-2 top-2 z-10 px-2 py-1 text-xs rounded-md border bg-background/90 hover:bg-accent`,children:`Close`}),we(r.treeName,r.path)?r.path===`/Trash`?(0,N.jsx)(`div`,{className:`h-full overflow-auto p-4`,children:(0,N.jsx)(nt,{workspaceName:e})}):(0,N.jsx)(lt,{workspace:e,path:r.path,onNavigate:l||(()=>{})}):(0,N.jsx)(qe,{frameContent:!1,onBrowseWorkspaces:()=>d(`workspaces`),onBrowseTree:()=>f(`workspaces`,`detail`,e),urlType:le?`canvas`:T===`directory`?r.treeName:`context`,urlDisplay:fe,contextPath:r.path,treeName:r.treeName,workspaceId:e,workspaceLabel:t,workspaceIcon:n,documentSchema:pe,documents:_,isLoading:v,totalCount:re,currentPage:x,pageSize:w,onPageChange:ie,onPageSizeChange:e=>{se(e),ie(1)},onRemoveDocument:r.path===`/`?void 0:e=>ve([e]),onRemoveDocuments:r.path===`/`?void 0:ve,onDeleteDocument:e=>ye([e]),onDeleteDocuments:ye,onDestroyDocument:e=>be([e]),onDestroyDocuments:be,onCopyDocuments:e=>{o({documentIds:e,operation:`copy`,sourcePath:r.path,sourceTreeName:r.treeName}),window.dispatchEvent(new CustomEvent(`documents:clipboard`,{detail:{documentIds:e,operation:`copy`}}))},onCutDocuments:e=>{o({documentIds:e,operation:`cut`,sourcePath:r.path,sourceTreeName:r.treeName}),window.dispatchEvent(new CustomEvent(`documents:clipboard`,{detail:{documentIds:e,operation:`cut`}}))},onPasteDocuments:r.treeName===`backends`?void 0:he,onSelectionChange:c,pastedDocumentIds:a?.documentIds,linkTree:h,folders:D,onOpenFolder:l,onNavigatePath:l,canvasInfo:le?{label:ce?.label,description:ce?.description,color:ce?.color}:void 0,children:O?.kind===`columns`?(0,N.jsx)(Qe,{documents:_,workspaceId:e,columns:O.columns??[],onColumnsChange:()=>{},readOnly:!0}):O?.kind===`app`&&O.app&&O.app!==`notes`?(0,N.jsx)(Xe,{app:O.app,workspaceId:e,treeName:r.treeName,path:r.path}):null})]})}export{Mt as default};