Skip to content

Commit

Permalink
fix(dnd): added check for null dragFromOutsideItem, updated example (#…
Browse files Browse the repository at this point in the history
…2651)

Based on the work of @achrafl0 in #2616

closes #2383
  • Loading branch information
matthiaseigner authored Sep 16, 2024
1 parent d66bd12 commit 17e62a3
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 8 deletions.
20 changes: 17 additions & 3 deletions src/addons/dragAndDrop/EventContainerWrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,18 @@ class EventContainerWrapper extends React.Component {
})
}

handleDragOverFromOutside = (point, bounds) => {
const { slotMetrics } = this.props

const start = slotMetrics.closestSlotFromPoint(
{ y: point.y, x: point.x },
bounds
)
const end = slotMetrics.nextSlot(start)
const event = this.context.draggable.dragFromOutsideItem()
this.update(event, slotMetrics.getRange(start, end, false, true))
}

updateParentScroll = (parent, node) => {
setTimeout(() => {
const draggedEl = qsa(node, '.rbc-addons-dnd-drag-preview')[0]
Expand Down Expand Up @@ -200,10 +212,12 @@ class EventContainerWrapper extends React.Component {
this.handleDropFromOutside(point, bounds)
})

selector.on('dragOver', (point) => {
if (!this.context.draggable.dragFromOutsideItem) return
selector.on('dragOverFromOutside', (point) => {
const item = this.context.draggable.dragFromOutsideItem ? this.context.draggable.dragFromOutsideItem() : null
if (!item) return
const bounds = getBoundsForNode(node)
this.handleDropFromOutside(point, bounds)
if (!pointInColumn(bounds, point)) return this.reset()
this.handleDragOverFromOutside(point, bounds)
})

selector.on('selectStart', () => {
Expand Down
5 changes: 3 additions & 2 deletions src/addons/dragAndDrop/WeekWrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,9 @@ class WeekWrapper extends React.Component {
}

handleDragOverFromOutside = (point, node) => {
if (!this.context.draggable.dragFromOutsideItem) return
this.handleMove(point, node, this.context.draggable.dragFromOutsideItem())
const item = this.context.draggable.dragFromOutsideItem ? this.context.draggable.dragFromOutsideItem() : null
if (!item) return
this.handleMove(point, node, item)
}

handleResize(point, bounds) {
Expand Down
6 changes: 3 additions & 3 deletions stories/demos/exampleCode/dndOutsideSource.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ export default function DnDOutsideResource({ localizer }) {
//,
const handleDragStart = useCallback((event) => setDraggedEvent(event), [])

const dragFromOutsideItem = useCallback(() => draggedEvent, [draggedEvent])
const dragFromOutsideItem = useCallback(() => draggedEvent === 'undroppable' ? null : draggedEvent, [draggedEvent])

const customOnDragOver = useCallback(
const customOnDragOverFromOutside = useCallback(
(dragEvent) => {
// check for undroppable is specific to this example
// and not part of API. This just demonstrates that
Expand Down Expand Up @@ -177,7 +177,7 @@ export default function DnDOutsideResource({ localizer }) {
events={myEvents}
localizer={localizer}
onDropFromOutside={onDropFromOutside}
onDragOver={customOnDragOver}
onDragOverFromOutside={customOnDragOverFromOutside}
onEventDrop={moveEvent}
onEventResize={resizeEvent}
onSelectSlot={newEvent}
Expand Down

0 comments on commit 17e62a3

Please sign in to comment.