always pass current pointer position to connection

This commit is contained in:
peterkogo
2025-10-29 12:11:05 +01:00
parent 905ab996f5
commit 11aa29b587
6 changed files with 14 additions and 20 deletions

View File

@@ -292,6 +292,7 @@ export const initialConnection: NoConnection = {
toHandle: null,
toPosition: null,
toNode: null,
pointer: null,
};
export type NoConnection = {
@@ -305,6 +306,7 @@ export type NoConnection = {
toHandle: null;
toPosition: null;
toNode: null;
pointer: null;
};
export type ConnectionInProgress<NodeType extends InternalNodeBase = InternalNodeBase> = {
/** Indicates whether a connection is currently in progress. */
@@ -330,6 +332,8 @@ export type ConnectionInProgress<NodeType extends InternalNodeBase = InternalNod
toPosition: Position;
/** Returns the end node or `null` if no connection is in progress. */
toNode: NodeType | null;
/** Returns the pointer position or `null` if no connection is in progress. */
pointer: XYPosition;
};
/**

View File

@@ -109,6 +109,7 @@ function onPointerDown(
toHandle: null,
toPosition: oppositePosition[fromHandle.position],
toNode: null,
pointer: position,
};
function startConnection() {
@@ -182,26 +183,9 @@ function onPointerDown(
toHandle: result.toHandle,
toPosition: isValid && result.toHandle ? result.toHandle.position : oppositePosition[fromHandle.position],
toNode: result.toHandle ? nodeLookup.get(result.toHandle.nodeId)! : null,
pointer: position,
};
/*
* we don't want to trigger an update when the connection
* is snapped to the same handle as before
*/
if (
isValid &&
closestHandle &&
previousConnection.toHandle &&
newConnection.toHandle &&
previousConnection.toHandle.type === newConnection.toHandle.type &&
previousConnection.toHandle.nodeId === newConnection.toHandle.nodeId &&
previousConnection.toHandle.id === newConnection.toHandle.id &&
previousConnection.to.x === newConnection.to.x &&
previousConnection.to.y === newConnection.to.y
) {
return;
}
updateConnection(newConnection);
previousConnection = newConnection;
}