@augmentd-labs/canvas-web 2.26.26 → 2.26.28

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 (114) hide show
  1. package/dist/assets/CalendarApplet-BPEp7Vc4.js +1 -0
  2. package/dist/assets/{DocumentBodyEditor-8DNmOBS0.js → DocumentBodyEditor-DRFQgBNB.js} +1 -1
  3. package/dist/assets/{DocumentIcon-x299QNu_.js → DocumentIcon-ByDAILhm.js} +1 -1
  4. package/dist/assets/{EditorOverlay-Cv1MaTok.js → EditorOverlay-DpQKmxkR.js} +1 -1
  5. package/dist/assets/{FileForm-CqJpRbXv.js → FileForm-BqTiW78K.js} +1 -1
  6. package/dist/assets/{FiltersApplet-BJALOBRh.js → FiltersApplet-DCTdYOjb.js} +1 -1
  7. package/dist/assets/{HomeFab-Chvwu8rQ.js → HomeFab-DG6YVz9N.js} +2 -2
  8. package/dist/assets/{IdentityFields-Bti7ojF3.js → IdentityFields-D13Y3wzc.js} +1 -1
  9. package/dist/assets/{LensApplet-Ckl0M4Wi.js → LensApplet-fVzXJVQr.js} +1 -1
  10. package/dist/assets/LinkToCard-bUXz_atc.js +1 -0
  11. package/dist/assets/{MarkdownEditor-CNY-VmKb.js → MarkdownEditor-Dnyez7VT.js} +2 -2
  12. package/dist/assets/{MessageComposerDialog-gbD0Gu_b.js → MessageComposerDialog-BKGlI7jO.js} +1 -1
  13. package/dist/assets/{NextShell-UX4Efo0u.js → NextShell-D4248rEY.js} +1 -1
  14. package/dist/assets/{NotesApplet-tNMaEcoj.js → NotesApplet-CQ92to3I.js} +1 -1
  15. package/dist/assets/ObjectPropertiesCard-CkcQp_zW.js +8 -0
  16. package/dist/assets/{PathPickerField-fZazwxCN.js → PathPickerField-B8MsG6xg.js} +1 -1
  17. package/dist/assets/{PickDocumentsCard-DamtV7fN.js → PickDocumentsCard-BQwJdHA9.js} +1 -1
  18. package/dist/assets/{SketchApplet-DDIg411i.js → SketchApplet-DbuBdGzr.js} +1 -1
  19. package/dist/assets/{SketchEditor-CKPPuZt3.js → SketchEditor-BGzrlfJR.js} +1 -1
  20. package/dist/assets/{TerminalApplet-wGJG1PPc.js → TerminalApplet-Dsv5Sktn.js} +1 -1
  21. package/dist/assets/{TextDocumentEditor-CRre32cj.js → TextDocumentEditor-Bnk3_hqG.js} +1 -1
  22. package/dist/assets/{TodosApplet-CleBd4uU.js → TodosApplet-CW69DfHJ.js} +1 -1
  23. package/dist/assets/{TodosWidget-CxiqmDuJ.js → TodosWidget-C3Ux5gnY.js} +1 -1
  24. package/dist/assets/{UploadProgressList-DRJzjy6A.js → UploadProgressList-BHxfFhkG.js} +1 -1
  25. package/dist/assets/{_agentId_-sMYqsnQk.js → _agentId_-hCidK3Gt.js} +0 -0
  26. package/dist/assets/{_contextId_-DRvqFeiU.js → _contextId_-DE4yZzvm.js} +1 -1
  27. package/dist/assets/{_workspaceName_-DqFTMP44.js → _workspaceName_-ewVVfjoI.js} +1 -1
  28. package/dist/assets/{about-DbGpwqCH.js → about--_m1Uqkl.js} +1 -1
  29. package/dist/assets/{add-DsH8MVg6.js → add-7Qd6XnoJ.js} +1 -1
  30. package/dist/assets/agents-CuRC26Ih.js +1 -0
  31. package/dist/assets/{agents-DlLq0q2s.js → agents-DEJU4O1Z.js} +1 -1
  32. package/dist/assets/{alert-dialog-izlVMXfa.js → alert-dialog-CShuAcnP.js} +1 -1
  33. package/dist/assets/{api-tokens-DDH7LMJ7.js → api-tokens-CmHhwd58.js} +1 -1
  34. package/dist/assets/{appearance-CN8I4_GQ.js → appearance-Cdb_NAoV.js} +1 -1
  35. package/dist/assets/{applet-target-C_gBgU-Z.js → applet-target-21tr63qk.js} +1 -1
  36. package/dist/assets/{apps-CvInUZwB.js → apps-k3O5qSWN.js} +1 -1
  37. package/dist/assets/{auth-HZNJB4wv.js → auth-_bmIEN02.js} +1 -1
  38. package/dist/assets/backend-sync-progress-CRHe59pS.js +7 -0
  39. package/dist/assets/{button-SgR3GVvV.js → button-Bum-POPT.js} +1 -1
  40. package/dist/assets/content-app-view-Bn7PuCxV.js +1 -0
  41. package/dist/assets/{context-DQoZFMDQ.js → context-DVlMC9Bk.js} +1 -1
  42. package/dist/assets/{contexts-CvMtPd1N2.js → contexts-DSBwT_Ml2.js} +1 -1
  43. package/dist/assets/{contexts-Ef3fHwv6.js → contexts-Dtl9oERX.js} +1 -1
  44. package/dist/assets/{date-time-picker-DebNUTx3.js → date-time-picker-S055eVuO.js} +1 -1
  45. package/dist/assets/{devices-C3gLuNDv.js → devices-CmVlYbam.js} +1 -1
  46. package/dist/assets/{document-DOp6AbOi.js → document-RoetUSIa.js} +1 -1
  47. package/dist/assets/document-list-CwkeIVAT.js +2 -0
  48. package/dist/assets/{embedding-B5JiUA9X.js → embedding-2EjzoVFT.js} +1 -1
  49. package/dist/assets/{embedding-B7cWrpy0.js → embedding-BqI3l5RB.js} +1 -1
  50. package/dist/assets/{form-panel-C34lByEH.js → form-panel-DZj3WZ3z.js} +1 -1
  51. package/dist/assets/{home-CFZRa_Mu.js → home-Bzy-sAMn.js} +1 -1
  52. package/dist/assets/index-QzZxj0Ty.js +16 -0
  53. package/dist/assets/index-XDD8pFI_.css +2 -0
  54. package/dist/assets/{inferd-config-editor--MDmN_7w.js → inferd-config-editor-CyDCQJRs.js} +1 -1
  55. package/dist/assets/{key-bindings-Dfa7ehDw.js → key-bindings-Dg3p3DnN.js} +1 -1
  56. package/dist/assets/{label-Dn4gCMcc.js → label-DJc8-3CQ.js} +1 -1
  57. package/dist/assets/{lazy-editor-BSRnneOo.js → lazy-editor-Bdm5JEXv.js} +2 -2
  58. package/dist/assets/{logs-Czn2sPeP.js → logs-DUeiDqCX.js} +1 -1
  59. package/dist/assets/{offline-COOUcZsG.js → offline-CfiX0_wL.js} +1 -1
  60. package/dist/assets/{page-header-DkOHw0g-.js → page-header-BoCaZiqu.js} +1 -1
  61. package/dist/assets/{public-share-g_wBd6BW.js → public-share-C3a_DycQ.js} +1 -1
  62. package/dist/assets/{query-debug-CrPsUwT-.js → query-debug-Bb-VKova.js} +1 -1
  63. package/dist/assets/registry-DxcaO-Vq.js +2 -0
  64. package/dist/assets/{remotes-CdEU1Y5l.js → remotes-BjjlqN_M.js} +1 -1
  65. package/dist/assets/{roles-BpVWTMmp.js → roles-BHJYWaBs.js} +1 -1
  66. package/dist/assets/{roles-Bo9GZdOk.js → roles-DXrNmLZt.js} +1 -1
  67. package/dist/assets/settings-BOmqY3dt.js +1 -0
  68. package/dist/assets/{settings-FiiJ5QFa.js → settings-CImTlDKY.js} +1 -1
  69. package/dist/assets/settings-CxUUEOjw.js +16 -0
  70. package/dist/assets/{settings-DhVz_Osu.js → settings-DynBIwbc.js} +1 -1
  71. package/dist/assets/{share-target-fpk-pz15.js → share-target-DmROSmKt.js} +1 -1
  72. package/dist/assets/{shared-BQZGA3ph.js → shared-D6K4WqN7.js} +1 -1
  73. package/dist/assets/{shared-CCCuTYCU.js → shared-qsV5Q5JG.js} +1 -1
  74. package/dist/assets/sketch-lazy-QRuqtP92.js +2 -0
  75. package/dist/assets/{subtree-transfer-dialog-ChBI5llU.js → subtree-transfer-dialog-BN9xBB9n.js} +1 -1
  76. package/dist/assets/{text-documents-0P9jkIpu.js → text-documents-BJ17V0oY.js} +2 -2
  77. package/dist/assets/ui-76Hw0NU_.js +41 -0
  78. package/dist/assets/{use-applet-docs-D5eXpITp.js → use-applet-docs-DD74tPAU.js} +1 -1
  79. package/dist/assets/{use-applet-target-gXPvZGgx.js → use-applet-target-M1Q8sd1B.js} +1 -1
  80. package/dist/assets/{use-canvas-pins-BvN6Gw6f.js → use-canvas-pins-r3a-TbLQ.js} +2 -2
  81. package/dist/assets/{use-menu-BiJ8N7sS.js → use-menu-CaiLyPdw.js} +1 -1
  82. package/dist/assets/use-settings-back-DE0SPb7h.js +1 -0
  83. package/dist/assets/{use-sortable-data-BW_0sXBs.js → use-sortable-data-W2inLcb5.js} +1 -1
  84. package/dist/assets/{use-workspace-identity-BCrrvfeE.js → use-workspace-identity-B_8AUozT.js} +1 -1
  85. package/dist/assets/{useAddTarget-CqnDU0Om.js → useAddTarget-D9S8RxCR.js} +1 -1
  86. package/dist/assets/{useAgentModels-CwNiA-Ak.js → useAgentModels-CITtKWhW.js} +1 -1
  87. package/dist/assets/{useDocumentThumbnail-DunxmU1A.js → useDocumentThumbnail-BpvX3fx0.js} +1 -1
  88. package/dist/assets/{useEditNoteFields-BehI0vog.js → useEditNoteFields-Dlr5PRFm.js} +1 -1
  89. package/dist/assets/{users-CKz9kOoR.js → users-DInwKAxz.js} +1 -1
  90. package/dist/assets/workspace-BuoZwRL5.js +1 -0
  91. package/dist/assets/{workspace-area-menu-C0-X-FpD.js → workspace-area-menu-CT1Yh2i4.js} +1 -1
  92. package/dist/assets/{workspace-content-gate-9okuA7J7.js → workspace-content-gate-CaCJlWnb.js} +1 -1
  93. package/dist/assets/{workspace-import-form-aR-DwHf6.js → workspace-import-form-g5tSCc9q.js} +1 -1
  94. package/dist/assets/workspaces-Bd0L13A9.js +1 -0
  95. package/dist/assets/{workspaces-Da_hUIj3.js → workspaces-p959p9BR.js} +1 -1
  96. package/dist/index.html +36 -36
  97. package/dist/sw.js +1 -1
  98. package/package.json +2 -2
  99. package/dist/assets/LinkToCard-5dg0jvSY.js +0 -1
  100. package/dist/assets/ObjectPropertiesCard-BIBMvx_i.js +0 -8
  101. package/dist/assets/agents-BBKnR8_O.js +0 -1
  102. package/dist/assets/backend-sync-progress-pZrhQPk3.js +0 -7
  103. package/dist/assets/content-app-view-BGg1GOMt.js +0 -1
  104. package/dist/assets/document-list-DKOU9Kcc.js +0 -2
  105. package/dist/assets/index-B-PM5mzp.css +0 -2
  106. package/dist/assets/index-BytAmMhU.js +0 -16
  107. package/dist/assets/registry--2kt6I6T.js +0 -2
  108. package/dist/assets/settings-BOHindnt.js +0 -14
  109. package/dist/assets/settings-N3fbO22m.js +0 -1
  110. package/dist/assets/sketch-lazy-C4pjV1WK.js +0 -2
  111. package/dist/assets/ui-Byg1cZDr.js +0 -41
  112. package/dist/assets/use-settings-back-CQauYjQ4.js +0 -1
  113. package/dist/assets/workspace-CrSpR4xf.js +0 -1
  114. package/dist/assets/workspaces-By3jZzrz.js +0 -1
