Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(core): reset drag items on drag end #1798

Merged
merged 2 commits into from
Mar 14, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/old-moose-fly.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@vue-flow/core": patch
---

Reset drag items on drag end
27 changes: 14 additions & 13 deletions packages/core/src/composables/useDrag.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import {
getEventPosition,
handleNodeClick,
hasSelector,
isUseDragEvent,
snapPosition,
} from '../utils'
import { useGetPointerPosition, useVueFlow } from '.'
Expand Down Expand Up @@ -226,8 +225,10 @@ export function useDrag(params: UseDragParams) {
}

const eventEnd = (event: UseDragEvent) => {
if (!isUseDragEvent(event) && !dragStarted && !dragging.value && !multiSelectionActive.value) {
const evt = event as MouseTouchEvent
let isClick = false

if (!dragStarted && !dragging.value && !multiSelectionActive.value) {
const evt = event.sourceEvent as MouseTouchEvent

const pointerPos = getPointerPosition(evt)

Expand All @@ -238,19 +239,11 @@ export function useDrag(params: UseDragParams) {
// dispatch a click event if the node was attempted to be dragged but the threshold was not exceeded
if (distance !== 0 && distance <= nodeDragThreshold.value) {
onClick?.(evt)
isClick = true
}

return
}

dragging.value = false
autoPanStarted = false
dragStarted = false
lastPos = { x: undefined, y: undefined }

cancelAnimationFrame(autoPanId)

if (dragItems.length) {
if (dragItems.length && !isClick) {
updateNodePositions(dragItems, false, false)

const [currentNode, nodes] = getEventHandlerParams({
Expand All @@ -261,6 +254,14 @@ export function useDrag(params: UseDragParams) {

onStop({ event: event.sourceEvent, node: currentNode, nodes })
}

dragItems = []
dragging.value = false
autoPanStarted = false
dragStarted = false
lastPos = { x: undefined, y: undefined }

cancelAnimationFrame(autoPanId)
}

watch([() => toValue(disabled), el], ([isDisabled, nodeEl], _, onCleanup) => {
Expand Down
Loading