@objectstack/console 5.0.0

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.
@@ -0,0 +1 @@
1
+ import{i as e}from"./rolldown-runtime-aKtaBQYM.js";import{$ as t,A as n,At as r,B as i,Bs as a,Cs as o,Ct as s,Dt as c,Et as l,Fs as u,It as d,Pt as f,Rt as p,Tt as m,Vs as h,Z as g,_c as _,_t as v,bc as y,dc as b,et as x,fc as S,gs as C,hs as w,ht as T,jt as E,k as D,kt as O,mt as k,ot as A,q as j,tt as M,uc as ee,vt as te,xo as N}from"./app-shell-CaJU0zqc.js";var P=e(y(),1),F=h(),I=`bg-blue-100 text-blue-900 border border-blue-200`,ne=new Date,L=[`bg-blue-100 text-blue-900 border border-blue-200`,`bg-emerald-100 text-emerald-900 border border-emerald-200`,`bg-amber-100 text-amber-900 border border-amber-200`,`bg-rose-100 text-rose-900 border border-rose-200`,`bg-violet-100 text-violet-900 border border-violet-200`,`bg-cyan-100 text-cyan-900 border border-cyan-200`,`bg-orange-100 text-orange-900 border border-orange-200`,`bg-fuchsia-100 text-fuchsia-900 border border-fuchsia-200`],R=/^#([0-9a-f]{3}|[0-9a-f]{6}|[0-9a-f]{8})$/i,z=/(^|\s)(bg|text|from|to|via)-/;function B(e){if(!e)return{className:I};if(R.test(e))return{className:`text-white`,inlineColor:e};if(z.test(e))return{className:e};let t=0;for(let n=0;n<e.length;n++)t=(t<<5)-t+e.charCodeAt(n)|0;return{className:L[Math.abs(t)%L.length]}}var V={"calendar.today":`Today`,"calendar.month":`Month`,"calendar.week":`Week`,"calendar.day":`Day`,"calendar.newEvent":`New event`,"calendar.moreEvents":`+{{count}} more`,"calendar.allDay":`all-day`};function H(){try{let e=_();return e.t(`calendar.today`)===`calendar.today`?{t:(e,t)=>{let n=V[e]||e;if(t)for(let[e,r]of Object.entries(t))n=n.replace(`{{${e}}}`,String(r));return n},language:`en`}:{t:e.t,language:e.language}}catch{return{t:(e,t)=>{let n=V[e]||e;if(t)for(let[e,r]of Object.entries(t))n=n.replace(`{{${e}}}`,String(r));return n},language:`en`}}}function re({events:e=[],view:n=`month`,currentDate:i=ne,locale:a=`default`,onEventClick:c,onDateClick:u,onViewChange:d,onNavigate:h,onAddClick:g,onEventDrop:_,onTimeRangeSelect:v,slotMinutes:y=30,className:b}){let[x,S]=P.useState(n),[E,D]=P.useState(i),{t:O,language:A}=H(),j=a===`default`?A:a;P.useEffect(()=>{D(i)},[i]),P.useEffect(()=>{S(n)},[n]);let ee=P.useRef(d);ee.current=d,P.useEffect(()=>{let e=window.matchMedia(`(max-width: 639px)`),t=e=>{e.matches&&(S(`day`),ee.current?.(`day`))};return t(e),e.addEventListener(`change`,t),()=>e.removeEventListener(`change`,t)},[]);let I=()=>{let e=new Date(E);x===`month`?e.setMonth(e.getMonth()-1):x===`week`?e.setDate(e.getDate()-7):e.setDate(e.getDate()-1),D(e),h?.(e)},L=()=>{let e=new Date(E);x===`month`?e.setMonth(e.getMonth()+1):x===`week`?e.setDate(e.getDate()+7):e.setDate(e.getDate()+1),D(e),h?.(e)},R=()=>{let e=new Date;D(e),h?.(e)},z=e=>{S(e),d?.(e)},B=()=>{if(x===`month`)return E.toLocaleDateString(j,{month:`long`,year:`numeric`});if(x===`week`){let e=U(E),t=new Date(e);return t.setDate(t.getDate()+6),`${e.toLocaleDateString(j,{month:`short`,day:`numeric`})} - ${t.toLocaleDateString(j,{month:`short`,day:`numeric`,year:`numeric`})}`}else return E.toLocaleDateString(j,{weekday:`long`,month:`long`,day:`numeric`,year:`numeric`})},V=P.useRef(0);return(0,F.jsxs)(`div`,{role:`region`,"aria-label":`Calendar`,className:t(`flex flex-col h-full bg-background min-w-0 overflow-hidden`,b),children:[(0,F.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-2 p-2 sm:p-4 border-b min-w-0`,children:[(0,F.jsxs)(`div`,{className:`flex items-center gap-4`,children:[(0,F.jsxs)(`div`,{className:`flex items-center bg-muted/50 rounded-lg p-1 gap-1`,children:[(0,F.jsx)(r,{variant:`ghost`,size:`sm`,onClick:R,className:`h-8`,"aria-label":`Go to today`,children:O(`calendar.today`)}),(0,F.jsx)(`div`,{className:`h-4 w-px bg-border mx-1`}),(0,F.jsx)(r,{variant:`ghost`,size:`icon`,"aria-label":`Previous period`,onClick:I,className:`h-8 w-8`,children:(0,F.jsx)(C,{className:`h-4 w-4`})}),(0,F.jsx)(r,{variant:`ghost`,size:`icon`,"aria-label":`Next period`,onClick:L,className:`h-8 w-8`,children:(0,F.jsx)(w,{className:`h-4 w-4`})})]}),(0,F.jsxs)(M,{children:[(0,F.jsx)(te,{asChild:!0,children:(0,F.jsxs)(r,{variant:`ghost`,"aria-label":`Current date: ${B()}`,className:t(`text-base sm:text-xl font-semibold h-auto px-2 sm:px-3 py-1 hover:bg-muted/50 transition-colors`,`flex items-center gap-2`),children:[(0,F.jsx)(o,{className:`h-5 w-5 text-muted-foreground`}),(0,F.jsx)(`span`,{children:B()})]})}),(0,F.jsx)(T,{className:`w-auto p-0`,align:`start`,children:(0,F.jsx)(p,{mode:`single`,selected:E,onSelect:e=>{e&&(D(e),h?.(e))},initialFocus:!0,fromYear:2e3,toYear:2050})})]})]}),(0,F.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,F.jsxs)(s,{value:x,onValueChange:z,children:[(0,F.jsx)(m,{className:`w-32 bg-background`,children:(0,F.jsx)(f,{})}),(0,F.jsxs)(l,{children:[(0,F.jsx)(k,{value:`day`,children:O(`calendar.day`)}),(0,F.jsx)(k,{value:`week`,children:O(`calendar.week`)}),(0,F.jsx)(k,{value:`month`,children:O(`calendar.month`)})]})]}),g&&(0,F.jsxs)(r,{onClick:g,size:`sm`,className:`gap-1`,children:[(0,F.jsx)(N,{className:`h-4 w-4`}),O(`calendar.newEvent`)]})]})]}),(0,F.jsxs)(`div`,{className:`flex-1 overflow-auto`,onTouchStart:e=>{V.current=e.touches[0].clientX},onTouchEnd:e=>{let t=V.current-e.changedTouches[0].clientX;if(Math.abs(t)>50){let e=new Date(E);x===`day`?e.setDate(e.getDate()+(t>0?1:-1)):x===`week`?e.setDate(e.getDate()+(t>0?7:-7)):e.setMonth(e.getMonth()+(t>0?1:-1)),D(e),h?.(e)}},children:[x===`month`&&(0,F.jsx)(G,{date:E,events:e,locale:j,onEventClick:c,onDateClick:u,onEventDrop:_}),x===`week`&&(0,F.jsx)(ae,{mode:`week`,date:E,events:e,locale:j,slotMinutes:y,onEventClick:c,onEventDrop:_,onTimeRangeSelect:v}),x===`day`&&(0,F.jsx)(ae,{mode:`day`,date:E,events:e,locale:j,slotMinutes:y,onEventClick:c,onEventDrop:_,onTimeRangeSelect:v})]})]})}function U(e){let t=new Date(e),n=t.getDay(),r=t.getDate()-n;return t.setDate(r),t}function ie(e){let t=e.getFullYear(),n=e.getMonth(),r=new Date(t,n,1),i=new Date(t,n+1,0),a=r.getDay(),o=[];for(let e=a-1;e>=0;e--){let t=new Date(r.getTime());t.setDate(t.getDate()-(e+1)),o.push(t)}for(let e=1;e<=i.getDate();e++)o.push(new Date(t,n,e));let s=42-o.length;for(let e=1;e<=s;e++){let t=new Date(i.getTime());t.setDate(t.getDate()+e),o.push(t)}return o}function W(e,t){return e.getFullYear()===t.getFullYear()&&e.getMonth()===t.getMonth()&&e.getDate()===t.getDate()}function G({date:e,events:n,locale:r=`default`,onEventClick:i,onDateClick:a,onEventDrop:o}){let s=P.useMemo(()=>ie(e),[e.getFullYear(),e.getMonth()]),c=P.useMemo(()=>new Date,[]),{t:l}=H(),u=P.useMemo(()=>{let e=new Date(2024,0,7);return Array.from({length:7},(t,n)=>{let i=new Date(e);return i.setDate(i.getDate()+n),i.toLocaleDateString(r,{weekday:`short`})})},[r]),[d,f]=P.useState(null),[p,m]=P.useState(null),h=P.useMemo(()=>{let e=new Map;for(let t of n){let n=new Date(t.start),r=t.end?new Date(t.end):new Date(n);n.setHours(0,0,0,0),r.setHours(0,0,0,0);let i=new Date(n);for(;i<=r;){let a=`${i.getFullYear()}-${i.getMonth()}-${i.getDate()}`,o=i.getTime()===n.getTime(),s=i.getTime()===r.getTime(),c=o||s||i.getDay()===0,l=e.get(a),u={event:t,isTitleDay:c,isSpanStart:o,isSpanEnd:s};l?l.push(u):e.set(a,[u]),i.setDate(i.getDate()+1)}}return e},[n]),g=(e,t,n=`move`,r)=>{f(t.id),e.dataTransfer.effectAllowed=`move`;let i={id:t.id,mode:n,...r?{sourceDay:`${r.getFullYear()}-${r.getMonth()}-${r.getDate()}`}:{}};e.dataTransfer.setData(`text/plain`,JSON.stringify(i)),n===`resize-end`&&e.stopPropagation()},_=()=>{f(null),m(null)},v=(e,t)=>{e.preventDefault(),e.dataTransfer.dropEffect=`move`,m(t)},y=e=>{e.currentTarget.contains(e.relatedTarget)||m(null)},b=(e,t)=>{if(e.preventDefault(),m(null),f(null),!o)return;let r=e.dataTransfer.getData(`text/plain`),i;try{i=JSON.parse(r)}catch{i={id:r,mode:`move`}}let a=n.find(e=>String(e.id)===String(i.id));if(!a)return;let s=new Date(t);if(s.setHours(0,0,0,0),i.mode===`resize-end`){let e=a.end?new Date(a.end):new Date(a.start),t=new Date(e);if(t.setHours(0,0,0,0),s.getTime()===t.getTime())return;let n=new Date(a.start);if(n.setHours(0,0,0,0),s.getTime()<n.getTime())return;let r=new Date(s);r.setHours(e.getHours(),e.getMinutes(),e.getSeconds(),0),o(a,new Date(a.start),r);return}let c=new Date(a.start),l;if(i.sourceDay){let[e,t,n]=i.sourceDay.split(`-`).map(e=>parseInt(e,10));l=new Date(e,t,n)}else l=new Date(c);l.setHours(0,0,0,0);let u=s.getTime()-l.getTime();if(u===0)return;let d=new Date(c.getTime()+u),p;a.end&&(p=new Date(new Date(a.end).getTime()+u)),o(a,d,p)};return(0,F.jsxs)(`div`,{className:`flex flex-col h-full`,children:[(0,F.jsx)(`div`,{role:`row`,className:`grid grid-cols-7 border-b`,children:u.map(e=>(0,F.jsx)(`div`,{role:`columnheader`,className:`p-2 text-center text-sm font-medium text-muted-foreground border-r last:border-r-0`,children:e},e))}),(0,F.jsx)(`div`,{role:`grid`,"aria-label":`Calendar grid`,className:`grid grid-cols-7 flex-1 auto-rows-fr`,children:s.map((n,r)=>{let s=`${n.getFullYear()}-${n.getMonth()}-${n.getDate()}`,u=h.get(s)||[],f=n.getMonth()===e.getMonth(),m=W(n,c);return(0,F.jsxs)(`div`,{role:`gridcell`,"aria-label":`${n.toLocaleDateString(`default`,{weekday:`long`,month:`long`,day:`numeric`,year:`numeric`})}${u.length>0?`, ${u.length} event${u.length>1?`s`:``}`:``}`,className:t(`border-b border-r last:border-r-0 p-2 min-h-[100px] cursor-pointer hover:bg-accent/50`,!f&&`bg-muted/50 text-muted-foreground opacity-50`,p===r&&`ring-2 ring-primary`),onClick:()=>a?.(n),onDragOver:e=>v(e,r),onDragLeave:y,onDrop:e=>b(e,n),children:[(0,F.jsx)(`div`,{className:t(`text-sm font-medium mb-2`,m&&`inline-flex items-center justify-center rounded-full bg-primary text-primary-foreground h-6 w-6`),...m?{"aria-current":`date`}:{},children:n.getDate()}),(0,F.jsxs)(`div`,{className:`space-y-0.5`,children:[u.slice(0,4).map(({event:e,isTitleDay:r,isSpanStart:a,isSpanEnd:s},c)=>{let l=!r,{className:u,inlineColor:f}=B(e.color),p=!!o&&s;return(0,F.jsxs)(`div`,{role:`button`,title:e.title,"aria-label":e.title,draggable:!!o,onDragStart:t=>g(t,e,`move`,n),onDragEnd:_,className:t(`relative text-xs hover:opacity-80 truncate`,o?`cursor-move`:`cursor-pointer`,l?`h-1.5`:`px-2 py-0.5`,a?`rounded-l`:`rounded-l-none`,s?`rounded-r`:`rounded-r-none`,!s&&`-mr-2`,u,d===e.id&&`opacity-50`),style:f?{backgroundColor:f}:void 0,onClick:t=>{t.stopPropagation(),i?.(e)},children:[l?``:e.title,p&&(0,F.jsx)(`span`,{role:`separator`,"aria-label":`Resize event end`,title:`Drag to change end date`,draggable:!0,onDragStart:t=>g(t,e,`resize-end`,n),onDragEnd:_,onClick:e=>e.stopPropagation(),className:`absolute inset-y-0 right-0 w-2 cursor-ew-resize bg-black/25 hover:bg-black/50 rounded-r`})]},`${e.id}-${c}`)}),u.length>4&&(0,F.jsx)(`div`,{className:`text-xs text-muted-foreground px-2`,children:l(`calendar.moreEvents`,{count:u.length-4})})]})]},r)})})]})}var K=48;function q(e){let t=new Date(e);return t.setHours(0,0,0,0),t}function J(e){return e.getHours()*60+e.getMinutes()}function Y(e){return`${e.getFullYear()}-${e.getMonth()}-${e.getDate()}`}function ae({mode:e,date:n,events:r,locale:i=`default`,slotMinutes:a=30,onEventClick:o,onEventDrop:s,onTimeRangeSelect:c}){let{t:l}=H(),u=K*a/60,d=K*24,f=P.useMemo(()=>{if(e===`day`)return[q(n)];let t=U(n);return Array.from({length:7},(e,n)=>{let r=new Date(t);return r.setDate(t.getDate()+n),q(r)})},[e,n.getFullYear(),n.getMonth(),n.getDate()]),p=P.useMemo(()=>new Date,[]),m=P.useCallback(e=>{if(e.allDay)return!0;let t=new Date(e.start),n=e.end?new Date(e.end):new Date(t),r=t.getHours()===0&&t.getMinutes()===0&&t.getSeconds()===0,i=n.getHours()===0&&n.getMinutes()===0&&n.getSeconds()===0,a=n.getTime()-t.getTime();return!!(r&&i||a>=1440*60*1e3)},[]),{allDayEvents:h,timedEvents:g}=P.useMemo(()=>{let e=[],t=[];for(let n of r)m(n)?e.push(n):t.push(n);return{allDayEvents:e,timedEvents:t}},[r,m]),_=P.useMemo(()=>{let e=new Map;for(let t of f)e.set(Y(t),[]);for(let t of h){let n=q(new Date(t.start)),r=t.end?new Date(t.end):new Date(t.start),i=q(r);r.getHours()===0&&r.getMinutes()===0&&r.getSeconds()===0&&r.getTime()>n.getTime()&&(i=new Date(i),i.setDate(i.getDate()-1));for(let r of f){let a=q(r);a<n||a>i||e.get(Y(r)).push({event:t,isStart:a.getTime()===n.getTime(),isEnd:a.getTime()===i.getTime()})}}return e},[f,h]),v=P.useMemo(()=>{let e=new Map;for(let t of f)e.set(Y(t),[]);for(let t of g){let n=new Date(t.start),r=t.end?new Date(t.end):new Date(n.getTime()+3600*1e3);for(let i of f){let a=q(i),o=new Date(a);if(o.setDate(o.getDate()+1),r<=a||n>=o)continue;let s=n<a?a:n,c=r>o?o:r,l=J(s),u=c.getTime()===o.getTime()?1440:J(c);e.get(Y(i)).push({event:t,startMin:l,endMin:Math.max(u,l+15),isStart:s.getTime()===n.getTime(),isEnd:c.getTime()===r.getTime()})}}return e},[f,g]),y=P.useMemo(()=>{let e=new Map;for(let[t,n]of v){let r=[...n].sort((e,t)=>e.startMin-t.startMin||e.endMin-t.endMin),i=[],a=[],o=[];for(let e of r){let t=0;for(;i[t]&&i[t].endMin>e.startMin;)t++;i[t]={endMin:e.endMin},a.push({entry:e,col:t})}for(let e=0;e<a.length;e++){let t=a[e],n=t.col;for(let r=0;r<a.length;r++){if(r===e)continue;let i=a[r];i.entry.startMin<t.entry.endMin&&i.entry.endMin>t.entry.startMin&&i.col>n&&(n=i.col)}o.push({...t.entry,col:t.col,cols:n+1})}e.set(t,o)}return e},[v]),b=P.useRef(null),x=P.useRef([]),[S,C]=P.useState(null),w=P.useRef(null);w.current=S;let T=P.useRef(!1),E=P.useCallback((e,t)=>{let n=x.current[t];if(!n)return 0;let r=(e-n.getBoundingClientRect().top+n.scrollTop)/K*60,i=Math.round(r/a)*a;return Math.max(0,Math.min(1440,i))},[a]),D=P.useCallback(e=>{for(let t=0;t<x.current.length;t++){let n=x.current[t];if(!n)continue;let r=n.getBoundingClientRect();if(e>=r.left&&e<=r.right)return t}return-1},[]);P.useEffect(()=>{if(!S)return;let e=e=>{let t=S.kind===`select`||S.kind===`move`?D(e.clientX):S.dayIndex,n=t<0?S.dayIndex??0:t,r=E(e.clientY,n);C(e=>e&&(e.kind===`select`?{...e,dayIndex:n>=0?n:e.dayIndex,headMinutes:r}:e.kind===`move`?{...e,dayIndex:n,minutes:r}:{...e,minutes:r}))},t=e=>{let t=w.current;if(!t){C(null);return}try{if(t.kind===`select`&&c){let e=Math.min(t.anchorMinutes,t.headMinutes),n=Math.max(t.anchorMinutes,t.headMinutes),r=e,i=n===e?Math.min(1440,e+a):n,o=f[t.dayIndex]??f[0],s=new Date(o);s.setHours(0,Math.round(r),0,0);let l=new Date(o);l.setHours(0,Math.round(i),0,0),T.current=!0,c(s,l)}else if(t.kind===`move`&&s){let e=r.find(e=>String(e.id)===String(t.eventId));if(e){let n=t.dayIndex<0?0:t.dayIndex,r=t.minutes-t.grabMinuteOffset,i=Math.max(0,Math.min(1440-t.durationMin,Math.round(r/a)*a)),o=f[n]??f[0],c=new Date(o);c.setHours(0,i,0,0);let l=new Date(c.getTime()+t.durationMin*60*1e3);T.current=!0,s(e,c,l)}}else if(t.kind===`resize-top`&&s){let e=r.find(e=>String(e.id)===String(t.eventId));if(e){let n=f[t.dayIndex]??f[0],r=Math.min(t.anchorEndMin-a,Math.max(0,t.minutes)),i=new Date(n);i.setHours(0,r,0,0);let o=new Date(n);o.setHours(0,t.anchorEndMin,0,0),T.current=!0,s(e,i,o)}}else if(t.kind===`resize-bottom`&&s){let e=r.find(e=>String(e.id)===String(t.eventId));if(e){let n=f[t.dayIndex]??f[0],r=Math.max(t.anchorStartMin+a,Math.min(1440,t.minutes)),i=new Date(n);i.setHours(0,t.anchorStartMin,0,0);let o=new Date(n);o.setHours(0,r,0,0),T.current=!0,s(e,i,o)}}}finally{C(null),setTimeout(()=>{T.current=!1},50)}};return window.addEventListener(`pointermove`,e),window.addEventListener(`pointerup`,t),()=>{window.removeEventListener(`pointermove`,e),window.removeEventListener(`pointerup`,t)}},[S,f,r,a,s,c,D,E]);let O=P.useMemo(()=>f.map(e=>({weekday:e.toLocaleDateString(i,{weekday:`short`}),day:e.getDate(),month:e.toLocaleDateString(i,{month:`short`}),isToday:W(e,p)})),[f,i,p]),k=P.useMemo(()=>Array.from({length:24},(e,t)=>new Date(2024,0,1,t,0).toLocaleTimeString(i,{hour:`numeric`})),[i]),A=(e,t,n,r)=>{if(!s||e.button!==0)return;e.stopPropagation(),e.preventDefault();let i=E(e.clientY,n);C(r===`body`?{kind:`move`,eventId:t.event.id,grabMinuteOffset:Math.max(0,i-t.startMin),durationMin:t.endMin-t.startMin,dayIndex:n,minutes:i}:r===`top`?{kind:`resize-top`,eventId:t.event.id,anchorEndMin:t.endMin,dayIndex:n,minutes:i}:{kind:`resize-bottom`,eventId:t.event.id,anchorStartMin:t.startMin,dayIndex:n,minutes:i})},j=(e,t)=>{if(!c||e.button!==0)return;e.preventDefault();let n=E(e.clientY,t);C({kind:`select`,dayIndex:t,anchorMinutes:n,headMinutes:n})},M=e=>{if(!S)return null;if(S.kind===`select`&&S.dayIndex===e){let t=Math.min(S.anchorMinutes,S.headMinutes),n=Math.max(S.anchorMinutes,S.headMinutes);return(0,F.jsx)(`div`,{className:`absolute left-1 right-1 rounded bg-primary/30 border border-primary pointer-events-none z-10`,style:{top:t/60*K,height:Math.max(u,(n-t)/60*K)},"aria-hidden":!0,children:(0,F.jsx)(`div`,{className:`px-2 py-0.5 text-xs font-medium text-primary`,children:X(f[e],t,n,i)})})}if(S.kind===`move`&&S.dayIndex===e){let t=S.minutes-S.grabMinuteOffset,n=Math.max(0,Math.min(1440-S.durationMin,Math.round(t/a)*a));return(0,F.jsx)(`div`,{className:`absolute left-1 right-1 rounded border-2 border-dashed border-primary bg-primary/10 pointer-events-none z-10`,style:{top:n/60*K,height:S.durationMin/60*K},"aria-hidden":!0,children:(0,F.jsx)(`div`,{className:`px-2 py-0.5 text-xs font-medium text-primary`,children:X(f[e],n,n+S.durationMin,i)})})}if((S.kind===`resize-top`||S.kind===`resize-bottom`)&&S.dayIndex===e){let t,n;return S.kind===`resize-top`?(t=Math.min(S.anchorEndMin-a,Math.max(0,S.minutes)),n=S.anchorEndMin):(t=S.anchorStartMin,n=Math.max(S.anchorStartMin+a,Math.min(1440,S.minutes))),(0,F.jsx)(`div`,{className:`absolute left-1 right-1 rounded border-2 border-dashed border-primary bg-primary/10 pointer-events-none z-10`,style:{top:t/60*K,height:(n-t)/60*K},"aria-hidden":!0,children:(0,F.jsx)(`div`,{className:`px-2 py-0.5 text-xs font-medium text-primary`,children:X(f[e],t,n,i)})})}return null};return(0,F.jsxs)(`div`,{className:`flex flex-col h-full`,ref:b,children:[(0,F.jsxs)(`div`,{className:`flex border-b sticky top-0 bg-background z-20`,children:[(0,F.jsx)(`div`,{className:`w-14 shrink-0 border-r`,"aria-hidden":!0}),O.map((e,n)=>(0,F.jsxs)(`div`,{role:`columnheader`,className:t(`flex-1 p-2 text-center text-sm border-r last:border-r-0`,e.isToday&&`bg-primary/5`),children:[(0,F.jsx)(`div`,{className:`text-xs text-muted-foreground`,children:e.weekday}),(0,F.jsx)(`div`,{className:t(`font-medium`,e.isToday&&`inline-flex items-center justify-center rounded-full bg-primary text-primary-foreground h-6 w-6 mx-auto`),children:e.day})]},n))]}),h.length>0&&(0,F.jsxs)(`div`,{className:`flex border-b bg-muted/20 max-h-[140px] overflow-y-auto`,children:[(0,F.jsx)(`div`,{className:`w-14 shrink-0 border-r flex items-start justify-end pr-1 pt-1 text-[10px] text-muted-foreground sticky left-0 bg-muted/20`,children:l(`calendar.allDay`)===`calendar.allDay`?`all-day`:l(`calendar.allDay`)}),f.map(e=>{let n=Y(e);return(0,F.jsx)(`div`,{className:`flex-1 border-r last:border-r-0 min-h-[28px] p-0.5 space-y-0.5`,children:(_.get(n)??[]).map(({event:e,isStart:n,isEnd:r},i)=>{let{className:a,inlineColor:s}=B(e.color);return(0,F.jsx)(`div`,{role:`button`,title:e.title,onClick:t=>{t.stopPropagation(),o?.(e)},className:t(`text-[11px] px-2 py-0.5 truncate cursor-pointer hover:opacity-80`,n?`rounded-l`:`rounded-l-none -ml-0.5`,r?`rounded-r`:`rounded-r-none -mr-0.5`,a),style:s?{backgroundColor:s}:void 0,children:n?e.title:`\xA0`},`${e.id}-${i}`)})},n)})]}),(0,F.jsx)(`div`,{className:`flex-1 overflow-auto`,children:(0,F.jsxs)(`div`,{className:`flex`,style:{height:d},children:[(0,F.jsx)(`div`,{className:`w-14 shrink-0 border-r relative`,children:k.map((e,t)=>(0,F.jsx)(`div`,{className:`absolute right-1 text-[10px] text-muted-foreground -translate-y-1/2`,style:{top:t*K},children:t===0?``:e},t))}),f.map((e,n)=>{let r=Y(e),c=y.get(r)??[];return(0,F.jsxs)(`div`,{ref:e=>{x.current[n]=e},className:`flex-1 border-r last:border-r-0 relative select-none`,style:{height:d},onPointerDown:e=>j(e,n),"aria-label":e.toLocaleDateString(i,{weekday:`long`,month:`long`,day:`numeric`,year:`numeric`}),children:[Array.from({length:24},(e,t)=>(0,F.jsx)(`div`,{className:`absolute left-0 right-0 border-t border-muted/60 pointer-events-none`,style:{top:t*K}},t)),a<60&&Array.from({length:Math.floor(1440/a)},(e,t)=>{let n=t*a;return n%60==0?null:(0,F.jsx)(`div`,{className:`absolute left-0 right-0 border-t border-dashed border-muted/30 pointer-events-none`,style:{top:n/60*K}},t)}),c.map(r=>{let a=r.startMin/60*K,c=Math.max(u,(r.endMin-r.startMin)/60*K),l=100/r.cols,d=r.col*l,{className:f,inlineColor:p}=B(r.event.color),m=S&&S.eventId===r.event.id;return(0,F.jsxs)(`div`,{role:`button`,tabIndex:0,title:r.event.title,"aria-label":r.event.title,onPointerDown:e=>A(e,r,n,`body`),onClick:e=>{if(T.current){e.stopPropagation();return}e.stopPropagation(),o?.(r.event)},className:t(`absolute rounded text-xs px-2 py-1 overflow-hidden shadow-sm`,s?`cursor-move`:`cursor-pointer`,f,m&&`opacity-40`),style:{top:a,height:c,left:`calc(${d}% + 2px)`,width:`calc(${l}% - 4px)`,...p?{backgroundColor:p}:{}},children:[(0,F.jsx)(`div`,{className:`font-medium truncate`,children:r.event.title}),(0,F.jsx)(`div`,{className:`text-[10px] opacity-80 truncate`,children:X(e,r.startMin,r.endMin,i)}),s&&r.isStart&&(0,F.jsx)(`div`,{onPointerDown:e=>A(e,r,n,`top`),className:`absolute top-0 left-0 right-0 h-1.5 cursor-ns-resize`,"aria-label":`Resize start`}),s&&r.isEnd&&(0,F.jsx)(`div`,{onPointerDown:e=>A(e,r,n,`bottom`),className:`absolute bottom-0 left-0 right-0 h-1.5 cursor-ns-resize`,"aria-label":`Resize end`})]},`${r.event.id}-${r.startMin}`)}),M(n)]},r)})]})})]})}function X(e,t,n,r){let i=new Date(e);i.setHours(0,Math.round(t),0,0);let a=new Date(e);a.setHours(0,Math.round(n),0,0);let o=e=>e.toLocaleTimeString(r,{hour:`numeric`,minute:`2-digit`});return`${o(i)} – ${o(a)}`}function oe(e){return`data`in e&&e.data?e.data:`staticData`in e&&e.staticData?{provider:`value`,items:e.staticData}:e.objectName?{provider:`object`,object:e.objectName}:null}function se(e){if(e){if(typeof e==`string`){let t=e.split(` `),n=t[0],r=t[1]?.toLowerCase()===`desc`?`desc`:`asc`;return{[n]:r}}if(Array.isArray(e))return e.reduce((e,t)=>(t.field&&t.order&&(e[t.field]=t.order),e),{})}}function ce(e){return`filter`in e&&e.filter&&typeof e.filter==`object`&&`calendar`in e.filter?e.filter.calendar:e.calendar?e.calendar:e.startDateField||e.dateField?{startDateField:e.startDateField||e.dateField,endDateField:e.endDateField||e.endField,titleField:e.titleField,colorField:e.colorField,allDayField:e.allDayField}:null}var le=({schema:e,dataSource:t,className:a,data:o,loading:s,onEventClick:l,onRowClick:f,onDateClick:p,onNavigate:m,onViewChange:h,onEventDrop:_,locale:y})=>{let S=Array.isArray(o),[C,w]=(0,P.useState)(S?o:[]),[T,k]=(0,P.useState)(S?s??!1:!0),[M,te]=(0,P.useState)(null),[N,I]=(0,P.useState)(null),[ne,L]=(0,P.useState)(new Date),R=g(),z=e.defaultView,[B,V]=(0,P.useState)(()=>{let e=z===`day`||!z;return typeof window<`u`&&window.innerWidth<768&&e?`month`:z||`month`});(0,P.useEffect)(()=>{R&&B===`day`&&(z===`day`||!z)&&V(`month`)},[R]);let[H,U]=(0,P.useState)(0);(0,P.useEffect)(()=>{if(!S&&!(!t?.onMutation||!e.objectName))return t.onMutation(t=>{t.resource===e.objectName&&U(e=>e+1)})},[t,e.objectName,S]);let{ref:ie,isRefreshing:W,pullDistance:G}=i({onRefresh:(0,P.useCallback)(async()=>{U(e=>e+1)},[]),enabled:!!t&&!!e.objectName}),K=(0,P.useMemo)(()=>oe(e),[e.data,e.staticData,e.objectName]),q=(0,P.useMemo)(()=>ce(e),[e.filter,e.calendar,e.dateField,e.endField,e.titleField,e.colorField]),J=K?.provider===`value`,Y=(0,P.useRef)(null);Y.current=N,(0,P.useEffect)(()=>{S&&w(o)},[o,S]),(0,P.useEffect)(()=>{S&&s!==void 0&&k(s)},[s,S]),(0,P.useEffect)(()=>{if(S)return;let n=!0;return(async()=>{try{if(!n)return;if(k(!0),J&&K?.provider===`value`){n&&(w(K.items),k(!1));return}if(!t||typeof t.find!=`function`)throw Error(`DataSource required for object/api providers`);if(K?.provider===`object`){let r=K.object,i=ee(Y.current?.fields),a=b(await t.find(r,{$filter:e.filter,$orderby:se(e.sort),...i.length>0?{$expand:i}:{}}));n&&w(a)}else K?.provider===`api`&&(console.warn(`API provider not yet implemented for ObjectCalendar`),n&&w([]));n&&k(!1)}catch(e){console.error(`[ObjectCalendar] Error fetching data:`,e),n&&(te(e),k(!1))}})(),()=>{n=!1}},[S,K,t,J,e.filter,e.sort,H]),(0,P.useEffect)(()=>{!J&&t&&(async()=>{try{if(!t)return;let n=K?.provider===`object`?K.object:e.objectName;if(!n)return;I(await t.getObjectSchema(n))}catch(e){console.error(`Failed to fetch object schema:`,e)}})()},[e.objectName,t,J,K]);let ae=(0,P.useMemo)(()=>{if(!q||!C.length)return[];let{startDateField:e,endDateField:t,titleField:n,colorField:r}=q,i=N?.titleFormat,a=typeof i==`string`?i:i&&typeof i==`object`&&typeof i.source==`string`?i.source:void 0,o=N?.NAME_FIELD_KEY,s=[`name`,`full_name`,`fullName`,`title`,`subject`,`label`,`display_name`,`displayName`],c=(e,t)=>{let n=`[-\\u2013\\u2014|/·,:]`,r=!1,i=e.replace(/\{([^{}]+)\}/g,(e,n)=>{let i=t[n.trim()];return i!=null&&i!==``?(r=!0,String(i)):`\0`});return r?i.replace(RegExp(`\\s*${n}\\s*`,`g`),``).replace(RegExp(`\\s*${n}\\s*`,`g`),``).replace(RegExp(`\0`,`g`),``).replace(/\s+/g,` `).trim():``},l=e=>{let t;if(n&&(t=e[n],typeof t==`string`&&(t=t.trim())),!t&&a){let n=c(a,e);n&&(t=n)}if(!t&&o){let n=e[o];typeof n==`string`?t=n.trim():n&&(t=n)}if(!t)for(let n of s){let r=e[n],i=typeof r==`string`?r.trim():r;if(i){t=i;break}}return t||`Untitled`};return C.map((n,i)=>{let a=n[e],o=t?n[t]:null,s=l(n),c=r?n[r]:void 0;return{id:n.id||n._id||`event-${i}`,title:s,start:a?new Date(a):new Date,end:o?new Date(o):void 0,color:c,allDay:!o,data:n}}).filter(e=>!isNaN(e.start.getTime()))},[C,q,N]);(0,P.useCallback)(()=>{p?.(new Date)},[p]);let X=e.navigation??{mode:`drawer`,width:`min(960px, 60vw)`},le=X.mode===`drawer`||X.mode===`modal`||X.mode===`split`||X.mode===`popover`,Z=u({navigation:X,objectName:e.objectName,onRowClick:le?void 0:f}),ue=(0,P.useCallback)(async(n,r,i)=>{if(!q)return;let{startDateField:a,endDateField:o}=q,s=n?.id??n?._id;if(!s||!e.objectName||!t?.update)return;let c={[a]:r.toISOString()};o&&i&&(c[o]=i.toISOString());let l=C;w(e=>e.map(e=>(e?.id??e?._id)===s?{...e,...c}:e));try{await t.update(e.objectName,s,c)}catch(e){w(l),console.error(`[ObjectCalendar] Failed to persist drag-and-drop reschedule:`,e)}},[q,e.objectName,t,C]),[Q,$]=(0,P.useState)(null),de=(0,P.useCallback)(n=>{!q||!e.objectName||!t?.create||$({start:n,title:``,submitting:!1})},[q,e.objectName,t]),fe=(0,P.useCallback)((n,r)=>{!q||!e.objectName||!t?.create||$({start:n,end:r,title:``,submitting:!1})},[q,e.objectName,t]),pe=(0,P.useCallback)(async()=>{if(!Q||!q)return;let n=Q.title.trim();if(!n){$(e=>e&&{...e,error:`Title is required`});return}if(!e.objectName||!t?.create)return;$(e=>e&&{...e,submitting:!0,error:void 0});let{startDateField:r,endDateField:i,titleField:a}=q,o={[a||`name`]:n,[r]:Q.start.toISOString()};i&&(o[i]=(Q.end??Q.start).toISOString());let s=N?.fields;if(s&&typeof s==`object`){let e=Array.isArray(s)?s.map(e=>[e.name??e.apiName,e]):Object.entries(s);for(let[t,n]of e){if(!t||t in o||!n?.required)continue;if(n.defaultValue!==void 0&&n.defaultValue!==null){o[t]=n.defaultValue;continue}let e=n.type;if(e===`select`||e===`picklist`||e===`status`){let e=(n.options||n.choices||[])[0];e!==void 0&&(o[t]=typeof e==`object`?e.value??e.id:e)}else e===`boolean`||e===`checkbox`?o[t]=!1:(e===`number`||e===`integer`||e===`decimal`||e===`currency`||e===`percent`)&&(o[t]=0)}}try{let n=await t.create(e.objectName,o),r=(n&&(n.record||n.data||n))??null;r&&(r.id!==void 0||r._id!==void 0)&&w(e=>[...e,r]),$(null)}catch(e){let t=e?.message||String(e);$(e=>e&&{...e,submitting:!1,error:t}),console.error(`[ObjectCalendar] Quick-create failed:`,e)}},[Q,q,e.objectName,t,N]);return T?(0,F.jsx)(`div`,{className:a,children:(0,F.jsx)(`div`,{className:`flex items-center justify-center h-96`,children:(0,F.jsx)(`div`,{className:`text-muted-foreground`,children:`Loading calendar...`})})}):M?(0,F.jsx)(`div`,{className:a,children:(0,F.jsx)(`div`,{className:`flex items-center justify-center h-96`,children:(0,F.jsxs)(`div`,{className:`text-destructive`,children:[`Error: `,M.message]})})}):q?(0,F.jsxs)(`div`,{ref:ie,className:a,children:[G>0&&(0,F.jsx)(`div`,{className:`flex items-center justify-center text-xs text-muted-foreground`,style:{height:G},children:W?`Refreshing…`:`Pull to refresh`}),(0,F.jsx)(`div`,{className:`bg-background h-[calc(100vh-120px)] sm:h-[calc(100vh-160px)] md:h-[calc(100vh-200px)] min-h-[400px] sm:min-h-[600px]`,children:(0,F.jsx)(re,{events:ae,currentDate:ne,view:B,locale:y,onEventClick:e=>{Z.handleClick(e.data),le||l?.(e.data)},onDateClick:e=>{p?p(e):de(e)},onNavigate:e=>{L(e),m?.(e)},onViewChange:e=>{V(e),h?.(e)},onAddClick:void 0,onEventDrop:(e,t,n)=>{_?_(e.data,t,n):ue(e.data,t,n)},onTimeRangeSelect:fe})}),(0,F.jsx)(E,{open:!!Q,onOpenChange:e=>{e||$(null)},children:(0,F.jsxs)(A,{className:`sm:max-w-md`,children:[(0,F.jsxs)(j,{children:[(0,F.jsx)(d,{children:`New event`}),(0,F.jsx)(O,{children:Q&&(()=>{let e=Q.end&&Q.end.getTime()!==Q.start.getTime(),t=Q.start.toLocaleDateString(y,{year:`numeric`,month:`long`,day:`numeric`});if(e){let e=e=>e.toLocaleTimeString(y,{hour:`numeric`,minute:`2-digit`});return(0,F.jsxs)(F.Fragment,{children:[t,` · `,e(Q.start),` – `,e(Q.end)]})}return(0,F.jsxs)(F.Fragment,{children:[`On `,t]})})()})]}),(0,F.jsxs)(`div`,{className:`space-y-2`,children:[(0,F.jsx)(x,{htmlFor:`quick-create-title`,children:`Title`}),(0,F.jsx)(v,{id:`quick-create-title`,autoFocus:!0,value:Q?.title??``,onChange:e=>$(t=>t&&{...t,title:e.target.value,error:void 0}),onKeyDown:e=>{e.key===`Enter`&&!Q?.submitting&&(e.preventDefault(),pe())},placeholder:`What's this event about?`,disabled:Q?.submitting}),Q?.error&&(0,F.jsx)(`p`,{className:`text-sm text-destructive`,children:Q.error})]}),(0,F.jsxs)(c,{children:[(0,F.jsx)(r,{variant:`outline`,onClick:()=>$(null),disabled:Q?.submitting,children:`Cancel`}),(0,F.jsx)(r,{onClick:()=>void pe(),disabled:Q?.submitting||!Q?.title.trim(),children:Q?.submitting?`Creating…`:`Create`})]})]})}),Z.isOverlay&&Z.isOpen&&Z.selectedRecord&&(()=>{let r=K?.provider===`object`?K.object:e.objectName,i=Z.selectedRecord,a=i.id??i._id;if(!r||a==null)return null;let o=q?.titleField?String(i[q.titleField]??`Event Details`):`Event Details`;return(0,F.jsx)(n,{open:!0,onClose:Z.close,title:o,record:i,objectName:r,recordId:a,dataSource:t,objectSchema:N,width:Z.width??`min(960px, 60vw)`,fullPageHref:D(r,a)??void 0,onFieldSave:async(e,n)=>{t?.update&&(await t.update(r,String(a),{[e]:n}),w(t=>t.map(t=>String(t.id??t._id)===String(a)?{...t,[e]:n}:t)))},onDelete:async()=>{t?.delete&&(await t.delete(r,String(a)),w(e=>e.filter(e=>String(e.id??e._id)!==String(a))))}})})()]}):(0,F.jsx)(`div`,{className:a,children:(0,F.jsx)(`div`,{className:`flex items-center justify-center h-96`,children:(0,F.jsx)(`div`,{className:`text-muted-foreground`,children:`Calendar configuration required. Please specify startDateField and titleField.`})})})};S.register(`calendar-view`,({schema:e,className:t,onAction:n,...r})=>(0,F.jsx)(re,{className:t,events:P.useMemo(()=>!e.data||!Array.isArray(e.data)?[]:e.data.map((t,n)=>{let r=e.titleField||`title`,i=e.startDateField||`start`,a=e.endDateField||`end`,o=e.colorField||`color`,s=e.allDayField||`allDay`;return{id:t.id||t._id||n,title:t[r]||`Untitled Event`,start:new Date(t[i]),end:t[a]?new Date(t[a]):void 0,allDay:t[s],color:t[o],data:t}}),[e.data,e.titleField,e.startDateField,e.endDateField,e.colorField,e.allDayField]),onEventClick:e=>{n?.({type:`event-click`,payload:e})},...r}),{namespace:`plugin-calendar`,label:`Calendar View`,inputs:[{name:`data`,type:`array`,label:`Data`,description:`Array of record objects to display as events`},{name:`titleField`,type:`string`,label:`Title Field`,defaultValue:`title`,description:`Field name to use for event title`},{name:`startDateField`,type:`string`,label:`Start Date Field`,defaultValue:`start`,description:`Field name for event start date`},{name:`endDateField`,type:`string`,label:`End Date Field`,defaultValue:`end`,description:`Field name for event end date (optional)`},{name:`allDayField`,type:`string`,label:`All Day Field`,defaultValue:`allDay`,description:`Field name for all-day flag`},{name:`colorField`,type:`string`,label:`Color Field`,defaultValue:`color`,description:`Field name for event color`},{name:`colorMapping`,type:`object`,label:`Color Mapping`,description:`Map field values to colors (e.g., {meeting: "blue", deadline: "red"})`},{name:`view`,type:`enum`,enum:[`month`,`week`,`day`],defaultValue:`month`,label:`View Mode`,description:`Calendar view mode (month, week, or day)`},{name:`currentDate`,type:`string`,label:`Current Date`,description:`ISO date string for initial calendar date`},{name:`allowCreate`,type:`boolean`,label:`Allow Create`,defaultValue:!1,description:`Allow creating events by clicking on dates`},{name:`className`,type:`string`,label:`CSS Class`}],defaultProps:{view:`month`,titleField:`title`,startDateField:`start`,endDateField:`end`,allDayField:`allDay`,colorField:`color`,allowCreate:!1,data:[{id:1,title:`Team Meeting`,start:new Date(new Date().setHours(10,0,0,0)).toISOString(),end:new Date(new Date().setHours(11,0,0,0)).toISOString(),color:`#3b82f6`,allDay:!1},{id:2,title:`Project Deadline`,start:new Date(new Date().setDate(new Date().getDate()+3)).toISOString(),color:`#ef4444`,allDay:!0},{id:3,title:`Conference`,start:new Date(new Date().setDate(new Date().getDate()+7)).toISOString(),end:new Date(new Date().setDate(new Date().getDate()+9)).toISOString(),color:`#10b981`,allDay:!0}],className:`h-[600px] border rounded-lg`}});var Z=({schema:e,...t})=>{let{dataSource:n}=a()||{};return(0,F.jsx)(le,{schema:e,dataSource:n,...t})};S.register(`object-calendar`,Z,{namespace:`plugin-calendar`,label:`Object Calendar`,category:`view`,inputs:[{name:`objectName`,type:`string`,label:`Object Name`,required:!0},{name:`calendar`,type:`object`,label:`Calendar Config`,description:`startDateField, endDateField, titleField, colorField`}]}),S.register(`calendar`,Z,{namespace:`view`,label:`Calendar View`,category:`view`,inputs:[{name:`objectName`,type:`string`,label:`Object Name`,required:!0},{name:`calendar`,type:`object`,label:`Calendar Config`,description:`startDateField, endDateField, titleField, colorField`}]});