UNPKG

@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.67 kB
/** * @license *------------------------------------------------------------------------------------------- * Copyright © 2025 Progress Software Corporation. All rights reserved. * Licensed under commercial license. See LICENSE.md in the package root for more information *------------------------------------------------------------------------------------------- */ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const me=require("react"),he=require("./SchedulerItem.js"),m=require("../utils/index.js"),D=require("../views/common/utils.js"),I=require("../constants/index.js"),fe=require("@progress/kendo-react-intl"),J=require("./SchedulerItemContent.js"),P=require("@progress/kendo-react-common"),H=require("@progress/kendo-svg-icons"),Q=require("../context/SchedulerViewContext.js"),ge=require("../context/SchedulerContext.js"),Se=require("../hooks/useRowSync.js");function Re(e){const w=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e){for(const S in e)if(S!=="default"){const x=Object.getOwnPropertyDescriptor(e,S);Object.defineProperty(w,S,x.get?x:{enumerable:!0,get:()=>e[S]})}}return w.default=e,Object.freeze(w)}const r=Re(me),Ie=1,U=25,X=r.forwardRef((e,w)=>{const{item:S,_ref:x,itemRef:Z,...ee}=e,M=r.useRef(void 0),o=r.useRef(null),C=r.useRef(null),k=r.useRef(null);r.useImperativeHandle(C,()=>({props:e,element:o.current&&o.current.element})),r.useImperativeHandle(w,()=>C.current),r.useImperativeHandle(x,()=>o.current),r.useImperativeHandle(Z,()=>o.current);const te=S||Y.item,b=fe.useInternationalization(),[re]=Q.useSchedulerViewItemsContext(),[ne]=Q.useSchedulerViewSlotsContext(),_=ge.useSchedulerElementContext(),[ce,V]=r.useState(!0),[ie,oe]=r.useState(!1),W=r.useRef(0),f=r.useRef(null),g=r.useRef([]),p=P.useDir(_),B=r.useMemo(()=>e.isAllDay?b.toString(e.zonedStart,"t"):b.format("{0:t} - {1:t}",e.zonedStart,e.zonedEnd),[b,e.isAllDay,e.zonedEnd,e.zonedStart]),N=r.useMemo(()=>`(${B}): ${e.title}`,[B,e.title]),se=(c,n)=>{let i=0;return n.forEach(l=>{l._order!==void 0&&l._order!==null&&i<l._order&&(i=l._order)}),i+1},le=(c,n,i)=>{const[l,h]=n,a=new Date(Math.min(h.props.end.getTime()-i,Math.max(e.start.getTime(),l.props.start.getTime()))),R=new Date(Math.max(a.getTime()+i,Math.min(e.end.getTime(),h.props.end.getTime())));return c.filter(u=>{const E=Math.max(Math.min(h.props.end.getTime()-i,u.props.start.getTime()),l.props.start.getTime()),T=Math.min(Math.max(E+i,u.props.end.getTime()),h.props.end.getTime());return u.props.id!==e.id&&u.props.group.index===e.group.index&&u.props.range.index===e.range.index&&(e.ignoreIsAllDay||u.props.isAllDay===e.isAllDay)&&m.intersects(new Date(E),new Date(T),a,R)&&m.intersects(l.props.start,h.props.end,u.props.start,u.props.end)})},ae=(c,n)=>c.group.index===n.group.index&&c.range.index===n.range.index&&(e.ignoreIsAllDay||c.isAllDay===n.isAllDay),z=()=>{var G,L,K;const c=ne.filter(t=>t.current&&ae(t.current.props,e)).sort((t,v)=>t.current.props.start.getTime()-v.current.props.start.getTime()),n=c.filter(t=>m.intersects(t.current.props.start,t.current.props.end,e.start,e.end)),i=o.current&&o.current.element;if(!i||!n.length)return;const l=m.first(c),h=m.last(c),a=m.first(n),R=m.last(n);if(!a.current||!o.current||!R.current||!l.current||!h.current)return;if(!m.intersects(a.current.props.start,R.current.props.end,e.start,e.end)){V(!1);return}const O=[],u=[],E=[],T=D.getRect(a.current.element),A=(e.vertical?T.height:T.width)/(a.current.props.end.getTime()-a.current.props.start.getTime()),F=(e.vertical?U:8)/A,y=(Math.min(e.start.getTime(),R.current.props.end.getTime()-F)-a.current.props.start.getTime())*A,$=Math.floor(Math.min(e.end.getTime(),R.current.props.end.getTime())-Math.max(e.start.getTime(),a.current.props.start.getTime()))*A;(re||[]).forEach(t=>{t.current&&(t.current.props.dragHint?u.push(t.current):t.current.props.resizeHint?E.push(t.current):O.push(t.current))}),g.current=le(O,[l.current,h.current],F),f.current=e.resizeHint||e.dragHint?0:m.calculateProportionalOrder(o.current,g.current);let d=1;e.resizeHint||e.dragHint||(d=se(o.current,g.current),g.current.forEach(t=>{t._maxSiblingsPerSlot&&d<t._maxSiblingsPerSlot&&(d=t._maxSiblingsPerSlot)}),g.current.forEach(t=>{t._maxSiblingsPerSlot!==void 0&&t._maxSiblingsPerSlot!==null&&t._maxSiblingsPerSlot<d&&(t._maxSiblingsPerSlot=d)}));let q=0;const s=T;g.current.forEach(t=>{let v=0;t._order!==void 0&&t._order!==null&&t._order<f.current&&(v=D.getRect(t.element).top+D.getRect(t.element).height-s.top-I.BORDER_WIDTH*f.current+Ie),v>q&&(q=v)});const de=20;s.width=e.vertical?s.width/d-I.BORDER_WIDTH-de/d:$-I.BORDER_WIDTH,s.height=e.vertical?$-I.BORDER_WIDTH:(e.resizeHint||e.dragHint)&&d<=1?s.height:e.style&&e.style.height?e.style.height:U,s.left=e.vertical?s.left+((G=f.current)!=null?G:0)+I.BORDER_WIDTH*((L=f.current)!=null?L:0)*s.width:s.left+(y<0?0:y),s.top=e.vertical?s.top+(y<0?0:y):s.top+q+I.BORDER_WIDTH*((K=f.current)!=null?K:0),W.current=d,D.setRect(i,s),oe(!0),V(!0)},j=r.useCallback(c=>{const n=c&&c[0],i=k.current;M.current!==void 0&&window.cancelAnimationFrame(M.current),i&&n&&(i.width!==n.contentRect.width||i.height!==n.contentRect.height)&&(M.current=window.requestAnimationFrame(()=>{z()})),k.current={width:n.contentRect.width,height:n.contentRect.height}},[z]);r.useEffect(z);const ue=o.current&&o.current.element?o.current.element.closest(".k-scheduler-layout"):null;return Se.useRowSync({element:ue,selector:".k-resource-row",horizontalAttribute:"data-depth-index",verticalAttribute:"data-resource-index",applyTo:".k-resource-cell",syncHeight:e.isLast}),r.useEffect(()=>{if(!_.current)return;const c=window.ResizeObserver,n=c&&new c(j);return n&&n.observe(_.current),()=>{n&&n.disconnect()}},[j,_]),r.createElement(te,{...ee,_ref:o,_order:f,_maxSiblingsPerSlot:W,_siblings:g,itemRef:o,style:{visibility:ie?void 0:"hidden",display:ce?void 0:"none",...e.style}},!e.resizeHint&&r.createElement("span",{className:"k-event-actions"},e.tail&&r.createElement(P.IconWrap,{name:p==="rtl"?"caret-alt-right":"caret-alt-left",icon:p==="rtl"?H.caretAltRightIcon:H.caretAltLeftIcon}),e.isRecurring&&!e.isException&&r.createElement(P.IconWrap,{name:"reload",icon:H.arrowRotateCwIcon}),!e.isRecurring&&e.isException&&r.createElement(P.IconWrap,{name:"non-recurrence",icon:H.nonRecurrenceIcon})),!e.resizeHint&&r.createElement("div",{title:N},!e.isAllDay&&r.createElement(J.SchedulerItemContent,{className:"k-event-time"},N),r.createElement(J.SchedulerItemContent,null,e.title)))}),Y={item:he.SchedulerItem};X.displayName="KendoReactSchedulerProportionalViewItem";exports.SchedulerProportionalViewItem=X;exports.schedulerProportionalViewItemDefaultProps=Y;