@object-ui/plugin-calendar 17.6.0 → 18.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.
@@ -1 +1 @@
1
- (function(e,t){typeof exports==`object`&&typeof module<`u`?t(exports,require("react"),require("@object-ui/core"),require("@object-ui/react"),require("lucide-react"),require("@object-ui/components"),require("@object-ui/i18n"),require("react/jsx-runtime"),require("@object-ui/mobile"),require("@object-ui/plugin-detail")):typeof define==`function`&&define.amd?define([`exports`,`react`,`@object-ui/core`,`@object-ui/react`,`lucide-react`,`@object-ui/components`,`@object-ui/i18n`,`react/jsx-runtime`,`@object-ui/mobile`,`@object-ui/plugin-detail`],t):(e=typeof globalThis<`u`?globalThis:e||self,t(e.ObjectUIPluginCalendar={},e.React,e.ObjectUICore,e.ObjectUIReact,e.LucideReact,e.ObjectUIComponents,e._object_ui_i18n,e.react_jsx_runtime,e._object_ui_mobile,e._object_ui_plugin_detail))})(this,function(e,t,n,r,i,a,o,s,c,l){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});var u=Object.create,d=Object.defineProperty,f=Object.getOwnPropertyDescriptor,p=Object.getOwnPropertyNames,m=Object.getPrototypeOf,h=Object.prototype.hasOwnProperty,g=(e,t,n,r)=>{if(t&&typeof t==`object`||typeof t==`function`)for(var i=p(t),a=0,o=i.length,s;a<o;a++)s=i[a],!h.call(e,s)&&s!==n&&d(e,s,{get:(e=>t[e]).bind(null,s),enumerable:!(r=f(t,s))||r.enumerable});return e};t=((e,t,n)=>(n=e==null?{}:u(m(e)),g(t||!e||!e.__esModule||!h.call(e,`default`)?d(n,`default`,{value:e,enumerable:!0}):n,e)))(t,1);var _=`bg-blue-100 text-blue-900 border border-blue-200`,v=new Date,y=[`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`],b=/^#([0-9a-f]{3}|[0-9a-f]{6}|[0-9a-f]{8})$/i,x=/(^|\s)(bg|text|from|to|via)-/;function S(e){if(!e)return{className:_};if(b.test(e))return{className:`text-white`,inlineColor:e};if(x.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:y[Math.abs(t)%y.length]}}var C=(0,o.createSafeTranslation)({"calendar.today":`Today`,"calendar.month":`Month`,"calendar.week":`Week`,"calendar.day":`Day`,"calendar.newEvent":`New event`,"calendar.moreEvents":`+{{count}} more`,"calendar.allDay":`all-day`},`calendar.today`);function w({events:e=[],view:n=`month`,currentDate:r=v,locale:o=`default`,onEventClick:c,onDateClick:l,onViewChange:u,onNavigate:d,onAddClick:f,onEventDrop:p,onTimeRangeSelect:m,slotMinutes:h=30,className:g}){let[_,y]=t.useState(n),[b,x]=t.useState(r),{t:S,language:w}=C(),E=o==="default"?w:o;t.useEffect(()=>{x(r)},[r]),t.useEffect(()=>{y(n)},[n]);let D=t.useRef(u);D.current=u,t.useEffect(()=>{let e=window.matchMedia(`(max-width: 639px)`),t=e=>{e.matches&&(y(`day`),D.current?.(`day`))};return t(e),e.addEventListener(`change`,t),()=>e.removeEventListener(`change`,t)},[]);let k=()=>{let e=new Date(b);_===`month`?e.setMonth(e.getMonth()-1):_===`week`?e.setDate(e.getDate()-7):e.setDate(e.getDate()-1),x(e),d?.(e)},A=()=>{let e=new Date(b);_===`month`?e.setMonth(e.getMonth()+1):_===`week`?e.setDate(e.getDate()+7):e.setDate(e.getDate()+1),x(e),d?.(e)},j=()=>{let e=new Date;x(e),d?.(e)},M=e=>{y(e),u?.(e)},P=()=>{if(_===`month`)return b.toLocaleDateString(E,{month:`long`,year:`numeric`});if(_===`week`){let e=T(b),t=new Date(e);return t.setDate(t.getDate()+6),`${e.toLocaleDateString(E,{month:`short`,day:`numeric`})} - ${t.toLocaleDateString(E,{month:`short`,day:`numeric`,year:`numeric`})}`}return b.toLocaleDateString(E,{weekday:`long`,month:`long`,day:`numeric`,year:`numeric`})},F=t.useRef(0);return(0,s.jsxs)(`div`,{role:`region`,"aria-label":`Calendar`,className:(0,a.cn)(`flex flex-col h-full bg-background min-w-0 overflow-hidden`,g),children:[(0,s.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-2 p-2 sm:p-4 border-b min-w-0`,children:[(0,s.jsxs)(`div`,{className:`flex items-center gap-4`,children:[(0,s.jsxs)(`div`,{className:`flex items-center bg-muted/50 rounded-lg p-1 gap-1`,children:[(0,s.jsx)(a.Button,{variant:`ghost`,size:`sm`,onClick:j,className:`h-8`,"aria-label":`Go to today`,children:S(`calendar.today`)}),(0,s.jsx)(`div`,{className:`h-4 w-px bg-border mx-1`}),(0,s.jsx)(a.Button,{variant:`ghost`,size:`icon`,"aria-label":`Previous period`,onClick:k,className:`h-8 w-8`,children:(0,s.jsx)(i.ChevronLeftIcon,{className:`h-4 w-4`})}),(0,s.jsx)(a.Button,{variant:`ghost`,size:`icon`,"aria-label":`Next period`,onClick:A,className:`h-8 w-8`,children:(0,s.jsx)(i.ChevronRightIcon,{className:`h-4 w-4`})})]}),(0,s.jsxs)(a.Popover,{children:[(0,s.jsx)(a.PopoverTrigger,{asChild:!0,children:(0,s.jsxs)(a.Button,{variant:`ghost`,"aria-label":`Current date: ${P()}`,className:(0,a.cn)(`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,s.jsx)(i.CalendarIcon,{className:`h-5 w-5 text-muted-foreground`}),(0,s.jsx)(`span`,{children:P()})]})}),(0,s.jsx)(a.PopoverContent,{className:`w-auto p-0`,align:`start`,children:(0,s.jsx)(a.Calendar,{mode:`single`,selected:b,onSelect:e=>{e&&(x(e),d?.(e))},autoFocus:!0,startMonth:new Date(2e3,0),endMonth:new Date(2050,11)})})]})]}),(0,s.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,s.jsxs)(a.Select,{value:_,onValueChange:M,children:[(0,s.jsx)(a.SelectTrigger,{className:`w-32 bg-background`,children:(0,s.jsx)(a.SelectValue,{})}),(0,s.jsxs)(a.SelectContent,{children:[(0,s.jsx)(a.SelectItem,{value:`day`,children:S(`calendar.day`)}),(0,s.jsx)(a.SelectItem,{value:`week`,children:S(`calendar.week`)}),(0,s.jsx)(a.SelectItem,{value:`month`,children:S(`calendar.month`)})]})]}),f&&(0,s.jsxs)(a.Button,{onClick:f,size:`sm`,className:`gap-1`,children:[(0,s.jsx)(i.PlusIcon,{className:`h-4 w-4`}),S(`calendar.newEvent`)]})]})]}),(0,s.jsxs)(`div`,{className:`flex-1 overflow-auto`,onTouchStart:e=>{F.current=e.touches[0].clientX},onTouchEnd:e=>{let t=F.current-e.changedTouches[0].clientX;if(Math.abs(t)>50){let e=new Date(b);_===`day`?e.setDate(e.getDate()+(t>0?1:-1)):_===`week`?e.setDate(e.getDate()+(t>0?7:-7)):e.setMonth(e.getMonth()+(t>0?1:-1)),x(e),d?.(e)}},children:[_===`month`&&(0,s.jsx)(O,{date:b,events:e,locale:E,onEventClick:c,onDateClick:l,onEventDrop:p}),_===`week`&&(0,s.jsx)(N,{mode:`week`,date:b,events:e,locale:E,slotMinutes:h,onEventClick:c,onEventDrop:p,onTimeRangeSelect:m}),_===`day`&&(0,s.jsx)(N,{mode:`day`,date:b,events:e,locale:E,slotMinutes:h,onEventClick:c,onEventDrop:p,onTimeRangeSelect:m})]})]})}function T(e){let t=new Date(e),n=t.getDay(),r=t.getDate()-n;return t.setDate(r),t}function E(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 D(e,t){return e.getFullYear()===t.getFullYear()&&e.getMonth()===t.getMonth()&&e.getDate()===t.getDate()}function O({date:e,events:n,locale:r=`default`,onEventClick:i,onDateClick:o,onEventDrop:c}){let l=t.useMemo(()=>E(e),[e.getFullYear(),e.getMonth()]),u=t.useMemo(()=>new Date,[]),{t:d}=C(),f=t.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]),[p,m]=t.useState(null),[h,g]=t.useState(null),_=t.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]),v=(e,t,n=`move`,r)=>{m(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()},y=()=>{m(null),g(null)},b=(e,t)=>{e.preventDefault(),e.dataTransfer.dropEffect=`move`,g(t)},x=e=>{e.currentTarget.contains(e.relatedTarget)||g(null)},w=(e,t)=>{if(e.preventDefault(),g(null),m(null),!c)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 o=new Date(t);if(o.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),o.getTime()===t.getTime())return;let n=new Date(a.start);if(n.setHours(0,0,0,0),o.getTime()<n.getTime())return;let r=new Date(o);r.setHours(e.getHours(),e.getMinutes(),e.getSeconds(),0),c(a,new Date(a.start),r);return}let s=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(s);l.setHours(0,0,0,0);let u=o.getTime()-l.getTime();if(u===0)return;let d=new Date(s.getTime()+u),f;a.end&&(f=new Date(new Date(a.end).getTime()+u)),c(a,d,f)};return(0,s.jsxs)(`div`,{className:`flex flex-col h-full`,children:[(0,s.jsx)(`div`,{role:`row`,className:`grid grid-cols-7 border-b`,children:f.map(e=>(0,s.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,s.jsx)(`div`,{role:`grid`,"aria-label":`Calendar grid`,className:`grid grid-cols-7 flex-1 auto-rows-fr`,children:l.map((t,n)=>{let r=`${t.getFullYear()}-${t.getMonth()}-${t.getDate()}`,l=_.get(r)||[],f=t.getMonth()===e.getMonth(),m=D(t,u);return(0,s.jsxs)(`div`,{role:`gridcell`,"aria-label":`${t.toLocaleDateString(`default`,{weekday:`long`,month:`long`,day:`numeric`,year:`numeric`})}${l.length>0?`, ${l.length} event${l.length>1?`s`:``}`:``}`,className:(0,a.cn)(`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`,h===n&&`ring-2 ring-primary`),onClick:()=>o?.(t),onDragOver:e=>b(e,n),onDragLeave:x,onDrop:e=>w(e,t),children:[(0,s.jsx)(`div`,{className:(0,a.cn)(`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:t.getDate()}),(0,s.jsxs)(`div`,{className:`space-y-0.5`,children:[l.slice(0,4).map(({event:e,isTitleDay:n,isSpanStart:r,isSpanEnd:o},l)=>{let u=!n,{className:d,inlineColor:f}=S(e.color),m=!!c&&o;return(0,s.jsxs)(`div`,{role:`button`,title:e.title,"aria-label":e.title,draggable:!!c,onDragStart:n=>v(n,e,`move`,t),onDragEnd:y,className:(0,a.cn)(`relative text-xs hover:opacity-80 truncate`,c?`cursor-move`:`cursor-pointer`,u?`h-1.5`:`px-2 py-0.5`,r?`rounded-l`:`rounded-l-none`,o?`rounded-r`:`rounded-r-none`,!o&&`-mr-2`,d,p===e.id&&`opacity-50`),style:f?{backgroundColor:f}:void 0,onClick:t=>{t.stopPropagation(),i?.(e)},children:[u?``:e.title,m&&(0,s.jsx)(`span`,{role:`separator`,"aria-label":`Resize event end`,title:`Drag to change end date`,draggable:!0,onDragStart:n=>v(n,e,`resize-end`,t),onDragEnd:y,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}-${l}`)}),l.length>4&&(0,s.jsx)(`div`,{className:`text-xs text-muted-foreground px-2`,children:d(`calendar.moreEvents`,{count:l.length-4})})]})]},n)})})]})}var k=48;function A(e){let t=new Date(e);return t.setHours(0,0,0,0),t}function j(e){return e.getHours()*60+e.getMinutes()}function M(e){return`${e.getFullYear()}-${e.getMonth()}-${e.getDate()}`}function N({mode:e,date:n,events:r,locale:i=`default`,slotMinutes:o=30,onEventClick:c,onEventDrop:l,onTimeRangeSelect:u}){let{t:d}=C(),f=k*o/60,p=1152,m=t.useMemo(()=>{if(e===`day`)return[A(n)];let t=T(n);return Array.from({length:7},(e,n)=>{let r=new Date(t);return r.setDate(t.getDate()+n),A(r)})},[e,n.getFullYear(),n.getMonth(),n.getDate()]),h=t.useMemo(()=>new Date,[]),g=t.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>=864e5)},[]),{allDayEvents:_,timedEvents:v}=t.useMemo(()=>{let e=[],t=[];for(let n of r)g(n)?e.push(n):t.push(n);return{allDayEvents:e,timedEvents:t}},[r,g]),y=t.useMemo(()=>{let e=new Map;for(let t of m)e.set(M(t),[]);for(let t of _){let n=A(new Date(t.start)),r=t.end?new Date(t.end):new Date(t.start),i=A(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 m){let a=A(r);a<n||a>i||e.get(M(r)).push({event:t,isStart:a.getTime()===n.getTime(),isEnd:a.getTime()===i.getTime()})}}return e},[m,_]),b=t.useMemo(()=>{let e=new Map;for(let t of m)e.set(M(t),[]);for(let t of v){let n=new Date(t.start),r=t.end?new Date(t.end):new Date(n.getTime()+36e5);for(let i of m){let a=A(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(M(i)).push({event:t,startMin:l,endMin:Math.max(u,l+15),isStart:s.getTime()===n.getTime(),isEnd:c.getTime()===r.getTime()})}}return e},[m,v]),x=t.useMemo(()=>{let e=new Map;for(let[t,n]of b){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},[b]),w=t.useRef(null),E=t.useRef([]),[O,N]=t.useState(null),F=t.useRef(null);F.current=O;let I=t.useRef(!1),L=t.useCallback((e,t)=>{let n=E.current[t];if(!n)return 0;let r=(e-n.getBoundingClientRect().top+n.scrollTop)/k*60,i=Math.round(r/o)*o;return Math.max(0,Math.min(1440,i))},[o]),R=t.useCallback(e=>{for(let t=0;t<E.current.length;t++){let n=E.current[t];if(!n)continue;let r=n.getBoundingClientRect();if(e>=r.left&&e<=r.right)return t}return-1},[]);t.useEffect(()=>{if(!O)return;let e=e=>{let t=O.kind===`select`||O.kind===`move`?R(e.clientX):O.dayIndex,n=t<0?O.dayIndex??0:t,r=L(e.clientY,n);N(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=F.current;if(!t){N(null);return}try{if(t.kind===`select`&&u){let e=Math.min(t.anchorMinutes,t.headMinutes),n=Math.max(t.anchorMinutes,t.headMinutes),r=e,i=n===e?Math.min(1440,e+o):n,a=m[t.dayIndex]??m[0],s=new Date(a);s.setHours(0,Math.round(r),0,0);let c=new Date(a);c.setHours(0,Math.round(i),0,0),I.current=!0,u(s,c)}else if(t.kind===`move`&&l){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/o)*o)),a=m[n]??m[0],s=new Date(a);s.setHours(0,i,0,0);let c=new Date(s.getTime()+t.durationMin*60*1e3);I.current=!0,l(e,s,c)}}else if(t.kind===`resize-top`&&l){let e=r.find(e=>String(e.id)===String(t.eventId));if(e){let n=m[t.dayIndex]??m[0],r=Math.min(t.anchorEndMin-o,Math.max(0,t.minutes)),i=new Date(n);i.setHours(0,r,0,0);let a=new Date(n);a.setHours(0,t.anchorEndMin,0,0),I.current=!0,l(e,i,a)}}else if(t.kind===`resize-bottom`&&l){let e=r.find(e=>String(e.id)===String(t.eventId));if(e){let n=m[t.dayIndex]??m[0],r=Math.max(t.anchorStartMin+o,Math.min(1440,t.minutes)),i=new Date(n);i.setHours(0,t.anchorStartMin,0,0);let a=new Date(n);a.setHours(0,r,0,0),I.current=!0,l(e,i,a)}}}finally{N(null),setTimeout(()=>{I.current=!1},50)}};return window.addEventListener(`pointermove`,e),window.addEventListener(`pointerup`,t),()=>{window.removeEventListener(`pointermove`,e),window.removeEventListener(`pointerup`,t)}},[O,m,r,o,l,u,R,L]);let z=t.useMemo(()=>m.map(e=>({weekday:e.toLocaleDateString(i,{weekday:`short`}),day:e.getDate(),month:e.toLocaleDateString(i,{month:`short`}),isToday:D(e,h)})),[m,i,h]),B=t.useMemo(()=>Array.from({length:24},(e,t)=>new Date(2024,0,1,t,0).toLocaleTimeString(i,{hour:`numeric`})),[i]),V=(e,t,n,r)=>{if(!l||e.button!==0)return;e.stopPropagation(),e.preventDefault();let i=L(e.clientY,n);N(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})},H=(e,t)=>{if(!u||e.button!==0)return;e.preventDefault();let n=L(e.clientY,t);N({kind:`select`,dayIndex:t,anchorMinutes:n,headMinutes:n})},U=e=>{if(!O)return null;if(O.kind===`select`&&O.dayIndex===e){let t=Math.min(O.anchorMinutes,O.headMinutes),n=Math.max(O.anchorMinutes,O.headMinutes),r=t/60*k,a=Math.max(f,(n-t)/60*k);return(0,s.jsx)(`div`,{className:`absolute left-1 right-1 rounded bg-primary/30 border border-primary pointer-events-none z-10`,style:{top:r,height:a},"aria-hidden":!0,children:(0,s.jsx)(`div`,{className:`px-2 py-0.5 text-xs font-medium text-primary`,children:P(m[e],t,n,i)})})}if(O.kind===`move`&&O.dayIndex===e){let t=O.minutes-O.grabMinuteOffset,n=Math.max(0,Math.min(1440-O.durationMin,Math.round(t/o)*o)),r=n/60*k,a=O.durationMin/60*k;return(0,s.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:r,height:a},"aria-hidden":!0,children:(0,s.jsx)(`div`,{className:`px-2 py-0.5 text-xs font-medium text-primary`,children:P(m[e],n,n+O.durationMin,i)})})}if((O.kind===`resize-top`||O.kind===`resize-bottom`)&&O.dayIndex===e){let t,n;O.kind===`resize-top`?(t=Math.min(O.anchorEndMin-o,Math.max(0,O.minutes)),n=O.anchorEndMin):(t=O.anchorStartMin,n=Math.max(O.anchorStartMin+o,Math.min(1440,O.minutes)));let r=t/60*k,a=(n-t)/60*k;return(0,s.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:r,height:a},"aria-hidden":!0,children:(0,s.jsx)(`div`,{className:`px-2 py-0.5 text-xs font-medium text-primary`,children:P(m[e],t,n,i)})})}return null};return(0,s.jsxs)(`div`,{className:`flex flex-col h-full`,ref:w,children:[(0,s.jsxs)(`div`,{className:`flex border-b sticky top-0 bg-background z-20`,children:[(0,s.jsx)(`div`,{className:`w-14 shrink-0 border-r`,"aria-hidden":!0}),z.map((e,t)=>(0,s.jsxs)(`div`,{role:`columnheader`,className:(0,a.cn)(`flex-1 p-2 text-center text-sm border-r last:border-r-0`,e.isToday&&`bg-primary/5`),children:[(0,s.jsx)(`div`,{className:`text-xs text-muted-foreground`,children:e.weekday}),(0,s.jsx)(`div`,{className:(0,a.cn)(`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})]},t))]}),_.length>0&&(0,s.jsxs)(`div`,{className:`flex border-b bg-muted/20 max-h-[140px] overflow-y-auto`,children:[(0,s.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:d(`calendar.allDay`)===`calendar.allDay`?`all-day`:d(`calendar.allDay`)}),m.map(e=>{let t=M(e),n=y.get(t)??[];return(0,s.jsx)(`div`,{className:`flex-1 border-r last:border-r-0 min-h-[28px] p-0.5 space-y-0.5`,children:n.map(({event:e,isStart:t,isEnd:n},r)=>{let{className:i,inlineColor:o}=S(e.color);return(0,s.jsx)(`div`,{role:`button`,title:e.title,onClick:t=>{t.stopPropagation(),c?.(e)},className:(0,a.cn)(`text-[11px] px-2 py-0.5 truncate cursor-pointer hover:opacity-80`,t?`rounded-l`:`rounded-l-none -ml-0.5`,n?`rounded-r`:`rounded-r-none -mr-0.5`,i),style:o?{backgroundColor:o}:void 0,children:t?e.title:`\xA0`},`${e.id}-${r}`)})},t)})]}),(0,s.jsx)(`div`,{className:`flex-1 overflow-auto`,children:(0,s.jsxs)(`div`,{className:`flex`,style:{height:p},children:[(0,s.jsx)(`div`,{className:`w-14 shrink-0 border-r relative`,children:B.map((e,t)=>(0,s.jsx)(`div`,{className:`absolute right-1 text-[10px] text-muted-foreground -translate-y-1/2`,style:{top:t*k},children:t===0?``:e},t))}),m.map((e,t)=>{let n=M(e),r=x.get(n)??[];return(0,s.jsxs)(`div`,{ref:e=>{E.current[t]=e},className:`flex-1 border-r last:border-r-0 relative select-none`,style:{height:p},onPointerDown:e=>H(e,t),"aria-label":e.toLocaleDateString(i,{weekday:`long`,month:`long`,day:`numeric`,year:`numeric`}),children:[Array.from({length:24},(e,t)=>(0,s.jsx)(`div`,{className:`absolute left-0 right-0 border-t border-muted/60 pointer-events-none`,style:{top:t*k}},t)),o<60&&Array.from({length:Math.floor(1440/o)},(e,t)=>{let n=t*o;return n%60==0?null:(0,s.jsx)(`div`,{className:`absolute left-0 right-0 border-t border-dashed border-muted/30 pointer-events-none`,style:{top:n/60*k}},t)}),r.map(n=>{let r=n.startMin/60*k,o=Math.max(f,(n.endMin-n.startMin)/60*k),u=100/n.cols,d=n.col*u,{className:p,inlineColor:m}=S(n.event.color),h=O&&O.eventId===n.event.id;return(0,s.jsxs)(`div`,{role:`button`,tabIndex:0,title:n.event.title,"aria-label":n.event.title,onPointerDown:e=>V(e,n,t,`body`),onClick:e=>{if(I.current){e.stopPropagation();return}e.stopPropagation(),c?.(n.event)},className:(0,a.cn)(`absolute rounded text-xs px-2 py-1 overflow-hidden shadow-sm`,l?`cursor-move`:`cursor-pointer`,p,h&&`opacity-40`),style:{top:r,height:o,left:`calc(${d}% + 2px)`,width:`calc(${u}% - 4px)`,...m?{backgroundColor:m}:{}},children:[(0,s.jsx)(`div`,{className:`font-medium truncate`,children:n.event.title}),(0,s.jsx)(`div`,{className:`text-[10px] opacity-80 truncate`,children:P(e,n.startMin,n.endMin,i)}),l&&n.isStart&&(0,s.jsx)(`div`,{onPointerDown:e=>V(e,n,t,`top`),className:`absolute top-0 left-0 right-0 h-1.5 cursor-ns-resize`,"aria-label":`Resize start`}),l&&n.isEnd&&(0,s.jsx)(`div`,{onPointerDown:e=>V(e,n,t,`bottom`),className:`absolute bottom-0 left-0 right-0 h-1.5 cursor-ns-resize`,"aria-label":`Resize end`})]},`${n.event.id}-${n.startMin}`)}),U(t)]},n)})]})})]})}function P(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 F(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 I(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 L=({schema:e,dataSource:i,className:o,data:u,loading:d,onEventClick:f,onRowClick:p,onDateClick:m,onNavigate:h,onViewChange:g,onEventDrop:_,locale:v})=>{let y=(0,r.useSafeTranslate)(),b=Array.isArray(u),[x,S]=(0,t.useState)(b?u:[]),[C,T]=(0,t.useState)(b?d??!1:!0),[E,D]=(0,t.useState)(null),[O,k]=(0,t.useState)(null),[A,j]=(0,t.useState)(new Date),M=(0,a.useIsMobile)(),N=e.defaultView,[P,L]=(0,t.useState)(()=>{let e=N===`day`||!N;return typeof window<`u`&&window.innerWidth<768&&e?`month`:N||`month`});(0,t.useEffect)(()=>{M&&P===`day`&&(N===`day`||!N)&&L(`month`)},[M]);let[R,z]=(0,t.useState)(0);(0,t.useEffect)(()=>{if(!b&&!(!i?.onMutation||!e.objectName))return i.onMutation(t=>{t.resource===e.objectName&&z(e=>e+1)})},[i,e.objectName,b]);let B=(0,t.useCallback)(async()=>{z(e=>e+1)},[]),{ref:V,isRefreshing:H,pullDistance:U}=(0,c.usePullToRefresh)({onRefresh:B,enabled:!!i&&!!e.objectName}),W=(0,t.useMemo)(()=>F(e),[e.data,e.staticData,e.objectName]),G=(0,t.useMemo)(()=>I(e),[e.filter,e.calendar,e.dateField,e.endField,e.titleField,e.colorField]),K=W?.provider===`value`,q=(0,t.useRef)(null);q.current=O,(0,t.useEffect)(()=>{b&&S(u)},[u,b]),(0,t.useEffect)(()=>{b&&d!==void 0&&T(d)},[d,b]),(0,t.useEffect)(()=>{if(b)return;let t=!0;return(async()=>{try{if(!t)return;if(T(!0),K&&W?.provider===`value`){t&&(S(W.items),T(!1));return}if(!i||typeof i.find!=`function`)throw Error(`DataSource required for object/api providers`);if(W?.provider===`object`){let r=W.object,a=(0,n.buildExpandFields)(q.current?.fields),o=await i.find(r,{$filter:e.filter,$orderby:(0,n.convertSortToQueryParams)(e.sort),...a.length>0?{$expand:a}:{}}),s=(0,n.extractRecords)(o);t&&S(s)}else W?.provider===`api`&&(console.warn(`API provider not yet implemented for ObjectCalendar`),t&&S([]));t&&T(!1)}catch(e){console.error(`[ObjectCalendar] Error fetching data:`,e),t&&(D(e),T(!1))}})(),()=>{t=!1}},[b,W,i,K,e.filter,e.sort,R]),(0,t.useEffect)(()=>{!K&&i&&(async()=>{try{if(!i)return;let t=W?.provider===`object`?W.object:e.objectName;if(!t)return;let n=await i.getObjectSchema(t);k(n)}catch(e){console.error(`Failed to fetch object schema:`,e)}})()},[e.objectName,i,K,W]);let J=(0,t.useMemo)(()=>{if(!G||!x.length)return[];let{startDateField:e,endDateField:t,titleField:r,colorField:i}=G,a=e=>{if(r){let t=e[r],n=typeof t==`string`?t.trim():t;if(n)return String(n)}return(0,n.getRecordDisplayName)(O,e)};return x.map((n,r)=>{let o=n[e],s=t?n[t]:null,c=a(n),l=i?n[i]:void 0;return{id:n.id||n._id||`event-${r}`,title:c,start:o?new Date(o):new Date,end:s?new Date(s):void 0,color:l,allDay:!s,data:n}}).filter(e=>!isNaN(e.start.getTime()))},[x,G,O]);(0,t.useCallback)(()=>{m?.(new Date)},[m]);let Y=e.navigation??{mode:`drawer`,width:`min(960px, 60vw)`},X=Y.mode===`drawer`||Y.mode===`modal`||Y.mode===`split`||Y.mode===`popover`,Z=(0,r.useNavigationOverlay)({navigation:Y,objectName:e.objectName,onRowClick:X?void 0:p}),ee=(0,t.useCallback)(async(t,n,o)=>{if(!G)return;let{startDateField:s,endDateField:c}=G,l=t?.id??t?._id;if(!l||!e.objectName||!i?.update)return;let u={[s]:n.toISOString()};c&&o&&(u[c]=o.toISOString());let d=x;S(e=>e.map(e=>(e?.id??e?._id)===l?{...e,...u}:e));try{await i.update(e.objectName,l,u)}catch(e){S(d),console.error(`[ObjectCalendar] Failed to persist drag-and-drop reschedule:`,e),a.toast.error((0,r.isPermissionError)(e)?y(`errors.unauthorized`,`You are not authorized to perform this action.`):(0,r.extractWriteErrorMessage)(e)??y(`table.saveFailed`,`Save failed`))}},[G,e.objectName,i,x,y]),[Q,$]=(0,t.useState)(null),te=(0,t.useCallback)(t=>{!G||!e.objectName||!i?.create||$({start:t,title:``,submitting:!1})},[G,e.objectName,i]),ne=(0,t.useCallback)((t,n)=>{!G||!e.objectName||!i?.create||$({start:t,end:n,title:``,submitting:!1})},[G,e.objectName,i]),re=(0,t.useCallback)(async()=>{if(!Q||!G)return;let t=Q.title.trim();if(!t){$(e=>e&&{...e,error:`Title is required`});return}if(!e.objectName||!i?.create)return;$(e=>e&&{...e,submitting:!0,error:void 0});let{startDateField:n,endDateField:r,titleField:a}=G,o={[a||`name`]:t,[n]:Q.start.toISOString()};r&&(o[r]=(Q.end??Q.start).toISOString());let s=O?.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 t=await i.create(e.objectName,o),n=(t&&(t.record||t.data||t))??null;n&&(n.id!==void 0||n._id!==void 0)&&S(e=>[...e,n]),$(null)}catch(e){let t=e?.message||String(e);$(e=>e&&{...e,submitting:!1,error:t}),console.error(`[ObjectCalendar] Quick-create failed:`,e)}},[Q,G,e.objectName,i,O]);return C?(0,s.jsx)(`div`,{className:o,children:(0,s.jsx)(`div`,{className:`flex items-center justify-center h-96`,children:(0,s.jsx)(`div`,{className:`text-muted-foreground`,children:`Loading calendar...`})})}):E?(0,s.jsx)(`div`,{className:o,children:(0,s.jsx)(`div`,{className:`flex items-center justify-center h-96`,children:(0,s.jsxs)(`div`,{className:`text-destructive`,children:[`Error: `,E.message]})})}):G?(0,s.jsxs)(`div`,{ref:V,className:o,children:[U>0&&(0,s.jsx)(`div`,{className:`flex items-center justify-center text-xs text-muted-foreground`,style:{height:U},children:H?`Refreshing…`:`Pull to refresh`}),(0,s.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,s.jsx)(w,{events:J,currentDate:A,view:P,locale:v,onEventClick:e=>{Z.handleClick(e.data),X||f?.(e.data)},onDateClick:e=>{m?m(e):te(e)},onNavigate:e=>{j(e),h?.(e)},onViewChange:e=>{L(e),g?.(e)},onAddClick:void 0,onEventDrop:(e,t,n)=>{_?_(e.data,t,n):ee(e.data,t,n)},onTimeRangeSelect:ne})}),(0,s.jsx)(a.Dialog,{open:!!Q,onOpenChange:e=>{e||$(null)},children:(0,s.jsxs)(a.DialogContent,{className:`sm:max-w-md`,children:[(0,s.jsxs)(a.DialogHeader,{children:[(0,s.jsx)(a.DialogTitle,{children:`New event`}),(0,s.jsx)(a.DialogDescription,{children:Q&&(()=>{let e=Q.end&&Q.end.getTime()!==Q.start.getTime(),t=Q.start.toLocaleDateString(v,{year:`numeric`,month:`long`,day:`numeric`});if(e){let e=e=>e.toLocaleTimeString(v,{hour:`numeric`,minute:`2-digit`});return(0,s.jsxs)(s.Fragment,{children:[t,` · `,e(Q.start),` – `,e(Q.end)]})}return(0,s.jsxs)(s.Fragment,{children:[`On `,t]})})()})]}),(0,s.jsxs)(`div`,{className:`space-y-2`,children:[(0,s.jsx)(a.Label,{htmlFor:`quick-create-title`,children:`Title`}),(0,s.jsx)(a.Input,{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(),re())},placeholder:`What's this event about?`,disabled:Q?.submitting}),Q?.error&&(0,s.jsx)(`p`,{className:`text-sm text-destructive`,children:Q.error})]}),(0,s.jsxs)(a.DialogFooter,{children:[(0,s.jsx)(a.Button,{variant:`outline`,onClick:()=>$(null),disabled:Q?.submitting,children:`Cancel`}),(0,s.jsx)(a.Button,{onClick:()=>void re(),disabled:Q?.submitting||!Q?.title.trim(),children:Q?.submitting?`Creating…`:`Create`})]})]})}),Z.isOverlay&&Z.isOpen&&Z.selectedRecord&&(()=>{let t=W?.provider===`object`?W.object:e.objectName,n=Z.selectedRecord,r=n.id??n._id;if(!t||r==null)return null;let a=G?.titleField?String(n[G.titleField]??`Event Details`):`Event Details`;return(0,s.jsx)(l.RecordDetailDrawer,{open:!0,onClose:Z.close,title:a,record:n,objectName:t,recordId:r,dataSource:i,objectSchema:O,width:Z.width??`min(960px, 60vw)`,fullPageHref:(0,l.deriveRecordPageHref)(t,r)??void 0,onFieldSave:async(e,n)=>{i?.update&&(await i.update(t,String(r),{[e]:n}),S(t=>t.map(t=>String(t.id??t._id)===String(r)?{...t,[e]:n}:t)))},onDelete:async()=>{i?.delete&&(await i.delete(t,String(r)),S(e=>e.filter(e=>String(e.id??e._id)!==String(r))))}})})()]}):(0,s.jsx)(`div`,{className:o,children:(0,s.jsx)(`div`,{className:`flex items-center justify-center h-96`,children:(0,s.jsx)(`div`,{className:`text-muted-foreground`,children:`Calendar configuration required. Please specify startDateField and titleField.`})})})},R=[`onEventClick`,`onDateClick`,`onViewChange`,`onNavigate`,`onAddClick`,`onEventDrop`,`onTimeRangeSelect`];function z(e){let t={};for(let n of R){let r=e[n];typeof r==`function`&&(t[n]=r)}return t}var B=[`month`,`week`,`day`];function V(e){return B.includes(e)?e:void 0}function H(e){if(typeof e==`string`){try{Intl.getCanonicalLocales(e)}catch{return}return e}}function U(e){return typeof e==`number`&&Number.isFinite(e)&&e>0?e:void 0}function W(e){if(e instanceof Date)return e;if(typeof e!=`string`)return;let t=new Date(e);return Number.isNaN(t.getTime())?void 0:t}function G(e){return e===!0}n.ComponentRegistry.register(`calendar-view`,({schema:e,className:n,onAction:r,events:i,currentDate:a,view:o,allowCreate:c,...l})=>{let u=t.default.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]),d=t.default.useMemo(()=>W(a),[a]),f=V(o),p=G(c),m=z(l),h=H(l.locale),g=U(l.slotMinutes),_=typeof r==`function`?r:void 0,v=e=>{_?.({type:`event-click`,payload:e})},y=()=>{_?.({type:`create`,payload:{}})};return(0,s.jsx)(w,{className:n,events:u,currentDate:d,view:f,locale:h,slotMinutes:g,...m,onEventClick:m.onEventClick??v,onAddClick:m.onAddClick??(p?y:void 0)})},{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:`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 K={filter:!0,sort:!0},q=[`onEventClick`,`onRowClick`,`onDateClick`,`onEdit`,`onDelete`,`onNavigate`,`onViewChange`,`onEventDrop`];function J(e){let t={};for(let n of q){let r=e[n];typeof r==`function`&&(t[n]=r)}return t}function Y(e){if(typeof e==`string`){try{Intl.getCanonicalLocales(e)}catch{return}return e}}function X(e){return Array.isArray(e)?e:void 0}function Z(e){return typeof e==`boolean`?e:void 0}function ee(e){return e&&typeof e.find==`function`?e:void 0}var Q=({schema:e,className:t,...n})=>{let{dataSource:i}=(0,r.useSchemaContext)()||{},a=J(n),o=Y(n.locale),c=X(n.data),l=Z(n.loading),u=ee(n.dataSource);return(0,s.jsx)(r.ElementDataSourceGate,{schema:e,mapping:K,dataSource:i,testId:`object-calendar`,errorTitle:`This calendar’s data source could not be resolved`,children:e=>(0,s.jsx)(L,{schema:e,dataSource:u??i,className:t,data:c,loading:l,locale:o,...a})})};n.ComponentRegistry.register(`object-calendar`,Q,{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`}]}),n.ComponentRegistry.register(`calendar`,Q,{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`}]}),e.CalendarView=w,e.ObjectCalendar=L,e.ObjectCalendarRenderer=Q});
1
+ (function(e,t){typeof exports==`object`&&typeof module<`u`?t(exports,require("react"),require("@object-ui/core"),require("@object-ui/react"),require("@object-ui/i18n"),require("lucide-react"),require("@object-ui/components"),require("react/jsx-runtime"),require("@object-ui/mobile"),require("@object-ui/plugin-detail"),require("@object-ui/permissions")):typeof define==`function`&&define.amd?define([`exports`,`react`,`@object-ui/core`,`@object-ui/react`,`@object-ui/i18n`,`lucide-react`,`@object-ui/components`,`react/jsx-runtime`,`@object-ui/mobile`,`@object-ui/plugin-detail`,`@object-ui/permissions`],t):(e=typeof globalThis<`u`?globalThis:e||self,t(e.ObjectUIPluginCalendar={},e.React,e.ObjectUICore,e.ObjectUIReact,e._object_ui_i18n,e.LucideReact,e.ObjectUIComponents,e.react_jsx_runtime,e._object_ui_mobile,e._object_ui_plugin_detail,e._object_ui_permissions))})(this,function(e,t,n,r,i,a,o,s,c,l,u){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});var d=Object.create,f=Object.defineProperty,p=Object.getOwnPropertyDescriptor,m=Object.getOwnPropertyNames,h=Object.getPrototypeOf,g=Object.prototype.hasOwnProperty,_=(e,t,n,r)=>{if(t&&typeof t==`object`||typeof t==`function`)for(var i=m(t),a=0,o=i.length,s;a<o;a++)s=i[a],!g.call(e,s)&&s!==n&&f(e,s,{get:(e=>t[e]).bind(null,s),enumerable:!(r=p(t,s))||r.enumerable});return e};t=((e,t,n)=>(n=e==null?{}:d(h(e)),_(t||!e||!e.__esModule||!g.call(e,`default`)?f(n,`default`,{value:e,enumerable:!0}):n,e)))(t,1);function v(e,t){return(e.getDay()-t+7)%7}function y(e,t){let n=new Date(e);return n.setDate(n.getDate()-v(n,t)),n}function b(e,t){let n=e.getFullYear(),r=e.getMonth(),i=new Date(n,r,1),a=new Date(n,r+1,0),o=v(i,t),s=[];for(let e=o-1;e>=0;e--){let t=new Date(i.getTime());t.setDate(t.getDate()-(e+1)),s.push(t)}for(let e=1;e<=a.getDate();e++)s.push(new Date(n,r,e));let c=42-s.length;for(let e=1;e<=c;e++){let t=new Date(a.getTime());t.setDate(t.getDate()+e),s.push(t)}return s}function x(e,t=0){return new Date(e.getFullYear(),e.getMonth(),e.getDate()+t)}function S(e,t,n){if(t===`month`){let t=b(e,n);return{start:x(t[0]),end:x(t[t.length-1],1)}}let r=x(t===`week`?y(e,n):e);return{start:r,end:x(r,t===`week`?7:1)}}var C=`bg-blue-100 text-blue-900 border border-blue-200`,w=new Date,T=[`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`],E=/^#([0-9a-f]{3}|[0-9a-f]{6}|[0-9a-f]{8})$/i,D=/(^|\s)(bg|text|from|to|via)-/;function O(e){if(!e)return{className:C};if(E.test(e))return{className:`text-white`,inlineColor:e};if(D.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:T[Math.abs(t)%T.length]}}var k=(0,i.createSafeTranslation)({"calendar.today":`Today`,"calendar.month":`Month`,"calendar.week":`Week`,"calendar.day":`Day`,"calendar.newEvent":`New event`,"calendar.moreEvents":`+{{count}} more`,"calendar.allDay":`All Day`,"calendar.a11y.region":`Calendar`,"calendar.a11y.grid":`Calendar grid`,"calendar.a11y.goToToday":`Go to today`,"calendar.a11y.previousPeriod":`Previous period`,"calendar.a11y.nextPeriod":`Next period`,"calendar.a11y.currentDate":`Current date: {{date}}`,"calendar.a11y.dayCell":`{{date}}, {{count}} events`,"calendar.a11y.resizeEventEnd":`Resize event end`,"calendar.a11y.resizeEventEndHint":`Drag to change end date`,"calendar.a11y.resizeStart":`Resize start`,"calendar.a11y.resizeEnd":`Resize end`},`calendar.today`);function A({events:e=[],view:n=`month`,currentDate:r=w,locale:c=`default`,onEventClick:l,onDateClick:u,onViewChange:d,onNavigate:f,onAddClick:p,onEventDrop:m,onTimeRangeSelect:h,slotMinutes:g=30,className:_}){let[v,b]=t.useState(n),[x,S]=t.useState(r),{t:C}=k(),T=(0,i.useDisplayLocale)(),E=c==="default"?T:c,D=(0,i.firstDayOfWeek)(E);t.useEffect(()=>{S(r)},[r]),t.useEffect(()=>{b(n)},[n]);let O=t.useRef(d);O.current=d,t.useEffect(()=>{let e=window.matchMedia(`(max-width: 639px)`),t=e=>{e.matches&&(b(`day`),O.current?.(`day`))};return t(e),e.addEventListener(`change`,t),()=>e.removeEventListener(`change`,t)},[]);let A=()=>{let e=new Date(x);v===`month`?e.setMonth(e.getMonth()-1):v===`week`?e.setDate(e.getDate()-7):e.setDate(e.getDate()-1),S(e),f?.(e)},j=()=>{let e=new Date(x);v===`month`?e.setMonth(e.getMonth()+1):v===`week`?e.setDate(e.getDate()+7):e.setDate(e.getDate()+1),S(e),f?.(e)},M=()=>{let e=new Date;S(e),f?.(e)},N=e=>{b(e),d?.(e)},F=(e=`full`)=>{let t=e===`short`;if(v===`month`)return x.toLocaleDateString(E,{month:t?`short`:`long`,year:`numeric`});if(v===`week`){let e=y(x,D),n=new Date(e);return n.setDate(n.getDate()+6),`${e.toLocaleDateString(E,{month:`short`,day:`numeric`})} - ${n.toLocaleDateString(E,t?{month:`short`,day:`numeric`}:{month:`short`,day:`numeric`,year:`numeric`})}`}return x.toLocaleDateString(E,t?{weekday:`short`,month:`short`,day:`numeric`}:{weekday:`long`,month:`long`,day:`numeric`,year:`numeric`})},I=t.useRef(0);return(0,s.jsxs)(`div`,{role:`region`,"aria-label":C(`calendar.a11y.region`),className:(0,o.cn)(`flex flex-col h-full bg-background min-w-0 overflow-hidden`,_),children:[(0,s.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-2 p-2 sm:p-4 border-b min-w-0`,children:[(0,s.jsxs)(`div`,{className:`flex items-center gap-4 min-w-0 max-w-full`,children:[(0,s.jsxs)(`div`,{className:`flex shrink-0 items-center bg-muted/50 rounded-lg p-1 gap-1`,children:[(0,s.jsx)(o.Button,{variant:`ghost`,size:`sm`,onClick:M,className:`h-8`,"aria-label":C(`calendar.a11y.goToToday`),children:C(`calendar.today`)}),(0,s.jsx)(`div`,{className:`h-4 w-px bg-border mx-1`}),(0,s.jsx)(o.Button,{variant:`ghost`,size:`icon`,"aria-label":C(`calendar.a11y.previousPeriod`),onClick:A,className:`h-8 w-8`,children:(0,s.jsx)(a.ChevronLeftIcon,{className:`h-4 w-4`})}),(0,s.jsx)(o.Button,{variant:`ghost`,size:`icon`,"aria-label":C(`calendar.a11y.nextPeriod`),onClick:j,className:`h-8 w-8`,children:(0,s.jsx)(a.ChevronRightIcon,{className:`h-4 w-4`})})]}),(0,s.jsxs)(o.Popover,{children:[(0,s.jsx)(o.PopoverTrigger,{asChild:!0,children:(0,s.jsxs)(o.Button,{variant:`ghost`,"aria-label":C(`calendar.a11y.currentDate`,{date:F()}),title:F(),className:(0,o.cn)(`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 min-w-0 max-w-full`),children:[(0,s.jsx)(a.CalendarIcon,{className:`h-5 w-5 shrink-0 text-muted-foreground`}),(0,s.jsx)(`span`,{"data-date-label":`full`,className:`hidden min-w-0 truncate sm:block`,children:F()}),(0,s.jsx)(`span`,{"data-date-label":`short`,className:`min-w-0 truncate sm:hidden`,children:F(`short`)})]})}),(0,s.jsx)(o.PopoverContent,{className:`w-auto p-0`,align:`start`,children:(0,s.jsx)(o.Calendar,{localeTag:E,weekStartsOn:D,mode:`single`,defaultMonth:Number.isNaN(x.getTime())?void 0:x,selected:x,onSelect:e=>{e&&(S(e),f?.(e))},autoFocus:!0,startMonth:new Date(2e3,0),endMonth:new Date(2050,11)})})]})]}),(0,s.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,s.jsxs)(o.Select,{value:v,onValueChange:N,children:[(0,s.jsx)(o.SelectTrigger,{className:`w-32 bg-background`,children:(0,s.jsx)(o.SelectValue,{})}),(0,s.jsxs)(o.SelectContent,{children:[(0,s.jsx)(o.SelectItem,{value:`day`,children:C(`calendar.day`)}),(0,s.jsx)(o.SelectItem,{value:`week`,children:C(`calendar.week`)}),(0,s.jsx)(o.SelectItem,{value:`month`,children:C(`calendar.month`)})]})]}),p&&(0,s.jsxs)(o.Button,{onClick:p,size:`sm`,className:`gap-1`,children:[(0,s.jsx)(a.PlusIcon,{className:`h-4 w-4`}),C(`calendar.newEvent`)]})]})]}),(0,s.jsxs)(`div`,{className:`flex-1 overflow-auto`,onTouchStart:e=>{I.current=e.touches[0].clientX},onTouchEnd:e=>{let t=I.current-e.changedTouches[0].clientX;if(Math.abs(t)>50){let e=new Date(x);v===`day`?e.setDate(e.getDate()+(t>0?1:-1)):v===`week`?e.setDate(e.getDate()+(t>0?7:-7)):e.setMonth(e.getMonth()+(t>0?1:-1)),S(e),f?.(e)}},children:[v===`month`&&(0,s.jsx)(P,{date:x,events:e,locale:E,weekStart:D,onEventClick:l,onDateClick:u,onEventDrop:m}),v===`week`&&(0,s.jsx)(V,{mode:`week`,date:x,events:e,locale:E,weekStart:D,slotMinutes:g,onEventClick:l,onEventDrop:m,onTimeRangeSelect:h}),v===`day`&&(0,s.jsx)(V,{mode:`day`,date:x,events:e,locale:E,weekStart:D,slotMinutes:g,onEventClick:l,onEventDrop:m,onTimeRangeSelect:h})]})]})}function j(e,t){return e.getFullYear()===t.getFullYear()&&e.getMonth()===t.getMonth()&&e.getDate()===t.getDate()}function M(e,t){return(Date.UTC(t.getFullYear(),t.getMonth(),t.getDate())-Date.UTC(e.getFullYear(),e.getMonth(),e.getDate()))/864e5}function N(e,t){let n=new Date(e);return n.setDate(n.getDate()+t),n}function P({date:e,events:n,locale:r=`default`,weekStart:i,onEventClick:a,onDateClick:c,onEventDrop:l}){let u=t.useMemo(()=>b(e,i),[e.getFullYear(),e.getMonth(),i]),d=t.useMemo(()=>new Date,[]),{t:f}=k(),p=t.useMemo(()=>{let e=new Date(2024,0,7);return Array.from({length:7},(t,n)=>{let a=new Date(e);return a.setDate(a.getDate()+i+n),a.toLocaleDateString(r,{weekday:`short`})})},[r,i]),[m,h]=t.useState(null),[g,_]=t.useState(null),v=t.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 a=new Date(n);for(;a<=r;){let o=`${a.getFullYear()}-${a.getMonth()}-${a.getDate()}`,s=a.getTime()===n.getTime(),c=a.getTime()===r.getTime(),l=s||c||a.getDay()===i,u=e.get(o),d={event:t,isTitleDay:l,isSpanStart:s,isSpanEnd:c};u?u.push(d):e.set(o,[d]),a.setDate(a.getDate()+1)}}return e},[n,i]),y=(e,t,n=`move`,r)=>{h(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()},x=()=>{h(null),_(null)},S=(e,t)=>{e.preventDefault(),e.dataTransfer.dropEffect=`move`,_(t)},C=e=>{e.currentTarget.contains(e.relatedTarget)||_(null)},w=(e,t)=>{if(e.preventDefault(),_(null),h(null),!l)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 o=new Date(t);if(o.setHours(0,0,0,0),i.mode===`resize-end`){let e=a.end?new Date(a.end):new Date(a.start),t=M(e,o);if(t===0)return;let n=new Date(a.start);if(n.setHours(0,0,0,0),o.getTime()<n.getTime())return;l(a,new Date(a.start),N(e,t));return}let s=new Date(a.start),c;if(i.sourceDay){let[e,t,n]=i.sourceDay.split(`-`).map(e=>parseInt(e,10));c=new Date(e,t,n)}else c=s;let u=M(c,o);if(u===0)return;let d=N(s,u),f;a.end&&(f=N(new Date(a.end),u)),l(a,d,f)};return(0,s.jsxs)(`div`,{className:`flex flex-col h-full`,children:[(0,s.jsx)(`div`,{role:`row`,className:`grid grid-cols-7 border-b`,children:p.map(e=>(0,s.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,s.jsx)(`div`,{role:`grid`,"aria-label":f(`calendar.a11y.grid`),className:`grid grid-cols-7 flex-1 auto-rows-fr`,children:u.map((t,n)=>{let i=`${t.getFullYear()}-${t.getMonth()}-${t.getDate()}`,u=v.get(i)||[],p=t.getMonth()===e.getMonth(),h=j(t,d),_=t.toLocaleDateString(r,{weekday:`long`,month:`long`,day:`numeric`,year:`numeric`});return(0,s.jsxs)(`div`,{role:`gridcell`,"aria-label":u.length>0?f(`calendar.a11y.dayCell`,{date:_,count:u.length}):_,className:(0,o.cn)(`border-b border-r last:border-r-0 p-2 min-h-[100px] cursor-pointer hover:bg-accent/50`,!p&&`bg-muted/50 text-muted-foreground opacity-50`,g===n&&`ring-2 ring-primary`),onClick:()=>c?.(t),onDragOver:e=>S(e,n),onDragLeave:C,onDrop:e=>w(e,t),children:[(0,s.jsx)(`div`,{className:(0,o.cn)(`text-sm font-medium mb-2`,h&&`inline-flex items-center justify-center rounded-full bg-primary text-primary-foreground h-6 w-6`),...h?{"aria-current":`date`}:{},children:t.getDate()}),(0,s.jsxs)(`div`,{className:`space-y-0.5`,children:[u.slice(0,4).map(({event:e,isTitleDay:n,isSpanStart:r,isSpanEnd:i},c)=>{let u=!n,{className:d,inlineColor:p}=O(e.color),h=!!l&&i;return(0,s.jsxs)(`div`,{role:`button`,title:e.title,"aria-label":e.title,draggable:!!l,onDragStart:n=>y(n,e,`move`,t),onDragEnd:x,className:(0,o.cn)(`relative text-xs hover:opacity-80 truncate`,l?`cursor-move`:`cursor-pointer`,u?`h-1.5`:`px-2 py-0.5`,r?`rounded-l`:`rounded-l-none`,i?`rounded-r`:`rounded-r-none`,!i&&`-mr-2`,d,m===e.id&&`opacity-50`),style:p?{backgroundColor:p}:void 0,onClick:t=>{t.stopPropagation(),a?.(e)},children:[u?``:e.title,h&&(0,s.jsx)(`span`,{role:`separator`,"aria-label":f(`calendar.a11y.resizeEventEnd`),title:f(`calendar.a11y.resizeEventEndHint`),draggable:!0,onDragStart:n=>y(n,e,`resize-end`,t),onDragEnd:x,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,s.jsx)(`div`,{className:`text-xs text-muted-foreground px-2`,children:f(`calendar.moreEvents`,{count:u.length-4})})]})]},n)})})]})}var F=48;function I(e){let t=new Date(e);return t.setHours(0,0,0,0),t}function L(e){return e.getHours()*60+e.getMinutes()}function R(e){return`${e.getFullYear()}-${e.getMonth()}-${e.getDate()}`}function z(e,t){let n=new Date(e);return n.setHours(0,t,0,0),n}function ee(e){let t=new Date(e.start);return{start:t,end:e.end?new Date(e.end):new Date(t.getTime()+36e5)}}function B(e,t){let n=e.minutes-e.grabOffsetMs/6e4,r=Math.round(n/t)*t;return e.withinOneDay?Math.max(0,Math.min(1440-e.durationMs/6e4,r)):r}function te(e,t){return Math.round((I(t).getTime()-e.getTime())/864e5)*1440+L(t)}function ne(e,t,n){let r=new Date(e.keptMs),i=te(t,r);if(e.kind===`resize-top`){let a=Math.min(i-n,Math.max(0,e.minutes));return{start:z(t,a),end:r,startMin:a,endMin:i}}let a=Math.max(i+n,Math.min(1440,e.minutes));return{start:r,end:z(t,a),startMin:i,endMin:a}}function V({mode:e,date:n,events:r,locale:i=`default`,weekStart:a,slotMinutes:c=30,onEventClick:l,onEventDrop:u,onTimeRangeSelect:d}){let{t:f}=k(),p=F*c/60,m=1152,h=t.useMemo(()=>{if(e===`day`)return[I(n)];let t=y(n,a);return Array.from({length:7},(e,n)=>{let r=new Date(t);return r.setDate(t.getDate()+n),I(r)})},[e,n.getFullYear(),n.getMonth(),n.getDate(),a]),g=t.useMemo(()=>new Date,[]),_=t.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>=864e5)},[]),{allDayEvents:v,timedEvents:b}=t.useMemo(()=>{let e=[],t=[];for(let n of r)_(n)?e.push(n):t.push(n);return{allDayEvents:e,timedEvents:t}},[r,_]),x=t.useMemo(()=>{let e=new Map;for(let t of h)e.set(R(t),[]);for(let t of v){let n=I(new Date(t.start)),r=t.end?new Date(t.end):new Date(t.start),i=I(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 h){let a=I(r);a<n||a>i||e.get(R(r)).push({event:t,isStart:a.getTime()===n.getTime(),isEnd:a.getTime()===i.getTime()})}}return e},[h,v]),S=t.useMemo(()=>{let e=new Map;for(let t of h)e.set(R(t),[]);for(let t of b){let{start:n,end:r}=ee(t);for(let i of h){let a=I(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=L(s),u=c.getTime()===o.getTime()?1440:L(c);e.get(R(i)).push({event:t,startMin:l,endMin:Math.max(u,l+15),isStart:s.getTime()===n.getTime(),isEnd:c.getTime()===r.getTime()})}}return e},[h,b]),C=t.useMemo(()=>{let e=new Map;for(let[t,n]of S){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},[S]),w=t.useRef(null),T=t.useRef([]),[E,D]=t.useState(null),A=t.useRef(null);A.current=E;let M=t.useRef(!1),N=t.useCallback((e,t)=>{let n=T.current[t];if(!n)return 0;let r=(e-n.getBoundingClientRect().top+n.scrollTop)/F*60,i=Math.round(r/c)*c;return Math.max(0,Math.min(1440,i))},[c]),P=t.useCallback(e=>{for(let t=0;t<T.current.length;t++){let n=T.current[t];if(!n)continue;let r=n.getBoundingClientRect();if(e>=r.left&&e<=r.right)return t}return-1},[]);t.useEffect(()=>{if(!E)return;let e=e=>{let t=E.kind===`select`||E.kind===`move`?P(e.clientX):E.dayIndex,n=t<0?E.dayIndex??0:t,r=N(e.clientY,n);D(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=A.current;if(!t){D(null);return}try{if(t.kind===`select`&&d){let e=Math.min(t.anchorMinutes,t.headMinutes),n=Math.max(t.anchorMinutes,t.headMinutes),r=e,i=n===e?Math.min(1440,e+c):n,a=h[t.dayIndex]??h[0],o=new Date(a);o.setHours(0,Math.round(r),0,0);let s=new Date(a);s.setHours(0,Math.round(i),0,0),M.current=!0,d(o,s)}else if(t.kind===`move`&&u){let e=r.find(e=>String(e.id)===String(t.eventId));if(e){let n=t.dayIndex<0?0:t.dayIndex,r=z(h[n]??h[0],B(t,c)),i=new Date(r.getTime()+t.durationMs);M.current=!0,u(e,r,i)}}else if((t.kind===`resize-top`||t.kind===`resize-bottom`)&&u){let e=r.find(e=>String(e.id)===String(t.eventId));if(e){let{start:n,end:r}=ne(t,h[t.dayIndex]??h[0],c);M.current=!0,u(e,n,r)}}}finally{D(null),setTimeout(()=>{M.current=!1},50)}};return window.addEventListener(`pointermove`,e),window.addEventListener(`pointerup`,t),()=>{window.removeEventListener(`pointermove`,e),window.removeEventListener(`pointerup`,t)}},[E,h,r,c,u,d,P,N]);let te=t.useMemo(()=>h.map(e=>({weekday:e.toLocaleDateString(i,{weekday:`short`}),day:e.getDate(),month:e.toLocaleDateString(i,{month:`short`}),isToday:j(e,g)})),[h,i,g]),V=t.useMemo(()=>Array.from({length:24},(e,t)=>new Date(2024,0,1,t,0).toLocaleTimeString(i,{hour:`numeric`})),[i]),re=(e,t,n,r)=>{if(!u||e.button!==0)return;e.stopPropagation(),e.preventDefault();let i=N(e.clientY,n);if(r===`body`){let{start:e,end:r}=ee(t.event),a=r.getTime()-e.getTime(),o=z(h[n],i);D({kind:`move`,eventId:t.event.id,grabOffsetMs:Math.max(0,Math.min(a,o.getTime()-e.getTime())),durationMs:a,withinOneDay:t.isStart&&t.isEnd,dayIndex:n,minutes:i})}else{let{start:e,end:a}=ee(t.event);D({kind:r===`top`?`resize-top`:`resize-bottom`,eventId:t.event.id,keptMs:(r===`top`?a:e).getTime(),dayIndex:n,minutes:i})}},W=(e,t)=>{if(!d||e.button!==0)return;e.preventDefault();let n=N(e.clientY,t);D({kind:`select`,dayIndex:t,anchorMinutes:n,headMinutes:n})},ie=e=>{if(!E)return null;if(E.kind===`select`&&E.dayIndex===e){let t=Math.min(E.anchorMinutes,E.headMinutes),n=Math.max(E.anchorMinutes,E.headMinutes),r=t/60*F,a=Math.max(p,(n-t)/60*F);return(0,s.jsx)(`div`,{className:`absolute left-1 right-1 rounded bg-primary/30 border border-primary pointer-events-none z-10`,style:{top:r,height:a},"aria-hidden":!0,children:(0,s.jsx)(`div`,{className:`px-2 py-0.5 text-xs font-medium text-primary`,children:H(h[e],t,n,i)})})}if(E.kind===`move`&&E.dayIndex===e){let t=B(E,c),n=z(h[e],t),r=new Date(n.getTime()+E.durationMs),a=Math.max(0,t),o=Math.min(1440,t+Math.max(15,E.durationMs/6e4)),l=a/60*F,u=Math.max(0,(o-a)/60*F);return(0,s.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:l,height:u},"aria-hidden":!0,children:(0,s.jsx)(`div`,{className:`px-2 py-0.5 text-xs font-medium text-primary`,children:U(n,r,i)})})}if((E.kind===`resize-top`||E.kind===`resize-bottom`)&&E.dayIndex===e){let{start:t,end:n,startMin:r,endMin:a}=ne(E,h[e],c),o=Math.max(0,r),l=Math.min(1440,a),u=o/60*F,d=Math.max(0,(l-o)/60*F);return(0,s.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:u,height:d},"aria-hidden":!0,children:(0,s.jsx)(`div`,{className:`px-2 py-0.5 text-xs font-medium text-primary`,children:U(t,n,i)})})}return null};return(0,s.jsxs)(`div`,{className:`flex flex-col h-full`,ref:w,children:[(0,s.jsxs)(`div`,{className:`flex border-b sticky top-0 bg-background z-20`,children:[(0,s.jsx)(`div`,{className:`w-14 shrink-0 border-r`,"aria-hidden":!0}),te.map((e,t)=>(0,s.jsxs)(`div`,{role:`columnheader`,className:(0,o.cn)(`flex-1 p-2 text-center text-sm border-r last:border-r-0`,e.isToday&&`bg-primary/5`),children:[(0,s.jsx)(`div`,{className:`text-xs text-muted-foreground`,children:e.weekday}),(0,s.jsx)(`div`,{className:(0,o.cn)(`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})]},t))]}),v.length>0&&(0,s.jsxs)(`div`,{className:`flex border-b bg-muted/20 max-h-[140px] overflow-y-auto`,children:[(0,s.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:f(`calendar.allDay`)}),h.map(e=>{let t=R(e),n=x.get(t)??[];return(0,s.jsx)(`div`,{className:`flex-1 border-r last:border-r-0 min-h-[28px] p-0.5 space-y-0.5`,children:n.map(({event:e,isStart:t,isEnd:n},r)=>{let{className:i,inlineColor:a}=O(e.color);return(0,s.jsx)(`div`,{role:`button`,title:e.title,onClick:t=>{t.stopPropagation(),l?.(e)},className:(0,o.cn)(`text-[11px] px-2 py-0.5 truncate cursor-pointer hover:opacity-80`,t?`rounded-l`:`rounded-l-none -ml-0.5`,n?`rounded-r`:`rounded-r-none -mr-0.5`,i),style:a?{backgroundColor:a}:void 0,children:t?e.title:`\xA0`},`${e.id}-${r}`)})},t)})]}),(0,s.jsx)(`div`,{className:`flex-1 overflow-auto`,children:(0,s.jsxs)(`div`,{className:`flex`,style:{height:m},children:[(0,s.jsx)(`div`,{className:`w-14 shrink-0 border-r relative`,children:V.map((e,t)=>(0,s.jsx)(`div`,{className:`absolute right-1 text-[10px] text-muted-foreground -translate-y-1/2`,style:{top:t*F},children:t===0?``:e},t))}),h.map((e,t)=>{let n=R(e),r=C.get(n)??[];return(0,s.jsxs)(`div`,{ref:e=>{T.current[t]=e},className:`flex-1 border-r last:border-r-0 relative select-none`,style:{height:m},onPointerDown:e=>W(e,t),"aria-label":e.toLocaleDateString(i,{weekday:`long`,month:`long`,day:`numeric`,year:`numeric`}),children:[Array.from({length:24},(e,t)=>(0,s.jsx)(`div`,{className:`absolute left-0 right-0 border-t border-muted/60 pointer-events-none`,style:{top:t*F}},t)),c<60&&Array.from({length:Math.floor(1440/c)},(e,t)=>{let n=t*c;return n%60==0?null:(0,s.jsx)(`div`,{className:`absolute left-0 right-0 border-t border-dashed border-muted/30 pointer-events-none`,style:{top:n/60*F}},t)}),r.map(n=>{let r=n.startMin/60*F,a=Math.max(p,(n.endMin-n.startMin)/60*F),c=100/n.cols,d=n.col*c,{className:m,inlineColor:h}=O(n.event.color),g=E&&E.eventId===n.event.id;return(0,s.jsxs)(`div`,{role:`button`,tabIndex:0,title:n.event.title,"aria-label":n.event.title,onPointerDown:e=>re(e,n,t,`body`),onClick:e=>{if(M.current){e.stopPropagation();return}e.stopPropagation(),l?.(n.event)},className:(0,o.cn)(`absolute rounded text-xs px-2 py-1 overflow-hidden shadow-sm`,u?`cursor-move`:`cursor-pointer`,m,g&&`opacity-40`),style:{top:r,height:a,left:`calc(${d}% + 2px)`,width:`calc(${c}% - 4px)`,...h?{backgroundColor:h}:{}},children:[(0,s.jsx)(`div`,{className:`font-medium truncate`,children:n.event.title}),(0,s.jsx)(`div`,{className:`text-[10px] opacity-80 truncate`,children:H(e,n.startMin,n.endMin,i)}),u&&n.isStart&&(0,s.jsx)(`div`,{onPointerDown:e=>re(e,n,t,`top`),className:`absolute top-0 left-0 right-0 h-1.5 cursor-ns-resize`,"aria-label":f(`calendar.a11y.resizeStart`)}),u&&n.isEnd&&(0,s.jsx)(`div`,{onPointerDown:e=>re(e,n,t,`bottom`),className:`absolute bottom-0 left-0 right-0 h-1.5 cursor-ns-resize`,"aria-label":f(`calendar.a11y.resizeEnd`)})]},`${n.event.id}-${n.startMin}`)}),ie(t)]},n)})]})})]})}function H(e,t,n,r){return U(z(e,Math.round(t)),z(e,Math.round(n)),r)}function U(e,t,n){let r=e=>e.toLocaleTimeString(n,{hour:`numeric`,minute:`2-digit`});return`${r(e)} – ${r(t)}`}function re(e){return e.calendar?e.calendar:e.startDateField?{startDateField:e.startDateField,endDateField:e.endDateField,titleField:e.titleField,colorField:e.colorField,allDayField:e.allDayField}:null}function W(e,t,r){return ie(t,r)?(0,n.toDateInputValue)(e):e.toISOString()}function ie(e,t){return typeof e==`string`?e===`date`:typeof t==`string`&&(0,n.isRealCalendarDate)(t)}function ae(e,t,n,r){let i={[e.startDateField]:W(n,t?.[e.startDateField]?.type,void 0)};return e.endDateField&&(i[e.endDateField]=W(r??n,t?.[e.endDateField]?.type,void 0)),i}function oe(e){return!e||typeof e!=`object`?[]:Array.isArray(e)?e.map(e=>[e.name??e.apiName??``,e]):Object.entries(e)}function se(e){if(e.defaultValue!==void 0&&e.defaultValue!==null)return{value:e.defaultValue};let t=e.type;if(t===`select`||t===`picklist`||t===`status`){let t=(e.options||e.choices||[])[0];if(t===void 0)return;if(typeof t!=`object`||!t)return{value:t};let n=t;return{value:n.value??n.id}}if(t===`boolean`||t===`checkbox`)return{value:!1};if(t===`number`||t===`integer`||t===`decimal`||t===`currency`||t===`percent`)return{value:0}}function ce(e,t){let n=[];for(let[r,i]of oe(e))r&&!t.has(r)&&i?.required&&i.readonly!==!0&&i.system!==!0&&i.type!==`autonumber`&&(se(i)||n.push(r));return n}var le=({schema:e,dataSource:d,className:f,data:p,loading:m,onEventClick:h,onRowClick:g,onDateClick:_,onEdit:v,onNavigate:y,onViewChange:b,onVisibleRangeChange:x,onEventDrop:C,locale:w})=>{let T=(0,r.useSafeTranslate)(),{t:E}=(0,r.useObjectTranslation)(),D=(0,i.useDisplayLocale)(),O=w!==void 0&&w!=="default"?w:D,k=Array.isArray(p),[j,M]=(0,t.useState)(k?p:[]),[N,P]=(0,t.useState)(k?m??!1:!0),[F,I]=(0,t.useState)(null),[L,R]=(0,t.useState)(null),[z,ee]=(0,t.useState)(new Date),[B,te]=(0,t.useState)(!1),ne=(0,o.useIsMobile)(),V=e.defaultView,[H,U]=(0,t.useState)(()=>{let e=V===`day`||!V;return typeof window<`u`&&window.innerWidth<768&&e?`month`:V||`month`});(0,t.useEffect)(()=>{ne&&H===`day`&&(V===`day`||!V)&&U(`month`)},[ne]);let ie=S(z,H,(0,i.firstDayOfWeek)(O)),le=ie.start.getTime(),ue=ie.end.getTime(),de=(0,t.useRef)(x);(0,t.useEffect)(()=>{de.current=x}),(0,t.useEffect)(()=>{de.current?.({start:new Date(le),end:new Date(ue)})},[le,ue]);let[fe,pe]=(0,t.useState)(0);(0,t.useEffect)(()=>{if(!k&&d?.onMutation&&e.objectName)return d.onMutation(t=>{t.resource===e.objectName&&pe(e=>e+1)})},[d,e.objectName,k]);let me=(0,t.useCallback)(async()=>{pe(e=>e+1)},[]),{ref:he,isRefreshing:ge,pullDistance:_e}=(0,c.usePullToRefresh)({onRefresh:me,enabled:!!d&&!!e.objectName}),G=(0,t.useMemo)(()=>(0,n.resolveRecordSourceConfig)({objectName:e.objectName,data:e.data,staticData:e.staticData},`array`),[e.data,e.staticData,e.objectName]),K=(0,t.useMemo)(()=>re(e),[e.calendar,e.startDateField,e.endDateField,e.titleField,e.colorField,e.allDayField]),ve=G?.provider===`value`,q=G?.provider,ye=G?.provider===`value`?G.items:void 0,J=(0,n.resolveRecordSourceObjectName)(e,G),{ready:be,def:Y}=(0,r.useSettledSchema)(J??``,ve?void 0:d),X=(0,u.usePermissions)();(0,t.useEffect)(()=>{k&&(M(p),R(null),I(null))},[p,k]),(0,t.useEffect)(()=>{k&&m!==void 0&&P(m)},[m,k]);let xe=(0,r.useDataInvalidation)(!k&&q===`object`&&J||void 0),Se=(0,r.useFilterScope)(),Ce=(0,r.useResolvedFilter)(e.filter,Se);(0,t.useEffect)(()=>{if(k||q===`object`&&!be)return;let t=!0;return(async()=>{try{if(!t)return;if(P(!0),ve&&q===`value`){let r=await new n.ValueDataSource({items:ye??[]}).find(``,{$filter:Ce,$orderby:(0,n.convertSortToQueryParams)(e.sort),...(0,n.nonGridRowCeilingQuery)()}),i=(0,n.applyNonGridRowCeiling)(r);t&&(M(i.rows),R(i),I(null),P(!1));return}if(!d||typeof d.find!=`function`)throw Error(`DataSource required for the object provider`);if(q===`object`){let r=J,i=(0,n.buildExpandFields)(Y?.fields),a=X?.isLoaded?i.filter(e=>X.checkField(r,e,`read`)):i,o=await d.find(r,{$filter:Ce,$orderby:(0,n.convertSortToQueryParams)(e.sort),...(0,n.nonGridRowCeilingQuery)(),...a.length>0?{$expand:a}:{}}),s=(0,n.applyNonGridRowCeiling)(o);t&&(M(s.rows),R(s),I(null))}t&&P(!1)}catch(e){console.error(`[ObjectCalendar] Error fetching data:`,e),t&&(I(e),P(!1))}})(),()=>{t=!1}},[k,q,J,ye,d,ve,Ce,e.sort,fe,be,Y,X,xe]);let{events:we,unscheduledRecords:Te}=(0,t.useMemo)(()=>{if(!K||!j.length)return{events:[],unscheduledRecords:[]};let{startDateField:e,endDateField:t,titleField:r,colorField:i,allDayField:a}=K,o=(0,n.createFieldColorResolver)(Y?.fields?.[i??``]),s=e=>{if(r){let t=e[r],n=typeof t==`string`?t.trim():t;if(n)return String(n)}return(0,n.getRecordDisplayName)(Y,e)},c=[],l=[];return j.forEach((r,u)=>{let d=r[e],f=t?r[t]:null,p=s(r),m=i?r[i]:void 0,h=o(m)??m,g=r.id||r._id||`event-${u}`;if(!d){l.push({id:g,title:p});return}let _=(0,n.toDisplayDate)(d);isNaN(_.getTime())||c.push({id:g,title:p,start:_,end:f?(0,n.toDisplayDate)(f):void 0,color:h,allDay:a?!!r[a]:!f,data:r})}),{events:c,unscheduledRecords:l}},[j,K,Y]);(0,t.useCallback)(()=>{_?.(new Date)},[_]);let Ee=e.navigation??{mode:`drawer`},De=Ee.mode===`drawer`||Ee.mode===`modal`||Ee.mode===`split`||Ee.mode===`popover`,Z=(0,r.useNavigationOverlay)({navigation:Ee,objectName:J??e.objectName,onRowClick:De?void 0:g}),{anchorRef:Oe,anchorCaptureProps:ke}=(0,o.useOverlayAnchor)(),Ae={objectSchema:J===e.objectName?Y:null,objectName:e.objectName,perms:X},je=(0,n.resolveAffordance)(`calendarQuickCreate`,Ae).allowed,Me=(0,n.resolveAffordance)(`calendarReschedule`,Ae).allowed,Ne=(0,t.useCallback)(async(t,n,i)=>{if(!K)return;let{startDateField:a,endDateField:s}=K,c=t?.id??t?._id;if(!c||!e.objectName||!d?.update)return;let l=Y?.fields,u={[a]:W(n,l?.[a]?.type,t?.[a])};s&&i&&(u[s]=W(i,l?.[s]?.type,t?.[s]));let f=j;M(e=>e.map(e=>(e?.id??e?._id)===c?{...e,...u}:e));try{await d.update(e.objectName,c,u)}catch(e){M(f),console.error(`[ObjectCalendar] Failed to persist drag-and-drop reschedule:`,e),o.toast.error((0,r.declaredUserMessage)(e)??((0,r.isPermissionError)(e)?T(`errors.unauthorized`,`You are not authorized to perform this action.`):(0,r.extractWriteErrorMessage)(e)??T(`table.saveFailed`,`Save failed`)))}},[K,e.objectName,d,j,T,Y]),[Q,$]=(0,t.useState)(null),Pe=T(`calendar.titleRequired`,`Title is required`),Fe=(0,t.useCallback)(t=>{K&&e.objectName&&d?.create&&$({start:t,title:``,submitting:!1})},[K,e.objectName,d]),Ie=(0,t.useCallback)((t,n)=>{K&&e.objectName&&d?.create&&$({start:t,end:n,title:``,submitting:!1})},[K,e.objectName,d]),Le=(K?ce(Y?.fields,new Set([K.titleField||`name`,K.startDateField,K.endDateField].filter(e=>!!e))):[]).length===0,Re=(0,t.useCallback)((t,n)=>{if(!K||!e.objectName||!v)return;let r=Y?.fields;v(ae(K,r,t,n))},[K,e.objectName,v,Y]),ze=v?Re:void 0,Be=je?Le?Fe:ze:void 0,Ve=je?Le?Ie:ze:void 0,He=(0,t.useCallback)(async()=>{if(!Q||!K)return;let t=Q.title.trim();if(!t){$(e=>e&&{...e,error:Pe});return}if(!e.objectName||!d?.create)return;$(e=>e&&{...e,submitting:!0,error:void 0});let{titleField:n}=K,r=Y?.fields,i={[n||`name`]:t,...ae(K,r,Q.start,Q.end)};for(let[e,t]of oe(Y?.fields)){if(!e||e in i||!t?.required)continue;let n=se(t);n&&(i[e]=n.value)}try{let t=await d.create(e.objectName,i),n=(t&&(t.record||t.data||t))??null;n&&(n.id!==void 0||n._id!==void 0)&&M(e=>[...e,n]),$(null)}catch(e){let t=e?.message||String(e);$(e=>e&&{...e,submitting:!1,error:t}),console.error(`[ObjectCalendar] Quick-create failed:`,e)}},[Q,K,e.objectName,d,Y,Pe]);if(N)return(0,s.jsx)(`div`,{className:f,children:(0,s.jsx)(`div`,{className:`flex items-center justify-center h-96`,children:(0,s.jsx)(`div`,{className:`text-muted-foreground`,children:T(`calendar.loading`,`Loading calendar…`)})})});if(F)return(0,s.jsx)(`div`,{className:f,children:(0,s.jsx)(`div`,{className:`flex items-center justify-center h-96`,children:(0,s.jsx)(`div`,{className:`text-destructive`,children:E(`calendar.loadError`,{message:F.message,defaultValue:`Error: {{message}}`})})})});if(!K)return(0,s.jsx)(`div`,{className:f,children:(0,s.jsx)(`div`,{className:`flex items-center justify-center h-96`,children:(0,s.jsxs)(`div`,{className:`text-muted-foreground max-w-md text-center space-y-2`,children:[(0,s.jsx)(`p`,{children:T(`calendar.configRequired`,`Calendar configuration required. Please specify startDateField, the calendar's one required key; the event title resolves without titleField.`)}),(0,s.jsx)(`p`,{className:`text-sm`,children:T(`calendar.configRequiredHint`,`It belongs on the view's calendar block. An interface page has no calendar slot of its own: point its sourceView at a view that declares one.`)})]})})});let Ue=t=>{if(!Z.isOverlay||!Z.isOpen||!Z.selectedRecord)return null;let r=(0,n.resolveRecordSourceObjectName)(e,G),i=Z.selectedRecord,a=i.id??i._id;if(!r||a==null)return null;let c=T(`calendar.eventDetails`,`Event Details`),u=K?.titleField?String(i[K.titleField]??c):c;return(0,s.jsx)(o.NavigationOverlay,{...Z,title:u,mainContent:t,popoverAnchorRef:Oe,storageKey:(0,o.recordOverlayWidthStorageKey)(r),legacyStorageKey:(0,o.legacyRecordDrawerWidthKey)(r),width:Z.width??l.RECORD_OVERLAY_DEFAULT_WIDTH,children:()=>(0,s.jsx)(`div`,{className:`px-6 pt-6 pb-6`,children:(0,s.jsx)(l.RecordDetailPanel,{record:i,objectName:r,recordId:a,dataSource:d,objectSchema:Y,onClose:Z.close,fullPageHref:(0,l.deriveRecordPageHref)(r,a)??void 0,onFieldSave:async(e,t)=>{d?.update&&(await d.update(r,String(a),{[e]:t}),M(n=>n.map(n=>String(n.id??n._id)===String(a)?{...n,[e]:t}:n)))},onDelete:async()=>{d?.delete&&(await d.delete(r,String(a)),M(e=>e.filter(e=>String(e.id??e._id)!==String(a))))}})})})},We=(0,s.jsxs)(`div`,{ref:he,className:f,...ke,children:[_e>0&&(0,s.jsx)(`div`,{className:`flex items-center justify-center text-xs text-muted-foreground`,style:{height:_e},children:ge?T(`calendar.refreshing`,`Refreshing…`):T(`calendar.pullToRefresh`,`Pull to refresh`)}),(0,s.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,s.jsx)(A,{events:we,currentDate:z,view:H,locale:w,onEventClick:e=>{Z.handleClick(e.data),De||h?.(e.data)},onDateClick:_??Be,onNavigate:e=>{ee(e),y?.(e)},onViewChange:e=>{U(e),b?.(e)},onAddClick:void 0,onEventDrop:C?(e,t,n)=>C(e.data,t,n):Me?(e,t,n)=>{Ne(e.data,t,n)}:void 0,onTimeRangeSelect:Ve})}),L&&(0,s.jsx)(r.NonGridRowCeilingNote,{result:L}),Te.length>0&&(0,s.jsxs)(`div`,{className:`mt-2 border-t pt-2`,"data-calendar-unscheduled":``,children:[(0,s.jsxs)(`button`,{type:`button`,className:`flex items-center gap-1 text-sm text-muted-foreground hover:text-foreground`,"aria-expanded":B,onClick:()=>te(e=>!e),children:[(0,s.jsx)(a.ChevronRight,{"aria-hidden":`true`,className:(0,o.cn)(`h-4 w-4 transition-transform`,B&&`rotate-90`)}),E(`calendar.unscheduled`,{count:Te.length,defaultValue:`Unscheduled ({{count}})`})]}),B&&(0,s.jsx)(`ul`,{className:`mt-1 space-y-1 pl-6`,"data-calendar-unscheduled-list":``,children:Te.map(e=>(0,s.jsx)(`li`,{className:`truncate text-sm`,children:e.title},e.id))})]}),(0,s.jsx)(o.Dialog,{open:!!Q,onOpenChange:e=>{e||$(null)},children:(0,s.jsxs)(o.DialogContent,{className:`sm:max-w-md`,children:[(0,s.jsxs)(o.DialogHeader,{children:[(0,s.jsx)(o.DialogTitle,{children:T(`calendar.newEvent`,`New event`)}),(0,s.jsx)(o.DialogDescription,{children:Q&&(()=>{let e=Q.end&&Q.end.getTime()!==Q.start.getTime(),t=Q.start.toLocaleDateString(O,{year:`numeric`,month:`long`,day:`numeric`});if(e){let e=e=>e.toLocaleTimeString(O,{hour:`numeric`,minute:`2-digit`});return(0,s.jsxs)(s.Fragment,{children:[t,` · `,e(Q.start),` – `,e(Q.end)]})}return(0,s.jsx)(s.Fragment,{children:E(`calendar.onDate`,{date:t,defaultValue:`On {{date}}`})})})()})]}),(0,s.jsxs)(`div`,{className:`space-y-2`,children:[(0,s.jsx)(o.Label,{htmlFor:`quick-create-title`,children:T(`calendar.eventTitle`,`Title`)}),(0,s.jsx)(o.Input,{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(),He())},placeholder:T(`calendar.eventTitlePlaceholder`,`What's this event about?`),disabled:Q?.submitting}),Q?.error&&(0,s.jsx)(`p`,{className:`text-sm text-destructive`,children:Q.error})]}),(0,s.jsxs)(o.DialogFooter,{children:[(0,s.jsx)(o.Button,{variant:`outline`,onClick:()=>$(null),disabled:Q?.submitting,children:T(`common.cancel`,`Cancel`)}),(0,s.jsx)(o.Button,{onClick:()=>void He(),disabled:Q?.submitting||!Q?.title.trim(),children:Q?.submitting?T(`calendar.creating`,`Creating…`):T(`common.create`,`Create`)})]})]})})]});if(Z.isOverlay&&Z.mode===`split`&&Z.isOpen&&Z.selectedRecord){let e=Ue(We);if(e)return(0,s.jsx)(s.Fragment,{children:e})}return(0,s.jsxs)(s.Fragment,{children:[We,Ue()]})},ue=[`onEventClick`,`onDateClick`,`onViewChange`,`onNavigate`,`onAddClick`,`onEventDrop`,`onTimeRangeSelect`];function de(e){let t={};for(let n of ue){let r=e[n];typeof r==`function`&&(t[n]=r)}return t}var fe=[`month`,`week`,`day`];function pe(e){return fe.includes(e)?e:void 0}function me(e){if(typeof e==`string`){try{Intl.getCanonicalLocales(e)}catch{return}return e}}function he(e){return typeof e==`number`&&Number.isFinite(e)&&e>0?e:void 0}function ge(e){if(e instanceof Date)return e;if(typeof e!=`string`)return;let t=(0,n.toDisplayDate)(e);return Number.isNaN(t.getTime())?void 0:t}function _e(e){return e===!0}n.ComponentRegistry.register(`calendar-view`,({schema:e,className:r,onAction:i,events:a,currentDate:o,view:c,allowCreate:l,...u})=>{let d=t.default.useMemo(()=>!e.data||!Array.isArray(e.data)?[]:e.data.map((t,r)=>{let i=e.titleField||`title`,a=e.startDateField||`start`,o=e.endDateField||`end`,s=e.colorField||`color`,c=e.allDayField||`allDay`;return{id:t.id||t._id||r,title:t[i]||`Untitled Event`,start:(0,n.toDisplayDate)(t[a]),end:t[o]?(0,n.toDisplayDate)(t[o]):void 0,allDay:t[c],color:t[s],data:t}}),[e.data,e.titleField,e.startDateField,e.endDateField,e.colorField,e.allDayField]),f=t.default.useMemo(()=>ge(o),[o]),p=pe(c),m=_e(l),h=de(u),g=me(u.locale),_=he(u.slotMinutes),v=typeof i==`function`?i:void 0,y=e=>{v?.({type:`event-click`,payload:e})},b=()=>{v?.({type:`create`,payload:{}})};return(0,s.jsx)(A,{className:r,events:d,currentDate:f,view:p,locale:g,slotMinutes:_,...h,onEventClick:h.onEventClick??y,onAddClick:h.onAddClick??(m?b:void 0)})},{namespace:`plugin-calendar`,label:`Calendar View`,inputs:[{name:`data`,type:`array`,description:`Array of record objects to display as events`},{name:`titleField`,type:`string`,description:`Field name to use for event title`},{name:`startDateField`,type:`string`,description:`Field name for event start date`},{name:`endDateField`,type:`string`,description:`Field name for event end date (optional)`},{name:`allDayField`,type:`string`,description:`Field name for all-day flag`},{name:`colorField`,type:`string`,description:`Field name for event color`},{name:`view`,type:`enum`,enum:[`month`,`week`,`day`],description:`Calendar view mode (month, week, or day)`},{name:`currentDate`,type:`string`,description:`ISO date string for initial calendar date`},{name:`allowCreate`,type:`boolean`,description:`Allow creating events by clicking on dates`},{name:`className`,type:`string`}],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 G={filter:!0,sort:!0},K=[`onEventClick`,`onRowClick`,`onDateClick`,`onEdit`,`onDelete`,`onNavigate`,`onViewChange`,`onVisibleRangeChange`,`onEventDrop`];function ve(e){let t={};for(let n of K){let r=e[n];typeof r==`function`&&(t[n]=r)}return t}function q(e){if(typeof e==`string`){try{Intl.getCanonicalLocales(e)}catch{return}return e}}function ye(e){return Array.isArray(e)?e:void 0}function J(e){return typeof e==`boolean`?e:void 0}function be(e){return e&&typeof e.find==`function`?e:void 0}var Y=(0,n.elementDataSourceBlock)(({schema:e,className:t,...n})=>{let{dataSource:a}=(0,r.useSchemaContext)()||{},o=a??void 0,c=ve(n),l=q(n.locale),u=ye(n.data),d=J(n.loading),f=be(n.dataSource),{t:p}=(0,i.useObjectTranslation)();return(0,s.jsx)(r.ElementDataSourceGate,{schema:e,mapping:G,dataSource:o,testId:`object-calendar`,errorTitle:p(`element.calendar.sourceUnresolved`,{defaultValue:`This calendar’s data source could not be resolved`}),children:e=>(0,s.jsx)(le,{schema:e,dataSource:f??o,className:t,data:u,loading:d,locale:l,...c})})}),X=[{name:`objectName`,type:`string`,description:"ObjectQL object name. The record source is one of `data`, `staticData` and `objectName`; the `object-calendar` schema refuses a block that declares none of them, unless the node's `dataSource.object` names the object, which then lands on this key."},{name:`calendar`,type:`object`,description:`startDateField, endDateField, titleField, colorField`},{name:`filter`,type:`array`,description:"Base query filter — the `ViewFilterRule` array `[{ field, operator, value }, ...]`, narrowing the records the calendar fetches. Lowered to `$filter` on the query."},{name:`sort`,type:`array`,description:"Sort order in `[{ field, order }]` form, ordering the records the calendar fetches. Lowered to `$orderby` on the query."},{name:`defaultView`,type:`enum`,enum:[`month`,`week`,`day`],description:"The grid the calendar opens on. A narrow viewport downgrades `day` to `month`; the author’s choice is otherwise honoured on first render."},{name:`locale`,type:`string`,description:"BCP-47 tag used to format the dates and times this calendar renders. A tag `Intl` refuses is dropped — the same answer as an absent key — rather than passed through to throw out of render."},{name:`data`,type:`array`,description:"Pre-fetched records drawn as-is, IN PLACE OF the calendar’s own query — `objectName`, `filter` and `sort` are then unused and `staticData` is never reached. Each member is a RECORD, read for the fields the `calendar` config names plus its `id`; a member with no value in the start field is counted in the unscheduled area rather than dropped."},{name:`staticData`,type:`array`,description:"Inline records, read SECOND on the record-source ladder: an authored `data` wins and this key is then never reached, while `objectName` is read AFTER it, so a calendar carrying both draws these rows and issues no query. Members are records read exactly as `data`’s are."},{name:`loading`,type:`boolean`,description:"External loading state, honoured ONLY alongside an array `data`: it then replaces the calendar with its loading placeholder. On a calendar fed by `staticData` or by `objectName` it is dropped, because that calendar owns its own loading state."},{name:`navigation`,type:`object`,description:"What an event click opens — the `{ mode, size, openNewTab, preventNavigation }` block a list view declares. With the key ABSENT a click opens the record in a drawer. `mode` is an overlay (`drawer`, `modal`, `split`, `popover`), `new_window`, `page` or `none`, and a block written without `mode` takes the spec’s `page` default. `page` opens the record page through the record navigator the host publishes (the console publishes one on its custom pages, record pages and list views); under a host that publishes none, such as an embedded renderer, there is no record page to open and the click opens nothing. `openNewTab: true` opens the record page in a new tab and outranks every mode except `none`, `preventNavigation: true` opens nothing, and `size` sets the overlay width. An overlay mode wins over a parent view’s click handler; any other mode hands the click to it."}];n.ComponentRegistry.register(`object-calendar`,Y,{namespace:`plugin-calendar`,label:`Object Calendar`,category:`view`,inputs:[...X]}),n.ComponentRegistry.register(`calendar`,Y,{namespace:`view`,label:`Calendar View`,category:`view`,inputs:[...X]}),e.CalendarView=A,e.ObjectCalendar=le,e.ObjectCalendarRenderer=Y});
@@ -0,0 +1,19 @@
1
+ import { WeekdayIndex } from '@object-ui/i18n';
2
+ /** `date` moved back, on the local calendar, to the first day of its week. */
3
+ export declare function getWeekStart(date: Date, weekStart: WeekdayIndex): Date;
4
+ export declare function getMonthDays(date: Date, weekStart: WeekdayIndex): Date[];
5
+ /**
6
+ * The days a calendar showing `date` in `view` draws, as a half-open range of
7
+ * local midnights: `start` is the first day on screen and `end` the day after
8
+ * the last (objectui#12081).
9
+ *
10
+ * Read off the SAME helpers the three grids draw with — `getMonthDays` for the
11
+ * month grid (its leading and trailing days included), `getWeekStart` for the
12
+ * week columns, the day itself for the day column — so the range a host fetches
13
+ * for is the range drawn, under the locale's first day of the week.
14
+ */
15
+ export declare function getVisibleDateRange(date: Date, view: "month" | "week" | "day", weekStart: WeekdayIndex): {
16
+ start: Date;
17
+ end: Date;
18
+ };
19
+ //# sourceMappingURL=visibleDays.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"visibleDays.d.ts","sourceRoot":"","sources":["../src/visibleDays.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH;;;;;;;;;GASG;AAEH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAA;AAUnD,8EAA8E;AAC9E,wBAAgB,YAAY,CAAC,IAAI,EAAE,IAAI,EAAE,SAAS,EAAE,YAAY,GAAG,IAAI,CAItE;AAED,wBAAgB,YAAY,CAAC,IAAI,EAAE,IAAI,EAAE,SAAS,EAAE,YAAY,GAAG,IAAI,EAAE,CA+BxE;AAOD;;;;;;;;;GASG;AACH,wBAAgB,mBAAmB,CACjC,IAAI,EAAE,IAAI,EACV,IAAI,EAAE,OAAO,GAAG,MAAM,GAAG,KAAK,EAC9B,SAAS,EAAE,YAAY,GACtB;IAAE,KAAK,EAAE,IAAI,CAAC;IAAC,GAAG,EAAE,IAAI,CAAA;CAAE,CAO5B"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@object-ui/plugin-calendar",
3
- "version": "17.6.0",
3
+ "version": "18.0.0",
4
4
  "type": "module",
