fix(core): use whole handle for snapping area (#1843)

* chore(changeset): add

* fix(core): use whole handle for snapping area

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-05-15 18:37:14 +02:00
parent 666e4eabab
commit 735c81c63f
3 changed files with 18 additions and 5 deletions
+5
View File
@@ -0,0 +1,5 @@
---
"@vue-flow/core": patch
---
Use whole handle area for snapping.
+12 -4
View File
@@ -163,6 +163,7 @@ export function useHandle({
id: toValue(handleId), id: toValue(handleId),
type: handleType, type: handleType,
position: (clickedHandle?.getAttribute('data-handlepos') as Position) || Position.Top, position: (clickedHandle?.getAttribute('data-handlepos') as Position) || Position.Top,
...connectionPosition,
}, },
{ {
x: x - containerBounds.left, x: x - containerBounds.left,
@@ -217,8 +218,8 @@ export function useHandle({
...previousConnection, ...previousConnection,
isValid, isValid,
to: to:
closestHandle && isValid result.toHandle && isValid
? rendererPointToPoint({ x: closestHandle.x, y: closestHandle.y }, viewport.value) ? rendererPointToPoint({ x: result.toHandle.x, y: result.toHandle.y }, viewport.value)
: connectionPosition, : connectionPosition,
toHandle: result.toHandle, toHandle: result.toHandle,
toPosition: isValid && result.toHandle ? result.toHandle.position : oppositePosition[fromHandle.position], toPosition: isValid && result.toHandle ? result.toHandle.position : oppositePosition[fromHandle.position],
@@ -325,7 +326,13 @@ export function useHandle({
emits.clickConnectStart({ event, nodeId: toValue(nodeId), handleId: toValue(handleId) }) emits.clickConnectStart({ event, nodeId: toValue(nodeId), handleId: toValue(handleId) })
startConnection( startConnection(
{ nodeId: toValue(nodeId), type: toValue(type), id: toValue(handleId), position: Position.Top }, {
nodeId: toValue(nodeId),
type: toValue(type),
id: toValue(handleId),
position: Position.Top,
...getEventPosition(event),
},
undefined, undefined,
true, true,
) )
@@ -355,10 +362,11 @@ export function useHandle({
id: toValue(handleId), id: toValue(handleId),
type: toValue(type), type: toValue(type),
position: Position.Top, position: Position.Top,
...getEventPosition(event),
}, },
connectionMode: connectionMode.value, connectionMode: connectionMode.value,
fromNodeId: connectionClickStartHandle.value.nodeId, fromNodeId: connectionClickStartHandle.value.nodeId,
fromHandleId: connectionClickStartHandle.value.id || null, fromHandleId: connectionClickStartHandle.value.id ?? null,
fromType: connectionClickStartHandle.value.type, fromType: connectionClickStartHandle.value.type,
isValidConnection: isValidConnectionHandler, isValidConnection: isValidConnectionHandler,
doc, doc,
+1 -1
View File
@@ -19,7 +19,7 @@ export interface ConnectionHandle extends XYPosition {
nodeId: string nodeId: string
} }
export interface ConnectingHandle { export interface ConnectingHandle extends XYPosition {
nodeId: string nodeId: string
type: HandleType type: HandleType
id?: string | null id?: string | null