@@ -1 +1 @@
1
- import{c as e,t}from"./api-CA6WiiYM.js";import{Dn as n,En as r}from"./workspace-CrSpR4xf.js";var i=`contexts:deleted`;function a(e,t){return e.id===t.id?t.ownerId===void 0?e.isShared!==!0&&e.type!==`shared`:e.userId===t.ownerId:!1}async function o(){try{let n=await t.get(e.contexts);return Array.isArray(n)?n:(console.warn(`listContexts: response.payload is not an array:`,n),[])}catch(e){throw console.error(`Failed to list contexts:`,e),e}}function s(e,t){return t?`${e}${e.includes(`?`)?`&`:`?`}ownerId=${encodeURIComponent(t)}`:e}async function c(n,r){try{let i=s(`${e.contexts}/${n}`,r),a=await t.get(i);if(a&&a)return a;throw Error(`Context data not found in API response`)}catch(e){throw console.error(`Failed to get context ${n}:`,e),e}}async function l(n){try{let r=await t.post(e.contexts,n);if(r&&r&&r.context)return r.context;throw Error(`Created context data not found in API response`)}catch(e){throw console.error(`Failed to create context:`,e),e}}async function u(n,r,i){try{let a=s(`${e.contexts}/${n}`,i),o=await t.put(a,r);if(o?.context)return o.context;throw Error(`Updated context data not found in API response`)}catch(e){throw console.error(`Failed to patch context ${n}:`,e),e}}async function d(n,r,i){try{let a=s(`${e.contexts}/${n}`,i),o=await t.put(a,r);if(o?.context)return o.context;throw Error(`Updated context data not found in API response`)}catch(e){throw console.error(`Failed to update context ${n}:`,e),e}}async function f(n,r,i,a){try{let o=s(`${e.contexts}/${n}/url`,i),c=await t.post(o,{url:r,...a?{treeName:a}:{}});if(c&&c&&c.url)return{url:c.url,treeId:c.treeId};throw Error(`Updated context data not found in API response`)}catch(e){throw console.error(`Failed to update context URL for ${n}:`,e),e}}async function p(n,r){try{let a=s(`${e.contexts}/${n}`,r);await t.delete(a),window.dispatchEvent(new CustomEvent(i,{detail:{id:n,ownerId:r}}))}catch(e){throw console.error(`Failed to delete context ${n}:`,e),e}}async function m(i,a=[],o=[],s={},c){try{if(s.ids?.length===0)return Object.assign([],{count:0,totalCount:0});if(n(s.sortBy)){let e=await r(s,async e=>{let t=await m(i,a,o,{...s,...e,sortBy:void 0,order:`asc`},c);return{payload:t,count:t.count,totalCount:t.totalCount}});return Object.assign(e.payload,{count:e.count,totalCount:e.totalCount})}let l=new URLSearchParams;s.geoSelection&&(l.set(`geoSelection`,JSON.stringify(s.geoSelection)),l.set(`includeUnlocated`,String(s.includeUnlocated===!0))),s.ids?.forEach(e=>l.append(`ids`,String(e))),a.forEach(e=>l.append(`allOf`,e)),o.forEach(e=>l.append(`filters`,e)),(s.anyOf||[]).filter(Boolean).forEach(e=>l.append(`anyOf`,e)),(s.noneOf||[]).filter(Boolean).forEach(e=>l.append(`noneOf`,e)),s.sortBy&&l.append(`sortBy`,s.sortBy),s.order&&l.append(`order`,s.order),s.applyContextSpec===!1&&l.append(`applyContextSpec`,`false`),c&&l.append(`ownerId`,c),s.includeServerContext!==void 0&&l.append(`includeServerContext`,s.includeServerContext.toString()),s.includeClientContext!==void 0&&l.append(`includeClientContext`,s.includeClientContext.toString()),s.limit!==void 0&&l.append(`limit`,s.limit.toString()),s.offset!==void 0&&l.append(`offset`,s.offset.toString()),s.page!==void 0&&l.append(`page`,s.page.toString()),(s.queries&&s.queries.length?s.queries:s.q?[s.q]:[]).map(e=>e.trim()).filter(Boolean).forEach(e=>l.append(`q`,e));let u=`${e.contexts}/${i}/documents${l.toString()?`?`+l.toString():``}`,d=await t.getEnvelope(u,{signal:s.signal}),f=d.payload;if(Array.isArray(f)){let e=f;return e.count=d.count??void 0,e.totalCount=d.totalCount??void 0,e}return console.warn(`getContextDocuments: payload is not an array:`,f),[]}catch(e){throw console.error(`Failed to get context documents for ${i}:`,e),e}}async function h(n){let r=await t.get(`${e.contexts}/${n}/shares`);return Array.isArray(r)?r:[]}async function g(n,r,i){try{return{message:(await t.post(`${e.contexts}/${n}/shares`,{userEmail:r,accessLevel:i})).message||`Context access granted`}}catch(e){throw console.error(`Failed to grant context access:`,e),e}}async function _(n,r){try{return{message:(await t.delete(`${e.contexts}/${n}/shares/${encodeURIComponent(r)}`)).message||`Context access revoked`}}catch(e){throw console.error(`Failed to revoke context access:`,e),e}}async function v(n,r){try{let i=s(`${e.contexts}/${n}/tree`,r),a=await t.get(i);if(a)return a;throw Error(`Context tree data not found in API response`)}catch(e){throw console.error(`Failed to get context tree for ${n}:`,e),e}}async function y(n,r,i,a){try{let a=Array.isArray(r)?r:[r],o=new URLSearchParams,c=`${e.contexts}/${n}/documents/remove${o.toString()?`?${o.toString()}`:``}`;return{message:await t.delete(s(c,i),{body:JSON.stringify(a),headers:{"Content-Type":`application/json`}})||`Documents removed from context`}}catch(e){throw console.error(`Failed to remove documents from context ${n}:`,e),e}}async function b(n,r,i,a){try{let a=Array.isArray(r)?r:[r],o=new URLSearchParams,c=`${e.contexts}/${n}/documents${o.toString()?`?${o.toString()}`:``}`;return await t.delete(s(c,i),{body:JSON.stringify(a),headers:{"Content-Type":`application/json`}})}catch(e){throw console.error(`Failed to delete documents from context ${n}:`,e),e}}async function x(n,r,i,a){try{let o=Array.isArray(i)?i:[i];return await t.post(s(`${e.contexts}/${n}/documents`,a),{documentIds:o,context:r}),!0}catch(e){throw console.error(`Failed to paste documents to context path ${r}:`,e),e}}async function S(n,r,i=!0){return await t.post(`${e.contexts}/${n}/tree/paths`,{path:r,autoCreateLayers:i})??!0}async function C(n,r,i=!1){let a=new URLSearchParams({path:r,recursive:i.toString()});return await t.delete(`${e.contexts}/${n}/tree/paths?${a}`)??!0}async function w(n,r,i){return await t.patch(`${e.contexts}/${n}/tree/paths`,{path:r,...i})??!0}async function T(n,r,i,a=!1,o={}){return await t.post(`${e.contexts}/${n}/tree/paths/move`,{from:r,to:i,recursive:a,...o.mergeDown?{mergeDown:!0}:{}})??!0}async function E(n,r){return await t.post(`${e.contexts}/${n}/tree/paths/merge-down`,{path:r})}async function D(n,r){return await t.post(`${e.contexts}/${n}/tree/paths/subtract-down`,{path:r})}async function O(n,r,i,a=!1){return await t.post(`${e.contexts}/${n}/tree/paths/copy`,{from:r,to:i,recursive:a})??!0}async function k(n,r,i){return await t.post(`${e.contexts}/${n}/tree/layers/merge`,{layerId:r,targetLayers:i})}async function A(n,r,i){return await t.post(`${e.contexts}/${n}/tree/layers/subtract`,{layerId:r,targetLayers:i})}async function j(n,r,i){try{let a=Array.isArray(i)?i:[i];return await t.post(`${e.workspaces}/${n}/documents`,{documents:a,treeType:`context`,context:r}),!0}catch(e){throw console.error(`Failed to import documents to context path ${r}:`,e),e}}async function M(n,r,i=[]){try{let a=Array.isArray(r)?r:[r],o=await t.post(`${e.contexts}/${n}/documents`,{documents:a,features:i});return Array.isArray(o)?o:[]}catch(e){throw console.error(`Failed to insert documents into context ${n}:`,e),e}}export{D as C,i as D,f as E,a as O,A as S,w as T,x as _,c as a,y as b,g as c,M as d,h as f,T as g,E as h,b as i,j as l,k as m,l as n,m as o,o as p,p as r,v as s,O as t,S as u,u as v,d as w,_ as x,C as y};
1
+ import{c as e,t}from"./api-CA6WiiYM.js";import{Dn as n,En as r}from"./workspace-BuoZwRL5.js";var i=`contexts:deleted`;function a(e,t){return e.id===t.id?t.ownerId===void 0?e.isShared!==!0&&e.type!==`shared`:e.userId===t.ownerId:!1}async function o(){try{let n=await t.get(e.contexts);return Array.isArray(n)?n:(console.warn(`listContexts: response.payload is not an array:`,n),[])}catch(e){throw console.error(`Failed to list contexts:`,e),e}}function s(e,t){return t?`${e}${e.includes(`?`)?`&`:`?`}ownerId=${encodeURIComponent(t)}`:e}async function c(n,r){try{let i=s(`${e.contexts}/${n}`,r),a=await t.get(i);if(a&&a)return a;throw Error(`Context data not found in API response`)}catch(e){throw console.error(`Failed to get context ${n}:`,e),e}}async function l(n){try{let r=await t.post(e.contexts,n);if(r&&r&&r.context)return r.context;throw Error(`Created context data not found in API response`)}catch(e){throw console.error(`Failed to create context:`,e),e}}async function u(n,r,i){try{let a=s(`${e.contexts}/${n}`,i),o=await t.put(a,r);if(o?.context)return o.context;throw Error(`Updated context data not found in API response`)}catch(e){throw console.error(`Failed to patch context ${n}:`,e),e}}async function d(n,r,i){try{let a=s(`${e.contexts}/${n}`,i),o=await t.put(a,r);if(o?.context)return o.context;throw Error(`Updated context data not found in API response`)}catch(e){throw console.error(`Failed to update context ${n}:`,e),e}}async function f(n,r,i,a){try{let o=s(`${e.contexts}/${n}/url`,i),c=await t.post(o,{url:r,...a?{treeName:a}:{}});if(c&&c&&c.url)return{url:c.url,treeId:c.treeId};throw Error(`Updated context data not found in API response`)}catch(e){throw console.error(`Failed to update context URL for ${n}:`,e),e}}async function p(n,r){try{let a=s(`${e.contexts}/${n}`,r);await t.delete(a),window.dispatchEvent(new CustomEvent(i,{detail:{id:n,ownerId:r}}))}catch(e){throw console.error(`Failed to delete context ${n}:`,e),e}}async function m(i,a=[],o=[],s={},c){try{if(s.ids?.length===0)return Object.assign([],{count:0,totalCount:0});if(n(s.sortBy)){let e=await r(s,async e=>{let t=await m(i,a,o,{...s,...e,sortBy:void 0,order:`asc`},c);return{payload:t,count:t.count,totalCount:t.totalCount}});return Object.assign(e.payload,{count:e.count,totalCount:e.totalCount})}let l=new URLSearchParams;s.geoSelection&&(l.set(`geoSelection`,JSON.stringify(s.geoSelection)),l.set(`includeUnlocated`,String(s.includeUnlocated===!0))),s.ids?.forEach(e=>l.append(`ids`,String(e))),a.forEach(e=>l.append(`allOf`,e)),o.forEach(e=>l.append(`filters`,e)),(s.anyOf||[]).filter(Boolean).forEach(e=>l.append(`anyOf`,e)),(s.noneOf||[]).filter(Boolean).forEach(e=>l.append(`noneOf`,e)),s.sortBy&&l.append(`sortBy`,s.sortBy),s.order&&l.append(`order`,s.order),s.applyContextSpec===!1&&l.append(`applyContextSpec`,`false`),c&&l.append(`ownerId`,c),s.includeServerContext!==void 0&&l.append(`includeServerContext`,s.includeServerContext.toString()),s.includeClientContext!==void 0&&l.append(`includeClientContext`,s.includeClientContext.toString()),s.limit!==void 0&&l.append(`limit`,s.limit.toString()),s.offset!==void 0&&l.append(`offset`,s.offset.toString()),s.page!==void 0&&l.append(`page`,s.page.toString()),(s.queries&&s.queries.length?s.queries:s.q?[s.q]:[]).map(e=>e.trim()).filter(Boolean).forEach(e=>l.append(`q`,e));let u=`${e.contexts}/${i}/documents${l.toString()?`?`+l.toString():``}`,d=await t.getEnvelope(u,{signal:s.signal}),f=d.payload;if(Array.isArray(f)){let e=f;return e.count=d.count??void 0,e.totalCount=d.totalCount??void 0,e}return console.warn(`getContextDocuments: payload is not an array:`,f),[]}catch(e){throw console.error(`Failed to get context documents for ${i}:`,e),e}}async function h(n){let r=await t.get(`${e.contexts}/${n}/shares`);return Array.isArray(r)?r:[]}async function g(n,r,i){try{return{message:(await t.post(`${e.contexts}/${n}/shares`,{userEmail:r,accessLevel:i})).message||`Context access granted`}}catch(e){throw console.error(`Failed to grant context access:`,e),e}}async function _(n,r){try{return{message:(await t.delete(`${e.contexts}/${n}/shares/${encodeURIComponent(r)}`)).message||`Context access revoked`}}catch(e){throw console.error(`Failed to revoke context access:`,e),e}}async function v(n,r){try{let i=s(`${e.contexts}/${n}/tree`,r),a=await t.get(i);if(a)return a;throw Error(`Context tree data not found in API response`)}catch(e){throw console.error(`Failed to get context tree for ${n}:`,e),e}}async function y(n,r,i,a){try{let a=Array.isArray(r)?r:[r],o=new URLSearchParams,c=`${e.contexts}/${n}/documents/remove${o.toString()?`?${o.toString()}`:``}`;return{message:await t.delete(s(c,i),{body:JSON.stringify(a),headers:{"Content-Type":`application/json`}})||`Documents removed from context`}}catch(e){throw console.error(`Failed to remove documents from context ${n}:`,e),e}}async function b(n,r,i,a){try{let a=Array.isArray(r)?r:[r],o=new URLSearchParams,c=`${e.contexts}/${n}/documents${o.toString()?`?${o.toString()}`:``}`;return await t.delete(s(c,i),{body:JSON.stringify(a),headers:{"Content-Type":`application/json`}})}catch(e){throw console.error(`Failed to delete documents from context ${n}:`,e),e}}async function x(n,r,i,a){try{let o=Array.isArray(i)?i:[i];return await t.post(s(`${e.contexts}/${n}/documents`,a),{documentIds:o,context:r}),!0}catch(e){throw console.error(`Failed to paste documents to context path ${r}:`,e),e}}async function S(n,r,i=!0){return await t.post(`${e.contexts}/${n}/tree/paths`,{path:r,autoCreateLayers:i})??!0}async function C(n,r,i=!1){let a=new URLSearchParams({path:r,recursive:i.toString()});return await t.delete(`${e.contexts}/${n}/tree/paths?${a}`)??!0}async function w(n,r,i){return await t.patch(`${e.contexts}/${n}/tree/paths`,{path:r,...i})??!0}async function T(n,r,i,a=!1,o={}){return await t.post(`${e.contexts}/${n}/tree/paths/move`,{from:r,to:i,recursive:a,...o.mergeDown?{mergeDown:!0}:{}})??!0}async function E(n,r){return await t.post(`${e.contexts}/${n}/tree/paths/merge-down`,{path:r})}async function D(n,r){return await t.post(`${e.contexts}/${n}/tree/paths/subtract-down`,{path:r})}async function O(n,r,i,a=!1){return await t.post(`${e.contexts}/${n}/tree/paths/copy`,{from:r,to:i,recursive:a})??!0}async function k(n,r,i){return await t.post(`${e.contexts}/${n}/tree/layers/merge`,{layerId:r,targetLayers:i})}async function A(n,r,i){return await t.post(`${e.contexts}/${n}/tree/layers/subtract`,{layerId:r,targetLayers:i})}async function j(n,r,i){try{let a=Array.isArray(i)?i:[i];return await t.post(`${e.workspaces}/${n}/documents`,{documents:a,treeType:`context`,context:r}),!0}catch(e){throw console.error(`Failed to import documents to context path ${r}:`,e),e}}async function M(n,r,i=[]){try{let a=Array.isArray(r)?r:[r],o=await t.post(`${e.contexts}/${n}/documents`,{documents:a,features:i});return Array.isArray(o)?o:[]}catch(e){throw console.error(`Failed to insert documents into context ${n}:`,e),e}}export{D as C,i as D,f as E,a as O,A as S,w as T,x as _,c as a,y as b,g as c,M as d,h as f,T as g,E as h,b as i,j as l,k as m,l as n,m as o,o as p,p as r,v as s,O as t,S as u,u as v,d as w,_ as x,C as y};
@@ -1 +1 @@
1
- import{o as e}from"./rolldown-runtime-C0FnF6B9.js";import{l as t,u as n}from"./code-editor-BOIngd5F.js";import{g as r}from"./chunk-62JRHF6Z-vspAGgtK.js";import{Nt as i,Y as a,at as o,mt as s,vr as c}from"./ui-Byg1cZDr.js";import{t as l}from"./button-SgR3GVvV.js";import{t as u}from"./input-BOtCd4HP.js";import{t as d}from"./socket-CtH3EU9m.js";import{n as ee}from"./use-toast-BlLDqSUO.js";import{Pt as te}from"./workspace-CrSpR4xf.js";import{a as ne,c as re,i as f,n as ie,o as ae,r as oe,s as se,t as ce}from"./alert-dialog-izlVMXfa.js";import{O as le,n as ue,p as de,r as p}from"./context-DQoZFMDQ.js";import{t as m}from"./PathPickerField-fZazwxCN.js";import{a as h,c as g,i as fe,n as _,o as pe,r as me,s as he,t as ge}from"./use-sortable-data-BW_0sXBs.js";import{n as _e}from"./page-header-DkOHw0g-.js";import{t as ve}from"./form-panel-C34lByEH.js";import{t as ye}from"./use-create-panel-DhSNIGtr.js";var v=e(n(),1);function y(e,t=`An error occurred`){if(e instanceof Error)return e.message;if(typeof e==`object`&&e){let n=e;return n.message||n.error||n.payload?.message||n.payload?.error||n.statusText||t}return t}function be(e,t,n=`An error occurred`){return console.error(t,e),y(e,n)}var b=t();function x(){let e=r(),[t,n]=(0,v.useState)([]),[y,x]=(0,v.useState)([]),[S,C]=(0,v.useState)(!0),[w,T]=(0,v.useState)(null),[E,D]=(0,v.useState)(``),[O,k]=(0,v.useState)(``),[A,j]=(0,v.useState)(`context`),[M,N]=(0,v.useState)(`/`),[P,F]=(0,v.useState)(``),[I,L]=(0,v.useState)(null),[R,z]=(0,v.useState)(`/`),[B,V]=(0,v.useState)(``),[H,U]=(0,v.useState)(!1),[W,G]=ye(),[K,q]=(0,v.useState)(null),[J,Y]=(0,v.useState)(null),{showToast:X}=ee();(0,v.useEffect)(()=>{d.isConnected()||(console.log(`Socket not connected, attempting to connect...`),d.reconnect())},[]);let Z=(0,v.useCallback)(async()=>{try{C(!0);let[e,t]=await Promise.all([de(),te()]),r=e?.filter(e=>e&&typeof e==`object`&&e.id&&e.userId)||[];n(r);let i=t||[];if(x(i),i.length>0){let e=i.some(e=>e.id===B);(!B||!e)&&V(i[0].id)}else V(``);T(null)}catch(e){console.error(`Data fetch error:`,e),n([]),x([]);let t=`Failed to fetch data`;if(e instanceof Error)t=e.message;else if(typeof e==`object`&&e){let n=e;t=n.message||n.error||n.payload?.message||n.payload?.error||n.statusText||`Failed to fetch data`}T(t),X({title:`Error`,description:t,variant:`destructive`})}finally{C(!1)}},[B,X]);(0,v.useEffect)(()=>{Z()},[Z]),(0,v.useEffect)(()=>{let e=()=>d.emit(`subscribe`,{channel:`context`}),t=()=>d.emit(`unsubscribe`,{channel:`context`}),r=d.on(`connect`,e);console.log(`Subscribing to context events`),e();let i=e=>{let t=e;if(console.log(`Received context created:`,t),!t||!t.id||!t.userId){console.error(`Invalid context data received in context:created event:`,t);return}n(e=>e.some(e=>e&&e.id===t.id&&e.userId===t.userId)?(console.log(`Context ${t.id} already exists, skipping duplicate add`),e):[...e,t])},a=e=>{let t=e;if(console.log(`Received context update:`,t),!t||!t.id||!t.userId){console.error(`Invalid context data received in context:updated event:`,t);return}n(e=>e.map(e=>e&&e.id===t.id&&e.userId===t.userId?{...e,...t}:e))},o=e=>{let t=e;console.log(`Received context deletion:`,t);let r=t?.contextId??t?.id;if(!r){console.error(`Invalid context deletion data received:`,t);return}n(e=>e.filter(e=>e&&e.id!==r))},s=e=>{let t=e;if(console.log(`Received context URL change:`,t),!t||!t.id||!t.userId){console.error(`Invalid context data received in context:url:changed event:`,t);return}n(e=>e.map(e=>e&&e.id===t.id&&e.userId===t.userId?{...e,...t}:e))},c=[[`context:created`,i],[`context.created`,i],[`context:updated`,a],[`context.updated`,a],[`context:deleted`,o],[`context.deleted`,o],[`context:url:changed`,s],[`context.url.set`,s],[`context:url:set`,s]];return c.forEach(([e,t])=>d.on(e,t)),()=>{console.log(`Unsubscribing from context events`),t(),r?.(),c.forEach(([e,t])=>d.off(e,t))}},[]);let xe=async t=>{if(t.preventDefault(),!M.trim()||!B||!E.trim()){X({title:`Missing Fields`,description:`Context ID, Context URL and Workspace are required.`,variant:`destructive`});return}U(!0);try{let t={id:E,name:O.trim()||void 0,url:M,description:P.trim()||void 0,metadata:{ui:{color:I}},workspaceId:B,baseUrl:R||void 0,treeType:A},n=await ue(t);D(``),k(``),N(`/`),F(``),L(null),z(`/`),await Z(),X({title:`Success`,description:`Context created successfully`}),G(!1),window.dispatchEvent(new CustomEvent(`contexts:refresh`)),e(`/contexts/${n.id}`)}catch(e){let t=be(e,`Context creation error:`,`Failed to create context`);X({title:`Error`,description:t,variant:`destructive`})}finally{U(!1)}},Se=async e=>{let n=t.find(t=>t.id===e);if(n&&n.url&&(n.url.endsWith(`/default`)||n.url.includes(`://default`))){X({title:`Error`,description:`Cannot delete the default context`,variant:`destructive`});return}Y(e)},Ce=async()=>{if(J)try{await p(J),n(e=>e.filter(e=>!le(e,{id:J}))),X({title:`Success`,description:`Context deleted successfully`})}catch(e){console.error(`Context deletion error:`,e);let t=`Failed to delete context`;if(e instanceof Error)t=e.message;else if(typeof e==`object`&&e){let n=e;t=n.message||n.error||n.payload?.message||n.payload?.error||n.statusText||`Failed to delete context`}X({title:`Error`,description:t,variant:`destructive`})}finally{Y(null)}},we=t=>{let n=t.isShared||t.type===`shared`;e(n?`/contexts/${t.id}?ownerId=${encodeURIComponent(t.userId)}`:`/contexts/${t.id}`)},Te=e=>{q(e)},Ee=async e=>{if(e.preventDefault(),K)try{n(e=>e.map(e=>e.id===K.id&&e.userId===K.userId?K:e)),X({title:`Success`,description:`Context updated successfully (mock update)`}),q(null)}catch(e){let t=e instanceof Error?e.message:`Failed to update context`;X({title:`Error`,description:t,variant:`destructive`})}},De=(0,v.useMemo)(()=>({type:e=>e.isShared||e.type===`shared`?`shared`:`owned`,id:e=>e.id??``,owner:e=>e.isShared||e.type===`shared`?e.ownerEmail||e.userId||``:`you`,url:e=>e.url??``,workspaceId:e=>e.workspaceId??``,baseUrl:e=>e.baseUrl??``,path:e=>e.path??``,locked:e=>+!!e.locked,created:e=>Date.parse(e.createdAt)||0,updated:e=>Date.parse(e.updatedAt)||0}),[]),{sorted:Oe,sort:Q,toggleSort:$}=ge(t.filter(e=>e!=null),De);return(0,b.jsxs)(`div`,{className:`space-y-6`,children:[(0,b.jsx)(_e,{title:`Contexts`,description:`Create and manage contexts in your workspaces. View contexts shared with you.`,actions:!W&&(0,b.jsxs)(l,{onClick:()=>G(!0),className:`max-sm:h-9 max-sm:w-9 max-sm:p-0`,"aria-label":`Create context`,title:`Create context`,children:[(0,b.jsx)(i,{className:`h-4 w-4 sm:mr-2`}),(0,b.jsx)(`span`,{className:`max-sm:hidden`,children:`Create Context`})]})}),W&&(0,b.jsx)(ve,{title:`Create New Context`,onClose:()=>G(!1),children:(0,b.jsxs)(`form`,{onSubmit:xe,className:`space-y-4`,children:[(0,b.jsxs)(`div`,{className:`grid gap-4 md:grid-cols-2`,children:[(0,b.jsxs)(`div`,{children:[(0,b.jsx)(`label`,{htmlFor:`workspace`,className:`block text-sm font-medium mb-1`,children:`Workspace`}),(0,b.jsxs)(`select`,{id:`workspace`,className:`w-full px-3 py-2 border border-border rounded-md shadow-elevation-1 focus:outline-none focus:ring-primary focus:border-primary`,value:B,onChange:e=>V(e.target.value),disabled:H||y.length===0,children:[y.length===0&&(0,b.jsx)(`option`,{value:``,children:`No workspaces available. Create one first.`}),y.map(e=>(0,b.jsx)(`option`,{value:e.id,children:e.label||e.name},`${e.owner}-${e.id}`))]})]}),(0,b.jsxs)(`div`,{children:[(0,b.jsx)(`label`,{htmlFor:`newContextId`,className:`block text-sm font-medium mb-1`,children:`Context ID`}),(0,b.jsx)(u,{id:`newContextId`,value:E,onChange:e=>D(e.target.value),placeholder:`e.g., my-new-context`,disabled:H})]})]}),(0,b.jsxs)(`div`,{children:[(0,b.jsx)(`label`,{htmlFor:`url`,className:`block text-sm font-medium mb-1`,children:`Context URL`}),(0,b.jsx)(m,{id:`url`,value:M,onChange:N,placeholder:`e.g., /project/path/resource`,disabled:H,pickerTitle:`Context URL path…`,onPickTarget:(e,t)=>{N(e),j(t.treeType);let n=y.find(e=>e.name===t.workspaceName||e.id===t.workspaceName);n&&V(n.id)}})]}),(0,b.jsxs)(`div`,{className:`grid gap-4 md:grid-cols-2`,children:[(0,b.jsxs)(`div`,{children:[(0,b.jsx)(`label`,{htmlFor:`baseUrl`,className:`block text-sm font-medium mb-1`,children:`Base URL (Optional)`}),(0,b.jsx)(m,{id:`baseUrl`,value:R,onChange:z,format:`path`,placeholder:`e.g., /base/path`,disabled:H,pickerTitle:`Base path…`})]}),(0,b.jsxs)(`div`,{children:[(0,b.jsx)(`label`,{htmlFor:`description`,className:`block text-sm font-medium mb-1`,children:`Description (Optional)`}),(0,b.jsx)(u,{id:`description`,value:P,onChange:e=>F(e.target.value),placeholder:`Description`,disabled:H})]})]}),(0,b.jsxs)(`div`,{children:[(0,b.jsx)(`label`,{htmlFor:`contextColor`,className:`block text-sm font-medium mb-1`,children:`Color (Optional)`}),(0,b.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,b.jsx)(u,{id:`contextColor`,type:`color`,value:I||`#808080`,onChange:e=>L(e.target.value),className:`h-10 w-16 p-1`,disabled:H}),(0,b.jsx)(l,{type:`button`,variant:`outline`,size:`sm`,disabled:H||I===null,onClick:()=>L(null),children:`Use inherited color`})]}),(0,b.jsx)(`p`,{className:`mt-1 text-xs text-muted-foreground`,children:I===null?`Uses the tree folder or workspace color.`:`Applies only to this context.`})]}),(0,b.jsxs)(`div`,{className:`grid gap-4 md:grid-cols-2`,children:[(0,b.jsxs)(`div`,{children:[(0,b.jsx)(`label`,{htmlFor:`contextName`,className:`block text-sm font-medium mb-1`,children:`Name (Optional)`}),(0,b.jsx)(u,{id:`contextName`,value:O,onChange:e=>k(e.target.value),placeholder:`My Context`,disabled:H})]}),(0,b.jsxs)(`div`,{children:[(0,b.jsx)(`label`,{htmlFor:`treeType`,className:`block text-sm font-medium mb-1`,children:`Tree`}),(0,b.jsxs)(`select`,{id:`treeType`,className:`w-full px-3 py-2 border border-border rounded-md shadow-elevation-1 focus:outline-none focus:ring-primary focus:border-primary`,value:A,onChange:e=>j(e.target.value),disabled:H,children:[(0,b.jsx)(`option`,{value:`context`,children:`Context tree`}),(0,b.jsx)(`option`,{value:`directory`,children:`Directory tree`})]}),(0,b.jsx)(`p`,{className:`mt-1 text-xs text-muted-foreground`,children:`Which workspace tree this context navigates.`})]})]}),(0,b.jsxs)(l,{type:`submit`,disabled:H||!M.trim()||!B||!E.trim(),children:[(0,b.jsx)(i,{className:`mr-2 h-4 w-4`}),`Create Context`]})]})}),(0,b.jsxs)(`div`,{className:`space-y-4`,children:[(0,b.jsx)(`h2`,{className:`text-xl font-semibold`,children:`Your Contexts & Shared Contexts`}),S&&(0,b.jsx)(`p`,{className:`text-center text-muted-foreground`,children:`Loading contexts...`}),w&&(0,b.jsx)(`div`,{className:`text-center text-destructive`,children:(0,b.jsx)(`p`,{children:w})}),!S&&!w&&t.length===0&&(0,b.jsx)(`p`,{className:`text-center text-muted-foreground`,children:`No contexts found. Create one above.`}),t.length>0&&(0,b.jsx)(`div`,{className:`border rounded-lg overflow-hidden`,children:(0,b.jsxs)(me,{children:[(0,b.jsx)(he,{children:(0,b.jsxs)(g,{children:[(0,b.jsx)(_,{label:`Type`,sortKey:`type`,sort:Q,onSort:$}),(0,b.jsx)(_,{label:`ID`,sortKey:`id`,sort:Q,onSort:$}),(0,b.jsx)(_,{label:`Owner`,sortKey:`owner`,sort:Q,onSort:$}),(0,b.jsx)(_,{label:`Context URL`,sortKey:`url`,sort:Q,onSort:$}),(0,b.jsx)(_,{label:`Workspace ID`,sortKey:`workspaceId`,sort:Q,onSort:$}),(0,b.jsx)(_,{label:`Base URL`,sortKey:`baseUrl`,sort:Q,onSort:$}),(0,b.jsx)(_,{label:`Path`,sortKey:`path`,sort:Q,onSort:$}),(0,b.jsx)(_,{label:`Locked`,sortKey:`locked`,sort:Q,onSort:$}),(0,b.jsx)(_,{label:`Created`,sortKey:`created`,sort:Q,onSort:$}),(0,b.jsx)(_,{label:`Updated`,sortKey:`updated`,sort:Q,onSort:$}),(0,b.jsx)(pe,{className:`text-right`,children:`Actions`})]})}),(0,b.jsx)(fe,{children:Oe.map(e=>{if(!e)return console.warn(`Found null/undefined context in contexts array, skipping`),null;let t=e.createdAt?new Date(e.createdAt).toLocaleDateString():`-`,n=e.updatedAt?new Date(e.updatedAt).toLocaleDateString():`-`,r=e.isShared||e.type===`shared`,i=r?e.ownerEmail||e.userId||`-`:`You`,u=r&&e.sharedVia?typeof e.sharedVia==`string`?e.sharedVia:e.sharedVia.accessLevel||`-`:`-`;return(0,b.jsxs)(g,{children:[(0,b.jsx)(h,{children:r?(0,b.jsxs)(`div`,{className:`flex items-center gap-1 text-info`,title:`Shared with you (${u})`,children:[(0,b.jsx)(s,{className:`h-4 w-4`}),(0,b.jsx)(`span`,{className:`text-xs`,children:`Shared`})]}):(0,b.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:`Owned`})}),(0,b.jsx)(h,{className:`font-mono text-sm`,children:e.id||`-`}),(0,b.jsx)(h,{className:`font-mono text-sm`,title:r?`Owned by: ${i}`:`You are the owner`,children:i}),(0,b.jsx)(h,{className:`font-mono text-sm max-w-xs truncate`,title:e.url||`-`,children:e.url||`-`}),(0,b.jsx)(h,{className:`font-mono text-sm`,children:e.workspaceId||`-`}),(0,b.jsx)(h,{className:`font-mono text-sm`,children:e.baseUrl||`-`}),(0,b.jsx)(h,{className:`font-mono text-sm`,children:e.path||`-`}),(0,b.jsx)(h,{children:e.locked?`Yes`:`No`}),(0,b.jsx)(h,{children:t}),(0,b.jsx)(h,{children:n}),(0,b.jsx)(h,{className:`text-right`,children:(0,b.jsxs)(`div`,{className:`flex justify-end gap-2`,children:[!r&&(0,b.jsx)(l,{variant:`outline`,size:`sm`,onClick:()=>Te(e),title:`Edit Context`,children:(0,b.jsx)(o,{className:`h-4 w-4`})}),(0,b.jsx)(l,{variant:`outline`,size:`sm`,onClick:()=>we(e),title:r?`Open Shared Context`:`Open Context Details`,children:(0,b.jsx)(c,{className:`h-4 w-4`})}),!r&&(0,b.jsx)(l,{variant:`outline`,size:`sm`,onClick:()=>Se(e.id),disabled:!!(e.url&&(e.url.endsWith(`/default`)||e.url.includes(`://default`))),className:`text-destructive hover:bg-destructive/10 hover:text-destructive disabled:opacity-50 disabled:cursor-not-allowed`,title:e.url&&(e.url.endsWith(`/default`)||e.url.includes(`://default`))?`Cannot delete default context`:`Delete Context`,children:(0,b.jsx)(a,{className:`h-4 w-4`})})]})})]},`${e.userId}-${e.id}`)})})]})})]}),K&&(0,b.jsxs)(`div`,{className:`space-y-4`,children:[(0,b.jsx)(`h2`,{className:`text-xl font-semibold`,children:`Edit Context`}),(0,b.jsxs)(`form`,{onSubmit:Ee,className:`space-y-4`,children:[(0,b.jsxs)(`div`,{children:[(0,b.jsx)(`label`,{htmlFor:`edit-context-id`,className:`block text-sm font-medium mb-1`,children:`Context ID (read-only)`}),(0,b.jsx)(u,{id:`edit-context-id`,value:K.id,disabled:!0,className:`bg-muted`})]}),(0,b.jsxs)(`div`,{children:[(0,b.jsx)(`label`,{htmlFor:`edit-context-url`,className:`block text-sm font-medium mb-1`,children:`Context URL`}),(0,b.jsx)(m,{id:`edit-context-url`,value:K.url,onChange:e=>q(t=>t?{...t,url:e}:null),placeholder:`workspace://path or /path`,pickerTitle:`Context URL path…`}),(0,b.jsx)(`p`,{className:`text-sm text-muted-foreground mt-1`,children:`Use format: workspace://path or /path for current workspace`})]}),(0,b.jsxs)(`div`,{children:[(0,b.jsx)(`label`,{htmlFor:`edit-base-url`,className:`block text-sm font-medium mb-1`,children:`Base URL (optional)`}),(0,b.jsx)(m,{id:`edit-base-url`,value:K.baseUrl||``,onChange:e=>q(t=>t?{...t,baseUrl:e||null}:null),format:`path`,placeholder:`/base/path`,pickerTitle:`Base path…`}),(0,b.jsx)(`p`,{className:`text-sm text-muted-foreground mt-1`,children:`Restricts context navigation to this base path`})]}),(0,b.jsxs)(`div`,{className:`flex gap-2`,children:[(0,b.jsx)(l,{type:`submit`,children:`Save Changes`}),(0,b.jsx)(l,{type:`button`,variant:`outline`,onClick:()=>q(null),children:`Cancel`})]})]})]}),(0,b.jsx)(ce,{open:J!==null,onOpenChange:e=>!e&&Y(null),children:(0,b.jsxs)(f,{children:[(0,b.jsxs)(se,{children:[(0,b.jsx)(re,{children:`Delete Context`}),(0,b.jsx)(ne,{children:`Are you sure you want to delete this context? This action cannot be undone.`})]}),(0,b.jsxs)(ae,{children:[(0,b.jsx)(oe,{children:`Cancel`}),(0,b.jsx)(ie,{onClick:Ce,className:`bg-destructive text-destructive-foreground hover:bg-destructive/90`,children:`Delete`})]})]})})]})}export{x as default};
1
+ import{o as e}from"./rolldown-runtime-C0FnF6B9.js";import{l as t,u as n}from"./code-editor-BOIngd5F.js";import{g as r}from"./chunk-62JRHF6Z-vspAGgtK.js";import{Pt as i,Y as a,at as o,mt as s,yr as c}from"./ui-76Hw0NU_.js";import{t as l}from"./button-Bum-POPT.js";import{t as u}from"./input-BOtCd4HP.js";import{t as d}from"./socket-CtH3EU9m.js";import{n as ee}from"./use-toast-BlLDqSUO.js";import{Pt as te}from"./workspace-BuoZwRL5.js";import{a as ne,c as re,i as f,n as ie,o as ae,r as oe,s as se,t as ce}from"./alert-dialog-CShuAcnP.js";import{O as le,n as ue,p as de,r as p}from"./context-DVlMC9Bk.js";import{t as m}from"./PathPickerField-B8MsG6xg.js";import{a as h,c as g,i as fe,n as _,o as pe,r as me,s as he,t as ge}from"./use-sortable-data-W2inLcb5.js";import{n as _e}from"./page-header-BoCaZiqu.js";import{t as ve}from"./form-panel-DZj3WZ3z.js";import{t as ye}from"./use-create-panel-DhSNIGtr.js";var v=e(n(),1);function y(e,t=`An error occurred`){if(e instanceof Error)return e.message;if(typeof e==`object`&&e){let n=e;return n.message||n.error||n.payload?.message||n.payload?.error||n.statusText||t}return t}function be(e,t,n=`An error occurred`){return console.error(t,e),y(e,n)}var b=t();function x(){let e=r(),[t,n]=(0,v.useState)([]),[y,x]=(0,v.useState)([]),[S,C]=(0,v.useState)(!0),[w,T]=(0,v.useState)(null),[E,D]=(0,v.useState)(``),[O,k]=(0,v.useState)(``),[A,j]=(0,v.useState)(`context`),[M,N]=(0,v.useState)(`/`),[P,F]=(0,v.useState)(``),[I,L]=(0,v.useState)(null),[R,z]=(0,v.useState)(`/`),[B,V]=(0,v.useState)(``),[H,U]=(0,v.useState)(!1),[W,G]=ye(),[K,q]=(0,v.useState)(null),[J,Y]=(0,v.useState)(null),{showToast:X}=ee();(0,v.useEffect)(()=>{d.isConnected()||(console.log(`Socket not connected, attempting to connect...`),d.reconnect())},[]);let Z=(0,v.useCallback)(async()=>{try{C(!0);let[e,t]=await Promise.all([de(),te()]),r=e?.filter(e=>e&&typeof e==`object`&&e.id&&e.userId)||[];n(r);let i=t||[];if(x(i),i.length>0){let e=i.some(e=>e.id===B);(!B||!e)&&V(i[0].id)}else V(``);T(null)}catch(e){console.error(`Data fetch error:`,e),n([]),x([]);let t=`Failed to fetch data`;if(e instanceof Error)t=e.message;else if(typeof e==`object`&&e){let n=e;t=n.message||n.error||n.payload?.message||n.payload?.error||n.statusText||`Failed to fetch data`}T(t),X({title:`Error`,description:t,variant:`destructive`})}finally{C(!1)}},[B,X]);(0,v.useEffect)(()=>{Z()},[Z]),(0,v.useEffect)(()=>{let e=()=>d.emit(`subscribe`,{channel:`context`}),t=()=>d.emit(`unsubscribe`,{channel:`context`}),r=d.on(`connect`,e);console.log(`Subscribing to context events`),e();let i=e=>{let t=e;if(console.log(`Received context created:`,t),!t||!t.id||!t.userId){console.error(`Invalid context data received in context:created event:`,t);return}n(e=>e.some(e=>e&&e.id===t.id&&e.userId===t.userId)?(console.log(`Context ${t.id} already exists, skipping duplicate add`),e):[...e,t])},a=e=>{let t=e;if(console.log(`Received context update:`,t),!t||!t.id||!t.userId){console.error(`Invalid context data received in context:updated event:`,t);return}n(e=>e.map(e=>e&&e.id===t.id&&e.userId===t.userId?{...e,...t}:e))},o=e=>{let t=e;console.log(`Received context deletion:`,t);let r=t?.contextId??t?.id;if(!r){console.error(`Invalid context deletion data received:`,t);return}n(e=>e.filter(e=>e&&e.id!==r))},s=e=>{let t=e;if(console.log(`Received context URL change:`,t),!t||!t.id||!t.userId){console.error(`Invalid context data received in context:url:changed event:`,t);return}n(e=>e.map(e=>e&&e.id===t.id&&e.userId===t.userId?{...e,...t}:e))},c=[[`context:created`,i],[`context.created`,i],[`context:updated`,a],[`context.updated`,a],[`context:deleted`,o],[`context.deleted`,o],[`context:url:changed`,s],[`context.url.set`,s],[`context:url:set`,s]];return c.forEach(([e,t])=>d.on(e,t)),()=>{console.log(`Unsubscribing from context events`),t(),r?.(),c.forEach(([e,t])=>d.off(e,t))}},[]);let xe=async t=>{if(t.preventDefault(),!M.trim()||!B||!E.trim()){X({title:`Missing Fields`,description:`Context ID, Context URL and Workspace are required.`,variant:`destructive`});return}U(!0);try{let t={id:E,name:O.trim()||void 0,url:M,description:P.trim()||void 0,metadata:{ui:{color:I}},workspaceId:B,baseUrl:R||void 0,treeType:A},n=await ue(t);D(``),k(``),N(`/`),F(``),L(null),z(`/`),await Z(),X({title:`Success`,description:`Context created successfully`}),G(!1),window.dispatchEvent(new CustomEvent(`contexts:refresh`)),e(`/contexts/${n.id}`)}catch(e){let t=be(e,`Context creation error:`,`Failed to create context`);X({title:`Error`,description:t,variant:`destructive`})}finally{U(!1)}},Se=async e=>{let n=t.find(t=>t.id===e);if(n&&n.url&&(n.url.endsWith(`/default`)||n.url.includes(`://default`))){X({title:`Error`,description:`Cannot delete the default context`,variant:`destructive`});return}Y(e)},Ce=async()=>{if(J)try{await p(J),n(e=>e.filter(e=>!le(e,{id:J}))),X({title:`Success`,description:`Context deleted successfully`})}catch(e){console.error(`Context deletion error:`,e);let t=`Failed to delete context`;if(e instanceof Error)t=e.message;else if(typeof e==`object`&&e){let n=e;t=n.message||n.error||n.payload?.message||n.payload?.error||n.statusText||`Failed to delete context`}X({title:`Error`,description:t,variant:`destructive`})}finally{Y(null)}},we=t=>{let n=t.isShared||t.type===`shared`;e(n?`/contexts/${t.id}?ownerId=${encodeURIComponent(t.userId)}`:`/contexts/${t.id}`)},Te=e=>{q(e)},Ee=async e=>{if(e.preventDefault(),K)try{n(e=>e.map(e=>e.id===K.id&&e.userId===K.userId?K:e)),X({title:`Success`,description:`Context updated successfully (mock update)`}),q(null)}catch(e){let t=e instanceof Error?e.message:`Failed to update context`;X({title:`Error`,description:t,variant:`destructive`})}},De=(0,v.useMemo)(()=>({type:e=>e.isShared||e.type===`shared`?`shared`:`owned`,id:e=>e.id??``,owner:e=>e.isShared||e.type===`shared`?e.ownerEmail||e.userId||``:`you`,url:e=>e.url??``,workspaceId:e=>e.workspaceId??``,baseUrl:e=>e.baseUrl??``,path:e=>e.path??``,locked:e=>+!!e.locked,created:e=>Date.parse(e.createdAt)||0,updated:e=>Date.parse(e.updatedAt)||0}),[]),{sorted:Oe,sort:Q,toggleSort:$}=ge(t.filter(e=>e!=null),De);return(0,b.jsxs)(`div`,{className:`space-y-6`,children:[(0,b.jsx)(_e,{title:`Contexts`,description:`Create and manage contexts in your workspaces. View contexts shared with you.`,actions:!W&&(0,b.jsxs)(l,{onClick:()=>G(!0),className:`max-sm:h-9 max-sm:w-9 max-sm:p-0`,"aria-label":`Create context`,title:`Create context`,children:[(0,b.jsx)(i,{className:`h-4 w-4 sm:mr-2`}),(0,b.jsx)(`span`,{className:`max-sm:hidden`,children:`Create Context`})]})}),W&&(0,b.jsx)(ve,{title:`Create New Context`,onClose:()=>G(!1),children:(0,b.jsxs)(`form`,{onSubmit:xe,className:`space-y-4`,children:[(0,b.jsxs)(`div`,{className:`grid gap-4 md:grid-cols-2`,children:[(0,b.jsxs)(`div`,{children:[(0,b.jsx)(`label`,{htmlFor:`workspace`,className:`block text-sm font-medium mb-1`,children:`Workspace`}),(0,b.jsxs)(`select`,{id:`workspace`,className:`w-full px-3 py-2 border border-border rounded-md shadow-elevation-1 focus:outline-none focus:ring-primary focus:border-primary`,value:B,onChange:e=>V(e.target.value),disabled:H||y.length===0,children:[y.length===0&&(0,b.jsx)(`option`,{value:``,children:`No workspaces available. Create one first.`}),y.map(e=>(0,b.jsx)(`option`,{value:e.id,children:e.label||e.name},`${e.owner}-${e.id}`))]})]}),(0,b.jsxs)(`div`,{children:[(0,b.jsx)(`label`,{htmlFor:`newContextId`,className:`block text-sm font-medium mb-1`,children:`Context ID`}),(0,b.jsx)(u,{id:`newContextId`,value:E,onChange:e=>D(e.target.value),placeholder:`e.g., my-new-context`,disabled:H})]})]}),(0,b.jsxs)(`div`,{children:[(0,b.jsx)(`label`,{htmlFor:`url`,className:`block text-sm font-medium mb-1`,children:`Context URL`}),(0,b.jsx)(m,{id:`url`,value:M,onChange:N,placeholder:`e.g., /project/path/resource`,disabled:H,pickerTitle:`Context URL path…`,onPickTarget:(e,t)=>{N(e),j(t.treeType);let n=y.find(e=>e.name===t.workspaceName||e.id===t.workspaceName);n&&V(n.id)}})]}),(0,b.jsxs)(`div`,{className:`grid gap-4 md:grid-cols-2`,children:[(0,b.jsxs)(`div`,{children:[(0,b.jsx)(`label`,{htmlFor:`baseUrl`,className:`block text-sm font-medium mb-1`,children:`Base URL (Optional)`}),(0,b.jsx)(m,{id:`baseUrl`,value:R,onChange:z,format:`path`,placeholder:`e.g., /base/path`,disabled:H,pickerTitle:`Base path…`})]}),(0,b.jsxs)(`div`,{children:[(0,b.jsx)(`label`,{htmlFor:`description`,className:`block text-sm font-medium mb-1`,children:`Description (Optional)`}),(0,b.jsx)(u,{id:`description`,value:P,onChange:e=>F(e.target.value),placeholder:`Description`,disabled:H})]})]}),(0,b.jsxs)(`div`,{children:[(0,b.jsx)(`label`,{htmlFor:`contextColor`,className:`block text-sm font-medium mb-1`,children:`Color (Optional)`}),(0,b.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,b.jsx)(u,{id:`contextColor`,type:`color`,value:I||`#808080`,onChange:e=>L(e.target.value),className:`h-10 w-16 p-1`,disabled:H}),(0,b.jsx)(l,{type:`button`,variant:`outline`,size:`sm`,disabled:H||I===null,onClick:()=>L(null),children:`Use inherited color`})]}),(0,b.jsx)(`p`,{className:`mt-1 text-xs text-muted-foreground`,children:I===null?`Uses the tree folder or workspace color.`:`Applies only to this context.`})]}),(0,b.jsxs)(`div`,{className:`grid gap-4 md:grid-cols-2`,children:[(0,b.jsxs)(`div`,{children:[(0,b.jsx)(`label`,{htmlFor:`contextName`,className:`block text-sm font-medium mb-1`,children:`Name (Optional)`}),(0,b.jsx)(u,{id:`contextName`,value:O,onChange:e=>k(e.target.value),placeholder:`My Context`,disabled:H})]}),(0,b.jsxs)(`div`,{children:[(0,b.jsx)(`label`,{htmlFor:`treeType`,className:`block text-sm font-medium mb-1`,children:`Tree`}),(0,b.jsxs)(`select`,{id:`treeType`,className:`w-full px-3 py-2 border border-border rounded-md shadow-elevation-1 focus:outline-none focus:ring-primary focus:border-primary`,value:A,onChange:e=>j(e.target.value),disabled:H,children:[(0,b.jsx)(`option`,{value:`context`,children:`Context tree`}),(0,b.jsx)(`option`,{value:`directory`,children:`Directory tree`})]}),(0,b.jsx)(`p`,{className:`mt-1 text-xs text-muted-foreground`,children:`Which workspace tree this context navigates.`})]})]}),(0,b.jsxs)(l,{type:`submit`,disabled:H||!M.trim()||!B||!E.trim(),children:[(0,b.jsx)(i,{className:`mr-2 h-4 w-4`}),`Create Context`]})]})}),(0,b.jsxs)(`div`,{className:`space-y-4`,children:[(0,b.jsx)(`h2`,{className:`text-xl font-semibold`,children:`Your Contexts & Shared Contexts`}),S&&(0,b.jsx)(`p`,{className:`text-center text-muted-foreground`,children:`Loading contexts...`}),w&&(0,b.jsx)(`div`,{className:`text-center text-destructive`,children:(0,b.jsx)(`p`,{children:w})}),!S&&!w&&t.length===0&&(0,b.jsx)(`p`,{className:`text-center text-muted-foreground`,children:`No contexts found. Create one above.`}),t.length>0&&(0,b.jsx)(`div`,{className:`border rounded-lg overflow-hidden`,children:(0,b.jsxs)(me,{children:[(0,b.jsx)(he,{children:(0,b.jsxs)(g,{children:[(0,b.jsx)(_,{label:`Type`,sortKey:`type`,sort:Q,onSort:$}),(0,b.jsx)(_,{label:`ID`,sortKey:`id`,sort:Q,onSort:$}),(0,b.jsx)(_,{label:`Owner`,sortKey:`owner`,sort:Q,onSort:$}),(0,b.jsx)(_,{label:`Context URL`,sortKey:`url`,sort:Q,onSort:$}),(0,b.jsx)(_,{label:`Workspace ID`,sortKey:`workspaceId`,sort:Q,onSort:$}),(0,b.jsx)(_,{label:`Base URL`,sortKey:`baseUrl`,sort:Q,onSort:$}),(0,b.jsx)(_,{label:`Path`,sortKey:`path`,sort:Q,onSort:$}),(0,b.jsx)(_,{label:`Locked`,sortKey:`locked`,sort:Q,onSort:$}),(0,b.jsx)(_,{label:`Created`,sortKey:`created`,sort:Q,onSort:$}),(0,b.jsx)(_,{label:`Updated`,sortKey:`updated`,sort:Q,onSort:$}),(0,b.jsx)(pe,{className:`text-right`,children:`Actions`})]})}),(0,b.jsx)(fe,{children:Oe.map(e=>{if(!e)return console.warn(`Found null/undefined context in contexts array, skipping`),null;let t=e.createdAt?new Date(e.createdAt).toLocaleDateString():`-`,n=e.updatedAt?new Date(e.updatedAt).toLocaleDateString():`-`,r=e.isShared||e.type===`shared`,i=r?e.ownerEmail||e.userId||`-`:`You`,u=r&&e.sharedVia?typeof e.sharedVia==`string`?e.sharedVia:e.sharedVia.accessLevel||`-`:`-`;return(0,b.jsxs)(g,{children:[(0,b.jsx)(h,{children:r?(0,b.jsxs)(`div`,{className:`flex items-center gap-1 text-info`,title:`Shared with you (${u})`,children:[(0,b.jsx)(s,{className:`h-4 w-4`}),(0,b.jsx)(`span`,{className:`text-xs`,children:`Shared`})]}):(0,b.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:`Owned`})}),(0,b.jsx)(h,{className:`font-mono text-sm`,children:e.id||`-`}),(0,b.jsx)(h,{className:`font-mono text-sm`,title:r?`Owned by: ${i}`:`You are the owner`,children:i}),(0,b.jsx)(h,{className:`font-mono text-sm max-w-xs truncate`,title:e.url||`-`,children:e.url||`-`}),(0,b.jsx)(h,{className:`font-mono text-sm`,children:e.workspaceId||`-`}),(0,b.jsx)(h,{className:`font-mono text-sm`,children:e.baseUrl||`-`}),(0,b.jsx)(h,{className:`font-mono text-sm`,children:e.path||`-`}),(0,b.jsx)(h,{children:e.locked?`Yes`:`No`}),(0,b.jsx)(h,{children:t}),(0,b.jsx)(h,{children:n}),(0,b.jsx)(h,{className:`text-right`,children:(0,b.jsxs)(`div`,{className:`flex justify-end gap-2`,children:[!r&&(0,b.jsx)(l,{variant:`outline`,size:`sm`,onClick:()=>Te(e),title:`Edit Context`,children:(0,b.jsx)(o,{className:`h-4 w-4`})}),(0,b.jsx)(l,{variant:`outline`,size:`sm`,onClick:()=>we(e),title:r?`Open Shared Context`:`Open Context Details`,children:(0,b.jsx)(c,{className:`h-4 w-4`})}),!r&&(0,b.jsx)(l,{variant:`outline`,size:`sm`,onClick:()=>Se(e.id),disabled:!!(e.url&&(e.url.endsWith(`/default`)||e.url.includes(`://default`))),className:`text-destructive hover:bg-destructive/10 hover:text-destructive disabled:opacity-50 disabled:cursor-not-allowed`,title:e.url&&(e.url.endsWith(`/default`)||e.url.includes(`://default`))?`Cannot delete default context`:`Delete Context`,children:(0,b.jsx)(a,{className:`h-4 w-4`})})]})})]},`${e.userId}-${e.id}`)})})]})})]}),K&&(0,b.jsxs)(`div`,{className:`space-y-4`,children:[(0,b.jsx)(`h2`,{className:`text-xl font-semibold`,children:`Edit Context`}),(0,b.jsxs)(`form`,{onSubmit:Ee,className:`space-y-4`,children:[(0,b.jsxs)(`div`,{children:[(0,b.jsx)(`label`,{htmlFor:`edit-context-id`,className:`block text-sm font-medium mb-1`,children:`Context ID (read-only)`}),(0,b.jsx)(u,{id:`edit-context-id`,value:K.id,disabled:!0,className:`bg-muted`})]}),(0,b.jsxs)(`div`,{children:[(0,b.jsx)(`label`,{htmlFor:`edit-context-url`,className:`block text-sm font-medium mb-1`,children:`Context URL`}),(0,b.jsx)(m,{id:`edit-context-url`,value:K.url,onChange:e=>q(t=>t?{...t,url:e}:null),placeholder:`workspace://path or /path`,pickerTitle:`Context URL path…`}),(0,b.jsx)(`p`,{className:`text-sm text-muted-foreground mt-1`,children:`Use format: workspace://path or /path for current workspace`})]}),(0,b.jsxs)(`div`,{children:[(0,b.jsx)(`label`,{htmlFor:`edit-base-url`,className:`block text-sm font-medium mb-1`,children:`Base URL (optional)`}),(0,b.jsx)(m,{id:`edit-base-url`,value:K.baseUrl||``,onChange:e=>q(t=>t?{...t,baseUrl:e||null}:null),format:`path`,placeholder:`/base/path`,pickerTitle:`Base path…`}),(0,b.jsx)(`p`,{className:`text-sm text-muted-foreground mt-1`,children:`Restricts context navigation to this base path`})]}),(0,b.jsxs)(`div`,{className:`flex gap-2`,children:[(0,b.jsx)(l,{type:`submit`,children:`Save Changes`}),(0,b.jsx)(l,{type:`button`,variant:`outline`,onClick:()=>q(null),children:`Cancel`})]})]})]}),(0,b.jsx)(ce,{open:J!==null,onOpenChange:e=>!e&&Y(null),children:(0,b.jsxs)(f,{children:[(0,b.jsxs)(se,{children:[(0,b.jsx)(re,{children:`Delete Context`}),(0,b.jsx)(ne,{children:`Are you sure you want to delete this context? This action cannot be undone.`})]}),(0,b.jsxs)(ae,{children:[(0,b.jsx)(oe,{children:`Cancel`}),(0,b.jsx)(ie,{onClick:Ce,className:`bg-destructive text-destructive-foreground hover:bg-destructive/90`,children:`Delete`})]})]})})]})}export{x as default};
@@ -1 +1 @@
1
- import{o as e}from"./rolldown-runtime-C0FnF6B9.js";import{l as t,u as n}from"./code-editor-BOIngd5F.js";import{i as r}from"./auth-Bx9fAZmz.js";import{n as i}from"./page-header-DkOHw0g-.js";var a=e(n(),1),o=t();function s(){let e=r()?.userType===`admin`;return(0,a.useEffect)(()=>{},[e]),e?(0,o.jsxs)(`div`,{className:`space-y-6`,children:[(0,o.jsx)(i,{title:`All Contexts`,description:`Manage all contexts across all users`}),(0,o.jsx)(`div`,{className:`flex flex-col items-center justify-center py-12 space-y-4`,children:(0,o.jsxs)(`div`,{className:`text-center`,children:[(0,o.jsx)(`h2`,{className:`text-2xl font-semibold mb-2`,children:`Coming Soon`}),(0,o.jsx)(`p`,{className:`text-muted-foreground max-w-md`,children:`Global context management is currently under development. Check back later for updates.`})]})})]}):(0,o.jsx)(`div`,{className:`text-center space-y-4`,children:(0,o.jsx)(`div`,{className:`text-destructive`,children:`Access denied. Admin privileges required.`})})}export{s as default};
1
+ import{o as e}from"./rolldown-runtime-C0FnF6B9.js";import{l as t,u as n}from"./code-editor-BOIngd5F.js";import{i as r}from"./auth-Bx9fAZmz.js";import{n as i}from"./page-header-BoCaZiqu.js";var a=e(n(),1),o=t();function s(){let e=r()?.userType===`admin`;return(0,a.useEffect)(()=>{},[e]),e?(0,o.jsxs)(`div`,{className:`space-y-6`,children:[(0,o.jsx)(i,{title:`All Contexts`,description:`Manage all contexts across all users`}),(0,o.jsx)(`div`,{className:`flex flex-col items-center justify-center py-12 space-y-4`,children:(0,o.jsxs)(`div`,{className:`text-center`,children:[(0,o.jsx)(`h2`,{className:`text-2xl font-semibold mb-2`,children:`Coming Soon`}),(0,o.jsx)(`p`,{className:`text-muted-foreground max-w-md`,children:`Global context management is currently under development. Check back later for updates.`})]})})]}):(0,o.jsx)(`div`,{className:`text-center space-y-4`,children:(0,o.jsx)(`div`,{className:`text-destructive`,children:`Access denied. Admin privileges required.`})})}export{s as default};
@@ -1 +1 @@
1
- import{o as e}from"./rolldown-runtime-C0FnF6B9.js";import{l as t,u as n}from"./code-editor-BOIngd5F.js";import{yt as r}from"./react-BHzhHVTZ.js";import{Br as i,L as a,Vr as o,qr as s}from"./ui-Byg1cZDr.js";import{t as c}from"./utils-2pl1SbIp.js";import{Vn as l}from"./workspace-CrSpR4xf.js";import{n as u}from"./tags-YamdPoBK.js";import{o as d}from"./useAddTarget-CqnDU0Om.js";import{r as f}from"./relation-events-CKio19hE.js";var p=e(n(),1),m=`2.1`,h=[`pending`,`in-progress`,`completed`,`cancelled`],g={pending:`Pending`,"in-progress":`In progress`,completed:`Completed`,cancelled:`Cancelled`};function _(e){return String(e).padStart(2,`0`)}function v(e){return`${e.getFullYear()}-${_(e.getMonth()+1)}-${_(e.getDate())}T${_(e.getHours())}:${_(e.getMinutes())}`}function y(e){if(!e)return``;let t=new Date(e);return Number.isNaN(t.getTime())?``:v(t)}function b(e){if(!e)return;let t=new Date(e);return Number.isNaN(t.getTime())?void 0:t.toISOString()}function x(){let e=new Date;return e.setHours(23,59,0,0),v(e)}function S(e){let t=b(e.due);return{title:e.title.trim(),...e.description.trim()?{description:e.description.trim()}:{},status:e.status,completed:e.status===`completed`,...t?{dueDate:t}:{},...e.priority===``?{}:{priority:Number(e.priority)}}}function C(){let[e,t]=(0,p.useState)(``),[n,r]=(0,p.useState)(``),[i,a]=(0,p.useState)(`pending`),[o,s]=(0,p.useState)(``),[c,h]=(0,p.useState)(x()),[g,_]=(0,p.useState)([]),[v,y]=(0,p.useState)(``),[b,C]=(0,p.useState)(!1),w=f(),T=e.trim().length>0&&!b;async function E(t){C(!0);try{let r=await w.capture(),a=v.trim(),s={schema:l,schemaVersion:m,data:S({title:e,description:n,status:i,priority:o,due:c}),...a?{comment:a}:{},metadata:{features:u(g),...r?{geo:r}:{}}};return await d(t,[s])}finally{C(!1)}}return{title:e,setTitle:t,description:n,setDescription:r,status:i,setStatus:a,priority:o,setPriority:s,due:c,setDue:h,tags:g,setTags:_,comment:v,setComment:y,saving:b,canSave:T,save:E,geotag:w}}var w=e(r(),1),T=t(),E=15,D=[`Mo`,`Tu`,`We`,`Th`,`Fr`,`Sa`,`Su`];function O(e){return String(e).padStart(2,`0`)}function k(e){let t=/^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2})/.exec(e||``);return t?{date:`${t[1]}-${t[2]}-${t[3]}`,time:`${t[4]}:${t[5]}`}:null}function A(e){return`${e.getFullYear()}-${O(e.getMonth()+1)}-${O(e.getDate())}`}function j(e){let[t,n,r]=e.split(`-`).map(Number);return new Date(t,n-1,r)}function M(){let e=new Date;return e.setSeconds(0,0),e.setMinutes(Math.ceil(e.getMinutes()/E)*E),`${O(e.getHours())}:${O(e.getMinutes())}`}function N(){let e=[];for(let t=0;t<1440;t+=E)e.push(`${O(Math.floor(t/60))}:${O(t%60)}`);return e}var P=N();function F(e){let t=new Date(e.getFullYear(),e.getMonth(),1),n=(t.getDay()+6)%7,r=new Date(t);return r.setDate(t.getDate()-n),Array.from({length:42},(e,t)=>{let n=new Date(r);return n.setDate(r.getDate()+t),n})}function I(e){let[t,n]=e.split(`:`).map(Number);return new Date(2e3,0,1,t,n).toLocaleTimeString(void 0,{hour:`2-digit`,minute:`2-digit`})}function L(e){let t=k(e);if(!t)return``;let[n,r,i]=t.date.split(`-`).map(Number),[a,o]=t.time.split(`:`).map(Number);return new Date(n,r-1,i,a,o).toLocaleString(void 0,{weekday:`short`,day:`numeric`,month:`short`,year:`numeric`,hour:`2-digit`,minute:`2-digit`})}function R({value:e,onChange:t,id:n,placeholder:r=`Pick a date & time`,clearable:i=!0,disabled:o=!1,compact:l=!1,className:u=``}){let[d,f]=(0,p.useState)(!1),m=(0,p.useRef)(null),h=k(e),g=h?L(e):``;return(0,T.jsxs)(T.Fragment,{children:[(0,T.jsxs)(`button`,{ref:m,id:n,type:`button`,disabled:o,onClick:()=>f(e=>!e),"aria-haspopup":`dialog`,"aria-expanded":d,className:c(`inline-flex w-full items-center gap-2 rounded-md border border-input bg-transparent text-left shadow-elevation-1 transition-colors`,`focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-50`,l?`h-6 px-1.5 text-[11px]`:`h-9 px-3 py-1 text-sm`,!h&&`text-muted-foreground`,u),children:[(0,T.jsx)(s,{className:c(`shrink-0 text-muted-foreground`,l?`h-3 w-3`:`h-4 w-4`)}),(0,T.jsx)(`span`,{className:`min-w-0 flex-1 truncate`,children:g||r}),i&&h&&(0,T.jsx)(`span`,{role:`button`,tabIndex:-1,"aria-label":`Clear date`,title:`Clear`,onClick:e=>{e.stopPropagation(),t(``)},className:`shrink-0 rounded p-0.5 text-muted-foreground hover:bg-muted hover:text-foreground`,children:(0,T.jsx)(a,{className:l?`h-2.5 w-2.5`:`h-3.5 w-3.5`})})]}),d&&(0,T.jsx)(z,{anchorRef:m,value:e,onChange:t,onClose:()=>f(!1)})]})}function z({anchorRef:e,value:t,onChange:n,onClose:r}){let a=k(t),s=a?.date??A(new Date),l=a?.time??null,[u,d]=(0,p.useState)(()=>{let e=j(s);return new Date(e.getFullYear(),e.getMonth(),1)}),f=(0,p.useRef)(null),m=(0,p.useRef)(null),[h,g]=(0,p.useState)(null);(0,p.useLayoutEffect)(()=>{let t=f.current,n=e.current;if(!t||!n)return;let r=()=>{let e=n.getBoundingClientRect(),{width:r,height:i}=t.getBoundingClientRect(),a=e.bottom+4,o=a+i+8>window.innerHeight?Math.max(8,e.top-i-4):a,s=Math.max(8,Math.min(e.left,window.innerWidth-r-8));g({x:s,y:o})};r();let i=new ResizeObserver(r);return i.observe(t),window.addEventListener(`resize`,r),window.addEventListener(`scroll`,r,!0),()=>{i.disconnect(),window.removeEventListener(`resize`,r),window.removeEventListener(`scroll`,r,!0)}},[e]),(0,p.useEffect)(()=>{let e=e=>{e.key===`Escape`&&(e.stopPropagation(),r())};return window.addEventListener(`keydown`,e,!0),()=>window.removeEventListener(`keydown`,e,!0)},[r]);let _=(0,p.useMemo)(()=>!l||P.includes(l)?P:[...P,l].sort(),[l]);(0,p.useEffect)(()=>{let e=m.current,t=e?.querySelector(`[data-selected="true"]`);e&&t&&(e.scrollTop=t.offsetTop-e.clientHeight/2+t.clientHeight/2)},[]);let v=(e,t)=>n(`${e}T${t}`),y=e=>{let t=l??M();v(A(e),t),e.getMonth()!==u.getMonth()&&d(new Date(e.getFullYear(),e.getMonth(),1))},b=e=>{v(s,e),r()},x=e=>{let t=new Date;t.setDate(t.getDate()+e);let n=l??M();v(A(t),n),d(new Date(t.getFullYear(),t.getMonth(),1))},S=A(new Date),C=F(u);return(0,w.createPortal)((0,T.jsxs)(T.Fragment,{children:[(0,T.jsx)(`div`,{className:`fixed inset-0 z-40`,onClick:r}),(0,T.jsxs)(`div`,{ref:f,role:`dialog`,"aria-label":`Choose date and time`,className:`fixed z-50 flex max-w-[95vw] gap-2 rounded-md border bg-popover p-2 text-popover-foreground shadow-elevation-4`,style:{left:h?.x??-9999,top:h?.y??-9999,visibility:h?`visible`:`hidden`},children:[(0,T.jsxs)(`div`,{className:`w-[236px]`,children:[(0,T.jsxs)(`div`,{className:`mb-1 flex items-center justify-between`,children:[(0,T.jsx)(`button`,{type:`button`,onClick:()=>d(new Date(u.getFullYear(),u.getMonth()-1,1)),"aria-label":`Previous month`,className:`rounded p-1 text-muted-foreground hover:bg-muted hover:text-foreground`,children:(0,T.jsx)(o,{className:`h-4 w-4`})}),(0,T.jsx)(`span`,{className:`text-xs font-medium`,children:u.toLocaleDateString(void 0,{month:`long`,year:`numeric`})}),(0,T.jsx)(`button`,{type:`button`,onClick:()=>d(new Date(u.getFullYear(),u.getMonth()+1,1)),"aria-label":`Next month`,className:`rounded p-1 text-muted-foreground hover:bg-muted hover:text-foreground`,children:(0,T.jsx)(i,{className:`h-4 w-4`})})]}),(0,T.jsx)(`div`,{className:`grid grid-cols-7 gap-0.5 px-0.5 pb-1 text-center text-[10px] uppercase tracking-wide text-muted-foreground/70`,children:D.map(e=>(0,T.jsx)(`span`,{children:e},e))}),(0,T.jsx)(`div`,{className:`grid grid-cols-7 gap-0.5`,children:C.map(e=>{let t=A(e),n=e.getMonth()!==u.getMonth(),r=t===s&&!!a;return(0,T.jsx)(`button`,{type:`button`,onClick:()=>y(e),"aria-pressed":r,className:c(`h-7 rounded text-xs tabular-nums transition-colors`,n?`text-muted-foreground/40`:`text-foreground`,r?`bg-primary text-primary-foreground`:`hover:bg-muted`,!r&&t===S&&`font-semibold ring-1 ring-inset ring-border`),children:e.getDate()},t)})}),(0,T.jsx)(`div`,{className:`mt-1.5 flex gap-1`,children:[[`Today`,0],[`Tomorrow`,1],[`Next week`,7]].map(([e,t])=>(0,T.jsx)(`button`,{type:`button`,onClick:()=>x(t),className:`flex-1 rounded border border-border px-1.5 py-1 text-[11px] text-muted-foreground transition-colors hover:bg-muted hover:text-foreground`,children:e},e))})]}),(0,T.jsxs)(`div`,{className:`flex w-[104px] flex-col`,children:[(0,T.jsx)(`input`,{type:`time`,step:900,value:l??``,onChange:e=>{e.target.value&&v(s,e.target.value.slice(0,5))},"aria-label":`Time`,className:`mb-1 h-7 w-full rounded border border-input bg-transparent px-1.5 text-xs tabular-nums focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring`}),(0,T.jsx)(`div`,{ref:m,className:`max-h-[236px] flex-1 overflow-y-auto pr-0.5`,children:_.map(e=>{let t=e===l;return(0,T.jsx)(`button`,{type:`button`,"data-selected":t,onClick:()=>b(e),"aria-pressed":t,className:c(`block w-full rounded px-2 py-1 text-left text-xs tabular-nums transition-colors`,t?`bg-primary text-primary-foreground`:`hover:bg-muted`),children:I(e)},e)})})]})]})]}),document.body)}export{y as a,C as c,S as i,h as n,b as o,g as r,x as s,R as t};
1
+ import{o as e}from"./rolldown-runtime-C0FnF6B9.js";import{l as t,u as n}from"./code-editor-BOIngd5F.js";import{yt as r}from"./react-BHzhHVTZ.js";import{Hr as i,Jr as a,L as o,Vr as s}from"./ui-76Hw0NU_.js";import{t as c}from"./utils-2pl1SbIp.js";import{Hn as l}from"./workspace-BuoZwRL5.js";import{n as u}from"./tags-YamdPoBK.js";import{o as d}from"./useAddTarget-D9S8RxCR.js";import{r as f}from"./relation-events-CKio19hE.js";var p=e(n(),1),m=`2.1`,h=[`pending`,`in-progress`,`completed`,`cancelled`],g={pending:`Pending`,"in-progress":`In progress`,completed:`Completed`,cancelled:`Cancelled`};function _(e){return String(e).padStart(2,`0`)}function v(e){return`${e.getFullYear()}-${_(e.getMonth()+1)}-${_(e.getDate())}T${_(e.getHours())}:${_(e.getMinutes())}`}function y(e){if(!e)return``;let t=new Date(e);return Number.isNaN(t.getTime())?``:v(t)}function b(e){if(!e)return;let t=new Date(e);return Number.isNaN(t.getTime())?void 0:t.toISOString()}function x(){let e=new Date;return e.setHours(23,59,0,0),v(e)}function S(e){let t=b(e.due);return{title:e.title.trim(),...e.description.trim()?{description:e.description.trim()}:{},status:e.status,completed:e.status===`completed`,...t?{dueDate:t}:{},...e.priority===``?{}:{priority:Number(e.priority)}}}function C(){let[e,t]=(0,p.useState)(``),[n,r]=(0,p.useState)(``),[i,a]=(0,p.useState)(`pending`),[o,s]=(0,p.useState)(``),[c,h]=(0,p.useState)(x()),[g,_]=(0,p.useState)([]),[v,y]=(0,p.useState)(``),[b,C]=(0,p.useState)(!1),w=f(),T=e.trim().length>0&&!b;async function E(t){C(!0);try{let r=await w.capture(),a=v.trim(),s={schema:l,schemaVersion:m,data:S({title:e,description:n,status:i,priority:o,due:c}),...a?{comment:a}:{},metadata:{features:u(g),...r?{geo:r}:{}}};return await d(t,[s])}finally{C(!1)}}return{title:e,setTitle:t,description:n,setDescription:r,status:i,setStatus:a,priority:o,setPriority:s,due:c,setDue:h,tags:g,setTags:_,comment:v,setComment:y,saving:b,canSave:T,save:E,geotag:w}}var w=e(r(),1),T=t(),E=15,D=[`Mo`,`Tu`,`We`,`Th`,`Fr`,`Sa`,`Su`];function O(e){return String(e).padStart(2,`0`)}function k(e){let t=/^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2})/.exec(e||``);return t?{date:`${t[1]}-${t[2]}-${t[3]}`,time:`${t[4]}:${t[5]}`}:null}function A(e){return`${e.getFullYear()}-${O(e.getMonth()+1)}-${O(e.getDate())}`}function j(e){let[t,n,r]=e.split(`-`).map(Number);return new Date(t,n-1,r)}function M(){let e=new Date;return e.setSeconds(0,0),e.setMinutes(Math.ceil(e.getMinutes()/E)*E),`${O(e.getHours())}:${O(e.getMinutes())}`}function N(){let e=[];for(let t=0;t<1440;t+=E)e.push(`${O(Math.floor(t/60))}:${O(t%60)}`);return e}var P=N();function F(e){let t=new Date(e.getFullYear(),e.getMonth(),1),n=(t.getDay()+6)%7,r=new Date(t);return r.setDate(t.getDate()-n),Array.from({length:42},(e,t)=>{let n=new Date(r);return n.setDate(r.getDate()+t),n})}function I(e){let[t,n]=e.split(`:`).map(Number);return new Date(2e3,0,1,t,n).toLocaleTimeString(void 0,{hour:`2-digit`,minute:`2-digit`})}function L(e){let t=k(e);if(!t)return``;let[n,r,i]=t.date.split(`-`).map(Number),[a,o]=t.time.split(`:`).map(Number);return new Date(n,r-1,i,a,o).toLocaleString(void 0,{weekday:`short`,day:`numeric`,month:`short`,year:`numeric`,hour:`2-digit`,minute:`2-digit`})}function R({value:e,onChange:t,id:n,placeholder:r=`Pick a date & time`,clearable:i=!0,disabled:s=!1,compact:l=!1,className:u=``}){let[d,f]=(0,p.useState)(!1),m=(0,p.useRef)(null),h=k(e),g=h?L(e):``;return(0,T.jsxs)(T.Fragment,{children:[(0,T.jsxs)(`button`,{ref:m,id:n,type:`button`,disabled:s,onClick:()=>f(e=>!e),"aria-haspopup":`dialog`,"aria-expanded":d,className:c(`inline-flex w-full items-center gap-2 rounded-md border border-input bg-transparent text-left shadow-elevation-1 transition-colors`,`focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-50`,l?`h-6 px-1.5 text-[11px]`:`h-9 px-3 py-1 text-sm`,!h&&`text-muted-foreground`,u),children:[(0,T.jsx)(a,{className:c(`shrink-0 text-muted-foreground`,l?`h-3 w-3`:`h-4 w-4`)}),(0,T.jsx)(`span`,{className:`min-w-0 flex-1 truncate`,children:g||r}),i&&h&&(0,T.jsx)(`span`,{role:`button`,tabIndex:-1,"aria-label":`Clear date`,title:`Clear`,onClick:e=>{e.stopPropagation(),t(``)},className:`shrink-0 rounded p-0.5 text-muted-foreground hover:bg-muted hover:text-foreground`,children:(0,T.jsx)(o,{className:l?`h-2.5 w-2.5`:`h-3.5 w-3.5`})})]}),d&&(0,T.jsx)(z,{anchorRef:m,value:e,onChange:t,onClose:()=>f(!1)})]})}function z({anchorRef:e,value:t,onChange:n,onClose:r}){let a=k(t),o=a?.date??A(new Date),l=a?.time??null,[u,d]=(0,p.useState)(()=>{let e=j(o);return new Date(e.getFullYear(),e.getMonth(),1)}),f=(0,p.useRef)(null),m=(0,p.useRef)(null),[h,g]=(0,p.useState)(null);(0,p.useLayoutEffect)(()=>{let t=f.current,n=e.current;if(!t||!n)return;let r=()=>{let e=n.getBoundingClientRect(),{width:r,height:i}=t.getBoundingClientRect(),a=e.bottom+4,o=a+i+8>window.innerHeight?Math.max(8,e.top-i-4):a,s=Math.max(8,Math.min(e.left,window.innerWidth-r-8));g({x:s,y:o})};r();let i=new ResizeObserver(r);return i.observe(t),window.addEventListener(`resize`,r),window.addEventListener(`scroll`,r,!0),()=>{i.disconnect(),window.removeEventListener(`resize`,r),window.removeEventListener(`scroll`,r,!0)}},[e]),(0,p.useEffect)(()=>{let e=e=>{e.key===`Escape`&&(e.stopPropagation(),r())};return window.addEventListener(`keydown`,e,!0),()=>window.removeEventListener(`keydown`,e,!0)},[r]);let _=(0,p.useMemo)(()=>!l||P.includes(l)?P:[...P,l].sort(),[l]);(0,p.useEffect)(()=>{let e=m.current,t=e?.querySelector(`[data-selected="true"]`);e&&t&&(e.scrollTop=t.offsetTop-e.clientHeight/2+t.clientHeight/2)},[]);let v=(e,t)=>n(`${e}T${t}`),y=e=>{let t=l??M();v(A(e),t),e.getMonth()!==u.getMonth()&&d(new Date(e.getFullYear(),e.getMonth(),1))},b=e=>{v(o,e),r()},x=e=>{let t=new Date;t.setDate(t.getDate()+e);let n=l??M();v(A(t),n),d(new Date(t.getFullYear(),t.getMonth(),1))},S=A(new Date),C=F(u);return(0,w.createPortal)((0,T.jsxs)(T.Fragment,{children:[(0,T.jsx)(`div`,{className:`fixed inset-0 z-40`,onClick:r}),(0,T.jsxs)(`div`,{ref:f,role:`dialog`,"aria-label":`Choose date and time`,className:`fixed z-50 flex max-w-[95vw] gap-2 rounded-md border bg-popover p-2 text-popover-foreground shadow-elevation-4`,style:{left:h?.x??-9999,top:h?.y??-9999,visibility:h?`visible`:`hidden`},children:[(0,T.jsxs)(`div`,{className:`w-[236px]`,children:[(0,T.jsxs)(`div`,{className:`mb-1 flex items-center justify-between`,children:[(0,T.jsx)(`button`,{type:`button`,onClick:()=>d(new Date(u.getFullYear(),u.getMonth()-1,1)),"aria-label":`Previous month`,className:`rounded p-1 text-muted-foreground hover:bg-muted hover:text-foreground`,children:(0,T.jsx)(i,{className:`h-4 w-4`})}),(0,T.jsx)(`span`,{className:`text-xs font-medium`,children:u.toLocaleDateString(void 0,{month:`long`,year:`numeric`})}),(0,T.jsx)(`button`,{type:`button`,onClick:()=>d(new Date(u.getFullYear(),u.getMonth()+1,1)),"aria-label":`Next month`,className:`rounded p-1 text-muted-foreground hover:bg-muted hover:text-foreground`,children:(0,T.jsx)(s,{className:`h-4 w-4`})})]}),(0,T.jsx)(`div`,{className:`grid grid-cols-7 gap-0.5 px-0.5 pb-1 text-center text-[10px] uppercase tracking-wide text-muted-foreground/70`,children:D.map(e=>(0,T.jsx)(`span`,{children:e},e))}),(0,T.jsx)(`div`,{className:`grid grid-cols-7 gap-0.5`,children:C.map(e=>{let t=A(e),n=e.getMonth()!==u.getMonth(),r=t===o&&!!a;return(0,T.jsx)(`button`,{type:`button`,onClick:()=>y(e),"aria-pressed":r,className:c(`h-7 rounded text-xs tabular-nums transition-colors`,n?`text-muted-foreground/40`:`text-foreground`,r?`bg-primary text-primary-foreground`:`hover:bg-muted`,!r&&t===S&&`font-semibold ring-1 ring-inset ring-border`),children:e.getDate()},t)})}),(0,T.jsx)(`div`,{className:`mt-1.5 flex gap-1`,children:[[`Today`,0],[`Tomorrow`,1],[`Next week`,7]].map(([e,t])=>(0,T.jsx)(`button`,{type:`button`,onClick:()=>x(t),className:`flex-1 rounded border border-border px-1.5 py-1 text-[11px] text-muted-foreground transition-colors hover:bg-muted hover:text-foreground`,children:e},e))})]}),(0,T.jsxs)(`div`,{className:`flex w-[104px] flex-col`,children:[(0,T.jsx)(`input`,{type:`time`,step:900,value:l??``,onChange:e=>{e.target.value&&v(o,e.target.value.slice(0,5))},"aria-label":`Time`,className:`mb-1 h-7 w-full rounded border border-input bg-transparent px-1.5 text-xs tabular-nums focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring`}),(0,T.jsx)(`div`,{ref:m,className:`max-h-[236px] flex-1 overflow-y-auto pr-0.5`,children:_.map(e=>{let t=e===l;return(0,T.jsx)(`button`,{type:`button`,"data-selected":t,onClick:()=>b(e),"aria-pressed":t,className:c(`block w-full rounded px-2 py-1 text-left text-xs tabular-nums transition-colors`,t?`bg-primary text-primary-foreground`:`hover:bg-muted`),children:I(e)},e)})})]})]})]}),document.body)}export{y as a,C as c,S as i,h as n,b as o,g as r,x as s,R as t};
@@ -1 +1 @@
1
- import{o as e}from"./rolldown-runtime-C0FnF6B9.js";import{l as t,u as n}from"./code-editor-BOIngd5F.js";import{L as r,Ot as i,Ur as a,Yt as o,_n as s,dt as c,zt as l}from"./ui-Byg1cZDr.js";import{t as u}from"./button-SgR3GVvV.js";import{t as d}from"./input-BOtCd4HP.js";import{n as f}from"./use-toast-BlLDqSUO.js";import{n as p}from"./page-header-DkOHw0g-.js";import{t as m}from"./use-settings-back-CQauYjQ4.js";import{i as h,n as g,o as _}from"./devices-CAa1bRxk.js";var v=e(n(),1),y=t();function b({device:e,onUpdated:t,onRemoved:n}){let[i,s]=(0,v.useState)(!1),[p,m]=(0,v.useState)(e.name),[g,b]=(0,v.useState)(e.description??``),[x,S]=(0,v.useState)(!1),[C,w]=(0,v.useState)(!1),[T,E]=(0,v.useState)(!1),{showToast:D}=f(),O=async()=>{E(!0);try{await h(e.deviceId),n(e.deviceId),D({title:`Revoked`,description:`${e.name} can no longer sign in; a running mirror stops on its next request.`})}catch(e){D({title:`Error`,description:e instanceof Error?e.message:`Failed to revoke device`,variant:`destructive`}),w(!1)}finally{E(!1)}},k=async()=>{let n=p.trim();if(n){if(n===e.name&&g.trim()===(e.description??``)){s(!1);return}S(!0);try{let r=await _(e.deviceId,{name:n,description:g.trim()||void 0});t({...e,...r}),s(!1),D({title:`Saved`,description:`Device updated`})}catch(e){D({title:`Error`,description:e instanceof Error?e.message:`Failed to update device`,variant:`destructive`})}finally{S(!1)}}},A=()=>{m(e.name),b(e.description??``),s(!1)},j=e=>e?new Date(e).toLocaleString(void 0,{dateStyle:`medium`,timeStyle:`short`}):`—`;return(0,y.jsx)(`div`,{className:`rounded-lg border p-4`,children:(0,y.jsxs)(`div`,{className:`flex items-start justify-between gap-4`,children:[(0,y.jsxs)(`div`,{className:`flex items-start gap-3 min-w-0`,children:[(0,y.jsx)(o,{className:`h-4 w-4 text-muted-foreground mt-0.5 shrink-0`}),(0,y.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[i?(0,y.jsxs)(`div`,{className:`space-y-2 mb-2`,children:[(0,y.jsx)(d,{value:p,onChange:e=>m(e.target.value),className:`h-7 text-sm`,placeholder:`Device name`,autoFocus:!0,disabled:x,onKeyDown:e=>{e.key===`Enter`&&k(),e.key===`Escape`&&A()}}),(0,y.jsx)(d,{value:g,onChange:e=>b(e.target.value),className:`h-7 text-xs`,placeholder:`Description (optional)`,disabled:x,onKeyDown:e=>{e.key===`Enter`&&k(),e.key===`Escape`&&A()}})]}):(0,y.jsxs)(`div`,{className:`mb-1`,children:[(0,y.jsx)(`span`,{className:`text-sm font-medium`,children:e.name}),e.description&&(0,y.jsx)(`p`,{className:`text-xs text-muted-foreground mt-0.5`,children:e.description})]}),(0,y.jsxs)(`div`,{className:`flex flex-wrap gap-x-3 gap-y-0.5 text-[11px] font-mono text-muted-foreground`,children:[(0,y.jsx)(`span`,{title:`Device ID`,children:e.deviceId}),e.platform&&(0,y.jsx)(`span`,{children:e.platform}),e.arch&&(0,y.jsx)(`span`,{children:e.arch}),e.type&&(0,y.jsx)(`span`,{className:`capitalize`,children:e.type})]}),(0,y.jsxs)(`div`,{className:`mt-2 flex flex-wrap gap-x-4 text-[11px] text-muted-foreground`,children:[e.createdAt&&(0,y.jsxs)(`span`,{children:[`registered `,j(e.createdAt)]}),e.updatedAt&&e.updatedAt!==e.createdAt&&(0,y.jsxs)(`span`,{children:[`updated `,j(e.updatedAt)]}),e.lastSeen&&(0,y.jsxs)(`span`,{children:[`seen `,j(e.lastSeen)]})]})]})]}),(0,y.jsx)(`div`,{className:`flex shrink-0 items-center gap-2`,children:C?(0,y.jsxs)(y.Fragment,{children:[(0,y.jsx)(u,{type:`button`,variant:`destructive`,size:`sm`,onClick:O,disabled:T,children:T?`Revoking…`:`Confirm revoke`}),(0,y.jsx)(u,{type:`button`,variant:`ghost`,size:`sm`,onClick:()=>w(!1),disabled:T,children:(0,y.jsx)(r,{className:`h-3.5 w-3.5`})})]}):i?(0,y.jsxs)(y.Fragment,{children:[(0,y.jsx)(u,{type:`button`,variant:`outline`,size:`sm`,onClick:k,disabled:x||!p.trim(),children:(0,y.jsx)(a,{className:`h-3.5 w-3.5`})}),(0,y.jsx)(u,{type:`button`,variant:`ghost`,size:`sm`,onClick:A,disabled:x,children:(0,y.jsx)(r,{className:`h-3.5 w-3.5`})})]}):(0,y.jsxs)(y.Fragment,{children:[(0,y.jsx)(u,{type:`button`,variant:`ghost`,size:`sm`,onClick:()=>s(!0),title:`Edit name / description`,children:(0,y.jsx)(l,{className:`h-3.5 w-3.5`})}),(0,y.jsx)(u,{type:`button`,variant:`ghost`,size:`sm`,onClick:()=>w(!0),title:`Revoke this device: its tokens stop working and its mirrors stop syncing`,children:(0,y.jsx)(c,{className:`h-3.5 w-3.5`})})]})})]})})}function x(){let[e,t]=(0,v.useState)([]),[n,r]=(0,v.useState)(!0),{showToast:a}=f(),c=async()=>{r(!0);try{t(await g())}catch(e){a({title:`Error`,description:e instanceof Error?e.message:`Failed to load devices`,variant:`destructive`})}finally{r(!1)}};(0,v.useEffect)(()=>{(async()=>{try{t(await g())}catch(e){a({title:`Error`,description:e instanceof Error?e.message:`Failed to load devices`,variant:`destructive`})}finally{r(!1)}})()},[a]);let l=e=>t(t=>t.map(t=>t.deviceId===e.deviceId?e:t)),d=e=>t(t=>t.filter(t=>t.deviceId!==e));return(0,y.jsx)(`div`,{className:`h-full min-h-0 overflow-y-auto`,children:(0,y.jsxs)(`div`,{className:`mx-auto max-w-3xl p-6 pb-12 space-y-6`,children:[(0,y.jsx)(p,{compact:!0,title:`Devices`,onBack:m(),description:`All devices registered to your account. Link them to individual workspaces in Workspace › Settings › Devices.`,actions:(0,y.jsxs)(u,{type:`button`,variant:`outline`,size:`sm`,onClick:c,disabled:n,children:[(0,y.jsx)(i,{className:`mr-2 h-3.5 w-3.5 ${n?`animate-spin`:``}`}),`Refresh`]})}),n?(0,y.jsxs)(`div`,{className:`flex items-center gap-2 text-sm text-muted-foreground`,children:[(0,y.jsx)(i,{className:`h-4 w-4 animate-spin`}),`Loading…`]}):e.length===0?(0,y.jsxs)(`div`,{className:`rounded-lg border p-6 text-center text-sm text-muted-foreground space-y-2`,children:[(0,y.jsx)(o,{className:`h-8 w-8 mx-auto text-muted-foreground/40`}),(0,y.jsx)(`p`,{children:`No devices registered yet.`}),(0,y.jsxs)(`p`,{className:`text-xs`,children:[`Devices register themselves automatically on first connection via`,` `,(0,y.jsx)(`span`,{className:`font-mono`,children:`POST /auth/devices/register`}),`.`]})]}):(0,y.jsx)(`div`,{className:`space-y-2`,children:e.map(e=>(0,y.jsx)(b,{device:e,onUpdated:l,onRemoved:d},e.deviceId))}),e.length>0&&(0,y.jsxs)(`div`,{className:`flex items-center gap-2 rounded-md border border-dashed p-3 text-xs text-muted-foreground`,children:[(0,y.jsx)(s,{className:`h-3.5 w-3.5 shrink-0`}),`To link a device to a workspace, go to Workspace › Settings › Devices.`]})]})})}export{x as default};
1
+ import{o as e}from"./rolldown-runtime-C0FnF6B9.js";import{l as t,u as n}from"./code-editor-BOIngd5F.js";import{Bt as r,L as i,Wr as a,Xt as o,dt as s,kt as c,vn as l}from"./ui-76Hw0NU_.js";import{t as u}from"./button-Bum-POPT.js";import{t as d}from"./input-BOtCd4HP.js";import{n as f}from"./use-toast-BlLDqSUO.js";import{n as p}from"./page-header-BoCaZiqu.js";import{t as m}from"./use-settings-back-DE0SPb7h.js";import{i as h,n as g,o as _}from"./devices-CAa1bRxk.js";var v=e(n(),1),y=t();function b({device:e,onUpdated:t,onRemoved:n}){let[c,l]=(0,v.useState)(!1),[p,m]=(0,v.useState)(e.name),[g,b]=(0,v.useState)(e.description??``),[x,S]=(0,v.useState)(!1),[C,w]=(0,v.useState)(!1),[T,E]=(0,v.useState)(!1),{showToast:D}=f(),O=async()=>{E(!0);try{await h(e.deviceId),n(e.deviceId),D({title:`Revoked`,description:`${e.name} can no longer sign in; a running mirror stops on its next request.`})}catch(e){D({title:`Error`,description:e instanceof Error?e.message:`Failed to revoke device`,variant:`destructive`}),w(!1)}finally{E(!1)}},k=async()=>{let n=p.trim();if(n){if(n===e.name&&g.trim()===(e.description??``)){l(!1);return}S(!0);try{let r=await _(e.deviceId,{name:n,description:g.trim()||void 0});t({...e,...r}),l(!1),D({title:`Saved`,description:`Device updated`})}catch(e){D({title:`Error`,description:e instanceof Error?e.message:`Failed to update device`,variant:`destructive`})}finally{S(!1)}}},A=()=>{m(e.name),b(e.description??``),l(!1)},j=e=>e?new Date(e).toLocaleString(void 0,{dateStyle:`medium`,timeStyle:`short`}):`—`;return(0,y.jsx)(`div`,{className:`rounded-lg border p-4`,children:(0,y.jsxs)(`div`,{className:`flex items-start justify-between gap-4`,children:[(0,y.jsxs)(`div`,{className:`flex items-start gap-3 min-w-0`,children:[(0,y.jsx)(o,{className:`h-4 w-4 text-muted-foreground mt-0.5 shrink-0`}),(0,y.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[c?(0,y.jsxs)(`div`,{className:`space-y-2 mb-2`,children:[(0,y.jsx)(d,{value:p,onChange:e=>m(e.target.value),className:`h-7 text-sm`,placeholder:`Device name`,autoFocus:!0,disabled:x,onKeyDown:e=>{e.key===`Enter`&&k(),e.key===`Escape`&&A()}}),(0,y.jsx)(d,{value:g,onChange:e=>b(e.target.value),className:`h-7 text-xs`,placeholder:`Description (optional)`,disabled:x,onKeyDown:e=>{e.key===`Enter`&&k(),e.key===`Escape`&&A()}})]}):(0,y.jsxs)(`div`,{className:`mb-1`,children:[(0,y.jsx)(`span`,{className:`text-sm font-medium`,children:e.name}),e.description&&(0,y.jsx)(`p`,{className:`text-xs text-muted-foreground mt-0.5`,children:e.description})]}),(0,y.jsxs)(`div`,{className:`flex flex-wrap gap-x-3 gap-y-0.5 text-[11px] font-mono text-muted-foreground`,children:[(0,y.jsx)(`span`,{title:`Device ID`,children:e.deviceId}),e.platform&&(0,y.jsx)(`span`,{children:e.platform}),e.arch&&(0,y.jsx)(`span`,{children:e.arch}),e.type&&(0,y.jsx)(`span`,{className:`capitalize`,children:e.type})]}),(0,y.jsxs)(`div`,{className:`mt-2 flex flex-wrap gap-x-4 text-[11px] text-muted-foreground`,children:[e.createdAt&&(0,y.jsxs)(`span`,{children:[`registered `,j(e.createdAt)]}),e.updatedAt&&e.updatedAt!==e.createdAt&&(0,y.jsxs)(`span`,{children:[`updated `,j(e.updatedAt)]}),e.lastSeen&&(0,y.jsxs)(`span`,{children:[`seen `,j(e.lastSeen)]})]})]})]}),(0,y.jsx)(`div`,{className:`flex shrink-0 items-center gap-2`,children:C?(0,y.jsxs)(y.Fragment,{children:[(0,y.jsx)(u,{type:`button`,variant:`destructive`,size:`sm`,onClick:O,disabled:T,children:T?`Revoking…`:`Confirm revoke`}),(0,y.jsx)(u,{type:`button`,variant:`ghost`,size:`sm`,onClick:()=>w(!1),disabled:T,children:(0,y.jsx)(i,{className:`h-3.5 w-3.5`})})]}):c?(0,y.jsxs)(y.Fragment,{children:[(0,y.jsx)(u,{type:`button`,variant:`outline`,size:`sm`,onClick:k,disabled:x||!p.trim(),children:(0,y.jsx)(a,{className:`h-3.5 w-3.5`})}),(0,y.jsx)(u,{type:`button`,variant:`ghost`,size:`sm`,onClick:A,disabled:x,children:(0,y.jsx)(i,{className:`h-3.5 w-3.5`})})]}):(0,y.jsxs)(y.Fragment,{children:[(0,y.jsx)(u,{type:`button`,variant:`ghost`,size:`sm`,onClick:()=>l(!0),title:`Edit name / description`,children:(0,y.jsx)(r,{className:`h-3.5 w-3.5`})}),(0,y.jsx)(u,{type:`button`,variant:`ghost`,size:`sm`,onClick:()=>w(!0),title:`Revoke this device: its tokens stop working and its mirrors stop syncing`,children:(0,y.jsx)(s,{className:`h-3.5 w-3.5`})})]})})]})})}function x(){let[e,t]=(0,v.useState)([]),[n,r]=(0,v.useState)(!0),{showToast:i}=f(),a=async()=>{r(!0);try{t(await g())}catch(e){i({title:`Error`,description:e instanceof Error?e.message:`Failed to load devices`,variant:`destructive`})}finally{r(!1)}};(0,v.useEffect)(()=>{(async()=>{try{t(await g())}catch(e){i({title:`Error`,description:e instanceof Error?e.message:`Failed to load devices`,variant:`destructive`})}finally{r(!1)}})()},[i]);let s=e=>t(t=>t.map(t=>t.deviceId===e.deviceId?e:t)),d=e=>t(t=>t.filter(t=>t.deviceId!==e));return(0,y.jsx)(`div`,{className:`h-full min-h-0 overflow-y-auto`,children:(0,y.jsxs)(`div`,{className:`mx-auto max-w-3xl p-6 pb-12 space-y-6`,children:[(0,y.jsx)(p,{compact:!0,title:`Devices`,onBack:m(),description:`All devices registered to your account. Link them to individual workspaces in Workspace › Settings › Devices.`,actions:(0,y.jsxs)(u,{type:`button`,variant:`outline`,size:`sm`,onClick:a,disabled:n,children:[(0,y.jsx)(c,{className:`mr-2 h-3.5 w-3.5 ${n?`animate-spin`:``}`}),`Refresh`]})}),n?(0,y.jsxs)(`div`,{className:`flex items-center gap-2 text-sm text-muted-foreground`,children:[(0,y.jsx)(c,{className:`h-4 w-4 animate-spin`}),`Loading…`]}):e.length===0?(0,y.jsxs)(`div`,{className:`rounded-lg border p-6 text-center text-sm text-muted-foreground space-y-2`,children:[(0,y.jsx)(o,{className:`h-8 w-8 mx-auto text-muted-foreground/40`}),(0,y.jsx)(`p`,{children:`No devices registered yet.`}),(0,y.jsxs)(`p`,{className:`text-xs`,children:[`Devices register themselves automatically on first connection via`,` `,(0,y.jsx)(`span`,{className:`font-mono`,children:`POST /auth/devices/register`}),`.`]})]}):(0,y.jsx)(`div`,{className:`space-y-2`,children:e.map(e=>(0,y.jsx)(b,{device:e,onUpdated:s,onRemoved:d},e.deviceId))}),e.length>0&&(0,y.jsxs)(`div`,{className:`flex items-center gap-2 rounded-md border border-dashed p-3 text-xs text-muted-foreground`,children:[(0,y.jsx)(l,{className:`h-3.5 w-3.5 shrink-0`}),`To link a device to a workspace, go to Workspace › Settings › Devices.`]})]})})}export{x as default};
@@ -1 +1 @@
1
- import{o as e}from"./rolldown-runtime-C0FnF6B9.js";import{l as t,u as n}from"./code-editor-BOIngd5F.js";import{_ as r,g as i,h as a}from"./chunk-62JRHF6Z-vspAGgtK.js";import{t as o}from"./button-SgR3GVvV.js";import{An as s,nt as c,rt as l}from"./workspace-CrSpR4xf.js";import{t as u,u as d}from"./ObjectPropertiesCard-BIBMvx_i.js";import{t as f}from"./url-params-n7kU_WZ-.js";import{i as p}from"./use-menu-BiJ8N7sS.js";import{t as m}from"./workspace-content-gate-9okuA7J7.js";import{t as h}from"./use-workspace-identity-BCrrvfeE.js";var g=e(n(),1),_=t();function v(){let{workspaceName:e}=r();return e?(0,_.jsx)(m,{workspaceName:e,children:(0,_.jsx)(y,{})}):(0,_.jsx)(`p`,{role:`alert`,className:`p-6`,children:`Workspace not specified.`})}function y(){let{workspaceName:e=``,documentId:t=``,algo:n=``,checksum:m=``}=r(),v=i(),y=a(),{goBack:b,openM1Drawer:x,openM2Drawer:S}=p(),C=h(e),w=!!n&&!!m,T=w?`${n}/${m}`:t,E=JSON.stringify([e,t,n,m]),D=Number(t),O=/^\d+$/.test(t)&&Number.isSafeInteger(D)&&D>0,k=w||O,[A,j]=(0,g.useState)(0),[M,N]=(0,g.useState)(null),P=M?.identity===E?M:null,F=k&&(!P||P.revision!==A);(0,g.useEffect)(()=>{let t=!1;if(k)return(w?l(e,n,m):c(e,D)).then(e=>{t||N({identity:E,revision:A,document:e||null,missing:!e,error:``})}).catch(e=>{t||N({identity:E,revision:A,document:null,missing:e?.statusCode===404,error:e instanceof Error?e.message:`Unable to retrieve this document.`})}),()=>{t=!0}},[e,D,E,A,k,w,n,m]);let I={workspace:C?.label||e,workspaceIcon:C?.icon,path:`/`,tree:`context`,document:P?.document?s(P.document).title:`Document ${T}`,onBack:b,onBrowseWorkspaces:()=>x(`workspaces`),onBrowseTree:()=>S(`workspaces`,`detail`,e),onNavigatePath:t=>v(f(e,t,`context`))},L=y.hash.slice(1),R=[`view`,`location`,`metadata`,`json`,`synapses`,`backends`].includes(L)?L:`view`;return(0,_.jsxs)(`div`,{className:`flex h-full min-h-0 flex-col`,children:[!P?.document&&(0,_.jsx)(d,{...I}),P?.document?(0,_.jsx)(u,{document:P.document,workspaceId:e,onChanged:()=>j(e=>e+1),navigation:I,initialTab:R,onTabChange:e=>v(`${y.pathname}${y.search}#${e}`,{replace:!0}),tabActions:(0,_.jsx)(o,{variant:`ghost`,disabled:F,onClick:()=>j(e=>e+1),children:`Refresh`})},E):F?(0,_.jsx)(`p`,{role:`status`,className:`p-6 text-sm text-muted-foreground`,children:`Loading document…`}):(0,_.jsxs)(`div`,{role:`alert`,className:`space-y-2 p-6 text-sm`,children:[(0,_.jsx)(`p`,{className:`font-medium`,children:P?.missing?`Document ${T} not found`:`Unable to load document`}),k&&(0,_.jsx)(o,{variant:`outline`,onClick:()=>j(e=>e+1),children:`Retry`}),(0,_.jsx)(`p`,{className:`text-muted-foreground`,children:k?P?.missing?`This record is no longer available in this workspace. Subtree exports skip missing records and report their IDs.`:P?.error:`Document ID must be a positive integer.`})]})]})}export{v as default};
1
+ import{o as e}from"./rolldown-runtime-C0FnF6B9.js";import{l as t,u as n}from"./code-editor-BOIngd5F.js";import{_ as r,g as i,h as a}from"./chunk-62JRHF6Z-vspAGgtK.js";import{t as o}from"./button-Bum-POPT.js";import{An as s,nt as c,rt as l}from"./workspace-BuoZwRL5.js";import{t as u,u as d}from"./ObjectPropertiesCard-CkcQp_zW.js";import{t as f}from"./url-params-n7kU_WZ-.js";import{i as p}from"./use-menu-CaiLyPdw.js";import{t as m}from"./workspace-content-gate-CaCJlWnb.js";import{t as h}from"./use-workspace-identity-B_8AUozT.js";var g=e(n(),1),_=t();function v(){let{workspaceName:e}=r();return e?(0,_.jsx)(m,{workspaceName:e,children:(0,_.jsx)(y,{})}):(0,_.jsx)(`p`,{role:`alert`,className:`p-6`,children:`Workspace not specified.`})}function y(){let{workspaceName:e=``,documentId:t=``,algo:n=``,checksum:m=``}=r(),v=i(),y=a(),{goBack:b,openM1Drawer:x,openM2Drawer:S}=p(),C=h(e),w=!!n&&!!m,T=w?`${n}/${m}`:t,E=JSON.stringify([e,t,n,m]),D=Number(t),O=/^\d+$/.test(t)&&Number.isSafeInteger(D)&&D>0,k=w||O,[A,j]=(0,g.useState)(0),[M,N]=(0,g.useState)(null),P=M?.identity===E?M:null,F=k&&(!P||P.revision!==A);(0,g.useEffect)(()=>{let t=!1;if(k)return(w?l(e,n,m):c(e,D)).then(e=>{t||N({identity:E,revision:A,document:e||null,missing:!e,error:``})}).catch(e=>{t||N({identity:E,revision:A,document:null,missing:e?.statusCode===404,error:e instanceof Error?e.message:`Unable to retrieve this document.`})}),()=>{t=!0}},[e,D,E,A,k,w,n,m]);let I={workspace:C?.label||e,workspaceIcon:C?.icon,path:`/`,tree:`context`,document:P?.document?s(P.document).title:`Document ${T}`,onBack:b,onBrowseWorkspaces:()=>x(`workspaces`),onBrowseTree:()=>S(`workspaces`,`detail`,e),onNavigatePath:t=>v(f(e,t,`context`))},L=y.hash.slice(1),R=[`view`,`location`,`metadata`,`json`,`synapses`,`backends`].includes(L)?L:`view`;return(0,_.jsxs)(`div`,{className:`flex h-full min-h-0 flex-col`,children:[!P?.document&&(0,_.jsx)(d,{...I}),P?.document?(0,_.jsx)(u,{document:P.document,workspaceId:e,onChanged:()=>j(e=>e+1),navigation:I,initialTab:R,onTabChange:e=>v(`${y.pathname}${y.search}#${e}`,{replace:!0}),tabActions:(0,_.jsx)(o,{variant:`ghost`,disabled:F,onClick:()=>j(e=>e+1),children:`Refresh`})},E):F?(0,_.jsx)(`p`,{role:`status`,className:`p-6 text-sm text-muted-foreground`,children:`Loading document…`}):(0,_.jsxs)(`div`,{role:`alert`,className:`space-y-2 p-6 text-sm`,children:[(0,_.jsx)(`p`,{className:`font-medium`,children:P?.missing?`Document ${T} not found`:`Unable to load document`}),k&&(0,_.jsx)(o,{variant:`outline`,onClick:()=>j(e=>e+1),children:`Retry`}),(0,_.jsx)(`p`,{className:`text-muted-foreground`,children:k?P?.missing?`This record is no longer available in this workspace. Subtree exports skip missing records and report their IDs.`:P?.error:`Document ID must be a positive integer.`})]})]})}export{v as default};
@@ -0,0 +1,2 @@
1
+ const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/subtree-transfer-dialog-BN9xBB9n.js","assets/rolldown-runtime-C0FnF6B9.js","assets/code-editor-BOIngd5F.js","assets/react-BHzhHVTZ.js","assets/ui-76Hw0NU_.js","assets/button-Bum-POPT.js","assets/utils-BxVxyehK.js","assets/utils-2pl1SbIp.js","assets/input-BOtCd4HP.js","assets/api-CA6WiiYM.js","assets/alert-dialog-CShuAcnP.js"])))=>i.map(i=>d[i]);
2
+ import{o as e,r as t}from"./rolldown-runtime-C0FnF6B9.js";import{l as n,u as r}from"./code-editor-BOIngd5F.js";import{vt as i,yt as a}from"./react-BHzhHVTZ.js";import{t as o}from"./preload-helper-Czpn1I53.js";import{g as s}from"./chunk-62JRHF6Z-vspAGgtK.js";import{$ as c,Ar as l,Bn as u,Br as d,Bt as f,Cr as p,Ct as m,Hr as h,It as g,Jt as _,Kn as v,Kr as y,L as b,Lt as x,Pt as S,Qn as C,Qt as w,Rt as ee,Tr as T,Tt as te,Un as ne,Vr as re,Vt as E,W as D,Wt as ie,X as ae,_n as oe,_r as O,an as se,ar as ce,cn as k,cr as le,di as ue,fr as de,gr as fe,lr as pe,mi as me,mr as he,ot as ge,pn as _e,qr as ve,rt as ye,si as be,st as xe,tt as A,vn as Se,vr as Ce,xn as we,xt as Te,yn as Ee,yt as De,zn as j,zr as Oe}from"./ui-76Hw0NU_.js";import{t as M}from"./utils-2pl1SbIp.js";import{t as N}from"./button-Bum-POPT.js";import{t as ke}from"./socket-CtH3EU9m.js";import{n as Ae}from"./use-toast-BlLDqSUO.js";import{c as je,d as Me,f as Ne,h as Pe,l as Fe,p as Ie,t as Le,u as Re}from"./LinkToCard-bUXz_atc.js";import{$ as ze,An as P,Bt as Be,Dn as Ve,Ft as He,It as Ue,Lt as F,Mn as We,Ot as Ge,P as Ke,Sn as qe,Tn as Je,Un as Ye,Vt as Xe,Wt as Ze,Xt as Qe,Yt as $e,_ as et,_n as tt,bn as nt,bt as rt,dt as it,gn as at,gt as ot,h as I,hn as st,ht as ct,i as lt,it as ut,jn as dt,jt as ft,k as pt,l as L,ln as R,m as z,mn as mt,nt as B,o as ht,s as gt,un as _t,wn as vt,zt as yt}from"./workspace-BuoZwRL5.js";import{a as bt,b as xt,c as St,f as Ct,l as wt,o as Tt,s as V,t as Et,v as Dt}from"./ObjectPropertiesCard-CkcQp_zW.js";import{i as Ot,n as kt,s as At}from"./document-open-mode-DoImW-xs.js";import{t as jt}from"./use-mobile-Db-vWu9Y.js";import{c as Mt,s as Nt}from"./IdentityFields-D13Y3wzc.js";import{i as Pt}from"./public-share-C3a_DycQ.js";import{o as Ft,s as It}from"./text-documents-BJ17V0oY.js";import{t as H}from"./useDocumentThumbnail-BpvX3fx0.js";import{t as Lt}from"./markdown-view-BBBZtNSR.js";import{n as Rt}from"./tags-YamdPoBK.js";import{r as zt}from"./use-toolbox-Ck_cLGgf.js";import{C as Bt,S as Vt,T as Ht,g as Ut,h as Wt,m as Gt,t as Kt,u as qt,y as Jt}from"./context-DVlMC9Bk.js";import{n as Yt}from"./relation-events-CKio19hE.js";import{n as Xt,t as Zt}from"./PickDocumentsCard-BQwJdHA9.js";import{t as U}from"./useEscapeClose-DR_xKT_k.js";import{t as Qt}from"./useToastHelpers-CRrpIIdY.js";import{u as $t}from"./layer-style-Byl5LNFR.js";import{t as W}from"./DocumentIcon-ByDAILhm.js";import{n as en,t as tn}from"./LinkToSidePanel-eCy3nW4R.js";import{C as nn,W as rn,c as an,d as on,i as sn,k as cn,s as ln,t as un,z as dn}from"./backend-sync-progress-CRHe59pS.js";import{t as fn}from"./workspace-access-C9nZlBBZ.js";import{t as pn}from"./search-COMZIxA7.js";import{a as G,c as mn,i as hn,n as gn,o as _n,r as vn,s as yn,t as bn}from"./use-sortable-data-W2inLcb5.js";import{n as xn}from"./workspace-BydSRtST.js";var K=e(r(),1),Sn=(0,K.createContext)(null),Cn=()=>(0,K.useContext)(Sn),wn=`canvas:readerWidth`,q=320,Tn=1600;function En(){try{let e=Number(sessionStorage.getItem(wn));return Number.isFinite(e)&&e>=q&&e<=Tn?e:null}catch{return null}}var Dn=En(),On=new Set;function kn(e){return On.add(e),()=>{On.delete(e)}}function An(e){Dn=e===null?null:Math.round(Math.max(q,Math.min(Tn,e)));try{Dn===null?sessionStorage.removeItem(wn):sessionStorage.setItem(wn,String(Dn))}catch{}On.forEach(e=>e())}function jn(){return(0,K.useSyncExternalStore)(kn,()=>Dn,()=>null)}function Mn(e,t){let[n,r]=(0,K.useState)(null),i=t?.id??null,a=`${e}:${i}`,[o,s]=(0,K.useState)(a);a!==o&&(s(a),r(null));let c=(0,K.useRef)(a),l=(0,K.useRef)(0);(0,K.useEffect)(()=>(c.current=a,l.current++,()=>{c.current=``}),[a]);let u=n?.id??i,d=(0,K.useCallback)(t=>{if(!e||u==null||c.current!==a)return;let n=++l.current;if(t){r(t);return}B(e,u).then(e=>{c.current===a&&l.current===n&&e&&r(e)}).catch(()=>{})},[e,u,a]);return{document:n??t,refresh:d}}var J=n();function Nn(e){return e.schema===`data/schema/note`?A:e.schema===`data/schema/tab`?oe:e.schema===`data/schema/file`?ce:e.schema===`data/schema/message/email`?k:pe}function Pn({entry:e,onClose:t,frame:n}={}){let r=Tt(),i=e??r.entry,a=t??r.close,{document:o,refresh:s}=Mn(i?.workspaceId,i?.document??null);if(!i||!o)return!e&&(r.loading||r.error)?(0,J.jsxs)(`div`,{className:`flex h-full w-full flex-col overflow-hidden rounded-(--card-radius) border bg-card`,children:[(0,J.jsxs)(`div`,{className:`flex h-[calc(3rem-1px)] shrink-0 items-center justify-between border-b-[3px] bg-muted pl-4 pr-2`,children:[(0,J.jsx)(`span`,{className:`text-sm`,children:`Document`}),(0,J.jsx)(`button`,{type:`button`,onClick:a,className:`flex h-8 w-8 items-center justify-center rounded hover:bg-accent`,"aria-label":`Close`,children:(0,J.jsx)(b,{className:`h-4 w-4`})})]}),(0,J.jsxs)(`div`,{className:`p-4 text-sm`,role:r.error?`alert`:`status`,children:[r.error||`Loading document…`,r.error&&(0,J.jsx)(`button`,{type:`button`,className:`ml-2 underline`,onClick:r.retry,children:`Retry`})]})]}):null;let{workspaceId:c}=i,l=t=>{s(t),t&&t.id!==i.document.id&&!e&&r.replace?.(t,c)};return(0,J.jsx)(Xt,{title:P(o).title,icon:Nn(o),onClose:a,onSave:async e=>(await Be(c,e.path,[o.id],e.treeName,e.treeType),[o.id]),canSave:!0,successMessage:`Linked`,lockedWorkspaceName:c,relationSubjectId:o.id,frame:n,fillParent:!0,fullWidthContent:Ct(o)===Dt,maximized:e?void 0:r.location?.maximized,onMaximizedChange:e?void 0:e=>r.update?.({maximized:e}),children:t=>(0,J.jsx)(`div`,{className:`document-side-content h-full min-h-0 min-w-0 w-full`,children:(0,J.jsx)(Et,{document:o,workspaceId:c,onChanged:l,compact:!0,tabActions:t,initialTab:e?void 0:r.location?.section,onTabChange:e?void 0:e=>r.update?.({section:e})},`${c}:${o.id}`)})})}var Fn=320,In=1600;function Ln({edge:e}){let t=jn(),n=(0,K.useRef)(null),r=e===`left`?-1:1;return(0,J.jsx)(`div`,{role:`separator`,"aria-label":`Resize document reader`,"aria-orientation":`vertical`,"aria-valuemin":Fn,"aria-valuemax":In,"aria-valuenow":t??420,tabIndex:0,title:`Drag to resize; arrow keys adjust width; double-click to reset`,className:`absolute inset-y-0 ${e===`left`?`left-0`:`right-0`} z-20 hidden w-2 touch-none cursor-col-resize select-none hover:bg-primary/20 focus-visible:bg-primary/20 focus-visible:outline-none md:block`,onPointerDown:t=>{if(t.button!==0)return;t.preventDefault(),t.stopPropagation();let r=t.currentTarget.closest(`[data-reader-pane]`),i=e===`left`?(r.parentElement?.clientWidth??window.innerWidth)-248:window.innerWidth;n.current={x:t.clientX,width:r.getBoundingClientRect().width,max:Math.max(Fn,i)},t.currentTarget.setPointerCapture(t.pointerId)},onPointerMove:e=>{n.current&&An(Math.min(n.current.max,n.current.width+r*(e.clientX-n.current.x)))},onPointerUp:e=>{n.current=null,e.currentTarget.hasPointerCapture(e.pointerId)&&e.currentTarget.releasePointerCapture(e.pointerId)},onPointerCancel:()=>{n.current=null},onLostPointerCapture:()=>{n.current=null},onDoubleClick:()=>An(null),onKeyDown:e=>{if(e.key!==`ArrowLeft`&&e.key!==`ArrowRight`&&e.key!==`Home`)return;e.preventDefault(),e.stopPropagation();let t=e.currentTarget.closest(`[data-reader-pane]`);e.key===`Home`?An(null):An(t.getBoundingClientRect().width+(e.key===`ArrowRight`?1:-1)*r*(e.shiftKey?64:16))}})}function Rn(e){let t=Cn(),n=Ot(),r=jt(),i=Tt();return!e.enabled||!e.workspaceId||r||t?.compact||i.location?e.children:(0,J.jsx)(zn,{...e,workspaceId:e.workspaceId,autoOpen:n},`${e.scope}:${n}`)}function zn({workspaceId:e,scope:t,documents:n,loading:r,children:i,autoOpen:a}){let o=jn(),[s,c]=(0,K.useState)(a),l=`canvas:readerSelection:${t}`,[u,d]=(0,K.useState)(()=>{try{return Number(sessionStorage.getItem(l))||null}catch{return null}}),f=!s||r?null:n.find(e=>e.id===u)??n[0]??null,p=(0,K.useCallback)((t,n)=>{if(n===e){c(!0),d(t.id);try{sessionStorage.setItem(l,String(t.id))}catch{}}},[e,l]),m=(0,K.useMemo)(()=>({entry:f?{document:f,workspaceId:e}:null,alwaysOn:!0,open:p,preview:p,replace:p,close:()=>c(!1)}),[f,e,p]);return(0,J.jsx)(bt.Provider,{value:m,children:(0,J.jsxs)(`div`,{"data-always-reader":!0,className:`flex h-full min-h-0 min-w-0 flex-1 gap-shell`,children:[(0,J.jsx)(`div`,{className:`min-h-0 min-w-0 flex-1 overflow-auto`,children:i}),s&&(0,J.jsxs)(`aside`,{"data-reader-pane":!0,"aria-label":`Document reading pane`,style:{width:o?`${o}px`:`50vw`,maxWidth:`calc(100% - 240px)`},className:`relative flex min-h-0 min-w-0 shrink-0 overflow-hidden border-l bg-card`,children:[(0,J.jsx)(Ln,{edge:`left`}),f?(0,J.jsx)(Pn,{},`${e}:${f.id}`):(0,J.jsx)(`div`,{className:`flex flex-1 items-center justify-center p-6 text-sm text-muted-foreground`,role:`status`,children:r?`Loading documents…`:`No documents in this list`})]})]})})}async function Bn(e,t,n){let r={successful:[],failed:[],pending:[]},i=[...new Set(e)],a=0;n.onProgress(0,i.length);for(let e of i){if(n.shouldStop())break;try{let n=await t([e]);r.successful.push(...n.successful),r.failed.push(...n.failed)}catch(t){r.failed.push({id:e,reason:t instanceof Error?t.message:String(t)}),a++,n.onProgress(a,i.length);break}a++,n.onProgress(a,i.length)}return r.pending=i.slice(a),r}function Vn(e){let t=[],n=!1;return{text:e.replace(/"[^"]*"|(^|\s)@id:([^\s]*)/g,(e,r,i)=>{if(i===void 0)return e;let a=i.replace(/^#/,``),o=Number(a);return!/^\d+$/.test(a)||!Number.isInteger(o)||o<=0||o>4294967295?n=!0:t.push(o),r}).trim(),ids:t,invalid:n}}function Hn(){let e,t,n=!1,r=()=>{clearTimeout(e),e=void 0,t=void 0};return{cancel:r,start(i,a,o){r(),n=!1,t={x:i,y:a},e=setTimeout(()=>{e=void 0,n=!0,o()},500)},move(e,n){t&&Math.hypot(e-t.x,n-t.y)>10&&r()},consumeClick(){let e=n;return n=!1,e},contextMenu(){let e=n;return t&&(n=!0),r(),e},reset(){r(),n=!1}}}function Un(){let[e]=(0,K.useState)(Hn);return(0,K.useEffect)(()=>e.cancel,[e]),{onPointerDown:t=>{if(e.reset(),t.pointerType!==`touch`||!t.isPrimary)return;let n=t.target;if(!t.currentTarget.contains(n)||n.closest(`button, input, textarea, select, a, [contenteditable="true"], [role="dialog"]`))return;let{clientX:r,clientY:i}=t;e.start(r,i,()=>{n.dispatchEvent(new window.MouseEvent(`contextmenu`,{bubbles:!0,cancelable:!0,clientX:r,clientY:i}))})},onPointerMove:t=>e.move(t.clientX,t.clientY),onPointerUp:e.cancel,onPointerCancel:e.cancel,onPointerLeave:e.cancel,onDragStartCapture:t=>{e.cancel(),e.consumeClick()&&t.preventDefault()},onContextMenuCapture:t=>{t.isTrusted&&e.contextMenu()&&(t.preventDefault(),t.stopPropagation())},onClickCapture:t=>{e.consumeClick()&&(t.preventDefault(),t.stopPropagation())}}}function Wn(e,t,n,r,i=!1){let a=e.indexOf(n);if(a<0)return new Set(r);let o=t===null?-1:e.indexOf(t),s=o<0?a:o,c=i?new Set(r):new Set;for(let t of e.slice(Math.min(s,a),Math.max(s,a)+1))c.add(t);return c}var Y=e=>typeof e==`string`?e:``,X=e=>e&&typeof e==`object`?e:{},Z=e=>e.replace(/[.*+?^${}()|[\]\\]/g,`\\$&`).replace(/\r/g,`\\r`).replace(/\n/g,`\\n`).replace(/\t/g,`\\t`);function Gn(e){let t=e.data||{},n=e.schema===`data/schema/message/email`,r=!n&&e.schema.startsWith(`data/schema/message`),i=Y(t.platform),a=Y(X(t.channel).id)||Y(t.channel),o=[],s=(t,n,r)=>o.push({id:t,label:n,rule:{id:``,description:n,enabled:!0,when:{event:`document.inserted`,schema:e.schema,...r},then:[{action:`link`,paths:[]}]}}),c=i?{platform:{equals:i}}:{};if(n){let e=Y(X(t.from).address)||Y(t.from);e&&s(`sender`,`Mail from ${e}`,{from:{equals:e}}),t.subject&&s(`subject`,`Subject matches regex`,{subject:{regex:Z(t.subject)}})}else if(r){let e=Y(X(t.sender).id)||Y(X(t.sender).username)||Y(X(t.sender).name)||Y(t.sender),n=Y(X(t.sender).name)||Y(X(t.sender).username)||e;e&&s(`sender`,`Messages from ${n}`,{...c,sender:{equals:e}})}let l=Y(t.body)||Y(t.text)||Y(t.content)||Y(t.bodyHtml)||Y(t.bodyPreview);if((n||r||l)&&s(`body`,n?`Email body matches regex`:`Text matches regex`,{...c,body:{regex:Z(l.slice(0,160))}}),r){let n=Y(t.threadId)||([`slack`,`teams`].includes(i)?Y(X(e.metadata).remoteId):``);n&&a&&s(`thread`,`Messages in this thread`,{...c,channel:{equals:a},thread:{equals:n}}),a&&s(`channel`,i===`whatsapp`?`Messages in this conversation`:`Messages in this channel`,{...c,channel:{equals:a}})}return t.url&&s(`url`,`URL matches regex`,{url:{regex:Z(t.url)}}),s(`schema`,`All items of this type`,{}),o}var Kn=e(a(),1);function qn({label:e,onClose:t,children:n}){return U(t),(0,Kn.createPortal)((0,J.jsx)(`div`,{className:`fixed inset-0 z-dialog flex items-center justify-center bg-scrim p-4`,onClick:t,children:(0,J.jsx)(`section`,{"data-dialog-surface":!0,role:`dialog`,"aria-modal":`true`,"aria-label":e,className:`h-[86dvh] max-h-full min-h-0 w-full max-w-3xl overflow-y-auto rounded-(--panel-radius) border bg-popover text-popover-foreground shadow-elevation-4`,onClick:e=>e.stopPropagation(),children:n})}),window.document.body)}function Jn({workspaceId:e,document:t,onClose:n}){let[r,i]=(0,K.useState)(null),[a,o]=(0,K.useState)(``),[s,c]=(0,K.useState)(``);U(n),(0,K.useEffect)(()=>{let n=!1;return(async()=>{let r=await ze(e);if(!fn(r))throw Error(`Only workspace administrators can create rules.`);let a=await B(e,t.id);n||i(a)})().catch(e=>{n||o(e instanceof Error?e.message:`Could not load document`)}),()=>{n=!0}},[e,t.id]);let l=(0,K.useMemo)(()=>r?Gn(r):[],[r]),u=l.find(e=>e.id===s)||l[0],d=(0,K.useMemo)(()=>u?{kind:`document`,rule:u.rule}:null,[u]);return(0,J.jsx)(qn,{label:`Create rule`,onClose:n,children:(0,J.jsxs)(`div`,{className:`p-5`,children:[(0,J.jsxs)(`div`,{className:`mb-4 flex items-start justify-between gap-3`,children:[(0,J.jsxs)(`div`,{className:`min-w-0`,children:[(0,J.jsx)(`h2`,{id:`document-rule-title`,className:`text-lg font-semibold`,children:`Create rule`}),(0,J.jsx)(`p`,{className:`truncate text-sm text-muted-foreground`,children:P(t).title})]}),(0,J.jsx)(`button`,{type:`button`,"aria-label":`Close`,onClick:n,className:`rounded-md p-2 hover:bg-accent`,children:(0,J.jsx)(b,{className:`h-4 w-4`})})]}),a?(0,J.jsx)(`p`,{role:`alert`,className:`text-sm text-destructive`,children:a}):r?(0,J.jsxs)(J.Fragment,{children:[(0,J.jsxs)(`label`,{className:`mb-4 block space-y-2 text-sm font-medium`,children:[(0,J.jsx)(`span`,{children:`Start with`}),(0,J.jsx)(`select`,{className:`h-10 w-full rounded-md border bg-background px-3`,value:u?.id,onChange:e=>c(e.target.value),children:l.map(e=>(0,J.jsx)(`option`,{value:e.id,children:e.label},e.id))})]}),(0,J.jsx)(on,{workspaceId:e,prefill:d,createOnly:!0,onCreated:n,onCancel:n})]}):(0,J.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`Loading document…`})]})})}function Yn(e,t){return{left:Math.min(e.x,t.x),top:Math.min(e.y,t.y),width:Math.abs(t.x-e.x),height:Math.abs(t.y-e.y)}}function Xn(e,t){return e.left<t.left+t.width&&e.left+e.width>t.left&&e.top<t.top+t.height&&e.top+e.height>t.top}function Zn(e,t,n,r){let i=new Set(r?n:[]);for(let n of t)Xn(e,n.bounds)&&i.add(n.id);return i}var Qn=`[data-document-id], button, a, input, textarea, select, [contenteditable]:not([contenteditable="false"]), [role="button"], [role="dialog"], [role="menu"], [draggable="true"], thead, [data-selection-ignore]`;function $n(e,t){let n=e.ownerDocument.defaultView,r=null,i=null,a=0,o=0,s=!1,c=!1,l=``,u=()=>{let t=e.getBoundingClientRect();return{left:t.left+e.clientLeft,top:t.top+e.clientTop,width:e.clientWidth,height:e.clientHeight}},d=t=>{let n=u();return{x:Math.max(0,Math.min(n.width,t.x-n.left))+e.scrollLeft,y:Math.max(0,Math.min(n.height,t.y-n.top))+e.scrollTop}},f=()=>{if(!r?.active||!i)return;let n=Yn(r.start,d(r.client));Object.assign(i.style,{left:`${n.left}px`,top:`${n.top}px`,width:`${n.width}px`,height:`${n.height}px`});let a=u(),o=Array.from(e.querySelectorAll(`[data-document-id]`)).filter(e=>e.getClientRects().length>0).map(t=>{let n=t.getBoundingClientRect();return{id:Number(t.dataset.documentId),bounds:{left:n.left-a.left+e.scrollLeft,top:n.top-a.top+e.scrollTop,width:n.width,height:n.height}}});t.onSelectionChange(Zn(n,o,r.initial,r.additive))},p=(e,t,n)=>{let r=Math.min(40,n/4);return e<t+r?-18*Math.min(1,(t+r-e)/r):e>t+n-r?18*Math.min(1,(e-t-n+r)/r):0},m=t=>{if(!r?.active)return;let i=u(),c=o?Math.min(2,(t-o)/(1e3/60)):1;o=t;let{scrollTop:l,scrollLeft:d}=e;e.scrollTop+=p(r.client.y,i.top,i.height)*c,e.scrollLeft+=p(r.client.x,i.left,i.width)*c,(s||e.scrollTop!==l||e.scrollLeft!==d)&&(f(),s=!1),a=n.requestAnimationFrame(m)},h=(s=!1)=>{if(!r)return;let u=r;r=null,n.cancelAnimationFrame(a),a=0,o=0,i?.remove(),i=null,u.active&&(e.style.userSelect=l,c=!0,s&&t.onSelectionChange(u.initial)),e.hasPointerCapture(u.pointerId)&&e.releasePointerCapture(u.pointerId)},g=n=>{if(c=!1,r||n.button!==0||!n.isPrimary||n.pointerType===`touch`)return;let i=n.target;if(!e.contains(i)||i.closest(Qn))return;let a=u();if(n.clientX<a.left||n.clientX>=a.left+a.width||n.clientY<a.top||n.clientY>=a.top+a.height)return;let o={x:n.clientX,y:n.clientY};r={pointerId:n.pointerId,start:d(o),clientStart:o,client:o,initial:new Set(t.getSelection()),additive:n.ctrlKey||n.metaKey||n.shiftKey,active:!1},n.preventDefault(),e.focus({preventScroll:!0}),e.setPointerCapture(n.pointerId)},_=t=>{if(!(!r||t.pointerId!==r.pointerId)){if(!(t.buttons&1)){h();return}if(r.client={x:t.clientX,y:t.clientY},!r.active){if(Math.hypot(t.clientX-r.clientStart.x,t.clientY-r.clientStart.y)<4)return;r.active=!0,l=e.style.userSelect,e.style.userSelect=`none`,n.getSelection()?.removeAllRanges(),i=e.ownerDocument.createElement(`div`),i.setAttribute(`aria-hidden`,`true`),i.dataset.selectionRectangle=``,i.className=`pointer-events-none absolute z-20 border border-info bg-info/15`,e.append(i),a=n.requestAnimationFrame(m)}s=!0,t.preventDefault()}},v=e=>{!r||e.pointerId!==r.pointerId||(r.client={x:e.clientX,y:e.clientY},r.active?f():r.additive||t.onSelectionChange(new Set),h())},y=()=>h(!0),b=e=>{e.pointerId===r?.pointerId&&y()},x=e=>{r&&e.key===`Escape`&&(e.preventDefault(),e.stopPropagation(),y())},S=e=>{c&&(c=!1,e.preventDefault(),e.stopImmediatePropagation())},C=()=>{s=!0};return e.addEventListener(`pointerdown`,g),e.addEventListener(`pointermove`,_),e.addEventListener(`pointerup`,v),e.addEventListener(`pointercancel`,b),e.addEventListener(`lostpointercapture`,b),e.addEventListener(`click`,S,!0),e.addEventListener(`scroll`,C,!0),n.addEventListener(`keydown`,x,!0),n.addEventListener(`blur`,y),()=>{h(),e.removeEventListener(`pointerdown`,g),e.removeEventListener(`pointermove`,_),e.removeEventListener(`pointerup`,v),e.removeEventListener(`pointercancel`,b),e.removeEventListener(`lostpointercapture`,b),e.removeEventListener(`click`,S,!0),e.removeEventListener(`scroll`,C,!0),n.removeEventListener(`keydown`,x,!0),n.removeEventListener(`blur`,y)}}function er({scope:e,selected:t,onSelectionChange:n,onContextMenu:r,children:i}){let a=(0,K.useRef)(null),o=(0,K.useRef)({selected:t,onSelectionChange:n});return(0,K.useLayoutEffect)(()=>{o.current={selected:t,onSelectionChange:n}},[t,n]),(0,K.useLayoutEffect)(()=>{if(a.current)return $n(a.current,{getSelection:()=>o.current.selected,onSelectionChange:e=>o.current.onSelectionChange(e)})},[e]),(0,J.jsx)(`div`,{ref:a,tabIndex:-1,"data-document-selection-area":``,onContextMenu:r,className:`relative isolate min-h-0 min-w-0 flex-1 overflow-auto p-2 outline-none`,children:i})}function tr(e){let t=2166136261;for(let e of localStorage.getItem(`authToken`)||``)t=Math.imul(t^e.charCodeAt(0),16777619);return`canvas:workspace-copy:${t>>>0}:${e}`}function nr({workspaceId:e,ids:t,onClose:n,modal:r=!1}){let{showProgress:i}=Ae();U(n,r);let[a]=(0,K.useState)(()=>{try{return tr(e)}catch{return``}}),[o,s]=(0,K.useState)(()=>{try{let e=JSON.parse(localStorage.getItem(a)||`null`);return e&&Array.isArray(e.ids)&&e.target&&e.index<e.ids.length?e:null}catch{return null}}),[c,l]=(0,K.useState)(!1),[u,d]=(0,K.useState)(``),f=(0,K.useRef)(!1),p=(0,K.useRef)(!1);(0,K.useEffect)(()=>(f.current=!1,()=>{f.current=!0}),[]);let m=e=>{try{e.index>=e.ids.length?localStorage.removeItem(a):localStorage.setItem(a,JSON.stringify(e))}catch{}f.current||s(e)},h=async t=>{if(p.current)return;p.current=!0,l(!0),d(``);let n=t,r=()=>`${n.index} / ${n.ids.length} document(s) → ${n.target.workspaceName}`,a=i({title:`Copying to workspace…`,description:r()});m(n);try{for(;n.index<n.ids.length&&!f.current;){if(!navigator.onLine)throw Error(`Offline. Your copy is saved; resume when connected.`);await z(e,n.ids[n.index],{destination:n.target.workspaceName,context:n.paths,treeType:n.target.treeType,treeNameOrTreeId:n.target.treeName,operationId:`${n.id}:${n.index}`}),n={...n,index:n.index+1},m(n),a.update({title:`Copying to workspace…`,description:r()})}a.done({title:n.index>=n.ids.length?`Copy complete`:`Copy paused`,description:r()}),window.dispatchEvent(new CustomEvent(`workspace:documents:refresh`)),window.dispatchEvent(new CustomEvent(`workspace:tree:refresh`))}catch(e){a.fail({title:`Copy incomplete`,description:`${r()}. ${e instanceof Error?e.message:`Copy failed`}`,variant:`destructive`}),f.current||d(`Document ${n.ids[n.index]}: ${e instanceof Error?e.message:`Copy failed`}. Resume to retry.`)}finally{p.current=!1,f.current||l(!1)}},g=()=>{f.current=!0,n()},_=o!=null&&o.index>=o.ids.length,v=r?`h-full min-h-0 w-full`:tn,y=(0,J.jsx)(J.Fragment,{children:o?(0,J.jsxs)(`section`,{role:`dialog`,"aria-label":`Copy to workspace`,className:`${v} flex flex-col rounded-(--panel-radius) border bg-card p-4 shadow-elevation-4`,children:[(0,J.jsx)(`h2`,{className:`text-sm font-semibold`,children:`Copy to workspace`}),(0,J.jsxs)(`p`,{className:`mt-3 break-words text-sm`,children:[o.target.workspaceName,`: `,o.paths.join(`, `)]}),(0,J.jsxs)(`p`,{role:`status`,className:`mt-3 text-sm`,children:[o.index,` of `,o.ids.length,` copied`,_?`.`:c?`…`:` — paused.`]}),u&&(0,J.jsx)(`p`,{role:`alert`,className:`mt-3 text-sm text-destructive`,children:u}),(0,J.jsx)(`p`,{className:`mt-3 text-xs text-muted-foreground`,children:`Files go to workspace:data. Destination rules handle storage placement. Relationships and sharing permissions are not copied. Source documents stay unchanged.`}),!_&&(0,J.jsx)(`p`,{className:`mt-2 text-xs text-muted-foreground`,children:`Closing lets the current item finish and pauses the rest. Reopen Copy to workspace to resume, including after reconnecting.`}),(0,J.jsxs)(`div`,{className:`mt-auto flex flex-wrap justify-end gap-2 pt-4`,children:[!_&&!c&&(0,J.jsx)(N,{variant:`ghost`,onClick:()=>{try{localStorage.removeItem(a)}catch{}s(null),d(``)},children:`Discard remaining`}),!_&&!c&&(0,J.jsx)(N,{onClick:()=>void h(o),children:`Resume copy`}),(0,J.jsx)(N,{variant:_?`default`:`outline`,onClick:g,children:_?`Done`:c?`Pause & close`:`Close`})]})]}):(0,J.jsx)(Le,{title:`Copy to workspace…`,confirmLabel:`Copy documents`,excludeWorkspace:e,documentCount:t.length,sizeClassName:v,onClose:g,onConfirm:(e,n)=>h({ids:t,target:n,paths:e,index:0,id:crypto.randomUUID()})})});return r?(0,J.jsx)(qn,{label:`Copy to workspace`,onClose:g,children:y}):(0,J.jsx)(en,{onClose:g,children:y})}function rr(e,t,n){return{...t.length?{features:[...new Set([...e.features??e.metadata?.features??[],...Rt(e.data?.tags??[]),...Rt(t)])]}:{},...n?{geo:n}:{}}}function ir(e,t,n,r){return{id:e.id,schema:e.schema,schemaVersion:e.schemaVersion,metadata:rr(e,t,n),...r===void 0?{}:{comment:r.trim()}}}function ar({workspaceId:e,documentIds:t,onClose:n}){let[r,i]=(0,K.useState)([]),[a,o]=(0,K.useState)(null),[s,c]=(0,K.useState)(`keep`),[l,u]=(0,K.useState)(``),d=(r.length>0||!!a||s!==`keep`)&&(s!==`replace`||l.trim().length>0),[f,p]=(0,K.useState)(t),[m,h]=(0,K.useState)(!1),[g,_]=(0,K.useState)(``);return U(n,!m),(0,Kn.createPortal)((0,J.jsx)(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-scrim p-4`,children:(0,J.jsxs)(`section`,{role:`dialog`,"aria-modal":`true`,"aria-labelledby":`bulk-edit-title`,className:`max-h-viewport-modal overflow-y-auto w-full max-w-md space-y-4 rounded-(--panel-radius) border bg-background p-5 shadow-elevation-4`,children:[(0,J.jsxs)(`h2`,{id:`bulk-edit-title`,className:`font-semibold`,children:[`Bulk Edit · `,f.length,` documents`]}),(0,J.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`Add tags to all selected documents. Choosing a location replaces their existing geotags; leaving it unset keeps them.`}),(0,J.jsxs)(`fieldset`,{disabled:m,className:`space-y-4`,children:[(0,J.jsxs)(`div`,{className:`space-y-2`,children:[(0,J.jsx)(`span`,{className:`text-sm font-medium`,children:`Add tags`}),(0,J.jsx)(Nt,{tags:r,onChange:i,suggestions:[]})]}),(0,J.jsx)(V,{value:a,onChange:o,idPrefix:`bulk-geo`}),(0,J.jsxs)(`div`,{className:`space-y-2`,children:[(0,J.jsx)(`label`,{htmlFor:`bulk-comment-mode`,className:`text-sm font-medium`,children:`Comment`}),(0,J.jsxs)(`select`,{id:`bulk-comment-mode`,value:s,onChange:e=>c(e.target.value),className:`w-full rounded-md border border-input bg-background px-3 py-2 text-sm`,children:[(0,J.jsx)(`option`,{value:`keep`,children:`Keep existing comments`}),(0,J.jsx)(`option`,{value:`replace`,children:`Replace comments`}),(0,J.jsx)(`option`,{value:`clear`,children:`Clear comments`})]}),s===`replace`&&(0,J.jsxs)(J.Fragment,{children:[(0,J.jsx)(`label`,{htmlFor:`bulk-comment`,className:`sr-only`,children:`New comment for all selected documents`}),(0,J.jsx)(`textarea`,{id:`bulk-comment`,rows:3,value:l,onChange:e=>u(e.target.value),placeholder:`Comment for all selected documents…`,className:`w-full rounded-md border border-input bg-background px-3 py-2 text-sm focus:outline-none focus:ring-2 focus:ring-ring`}),(0,J.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`This replaces the comment on every selected document.`})]}),s===`clear`&&(0,J.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`This removes the comment from every selected document.`})]})]}),g&&(0,J.jsx)(`p`,{role:`alert`,className:`text-sm text-destructive`,children:g}),(0,J.jsxs)(`div`,{className:`flex justify-end gap-2`,children:[(0,J.jsx)(N,{variant:`outline`,onClick:n,disabled:m,children:`Cancel`}),(0,J.jsx)(N,{onClick:async()=>{if(m||!d)return;h(!0),_(``);let t=[];for(let n of f)try{let t=await B(e,n);await nt(e,ir(t,r,a,s===`keep`?void 0:s===`clear`?``:l))}catch{t.push(n)}window.dispatchEvent(new CustomEvent(`workspace:documents:refresh`)),h(!1),t.length?(p(t),_(`${f.length-t.length} saved; ${t.length} could not be updated. Retry applies only to those documents.`)):n()},disabled:m||!d,children:m?`Saving…`:g?`Retry failed`:`Apply to all`})]})]})}),window.document.body)}var or=e=>`/${e}`.replace(/\/+/g,`/`).replace(/\/$/,``)||`/`;function sr(e,t,n,r){return typeof e.sourcePath==`string`&&!!t&&e.sourceWorkspaceId===t&&!!n&&e.sourceTreeName===n&&or(e.sourcePath)===or(r)}var cr=i();function lr(e){let{id:t,...n}=e;return n}function ur(e){let t=kt(),n=(0,K.useContext)(bt),{document:r,workspaceId:i,isOpen:a,onClose:o,initialEdit:s,initialTab:c}=e,l=(t===`side`||n?.alwaysOn===!0)&&!!n&&!!i&&!s&&!c;return(0,K.useLayoutEffect)(()=>{!l||!a||!r||!i||!n||((n.preview??n.open)(r,i),o())},[l,a,r,i,n,o]),l?null:(0,J.jsx)(dr,{...e})}function dr({document:e,isOpen:t,onClose:n,workspaceId:r,initialTab:i,initialEdit:a}){let[o,s]=(0,K.useState)(!1),c=zt(),{document:l,refresh:u}=Mn(r,e);if(U(()=>o?s(!1):n(),t&&!!l),!t||!l)return null;let d=!!(c?.state.t1Open||c?.state.t2Open);return(0,Kn.createPortal)((0,J.jsx)(`div`,{role:`dialog`,"aria-modal":`true`,className:M(`fixed inset-0 z-50 flex items-center justify-center bg-scrim`,o?`p-0`:`p-4 max-md:p-2`,o&&d&&`md:right-[min(436px,90vw)]`),onClick:n,children:(0,J.jsxs)(`div`,{className:M(`flex w-full flex-col border bg-background max-md:h-full max-md:max-w-none`,o?`h-full max-w-none rounded-none md:rounded-(--panel-radius) md:m-2 md:h-[calc(var(--viewport-h)-1rem)]`:`h-viewport-card max-w-3xl rounded-(--panel-radius)`),onClick:e=>e.stopPropagation(),children:[(0,J.jsxs)(`div`,{className:`flex shrink-0 items-center justify-between p-4 pb-2`,children:[(0,J.jsxs)(`div`,{className:`min-w-0`,children:[(0,J.jsx)(`h2`,{className:`truncate text-lg font-bold`,children:P(l).title}),(0,J.jsxs)(`p`,{className:`text-xs text-muted-foreground`,children:[`ID: `,l.id,` · `,l.schema]})]}),(0,J.jsxs)(`div`,{className:`flex shrink-0 items-center gap-1`,children:[(()=>{let e=dt(l);return e?(0,J.jsx)(`a`,{href:e,target:`_blank`,rel:`noopener noreferrer`,className:`rounded-sm p-2 text-muted-foreground hover:bg-muted hover:text-foreground`,title:`Open original: ${e}`,"aria-label":`Open original`,children:(0,J.jsx)(he,{className:`h-4 w-4`})}):null})(),(0,J.jsx)(`button`,{onClick:()=>s(!o),className:`hidden rounded-sm p-2 hover:bg-muted md:block`,title:o?`Restore`:`Fullscreen`,"aria-label":o?`Restore`:`Fullscreen`,children:o?(0,J.jsx)(w,{className:`h-4 w-4`}):(0,J.jsx)(se,{className:`h-4 w-4`})}),(0,J.jsx)(`button`,{onClick:n,className:`rounded-sm p-2 hover:bg-muted`,title:`Close`,children:`✕`})]})]}),(0,J.jsx)(`div`,{className:`min-h-0 flex-1`,children:(0,J.jsx)(Mt.Provider,{value:()=>s(e=>!e),children:(0,J.jsx)(Et,{document:l,workspaceId:r??``,initialTab:i,initialEdit:a,onChanged:u})})})]})}),window.document.body)}var fr=xn,pr={alphabetical:`Alphabetical`,type:`Type`,"crud:created":`Created`,"crud:updated":`Updated`,content:`Content`};function mr(e){return pr[e]??e}function hr(e){let[t,n]=(0,K.useState)([]);return(0,K.useEffect)(()=>{let t=!1;return ft(e).then(e=>{t||n(e)}).catch(()=>{t||n([])}),()=>{t=!0}},[e]),(0,K.useMemo)(()=>[...new Set([`alphabetical`,`type`,`crud:created`,`crud:updated`,`content`,...t.filter(e=>e!==`crud:deleted`)])].map(e=>({value:e,label:mr(e)})),[t])}function gr({workspaceId:e,value:t,onChange:n}){let r=hr(e);return(0,J.jsxs)(`div`,{className:`canvas-no-drag flex items-center gap-1`,children:[(0,J.jsxs)(`select`,{value:t.sortBy,onChange:e=>n({...t,sortBy:e.target.value,order:[`alphabetical`,`type`].includes(e.target.value)?`asc`:t.order}),className:`h-7 rounded-md border bg-background px-1.5 text-xs`,title:`Sort by`,"aria-label":`Sort by`,children:[t.sortBy!==`crud:deleted`&&!r.some(e=>e.value===t.sortBy)&&(0,J.jsx)(`option`,{value:t.sortBy,children:mr(t.sortBy)}),r.map(e=>(0,J.jsx)(`option`,{value:e.value,children:e.label},e.value))]}),(0,J.jsx)(`button`,{type:`button`,onClick:()=>n({...t,order:t.order===`asc`?`desc`:`asc`}),title:t.order===`asc`?`Ascending`:`Descending`,"aria-label":t.order===`asc`?`Ascending`:`Descending`,className:`flex h-7 w-7 items-center justify-center rounded-md border text-muted-foreground hover:bg-accent hover:text-foreground touch-target`,children:t.order===`asc`?(0,J.jsx)(be,{className:`h-3.5 w-3.5`}):(0,J.jsx)(me,{className:`h-3.5 w-3.5`})})]})}function _r(e,t){let n=t?.replace(/^t:/,``)||`crud:created`,r=(n===`crud:created`?[e.createdAt]:n===`crud:updated`?[e.updatedAt]:(e.timelines??[]).filter(e=>(e.timeline||e.name)===n).map(e=>e.start)).map(e=>Date.parse(e??``)).filter(Number.isFinite);if(r.length)return Math.min(...r);let i=n===`content`?Date.parse(e.createdAt??``):NaN;return Number.isFinite(i)?i:null}var Q={today:8,yesterday:7,thisWeek:6,lastWeek:5,thisMonth:4,lastMonth:3,thisYear:2,year:1,unknown:0},$=e=>e*1e6;function vr(){try{let e=new Intl.Locale(navigator.language),t=(typeof e.getWeekInfo==`function`?e.getWeekInfo():e.weekInfo)?.firstDay;if(typeof t==`number`&&t>=1&&t<=7)return t}catch{}return 1}function yr(e){return new Date(e.getFullYear(),e.getMonth(),e.getDate())}function br(e,t){let n=((e.getDay()===0?7:e.getDay())-t+7)%7,r=yr(e);return r.setDate(r.getDate()-n),r}var xr=864e5;function Sr(e){let t=vr(),n=yr(e),r=br(e,t);return{today:n.getTime(),yesterday:n.getTime()-xr,weekStart:r.getTime(),lastWeekStart:r.getTime()-7*xr,year:e.getFullYear(),month:e.getFullYear()*12+e.getMonth()}}function Cr(e,t){if(e===null||!Number.isFinite(e))return{key:`unknown`,label:`Unknown date`,rank:$(Q.unknown)};if(e>=t.today)return{key:`today`,label:`Today`,rank:$(Q.today)};if(e>=t.yesterday)return{key:`yesterday`,label:`Yesterday`,rank:$(Q.yesterday)};if(e>=t.weekStart)return{key:`this-week`,label:`Earlier this week`,rank:$(Q.thisWeek)};if(e>=t.lastWeekStart)return{key:`last-week`,label:`Last week`,rank:$(Q.lastWeek)};let n=new Date(e),r=n.getFullYear()*12+n.getMonth();if(r===t.month)return{key:`this-month`,label:`Earlier this month`,rank:$(Q.thisMonth)};if(r===t.month-1)return{key:`last-month`,label:`Last month`,rank:$(Q.lastMonth)};if(n.getFullYear()===t.year)return{key:`this-year`,label:`Earlier this year`,rank:$(Q.thisYear)};let i=n.getFullYear();return{key:`year-${i}`,label:String(i),rank:$(Q.year)+i}}function wr(e,t,n=`desc`,r=new Date){let i=Sr(r),a=new Map;for(let n of e){let e=Cr(t(n),i),r=a.get(e.key);r?r.items.push(n):a.set(e.key,{...e,items:[n]})}let o=[...a.values()].sort((e,t)=>n===`asc`?e.rank-t.rank:t.rank-e.rank),s=o.filter(e=>e.key===`unknown`);return s.length?[...o.filter(e=>e.key!==`unknown`),...s]:o}function Tr(){let{showProgress:e}=Ae();return(0,K.useCallback)(async(t,n,r,i)=>{let a=e({title:t,description:n});try{let e=await i();if(e===!1)throw Error(`The operation could not be completed.`);return a.done({title:r,description:n}),e}catch(e){throw a.fail({title:`Operation failed`,description:e instanceof Error?e.message:String(e),variant:`destructive`}),e}},[e])}var Er=[`tree.path.inserted`,`tree.path.moved`,`tree.path.removed`,`tree.path.copied`,`tree.path.locked`,`tree.path.unlocked`,`tree.layer.updated`,`tree.layer.converted`,`tree.recalculated`,`tree.created`,`tree.deleted`,`tree.renamed`,`context.path.changed`,`backend.tree.changed`,`backend.changed`,`backend.resync.changed`,`dataBackends.changed`,`services.changed`,`connect`],Dr=new Map;function Or(e,t,n){ot(e,t),window.dispatchEvent(new CustomEvent(`workspace:tree:refresh`,{detail:{workspaceName:e,treeName:t,cacheInvalidated:!0}})),window.dispatchEvent(new CustomEvent(`workspace:documents:refresh`,{detail:{workspaceName:e,treeName:t,path:n}}))}function kr(e,t){let n=Dr.get(e);if(!n){let t=new Set([e]),r=new Set,i,a=Er.map(n=>{let a=(a={})=>{if(n===`backend.resync.changed`&&a.resyncing!==!1)return;let o=typeof a.workspaceId==`string`?a.workspaceId:null,s=typeof a.workspaceName==`string`?a.workspaceName:null;if(o&&!t.has(o)||!o&&s&&s!==e)return;let c=typeof a.treeName==`string`?a.treeName:void 0;n===`tree.renamed`?c=void 0:n===`context.path.changed`?c??=`context`:[`backend.tree.changed`,`backend.changed`,`backend.resync.changed`,`dataBackends.changed`,`services.changed`,`connect`].includes(n)&&(c??=`backends`),r.add(c),!i&&(i=setTimeout(()=>{i=void 0;let t=r.has(void 0)?[void 0]:[...r];r.clear();for(let n of t)ot(e,n),window.dispatchEvent(new CustomEvent(`workspace:tree:refresh`,{detail:{workspaceName:e,treeName:n,cacheInvalidated:!0}}))},200))};return ke.on(n,a),[n,a]});n={users:0,workspaceIds:t,stop:()=>{clearTimeout(i);for(let t of r)ot(e,t);a.forEach(([e,t])=>ke.off(e,t))}},Dr.set(e,n)}n.users++,t&&n.workspaceIds.add(t);let r=n;return()=>{--r.users===0&&(r.stop(),Dr.delete(e))}}function Ar({contextId:e,workspaceId:t,treeName:n,onRefresh:r}){let i=Tr(),{showProgress:a}=Ae(),s=n||`context`,c=s===`directory`,[l,u]=(0,K.useState)([]);(0,K.useEffect)(()=>{let e=!1,n=()=>{t&&cn(t).then(t=>{e||u(t)}).catch(()=>{})};return n(),window.addEventListener(`focus`,n),()=>{e=!0,window.removeEventListener(`focus`,n)}},[t,s]);let d=(0,K.useCallback)(e=>{if(s===`backends`)return[e];let t=`${c?`dir`:`ctx`}:${e}`;return[...new Set(l.filter(e=>e.enabled!==!1).flatMap(e=>{let n=e.when.pathExact||e.when.path,r=(Array.isArray(n)?n:[n]).filter(e=>typeof e==`string`&&e.startsWith(`backends:`));return e.then.flatMap(e=>e.action!==`link`||!Array.isArray(e.paths)?[]:e.paths.flatMap(n=>{if(typeof n!=`string`)return[];let i=n===t?``:e.recursive&&t.startsWith(n+`/`)?t.slice(n.length):null;return i===null?[]:r.map(e=>e.slice(9)+i)}))}))]},[l,s,c]),f=(0,K.useCallback)((e=150)=>{r&&setTimeout(r,e),t&&setTimeout(()=>window.dispatchEvent(new CustomEvent(`workspace:tree:refresh`,{detail:{workspaceName:t}})),e)},[r,t]),p=(0,K.useCallback)(async(n,r=!0)=>{let i;if(e)i=await qt(e,n,r);else if(t)i=await ct(t,n,r,s);else return!1;let a=$t(n);if(i&&a)try{e?await Ht(e,n,a):t&&await qe(t,n,a,s)}catch{}return f(),i},[e,t,s,f]),m=(0,K.useCallback)(async(n,r=!1,a=!1,o=!1)=>i(o?`Destroying…`:a?`Purging…`:`Removing…`,n,o?`Destroyed`:a?`Purged`:`Removed`,async()=>{try{return e?await Jt(e,n,r):t?await $e(t,n,r,s,a,o):!1}finally{f()}}),[e,t,s,f,i]),h=(0,K.useCallback)(async(n,r)=>{let i;if(e){let t=n.split(`/`);t[t.length-1]=r,i=await Ut(e,n,t.join(`/`),!1)}else if(t)i=await qe(t,n,{name:r},s);else return!1;return f(),i},[e,t,s,f]),g=(0,K.useCallback)(async(n,r,a=!1,o=s,c=s,l={})=>i(`Moving…`,`${n} → ${r}`,`Moved`,async()=>{let i;if(e)i=await Ut(e,n,r,a,l);else if(t)i=await yt(t,n,r,a,o,c,l);else return!1;return f(),i}),[e,t,s,f,i]),_=(0,K.useCallback)(async n=>{let r;if(e)r=await Wt(e,n);else if(t)r=await Ue(t,n,s);else return null;return f(),r},[e,t,s,f]),v=(0,K.useCallback)(async n=>{let r;if(e)r=await Bt(e,n);else if(t)r=await R(t,n,s);else return null;return f(),r},[e,t,s,f]),y=(0,K.useCallback)(async(n,r,a=!1,o=s,c=s)=>i(`Copying…`,`${n} → ${r}`,`Copied`,async()=>{let i;if(e)i=await Kt(e,n,r,a);else if(t)i=await I(t,n,r,a,o,c);else return!1;return f(),i}),[e,t,s,f,i]),b=(0,K.useCallback)(async(n,r)=>e?await Ht(e,n,r):t?await qe(t,n,r,s):!1,[e,t,s]),x=(0,K.useCallback)(async(n,r)=>{let i;if(e)i=await Gt(e,n,r);else if(t)i=await F(t,n,r,s);else return null;return f(),i},[e,t,s,f]),S=(0,K.useCallback)(async(n,r)=>{let i;if(e)i=await Vt(e,n,r);else if(t)i=await _t(t,n,r,s);else return null;return f(),i},[e,t,s,f]),C=(0,K.useCallback)(async e=>{if(!t)return!1;let n=await He(t,e,t,s);return f(300),n},[t,s,f]),w=(0,K.useCallback)(async(e,n)=>{if(!t)return!1;try{await at(t,e,n??t,s)}catch(e){if(!(e instanceof Error)||!/still locked by/i.test(e.message))throw e}return f(300),!0},[t,s,f]),ee=(0,K.useCallback)(async e=>{if(!t)return!1;let n=await pt(t,e,s);return f(),n},[t,s,f]),T=(0,K.useCallback)(async e=>{if(!t)return!1;let n=await rt(t).catch(()=>[]),r=d(e);for(let e of r){let r=ht(e,n);if(!r)continue;let i=n.find(e=>e.driver===r.driver&&e.address===r.address),o=r.driver===`imap`?i?.containers?.find(t=>t.treePath===e):void 0;if(r.driver===`imap`&&e!==i?.treePath&&!o)throw Error(`Select a subscribed mailbox folder to refresh`);await un(a,t,r.driver,r.address,void 0,o?.name)}return f(300),r.length>0},[t,f,a,d]),te=(0,K.useCallback)(async(e,n)=>{if(!t)return!1;let r=await rt(t).catch(()=>[]),i=gt(e,r);if(!i)return!1;let a=i.key?`${i.key}/${n}`:n;return await lt(t,i.driver,i.address,[a]),f(200),!0},[t,f]),ne=(0,K.useCallback)(async(e,n)=>{if(!t)return!1;let r=await rt(t).catch(()=>[]),i=gt(e,r);return!i||!i.key?!1:(await Qe(t,i.driver,i.address,i.key,n),f(200),!0)},[t,f]),re=(0,K.useCallback)(async e=>t?i(`Deleting folder…`,e,`Folder deleted`,async()=>{let n=await rt(t),r=L(e,n);if(!r)throw Error(`This folder is not on a writable backend, or is a backend root.`);try{return await Ze(t,r.driver,r.address,r.key),!0}finally{f(200)}}):!1,[t,f,i]),E=(0,K.useCallback)(async(e,n)=>{if(!t)return;let{showSubtreeTransfer:r}=await o(async()=>{let{showSubtreeTransfer:e}=await import(`./subtree-transfer-dialog-BN9xBB9n.js`);return{showSubtreeTransfer:e}},__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10]));r({mode:e,path:n,workspaceId:t,treeName:s,onImported:()=>{Or(t,s),f()}})},[t,s,f]),D=(0,K.useCallback)(async(e,n)=>{if(!t)return;let r=await o(()=>Promise.resolve().then(()=>Mr),void 0);if(e===`import`)r.showDocumentImport(async e=>{if((await it(t,n,e,s,st(s))).length!==e.length)throw Error(`Some documents could not be imported`);return Or(t,s),f(),!0});else{let e=[];for(let r=0;;){let i=await ut(t,n,[],{treeName:s,treeType:st(s),limit:500,offset:r,order:`asc`}),a=i.payload||[];if(e.push(...a),r+=a.length,!a.length||r>=(i.totalCount??i.count??1/0))break}r.showDocumentExport(e)}},[t,s,f]);return{onImportDocuments:t&&s!==`backends`?e=>D(`import`,e):void 0,onExportDocuments:t?e=>D(`export`,e):void 0,onInsertPath:p,onRemovePath:m,onRenamePath:h,onMovePath:g,onCopyPath:y,onExportSubtree:t?e=>E(`export`,e):void 0,onImportSubtree:t&&s!==`backends`?e=>E(`import`,e):void 0,onUpdateNode:b,onMergeLayer:x,onSubtractLayer:S,onMergeDown:c?void 0:_,onSubtractDown:c?void 0:v,onLockLayer:t?C:void 0,onUnlockLayer:t?w:void 0,onDestroyLayer:t&&!c?ee:void 0,canResyncBackend:e=>d(e).length>0,onResyncBackend:t?T:void 0,onCreateBackendFolder:t?te:void 0,onRenameBackendFolder:t?ne:void 0,onDeleteBackendFolder:t?re:void 0}}function jr({x:e,y:t,workspaceName:n,treeName:r,path:i,onClose:a,onOpen:o,onOpenToSide:c,pastedDocumentIds:d,onPasteDocuments:f}){let p=s(),m=Ar({workspaceId:n,treeName:r}),h=r===`backends`,g=h?gt(i):null,[_,v]=(0,K.useState)([]);(0,K.useEffect)(()=>{if(!h)return;let e=!1;return rt(n).then(t=>{e||v(t)}).catch(()=>{}),()=>{e=!0}},[n,h]);let y=h?L(i,_):null,b=i.split(`/`).filter(Boolean).pop()||i,[w,ne]=(0,K.useState)(void 0);(0,K.useEffect)(()=>{let e=!1;return Ge(n).then(t=>{e||ne(t.find(e=>e.tree===r&&e.path===i)??null)}).catch(()=>{e||ne(null)}),()=>{e=!0}},[n,r,i]);let re=async e=>{a();try{await e()}catch(e){alert(e instanceof Error?e.message:String(e))}},D=(e,t,n,r=!1)=>(0,J.jsxs)(`button`,{type:`button`,className:M(`flex items-center gap-2 w-full px-3 py-1.5 text-xs hover:bg-accent rounded-sm text-left`,r&&`text-destructive hover:bg-destructive/10`),onClick:()=>re(n),children:[e,t]}),ie=(0,J.jsx)(`div`,{className:`my-1 h-px bg-border`}),oe=e=>{let t=h?(()=>{let t=rn(i);return{kind:e,storeTo:t?.backend||``,storeFolder:t?.rel||``}})():{kind:e,path:`dir:${i}`,storeFolder:e===`download`?`Downloads`:nn(i)};p(`/workspaces/${n}/settings/hooks?${dn(t).toString()}`)},O=(e,t=``)=>{let n=prompt(e,t)?.trim();return n&&n!==t&&!n.includes(`/`)?n:null},se=an(r,i);return se?(0,J.jsxs)(Pe,{x:e,y:t,onClose:a,className:`min-w-44 rounded-md border bg-popover p-1 shadow-elevation-3`,children:[D((0,J.jsx)(ae,{className:`h-3 w-3`}),`Open Trash`,()=>o(i)),se.backend&&D((0,J.jsx)(te,{className:`h-3 w-3`}),`Restore original paths`,()=>ln(n,i)),se.backend&&D((0,J.jsx)(ae,{className:`h-3 w-3`}),`Empty Trash`,()=>sn(n,i),!0)]}):(0,J.jsxs)(Pe,{x:e,y:t,onClose:a,className:`min-w-[11rem] rounded-md border bg-popover p-1 shadow-elevation-3`,children:[D((0,J.jsx)(C,{className:`w-3 h-3`}),`Open`,()=>o(i)),c&&D((0,J.jsx)(de,{className:`w-3 h-3`}),`Open to the side`,()=>c(i)),ie,h?g&&(0,J.jsxs)(J.Fragment,{children:[D((0,J.jsx)(S,{className:`w-3 h-3`}),`New folder here`,async()=>{let e=O(`New folder name:`);e&&await m.onCreateBackendFolder?.(i,e)}),g.key&&D((0,J.jsx)(E,{className:`w-3 h-3`}),`Rename folder`,async()=>{let e=O(`New folder name:`,b);e&&await m.onRenameBackendFolder?.(i,e)}),D((0,J.jsx)(u,{className:`w-3 h-3`}),`Create storage rule…`,()=>oe(`store`))]}):(0,J.jsxs)(J.Fragment,{children:[D((0,J.jsx)(S,{className:`w-3 h-3`}),`New folder here`,async()=>{let e=O(`New folder name:`);e&&await m.onInsertPath(`${i===`/`?``:i}/${e}`)}),D((0,J.jsx)(E,{className:`w-3 h-3`}),`Rename`,async()=>{let e=O(`New name:`,b);e&&await m.onRenamePath(i,e)}),D((0,J.jsx)(u,{className:`w-3 h-3`}),`Create rule…`,()=>oe(`store`)),D((0,J.jsx)(Ce,{className:`w-3 h-3`}),`Create download rule…`,()=>oe(`download`))]}),w!==void 0&&D(w?(0,J.jsx)(ee,{className:`w-3 h-3`}):(0,J.jsx)(x,{className:`w-3 h-3`}),w?`Unpin`:`Pin`,async()=>{w?await tt(n,w.id):await Xe(n,i,r),window.dispatchEvent(new CustomEvent(`workspace:tree:refresh`,{detail:{workspaceName:n}}))}),ie,m.onImportDocuments&&D((0,J.jsx)(S,{className:`w-3 h-3`}),`Import documents…`,()=>m.onImportDocuments(i)),m.onExportDocuments&&D((0,J.jsx)(Ce,{className:`w-3 h-3`}),`Export documents…`,()=>m.onExportDocuments(i)),D((0,J.jsx)(T,{className:`w-3 h-3`}),`Copy path`,()=>navigator.clipboard?.writeText(i)),!h&&f&&d&&d.length>0&&D((0,J.jsx)(l,{className:`w-3 h-3`}),`Paste ${d.length} document(s)`,()=>f(i,d)),h?y&&(0,J.jsxs)(J.Fragment,{children:[ie,D((0,J.jsx)(ae,{className:`w-3 h-3`}),`Delete from backend`,async()=>{confirm(`Delete folder "${b}" and its contents from the backend?`)&&await m.onDeleteBackendFolder?.(i)},!0)]}):(0,J.jsxs)(J.Fragment,{children:[ie,D((0,J.jsx)(ae,{className:`w-3 h-3`}),`Remove`,async()=>{confirm(`Remove "${i}" and all children?`)&&await m.onRemovePath(i,!0)},!0)]})]})}var Mr=t({DocumentList:()=>ii,default:()=>ii,showDocumentExport:()=>oi,showDocumentImport:()=>ai});function Nr({isOpen:e,onClose:t,documents:n,selectedDocuments:r}){let[i,a]=(0,K.useState)(`idle`);if(!e)return null;let o=()=>{a(`idle`),t()},s=r.size>0?n.filter(e=>r.has(e.id)):n,c=s.map(lr),l=JSON.stringify(c,null,2),u=async()=>{try{await navigator.clipboard.writeText(l),a(`copied`),setTimeout(()=>a(`idle`),2e3)}catch(e){console.error(`Failed to copy to clipboard:`,e),a(`error`),setTimeout(()=>a(`idle`),2e3)}};return(0,J.jsx)(qn,{label:`Export Documents`,onClose:o,children:(0,J.jsxs)(`div`,{className:`flex h-full min-h-0 flex-col p-4 sm:p-6`,children:[(0,J.jsxs)(`div`,{className:`flex items-center justify-between mb-6`,children:[(0,J.jsxs)(`div`,{children:[(0,J.jsx)(`h2`,{className:`text-2xl font-bold`,children:`Export Documents`}),(0,J.jsxs)(`p`,{className:`text-muted-foreground`,children:[`Exporting `,s.length,` document`,s.length===1?``:`s`,i===`copied`&&(0,J.jsx)(`span`,{className:`text-success ml-2`,children:`✓ Copied to clipboard!`}),i===`error`&&(0,J.jsx)(`span`,{className:`text-destructive ml-2`,children:`✗ Failed to copy`})]})]}),(0,J.jsx)(`button`,{onClick:o,className:`p-2 hover:bg-muted rounded-sm`,title:`Close`,children:`✕`})]}),(0,J.jsx)(`div`,{className:`flex min-h-0 flex-1 flex-col`,children:(0,J.jsxs)(`div`,{className:`flex min-h-0 flex-1 flex-col`,children:[(0,J.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-2 mb-2`,children:[(0,J.jsx)(`h3`,{className:`font-semibold`,children:`JSON Data (Press Ctrl+A to select all, Ctrl+C to copy)`}),(0,J.jsxs)(N,{onClick:u,size:`sm`,className:`flex items-center gap-2`,children:[(0,J.jsx)(T,{className:`h-4 w-4`}),`Copy to Clipboard`]})]}),(0,J.jsx)(`textarea`,{className:`w-full min-h-24 flex-1 p-4 bg-muted border rounded-lg text-sm font-mono resize-none focus:outline-none focus:ring-2 focus:ring-primary`,value:l,readOnly:!0,autoFocus:!0,onKeyDown:e=>{if(e.ctrlKey||e.metaKey){if(e.key===`a`){e.preventDefault();let t=window.getSelection(),n=document.createRange();n.selectNodeContents(e.currentTarget),t?.removeAllRanges(),t?.addRange(n)}else e.key===`c`&&u()}},onFocus:e=>e.target.select()})]})}),(0,J.jsxs)(`div`,{className:`mt-8 pt-4 border-t flex justify-end gap-2`,children:[(0,J.jsx)(N,{variant:`outline`,onClick:()=>{let e=URL.createObjectURL(new Blob([l],{type:`application/json`})),t=window.document.createElement(`a`);t.href=e,t.download=`canvas-documents.json`,t.click(),setTimeout(()=>URL.revokeObjectURL(e),1e3)},children:`Download JSON`}),(0,J.jsx)(N,{onClick:o,children:`Close`})]})]})})}function Pr({isOpen:e,onClose:t,onImport:n}){let[r,i]=(0,K.useState)(``),[a,o]=(0,K.useState)(!1),[s,c]=(0,K.useState)(null);if(!e)return null;let l=async()=>{if(c(null),!r.trim()){c(`Please enter JSON data`);return}try{let e=JSON.parse(r),a=Array.isArray(e)?e:[e];for(let e of a)if(!e||typeof e!=`object`||!e.schema||!e.data){c(`Each document must have "schema" and "data" fields`);return}o(!0),await n(a)?(i(``),t()):c(`Failed to import documents`)}catch(e){c(e instanceof Error?e.message:`Import failed`)}finally{o(!1)}},u=()=>{i(``),c(null),t()};return(0,Kn.createPortal)((0,J.jsx)(`div`,{role:`dialog`,"aria-modal":`true`,className:`fixed inset-0 bg-scrim flex items-center justify-center z-50 p-4 max-md:p-2`,children:(0,J.jsx)(`div`,{className:`bg-background border rounded-(--panel-radius) max-w-3xl w-full max-h-viewport-card overflow-y-auto max-md:h-full max-md:max-h-none max-md:max-w-none`,children:(0,J.jsxs)(`div`,{className:`p-6`,children:[(0,J.jsxs)(`div`,{className:`flex items-center justify-between mb-6`,children:[(0,J.jsxs)(`div`,{children:[(0,J.jsx)(`h2`,{className:`text-2xl font-bold`,children:`Import Documents`}),(0,J.jsx)(`p`,{className:`text-muted-foreground`,children:`Paste JSON data or choose a document export file`})]}),(0,J.jsx)(`button`,{onClick:u,className:`p-2 hover:bg-muted rounded-sm`,title:`Close`,children:`✕`})]}),(0,J.jsxs)(`div`,{className:`space-y-4`,children:[(0,J.jsxs)(`div`,{children:[(0,J.jsx)(`label`,{className:`block text-sm font-medium mb-2`,children:`JSON Data (single document or array of documents)`}),(0,J.jsx)(`textarea`,{value:r,onChange:e=>i(e.target.value),className:`w-full h-64 p-3 border rounded-lg font-mono text-sm`,placeholder:`[{"schema": "data/schema/tab", "schemaVersion": "2.0", "data": {...}, "metadata": {...}}]`,disabled:a,autoFocus:!0})]}),s&&(0,J.jsx)(`div`,{className:`text-sm text-destructive bg-destructive/10 p-3 rounded-lg border`,children:s}),(0,J.jsxs)(`div`,{className:`text-xs text-muted-foreground`,children:[(0,J.jsxs)(`p`,{children:[(0,J.jsx)(`strong`,{children:`Format:`}),` Each document must have "schema", "schemaVersion", "data", and "metadata" fields.`]}),(0,J.jsxs)(`p`,{children:[(0,J.jsx)(`strong`,{children:`Example schemas:`}),` "data/schema/tab", "data/schema/file", etc.`]})]})]}),(0,J.jsxs)(`label`,{className:`mt-4 block text-sm`,children:[`Import JSON file`,(0,J.jsx)(`input`,{type:`file`,accept:`.json,application/json`,disabled:a,className:`mt-2 block w-full text-sm`,onChange:e=>{let t=e.target.files?.[0];t&&t.text().then(e=>{i(e),c(null)}).catch(e=>c(String(e)))}})]}),(0,J.jsxs)(`div`,{className:`mt-8 pt-4 border-t flex justify-between`,children:[(0,J.jsx)(N,{variant:`outline`,onClick:u,disabled:a,children:`Cancel`}),(0,J.jsx)(N,{onClick:l,disabled:a||!r.trim(),children:a?`Importing...`:`Import Documents`})]})]})})}),window.document.body)}function Fr({document:e}){let{replicating:t,label:n}=vt(e);return t?(0,J.jsxs)(`span`,{role:`status`,className:`inline-flex shrink-0 items-center gap-1 rounded-full border bg-muted/60 px-2 py-0.5 text-[11px] font-normal text-muted-foreground`,children:[(0,J.jsx)(_e,{className:`h-3 w-3 animate-spin`}),n]}):null}function Ir(e){return e.clientX||e.clientY?{x:e.clientX,y:e.clientY}:Fe(e.currentTarget,`inside`)}function Lr({documentId:e,onOpenActions:t,className:n}){return t?(0,J.jsx)(`button`,{type:`button`,onClick:n=>{n.stopPropagation(),t(n.currentTarget,e)},className:`rounded-sm p-1.5 text-muted-foreground hover:bg-muted hover:text-foreground ${n??``}`,title:`Actions`,"aria-label":`Document actions`,"aria-haspopup":`menu`,children:(0,J.jsx)(O,{className:`h-4 w-4`})}):null}function Rr(e,t,n){e.target===e.currentTarget&&(e.key===`Enter`?(e.preventDefault(),t()):e.key===` `&&n&&(e.preventDefault(),n()))}function zr({document:e}){let t=dt(e);return t?(0,J.jsx)(`a`,{href:t,target:`_blank`,rel:`noopener noreferrer`,title:`Open original in browser`,"aria-label":`Open original in browser`,className:`shrink-0 rounded p-1 text-muted-foreground hover:text-foreground`,onClick:e=>e.stopPropagation(),onKeyDown:e=>e.stopPropagation(),children:(0,J.jsx)(he,{className:`h-3.5 w-3.5`})}):null}function Br({document:e,isSelected:t,workspaceId:n,onSelect:r,onRightClick:i,onOpenActions:a,onDragStart:o}){let s=Tt(),c=s.alwaysOn&&s.entry?.workspaceId===n&&s.entry?.document.id===e.id,l=Un(),[u,d]=(0,K.useState)(!1),{replicating:f}=vt(e),p=P(e),m=Hr(e),h=m||Wr(e),{blobUrl:g}=H(n??``,e.id,128,{enabled:h,blobFallback:m,version:e.checksumArray?.[0]??null}),_=t=>{o?.(t,e.id)},v=e=>new Date(e).toLocaleDateString(`en-US`,{year:`numeric`,month:`short`,day:`numeric`,hour:`2-digit`,minute:`2-digit`}),y=(()=>{let t=e.checksumArray?.[0];if(t){let[e,n]=t.split(`/`);if(n)return{algo:e,hash:n.substring(0,8)+`...`}}return null})(),b=n=>{let i=n.ctrlKey||n.metaKey;if(n.shiftKey&&r){n.preventDefault(),r(e.id,!0,i,!0);return}r&&(i?r(e.id,!t,i):r(e.id,!0,i)),i||d(!0)},x=e=>{e.shiftKey&&e.preventDefault()},S=n=>{n.preventDefault(),n.stopPropagation(),r&&!t&&r(e.id,!0,!1),i?.(n,e.id)};return(0,J.jsxs)(J.Fragment,{children:[(0,J.jsxs)(mn,{tabIndex:0,"data-document-id":e.id,"data-reading":c||void 0,"aria-selected":!!t,onKeyDown:n=>Rr(n,()=>d(!0),()=>r?.(e.id,!t,!0)),className:`data-[reading=true]:bg-accent data-[reading=true]:text-accent-foreground cursor-pointer outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-ring transition-opacity ${f?`opacity-60`:``} ${t?`bg-info-subtle hover:bg-info-subtle`:`hover:bg-muted/50`}`,onClick:b,onMouseDown:x,...l,onContextMenu:S,draggable:!0,onDragStart:_,children:[(0,J.jsx)(G,{className:`w-10`,onClick:e=>e.stopPropagation(),children:(0,J.jsx)(`input`,{type:`checkbox`,className:`h-4 w-4 cursor-pointer accent-primary align-middle`,checked:!!t,onClick:t=>{t.stopPropagation(),r?.(e.id,t.currentTarget.checked,!0,t.shiftKey)},onChange:()=>{}})}),(0,J.jsx)(G,{className:`w-12`,children:g?(0,J.jsx)(`img`,{src:g,alt:``,className:`h-8 w-8 rounded-md border object-cover`}):(0,J.jsx)(W,{document:e,chip:!0})}),(0,J.jsx)(G,{className:`font-medium w-full max-w-0 md:w-auto md:max-w-xs`,children:(0,J.jsxs)(`div`,{className:`min-w-0`,children:[(0,J.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,J.jsx)(`span`,{className:`truncate`,title:p.title,children:p.title}),(0,J.jsx)(zr,{document:e}),(0,J.jsx)(Fr,{document:e})]}),p.subtitle&&(0,J.jsx)(`div`,{className:`truncate text-xs text-muted-foreground`,title:p.subtitle,children:p.subtitle})]})}),(0,J.jsx)(G,{className:`hidden md:table-cell`,children:(0,J.jsx)(`span`,{className:`px-2 py-1 text-xs bg-muted rounded border`,children:p.schemaLabel})}),(0,J.jsx)(G,{className:`hidden text-xs text-muted-foreground lg:table-cell`,children:e.id}),(0,J.jsx)(G,{className:`hidden text-xs text-muted-foreground lg:table-cell`,children:y&&(0,J.jsx)(`span`,{className:`font-mono`,title:`${y.algo} checksum`,children:y.hash})}),(0,J.jsx)(G,{className:`hidden text-xs text-muted-foreground sm:table-cell`,children:v(e.createdAt)}),(0,J.jsx)(G,{className:`w-12 text-right`,children:(0,J.jsx)(Lr,{documentId:e.id,onOpenActions:a})})]}),(0,J.jsx)(ur,{document:e,isOpen:u,onClose:()=>d(!1),workspaceId:n})]})}function Vr({document:e,isSelected:t,workspaceId:n,onSelect:r,onRightClick:i,onOpenActions:a,onDragStart:o}){let s=Tt(),c=s.alwaysOn&&s.entry?.workspaceId===n&&s.entry?.document.id===e.id,l=Un(),[u,d]=(0,K.useState)(!1),f=e.schema===`data/schema/tab`,{replicating:p}=vt(e),m=P(e),h=Hr(e),_=Ur(e),v=h||Wr(e)||_,{blobUrl:b,loading:x}=H(n??``,e.id,512,{enabled:v,blobFallback:h,version:e.checksumArray?.[0]??null}),S=t=>{o?.(t,e.id)},C=e=>new Date(e).toLocaleDateString(`en-US`,{year:`numeric`,month:`short`,day:`numeric`,hour:`2-digit`,minute:`2-digit`}),w=(()=>{let t=e.checksumArray?.[0];if(t){let[e,n]=t.split(`/`);if(n)return{algo:e,hash:n.substring(0,8)+`...`}}return null})(),ee=n=>{let i=n.ctrlKey||n.metaKey;if(n.shiftKey&&r){n.preventDefault(),r(e.id,!0,i,!0);return}r&&(i?r(e.id,!t,i):r(e.id,!0,i)),i||d(!0)},T=e=>{e.shiftKey&&e.preventDefault()},te=n=>{n.preventDefault(),n.stopPropagation(),r&&!t&&r(e.id,!0,!1),i?.(n,e.id)};return(0,J.jsxs)(J.Fragment,{children:[(0,J.jsx)(`div`,{tabIndex:0,"data-document-id":e.id,"data-reading":c||void 0,"aria-selected":!!t,onKeyDown:n=>Rr(n,()=>d(!0),()=>r?.(e.id,!t,!0)),className:`data-[reading=true]:bg-accent data-[reading=true]:border-primary border rounded-(--card-radius) p-4 transition cursor-pointer outline-none focus-visible:ring-2 focus-visible:ring-ring ${p?`opacity-60`:``} ${t?`bg-info-subtle border-info ring-1 ring-info`:``} ${f&&!t?`hover:bg-info-subtle hover:border-info`:t?``:`hover:bg-accent/50`}`,onClick:ee,onMouseDown:T,...l,onContextMenu:te,draggable:!0,onDragStart:S,children:(0,J.jsxs)(`div`,{className:`flex items-start justify-between gap-4`,children:[v&&(0,J.jsxs)(`div`,{className:`relative h-32 w-40 max-w-[40%] sm:h-40 sm:w-56 shrink-0 overflow-hidden rounded-md border bg-muted/40`,children:[b?(0,J.jsx)(`img`,{src:b,alt:m.title,loading:`lazy`,className:`h-full w-full object-cover`}):_&&n&&!x?(0,J.jsx)(Gr,{workspaceId:n,documentId:e.id,fallback:(0,J.jsx)(W,{document:e})}):x?(0,J.jsx)(`div`,{className:`h-full w-full animate-pulse bg-muted/60`}):(0,J.jsx)(`div`,{className:`flex h-full w-full items-center justify-center`,children:(0,J.jsx)(W,{document:e})}),_&&(0,J.jsx)(g,{className:`pointer-events-none absolute bottom-2 right-2 h-5 w-5 rounded bg-scrim text-scrim-foreground`})]}),(0,J.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,J.jsxs)(`div`,{className:`flex items-center gap-2 mb-2 overflow-hidden`,children:[(0,J.jsx)(W,{document:e,chip:!0}),(0,J.jsx)(`h4`,{className:`font-medium truncate min-w-0 flex-1 max-w-[640px]`,title:m.title,children:m.title}),(0,J.jsx)(zr,{document:e}),(0,J.jsx)(`span`,{className:`ml-auto px-2 py-0.5 text-xs bg-muted text-muted-foreground rounded border flex-shrink-0`,children:m.schemaLabel}),(0,J.jsx)(Fr,{document:e})]}),m.subtitle&&(0,J.jsx)(`p`,{className:`text-xs text-muted-foreground mb-2 truncate`,title:m.subtitle,children:m.subtitle}),m.preview&&(0,J.jsx)(`p`,{className:`text-sm text-muted-foreground mb-3 line-clamp-2 break-all overflow-hidden`,children:m.preview}),(0,J.jsxs)(`div`,{className:`flex items-center gap-4 text-xs text-muted-foreground overflow-hidden`,children:[(0,J.jsxs)(`div`,{className:`flex items-center gap-1 flex-shrink-0`,children:[(0,J.jsx)(`span`,{className:`font-medium`,children:`ID:`}),(0,J.jsx)(`span`,{className:`font-mono truncate max-w-[60px]`,title:`ID: ${e.id}`,children:e.id})]}),w&&(0,J.jsxs)(`div`,{className:`flex items-center gap-1 flex-shrink-0`,children:[(0,J.jsx)(j,{className:`h-3 w-3`}),(0,J.jsx)(`span`,{className:`font-mono`,title:`${w.algo} checksum`,children:w.hash})]}),(0,J.jsxs)(`div`,{className:`flex items-center gap-1 flex-shrink-0`,children:[(0,J.jsx)(y,{className:`h-3 w-3`}),(0,J.jsx)(`span`,{title:`Created: ${C(e.createdAt)}`,children:C(e.createdAt)})]})]})]}),(0,J.jsx)(Lr,{documentId:e.id,onOpenActions:a,className:`-mr-1 -mt-1 p-2`})]})}),(0,J.jsx)(ur,{document:e,isOpen:u,onClose:()=>d(!1),workspaceId:n})]})}function Hr(e){return(e.schema===`data/schema/file`||e.schema===`data/schema/drawing`)&&String(e.metadata?.contentType||``).startsWith(`image/`)}function Ur(e){return e.schema===`data/schema/file`&&String(e.metadata?.contentType||``).startsWith(`video/`)}function Wr(e){return e.schema===`data/schema/file`&&String(e.metadata?.contentType||``)===`application/pdf`}function Gr({workspaceId:e,documentId:t,fallback:n}){let{src:r,error:i}=It(e,t),[a,o]=(0,K.useState)(!1);return i||a?(0,J.jsx)(J.Fragment,{children:n}):r?(0,J.jsxs)(`div`,{className:`relative h-full w-full`,children:[(0,J.jsx)(`video`,{src:r,preload:`metadata`,muted:!0,playsInline:!0,onError:()=>o(!0),className:`block h-full w-full object-cover`}),(0,J.jsx)(`span`,{className:`pointer-events-none absolute bottom-2 right-2 rounded-sm bg-scrim p-1 text-scrim-foreground`,children:(0,J.jsx)(g,{className:`h-3.5 w-3.5`})})]}):(0,J.jsx)(`div`,{className:`aspect-video w-full animate-pulse bg-muted/60`})}function Kr({document:e,workspaceId:t,markdown:n}){let r=(0,K.useRef)(null),[i,a]=(0,K.useState)(()=>typeof IntersectionObserver>`u`);(0,K.useEffect)(()=>{let e=r.current;if(!e||typeof IntersectionObserver>`u`)return;let t=new IntersectionObserver(e=>{e.some(e=>e.isIntersecting)&&(a(!0),t.disconnect())});return t.observe(e),()=>t.disconnect()},[]);let{text:o,loading:s,error:c}=Ft(t,e.id,{mode:`text`,enabled:i,maxTextLength:8e3});return(0,J.jsx)(`div`,{ref:r,className:`relative h-48 w-full overflow-hidden bg-card text-card-foreground`,children:o!=null&&!c?(0,J.jsxs)(`div`,{className:`pointer-events-none p-3 pt-7 text-xs leading-relaxed`,"aria-hidden":`true`,children:[o.length===0?(0,J.jsx)(`span`,{className:`text-muted-foreground`,children:`Empty file`}):n?(0,J.jsx)(Lt,{content:o,preview:!0,className:`text-xs [&_pre]:whitespace-pre-wrap [&_pre]:break-words [&_table]:table-fixed [&_table]:w-full`}):(0,J.jsx)(`pre`,{className:`whitespace-pre-wrap break-words font-mono`,children:o}),(0,J.jsx)(`div`,{className:`absolute inset-x-0 bottom-0 h-8 bg-gradient-to-t from-card to-transparent`})]}):(0,J.jsxs)(`div`,{className:`flex h-full items-center justify-center`,children:[(0,J.jsx)(W,{document:e,size:10,chip:!0}),i&&s&&(0,J.jsx)(`span`,{className:`sr-only`,children:`Loading text preview`})]})})}function qr({document:e,isSelected:t,workspaceId:n,onSelect:r,onOpenToSide:i,onRightClick:a,onOpenActions:o,onDragStart:s}){let[c,l]=(0,K.useState)(null),u=e.metadata?.dimensions,d=c??(u?.width&&u?.height?Math.max(.2,Math.min(5,u.width/u.height)):1),f=Tt(),p=f.alwaysOn&&f.entry?.workspaceId===n&&f.entry?.document.id===e.id,m=Un(),[h,_]=(0,K.useState)(!1),v=Hr(e),y=Ur(e),b=v||Wr(e)||y,x=P(e),S=Ye(String(e.metadata?.contentType||``).split(`;`)[0].trim().toLowerCase(),e.metadata?.filename||We(e)),C=e.schema===`data/schema/file`&&(S===`markdown`||S===`text`)&&(e.metadata?.size??e.data?.size??0)<=1048576,w=!b&&e.schema!==`data/schema/file`&&!!(x.preview||x.subtitle),{replicating:ee}=vt(e),{blobUrl:T,loading:te}=H(n??``,e.id,768,{enabled:b,blobFallback:v,version:e.checksumArray?.[0]??null}),ne=n=>{let i=n.ctrlKey||n.metaKey;if(n.shiftKey&&r){n.preventDefault(),r(e.id,!0,i,!0);return}r&&r(e.id,!i||!t,i),i||_(!0)},re=n=>{n.preventDefault(),n.stopPropagation(),r&&!t&&r(e.id,!0,!1),a?.(n,e.id)};return(0,J.jsxs)(J.Fragment,{children:[(0,J.jsxs)(`div`,{tabIndex:0,"data-document-id":e.id,style:{flexGrow:d,flexBasis:`${d*220}px`,"--tile-ratio":d},"data-reading":p||void 0,"aria-selected":!!t,onKeyDown:n=>Rr(n,()=>_(!0),()=>r?.(e.id,!t,!0)),className:`document-tile data-[reading=true]:bg-accent data-[reading=true]:border-primary group relative mb-3 flex break-inside-avoid flex-col overflow-hidden rounded-(--card-radius) border transition cursor-pointer outline-none hover:shadow-elevation-2 focus-visible:ring-2 focus-visible:ring-ring ${ee?`opacity-60`:``} ${t?`ring-2 ring-info border-info`:``}`,onClick:ne,onMouseDown:e=>{e.shiftKey&&e.preventDefault()},...m,onContextMenu:re,draggable:!0,onDragStart:t=>s?.(t,e.id),title:x.title,children:[(0,J.jsx)(`input`,{type:`checkbox`,className:`absolute left-2 top-2 z-10 h-4 w-4 cursor-pointer accent-primary ${t?``:`reveal-on-hover`}`,checked:t,onClick:t=>{t.stopPropagation(),r?.(e.id,t.currentTarget.checked,!0,t.shiftKey)},onChange:()=>{}}),(0,J.jsxs)(`div`,{className:`document-tile-media relative w-full bg-muted/40 ${b&&T||w||C&&n||y&&n?``:`aspect-square`}`,children:[b&&te&&(0,J.jsx)(`div`,{className:`absolute inset-0 animate-pulse bg-muted/60`}),b&&T?(0,J.jsx)(`img`,{src:T,alt:x.title,loading:`lazy`,className:`block h-auto w-full`,onLoad:e=>{let t=e.currentTarget;t.naturalHeight&&l(t.naturalWidth/t.naturalHeight)}}):y&&n&&!te?(0,J.jsx)(Gr,{workspaceId:n,documentId:e.id,fallback:(0,J.jsx)(`div`,{className:`flex aspect-square w-full items-center justify-center`,children:(0,J.jsx)(W,{document:e,size:10,chip:!0})})}):C&&n?(0,J.jsx)(Kr,{document:e,workspaceId:n,markdown:S===`markdown`},`${n}:${e.id}:${e.checksumArray?.[0]??``}`):w?(0,J.jsxs)(`div`,{className:`flex min-h-28 w-full flex-col gap-1.5 overflow-hidden bg-card p-3 pt-7 text-left`,children:[(0,J.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,J.jsx)(W,{document:e}),(0,J.jsx)(`span`,{className:`min-w-0 truncate text-[10px] uppercase tracking-wide text-muted-foreground`,children:x.schemaLabel}),(0,J.jsx)(zr,{document:e})]}),(0,J.jsx)(`div`,{className:`line-clamp-2 text-sm font-semibold leading-snug`,children:x.title}),x.subtitle&&(0,J.jsx)(`div`,{className:`truncate text-[11px] text-info`,children:x.subtitle}),(0,J.jsx)(`p`,{className:`line-clamp-[8] text-xs leading-relaxed text-muted-foreground`,children:x.preview})]}):(0,J.jsx)(`div`,{className:`flex h-full w-full items-center justify-center`,children:(0,J.jsx)(W,{document:e,size:10,chip:!0})}),y&&T&&(0,J.jsx)(g,{className:`pointer-events-none absolute bottom-2 right-2 h-5 w-5 rounded bg-scrim text-scrim-foreground`}),(0,J.jsxs)(`div`,{className:`absolute right-2 top-2 flex gap-1 reveal-on-hover`,children:[i&&(0,J.jsx)(`button`,{onClick:t=>{t.stopPropagation(),i(e)},className:`rounded-sm bg-scrim p-1 text-scrim-foreground`,title:`Open to the side`,children:(0,J.jsx)(ie,{className:`h-3.5 w-3.5`})}),o&&(0,J.jsx)(`button`,{onClick:t=>{t.stopPropagation(),o(t.currentTarget,e.id)},className:`rounded-sm bg-scrim p-1 text-scrim-foreground`,title:`Actions`,"aria-label":`Document actions`,"aria-haspopup":`menu`,children:(0,J.jsx)(O,{className:`h-3.5 w-3.5`})})]})]}),!w&&(0,J.jsxs)(`div`,{className:`flex items-center gap-1.5 border-t bg-card px-2 py-1.5`,children:[(0,J.jsx)(`span`,{className:`truncate text-xs font-medium`,title:x.title,children:x.title}),(0,J.jsx)(zr,{document:e})]})]}),(0,J.jsx)(ur,{document:e,isOpen:h,onClose:()=>_(!1),workspaceId:n})]})}function Jr(e,t,n,r,i){let[a,o]=(0,K.useState)(!1),s=e=>Array.from(e.dataTransfer.types).includes(`application/json`);return{over:a,onDragOver:e=>{!t||!s(e)||(e.preventDefault(),e.dataTransfer.dropEffect=`link`,a||o(!0))},onDragLeave:()=>o(!1),onDrop:async a=>{if(o(!1),!t||!s(a))return;a.preventDefault(),a.stopPropagation();let c=null;try{c=JSON.parse(a.dataTransfer.getData(`application/json`))}catch{c=null}if(!(c?.type!==`document`||!Array.isArray(c.documentIds)||c.documentIds.length===0)&&!sr(c,i,r,e.path))try{await t(e.path,c.documentIds,{move:!1,sourcePath:c.sourcePath??n,sourceTreeName:c.sourceTreeName??r})}catch{}}}}function Yr(e,t,n){e.stopPropagation(),!(t.isParent||!n)&&(e.preventDefault(),n(t.path,e))}function Xr({folder:e,className:t=`h-4 w-4`}){if(e.isParent)return(0,J.jsx)(p,{className:`${t} text-muted-foreground`});let n=e.color?{color:e.color}:void 0;return(0,J.jsx)(v,{className:`${t} ${e.color?``:`text-warning`}`,style:n})}var Zr=e=>e.isParent?`Parent folder`:e.label&&e.label!==e.name?`${e.label} (${e.name})`:e.name;function Qr({folder:e,onOpen:t,onMenu:n,onPasteDocuments:r,contextPath:i,treeName:a,workspaceId:o}){let s=Jr(e,r,i,a,o);return(0,J.jsxs)(`button`,{type:`button`,title:Zr(e),onClick:()=>t?.(e.path),onContextMenu:t=>Yr(t,e,n),onDragOver:s.onDragOver,onDragLeave:s.onDragLeave,onDrop:s.onDrop,className:`folder-surface group flex min-w-0 max-w-full items-center gap-2 rounded-md border px-2.5 py-1.5 text-sm transition-colors hover:bg-accent ${s.over?`ring-2 ring-info border-info bg-accent`:``} ${e.isParent?`text-muted-foreground`:``}`,children:[(0,J.jsxs)(`span`,{className:`relative shrink-0`,children:[(0,J.jsx)(Xr,{folder:e,className:`h-4 w-4 group-hover:hidden`}),e.isParent?(0,J.jsx)(p,{className:`hidden h-4 w-4 group-hover:block`}):(0,J.jsx)(C,{className:`hidden h-4 w-4 group-hover:block`,style:e.color?{color:e.color}:void 0})]}),(0,J.jsx)(`span`,{className:`truncate`,children:e.isParent?`..`:e.label||e.name}),!e.isParent&&!!e.childCount&&(0,J.jsx)(`span`,{className:`shrink-0 text-[11px] tabular-nums text-muted-foreground`,children:e.childCount})]})}function $r({folder:e,onOpen:t,onMenu:n,onPasteDocuments:r,contextPath:i,treeName:a,workspaceId:o}){let s=Jr(e,r,i,a,o),c=e.color?{color:e.color}:void 0;return(0,J.jsxs)(`button`,{type:`button`,title:Zr(e),onClick:()=>t?.(e.path),onContextMenu:t=>Yr(t,e,n),onDragOver:s.onDragOver,onDragLeave:s.onDragLeave,onDrop:s.onDrop,className:`folder-surface group flex min-w-0 flex-col items-center gap-1.5 rounded-(--card-radius) border px-2 py-3 text-sm transition hover:bg-accent hover:shadow-elevation-2 ${s.over?`ring-2 ring-info border-info bg-accent`:``} ${e.isParent?`text-muted-foreground`:``}`,children:[(0,J.jsx)(`span`,{className:`relative flex h-14 w-14 items-center justify-center`,children:e.isParent?(0,J.jsx)(p,{className:`h-10 w-10`,strokeWidth:1.5}):(0,J.jsxs)(J.Fragment,{children:[(0,J.jsx)(v,{className:`h-14 w-14 group-hover:hidden ${e.color?``:`text-warning`}`,strokeWidth:1.25,fill:`currentColor`,fillOpacity:.18,style:c}),(0,J.jsx)(C,{className:`hidden h-14 w-14 group-hover:block ${e.color?``:`text-warning`}`,strokeWidth:1.25,fill:`currentColor`,fillOpacity:.18,style:c})]})}),(0,J.jsx)(`span`,{className:`w-full truncate text-center font-medium`,children:e.isParent?`..`:e.label||e.name}),!e.isParent&&!!e.childCount&&(0,J.jsxs)(`span`,{className:`text-[11px] tabular-nums text-muted-foreground`,children:[e.childCount,` subfolder`,e.childCount===1?``:`s`]})]})}function ei({folders:e,onOpen:t,onMenu:n,onPasteDocuments:r,contextPath:i,treeName:a,workspaceId:o}){return e.length===0?null:(0,J.jsx)(`div`,{className:`mb-4 grid grid-cols-[repeat(auto-fill,minmax(120px,1fr))] gap-3 pr-2`,onContextMenu:e=>e.stopPropagation(),children:e.map(e=>(0,J.jsx)($r,{folder:e,onOpen:t,onMenu:n,onPasteDocuments:r,contextPath:i,treeName:a,workspaceId:o},e.path))})}function ti({folders:e,onOpen:t,onMenu:n,onPasteDocuments:r,contextPath:i,treeName:a,workspaceId:o}){return e.length===0?null:(0,J.jsx)(`div`,{className:`mb-3 flex flex-wrap gap-2 pr-2`,onContextMenu:e=>e.stopPropagation(),children:e.map(e=>(0,J.jsx)(Qr,{folder:e,onOpen:t,onMenu:n,onPasteDocuments:r,contextPath:i,treeName:a,workspaceId:o},e.path))})}function ni({folder:e,onOpen:t,onMenu:n,onPasteDocuments:r,contextPath:i,treeName:a,workspaceId:o}){let s=Jr(e,r,i,a,o);return(0,J.jsxs)(mn,{"data-selection-ignore":``,className:`cursor-pointer ${s.over?`bg-accent ring-1 ring-inset ring-info`:``} ${e.isParent?`text-muted-foreground`:``}`,onClick:()=>t?.(e.path),onContextMenu:t=>Yr(t,e,n),onDragOver:s.onDragOver,onDragLeave:s.onDragLeave,onDrop:s.onDrop,title:Zr(e),children:[(0,J.jsx)(G,{className:`w-10`}),(0,J.jsx)(G,{className:`w-12`,children:(0,J.jsx)(Xr,{folder:e})}),(0,J.jsx)(G,{className:`w-full max-w-0 md:w-auto md:max-w-none`,children:(0,J.jsx)(`span`,{className:`block truncate font-medium`,children:e.isParent?`..`:e.label||e.name})}),(0,J.jsx)(G,{className:`hidden md:table-cell text-xs text-muted-foreground`,children:e.isParent?``:`Folder`}),(0,J.jsx)(G,{className:`hidden lg:table-cell`}),(0,J.jsx)(G,{className:`hidden lg:table-cell`}),(0,J.jsx)(G,{className:`hidden sm:table-cell text-xs text-muted-foreground`,children:!e.isParent&&e.childCount?`${e.childCount} subfolder${e.childCount===1?``:`s`}`:``}),(0,J.jsx)(G,{className:`w-12 md:w-auto`})]})}function ri({label:e,count:t,collapsed:n,allSelected:r,someSelected:i,onToggle:a,onSelectAll:o}){return(0,J.jsxs)(`div`,{className:`sticky top-0 z-10 -mx-1 mb-2 flex items-center gap-2 bg-background/95 px-1 py-1.5 backdrop-blur-sm`,children:[(0,J.jsx)(`input`,{type:`checkbox`,className:`h-3.5 w-3.5 cursor-pointer accent-primary ${r||i?``:`reveal-on-hover`}`,checked:r,ref:e=>{e&&(e.indeterminate=i&&!r)},onChange:e=>o(e.target.checked),title:`Select everything in "${e}"`,onClick:e=>e.stopPropagation()}),(0,J.jsxs)(`button`,{type:`button`,onClick:a,"aria-expanded":!n,className:`flex min-w-0 items-center gap-1.5 text-left text-muted-foreground transition-colors hover:text-foreground`,children:[(0,J.jsx)(re,{className:`h-3.5 w-3.5 shrink-0 transition-transform ${n?``:`rotate-90`}`}),(0,J.jsx)(`span`,{className:`truncate text-xs font-semibold uppercase tracking-wide`,children:e}),(0,J.jsx)(`span`,{className:`shrink-0 text-xs font-normal tabular-nums opacity-70`,children:t})]}),(0,J.jsx)(`div`,{className:`h-px flex-1 bg-border`})]})}function ii({readingPane:e=!1,externalSearchQuery:t,toolbarActions:n,documents:r,isLoading:i,contextPath:a,treeName:o,workspaceId:s,totalCount:p,onRemoveDocument:g,onDeleteDocument:v,onDestroyDocument:y,onRemoveDocuments:x,onDeleteDocuments:C,onDestroyDocuments:w,onCopyDocuments:ee,onCutDocuments:te,onPasteDocuments:E,onImportDocuments:O,onSelectionChange:se,pastedDocumentIds:k,viewMode:pe=`card`,allowViewToggle:me=!1,activeContextUrl:_e,currentContextUrl:be,currentPage:A=1,pageSize:j=50,onPageChange:M,onPageSizeChange:ke,onPurgeDocuments:Pe,disablePurgeDocuments:ze=!1,backendSearchQueries:Be=[],onBackendSearch:He,onRemoveBackendQuery:Ue,serverSort:F,onServerSortChange:Ge,scope:qe=`path`,onScopeChange:Ye,canSaveChanges:Xe=!1,isSavingChanges:Ze=!1,onSaveChanges:Qe,linkTree:$e,folders:tt,onOpenFolder:nt}){let rt=Cn(),it=At(),[at,ot]=(0,K.useState)(()=>{if(!me)return pe;try{let e=localStorage.getItem(`doclist:view`);if(e===`card`||e===`table`||e===`tile`)return e}catch{}return pe}),I=me?rt?.documentLayout??at:pe,st=(0,K.useCallback)(e=>{rt?.selectDocumentLayout(e),ot(e);try{localStorage.setItem(`doclist:view`,e)}catch{}},[rt]),[ct,lt]=(0,K.useState)(()=>{try{return localStorage.getItem(`doclist:groupdates`)!==`off`}catch{return!0}}),ut=(0,K.useCallback)(()=>{lt(e=>{let t=!e;try{localStorage.setItem(`doclist:groupdates`,t?`on`:`off`)}catch{}return t})},[]),[dt,ft]=(0,K.useState)(new Set),pt=(0,K.useCallback)(e=>{ft(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},[]),[L,R]=(0,K.useState)(new Set),[z,B]=(0,K.useState)(null),[ht,gt]=(0,K.useState)(null),_t=zt(),vt=!!(_t&&s),yt=(0,K.useCallback)((e,t=!1)=>{if(!_t||!s)return;let n=e.map(e=>r.find(t=>t.id===e)).filter(e=>!!e);n.length!==0&&_t.openAddRelated({workspaceName:s,documents:n},t)},[_t,s,r]),[bt,Ct]=(0,K.useState)(!1),[V,Et]=(0,K.useState)(null),[Dt,Ot]=(0,K.useState)(!1),[kt,jt]=(0,K.useState)(null),[Mt,Nt]=(0,K.useState)(!1),Ft=(0,K.useRef)(!1),It=(0,K.useRef)(!1),H=o===`backends`&&qe===`path`?rn(a):null;(0,K.useEffect)(()=>()=>{Ft.current=!0},[]);let[Lt,Rt]=(0,K.useState)(!1),[Bt,Vt]=(0,K.useState)(null),[Ht,Ut]=(0,K.useState)(!1),[Wt,Gt]=(0,K.useState)(null),Kt=Pt()==null&&!!s,[qt,Jt]=(0,K.useState)(null),[Xt,U]=(0,K.useState)(null),$t=!!($e&&E),en=!!s,{showSuccessToast:tn,showErrorToast:nn}=Qt(),{showProgress:an}=Ae(),on=Tt(),sn=s?e=>on.open(e,s):void 0,cn=qe===`workspace`,ln=cn?void 0:g,un=cn?void 0:x,[dn,fn]=(0,K.useState)(!1),[G,xn]=(0,K.useState)(!1),[Sn,wn]=(0,K.useState)(``),q=t??Sn,Tn=t!==void 0,[En,Dn]=(0,K.useState)(!1),On=Be.length>0,kn=(0,K.useRef)(null),An=(0,K.useCallback)(()=>{wn(``),kn.current&&(kn.current.value=``)},[]);(0,K.useEffect)(()=>{if(!me||window.matchMedia(`(max-width: 767px)`).matches)return;let e=kn.current;if(!e)return;let t=setTimeout(()=>{let t=window.document.activeElement;t&&t!==window.document.body||e.focus()},60);return()=>clearTimeout(t)},[me]);let jn=JSON.stringify([s,o,a]),[Mn,Nn]=(0,K.useState)(jn);jn!==Mn&&(Nn(jn),R(new Set),Et(null),gt(null),B(null)),(0,K.useEffect)(()=>{se?.(Array.from(L))},[L,se]);let Pn=(0,K.useCallback)(()=>{if(!He)return;let e=q.trim();e&&(He(e),An())},[He,q,An]),Fn=(0,K.useCallback)(()=>{An(),Ue&&Be.length>0&&Ue(-1)},[Ue,Be.length,An]),In=(0,K.useCallback)((e,t)=>{let n;L.has(t)&&L.size>1?n=Array.from(L):(n=[t],R(new Set([t])));let r={type:`document`,documentIds:n,sourcePath:qe===`path`?a:void 0,sourceTreeName:o,sourceWorkspaceId:s};e.dataTransfer.setData(`application/json`,JSON.stringify(r)),e.dataTransfer.effectAllowed=`copyMove`,e.dataTransfer.setDragImage(e.currentTarget,0,0)},[L,a,o,s,qe]),Ln=(0,K.useCallback)(async e=>{if(!E)return;let t=e.dataTransfer.getData(`application/json`);if(!t)return;let n=null;try{n=JSON.parse(t)}catch{return}n?.type!==`document`||!Array.isArray(n.documentIds)||n.documentIds.length===0||(e.preventDefault(),e.stopPropagation(),Dn(!1),!sr(n,s,o,a)&&(await E(a,n.documentIds,{move:e.shiftKey,sourcePath:n.sourcePath,sourceTreeName:n.sourceTreeName}),R(new Set)))},[a,o,s,E]),zn=(0,K.useCallback)(e=>{E&&Array.from(e.dataTransfer.types).includes(`application/json`)&&(e.preventDefault(),e.dataTransfer.dropEffect=e.shiftKey?`move`:`copy`,Dn(!0))},[E]),Hn=(0,K.useCallback)(e=>{e.currentTarget.contains(e.relatedTarget)||Dn(!1)},[]),Un=(0,K.useMemo)(()=>({keys:[{name:`data.title`,weight:.4},{name:`data.name`,weight:.4},{name:`locations.url`,weight:.4},{name:`data.url`,weight:.3},{name:`data.content`,weight:.2},{name:`data.description`,weight:.2}],threshold:.4,location:0,distance:100,minMatchCharLength:1,includeScore:!0,includeMatches:!0,ignoreLocation:!0}),[]),Y=(0,K.useMemo)(()=>r.length===0?null:new pn(r,Un),[r,Un]),X=(0,K.useDeferredValue)(q),Z=(0,K.useMemo)(()=>{if(!X.trim())return r;let{text:e,ids:t,invalid:n}=Vn(X);if(n)return[];let i=e&&Y?Y.search(e).map(e=>e.item):r;return t.length?i.filter(e=>t.every(t=>e.id===t)):i},[r,X,Y]),Gn=(0,K.useMemo)(()=>{if(!tt||tt.length===0||X.trim())return[];let e=F?.order===`desc`?-1:1;return[...tt].sort((t,n)=>Number(!!n.isParent)-Number(!!t.isParent)||(t.label||t.name).localeCompare(n.label||n.name,void 0,{numeric:!0,sensitivity:`base`})*e)},[tt,X,F?.order]),Yn=Gn.length>0,[Xn,Zn]=(0,K.useState)(null),Qn=(0,K.useMemo)(()=>s&&o&&nt?(e,t)=>Zn({x:t.clientX,y:t.clientY,path:e}):void 0,[s,o,nt]),$n={folders:Gn,onOpen:nt,onMenu:Qn,onPasteDocuments:E,contextPath:a,treeName:o,workspaceId:s},tr=(0,K.useMemo)(()=>({title:e=>P(e).title?.toLowerCase()??``,schema:e=>P(e).schemaLabel??``,type:Je,id:e=>e.id,created:e=>Date.parse(e.createdAt)||0}),[]),{sorted:rr,sort:ir,toggleSort:or}=bn(Z,tr),cr=(0,K.useCallback)(e=>_r(e,F?.sortBy),[F?.sortBy]),lr=(0,K.useMemo)(()=>wr(Z,cr,F?.order===`asc`?`asc`:`desc`),[Z,cr,F?.order]),dr=ct&&!Ve(F?.sortBy)&&lr.length>1,fr=(0,K.useCallback)((e,t)=>{R(n=>{let r=new Set(n);for(let n of e)t?r.add(n):r.delete(n);return r})},[]),pr=(0,K.useMemo)(()=>(I===`table`?rr:dr?lr.filter(e=>!dt.has(e.key)).flatMap(e=>e.items):Z).map(e=>e.id),[I,rr,dr,lr,dt,Z]),mr=(0,K.useRef)(null),hr=JSON.stringify([s,a,o,A]),Q=(0,K.useCallback)(e=>{mr.current=null,R(t=>t.size===e.size&&[...t].every(t=>e.has(t))?t:e)},[]),$=(0,K.useCallback)((e,t,n,r=!1)=>{let i=mr.current,a=i?.scope===hr&&pr.includes(i.id)?i.id:null;(!r||a===null)&&(mr.current={scope:hr,id:e}),R(i=>{if(r)return Wn(pr,a,e,i,n);let o=n?new Set(i):new Set;return t?o.add(e):o.delete(e),o})},[hr,pr]),vr=(0,K.useCallback)((e,t)=>{let n;L.has(e)?n=Array.from(L):(n=[e],R(new Set([e]))),B({anchor:t,ids:n})},[L]),yr=(0,K.useCallback)((e,t)=>{vr(t,Fe(e))},[vr]),br=(0,K.useCallback)((e,t)=>{e.target.closest?.(`[role="dialog"]`)||(e.preventDefault(),e.stopPropagation(),vr(t,Ir(e)))},[vr]),xr=(0,K.useCallback)(async(e,t)=>{if(t.length!==0&&e.targetIds.length!==0){Ct(!0);try{for(let n of t)await et(s,n,e.predicate,e.targetIds,e.direction);let n=t.length*e.targetIds.length;tn(`Created ${n} relation${n===1?``:`s`}`),Yt(),gt(null)}catch(e){nn(e instanceof Error?e.message:`Failed to create relations`)}finally{Ct(!1)}}},[s,tn,nn]),Sr=(0,K.useCallback)(async(e,t,n)=>{if(E){for(let r of e)await E(r,t,{move:!1,targetTreeName:n?.treeName,targetTreeType:n?.treeType});R(new Set)}},[E]),Cr=(0,K.useCallback)(async(e,t,n)=>{if(!s||!V||It.current)return;It.current=!0,Ft.current=!1,Nt(!1),Ot(!0);let i=an({title:t===`delete`?`Deleting…`:t===`move`?`Moving…`:`Copying…`,description:`${V.ids.length} document(s) · ${e.join(`, `)}`});try{let a=r=>mt(s,r,{to:e,mode:t,keepDocument:n.keepDocument,...t===`delete`&&H?{deleteFrom:{backend:H.backend,folder:H.rel}}:{},folder:n.folder,filename:n.filename,onConflict:n.onConflict}),o=t===`delete`?await Bn(V.ids,a,{shouldStop:()=>Ft.current,onProgress:(t,n)=>{jt({completed:t,total:n}),i.update({title:`Deleting…`,description:`${t} / ${n} document(s) · ${e.join(`, `)}`})}}):{...await a(V.ids),pending:[]},c=o.successful.filter(e=>e.transfers?.every(e=>e.state===`unchanged`)).length,l=o.successful.filter(e=>e.transfers?.some(e=>e.state===`pending`)).length,u=o.successful.length-c-l,d=o.failed.length,f=t===`delete`?`Deleted from`:t===`move`?`Moved to`:`Copied to`,p=e.join(`, `),m=[c?`${c} already there`:null,l?`${l} queued for backend sync`:null,d?`${d} skipped`:null,o.pending.length?`${o.pending.length} not processed`:null].filter(Boolean).join(` · `),h=`${f} ${p}: ${u} document${u===1?``:`s`}${m?` · ${m}`:``}`;d>0?(i.fail({title:`Operation incomplete`,description:`${h}. ${wt(o.failed,new Map(r.map(e=>[e.id,P(e).title])))}`,variant:`destructive`}),console.warn(`Backend transfer skipped documents:`,o.failed)):i.done({title:o.pending.length?`Operation stopped`:l?`Transfer queued`:`Operation complete`,description:h}),window.dispatchEvent(new CustomEvent(`workspace:documents:refresh`));let g=[...o.failed.map(e=>e.id),...o.pending];Et(g.length?{ids:g,mode:t}:null),R(new Set(g))}catch(e){i.fail({title:`Operation failed`,description:e instanceof Error?e.message:String(e),variant:`destructive`})}finally{It.current=!1,Ot(!1),jt(null)}},[s,V,H,r,an]),Tr=(0,K.useCallback)(()=>{L.size===Z.length?R(new Set):R(new Set(Z.map(e=>e.id)))},[L.size,Z]),Er=(0,K.useCallback)(async e=>{try{await navigator.clipboard.writeText(e)}catch{let t=window.document.createElement(`textarea`);t.value=e,window.document.body.appendChild(t),t.select(),window.document.execCommand(`copy`),window.document.body.removeChild(t)}},[]),Dr=e=>{if(e.length===0)return[];let t=e.length,n=t>1?` (${t})`:``,i=t===1?r.find(t=>t.id===e[0]):void 0,a=()=>R(new Set),c=e.some(e=>r.find(t=>t.id===e)?.locations?.some(e=>e.status==null||e.status===`available`)),l=[],d=e=>{e&&l.push(e)};if(i){let e=i.schema===`data/schema/tab`?i.data.url:null;d({id:`view`,group:`open`,label:`View details`,icon:de,run:()=>U({document:i})}),d(Kt&&{id:`edit`,group:`open`,label:`Edit`,icon:f,run:()=>U({document:i,edit:!0})}),d(Kt&&i.schema===`data/schema/file`&&{id:`rename`,group:`open`,label:`Rename…`,icon:f,run:()=>U({document:i,edit:!0})});let t=i.data?.url||i.data?.uri;d(Kt&&s&&i.schema!==`data/schema/file`&&typeof t==`string`&&/^https?:\/\//i.test(t)&&{id:`download-link`,group:`open`,label:`Download to workspace`,icon:Ce,run:async()=>{let e=an({title:`Downloading file…`});try{await Ke(s,i.id),window.dispatchEvent(new CustomEvent(`workspace:documents:refresh`)),e.done({title:`File saved to workspace`})}catch(t){e.fail({title:`Download failed`,description:t instanceof Error?t.message:String(t),variant:`destructive`})}}}),d(e&&{id:`open-url`,group:`open`,label:`Open URL`,icon:he,run:()=>{window.open(e,`_blank`,`noopener,noreferrer`)}}),d(sn&&{id:`open-side`,group:`open`,label:`Open to the side`,icon:ie,run:()=>sn(i)})}return d(ee&&{id:`copy`,group:`clipboard`,label:`Copy${n}`,icon:T,shortcut:`Mod+C`,run:()=>ee(e)}),d(te&&{id:`cut`,group:`clipboard`,label:`Cut${n}`,icon:Te,shortcut:`Mod+X`,run:()=>te(e)}),d(i&&{id:`copy-id`,group:`clipboard`,label:`Copy ID`,icon:oe,run:()=>Er(String(i.id))}),d(i&&Kt&&{id:`create-rule`,group:`organize`,label:`Create rule…`,icon:xe,run:()=>Jt(i)}),d($t&&{id:`link-to`,group:`organize`,label:`Link to…${n}`,icon:Se,run:()=>gt(e)}),d(vt&&{id:`add-related`,group:`organize`,label:`Add related document…${n}`,icon:S,run:t=>yt(e,t?.shiftKey)}),d(Kt&&{id:`bulk-edit`,group:`organize`,label:`Bulk edit…${n}`,icon:f,run:()=>Gt(e)}),d(Kt&&{id:`copy-workspace`,group:`organize`,label:`Copy to workspace…`,icon:T,run:t=>{Ut(!!t?.shiftKey),Vt(e)}}),d({id:`export`,group:`organize`,label:`Export…${n}`,icon:Ce,run:()=>fn(!0)}),d(o!==`backends`&&(ln||un)&&{id:`remove`,group:`remove`,label:`Remove (unlink) from folder${n}`,icon:_,shortcut:`Delete`,hint:`Unlinks from this folder; the document stays in the index`,run:()=>{t===1&&ln?ln(e[0]):un?.(e),a()}}),d(o!==`backends`&&(v||C)&&{id:`delete`,group:`remove`,label:`Delete from index${n}`,icon:ae,destructive:!0,hint:`Removes the document from the index entirely; file data stays on its backend(s)`,run:()=>{t===1&&v?v(e[0]):C?.(e),a()}}),c&&en?(d({id:`backend-copy`,group:`backends`,groupLabel:`Backends`,label:`Copy to backend…${n}`,icon:u,hint:`Copy the file data to another storage backend (keeps the existing copies)`,run:()=>Et({ids:e,mode:`copy`})}),d({id:`backend-move`,group:`backends`,label:`Move to backend…${n}`,icon:ue,hint:`Move the file data to another storage backend (source released once the copy is durable)`,run:()=>Et({ids:e,mode:`move`})}),d({id:`backend-delete`,group:`backends`,label:`Delete from backend…${n}`,icon:ae,destructive:!0,hint:`Delete the file data from selected backends (copies elsewhere are kept)`,run:()=>Et({ids:e,mode:`delete`})})):c&&(y||w)&&d({id:`destroy`,group:`backends`,label:`Delete from backend(s)${n}`,icon:ae,destructive:!0,hint:`Deletes the document and its file data from the storage backend(s)`,run:()=>{t===1&&y?y(e[0]):w?.(e),a()}}),l},Or=()=>{let e=[],t=t=>{t&&e.push(t)},n=k??[];return t(E&&n.length>0&&{id:`paste`,group:`clipboard`,label:`Paste (${n.length})`,icon:l,shortcut:`Mod+V`,run:async()=>{try{await E(a,n)}catch(e){console.error(`Failed to paste documents:`,e)}}}),t(Z.length>0&&{id:`select-all`,group:`select`,label:q?`Select all matches (${Z.length})`:`Select all on this page`,icon:ge,shortcut:`Mod+A`,run:()=>R(new Set(Z.map(e=>e.id)))}),t(L.size>0&&{id:`select-none`,group:`select`,label:`Clear selection`,icon:ye,run:()=>R(new Set)}),t(E&&{id:`add-existing`,group:`add`,label:`Add existing documents…`,icon:le,hint:`Browse and add existing documents to this folder`,run:()=>Rt(!0)}),t(O&&{id:`import`,group:`add`,label:`Import…`,icon:D,run:()=>xn(!0)}),t(r.length>0&&{id:`export-all`,group:`add`,label:`Export all…`,icon:Ce,run:()=>{R(new Set),fn(!0)}}),t(Pe&&p>0&&{id:`purge`,group:`purge`,label:`Purge all (${p})`,icon:ae,destructive:!0,disabled:ze||!!q,hint:q?`Purge is disabled while local search is active`:ze?`Purge requires loaded server results with no browser-only or live selection`:`Delete all documents matching the current server-side filters across all pages`,run:Pe}),e},kr=!!(Ge&&F&&s),Ar=z?z.ids?Dr(z.ids):Or():[],Mr=z?.ids?.length===1?r.find(e=>e.id===z.ids[0]):void 0,Fr=Mr?(0,J.jsxs)(`div`,{className:`flex items-start gap-3`,children:[(0,J.jsx)(W,{document:Mr,chip:!0}),(0,J.jsxs)(`div`,{className:`min-w-0`,children:[(0,J.jsx)(`div`,{className:`truncate text-base font-semibold`,children:P(Mr).title}),(0,J.jsxs)(`div`,{className:`truncate text-xs text-muted-foreground`,children:[`ID: `,Mr.id,` · `,Mr.schema]})]})]}):(0,J.jsx)(`div`,{className:`truncate text-base font-semibold`,children:z?.ids?`${z.ids.length} documents`:`This folder`}),Lr=e=>{B({anchor:Fe(e.currentTarget),ids:L.size>0?Array.from(L):null})},Rr=e=>{e.target.closest?.(`[role="dialog"]`)||(e.preventDefault(),e.stopPropagation(),R(new Set),B({anchor:Ir(e),ids:null}))},zr=e=>{if(e.defaultPrevented||Ie(e.target))return;let t=e.target.closest?.(`[data-document-id]`)??null;if(Ne(e)){e.preventDefault(),t?vr(Number(t.dataset.documentId),Fe(t,`inside`)):B({anchor:Fe(e.target,`inside`),ids:L.size>0?Array.from(L):null});return}if(e.key===`ArrowDown`||e.key===`ArrowUp`){let n=Array.from(e.currentTarget.querySelectorAll(`[data-document-id]`));if(n.length===0)return;let r=t?n.indexOf(t):-1,i=n[e.key===`ArrowDown`?Math.min(r+1,n.length-1):Math.max(r-1,0)];e.preventDefault(),i.focus({preventScroll:!0}),i.scrollIntoView({block:`nearest`}),e.shiftKey&&$(Number(i.dataset.documentId),!0,!1,!0);return}if(e.key===`Escape`&&L.size>0){e.preventDefault(),R(new Set);return}Re(e,[...Dr(Array.from(L)),...Or()])},Hr=(0,K.useCallback)(async e=>{if(!O)return!1;try{return await O(e,a)}catch(e){return console.error(`Failed to import documents:`,e),!1}},[O,a]),Ur=e=>dr?lr.map(t=>{let n=dt.has(t.key),r=t.items.map(e=>e.id),i=r.reduce((e,t)=>e+ +!!L.has(t),0);return(0,J.jsxs)(`section`,{className:`group mb-4`,children:[(0,J.jsx)(ri,{label:t.label,count:t.items.length,collapsed:n,allSelected:i===r.length,someSelected:i>0,onToggle:()=>pt(t.key),onSelectAll:e=>fr(r,e)}),!n&&e(t.items)]},t.key)}):e(Z);return i?(0,J.jsx)(Rn,{enabled:e,workspaceId:s,scope:JSON.stringify([s,o,a]),documents:[],loading:!0,children:(0,J.jsx)(`div`,{className:`flex-1 flex items-center justify-center`,children:(0,J.jsxs)(`div`,{className:`text-center space-y-2`,children:[(0,J.jsx)(`div`,{className:`animate-spin rounded-full h-8 w-8 border-b-2 border-primary mx-auto`}),(0,J.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`Loading documents...`})]})})}):(0,J.jsx)(Rn,{enabled:e,workspaceId:s,scope:JSON.stringify([s,o,a]),documents:I===`table`?rr:Z,loading:!1,children:(0,J.jsxs)(`div`,{tabIndex:-1,onKeyDown:zr,className:`flex-1 flex flex-col min-h-0 min-w-0 p-4 rounded-(--card-radius) outline-none transition-colors ${En?`ring-2 ring-inset ring-primary bg-primary/5`:``}`,onDragOver:zn,onDragLeave:Hn,onDrop:Ln,children:[(0,J.jsxs)(`div`,{className:`border-b pb-3 mb-4 flex-shrink-0`,children:[(0,J.jsxs)(`div`,{className:`min-w-0 space-y-0.5`,children:[(0,J.jsxs)(`div`,{className:`flex items-baseline justify-between gap-2`,children:[(0,J.jsx)(`h3`,{className:`font-semibold text-sm text-muted-foreground`,children:`Documents`}),(0,J.jsx)(`p`,{className:`shrink-0 text-sm font-medium`,children:q?`${Z.length} of ${r.length}`:`${p.toLocaleString()} document${p===1?``:`s`}`})]}),(0,J.jsxs)(`div`,{className:`flex items-baseline justify-between gap-2 text-xs text-muted-foreground`,children:[(0,J.jsxs)(`p`,{hidden:Tn,className:`min-w-0 truncate`,children:[`Context: `,(0,J.jsx)(`span`,{className:`font-mono`,children:a}),_e&&be&&_e!==be&&(0,J.jsx)(`span`,{className:`text-warning ml-2`,children:`(not yet active)`})]}),(0,J.jsxs)(`p`,{className:`shrink-0`,children:[L.size>0&&(0,J.jsxs)(`span`,{className:`text-info`,children:[L.size,` selected`]}),L.size>0&&(q||p>j)&&(0,J.jsx)(`span`,{className:`mx-1`,children:`·`}),q?`on this page`:p>j?`Showing ${Math.min((A-1)*j+1,p)}–${Math.min(A*j,p)}`:null]})]})]}),!Tn&&(0,J.jsxs)(`div`,{className:`mt-3 space-y-2`,children:[(0,J.jsxs)(`div`,{className:`relative flex flex-wrap items-center gap-2`,children:[!Tn&&Ye&&(0,J.jsxs)(`div`,{className:`flex shrink-0 rounded-md border border-input overflow-hidden text-xs font-medium`,children:[(0,J.jsx)(`button`,{type:`button`,onClick:()=>Ye(`path`),className:`px-2.5 py-2 transition-colors ${qe===`path`?`bg-primary text-primary-foreground`:`bg-background text-muted-foreground hover:text-foreground hover:bg-muted`}`,title:`List documents in the selected path`,children:`This path`}),(0,J.jsxs)(`button`,{type:`button`,onClick:()=>Ye(`workspace`),className:`px-2.5 py-2 border-l border-input transition-colors flex items-center gap-1 ${qe===`workspace`?`bg-primary text-primary-foreground`:`bg-background text-muted-foreground hover:text-foreground hover:bg-muted`}`,title:`List every document in the workspace (staging excluded)`,children:[(0,J.jsx)(ne,{className:`h-3.5 w-3.5`}),`Whole workspace`]})]}),!Tn&&(0,J.jsxs)(`div`,{className:`relative flex-1 min-w-[12rem]`,children:[(0,J.jsx)(De,{className:`absolute left-3 top-1/2 transform -translate-y-1/2 h-4 w-4 text-muted-foreground pointer-events-none`}),(0,J.jsx)(`input`,{ref:kn,type:`text`,placeholder:He?On?`Refine: add another query (Enter)…`:`Search documents (Enter for server search)…`:`Search documents...`,title:`Search text or an exact document ID, e.g. @id:101140. Press Enter to search the server.`,defaultValue:``,onChange:e=>wn(e.target.value),onFocus:e=>{let t=e.currentTarget;window.matchMedia(`(max-width: 767px)`).matches&&setTimeout(()=>t.scrollIntoView({block:`center`,behavior:`smooth`}),250)},onKeyDown:e=>{e.key===`Enter`&&He&&(e.preventDefault(),Pn())},className:`w-full pl-10 pr-9 py-2 border border-input rounded-md bg-background text-sm placeholder:text-muted-foreground focus:outline-none focus:ring-2 focus:ring-ring focus:border-transparent`}),He&&s&&(0,J.jsx)(xt,{workspaceId:s,inputRef:kn,onChange:wn}),(q||On)&&(0,J.jsx)(`button`,{onClick:Fn,className:`absolute right-3 top-1/2 transform -translate-y-1/2 h-4 w-4 text-muted-foreground hover:text-foreground`,title:`Clear search`,children:(0,J.jsx)(b,{className:`h-4 w-4`})})]}),!Tn&&He&&q.trim()&&!Be.includes(q.trim())&&(0,J.jsxs)(N,{size:`sm`,variant:`default`,onClick:Pn,className:`shrink-0`,title:On?`Refine: narrow the current results by this query`:`Run full-text search on the server`,children:[(0,J.jsx)(De,{className:`h-3.5 w-3.5 mr-1`}),On?`Refine`:`Search server`]})]}),!Tn&&On&&(0,J.jsxs)(`div`,{className:`flex flex-wrap items-center gap-1.5 text-xs`,children:[(0,J.jsx)(`span`,{className:`text-muted-foreground`,children:`Server search:`}),Be.map((e,t)=>(0,J.jsxs)(`span`,{className:`flex items-center gap-1`,children:[t>0&&(0,J.jsx)(`span`,{className:`text-muted-foreground/70 font-medium uppercase text-[10px]`,children:`then`}),(0,J.jsxs)(`span`,{className:`flex items-center gap-1 px-2 py-0.5 rounded bg-muted text-foreground border`,children:[(0,J.jsxs)(`span`,{className:`font-mono`,children:[`"`,e,`"`]}),Ue&&(0,J.jsx)(`button`,{onClick:()=>Ue(t),className:`text-muted-foreground hover:text-foreground`,title:`Remove this query`,children:(0,J.jsx)(b,{className:`h-3 w-3`})})]})]},`${e}-${t}`)),Ue&&Be.length>1&&(0,J.jsx)(`button`,{onClick:()=>Ue(-1),className:`ml-1 text-muted-foreground hover:text-foreground underline`,title:`Clear all queries`,children:`clear all`})]})]}),(0,J.jsx)(`div`,{className:`document-toolbar mt-3`,children:(0,J.jsxs)(`div`,{className:`document-toolbar-row`,children:[(0,J.jsxs)(`div`,{className:`document-toolbar-controls`,children:[(0,J.jsxs)(`div`,{className:`flex shrink-0 items-center gap-2`,role:`group`,"aria-label":`Document layout`,children:[me&&(0,J.jsx)(`div`,{className:`flex shrink-0 items-center rounded-md border p-0.5 touch-target`,children:[[`table`,c,`Table view`],[`tile`,we,`Tile view`],[`card`,Ee,`Card view`]].map(([e,t,n])=>(0,J.jsx)(`button`,{type:`button`,onClick:()=>st(e),title:n,"aria-pressed":I===e,className:`rounded-sm p-1.5 transition-colors focus-ring ${I===e?`bg-primary text-primary-foreground`:`text-muted-foreground hover:bg-accent/50`}`,children:(0,J.jsx)(t,{className:`h-4 w-4`})},e))}),me&&I!==`table`&&!Ve(F?.sortBy)&&(0,J.jsx)(`button`,{type:`button`,onClick:ut,title:ct?`Grouping by date — click for a flat list`:`Group by date (Today, Yesterday, …)`,"aria-pressed":ct,className:`touch-target shrink-0 rounded-md border p-1.5 transition-colors focus-ring ${ct?`bg-primary text-primary-foreground`:`text-muted-foreground hover:bg-accent/50`}`,children:(0,J.jsx)(ve,{className:`h-4 w-4`})})]}),M&&p>0&&(0,J.jsxs)(`div`,{className:`flex shrink-0 items-center gap-1.5`,children:[(0,J.jsx)(`span`,{className:`document-toolbar-label`,children:`Show:`}),(0,J.jsxs)(`select`,{value:j,onChange:e=>ke?.(Number(e.target.value)),className:`h-control-sm rounded-(--input-radius) border-(length:--input-border-width) border-input bg-background px-2 text-sm focus-ring`,"aria-label":`Documents per page`,children:[(0,J.jsx)(`option`,{value:25,children:`25`}),(0,J.jsx)(`option`,{value:50,children:`50`}),(0,J.jsx)(`option`,{value:100,children:`100`}),(0,J.jsx)(`option`,{value:200,children:`200`})]}),(0,J.jsx)(`span`,{className:`document-toolbar-label`,children:`per page`})]})]}),(0,J.jsxs)(`div`,{className:`document-toolbar-secondary`,children:[kr&&(0,J.jsxs)(`div`,{className:`document-toolbar-sort flex min-w-0 items-center gap-1.5`,children:[(0,J.jsx)(`span`,{className:`document-toolbar-label`,children:`Sort`}),(0,J.jsx)(gr,{workspaceId:s,value:F,onChange:Ge})]}),(0,J.jsxs)(`div`,{className:`document-toolbar-actions`,children:[(r.length>0||O||E)&&(0,J.jsxs)(`div`,{className:`contents`,children:[(0,J.jsxs)(N,{variant:`outline`,size:`sm`,onClick:Lr,"aria-haspopup":`menu`,"aria-label":L.size>0?`Actions (${L.size} selected)`:`Actions`,className:`document-toolbar-action-button flex items-center gap-1.5 touch-target`,title:`Actions (${Me(`Shift+F10`)} or right-click)`,children:[(0,J.jsx)(fe,{className:`h-4 w-4`}),(0,J.jsxs)(`span`,{className:`document-toolbar-action-label`,children:[`Actions`,L.size>0?` (${L.size} selected)`:``]})]}),L.size>0&&(0,J.jsxs)(N,{variant:`ghost`,size:`sm`,onClick:()=>R(new Set),"aria-label":`Clear selection`,className:`document-toolbar-action-button touch-target`,title:`Clear selection (Esc)`,children:[(0,J.jsx)(b,{className:`h-3.5 w-3.5`}),(0,J.jsx)(`span`,{className:`document-toolbar-action-label`,children:`Clear`})]}),k&&k.length>0&&E&&(0,J.jsxs)(N,{variant:`outline`,size:`sm`,onClick:()=>E(a,k),className:`flex items-center gap-1.5`,title:`Paste into this folder (${Me(`Mod+V`)})`,children:[(0,J.jsx)(l,{className:`h-4 w-4`}),`Paste (`,k.length,`)`]})]}),Xe&&Qe&&(0,J.jsx)(N,{size:`sm`,variant:`outline`,onClick:Qe,disabled:Ze,className:`w-control-sm shrink-0 px-0 touch-target`,"aria-label":Ze?`Saving filters`:`Save current query and filters`,title:`Save current query and filters`,children:(0,J.jsx)(m,{className:`h-3.5 w-3.5`})}),n]})]})]})}),M&&p>j&&(0,J.jsxs)(`div`,{className:`document-pagination mt-3 flex min-w-0 flex-wrap items-center justify-end gap-2 border-t pt-3 max-sm:gap-0.5`,children:[(0,J.jsxs)(`span`,{className:`text-sm text-muted-foreground max-md:hidden`,children:[`Showing `,Math.min((A-1)*j+1,p),` - `,Math.min(A*j,p),` of `,p]}),(0,J.jsxs)(`div`,{className:`flex items-center gap-1 max-sm:gap-0.5`,children:[(0,J.jsx)(N,{variant:`outline`,size:`sm`,"aria-label":`First page`,onClick:()=>M(1),disabled:A===1,className:`p-1 touch-target`,children:(0,J.jsx)(d,{className:`h-4 w-4`})}),(0,J.jsx)(N,{variant:`outline`,size:`sm`,"aria-label":`Previous page`,onClick:()=>M(A-1),disabled:A===1,className:`p-1 touch-target`,children:(0,J.jsx)(h,{className:`h-4 w-4`})}),(0,J.jsxs)(`span`,{className:`whitespace-nowrap px-3 py-1 text-sm font-medium max-sm:px-1 max-sm:text-xs`,children:[(0,J.jsx)(`span`,{className:`max-sm:sr-only`,children:`Page `}),A,(0,J.jsx)(`span`,{className:`max-sm:hidden`,children:` of `}),(0,J.jsx)(`span`,{className:`sm:hidden`,children:`/`}),Math.ceil(p/j)]}),(0,J.jsx)(N,{variant:`outline`,size:`sm`,"aria-label":`Next page`,onClick:()=>M(A+1),disabled:A>=Math.ceil(p/j),className:`p-1 touch-target`,children:(0,J.jsx)(re,{className:`h-4 w-4`})}),(0,J.jsx)(N,{variant:`outline`,size:`sm`,"aria-label":`Last page`,onClick:()=>M(Math.ceil(p/j)),disabled:A>=Math.ceil(p/j),className:`p-1 touch-target`,children:(0,J.jsx)(Oe,{className:`h-4 w-4`})})]})]})]}),(0,J.jsx)(er,{scope:JSON.stringify([hr,I,pr]),selected:L,onSelectionChange:Q,onContextMenu:Rr,children:Z.length===0&&!Yn?(0,J.jsx)(`div`,{className:`min-h-full flex items-center justify-center`,children:(0,J.jsxs)(`div`,{className:`text-center space-y-2`,children:[(0,J.jsx)(ce,{className:`h-12 w-12 text-muted-foreground/50 mx-auto`}),(0,J.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:q?`No documents match your search`:`No documents found in this context`}),(0,J.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:q?(0,J.jsxs)(J.Fragment,{children:[`Search: `,(0,J.jsxs)(`span`,{className:`font-mono`,children:[`"`,q,`"`]})]}):(0,J.jsxs)(J.Fragment,{children:[`Path: `,(0,J.jsx)(`span`,{className:`font-mono`,children:a})]})}),!Tn&&q&&(0,J.jsx)(`button`,{onClick:An,className:`text-xs text-primary hover:text-primary/80 underline mt-1`,children:`Clear search`}),!q&&k&&k.length>0&&(0,J.jsxs)(`p`,{className:`text-xs text-muted-foreground`,children:[`Right-click or press `,Me(`Mod+V`),` to paste `,k.length,` document(s)`]})]})}):I===`tile`?(0,J.jsxs)(`div`,{children:[(0,J.jsx)(ei,{...$n}),Z.length===0&&(0,J.jsx)(`p`,{className:`py-6 text-center text-xs text-muted-foreground`,children:`No documents in this folder`}),Ur(e=>(0,J.jsx)(`div`,{className:`document-tiles pr-2`,"data-tile-style":it,children:e.map(e=>(0,J.jsx)(qr,{document:e,isSelected:L.has(e.id),workspaceId:s,onSelect:$,onOpenToSide:sn,onRightClick:br,onOpenActions:yr,onDragStart:In},e.id))}))]}):I===`table`?(0,J.jsx)(`div`,{children:(0,J.jsxs)(vn,{children:[(0,J.jsx)(yn,{children:(0,J.jsxs)(mn,{children:[(0,J.jsx)(_n,{className:`w-10`,children:(0,J.jsx)(`input`,{type:`checkbox`,className:`h-4 w-4 cursor-pointer accent-primary align-middle`,checked:Z.length>0&&L.size===Z.length,ref:e=>{e&&(e.indeterminate=L.size>0&&L.size<Z.length)},onChange:Tr,title:`Select all on this page`})}),(0,J.jsx)(gn,{label:(0,J.jsx)(`span`,{className:`max-md:sr-only`,children:`Type`}),sortKey:`type`,sort:ir,onSort:or,className:`w-12`}),(0,J.jsx)(gn,{label:`Title`,sortKey:`title`,sort:ir,onSort:or,className:`w-full max-w-0 md:w-auto md:max-w-none`}),(0,J.jsx)(gn,{label:`Schema`,sortKey:`schema`,sort:ir,onSort:or,className:`hidden md:table-cell`}),(0,J.jsx)(gn,{label:`ID`,sortKey:`id`,sort:ir,onSort:or,className:`hidden lg:table-cell`}),(0,J.jsx)(_n,{className:`hidden lg:table-cell`,children:`Checksum`}),(0,J.jsx)(gn,{label:`Created`,sortKey:`created`,sort:ir,onSort:or,className:`hidden sm:table-cell`}),(0,J.jsx)(_n,{className:`w-12 md:w-auto`,children:(0,J.jsx)(`span`,{className:`max-md:sr-only`,children:`Actions`})})]})}),(0,J.jsxs)(hn,{children:[Gn.map(e=>(0,J.jsx)(ni,{folder:e,onOpen:nt,onMenu:Qn,onPasteDocuments:E,contextPath:a,treeName:o,workspaceId:s},e.path)),rr.map(e=>(0,J.jsx)(Br,{document:e,isSelected:L.has(e.id),workspaceId:s,onSelect:$,onOpenToSide:sn,onRightClick:br,onOpenActions:yr,onDragStart:In},e.id))]})]})}):(0,J.jsxs)(`div`,{children:[(0,J.jsx)(ti,{...$n}),Z.length===0&&(0,J.jsx)(`p`,{className:`py-6 text-center text-xs text-muted-foreground`,children:`No documents in this folder`}),Ur(e=>(0,J.jsx)(`div`,{className:`space-y-3 pr-2`,children:e.map(e=>(0,J.jsx)(`div`,{children:(0,J.jsx)(Vr,{document:e,isSelected:L.has(e.id),workspaceId:s,onSelect:$,onOpenToSide:sn,onRightClick:br,onOpenActions:yr,onDragStart:In})},e.id))}))]})}),z&&(0,J.jsx)(je,{anchor:z.anchor,items:Ar,onClose:()=>B(null),label:z.ids?`Document actions`:`Folder actions`,header:Fr}),(0,J.jsx)(Nr,{isOpen:dn,onClose:()=>fn(!1),documents:r,selectedDocuments:L}),(0,J.jsx)(Pr,{isOpen:G,onClose:()=>xn(!1),onImport:Hr}),Bt&&s&&(0,J.jsx)(nr,{modal:Ht,workspaceId:s,ids:Bt,onClose:()=>Vt(null)}),ht&&$e&&(0,J.jsx)(qn,{label:`Link to`,onClose:()=>gt(null),children:(0,J.jsx)(Le,{sizeClassName:`h-full w-full rounded-none border-0 bg-popover text-popover-foreground shadow-none`,documentCount:ht.length,fixedWorkspaceName:s,tabs:[`context`,`directory`,`relations`],saving:bt,relationExcludeIds:new Set(ht),onConfirm:(e,t)=>Sr(e,ht,t),onConfirmRelation:e=>xr(e,ht),onClose:()=>gt(null)})}),V&&s&&(0,Kn.createPortal)((0,J.jsx)(`div`,{className:`fixed inset-0 z-picker flex items-center justify-center bg-scrim p-4 max-md:p-2`,children:(0,J.jsx)(St,{workspaceId:s,documentCount:V.ids.length,initialMode:V.mode,defaultFilename:V.ids.length===1?We(r.find(e=>e.id===V.ids[0])??{}):``,saving:Dt,progress:kt,stopping:Mt,onStop:()=>{Ft.current=!0,Nt(!0)},deleteFrom:H?{backend:H.backend,folder:H.rel}:void 0,onConfirm:Cr,onClose:()=>{Dt||Et(null)}})}),window.document.body),Lt&&E&&(0,Kn.createPortal)((0,J.jsxs)(J.Fragment,{children:[(0,J.jsx)(`div`,{className:`fixed inset-0 z-picker-scrim bg-scrim animate-fade-in md:hidden`,onClick:()=>Rt(!1),"aria-hidden":!0}),(0,J.jsx)(`div`,{className:`fixed inset-y-0 right-0 z-picker flex items-stretch py-2 pr-2 max-md:bottom-2 max-md:left-2 max-md:top-2 max-md:py-0 max-md:pr-0 max-md:animate-fade-in`,children:(0,J.jsx)(Zt,{sizeClassName:`h-full w-[420px] max-w-full max-md:w-full max-md:shadow-elevation-5`,fixedWorkspaceName:s,onConfirm:async e=>{await E(a,e),Rt(!1)},onClose:()=>Rt(!1)})})]}),window.document.body),qt&&s&&(0,J.jsx)(Jn,{workspaceId:s,document:qt,onClose:()=>Jt(null)},`${s}:${qt.id}`),Wt&&s&&(0,J.jsx)(ar,{workspaceId:s,documentIds:Wt,onClose:()=>Gt(null)}),(0,J.jsx)(ur,{document:Xt?.document??null,isOpen:!!Xt,onClose:()=>U(null),workspaceId:s,initialEdit:Xt?.edit}),Xn&&s&&o&&nt&&(0,J.jsx)(jr,{x:Xn.x,y:Xn.y,workspaceName:s,treeName:o,path:Xn.path,onClose:()=>Zn(null),onOpen:nt,onOpenToSide:e=>window.dispatchEvent(new CustomEvent(`workspace:open-to-side`,{detail:{workspaceName:s,treeName:o,path:e}})),pastedDocumentIds:k,onPasteDocuments:E?(e,t)=>E(e,t):void 0})]})})}function ai(e){let t=window.document.createElement(`div`);window.document.body.appendChild(t);let n=(0,cr.createRoot)(t);n.render((0,J.jsx)(Pr,{isOpen:!0,onClose:()=>{n.unmount(),t.remove()},onImport:e}))}function oi(e){let t=window.document.createElement(`div`);window.document.body.appendChild(t);let n=(0,cr.createRoot)(t);n.render((0,J.jsx)(Nr,{isOpen:!0,onClose:()=>{n.unmount(),t.remove()},documents:e,selectedDocuments:new Set}))}export{gr as a,sr as c,Un as d,Ln as f,Cn as h,kr as i,ar as l,jn as m,Ar as n,fr as o,Pn as p,Or as r,ur as s,ii as t,qn as u};
@@ -1 +1 @@
1
- import{o as e}from"./rolldown-runtime-C0FnF6B9.js";import{l as t,u as n}from"./code-editor-BOIngd5F.js";import{Ot as r}from"./ui-Byg1cZDr.js";import{t as i}from"./button-SgR3GVvV.js";import{n as a}from"./use-toast-BlLDqSUO.js";import{n as o}from"./page-header-DkOHw0g-.js";import{t as s}from"./use-settings-back-CQauYjQ4.js";import{a as c,d as l,t as u}from"./inferd-config-editor--MDmN_7w.js";var d=e(n(),1),f=t();function p(){let{showToast:e}=a(),[t,n]=(0,d.useState)(null),[p,m]=(0,d.useState)(!0),[h,g]=(0,d.useState)(!1),[_,v]=(0,d.useState)(null),y=(0,d.useCallback)(()=>c().then(e=>{n(e),v(null)}).catch(e=>v(e instanceof Error?e.message:`Failed to load embedding defaults`)).finally(()=>m(!1)),[]);(0,d.useEffect)(()=>{y()},[y]);let b=()=>{m(!0),y()};return(0,f.jsxs)(`div`,{className:`mx-auto max-w-4xl p-6`,children:[(0,f.jsx)(o,{compact:!0,className:`mb-6`,title:`Search & AI defaults`,onBack:s(),description:`Your account · Choose the embedding models used for text and image search. Workspace settings override these defaults. Running workspaces adopt new defaults when restarted.`,actions:(0,f.jsxs)(i,{type:`button`,size:`sm`,variant:`outline`,onClick:b,disabled:p,children:[(0,f.jsx)(r,{className:`mr-2 h-3.5 w-3.5`}),`Refresh`]})}),p?(0,f.jsxs)(`div`,{className:`flex items-center gap-2 text-sm text-muted-foreground`,children:[(0,f.jsx)(r,{className:`h-4 w-4 animate-spin`}),`Loading…`]}):_||!t?(0,f.jsxs)(`div`,{className:`space-y-3`,children:[(0,f.jsxs)(`div`,{className:`rounded-md border border-destructive/40 bg-destructive/5 p-4 text-sm`,children:[(0,f.jsx)(`p`,{className:`font-medium text-destructive`,children:`Embedding defaults unavailable`}),(0,f.jsx)(`p`,{className:`mt-1 text-xs text-muted-foreground`,children:_||`No config returned.`})]}),(0,f.jsx)(i,{type:`button`,size:`sm`,variant:`outline`,onClick:b,children:`Retry`})]}):(0,f.jsx)(u,{value:t.user||{},effective:t.effective||{},inherited:t.serverDefaults||{},invalid:t.invalid,saving:h,saveLabel:`Save defaults`,onSave:async t=>{g(!0);try{let n=await l(t);e({title:`Defaults saved`,description:n.restartRequired?`${n.workspaces.length} running workspace(s) keep their current tables until restarted. Set the config on a workspace directly to change it live.`:`New workspaces will inherit this.`}),await y()}catch(t){e({title:`Save failed`,description:t instanceof Error?t.message:`Failed to save`,variant:`destructive`})}finally{g(!1)}}},JSON.stringify(t.user))]})}export{p as default};
1
+ import{o as e}from"./rolldown-runtime-C0FnF6B9.js";import{l as t,u as n}from"./code-editor-BOIngd5F.js";import{kt as r}from"./ui-76Hw0NU_.js";import{t as i}from"./button-Bum-POPT.js";import{n as a}from"./use-toast-BlLDqSUO.js";import{n as o}from"./page-header-BoCaZiqu.js";import{t as s}from"./use-settings-back-DE0SPb7h.js";import{a as c,d as l,t as u}from"./inferd-config-editor-CyDCQJRs.js";var d=e(n(),1),f=t();function p(){let{showToast:e}=a(),[t,n]=(0,d.useState)(null),[p,m]=(0,d.useState)(!0),[h,g]=(0,d.useState)(!1),[_,v]=(0,d.useState)(null),y=(0,d.useCallback)(()=>c().then(e=>{n(e),v(null)}).catch(e=>v(e instanceof Error?e.message:`Failed to load embedding defaults`)).finally(()=>m(!1)),[]);(0,d.useEffect)(()=>{y()},[y]);let b=()=>{m(!0),y()};return(0,f.jsxs)(`div`,{className:`mx-auto max-w-4xl p-6`,children:[(0,f.jsx)(o,{compact:!0,className:`mb-6`,title:`Search & AI defaults`,onBack:s(),description:`Your account · Choose the embedding models used for text and image search. Workspace settings override these defaults. Running workspaces adopt new defaults when restarted.`,actions:(0,f.jsxs)(i,{type:`button`,size:`sm`,variant:`outline`,onClick:b,disabled:p,children:[(0,f.jsx)(r,{className:`mr-2 h-3.5 w-3.5`}),`Refresh`]})}),p?(0,f.jsxs)(`div`,{className:`flex items-center gap-2 text-sm text-muted-foreground`,children:[(0,f.jsx)(r,{className:`h-4 w-4 animate-spin`}),`Loading…`]}):_||!t?(0,f.jsxs)(`div`,{className:`space-y-3`,children:[(0,f.jsxs)(`div`,{className:`rounded-md border border-destructive/40 bg-destructive/5 p-4 text-sm`,children:[(0,f.jsx)(`p`,{className:`font-medium text-destructive`,children:`Embedding defaults unavailable`}),(0,f.jsx)(`p`,{className:`mt-1 text-xs text-muted-foreground`,children:_||`No config returned.`})]}),(0,f.jsx)(i,{type:`button`,size:`sm`,variant:`outline`,onClick:b,children:`Retry`})]}):(0,f.jsx)(u,{value:t.user||{},effective:t.effective||{},inherited:t.serverDefaults||{},invalid:t.invalid,saving:h,saveLabel:`Save defaults`,onSave:async t=>{g(!0);try{let n=await l(t);e({title:`Defaults saved`,description:n.restartRequired?`${n.workspaces.length} running workspace(s) keep their current tables until restarted. Set the config on a workspace directly to change it live.`:`New workspaces will inherit this.`}),await y()}catch(t){e({title:`Save failed`,description:t instanceof Error?t.message:`Failed to save`,variant:`destructive`})}finally{g(!1)}}},JSON.stringify(t.user))]})}export{p as default};
@@ -1 +1 @@
1
- import{o as e}from"./rolldown-runtime-C0FnF6B9.js";import{l as t,u as n}from"./code-editor-BOIngd5F.js";import{Ot as r,pt as i}from"./ui-Byg1cZDr.js";import{t as a}from"./button-SgR3GVvV.js";import{t as o}from"./input-BOtCd4HP.js";import{i as s}from"./auth-Bx9fAZmz.js";import{n as c}from"./use-toast-BlLDqSUO.js";import{n as l}from"./page-header-DkOHw0g-.js";import{t as u}from"./use-settings-back-CQauYjQ4.js";import{i as d,t as f,u as p}from"./inferd-config-editor--MDmN_7w.js";var m=e(n(),1),h=t();function g(){let e=u(),{showToast:t}=c(),[n,g]=(0,m.useState)(null),[_,v]=(0,m.useState)(!0),[y,b]=(0,m.useState)(!1),[x,S]=(0,m.useState)(null),[C,w]=(0,m.useState)(``),T=s()?.userType===`admin`,E=(0,m.useCallback)(()=>d().then(e=>{g(e),w((e.allowHosts||[]).join(`, `)),S(null)}).catch(e=>S(e instanceof Error?e.message:`Failed to load server defaults`)).finally(()=>v(!1)),[]);(0,m.useEffect)(()=>{E()},[E]);let D=()=>{v(!0),E()};return(0,h.jsxs)(`div`,{className:`mx-auto max-w-4xl p-6`,children:[(0,h.jsx)(l,{onBack:e,compact:!0,className:`mb-6`,title:`Server search & AI defaults`,description:`Entire server · Set the embedding defaults accounts inherit. Account and workspace overrides take priority. Running workspaces adopt new defaults when restarted.`,actions:(0,h.jsxs)(a,{type:`button`,size:`sm`,variant:`outline`,onClick:D,disabled:_,children:[(0,h.jsx)(r,{className:`mr-2 h-3.5 w-3.5`}),`Refresh`]})}),!T&&(0,h.jsxs)(`div`,{className:`mb-4 flex items-start gap-2 rounded-md border p-3 text-xs`,children:[(0,h.jsx)(i,{className:`mt-0.5 h-4 w-4 shrink-0 text-muted-foreground`}),(0,h.jsx)(`p`,{className:`text-muted-foreground`,children:`Read-only. Changing server defaults requires an admin account. This is what your workspaces inherit.`})]}),_?(0,h.jsxs)(`div`,{className:`flex items-center gap-2 text-sm text-muted-foreground`,children:[(0,h.jsx)(r,{className:`h-4 w-4 animate-spin`}),`Loading…`]}):x||!n?(0,h.jsxs)(`div`,{className:`space-y-3`,children:[(0,h.jsxs)(`div`,{className:`rounded-md border border-destructive/40 bg-destructive/5 p-4 text-sm`,children:[(0,h.jsx)(`p`,{className:`font-medium text-destructive`,children:`Server defaults unavailable`}),(0,h.jsx)(`p`,{className:`mt-1 text-xs text-muted-foreground`,children:x||`No config returned.`})]}),(0,h.jsx)(a,{type:`button`,size:`sm`,variant:`outline`,onClick:D,children:`Retry`})]}):(0,h.jsxs)(`div`,{className:`space-y-4`,children:[(0,h.jsxs)(`p`,{className:`text-[11px] text-muted-foreground`,children:[`Config file: `,(0,h.jsx)(`span`,{className:`font-mono`,children:n.configPath})]}),(0,h.jsxs)(`section`,{className:`rounded-lg border p-4`,children:[(0,h.jsx)(`h3`,{className:`text-sm font-semibold`,children:`Endpoint allowlist`}),(0,h.jsx)(`p`,{className:`mb-2 mt-1 text-[11px] text-muted-foreground`,children:`Provider URLs are fetched by the server, so they are an SSRF surface. Link-local and cloud-metadata targets are always refused; list additional hosts here to permit them. Comma-separated, empty = only the always-blocked ranges apply.`}),(0,h.jsx)(o,{value:C,disabled:!T,onChange:e=>w(e.target.value),placeholder:`gpu.internal, embeddings.example.com`,className:`h-8 text-sm`})]}),(0,h.jsx)(f,{value:n.serverDefaults||{},effective:n.serverDefaults||{},inherited:{},saving:y,disabled:!T,saveLabel:`Save server defaults`,onSave:async e=>{b(!0);try{let n=C.split(`,`).map(e=>e.trim()).filter(Boolean),r=await p({...e,...n.length?{allowHosts:n}:{}});t({title:`Server defaults saved`,description:`Written to ${r.configPath}. Every user inherits these, so running workspaces keep their current tables until restarted.`}),await E()}catch(e){t({title:`Save failed`,description:e instanceof Error?e.message:`Failed to save`,variant:`destructive`})}finally{b(!1)}}},JSON.stringify(n.serverDefaults))]})]})}export{g as default};
1
+ import{o as e}from"./rolldown-runtime-C0FnF6B9.js";import{l as t,u as n}from"./code-editor-BOIngd5F.js";import{kt as r,pt as i}from"./ui-76Hw0NU_.js";import{t as a}from"./button-Bum-POPT.js";import{t as o}from"./input-BOtCd4HP.js";import{i as s}from"./auth-Bx9fAZmz.js";import{n as c}from"./use-toast-BlLDqSUO.js";import{n as l}from"./page-header-BoCaZiqu.js";import{t as u}from"./use-settings-back-DE0SPb7h.js";import{i as d,t as f,u as p}from"./inferd-config-editor-CyDCQJRs.js";var m=e(n(),1),h=t();function g(){let e=u(),{showToast:t}=c(),[n,g]=(0,m.useState)(null),[_,v]=(0,m.useState)(!0),[y,b]=(0,m.useState)(!1),[x,S]=(0,m.useState)(null),[C,w]=(0,m.useState)(``),T=s()?.userType===`admin`,E=(0,m.useCallback)(()=>d().then(e=>{g(e),w((e.allowHosts||[]).join(`, `)),S(null)}).catch(e=>S(e instanceof Error?e.message:`Failed to load server defaults`)).finally(()=>v(!1)),[]);(0,m.useEffect)(()=>{E()},[E]);let D=()=>{v(!0),E()};return(0,h.jsxs)(`div`,{className:`mx-auto max-w-4xl p-6`,children:[(0,h.jsx)(l,{onBack:e,compact:!0,className:`mb-6`,title:`Server search & AI defaults`,description:`Entire server · Set the embedding defaults accounts inherit. Account and workspace overrides take priority. Running workspaces adopt new defaults when restarted.`,actions:(0,h.jsxs)(a,{type:`button`,size:`sm`,variant:`outline`,onClick:D,disabled:_,children:[(0,h.jsx)(r,{className:`mr-2 h-3.5 w-3.5`}),`Refresh`]})}),!T&&(0,h.jsxs)(`div`,{className:`mb-4 flex items-start gap-2 rounded-md border p-3 text-xs`,children:[(0,h.jsx)(i,{className:`mt-0.5 h-4 w-4 shrink-0 text-muted-foreground`}),(0,h.jsx)(`p`,{className:`text-muted-foreground`,children:`Read-only. Changing server defaults requires an admin account. This is what your workspaces inherit.`})]}),_?(0,h.jsxs)(`div`,{className:`flex items-center gap-2 text-sm text-muted-foreground`,children:[(0,h.jsx)(r,{className:`h-4 w-4 animate-spin`}),`Loading…`]}):x||!n?(0,h.jsxs)(`div`,{className:`space-y-3`,children:[(0,h.jsxs)(`div`,{className:`rounded-md border border-destructive/40 bg-destructive/5 p-4 text-sm`,children:[(0,h.jsx)(`p`,{className:`font-medium text-destructive`,children:`Server defaults unavailable`}),(0,h.jsx)(`p`,{className:`mt-1 text-xs text-muted-foreground`,children:x||`No config returned.`})]}),(0,h.jsx)(a,{type:`button`,size:`sm`,variant:`outline`,onClick:D,children:`Retry`})]}):(0,h.jsxs)(`div`,{className:`space-y-4`,children:[(0,h.jsxs)(`p`,{className:`text-[11px] text-muted-foreground`,children:[`Config file: `,(0,h.jsx)(`span`,{className:`font-mono`,children:n.configPath})]}),(0,h.jsxs)(`section`,{className:`rounded-lg border p-4`,children:[(0,h.jsx)(`h3`,{className:`text-sm font-semibold`,children:`Endpoint allowlist`}),(0,h.jsx)(`p`,{className:`mb-2 mt-1 text-[11px] text-muted-foreground`,children:`Provider URLs are fetched by the server, so they are an SSRF surface. Link-local and cloud-metadata targets are always refused; list additional hosts here to permit them. Comma-separated, empty = only the always-blocked ranges apply.`}),(0,h.jsx)(o,{value:C,disabled:!T,onChange:e=>w(e.target.value),placeholder:`gpu.internal, embeddings.example.com`,className:`h-8 text-sm`})]}),(0,h.jsx)(f,{value:n.serverDefaults||{},effective:n.serverDefaults||{},inherited:{},saving:y,disabled:!T,saveLabel:`Save server defaults`,onSave:async e=>{b(!0);try{let n=C.split(`,`).map(e=>e.trim()).filter(Boolean),r=await p({...e,...n.length?{allowHosts:n}:{}});t({title:`Server defaults saved`,description:`Written to ${r.configPath}. Every user inherits these, so running workspaces keep their current tables until restarted.`}),await E()}catch(e){t({title:`Save failed`,description:e instanceof Error?e.message:`Failed to save`,variant:`destructive`})}finally{b(!1)}}},JSON.stringify(n.serverDefaults))]})]})}export{g as default};
@@ -1 +1 @@
1
- import{l as e}from"./code-editor-BOIngd5F.js";import{L as t}from"./ui-Byg1cZDr.js";var n=e();function r({title:e,onClose:r,children:i}){return(0,n.jsxs)(`div`,{className:`space-y-4 rounded-(--card-radius) border bg-card p-4 shadow-elevation-1`,children:[(0,n.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,n.jsx)(`h2`,{className:`text-xl font-semibold`,children:e}),(0,n.jsx)(`button`,{type:`button`,onClick:r,"aria-label":`Close`,className:`rounded p-1.5 text-muted-foreground transition-colors hover:bg-muted hover:text-foreground touch-target`,children:(0,n.jsx)(t,{className:`h-4 w-4`})})]}),i]})}export{r as t};
1
+ import{l as e}from"./code-editor-BOIngd5F.js";import{L as t}from"./ui-76Hw0NU_.js";var n=e();function r({title:e,onClose:r,children:i}){return(0,n.jsxs)(`div`,{className:`space-y-4 rounded-(--card-radius) border bg-card p-4 shadow-elevation-1`,children:[(0,n.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,n.jsx)(`h2`,{className:`text-xl font-semibold`,children:e}),(0,n.jsx)(`button`,{type:`button`,onClick:r,"aria-label":`Close`,className:`rounded p-1.5 text-muted-foreground transition-colors hover:bg-muted hover:text-foreground touch-target`,children:(0,n.jsx)(t,{className:`h-4 w-4`})})]}),i]})}export{r as t};
@@ -1 +1 @@
1
- import{o as e}from"./rolldown-runtime-C0FnF6B9.js";import{l as t,u as n}from"./code-editor-BOIngd5F.js";import{r}from"./chunk-62JRHF6Z-vspAGgtK.js";import{Lt as i,Vn as a,Xt as o,Zt as s,in as c,pr as l,yn as u}from"./ui-Byg1cZDr.js";import{H as d,ct as f}from"./workspace-CrSpR4xf.js";import{n as p,r as m}from"./use-canvas-pins-BvN6Gw6f.js";import{t as h}from"./useToastHelpers-CRrpIIdY.js";import{h as g}from"./index-BytAmMhU.js";import{t as _}from"./HomeFab-Chvwu8rQ.js";var v=e(n(),1),y=t();function b(e){let t=`${e.workspaceName}\0${e.treeName}\0${e.path}`,[n,r]=(0,v.useState)(null);return(0,v.useEffect)(()=>{let n=!1;return f(e.workspaceName,e.treeName).then(i=>{n||r({key:t,node:d(i,e.path)})}).catch(()=>{n||r({key:t,node:null})}),()=>{n=!0}},[t,e.workspaceName,e.treeName,e.path]),!n||n.key!==t?{state:`loading`}:n.node?{state:`ready`,node:n.node}:{state:`missing`}}function x(e){let t=`/workspaces/${encodeURIComponent(e.workspaceName)}`,n=e.path.replace(/^\//,``);return e.treeName===`context`?`${t}/path/${n}`:`${t}/trees/${encodeURIComponent(e.treeName)}/path/${n}`}var S=`application/x-canvas-pin`;function C({pin:e,onUnpin:t,onMinimize:n,onDropPin:d}){let f=b(e),[p,h]=(0,v.useState)(!1),[g,_]=(0,v.useState)(null),C=!!d&&!p,w=e=>{let t=e.currentTarget.getBoundingClientRect();return e.clientX>t.left+t.width/2?`after`:`before`},T=C?{onDragOver:e=>{e.dataTransfer.types.includes(`application/x-canvas-pin`)&&(e.preventDefault(),e.dataTransfer.dropEffect=`move`,_(w(e)))},onDragLeave:()=>_(null),onDrop:t=>{let n=t.dataTransfer.getData(S);_(null),!(!n||n===e.id)&&(t.preventDefault(),d?.(n,w(t)===`after`))}}:{},E=f.state===`ready`?f.node:null,D=E?.label||e.label||e.path.split(`/`).filter(Boolean).pop()||`Canvas`,O=E?.color;return(0,v.useEffect)(()=>{if(!p)return;let e=e=>{e.key===`Escape`&&h(!1)};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[p]),(0,y.jsxs)(`section`,{...T,className:p?`fixed inset-0 z-picker flex flex-col bg-background`:`flex flex-col rounded-(--card-radius) border bg-background overflow-hidden min-h-0 min-w-0 ${g?`ring-2 ring-primary/60`:``}`,children:[(0,y.jsxs)(`header`,{draggable:C,onDragStart:C?t=>{t.dataTransfer.setData(S,e.id),t.dataTransfer.effectAllowed=`move`}:void 0,className:`flex items-center gap-2 px-3 py-2 border-b bg-muted/20 shrink-0 min-w-0 ${C?`cursor-grab active:cursor-grabbing`:``}`,children:[C&&(0,y.jsx)(a,{className:`w-3.5 h-3.5 shrink-0 text-muted-foreground/60`,"aria-hidden":!0}),O&&(0,y.jsx)(`div`,{className:`w-1 h-5 rounded-full shrink-0`,style:{backgroundColor:O}}),(0,y.jsx)(u,{className:`w-4 h-4 shrink-0 text-primary`}),(0,y.jsxs)(`div`,{className:`flex flex-col min-w-0 flex-1`,children:[(0,y.jsx)(`span`,{className:`text-sm font-semibold leading-tight truncate`,children:D}),(0,y.jsxs)(`span`,{className:`text-[11px] text-muted-foreground truncate leading-tight font-mono`,children:[e.workspaceName,`://`,e.path.replace(/^\//,``)]})]}),n&&(0,y.jsx)(`button`,{type:`button`,onClick:n,title:`Minimize to tab bar`,"aria-label":`Minimize to tab bar`,className:`shrink-0 flex items-center justify-center w-7 h-7 rounded-md text-muted-foreground hover:bg-accent hover:text-foreground transition-colors`,children:(0,y.jsx)(o,{className:`w-3.5 h-3.5`})}),(0,y.jsx)(`button`,{type:`button`,onClick:()=>h(e=>!e),"aria-pressed":p,title:p?`Restore tile (Esc)`:`Fill view area`,"aria-label":p?`Restore tile`:`Fill view area`,className:`shrink-0 flex items-center justify-center w-7 h-7 rounded-md text-muted-foreground hover:bg-accent hover:text-foreground transition-colors`,children:p?(0,y.jsx)(s,{className:`w-3.5 h-3.5`}):(0,y.jsx)(c,{className:`w-3.5 h-3.5`})}),(0,y.jsx)(r,{to:x(e),title:`Open in workspace`,"aria-label":`Open in workspace`,className:`shrink-0 flex items-center justify-center w-7 h-7 rounded-md text-muted-foreground hover:bg-accent hover:text-foreground transition-colors`,children:(0,y.jsx)(l,{className:`w-3.5 h-3.5`})}),(0,y.jsx)(`button`,{type:`button`,onClick:t,title:`Unpin from home`,"aria-label":`Unpin from home`,className:`shrink-0 flex items-center justify-center w-7 h-7 rounded-md text-muted-foreground hover:bg-destructive/10 hover:text-destructive transition-colors`,children:(0,y.jsx)(i,{className:`w-3.5 h-3.5`})})]}),(0,y.jsxs)(`div`,{className:`flex-1 min-h-0`,children:[f.state===`loading`&&(0,y.jsx)(`div`,{className:`flex items-center justify-center h-full text-xs text-muted-foreground`,children:`Loading…`}),f.state===`missing`&&(0,y.jsxs)(`div`,{className:`flex flex-col items-center justify-center h-full gap-2 px-4 text-center`,children:[(0,y.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`This canvas is no longer available.`}),(0,y.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`It may have been renamed, moved or deleted.`}),(0,y.jsx)(`button`,{type:`button`,onClick:t,className:`mt-1 px-2.5 py-1 text-xs border rounded-md hover:bg-accent`,children:`Remove pin`})]}),f.state===`ready`&&(0,y.jsx)(m,{workspaceId:e.workspaceName,treeName:e.treeName,path:e.path,layerId:f.node.id,querySpec:f.node.querySpec,metadata:f.node.metadata,readOnly:!0})]})]})}function w(e){return e.label||e.path.split(`/`).filter(Boolean).pop()||`Canvas`}function T({pins:e,onRestore:t}){let[n,r]=(0,v.useState)(!1),[i,a]=(0,v.useState)(e.length);return i!==e.length&&(a(e.length),e.length===0&&r(!1)),e.length===0?null:(0,y.jsxs)(y.Fragment,{children:[(0,y.jsx)(`div`,{className:`pointer-events-none absolute bottom-0 left-0 right-0 z-40 max-md:hidden`,children:(0,y.jsx)(`div`,{className:`pointer-events-auto flex items-end gap-1 overflow-x-auto px-3 pr-28 pb-safe-bottom`,children:e.map(e=>(0,y.jsxs)(`button`,{type:`button`,onClick:()=>t(e.id),title:`Restore ${w(e)}`,className:`flex max-w-[180px] shrink-0 items-center gap-1.5 rounded-t-lg border border-b-0 bg-background px-3 py-1.5 text-xs shadow-elevation-1 hover:bg-accent`,children:[(0,y.jsx)(u,{className:`h-3.5 w-3.5 shrink-0 text-primary`}),(0,y.jsx)(`span`,{className:`truncate`,children:w(e)})]},e.id))})}),n&&(0,y.jsxs)(y.Fragment,{children:[(0,y.jsx)(`div`,{className:`fixed inset-0 z-drawer md:hidden`,onClick:()=>r(!1),"aria-hidden":!0}),(0,y.jsx)(`div`,{className:`fixed bottom-rail-stack left-2 z-rail w-60 max-w-[calc(100vw-1rem)] rounded-xl border bg-card p-1.5 shadow-elevation-5 animate-fade-in md:hidden touch-target`,children:e.map(e=>(0,y.jsxs)(`button`,{type:`button`,onClick:()=>t(e.id),className:`flex w-full items-center gap-2 rounded-lg px-2.5 py-2 text-left text-sm hover:bg-accent`,children:[(0,y.jsx)(u,{className:`h-4 w-4 shrink-0 text-primary`}),(0,y.jsx)(`span`,{className:`truncate`,children:w(e)})]},e.id))})]}),(0,y.jsxs)(`button`,{type:`button`,onClick:()=>r(e=>!e),"aria-label":n?`Close minimized canvases`:`Minimized canvases (${e.length})`,className:`fixed bottom-rail-inset left-16 z-nav flex h-12 w-12 items-center justify-center rounded-full bg-foreground text-background shadow-elevation-4 md:hidden`,children:[(0,y.jsx)(u,{className:`h-5 w-5`}),(0,y.jsx)(`span`,{className:`absolute -top-1 -right-1 flex h-5 min-w-5 items-center justify-center rounded-full bg-primary px-1 text-[10px] font-semibold`,children:e.length})]})]})}function E(){let{pins:e,unpin:t,movePin:n,setMinimized:r,isLoading:i}=p(),{showErrorToast:a}=h(),[o,s]=(0,v.useState)(new Set),c=(0,v.useRef)(e);(0,v.useEffect)(()=>{c.current=e},[e]);let l=e=>{r(e,!0).catch(()=>a(`Could not save minimized state`))},u=t=>{s(e=>{let n=new Set(e);return n.delete(t),n}),e.find(e=>e.id===t)?.minimized&&r(t,!1).catch(()=>a(`Could not save restored state`))},d=(0,v.useCallback)(e=>{s(e?new Set(c.current.filter(e=>!e.minimized).map(e=>e.id)):new Set)},[]),f=e.filter(e=>!g(e,o)),m=e.filter(e=>g(e,o)),b=(t,r,i)=>{let a=e.findIndex(e=>e.id===r.id);if(a===-1)return;let o=i?e[a+1]?.id??null:r.id;n(t,o)};return(0,y.jsxs)(`div`,{className:`relative h-full`,children:[(0,y.jsx)(`div`,{className:`h-full overflow-y-auto`,children:i?(0,y.jsx)(`div`,{className:`flex items-center justify-center h-full text-xs text-muted-foreground`,children:`Loading…`}):(0,y.jsx)(`div`,{className:`grid gap-4 p-4 h-full grid-cols-[repeat(auto-fit,minmax(min(640px,100%),1fr))] auto-rows-fr ${m.length>0?`md:pb-12`:``}`,children:f.map(e=>(0,y.jsx)(C,{pin:e,onUnpin:()=>{t(e.id)},onMinimize:()=>l(e.id),onDropPin:(t,n)=>b(t,e,n)},e.id))})}),(0,y.jsx)(`div`,{className:`pointer-events-none absolute inset-0`,children:(0,y.jsx)(_,{onCardsOpenChange:d})}),(0,y.jsx)(T,{pins:m,onRestore:u})]})}export{E as default};
1
+ import{o as e}from"./rolldown-runtime-C0FnF6B9.js";import{l as t,u as n}from"./code-editor-BOIngd5F.js";import{r}from"./chunk-62JRHF6Z-vspAGgtK.js";import{Hn as i,Qt as a,Rt as o,Zt as s,an as c,bn as l,mr as u}from"./ui-76Hw0NU_.js";import{H as d,ct as f}from"./workspace-BuoZwRL5.js";import{n as p,r as m}from"./use-canvas-pins-r3a-TbLQ.js";import{t as h}from"./useToastHelpers-CRrpIIdY.js";import{h as g}from"./index-QzZxj0Ty.js";import{t as _}from"./HomeFab-DG6YVz9N.js";var v=e(n(),1),y=t();function b(e){let t=`${e.workspaceName}\0${e.treeName}\0${e.path}`,[n,r]=(0,v.useState)(null);return(0,v.useEffect)(()=>{let n=!1;return f(e.workspaceName,e.treeName).then(i=>{n||r({key:t,node:d(i,e.path)})}).catch(()=>{n||r({key:t,node:null})}),()=>{n=!0}},[t,e.workspaceName,e.treeName,e.path]),!n||n.key!==t?{state:`loading`}:n.node?{state:`ready`,node:n.node}:{state:`missing`}}function x(e){let t=`/workspaces/${encodeURIComponent(e.workspaceName)}`,n=e.path.replace(/^\//,``);return e.treeName===`context`?`${t}/path/${n}`:`${t}/trees/${encodeURIComponent(e.treeName)}/path/${n}`}var S=`application/x-canvas-pin`;function C({pin:e,onUnpin:t,onMinimize:n,onDropPin:d}){let f=b(e),[p,h]=(0,v.useState)(!1),[g,_]=(0,v.useState)(null),C=!!d&&!p,w=e=>{let t=e.currentTarget.getBoundingClientRect();return e.clientX>t.left+t.width/2?`after`:`before`},T=C?{onDragOver:e=>{e.dataTransfer.types.includes(`application/x-canvas-pin`)&&(e.preventDefault(),e.dataTransfer.dropEffect=`move`,_(w(e)))},onDragLeave:()=>_(null),onDrop:t=>{let n=t.dataTransfer.getData(S);_(null),!(!n||n===e.id)&&(t.preventDefault(),d?.(n,w(t)===`after`))}}:{},E=f.state===`ready`?f.node:null,D=E?.label||e.label||e.path.split(`/`).filter(Boolean).pop()||`Canvas`,O=E?.color;return(0,v.useEffect)(()=>{if(!p)return;let e=e=>{e.key===`Escape`&&h(!1)};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[p]),(0,y.jsxs)(`section`,{...T,className:p?`fixed inset-0 z-picker flex flex-col bg-background`:`flex flex-col rounded-(--card-radius) border bg-background overflow-hidden min-h-0 min-w-0 ${g?`ring-2 ring-primary/60`:``}`,children:[(0,y.jsxs)(`header`,{draggable:C,onDragStart:C?t=>{t.dataTransfer.setData(S,e.id),t.dataTransfer.effectAllowed=`move`}:void 0,className:`flex items-center gap-2 px-3 py-2 border-b bg-muted/20 shrink-0 min-w-0 ${C?`cursor-grab active:cursor-grabbing`:``}`,children:[C&&(0,y.jsx)(i,{className:`w-3.5 h-3.5 shrink-0 text-muted-foreground/60`,"aria-hidden":!0}),O&&(0,y.jsx)(`div`,{className:`w-1 h-5 rounded-full shrink-0`,style:{backgroundColor:O}}),(0,y.jsx)(l,{className:`w-4 h-4 shrink-0 text-primary`}),(0,y.jsxs)(`div`,{className:`flex flex-col min-w-0 flex-1`,children:[(0,y.jsx)(`span`,{className:`text-sm font-semibold leading-tight truncate`,children:D}),(0,y.jsxs)(`span`,{className:`text-[11px] text-muted-foreground truncate leading-tight font-mono`,children:[e.workspaceName,`://`,e.path.replace(/^\//,``)]})]}),n&&(0,y.jsx)(`button`,{type:`button`,onClick:n,title:`Minimize to tab bar`,"aria-label":`Minimize to tab bar`,className:`shrink-0 flex items-center justify-center w-7 h-7 rounded-md text-muted-foreground hover:bg-accent hover:text-foreground transition-colors`,children:(0,y.jsx)(s,{className:`w-3.5 h-3.5`})}),(0,y.jsx)(`button`,{type:`button`,onClick:()=>h(e=>!e),"aria-pressed":p,title:p?`Restore tile (Esc)`:`Fill view area`,"aria-label":p?`Restore tile`:`Fill view area`,className:`shrink-0 flex items-center justify-center w-7 h-7 rounded-md text-muted-foreground hover:bg-accent hover:text-foreground transition-colors`,children:p?(0,y.jsx)(a,{className:`w-3.5 h-3.5`}):(0,y.jsx)(c,{className:`w-3.5 h-3.5`})}),(0,y.jsx)(r,{to:x(e),title:`Open in workspace`,"aria-label":`Open in workspace`,className:`shrink-0 flex items-center justify-center w-7 h-7 rounded-md text-muted-foreground hover:bg-accent hover:text-foreground transition-colors`,children:(0,y.jsx)(u,{className:`w-3.5 h-3.5`})}),(0,y.jsx)(`button`,{type:`button`,onClick:t,title:`Unpin from home`,"aria-label":`Unpin from home`,className:`shrink-0 flex items-center justify-center w-7 h-7 rounded-md text-muted-foreground hover:bg-destructive/10 hover:text-destructive transition-colors`,children:(0,y.jsx)(o,{className:`w-3.5 h-3.5`})})]}),(0,y.jsxs)(`div`,{className:`flex-1 min-h-0`,children:[f.state===`loading`&&(0,y.jsx)(`div`,{className:`flex items-center justify-center h-full text-xs text-muted-foreground`,children:`Loading…`}),f.state===`missing`&&(0,y.jsxs)(`div`,{className:`flex flex-col items-center justify-center h-full gap-2 px-4 text-center`,children:[(0,y.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`This canvas is no longer available.`}),(0,y.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`It may have been renamed, moved or deleted.`}),(0,y.jsx)(`button`,{type:`button`,onClick:t,className:`mt-1 px-2.5 py-1 text-xs border rounded-md hover:bg-accent`,children:`Remove pin`})]}),f.state===`ready`&&(0,y.jsx)(m,{workspaceId:e.workspaceName,treeName:e.treeName,path:e.path,layerId:f.node.id,querySpec:f.node.querySpec,metadata:f.node.metadata,readOnly:!0})]})]})}function w(e){return e.label||e.path.split(`/`).filter(Boolean).pop()||`Canvas`}function T({pins:e,onRestore:t}){let[n,r]=(0,v.useState)(!1),[i,a]=(0,v.useState)(e.length);return i!==e.length&&(a(e.length),e.length===0&&r(!1)),e.length===0?null:(0,y.jsxs)(y.Fragment,{children:[(0,y.jsx)(`div`,{className:`pointer-events-none absolute bottom-0 left-0 right-0 z-40 max-md:hidden`,children:(0,y.jsx)(`div`,{className:`pointer-events-auto flex items-end gap-1 overflow-x-auto px-3 pr-28 pb-safe-bottom`,children:e.map(e=>(0,y.jsxs)(`button`,{type:`button`,onClick:()=>t(e.id),title:`Restore ${w(e)}`,className:`flex max-w-[180px] shrink-0 items-center gap-1.5 rounded-t-lg border border-b-0 bg-background px-3 py-1.5 text-xs shadow-elevation-1 hover:bg-accent`,children:[(0,y.jsx)(l,{className:`h-3.5 w-3.5 shrink-0 text-primary`}),(0,y.jsx)(`span`,{className:`truncate`,children:w(e)})]},e.id))})}),n&&(0,y.jsxs)(y.Fragment,{children:[(0,y.jsx)(`div`,{className:`fixed inset-0 z-drawer md:hidden`,onClick:()=>r(!1),"aria-hidden":!0}),(0,y.jsx)(`div`,{className:`fixed bottom-rail-stack left-2 z-rail w-60 max-w-[calc(100vw-1rem)] rounded-xl border bg-card p-1.5 shadow-elevation-5 animate-fade-in md:hidden touch-target`,children:e.map(e=>(0,y.jsxs)(`button`,{type:`button`,onClick:()=>t(e.id),className:`flex w-full items-center gap-2 rounded-lg px-2.5 py-2 text-left text-sm hover:bg-accent`,children:[(0,y.jsx)(l,{className:`h-4 w-4 shrink-0 text-primary`}),(0,y.jsx)(`span`,{className:`truncate`,children:w(e)})]},e.id))})]}),(0,y.jsxs)(`button`,{type:`button`,onClick:()=>r(e=>!e),"aria-label":n?`Close minimized canvases`:`Minimized canvases (${e.length})`,className:`fixed bottom-rail-inset left-16 z-nav flex h-12 w-12 items-center justify-center rounded-full bg-foreground text-background shadow-elevation-4 md:hidden`,children:[(0,y.jsx)(l,{className:`h-5 w-5`}),(0,y.jsx)(`span`,{className:`absolute -top-1 -right-1 flex h-5 min-w-5 items-center justify-center rounded-full bg-primary px-1 text-[10px] font-semibold`,children:e.length})]})]})}function E(){let{pins:e,unpin:t,movePin:n,setMinimized:r,isLoading:i}=p(),{showErrorToast:a}=h(),[o,s]=(0,v.useState)(new Set),c=(0,v.useRef)(e);(0,v.useEffect)(()=>{c.current=e},[e]);let l=e=>{r(e,!0).catch(()=>a(`Could not save minimized state`))},u=t=>{s(e=>{let n=new Set(e);return n.delete(t),n}),e.find(e=>e.id===t)?.minimized&&r(t,!1).catch(()=>a(`Could not save restored state`))},d=(0,v.useCallback)(e=>{s(e?new Set(c.current.filter(e=>!e.minimized).map(e=>e.id)):new Set)},[]),f=e.filter(e=>!g(e,o)),m=e.filter(e=>g(e,o)),b=(t,r,i)=>{let a=e.findIndex(e=>e.id===r.id);if(a===-1)return;let o=i?e[a+1]?.id??null:r.id;n(t,o)};return(0,y.jsxs)(`div`,{className:`relative h-full`,children:[(0,y.jsx)(`div`,{className:`h-full overflow-y-auto`,children:i?(0,y.jsx)(`div`,{className:`flex items-center justify-center h-full text-xs text-muted-foreground`,children:`Loading…`}):(0,y.jsx)(`div`,{className:`grid gap-4 p-4 h-full grid-cols-[repeat(auto-fit,minmax(min(640px,100%),1fr))] auto-rows-fr ${m.length>0?`md:pb-12`:``}`,children:f.map(e=>(0,y.jsx)(C,{pin:e,onUnpin:()=>{t(e.id)},onMinimize:()=>l(e.id),onDropPin:(t,n)=>b(t,e,n)},e.id))})}),(0,y.jsx)(`div`,{className:`pointer-events-none absolute inset-0`,children:(0,y.jsx)(_,{onCardsOpenChange:d})}),(0,y.jsx)(T,{pins:m,onRestore:u})]})}export{E as default};