@augmentd-labs/canvas-web 2.26.35 → 2.26.37

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 (37) hide show
  1. package/dist/assets/CalendarApplet-BmrEfNPa.js +2 -0
  2. package/dist/assets/{FiltersApplet-NltVCRY8.js → FiltersApplet-BuOfikkU.js} +1 -1
  3. package/dist/assets/HomeFab-DtUgQqjj.js +3 -0
  4. package/dist/assets/{LensApplet-D-E4YyKz.js → LensApplet-DWoA0AeK.js} +1 -1
  5. package/dist/assets/{NotesApplet-DZ7lSkfC.js → NotesApplet-BnHiH-Vm.js} +1 -1
  6. package/dist/assets/{_agentId_-BuZ9wBek.js → _agentId_-Cm8yJTqD.js} +0 -0
  7. package/dist/assets/{_contextId_-DURo7ANU.js → _contextId_-LRp2S1tj.js} +1 -1
  8. package/dist/assets/{_workspaceName_-JpQwQGvI.js → _workspaceName_-BC1W0_NU.js} +1 -1
  9. package/dist/assets/{about-BpN8_1bC.js → about-aJJuQSFB.js} +1 -1
  10. package/dist/assets/{add-B7zdhw47.js → add-Ruml_x6t.js} +1 -1
  11. package/dist/assets/{agents-ChD6m_5J.js → agents-BWYACYNH.js} +1 -1
  12. package/dist/assets/{appearance-DEL04cKR.js → appearance-CSvWylrJ.js} +1 -1
  13. package/dist/assets/{apps-BYrwwspU.js → apps-CdUhD9HG.js} +1 -1
  14. package/dist/assets/content-app-view-AUB8kjjJ.js +1 -0
  15. package/dist/assets/{home-Bg5pLpIh.js → home-DwSabq_0.js} +1 -1
  16. package/dist/assets/index-AELn_vht.js +16 -0
  17. package/dist/assets/index-BAeuh9Mu.css +2 -0
  18. package/dist/assets/{key-bindings--OI4Iz7e.js → key-bindings-Cv7mVdte.js} +1 -1
  19. package/dist/assets/{registry-DQPkddij.js → registry-D1CIT_aZ.js} +2 -2
  20. package/dist/assets/{settings-B6TQfRMQ.js → settings-D8jDlO3y.js} +1 -1
  21. package/dist/assets/{settings-BgqCRJzb.js → settings-DaYH1KUc.js} +3 -3
  22. package/dist/assets/settings-DnXGDMuM.js +1 -0
  23. package/dist/assets/{settings-BQmgBTa-.js → settings-MRGmsYtV.js} +1 -1
  24. package/dist/assets/{share-target-BZmiLt2r.js → share-target-vNEvk9Rt.js} +1 -1
  25. package/dist/assets/{shared-qweQ1MKt.js → shared-C0dVLLZX.js} +1 -1
  26. package/dist/assets/{useAgentModels-Bda5ilvQ.js → useAgentModels-Dw4f4pZz.js} +1 -1
  27. package/dist/assets/workspaces-Ban7--8l.js +1 -0
  28. package/dist/index.html +3 -3
  29. package/dist/sw.js +1 -1
  30. package/package.json +2 -2
  31. package/dist/assets/CalendarApplet-gN_A0sQe.js +0 -2
  32. package/dist/assets/HomeFab-Cc33x4F2.js +0 -3
  33. package/dist/assets/content-app-view-Dcknmau8.js +0 -1
  34. package/dist/assets/index-C51Jk0Xq.css +0 -2
  35. package/dist/assets/index-VAgMESOp.js +0 -16
  36. package/dist/assets/settings-CljJz3ui.js +0 -1
  37. package/dist/assets/workspaces-BK7Rj72s.js +0 -1
