update(edges): Use proper handle bounds
This commit is contained in:
@@ -64,9 +64,9 @@ const targetNodeHandles = computed(() => {
|
|||||||
return edge.value.targetNode.handleBounds.target
|
return edge.value.targetNode.handleBounds.target
|
||||||
}
|
}
|
||||||
|
|
||||||
const targetBounds = edge.value.targetNode.handleBounds.target || []
|
const targetBounds = edge.value.targetNode.handleBounds.target
|
||||||
const sourceBounds = edge.value.targetNode.handleBounds.source || []
|
const sourceBounds = edge.value.targetNode.handleBounds.source
|
||||||
return [...sourceBounds, ...targetBounds]
|
return targetBounds ?? sourceBounds
|
||||||
})
|
})
|
||||||
|
|
||||||
const sourceNodeHandles = computed(() => {
|
const sourceNodeHandles = computed(() => {
|
||||||
@@ -74,17 +74,14 @@ const sourceNodeHandles = computed(() => {
|
|||||||
return edge.value.sourceNode.handleBounds.source
|
return edge.value.sourceNode.handleBounds.source
|
||||||
}
|
}
|
||||||
|
|
||||||
const targetBounds = edge.value.sourceNode.handleBounds.target || []
|
const targetBounds = edge.value.sourceNode.handleBounds.target
|
||||||
const sourceBounds = edge.value.sourceNode.handleBounds.source || []
|
const sourceBounds = edge.value.sourceNode.handleBounds.source
|
||||||
return [...sourceBounds, ...targetBounds]
|
return sourceBounds ?? targetBounds
|
||||||
})
|
})
|
||||||
|
|
||||||
const sourceHandle = controlledComputed(
|
const sourceHandle = computed(() => getHandle(sourceNodeHandles.value, edge.value.sourceHandle))
|
||||||
() => edge.value.sourceNode.handleBounds,
|
|
||||||
() => getHandle(sourceNodeHandles.value, edge.value.sourceHandle),
|
|
||||||
)
|
|
||||||
|
|
||||||
const targetHandle = computed(() => getHandle(targetNodeHandles.value, edge.value.targetHandle))
|
const targetHandle = computed(() => getHandle(targetNodeHandles.value, edge.value.targetHandle))
|
||||||
|
|
||||||
const sourcePosition = computed(() => (sourceHandle.value ? sourceHandle.value.position : Position.Bottom))
|
const sourcePosition = computed(() => (sourceHandle.value ? sourceHandle.value.position : Position.Bottom))
|
||||||
const targetPosition = computed(() => (targetHandle.value ? targetHandle.value.position : Position.Top))
|
const targetPosition = computed(() => (targetHandle.value ? targetHandle.value.position : Position.Top))
|
||||||
|
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
<script lang="ts" setup>
|
<script lang="ts" setup>
|
||||||
import { useHandle, useVueFlow } from '../../composables'
|
import { useHandle, useVueFlow } from '../../composables'
|
||||||
import { Position } from '../../types'
|
import { ConnectionMode, Position } from '../../types'
|
||||||
import { NodeId } from '../../context'
|
import { NodeId } from '../../context'
|
||||||
import type { HandleProps } from '../../types/handle'
|
import type { HandleProps } from '../../types/handle'
|
||||||
|
|
||||||
const { id, hooks, connectionStartHandle } = useVueFlow()
|
const { id, hooks, connectionStartHandle, connectionMode } = useVueFlow()
|
||||||
const props = withDefaults(defineProps<HandleProps>(), {
|
const props = withDefaults(defineProps<HandleProps>(), {
|
||||||
type: 'source',
|
type: 'source',
|
||||||
position: 'top' as Position,
|
position: 'top' as Position,
|
||||||
@@ -13,11 +13,13 @@ const props = withDefaults(defineProps<HandleProps>(), {
|
|||||||
|
|
||||||
const nodeId = inject(NodeId, '')
|
const nodeId = inject(NodeId, '')
|
||||||
|
|
||||||
const handleId = props.id ?? `${nodeId}__handle-${props.position}`
|
const handleId = computed(() =>
|
||||||
|
props.id ?? connectionMode.value === ConnectionMode.Strict ? null : `${nodeId}__handle-${props.position}`,
|
||||||
|
)
|
||||||
|
|
||||||
const { onMouseDown, onClick } = useHandle()
|
const { onMouseDown, onClick } = useHandle()
|
||||||
const onMouseDownHandler = (event: MouseEvent) =>
|
const onMouseDownHandler = (event: MouseEvent) =>
|
||||||
onMouseDown(event, handleId, nodeId, props.type === 'target', props.isValidConnection, undefined)
|
onMouseDown(event, handleId.value, nodeId, props.type === 'target', props.isValidConnection, undefined)
|
||||||
const onClickHandler = (event: MouseEvent) => onClick(event, props.id ?? null, nodeId, props.type, props.isValidConnection)
|
const onClickHandler = (event: MouseEvent) => onClick(event, props.id ?? null, nodeId, props.type, props.isValidConnection)
|
||||||
</script>
|
</script>
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
|
|||||||
@@ -34,13 +34,11 @@ export const getHandlePosition = (position: Position, rect: Rect, handle?: Handl
|
|||||||
export const getHandle = (bounds: HandleElement[] = [], handleId?: string | null): HandleElement | undefined => {
|
export const getHandle = (bounds: HandleElement[] = [], handleId?: string | null): HandleElement | undefined => {
|
||||||
if (!bounds.length) return undefined
|
if (!bounds.length) return undefined
|
||||||
|
|
||||||
// there is no handleId when there are no multiple handles/ handles with ids
|
|
||||||
// so we just pick the first one
|
|
||||||
let handle
|
let handle
|
||||||
if (!handleId && bounds.length === 1) handle = bounds[0]
|
if (!handleId && bounds.length === 1) handle = bounds[0]
|
||||||
else if (handleId) handle = bounds.find((d) => d.id === handleId)
|
else if (handleId) handle = bounds.find((d) => d.id === handleId)
|
||||||
|
|
||||||
return handle
|
return handle || bounds[0]
|
||||||
}
|
}
|
||||||
|
|
||||||
export const getEdgePositions = (
|
export const getEdgePositions = (
|
||||||
|
|||||||
Reference in New Issue
Block a user