fix(core): fall back to changedTouches for touchend events (#1830)

* fix(core): fall back to changedTouches for touchend events

Signed-off-by: braks <78412429+bcakmakoglu@users.noreply.github.com>

* chore(changeset): add

Signed-off-by: braks <78412429+bcakmakoglu@users.noreply.github.com>

---------

Signed-off-by: braks <78412429+bcakmakoglu@users.noreply.github.com>
This commit is contained in:
Braks
2025-04-23 20:25:19 +02:00
parent 265f928f13
commit cc65f12af9
3 changed files with 23 additions and 3 deletions

View File

@@ -0,0 +1,5 @@
---
"@vue-flow/core": patch
---
Fall back to using changedTouches when passing a touchend or touchcancel event to getEventPosition.

View File

@@ -12,8 +12,23 @@ export function isUseDragEvent(event: any): event is UseDragEvent {
export function getEventPosition(event: MouseEvent | TouchEvent, bounds?: DOMRect) {
const isMouse = isMouseEvent(event)
const evtX = isMouse ? event.clientX : event.touches?.[0].clientX
const evtY = isMouse ? event.clientY : event.touches?.[0].clientY
let evtX: number
let evtY: number
if (isMouse) {
evtX = event.clientX
evtY = event.clientY
} else if ('touches' in event && event.touches.length > 0) {
evtX = event.touches[0].clientX
evtY = event.touches[0].clientY
} else if ('changedTouches' in event && event.changedTouches.length > 0) {
evtX = event.changedTouches[0].clientX
evtY = event.changedTouches[0].clientY
} else {
// fallback for other cases
evtX = 0
evtY = 0
}
return {
x: evtX - (bounds?.left ?? 0),

View File

@@ -122,7 +122,7 @@ export function getClosestHandle(
return closestHandles[0]
}
// checks if and returns connection in form of an object { source: 123, target: 312 }
// checks if and returns connection in form of an object { source: 123, target: 312 }
export function isValidHandle(
event: MouseEvent | TouchEvent,
{