makula-schedule 2.2.6 → 2.3.1

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.
@@ -62,9 +62,6 @@ var DnDContext = exports["default"] = /*#__PURE__*/_createClass(function DnDCont
62
62
  if (cellUnit !== _default.CellUnit.Hour) {
63
63
  endTime = localeDayjs(new Date(resourceEvents.headerItems[leftIndex].start)).hour(23).minute(59).second(59).format(_default.DATETIME_FORMAT);
64
64
  }
65
- if (component && component.clearShadowState) {
66
- component.clearShadowState();
67
- }
68
65
  return {
69
66
  slotId: resourceEvents.slotId,
70
67
  slotName: resourceEvents.slotName,
@@ -130,30 +127,44 @@ var DnDContext = exports["default"] = /*#__PURE__*/_createClass(function DnDCont
130
127
  movingEvent(schedulerData, slotId, slotName, newStart, newEnd, action, type, item);
131
128
  }
132
129
 
133
- // Compute and set drop shadow position
134
- if (config.snapToGrid && component && component.setShadowState) {
135
- var shadowStartDayjs = localeDayjs(newStart);
136
- var shadowEndDayjs = localeDayjs(newEnd);
137
- var shadowLeftIndex = -1;
138
- var shadowSpan = 0;
139
- resourceEvents.headerItems.forEach(function (header, idx) {
140
- var headerStart = new Date(header.start);
141
- var headerEnd = new Date(header.end);
142
- if (headerEnd > shadowStartDayjs.toDate() && headerStart < shadowEndDayjs.toDate()) {
143
- if (shadowLeftIndex === -1) shadowLeftIndex = idx;
144
- shadowSpan += 1;
130
+ // Store preview data for drop indicator on the dragged item
131
+ if (config.dropPreviewEnabled !== false) {
132
+ // Find the header index that matches the adjusted newStart
133
+ var newStartDayjs = localeDayjs(newStart);
134
+ var previewLeftIndex = -1;
135
+ for (var i = 0; i < resourceEvents.headerItems.length; i++) {
136
+ var hStart = localeDayjs(resourceEvents.headerItems[i].start);
137
+ var hEnd = localeDayjs(resourceEvents.headerItems[i].end);
138
+ if (newStartDayjs >= hStart && newStartDayjs < hEnd) {
139
+ previewLeftIndex = i;
140
+ break;
145
141
  }
146
- });
147
- if (shadowLeftIndex >= 0 && shadowSpan > 0) {
148
- var shadowLeft = shadowLeftIndex * cellWidth + (shadowLeftIndex > 0 ? 2 : 3);
149
- var shadowWidth = shadowSpan * cellWidth - (shadowLeftIndex > 0 ? 5 : 6) > 0 ? shadowSpan * cellWidth - (shadowLeftIndex > 0 ? 5 : 6) : 0;
150
- component.setShadowState({
151
- left: shadowLeft,
152
- width: shadowWidth,
153
- top: 1,
154
- bgColor: isEvent ? item.bgColor : config.defaultEventBgColor
155
- });
156
142
  }
143
+ // Fallback: if newStart is before all headers, use first cell
144
+ if (previewLeftIndex < 0) previewLeftIndex = 0;
145
+ var durationMs = localeDayjs(newEnd).diff(newStartDayjs, 'ms');
146
+ var cellDurationMs;
147
+ if (cellUnit === _default.CellUnit.Hour) {
148
+ cellDurationMs = config.minuteStep * 60 * 1000;
149
+ } else {
150
+ cellDurationMs = 24 * 60 * 60 * 1000;
151
+ }
152
+ var cellSpan = Math.max(1, Math.ceil(durationMs / cellDurationMs));
153
+ var bgColor = isEvent ? item.bgColor || config.defaultEventBgColor : config.defaultEventBgColor;
154
+ var title = isEvent ? schedulerData.behaviors.getEventTextFunc(schedulerData, item) : '';
155
+
156
+ // Store on dragged item so collect can read it reliably
157
+ item._dropPreview = {
158
+ slotId: resourceEvents.slotId,
159
+ leftIndex: previewLeftIndex,
160
+ cellSpan: cellSpan,
161
+ bgColor: bgColor,
162
+ title: title,
163
+ eventItemHeight: config.eventItemHeight,
164
+ newStart: newStart,
165
+ newEnd: newEnd,
166
+ eventItem: isEvent ? item : null
167
+ };
157
168
  }
158
169
  },
159
170
  canDrop: function canDrop(props, monitor) {
@@ -182,9 +193,21 @@ var DnDContext = exports["default"] = /*#__PURE__*/_createClass(function DnDCont
182
193
  return spec.canDrop(props, monitor);
183
194
  },
184
195
  collect: function collect(monitor) {
196
+ var isOver = monitor.isOver();
197
+ var canDrop = monitor.canDrop();
198
+ var dropPreview = null;
199
+ if (isOver && canDrop) {
200
+ // Reading getClientOffset subscribes collect to offset changes during drag
201
+ monitor.getClientOffset();
202
+ var item = monitor.getItem();
203
+ if (item && item._dropPreview && item._dropPreview.slotId === props.resourceEvents.slotId) {
204
+ dropPreview = item._dropPreview;
205
+ }
206
+ }
185
207
  return {
186
- isOver: monitor.isOver(),
187
- canDrop: monitor.canDrop()
208
+ isOver: isOver,
209
+ canDrop: canDrop,
210
+ dropPreview: dropPreview
188
211
  };
189
212
  }
190
213
  };
@@ -39,7 +39,7 @@ function _inherits(t, e) { if ("function" != typeof e && null !== e) throw new T
39
39
  function _setPrototypeOf(t, e) { return _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function (t, e) { return t.__proto__ = e, t; }, _setPrototypeOf(t, e); }
40
40
  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; }
41
41
  function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
42
- 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); } // eslint-disable-next-line no-unused-vars
42
+ 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); }
43
43
  var ResourceEvents = /*#__PURE__*/function (_Component) {
44
44
  function ResourceEvents(props) {
45
45
  var _this;
@@ -252,16 +252,6 @@ var ResourceEvents = /*#__PURE__*/function (_Component) {
252
252
  }
253
253
  }
254
254
  });
