diff --git a/packages/core/src/composables/useHandle.ts b/packages/core/src/composables/useHandle.ts index 09761ef7..b2185072 100644 --- a/packages/core/src/composables/useHandle.ts +++ b/packages/core/src/composables/useHandle.ts @@ -64,8 +64,8 @@ export default function useHandle({ let isValidConnectionHandler = isValidConnection || isValidConnectionProp.value || alwaysValid - if (!isValidConnectionHandler) { - if (node) isValidConnectionHandler = (!isTarget ? node.isValidTargetPos : node.isValidSourcePos) || alwaysValid + if (!isValidConnectionHandler && node) { + isValidConnectionHandler = (!isTarget ? node.isValidTargetPos : node.isValidSourcePos) || alwaysValid } let prevClosestHandle: ConnectionHandle | null @@ -97,6 +97,7 @@ export default function useHandle({ if (!autoPanOnConnect) { return } + const [xMovement, yMovement] = calcAutoPan(connectionPosition, containerBounds) panBy({ x: xMovement, y: yMovement }) @@ -163,7 +164,9 @@ export default function useHandle({ getConnectionStatus(!!prevClosestHandle, isValid), ) - if (!prevClosestHandle && !isValid && !handleDomNode) return resetRecentHandle(prevActiveHandle) + if (!prevClosestHandle && !isValid && !handleDomNode) { + return resetRecentHandle(prevActiveHandle) + } if (connection && connection.source !== connection.target && handleDomNode) { resetRecentHandle(prevActiveHandle) @@ -179,16 +182,19 @@ export default function useHandle({ } function onPointerUp(event: MouseTouchEvent) { - if (prevClosestHandle || handleDomNode) { - if (connection && isValid) { - if (!onEdgeUpdate) emits.connect(connection) - else onEdgeUpdate(event, connection) + if ((prevClosestHandle || handleDomNode) && connection && isValid) { + if (!onEdgeUpdate) { + emits.connect(connection) + } else { + onEdgeUpdate(event, connection) } } emits.connectEnd(event) - if (edgeUpdaterType) onEdgeUpdateEnd?.(event) + if (edgeUpdaterType) { + onEdgeUpdateEnd?.(event) + } resetRecentHandle(prevActiveHandle) @@ -216,7 +222,9 @@ export default function useHandle({ } const handleClick = (event: MouseEvent) => { - if (!connectOnClick.value) return + if (!connectOnClick.value) { + return + } if (!connectionClickStartHandle.value) { startConnection({ nodeId: unref(nodeId), type: unref(type), handleId: unref(handleId) }, undefined, event, true) @@ -225,11 +233,13 @@ export default function useHandle({ const node = findNode(unref(nodeId)) - if (!isValidConnectionHandler) { - if (node) isValidConnectionHandler = (!isTarget ? node.isValidTargetPos : node.isValidSourcePos) || alwaysValid + if (!isValidConnectionHandler && node) { + isValidConnectionHandler = (!isTarget ? node.isValidTargetPos : node.isValidSourcePos) || alwaysValid } - if (node && (typeof node.connectable === 'undefined' ? nodesConnectable : node.connectable) === false) return + if (node && (typeof node.connectable === 'undefined' ? nodesConnectable.value : node.connectable) === false) { + return + } const doc = getHostForElement(event.target as HTMLElement) @@ -252,7 +262,9 @@ export default function useHandle({ const isOwnHandle = connection.source === connection.target - if (isValid && !isOwnHandle) emits.connect(connection) + if (isValid && !isOwnHandle) { + emits.connect(connection) + } endConnection(event, true) }