@augmentd-labs/canvas-web 2.26.39 → 2.26.40

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 (82) hide show
  1. package/dist/assets/CalendarApplet-Co0RKLQE.js +2 -0
  2. package/dist/assets/FileForm-CDiVKvxq.js +1 -0
  3. package/dist/assets/{FiltersApplet-CvdFlyn1.js → FiltersApplet-DMoH8Y2S.js} +1 -1
  4. package/dist/assets/{HomeFab-DRmbW2Uu.js → HomeFab-CpgkP2jx.js} +1 -1
  5. package/dist/assets/{IdentityFields-C7sv9pMk.js → IdentityFields-D-NCTUaE.js} +1 -1
  6. package/dist/assets/{LensApplet-gIiGSdLb.js → LensApplet-BRvNa6QA.js} +1 -1
  7. package/dist/assets/LinkToCard-CKVi4Nrg.js +1 -0
  8. package/dist/assets/{NextShell-DiyMsTp5.js → NextShell-ull6WmMg.js} +1 -1
  9. package/dist/assets/{NotesApplet-BUXkez68.js → NotesApplet-BUlo1AeT.js} +1 -1
  10. package/dist/assets/{ObjectPropertiesCard-pE3IL82x.js → ObjectPropertiesCard-D2lrTQqT.js} +4 -4
  11. package/dist/assets/{PathPickerField-D7SubxSh.js → PathPickerField-CW2yG2Yg.js} +1 -1
  12. package/dist/assets/{PickDocumentsCard-BhJbPlxk.js → PickDocumentsCard-BWgc-A02.js} +1 -1
  13. package/dist/assets/{SketchApplet-CQexRECa.js → SketchApplet-BKnhzTBA.js} +1 -1
  14. package/dist/assets/{SketchEditor-DxIN-6wI.js → SketchEditor-DmGMcbU0.js} +2 -2
  15. package/dist/assets/{TerminalApplet-D-F4-4Zt.js → TerminalApplet-D7YxftqM.js} +1 -1
  16. package/dist/assets/{TextDocumentEditor-YAeo69K7.js → TextDocumentEditor-BQnVD0dd.js} +1 -1
  17. package/dist/assets/{TodosApplet-OBi0XUdm.js → TodosApplet-DU5VWc5i.js} +1 -1
  18. package/dist/assets/{TodosWidget-B_R-vHxf.js → TodosWidget-CNnfNk4L.js} +1 -1
  19. package/dist/assets/{UploadProgressList-C9teR7r-.js → UploadProgressList-D2wEpa7t.js} +1 -1
  20. package/dist/assets/{_agentId_-CYfkXrJk.js → _agentId_-DpUGhD0N.js} +0 -0
  21. package/dist/assets/_contextId_-BYACtvKh.js +1 -0
  22. package/dist/assets/_workspaceName_-V027dHb_.js +1 -0
  23. package/dist/assets/{about-CCShKl-5.js → about-he3_XqHw.js} +1 -1
  24. package/dist/assets/{add-G2dEzOng.js → add-CPWQz9ZK.js} +1 -1
  25. package/dist/assets/{agents-vx49b2X5.js → agents-e-nclilT.js} +1 -1
  26. package/dist/assets/{appearance-Dmzr0s9n.js → appearance-De5ieWdQ.js} +1 -1
  27. package/dist/assets/{applet-target-DYrCD8BZ.js → applet-target-pLdP-R76.js} +1 -1
  28. package/dist/assets/{apps-B6DG6ZpO.js → apps-o8pk-feK.js} +1 -1
  29. package/dist/assets/backend-sync-progress-DqI8zbnK.js +6 -0
  30. package/dist/assets/{context-1vR30CeC.js → context-t3rdtGUB.js} +1 -1
  31. package/dist/assets/{contexts-DFYjIhsj2.js → contexts-Bq8LHUTK2.js} +1 -1
  32. package/dist/assets/{date-time-picker-C40sYmga.js → date-time-picker-DCikruos.js} +1 -1
  33. package/dist/assets/{document-BiNwuf1n.js → document-Cr7GhnVd.js} +1 -1
  34. package/dist/assets/document-list-J63eer10.js +3 -0
  35. package/dist/assets/{home-B1ilyR89.js → home-Cgt-SPAO.js} +1 -1
  36. package/dist/assets/{index-CXPA9Fj8.js → index-B01BkfMJ.js} +6 -6
  37. package/dist/assets/index-CYvpxvg6.css +2 -0
  38. package/dist/assets/{key-bindings-DXepopri.js → key-bindings-DbpenCz7.js} +1 -1
  39. package/dist/assets/{offline-DonGsRsw.js → offline-ByoT6JJX.js} +1 -1
  40. package/dist/assets/{public-share-DLXh7Ie6.js → public-share-CXR25Q1X.js} +1 -1
  41. package/dist/assets/query-debug-lD5vbJGi.js +1 -0
  42. package/dist/assets/{registry-eFbDXN9w.js → registry-CPdMkdKq.js} +2 -2
  43. package/dist/assets/{roles-DDiKiRii.js → roles-sb8vgjV_.js} +1 -1
  44. package/dist/assets/{settings-CwyGwKFU.js → settings-3y1P0NnU.js} +1 -1
  45. package/dist/assets/{settings-CgjGE01m.js → settings-B25sRmAM.js} +1 -1
  46. package/dist/assets/{settings-D-yPOLZk.js → settings-D1g-5DNT.js} +1 -1
  47. package/dist/assets/settings-DX6t8wLi.js +16 -0
  48. package/dist/assets/{share-target-BhGDitlj.js → share-target-DAjpH4Qw.js} +1 -1
  49. package/dist/assets/{shared-XYVtCrC8.js → shared-BLOuO2Is.js} +1 -1
  50. package/dist/assets/{shared-DimeKqW8.js → shared-BiquP0Yf.js} +1 -1
  51. package/dist/assets/{sketch-lazy-6eEi8GIA.js → sketch-lazy-BY_ka1hw.js} +2 -2
  52. package/dist/assets/{text-documents-DxVsu9zG.js → text-documents-Cdb3U63i.js} +2 -2
  53. package/dist/assets/tree-folders-BMqMmyq7.js +1 -0
  54. package/dist/assets/{use-applet-docs-FqhvvOWx.js → use-applet-docs-rimRHjID.js} +1 -1
  55. package/dist/assets/{use-applet-target-1DU4mgJH.js → use-applet-target-BygCSj5n.js} +1 -1
  56. package/dist/assets/use-canvas-pins-BV8AsYCE.js +3 -0
  57. package/dist/assets/{use-workspace-identity-KEG0VpcX.js → use-workspace-identity-CSkRwVyo.js} +1 -1
  58. package/dist/assets/{useAddTarget-BEgKjqGj.js → useAddTarget-DeRZWtGg.js} +1 -1
  59. package/dist/assets/{useAgentModels-CI7iZlUR.js → useAgentModels-KcfEQ6u9.js} +1 -1
  60. package/dist/assets/{useDocumentThumbnail-DutrNFK3.js → useDocumentThumbnail-Cj4UYyhC.js} +1 -1
  61. package/dist/assets/{useEditNoteFields-HAsbBak7.js → useEditNoteFields-BT1ASu_q.js} +1 -1
  62. package/dist/assets/{workspace-cv6Hrfhh.js → workspace-C5V-ZCOE.js} +1 -1
  63. package/dist/assets/{workspace-area-menu-CUqTxXmz.js → workspace-area-menu-Y2-IWSxU.js} +1 -1
  64. package/dist/assets/{workspace-content-gate-B6T3nLfW.js → workspace-content-gate-C54J9Man.js} +1 -1
  65. package/dist/assets/{workspace-import-form-D5qPcNFq.js → workspace-import-form-DTvV9jYt.js} +1 -1
  66. package/dist/assets/workspaces-CWqg_P7W.js +1 -0
  67. package/dist/index.html +26 -26
  68. package/dist/sw.js +1 -1
  69. package/package.json +2 -2
  70. package/dist/assets/CalendarApplet-DVUCGIPB.js +0 -2
  71. package/dist/assets/FileForm-CMuWZbUX.js +0 -1
  72. package/dist/assets/LinkToCard-DGpvNE_V.js +0 -1
  73. package/dist/assets/_contextId_-CkahAS5d.js +0 -1
  74. package/dist/assets/_workspaceName_--lNvJpY1.js +0 -1
  75. package/dist/assets/backend-sync-progress-m7wUKTJn.js +0 -7
  76. package/dist/assets/document-list-ASCemk7T.js +0 -2
  77. package/dist/assets/index-Bi5-zGgp.css +0 -2
  78. package/dist/assets/query-debug-DhboV3qX.js +0 -1
  79. package/dist/assets/settings-CcdxMKot.js +0 -16
  80. package/dist/assets/tree-folders-whK_PK4c.js +0 -1
  81. package/dist/assets/use-canvas-pins-DqkSe_aU.js +0 -3
  82. package/dist/assets/workspaces-yHyufXqs.js +0 -1
