From 046ee41e79b8fc1cb6d593a978a9b41d761c48b4 Mon Sep 17 00:00:00 2001 From: braks <78412429+bcakmakoglu@users.noreply.github.com> Date: Wed, 8 Mar 2023 14:09:10 +0100 Subject: [PATCH] fix(core): add connection target handle id to result type Signed-off-by: braks <78412429+bcakmakoglu@users.noreply.github.com> --- .../ConnectionLine/ConnectionLine.vue | 18 +++++++++++------- packages/core/src/types/handle.ts | 1 + packages/core/src/utils/handle.ts | 2 ++ 3 files changed, 14 insertions(+), 7 deletions(-) diff --git a/packages/core/src/components/ConnectionLine/ConnectionLine.vue b/packages/core/src/components/ConnectionLine/ConnectionLine.vue index 8ff4196f..36564373 100644 --- a/packages/core/src/components/ConnectionLine/ConnectionLine.vue +++ b/packages/core/src/components/ConnectionLine/ConnectionLine.vue @@ -42,17 +42,21 @@ const sourceHandle = $computed( sourceNode.handleBounds[type.value ?? 'source']?.[0], ) -const targetHandle = $computed( - () => +const targetHandle = $computed(() => { + return ( (targetNode && + connectionStartHandle?.result?.handleId && ((connectionMode === ConnectionMode.Strict - ? targetNode.handleBounds[type.value === 'source' ? 'target' : 'source']?.find((d) => d.id === handleId) + ? targetNode.handleBounds[type.value === 'source' ? 'target' : 'source']?.find( + (d) => d.id === connectionStartHandle?.result?.handleId, + ) : [...(targetNode.handleBounds.source || []), ...(targetNode.handleBounds.target || [])]?.find( - (d) => d.id === handleId, + (d) => d.id === connectionStartHandle?.result?.handleId, )) || - targetNode.handleBounds[type.value ?? 'source']?.[0])) || - null, -) + targetNode.handleBounds[type.value ?? 'target']?.[0])) || + null + ) +}) const sourceHandleX = $computed(() => (sourceHandle ? sourceHandle.x + sourceHandle.width / 2 : sourceNode.dimensions.width / 2)) const sourceHandleY = $computed(() => (sourceHandle ? sourceHandle.y + sourceHandle.height / 2 : sourceNode.dimensions.height)) diff --git a/packages/core/src/types/handle.ts b/packages/core/src/types/handle.ts index b0462961..6ca30816 100644 --- a/packages/core/src/types/handle.ts +++ b/packages/core/src/types/handle.ts @@ -19,6 +19,7 @@ export interface ConnectionHandle { } export interface ValidHandleResult { + handleId: string | null handleDomNode: Element | null isValid: boolean connection: Connection diff --git a/packages/core/src/utils/handle.ts b/packages/core/src/utils/handle.ts index 1a7272e7..95894ea2 100644 --- a/packages/core/src/utils/handle.ts +++ b/packages/core/src/utils/handle.ts @@ -86,6 +86,7 @@ export function isValidHandle( const handleToCheck = handleBelow?.classList.contains('vue-flow__handle') ? handleBelow : handleDomNode const result: ValidHandleResult = { + handleId: null, handleDomNode: handleToCheck, isValid: false, connection: { source: '', target: '', sourceHandle: null, targetHandle: null }, @@ -103,6 +104,7 @@ export function isValidHandle( } result.connection = connection + result.handleId = handleId // in strict mode we don't allow target to target or source to source connections const isValid =