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) 4.58 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 z=require("react"),m=require("@progress/kendo-react-common"),s=require("../utils/index.js"),B=require("../components/SchedulerForm.js"),G=require("./SchedulerViewSlot.js"),$=require("../hooks/useControlledState.js"),J=require("../context/SchedulerContext.js"),Q=require("../context/SchedulerEditSlotContext.js"),W=require("../hooks/use-slots-selection.js"),X=require("../constants/index.js"),Y=require("../hooks/useEditable.js"),b=require("../context/SchedulerViewContext.js"),y=require("../hooks/use-slots-focus.js");function Z(t){const f=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(t){for(const u in t)if(u!=="default"){const a=Object.getOwnPropertyDescriptor(t,u);Object.defineProperty(f,u,a.get?a:{enumerable:!0,get:()=>t[u]})}}return f.default=t,Object.freeze(f)}const n=Z(z),k=n.forwardRef((t,f)=>{const{_ref:u,onDataAction:a,viewSlot:w,form:T,formItem:O,onFormItemChange:p,..._}=t,[A,q]=n.useState(t.tabIndex),c=n.useRef(null),E=n.useRef(null);n.useImperativeHandle(E,()=>({props:t})),n.useImperativeHandle(f,()=>E.current),n.useImperativeHandle(u,()=>c.current);const d=Y.useEditable(t.editable),S=J.useSchedulerFieldsContext(),[r]=b.useSchedulerViewSlotsContext(),[D]=b.useSchedulerViewItemsContext(),[g,x]=b.useSchedulerViewSelectedSlotsContext(),[,h]=b.useSchedulerViewFocusedSlotsContext(),K=T||I.form,V=w||I.viewSlot,[F,l]=$.useControlledState(null,O,t.onFormItemChange),N=g.some(e=>!!(e.current&&e.current.props.start.getTime()===t.start.getTime()&&e.current.props.end.getTime()===t.end.getTime()&&e.current.props.index===t.index&&e.current.props.group.index===t.group.index&&e.current.props.range.index===t.range.index&&e.current.props.isAllDay===t.isAllDay)),C=n.useCallback(()=>{const e={};if(s.setField(e,S.start,new Date(t.start.getTime())),s.setField(e,S.end,new Date(t.end.getTime())),s.setField(e,S.isAllDay,t.isAllDay),t.group.resources.length)for(let o=0;o<t.group.resources.length;o++){const i=t.group.resources[o];if(s.isGroupped(t.group.resources)){const v=s.getField(t.group.resources[o],i.valueField);s.setField(e,i.field,i.multiple?[v]:v)}else s.setField(e,i.field,i.multiple?[]:void 0)}return e},[S.start,S.end,S.isAllDay,t.start,t.end,t.isAllDay,t.group.resources]),R=n.useCallback(e=>{d.select&&x({type:W.SLOTS_SELECT_ACTION.select,slot:c},e.syntheticEvent),t.onFocus&&t.onFocus.call(void 0,e)},[x,d.select,t.onFocus]),L=n.useCallback(e=>{if(d.add){const o=C();l(o,e)}t.onDoubleClick&&t.onDoubleClick.call(void 0,e)},[C,d.add,t.onDoubleClick,l]),P=n.useCallback(e=>{let o;switch(e.syntheticEvent.keyCode){case m.Keys.left:if(!r)return;e.syntheticEvent.preventDefault(),h({type:y.SLOTS_FOCUS_ACTION.left,slot:c},e.syntheticEvent);break;case m.Keys.right:if(!r)return;e.syntheticEvent.preventDefault(),h({type:y.SLOTS_FOCUS_ACTION.right,slot:c},e.syntheticEvent);break;case m.Keys.up:if(!r)return;e.syntheticEvent.preventDefault(),h({type:y.SLOTS_FOCUS_ACTION.up,slot:c},e.syntheticEvent);break;case m.Keys.down:if(!r)return;e.syntheticEvent.preventDefault(),h({type:y.SLOTS_FOCUS_ACTION.down,slot:c},e.syntheticEvent);break;case m.Keys.enter:{if(!r||!d.add)return;const i=C();l(i);break}case m.Keys.tab:o=s.findFirstItem(e.target);break}o&&(e.syntheticEvent.preventDefault(),o.element&&o.element.focus())},[C,h,d.add,l,r]),j=n.useCallback(e=>{a&&a.call(void 0,{type:X.DATA_ACTION.create,series:!1,dataItem:e.value},e),l(null,e.syntheticEvent)},[a,l]),U=n.useCallback(e=>{l(null,e.syntheticEvent)},[l]),H=n.useCallback(e=>{l(null,e)},[l]),M=n.useCallback((e,o)=>{l&&l(e,o)},[l]);return n.useEffect(()=>{const e=r.length&&r[0].current===c.current;q(t.tabIndex!==void 0?t.tabIndex===null?void 0:t.tabIndex:g.length===0&&e&&D.length===0?0:void 0)},[D,t.tabIndex,g.length,r]),n.createElement(Q.SchedulerEditSlotContext,{props:t,form:[F,M]},n.createElement(V,{..._,_ref:c,selected:N,tabIndex:A,onFocus:R,onDoubleClick:L,onKeyDown:P}),F&&n.createElement(K,{dataItem:F,onSubmit:j,onClose:H,onCancel:U}))}),I={viewSlot:G.SchedulerViewSlot,form:B.SchedulerForm};k.displayName="KendoReactSchedulerEditSlot";exports.SchedulerEditSlot=k;exports.schedulerEditSlotDefaultProps=I;