diff --git a/packages/core/src/utils/edge.ts b/packages/core/src/utils/edge.ts index 98d5e19b..b33e5565 100644 --- a/packages/core/src/utils/edge.ts +++ b/packages/core/src/utils/edge.ts @@ -2,7 +2,7 @@ import { isNumber } from '@vueuse/core' import type { Actions, EdgePositions, GraphEdge, GraphNode, HandleElement, Rect, ViewportTransform, XYPosition } from '~/types' import { Position } from '~/types' -export function getHandlePosition(position: Position, rect: Rect, handle?: HandleElement): XYPosition { +export function getHandlePosition(position: Position, rect: Rect, handle: HandleElement | null): XYPosition { const x = (handle?.x ?? 0) + rect.x const y = (handle?.y ?? 0) + rect.y const width = handle?.width ?? rect.width @@ -32,22 +32,26 @@ export function getHandlePosition(position: Position, rect: Rect, handle?: Handl } } -export function getHandle(bounds: HandleElement[] = [], handleId?: string | null): HandleElement | undefined { - if (!bounds.length) return undefined +export function getHandle(bounds: HandleElement[] = [], handleId?: string | null): HandleElement | null { + if (!bounds.length) { + return null + } - let handle - if (!handleId && bounds.length === 1) handle = bounds[0] - else if (handleId) handle = bounds.find((d) => d.id === handleId) + if (!handleId || bounds.length === 1) { + return bounds[0] + } else if (handleId) { + return bounds.find((d) => d.id === handleId) || null + } - return handle || bounds[0] + return null } export function getEdgePositions( sourceNode: GraphNode, - sourceHandle: HandleElement | undefined, + sourceHandle: HandleElement | null, sourcePosition: Position, targetNode: GraphNode, - targetHandle: HandleElement | undefined, + targetHandle: HandleElement | null, targetPosition: Position, ): EdgePositions { const sourceHandlePos = getHandlePosition(