From b1c88b37929fd763ac46b3153e992891cc7d08b7 Mon Sep 17 00:00:00 2001 From: braks <78412429+bcakmakoglu@users.noreply.github.com> Date: Sat, 1 Apr 2023 01:04:36 +0200 Subject: [PATCH] chore(core): cleanup handle Signed-off-by: braks <78412429+bcakmakoglu@users.noreply.github.com> --- .../core/src/components/Handle/Handle.vue | 8 ++-- packages/core/src/composables/useHandle.ts | 47 +++++++++---------- 2 files changed, 27 insertions(+), 28 deletions(-) diff --git a/packages/core/src/components/Handle/Handle.vue b/packages/core/src/components/Handle/Handle.vue index 013817f5..687cef5c 100644 --- a/packages/core/src/components/Handle/Handle.vue +++ b/packages/core/src/components/Handle/Handle.vue @@ -58,10 +58,10 @@ const isConnectable = computed(() => { const isConnecting = computed( () => - connectionStartHandle && - connectionStartHandle.nodeId === nodeId && - connectionStartHandle.handleId === handleId && - connectionStartHandle.type === type.value, + connectionStartHandle.value && + connectionStartHandle.value.nodeId === nodeId && + connectionStartHandle.value.handleId === handleId.value && + connectionStartHandle.value.type === type.value, ) // set up handle bounds if they don't exist yet and the node has been initialized (i.e. the handle was added after the node has already been mounted) diff --git a/packages/core/src/composables/useHandle.ts b/packages/core/src/composables/useHandle.ts index 0d2a9e8f..7b1e976b 100644 --- a/packages/core/src/composables/useHandle.ts +++ b/packages/core/src/composables/useHandle.ts @@ -24,10 +24,10 @@ export default function useHandle({ onEdgeUpdate, onEdgeUpdateEnd, }: UseHandleProps) { - const isTarget = $computed(() => unref(type) === 'target') - const nodeId = $computed(() => unref(_nodeId)) - const handleId = $computed(() => unref(_handleId)) - const edgeUpdaterType = $computed(() => unref(_edgeUpdaterType)) + const isTarget = computed(() => unref(type) === 'target') + const nodeId = computed(() => unref(_nodeId)) + const handleId = computed(() => unref(_handleId)) + const edgeUpdaterType = computed(() => unref(_edgeUpdaterType)) const { vueFlowRef, @@ -56,10 +56,10 @@ export default function useHandle({ function handlePointerDown(event: MouseTouchEvent) { const isMouseTriggered = isMouseEvent(event) - if ((isMouseTriggered && event.button === 0) || !isMouseTriggered) { - // when vue-flow is used inside a shadow root we can't use document - const doc = getHostForElement(event.target as HTMLElement) + // when vue-flow is used inside a shadow root we can't use document + const doc = getHostForElement(event.target as HTMLElement) + if ((isMouseTriggered && event.button === 0) || !isMouseTriggered) { const node = findNode(unref(nodeId)) let isValidConnectionHandler = isValidConnection || isValidConnectionProp.value || alwaysValid @@ -87,8 +87,8 @@ export default function useHandle({ const handleLookup = getHandleLookup({ nodes: getNodes.value, - nodeId, - handleId, + nodeId: nodeId.value, + handleId: handleId.value, handleType, }) @@ -106,9 +106,9 @@ export default function useHandle({ startConnection( { - nodeId: unref(nodeId), - handleId: unref(handleId), - type: unref(handleType), + nodeId: nodeId.value, + handleId: handleId.value, + type: handleType, }, { x: x - containerBounds.left, @@ -117,7 +117,7 @@ export default function useHandle({ event, ) - emits.connectStart({ event, nodeId, handleId, handleType }) + emits.connectStart({ event, nodeId: nodeId.value, handleId: handleId.value, handleType }) function onPointerMove(event: MouseTouchEvent) { connectionPosition = getEventPosition(event, containerBounds) @@ -137,9 +137,9 @@ export default function useHandle({ event, prevClosestHandle, connectionMode.value, - nodeId, - handleId, - isTarget ? 'target' : 'source', + nodeId.value, + handleId.value, + isTarget.value ? 'target' : 'source', isValidConnectionHandler, doc, edges.value, @@ -184,10 +184,9 @@ export default function useHandle({ function onPointerUp(event: MouseTouchEvent) { if ((prevClosestHandle || handleDomNode) && connection && isValid) { if (!onEdgeUpdate) { - emits.connect(connection) - } else { - onEdgeUpdate(event, connection) - } + emits.connect(connection) + } else { + onEdgeUpdate(event, connection) } } @@ -222,13 +221,13 @@ export default function useHandle({ } } - const handleClick = (event: MouseEvent) => { + function handleClick(event: MouseEvent) { if (!connectOnClick.value) { return } if (!connectionClickStartHandle.value) { - emits.clickConnectStart({ event, nodeId, handleId }) + emits.clickConnectStart({ event, nodeId: nodeId.value, handleId: handleId.value }) startConnection({ nodeId: unref(nodeId), type: unref(type), handleId: unref(handleId) }, undefined, event, true) } else { @@ -249,8 +248,8 @@ export default function useHandle({ const { connection, isValid } = isValidHandle( event, { - nodeId, - id: handleId, + nodeId: nodeId.value, + id: handleId.value, type: unref(type), }, connectionMode.value,