@@ -1,2 +0,0 @@
1
- import{o as e}from"./rolldown-runtime-C0FnF6B9.js";import{l as t,u as n}from"./code-editor-BOIngd5F.js";import{g as r,r as i}from"./chunk-62JRHF6Z-vspAGgtK.js";import{Fr as a,Hr as o,Jr as s,L as c,Ot as l,Pt as u,Vr as d,X as f,ct as p,et as m,fr as h,jr as g,mr as _,pn as v,qr as y,vn as b}from"./ui-CDoK3F3U.js";import{t as x}from"./utils-2pl1SbIp.js";import{h as S}from"./LinkToCard-BQ1yoFDr.js";import{Hn as C,In as w,St as T,jt as E,rt as D,vn as ee,w as te,wn as O}from"./workspace-BJELPCNs.js";import{o as ne,t as k}from"./useAddTarget-B3b6TyZr.js";import{a as A,o as j}from"./context-DZ1Hn7tt.js";import{n as M,o as N,s as P,t as F}from"./date-time-picker-txVhlNO0.js";import{n as re}from"./use-applet-target-ffIGaAqT.js";import{y as I}from"./index-VAgMESOp.js";import{r as ie,t as ae}from"./shared-BnpwVpxG.js";var L=e(n(),1),oe=864e5,se=[`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 ce(e){return`${z(e)}T${R(e.getHours())}:${R(e.getMinutes())}`}function V(e){return new Date(e.getFullYear(),e.getMonth(),e.getDate())}function H(e,t){return new Date(e.getFullYear(),e.getMonth(),e.getDate()+t,e.getHours(),e.getMinutes(),e.getSeconds(),e.getMilliseconds())}function le(e,t){return new Date(e.getFullYear(),e.getMonth()+t,1)}function ue(e){let t=V(e);return H(t,-((t.getDay()+6)%7))}function de(e){return new Date(e.getFullYear(),e.getMonth(),1)}function U(e,t){return e.getFullYear()===t.getFullYear()&&e.getMonth()===t.getMonth()&&e.getDate()===t.getDate()}function fe(e){let t=ue(de(e));return Array.from({length:42},(e,n)=>H(t,n))}function W(e,t){let n=[],r=t.getTime()>e.getTime()?new Date(t.getTime()-1):e;for(let t=V(e);t.getTime()<=r.getTime();t=H(t,1))n.push(t);return n}function G(e,t){let n=e.getTime()-V(t).getTime();return Math.max(0,Math.min(oe,n))/6e4}var pe=new Intl.DateTimeFormat(void 0,{month:`long`,year:`numeric`}),K=new Intl.DateTimeFormat(void 0,{month:`short`}),me=new Intl.DateTimeFormat(void 0,{weekday:`long`,day:`numeric`,month:`long`,year:`numeric`}),q=new Intl.DateTimeFormat(void 0,{weekday:`short`,day:`numeric`,month:`short`}),J=new Intl.DateTimeFormat(void 0,{hour:`numeric`,minute:`2-digit`});function he(e){return pe.format(e)}function ge(e){return K.format(e)}function Y(e){return me.format(e)}function X(e){return q.format(e)}function Z(e){return J.format(e)}function _e(e,t){return U(e,t)?Y(e):e.getFullYear()===t.getFullYear()?e.getMonth()===t.getMonth()?`${e.getDate()} – ${t.getDate()} ${K.format(e)} ${e.getFullYear()}`:`${e.getDate()} ${K.format(e)} – ${t.getDate()} ${K.format(t)} ${t.getFullYear()}`:`${e.getDate()} ${K.format(e)} ${e.getFullYear()} – ${t.getDate()} ${K.format(t)} ${t.getFullYear()}`}function ve(e){return _e(e,H(e,6))}function ye(e){return J.format(new Date(2e3,0,1,e,0)).replace(/:00(?=\s|$)/,``)}var be={SU:0,MO:1,TU:2,WE:3,TH:4,FR:5,SA:6},xe=new Set([`FREQ`,`INTERVAL`,`COUNT`,`UNTIL`,`BYDAY`,`BYMONTHDAY`,`BYMONTH`,`WKST`]);function Se(e){let t={};for(let n of e.replace(/^RRULE:/i,``).split(`;`)){let e=n.trim();if(!e)continue;let r=e.indexOf(`=`);if(r<1)return null;t[e.slice(0,r).toUpperCase()]=e.slice(r+1).toUpperCase()}if(Object.keys(t).some(e=>!xe.has(e)))return null;let n=t.FREQ;if(n!==`DAILY`&&n!==`WEEKLY`&&n!==`MONTHLY`&&n!==`YEARLY`)return null;let r=t.INTERVAL?Number(t.INTERVAL):1;if(!Number.isInteger(r)||r<1)return null;let i=t.COUNT?Number(t.COUNT):null;if(i!==null&&(!Number.isInteger(i)||i<1))return null;let a=null;if(t.UNTIL){let e=/^(\d{4})(\d{2})(\d{2})(?:T(\d{2})(\d{2})(\d{2})(Z?))?$/.exec(t.UNTIL);if(!e)return null;let[,n,r,i,o,s,c,l]=e;if(a=o===void 0?new Date(Number(n),Number(r)-1,Number(i),23,59,59,999):l?new Date(Date.UTC(Number(n),Number(r)-1,Number(i),Number(o),Number(s),Number(c))):new Date(Number(n),Number(r)-1,Number(i),Number(o),Number(s),Number(c)),Number.isNaN(a.getTime()))return null}let o=[];if(t.BYDAY)for(let e of t.BYDAY.split(`,`)){let t=/^([+-]?\d{1,2})?(SU|MO|TU|WE|TH|FR|SA)$/.exec(e.trim());if(!t)return null;o.push({day:be[t[2]],ordinal:t[1]?Number(t[1]):null})}let s=t.BYMONTHDAY?t.BYMONTHDAY.split(`,`).map(Number):[];if(s.some(e=>!Number.isInteger(e)||e===0||e<-31||e>31))return null;let c=t.BYMONTH?t.BYMONTH.split(`,`).map(Number):[];return c.some(e=>!Number.isInteger(e)||e<1||e>12)||o.some(e=>e.ordinal!==null)&&n!==`MONTHLY`&&n!==`YEARLY`?null:{freq:n,interval:r,count:i,until:a,byDay:o,byMonthDay:s,byMonth:c}}function Ce(e,t){return new Date(e.getFullYear(),e.getMonth(),e.getDate(),t.getHours(),t.getMinutes(),t.getSeconds(),t.getMilliseconds())}function we(e,t){return new Date(e,t+1,0).getDate()}function Te(e,t,n,r){let i=we(e,t),a=new Set;if(n.byMonthDay.length)for(let e of n.byMonthDay){let t=e>0?e:i+1+e;t>=1&&t<=i&&a.add(t)}if(n.byDay.length){let r=new Set;for(let{day:a,ordinal:o}of n.byDay){let n=[];for(let r=1;r<=i;r++)new Date(e,t,r).getDay()===a&&n.push(r);if(o===null)n.forEach(e=>r.add(e));else{let e=o>0?n[o-1]:n[n.length+o];e&&r.add(e)}}if(n.byMonthDay.length)for(let e of[...a])r.has(e)||a.delete(e);else r.forEach(e=>a.add(e))}return!n.byMonthDay.length&&!n.byDay.length&&r.getDate()<=i&&a.add(r.getDate()),[...a].sort((e,t)=>e-t).map(n=>Ce(new Date(e,t,n),r))}function Ee(e,t,n,r,i=0,a=5e3){let o=[],s=n.getTime()-Math.max(0,i),c=r.getTime(),l=0,u=t=>{let n=t.getTime();return e.until&&n>e.until.getTime()||(l++,n>=s&&n<c&&o.push(t),e.count!==null&&l>=e.count)?!1:l<a};if(!u(t))return o;let d=t.getTime();if(e.freq===`DAILY`){for(let n=e.interval,r=0;r<a*12;n+=e.interval,r++){let r=Ce(new Date(t.getFullYear(),t.getMonth(),t.getDate()+n),t);if(r.getTime()>=c&&e.count===null||!(e.byMonth.length&&!e.byMonth.includes(r.getMonth()+1))&&!u(r))break}return o}if(e.freq===`WEEKLY`){let n=e.byDay.length?[...new Set(e.byDay.map(e=>e.day))]:[t.getDay()],r=new Date(t.getFullYear(),t.getMonth(),t.getDate()-(t.getDay()+6)%7);for(let i=0;;i+=e.interval){let a=new Date(r.getFullYear(),r.getMonth(),r.getDate()+i*7);if(a.getTime()>=c+6048e5&&e.count===null)break;let o=!1;for(let e=0;e<7;e++){let r=new Date(a.getFullYear(),a.getMonth(),a.getDate()+e);if(!n.includes(r.getDay()))continue;let i=Ce(r,t);if(!(i.getTime()<=d)&&!u(i)){o=!0;break}}if(o)break}return o}let f=e.freq===`MONTHLY`?e.interval:12*e.interval;for(let n=0;;n+=f){let r=t.getFullYear()+Math.floor((t.getMonth()+n)/12),i=(t.getMonth()+n)%12;if(new Date(r,i,1).getTime()>=c&&e.count===null)break;if(e.freq===`YEARLY`&&e.byMonth.length&&!e.byMonth.includes(i+1)){let n=!1;for(let i of e.byMonth){for(let a of Te(r,i-1,e,t))if(!(a.getTime()<=d)&&!u(a)){n=!0;break}if(n)break}if(n)break;continue}if(e.freq===`MONTHLY`&&e.byMonth.length&&!e.byMonth.includes(i+1))continue;let a=!1;for(let n of Te(r,i,e,t))if(!(n.getTime()<=d)&&!u(n)){a=!0;break}if(a||n>4800)break}return o}function De(e){let t={DAILY:`day`,WEEKLY:`week`,MONTHLY:`month`,YEARLY:`year`}[e.freq],n=e.interval===1?`Every ${t}`:`Every ${e.interval} ${t}s`,r=[`Sun`,`Mon`,`Tue`,`Wed`,`Thu`,`Fri`,`Sat`];return e.byDay.length?n+=` on `+e.byDay.map(({day:e,ordinal:t})=>t===null?r[e]:`${t===-1?`last`:`${t}.`} ${r[e]}`).join(`, `):e.byMonthDay.length&&(n+=` on day `+e.byMonthDay.join(`, `)),e.count!==null&&(n+=`, ${e.count} times`),e.until&&(n+=` until ${e.until.toLocaleDateString(void 0,{day:`numeric`,month:`short`,year:`numeric`})}`),n}function Oe(e){if(!e)return`none`;let t=Se(e);return!t||t.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 ke(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 Ae=`tasks`,je=`data/schema/event`,Me=`data/schema/task`;function Ne(e){if(typeof e!=`string`||!e)return null;let t=new Date(e);return Number.isNaN(t.getTime())?null:t}function Pe(e){return new Date(e.getUTCFullYear(),e.getUTCMonth(),e.getUTCDate())}function Fe(e){return e.schema.startsWith(je)}function Ie(e){return e.schema===Me}function Le(e,t,n){let r=e.data??{};if(Ie(e)){let i=Ne(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:Ae,recurring:!1,unsupportedRule:!1,done:a===`completed`||a===`cancelled`}]}if(!Fe(e))return[];let i=Ne(r.start);if(!i)return[];let a=r.allDay===!0,o=r.end===null?null:Ne(r.end),s=a?Pe(i):i,c=a?o?Pe(o):H(s,1):o??(r.end===null?n:s),l=Math.max(0,c.getTime()-s.getTime()),u={doc:e,kind:`event`,title:String(r.title??`Untitled`),allDay:a,calendar:typeof r.calendar==`string`?r.calendar:``,done:!1},d=typeof r.recurrence==`string`?r.recurrence:``;if(!d)return c.getTime()<=t.getTime()&&!(c.getTime()===s.getTime()&&s>=t)||s>=n?[]:[{...u,key:`${e.id}@${s.getTime()}`,start:s,end:c,recurring:!1,unsupportedRule:!1}];let f=Se(d);return f?Ee(f,s,t,n,l).map(t=>({...u,key:`${e.id}@${t.getTime()}`,start:t,end:new Date(t.getTime()+l),recurring:!0,unsupportedRule:!1})):c<=t||s>=n?[]:[{...u,key:`${e.id}@${s.getTime()}`,start:s,end:c,recurring:!0,unsupportedRule:!0}]}function Re(e,t,n){return e.flatMap(e=>Le(e,t,n)).sort((e,t)=>e.start.getTime()-t.start.getTime()||t.end.getTime()-e.end.getTime()||e.title.localeCompare(t.title))}function ze(e){let t=new Map;for(let n of e)for(let e of W(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 Be(e){return e.allDay||e.end.getTime()-e.start.getTime()>=864e5||!U(e.start,new Date(e.end.getTime()-1))&&e.end.getTime()>e.start.getTime()}function Ve(e,t,n=30){let r=V(e),i=t.filter(e=>!Be(e)).map(e=>{let t=G(e.start,r),i=Math.max(n,G(e.end,r)-t);return{occurrence:e,top:t,height:Math.min(i,1440-t),column:0,columns:1}}).sort((e,t)=>e.top-t.top||t.height-e.height),a=[],o=-1,s=()=>{let e=[];for(let t of a){let n=e.findIndex(e=>e<=t.top);n<0&&(n=e.length,e.push(0)),e[n]=t.top+t.height,t.column=n}for(let t of a)t.columns=e.length;a=[]};for(let e of i)a.length&&e.top>=o&&s(),a.push(e),o=Math.max(o,e.top+e.height);return a.length&&s(),i}function He(e,t,n,r){if(t.kind===`task`)return{...e,dueDate:n.toISOString()};if(t.allDay)return{...e,start:`${z(n)}T00:00:00.000Z`,end:`${z(r)}T00:00:00.000Z`};let i={...e,start:n.toISOString()};return e.end===null||(r.getTime()>n.getTime()?i.end=r.toISOString():delete i.end),i}var Ue=[{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`}],We={view:`week`,hidden:[],showTasks:!0,defaultCalendar:`Personal`},Ge=`canvas:calendar:prefs`;function Ke(e){return`${Ge}:${e??`global`}`}function qe(e){try{let t=JSON.parse(localStorage.getItem(Ke(e))||`null`);if(!t||typeof t!=`object`)return We;let n=t;return{view:Ue.some(e=>e.id===n.view)?n.view:We.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:We.defaultCalendar}}catch{return We}}function Je(e,t){try{localStorage.setItem(Ke(e),JSON.stringify(t))}catch{}}function Ye(e,t){let n=z(H(V(e),-1)),r=z(H(V(t),1));return{events:`t:events:${n}..${r}`,tasks:`t:tasks:${n}..${r}`}}var Xe=5e3;function Ze(e){return!!e&&!e.includes(`:`)&&![`content`,`events`,`tasks`].includes(e.toLowerCase())}function Qe(e){return e?e.mode===`context`?`ctx:${e.contextId}`:`${e.workspaceName}:${e.treeName}:${e.treeType}:${e.path}`:``}function $e(e,t,n,r){let[i,a]=(0,L.useState)([]),[o,s]=(0,L.useState)(!1),[c,l]=(0,L.useState)(null),[u,d]=(0,L.useState)(null),[f,p]=(0,L.useState)([]),m=t.getTime(),h=n.getTime(),g=(0,L.useCallback)(()=>{if(!e)return Promise.resolve();let t=Ye(new Date(m),new Date(h));return(e.mode===`context`?Promise.all([j(e.contextId,[w],[t.events],{limit:Xe}),r?j(e.contextId,[C],[t.tasks],{limit:Xe}):Promise.resolve([]),A(e.contextId)]).then(([e,t,n])=>{a([...e,...t]);let r=n.workspaceName||n.workspaceId;d(r?{workspaceName:r,path:n.path||`/`,treeName:n.treeId||`context`,treeType:`context`}:null)}):(()=>{let{workspaceName:n,path:i,treeName:o,treeType:s}=e,c={treeName:o,treeType:s,limit:0};return Promise.all([D(n,i,[w],{...c,filters:[t.events]}),r?D(n,i,[C],{...c,filters:[t.tasks]}):Promise.resolve({payload:[]})]).then(([e,t])=>{a([...e.payload||[],...t.payload||[]]),d({workspaceName:n,path:i,treeName:o,treeType:s})})})()).catch(e=>l(e instanceof Error?e.message:`Failed to load calendar`)).finally(()=>s(!1))},[e,m,h,r]),_=(0,L.useCallback)(async()=>{if(!e){a([]),d(null);return}s(!0),l(null),await g()},[e,g]),[v,y]=(0,L.useState)(null),b=`${Qe(e)}|${m}|${h}|${r}`;v!==b&&(y(b),e?(s(!0),l(null)):(a([]),d(null))),(0,L.useEffect)(()=>{g()},[g]),(0,L.useEffect)(()=>{let e=()=>{_()};return window.addEventListener(`workspace:documents:refresh`,e),()=>window.removeEventListener(`workspace:documents:refresh`,e)},[_]);let x=u?.workspaceName??null,S=(0,L.useCallback)(()=>x?Promise.all([T(x),E(x)]).then(([e,t])=>{let n=new Set;for(let t of e)t.startsWith(`data/calendar/`)&&t.length>14&&n.add(t.slice(14));for(let e of t)Ze(e.name)&&n.add(e.name);p([...n].sort())}).catch(()=>{}):Promise.resolve(),[x]);(0,L.useEffect)(()=>{S()},[S,i.length]),(0,L.useEffect)(()=>{let e=()=>{S()};return window.addEventListener(`workspace:timelines:changed`,e),()=>window.removeEventListener(`workspace:timelines:changed`,e)},[S]);let ee=(0,L.useCallback)(async e=>{if(!u)throw Error(`No workspace scope resolved`);await te(u.workspaceName,[e],u.path,[],u.treeName,u.treeType),a(t=>t.filter(t=>t.id!==e))},[u]),O=(0,L.useCallback)(e=>{a(t=>t.some(t=>t.id===e.id)?t.map(t=>t.id===e.id?e:t):[...t,e])},[]);return(0,L.useMemo)(()=>({docs:i,loading:o,error:c,scope:u,knownCalendars:f,reload:_,removeDoc:ee,patchDoc:O}),[i,o,c,u,f,_,ee,O])}function et(e){return I(e?e.toLowerCase():`events`)}function tt(e){return e.kind===`task`?I(Ae):et(e.calendar)}function nt(e,t=18){return`color-mix(in oklch, ${e} ${t}%, transparent)`}function rt(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:V(e[t]),end:H(V(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=V(e[o]);return{start:new Date(d.getTime()+l*6e4),end:new Date(d.getTime()+u*6e4),allDay:!1}}function it(e,t){let[n,r]=e.getTime()<=t.getTime()?[e,t]:[t,e];return{start:V(n),end:H(V(r),1),allDay:!0}}function at(e,t,n,r,i,a,o=15){let s=t=>Math.max(0,Math.min(e.length-1,t)),c=s(i)-s(n),l=Math.round((a-r)/o)*o,u=t.end.getTime()-t.start.getTime(),d=H(t.start,c),f=V(d),p=Math.max(0,Math.min(1440-o,(d.getTime()-f.getTime())/6e4+l)),m=new Date(f.getTime()+p*6e4);return{start:m,end:new Date(m.getTime()+u)}}function ot(e,t,n,r,i=15){let a=V(e[Math.max(0,Math.min(e.length-1,n))]),o=Math.min(1440,Math.ceil(r/i)*i),s=new Date(a.getTime()+o*6e4);return{start:t.start,end:s.getTime()<t.start.getTime()+i*6e4?new Date(t.start.getTime()+i*6e4):s}}function st(e,t){return{start:H(e.start,t),end:H(e.end,t)}}var Q=t();function ct({month:e,selection:t,marks:n,onPick:r,onPickRange:i,onPrev:a,onNext:s,onTitle:c,onDayMenu:l,title:u,className:f}){let p=new Date,m=fe(e),h=u??he(e),[g,_]=(0,L.useState)(null),v=(0,L.useRef)(g);(0,L.useEffect)(()=>{v.current=g});let y=(0,L.useRef)(!1),b=e=>(document.elementFromPoint(e.clientX,e.clientY)?.closest(`[data-day]`))?.dataset.day??null,S=e=>{if(!i||e.button!==0)return;let t=b(e);t&&(e.currentTarget.setPointerCapture(e.pointerId),_({from:t,to:t}))},C=e=>{if(!v.current)return;let t=b(e);t&&t!==v.current.to&&_({...v.current,to:t})},w=e=>{let t=v.current;if(!t||(e.currentTarget.releasePointerCapture(e.pointerId),_(null),t.from===t.to))return;y.current=!0,setTimeout(()=>{y.current=!1},0);let n=it(B(t.from),B(t.to));i?.(n.start,n.end)},T=(e,n)=>{if(y.current){y.current=!1;return}if(e.shiftKey&&i&&t){let e=it(t.start,n);i(e.start,e.end)}else r(n)},E=g?it(B(g.from),B(g.to)):t;return(0,Q.jsxs)(`div`,{className:x(`select-none`,f),children:[(0,Q.jsxs)(`div`,{className:`mb-1 flex items-center justify-between`,children:[a?(0,Q.jsx)(`button`,{type:`button`,onClick:a,className:`rounded p-0.5 text-muted-foreground hover:bg-muted hover:text-foreground`,"aria-label":`Previous month`,children:(0,Q.jsx)(o,{className:`h-3.5 w-3.5`})}):(0,Q.jsx)(`span`,{}),c?(0,Q.jsx)(`button`,{type:`button`,onClick:c,className:`text-xs font-semibold hover:underline`,children:h}):(0,Q.jsx)(`span`,{className:`text-xs font-semibold`,children:h}),s?(0,Q.jsx)(`button`,{type:`button`,onClick:s,className:`rounded p-0.5 text-muted-foreground hover:bg-muted hover:text-foreground`,"aria-label":`Next month`,children:(0,Q.jsx)(d,{className:`h-3.5 w-3.5`})}):(0,Q.jsx)(`span`,{})]}),(0,Q.jsx)(`div`,{className:`grid grid-cols-7 text-center text-[10px] text-muted-foreground`,children:se.map(e=>(0,Q.jsx)(`span`,{children:e[0]},e))}),(0,Q.jsx)(`div`,{className:x(`grid grid-cols-7 gap-y-px text-center text-[11px]`,g&&`cursor-crosshair`),onPointerDown:S,onPointerMove:C,onPointerUp:w,onPointerCancel:()=>_(null),children:m.map(t=>{let r=z(t),i=t.getMonth()===e.getMonth(),a=U(t,p),o=!!E&&t>=E.start&&t<E.end,s=!!E&&o&&U(t,E.start),c=!!E&&o&&U(t,new Date(E.end.getTime()-1)),u=n?.get(r)??[],d=[...new Set(u.map(tt))].slice(0,3);return(0,Q.jsxs)(`button`,{type:`button`,"data-day":r,onClick:e=>T(e,t),onContextMenu:l?e=>{e.preventDefault(),l(e,t)}:void 0,"aria-label":u.length?`${t.toDateString()}, ${u.length} ${u.length===1?`entry`:`entries`}`:t.toDateString(),title:u.length?u.slice(0,6).map(e=>e.title).join(`
2
- `)+(u.length>6?`\n+${u.length-6} more`:``):void 0,className:x(`relative mx-auto flex h-6 w-full items-center justify-center transition-colors hover:bg-muted`,s&&c?`rounded-full`:s?`rounded-l-full`:c?`rounded-r-full`:o?``:`rounded-full`,!i&&`text-muted-foreground/40`,a&&!o&&`font-bold text-primary`,o&&`bg-primary text-primary-foreground hover:bg-primary`,u.length>0&&!o&&`font-semibold`),style:u.length&&!o?{background:`color-mix(in srgb, ${d[0]} 22%, transparent)`}:void 0,children:[t.getDate(),u.length>0&&!o&&(0,Q.jsx)(`span`,{className:`absolute bottom-0 left-1/2 flex -translate-x-1/2 gap-px`,children:d.map(e=>(0,Q.jsx)(`span`,{className:`h-1 w-1 rounded-full`,style:{background:e}},e))})]},r)})})]})}function lt({occurrence:e,selected:t,moving:n,showTime:r=!0,onSelect:i,className:o,...s}){let c=tt(e),u=!e.allDay&&e.kind===`event`&&e.end.getTime()>e.start.getTime();return(0,Q.jsxs)(`button`,{type:`button`,onClick:t=>{t.stopPropagation(),i(e)},title:`${e.title}${e.calendar?` · ${e.calendar}`:``}`,className:x(`flex w-full min-w-0 items-center gap-1 truncate rounded px-1 py-px text-left text-[11px] leading-4 text-foreground transition-colors hover:brightness-110`,!e.recurring&&`touch-none`,t&&`ring-1 ring-ring`,n&&`cursor-grabbing ring-2 ring-primary shadow-elevation-2`,e.done&&`line-through opacity-60`,o),style:{background:nt(c,e.allDay||e.kind===`task`?28:14),borderLeft:`3px solid ${c}`},...s,children:[e.kind===`task`&&(0,Q.jsx)(a,{className:`h-3 w-3 shrink-0`,style:{color:c}}),r&&u&&(0,Q.jsx)(`span`,{className:`shrink-0 tabular-nums text-muted-foreground`,children:Z(e.start)}),(0,Q.jsx)(`span`,{className:`truncate`,children:e.title}),e.recurring&&(0,Q.jsx)(l,{className:`ml-auto h-2.5 w-2.5 shrink-0 text-muted-foreground`})]})}function ut(e){let[t,n]=(0,L.useState)(null),r=(0,L.useRef)(null),i=(0,L.useRef)(!1),a=e=>(document.elementFromPoint(e.clientX,e.clientY)?.closest(`[data-day]`))?.dataset.day??null;return{moving:t,handlers:t=>t.recurring?{}:{onPointerDown:e=>{if(e.button!==0)return;let n=a(e);n&&(e.currentTarget.setPointerCapture(e.pointerId),r.current={o:t,fromKey:n,delta:0})},onPointerMove:e=>{let t=r.current;if(!t)return;let i=a(e);if(!i)return;let o=Math.round((B(i).getTime()-B(t.fromKey).getTime())/oe);o!==t.delta&&(t.delta=o,n(o?{key:t.o.key,...st(t.o,o)}:null))},onPointerUp:t=>{let a=r.current;if(r.current=null,!a||(t.currentTarget.releasePointerCapture(t.pointerId),n(null),!a.delta))return;i.current=!0,setTimeout(()=>{i.current=!1},0);let o=st(a.o,a.delta);e(a.o,o.start,o.end)},onPointerCancel:()=>{r.current=null,n(null)},onClickCapture:e=>{i.current&&(i.current=!1,e.stopPropagation(),e.preventDefault())}},apply:e=>t?e.map(e=>e.key===t.key?{...e,start:t.start,end:t.end}:e):e}}var $=48,dt=30,ft=15,pt=`w-12`,mt=48;function ht({days:e,occurrences:t,selectedKey:n,pending:r,onSelect:i,onCreate:a,onMove:o,onPickDay:s,onEntryMenu:c,onSlotMenu:l,compact:u}){let d=(0,L.useRef)(null),f=(0,L.useRef)(null),[p,m]=(0,L.useState)(null),h=(0,L.useRef)(p);(0,L.useEffect)(()=>{h.current=p});let g=t=>{let n=f.current;if(!n)return null;let r=n.getBoundingClientRect(),i=(r.width-mt)/e.length,a=Math.floor((t.clientX-r.left-mt)/i),o=Math.max(0,Math.min(1439,(t.clientY-r.top)/$*60));return a<0||a>=e.length?null:{day:a,min:o}},_=e=>{if(e.button!==0||e.target.closest(`button`))return;let t=g(e);t&&(e.currentTarget.setPointerCapture(e.pointerId),m({fromDay:t.day,fromMin:t.min,toDay:t.day,toMin:t.min}))},v=e=>{if(!h.current)return;let t=g(e);t&&m({...h.current,toDay:t.day,toMin:t.min})},y=t=>{let n=h.current;if(!n)return;t.currentTarget.releasePointerCapture(t.pointerId),m(null);let r=rt(e,n.fromDay,n.fromMin,n.toDay,n.toMin,dt);a(r.start,r.allDay,r.end)},b=t=>{let n=g(t);n&&(t.preventDefault(),l(t,rt(e,n.day,n.min,n.day,n.min,dt).start,!1))},S=p?rt(e,p.fromDay,p.fromMin,p.toDay,p.toMin,dt):r,[C,w]=(0,L.useState)(null),T=(0,L.useRef)(C);(0,L.useEffect)(()=>{T.current=C});let E=(0,L.useRef)(null),D=(0,L.useRef)(!1),ee=(e,t)=>{if(e.button!==0||t.recurring)return;let n=g(e);n&&(e.currentTarget.setPointerCapture(e.pointerId),E.current={o:t,mode:e.target.dataset.resize?`resize`:`move`,fromDay:n.day,fromMin:n.min})},te=t=>{let n=E.current;if(!n)return;let r=g(t);if(!r)return;let i=n.mode===`move`?at(e,n.o,n.fromDay,n.fromMin,r.day,r.min,ft):ot(e,n.o,r.day,r.min,ft),a=i.start.getTime()===n.o.start.getTime()&&i.end.getTime()===n.o.end.getTime();w(a?null:{key:n.o.key,...i,mode:n.mode})},O=e=>{let t=E.current;if(E.current=null,!t)return;e.currentTarget.releasePointerCapture(e.pointerId);let n=T.current;w(null),n&&(D.current=!0,setTimeout(()=>{D.current=!1},0),o(t.o,n.start,n.end))},ne=ut(o),k=ne.apply(t),A=(0,L.useMemo)(()=>C?k.map(e=>e.key===C.key?{...e,start:C.start,end:C.end}:e):k,[k,C]),j=(0,L.useMemo)(()=>ze(A),[A]),[M,N]=(0,L.useState)(()=>new Date);(0,L.useEffect)(()=>{let e=setInterval(()=>N(new Date),6e4);return()=>clearInterval(e)},[]);let P=z(e[0]);(0,L.useEffect)(()=>{let t=d.current;t&&(t.scrollTop=(e.some(e=>U(e,M))?Math.max(0,M.getHours()-1):7)*$)},[P,e.length]);let F=Array.from({length:24},(e,t)=>t),re=e.map(e=>(j.get(z(e))??[]).filter(Be)),I=Math.max(0,...re.map(e=>e.length)),ie=!!p||!!C||!!ne.moving;return(0,Q.jsxs)(`div`,{className:`flex h-full min-h-0 flex-col`,children:[(0,Q.jsxs)(`div`,{className:`flex shrink-0 border-b border-border`,children:[(0,Q.jsx)(`div`,{className:x(pt,`shrink-0`)}),e.map(e=>{let t=U(e,M);return(0,Q.jsxs)(`button`,{type:`button`,onClick:()=>s(e),className:`flex min-w-0 flex-1 flex-col items-center border-l border-border/60 py-1 hover:bg-muted/50`,title:`Open day`,children:[(0,Q.jsx)(`span`,{className:`text-[10px] uppercase tracking-wide text-muted-foreground`,children:se[(e.getDay()+6)%7]}),(0,Q.jsx)(`span`,{className:x(`flex h-7 w-7 items-center justify-center rounded-full text-sm font-semibold`,t&&`bg-primary text-primary-foreground`),children:e.getDate()})]},z(e))})]}),I>0&&(0,Q.jsxs)(`div`,{className:x(`flex shrink-0 border-b border-border bg-muted/20`,ne.moving&&`select-none`),children:[(0,Q.jsx)(`div`,{className:x(pt,`shrink-0 py-1 pr-1 text-right text-[10px] text-muted-foreground`),children:u?``:`all day`}),e.map((e,t)=>(0,Q.jsx)(`div`,{"data-day":z(e),className:`flex min-w-0 flex-1 flex-col gap-0.5 border-l border-border/60 p-0.5`,onClick:t=>{t.target===t.currentTarget&&a(V(e),!0)},onContextMenu:t=>{t.preventDefault(),l(t,V(e),!0)},children:re[t].map(e=>(0,Q.jsx)(lt,{occurrence:e,selected:e.key===n,moving:ne.moving?.key===e.key,showTime:!1,onSelect:i,onContextMenu:t=>{t.preventDefault(),t.stopPropagation(),c(t,e)},...ne.handlers(e)},e.key))},z(e)))]}),(0,Q.jsx)(`div`,{ref:d,className:`min-h-0 flex-1 overflow-y-auto`,children:(0,Q.jsxs)(`div`,{ref:f,className:x(`relative flex select-none`,p&&`cursor-crosshair`,C?.mode===`move`&&`cursor-grabbing`,C?.mode===`resize`&&`cursor-ns-resize`),style:{height:1152},onPointerDown:_,onPointerMove:v,onPointerUp:y,onPointerCancel:()=>m(null),onContextMenu:b,children:[(0,Q.jsx)(`div`,{className:x(pt,`relative shrink-0`),children:F.map(e=>(0,Q.jsx)(`div`,{className:`absolute right-1 -translate-y-1/2 text-[10px] tabular-nums text-muted-foreground`,style:{top:e*$},children:e===0?``:ye(e)},e))}),e.map(e=>{let t=Ve(e,j.get(z(e))??[]),r=U(e,M)?(M.getHours()*60+M.getMinutes())/60*$:null;return(0,Q.jsxs)(`div`,{"data-day":z(e),className:`relative min-w-0 flex-1 cursor-cell border-l border-border/60`,role:`presentation`,children:[S&&S.end>e&&S.start<V(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:G(S.start,e)/60*$,height:Math.max(8,(G(S.end,e)-G(S.start,e))/60*$)},children:(0,Q.jsx)(`span`,{className:`absolute left-1 top-0.5 text-[10px] font-medium text-primary`,children:S.allDay?`All day`:`${Z(S.start)} – ${Z(S.end)}`})}),F.map(e=>(0,Q.jsx)(`div`,{className:`pointer-events-none absolute inset-x-0 border-t border-border/50`,style:{top:e*$}},e)),t.map(e=>{let t=e.occurrence,r=tt(t),a=100/e.columns,o=e.height<45,s=C?.key===t.key,l=!t.recurring;return(0,Q.jsxs)(`button`,{type:`button`,onClick:e=>{if(e.stopPropagation(),D.current){D.current=!1;return}i(t)},onContextMenu:e=>{e.preventDefault(),e.stopPropagation(),c(e,t)},onPointerDown:e=>ee(e,t),onPointerMove:te,onPointerUp:O,onPointerCancel:()=>{E.current=null,w(null)},title:`${t.title} · ${Z(t.start)}${t.end>t.start?` – ${Z(t.end)}`:``}`,className:x(`absolute overflow-hidden rounded-md border-l-[3px] px-1.5 text-left text-[11px] leading-tight text-foreground shadow-elevation-1 transition-[filter] hover:brightness-110`,l&&`touch-none`,s?`z-20 ring-2 ring-primary shadow-elevation-2`:ie&&`pointer-events-none`,t.key===n&&!s&&`ring-1 ring-ring`,t.done&&`line-through opacity-60`),style:{top:e.top/60*$,height:Math.max(18,e.height/60*$-2),left:`calc(${e.column*a}% + 2px)`,width:`calc(${a}% - 4px)`,background:nt(r,24),borderLeftColor:r,paddingTop:o?1:3},children:[(0,Q.jsx)(`span`,{className:x(`font-medium`,o?`inline`:`block truncate`),children:t.title}),!o&&(0,Q.jsxs)(`span`,{className:`block truncate text-[10px] text-muted-foreground`,children:[Z(t.start),t.end>t.start?` – ${Z(t.end)}`:``,t.calendar&&!u?` · ${t.calendar}`:``]}),l&&t.kind===`event`&&(0,Q.jsx)(`span`,{"data-resize":`1`,className:`absolute inset-x-0 bottom-0 h-1.5 cursor-ns-resize`})]},t.key)}),r!==null&&(0,Q.jsx)(`div`,{className:`pointer-events-none absolute inset-x-0 z-10 border-t-2 border-destructive`,style:{top:r},children:(0,Q.jsx)(`span`,{className:`absolute -left-1 -top-[5px] h-2 w-2 rounded-full bg-destructive`})})]},z(e))})]})})]})}var gt=3;function _t({month:e,occurrences:t,selectedKey:n,pending:r,onSelect:i,onCreate:a,onMove:o,onPickDay:s,onEntryMenu:c,onSlotMenu:l,narrow:u}){let d=fe(e),f=ut(o),p=f.apply(t),m=(0,L.useMemo)(()=>ze(p),[p]),h=new Date,[g,_]=(0,L.useState)(null),v=(0,L.useRef)(g);(0,L.useEffect)(()=>{v.current=g});let y=e=>(document.elementFromPoint(e.clientX,e.clientY)?.closest(`[data-day]`))?.dataset.day??null,b=e=>{if(u||e.button!==0||e.target.closest(`button`))return;let t=y(e);t&&(e.currentTarget.setPointerCapture(e.pointerId),_({from:t,to:t}))},S=e=>{if(!v.current)return;let t=y(e);t&&t!==v.current.to&&_({...v.current,to:t})},C=e=>{let t=v.current;if(!t)return;e.currentTarget.releasePointerCapture(e.pointerId),_(null);let n=it(B(t.from),B(t.to));a(n.start,!0,n.end)},w=e=>{let t=y(e);t&&(e.preventDefault(),l(e,B(t),!0))},T=g?it(B(g.from),B(g.to)):r;return(0,Q.jsxs)(`div`,{className:`flex h-full min-h-0 flex-col`,children:[(0,Q.jsx)(`div`,{className:`grid shrink-0 grid-cols-7 border-b border-border text-center text-[10px] uppercase tracking-wide text-muted-foreground`,children:se.map(e=>(0,Q.jsx)(`span`,{className:`py-1`,children:u?e[0]:e},e))}),(0,Q.jsx)(`div`,{className:x(`grid min-h-0 flex-1 grid-cols-7 grid-rows-6 overflow-y-auto`,g&&`cursor-crosshair select-none`,f.moving&&`select-none`),onPointerDown:b,onPointerMove:S,onPointerUp:C,onPointerCancel:()=>_(null),onContextMenu:w,children:d.map(t=>{let r=z(t),a=m.get(r)??[],o=t.getMonth()===e.getMonth(),l=U(t,h),d=a.length-gt;return(0,Q.jsxs)(`div`,{role:`presentation`,"data-day":r,onClick:e=>{u&&e.target===e.currentTarget&&s(t)},className:x(`flex min-h-[3.5rem] min-w-0 flex-col gap-0.5 border-b border-r border-border/60 p-0.5`,!o&&`bg-muted/20 text-muted-foreground/60`,!u&&`cursor-cell`,T&&t>=T.start&&t<T.end&&`bg-primary/15 ring-1 ring-inset ring-primary`),children:[(0,Q.jsx)(`button`,{type:`button`,onClick:()=>s(t),className:x(`mx-auto flex h-5 w-5 items-center justify-center rounded-full text-[11px] hover:bg-muted sm:mx-0`,l&&`bg-primary font-bold text-primary-foreground hover:bg-primary`),title:`Open day`,children:t.getDate()}),u?(0,Q.jsx)(`div`,{className:`flex flex-wrap justify-center gap-0.5 px-0.5`,children:a.slice(0,4).map(e=>(0,Q.jsx)(`span`,{className:`h-1.5 w-1.5 rounded-full`,style:{background:tt(e)}},e.key))}):(0,Q.jsxs)(Q.Fragment,{children:[a.slice(0,gt).map(e=>(0,Q.jsx)(lt,{occurrence:e,selected:e.key===n,moving:f.moving?.key===e.key,onSelect:i,onContextMenu:t=>{t.preventDefault(),t.stopPropagation(),c(t,e)},...f.handlers(e)},e.key)),d>0&&(0,Q.jsxs)(`button`,{type:`button`,onClick:()=>s(t),className:`px-1 text-left text-[10px] text-muted-foreground hover:text-foreground`,children:[`+`,d,` more`]})]})]},r)})})]})}function vt({year:e,occurrences:t,onPickDay:n,onPickRange:r,onPickMonth:i,onSlotMenu:a}){let o=(0,L.useMemo)(()=>ze(t),[t]),s=Array.from({length:12},(t,n)=>new Date(e,n,1));return(0,Q.jsx)(`div`,{className:`grid h-full min-h-0 grid-cols-[repeat(auto-fill,minmax(11rem,1fr))] gap-x-4 gap-y-5 overflow-y-auto p-3`,children:s.map(e=>(0,Q.jsx)(ct,{month:e,marks:o,title:e.toLocaleDateString(void 0,{month:`long`}),onTitle:()=>i(e),onPick:n,onPickRange:r,onDayMenu:(e,t)=>a(e,t,!0)},z(e)))})}function yt({occurrences:e,selectedKey:t,onSelect:n,onEntryMenu:r,onEarlier:i,onLater:a,onPickDay:o,loading:s}){let c=(0,L.useMemo)(()=>[...ze(e).entries()].sort(([e],[t])=>e.localeCompare(t)),[e]),l=new Date;return(0,Q.jsxs)(`div`,{className:`h-full min-h-0 overflow-y-auto`,children:[(0,Q.jsx)(`div`,{className:`flex justify-center py-2`,children:(0,Q.jsx)(`button`,{type:`button`,onClick:i,className:`rounded-md border border-border px-3 py-1 text-xs text-muted-foreground hover:bg-muted hover:text-foreground`,children:`Earlier`})}),!s&&!c.length&&(0,Q.jsx)(`p`,{className:`py-10 text-center text-sm text-muted-foreground`,children:`Nothing scheduled in this range.`}),c.map(([e,i])=>{let a=B(e),s=U(a,l);return(0,Q.jsxs)(`div`,{className:`flex border-t border-border/60 px-2 py-2`,children:[(0,Q.jsxs)(`button`,{type:`button`,onClick:()=>o(a),className:`flex w-14 shrink-0 flex-col items-start`,title:`Open day`,children:[(0,Q.jsx)(`span`,{className:x(`flex h-8 w-8 items-center justify-center rounded-full text-lg font-semibold`,s&&`bg-primary text-primary-foreground`),children:a.getDate()}),(0,Q.jsxs)(`span`,{className:`text-[10px] uppercase tracking-wide text-muted-foreground`,children:[ge(a),`, `,se[(a.getDay()+6)%7]]})]}),(0,Q.jsx)(`div`,{className:`min-w-0 flex-1 space-y-0.5`,children:i.map(e=>{let i=tt(e),a=!Be(e)&&e.kind===`event`;return(0,Q.jsxs)(`button`,{type:`button`,onClick:()=>n(e),onContextMenu:t=>{t.preventDefault(),r(t,e)},className:x(`flex w-full items-center gap-2 rounded-md px-2 py-1 text-left text-sm hover:bg-muted`,e.key===t&&`bg-muted ring-1 ring-ring`,e.done&&`line-through opacity-60`),children:[(0,Q.jsx)(`span`,{className:`h-2.5 w-2.5 shrink-0 rounded-full`,style:{background:i}}),(0,Q.jsx)(`span`,{className:`w-[7.5rem] shrink-0 text-xs tabular-nums text-muted-foreground`,children:a?`${Z(e.start)}${e.end>e.start?` – ${Z(e.end)}`:``}`:e.kind===`task`?`due ${Z(e.start)}`:`All day`}),(0,Q.jsx)(`span`,{className:`truncate`,children:e.title}),e.calendar&&e.kind===`event`&&(0,Q.jsx)(`span`,{className:`ml-auto shrink-0 text-[10px] text-muted-foreground`,children:e.calendar})]},e.key)})})]},e)}),(0,Q.jsx)(`div`,{className:`flex justify-center py-2`,children:(0,Q.jsx)(`button`,{type:`button`,onClick:a,className:`rounded-md border border-border px-3 py-1 text-xs text-muted-foreground hover:bg-muted hover:text-foreground`,children:`Later`})})]})}var bt=`3.0`,xt=[{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 St(e,t){let n=e.data??{},r=n.allDay===!0,i=String(n.start??``),a=typeof n.end==`string`?n.end:``,o=typeof n.recurrence==`string`?n.recurrence:``,s=Oe(o||void 0);return{title:String(n.title??``),calendar:typeof n.calendar==`string`?n.calendar:wt(e)?``:t,allDay:r,start:r?i.slice(0,10):N(i),end:r?Tt(i.slice(0,10),a):N(a),location:String(n.location??``),description:String(n.description??``),repeat:s,rrule:o}}function Ct(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):ce(e.start),end:e.allDay?z(H(n,-1)<e.start?e.start:H(n,-1)):ce(n),location:``,description:``,repeat:`none`,rrule:``}}function wt(e){let t=e.metadata;return typeof t?.source==`string`&&t.source?{source:t.source,connector:typeof t.connector==`string`?t.connector:``}:null}function Tt(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 Et(e){return`${z(H(B(e),1))}T00:00:00.000Z`}function Dt(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():ke(t.repeat)),t.allDay?(n.start=`${t.start}T00:00:00.000Z`,r(`end`,t.end?Et(t.end):void 0)):(n.start=P(t.start),r(`end`,P(t.end))),n}function Ot(e){return e.title.trim()?e.start?e.end&&e.end<e.start?`The end is before the start.`:e.calendar.includes(`:`)?`A calendar name cannot contain ":".`:e.repeat===`custom`&&(!e.rrule.trim()||!Se(e.rrule))?`Enter a supported RRULE (FREQ=…, INTERVAL, COUNT, UNTIL, BYDAY, BYMONTHDAY, BYMONTH).`:null:`Pick a start.`:`Give the event a title.`}function kt({subject:e,target:t,workspaceName:n,calendars:r,defaultCalendar:a,onClose:o,onSaved:s,onDelete:u}){let d=e.kind===`occurrence`?e.occurrence.doc:null,p=e.kind===`occurrence`&&e.occurrence.kind===`task`,[m,h]=(0,L.useState)(()=>d?St(d,a):Ct(e.draft,a)),[g,y]=(0,L.useState)(!1),[S,C]=(0,L.useState)(null),[T,E]=(0,L.useState)(!1),D=e.kind===`draft`?`draft:${e.draft.start.getTime()}:${e.draft.end?.getTime()??``}:${e.draft.allDay}`:e.occurrence.key,[te,O]=(0,L.useState)(D);te!==D&&(O(D),h(d?St(d,a):Ct(e.draft,a)),C(null)),(0,L.useEffect)(()=>{let e=e=>{e.key===`Escape`&&o()};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[o]);let k=e=>h(t=>({...t,...e})),A=d?wt(d):null,j=typeof d?.data?.htmlLink==`string`?d.data.htmlLink:null,N=async()=>{let e=Ot(m);if(e){C(e);return}y(!0),C(null);try{if(d){if(!n)throw Error(`No workspace resolved for this calendar`);await ee(n,{id:d.id,schema:d.schema,schemaVersion:d.schemaVersion||bt,data:Dt(d.data??{},m),metadata:d.metadata})}else await ne(t,[{schema:w,schemaVersion:bt,data:Dt({},m),metadata:{features:[]}}]);s(m.calendar.trim())}catch(e){C(e instanceof Error?e.message:`Failed to save the event`)}finally{y(!1)}},P=p?`Task`:d?`Event`:`New event`;return(0,Q.jsxs)(`div`,{className:`flex h-full min-h-0 flex-col`,children:[(0,Q.jsxs)(`div`,{className:`flex shrink-0 items-center gap-2 border-b border-border px-3 py-2`,children:[(0,Q.jsx)(`span`,{className:`h-3 w-3 rounded-full`,style:{background:et(p?`tasks`:m.calendar)}}),(0,Q.jsx)(`span`,{className:`text-sm font-semibold`,children:P}),d&&(0,Q.jsxs)(`span`,{className:`text-[10px] text-muted-foreground`,children:[`#`,d.id]}),(0,Q.jsx)(`span`,{className:`flex-1`}),d&&n&&(0,Q.jsx)(i,{to:`/workspaces/${encodeURIComponent(n)}/documents/${d.id}`,className:`rounded p-1 text-muted-foreground hover:bg-muted hover:text-foreground`,title:`Open document`,"aria-label":`Open document`,children:(0,Q.jsx)(_,{className:`h-3.5 w-3.5`})}),d&&(0,Q.jsx)(`button`,{type:`button`,onClick:()=>E(!0),className:`rounded p-1 text-muted-foreground hover:bg-muted hover:text-foreground`,title:`Link to…`,"aria-label":`Link to…`,children:(0,Q.jsx)(b,{className:`h-3.5 w-3.5`})}),d&&!p&&(0,Q.jsx)(`button`,{type:`button`,onClick:()=>{u(d)},className:`rounded p-1 text-muted-foreground hover:bg-muted hover:text-destructive`,title:`Delete (moves to trash)`,"aria-label":`Delete`,children:(0,Q.jsx)(f,{className:`h-3.5 w-3.5`})}),(0,Q.jsx)(`button`,{type:`button`,onClick:o,className:`rounded p-1 text-muted-foreground hover:bg-muted hover:text-foreground`,"aria-label":`Close`,children:(0,Q.jsx)(c,{className:`h-4 w-4`})})]}),p&&d?(0,Q.jsx)(Mt,{doc:d,occurrence:e.occurrence,workspaceName:n,onSaved:()=>s(``)}):(0,Q.jsxs)(`div`,{className:`min-h-0 flex-1 space-y-3 overflow-y-auto p-3`,children:[(0,Q.jsx)(`input`,{value:m.title,onChange:e=>k({title:e.target.value}),placeholder:`Title`,autoFocus:!d,spellCheck:!1,className:`w-full border-0 border-b border-border bg-transparent px-0 py-1 text-base font-semibold outline-none placeholder:text-muted-foreground/60 focus:border-ring`}),(0,Q.jsx)(At,{value:m.calendar,calendars:r,onChange:e=>k({calendar:e})}),(0,Q.jsxs)(`label`,{className:`flex items-center gap-2 text-xs`,children:[(0,Q.jsx)(`input`,{type:`checkbox`,checked:m.allDay,onChange:e=>{let t=e.target.checked;if(t)k({allDay:t,start:m.start.slice(0,10),end:(m.end||m.start).slice(0,10)});else{let e=m.start.slice(0,10)||z(new Date);k({allDay:t,start:`${e}T09:00`,end:`${(m.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`}),m.allDay?(0,Q.jsx)(`div`,{className:`mt-1`,children:(0,Q.jsx)(F,{value:m.start,onChange:e=>k({start:e,end:m.end&&m.end<e?e:m.end})})}):(0,Q.jsx)(`div`,{className:`mt-1`,children:(0,Q.jsx)(M,{value:m.start,onChange:e=>k({start:e}),clearable:!1})})]}),(0,Q.jsxs)(`label`,{className:`block text-xs`,children:[(0,Q.jsx)(`span`,{className:`text-muted-foreground`,children:`End`}),m.allDay?(0,Q.jsx)(`div`,{className:`mt-1`,children:(0,Q.jsx)(F,{value:m.end,min:m.start,placeholder:`Same day`,onChange:e=>k({end:e})})}):(0,Q.jsx)(`div`,{className:`mt-1`,children:(0,Q.jsx)(M,{value:m.end,onChange:e=>k({end:e}),placeholder:`No end`})})]})]}),(0,Q.jsxs)(`label`,{className:`block text-xs`,children:[(0,Q.jsxs)(`span`,{className:`flex items-center gap-1 text-muted-foreground`,children:[(0,Q.jsx)(l,{className:`h-3 w-3`}),` Repeat`]}),(0,Q.jsx)(`select`,{value:m.repeat,onChange:e=>k({repeat:e.target.value,rrule:e.target.value===`custom`?m.rrule||ke(m.repeat)||`FREQ=WEEKLY`:m.rrule}),className:`mt-1 h-8 w-full rounded-md border border-input bg-transparent px-2 text-sm`,children:xt.map(e=>(0,Q.jsx)(`option`,{value:e.id,children:e.label},e.id))}),m.repeat===`custom`&&(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(`input`,{value:m.rrule,onChange:e=>k({rrule:e.target.value}),placeholder:`FREQ=WEEKLY;INTERVAL=2;BYDAY=TU,TH`,spellCheck:!1,className:`mt-1 h-8 w-full rounded-md border border-input bg-transparent px-2 font-mono text-xs`}),(0,Q.jsx)(`span`,{className:`mt-0.5 block text-[11px] text-muted-foreground`,children:Se(m.rrule)?De(Se(m.rrule)):`RFC 5545 RRULE value`})]})]}),(0,Q.jsxs)(`label`,{className:`block text-xs`,children:[(0,Q.jsx)(`span`,{className:`text-muted-foreground`,children:`Location`}),(0,Q.jsx)(`input`,{value:m.location,onChange:e=>k({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)(ae,{value:m.description,onChange:e=>k({description:e}),placeholder:`Notes, agenda, links…`})})]}),A&&(0,Q.jsxs)(`p`,{className:`rounded-md bg-muted/50 px-2 py-1.5 text-[11px] text-muted-foreground`,children:[`Synced from `,A.connector||A.source,`. Edits stay in Canvas unless the connector supports write-back.`,j&&(0,Q.jsxs)(Q.Fragment,{children:[` `,(0,Q.jsx)(`a`,{href:j,target:`_blank`,rel:`noopener noreferrer`,className:`underline hover:text-foreground`,children:`Open at source`})]})]}),e.kind===`occurrence`&&e.occurrence.unsupportedRule&&(0,Q.jsx)(`p`,{className:`text-[11px] text-muted-foreground`,children:`This series uses RRULE parts the calendar cannot expand; only its first occurrence is shown.`}),S&&(0,Q.jsx)(`p`,{className:`text-xs text-destructive`,role:`alert`,children:S})]}),!p&&(0,Q.jsxs)(`div`,{className:`flex shrink-0 items-center justify-end gap-2 border-t border-border px-3 py-2`,children:[(0,Q.jsx)(jt,{doc:d}),(0,Q.jsx)(`button`,{type:`button`,onClick:o,className:`rounded-md border border-border px-3 py-1.5 text-xs hover:bg-muted`,children:`Cancel`}),(0,Q.jsxs)(`button`,{type:`button`,onClick:N,disabled:g,className:x(`flex items-center gap-1 rounded-md bg-primary px-3 py-1.5 text-xs text-primary-foreground disabled:opacity-50`),children:[g&&(0,Q.jsx)(v,{className:`h-3 w-3 animate-spin`}),d?`Save`:`Create`]})]}),T&&d&&(0,Q.jsx)(ie,{documentId:d.id,workspaceName:n??void 0,onClose:()=>E(!1)})]})}function At({value:e,calendars:t,onChange:n}){let r=t.some(t=>t.toLowerCase()===e.toLowerCase()),[i,a]=(0,L.useState)(!r&&!e&&t.length===0),o=r||!e?t:[e,...t];return(0,Q.jsxs)(`label`,{className:`block text-xs`,children:[(0,Q.jsx)(`span`,{className:`text-muted-foreground`,children:`Calendar`}),i?(0,Q.jsxs)(`span`,{className:`mt-1 flex gap-1`,children:[(0,Q.jsx)(`input`,{autoFocus:!0,value:e,onChange:e=>n(e.target.value),placeholder:`New calendar name`,spellCheck:!1,className:`h-8 min-w-0 flex-1 rounded-md border border-input bg-transparent px-2 text-sm outline-none focus-visible:ring-1 focus-visible:ring-ring`}),t.length>0&&(0,Q.jsx)(`button`,{type:`button`,onClick:()=>{a(!1),n(t[0])},className:`rounded-md border border-border px-2 text-xs text-muted-foreground hover:bg-muted`,"aria-label":`Pick an existing calendar`,children:(0,Q.jsx)(c,{className:`h-3 w-3`})})]}):(0,Q.jsxs)(`select`,{value:e,onChange:e=>{e.target.value===`\0new`?(a(!0),n(``)):n(e.target.value)},className:`mt-1 h-8 w-full rounded-md border border-input bg-transparent px-2 text-sm`,children:[!e&&(0,Q.jsx)(`option`,{value:``,children:`No calendar`}),o.map(e=>(0,Q.jsx)(`option`,{value:e,children:e},e)),(0,Q.jsx)(`option`,{value:`\0new`,children:`New calendar…`})]})]})}function jt({doc:e}){let t=O(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 Mt({doc:e,occurrence:t,workspaceName:n,onSaved:r}){let[i,o]=(0,L.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 ee(n,{id:e.id,schema:e.schema,schemaVersion:e.schemaVersion,data:{...e.data??{},status:t,completed:t===`completed`},metadata:e.metadata}),r()}finally{o(!1)}}},disabled:i,className:`mt-0.5 text-muted-foreground hover:text-foreground`,"aria-label":s?`Mark as pending`:`Mark as completed`,children:s?(0,Q.jsx)(a,{className:`h-4 w-4 text-success`}):(0,Q.jsx)(g,{className:`h-4 w-4`})}),(0,Q.jsxs)(`div`,{className:`min-w-0`,children:[(0,Q.jsx)(`p`,{className:x(`font-semibold`,s&&`line-through text-muted-foreground`),children:t.title}),(0,Q.jsxs)(`p`,{className:`text-xs text-muted-foreground`,children:[`Due `,t.start.toLocaleString(void 0,{dateStyle:`medium`,timeStyle:`short`})]})]})]}),typeof e.data?.description==`string`&&e.data.description&&(0,Q.jsx)(`p`,{className:`whitespace-pre-wrap text-xs text-muted-foreground`,children:e.data.description}),(0,Q.jsx)(`p`,{className:`text-[11px] text-muted-foreground`,children:`Edit the task in the Todos app or on its document page.`})]})}function Nt({menu:e,onClose:t,onOpen:n,onOpenDocument:r,onToggleDone:i,onDelete:o,onCreate:s,onPickDay:c}){let l=e=>()=>{t(),e()};return(0,Q.jsx)(S,{x:e.x,y:e.y,onClose:t,className:`min-w-44 rounded-md border bg-popover p-1 text-xs shadow-elevation-3`,children:e.kind===`entry`?(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(`p`,{className:`truncate px-3 py-1.5 text-[11px] text-muted-foreground`,title:e.occurrence.title,children:e.occurrence.title}),(0,Q.jsx)(Pt,{icon:(0,Q.jsx)(h,{className:`h-3.5 w-3.5`}),onClick:l(()=>n(e.occurrence)),children:`Open`}),r&&(0,Q.jsx)(Pt,{icon:(0,Q.jsx)(_,{className:`h-3.5 w-3.5`}),onClick:l(()=>r(e.occurrence)),children:`Open document`}),e.occurrence.kind===`task`&&(0,Q.jsx)(Pt,{icon:e.occurrence.done?(0,Q.jsx)(g,{className:`h-3.5 w-3.5`}):(0,Q.jsx)(a,{className:`h-3.5 w-3.5`}),onClick:l(()=>i(e.occurrence)),children:e.occurrence.done?`Mark as pending`:`Mark as completed`}),e.occurrence.kind===`event`&&(0,Q.jsx)(Pt,{icon:(0,Q.jsx)(f,{className:`h-3.5 w-3.5`}),className:`text-destructive`,onClick:l(()=>o(e.occurrence)),children:`Delete…`})]}):(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsxs)(`p`,{className:`px-3 py-1.5 text-[11px] text-muted-foreground`,children:[X(e.start),e.allDay?``:`, ${Z(e.start)}`]}),(0,Q.jsx)(Pt,{icon:(0,Q.jsx)(y,{className:`h-3.5 w-3.5`}),onClick:l(()=>s(e.start,e.allDay)),children:e.allDay?`New event`:`New event at ${Z(e.start)}`}),!e.allDay&&(0,Q.jsx)(Pt,{icon:(0,Q.jsx)(m,{className:`h-3.5 w-3.5`}),onClick:l(()=>s(e.start,!0)),children:`New all-day event`}),(0,Q.jsx)(Pt,{icon:(0,Q.jsx)(h,{className:`h-3.5 w-3.5`}),onClick:l(()=>c(e.start)),children:`Open day`})]})})}function Pt({icon:e,onClick:t,className:n,children:r}){return(0,Q.jsxs)(`button`,{type:`button`,onClick:t,className:x(`flex w-full items-center gap-2 rounded px-3 py-1.5 text-left hover:bg-accent`,n),children:[(0,Q.jsx)(`span`,{className:`text-muted-foreground`,children:e}),r]})}var Ft=640,It=420,Lt=30,Rt=14;function zt(e,t,n,r){switch(e){case`day`:{let e=V(t);return{start:e,end:H(e,n)}}case`week`:{let e=ue(t);return{start:e,end:H(e,7)}}case`month`:{let e=fe(t);return{start:e[0],end:H(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=V(t);return{start:H(e,-r.before),end:H(e,r.after)}}}}function Bt(e,t,n,r){switch(e){case`day`:return H(t,n*r);case`week`:return H(t,7*r);case`month`:return le(t,r);case`year`:return new Date(t.getFullYear()+r,t.getMonth(),1);case`schedule`:return H(t,Lt*r)}}function Vt(e,t,n,r){switch(e){case`day`:return n>1?_e(t,H(t,n-1)):r?X(t):Y(t);case`week`:return ve(ue(t));case`month`:return he(t);case`year`:return String(t.getFullYear());case`schedule`:return r?X(t):`From ${Y(t)}`}}function Ht({autoAdd:e=!1}){let t=re(),n=t?.mode===`workspace`?t.workspaceName:t?.mode===`context`?`ctx:${t.contextId}`:null,[i,a]=(0,L.useState)(()=>qe(n)),c=(0,L.useCallback)(e=>{a(t=>{let r={...t,...e};return Je(n,r),r})},[n]),l=i.view,[f,m]=(0,L.useState)(()=>V(new Date)),[h,g]=(0,L.useState)(1),[_,y]=(0,L.useState)(null),b=r(),[S,C]=(0,L.useState)({before:0,after:Lt}),[w,T]=(0,L.useState)(()=>e?{kind:`draft`,draft:{start:Ut(),allDay:!1}}:null),[E,D]=(0,L.useState)(!1),te=(0,L.useRef)(null),[O,ne]=(0,L.useState)(1024);(0,L.useEffect)(()=>{let e=te.current;if(!e)return;let t=new ResizeObserver(e=>{for(let t of e)ne(t.contentRect.width)});return t.observe(e),()=>t.disconnect()},[]);let A=O<Ft,j=O<It,M=(0,L.useMemo)(()=>zt(l,f,h,S),[l,f,h,S]),{docs:N,loading:P,error:F,scope:I,knownCalendars:ie,reload:ae,removeDoc:se,patchDoc:R}=$e(t,M.start,M.end,i.showTasks),z=(0,L.useMemo)(()=>{let e=new Map;for(let t of ie)e.set(t,t);for(let t of N){let n=t.data?.calendar;typeof n==`string`&&n.trim()&&e.set(n.trim().toLowerCase(),n.trim())}return i.defaultCalendar&&e.set(i.defaultCalendar.toLowerCase(),e.get(i.defaultCalendar.toLowerCase())??i.defaultCalendar),[...e.values()].sort((e,t)=>e.localeCompare(t))},[ie,N,i.defaultCalendar]),B=(0,L.useMemo)(()=>new Set(i.hidden),[i.hidden]),ce=(0,L.useMemo)(()=>N.some(e=>e.schema.startsWith(`data/schema/event`)&&!(typeof e.data?.calendar==`string`&&e.data.calendar.trim())),[N]),U=(0,L.useMemo)(()=>Re(N.filter(e=>{let t=typeof e.data?.calendar==`string`?e.data.calendar.trim().toLowerCase():``;return!B.has(t||``)}),M.start,M.end),[N,B,M]),fe=w?.kind===`occurrence`?w.occurrence.key:null,W=(0,L.useCallback)((e,t)=>{m(V(e)),g(1),C({before:0,after:Lt}),t&&c({view:t})},[c]),G=(0,L.useCallback)((e,t)=>{let n=Math.round((V(t).getTime()-V(e).getTime())/oe);if(n>Rt){W(e,`month`);return}W(e,`day`),g(Math.max(1,n))},[W]),pe=(0,L.useCallback)(e=>{g(1),c({view:e})},[c]),K=(0,L.useMemo)(()=>l===`day`||l===`week`?{start:M.start,end:M.end}:{start:f,end:H(f,1)},[l,M,f]),me=(0,L.useMemo)(()=>{if(w?.kind!==`draft`)return null;let{start:e,allDay:t,end:n}=w.draft;return{start:e,allDay:t,end:n??(t?H(V(e),1):new Date(e.getTime()+36e5))}},[w]),q=(0,L.useCallback)((e,t,n)=>T({kind:`draft`,draft:{start:e,allDay:t,end:n}}),[]),J=(0,L.useCallback)(e=>T({kind:`occurrence`,occurrence:e}),[]),he=(0,L.useCallback)(async(e,t,n)=>{if(!I)return;let r=e.doc,i=He(r.data??{},e,t,n);R({...r,data:i});try{await ee(I.workspaceName,{id:r.id,schema:r.schema,schemaVersion:r.schemaVersion||`3.0`,data:i,metadata:r.metadata})}catch{R(r)}},[I,R]),ge=(0,L.useCallback)(async e=>{if(!I)return;let t=e.doc,n=e.done?`pending`:`completed`,r={...t.data??{},status:n,completed:n===`completed`};R({...t,data:r});try{await ee(I.workspaceName,{id:t.id,schema:t.schema,schemaVersion:t.schemaVersion,data:r,metadata:t.metadata})}catch{R(t)}},[I,R]),Y=(0,L.useCallback)((e,t)=>y({x:e.clientX,y:e.clientY,kind:`entry`,occurrence:t}),[]),X=(0,L.useCallback)((e,t,n)=>y({x:e.clientX,y:e.clientY,kind:`slot`,start:t,allDay:n}),[]),Z=(0,L.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 se(e.id),T(null)}catch{}},[se]),_e=e=>{let t=e.target;if(!([`INPUT`,`TEXTAREA`,`SELECT`].includes(t.tagName)||t.isContentEditable)){if(e.key===`ArrowLeft`)ve(-1),e.preventDefault();else if(e.key===`ArrowRight`)ve(1),e.preventDefault();else if(e.key===`t`)W(new Date);else if(e.key===`n`)q(Ut(f),!1);else if(e.key===`Escape`)T(null),D(!1);else{let t=Ue.find(t=>t.key===e.key);t&&pe(t.id)}}},ve=e=>{let t=h;W(Bt(l,f,h,e)),g(t)};if(!t)return(0,Q.jsx)(`div`,{className:`flex h-full items-center justify-center p-6 text-center text-sm text-muted-foreground`,children:k(t)});let ye=e=>{let t=e.toLowerCase();c({hidden:B.has(t)?i.hidden.filter(e=>e!==t):[...i.hidden,t]})},be=(0,Q.jsxs)(`div`,{className:`space-y-1 text-xs`,children:[(0,Q.jsx)(`p`,{className:`px-1 text-[10px] uppercase tracking-wide text-muted-foreground`,children:`Calendars`}),z.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:!B.has(e.toLowerCase()),onChange:()=>ye(e),className:`h-3.5 w-3.5 accent-primary`,style:{accentColor:et(e)}}),(0,Q.jsx)(`span`,{className:`h-2.5 w-2.5 shrink-0 rounded-sm`,style:{background:et(e)}}),(0,Q.jsx)(`span`,{className:`truncate`,children:e})]},e)),ce&&(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:!B.has(``),onChange:()=>ye(``),className:`h-3.5 w-3.5 accent-primary`}),(0,Q.jsx)(`span`,{className:`h-2.5 w-2.5 shrink-0 rounded-sm`,style:{background:et(``)}}),(0,Q.jsx)(`span`,{className:`truncate text-muted-foreground`,children:`Other events`})]}),(0,Q.jsxs)(`label`,{className:`flex cursor-pointer items-center gap-2 rounded px-1 py-0.5 hover:bg-muted`,children:[(0,Q.jsx)(`input`,{type:`checkbox`,checked:i.showTasks,onChange:e=>c({showTasks:e.target.checked}),className:`h-3.5 w-3.5 accent-primary`}),(0,Q.jsx)(`span`,{className:`h-2.5 w-2.5 shrink-0 rounded-sm`,style:{background:et(Ae)}}),(0,Q.jsx)(`span`,{className:`truncate`,children:`Tasks (due dates)`})]})]}),xe=(()=>{switch(l){case`day`:return(0,Q.jsx)(ht,{days:Array.from({length:h},(e,t)=>H(V(f),t)),occurrences:U,selectedKey:fe,pending:me,onSelect:J,onCreate:q,onMove:he,onPickDay:e=>W(e,`day`),onEntryMenu:Y,onSlotMenu:X,compact:j||h>3});case`week`:return(0,Q.jsx)(ht,{days:Array.from({length:7},(e,t)=>H(ue(f),t)),occurrences:U,selectedKey:fe,pending:me,onSelect:J,onCreate:q,onMove:he,onPickDay:e=>W(e,`day`),onEntryMenu:Y,onSlotMenu:X,compact:A});case`month`:return(0,Q.jsx)(_t,{month:de(f),occurrences:U,selectedKey:fe,pending:me,onSelect:J,onCreate:q,onMove:he,onPickDay:e=>W(e,`day`),onEntryMenu:Y,onSlotMenu:X,narrow:A});case`year`:return(0,Q.jsx)(vt,{year:f.getFullYear(),occurrences:U,onPickDay:e=>W(e,`day`),onPickRange:G,onPickMonth:e=>W(e,`month`),onSlotMenu:X});case`schedule`:return(0,Q.jsx)(yt,{occurrences:U,selectedKey:fe,onSelect:J,onEntryMenu:Y,loading:P,onEarlier:()=>C(e=>({...e,before:e.before+Lt})),onLater:()=>C(e=>({...e,after:e.after+Lt})),onPickDay:e=>W(e,`day`)})}})();return(0,Q.jsxs)(`div`,{ref:te,tabIndex:0,onKeyDown:_e,className:`relative flex h-full min-h-0 flex-col outline-none`,children:[(0,Q.jsxs)(`div`,{className:`flex shrink-0 flex-wrap items-center gap-1.5 border-b border-border px-2 py-1.5`,children:[(0,Q.jsx)(`button`,{type:`button`,onClick:()=>W(new Date),className:`rounded-md border border-border px-2 py-1 text-xs hover:bg-muted`,title:`Today (t)`,children:`Today`}),(0,Q.jsx)(`button`,{type:`button`,onClick:()=>ve(-1),className:`rounded-md p-1 text-muted-foreground hover:bg-muted hover:text-foreground`,"aria-label":`Previous`,title:`Previous (←)`,children:(0,Q.jsx)(o,{className:`h-4 w-4`})}),(0,Q.jsx)(`button`,{type:`button`,onClick:()=>ve(1),className:`rounded-md p-1 text-muted-foreground hover:bg-muted hover:text-foreground`,"aria-label":`Next`,title:`Next (→)`,children:(0,Q.jsx)(d,{className:`h-4 w-4`})}),(0,Q.jsx)(`span`,{className:`min-w-0 truncate text-sm font-semibold`,children:Vt(l,f,h,j)}),P&&(0,Q.jsx)(v,{className:`h-3.5 w-3.5 animate-spin text-muted-foreground`}),(0,Q.jsx)(`span`,{className:`flex-1`}),j?(0,Q.jsx)(`select`,{value:l,onChange:e=>pe(e.target.value),"aria-label":`View`,className:`h-7 rounded-md border border-input bg-transparent px-1.5 text-xs`,children:Ue.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:Ue.map(e=>(0,Q.jsx)(`button`,{type:`button`,role:`tab`,"aria-selected":l===e.id,onClick:()=>pe(e.id),title:`${e.label} (${e.key})`,className:x(`px-2 py-1 text-xs transition-colors`,l===e.id?`bg-foreground text-background`:`text-muted-foreground hover:bg-muted hover:text-foreground`),children:e.label},e.id))}),A&&(0,Q.jsx)(`button`,{type:`button`,onClick:()=>D(e=>!e),className:x(`rounded-md border p-1.5`,E?`border-foreground text-foreground`:`border-border text-muted-foreground hover:bg-muted hover:text-foreground`),"aria-label":`Calendars`,title:`Calendars`,children:(0,Q.jsx)(p,{className:`h-3.5 w-3.5`})}),(0,Q.jsxs)(`button`,{type:`button`,onClick:()=>q(Ut(f),!1),className:`flex items-center gap-1 rounded-md bg-primary px-2 py-1.5 text-xs text-primary-foreground`,title:`New event (n)`,children:[(0,Q.jsx)(u,{className:`h-3.5 w-3.5`}),!j&&`Event`]})]}),F&&(0,Q.jsx)(`p`,{className:`border-b border-border px-3 py-2 text-xs text-destructive`,children:F}),(0,Q.jsxs)(`div`,{className:`flex min-h-0 flex-1`,children:[!A&&(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)(ct,{month:de(f),selection:K,onPick:e=>W(e,l===`year`||l===`month`?`day`:l),onPickRange:G,onPrev:()=>m(e=>le(e,-1)),onNext:()=>m(e=>le(e,1))}),be]}),(0,Q.jsxs)(`div`,{className:`relative min-w-0 flex-1`,children:[xe,A&&E&&(0,Q.jsx)(`div`,{className:`absolute right-2 top-2 z-20 w-56 rounded-md border border-border bg-popover p-2 text-popover-foreground shadow-elevation-2`,children:be})]}),w&&!A&&(0,Q.jsx)(`aside`,{className:`w-80 shrink-0 border-l border-border bg-card`,children:(0,Q.jsx)(kt,{subject:w,target:t,workspaceName:I?.workspaceName??null,calendars:z,defaultCalendar:i.defaultCalendar,onClose:()=>T(null),onSaved:e=>{e&&c({defaultCalendar:e}),T(null),ae()},onDelete:Z})})]}),w&&A&&(0,Q.jsx)(`div`,{className:`absolute inset-0 z-30 flex flex-col bg-card`,children:(0,Q.jsx)(kt,{subject:w,target:t,workspaceName:I?.workspaceName??null,calendars:z,defaultCalendar:i.defaultCalendar,onClose:()=>T(null),onSaved:e=>{e&&c({defaultCalendar:e}),T(null),ae()},onDelete:Z})}),_&&(0,Q.jsx)(Nt,{menu:_,onClose:()=>y(null),onOpen:J,onOpenDocument:I?e=>b(`/workspaces/${encodeURIComponent(I.workspaceName)}/documents/${e.doc.id}`):null,onToggleDone:e=>{ge(e)},onDelete:e=>{Z(e.doc)},onCreate:(e,t)=>q(e,t),onPickDay:e=>W(e,`day`)}),!P&&!F&&!N.length&&l!==`schedule`&&(0,Q.jsxs)(`p`,{className:`pointer-events-none absolute bottom-2 left-1/2 -translate-x-1/2 rounded-full bg-muted/80 px-3 py-1 text-[11px] text-muted-foreground`,children:[(0,Q.jsx)(s,{className:`mr-1 inline h-3 w-3`}),`Nothing here yet — click or drag a slot to add an event.`]})]})}function Ut(e){let t=new Date,n=e&&!Wt(e,t)?new Date(e.getFullYear(),e.getMonth(),e.getDate(),9,0):new Date(t);return(!e||Wt(e,t))&&n.setMinutes(t.getMinutes()<30?30:60,0,0),n}function Wt(e,t){return e.toDateString()===t.toDateString()}export{Ht as CalendarApplet};
@@ -1,3 +0,0 @@
1
- import{o as e}from"./rolldown-runtime-C0FnF6B9.js";import{l as t,u as n}from"./code-editor-BOIngd5F.js";import{yt as r}from"./react-BHzhHVTZ.js";import{g as i}from"./chunk-62JRHF6Z-vspAGgtK.js";import{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-CDoK3F3U.js";import{t as m}from"./utils-2pl1SbIp.js";import{t as h}from"./input-BOtCd4HP.js";import{t as g}from"./label-BSTdjCWU.js";import{t as _}from"./LinkToCard-BQ1yoFDr.js";import{zt as v}from"./workspace-BJELPCNs.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-DZRqtnIG.js";import{n as C,r as te}from"./use-toolbox-Ck_cLGgf.js";import{l as ne}from"./date-time-picker-txVhlNO0.js";import{n as w,t as re}from"./PickDocumentsCard-CFDQL70e.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-CVO5KPCs.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-Ci1akl_D.js";import{A as I,O as L,j as R,k as z}from"./index-VAgMESOp.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
- 
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 +0,0 @@
1
- import{o as e}from"./rolldown-runtime-C0FnF6B9.js";import{l as t,u as n}from"./code-editor-BOIngd5F.js";import{h as r}from"./chunk-62JRHF6Z-vspAGgtK.js";import{Ct as i,Er as a,G as o,Jr as s,L as c,Lt as l,Pt as u,Rt as d,St as f,Vr as p,Wt as m,X as h,Zr as g,bn as _,ct as v,hn as y,it as b,mt as x,ri as S,tt as C,yn as w}from"./ui-CDoK3F3U.js";import{t as T}from"./utils-2pl1SbIp.js";import{An as E,Cn as D,Hn as O,K as k}from"./workspace-BJELPCNs.js";import{t as ee}from"./TodosWidget-CYK5RbYD.js";import{d as te,o as ne,u as re}from"./ObjectPropertiesCard-BTTwYnN9.js";import{h as ie,s as ae,t as oe,u as se}from"./document-list-CQ1_7Sja.js";import{n as ce,r as le}from"./use-toolbox-Ck_cLGgf.js";import{t as ue}from"./useToastHelpers-CRrpIIdY.js";import{n as A}from"./color-DFEH4BfK.js";import{t as de}from"./DocumentIcon-9i1uCMQa.js";import{r as fe}from"./workspace-BydSRtST.js";import{t as j}from"./registry-DQPkddij.js";import{t as pe}from"./FileForm-C35drQ_R.js";import{t as me}from"./applet-target-I8w6EPj0.js";var M=e(n(),1);function he(e){let{pathname:t}=r(),n=le()?.setAgentView,i=JSON.stringify(e);(0,M.useEffect)(()=>(n?.({pathname:t,view:JSON.parse(i)}),()=>n?.(null)),[t,i,n])}function ge(e,t,n,r){return structuredClone({...e,query:fe(t,n,r),timezone:Intl.DateTimeFormat().resolvedOptions().timeZone})}var N=t();function _e({target:e,children:t}){let[n,r]=(0,M.useState)([]),i=(0,M.useRef)(!1),[a,o]=(0,M.useState)(!1),[s,c]=(0,M.useState)(!1),[l,u]=(0,M.useState)(null),{showErrorToast:d}=ue();return(0,N.jsxs)(`div`,{className:`relative flex flex-col h-full min-h-0 bg-background ${a?`ring-2 ring-inset ring-primary`:``}`,onDragOverCapture:t=>{s||!e||!Array.from(t.dataTransfer.types).includes(`Files`)||(t.preventDefault(),t.stopPropagation(),t.dataTransfer.dropEffect=i.current?`none`:`copy`,o(!i.current))},onDragLeaveCapture:e=>{e.currentTarget.contains(e.relatedTarget)||o(!1)},onDropCapture:t=>{if(s||!e||!Array.from(t.dataTransfer.types).includes(`Files`))return;if(t.preventDefault(),t.stopPropagation(),o(!1),i.current){d(`Wait for the current upload to finish`);return}let n=Array.from(t.dataTransfer.files);if(!n.length){d(`Drop files rather than folders`);return}r(n),u(e),c(!0)},children:[t,a&&(0,N.jsxs)(`div`,{className:`pointer-events-none absolute inset-0 z-30 flex items-center justify-center bg-background/80 text-sm font-medium`,children:[`Drop files to upload to `,e?.mode===`workspace`?e.path:`this context`]}),s&&(0,N.jsxs)(se,{label:`Import files`,onClose:()=>{i.current||c(!1)},children:[(0,N.jsx)(`h2`,{className:`border-b px-4 py-3 text-sm font-medium`,children:`Import files`}),(0,N.jsx)(pe,{target:l,initialFiles:n,onClose:()=>c(!1),onBusyChange:e=>{i.current=e}})]})]})}function P({navigationTabs:e,navigationActions:t,onBack:n,accentColor:r,frameContent:a=!0,urlType:s,urlDisplay:c,contextPath:u,treeName:f,workspaceId:p,workspaceLabel:m,workspaceIcon:g,documentSchema:v,documents:y,isLoading:b,totalCount:C,currentPage:w,pageSize:T,onPageChange:E,onPageSizeChange:O,onRemoveDocument:k,onDeleteDocument:ee,onDestroyDocument:ae,onRemoveDocuments:se,onDeleteDocuments:le,onDestroyDocuments:ue,onCopyDocuments:A,onCutDocuments:de,onPasteDocuments:fe,onImportDocuments:j,onSelectionChange:pe,pastedDocumentIds:me,onPurgeDocuments:he,disablePurgeDocuments:ge,canvasInfo:P,isCanvasPinned:F,onTogglePinCanvas:I,onSaveAsCanvas:L,onShareCanvas:R,onUnshareCanvas:z,onDeleteCanvas:B,isSharingCanvas:V,isDeletingCanvas:H,isCanvasShared:U,isCanvasLocked:W,backendSearchQueries:G,onBackendSearch:K,onRemoveBackendQuery:q,serverSort:ve,onServerSortChange:ye,scope:be,onScopeChange:xe,canSaveChanges:Se,isSavingChanges:J,onSaveChanges:Y,onBrowseWorkspaces:Ce,onBrowseTree:we,onNavigatePath:Te,linkTree:Ee,children:X,contentBanner:De,folders:Oe,onOpenFolder:ke}){let Ae=s===`canvas`,Z=ie(),{state:je,toggleView:Me,hasActiveFilters:Ne,openAddPicker:Pe}=ce(),Q=ne(),[Fe,$]=(0,M.useState)(``),Ie=JSON.stringify([p,f,u,v]),[Le,Re]=(0,M.useState)(Ie);Le!==Ie&&(Re(Ie),$(``));let ze=(0,N.jsxs)(N.Fragment,{children:[t,L&&(0,N.jsx)(`button`,{type:`button`,onClick:L,title:`Save as canvas`,"aria-label":`Save as canvas`,className:`flex h-control-sm w-control-sm shrink-0 items-center justify-center rounded-md border text-muted-foreground hover:bg-accent touch-target`,children:(0,N.jsx)(S,{className:`h-4 w-4`})})]});return(0,N.jsxs)(_e,{target:j&&p?{mode:`workspace`,workspaceName:p,path:u,treeName:f||`context`,treeType:D(f)}:null,children:[e&&!Z&&(0,N.jsx)(te,{accentColor:r,children:e}),(0,N.jsxs)(`div`,{className:`canvas-surface-body${a&&!Z?` is-framed`:``}`,children:[(0,N.jsx)(re,{workspaceIcon:g,workspace:m||p||c.split(`://`)[0]||`Workspace`,actions:Z&&e?(0,N.jsxs)(`details`,{className:`relative shrink-0`,"aria-label":`Canvas views`,children:[(0,N.jsx)(`summary`,{className:`cursor-pointer rounded-md border px-2 py-1 text-xs`,title:`Choose or manage content views`,children:`Views`}),(0,N.jsx)(`div`,{className:`absolute right-0 top-full z-30 mt-2 min-w-64 max-w-[80vw] rounded-md border bg-background p-2 shadow-lg`,children:e})]}):void 0,tree:f?`${f}${s.endsWith(`-layer`)?`:layer`:``}`:s.replace(`-layer`,``),path:u,accentColor:r,onBack:Q.location?Q.location.section===`view`?Q.close:()=>Q.update?.({section:`view`}):n,section:Q.location?`document/${Q.location.documentId}/${Q.location.section}`:void 0,onSection:Q.location?()=>Q.update?.({section:`view`}):void 0,onBrowseWorkspaces:Ce,onBrowseTree:we,onNavigatePath:Te,onFilter:()=>Me(`tools`),filtersActive:Ne,filtersOpen:je.t1Open&&je.t1View===`tools`,onAdd:e=>Pe({modal:e.shiftKey,fresh:!0}),search:K||!X?{workspaceId:p,queries:G||[],onSearch:K??$,localOnly:!K,onRemoveQuery:q,scope:be,onScopeChange:xe}:void 0,onDraftChange:X?void 0:$}),Ae&&P?(0,N.jsx)(N.Fragment,{children:(0,N.jsxs)(`div`,{className:`flex items-center gap-3 px-4 py-2.5 border-b bg-muted/20 shrink-0 min-w-0`,children:[P.color&&(0,N.jsx)(`div`,{className:`w-1 h-6 rounded-full shrink-0`,style:{backgroundColor:P.color}}),(0,N.jsx)(_,{className:`w-4 h-4 shrink-0 text-primary`}),(0,N.jsxs)(`div`,{className:`flex flex-col min-w-0 flex-1`,children:[(0,N.jsx)(`span`,{className:`text-lg font-semibold leading-tight truncate`,children:P.label||c.split(`://`)[1]||`Canvas`}),P.description&&(0,N.jsx)(`span`,{className:`text-xs text-muted-foreground truncate leading-tight`,children:P.description})]}),Se&&Y&&(0,N.jsxs)(`button`,{type:`button`,onClick:Y,disabled:J,className:`shrink-0 flex items-center gap-1.5 px-2.5 py-1 text-xs border rounded-md hover:bg-accent transition-colors text-muted-foreground hover:text-foreground disabled:opacity-50`,title:`Save filters`,children:[(0,N.jsx)(i,{className:`w-3 h-3`}),(0,N.jsx)(`span`,{className:`hidden sm:inline`,children:J?`Saving...`:`Save filters`})]}),I&&(0,N.jsxs)(`button`,{type:`button`,onClick:I,"aria-pressed":!!F,className:`shrink-0 flex items-center gap-1.5 px-2.5 py-1 text-xs border rounded-md hover:bg-accent transition-colors text-muted-foreground hover:text-foreground`,title:F?`Unpin from home`:`Pin to home`,children:[F?(0,N.jsx)(d,{className:`w-3 h-3`}):(0,N.jsx)(l,{className:`w-3 h-3`}),(0,N.jsx)(`span`,{className:`hidden sm:inline`,children:F?`Unpin`:`Pin`})]}),R&&(0,N.jsxs)(`button`,{type:`button`,onClick:R,disabled:V||H,className:`shrink-0 flex items-center gap-1.5 px-2.5 py-1 text-xs border rounded-md hover:bg-accent transition-colors text-muted-foreground hover:text-foreground disabled:opacity-50`,title:U?`Copy public link`:`Share canvas`,children:[(0,N.jsx)(x,{className:`w-3 h-3`}),(0,N.jsx)(`span`,{className:`hidden sm:inline`,children:V?`Sharing...`:U?`Copy link`:`Share`})]}),U&&z&&(0,N.jsxs)(`button`,{type:`button`,onClick:z,disabled:V||H,className:`shrink-0 flex items-center gap-1.5 px-2.5 py-1 text-xs border rounded-md hover:bg-destructive/10 transition-colors text-muted-foreground hover:text-destructive disabled:opacity-50`,children:[(0,N.jsx)(o,{className:`w-3 h-3`}),(0,N.jsx)(`span`,{className:`hidden sm:inline`,children:`Unshare`})]}),B&&(0,N.jsxs)(`button`,{type:`button`,onClick:B,disabled:H||W&&!U,title:W&&!U?`Unlock this canvas before deleting it`:`Delete canvas`,className:`shrink-0 flex items-center gap-1.5 px-2.5 py-1 text-xs border rounded-md hover:bg-destructive/10 transition-colors text-muted-foreground hover:text-destructive disabled:opacity-50`,children:[(0,N.jsx)(h,{className:`w-3 h-3`}),(0,N.jsx)(`span`,{className:`hidden sm:inline`,children:H?`Deleting…`:`Delete`})]})]})}):null,X&&(L||t)&&(0,N.jsx)(`div`,{className:`flex items-center gap-2 border-b px-3 py-1`,children:ze}),(0,N.jsxs)(`div`,{className:`flex-1 min-h-0 overflow-y-auto`,children:[De,X||(0,N.jsx)(oe,{readingPane:!0,externalSearchQuery:Fe,toolbarActions:ze,documents:v?y.filter(e=>e.schema===v):y,isLoading:b,folders:v?void 0:Oe,onOpenFolder:ke,contextPath:u,treeName:f,workspaceId:p,totalCount:C,viewMode:v?`card`:`table`,allowViewToggle:!0,currentPage:w,pageSize:T,onPageChange:E,onPageSizeChange:O,onRemoveDocument:k,onDeleteDocument:ee,onDestroyDocument:ae,onRemoveDocuments:se,onDeleteDocuments:le,onDestroyDocuments:ue,onCopyDocuments:A,onCutDocuments:de,onPasteDocuments:fe,onImportDocuments:j,onSelectionChange:pe,pastedDocumentIds:me,onPurgeDocuments:v?void 0:he,disablePurgeDocuments:ge,backendSearchQueries:G,onBackendSearch:K,serverSort:ve,onServerSortChange:ye,onRemoveBackendQuery:q,scope:be,onScopeChange:xe,canSaveChanges:!Ae&&Se,isSavingChanges:J,onSaveChanges:Y,linkTree:Ee},v??`documents`)]})]})]})}var F=[{id:`todos`,label:`Todo list`},{id:`todo-app`,label:`Todo App`},{id:`notes`,label:`Notes list`},{id:`notes-app`,label:`Notes App`},{id:`calendar`,label:`Calendar`},{id:`sketch`,label:`Sketch`},{id:`terminal`,label:`Terminal`}];function I(e){return e?.kind===`app`&&e.app===`notes`?`data/schema/note`:void 0}var L={id:`default`,name:`All`,kind:`documents`};function R(){return[{id:`emails`,label:`Emails`,schemas:[`data/schema/message`]},{id:`todos`,label:`Todos`,schemas:[`data/schema/task`]},{id:`notes`,label:`Notes`,schemas:[`data/schema/note`]},{id:`links`,label:`Links`,schemas:[`data/schema/tab`,`data/schema/link`]},{id:`files`,label:`Files`,schemas:[`data/schema/file`]}]}function z(e){let t=e?.views;if(!Array.isArray(t))return[L];let n=t.filter(e=>{let t=e;return!t||typeof t.id!=`string`||typeof t.name!=`string`?!1:t.kind===`documents`||t.kind===`columns`||t.kind===`app`&&(F.some(e=>e.id===t.app)||t.app===`filters`||t.app===`lens`)});return n.length>0?n:[L]}var B={todos:y,"todo-app":y,notes:C,"notes-app":C,calendar:s,filters:v,sketch:g,terminal:b,lens:f};function V({views:e,activeId:t,onSelect:n,onSave:r,readOnly:i=!1,className:o,accentColor:s,onOpenToSide:l}){let[d,f]=(0,M.useState)(null),[p,h]=(0,M.useState)(``),[g,_]=(0,M.useState)(!1),[v,y]=(0,M.useState)(null),[b,x]=(0,M.useState)(null),S=(0,M.useRef)(null);(0,M.useEffect)(()=>{let e=S.current;if(!e)return;let t=t=>{if(t.ctrlKey||e.scrollWidth<=e.clientWidth)return;let n=Math.abs(t.deltaX)>Math.abs(t.deltaY)?t.deltaX:t.deltaY,r=t.deltaMode===1?16:t.deltaMode===2?e.clientWidth:1;t.preventDefault(),e.scrollLeft+=n*r};return e.addEventListener(`wheel`,t,{passive:!1}),()=>e.removeEventListener(`wheel`,t)},[]),(0,M.useEffect)(()=>{S.current?.querySelector(`[aria-pressed="true"], input`)?.scrollIntoView({block:`nearest`,inline:`nearest`})},[t,d]);let C=()=>{y(null),x(null)},E=()=>{if(v&&b&&v!==b.id){let t=e.find(e=>e.id===v),n=e.filter(e=>e.id!==v),i=n.findIndex(e=>e.id===b.id);t&&i>=0&&(n.splice(b.before?i:i+1,0,t),n.some((t,n)=>t.id!==e[n].id)&&r(n))}C()},D=()=>{if(!d)return;let t=p.trim();t&&r(e.map(e=>e.id===d?{...e,name:t}:e)),f(null)},O=(t,n)=>{_(!1);let i=`view-${Date.now().toString(36)}`,a=t===`columns`?`Board`:t===`app`?F.find(e=>e.id===n)?.label??`App`:`List`,o=t===`columns`?{id:i,name:a,kind:t,columns:R()}:t===`app`?{id:i,name:a,kind:t,app:n}:{id:i,name:a,kind:t};r([...e,o],i),f(i),h(a)},k=n=>{let i=e.filter(e=>e.id!==n);r(i.length>0?i:[L],n===t?i[0]?.id??L.id:void 0)};return(0,N.jsxs)(`div`,{className:T(`relative flex h-full min-w-0 items-end`,o),children:[(0,N.jsx)(`div`,{ref:S,className:`flex min-w-0 items-end gap-0.5 overflow-x-auto overscroll-x-contain pt-1 [scrollbar-width:none]`,children:e.map(r=>{let o=r.id===t,u=r.kind===`columns`?a:r.kind===`app`&&r.app?B[r.app]:w;return d===r.id?(0,N.jsx)(`input`,{autoFocus:!0,"aria-label":`Tab name`,value:p,onChange:e=>h(e.target.value),onBlur:D,onKeyDown:e=>{e.key===`Enter`&&D(),e.key===`Escape`&&f(null)},className:T(`relative h-[2.3rem] w-28 shrink-0 rounded-t-[.5rem] border-0 px-3 pb-1 text-xs outline-none ring-0`,o?T(`z-[2] bg-background font-medium`,s?A(s):`text-foreground`):`bg-muted text-muted-foreground`),style:{backgroundColor:o?s:void 0}},r.id):(0,N.jsxs)(`button`,{type:`button`,"aria-pressed":o,onClick:()=>n(r.id),onDoubleClick:()=>{i||(f(r.id),h(r.name))},title:i?r.name:`${r.name}: double-click to rename, drag to reorder`,draggable:!i,onDragStart:e=>{e.dataTransfer.setData(`text/plain`,r.name),e.dataTransfer.effectAllowed=`move`,y(r.id)},onDragOver:e=>{if(!v||v===r.id)return;e.preventDefault(),e.dataTransfer.dropEffect=`move`;let t=e.currentTarget.getBoundingClientRect(),n=e.clientX<t.left+t.width/2;x(e=>e?.id===r.id&&e.before===n?e:{id:r.id,before:n})},onDrop:e=>{e.preventDefault(),E()},onDragEnd:C,className:T(`group relative flex h-[2.3rem] shrink-0 items-center gap-1.5 rounded-t-[.5rem] border-0 px-3 pb-1 text-xs transition-colors`,o?T(`z-[2] bg-background font-medium`,s?A(s):`text-foreground`):`bg-muted text-muted-foreground hover:bg-accent hover:text-foreground`,v===r.id&&`opacity-50`),style:{backgroundColor:o?s:void 0,boxShadow:b?.id===r.id?`inset ${b.before?`2px`:`-2px`} 0 0 var(--primary)`:void 0},children:[(0,N.jsx)(u,{className:`h-3 w-3 shrink-0`}),(0,N.jsx)(`span`,{className:`max-w-32 truncate`,children:r.name}),l&&(0,N.jsx)(m,{className:`h-3 w-3 shrink-0 opacity-0 transition-opacity hover:opacity-100 group-hover:opacity-60`,"aria-label":`Open to the side`,onClick:e=>{e.stopPropagation(),l(r.id)}}),!i&&e.length>1&&(0,N.jsx)(c,{className:T(`h-3 w-3 shrink-0 transition-opacity hover:text-destructive`,o?`opacity-60 hover:opacity-100`:`opacity-0 group-hover:opacity-100`),onClick:e=>{e.stopPropagation(),k(r.id)}})]},r.id)})}),!i&&(g?(0,N.jsxs)(`span`,{className:`absolute left-0 top-full z-30 flex w-full min-w-64 flex-wrap items-center gap-2 rounded-b-xl border bg-card p-2 shadow-lg`,children:[(0,N.jsxs)(`button`,{type:`button`,onClick:()=>O(`documents`),className:`flex h-10 items-center gap-1.5 rounded-md border px-2 text-xs text-muted-foreground hover:bg-accent/50 hover:text-foreground`,children:[(0,N.jsx)(w,{className:`h-3 w-3`}),` List`]}),(0,N.jsxs)(`button`,{type:`button`,onClick:()=>O(`columns`),className:`flex h-10 items-center gap-1.5 rounded-md border px-2 text-xs text-muted-foreground hover:bg-accent/50 hover:text-foreground`,children:[(0,N.jsx)(a,{className:`h-3 w-3`}),` Board`]}),F.map(e=>{let t=B[e.id];return(0,N.jsxs)(`button`,{type:`button`,onClick:()=>O(`app`,e.id),className:`flex h-10 items-center gap-1.5 rounded-md border px-2 text-xs text-muted-foreground hover:bg-accent/50 hover:text-foreground`,children:[(0,N.jsx)(t,{className:`h-3 w-3`}),` `,e.label]},e.id)}),(0,N.jsx)(`button`,{type:`button`,onClick:()=>_(!1),className:`p-1 text-muted-foreground hover:text-foreground`,"aria-label":`Cancel`,children:(0,N.jsx)(c,{className:`h-3 w-3`})})]}):(0,N.jsx)(`button`,{type:`button`,onClick:()=>_(!0),title:`Add view`,"aria-label":`Add view`,className:`relative ml-1 flex h-[2.3rem] w-10 shrink-0 items-center justify-center rounded-md pb-1 text-muted-foreground hover:bg-accent/50 hover:text-foreground`,children:(0,N.jsx)(u,{className:`h-3.5 w-3.5`})}))]})}var H=[{id:`emails`,label:`Emails`,schemas:[`data/schema/message`]},{id:`todos`,label:`Todos`,schemas:[`data/schema/task`]},{id:`notes`,label:`Notes`,schemas:[`data/schema/note`]},{id:`links`,label:`Links`,schemas:[`data/schema/tab`,`data/schema/link`]},{id:`files`,label:`Files`,schemas:[`data/schema/file`]}];function U(e,t){return t.some(t=>e.schema===t||e.schema.startsWith(`${t}/`))}function W({documents:e,workspaceId:t,columns:n,onColumnsChange:r,readOnly:i=!1}){let[a,o]=(0,M.useState)(null),[s,l]=(0,M.useState)(!1),[d,f]=(0,M.useState)({}),[m,h]=(0,M.useState)({}),g=(0,M.useRef)(null),[_,v]=(0,M.useState)(!1),y=(0,M.useCallback)(()=>{let e=g.current;e&&v(e.scrollWidth-e.clientWidth-e.scrollLeft>8)},[]);(0,M.useEffect)(()=>{let e=g.current;if(!e)return;let t=new ResizeObserver(()=>y());return t.observe(e),()=>t.disconnect()},[y]);let b=(e,t)=>{e.preventDefault();let i=e.currentTarget.parentElement;if(!i)return;let a=e.clientX,o=i.getBoundingClientRect().width,s=o,c=e=>{s=Math.min(900,Math.max(220,o+e.clientX-a)),h(e=>({...e,[t]:s}))},l=()=>{window.removeEventListener(`pointermove`,c),window.removeEventListener(`pointerup`,l),r(n.map(e=>e.id===t?{...e,width:Math.round(s)}:e))};window.addEventListener(`pointermove`,c),window.addEventListener(`pointerup`,l)},x=e=>{h(t=>{let n={...t};return delete n[e],n}),r(n.map(t=>t.id===e?{...t,width:void 0}:t))},S=e=>{let t=d[e];if(t===void 0)return;let i=n.find(t=>t.id===e);i&&(i.filter||``)!==t&&r(n.map(n=>n.id===e?{...n,filter:t||void 0}:n))},C=H.filter(e=>!n.some(t=>t.id===e.id));return(0,N.jsxs)(`div`,{className:`relative h-full`,children:[(0,N.jsx)(`div`,{ref:g,onScroll:y,className:`flex h-full snap-x snap-mandatory gap-3 overflow-x-auto overscroll-x-contain p-2`,"data-testid":`schema-columns-board`,children:n.map(t=>{let a=(d[t.id]??t.filter??``).toLowerCase(),s=e.filter(e=>U(e,t.schemas)).filter(e=>{if(!a)return!0;let t=E(e);return`${t.title}\n${t.preview}\n${t.subtitle}`.toLowerCase().includes(a)}),l=m[t.id]??t.width;return(0,N.jsxs)(`div`,{className:`relative flex h-full min-h-0 min-w-0 shrink-0 grow-0 basis-full snap-start flex-col rounded-(--card-radius) border bg-muted/20 ${l?`sm:basis-[var(--col-w)]`:`sm:basis-[48%] lg:basis-[32%] xl:basis-[24%]`}`,style:l?{"--col-w":`${l}px`}:void 0,children:[!i&&(0,N.jsx)(`div`,{onPointerDown:e=>b(e,t.id),onDoubleClick:()=>x(t.id),title:`Drag to resize; double-click to reset`,className:`absolute right-0 inset-y-0 z-10 w-2 cursor-col-resize touch-none rounded-r-lg transition-colors hover:bg-primary/25 active:bg-primary/40 max-sm:hidden`}),(0,N.jsxs)(`div`,{className:`flex items-center gap-2 px-3 pb-1 pt-2.5 max-sm:pr-10`,children:[(0,N.jsx)(`span`,{className:`truncate text-sm font-medium`,children:t.label}),(0,N.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:s.length}),(0,N.jsx)(`span`,{className:`flex-1`}),!i&&(0,N.jsx)(`button`,{type:`button`,onClick:()=>r(n.filter(e=>e.id!==t.id)),title:`Remove column`,className:`rounded-sm p-0.5 text-muted-foreground hover:text-destructive`,children:(0,N.jsx)(c,{className:`h-3.5 w-3.5`})})]}),(0,N.jsx)(`div`,{className:`px-3 pb-2`,children:(0,N.jsx)(`input`,{value:d[t.id]??t.filter??``,onChange:e=>f(n=>({...n,[t.id]:e.target.value})),onBlur:()=>S(t.id),onKeyDown:e=>{e.key===`Enter`&&S(t.id)},placeholder:`Filter…`,readOnly:i,className:`h-7 w-full rounded-md border border-input bg-background px-2 text-xs placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring`})}),(0,N.jsxs)(`div`,{className:`flex-1 space-y-1.5 overflow-y-auto px-2 pb-2`,children:[s.map(e=>{let t=E(e);return(0,N.jsxs)(`button`,{type:`button`,onClick:()=>o(e),className:`w-full min-w-0 rounded-md border bg-card px-2.5 py-2 text-left transition-colors hover:bg-accent/50`,children:[(0,N.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,N.jsx)(de,{document:e,size:3.5}),(0,N.jsx)(`span`,{className:`truncate text-xs font-medium`,title:t.title,children:t.title})]}),t.preview&&(0,N.jsx)(`p`,{className:`mt-1 line-clamp-2 break-words text-[11px] leading-snug text-muted-foreground`,children:t.preview}),(0,N.jsx)(`p`,{className:`mt-1 text-[10px] text-muted-foreground/70`,children:new Date(e.updatedAt||e.createdAt).toLocaleDateString()})]},e.id)}),s.length===0&&(0,N.jsx)(`p`,{className:`px-2 py-3 text-center text-xs text-muted-foreground/60`,children:`Empty`})]})]},t.id)})}),(!i&&C.length>0||_)&&(0,N.jsxs)(`div`,{className:`pointer-events-none absolute inset-y-0 right-0 z-20 flex w-7 flex-col items-end bg-gradient-to-l from-background via-background/60 to-transparent py-2`,children:[!i&&C.length>0&&(0,N.jsxs)(`div`,{className:`pointer-events-auto relative`,children:[(0,N.jsx)(`button`,{type:`button`,onClick:()=>l(e=>!e),title:`Add column`,"aria-label":`Add column`,className:`flex h-7 w-6 items-center justify-center rounded-l-md border border-r-0 bg-background text-muted-foreground shadow-elevation-1 hover:bg-accent hover:text-foreground`,children:(0,N.jsx)(u,{className:`h-3.5 w-3.5`})}),s&&(0,N.jsxs)(`div`,{className:`absolute right-0 top-8 w-44 rounded-lg border bg-background p-2 shadow-elevation-2`,children:[(0,N.jsx)(`p`,{className:`px-2 pb-1 text-[10px] uppercase tracking-wide text-muted-foreground`,children:`Add column`}),C.map(e=>(0,N.jsx)(`button`,{type:`button`,onClick:()=>{l(!1),r([...n,{...e}])},className:`w-full rounded-md px-2 py-1.5 text-left text-xs text-muted-foreground hover:bg-accent/50 hover:text-foreground`,children:e.label},e.id)),(0,N.jsx)(`button`,{type:`button`,onClick:()=>l(!1),className:`mt-1 w-full rounded-md px-2 py-1.5 text-left text-xs text-muted-foreground/60 hover:bg-accent/50`,children:`Cancel`})]})]}),_&&(0,N.jsx)(p,{className:`my-auto h-4 w-4 self-center text-muted-foreground/70`,"aria-label":`More columns`})]}),(0,N.jsx)(ae,{document:a,isOpen:a!==null,onClose:()=>o(null),workspaceId:t})]})}function G(e,t,n,r,i){let a=`${e}\0${t}\0${n}\0${r}\0${i??``}`,[o,s]=(0,M.useState)(0),[c,l]=(0,M.useState)(null);(0,M.useEffect)(()=>{let o=!1;return k(e,n,t,{limit:200,allOf:[r],...i?{sortBy:i,order:`asc`}:{}}).then(e=>{o||l({key:a,docs:e.payload||[]})}).catch(()=>{o||l({key:a,docs:[]})}),()=>{o=!0}},[a,o]);let u=c?.key===a?c.docs:[],d=c?.key!==a;return(0,M.useEffect)(()=>{let e=()=>s(e=>e+1);return window.addEventListener(`workspace:documents:refresh`,e),()=>window.removeEventListener(`workspace:documents:refresh`,e)},[]),{docs:u,isLoading:d,refresh:(0,M.useCallback)(()=>s(e=>e+1),[])}}function K({workspaceId:e,treeName:t,path:n}){let{docs:r,isLoading:i,refresh:a}=G(e,t,n,O,`tasks`),[o,s]=(0,M.useState)(!1),c=o?r.filter(e=>e.data?.status!==`completed`):r,l=r.filter(e=>{let t=e.data?.status;return t!==`completed`&&t!==`cancelled`}).length;return(0,N.jsxs)(`div`,{className:`mx-auto flex h-full w-full max-w-3xl flex-col p-4`,children:[(0,N.jsxs)(`div`,{className:`mb-2 flex shrink-0 items-center justify-between gap-2`,children:[(0,N.jsxs)(`span`,{className:`text-xs text-muted-foreground`,children:[l,` open`]}),(0,N.jsxs)(`label`,{className:`flex cursor-pointer items-center gap-1.5 text-xs text-muted-foreground`,children:[(0,N.jsx)(`input`,{type:`checkbox`,checked:o,onChange:e=>s(e.target.checked)}),`hide done`]})]}),(0,N.jsx)(`div`,{className:`min-h-0 flex-1 space-y-1 overflow-y-auto`,children:i?(0,N.jsx)(`p`,{className:`py-4 text-sm text-muted-foreground`,children:`Loading…`}):c.length===0?(0,N.jsx)(`p`,{className:`py-4 text-sm text-muted-foreground`,children:`No todos here.`}):c.map(t=>(0,N.jsx)(ee,{doc:t,workspaceId:e,readOnly:!1,onChanged:a},t.id))})]})}function q({app:e,contextId:t,...n}){let r=t&&e!==`lens`?{mode:`context`,contextId:t}:{mode:`workspace`,workspaceName:n.workspaceId,treeName:n.treeName,path:n.path,treeType:D(n.treeName)},i=e===`todo-app`?`todo`:e===`notes-app`?`notes`:e,a=j.find(e=>e.id===i);return(0,N.jsx)(me,{target:r,children:e===`todos`?(0,N.jsx)(K,{...n}):a?(0,N.jsx)(a.Component,{}):null})}export{I as a,ge as c,L as i,he as l,W as n,z as o,V as r,P as s,q as t};