UNPKG

react-big-schedule

Version:

React Big Schedule is a powerful and intuitive scheduler and resource planning solution built with React. Seamlessly integrate this modern browser-compatible component into your applications to effectively manage time, appointments, and resources. With d

734 lines (726 loc) 37.1 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports["default"] = void 0; var _propTypes = require("prop-types"); var _react = _interopRequireWildcard(require("react")); var _reactDnd = require("react-dnd"); var _default2 = require("../config/default"); var _utility = require("../helper/utility"); var _AddMore = _interopRequireDefault(require("./AddMore")); var _EventItem = _interopRequireDefault(require("./EventItem")); var _SelectedArea = _interopRequireDefault(require("./SelectedArea")); var _Summary = _interopRequireDefault(require("./Summary")); var _jsxRuntime = require("react/jsx-runtime"); function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; } function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function _interopRequireWildcard(e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, "default": e }; if (null === e || "object" != _typeof(e) && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (var _t in e) "default" !== _t && {}.hasOwnProperty.call(e, _t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, _t)) && (i.get || i.set) ? o(f, _t, i) : f[_t] = e[_t]); return f; })(e, t); } function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); } function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; } function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; } function _toConsumableArray(r) { return _arrayWithoutHoles(r) || _iterableToArray(r) || _unsupportedIterableToArray(r) || _nonIterableSpread(); } function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } function _iterableToArray(r) { if ("undefined" != typeof Symbol && null != r[Symbol.iterator] || null != r["@@iterator"]) return Array.from(r); } function _arrayWithoutHoles(r) { if (Array.isArray(r)) return _arrayLikeToArray(r); } function _slicedToArray(r, e) { return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest(); } function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } } function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; } function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t["return"] && (u = t["return"](), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } } function _arrayWithHoles(r) { if (Array.isArray(r)) return r; } function _classCallCheck(a, n) { if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function"); } function _defineProperties(e, r) { for (var t = 0; t < r.length; t++) { var o = r[t]; o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, _toPropertyKey(o.key), o); } } function _createClass(e, r, t) { return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", { writable: !1 }), e; } function _callSuper(t, o, e) { return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], _getPrototypeOf(t).constructor) : o.apply(t, e)); } function _possibleConstructorReturn(t, e) { if (e && ("object" == _typeof(e) || "function" == typeof e)) return e; if (void 0 !== e) throw new TypeError("Derived constructors may only return object or undefined"); return _assertThisInitialized(t); } function _assertThisInitialized(e) { if (void 0 === e) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); return e; } function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); } function _getPrototypeOf(t) { return _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function (t) { return t.__proto__ || Object.getPrototypeOf(t); }, _getPrototypeOf(t); } function _inherits(t, e) { if ("function" != typeof e && null !== e) throw new TypeError("Super expression must either be null or a function"); t.prototype = Object.create(e && e.prototype, { constructor: { value: t, writable: !0, configurable: !0 } }), Object.defineProperty(t, "prototype", { writable: !1 }), e && _setPrototypeOf(t, e); } function _setPrototypeOf(t, e) { return _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function (t, e) { return t.__proto__ = e, t; }, _setPrototypeOf(t, e); } function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; } function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; } function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); } var DEFAULT_ROW_HEIGHT = 50; var ResourceEvents = /*#__PURE__*/function (_PureComponent) { function ResourceEvents(props) { var _this; _classCallCheck(this, ResourceEvents); _this = _callSuper(this, ResourceEvents, [props]); _defineProperty(_this, "cleanupDragInteraction", function () { document.documentElement.removeEventListener('touchmove', _this.doDrag, false); document.documentElement.removeEventListener('touchend', _this.stopDrag, false); document.documentElement.removeEventListener('touchcancel', _this.cancelDrag, false); document.documentElement.removeEventListener('mousemove', _this.doDrag, false); document.documentElement.removeEventListener('mouseup', _this.stopDrag, false); document.onselectstart = null; document.ondragstart = null; }); _defineProperty(_this, "supportTouchHelper", function () { var evType = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'add'; var ev = evType === 'add' ? _this.eventContainer.addEventListener : _this.eventContainer.removeEventListener; if (_this.supportTouch) { // ev('touchstart', this.initDrag, false); } else { ev('mousedown', _this.initDrag, false); } }); _defineProperty(_this, "initDrag", function (ev) { var isSelecting = _this.state.isSelecting; if (isSelecting) return; if ((ev.srcElement || ev.target) !== _this.eventContainer) return; ev.stopPropagation(); var resourceEvents = _this.props.resourceEvents; if (resourceEvents.groupOnly) return; var _this$dragHelper = _this.dragHelper(ev, 'init'), _this$dragHelper2 = _slicedToArray(_this$dragHelper, 2), clientX = _this$dragHelper2[0], toReturn = _this$dragHelper2[1]; if (toReturn) { return; } var schedulerData = _this.props.schedulerData; var cellWidth = schedulerData.getContentCellWidth(); var pos = (0, _utility.getPos)(_this.eventContainer); var startX = clientX - pos.x; var leftIndex = Math.floor(startX / cellWidth); var left = leftIndex * cellWidth; var rightIndex = Math.ceil(startX / cellWidth); var width = (rightIndex - leftIndex) * cellWidth; // Get the row index of this resource var startRowIndex = _this.getResourceRowIndex(resourceEvents.slotId); _this.setState({ startX: startX, left: left, leftIndex: leftIndex, width: width, rightIndex: rightIndex, isSelecting: true, originalStartRowIndex: startRowIndex, startRowIndex: startRowIndex, endRowIndex: startRowIndex // Initially same as start }); _this.emitSelectionChange(true, _this.getSelectedResourceIds(startRowIndex, startRowIndex), { left: left, width: width }); if (_this.supportTouch) { document.documentElement.addEventListener('touchmove', _this.doDrag, false); document.documentElement.addEventListener('touchend', _this.stopDrag, false); document.documentElement.addEventListener('touchcancel', _this.cancelDrag, false); } else { document.documentElement.addEventListener('mousemove', _this.doDrag, false); document.documentElement.addEventListener('mouseup', _this.stopDrag, false); } document.onselectstart = function () { return false; }; document.ondragstart = function () { return false; }; }); _defineProperty(_this, "doDrag", function (ev) { ev.stopPropagation(); var _this$dragHelper3 = _this.dragHelper(ev, 'do'), _this$dragHelper4 = _slicedToArray(_this$dragHelper3, 2), clientX = _this$dragHelper4[0], toReturn = _this$dragHelper4[1]; if (toReturn) { return; } var _this$state = _this.state, startX = _this$state.startX, originalStartRowIndex = _this$state.originalStartRowIndex; var schedulerData = _this.props.schedulerData; var headers = schedulerData.headers; var cellWidth = schedulerData.getContentCellWidth(); var pos = (0, _utility.getPos)(_this.eventContainer); var currentX = clientX - pos.x; var leftIndex = Math.floor(Math.min(startX, currentX) / cellWidth); leftIndex = leftIndex < 0 ? 0 : leftIndex; var left = leftIndex * cellWidth; var rightIndex = Math.ceil(Math.max(startX, currentX) / cellWidth); rightIndex = rightIndex > headers.length ? headers.length : rightIndex; var width = (rightIndex - leftIndex) * cellWidth; // Calculate current row based on per-row heights (not a uniform row height assumption). var clientY = ev.clientY; if (_this.supportTouch && ev.changedTouches && ev.changedTouches.length > 0) { clientY = ev.changedTouches[0].clientY; } var currentY = clientY - pos.y; var displayRenderData = _this.getDisplayRenderData(); if (displayRenderData.length === 0) { _this.setState({ leftIndex: leftIndex, left: left, rightIndex: rightIndex, width: width, isSelecting: true, startRowIndex: -1, endRowIndex: -1 }); _this.emitSelectionChange(true, [], { left: left, width: width }); return; } var rowHeights = displayRenderData.map(function (row) { return (row === null || row === void 0 ? void 0 : row.rowHeight) || DEFAULT_ROW_HEIGHT; }); var startRowTop = rowHeights.slice(0, Math.max(0, originalStartRowIndex)).reduce(function (sum, h) { return sum + h; }, 0); var absoluteY = startRowTop + currentY; var cumulativeHeight = 0; var currentRowIndex = rowHeights.length - 1; for (var i = 0; i < rowHeights.length; i += 1) { cumulativeHeight += rowHeights[i]; if (absoluteY < cumulativeHeight) { currentRowIndex = i; break; } } if (absoluteY < 0) { currentRowIndex = 0; } var minRowIndex = Math.min(originalStartRowIndex, currentRowIndex); var maxRowIndex = Math.max(originalStartRowIndex, currentRowIndex); // Clamp to valid row indices var clampedMinRow = Math.max(0, minRowIndex); var clampedMaxRow = Math.min(displayRenderData.length - 1, maxRowIndex); _this.setState({ leftIndex: leftIndex, left: left, rightIndex: rightIndex, width: width, isSelecting: true, startRowIndex: clampedMinRow, endRowIndex: clampedMaxRow }); _this.emitSelectionChange(true, _this.getSelectedResourceIds(clampedMinRow, clampedMaxRow), { left: left, width: width }); }); _defineProperty(_this, "dragHelper", function (ev, dragType) { var clientX = 0; if (_this.supportTouch) { if (ev.changedTouches.length === 0) return [clientX, true]; var touch = ev.changedTouches[0]; clientX = touch.pageX; } else if (dragType === 'init') { if (ev.buttons !== undefined && ev.buttons !== 1) return [clientX, true]; clientX = ev.clientX; } else { clientX = ev.clientX; } return [clientX, false]; }); _defineProperty(_this, "stopDrag", function (ev) { var _schedulerData$getRes; if (ev !== null && ev !== void 0 && ev.stopPropagation) ev.stopPropagation(); var _this$props = _this.props, schedulerData = _this$props.schedulerData, newEvent = _this$props.newEvent, resourceEvents = _this$props.resourceEvents; var headers = schedulerData.headers, events = schedulerData.events, config = schedulerData.config, cellUnit = schedulerData.cellUnit, localeDayjs = schedulerData.localeDayjs; var _this$state2 = _this.state, leftIndex = _this$state2.leftIndex, rightIndex = _this$state2.rightIndex; _this.cleanupDragInteraction(); if (headers.length === 0 || !resourceEvents.headerItems || resourceEvents.headerItems.length === 0) { _this.setState({ startX: 0, leftIndex: 0, left: 0, rightIndex: 0, width: 0, isSelecting: false, originalStartRowIndex: -1, startRowIndex: -1, endRowIndex: -1 }); _this.emitSelectionChange(false, [], { left: 0, width: 0 }); return; } var maxLeftIndex = headers.length - 1; var safeLeftIndex = Math.max(0, Math.min(leftIndex, maxLeftIndex)); var maxRightIndex = Math.min(headers.length, resourceEvents.headerItems.length); var safeRightIndex = Math.max(1, rightIndex, safeLeftIndex + 1); safeRightIndex = Math.min(safeRightIndex, maxRightIndex); var startTime = headers[safeLeftIndex].time; var endTime = resourceEvents.headerItems[safeRightIndex - 1].end; if (cellUnit !== _default2.CellUnit.Hour) { endTime = localeDayjs(new Date(resourceEvents.headerItems[safeRightIndex - 1].start)).hour(23).minute(59).second(59).format(_default2.DATETIME_FORMAT); } // Get selected resource IDs var selectedResourceIds = _this.getSelectedResourceIds(); var slotId = selectedResourceIds.length > 0 ? selectedResourceIds[0] : resourceEvents.slotId; var slotName = selectedResourceIds.length > 0 ? ((_schedulerData$getRes = schedulerData.getResourceById(slotId)) === null || _schedulerData$getRes === void 0 ? void 0 : _schedulerData$getRes.name) || slotId : resourceEvents.slotName; _this.setState({ startX: 0, leftIndex: 0, left: 0, rightIndex: 0, width: 0, isSelecting: false, originalStartRowIndex: -1, startRowIndex: -1, endRowIndex: -1 }); _this.emitSelectionChange(false, [], { left: 0, width: 0 }); var hasConflict = false; if (config.checkConflict) { var start = localeDayjs(new Date(startTime)); var end = localeDayjs(endTime); events.forEach(function (e) { var eventResourceIds = e.resourceIds || [e.resourceId]; var hasOverlap = selectedResourceIds.some(function (selectedId) { return eventResourceIds.includes(selectedId); }); if (hasOverlap) { var eStart = localeDayjs(e.start); var eEnd = localeDayjs(e.end); if (start >= eStart && start < eEnd || end > eStart && end <= eEnd || eStart >= start && eStart < end || eEnd > start && eEnd <= end) hasConflict = true; } }); } if (hasConflict) { var conflictOccurred = _this.props.conflictOccurred; if (conflictOccurred !== undefined) { conflictOccurred(schedulerData, 'New', { id: undefined, start: startTime, end: endTime, resourceId: slotId, // Keep for backward compatibility resourceIds: selectedResourceIds, // Add multi-resource support slotId: slotId, slotName: slotName, title: undefined }, _default2.DnDTypes.EVENT, slotId, slotName, startTime, endTime); } else { console.log('Conflict occurred, set conflictOccurred func in Scheduler to handle it'); } } else if (newEvent !== undefined) { // Pass resourceIds for multi-resource events newEvent(schedulerData, slotId, slotName, startTime, endTime, undefined, { resourceIds: selectedResourceIds.length > 1 ? selectedResourceIds : undefined }); } }); _defineProperty(_this, "cancelDrag", function (ev) { if (ev !== null && ev !== void 0 && ev.stopPropagation) ev.stopPropagation(); var isSelecting = _this.state.isSelecting; if (isSelecting) { _this.cleanupDragInteraction(); _this.setState({ startX: 0, leftIndex: 0, left: 0, rightIndex: 0, width: 0, isSelecting: false, originalStartRowIndex: -1, startRowIndex: -1, endRowIndex: -1 }); _this.emitSelectionChange(false, [], { left: 0, width: 0 }); } }); _defineProperty(_this, "emitSelectionChange", function (isSelecting, selectedResourceIds) { var preview = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}; var onSelectionChange = _this.props.onSelectionChange; if (onSelectionChange) { onSelectionChange(isSelecting, selectedResourceIds, preview); } }); _defineProperty(_this, "onAddMoreClick", function (headerItem) { var _this$props2 = _this.props, onSetAddMoreState = _this$props2.onSetAddMoreState, resourceEvents = _this$props2.resourceEvents, schedulerData = _this$props2.schedulerData; if (onSetAddMoreState) { var config = schedulerData.config; var cellWidth = schedulerData.getContentCellWidth(); var index = resourceEvents.headerItems.indexOf(headerItem); if (index !== -1) { var left = index * (cellWidth - 1); var pos = (0, _utility.getPos)(_this.eventContainer); left += pos.x; var top = pos.y; var height = (headerItem.count + 1) * config.eventItemLineHeight + 20; onSetAddMoreState({ headerItem: headerItem, left: left, top: top, height: height }); } } }); _defineProperty(_this, "eventContainerRef", function (element) { _this.eventContainer = element; // Also set the drop ref if it exists var dropRef = _this.props.dropRef; if (dropRef) { dropRef(element); } }); _defineProperty(_this, "getResourceRowIndex", function (slotId) { return _this.getDisplayRenderData().findIndex(function (row) { return row.slotId === slotId; }); }); _defineProperty(_this, "getDisplayRenderData", function () { var schedulerData = _this.props.schedulerData; return schedulerData.renderData.filter(function (row) { return row.render; }); }); _defineProperty(_this, "getSelectedResourceIds", function (startOverride, endOverride) { var _this$state3 = _this.state, startRowIndex = _this$state3.startRowIndex, endRowIndex = _this$state3.endRowIndex; var displayRenderData = _this.getDisplayRenderData(); var from = startOverride !== undefined ? startOverride : startRowIndex; var to = endOverride !== undefined ? endOverride : endRowIndex; if (from === -1 || to === -1) { return []; } var selectedResourceIds = []; for (var i = from; i <= to; i++) { var row = displayRenderData[i]; if (row && !row.groupOnly) { selectedResourceIds.push(row.slotId); } } return selectedResourceIds; }); _this.state = { isSelecting: false, left: 0, width: 0, // Add vertical selection tracking originalStartRowIndex: -1, startRowIndex: -1, endRowIndex: -1 }; _this.supportTouch = false; // 'ontouchstart' in window; return _this; } _inherits(ResourceEvents, _PureComponent); return _createClass(ResourceEvents, [{ key: "componentDidMount", value: function componentDidMount() { var schedulerData = this.props.schedulerData; var config = schedulerData.config; this.supportTouch = 'ontouchstart' in window; if (config.creatable === true) { this.supportTouchHelper(); } } }, { key: "componentDidUpdate", value: function componentDidUpdate(prevProps) { var _prevProps$schedulerD, _this$props$scheduler; var prevCreatable = (_prevProps$schedulerD = prevProps.schedulerData) === null || _prevProps$schedulerD === void 0 || (_prevProps$schedulerD = _prevProps$schedulerD.config) === null || _prevProps$schedulerD === void 0 ? void 0 : _prevProps$schedulerD.creatable; var currentCreatable = (_this$props$scheduler = this.props.schedulerData) === null || _this$props$scheduler === void 0 || (_this$props$scheduler = _this$props$scheduler.config) === null || _this$props$scheduler === void 0 ? void 0 : _this$props$scheduler.creatable; if (prevCreatable !== currentCreatable) { this.supportTouchHelper('remove'); if (currentCreatable) { this.supportTouchHelper(); } } } }, { key: "componentWillUnmount", value: function componentWillUnmount() { this.cleanupDragInteraction(); this.supportTouchHelper('remove'); this.emitSelectionChange(false, [], { left: 0, width: 0 }); } }, { key: "render", value: function render() { var _this$props$selection, _this$props$selection2, _this$props$selection3, _this2 = this; var _this$props3 = this.props, resourceEvents = _this$props3.resourceEvents, schedulerData = _this$props3.schedulerData, dndSource = _this$props3.dndSource; var cellUnit = schedulerData.cellUnit, startDate = schedulerData.startDate, endDate = schedulerData.endDate, config = schedulerData.config, localeDayjs = schedulerData.localeDayjs; var _this$state4 = this.state, isSelecting = _this$state4.isSelecting, left = _this$state4.left, width = _this$state4.width, startRowIndex = _this$state4.startRowIndex, endRowIndex = _this$state4.endRowIndex; var cellWidth = schedulerData.getContentCellWidth(); var cellMaxEvents = schedulerData.getCellMaxEvents(); var rowWidth = schedulerData.getContentTableWidth(); var selectedArea = isSelecting ? /*#__PURE__*/(0, _jsxRuntime.jsx)(_SelectedArea["default"], { schedulerData: schedulerData, left: left, width: width }) : /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {}); var sharedSelecting = (_this$props$selection = this.props.selectionPreview) === null || _this$props$selection === void 0 ? void 0 : _this$props$selection.isSelecting; var isSharedSelectedRow = sharedSelecting && this.props.isRowSelected; var sharedLeft = ((_this$props$selection2 = this.props.selectionPreview) === null || _this$props$selection2 === void 0 ? void 0 : _this$props$selection2.left) || 0; var sharedWidth = ((_this$props$selection3 = this.props.selectionPreview) === null || _this$props$selection3 === void 0 ? void 0 : _this$props$selection3.width) || 0; var sharedSelectedArea = !isSelecting && isSharedSelectedRow ? /*#__PURE__*/(0, _jsxRuntime.jsx)(_SelectedArea["default"], { schedulerData: schedulerData, left: sharedLeft, width: sharedWidth }) : null; // Add vertical selection overlay var verticalSelectionOverlay = isSelecting && startRowIndex !== endRowIndex ? /*#__PURE__*/(0, _jsxRuntime.jsx)("div", { className: "vertical-selection-overlay" }) : null; var eventList = []; resourceEvents.headerItems.forEach(function (headerItem, index) { if (headerItem.count > 0 || headerItem.summary !== undefined) { var isTop = config.summaryPos === _default2.SummaryPos.TopRight || config.summaryPos === _default2.SummaryPos.Top || config.summaryPos === _default2.SummaryPos.TopLeft; var marginTop = resourceEvents.hasSummary && isTop ? 1 + config.eventItemLineHeight : 1; var renderEventsMaxIndex = headerItem.addMore === 0 ? cellMaxEvents : headerItem.addMoreIndex; headerItem.events.forEach(function (evt, idx) { if (idx < renderEventsMaxIndex && evt !== undefined && evt.render) { var durationStart = localeDayjs(new Date(startDate)); var durationEnd = localeDayjs(endDate); if (cellUnit === _default2.CellUnit.Hour) { durationStart = localeDayjs(new Date(startDate)).add(config.dayStartFrom, 'hours'); durationEnd = localeDayjs(endDate).add(config.dayStopTo + 1, 'hours'); } var eventStart = localeDayjs(evt.eventItem.start); var eventEnd = localeDayjs(evt.eventItem.end); var isStart = eventStart >= durationStart; var isEnd = eventEnd <= durationEnd; var _left = index * cellWidth + (index > 0 ? 2 : 3); var _width = evt.span * cellWidth - (index > 0 ? 5 : 6) > 0 ? evt.span * cellWidth - (index > 0 ? 5 : 6) : 0; var dayStart = localeDayjs(new Date(headerItem.start)).startOf('day'); var dayDurationMinutes = 1440; var baseCellWidth = cellWidth - (index > 0 ? 5 : 6); if (cellUnit === _default2.CellUnit.Day) { if (evt.span === 1) { var startOffsetMinutes = eventStart.diff(dayStart, 'minute'); var eventDurationMinutes = eventEnd.diff(eventStart, 'minute'); var startPercentage = startOffsetMinutes / dayDurationMinutes; var durationPercentage = eventDurationMinutes / dayDurationMinutes; var leftOffset = baseCellWidth * startPercentage; var eventWidth = baseCellWidth * durationPercentage; _left = index * cellWidth + (index > 0 ? 2 : 3) + leftOffset; _width = Math.max(1, eventWidth); // ensure minimum width of 1px } else { var headerStart = localeDayjs(new Date(headerItem.start)); var headerEnd = localeDayjs(new Date(headerItem.end)); var isFirstDay = eventStart >= headerStart && eventStart < headerEnd; if (isFirstDay) { var eventStartDayStart = eventStart.startOf('day'); var eventEndDayEnd = eventEnd.endOf('day'); var totalSpanMinutes = eventEndDayEnd.diff(eventStartDayStart, 'minute'); var eventStartOffsetMinutes = eventStart.diff(eventStartDayStart, 'minute'); var _eventDurationMinutes = eventEnd.diff(eventStart, 'minute'); var _startPercentage = eventStartOffsetMinutes / dayDurationMinutes; var _durationPercentage = totalSpanMinutes > 0 ? _eventDurationMinutes / totalSpanMinutes : 1; var totalWidth = evt.span * cellWidth - (index > 0 ? 5 : 6); var _leftOffset = cellWidth * _startPercentage; var _eventWidth = totalWidth * _durationPercentage; _left = index * cellWidth + (index > 0 ? 2 : 3) + _leftOffset; _width = Math.max(1, _eventWidth); } } } else { _width = evt.span * cellWidth - (index > 0 ? 5 : 6) > 0 ? evt.span * cellWidth - (index > 0 ? 5 : 6) : 0; } var top = marginTop + idx * config.eventItemLineHeight; var eventKey = "".concat(evt.eventItem.id, "_").concat(resourceEvents.slotId, "_").concat(index); var eventItem = /*#__PURE__*/(0, _jsxRuntime.jsx)(_EventItem["default"], { schedulerData: schedulerData, eventItem: evt.eventItem, dndSource: dndSource, isStart: isStart, isEnd: isEnd, isInPopover: false, left: _left, width: _width, top: top, leftIndex: index, rightIndex: index + evt.span // Passing through functional props , eventItemClick: _this2.props.eventItemClick, viewEventClick: _this2.props.viewEventClick, viewEventText: _this2.props.viewEventText, viewEvent2Click: _this2.props.viewEvent2Click, viewEvent2Text: _this2.props.viewEvent2Text, eventItemTemplateResolver: _this2.props.eventItemTemplateResolver, subtitleGetter: _this2.props.subtitleGetter, updateEventStart: _this2.props.updateEventStart, updateEventEnd: _this2.props.updateEventEnd, moveEvent: _this2.props.moveEvent, conflictOccurred: _this2.props.conflictOccurred }, eventKey); eventList.push(eventItem); } }); if (headerItem.addMore > 0) { var _left2 = index * cellWidth + (index > 0 ? 2 : 3); var _width2 = cellWidth - (index > 0 ? 5 : 6); var top = marginTop + headerItem.addMoreIndex * config.eventItemLineHeight; var addMoreItem = /*#__PURE__*/(0, _jsxRuntime.jsx)(_AddMore["default"], { schedulerData: schedulerData, headerItem: headerItem, number: headerItem.addMore, left: _left2, width: _width2, top: top, clickAction: _this2.onAddMoreClick }); eventList.push(addMoreItem); } if (headerItem.summary !== undefined) { var _top = isTop ? 1 : resourceEvents.rowHeight - config.eventItemLineHeight + 1; var _left3 = index * cellWidth + (index > 0 ? 2 : 3); var _width3 = cellWidth - (index > 0 ? 5 : 6); var key = "".concat(resourceEvents.slotId, "_").concat(headerItem.time); var summary = /*#__PURE__*/(0, _jsxRuntime.jsx)(_Summary["default"], { schedulerData: schedulerData, summary: headerItem.summary, left: _left3, width: _width3, top: _top }, key); eventList.push(summary); } } }); var eventContainer = /*#__PURE__*/(0, _jsxRuntime.jsxs)("div", { ref: this.eventContainerRef, className: "event-container", style: { height: resourceEvents.rowHeight }, children: [selectedArea, sharedSelectedArea, verticalSelectionOverlay, eventList] }); return /*#__PURE__*/(0, _jsxRuntime.jsx)("tr", { children: /*#__PURE__*/(0, _jsxRuntime.jsx)("td", { style: { width: rowWidth }, children: eventContainer }) }); } }]); }(_react.PureComponent); // Wrapper component to use useDrop hook _defineProperty(ResourceEvents, "propTypes", { resourceEvents: _propTypes.PropTypes.object.isRequired, schedulerData: _propTypes.PropTypes.object.isRequired, schedulerDataVersion: _propTypes.PropTypes.number, dndSource: _propTypes.PropTypes.object.isRequired, onSetAddMoreState: _propTypes.PropTypes.func, updateEventStart: _propTypes.PropTypes.func, updateEventEnd: _propTypes.PropTypes.func, moveEvent: _propTypes.PropTypes.func, movingEvent: _propTypes.PropTypes.func, conflictOccurred: _propTypes.PropTypes.func, subtitleGetter: _propTypes.PropTypes.func, eventItemClick: _propTypes.PropTypes.func, viewEventClick: _propTypes.PropTypes.func, viewEventText: _propTypes.PropTypes.string, viewEvent2Click: _propTypes.PropTypes.func, viewEvent2Text: _propTypes.PropTypes.string, newEvent: _propTypes.PropTypes.func, eventItemTemplateResolver: _propTypes.PropTypes.func, onSelectionChange: _propTypes.PropTypes.func, isRowSelected: _propTypes.PropTypes.bool, selectionPreview: _propTypes.PropTypes.shape({ isSelecting: _propTypes.PropTypes.bool, left: _propTypes.PropTypes.number, width: _propTypes.PropTypes.number }) }); var ResourceEventsWithDnD = function ResourceEventsWithDnD(props) { var schedulerData = props.schedulerData, dndContext = props.dndContext; var config = schedulerData.config; var componentRef = _react["default"].useRef(null); var propsRef = _react["default"].useRef(props); // Keep propsRef up to date _react["default"].useEffect(function () { propsRef.current = props; }, [props]); // Always call useDrop unconditionally (Rules of Hooks) // Disable functionality when drag and drop is not enabled var _useDrop = (0, _reactDnd.useDrop)(function () { // If drag and drop is disabled, return a no-op spec if (!config.dragAndDropEnabled || !dndContext) { return { accept: [], collect: function collect() { return { isOver: false, canDrop: false }; } }; } var spec = dndContext.getDropSpec(); return { accept: _toConsumableArray(dndContext.sourceMap.keys()), drop: function drop(item, monitor) { return spec.drop(propsRef.current, monitor, componentRef.current); }, hover: function hover(item, monitor) { return spec.hover(propsRef.current, monitor, componentRef.current); }, canDrop: function canDrop(item, monitor) { return spec.canDrop(propsRef.current, monitor); }, collect: function collect(monitor) { return { isOver: monitor.isOver(), canDrop: monitor.canDrop() }; } }; }, [dndContext, config.dragAndDropEnabled]), _useDrop2 = _slicedToArray(_useDrop, 2), _useDrop2$ = _useDrop2[0], isOver = _useDrop2$.isOver, canDrop = _useDrop2$.canDrop, dropRef = _useDrop2[1]; return /*#__PURE__*/(0, _jsxRuntime.jsx)(ResourceEvents, _objectSpread(_objectSpread({ ref: componentRef }, props), {}, { dropRef: dropRef, isOver: isOver, canDrop: canDrop })); }; ResourceEventsWithDnD.displayName = 'ResourceEventsWithDnD'; var _default = exports["default"] = /*#__PURE__*/_react["default"].memo(ResourceEventsWithDnD);