refactor(core): use correct end handle position in connection line (#1508)
* refactor(core): use correct end handle position in connection line * chore(changeset): add
This commit is contained in:
@@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
"@vue-flow/core": minor
|
||||||
|
---
|
||||||
|
|
||||||
|
Use correct end handle position in connection line component and store handle positions during connections.
|
||||||
@@ -93,8 +93,7 @@ const ConnectionLine = defineComponent({
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// we assume the target position is opposite to the source position
|
const toPosition = connectionEndHandle.value?.position ?? (fromPosition ? oppositePosition[fromPosition] : null)
|
||||||
const toPosition = fromPosition ? oppositePosition[fromPosition] : null
|
|
||||||
|
|
||||||
if (!fromPosition || !toPosition) {
|
if (!fromPosition || !toPosition) {
|
||||||
return null
|
return null
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ import {
|
|||||||
rendererPointToPoint,
|
rendererPointToPoint,
|
||||||
resetRecentHandle,
|
resetRecentHandle,
|
||||||
} from '../utils'
|
} from '../utils'
|
||||||
|
import { Position } from '../types'
|
||||||
import { useVueFlow } from './useVueFlow'
|
import { useVueFlow } from './useVueFlow'
|
||||||
|
|
||||||
export interface UseHandleProps {
|
export interface UseHandleProps {
|
||||||
@@ -129,6 +130,7 @@ export function useHandle({
|
|||||||
nodeId: toValue(nodeId),
|
nodeId: toValue(nodeId),
|
||||||
handleId: toValue(handleId),
|
handleId: toValue(handleId),
|
||||||
type: handleType,
|
type: handleType,
|
||||||
|
position: (clickedHandle?.getAttribute('data-handlepos') as Position) || Position.Top,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
x: x - containerBounds.left,
|
x: x - containerBounds.left,
|
||||||
|
|||||||
@@ -26,7 +26,8 @@ export interface ValidHandleResult {
|
|||||||
export interface ConnectingHandle {
|
export interface ConnectingHandle {
|
||||||
nodeId: string
|
nodeId: string
|
||||||
type: HandleType
|
type: HandleType
|
||||||
handleId: string | null
|
handleId?: string | null
|
||||||
|
position?: Position | null
|
||||||
}
|
}
|
||||||
|
|
||||||
/** A valid connection function can determine if an attempted connection is valid or not, i.e. abort creating a new edge */
|
/** A valid connection function can determine if an attempted connection is valid or not, i.e. abort creating a new edge */
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import type {
|
|||||||
GraphNode,
|
GraphNode,
|
||||||
HandleType,
|
HandleType,
|
||||||
NodeHandleBounds,
|
NodeHandleBounds,
|
||||||
|
Position,
|
||||||
ValidConnectionFunc,
|
ValidConnectionFunc,
|
||||||
ValidHandleResult,
|
ValidHandleResult,
|
||||||
XYPosition,
|
XYPosition,
|
||||||
@@ -192,12 +193,6 @@ export function isValidHandle(
|
|||||||
? (isTarget && handleType === 'source') || (!isTarget && handleType === 'target')
|
? (isTarget && handleType === 'source') || (!isTarget && handleType === 'target')
|
||||||
: handleNodeId !== fromNodeId || handleId !== fromHandleId)
|
: handleNodeId !== fromNodeId || handleId !== fromHandleId)
|
||||||
|
|
||||||
result.endHandle = {
|
|
||||||
nodeId: handleNodeId,
|
|
||||||
handleId,
|
|
||||||
type: handleType as HandleType,
|
|
||||||
}
|
|
||||||
|
|
||||||
if (isValid) {
|
if (isValid) {
|
||||||
result.isValid = isValidConnection(connection, {
|
result.isValid = isValidConnection(connection, {
|
||||||
edges,
|
edges,
|
||||||
@@ -205,6 +200,13 @@ export function isValidHandle(
|
|||||||
sourceNode: findNode(connection.source)!,
|
sourceNode: findNode(connection.source)!,
|
||||||
targetNode: findNode(connection.target)!,
|
targetNode: findNode(connection.target)!,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
result.endHandle = {
|
||||||
|
nodeId: handleNodeId,
|
||||||
|
handleId,
|
||||||
|
type: handleType as HandleType,
|
||||||
|
position: result.isValid ? (handleToCheck.getAttribute('data-handlepos') as Position) : null,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user