5
5
  "license": "MIT",
6
6
  "description": "Calendar view plugins for Object UI - includes both ObjectQL-integrated and standalone calendar components",
@@ -24,15 +24,15 @@
24
24
  }
25
25
  },
26
26
  "dependencies": {
27
- "lucide-react": "^1.31.0",
28
- "@object-ui/components": "17.6.0",
29
- "@object-ui/core": "17.6.0",
30
- "@object-ui/fields": "17.6.0",
31
- "@object-ui/i18n": "17.6.0",
32
- "@object-ui/mobile": "17.6.0",
33
- "@object-ui/plugin-detail": "17.6.0",
34
- "@object-ui/react": "17.6.0",
35
- "@object-ui/types": "17.6.0"
27
+ "lucide-react": "^1.43.0",
28
+ "@object-ui/core": "18.0.0",
29
+ "@object-ui/i18n": "18.0.0",
30
+ "@object-ui/components": "18.0.0",
31
+ "@object-ui/mobile": "18.0.0",
32
+ "@object-ui/permissions": "18.0.0",
33
+ "@object-ui/plugin-detail": "18.0.0",
34
+ "@object-ui/react": "18.0.0",
35
+ "@object-ui/types": "18.0.0"
36
36
  },
37
37
  "peerDependencies": {
38
38
  "react": "^18.0.0 || ^19.0.0",
@@ -45,7 +45,9 @@
45
45
  "typescript": "^6.0.3",
46
46
  "vite": "^8.2.1",
47
47
  "vite-plugin-dts": "^5.0.3",
48
- "@object-ui/data-objectstack": "17.6.0"
48
+ "@object-ui/test-support": "17.4.0",
49
+ "@object-ui/data-objectstack": "18.0.0",
50
+ "@object-ui/sdui-parser": "18.0.0"
49
51
  },
50
52
  "keywords": [
51
53
  "objectui",
@@ -72,8 +74,8 @@
72
74
  ],
73
75
  "scripts": {
74
76
  "build": "vite build",
75
- "test": "vitest run",
76
- "test:watch": "vitest",
77
+ "test": "vitest run --root ../.. packages/plugin-calendar/",
78
+ "test:watch": "vitest --root ../.. packages/plugin-calendar/",
77
79
  "type-check": "tsc --noEmit && tsc -p tsconfig.test.json",
78
80
  "lint": "eslint ."
79
81
  }