@@ -1,4 +1,4 @@
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,Pt as i}from"./ui-CDoK3F3U.js";import{n as a}from"./use-applet-target-1DU4mgJH.js";var o=e(n(),1),s=Object.defineProperty,c=Object.getOwnPropertyDescriptor,l=(e,t)=>{for(var n in t)s(e,n,{get:t[n],enumerable:!0})},u=(e,t,n,r)=>{for(var i=r>1?void 0:r?c(t,n):t,a=e.length-1,o;a>=0;a--)(o=e[a])&&(i=(r?o(t,n,i):o(i))||i);return r&&i&&s(t,n,i),i},d=(e,t)=>(n,r)=>t(n,r,e),f=`Terminal input`,p={get:()=>f,set:e=>f=e},m=`Too much output to announce, navigate to rows manually to read`,h={get:()=>m,set:e=>m=e};function g(e){return e.replace(/\r?\n/g,`\r`)}function _(e,t){return t?`\x1B[200~`+e+`\x1B[201~`:e}function v(e,t){e.clipboardData&&e.clipboardData.setData(`text/plain`,t.selectionText),e.preventDefault()}function ee(e,t,n,r){e.stopPropagation(),e.clipboardData&&te(e.clipboardData.getData(`text/plain`),t,n,r)}function te(e,t,n,r){e=g(e),e=_(e,n.decPrivateModes.bracketedPasteMode&&r.rawOptions.ignoreBracketedPasteMode!==!0),n.triggerDataEvent(e,!0),t.value=``}function ne(e,t,n){let r=n.getBoundingClientRect(),i=e.clientX-r.left-10,a=e.clientY-r.top-10;t.style.width=`20px`,t.style.height=`20px`,t.style.left=`${i}px`,t.style.top=`${a}px`,t.style.zIndex=`1000`,t.focus()}function re(e,t,n,r,i){ne(e,t,n),i&&r.rightClickSelect(e),t.value=r.selectionText,t.select()}function ie(e){return e>65535?(e-=65536,String.fromCharCode((e>>10)+55296)+String.fromCharCode(e%1024+56320)):String.fromCharCode(e)}function ae(e,t=0,n=e.length){let r=``;for(let i=t;i<n;++i){let t=e[i];t>65535?(t-=65536,r+=String.fromCharCode((t>>10)+55296)+String.fromCharCode(t%1024+56320)):r+=String.fromCharCode(t)}return r}var oe=class{constructor(){this._interim=0}clear(){this._interim=0}decode(e,t){let n=e.length;if(!n)return 0;let r=0,i=0;if(this._interim){let n=e.charCodeAt(i++);56320<=n&&n<=57343?t[r++]=(this._interim-55296)*1024+n-56320+65536:(t[r++]=this._interim,t[r++]=n),this._interim=0}for(let a=i;a<n;++a){let i=e.charCodeAt(a);if(55296<=i&&i<=56319){if(++a>=n)return this._interim=i,r;let o=e.charCodeAt(a);56320<=o&&o<=57343?t[r++]=(i-55296)*1024+o-56320+65536:(t[r++]=i,t[r++]=o);continue}i!==65279&&(t[r++]=i)}return r}},se=class{constructor(){this.interim=new Uint8Array(3)}clear(){this.interim.fill(0)}decode(e,t){let n=e.length;if(!n)return 0;let r=0,i,a,o,s,c=0,l=0;if(this.interim[0]){let i=!1,a=this.interim[0];a&=(a&224)==192?31:(a&240)==224?15:7;let o=0,s;for(;(s=this.interim[++o]&63)&&o<4;)a<<=6,a|=s;let c=(this.interim[0]&224)==192?2:(this.interim[0]&240)==224?3:4,u=c-o;for(;l<u;){if(l>=n)return 0;if(s=e[l++],(s&192)!=128){l--,i=!0;break}this.interim[o++]=s,a<<=6,a|=s&63}i||(c===2?a<128?l--:t[r++]=a:c===3?a<2048||a>=55296&&a<=57343||a===65279||(t[r++]=a):a<65536||a>1114111||(t[r++]=a)),this.interim.fill(0)}let u=n-4,d=l;for(;d<n;){for(;d<u&&!((i=e[d])&128)&&!((a=e[d+1])&128)&&!((o=e[d+2])&128)&&!((s=e[d+3])&128);)t[r++]=i,t[r++]=a,t[r++]=o,t[r++]=s,d+=4;if(i=e[d++],i<128)t[r++]=i;else if((i&224)==192){if(d>=n)return this.interim[0]=i,r;if(a=e[d++],(a&192)!=128){d--;continue}if(c=(i&31)<<6|a&63,c<128){d--;continue}t[r++]=c}else if((i&240)==224){if(d>=n)return this.interim[0]=i,r;if(a=e[d++],(a&192)!=128){d--;continue}if(d>=n)return this.interim[0]=i,this.interim[1]=a,r;if(o=e[d++],(o&192)!=128){d--;continue}if(c=(i&15)<<12|(a&63)<<6|o&63,c<2048||c>=55296&&c<=57343||c===65279)continue;t[r++]=c}else if((i&248)==240){if(d>=n)return this.interim[0]=i,r;if(a=e[d++],(a&192)!=128){d--;continue}if(d>=n)return this.interim[0]=i,this.interim[1]=a,r;if(o=e[d++],(o&192)!=128){d--;continue}if(d>=n)return this.interim[0]=i,this.interim[1]=a,this.interim[2]=o,r;if(s=e[d++],(s&192)!=128){d--;continue}if(c=(i&7)<<18|(a&63)<<12|(o&63)<<6|s&63,c<65536||c>1114111)continue;t[r++]=c}}return r}},y=``,ce=` `,le=class e{constructor(){this.fg=0,this.bg=0,this.extended=new ue}static toColorRGB(e){return[e>>>16&255,e>>>8&255,e&255]}static fromColorRGB(e){return(e[0]&255)<<16|(e[1]&255)<<8|e[2]&255}clone(){let t=new e;return t.fg=this.fg,t.bg=this.bg,t.extended=this.extended.clone(),t}isInverse(){return this.fg&67108864}isBold(){return this.fg&134217728}isUnderline(){return this.hasExtendedAttrs()&&this.extended.underlineStyle!==0?1:this.fg&268435456}isBlink(){return this.fg&536870912}isInvisible(){return this.fg&1073741824}isItalic(){return this.bg&67108864}isDim(){return this.bg&134217728}isStrikethrough(){return this.fg&2147483648}isProtected(){return this.bg&536870912}isOverline(){return this.bg&1073741824}getFgColorMode(){return this.fg&50331648}getBgColorMode(){return this.bg&50331648}isFgRGB(){return(this.fg&50331648)==50331648}isBgRGB(){return(this.bg&50331648)==50331648}isFgPalette(){return(this.fg&50331648)==16777216||(this.fg&50331648)==33554432}isBgPalette(){return(this.bg&50331648)==16777216||(this.bg&50331648)==33554432}isFgDefault(){return!(this.fg&50331648)}isBgDefault(){return!(this.bg&50331648)}isAttributeDefault(){return this.fg===0&&this.bg===0}getFgColor(){switch(this.fg&50331648){case 16777216:case 33554432:return this.fg&255;case 50331648:return this.fg&16777215;default:return-1}}getBgColor(){switch(this.bg&50331648){case 16777216:case 33554432:return this.bg&255;case 50331648:return this.bg&16777215;default:return-1}}hasExtendedAttrs(){return this.bg&268435456}updateExtended(){this.extended.isEmpty()?this.bg&=-268435457:this.bg|=268435456}getUnderlineColor(){if(this.bg&268435456&&~this.extended.underlineColor)switch(this.extended.underlineColor&50331648){case 16777216:case 33554432:return this.extended.underlineColor&255;case 50331648:return this.extended.underlineColor&16777215;default:return this.getFgColor()}return this.getFgColor()}getUnderlineColorMode(){return this.bg&268435456&&~this.extended.underlineColor?this.extended.underlineColor&50331648:this.getFgColorMode()}isUnderlineColorRGB(){return this.bg&268435456&&~this.extended.underlineColor?(this.extended.underlineColor&50331648)==50331648:this.isFgRGB()}isUnderlineColorPalette(){return this.bg&268435456&&~this.extended.underlineColor?(this.extended.underlineColor&50331648)==16777216||(this.extended.underlineColor&50331648)==33554432:this.isFgPalette()}isUnderlineColorDefault(){return this.bg&268435456&&~this.extended.underlineColor?!(this.extended.underlineColor&50331648):this.isFgDefault()}getUnderlineStyle(){return this.fg&268435456?this.bg&268435456?this.extended.underlineStyle:1:0}getUnderlineVariantOffset(){return this.extended.underlineVariantOffset}},ue=class e{constructor(e=0,t=0){this._ext=0,this._urlId=0,this._ext=e,this._urlId=t}get ext(){return this._urlId?this._ext&-469762049|this.underlineStyle<<26:this._ext}set ext(e){this._ext=e}get underlineStyle(){return this._urlId?5:(this._ext&469762048)>>26}set underlineStyle(e){this._ext&=-469762049,this._ext|=e<<26&469762048}get underlineColor(){return this._ext&67108863}set underlineColor(e){this._ext&=-67108864,this._ext|=e&67108863}get urlId(){return this._urlId}set urlId(e){this._urlId=e}get underlineVariantOffset(){let e=(this._ext&3758096384)>>29;return e<0?e^4294967288:e}set underlineVariantOffset(e){this._ext&=536870911,this._ext|=e<<29&3758096384}clone(){return new e(this._ext,this._urlId)}isEmpty(){return this.underlineStyle===0&&this._urlId===0}},b=class e extends le{constructor(){super(...arguments),this.content=0,this.fg=0,this.bg=0,this.extended=new ue,this.combinedData=``}static fromCharData(t){let n=new e;return n.setFromCharData(t),n}isCombined(){return this.content&2097152}getWidth(){return this.content>>22}getChars(){return this.content&2097152?this.combinedData:this.content&2097151?ie(this.content&2097151):``}getCode(){return this.isCombined()?this.combinedData.charCodeAt(this.combinedData.length-1):this.content&2097151}setFromCharData(e){this.fg=e[0],this.bg=0;let t=!1;if(e[1].length>2)t=!0;else if(e[1].length===2){let n=e[1].charCodeAt(0);if(55296<=n&&n<=56319){let r=e[1].charCodeAt(1);56320<=r&&r<=57343?this.content=(n-55296)*1024+r-56320+65536|e[2]<<22:t=!0}else t=!0}else this.content=e[1].charCodeAt(0)|e[2]<<22;t&&(this.combinedData=e[1],this.content=2097152|e[2]<<22)}getAsCharData(){return[this.fg,this.getChars(),this.getWidth(),this.getCode()]}},de=`di$target`,fe=`di$dependencies`,pe=new Map;function x(e){return e[fe]||[]}function S(e){if(pe.has(e))return pe.get(e);let t=function(e,n,r){if(arguments.length!==3)throw Error(`@IServiceName-decorator can only be used to decorate a parameter`);me(t,e,r)};return t._id=e,pe.set(e,t),t}function me(e,t,n){t[de]===t?t[fe].push({id:e,index:n}):(t[fe]=[{id:e,index:n}],t[de]=t)}var C=S(`BufferService`),he=S(`CoreMouseService`),ge=S(`CoreService`),w=S(`CharsetService`),_e=S(`InstantiationService`),ve=S(`LogService`),T=S(`OptionsService`),ye=S(`OscLinkService`),be=S(`UnicodeService`),xe=S(`DecorationService`),Se=class{constructor(e,t,n){this._bufferService=e,this._optionsService=t,this._oscLinkService=n}provideLinks(e,t){let n=this._bufferService.buffer.lines.get(e-1);if(!n){t(void 0);return}let r=[],i=this._optionsService.rawOptions.linkHandler,a=new b,o=n.getTrimmedLength(),s=-1,c=-1,l=!1;for(let t=0;t<o;t++)if(!(c===-1&&!n.hasContent(t))){if(n.loadCell(t,a),a.hasExtendedAttrs()&&a.extended.urlId){if(c===-1){c=t,s=a.extended.urlId;continue}l=a.extended.urlId!==s}else c!==-1&&(l=!0);if(l||c!==-1&&t===o-1){let n=this._oscLinkService.getLinkData(s)?.uri;if(n){let a={start:{x:c+1,y:e},end:{x:t+ +(!l&&t===o-1),y:e}},s=!1;if(!i?.allowNonHttpProtocols)try{let e=new URL(n);[`http:`,`https:`].includes(e.protocol)||(s=!0)}catch{s=!0}s||r.push({text:n,range:a,activate:(e,t)=>i?i.activate(e,t,a):Ce(e,t),hover:(e,t)=>i?.hover?.(e,t,a),leave:(e,t)=>i?.leave?.(e,t,a)})}l=!1,a.hasExtendedAttrs()&&a.extended.urlId?(c=t,s=a.extended.urlId):(c=-1,s=-1)}}t(r)}};Se=u([d(0,C),d(1,T),d(2,ye)],Se);function Ce(e,t){if(confirm(`Do you want to navigate to ${t}?
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,Pt as i}from"./ui-CDoK3F3U.js";import{n as a}from"./use-applet-target-BygCSj5n.js";var o=e(n(),1),s=Object.defineProperty,c=Object.getOwnPropertyDescriptor,l=(e,t)=>{for(var n in t)s(e,n,{get:t[n],enumerable:!0})},u=(e,t,n,r)=>{for(var i=r>1?void 0:r?c(t,n):t,a=e.length-1,o;a>=0;a--)(o=e[a])&&(i=(r?o(t,n,i):o(i))||i);return r&&i&&s(t,n,i),i},d=(e,t)=>(n,r)=>t(n,r,e),f=`Terminal input`,p={get:()=>f,set:e=>f=e},m=`Too much output to announce, navigate to rows manually to read`,h={get:()=>m,set:e=>m=e};function g(e){return e.replace(/\r?\n/g,`\r`)}function _(e,t){return t?`\x1B[200~`+e+`\x1B[201~`:e}function v(e,t){e.clipboardData&&e.clipboardData.setData(`text/plain`,t.selectionText),e.preventDefault()}function ee(e,t,n,r){e.stopPropagation(),e.clipboardData&&te(e.clipboardData.getData(`text/plain`),t,n,r)}function te(e,t,n,r){e=g(e),e=_(e,n.decPrivateModes.bracketedPasteMode&&r.rawOptions.ignoreBracketedPasteMode!==!0),n.triggerDataEvent(e,!0),t.value=``}function ne(e,t,n){let r=n.getBoundingClientRect(),i=e.clientX-r.left-10,a=e.clientY-r.top-10;t.style.width=`20px`,t.style.height=`20px`,t.style.left=`${i}px`,t.style.top=`${a}px`,t.style.zIndex=`1000`,t.focus()}function re(e,t,n,r,i){ne(e,t,n),i&&r.rightClickSelect(e),t.value=r.selectionText,t.select()}function ie(e){return e>65535?(e-=65536,String.fromCharCode((e>>10)+55296)+String.fromCharCode(e%1024+56320)):String.fromCharCode(e)}function ae(e,t=0,n=e.length){let r=``;for(let i=t;i<n;++i){let t=e[i];t>65535?(t-=65536,r+=String.fromCharCode((t>>10)+55296)+String.fromCharCode(t%1024+56320)):r+=String.fromCharCode(t)}return r}var oe=class{constructor(){this._interim=0}clear(){this._interim=0}decode(e,t){let n=e.length;if(!n)return 0;let r=0,i=0;if(this._interim){let n=e.charCodeAt(i++);56320<=n&&n<=57343?t[r++]=(this._interim-55296)*1024+n-56320+65536:(t[r++]=this._interim,t[r++]=n),this._interim=0}for(let a=i;a<n;++a){let i=e.charCodeAt(a);if(55296<=i&&i<=56319){if(++a>=n)return this._interim=i,r;let o=e.charCodeAt(a);56320<=o&&o<=57343?t[r++]=(i-55296)*1024+o-56320+65536:(t[r++]=i,t[r++]=o);continue}i!==65279&&(t[r++]=i)}return r}},se=class{constructor(){this.interim=new Uint8Array(3)}clear(){this.interim.fill(0)}decode(e,t){let n=e.length;if(!n)return 0;let r=0,i,a,o,s,c=0,l=0;if(this.interim[0]){let i=!1,a=this.interim[0];a&=(a&224)==192?31:(a&240)==224?15:7;let o=0,s;for(;(s=this.interim[++o]&63)&&o<4;)a<<=6,a|=s;let c=(this.interim[0]&224)==192?2:(this.interim[0]&240)==224?3:4,u=c-o;for(;l<u;){if(l>=n)return 0;if(s=e[l++],(s&192)!=128){l--,i=!0;break}this.interim[o++]=s,a<<=6,a|=s&63}i||(c===2?a<128?l--:t[r++]=a:c===3?a<2048||a>=55296&&a<=57343||a===65279||(t[r++]=a):a<65536||a>1114111||(t[r++]=a)),this.interim.fill(0)}let u=n-4,d=l;for(;d<n;){for(;d<u&&!((i=e[d])&128)&&!((a=e[d+1])&128)&&!((o=e[d+2])&128)&&!((s=e[d+3])&128);)t[r++]=i,t[r++]=a,t[r++]=o,t[r++]=s,d+=4;if(i=e[d++],i<128)t[r++]=i;else if((i&224)==192){if(d>=n)return this.interim[0]=i,r;if(a=e[d++],(a&192)!=128){d--;continue}if(c=(i&31)<<6|a&63,c<128){d--;continue}t[r++]=c}else if((i&240)==224){if(d>=n)return this.interim[0]=i,r;if(a=e[d++],(a&192)!=128){d--;continue}if(d>=n)return this.interim[0]=i,this.interim[1]=a,r;if(o=e[d++],(o&192)!=128){d--;continue}if(c=(i&15)<<12|(a&63)<<6|o&63,c<2048||c>=55296&&c<=57343||c===65279)continue;t[r++]=c}else if((i&248)==240){if(d>=n)return this.interim[0]=i,r;if(a=e[d++],(a&192)!=128){d--;continue}if(d>=n)return this.interim[0]=i,this.interim[1]=a,r;if(o=e[d++],(o&192)!=128){d--;continue}if(d>=n)return this.interim[0]=i,this.interim[1]=a,this.interim[2]=o,r;if(s=e[d++],(s&192)!=128){d--;continue}if(c=(i&7)<<18|(a&63)<<12|(o&63)<<6|s&63,c<65536||c>1114111)continue;t[r++]=c}}return r}},y=``,ce=` `,le=class e{constructor(){this.fg=0,this.bg=0,this.extended=new ue}static toColorRGB(e){return[e>>>16&255,e>>>8&255,e&255]}static fromColorRGB(e){return(e[0]&255)<<16|(e[1]&255)<<8|e[2]&255}clone(){let t=new e;return t.fg=this.fg,t.bg=this.bg,t.extended=this.extended.clone(),t}isInverse(){return this.fg&67108864}isBold(){return this.fg&134217728}isUnderline(){return this.hasExtendedAttrs()&&this.extended.underlineStyle!==0?1:this.fg&268435456}isBlink(){return this.fg&536870912}isInvisible(){return this.fg&1073741824}isItalic(){return this.bg&67108864}isDim(){return this.bg&134217728}isStrikethrough(){return this.fg&2147483648}isProtected(){return this.bg&536870912}isOverline(){return this.bg&1073741824}getFgColorMode(){return this.fg&50331648}getBgColorMode(){return this.bg&50331648}isFgRGB(){return(this.fg&50331648)==50331648}isBgRGB(){return(this.bg&50331648)==50331648}isFgPalette(){return(this.fg&50331648)==16777216||(this.fg&50331648)==33554432}isBgPalette(){return(this.bg&50331648)==16777216||(this.bg&50331648)==33554432}isFgDefault(){return!(this.fg&50331648)}isBgDefault(){return!(this.bg&50331648)}isAttributeDefault(){return this.fg===0&&this.bg===0}getFgColor(){switch(this.fg&50331648){case 16777216:case 33554432:return this.fg&255;case 50331648:return this.fg&16777215;default:return-1}}getBgColor(){switch(this.bg&50331648){case 16777216:case 33554432:return this.bg&255;case 50331648:return this.bg&16777215;default:return-1}}hasExtendedAttrs(){return this.bg&268435456}updateExtended(){this.extended.isEmpty()?this.bg&=-268435457:this.bg|=268435456}getUnderlineColor(){if(this.bg&268435456&&~this.extended.underlineColor)switch(this.extended.underlineColor&50331648){case 16777216:case 33554432:return this.extended.underlineColor&255;case 50331648:return this.extended.underlineColor&16777215;default:return this.getFgColor()}return this.getFgColor()}getUnderlineColorMode(){return this.bg&268435456&&~this.extended.underlineColor?this.extended.underlineColor&50331648:this.getFgColorMode()}isUnderlineColorRGB(){return this.bg&268435456&&~this.extended.underlineColor?(this.extended.underlineColor&50331648)==50331648:this.isFgRGB()}isUnderlineColorPalette(){return this.bg&268435456&&~this.extended.underlineColor?(this.extended.underlineColor&50331648)==16777216||(this.extended.underlineColor&50331648)==33554432:this.isFgPalette()}isUnderlineColorDefault(){return this.bg&268435456&&~this.extended.underlineColor?!(this.extended.underlineColor&50331648):this.isFgDefault()}getUnderlineStyle(){return this.fg&268435456?this.bg&268435456?this.extended.underlineStyle:1:0}getUnderlineVariantOffset(){return this.extended.underlineVariantOffset}},ue=class e{constructor(e=0,t=0){this._ext=0,this._urlId=0,this._ext=e,this._urlId=t}get ext(){return this._urlId?this._ext&-469762049|this.underlineStyle<<26:this._ext}set ext(e){this._ext=e}get underlineStyle(){return this._urlId?5:(this._ext&469762048)>>26}set underlineStyle(e){this._ext&=-469762049,this._ext|=e<<26&469762048}get underlineColor(){return this._ext&67108863}set underlineColor(e){this._ext&=-67108864,this._ext|=e&67108863}get urlId(){return this._urlId}set urlId(e){this._urlId=e}get underlineVariantOffset(){let e=(this._ext&3758096384)>>29;return e<0?e^4294967288:e}set underlineVariantOffset(e){this._ext&=536870911,this._ext|=e<<29&3758096384}clone(){return new e(this._ext,this._urlId)}isEmpty(){return this.underlineStyle===0&&this._urlId===0}},b=class e extends le{constructor(){super(...arguments),this.content=0,this.fg=0,this.bg=0,this.extended=new ue,this.combinedData=``}static fromCharData(t){let n=new e;return n.setFromCharData(t),n}isCombined(){return this.content&2097152}getWidth(){return this.content>>22}getChars(){return this.content&2097152?this.combinedData:this.content&2097151?ie(this.content&2097151):``}getCode(){return this.isCombined()?this.combinedData.charCodeAt(this.combinedData.length-1):this.content&2097151}setFromCharData(e){this.fg=e[0],this.bg=0;let t=!1;if(e[1].length>2)t=!0;else if(e[1].length===2){let n=e[1].charCodeAt(0);if(55296<=n&&n<=56319){let r=e[1].charCodeAt(1);56320<=r&&r<=57343?this.content=(n-55296)*1024+r-56320+65536|e[2]<<22:t=!0}else t=!0}else this.content=e[1].charCodeAt(0)|e[2]<<22;t&&(this.combinedData=e[1],this.content=2097152|e[2]<<22)}getAsCharData(){return[this.fg,this.getChars(),this.getWidth(),this.getCode()]}},de=`di$target`,fe=`di$dependencies`,pe=new Map;function x(e){return e[fe]||[]}function S(e){if(pe.has(e))return pe.get(e);let t=function(e,n,r){if(arguments.length!==3)throw Error(`@IServiceName-decorator can only be used to decorate a parameter`);me(t,e,r)};return t._id=e,pe.set(e,t),t}function me(e,t,n){t[de]===t?t[fe].push({id:e,index:n}):(t[fe]=[{id:e,index:n}],t[de]=t)}var C=S(`BufferService`),he=S(`CoreMouseService`),ge=S(`CoreService`),w=S(`CharsetService`),_e=S(`InstantiationService`),ve=S(`LogService`),T=S(`OptionsService`),ye=S(`OscLinkService`),be=S(`UnicodeService`),xe=S(`DecorationService`),Se=class{constructor(e,t,n){this._bufferService=e,this._optionsService=t,this._oscLinkService=n}provideLinks(e,t){let n=this._bufferService.buffer.lines.get(e-1);if(!n){t(void 0);return}let r=[],i=this._optionsService.rawOptions.linkHandler,a=new b,o=n.getTrimmedLength(),s=-1,c=-1,l=!1;for(let t=0;t<o;t++)if(!(c===-1&&!n.hasContent(t))){if(n.loadCell(t,a),a.hasExtendedAttrs()&&a.extended.urlId){if(c===-1){c=t,s=a.extended.urlId;continue}l=a.extended.urlId!==s}else c!==-1&&(l=!0);if(l||c!==-1&&t===o-1){let n=this._oscLinkService.getLinkData(s)?.uri;if(n){let a={start:{x:c+1,y:e},end:{x:t+ +(!l&&t===o-1),y:e}},s=!1;if(!i?.allowNonHttpProtocols)try{let e=new URL(n);[`http:`,`https:`].includes(e.protocol)||(s=!0)}catch{s=!0}s||r.push({text:n,range:a,activate:(e,t)=>i?i.activate(e,t,a):Ce(e,t),hover:(e,t)=>i?.hover?.(e,t,a),leave:(e,t)=>i?.leave?.(e,t,a)})}l=!1,a.hasExtendedAttrs()&&a.extended.urlId?(c=t,s=a.extended.urlId):(c=-1,s=-1)}}t(r)}};Se=u([d(0,C),d(1,T),d(2,ye)],Se);function Ce(e,t){if(confirm(`Do you want to navigate to ${t}?
2
2
 
3
3
  WARNING: This link could potentially be dangerous`)){let e=window.open();if(e){try{e.opener=null}catch{}e.location.href=t}else console.warn(`Opening link blocked as opener could not be cleared`)}}var we=S(`CharSizeService`),Te=S(`CoreBrowserService`),Ee=S(`MouseService`),De=S(`RenderService`),Oe=S(`SelectionService`),ke=S(`CharacterJoinerService`),Ae=S(`ThemeService`),je=S(`LinkProviderService`),Me=new class{constructor(){this.listeners=[],this.unexpectedErrorHandler=function(e){setTimeout(()=>{throw e.stack?Re.isErrorNoTelemetry(e)?new Re(e.message+`
4
4
 
@@ -1 +1 @@
1
- import{o as e}from"./rolldown-runtime-C0FnF6B9.js";import{l as t,u as n}from"./code-editor-BOIngd5F.js";import{Ct as r}from"./ui-CDoK3F3U.js";import{t as i}from"./button-SeUZ_Pvi.js";import{Bn as a,Mn as o}from"./workspace-cv6Hrfhh.js";import{a as s,i as c,n as l,o as u,r as d,t as f}from"./text-documents-DxVsu9zG.js";import{t as p}from"./useToastHelpers-CRrpIIdY.js";import{t as m}from"./note-save-status-DPz4VzL6.js";import{t as h}from"./useEditNoteFields-HAsbBak7.js";import{t as g}from"./DocumentBodyEditor-CVO5KPCs.js";import{t as _}from"./EditorOverlay-D5t3xg4w.js";var v=e(n(),1),y=t();function b({doc:e,workspaceName:t,onSaved:n,onClose:b,onDetails:x}){let{showSuccessToast:S,showErrorToast:C}=p(),w=e.schema===a,T=c(e),E=T&&s(e),D=d(e)??`markdown`,O=u(t,e.id,{mode:`text`,enabled:T&&!E,maxTextLength:l,version:e.checksumArray?.[0]??null}),[k,A]=(0,v.useState)(w?String(e.data?.content??``):``),j=h(e,t,w),M=w?j.content:k,N=w?j.setContent:A,[P,F]=(0,v.useState)(null),I=`${e.id}:${e.checksumArray?.[0]??``}`;T&&O.text!=null&&P!==I&&(F(I),N(O.text));let[L,R]=(0,v.useState)(!1),z=w||O.text!=null&&!O.loading,B=async()=>{R(!0);try{let r;w?await j.save():r=await f(t,e,M),S(`Document saved`),window.dispatchEvent(new CustomEvent(`workspace:documents:refresh`)),n(r)}catch(e){C(e instanceof Error?e.message:`Failed to save document`)}finally{R(!1)}},V=w?String(e.data?.title??`Note`):o(e)||`document-${e.id}`;return(0,y.jsx)(_,{onClose:b,onDetails:x,title:(0,y.jsx)(`span`,{className:`truncate text-sm font-medium`,children:V}),actions:(0,y.jsxs)(y.Fragment,{children:[w&&(0,y.jsx)(m,{...j,onRetry:j.save}),(0,y.jsxs)(i,{size:`sm`,onClick:B,disabled:L||!z||E,children:[(0,y.jsx)(r,{className:`mr-1.5 h-4 w-4`}),L?`Saving…`:`Save`]})]}),children:(0,y.jsx)(`div`,{className:`flex h-full min-h-0 flex-col px-4 py-4 md:px-8`,children:(0,y.jsx)(`div`,{className:`mx-auto flex min-h-0 w-full max-w-full flex-1 flex-col overflow-auto md:w-[700px] md:min-w-[320px] md:resize-x`,children:E?(0,y.jsxs)(`p`,{className:`text-sm text-muted-foreground`,children:[`This file is too large to edit here (`,`>`,Math.round(l/1e3),` kB) — download it instead.`]}):O.error?(0,y.jsx)(`p`,{className:`text-sm text-destructive`,children:O.error}):z?(0,y.jsx)(g,{kind:w?`markdown`:D,value:M,onChange:N,placeholder:w?`Write your note…`:void 0,fill:!0}):(0,y.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`Loading content…`})})})})}export{b as default};
1
+ import{o as e}from"./rolldown-runtime-C0FnF6B9.js";import{l as t,u as n}from"./code-editor-BOIngd5F.js";import{Ct as r}from"./ui-CDoK3F3U.js";import{t as i}from"./button-SeUZ_Pvi.js";import{Ln as a,kn as o}from"./workspace-C5V-ZCOE.js";import{a as s,i as c,n as l,o as u,r as d,t as f}from"./text-documents-Cdb3U63i.js";import{t as p}from"./useToastHelpers-CRrpIIdY.js";import{t as m}from"./note-save-status-DPz4VzL6.js";import{t as h}from"./useEditNoteFields-BT1ASu_q.js";import{t as g}from"./DocumentBodyEditor-CVO5KPCs.js";import{t as _}from"./EditorOverlay-D5t3xg4w.js";var v=e(n(),1),y=t();function b({doc:e,workspaceName:t,onSaved:n,onClose:b,onDetails:x}){let{showSuccessToast:S,showErrorToast:C}=p(),w=e.schema===a,T=c(e),E=T&&s(e),D=d(e)??`markdown`,O=u(t,e.id,{mode:`text`,enabled:T&&!E,maxTextLength:l,version:e.checksumArray?.[0]??null}),[k,A]=(0,v.useState)(w?String(e.data?.content??``):``),j=h(e,t,w),M=w?j.content:k,N=w?j.setContent:A,[P,F]=(0,v.useState)(null),I=`${e.id}:${e.checksumArray?.[0]??``}`;T&&O.text!=null&&P!==I&&(F(I),N(O.text));let[L,R]=(0,v.useState)(!1),z=w||O.text!=null&&!O.loading,B=async()=>{R(!0);try{let r;w?await j.save():r=await f(t,e,M),S(`Document saved`),window.dispatchEvent(new CustomEvent(`workspace:documents:refresh`)),n(r)}catch(e){C(e instanceof Error?e.message:`Failed to save document`)}finally{R(!1)}},V=w?String(e.data?.title??`Note`):o(e)||`document-${e.id}`;return(0,y.jsx)(_,{onClose:b,onDetails:x,title:(0,y.jsx)(`span`,{className:`truncate text-sm font-medium`,children:V}),actions:(0,y.jsxs)(y.Fragment,{children:[w&&(0,y.jsx)(m,{...j,onRetry:j.save}),(0,y.jsxs)(i,{size:`sm`,onClick:B,disabled:L||!z||E,children:[(0,y.jsx)(r,{className:`mr-1.5 h-4 w-4`}),L?`Saving…`:`Save`]})]}),children:(0,y.jsx)(`div`,{className:`flex h-full min-h-0 flex-col px-4 py-4 md:px-8`,children:(0,y.jsx)(`div`,{className:`mx-auto flex min-h-0 w-full max-w-full flex-1 flex-col overflow-auto md:w-[700px] md:min-w-[320px] md:resize-x`,children:E?(0,y.jsxs)(`p`,{className:`text-sm text-muted-foreground`,children:[`This file is too large to edit here (`,`>`,Math.round(l/1e3),` kB) — download it instead.`]}):O.error?(0,y.jsx)(`p`,{className:`text-sm text-destructive`,children:O.error}):z?(0,y.jsx)(g,{kind:w?`markdown`:D,value:M,onChange:N,placeholder:w?`Write your note…`:void 0,fill:!0}):(0,y.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`Loading content…`})})})})}export{b 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{Fr as r,L as i,Pt as a,Wr as o,fr as s,hi as c,jr as l,li as u,pn as d,pr as f,yt as p}from"./ui-CDoK3F3U.js";import{t as m}from"./utils-2pl1SbIp.js";import{Hn as h,vn as g,wn as _}from"./workspace-cv6Hrfhh.js";import{o as v,t as y}from"./useAddTarget-BEgKjqGj.js";import{a as b,c as x,i as S,n as C,o as w,s as T}from"./date-time-picker-C40sYmga.js";import{n as E}from"./use-applet-target-1DU4mgJH.js";import{n as D,r as O,t as k}from"./shared-XYVtCrC8.js";import{n as A,r as j,t as M}from"./use-applet-docs-FqhvvOWx.js";var N=e(n(),1),P=t(),F=`2.1`,I=new Set([`completed`,`cancelled`]);function L({doc:e,updateWorkspace:t,registerEl:n,registerBody:i,highlighted:a,onLinkTo:s,onDelete:c,onStatusSaved:u}){let[f,p]=(0,N.useState)(String(e.data?.title??``)),[h,v]=(0,N.useState)(String(e.data?.description??``)),[y,b]=(0,N.useState)(e.data?.status||`pending`),[x,E]=(0,N.useState)(w(e.data?.dueDate)),[O,j]=(0,N.useState)(`idle`),{replicating:F,label:L}=_(e),R=(0,N.useRef)({title:String(e.data?.title??``),description:String(e.data?.description??``)}),z=(0,N.useRef)(null),B=(0,N.useRef)(0),V=(0,N.useCallback)(async n=>{if(!t||!n.title.trim())return!1;let r=++B.current;j(`saving`);try{let i=T(n.due),a={...e.data||{},title:n.title.trim(),...n.description.trim()?{description:n.description.trim()}:{description:void 0},status:n.status,completed:n.status===`completed`};return i?a.dueDate=i:delete a.dueDate,await g(t,{id:e.id,schema:e.schema,schemaVersion:e.schemaVersion,data:a,metadata:e.metadata}),r!==B.current||(R.current={title:n.title,description:n.description},j(`saved`),setTimeout(()=>j(e=>e===`saved`?`idle`:e),1500),!0)}catch{return r===B.current&&j(`error`),!1}},[e.id,e.schema,e.schemaVersion,e.data,e.metadata,t]),H=(0,N.useCallback)((e,t)=>{(e!==R.current.title||t!==R.current.description)&&(j(`dirty`),z.current&&clearTimeout(z.current),z.current=setTimeout(()=>V({title:e,description:t,status:y,due:x}),M))},[V,y,x]),U=(0,N.useCallback)(()=>{z.current&&=(clearTimeout(z.current),null),V({title:f,description:h,status:y,due:x})},[V,f,h,y,x]);(0,N.useEffect)(()=>()=>{z.current&&clearTimeout(z.current)},[]);let W=(0,N.useCallback)(async()=>{let t=y,n=y===`completed`?`pending`:`completed`;b(n),await V({title:f,description:h,status:n,due:x})?u(e.id,n):b(t)},[y,V,f,h,x,e.id,u]),G=(0,N.useCallback)(e=>{E(e),z.current&&=(clearTimeout(z.current),null),V({title:f,description:h,status:y,due:e})},[V,f,h,y]),K=I.has(y);return(0,P.jsxs)(`div`,{ref:t=>n(e.id,t),className:m(`group border-t border-border/60 px-4 py-3 transition-colors`,a&&`bg-primary/5`),children:[(0,P.jsxs)(`div`,{className:`mb-1 flex items-baseline justify-between gap-2`,children:[(0,P.jsxs)(`span`,{className:`flex min-w-0 items-center gap-1.5 text-[10px] uppercase tracking-wide text-muted-foreground/70`,children:[(0,P.jsxs)(`span`,{className:`shrink-0`,children:[A(e.createdAt),` · #`,e.id,y!==`pending`&&(0,P.jsxs)(`span`,{children:[` · `,S[y]??y]})]}),(0,P.jsx)(C,{value:x,onChange:G,compact:!0,placeholder:`No due date`,className:`w-[168px] shrink-0 normal-case tracking-normal`})]}),(0,P.jsxs)(`span`,{className:`flex items-center gap-1 text-[10px] text-muted-foreground/70`,children:[O===`saving`&&(0,P.jsx)(d,{className:`inline h-3 w-3 animate-spin`}),F&&(0,P.jsx)(`span`,{className:`whitespace-nowrap`,children:L}),O===`saved`&&(0,P.jsx)(o,{className:`inline h-3 w-3 text-success`}),O===`dirty`&&`·`,O===`error`&&(0,P.jsx)(`span`,{className:`text-destructive`,children:`save failed`}),(0,P.jsx)(D,{onLinkTo:s,onDelete:c})]})]}),(0,P.jsxs)(`div`,{className:`flex items-start gap-2`,children:[(0,P.jsx)(`button`,{type:`button`,onClick:W,className:`mt-0.5 shrink-0 text-muted-foreground transition-colors hover:text-foreground`,"aria-label":K?`Mark as pending`:`Mark as completed`,title:K?`Mark as pending`:`Mark as completed`,children:K?(0,P.jsx)(r,{className:`h-4 w-4 text-success`}):(0,P.jsx)(l,{className:`h-4 w-4`})}),(0,P.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,P.jsx)(`input`,{value:f,onChange:e=>{p(e.target.value),H(e.target.value,h)},onBlur:U,placeholder:`Untitled`,spellCheck:!1,className:m(`mb-1 w-full border-0 bg-transparent p-0 text-sm font-semibold outline-none placeholder:text-muted-foreground/50`,K?`text-muted-foreground line-through`:`text-foreground`)}),(0,P.jsx)(k,{value:h,onChange:e=>{v(e),H(f,e)},onBlur:U,placeholder:`Description…`,innerRef:t=>i(e.id,t)})]})]})]})}function R({target:e,onCreated:t,onCancel:n}){let[r,a]=(0,N.useState)(``),[o,s]=(0,N.useState)(``),[c,l]=(0,N.useState)(x()),[u,d]=(0,N.useState)(!1),[f,p]=(0,N.useState)(null);return(0,P.jsxs)(`div`,{className:`border-t border-border/60 bg-muted/30 px-4 py-3`,children:[(0,P.jsxs)(`div`,{className:`mb-1 flex items-baseline justify-between`,children:[(0,P.jsx)(`span`,{className:`text-[10px] uppercase tracking-wide text-muted-foreground/70`,children:`New todo`}),(0,P.jsx)(`button`,{type:`button`,onClick:n,className:`text-muted-foreground hover:text-foreground`,"aria-label":`Discard draft`,children:(0,P.jsx)(i,{className:`h-3 w-3`})})]}),(0,P.jsx)(`input`,{value:r,onChange:e=>a(e.target.value),placeholder:`What needs doing?`,autoFocus:!0,spellCheck:!1,className:`mb-1 w-full border-0 bg-transparent p-0 text-sm font-semibold text-foreground outline-none placeholder:text-muted-foreground/50`}),(0,P.jsx)(k,{value:o,onChange:s,placeholder:`Description (optional)…`}),(0,P.jsx)(`div`,{className:`mt-2`,children:(0,P.jsx)(C,{value:c,onChange:l,compact:!0,placeholder:`No due date`,className:`w-[188px]`})}),f&&(0,P.jsx)(`p`,{className:`mt-1 text-xs text-destructive`,children:f}),(0,P.jsx)(`div`,{className:`mt-2 flex justify-end`,children:(0,P.jsx)(`button`,{type:`button`,onClick:async()=>{if(!(!r.trim()||!e||u)){d(!0),p(null);try{await v(e,[{schema:h,schemaVersion:F,data:b({title:r,description:o,status:`pending`,priority:``,due:c}),metadata:{features:[]}}]),t()}catch(e){p(e instanceof Error?e.message:`Failed to create todo`),d(!1)}}},disabled:!r.trim()||u,className:`rounded-md bg-primary px-2.5 py-1 text-xs text-primary-foreground disabled:opacity-50`,children:u?`Saving…`:`Save todo`})})]})}function z({autoAdd:e=!1}){let t=E(),{docs:n,setDocs:r,loading:i,error:o,scope:l,reload:g,removeDoc:_}=j(t,h),[v,b]=(0,N.useState)(``),[x,S]=(0,N.useState)(0),[C,w]=(0,N.useState)(`desc`),[T,D]=(0,N.useState)(!1),[k,A]=(0,N.useState)(e),[M,F]=(0,N.useState)(null),z=(0,N.useRef)(new Map),B=(0,N.useRef)(new Map),V=(0,N.useCallback)((e,t)=>{t?z.current.set(e,t):z.current.delete(e)},[]),H=(0,N.useCallback)((e,t)=>{t?B.current.set(e,t):B.current.delete(e)},[]),U=(0,N.useCallback)(async e=>{let t=e.data?.title?`"${e.data.title}"`:`#${e.id}`;if(window.confirm(`Delete todo ${t}?\n\nIt is removed from this path and moves to the workspace trash if nothing else links it.`))try{await _(e.id)}catch{}},[_]),W=(0,N.useCallback)((e,t)=>{r(n=>n.map(n=>n.id===e?{...n,data:{...n.data||{},status:t,completed:t===`completed`}}:n))},[r]),G=(0,N.useMemo)(()=>{let e=T?[...n]:n.filter(e=>!I.has(String(e.data?.status??`pending`)));return e.sort((e,t)=>{let n=new Date(e.createdAt).getTime()-new Date(t.createdAt).getTime();return C===`asc`?n:-n}),e},[n,C,T]),K=(0,N.useMemo)(()=>n.filter(e=>I.has(String(e.data?.status??`pending`))).length,[n]),q=(0,N.useMemo)(()=>{let e=v.trim().toLowerCase();if(!e)return[];let t=[];for(let n of G){let r=String(n.data?.description??``),i=String(n.data?.title??``),a=r.toLowerCase().indexOf(e);a>=0?t.push({docId:n.id,offset:a}):i.toLowerCase().includes(e)&&t.push({docId:n.id,offset:-1})}return t},[v,G]),J=q.length?q[Math.min(x,q.length-1)]:null;(0,N.useEffect)(()=>{J&&z.current.get(J.docId)?.scrollIntoView({block:`center`,behavior:`smooth`})},[J]);let Y=(0,N.useCallback)(e=>{if(!q.length)return;let t=e?(x+1)%q.length:x;e&&S(t);let n=q[t],r=B.current.get(n.docId);r&&n.offset>=0&&(r.focus(),r.setSelectionRange(n.offset,n.offset+v.trim().length)),z.current.get(n.docId)?.scrollIntoView({block:`center`,behavior:`smooth`})},[q,x,v]);return t?(0,P.jsxs)(`div`,{className:`flex h-full flex-col`,children:[(0,P.jsxs)(`div`,{className:`flex shrink-0 items-center gap-2 border-b border-border px-3 py-2`,children:[(0,P.jsxs)(`div`,{className:`relative flex-1`,children:[(0,P.jsx)(p,{className:`pointer-events-none absolute left-2 top-1/2 h-3.5 w-3.5 -translate-y-1/2 text-muted-foreground`}),(0,P.jsx)(`input`,{value:v,onChange:e=>{b(e.target.value),S(0)},onKeyDown:e=>{e.key===`Enter`&&(e.preventDefault(),Y(!0))},placeholder:`Search todos…`,spellCheck:!1,className:`w-full rounded-md border border-input bg-transparent py-1 pl-7 pr-14 text-xs outline-none placeholder:text-muted-foreground focus-visible:ring-1 focus-visible:ring-ring`}),v.trim()&&(0,P.jsx)(`span`,{className:`absolute right-2 top-1/2 -translate-y-1/2 text-[10px] tabular-nums text-muted-foreground`,children:q.length?`${Math.min(x+1,q.length)}/${q.length}`:`0/0`})]}),(0,P.jsx)(`button`,{type:`button`,onClick:()=>D(e=>!e),className:m(`rounded-md border p-1.5 transition-colors`,T?`border-foreground text-foreground`:`border-border text-muted-foreground hover:bg-muted hover:text-foreground`),title:T?`Hide done items`:`Show done items${K?` (${K})`:``}`,"aria-label":T?`Hide done items`:`Show done items`,children:T?(0,P.jsx)(s,{className:`h-3.5 w-3.5`}):(0,P.jsx)(f,{className:`h-3.5 w-3.5`})}),(0,P.jsx)(`button`,{type:`button`,onClick:()=>w(e=>e===`desc`?`asc`:`desc`),className:`rounded-md border border-border p-1.5 text-muted-foreground transition-colors hover:bg-muted hover:text-foreground`,title:C===`desc`?`Newest first (click for oldest first)`:`Oldest first (click for newest first)`,"aria-label":`Toggle sort order`,children:C===`desc`?(0,P.jsx)(c,{className:`h-3.5 w-3.5`}):(0,P.jsx)(u,{className:`h-3.5 w-3.5`})}),(0,P.jsxs)(`button`,{type:`button`,onClick:()=>A(!0),className:`flex items-center gap-1 rounded-md bg-primary px-2 py-1.5 text-xs text-primary-foreground`,title:`Add a todo`,children:[(0,P.jsx)(a,{className:`h-3.5 w-3.5`}),`Todo`]})]}),(0,P.jsxs)(`div`,{className:`min-h-0 flex-1 overflow-y-auto`,children:[k&&(0,P.jsx)(R,{target:t,onCreated:()=>{A(!1),g()},onCancel:()=>A(!1)}),i&&!n.length&&(0,P.jsx)(`div`,{className:`flex items-center justify-center py-10`,children:(0,P.jsx)(d,{className:`h-5 w-5 animate-spin text-muted-foreground`})}),o&&(0,P.jsx)(`p`,{className:`px-4 py-6 text-center text-sm text-destructive`,children:o}),!i&&!o&&!G.length&&!k&&(0,P.jsx)(`p`,{className:`px-4 py-10 text-center text-sm text-muted-foreground`,children:K?`Nothing pending - ${K} done item${K>1?`s`:``} hidden.`:`No todos here yet - add the first one.`}),G.map(e=>(0,P.jsx)(L,{doc:e,updateWorkspace:l?.workspaceName??null,registerEl:V,registerBody:H,highlighted:J?.docId===e.id,onLinkTo:()=>F(e.id),onDelete:()=>U(e),onStatusSaved:W},e.id))]}),M!==null&&(0,P.jsx)(O,{documentId:M,workspaceName:l?.workspaceName,onClose:()=>F(null)})]}):(0,P.jsx)(`div`,{className:`flex h-full items-center justify-center p-6 text-center text-sm text-muted-foreground`,children:y(t)})}export{z as TodosApplet};
1
+ import{o as e}from"./rolldown-runtime-C0FnF6B9.js";import{l as t,u as n}from"./code-editor-BOIngd5F.js";import{Fr as r,L as i,Pt as a,Wr as o,fr as s,hi as c,jr as l,li as u,pn as d,pr as f,yt as p}from"./ui-CDoK3F3U.js";import{t as m}from"./utils-2pl1SbIp.js";import{hn as h,xn as g,zn as _}from"./workspace-C5V-ZCOE.js";import{o as v,t as y}from"./useAddTarget-DeRZWtGg.js";import{a as b,c as x,i as S,n as C,o as w,s as T}from"./date-time-picker-DCikruos.js";import{n as E}from"./use-applet-target-BygCSj5n.js";import{n as D,r as O,t as k}from"./shared-BLOuO2Is.js";import{n as A,r as j,t as M}from"./use-applet-docs-rimRHjID.js";var N=e(n(),1),P=t(),F=`2.1`,I=new Set([`completed`,`cancelled`]);function L({doc:e,updateWorkspace:t,registerEl:n,registerBody:i,highlighted:a,onLinkTo:s,onDelete:c,onStatusSaved:u}){let[f,p]=(0,N.useState)(String(e.data?.title??``)),[_,v]=(0,N.useState)(String(e.data?.description??``)),[y,b]=(0,N.useState)(e.data?.status||`pending`),[x,E]=(0,N.useState)(w(e.data?.dueDate)),[O,j]=(0,N.useState)(`idle`),{replicating:F,label:L}=g(e),R=(0,N.useRef)({title:String(e.data?.title??``),description:String(e.data?.description??``)}),z=(0,N.useRef)(null),B=(0,N.useRef)(0),V=(0,N.useCallback)(async n=>{if(!t||!n.title.trim())return!1;let r=++B.current;j(`saving`);try{let i=T(n.due),a={...e.data||{},title:n.title.trim(),...n.description.trim()?{description:n.description.trim()}:{description:void 0},status:n.status,completed:n.status===`completed`};return i?a.dueDate=i:delete a.dueDate,await h(t,{id:e.id,schema:e.schema,schemaVersion:e.schemaVersion,data:a,metadata:e.metadata}),r!==B.current||(R.current={title:n.title,description:n.description},j(`saved`),setTimeout(()=>j(e=>e===`saved`?`idle`:e),1500),!0)}catch{return r===B.current&&j(`error`),!1}},[e.id,e.schema,e.schemaVersion,e.data,e.metadata,t]),H=(0,N.useCallback)((e,t)=>{(e!==R.current.title||t!==R.current.description)&&(j(`dirty`),z.current&&clearTimeout(z.current),z.current=setTimeout(()=>V({title:e,description:t,status:y,due:x}),M))},[V,y,x]),U=(0,N.useCallback)(()=>{z.current&&=(clearTimeout(z.current),null),V({title:f,description:_,status:y,due:x})},[V,f,_,y,x]);(0,N.useEffect)(()=>()=>{z.current&&clearTimeout(z.current)},[]);let W=(0,N.useCallback)(async()=>{let t=y,n=y===`completed`?`pending`:`completed`;b(n),await V({title:f,description:_,status:n,due:x})?u(e.id,n):b(t)},[y,V,f,_,x,e.id,u]),G=(0,N.useCallback)(e=>{E(e),z.current&&=(clearTimeout(z.current),null),V({title:f,description:_,status:y,due:e})},[V,f,_,y]),K=I.has(y);return(0,P.jsxs)(`div`,{ref:t=>n(e.id,t),className:m(`group border-t border-border/60 px-4 py-3 transition-colors`,a&&`bg-primary/5`),children:[(0,P.jsxs)(`div`,{className:`mb-1 flex items-baseline justify-between gap-2`,children:[(0,P.jsxs)(`span`,{className:`flex min-w-0 items-center gap-1.5 text-[10px] uppercase tracking-wide text-muted-foreground/70`,children:[(0,P.jsxs)(`span`,{className:`shrink-0`,children:[A(e.createdAt),` · #`,e.id,y!==`pending`&&(0,P.jsxs)(`span`,{children:[` · `,S[y]??y]})]}),(0,P.jsx)(C,{value:x,onChange:G,compact:!0,placeholder:`No due date`,className:`w-[168px] shrink-0 normal-case tracking-normal`})]}),(0,P.jsxs)(`span`,{className:`flex items-center gap-1 text-[10px] text-muted-foreground/70`,children:[O===`saving`&&(0,P.jsx)(d,{className:`inline h-3 w-3 animate-spin`}),F&&(0,P.jsx)(`span`,{className:`whitespace-nowrap`,children:L}),O===`saved`&&(0,P.jsx)(o,{className:`inline h-3 w-3 text-success`}),O===`dirty`&&`·`,O===`error`&&(0,P.jsx)(`span`,{className:`text-destructive`,children:`save failed`}),(0,P.jsx)(D,{onLinkTo:s,onDelete:c})]})]}),(0,P.jsxs)(`div`,{className:`flex items-start gap-2`,children:[(0,P.jsx)(`button`,{type:`button`,onClick:W,className:`mt-0.5 shrink-0 text-muted-foreground transition-colors hover:text-foreground`,"aria-label":K?`Mark as pending`:`Mark as completed`,title:K?`Mark as pending`:`Mark as completed`,children:K?(0,P.jsx)(r,{className:`h-4 w-4 text-success`}):(0,P.jsx)(l,{className:`h-4 w-4`})}),(0,P.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,P.jsx)(`input`,{value:f,onChange:e=>{p(e.target.value),H(e.target.value,_)},onBlur:U,placeholder:`Untitled`,spellCheck:!1,className:m(`mb-1 w-full border-0 bg-transparent p-0 text-sm font-semibold outline-none placeholder:text-muted-foreground/50`,K?`text-muted-foreground line-through`:`text-foreground`)}),(0,P.jsx)(k,{value:_,onChange:e=>{v(e),H(f,e)},onBlur:U,placeholder:`Description…`,innerRef:t=>i(e.id,t)})]})]})]})}function R({target:e,onCreated:t,onCancel:n}){let[r,a]=(0,N.useState)(``),[o,s]=(0,N.useState)(``),[c,l]=(0,N.useState)(x()),[u,d]=(0,N.useState)(!1),[f,p]=(0,N.useState)(null);return(0,P.jsxs)(`div`,{className:`border-t border-border/60 bg-muted/30 px-4 py-3`,children:[(0,P.jsxs)(`div`,{className:`mb-1 flex items-baseline justify-between`,children:[(0,P.jsx)(`span`,{className:`text-[10px] uppercase tracking-wide text-muted-foreground/70`,children:`New todo`}),(0,P.jsx)(`button`,{type:`button`,onClick:n,className:`text-muted-foreground hover:text-foreground`,"aria-label":`Discard draft`,children:(0,P.jsx)(i,{className:`h-3 w-3`})})]}),(0,P.jsx)(`input`,{value:r,onChange:e=>a(e.target.value),placeholder:`What needs doing?`,autoFocus:!0,spellCheck:!1,className:`mb-1 w-full border-0 bg-transparent p-0 text-sm font-semibold text-foreground outline-none placeholder:text-muted-foreground/50`}),(0,P.jsx)(k,{value:o,onChange:s,placeholder:`Description (optional)…`}),(0,P.jsx)(`div`,{className:`mt-2`,children:(0,P.jsx)(C,{value:c,onChange:l,compact:!0,placeholder:`No due date`,className:`w-[188px]`})}),f&&(0,P.jsx)(`p`,{className:`mt-1 text-xs text-destructive`,children:f}),(0,P.jsx)(`div`,{className:`mt-2 flex justify-end`,children:(0,P.jsx)(`button`,{type:`button`,onClick:async()=>{if(!(!r.trim()||!e||u)){d(!0),p(null);try{await v(e,[{schema:_,schemaVersion:F,data:b({title:r,description:o,status:`pending`,priority:``,due:c}),metadata:{features:[]}}]),t()}catch(e){p(e instanceof Error?e.message:`Failed to create todo`),d(!1)}}},disabled:!r.trim()||u,className:`rounded-md bg-primary px-2.5 py-1 text-xs text-primary-foreground disabled:opacity-50`,children:u?`Saving…`:`Save todo`})})]})}function z({autoAdd:e=!1}){let t=E(),{docs:n,setDocs:r,loading:i,error:o,scope:l,reload:h,removeDoc:g}=j(t,_),[v,b]=(0,N.useState)(``),[x,S]=(0,N.useState)(0),[C,w]=(0,N.useState)(`desc`),[T,D]=(0,N.useState)(!1),[k,A]=(0,N.useState)(e),[M,F]=(0,N.useState)(null),z=(0,N.useRef)(new Map),B=(0,N.useRef)(new Map),V=(0,N.useCallback)((e,t)=>{t?z.current.set(e,t):z.current.delete(e)},[]),H=(0,N.useCallback)((e,t)=>{t?B.current.set(e,t):B.current.delete(e)},[]),U=(0,N.useCallback)(async e=>{let t=e.data?.title?`"${e.data.title}"`:`#${e.id}`;if(window.confirm(`Delete todo ${t}?\n\nIt is removed from this path and moves to the workspace trash if nothing else links it.`))try{await g(e.id)}catch{}},[g]),W=(0,N.useCallback)((e,t)=>{r(n=>n.map(n=>n.id===e?{...n,data:{...n.data||{},status:t,completed:t===`completed`}}:n))},[r]),G=(0,N.useMemo)(()=>{let e=T?[...n]:n.filter(e=>!I.has(String(e.data?.status??`pending`)));return e.sort((e,t)=>{let n=new Date(e.createdAt).getTime()-new Date(t.createdAt).getTime();return C===`asc`?n:-n}),e},[n,C,T]),K=(0,N.useMemo)(()=>n.filter(e=>I.has(String(e.data?.status??`pending`))).length,[n]),q=(0,N.useMemo)(()=>{let e=v.trim().toLowerCase();if(!e)return[];let t=[];for(let n of G){let r=String(n.data?.description??``),i=String(n.data?.title??``),a=r.toLowerCase().indexOf(e);a>=0?t.push({docId:n.id,offset:a}):i.toLowerCase().includes(e)&&t.push({docId:n.id,offset:-1})}return t},[v,G]),J=q.length?q[Math.min(x,q.length-1)]:null;(0,N.useEffect)(()=>{J&&z.current.get(J.docId)?.scrollIntoView({block:`center`,behavior:`smooth`})},[J]);let Y=(0,N.useCallback)(e=>{if(!q.length)return;let t=e?(x+1)%q.length:x;e&&S(t);let n=q[t],r=B.current.get(n.docId);r&&n.offset>=0&&(r.focus(),r.setSelectionRange(n.offset,n.offset+v.trim().length)),z.current.get(n.docId)?.scrollIntoView({block:`center`,behavior:`smooth`})},[q,x,v]);return t?(0,P.jsxs)(`div`,{className:`flex h-full flex-col`,children:[(0,P.jsxs)(`div`,{className:`flex shrink-0 items-center gap-2 border-b border-border px-3 py-2`,children:[(0,P.jsxs)(`div`,{className:`relative flex-1`,children:[(0,P.jsx)(p,{className:`pointer-events-none absolute left-2 top-1/2 h-3.5 w-3.5 -translate-y-1/2 text-muted-foreground`}),(0,P.jsx)(`input`,{value:v,onChange:e=>{b(e.target.value),S(0)},onKeyDown:e=>{e.key===`Enter`&&(e.preventDefault(),Y(!0))},placeholder:`Search todos…`,spellCheck:!1,className:`w-full rounded-md border border-input bg-transparent py-1 pl-7 pr-14 text-xs outline-none placeholder:text-muted-foreground focus-visible:ring-1 focus-visible:ring-ring`}),v.trim()&&(0,P.jsx)(`span`,{className:`absolute right-2 top-1/2 -translate-y-1/2 text-[10px] tabular-nums text-muted-foreground`,children:q.length?`${Math.min(x+1,q.length)}/${q.length}`:`0/0`})]}),(0,P.jsx)(`button`,{type:`button`,onClick:()=>D(e=>!e),className:m(`rounded-md border p-1.5 transition-colors`,T?`border-foreground text-foreground`:`border-border text-muted-foreground hover:bg-muted hover:text-foreground`),title:T?`Hide done items`:`Show done items${K?` (${K})`:``}`,"aria-label":T?`Hide done items`:`Show done items`,children:T?(0,P.jsx)(s,{className:`h-3.5 w-3.5`}):(0,P.jsx)(f,{className:`h-3.5 w-3.5`})}),(0,P.jsx)(`button`,{type:`button`,onClick:()=>w(e=>e===`desc`?`asc`:`desc`),className:`rounded-md border border-border p-1.5 text-muted-foreground transition-colors hover:bg-muted hover:text-foreground`,title:C===`desc`?`Newest first (click for oldest first)`:`Oldest first (click for newest first)`,"aria-label":`Toggle sort order`,children:C===`desc`?(0,P.jsx)(c,{className:`h-3.5 w-3.5`}):(0,P.jsx)(u,{className:`h-3.5 w-3.5`})}),(0,P.jsxs)(`button`,{type:`button`,onClick:()=>A(!0),className:`flex items-center gap-1 rounded-md bg-primary px-2 py-1.5 text-xs text-primary-foreground`,title:`Add a todo`,children:[(0,P.jsx)(a,{className:`h-3.5 w-3.5`}),`Todo`]})]}),(0,P.jsxs)(`div`,{className:`min-h-0 flex-1 overflow-y-auto`,children:[k&&(0,P.jsx)(R,{target:t,onCreated:()=>{A(!1),h()},onCancel:()=>A(!1)}),i&&!n.length&&(0,P.jsx)(`div`,{className:`flex items-center justify-center py-10`,children:(0,P.jsx)(d,{className:`h-5 w-5 animate-spin text-muted-foreground`})}),o&&(0,P.jsx)(`p`,{className:`px-4 py-6 text-center text-sm text-destructive`,children:o}),!i&&!o&&!G.length&&!k&&(0,P.jsx)(`p`,{className:`px-4 py-10 text-center text-sm text-muted-foreground`,children:K?`Nothing pending - ${K} done item${K>1?`s`:``} hidden.`:`No todos here yet - add the first one.`}),G.map(e=>(0,P.jsx)(L,{doc:e,updateWorkspace:l?.workspaceName??null,registerEl:V,registerBody:H,highlighted:J?.docId===e.id,onLinkTo:()=>F(e.id),onDelete:()=>U(e),onStatusSaved:W},e.id))]}),M!==null&&(0,P.jsx)(O,{documentId:M,workspaceName:l?.workspaceName,onClose:()=>F(null)})]}):(0,P.jsx)(`div`,{className:`flex h-full items-center justify-center p-6 text-center text-sm text-muted-foreground`,children:y(t)})}export{z as TodosApplet};
@@ -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{Wr as r,Yr as i,hn as a,nr as o,pn as s}from"./ui-CDoK3F3U.js";import{Hn as c,wn as l}from"./workspace-cv6Hrfhh.js";import{_ as u,g as d,h as f,m as p,p as m}from"./ObjectPropertiesCard-pE3IL82x.js";import{i as h}from"./date-time-picker-C40sYmga.js";import{n as g}from"./use-document-modal-PG8bQyIB.js";var _=e(n(),1),v=new Map;function y(e){v.set(e.type,e)}function b(e){return v.get(e)}function x(){return[...v.values()]}var S=450,C=10;function w(e,t){let{open:n}=g(),r=(0,_.useRef)(null),i=(0,_.useRef)(null),a=(0,_.useRef)(!1),o=()=>{e&&n(e,t)},s=()=>{r.current&&=(clearTimeout(r.current),null)};return{activationProps:{role:`button`,tabIndex:0,onClick:()=>{if(a.current){a.current=!1;return}o()},onKeyDown:e=>{(e.key===`Enter`||e.key===` `)&&(e.preventDefault(),o())},onContextMenu:e=>{e.preventDefault(),o()},onPointerDown:e=>{e.pointerType===`touch`&&(i.current={x:e.clientX,y:e.clientY},a.current=!1,s(),r.current=setTimeout(()=>{a.current=!0,o()},S))},onPointerMove:e=>{i.current&&Math.hypot(e.clientX-i.current.x,e.clientY-i.current.y)>C&&s()},onPointerUp:s,onPointerCancel:s,onPointerLeave:s},stopRowActivation:e=>e.stopPropagation()}}var T=t(),E=`data/schema/task`;function D({doc:e,workspaceId:t,readOnly:n,onChanged:a}){let c=u(e),[g,v]=(0,_.useState)(!1),{replicating:y,label:b}=l(e),x=c.status===`completed`,S=c.status??`pending`,C=f(c),{activationProps:E,stopRowActivation:D}=w(e,t),O=async()=>{if(!(n||g)){v(!0);try{await d(t,e,x?`pending`:`completed`),a()}catch{}finally{v(!1)}}};return(0,T.jsxs)(`div`,{...E,title:`Open details`,className:`canvas-no-drag flex cursor-pointer items-start gap-2.5 rounded-md border bg-card px-2.5 py-2 transition-colors hover:bg-accent/50 focus:outline-none focus-visible:ring-2 focus-visible:ring-ring ${y?`opacity-60`:``}`,children:[(0,T.jsx)(`button`,{type:`button`,onClick:e=>{D(e),O()},disabled:n||g||y,"aria-pressed":x,title:x?`Mark not done`:`Mark done`,className:`canvas-no-drag mt-0.5 flex h-4 w-4 shrink-0 items-center justify-center rounded border transition-colors ${x?`border-success bg-success text-success-foreground`:`border-input hover:border-success`} ${n?`cursor-default opacity-70`:``}`,children:g?(0,T.jsx)(s,{className:`h-2.5 w-2.5 animate-spin`}):x&&(0,T.jsx)(r,{className:`h-3 w-3`})}),(0,T.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,T.jsx)(`div`,{className:`truncate text-sm ${x?`text-muted-foreground line-through`:``}`,children:c.title||`Todo ${e.id}`}),(0,T.jsxs)(`div`,{className:`mt-0.5 flex flex-wrap items-center gap-1.5 text-[11px]`,children:[(0,T.jsx)(`span`,{className:`rounded-full px-1.5 py-0.5 ${m[S]}`,children:h[S]}),c.dueDate&&(0,T.jsxs)(`span`,{className:`inline-flex items-center gap-0.5 ${C?`font-medium text-destructive`:`text-muted-foreground`}`,children:[(0,T.jsx)(i,{className:`h-3 w-3`}),p(c.dueDate)]}),typeof c.priority==`number`&&(0,T.jsxs)(`span`,{className:`inline-flex items-center gap-0.5 text-muted-foreground`,children:[(0,T.jsx)(o,{className:`h-3 w-3`}),`P`,c.priority]}),y&&(0,T.jsxs)(`span`,{className:`inline-flex items-center gap-1 text-muted-foreground`,role:`status`,children:[(0,T.jsx)(s,{className:`h-3 w-3 animate-spin`}),b]})]})]})]})}function O({config:e,setConfig:t,canvas:n}){let r=typeof e.pageSize==`number`?e.pageSize:50,[i,a]=(0,_.useState)([]),[o,s]=(0,_.useState)(!0),[l,d]=(0,_.useState)(0),f=n.interactive===!1,p=n.readOnly!==!0,[m,h]=(0,_.useState)(e.hideDone===!0),g=p?e.hideDone===!0:m,v=n=>{p?t({...e,hideDone:n}):h(n)};(0,_.useEffect)(()=>{let e=!1;return(async()=>{s(!0);try{let t=await n.fetchDocuments({limit:r,allOf:[E],sortBy:`tasks`,order:`asc`});if(e)return;a((t.payload||[]).filter(e=>e.schema===c))}catch{e||a([])}finally{e||s(!1)}})(),()=>{e=!0}},[n,r,l]),(0,_.useEffect)(()=>{let e=()=>d(e=>e+1);return window.addEventListener(`workspace:documents:refresh`,e),()=>window.removeEventListener(`workspace:documents:refresh`,e)},[]);let y=(0,_.useCallback)(()=>d(e=>e+1),[]),b=g?i.filter(e=>u(e).status!==`completed`):i,x=i.filter(e=>{let t=u(e).status;return t!==`completed`&&t!==`cancelled`}).length;return(0,T.jsxs)(`div`,{className:`flex h-full flex-col`,children:[(0,T.jsxs)(`div`,{className:`canvas-no-drag flex items-center justify-between gap-2 border-b px-1 pb-2`,children:[(0,T.jsxs)(`span`,{className:`text-xs text-muted-foreground`,children:[x,` open`]}),(0,T.jsxs)(`label`,{className:`flex items-center gap-1.5 text-xs text-muted-foreground`,children:[(0,T.jsx)(`input`,{type:`checkbox`,checked:g,onChange:e=>v(e.target.checked),className:`h-3 w-3`}),`Hide done`]})]}),(0,T.jsx)(`div`,{className:`flex-1 space-y-1.5 overflow-y-auto p-1`,children:o&&i.length===0?(0,T.jsx)(`div`,{className:`p-3 text-sm text-muted-foreground`,children:`Loading todos…`}):b.length===0?(0,T.jsx)(`div`,{className:`p-3 text-sm text-muted-foreground`,children:`No todos in this canvas' context.`}):b.map(e=>(0,T.jsx)(D,{doc:e,workspaceId:n.workspaceId,readOnly:f,onChanged:y},e.id))})]})}y({type:`todos`,name:`Todos`,icon:a,defaultSize:{w:4,h:6,minW:3,minH:3},mobileHeight:.6,defaultConfig:{pageSize:50,hideDone:!1},component:O});export{y as a,x as i,w as n,b as r,D as t};
1
+ import{o as e}from"./rolldown-runtime-C0FnF6B9.js";import{l as t,u as n}from"./code-editor-BOIngd5F.js";import{Wr as r,Yr as i,hn as a,nr as o,pn as s}from"./ui-CDoK3F3U.js";import{xn as c,zn as l}from"./workspace-C5V-ZCOE.js";import{_ as u,g as d,h as f,m as p,p as m}from"./ObjectPropertiesCard-D2lrTQqT.js";import{i as h}from"./date-time-picker-DCikruos.js";import{n as g}from"./use-document-modal-PG8bQyIB.js";var _=e(n(),1),v=new Map;function y(e){v.set(e.type,e)}function b(e){return v.get(e)}function x(){return[...v.values()]}var S=450,C=10;function w(e,t){let{open:n}=g(),r=(0,_.useRef)(null),i=(0,_.useRef)(null),a=(0,_.useRef)(!1),o=()=>{e&&n(e,t)},s=()=>{r.current&&=(clearTimeout(r.current),null)};return{activationProps:{role:`button`,tabIndex:0,onClick:()=>{if(a.current){a.current=!1;return}o()},onKeyDown:e=>{(e.key===`Enter`||e.key===` `)&&(e.preventDefault(),o())},onContextMenu:e=>{e.preventDefault(),o()},onPointerDown:e=>{e.pointerType===`touch`&&(i.current={x:e.clientX,y:e.clientY},a.current=!1,s(),r.current=setTimeout(()=>{a.current=!0,o()},S))},onPointerMove:e=>{i.current&&Math.hypot(e.clientX-i.current.x,e.clientY-i.current.y)>C&&s()},onPointerUp:s,onPointerCancel:s,onPointerLeave:s},stopRowActivation:e=>e.stopPropagation()}}var T=t(),E=`data/schema/task`;function D({doc:e,workspaceId:t,readOnly:n,onChanged:a}){let l=u(e),[g,v]=(0,_.useState)(!1),{replicating:y,label:b}=c(e),x=l.status===`completed`,S=l.status??`pending`,C=f(l),{activationProps:E,stopRowActivation:D}=w(e,t),O=async()=>{if(!(n||g)){v(!0);try{await d(t,e,x?`pending`:`completed`),a()}catch{}finally{v(!1)}}};return(0,T.jsxs)(`div`,{...E,title:`Open details`,className:`canvas-no-drag flex cursor-pointer items-start gap-2.5 rounded-md border bg-card px-2.5 py-2 transition-colors hover:bg-accent/50 focus:outline-none focus-visible:ring-2 focus-visible:ring-ring ${y?`opacity-60`:``}`,children:[(0,T.jsx)(`button`,{type:`button`,onClick:e=>{D(e),O()},disabled:n||g||y,"aria-pressed":x,title:x?`Mark not done`:`Mark done`,className:`canvas-no-drag mt-0.5 flex h-4 w-4 shrink-0 items-center justify-center rounded border transition-colors ${x?`border-success bg-success text-success-foreground`:`border-input hover:border-success`} ${n?`cursor-default opacity-70`:``}`,children:g?(0,T.jsx)(s,{className:`h-2.5 w-2.5 animate-spin`}):x&&(0,T.jsx)(r,{className:`h-3 w-3`})}),(0,T.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,T.jsx)(`div`,{className:`truncate text-sm ${x?`text-muted-foreground line-through`:``}`,children:l.title||`Todo ${e.id}`}),(0,T.jsxs)(`div`,{className:`mt-0.5 flex flex-wrap items-center gap-1.5 text-[11px]`,children:[(0,T.jsx)(`span`,{className:`rounded-full px-1.5 py-0.5 ${m[S]}`,children:h[S]}),l.dueDate&&(0,T.jsxs)(`span`,{className:`inline-flex items-center gap-0.5 ${C?`font-medium text-destructive`:`text-muted-foreground`}`,children:[(0,T.jsx)(i,{className:`h-3 w-3`}),p(l.dueDate)]}),typeof l.priority==`number`&&(0,T.jsxs)(`span`,{className:`inline-flex items-center gap-0.5 text-muted-foreground`,children:[(0,T.jsx)(o,{className:`h-3 w-3`}),`P`,l.priority]}),y&&(0,T.jsxs)(`span`,{className:`inline-flex items-center gap-1 text-muted-foreground`,role:`status`,children:[(0,T.jsx)(s,{className:`h-3 w-3 animate-spin`}),b]})]})]})]})}function O({config:e,setConfig:t,canvas:n}){let r=typeof e.pageSize==`number`?e.pageSize:50,[i,a]=(0,_.useState)([]),[o,s]=(0,_.useState)(!0),[c,d]=(0,_.useState)(0),f=n.interactive===!1,p=n.readOnly!==!0,[m,h]=(0,_.useState)(e.hideDone===!0),g=p?e.hideDone===!0:m,v=n=>{p?t({...e,hideDone:n}):h(n)};(0,_.useEffect)(()=>{let e=!1;return(async()=>{s(!0);try{let t=await n.fetchDocuments({limit:r,allOf:[E],sortBy:`tasks`,order:`asc`});if(e)return;a((t.payload||[]).filter(e=>e.schema===l))}catch{e||a([])}finally{e||s(!1)}})(),()=>{e=!0}},[n,r,c]),(0,_.useEffect)(()=>{let e=()=>d(e=>e+1);return window.addEventListener(`workspace:documents:refresh`,e),()=>window.removeEventListener(`workspace:documents:refresh`,e)},[]);let y=(0,_.useCallback)(()=>d(e=>e+1),[]),b=g?i.filter(e=>u(e).status!==`completed`):i,x=i.filter(e=>{let t=u(e).status;return t!==`completed`&&t!==`cancelled`}).length;return(0,T.jsxs)(`div`,{className:`flex h-full flex-col`,children:[(0,T.jsxs)(`div`,{className:`canvas-no-drag flex items-center justify-between gap-2 border-b px-1 pb-2`,children:[(0,T.jsxs)(`span`,{className:`text-xs text-muted-foreground`,children:[x,` open`]}),(0,T.jsxs)(`label`,{className:`flex items-center gap-1.5 text-xs text-muted-foreground`,children:[(0,T.jsx)(`input`,{type:`checkbox`,checked:g,onChange:e=>v(e.target.checked),className:`h-3 w-3`}),`Hide done`]})]}),(0,T.jsx)(`div`,{className:`flex-1 space-y-1.5 overflow-y-auto p-1`,children:o&&i.length===0?(0,T.jsx)(`div`,{className:`p-3 text-sm text-muted-foreground`,children:`Loading todos…`}):b.length===0?(0,T.jsx)(`div`,{className:`p-3 text-sm text-muted-foreground`,children:`No todos in this canvas' context.`}):b.map(e=>(0,T.jsx)(D,{doc:e,workspaceId:n.workspaceId,readOnly:f,onChanged:y},e.id))})]})}y({type:`todos`,name:`Todos`,icon:a,defaultSize:{w:4,h:6,minW:3,minH:3},mobileHeight:.6,defaultConfig:{pageSize:50,hideDone:!1},component:O});export{y as a,x as i,w as n,b as r,D as t};
@@ -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,Lr as i,Wr as a,ar as o,on as s,pn as c,sn as l}from"./ui-CDoK3F3U.js";import{t as u}from"./utils-2pl1SbIp.js";import{t as d}from"./button-SeUZ_Pvi.js";import{t as f}from"./label-BSTdjCWU.js";import{kt as p}from"./workspace-cv6Hrfhh.js";import{o as m,s as h}from"./IdentityFields-C7sv9pMk.js";import{n as g}from"./tags-YamdPoBK.js";import{a as _,i as v,l as y,o as b,r as x}from"./useAddTarget-BEgKjqGj.js";import{r as S}from"./relation-events-CKio19hE.js";import{a as C,n as w,r as T}from"./blobs-WiXP9QRi.js";import{t as E}from"./sha256-65KIjGvZ.js";var D=e(n(),1);function O(e){let[t,n]=(0,D.useState)(null);return(0,D.useEffect)(()=>{if(!e)return;let t=!1;return p(e).then(r=>{t||n({workspace:e,tags:r})}).catch(()=>{}),()=>{t=!0}},[e]),t&&t.workspace===e?t.tags:[]}var k=t();function A(e){if(e.manual){let t=`${e.manual.lat.toFixed(5)}, ${e.manual.lon.toFixed(5)}`;return e.manualLabel?`${e.manualLabel} · ${t}`:`Custom pin · ${t}`}if(!e.supported)return`Needs a secure (https) connection, or pick a point on the map`;if(e.permission===`denied`)return`Blocked. Allow location for this site, or pick a point on the map`;if(e.error)return e.error;if(e.busy)return`Getting your location…`;if(e.enabled&&e.fix){let{lat:t,lon:n,accuracy:r}=e.fix;return`${t.toFixed(5)}, ${n.toFixed(5)}${r==null?``:` · ±${r} m`}`}return e.enabled?`Location will be attached when you save`:`Attach where you are, or pick any point on the map`}function j({geotag:e,idPrefix:t=`geotag`}){let[n,i]=(0,D.useState)(!1),a=!e.supported||e.permission===`denied`,o=!e.manual&&(!e.supported||e.permission===`denied`||!!e.error);return(0,k.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,k.jsxs)(`div`,{className:`flex items-center justify-between gap-3`,children:[(0,k.jsxs)(`div`,{role:`switch`,"aria-checked":e.enabled,"aria-disabled":a,"aria-label":`Geotag this document`,"aria-describedby":`${t}-hint`,tabIndex:a?-1:0,onClick:()=>!a&&e.setEnabled(!e.enabled),onKeyDown:t=>{a||(t.key===` `||t.key===`Enter`)&&(t.preventDefault(),e.setEnabled(!e.enabled))},className:u(`flex flex-1 items-center justify-between gap-3 select-none outline-none rounded focus-visible:ring-2 focus-visible:ring-ring`,a?`cursor-not-allowed opacity-50`:`cursor-pointer`),children:[(0,k.jsxs)(`span`,{className:`flex items-center gap-2 text-sm text-foreground`,children:[e.busy?(0,k.jsx)(c,{className:`h-4 w-4 shrink-0 animate-spin text-muted-foreground`}):(0,k.jsx)(l,{className:u(`h-4 w-4 shrink-0`,e.enabled?`text-info`:`text-muted-foreground`)}),`Geotag`]}),(0,k.jsx)(`div`,{className:u(`relative h-5 w-10 shrink-0 rounded-full transition-colors`,e.enabled?`bg-info`:`bg-muted-foreground/30`),children:(0,k.jsx)(`div`,{className:u(`absolute top-[2px] h-4 w-4 rounded-full bg-background shadow-elevation-1 transition-transform`,e.enabled?`translate-x-[22px]`:`translate-x-[2px]`)})})]}),(0,k.jsxs)(`span`,{className:`flex shrink-0 items-center gap-1`,children:[(0,k.jsxs)(`button`,{type:`button`,onClick:()=>i(!0),title:`Pick a point on the map`,className:`inline-flex items-center gap-1.5 rounded-md border border-border px-2 py-1 text-xs text-muted-foreground transition-colors hover:bg-muted hover:text-foreground`,children:[(0,k.jsx)(s,{className:`h-3.5 w-3.5`}),e.manual?`Change pin`:`Pick on map`]}),e.manual&&(0,k.jsx)(`button`,{type:`button`,onClick:()=>e.setManual(null),"aria-label":`Remove custom pin`,title:`Remove custom pin`,className:`rounded p-1 text-muted-foreground hover:bg-muted hover:text-foreground`,children:(0,k.jsx)(r,{className:`h-3.5 w-3.5`})})]})]}),(0,k.jsx)(`p`,{id:`${t}-hint`,className:u(`text-xs`,o?`text-warning`:`text-muted-foreground`),children:A(e)}),n&&(0,k.jsx)(m,{initial:e.manual??e.fix??null,onPick:t=>e.setManual(t),onClose:()=>i(!1)})]})}var M=`data/schema/file`,N=`3.0`;function P(e){let[t,n]=(0,D.useState)([]),[r,i]=(0,D.useState)(``);return{tags:t,setTags:n,comment:r,setComment:i,suggestions:O(e),geotag:S()}}function F(e,t,n={}){let r=g(n.tags??[]),i=n.comment?.trim();return{schema:M,schemaVersion:N,data:{},checksumArray:[`sha256/${e.checksum}`],locations:[{url:e.url,metadata:{filename:t.name}}],...i?{comment:i}:{},metadata:{contentType:t.type,size:e.size,...r.length?{features:r}:{},...n.geo?{geo:n.geo}:{}}}}var I=`flex w-full rounded-md border border-input bg-transparent px-3 py-2 text-sm shadow-elevation-1 transition-colors placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring`;function L({fields:e,idPrefix:t=`file`,multiple:n=!1}){return(0,k.jsxs)(k.Fragment,{children:[(0,k.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,k.jsx)(f,{children:`Tags`}),(0,k.jsx)(h,{tags:e.tags,onChange:e.setTags,suggestions:e.suggestions})]}),(0,k.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,k.jsx)(f,{htmlFor:`${t}-comment`,children:`Comment`}),(0,k.jsx)(`textarea`,{id:`${t}-comment`,value:e.comment,onChange:t=>e.setComment(t.target.value),rows:3,placeholder:`Optional; searchable, and the only text a photo has`,className:I}),n&&e.tags.length+e.comment.trim().length>0&&(0,k.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`Applied to every file in this upload`})]}),(0,k.jsx)(j,{geotag:e.geotag,idPrefix:`${t}-geotag`})]})}var R=3;function z(e){return`${e.name}:${e.size}:${e.lastModified}`}function B(e=[]){let[t,n]=(0,D.useState)(()=>e.map(e=>({id:z(e),file:e,status:`queued`,progress:0}))),[r,i]=(0,D.useState)(!1),a=(0,D.useRef)(t),o=(0,D.useRef)(null),s=(0,D.useRef)(null);(0,D.useEffect)(()=>()=>s.current?.abort(),[]);let c=(0,D.useCallback)(e=>{a.current=e,n(e)},[]),l=(0,D.useCallback)((e,t)=>{let r=a.current.map(n=>n.id===e?{...n,...t}:n);a.current=r,n(r)},[]),u=(0,D.useCallback)(e=>{let t=new Set(a.current.map(e=>e.id)),n=e.filter(e=>!t.has(z(e))).map(e=>({id:z(e),file:e,status:`queued`,progress:0}));n.length&&c([...a.current,...n])},[c]),d=(0,D.useCallback)(e=>{c(a.current.filter(t=>t.id!==e))},[c]),f=(0,D.useCallback)(()=>{s.current?.abort(),s.current=null,c([]),i(!1)},[c]),p=(0,D.useCallback)(()=>{s.current?.abort()},[]);return{items:t,running:r,addFiles:u,removeItem:d,reset:f,start:(0,D.useCallback)(async(e,t)=>{if(!e)throw Error(`No active workspace or context to add to`);let{workspaceName:n,treeName:r,path:u}=await _(e),d=r===`backends`?await v(n,u):null,f=JSON.stringify([n,r,u]);o.current!==null&&o.current!==f&&c(a.current.map(({id:e,file:t})=>({id:e,file:t,status:`queued`,progress:0}))),o.current=f;let p=new AbortController;s.current=p,i(!0);let m=a.current.filter(e=>e.status!==`done`);for(let e of m)l(e.id,{status:`queued`,progress:0,error:void 0});try{if(d){let e=0;await Promise.all(Array.from({length:Math.min(R,m.length)},async()=>{for(;e<m.length&&!p.signal.aborted;){let t=m[e++];try{l(t.id,{status:`uploading`,progress:0,resumed:!1});let e=await T(n,{...d,key:y(d.key,t.file.name)},t.file,{signal:p.signal,onProgress:(e,n)=>l(t.id,{progress:n?e/n:0})});l(t.id,{status:`done`,progress:1,docId:e.docId??void 0})}catch(e){l(t.id,{status:`error`,error:e instanceof Error?e.message:`Upload failed`})}}}))}else{let r=new Map;for(let e of m){if(p.signal.aborted)throw new DOMException(`cancelled`,`AbortError`);if(!(e.file.size>=8388608)){l(e.id,{status:`hashing`});try{let t=await E(e.file,t=>l(e.id,{progress:t}));r.set(e.id,t),l(e.id,{status:`checking`,progress:0})}catch(t){l(e.id,{status:`error`,error:t instanceof Error?t.message:`Failed to read file`})}}}let i={};if(r.size)try{i=await w(n,[...new Set(r.values())])}catch{i={}}let a=m.filter(e=>r.has(e.id)||e.file.size>=8388608),o=0;await Promise.all(Array.from({length:Math.min(R,a.length)},async()=>{for(;o<a.length;){if(p.signal.aborted)return;let s=a[o++],c=r.get(s.id);try{let r=c?i[c]??null:null;r?l(s.id,{status:`linking`,progress:1,resumed:!0}):(l(s.id,{status:`uploading`,progress:0}),r=await C(n,s.file,{sha256:c,signal:p.signal,onProgress:(e,t)=>l(s.id,{progress:t?e/t:0})}),l(s.id,{status:`linking`,progress:1}));let a=await b(e,[t(r,s.file)],{refresh:!1});l(s.id,{status:`done`,docId:a[0]})}catch(e){let t=e instanceof DOMException&&e.name===`AbortError`;l(s.id,{status:`error`,error:t?`Cancelled`:e instanceof Error?e.message:`Upload failed`})}}}))}}finally{if(p.signal.aborted)for(let e of a.current)e.status!==`done`&&e.status!==`error`&&l(e.id,{status:`error`,error:`Cancelled`});i(!1),s.current===p&&(s.current=null),a.current.some(e=>e.status===`done`)&&x(e)}let h=a.current;return{done:h.filter(e=>e.status===`done`).length,resumed:h.filter(e=>e.status===`done`&&e.resumed).length,failed:h.filter(e=>e.status===`error`).length,total:h.length,docIds:h.flatMap(e=>e.status===`done`&&e.docId!=null?[e.docId]:[])}},[l,c]),cancel:p}}function V(e){return e<1024?`${e} B`:e<1048576?`${(e/1024).toFixed(1)} KB`:`${(e/1048576).toFixed(1)} MB`}function H(e){switch(e.status){case`hashing`:return`hashing`;case`checking`:return`checking`;case`uploading`:return`${Math.round(e.progress*100)}%`;case`linking`:return`saving`;case`done`:return e.resumed?`already uploaded`:`done`;case`error`:return e.error||`failed`;default:return V(e.file.size)}}function U({item:e}){switch(e.status){case`done`:return(0,k.jsx)(a,{className:`h-3.5 w-3.5 shrink-0 text-green-600 dark:text-green-500`});case`error`:return(0,k.jsx)(i,{className:`h-3.5 w-3.5 shrink-0 text-destructive`});case`queued`:return(0,k.jsx)(o,{className:`h-3.5 w-3.5 shrink-0 text-muted-foreground`});default:return(0,k.jsx)(c,{className:`h-3.5 w-3.5 shrink-0 animate-spin text-muted-foreground`})}}function W({item:e}){if(e.status===`queued`)return null;let t=e.status===`done`||e.status===`error`||e.status===`linking`?1:e.status===`checking`?0:e.progress;return(0,k.jsx)(`div`,{className:`h-1 w-full overflow-hidden rounded-full bg-muted`,children:(0,k.jsx)(`div`,{className:u(`h-full rounded-full transition-[width] duration-normal`,e.status===`error`?`bg-destructive`:e.status===`done`?`bg-green-600 dark:bg-green-500`:`bg-primary`),style:{width:`${Math.round(t*100)}%`}})})}function G({items:e,running:t,onRemove:n}){let i=e.filter(e=>e.status===`done`).length,a=e.filter(e=>e.status===`error`).length;return(0,k.jsx)(k.Fragment,{children:e.length>0&&(0,k.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,k.jsxs)(f,{children:[e.length,` file(s)`,i>0&&(0,k.jsxs)(`span`,{className:`ml-1 text-muted-foreground`,children:[`— `,i,` done`,a>0?`, ${a} failed`:``]})]}),(0,k.jsx)(`ul`,{className:`max-h-48 space-y-1 overflow-y-auto`,children:e.map(e=>(0,k.jsxs)(`li`,{className:`flex flex-col gap-1 rounded border border-input px-2 py-1 text-sm`,children:[(0,k.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,k.jsx)(U,{item:e}),(0,k.jsx)(`span`,{className:`flex-1 truncate`,title:e.file.name,children:e.file.name}),(0,k.jsx)(`span`,{className:u(`shrink-0 text-xs`,e.status===`error`?`text-destructive`:`text-muted-foreground`),title:e.status===`error`?e.error:void 0,children:H(e)}),!t&&e.status!==`done`&&(0,k.jsx)(`button`,{type:`button`,onClick:()=>n(e.id),className:`text-muted-foreground hover:text-foreground`,"aria-label":`Remove ${e.file.name}`,children:(0,k.jsx)(r,{className:`h-3.5 w-3.5`})})]}),(0,k.jsx)(W,{item:e})]},e.id))})]})})}function K({items:e,running:t,onCancel:n}){return(0,k.jsxs)(`div`,{className:`space-y-4 overflow-y-auto p-4`,children:[(0,k.jsx)(`h2`,{className:`text-sm font-medium`,children:`Uploading files`}),!t&&(0,k.jsx)(`p`,{role:`status`,className:`text-sm text-muted-foreground`,children:`Preparing / finishing upload…`}),(0,k.jsx)(G,{items:e,running:!0,onRemove:()=>{}}),(0,k.jsx)(d,{variant:`outline`,size:`sm`,disabled:!t,onClick:n,children:`Cancel upload`})]})}export{F as a,O as c,L as i,K as n,P as o,B as r,j as s,G as t};
1
+ import{o as e}from"./rolldown-runtime-C0FnF6B9.js";import{l as t,u as n}from"./code-editor-BOIngd5F.js";import{L as r,Lr as i,Wr as a,ar as o,on as s,pn as c,sn as l}from"./ui-CDoK3F3U.js";import{t as u}from"./utils-2pl1SbIp.js";import{t as d}from"./button-SeUZ_Pvi.js";import{t as f}from"./label-BSTdjCWU.js";import{Dt as p}from"./workspace-C5V-ZCOE.js";import{o as m,s as h}from"./IdentityFields-D-NCTUaE.js";import{n as g}from"./tags-YamdPoBK.js";import{a as _,i as v,l as y,o as b,r as x}from"./useAddTarget-DeRZWtGg.js";import{r as S}from"./relation-events-CKio19hE.js";import{a as C,n as w,r as T}from"./blobs-WiXP9QRi.js";import{t as E}from"./sha256-65KIjGvZ.js";var D=e(n(),1);function O(e){let[t,n]=(0,D.useState)(null);return(0,D.useEffect)(()=>{if(!e)return;let t=!1;return p(e).then(r=>{t||n({workspace:e,tags:r})}).catch(()=>{}),()=>{t=!0}},[e]),t&&t.workspace===e?t.tags:[]}var k=t();function A(e){if(e.manual){let t=`${e.manual.lat.toFixed(5)}, ${e.manual.lon.toFixed(5)}`;return e.manualLabel?`${e.manualLabel} · ${t}`:`Custom pin · ${t}`}if(!e.supported)return`Needs a secure (https) connection, or pick a point on the map`;if(e.permission===`denied`)return`Blocked. Allow location for this site, or pick a point on the map`;if(e.error)return e.error;if(e.busy)return`Getting your location…`;if(e.enabled&&e.fix){let{lat:t,lon:n,accuracy:r}=e.fix;return`${t.toFixed(5)}, ${n.toFixed(5)}${r==null?``:` · ±${r} m`}`}return e.enabled?`Location will be attached when you save`:`Attach where you are, or pick any point on the map`}function j({geotag:e,idPrefix:t=`geotag`}){let[n,i]=(0,D.useState)(!1),a=!e.supported||e.permission===`denied`,o=!e.manual&&(!e.supported||e.permission===`denied`||!!e.error);return(0,k.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,k.jsxs)(`div`,{className:`flex items-center justify-between gap-3`,children:[(0,k.jsxs)(`div`,{role:`switch`,"aria-checked":e.enabled,"aria-disabled":a,"aria-label":`Geotag this document`,"aria-describedby":`${t}-hint`,tabIndex:a?-1:0,onClick:()=>!a&&e.setEnabled(!e.enabled),onKeyDown:t=>{a||(t.key===` `||t.key===`Enter`)&&(t.preventDefault(),e.setEnabled(!e.enabled))},className:u(`flex flex-1 items-center justify-between gap-3 select-none outline-none rounded focus-visible:ring-2 focus-visible:ring-ring`,a?`cursor-not-allowed opacity-50`:`cursor-pointer`),children:[(0,k.jsxs)(`span`,{className:`flex items-center gap-2 text-sm text-foreground`,children:[e.busy?(0,k.jsx)(c,{className:`h-4 w-4 shrink-0 animate-spin text-muted-foreground`}):(0,k.jsx)(l,{className:u(`h-4 w-4 shrink-0`,e.enabled?`text-info`:`text-muted-foreground`)}),`Geotag`]}),(0,k.jsx)(`div`,{className:u(`relative h-5 w-10 shrink-0 rounded-full transition-colors`,e.enabled?`bg-info`:`bg-muted-foreground/30`),children:(0,k.jsx)(`div`,{className:u(`absolute top-[2px] h-4 w-4 rounded-full bg-background shadow-elevation-1 transition-transform`,e.enabled?`translate-x-[22px]`:`translate-x-[2px]`)})})]}),(0,k.jsxs)(`span`,{className:`flex shrink-0 items-center gap-1`,children:[(0,k.jsxs)(`button`,{type:`button`,onClick:()=>i(!0),title:`Pick a point on the map`,className:`inline-flex items-center gap-1.5 rounded-md border border-border px-2 py-1 text-xs text-muted-foreground transition-colors hover:bg-muted hover:text-foreground`,children:[(0,k.jsx)(s,{className:`h-3.5 w-3.5`}),e.manual?`Change pin`:`Pick on map`]}),e.manual&&(0,k.jsx)(`button`,{type:`button`,onClick:()=>e.setManual(null),"aria-label":`Remove custom pin`,title:`Remove custom pin`,className:`rounded p-1 text-muted-foreground hover:bg-muted hover:text-foreground`,children:(0,k.jsx)(r,{className:`h-3.5 w-3.5`})})]})]}),(0,k.jsx)(`p`,{id:`${t}-hint`,className:u(`text-xs`,o?`text-warning`:`text-muted-foreground`),children:A(e)}),n&&(0,k.jsx)(m,{initial:e.manual??e.fix??null,onPick:t=>e.setManual(t),onClose:()=>i(!1)})]})}var M=`data/schema/file`,N=`3.0`;function P(e){let[t,n]=(0,D.useState)([]),[r,i]=(0,D.useState)(``);return{tags:t,setTags:n,comment:r,setComment:i,suggestions:O(e),geotag:S()}}function F(e,t,n={}){let r=g(n.tags??[]),i=n.comment?.trim();return{schema:M,schemaVersion:N,data:{},checksumArray:[`sha256/${e.checksum}`],locations:[{url:e.url,metadata:{filename:t.name}}],...i?{comment:i}:{},metadata:{contentType:t.type,size:e.size,...r.length?{features:r}:{},...n.geo?{geo:n.geo}:{}}}}var I=`flex w-full rounded-md border border-input bg-transparent px-3 py-2 text-sm shadow-elevation-1 transition-colors placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring`;function L({fields:e,idPrefix:t=`file`,multiple:n=!1}){return(0,k.jsxs)(k.Fragment,{children:[(0,k.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,k.jsx)(f,{children:`Tags`}),(0,k.jsx)(h,{tags:e.tags,onChange:e.setTags,suggestions:e.suggestions})]}),(0,k.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,k.jsx)(f,{htmlFor:`${t}-comment`,children:`Comment`}),(0,k.jsx)(`textarea`,{id:`${t}-comment`,value:e.comment,onChange:t=>e.setComment(t.target.value),rows:3,placeholder:`Optional; searchable, and the only text a photo has`,className:I}),n&&e.tags.length+e.comment.trim().length>0&&(0,k.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`Applied to every file in this upload`})]}),(0,k.jsx)(j,{geotag:e.geotag,idPrefix:`${t}-geotag`})]})}var R=3;function z(e){return`${e.name}:${e.size}:${e.lastModified}`}function B(e=[]){let[t,n]=(0,D.useState)(()=>e.map(e=>({id:z(e),file:e,status:`queued`,progress:0}))),[r,i]=(0,D.useState)(!1),a=(0,D.useRef)(t),o=(0,D.useRef)(null),s=(0,D.useRef)(null);(0,D.useEffect)(()=>()=>s.current?.abort(),[]);let c=(0,D.useCallback)(e=>{a.current=e,n(e)},[]),l=(0,D.useCallback)((e,t)=>{let r=a.current.map(n=>n.id===e?{...n,...t}:n);a.current=r,n(r)},[]),u=(0,D.useCallback)(e=>{let t=new Set(a.current.map(e=>e.id)),n=e.filter(e=>!t.has(z(e))).map(e=>({id:z(e),file:e,status:`queued`,progress:0}));n.length&&c([...a.current,...n])},[c]),d=(0,D.useCallback)(e=>{c(a.current.filter(t=>t.id!==e))},[c]),f=(0,D.useCallback)(()=>{s.current?.abort(),s.current=null,c([]),i(!1)},[c]),p=(0,D.useCallback)(()=>{s.current?.abort()},[]);return{items:t,running:r,addFiles:u,removeItem:d,reset:f,start:(0,D.useCallback)(async(e,t)=>{if(!e)throw Error(`No active workspace or context to add to`);let{workspaceName:n,treeName:r,path:u}=await _(e),d=r===`backends`?await v(n,u):null,f=JSON.stringify([n,r,u]);o.current!==null&&o.current!==f&&c(a.current.map(({id:e,file:t})=>({id:e,file:t,status:`queued`,progress:0}))),o.current=f;let p=new AbortController;s.current=p,i(!0);let m=a.current.filter(e=>e.status!==`done`);for(let e of m)l(e.id,{status:`queued`,progress:0,error:void 0});try{if(d){let e=0;await Promise.all(Array.from({length:Math.min(R,m.length)},async()=>{for(;e<m.length&&!p.signal.aborted;){let t=m[e++];try{l(t.id,{status:`uploading`,progress:0,resumed:!1});let e=await T(n,{...d,key:y(d.key,t.file.name)},t.file,{signal:p.signal,onProgress:(e,n)=>l(t.id,{progress:n?e/n:0})});l(t.id,{status:`done`,progress:1,docId:e.docId??void 0})}catch(e){l(t.id,{status:`error`,error:e instanceof Error?e.message:`Upload failed`})}}}))}else{let r=new Map;for(let e of m){if(p.signal.aborted)throw new DOMException(`cancelled`,`AbortError`);if(!(e.file.size>=8388608)){l(e.id,{status:`hashing`});try{let t=await E(e.file,t=>l(e.id,{progress:t}));r.set(e.id,t),l(e.id,{status:`checking`,progress:0})}catch(t){l(e.id,{status:`error`,error:t instanceof Error?t.message:`Failed to read file`})}}}let i={};if(r.size)try{i=await w(n,[...new Set(r.values())])}catch{i={}}let a=m.filter(e=>r.has(e.id)||e.file.size>=8388608),o=0;await Promise.all(Array.from({length:Math.min(R,a.length)},async()=>{for(;o<a.length;){if(p.signal.aborted)return;let s=a[o++],c=r.get(s.id);try{let r=c?i[c]??null:null;r?l(s.id,{status:`linking`,progress:1,resumed:!0}):(l(s.id,{status:`uploading`,progress:0}),r=await C(n,s.file,{sha256:c,signal:p.signal,onProgress:(e,t)=>l(s.id,{progress:t?e/t:0})}),l(s.id,{status:`linking`,progress:1}));let a=await b(e,[t(r,s.file)],{refresh:!1});l(s.id,{status:`done`,docId:a[0]})}catch(e){let t=e instanceof DOMException&&e.name===`AbortError`;l(s.id,{status:`error`,error:t?`Cancelled`:e instanceof Error?e.message:`Upload failed`})}}}))}}finally{if(p.signal.aborted)for(let e of a.current)e.status!==`done`&&e.status!==`error`&&l(e.id,{status:`error`,error:`Cancelled`});i(!1),s.current===p&&(s.current=null),a.current.some(e=>e.status===`done`)&&x(e)}let h=a.current;return{done:h.filter(e=>e.status===`done`).length,resumed:h.filter(e=>e.status===`done`&&e.resumed).length,failed:h.filter(e=>e.status===`error`).length,total:h.length,docIds:h.flatMap(e=>e.status===`done`&&e.docId!=null?[e.docId]:[])}},[l,c]),cancel:p}}function V(e){return e<1024?`${e} B`:e<1048576?`${(e/1024).toFixed(1)} KB`:`${(e/1048576).toFixed(1)} MB`}function H(e){switch(e.status){case`hashing`:return`hashing`;case`checking`:return`checking`;case`uploading`:return`${Math.round(e.progress*100)}%`;case`linking`:return`saving`;case`done`:return e.resumed?`already uploaded`:`done`;case`error`:return e.error||`failed`;default:return V(e.file.size)}}function U({item:e}){switch(e.status){case`done`:return(0,k.jsx)(a,{className:`h-3.5 w-3.5 shrink-0 text-green-600 dark:text-green-500`});case`error`:return(0,k.jsx)(i,{className:`h-3.5 w-3.5 shrink-0 text-destructive`});case`queued`:return(0,k.jsx)(o,{className:`h-3.5 w-3.5 shrink-0 text-muted-foreground`});default:return(0,k.jsx)(c,{className:`h-3.5 w-3.5 shrink-0 animate-spin text-muted-foreground`})}}function W({item:e}){if(e.status===`queued`)return null;let t=e.status===`done`||e.status===`error`||e.status===`linking`?1:e.status===`checking`?0:e.progress;return(0,k.jsx)(`div`,{className:`h-1 w-full overflow-hidden rounded-full bg-muted`,children:(0,k.jsx)(`div`,{className:u(`h-full rounded-full transition-[width] duration-normal`,e.status===`error`?`bg-destructive`:e.status===`done`?`bg-green-600 dark:bg-green-500`:`bg-primary`),style:{width:`${Math.round(t*100)}%`}})})}function G({items:e,running:t,onRemove:n}){let i=e.filter(e=>e.status===`done`).length,a=e.filter(e=>e.status===`error`).length;return(0,k.jsx)(k.Fragment,{children:e.length>0&&(0,k.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,k.jsxs)(f,{children:[e.length,` file(s)`,i>0&&(0,k.jsxs)(`span`,{className:`ml-1 text-muted-foreground`,children:[`— `,i,` done`,a>0?`, ${a} failed`:``]})]}),(0,k.jsx)(`ul`,{className:`max-h-48 space-y-1 overflow-y-auto`,children:e.map(e=>(0,k.jsxs)(`li`,{className:`flex flex-col gap-1 rounded border border-input px-2 py-1 text-sm`,children:[(0,k.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,k.jsx)(U,{item:e}),(0,k.jsx)(`span`,{className:`flex-1 truncate`,title:e.file.name,children:e.file.name}),(0,k.jsx)(`span`,{className:u(`shrink-0 text-xs`,e.status===`error`?`text-destructive`:`text-muted-foreground`),title:e.status===`error`?e.error:void 0,children:H(e)}),!t&&e.status!==`done`&&(0,k.jsx)(`button`,{type:`button`,onClick:()=>n(e.id),className:`text-muted-foreground hover:text-foreground`,"aria-label":`Remove ${e.file.name}`,children:(0,k.jsx)(r,{className:`h-3.5 w-3.5`})})]}),(0,k.jsx)(W,{item:e})]},e.id))})]})})}function K({items:e,running:t,onCancel:n}){return(0,k.jsxs)(`div`,{className:`space-y-4 overflow-y-auto p-4`,children:[(0,k.jsx)(`h2`,{className:`text-sm font-medium`,children:`Uploading files`}),!t&&(0,k.jsx)(`p`,{role:`status`,className:`text-sm text-muted-foreground`,children:`Preparing / finishing upload…`}),(0,k.jsx)(G,{items:e,running:!0,onRemove:()=>{}}),(0,k.jsx)(d,{variant:`outline`,size:`sm`,disabled:!t,onClick:n,children:`Cancel upload`})]})}export{F as a,O as c,L as i,K as n,P as o,B as r,j as s,G as t};
@@ -0,0 +1 @@
1
+ import{o as e}from"./rolldown-runtime-C0FnF6B9.js";import{l as t,u as n}from"./code-editor-BOIngd5F.js";import{_ as r,g as i,h as a}from"./chunk-62JRHF6Z-vspAGgtK.js";import{t as o}from"./socket-CtH3EU9m.js";import{n as s}from"./use-toast-BlLDqSUO.js";import{o as c,s as l}from"./LinkToCard-CKVi4Nrg.js";import{B as u,Lt as d,W as ee,_n as te,yn as f}from"./workspace-C5V-ZCOE.js";import{r as ne}from"./document-list-J63eer10.js";import{n as re}from"./use-toolbox-Ck_cLGgf.js";import{E as ie,_ as ae,a as oe,b as se,i as ce,l as le,o as ue}from"./context-t3rdtGUB.js";import{i as de}from"./color-DFEH4BfK.js";import{t as fe}from"./geo-CZfs0E-x.js";import{a as pe,i as me,o as he}from"./workspace-BydSRtST.js";import{i as ge}from"./use-menu-DIP1zh7I.js";import{a as _e,c as ve,i as ye,l as be,n as xe,o as Se,r as Ce,s as we,t as Te,u as Ee}from"./tree-folders-BMqMmyq7.js";import{t as De}from"./use-workspace-identity-CSkRwVyo.js";var p=e(n(),1),m=t();function Oe(e,t){if(!e||!t)return`/`;let n=`${t}://`;if(!e.startsWith(n))return`/`;let r=e.slice(n.length).replace(/^\/+/,``).replace(/\/+$/,``);return r?`/${r}`:`/`}function h(){let{contextId:e}=r(),t=a(),n=i(),h=new URLSearchParams(t.search).get(`ownerId`)||void 0,g=(0,p.useMemo)(()=>{let e=new URLSearchParams(t.search),n=e.getAll(`q`).map(e=>e.trim()).filter(Boolean),r=(e.get(`search`)||``).trim();return n.length?n:r?[r]:[]},[t.search]),{showToast:_,showProgress:ke}=s(),{state:v,saveFilters:Ae,setSort:je,setAccentColor:y,setMapDocuments:b}=re(),{openM1Drawer:Me,openM2Drawer:Ne,goBack:Pe}=ge(),x=v.filters.features.allOf,Fe=v.filters.features.anyOf,Ie=v.filters.features.noneOf,Le=[...me(v.filters.timeline),...pe(v.filters.geo),...he(v.filters.lens,v.filters.geo.includeUnlocated)],S=JSON.stringify({a:x,b:Fe,c:Ie,d:Le,ids:v.filters.lens.ids,sort:v.filters.sort,geoSelection:v.geoSelection,includeUnlocated:v.filters.geo.includeUnlocated}),C=(0,p.useMemo)(()=>JSON.parse(S),[S]),[w,T]=(0,p.useState)(null),[Re,ze]=(0,p.useState)(!0),[Be,Ve]=(0,p.useState)(null),[E,D]=(0,p.useState)([]),[He,Ue]=(0,p.useState)(!1),[We,O]=(0,p.useState)(0),[Ge,Ke]=(0,p.useState)([]),[k,A]=(0,p.useState)(1),[j,qe]=(0,p.useState)(50),[M,N]=(0,p.useState)(g),[P,F]=(0,p.useState)(!1),[I,L]=(0,p.useState)(null),[R,Je]=(0,p.useState)(!1),z=(0,p.useRef)(!1),B=I?.id===w?.id&&I?.url===w?.url?I?.path:null,Ye=new URLSearchParams(t.search).get(`layer`),V=!!h,Xe=De(V?void 0:w?.workspaceName||w?.workspaceId),H=w?Oe(w.url,w.workspaceName):`/`,Ze=Ye?`context-layer`:`context`,U=!v.liveEnabled&&typeof w?.metadata?.toolboxSearchQuery==`string`?w.metadata.toolboxSearchQuery:``,W=V?null:w?.workspaceName??null,[Qe,$e]=(0,p.useState)(null);(0,p.useEffect)(()=>{if(!W)return;let e=!1;return ee(W,f).then(t=>{e||$e({key:W,tree:t})}).catch(()=>{e||$e({key:W,tree:null})}),()=>{e=!0}},[W]);let G=W&&Qe?.key===W?Qe.tree:null,et=!Ye&&!V&&G?H===`/`?G:u(G,H):null,tt=!Ye&&!V&&M.length===0,nt=(0,p.useMemo)(()=>tt?Te(G,H):[],[tt,G,H]),K=`${w?.workspaceName??``}\0${H}`,[q,rt]=(0,p.useState)(null),J=q?.key===K?q.views:we(et?.metadata),Y=q?.key===K?q.activeId:J[0]?.id??_e.id,X=J.find(e=>e.id===Y)??J[0]??_e,Z=Se(X);Ee(be({workspace:w?.workspaceName||w?.workspaceId||null,treeNameOrId:v.activeTreeName,path:H,contextId:e??null,scope:`context`},{...v.filters,features:{...v.filters.features,allOf:Z?[...x,Z]:x}},v.geoSelection,M));let it=e=>{A(1),rt({key:K,views:J,activeId:e})},at=(e,t)=>{t&&t!==Y&&A(1),rt({key:K,views:e,activeId:t??Y}),w?.workspaceName&&te(w.workspaceName,H,{metadata:{...et?.metadata??{},views:e}},f).catch(()=>{_({title:`View not saved`,description:`Could not persist views to the layer`,variant:`destructive`})})},ot=(0,p.useRef)(null);(0,p.useEffect)(()=>()=>ot.current?.abort(),[]);let Q=(0,p.useCallback)(async()=>{if(!e)return;ot.current?.abort();let t=new AbortController;ot.current=t,Ue(!0);try{let n=await ue(e,Z?[...C.a,Z]:C.a,C.d,{...C.sort,geoSelection:C.geoSelection,includeUnlocated:C.includeUnlocated,ids:C.ids,signal:t.signal,limit:j,page:k,queries:M.length?M:void 0,anyOf:C.b,noneOf:C.c,applyContextSpec:!1},h);if(t.signal.aborted)return;D(n),O(n.totalCount||n.count||n.length)}catch(e){if(t.signal.aborted)return;_({title:`Error`,description:e instanceof Error?e.message:`Failed to fetch documents`,variant:`destructive`}),D([]),O(0)}finally{t.signal.aborted||Ue(!1)}},[e,k,j,h,M,C,_,Z]),st=(0,p.useCallback)(async()=>{if(e){ze(!0);try{let t=V?await oe(e,h):await oe(e);if(!t)throw Error(`No context data received.`);let n=t.workspace,r=t.workspaceId||(typeof n==`string`?n:n?.id)||``,i=t.workspaceName||(typeof n==`string`?n:n?.name)||``;T({id:t.id,userId:t.userId,url:t.url,baseUrl:t.baseUrl||null,path:t.path||null,pathArray:t.pathArray||[],workspaceId:r,workspaceName:i,acl:t.acl||{},createdAt:t.createdAt,updatedAt:t.updatedAt,locked:t.locked||!1,serverContextArray:t.serverContextArray||[],clientContextArray:t.clientContextArray||[],contextBitmapArray:t.contextBitmapArray||[],featureBitmapArray:t.featureBitmapArray||[],filterArray:t.filterArray||[],pendingUrl:t.pendingUrl||null,description:t.description||null,metadata:t.metadata||{},name:t.name??null,color:t.color??null,icon:t.icon??null}),Ve(null)}catch(t){let n=t instanceof Error?t.message:`Failed to fetch context ${e}`;Ve(n),T(null),_({title:`Error`,description:n,variant:`destructive`})}ze(!1)}},[e,h,V,_]);(0,p.useEffect)(()=>{st()},[st]);let ct=de(w?.color)||null;(0,p.useEffect)(()=>(y(ct),()=>y(null)),[ct,y]);let lt=v.geoSelection,ut=w?.workspaceName||w?.workspaceId||null;(0,p.useEffect)(()=>{b(E,ut)},[E,ut,b]),(0,p.useEffect)(()=>()=>b([]),[b]);let dt=(0,p.useMemo)(()=>lt?E.filter(e=>fe(e,lt,v.filters.geo.includeUnlocated)):E,[E,lt,v.filters.geo.includeUnlocated]),ft=w?.id,pt=w?.url;(0,p.useEffect)(()=>{ft&&Q()},[ft,pt,Q]),(0,p.useEffect)(()=>{let e=()=>Q();return window.addEventListener(`workspace:documents:refresh`,e),()=>window.removeEventListener(`workspace:documents:refresh`,e)},[Q]);let[mt,ht]=(0,p.useState)(S);mt!==S&&(ht(S),A(1));let[gt,_t]=(0,p.useState)(e);gt!==e&&(_t(e),A(1),F(!1));let[vt,yt]=(0,p.useState)(g);vt!==g&&(yt(g),N(g),A(1));let[bt,xt]=(0,p.useState)({urlSearchQueries:g,ignoreSavedSearch:P,savedContextSearchQuery:U});(bt.urlSearchQueries!==g||bt.ignoreSavedSearch!==P||bt.savedContextSearchQuery!==U)&&(xt({urlSearchQueries:g,ignoreSavedSearch:P,savedContextSearchQuery:U}),!new URLSearchParams(t.search).has(`q`)&&!g.length&&!P&&(N(U?[U]:[]),A(1)));let $=(0,p.useCallback)(e=>{let r=new URLSearchParams(t.search);r.delete(`q`),r.delete(`search`);for(let t of e)r.append(`q`,t);let i=r.toString();n(`${t.pathname}${i?`?${i}`:``}${t.hash}`)},[t.pathname,t.search,t.hash,n]),St=(0,p.useCallback)(e=>{let t=e.trim();if(!t)return;F(!1);let n=M.includes(t)?M:[...M,t];N(n),$(n)},[M,$]),Ct=(0,p.useCallback)(e=>{let t=e<0?[]:M.filter((t,n)=>n!==e);t.length===0&&F(!0),N(t),$(t)},[M,$]),wt=(M[0]||``).trim(),Tt=!!v.activeContextType&&(v.isDirty||wt!==(v.savedSearchQuery||U||``));(0,p.useEffect)(()=>{if(!e)return;let t=`context:${h?`${h}/`:``}${e}`,n=()=>o.emit(`subscribe`,{channel:t}),r=()=>o.emit(`unsubscribe`,{channel:t}),i=o.on(`connect`,n);n();let a=new Map,s=(t,n)=>{let r=Date.now(),i=`${t}:${n?.id||n?.contextId||e}`;return(a.get(i)||0)+1e3>r?!1:(a.set(i,r),!0)},c=t=>{let n=t,r=n?.context||n;(r?.id===e||r?.contextId===e)&&s(`ctx:updated`,r)&&(T(e=>e?{...e,...r}:null),r.url&&Q())},l=t=>{let n=t,r=n?.id||n?.contextId||n?.context?.id,i=n?.url||n?.context?.url;r===e&&typeof i==`string`&&s(`ctx:url`,n)&&(T(e=>e?{...e,url:i}:null),Q())},u=t=>{let n=t;(n?.contextId||n?.id||n?.context?.id)===e&&s(`doc:changed`,n)&&Q()},d=[[`context.updated`,c],[`context:updated`,c],[`context.url.set`,l],[`context:url:set`,l],[`document.inserted`,u],[`document.updated`,u],[`document.removed`,u],[`document.removed.batch`,u],[`document.linked`,u],[`document.unlinked`,u],[`document.linked.batch`,u],[`document.unlinked.batch`,u],[`document.deleted`,u],[`document.deleted.batch`,u]];return d.forEach(([e,t])=>o.on(e,t)),()=>{i(),r(),d.forEach(([e,t])=>o.off(e,t))}},[e,h,Q]);let Et=async e=>{if(w)try{await se(w.id,[e],h,H),D(t=>t.filter(t=>t.id!==e)),O(e=>Math.max(0,e-1)),_({title:`Success`,description:`Document removed from context.`})}catch(e){_({title:`Error`,description:e instanceof Error?e.message:`Failed to remove document`,variant:`destructive`})}},Dt=async e=>{if(w)try{await ce(w.id,[e],h,H),D(t=>t.filter(t=>t.id!==e)),O(e=>Math.max(0,e-1)),_({title:`Success`,description:`Document deleted.`})}catch(e){_({title:`Error`,description:e instanceof Error?e.message:`Failed to delete document`,variant:`destructive`})}},Ot=async e=>{if(w)try{await se(w.id,e,h,H),D(t=>t.filter(t=>!e.includes(t.id))),O(t=>Math.max(0,t-e.length)),_({title:`Success`,description:`${e.length} document(s) removed.`})}catch(e){_({title:`Error`,description:e instanceof Error?e.message:`Failed to remove documents`,variant:`destructive`})}},kt=async e=>{if(w)try{await ce(w.id,e,h,H),D(t=>t.filter(t=>!e.includes(t.id))),O(t=>Math.max(0,t-e.length)),_({title:`Success`,description:`${e.length} document(s) deleted.`})}catch(e){_({title:`Error`,description:e instanceof Error?e.message:`Failed to delete documents`,variant:`destructive`})}},At=e=>{Ke(e),_({title:`Copied`,description:`${e.length} document(s) copied to clipboard`})},jt=async(e,t,n={})=>{if(!w)return!1;let r=ke({title:`Pasting…`,description:`${t.length} document(s) → "${e}"`});try{let i=n.targetTreeName&&!V?await d(w.workspaceName||w.workspaceId,e,t,n.targetTreeName,n.targetTreeType):await ae(w.id,e,t,h);return r.done(i?{title:`Success`,description:`${t.length} document(s) pasted to "${e}"`}:void 0),i&&(Ke([]),await Q()),i}catch(e){return r.fail({title:`Error`,description:e instanceof Error?e.message:`Failed to paste documents`,variant:`destructive`}),!1}},Mt=async(e,t)=>{if(!w)return!1;try{let n=await le(w.workspaceId,t,e);return n&&(ne(w.workspaceName||w.workspaceId,`context`,t),_({title:`Success`,description:`Imported ${e.length} document(s) to "${t}"`})),n}catch(e){return _({title:`Error`,description:e instanceof Error?e.message:`Failed to import documents`,variant:`destructive`}),!1}},Nt=async()=>{if(!w||!B||V||z.current)return;let e={id:w.id,url:w.url,path:B};z.current=!0,Je(!0);try{let t=await ie(e.id,`${w.workspaceName}://${e.path.replace(/^\/+/,``)}`);T(n=>n?.id===e.id&&n.url===e.url?{...n,url:t.url,path:e.path}:n),L(null),A(1),window.dispatchEvent(new CustomEvent(`contexts:refresh`,{detail:{contextId:e.id}})),_({title:`Saved`,description:`Context path updated`})}catch(e){_({title:`Error`,description:e instanceof Error?e.message:`Could not update context path`,variant:`destructive`})}finally{z.current=!1,Je(!1)}};if(Re)return(0,m.jsx)(`div`,{className:`flex items-center justify-center h-full`,children:(0,m.jsxs)(`div`,{className:`text-center space-y-2`,children:[(0,m.jsx)(`div`,{className:`animate-spin rounded-full h-8 w-8 border-b-2 border-primary mx-auto`}),(0,m.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`Loading context...`})]})});if(Be&&!w)return(0,m.jsxs)(`div`,{className:`flex items-center justify-center h-full text-destructive`,children:[`Error: `,Be]});if(!w)return(0,m.jsx)(`div`,{className:`flex items-center justify-center h-full text-muted-foreground`,children:`Context not found.`});let Pt=de(w.color);return(0,m.jsx)(`div`,{className:`flex flex-col h-full min-h-0`,children:(0,m.jsx)(ve,{onBack:Pe,accentColor:Pt,navigationTabs:et?(0,m.jsx)(ye,{views:J,activeId:Y,onSelect:it,onSave:at,accentColor:Pt}):void 0,workspaceLabel:Xe?.label||w.workspaceName||w.workspaceId,workspaceIcon:Xe?.icon,treeName:f,urlType:Ze,urlDisplay:w.url,contextPath:H,workspaceId:w.workspaceName||w.workspaceId,documentSchema:Z,linkTree:G,documents:dt,isLoading:He,totalCount:We,currentPage:k,pageSize:j,onPageChange:A,onPageSizeChange:e=>{qe(e),A(1)},onRemoveDocument:H===`/`?void 0:Et,onDeleteDocument:Dt,onRemoveDocuments:H===`/`?void 0:Ot,onDeleteDocuments:kt,onCopyDocuments:At,onPasteDocuments:jt,onImportDocuments:V?void 0:Mt,pastedDocumentIds:Ge,backendSearchQueries:M,onBackendSearch:St,serverSort:v.filters.sort,onServerSortChange:je,onRemoveBackendQuery:Ct,canSaveChanges:Tt,isSavingChanges:v.isSaving,onSaveChanges:Ae,onBrowseTree:!V&&e?()=>Ne(`contexts`,`detail`,e):void 0,onBrowseWorkspaces:()=>Me(`workspaces`),folders:nt,onOpenFolder:e=>{z.current||L({id:w.id,url:w.url,path:e})},onNavigatePath:V?void 0:e=>{z.current||L({id:w.id,url:w.url,path:e})},contentBanner:B?(0,m.jsxs)(`div`,{className:`border-b bg-warning/10 px-4 py-2`,role:`status`,children:[(0,m.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`Set this context to the selected path? Contents stay at the current path until you apply it.`}),(0,m.jsxs)(`div`,{className:`flex min-w-0 items-center gap-2`,children:[(0,m.jsx)(l,{items:c(B,w.workspaceName),label:`Selected context path`}),(0,m.jsx)(`button`,{type:`button`,disabled:R,onClick:()=>void Nt(),className:`shrink-0 rounded border px-3 py-1 text-sm hover:bg-accent disabled:opacity-50`,children:R?`Setting…`:`Set`}),(0,m.jsx)(`button`,{type:`button`,disabled:R,onClick:()=>L(null),className:`shrink-0 rounded px-2 py-1 text-sm hover:bg-accent disabled:opacity-50`,children:`Cancel`})]})]}):void 0,children:X.kind===`columns`?(0,m.jsx)(Ce,{documents:dt,workspaceId:w.workspaceName||w.workspaceId,columns:X.columns??[],onColumnsChange:e=>at(J.map(t=>t.id===X.id?{...t,columns:e}:t))}):X.kind===`app`&&X.app&&X.app!==`notes`?(0,m.jsx)(xe,{app:X.app,contextId:e,workspaceId:w.workspaceName||w.workspaceId,treeName:f,path:H}):null})})}export{h as default};
@@ -0,0 +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{Kn as o,L as s,Tt as c,Ur as l,Vr as u,X as d,ar as f,gr as p,kt as m,pn as h}from"./ui-CDoK3F3U.js";import{t as g}from"./utils-2pl1SbIp.js";import{t as ee}from"./button-SeUZ_Pvi.js";import{c as _,t as te}from"./api-CA6WiiYM.js";import{t as v}from"./socket-CtH3EU9m.js";import{n as ne}from"./use-toast-BlLDqSUO.js";import{h as y,o as re,s as b}from"./LinkToCard-CKVi4Nrg.js";import{At as x,D as S,G as ie,Gt as C,Kt as w,Lt as ae,W as oe,Y as se,_ as T,_n as ce,a as le,bn as E,gt as D,lt as O,mt as ue,nt as de,rn as fe,rt as pe,u as me,vt as he,w as ge,x as _e,y as ve,zt as ye}from"./workspace-C5V-ZCOE.js";import{n as be,r as xe}from"./use-canvas-pins-BV8AsYCE.js";import{u as Se}from"./ObjectPropertiesCard-D2lrTQqT.js";import{a as Ce,c as k,d as we,f as A,i as Te,l as Ee,o as De,p as Oe,r as ke,w as Ae}from"./document-list-J63eer10.js";import{n as je}from"./use-toolbox-Ck_cLGgf.js";import{i as Me}from"./color-DFEH4BfK.js";import{t as Ne}from"./geo-CZfs0E-x.js";import{a as Pe,i as Fe,n as Ie,o as Le}from"./workspace-BydSRtST.js";import{n as Re,r as ze,t as Be}from"./url-params-n7kU_WZ-.js";import{i as Ve}from"./use-menu-DIP1zh7I.js";import{n as He}from"./last-path-BbXWC3b3.js";import{t as Ue}from"./workspace-area-menu-Y2-IWSxU.js";import{t as We}from"./workspace-content-gate-C54J9Man.js";import{t as Ge}from"./form-panel-3p-ncEVK.js";import{a as Ke,c as qe,i as Je,l as Ye,n as Xe,o as Ze,r as Qe,s as $e,t as et,u as tt}from"./tree-folders-BMqMmyq7.js";import{i as nt,r as rt}from"./query-debug-lD5vbJGi.js";var j=`session.open`,it=`session.set`,at=`session.ids`,ot=`session.materialize`,st=`session.close`,ct=`session.delta`,M=e(n(),1),N=t();function lt(e){let t=we(`backends`,e.path)?.backend;return(0,N.jsx)(ut,{...e},JSON.stringify([e.workspace,t]))}function ut({workspace:e,path:t,onNavigate:n}){let r=we(`backends`,t),i=r.backend,a=r.prefix,[s,l]=(0,M.useState)(null),[u,h]=(0,M.useState)(null),g=(0,M.useRef)(!1),[ee,_]=(0,M.useState)(null),[te,v]=(0,M.useState)(null),[ne,x]=(0,M.useState)(0),[S,ie]=(0,M.useState)(new Set),[C,w]=(0,M.useState)(null),ae=(0,M.useCallback)(()=>x(e=>e+1),[]),[oe,se]=(0,M.useState)(t);oe!==t&&(se(t),ie(new Set),w(null),v(null),_(null));let T=s?.revision!==ne,ce=T?[]:s.items,le=T?[]:s.backends,E=s?.days;(0,M.useEffect)(()=>{let t=!1;return(i?k(e,i).then(e=>({...e,backends:[]})):he(e).then(e=>({items:[],days:null,backends:e.filter(e=>e.driver===`file`&&e.enabled!==!1)}))).then(e=>{t||l({...e,revision:ne,error:null})}).catch(e=>{t||l({revision:ne,items:[],backends:[],days:null,error:e instanceof Error?e.message:String(e)})}),()=>{t=!0}},[e,i,ne]),(0,M.useEffect)(()=>{let t=null,n=n=>{let r=n.detail;r?.workspaceName&&r.workspaceName!==e||r?.treeName&&r.treeName!==`backends`||(t||=setTimeout(()=>{t=null,ae()},500))};return window.addEventListener(`workspace:trash:refresh`,n),window.addEventListener(`workspace:tree:refresh`,n),()=>{window.removeEventListener(`workspace:trash:refresh`,n),window.removeEventListener(`workspace:tree:refresh`,n),t&&clearTimeout(t)}},[e,ae]);let D=Oe(ce,a),O=async(t,n)=>{if(!(!i||g.current||T||!n.length)&&!(t===`discard`&&!Ce(i,n))){g.current=!0,h(t),_(null),v(null),w(null);try{let r=await(t===`restore`?Ee:De)(e,i,[...n].sort((e,t)=>t.deletedAt-e.deletedAt).map(e=>e.id)),a=r.filter(e=>!e.ok);v(`${r.length-a.length} item(s) ${t===`restore`?`restored to their original paths`:`permanently deleted`}.`),a.length&&_(`${a.length} item(s) remain in Trash. ${a.slice(0,3).map(e=>`${e.key||`Item`}: ${e.reason===`precondition-failed`||e.reason===`target-exists`?`original path is occupied`:e.message||e.reason}`).join(`; `)}`),ie(new Set)}catch(e){_(e instanceof Error?e.message:String(e))}finally{g.current=!1,h(null),ae()}}},ue=(e,t,n)=>w({x:e,y:t,row:n});return(0,N.jsxs)(`section`,{className:`flex h-full min-h-0 flex-col bg-background`,"aria-label":`Backend Trash`,children:[(0,N.jsxs)(`div`,{className:`flex min-w-0 flex-wrap items-center gap-2 border-b px-4 py-3`,children:[(0,N.jsx)(d,{className:`h-4 w-4 shrink-0 text-muted-foreground`}),(0,N.jsx)(b,{items:re(t,e).map((e,t)=>t===2&&i?{...e,label:i}:e),onNavigate:n,className:`basis-48`}),(0,N.jsxs)(`div`,{className:`ml-auto flex max-w-full flex-wrap items-center gap-2`,children:[S.size>0&&(0,N.jsxs)(N.Fragment,{children:[(0,N.jsxs)(`button`,{className:`flex items-center gap-1 rounded border px-2 py-1 text-sm disabled:opacity-50`,disabled:!!u||T,onClick:()=>void O(`restore`,D.filter(e=>S.has(e.id)).flatMap(e=>e.items)),children:[(0,N.jsx)(c,{className:`h-3.5 w-3.5`}),`Restore selected`]}),(0,N.jsxs)(`button`,{className:`flex items-center gap-1 rounded border px-2 py-1 text-sm text-destructive disabled:opacity-50`,disabled:!!u||T,onClick:()=>void O(`discard`,D.filter(e=>S.has(e.id)).flatMap(e=>e.items)),children:[(0,N.jsx)(d,{className:`h-3.5 w-3.5`}),`Delete selected`]})]}),i&&D.length>0&&(0,N.jsxs)(`button`,{className:`flex items-center gap-1 rounded border px-2 py-1 text-sm text-destructive disabled:opacity-50`,disabled:!!u||T,onClick:()=>void O(`discard`,D.flatMap(e=>e.items)),children:[(0,N.jsx)(d,{className:`h-3.5 w-3.5`}),a?`Empty this folder`:`Empty Trash`]}),(0,N.jsx)(`button`,{title:`Refresh Trash`,"aria-label":`Refresh Trash`,className:`rounded p-2 hover:bg-accent`,disabled:!!u||T,onClick:ae,children:(0,N.jsx)(m,{className:`h-4 w-4 ${T?`animate-spin`:``}`})})]})]}),(0,N.jsxs)(`div`,{className:`border-b px-4 py-2 text-xs text-muted-foreground`,children:[`Restore files and folders to their original paths. Existing files are kept.`,E?` Deleted items are kept for ${E} days.`:``]}),te&&(0,N.jsx)(`p`,{role:`status`,className:`px-4 py-2 text-sm`,children:te}),(ee||s?.error)&&(0,N.jsx)(`p`,{role:`alert`,className:`px-4 py-2 text-sm text-destructive`,children:ee||s?.error}),u&&(0,N.jsx)(`p`,{role:`status`,className:`px-4 py-2 text-sm`,children:u===`restore`?`Restoring…`:`Deleting permanently…`}),(0,N.jsx)(`div`,{className:`min-h-0 flex-1 overflow-auto p-3`,children:T?(0,N.jsx)(`p`,{className:`p-4 text-sm text-muted-foreground`,children:`Loading Trash…`}):i?D.length===0?(0,N.jsx)(`p`,{className:`p-4 text-sm text-muted-foreground`,children:`This Trash folder is empty.`}):(0,N.jsxs)(`table`,{className:`w-full text-left text-sm`,children:[(0,N.jsx)(`thead`,{className:`border-b text-xs text-muted-foreground`,children:(0,N.jsxs)(`tr`,{children:[(0,N.jsx)(`th`,{className:`w-8 p-2`,children:(0,N.jsx)(`input`,{type:`checkbox`,"aria-label":`Select all visible items`,checked:D.length>0&&D.every(e=>S.has(e.id)),onChange:e=>ie(e.target.checked?new Set(D.map(e=>e.id)):new Set)})}),(0,N.jsx)(`th`,{className:`p-2`,children:`Name`}),(0,N.jsx)(`th`,{className:`p-2 max-sm:hidden`,children:`Original path`}),(0,N.jsx)(`th`,{className:`p-2 max-md:hidden`,children:`Deleted`}),(0,N.jsx)(`th`,{className:`p-2`,children:(0,N.jsx)(`span`,{className:`sr-only`,children:`Actions`})})]})}),(0,N.jsx)(`tbody`,{children:D.map(e=>(0,N.jsxs)(`tr`,{className:`border-b border-border/50 hover:bg-accent/50`,onContextMenu:t=>{t.preventDefault(),ue(t.clientX,t.clientY,e)},onDoubleClick:()=>e.navigable&&n(A(i,e.key)),children:[(0,N.jsx)(`td`,{className:`p-2`,children:(0,N.jsx)(`input`,{type:`checkbox`,"aria-label":`Select ${e.name}`,checked:S.has(e.id),disabled:!!u,onChange:t=>ie(n=>{let r=new Set(n);return t.target.checked?r.add(e.id):r.delete(e.id),r})})}),(0,N.jsx)(`td`,{className:`p-2`,children:(0,N.jsxs)(`button`,{className:`flex items-center gap-2 text-left`,onClick:()=>e.navigable&&n(A(i,e.key)),children:[e.directory?(0,N.jsx)(o,{className:`h-4 w-4 shrink-0`}):(0,N.jsx)(f,{className:`h-4 w-4 shrink-0`}),(0,N.jsxs)(`span`,{children:[e.name,e.navigable&&(0,N.jsxs)(`span`,{className:`ml-2 text-xs text-muted-foreground`,children:[e.items.length,` items`]})]})]})}),(0,N.jsx)(`td`,{className:`p-2 text-xs text-muted-foreground max-sm:hidden`,children:e.key}),(0,N.jsx)(`td`,{className:`p-2 text-xs text-muted-foreground max-md:hidden`,children:new Date(e.items.reduce((e,t)=>Math.max(e,t.deletedAt),0)).toLocaleString()}),(0,N.jsx)(`td`,{className:`p-2 text-right`,children:(0,N.jsx)(`button`,{title:`Actions for ${e.name}`,"aria-label":`Actions for ${e.name}`,disabled:!!u,className:`rounded p-2 hover:bg-accent`,onClick:t=>ue(t.clientX,t.clientY,e),children:(0,N.jsx)(p,{className:`h-4 w-4`})})})]},e.id))})]}):(0,N.jsxs)(`div`,{className:`grid gap-2 sm:grid-cols-2 lg:grid-cols-3`,children:[le.map(e=>(0,N.jsxs)(`button`,{onClick:()=>n(A(e.address)),className:`flex items-center gap-3 rounded-lg border p-4 text-left hover:bg-accent`,children:[(0,N.jsx)(d,{className:`h-6 w-6 text-muted-foreground`}),(0,N.jsxs)(`span`,{children:[(0,N.jsx)(`span`,{className:`block text-sm font-medium`,children:e.label||e.address}),(0,N.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:e.address})]})]},e.address)),!le.length&&(0,N.jsx)(`p`,{className:`p-4 text-sm text-muted-foreground`,children:`No file backends are available.`})]})}),C&&(0,N.jsxs)(y,{x:C.x,y:C.y,onClose:()=>w(null),className:`min-w-44 rounded-md border bg-popover p-1 shadow-elevation-3`,children:[C.row.navigable&&(0,N.jsxs)(`button`,{className:`flex w-full items-center gap-2 rounded px-3 py-2 text-sm hover:bg-accent`,onClick:()=>{n(A(i,C.row.key)),w(null)},children:[(0,N.jsx)(o,{className:`h-4 w-4`}),`Open folder`]}),(0,N.jsxs)(`button`,{disabled:!!u,className:`flex w-full items-center gap-2 rounded px-3 py-2 text-sm hover:bg-accent disabled:opacity-50`,onClick:()=>void O(`restore`,C.row.items),children:[(0,N.jsx)(c,{className:`h-4 w-4`}),`Restore `,C.row.directory?`folder`:`file`]}),(0,N.jsxs)(`button`,{disabled:!!u||T,className:`flex w-full items-center gap-2 rounded px-3 py-2 text-sm text-destructive hover:bg-destructive/10 disabled:opacity-50`,onClick:()=>void O(`discard`,C.row.items),children:[(0,N.jsx)(d,{className:`h-4 w-4`}),`Delete permanently`]})]})]})}function dt({workspaceId:e,workspaceName:t}){let[n,r]=(0,M.useState)([]),[i,a]=(0,M.useState)(new Set),o=t=>`${e}:${t.address}:${t.resyncStartedAt||``}`;(0,M.useEffect)(()=>{let t=!1,n=!1,i=!1,a=0,o=new Map,s=new Map,c=(e,t)=>{let n=e.filter(e=>e.address!==t.backend);if(!t.resyncing)return n;let r=e.find(e=>e.address===t.backend)||s.get(t.backend);return[...n,{address:t.backend,config:r?.config,resyncStartedAt:r?.resyncStartedAt||new Date().toISOString(),progress:t.progress??r?.progress}]},l=async()=>{if(n){i=!0;return}n=!0;let u=a;try{let n=await he(e);if(!t){s=new Map(n.map(e=>[e.address,e]));let e=n.filter(e=>e.resyncing);for(let t of o.values())t.version>u&&(e=c(e,t.event));r(e)}}catch{}finally{n=!1,i&&!t&&(i=!1,l())}},u=t=>{t.workspaceId!==e||!t.backend||typeof t.resyncing!=`boolean`||(o.set(t.backend,{version:++a,event:t}),r(e=>c(e,t)))},d=t=>{t.workspaceId===e&&l()};l();let f=v.on(`connect`,l);return v.on(`backend.resync.changed`,u),v.on(`backend.changed`,d),window.addEventListener(`focus`,l),()=>{t=!0,f?.(),v.off(`backend.resync.changed`,u),v.off(`backend.changed`,d),window.removeEventListener(`focus`,l)}},[e]);let c=n.filter(e=>!i.has(o(e)));return c.length?(0,N.jsxs)(`aside`,{"aria-label":`Storage scans for ${t}`,className:`absolute bottom-5 right-5 z-50 w-72 max-w-[calc(100vw-2.5rem)] rounded-lg border bg-popover/95 p-3 text-popover-foreground shadow-lg backdrop-blur`,children:[(0,N.jsxs)(`div`,{role:`status`,className:`mb-2 flex items-center gap-2 text-sm font-medium`,children:[(0,N.jsx)(h,{"aria-hidden":`true`,className:`h-4 w-4 animate-spin`}),(0,N.jsxs)(`span`,{className:`min-w-0 flex-1`,children:[(0,N.jsx)(`span`,{className:`block`,children:`Scanning storage`}),(0,N.jsx)(`span`,{className:`block truncate text-xs font-normal text-muted-foreground`,title:t,children:t})]}),(0,N.jsx)(`button`,{type:`button`,"aria-label":`Hide scan progress for ${t}`,title:`Hide progress; scanning continues`,className:`rounded p-1 hover:bg-muted focus-visible:outline focus-visible:outline-2`,onClick:()=>a(e=>new Set([...e,...c.map(o)])),children:(0,N.jsx)(s,{"aria-hidden":`true`,className:`h-4 w-4`})})]}),(0,N.jsx)(`div`,{className:`max-h-48 space-y-3 overflow-y-auto`,children:c.map(e=>{let{scanned:t=0,total:n=null}=e.progress||{},r=n&&n>0?Math.min(100,Math.round(t/n*100)):null,i=typeof e.config?.label==`string`?e.config.label:e.address;return(0,N.jsxs)(`div`,{children:[(0,N.jsxs)(`div`,{className:`flex items-center justify-between gap-3 text-xs`,children:[(0,N.jsx)(`span`,{className:`truncate`,children:i}),(0,N.jsx)(`span`,{className:`shrink-0 text-muted-foreground`,children:n===null?`${t} files`:`${t} / ${n}`})]}),(0,N.jsx)(`div`,{role:`progressbar`,"aria-label":`Scanning ${i}`,"aria-valuemin":0,"aria-valuemax":100,"aria-valuenow":r??void 0,className:`mt-1.5 h-1 overflow-hidden rounded-full bg-muted`,children:(0,N.jsx)(`div`,{className:`h-full rounded-full bg-primary ${r===null?`animate-pulse`:`transition-all`}`,style:{width:r===null?`35%`:`${r}%`}})})]},e.address)})})]}):null}var ft=e=>e&&typeof e==`object`&&!Array.isArray(e)?e:null;function pt(e){return`/${e}`.replace(/\/+/g,`/`).replace(/\/$/,``)||`/`}function mt(e,t,n){if(e==null)return[];if(Array.isArray(e))return e.flatMap(e=>mt(e,t,n));if(typeof e==`string`)return[{tree:null,kind:t,path:pt(e)}];let r=ft(e);if(!r)return[];let i=r.tree??r.treeId,a=typeof i==`string`?n.get(i)??null:null;return[].concat(r.paths??r.path??`/`).filter(e=>typeof e==`string`).map(e=>({tree:a,kind:t,path:pt(e)}))}function ht(e){let t=[],n=e=>{let n=Number(e);Number.isSafeInteger(n)&&n>0&&t.push(n)};return Array.isArray(e.ids)&&e.ids.forEach(n),Array.isArray(e.documentIds)&&e.documentIds.forEach(n),e.id!=null&&n(e.id),e.documentId!=null&&n(e.documentId),t}function gt(e){let t=new Map;for(let n of e)t.set(n.id,n.name),t.set(n.name,n.name);return t}function _t(e,t,n=new Map){let r=ft(t);if(!r)return{targets:[],ids:[],unknown:!0};if(e.startsWith(`tree.`)){let e=typeof r.treeName==`string`?r.treeName:null,t=r.treeType===`directory`||r.treeType===`context`?r.treeType:null,n=r.contextSpec??r.path;return typeof n==`string`?{targets:[{tree:e,kind:t,path:pt(n)}],ids:ht(r),unknown:!1}:{targets:[],ids:[],unknown:!0}}let i=[...mt(r.context,`context`,n),...mt(r.directory,`directory`,n)],a=ft(r.changed);a&&i.push(...mt(a.context,`context`,n),...mt(a.directory,`directory`,n));let o=ht(r);if(i.length)return{targets:i,ids:o,unknown:!1};let s=r.reason===`content`||r.reason===`relations`;return e.startsWith(`document.updated`)&&s&&o.length?{targets:[],ids:o,unknown:!1}:{targets:[],ids:o,unknown:!0}}function vt(e,t){return e===t||e===`/`||t===`/`||e.startsWith(`${t}/`)||t.startsWith(`${e}/`)}function yt(e,t){if(e.kind&&e.kind!==t.kind||e.tree&&e.tree!==t.tree)return!1;if(t.kind===`context`){let n=e=>pt(e).split(`/`).filter(Boolean).map(e=>e.normalize(`NFKC`).trim().replace(/\s+/g,` `).replace(/[^\p{L}\p{N}\p{M} .+_@-]/gu,`_`).replace(/_+/g,`_`).toLowerCase()||`_`),r=new Set(n(e.path)),i=n(t.path);return r.size===0||i.length===0||i.some(e=>r.has(e))}return vt(e.path,t.path)}function bt(e){return _t(`tree.refresh`,{treeName:e?.treeName,path:e?.path||`/`})}function xt(e,t,n){if(e.unknown||e.targets.length&&(t.wholeWorkspace||e.targets.some(e=>yt(e,t))))return!0;if(e.ids.length&&n){let t=n instanceof Set?n:new Set(n);if(e.ids.some(e=>t.has(e)))return!0}return!1}function St(e,t,n={}){return v.request(j,{workspace:e,specs:t,opts:n})}function Ct(e,t,n){return v.request(it,{sessionId:e,label:t,spec:n})}function wt(e){return v.request(at,{sessionId:e})}function P(e,t={}){return v.request(ot,{sessionId:e,...t})}function Tt(e){return v.request(st,{sessionId:e})}function F(e){return v.on(ct,e)}var I=100;function Et({workspaceRef:e,specs:t,opts:n,enabled:r=!0}){let[i,a]=(0,M.useState)([]),[o,s]=(0,M.useState)(0),[c,l]=(0,M.useState)(null),[u,d]=(0,M.useState)(null),f=(0,M.useRef)([]),p=(0,M.useRef)(new Map),m=(0,M.useRef)(null),h=(0,M.useRef)(null),g=(0,M.useRef)(null),ee=(0,M.useRef)({}),_=(0,M.useRef)(null),te=(0,M.useMemo)(()=>JSON.stringify(t),[t]),ne=(0,M.useMemo)(()=>JSON.stringify(n??{}),[n]),y=(0,M.useCallback)(()=>{let e=p.current;a(f.current.map(t=>e.get(t)).filter(Boolean))},[]),re=(0,M.useCallback)(async e=>{let t=h.current;if(!t||e.length===0)return[];let n=[];for(let r=0;r<e.length;r+=I){let i=e.slice(r,r+I),a=await de(t,`/`,[],{ids:i,scope:`workspace`,limit:i.length});n.push(...a.payload||[])}return n},[]),b=(0,M.useCallback)(async(e,t,n)=>{if(t.length>0){let e=new Set(t);f.current=f.current.filter(t=>!e.has(t));for(let t of e)p.current.delete(t)}let r=e.filter(e=>!p.current.has(e)),i=new Set(f.current);for(let t of e)i.has(t)||(f.current.push(t),i.add(t));if(n!==null&&s(n),y(),r.length===0)return;let a=await re(r);for(let e of a)p.current.set(e.id,e);let o=new Set(a.map(e=>e.id)),c=r.filter(e=>!o.has(e));if(c.length>0){let e=new Set(c);f.current=f.current.filter(t=>!e.has(t))}y()},[re,y]),x=(0,M.useCallback)(async(e,t)=>{let n=e??[],r=new Set(n);f.current=f.current.filter(e=>r.has(e));for(let e of p.current.keys())r.has(e)||p.current.delete(e);let i=new Set(f.current),a=n.filter(e=>!i.has(e));await b(a,[],t)},[b]);(0,M.useEffect)(()=>{if(h.current=e??null,!r||!e)return;let t=!1,n=null,i=async()=>{try{let r=await St(e,JSON.parse(te),JSON.parse(ne));if(t){Tt(r.sessionId).catch(()=>{});return}n=r.sessionId,m.current=r.sessionId,l(r.sessionId),d(null),f.current=[],p.current=new Map,await x(r.ids,r.count)}catch(e){if(t)return;d(e instanceof Error?e.message:`Failed to open query session`),l(null),m.current=null}};i();let o=v.on(`connect`,()=>{i()});return()=>{t=!0,o?.();let e=n??m.current;e&&Tt(e).catch(()=>{}),m.current=null,f.current=[],p.current=new Map,l(null),a([]),s(0)}},[e,te,ne,r]),(0,M.useEffect)(()=>{if(!c)return;let e=F(e=>{if(e.sessionId===c){if(g.current!==null){_.current?.(g.current,ee.current);return}e.ids===void 0?b(e.added??[],e.removed??[],e.count):x(e.ids,e.count)}});return()=>{e?.()}},[c,b,x]);let S=(0,M.useCallback)(async()=>{let e=m.current;if(e)try{let t=await wt(e);await x(t.ids,t.count)}catch{}},[x]),ie=(0,M.useCallback)(async(e,t)=>{let n=m.current;if(!n)throw Error(`No open query session`);let r=await Ct(n,e,t);if(g.current!==null){await _.current?.(g.current,ee.current);return}await x(r.ids,r.count)},[x]),C=(0,M.useCallback)(async(e,t={})=>{let n=m.current;if(!n)throw Error(`No open query session`);if(g.current=e,ee.current=t,e===null){await S();return}let r=await P(n,{match:e,...t});for(let e of r.documents)p.current.set(e.id,e);f.current=r.ids,s(r.totalCount),y()},[y,S]);(0,M.useEffect)(()=>{_.current=C},[C]);let w=(0,M.useCallback)(async(e,t,n={})=>{let r=m.current;if(!r)throw Error(`No open query session`);let i=await P(r,{match:t,limit:n.limit??100,...n.mode?{mode:n.mode}:{}});for(let e of i.documents)p.current.set(e.id,e);let a=await Ct(r,e,{ids:i.ids});return await x(a.ids,a.count),i.ids},[x]);return{documents:i,count:o,ready:c!==null,error:u,setCue:ie,resync:S,rank:C,rankAndPin:w}}function Dt({data:e,className:t}){let[n,r]=(0,M.useState)(!0),{rows:i,gapIndex:a,span:o}=(0,M.useMemo)(()=>{let t=[...e.distances].sort((e,t)=>e.distance-t.distance),n=[];for(let e=1;e<t.length;e++)n.push(t[e].distance-t[e-1].distance);let r=n.length?[...n].sort((e,t)=>e-t)[Math.floor(n.length/2)]:0,i=-1,a=0;for(let e=0;e<n.length;e++)n[e]>a&&(a=n[e],i=e+1);let o=i>0&&a>=Math.max(r*4,1e-6),s=t[0]?.distance??0,c=t[t.length-1]?.distance??0;return{rows:t,gapIndex:o?i:-1,span:{first:s,last:c,biggest:a,median:r}}},[e.distances]);if(i.length===0)return(0,N.jsxs)(`div`,{className:g(`rounded-md border border-dashed border-border px-3 py-2 text-xs text-muted-foreground`,t),children:[`Query debug: no image distances for “`,e.query,`”. The dense side returned nothing: either no photos are embedded in this scope, or the image space is not ready.`]});let s=a>0?i[a].distance:null;return(0,N.jsxs)(`div`,{className:g(`rounded-md border border-border bg-muted/30 text-xs`,t),children:[(0,N.jsxs)(`button`,{type:`button`,onClick:()=>r(e=>!e),className:`flex w-full items-center gap-1.5 px-3 py-2 text-left font-medium`,children:[n?(0,N.jsx)(l,{className:`h-3.5 w-3.5`}):(0,N.jsx)(u,{className:`h-3.5 w-3.5`}),`Query debug`,(0,N.jsxs)(`span`,{className:`font-normal text-muted-foreground`,children:[`: image distances for “`,e.query,`” (`,i.length,` nearest, unfloored)`]})]}),n&&(0,N.jsxs)(`div`,{className:`space-y-2 border-t border-border px-3 py-2`,children:[(0,N.jsxs)(`p`,{className:`text-[11px] text-muted-foreground`,children:[`Best-first cosine distance (0 = identical). Scroll to where the photos stop being relevant and set the image relevance floor just above that value in Settings → Database → Search tuning.`,s===null?(0,N.jsxs)(N.Fragment,{children:[` `,(0,N.jsx)(`span`,{className:`text-amber-600 dark:text-amber-500`,children:`No boundary in this window`}),`; the distances step evenly (typical Δ`,o.median.toFixed(4),`), so there is nothing here to set a floor from. Relevance probably ends further down the list than this window reaches, or the model is not separating this query at all.`]}):(0,N.jsxs)(N.Fragment,{children:[` A jump at `,(0,N.jsx)(`span`,{className:`font-mono`,children:s.toFixed(4)}),` (Δ`,o.biggest.toFixed(4),`, vs typical Δ`,o.median.toFixed(4),`) stands out (a likely boundary).`]})]}),(0,N.jsx)(`div`,{className:`max-h-56 overflow-y-auto`,children:(0,N.jsx)(`table`,{className:`w-full font-mono text-[11px]`,children:(0,N.jsx)(`tbody`,{children:i.map((e,t)=>(0,N.jsxs)(`tr`,{className:g(`border-b border-border/40 last:border-0`,t===a&&`border-t-2 border-t-amber-500/70`),children:[(0,N.jsx)(`td`,{className:`py-0.5 pr-3 text-muted-foreground`,children:t+1}),(0,N.jsxs)(`td`,{className:`py-0.5 pr-3`,children:[`#`,e.id]}),(0,N.jsx)(`td`,{className:`py-0.5 tabular-nums`,children:e.distance.toFixed(4)}),t===a&&(0,N.jsx)(`td`,{className:`py-0.5 pl-2 font-sans text-[10px] text-amber-600 dark:text-amber-500`,children:`← biggest gap`})]},e.id))})})}),(0,N.jsxs)(`p`,{className:`text-[11px] text-muted-foreground`,children:[`Range `,o.first.toFixed(4),` – `,o.last.toFixed(4),` (spread `,(o.last-o.first).toFixed(4),`) over `,i.length,` rows. Absolute values shift with the model and are not comparable across models. After a re-embed every floor has to be picked again. A spread this narrow relative to the range means ranking is doing the work, not distance.`]})]})]})}var Ot=new Map;function L(e,t,n){return`${e}\0${t}\0${n}`}function kt(e,t,n,r,i,a,o=``,s=``,c=`path`){return`${L(e,t,n)}\0${r}\0${i}\0${a}\0${o}\0${s}\0${c}`}function R(e,t,n){let r=L(e,t,n);for(let e of Ot.keys())e.startsWith(r)&&Ot.delete(e)}function At(e,t){let n=`${e}\0`;for(let[e,r]of Ot){if(!e.startsWith(n))continue;let[,i,a,,,,,,o=`path`]=e.split(`\0`);xt(t,{tree:i,kind:E(i),path:a,wholeWorkspace:o.startsWith(`workspace`)},r.documents.map(e=>Number(e.id)))&&Ot.delete(e)}}function jt(e,t){At(t?.workspaceName??e,bt(t))}function Mt(){let{workspaceName:e}=r();return e?(0,N.jsx)(We,{workspaceName:e,children:(0,N.jsx)(z,{})}):null}function z(){let{workspaceName:e,treeName:t}=r(),n=a(),o=i(),{showToast:s,showProgress:c}=ne(),l=new URLSearchParams(n.search),u=(()=>{let e=l.getAll(`q`).map(e=>e.trim()).filter(Boolean);if(e.length>0)return e;let t=(l.get(`search`)||``).trim();return t?[t]:[]})(),[d,f]=(0,M.useState)(null),[p,m]=(0,M.useState)(!0),[h,y]=(0,M.useState)([]),[re,b]=(0,M.useState)(!1),[Ce,k]=(0,M.useState)(0),A=rt(),[Ee,De]=(0,M.useState)(null),[Oe,We]=(0,M.useState)(A);Oe!==A&&(We(A),A||De(null));let[j,it]=(0,M.useState)(`path`),[at,ot]=(0,M.useState)(!1),[st,ct]=(0,M.useState)(null),[ut,ft]=(0,M.useState)(null),[pt,mt]=(0,M.useState)(``),[ht,vt]=(0,M.useState)(!1),[yt,St]=(0,M.useState)(!1),[Ct,wt]=(0,M.useState)(!1),[P,Tt]=(0,M.useState)(null),[F,I]=(0,M.useState)(1),[L,Mt]=(0,M.useState)(50),[z,Nt]=(0,M.useState)(u),[Ft,It]=(0,M.useState)(null),{state:B,saveFilters:Lt,setSort:Rt,setAccentColor:zt,setMapDocuments:Bt}=je(),Vt=B.filters.features.allOf,Ht=B.filters.features.anyOf,Ut=B.filters.features.noneOf,Wt=Fe(B.filters.timeline),Gt=Pe(B.filters.geo),Kt=Le(B.filters.lens,B.filters.geo.includeUnlocated),V=B.filters.lens.ids,qt=[...Wt,...Gt,...Kt],Jt=B.filters.sort??Ie,Yt=JSON.stringify({a:Vt,b:Ht,c:Ut,d:qt,i:V,s:Jt}),Xt=JSON.stringify({a:Vt,b:Ht,c:Ut,d:qt,s:Jt}),H=Re(n.pathname).path,U=t??`context`,W=U===`backends`,[Zt,Qt]=(0,M.useState)([]);(0,M.useEffect)(()=>{!W||!e||he(e).then(Qt).catch(()=>Qt([]))},[W,e]);let $t=W?le(H,Zt):null,[en,tn]=(0,M.useState)(!1),nn=`${U}\0${H}`,[rn,an]=(0,M.useState)(nn);rn!==nn&&(an(nn),tn(!1));let G=l.get(`layer`)===`1`,K=l.get(`layerId`)||null,[q,on]=(0,M.useState)(null),[J,sn]=(0,M.useState)(null),cn=(0,M.useRef)(null);(0,M.useEffect)(()=>{cn.current=J},[J]);let[ln,un]=(0,M.useState)(`left`),[dn,fn]=(0,M.useState)([]),{openM1Drawer:pn,openM2Drawer:mn,goBack:hn}=Ve(),[gn,_n]=(0,M.useState)([]),Y=(0,M.useMemo)(()=>{if(!q||H===`/`||G)return null;let e=H.split(`/`).filter(Boolean),t=q;for(let n of e)if(t=t?.children?.find(e=>e.name===n)??null,!t)return null;return t},[q,H,G]),X=Y?.type===`canvas`?`canvas`:null,vn=(0,M.useRef)(null);(0,M.useEffect)(()=>{!e||!q||G||vn.current===`${e}/${U}`&&(H!==`/`&&!Y||He(e,U,H))},[e,q,G,H,Y,U]);let yn=(0,M.useMemo)(()=>G||j===`workspace`||z.length>0?[]:et(q,H),[q,H,G,j,z]),bn=G?null:H===`/`?q:Y,Z=Ae(),xn=`${U}\0${H}`,[Sn,Cn]=(0,M.useState)(null),wn=Sn?.key===xn?Sn.views:$e(bn?.metadata),Tn=Z?.pinned&&Z.view?[Z.view,...wn.filter(e=>e.id!==Z.view.id)]:wn,En=Z?.pinned&&Z.view?Z.view.id:Sn?.key===xn?Sn.activeId:Tn[0]?.id??Ke.id,Q=Tn.find(e=>e.id===En)??Tn[0]??Ke;(0,M.useEffect)(()=>{Z?.selectView(Q)},[Q,Z]);let Dn=W?void 0:Z?.schema??Ze(Q),On=Dn?[...Vt,Dn]:Vt;tt(Ye({workspace:e??null,treeNameOrId:U,treeType:E(U),path:H,scope:j===`workspace`?`workspace`:G?`layer`:`path`,layerId:G?K:void 0,unfiledOnly:en},{...B.filters,features:{...B.filters.features,allOf:On}},B.geoSelection,z));let kn=e=>{let t=Tn.find(t=>t.id===e);t&&Z?.selectView(t),I(1),fn([]),Cn({key:xn,views:Tn,activeId:e})},An=(t,n)=>{n&&n!==En&&(I(1),fn([]));let r=t.find(e=>e.id===(n??En));r&&Z?.selectView(r),Cn({key:xn,views:t,activeId:n??En}),ce(e,H,{metadata:{...bn?.metadata??{},views:t}},U).catch(()=>{s({title:`View not saved`,description:`Could not persist views to the layer`,variant:`destructive`})})},jn=X===`canvas`&&typeof Y?.querySpec?.query==`string`?Y.querySpec.query:``,Mn=X===`canvas`?{label:Y?.label,description:Y?.description,color:Y?.color}:null,{isPinned:Nn,pin:Pn,unpin:Fn,pins:In}=be(),Ln=d?.name,$=(0,M.useMemo)(()=>Ln&&X===`canvas`&&!G?{workspaceName:Ln,treeName:U,path:H}:null,[Ln,X,G,U,H]),Rn=$?Nn($):!1,zn=Y?.id,Bn=Y?.label,Vn=(0,M.useCallback)(async()=>{if($)try{let e=In.find(e=>e.workspaceName===$.workspaceName&&e.treeName===$.treeName&&e.path===$.path);e?await Fn(e.id):await Pn({...$,layerId:zn,label:Bn})}catch(e){console.error(`Failed to update home pins:`,e)}},[$,In,Pn,Fn,zn,Bn]),Hn=e?`${e}://${H===`/`?``:H.replace(/^\//,``)}`:``,Un=Me(d?.color)||null;(0,M.useEffect)(()=>(zt(Un),()=>zt(null)),[Un,zt]);let Wn=(0,M.useCallback)(async t=>{let n=V;if(t?.anyOf?.length&&Ht.length&&(n=((await ie(e,H,U,{limit:0,anyOf:Ht,ids:V,applyCanvasSpec:!1})).payload||[]).map(e=>e.id),!n.length))return{payload:[],count:0,totalCount:0};let r=await ie(e,H,U,{limit:t?.limit,offset:t?.offset,page:t?.page,sortBy:t?.sortBy,order:t?.order,allOf:[...Vt,...t?.allOf??[]],anyOf:t?.anyOf?.length?t.anyOf:Ht,noneOf:Ut,filters:qt,ids:n,queries:[...z,...t?.queries??[],...t?.q?[t.q]:[]],applyCanvasSpec:!1});return{payload:r.payload||[],count:r.count??void 0,totalCount:r.totalCount??void 0}},[e,H,U,Yt,z]);(0,M.useEffect)(()=>{e&&(async()=>{m(!0);try{let t=await te.get(`${_.workspaces}/${e}`),n;n=t&&`workspace`in t?t.workspace:t,f(n)}catch(t){let n=t instanceof Error?t.message:`Failed to fetch workspace ${e}`;s({title:`Error`,description:n,variant:`destructive`}),f(null)}finally{m(!1)}})()},[e,s]),(0,M.useEffect)(()=>{let e=e=>{let t=e.detail?.workspace;t&&f(e=>e&&(t===e.name||t===e.id)&&e.status!==`active`?{...e,status:`active`}:e)};return window.addEventListener(`workspace:autostarted`,e),()=>window.removeEventListener(`workspace:autostarted`,e)},[]);let Gn=(V?.length??0)>0&&!G&&!(en&&$t)&&z.length<=1,{documents:Kn,count:qn,ready:Jn,setCue:Yn,resync:Xn,rank:Zn}=Et({workspaceRef:e,specs:(0,M.useMemo)(()=>{let e={features:{allOf:On,anyOf:Ht,noneOf:Ut},filters:qt};return j!==`workspace`&&(E(U)===`directory`?e.directory={tree:U,path:H}:e.context=H),[{label:`scope`,spec:e}]},[Xt,H,U,j,Dn]),opts:(0,M.useMemo)(()=>({mode:`live`,debounceMs:150}),[]),enabled:Gn}),Qn=Gn&&Jn,$n=(0,M.useRef)(!1);(0,M.useEffect)(()=>{$n.current=Qn},[Qn]);let er=z.length===1?z[0].trim():``;(0,M.useEffect)(()=>{Jn&&Zn(er?{text:er}:null,{limit:L,offset:(F-1)*L}).catch(()=>{})},[Jn,er,L,F,Zn]);let tr=(V??[]).join(`,`);(0,M.useEffect)(()=>{Jn&&Yn(`lens`,{ids:V??[]}).catch(()=>{})},[Jn,tr,Yn,V]);let nr=Qn?Kn:h,rr=Qn?qn:Ce,ir=(0,M.useRef)(new Set);(0,M.useEffect)(()=>{ir.current=new Set(nr.map(e=>Number(e.id)))},[nr]);let ar=B.geoSelection;(0,M.useEffect)(()=>{Bt(nr,d?.name??null)},[nr,d?.name,Bt]),(0,M.useEffect)(()=>()=>Bt([]),[Bt]);let or=(0,M.useMemo)(()=>ar?nr.filter(e=>Ne(e,ar,B.filters.geo.includeUnlocated)):nr,[nr,ar,B.filters.geo.includeUnlocated]),sr=me(H,On,{treeName:U,treeType:E(U),scope:j,queries:z,anyOf:Ht,noneOf:Ut,filters:qt,ids:V,layerId:G&&K?K:void 0}),cr=JSON.stringify([e,sr]),[lr,ur]=(0,M.useState)(``),[dr,fr]=(0,M.useState)(!1),pr=(0,M.useRef)(!1),mr=re||dr||lr!==cr||Qn||!!ar,hr=(0,M.useRef)(0),gr=(0,M.useRef)(null);(0,M.useEffect)(()=>()=>{hr.current++,gr.current=null},[]);let _r=(0,M.useRef)(``),vr=(0,M.useCallback)(async t=>{if(!e)return;if(we(U,H)){hr.current++,gr.current=null,_r.current=``,y([]),k(0),b(!1);return}if($n.current)return;let n=`${en&&$t?`${j}:unfiled`:j}:${Dn??``}`,r=(V?.length??0)>0,i=kt(e,U,H,F,L,z.join(`␟`),Xt,G&&K?K:``,n),a=r&&i===_r.current;_r.current=i;let o=kt(e,U,H,F,L,z.join(`␟`),Yt,G&&K?K:``,n),c=`${o}\0${A}`;if(t?.silent&&gr.current?.key===c){gr.current.refreshPending=!0;return}let l=++hr.current,u=t?.silent||r||A?void 0:Ot.get(o);u&&(y(u.documents),k(u.totalCount),ur(cr),b(!1)),(t?.silent??(a||!!u))||b(!0);let d={key:c,refreshPending:!1};gr.current=d;try{let t;if(en&&$t)t=await D(e,$t.driver,$t.address,{linked:!1,limit:L,offset:(F-1)*L});else if(G&&K&&j!==`workspace`)t=await pe(e,U,K,{limit:L,page:F,queries:z,allOf:On,anyOf:Ht,noneOf:Ut,filters:qt,ids:V,sortBy:Jt.sortBy||void 0,order:Jt.order});else{let n=E(U);t=await de(e,H,On,{limit:L,page:F,treeName:U,treeType:n,queries:z,anyOf:Ht,noneOf:Ut,filters:qt,ids:V,sortBy:Jt.sortBy||void 0,order:Jt.order,scope:j,debug:A&&z.length>0,debugLimit:200})}let n=t.payload||[],i=t.totalCount||t.count||0;if(!r&&!d.refreshPending&&Ot.set(o,{documents:n,totalCount:i}),l!==hr.current)return;let s=t.debug,c=s?.imageDistances??s?.distances??null;De(c?{query:z[z.length-1]??``,distances:c}:null),y(a?e=>e.length===n.length&&e.every((e,t)=>e.id===n[t].id)?e:n:n),k(i),ur(cr)}catch(e){if(l!==hr.current)return;let t=e instanceof Error?e.message:`Failed to fetch documents`;s({title:`Error`,description:t,variant:`destructive`}),y([]),k(0)}finally{gr.current===d&&(gr.current=null),l===hr.current&&b(!1),l===hr.current&&d.refreshPending&&vr({silent:!0})}},[e,H,U,K,G,F,L,d?.status,z,Yt,j,en,A,Dn]);(0,M.useEffect)(()=>{vr()},[vr]),(0,M.useEffect)(()=>{let t=t=>{let n=t.detail;!n||n.workspaceName!==e||(sn({treeName:n.treeName||`context`,path:ze(n.path||`/`)}),un(`left`))};return window.addEventListener(`workspace:open-to-side`,t),()=>window.removeEventListener(`workspace:open-to-side`,t)},[e,U,H]),(0,M.useEffect)(()=>{let t=t=>{let n=t.detail;if(!(n?.workspaceName&&n.workspaceName!==e)&&(e&&jt(e,n),xt(bt(n),{tree:U,kind:E(U),path:H,wholeWorkspace:j===`workspace`}))){if(e&&R(e,U,H),$n.current){Xn();return}vr({silent:!0})}};return window.addEventListener(`workspace:documents:refresh`,t),()=>window.removeEventListener(`workspace:documents:refresh`,t)},[vr,e,H,U,j,Xn]);let yr=d?.name,br=d?.id;(0,M.useEffect)(()=>{if(!e||!yr&&!br)return;let t=[yr,br].filter(Boolean).map(e=>`workspace:${e}`),n=()=>t.forEach(e=>v.emit(`subscribe`,{channel:e}));n();let r=v.on(`connect`,n),i=new Map,a=!1,o=()=>{x(e).then(e=>{a||(i=gt(e))}).catch(()=>{})};o();let s=null,c=0,l=!1,u=null,d=()=>{if(s=null,c=Date.now(),u){let{treeName:t,path:n}=u;u=null,window.dispatchEvent(new CustomEvent(`workspace:documents:refresh`,{detail:{workspaceName:e,treeName:t,path:n}}))}if(l){if(l=!1,$n.current){Xn();return}vr({silent:!0})}},f=t=>n=>{(t.startsWith(`tree.created`)||t.startsWith(`tree.renamed`))&&o();let r=_t(t,n,i);At(e,r);let a={tree:U,kind:E(U),path:H,wholeWorkspace:j===`workspace`},f=cn.current;f&&xt(r,{tree:f.treeName,kind:E(f.treeName),path:f.path})&&(u=f),xt(r,a,ir.current)&&(l=!0),!(!l&&!u)&&(s||=setTimeout(d,Math.max(200,c+1500-Date.now())))},p=[`document.inserted`,`document.inserted.batch`,`document.updated`,`document.removed`,`document.deleted`,`document.removed.batch`,`document.deleted.batch`,`document.linked`,`document.unlinked`,`document.linked.batch`,`document.unlinked.batch`,`tree.document.inserted`,`tree.document.inserted.batch`,`tree.document.removed`,`tree.document.removed.batch`,`tree.document.deleted`,`tree.document.deleted.batch`,`tree.layer.merged`,`tree.layer.subtracted`,`tree.created`,`tree.renamed`].map(e=>[e,f(e)]);return p.forEach(([e,t])=>v.on(e,t)),()=>{a=!0,s&&clearTimeout(s),r?.(),p.forEach(([e,t])=>v.off(e,t))}},[e,br,yr,U,H,j,vr,Xn]);let xr=`${H}\0${U}\0${K??``}\0${j}`,[Sr,Cr]=(0,M.useState)(xr);Sr!==xr&&(Cr(xr),I(1),It(null));let wr=`${H}\0${U}\0${K??``}`,[Tr,Er]=(0,M.useState)(wr);Tr!==wr&&(Er(wr),it(`path`));let Dr=(e,t)=>{let n=e===`/`?`canvas`:e.split(`/`).pop()||`canvas`;mt(n),ft({parentPath:e,captureView:t})},Or=l.get(`createCanvas`)===`1`,[kr,Ar]=(0,M.useState)(!1);kr!==Or&&(Ar(Or),Or&&Dr(H,!1)),(0,M.useEffect)(()=>{if(!Or)return;let e=new URLSearchParams(n.search);e.delete(`createCanvas`);let t=e.toString();o(`${n.pathname}${t?`?${t}`:``}${n.hash}`,{replace:!0})},[Or,H]);let jr=(0,M.useCallback)(e=>{let t=new URLSearchParams(n.search);t.delete(`q`),t.delete(`search`);for(let n of e)t.append(`q`,n);let r=t.toString();o(`${n.pathname}${r?`?${r}`:``}${n.hash}`)},[n.pathname,n.search,n.hash,o]),Mr=JSON.stringify([l.has(`q`),...u]),[Nr,Pr]=(0,M.useState)(Mr);Nr!==Mr&&(Pr(Mr),Nt(u),I(1));let Fr=`${Mr}\0${X??``}\0${jn}\0${H}\0${Ft??``}`,[Ir,Lr]=(0,M.useState)(Fr);Ir!==Fr&&(Lr(Fr),l.has(`q`)||u.length>0||X!==`canvas`||Ft===H||(Nt(jn?[jn]:[]),I(1)));let Rr=(0,M.useCallback)(e=>{let t=e.trim();t&&(It(null),Nt(e=>{if(e.includes(t))return e;let n=[...e,t];return jr(n),I(1),n}))},[jr,It,Nt,I]),zr=(0,M.useCallback)(e=>{Nt(t=>{let n=e<0?[]:t.filter((t,n)=>n!==e);return n.length===0&&It(H),jr(n),I(1),n})},[jr,H,It,Nt,I]),Br=z.join(` `).trim(),Vr=!!B.activeContextType&&(B.isDirty||Br!==(X===`canvas`?jn:B.savedSearchQuery||``));!e&&q!==null&&on(null),(0,M.useEffect)(()=>{let t=!1;if(!e)return;let n=0,r=!1,i=(i=!1)=>{let a=++n;i&&ue(e,U),oe(e,U).then(i=>{!t&&a===n&&(r=!0,vn.current=`${e}/${U}`,on(i))}).catch(()=>{!t&&a===n&&!r&&on(null)})};i(!1);let a=t=>{let n=t.detail;n?.workspaceName&&n.workspaceName!==e||n?.treeName&&n.treeName!==U||i(!n?.cacheInvalidated)};window.addEventListener(`workspace:tree:refresh`,a);let o=Te(e,br);return()=>{t=!0,o(),window.removeEventListener(`workspace:tree:refresh`,a)}},[e,U,br]),!(e&&X===`canvas`&&!G)&&P!==null&&Tt(null),(0,M.useEffect)(()=>{let t=!1;if(!(!e||X!==`canvas`||G))return se(e,H,U).then(e=>{t||Tt(e)}).catch(()=>{t||Tt(null)}),()=>{t=!0}},[e,H,U,X,G]);let Hr=async()=>{if(d){ot(!0);try{let t=await fe(e||d.id);f(t),s({title:`Success`,description:`Workspace started successfully`}),window.dispatchEvent(new CustomEvent(`workspaces:refresh`))}catch(e){let t=e instanceof Error?e.message:`Failed to start workspace`;s({title:`Error`,description:t,variant:`destructive`})}finally{ot(!1)}}},Ur=async t=>{if(!d)return;let n=c({title:`Removing…`,description:`Document from "${H}"`});try{await C(e||d.id,[t],H,[],U,Zr,{trashIfOrphaned:!0}),R(e||d.id,U,H),y(e=>e.filter(e=>e.id!==t)),k(e=>Math.max(0,e-1)),n.done({title:`Success`,description:`Document removed from workspace path.`})}catch(e){n.fail({title:`Error`,description:e instanceof Error?e.message:`Failed to remove document`,variant:`destructive`})}},Wr=async t=>{if(!d)return;let n=c({title:`Deleting…`,description:`Document from "${H}"`});try{await ge(e||d.id,[t],H,[],U,Zr),R(e||d.id,U,H),y(e=>e.filter(e=>e.id!==t)),k(e=>Math.max(0,e-1)),n.done({title:`Success`,description:`Document deleted.`})}catch(e){n.fail({title:`Error`,description:e instanceof Error?e.message:`Failed to delete document`,variant:`destructive`})}},Gr=async t=>{if(!d)return;let n=c({title:`Removing…`,description:`${t.length} document(s) from "${H}"`});try{await C(e||d.id,t,H,[],U,Zr,{trashIfOrphaned:!0}),R(e||d.id,U,H),y(e=>e.filter(e=>!t.includes(e.id))),k(e=>Math.max(0,e-t.length)),n.done({title:`Success`,description:`${t.length} document(s) removed.`})}catch(e){n.fail({title:`Error`,description:e instanceof Error?e.message:`Failed to remove documents`,variant:`destructive`})}},Kr=async t=>{if(!d)return;let n=c({title:`Deleting…`,description:`${t.length} document(s)`});try{await ge(e||d.id,t,H,[],U,Zr),R(e||d.id,U,H),y(e=>e.filter(e=>!t.includes(e.id))),k(e=>Math.max(0,e-t.length)),n.done({title:`Success`,description:`${t.length} document(s) deleted.`})}catch(e){n.fail({title:`Error`,description:e instanceof Error?e.message:`Failed to delete documents`,variant:`destructive`})}},qr=async t=>{if(!d)return;let n=c({title:`Destroying…`,description:`Document and its backend copies`});try{let r=await S(e||d.id,[t]);if(r.failed?.length){n.fail({title:`Error`,description:r.failed[0].reason,variant:`destructive`});return}y(e=>e.filter(e=>e.id!==t)),k(e=>Math.max(0,e-1)),n.done({title:`Destroyed`,description:`Document removed from all backends.`})}catch(e){n.fail({title:`Error`,description:e instanceof Error?e.message:`Failed to destroy document`,variant:`destructive`})}},Jr=async t=>{if(!d)return;let n=c({title:`Destroying…`,description:`${t.length} document(s) and their backend copies`});try{let r=await S(e||d.id,t),i=new Set(r.successful?.filter(e=>e.docDeleted).map(e=>e.id)??[]);y(e=>e.filter(e=>!i.has(e.id))),k(e=>Math.max(0,e-i.size));let a=[r.successful?.length?`${r.successful.length} destroyed`:null,r.failed?.length?`${r.failed.length} failed`:null].filter(Boolean).join(`, `);r.failed?.length?n.fail({title:`Destroy incomplete`,description:a,variant:`destructive`}):n.done({title:`Destroyed`,description:a||`No documents destroyed`})}catch(e){n.fail({title:`Error`,description:e instanceof Error?e.message:`Failed to destroy documents`,variant:`destructive`})}},Yr=e=>{ct({documentIds:e,operation:`copy`,sourcePath:H,sourceTreeName:U}),window.dispatchEvent(new CustomEvent(`documents:clipboard`,{detail:{documentIds:e,operation:`copy`}})),s({title:`Copied`,description:`${e.length} document(s) copied to clipboard`})},Xr=e=>{ct({documentIds:e,operation:`cut`,sourcePath:H,sourceTreeName:U}),window.dispatchEvent(new CustomEvent(`documents:clipboard`,{detail:{documentIds:e,operation:`cut`}})),s({title:`Cut`,description:`${e.length} document(s) cut to clipboard`})},Zr=E(U),Qr=async(t,n,r={})=>{if(!e)return!1;let i=r.targetTreeName??U,a=r.targetTreeType??Zr,o=r.move??st?.operation===`cut`,s=c({title:o?`Moving…`:`Pasting…`,description:`${n.length} document(s) → "${t}"`});try{let c=await ae(e,t,n,i,a);if(c){R(e,i,t);let a=r.sourceTreeName||st?.sourceTreeName,c=r.sourcePath||st?.sourcePath;if((r.move??st?.operation===`cut`)&&c&&a){let t=E(a);await C(e,n,c,[],a,t),R(e,a,c),window.dispatchEvent(new CustomEvent(`workspace:documents:refresh`,{detail:{workspaceName:e,path:c,treeName:a}}))}s.done({title:`Success`,description:`${n.length} document(s) ${o?`moved`:`pasted`} to "${t}"`}),ct(null),window.dispatchEvent(new CustomEvent(`documents:clipboard`,{detail:null}));let l=performance.now();await vr(),console.info(`[paste] list refresh ${Math.round(performance.now()-l)} ms`),window.dispatchEvent(new CustomEvent(`workspace:documents:refresh`,{detail:{workspaceName:e,path:t,treeName:i}}))}else s.done();return c}catch(e){return s.fail({title:`Error`,description:e instanceof Error?e.message:`Failed to paste documents`,variant:`destructive`}),!1}},$r=async(t,n)=>{if(!e)return!1;try{let r=(await O(e,n,t,U,Zr)).length>0;return r&&(ke(e,U,n),s({title:`Success`,description:`Imported ${t.length} document(s) to "${n}"`})),r}catch(e){return s({title:`Error`,description:e instanceof Error?e.message:`Failed to import documents`,variant:`destructive`}),!1}},ei=async()=>{if(!d||rr===0||mr||pr.current||window.prompt(`Type PURGE to permanently delete all ${rr} matching documents across all pages.`)!==`PURGE`)return;pr.current=!0,fr(!0);let t=c({title:`Purging…`,description:`${rr} matching document(s)`});try{let n=await ye(e||d.id,sr,rr);n.deleted===n.requested?t.done({title:`Success`,description:`${n.deleted} document(s) purged.`}):t.fail({title:`Purge incomplete`,description:`${n.deleted} of ${n.requested} document(s) purged. Refresh and review the remaining results before retrying.`})}catch(e){t.fail({title:`Error`,description:e instanceof Error?e.message:`Failed to purge documents`,variant:`destructive`})}finally{R(e||d.id,U,H),await vr({silent:!0}),pr.current=!1,fr(!1)}},ti=()=>Dr(H,!0),ni=async()=>{if(!(!e||!ut||!pt.trim())){vt(!0);try{let t=pt.trim(),n=ut.parentPath,r=n===`/`?`/${t}`:`${n}/${t}`,i={...B.filters,features:{...B.filters.features,allOf:On}};await ve(e,r,U,ut.captureView?{metadata:{toolbox:i},querySpec:{features:i.features,filters:[...Fe(B.filters.timeline),...Pe(B.filters.geo)],query:Br||void 0,sort:B.filters.sort?.sortBy?B.filters.sort:null}}:{}),ft(null),ue(e,U);try{let t=await oe(e,U,{force:!0});on(t)}catch{}window.dispatchEvent(new CustomEvent(`workspace:tree:refresh`,{detail:{workspaceName:e}})),o(Be(e,r,U))}catch(e){s({title:`Error`,description:e instanceof Error?e.message:`Failed to create canvas`,variant:`destructive`})}finally{vt(!1)}}},ri=async()=>{if(!(!e||X!==`canvas`)){St(!0);try{let t=P||await T(e,H,U);Tt(t);let n=`${window.location.origin}${t.url}`;await navigator.clipboard?.writeText(n),s({title:`Public canvas link copied`,description:n})}catch(e){s({title:`Error`,description:e instanceof Error?e.message:`Failed to share canvas`,variant:`destructive`})}finally{St(!1)}}},ii=async()=>{if(P){St(!0);try{await _e(P.code),Tt(null),window.dispatchEvent(new CustomEvent(`workspace:tree:refresh`,{detail:{workspaceName:e,treeName:U}})),s({title:`Canvas unshared`,description:`The public link no longer works.`})}catch(e){s({title:`Error`,description:e instanceof Error?e.message:`Failed to unshare canvas`,variant:`destructive`})}finally{St(!1)}}},ai=async()=>{if(!e||X!==`canvas`||H===`/`)return;let t=Mn?.label||H.split(`/`).pop()||`canvas`,n=P?` Its public link will stop working.`:``;if(window.confirm(`Delete canvas "${t}"? This cannot be undone.${n}`)){wt(!0);try{if(P)await _e(P.code),Tt(null);else if(Y?.locked){s({title:`Canvas is locked`,description:`Unlock it before deleting.`,variant:`destructive`});return}await w(e,H,!1,U);let n=H.split(`/`).filter(Boolean);n.pop();let r=n.length?`/${n.join(`/`)}`:`/`;window.dispatchEvent(new CustomEvent(`workspace:tree:refresh`,{detail:{workspaceName:e,treeName:U}})),o(Be(e,r,U)),s({title:`Canvas deleted`,description:`"${t}" was removed.`})}catch(e){s({title:`Error`,description:e instanceof Error?e.message:`Failed to delete canvas`,variant:`destructive`})}finally{wt(!1)}}},oi=(0,M.useCallback)(async t=>{if(!e||!J)return;let n={treeName:U,path:H},r=ln===`left`?n:J,i=ln===`left`?J:n,a=ln===`left`?dn:gn;if(a.length===0){s({title:`Nothing selected`,description:`Tick documents in the focused pane first.`});return}let o=E(i.treeName),l=c({title:t?`Moving…`:`Copying…`,description:`${a.length} document(s) → "${i.path}"`});try{if(!await ae(e,i.path,a,i.treeName,o)){l.done();return}if(R(e,i.treeName,i.path),t){let t=E(r.treeName);await C(e,a,r.path,[],r.treeName,t),R(e,r.treeName,r.path)}[r,i].forEach(t=>window.dispatchEvent(new CustomEvent(`workspace:documents:refresh`,{detail:{workspaceName:e,path:t.path,treeName:t.treeName}}))),l.done({title:t?`Moved`:`Copied`,description:`${a.length} document(s) → "${i.path}"`})}catch(e){l.fail({title:`Error`,description:e instanceof Error?e.message:`Transfer failed`,variant:`destructive`})}},[e,J,ln,U,H,dn,gn,s,c]);if((0,M.useEffect)(()=>{if(!J)return;let e=e=>{if(e.key!==`F5`&&e.key!==`F6`)return;let t=e.target;t.tagName!==`INPUT`&&t.tagName!==`TEXTAREA`&&(e.preventDefault(),oi(e.key===`F6`))};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[J,oi]),p)return(0,N.jsx)(`div`,{className:`flex items-center justify-center h-full`,children:(0,N.jsxs)(`div`,{className:`text-center space-y-2`,children:[(0,N.jsx)(`div`,{className:`animate-spin rounded-full h-8 w-8 border-b-2 border-primary mx-auto`}),(0,N.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`Loading workspace...`})]})});if(!d)return(0,N.jsx)(`div`,{className:`flex items-center justify-center h-full text-muted-foreground`,children:`Workspace not found.`});let si=X===`canvas`&&!G&&!!Y,ci=!si&&!W&&bn?(0,N.jsx)(Je,{views:Tn,activeId:En,onSelect:kn,onSave:An,accentColor:Me(d.color),onOpenToSide:e=>{sn({treeName:U,path:H,viewId:e}),un(`right`)}}):void 0,li=$t||d.status!==`active`?(0,N.jsxs)(N.Fragment,{children:[$t&&(0,N.jsx)(`button`,{type:`button`,onClick:()=>{tn(!en),I(1)},"aria-pressed":en,className:g(`min-h-10 rounded-md border px-2 text-xs`,en&&`bg-warning/15 text-warning`),children:`Unfiled only`}),d.status!==`active`&&(0,N.jsx)(`button`,{type:`button`,onClick:Hr,disabled:at,className:`min-h-10 rounded-md border px-2 text-xs`,children:at?`Starting…`:`Start`})]}):void 0,ui=we(U,H)?H===`/Trash`?(0,N.jsx)(`div`,{className:`h-full overflow-auto p-4`,children:(0,N.jsx)(nt,{workspaceName:e||d.id})}):(0,N.jsx)(lt,{workspace:e||d.id,path:H,onNavigate:t=>o(Be(e,t,`backends`))},e):(0,N.jsx)(qe,{navigationTabs:ci,navigationActions:li,onBack:hn,accentColor:Me(d.color),urlType:G?E(U)===`directory`?`${U}-layer`:`context-layer`:X===`canvas`?`canvas`:E(U)===`directory`?U:`context`,urlDisplay:Hn,contextPath:H,treeName:U,workspaceId:e||d.id,workspaceLabel:d.label||d.name,workspaceIcon:d.icon,documentSchema:Dn,documents:or,isLoading:re,totalCount:rr,currentPage:F,pageSize:L,onPageChange:I,onPageSizeChange:e=>{Mt(e),I(1)},onRemoveDocument:H===`/`?void 0:Ur,onDeleteDocument:Wr,onDestroyDocument:qr,onRemoveDocuments:H===`/`?void 0:Gr,onDeleteDocuments:Kr,onDestroyDocuments:Jr,onCopyDocuments:Yr,onCutDocuments:Xr,onPasteDocuments:W?void 0:Qr,onImportDocuments:W?void 0:$r,onSelectionChange:fn,onBrowseTree:()=>mn(`workspaces`,`detail`,e??null),onBrowseWorkspaces:()=>pn(`workspaces`),onNavigatePath:t=>o(Be(e,t,U)),folders:yn,onOpenFolder:t=>o(Be(e,ze(t),U)),scope:j,onScopeChange:it,pastedDocumentIds:st?.documentIds,linkTree:q,onPurgeDocuments:W?void 0:ei,disablePurgeDocuments:mr,canvasInfo:Mn??void 0,isCanvasPinned:Rn,onTogglePinCanvas:$?Vn:void 0,onSaveAsCanvas:q&&X!==`canvas`&&!G&&!W?ti:void 0,onShareCanvas:X===`canvas`&&!G?ri:void 0,onUnshareCanvas:P?ii:void 0,onDeleteCanvas:X===`canvas`&&!G?ai:void 0,isSharingCanvas:yt,isDeletingCanvas:Ct,isCanvasShared:!!P,isCanvasLocked:!!Y?.locked,backendSearchQueries:z,onBackendSearch:Rr,serverSort:B.filters.sort,onServerSortChange:Rt,onRemoveBackendQuery:zr,canSaveChanges:Vr,isSavingChanges:B.isSaving,onSaveChanges:Lt,contentBanner:A&&Ee?(0,N.jsx)(Dt,{data:Ee,className:`mb-3`}):null,children:si&&Y?(0,N.jsx)(xe,{workspaceId:e||d.id,treeName:U,path:H,layerId:Y.id,querySpec:Y.querySpec,metadata:Y.metadata,isLocked:!!Y.locked,fetchDocuments:B.isDirty?Wn:void 0}):!W&&Q.kind===`columns`?(0,N.jsx)(Qe,{documents:or,workspaceId:e||d.id,columns:Q.columns??[],onColumnsChange:e=>An(Tn.map(t=>t.id===Q.id?{...t,columns:e}:t))}):!W&&Q.kind===`app`&&Q.app&&Q.app!==`notes`?(0,N.jsx)(Xe,{app:Q.app,workspaceId:e||d.id,treeName:U,path:H}):null});return(0,N.jsxs)(Ue,{workspaceId:e||d.id,treeName:U,path:H,headerOnly:!0,className:`relative flex flex-col h-full min-h-0`,children:[(0,N.jsx)(dt,{workspaceId:d.id,workspaceName:d.label||d.name},d.id),we(U,H)&&(0,N.jsx)(Se,{workspace:d.label||d.name,workspaceIcon:d.icon,tree:U,path:H,onBack:hn,onBrowseTree:()=>mn(`workspaces`,`detail`,e||d.id),onBrowseWorkspaces:()=>pn(`workspaces`),onNavigatePath:t=>o(Be(e,t,U)),accentColor:Me(d.color)}),ut&&(0,N.jsx)(`div`,{className:`shrink-0 px-2 pt-2`,children:(0,N.jsx)(Ge,{title:`New canvas`,onClose:()=>ft(null),children:(0,N.jsxs)(`form`,{onSubmit:e=>{e.preventDefault(),ni()},className:`space-y-4`,children:[(0,N.jsxs)(`div`,{className:`grid gap-4 md:grid-cols-2`,children:[(0,N.jsxs)(`div`,{children:[(0,N.jsx)(`label`,{htmlFor:`canvas-name`,className:`mb-1 block text-sm font-medium`,children:`Name`}),(0,N.jsx)(`input`,{id:`canvas-name`,className:`w-full rounded-md border bg-background px-3 py-2 text-sm focus:outline-none focus:ring-1 focus:ring-primary`,placeholder:`Canvas name…`,value:pt,onChange:e=>mt(e.target.value),onKeyDown:e=>{e.key===`Escape`&&ft(null)},autoFocus:!0})]}),(0,N.jsxs)(`div`,{children:[(0,N.jsx)(`span`,{className:`mb-1 block text-sm font-medium`,children:`Parent path`}),(0,N.jsx)(`div`,{className:`flex h-10 items-center rounded-md bg-muted px-3 font-mono text-sm text-muted-foreground`,children:ut.parentPath===`/`?`/`:ut.parentPath})]})]}),(0,N.jsxs)(`label`,{className:`flex items-start gap-2 text-sm`,children:[(0,N.jsx)(`input`,{type:`checkbox`,className:`mt-0.5`,checked:ut.captureView,onChange:e=>ft({...ut,captureView:e.target.checked})}),(0,N.jsxs)(`span`,{children:[`Capture the current view`,(0,N.jsx)(`span`,{className:`block text-xs text-muted-foreground`,children:`Freezes the active filters, search and sort into the canvas.`})]})]}),(0,N.jsxs)(`div`,{className:`flex gap-2`,children:[(0,N.jsx)(ee,{type:`submit`,disabled:!pt.trim()||ht,children:ht?`Creating…`:`Create canvas`}),(0,N.jsx)(ee,{type:`button`,variant:`outline`,onClick:()=>ft(null),children:`Cancel`})]})]})})}),(0,N.jsxs)(`div`,{"data-canvas-panes":!0,className:`flex-1 min-h-0 flex gap-2`,children:[(0,N.jsx)(`div`,{"data-canvas-pane":!0,className:g(`flex-1 min-w-0 bg-background overflow-hidden`,J&&(ln===`left`?`ring-2 ring-primary`:`ring-1 ring-primary/20`)),onMouseDown:e=>{e.target.closest(`button,input,textarea,select,a`)||un(`left`)},children:ui}),J&&e&&(0,N.jsx)(Pt,{workspaceName:e,workspaceLabel:d.label||d.name,workspaceIcon:d.icon,pane:J,isFocused:ln===`right`,clipboard:st,setClipboard:ct,onFocus:()=>un(`right`),onSelectionChange:_n,onNavigate:e=>sn(t=>t&&{...t,path:e,viewId:void 0}),onClose:()=>{sn(null),un(`left`),_n([])}})]})]})}function Nt(e,t){if(!e||t===`/`)return e;let n=e;for(let e of t.split(`/`).filter(Boolean))if(n=n?.children?.find(t=>t.name===e)??null,!n)return null;return n}function Pt({workspaceName:e,workspaceLabel:t,workspaceIcon:n,pane:r,isFocused:i=!1,clipboard:a,setClipboard:o,onFocus:s,onSelectionChange:c,onNavigate:l,onClose:u}){let{openM1Drawer:d,openM2Drawer:f}=Ve(),{showToast:p,showProgress:m}=ne(),[h,ee]=(0,M.useState)(null),[_,te]=(0,M.useState)([]),[v,y]=(0,M.useState)(!1),[re,b]=(0,M.useState)(0),[x,ie]=(0,M.useState)(1),[w,se]=(0,M.useState)(50),T=E(r.treeName),ce=Nt(h,r.path),le=ce?.type===`canvas`,D=(0,M.useMemo)(()=>et(h,r.path),[h,r.path]),O=r.viewId?$e(ce?.metadata).find(e=>e.id===r.viewId)??null:null,fe=`${e}://${r.path===`/`?``:r.path.replace(/^\//,``)}`,pe=Ze(O),me=(0,M.useCallback)(async()=>{if(we(r.treeName,r.path)){te([]),b(0),y(!1);return}let t=kt(e,r.treeName,r.path,x,w,``,pe??``),n=Ot.get(t);if(n){te(n.documents),b(n.totalCount);return}y(!0);try{let n=await de(e,r.path,pe?[pe]:[],{limit:w,page:x,treeName:r.treeName,treeType:T}),i=n.payload||[],a=n.totalCount||n.count||0;te(i),b(a),Ot.set(t,{documents:i,totalCount:a})}catch(e){p({title:`Error`,description:e instanceof Error?e.message:`Failed to fetch side pane documents`,variant:`destructive`}),te([]),b(0)}finally{y(!1)}},[e,r.path,r.treeName,T,w,x,p,pe]);(0,M.useEffect)(()=>{let t=!1,n=0,i=!1,a=(a=!1)=>{let o=++n;a&&ue(e,r.treeName),oe(e,r.treeName).then(e=>{!t&&o===n&&(i=!0,ee(e))}).catch(()=>{!t&&o===n&&!i&&ee(null)})};a(!1);let o=t=>{let n=t.detail;n?.workspaceName&&n.workspaceName!==e||n?.treeName&&n.treeName!==r.treeName||a(!n?.cacheInvalidated)};return window.addEventListener(`workspace:tree:refresh`,o),()=>{t=!0,window.removeEventListener(`workspace:tree:refresh`,o)}},[e,r.treeName]),(0,M.useEffect)(()=>{me()},[me]),(0,M.useEffect)(()=>{let t=t=>{let n=t.detail;n?.workspaceName&&n.workspaceName!==e||(jt(e,n),xt(bt(n),{tree:r.treeName,kind:E(r.treeName),path:r.path})&&(R(e,r.treeName,r.path),me()))};return window.addEventListener(`workspace:documents:refresh`,t),()=>window.removeEventListener(`workspace:documents:refresh`,t)},[me,e,r.treeName,r.path]);let he=(0,M.useCallback)(async(t,n,i={})=>{let s=i.targetTreeName??r.treeName,c=i.targetTreeType??T,l=i.move??a?.operation===`cut`,u=m({title:l?`Moving…`:`Pasting…`,description:`${n.length} document(s) → "${t}"`});try{let r=await ae(e,t,n,s,c);if(r){R(e,s,t);let r=i.sourcePath||a?.sourcePath,c=i.sourceTreeName||a?.sourceTreeName;if((i.move??a?.operation===`cut`)&&r&&c){let t=E(c);await C(e,n,r,[],c,t),R(e,c,r),window.dispatchEvent(new CustomEvent(`workspace:documents:refresh`,{detail:{workspaceName:e,path:r,treeName:c}}))}u.done({title:`Success`,description:`${n.length} document(s) ${l?`moved`:`pasted`} to "${t}"`}),o(null),await me(),window.dispatchEvent(new CustomEvent(`workspace:documents:refresh`,{detail:{workspaceName:e,path:t,treeName:s}}))}else u.done();return r}catch(e){return u.fail({title:`Error`,description:e instanceof Error?e.message:`Failed to paste documents`,variant:`destructive`}),!1}},[e,r.treeName,T,me,m,a,o]),_e=(0,M.useCallback)(()=>{R(e,r.treeName,r.path),me()},[e,r.treeName,r.path,me]),ve=(0,M.useCallback)(async t=>{let n=m({title:`Removing…`,description:`${t.length} document(s) from "${r.path}"`});try{await C(e,t,r.path,[],r.treeName,T),_e(),n.done({title:`Removed`,description:`${t.length} document(s) removed from "${r.path}"`})}catch(e){n.fail({title:`Error`,description:e instanceof Error?e.message:`Failed to remove documents`,variant:`destructive`})}},[e,r.path,r.treeName,T,_e,m]),ye=(0,M.useCallback)(async t=>{let n=m({title:`Deleting…`,description:`${t.length} document(s)`});try{await ge(e,t,r.path,[],r.treeName,T),_e(),n.done({title:`Deleted`,description:`${t.length} document(s) deleted.`})}catch(e){n.fail({title:`Error`,description:e instanceof Error?e.message:`Failed to delete documents`,variant:`destructive`})}},[e,r.path,r.treeName,T,_e,m]),be=(0,M.useCallback)(async t=>{let n=m({title:`Destroying…`,description:`${t.length} document(s) and their backend copies`});try{let r=await S(e,t);if(r.failed?.length&&!r.successful?.length){n.fail({title:`Error`,description:r.failed[0].reason,variant:`destructive`});return}_e();let i=`${r.successful?.length??0} document(s) destroyed${r.failed?.length?` · ${r.failed.length} failed`:``}.`;r.failed?.length?n.fail({title:`Destroy incomplete`,description:i,variant:`destructive`}):n.done({title:`Destroyed`,description:i})}catch(e){n.fail({title:`Error`,description:e instanceof Error?e.message:`Failed to destroy documents`,variant:`destructive`})}},[e,_e,m]);return(0,N.jsxs)(`div`,{className:g(`relative flex-1 min-w-0 rounded-(--sheet-radius) border bg-background overflow-hidden`,i?`ring-2 ring-primary`:`ring-1 ring-primary/20`),onMouseDown:e=>{e.target.closest(`button,input,textarea,select,a`)||s()},children:[u&&(0,N.jsx)(`button`,{type:`button`,onClick:u,className:`absolute right-2 top-2 z-10 px-2 py-1 text-xs rounded-md border bg-background/90 hover:bg-accent`,children:`Close`}),we(r.treeName,r.path)?r.path===`/Trash`?(0,N.jsx)(`div`,{className:`h-full overflow-auto p-4`,children:(0,N.jsx)(nt,{workspaceName:e})}):(0,N.jsx)(lt,{workspace:e,path:r.path,onNavigate:l||(()=>{})}):(0,N.jsx)(qe,{frameContent:!1,onBrowseWorkspaces:()=>d(`workspaces`),onBrowseTree:()=>f(`workspaces`,`detail`,e),urlType:le?`canvas`:T===`directory`?r.treeName:`context`,urlDisplay:fe,contextPath:r.path,treeName:r.treeName,workspaceId:e,workspaceLabel:t,workspaceIcon:n,documentSchema:pe,documents:_,isLoading:v,totalCount:re,currentPage:x,pageSize:w,onPageChange:ie,onPageSizeChange:e=>{se(e),ie(1)},onRemoveDocument:r.path===`/`?void 0:e=>ve([e]),onRemoveDocuments:r.path===`/`?void 0:ve,onDeleteDocument:e=>ye([e]),onDeleteDocuments:ye,onDestroyDocument:e=>be([e]),onDestroyDocuments:be,onCopyDocuments:e=>{o({documentIds:e,operation:`copy`,sourcePath:r.path,sourceTreeName:r.treeName}),window.dispatchEvent(new CustomEvent(`documents:clipboard`,{detail:{documentIds:e,operation:`copy`}}))},onCutDocuments:e=>{o({documentIds:e,operation:`cut`,sourcePath:r.path,sourceTreeName:r.treeName}),window.dispatchEvent(new CustomEvent(`documents:clipboard`,{detail:{documentIds:e,operation:`cut`}}))},onPasteDocuments:r.treeName===`backends`?void 0:he,onSelectionChange:c,pastedDocumentIds:a?.documentIds,linkTree:h,folders:D,onOpenFolder:l,onNavigatePath:l,canvasInfo:le?{label:ce?.label,description:ce?.description,color:ce?.color}:void 0,children:O?.kind===`columns`?(0,N.jsx)(Qe,{documents:_,workspaceId:e,columns:O.columns??[],onColumnsChange:()=>{},readOnly:!0}):O?.kind===`app`&&O.app&&O.app!==`notes`?(0,N.jsx)(Xe,{app:O.app,workspaceId:e,treeName:r.treeName,path:r.path}):null})]})}export{Mt as default};
@@ -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{t as r}from"./api-CA6WiiYM.js";import{n as i}from"./page-header-DrDt1sQ2.js";import{t as a}from"./use-settings-back-DGmLAD63.js";var o=e(n(),1),s=t();function c(e){let t=Math.floor(e/86400),n=Math.floor(e%86400/3600),r=Math.floor(e%3600/60);return t>0?`${t}d ${n}h ${r}m`:n>0?`${n}h ${r}m`:`${r}m`}function l({name:e,version:t,detail:n}){return(0,s.jsxs)(`div`,{className:`flex items-baseline justify-between gap-4 px-4 py-2.5`,children:[(0,s.jsxs)(`div`,{className:`min-w-0`,children:[(0,s.jsx)(`div`,{className:`text-sm font-medium truncate`,children:e}),n&&(0,s.jsx)(`div`,{className:`text-xs text-muted-foreground truncate`,children:n})]}),(0,s.jsx)(`code`,{className:`text-xs text-muted-foreground shrink-0`,children:t})]})}function u(){let[e,t]=(0,o.useState)(null),[n,u]=(0,o.useState)(null);(0,o.useEffect)(()=>{let e=!0;return r.get(`/ping`,{skipAuth:!0}).then(n=>{e&&t(n??{})}).catch(t=>{e&&u(t instanceof Error?t.message:`Failed to reach the server`)}),()=>{e=!1}},[]);let d=[e?.commit?`commit ${e.commit.slice(0,7)}`:null,typeof e?.uptime==`number`?`up ${c(e.uptime)}`:null].filter(Boolean).join(` · `),f=Object.entries(e?.components??{}).sort(([e],[t])=>e.localeCompare(t));return(0,s.jsxs)(`div`,{className:`mx-auto max-w-4xl`,children:[(0,s.jsx)(i,{className:`mb-6`,title:`About`,onBack:a(),description:`Versions of every Canvas component this installation is running.`}),(0,s.jsxs)(`div`,{className:`space-y-6`,children:[(0,s.jsxs)(`section`,{className:`rounded-md border border-border divide-y divide-border`,children:[(0,s.jsx)(l,{name:`Canvas Web`,detail:`this interface`,version:`v2.26.39`}),e?.version&&(0,s.jsx)(l,{name:e.productName||e.appName||`Canvas Server`,detail:d||void 0,version:`v${e.version}`})]}),f.length>0&&(0,s.jsxs)(`section`,{children:[(0,s.jsx)(`h2`,{className:`mb-2 px-1 text-xs font-semibold uppercase tracking-wide text-muted-foreground`,children:`Server components`}),(0,s.jsx)(`div`,{className:`rounded-md border border-border divide-y divide-border`,children:f.map(([e,t])=>(0,s.jsx)(l,{name:e,version:`v${t}`},e))})]}),n&&(0,s.jsxs)(`p`,{className:`text-sm text-muted-foreground`,children:[`Server details unavailable: `,n]}),e?.sourceUrl&&(0,s.jsxs)(`p`,{className:`text-xs text-muted-foreground`,children:[e.license?`Licensed ${e.license}. `:``,(0,s.jsx)(`a`,{href:e.sourceUrl,target:`_blank`,rel:`noreferrer`,className:`underline underline-offset-2 hover:text-foreground`,children:`Get the source code`}),`.`]})]})]})}export{u as default};
1
+ import{o as e}from"./rolldown-runtime-C0FnF6B9.js";import{l as t,u as n}from"./code-editor-BOIngd5F.js";import{t as r}from"./api-CA6WiiYM.js";import{n as i}from"./page-header-DrDt1sQ2.js";import{t as a}from"./use-settings-back-DGmLAD63.js";var o=e(n(),1),s=t();function c(e){let t=Math.floor(e/86400),n=Math.floor(e%86400/3600),r=Math.floor(e%3600/60);return t>0?`${t}d ${n}h ${r}m`:n>0?`${n}h ${r}m`:`${r}m`}function l({name:e,version:t,detail:n}){return(0,s.jsxs)(`div`,{className:`flex items-baseline justify-between gap-4 px-4 py-2.5`,children:[(0,s.jsxs)(`div`,{className:`min-w-0`,children:[(0,s.jsx)(`div`,{className:`text-sm font-medium truncate`,children:e}),n&&(0,s.jsx)(`div`,{className:`text-xs text-muted-foreground truncate`,children:n})]}),(0,s.jsx)(`code`,{className:`text-xs text-muted-foreground shrink-0`,children:t})]})}function u(){let[e,t]=(0,o.useState)(null),[n,u]=(0,o.useState)(null);(0,o.useEffect)(()=>{let e=!0;return r.get(`/ping`,{skipAuth:!0}).then(n=>{e&&t(n??{})}).catch(t=>{e&&u(t instanceof Error?t.message:`Failed to reach the server`)}),()=>{e=!1}},[]);let d=[e?.commit?`commit ${e.commit.slice(0,7)}`:null,typeof e?.uptime==`number`?`up ${c(e.uptime)}`:null].filter(Boolean).join(` · `),f=Object.entries(e?.components??{}).sort(([e],[t])=>e.localeCompare(t));return(0,s.jsxs)(`div`,{className:`mx-auto max-w-4xl`,children:[(0,s.jsx)(i,{className:`mb-6`,title:`About`,onBack:a(),description:`Versions of every Canvas component this installation is running.`}),(0,s.jsxs)(`div`,{className:`space-y-6`,children:[(0,s.jsxs)(`section`,{className:`rounded-md border border-border divide-y divide-border`,children:[(0,s.jsx)(l,{name:`Canvas Web`,detail:`this interface`,version:`v2.26.40`}),e?.version&&(0,s.jsx)(l,{name:e.productName||e.appName||`Canvas Server`,detail:d||void 0,version:`v${e.version}`})]}),f.length>0&&(0,s.jsxs)(`section`,{children:[(0,s.jsx)(`h2`,{className:`mb-2 px-1 text-xs font-semibold uppercase tracking-wide text-muted-foreground`,children:`Server components`}),(0,s.jsx)(`div`,{className:`rounded-md border border-border divide-y divide-border`,children:f.map(([e,t])=>(0,s.jsx)(l,{name:e,version:`v${t}`},e))})]}),n&&(0,s.jsxs)(`p`,{className:`text-sm text-muted-foreground`,children:[`Server details unavailable: `,n]}),e?.sourceUrl&&(0,s.jsxs)(`p`,{className:`text-xs text-muted-foreground`,children:[e.license?`Licensed ${e.license}. `:``,(0,s.jsx)(`a`,{href:e.sourceUrl,target:`_blank`,rel:`noreferrer`,className:`underline underline-offset-2 hover:text-foreground`,children:`Get the source code`}),`.`]})]})]})}export{u as default};
@@ -1 +1 @@
1
- import{l as e}from"./code-editor-BOIngd5F.js";import{_ as t,a as n,g as r}from"./chunk-62JRHF6Z-vspAGgtK.js";import{t as i}from"./HomeFab-DRmbW2Uu.js";var a=e(),o=[`note`,`todo`,`link`,`file`,`photo`];function s(){let{kind:e}=t(),s=r();return e===`sketch`?(0,a.jsx)(n,{to:`/apps/sketch?add=1`,replace:!0}):!e||!o.includes(e)?(0,a.jsx)(n,{to:`/home`,replace:!0}):(0,a.jsx)(i,{initialKind:e,onInitialCardClose:()=>s(`/home`)})}export{s as default};
1
+ import{l as e}from"./code-editor-BOIngd5F.js";import{_ as t,a as n,g as r}from"./chunk-62JRHF6Z-vspAGgtK.js";import{t as i}from"./HomeFab-CpgkP2jx.js";var a=e(),o=[`note`,`todo`,`link`,`file`,`photo`];function s(){let{kind:e}=t(),s=r();return e===`sketch`?(0,a.jsx)(n,{to:`/apps/sketch?add=1`,replace:!0}):!e||!o.includes(e)?(0,a.jsx)(n,{to:`/home`,replace:!0}):(0,a.jsx)(i,{initialKind:e,onInitialCardClose:()=>s(`/home`)})}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{g as r}from"./chunk-62JRHF6Z-vspAGgtK.js";import{I as i,It as a,Pt as o,Qr as s,Sr as c,rn as l,rt as u}from"./ui-CDoK3F3U.js";import{t as d}from"./button-SeUZ_Pvi.js";import{t as f}from"./input-BOtCd4HP.js";import{n as p}from"./use-toast-BlLDqSUO.js";import{t as m}from"./color-DFEH4BfK.js";import{R as h,Y as g,kt as _,nt as v,tt as y}from"./index-CXPA9Fj8.js";import{n as b}from"./page-header-DrDt1sQ2.js";import{n as ee,r as x,t as te}from"./useAgentModels-CI7iZlUR.js";import{t as ne}from"./form-panel-3p-ncEVK.js";import{t as re}from"./use-create-panel-DhSNIGtr.js";import{n as ie,t as ae}from"./useSocketSubscription-ifW-vnlb.js";var S=e(n(),1),C=t();function w({agent:e,onStart:t,onStop:n,onEnter:r}){let[o,f]=(0,S.useState)(!1),p=async()=>{f(!0);try{await t(e.name)}finally{f(!1)}},m=async()=>{f(!0);try{await n(e.name)}finally{f(!1)}},h=()=>{switch(e.status){case`active`:return(0,C.jsx)(c,{className:`h-4 w-4 text-success`});case`inactive`:return(0,C.jsx)(c,{className:`h-4 w-4 text-warning`});case`error`:return(0,C.jsx)(c,{className:`h-4 w-4 text-destructive`});default:return(0,C.jsx)(c,{className:`h-4 w-4 text-muted-foreground`})}},g=()=>{switch(e.llmProvider){case`anthropic`:return(0,C.jsx)(s,{className:`h-4 w-4 text-warning`});case`openai`:return(0,C.jsx)(s,{className:`h-4 w-4 text-success`});case`ollama`:return(0,C.jsx)(i,{className:`h-4 w-4 text-info`});default:return(0,C.jsx)(s,{className:`h-4 w-4 text-muted-foreground`})}},_=()=>{switch(e.status){case`active`:return`text-success bg-success-subtle border-success`;case`inactive`:return`text-warning bg-warning-subtle border-warning`;case`error`:return`text-destructive bg-destructive-subtle border-destructive`;case`available`:return`text-info bg-info-subtle border-info`;default:return`text-foreground bg-muted border-border`}},v=e.status===`available`||e.status===`inactive`,y=e.status===`active`;return(0,C.jsxs)(`div`,{className:`border rounded-lg p-4 space-y-4 hover:shadow-elevation-2 transition-shadow bg-card`,children:[(0,C.jsxs)(`div`,{className:`flex items-start justify-between`,children:[(0,C.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,C.jsxs)(`div`,{className:`flex items-center gap-2 mb-1`,children:[g(),(0,C.jsx)(`h3`,{className:`text-lg font-semibold truncate`,children:e.label||e.name}),e.color&&(0,C.jsx)(`div`,{className:`w-4 h-4 rounded border flex-shrink-0`,style:{backgroundColor:e.color},title:`Color: ${e.color}`})]}),(0,C.jsx)(`p`,{className:`text-sm text-muted-foreground font-mono`,children:e.name}),e.description&&(0,C.jsx)(`p`,{className:`text-sm text-muted-foreground mt-1 line-clamp-2`,children:e.description})]}),(0,C.jsxs)(`div`,{className:`flex items-center gap-2 flex-shrink-0`,children:[h(),(0,C.jsx)(`span`,{className:`px-2 py-1 rounded-full text-xs font-medium border ${_()}`,children:e.status})]})]}),(0,C.jsxs)(`div`,{className:`grid grid-cols-2 gap-4 text-sm`,children:[(0,C.jsxs)(`div`,{children:[(0,C.jsx)(`span`,{className:`text-muted-foreground`,children:`Provider:`}),(0,C.jsx)(`div`,{className:`font-medium capitalize`,children:e.llmProvider})]}),(0,C.jsxs)(`div`,{children:[(0,C.jsx)(`span`,{className:`text-muted-foreground`,children:`Model:`}),(0,C.jsx)(`div`,{className:`font-mono text-xs`,children:e.model})]}),(0,C.jsxs)(`div`,{children:[(0,C.jsx)(`span`,{className:`text-muted-foreground`,children:`Created:`}),(0,C.jsx)(`div`,{children:new Date(e.createdAt).toLocaleDateString()})]}),(0,C.jsxs)(`div`,{children:[(0,C.jsx)(`span`,{className:`text-muted-foreground`,children:`Last Access:`}),(0,C.jsx)(`div`,{children:e.lastAccessed?new Date(e.lastAccessed).toLocaleDateString():`Never`})]})]}),e.config.mcp?.servers&&e.config.mcp.servers.length>0&&(0,C.jsxs)(`div`,{className:`text-sm`,children:[(0,C.jsx)(`span`,{className:`text-muted-foreground`,children:`MCP Servers:`}),(0,C.jsx)(`div`,{className:`flex flex-wrap gap-1 mt-1`,children:e.config.mcp.servers.map((e,t)=>(0,C.jsx)(`span`,{className:`px-2 py-1 bg-secondary text-secondary-foreground rounded text-xs`,children:e.name},t))})]}),(0,C.jsxs)(`div`,{className:`flex gap-2 pt-2 border-t`,children:[v&&(0,C.jsxs)(d,{onClick:p,disabled:o,size:`sm`,variant:`outline`,className:`flex-1`,children:[(0,C.jsx)(a,{className:`mr-2 h-4 w-4`}),`Start`]}),y&&(0,C.jsxs)(d,{onClick:m,disabled:o,size:`sm`,variant:`outline`,className:`flex-1`,children:[(0,C.jsx)(u,{className:`mr-2 h-4 w-4`}),`Stop`]}),(0,C.jsxs)(d,{onClick:()=>r(e.name),size:`sm`,className:`flex-1`,children:[(0,C.jsx)(l,{className:`mr-2 h-4 w-4`}),`Chat`]})]})]})}function T(){let e={anthropic:`https://api.anthropic.com`,openai:`https://api.openai.com/v1`,ollama:`http://localhost:11434/v1`},t={anthropic:`claude-3-5-sonnet-20241022`,openai:`gpt-4o`,ollama:`qwen2.5-coder:latest`},[n,i]=(0,S.useState)([]),[a,s]=(0,S.useState)(!0),[c,l]=(0,S.useState)(null),[u,T]=(0,S.useState)(``),[E,D]=(0,S.useState)(``),[O,k]=(0,S.useState)(m()),[A,j]=(0,S.useState)(``),[M,oe]=(0,S.useState)(`anthropic`),[N,P]=(0,S.useState)(t.anthropic),[F,I]=(0,S.useState)({apiKey:``,baseUrl:e.anthropic,maxTokens:4096,temperature:.7,topP:1,frequencyPenalty:0,presencePenalty:0,numCtx:4096}),L=te(M,F.apiKey,F.baseUrl),R=L.models.find(e=>e.id===N),[z,B]=(0,S.useState)(``),[V,H]=(0,S.useState)(``),[U,W]=(0,S.useState)(``),[G,K]=(0,S.useState)(``),[q,J]=(0,S.useState)(!1),Y=_(),[X,Z]=re(),{showToast:Q}=p(),se=r(),$=ie();ae($,`agent`,{"agent:status:changed":e=>{i(t=>t.map(t=>t.id===e.agentId?{...t,status:e.status,isActive:e.isActive}:t))},"agent:created":e=>{i(t=>[...t,e.agent])},"agent:deleted":e=>{i(t=>t.filter(t=>t.id!==e.agentId))}});let ce=n=>{oe(n),P(t[n]),I({apiKey:``,baseUrl:e[n],maxTokens:4096,temperature:.7,topP:1,frequencyPenalty:0,presencePenalty:0,numCtx:4096})};(0,S.useEffect)(()=>((async()=>{try{s(!0);let e=await g();i(e),l(null)}catch(e){console.error(`Agent fetch error:`,e);let t=`Failed to fetch agents`;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 agents`}l(t),Q({title:`Error`,description:t,variant:`destructive`})}finally{s(!1)}})(),()=>{}),[$,Q]);let le=async t=>{if(t.preventDefault(),u.trim()){J(!0);try{let t=G.trim()||x(z,V,U),n={name:u,label:A||u,description:E||void 0,color:O,llmProvider:M,model:N,apiKey:F.apiKey.trim()||void 0,baseUrl:F.baseUrl.trim()||void 0,config:{type:M,model:N,identity:{role:z.trim()||void 0,identity:V.trim()||void 0,instructions:U.trim()||void 0},prompts:t?{system:t}:void 0,connectors:{[M]:{maxTokens:F.maxTokens,...M===`anthropic`?{}:{temperature:F.temperature},topP:F.topP,frequencyPenalty:F.frequencyPenalty,presencePenalty:F.presencePenalty,...M===`ollama`?{numCtx:F.numCtx}:{}}}},mcp:{enabled:!0,servers:[{name:`weather`,command:`node`,args:[`src/managers/agent/mcp-servers/weather.js`]}]}},r=await h(n);i(e=>[...e,r]),T(``),D(``),k(m()),j(``),K(``),B(``),H(``),W(``),I({apiKey:``,baseUrl:e[M],maxTokens:4096,temperature:.7,topP:1,frequencyPenalty:0,presencePenalty:0,numCtx:4096}),Q({title:`Success`,description:`Agent '${r.label||r.name}' created.`}),Z(!1)}catch(e){console.error(`Agent creation error:`,e);let t=`Failed to create agent`;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 create agent`}Q({title:`Error`,description:t,variant:`destructive`})}finally{J(!1)}}},ue=async e=>{try{let t=await y(e);i(e=>e.map(e=>e.name===t.name?t:e)),Q({title:`Success`,description:`Agent '${t.label||t.name}' started.`})}catch(e){console.error(`Agent start error:`,e);let t=`Failed to start agent`;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 start agent`}Q({title:`Error`,description:t,variant:`destructive`})}},de=async e=>{try{await v(e),i(t=>t.map(t=>t.name===e?{...t,status:`inactive`,isActive:!1}:t)),Q({title:`Success`,description:`Agent '${e}' stopped.`})}catch(e){console.error(`Agent stop error:`,e);let t=`Failed to stop agent`;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 stop agent`}Q({title:`Error`,description:t,variant:`destructive`})}},fe=e=>{se(`/agents/${e}`)};return(0,C.jsxs)(`div`,{className:`space-y-6`,children:[(0,C.jsx)(b,{title:`AI Agents`,description:`Create and manage your AI agents with multiple LLM providers`,actions:!Y.local&&!X&&(0,C.jsxs)(d,{onClick:()=>Z(!0),className:`max-sm:h-9 max-sm:w-9 max-sm:p-0`,"aria-label":`Create agent`,title:`Create agent`,children:[(0,C.jsx)(o,{className:`h-4 w-4 sm:mr-2`}),(0,C.jsx)(`span`,{className:`max-sm:hidden`,children:`Create Agent`})]})}),!Y.local&&X&&(0,C.jsx)(ne,{title:`Create New Agent`,onClose:()=>Z(!1),children:(0,C.jsxs)(`form`,{onSubmit:le,className:`space-y-4`,children:[(0,C.jsxs)(`div`,{className:`grid gap-4 md:grid-cols-2`,children:[(0,C.jsx)(f,{value:u,onChange:e=>T(e.target.value),placeholder:`Agent Name (e.g., 'my-assistant')`,disabled:q}),(0,C.jsx)(f,{value:A,onChange:e=>j(e.target.value),placeholder:`Agent Label (display name, optional)`,disabled:q})]}),(0,C.jsx)(f,{value:E,onChange:e=>D(e.target.value),placeholder:`Description (optional)`,disabled:q}),(0,C.jsxs)(`div`,{className:`grid gap-4 md:grid-cols-2`,children:[(0,C.jsxs)(`div`,{children:[(0,C.jsx)(`label`,{htmlFor:`agent-provider`,className:`text-sm font-medium`,children:`LLM Provider`}),(0,C.jsxs)(`select`,{id:`agent-provider`,value:M,onChange:e=>ce(e.target.value),className:`w-full mt-1 px-3 py-2 border border-input bg-background rounded-md text-sm focus:outline-none focus:ring-2 focus:ring-ring`,disabled:q,children:[(0,C.jsx)(`option`,{value:`anthropic`,children:`Anthropic Claude`}),(0,C.jsx)(`option`,{value:`openai`,children:`OpenAI GPT`}),(0,C.jsx)(`option`,{value:`ollama`,children:`Ollama (Local)`})]})]}),(0,C.jsxs)(`div`,{children:[(0,C.jsx)(`label`,{htmlFor:`agent-model`,className:`text-sm font-medium`,children:`Model`}),(0,C.jsx)(ee,{id:`agent-model`,value:N,onChange:(e,t)=>{P(e),t?.maxTokens&&I(e=>({...e,maxTokens:t.maxTokens}))},...L,disabled:q})]})]}),(0,C.jsxs)(`div`,{className:`space-y-4`,children:[(0,C.jsx)(`h3`,{className:`text-lg font-medium`,children:`Persona`}),(0,C.jsxs)(`div`,{children:[(0,C.jsx)(`label`,{htmlFor:`agent-role`,className:`text-sm font-medium`,children:`Role`}),(0,C.jsx)(f,{id:`agent-role`,value:z,onChange:e=>B(e.target.value),placeholder:`e.g. Software Engineer`,disabled:q})]}),(0,C.jsxs)(`div`,{children:[(0,C.jsx)(`label`,{htmlFor:`agent-identity`,className:`text-sm font-medium`,children:`Identity`}),(0,C.jsx)(`textarea`,{id:`agent-identity`,value:V,onChange:e=>H(e.target.value),placeholder:`Who this agent is…`,disabled:q,className:`w-full mt-1 px-3 py-2 border border-input bg-background rounded-md text-sm min-h-[80px] resize-y`})]}),(0,C.jsxs)(`div`,{children:[(0,C.jsx)(`label`,{htmlFor:`agent-instructions`,className:`text-sm font-medium`,children:`Instructions`}),(0,C.jsx)(`textarea`,{id:`agent-instructions`,value:U,onChange:e=>W(e.target.value),placeholder:`Behavioral instructions…`,disabled:q,className:`w-full mt-1 px-3 py-2 border border-input bg-background rounded-md text-sm min-h-[80px] resize-y`})]})]}),(0,C.jsxs)(`div`,{children:[(0,C.jsx)(`label`,{htmlFor:`system-prompt`,className:`text-sm font-medium`,children:`System Prompt (Optional Override)`}),(0,C.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`Built from Role, Identity and Instructions unless you enter an override.`}),(0,C.jsx)(`textarea`,{id:`system-prompt`,value:G,onChange:e=>K(e.target.value),placeholder:x(z,V,U)||`System prompt sent to the LLM…`,className:`w-full mt-1 px-3 py-2 border border-input bg-background rounded-md text-sm focus:outline-none focus:ring-2 focus:ring-ring min-h-[80px] resize-y`,disabled:q})]}),(0,C.jsxs)(`div`,{className:`grid gap-4 md:grid-cols-2`,children:[(0,C.jsxs)(`div`,{children:[(0,C.jsx)(`label`,{htmlFor:`api-key`,className:`text-sm font-medium`,children:`API Key (Optional)`}),(0,C.jsx)(f,{id:`api-key`,type:`password`,value:F.apiKey,onChange:e=>I(t=>({...t,apiKey:e.target.value})),placeholder:`Enter your API key`,disabled:q})]}),(0,C.jsxs)(`div`,{children:[(0,C.jsx)(`label`,{htmlFor:`baseUrl`,className:`text-sm font-medium`,children:`Base URL (Optional)`}),(0,C.jsx)(f,{id:`baseUrl`,value:F.baseUrl,onChange:e=>I(t=>({...t,baseUrl:e.target.value})),placeholder:e[M],disabled:q})]})]}),(0,C.jsxs)(`div`,{className:`space-y-4`,children:[(0,C.jsx)(`h3`,{className:`text-lg font-medium`,children:`LLM Parameters`}),(0,C.jsxs)(`div`,{className:`grid gap-4 md:grid-cols-2 lg:grid-cols-4`,children:[(0,C.jsxs)(`div`,{children:[(0,C.jsx)(`label`,{htmlFor:`max-tokens`,className:`text-sm font-medium`,children:`Max Output Tokens`}),(0,C.jsx)(f,{id:`max-tokens`,type:`number`,min:`1`,max:R?.maxTokens,value:F.maxTokens,onChange:e=>I(t=>({...t,maxTokens:parseInt(e.target.value)||4096})),disabled:q})]}),M!==`anthropic`&&(0,C.jsxs)(`div`,{children:[(0,C.jsx)(`label`,{htmlFor:`temperature`,className:`text-sm font-medium`,children:`Temperature`}),(0,C.jsx)(f,{id:`temperature`,type:`number`,min:`0`,max:`2`,step:`0.1`,value:F.temperature,onChange:e=>I(t=>({...t,temperature:Number.isNaN(e.target.valueAsNumber)?.7:e.target.valueAsNumber})),disabled:q})]}),(0,C.jsxs)(`div`,{children:[(0,C.jsx)(`label`,{htmlFor:`top-p`,className:`text-sm font-medium`,children:`Top P`}),(0,C.jsx)(f,{id:`top-p`,type:`number`,min:`0`,max:`1`,step:`0.1`,value:F.topP,onChange:e=>I(t=>({...t,topP:Number.isNaN(e.target.valueAsNumber)?1:e.target.valueAsNumber})),disabled:q})]}),M===`ollama`&&(0,C.jsxs)(`div`,{children:[(0,C.jsx)(`label`,{htmlFor:`num-ctx`,className:`text-sm font-medium`,children:`Context Length`}),(0,C.jsx)(f,{id:`num-ctx`,type:`number`,min:`1024`,max:R?.contextWindow,value:F.numCtx,onChange:e=>I(t=>({...t,numCtx:parseInt(e.target.value)||4096})),disabled:q})]})]}),M!==`ollama`&&(0,C.jsxs)(`div`,{className:`grid gap-4 md:grid-cols-2`,children:[(0,C.jsxs)(`div`,{children:[(0,C.jsx)(`label`,{htmlFor:`frequency-penalty`,className:`text-sm font-medium`,children:`Frequency Penalty`}),(0,C.jsx)(f,{id:`frequency-penalty`,type:`number`,min:`-2`,max:`2`,step:`0.1`,value:F.frequencyPenalty,onChange:e=>I(t=>({...t,frequencyPenalty:parseFloat(e.target.value)||0})),disabled:q})]}),(0,C.jsxs)(`div`,{children:[(0,C.jsx)(`label`,{htmlFor:`presence-penalty`,className:`text-sm font-medium`,children:`Presence Penalty`}),(0,C.jsx)(f,{id:`presence-penalty`,type:`number`,min:`-2`,max:`2`,step:`0.1`,value:F.presencePenalty,onChange:e=>I(t=>({...t,presencePenalty:parseFloat(e.target.value)||0})),disabled:q})]})]})]}),(0,C.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,C.jsx)(`label`,{htmlFor:`agent-color`,className:`text-sm font-medium`,children:`Agent Color`}),(0,C.jsx)(f,{id:`agent-color`,type:`color`,value:O,onChange:e=>k(e.target.value),className:`h-10 w-16 p-1`,disabled:q}),(0,C.jsx)(d,{type:`button`,variant:`outline`,size:`sm`,onClick:()=>k(m()),disabled:q,children:`Randomize`})]}),(0,C.jsxs)(d,{type:`submit`,disabled:q||!u.trim(),children:[(0,C.jsx)(o,{className:`mr-2 h-4 w-4`}),`Create Agent`]})]})}),(0,C.jsxs)(`div`,{className:`space-y-4`,children:[(0,C.jsx)(`h2`,{className:`text-xl font-semibold`,children:`Your Agents`}),a&&(0,C.jsx)(`p`,{className:`text-center text-muted-foreground`,children:`Loading agents...`}),c&&(0,C.jsx)(`div`,{className:`text-center text-destructive`,children:(0,C.jsx)(`p`,{children:c})}),!a&&!c&&n.length===0&&(0,C.jsx)(`p`,{className:`text-center text-muted-foreground`,children:`No agents found`}),n.length>0&&(0,C.jsx)(`div`,{className:`grid gap-4`,children:n.map(e=>(0,C.jsx)(w,{agent:e,onStart:ue,onStop:de,onEnter:fe},e.id))})]})]})}export{T 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{I as i,It as a,Pt as o,Qr as s,Sr as c,rn as l,rt as u}from"./ui-CDoK3F3U.js";import{t as d}from"./button-SeUZ_Pvi.js";import{t as f}from"./input-BOtCd4HP.js";import{n as p}from"./use-toast-BlLDqSUO.js";import{t as m}from"./color-DFEH4BfK.js";import{R as h,Y as g,kt as _,nt as v,tt as y}from"./index-B01BkfMJ.js";import{n as b}from"./page-header-DrDt1sQ2.js";import{n as ee,r as x,t as te}from"./useAgentModels-KcfEQ6u9.js";import{t as ne}from"./form-panel-3p-ncEVK.js";import{t as re}from"./use-create-panel-DhSNIGtr.js";import{n as ie,t as ae}from"./useSocketSubscription-ifW-vnlb.js";var S=e(n(),1),C=t();function w({agent:e,onStart:t,onStop:n,onEnter:r}){let[o,f]=(0,S.useState)(!1),p=async()=>{f(!0);try{await t(e.name)}finally{f(!1)}},m=async()=>{f(!0);try{await n(e.name)}finally{f(!1)}},h=()=>{switch(e.status){case`active`:return(0,C.jsx)(c,{className:`h-4 w-4 text-success`});case`inactive`:return(0,C.jsx)(c,{className:`h-4 w-4 text-warning`});case`error`:return(0,C.jsx)(c,{className:`h-4 w-4 text-destructive`});default:return(0,C.jsx)(c,{className:`h-4 w-4 text-muted-foreground`})}},g=()=>{switch(e.llmProvider){case`anthropic`:return(0,C.jsx)(s,{className:`h-4 w-4 text-warning`});case`openai`:return(0,C.jsx)(s,{className:`h-4 w-4 text-success`});case`ollama`:return(0,C.jsx)(i,{className:`h-4 w-4 text-info`});default:return(0,C.jsx)(s,{className:`h-4 w-4 text-muted-foreground`})}},_=()=>{switch(e.status){case`active`:return`text-success bg-success-subtle border-success`;case`inactive`:return`text-warning bg-warning-subtle border-warning`;case`error`:return`text-destructive bg-destructive-subtle border-destructive`;case`available`:return`text-info bg-info-subtle border-info`;default:return`text-foreground bg-muted border-border`}},v=e.status===`available`||e.status===`inactive`,y=e.status===`active`;return(0,C.jsxs)(`div`,{className:`border rounded-lg p-4 space-y-4 hover:shadow-elevation-2 transition-shadow bg-card`,children:[(0,C.jsxs)(`div`,{className:`flex items-start justify-between`,children:[(0,C.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,C.jsxs)(`div`,{className:`flex items-center gap-2 mb-1`,children:[g(),(0,C.jsx)(`h3`,{className:`text-lg font-semibold truncate`,children:e.label||e.name}),e.color&&(0,C.jsx)(`div`,{className:`w-4 h-4 rounded border flex-shrink-0`,style:{backgroundColor:e.color},title:`Color: ${e.color}`})]}),(0,C.jsx)(`p`,{className:`text-sm text-muted-foreground font-mono`,children:e.name}),e.description&&(0,C.jsx)(`p`,{className:`text-sm text-muted-foreground mt-1 line-clamp-2`,children:e.description})]}),(0,C.jsxs)(`div`,{className:`flex items-center gap-2 flex-shrink-0`,children:[h(),(0,C.jsx)(`span`,{className:`px-2 py-1 rounded-full text-xs font-medium border ${_()}`,children:e.status})]})]}),(0,C.jsxs)(`div`,{className:`grid grid-cols-2 gap-4 text-sm`,children:[(0,C.jsxs)(`div`,{children:[(0,C.jsx)(`span`,{className:`text-muted-foreground`,children:`Provider:`}),(0,C.jsx)(`div`,{className:`font-medium capitalize`,children:e.llmProvider})]}),(0,C.jsxs)(`div`,{children:[(0,C.jsx)(`span`,{className:`text-muted-foreground`,children:`Model:`}),(0,C.jsx)(`div`,{className:`font-mono text-xs`,children:e.model})]}),(0,C.jsxs)(`div`,{children:[(0,C.jsx)(`span`,{className:`text-muted-foreground`,children:`Created:`}),(0,C.jsx)(`div`,{children:new Date(e.createdAt).toLocaleDateString()})]}),(0,C.jsxs)(`div`,{children:[(0,C.jsx)(`span`,{className:`text-muted-foreground`,children:`Last Access:`}),(0,C.jsx)(`div`,{children:e.lastAccessed?new Date(e.lastAccessed).toLocaleDateString():`Never`})]})]}),e.config.mcp?.servers&&e.config.mcp.servers.length>0&&(0,C.jsxs)(`div`,{className:`text-sm`,children:[(0,C.jsx)(`span`,{className:`text-muted-foreground`,children:`MCP Servers:`}),(0,C.jsx)(`div`,{className:`flex flex-wrap gap-1 mt-1`,children:e.config.mcp.servers.map((e,t)=>(0,C.jsx)(`span`,{className:`px-2 py-1 bg-secondary text-secondary-foreground rounded text-xs`,children:e.name},t))})]}),(0,C.jsxs)(`div`,{className:`flex gap-2 pt-2 border-t`,children:[v&&(0,C.jsxs)(d,{onClick:p,disabled:o,size:`sm`,variant:`outline`,className:`flex-1`,children:[(0,C.jsx)(a,{className:`mr-2 h-4 w-4`}),`Start`]}),y&&(0,C.jsxs)(d,{onClick:m,disabled:o,size:`sm`,variant:`outline`,className:`flex-1`,children:[(0,C.jsx)(u,{className:`mr-2 h-4 w-4`}),`Stop`]}),(0,C.jsxs)(d,{onClick:()=>r(e.name),size:`sm`,className:`flex-1`,children:[(0,C.jsx)(l,{className:`mr-2 h-4 w-4`}),`Chat`]})]})]})}function T(){let e={anthropic:`https://api.anthropic.com`,openai:`https://api.openai.com/v1`,ollama:`http://localhost:11434/v1`},t={anthropic:`claude-3-5-sonnet-20241022`,openai:`gpt-4o`,ollama:`qwen2.5-coder:latest`},[n,i]=(0,S.useState)([]),[a,s]=(0,S.useState)(!0),[c,l]=(0,S.useState)(null),[u,T]=(0,S.useState)(``),[E,D]=(0,S.useState)(``),[O,k]=(0,S.useState)(m()),[A,j]=(0,S.useState)(``),[M,oe]=(0,S.useState)(`anthropic`),[N,P]=(0,S.useState)(t.anthropic),[F,I]=(0,S.useState)({apiKey:``,baseUrl:e.anthropic,maxTokens:4096,temperature:.7,topP:1,frequencyPenalty:0,presencePenalty:0,numCtx:4096}),L=te(M,F.apiKey,F.baseUrl),R=L.models.find(e=>e.id===N),[z,B]=(0,S.useState)(``),[V,H]=(0,S.useState)(``),[U,W]=(0,S.useState)(``),[G,K]=(0,S.useState)(``),[q,J]=(0,S.useState)(!1),Y=_(),[X,Z]=re(),{showToast:Q}=p(),se=r(),$=ie();ae($,`agent`,{"agent:status:changed":e=>{i(t=>t.map(t=>t.id===e.agentId?{...t,status:e.status,isActive:e.isActive}:t))},"agent:created":e=>{i(t=>[...t,e.agent])},"agent:deleted":e=>{i(t=>t.filter(t=>t.id!==e.agentId))}});let ce=n=>{oe(n),P(t[n]),I({apiKey:``,baseUrl:e[n],maxTokens:4096,temperature:.7,topP:1,frequencyPenalty:0,presencePenalty:0,numCtx:4096})};(0,S.useEffect)(()=>((async()=>{try{s(!0);let e=await g();i(e),l(null)}catch(e){console.error(`Agent fetch error:`,e);let t=`Failed to fetch agents`;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 agents`}l(t),Q({title:`Error`,description:t,variant:`destructive`})}finally{s(!1)}})(),()=>{}),[$,Q]);let le=async t=>{if(t.preventDefault(),u.trim()){J(!0);try{let t=G.trim()||x(z,V,U),n={name:u,label:A||u,description:E||void 0,color:O,llmProvider:M,model:N,apiKey:F.apiKey.trim()||void 0,baseUrl:F.baseUrl.trim()||void 0,config:{type:M,model:N,identity:{role:z.trim()||void 0,identity:V.trim()||void 0,instructions:U.trim()||void 0},prompts:t?{system:t}:void 0,connectors:{[M]:{maxTokens:F.maxTokens,...M===`anthropic`?{}:{temperature:F.temperature},topP:F.topP,frequencyPenalty:F.frequencyPenalty,presencePenalty:F.presencePenalty,...M===`ollama`?{numCtx:F.numCtx}:{}}}},mcp:{enabled:!0,servers:[{name:`weather`,command:`node`,args:[`src/managers/agent/mcp-servers/weather.js`]}]}},r=await h(n);i(e=>[...e,r]),T(``),D(``),k(m()),j(``),K(``),B(``),H(``),W(``),I({apiKey:``,baseUrl:e[M],maxTokens:4096,temperature:.7,topP:1,frequencyPenalty:0,presencePenalty:0,numCtx:4096}),Q({title:`Success`,description:`Agent '${r.label||r.name}' created.`}),Z(!1)}catch(e){console.error(`Agent creation error:`,e);let t=`Failed to create agent`;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 create agent`}Q({title:`Error`,description:t,variant:`destructive`})}finally{J(!1)}}},ue=async e=>{try{let t=await y(e);i(e=>e.map(e=>e.name===t.name?t:e)),Q({title:`Success`,description:`Agent '${t.label||t.name}' started.`})}catch(e){console.error(`Agent start error:`,e);let t=`Failed to start agent`;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 start agent`}Q({title:`Error`,description:t,variant:`destructive`})}},de=async e=>{try{await v(e),i(t=>t.map(t=>t.name===e?{...t,status:`inactive`,isActive:!1}:t)),Q({title:`Success`,description:`Agent '${e}' stopped.`})}catch(e){console.error(`Agent stop error:`,e);let t=`Failed to stop agent`;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 stop agent`}Q({title:`Error`,description:t,variant:`destructive`})}},fe=e=>{se(`/agents/${e}`)};return(0,C.jsxs)(`div`,{className:`space-y-6`,children:[(0,C.jsx)(b,{title:`AI Agents`,description:`Create and manage your AI agents with multiple LLM providers`,actions:!Y.local&&!X&&(0,C.jsxs)(d,{onClick:()=>Z(!0),className:`max-sm:h-9 max-sm:w-9 max-sm:p-0`,"aria-label":`Create agent`,title:`Create agent`,children:[(0,C.jsx)(o,{className:`h-4 w-4 sm:mr-2`}),(0,C.jsx)(`span`,{className:`max-sm:hidden`,children:`Create Agent`})]})}),!Y.local&&X&&(0,C.jsx)(ne,{title:`Create New Agent`,onClose:()=>Z(!1),children:(0,C.jsxs)(`form`,{onSubmit:le,className:`space-y-4`,children:[(0,C.jsxs)(`div`,{className:`grid gap-4 md:grid-cols-2`,children:[(0,C.jsx)(f,{value:u,onChange:e=>T(e.target.value),placeholder:`Agent Name (e.g., 'my-assistant')`,disabled:q}),(0,C.jsx)(f,{value:A,onChange:e=>j(e.target.value),placeholder:`Agent Label (display name, optional)`,disabled:q})]}),(0,C.jsx)(f,{value:E,onChange:e=>D(e.target.value),placeholder:`Description (optional)`,disabled:q}),(0,C.jsxs)(`div`,{className:`grid gap-4 md:grid-cols-2`,children:[(0,C.jsxs)(`div`,{children:[(0,C.jsx)(`label`,{htmlFor:`agent-provider`,className:`text-sm font-medium`,children:`LLM Provider`}),(0,C.jsxs)(`select`,{id:`agent-provider`,value:M,onChange:e=>ce(e.target.value),className:`w-full mt-1 px-3 py-2 border border-input bg-background rounded-md text-sm focus:outline-none focus:ring-2 focus:ring-ring`,disabled:q,children:[(0,C.jsx)(`option`,{value:`anthropic`,children:`Anthropic Claude`}),(0,C.jsx)(`option`,{value:`openai`,children:`OpenAI GPT`}),(0,C.jsx)(`option`,{value:`ollama`,children:`Ollama (Local)`})]})]}),(0,C.jsxs)(`div`,{children:[(0,C.jsx)(`label`,{htmlFor:`agent-model`,className:`text-sm font-medium`,children:`Model`}),(0,C.jsx)(ee,{id:`agent-model`,value:N,onChange:(e,t)=>{P(e),t?.maxTokens&&I(e=>({...e,maxTokens:t.maxTokens}))},...L,disabled:q})]})]}),(0,C.jsxs)(`div`,{className:`space-y-4`,children:[(0,C.jsx)(`h3`,{className:`text-lg font-medium`,children:`Persona`}),(0,C.jsxs)(`div`,{children:[(0,C.jsx)(`label`,{htmlFor:`agent-role`,className:`text-sm font-medium`,children:`Role`}),(0,C.jsx)(f,{id:`agent-role`,value:z,onChange:e=>B(e.target.value),placeholder:`e.g. Software Engineer`,disabled:q})]}),(0,C.jsxs)(`div`,{children:[(0,C.jsx)(`label`,{htmlFor:`agent-identity`,className:`text-sm font-medium`,children:`Identity`}),(0,C.jsx)(`textarea`,{id:`agent-identity`,value:V,onChange:e=>H(e.target.value),placeholder:`Who this agent is…`,disabled:q,className:`w-full mt-1 px-3 py-2 border border-input bg-background rounded-md text-sm min-h-[80px] resize-y`})]}),(0,C.jsxs)(`div`,{children:[(0,C.jsx)(`label`,{htmlFor:`agent-instructions`,className:`text-sm font-medium`,children:`Instructions`}),(0,C.jsx)(`textarea`,{id:`agent-instructions`,value:U,onChange:e=>W(e.target.value),placeholder:`Behavioral instructions…`,disabled:q,className:`w-full mt-1 px-3 py-2 border border-input bg-background rounded-md text-sm min-h-[80px] resize-y`})]})]}),(0,C.jsxs)(`div`,{children:[(0,C.jsx)(`label`,{htmlFor:`system-prompt`,className:`text-sm font-medium`,children:`System Prompt (Optional Override)`}),(0,C.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`Built from Role, Identity and Instructions unless you enter an override.`}),(0,C.jsx)(`textarea`,{id:`system-prompt`,value:G,onChange:e=>K(e.target.value),placeholder:x(z,V,U)||`System prompt sent to the LLM…`,className:`w-full mt-1 px-3 py-2 border border-input bg-background rounded-md text-sm focus:outline-none focus:ring-2 focus:ring-ring min-h-[80px] resize-y`,disabled:q})]}),(0,C.jsxs)(`div`,{className:`grid gap-4 md:grid-cols-2`,children:[(0,C.jsxs)(`div`,{children:[(0,C.jsx)(`label`,{htmlFor:`api-key`,className:`text-sm font-medium`,children:`API Key (Optional)`}),(0,C.jsx)(f,{id:`api-key`,type:`password`,value:F.apiKey,onChange:e=>I(t=>({...t,apiKey:e.target.value})),placeholder:`Enter your API key`,disabled:q})]}),(0,C.jsxs)(`div`,{children:[(0,C.jsx)(`label`,{htmlFor:`baseUrl`,className:`text-sm font-medium`,children:`Base URL (Optional)`}),(0,C.jsx)(f,{id:`baseUrl`,value:F.baseUrl,onChange:e=>I(t=>({...t,baseUrl:e.target.value})),placeholder:e[M],disabled:q})]})]}),(0,C.jsxs)(`div`,{className:`space-y-4`,children:[(0,C.jsx)(`h3`,{className:`text-lg font-medium`,children:`LLM Parameters`}),(0,C.jsxs)(`div`,{className:`grid gap-4 md:grid-cols-2 lg:grid-cols-4`,children:[(0,C.jsxs)(`div`,{children:[(0,C.jsx)(`label`,{htmlFor:`max-tokens`,className:`text-sm font-medium`,children:`Max Output Tokens`}),(0,C.jsx)(f,{id:`max-tokens`,type:`number`,min:`1`,max:R?.maxTokens,value:F.maxTokens,onChange:e=>I(t=>({...t,maxTokens:parseInt(e.target.value)||4096})),disabled:q})]}),M!==`anthropic`&&(0,C.jsxs)(`div`,{children:[(0,C.jsx)(`label`,{htmlFor:`temperature`,className:`text-sm font-medium`,children:`Temperature`}),(0,C.jsx)(f,{id:`temperature`,type:`number`,min:`0`,max:`2`,step:`0.1`,value:F.temperature,onChange:e=>I(t=>({...t,temperature:Number.isNaN(e.target.valueAsNumber)?.7:e.target.valueAsNumber})),disabled:q})]}),(0,C.jsxs)(`div`,{children:[(0,C.jsx)(`label`,{htmlFor:`top-p`,className:`text-sm font-medium`,children:`Top P`}),(0,C.jsx)(f,{id:`top-p`,type:`number`,min:`0`,max:`1`,step:`0.1`,value:F.topP,onChange:e=>I(t=>({...t,topP:Number.isNaN(e.target.valueAsNumber)?1:e.target.valueAsNumber})),disabled:q})]}),M===`ollama`&&(0,C.jsxs)(`div`,{children:[(0,C.jsx)(`label`,{htmlFor:`num-ctx`,className:`text-sm font-medium`,children:`Context Length`}),(0,C.jsx)(f,{id:`num-ctx`,type:`number`,min:`1024`,max:R?.contextWindow,value:F.numCtx,onChange:e=>I(t=>({...t,numCtx:parseInt(e.target.value)||4096})),disabled:q})]})]}),M!==`ollama`&&(0,C.jsxs)(`div`,{className:`grid gap-4 md:grid-cols-2`,children:[(0,C.jsxs)(`div`,{children:[(0,C.jsx)(`label`,{htmlFor:`frequency-penalty`,className:`text-sm font-medium`,children:`Frequency Penalty`}),(0,C.jsx)(f,{id:`frequency-penalty`,type:`number`,min:`-2`,max:`2`,step:`0.1`,value:F.frequencyPenalty,onChange:e=>I(t=>({...t,frequencyPenalty:parseFloat(e.target.value)||0})),disabled:q})]}),(0,C.jsxs)(`div`,{children:[(0,C.jsx)(`label`,{htmlFor:`presence-penalty`,className:`text-sm font-medium`,children:`Presence Penalty`}),(0,C.jsx)(f,{id:`presence-penalty`,type:`number`,min:`-2`,max:`2`,step:`0.1`,value:F.presencePenalty,onChange:e=>I(t=>({...t,presencePenalty:parseFloat(e.target.value)||0})),disabled:q})]})]})]}),(0,C.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,C.jsx)(`label`,{htmlFor:`agent-color`,className:`text-sm font-medium`,children:`Agent Color`}),(0,C.jsx)(f,{id:`agent-color`,type:`color`,value:O,onChange:e=>k(e.target.value),className:`h-10 w-16 p-1`,disabled:q}),(0,C.jsx)(d,{type:`button`,variant:`outline`,size:`sm`,onClick:()=>k(m()),disabled:q,children:`Randomize`})]}),(0,C.jsxs)(d,{type:`submit`,disabled:q||!u.trim(),children:[(0,C.jsx)(o,{className:`mr-2 h-4 w-4`}),`Create Agent`]})]})}),(0,C.jsxs)(`div`,{className:`space-y-4`,children:[(0,C.jsx)(`h2`,{className:`text-xl font-semibold`,children:`Your Agents`}),a&&(0,C.jsx)(`p`,{className:`text-center text-muted-foreground`,children:`Loading agents...`}),c&&(0,C.jsx)(`div`,{className:`text-center text-destructive`,children:(0,C.jsx)(`p`,{children:c})}),!a&&!c&&n.length===0&&(0,C.jsx)(`p`,{className:`text-center text-muted-foreground`,children:`No agents found`}),n.length>0&&(0,C.jsx)(`div`,{className:`grid gap-4`,children:n.map(e=>(0,C.jsx)(w,{agent:e,onStart:ue,onStop:de,onEnter:fe},e.id))})]})]})}export{T 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{Wr as r,Xt as i,Yt as a,et as o}from"./ui-CDoK3F3U.js";import{t as s}from"./utils-2pl1SbIp.js";import{a as c,i as l,n as u,o as d,r as f,s as p,t as m}from"./document-open-mode-DoImW-xs.js";import{d as h,f as g,l as _,o as v,s as y,u as b}from"./use-menu-DIP1zh7I.js";import{t as x}from"./use-theme-DaxpiICf.js";import{Ct as S,St as C,a as w,c as T,d as E,f as D,i as O,l as k,m as A,n as j,o as M,p as N,r as P,s as F,t as I,u as L,xt as R}from"./index-CXPA9Fj8.js";import{n as z}from"./page-header-DrDt1sQ2.js";import{t as B}from"./use-settings-back-DGmLAD63.js";var V=e(n(),1),H=t(),U={system:i,light:o,dark:a};function W(){let{theme:e,scheme:t,density:n,resolvedScheme:i,setTheme:a,setScheme:o,setDensity:w,reset:T}=x(),E=l(),O=u(),k=h(),j=p(),M=S(),P=g();return(0,H.jsxs)(`div`,{className:`space-y-8`,children:[(0,H.jsxs)(`section`,{children:[(0,H.jsx)(J,{title:`Theme`,description:`Palette, shape and typography. Each theme defines its own light and dark variants.`}),(0,H.jsx)(`div`,{className:`grid gap-3 sm:grid-cols-2 lg:grid-cols-3`,children:A.map(t=>{let n=t.id===e;return(0,H.jsxs)(`button`,{type:`button`,onClick:()=>a(t.id),"aria-pressed":n,className:s(`focus-ring group flex flex-col gap-3 rounded-lg border p-4 text-left transition-colors`,n?`border-primary bg-accent`:`border-border hover:border-muted-foreground/40 hover:bg-accent/50`),children:[(0,H.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,H.jsx)(`span`,{className:`text-sm font-medium`,children:t.name}),n&&(0,H.jsx)(r,{className:`size-4 shrink-0 text-primary`})]}),(0,H.jsx)(`div`,{className:`flex gap-1.5`,"aria-hidden":!0,children:t.swatches.map(e=>(0,H.jsx)(`span`,{className:`size-6 rounded-full border border-border`,style:{backgroundColor:e}},e))}),(0,H.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:t.description})]},t.id)})})]}),(0,H.jsxs)(`section`,{children:[(0,H.jsx)(J,{title:`Colour scheme`,description:t===`system`?`Following your system setting, currently ${i}.`:`Overrides your system setting.`}),(0,H.jsx)(Y,{options:N.map(e=>{let t=U[e.id];return{id:e.id,label:e.name,icon:(0,H.jsx)(t,{className:`size-4 shrink-0`})}}),value:t,onChange:o})]}),(0,H.jsxs)(`section`,{children:[(0,H.jsx)(J,{title:`Density`,description:`Controls row height, hit-target size and shell spacing across the whole app.`}),(0,H.jsx)(Y,{options:D.map(e=>({id:e.id,label:e.name,title:e.description})),value:n,onChange:w}),(0,H.jsx)(`p`,{className:`mt-2 text-xs text-muted-foreground`,children:D.find(e=>e.id===n)?.description})]}),(0,H.jsxs)(`section`,{children:[(0,H.jsx)(J,{title:`Layout`,description:`How menus and content share the screen. Device-local, like the wallpaper.`}),(0,H.jsx)(Y,{options:y.map(e=>({id:e.id,label:e.name,title:e.description})),value:k,onChange:_}),(0,H.jsx)(`p`,{className:`mt-2 text-xs text-muted-foreground`,children:y.find(e=>e.id===k)?.description}),k===`strip`&&(0,H.jsxs)(`div`,{className:`mt-4`,children:[(0,H.jsx)(`p`,{className:`mb-2 text-sm font-medium`,children:`Navigation keys`}),(0,H.jsx)(Y,{options:v.map(e=>({id:e.id,label:e.name,title:e.description})),value:P,onChange:b}),(0,H.jsxs)(`p`,{className:`mt-2 text-xs text-muted-foreground`,children:[v.find(e=>e.id===P)?.description,` `,`Left and right walk the columns, up and down switch pin rows.`]})]})]}),(0,H.jsxs)(`section`,{children:[(0,H.jsx)(J,{title:`Tree style`,description:`How workspace and context trees are drawn in the menu. Device-local.`}),(0,H.jsx)(Y,{options:R.map(e=>({id:e.id,label:e.name,title:e.description})),value:M,onChange:C}),(0,H.jsx)(`p`,{className:`mt-2 text-xs text-muted-foreground`,children:R.find(e=>e.id===M)?.description})]}),(0,H.jsxs)(`section`,{children:[(0,H.jsx)(J,{title:`Open documents`,description:`Choose how documents open from lists, tiles and boards. Saved on this device.`}),(0,H.jsx)(Y,{options:[{id:`modal`,label:`Modal`},{id:`side`,label:`Side reading pane`}],value:O,onChange:m}),(0,H.jsx)(`p`,{className:`mt-2 text-xs text-muted-foreground`,children:`The reading pane opens beside the content and updates as you select another document. On small screens it opens as a drawer.`})]}),(0,H.jsxs)(`section`,{children:[(0,H.jsx)(J,{title:`Always-on content area`,description:`Keep a reading pane beside document lists on tablets and desktops. Remember the selected item in each folder, or show the first available item.`}),(0,H.jsx)(Y,{options:[{id:`on`,label:`On`},{id:`off`,label:`Off`}],value:E?`on`:`off`,onChange:e=>f(e===`on`)}),(0,H.jsx)(`p`,{className:`mt-2 text-xs text-muted-foreground`,children:`On by default. The reader uses roughly half the screen; drag its divider to resize. Phones keep tap-to-open navigation. When enabled, list selections use this pane regardless of the Open documents setting.`})]}),(0,H.jsxs)(`section`,{children:[(0,H.jsx)(J,{title:`Document tiles`,description:`Choose the photo and media layout for tile view. Saved on this device.`}),(0,H.jsx)(Y,{options:c,value:j,onChange:d})]}),(0,H.jsx)(G,{}),(0,H.jsx)(`section`,{children:(0,H.jsx)(`button`,{type:`button`,onClick:()=>{T(),m(`modal`)},className:`focus-ring rounded-md text-sm text-muted-foreground underline-offset-4 hover:text-foreground hover:underline`,children:`Reset to defaults`})})]})}function G(){let[e,t]=(0,V.useState)(M),[n,r]=(0,V.useState)(null),[i,a]=(0,V.useState)(!0),[o,s]=(0,V.useState)(!1),c=(0,V.useRef)(!1);(0,V.useEffect)(()=>{let e=!1;return T().then(()=>{e||(t(M()),a(!1))}),()=>{e=!0}},[]);let l=async(e,n)=>{if(!c.current){c.current=!0,s(!0);try{let i=n?{...e,image:await F(n)}:e;await k(i),t(i),r(null)}catch(e){r(e instanceof Error&&e.name!==`QuotaExceededError`?e.message:`Could not store the wallpaper. Free some browser storage or try a smaller image.`)}finally{c.current=!1,s(!1)}}},u=t=>{t&&l(e,t)},d=e.image!==null&&P(e.image)===null,f=L(e.image);return(0,H.jsx)(`section`,{children:(0,H.jsxs)(`fieldset`,{disabled:i||o,className:`min-w-0`,children:[(0,H.jsx)(J,{title:`Wallpaper`,description:`Background image for the desk behind all panels. Without one, the theme's desk color shows (the default).`}),(0,H.jsxs)(`div`,{role:`radiogroup`,"aria-label":`Wallpaper`,className:`grid grid-cols-3 gap-3 sm:grid-cols-4 lg:grid-cols-6`,children:[(0,H.jsx)(q,{label:`None`,isActive:e.image===null,onSelect:()=>l({...e,image:null}),children:(0,H.jsx)(`span`,{className:`flex size-full items-center justify-center surface-desk text-xs text-muted-foreground`,style:{backgroundImage:`none`},children:`None`})}),I.map(t=>(0,H.jsx)(q,{label:t.title,title:`${t.title} — suits the ${t.scheme} scheme`,isActive:P(e.image)===t.id,onSelect:()=>l({...e,image:O(t.id)}),children:(0,H.jsx)(`img`,{src:w(t),alt:``,loading:`lazy`,className:`size-full object-cover`,style:{backgroundColor:t.background}})},t.id)),d&&(0,H.jsx)(q,{label:`Your image`,isActive:!0,onSelect:()=>{},children:(0,H.jsx)(`img`,{src:e.image??void 0,alt:``,className:`size-full object-cover`})})]}),(0,H.jsx)(K,{}),(0,H.jsxs)(`div`,{className:`mt-4 flex flex-wrap items-center gap-3`,children:[(0,H.jsx)(`div`,{className:`h-20 w-32 shrink-0 rounded-md border surface-desk`,style:f?{backgroundImage:f,backgroundSize:E(e.fit),backgroundPosition:`center`,backgroundRepeat:`no-repeat`}:void 0,"aria-hidden":!0}),(0,H.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,H.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[(0,H.jsxs)(`label`,{className:`focus-ring inline-flex cursor-pointer items-center rounded-md border px-3 py-1.5 text-sm hover:bg-accent/50`,children:[d?`Change image…`:`Use your own image…`,(0,H.jsx)(`input`,{type:`file`,accept:`image/*,.gif`,className:`hidden`,onChange:e=>{u(e.target.files?.[0]),e.target.value=``}})]}),e.image&&(0,H.jsx)(`button`,{type:`button`,onClick:()=>l({...e,image:null}),className:`focus-ring rounded-md border px-3 py-1.5 text-sm text-muted-foreground hover:bg-accent/50 hover:text-foreground`,children:`Remove`})]}),(0,H.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`Images and animated GIFs up to 10 MB. Stored on this device.`}),(0,H.jsx)(Y,{options:j.map(e=>({id:e.id,label:e.label,title:e.description})),value:e.fit,onChange:t=>l({...e,fit:t})}),n&&(0,H.jsx)(`p`,{className:`text-xs text-destructive`,children:n}),o&&(0,H.jsx)(`p`,{role:`status`,className:`text-xs text-muted-foreground`,children:`Saving wallpaper…`})]})]})]})})}function K(){let e=I.filter(e=>e.author!==`Canvas`);return e.length===0?null:(0,H.jsx)(`p`,{className:`mt-2 text-xs text-muted-foreground`,children:e.map((e,t)=>(0,H.jsxs)(`span`,{children:[t>0&&` · `,e.title,` © `,e.author,e.source&&(0,H.jsxs)(H.Fragment,{children:[` `,(0,H.jsx)(`a`,{href:e.source,target:`_blank`,rel:`noreferrer noopener`,className:`focus-ring underline underline-offset-2 hover:text-foreground`,children:new URL(e.source).hostname})]})]},e.id))})}function q({label:e,title:t,isActive:n,onSelect:i,children:a}){return(0,H.jsxs)(`button`,{type:`button`,role:`radio`,"aria-checked":n,"aria-label":e,title:t??e,onClick:i,className:s(`focus-ring group relative aspect-video overflow-hidden rounded-md border transition-colors`,n?`border-primary ring-1 ring-primary`:`border-border hover:border-muted-foreground/40`),children:[a,n&&(0,H.jsx)(`span`,{className:`absolute right-1 top-1 rounded-full bg-primary p-0.5 text-primary-foreground`,children:(0,H.jsx)(r,{className:`size-3`})})]})}function J({title:e,description:t}){return(0,H.jsxs)(`div`,{className:`mb-3`,children:[(0,H.jsx)(`h2`,{className:`text-base font-semibold`,children:e}),(0,H.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:t})]})}function Y({options:e,value:t,onChange:n}){return(0,H.jsx)(`div`,{role:`radiogroup`,className:`inline-flex flex-wrap gap-1 rounded-lg bg-muted p-1`,children:e.map(e=>{let r=e.id===t;return(0,H.jsxs)(`button`,{type:`button`,role:`radio`,"aria-checked":r,title:e.title,onClick:()=>n(e.id),className:s(`focus-ring flex h-control items-center gap-2 rounded-md px-3 text-sm transition-colors`,r?`bg-card text-foreground shadow-elevation-1`:`text-muted-foreground hover:text-foreground`),children:[e.icon,e.label]},e.id)})})}function X(){return(0,H.jsxs)(`div`,{className:`mx-auto max-w-4xl`,children:[(0,H.jsx)(z,{className:`mb-6`,title:`Appearance`,onBack:B(),description:`Theme, colour scheme and density. Changes apply immediately and are remembered on this device.`}),(0,H.jsx)(W,{})]})}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{Wr as r,Xt as i,Yt as a,et as o}from"./ui-CDoK3F3U.js";import{t as s}from"./utils-2pl1SbIp.js";import{a as c,i as l,n as u,o as d,r as f,s as p,t as m}from"./document-open-mode-DoImW-xs.js";import{d as h,f as g,l as _,o as v,s as y,u as b}from"./use-menu-DIP1zh7I.js";import{t as x}from"./use-theme-DaxpiICf.js";import{Ct as S,St as C,a as w,c as T,d as E,f as D,i as O,l as k,m as A,n as j,o as M,p as N,r as P,s as F,t as I,u as L,xt as R}from"./index-B01BkfMJ.js";import{n as z}from"./page-header-DrDt1sQ2.js";import{t as B}from"./use-settings-back-DGmLAD63.js";var V=e(n(),1),H=t(),U={system:i,light:o,dark:a};function W(){let{theme:e,scheme:t,density:n,resolvedScheme:i,setTheme:a,setScheme:o,setDensity:w,reset:T}=x(),E=l(),O=u(),k=h(),j=p(),M=S(),P=g();return(0,H.jsxs)(`div`,{className:`space-y-8`,children:[(0,H.jsxs)(`section`,{children:[(0,H.jsx)(J,{title:`Theme`,description:`Palette, shape and typography. Each theme defines its own light and dark variants.`}),(0,H.jsx)(`div`,{className:`grid gap-3 sm:grid-cols-2 lg:grid-cols-3`,children:A.map(t=>{let n=t.id===e;return(0,H.jsxs)(`button`,{type:`button`,onClick:()=>a(t.id),"aria-pressed":n,className:s(`focus-ring group flex flex-col gap-3 rounded-lg border p-4 text-left transition-colors`,n?`border-primary bg-accent`:`border-border hover:border-muted-foreground/40 hover:bg-accent/50`),children:[(0,H.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,H.jsx)(`span`,{className:`text-sm font-medium`,children:t.name}),n&&(0,H.jsx)(r,{className:`size-4 shrink-0 text-primary`})]}),(0,H.jsx)(`div`,{className:`flex gap-1.5`,"aria-hidden":!0,children:t.swatches.map(e=>(0,H.jsx)(`span`,{className:`size-6 rounded-full border border-border`,style:{backgroundColor:e}},e))}),(0,H.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:t.description})]},t.id)})})]}),(0,H.jsxs)(`section`,{children:[(0,H.jsx)(J,{title:`Colour scheme`,description:t===`system`?`Following your system setting, currently ${i}.`:`Overrides your system setting.`}),(0,H.jsx)(Y,{options:N.map(e=>{let t=U[e.id];return{id:e.id,label:e.name,icon:(0,H.jsx)(t,{className:`size-4 shrink-0`})}}),value:t,onChange:o})]}),(0,H.jsxs)(`section`,{children:[(0,H.jsx)(J,{title:`Density`,description:`Controls row height, hit-target size and shell spacing across the whole app.`}),(0,H.jsx)(Y,{options:D.map(e=>({id:e.id,label:e.name,title:e.description})),value:n,onChange:w}),(0,H.jsx)(`p`,{className:`mt-2 text-xs text-muted-foreground`,children:D.find(e=>e.id===n)?.description})]}),(0,H.jsxs)(`section`,{children:[(0,H.jsx)(J,{title:`Layout`,description:`How menus and content share the screen. Device-local, like the wallpaper.`}),(0,H.jsx)(Y,{options:y.map(e=>({id:e.id,label:e.name,title:e.description})),value:k,onChange:_}),(0,H.jsx)(`p`,{className:`mt-2 text-xs text-muted-foreground`,children:y.find(e=>e.id===k)?.description}),k===`strip`&&(0,H.jsxs)(`div`,{className:`mt-4`,children:[(0,H.jsx)(`p`,{className:`mb-2 text-sm font-medium`,children:`Navigation keys`}),(0,H.jsx)(Y,{options:v.map(e=>({id:e.id,label:e.name,title:e.description})),value:P,onChange:b}),(0,H.jsxs)(`p`,{className:`mt-2 text-xs text-muted-foreground`,children:[v.find(e=>e.id===P)?.description,` `,`Left and right walk the columns, up and down switch pin rows.`]})]})]}),(0,H.jsxs)(`section`,{children:[(0,H.jsx)(J,{title:`Tree style`,description:`How workspace and context trees are drawn in the menu. Device-local.`}),(0,H.jsx)(Y,{options:R.map(e=>({id:e.id,label:e.name,title:e.description})),value:M,onChange:C}),(0,H.jsx)(`p`,{className:`mt-2 text-xs text-muted-foreground`,children:R.find(e=>e.id===M)?.description})]}),(0,H.jsxs)(`section`,{children:[(0,H.jsx)(J,{title:`Open documents`,description:`Choose how documents open from lists, tiles and boards. Saved on this device.`}),(0,H.jsx)(Y,{options:[{id:`modal`,label:`Modal`},{id:`side`,label:`Side reading pane`}],value:O,onChange:m}),(0,H.jsx)(`p`,{className:`mt-2 text-xs text-muted-foreground`,children:`The reading pane opens beside the content and updates as you select another document. On small screens it opens as a drawer.`})]}),(0,H.jsxs)(`section`,{children:[(0,H.jsx)(J,{title:`Always-on content area`,description:`Keep a reading pane beside document lists on tablets and desktops. Remember the selected item in each folder, or show the first available item.`}),(0,H.jsx)(Y,{options:[{id:`on`,label:`On`},{id:`off`,label:`Off`}],value:E?`on`:`off`,onChange:e=>f(e===`on`)}),(0,H.jsx)(`p`,{className:`mt-2 text-xs text-muted-foreground`,children:`On by default. The reader uses roughly half the screen; drag its divider to resize. Phones keep tap-to-open navigation. When enabled, list selections use this pane regardless of the Open documents setting.`})]}),(0,H.jsxs)(`section`,{children:[(0,H.jsx)(J,{title:`Document tiles`,description:`Choose the photo and media layout for tile view. Saved on this device.`}),(0,H.jsx)(Y,{options:c,value:j,onChange:d})]}),(0,H.jsx)(G,{}),(0,H.jsx)(`section`,{children:(0,H.jsx)(`button`,{type:`button`,onClick:()=>{T(),m(`modal`)},className:`focus-ring rounded-md text-sm text-muted-foreground underline-offset-4 hover:text-foreground hover:underline`,children:`Reset to defaults`})})]})}function G(){let[e,t]=(0,V.useState)(M),[n,r]=(0,V.useState)(null),[i,a]=(0,V.useState)(!0),[o,s]=(0,V.useState)(!1),c=(0,V.useRef)(!1);(0,V.useEffect)(()=>{let e=!1;return T().then(()=>{e||(t(M()),a(!1))}),()=>{e=!0}},[]);let l=async(e,n)=>{if(!c.current){c.current=!0,s(!0);try{let i=n?{...e,image:await F(n)}:e;await k(i),t(i),r(null)}catch(e){r(e instanceof Error&&e.name!==`QuotaExceededError`?e.message:`Could not store the wallpaper. Free some browser storage or try a smaller image.`)}finally{c.current=!1,s(!1)}}},u=t=>{t&&l(e,t)},d=e.image!==null&&P(e.image)===null,f=L(e.image);return(0,H.jsx)(`section`,{children:(0,H.jsxs)(`fieldset`,{disabled:i||o,className:`min-w-0`,children:[(0,H.jsx)(J,{title:`Wallpaper`,description:`Background image for the desk behind all panels. Without one, the theme's desk color shows (the default).`}),(0,H.jsxs)(`div`,{role:`radiogroup`,"aria-label":`Wallpaper`,className:`grid grid-cols-3 gap-3 sm:grid-cols-4 lg:grid-cols-6`,children:[(0,H.jsx)(q,{label:`None`,isActive:e.image===null,onSelect:()=>l({...e,image:null}),children:(0,H.jsx)(`span`,{className:`flex size-full items-center justify-center surface-desk text-xs text-muted-foreground`,style:{backgroundImage:`none`},children:`None`})}),I.map(t=>(0,H.jsx)(q,{label:t.title,title:`${t.title} — suits the ${t.scheme} scheme`,isActive:P(e.image)===t.id,onSelect:()=>l({...e,image:O(t.id)}),children:(0,H.jsx)(`img`,{src:w(t),alt:``,loading:`lazy`,className:`size-full object-cover`,style:{backgroundColor:t.background}})},t.id)),d&&(0,H.jsx)(q,{label:`Your image`,isActive:!0,onSelect:()=>{},children:(0,H.jsx)(`img`,{src:e.image??void 0,alt:``,className:`size-full object-cover`})})]}),(0,H.jsx)(K,{}),(0,H.jsxs)(`div`,{className:`mt-4 flex flex-wrap items-center gap-3`,children:[(0,H.jsx)(`div`,{className:`h-20 w-32 shrink-0 rounded-md border surface-desk`,style:f?{backgroundImage:f,backgroundSize:E(e.fit),backgroundPosition:`center`,backgroundRepeat:`no-repeat`}:void 0,"aria-hidden":!0}),(0,H.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,H.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[(0,H.jsxs)(`label`,{className:`focus-ring inline-flex cursor-pointer items-center rounded-md border px-3 py-1.5 text-sm hover:bg-accent/50`,children:[d?`Change image…`:`Use your own image…`,(0,H.jsx)(`input`,{type:`file`,accept:`image/*,.gif`,className:`hidden`,onChange:e=>{u(e.target.files?.[0]),e.target.value=``}})]}),e.image&&(0,H.jsx)(`button`,{type:`button`,onClick:()=>l({...e,image:null}),className:`focus-ring rounded-md border px-3 py-1.5 text-sm text-muted-foreground hover:bg-accent/50 hover:text-foreground`,children:`Remove`})]}),(0,H.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`Images and animated GIFs up to 10 MB. Stored on this device.`}),(0,H.jsx)(Y,{options:j.map(e=>({id:e.id,label:e.label,title:e.description})),value:e.fit,onChange:t=>l({...e,fit:t})}),n&&(0,H.jsx)(`p`,{className:`text-xs text-destructive`,children:n}),o&&(0,H.jsx)(`p`,{role:`status`,className:`text-xs text-muted-foreground`,children:`Saving wallpaper…`})]})]})]})})}function K(){let e=I.filter(e=>e.author!==`Canvas`);return e.length===0?null:(0,H.jsx)(`p`,{className:`mt-2 text-xs text-muted-foreground`,children:e.map((e,t)=>(0,H.jsxs)(`span`,{children:[t>0&&` · `,e.title,` © `,e.author,e.source&&(0,H.jsxs)(H.Fragment,{children:[` `,(0,H.jsx)(`a`,{href:e.source,target:`_blank`,rel:`noreferrer noopener`,className:`focus-ring underline underline-offset-2 hover:text-foreground`,children:new URL(e.source).hostname})]})]},e.id))})}function q({label:e,title:t,isActive:n,onSelect:i,children:a}){return(0,H.jsxs)(`button`,{type:`button`,role:`radio`,"aria-checked":n,"aria-label":e,title:t??e,onClick:i,className:s(`focus-ring group relative aspect-video overflow-hidden rounded-md border transition-colors`,n?`border-primary ring-1 ring-primary`:`border-border hover:border-muted-foreground/40`),children:[a,n&&(0,H.jsx)(`span`,{className:`absolute right-1 top-1 rounded-full bg-primary p-0.5 text-primary-foreground`,children:(0,H.jsx)(r,{className:`size-3`})})]})}function J({title:e,description:t}){return(0,H.jsxs)(`div`,{className:`mb-3`,children:[(0,H.jsx)(`h2`,{className:`text-base font-semibold`,children:e}),(0,H.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:t})]})}function Y({options:e,value:t,onChange:n}){return(0,H.jsx)(`div`,{role:`radiogroup`,className:`inline-flex flex-wrap gap-1 rounded-lg bg-muted p-1`,children:e.map(e=>{let r=e.id===t;return(0,H.jsxs)(`button`,{type:`button`,role:`radio`,"aria-checked":r,title:e.title,onClick:()=>n(e.id),className:s(`focus-ring flex h-control items-center gap-2 rounded-md px-3 text-sm transition-colors`,r?`bg-card text-foreground shadow-elevation-1`:`text-muted-foreground hover:text-foreground`),children:[e.icon,e.label]},e.id)})})}function X(){return(0,H.jsxs)(`div`,{className:`mx-auto max-w-4xl`,children:[(0,H.jsx)(z,{className:`mb-6`,title:`Appearance`,onBack:B(),description:`Theme, colour scheme and density. Changes apply immediately and are remembered on this device.`}),(0,H.jsx)(W,{})]})}export{X as default};
@@ -1 +1 @@
1
- import{l as e}from"./code-editor-BOIngd5F.js";import{t}from"./use-applet-target-1DU4mgJH.js";var n=e();function r({target:e,children:r}){return(0,n.jsx)(t.Provider,{value:e,children:r})}export{r as t};
1
+ import{l as e}from"./code-editor-BOIngd5F.js";import{t}from"./use-applet-target-BygCSj5n.js";var n=e();function r({target:e,children:r}){return(0,n.jsx)(t.Provider,{value:e,children:r})}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{_ as r,r as i,v as a}from"./chunk-62JRHF6Z-vspAGgtK.js";import{t as o}from"./utils-2pl1SbIp.js";import{Cn as s,Nt as c}from"./workspace-cv6Hrfhh.js";import{p as l}from"./context-1vR30CeC.js";import{t as u}from"./registry-eFbDXN9w.js";import{t as d}from"./applet-target-DYrCD8BZ.js";var f=e(n(),1),p=t(),m=`universe`;function h(){let{appletId:e}=r(),[t,n]=a(),h=u.find(t=>t.id===e),g=t.get(`context`),_=t.get(`workspace`)||m,v=t.get(`path`)||`/`,y=t.get(`tree`)||`context`,b=t.get(`add`)===`1`,x=(0,f.useMemo)(()=>g?{mode:`context`,contextId:g}:{mode:`workspace`,workspaceName:_,path:v,treeName:y,treeType:s(y)},[g,_,v,y]),[S,C]=(0,f.useState)([]),[w,T]=(0,f.useState)([]);(0,f.useEffect)(()=>{c().then(C).catch(()=>C([])),l().then(T).catch(()=>T([]))},[]);let[E,D]=(0,f.useState)(v),[O,k]=(0,f.useState)(v);O!==v&&(k(v),D(v));let A=e=>{let r=new URLSearchParams(t);r.delete(`add`);for(let[t,n]of Object.entries(e))n===null?r.delete(t):r.set(t,n);n(r,{replace:!0})};if(!h)return(0,p.jsxs)(`div`,{className:`flex h-full min-h-0 flex-col items-center justify-center gap-3 surface-desk`,children:[(0,p.jsxs)(`p`,{className:`text-sm text-muted-foreground`,children:[`Unknown app`,e?` "${e}"`:``,`.`]}),(0,p.jsx)(`div`,{className:`flex gap-2`,children:u.map(e=>(0,p.jsx)(i,{to:`/apps/${e.id}`,className:`rounded-md border border-border px-3 py-1.5 text-sm hover:bg-muted`,children:e.label},e.id))})]});let j=g?`context`:`path`;return(0,p.jsxs)(`div`,{className:`flex h-full min-h-0 flex-col surface-desk p-shell gap-shell`,children:[(0,p.jsxs)(`div`,{className:`flex shrink-0 flex-wrap items-center gap-2 rounded-xl border bg-card px-3 py-2 shadow-elevation-2`,children:[(0,p.jsx)(h.icon,{className:`h-4 w-4 text-muted-foreground`}),(0,p.jsx)(`span`,{className:`text-sm font-semibold`,children:h.label}),(0,p.jsx)(`div`,{className:`ml-2 flex overflow-hidden rounded-md border border-border`,children:[`path`,`context`].map(e=>(0,p.jsx)(`button`,{type:`button`,onClick:()=>{e!==j&&A(e===`path`?{context:null}:{context:w[0]?.id??``,workspace:null,path:null,tree:null})},className:o(`px-2.5 py-1 text-xs capitalize transition-colors`,j===e?`bg-foreground text-background`:`text-muted-foreground hover:bg-muted hover:text-foreground`),children:e},e))}),j===`path`?(0,p.jsxs)(p.Fragment,{children:[(0,p.jsxs)(`select`,{value:_,onChange:e=>A({workspace:e.target.value,path:`/`}),className:`h-7 rounded-md border border-input bg-transparent px-1.5 text-xs`,"aria-label":`Workspace`,children:[!S.some(e=>e.name===_)&&(0,p.jsx)(`option`,{value:_,children:_}),S.map(e=>(0,p.jsx)(`option`,{value:e.name,children:e.label||e.name},e.id))]}),(0,p.jsx)(`input`,{value:E,onChange:e=>D(e.target.value),onBlur:()=>{let e=E.trim()||`/`;e!==v&&A({path:e})},onKeyDown:e=>{e.key===`Enter`&&e.target.blur()},spellCheck:!1,placeholder:`/`,className:`h-7 w-40 rounded-md border border-input bg-transparent px-2 text-xs outline-none focus-visible:ring-1 focus-visible:ring-ring`,"aria-label":`Path`})]}):(0,p.jsxs)(`select`,{value:g??``,onChange:e=>A({context:e.target.value}),className:`h-7 max-w-56 rounded-md border border-input bg-transparent px-1.5 text-xs`,"aria-label":`Context`,children:[!g&&(0,p.jsx)(`option`,{value:``,children:`Pick a context…`}),w.map(e=>(0,p.jsxs)(`option`,{value:e.id,children:[e.id,e.url?` (${e.url})`:``]},e.id))]}),(0,p.jsx)(`div`,{className:`grow`})]}),(0,p.jsx)(`div`,{className:`flex min-h-0 flex-1 flex-col overflow-hidden rounded-xl border bg-card shadow-elevation-2`,children:j===`context`&&!g?(0,p.jsxs)(`div`,{className:`flex h-full items-center justify-center p-6 text-center text-sm text-muted-foreground`,children:[`Pick a context above to bind `,h.label,` to it.`]}):(0,p.jsx)(d,{target:x,children:(0,p.jsx)(h.Component,{autoAdd:b},JSON.stringify(x))})})]})}export{h 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,r as i,v as a}from"./chunk-62JRHF6Z-vspAGgtK.js";import{t as o}from"./utils-2pl1SbIp.js";import{bn as s,jt as c}from"./workspace-C5V-ZCOE.js";import{p as l}from"./context-t3rdtGUB.js";import{t as u}from"./registry-CPdMkdKq.js";import{t as d}from"./applet-target-pLdP-R76.js";var f=e(n(),1),p=t(),m=`universe`;function h(){let{appletId:e}=r(),[t,n]=a(),h=u.find(t=>t.id===e),g=t.get(`context`),_=t.get(`workspace`)||m,v=t.get(`path`)||`/`,y=t.get(`tree`)||`context`,b=t.get(`add`)===`1`,x=(0,f.useMemo)(()=>g?{mode:`context`,contextId:g}:{mode:`workspace`,workspaceName:_,path:v,treeName:y,treeType:s(y)},[g,_,v,y]),[S,C]=(0,f.useState)([]),[w,T]=(0,f.useState)([]);(0,f.useEffect)(()=>{c().then(C).catch(()=>C([])),l().then(T).catch(()=>T([]))},[]);let[E,D]=(0,f.useState)(v),[O,k]=(0,f.useState)(v);O!==v&&(k(v),D(v));let A=e=>{let r=new URLSearchParams(t);r.delete(`add`);for(let[t,n]of Object.entries(e))n===null?r.delete(t):r.set(t,n);n(r,{replace:!0})};if(!h)return(0,p.jsxs)(`div`,{className:`flex h-full min-h-0 flex-col items-center justify-center gap-3 surface-desk`,children:[(0,p.jsxs)(`p`,{className:`text-sm text-muted-foreground`,children:[`Unknown app`,e?` "${e}"`:``,`.`]}),(0,p.jsx)(`div`,{className:`flex gap-2`,children:u.map(e=>(0,p.jsx)(i,{to:`/apps/${e.id}`,className:`rounded-md border border-border px-3 py-1.5 text-sm hover:bg-muted`,children:e.label},e.id))})]});let j=g?`context`:`path`;return(0,p.jsxs)(`div`,{className:`flex h-full min-h-0 flex-col surface-desk p-shell gap-shell`,children:[(0,p.jsxs)(`div`,{className:`flex shrink-0 flex-wrap items-center gap-2 rounded-xl border bg-card px-3 py-2 shadow-elevation-2`,children:[(0,p.jsx)(h.icon,{className:`h-4 w-4 text-muted-foreground`}),(0,p.jsx)(`span`,{className:`text-sm font-semibold`,children:h.label}),(0,p.jsx)(`div`,{className:`ml-2 flex overflow-hidden rounded-md border border-border`,children:[`path`,`context`].map(e=>(0,p.jsx)(`button`,{type:`button`,onClick:()=>{e!==j&&A(e===`path`?{context:null}:{context:w[0]?.id??``,workspace:null,path:null,tree:null})},className:o(`px-2.5 py-1 text-xs capitalize transition-colors`,j===e?`bg-foreground text-background`:`text-muted-foreground hover:bg-muted hover:text-foreground`),children:e},e))}),j===`path`?(0,p.jsxs)(p.Fragment,{children:[(0,p.jsxs)(`select`,{value:_,onChange:e=>A({workspace:e.target.value,path:`/`}),className:`h-7 rounded-md border border-input bg-transparent px-1.5 text-xs`,"aria-label":`Workspace`,children:[!S.some(e=>e.name===_)&&(0,p.jsx)(`option`,{value:_,children:_}),S.map(e=>(0,p.jsx)(`option`,{value:e.name,children:e.label||e.name},e.id))]}),(0,p.jsx)(`input`,{value:E,onChange:e=>D(e.target.value),onBlur:()=>{let e=E.trim()||`/`;e!==v&&A({path:e})},onKeyDown:e=>{e.key===`Enter`&&e.target.blur()},spellCheck:!1,placeholder:`/`,className:`h-7 w-40 rounded-md border border-input bg-transparent px-2 text-xs outline-none focus-visible:ring-1 focus-visible:ring-ring`,"aria-label":`Path`})]}):(0,p.jsxs)(`select`,{value:g??``,onChange:e=>A({context:e.target.value}),className:`h-7 max-w-56 rounded-md border border-input bg-transparent px-1.5 text-xs`,"aria-label":`Context`,children:[!g&&(0,p.jsx)(`option`,{value:``,children:`Pick a context…`}),w.map(e=>(0,p.jsxs)(`option`,{value:e.id,children:[e.id,e.url?` (${e.url})`:``]},e.id))]}),(0,p.jsx)(`div`,{className:`grow`})]}),(0,p.jsx)(`div`,{className:`flex min-h-0 flex-1 flex-col overflow-hidden rounded-xl border bg-card shadow-elevation-2`,children:j===`context`&&!g?(0,p.jsxs)(`div`,{className:`flex h-full items-center justify-center p-6 text-center text-sm text-muted-foreground`,children:[`Pick a context above to bind `,h.label,` to it.`]}):(0,p.jsx)(d,{target:x,children:(0,p.jsx)(h.Component,{autoAdd:b},JSON.stringify(x))})})]})}export{h as default};