From 9442c72ce3d87cd9c8dde8faa6eb088430ddace8 Mon Sep 17 00:00:00 2001 From: Duc Filan Date: Thu, 21 Nov 2024 16:08:22 +0800 Subject: [PATCH] Customize drag from outside event's length --- .../dragAndDrop/EventContainerWrapper.js | 24 +++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/src/addons/dragAndDrop/EventContainerWrapper.js b/src/addons/dragAndDrop/EventContainerWrapper.js index 583da4077..07742e55c 100644 --- a/src/addons/dragAndDrop/EventContainerWrapper.js +++ b/src/addons/dragAndDrop/EventContainerWrapper.js @@ -118,9 +118,11 @@ class EventContainerWrapper extends React.Component { boundaryBox ) + const end = this._calculateDnDEnd(start) + this.context.draggable.onDropFromOutside({ start, - end: slotMetrics.nextSlot(start), + end, allDay: false, resource, }) @@ -133,11 +135,25 @@ class EventContainerWrapper extends React.Component { { y: point.y, x: point.x }, bounds ) - const end = slotMetrics.nextSlot(start) + const end = this._calculateDnDEnd(start) const event = this.context.draggable.dragFromOutsideItem() this.update(event, slotMetrics.getRange(start, end, false, true)) } + _calculateDnDEnd = (start) => { + const { accessors, slotMetrics, localizer } = this.props + const event = this.context.draggable.dragFromOutsideItem() + const { duration: eventDuration } = eventTimes(event, accessors, localizer) + + const end = slotMetrics.nextSlot(start) + const eventHasDuration = !isNaN(eventDuration) + if (eventHasDuration) { + const eventEndSlot = localizer.add(start, eventDuration, 'milliseconds') + end = new Date(Math.max(eventEndSlot, end)) + } + return end + } + updateParentScroll = (parent, node) => { setTimeout(() => { const draggedEl = qsa(node, '.rbc-addons-dnd-drag-preview')[0] @@ -152,8 +168,8 @@ class EventContainerWrapper extends React.Component { parent, Math.min( draggedEl.offsetTop - - parent.offsetHeight + - draggedEl.offsetHeight, + parent.offsetHeight + + draggedEl.offsetHeight, parent.scrollHeight ) )