@augmentd-labs/canvas-web 2.26.31 → 2.26.33

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (29) hide show
  1. package/dist/assets/{CalendarApplet-1-_9Pqfs.js → CalendarApplet-CG6XE01c.js} +1 -1
  2. package/dist/assets/{FiltersApplet-bF_7ntZU.js → FiltersApplet-Bh-Ti230.js} +1 -1
  3. package/dist/assets/{HomeFab-B_AndThd.js → HomeFab-DjDhl9Kx.js} +1 -1
  4. package/dist/assets/{LensApplet-FoQc4ieR.js → LensApplet-CTRYyg4u.js} +1 -1
  5. package/dist/assets/{NotesApplet-DfagszMP.js → NotesApplet-DShxjAo_.js} +1 -1
  6. package/dist/assets/{_agentId_-GsPtoz9i.js → _agentId_-D9i9ZJWV.js} +0 -0
  7. package/dist/assets/{_contextId_-xoan5Zgw.js → _contextId_-C6KmQgsY.js} +1 -1
  8. package/dist/assets/{_workspaceName_-DfNeZ188.js → _workspaceName_-DOmVjYen.js} +1 -1
  9. package/dist/assets/{about-DWl4-RY1.js → about-BzJi5UDC.js} +1 -1
  10. package/dist/assets/{add-AHQUHZBr.js → add-DJ45m1Gq.js} +1 -1
  11. package/dist/assets/{agents-DT1XtFUN.js → agents-mnY8dZIT.js} +1 -1
  12. package/dist/assets/{appearance-C8m9uEmD.js → appearance-CRoFdA6E.js} +1 -1
  13. package/dist/assets/{apps-DbYkQgyL.js → apps-4xGIx_KA.js} +1 -1
  14. package/dist/assets/{content-app-view-B4ada874.js → content-app-view-3BCpYf7m.js} +1 -1
  15. package/dist/assets/{home-BWAoF6jL.js → home-DB-ohpoi.js} +1 -1
  16. package/dist/assets/{index-D-y76fV7.js → index-BG5J93SO.js} +2 -2
  17. package/dist/assets/{key-bindings-C3rMnRos.js → key-bindings-BYwqkLkk.js} +1 -1
  18. package/dist/assets/{registry-BEyieXxp.js → registry-CtnhH0si.js} +2 -2
  19. package/dist/assets/{settings-BZsdOcHy.js → settings-BGCP2DRw.js} +1 -1
  20. package/dist/assets/{settings-QL_HG2aL.js → settings-BjieBx_W.js} +1 -1
  21. package/dist/assets/{settings-CFbSvlXK.js → settings-DAwqsOhZ.js} +1 -1
  22. package/dist/assets/{settings-DD2zxZ8C.js → settings-Id06aU1g.js} +6 -6
  23. package/dist/assets/{share-target-pA9r0Obg.js → share-target-BhCMpdxU.js} +1 -1
  24. package/dist/assets/{shared-ZTRGU8MK.js → shared-Dnd9GFGT.js} +1 -1
  25. package/dist/assets/{useAgentModels-fXPBeHX2.js → useAgentModels-CTCpJy1M.js} +1 -1
  26. package/dist/assets/{workspaces-BZ395Y1p.js → workspaces-BzAZpTMK.js} +1 -1
  27. package/dist/index.html +2 -2
  28. package/dist/sw.js +1 -1
  29. package/package.json +2 -2
