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) 3.64 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 E=require("react"),P=require("react-dom"),z=require("@progress/kendo-date-math"),k=require("@progress/kendo-react-common"),w=require("../utils/index.js"),h=require("../views/common/utils.js"),I=require("../context/SchedulerContext.js"),j=require("../context/SchedulerViewContext.js");function M(e){const r=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e){for(const n in e)if(n!=="default"){const s=Object.getOwnPropertyDescriptor(e,n);Object.defineProperty(r,n,s.get?s:{enumerable:!0,get:()=>e[n]})}}return r.default=e,Object.freeze(r)}const c=M(E),_=M(P),$=e=>{let r=0;return e.forEach(n=>{if(n.current){const s=h.getRect(n.current.element);r+=s.width}}),r},A=e=>{let r=0;return e.forEach(n=>{if(n.current){const s=h.getRect(n.current.element);r+=s.height}}),r},N=(e,r)=>{const n=z.cloneDate(e);return n.setHours(r.getHours(),r.getMinutes(),r.getSeconds(),r.getMilliseconds()),n},H=e=>{const[r,n]=c.useState(!1),s=I.useSchedulerElementContext(),T=I.useSchedulerPropsContext(),m=c.useRef(void 0),a=c.useRef(null),o=c.useRef(null),b=e.updateInterval||X.updateInterval,[,C]=c.useState(!1),u=k.useDir(o,T.rtl===!0?"rtl":void 0),[v]=j.useSchedulerViewSlotsContext(),d=c.useCallback(()=>{if(!v)return;const i=v.filter(t=>t.current&&(e.groupIndex===void 0||e.groupIndex===null||t.current.props.group.index===e.groupIndex)&&(e.vertical?w.intersects(new Date,new Date,t.current.props.start,t.current.props.end,!0):w.isInTimeRange(new Date,t.current.props.start,t.current.props.end))&&!t.current.props.isAllDay);if(i&&i.length&&a.current&&o.current){const t=w.first(i);if(!t.current)return;const O=e.vertical?A(i):$(i),l=h.getRect(t.current.element),R=h.getRect(a.current),p=(e.vertical?l.width:l.height)/(t.current.props.end.getTime()-t.current.props.start.getTime()),S=(Date.now()-N(new Date,t.current.props.start).getTime())*p,q=u==="rtl",y=e.vertical?l.top:l.top+S-R.height/2,f=q?"right":"left",D=e.vertical?l[f]+S-R.width/2:l[f];e.vertical?a.current.style[f]=`${D}px`:a.current.style.top=`${y}px`,o.current.style[f]=`${D}px`,o.current.style.top=`${y}px`,o.current.style[e.vertical?"height":"width"]=`${O-1}px`,n(!0)}else n(!1)},[v,e.groupIndex,e.vertical,u]),g=c.useCallback(()=>{d(),C(i=>!i)},[d]);c.useEffect(()=>{if(!s.current||!window)return;clearInterval(m.current),m.current=window.setInterval(g,b);const i=window.ResizeObserver,t=i&&new i(g);return t&&t.observe(s.current),()=>{clearInterval(m.current),t&&t.disconnect()}},[d,g,s,b]),c.useEffect(d);const x=c.createElement("div",{ref:a,className:k.classNames("k-current-time",{"k-current-time-arrow-right":!e.vertical&&u!=="rtl","k-current-time-arrow-left":!e.vertical&&u==="rtl","k-current-time-arrow-down":e.vertical}),style:{transform:e.vertical?u==="rtl"?"translateX(50%)":"translateX(-50%)":"translateY(-50%)",visibility:r?void 0:"hidden"}});return c.createElement(c.Fragment,null,e.attachArrow&&e.attachArrow.current?_.createPortal(x,e.attachArrow.current):x,c.createElement("div",{className:"k-current-time",ref:o,style:{transform:e.vertical?"translateX(-50%)":"translateY(-50%)",[e.vertical?"width":"height"]:"1px",visibility:r?void 0:"hidden"}}))},X={updateInterval:6e4};exports.CurrentTimeMarker=H;