255
- _defineProperty(_this, "setShadowState", function (shadow) {
256
- _this.setState({
257
- shadowState: shadow
258
- });
259
- });
260
- _defineProperty(_this, "clearShadowState", function () {
261
- _this.setState({
262
- shadowState: null
263
- });
264
- });
265
255
  _defineProperty(_this, "eventContainerRef", function (element) {
266
256
  _this.eventContainer = element;
267
257
  // Also set the drop ref if it exists
@@ -273,8 +263,7 @@ var ResourceEvents = /*#__PURE__*/function (_Component) {
273
263
  _this.state = {
274
264
  isSelecting: false,
275
265
  left: 0,
276
- width: 0,
277
- shadowState: null
266
+ width: 0
278
267
  };
279
268
  _this.supportTouch = false; // 'ontouchstart' in window;
280
269
  return _this;
@@ -317,8 +306,7 @@ var ResourceEvents = /*#__PURE__*/function (_Component) {
317
306
  var _this$state2 = this.state,
318
307
  isSelecting = _this$state2.isSelecting,
319
308
  left = _this$state2.left,
320
- width = _this$state2.width,
321
- shadowState = _this$state2.shadowState;
309
+ width = _this$state2.width;
322
310
  var cellWidth = schedulerData.getContentCellWidth();
323
311
  var cellMaxEvents = schedulerData.getCellMaxEvents();
324
312
  var rowWidth = schedulerData.getContentTableWidth();
@@ -441,23 +429,70 @@ var ResourceEvents = /*#__PURE__*/function (_Component) {
441
429
  }
442
430
  }
443
431
  });
444
- var dropShadow = shadowState && config.snapToGrid ? /*#__PURE__*/_react["default"].createElement("div", {
445
- className: "event-drop-shadow",
446
- style: {
447
- left: shadowState.left,
448
- width: shadowState.width,
449
- top: shadowState.top,
450
- height: config.eventItemHeight,
451
- backgroundColor: shadowState.bgColor || config.defaultEventBgColor
432
+ var dropPreview = this.props.dropPreview;
433
+ var dropPreviewElement = null;
434
+ if (dropPreview && config.dropPreviewEnabled !== false) {
435
+ var idx = dropPreview.leftIndex;
436
+ var previewLeft = idx * cellWidth + (idx > 0 ? 2 : 3);
437
+ var previewWidth = dropPreview.cellSpan * cellWidth - (idx > 0 ? 5 : 6);
438
+ if (cellUnit === _default2.CellUnit.Day) {
439
+ var previewStart = localeDayjs(dropPreview.newStart);
440
+ var previewEnd = localeDayjs(dropPreview.newEnd);
441
+ var dayStart = localeDayjs(resourceEvents.headerItems[idx].start).startOf('day');
442
+ var dayDurationMinutes = 1440;
443
+ var baseCellWidth = cellWidth - (idx > 0 ? 5 : 6);
444
+ if (dropPreview.cellSpan === 1) {
445
+ var startOffsetMinutes = previewStart.diff(dayStart, 'minute');
446
+ var eventDurationMinutes = previewEnd.diff(previewStart, 'minute');
447
+ var startPercentage = startOffsetMinutes / dayDurationMinutes;
448
+ var durationPercentage = eventDurationMinutes / dayDurationMinutes;
449
+ previewLeft = idx * cellWidth + (idx > 0 ? 2 : 3) + baseCellWidth * startPercentage;
450
+ previewWidth = Math.max(1, baseCellWidth * durationPercentage);
451
+ } else {
452
+ var eventStartDayStart = previewStart.startOf('day');
453
+ var eventEndDayEnd = previewEnd.endOf('day');
454
+ var totalSpanMinutes = eventEndDayEnd.diff(eventStartDayStart, 'minute');
455
+ var _startOffsetMinutes = previewStart.diff(eventStartDayStart, 'minute');
456
+ var _eventDurationMinutes2 = previewEnd.diff(previewStart, 'minute');
457
+ var _startPercentage2 = _startOffsetMinutes / dayDurationMinutes;
458
+ var _durationPercentage2 = totalSpanMinutes > 0 ? _eventDurationMinutes2 / totalSpanMinutes : 1;
459
+ var totalWidth = dropPreview.cellSpan * cellWidth - (idx > 0 ? 5 : 6);
460
+ previewLeft = idx * cellWidth + (idx > 0 ? 2 : 3) + cellWidth * _startPercentage2;
461
+ previewWidth = Math.max(1, totalWidth * _durationPercentage2);
462
+ }
452
463
  }
453
- }) : null;
464
+ var eventItemTemplateResolver = this.props.eventItemTemplateResolver;
465
+ var previewContent = /*#__PURE__*/_react["default"].createElement("div", {
466
+ className: "round-all event-item",
467
+ style: {
468
+ height: dropPreview.eventItemHeight,
469
+ backgroundColor: dropPreview.bgColor
470
+ }
471
+ }, /*#__PURE__*/_react["default"].createElement("span", {
472
+ style: {
473
+ marginLeft: '10px',
474
+ lineHeight: "".concat(dropPreview.eventItemHeight, "px")
475
+ }
476
+ }, dropPreview.title));
477
+ if (eventItemTemplateResolver && dropPreview.eventItem) {
478
+ previewContent = eventItemTemplateResolver(schedulerData, dropPreview.eventItem, dropPreview.bgColor, true, true, 'event-item', dropPreview.eventItemHeight, undefined);
479
+ }
480
+ dropPreviewElement = /*#__PURE__*/_react["default"].createElement("a", {
481
+ className: "timeline-event drop-preview",
482
+ style: {
483
+ left: previewLeft,
484
+ width: Math.max(0, previewWidth),
485
+ top: 1
486
+ }
487
+ }, previewContent);
488
+ }
454
489
  var eventContainer = /*#__PURE__*/_react["default"].createElement("div", {
455
490
  ref: this.eventContainerRef,
456
491
  className: "event-container",
457
492
  style: {
458
493
  height: resourceEvents.rowHeight
459
494
  }
460
- }, selectedArea, dropShadow, eventList);
495
+ }, selectedArea, dropPreviewElement, eventList);
461
496
  return /*#__PURE__*/_react["default"].createElement("tr", null, /*#__PURE__*/_react["default"].createElement("td", {
462
497
  style: {
463
498
  width: rowWidth
@@ -489,7 +524,7 @@ var ResourceEventsWithDnD = function ResourceEventsWithDnD(props) {
489
524
  var schedulerData = props.schedulerData,
490
525
  dndContext = props.dndContext;
491
526
  var config = schedulerData.config;
492
- var componentRef = (0, _react.useRef)(null);
527
+ var componentRef = _react["default"].useRef(null);
493
528
 
494
529
  // Always call useDrop unconditionally (Rules of Hooks)
495
530
  // Disable functionality when drag and drop is not enabled
@@ -501,7 +536,8 @@ var ResourceEventsWithDnD = function ResourceEventsWithDnD(props) {
501
536
  collect: function collect() {
502
537
  return {
503
538
  isOver: false,
504
- canDrop: false
539
+ canDrop: false,
540
+ dropPreview: null
505
541
  };
506
542
  }
507
543
  };
@@ -519,9 +555,21 @@ var ResourceEventsWithDnD = function ResourceEventsWithDnD(props) {
519
555
  return spec.canDrop(props, monitor);
520
556
  },
521
557
  collect: function collect(monitor) {
558
+ var over = monitor.isOver();
559
+ var drop = monitor.canDrop();
560
+ var preview = null;
561
+ if (over && drop) {
562
+ // Reading getClientOffset subscribes collect to offset changes during drag
563
+ monitor.getClientOffset();
564
+ var item = monitor.getItem();
565
+ if (item && item._dropPreview && item._dropPreview.slotId === props.resourceEvents.slotId) {
566
+ preview = item._dropPreview;
567
+ }
568
+ }
522
569
  return {
523
- isOver: monitor.isOver(),
524
- canDrop: monitor.canDrop()
570
+ isOver: over,
571
+ canDrop: drop,
572
+ dropPreview: preview
525
573
  };
526
574
  }
527
575
  };
@@ -530,18 +578,15 @@ var ResourceEventsWithDnD = function ResourceEventsWithDnD(props) {
530
578
  _useDrop2$ = _useDrop2[0],
531
579
  isOver = _useDrop2$.isOver,
532
580
  canDrop = _useDrop2$.canDrop,
581
+ dropPreview = _useDrop2$.dropPreview,
533
582
  dropRef = _useDrop2[1];
534
- (0, _react.useEffect)(function () {
535
- if (!isOver && componentRef.current) {
536
- componentRef.current.clearShadowState();
537
- }
538
- }, [isOver]);
539
583
  return /*#__PURE__*/_react["default"].createElement(ResourceEvents, _extends({
540
584
  ref: componentRef
541
585
  }, props, {
542
586
  dropRef: dropRef,
543
587
  isOver: isOver,
544
- canDrop: canDrop
588
+ canDrop: canDrop,
589
+ dropPreview: dropPreview
545
590
  }));
546
591
  };
547
592
  ResourceEventsWithDnD.displayName = 'ResourceEventsWithDnD';
@@ -80,8 +80,7 @@ var _default = exports["default"] = {
80
80
  relativeMove: true,
81
81
  defaultExpanded: true,
82
82
  dragAndDropEnabled: true,
83
- overflowArrowsEnabled: true,
84
- snapToGrid: false,
83
+ dropPreviewEnabled: true,
85
84
  schedulerHeaderEventsFuncsTimeoutMs: 100,
86
85
  resourceName: 'Resource Name',
87
86
  taskName: 'Task Name',
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "makula-schedule",
3
- "version": "2.2.6",
3
+ "version": "2.3.1",
4
4
  "description": "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 drag-and-drop functionality, interactive UI, and granular views, react-big-schedule empowers users to effortlessly schedule and allocate resources with precision. Enhance productivity and streamline your workflow with this React-based solution, designed to optimize time management and simplify calendar-based operations. Perfect for applications requiring advanced scheduling capabilities, react-big-schedule offers a seamless and intuitive experience for managing appointments, resource allocation, and time slots. Unlock the potential of your React projects with react-big-schedule and revolutionize the way you handle scheduling and resource planning. It is the updated version of react-big-scheduler",
5
5
  "keywords": [
6
6
  "react-big-schedule",