@@ -1 +1 @@
1
- import{o as e}from"./rolldown-runtime-C0FnF6B9.js";import{l as t,u as n}from"./code-editor-BOIngd5F.js";import{r}from"./chunk-62JRHF6Z-vspAGgtK.js";import{Fr as i,Hr as a,L as o,Ot as s,Pt as c,Vr as l,X as u,ct as d,jr as f,mr as p,pn as m,qr as h,vn as g}from"./ui-76Hw0NU_.js";import{t as _}from"./utils-2pl1SbIp.js";import{Hn as v,In as y,St as b,jt as x,rt as S,vn as C,w,wn as T}from"./workspace-46EFyEKZ.js";import{o as E,t as D}from"./useAddTarget-D4ra50Am.js";import{a as O,o as k}from"./context-BGgz0Y_q.js";import{a as A,o as j,t as M}from"./date-time-picker-Bzu8H_Oa.js";import{n as N}from"./use-applet-target-DmIdCxa_.js";import{y as P}from"./index-D-y76fV7.js";import{r as ee,t as te}from"./shared-C-uHNNY8.js";var F=e(n(),1),I=864e5,L=[`Mon`,`Tue`,`Wed`,`Thu`,`Fri`,`Sat`,`Sun`];function R(e){return String(e).padStart(2,`0`)}function z(e){return`${e.getFullYear()}-${R(e.getMonth()+1)}-${R(e.getDate())}`}function B(e){let[t,n,r]=e.split(`-`).map(Number);return new Date(t,n-1,r)}function V(e){return`${z(e)}T${R(e.getHours())}:${R(e.getMinutes())}`}function H(e){return new Date(e.getFullYear(),e.getMonth(),e.getDate())}function U(e,t){return new Date(e.getFullYear(),e.getMonth(),e.getDate()+t,e.getHours(),e.getMinutes(),e.getSeconds(),e.getMilliseconds())}function ne(e,t){return new Date(e.getFullYear(),e.getMonth()+t,1)}function re(e){let t=H(e);return U(t,-((t.getDay()+6)%7))}function ie(e){return new Date(e.getFullYear(),e.getMonth(),1)}function W(e,t){return e.getFullYear()===t.getFullYear()&&e.getMonth()===t.getMonth()&&e.getDate()===t.getDate()}function G(e){let t=re(ie(e));return Array.from({length:42},(e,n)=>U(t,n))}function K(e,t){let n=[],r=t.getTime()>e.getTime()?new Date(t.getTime()-1):e;for(let t=H(e);t.getTime()<=r.getTime();t=U(t,1))n.push(t);return n}function q(e,t){let n=e.getTime()-H(t).getTime();return Math.max(0,Math.min(I,n))/6e4}var ae=new Intl.DateTimeFormat(void 0,{month:`long`,year:`numeric`}),J=new Intl.DateTimeFormat(void 0,{month:`short`}),oe=new Intl.DateTimeFormat(void 0,{weekday:`long`,day:`numeric`,month:`long`,year:`numeric`}),se=new Intl.DateTimeFormat(void 0,{weekday:`short`,day:`numeric`,month:`short`}),ce=new Intl.DateTimeFormat(void 0,{hour:`numeric`,minute:`2-digit`});function le(e){return ae.format(e)}function ue(e){return J.format(e)}function de(e){return oe.format(e)}function fe(e){return se.format(e)}function Y(e){return ce.format(e)}function pe(e){let t=U(e,6),n=e,r=t;return n.getFullYear()===r.getFullYear()?n.getMonth()===r.getMonth()?`${n.getDate()} – ${r.getDate()} ${J.format(n)} ${n.getFullYear()}`:`${n.getDate()} ${J.format(n)} – ${r.getDate()} ${J.format(r)} ${r.getFullYear()}`:`${n.getDate()} ${J.format(n)} ${n.getFullYear()} – ${r.getDate()} ${J.format(r)} ${r.getFullYear()}`}function me(e){return ce.format(new Date(2e3,0,1,e,0)).replace(/:00(?=\s|$)/,``)}var he={SU:0,MO:1,TU:2,WE:3,TH:4,FR:5,SA:6},ge=new Set([`FREQ`,`INTERVAL`,`COUNT`,`UNTIL`,`BYDAY`,`BYMONTHDAY`,`BYMONTH`,`WKST`]);function X(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=>!ge.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:he[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 _e(e,t){return new Date(e.getFullYear(),e.getMonth(),e.getDate(),t.getHours(),t.getMinutes(),t.getSeconds(),t.getMilliseconds())}function ve(e,t){return new Date(e,t+1,0).getDate()}function ye(e,t,n,r){let i=ve(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=>_e(new Date(e,t,n),r))}function be(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=_e(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=_e(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 ye(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 ye(r,i,e,t))if(!(n.getTime()<=d)&&!u(n)){a=!0;break}if(a||n>4800)break}return o}function xe(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 Se(e){if(!e)return`none`;let t=X(e);return!t||t.count!==null||t.until||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 Ce(e){switch(e){case`daily`:return`FREQ=DAILY`;case`weekly`:return`FREQ=WEEKLY`;case`monthly`:return`FREQ=MONTHLY`;case`yearly`:return`FREQ=YEARLY`;case`weekdays`:return`FREQ=WEEKLY;BYDAY=MO,TU,WE,TH,FR`;default:return}}var we=`tasks`,Te=`data/schema/event`,Ee=`data/schema/task`;function De(e){if(typeof e!=`string`||!e)return null;let t=new Date(e);return Number.isNaN(t.getTime())?null:t}function Oe(e){return new Date(e.getUTCFullYear(),e.getUTCMonth(),e.getUTCDate())}function ke(e){return e.schema.startsWith(Te)}function Ae(e){return e.schema===Ee}function je(e,t,n){let r=e.data??{};if(Ae(e)){let i=De(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:we,recurring:!1,unsupportedRule:!1,done:a===`completed`||a===`cancelled`}]}if(!ke(e))return[];let i=De(r.start);if(!i)return[];let a=r.allDay===!0,o=r.end===null?null:De(r.end),s=a?Oe(i):i,c=a?o?Oe(o):U(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=X(d);return f?be(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 Me(e,t,n){return e.flatMap(e=>je(e,t,n)).sort((e,t)=>e.start.getTime()-t.start.getTime()||t.end.getTime()-e.end.getTime()||e.title.localeCompare(t.title))}function Ne(e){let t=new Map;for(let n of e)for(let e of K(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 Pe(e){return e.allDay||e.end.getTime()-e.start.getTime()>=864e5||!W(e.start,new Date(e.end.getTime()-1))&&e.end.getTime()>e.start.getTime()}function Fe(e,t,n=30){let r=H(e),i=t.filter(e=>!Pe(e)).map(e=>{let t=q(e.start,r),i=Math.max(n,q(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}var Ie=[{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`}],Le={view:`week`,hidden:[],showTasks:!0,defaultCalendar:`Personal`},Re=`canvas:calendar:prefs`;function ze(e){return`${Re}:${e??`global`}`}function Be(e){try{let t=JSON.parse(localStorage.getItem(ze(e))||`null`);if(!t||typeof t!=`object`)return Le;let n=t;return{view:Ie.some(e=>e.id===n.view)?n.view:Le.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:Le.defaultCalendar}}catch{return Le}}function Ve(e,t){try{localStorage.setItem(ze(e),JSON.stringify(t))}catch{}}function He(e,t){let n=z(U(H(e),-1)),r=z(U(H(t),1));return{events:`t:events:${n}..${r}`,tasks:`t:tasks:${n}..${r}`}}var Ue=5e3;function We(e){return!!e&&!e.includes(`:`)&&![`content`,`events`,`tasks`].includes(e.toLowerCase())}function Ge(e){return e?e.mode===`context`?`ctx:${e.contextId}`:`${e.workspaceName}:${e.treeName}:${e.treeType}:${e.path}`:``}function Ke(e,t,n,r){let[i,a]=(0,F.useState)([]),[o,s]=(0,F.useState)(!1),[c,l]=(0,F.useState)(null),[u,d]=(0,F.useState)(null),[f,p]=(0,F.useState)([]),m=t.getTime(),h=n.getTime(),g=(0,F.useCallback)(()=>{if(!e)return Promise.resolve();let t=He(new Date(m),new Date(h));return(e.mode===`context`?Promise.all([k(e.contextId,[y],[t.events],{limit:Ue}),r?k(e.contextId,[v],[t.tasks],{limit:Ue}):Promise.resolve([]),O(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([S(n,i,[y],{...c,filters:[t.events]}),r?S(n,i,[v],{...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,F.useCallback)(async()=>{if(!e){a([]),d(null);return}s(!0),l(null),await g()},[e,g]),[C,T]=(0,F.useState)(null),E=`${Ge(e)}|${m}|${h}|${r}`;C!==E&&(T(E),e?(s(!0),l(null)):(a([]),d(null))),(0,F.useEffect)(()=>{g()},[g]),(0,F.useEffect)(()=>{let e=()=>{_()};return window.addEventListener(`workspace:documents:refresh`,e),()=>window.removeEventListener(`workspace:documents:refresh`,e)},[_]);let D=u?.workspaceName??null,A=(0,F.useCallback)(()=>D?Promise.all([b(D),x(D)]).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)We(e.name)&&n.add(e.name);p([...n].sort())}).catch(()=>{}):Promise.resolve(),[D]);(0,F.useEffect)(()=>{A()},[A,i.length]),(0,F.useEffect)(()=>{let e=()=>{A()};return window.addEventListener(`workspace:timelines:changed`,e),()=>window.removeEventListener(`workspace:timelines:changed`,e)},[A]);let j=(0,F.useCallback)(async e=>{if(!u)throw Error(`No workspace scope resolved`);await w(u.workspaceName,[e],u.path,[],u.treeName,u.treeType),a(t=>t.filter(t=>t.id!==e))},[u]),M=(0,F.useCallback)(e=>{a(t=>t.some(t=>t.id===e.id)?t.map(t=>t.id===e.id?e:t):[...t,e])},[]);return(0,F.useMemo)(()=>({docs:i,loading:o,error:c,scope:u,knownCalendars:f,reload:_,removeDoc:j,patchDoc:M}),[i,o,c,u,f,_,j,M])}function Z(e){return P(e?e.toLowerCase():`events`)}function qe(e){return e.kind===`task`?P(we):Z(e.calendar)}function Je(e,t=18){return`color-mix(in oklch, ${e} ${t}%, transparent)`}var Q=t();function Ye({month:e,selected:t,marks:n,onPick:r,onPrev:i,onNext:o,onTitle:s,title:c,className:u}){let d=new Date,f=G(e),p=c??le(e);return(0,Q.jsxs)(`div`,{className:_(`select-none`,u),children:[(0,Q.jsxs)(`div`,{className:`mb-1 flex items-center justify-between`,children:[i?(0,Q.jsx)(`button`,{type:`button`,onClick:i,className:`rounded p-0.5 text-muted-foreground hover:bg-muted hover:text-foreground`,"aria-label":`Previous month`,children:(0,Q.jsx)(a,{className:`h-3.5 w-3.5`})}):(0,Q.jsx)(`span`,{}),s?(0,Q.jsx)(`button`,{type:`button`,onClick:s,className:`text-xs font-semibold hover:underline`,children:p}):(0,Q.jsx)(`span`,{className:`text-xs font-semibold`,children:p}),o?(0,Q.jsx)(`button`,{type:`button`,onClick:o,className:`rounded p-0.5 text-muted-foreground hover:bg-muted hover:text-foreground`,"aria-label":`Next month`,children:(0,Q.jsx)(l,{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:L.map(e=>(0,Q.jsx)(`span`,{children:e[0]},e))}),(0,Q.jsx)(`div`,{className:`grid grid-cols-7 text-center text-[11px]`,children:f.map(i=>{let a=z(i),o=i.getMonth()===e.getMonth(),s=W(i,d),c=!!t&&W(i,t),l=n?.get(a)??0;return(0,Q.jsxs)(`button`,{type:`button`,onClick:()=>r(i),"aria-label":i.toDateString(),className:_(`relative mx-auto flex h-6 w-6 items-center justify-center rounded-full transition-colors hover:bg-muted`,!o&&`text-muted-foreground/40`,s&&!c&&`font-bold text-primary`,c&&`bg-primary text-primary-foreground hover:bg-primary`),children:[i.getDate(),l>0&&!c&&(0,Q.jsx)(`span`,{className:_(`absolute bottom-0.5 h-1 w-1 rounded-full`,l>2?`bg-foreground`:`bg-muted-foreground`)})]},a)})})]})}function Xe(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:H(e[t]),end:U(H(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=H(e[o]);return{start:new Date(d.getTime()+l*6e4),end:new Date(d.getTime()+u*6e4),allDay:!1}}function Ze(e,t){let[n,r]=e.getTime()<=t.getTime()?[e,t]:[t,e];return{start:H(n),end:U(H(r),1),allDay:!0}}function Qe({occurrence:e,selected:t,showTime:n=!0,onSelect:r,className:a}){let o=qe(e),c=!e.allDay&&e.kind===`event`&&e.end.getTime()>e.start.getTime();return(0,Q.jsxs)(`button`,{type:`button`,onClick:t=>{t.stopPropagation(),r(e)},title:`${e.title}${e.calendar?` · ${e.calendar}`:``}`,className:_(`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`,t&&`ring-1 ring-ring`,e.done&&`line-through opacity-60`,a),style:{background:Je(o,e.allDay||e.kind===`task`?28:14),borderLeft:`3px solid ${o}`},children:[e.kind===`task`&&(0,Q.jsx)(i,{className:`h-3 w-3 shrink-0`,style:{color:o}}),n&&c&&(0,Q.jsx)(`span`,{className:`shrink-0 tabular-nums text-muted-foreground`,children:Y(e.start)}),(0,Q.jsx)(`span`,{className:`truncate`,children:e.title}),e.recurring&&(0,Q.jsx)(s,{className:`ml-auto h-2.5 w-2.5 shrink-0 text-muted-foreground`})]})}var $=48,$e=30,et=`w-12`,tt=48;function nt({days:e,occurrences:t,selectedKey:n,pending:r,onSelect:i,onCreate:a,onPickDay:o,compact:s}){let c=(0,F.useRef)(null),l=(0,F.useRef)(null),[u,d]=(0,F.useState)(null),f=(0,F.useRef)(u);(0,F.useEffect)(()=>{f.current=u});let p=t=>{let n=l.current;if(!n)return null;let r=n.getBoundingClientRect(),i=(r.width-tt)/e.length,a=Math.floor((t.clientX-r.left-tt)/i),o=Math.max(0,Math.min(1439,(t.clientY-r.top)/$*60));return a<0||a>=e.length?null:{day:a,min:o}},m=e=>{if(e.button!==0||e.target.closest(`button`))return;let t=p(e);t&&(e.currentTarget.setPointerCapture(e.pointerId),d({fromDay:t.day,fromMin:t.min,toDay:t.day,toMin:t.min}))},h=e=>{if(!f.current)return;let t=p(e);t&&d({...f.current,toDay:t.day,toMin:t.min})},g=t=>{let n=f.current;if(!n)return;t.currentTarget.releasePointerCapture(t.pointerId),d(null);let r=Xe(e,n.fromDay,n.fromMin,n.toDay,n.toMin,$e);a(r.start,r.allDay,r.end)},v=u?Xe(e,u.fromDay,u.fromMin,u.toDay,u.toMin,$e):r,y=(0,F.useMemo)(()=>Ne(t),[t]),[b,x]=(0,F.useState)(()=>new Date);(0,F.useEffect)(()=>{let e=setInterval(()=>x(new Date),6e4);return()=>clearInterval(e)},[]);let S=z(e[0]);(0,F.useEffect)(()=>{let t=c.current;t&&(t.scrollTop=(e.some(e=>W(e,b))?Math.max(0,b.getHours()-1):7)*$)},[S,e.length]);let C=Array.from({length:24},(e,t)=>t),w=e.map(e=>(y.get(z(e))??[]).filter(Pe)),T=Math.max(0,...w.map(e=>e.length));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:_(et,`shrink-0`)}),e.map(e=>{let t=W(e,b);return(0,Q.jsxs)(`button`,{type:`button`,onClick:()=>o(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:L[(e.getDay()+6)%7]}),(0,Q.jsx)(`span`,{className:_(`flex h-7 w-7 items-center justify-center rounded-full text-sm font-semibold`,t&&`bg-primary text-primary-foreground`),children:e.getDate()})]},z(e))})]}),T>0&&(0,Q.jsxs)(`div`,{className:`flex shrink-0 border-b border-border bg-muted/20`,children:[(0,Q.jsx)(`div`,{className:_(et,`shrink-0 py-1 pr-1 text-right text-[10px] text-muted-foreground`),children:s?``:`all day`}),e.map((e,t)=>(0,Q.jsx)(`div`,{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(H(e),!0)},children:w[t].map(e=>(0,Q.jsx)(Qe,{occurrence:e,selected:e.key===n,showTime:!1,onSelect:i},e.key))},z(e)))]}),(0,Q.jsx)(`div`,{ref:c,className:`min-h-0 flex-1 overflow-y-auto`,children:(0,Q.jsxs)(`div`,{ref:l,className:_(`relative flex select-none`,u&&`cursor-crosshair`),style:{height:1152},onPointerDown:m,onPointerMove:h,onPointerUp:g,onPointerCancel:()=>d(null),children:[(0,Q.jsx)(`div`,{className:_(et,`relative shrink-0`),children:C.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?``:me(e)},e))}),e.map(e=>{let t=Fe(e,y.get(z(e))??[]),r=W(e,b)?(b.getHours()*60+b.getMinutes())/60*$:null;return(0,Q.jsxs)(`div`,{className:`relative min-w-0 flex-1 cursor-cell border-l border-border/60`,role:`presentation`,children:[v&&v.end>e&&v.start<H(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:q(v.start,e)/60*$,height:Math.max(8,(q(v.end,e)-q(v.start,e))/60*$)},children:(0,Q.jsx)(`span`,{className:`absolute left-1 top-0.5 text-[10px] font-medium text-primary`,children:v.allDay?`All day`:`${Y(v.start)} – ${Y(v.end)}`})}),C.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=qe(t),a=100/e.columns,o=e.height<45;return(0,Q.jsxs)(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),i(t)},title:`${t.title} · ${Y(t.start)}${t.end>t.start?` – ${Y(t.end)}`:``}`,className:_(`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`,t.key===n&&`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:Je(r,24),borderLeftColor:r,paddingTop:o?1:3},children:[(0,Q.jsx)(`span`,{className:_(`font-medium`,o?`inline`:`block truncate`),children:t.title}),!o&&(0,Q.jsxs)(`span`,{className:`block truncate text-[10px] text-muted-foreground`,children:[Y(t.start),t.end>t.start?` – ${Y(t.end)}`:``,t.calendar&&!s?` · ${t.calendar}`:``]})]},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`})})]},z(e))})]})})]})}var rt=3;function it({month:e,occurrences:t,selectedKey:n,pending:r,onSelect:i,onCreate:a,onPickDay:o,narrow:s}){let c=G(e),l=(0,F.useMemo)(()=>Ne(t),[t]),u=new Date,[d,f]=(0,F.useState)(null),p=(0,F.useRef)(d);(0,F.useEffect)(()=>{p.current=d});let m=e=>(document.elementFromPoint(e.clientX,e.clientY)?.closest(`[data-day]`))?.dataset.day??null,h=e=>{if(s||e.button!==0||e.target.closest(`button`))return;let t=m(e);t&&(e.currentTarget.setPointerCapture(e.pointerId),f({from:t,to:t}))},g=e=>{if(!p.current)return;let t=m(e);t&&t!==p.current.to&&f({...p.current,to:t})},v=e=>{let t=p.current;if(!t)return;e.currentTarget.releasePointerCapture(e.pointerId),f(null);let n=Ze(B(t.from),B(t.to));a(n.start,!0,n.end)},y=d?Ze(B(d.from),B(d.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:L.map(e=>(0,Q.jsx)(`span`,{className:`py-1`,children:s?e[0]:e},e))}),(0,Q.jsx)(`div`,{className:_(`grid min-h-0 flex-1 grid-cols-7 grid-rows-6 overflow-y-auto`,d&&`cursor-crosshair select-none`),onPointerDown:h,onPointerMove:g,onPointerUp:v,onPointerCancel:()=>f(null),children:c.map(t=>{let r=z(t),a=l.get(r)??[],c=t.getMonth()===e.getMonth(),d=W(t,u),f=a.length-rt;return(0,Q.jsxs)(`div`,{role:`presentation`,"data-day":r,onClick:e=>{s&&e.target===e.currentTarget&&o(t)},className:_(`flex min-h-[3.5rem] min-w-0 flex-col gap-0.5 border-b border-r border-border/60 p-0.5`,!c&&`bg-muted/20 text-muted-foreground/60`,!s&&`cursor-cell`,y&&t>=y.start&&t<y.end&&`bg-primary/15 ring-1 ring-inset ring-primary`),children:[(0,Q.jsx)(`button`,{type:`button`,onClick:()=>o(t),className:_(`mx-auto flex h-5 w-5 items-center justify-center rounded-full text-[11px] hover:bg-muted sm:mx-0`,d&&`bg-primary font-bold text-primary-foreground hover:bg-primary`),title:`Open day`,children:t.getDate()}),s?(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:qe(e)}},e.key))}):(0,Q.jsxs)(Q.Fragment,{children:[a.slice(0,rt).map(e=>(0,Q.jsx)(Qe,{occurrence:e,selected:e.key===n,onSelect:i},e.key)),f>0&&(0,Q.jsxs)(`button`,{type:`button`,onClick:()=>o(t),className:`px-1 text-left text-[10px] text-muted-foreground hover:text-foreground`,children:[`+`,f,` more`]})]})]},r)})})]})}function at({year:e,occurrences:t,onPickDay:n,onPickMonth:r}){let i=(0,F.useMemo)(()=>{let e=new Map;for(let[n,r]of Ne(t))e.set(n,r.length);return e},[t]),a=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:a.map(e=>(0,Q.jsx)(Ye,{month:e,marks:i,title:e.toLocaleDateString(void 0,{month:`long`}),onTitle:()=>r(e),onPick:n},z(e)))})}function ot({occurrences:e,selectedKey:t,onSelect:n,onEarlier:r,onLater:i,onPickDay:a,loading:o}){let s=(0,F.useMemo)(()=>[...Ne(e).entries()].sort(([e],[t])=>e.localeCompare(t)),[e]),c=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:r,className:`rounded-md border border-border px-3 py-1 text-xs text-muted-foreground hover:bg-muted hover:text-foreground`,children:`Earlier`})}),!o&&!s.length&&(0,Q.jsx)(`p`,{className:`py-10 text-center text-sm text-muted-foreground`,children:`Nothing scheduled in this range.`}),s.map(([e,r])=>{let i=B(e),o=W(i,c);return(0,Q.jsxs)(`div`,{className:`flex border-t border-border/60 px-2 py-2`,children:[(0,Q.jsxs)(`button`,{type:`button`,onClick:()=>a(i),className:`flex w-14 shrink-0 flex-col items-start`,title:`Open day`,children:[(0,Q.jsx)(`span`,{className:_(`flex h-8 w-8 items-center justify-center rounded-full text-lg font-semibold`,o&&`bg-primary text-primary-foreground`),children:i.getDate()}),(0,Q.jsxs)(`span`,{className:`text-[10px] uppercase tracking-wide text-muted-foreground`,children:[ue(i),`, `,L[(i.getDay()+6)%7]]})]}),(0,Q.jsx)(`div`,{className:`min-w-0 flex-1 space-y-0.5`,children:r.map(e=>{let r=qe(e),i=!Pe(e)&&e.kind===`event`;return(0,Q.jsxs)(`button`,{type:`button`,onClick:()=>n(e),className:_(`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:r}}),(0,Q.jsx)(`span`,{className:`w-[7.5rem] shrink-0 text-xs tabular-nums text-muted-foreground`,children:i?`${Y(e.start)}${e.end>e.start?` – ${Y(e.end)}`:``}`:e.kind===`task`?`due ${Y(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:i,className:`rounded-md border border-border px-3 py-1 text-xs text-muted-foreground hover:bg-muted hover:text-foreground`,children:`Later`})})]})}var st=`3.0`,ct=[{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 lt(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=Se(o||void 0);return{title:String(n.title??``),calendar:typeof n.calendar==`string`?n.calendar:dt(e)?``:t,allDay:r,start:r?i.slice(0,10):A(i),end:r?ft(i.slice(0,10),a):A(a),location:String(n.location??``),description:String(n.description??``),repeat:s,rrule:o}}function ut(e,t){let n=e.end??new Date(e.start.getTime()+36e5);return{title:``,calendar:t,allDay:e.allDay,start:e.allDay?z(e.start):V(e.start),end:e.allDay?z(U(n,-1)<e.start?e.start:U(n,-1)):V(n),location:``,description:``,repeat:`none`,rrule:``}}function dt(e){let t=e.metadata;return typeof t?.source==`string`&&t.source?{source:t.source,connector:typeof t.connector==`string`?t.connector:``}:null}function ft(e,t){if(!t)return``;let[n,r,i]=t.slice(0,10).split(`-`).map(Number),a=z(new Date(n,r-1,i-1));return a<e?e:a}function pt(e){return`${z(U(B(e),1))}T00:00:00.000Z`}function mt(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`,t.repeat===`custom`?t.rrule.trim():Ce(t.repeat)),t.allDay?(n.start=`${t.start}T00:00:00.000Z`,r(`end`,t.end?pt(t.end):void 0)):(n.start=j(t.start),r(`end`,j(t.end))),n}function ht(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()||!X(e.rrule))?`Enter a supported RRULE (FREQ=…, INTERVAL, COUNT, UNTIL, BYDAY, BYMONTHDAY, BYMONTH).`:null:`Pick a start.`:`Give the event a title.`}function gt({subject:e,target:t,workspaceName:n,calendars:i,defaultCalendar:a,onClose:c,onSaved:l,onDelete:d}){let f=e.kind===`occurrence`?e.occurrence.doc:null,h=e.kind===`occurrence`&&e.occurrence.kind===`task`,[v,b]=(0,F.useState)(()=>f?lt(f,a):ut(e.draft,a)),[x,S]=(0,F.useState)(!1),[w,T]=(0,F.useState)(null),[D,O]=(0,F.useState)(!1),k=e.kind===`draft`?`draft:${e.draft.start.getTime()}:${e.draft.end?.getTime()??``}:${e.draft.allDay}`:e.occurrence.key,[A,j]=(0,F.useState)(k);A!==k&&(j(k),b(f?lt(f,a):ut(e.draft,a)),T(null)),(0,F.useEffect)(()=>{let e=e=>{e.key===`Escape`&&c()};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[c]);let N=e=>b(t=>({...t,...e})),P=f?dt(f):null,I=typeof f?.data?.htmlLink==`string`?f.data.htmlLink:null,L=async()=>{let e=ht(v);if(e){T(e);return}S(!0),T(null);try{if(f){if(!n)throw Error(`No workspace resolved for this calendar`);await C(n,{id:f.id,schema:f.schema,schemaVersion:f.schemaVersion||st,data:mt(f.data??{},v),metadata:f.metadata})}else await E(t,[{schema:y,schemaVersion:st,data:mt({},v),metadata:{features:[]}}]);l(v.calendar.trim())}catch(e){T(e instanceof Error?e.message:`Failed to save the event`)}finally{S(!1)}},R=h?`Task`:f?`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:Z(h?`tasks`:v.calendar)}}),(0,Q.jsx)(`span`,{className:`text-sm font-semibold`,children:R}),f&&(0,Q.jsxs)(`span`,{className:`text-[10px] text-muted-foreground`,children:[`#`,f.id]}),(0,Q.jsx)(`span`,{className:`flex-1`}),f&&n&&(0,Q.jsx)(r,{to:`/workspaces/${encodeURIComponent(n)}/documents/${f.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)(p,{className:`h-3.5 w-3.5`})}),f&&(0,Q.jsx)(`button`,{type:`button`,onClick:()=>O(!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)(g,{className:`h-3.5 w-3.5`})}),f&&!h&&(0,Q.jsx)(`button`,{type:`button`,onClick:()=>{d(f)},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)(u,{className:`h-3.5 w-3.5`})}),(0,Q.jsx)(`button`,{type:`button`,onClick:c,className:`rounded p-1 text-muted-foreground hover:bg-muted hover:text-foreground`,"aria-label":`Close`,children:(0,Q.jsx)(o,{className:`h-4 w-4`})})]}),h&&f?(0,Q.jsx)(yt,{doc:f,occurrence:e.occurrence,workspaceName:n,onSaved:()=>l(``)}):(0,Q.jsxs)(`div`,{className:`min-h-0 flex-1 space-y-3 overflow-y-auto p-3`,children:[(0,Q.jsx)(`input`,{value:v.title,onChange:e=>N({title:e.target.value}),placeholder:`Title`,autoFocus:!f,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)(_t,{value:v.calendar,calendars:i,onChange:e=>N({calendar:e})}),(0,Q.jsxs)(`label`,{className:`flex items-center gap-2 text-xs`,children:[(0,Q.jsx)(`input`,{type:`checkbox`,checked:v.allDay,onChange:e=>{let t=e.target.checked;if(t)N({allDay:t,start:v.start.slice(0,10),end:(v.end||v.start).slice(0,10)});else{let e=v.start.slice(0,10)||z(new Date);N({allDay:t,start:`${e}T09:00`,end:`${(v.end||e).slice(0,10)}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`}),v.allDay?(0,Q.jsx)(`input`,{type:`date`,value:v.start,onChange:e=>N({start:e.target.value,end:v.end&&v.end<e.target.value?e.target.value:v.end}),className:`mt-1 h-8 w-full rounded-md border border-input bg-transparent px-2 text-sm`}):(0,Q.jsx)(`div`,{className:`mt-1`,children:(0,Q.jsx)(M,{value:v.start,onChange:e=>N({start:e}),clearable:!1})})]}),(0,Q.jsxs)(`label`,{className:`block text-xs`,children:[(0,Q.jsx)(`span`,{className:`text-muted-foreground`,children:`End`}),v.allDay?(0,Q.jsx)(`input`,{type:`date`,value:v.end,min:v.start,onChange:e=>N({end:e.target.value}),className:`mt-1 h-8 w-full rounded-md border border-input bg-transparent px-2 text-sm`}):(0,Q.jsx)(`div`,{className:`mt-1`,children:(0,Q.jsx)(M,{value:v.end,onChange:e=>N({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)(s,{className:`h-3 w-3`}),` Repeat`]}),(0,Q.jsx)(`select`,{value:v.repeat,onChange:e=>N({repeat:e.target.value,rrule:e.target.value===`custom`?v.rrule||Ce(v.repeat)||`FREQ=WEEKLY`:v.rrule}),className:`mt-1 h-8 w-full rounded-md border border-input bg-transparent px-2 text-sm`,children:ct.map(e=>(0,Q.jsx)(`option`,{value:e.id,children:e.label},e.id))}),v.repeat===`custom`&&(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(`input`,{value:v.rrule,onChange:e=>N({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:X(v.rrule)?xe(X(v.rrule)):`RFC 5545 RRULE value`})]})]}),(0,Q.jsxs)(`label`,{className:`block text-xs`,children:[(0,Q.jsx)(`span`,{className:`text-muted-foreground`,children:`Location`}),(0,Q.jsx)(`input`,{value:v.location,onChange:e=>N({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)(te,{value:v.description,onChange:e=>N({description:e}),placeholder:`Notes, agenda, links…`})})]}),P&&(0,Q.jsxs)(`p`,{className:`rounded-md bg-muted/50 px-2 py-1.5 text-[11px] text-muted-foreground`,children:[`Synced from `,P.connector||P.source,`. Edits stay in Canvas unless the connector supports write-back.`,I&&(0,Q.jsxs)(Q.Fragment,{children:[` `,(0,Q.jsx)(`a`,{href:I,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.`}),w&&(0,Q.jsx)(`p`,{className:`text-xs text-destructive`,role:`alert`,children:w})]}),!h&&(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)(vt,{doc:f}),(0,Q.jsx)(`button`,{type:`button`,onClick:c,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:L,disabled:x,className:_(`flex items-center gap-1 rounded-md bg-primary px-3 py-1.5 text-xs text-primary-foreground disabled:opacity-50`),children:[x&&(0,Q.jsx)(m,{className:`h-3 w-3 animate-spin`}),f?`Save`:`Create`]})]}),D&&f&&(0,Q.jsx)(ee,{documentId:f.id,workspaceName:n??void 0,onClose:()=>O(!1)})]})}function _t({value:e,calendars:t,onChange:n}){let r=t.some(t=>t.toLowerCase()===e.toLowerCase()),[i,a]=(0,F.useState)(!r&&!e&&t.length===0),s=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)(o,{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`}),s.map(e=>(0,Q.jsx)(`option`,{value:e,children:e},e)),(0,Q.jsx)(`option`,{value:`\0new`,children:`New calendar…`})]})]})}function vt({doc:e}){let t=T(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 yt({doc:e,occurrence:t,workspaceName:n,onSaved:r}){let[a,o]=(0,F.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 C(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:a,className:`mt-0.5 text-muted-foreground hover:text-foreground`,"aria-label":s?`Mark as pending`:`Mark as completed`,children:s?(0,Q.jsx)(i,{className:`h-4 w-4 text-success`}):(0,Q.jsx)(f,{className:`h-4 w-4`})}),(0,Q.jsxs)(`div`,{className:`min-w-0`,children:[(0,Q.jsx)(`p`,{className:_(`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.`})]})}var bt=640,xt=420,St=30;function Ct(e,t,n){switch(e){case`day`:{let e=H(t);return{start:e,end:U(e,1)}}case`week`:{let e=re(t);return{start:e,end:U(e,7)}}case`month`:{let e=G(t);return{start:e[0],end:U(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=H(t);return{start:U(e,-n.before),end:U(e,n.after)}}}}function wt(e,t,n){switch(e){case`day`:return U(t,n);case`week`:return U(t,7*n);case`month`:return ne(t,n);case`year`:return new Date(t.getFullYear()+n,t.getMonth(),1);case`schedule`:return U(t,St*n)}}function Tt(e,t,n){switch(e){case`day`:return n?fe(t):de(t);case`week`:return pe(re(t));case`month`:return le(t);case`year`:return String(t.getFullYear());case`schedule`:return n?fe(t):`From ${de(t)}`}}function Et({autoAdd:e=!1}){let t=N(),n=t?.mode===`workspace`?t.workspaceName:t?.mode===`context`?`ctx:${t.contextId}`:null,[r,i]=(0,F.useState)(()=>Be(n)),o=(0,F.useCallback)(e=>{i(t=>{let r={...t,...e};return Ve(n,r),r})},[n]),s=r.view,[u,f]=(0,F.useState)(()=>H(new Date)),[p,g]=(0,F.useState)({before:0,after:St}),[v,y]=(0,F.useState)(()=>e?{kind:`draft`,draft:{start:Dt(),allDay:!1}}:null),[b,x]=(0,F.useState)(!1),S=(0,F.useRef)(null),[C,w]=(0,F.useState)(1024);(0,F.useEffect)(()=>{let e=S.current;if(!e)return;let t=new ResizeObserver(e=>{for(let t of e)w(t.contentRect.width)});return t.observe(e),()=>t.disconnect()},[]);let T=C<bt,E=C<xt,O=(0,F.useMemo)(()=>Ct(s,u,p),[s,u,p]),{docs:k,loading:A,error:j,scope:M,knownCalendars:P,reload:ee,removeDoc:te}=Ke(t,O.start,O.end,r.showTasks),I=(0,F.useMemo)(()=>{let e=new Map;for(let t of P)e.set(t,t);for(let t of k){let n=t.data?.calendar;typeof n==`string`&&n.trim()&&e.set(n.trim().toLowerCase(),n.trim())}return r.defaultCalendar&&e.set(r.defaultCalendar.toLowerCase(),e.get(r.defaultCalendar.toLowerCase())??r.defaultCalendar),[...e.values()].sort((e,t)=>e.localeCompare(t))},[P,k,r.defaultCalendar]),L=(0,F.useMemo)(()=>new Set(r.hidden),[r.hidden]),R=(0,F.useMemo)(()=>k.some(e=>e.schema.startsWith(`data/schema/event`)&&!(typeof e.data?.calendar==`string`&&e.data.calendar.trim())),[k]),z=(0,F.useMemo)(()=>Me(k.filter(e=>{let t=typeof e.data?.calendar==`string`?e.data.calendar.trim().toLowerCase():``;return!L.has(t||``)}),O.start,O.end),[k,L,O]),B=v?.kind===`occurrence`?v.occurrence.key:null,V=(0,F.useCallback)((e,t)=>{f(H(e)),g({before:0,after:St}),t&&o({view:t})},[o]),W=(0,F.useMemo)(()=>{if(v?.kind!==`draft`)return null;let{start:e,allDay:t,end:n}=v.draft;return{start:e,allDay:t,end:n??(t?U(H(e),1):new Date(e.getTime()+36e5))}},[v]),G=(0,F.useCallback)((e,t,n)=>y({kind:`draft`,draft:{start:e,allDay:t,end:n}}),[]),K=(0,F.useCallback)(e=>y({kind:`occurrence`,occurrence:e}),[]),q=(0,F.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 te(e.id),y(null)}catch{}},[te]),ae=e=>{let t=e.target;if(!([`INPUT`,`TEXTAREA`,`SELECT`].includes(t.tagName)||t.isContentEditable)){if(e.key===`ArrowLeft`)V(wt(s,u,-1)),e.preventDefault();else if(e.key===`ArrowRight`)V(wt(s,u,1)),e.preventDefault();else if(e.key===`t`)V(new Date);else if(e.key===`n`)G(Dt(u),!1);else if(e.key===`Escape`)y(null),x(!1);else{let t=Ie.find(t=>t.key===e.key);t&&o({view:t.id})}}};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:D(t)});let J=e=>{let t=e.toLowerCase();o({hidden:L.has(t)?r.hidden.filter(e=>e!==t):[...r.hidden,t]})},oe=(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`}),I.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:!L.has(e.toLowerCase()),onChange:()=>J(e),className:`h-3.5 w-3.5 accent-primary`,style:{accentColor:Z(e)}}),(0,Q.jsx)(`span`,{className:`h-2.5 w-2.5 shrink-0 rounded-sm`,style:{background:Z(e)}}),(0,Q.jsx)(`span`,{className:`truncate`,children:e})]},e)),R&&(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:!L.has(``),onChange:()=>J(``),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:Z(``)}}),(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:r.showTasks,onChange:e=>o({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:Z(we)}}),(0,Q.jsx)(`span`,{className:`truncate`,children:`Tasks (due dates)`})]})]}),se=(()=>{switch(s){case`day`:return(0,Q.jsx)(nt,{days:[H(u)],occurrences:z,selectedKey:B,pending:W,onSelect:K,onCreate:G,onPickDay:e=>V(e,`day`),compact:E});case`week`:return(0,Q.jsx)(nt,{days:Array.from({length:7},(e,t)=>U(re(u),t)),occurrences:z,selectedKey:B,pending:W,onSelect:K,onCreate:G,onPickDay:e=>V(e,`day`),compact:T});case`month`:return(0,Q.jsx)(it,{month:ie(u),occurrences:z,selectedKey:B,pending:W,onSelect:K,onCreate:G,onPickDay:e=>V(e,`day`),narrow:T});case`year`:return(0,Q.jsx)(at,{year:u.getFullYear(),occurrences:z,onPickDay:e=>V(e,`day`),onPickMonth:e=>V(e,`month`)});case`schedule`:return(0,Q.jsx)(ot,{occurrences:z,selectedKey:B,onSelect:K,loading:A,onEarlier:()=>g(e=>({...e,before:e.before+St})),onLater:()=>g(e=>({...e,after:e.after+St})),onPickDay:e=>V(e,`day`)})}})();return(0,Q.jsxs)(`div`,{ref:S,tabIndex:0,onKeyDown:ae,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:()=>V(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:()=>V(wt(s,u,-1)),className:`rounded-md p-1 text-muted-foreground hover:bg-muted hover:text-foreground`,"aria-label":`Previous`,title:`Previous (←)`,children:(0,Q.jsx)(a,{className:`h-4 w-4`})}),(0,Q.jsx)(`button`,{type:`button`,onClick:()=>V(wt(s,u,1)),className:`rounded-md p-1 text-muted-foreground hover:bg-muted hover:text-foreground`,"aria-label":`Next`,title:`Next (→)`,children:(0,Q.jsx)(l,{className:`h-4 w-4`})}),(0,Q.jsx)(`span`,{className:`min-w-0 truncate text-sm font-semibold`,children:Tt(s,u,E)}),A&&(0,Q.jsx)(m,{className:`h-3.5 w-3.5 animate-spin text-muted-foreground`}),(0,Q.jsx)(`span`,{className:`flex-1`}),E?(0,Q.jsx)(`select`,{value:s,onChange:e=>o({view:e.target.value}),"aria-label":`View`,className:`h-7 rounded-md border border-input bg-transparent px-1.5 text-xs`,children:Ie.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:Ie.map(e=>(0,Q.jsx)(`button`,{type:`button`,role:`tab`,"aria-selected":s===e.id,onClick:()=>o({view:e.id}),title:`${e.label} (${e.key})`,className:_(`px-2 py-1 text-xs transition-colors`,s===e.id?`bg-foreground text-background`:`text-muted-foreground hover:bg-muted hover:text-foreground`),children:e.label},e.id))}),T&&(0,Q.jsx)(`button`,{type:`button`,onClick:()=>x(e=>!e),className:_(`rounded-md border p-1.5`,b?`border-foreground text-foreground`:`border-border text-muted-foreground hover:bg-muted hover:text-foreground`),"aria-label":`Calendars`,title:`Calendars`,children:(0,Q.jsx)(d,{className:`h-3.5 w-3.5`})}),(0,Q.jsxs)(`button`,{type:`button`,onClick:()=>G(Dt(u),!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)(c,{className:`h-3.5 w-3.5`}),!E&&`Event`]})]}),j&&(0,Q.jsx)(`p`,{className:`border-b border-border px-3 py-2 text-xs text-destructive`,children:j}),(0,Q.jsxs)(`div`,{className:`flex min-h-0 flex-1`,children:[!T&&(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)(Ye,{month:ie(u),selected:u,onPick:e=>V(e,s===`year`||s===`month`?`day`:s),onPrev:()=>f(e=>ne(e,-1)),onNext:()=>f(e=>ne(e,1))}),oe]}),(0,Q.jsxs)(`div`,{className:`relative min-w-0 flex-1`,children:[se,T&&b&&(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:oe})]}),v&&!T&&(0,Q.jsx)(`aside`,{className:`w-80 shrink-0 border-l border-border bg-card`,children:(0,Q.jsx)(gt,{subject:v,target:t,workspaceName:M?.workspaceName??null,calendars:I,defaultCalendar:r.defaultCalendar,onClose:()=>y(null),onSaved:e=>{e&&o({defaultCalendar:e}),y(null),ee()},onDelete:q})})]}),v&&T&&(0,Q.jsx)(`div`,{className:`absolute inset-0 z-30 flex flex-col bg-card`,children:(0,Q.jsx)(gt,{subject:v,target:t,workspaceName:M?.workspaceName??null,calendars:I,defaultCalendar:r.defaultCalendar,onClose:()=>y(null),onSaved:e=>{e&&o({defaultCalendar:e}),y(null),ee()},onDelete:q})}),!A&&!j&&!k.length&&s!==`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)(h,{className:`mr-1 inline h-3 w-3`}),`Nothing here yet — click or drag a slot to add an event.`]})]})}function Dt(e){let t=new Date,n=e&&!Ot(e,t)?new Date(e.getFullYear(),e.getMonth(),e.getDate(),9,0):new Date(t);return(!e||Ot(e,t))&&n.setMinutes(t.getMinutes()<30?30:60,0,0),n}function Ot(e,t){return e.toDateString()===t.toDateString()}export{Et as CalendarApplet};
1
+ import{o as e}from"./rolldown-runtime-C0FnF6B9.js";import{l as t,u as n}from"./code-editor-BOIngd5F.js";import{r}from"./chunk-62JRHF6Z-vspAGgtK.js";import{Fr as i,Hr as a,L as o,Ot as s,Pt as c,Vr as l,X as u,ct as d,jr as f,mr as p,pn as m,qr as h,vn as g}from"./ui-76Hw0NU_.js";import{t as _}from"./utils-2pl1SbIp.js";import{Hn as v,In as y,St as b,jt as x,rt as S,vn as C,w,wn as T}from"./workspace-46EFyEKZ.js";import{o as E,t as D}from"./useAddTarget-D4ra50Am.js";import{a as O,o as k}from"./context-BGgz0Y_q.js";import{a as A,o as j,t as M}from"./date-time-picker-Bzu8H_Oa.js";import{n as N}from"./use-applet-target-DmIdCxa_.js";import{y as P}from"./index-BG5J93SO.js";import{r as ee,t as te}from"./shared-C-uHNNY8.js";var F=e(n(),1),I=864e5,L=[`Mon`,`Tue`,`Wed`,`Thu`,`Fri`,`Sat`,`Sun`];function R(e){return String(e).padStart(2,`0`)}function z(e){return`${e.getFullYear()}-${R(e.getMonth()+1)}-${R(e.getDate())}`}function B(e){let[t,n,r]=e.split(`-`).map(Number);return new Date(t,n-1,r)}function V(e){return`${z(e)}T${R(e.getHours())}:${R(e.getMinutes())}`}function H(e){return new Date(e.getFullYear(),e.getMonth(),e.getDate())}function U(e,t){return new Date(e.getFullYear(),e.getMonth(),e.getDate()+t,e.getHours(),e.getMinutes(),e.getSeconds(),e.getMilliseconds())}function ne(e,t){return new Date(e.getFullYear(),e.getMonth()+t,1)}function re(e){let t=H(e);return U(t,-((t.getDay()+6)%7))}function ie(e){return new Date(e.getFullYear(),e.getMonth(),1)}function W(e,t){return e.getFullYear()===t.getFullYear()&&e.getMonth()===t.getMonth()&&e.getDate()===t.getDate()}function G(e){let t=re(ie(e));return Array.from({length:42},(e,n)=>U(t,n))}function K(e,t){let n=[],r=t.getTime()>e.getTime()?new Date(t.getTime()-1):e;for(let t=H(e);t.getTime()<=r.getTime();t=U(t,1))n.push(t);return n}function q(e,t){let n=e.getTime()-H(t).getTime();return Math.max(0,Math.min(I,n))/6e4}var ae=new Intl.DateTimeFormat(void 0,{month:`long`,year:`numeric`}),J=new Intl.DateTimeFormat(void 0,{month:`short`}),oe=new Intl.DateTimeFormat(void 0,{weekday:`long`,day:`numeric`,month:`long`,year:`numeric`}),se=new Intl.DateTimeFormat(void 0,{weekday:`short`,day:`numeric`,month:`short`}),ce=new Intl.DateTimeFormat(void 0,{hour:`numeric`,minute:`2-digit`});function le(e){return ae.format(e)}function ue(e){return J.format(e)}function de(e){return oe.format(e)}function fe(e){return se.format(e)}function Y(e){return ce.format(e)}function pe(e){let t=U(e,6),n=e,r=t;return n.getFullYear()===r.getFullYear()?n.getMonth()===r.getMonth()?`${n.getDate()} – ${r.getDate()} ${J.format(n)} ${n.getFullYear()}`:`${n.getDate()} ${J.format(n)} – ${r.getDate()} ${J.format(r)} ${r.getFullYear()}`:`${n.getDate()} ${J.format(n)} ${n.getFullYear()} – ${r.getDate()} ${J.format(r)} ${r.getFullYear()}`}function me(e){return ce.format(new Date(2e3,0,1,e,0)).replace(/:00(?=\s|$)/,``)}var he={SU:0,MO:1,TU:2,WE:3,TH:4,FR:5,SA:6},ge=new Set([`FREQ`,`INTERVAL`,`COUNT`,`UNTIL`,`BYDAY`,`BYMONTHDAY`,`BYMONTH`,`WKST`]);function X(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=>!ge.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:he[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 _e(e,t){return new Date(e.getFullYear(),e.getMonth(),e.getDate(),t.getHours(),t.getMinutes(),t.getSeconds(),t.getMilliseconds())}function ve(e,t){return new Date(e,t+1,0).getDate()}function ye(e,t,n,r){let i=ve(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=>_e(new Date(e,t,n),r))}function be(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=_e(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=_e(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 ye(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 ye(r,i,e,t))if(!(n.getTime()<=d)&&!u(n)){a=!0;break}if(a||n>4800)break}return o}function xe(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 Se(e){if(!e)return`none`;let t=X(e);return!t||t.count!==null||t.until||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 Ce(e){switch(e){case`daily`:return`FREQ=DAILY`;case`weekly`:return`FREQ=WEEKLY`;case`monthly`:return`FREQ=MONTHLY`;case`yearly`:return`FREQ=YEARLY`;case`weekdays`:return`FREQ=WEEKLY;BYDAY=MO,TU,WE,TH,FR`;default:return}}var we=`tasks`,Te=`data/schema/event`,Ee=`data/schema/task`;function De(e){if(typeof e!=`string`||!e)return null;let t=new Date(e);return Number.isNaN(t.getTime())?null:t}function Oe(e){return new Date(e.getUTCFullYear(),e.getUTCMonth(),e.getUTCDate())}function ke(e){return e.schema.startsWith(Te)}function Ae(e){return e.schema===Ee}function je(e,t,n){let r=e.data??{};if(Ae(e)){let i=De(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:we,recurring:!1,unsupportedRule:!1,done:a===`completed`||a===`cancelled`}]}if(!ke(e))return[];let i=De(r.start);if(!i)return[];let a=r.allDay===!0,o=r.end===null?null:De(r.end),s=a?Oe(i):i,c=a?o?Oe(o):U(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=X(d);return f?be(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 Me(e,t,n){return e.flatMap(e=>je(e,t,n)).sort((e,t)=>e.start.getTime()-t.start.getTime()||t.end.getTime()-e.end.getTime()||e.title.localeCompare(t.title))}function Ne(e){let t=new Map;for(let n of e)for(let e of K(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 Pe(e){return e.allDay||e.end.getTime()-e.start.getTime()>=864e5||!W(e.start,new Date(e.end.getTime()-1))&&e.end.getTime()>e.start.getTime()}function Fe(e,t,n=30){let r=H(e),i=t.filter(e=>!Pe(e)).map(e=>{let t=q(e.start,r),i=Math.max(n,q(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}var Ie=[{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`}],Le={view:`week`,hidden:[],showTasks:!0,defaultCalendar:`Personal`},Re=`canvas:calendar:prefs`;function ze(e){return`${Re}:${e??`global`}`}function Be(e){try{let t=JSON.parse(localStorage.getItem(ze(e))||`null`);if(!t||typeof t!=`object`)return Le;let n=t;return{view:Ie.some(e=>e.id===n.view)?n.view:Le.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:Le.defaultCalendar}}catch{return Le}}function Ve(e,t){try{localStorage.setItem(ze(e),JSON.stringify(t))}catch{}}function He(e,t){let n=z(U(H(e),-1)),r=z(U(H(t),1));return{events:`t:events:${n}..${r}`,tasks:`t:tasks:${n}..${r}`}}var Ue=5e3;function We(e){return!!e&&!e.includes(`:`)&&![`content`,`events`,`tasks`].includes(e.toLowerCase())}function Ge(e){return e?e.mode===`context`?`ctx:${e.contextId}`:`${e.workspaceName}:${e.treeName}:${e.treeType}:${e.path}`:``}function Ke(e,t,n,r){let[i,a]=(0,F.useState)([]),[o,s]=(0,F.useState)(!1),[c,l]=(0,F.useState)(null),[u,d]=(0,F.useState)(null),[f,p]=(0,F.useState)([]),m=t.getTime(),h=n.getTime(),g=(0,F.useCallback)(()=>{if(!e)return Promise.resolve();let t=He(new Date(m),new Date(h));return(e.mode===`context`?Promise.all([k(e.contextId,[y],[t.events],{limit:Ue}),r?k(e.contextId,[v],[t.tasks],{limit:Ue}):Promise.resolve([]),O(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([S(n,i,[y],{...c,filters:[t.events]}),r?S(n,i,[v],{...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,F.useCallback)(async()=>{if(!e){a([]),d(null);return}s(!0),l(null),await g()},[e,g]),[C,T]=(0,F.useState)(null),E=`${Ge(e)}|${m}|${h}|${r}`;C!==E&&(T(E),e?(s(!0),l(null)):(a([]),d(null))),(0,F.useEffect)(()=>{g()},[g]),(0,F.useEffect)(()=>{let e=()=>{_()};return window.addEventListener(`workspace:documents:refresh`,e),()=>window.removeEventListener(`workspace:documents:refresh`,e)},[_]);let D=u?.workspaceName??null,A=(0,F.useCallback)(()=>D?Promise.all([b(D),x(D)]).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)We(e.name)&&n.add(e.name);p([...n].sort())}).catch(()=>{}):Promise.resolve(),[D]);(0,F.useEffect)(()=>{A()},[A,i.length]),(0,F.useEffect)(()=>{let e=()=>{A()};return window.addEventListener(`workspace:timelines:changed`,e),()=>window.removeEventListener(`workspace:timelines:changed`,e)},[A]);let j=(0,F.useCallback)(async e=>{if(!u)throw Error(`No workspace scope resolved`);await w(u.workspaceName,[e],u.path,[],u.treeName,u.treeType),a(t=>t.filter(t=>t.id!==e))},[u]),M=(0,F.useCallback)(e=>{a(t=>t.some(t=>t.id===e.id)?t.map(t=>t.id===e.id?e:t):[...t,e])},[]);return(0,F.useMemo)(()=>({docs:i,loading:o,error:c,scope:u,knownCalendars:f,reload:_,removeDoc:j,patchDoc:M}),[i,o,c,u,f,_,j,M])}function Z(e){return P(e?e.toLowerCase():`events`)}function qe(e){return e.kind===`task`?P(we):Z(e.calendar)}function Je(e,t=18){return`color-mix(in oklch, ${e} ${t}%, transparent)`}var Q=t();function Ye({month:e,selected:t,marks:n,onPick:r,onPrev:i,onNext:o,onTitle:s,title:c,className:u}){let d=new Date,f=G(e),p=c??le(e);return(0,Q.jsxs)(`div`,{className:_(`select-none`,u),children:[(0,Q.jsxs)(`div`,{className:`mb-1 flex items-center justify-between`,children:[i?(0,Q.jsx)(`button`,{type:`button`,onClick:i,className:`rounded p-0.5 text-muted-foreground hover:bg-muted hover:text-foreground`,"aria-label":`Previous month`,children:(0,Q.jsx)(a,{className:`h-3.5 w-3.5`})}):(0,Q.jsx)(`span`,{}),s?(0,Q.jsx)(`button`,{type:`button`,onClick:s,className:`text-xs font-semibold hover:underline`,children:p}):(0,Q.jsx)(`span`,{className:`text-xs font-semibold`,children:p}),o?(0,Q.jsx)(`button`,{type:`button`,onClick:o,className:`rounded p-0.5 text-muted-foreground hover:bg-muted hover:text-foreground`,"aria-label":`Next month`,children:(0,Q.jsx)(l,{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:L.map(e=>(0,Q.jsx)(`span`,{children:e[0]},e))}),(0,Q.jsx)(`div`,{className:`grid grid-cols-7 text-center text-[11px]`,children:f.map(i=>{let a=z(i),o=i.getMonth()===e.getMonth(),s=W(i,d),c=!!t&&W(i,t),l=n?.get(a)??0;return(0,Q.jsxs)(`button`,{type:`button`,onClick:()=>r(i),"aria-label":i.toDateString(),className:_(`relative mx-auto flex h-6 w-6 items-center justify-center rounded-full transition-colors hover:bg-muted`,!o&&`text-muted-foreground/40`,s&&!c&&`font-bold text-primary`,c&&`bg-primary text-primary-foreground hover:bg-primary`),children:[i.getDate(),l>0&&!c&&(0,Q.jsx)(`span`,{className:_(`absolute bottom-0.5 h-1 w-1 rounded-full`,l>2?`bg-foreground`:`bg-muted-foreground`)})]},a)})})]})}function Xe(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:H(e[t]),end:U(H(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=H(e[o]);return{start:new Date(d.getTime()+l*6e4),end:new Date(d.getTime()+u*6e4),allDay:!1}}function Ze(e,t){let[n,r]=e.getTime()<=t.getTime()?[e,t]:[t,e];return{start:H(n),end:U(H(r),1),allDay:!0}}function Qe({occurrence:e,selected:t,showTime:n=!0,onSelect:r,className:a}){let o=qe(e),c=!e.allDay&&e.kind===`event`&&e.end.getTime()>e.start.getTime();return(0,Q.jsxs)(`button`,{type:`button`,onClick:t=>{t.stopPropagation(),r(e)},title:`${e.title}${e.calendar?` · ${e.calendar}`:``}`,className:_(`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`,t&&`ring-1 ring-ring`,e.done&&`line-through opacity-60`,a),style:{background:Je(o,e.allDay||e.kind===`task`?28:14),borderLeft:`3px solid ${o}`},children:[e.kind===`task`&&(0,Q.jsx)(i,{className:`h-3 w-3 shrink-0`,style:{color:o}}),n&&c&&(0,Q.jsx)(`span`,{className:`shrink-0 tabular-nums text-muted-foreground`,children:Y(e.start)}),(0,Q.jsx)(`span`,{className:`truncate`,children:e.title}),e.recurring&&(0,Q.jsx)(s,{className:`ml-auto h-2.5 w-2.5 shrink-0 text-muted-foreground`})]})}var $=48,$e=30,et=`w-12`,tt=48;function nt({days:e,occurrences:t,selectedKey:n,pending:r,onSelect:i,onCreate:a,onPickDay:o,compact:s}){let c=(0,F.useRef)(null),l=(0,F.useRef)(null),[u,d]=(0,F.useState)(null),f=(0,F.useRef)(u);(0,F.useEffect)(()=>{f.current=u});let p=t=>{let n=l.current;if(!n)return null;let r=n.getBoundingClientRect(),i=(r.width-tt)/e.length,a=Math.floor((t.clientX-r.left-tt)/i),o=Math.max(0,Math.min(1439,(t.clientY-r.top)/$*60));return a<0||a>=e.length?null:{day:a,min:o}},m=e=>{if(e.button!==0||e.target.closest(`button`))return;let t=p(e);t&&(e.currentTarget.setPointerCapture(e.pointerId),d({fromDay:t.day,fromMin:t.min,toDay:t.day,toMin:t.min}))},h=e=>{if(!f.current)return;let t=p(e);t&&d({...f.current,toDay:t.day,toMin:t.min})},g=t=>{let n=f.current;if(!n)return;t.currentTarget.releasePointerCapture(t.pointerId),d(null);let r=Xe(e,n.fromDay,n.fromMin,n.toDay,n.toMin,$e);a(r.start,r.allDay,r.end)},v=u?Xe(e,u.fromDay,u.fromMin,u.toDay,u.toMin,$e):r,y=(0,F.useMemo)(()=>Ne(t),[t]),[b,x]=(0,F.useState)(()=>new Date);(0,F.useEffect)(()=>{let e=setInterval(()=>x(new Date),6e4);return()=>clearInterval(e)},[]);let S=z(e[0]);(0,F.useEffect)(()=>{let t=c.current;t&&(t.scrollTop=(e.some(e=>W(e,b))?Math.max(0,b.getHours()-1):7)*$)},[S,e.length]);let C=Array.from({length:24},(e,t)=>t),w=e.map(e=>(y.get(z(e))??[]).filter(Pe)),T=Math.max(0,...w.map(e=>e.length));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:_(et,`shrink-0`)}),e.map(e=>{let t=W(e,b);return(0,Q.jsxs)(`button`,{type:`button`,onClick:()=>o(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:L[(e.getDay()+6)%7]}),(0,Q.jsx)(`span`,{className:_(`flex h-7 w-7 items-center justify-center rounded-full text-sm font-semibold`,t&&`bg-primary text-primary-foreground`),children:e.getDate()})]},z(e))})]}),T>0&&(0,Q.jsxs)(`div`,{className:`flex shrink-0 border-b border-border bg-muted/20`,children:[(0,Q.jsx)(`div`,{className:_(et,`shrink-0 py-1 pr-1 text-right text-[10px] text-muted-foreground`),children:s?``:`all day`}),e.map((e,t)=>(0,Q.jsx)(`div`,{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(H(e),!0)},children:w[t].map(e=>(0,Q.jsx)(Qe,{occurrence:e,selected:e.key===n,showTime:!1,onSelect:i},e.key))},z(e)))]}),(0,Q.jsx)(`div`,{ref:c,className:`min-h-0 flex-1 overflow-y-auto`,children:(0,Q.jsxs)(`div`,{ref:l,className:_(`relative flex select-none`,u&&`cursor-crosshair`),style:{height:1152},onPointerDown:m,onPointerMove:h,onPointerUp:g,onPointerCancel:()=>d(null),children:[(0,Q.jsx)(`div`,{className:_(et,`relative shrink-0`),children:C.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?``:me(e)},e))}),e.map(e=>{let t=Fe(e,y.get(z(e))??[]),r=W(e,b)?(b.getHours()*60+b.getMinutes())/60*$:null;return(0,Q.jsxs)(`div`,{className:`relative min-w-0 flex-1 cursor-cell border-l border-border/60`,role:`presentation`,children:[v&&v.end>e&&v.start<H(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:q(v.start,e)/60*$,height:Math.max(8,(q(v.end,e)-q(v.start,e))/60*$)},children:(0,Q.jsx)(`span`,{className:`absolute left-1 top-0.5 text-[10px] font-medium text-primary`,children:v.allDay?`All day`:`${Y(v.start)} – ${Y(v.end)}`})}),C.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=qe(t),a=100/e.columns,o=e.height<45;return(0,Q.jsxs)(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),i(t)},title:`${t.title} · ${Y(t.start)}${t.end>t.start?` – ${Y(t.end)}`:``}`,className:_(`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`,t.key===n&&`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:Je(r,24),borderLeftColor:r,paddingTop:o?1:3},children:[(0,Q.jsx)(`span`,{className:_(`font-medium`,o?`inline`:`block truncate`),children:t.title}),!o&&(0,Q.jsxs)(`span`,{className:`block truncate text-[10px] text-muted-foreground`,children:[Y(t.start),t.end>t.start?` – ${Y(t.end)}`:``,t.calendar&&!s?` · ${t.calendar}`:``]})]},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`})})]},z(e))})]})})]})}var rt=3;function it({month:e,occurrences:t,selectedKey:n,pending:r,onSelect:i,onCreate:a,onPickDay:o,narrow:s}){let c=G(e),l=(0,F.useMemo)(()=>Ne(t),[t]),u=new Date,[d,f]=(0,F.useState)(null),p=(0,F.useRef)(d);(0,F.useEffect)(()=>{p.current=d});let m=e=>(document.elementFromPoint(e.clientX,e.clientY)?.closest(`[data-day]`))?.dataset.day??null,h=e=>{if(s||e.button!==0||e.target.closest(`button`))return;let t=m(e);t&&(e.currentTarget.setPointerCapture(e.pointerId),f({from:t,to:t}))},g=e=>{if(!p.current)return;let t=m(e);t&&t!==p.current.to&&f({...p.current,to:t})},v=e=>{let t=p.current;if(!t)return;e.currentTarget.releasePointerCapture(e.pointerId),f(null);let n=Ze(B(t.from),B(t.to));a(n.start,!0,n.end)},y=d?Ze(B(d.from),B(d.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:L.map(e=>(0,Q.jsx)(`span`,{className:`py-1`,children:s?e[0]:e},e))}),(0,Q.jsx)(`div`,{className:_(`grid min-h-0 flex-1 grid-cols-7 grid-rows-6 overflow-y-auto`,d&&`cursor-crosshair select-none`),onPointerDown:h,onPointerMove:g,onPointerUp:v,onPointerCancel:()=>f(null),children:c.map(t=>{let r=z(t),a=l.get(r)??[],c=t.getMonth()===e.getMonth(),d=W(t,u),f=a.length-rt;return(0,Q.jsxs)(`div`,{role:`presentation`,"data-day":r,onClick:e=>{s&&e.target===e.currentTarget&&o(t)},className:_(`flex min-h-[3.5rem] min-w-0 flex-col gap-0.5 border-b border-r border-border/60 p-0.5`,!c&&`bg-muted/20 text-muted-foreground/60`,!s&&`cursor-cell`,y&&t>=y.start&&t<y.end&&`bg-primary/15 ring-1 ring-inset ring-primary`),children:[(0,Q.jsx)(`button`,{type:`button`,onClick:()=>o(t),className:_(`mx-auto flex h-5 w-5 items-center justify-center rounded-full text-[11px] hover:bg-muted sm:mx-0`,d&&`bg-primary font-bold text-primary-foreground hover:bg-primary`),title:`Open day`,children:t.getDate()}),s?(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:qe(e)}},e.key))}):(0,Q.jsxs)(Q.Fragment,{children:[a.slice(0,rt).map(e=>(0,Q.jsx)(Qe,{occurrence:e,selected:e.key===n,onSelect:i},e.key)),f>0&&(0,Q.jsxs)(`button`,{type:`button`,onClick:()=>o(t),className:`px-1 text-left text-[10px] text-muted-foreground hover:text-foreground`,children:[`+`,f,` more`]})]})]},r)})})]})}function at({year:e,occurrences:t,onPickDay:n,onPickMonth:r}){let i=(0,F.useMemo)(()=>{let e=new Map;for(let[n,r]of Ne(t))e.set(n,r.length);return e},[t]),a=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:a.map(e=>(0,Q.jsx)(Ye,{month:e,marks:i,title:e.toLocaleDateString(void 0,{month:`long`}),onTitle:()=>r(e),onPick:n},z(e)))})}function ot({occurrences:e,selectedKey:t,onSelect:n,onEarlier:r,onLater:i,onPickDay:a,loading:o}){let s=(0,F.useMemo)(()=>[...Ne(e).entries()].sort(([e],[t])=>e.localeCompare(t)),[e]),c=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:r,className:`rounded-md border border-border px-3 py-1 text-xs text-muted-foreground hover:bg-muted hover:text-foreground`,children:`Earlier`})}),!o&&!s.length&&(0,Q.jsx)(`p`,{className:`py-10 text-center text-sm text-muted-foreground`,children:`Nothing scheduled in this range.`}),s.map(([e,r])=>{let i=B(e),o=W(i,c);return(0,Q.jsxs)(`div`,{className:`flex border-t border-border/60 px-2 py-2`,children:[(0,Q.jsxs)(`button`,{type:`button`,onClick:()=>a(i),className:`flex w-14 shrink-0 flex-col items-start`,title:`Open day`,children:[(0,Q.jsx)(`span`,{className:_(`flex h-8 w-8 items-center justify-center rounded-full text-lg font-semibold`,o&&`bg-primary text-primary-foreground`),children:i.getDate()}),(0,Q.jsxs)(`span`,{className:`text-[10px] uppercase tracking-wide text-muted-foreground`,children:[ue(i),`, `,L[(i.getDay()+6)%7]]})]}),(0,Q.jsx)(`div`,{className:`min-w-0 flex-1 space-y-0.5`,children:r.map(e=>{let r=qe(e),i=!Pe(e)&&e.kind===`event`;return(0,Q.jsxs)(`button`,{type:`button`,onClick:()=>n(e),className:_(`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:r}}),(0,Q.jsx)(`span`,{className:`w-[7.5rem] shrink-0 text-xs tabular-nums text-muted-foreground`,children:i?`${Y(e.start)}${e.end>e.start?` – ${Y(e.end)}`:``}`:e.kind===`task`?`due ${Y(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:i,className:`rounded-md border border-border px-3 py-1 text-xs text-muted-foreground hover:bg-muted hover:text-foreground`,children:`Later`})})]})}var st=`3.0`,ct=[{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 lt(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=Se(o||void 0);return{title:String(n.title??``),calendar:typeof n.calendar==`string`?n.calendar:dt(e)?``:t,allDay:r,start:r?i.slice(0,10):A(i),end:r?ft(i.slice(0,10),a):A(a),location:String(n.location??``),description:String(n.description??``),repeat:s,rrule:o}}function ut(e,t){let n=e.end??new Date(e.start.getTime()+36e5);return{title:``,calendar:t,allDay:e.allDay,start:e.allDay?z(e.start):V(e.start),end:e.allDay?z(U(n,-1)<e.start?e.start:U(n,-1)):V(n),location:``,description:``,repeat:`none`,rrule:``}}function dt(e){let t=e.metadata;return typeof t?.source==`string`&&t.source?{source:t.source,connector:typeof t.connector==`string`?t.connector:``}:null}function ft(e,t){if(!t)return``;let[n,r,i]=t.slice(0,10).split(`-`).map(Number),a=z(new Date(n,r-1,i-1));return a<e?e:a}function pt(e){return`${z(U(B(e),1))}T00:00:00.000Z`}function mt(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`,t.repeat===`custom`?t.rrule.trim():Ce(t.repeat)),t.allDay?(n.start=`${t.start}T00:00:00.000Z`,r(`end`,t.end?pt(t.end):void 0)):(n.start=j(t.start),r(`end`,j(t.end))),n}function ht(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()||!X(e.rrule))?`Enter a supported RRULE (FREQ=…, INTERVAL, COUNT, UNTIL, BYDAY, BYMONTHDAY, BYMONTH).`:null:`Pick a start.`:`Give the event a title.`}function gt({subject:e,target:t,workspaceName:n,calendars:i,defaultCalendar:a,onClose:c,onSaved:l,onDelete:d}){let f=e.kind===`occurrence`?e.occurrence.doc:null,h=e.kind===`occurrence`&&e.occurrence.kind===`task`,[v,b]=(0,F.useState)(()=>f?lt(f,a):ut(e.draft,a)),[x,S]=(0,F.useState)(!1),[w,T]=(0,F.useState)(null),[D,O]=(0,F.useState)(!1),k=e.kind===`draft`?`draft:${e.draft.start.getTime()}:${e.draft.end?.getTime()??``}:${e.draft.allDay}`:e.occurrence.key,[A,j]=(0,F.useState)(k);A!==k&&(j(k),b(f?lt(f,a):ut(e.draft,a)),T(null)),(0,F.useEffect)(()=>{let e=e=>{e.key===`Escape`&&c()};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[c]);let N=e=>b(t=>({...t,...e})),P=f?dt(f):null,I=typeof f?.data?.htmlLink==`string`?f.data.htmlLink:null,L=async()=>{let e=ht(v);if(e){T(e);return}S(!0),T(null);try{if(f){if(!n)throw Error(`No workspace resolved for this calendar`);await C(n,{id:f.id,schema:f.schema,schemaVersion:f.schemaVersion||st,data:mt(f.data??{},v),metadata:f.metadata})}else await E(t,[{schema:y,schemaVersion:st,data:mt({},v),metadata:{features:[]}}]);l(v.calendar.trim())}catch(e){T(e instanceof Error?e.message:`Failed to save the event`)}finally{S(!1)}},R=h?`Task`:f?`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:Z(h?`tasks`:v.calendar)}}),(0,Q.jsx)(`span`,{className:`text-sm font-semibold`,children:R}),f&&(0,Q.jsxs)(`span`,{className:`text-[10px] text-muted-foreground`,children:[`#`,f.id]}),(0,Q.jsx)(`span`,{className:`flex-1`}),f&&n&&(0,Q.jsx)(r,{to:`/workspaces/${encodeURIComponent(n)}/documents/${f.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)(p,{className:`h-3.5 w-3.5`})}),f&&(0,Q.jsx)(`button`,{type:`button`,onClick:()=>O(!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)(g,{className:`h-3.5 w-3.5`})}),f&&!h&&(0,Q.jsx)(`button`,{type:`button`,onClick:()=>{d(f)},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)(u,{className:`h-3.5 w-3.5`})}),(0,Q.jsx)(`button`,{type:`button`,onClick:c,className:`rounded p-1 text-muted-foreground hover:bg-muted hover:text-foreground`,"aria-label":`Close`,children:(0,Q.jsx)(o,{className:`h-4 w-4`})})]}),h&&f?(0,Q.jsx)(yt,{doc:f,occurrence:e.occurrence,workspaceName:n,onSaved:()=>l(``)}):(0,Q.jsxs)(`div`,{className:`min-h-0 flex-1 space-y-3 overflow-y-auto p-3`,children:[(0,Q.jsx)(`input`,{value:v.title,onChange:e=>N({title:e.target.value}),placeholder:`Title`,autoFocus:!f,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)(_t,{value:v.calendar,calendars:i,onChange:e=>N({calendar:e})}),(0,Q.jsxs)(`label`,{className:`flex items-center gap-2 text-xs`,children:[(0,Q.jsx)(`input`,{type:`checkbox`,checked:v.allDay,onChange:e=>{let t=e.target.checked;if(t)N({allDay:t,start:v.start.slice(0,10),end:(v.end||v.start).slice(0,10)});else{let e=v.start.slice(0,10)||z(new Date);N({allDay:t,start:`${e}T09:00`,end:`${(v.end||e).slice(0,10)}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`}),v.allDay?(0,Q.jsx)(`input`,{type:`date`,value:v.start,onChange:e=>N({start:e.target.value,end:v.end&&v.end<e.target.value?e.target.value:v.end}),className:`mt-1 h-8 w-full rounded-md border border-input bg-transparent px-2 text-sm`}):(0,Q.jsx)(`div`,{className:`mt-1`,children:(0,Q.jsx)(M,{value:v.start,onChange:e=>N({start:e}),clearable:!1})})]}),(0,Q.jsxs)(`label`,{className:`block text-xs`,children:[(0,Q.jsx)(`span`,{className:`text-muted-foreground`,children:`End`}),v.allDay?(0,Q.jsx)(`input`,{type:`date`,value:v.end,min:v.start,onChange:e=>N({end:e.target.value}),className:`mt-1 h-8 w-full rounded-md border border-input bg-transparent px-2 text-sm`}):(0,Q.jsx)(`div`,{className:`mt-1`,children:(0,Q.jsx)(M,{value:v.end,onChange:e=>N({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)(s,{className:`h-3 w-3`}),` Repeat`]}),(0,Q.jsx)(`select`,{value:v.repeat,onChange:e=>N({repeat:e.target.value,rrule:e.target.value===`custom`?v.rrule||Ce(v.repeat)||`FREQ=WEEKLY`:v.rrule}),className:`mt-1 h-8 w-full rounded-md border border-input bg-transparent px-2 text-sm`,children:ct.map(e=>(0,Q.jsx)(`option`,{value:e.id,children:e.label},e.id))}),v.repeat===`custom`&&(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(`input`,{value:v.rrule,onChange:e=>N({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:X(v.rrule)?xe(X(v.rrule)):`RFC 5545 RRULE value`})]})]}),(0,Q.jsxs)(`label`,{className:`block text-xs`,children:[(0,Q.jsx)(`span`,{className:`text-muted-foreground`,children:`Location`}),(0,Q.jsx)(`input`,{value:v.location,onChange:e=>N({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)(te,{value:v.description,onChange:e=>N({description:e}),placeholder:`Notes, agenda, links…`})})]}),P&&(0,Q.jsxs)(`p`,{className:`rounded-md bg-muted/50 px-2 py-1.5 text-[11px] text-muted-foreground`,children:[`Synced from `,P.connector||P.source,`. Edits stay in Canvas unless the connector supports write-back.`,I&&(0,Q.jsxs)(Q.Fragment,{children:[` `,(0,Q.jsx)(`a`,{href:I,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.`}),w&&(0,Q.jsx)(`p`,{className:`text-xs text-destructive`,role:`alert`,children:w})]}),!h&&(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)(vt,{doc:f}),(0,Q.jsx)(`button`,{type:`button`,onClick:c,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:L,disabled:x,className:_(`flex items-center gap-1 rounded-md bg-primary px-3 py-1.5 text-xs text-primary-foreground disabled:opacity-50`),children:[x&&(0,Q.jsx)(m,{className:`h-3 w-3 animate-spin`}),f?`Save`:`Create`]})]}),D&&f&&(0,Q.jsx)(ee,{documentId:f.id,workspaceName:n??void 0,onClose:()=>O(!1)})]})}function _t({value:e,calendars:t,onChange:n}){let r=t.some(t=>t.toLowerCase()===e.toLowerCase()),[i,a]=(0,F.useState)(!r&&!e&&t.length===0),s=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)(o,{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`}),s.map(e=>(0,Q.jsx)(`option`,{value:e,children:e},e)),(0,Q.jsx)(`option`,{value:`\0new`,children:`New calendar…`})]})]})}function vt({doc:e}){let t=T(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 yt({doc:e,occurrence:t,workspaceName:n,onSaved:r}){let[a,o]=(0,F.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 C(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:a,className:`mt-0.5 text-muted-foreground hover:text-foreground`,"aria-label":s?`Mark as pending`:`Mark as completed`,children:s?(0,Q.jsx)(i,{className:`h-4 w-4 text-success`}):(0,Q.jsx)(f,{className:`h-4 w-4`})}),(0,Q.jsxs)(`div`,{className:`min-w-0`,children:[(0,Q.jsx)(`p`,{className:_(`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.`})]})}var bt=640,xt=420,St=30;function Ct(e,t,n){switch(e){case`day`:{let e=H(t);return{start:e,end:U(e,1)}}case`week`:{let e=re(t);return{start:e,end:U(e,7)}}case`month`:{let e=G(t);return{start:e[0],end:U(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=H(t);return{start:U(e,-n.before),end:U(e,n.after)}}}}function wt(e,t,n){switch(e){case`day`:return U(t,n);case`week`:return U(t,7*n);case`month`:return ne(t,n);case`year`:return new Date(t.getFullYear()+n,t.getMonth(),1);case`schedule`:return U(t,St*n)}}function Tt(e,t,n){switch(e){case`day`:return n?fe(t):de(t);case`week`:return pe(re(t));case`month`:return le(t);case`year`:return String(t.getFullYear());case`schedule`:return n?fe(t):`From ${de(t)}`}}function Et({autoAdd:e=!1}){let t=N(),n=t?.mode===`workspace`?t.workspaceName:t?.mode===`context`?`ctx:${t.contextId}`:null,[r,i]=(0,F.useState)(()=>Be(n)),o=(0,F.useCallback)(e=>{i(t=>{let r={...t,...e};return Ve(n,r),r})},[n]),s=r.view,[u,f]=(0,F.useState)(()=>H(new Date)),[p,g]=(0,F.useState)({before:0,after:St}),[v,y]=(0,F.useState)(()=>e?{kind:`draft`,draft:{start:Dt(),allDay:!1}}:null),[b,x]=(0,F.useState)(!1),S=(0,F.useRef)(null),[C,w]=(0,F.useState)(1024);(0,F.useEffect)(()=>{let e=S.current;if(!e)return;let t=new ResizeObserver(e=>{for(let t of e)w(t.contentRect.width)});return t.observe(e),()=>t.disconnect()},[]);let T=C<bt,E=C<xt,O=(0,F.useMemo)(()=>Ct(s,u,p),[s,u,p]),{docs:k,loading:A,error:j,scope:M,knownCalendars:P,reload:ee,removeDoc:te}=Ke(t,O.start,O.end,r.showTasks),I=(0,F.useMemo)(()=>{let e=new Map;for(let t of P)e.set(t,t);for(let t of k){let n=t.data?.calendar;typeof n==`string`&&n.trim()&&e.set(n.trim().toLowerCase(),n.trim())}return r.defaultCalendar&&e.set(r.defaultCalendar.toLowerCase(),e.get(r.defaultCalendar.toLowerCase())??r.defaultCalendar),[...e.values()].sort((e,t)=>e.localeCompare(t))},[P,k,r.defaultCalendar]),L=(0,F.useMemo)(()=>new Set(r.hidden),[r.hidden]),R=(0,F.useMemo)(()=>k.some(e=>e.schema.startsWith(`data/schema/event`)&&!(typeof e.data?.calendar==`string`&&e.data.calendar.trim())),[k]),z=(0,F.useMemo)(()=>Me(k.filter(e=>{let t=typeof e.data?.calendar==`string`?e.data.calendar.trim().toLowerCase():``;return!L.has(t||``)}),O.start,O.end),[k,L,O]),B=v?.kind===`occurrence`?v.occurrence.key:null,V=(0,F.useCallback)((e,t)=>{f(H(e)),g({before:0,after:St}),t&&o({view:t})},[o]),W=(0,F.useMemo)(()=>{if(v?.kind!==`draft`)return null;let{start:e,allDay:t,end:n}=v.draft;return{start:e,allDay:t,end:n??(t?U(H(e),1):new Date(e.getTime()+36e5))}},[v]),G=(0,F.useCallback)((e,t,n)=>y({kind:`draft`,draft:{start:e,allDay:t,end:n}}),[]),K=(0,F.useCallback)(e=>y({kind:`occurrence`,occurrence:e}),[]),q=(0,F.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 te(e.id),y(null)}catch{}},[te]),ae=e=>{let t=e.target;if(!([`INPUT`,`TEXTAREA`,`SELECT`].includes(t.tagName)||t.isContentEditable)){if(e.key===`ArrowLeft`)V(wt(s,u,-1)),e.preventDefault();else if(e.key===`ArrowRight`)V(wt(s,u,1)),e.preventDefault();else if(e.key===`t`)V(new Date);else if(e.key===`n`)G(Dt(u),!1);else if(e.key===`Escape`)y(null),x(!1);else{let t=Ie.find(t=>t.key===e.key);t&&o({view:t.id})}}};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:D(t)});let J=e=>{let t=e.toLowerCase();o({hidden:L.has(t)?r.hidden.filter(e=>e!==t):[...r.hidden,t]})},oe=(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`}),I.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:!L.has(e.toLowerCase()),onChange:()=>J(e),className:`h-3.5 w-3.5 accent-primary`,style:{accentColor:Z(e)}}),(0,Q.jsx)(`span`,{className:`h-2.5 w-2.5 shrink-0 rounded-sm`,style:{background:Z(e)}}),(0,Q.jsx)(`span`,{className:`truncate`,children:e})]},e)),R&&(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:!L.has(``),onChange:()=>J(``),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:Z(``)}}),(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:r.showTasks,onChange:e=>o({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:Z(we)}}),(0,Q.jsx)(`span`,{className:`truncate`,children:`Tasks (due dates)`})]})]}),se=(()=>{switch(s){case`day`:return(0,Q.jsx)(nt,{days:[H(u)],occurrences:z,selectedKey:B,pending:W,onSelect:K,onCreate:G,onPickDay:e=>V(e,`day`),compact:E});case`week`:return(0,Q.jsx)(nt,{days:Array.from({length:7},(e,t)=>U(re(u),t)),occurrences:z,selectedKey:B,pending:W,onSelect:K,onCreate:G,onPickDay:e=>V(e,`day`),compact:T});case`month`:return(0,Q.jsx)(it,{month:ie(u),occurrences:z,selectedKey:B,pending:W,onSelect:K,onCreate:G,onPickDay:e=>V(e,`day`),narrow:T});case`year`:return(0,Q.jsx)(at,{year:u.getFullYear(),occurrences:z,onPickDay:e=>V(e,`day`),onPickMonth:e=>V(e,`month`)});case`schedule`:return(0,Q.jsx)(ot,{occurrences:z,selectedKey:B,onSelect:K,loading:A,onEarlier:()=>g(e=>({...e,before:e.before+St})),onLater:()=>g(e=>({...e,after:e.after+St})),onPickDay:e=>V(e,`day`)})}})();return(0,Q.jsxs)(`div`,{ref:S,tabIndex:0,onKeyDown:ae,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:()=>V(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:()=>V(wt(s,u,-1)),className:`rounded-md p-1 text-muted-foreground hover:bg-muted hover:text-foreground`,"aria-label":`Previous`,title:`Previous (←)`,children:(0,Q.jsx)(a,{className:`h-4 w-4`})}),(0,Q.jsx)(`button`,{type:`button`,onClick:()=>V(wt(s,u,1)),className:`rounded-md p-1 text-muted-foreground hover:bg-muted hover:text-foreground`,"aria-label":`Next`,title:`Next (→)`,children:(0,Q.jsx)(l,{className:`h-4 w-4`})}),(0,Q.jsx)(`span`,{className:`min-w-0 truncate text-sm font-semibold`,children:Tt(s,u,E)}),A&&(0,Q.jsx)(m,{className:`h-3.5 w-3.5 animate-spin text-muted-foreground`}),(0,Q.jsx)(`span`,{className:`flex-1`}),E?(0,Q.jsx)(`select`,{value:s,onChange:e=>o({view:e.target.value}),"aria-label":`View`,className:`h-7 rounded-md border border-input bg-transparent px-1.5 text-xs`,children:Ie.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:Ie.map(e=>(0,Q.jsx)(`button`,{type:`button`,role:`tab`,"aria-selected":s===e.id,onClick:()=>o({view:e.id}),title:`${e.label} (${e.key})`,className:_(`px-2 py-1 text-xs transition-colors`,s===e.id?`bg-foreground text-background`:`text-muted-foreground hover:bg-muted hover:text-foreground`),children:e.label},e.id))}),T&&(0,Q.jsx)(`button`,{type:`button`,onClick:()=>x(e=>!e),className:_(`rounded-md border p-1.5`,b?`border-foreground text-foreground`:`border-border text-muted-foreground hover:bg-muted hover:text-foreground`),"aria-label":`Calendars`,title:`Calendars`,children:(0,Q.jsx)(d,{className:`h-3.5 w-3.5`})}),(0,Q.jsxs)(`button`,{type:`button`,onClick:()=>G(Dt(u),!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)(c,{className:`h-3.5 w-3.5`}),!E&&`Event`]})]}),j&&(0,Q.jsx)(`p`,{className:`border-b border-border px-3 py-2 text-xs text-destructive`,children:j}),(0,Q.jsxs)(`div`,{className:`flex min-h-0 flex-1`,children:[!T&&(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)(Ye,{month:ie(u),selected:u,onPick:e=>V(e,s===`year`||s===`month`?`day`:s),onPrev:()=>f(e=>ne(e,-1)),onNext:()=>f(e=>ne(e,1))}),oe]}),(0,Q.jsxs)(`div`,{className:`relative min-w-0 flex-1`,children:[se,T&&b&&(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:oe})]}),v&&!T&&(0,Q.jsx)(`aside`,{className:`w-80 shrink-0 border-l border-border bg-card`,children:(0,Q.jsx)(gt,{subject:v,target:t,workspaceName:M?.workspaceName??null,calendars:I,defaultCalendar:r.defaultCalendar,onClose:()=>y(null),onSaved:e=>{e&&o({defaultCalendar:e}),y(null),ee()},onDelete:q})})]}),v&&T&&(0,Q.jsx)(`div`,{className:`absolute inset-0 z-30 flex flex-col bg-card`,children:(0,Q.jsx)(gt,{subject:v,target:t,workspaceName:M?.workspaceName??null,calendars:I,defaultCalendar:r.defaultCalendar,onClose:()=>y(null),onSaved:e=>{e&&o({defaultCalendar:e}),y(null),ee()},onDelete:q})}),!A&&!j&&!k.length&&s!==`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)(h,{className:`mr-1 inline h-3 w-3`}),`Nothing here yet — click or drag a slot to add an event.`]})]})}function Dt(e){let t=new Date,n=e&&!Ot(e,t)?new Date(e.getFullYear(),e.getMonth(),e.getDate(),9,0):new Date(t);return(!e||Ot(e,t))&&n.setMinutes(t.getMinutes()<30?30:60,0,0),n}function Ot(e,t){return e.toDateString()===t.toDateString()}export{Et as CalendarApplet};
@@ -1 +1 @@
1
- import{o as e}from"./rolldown-runtime-C0FnF6B9.js";import{l as t,u as n}from"./code-editor-BOIngd5F.js";import{t as r}from"./socket-CtH3EU9m.js";import{r as i}from"./use-toolbox-Ck_cLGgf.js";import{n as a}from"./use-applet-target-DmIdCxa_.js";import{C as o,M as s,v as c}from"./index-D-y76fV7.js";var l=e(n(),1),u=t();function d(){let e=a(),t=i()?.state,n=!!t&&(e?.mode===`context`?t.activeContextType===`context`&&t.activeContextId===e.contextId:e?.mode===`workspace`?t.activeContextType!==`context`&&t.activeWorkspaceName===e.workspaceName&&t.activeTreeName===e.treeName&&t.activeContextPath===e.path:!t.activeWorkspaceName&&!t.activeContextId),d=!n&&e?.mode===`context`?e.contextId:null;return(0,l.useEffect)(()=>{if(!d)return;let e=`context:${d}`,t=()=>r.emit(`subscribe`,{channel:e}),n=r.on(`connect`,t);return t(),()=>{n(),r.emit(`unsubscribe`,{channel:e})}},[d]),n?(0,u.jsx)(c,{}):(0,u.jsx)(s,{target:e,children:(0,u.jsx)(o,{children:(0,u.jsx)(c,{})})})}export{d as FiltersApplet};
1
+ import{o as e}from"./rolldown-runtime-C0FnF6B9.js";import{l as t,u as n}from"./code-editor-BOIngd5F.js";import{t as r}from"./socket-CtH3EU9m.js";import{r as i}from"./use-toolbox-Ck_cLGgf.js";import{n as a}from"./use-applet-target-DmIdCxa_.js";import{C as o,M as s,v as c}from"./index-BG5J93SO.js";var l=e(n(),1),u=t();function d(){let e=a(),t=i()?.state,n=!!t&&(e?.mode===`context`?t.activeContextType===`context`&&t.activeContextId===e.contextId:e?.mode===`workspace`?t.activeContextType!==`context`&&t.activeWorkspaceName===e.workspaceName&&t.activeTreeName===e.treeName&&t.activeContextPath===e.path:!t.activeWorkspaceName&&!t.activeContextId),d=!n&&e?.mode===`context`?e.contextId:null;return(0,l.useEffect)(()=>{if(!d)return;let e=`context:${d}`,t=()=>r.emit(`subscribe`,{channel:e}),n=r.on(`connect`,t);return t(),()=>{n(),r.emit(`unsubscribe`,{channel:e})}},[d]),n?(0,u.jsx)(c,{}):(0,u.jsx)(s,{target:e,children:(0,u.jsx)(o,{children:(0,u.jsx)(c,{})})})}export{d as FiltersApplet};
@@ -1,3 +1,3 @@
1
- import{o as e}from"./rolldown-runtime-C0FnF6B9.js";import{l as t,u as n}from"./code-editor-BOIngd5F.js";import{yt as r}from"./react-BHzhHVTZ.js";import{g as i}from"./chunk-62JRHF6Z-vspAGgtK.js";import{Gr as a,L as o,Pt as s,U as c,W as l,_n as u,ar as d,hn as f,tt as p}from"./ui-76Hw0NU_.js";import{t as m}from"./utils-2pl1SbIp.js";import{t as h}from"./input-BOtCd4HP.js";import{t as g}from"./label-DJc8-3CQ.js";import{t as _}from"./LinkToCard-VXpoeMDH.js";import{zt as v}from"./workspace-46EFyEKZ.js";import{t as y}from"./use-mobile-Db-vWu9Y.js";import{a as b,i as x,s as S,t as ee}from"./IdentityFields-CEDxU-Hd.js";import{n as C,r as te}from"./use-toolbox-Ck_cLGgf.js";import{c as ne}from"./date-time-picker-Bzu8H_Oa.js";import{n as w,t as re}from"./PickDocumentsCard-B72XNYh3.js";import{t as T}from"./useToastHelpers-CRrpIIdY.js";import{r as E,t as D}from"./note-save-status-DPz4VzL6.js";import{t as O}from"./DocumentBodyEditor-DRFQgBNB.js";import{a as k,i as A,n as j,o as M,r as N,s as P,t as F}from"./UploadProgressList-CHQ-Kn-e.js";import{A as I,O as L,j as R,k as z}from"./index-D-y76fV7.js";var B=e(r(),1),V=e(n(),1),H=t();function U({onClose:e,initialData:t,draftId:n}){let r=z(void 0,void 0,`home-card:${n}`);return(0,V.useEffect)(()=>{t?.title&&r.setTitle(t.title),t?.content&&r.setContent(t.content)},[]),(0,H.jsx)(w,{title:`New Note`,icon:p,onClose:e,onSave:async e=>{let t=await r.save({mode:`workspace`,...e});return r.finish(),t},canSave:r.canSave,saving:r.saving,successMessage:`Note created`,children:(0,H.jsxs)(`div`,{className:`flex h-full flex-col gap-4 p-4`,children:[(0,H.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,H.jsx)(g,{htmlFor:`qa-note-title`,children:`Title`}),(0,H.jsx)(h,{id:`qa-note-title`,value:r.title,onChange:e=>r.setTitle(e.target.value),placeholder:`Optional; defaults to today's date`})]}),(0,H.jsxs)(`div`,{className:`flex flex-1 flex-col gap-1.5`,children:[(0,H.jsx)(g,{children:`Body`}),(0,H.jsx)(`div`,{className:`flex-1`,children:(0,H.jsx)(O,{kind:`markdown`,value:r.content,onChange:r.setContent,placeholder:`Write your note…`})})]}),(0,H.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,H.jsx)(g,{children:`Tags`}),(0,H.jsx)(S,{tags:r.tags,onChange:r.setTags})]}),(0,H.jsx)(D,{...r,onRetry:r.retry}),(0,H.jsx)(P,{geotag:r.geotag,idPrefix:`qa-note-geotag`})]})})}function W({onClose:e,initialData:t}){let n=L();return(0,V.useEffect)(()=>{t?.url&&n.setUrl(t.url),t?.title&&n.setTitle(t.title)},[]),(0,H.jsx)(w,{title:`New Link`,icon:u,onClose:e,onSave:e=>n.save({mode:`workspace`,...e}),canSave:n.canSave,saving:n.saving,successMessage:`Link created`,children:(0,H.jsxs)(`div`,{className:`flex flex-col gap-4 p-4`,children:[(0,H.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,H.jsx)(g,{htmlFor:`qa-link-url`,children:`URL`}),(0,H.jsx)(h,{id:`qa-link-url`,value:n.url,onChange:e=>n.setUrl(e.target.value),placeholder:`https://example.com`,autoFocus:!0}),n.showUrlError&&(0,H.jsx)(`p`,{className:`text-xs text-destructive`,children:`Enter a valid URL, e.g. https://example.com`})]}),(0,H.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,H.jsx)(g,{htmlFor:`qa-link-title`,children:`Title`}),(0,H.jsx)(h,{id:`qa-link-title`,value:n.title,onChange:e=>n.setTitle(e.target.value),placeholder:`Optional display title`})]}),(0,H.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,H.jsx)(g,{children:`Tags`}),(0,H.jsx)(S,{tags:n.tags,onChange:n.setTags})]}),(0,H.jsx)(P,{geotag:n.geotag,idPrefix:`qa-link-geotag`})]})})}function G({onClose:e,initialData:t}){let n=ne();return(0,V.useEffect)(()=>{t?.title&&n.setTitle(t.title),t?.content&&n.setDescription(t.content)},[]),(0,H.jsx)(w,{title:`New Todo`,icon:f,onClose:e,onSave:e=>n.save({mode:`workspace`,...e}),canSave:n.canSave,saving:n.saving,successMessage:`Todo created`,children:(0,H.jsxs)(`div`,{className:`flex h-full flex-col gap-4 p-4`,children:[(0,H.jsx)(b,{...n,idPrefix:`qa-todo`}),(0,H.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,H.jsx)(g,{children:`Tags`}),(0,H.jsx)(S,{tags:n.tags,onChange:n.setTags})]}),(0,H.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,H.jsx)(g,{htmlFor:`qa-todo-comment`,children:`Comment`}),(0,H.jsx)(`textarea`,{id:`qa-todo-comment`,value:n.comment,onChange:e=>n.setComment(e.target.value),rows:3,placeholder:`Optional context`,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`})]}),(0,H.jsx)(P,{geotag:n.geotag,idPrefix:`qa-todo-geotag`})]})})}function K({onClose:e,initialData:t}){let n=x();return(0,V.useEffect)(()=>{t?.title&&n.setDisplayName(t.title)},[]),(0,H.jsx)(w,{title:`New Identity`,icon:c,onClose:e,onSave:e=>n.save({mode:`workspace`,...e}),canSave:n.canSave,saving:n.saving,successMessage:`Identity created`,children:(0,H.jsxs)(`div`,{className:`flex h-full flex-col gap-4 p-4`,children:[(0,H.jsx)(ee,{idPrefix:`qa-identity`,...n,emailValid:n.emailValid}),(0,H.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,H.jsx)(g,{children:`Tags`}),(0,H.jsx)(S,{tags:n.tags,onChange:n.setTags})]}),(0,H.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,H.jsx)(g,{htmlFor:`qa-identity-comment`,children:`Comment`}),(0,H.jsx)(`textarea`,{id:`qa-identity-comment`,value:n.comment,onChange:e=>n.setComment(e.target.value),rows:3,placeholder:`How you know them, where they came from…`,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`})]})]})})}var q={jpg:`image/jpeg`,jpeg:`image/jpeg`,png:`image/png`,gif:`image/gif`,webp:`image/webp`,avif:`image/avif`,heic:`image/heic`,heif:`image/heif`,bmp:`image/bmp`,tif:`image/tiff`,tiff:`image/tiff`,svg:`image/svg+xml`,mp4:`video/mp4`,mov:`video/quicktime`,webm:`video/webm`,"3gp":`video/3gpp`};function J(e){return/^(image|video)\//.test(e.type)}async function Y(e){let t=await Promise.all(e.map(async e=>{let t=new Uint8Array(await e.slice(0,64).arrayBuffer()),n=(e,n)=>String.fromCharCode(...t.slice(e,e+n)),r=``;if(t[0]===255&&t[1]===216&&t[2]===255)r=`image/jpeg`;else if(n(0,8)===`‰PNG\r
1
+ import{o as e}from"./rolldown-runtime-C0FnF6B9.js";import{l as t,u as n}from"./code-editor-BOIngd5F.js";import{yt as r}from"./react-BHzhHVTZ.js";import{g as i}from"./chunk-62JRHF6Z-vspAGgtK.js";import{Gr as a,L as o,Pt as s,U as c,W as l,_n as u,ar as d,hn as f,tt as p}from"./ui-76Hw0NU_.js";import{t as m}from"./utils-2pl1SbIp.js";import{t as h}from"./input-BOtCd4HP.js";import{t as g}from"./label-DJc8-3CQ.js";import{t as _}from"./LinkToCard-VXpoeMDH.js";import{zt as v}from"./workspace-46EFyEKZ.js";import{t as y}from"./use-mobile-Db-vWu9Y.js";import{a as b,i as x,s as S,t as ee}from"./IdentityFields-CEDxU-Hd.js";import{n as C,r as te}from"./use-toolbox-Ck_cLGgf.js";import{c as ne}from"./date-time-picker-Bzu8H_Oa.js";import{n as w,t as re}from"./PickDocumentsCard-B72XNYh3.js";import{t as T}from"./useToastHelpers-CRrpIIdY.js";import{r as E,t as D}from"./note-save-status-DPz4VzL6.js";import{t as O}from"./DocumentBodyEditor-DRFQgBNB.js";import{a as k,i as A,n as j,o as M,r as N,s as P,t as F}from"./UploadProgressList-CHQ-Kn-e.js";import{A as I,O as L,j as R,k as z}from"./index-BG5J93SO.js";var B=e(r(),1),V=e(n(),1),H=t();function U({onClose:e,initialData:t,draftId:n}){let r=z(void 0,void 0,`home-card:${n}`);return(0,V.useEffect)(()=>{t?.title&&r.setTitle(t.title),t?.content&&r.setContent(t.content)},[]),(0,H.jsx)(w,{title:`New Note`,icon:p,onClose:e,onSave:async e=>{let t=await r.save({mode:`workspace`,...e});return r.finish(),t},canSave:r.canSave,saving:r.saving,successMessage:`Note created`,children:(0,H.jsxs)(`div`,{className:`flex h-full flex-col gap-4 p-4`,children:[(0,H.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,H.jsx)(g,{htmlFor:`qa-note-title`,children:`Title`}),(0,H.jsx)(h,{id:`qa-note-title`,value:r.title,onChange:e=>r.setTitle(e.target.value),placeholder:`Optional; defaults to today's date`})]}),(0,H.jsxs)(`div`,{className:`flex flex-1 flex-col gap-1.5`,children:[(0,H.jsx)(g,{children:`Body`}),(0,H.jsx)(`div`,{className:`flex-1`,children:(0,H.jsx)(O,{kind:`markdown`,value:r.content,onChange:r.setContent,placeholder:`Write your note…`})})]}),(0,H.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,H.jsx)(g,{children:`Tags`}),(0,H.jsx)(S,{tags:r.tags,onChange:r.setTags})]}),(0,H.jsx)(D,{...r,onRetry:r.retry}),(0,H.jsx)(P,{geotag:r.geotag,idPrefix:`qa-note-geotag`})]})})}function W({onClose:e,initialData:t}){let n=L();return(0,V.useEffect)(()=>{t?.url&&n.setUrl(t.url),t?.title&&n.setTitle(t.title)},[]),(0,H.jsx)(w,{title:`New Link`,icon:u,onClose:e,onSave:e=>n.save({mode:`workspace`,...e}),canSave:n.canSave,saving:n.saving,successMessage:`Link created`,children:(0,H.jsxs)(`div`,{className:`flex flex-col gap-4 p-4`,children:[(0,H.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,H.jsx)(g,{htmlFor:`qa-link-url`,children:`URL`}),(0,H.jsx)(h,{id:`qa-link-url`,value:n.url,onChange:e=>n.setUrl(e.target.value),placeholder:`https://example.com`,autoFocus:!0}),n.showUrlError&&(0,H.jsx)(`p`,{className:`text-xs text-destructive`,children:`Enter a valid URL, e.g. https://example.com`})]}),(0,H.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,H.jsx)(g,{htmlFor:`qa-link-title`,children:`Title`}),(0,H.jsx)(h,{id:`qa-link-title`,value:n.title,onChange:e=>n.setTitle(e.target.value),placeholder:`Optional display title`})]}),(0,H.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,H.jsx)(g,{children:`Tags`}),(0,H.jsx)(S,{tags:n.tags,onChange:n.setTags})]}),(0,H.jsx)(P,{geotag:n.geotag,idPrefix:`qa-link-geotag`})]})})}function G({onClose:e,initialData:t}){let n=ne();return(0,V.useEffect)(()=>{t?.title&&n.setTitle(t.title),t?.content&&n.setDescription(t.content)},[]),(0,H.jsx)(w,{title:`New Todo`,icon:f,onClose:e,onSave:e=>n.save({mode:`workspace`,...e}),canSave:n.canSave,saving:n.saving,successMessage:`Todo created`,children:(0,H.jsxs)(`div`,{className:`flex h-full flex-col gap-4 p-4`,children:[(0,H.jsx)(b,{...n,idPrefix:`qa-todo`}),(0,H.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,H.jsx)(g,{children:`Tags`}),(0,H.jsx)(S,{tags:n.tags,onChange:n.setTags})]}),(0,H.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,H.jsx)(g,{htmlFor:`qa-todo-comment`,children:`Comment`}),(0,H.jsx)(`textarea`,{id:`qa-todo-comment`,value:n.comment,onChange:e=>n.setComment(e.target.value),rows:3,placeholder:`Optional context`,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`})]}),(0,H.jsx)(P,{geotag:n.geotag,idPrefix:`qa-todo-geotag`})]})})}function K({onClose:e,initialData:t}){let n=x();return(0,V.useEffect)(()=>{t?.title&&n.setDisplayName(t.title)},[]),(0,H.jsx)(w,{title:`New Identity`,icon:c,onClose:e,onSave:e=>n.save({mode:`workspace`,...e}),canSave:n.canSave,saving:n.saving,successMessage:`Identity created`,children:(0,H.jsxs)(`div`,{className:`flex h-full flex-col gap-4 p-4`,children:[(0,H.jsx)(ee,{idPrefix:`qa-identity`,...n,emailValid:n.emailValid}),(0,H.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,H.jsx)(g,{children:`Tags`}),(0,H.jsx)(S,{tags:n.tags,onChange:n.setTags})]}),(0,H.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,H.jsx)(g,{htmlFor:`qa-identity-comment`,children:`Comment`}),(0,H.jsx)(`textarea`,{id:`qa-identity-comment`,value:n.comment,onChange:e=>n.setComment(e.target.value),rows:3,placeholder:`How you know them, where they came from…`,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`})]})]})})}var q={jpg:`image/jpeg`,jpeg:`image/jpeg`,png:`image/png`,gif:`image/gif`,webp:`image/webp`,avif:`image/avif`,heic:`image/heic`,heif:`image/heif`,bmp:`image/bmp`,tif:`image/tiff`,tiff:`image/tiff`,svg:`image/svg+xml`,mp4:`video/mp4`,mov:`video/quicktime`,webm:`video/webm`,"3gp":`video/3gpp`};function J(e){return/^(image|video)\//.test(e.type)}async function Y(e){let t=await Promise.all(e.map(async e=>{let t=new Uint8Array(await e.slice(0,64).arrayBuffer()),n=(e,n)=>String.fromCharCode(...t.slice(e,e+n)),r=``;if(t[0]===255&&t[1]===216&&t[2]===255)r=`image/jpeg`;else if(n(0,8)===`‰PNG\r
2
2
  
3
3
  `)r=`image/png`;else if([`GIF87a`,`GIF89a`].includes(n(0,6)))r=`image/gif`;else if(n(0,4)===`RIFF`&&n(8,4)===`WEBP`)r=`image/webp`;else if(n(0,5)===`%PDF-`)r=`application/pdf`;else if(n(0,4)===`PK`)r=`application/zip`;else if(n(4,4)===`ftyp`){let e=[n(8,4)],i=new DataView(t.buffer).getUint32(0);for(let r=16;r+4<=Math.min(t.length,i);r+=4)e.push(n(r,4));e.some(e=>[`avif`,`avis`].includes(e))?r=`image/avif`:e.some(e=>[`heic`,`heix`,`hevc`,`hevx`].includes(e))?r=`image/heic`:e.some(e=>[`mif1`,`msf1`].includes(e))?r=`image/heif`:e.includes(`qt `)?r=`video/quicktime`:e.some(e=>[`isom`,`iso2`,`mp41`,`mp42`,`avc1`,`M4V `].includes(e))&&(r=`video/mp4`)}let i=e.type.toLowerCase().split(`;`)[0].trim(),a=!i||[`application/octet-stream`,`binary/octet-stream`,`*/*`].includes(i),o=e.name.split(`.`).pop()?.toLowerCase()??``,s=r||a&&q[o]||i;return s===e.type?e:new File([e],e.name,{type:s,lastModified:e.lastModified})}));return{kind:t.length>0&&t.every(J)?`photo`:`file`,files:t}}function X({file:e}){let t=(0,V.useRef)(null),[n,r]=(0,V.useState)(!1);return(0,V.useEffect)(()=>{let n=t.current;if(!n)return;let r=URL.createObjectURL(e);return n.src=r,()=>{n.removeAttribute(`src`),URL.revokeObjectURL(r)}},[e]),(0,H.jsx)(`div`,{className:`flex min-h-24 items-center justify-center overflow-hidden rounded-md border border-input bg-muted/30`,children:n?(0,H.jsxs)(`p`,{className:`p-4 text-center text-sm text-muted-foreground`,children:[`Preview unavailable for `,e.name,`. You can still save the original.`]}):e.type.startsWith(`video/`)?(0,H.jsx)(`video`,{ref:t,controls:!0,preload:`metadata`,"aria-label":e.name,onError:()=>r(!0),className:`max-h-64 max-w-full`}):(0,H.jsx)(`img`,{ref:t,alt:e.name,onError:()=>r(!0),className:`max-h-64 max-w-full object-contain`})})}function ie({onClose:e,initialData:t}){let n=(0,V.useRef)(null),r=N(t?.files),i=r.items.map(e=>e.file),[a,o]=(0,V.useState)(!1),[s,c]=(0,V.useState)(!1),{state:u}=C(),d=M(u.activeWorkspaceName),f=e=>{e&&(s||r.addFiles(Array.from(e)))},p=e=>{e.preventDefault(),o(!1),f(e.dataTransfer.files)},h=i.length>0;return(0,H.jsx)(w,{title:`Upload File`,icon:l,onClose:e,onSave:async e=>{c(!0);try{let t={mode:`workspace`,...e},n=await d.geotag.capture(),i=await r.start(t,(e,t)=>k(e,t,{tags:d.tags,comment:d.comment,geo:n}));if(i.failed)throw Error(`${i.failed} file(s) failed or cancelled. Retry keeps completed uploads.`);return i.docIds}finally{c(!1)}},navigateAfterSave:!0,canSave:h,saving:s,saveProgress:(0,H.jsx)(j,{items:r.items,running:r.running,onCancel:r.cancel}),successMessage:`File(s) uploaded`,children:(0,H.jsxs)(`div`,{className:`flex flex-col gap-4 p-4`,children:[(0,H.jsxs)(`div`,{onDragOver:e=>{e.preventDefault(),o(!0)},onDragLeave:()=>o(!1),onDrop:p,onClick:()=>n.current?.click(),className:m(`flex cursor-pointer flex-col items-center justify-center gap-2 rounded-md border border-dashed px-4 py-8 text-center transition-colors`,a?`border-primary bg-primary/5`:`border-input hover:bg-muted/40`),children:[(0,H.jsx)(l,{className:`h-6 w-6 text-muted-foreground touch-target`}),(0,H.jsx)(`p`,{className:`text-sm`,children:`Drag & drop files here`}),(0,H.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`or click to browse`}),(0,H.jsx)(`input`,{ref:n,type:`file`,multiple:!0,disabled:s,className:`hidden`,onChange:e=>{f(e.target.files),e.target.value=``}})]}),r.items.filter(e=>J(e.file)).map(e=>(0,H.jsx)(X,{file:e.file},e.id)),(0,H.jsx)(F,{items:r.items,running:s,onRemove:r.removeItem}),(0,H.jsx)(A,{fields:d,idPrefix:`qa-file`,multiple:i.length>1})]})})}function ae({onClose:e,initialData:t}){let n=N(t?.files),r=(0,V.useRef)(null),i=n.items.length>0,[s,c]=(0,V.useState)(!1),{state:l}=C(),u=M(l.activeWorkspaceName),f=e=>{!s&&e&&n.addFiles([e])};return(0,H.jsx)(w,{title:`Photo/Video`,icon:a,onClose:e,onSave:async e=>{if(!i)return[];c(!0);try{let t=await u.geotag.capture(),r={mode:`workspace`,...e},i=await n.start(r,(e,n)=>k(e,n,{tags:u.tags,comment:u.comment,geo:t}));if(i.failed)throw Error(`Upload failed or cancelled. You can retry.`);return i.docIds}finally{c(!1)}},navigateAfterSave:!0,canSave:i,saving:s,saveProgress:(0,H.jsx)(j,{items:n.items,running:n.running,onCancel:n.cancel}),successMessage:`Upload saved`,children:(0,H.jsxs)(`div`,{className:m(`flex h-full flex-col gap-4 p-4`,!i&&`items-center justify-center`),children:[i?(0,H.jsxs)(H.Fragment,{children:[(0,H.jsx)(`div`,{className:`flex min-h-0 w-full flex-1 flex-col gap-3 overflow-y-auto`,children:n.items.map(({id:e,file:t,status:r})=>(0,H.jsxs)(`div`,{className:`space-y-2`,children:[(0,H.jsx)(X,{file:t}),(0,H.jsxs)(`div`,{className:`flex w-full items-center gap-2 rounded border border-input px-3 py-2 text-sm`,children:[(0,H.jsx)(d,{className:`h-4 w-4 shrink-0 text-muted-foreground`}),(0,H.jsx)(`span`,{className:`flex-1 truncate`,children:t.name}),(0,H.jsxs)(`span`,{className:`shrink-0 text-xs text-muted-foreground`,children:[(t.size/1024/1024).toFixed(1),` MB`]}),(0,H.jsx)(`button`,{type:`button`,disabled:s||r===`done`,onClick:()=>n.removeItem(e),"aria-label":`Remove ${t.name}`,className:`text-muted-foreground hover:text-foreground disabled:opacity-40`,children:(0,H.jsx)(o,{className:`h-3.5 w-3.5`})})]})]},e))}),(0,H.jsx)(`div`,{className:`w-full shrink-0 space-y-4`,children:(0,H.jsx)(A,{fields:u,idPrefix:`qa-photo`,multiple:n.items.length>1})})]}):(0,H.jsxs)(`button`,{type:`button`,onClick:()=>r.current?.click(),className:`flex flex-col items-center gap-2 rounded-md border border-dashed border-input px-6 py-10 text-center transition-colors hover:bg-muted/40`,children:[(0,H.jsx)(a,{className:`h-8 w-8 text-muted-foreground`}),(0,H.jsx)(`span`,{className:`text-sm`,children:`Open camera`})]}),(0,H.jsx)(`input`,{ref:r,type:`file`,accept:`image/*,video/*`,capture:`environment`,className:`hidden`,disabled:s,onChange:e=>{f(e.target.files?.[0]??null),e.target.value=``}})]})})}var Z=`shrink-0 h-viewport-card w-[min(380px,90vw)] max-md:fixed max-md:inset-2 max-md:z-40 max-md:h-auto max-md:w-auto max-md:shadow-elevation-5`;function oe({onClose:e}){let{showSuccessToast:t,showErrorToast:n}=T(),[r,i]=(0,V.useState)(null),[a,o]=(0,V.useState)(!1);return r?(0,H.jsx)(_,{sizeClassName:Z,documentCount:r.length,saving:a,onClose:e,onConfirm:async(i,a)=>{o(!0);try{await Promise.all(i.map(e=>v(a.workspaceName,e,r,a.treeName,a.treeType))),t(`${r.length} document${r.length===1?``:`s`} linked`),e()}catch(e){n(e instanceof Error?e.message:`Failed to link documents`)}finally{o(!1)}}}):(0,H.jsx)(re,{sizeClassName:Z,onConfirm:e=>{e.length&&i(e)},onClose:e})}function Q(){let e=E(`new:home-card:`);try{return Object.keys(localStorage).filter(t=>t.startsWith(e)&&t.endsWith(`:home`)).filter(e=>{let t=JSON.parse(localStorage.getItem(e)||`null`)?.value;return t&&(t.title||t.content||t.comment||t.tags?.length)}).map(t=>t.slice(e.length,-5))}catch{return[]}}var $=0;function se(){return $+=1,`card-${$}`}function ce({initialKind:e,initialData:t,onInitialCardClose:n,onCardsOpenChange:r}){let[a,c]=(0,V.useState)(!1),l=y(),u=te(),d=!!(u?.state.t1Open||u?.state.addOpen),[f,p]=(0,V.useState)(()=>e?[{id:`initial`,kind:e,initialData:t,noteDraftId:crypto.randomUUID()}]:Q().map(e=>({id:e,kind:`note`,noteDraftId:e}))),h=f.length>0,g=(0,V.useRef)(r);(0,V.useEffect)(()=>{g.current=r},[r]),(0,V.useEffect)(()=>{g.current?.(h)},[h]),d&&a&&c(!1);let _=i(),v=e=>{if(e===`sketch`){c(!1),_(R.createUrl(null));return}let t=e===`note`?Q().find(e=>!f.some(t=>t.noteDraftId===e))||crypto.randomUUID():void 0;p(n=>[...n,{id:se(),kind:e,noteDraftId:t}]),c(!1)},b=e=>{p(t=>t.filter(t=>t.id!==e)),e===`initial`&&n?.()},x=(0,H.jsxs)(`div`,{className:m(`pointer-events-none fixed right-6 z-40 flex flex-col items-end gap-2`,`bottom-fab-inset md:bottom-[calc(var(--spacing-fab-inset)+5rem)]`,f.length>0&&`max-md:hidden`,d&&`hidden`),children:[(0,H.jsx)(`div`,{className:m(`flex flex-col items-end gap-2 transition-all duration-fast`,a?`pointer-events-auto opacity-100`:`pointer-events-none translate-y-2 opacity-0`),children:(0,H.jsx)(I,{variant:`stack`,omit:[`plaintext`,`folder`,`message`],onSelect:v})}),(0,H.jsx)(`div`,{className:`pointer-events-none flex w-16 justify-center`,children:(0,H.jsx)(`button`,{type:`button`,onClick:()=>c(e=>!e),"aria-label":a?`Close quick add`:`Quick add`,className:`pointer-events-auto flex h-11 w-11 items-center justify-center rounded-full bg-primary text-primary-foreground shadow-elevation-3 transition-transform hover:scale-105`,children:a?(0,H.jsx)(o,{className:`h-5 w-5`}):(0,H.jsx)(s,{className:`h-5 w-5`})})})]});return(0,H.jsxs)(`div`,{className:`relative flex h-full w-full flex-col`,children:[f.length>0&&(0,H.jsx)(`div`,{className:`pointer-events-auto flex flex-1 items-center gap-4 overflow-x-auto p-6 md:pr-28`,children:f.map(e=>{let t=()=>b(e.id);switch(e.kind){case`note`:return(0,H.jsx)(U,{draftId:e.noteDraftId,onClose:t,initialData:e.initialData},e.id);case`link`:return(0,H.jsx)(W,{onClose:t,initialData:e.initialData},e.id);case`todo`:return(0,H.jsx)(G,{onClose:t,initialData:e.initialData},e.id);case`identity`:return(0,H.jsx)(K,{onClose:t,initialData:e.initialData},e.id);case`file`:return(0,H.jsx)(ie,{onClose:t,initialData:e.initialData},e.id);case`photo`:return(0,H.jsx)(ae,{onClose:t,initialData:e.initialData},e.id);case`existing`:return(0,H.jsx)(oe,{onClose:t},e.id);case`sketch`:return null;case`folder`:case`message`:return null}})}),l?(0,B.createPortal)(x,document.body):x]})}export{Y as n,ce as t};
@@ -1 +1 @@
1
- import{o as e}from"./rolldown-runtime-C0FnF6B9.js";import{l as t,u as n}from"./code-editor-BOIngd5F.js";import{$n as r,Gr as i,Nr as a,Xt as o}from"./ui-76Hw0NU_.js";import{t as s}from"./utils-2pl1SbIp.js";import{An as c,Nn as l}from"./workspace-46EFyEKZ.js";import{t as u}from"./useDocumentThumbnail-Bs2Ju0eb.js";import{t as d}from"./DocumentIcon-ByDAILhm.js";import{n as f}from"./use-document-modal-PG8bQyIB.js";import{n as p}from"./use-applet-target-DmIdCxa_.js";import{D as m,E as h,S as g,T as _,b as v,w as y,x as b}from"./index-D-y76fV7.js";var x=e(n(),1),S=t(),C=`h-8 rounded-md border border-input bg-transparent px-2 text-xs outline-none focus-visible:ring-2 focus-visible:ring-ring`,w=`h-8 rounded-md border border-input bg-transparent px-2 text-xs outline-none focus-visible:ring-1 focus-visible:ring-ring`;function T({workspaceRef:e,doc:t,distance:n,onOpen:r}){let i=l(t),{blobUrl:a}=u(e,t.id,256,{enabled:i}),o=c(t);return(0,S.jsxs)(`button`,{type:`button`,onClick:()=>r(t),title:`Open ${o.title}`,className:`rounded-(--card-radius) border border-border bg-card overflow-hidden flex flex-col text-left cursor-pointer transition-colors hover:border-foreground/30 hover:bg-muted/40 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring`,children:[(0,S.jsx)(`div`,{className:`aspect-square bg-muted/40 flex items-center justify-center overflow-hidden`,children:i&&a?(0,S.jsx)(`img`,{src:a,alt:o.title,className:`h-full w-full object-cover`}):(0,S.jsx)(d,{document:t,size:10})}),(0,S.jsxs)(`div`,{className:`p-2 min-w-0`,children:[(0,S.jsx)(`div`,{className:`text-xs font-medium truncate`,title:o.title,children:o.title}),(0,S.jsxs)(`div`,{className:`text-[10px] text-muted-foreground truncate`,children:[o.schemaLabel,n==null?``:` · d=${n.toFixed(3)}`]})]})]})}function E(){let e=p(),t=f(),n=h(),{rateMs:c,setRateMs:l,text:u,setText:d,maxDistance:E,setMaxDistance:D,latencyMs:O,error:k}=n,A=e?.mode===`workspace`?e.workspaceName:``,j=e?.mode===`workspace`&&e.path!==`/`?e.path:null,M=n.running&&n.consumer===`applet`,N=n.running&&n.consumer!==`applet`,P=M?n.hits:[];m(M);let F=M?n.snapshotSize??n.camera?.size:null,I=!!F&&F.height>F.width,L=e=>{A&&n.start(e,`applet`,{workspaceRef:A,contextPath:j})},{setContextPath:R}=n;return(0,x.useEffect)(()=>{M&&R(j)},[M,j,R]),e?.mode===`workspace`?(0,S.jsxs)(`div`,{className:`flex h-full min-h-0 flex-col gap-3 overflow-y-auto p-3`,children:[(0,S.jsxs)(`div`,{className:`flex shrink-0 flex-wrap items-center gap-2`,children:[(0,S.jsx)(`select`,{className:C,value:c,onChange:e=>l(Number(e.target.value)),title:`Frame rate. High rates (10–30 fps) are experimental; the loop never overlaps requests, so the effective rate is capped by search latency.`,children:_.map(e=>(0,S.jsx)(`option`,{value:e.ms,children:e.label},e.ms))}),(0,S.jsx)(`input`,{className:s(w,`w-44`),placeholder:`Optional text (fused mode)`,value:u,onChange:e=>d(e.target.value)}),(0,S.jsx)(`input`,{className:s(w,`w-28`),placeholder:`max distance`,inputMode:`decimal`,value:E,onChange:e=>D(e.target.value),title:`Cosine-distance floor (0 = identical). Empty = top-K.`}),M?(0,S.jsxs)(`button`,{type:`button`,onClick:n.stop,className:`flex h-8 items-center gap-1 rounded-md bg-destructive px-3 text-xs font-medium text-destructive-foreground transition-colors hover:bg-destructive/90`,children:[(0,S.jsx)(a,{className:`h-3.5 w-3.5`}),` `,n.source===`photo`?`Close photo`:`Stop`]}):(0,S.jsxs)(S.Fragment,{children:[(0,S.jsxs)(`button`,{type:`button`,onClick:()=>L(`camera`),disabled:N,className:`flex h-8 items-center gap-1 rounded-md bg-foreground px-3 text-xs font-medium text-background transition-colors hover:bg-foreground/90 disabled:opacity-50`,children:[(0,S.jsx)(i,{className:`h-3.5 w-3.5`}),` Camera`]}),(0,S.jsxs)(`button`,{type:`button`,onClick:()=>L(`screen`),disabled:N,className:`flex h-8 items-center gap-1 rounded-md bg-foreground px-3 text-xs font-medium text-background transition-colors hover:bg-foreground/90 disabled:opacity-50`,children:[(0,S.jsx)(o,{className:`h-3.5 w-3.5`}),` Desktop`]})]}),(0,S.jsx)(b,{consumer:`applet`,workspaceRef:A,contextPath:j,disabled:N,className:`flex h-8 items-center gap-1 rounded-md bg-foreground px-3 text-xs font-medium text-background transition-colors hover:bg-foreground/90 disabled:opacity-50`})]}),(0,S.jsxs)(`div`,{className:s(`relative shrink-0 overflow-hidden rounded-xl border border-border bg-black/80`,I?`aspect-[3/4] max-h-[60vh]`:`aspect-video max-h-80`),children:[M&&(0,S.jsx)(y,{className:`h-full w-full`,interactive:!0}),M&&(0,S.jsx)(g,{}),!M&&(0,S.jsxs)(`div`,{className:`absolute inset-0 flex items-center justify-center text-sm text-muted-foreground`,children:[(0,S.jsx)(r,{className:`mr-2 h-4 w-4`}),` camera off · or pick a photo`]})]}),M&&(0,S.jsx)(v,{className:`shrink-0`}),(0,S.jsx)(`div`,{className:`shrink-0 text-xs text-muted-foreground`,children:k?(0,S.jsx)(`span`,{className:`text-destructive`,children:k}):M?(0,S.jsxs)(S.Fragment,{children:[n.snapshot?`snapshot`:`live`,` · `,O==null?`searching…`:`${O} ms/frame`,` · `,P.length,` match`,P.length===1?``:`es`,j?` · scoped to ${j}`:``]}):N?`The Lens filter is using the camera. Stop it there first.`:`Frames are ephemeral: embedded for the query, never stored or indexed.`}),P.length===0?(0,S.jsx)(`div`,{className:`flex min-h-24 flex-1 items-center justify-center rounded-xl border border-dashed border-border text-sm text-muted-foreground`,children:M?n.snapshot?`Nothing similar in the snapshot`:`Nothing matching in view`:`Matches appear here`}):(0,S.jsx)(`div`,{className:`grid grid-cols-2 gap-3 sm:grid-cols-3 lg:grid-cols-4`,children:P.map(e=>(0,S.jsx)(T,{workspaceRef:A,doc:e.doc,distance:e.distance,onOpen:e=>t.open(e,A)},e.doc.id))})]}):(0,S.jsx)(`div`,{className:`flex h-full items-center justify-center p-6 text-center text-sm text-muted-foreground`,children:`Lens searches a workspace. Bind it to a workspace path to start.`})}export{E as LensApplet};
1
+ import{o as e}from"./rolldown-runtime-C0FnF6B9.js";import{l as t,u as n}from"./code-editor-BOIngd5F.js";import{$n as r,Gr as i,Nr as a,Xt as o}from"./ui-76Hw0NU_.js";import{t as s}from"./utils-2pl1SbIp.js";import{An as c,Nn as l}from"./workspace-46EFyEKZ.js";import{t as u}from"./useDocumentThumbnail-Bs2Ju0eb.js";import{t as d}from"./DocumentIcon-ByDAILhm.js";import{n as f}from"./use-document-modal-PG8bQyIB.js";import{n as p}from"./use-applet-target-DmIdCxa_.js";import{D as m,E as h,S as g,T as _,b as v,w as y,x as b}from"./index-BG5J93SO.js";var x=e(n(),1),S=t(),C=`h-8 rounded-md border border-input bg-transparent px-2 text-xs outline-none focus-visible:ring-2 focus-visible:ring-ring`,w=`h-8 rounded-md border border-input bg-transparent px-2 text-xs outline-none focus-visible:ring-1 focus-visible:ring-ring`;function T({workspaceRef:e,doc:t,distance:n,onOpen:r}){let i=l(t),{blobUrl:a}=u(e,t.id,256,{enabled:i}),o=c(t);return(0,S.jsxs)(`button`,{type:`button`,onClick:()=>r(t),title:`Open ${o.title}`,className:`rounded-(--card-radius) border border-border bg-card overflow-hidden flex flex-col text-left cursor-pointer transition-colors hover:border-foreground/30 hover:bg-muted/40 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring`,children:[(0,S.jsx)(`div`,{className:`aspect-square bg-muted/40 flex items-center justify-center overflow-hidden`,children:i&&a?(0,S.jsx)(`img`,{src:a,alt:o.title,className:`h-full w-full object-cover`}):(0,S.jsx)(d,{document:t,size:10})}),(0,S.jsxs)(`div`,{className:`p-2 min-w-0`,children:[(0,S.jsx)(`div`,{className:`text-xs font-medium truncate`,title:o.title,children:o.title}),(0,S.jsxs)(`div`,{className:`text-[10px] text-muted-foreground truncate`,children:[o.schemaLabel,n==null?``:` · d=${n.toFixed(3)}`]})]})]})}function E(){let e=p(),t=f(),n=h(),{rateMs:c,setRateMs:l,text:u,setText:d,maxDistance:E,setMaxDistance:D,latencyMs:O,error:k}=n,A=e?.mode===`workspace`?e.workspaceName:``,j=e?.mode===`workspace`&&e.path!==`/`?e.path:null,M=n.running&&n.consumer===`applet`,N=n.running&&n.consumer!==`applet`,P=M?n.hits:[];m(M);let F=M?n.snapshotSize??n.camera?.size:null,I=!!F&&F.height>F.width,L=e=>{A&&n.start(e,`applet`,{workspaceRef:A,contextPath:j})},{setContextPath:R}=n;return(0,x.useEffect)(()=>{M&&R(j)},[M,j,R]),e?.mode===`workspace`?(0,S.jsxs)(`div`,{className:`flex h-full min-h-0 flex-col gap-3 overflow-y-auto p-3`,children:[(0,S.jsxs)(`div`,{className:`flex shrink-0 flex-wrap items-center gap-2`,children:[(0,S.jsx)(`select`,{className:C,value:c,onChange:e=>l(Number(e.target.value)),title:`Frame rate. High rates (10–30 fps) are experimental; the loop never overlaps requests, so the effective rate is capped by search latency.`,children:_.map(e=>(0,S.jsx)(`option`,{value:e.ms,children:e.label},e.ms))}),(0,S.jsx)(`input`,{className:s(w,`w-44`),placeholder:`Optional text (fused mode)`,value:u,onChange:e=>d(e.target.value)}),(0,S.jsx)(`input`,{className:s(w,`w-28`),placeholder:`max distance`,inputMode:`decimal`,value:E,onChange:e=>D(e.target.value),title:`Cosine-distance floor (0 = identical). Empty = top-K.`}),M?(0,S.jsxs)(`button`,{type:`button`,onClick:n.stop,className:`flex h-8 items-center gap-1 rounded-md bg-destructive px-3 text-xs font-medium text-destructive-foreground transition-colors hover:bg-destructive/90`,children:[(0,S.jsx)(a,{className:`h-3.5 w-3.5`}),` `,n.source===`photo`?`Close photo`:`Stop`]}):(0,S.jsxs)(S.Fragment,{children:[(0,S.jsxs)(`button`,{type:`button`,onClick:()=>L(`camera`),disabled:N,className:`flex h-8 items-center gap-1 rounded-md bg-foreground px-3 text-xs font-medium text-background transition-colors hover:bg-foreground/90 disabled:opacity-50`,children:[(0,S.jsx)(i,{className:`h-3.5 w-3.5`}),` Camera`]}),(0,S.jsxs)(`button`,{type:`button`,onClick:()=>L(`screen`),disabled:N,className:`flex h-8 items-center gap-1 rounded-md bg-foreground px-3 text-xs font-medium text-background transition-colors hover:bg-foreground/90 disabled:opacity-50`,children:[(0,S.jsx)(o,{className:`h-3.5 w-3.5`}),` Desktop`]})]}),(0,S.jsx)(b,{consumer:`applet`,workspaceRef:A,contextPath:j,disabled:N,className:`flex h-8 items-center gap-1 rounded-md bg-foreground px-3 text-xs font-medium text-background transition-colors hover:bg-foreground/90 disabled:opacity-50`})]}),(0,S.jsxs)(`div`,{className:s(`relative shrink-0 overflow-hidden rounded-xl border border-border bg-black/80`,I?`aspect-[3/4] max-h-[60vh]`:`aspect-video max-h-80`),children:[M&&(0,S.jsx)(y,{className:`h-full w-full`,interactive:!0}),M&&(0,S.jsx)(g,{}),!M&&(0,S.jsxs)(`div`,{className:`absolute inset-0 flex items-center justify-center text-sm text-muted-foreground`,children:[(0,S.jsx)(r,{className:`mr-2 h-4 w-4`}),` camera off · or pick a photo`]})]}),M&&(0,S.jsx)(v,{className:`shrink-0`}),(0,S.jsx)(`div`,{className:`shrink-0 text-xs text-muted-foreground`,children:k?(0,S.jsx)(`span`,{className:`text-destructive`,children:k}):M?(0,S.jsxs)(S.Fragment,{children:[n.snapshot?`snapshot`:`live`,` · `,O==null?`searching…`:`${O} ms/frame`,` · `,P.length,` match`,P.length===1?``:`es`,j?` · scoped to ${j}`:``]}):N?`The Lens filter is using the camera. Stop it there first.`:`Frames are ephemeral: embedded for the query, never stored or indexed.`}),P.length===0?(0,S.jsx)(`div`,{className:`flex min-h-24 flex-1 items-center justify-center rounded-xl border border-dashed border-border text-sm text-muted-foreground`,children:M?n.snapshot?`Nothing similar in the snapshot`:`Nothing matching in view`:`Matches appear here`}):(0,S.jsx)(`div`,{className:`grid grid-cols-2 gap-3 sm:grid-cols-3 lg:grid-cols-4`,children:P.map(e=>(0,S.jsx)(T,{workspaceRef:A,doc:e.doc,distance:e.distance,onOpen:e=>t.open(e,A)},e.doc.id))})]}):(0,S.jsx)(`div`,{className:`flex h-full items-center justify-center p-6 text-center text-sm text-muted-foreground`,children:`Lens searches a workspace. Bind it to a workspace path to start.`})}export{E as LensApplet};
@@ -1 +1 @@
1
- import{o as e}from"./rolldown-runtime-C0FnF6B9.js";import{l as t,u as n}from"./code-editor-BOIngd5F.js";import{L as r,Pt as i,ci as a,mi as o,pn as s,yt as c}from"./ui-76Hw0NU_.js";import{t as l}from"./utils-2pl1SbIp.js";import{Bn as u}from"./workspace-46EFyEKZ.js";import{t as d}from"./useAddTarget-D4ra50Am.js";import{t as f}from"./note-save-status-DPz4VzL6.js";import{t as p}from"./useEditNoteFields-CKYMBf8V.js";import{n as m}from"./use-applet-target-DmIdCxa_.js";import{k as h}from"./index-D-y76fV7.js";import{n as g,r as _,t as v}from"./shared-C-uHNNY8.js";import{n as y,r as b}from"./use-applet-docs-DBshA7yq.js";var x=e(n(),1),S=t();function C({doc:e,updateWorkspace:t,registerEl:n,registerBody:r,highlighted:i,onLinkTo:a,onDelete:o}){let s=p(e,t||``,!!t),{title:c,content:u,setTitle:d,setContent:m}=s,h=()=>{s.save().catch(()=>{})};return(0,S.jsxs)(`div`,{ref:t=>n(e.id,t),className:l(`group border-t border-border/60 px-4 py-3 transition-colors`,i&&`bg-primary/5`),children:[(0,S.jsxs)(`div`,{className:`mb-1 flex items-baseline justify-between gap-2`,children:[(0,S.jsxs)(`span`,{className:`text-[10px] uppercase tracking-wide text-muted-foreground/70`,children:[y(e.createdAt),` · #`,e.id]}),(0,S.jsxs)(`div`,{className:`flex items-center gap-1 text-[10px] text-muted-foreground/70`,children:[(0,S.jsx)(f,{...s,onRetry:s.save}),(0,S.jsx)(g,{onLinkTo:a,onDelete:o})]})]}),(0,S.jsx)(`input`,{value:c,onChange:e=>d(e.target.value),onBlur:h,placeholder:`Untitled`,spellCheck:!1,className:`mb-1 w-full border-0 bg-transparent p-0 text-sm font-semibold text-foreground outline-none placeholder:text-muted-foreground/50`}),(0,S.jsx)(v,{value:u,onChange:m,onBlur:h,innerRef:t=>r(e.id,t)})]})}function w({target:e,onCreated:t,onCancel:n}){let i=h(e,void 0,`applet`),{title:a,content:o,setTitle:s,setContent:c,saving:l}=i,[u,d]=(0,x.useState)(null),p=async()=>{try{await i.save(e),i.finish(),t()}catch(e){d(e instanceof Error?e.message:`Failed to save note`)}};return(0,S.jsxs)(`div`,{className:`border-t border-border/60 bg-muted/30 px-4 py-3`,children:[(0,S.jsxs)(`div`,{className:`mb-1 flex items-baseline justify-between`,children:[(0,S.jsx)(`span`,{className:`text-[10px] uppercase tracking-wide text-muted-foreground/70`,children:`New note`}),(0,S.jsx)(`button`,{type:`button`,onClick:n,className:`text-muted-foreground hover:text-foreground`,"aria-label":`Close note`,children:(0,S.jsx)(r,{className:`h-3 w-3`})})]}),(0,S.jsx)(`input`,{value:a,onChange:e=>s(e.target.value),placeholder:`Untitled`,autoFocus:!0,spellCheck:!1,className:`mb-1 w-full border-0 bg-transparent p-0 text-sm font-semibold text-foreground outline-none placeholder:text-muted-foreground/50`}),(0,S.jsx)(v,{value:o,onChange:c,placeholder:`Write your note…`}),(0,S.jsx)(f,{...i,onRetry:i.retry}),u&&(0,S.jsx)(`p`,{className:`mt-1 text-xs text-destructive`,children:u}),(0,S.jsx)(`div`,{className:`mt-2 flex justify-end`,children:(0,S.jsx)(`button`,{type:`button`,onClick:p,disabled:!o.trim()||l,className:`rounded-md bg-primary px-2.5 py-1 text-xs text-primary-foreground disabled:opacity-50`,children:l?`Saving…`:`Done`})})]})}function T({autoAdd:e=!1}){let t=m(),{docs:n,loading:r,error:l,scope:f,reload:p,removeDoc:h}=b(t,u),[g,v]=(0,x.useState)(``),[y,T]=(0,x.useState)(0),[E,D]=(0,x.useState)(`desc`),[O,k]=(0,x.useState)(e),[A,j]=(0,x.useState)(null),M=(0,x.useRef)(new Map),N=(0,x.useRef)(new Map),P=(0,x.useCallback)((e,t)=>{t?M.current.set(e,t):M.current.delete(e)},[]),F=(0,x.useCallback)((e,t)=>{t?N.current.set(e,t):N.current.delete(e)},[]),I=(0,x.useCallback)(async e=>{let t=e.data?.title?`"${e.data.title}"`:`#${e.id}`;if(window.confirm(`Delete note ${t}?\n\nIt is removed from this path and moves to the workspace trash if nothing else links it.`))try{await h(e.id)}catch{}},[h]),L=(0,x.useMemo)(()=>{let e=[...n];return e.sort((e,t)=>{let n=new Date(e.createdAt).getTime()-new Date(t.createdAt).getTime();return E===`asc`?n:-n}),e},[n,E]),R=(0,x.useMemo)(()=>{let e=g.trim().toLowerCase();if(!e)return[];let t=[];for(let n of L){let r=String(n.data?.content??``),i=String(n.data?.title??``),a=r.toLowerCase().indexOf(e);a>=0?t.push({docId:n.id,offset:a}):i.toLowerCase().includes(e)&&t.push({docId:n.id,offset:-1})}return t},[g,L]),z=R.length?R[Math.min(y,R.length-1)]:null;(0,x.useEffect)(()=>{z&&M.current.get(z.docId)?.scrollIntoView({block:`center`,behavior:`smooth`})},[z]);let B=(0,x.useCallback)(e=>{if(!R.length)return;let t=e?(y+1)%R.length:y;e&&T(t);let n=R[t],r=N.current.get(n.docId);r&&n.offset>=0&&(r.focus(),r.setSelectionRange(n.offset,n.offset+g.trim().length)),M.current.get(n.docId)?.scrollIntoView({block:`center`,behavior:`smooth`})},[R,y,g]);return t?(0,S.jsxs)(`div`,{className:`flex h-full flex-col`,children:[(0,S.jsxs)(`div`,{className:`flex shrink-0 items-center gap-2 border-b border-border px-3 py-2`,children:[(0,S.jsxs)(`div`,{className:`relative flex-1`,children:[(0,S.jsx)(c,{className:`pointer-events-none absolute left-2 top-1/2 h-3.5 w-3.5 -translate-y-1/2 text-muted-foreground`}),(0,S.jsx)(`input`,{value:g,onChange:e=>{v(e.target.value),T(0)},onKeyDown:e=>{e.key===`Enter`&&(e.preventDefault(),B(!0))},placeholder:`Search notes…`,spellCheck:!1,className:`w-full rounded-md border border-input bg-transparent py-1 pl-7 pr-14 text-xs outline-none placeholder:text-muted-foreground focus-visible:ring-1 focus-visible:ring-ring`}),g.trim()&&(0,S.jsx)(`span`,{className:`absolute right-2 top-1/2 -translate-y-1/2 text-[10px] tabular-nums text-muted-foreground`,children:R.length?`${Math.min(y+1,R.length)}/${R.length}`:`0/0`})]}),(0,S.jsx)(`button`,{type:`button`,onClick:()=>D(e=>e===`desc`?`asc`:`desc`),className:`rounded-md border border-border p-1.5 text-muted-foreground transition-colors hover:bg-muted hover:text-foreground`,title:E===`desc`?`Newest first (click for oldest first)`:`Oldest first (click for newest first)`,"aria-label":`Toggle sort order`,children:E===`desc`?(0,S.jsx)(o,{className:`h-3.5 w-3.5`}):(0,S.jsx)(a,{className:`h-3.5 w-3.5`})}),(0,S.jsxs)(`button`,{type:`button`,onClick:()=>k(!0),className:`flex items-center gap-1 rounded-md bg-primary px-2 py-1.5 text-xs text-primary-foreground`,title:`Add a note`,children:[(0,S.jsx)(i,{className:`h-3.5 w-3.5`}),`Note`]})]}),(0,S.jsxs)(`div`,{className:`min-h-0 flex-1 overflow-y-auto`,children:[O&&(0,S.jsx)(w,{target:t,onCreated:()=>{k(!1),p()},onCancel:()=>k(!1)},JSON.stringify(t)),r&&!n.length&&(0,S.jsx)(`div`,{className:`flex items-center justify-center py-10`,children:(0,S.jsx)(s,{className:`h-5 w-5 animate-spin text-muted-foreground`})}),l&&(0,S.jsx)(`p`,{className:`px-4 py-6 text-center text-sm text-destructive`,children:l}),!r&&!l&&!L.length&&!O&&(0,S.jsx)(`p`,{className:`px-4 py-10 text-center text-sm text-muted-foreground`,children:`No notes here yet - add the first one.`}),L.map(e=>(0,S.jsx)(C,{doc:e,updateWorkspace:f?.workspaceName??null,registerEl:P,registerBody:F,highlighted:z?.docId===e.id,onLinkTo:()=>j(e.id),onDelete:()=>I(e)},e.id))]}),A!==null&&(0,S.jsx)(_,{documentId:A,workspaceName:f?.workspaceName,onClose:()=>j(null)})]}):(0,S.jsx)(`div`,{className:`flex h-full items-center justify-center p-6 text-center text-sm text-muted-foreground`,children:d(t)})}export{T as NotesApplet};
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,ci as a,mi as o,pn as s,yt as c}from"./ui-76Hw0NU_.js";import{t as l}from"./utils-2pl1SbIp.js";import{Bn as u}from"./workspace-46EFyEKZ.js";import{t as d}from"./useAddTarget-D4ra50Am.js";import{t as f}from"./note-save-status-DPz4VzL6.js";import{t as p}from"./useEditNoteFields-CKYMBf8V.js";import{n as m}from"./use-applet-target-DmIdCxa_.js";import{k as h}from"./index-BG5J93SO.js";import{n as g,r as _,t as v}from"./shared-C-uHNNY8.js";import{n as y,r as b}from"./use-applet-docs-DBshA7yq.js";var x=e(n(),1),S=t();function C({doc:e,updateWorkspace:t,registerEl:n,registerBody:r,highlighted:i,onLinkTo:a,onDelete:o}){let s=p(e,t||``,!!t),{title:c,content:u,setTitle:d,setContent:m}=s,h=()=>{s.save().catch(()=>{})};return(0,S.jsxs)(`div`,{ref:t=>n(e.id,t),className:l(`group border-t border-border/60 px-4 py-3 transition-colors`,i&&`bg-primary/5`),children:[(0,S.jsxs)(`div`,{className:`mb-1 flex items-baseline justify-between gap-2`,children:[(0,S.jsxs)(`span`,{className:`text-[10px] uppercase tracking-wide text-muted-foreground/70`,children:[y(e.createdAt),` · #`,e.id]}),(0,S.jsxs)(`div`,{className:`flex items-center gap-1 text-[10px] text-muted-foreground/70`,children:[(0,S.jsx)(f,{...s,onRetry:s.save}),(0,S.jsx)(g,{onLinkTo:a,onDelete:o})]})]}),(0,S.jsx)(`input`,{value:c,onChange:e=>d(e.target.value),onBlur:h,placeholder:`Untitled`,spellCheck:!1,className:`mb-1 w-full border-0 bg-transparent p-0 text-sm font-semibold text-foreground outline-none placeholder:text-muted-foreground/50`}),(0,S.jsx)(v,{value:u,onChange:m,onBlur:h,innerRef:t=>r(e.id,t)})]})}function w({target:e,onCreated:t,onCancel:n}){let i=h(e,void 0,`applet`),{title:a,content:o,setTitle:s,setContent:c,saving:l}=i,[u,d]=(0,x.useState)(null),p=async()=>{try{await i.save(e),i.finish(),t()}catch(e){d(e instanceof Error?e.message:`Failed to save note`)}};return(0,S.jsxs)(`div`,{className:`border-t border-border/60 bg-muted/30 px-4 py-3`,children:[(0,S.jsxs)(`div`,{className:`mb-1 flex items-baseline justify-between`,children:[(0,S.jsx)(`span`,{className:`text-[10px] uppercase tracking-wide text-muted-foreground/70`,children:`New note`}),(0,S.jsx)(`button`,{type:`button`,onClick:n,className:`text-muted-foreground hover:text-foreground`,"aria-label":`Close note`,children:(0,S.jsx)(r,{className:`h-3 w-3`})})]}),(0,S.jsx)(`input`,{value:a,onChange:e=>s(e.target.value),placeholder:`Untitled`,autoFocus:!0,spellCheck:!1,className:`mb-1 w-full border-0 bg-transparent p-0 text-sm font-semibold text-foreground outline-none placeholder:text-muted-foreground/50`}),(0,S.jsx)(v,{value:o,onChange:c,placeholder:`Write your note…`}),(0,S.jsx)(f,{...i,onRetry:i.retry}),u&&(0,S.jsx)(`p`,{className:`mt-1 text-xs text-destructive`,children:u}),(0,S.jsx)(`div`,{className:`mt-2 flex justify-end`,children:(0,S.jsx)(`button`,{type:`button`,onClick:p,disabled:!o.trim()||l,className:`rounded-md bg-primary px-2.5 py-1 text-xs text-primary-foreground disabled:opacity-50`,children:l?`Saving…`:`Done`})})]})}function T({autoAdd:e=!1}){let t=m(),{docs:n,loading:r,error:l,scope:f,reload:p,removeDoc:h}=b(t,u),[g,v]=(0,x.useState)(``),[y,T]=(0,x.useState)(0),[E,D]=(0,x.useState)(`desc`),[O,k]=(0,x.useState)(e),[A,j]=(0,x.useState)(null),M=(0,x.useRef)(new Map),N=(0,x.useRef)(new Map),P=(0,x.useCallback)((e,t)=>{t?M.current.set(e,t):M.current.delete(e)},[]),F=(0,x.useCallback)((e,t)=>{t?N.current.set(e,t):N.current.delete(e)},[]),I=(0,x.useCallback)(async e=>{let t=e.data?.title?`"${e.data.title}"`:`#${e.id}`;if(window.confirm(`Delete note ${t}?\n\nIt is removed from this path and moves to the workspace trash if nothing else links it.`))try{await h(e.id)}catch{}},[h]),L=(0,x.useMemo)(()=>{let e=[...n];return e.sort((e,t)=>{let n=new Date(e.createdAt).getTime()-new Date(t.createdAt).getTime();return E===`asc`?n:-n}),e},[n,E]),R=(0,x.useMemo)(()=>{let e=g.trim().toLowerCase();if(!e)return[];let t=[];for(let n of L){let r=String(n.data?.content??``),i=String(n.data?.title??``),a=r.toLowerCase().indexOf(e);a>=0?t.push({docId:n.id,offset:a}):i.toLowerCase().includes(e)&&t.push({docId:n.id,offset:-1})}return t},[g,L]),z=R.length?R[Math.min(y,R.length-1)]:null;(0,x.useEffect)(()=>{z&&M.current.get(z.docId)?.scrollIntoView({block:`center`,behavior:`smooth`})},[z]);let B=(0,x.useCallback)(e=>{if(!R.length)return;let t=e?(y+1)%R.length:y;e&&T(t);let n=R[t],r=N.current.get(n.docId);r&&n.offset>=0&&(r.focus(),r.setSelectionRange(n.offset,n.offset+g.trim().length)),M.current.get(n.docId)?.scrollIntoView({block:`center`,behavior:`smooth`})},[R,y,g]);return t?(0,S.jsxs)(`div`,{className:`flex h-full flex-col`,children:[(0,S.jsxs)(`div`,{className:`flex shrink-0 items-center gap-2 border-b border-border px-3 py-2`,children:[(0,S.jsxs)(`div`,{className:`relative flex-1`,children:[(0,S.jsx)(c,{className:`pointer-events-none absolute left-2 top-1/2 h-3.5 w-3.5 -translate-y-1/2 text-muted-foreground`}),(0,S.jsx)(`input`,{value:g,onChange:e=>{v(e.target.value),T(0)},onKeyDown:e=>{e.key===`Enter`&&(e.preventDefault(),B(!0))},placeholder:`Search notes…`,spellCheck:!1,className:`w-full rounded-md border border-input bg-transparent py-1 pl-7 pr-14 text-xs outline-none placeholder:text-muted-foreground focus-visible:ring-1 focus-visible:ring-ring`}),g.trim()&&(0,S.jsx)(`span`,{className:`absolute right-2 top-1/2 -translate-y-1/2 text-[10px] tabular-nums text-muted-foreground`,children:R.length?`${Math.min(y+1,R.length)}/${R.length}`:`0/0`})]}),(0,S.jsx)(`button`,{type:`button`,onClick:()=>D(e=>e===`desc`?`asc`:`desc`),className:`rounded-md border border-border p-1.5 text-muted-foreground transition-colors hover:bg-muted hover:text-foreground`,title:E===`desc`?`Newest first (click for oldest first)`:`Oldest first (click for newest first)`,"aria-label":`Toggle sort order`,children:E===`desc`?(0,S.jsx)(o,{className:`h-3.5 w-3.5`}):(0,S.jsx)(a,{className:`h-3.5 w-3.5`})}),(0,S.jsxs)(`button`,{type:`button`,onClick:()=>k(!0),className:`flex items-center gap-1 rounded-md bg-primary px-2 py-1.5 text-xs text-primary-foreground`,title:`Add a note`,children:[(0,S.jsx)(i,{className:`h-3.5 w-3.5`}),`Note`]})]}),(0,S.jsxs)(`div`,{className:`min-h-0 flex-1 overflow-y-auto`,children:[O&&(0,S.jsx)(w,{target:t,onCreated:()=>{k(!1),p()},onCancel:()=>k(!1)},JSON.stringify(t)),r&&!n.length&&(0,S.jsx)(`div`,{className:`flex items-center justify-center py-10`,children:(0,S.jsx)(s,{className:`h-5 w-5 animate-spin text-muted-foreground`})}),l&&(0,S.jsx)(`p`,{className:`px-4 py-6 text-center text-sm text-destructive`,children:l}),!r&&!l&&!L.length&&!O&&(0,S.jsx)(`p`,{className:`px-4 py-10 text-center text-sm text-muted-foreground`,children:`No notes here yet - add the first one.`}),L.map(e=>(0,S.jsx)(C,{doc:e,updateWorkspace:f?.workspaceName??null,registerEl:P,registerBody:F,highlighted:z?.docId===e.id,onLinkTo:()=>j(e.id),onDelete:()=>I(e)},e.id))]}),A!==null&&(0,S.jsx)(_,{documentId:A,workspaceName:f?.workspaceName,onClose:()=>j(null)})]}):(0,S.jsx)(`div`,{className:`flex h-full items-center justify-center p-6 text-center text-sm text-muted-foreground`,children:d(t)})}export{T as NotesApplet};
@@ -1 +1 @@
1
- import{o as e}from"./rolldown-runtime-C0FnF6B9.js";import{l as t,u as n}from"./code-editor-BOIngd5F.js";import{_ as r,g as i,h as a}from"./chunk-62JRHF6Z-vspAGgtK.js";import{t as o}from"./socket-CtH3EU9m.js";import{n as s}from"./use-toast-BlLDqSUO.js";import{o as c,s as l}from"./LinkToCard-VXpoeMDH.js";import{G as u,Sn as d,V as ee,bn as te,zt as ne}from"./workspace-46EFyEKZ.js";import{r as re}from"./document-list-CwStaizB.js";import{n as ie}from"./use-toolbox-Ck_cLGgf.js";import{E as ae,_ as oe,a as se,b as ce,i as le,l as ue,o as de}from"./context-BGgz0Y_q.js";import{i as fe}from"./color-DFEH4BfK.js";import{t as pe}from"./geo-CZfs0E-x.js";import{a as me,i as he,o as ge}from"./workspace-BydSRtST.js";import{i as _e}from"./use-menu-CaiLyPdw.js";import{a as ve,c as ye,i as be,l as xe,n as Se,o as Ce,r as we,s as Te,t as Ee}from"./content-app-view-B4ada874.js";import{t as De}from"./use-workspace-identity-KxY9injc.js";var f=e(n(),1),p=t();function Oe(e,t){if(!e||!t)return`/`;let n=`${t}://`;if(!e.startsWith(n))return`/`;let r=e.slice(n.length).replace(/^\/+/,``).replace(/\/+$/,``);return r?`/${r}`:`/`}function m(){let{contextId:e}=r(),t=a(),n=i(),m=new URLSearchParams(t.search).get(`ownerId`)||void 0,h=(0,f.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:g,showProgress:ke}=s(),{state:_,saveFilters:Ae,setSort:je,setAccentColor:v,setMapDocuments:y}=ie(),{openM1Drawer:Me,openM2Drawer:Ne,goBack:Pe}=_e(),b=_.filters.features.allOf,Fe=_.filters.features.anyOf,Ie=_.filters.features.noneOf,Le=[...he(_.filters.timeline),...me(_.filters.geo),...ge(_.filters.lens,_.filters.geo.includeUnlocated)],x=JSON.stringify({a:b,b:Fe,c:Ie,d:Le,ids:_.filters.lens.ids,sort:_.filters.sort,geoSelection:_.geoSelection,includeUnlocated:_.filters.geo.includeUnlocated}),S=(0,f.useMemo)(()=>JSON.parse(x),[x]),[C,w]=(0,f.useState)(null),[Re,ze]=(0,f.useState)(!0),[Be,Ve]=(0,f.useState)(null),[T,E]=(0,f.useState)([]),[He,Ue]=(0,f.useState)(!1),[We,D]=(0,f.useState)(0),[Ge,Ke]=(0,f.useState)([]),[O,k]=(0,f.useState)(1),[A,qe]=(0,f.useState)(50),[j,M]=(0,f.useState)(h),[N,P]=(0,f.useState)(!1),[F,Je]=(0,f.useState)(null),[I,Ye]=(0,f.useState)(!1),L=(0,f.useRef)(!1),R=F?.id===C?.id&&F?.url===C?.url?F?.path:null,Xe=new URLSearchParams(t.search).get(`layer`),z=!!m,Ze=De(z?void 0:C?.workspaceName||C?.workspaceId),B=C?Oe(C.url,C.workspaceName):`/`,Qe=Xe?`context-layer`:`context`,V=!_.liveEnabled&&typeof C?.metadata?.toolboxSearchQuery==`string`?C.metadata.toolboxSearchQuery:``,H=z?null:C?.workspaceName??null,[$e,et]=(0,f.useState)(null);(0,f.useEffect)(()=>{if(!H)return;let e=!1;return u(H,d).then(t=>{e||et({key:H,tree:t})}).catch(()=>{e||et({key:H,tree:null})}),()=>{e=!0}},[H]);let U=H&&$e?.key===H?$e.tree:null,W=!Xe&&!z&&U?B===`/`?U:ee(U,B):null,G=`${C?.workspaceName??``}\0${B}`,[K,tt]=(0,f.useState)(null),q=K?.key===G?K.views:Ce(W?.metadata),J=K?.key===G?K.activeId:q[0]?.id??be.id,Y=q.find(e=>e.id===J)??q[0]??be,X=ve(Y);xe(ye({workspace:C?.workspaceName||C?.workspaceId||null,treeNameOrId:_.activeTreeName,path:B,contextId:e??null,scope:`context`},{..._.filters,features:{..._.filters.features,allOf:X?[...b,X]:b}},_.geoSelection,j));let nt=e=>{k(1),tt({key:G,views:q,activeId:e})},rt=(e,t)=>{t&&t!==J&&k(1),tt({key:G,views:e,activeId:t??J}),C?.workspaceName&&te(C.workspaceName,B,{metadata:{...W?.metadata??{},views:e}},d).catch(()=>{g({title:`View not saved`,description:`Could not persist views to the layer`,variant:`destructive`})})},Z=(0,f.useRef)(null);(0,f.useEffect)(()=>()=>Z.current?.abort(),[]);let Q=(0,f.useCallback)(async()=>{if(!e)return;Z.current?.abort();let t=new AbortController;Z.current=t,Ue(!0);try{let n=await de(e,X?[...S.a,X]:S.a,S.d,{...S.sort,geoSelection:S.geoSelection,includeUnlocated:S.includeUnlocated,ids:S.ids,signal:t.signal,limit:A,page:O,queries:j.length?j:void 0,anyOf:S.b,noneOf:S.c,applyContextSpec:!1},m);if(t.signal.aborted)return;E(n),D(n.totalCount||n.count||n.length)}catch(e){if(t.signal.aborted)return;g({title:`Error`,description:e instanceof Error?e.message:`Failed to fetch documents`,variant:`destructive`}),E([]),D(0)}finally{t.signal.aborted||Ue(!1)}},[e,O,A,m,j,S,g,X]),it=(0,f.useCallback)(async()=>{if(e){ze(!0);try{let t=z?await se(e,m):await se(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)||``;w({id:t.id,userId:t.userId,url:t.url,baseUrl:t.baseUrl||null,path:t.path||null,pathArray:t.pathArray||[],workspaceId:r,workspaceName:i,acl:t.acl||{},createdAt:t.createdAt,updatedAt:t.updatedAt,locked:t.locked||!1,serverContextArray:t.serverContextArray||[],clientContextArray:t.clientContextArray||[],contextBitmapArray:t.contextBitmapArray||[],featureBitmapArray:t.featureBitmapArray||[],filterArray:t.filterArray||[],pendingUrl:t.pendingUrl||null,description:t.description||null,metadata:t.metadata||{},name:t.name??null,color:t.color??null,icon:t.icon??null}),Ve(null)}catch(t){let n=t instanceof Error?t.message:`Failed to fetch context ${e}`;Ve(n),w(null),g({title:`Error`,description:n,variant:`destructive`})}ze(!1)}},[e,m,z,g]);(0,f.useEffect)(()=>{it()},[it]);let at=fe(C?.color)||null;(0,f.useEffect)(()=>(v(at),()=>v(null)),[at,v]);let ot=_.geoSelection,st=C?.workspaceName||C?.workspaceId||null;(0,f.useEffect)(()=>{y(T,st)},[T,st,y]),(0,f.useEffect)(()=>()=>y([]),[y]);let ct=(0,f.useMemo)(()=>ot?T.filter(e=>pe(e,ot,_.filters.geo.includeUnlocated)):T,[T,ot,_.filters.geo.includeUnlocated]),lt=C?.id,ut=C?.url;(0,f.useEffect)(()=>{lt&&Q()},[lt,ut,Q]),(0,f.useEffect)(()=>{let e=()=>Q();return window.addEventListener(`workspace:documents:refresh`,e),()=>window.removeEventListener(`workspace:documents:refresh`,e)},[Q]);let[dt,ft]=(0,f.useState)(x);dt!==x&&(ft(x),k(1));let[pt,mt]=(0,f.useState)(e);pt!==e&&(mt(e),k(1),P(!1));let[ht,gt]=(0,f.useState)(h);ht!==h&&(gt(h),M(h),k(1));let[_t,vt]=(0,f.useState)({urlSearchQueries:h,ignoreSavedSearch:N,savedContextSearchQuery:V});(_t.urlSearchQueries!==h||_t.ignoreSavedSearch!==N||_t.savedContextSearchQuery!==V)&&(vt({urlSearchQueries:h,ignoreSavedSearch:N,savedContextSearchQuery:V}),!new URLSearchParams(t.search).has(`q`)&&!h.length&&!N&&(M(V?[V]:[]),k(1)));let $=(0,f.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]),yt=(0,f.useCallback)(e=>{let t=e.trim();if(!t)return;P(!1);let n=j.includes(t)?j:[...j,t];M(n),$(n)},[j,$]),bt=(0,f.useCallback)(e=>{let t=e<0?[]:j.filter((t,n)=>n!==e);t.length===0&&P(!0),M(t),$(t)},[j,$]),xt=(j[0]||``).trim(),St=!!_.activeContextType&&(_.isDirty||xt!==(_.savedSearchQuery||V||``));(0,f.useEffect)(()=>{if(!e)return;let t=`context:${m?`${m}/`:``}${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)&&(w(e=>e?{...e,...r}:null),r.url&&Q())},l=t=>{let n=t,r=n?.id||n?.contextId||n?.context?.id,i=n?.url||n?.context?.url;r===e&&typeof i==`string`&&s(`ctx:url`,n)&&(w(e=>e?{...e,url:i}:null),Q())},u=t=>{let n=t;(n?.contextId||n?.id||n?.context?.id)===e&&s(`doc:changed`,n)&&Q()},d=[[`context.updated`,c],[`context:updated`,c],[`context.url.set`,l],[`context:url:set`,l],[`document.inserted`,u],[`document.updated`,u],[`document.removed`,u],[`document.removed.batch`,u],[`document.linked`,u],[`document.unlinked`,u],[`document.linked.batch`,u],[`document.unlinked.batch`,u],[`document.deleted`,u],[`document.deleted.batch`,u]];return d.forEach(([e,t])=>o.on(e,t)),()=>{i(),r(),d.forEach(([e,t])=>o.off(e,t))}},[e,m,Q]);let Ct=async e=>{if(C)try{await ce(C.id,[e],m,B),E(t=>t.filter(t=>t.id!==e)),D(e=>Math.max(0,e-1)),g({title:`Success`,description:`Document removed from context.`})}catch(e){g({title:`Error`,description:e instanceof Error?e.message:`Failed to remove document`,variant:`destructive`})}},wt=async e=>{if(C)try{await le(C.id,[e],m,B),E(t=>t.filter(t=>t.id!==e)),D(e=>Math.max(0,e-1)),g({title:`Success`,description:`Document deleted.`})}catch(e){g({title:`Error`,description:e instanceof Error?e.message:`Failed to delete document`,variant:`destructive`})}},Tt=async e=>{if(C)try{await ce(C.id,e,m,B),E(t=>t.filter(t=>!e.includes(t.id))),D(t=>Math.max(0,t-e.length)),g({title:`Success`,description:`${e.length} document(s) removed.`})}catch(e){g({title:`Error`,description:e instanceof Error?e.message:`Failed to remove documents`,variant:`destructive`})}},Et=async e=>{if(C)try{await le(C.id,e,m,B),E(t=>t.filter(t=>!e.includes(t.id))),D(t=>Math.max(0,t-e.length)),g({title:`Success`,description:`${e.length} document(s) deleted.`})}catch(e){g({title:`Error`,description:e instanceof Error?e.message:`Failed to delete documents`,variant:`destructive`})}},Dt=e=>{Ke(e),g({title:`Copied`,description:`${e.length} document(s) copied to clipboard`})},Ot=async(e,t,n={})=>{if(!C)return!1;let r=ke({title:`Pasting…`,description:`${t.length} document(s) → "${e}"`});try{let i=n.targetTreeName&&!z?await ne(C.workspaceName||C.workspaceId,e,t,n.targetTreeName,n.targetTreeType):await oe(C.id,e,t,m);return r.done(i?{title:`Success`,description:`${t.length} document(s) pasted to "${e}"`}:void 0),i&&(Ke([]),await Q()),i}catch(e){return r.fail({title:`Error`,description:e instanceof Error?e.message:`Failed to paste documents`,variant:`destructive`}),!1}},kt=async(e,t)=>{if(!C)return!1;try{let n=await ue(C.workspaceId,t,e);return n&&(re(C.workspaceName||C.workspaceId,`context`,t),g({title:`Success`,description:`Imported ${e.length} document(s) to "${t}"`})),n}catch(e){return g({title:`Error`,description:e instanceof Error?e.message:`Failed to import documents`,variant:`destructive`}),!1}},At=async()=>{if(!C||!R||z||L.current)return;let e={id:C.id,url:C.url,path:R};L.current=!0,Ye(!0);try{let t=await ae(e.id,`${C.workspaceName}://${e.path.replace(/^\/+/,``)}`);w(n=>n?.id===e.id&&n.url===e.url?{...n,url:t.url,path:e.path}:n),Je(null),k(1),window.dispatchEvent(new CustomEvent(`contexts:refresh`,{detail:{contextId:e.id}})),g({title:`Saved`,description:`Context path updated`})}catch(e){g({title:`Error`,description:e instanceof Error?e.message:`Could not update context path`,variant:`destructive`})}finally{L.current=!1,Ye(!1)}};if(Re)return(0,p.jsx)(`div`,{className:`flex items-center justify-center h-full`,children:(0,p.jsxs)(`div`,{className:`text-center space-y-2`,children:[(0,p.jsx)(`div`,{className:`animate-spin rounded-full h-8 w-8 border-b-2 border-primary mx-auto`}),(0,p.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`Loading context...`})]})});if(Be&&!C)return(0,p.jsxs)(`div`,{className:`flex items-center justify-center h-full text-destructive`,children:[`Error: `,Be]});if(!C)return(0,p.jsx)(`div`,{className:`flex items-center justify-center h-full text-muted-foreground`,children:`Context not found.`});let jt=fe(C.color);return(0,p.jsx)(`div`,{className:`flex flex-col h-full min-h-0`,children:(0,p.jsx)(Te,{onBack:Pe,accentColor:jt,navigationTabs:W?(0,p.jsx)(we,{views:q,activeId:J,onSelect:nt,onSave:rt,accentColor:jt}):void 0,workspaceLabel:Ze?.label||C.workspaceName||C.workspaceId,workspaceIcon:Ze?.icon,treeName:d,urlType:Qe,urlDisplay:C.url,contextPath:B,workspaceId:C.workspaceName||C.workspaceId,documentSchema:X,linkTree:U,documents:ct,isLoading:He,totalCount:We,currentPage:O,pageSize:A,onPageChange:k,onPageSizeChange:e=>{qe(e),k(1)},onRemoveDocument:B===`/`?void 0:Ct,onDeleteDocument:wt,onRemoveDocuments:B===`/`?void 0:Tt,onDeleteDocuments:Et,onCopyDocuments:Dt,onPasteDocuments:Ot,onImportDocuments:z?void 0:kt,pastedDocumentIds:Ge,backendSearchQueries:j,onBackendSearch:yt,serverSort:_.filters.sort,onServerSortChange:je,onRemoveBackendQuery:bt,canSaveChanges:St,isSavingChanges:_.isSaving,onSaveChanges:Ae,onBrowseTree:!z&&e?()=>Ne(`contexts`,`detail`,e):void 0,onBrowseWorkspaces:()=>Me(`workspaces`),onNavigatePath:z?void 0:e=>{L.current||Je({id:C.id,url:C.url,path:e})},contentBanner:R?(0,p.jsxs)(`div`,{className:`border-b bg-warning/10 px-4 py-2`,role:`status`,children:[(0,p.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,p.jsxs)(`div`,{className:`flex min-w-0 items-center gap-2`,children:[(0,p.jsx)(l,{items:c(R,C.workspaceName),label:`Selected context path`}),(0,p.jsx)(`button`,{type:`button`,disabled:I,onClick:()=>void At(),className:`shrink-0 rounded border px-3 py-1 text-sm hover:bg-accent disabled:opacity-50`,children:I?`Setting…`:`Set`}),(0,p.jsx)(`button`,{type:`button`,disabled:I,onClick:()=>Je(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,p.jsx)(Se,{documents:ct,workspaceId:C.workspaceName||C.workspaceId,columns:Y.columns??[],onColumnsChange:e=>rt(q.map(t=>t.id===Y.id?{...t,columns:e}:t))}):Y.kind===`app`&&Y.app&&Y.app!==`notes`?(0,p.jsx)(Ee,{app:Y.app,contextId:e,workspaceId:C.workspaceName||C.workspaceId,treeName:d,path:B}):null})})}export{m as default};
1
+ import{o as e}from"./rolldown-runtime-C0FnF6B9.js";import{l as t,u as n}from"./code-editor-BOIngd5F.js";import{_ as r,g as i,h as a}from"./chunk-62JRHF6Z-vspAGgtK.js";import{t as o}from"./socket-CtH3EU9m.js";import{n as s}from"./use-toast-BlLDqSUO.js";import{o as c,s as l}from"./LinkToCard-VXpoeMDH.js";import{G as u,Sn as d,V as ee,bn as te,zt as ne}from"./workspace-46EFyEKZ.js";import{r as re}from"./document-list-CwStaizB.js";import{n as ie}from"./use-toolbox-Ck_cLGgf.js";import{E as ae,_ as oe,a as se,b as ce,i as le,l as ue,o as de}from"./context-BGgz0Y_q.js";import{i as fe}from"./color-DFEH4BfK.js";import{t as pe}from"./geo-CZfs0E-x.js";import{a as me,i as he,o as ge}from"./workspace-BydSRtST.js";import{i as _e}from"./use-menu-CaiLyPdw.js";import{a as ve,c as ye,i as be,l as xe,n as Se,o as Ce,r as we,s as Te,t as Ee}from"./content-app-view-3BCpYf7m.js";import{t as De}from"./use-workspace-identity-KxY9injc.js";var f=e(n(),1),p=t();function Oe(e,t){if(!e||!t)return`/`;let n=`${t}://`;if(!e.startsWith(n))return`/`;let r=e.slice(n.length).replace(/^\/+/,``).replace(/\/+$/,``);return r?`/${r}`:`/`}function m(){let{contextId:e}=r(),t=a(),n=i(),m=new URLSearchParams(t.search).get(`ownerId`)||void 0,h=(0,f.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:g,showProgress:ke}=s(),{state:_,saveFilters:Ae,setSort:je,setAccentColor:v,setMapDocuments:y}=ie(),{openM1Drawer:Me,openM2Drawer:Ne,goBack:Pe}=_e(),b=_.filters.features.allOf,Fe=_.filters.features.anyOf,Ie=_.filters.features.noneOf,Le=[...he(_.filters.timeline),...me(_.filters.geo),...ge(_.filters.lens,_.filters.geo.includeUnlocated)],x=JSON.stringify({a:b,b:Fe,c:Ie,d:Le,ids:_.filters.lens.ids,sort:_.filters.sort,geoSelection:_.geoSelection,includeUnlocated:_.filters.geo.includeUnlocated}),S=(0,f.useMemo)(()=>JSON.parse(x),[x]),[C,w]=(0,f.useState)(null),[Re,ze]=(0,f.useState)(!0),[Be,Ve]=(0,f.useState)(null),[T,E]=(0,f.useState)([]),[He,Ue]=(0,f.useState)(!1),[We,D]=(0,f.useState)(0),[Ge,Ke]=(0,f.useState)([]),[O,k]=(0,f.useState)(1),[A,qe]=(0,f.useState)(50),[j,M]=(0,f.useState)(h),[N,P]=(0,f.useState)(!1),[F,Je]=(0,f.useState)(null),[I,Ye]=(0,f.useState)(!1),L=(0,f.useRef)(!1),R=F?.id===C?.id&&F?.url===C?.url?F?.path:null,Xe=new URLSearchParams(t.search).get(`layer`),z=!!m,Ze=De(z?void 0:C?.workspaceName||C?.workspaceId),B=C?Oe(C.url,C.workspaceName):`/`,Qe=Xe?`context-layer`:`context`,V=!_.liveEnabled&&typeof C?.metadata?.toolboxSearchQuery==`string`?C.metadata.toolboxSearchQuery:``,H=z?null:C?.workspaceName??null,[$e,et]=(0,f.useState)(null);(0,f.useEffect)(()=>{if(!H)return;let e=!1;return u(H,d).then(t=>{e||et({key:H,tree:t})}).catch(()=>{e||et({key:H,tree:null})}),()=>{e=!0}},[H]);let U=H&&$e?.key===H?$e.tree:null,W=!Xe&&!z&&U?B===`/`?U:ee(U,B):null,G=`${C?.workspaceName??``}\0${B}`,[K,tt]=(0,f.useState)(null),q=K?.key===G?K.views:Ce(W?.metadata),J=K?.key===G?K.activeId:q[0]?.id??be.id,Y=q.find(e=>e.id===J)??q[0]??be,X=ve(Y);xe(ye({workspace:C?.workspaceName||C?.workspaceId||null,treeNameOrId:_.activeTreeName,path:B,contextId:e??null,scope:`context`},{..._.filters,features:{..._.filters.features,allOf:X?[...b,X]:b}},_.geoSelection,j));let nt=e=>{k(1),tt({key:G,views:q,activeId:e})},rt=(e,t)=>{t&&t!==J&&k(1),tt({key:G,views:e,activeId:t??J}),C?.workspaceName&&te(C.workspaceName,B,{metadata:{...W?.metadata??{},views:e}},d).catch(()=>{g({title:`View not saved`,description:`Could not persist views to the layer`,variant:`destructive`})})},Z=(0,f.useRef)(null);(0,f.useEffect)(()=>()=>Z.current?.abort(),[]);let Q=(0,f.useCallback)(async()=>{if(!e)return;Z.current?.abort();let t=new AbortController;Z.current=t,Ue(!0);try{let n=await de(e,X?[...S.a,X]:S.a,S.d,{...S.sort,geoSelection:S.geoSelection,includeUnlocated:S.includeUnlocated,ids:S.ids,signal:t.signal,limit:A,page:O,queries:j.length?j:void 0,anyOf:S.b,noneOf:S.c,applyContextSpec:!1},m);if(t.signal.aborted)return;E(n),D(n.totalCount||n.count||n.length)}catch(e){if(t.signal.aborted)return;g({title:`Error`,description:e instanceof Error?e.message:`Failed to fetch documents`,variant:`destructive`}),E([]),D(0)}finally{t.signal.aborted||Ue(!1)}},[e,O,A,m,j,S,g,X]),it=(0,f.useCallback)(async()=>{if(e){ze(!0);try{let t=z?await se(e,m):await se(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)||``;w({id:t.id,userId:t.userId,url:t.url,baseUrl:t.baseUrl||null,path:t.path||null,pathArray:t.pathArray||[],workspaceId:r,workspaceName:i,acl:t.acl||{},createdAt:t.createdAt,updatedAt:t.updatedAt,locked:t.locked||!1,serverContextArray:t.serverContextArray||[],clientContextArray:t.clientContextArray||[],contextBitmapArray:t.contextBitmapArray||[],featureBitmapArray:t.featureBitmapArray||[],filterArray:t.filterArray||[],pendingUrl:t.pendingUrl||null,description:t.description||null,metadata:t.metadata||{},name:t.name??null,color:t.color??null,icon:t.icon??null}),Ve(null)}catch(t){let n=t instanceof Error?t.message:`Failed to fetch context ${e}`;Ve(n),w(null),g({title:`Error`,description:n,variant:`destructive`})}ze(!1)}},[e,m,z,g]);(0,f.useEffect)(()=>{it()},[it]);let at=fe(C?.color)||null;(0,f.useEffect)(()=>(v(at),()=>v(null)),[at,v]);let ot=_.geoSelection,st=C?.workspaceName||C?.workspaceId||null;(0,f.useEffect)(()=>{y(T,st)},[T,st,y]),(0,f.useEffect)(()=>()=>y([]),[y]);let ct=(0,f.useMemo)(()=>ot?T.filter(e=>pe(e,ot,_.filters.geo.includeUnlocated)):T,[T,ot,_.filters.geo.includeUnlocated]),lt=C?.id,ut=C?.url;(0,f.useEffect)(()=>{lt&&Q()},[lt,ut,Q]),(0,f.useEffect)(()=>{let e=()=>Q();return window.addEventListener(`workspace:documents:refresh`,e),()=>window.removeEventListener(`workspace:documents:refresh`,e)},[Q]);let[dt,ft]=(0,f.useState)(x);dt!==x&&(ft(x),k(1));let[pt,mt]=(0,f.useState)(e);pt!==e&&(mt(e),k(1),P(!1));let[ht,gt]=(0,f.useState)(h);ht!==h&&(gt(h),M(h),k(1));let[_t,vt]=(0,f.useState)({urlSearchQueries:h,ignoreSavedSearch:N,savedContextSearchQuery:V});(_t.urlSearchQueries!==h||_t.ignoreSavedSearch!==N||_t.savedContextSearchQuery!==V)&&(vt({urlSearchQueries:h,ignoreSavedSearch:N,savedContextSearchQuery:V}),!new URLSearchParams(t.search).has(`q`)&&!h.length&&!N&&(M(V?[V]:[]),k(1)));let $=(0,f.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]),yt=(0,f.useCallback)(e=>{let t=e.trim();if(!t)return;P(!1);let n=j.includes(t)?j:[...j,t];M(n),$(n)},[j,$]),bt=(0,f.useCallback)(e=>{let t=e<0?[]:j.filter((t,n)=>n!==e);t.length===0&&P(!0),M(t),$(t)},[j,$]),xt=(j[0]||``).trim(),St=!!_.activeContextType&&(_.isDirty||xt!==(_.savedSearchQuery||V||``));(0,f.useEffect)(()=>{if(!e)return;let t=`context:${m?`${m}/`:``}${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)&&(w(e=>e?{...e,...r}:null),r.url&&Q())},l=t=>{let n=t,r=n?.id||n?.contextId||n?.context?.id,i=n?.url||n?.context?.url;r===e&&typeof i==`string`&&s(`ctx:url`,n)&&(w(e=>e?{...e,url:i}:null),Q())},u=t=>{let n=t;(n?.contextId||n?.id||n?.context?.id)===e&&s(`doc:changed`,n)&&Q()},d=[[`context.updated`,c],[`context:updated`,c],[`context.url.set`,l],[`context:url:set`,l],[`document.inserted`,u],[`document.updated`,u],[`document.removed`,u],[`document.removed.batch`,u],[`document.linked`,u],[`document.unlinked`,u],[`document.linked.batch`,u],[`document.unlinked.batch`,u],[`document.deleted`,u],[`document.deleted.batch`,u]];return d.forEach(([e,t])=>o.on(e,t)),()=>{i(),r(),d.forEach(([e,t])=>o.off(e,t))}},[e,m,Q]);let Ct=async e=>{if(C)try{await ce(C.id,[e],m,B),E(t=>t.filter(t=>t.id!==e)),D(e=>Math.max(0,e-1)),g({title:`Success`,description:`Document removed from context.`})}catch(e){g({title:`Error`,description:e instanceof Error?e.message:`Failed to remove document`,variant:`destructive`})}},wt=async e=>{if(C)try{await le(C.id,[e],m,B),E(t=>t.filter(t=>t.id!==e)),D(e=>Math.max(0,e-1)),g({title:`Success`,description:`Document deleted.`})}catch(e){g({title:`Error`,description:e instanceof Error?e.message:`Failed to delete document`,variant:`destructive`})}},Tt=async e=>{if(C)try{await ce(C.id,e,m,B),E(t=>t.filter(t=>!e.includes(t.id))),D(t=>Math.max(0,t-e.length)),g({title:`Success`,description:`${e.length} document(s) removed.`})}catch(e){g({title:`Error`,description:e instanceof Error?e.message:`Failed to remove documents`,variant:`destructive`})}},Et=async e=>{if(C)try{await le(C.id,e,m,B),E(t=>t.filter(t=>!e.includes(t.id))),D(t=>Math.max(0,t-e.length)),g({title:`Success`,description:`${e.length} document(s) deleted.`})}catch(e){g({title:`Error`,description:e instanceof Error?e.message:`Failed to delete documents`,variant:`destructive`})}},Dt=e=>{Ke(e),g({title:`Copied`,description:`${e.length} document(s) copied to clipboard`})},Ot=async(e,t,n={})=>{if(!C)return!1;let r=ke({title:`Pasting…`,description:`${t.length} document(s) → "${e}"`});try{let i=n.targetTreeName&&!z?await ne(C.workspaceName||C.workspaceId,e,t,n.targetTreeName,n.targetTreeType):await oe(C.id,e,t,m);return r.done(i?{title:`Success`,description:`${t.length} document(s) pasted to "${e}"`}:void 0),i&&(Ke([]),await Q()),i}catch(e){return r.fail({title:`Error`,description:e instanceof Error?e.message:`Failed to paste documents`,variant:`destructive`}),!1}},kt=async(e,t)=>{if(!C)return!1;try{let n=await ue(C.workspaceId,t,e);return n&&(re(C.workspaceName||C.workspaceId,`context`,t),g({title:`Success`,description:`Imported ${e.length} document(s) to "${t}"`})),n}catch(e){return g({title:`Error`,description:e instanceof Error?e.message:`Failed to import documents`,variant:`destructive`}),!1}},At=async()=>{if(!C||!R||z||L.current)return;let e={id:C.id,url:C.url,path:R};L.current=!0,Ye(!0);try{let t=await ae(e.id,`${C.workspaceName}://${e.path.replace(/^\/+/,``)}`);w(n=>n?.id===e.id&&n.url===e.url?{...n,url:t.url,path:e.path}:n),Je(null),k(1),window.dispatchEvent(new CustomEvent(`contexts:refresh`,{detail:{contextId:e.id}})),g({title:`Saved`,description:`Context path updated`})}catch(e){g({title:`Error`,description:e instanceof Error?e.message:`Could not update context path`,variant:`destructive`})}finally{L.current=!1,Ye(!1)}};if(Re)return(0,p.jsx)(`div`,{className:`flex items-center justify-center h-full`,children:(0,p.jsxs)(`div`,{className:`text-center space-y-2`,children:[(0,p.jsx)(`div`,{className:`animate-spin rounded-full h-8 w-8 border-b-2 border-primary mx-auto`}),(0,p.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`Loading context...`})]})});if(Be&&!C)return(0,p.jsxs)(`div`,{className:`flex items-center justify-center h-full text-destructive`,children:[`Error: `,Be]});if(!C)return(0,p.jsx)(`div`,{className:`flex items-center justify-center h-full text-muted-foreground`,children:`Context not found.`});let jt=fe(C.color);return(0,p.jsx)(`div`,{className:`flex flex-col h-full min-h-0`,children:(0,p.jsx)(Te,{onBack:Pe,accentColor:jt,navigationTabs:W?(0,p.jsx)(we,{views:q,activeId:J,onSelect:nt,onSave:rt,accentColor:jt}):void 0,workspaceLabel:Ze?.label||C.workspaceName||C.workspaceId,workspaceIcon:Ze?.icon,treeName:d,urlType:Qe,urlDisplay:C.url,contextPath:B,workspaceId:C.workspaceName||C.workspaceId,documentSchema:X,linkTree:U,documents:ct,isLoading:He,totalCount:We,currentPage:O,pageSize:A,onPageChange:k,onPageSizeChange:e=>{qe(e),k(1)},onRemoveDocument:B===`/`?void 0:Ct,onDeleteDocument:wt,onRemoveDocuments:B===`/`?void 0:Tt,onDeleteDocuments:Et,onCopyDocuments:Dt,onPasteDocuments:Ot,onImportDocuments:z?void 0:kt,pastedDocumentIds:Ge,backendSearchQueries:j,onBackendSearch:yt,serverSort:_.filters.sort,onServerSortChange:je,onRemoveBackendQuery:bt,canSaveChanges:St,isSavingChanges:_.isSaving,onSaveChanges:Ae,onBrowseTree:!z&&e?()=>Ne(`contexts`,`detail`,e):void 0,onBrowseWorkspaces:()=>Me(`workspaces`),onNavigatePath:z?void 0:e=>{L.current||Je({id:C.id,url:C.url,path:e})},contentBanner:R?(0,p.jsxs)(`div`,{className:`border-b bg-warning/10 px-4 py-2`,role:`status`,children:[(0,p.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,p.jsxs)(`div`,{className:`flex min-w-0 items-center gap-2`,children:[(0,p.jsx)(l,{items:c(R,C.workspaceName),label:`Selected context path`}),(0,p.jsx)(`button`,{type:`button`,disabled:I,onClick:()=>void At(),className:`shrink-0 rounded border px-3 py-1 text-sm hover:bg-accent disabled:opacity-50`,children:I?`Setting…`:`Set`}),(0,p.jsx)(`button`,{type:`button`,disabled:I,onClick:()=>Je(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,p.jsx)(Se,{documents:ct,workspaceId:C.workspaceName||C.workspaceId,columns:Y.columns??[],onColumnsChange:e=>rt(q.map(t=>t.id===Y.id?{...t,columns:e}:t))}):Y.kind===`app`&&Y.app&&Y.app!==`notes`?(0,p.jsx)(Ee,{app:Y.app,contextId:e,workspaceId:C.workspaceName||C.workspaceId,treeName:d,path:B}):null})})}export{m as default};