Skip to content

Commit 3489fae

Browse files
committed
refactor(core): use correct end handle position in connection line (#1508)
* refactor(core): use correct end handle position in connection line * chore(changeset): add
1 parent 266f874 commit 3489fae

File tree

5 files changed

+18
-9
lines changed

5 files changed

+18
-9
lines changed

.changeset/short-ligers-help.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@vue-flow/core": minor
3+
---
4+
5+
Use correct end handle position in connection line component and store handle positions during connections.

packages/core/src/components/ConnectionLine/index.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,7 @@ const ConnectionLine = defineComponent({
9393
}
9494
}
9595

96-
// we assume the target position is opposite to the source position
97-
const toPosition = fromPosition ? oppositePosition[fromPosition] : null
96+
const toPosition = connectionEndHandle.value?.position ?? (fromPosition ? oppositePosition[fromPosition] : null)
9897

9998
if (!fromPosition || !toPosition) {
10099
return null

packages/core/src/composables/useHandle.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import {
1515
rendererPointToPoint,
1616
resetRecentHandle,
1717
} from '../utils'
18+
import { Position } from '../types'
1819
import { useVueFlow } from './useVueFlow'
1920

2021
export interface UseHandleProps {
@@ -129,6 +130,7 @@ export function useHandle({
129130
nodeId: toValue(nodeId),
130131
handleId: toValue(handleId),
131132
type: handleType,
133+
position: (clickedHandle?.getAttribute('data-handlepos') as Position) || Position.Top,
132134
},
133135
{
134136
x: x - containerBounds.left,

packages/core/src/types/handle.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ export interface ValidHandleResult {
2626
export interface ConnectingHandle {
2727
nodeId: string
2828
type: HandleType
29-
handleId: string | null
29+
handleId?: string | null
30+
position?: Position | null
3031
}
3132

3233
/** A valid connection function can determine if an attempted connection is valid or not, i.e. abort creating a new edge */

packages/core/src/utils/handle.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import type {
88
GraphNode,
99
HandleType,
1010
NodeHandleBounds,
11+
Position,
1112
ValidConnectionFunc,
1213
ValidHandleResult,
1314
XYPosition,
@@ -192,19 +193,20 @@ export function isValidHandle(
192193
? (isTarget && handleType === 'source') || (!isTarget && handleType === 'target')
193194
: handleNodeId !== fromNodeId || handleId !== fromHandleId)
194195

195-
result.endHandle = {
196-
nodeId: handleNodeId,
197-
handleId,
198-
type: handleType as HandleType,
199-
}
200-
201196
if (isValid) {
202197
result.isValid = isValidConnection(connection, {
203198
edges,
204199
nodes,
205200
sourceNode: findNode(connection.source)!,
206201
targetNode: findNode(connection.target)!,
207202
})
203+
204+
result.endHandle = {
205+
nodeId: handleNodeId,
206+
handleId,
207+
type: handleType as HandleType,
208+
position: result.isValid ? (handleToCheck.getAttribute('data-handlepos') as Position) : null,
209+
}
208210
}
209211
}
210212

0 commit comments

Comments
 (0)