bevacqua / dragula

:ok_hand: Drag and drop so simple it hurts
https://bevacqua.github.io/dragula/
MIT License
22.01k stars 1.97k forks source link

is it guaranteed that drop will be triggered only when order has changed? #642

Closed lingtalfi closed 4 years ago

lingtalfi commented 4 years ago

Hi, I'm trying to implement a sort system (like jquery ui sortable) with dragula.

I need to know whether or not the drop event is only fire when there is an actual reordering in the dom, or is it whenever the dragged object is dropped (even if in the same place).

From my tests, I believe that the drop event is indeed only fire if the order of the draggable items has changed, but I cannot be 100% sure because the doc doesn't specify it.

It says:

el was dropped into target before a sibling element, and originally came from source

Can you confirm that the drop event is only fired when there is a change in the items order? And if so, would it be possible to update the documentation so that developers might be able to build there logic from there.

(I mean if it's not stated clearly in the documentation, it might change on the next version).

dcantatore commented 4 years ago

The logic is currently:

    if (isInitialPlacement(target)) {
      drake.emit('cancel', item, _source, _source);
    } else {
      drake.emit('drop', item, target, _source, _currentSibling);
    }