react-big-schedule 5.5.2-beta.5 → 6.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,276 +1,275 @@
1
- "use strict";
1
+ import { PropTypes } from 'prop-types';
2
+ import React, { PureComponent } from 'react';
3
+ import { useDrop } from 'react-dnd';
4
+ import { CellUnit, DATETIME_FORMAT, DnDTypes, SummaryPos } from '../config/default';
5
+ import { getPos, normalizeEventEnd, normalizeEventStart } from '../helper/utility';
6
+ import AddMore from './AddMore';
7
+ import EventItem from './EventItem';
8
+ import SelectedArea from './SelectedArea';
9
+ import Summary from './Summary';
10
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
11
+ const DEFAULT_ROW_HEIGHT = 50;
12
+ class ResourceEvents extends PureComponent {
13
+ static propTypes = {
14
+ resourceEvents: PropTypes.object.isRequired,
15
+ schedulerData: PropTypes.object.isRequired,
16
+ schedulerDataVersion: PropTypes.number,
17
+ dndSource: PropTypes.object.isRequired,
18
+ onSetAddMoreState: PropTypes.func,
19
+ updateEventStart: PropTypes.func,
20
+ updateEventEnd: PropTypes.func,
21
+ moveEvent: PropTypes.func,
22
+ movingEvent: PropTypes.func,
23
+ conflictOccurred: PropTypes.func,
24
+ subtitleGetter: PropTypes.func,
25
+ eventItemClick: PropTypes.func,
26
+ viewEventClick: PropTypes.func,
27
+ viewEventText: PropTypes.string,
28
+ viewEvent2Click: PropTypes.func,
29
+ viewEvent2Text: PropTypes.string,
30
+ newEvent: PropTypes.func,
31
+ eventItemTemplateResolver: PropTypes.func,
32
+ onSelectionChange: PropTypes.func,
33
+ isRowSelected: PropTypes.bool,
34
+ selectionPreview: PropTypes.shape({
35
+ isSelecting: PropTypes.bool,
36
+ left: PropTypes.number,
37
+ width: PropTypes.number
38
+ })
39
+ };
40
+ constructor(props) {
41
+ super(props);
42
+ this.state = {
43
+ isSelecting: false,
44
+ left: 0,
45
+ width: 0,
46
+ // Add vertical selection tracking
47
+ originalStartRowIndex: -1,
48
+ startRowIndex: -1,
49
+ endRowIndex: -1
50
+ };
51
+ this.supportTouch = false; // 'ontouchstart' in window;
52
+ }
53
+ componentDidMount() {
54
+ const {
55
+ schedulerData
56
+ } = this.props;
57
+ const {
58
+ config
59
+ } = schedulerData;
60
+ this.supportTouch = 'ontouchstart' in window;
61
+ if (config.creatable === true) {
62
+ this.supportTouchHelper();
63
+ }
64
+ }
65
+ componentDidUpdate(prevProps) {
66
+ const prevCreatable = prevProps.schedulerData?.config?.creatable;
67
+ const currentCreatable = this.props.schedulerData?.config?.creatable;
68
+ if (prevCreatable !== currentCreatable) {
69
+ this.supportTouchHelper('remove');
70
+ if (currentCreatable) {
71
+ this.supportTouchHelper();
72
+ }
73
+ }
74
+ }
75
+ componentWillUnmount() {
76
+ this.cleanupDragInteraction();
77
+ this.supportTouchHelper('remove');
78
+ this.emitSelectionChange(false, [], {
79
+ left: 0,
80
+ width: 0
81
+ });
82
+ }
83
+ cleanupDragInteraction = () => {
84
+ document.documentElement.removeEventListener('touchmove', this.doDrag, false);
85
+ document.documentElement.removeEventListener('touchend', this.stopDrag, false);
86
+ document.documentElement.removeEventListener('touchcancel', this.cancelDrag, false);
87
+ document.documentElement.removeEventListener('mousemove', this.doDrag, false);
88
+ document.documentElement.removeEventListener('mouseup', this.stopDrag, false);
89
+ document.onselectstart = null;
90
+ document.ondragstart = null;
91
+ };
92
+ supportTouchHelper = (evType = 'add') => {
93
+ const ev = evType === 'add' ? this.eventContainer.addEventListener : this.eventContainer.removeEventListener;
94
+ if (this.supportTouch) {
95
+ // ev('touchstart', this.initDrag, false);
96
+ } else {
97
+ ev('mousedown', this.initDrag, false);
98
+ }
99
+ };
100
+ initDrag = ev => {
101
+ const {
102
+ isSelecting
103
+ } = this.state;
104
+ if (isSelecting) return;
105
+ if ((ev.srcElement || ev.target) !== this.eventContainer) return;
106
+ ev.stopPropagation();
107
+ const {
108
+ resourceEvents
109
+ } = this.props;
110
+ if (resourceEvents.groupOnly) return;
111
+ const [clientX, toReturn] = this.dragHelper(ev, 'init');
112
+ if (toReturn) {
113
+ return;
114
+ }
115
+ const {
116
+ schedulerData
117
+ } = this.props;
118
+ const cellWidth = schedulerData.getContentCellWidth();
119
+ const pos = getPos(this.eventContainer);
120
+ const startX = clientX - pos.x;
121
+ const leftIndex = Math.floor(startX / cellWidth);
122
+ const left = leftIndex * cellWidth;
123
+ const rightIndex = Math.ceil(startX / cellWidth);
124
+ const width = (rightIndex - leftIndex) * cellWidth;
2
125
 
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports["default"] = void 0;
7
- var _propTypes = require("prop-types");
8
- var _react = _interopRequireWildcard(require("react"));
9
- var _reactDnd = require("react-dnd");
10
- var _default2 = require("../config/default");
11
- var _utility = require("../helper/utility");
12
- var _AddMore = _interopRequireDefault(require("./AddMore"));
13
- var _EventItem = _interopRequireDefault(require("./EventItem"));
14
- var _SelectedArea = _interopRequireDefault(require("./SelectedArea"));
15
- var _Summary = _interopRequireDefault(require("./Summary"));
16
- var _jsxRuntime = require("react/jsx-runtime");
17
- function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
18
- 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); }
19
- 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); }
20
- 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; }
21
- 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; }
22
- function _toConsumableArray(r) { return _arrayWithoutHoles(r) || _iterableToArray(r) || _unsupportedIterableToArray(r) || _nonIterableSpread(); }
23
- 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."); }
24
- function _iterableToArray(r) { if ("undefined" != typeof Symbol && null != r[Symbol.iterator] || null != r["@@iterator"]) return Array.from(r); }
25
- function _arrayWithoutHoles(r) { if (Array.isArray(r)) return _arrayLikeToArray(r); }
26
- function _slicedToArray(r, e) { return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest(); }
27
- 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."); }
28
- 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; } }
29
- 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; }
30
- 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; } }
31
- function _arrayWithHoles(r) { if (Array.isArray(r)) return r; }
32
- function _classCallCheck(a, n) { if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function"); }
33
- 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); } }
34
- function _createClass(e, r, t) { return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", { writable: !1 }), e; }
35
- function _callSuper(t, o, e) { return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], _getPrototypeOf(t).constructor) : o.apply(t, e)); }
36
- 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); }
37
- function _assertThisInitialized(e) { if (void 0 === e) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); return e; }
38
- function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
39
- function _getPrototypeOf(t) { return _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function (t) { return t.__proto__ || Object.getPrototypeOf(t); }, _getPrototypeOf(t); }
40
- 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); }
41
- function _setPrototypeOf(t, e) { return _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function (t, e) { return t.__proto__ = e, t; }, _setPrototypeOf(t, e); }
42
- 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; }
43
- function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
44
- 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); }
45
- var DEFAULT_ROW_HEIGHT = 50;
46
- var ResourceEvents = /*#__PURE__*/function (_PureComponent) {
47
- function ResourceEvents(props) {
48
- var _this;
49
- _classCallCheck(this, ResourceEvents);
50
- _this = _callSuper(this, ResourceEvents, [props]);
51
- _defineProperty(_this, "cleanupDragInteraction", function () {
52
- document.documentElement.removeEventListener('touchmove', _this.doDrag, false);
53
- document.documentElement.removeEventListener('touchend', _this.stopDrag, false);
54
- document.documentElement.removeEventListener('touchcancel', _this.cancelDrag, false);
55
- document.documentElement.removeEventListener('mousemove', _this.doDrag, false);
56
- document.documentElement.removeEventListener('mouseup', _this.stopDrag, false);
57
- document.onselectstart = null;
58
- document.ondragstart = null;
126
+ // Get the row index of this resource
127
+ const startRowIndex = this.getResourceRowIndex(resourceEvents.slotId);
128
+ this.setState({
129
+ startX,
130
+ left,
131
+ leftIndex,
132
+ width,
133
+ rightIndex,
134
+ isSelecting: true,
135
+ originalStartRowIndex: startRowIndex,
136
+ startRowIndex,
137
+ endRowIndex: startRowIndex // Initially same as start
59
138
  });
60
- _defineProperty(_this, "supportTouchHelper", function () {
61
- var evType = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'add';
62
- var ev = evType === 'add' ? _this.eventContainer.addEventListener : _this.eventContainer.removeEventListener;
63
- if (_this.supportTouch) {
64
- // ev('touchstart', this.initDrag, false);
65
- } else {
66
- ev('mousedown', _this.initDrag, false);
67
- }
139
+ this.emitSelectionChange(true, this.getSelectedResourceIds(startRowIndex, startRowIndex), {
140
+ left,
141
+ width
68
142
  });
69
- _defineProperty(_this, "initDrag", function (ev) {
70
- var isSelecting = _this.state.isSelecting;
71
- if (isSelecting) return;
72
- if ((ev.srcElement || ev.target) !== _this.eventContainer) return;
73
- ev.stopPropagation();
74
- var resourceEvents = _this.props.resourceEvents;
75
- if (resourceEvents.groupOnly) return;
76
- var _this$dragHelper = _this.dragHelper(ev, 'init'),
77
- _this$dragHelper2 = _slicedToArray(_this$dragHelper, 2),
78
- clientX = _this$dragHelper2[0],
79
- toReturn = _this$dragHelper2[1];
80
- if (toReturn) {
81
- return;
82
- }
83
- var schedulerData = _this.props.schedulerData;
84
- var cellWidth = schedulerData.getContentCellWidth();
85
- var pos = (0, _utility.getPos)(_this.eventContainer);
86
- var startX = clientX - pos.x;
87
- var leftIndex = Math.floor(startX / cellWidth);
88
- var left = leftIndex * cellWidth;
89
- var rightIndex = Math.ceil(startX / cellWidth);
90
- var width = (rightIndex - leftIndex) * cellWidth;
143
+ if (this.supportTouch) {
144
+ document.documentElement.addEventListener('touchmove', this.doDrag, false);
145
+ document.documentElement.addEventListener('touchend', this.stopDrag, false);
146
+ document.documentElement.addEventListener('touchcancel', this.cancelDrag, false);
147
+ } else {
148
+ document.documentElement.addEventListener('mousemove', this.doDrag, false);
149
+ document.documentElement.addEventListener('mouseup', this.stopDrag, false);
150
+ }
151
+ document.onselectstart = () => false;
152
+ document.ondragstart = () => false;
153
+ };
154
+ doDrag = ev => {
155
+ ev.stopPropagation();
156
+ const [clientX, toReturn] = this.dragHelper(ev, 'do');
157
+ if (toReturn) {
158
+ return;
159
+ }
160
+ const {
161
+ startX,
162
+ originalStartRowIndex
163
+ } = this.state;
164
+ const {
165
+ schedulerData
166
+ } = this.props;
167
+ const {
168
+ headers
169
+ } = schedulerData;
170
+ const cellWidth = schedulerData.getContentCellWidth();
171
+ const pos = getPos(this.eventContainer);
172
+ const currentX = clientX - pos.x;
173
+ let leftIndex = Math.floor(Math.min(startX, currentX) / cellWidth);
174
+ leftIndex = leftIndex < 0 ? 0 : leftIndex;
175
+ const left = leftIndex * cellWidth;
176
+ let rightIndex = Math.ceil(Math.max(startX, currentX) / cellWidth);
177
+ rightIndex = rightIndex > headers.length ? headers.length : rightIndex;
178
+ const width = (rightIndex - leftIndex) * cellWidth;
91
179
 
92
- // Get the row index of this resource
93
- var startRowIndex = _this.getResourceRowIndex(resourceEvents.slotId);
94
- _this.setState({
95
- startX: startX,
96
- left: left,
97
- leftIndex: leftIndex,
98
- width: width,
99
- rightIndex: rightIndex,
180
+ // Calculate current row based on per-row heights (not a uniform row height assumption).
181
+ let clientY = ev.clientY;
182
+ if (this.supportTouch && ev.changedTouches && ev.changedTouches.length > 0) {
183
+ clientY = ev.changedTouches[0].clientY;
184
+ }
185
+ const currentY = clientY - pos.y;
186
+ const displayRenderData = this.getDisplayRenderData();
187
+ if (displayRenderData.length === 0) {
188
+ this.setState({
189
+ leftIndex,
190
+ left,
191
+ rightIndex,
192
+ width,
100
193
  isSelecting: true,
101
- originalStartRowIndex: startRowIndex,
102
- startRowIndex: startRowIndex,
103
- endRowIndex: startRowIndex // Initially same as start
194
+ startRowIndex: -1,
195
+ endRowIndex: -1
104
196
  });
105
- _this.emitSelectionChange(true, _this.getSelectedResourceIds(startRowIndex, startRowIndex), {
106
- left: left,
107
- width: width
197
+ this.emitSelectionChange(true, [], {
198
+ left,
199
+ width
108
200
  });
109
- if (_this.supportTouch) {
110
- document.documentElement.addEventListener('touchmove', _this.doDrag, false);
111
- document.documentElement.addEventListener('touchend', _this.stopDrag, false);
112
- document.documentElement.addEventListener('touchcancel', _this.cancelDrag, false);
113
- } else {
114
- document.documentElement.addEventListener('mousemove', _this.doDrag, false);
115
- document.documentElement.addEventListener('mouseup', _this.stopDrag, false);
116
- }
117
- document.onselectstart = function () {
118
- return false;
119
- };
120
- document.ondragstart = function () {
121
- return false;
122
- };
123
- });
124
- _defineProperty(_this, "doDrag", function (ev) {
125
- ev.stopPropagation();
126
- var _this$dragHelper3 = _this.dragHelper(ev, 'do'),
127
- _this$dragHelper4 = _slicedToArray(_this$dragHelper3, 2),
128
- clientX = _this$dragHelper4[0],
129
- toReturn = _this$dragHelper4[1];
130
- if (toReturn) {
131
- return;
132
- }
133
- var _this$state = _this.state,
134
- startX = _this$state.startX,
135
- originalStartRowIndex = _this$state.originalStartRowIndex;
136
- var schedulerData = _this.props.schedulerData;
137
- var headers = schedulerData.headers;
138
- var cellWidth = schedulerData.getContentCellWidth();
139
- var pos = (0, _utility.getPos)(_this.eventContainer);
140
- var currentX = clientX - pos.x;
141
- var leftIndex = Math.floor(Math.min(startX, currentX) / cellWidth);
142
- leftIndex = leftIndex < 0 ? 0 : leftIndex;
143
- var left = leftIndex * cellWidth;
144
- var rightIndex = Math.ceil(Math.max(startX, currentX) / cellWidth);
145
- rightIndex = rightIndex > headers.length ? headers.length : rightIndex;
146
- var width = (rightIndex - leftIndex) * cellWidth;
147
-
148
- // Calculate current row based on per-row heights (not a uniform row height assumption).
149
- var clientY = ev.clientY;
150
- if (_this.supportTouch && ev.changedTouches && ev.changedTouches.length > 0) {
151
- clientY = ev.changedTouches[0].clientY;
152
- }
153
- var currentY = clientY - pos.y;
154
- var displayRenderData = _this.getDisplayRenderData();
155
- if (displayRenderData.length === 0) {
156
- _this.setState({
157
- leftIndex: leftIndex,
158
- left: left,
159
- rightIndex: rightIndex,
160
- width: width,
161
- isSelecting: true,
162
- startRowIndex: -1,
163
- endRowIndex: -1
164
- });
165
- _this.emitSelectionChange(true, [], {
166
- left: left,
167
- width: width
168
- });
169
- return;
170
- }
171
- var rowHeights = displayRenderData.map(function (row) {
172
- return (row === null || row === void 0 ? void 0 : row.rowHeight) || DEFAULT_ROW_HEIGHT;
173
- });
174
- var startRowTop = rowHeights.slice(0, Math.max(0, originalStartRowIndex)).reduce(function (sum, h) {
175
- return sum + h;
176
- }, 0);
177
- var absoluteY = startRowTop + currentY;
178
- var cumulativeHeight = 0;
179
- var currentRowIndex = rowHeights.length - 1;
180
- for (var i = 0; i < rowHeights.length; i += 1) {
181
- cumulativeHeight += rowHeights[i];
182
- if (absoluteY < cumulativeHeight) {
183
- currentRowIndex = i;
184
- break;
185
- }
186
- }
187
- if (absoluteY < 0) {
188
- currentRowIndex = 0;
201
+ return;
202
+ }
203
+ const rowHeights = displayRenderData.map(row => row?.rowHeight || DEFAULT_ROW_HEIGHT);
204
+ const startRowTop = rowHeights.slice(0, Math.max(0, originalStartRowIndex)).reduce((sum, h) => sum + h, 0);
205
+ const absoluteY = startRowTop + currentY;
206
+ let cumulativeHeight = 0;
207
+ let currentRowIndex = rowHeights.length - 1;
208
+ for (let i = 0; i < rowHeights.length; i += 1) {
209
+ cumulativeHeight += rowHeights[i];
210
+ if (absoluteY < cumulativeHeight) {
211
+ currentRowIndex = i;
212
+ break;
189
213
  }
190
- var minRowIndex = Math.min(originalStartRowIndex, currentRowIndex);
191
- var maxRowIndex = Math.max(originalStartRowIndex, currentRowIndex);
214
+ }
215
+ if (absoluteY < 0) {
216
+ currentRowIndex = 0;
217
+ }
218
+ const minRowIndex = Math.min(originalStartRowIndex, currentRowIndex);
219
+ const maxRowIndex = Math.max(originalStartRowIndex, currentRowIndex);
192
220
 
193
- // Clamp to valid row indices
194
- var clampedMinRow = Math.max(0, minRowIndex);
195
- var clampedMaxRow = Math.min(displayRenderData.length - 1, maxRowIndex);
196
- _this.setState({
197
- leftIndex: leftIndex,
198
- left: left,
199
- rightIndex: rightIndex,
200
- width: width,
201
- isSelecting: true,
202
- startRowIndex: clampedMinRow,
203
- endRowIndex: clampedMaxRow
204
- });
205
- _this.emitSelectionChange(true, _this.getSelectedResourceIds(clampedMinRow, clampedMaxRow), {
206
- left: left,
207
- width: width
208
- });
221
+ // Clamp to valid row indices
222
+ const clampedMinRow = Math.max(0, minRowIndex);
223
+ const clampedMaxRow = Math.min(displayRenderData.length - 1, maxRowIndex);
224
+ this.setState({
225
+ leftIndex,
226
+ left,
227
+ rightIndex,
228
+ width,
229
+ isSelecting: true,
230
+ startRowIndex: clampedMinRow,
231
+ endRowIndex: clampedMaxRow
209
232
  });
210
- _defineProperty(_this, "dragHelper", function (ev, dragType) {
211
- var clientX = 0;
212
- if (_this.supportTouch) {
213
- if (ev.changedTouches.length === 0) return [clientX, true];
214
- var touch = ev.changedTouches[0];
215
- clientX = touch.pageX;
216
- } else if (dragType === 'init') {
217
- if (ev.buttons !== undefined && ev.buttons !== 1) return [clientX, true];
218
- clientX = ev.clientX;
219
- } else {
220
- clientX = ev.clientX;
221
- }
222
- return [clientX, false];
233
+ this.emitSelectionChange(true, this.getSelectedResourceIds(clampedMinRow, clampedMaxRow), {
234
+ left,
235
+ width
223
236
  });
224
- _defineProperty(_this, "stopDrag", function (ev) {
225
- var _schedulerData$getRes;
226
- if (ev !== null && ev !== void 0 && ev.stopPropagation) ev.stopPropagation();
227
- var _this$props = _this.props,
228
- schedulerData = _this$props.schedulerData,
229
- newEvent = _this$props.newEvent,
230
- resourceEvents = _this$props.resourceEvents;
231
- var headers = schedulerData.headers,
232
- events = schedulerData.events,
233
- config = schedulerData.config,
234
- cellUnit = schedulerData.cellUnit,
235
- localeDayjs = schedulerData.localeDayjs;
236
- var _this$state2 = _this.state,
237
- leftIndex = _this$state2.leftIndex,
238
- rightIndex = _this$state2.rightIndex;
239
- _this.cleanupDragInteraction();
240
- if (headers.length === 0 || !resourceEvents.headerItems || resourceEvents.headerItems.length === 0) {
241
- _this.setState({
242
- startX: 0,
243
- leftIndex: 0,
244
- left: 0,
245
- rightIndex: 0,
246
- width: 0,
247
- isSelecting: false,
248
- originalStartRowIndex: -1,
249
- startRowIndex: -1,
250
- endRowIndex: -1
251
- });
252
- _this.emitSelectionChange(false, [], {
253
- left: 0,
254
- width: 0
255
- });
256
- return;
257
- }
258
- var maxLeftIndex = headers.length - 1;
259
- var safeLeftIndex = Math.max(0, Math.min(leftIndex, maxLeftIndex));
260
- var maxRightIndex = Math.min(headers.length, resourceEvents.headerItems.length);
261
- var safeRightIndex = Math.max(1, rightIndex, safeLeftIndex + 1);
262
- safeRightIndex = Math.min(safeRightIndex, maxRightIndex);
263
- var startTime = headers[safeLeftIndex].time;
264
- var endTime = resourceEvents.headerItems[safeRightIndex - 1].end;
265
- if (cellUnit !== _default2.CellUnit.Hour) {
266
- endTime = localeDayjs(new Date(resourceEvents.headerItems[safeRightIndex - 1].start)).hour(23).minute(59).second(59).format(_default2.DATETIME_FORMAT);
267
- }
268
-
269
- // Get selected resource IDs
270
- var selectedResourceIds = _this.getSelectedResourceIds();
271
- var slotId = selectedResourceIds.length > 0 ? selectedResourceIds[0] : resourceEvents.slotId;
272
- var slotName = selectedResourceIds.length > 0 ? ((_schedulerData$getRes = schedulerData.getResourceById(slotId)) === null || _schedulerData$getRes === void 0 ? void 0 : _schedulerData$getRes.name) || slotId : resourceEvents.slotName;
273
- _this.setState({
237
+ };
238
+ dragHelper = (ev, dragType) => {
239
+ let clientX = 0;
240
+ if (this.supportTouch) {
241
+ if (ev.changedTouches.length === 0) return [clientX, true];
242
+ const touch = ev.changedTouches[0];
243
+ clientX = touch.pageX;
244
+ } else if (dragType === 'init') {
245
+ if (ev.buttons !== undefined && ev.buttons !== 1) return [clientX, true];
246
+ clientX = ev.clientX;
247
+ } else {
248
+ clientX = ev.clientX;
249
+ }
250
+ return [clientX, false];
251
+ };
252
+ stopDrag = ev => {
253
+ if (ev?.stopPropagation) ev.stopPropagation();
254
+ const {
255
+ schedulerData,
256
+ newEvent,
257
+ resourceEvents
258
+ } = this.props;
259
+ const {
260
+ headers,
261
+ events,
262
+ config,
263
+ cellUnit,
264
+ localeDayjs
265
+ } = schedulerData;
266
+ const {
267
+ leftIndex,
268
+ rightIndex
269
+ } = this.state;
270
+ this.cleanupDragInteraction();
271
+ if (headers.length === 0 || !resourceEvents.headerItems || resourceEvents.headerItems.length === 0) {
272
+ this.setState({
274
273
  startX: 0,
275
274
  leftIndex: 0,
276
275
  left: 0,
@@ -281,455 +280,394 @@ var ResourceEvents = /*#__PURE__*/function (_PureComponent) {
281
280
  startRowIndex: -1,
282
281
  endRowIndex: -1
283
282
  });
284
- _this.emitSelectionChange(false, [], {
283
+ this.emitSelectionChange(false, [], {
285
284
  left: 0,
286
285
  width: 0
287
286
  });
288
- var hasConflict = false;
289
- if (config.checkConflict) {
290
- var start = localeDayjs(new Date(startTime));
291
- var end = localeDayjs(endTime);
292
- events.forEach(function (e) {
293
- var eventResourceIds = e.resourceIds || [e.resourceId];
294
- var hasOverlap = selectedResourceIds.some(function (selectedId) {
295
- return eventResourceIds.includes(selectedId);
296
- });
297
- if (hasOverlap) {
298
- var eStart = localeDayjs(e.start);
299
- var eEnd = localeDayjs(e.end);
300
- if (start >= eStart && start < eEnd || end > eStart && end <= eEnd || eStart >= start && eStart < end || eEnd > start && eEnd <= end) hasConflict = true;
301
- }
302
- });
303
- }
304
- if (hasConflict) {
305
- var conflictOccurred = _this.props.conflictOccurred;
306
- if (conflictOccurred !== undefined) {
307
- conflictOccurred(schedulerData, 'New', {
308
- id: undefined,
309
- start: startTime,
310
- end: endTime,
311
- resourceId: slotId,
312
- // Keep for backward compatibility
313
- resourceIds: selectedResourceIds,
314
- // Add multi-resource support
315
- slotId: slotId,
316
- slotName: slotName,
317
- title: undefined
318
- }, _default2.DnDTypes.EVENT, slotId, slotName, startTime, endTime);
319
- } else {
320
- console.log('Conflict occurred, set conflictOccurred func in Scheduler to handle it');
321
- }
322
- } else if (newEvent !== undefined) {
323
- // Pass resourceIds for multi-resource events
324
- newEvent(schedulerData, slotId, slotName, startTime, endTime, undefined, {
325
- resourceIds: selectedResourceIds.length > 1 ? selectedResourceIds : undefined
326
- });
327
- }
328
- });
329
- _defineProperty(_this, "cancelDrag", function (ev) {
330
- if (ev !== null && ev !== void 0 && ev.stopPropagation) ev.stopPropagation();
331
- var isSelecting = _this.state.isSelecting;
332
- if (isSelecting) {
333
- _this.cleanupDragInteraction();
334
- _this.setState({
335
- startX: 0,
336
- leftIndex: 0,
337
- left: 0,
338
- rightIndex: 0,
339
- width: 0,
340
- isSelecting: false,
341
- originalStartRowIndex: -1,
342
- startRowIndex: -1,
343
- endRowIndex: -1
344
- });
345
- _this.emitSelectionChange(false, [], {
346
- left: 0,
347
- width: 0
348
- });
349
- }
350
- });
351
- _defineProperty(_this, "emitSelectionChange", function (isSelecting, selectedResourceIds) {
352
- var preview = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
353
- var onSelectionChange = _this.props.onSelectionChange;
354
- if (onSelectionChange) {
355
- onSelectionChange(isSelecting, selectedResourceIds, preview);
356
- }
357
- });
358
- _defineProperty(_this, "onAddMoreClick", function (headerItem) {
359
- var _this$props2 = _this.props,
360
- onSetAddMoreState = _this$props2.onSetAddMoreState,
361
- resourceEvents = _this$props2.resourceEvents,
362
- schedulerData = _this$props2.schedulerData;
363
- if (onSetAddMoreState) {
364
- var config = schedulerData.config;
365
- var cellWidth = schedulerData.getContentCellWidth();
366
- var index = resourceEvents.headerItems.indexOf(headerItem);
367
- if (index !== -1) {
368
- var left = index * (cellWidth - 1);
369
- var pos = (0, _utility.getPos)(_this.eventContainer);
370
- left += pos.x;
371
- var top = pos.y;
372
- var height = (headerItem.count + 1) * config.eventItemLineHeight + 20;
373
- onSetAddMoreState({
374
- headerItem: headerItem,
375
- left: left,
376
- top: top,
377
- height: height
378
- });
379
- }
380
- }
381
- });
382
- _defineProperty(_this, "eventContainerRef", function (element) {
383
- _this.eventContainer = element;
384
- // Also set the drop ref if it exists
385
- var dropRef = _this.props.dropRef;
386
- if (dropRef) {
387
- dropRef(element);
388
- }
389
- });
390
- _defineProperty(_this, "getResourceRowIndex", function (slotId) {
391
- return _this.getDisplayRenderData().findIndex(function (row) {
392
- return row.slotId === slotId;
393
- });
394
- });
395
- _defineProperty(_this, "getDisplayRenderData", function () {
396
- var schedulerData = _this.props.schedulerData;
397
- return schedulerData.renderData.filter(function (row) {
398
- return row.render;
399
- });
400
- });
401
- _defineProperty(_this, "getSelectedResourceIds", function (startOverride, endOverride) {
402
- var _this$state3 = _this.state,
403
- startRowIndex = _this$state3.startRowIndex,
404
- endRowIndex = _this$state3.endRowIndex;
405
- var displayRenderData = _this.getDisplayRenderData();
406
- var from = startOverride !== undefined ? startOverride : startRowIndex;
407
- var to = endOverride !== undefined ? endOverride : endRowIndex;
408
- if (from === -1 || to === -1) {
409
- return [];
410
- }
411
- var selectedResourceIds = [];
412
- for (var i = from; i <= to; i++) {
413
- var row = displayRenderData[i];
414
- if (row && !row.groupOnly) {
415
- selectedResourceIds.push(row.slotId);
416
- }
417
- }
418
- return selectedResourceIds;
419
- });
420
- _this.state = {
421
- isSelecting: false,
287
+ return;
288
+ }
289
+ const maxLeftIndex = headers.length - 1;
290
+ const safeLeftIndex = Math.max(0, Math.min(leftIndex, maxLeftIndex));
291
+ const maxRightIndex = Math.min(headers.length, resourceEvents.headerItems.length);
292
+ let safeRightIndex = Math.max(1, rightIndex, safeLeftIndex + 1);
293
+ safeRightIndex = Math.min(safeRightIndex, maxRightIndex);
294
+ const startTime = headers[safeLeftIndex].time;
295
+ let endTime = resourceEvents.headerItems[safeRightIndex - 1].end;
296
+ if (cellUnit !== CellUnit.Hour) {
297
+ endTime = localeDayjs(new Date(resourceEvents.headerItems[safeRightIndex - 1].start)).hour(23).minute(59).second(59).format(DATETIME_FORMAT);
298
+ }
299
+
300
+ // Get selected resource IDs
301
+ const selectedResourceIds = this.getSelectedResourceIds();
302
+ const slotId = selectedResourceIds.length > 0 ? selectedResourceIds[0] : resourceEvents.slotId;
303
+ const slotName = selectedResourceIds.length > 0 ? schedulerData.getResourceById(slotId)?.name || slotId : resourceEvents.slotName;
304
+ this.setState({
305
+ startX: 0,
306
+ leftIndex: 0,
422
307
  left: 0,
308
+ rightIndex: 0,
423
309
  width: 0,
424
- // Add vertical selection tracking
310
+ isSelecting: false,
425
311
  originalStartRowIndex: -1,
426
312
  startRowIndex: -1,
427
313
  endRowIndex: -1
428
- };
429
- _this.supportTouch = false; // 'ontouchstart' in window;
430
- return _this;
431
- }
432
- _inherits(ResourceEvents, _PureComponent);
433
- return _createClass(ResourceEvents, [{
434
- key: "componentDidMount",
435
- value: function componentDidMount() {
436
- var schedulerData = this.props.schedulerData;
437
- var config = schedulerData.config;
438
- this.supportTouch = 'ontouchstart' in window;
439
- if (config.creatable === true) {
440
- this.supportTouchHelper();
441
- }
442
- }
443
- }, {
444
- key: "componentDidUpdate",
445
- value: function componentDidUpdate(prevProps) {
446
- var _prevProps$schedulerD, _this$props$scheduler;
447
- 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;
448
- 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;
449
- if (prevCreatable !== currentCreatable) {
450
- this.supportTouchHelper('remove');
451
- if (currentCreatable) {
452
- this.supportTouchHelper();
314
+ });
315
+ this.emitSelectionChange(false, [], {
316
+ left: 0,
317
+ width: 0
318
+ });
319
+ let hasConflict = false;
320
+ if (config.checkConflict) {
321
+ const start = localeDayjs(new Date(startTime));
322
+ const end = localeDayjs(endTime);
323
+ events.forEach(e => {
324
+ const eventResourceIds = e.resourceIds || [e.resourceId];
325
+ const hasOverlap = selectedResourceIds.some(selectedId => eventResourceIds.includes(selectedId));
326
+ if (hasOverlap) {
327
+ const eStart = localeDayjs(e.start);
328
+ const eEnd = localeDayjs(e.end);
329
+ if (start >= eStart && start < eEnd || end > eStart && end <= eEnd || eStart >= start && eStart < end || eEnd > start && eEnd <= end) hasConflict = true;
453
330
  }
331
+ });
332
+ }
333
+ if (hasConflict) {
334
+ const {
335
+ conflictOccurred
336
+ } = this.props;
337
+ if (conflictOccurred !== undefined) {
338
+ conflictOccurred(schedulerData, 'New', {
339
+ id: undefined,
340
+ start: startTime,
341
+ end: endTime,
342
+ resourceId: slotId,
343
+ // Keep for backward compatibility
344
+ resourceIds: selectedResourceIds,
345
+ // Add multi-resource support
346
+ slotId,
347
+ slotName,
348
+ title: undefined
349
+ }, DnDTypes.EVENT, slotId, slotName, startTime, endTime);
350
+ } else {
351
+ console.log('Conflict occurred, set conflictOccurred func in Scheduler to handle it');
454
352
  }
353
+ } else if (newEvent !== undefined) {
354
+ // Pass resourceIds for multi-resource events
355
+ newEvent(schedulerData, slotId, slotName, startTime, endTime, undefined, {
356
+ resourceIds: selectedResourceIds.length > 1 ? selectedResourceIds : undefined
357
+ });
455
358
  }
456
- }, {
457
- key: "componentWillUnmount",
458
- value: function componentWillUnmount() {
359
+ };
360
+ cancelDrag = ev => {
361
+ if (ev?.stopPropagation) ev.stopPropagation();
362
+ const {
363
+ isSelecting
364
+ } = this.state;
365
+ if (isSelecting) {
459
366
  this.cleanupDragInteraction();
460
- this.supportTouchHelper('remove');
367
+ this.setState({
368
+ startX: 0,
369
+ leftIndex: 0,
370
+ left: 0,
371
+ rightIndex: 0,
372
+ width: 0,
373
+ isSelecting: false,
374
+ originalStartRowIndex: -1,
375
+ startRowIndex: -1,
376
+ endRowIndex: -1
377
+ });
461
378
  this.emitSelectionChange(false, [], {
462
379
  left: 0,
463
380
  width: 0
464
381
  });
465
382
  }
466
- }, {
467
- key: "render",
468
- value: function render() {
469
- var _this$props$selection,
470
- _this$props$selection2,
471
- _this$props$selection3,
472
- _this2 = this;
473
- var _this$props3 = this.props,
474
- resourceEvents = _this$props3.resourceEvents,
475
- schedulerData = _this$props3.schedulerData,
476
- dndSource = _this$props3.dndSource;
477
- var cellUnit = schedulerData.cellUnit,
478
- startDate = schedulerData.startDate,
479
- endDate = schedulerData.endDate,
480
- config = schedulerData.config,
481
- localeDayjs = schedulerData.localeDayjs;
482
- var _this$state4 = this.state,
483
- isSelecting = _this$state4.isSelecting,
484
- left = _this$state4.left,
485
- width = _this$state4.width,
486
- startRowIndex = _this$state4.startRowIndex,
487
- endRowIndex = _this$state4.endRowIndex;
488
- var cellWidth = schedulerData.getContentCellWidth();
489
- var cellMaxEvents = schedulerData.getCellMaxEvents();
490
- var rowWidth = schedulerData.getContentTableWidth();
491
- var selectedArea = isSelecting ? /*#__PURE__*/(0, _jsxRuntime.jsx)(_SelectedArea["default"], {
492
- schedulerData: schedulerData,
493
- left: left,
494
- width: width
495
- }) : /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {});
496
- var sharedSelecting = (_this$props$selection = this.props.selectionPreview) === null || _this$props$selection === void 0 ? void 0 : _this$props$selection.isSelecting;
497
- var isSharedSelectedRow = sharedSelecting && this.props.isRowSelected;
498
- var sharedLeft = ((_this$props$selection2 = this.props.selectionPreview) === null || _this$props$selection2 === void 0 ? void 0 : _this$props$selection2.left) || 0;
499
- var sharedWidth = ((_this$props$selection3 = this.props.selectionPreview) === null || _this$props$selection3 === void 0 ? void 0 : _this$props$selection3.width) || 0;
500
- var sharedSelectedArea = !isSelecting && isSharedSelectedRow ? /*#__PURE__*/(0, _jsxRuntime.jsx)(_SelectedArea["default"], {
501
- schedulerData: schedulerData,
502
- left: sharedLeft,
503
- width: sharedWidth
504
- }) : null;
383
+ };
384
+ emitSelectionChange = (isSelecting, selectedResourceIds, preview = {}) => {
385
+ const {
386
+ onSelectionChange
387
+ } = this.props;
388
+ if (onSelectionChange) {
389
+ onSelectionChange(isSelecting, selectedResourceIds, preview);
390
+ }
391
+ };
392
+ onAddMoreClick = headerItem => {
393
+ const {
394
+ onSetAddMoreState,
395
+ resourceEvents,
396
+ schedulerData
397
+ } = this.props;
398
+ if (onSetAddMoreState) {
399
+ const {
400
+ config
401
+ } = schedulerData;
402
+ const cellWidth = schedulerData.getContentCellWidth();
403
+ const index = resourceEvents.headerItems.indexOf(headerItem);
404
+ if (index !== -1) {
405
+ let left = index * (cellWidth - 1);
406
+ const pos = getPos(this.eventContainer);
407
+ left += pos.x;
408
+ const top = pos.y;
409
+ const height = (headerItem.count + 1) * config.eventItemLineHeight + 20;
410
+ onSetAddMoreState({
411
+ headerItem,
412
+ left,
413
+ top,
414
+ height
415
+ });
416
+ }
417
+ }
418
+ };
419
+ eventContainerRef = element => {
420
+ this.eventContainer = element;
421
+ // Also set the drop ref if it exists
422
+ const {
423
+ dropRef
424
+ } = this.props;
425
+ if (dropRef) {
426
+ dropRef(element);
427
+ }
428
+ };
429
+ getResourceRowIndex = slotId => {
430
+ return this.getDisplayRenderData().findIndex(row => row.slotId === slotId);
431
+ };
432
+ getDisplayRenderData = () => {
433
+ const {
434
+ schedulerData
435
+ } = this.props;
436
+ return schedulerData.renderData.filter(row => row.render);
437
+ };
438
+ getSelectedResourceIds = (startOverride, endOverride) => {
439
+ const {
440
+ startRowIndex,
441
+ endRowIndex
442
+ } = this.state;
443
+ const displayRenderData = this.getDisplayRenderData();
444
+ const from = startOverride !== undefined ? startOverride : startRowIndex;
445
+ const to = endOverride !== undefined ? endOverride : endRowIndex;
446
+ if (from === -1 || to === -1) {
447
+ return [];
448
+ }
449
+ const selectedResourceIds = [];
450
+ for (let i = from; i <= to; i++) {
451
+ const row = displayRenderData[i];
452
+ if (row && !row.groupOnly) {
453
+ selectedResourceIds.push(row.slotId);
454
+ }
455
+ }
456
+ return selectedResourceIds;
457
+ };
458
+ render() {
459
+ const {
460
+ resourceEvents,
461
+ schedulerData,
462
+ dndSource
463
+ } = this.props;
464
+ const {
465
+ cellUnit,
466
+ startDate,
467
+ endDate,
468
+ config,
469
+ localeDayjs
470
+ } = schedulerData;
471
+ const {
472
+ isSelecting,
473
+ left,
474
+ width,
475
+ startRowIndex,
476
+ endRowIndex
477
+ } = this.state;
478
+ const cellWidth = schedulerData.getContentCellWidth();
479
+ const cellMaxEvents = schedulerData.getCellMaxEvents();
480
+ const rowWidth = schedulerData.getContentTableWidth();
481
+ const selectedArea = isSelecting ? /*#__PURE__*/_jsx(SelectedArea, {
482
+ schedulerData: schedulerData,
483
+ left: left,
484
+ width: width
485
+ }) : /*#__PURE__*/_jsx("div", {});
486
+ const sharedSelecting = this.props.selectionPreview?.isSelecting;
487
+ const isSharedSelectedRow = sharedSelecting && this.props.isRowSelected;
488
+ const sharedLeft = this.props.selectionPreview?.left || 0;
489
+ const sharedWidth = this.props.selectionPreview?.width || 0;
490
+ const sharedSelectedArea = !isSelecting && isSharedSelectedRow ? /*#__PURE__*/_jsx(SelectedArea, {
491
+ schedulerData: schedulerData,
492
+ left: sharedLeft,
493
+ width: sharedWidth
494
+ }) : null;
505
495
 
506
- // Add vertical selection overlay
507
- var verticalSelectionOverlay = isSelecting && startRowIndex !== endRowIndex ? /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
508
- className: "vertical-selection-overlay"
509
- }) : null;
510
- var eventList = [];
511
- resourceEvents.headerItems.forEach(function (headerItem, index) {
512
- if (headerItem.count > 0 || headerItem.summary !== undefined) {
513
- var isTop = config.summaryPos === _default2.SummaryPos.TopRight || config.summaryPos === _default2.SummaryPos.Top || config.summaryPos === _default2.SummaryPos.TopLeft;
514
- var marginTop = resourceEvents.hasSummary && isTop ? 1 + config.eventItemLineHeight : 1;
515
- var renderEventsMaxIndex = headerItem.addMore === 0 ? cellMaxEvents : headerItem.addMoreIndex;
516
- headerItem.events.forEach(function (evt, idx) {
517
- if (idx < renderEventsMaxIndex && evt !== undefined && evt.render) {
518
- var durationStart = localeDayjs(new Date(startDate));
519
- var durationEnd = localeDayjs(endDate);
520
- if (cellUnit === _default2.CellUnit.Hour) {
521
- durationStart = localeDayjs(new Date(startDate)).add(config.dayStartFrom, 'hours');
522
- durationEnd = localeDayjs(endDate).add(config.dayStopTo + 1, 'hours');
523
- }
524
- var eventStart = localeDayjs(evt.eventItem.start);
525
- var eventEnd = localeDayjs(evt.eventItem.end);
526
- var isStart = eventStart >= durationStart;
527
- var isEnd = eventEnd <= durationEnd;
528
- var _left = index * cellWidth + (index > 0 ? 2 : 3);
529
- var _width = evt.span * cellWidth - (index > 0 ? 5 : 6) > 0 ? evt.span * cellWidth - (index > 0 ? 5 : 6) : 0;
530
- var dayStart = localeDayjs(new Date(headerItem.start)).startOf('day');
531
- var dayDurationMinutes = 1440;
532
- var baseCellWidth = cellWidth - (index > 0 ? 5 : 6);
533
- if (cellUnit === _default2.CellUnit.Day) {
534
- if (evt.span === 1) {
535
- var startOffsetMinutes = eventStart.diff(dayStart, 'minute');
536
- var eventDurationMinutes = eventEnd.diff(eventStart, 'minute');
537
- var startPercentage = startOffsetMinutes / dayDurationMinutes;
538
- var durationPercentage = eventDurationMinutes / dayDurationMinutes;
539
- var leftOffset = baseCellWidth * startPercentage;
540
- var eventWidth = baseCellWidth * durationPercentage;
541
- _left = index * cellWidth + (index > 0 ? 2 : 3) + leftOffset;
542
- _width = Math.max(1, eventWidth); // ensure minimum width of 1px
543
- } else {
544
- var headerStart = localeDayjs(new Date(headerItem.start));
545
- var headerEnd = localeDayjs(new Date(headerItem.end));
546
- var isFirstDay = eventStart >= headerStart && eventStart < headerEnd;
547
- if (isFirstDay) {
548
- var eventStartDayStart = eventStart.startOf('day');
549
- var eventEndDayEnd = eventEnd.endOf('day');
550
- var totalSpanMinutes = eventEndDayEnd.diff(eventStartDayStart, 'minute');
551
- var eventStartOffsetMinutes = eventStart.diff(eventStartDayStart, 'minute');
552
- var _eventDurationMinutes = eventEnd.diff(eventStart, 'minute');
553
- var _startPercentage = eventStartOffsetMinutes / dayDurationMinutes;
554
- var _durationPercentage = totalSpanMinutes > 0 ? _eventDurationMinutes / totalSpanMinutes : 1;
555
- var totalWidth = evt.span * cellWidth - (index > 0 ? 5 : 6);
556
- var _leftOffset = cellWidth * _startPercentage;
557
- var _eventWidth = totalWidth * _durationPercentage;
558
- _left = index * cellWidth + (index > 0 ? 2 : 3) + _leftOffset;
559
- _width = Math.max(1, _eventWidth);
560
- }
561
- }
562
- } else {
563
- _width = evt.span * cellWidth - (index > 0 ? 5 : 6) > 0 ? evt.span * cellWidth - (index > 0 ? 5 : 6) : 0;
564
- }
565
- var top = marginTop + idx * config.eventItemLineHeight;
566
- var eventKey = "".concat(evt.eventItem.id, "_").concat(resourceEvents.slotId, "_").concat(index);
567
- var eventItem = /*#__PURE__*/(0, _jsxRuntime.jsx)(_EventItem["default"], {
568
- schedulerData: schedulerData,
569
- eventItem: evt.eventItem,
570
- dndSource: dndSource,
571
- isStart: isStart,
572
- isEnd: isEnd,
573
- isInPopover: false,
574
- left: _left,
575
- width: _width,
576
- top: top,
577
- leftIndex: index,
578
- rightIndex: index + evt.span
579
- // Passing through functional props
580
- ,
581
- eventItemClick: _this2.props.eventItemClick,
582
- viewEventClick: _this2.props.viewEventClick,
583
- viewEventText: _this2.props.viewEventText,
584
- viewEvent2Click: _this2.props.viewEvent2Click,
585
- viewEvent2Text: _this2.props.viewEvent2Text,
586
- eventItemTemplateResolver: _this2.props.eventItemTemplateResolver,
587
- subtitleGetter: _this2.props.subtitleGetter,
588
- updateEventStart: _this2.props.updateEventStart,
589
- updateEventEnd: _this2.props.updateEventEnd,
590
- moveEvent: _this2.props.moveEvent,
591
- conflictOccurred: _this2.props.conflictOccurred
592
- }, eventKey);
593
- eventList.push(eventItem);
496
+ // Add vertical selection overlay
497
+ const verticalSelectionOverlay = isSelecting && startRowIndex !== endRowIndex ? /*#__PURE__*/_jsx("div", {
498
+ className: "vertical-selection-overlay"
499
+ }) : null;
500
+ const eventList = [];
501
+ resourceEvents.headerItems.forEach((headerItem, index) => {
502
+ if (headerItem.count > 0 || headerItem.summary !== undefined) {
503
+ const isTop = config.summaryPos === SummaryPos.TopRight || config.summaryPos === SummaryPos.Top || config.summaryPos === SummaryPos.TopLeft;
504
+ const marginTop = resourceEvents.hasSummary && isTop ? 1 + config.eventItemLineHeight : 1;
505
+ const renderEventsMaxIndex = headerItem.addMore === 0 ? cellMaxEvents : headerItem.addMoreIndex;
506
+ headerItem.events.forEach((evt, idx) => {
507
+ if (idx < renderEventsMaxIndex && evt !== undefined && evt.render) {
508
+ let durationStart = localeDayjs(new Date(startDate));
509
+ let durationEnd = localeDayjs(endDate);
510
+ if (cellUnit === CellUnit.Hour) {
511
+ durationStart = localeDayjs(new Date(startDate)).add(config.dayStartFrom, 'hours');
512
+ durationEnd = localeDayjs(endDate).add(config.dayStopTo + 1, 'hours');
513
+ }
514
+ const eventStart = normalizeEventStart(evt.eventItem.start);
515
+ const eventEnd = normalizeEventEnd(evt.eventItem.end);
516
+ const isStart = eventStart >= durationStart;
517
+ const isEnd = eventEnd <= durationEnd;
518
+ let left = index * cellWidth + (index > 0 ? 2 : 3);
519
+ let width = evt.span * cellWidth - (index > 0 ? 5 : 6) > 0 ? evt.span * cellWidth - (index > 0 ? 5 : 6) : 0;
520
+ if (cellUnit === CellUnit.Day || cellUnit === CellUnit.Hour) {
521
+ // Clamp the event to the cells it covers, then position it proportionally inside the
522
+ // first and last cell (each cell's own duration, so DST days and sub-slot times are handled).
523
+ const lastHeaderItem = resourceEvents.headerItems[index + evt.span - 1] ?? headerItem;
524
+ const firstCellStart = localeDayjs(new Date(headerItem.start));
525
+ const firstCellEnd = localeDayjs(new Date(headerItem.end));
526
+ const lastCellStart = localeDayjs(new Date(lastHeaderItem.start));
527
+ const lastCellEnd = localeDayjs(new Date(lastHeaderItem.end));
528
+ const clampedStart = eventStart.isAfter(firstCellStart) ? eventStart : firstCellStart;
529
+ const clampedEnd = eventEnd.isBefore(lastCellEnd) ? eventEnd : lastCellEnd;
530
+ const startFraction = clampedStart.diff(firstCellStart) / firstCellEnd.diff(firstCellStart);
531
+ const endFraction = clampedEnd.diff(lastCellStart) / lastCellEnd.diff(lastCellStart);
532
+ const usableWidth = evt.span * cellWidth - (index > 0 ? 5 : 6);
533
+ left = index * cellWidth + (index > 0 ? 2 : 3) + usableWidth * startFraction / evt.span;
534
+ width = Math.max(1, usableWidth * (evt.span - 1 + endFraction - startFraction) / evt.span);
535
+ } else {
536
+ width = evt.span * cellWidth - (index > 0 ? 5 : 6) > 0 ? evt.span * cellWidth - (index > 0 ? 5 : 6) : 0;
594
537
  }
595
- });
596
- if (headerItem.addMore > 0) {
597
- var _left2 = index * cellWidth + (index > 0 ? 2 : 3);
598
- var _width2 = cellWidth - (index > 0 ? 5 : 6);
599
- var top = marginTop + headerItem.addMoreIndex * config.eventItemLineHeight;
600
- var addMoreItem = /*#__PURE__*/(0, _jsxRuntime.jsx)(_AddMore["default"], {
538
+ const top = marginTop + idx * config.eventItemLineHeight;
539
+ const eventKey = `${evt.eventItem.id}_${resourceEvents.slotId}_${index}`;
540
+ const eventItem = /*#__PURE__*/_jsx(EventItem, {
601
541
  schedulerData: schedulerData,
602
- headerItem: headerItem,
603
- number: headerItem.addMore,
604
- left: _left2,
605
- width: _width2,
542
+ eventItem: evt.eventItem,
543
+ dndSource: dndSource,
544
+ isStart: isStart,
545
+ isEnd: isEnd,
546
+ isInPopover: false,
547
+ left: left,
548
+ width: width,
606
549
  top: top,
607
- clickAction: _this2.onAddMoreClick
608
- }, "add-more-".concat(headerItem.time));
609
- eventList.push(addMoreItem);
610
- }
611
- if (headerItem.summary !== undefined) {
612
- var _top = isTop ? 1 : resourceEvents.rowHeight - config.eventItemLineHeight + 1;
613
- var _left3 = index * cellWidth + (index > 0 ? 2 : 3);
614
- var _width3 = cellWidth - (index > 0 ? 5 : 6);
615
- var key = "".concat(resourceEvents.slotId, "_").concat(headerItem.time);
616
- var summary = /*#__PURE__*/(0, _jsxRuntime.jsx)(_Summary["default"], {
617
- schedulerData: schedulerData,
618
- summary: headerItem.summary,
619
- left: _left3,
620
- width: _width3,
621
- top: _top
622
- }, key);
623
- eventList.push(summary);
550
+ leftIndex: index,
551
+ rightIndex: index + evt.span
552
+ // Passing through functional props
553
+ ,
554
+ eventItemClick: this.props.eventItemClick,
555
+ viewEventClick: this.props.viewEventClick,
556
+ viewEventText: this.props.viewEventText,
557
+ viewEvent2Click: this.props.viewEvent2Click,
558
+ viewEvent2Text: this.props.viewEvent2Text,
559
+ eventItemTemplateResolver: this.props.eventItemTemplateResolver,
560
+ subtitleGetter: this.props.subtitleGetter,
561
+ updateEventStart: this.props.updateEventStart,
562
+ updateEventEnd: this.props.updateEventEnd,
563
+ moveEvent: this.props.moveEvent,
564
+ conflictOccurred: this.props.conflictOccurred
565
+ }, eventKey);
566
+ eventList.push(eventItem);
624
567
  }
568
+ });
569
+ if (headerItem.addMore > 0) {
570
+ const left = index * cellWidth + (index > 0 ? 2 : 3);
571
+ const width = cellWidth - (index > 0 ? 5 : 6);
572
+ const top = marginTop + headerItem.addMoreIndex * config.eventItemLineHeight;
573
+ const addMoreItem = /*#__PURE__*/_jsx(AddMore, {
574
+ schedulerData: schedulerData,
575
+ headerItem: headerItem,
576
+ number: headerItem.addMore,
577
+ left: left,
578
+ width: width,
579
+ top: top,
580
+ clickAction: this.onAddMoreClick
581
+ }, `add-more-${headerItem.time}`);
582
+ eventList.push(addMoreItem);
625
583
  }
626
- });
627
- var eventContainer = /*#__PURE__*/(0, _jsxRuntime.jsxs)("div", {
628
- ref: this.eventContainerRef,
629
- className: "event-container",
584
+ if (headerItem.summary !== undefined) {
585
+ const top = isTop ? 1 : resourceEvents.rowHeight - config.eventItemLineHeight + 1;
586
+ const left = index * cellWidth + (index > 0 ? 2 : 3);
587
+ const width = cellWidth - (index > 0 ? 5 : 6);
588
+ const key = `${resourceEvents.slotId}_${headerItem.time}`;
589
+ const summary = /*#__PURE__*/_jsx(Summary, {
590
+ schedulerData: schedulerData,
591
+ summary: headerItem.summary,
592
+ left: left,
593
+ width: width,
594
+ top: top
595
+ }, key);
596
+ eventList.push(summary);
597
+ }
598
+ }
599
+ });
600
+ const eventContainer = /*#__PURE__*/_jsxs("div", {
601
+ ref: this.eventContainerRef,
602
+ className: "event-container",
603
+ style: {
604
+ height: resourceEvents.rowHeight
605
+ },
606
+ children: [selectedArea, sharedSelectedArea, verticalSelectionOverlay, eventList]
607
+ });
608
+ return /*#__PURE__*/_jsx("tr", {
609
+ children: /*#__PURE__*/_jsx("td", {
630
610
  style: {
631
- height: resourceEvents.rowHeight
611
+ width: rowWidth
632
612
  },
633
- children: [selectedArea, sharedSelectedArea, verticalSelectionOverlay, eventList]
634
- });
635
- return /*#__PURE__*/(0, _jsxRuntime.jsx)("tr", {
636
- children: /*#__PURE__*/(0, _jsxRuntime.jsx)("td", {
637
- style: {
638
- width: rowWidth
639
- },
640
- children: eventContainer
641
- })
642
- });
643
- }
644
- }]);
645
- }(_react.PureComponent); // Wrapper component to use useDrop hook
646
- _defineProperty(ResourceEvents, "propTypes", {
647
- resourceEvents: _propTypes.PropTypes.object.isRequired,
648
- schedulerData: _propTypes.PropTypes.object.isRequired,
649
- schedulerDataVersion: _propTypes.PropTypes.number,
650
- dndSource: _propTypes.PropTypes.object.isRequired,
651
- onSetAddMoreState: _propTypes.PropTypes.func,
652
- updateEventStart: _propTypes.PropTypes.func,
653
- updateEventEnd: _propTypes.PropTypes.func,
654
- moveEvent: _propTypes.PropTypes.func,
655
- movingEvent: _propTypes.PropTypes.func,
656
- conflictOccurred: _propTypes.PropTypes.func,
657
- subtitleGetter: _propTypes.PropTypes.func,
658
- eventItemClick: _propTypes.PropTypes.func,
659
- viewEventClick: _propTypes.PropTypes.func,
660
- viewEventText: _propTypes.PropTypes.string,
661
- viewEvent2Click: _propTypes.PropTypes.func,
662
- viewEvent2Text: _propTypes.PropTypes.string,
663
- newEvent: _propTypes.PropTypes.func,
664
- eventItemTemplateResolver: _propTypes.PropTypes.func,
665
- onSelectionChange: _propTypes.PropTypes.func,
666
- isRowSelected: _propTypes.PropTypes.bool,
667
- selectionPreview: _propTypes.PropTypes.shape({
668
- isSelecting: _propTypes.PropTypes.bool,
669
- left: _propTypes.PropTypes.number,
670
- width: _propTypes.PropTypes.number
671
- })
672
- });
673
- var ResourceEventsWithDnD = function ResourceEventsWithDnD(props) {
674
- var schedulerData = props.schedulerData,
675
- dndContext = props.dndContext;
676
- var config = schedulerData.config;
677
- var componentRef = _react["default"].useRef(null);
678
- var propsRef = _react["default"].useRef(props);
613
+ children: eventContainer
614
+ })
615
+ });
616
+ }
617
+ }
618
+
619
+ // Wrapper component to use useDrop hook
620
+ const ResourceEventsWithDnD = props => {
621
+ const {
622
+ schedulerData,
623
+ dndContext
624
+ } = props;
625
+ const {
626
+ config
627
+ } = schedulerData;
628
+ const componentRef = React.useRef(null);
629
+ const propsRef = React.useRef(props);
679
630
 
680
631
  // Keep propsRef up to date
681
- _react["default"].useEffect(function () {
632
+ React.useEffect(() => {
682
633
  propsRef.current = props;
683
- // biome-ignore lint/correctness/useExhaustiveDependencies: propsRef is intended to always hold the latest props
684
634
  }, [props]);
685
635
 
686
636
  // Always call useDrop unconditionally (Rules of Hooks)
687
637
  // Disable functionality when drag and drop is not enabled
688
- var _useDrop = (0, _reactDnd.useDrop)(function () {
689
- // If drag and drop is disabled, return a no-op spec
690
- if (!config.dragAndDropEnabled || !dndContext) {
691
- return {
692
- accept: [],
693
- collect: function collect() {
694
- return {
695
- isOver: false,
696
- canDrop: false
697
- };
698
- }
699
- };
700
- }
701
- var spec = dndContext.getDropSpec();
638
+ const [{
639
+ isOver,
640
+ canDrop
641
+ }, dropRef] = useDrop(() => {
642
+ // If drag and drop is disabled, return a no-op spec
643
+ if (!config.dragAndDropEnabled || !dndContext) {
702
644
  return {
703
- accept: _toConsumableArray(dndContext.sourceMap.keys()),
704
- drop: function drop(_item, monitor) {
705
- return spec.drop(propsRef.current, monitor, componentRef.current);
706
- },
707
- hover: function hover(_item, monitor) {
708
- return spec.hover(propsRef.current, monitor, componentRef.current);
709
- },
710
- canDrop: function canDrop(_item, monitor) {
711
- return spec.canDrop(propsRef.current, monitor);
712
- },
713
- collect: function collect(monitor) {
714
- return {
715
- isOver: monitor.isOver(),
716
- canDrop: monitor.canDrop()
717
- };
718
- }
645
+ accept: [],
646
+ collect: () => ({
647
+ isOver: false,
648
+ canDrop: false
649
+ })
719
650
  };
720
- }, [dndContext, config.dragAndDropEnabled]),
721
- _useDrop2 = _slicedToArray(_useDrop, 2),
722
- _useDrop2$ = _useDrop2[0],
723
- isOver = _useDrop2$.isOver,
724
- canDrop = _useDrop2$.canDrop,
725
- dropRef = _useDrop2[1];
726
- return /*#__PURE__*/(0, _jsxRuntime.jsx)(ResourceEvents, _objectSpread(_objectSpread({
727
- ref: componentRef
728
- }, props), {}, {
651
+ }
652
+ const spec = dndContext.getDropSpec();
653
+ return {
654
+ accept: [...dndContext.sourceMap.keys()],
655
+ drop: (_item, monitor) => spec.drop(propsRef.current, monitor, componentRef.current),
656
+ hover: (_item, monitor) => spec.hover(propsRef.current, monitor, componentRef.current),
657
+ canDrop: (_item, monitor) => spec.canDrop(propsRef.current, monitor),
658
+ collect: monitor => ({
659
+ isOver: monitor.isOver(),
660
+ canDrop: monitor.canDrop()
661
+ })
662
+ };
663
+ }, [dndContext, config.dragAndDropEnabled]);
664
+ return /*#__PURE__*/_jsx(ResourceEvents, {
665
+ ref: componentRef,
666
+ ...props,
729
667
  dropRef: dropRef,
730
668
  isOver: isOver,
731
669
  canDrop: canDrop
732
- }));
670
+ });
733
671
  };
734
672
  ResourceEventsWithDnD.displayName = 'ResourceEventsWithDnD';
735
- var _default = exports["default"] = /*#__PURE__*/_react["default"].memo(ResourceEventsWithDnD);
673
+ export default /*#__PURE__*/React.memo(ResourceEventsWithDnD);