@augmentd-labs/canvas-web 2.26.38 → 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.
- package/dist/assets/CalendarApplet-Co0RKLQE.js +2 -0
- package/dist/assets/FileForm-CDiVKvxq.js +1 -0
- package/dist/assets/{FiltersApplet-Dh4SUfjN.js → FiltersApplet-DMoH8Y2S.js} +1 -1
- package/dist/assets/{HomeFab-W7y591CD.js → HomeFab-CpgkP2jx.js} +1 -1
- package/dist/assets/{IdentityFields-DZRqtnIG.js → IdentityFields-D-NCTUaE.js} +1 -1
- package/dist/assets/{LensApplet-CddpZXRw.js → LensApplet-BRvNa6QA.js} +1 -1
- package/dist/assets/LinkToCard-CKVi4Nrg.js +1 -0
- package/dist/assets/{NextShell-BfQHKEKO.js → NextShell-ull6WmMg.js} +1 -1
- package/dist/assets/{NotesApplet-Cyuirnp1.js → NotesApplet-BUlo1AeT.js} +1 -1
- package/dist/assets/ObjectPropertiesCard-D2lrTQqT.js +8 -0
- package/dist/assets/{PathPickerField-B4yFUjgD.js → PathPickerField-CW2yG2Yg.js} +1 -1
- package/dist/assets/{PickDocumentsCard-CFDQL70e.js → PickDocumentsCard-BWgc-A02.js} +1 -1
- package/dist/assets/{SketchApplet-14xrogy3.js → SketchApplet-BKnhzTBA.js} +1 -1
- package/dist/assets/{SketchEditor-B2LYe_MO.js → SketchEditor-DmGMcbU0.js} +2 -2
- package/dist/assets/{TerminalApplet-BNeLmNFF.js → TerminalApplet-D7YxftqM.js} +1 -1
- package/dist/assets/{TextDocumentEditor-CU5ersd_.js → TextDocumentEditor-BQnVD0dd.js} +1 -1
- package/dist/assets/{TodosApplet-ASG9wXjL.js → TodosApplet-DU5VWc5i.js} +1 -1
- package/dist/assets/{TodosWidget-CYK5RbYD.js → TodosWidget-CNnfNk4L.js} +1 -1
- package/dist/assets/{UploadProgressList-Ci1akl_D.js → UploadProgressList-D2wEpa7t.js} +1 -1
- package/dist/assets/{_agentId_-Dy7lgkJK.js → _agentId_-DpUGhD0N.js} +0 -0
- package/dist/assets/_contextId_-BYACtvKh.js +1 -0
- package/dist/assets/_workspaceName_-V027dHb_.js +1 -0
- package/dist/assets/{about-Cns4GXCX.js → about-he3_XqHw.js} +1 -1
- package/dist/assets/{add-jGjbB0x1.js → add-CPWQz9ZK.js} +1 -1
- package/dist/assets/{agents-DsaNiZJc.js → agents-e-nclilT.js} +1 -1
- package/dist/assets/{appearance-C1xkguK7.js → appearance-De5ieWdQ.js} +1 -1
- package/dist/assets/{applet-target-I8w6EPj0.js → applet-target-pLdP-R76.js} +1 -1
- package/dist/assets/{apps-BCy4q37-.js → apps-o8pk-feK.js} +1 -1
- package/dist/assets/backend-sync-progress-DqI8zbnK.js +6 -0
- package/dist/assets/{context-DZ1Hn7tt.js → context-t3rdtGUB.js} +1 -1
- package/dist/assets/{contexts-Df-cWUlj2.js → contexts-Bq8LHUTK2.js} +1 -1
- package/dist/assets/{date-time-picker-txVhlNO0.js → date-time-picker-DCikruos.js} +1 -1
- package/dist/assets/{document-CTvT2Qa5.js → document-Cr7GhnVd.js} +1 -1
- package/dist/assets/document-list-J63eer10.js +3 -0
- package/dist/assets/{home-C8Wq8hsp.js → home-Cgt-SPAO.js} +1 -1
- package/dist/assets/{index-Cp75myNf.js → index-B01BkfMJ.js} +6 -6
- package/dist/assets/index-CYvpxvg6.css +2 -0
- package/dist/assets/{key-bindings-CA_ePKGA.js → key-bindings-DbpenCz7.js} +1 -1
- package/dist/assets/{offline-sNCjxnp-.js → offline-ByoT6JJX.js} +1 -1
- package/dist/assets/{public-share-D5yz-Pmo.js → public-share-CXR25Q1X.js} +1 -1
- package/dist/assets/query-debug-lD5vbJGi.js +1 -0
- package/dist/assets/{registry-QDfCL8gg.js → registry-CPdMkdKq.js} +2 -2
- package/dist/assets/{roles-DoR2drD1.js → roles-sb8vgjV_.js} +1 -1
- package/dist/assets/{settings-jIm9JVC-.js → settings-3y1P0NnU.js} +1 -1
- package/dist/assets/{settings-aOogFA9n.js → settings-B25sRmAM.js} +1 -1
- package/dist/assets/{settings-tgfewl6I.js → settings-D1g-5DNT.js} +1 -1
- package/dist/assets/settings-DX6t8wLi.js +16 -0
- package/dist/assets/{share-target-cRZICq5X.js → share-target-DAjpH4Qw.js} +1 -1
- package/dist/assets/{shared-BnpwVpxG.js → shared-BLOuO2Is.js} +1 -1
- package/dist/assets/{shared-eIOEFQRM.js → shared-BiquP0Yf.js} +1 -1
- package/dist/assets/{sketch-lazy-BbNgGbR3.js → sketch-lazy-BY_ka1hw.js} +2 -2
- package/dist/assets/{text-documents-BaXhu3ra.js → text-documents-Cdb3U63i.js} +2 -2
- package/dist/assets/tree-folders-BMqMmyq7.js +1 -0
- package/dist/assets/{use-applet-docs-B2dk__vk.js → use-applet-docs-rimRHjID.js} +1 -1
- package/dist/assets/{use-applet-target-ffIGaAqT.js → use-applet-target-BygCSj5n.js} +1 -1
- package/dist/assets/use-canvas-pins-BV8AsYCE.js +3 -0
- package/dist/assets/{use-workspace-identity-B8gOMGj4.js → use-workspace-identity-CSkRwVyo.js} +1 -1
- package/dist/assets/{useAddTarget-B3b6TyZr.js → useAddTarget-DeRZWtGg.js} +1 -1
- package/dist/assets/{useAgentModels-B10Tbl6D.js → useAgentModels-KcfEQ6u9.js} +1 -1
- package/dist/assets/{useDocumentThumbnail-wW0lSOEy.js → useDocumentThumbnail-Cj4UYyhC.js} +1 -1
- package/dist/assets/{useEditNoteFields-DXLTFEqL.js → useEditNoteFields-BT1ASu_q.js} +1 -1
- package/dist/assets/workspace-C5V-ZCOE.js +1 -0
- package/dist/assets/{workspace-area-menu-BFw2yUHk.js → workspace-area-menu-Y2-IWSxU.js} +1 -1
- package/dist/assets/{workspace-content-gate-NLuRPvbm.js → workspace-content-gate-C54J9Man.js} +1 -1
- package/dist/assets/{workspace-import-form-Bb6z42nw.js → workspace-import-form-DTvV9jYt.js} +1 -1
- package/dist/assets/workspaces-CWqg_P7W.js +1 -0
- package/dist/index.html +26 -26
- package/dist/sw.js +1 -1
- package/package.json +2 -2
- package/dist/assets/CalendarApplet-7wqNCpcs.js +0 -2
- package/dist/assets/FileForm-C35drQ_R.js +0 -1
- package/dist/assets/LinkToCard-BQ1yoFDr.js +0 -1
- package/dist/assets/ObjectPropertiesCard-BTTwYnN9.js +0 -8
- package/dist/assets/_contextId_-BBpL3f_T.js +0 -1
- package/dist/assets/_workspaceName_-CU-hpvv7.js +0 -1
- package/dist/assets/backend-sync-progress-tUU2XWtW.js +0 -7
- package/dist/assets/document-list-CQ1_7Sja.js +0 -2
- package/dist/assets/index-_0FSwEvG.css +0 -2
- package/dist/assets/query-debug-CQ0I3cXX.js +0 -1
- package/dist/assets/settings-Bz400KLm.js +0 -16
- package/dist/assets/tree-folders-cmsIS19Z.js +0 -1
- package/dist/assets/use-canvas-pins-DkWN9oEd.js +0 -3
- package/dist/assets/workspace-BJELPCNs.js +0 -1
- package/dist/assets/workspaces-DC19HlpI.js +0 -1
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
import{o as e}from"./rolldown-runtime-C0FnF6B9.js";import{l as t,u as n}from"./code-editor-BOIngd5F.js";import{g as r,r as i}from"./chunk-62JRHF6Z-vspAGgtK.js";import{Fr as a,Hr as o,Jr as s,L as c,Ot as l,Pt as u,Vr as d,X as f,ct as p,et as m,fr as h,jr as g,mr as _,pn as v,qr as y,vn as b}from"./ui-CDoK3F3U.js";import{t as x}from"./utils-2pl1SbIp.js";import{h as S}from"./LinkToCard-BQ1yoFDr.js";import{Hn as C,In as w,St as T,jt as E,rt as D,vn as O,w as k,wn as A}from"./workspace-BJELPCNs.js";import{o as ee,t as j}from"./useAddTarget-B3b6TyZr.js";import{a as M,o as N}from"./context-DZ1Hn7tt.js";import{n as P,o as F,s as I,t as L}from"./date-time-picker-txVhlNO0.js";import{n as te}from"./use-applet-target-ffIGaAqT.js";import{y as R}from"./index-Cp75myNf.js";import{r as ne,t as re}from"./shared-BnpwVpxG.js";var z=e(n(),1),ie=864e5,ae=[`Mon`,`Tue`,`Wed`,`Thu`,`Fri`,`Sat`,`Sun`];function B(e){return String(e).padStart(2,`0`)}function V(e){return`${e.getFullYear()}-${B(e.getMonth()+1)}-${B(e.getDate())}`}function H(e){let[t,n,r]=e.split(`-`).map(Number);return new Date(t,n-1,r)}function oe(e){return`${V(e)}T${B(e.getHours())}:${B(e.getMinutes())}`}function U(e){return new Date(e.getFullYear(),e.getMonth(),e.getDate())}function W(e,t){return new Date(e.getFullYear(),e.getMonth(),e.getDate()+t,e.getHours(),e.getMinutes(),e.getSeconds(),e.getMilliseconds())}function se(e,t){return new Date(e.getFullYear(),e.getMonth()+t,1)}function ce(e){let t=U(e);return W(t,-((t.getDay()+6)%7))}function le(e){return new Date(e.getFullYear(),e.getMonth(),1)}function G(e,t){return e.getFullYear()===t.getFullYear()&&e.getMonth()===t.getMonth()&&e.getDate()===t.getDate()}function K(e){let t=ce(le(e));return Array.from({length:42},(e,n)=>W(t,n))}function q(e,t){let n=[],r=t.getTime()>e.getTime()?new Date(t.getTime()-1):e;for(let t=U(e);t.getTime()<=r.getTime();t=W(t,1))n.push(t);return n}function J(e,t){let n=e.getTime()-U(t).getTime();return Math.max(0,Math.min(ie,n))/6e4}var ue=new Intl.DateTimeFormat(void 0,{month:`long`,year:`numeric`}),Y=new Intl.DateTimeFormat(void 0,{month:`short`}),de=new Intl.DateTimeFormat(void 0,{weekday:`long`,day:`numeric`,month:`long`,year:`numeric`}),X=new Intl.DateTimeFormat(void 0,{weekday:`short`,day:`numeric`,month:`short`}),fe=new Intl.DateTimeFormat(void 0,{hour:`numeric`,minute:`2-digit`});function pe(e){return ue.format(e)}function me(e){return Y.format(e)}function he(e){return de.format(e)}function ge(e){return X.format(e)}function Z(e){return fe.format(e)}function _e(e,t){return G(e,t)?he(e):e.getFullYear()===t.getFullYear()?e.getMonth()===t.getMonth()?`${e.getDate()} – ${t.getDate()} ${Y.format(e)} ${e.getFullYear()}`:`${e.getDate()} ${Y.format(e)} – ${t.getDate()} ${Y.format(t)} ${t.getFullYear()}`:`${e.getDate()} ${Y.format(e)} ${e.getFullYear()} – ${t.getDate()} ${Y.format(t)} ${t.getFullYear()}`}function ve(e){return _e(e,W(e,6))}function ye(e){return fe.format(new Date(2e3,0,1,e,0)).replace(/:00(?=\s|$)/,``)}var be={SU:0,MO:1,TU:2,WE:3,TH:4,FR:5,SA:6},xe=new Set([`FREQ`,`INTERVAL`,`COUNT`,`UNTIL`,`BYDAY`,`BYMONTHDAY`,`BYMONTH`,`WKST`]);function Se(e){let t={};for(let n of e.replace(/^RRULE:/i,``).split(`;`)){let e=n.trim();if(!e)continue;let r=e.indexOf(`=`);if(r<1)return null;t[e.slice(0,r).toUpperCase()]=e.slice(r+1).toUpperCase()}if(Object.keys(t).some(e=>!xe.has(e)))return null;let n=t.FREQ;if(n!==`DAILY`&&n!==`WEEKLY`&&n!==`MONTHLY`&&n!==`YEARLY`)return null;let r=t.INTERVAL?Number(t.INTERVAL):1;if(!Number.isInteger(r)||r<1)return null;let i=t.COUNT?Number(t.COUNT):null;if(i!==null&&(!Number.isInteger(i)||i<1))return null;let a=null;if(t.UNTIL){let e=/^(\d{4})(\d{2})(\d{2})(?:T(\d{2})(\d{2})(\d{2})(Z?))?$/.exec(t.UNTIL);if(!e)return null;let[,n,r,i,o,s,c,l]=e;if(a=o===void 0?new Date(Number(n),Number(r)-1,Number(i),23,59,59,999):l?new Date(Date.UTC(Number(n),Number(r)-1,Number(i),Number(o),Number(s),Number(c))):new Date(Number(n),Number(r)-1,Number(i),Number(o),Number(s),Number(c)),Number.isNaN(a.getTime()))return null}let o=[];if(t.BYDAY)for(let e of t.BYDAY.split(`,`)){let t=/^([+-]?\d{1,2})?(SU|MO|TU|WE|TH|FR|SA)$/.exec(e.trim());if(!t)return null;o.push({day:be[t[2]],ordinal:t[1]?Number(t[1]):null})}let s=t.BYMONTHDAY?t.BYMONTHDAY.split(`,`).map(Number):[];if(s.some(e=>!Number.isInteger(e)||e===0||e<-31||e>31))return null;let c=t.BYMONTH?t.BYMONTH.split(`,`).map(Number):[];return c.some(e=>!Number.isInteger(e)||e<1||e>12)||o.some(e=>e.ordinal!==null)&&n!==`MONTHLY`&&n!==`YEARLY`?null:{freq:n,interval:r,count:i,until:a,byDay:o,byMonthDay:s,byMonth:c}}function Ce(e,t){return new Date(e.getFullYear(),e.getMonth(),e.getDate(),t.getHours(),t.getMinutes(),t.getSeconds(),t.getMilliseconds())}function we(e,t){return new Date(e,t+1,0).getDate()}function Te(e,t,n,r){let i=we(e,t),a=new Set;if(n.byMonthDay.length)for(let e of n.byMonthDay){let t=e>0?e:i+1+e;t>=1&&t<=i&&a.add(t)}if(n.byDay.length){let r=new Set;for(let{day:a,ordinal:o}of n.byDay){let n=[];for(let r=1;r<=i;r++)new Date(e,t,r).getDay()===a&&n.push(r);if(o===null)n.forEach(e=>r.add(e));else{let e=o>0?n[o-1]:n[n.length+o];e&&r.add(e)}}if(n.byMonthDay.length)for(let e of[...a])r.has(e)||a.delete(e);else r.forEach(e=>a.add(e))}return!n.byMonthDay.length&&!n.byDay.length&&r.getDate()<=i&&a.add(r.getDate()),[...a].sort((e,t)=>e-t).map(n=>Ce(new Date(e,t,n),r))}function Ee(e,t,n,r,i=0,a=5e3){let o=[],s=n.getTime()-Math.max(0,i),c=r.getTime(),l=0,u=t=>{let n=t.getTime();return e.until&&n>e.until.getTime()||(l++,n>=s&&n<c&&o.push(t),e.count!==null&&l>=e.count)?!1:l<a};if(!u(t))return o;let d=t.getTime();if(e.freq===`DAILY`){for(let n=e.interval,r=0;r<a*12;n+=e.interval,r++){let r=Ce(new Date(t.getFullYear(),t.getMonth(),t.getDate()+n),t);if(r.getTime()>=c&&e.count===null||!(e.byMonth.length&&!e.byMonth.includes(r.getMonth()+1))&&!u(r))break}return o}if(e.freq===`WEEKLY`){let n=e.byDay.length?[...new Set(e.byDay.map(e=>e.day))]:[t.getDay()],r=new Date(t.getFullYear(),t.getMonth(),t.getDate()-(t.getDay()+6)%7);for(let i=0;;i+=e.interval){let a=new Date(r.getFullYear(),r.getMonth(),r.getDate()+i*7);if(a.getTime()>=c+6048e5&&e.count===null)break;let o=!1;for(let e=0;e<7;e++){let r=new Date(a.getFullYear(),a.getMonth(),a.getDate()+e);if(!n.includes(r.getDay()))continue;let i=Ce(r,t);if(!(i.getTime()<=d)&&!u(i)){o=!0;break}}if(o)break}return o}let f=e.freq===`MONTHLY`?e.interval:12*e.interval;for(let n=0;;n+=f){let r=t.getFullYear()+Math.floor((t.getMonth()+n)/12),i=(t.getMonth()+n)%12;if(new Date(r,i,1).getTime()>=c&&e.count===null)break;if(e.freq===`YEARLY`&&e.byMonth.length&&!e.byMonth.includes(i+1)){let n=!1;for(let i of e.byMonth){for(let a of Te(r,i-1,e,t))if(!(a.getTime()<=d)&&!u(a)){n=!0;break}if(n)break}if(n)break;continue}if(e.freq===`MONTHLY`&&e.byMonth.length&&!e.byMonth.includes(i+1))continue;let a=!1;for(let n of Te(r,i,e,t))if(!(n.getTime()<=d)&&!u(n)){a=!0;break}if(a||n>4800)break}return o}function De(e){let t={DAILY:`day`,WEEKLY:`week`,MONTHLY:`month`,YEARLY:`year`}[e.freq],n=e.interval===1?`Every ${t}`:`Every ${e.interval} ${t}s`,r=[`Sun`,`Mon`,`Tue`,`Wed`,`Thu`,`Fri`,`Sat`];return e.byDay.length?n+=` on `+e.byDay.map(({day:e,ordinal:t})=>t===null?r[e]:`${t===-1?`last`:`${t}.`} ${r[e]}`).join(`, `):e.byMonthDay.length&&(n+=` on day `+e.byMonthDay.join(`, `)),e.count!==null&&(n+=`, ${e.count} times`),e.until&&(n+=` until ${e.until.toLocaleDateString(void 0,{day:`numeric`,month:`short`,year:`numeric`})}`),n}function Oe(e){if(!e)return`none`;let t=Se(e);return!t||t.interval!==1||t.byMonthDay.length||t.byMonth.length?`custom`:t.freq===`WEEKLY`&&t.byDay.length===5&&t.byDay.every(e=>e.ordinal===null&&e.day>=1&&e.day<=5)?`weekdays`:t.byDay.length?`custom`:{DAILY:`daily`,WEEKLY:`weekly`,MONTHLY:`monthly`,YEARLY:`yearly`}[t.freq]}function ke(e,t){let n={daily:`FREQ=DAILY`,weekly:`FREQ=WEEKLY`,monthly:`FREQ=MONTHLY`,yearly:`FREQ=YEARLY`,weekdays:`FREQ=WEEKLY;BYDAY=MO,TU,WE,TH,FR`}[e];if(n)return t?.until?`${n};UNTIL=${t.until.replace(/-/g,``)}`:t?.count?`${n};COUNT=${t.count}`:n}function Ae(e){let t=e?Se(e):null;if(!t)return{until:``,count:null};let n=t.until,r=e=>String(e).padStart(2,`0`);return{until:n?`${n.getFullYear()}-${r(n.getMonth()+1)}-${r(n.getDate())}`:``,count:t.count}}var je=`tasks`,Me=`data/schema/event`,Ne=`data/schema/task`;function Pe(e){if(typeof e!=`string`||!e)return null;let t=new Date(e);return Number.isNaN(t.getTime())?null:t}function Fe(e){return new Date(e.getUTCFullYear(),e.getUTCMonth(),e.getUTCDate())}function Ie(e){return e.schema.startsWith(Me)}function Le(e){return e.schema===Ne}function Re(e,t,n){let r=e.data??{};if(Le(e)){let i=Pe(r.dueDate);if(!i||i<t||i>=n)return[];let a=String(r.status??`pending`);return[{key:`${e.id}@${i.getTime()}`,doc:e,kind:`task`,title:String(r.title??`Untitled`),start:i,end:i,allDay:!1,calendar:je,recurring:!1,unsupportedRule:!1,done:a===`completed`||a===`cancelled`}]}if(!Ie(e))return[];let i=Pe(r.start);if(!i)return[];let a=r.allDay===!0,o=r.end===null?null:Pe(r.end),s=a?Fe(i):i,c=a?o?Fe(o):W(s,1):o??(r.end===null?n:s),l=Math.max(0,c.getTime()-s.getTime()),u={doc:e,kind:`event`,title:String(r.title??`Untitled`),allDay:a,calendar:typeof r.calendar==`string`?r.calendar:``,done:!1},d=typeof r.recurrence==`string`?r.recurrence:``;if(!d)return c.getTime()<=t.getTime()&&!(c.getTime()===s.getTime()&&s>=t)||s>=n?[]:[{...u,key:`${e.id}@${s.getTime()}`,start:s,end:c,recurring:!1,unsupportedRule:!1}];let f=Se(d);return f?Ee(f,s,t,n,l).map(t=>({...u,key:`${e.id}@${t.getTime()}`,start:t,end:new Date(t.getTime()+l),recurring:!0,unsupportedRule:!1})):c<=t||s>=n?[]:[{...u,key:`${e.id}@${s.getTime()}`,start:s,end:c,recurring:!0,unsupportedRule:!0}]}function ze(e,t,n){return e.flatMap(e=>Re(e,t,n)).sort((e,t)=>e.start.getTime()-t.start.getTime()||t.end.getTime()-e.end.getTime()||e.title.localeCompare(t.title))}function Be(e){let t=new Map;for(let n of e)for(let e of q(n.start,n.end)){let r=`${e.getFullYear()}-${String(e.getMonth()+1).padStart(2,`0`)}-${String(e.getDate()).padStart(2,`0`)}`,i=t.get(r);i?i.push(n):t.set(r,[n])}return t}function Ve(e){return e.allDay||e.end.getTime()-e.start.getTime()>=864e5||!G(e.start,new Date(e.end.getTime()-1))&&e.end.getTime()>e.start.getTime()}function He(e,t,n=30){let r=U(e),i=t.filter(e=>!Ve(e)).map(e=>{let t=J(e.start,r),i=Math.max(n,J(e.end,r)-t);return{occurrence:e,top:t,height:Math.min(i,1440-t),column:0,columns:1}}).sort((e,t)=>e.top-t.top||t.height-e.height),a=[],o=-1,s=()=>{let e=[];for(let t of a){let n=e.findIndex(e=>e<=t.top);n<0&&(n=e.length,e.push(0)),e[n]=t.top+t.height,t.column=n}for(let t of a)t.columns=e.length;a=[]};for(let e of i)a.length&&e.top>=o&&s(),a.push(e),o=Math.max(o,e.top+e.height);return a.length&&s(),i}function Ue(e,t,n,r){if(t.kind===`task`)return{...e,dueDate:n.toISOString()};if(t.allDay)return{...e,start:`${V(n)}T00:00:00.000Z`,end:`${V(r)}T00:00:00.000Z`};let i={...e,start:n.toISOString()};return e.end===null||(r.getTime()>n.getTime()?i.end=r.toISOString():delete i.end),i}var We=[{id:`day`,label:`Day`,key:`d`},{id:`week`,label:`Week`,key:`w`},{id:`month`,label:`Month`,key:`m`},{id:`year`,label:`Year`,key:`y`},{id:`schedule`,label:`Schedule`,key:`s`}],Ge={view:`week`,hidden:[],showTasks:!0,defaultCalendar:`Personal`},Ke=`canvas:calendar:prefs`;function qe(e){return`${Ke}:${e??`global`}`}function Je(e){try{let t=JSON.parse(localStorage.getItem(qe(e))||`null`);if(!t||typeof t!=`object`)return Ge;let n=t;return{view:We.some(e=>e.id===n.view)?n.view:Ge.view,hidden:Array.isArray(n.hidden)?n.hidden.filter(e=>typeof e==`string`):[],showTasks:n.showTasks!==!1,defaultCalendar:typeof n.defaultCalendar==`string`&&n.defaultCalendar.trim()?n.defaultCalendar:Ge.defaultCalendar}}catch{return Ge}}function Ye(e,t){try{localStorage.setItem(qe(e),JSON.stringify(t))}catch{}}function Xe(e,t){let n=V(W(U(e),-1)),r=V(W(U(t),1));return{events:`t:events:${n}..${r}`,tasks:`t:tasks:${n}..${r}`}}var Ze=5e3;function Qe(e){return!!e&&!e.includes(`:`)&&![`content`,`events`,`tasks`].includes(e.toLowerCase())}function $e(e){return e?e.mode===`context`?`ctx:${e.contextId}`:`${e.workspaceName}:${e.treeName}:${e.treeType}:${e.path}`:``}function et(e,t,n,r){let[i,a]=(0,z.useState)([]),[o,s]=(0,z.useState)(!1),[c,l]=(0,z.useState)(null),[u,d]=(0,z.useState)(null),[f,p]=(0,z.useState)([]),m=t.getTime(),h=n.getTime(),g=(0,z.useCallback)(()=>{if(!e)return Promise.resolve();let t=Xe(new Date(m),new Date(h));return(e.mode===`context`?Promise.all([N(e.contextId,[w],[t.events],{limit:Ze}),r?N(e.contextId,[C],[t.tasks],{limit:Ze}):Promise.resolve([]),M(e.contextId)]).then(([e,t,n])=>{a([...e,...t]);let r=n.workspaceName||n.workspaceId;d(r?{workspaceName:r,path:n.path||`/`,treeName:n.treeId||`context`,treeType:`context`}:null)}):(()=>{let{workspaceName:n,path:i,treeName:o,treeType:s}=e,c={treeName:o,treeType:s,limit:0};return Promise.all([D(n,i,[w],{...c,filters:[t.events]}),r?D(n,i,[C],{...c,filters:[t.tasks]}):Promise.resolve({payload:[]})]).then(([e,t])=>{a([...e.payload||[],...t.payload||[]]),d({workspaceName:n,path:i,treeName:o,treeType:s})})})()).catch(e=>l(e instanceof Error?e.message:`Failed to load calendar`)).finally(()=>s(!1))},[e,m,h,r]),_=(0,z.useCallback)(async()=>{if(!e){a([]),d(null);return}s(!0),l(null),await g()},[e,g]),[v,y]=(0,z.useState)(null),b=`${$e(e)}|${m}|${h}|${r}`;v!==b&&(y(b),e?(s(!0),l(null)):(a([]),d(null))),(0,z.useEffect)(()=>{g()},[g]),(0,z.useEffect)(()=>{let e=()=>{_()};return window.addEventListener(`workspace:documents:refresh`,e),()=>window.removeEventListener(`workspace:documents:refresh`,e)},[_]);let x=u?.workspaceName??null,S=(0,z.useCallback)(()=>x?Promise.all([T(x),E(x)]).then(([e,t])=>{let n=new Set;for(let t of e)t.startsWith(`data/calendar/`)&&t.length>14&&n.add(t.slice(14));for(let e of t)Qe(e.name)&&n.add(e.name);p([...n].sort())}).catch(()=>{}):Promise.resolve(),[x]);(0,z.useEffect)(()=>{S()},[S,i.length]),(0,z.useEffect)(()=>{let e=()=>{S()};return window.addEventListener(`workspace:timelines:changed`,e),()=>window.removeEventListener(`workspace:timelines:changed`,e)},[S]);let O=(0,z.useCallback)(async e=>{if(!u)throw Error(`No workspace scope resolved`);await k(u.workspaceName,[e],u.path,[],u.treeName,u.treeType),a(t=>t.filter(t=>t.id!==e))},[u]),A=(0,z.useCallback)(e=>{a(t=>t.some(t=>t.id===e.id)?t.map(t=>t.id===e.id?e:t):[...t,e])},[]);return(0,z.useMemo)(()=>({docs:i,loading:o,error:c,scope:u,knownCalendars:f,reload:_,removeDoc:O,patchDoc:A}),[i,o,c,u,f,_,O,A])}function tt(e){return R(e?e.toLowerCase():`events`)}function nt(e){return e.kind===`task`?R(je):tt(e.calendar)}function rt(e,t=18){return`color-mix(in oklch, ${e} ${t}%, transparent)`}function it(e,t,n,r,i,a=30){let o=Math.max(0,Math.min(e.length-1,t)),s=Math.max(0,Math.min(e.length-1,r));if(o!==s){let[t,n]=o<s?[o,s]:[s,o];return{start:U(e[t]),end:W(U(e[n]),1),allDay:!0}}let c=e=>Math.floor(e/a)*a,l=c(Math.min(n,i)),u=c(Math.max(n,i))+a;l=Math.max(0,Math.min(1440-a,l)),u=Math.max(l+a,Math.min(1440,u));let d=U(e[o]);return{start:new Date(d.getTime()+l*6e4),end:new Date(d.getTime()+u*6e4),allDay:!1}}function at(e,t){let[n,r]=e.getTime()<=t.getTime()?[e,t]:[t,e];return{start:U(n),end:W(U(r),1),allDay:!0}}function ot(e,t,n,r,i,a,o=15){let s=t=>Math.max(0,Math.min(e.length-1,t)),c=s(i)-s(n),l=Math.round((a-r)/o)*o,u=t.end.getTime()-t.start.getTime(),d=W(t.start,c),f=U(d),p=Math.max(0,Math.min(1440-o,(d.getTime()-f.getTime())/6e4+l)),m=new Date(f.getTime()+p*6e4);return{start:m,end:new Date(m.getTime()+u)}}function st(e,t,n,r,i=15){let a=U(e[Math.max(0,Math.min(e.length-1,n))]),o=Math.min(1440,Math.ceil(r/i)*i),s=new Date(a.getTime()+o*6e4);return{start:t.start,end:s.getTime()<t.start.getTime()+i*6e4?new Date(t.start.getTime()+i*6e4):s}}function ct(e,t){return{start:W(e.start,t),end:W(e.end,t)}}var Q=t();function lt({month:e,selection:t,marks:n,onPick:r,onPickRange:i,onPrev:a,onNext:s,onTitle:c,onDayMenu:l,title:u,className:f}){let p=new Date,m=K(e),h=u??pe(e),[g,_]=(0,z.useState)(null),v=(0,z.useRef)(g);(0,z.useEffect)(()=>{v.current=g});let y=e=>(document.elementFromPoint(e.clientX,e.clientY)?.closest(`[data-day]`))?.dataset.day??null,b=e=>{if(!i||e.button!==0)return;let t=y(e);t&&(e.currentTarget.setPointerCapture(e.pointerId),_({from:t,to:t}))},S=e=>{if(!v.current)return;let t=y(e);t&&t!==v.current.to&&_({...v.current,to:t})},C=e=>{let t=v.current;if(!t)return;if(e.currentTarget.releasePointerCapture(e.pointerId),_(null),t.from===t.to){w(e,H(t.from));return}let n=at(H(t.from),H(t.to));i?.(n.start,n.end)},w=(e,n)=>{if(e.shiftKey&&i&&t){let e=at(t.start,n);i(e.start,e.end)}else r(n)},T=g?at(H(g.from),H(g.to)):t;return(0,Q.jsxs)(`div`,{className:x(`select-none`,f),children:[(0,Q.jsxs)(`div`,{className:`mb-1 flex items-center justify-between`,children:[a?(0,Q.jsx)(`button`,{type:`button`,onClick:a,className:`rounded p-0.5 text-muted-foreground hover:bg-muted hover:text-foreground`,"aria-label":`Previous month`,children:(0,Q.jsx)(o,{className:`h-3.5 w-3.5`})}):(0,Q.jsx)(`span`,{}),c?(0,Q.jsx)(`button`,{type:`button`,onClick:c,className:`text-xs font-semibold hover:underline`,children:h}):(0,Q.jsx)(`span`,{className:`text-xs font-semibold`,children:h}),s?(0,Q.jsx)(`button`,{type:`button`,onClick:s,className:`rounded p-0.5 text-muted-foreground hover:bg-muted hover:text-foreground`,"aria-label":`Next month`,children:(0,Q.jsx)(d,{className:`h-3.5 w-3.5`})}):(0,Q.jsx)(`span`,{})]}),(0,Q.jsx)(`div`,{className:`grid grid-cols-7 text-center text-[10px] text-muted-foreground`,children:ae.map(e=>(0,Q.jsx)(`span`,{children:e[0]},e))}),(0,Q.jsx)(`div`,{className:x(`grid grid-cols-7 gap-y-px text-center text-[11px]`,g&&`cursor-crosshair`),onPointerDown:b,onPointerMove:S,onPointerUp:C,onPointerCancel:()=>_(null),children:m.map(t=>{let r=V(t),a=t.getMonth()===e.getMonth(),o=G(t,p),s=!!T&&t>=T.start&&t<T.end,c=!!T&&s&&G(t,T.start),u=!!T&&s&&G(t,new Date(T.end.getTime()-1)),d=n?.get(r)??[],f=[...new Set(d.map(nt))].slice(0,3);return(0,Q.jsxs)(`button`,{type:`button`,"data-day":r,onClick:e=>{(e.detail===0||!i)&&w(e,t)},onContextMenu:l?e=>{e.preventDefault(),l(e,t)}:void 0,"aria-label":d.length?`${t.toDateString()}, ${d.length} ${d.length===1?`entry`:`entries`}`:t.toDateString(),title:d.length?d.slice(0,6).map(e=>e.title).join(`
|
|
2
|
-
`)+(d.length>6?`\n+${d.length-6} more`:``):void 0,className:x(`relative mx-auto flex h-6 w-full items-center justify-center transition-colors hover:bg-muted`,c&&u?`rounded-full`:c?`rounded-l-full`:u?`rounded-r-full`:s?``:`rounded-full`,!a&&`text-muted-foreground/40`,o&&!s&&`font-bold text-primary`,s&&`bg-primary text-primary-foreground hover:bg-primary`,d.length>0&&!s&&`font-semibold`),style:d.length&&!s?{background:`color-mix(in srgb, ${f[0]} 22%, transparent)`}:void 0,children:[t.getDate(),d.length>0&&!s&&(0,Q.jsx)(`span`,{className:`absolute bottom-0 left-1/2 flex -translate-x-1/2 gap-px`,children:f.map(e=>(0,Q.jsx)(`span`,{className:`h-1 w-1 rounded-full`,style:{background:e}},e))})]},r)})})]})}function ut({occurrence:e,selected:t,moving:n,showTime:r=!0,onSelect:i,className:o,...s}){let c=nt(e),u=!e.allDay&&e.kind===`event`&&e.end.getTime()>e.start.getTime();return(0,Q.jsxs)(`button`,{type:`button`,onClick:t=>{t.stopPropagation(),i(e)},title:`${e.title}${e.calendar?` · ${e.calendar}`:``}`,className:x(`flex w-full min-w-0 items-center gap-1 truncate rounded px-1 py-px text-left text-[11px] leading-4 text-foreground transition-colors hover:brightness-110`,!e.recurring&&`touch-none`,t&&`ring-1 ring-ring`,n&&`cursor-grabbing ring-2 ring-primary shadow-elevation-2`,e.done&&`line-through opacity-60`,o),style:{background:rt(c,e.allDay||e.kind===`task`?28:14),borderLeft:`3px solid ${c}`},...s,children:[e.kind===`task`&&(0,Q.jsx)(a,{className:`h-3 w-3 shrink-0`,style:{color:c}}),r&&u&&(0,Q.jsx)(`span`,{className:`shrink-0 tabular-nums text-muted-foreground`,children:Z(e.start)}),(0,Q.jsx)(`span`,{className:`truncate`,children:e.title}),e.recurring&&(0,Q.jsx)(l,{className:`ml-auto h-2.5 w-2.5 shrink-0 text-muted-foreground`})]})}function dt(e){let[t,n]=(0,z.useState)(null),r=(0,z.useRef)(e);(0,z.useEffect)(()=>{r.current=e});let i=(0,z.useRef)(null),a=(0,z.useRef)(!1);(0,z.useEffect)(()=>()=>i.current?.stop(),[]);let o=e=>(document.elementFromPoint(e.clientX,e.clientY)?.closest(`[data-day]`))?.dataset.day??null;return{moving:t,handlers:e=>e.recurring?{}:{onPointerDown:t=>{if(t.button!==0||i.current)return;let s=o(t);if(!s)return;let c=e=>{let t=i.current;if(!t)return;let r=o(e);if(!r)return;let a=Math.round((H(r).getTime()-H(t.fromKey).getTime())/ie);a!==t.delta&&(t.delta=a,n(a?{key:t.o.key,...ct(t.o,a)}:null))},l=()=>{let e=i.current;if(!e||(e.stop(),n(null),!e.delta))return;a.current=!0,setTimeout(()=>{a.current=!1},0);let t=ct(e.o,e.delta);r.current(e.o,t.start,t.end)},u=()=>{i.current?.stop(),n(null)};window.addEventListener(`pointermove`,c),window.addEventListener(`pointerup`,l),window.addEventListener(`pointercancel`,u),i.current={o:e,fromKey:s,delta:0,stop:()=>{i.current=null,window.removeEventListener(`pointermove`,c),window.removeEventListener(`pointerup`,l),window.removeEventListener(`pointercancel`,u)}}},onClickCapture:e=>{a.current&&(a.current=!1,e.stopPropagation(),e.preventDefault())}},apply:e=>t?e.map(e=>e.key===t.key?{...e,start:t.start,end:t.end}:e):e}}var $=48,ft=30,pt=15,mt=`w-12`,ht=48;function gt({days:e,occurrences:t,selectedKey:n,pending:r,onSelect:i,onCreate:a,onMove:o,onPickDay:s,onEntryMenu:c,onSlotMenu:l,compact:u}){let d=(0,z.useRef)(null),f=(0,z.useRef)(null),[p,m]=(0,z.useState)(null),h=(0,z.useRef)(p);(0,z.useEffect)(()=>{h.current=p});let g=t=>{let n=f.current;if(!n)return null;let r=n.getBoundingClientRect(),i=(r.width-ht)/e.length,a=Math.floor((t.clientX-r.left-ht)/i),o=Math.max(0,Math.min(1439,(t.clientY-r.top)/$*60));return a<0||a>=e.length?null:{day:a,min:o}},_=e=>{if(e.button!==0||e.target.closest(`button`))return;let t=g(e);t&&(e.currentTarget.setPointerCapture(e.pointerId),m({fromDay:t.day,fromMin:t.min,toDay:t.day,toMin:t.min}))},v=e=>{if(!h.current)return;let t=g(e);t&&m({...h.current,toDay:t.day,toMin:t.min})},y=t=>{let n=h.current;if(!n)return;t.currentTarget.releasePointerCapture(t.pointerId),m(null);let r=it(e,n.fromDay,n.fromMin,n.toDay,n.toMin,ft);a(r.start,r.allDay,r.end)},b=t=>{let n=g(t);n&&(t.preventDefault(),l(t,it(e,n.day,n.min,n.day,n.min,ft).start,!1))},S=p?it(e,p.fromDay,p.fromMin,p.toDay,p.toMin,ft):r,[C,w]=(0,z.useState)(null),T=(0,z.useRef)(o);(0,z.useEffect)(()=>{T.current=o});let E=(0,z.useRef)(null);(0,z.useEffect)(()=>()=>E.current?.stop(),[]);let D=(0,z.useRef)(!1),O=(t,n)=>{if(t.button!==0||n.recurring||E.current)return;let r=g(t);if(!r)return;let i=t.target.dataset.resize?`resize`:`move`,a=null,o=t=>{let o=g(t);if(!o)return;let s=i===`move`?ot(e,n,r.day,r.min,o.day,o.min,pt):st(e,n,o.day,o.min,pt);a=s.start.getTime()===n.start.getTime()&&s.end.getTime()===n.end.getTime()?null:s,w(a?{key:n.key,...a,mode:i}:null)},s=()=>{l(),w(null),a&&(D.current=!0,setTimeout(()=>{D.current=!1},0),T.current(n,a.start,a.end))},c=()=>{l(),w(null)},l=()=>{E.current=null,window.removeEventListener(`pointermove`,o),window.removeEventListener(`pointerup`,s),window.removeEventListener(`pointercancel`,c)};window.addEventListener(`pointermove`,o),window.addEventListener(`pointerup`,s),window.addEventListener(`pointercancel`,c),E.current={stop:l}},k=dt(o),A=k.apply(t),ee=(0,z.useMemo)(()=>C?A.map(e=>e.key===C.key?{...e,start:C.start,end:C.end}:e):A,[A,C]),j=(0,z.useMemo)(()=>Be(ee),[ee]),[M,N]=(0,z.useState)(()=>new Date);(0,z.useEffect)(()=>{let e=setInterval(()=>N(new Date),6e4);return()=>clearInterval(e)},[]);let P=V(e[0]);(0,z.useEffect)(()=>{let t=d.current;t&&(t.scrollTop=(e.some(e=>G(e,M))?Math.max(0,M.getHours()-1):7)*$)},[P,e.length]);let F=Array.from({length:24},(e,t)=>t),I=e.map(e=>(j.get(V(e))??[]).filter(Ve)),L=Math.max(0,...I.map(e=>e.length)),te=!!p||!!C||!!k.moving;return(0,Q.jsxs)(`div`,{className:`flex h-full min-h-0 flex-col`,children:[(0,Q.jsxs)(`div`,{className:`flex shrink-0 border-b border-border`,children:[(0,Q.jsx)(`div`,{className:x(mt,`shrink-0`)}),e.map(e=>{let t=G(e,M);return(0,Q.jsxs)(`button`,{type:`button`,onClick:()=>s(e),className:`flex min-w-0 flex-1 flex-col items-center border-l border-border/60 py-1 hover:bg-muted/50`,title:`Open day`,children:[(0,Q.jsx)(`span`,{className:`text-[10px] uppercase tracking-wide text-muted-foreground`,children:ae[(e.getDay()+6)%7]}),(0,Q.jsx)(`span`,{className:x(`flex h-7 w-7 items-center justify-center rounded-full text-sm font-semibold`,t&&`bg-primary text-primary-foreground`),children:e.getDate()})]},V(e))})]}),L>0&&(0,Q.jsxs)(`div`,{className:x(`flex shrink-0 border-b border-border bg-muted/20`,k.moving&&`select-none`),children:[(0,Q.jsx)(`div`,{className:x(mt,`shrink-0 py-1 pr-1 text-right text-[10px] text-muted-foreground`),children:u?``:`all day`}),e.map((e,t)=>(0,Q.jsx)(`div`,{"data-day":V(e),className:`flex min-w-0 flex-1 flex-col gap-0.5 border-l border-border/60 p-0.5`,onClick:t=>{t.target===t.currentTarget&&a(U(e),!0)},onContextMenu:t=>{t.preventDefault(),l(t,U(e),!0)},children:I[t].map(e=>(0,Q.jsx)(ut,{occurrence:e,selected:e.key===n,moving:k.moving?.key===e.key,showTime:!1,onSelect:i,onContextMenu:t=>{t.preventDefault(),t.stopPropagation(),c(t,e)},...k.handlers(e)},e.key))},V(e)))]}),(0,Q.jsx)(`div`,{ref:d,className:`min-h-0 flex-1 overflow-y-auto`,children:(0,Q.jsxs)(`div`,{ref:f,className:x(`relative flex select-none`,p&&`cursor-crosshair`,C?.mode===`move`&&`cursor-grabbing`,C?.mode===`resize`&&`cursor-ns-resize`),style:{height:1152},onPointerDown:_,onPointerMove:v,onPointerUp:y,onPointerCancel:()=>m(null),onContextMenu:b,children:[(0,Q.jsx)(`div`,{className:x(mt,`relative shrink-0`),children:F.map(e=>(0,Q.jsx)(`div`,{className:`absolute right-1 -translate-y-1/2 text-[10px] tabular-nums text-muted-foreground`,style:{top:e*$},children:e===0?``:ye(e)},e))}),e.map(e=>{let t=He(e,j.get(V(e))??[]),r=G(e,M)?(M.getHours()*60+M.getMinutes())/60*$:null;return(0,Q.jsxs)(`div`,{"data-day":V(e),className:`relative min-w-0 flex-1 cursor-cell border-l border-border/60`,role:`presentation`,children:[S&&S.end>e&&S.start<U(new Date(e.getTime()+864e5))&&(0,Q.jsx)(`div`,{className:`pointer-events-none absolute inset-x-0.5 z-[5] rounded-md border border-primary bg-primary/15`,style:{top:J(S.start,e)/60*$,height:Math.max(8,(J(S.end,e)-J(S.start,e))/60*$)},children:(0,Q.jsx)(`span`,{className:`absolute left-1 top-0.5 text-[10px] font-medium text-primary`,children:S.allDay?`All day`:`${Z(S.start)} – ${Z(S.end)}`})}),F.map(e=>(0,Q.jsx)(`div`,{className:`pointer-events-none absolute inset-x-0 border-t border-border/50`,style:{top:e*$}},e)),t.map(e=>{let t=e.occurrence,r=nt(t),a=100/e.columns,o=e.height<45,s=C?.key===t.key,l=!t.recurring;return(0,Q.jsxs)(`button`,{type:`button`,onClick:e=>{if(e.stopPropagation(),D.current){D.current=!1;return}i(t)},onContextMenu:e=>{e.preventDefault(),e.stopPropagation(),c(e,t)},onPointerDown:e=>O(e,t),title:`${t.title} · ${Z(t.start)}${t.end>t.start?` – ${Z(t.end)}`:``}`,className:x(`absolute overflow-hidden rounded-md border-l-[3px] px-1.5 text-left text-[11px] leading-tight text-foreground shadow-elevation-1 transition-[filter] hover:brightness-110`,l&&`touch-none`,s?`z-20 ring-2 ring-primary shadow-elevation-2`:te&&`pointer-events-none`,t.key===n&&!s&&`ring-1 ring-ring`,t.done&&`line-through opacity-60`),style:{top:e.top/60*$,height:Math.max(18,e.height/60*$-2),left:`calc(${e.column*a}% + 2px)`,width:`calc(${a}% - 4px)`,background:rt(r,24),borderLeftColor:r,paddingTop:o?1:3},children:[(0,Q.jsx)(`span`,{className:x(`font-medium`,o?`inline`:`block truncate`),children:t.title}),!o&&(0,Q.jsxs)(`span`,{className:`block truncate text-[10px] text-muted-foreground`,children:[Z(t.start),t.end>t.start?` – ${Z(t.end)}`:``,t.calendar&&!u?` · ${t.calendar}`:``]}),l&&t.kind===`event`&&(0,Q.jsx)(`span`,{"data-resize":`1`,className:`absolute inset-x-0 bottom-0 h-1.5 cursor-ns-resize`})]},t.key)}),r!==null&&(0,Q.jsx)(`div`,{className:`pointer-events-none absolute inset-x-0 z-10 border-t-2 border-destructive`,style:{top:r},children:(0,Q.jsx)(`span`,{className:`absolute -left-1 -top-[5px] h-2 w-2 rounded-full bg-destructive`})})]},V(e))})]})})]})}var _t=3;function vt({month:e,occurrences:t,selectedKey:n,pending:r,onSelect:i,onCreate:a,onMove:o,onPickDay:s,onEntryMenu:c,onSlotMenu:l,narrow:u}){let d=K(e),f=dt(o),p=f.apply(t),m=(0,z.useMemo)(()=>Be(p),[p]),h=new Date,[g,_]=(0,z.useState)(null),v=(0,z.useRef)(g);(0,z.useEffect)(()=>{v.current=g});let y=e=>(document.elementFromPoint(e.clientX,e.clientY)?.closest(`[data-day]`))?.dataset.day??null,b=e=>{if(u||e.button!==0||e.target.closest(`button`))return;let t=y(e);t&&(e.currentTarget.setPointerCapture(e.pointerId),_({from:t,to:t}))},S=e=>{if(!v.current)return;let t=y(e);t&&t!==v.current.to&&_({...v.current,to:t})},C=e=>{let t=v.current;if(!t)return;e.currentTarget.releasePointerCapture(e.pointerId),_(null);let n=at(H(t.from),H(t.to));a(n.start,!0,n.end)},w=e=>{let t=y(e);t&&(e.preventDefault(),l(e,H(t),!0))},T=g?at(H(g.from),H(g.to)):r;return(0,Q.jsxs)(`div`,{className:`flex h-full min-h-0 flex-col`,children:[(0,Q.jsx)(`div`,{className:`grid shrink-0 grid-cols-7 border-b border-border text-center text-[10px] uppercase tracking-wide text-muted-foreground`,children:ae.map(e=>(0,Q.jsx)(`span`,{className:`py-1`,children:u?e[0]:e},e))}),(0,Q.jsx)(`div`,{className:x(`grid min-h-0 flex-1 grid-cols-7 grid-rows-6 overflow-y-auto`,g&&`cursor-crosshair select-none`,f.moving&&`select-none`),onPointerDown:b,onPointerMove:S,onPointerUp:C,onPointerCancel:()=>_(null),onContextMenu:w,children:d.map(t=>{let r=V(t),a=m.get(r)??[],o=t.getMonth()===e.getMonth(),l=G(t,h),d=a.length-_t;return(0,Q.jsxs)(`div`,{role:`presentation`,"data-day":r,onClick:e=>{u&&e.target===e.currentTarget&&s(t)},className:x(`flex min-h-[3.5rem] min-w-0 flex-col gap-0.5 border-b border-r border-border/60 p-0.5`,!o&&`bg-muted/20 text-muted-foreground/60`,!u&&`cursor-cell`,T&&t>=T.start&&t<T.end&&`bg-primary/15 ring-1 ring-inset ring-primary`),children:[(0,Q.jsx)(`button`,{type:`button`,onClick:()=>s(t),className:x(`mx-auto flex h-5 w-5 items-center justify-center rounded-full text-[11px] hover:bg-muted sm:mx-0`,l&&`bg-primary font-bold text-primary-foreground hover:bg-primary`),title:`Open day`,children:t.getDate()}),u?(0,Q.jsx)(`div`,{className:`flex flex-wrap justify-center gap-0.5 px-0.5`,children:a.slice(0,4).map(e=>(0,Q.jsx)(`span`,{className:`h-1.5 w-1.5 rounded-full`,style:{background:nt(e)}},e.key))}):(0,Q.jsxs)(Q.Fragment,{children:[a.slice(0,_t).map(e=>(0,Q.jsx)(ut,{occurrence:e,selected:e.key===n,moving:f.moving?.key===e.key,onSelect:i,onContextMenu:t=>{t.preventDefault(),t.stopPropagation(),c(t,e)},...f.handlers(e)},e.key)),d>0&&(0,Q.jsxs)(`button`,{type:`button`,onClick:()=>s(t),className:`px-1 text-left text-[10px] text-muted-foreground hover:text-foreground`,children:[`+`,d,` more`]})]})]},r)})})]})}function yt({year:e,occurrences:t,onPickDay:n,onPickRange:r,onPickMonth:i,onSlotMenu:a}){let o=(0,z.useMemo)(()=>Be(t),[t]),s=Array.from({length:12},(t,n)=>new Date(e,n,1));return(0,Q.jsx)(`div`,{className:`grid h-full min-h-0 grid-cols-[repeat(auto-fill,minmax(11rem,1fr))] gap-x-4 gap-y-5 overflow-y-auto p-3`,children:s.map(e=>(0,Q.jsx)(lt,{month:e,marks:o,title:e.toLocaleDateString(void 0,{month:`long`}),onTitle:()=>i(e),onPick:n,onPickRange:r,onDayMenu:(e,t)=>a(e,t,!0)},V(e)))})}function bt({occurrences:e,selectedKey:t,onSelect:n,onEntryMenu:r,onEarlier:i,onLater:a,onPickDay:o,loading:s}){let c=(0,z.useMemo)(()=>[...Be(e).entries()].sort(([e],[t])=>e.localeCompare(t)),[e]),l=new Date;return(0,Q.jsxs)(`div`,{className:`h-full min-h-0 overflow-y-auto`,children:[(0,Q.jsx)(`div`,{className:`flex justify-center py-2`,children:(0,Q.jsx)(`button`,{type:`button`,onClick:i,className:`rounded-md border border-border px-3 py-1 text-xs text-muted-foreground hover:bg-muted hover:text-foreground`,children:`Earlier`})}),!s&&!c.length&&(0,Q.jsx)(`p`,{className:`py-10 text-center text-sm text-muted-foreground`,children:`Nothing scheduled in this range.`}),c.map(([e,i])=>{let a=H(e),s=G(a,l);return(0,Q.jsxs)(`div`,{className:`flex border-t border-border/60 px-2 py-2`,children:[(0,Q.jsxs)(`button`,{type:`button`,onClick:()=>o(a),className:`flex w-14 shrink-0 flex-col items-start`,title:`Open day`,children:[(0,Q.jsx)(`span`,{className:x(`flex h-8 w-8 items-center justify-center rounded-full text-lg font-semibold`,s&&`bg-primary text-primary-foreground`),children:a.getDate()}),(0,Q.jsxs)(`span`,{className:`text-[10px] uppercase tracking-wide text-muted-foreground`,children:[me(a),`, `,ae[(a.getDay()+6)%7]]})]}),(0,Q.jsx)(`div`,{className:`min-w-0 flex-1 space-y-0.5`,children:i.map(e=>{let i=nt(e),a=!Ve(e)&&e.kind===`event`;return(0,Q.jsxs)(`button`,{type:`button`,onClick:()=>n(e),onContextMenu:t=>{t.preventDefault(),r(t,e)},className:x(`flex w-full items-center gap-2 rounded-md px-2 py-1 text-left text-sm hover:bg-muted`,e.key===t&&`bg-muted ring-1 ring-ring`,e.done&&`line-through opacity-60`),children:[(0,Q.jsx)(`span`,{className:`h-2.5 w-2.5 shrink-0 rounded-full`,style:{background:i}}),(0,Q.jsx)(`span`,{className:`w-[7.5rem] shrink-0 text-xs tabular-nums text-muted-foreground`,children:a?`${Z(e.start)}${e.end>e.start?` – ${Z(e.end)}`:``}`:e.kind===`task`?`due ${Z(e.start)}`:`All day`}),(0,Q.jsx)(`span`,{className:`truncate`,children:e.title}),e.calendar&&e.kind===`event`&&(0,Q.jsx)(`span`,{className:`ml-auto shrink-0 text-[10px] text-muted-foreground`,children:e.calendar})]},e.key)})})]},e)}),(0,Q.jsx)(`div`,{className:`flex justify-center py-2`,children:(0,Q.jsx)(`button`,{type:`button`,onClick:a,className:`rounded-md border border-border px-3 py-1 text-xs text-muted-foreground hover:bg-muted hover:text-foreground`,children:`Later`})})]})}var xt=`3.0`,St=[{id:`none`,label:`Does not repeat`},{id:`daily`,label:`Every day`},{id:`weekdays`,label:`Every weekday`},{id:`weekly`,label:`Every week`},{id:`monthly`,label:`Every month`},{id:`yearly`,label:`Every year`},{id:`custom`,label:`Custom (RRULE)…`}];function Ct(e,t){let n=e.data??{},r=n.allDay===!0,i=String(n.start??``),a=typeof n.end==`string`?n.end:``,o=typeof n.recurrence==`string`?n.recurrence:``,s=Oe(o||void 0),c=Ae(o||void 0);return{title:String(n.title??``),calendar:typeof n.calendar==`string`?n.calendar:Et(e)?``:t,allDay:r,start:r?i.slice(0,10):F(i),end:r?Dt(i.slice(0,10),a):F(a),location:String(n.location??``),description:String(n.description??``),repeat:s,until:c.until,count:c.count===null?``:String(c.count),rrule:o}}function wt(e,t){let n=e.end??new Date(e.start.getTime()+36e5);return{title:``,calendar:t,allDay:e.allDay,start:e.allDay?V(e.start):oe(e.start),end:e.allDay?V(W(n,-1)<e.start?e.start:W(n,-1)):oe(n),location:``,description:``,repeat:`none`,until:``,count:``,rrule:``}}function Tt(e){if(e.repeat===`custom`)return e.rrule.trim();let t=Number(e.count);return ke(e.repeat,{until:e.until,count:Number.isInteger(t)&&t>0?t:null})}function Et(e){let t=e.metadata;return typeof t?.source==`string`&&t.source?{source:t.source,connector:typeof t.connector==`string`?t.connector:``}:null}function Dt(e,t){if(!t)return``;let[n,r,i]=t.slice(0,10).split(`-`).map(Number),a=V(new Date(n,r-1,i-1));return a<e?e:a}function Ot(e){return`${V(W(H(e),1))}T00:00:00.000Z`}function kt(e,t){let n={...e,title:t.title.trim()},r=(e,t)=>{t===void 0||t===``||t===!1?delete n[e]:n[e]=t};return r(`calendar`,t.calendar.trim()),r(`allDay`,t.allDay),r(`location`,t.location.trim()),r(`description`,t.description.trim()),r(`recurrence`,Tt(t)),t.allDay?(n.start=`${t.start}T00:00:00.000Z`,r(`end`,t.end?Ot(t.end):void 0)):(n.start=I(t.start),r(`end`,I(t.end))),n}function At(e){return e.title.trim()?e.start?e.end&&e.end<e.start?`The end is before the start.`:e.calendar.includes(`:`)?`A calendar name cannot contain ":".`:e.repeat===`custom`&&(!e.rrule.trim()||!Se(e.rrule))?`Enter a supported RRULE (FREQ=…, INTERVAL, COUNT, UNTIL, BYDAY, BYMONTHDAY, BYMONTH).`:e.repeat!==`none`&&e.repeat!==`custom`&&e.until&&e.until<e.start.slice(0,10)?`The series ends before it starts.`:e.repeat!==`none`&&e.repeat!==`custom`&&e.count&&!(Number.isInteger(Number(e.count))&&Number(e.count)>0)?`The number of occurrences must be a whole number above zero.`:null:`Pick a start.`:`Give the event a title.`}function jt({subject:e,target:t,workspaceName:n,calendars:r,defaultCalendar:a,onClose:o,onSaved:s,onDelete:u}){let d=e.kind===`occurrence`?e.occurrence.doc:null,p=e.kind===`occurrence`&&e.occurrence.kind===`task`,[m,h]=(0,z.useState)(()=>d?Ct(d,a):wt(e.draft,a)),[g,y]=(0,z.useState)(!1),[S,C]=(0,z.useState)(null),[T,E]=(0,z.useState)(!1),D=e.kind===`draft`?`draft:${e.draft.start.getTime()}:${e.draft.end?.getTime()??``}:${e.draft.allDay}`:e.occurrence.key,[k,A]=(0,z.useState)(D);k!==D&&(A(D),h(d?Ct(d,a):wt(e.draft,a)),C(null)),(0,z.useEffect)(()=>{let e=e=>{e.key===`Escape`&&o()};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[o]);let j=e=>h(t=>({...t,...e})),M=d?Et(d):null,N=typeof d?.data?.htmlLink==`string`?d.data.htmlLink:null,F=async()=>{let e=At(m);if(e){C(e);return}y(!0),C(null);try{if(d){if(!n)throw Error(`No workspace resolved for this calendar`);await O(n,{id:d.id,schema:d.schema,schemaVersion:d.schemaVersion||xt,data:kt(d.data??{},m),metadata:d.metadata})}else await ee(t,[{schema:w,schemaVersion:xt,data:kt({},m),metadata:{features:[]}}]);s(m.calendar.trim())}catch(e){C(e instanceof Error?e.message:`Failed to save the event`)}finally{y(!1)}},I=p?`Task`:d?`Event`:`New event`;return(0,Q.jsxs)(`div`,{className:`flex h-full min-h-0 flex-col`,children:[(0,Q.jsxs)(`div`,{className:`flex shrink-0 items-center gap-2 border-b border-border px-3 py-2`,children:[(0,Q.jsx)(`span`,{className:`h-3 w-3 rounded-full`,style:{background:tt(p?`tasks`:m.calendar)}}),(0,Q.jsx)(`span`,{className:`text-sm font-semibold`,children:I}),d&&(0,Q.jsxs)(`span`,{className:`text-[10px] text-muted-foreground`,children:[`#`,d.id]}),(0,Q.jsx)(`span`,{className:`flex-1`}),d&&n&&(0,Q.jsx)(i,{to:`/workspaces/${encodeURIComponent(n)}/documents/${d.id}`,className:`rounded p-1 text-muted-foreground hover:bg-muted hover:text-foreground`,title:`Open document`,"aria-label":`Open document`,children:(0,Q.jsx)(_,{className:`h-3.5 w-3.5`})}),d&&(0,Q.jsx)(`button`,{type:`button`,onClick:()=>E(!0),className:`rounded p-1 text-muted-foreground hover:bg-muted hover:text-foreground`,title:`Link to…`,"aria-label":`Link to…`,children:(0,Q.jsx)(b,{className:`h-3.5 w-3.5`})}),d&&!p&&(0,Q.jsx)(`button`,{type:`button`,onClick:()=>{u(d)},className:`rounded p-1 text-muted-foreground hover:bg-muted hover:text-destructive`,title:`Delete (moves to trash)`,"aria-label":`Delete`,children:(0,Q.jsx)(f,{className:`h-3.5 w-3.5`})}),(0,Q.jsx)(`button`,{type:`button`,onClick:o,className:`rounded p-1 text-muted-foreground hover:bg-muted hover:text-foreground`,"aria-label":`Close`,children:(0,Q.jsx)(c,{className:`h-4 w-4`})})]}),p&&d?(0,Q.jsx)(Ft,{doc:d,occurrence:e.occurrence,workspaceName:n,onSaved:()=>s(``)}):(0,Q.jsxs)(`div`,{className:`min-h-0 flex-1 space-y-3 overflow-y-auto p-3`,children:[(0,Q.jsx)(`input`,{value:m.title,onChange:e=>j({title:e.target.value}),placeholder:`Title`,autoFocus:!d,spellCheck:!1,className:`w-full border-0 border-b border-border bg-transparent px-0 py-1 text-base font-semibold outline-none placeholder:text-muted-foreground/60 focus:border-ring`}),(0,Q.jsx)(Nt,{value:m.calendar,calendars:r,onChange:e=>j({calendar:e})}),(0,Q.jsxs)(`label`,{className:`flex items-center gap-2 text-xs`,children:[(0,Q.jsx)(`input`,{type:`checkbox`,checked:m.allDay,onChange:e=>{let t=e.target.checked;if(t)j({allDay:t,start:m.start.slice(0,10),end:(m.end||m.start).slice(0,10)});else{let e=m.start.slice(0,10)||V(new Date),n=(m.end||e).slice(0,10);j(n>e?{allDay:t,start:`${e}T09:00`,end:`${e}T10:00`,repeat:m.repeat===`none`?`daily`:m.repeat,until:n,count:``}:{allDay:t,start:`${e}T09:00`,end:`${e}T10:00`})}},className:`h-4 w-4 accent-primary`}),`All day`]}),(0,Q.jsxs)(`div`,{className:`grid grid-cols-1 gap-2 sm:grid-cols-2`,children:[(0,Q.jsxs)(`label`,{className:`block text-xs`,children:[(0,Q.jsx)(`span`,{className:`text-muted-foreground`,children:`Start`}),m.allDay?(0,Q.jsx)(`div`,{className:`mt-1`,children:(0,Q.jsx)(L,{value:m.start,onChange:e=>j({start:e,end:m.end&&m.end<e?e:m.end})})}):(0,Q.jsx)(`div`,{className:`mt-1`,children:(0,Q.jsx)(P,{value:m.start,onChange:e=>j({start:e}),clearable:!1})})]}),(0,Q.jsxs)(`label`,{className:`block text-xs`,children:[(0,Q.jsx)(`span`,{className:`text-muted-foreground`,children:`End`}),m.allDay?(0,Q.jsx)(`div`,{className:`mt-1`,children:(0,Q.jsx)(L,{value:m.end,min:m.start,placeholder:`Same day`,onChange:e=>j({end:e})})}):(0,Q.jsx)(`div`,{className:`mt-1`,children:(0,Q.jsx)(P,{value:m.end,onChange:e=>j({end:e}),placeholder:`No end`})})]})]}),(0,Q.jsxs)(`label`,{className:`block text-xs`,children:[(0,Q.jsxs)(`span`,{className:`flex items-center gap-1 text-muted-foreground`,children:[(0,Q.jsx)(l,{className:`h-3 w-3`}),` Repeat`]}),(0,Q.jsx)(`select`,{value:m.repeat,onChange:e=>j({repeat:e.target.value,rrule:e.target.value===`custom`?m.rrule||ke(m.repeat)||`FREQ=WEEKLY`:m.rrule}),className:`mt-1 h-8 w-full rounded-md border border-input bg-transparent px-2 text-sm`,children:St.map(e=>(0,Q.jsx)(`option`,{value:e.id,children:e.label},e.id))}),m.repeat===`custom`&&(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(`input`,{value:m.rrule,onChange:e=>j({rrule:e.target.value}),placeholder:`FREQ=WEEKLY;INTERVAL=2;BYDAY=TU,TH`,spellCheck:!1,className:`mt-1 h-8 w-full rounded-md border border-input bg-transparent px-2 font-mono text-xs`}),(0,Q.jsx)(`span`,{className:`mt-0.5 block text-[11px] text-muted-foreground`,children:Se(m.rrule)?De(Se(m.rrule)):`RFC 5545 RRULE value`})]})]}),m.repeat!==`none`&&m.repeat!==`custom`&&(0,Q.jsx)(Mt,{fields:m,patch:j}),(0,Q.jsxs)(`label`,{className:`block text-xs`,children:[(0,Q.jsx)(`span`,{className:`text-muted-foreground`,children:`Location`}),(0,Q.jsx)(`input`,{value:m.location,onChange:e=>j({location:e.target.value}),spellCheck:!1,className:`mt-1 h-8 w-full rounded-md border border-input bg-transparent px-2 text-sm`})]}),(0,Q.jsxs)(`div`,{className:`text-xs`,children:[(0,Q.jsx)(`span`,{className:`text-muted-foreground`,children:`Description`}),(0,Q.jsx)(`div`,{className:`mt-1 rounded-md border border-input px-2 py-1.5`,children:(0,Q.jsx)(re,{value:m.description,onChange:e=>j({description:e}),placeholder:`Notes, agenda, links…`})})]}),M&&(0,Q.jsxs)(`p`,{className:`rounded-md bg-muted/50 px-2 py-1.5 text-[11px] text-muted-foreground`,children:[`Synced from `,M.connector||M.source,`. Edits stay in Canvas unless the connector supports write-back.`,N&&(0,Q.jsxs)(Q.Fragment,{children:[` `,(0,Q.jsx)(`a`,{href:N,target:`_blank`,rel:`noopener noreferrer`,className:`underline hover:text-foreground`,children:`Open at source`})]})]}),e.kind===`occurrence`&&e.occurrence.unsupportedRule&&(0,Q.jsx)(`p`,{className:`text-[11px] text-muted-foreground`,children:`This series uses RRULE parts the calendar cannot expand; only its first occurrence is shown.`}),S&&(0,Q.jsx)(`p`,{className:`text-xs text-destructive`,role:`alert`,children:S})]}),!p&&(0,Q.jsxs)(`div`,{className:`flex shrink-0 items-center justify-end gap-2 border-t border-border px-3 py-2`,children:[(0,Q.jsx)(Pt,{doc:d}),(0,Q.jsx)(`button`,{type:`button`,onClick:o,className:`rounded-md border border-border px-3 py-1.5 text-xs hover:bg-muted`,children:`Cancel`}),(0,Q.jsxs)(`button`,{type:`button`,onClick:F,disabled:g,className:x(`flex items-center gap-1 rounded-md bg-primary px-3 py-1.5 text-xs text-primary-foreground disabled:opacity-50`),children:[g&&(0,Q.jsx)(v,{className:`h-3 w-3 animate-spin`}),d?`Save`:`Create`]})]}),T&&d&&(0,Q.jsx)(ne,{documentId:d.id,workspaceName:n??void 0,onClose:()=>E(!1)})]})}function Mt({fields:e,patch:t}){let n=e.until?`until`:e.count?`count`:`never`,r=e.start.slice(0,10),i=Tt(e),a=i?Se(i):null;return(0,Q.jsxs)(`div`,{className:`text-xs`,children:[(0,Q.jsx)(`span`,{className:`text-muted-foreground`,children:`Ends`}),(0,Q.jsxs)(`div`,{className:`mt-1 flex items-center gap-1.5`,children:[(0,Q.jsxs)(`select`,{value:n,onChange:n=>{let i=n.target.value;t(i===`never`?{until:``,count:``}:i===`until`?{until:e.until||r,count:``}:{until:``,count:e.count||`10`})},className:`h-8 w-28 shrink-0 rounded-md border border-input bg-transparent px-2 text-sm`,children:[(0,Q.jsx)(`option`,{value:`never`,children:`Never`}),(0,Q.jsx)(`option`,{value:`until`,children:`On date`}),(0,Q.jsx)(`option`,{value:`count`,children:`After`})]}),n===`until`&&(0,Q.jsx)(`div`,{className:`min-w-0 flex-1`,children:(0,Q.jsx)(L,{value:e.until,min:r,onChange:e=>t({until:e})})}),n===`count`&&(0,Q.jsxs)(`label`,{className:`flex items-center gap-1.5`,children:[(0,Q.jsx)(`input`,{type:`number`,min:1,step:1,value:e.count,onChange:e=>t({count:e.target.value}),className:`h-8 w-20 rounded-md border border-input bg-transparent px-2 text-sm tabular-nums`}),(0,Q.jsx)(`span`,{className:`text-muted-foreground`,children:`occurrences`})]})]}),a&&(0,Q.jsx)(`span`,{className:`mt-0.5 block text-[11px] text-muted-foreground`,children:De(a)})]})}function Nt({value:e,calendars:t,onChange:n}){let r=t.some(t=>t.toLowerCase()===e.toLowerCase()),[i,a]=(0,z.useState)(!r&&!e&&t.length===0),o=r||!e?t:[e,...t];return(0,Q.jsxs)(`label`,{className:`block text-xs`,children:[(0,Q.jsx)(`span`,{className:`text-muted-foreground`,children:`Calendar`}),i?(0,Q.jsxs)(`span`,{className:`mt-1 flex gap-1`,children:[(0,Q.jsx)(`input`,{autoFocus:!0,value:e,onChange:e=>n(e.target.value),placeholder:`New calendar name`,spellCheck:!1,className:`h-8 min-w-0 flex-1 rounded-md border border-input bg-transparent px-2 text-sm outline-none focus-visible:ring-1 focus-visible:ring-ring`}),t.length>0&&(0,Q.jsx)(`button`,{type:`button`,onClick:()=>{a(!1),n(t[0])},className:`rounded-md border border-border px-2 text-xs text-muted-foreground hover:bg-muted`,"aria-label":`Pick an existing calendar`,children:(0,Q.jsx)(c,{className:`h-3 w-3`})})]}):(0,Q.jsxs)(`select`,{value:e,onChange:e=>{e.target.value===`\0new`?(a(!0),n(``)):n(e.target.value)},className:`mt-1 h-8 w-full rounded-md border border-input bg-transparent px-2 text-sm`,children:[!e&&(0,Q.jsx)(`option`,{value:``,children:`No calendar`}),o.map(e=>(0,Q.jsx)(`option`,{value:e,children:e},e)),(0,Q.jsx)(`option`,{value:`\0new`,children:`New calendar…`})]})]})}function Pt({doc:e}){let t=A(e??{id:-1,locations:[]});return!e||!t.replicating?null:(0,Q.jsx)(`span`,{className:`mr-auto text-[10px] text-muted-foreground`,children:t.label})}function Ft({doc:e,occurrence:t,workspaceName:n,onSaved:r}){let[i,o]=(0,z.useState)(!1),s=t.done;return(0,Q.jsxs)(`div`,{className:`space-y-3 p-3 text-sm`,children:[(0,Q.jsxs)(`div`,{className:`flex items-start gap-2`,children:[(0,Q.jsx)(`button`,{type:`button`,onClick:async()=>{if(n){o(!0);try{let t=s?`pending`:`completed`;await O(n,{id:e.id,schema:e.schema,schemaVersion:e.schemaVersion,data:{...e.data??{},status:t,completed:t===`completed`},metadata:e.metadata}),r()}finally{o(!1)}}},disabled:i,className:`mt-0.5 text-muted-foreground hover:text-foreground`,"aria-label":s?`Mark as pending`:`Mark as completed`,children:s?(0,Q.jsx)(a,{className:`h-4 w-4 text-success`}):(0,Q.jsx)(g,{className:`h-4 w-4`})}),(0,Q.jsxs)(`div`,{className:`min-w-0`,children:[(0,Q.jsx)(`p`,{className:x(`font-semibold`,s&&`line-through text-muted-foreground`),children:t.title}),(0,Q.jsxs)(`p`,{className:`text-xs text-muted-foreground`,children:[`Due `,t.start.toLocaleString(void 0,{dateStyle:`medium`,timeStyle:`short`})]})]})]}),typeof e.data?.description==`string`&&e.data.description&&(0,Q.jsx)(`p`,{className:`whitespace-pre-wrap text-xs text-muted-foreground`,children:e.data.description}),(0,Q.jsx)(`p`,{className:`text-[11px] text-muted-foreground`,children:`Edit the task in the Todos app or on its document page.`})]})}function It({menu:e,onClose:t,onOpen:n,onOpenDocument:r,onToggleDone:i,onDelete:o,onCreate:s,onPickDay:c}){let l=e=>()=>{t(),e()};return(0,Q.jsx)(S,{x:e.x,y:e.y,onClose:t,className:`min-w-44 rounded-md border bg-popover p-1 text-xs shadow-elevation-3`,children:e.kind===`entry`?(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(`p`,{className:`truncate px-3 py-1.5 text-[11px] text-muted-foreground`,title:e.occurrence.title,children:e.occurrence.title}),(0,Q.jsx)(Lt,{icon:(0,Q.jsx)(h,{className:`h-3.5 w-3.5`}),onClick:l(()=>n(e.occurrence)),children:`Open`}),r&&(0,Q.jsx)(Lt,{icon:(0,Q.jsx)(_,{className:`h-3.5 w-3.5`}),onClick:l(()=>r(e.occurrence)),children:`Open document`}),e.occurrence.kind===`task`&&(0,Q.jsx)(Lt,{icon:e.occurrence.done?(0,Q.jsx)(g,{className:`h-3.5 w-3.5`}):(0,Q.jsx)(a,{className:`h-3.5 w-3.5`}),onClick:l(()=>i(e.occurrence)),children:e.occurrence.done?`Mark as pending`:`Mark as completed`}),e.occurrence.kind===`event`&&(0,Q.jsx)(Lt,{icon:(0,Q.jsx)(f,{className:`h-3.5 w-3.5`}),className:`text-destructive`,onClick:l(()=>o(e.occurrence)),children:`Delete…`})]}):(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsxs)(`p`,{className:`px-3 py-1.5 text-[11px] text-muted-foreground`,children:[ge(e.start),e.allDay?``:`, ${Z(e.start)}`]}),(0,Q.jsx)(Lt,{icon:(0,Q.jsx)(y,{className:`h-3.5 w-3.5`}),onClick:l(()=>s(e.start,e.allDay)),children:e.allDay?`New event`:`New event at ${Z(e.start)}`}),!e.allDay&&(0,Q.jsx)(Lt,{icon:(0,Q.jsx)(m,{className:`h-3.5 w-3.5`}),onClick:l(()=>s(e.start,!0)),children:`New all-day event`}),(0,Q.jsx)(Lt,{icon:(0,Q.jsx)(h,{className:`h-3.5 w-3.5`}),onClick:l(()=>c(e.start)),children:`Open day`})]})})}function Lt({icon:e,onClick:t,className:n,children:r}){return(0,Q.jsxs)(`button`,{type:`button`,onClick:t,className:x(`flex w-full items-center gap-2 rounded px-3 py-1.5 text-left hover:bg-accent`,n),children:[(0,Q.jsx)(`span`,{className:`text-muted-foreground`,children:e}),r]})}var Rt=640,zt=420,Bt=30,Vt=14;function Ht(e,t,n,r){switch(e){case`day`:{let e=U(t);return{start:e,end:W(e,n)}}case`week`:{let e=ce(t);return{start:e,end:W(e,7)}}case`month`:{let e=K(t);return{start:e[0],end:W(e[41],1)}}case`year`:return{start:new Date(t.getFullYear(),0,1),end:new Date(t.getFullYear()+1,0,1)};case`schedule`:{let e=U(t);return{start:W(e,-r.before),end:W(e,r.after)}}}}function Ut(e,t,n,r){switch(e){case`day`:return W(t,n*r);case`week`:return W(t,7*r);case`month`:return se(t,r);case`year`:return new Date(t.getFullYear()+r,t.getMonth(),1);case`schedule`:return W(t,Bt*r)}}function Wt(e,t,n,r){switch(e){case`day`:return n>1?_e(t,W(t,n-1)):r?ge(t):he(t);case`week`:return ve(ce(t));case`month`:return pe(t);case`year`:return String(t.getFullYear());case`schedule`:return r?ge(t):`From ${he(t)}`}}function Gt({autoAdd:e=!1}){let t=te(),n=t?.mode===`workspace`?t.workspaceName:t?.mode===`context`?`ctx:${t.contextId}`:null,[i,a]=(0,z.useState)(()=>Je(n)),c=(0,z.useCallback)(e=>{a(t=>{let r={...t,...e};return Ye(n,r),r})},[n]),l=i.view,[f,m]=(0,z.useState)(()=>U(new Date)),[h,g]=(0,z.useState)(1),[_,y]=(0,z.useState)(null),b=r(),[S,C]=(0,z.useState)({before:0,after:Bt}),[w,T]=(0,z.useState)(()=>e?{kind:`draft`,draft:{start:Kt(),allDay:!1}}:null),[E,D]=(0,z.useState)(!1),k=(0,z.useRef)(null),[A,ee]=(0,z.useState)(1024);(0,z.useEffect)(()=>{let e=k.current;if(!e)return;let t=new ResizeObserver(e=>{for(let t of e)ee(t.contentRect.width)});return t.observe(e),()=>t.disconnect()},[]);let M=A<Rt,N=A<zt,P=(0,z.useMemo)(()=>Ht(l,f,h,S),[l,f,h,S]),{docs:F,loading:I,error:L,scope:R,knownCalendars:ne,reload:re,removeDoc:ae,patchDoc:B}=et(t,P.start,P.end,i.showTasks),V=(0,z.useMemo)(()=>{let e=new Map;for(let t of ne)e.set(t,t);for(let t of F){let n=t.data?.calendar;typeof n==`string`&&n.trim()&&e.set(n.trim().toLowerCase(),n.trim())}return i.defaultCalendar&&e.set(i.defaultCalendar.toLowerCase(),e.get(i.defaultCalendar.toLowerCase())??i.defaultCalendar),[...e.values()].sort((e,t)=>e.localeCompare(t))},[ne,F,i.defaultCalendar]),H=(0,z.useMemo)(()=>new Set(i.hidden),[i.hidden]),oe=(0,z.useMemo)(()=>F.some(e=>e.schema.startsWith(`data/schema/event`)&&!(typeof e.data?.calendar==`string`&&e.data.calendar.trim())),[F]),G=(0,z.useMemo)(()=>ze(F.filter(e=>{let t=typeof e.data?.calendar==`string`?e.data.calendar.trim().toLowerCase():``;return!H.has(t||``)}),P.start,P.end),[F,H,P]),K=w?.kind===`occurrence`?w.occurrence.key:null,q=(0,z.useCallback)((e,t)=>{m(U(e)),g(1),C({before:0,after:Bt}),t&&c({view:t})},[c]),J=(0,z.useCallback)((e,t)=>{let n=Math.round((U(t).getTime()-U(e).getTime())/ie);if(n>Vt){q(e,`month`);return}q(e,`day`),g(Math.max(1,n))},[q]),ue=(0,z.useCallback)(e=>{g(1),c({view:e})},[c]),Y=(0,z.useMemo)(()=>l===`day`||l===`week`?{start:P.start,end:P.end}:{start:f,end:W(f,1)},[l,P,f]),de=(0,z.useMemo)(()=>{if(w?.kind!==`draft`)return null;let{start:e,allDay:t,end:n}=w.draft;return{start:e,allDay:t,end:n??(t?W(U(e),1):new Date(e.getTime()+36e5))}},[w]),X=(0,z.useCallback)((e,t,n)=>T({kind:`draft`,draft:{start:e,allDay:t,end:n}}),[]),fe=(0,z.useCallback)(e=>T({kind:`occurrence`,occurrence:e}),[]),pe=(0,z.useCallback)(async(e,t,n)=>{if(!R)return;let r=e.doc,i=Ue(r.data??{},e,t,n);B({...r,data:i});try{await O(R.workspaceName,{id:r.id,schema:r.schema,schemaVersion:r.schemaVersion||`3.0`,data:i,metadata:r.metadata})}catch{B(r)}},[R,B]),me=(0,z.useCallback)(async e=>{if(!R)return;let t=e.doc,n=e.done?`pending`:`completed`,r={...t.data??{},status:n,completed:n===`completed`};B({...t,data:r});try{await O(R.workspaceName,{id:t.id,schema:t.schema,schemaVersion:t.schemaVersion,data:r,metadata:t.metadata})}catch{B(t)}},[R,B]),he=(0,z.useCallback)((e,t)=>y({x:e.clientX,y:e.clientY,kind:`entry`,occurrence:t}),[]),ge=(0,z.useCallback)((e,t,n)=>y({x:e.clientX,y:e.clientY,kind:`slot`,start:t,allDay:n}),[]),Z=(0,z.useCallback)(async e=>{let t=e.data?.title?`"${e.data.title}"`:`#${e.id}`;if(window.confirm(`Delete event ${t}?\n\nIt is removed from this path and moves to the workspace trash if nothing else links it.`))try{await ae(e.id),T(null)}catch{}},[ae]),_e=e=>{let t=e.target;if(!([`INPUT`,`TEXTAREA`,`SELECT`].includes(t.tagName)||t.isContentEditable)){if(e.key===`ArrowLeft`)ve(-1),e.preventDefault();else if(e.key===`ArrowRight`)ve(1),e.preventDefault();else if(e.key===`t`)q(new Date);else if(e.key===`n`)X(Kt(f),!1);else if(e.key===`Escape`)T(null),D(!1);else{let t=We.find(t=>t.key===e.key);t&&ue(t.id)}}},ve=e=>{let t=h;q(Ut(l,f,h,e)),g(t)};if(!t)return(0,Q.jsx)(`div`,{className:`flex h-full items-center justify-center p-6 text-center text-sm text-muted-foreground`,children:j(t)});let ye=e=>{let t=e.toLowerCase();c({hidden:H.has(t)?i.hidden.filter(e=>e!==t):[...i.hidden,t]})},be=(0,Q.jsxs)(`div`,{className:`space-y-1 text-xs`,children:[(0,Q.jsx)(`p`,{className:`px-1 text-[10px] uppercase tracking-wide text-muted-foreground`,children:`Calendars`}),V.map(e=>(0,Q.jsxs)(`label`,{className:`flex cursor-pointer items-center gap-2 rounded px-1 py-0.5 hover:bg-muted`,children:[(0,Q.jsx)(`input`,{type:`checkbox`,checked:!H.has(e.toLowerCase()),onChange:()=>ye(e),className:`h-3.5 w-3.5 accent-primary`,style:{accentColor:tt(e)}}),(0,Q.jsx)(`span`,{className:`h-2.5 w-2.5 shrink-0 rounded-sm`,style:{background:tt(e)}}),(0,Q.jsx)(`span`,{className:`truncate`,children:e})]},e)),oe&&(0,Q.jsxs)(`label`,{className:`flex cursor-pointer items-center gap-2 rounded px-1 py-0.5 hover:bg-muted`,children:[(0,Q.jsx)(`input`,{type:`checkbox`,checked:!H.has(``),onChange:()=>ye(``),className:`h-3.5 w-3.5 accent-primary`}),(0,Q.jsx)(`span`,{className:`h-2.5 w-2.5 shrink-0 rounded-sm`,style:{background:tt(``)}}),(0,Q.jsx)(`span`,{className:`truncate text-muted-foreground`,children:`Other events`})]}),(0,Q.jsxs)(`label`,{className:`flex cursor-pointer items-center gap-2 rounded px-1 py-0.5 hover:bg-muted`,children:[(0,Q.jsx)(`input`,{type:`checkbox`,checked:i.showTasks,onChange:e=>c({showTasks:e.target.checked}),className:`h-3.5 w-3.5 accent-primary`}),(0,Q.jsx)(`span`,{className:`h-2.5 w-2.5 shrink-0 rounded-sm`,style:{background:tt(je)}}),(0,Q.jsx)(`span`,{className:`truncate`,children:`Tasks (due dates)`})]})]}),xe=(()=>{switch(l){case`day`:return(0,Q.jsx)(gt,{days:Array.from({length:h},(e,t)=>W(U(f),t)),occurrences:G,selectedKey:K,pending:de,onSelect:fe,onCreate:X,onMove:pe,onPickDay:e=>q(e,`day`),onEntryMenu:he,onSlotMenu:ge,compact:N||h>3});case`week`:return(0,Q.jsx)(gt,{days:Array.from({length:7},(e,t)=>W(ce(f),t)),occurrences:G,selectedKey:K,pending:de,onSelect:fe,onCreate:X,onMove:pe,onPickDay:e=>q(e,`day`),onEntryMenu:he,onSlotMenu:ge,compact:M});case`month`:return(0,Q.jsx)(vt,{month:le(f),occurrences:G,selectedKey:K,pending:de,onSelect:fe,onCreate:X,onMove:pe,onPickDay:e=>q(e,`day`),onEntryMenu:he,onSlotMenu:ge,narrow:M});case`year`:return(0,Q.jsx)(yt,{year:f.getFullYear(),occurrences:G,onPickDay:e=>q(e,`day`),onPickRange:J,onPickMonth:e=>q(e,`month`),onSlotMenu:ge});case`schedule`:return(0,Q.jsx)(bt,{occurrences:G,selectedKey:K,onSelect:fe,onEntryMenu:he,loading:I,onEarlier:()=>C(e=>({...e,before:e.before+Bt})),onLater:()=>C(e=>({...e,after:e.after+Bt})),onPickDay:e=>q(e,`day`)})}})();return(0,Q.jsxs)(`div`,{ref:k,tabIndex:0,onKeyDown:_e,className:`relative flex h-full min-h-0 flex-col outline-none`,children:[(0,Q.jsxs)(`div`,{className:`flex shrink-0 flex-wrap items-center gap-1.5 border-b border-border px-2 py-1.5`,children:[(0,Q.jsx)(`button`,{type:`button`,onClick:()=>q(new Date),className:`rounded-md border border-border px-2 py-1 text-xs hover:bg-muted`,title:`Today (t)`,children:`Today`}),(0,Q.jsx)(`button`,{type:`button`,onClick:()=>ve(-1),className:`rounded-md p-1 text-muted-foreground hover:bg-muted hover:text-foreground`,"aria-label":`Previous`,title:`Previous (←)`,children:(0,Q.jsx)(o,{className:`h-4 w-4`})}),(0,Q.jsx)(`button`,{type:`button`,onClick:()=>ve(1),className:`rounded-md p-1 text-muted-foreground hover:bg-muted hover:text-foreground`,"aria-label":`Next`,title:`Next (→)`,children:(0,Q.jsx)(d,{className:`h-4 w-4`})}),(0,Q.jsx)(`span`,{className:`min-w-0 truncate text-sm font-semibold`,children:Wt(l,f,h,N)}),I&&(0,Q.jsx)(v,{className:`h-3.5 w-3.5 animate-spin text-muted-foreground`}),(0,Q.jsx)(`span`,{className:`flex-1`}),N?(0,Q.jsx)(`select`,{value:l,onChange:e=>ue(e.target.value),"aria-label":`View`,className:`h-7 rounded-md border border-input bg-transparent px-1.5 text-xs`,children:We.map(e=>(0,Q.jsx)(`option`,{value:e.id,children:e.label},e.id))}):(0,Q.jsx)(`div`,{className:`flex overflow-hidden rounded-md border border-border`,role:`tablist`,"aria-label":`View`,children:We.map(e=>(0,Q.jsx)(`button`,{type:`button`,role:`tab`,"aria-selected":l===e.id,onClick:()=>ue(e.id),title:`${e.label} (${e.key})`,className:x(`px-2 py-1 text-xs transition-colors`,l===e.id?`bg-foreground text-background`:`text-muted-foreground hover:bg-muted hover:text-foreground`),children:e.label},e.id))}),M&&(0,Q.jsx)(`button`,{type:`button`,onClick:()=>D(e=>!e),className:x(`rounded-md border p-1.5`,E?`border-foreground text-foreground`:`border-border text-muted-foreground hover:bg-muted hover:text-foreground`),"aria-label":`Calendars`,title:`Calendars`,children:(0,Q.jsx)(p,{className:`h-3.5 w-3.5`})}),(0,Q.jsxs)(`button`,{type:`button`,onClick:()=>X(Kt(f),!1),className:`flex items-center gap-1 rounded-md bg-primary px-2 py-1.5 text-xs text-primary-foreground`,title:`New event (n)`,children:[(0,Q.jsx)(u,{className:`h-3.5 w-3.5`}),!N&&`Event`]})]}),L&&(0,Q.jsx)(`p`,{className:`border-b border-border px-3 py-2 text-xs text-destructive`,children:L}),(0,Q.jsxs)(`div`,{className:`flex min-h-0 flex-1`,children:[!M&&(0,Q.jsxs)(`aside`,{className:`flex w-52 shrink-0 flex-col gap-4 overflow-y-auto border-r border-border p-3`,children:[(0,Q.jsx)(lt,{month:le(f),selection:Y,onPick:e=>q(e,l===`year`||l===`month`?`day`:l),onPickRange:J,onPrev:()=>m(e=>se(e,-1)),onNext:()=>m(e=>se(e,1))}),be]}),(0,Q.jsxs)(`div`,{className:`relative min-w-0 flex-1`,children:[xe,M&&E&&(0,Q.jsx)(`div`,{className:`absolute right-2 top-2 z-20 w-56 rounded-md border border-border bg-popover p-2 text-popover-foreground shadow-elevation-2`,children:be})]}),w&&!M&&(0,Q.jsx)(`aside`,{className:`w-80 shrink-0 border-l border-border bg-card`,children:(0,Q.jsx)(jt,{subject:w,target:t,workspaceName:R?.workspaceName??null,calendars:V,defaultCalendar:i.defaultCalendar,onClose:()=>T(null),onSaved:e=>{e&&c({defaultCalendar:e}),T(null),re()},onDelete:Z})})]}),w&&M&&(0,Q.jsx)(`div`,{className:`absolute inset-0 z-30 flex flex-col bg-card`,children:(0,Q.jsx)(jt,{subject:w,target:t,workspaceName:R?.workspaceName??null,calendars:V,defaultCalendar:i.defaultCalendar,onClose:()=>T(null),onSaved:e=>{e&&c({defaultCalendar:e}),T(null),re()},onDelete:Z})}),_&&(0,Q.jsx)(It,{menu:_,onClose:()=>y(null),onOpen:fe,onOpenDocument:R?e=>b(`/workspaces/${encodeURIComponent(R.workspaceName)}/documents/${e.doc.id}`):null,onToggleDone:e=>{me(e)},onDelete:e=>{Z(e.doc)},onCreate:(e,t)=>X(e,t),onPickDay:e=>q(e,`day`)}),!I&&!L&&!F.length&&l!==`schedule`&&(0,Q.jsxs)(`p`,{className:`pointer-events-none absolute bottom-2 left-1/2 -translate-x-1/2 rounded-full bg-muted/80 px-3 py-1 text-[11px] text-muted-foreground`,children:[(0,Q.jsx)(s,{className:`mr-1 inline h-3 w-3`}),`Nothing here yet — click or drag a slot to add an event.`]})]})}function Kt(e){let t=new Date,n=e&&!qt(e,t)?new Date(e.getFullYear(),e.getMonth(),e.getDate(),9,0):new Date(t);return(!e||qt(e,t))&&n.setMinutes(t.getMinutes()<30?30:60,0,0),n}function qt(e,t){return e.toDateString()===t.toDateString()}export{Gt as CalendarApplet};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{o as e}from"./rolldown-runtime-C0FnF6B9.js";import{l as t,u as n}from"./code-editor-BOIngd5F.js";import{L as r,Pt as i,Tt as a,W as o,di as s,pi as c}from"./ui-CDoK3F3U.js";import{t as l}from"./utils-2pl1SbIp.js";import{t as u}from"./button-SeUZ_Pvi.js";import{t as d}from"./label-BSTdjCWU.js";import{g as f,t as p}from"./LinkToCard-BQ1yoFDr.js";import{An as m,g as h,tt as g}from"./workspace-BJELPCNs.js";import{a as _,s as v,t as y}from"./useAddTarget-B3b6TyZr.js";import{n as b}from"./use-toolbox-Ck_cLGgf.js";import{n as x}from"./relation-events-CKio19hE.js";import{t as S}from"./useToastHelpers-CRrpIIdY.js";import{t as C}from"./DocumentIcon-9i1uCMQa.js";import{n as w}from"./LinkToSidePanel-eCy3nW4R.js";import{a as T,i as E,o as D,r as O,t as k}from"./UploadProgressList-Ci1akl_D.js";var A=e(n(),1),j=`references`;function M(e){return e?e.documents.map(e=>({predicate:j,direction:`out`,targetId:e.id,document:e})):[]}function N(e,t){let[n,r]=(0,A.useState)(()=>M(t)),i=e?.mode===`context`?e.contextId:null,[a,o]=(0,A.useState)(null);(0,A.useEffect)(()=>{if(!i)return;let e=!1;return _({mode:`context`,contextId:i}).then(t=>{e||o({contextId:i,workspaceName:t.workspaceName})}).catch(()=>{}),()=>{e=!0}},[i]);let s=e?.mode===`workspace`?e.workspaceName:i&&a?.contextId===i?a.workspaceName:t?.workspaceName??null,{predicates:c}=f(s);return{rows:n,predicates:c,workspaceName:s,add:(0,A.useCallback)(async(e,t,i)=>{let a=i.filter(r=>!n.some(n=>n.targetId===r&&n.predicate===e&&n.direction===t));if(a.length===0)return;let o=await Promise.all(a.map(e=>s?g(s,e).catch(()=>null):Promise.resolve(null)));r(n=>[...n,...a.map((n,r)=>({predicate:e,direction:t,targetId:n,document:o[r]??null}))])},[n,s]),update:(0,A.useCallback)((e,t)=>{r(n=>n.map((n,r)=>r===e?{...n,...t}:n))},[]),remove:(0,A.useCallback)(e=>{r(t=>t.filter((t,n)=>n!==e))},[]),write:(0,A.useCallback)(async e=>{if(n.length===0||e.length===0||!s)return 0;let t=new Map;for(let e of n){let n=`${e.direction}:${e.predicate}`,r=t.get(n)??{predicate:e.predicate,direction:e.direction,targets:[]};r.targets.push(e.targetId),t.set(n,r)}let r=0;for(let n of e)for(let e of t.values())try{await h(s,n,e.predicate,e.targets,e.direction)}catch(t){r+=1,console.error(`Failed to relate document`,n,e.predicate,t)}return r<e.length*t.size&&x(),r},[n,s]),hasRows:n.length>0}}var P=t();function F({f:e,idPrefix:t}){let[n,a]=(0,A.useState)(!1),[o,f]=(0,A.useState)(!1),h=!e.workspaceName;return(0,P.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,P.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,P.jsx)(d,{children:`Related documents`}),(0,P.jsxs)(u,{type:`button`,variant:`ghost`,size:`sm`,className:`h-7 px-2 text-xs`,disabled:h,onClick:()=>a(!0),title:h?`No workspace to relate within`:`Pick documents the new one relates to`,children:[(0,P.jsx)(i,{className:`mr-1 h-3 w-3`}),` Add`]})]}),e.rows.length===0?(0,P.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`None. Relations are written right after the document is created.`}):(0,P.jsx)(`ul`,{className:`space-y-1`,children:e.rows.map((n,i)=>{let a=n.document?m(n.document).title:`Document ${n.targetId}`,o=`${t}-relation-${i}`;return(0,P.jsxs)(`li`,{className:`flex items-center gap-1.5 rounded-md border border-input px-2 py-1.5 text-sm`,children:[(0,P.jsx)(`button`,{type:`button`,onClick:()=>e.update(i,{direction:n.direction===`out`?`in`:`out`}),className:`shrink-0 rounded p-0.5 text-muted-foreground hover:bg-accent hover:text-foreground`,title:n.direction===`out`?`The new document ${n.predicate} this one (click to flip)`:`This document ${n.predicate} the new one (click to flip)`,"aria-label":`Flip relation direction`,children:n.direction===`out`?(0,P.jsx)(s,{className:`h-3.5 w-3.5`}):(0,P.jsx)(c,{className:`h-3.5 w-3.5`})}),(0,P.jsx)(`label`,{htmlFor:o,className:`sr-only`,children:`Predicate`}),(0,P.jsx)(`select`,{id:o,value:n.predicate,onChange:t=>e.update(i,{predicate:t.target.value}),className:`w-[9.5rem] shrink-0 rounded-md border border-input bg-background px-1.5 py-1 font-mono text-[11px] focus:outline-none focus:ring-2 focus:ring-ring`,children:(e.predicates.includes(n.predicate)?e.predicates:[n.predicate,...e.predicates]).map(e=>(0,P.jsx)(`option`,{value:e,children:e},e))}),n.document?(0,P.jsx)(C,{document:n.document,size:3.5}):null,(0,P.jsx)(`span`,{className:l(`min-w-0 flex-1 truncate`,!n.document&&`italic text-muted-foreground`),title:a,children:a}),(0,P.jsx)(`button`,{type:`button`,onClick:()=>e.remove(i),className:`shrink-0 rounded p-0.5 text-muted-foreground hover:bg-destructive/10 hover:text-destructive`,title:`Remove`,"aria-label":`Remove relation`,children:(0,P.jsx)(r,{className:`h-3.5 w-3.5`})})]},`${n.direction}:${n.predicate}:${n.targetId}`)})}),n&&e.workspaceName&&(0,P.jsx)(w,{onClose:()=>{o||a(!1)},children:(0,P.jsx)(p,{sizeClassName:`h-full w-[380px] max-w-[90vw] max-md:w-full`,title:`Relate to…`,confirmLabel:`Add`,tabs:[`relations`],fixedWorkspaceName:e.workspaceName,documentCount:1,saving:o,relationPredicates:e.predicates,relationExcludeIds:new Set(e.rows.map(e=>e.targetId)),onClose:()=>a(!1),onConfirm:()=>{},onConfirmRelation:async({predicate:t,direction:n,targetIds:r})=>{f(!0);try{await e.add(t,n,r),a(!1)}finally{f(!1)}}})})]})}function I({capture:e=!1,target:t,initialFiles:n=[],onClose:r,onBusyChange:i}={}){let{closeAdd:s,state:c}=b(),d=v(),f=t===void 0?d:t,p=r??s,m=f?.mode===`workspace`&&f.treeName===`backends`,h=N(f,t===void 0?c.addRelateTo:null),{showSuccessToast:g,showErrorToast:x}=S(),C=(0,A.useRef)(null),[w,j]=(0,A.useState)(!1),M=O(n),{items:I,running:L}=M,R=(0,A.useRef)(!1),z=(0,A.useRef)(!1),[B,V]=(0,A.useState)(!1),[H,U]=(0,A.useState)(null);(0,A.useEffect)(()=>{if(f?.mode!==`context`)return;let e=!1;return _(f).then(t=>{e||U({contextId:f.contextId,workspaceName:t.workspaceName})}).catch(()=>{}),()=>{e=!0}},[f]);let W=f?.mode===`workspace`?f.workspaceName:f&&H?.contextId===f.contextId?H.workspaceName:null,G=D(W),K=e=>{e&&M.addFiles(Array.from(e))},q=e=>{e.preventDefault(),j(!1),K(e.dataTransfer.files)},J=I.filter(e=>e.status===`error`).length,Y=I.filter(e=>e.status===`done`).length,X=I.length-Y,Z=!!f&&!B&&X>0;return(0,P.jsxs)(`div`,{className:`flex flex-col gap-4 p-4`,children:[(0,P.jsxs)(`div`,{onDragOver:e=>{e.preventDefault(),j(!0)},onDragLeave:()=>j(!1),onDrop:q,onClick:()=>C.current?.click(),className:l(`flex cursor-pointer flex-col items-center justify-center gap-2 rounded-md border border-dashed px-4 py-8 text-center transition-colors`,w?`border-primary bg-primary/5`:`border-input hover:bg-muted/40`),children:[(0,P.jsx)(o,{className:`h-6 w-6 text-muted-foreground touch-target`}),(0,P.jsx)(`p`,{className:`text-sm`,children:e?`Take a photo or video`:`Drag & drop files here`}),(0,P.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:e?`click to open the camera`:`or click to browse`}),(0,P.jsx)(`input`,{ref:C,type:`file`,multiple:!0,accept:e?`image/*,video/*`:void 0,capture:e?`environment`:void 0,className:`hidden`,onChange:e=>{K(e.target.files),e.target.value=``}})]}),(0,P.jsx)(k,{items:I,running:L,onRemove:M.removeItem}),!m&&(0,P.jsx)(E,{fields:G,idPrefix:`file`,multiple:I.length>1}),(0,P.jsx)(F,{f:h,idPrefix:`file`}),(0,P.jsxs)(`p`,{className:`text-xs text-muted-foreground`,children:[y(f),m?`. Existing files are never overwritten.`:``]}),(0,P.jsxs)(`div`,{className:`flex justify-end gap-2`,children:[(0,P.jsx)(u,{variant:`outline`,size:`sm`,onClick:()=>{B?(z.current=!0,M.cancel()):p()},children:`Cancel`}),(0,P.jsx)(u,{size:`sm`,onClick:async()=>{if(!(!Z||!f||R.current)){R.current=!0,z.current=!1,V(!0),i?.(!0);try{let e=m?null:await G.geotag.capture();if(z.current)return;let t=await M.start(f,(t,n)=>T(t,n,{tags:G.tags,comment:G.comment,geo:e})),n=await h.write(t.docIds);if(t.failed===0){let e=t.resumed?` (${t.resumed} already uploaded)`:``,r=n?`; some relations failed`:``;g(`${t.done} file(s) uploaded${e}${r}`),p()}else x(`${t.failed} of ${t.total} file(s) failed — retry keeps what already made it`)}catch(e){x(e instanceof Error?e.message:`Failed to upload files`)}finally{R.current=!1,V(!1),i?.(!1)}}},disabled:!Z,children:B?`Uploading…`:J>0?(0,P.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,P.jsx)(a,{className:`h-3.5 w-3.5`}),`Retry failed (`,J,`)`]}):`Add files`})]})]})}export{F as n,N as r,I as t};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{o as e}from"./rolldown-runtime-C0FnF6B9.js";import{l as t,u as n}from"./code-editor-BOIngd5F.js";import{_t as r,yt as i}from"./react-BHzhHVTZ.js";import{Bn as a,L as o,Lt as s,Ur as ee,Vr as c,Wn as l,Zn as u,mt as d,qn as f,vn as p,wr as m,yt as h}from"./ui-CDoK3F3U.js";import{t as g}from"./utils-2pl1SbIp.js";import{t as _}from"./button-SeUZ_Pvi.js";import{An as v,Dt as y,G as b,K as x,Nt as te,Sn as S,Z as C,ht as w,mt as ne,rt as re}from"./workspace-BJELPCNs.js";import{t as T}from"./useEscapeClose-DR_xKT_k.js";import{t as ie}from"./useToastHelpers-CRrpIIdY.js";import{s as E}from"./layer-style-Byl5LNFR.js";import{i as D}from"./color-DFEH4BfK.js";import{t as ae}from"./DocumentIcon-9i1uCMQa.js";var O=e(n(),1),k=t();function A({className:e=`h-5 w-5`,...t}){return(0,k.jsxs)(`svg`,{className:`animate-spin ${e}`,xmlns:`http://www.w3.org/2000/svg`,fill:`none`,viewBox:`0 0 24 24`,...t,children:[(0,k.jsx)(`circle`,{className:`opacity-25`,cx:`12`,cy:`12`,r:`10`,stroke:`currentColor`,strokeWidth:`4`}),(0,k.jsx)(`path`,{className:`opacity-75`,fill:`currentColor`,d:`M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z`})]})}var j=e(i(),1);function M(e){let[t,n]=(0,O.useState)(null);(0,O.useEffect)(()=>{if(!e)return;let t=!1;return C(e).then(r=>{t||n({workspaceId:e,predicates:r,error:!1})},()=>{t||n({workspaceId:e,predicates:[],error:!0})}),()=>{t=!0}},[e]);let r=t?.workspaceId===e?t:null;return{predicates:r?.predicates??[],error:r?.error??!1,loading:!!e&&!r}}function N({x:e,y:t,onClose:n,className:r,children:i}){let a=(0,O.useRef)(null),[o,s]=(0,O.useState)({x:e,y:t});return T(n),(0,O.useLayoutEffect)(()=>{let n=a.current;if(!n)return;let{width:r,height:i}=n.getBoundingClientRect();s({x:Math.max(8,Math.min(e,window.innerWidth-r-8)),y:Math.max(8,Math.min(t,window.innerHeight-i-8))})},[e,t]),(0,j.createPortal)((0,k.jsxs)(k.Fragment,{children:[(0,k.jsx)(`div`,{className:`fixed inset-0 z-menu-scrim`,onClick:n,onContextMenu:e=>{e.preventDefault(),n()}}),(0,k.jsx)(`div`,{ref:a,style:{left:o.x,top:o.y},className:g(`fixed z-menu max-h-viewport-modal overflow-y-auto`,r,`bg-popover text-popover-foreground`),children:i})]}),document.body)}var P=typeof navigator<`u`&&/Mac|iPhone|iPad/.test(navigator.platform||navigator.userAgent),F={Delete:`Del`,Backspace:`⌫`,Enter:`↵`,ArrowUp:`↑`,ArrowDown:`↓`};function I(e){let t=e.split(`+`),n=t.pop()||``,r=F[n]||(n.length===1?n.toUpperCase():n);if(P){let e={Mod:`⌘`,Shift:`⇧`,Alt:`⌥`,Ctrl:`⌃`};return[...[`Ctrl`,`Alt`,`Shift`,`Mod`].filter(e=>t.includes(e)).map(t=>e[t]),r].join(``)}return[...t.map(e=>e===`Mod`?`Ctrl`:e),r].join(`+`)}function L(e,t){let n=t.split(`+`),r=n.pop()||``;return(P?e.metaKey:e.ctrlKey)!==n.includes(`Mod`)||e.shiftKey!==n.includes(`Shift`)||e.altKey!==n.includes(`Alt`)||P&&e.ctrlKey!==n.includes(`Ctrl`)?!1:r.length===1?e.key.toLowerCase()===r.toLowerCase():e.key===r}function R(e){if(e?.closest?.(`input, textarea, select, [contenteditable="true"], [role="dialog"], [role="menu"]`))return!0;let t=typeof window<`u`?window.getSelection():null;return!!t&&!t.isCollapsed&&t.toString().length>0}function z(e,t){if(e.defaultPrevented||e.nativeEvent.isComposing||R(e.target))return!1;let n=t.find(t=>t.shortcut&&!t.disabled&&L(e,t.shortcut));return n?(e.preventDefault(),e.stopPropagation(),n.run({shiftKey:e.shiftKey}),!0):!1}function B(e){return e.key===`ContextMenu`||e.key===`F10`&&e.shiftKey}function oe(){return typeof window<`u`&&window.matchMedia(`(max-width: 767px)`).matches}function V(e,t=`below`){let n=e.getBoundingClientRect();return t===`below`?{x:n.left,y:n.bottom+4}:{x:n.left+Math.min(24,n.width/2),y:n.top+Math.min(24,n.height/2)}}function H(e){let t=[];for(let n of e){let e=t[t.length-1];e&&(e[0].group??``)===(n.group??``)?e.push(n):t.push([n])}return t}function se(e,t,n){t(),setTimeout(()=>{e.run({shiftKey:n})},0)}function ce({anchor:e,items:t,onClose:n,label:r}){let i=(0,O.useRef)(null);return(0,O.useEffect)(()=>{let e=document.activeElement;return i.current?.querySelector(`[role="menuitem"]:not([aria-disabled="true"])`)?.focus(),()=>{e?.isConnected&&e.focus({preventScroll:!0})}},[]),(0,k.jsx)(N,{x:e.x,y:e.y,onClose:n,className:`min-w-[200px] rounded-lg border bg-popover text-popover-foreground py-1 shadow-elevation-3`,children:(0,k.jsx)(`div`,{ref:i,role:`menu`,"aria-label":r,onKeyDown:e=>{let t=Array.from(i.current?.querySelectorAll(`[role="menuitem"]:not([aria-disabled="true"])`)??[]);if(t.length===0)return;let r=t.indexOf(document.activeElement),a=e=>t[(e+t.length)%t.length]?.focus();switch(e.key){case`ArrowDown`:e.preventDefault(),a(r+1);return;case`ArrowUp`:e.preventDefault(),a(r<0?-1:r-1);return;case`Home`:e.preventDefault(),a(0);return;case`End`:e.preventDefault(),a(-1);return;case`Tab`:e.preventDefault(),n();return}if(e.key.length===1&&!e.ctrlKey&&!e.metaKey&&!e.altKey){let n=e.key.toLowerCase(),i=[...t.slice(r+1),...t.slice(0,r+1)].find(e=>e.textContent?.trim().toLowerCase().startsWith(n));i&&(e.preventDefault(),i.focus())}},onContextMenu:e=>e.preventDefault(),children:H(t).map((e,t)=>(0,k.jsxs)(O.Fragment,{children:[t>0&&(0,k.jsx)(`div`,{role:`separator`,className:`my-1 h-px bg-border`}),e[0].groupLabel&&(0,k.jsx)(`div`,{className:`px-3 py-1 text-[10px] font-medium uppercase tracking-wide text-muted-foreground`,children:e[0].groupLabel}),e.map(e=>{let t=e.icon;return(0,k.jsxs)(`button`,{type:`button`,role:`menuitem`,tabIndex:-1,"aria-disabled":e.disabled||void 0,title:e.hint,onClick:t=>{e.disabled||se(e,n,t.shiftKey)},className:g(`flex w-full items-center gap-2 px-3 py-1.5 text-left text-sm outline-none`,e.disabled?`cursor-default opacity-50`:e.destructive?`text-destructive hover:bg-destructive hover:text-destructive-foreground focus:bg-destructive focus:text-destructive-foreground`:`hover:bg-muted focus:bg-muted`),children:[t?(0,k.jsx)(t,{className:`h-3.5 w-3.5 shrink-0`}):(0,k.jsx)(`span`,{className:`w-3.5 shrink-0`}),(0,k.jsx)(`span`,{className:`flex-1 truncate`,children:e.label}),e.shortcut&&(0,k.jsx)(`kbd`,{className:`ml-4 shrink-0 font-sans text-[11px] text-muted-foreground`,children:I(e.shortcut)})]},e.id)})]},`${e[0].group??``}:${t}`))})})}function U({items:e,onClose:t,header:n}){T(t);let r=`flex w-full items-center gap-3 rounded-xl border bg-card px-4 py-3.5 text-base font-medium transition-transform active:scale-[.98]`;return(0,j.createPortal)((0,k.jsxs)(`div`,{role:`dialog`,"aria-modal":`true`,className:`fixed inset-0 z-fullscreen flex flex-col bg-popover text-popover-foreground animate-in slide-in-from-bottom-10 fade-in duration-normal`,onClick:t,onContextMenu:e=>e.preventDefault(),children:[(0,k.jsxs)(`div`,{className:`flex shrink-0 items-start gap-3 border-b p-4`,onClick:e=>e.stopPropagation(),children:[(0,k.jsx)(`div`,{className:`min-w-0 flex-1`,children:n}),(0,k.jsx)(`button`,{type:`button`,onClick:t,className:`rounded-sm p-2 hover:bg-muted`,title:`Close`,"aria-label":`Close`,children:(0,k.jsx)(o,{className:`h-5 w-5`})})]}),(0,k.jsx)(`div`,{className:`min-h-4 flex-1`}),(0,k.jsxs)(`div`,{className:`max-h-[75vh] shrink-0 space-y-2 overflow-y-auto px-4 pt-2`,style:{paddingBottom:`calc(var(--safe-bottom) + 1.25rem)`},onClick:e=>e.stopPropagation(),children:[H(e).map((e,n)=>(0,k.jsxs)(`div`,{className:g(`space-y-2`,n>0&&`pt-2`),children:[e[0].groupLabel&&(0,k.jsx)(`div`,{className:`px-1 text-[11px] font-medium uppercase tracking-wide text-muted-foreground`,children:e[0].groupLabel}),e.map(e=>{let n=e.icon;return(0,k.jsxs)(`button`,{type:`button`,disabled:e.disabled,onClick:n=>se(e,t,n.shiftKey),className:g(r,e.destructive&&`border-destructive/30 text-destructive`,e.disabled&&`opacity-50`),children:[n&&(0,k.jsx)(n,{className:g(`h-5 w-5 shrink-0`,!e.destructive&&`text-muted-foreground`)}),e.label]},e.id)})]},`${e[0].group??``}:${n}`)),(0,k.jsx)(`button`,{type:`button`,onClick:t,className:`${r} justify-center bg-muted`,children:`Cancel`})]})]}),window.document.body)}function le({anchor:e,items:t,onClose:n,label:r,header:i}){return t.length===0?null:oe()?(0,k.jsx)(U,{items:t,onClose:n,header:i??(r&&(0,k.jsx)(`div`,{className:`truncate text-base font-semibold`,children:r}))}):(0,k.jsx)(ce,{anchor:e,items:t,onClose:n,label:r})}function ue({items:e,onNavigate:t,disabled:n,className:r,label:i=`Tree path`}){let a=(0,O.useRef)(null),o=e[e.length-1]?.path;return(0,O.useEffect)(()=>{let e=a.current;e&&(e.scrollLeft=e.scrollWidth)},[o]),(0,k.jsx)(`nav`,{"aria-label":i,className:g(`min-w-0 flex-1`,r),children:(0,k.jsx)(`ol`,{ref:a,className:`flex min-w-0 items-center gap-1 overflow-x-auto py-0.5 text-sm`,children:e.map((r,i)=>{let a=i===e.length-1,o=g(`block max-w-56 truncate rounded px-1.5 py-1`,a?`font-medium text-foreground`:`text-muted-foreground`);return(0,k.jsxs)(`li`,{className:`flex shrink-0 items-center gap-1`,children:[i>0&&(0,k.jsx)(`span`,{"aria-hidden":`true`,className:`text-muted-foreground/60`,children:`/`}),t&&!a?(0,k.jsx)(`button`,{type:`button`,title:r.path===`/`?`${r.label} (root)`:r.path,disabled:n,onClick:()=>t(r.path),className:g(o,`hover:bg-accent hover:text-foreground hover:underline focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring disabled:opacity-50`),children:r.label}):(0,k.jsx)(`span`,{title:r.path===`/`?r.label:r.path,"aria-current":a?`location`:void 0,className:o,children:r.label})]},r.path)})})})}function W(e,t){let n=e.split(`/`).filter(Boolean);return[{label:t,path:`/`},...n.map((e,t)=>({label:e,path:`/${n.slice(0,t+1).join(`/`)}`}))]}var de={context:(0,k.jsx)(l,{className:`h-3.5 w-3.5`}),directory:(0,k.jsx)(f,{className:`h-3.5 w-3.5`}),backends:(0,k.jsx)(a,{className:`h-3.5 w-3.5`}),relations:(0,k.jsx)(d,{className:`h-3.5 w-3.5`})},fe={context:`Context tree`,directory:`Directory tree`,backends:`Backends tree`,relations:`Relations`};function pe(e,t){return e===`/`?`/${t}`:`${e}/${t}`}function me(e,t){let n=(0,O.useRef)(null),r=(0,O.useRef)(!1),i=()=>{n.current&&=(clearTimeout(n.current),null)},a=e=>t=>{if(r.current){r.current=!1;return}t.detail>1||e()};return t?{guardClick:a,handlers:{onContextMenu:n=>{n.preventDefault(),n.stopPropagation(),t({clientX:n.clientX,clientY:n.clientY,path:e})},onPointerDown:a=>{if(a.pointerType!==`touch`)return;let{clientX:o,clientY:s}=a;i(),n.current=setTimeout(()=>{r.current=!0,t({clientX:o,clientY:s,path:e})},500)},onPointerUp:i,onPointerLeave:i,onPointerMove:i}}:{handlers:{},guardClick:a}}function he(e,t,n){let r=pe(t,e.name);return r.toLowerCase().includes(n)||(e.label||``).toLowerCase().includes(n)?!0:e.children?.some(e=>he(e,r,n))??!1}var G=200;function ge({onConfirm:e,onCancel:t,busy:n}){let[r,i]=(0,O.useState)(``);return(0,k.jsxs)(`div`,{className:`flex min-h-11 items-center gap-2 rounded-(--card-radius) bg-card px-3 py-2.5 text-sm shadow-elevation-1`,children:[(0,k.jsx)(m,{className:`h-4 w-4 shrink-0 text-muted-foreground`}),(0,k.jsx)(`input`,{type:`text`,value:r,onChange:e=>i(e.target.value),onKeyDown:n=>{n.key===`Enter`&&r.trim()&&e(r.trim()),n.key===`Escape`&&t()},onBlur:()=>{n||t()},placeholder:`New folder name…`,autoFocus:!0,disabled:n,className:`w-full flex-1 bg-transparent text-sm outline-none placeholder:text-muted-foreground`}),n&&(0,k.jsx)(`span`,{className:`shrink-0 text-xs text-muted-foreground`,children:`Creating…`})]})}function _e({node:e,parentPath:t,query:n,selected:i,onToggle:a,onActivate:o,onRowMenu:s,createParent:l,onCreateConfirm:u,onCreateCancel:d,creating:f}){let p=pe(t,e.name),m=!!e.children?.length,[h,_]=(0,O.useState)(!1),{handlers:v,guardClick:y}=me(p,s);if(n&&!he(e,t,n))return null;let b=l===p,x=h||n.length>0||b,te=i.has(p),S=e.type===`canvas`,C=E(e);return(0,k.jsxs)(`div`,{children:[(0,k.jsxs)(`div`,{className:g(`group relative flex min-h-11 items-center gap-2 rounded-md px-3 py-2.5 cursor-pointer transition-all select-none text-sm shadow-elevation-1 hover:shadow`,`before:absolute before:left-0 before:top-0 before:bottom-0 before:w-1.5 before:transition-colors`,te?`bg-primary/[0.08] hover:bg-primary/[0.12] before:bg-primary`:`bg-card hover:bg-primary/[0.04] before:bg-transparent`),onClick:y(()=>a(p)),onDoubleClick:e=>{e.ctrlKey||e.metaKey||e.shiftKey||e.altKey||e.target.closest(`button,input,textarea,select,a,[contenteditable="true"]`)||(e.preventDefault(),e.stopPropagation(),m?_(e=>!e):o?.(p))},title:p,...v,children:[(0,k.jsx)(`button`,{type:`button`,"aria-label":`${x?`Collapse`:`Expand`} ${e.label||e.name}`,"aria-expanded":m?x:void 0,disabled:!m,className:g(`shrink-0 text-muted-foreground hover:text-foreground`,!m&&`invisible`),onClick:e=>{e.stopPropagation(),e.detail<=1&&_(e=>!e)},children:x?(0,k.jsx)(ee,{className:`w-4 h-4`}):(0,k.jsx)(c,{className:`w-4 h-4`})}),(0,k.jsx)(r,{icon:C.icon||(S?`ph:squares-four-fill`:`ph:folder-fill`),width:16,height:16,color:D(C.color),className:g(`shrink-0`,!D(C.color)&&(S?`text-primary`:`text-muted-foreground`))}),(0,k.jsx)(`span`,{className:`flex-1 truncate font-medium`,title:e.description||void 0,children:e.label||e.name})]}),x&&m||b?(0,k.jsxs)(`div`,{className:`ml-[22px] mt-1.5 space-y-1.5`,children:[b&&u&&d&&(0,k.jsx)(ge,{busy:f,onConfirm:e=>{_(!0),u(p,e)},onCancel:d}),x&&e.children?.map(e=>(0,k.jsx)(_e,{node:e,parentPath:p,query:n,selected:i,onToggle:a,onActivate:o,onRowMenu:s,createParent:l,onCreateConfirm:u,onCreateCancel:d,creating:f},e.id||e.name))]}):null]})}function ve({workspaces:e,loading:t,onPick:n}){return t&&e.length===0?(0,k.jsx)(`div`,{className:`px-2 py-3 text-xs text-muted-foreground`,children:`Loading…`}):e.length===0?(0,k.jsx)(`div`,{className:`px-2 py-3 text-xs text-muted-foreground`,children:`No workspaces found`}):(0,k.jsx)(`div`,{className:`space-y-1.5`,children:e.map(e=>{let t=D(e.color);return(0,k.jsxs)(`div`,{onClick:()=>n(e.name),className:`group relative flex cursor-pointer items-center gap-2 rounded-(--card-radius) bg-card px-3 py-2.5 shadow-elevation-1 transition-all hover:bg-accent/50 hover:shadow`,style:{borderRight:`6px solid ${t||`transparent`}`},children:[(0,k.jsx)(r,{icon:e.icon||`ph:stack-fill`,width:18,height:18,color:t,className:g(`shrink-0`,!t&&`text-muted-foreground`)}),(0,k.jsx)(`span`,{className:`flex-1 truncate text-sm font-medium`,children:e.label||e.name}),(0,k.jsx)(c,{className:`h-4 w-4 shrink-0 text-muted-foreground`})]},e.id||e.name)})})}function ye({workspaceName:e,treeTab:t,onTreeTabChange:n,selectedDocIds:r,onToggleDoc:i,onNavigate:a,excludeDocumentIds:s}){let[l,u]=(0,O.useState)(`folder`),[d,f]=(0,O.useState)(``),p=d.trim().toLowerCase(),[m,_]=(0,O.useState)(`/`),[y,te]=(0,O.useState)(null),[C,w]=(0,O.useState)(!1),[ne,T]=(0,O.useState)([]),[ie,E]=(0,O.useState)(!1),[D,A]=(0,O.useState)(``),[j,M]=(0,O.useState)(``),[N,P]=(0,O.useState)(t),F=n?t:N,I=e=>{_(`/`),u(`folder`),A(``),M(``),a?.(`/`),n?n(e):P(e)},[L,R]=(0,O.useState)(F);F!==L&&(R(F),_(`/`),u(`folder`)),(0,O.useEffect)(()=>{let e=setTimeout(()=>M(D.trim()),300);return()=>clearTimeout(e)},[D]),(0,O.useEffect)(()=>{let t=!1;async function n(){w(!0);try{let n=await b(e,F);t||te(n)}catch{t||te(null)}finally{t||w(!1)}}return n(),()=>{t=!0}},[e,F]),(0,O.useEffect)(()=>{if(l!==`documents`)return;let t=!1,n=F===`directory`?`directory`:S,r=F===`context`?`context`:`directory`;async function i(){E(!0);try{let i=j?await re(e,m,[],{treeName:n,treeType:r,q:j,limit:G}):await x(e,m,n,{limit:G});t||T(i.payload||[])}catch{t||T([])}finally{t||E(!1)}}return i(),()=>{t=!0}},[e,F,m,l,j]);let z=e=>{_(e),a?.(e)},B=s?.size?ne.filter(e=>!s.has(e.id)):ne;return l===`folder`?(0,k.jsxs)(`div`,{className:`flex min-h-0 flex-1 flex-col`,children:[(0,k.jsxs)(`div`,{className:`shrink-0 space-y-2 border-b bg-muted/30 px-3 py-2`,children:[!n&&(0,k.jsx)(`div`,{className:`flex items-center gap-1 rounded-md border border-input p-0.5`,children:[`context`,`directory`].map(e=>(0,k.jsxs)(`button`,{type:`button`,onClick:()=>I(e),className:g(`flex flex-1 items-center justify-center gap-1.5 rounded px-2 py-1 text-xs transition-colors`,F===e?`bg-primary text-primary-foreground`:`text-muted-foreground hover:bg-muted hover:text-foreground`),title:`Browse the ${fe[e].toLowerCase()}`,children:[de[e],(0,k.jsx)(`span`,{className:`font-mono`,children:e===`directory`?`dir://`:`ctx://`})]},e))}),(0,k.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,k.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:`Step 1 of 2 · Pick a folder`}),(0,k.jsxs)(`button`,{type:`button`,onClick:()=>u(`documents`),className:`inline-flex items-center gap-1 rounded-md bg-primary px-2.5 py-1 text-xs font-medium text-primary-foreground transition-opacity hover:opacity-90`,children:[`Next `,(0,k.jsx)(c,{className:`h-3.5 w-3.5`})]})]}),(0,k.jsx)(ue,{items:W(m,e),onNavigate:z,label:`Folder path`}),(0,k.jsxs)(`div`,{className:`relative`,children:[(0,k.jsx)(h,{className:`pointer-events-none absolute left-2.5 top-1/2 h-3.5 w-3.5 -translate-y-1/2 text-muted-foreground`}),(0,k.jsx)(`input`,{type:`text`,placeholder:`Filter folders…`,value:d,onChange:e=>f(e.target.value),className:`w-full rounded-md border border-input bg-background py-1.5 pl-8 pr-3 text-xs placeholder:text-muted-foreground focus:outline-none focus:ring-2 focus:ring-ring`})]})]}),(0,k.jsx)(`div`,{className:`min-h-0 flex-1 space-y-1.5 overflow-y-auto p-3`,children:C?(0,k.jsx)(`div`,{className:`px-2 py-3 text-xs text-muted-foreground`,children:`Loading…`}):(0,k.jsxs)(k.Fragment,{children:[(0,k.jsxs)(`div`,{className:g(`group relative flex min-h-11 items-center gap-2 rounded-md px-3 py-2.5 cursor-pointer transition-all select-none text-sm shadow-elevation-1 hover:shadow`,`before:absolute before:left-0 before:top-0 before:bottom-0 before:w-1.5 before:transition-colors`,m===`/`?`bg-primary/[0.08] hover:bg-primary/[0.12] before:bg-primary`:`bg-card hover:bg-primary/[0.04] before:bg-transparent`),onClick:()=>z(`/`),onDoubleClick:()=>{z(`/`),u(`documents`)},title:`/`,children:[(0,k.jsx)(ee,{className:`w-4 h-4 shrink-0 text-muted-foreground`}),(0,k.jsx)(`span`,{className:`flex-1 truncate font-medium`,children:`/`})]}),(0,k.jsx)(`div`,{className:`ml-[22px] space-y-1.5`,children:y?.children?.length?y.children.map(e=>(0,k.jsx)(_e,{node:e,parentPath:`/`,query:p,selected:new Set([m]),onToggle:z,onActivate:e=>{z(e),u(`documents`)}},e.id||e.name)):(0,k.jsx)(`p`,{className:`px-2 py-1.5 text-xs text-muted-foreground`,children:`Empty tree`})})]})})]}):(0,k.jsxs)(`div`,{className:`flex min-h-0 flex-1 flex-col`,children:[(0,k.jsxs)(`div`,{className:`shrink-0 space-y-2 border-b bg-muted/30 px-3 py-2`,children:[(0,k.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,k.jsxs)(`button`,{type:`button`,onClick:()=>u(`folder`),className:`inline-flex min-w-0 items-center gap-1 rounded-md px-1.5 py-1 text-xs text-muted-foreground transition-colors hover:bg-muted hover:text-foreground`,title:`Back to folders`,children:[(0,k.jsx)(c,{className:`h-3.5 w-3.5 shrink-0 rotate-180`}),(0,k.jsx)(`span`,{children:`Folders`})]}),(0,k.jsx)(`span`,{className:`ml-auto shrink-0 text-xs text-muted-foreground`,children:`Step 2 of 2 · Pick a document`})]}),(0,k.jsxs)(`div`,{className:`flex min-w-0 items-center gap-2`,children:[(0,k.jsxs)(`span`,{className:`shrink-0 font-mono text-xs text-muted-foreground`,children:[`[`,F,`]`]}),(0,k.jsx)(ue,{items:W(m,e),onNavigate:z,label:`Document folder path`})]}),(0,k.jsxs)(`div`,{className:`relative`,children:[(0,k.jsx)(h,{className:`pointer-events-none absolute left-2.5 top-1/2 h-3.5 w-3.5 -translate-y-1/2 text-muted-foreground`}),(0,k.jsx)(`input`,{type:`text`,placeholder:`Search documents in this folder…`,value:D,onChange:e=>A(e.target.value),className:`w-full rounded-md border border-input bg-background py-1.5 pl-8 pr-7 text-xs placeholder:text-muted-foreground focus:outline-none focus:ring-2 focus:ring-ring`}),D&&(0,k.jsx)(`button`,{type:`button`,onClick:()=>A(``),className:`absolute right-2 top-1/2 -translate-y-1/2 text-muted-foreground hover:text-foreground`,"aria-label":`Clear document search`,children:(0,k.jsx)(o,{className:`h-3.5 w-3.5`})})]})]}),(0,k.jsx)(`div`,{className:`min-h-0 flex-1 space-y-1 overflow-y-auto p-3`,children:ie?(0,k.jsx)(`div`,{className:`px-2 py-3 text-xs text-muted-foreground`,children:`Loading documents…`}):B.length===0?(0,k.jsx)(`div`,{className:`px-2 py-3 text-xs text-muted-foreground`,children:j?`No documents match “${j}” here.`:`No documents in this folder.`}):B.map(e=>{let t=v(e),n=r.has(e.id);return(0,k.jsxs)(`div`,{onClick:()=>i(e.id),className:g(`flex min-h-9 items-center gap-2 rounded-md px-3 py-1.5 cursor-pointer transition-all select-none text-sm`,n?`bg-primary/[0.08] hover:bg-primary/[0.12]`:`hover:bg-primary/[0.04]`),children:[(0,k.jsx)(`input`,{type:`checkbox`,checked:n,onChange:()=>i(e.id),className:`shrink-0`,onClick:e=>e.stopPropagation()}),(0,k.jsx)(ae,{document:e,size:3.5}),(0,k.jsx)(`span`,{className:`flex-1 truncate`,children:t.title})]},e.id)})})]})}function be({onClose:e,onConfirm:t,documentCount:n,fixedWorkspaceName:r,excludeWorkspace:i,multiple:a=!0,saving:l=!1,savingContent:d,sizeClassName:f,tabs:m=[`context`,`directory`],initialTab:v,title:x,confirmLabel:C,backendFolderCreation:re,onConfirmRelation:E,relationWorkspaceName:D,relationPredicates:ae,relationExcludeIds:j}){let[N,P]=(0,O.useState)(r?`tree`:`workspace`),[F,I]=(0,O.useState)([]),[L,R]=(0,O.useState)(!r),[z,B]=(0,O.useState)(r??null),oe=v&&m.includes(v)?v:m.includes(`context`)||m.includes(`directory`)?`pins`:m[0]??`context`,[V,H]=(0,O.useState)(oe),se=M(m.includes(`relations`)&&!ae?D??z:null),U=ae??se.predicates,[le,ue]=(0,O.useState)(``),W=U.includes(le)?le:U[0]??``,[pe,he]=(0,O.useState)(`out`),[G,be]=(0,O.useState)(new Set),[xe,Se]=(0,O.useState)(null),[K,Ce]=(0,O.useState)(`context`),[we,Te]=(0,O.useState)(!1),Ee=V===`pins`?K:V;(0,O.useEffect)(()=>{if(!z)return;let e=!1;return y(z).then(t=>{e||Se(t)}).catch(()=>{e||Te(!0)}),()=>{e=!0}},[z]);let q=V===`relations`,[De,Oe]=(0,O.useState)(null),[ke,Ae]=(0,O.useState)(!1),[J,Y]=(0,O.useState)(new Set),[je,Me]=(0,O.useState)(``),Ne=je.trim().toLowerCase(),{showErrorToast:Pe}=ie(),[X,Fe]=(0,O.useState)(null),[Ie,Z]=(0,O.useState)(null),[Q,Le]=(0,O.useState)(!1);T(e,!l&&!Q);let Re=me(`/`,e=>Fe(e)),ze=e=>!l&&(V===`backends`?re?.canCreate(e)===!0:V!==`pins`&&V!==`relations`),Be=async(e,t)=>{let n=t.trim().replace(/^\/+|\/+$/g,``);if(!(!n||!z||Q||!ze(e))){Le(!0);try{let t=`${e===`/`?``:e}/${n}`,r=V===`context`?S:V;V===`backends`?await re.create(e,n):await ne(z,t,!0,r),w(z,r),window.dispatchEvent(new CustomEvent(`workspace:tree:refresh`,{detail:{workspaceName:z,treeName:r,cacheInvalidated:!0}}));let i=await b(z,V);Oe(i),Y(e=>a?new Set([...e,t]):new Set([t])),Me(``),Z(null)}catch(e){Pe(e instanceof Error?e.message:`Failed to create folder`)}finally{Le(!1)}}},[Ve,He]=(0,O.useState)(r);r!==Ve&&(He(r),r||R(!0)),(0,O.useEffect)(()=>{r||te().then(e=>I(e.filter(e=>e.id!==i&&e.name!==i))).catch(()=>I([])).finally(()=>R(!1))},[r,i]),(0,O.useEffect)(()=>{if(!z||V===`relations`||V===`pins`)return;let e=!1,t=0;async function n(n=!1){let r=++t;n||Ae(!0);try{let n=await b(z,V);!e&&r===t&&Oe(n)}catch{!e&&r===t&&!n&&Oe(null)}finally{!e&&r===t&&Ae(!1)}}let r=e=>{let t=e.detail;t?.workspaceName&&t.workspaceName!==z||t?.treeName&&t.treeName!==V||(t?.cacheInvalidated||w(z,V),n(!0))};return window.addEventListener(`workspace:tree:refresh`,r),n(),()=>{e=!0,window.removeEventListener(`workspace:tree:refresh`,r)}},[z,V]);let Ue=e=>{e!==z&&(Se(null),Te(!1)),H(oe),B(e),Y(new Set),be(new Set),P(`tree`)},We=e=>{be(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},Ge=e=>{if(!a){Y(new Set([e]));return}Y(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},Ke=q?!!W&&G.size>0&&!!E:J.size>0,qe=async()=>{if(!(!z||l||!Ke)){if(q){await E?.({predicate:W,direction:pe,targetIds:Array.from(G)},{workspaceName:D??z});return}await t(Array.from(J),{workspaceName:z,treeName:Ee===`context`?S:Ee,treeType:Ee===`context`?`context`:`directory`})}},$=n??1;return l&&d?(0,k.jsx)(`div`,{className:g(`flex flex-col overflow-hidden rounded-(--panel-radius) border bg-card shadow-elevation-4`,f||`h-viewport-card max-h-full w-[min(380px,90vw)] max-md:h-full max-md:w-full max-md:shadow-elevation-5`),children:d}):(0,k.jsxs)(`div`,{className:g(`flex flex-col overflow-hidden rounded-(--panel-radius) border bg-card shadow-elevation-4`,f||`h-viewport-card max-h-full w-[min(380px,90vw)] max-md:h-full max-md:w-full max-md:shadow-elevation-5`),children:[(0,k.jsxs)(`div`,{className:`flex h-12 shrink-0 items-center justify-between border-b px-4`,children:[(0,k.jsxs)(`span`,{className:`flex items-center gap-2 text-sm font-medium`,children:[(0,k.jsx)(p,{className:`h-4 w-4`}),x??(N===`workspace`?`Link to…`:q?`Relate ${$} document${$===1?``:`s`} to…`:`Link ${$} document${$===1?``:`s`} to…`)]}),(0,k.jsx)(`button`,{type:`button`,onClick:e,disabled:l||Q,className:`text-muted-foreground transition-colors hover:text-foreground disabled:opacity-40`,"aria-label":`Close`,children:(0,k.jsx)(o,{className:`h-4 w-4`})})]}),(0,k.jsx)(`div`,{className:`flex-1 overflow-hidden`,children:(0,k.jsxs)(`div`,{className:`grid h-full w-[200%] grid-cols-2 transition-transform duration-normal`,style:{transform:N===`workspace`?`translateX(0)`:`translateX(-50%)`},children:[(0,k.jsx)(`div`,{className:`flex min-w-0 flex-col overflow-y-auto p-2`,children:(0,k.jsx)(ve,{workspaces:F,loading:L,onPick:Ue})}),(0,k.jsxs)(`div`,{className:`flex min-w-0 flex-col overflow-hidden`,children:[(0,k.jsxs)(`div`,{className:`flex shrink-0 items-center gap-1 overflow-x-auto border-b px-2 pt-2`,children:[!r&&(0,k.jsx)(`button`,{type:`button`,disabled:Q,onClick:()=>P(`workspace`),className:`mr-1 rounded p-1.5 text-muted-foreground hover:bg-muted hover:text-foreground touch-target`,"aria-label":`Back to workspaces`,children:(0,k.jsx)(c,{className:`h-4 w-4 rotate-180`})}),(m.includes(`context`)||m.includes(`directory`))&&(0,k.jsxs)(`button`,{type:`button`,disabled:Q,onClick:()=>{H(`pins`),Y(new Set),Z(null)},className:g(`flex shrink-0 items-center gap-1.5 border-b-2 px-3 py-2 text-xs`,V===`pins`?`border-primary`:`border-transparent text-muted-foreground`),children:[(0,k.jsx)(s,{className:`h-3.5 w-3.5`}),`Pins`]}),m.map(e=>(0,k.jsxs)(`button`,{type:`button`,disabled:Q,onClick:()=>{H(e),Y(new Set),Z(null)},className:g(`flex shrink-0 items-center gap-1.5 rounded-t-md border-b-2 px-3 py-2 text-xs font-medium transition-colors`,V===e?`border-primary text-foreground`:`border-transparent text-muted-foreground hover:text-foreground`),children:[de[e],fe[e]]},e))]}),!q&&(0,k.jsx)(`div`,{className:`shrink-0 border-b p-2`,children:(0,k.jsxs)(`div`,{className:`relative`,children:[(0,k.jsx)(h,{className:`pointer-events-none absolute left-2.5 top-1/2 h-4 w-4 -translate-y-1/2 text-muted-foreground`}),(0,k.jsx)(`input`,{type:`text`,placeholder:`Search paths…`,value:je,onChange:e=>Me(e.target.value),className:`w-full rounded-md border border-input bg-background py-2 pl-9 pr-3 text-sm placeholder:text-muted-foreground focus:outline-none focus:ring-2 focus:ring-ring`})]})}),q&&(0,k.jsxs)(`div`,{className:`shrink-0 space-y-2 border-b bg-primary/[0.04] px-3 py-2`,children:[(0,k.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,k.jsx)(`label`,{htmlFor:`relation-predicate`,className:`shrink-0 text-xs text-muted-foreground`,children:`Predicate`}),(0,k.jsx)(`select`,{id:`relation-predicate`,value:W,onChange:e=>ue(e.target.value),className:`min-w-0 flex-1 rounded-md border border-input bg-background px-2 py-1.5 text-xs focus:outline-none focus:ring-2 focus:ring-ring`,children:U.map(e=>(0,k.jsx)(`option`,{value:e,children:e},e))})]}),(0,k.jsx)(`div`,{className:`flex items-center gap-1`,children:[{dir:`out`,label:`This → picked`,hint:`the ${$===1?`document`:`documents`} you started from ${W} the picked one(s)`},{dir:`in`,label:`Picked → this`,hint:`the picked document(s) ${W} the ${$===1?`one`:`ones`} you started from`}].map(({dir:e,label:t,hint:n})=>(0,k.jsx)(`button`,{type:`button`,title:n,onClick:()=>he(e),className:g(`flex-1 rounded-md border px-2 py-1.5 text-xs transition-colors`,pe===e?`border-primary bg-primary text-primary-foreground`:`border-input hover:bg-accent`),children:t},e))})]}),!q&&a&&(0,k.jsxs)(`div`,{className:`flex h-10 shrink-0 items-center gap-1.5 overflow-x-auto border-b bg-primary/[0.04] px-3`,children:[!J.size&&(0,k.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:`Selected folders appear here`}),Array.from(J).map(e=>(0,k.jsxs)(`span`,{className:`inline-flex max-w-full shrink-0 items-center gap-1 rounded-full bg-primary px-2 py-0.5 text-xs text-primary-foreground`,children:[(0,k.jsx)(`span`,{className:`truncate`,title:e,children:e}),(0,k.jsx)(`button`,{type:`button`,onClick:()=>Ge(e),className:`shrink-0 rounded-full hover:bg-primary-foreground/20`,"aria-label":`Remove ${e}`,children:(0,k.jsx)(o,{className:`h-3 w-3`})})]},e))]}),q&&(D??z)&&(0,k.jsx)(ye,{workspaceName:D??z,treeTab:`context`,selectedDocIds:G,onToggleDoc:We,excludeDocumentIds:j}),V===`pins`&&(0,k.jsxs)(`div`,{className:`min-h-0 flex-1 overflow-y-auto p-3 space-y-2`,children:[!xe&&!we&&(0,k.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`Loading pins…`}),we&&(0,k.jsx)(`p`,{className:`text-xs text-destructive`,children:`Could not load pins. You can still browse the trees.`}),!we&&xe?.length===0&&(0,k.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`No pinned paths yet. Choose a path from a tree.`}),xe?.filter(e=>e.resolvable!==!1&&m.includes(e.tree===`context`?`context`:e.tree)&&`${e.label??e.name??``} ${e.path}`.toLowerCase().includes(Ne)).map(e=>{let t=e.tree===`context`?`context`:e.tree;return(0,k.jsxs)(`button`,{type:`button`,"aria-pressed":K===t&&J.has(e.path),className:g(`w-full rounded-md border p-3 text-left text-sm hover:bg-muted`,K===t&&J.has(e.path)&&`border-primary bg-primary/10`),onClick:()=>{K===t?Ge(e.path):(Ce(t),Y(new Set([e.path])))},children:[(0,k.jsxs)(`span`,{className:`flex items-center gap-2`,children:[(0,k.jsx)(s,{className:`h-3.5 w-3.5`}),e.label||e.name||e.path]}),(0,k.jsxs)(`span`,{className:`block truncate text-xs text-muted-foreground`,children:[t,` · `,e.path]})]},e.id)})]}),(0,k.jsx)(`div`,{className:g(`min-h-0 flex-1 space-y-1.5 overflow-y-auto p-3`,(q||V===`pins`)&&`hidden`),children:ke?(0,k.jsx)(`div`,{className:`px-2 py-3 text-xs text-muted-foreground`,children:`Loading…`}):(0,k.jsxs)(k.Fragment,{children:[(0,k.jsxs)(`div`,{className:g(`group relative flex min-h-11 items-center gap-2 rounded-md px-3 py-2.5 cursor-pointer transition-all select-none text-sm shadow-elevation-1 hover:shadow`,`before:absolute before:left-0 before:top-0 before:bottom-0 before:w-1.5 before:transition-colors`,J.has(`/`)?`bg-primary/[0.08] hover:bg-primary/[0.12] before:bg-primary`:`bg-card hover:bg-primary/[0.04] before:bg-transparent`),onClick:Re.guardClick(()=>Ge(`/`)),title:`/`,...ze(`/`)?Re.handlers:{},children:[(0,k.jsx)(ee,{className:`w-4 h-4 shrink-0 text-muted-foreground`}),(0,k.jsx)(`span`,{className:`flex-1 truncate font-medium`,children:`/`})]}),(0,k.jsxs)(`div`,{className:`ml-[22px] space-y-1.5`,children:[Ie===`/`&&(0,k.jsx)(ge,{busy:Q,onConfirm:e=>Be(`/`,e),onCancel:()=>Z(null)}),De?.children?.length?De.children.map(e=>(0,k.jsx)(_e,{node:e,parentPath:`/`,query:Ne,selected:J,onToggle:Ge,onRowMenu:e=>{ze(e.path)&&Fe(e)},createParent:Ie,onCreateConfirm:Be,onCreateCancel:()=>Z(null),creating:Q},e.id||e.name)):Ie===`/`?null:(0,k.jsx)(`p`,{className:`px-2 py-1.5 text-xs text-muted-foreground`,children:`Empty tree`})]})]})})]})]})}),N===`tree`&&(0,k.jsxs)(`div`,{className:`flex shrink-0 items-center justify-between border-t px-4 py-3`,children:[(0,k.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:q?`${G.size} document${G.size===1?``:`s`} selected`:`${J.size} path${J.size===1?``:`s`} selected`}),(0,k.jsx)(_,{size:`sm`,onClick:qe,disabled:!Ke||l||Q,children:l?(0,k.jsxs)(k.Fragment,{children:[(0,k.jsx)(A,{className:`mr-1.5 h-3.5 w-3.5`}),q?`Relating…`:`Linking…`]}):(0,k.jsxs)(k.Fragment,{children:[(0,k.jsx)(p,{className:`mr-1 h-3.5 w-3.5`}),q?`Relate`:C??`Link`]})})]}),X&&(0,k.jsx)(ce,{anchor:{x:X.clientX,y:X.clientY},onClose:()=>Fe(null),items:[{id:`new-folder`,label:`New folder in ${X.path}`,icon:u,run:()=>Z(X.path)}]})]})}export{A as _,fe as a,le as c,I as d,B as f,M as g,N as h,de as i,V as l,L as m,ye as n,W as o,R as p,ve as r,ue as s,be as t,z as u};
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/pdf-Ciz5_WNq.js","assets/preload-helper-Czpn1I53.js","assets/TextDocumentEditor-CU5ersd_.js","assets/rolldown-runtime-C0FnF6B9.js","assets/code-editor-BOIngd5F.js","assets/ui-CDoK3F3U.js","assets/react-BHzhHVTZ.js","assets/button-SeUZ_Pvi.js","assets/utils-BxVxyehK.js","assets/utils-2pl1SbIp.js","assets/workspace-BJELPCNs.js","assets/input-BOtCd4HP.js","assets/api-CA6WiiYM.js","assets/alert-dialog-CFeuDt0T.js","assets/text-documents-BaXhu3ra.js","assets/public-share-D5yz-Pmo.js","assets/blobs-WiXP9QRi.js","assets/useToastHelpers-CRrpIIdY.js","assets/use-toast-BlLDqSUO.js","assets/note-save-status-DPz4VzL6.js","assets/useEditNoteFields-DXLTFEqL.js","assets/tags-YamdPoBK.js","assets/DocumentBodyEditor-CVO5KPCs.js","assets/lazy-editor-BUFAkTGl.js","assets/EditorOverlay-D5t3xg4w.js","assets/LocationTab-DAtqAQ3l.js","assets/map-BxCwdK0d.js","assets/map-BcsP_QXj.css"])))=>i.map(i=>d[i]);
|
|
2
|
-
import{o as e}from"./rolldown-runtime-C0FnF6B9.js";import{l as t,u as n}from"./code-editor-BOIngd5F.js";import{_t as r,yt as i}from"./react-BHzhHVTZ.js";import{t as a}from"./preload-helper-Czpn1I53.js";import{$r as o,Bn as s,Bt as c,Dr as l,Dt as u,Et as d,Gn as f,Ht as p,J as m,L as h,Lt as g,Mn as _,Or as v,Pn as y,Pt as b,Tr as x,Un as S,Wr as C,X as w,Xr as T,Yr as E,Zr as D,_n as O,br as k,cn as A,ct as j,di as M,en as N,fr as P,jt as F,kn as ee,lr as I,mr as L,mt as te,nr as ne,nt as R,on as z,or as B,pi as V,pn as H,qn as re,rr as ie,sn as ae,vr as U,yt as W,zt as oe}from"./ui-CDoK3F3U.js";import{t as G}from"./utils-2pl1SbIp.js";import{t as K}from"./button-SeUZ_Pvi.js";import{t as se}from"./input-BOtCd4HP.js";import{t as q}from"./label-BSTdjCWU.js";import{l as J}from"./api-CA6WiiYM.js";import{_ as ce,g as le,o as ue,t as de}from"./LinkToCard-BQ1yoFDr.js";import{An as fe,Bn as pe,D as me,Gn as he,Hn as ge,J as _e,M as ve,Mn as Y,N as ye,Pn as be,Rn as xe,Un as Se,Wn as Ce,Wt as we,Y as Te,g as Ee,kt as De,l as Oe,o as ke,pn as Ae,q as je,r as Me,s as Ne,tt as Pe,vn as Fe,wn as Ie,yt as Le}from"./workspace-BJELPCNs.js";import{r as Re,t as ze}from"./use-mobile-Db-vWu9Y.js";import{a as Be,c as Ve,i as He,n as Ue,o as We,r as Ge,s as Ke,t as qe}from"./IdentityFields-DZRqtnIG.js";import{i as Je,r as Ye}from"./public-share-D5yz-Pmo.js";import{a as Xe,i as Ze,n as Qe,o as $e,r as et,s as tt,t as nt}from"./text-documents-BaXhu3ra.js";import{t as rt}from"./useDocumentThumbnail-wW0lSOEy.js";import{t as it}from"./markdown-view-BBBZtNSR.js";import{n as at,t as ot}from"./tags-YamdPoBK.js";import{n as st,t as ct}from"./relation-events-CKio19hE.js";import{a as lt,c as ut,i as dt,o as ft}from"./date-time-picker-txVhlNO0.js";import{t as pt}from"./sanitize-DrVcFY1Q.js";import{t as mt}from"./useEscapeClose-DR_xKT_k.js";import{t as X}from"./useToastHelpers-CRrpIIdY.js";import"./layer-style-Byl5LNFR.js";import{t as ht}from"./DocumentIcon-9i1uCMQa.js";import{r as gt,s as _t,t as vt}from"./MessageComposerDialog-CdPp-3GR.js";import{n as yt}from"./LinkToSidePanel-eCy3nW4R.js";import{t as bt}from"./note-save-status-DPz4VzL6.js";import{t as xt}from"./useEditNoteFields-DXLTFEqL.js";import{t as St}from"./DocumentBodyEditor-CVO5KPCs.js";import{n as Ct}from"./use-document-modal-PG8bQyIB.js";import{t as wt}from"./sketch-lazy-BbNgGbR3.js";import{r as Tt}from"./geo-CZfs0E-x.js";var Z=e(n(),1);function Et(e,t){let n=/(^|\s)(!?)@([a-z-]*)$/i.exec(e);if(!n)return null;let r=n[3].toLowerCase();return{before:e.slice(0,n.index)+n[1]+n[2],predicates:t.filter(e=>e.startsWith(r))}}var Q=t();function Dt({workspaceId:e,inputRef:t,onChange:n}){let[r,i]=(0,Z.useState)(``),[a,o]=(0,Z.useState)(!1),[s,c]=(0,Z.useState)(0),l=le(e),u=Et(r,l.predicates),d=!!e&&a&&u!==null,f=u?.predicates??[],p=(0,Z.useId)(),m=Math.min(s,Math.max(0,f.length-1));(0,Z.useEffect)(()=>{d&&document.getElementById(`${p}-${m}`)?.scrollIntoView({block:`nearest`})},[p,m,d,f.length]);let h=e=>{let r=t.current;if(!r||!u)return;let a=`${u.before}@${e}: `;r.value=a,n?.(a),i(a),o(!1),r.focus()};return(0,Z.useEffect)(()=>{let e=t.current;if(!e)return;let n=()=>{i(e.value),c(0),o(!0)},r=()=>o(!1),a=e=>{!d||e.isComposing||(e.key===`Escape`?(e.preventDefault(),e.stopPropagation(),o(!1)):f.length&&[`ArrowDown`,`ArrowUp`,`Enter`,`Tab`].includes(e.key)&&(e.preventDefault(),e.stopPropagation(),e.key===`ArrowDown`?c((m+1)%f.length):e.key===`ArrowUp`?c((m+f.length-1)%f.length):h(f[m])))};return e.addEventListener(`input`,n),e.addEventListener(`focus`,n),e.addEventListener(`blur`,r),e.addEventListener(`keydown`,a),e.setAttribute(`role`,`combobox`),e.setAttribute(`aria-autocomplete`,`list`),e.setAttribute(`aria-expanded`,String(d)),d?e.setAttribute(`aria-controls`,p):e.removeAttribute(`aria-controls`),d&&f.length?e.setAttribute(`aria-activedescendant`,`${p}-${m}`):e.removeAttribute(`aria-activedescendant`),()=>{e.removeEventListener(`input`,n),e.removeEventListener(`focus`,n),e.removeEventListener(`blur`,r),e.removeEventListener(`keydown`,a);for(let t of[`role`,`aria-autocomplete`,`aria-expanded`,`aria-controls`,`aria-activedescendant`])e.removeAttribute(t)}}),d?(0,Q.jsxs)(`div`,{className:`absolute left-0 right-0 top-full z-50 mt-1 max-h-64 overflow-y-auto rounded-md border bg-popover p-1 text-popover-foreground shadow-lg`,children:[(0,Q.jsx)(`div`,{id:p,role:`listbox`,"aria-label":`Relation predicates`,children:f.map((e,t)=>(0,Q.jsxs)(`button`,{id:`${p}-${t}`,type:`button`,role:`option`,"aria-selected":t===m,className:`block w-full rounded px-3 py-2 text-left text-sm font-mono ${t===m?`bg-accent text-accent-foreground`:`hover:bg-accent`}`,onMouseDown:e=>e.preventDefault(),onClick:()=>h(e),children:[`@`,e,`:`]},e))}),!f.length&&(0,Q.jsx)(`p`,{role:`status`,className:`px-3 py-2 text-sm text-muted-foreground`,children:l.loading?`Loading relations…`:l.error?`Unable to load relation predicates.`:`No matching predicates.`})]}):null}var Ot=1,kt=8,At=320,jt=28,Mt=2.5,Nt={scale:1,x:0,y:0};function Pt({src:e,alt:t,className:n=``,onZoomChange:r}){let i=(0,Z.useRef)(null),a=(0,Z.useRef)(null),[o,s]=(0,Z.useState)(Nt),c=(0,Z.useRef)(new Map),l=(0,Z.useRef)(null),u=(0,Z.useRef)(null),d=(0,Z.useRef)(!1),f=(0,Z.useRef)(null),[p,m]=(0,Z.useState)(!1),[h,g]=(0,Z.useState)(e);h!==e&&(g(e),s(Nt)),(0,Z.useEffect)(()=>{r?.(o.scale>1.001)},[o.scale,r]);let _=(0,Z.useCallback)(e=>{let t=i.current,n=a.current;if(!t||!n)return e;let r=Math.min(kt,Math.max(Ot,e.scale)),o=Math.max(0,(n.offsetWidth*r-t.clientWidth)/2),s=Math.max(0,(n.offsetHeight*r-t.clientHeight)/2);return{scale:r,x:Math.min(o,Math.max(-o,e.x)),y:Math.min(s,Math.max(-s,e.y))}},[]),v=(0,Z.useCallback)((e,t,n)=>{let r=i.current;if(!r)return;let a=r.getBoundingClientRect(),o=t-a.left-a.width/2,c=n-a.top-a.height/2;s(t=>{let n=e/t.scale;return _({scale:e,x:o-(o-t.x)*n,y:c-(c-t.y)*n})})},[_]),y=(0,Z.useCallback)(()=>{let e=i.current,t=a.current;if(!e||!t||!t.offsetWidth||!t.offsetHeight)return Mt;let n=Math.max(e.clientWidth/t.offsetWidth,e.clientHeight/t.offsetHeight),r=Math.max(t.naturalWidth/t.offsetWidth,t.naturalHeight/t.offsetHeight)||kt;return Math.min(kt,Math.max(Mt,Math.min(Math.max(n,Mt),r)))},[]),b=(0,Z.useCallback)((e,t)=>{o.scale>1.001?s(Nt):v(y(),e,t)},[o.scale,v,y]),x=e=>{if(c.current.set(e.pointerId,{x:e.clientX,y:e.clientY}),d.current=!1,c.current.size===2){let[e,t]=[...c.current.values()];l.current={dist:Math.hypot(e.x-t.x,e.y-t.y),scale:o.scale,cx:(e.x+t.x)/2,cy:(e.y+t.y)/2}}e.currentTarget.setPointerCapture(e.pointerId)},S=e=>{let t=c.current.get(e.pointerId);if(!t)return;if(c.current.set(e.pointerId,{x:e.clientX,y:e.clientY}),c.current.size>=2&&l.current){let[e,t]=[...c.current.values()],n=Math.hypot(e.x-t.x,e.y-t.y);l.current.dist>0&&(d.current=!0,m(!0),v(l.current.scale*(n/l.current.dist),l.current.cx,l.current.cy));return}if(o.scale<=1.001)return;let n=e.clientX-t.x,r=e.clientY-t.y;(Math.abs(n)>1||Math.abs(r)>1)&&(d.current=!0,m(!0)),s(e=>_({...e,x:e.x+n,y:e.y+r}))},C=e=>{if(c.current.delete(e.pointerId),c.current.size<2&&(l.current=null),c.current.size===0&&m(!1),d.current){u.current=null;return}let t=e.timeStamp,n=u.current;if(n&&t-n.t<At&&Math.hypot(e.clientX-n.x,e.clientY-n.y)<jt){u.current=null,f.current=t,b(e.clientX,e.clientY);return}u.current={t,x:e.clientX,y:e.clientY}},w=e=>{e.preventDefault();let t=o.scale*(e.deltaY<0?1.15:1/1.15);t<=Ot?s(Nt):v(Math.min(kt,t),e.clientX,e.clientY)},T=o.scale>1.001;return(0,Q.jsx)(`div`,{ref:i,className:`relative flex h-full w-full items-center justify-center overflow-hidden`,style:{touchAction:`none`,cursor:T?`grab`:`zoom-in`},onPointerDown:x,onPointerMove:S,onPointerUp:C,onPointerCancel:e=>{c.current.delete(e.pointerId),l.current=null,u.current=null,d.current=!0,c.current.size===0&&m(!1)},onWheel:w,onDoubleClick:e=>{e.preventDefault(),e.stopPropagation(),!(f.current!==null&&e.timeStamp-f.current<At)&&b(e.clientX,e.clientY)},children:(0,Q.jsx)(`img`,{ref:a,src:e,alt:t,draggable:!1,className:n,style:{transform:`translate3d(${o.x}px, ${o.y}px, 0) scale(${o.scale})`,transformOrigin:`center center`,transition:p?`none`:`transform var(--duration-normal) ease-out`,willChange:`transform`}})})}function Ft(){return!/android|iphone|ipad|mobile/i.test(navigator.userAgent)&&navigator.pdfViewerEnabled!==!1}var It=40,Lt=1600;function Rt({blob:e,filename:t}){let n=(0,Z.useRef)(null),[r,i]=(0,Z.useState)({error:null,pages:0,truncated:!1});return(0,Z.useEffect)(()=>{let r=n.current;if(!r)return;let o=!1,s=null;return(async()=>{let n=await a(()=>import(`./pdf-Ciz5_WNq.js`),__vite__mapDeps([0,1])),c=(await a(async()=>{let{default:e}=await import(`./pdf.worker.min-C8Ts8bNu.js`);return{default:e}},[])).default;n.GlobalWorkerOptions.workerSrc=c;let l=await e.arrayBuffer();if(o)return;let u=n.getDocument({data:l});s=()=>{u.destroy()};let d=await u.promise;if(o)return;let f=Math.min(d.numPages,It),p=r.clientWidth||600,m=window.devicePixelRatio||1;for(let e=1;e<=f;e++){if(o)return;let n=await d.getPage(e),a=n.getViewport({scale:1}),s=Math.min(p*m,Lt*m)/a.width,c=n.getViewport({scale:s}),l=document.createElement(`canvas`);if(l.width=c.width,l.height=c.height,l.style.width=`100%`,l.style.height=`auto`,l.className=`rounded border bg-white`,l.setAttribute(`aria-label`,`${t}, page ${e}`),await n.render({canvas:l,viewport:c}).promise,n.cleanup(),o)return;r.appendChild(l),i({error:null,pages:e,truncated:d.numPages>It})}})().catch(e=>{o||i(t=>({...t,error:e instanceof Error?e.message:String(e)}))}),()=>{o=!0,s?.(),r.replaceChildren()}},[e,t]),(0,Q.jsxs)(`div`,{className:`space-y-2`,children:[r.error&&(0,Q.jsxs)(`p`,{className:`text-sm text-destructive`,children:[`Could not render PDF: `,r.error]}),!r.error&&r.pages===0&&(0,Q.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`Rendering PDF…`}),(0,Q.jsx)(`div`,{ref:n,className:`space-y-2`}),r.truncated&&(0,Q.jsxs)(`p`,{className:`text-xs text-muted-foreground`,children:[`Showing the first `,It,` pages. Download the file for the full document.`]})]})}function zt({blob:e,blobUrl:t,filename:n,className:r=``}){let i=(0,Z.useMemo)(()=>e&&e.type!==`application/pdf`?URL.createObjectURL(e.slice(0,e.size,`application/pdf`)):null,[e]);return(0,Z.useEffect)(()=>()=>{i&&URL.revokeObjectURL(i)},[i]),Ft()||!e?(0,Q.jsx)(`div`,{className:`min-h-[300px] ${r}`,children:(0,Q.jsx)(`iframe`,{src:i??t,className:`h-full min-h-[300px] w-full rounded border`,title:n})}):(0,Q.jsx)(`div`,{className:`max-h-viewport-pane overflow-y-auto ${r}`,children:(0,Q.jsx)(Rt,{blob:e,filename:n})})}function Bt({workspaceId:e,document:t}){let{download:n}=Ye(e),[r,i]=(0,Z.useState)(!1),a=Y(t)||`document-${t.id}`;return(0,Q.jsxs)(`button`,{type:`button`,onClick:async()=>{i(!0);try{await n(t.id,a)}finally{i(!1)}},disabled:r,className:`inline-flex items-center gap-1.5 rounded-md border px-2.5 py-1 text-xs text-muted-foreground transition-colors hover:bg-accent hover:text-foreground disabled:opacity-50`,children:[(0,Q.jsx)(U,{className:`h-3.5 w-3.5`}),r?`Preparing…`:`Download`]})}var Vt=1600;function Ht({error:e,loading:t,children:n}){return e?(0,Q.jsx)(`p`,{className:`text-sm text-destructive`,children:e}):t?(0,Q.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`Loading preview...`}):(0,Q.jsx)(Q.Fragment,{children:n})}function Ut({workspaceId:e,document:t,className:n=``}){let r=(0,Z.useContext)(Ve),i=ze(),a=Re(`(pointer: coarse)`),{blobUrl:o,error:s,loading:c}=rt(e,t.id,Vt,{version:t.checksumArray?.[0]??null}),{fetchBlob:l}=Ye(e),u=Y(t)||`document-${t.id}`,[d,f]=(0,Z.useState)(!1);return(0,Q.jsx)(Ht,{error:s,loading:c,children:o&&(0,Q.jsxs)(`div`,{className:`flex h-full min-h-0 flex-col gap-2 ${n}`,children:[i||a?(0,Q.jsx)(`div`,{className:`min-h-0 flex-1`,children:(0,Q.jsx)(Pt,{src:o,alt:u,className:`max-h-full max-w-full object-contain`})}):(0,Q.jsx)(`img`,{src:o,alt:u,draggable:!1,onDoubleClick:r?e=>{e.preventDefault(),e.stopPropagation(),r()}:void 0,title:r?`Double-click to maximize or restore`:void 0,className:`min-h-0 w-full flex-1 object-contain ${r?`cursor-zoom-in`:``}`}),(0,Q.jsxs)(`button`,{type:`button`,onClick:async()=>{f(!0);try{let{blob:e}=await l(t.id),n=URL.createObjectURL(e),r=window.document.createElement(`a`);r.href=n,r.download=u,window.document.body.appendChild(r),r.click(),r.remove(),setTimeout(()=>URL.revokeObjectURL(n),3e4)}finally{f(!1)}},disabled:d,className:`inline-flex shrink-0 self-start items-center gap-1.5 rounded-md border px-2.5 py-1 text-xs text-muted-foreground transition-colors hover:bg-accent hover:text-foreground disabled:opacity-50`,children:[(0,Q.jsx)(U,{className:`h-3.5 w-3.5`}),d?`Preparing…`:`Download original`]})]})})}function Wt({workspaceId:e,document:t,className:n=``}){let{src:r,error:i,loading:a}=tt(e,t.id);return(0,Q.jsx)(Ht,{error:i,loading:a,children:r&&(0,Q.jsxs)(`div`,{className:`space-y-2 ${n}`,children:[(0,Q.jsx)(`audio`,{src:r,controls:!0,preload:`metadata`,className:`w-full`}),(0,Q.jsx)(Bt,{workspaceId:e,document:t})]})})}function Gt({workspaceId:e,document:t,className:n=``}){let{src:r,error:i,loading:a}=tt(e,t.id),[o,s]=(0,Z.useState)(!1);return(0,Q.jsx)(Ht,{error:i,loading:a,children:r&&(0,Q.jsxs)(`div`,{className:`space-y-2 ${n}`,children:[(0,Q.jsx)(`video`,{src:r,controls:!0,playsInline:!0,preload:`metadata`,onError:()=>s(!0),className:`max-h-viewport-pane w-full rounded border`}),o&&(0,Q.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`This video can’t be played inline in your browser. Download it to view.`}),(0,Q.jsx)(Bt,{workspaceId:e,document:t})]})})}function Kt({workspaceId:e,document:t,className:n=``}){let{blobUrl:r,blob:i,error:a,loading:o}=$e(e,t.id,{typeHint:`application/pdf`}),s=Y(t)||`document-${t.id}`;return(0,Q.jsx)(Ht,{error:a,loading:o,children:r&&(0,Q.jsxs)(`div`,{className:`flex h-full min-h-0 flex-col gap-2 ${n}`,children:[(0,Q.jsx)(zt,{blob:i,blobUrl:r,filename:s,className:`min-h-0 flex-1`}),(0,Q.jsx)(`div`,{children:(0,Q.jsx)(Bt,{workspaceId:e,document:t})})]})})}function qt({workspaceId:e,document:t,className:n=``}){let{text:r,error:i,loading:a}=$e(e,t.id,{mode:`text`,version:t.checksumArray?.[0]});return i?(0,Q.jsx)(`p`,{className:`text-sm text-destructive`,children:i}):a||r==null?(0,Q.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`Loading...`}):(0,Q.jsx)(`pre`,{className:`bg-muted p-3 rounded text-xs overflow-auto max-h-viewport-pane whitespace-pre-wrap ${n}`,children:r})}function Jt({workspaceId:e,document:t,className:n=``}){let r=t.schema===pe,{text:i,error:a,loading:o}=$e(e,t.id,{mode:`text`,enabled:!r,version:t.checksumArray?.[0]});return r?(0,Q.jsxs)(`div`,{className:`markdown-note space-y-3 ${n}`,children:[t.data?.title?(0,Q.jsx)(`h3`,{className:`text-lg font-semibold`,children:String(t.data.title)}):null,(0,Q.jsx)(`div`,{className:`markdown-document-frame rounded-md border border-input bg-transparent`,children:(0,Q.jsx)(it,{content:String(t.data?.content??``),className:`markdown-doc px-4 py-3`})})]}):a?(0,Q.jsx)(`p`,{className:`text-sm text-destructive`,children:a}):o||i==null?(0,Q.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`Loading...`}):(0,Q.jsx)(`div`,{className:`markdown-document-frame rounded-md border border-input bg-transparent overflow-auto max-h-viewport-pane ${n}`,children:(0,Q.jsx)(it,{content:i,className:`markdown-doc px-4 py-3`})})}function Yt({document:e,className:t=``}){let n=String(e.data?.url??e.data?.uri??``),r=he(n);return r?(0,Q.jsx)(`div`,{className:`aspect-video w-full ${t}`,children:(0,Q.jsx)(`iframe`,{src:`https://www.youtube-nocookie.com/embed/${encodeURIComponent(r)}`,title:String(e.data?.title??e.data?.label??`YouTube video`),className:`h-full w-full rounded border`,allow:`accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture`,allowFullScreen:!0})}):null}function Xt({document:e,className:t=``}){let n=String(e.data?.url??e.data?.uri??``),[r,i]=(0,Z.useState)({blobUrl:null,blob:null,failed:!1,loading:!0}),[a,o]=(0,Z.useState)(n);n!==a&&(o(n),i({blobUrl:null,blob:null,failed:!1,loading:!0})),(0,Z.useEffect)(()=>{let e=!1,t=null,r=async e=>{if(!e.ok)throw Error(`HTTP ${e.status}`);let t=await e.blob();return new Blob([t],{type:`application/pdf`})},a=()=>{let e=localStorage.getItem(`authToken`);return fetch(`${J}/proxy/pdf?url=${encodeURIComponent(n)}`,{headers:e?{Authorization:`Bearer ${e}`}:{}})};return fetch(n).then(r).catch(()=>a().then(r)).then(n=>{e||(t=URL.createObjectURL(n),i({blobUrl:t,blob:n,failed:!1,loading:!1}))}).catch(()=>{e||i({blobUrl:null,blob:null,failed:!0,loading:!1})}),()=>{e=!0,t&&URL.revokeObjectURL(t)}},[n]);let{blobUrl:s,blob:c,failed:l,loading:u}=r,d=(()=>{try{let e=decodeURIComponent(new URL(n).pathname.split(`/`).filter(Boolean).pop()??``)||`document`;return/\.pdf$/i.test(e)?e:`${e}.pdf`}catch{return`document.pdf`}})();return(0,Q.jsxs)(`div`,{className:`flex h-full min-h-0 flex-col gap-2 ${t}`,children:[(0,Q.jsxs)(`div`,{className:`flex shrink-0 flex-wrap items-center gap-3`,children:[(0,Q.jsxs)(`a`,{href:n,target:`_blank`,rel:`noopener noreferrer`,className:`inline-flex items-center gap-1 text-xs text-primary hover:underline`,children:[(0,Q.jsx)(L,{className:`h-3 w-3`}),` `,n]}),c&&(0,Q.jsxs)(`button`,{type:`button`,onClick:()=>{if(!c)return;let e=URL.createObjectURL(c),t=window.document.createElement(`a`);t.href=e,t.download=d,window.document.body.appendChild(t),t.click(),t.remove(),setTimeout(()=>URL.revokeObjectURL(e),3e4)},className:`inline-flex items-center gap-1.5 rounded-md border px-2.5 py-1 text-xs text-muted-foreground transition-colors hover:bg-accent hover:text-foreground`,children:[(0,Q.jsx)(U,{className:`h-3.5 w-3.5`}),` Download`]})]}),u&&(0,Q.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`Loading PDF…`}),l&&(0,Q.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`Inline preview unavailable (direct fetch and server proxy both failed). Use the link above.`}),s&&(0,Q.jsx)(zt,{blob:c,blobUrl:s,filename:d,className:`min-h-[300px] flex-1`})]})}function Zt(e){if(!e)return!1;try{let t=new URL(e);return!!(/\.pdf$/i.test(t.pathname)||t.hostname.endsWith(`arxiv.org`)&&t.pathname.startsWith(`/pdf/`))}catch{return!1}}function Qt(e){try{return new URL(e).hostname.replace(/^www\./,``)}catch{return e}}function $t({document:e,className:t=``}){let n=e.data||{},r=String(n.url??n.uri??``),i=String(n.title??n.label??``)||Qt(r),a=typeof n.favIconUrl==`string`?n.favIconUrl:``,o=n.pinned===!0,s=typeof n.timestamp==`string`?n.timestamp:null,[c,l]=(0,Z.useState)(!1);return(0,Q.jsxs)(`div`,{className:`space-y-3 ${t}`,children:[(0,Q.jsxs)(`a`,{href:r,target:`_blank`,rel:`noopener noreferrer`,className:`group flex items-start gap-3 rounded-lg border bg-card p-3 transition-colors hover:bg-accent/40`,children:[(0,Q.jsx)(`div`,{className:`mt-0.5 flex h-9 w-9 shrink-0 items-center justify-center overflow-hidden rounded bg-muted`,children:a&&!c?(0,Q.jsx)(`img`,{src:a,alt:``,className:`h-5 w-5`,onError:()=>l(!0)}):(0,Q.jsx)(S,{className:`h-4 w-4 text-muted-foreground`})}),(0,Q.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,Q.jsx)(`span`,{className:`truncate font-medium leading-tight`,children:i}),o&&(0,Q.jsx)(g,{className:`h-3 w-3 shrink-0 fill-warning text-warning`})]}),(0,Q.jsx)(`div`,{className:`mt-0.5 truncate text-xs text-muted-foreground`,children:Qt(r)}),(0,Q.jsx)(`div`,{className:`mt-1 truncate font-mono text-[11px] text-muted-foreground/70`,children:r})]}),(0,Q.jsx)(L,{className:`mt-1 h-4 w-4 shrink-0 text-muted-foreground reveal-on-hover`})]}),s&&(0,Q.jsxs)(`p`,{className:`text-xs text-muted-foreground`,children:[`Saved `,new Date(s).toLocaleString()]})]})}function en(e){return e.data||{}}var tn={pending:`bg-muted text-muted-foreground`,"in-progress":`bg-info/15 text-info dark:text-info`,completed:`bg-success/15 text-success dark:text-success`,cancelled:`bg-muted text-muted-foreground line-through`};function nn(e){if(!e.dueDate||e.status===`completed`||e.status===`cancelled`)return!1;let t=new Date(e.dueDate).getTime();return Number.isFinite(t)&&t<Date.now()}function rn(e){if(!e)return``;let t=new Date(e);return Number.isNaN(t.getTime())?``:t.toLocaleString(void 0,{month:`short`,day:`numeric`,hour:`2-digit`,minute:`2-digit`})}async function an(e,t,n){let r=n===`completed`,i={...t.data||{},status:n,completed:r};r?i.completedAt=new Date().toISOString():delete i.completedAt,await Fe(e,{id:t.id,schema:t.schema,schemaVersion:t.schemaVersion,data:i}),window.dispatchEvent(new CustomEvent(`workspace:documents:refresh`))}function on({document:e,workspaceId:t,className:n=``}){let r=en(e),i=Je()!=null,[a,o]=(0,Z.useState)(!1),{replicating:s,label:c}=Ie(e),l=r.status===`completed`,u=r.status??`pending`,d=nn(r);return(0,Q.jsx)(`div`,{className:`space-y-3 ${n}`,children:(0,Q.jsxs)(`div`,{className:`relative flex items-start gap-3 rounded-lg border bg-card p-3 transition-opacity ${s?`opacity-60`:``}`,children:[(0,Q.jsx)(`button`,{type:`button`,onClick:async()=>{if(!(i||a)){o(!0);try{await an(t,e,l?`pending`:`completed`)}catch{}finally{o(!1)}}},disabled:i||a||s,"aria-pressed":l,title:l?`Mark not done`:`Mark done`,className:`mt-0.5 flex h-5 w-5 shrink-0 items-center justify-center rounded border transition-colors ${l?`border-success bg-success text-success-foreground`:`border-input hover:border-success`} ${i?`cursor-default opacity-70`:``}`,children:a?(0,Q.jsx)(H,{className:`h-3 w-3 animate-spin`}):l&&(0,Q.jsx)(C,{className:`h-3.5 w-3.5`})}),(0,Q.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,Q.jsx)(`div`,{className:`font-medium leading-tight ${l?`text-muted-foreground line-through`:``}`,children:r.title||`Todo ${e.id}`}),(0,Q.jsxs)(`div`,{className:`mt-1.5 flex flex-wrap items-center gap-2 text-xs`,children:[(0,Q.jsx)(`span`,{className:`rounded-full px-2 py-0.5 ${tn[u]}`,children:dt[u]}),r.dueDate&&(0,Q.jsxs)(`span`,{className:`inline-flex items-center gap-1 ${d?`font-medium text-destructive`:`text-muted-foreground`}`,children:[(0,Q.jsx)(E,{className:`h-3 w-3`}),rn(r.dueDate),d?` · overdue`:``]}),typeof r.priority==`number`&&(0,Q.jsxs)(`span`,{className:`inline-flex items-center gap-1 text-muted-foreground`,children:[(0,Q.jsx)(ne,{className:`h-3 w-3`}),`P`,r.priority]})]}),r.description&&(0,Q.jsx)(it,{content:String(r.description),className:`mt-2 text-sm text-muted-foreground`}),s&&(0,Q.jsxs)(`div`,{className:`mt-2 inline-flex items-center gap-1.5 text-xs text-muted-foreground`,role:`status`,children:[(0,Q.jsx)(H,{className:`h-3 w-3 animate-spin`}),c]})]})]})})}function sn(e,t){let{fetchBlob:n}=Ye(e),r=Je(),i=t.checksumArray?.[0]||t.updatedAt||``,a=JSON.stringify([e,r,t.id,i]),o=typeof t.data?.body==`string`?t.data.body:null,s=typeof t.data?.bodyHtml==`string`?t.data.bodyHtml:null,c=o!==null||s!==null,[l,u]=(0,Z.useState)(null);return(0,Z.useEffect)(()=>{if(c)return;let e=new AbortController;return n(t.id,{format:`email`,version:i,signal:e.signal}).then(async({blob:t})=>{let n=JSON.parse(await t.text());if(typeof n.body!=`string`||n.bodyHtml!=null&&typeof n.bodyHtml!=`string`)throw Error(`Invalid email content response`);e.signal.aborted||u({key:a,body:n.body,bodyHtml:n.bodyHtml||null,error:null})}).catch(t=>{e.signal.aborted||u({key:a,body:``,bodyHtml:null,error:t instanceof Error?t.message:String(t)})}),()=>e.abort()},[a,c,n,t.id,i]),c?{body:o||``,bodyHtml:s,loading:!1,error:null}:l?.key===a?{...l,loading:!1}:{body:``,bodyHtml:null,loading:!0,error:null}}function cn(e){return e?typeof e==`string`?e:e.name&&e.address?`${e.name} <${e.address}>`:e.address||e.name||``:``}function $(e){return e?(Array.isArray(e)?e:[e]).map(e=>cn(e)).filter(Boolean).join(`, `):``}function ln(e){if(!Number.isFinite(e))return``;let t=Number(e);return t<1024?`${t} B`:t<1048576?`${(t/1024).toFixed(1)} KB`:`${(t/1024/1024).toFixed(1)} MB`}function un(e,t,n){let r=0;pt.addHook(`afterSanitizeAttributes`,e=>{if(e.tagName===`IMG`){let i=e.getAttribute(`src`)||``,a=i.toLowerCase();if(a.startsWith(`cid:`)){let n=i.slice(4).replace(/^<|>$/g,``),r=t.get(n)||t.get(`<${n}>`);r?e.setAttribute(`src`,r):e.removeAttribute(`src`)}else(a.startsWith(`http:`)||a.startsWith(`https:`)||a.startsWith(`//`))&&(r++,n?e.setAttribute(`src`,i.replace(/^http:/i,`https:`).replace(/^\/\//,`https://`)):e.removeAttribute(`src`))}e.tagName===`A`&&(e.setAttribute(`target`,`_blank`),e.setAttribute(`rel`,`noopener noreferrer`))});try{let t=pt.sanitize(e,{FORBID_TAGS:[`script`,`iframe`,`object`,`embed`,`form`,`base`,`link`,`meta`],FORBID_ATTR:[`srcset`]}),i=`<!doctype html><html><head>
|
|
3
|
-
<meta charset="utf-8">
|
|
4
|
-
<meta name="viewport" content="width=device-width,initial-scale=1">
|
|
5
|
-
<meta http-equiv="Content-Security-Policy" content="${`default-src 'none'; img-src data:${n?` https:`:``}; style-src 'unsafe-inline'`}">
|
|
6
|
-
<style>html{overflow:auto}body{margin:12px;font:14px/1.5 system-ui,sans-serif;color:#1a1a1a;background:#fff}@media(max-width:480px){body{margin:8px}}</style>
|
|
7
|
-
</head><body>${t}</body></html>`;return{url:URL.createObjectURL(new Blob([i],{type:`text/html;charset=utf-8`})),remoteCount:r}}finally{pt.removeHook(`afterSanitizeAttributes`)}}function dn(e){return new Promise((t,n)=>{let r=new FileReader;r.onload=()=>t(String(r.result)),r.onerror=()=>n(r.error),r.readAsDataURL(e)})}function fn(e){return(0,Q.jsx)(pn,{...e},`${e.workspaceId}:${e.document.id}`)}function pn({workspaceId:e,document:t,className:n=``}){let{fetchBlob:r,download:i}=Ye(e),a=t.data||{},o=Array.isArray(a.attachments)?a.attachments:[],{body:s,bodyHtml:c,loading:u,error:d}=sn(e,t),[f,p]=(0,Z.useState)(null),[m,h]=(0,Z.useState)(!1),[g,v]=(0,Z.useState)(!1),[b,x]=(0,Z.useState)(0),[S,C]=(0,Z.useState)(null);(0,Z.useEffect)(()=>{if(!c||m)return;let e=!1,n=[],i=o.filter(e=>e.contentId&&e.url);return Promise.all(i.slice(0,20).map(async e=>{try{let{blob:n}=await r(t.id,{url:e.url}),i=await dn(n);return[String(e.contentId).replace(/^<|>$/g,``),i]}catch{return null}})).then(t=>{if(e)return;let r=new Map(t.filter(Boolean)),{url:i,remoteCount:a}=un(c,r,g);n.push(i),p(i),x(a)}).catch(t=>{e||C(String(t instanceof Error?t.message:t))}),()=>{e=!0,n.forEach(e=>URL.revokeObjectURL(e)),p(null)}},[e,t.id,c,m,g]);let w=typeof a.date==`string`?new Date(a.date).toLocaleString():null,T=o.filter(e=>!e.isInline||!e.contentId),E=async e=>{if(e.url)try{await i(t.id,e.filename||`attachment`,{url:e.url})}catch(e){C(e instanceof Error?e.message:String(e))}};return(0,Q.jsxs)(`div`,{className:`flex h-full min-h-0 min-w-0 flex-col gap-3 ${n}`,children:[(0,Q.jsx)(`div`,{className:`shrink-0 rounded-md border bg-muted/30 p-2 text-sm sm:p-3`,children:(0,Q.jsxs)(`div`,{className:`flex flex-wrap items-start justify-between gap-2 sm:gap-3`,children:[(0,Q.jsxs)(`div`,{className:`min-w-0 flex-1 basis-64 space-y-1`,children:[(0,Q.jsx)(`div`,{className:`truncate text-base font-semibold`,children:String(a.subject??`(no subject)`)}),(0,Q.jsxs)(`details`,{className:`sm:hidden`,children:[(0,Q.jsxs)(`summary`,{className:`cursor-pointer text-xs`,children:[(0,Q.jsx)(`span`,{className:`inline-block max-w-[85%] truncate align-bottom`,children:typeof a.from==`object`&&a.from?a.from.name||a.from.address:String(a.from||`Unknown sender`)}),(0,Q.jsx)(`span`,{className:`ml-2 text-muted-foreground`,children:`Details`})]}),(0,Q.jsxs)(`div`,{className:`mt-2 space-y-1 break-words text-xs`,children:[(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`span`,{className:`text-muted-foreground`,children:`From:`}),` `,cn(a.from)]}),$(a.to)&&(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`span`,{className:`text-muted-foreground`,children:`To:`}),` `,$(a.to)]}),$(a.cc)&&(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`span`,{className:`text-muted-foreground`,children:`Cc:`}),` `,$(a.cc)]}),w&&(0,Q.jsx)(`div`,{className:`text-xs text-muted-foreground`,children:w})]})]}),(0,Q.jsxs)(`div`,{className:`hidden space-y-1 break-words sm:block`,children:[(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`span`,{className:`text-muted-foreground`,children:`From:`}),` `,cn(a.from)]}),$(a.to)&&(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`span`,{className:`text-muted-foreground`,children:`To:`}),` `,$(a.to)]}),$(a.cc)&&(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`span`,{className:`text-muted-foreground`,children:`Cc:`}),` `,$(a.cc)]}),w&&(0,Q.jsx)(`div`,{className:`text-xs text-muted-foreground`,children:w})]})]}),c&&(0,Q.jsxs)(`div`,{className:`flex max-w-full flex-wrap gap-2`,children:[(0,Q.jsxs)(K,{size:`sm`,variant:`outline`,onClick:()=>h(!m),children:[m?(0,Q.jsx)(l,{className:`mr-1.5 h-3.5 w-3.5`}):(0,Q.jsx)(B,{className:`mr-1.5 h-3.5 w-3.5`}),m?`HTML`:`Plain text`]}),!m&&b>0&&(0,Q.jsxs)(K,{size:`sm`,variant:g?`secondary`:`outline`,onClick:()=>v(!g),title:`Remote images can reveal your IP/read status to the sender`,children:[g?(0,Q.jsx)(y,{className:`mr-1.5 h-3.5 w-3.5`}):(0,Q.jsx)(_,{className:`mr-1.5 h-3.5 w-3.5`}),g?`Hide remote images`:`Show remote images (${b})`]})]})]})}),(S||d)&&(0,Q.jsx)(`p`,{className:`text-sm text-destructive`,children:S||d}),u?(0,Q.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`Loading message…`}):d?(0,Q.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:String(a.bodyPreview||`Message content could not be loaded.`)}):!m&&c?f?(0,Q.jsx)(`iframe`,{src:f,sandbox:``,title:String(a.subject??`email`),className:`min-h-[12rem] w-full flex-1 rounded border bg-white`}):(0,Q.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`Rendering...`}):(0,Q.jsx)(`pre`,{className:`min-h-[12rem] flex-1 overflow-auto whitespace-pre-wrap rounded bg-muted p-3 text-sm`,children:s||`(empty body)`}),T.length>0&&(0,Q.jsxs)(`div`,{className:`shrink-0 space-y-1`,children:[(0,Q.jsxs)(`div`,{className:`text-xs font-medium text-muted-foreground`,children:[`Attachments (`,T.length,`)`]}),T.map((e,t)=>(0,Q.jsxs)(`div`,{className:`flex items-center justify-between gap-2 rounded border px-2 py-1.5 text-sm`,children:[(0,Q.jsxs)(`span`,{className:`inline-flex min-w-0 items-center gap-2`,children:[(0,Q.jsx)(B,{className:`h-4 w-4 shrink-0 text-muted-foreground`}),(0,Q.jsx)(`span`,{className:`truncate`,children:e.filename||`attachment`}),(0,Q.jsx)(`span`,{className:`shrink-0 text-xs text-muted-foreground`,children:ln(e.size)})]}),e.url&&(0,Q.jsxs)(`button`,{onClick:()=>E(e),className:`inline-flex shrink-0 items-center gap-1 text-xs text-primary hover:underline`,children:[(0,Q.jsx)(U,{className:`h-3 w-3`}),` Download`]})]},e.url||t))]})]})}function mn({attachment:e,workspaceId:t,document:n}){let{download:r}=Ye(t),i=e.mimeType||e.contentType||``,a=e.name||e.filename||`Attachment`,o=i.startsWith(`audio/`)||i.startsWith(`video/`),{blobUrl:s,error:c,loading:l}=$e(t,n.id,{url:e.url,typeHint:i,enabled:!o&&!!e.url}),{src:u,error:d,loading:f}=tt(t,n.id,{url:e.url,enabled:o&&!!e.url}),[p,m]=(0,Z.useState)(!1),[h,g]=(0,Z.useState)(``),_=o?d:c;return(0,Q.jsxs)(`div`,{className:`space-y-2 rounded border p-2`,children:[_&&(0,Q.jsx)(`p`,{className:`text-xs text-destructive`,children:_}),(o?f:l)&&(0,Q.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`Loading attachment…`}),!o&&s&&i.startsWith(`image/`)&&(0,Q.jsx)(`img`,{src:s,alt:a,className:`max-h-96 max-w-full rounded object-contain`}),o&&u&&(i.startsWith(`video/`)?(0,Q.jsx)(`video`,{controls:!0,playsInline:!0,preload:`metadata`,src:u,onError:()=>m(!0),className:`max-h-96 w-full rounded`},u):(0,Q.jsx)(`audio`,{controls:!0,preload:`metadata`,src:u,onError:()=>m(!0),className:`w-full`},u)),p&&(0,Q.jsx)(`p`,{role:`alert`,className:`text-xs text-destructive`,children:`This media could not be played in your browser. Download it to play in another app.`}),h&&(0,Q.jsx)(`p`,{role:`alert`,className:`text-xs text-destructive`,children:h}),e.url&&(0,Q.jsxs)(`button`,{className:`text-sm text-primary underline`,onClick:()=>{r(n.id,a,{url:e.url}).catch(()=>g(`Attachment could not be downloaded.`))},children:[`Download `,a]})]})}function hn(e){let t=e.document.data,n=t.sender,r=t.channel,i=Array.isArray(t.attachments)?t.attachments:[],a=t.timestamp?new Date(String(t.timestamp)):null;return(0,Q.jsxs)(`article`,{className:`space-y-4 p-3 ${e.className||``}`,children:[(0,Q.jsxs)(`header`,{className:`space-y-1 border-b pb-3`,children:[(0,Q.jsx)(`p`,{className:`font-medium`,children:n?.name||n?.displayName||n?.username||n?.id||`Unknown sender`}),(0,Q.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:[r?.name||r?.id,String(t.platform||``),a&&!Number.isNaN(a.getTime())?a.toLocaleString():``].filter(Boolean).join(` · `)})]}),(0,Q.jsx)(`p`,{className:`whitespace-pre-wrap break-words text-sm`,children:String(t.text||`(No text)`)}),!!t.mediaError&&(0,Q.jsx)(`p`,{className:`text-xs text-destructive`,children:String(t.mediaError)}),i.map((t,n)=>(0,Q.jsx)(mn,{...e,attachment:t},t.url||n))]})}var gn={email:A,phone:oe,sms:N,chat:N,slack:N,matrix:N,web:S,url:S},_n={person:`Person`,organization:`Organization`,service:`Service`,bot:`Bot`},vn=e=>Array.isArray(e)?e:[];function yn(e,t){return t?e===`email`?`mailto:${t}`:e===`phone`||e===`sms`?`tel:${t.replace(/[^\d+]/g,``)}`:/^https?:\/\//i.test(t)?t:null:null}function bn({title:e,count:t,children:n}){return t===0?null:(0,Q.jsxs)(`div`,{className:`space-y-1`,children:[(0,Q.jsx)(`p`,{className:`text-xs font-medium text-muted-foreground`,children:e}),(0,Q.jsx)(`div`,{className:`space-y-1`,children:n})]})}function xn({icon:e,primary:t,children:n,title:r}){return(0,Q.jsxs)(`div`,{className:`flex min-w-0 items-center gap-2 rounded-md border bg-card px-2.5 py-1.5 text-sm`,title:r,children:[(0,Q.jsx)(e,{className:`h-3.5 w-3.5 shrink-0 text-muted-foreground`}),(0,Q.jsx)(`div`,{className:`min-w-0 flex-1 truncate`,children:n}),t&&(0,Q.jsx)(R,{className:`h-3 w-3 shrink-0 fill-current text-data-5`,"aria-label":`Primary`})]})}function Sn({document:e,className:t}){let n=e.data??{},r=vn(n.identifiers),i=vn(n.channels),a=vn(n.organizations),o=vn(n.links),s=vn(n.tags),c=String(n.displayName||``).trim(),l=Ce(e.schema,xe),u=String(n.primaryEmail||``).trim(),d=n.name&&typeof n.name==`object`?n.name:{},f=[d.prefix,d.given,d.middle,d.family,d.suffix].map(e=>String(e||``).trim()).filter(Boolean).join(` `),p=i.some(e=>e.kind===`email`&&e.value===u);return(0,Q.jsxs)(`div`,{className:G(`space-y-4`,t),children:[(0,Q.jsxs)(`div`,{className:`space-y-1`,children:[(0,Q.jsx)(`h2`,{className:`text-lg font-semibold`,children:c||`Identity ${e.id}`}),(0,Q.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2 text-xs text-muted-foreground`,children:[l&&(0,Q.jsx)(`span`,{className:`rounded-full bg-muted px-2 py-0.5`,children:_n[l]||l}),f&&f!==c&&(0,Q.jsx)(`span`,{children:f}),String(n.timezone||``)&&(0,Q.jsx)(`span`,{children:String(n.timezone)}),String(n.locale||``)&&(0,Q.jsx)(`span`,{children:String(n.locale)})]})]}),u&&!p&&(0,Q.jsx)(bn,{title:`Primary email`,count:1,children:(0,Q.jsx)(xn,{icon:A,primary:!0,children:(0,Q.jsx)(`a`,{href:`mailto:${u}`,className:`hover:underline`,children:u})})}),(0,Q.jsx)(bn,{title:`Channels`,count:i.length,children:i.map((e,t)=>{let n=String(e.kind||``).toLowerCase(),r=String(e.value||``),i=yn(n,r),a=gn[n]||N;return(0,Q.jsxs)(xn,{icon:a,primary:e.primary,title:e.platform||n,children:[i?(0,Q.jsx)(`a`,{href:i,className:`hover:underline`,target:i.startsWith(`http`)?`_blank`:void 0,rel:`noopener noreferrer`,children:r}):r,e.label&&(0,Q.jsx)(`span`,{className:`ml-2 text-xs text-muted-foreground`,children:e.label})]},`${n}:${r}:${t}`)})}),(0,Q.jsx)(bn,{title:`Identifiers`,count:r.length,children:r.map((e,t)=>(0,Q.jsxs)(xn,{icon:ie,primary:e.primary,children:[(0,Q.jsx)(`span`,{className:`font-mono text-xs`,children:e.identifier}),(0,Q.jsx)(`span`,{className:`ml-2 text-xs text-muted-foreground`,children:[e.type,e.provider].filter(Boolean).join(` · `)})]},`${e.type}:${e.identifier}:${t}`))}),(0,Q.jsx)(bn,{title:`Organizations`,count:a.length,children:a.map((e,t)=>(0,Q.jsxs)(xn,{icon:T,children:[e.name,e.role&&(0,Q.jsx)(`span`,{className:`ml-2 text-xs text-muted-foreground`,children:e.role})]},`${e.name}:${t}`))}),(0,Q.jsx)(bn,{title:`Links`,count:o.length,children:o.map((e,t)=>(0,Q.jsxs)(xn,{icon:O,children:[(0,Q.jsx)(`span`,{className:`font-mono text-xs`,children:e.target}),e.type&&(0,Q.jsx)(`span`,{className:`ml-2 text-xs text-muted-foreground`,children:e.type})]},`${e.type}:${e.target}:${t}`))}),s.length>0&&(0,Q.jsx)(`div`,{className:`flex flex-wrap gap-1.5`,children:s.map(e=>(0,Q.jsx)(`span`,{className:`rounded-full bg-muted px-2 py-0.5 text-xs text-muted-foreground`,children:e},e))})]})}function Cn({document:e}){let t=String(e.metadata?.contentType||`application/octet-stream`);return(0,Q.jsxs)(`p`,{className:`text-sm text-muted-foreground`,children:[`No inline preview available for `,(0,Q.jsx)(`span`,{className:`font-mono`,children:t}),`. Use Download.`]})}function wn(e){let t=e.schema;if(t===`data/schema/note`)return Jt;if(t===`data/schema/drawing`)return Ut;if(t===`data/schema/task`)return on;if(t===`data/schema/message/email`)return fn;if(t===`data/schema/message`)return hn;if(t===`data/schema/identity`||t.startsWith(`data/schema/identity/`))return Sn;if(t===`data/schema/tab`||t===`data/schema/link`){let t=String(e.data?.url??e.data?.uri??``);return he(t)?Yt:Zt(t)?Xt:$t}if(t!==`data/schema/file`)return null;let n=String(e.metadata?.contentType||``);switch(Se(n,Y(e))){case`image`:return Ut;case`audio`:return Wt;case`video`:return Gt;case`pdf`:return Kt;case`markdown`:return Jt;case`text`:return qt;default:return Cn}}function Tn({onSearch:e,onDraftChange:t,inputRef:n,workspaceId:r,label:i=`Search documents`,clearOnSubmit:a=!0,showSubmitButton:o=!0}){let s=(0,Z.useRef)(null),c=n??s;return(0,Q.jsxs)(`form`,{className:`canvas-search-input`,role:`search`,onSubmit:n=>{n.preventDefault();let r=n.currentTarget.elements.namedItem(`query`),i=r.value.trim();i&&(e(i),a&&(r.value=``,t?.(``)))},children:[(0,Q.jsx)(`input`,{ref:c,name:`query`,type:`search`,"aria-label":i,placeholder:i,autoComplete:`off`,enterKeyHint:`search`,onChange:e=>t?.(e.target.value),onKeyDown:e=>{e.key===`Enter`&&e.nativeEvent.isComposing&&e.preventDefault()}}),o&&(0,Q.jsx)(`button`,{type:`submit`,className:`canvas-nav-button`,"aria-label":`Run search`,title:`Run search`,children:(0,Q.jsx)(W,{size:17})}),r&&(0,Q.jsx)(Dt,{workspaceId:r,inputRef:c,onChange:t})]})}function En({queries:e,onRemoveQuery:t,scope:n=`path`,onScopeChange:r}){return(0,Q.jsxs)(`div`,{className:`canvas-search-options`,children:[r&&(0,Q.jsxs)(`div`,{className:`canvas-search-scopes`,"aria-label":`Search scope`,children:[(0,Q.jsx)(`span`,{children:`Search in`}),(0,Q.jsx)(`button`,{type:`button`,"aria-pressed":n===`path`,onClick:()=>r(`path`),children:`This path`}),(0,Q.jsx)(`button`,{type:`button`,"aria-pressed":n===`workspace`,onClick:()=>r(`workspace`),children:`Workspace`})]}),e.length>0&&(0,Q.jsxs)(`div`,{className:`canvas-search-queries`,"aria-label":`Active searches`,children:[e.map((e,n)=>{let r=/"[^"]+/.test(e);return(0,Q.jsxs)(`span`,{className:r?`canvas-search-query canvas-search-query-exact`:`canvas-search-query`,children:[r?(0,Q.jsx)(F,{size:12,"aria-hidden":`true`}):(0,Q.jsx)(W,{size:12,"aria-hidden":`true`}),(0,Q.jsx)(`span`,{title:r?`${e} (exact phrase)`:e,children:e}),t&&(0,Q.jsx)(`button`,{type:`button`,onClick:()=>t(n),"aria-label":`Remove search: ${e}`,children:(0,Q.jsx)(h,{size:14})})]},`${e}-${n}`)}),t&&e.length>1&&(0,Q.jsx)(`button`,{type:`button`,onClick:()=>t(-1),className:`canvas-search-clear`,children:`Clear all`})]})]})}function Dn({children:e,accentColor:t}){return(0,Q.jsxs)(`div`,{className:`canvas-navigation-tabs`,children:[(0,Q.jsx)(`span`,{"aria-hidden":`true`,className:`canvas-tab-divider`,style:t?{backgroundColor:t}:void 0}),e]})}function On({workspace:e,workspaceIcon:t,tree:n,path:i,document:a,section:o,onBack:s,onBrowseWorkspaces:c,onBrowseTree:l,onNavigatePath:u,onDocument:d,onSection:f,onFilter:p,filtersActive:m,filtersOpen:g,onAdd:_,search:v,onDraftChange:y,tabs:x,accentColor:S,actions:C}){let w=ze(),[T,E]=(0,Z.useState)(!1),[D,O]=(0,Z.useState)(!1),k=(0,Z.useRef)(null),A=(0,Z.useRef)(null),M=(0,Z.useRef)(null),N=(0,Z.useRef)(!1),P=JSON.stringify([e,n,i,a]),[F,ee]=(0,Z.useState)(P);F!==P&&(ee(P),E(!1)),(0,Z.useEffect)(()=>{T?A.current?.focus():(k.current&&(k.current.scrollLeft=k.current.scrollWidth,O(k.current.scrollLeft>1)),N.current&&=(M.current?.focus(),!1))},[T,P,o]);let I=()=>{N.current=!0,E(!1),y?.(``)},L=w&&!!l,te=T?I:L?l:s??l,ne=T?`Back to address`:L?`Back to tree`:`Back to previous view`,R=ue(i,e).slice(1),z=(e,t,n,r,i=!1)=>n?(0,Q.jsx)(`button`,{type:`button`,className:t,onClick:n,title:r,"aria-current":i?`location`:void 0,children:e}):(0,Q.jsx)(`span`,{className:`canvas-address-label ${t}`,title:r,"aria-current":i?`location`:void 0,children:e});return(0,Q.jsxs)(`header`,{className:`canvas-navigation${x?` has-tabs`:``}`,style:S?{borderTopColor:S}:void 0,children:[x&&(0,Q.jsx)(Dn,{accentColor:S,children:x}),(0,Q.jsxs)(`div`,{className:`canvas-address-row`,children:[(0,Q.jsx)(`button`,{type:`button`,className:`canvas-nav-button`,"aria-label":ne,title:ne,disabled:!T&&!s&&!l,onClick:te,children:L&&!T?(0,Q.jsx)(re,{size:19}):(0,Q.jsx)(V,{size:19})}),(0,Q.jsxs)(`div`,{className:`canvas-address-field`,onDoubleClick:e=>{v&&!e.target.closest(`button`)&&E(!0)},onKeyDown:e=>{e.key===`Escape`&&T&&(e.preventDefault(),e.stopPropagation(),I())},children:[T&&v?(0,Q.jsx)(Tn,{inputRef:A,workspaceId:v.localOnly?void 0:v.workspaceId,onSearch:v.onSearch,onDraftChange:y,clearOnSubmit:!v.localOnly,showSubmitButton:!1,label:v.queries.length?`Refine search…`:`Search documents…`}):(0,Q.jsx)(Q.Fragment,{children:(0,Q.jsxs)(`div`,{ref:k,className:`canvas-address-crumbs${D?` is-scrolled`:``}`,onScroll:e=>O(e.currentTarget.scrollLeft>1),role:`navigation`,"aria-label":`Canvas address`,tabIndex:0,onKeyDown:e=>{e.key===`Enter`&&e.target===e.currentTarget&&v&&E(!0)},children:[z((0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(r,{icon:t||`ph:stack-fill`,className:`h-4 w-4 shrink-0`,"aria-hidden":`true`}),(0,Q.jsx)(`span`,{className:`truncate`,children:e})]}),`canvas-address-workspace`,c,`Browse workspaces`),n&&z(`[${n}]`,`canvas-address-tree`,l,`Browse tree: ${n}`),z(`:/`,`canvas-address-root`,u?()=>u(`/`):void 0,`Go to tree root`),R.map((e,t)=>(0,Q.jsxs)(`span`,{className:`canvas-address-segment`,children:[t>0&&(0,Q.jsx)(`span`,{"aria-hidden":`true`,children:`/`}),z(e.label,``,u?()=>u(e.path):void 0,e.path,!a&&t===R.length-1)]},e.path)),a&&(0,Q.jsxs)(`span`,{className:`canvas-address-segment`,children:[(0,Q.jsx)(`span`,{"aria-hidden":`true`,children:R.length?`/`:``}),z(a,``,d,a)]}),o&&z(`#${o}`,`canvas-address-section`,f,o,!0)]})}),v&&(0,Q.jsxs)(`button`,{ref:M,type:`button`,className:`canvas-nav-button canvas-address-search`,onClick:()=>{T?A.current?.form?.requestSubmit():E(!0)},"aria-label":T?`Run search`:`Search this canvas`,"aria-expanded":T,title:T?`Run search`:`Search this canvas`,children:[(0,Q.jsx)(W,{size:17}),v.queries.length>0&&(0,Q.jsx)(`span`,{className:`canvas-nav-dot`})]})]}),p&&(0,Q.jsxs)(`button`,{type:`button`,className:`canvas-nav-button canvas-filter-button`,onClick:p,"aria-label":m?`Filters active`:`Filters`,"aria-expanded":!!g,"data-active":!!m,title:m?`Filters active`:`Filters`,children:[(0,Q.jsx)(j,{size:19}),m&&(0,Q.jsx)(`span`,{className:`canvas-nav-dot`})]}),_&&(0,Q.jsx)(`button`,{type:`button`,className:`canvas-nav-button canvas-add-button`,onClick:_,"aria-label":`Add here`,title:`Add here`,children:(0,Q.jsx)(b,{size:21})}),C]}),T&&v&&(0,Q.jsxs)(`div`,{className:`canvas-search-dropdown`,children:[(0,Q.jsxs)(`div`,{className:`canvas-search-heading`,children:[(0,Q.jsx)(`span`,{children:v.localOnly?`Filter documents on this page`:y?`Type to filter this page · Enter to search all results`:`Search text or an exact ID, e.g. @id:123`}),(0,Q.jsx)(`button`,{type:`button`,className:`canvas-nav-button`,onClick:I,"aria-label":`Close search`,children:(0,Q.jsx)(h,{size:16})})]}),(0,Q.jsx)(En,{...v})]}),!T&&v&&v.queries.length>0&&(0,Q.jsx)(`div`,{className:`px-3 pb-2`,children:(0,Q.jsx)(En,{queries:v.queries,onRemoveQuery:v.onRemoveQuery})})]})}function kn({workspaceId:e,document:t,className:n}){let r=wn(t);return r?(0,Q.jsx)(r,{workspaceId:e,document:t,className:n}):(0,Q.jsx)(`pre`,{className:`overflow-auto p-2 text-xs`,children:JSON.stringify(t.data,null,2)})}function An({workspaceId:e,documentId:t}){let[n,r]=(0,Z.useState)(null),[i,a]=(0,Z.useState)(``),[o,s]=(0,Z.useState)({}),[c,l]=(0,Z.useState)(null),u=(0,Z.useCallback)(async()=>{try{let n=await gt(e,t);r(n),a(``)}catch(e){a(e instanceof Error?e.message:`Could not load thread`)}},[e,t]);return(0,Z.useEffect)(()=>{let n=!0;gt(e,t).then(e=>{n&&(r(e),a(``))}).catch(e=>{n&&a(e instanceof Error?e.message:`Could not load thread`)});let i=()=>{u()};return window.addEventListener(`workspace:documents:refresh`,i),window.addEventListener(ct,i),()=>{n=!1,window.removeEventListener(`workspace:documents:refresh`,i),window.removeEventListener(ct,i)}},[e,t,u]),i?(0,Q.jsxs)(`div`,{className:`p-3`,children:[(0,Q.jsx)(`p`,{role:`alert`,className:`text-sm text-destructive`,children:i}),(0,Q.jsx)(K,{variant:`outline`,size:`sm`,onClick:()=>void u(),children:`Retry`})]}):!n||n.documentId!==t?(0,Q.jsx)(`p`,{className:`p-3 text-sm text-muted-foreground`,children:`Loading thread…`}):(0,Q.jsxs)(`section`,{"aria-label":`Message thread`,className:`space-y-3 p-2`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,Q.jsxs)(`h3`,{className:`text-sm font-medium`,children:[`Thread · `,n.documents.length,` message`,n.documents.length===1?``:`s`]}),(0,Q.jsx)(K,{size:`sm`,variant:`outline`,onClick:()=>void u(),children:`Refresh`})]}),n.documents.length===1&&(0,Q.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`No linked replies have been indexed. Other messages in this conversation are separate from this reply thread.`}),n.truncated&&(0,Q.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`Showing up to 200 linked messages.`}),n.documents.map(r=>{let i=fe(r),a=r.schema===`data/schema/message/email`,c=a||[`slack`,`whatsapp`].includes(String(r.data.platform)),u=r.data.timestamp||r.data.date,d=u?new Date(String(u)):null,f=(n.parents[r.id]||[]).flatMap(e=>{let t=n.documents.find(t=>Number(t.id)===e);return t?[fe(t).title]:[]}),p=o[Number(r.id)]??Number(r.id)===t;return(0,Q.jsxs)(`details`,{open:p,onToggle:e=>{let t=e.currentTarget.open;s(e=>e[Number(r.id)]===t?e:{...e,[Number(r.id)]:t})},className:`rounded-lg border bg-card`,children:[(0,Q.jsxs)(`summary`,{className:`cursor-pointer space-y-1 p-3 text-sm`,children:[(0,Q.jsx)(`span`,{className:`font-medium`,children:i.title}),(0,Q.jsxs)(`span`,{className:`block text-xs text-muted-foreground`,children:[i.subtitle,d&&!Number.isNaN(d.getTime())?` · ${d.toLocaleString()}`:``]}),f.length>0&&(0,Q.jsxs)(`span`,{className:`block text-xs text-muted-foreground`,children:[`Reply to `,f.join(`, `)]})]}),p&&c&&(0,Q.jsx)(`div`,{className:`flex flex-wrap gap-2 px-3 pb-2`,children:(a?[`reply`,`replyAll`,`forward`]:[`reply`]).map(e=>(0,Q.jsx)(K,{variant:`outline`,size:`sm`,onClick:()=>l({document:r,mode:e}),children:e===`replyAll`?`Reply all`:e===`forward`?`Forward`:`Reply`},e))}),p&&(0,Q.jsx)(kn,{workspaceId:e,document:r})]},r.id)}),c&&(0,Q.jsx)(vt,{workspaceId:e,replyToDocumentId:Number(c.document.id),mode:c.mode,originalSubject:typeof c.document.data.subject==`string`?c.document.data.subject:void 0,onClose:()=>l(null)},`${c.document.id}:${c.mode}`)]})}function jn(e,t){return e.slice(0,3).map(e=>{let n=t.get(e.id),r=e.reason===`not-found`?`Source missing from the storage index. Resync the source backend and retry.`:e.reason===`not found`?`Document no longer exists in this workspace. Refresh the list and select it again.`:e.reason;return`${n?`${n} (ID ${e.id})`:`Document ${e.id}`}: ${r}`}).join(`
|
|
8
|
-
`)+(e.length>3?`\n…and ${e.length-3} more failed file${e.length===4?``:`s`}.`:``)}var Mn=e(i(),1),Nn=[{mode:`copy`,label:`Copy to`,icon:(0,Q.jsx)(x,{className:`h-3.5 w-3.5`})},{mode:`move`,label:`Move to`,icon:(0,Q.jsx)(M,{className:`h-3.5 w-3.5`})},{mode:`delete`,label:`Delete from`,icon:(0,Q.jsx)(w,{className:`h-3.5 w-3.5`})}],Pn=[{value:`rename`,label:`Rename mine (file-1.ext)`},{value:`overwrite`,label:`Overwrite the existing file`},{value:`error`,label:`Skip the document`}],Fn=`h-9 w-full rounded-md border bg-background px-2 text-xs outline-none focus:ring-2 focus:ring-ring disabled:opacity-50`;function In(e){return e.driver===`cacache`?k:e.config?.remote===!0?v:s}function Ln({workspaceId:e,documentCount:t,initialMode:n=`copy`,defaultFilename:r=``,onConfirm:i,onClose:a,saving:o=!1,sizeClassName:c,deleteFrom:l,progress:u,stopping:d=!1,onStop:f}){let{showErrorToast:p}=X(),[g,_]=(0,Z.useState)(!1);mt(a,!o&&!g);let[v,y]=(0,Z.useState)(n),[b,S]=(0,Z.useState)(null),[C,T]=(0,Z.useState)(null),[E,D]=(0,Z.useState)(()=>new Set(n===`delete`&&l?[l.backend]:[])),[O,k]=(0,Z.useState)(!1),[A,j]=(0,Z.useState)(``),[N,P]=(0,Z.useState)(r),[F,ee]=(0,Z.useState)(`rename`);(0,Z.useEffect)(()=>{let t=!1;return Le(e).then(e=>{if(t)return;S(e.filter(e=>e.kind===`storage`));let n=new Set(e.filter(e=>e.kind===`storage`&&e.enabled!==!1&&e.config?.readOnly!==!0&&e.config?.supported!==!1).map(e=>e.address));D(e=>new Set([...e].filter(e=>n.has(e))))}).catch(e=>{t||T(e instanceof Error?e.message:String(e))}),()=>{t=!0}},[e]);let I=v===`move`,L=e=>e.enabled===!1?`disabled`:e.config?.readOnly===!0?`read-only`:e.config?.supported===!1?`unsupported`:null,te=(0,Z.useMemo)(()=>(b||[]).filter(e=>!L(e)).map(e=>e.address),[b,v]),ne=e=>{y(e),D(t=>{let n=(b||[]).filter(e=>e.enabled!==!1&&e.config?.readOnly!==!0&&e.config?.supported!==!1).map(e=>e.address),r=[...t].filter(e=>n.includes(e));return new Set(e===`move`?r.slice(0,1):r)})},R=e=>{D(t=>{if(I)return t.has(e)?new Set:new Set([e]);let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},z=(0,Z.useMemo)(()=>(b||[]).filter(e=>E.has(e.address)&&Ne(e)),[b,E]),B=v!==`delete`&&z.length>0,V=e=>{let t=ke(e,b||[]),n=t&&b?.find(e=>e.address===t.address);return!!n&&!L(n)&&v!==`delete`&&!o},H=async(t,n)=>{let r=ke(t,b||[]);if(!r||!V(t))throw Error(`Choose a writable file backend folder`);await Me(e,r.driver,r.address,[[r.key,n].filter(Boolean).join(`/`)])},ie=e=>{_(!1);let t=Oe(e[0]||``,b||[]),n=t?(b||[]).find(e=>e.address===t.address):null;if(!t||!n){p(`Pick a folder inside a storage backend`);return}if(L(n)){p(`${n.address} is ${L(n)}`);return}if(!Ne(n)){p(`${n.address} does not keep folders — objects are stored by content`);return}j(t.key),D(e=>I?new Set([t.address]):new Set([...e,t.address]))},ae=async()=>{E.size===0||o||await i([...E],v,{keepDocument:O,folder:B?A.trim():``,filename:B&&t===1?N.trim():``,onConflict:F})},U=t,W=U===1?``:`s`,oe=v===`delete`?`Delete ${U} document${W} from…`:`${v===`move`?`Move`:`Copy`} ${U} document${W} to…`,q=v===`delete`?`Delete from`:v===`move`?`Move to`:`Copy to`,J=E.size===0?q.split(` `)[0]:`${q} ${E.size} backend${E.size===1?``:`s`}`;return(0,Q.jsxs)(`div`,{className:G(`flex flex-col overflow-hidden rounded-(--panel-radius) border bg-card shadow-elevation-4`,c||`max-h-viewport-card w-[min(420px,90vw)] max-md:h-full max-md:w-full max-md:shadow-elevation-5`),children:[(0,Q.jsxs)(`div`,{className:`flex h-12 shrink-0 items-center justify-between border-b px-4`,children:[(0,Q.jsxs)(`span`,{className:`flex items-center gap-2 text-sm font-medium`,children:[(0,Q.jsx)(s,{className:`h-4 w-4`}),oe]}),(0,Q.jsx)(`button`,{type:`button`,onClick:a,disabled:o,className:`text-muted-foreground transition-colors hover:text-foreground disabled:opacity-40`,"aria-label":`Close`,children:(0,Q.jsx)(h,{className:`h-4 w-4`})})]}),(0,Q.jsx)(`div`,{className:`flex shrink-0 items-center gap-1 border-b px-2 pt-2`,children:Nn.map(({mode:e,label:t,icon:n})=>(0,Q.jsxs)(`button`,{type:`button`,onClick:()=>ne(e),disabled:o,className:G(`flex items-center gap-1.5 rounded-t-md border-b-2 px-3 py-2 text-xs font-medium transition-colors disabled:opacity-50`,v===e?e===`delete`?`border-destructive text-destructive`:`border-primary text-foreground`:`border-transparent text-muted-foreground hover:text-foreground`),children:[n,t]},e))}),(0,Q.jsxs)(`div`,{className:`min-h-0 flex-1 space-y-1.5 overflow-y-auto p-3`,children:[C&&(0,Q.jsx)(`p`,{className:`px-2 py-1.5 text-xs text-destructive`,children:C}),!b&&!C&&(0,Q.jsx)(`div`,{className:`px-2 py-3 text-xs text-muted-foreground`,children:`Loading backends…`}),b?.length===0&&(0,Q.jsx)(`p`,{className:`px-2 py-1.5 text-xs text-muted-foreground`,children:`No storage backends configured.`}),b?.map(e=>{let t=In(e),n=L(e),r=E.has(e.address),i=e.config?.remote===!0;return(0,Q.jsxs)(`div`,{onClick:()=>!n&&!o&&R(e.address),className:G(`group relative flex min-h-10 items-center gap-2 rounded-md px-3 py-2 text-sm shadow-elevation-1 transition-all select-none`,`before:absolute before:left-0 before:top-0 before:bottom-0 before:w-1.5 before:transition-colors`,n?`cursor-not-allowed bg-muted/40 opacity-60 before:bg-transparent`:`cursor-pointer hover:shadow`,!n&&r?v===`delete`?`bg-destructive/[0.08] hover:bg-destructive/[0.12] before:bg-destructive`:`bg-primary/[0.08] hover:bg-primary/[0.12] before:bg-primary`:n?``:`bg-card hover:bg-primary/[0.04] before:bg-transparent`),title:e.address,children:[(0,Q.jsx)(`input`,{type:I?`radio`:`checkbox`,checked:r,disabled:!!n||o,onChange:()=>R(e.address),onClick:e=>e.stopPropagation(),className:`h-4 w-4 shrink-0 accent-primary`,"aria-label":e.address}),(0,Q.jsx)(t,{className:`h-4 w-4 shrink-0 text-muted-foreground`}),(0,Q.jsxs)(`span`,{className:`min-w-0 flex-1`,children:[(0,Q.jsx)(`span`,{className:`block truncate font-medium`,children:e.config?.label||e.address}),(0,Q.jsxs)(`span`,{className:`block truncate font-mono text-[10px] text-muted-foreground`,children:[e.driver,` · `,e.address]})]}),i&&(0,Q.jsx)(`span`,{className:`shrink-0 rounded bg-info-subtle px-1.5 py-0.5 text-[10px] uppercase text-muted-foreground`,title:`Network mount${e.config?.transport?` (${e.config.transport})`:``} — transfers cross the network`,children:e.config?.transport||`remote`}),n&&(0,Q.jsx)(`span`,{className:`shrink-0 rounded bg-muted px-1.5 py-0.5 text-[10px] uppercase text-muted-foreground`,children:n})]},`${e.driver}/${e.address}`)}),v===`delete`&&(0,Q.jsxs)(`label`,{className:`mt-3 flex cursor-pointer items-start gap-2 rounded-md border border-destructive/30 bg-destructive/5 px-3 py-2 text-xs`,children:[(0,Q.jsx)(`input`,{type:`checkbox`,checked:O,onChange:e=>k(e.target.checked),disabled:o,className:`mt-0.5 h-3.5 w-3.5 accent-destructive`}),(0,Q.jsxs)(`span`,{children:[`Keep the index entry when its `,(0,Q.jsx)(`strong`,{children:`last`}),` copy is deleted.`,(0,Q.jsx)(`span`,{className:`block text-muted-foreground`,children:`Otherwise the document moves to workspace Trash once no locations remain.`})]})]}),B&&(0,Q.jsxs)(`div`,{className:`mt-3 space-y-2 rounded-md border px-3 py-2`,children:[(0,Q.jsxs)(`p`,{className:`text-xs font-medium`,children:[`Destination on `,z.map(e=>e.config?.label||e.address).join(`, `)]}),(0,Q.jsxs)(`div`,{className:`space-y-1`,children:[(0,Q.jsx)(`label`,{htmlFor:`backend-transfer-folder`,className:`text-[11px] text-muted-foreground`,children:`Folder (relative to the backend root)`}),(0,Q.jsxs)(`div`,{className:`flex gap-1.5`,children:[(0,Q.jsx)(se,{id:`backend-transfer-folder`,value:A,onChange:e=>j(e.target.value),placeholder:`/`,disabled:o,className:`h-9 font-mono text-xs`}),(0,Q.jsx)(K,{type:`button`,variant:`outline`,size:`icon`,className:`h-9 w-9 shrink-0`,onClick:()=>_(!0),disabled:o,"aria-label":`Browse backend folders`,title:`Browse…`,children:(0,Q.jsx)(re,{className:`h-4 w-4`})})]})]}),t===1?(0,Q.jsxs)(`div`,{className:`space-y-1`,children:[(0,Q.jsx)(`label`,{htmlFor:`backend-transfer-filename`,className:`text-[11px] text-muted-foreground`,children:`File name`}),(0,Q.jsx)(se,{id:`backend-transfer-filename`,value:N,onChange:e=>P(e.target.value),placeholder:r||`keeps the document's own name`,disabled:o,className:`h-9 font-mono text-xs`})]}):(0,Q.jsx)(`p`,{className:`text-[11px] text-muted-foreground`,children:`Each document keeps its own file name and extension.`}),(0,Q.jsxs)(`div`,{className:`space-y-1`,children:[(0,Q.jsx)(`label`,{htmlFor:`backend-transfer-conflict`,className:`text-[11px] text-muted-foreground`,children:`If a different file already has that name`}),(0,Q.jsx)(`select`,{id:`backend-transfer-conflict`,className:Fn,value:F,onChange:e=>ee(e.target.value),disabled:o,children:Pn.map(e=>(0,Q.jsx)(`option`,{value:e.value,children:e.label},e.value))})]})]}),v===`move`&&te.length>0&&(0,Q.jsx)(`p`,{className:`px-1 pt-2 text-[11px] text-muted-foreground`,children:`The source copy is released only once the destination write is durable.`})]}),o&&u&&(0,Q.jsxs)(`div`,{role:`status`,className:`flex items-center justify-between gap-2 border-t px-4 py-2 text-xs`,children:[(0,Q.jsxs)(`span`,{children:[d?`Stopping after current file`:`Processing`,` · `,u.completed,`/`,u.total]}),f&&(0,Q.jsx)(K,{size:`sm`,variant:`outline`,onClick:f,disabled:d,children:`Stop`})]}),(0,Q.jsxs)(`div`,{className:`flex shrink-0 items-center justify-between gap-2 border-t px-4 py-3`,children:[(0,Q.jsxs)(`span`,{className:`text-xs text-muted-foreground`,children:[E.size,` backend`,E.size===1?``:`s`,` selected`]}),(0,Q.jsx)(K,{size:`sm`,variant:v===`delete`?`destructive`:`default`,onClick:ae,disabled:E.size===0||o,children:o?(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(ce,{className:`mr-1.5 h-3.5 w-3.5`}),`Working…`]}):(0,Q.jsxs)(Q.Fragment,{children:[v===`delete`?(0,Q.jsx)(w,{className:`mr-1 h-3.5 w-3.5`}):v===`move`?(0,Q.jsx)(M,{className:`mr-1 h-3.5 w-3.5`}):(0,Q.jsx)(x,{className:`mr-1 h-3.5 w-3.5`}),J]})})]}),v===`delete`&&(0,Q.jsxs)(`div`,{className:`flex items-start gap-2 border-t bg-destructive/5 px-4 py-2 text-[11px] text-muted-foreground`,children:[(0,Q.jsx)(m,{className:`mt-0.5 h-3.5 w-3.5 shrink-0 text-destructive`}),(0,Q.jsx)(`span`,{children:l&&E.has(l.backend)?`Deletes selected files in ${l.backend}/${l.folder}. Copies in other folders are kept.${E.size>1?` Other selected backends are also targeted.`:` Copies on other backends are kept.`}`:`Deletes the file data from the selected backends. Copies on other backends are untouched.`})]}),g&&(0,Q.jsx)(yt,{onClose:()=>_(!1),children:(0,Q.jsx)(de,{sizeClassName:`h-full w-[380px] max-w-[90vw] max-md:w-full`,multiple:!1,tabs:[`backends`],fixedWorkspaceName:e,title:`Pick a destination folder…`,confirmLabel:`Use folder`,backendFolderCreation:{canCreate:V,create:H},onConfirm:ie,onClose:()=>_(!1)})})]})}var Rn={exif:`from the photo's EXIF`,device:`from the device at capture`,manual:`placed by hand`};function zn(e){let t=`${e.lat.toFixed(5)}, ${e.lon.toFixed(5)}`,n=e.source?Rn[e.source]:null;return[t,e.accuracy==null?null:`±${e.accuracy} m`,n].filter(Boolean).join(` · `)}function Bn({value:e,onChange:t,idPrefix:n=`edit-geo`}){let[r,i]=(0,Z.useState)(!1);return(0,Q.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Q.jsx)(q,{htmlFor:`${n}-action`,children:`Location`}),(0,Q.jsxs)(`div`,{className:`flex items-center justify-between gap-3`,children:[(0,Q.jsxs)(`span`,{className:`flex min-w-0 items-center gap-2 text-xs`,children:[(0,Q.jsx)(ae,{className:e?`h-4 w-4 shrink-0 text-info`:`h-4 w-4 shrink-0 text-muted-foreground`}),(0,Q.jsx)(`span`,{className:e?`truncate tabular-nums`:`truncate text-muted-foreground`,children:e?zn(e):`No location on this document`})]}),(0,Q.jsxs)(`span`,{className:`flex shrink-0 items-center gap-1`,children:[(0,Q.jsxs)(`button`,{id:`${n}-action`,type:`button`,onClick:()=>i(!0),className:`inline-flex items-center gap-1.5 rounded-md border border-border px-2 py-1 text-xs text-muted-foreground transition-colors hover:bg-muted hover:text-foreground`,children:[(0,Q.jsx)(z,{className:`h-3.5 w-3.5`}),e?`Move pin`:`Set on map`]}),e&&(0,Q.jsx)(`button`,{type:`button`,onClick:()=>t(null),"aria-label":`Remove location`,title:`Remove location`,className:`rounded p-1 text-muted-foreground hover:bg-muted hover:text-foreground`,children:(0,Q.jsx)(w,{className:`h-3.5 w-3.5`})})]})]}),r&&(0,Q.jsx)(We,{initial:e,onPick:e=>t({lat:e.lat,lon:e.lon,source:`manual`}),onClose:()=>i(!1)})]})}function Vn(e){return e===`data/schema/note`||e===`data/schema/link`||e===`data/schema/tab`||e===`data/schema/task`||e===`data/schema/drawing`||e===`data/schema/identity`||e.startsWith(`data/schema/identity/`)}function Hn(e){return Vn(e.schema)||Ze(e)}function Un(e){return e===`data/schema/link`?{urlKey:`uri`,titleKey:`label`}:e===`data/schema/tab`?{urlKey:`url`,titleKey:`title`}:{urlKey:null,titleKey:`title`}}async function Wn(e,t,n){try{let r=new Set(n.map(e=>e.identityId).filter(Boolean)),i=await Te(e,t,{resolve:!1}),a=new Set(i.outgoing.filter(e=>e.p===`member-of`).map(e=>e.to));for(let n of r)a.has(n)||await Ee(e,t,`member-of`,[n]);for(let n of a)r.has(n)||await we(e,t,`member-of`,n)}catch(e){console.error(`Failed to sync organization relations`,e)}}function Gn({document:e,workspaceId:t,onClose:n}){let{showSuccessToast:r,showErrorToast:i}=X(),a=Vn(e.schema),o=e.schema===`data/schema/file`,[s,c]=(0,Z.useState)(()=>Y(e)),l=!o||!!s.trim()&&!/[\\/]/.test(s)&&!Array.from(s).some(e=>e.charCodeAt(0)<32)&&s!==`.`&&s!==`..`,u=e.schema===pe,d=Ze(e),f=et(e)??`markdown`,p=d&&Xe(e),m=e.schema===ge,h=e.schema===`data/schema/identity`||e.schema.startsWith(`data/schema/identity/`),{urlKey:g,titleKey:_}=Un(e.schema),[v,y]=(0,Z.useState)(g?String(e.data?.[g]??``):``),[b,x]=(0,Z.useState)(String(e.data?.[_]??``)),[S,C]=(0,Z.useState)(String(e.data?.content??``)),[w,T]=(0,Z.useState)(String(e.data?.description??``)),[E,D]=(0,Z.useState)(e.data?.status??`pending`),[O,k]=(0,Z.useState)(typeof e.data?.priority==`number`?e.data.priority:``),[A,j]=(0,Z.useState)(e.data?.dueDate?ft(String(e.data.dueDate)):ut()),M=He(Ge(e)),[N,P]=(0,Z.useState)(String(e.comment??``)),F=e.metadata?.geo??null,[ee,I]=(0,Z.useState)(F),L=e.features??e.metadata?.features,[te,ne]=(0,Z.useState)(ot(L).length?ot(L):e.data?.tags??[]),R=xt(e,t,u),{title:z,content:B,comment:V,tags:H,geo:re,setTitle:ie,setContent:ae,setComment:U,setTags:W,setGeo:oe}=u?R:{title:b,content:S,comment:N,tags:te,geo:ee,setTitle:x,setContent:C,setComment:P,setTags:ne,setGeo:I},G=JSON.stringify(re??null)!==JSON.stringify(F??null),J=$e(t,e.id,{mode:`text`,enabled:d&&!p,maxTextLength:Qe,version:e.checksumArray?.[0]??null}),[ce,le]=(0,Z.useState)(null),ue=`${e.id}:${e.checksumArray?.[0]??``}`;d&&J.text!=null&&ce!==ue&&(le(ue),ae(J.text));let[de,fe]=(0,Z.useState)([]),[me,he]=(0,Z.useState)(!1),{replicating:_e,mirror:ve}=Ie(e);(0,Z.useEffect)(()=>{let e=!1;return De(t).then(t=>{e||fe(t)}).catch(()=>{}),()=>{e=!0}},[t]);let ye=!g||(()=>{try{return new URL(v.trim()),!0}catch{return!1}})(),be=!me&&l&&(d?!p&&J.text!=null&&!J.loading:a?h?M.displayName.trim().length>0&&M.emailValid:m?z.trim().length>0:u?R.canSave:ye:!0),Se=async()=>{he(!0);let c=[...(L||[]).filter(e=>!e.startsWith(`tag/`)),...at(H)];try{if(u){await R.save(),n();return}if(d){let i=await nt(t,e,B,{comment:V.trim(),metadata:{features:c,...o?{filename:s.trim()}:{},...G?{geo:re}:{}}});r(`Document updated`),window.dispatchEvent(new CustomEvent(`workspace:documents:refresh`)),n(i);return}let i={id:e.id,schema:e.schema,schemaVersion:e.schemaVersion,comment:V.trim(),metadata:{features:c,...o?{filename:s.trim()}:{}}};if(h){let{type:t,...n}=e.data??{};i.schema=`${xe}/${M.values.type}`,i.data={...n,...Ue(M.values)}}else if(m)i.data={...e.data,...lt({title:z,description:w,status:E,priority:O,due:A})};else if(a){let t=H.map(e=>e.trim()).filter(Boolean),n;u?n={...z.trim()?{title:z.trim()}:{},content:B}:(n={...e.data},g&&(n[g]=v.trim()),z.trim()?n[_]=z.trim():delete n[_],n.tags=t),i.data=n}G&&(i.metadata={...i.metadata??{},geo:re}),await Fe(t,i),h&&(await Wn(t,e.id,M.values.organizations),st()),r(`Document updated`),window.dispatchEvent(new CustomEvent(`workspace:documents:refresh`)),n()}catch(e){i(e instanceof Error?e.message:`Failed to update document`)}finally{he(!1)}};return(0,Q.jsxs)(`div`,{className:`flex flex-col gap-4`,children:[o&&(0,Q.jsxs)(`div`,{className:`space-y-2`,children:[(0,Q.jsx)(q,{htmlFor:`file-name`,children:`File name`}),(0,Q.jsx)(se,{id:`file-name`,value:s,onChange:e=>c(e.target.value)}),(0,Q.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`Changes the object’s name; storage locations stay the same.`})]}),a&&g&&(0,Q.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Q.jsx)(q,{htmlFor:`edit-url`,children:`URL`}),(0,Q.jsx)(se,{id:`edit-url`,value:v,onChange:e=>y(e.target.value),placeholder:`https://example.com`,className:`font-mono text-xs`}),v.trim()&&!ye&&(0,Q.jsx)(`p`,{className:`text-xs text-destructive`,children:`Enter a valid URL, e.g. https://example.com`})]}),a&&h&&(0,Q.jsx)(qe,{idPrefix:`edit-identity`,workspaceName:t,...M,emailValid:M.emailValid}),a&&m&&(0,Q.jsx)(Be,{idPrefix:`edit-todo`,title:z,setTitle:ie,description:w,setDescription:T,status:E,setStatus:D,priority:O,setPriority:k,due:A,setDue:j}),a&&!m&&!h&&(0,Q.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Q.jsx)(q,{htmlFor:`edit-title`,children:`Title`}),(0,Q.jsx)(se,{id:`edit-title`,value:z,onChange:e=>ie(e.target.value),placeholder:u?`Optional; defaults to today's date`:`Optional display title`})]}),(u||d)&&(0,Q.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Q.jsx)(q,{children:`Body`}),p?(0,Q.jsxs)(`p`,{className:`text-xs text-muted-foreground`,children:[`This file is too large to edit here (`,`>`,1e3,` kB) — download it instead.`]}):d&&J.error?(0,Q.jsx)(`p`,{className:`text-xs text-destructive`,children:J.error}):d&&J.text==null?(0,Q.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`Loading content…`}):(0,Q.jsx)(St,{kind:u?`markdown`:f,value:B,onChange:ae,placeholder:u?`Write your note…`:void 0})]}),(0,Q.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Q.jsx)(q,{children:`Tags`}),(0,Q.jsx)(Ke,{tags:H,onChange:W,suggestions:de})]}),(0,Q.jsx)(Bn,{value:re,onChange:oe}),(0,Q.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Q.jsx)(q,{htmlFor:`edit-comment`,children:`Comment`}),(0,Q.jsx)(`textarea`,{id:`edit-comment`,value:V,onChange:e=>U(e.target.value),rows:3,placeholder:`Add context you can't infer from the content, e.g. “sofa from the cozmo bar in Košice”`,className:`flex w-full rounded-md border border-input bg-transparent px-3 py-2 text-sm shadow-elevation-1 transition-colors placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-50`})]}),u&&(0,Q.jsx)(bt,{...R,onRetry:R.save}),(0,Q.jsxs)(`div`,{className:`flex justify-end gap-2 pt-2`,children:[(0,Q.jsx)(K,{variant:`outline`,size:`sm`,onClick:()=>n(),disabled:me,children:u?`Close`:`Cancel`}),(0,Q.jsx)(K,{size:`sm`,onClick:Se,disabled:!be,children:me?_e?`Replicating to ${ve.label}…`:`Saving…`:`Save changes`})]})]})}var Kn=(0,Z.createContext)(null),qn={entry:null,open:()=>{},close:()=>{}};function Jn(){return(0,Z.useContext)(Kn)??qn}var Yn=`main`,Xn=(0,Z.createContext)(null);function Zn(){return(0,Z.useContext)(Xn)}var Qn=50;function $n({relation:e,workspaceId:t,direction:n,onRemove:r,removing:i}){let{open:a}=Ct(),o=Jn(),s=Zn(),c=n===`out`?e.to:e.from,l=e.document??null,u=l?fe(l).title:``,[d,f]=(0,Z.useState)(!1),{showErrorToast:p}=X(),m=async()=>{if(!(c==null||!l)){f(!0);try{let n=e.preview?await Pe(t,c):l;s?o.open(n,t):a(n,t)}catch(e){p(e instanceof Error?e.message:`Failed to open document`)}finally{f(!1)}}},h=!e.meta||e.meta.src===`doc`;return(0,Q.jsxs)(`div`,{className:`group flex items-center gap-2 rounded-md px-2 py-1.5 text-sm hover:bg-muted/60`,children:[n===`out`?(0,Q.jsx)(M,{className:`h-3.5 w-3.5 shrink-0 text-muted-foreground`}):(0,Q.jsx)(V,{className:`h-3.5 w-3.5 shrink-0 text-muted-foreground`}),l?(0,Q.jsx)(ht,{document:l,size:3.5}):null,l?(0,Q.jsx)(`button`,{type:`button`,onClick:()=>void m(),disabled:d,className:`min-w-0 flex-1 truncate text-left hover:underline`,title:u,children:u}):(0,Q.jsxs)(`span`,{className:`min-w-0 flex-1 truncate italic text-muted-foreground`,children:[`Document `,c,` (not available)`]}),(0,Q.jsxs)(`span`,{className:`shrink-0 font-mono text-[10px] text-muted-foreground`,children:[`#`,c]}),!h&&(0,Q.jsx)(`span`,{className:`shrink-0 rounded-full bg-muted px-1.5 py-0.5 text-[10px] text-muted-foreground`,title:`Derived by ${e.meta?.src}`,children:e.meta?.src}),h&&(0,Q.jsx)(`button`,{type:`button`,onClick:r,disabled:i,className:`shrink-0 rounded p-1 text-muted-foreground opacity-0 transition-opacity hover:bg-destructive/10 hover:text-destructive group-hover:opacity-100 disabled:opacity-40`,title:`Remove relation`,"aria-label":`Remove relation`,children:(0,Q.jsx)(w,{className:`h-3.5 w-3.5`})})]})}function er({document:e,workspaceId:t}){let{showSuccessToast:n,showErrorToast:r}=X(),[i,a]=(0,Z.useState)(null),[o,s]=(0,Z.useState)(null),[c,l]=(0,Z.useState)(!1),[u,d]=(0,Z.useState)(!1),[f,p]=(0,Z.useState)(null),[m,h]=(0,Z.useState)(0),[g,_]=(0,Z.useState)(1),v=(0,Z.useRef)(0),y=(0,Z.useCallback)(()=>{v.current++},[]),x=(0,Z.useCallback)(async()=>{let n=++v.current;try{let r=await Te(t,e.id,{offset:m*Qn,limit:Qn,summary:!0});if(n!==v.current)return;let i=Math.max(0,Math.ceil(Math.max(r.outgoingCount??r.outgoing.length,r.incomingCount??r.incoming.length)/Qn)-1);if(_(i+1),m>i){h(i);return}a(r),s(null)}catch(e){if(n!==v.current)return;s(e instanceof Error?e.message:String(e))}},[t,e.id,m]),S=`${t}:${e.id}`,[C,w]=(0,Z.useState)(S);S!==C&&(w(S),a(null),s(null),h(0),_(1)),(0,Z.useEffect)(()=>{async function e(){await x()}return e(),window.addEventListener(ct,e),()=>{y(),window.removeEventListener(ct,e)}},[x,y]);let T=async(i,a)=>{let o=a===`out`?i.to:i.from;if(o==null)return;let s=`${a}:${i.p}:${o}`;p(s);try{await we(t,e.id,i.p,o,a),n(`Relation removed`),st()}catch(e){r(e instanceof Error?e.message:`Failed to remove relation`)}finally{p(null)}},E=[{dir:`out`,title:`Points at`,hint:`this document as the subject`,entries:i?.outgoing??[]},{dir:`in`,title:`Pointed at by`,hint:`this document as the object`,entries:i?.incoming??[]}],D=e=>{a(null),h(e)};return(0,Q.jsxs)(`div`,{children:[(0,Q.jsxs)(`div`,{className:`mb-2 flex items-center justify-between gap-2`,children:[(0,Q.jsx)(`h3`,{className:`font-semibold`,children:`Documents`}),(0,Q.jsxs)(K,{variant:`outline`,size:`sm`,onClick:()=>l(!0),children:[(0,Q.jsx)(b,{className:`mr-1 h-3 w-3`}),` Add relation`]})]}),o?(0,Q.jsx)(`p`,{className:`text-sm text-destructive`,children:o}):i?E.every(e=>e.entries.length===0)?(0,Q.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`No related documents.`}):(0,Q.jsx)(`div`,{className:`space-y-4`,children:E.filter(e=>e.entries.length>0).map(({dir:e,title:n,hint:r,entries:i})=>(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`p`,{className:`mb-1 text-xs font-medium text-muted-foreground`,title:r,children:n}),Array.from(new Set(i.map(e=>e.p))).map(n=>(0,Q.jsxs)(`div`,{className:`mb-2`,children:[(0,Q.jsx)(`p`,{className:`px-2 font-mono text-[11px] text-muted-foreground`,children:n}),i.filter(e=>e.p===n).map(n=>{let r=e===`out`?n.to:n.from,i=`${e}:${n.p}:${r}`;return(0,Q.jsx)($n,{relation:n,workspaceId:t,direction:e,removing:f===i,onRemove:()=>void T(n,e)},i)})]},n))]},e))}):(0,Q.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`Loading relations…`}),(g>1||m>0)&&(0,Q.jsxs)(`div`,{className:`mt-3 flex items-center justify-between gap-2 text-xs text-muted-foreground`,children:[(0,Q.jsx)(K,{variant:`outline`,size:`sm`,disabled:m===0,onClick:()=>D(m-1),children:`Previous`}),(0,Q.jsxs)(`span`,{children:[`Page `,m+1,` of `,g]}),(0,Q.jsx)(K,{variant:`outline`,size:`sm`,disabled:!i||m+1>=g,onClick:()=>D(m+1),children:`Next`})]}),c&&(0,Q.jsx)(yt,{onClose:()=>{u||l(!1)},children:(0,Q.jsx)(de,{sizeClassName:`h-full w-[380px] max-w-[90vw] max-md:w-full`,title:`Relate to…`,tabs:[`relations`],fixedWorkspaceName:t,documentCount:1,saving:u,relationPredicates:i?.predicates,relationExcludeIds:new Set([e.id]),onClose:()=>l(!1),onConfirm:()=>{},onConfirmRelation:async({predicate:i,direction:a,targetIds:o})=>{d(!0);try{await Ee(t,e.id,i,o,a),n(`Related to ${o.length} document${o.length===1?``:`s`}`),l(!1),st()}catch(e){r(e instanceof Error?e.message:`Failed to create relation`)}finally{d(!1)}}})})]})}var tr=(0,Z.lazy)(()=>a(()=>import(`./TextDocumentEditor-CU5ersd_.js`),__vite__mapDeps([2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,1,24]))),nr={reply:`Reply`,replyAll:`Reply all`,forward:`Forward`},rr={reply:d,replyAll:u,forward:f};function ir({document:e,workspaceId:t,initialEdit:n=!1,onChanged:r}){let i=Je()!=null,{showErrorToast:a,showSuccessToast:o}=X(),[s,l]=(0,Z.useState)(!1),u=e.data?.url||e.data?.uri,d=e.schema!==`data/schema/file`&&typeof u==`string`&&/^https?:\/\//i.test(u),[f,m]=(0,Z.useState)(!1),h=[`data/schema/message`,`data/schema/message/email`].includes(e.schema),[g,_]=(0,Z.useState)(null),v=e.schema===`data/schema/message/email`,y=!i&&(v||[`slack`,`whatsapp`].includes(String(e.data?.platform))),b=v?[`reply`,`replyAll`,`forward`]:[`reply`],x=e=>_(t=>t===e?null:e),S=!i,[C,w]=(0,Z.useState)(n&&!i),T=e.schema===be,[E,O]=(0,Z.useState)(!1),k=e.schema===`data/schema/note`||Ze(e),[A,j]=(0,Z.useState)(!1),M=`${t}:${e.id}:${n}:${i}`,[N,P]=(0,Z.useState)(M);M!==N&&(P(M),w(n&&!i),_(null),m(!1),O(!1),j(!1));let F=t=>{if(!S||!Hn(e)||t.defaultPrevented)return!1;let n=t.target;return n instanceof Element&&t.currentTarget.contains(n)&&!n.closest(`a, button, input, textarea, select, label, summary, audio, video, [role="button"], [role="checkbox"], [contenteditable]:not([contenteditable="false"])`)};return C&&S?(0,Q.jsx)(Gn,{document:e,workspaceId:t,onClose:e=>{w(!1),r?.(e)}}):(0,Q.jsxs)(`div`,{className:`flex h-full min-h-0 flex-col gap-3`,children:[S&&(0,Q.jsxs)(`div`,{className:`flex shrink-0 justify-end gap-2`,children:[h&&(0,Q.jsx)(K,{size:`sm`,variant:f?`secondary`:`outline`,onClick:()=>m(!f),children:f?`Show message`:`View thread`}),y&&b.map(e=>{let t=rr[e];return(0,Q.jsxs)(K,{size:`sm`,variant:g===e?`secondary`:`outline`,onClick:()=>x(e),children:[(0,Q.jsx)(t,{className:`mr-1.5 h-3.5 w-3.5`}),nr[e]]},e)}),d&&(0,Q.jsxs)(K,{variant:`outline`,size:`sm`,disabled:s,onClick:async()=>{l(!0);try{await ye(t,e.id),window.dispatchEvent(new CustomEvent(`workspace:documents:refresh`)),r?.(),o(`File saved to workspace; the original link is preserved`)}catch(e){a(e instanceof Error?e.message:String(e))}finally{l(!1)}},children:[(0,Q.jsx)(U,{className:`mr-1 h-3 w-3`}),s?`Downloading…`:`Download to workspace`]}),e.schema===`data/schema/file`&&(0,Q.jsxs)(K,{variant:`outline`,size:`sm`,onClick:()=>ve(t,e.id,Y(e)||`document-${e.id}`).catch(e=>a(e instanceof Error?e.message:String(e))),children:[(0,Q.jsx)(U,{className:`mr-1 h-3 w-3`}),` Download`]}),T&&(0,Q.jsxs)(K,{variant:`outline`,size:`sm`,onClick:()=>O(!0),children:[(0,Q.jsx)(D,{className:`mr-1 h-3 w-3`}),` Edit sketch`]}),k&&(0,Q.jsxs)(K,{variant:`outline`,size:`sm`,onClick:()=>j(!0),children:[(0,Q.jsx)(p,{className:`mr-1 h-3 w-3`}),` Open editor`]}),(0,Q.jsxs)(K,{variant:`outline`,size:`sm`,onClick:()=>w(!0),children:[(0,Q.jsx)(c,{className:`mr-1 h-3 w-3`}),` Edit`]})]}),E&&S&&(0,Q.jsx)(Z.Suspense,{fallback:(0,Q.jsx)(`div`,{className:`fixed inset-0 z-fullscreen flex items-center justify-center bg-background surface-glass`,children:(0,Q.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`Loading sketch editor…`})}),children:(0,Q.jsx)(wt,{doc:e,workspaceName:t,onSaved:()=>{O(!1),r?.()},onClose:()=>O(!1),onDetails:()=>{O(!1),w(!0)}})}),A&&S&&(0,Q.jsx)(Z.Suspense,{fallback:(0,Q.jsx)(`div`,{className:`fixed inset-0 z-fullscreen flex items-center justify-center bg-background surface-glass`,children:(0,Q.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`Loading editor…`})}),children:(0,Q.jsx)(tr,{doc:e,workspaceName:t,onSaved:e=>{j(!1),r?.(e)},onClose:()=>j(!1),onDetails:()=>{j(!1),w(!0)}})}),(0,Q.jsxs)(`div`,{className:`min-h-0 flex-1 overflow-auto`,onMouseDownCapture:e=>{e.button===0&&e.detail>1&&F(e)&&e.preventDefault()},onDoubleClickCapture:e=>{F(e)&&(e.preventDefault(),e.stopPropagation(),e.currentTarget.ownerDocument.getSelection()?.removeAllRanges(),w(!0))},children:[f&&!i?(0,Q.jsx)(An,{workspaceId:t,documentId:Number(e.id)},`${t}:${e.id}`):(0,Q.jsx)(kn,{workspaceId:t,document:e}),g&&y&&(0,Q.jsx)(vt,{workspaceId:t,replyToDocumentId:Number(e.id),mode:g,originalSubject:v&&typeof e.data?.subject==`string`?e.data.subject:void 0,onClose:()=>_(null)},`${e.id}:${g}`)]}),e.comment?.trim()&&(0,Q.jsxs)(`div`,{className:`shrink-0 rounded-md border border-border bg-muted/40 px-3 py-2`,children:[(0,Q.jsx)(`p`,{className:`text-xs font-medium text-muted-foreground mb-0.5`,children:`Comment`}),(0,Q.jsx)(`p`,{className:`text-sm whitespace-pre-wrap`,children:e.comment})]})]})}var ar=e=>e?new Date(e).toLocaleDateString(`en-US`,{year:`numeric`,month:`long`,day:`numeric`,hour:`2-digit`,minute:`2-digit`,second:`2-digit`}):`—`,or=e=>!Number.isFinite(e)||!e?null:e>=1?`${e}s`:`1/${Math.round(1/e)}s`;function sr({meta:e}){let{geo:t,exif:n,dimensions:r}=e;if(!t&&!n&&!r)return null;let i=(e,t)=>t==null||t===``?null:(0,Q.jsxs)(`div`,{children:[(0,Q.jsxs)(`span`,{className:`font-medium`,children:[e,`:`]}),(0,Q.jsx)(`span`,{className:`ml-2`,children:t})]});return(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`h3`,{className:`font-semibold mb-3`,children:`Photo`}),(0,Q.jsxs)(`div`,{className:`grid gap-3 text-sm`,children:[r&&i(`Dimensions`,r.width&&r.height?`${r.width} × ${r.height}`:null),n&&i(`Camera`,[n.make,n.model].filter(Boolean).join(` `)),n&&i(`Lens`,n.lensModel),n&&i(`Aperture`,Number.isFinite(n.fNumber)?`ƒ/${n.fNumber}`:null),n&&i(`Shutter`,or(n.exposureTime)),n&&i(`ISO`,Number.isFinite(n.iso)?n.iso:null),n&&i(`Focal length`,Number.isFinite(n.focalLength)?`${n.focalLength} mm`:null),n&&i(`Captured`,ar(n.capturedAt)),t&&Number.isFinite(t.lat)&&Number.isFinite(t.lon)&&i(`Location`,(0,Q.jsxs)(`a`,{href:`https://www.openstreetmap.org/?mlat=${t.lat}&mlon=${t.lon}#map=15/${t.lat}/${t.lon}`,target:`_blank`,rel:`noopener noreferrer`,className:`text-primary underline underline-offset-2`,children:[t.lat.toFixed(5),`, `,t.lon.toFixed(5),Number.isFinite(t.alt)?` · ${Math.round(t.alt)} m`:``]}))]})]})}function cr({document:e}){let t=e.metadata;return(0,Q.jsxs)(`div`,{className:`space-y-6`,children:[(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`h3`,{className:`font-semibold mb-3`,children:`Basic Information`}),(0,Q.jsxs)(`div`,{className:`grid gap-3 text-sm`,children:[(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`span`,{className:`font-medium`,children:`ID:`}),(0,Q.jsx)(`span`,{className:`ml-2 font-mono`,children:e.id})]}),(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`span`,{className:`font-medium`,children:`Schema:`}),(0,Q.jsx)(`span`,{className:`ml-2 font-mono`,children:e.schema})]}),(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`span`,{className:`font-medium`,children:`Schema Version:`}),(0,Q.jsx)(`span`,{className:`ml-2`,children:e.schemaVersion})]}),(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`span`,{className:`font-medium`,children:`Created:`}),(0,Q.jsx)(`span`,{className:`ml-2`,children:ar(e.createdAt)})]}),(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`span`,{className:`font-medium`,children:`Updated:`}),(0,Q.jsx)(`span`,{className:`ml-2`,children:ar(e.updatedAt)})]})]})]}),(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`h3`,{className:`font-semibold mb-3`,children:`Metadata`}),(0,Q.jsxs)(`div`,{className:`grid gap-3 text-sm`,children:[(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`span`,{className:`font-medium`,children:`Content Type:`}),(0,Q.jsx)(`span`,{className:`ml-2`,children:e.metadata?.contentType??`—`})]}),(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`span`,{className:`font-medium`,children:`Content Encoding:`}),(0,Q.jsx)(`span`,{className:`ml-2`,children:e.metadata?.contentEncoding??`—`})]}),Number.isFinite(e.metadata?.size)&&(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`span`,{className:`font-medium`,children:`Size:`}),(0,Q.jsxs)(`span`,{className:`ml-2`,children:[e.metadata?.size,` bytes`]})]})]})]}),(0,Q.jsx)(sr,{meta:t}),Array.isArray(e.locations)&&e.locations.length>0&&(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`h3`,{className:`font-semibold mb-3`,children:`Locations`}),(0,Q.jsx)(`div`,{className:`space-y-2`,children:e.locations.map((e,t)=>{let{backend:n,key:r}=fr(e.url);return(0,Q.jsxs)(`div`,{className:`flex items-baseline gap-2 text-sm font-mono`,children:[(0,Q.jsx)(`span`,{className:`font-medium shrink-0`,children:n}),e.status&&e.status!==`available`&&(0,Q.jsx)(`span`,{className:`shrink-0 rounded border px-1 text-xs`,title:e.statusChangedAt,children:e.status===`deleted`?`Deleted`:`Not found`}),r&&(0,Q.jsx)(`span`,{className:`break-all text-muted-foreground`,children:r})]},t)})})]}),Array.isArray(e.checksumArray)&&e.checksumArray.length>0&&(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`h3`,{className:`font-semibold mb-3`,children:`Checksums`}),(0,Q.jsx)(`div`,{className:`space-y-2`,children:e.checksumArray.map((e,t)=>{let[n,r]=e.split(`/`);return(0,Q.jsxs)(`div`,{className:`flex items-center gap-2 text-sm font-mono`,children:[(0,Q.jsxs)(`span`,{className:`font-medium`,children:[n,`:`]}),(0,Q.jsx)(`span`,{className:`break-all text-muted-foreground`,children:r})]},t)})})]}),e.indexOptions&&(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`h3`,{className:`font-semibold mb-3`,children:`Index Options`}),(0,Q.jsxs)(`div`,{className:`space-y-3 text-sm`,children:[(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`span`,{className:`font-medium`,children:`FTS Search Fields:`}),(0,Q.jsx)(`div`,{className:`ml-2 mt-1`,children:(e.indexOptions.ftsSearchFields??[]).map((e,t)=>(0,Q.jsx)(`span`,{className:`mb-1 mr-2 inline-block rounded bg-muted px-2 py-1 text-xs`,children:e},t))})]}),(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`span`,{className:`font-medium`,children:`Vector Embedding Fields:`}),(0,Q.jsx)(`div`,{className:`ml-2 mt-1`,children:(e.indexOptions.vectorEmbeddingFields??[]).map((e,t)=>(0,Q.jsx)(`span`,{className:`mb-1 mr-2 inline-block rounded bg-muted px-2 py-1 text-xs`,children:e},t))})]})]})]})]})}function lr({document:e}){let{showSuccessToast:t,showErrorToast:n}=X(),r=JSON.stringify(e,null,2);return(0,Q.jsxs)(`div`,{className:`space-y-2`,children:[(0,Q.jsx)(`div`,{className:`flex justify-end`,children:(0,Q.jsxs)(K,{variant:`outline`,size:`sm`,onClick:async()=>{try{await navigator.clipboard.writeText(r),t(`Copied to clipboard`)}catch{n(`Copy failed`)}},children:[(0,Q.jsx)(x,{className:`mr-1 h-3 w-3`}),` Copy to clipboard`]})}),(0,Q.jsx)(`pre`,{className:`overflow-x-auto rounded-lg bg-muted p-4 text-xs`,children:r})]})}function ur({document:e,workspaceId:t}){let[n,r]=(0,Z.useState)(null),[i,a]=(0,Z.useState)(null),o=`${t}:${e.id}`,[s,c]=(0,Z.useState)(o);return o!==s&&(c(o),r(null),a(null)),(0,Z.useEffect)(()=>{let n=!1;return _e(t,e.id).then(e=>{n||r(e)}).catch(e=>{n||a(e instanceof Error?e.message:String(e))}),()=>{n=!0}},[o]),i?(0,Q.jsx)(`p`,{className:`text-sm text-destructive`,children:i}):n?(0,Q.jsxs)(`div`,{className:`space-y-6`,children:[[{title:`Context tree`,type:`context`},{title:`Directory tree`,type:`directory`}].map(({title:e,type:t})=>{let r=n.filter(e=>e.type===t),i=r.flatMap(e=>e.paths.map(t=>({tree:e.tree,path:t})));return(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`h3`,{className:`mb-3 font-semibold`,children:e}),i.length===0?(0,Q.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`No placements.`}):(0,Q.jsx)(`div`,{className:`space-y-1`,children:i.map(({tree:e,path:t},n)=>(0,Q.jsxs)(`div`,{className:`flex items-center gap-2 text-sm`,children:[(0,Q.jsx)(`span`,{className:`break-all font-mono text-xs`,children:t}),r.length>1&&(0,Q.jsxs)(`span`,{className:`shrink-0 text-xs text-muted-foreground`,children:[`(`,e,`)`]})]},`${e}:${t}:${n}`))})]},t)}),(0,Q.jsx)(er,{document:e,workspaceId:t})]}):(0,Q.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`Loading memberships...`})}function dr(e){return e===`stored`?k:e===`workspace-file`?s:e===`imap`?A:e===`readonly`?S:I}function fr(e){let t=e.match(/^([a-z][a-z0-9+.-]*):\/\/([^/]*)\/?(.*)$/i);return t?{backend:`${t[1]}://${t[2]}`,key:t[3]}:{backend:e,key:``}}function pr({document:e,workspaceId:t,onChanged:n}){let{showSuccessToast:r,showErrorToast:i}=X(),[a,o]=(0,Z.useState)(null),[s,c]=(0,Z.useState)(null),[l,u]=(0,Z.useState)(null),[d,f]=(0,Z.useState)(null),[p,m]=(0,Z.useState)(null),[h,g]=(0,Z.useState)(!1),_=`${t}:${e.id}`,[v,y]=(0,Z.useState)(_);_!==v&&(y(_),o(null),c(null),f(null));let b=()=>{je(t,e.id).then(o).catch(e=>c(e instanceof Error?e.message:String(e)))};(0,Z.useEffect)(()=>{let n=!1;return je(t,e.id).then(e=>{n||o(e)}).catch(e=>{n||c(e instanceof Error?e.message:String(e))}),()=>{n=!0}},[_]);let S=async(a,o)=>{u(a),f(null);try{let i=await me(t,[e.id],{urls:[a],...o===void 0?{}:{keepDocument:o}}),s=i.successful[0];if(!s)throw Error(i.failed[0]?.reason||`Destroy failed`);s.docDeleted?r(`Removed from backend; document removed from index`):s.deleted.includes(a)?r(`Removed from backend`):r(`Reference dropped (backend is read-only)`),window.dispatchEvent(new CustomEvent(`workspace:documents:refresh`)),n?.(),b()}catch(e){i(e instanceof Error?e.message:String(e))}finally{u(null)}},C=async(a,o,s)=>{g(!0);try{let i=await Ae(t,[e.id],{to:a,mode:o,keepDocument:s.keepDocument,folder:s.folder,filename:s.filename,onConflict:s.onConflict}),c=i.successful[0];if(!c)throw Error(jn(i.failed,new Map([[e.id,Y(e)||`Document ${e.id}`]]))||`Transfer failed`);let l=c.transfers?.flatMap(e=>e.state===`unchanged`?[]:[e.backend])??[],u=a.join(`, `);o===`delete`?r(`Deleted from ${u}`):l.length===0?r(`Nothing to do — already on ${u}`):r(`${o===`move`?`Moved to`:`Copied to`} ${l.join(`, `)}${c.transfers?.some(e=>e.state===`pending`)?` (pending sync)`:``}`),window.dispatchEvent(new CustomEvent(`workspace:documents:refresh`)),m(null),n?.(),b()}catch(e){i(e instanceof Error?e.message:String(e))}finally{g(!1)}},T=e=>{if((a?.length??0)<=1){f(e.url);return}window.confirm(`Remove this copy from the backend?\n\n${e.url}`)&&S(e.url)};if(s)return(0,Q.jsx)(`p`,{className:`text-sm text-destructive`,children:s});if(!a)return(0,Q.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`Loading locations...`});let E=a.length===0,D=Y(e);return(0,Q.jsxs)(`div`,{className:`space-y-3`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center justify-between gap-2 rounded border px-3 py-2 text-sm`,children:[(0,Q.jsxs)(`span`,{className:`inline-flex min-w-0 items-center gap-2`,children:[(0,Q.jsx)(k,{className:`h-4 w-4 shrink-0 text-muted-foreground`}),(0,Q.jsx)(`span`,{className:`font-mono text-xs`,children:`workspace:db`}),(0,Q.jsxs)(`span`,{className:`truncate text-xs text-muted-foreground`,children:[`index entry (id `,e.id,`)`]})]}),(0,Q.jsx)(`span`,{className:`shrink-0 rounded bg-muted px-1.5 py-0.5 text-[10px] uppercase text-muted-foreground`,children:`json`})]}),E?(0,Q.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`No byte locations; this object lives only in the workspace database, so there is no file data to copy or move.`}):(0,Q.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,Q.jsxs)(K,{variant:`outline`,size:`sm`,onClick:()=>m(`copy`),title:`Copy the file data to another storage backend (keeps the existing copies)`,children:[(0,Q.jsx)(x,{className:`mr-1 h-3.5 w-3.5`}),` Copy to…`]}),(0,Q.jsxs)(K,{variant:`outline`,size:`sm`,onClick:()=>m(`move`),title:`Move the file data to another storage backend (source released once the copy is durable)`,children:[(0,Q.jsx)(M,{className:`mr-1 h-3.5 w-3.5`}),` Move to…`]})]}),a.map(n=>{let r=dr(n.kind),{backend:a,key:o}=fr(n.url),s=l===n.url;return(0,Q.jsxs)(`div`,{className:`space-y-2 rounded border px-3 py-2 text-sm`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,Q.jsxs)(`span`,{className:`inline-flex min-w-0 items-center gap-2`,children:[(0,Q.jsx)(r,{className:`h-4 w-4 shrink-0 text-muted-foreground`}),(0,Q.jsx)(`span`,{className:`shrink-0 font-mono text-xs`,children:n.backend||a}),(0,Q.jsx)(`span`,{className:`truncate font-mono text-xs text-muted-foreground`,title:n.url,children:o||n.url})]}),(0,Q.jsxs)(`span`,{className:`flex shrink-0 items-center gap-2`,children:[(0,Q.jsx)(`span`,{className:`rounded px-1.5 py-0.5 text-[10px] uppercase ${n.deletable?`bg-muted text-muted-foreground`:`bg-warning/15 text-warning`}`,children:n.deletable?n.kind:`read-only`}),(0,Q.jsx)(`button`,{onClick:()=>ve(t,e.id,D||`document-${e.id}`,{url:n.url}).catch(e=>i(e instanceof Error?e.message:String(e))),className:`text-muted-foreground hover:text-foreground`,title:`Download this copy`,children:(0,Q.jsx)(U,{className:`h-3.5 w-3.5`})}),(0,Q.jsx)(`button`,{onClick:()=>T(n),disabled:s,className:`text-muted-foreground hover:text-destructive disabled:opacity-50`,title:n.deletable?`Remove from backend`:`Drop reference (bytes stay; backend is read-only)`,children:(0,Q.jsx)(w,{className:`h-3.5 w-3.5`})})]})]}),d===n.url&&(0,Q.jsxs)(`div`,{className:`space-y-2 rounded border border-destructive/40 bg-destructive/5 p-2`,children:[(0,Q.jsxs)(`p`,{className:`text-xs`,children:[`This is the object's `,(0,Q.jsx)(`strong`,{children:`last`}),` location. Remove the bytes from the backend and…`]}),(0,Q.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[(0,Q.jsx)(K,{variant:`destructive`,size:`sm`,disabled:s,onClick:()=>void S(n.url,!1),children:`Also remove index entry`}),(0,Q.jsx)(K,{variant:`outline`,size:`sm`,disabled:s,onClick:()=>void S(n.url,!0),children:`Keep index entry (no bytes)`}),(0,Q.jsx)(K,{variant:`ghost`,size:`sm`,onClick:()=>f(null),children:`Cancel`})]})]})]},n.url)}),p&&(0,Mn.createPortal)((0,Q.jsx)(`div`,{className:`fixed inset-0 z-picker flex items-center justify-center bg-scrim p-4 max-md:p-2`,children:(0,Q.jsx)(Ln,{workspaceId:t,documentCount:1,initialMode:p,defaultFilename:D,saving:h,onConfirm:C,onClose:()=>{h||m(null)}})}),window.document.body)]})}var mr=(0,Z.lazy)(()=>a(()=>import(`./LocationTab-DAtqAQ3l.js`),__vite__mapDeps([25,3,4,26,27]))),hr=[{id:`view`,label:`View`,icon:P},{id:`location`,label:`Location`,icon:ae},{id:`metadata`,label:`Metadata`,icon:ee},{id:`json`,label:`JSON`,icon:o},{id:`synapses`,label:`Synapses`,icon:te},{id:`backends`,label:`Backends`,icon:k}];function gr({document:e,workspaceId:t,initialTab:n=`view`,initialEdit:r=!1,onChanged:i,className:a=``,compact:o=!1,navigation:s,tabActions:c,onTabChange:l}){let u=Je()!=null,d=Tt(e),f=hr.filter(e=>(e.id!==`location`||d!==null)&&(!u||![`synapses`,`backends`].includes(e.id))),[p,m]=(0,Z.useState)(n),h=`${e.id}:${n}`,[g,_]=(0,Z.useState)(h);h!==g&&(_(h),m(n));let v=f.some(e=>e.id===p)?p:`view`,y=e=>{m(e),l?.(e)},b=o&&!!c&&!s,x=(0,Q.jsx)(`div`,{className:G(b&&`document-detail-header shrink-0 border-b-[3px] bg-muted`),children:(0,Q.jsxs)(`div`,{className:G(`flex min-w-0 items-center`,b&&`mx-auto h-[calc(3rem-4px)] w-full max-w-[var(--document-reading-width,100%)] gap-1 pl-2 pr-2 sm:pl-4`),children:[(0,Q.jsx)(_t,{tabs:f,active:v,onChange:y,className:G(`min-w-0 flex-1 px-1`,b&&`h-full border-b-0 px-0 max-sm:gap-0 max-sm:[&>button]:px-2.5`),iconOnly:o}),c]})});return(0,Q.jsxs)(`div`,{className:`flex h-full min-h-0 flex-col ${a}`,children:[s?(0,Q.jsx)(On,{...s,tabs:x,section:v,onDocument:()=>y(`view`),onSection:()=>y(`view`),onBack:v===`view`?s.onBack:()=>y(`view`)}):x,(0,Q.jsx)(`div`,{className:`min-h-0 flex-1 overflow-y-auto`,children:(0,Q.jsxs)(`div`,{className:`mx-auto h-full w-full max-w-[var(--document-reading-width,100%)] p-4`,children:[v===`view`&&(0,Q.jsx)(ir,{document:e,workspaceId:t,initialEdit:r&&!u,onChanged:i}),v===`location`&&d&&(0,Q.jsx)(Z.Suspense,{fallback:(0,Q.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`Loading map…`}),children:(0,Q.jsx)(mr,{lat:d.lat,lon:d.lon})}),v===`metadata`&&(0,Q.jsx)(cr,{document:e,workspaceId:t}),v===`json`&&(0,Q.jsx)(lr,{document:e,workspaceId:t}),v===`synapses`&&!u&&(0,Q.jsx)(ur,{document:e,workspaceId:t}),v===`backends`&&!u&&(0,Q.jsx)(pr,{document:e,workspaceId:t,onChanged:i})]})})]})}export{en as _,Kn as a,Dt as b,Ln as c,Dn as d,wn as f,an as g,nn as h,Zn as i,jn as l,rn as m,Xn as n,Jn as o,tn as p,Yn as r,Bn as s,gr as t,On as u,Ut as v,Pt as y};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{o as e}from"./rolldown-runtime-C0FnF6B9.js";import{l as t,u as n}from"./code-editor-BOIngd5F.js";import{_ 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 ee}from"./LinkToCard-BQ1yoFDr.js";import{G as l,Sn as u,V as te,bn as ne,zt as re}from"./workspace-BJELPCNs.js";import{r as ie}from"./document-list-CQ1_7Sja.js";import{n as ae}from"./use-toolbox-Ck_cLGgf.js";import{E as oe,_ as se,a as ce,b as le,i as ue,l as de,o as fe}from"./context-DZ1Hn7tt.js";import{i as pe}from"./color-DFEH4BfK.js";import{t as me}from"./geo-CZfs0E-x.js";import{a as he,i as ge,o as _e}from"./workspace-BydSRtST.js";import{i as ve}from"./use-menu-DIP1zh7I.js";import{a as ye,c as be,i as xe,l as Se,n as Ce,o as we,r as Te,s as Ee,t as De,u as Oe}from"./tree-folders-cmsIS19Z.js";import{t as ke}from"./use-workspace-identity-B8gOMGj4.js";var d=e(n(),1),f=t();function Ae(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 p(){let{contextId:e}=r(),t=a(),n=i(),p=new URLSearchParams(t.search).get(`ownerId`)||void 0,m=(0,d.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:h,showProgress:je}=s(),{state:g,saveFilters:Me,setSort:Ne,setAccentColor:_,setMapDocuments:v}=ae(),{openM1Drawer:Pe,openM2Drawer:Fe,goBack:Ie}=ve(),y=g.filters.features.allOf,Le=g.filters.features.anyOf,Re=g.filters.features.noneOf,ze=[...ge(g.filters.timeline),...he(g.filters.geo),..._e(g.filters.lens,g.filters.geo.includeUnlocated)],b=JSON.stringify({a:y,b:Le,c:Re,d:ze,ids:g.filters.lens.ids,sort:g.filters.sort,geoSelection:g.geoSelection,includeUnlocated:g.filters.geo.includeUnlocated}),x=(0,d.useMemo)(()=>JSON.parse(b),[b]),[S,C]=(0,d.useState)(null),[Be,Ve]=(0,d.useState)(!0),[He,Ue]=(0,d.useState)(null),[w,T]=(0,d.useState)([]),[We,Ge]=(0,d.useState)(!1),[Ke,E]=(0,d.useState)(0),[qe,Je]=(0,d.useState)([]),[D,O]=(0,d.useState)(1),[k,Ye]=(0,d.useState)(50),[A,j]=(0,d.useState)(m),[M,N]=(0,d.useState)(!1),[P,F]=(0,d.useState)(null),[Xe,Ze]=(0,d.useState)(!1),I=(0,d.useRef)(!1),L=P?.id===S?.id&&P?.url===S?.url?P?.path:null,R=new URLSearchParams(t.search).get(`layer`),z=!!p,Qe=ke(z?void 0:S?.workspaceName||S?.workspaceId),B=S?Ae(S.url,S.workspaceName):`/`,$e=R?`context-layer`:`context`,V=!g.liveEnabled&&typeof S?.metadata?.toolboxSearchQuery==`string`?S.metadata.toolboxSearchQuery:``,H=z?null:S?.workspaceName??null,[et,tt]=(0,d.useState)(null);(0,d.useEffect)(()=>{if(!H)return;let e=!1;return l(H,u).then(t=>{e||tt({key:H,tree:t})}).catch(()=>{e||tt({key:H,tree:null})}),()=>{e=!0}},[H]);let U=H&&et?.key===H?et.tree:null,W=!R&&!z&&U?B===`/`?U:te(U,B):null,nt=!R&&!z&&A.length===0,rt=(0,d.useMemo)(()=>nt?De(U,B):[],[nt,U,B]),G=`${S?.workspaceName??``}\0${B}`,[K,it]=(0,d.useState)(null),q=K?.key===G?K.views:Ee(W?.metadata),J=K?.key===G?K.activeId:q[0]?.id??ye.id,Y=q.find(e=>e.id===J)??q[0]??ye,X=we(Y);Oe(Se({workspace:S?.workspaceName||S?.workspaceId||null,treeNameOrId:g.activeTreeName,path:B,contextId:e??null,scope:`context`},{...g.filters,features:{...g.filters.features,allOf:X?[...y,X]:y}},g.geoSelection,A));let at=e=>{O(1),it({key:G,views:q,activeId:e})},ot=(e,t)=>{t&&t!==J&&O(1),it({key:G,views:e,activeId:t??J}),S?.workspaceName&&ne(S.workspaceName,B,{metadata:{...W?.metadata??{},views:e}},u).catch(()=>{h({title:`View not saved`,description:`Could not persist views to the layer`,variant:`destructive`})})},Z=(0,d.useRef)(null);(0,d.useEffect)(()=>()=>Z.current?.abort(),[]);let Q=(0,d.useCallback)(async()=>{if(!e)return;Z.current?.abort();let t=new AbortController;Z.current=t,Ge(!0);try{let n=await fe(e,X?[...x.a,X]:x.a,x.d,{...x.sort,geoSelection:x.geoSelection,includeUnlocated:x.includeUnlocated,ids:x.ids,signal:t.signal,limit:k,page:D,queries:A.length?A:void 0,anyOf:x.b,noneOf:x.c,applyContextSpec:!1},p);if(t.signal.aborted)return;T(n),E(n.totalCount||n.count||n.length)}catch(e){if(t.signal.aborted)return;h({title:`Error`,description:e instanceof Error?e.message:`Failed to fetch documents`,variant:`destructive`}),T([]),E(0)}finally{t.signal.aborted||Ge(!1)}},[e,D,k,p,A,x,h,X]),st=(0,d.useCallback)(async()=>{if(e){Ve(!0);try{let t=z?await ce(e,p):await ce(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)||``;C({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}),Ue(null)}catch(t){let n=t instanceof Error?t.message:`Failed to fetch context ${e}`;Ue(n),C(null),h({title:`Error`,description:n,variant:`destructive`})}Ve(!1)}},[e,p,z,h]);(0,d.useEffect)(()=>{st()},[st]);let ct=pe(S?.color)||null;(0,d.useEffect)(()=>(_(ct),()=>_(null)),[ct,_]);let lt=g.geoSelection,ut=S?.workspaceName||S?.workspaceId||null;(0,d.useEffect)(()=>{v(w,ut)},[w,ut,v]),(0,d.useEffect)(()=>()=>v([]),[v]);let dt=(0,d.useMemo)(()=>lt?w.filter(e=>me(e,lt,g.filters.geo.includeUnlocated)):w,[w,lt,g.filters.geo.includeUnlocated]),ft=S?.id,pt=S?.url;(0,d.useEffect)(()=>{ft&&Q()},[ft,pt,Q]),(0,d.useEffect)(()=>{let e=()=>Q();return window.addEventListener(`workspace:documents:refresh`,e),()=>window.removeEventListener(`workspace:documents:refresh`,e)},[Q]);let[mt,ht]=(0,d.useState)(b);mt!==b&&(ht(b),O(1));let[gt,_t]=(0,d.useState)(e);gt!==e&&(_t(e),O(1),N(!1));let[vt,yt]=(0,d.useState)(m);vt!==m&&(yt(m),j(m),O(1));let[bt,xt]=(0,d.useState)({urlSearchQueries:m,ignoreSavedSearch:M,savedContextSearchQuery:V});(bt.urlSearchQueries!==m||bt.ignoreSavedSearch!==M||bt.savedContextSearchQuery!==V)&&(xt({urlSearchQueries:m,ignoreSavedSearch:M,savedContextSearchQuery:V}),!new URLSearchParams(t.search).has(`q`)&&!m.length&&!M&&(j(V?[V]:[]),O(1)));let $=(0,d.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,d.useCallback)(e=>{let t=e.trim();if(!t)return;N(!1);let n=A.includes(t)?A:[...A,t];j(n),$(n)},[A,$]),Ct=(0,d.useCallback)(e=>{let t=e<0?[]:A.filter((t,n)=>n!==e);t.length===0&&N(!0),j(t),$(t)},[A,$]),wt=(A[0]||``).trim(),Tt=!!g.activeContextType&&(g.isDirty||wt!==(g.savedSearchQuery||V||``));(0,d.useEffect)(()=>{if(!e)return;let t=`context:${p?`${p}/`:``}${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)&&(C(e=>e?{...e,...r}:null),r.url&&Q())},ee=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)&&(C(e=>e?{...e,url:i}:null),Q())},l=t=>{let n=t;(n?.contextId||n?.id||n?.context?.id)===e&&s(`doc:changed`,n)&&Q()},u=[[`context.updated`,c],[`context:updated`,c],[`context.url.set`,ee],[`context:url:set`,ee],[`document.inserted`,l],[`document.updated`,l],[`document.removed`,l],[`document.removed.batch`,l],[`document.linked`,l],[`document.unlinked`,l],[`document.linked.batch`,l],[`document.unlinked.batch`,l],[`document.deleted`,l],[`document.deleted.batch`,l]];return u.forEach(([e,t])=>o.on(e,t)),()=>{i(),r(),u.forEach(([e,t])=>o.off(e,t))}},[e,p,Q]);let Et=async e=>{if(S)try{await le(S.id,[e],p,B),T(t=>t.filter(t=>t.id!==e)),E(e=>Math.max(0,e-1)),h({title:`Success`,description:`Document removed from context.`})}catch(e){h({title:`Error`,description:e instanceof Error?e.message:`Failed to remove document`,variant:`destructive`})}},Dt=async e=>{if(S)try{await ue(S.id,[e],p,B),T(t=>t.filter(t=>t.id!==e)),E(e=>Math.max(0,e-1)),h({title:`Success`,description:`Document deleted.`})}catch(e){h({title:`Error`,description:e instanceof Error?e.message:`Failed to delete document`,variant:`destructive`})}},Ot=async e=>{if(S)try{await le(S.id,e,p,B),T(t=>t.filter(t=>!e.includes(t.id))),E(t=>Math.max(0,t-e.length)),h({title:`Success`,description:`${e.length} document(s) removed.`})}catch(e){h({title:`Error`,description:e instanceof Error?e.message:`Failed to remove documents`,variant:`destructive`})}},kt=async e=>{if(S)try{await ue(S.id,e,p,B),T(t=>t.filter(t=>!e.includes(t.id))),E(t=>Math.max(0,t-e.length)),h({title:`Success`,description:`${e.length} document(s) deleted.`})}catch(e){h({title:`Error`,description:e instanceof Error?e.message:`Failed to delete documents`,variant:`destructive`})}},At=e=>{Je(e),h({title:`Copied`,description:`${e.length} document(s) copied to clipboard`})},jt=async(e,t,n={})=>{if(!S)return!1;let r=je({title:`Pasting…`,description:`${t.length} document(s) → "${e}"`});try{let i=n.targetTreeName&&!z?await re(S.workspaceName||S.workspaceId,e,t,n.targetTreeName,n.targetTreeType):await se(S.id,e,t,p);return r.done(i?{title:`Success`,description:`${t.length} document(s) pasted to "${e}"`}:void 0),i&&(Je([]),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(!S)return!1;try{let n=await de(S.workspaceId,t,e);return n&&(ie(S.workspaceName||S.workspaceId,`context`,t),h({title:`Success`,description:`Imported ${e.length} document(s) to "${t}"`})),n}catch(e){return h({title:`Error`,description:e instanceof Error?e.message:`Failed to import documents`,variant:`destructive`}),!1}},Nt=async()=>{if(!S||!L||z||I.current)return;let e={id:S.id,url:S.url,path:L};I.current=!0,Ze(!0);try{let t=await oe(e.id,`${S.workspaceName}://${e.path.replace(/^\/+/,``)}`);C(n=>n?.id===e.id&&n.url===e.url?{...n,url:t.url,path:e.path}:n),F(null),O(1),window.dispatchEvent(new CustomEvent(`contexts:refresh`,{detail:{contextId:e.id}})),h({title:`Saved`,description:`Context path updated`})}catch(e){h({title:`Error`,description:e instanceof Error?e.message:`Could not update context path`,variant:`destructive`})}finally{I.current=!1,Ze(!1)}};if(Be)return(0,f.jsx)(`div`,{className:`flex items-center justify-center h-full`,children:(0,f.jsxs)(`div`,{className:`text-center space-y-2`,children:[(0,f.jsx)(`div`,{className:`animate-spin rounded-full h-8 w-8 border-b-2 border-primary mx-auto`}),(0,f.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`Loading context...`})]})});if(He&&!S)return(0,f.jsxs)(`div`,{className:`flex items-center justify-center h-full text-destructive`,children:[`Error: `,He]});if(!S)return(0,f.jsx)(`div`,{className:`flex items-center justify-center h-full text-muted-foreground`,children:`Context not found.`});let Pt=pe(S.color);return(0,f.jsx)(`div`,{className:`flex flex-col h-full min-h-0`,children:(0,f.jsx)(be,{onBack:Ie,accentColor:Pt,navigationTabs:W?(0,f.jsx)(xe,{views:q,activeId:J,onSelect:at,onSave:ot,accentColor:Pt}):void 0,workspaceLabel:Qe?.label||S.workspaceName||S.workspaceId,workspaceIcon:Qe?.icon,treeName:u,urlType:$e,urlDisplay:S.url,contextPath:B,workspaceId:S.workspaceName||S.workspaceId,documentSchema:X,linkTree:U,documents:dt,isLoading:We,totalCount:Ke,currentPage:D,pageSize:k,onPageChange:O,onPageSizeChange:e=>{Ye(e),O(1)},onRemoveDocument:B===`/`?void 0:Et,onDeleteDocument:Dt,onRemoveDocuments:B===`/`?void 0:Ot,onDeleteDocuments:kt,onCopyDocuments:At,onPasteDocuments:jt,onImportDocuments:z?void 0:Mt,pastedDocumentIds:qe,backendSearchQueries:A,onBackendSearch:St,serverSort:g.filters.sort,onServerSortChange:Ne,onRemoveBackendQuery:Ct,canSaveChanges:Tt,isSavingChanges:g.isSaving,onSaveChanges:Me,onBrowseTree:!z&&e?()=>Fe(`contexts`,`detail`,e):void 0,onBrowseWorkspaces:()=>Pe(`workspaces`),folders:rt,onOpenFolder:e=>{I.current||F({id:S.id,url:S.url,path:e})},onNavigatePath:z?void 0:e=>{I.current||F({id:S.id,url:S.url,path:e})},contentBanner:L?(0,f.jsxs)(`div`,{className:`border-b bg-warning/10 px-4 py-2`,role:`status`,children:[(0,f.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,f.jsxs)(`div`,{className:`flex min-w-0 items-center gap-2`,children:[(0,f.jsx)(ee,{items:c(L,S.workspaceName),label:`Selected context path`}),(0,f.jsx)(`button`,{type:`button`,disabled:Xe,onClick:()=>void Nt(),className:`shrink-0 rounded border px-3 py-1 text-sm hover:bg-accent disabled:opacity-50`,children:Xe?`Setting…`:`Set`}),(0,f.jsx)(`button`,{type:`button`,disabled:Xe,onClick:()=>F(null),className:`shrink-0 rounded px-2 py-1 text-sm hover:bg-accent disabled:opacity-50`,children:`Cancel`})]})]}):void 0,children:Y.kind===`columns`?(0,f.jsx)(Te,{documents:dt,workspaceId:S.workspaceName||S.workspaceId,columns:Y.columns??[],onColumnsChange:e=>ot(q.map(t=>t.id===Y.id?{...t,columns:e}:t))}):Y.kind===`app`&&Y.app&&Y.app!==`notes`?(0,f.jsx)(Ce,{app:Y.app,contextId:e,workspaceId:S.workspaceName||S.workspaceId,treeName:u,path:B}):null})})}export{p as default};
|