@progress/kendo-react-scheduler
Version:
React Scheduler brings the functionality of Outlook's Calendar to a single UI component. KendoReact Scheduler package
9 lines (8 loc) • 6.64 kB
JavaScript
/**
* @license
*-------------------------------------------------------------------------------------------
* Copyright © 2026 Progress Software Corporation. All rights reserved.
* Licensed under commercial license. See LICENSE.md in the package root for more information
*-------------------------------------------------------------------------------------------
*/
;Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const ue=require("react"),de=require("./SchedulerItem.js"),b=require("../utils/index.js"),P=require("../views/common/utils.js"),R=require("../constants/index.js"),me=require("@progress/kendo-react-intl"),G=require("./SchedulerItemContent.js"),O=require("@progress/kendo-react-common"),z=require("@progress/kendo-svg-icons"),fe=require("../hooks/useRowSync.js"),ge=require("../hooks/useEditable.js"),K=require("../context/SchedulerViewContext.js"),he=require("../context/SchedulerContext.js");function Ie(e){const v=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e){for(const S in e)if(S!=="default"){const E=Object.getOwnPropertyDescriptor(e,S);Object.defineProperty(v,S,E.get?E:{enumerable:!0,get:()=>e[S]})}}return v.default=e,Object.freeze(v)}const i=Ie(ue),U=1,J=25,Q=i.forwardRef((e,v)=>{const{item:S,_ref:E,itemRef:Z,...p}=e,x=i.useRef(void 0),d=i.useRef(null),C=i.useRef(null),M=i.useRef(null),ee=ge.useEditable(e.editable);i.useImperativeHandle(C,()=>({props:e,element:d.current&&d.current.element})),i.useImperativeHandle(v,()=>C.current),i.useImperativeHandle(E,()=>d.current),i.useImperativeHandle(Z,()=>d.current);const te=S||X.item,k=me.useInternationalization(),[ne]=K.useSchedulerViewItemsContext(),[re]=K.useSchedulerViewSlotsContext(),H=he.useSchedulerElementContext(),[ie,_]=i.useState(!0),[ce,se]=i.useState(!1),f=i.useRef(e.order),F=i.useRef(0),V=O.useDir(H),W=i.useMemo(()=>{var t,n;return e.isAllDay?(t=e.title)!=null?t:"":`(${k.format("{0:t} - {1:t}",e.zonedStart,e.zonedEnd)}): ${(n=e.title)!=null?n:""}`},[k,e.isAllDay,e.title,e.zonedEnd,e.zonedStart]),B=(t,n)=>{let u=1;return t.forEach(c=>{const a=n.filter(m=>T(c.current.props,m.props));a.length>u&&(u=a.length)}),u},le=(t,n)=>t.map(c=>n.filter(a=>T(c.current.props,a.props))),oe=(t,n)=>{var A;const u=n.filter(r=>r.props.order!==null&&r.props.order!==void 0).map(r=>{let s=r.props.start,l=r.props.end;if(r.props.isAllDay){s=new Date(s.getFullYear(),s.getMonth(),s.getDate());const g=new Date(l.getFullYear(),l.getMonth(),l.getDate());l=g.getTime()<=s.getTime()?new Date(s.getFullYear(),s.getMonth(),s.getDate()+1):g}return{order:r.props.order,start:s,end:l}}),c=Array.from(new Set(u.map(r=>r.order))).sort((r,s)=>r-s),a=new Map;for(const r of u)a.has(r.order)||a.set(r.order,[]),a.get(r.order).push({start:r.start,end:r.end});const m=[],w=new Map;for(const r of c){const s=a.get(r);let l=-1;for(let g=0;g<m.length;g++)if(s.every(y=>m[g].every(D=>!b.intersects(D.start,D.end,y.start,y.end,!0)))){l=g;break}l===-1&&(l=m.length,m.push([])),m[l].push(...s),w.set(r,l)}return(A=w.get(t))!=null?A:t},T=(t,n)=>b.intersects(t.start,t.end,n.start,n.end)&&t.group.index===n.group.index&&t.range.index===n.range.index&&(t.range.isAllDay===void 0||n.range.isAllDay===void 0||t.range.isAllDay===n.range.isAllDay)&&(e.ignoreIsAllDay||t.isAllDay===n.isAllDay),q=()=>{var y,D,L,Y;const t=(re||[]).filter(o=>o.current&&T(o.current.props,e)),n=d.current&&d.current.element,u=b.first(t);if(t.length===0){_(!1);return}if(!u.current||!n)return;const c=P.getRect(u.current.element),a=[],m=[],w=[];(ne||[]).forEach(o=>{o.current&&(o.current.props.dragHint?m.push(o.current):o.current.props.resizeHint?w.push(o.current):a.push(o.current))});const A=e.dragHint||e.resizeHint?b.calculateOrder(d.current,e.dragHint?m:w,t,e.ignoreIsAllDay):(y=e.order)!=null?y:0;if(!e.vertical&&!(e.dragHint||e.resizeHint)&&e.order!==null&&e.order!==void 0){const o=e.ignoreIsAllDay?a:a.filter(I=>I.props.isAllDay);f.current=oe(e.order,o)}else f.current=A;let r=e.dragHint||e.resizeHint?B(t,e.dragHint?m:w):B(t,a);const s=le(t,a);let l=0;const g=!e.vertical&&f.current!==null;if(s.forEach(o=>{let I=0;o.forEach(h=>{if(b.intersects(h.props.start,h.props.end,e.start,e.end)&&!(e.dragHint||e.resizeHint)&&h._maxSiblingsPerSlot&&h._maxSiblingsPerSlot>r&&h.element!==n&&(r=h._maxSiblingsPerSlot),!g){const $=P.getRect(h.element);h.props.order!==null&&h.props.order!==void 0&&h.props.order<f.current&&(I=$.top+$.height-c.top-R.BORDER_WIDTH*f.current+U)}}),I>l&&(l=I)}),g){const o=(D=e.style)==null?void 0:D.height,I=typeof o=="number"?o:J;l=f.current*(I+U)}if(t.length===0){_(!1);return}const j=ee.add?20:0;c.width=e.vertical?c.width/r-R.BORDER_WIDTH-j/r:c.width*t.length-R.BORDER_WIDTH,e.vertical?c.height=c.height*t.length-R.BORDER_WIDTH:(e.resizeHint||e.dragHint)&&r<=1||(c.height=(Y=(L=e.style)==null?void 0:L.height)!=null?Y:J),c.left=e.vertical?c.left+f.current*c.width+R.BORDER_WIDTH*f.current:c.left,c.top=e.vertical?c.top:c.top+l+R.BORDER_WIDTH*f.current,F.current=r,P.setRect(n,c),se(!0),_(!0)},N=i.useCallback(t=>{const n=t&&t[0],u=M.current;x.current!==void 0&&window.cancelAnimationFrame(x.current),u&&n&&(u.width!==n.contentRect.width||u.height!==n.contentRect.height)&&(x.current=window.requestAnimationFrame(()=>{q()})),M.current={width:n.contentRect.width,height:n.contentRect.height}},[q]);i.useEffect(q);const ae=d.current&&d.current.element?d.current.element.closest(".k-scheduler-layout"):null;return fe.useRowSync({element:ae,selector:".k-resource-row",horizontalAttribute:"data-depth-index",verticalAttribute:"data-resource-index",applyTo:".k-resource-cell",syncHeight:e.isLast}),i.useEffect(()=>{if(!H.current)return;const t=window.ResizeObserver,n=t&&new t(N);return n&&n.observe(H.current),()=>{n&&n.disconnect()}},[N,H]),i.createElement(te,{...p,_ref:d,_maxSiblingsPerSlot:F,_order:f,itemRef:d,style:{visibility:ce?void 0:"hidden",display:ie?void 0:"none",...e.style}},!e.resizeHint&&i.createElement("span",{className:"k-event-actions"},e.tail&&i.createElement(O.IconWrap,{name:V==="rtl"?"chevron-right":"chevron-left",icon:V==="rtl"?z.chevronRightIcon:z.chevronLeftIcon}),e.isRecurring&&!e.isException&&i.createElement(O.IconWrap,{name:"arrow-rotate-cw",icon:z.arrowRotateCwIcon}),!e.isRecurring&&e.isException&&i.createElement(O.IconWrap,{name:"arrows-no-repeat",icon:z.arrowsNoRepeatIcon})),!e.resizeHint&&i.createElement("div",{title:W},!e.isAllDay&&i.createElement(G.SchedulerItemContent,{className:"k-event-time"},W),i.createElement(G.SchedulerItemContent,null,e.title)))}),X={item:de.SchedulerItem};Q.displayName="KendoReactSchedulerViewItem";exports.SchedulerViewItem=Q;exports.schedulerViewItemDefaultProps=X;