Skip to content

Commit f08af3f

Browse files
committed
chore(core): accept invalid handle id config
Signed-off-by: braks <[email protected]>
1 parent 17da28e commit f08af3f

File tree

1 file changed

+13
-9
lines changed

1 file changed

+13
-9
lines changed

packages/core/src/utils/edge.ts

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { isNumber } from '@vueuse/core'
22
import type { Actions, EdgePositions, GraphEdge, GraphNode, HandleElement, Rect, ViewportTransform, XYPosition } from '~/types'
33
import { Position } from '~/types'
44

5-
export function getHandlePosition(position: Position, rect: Rect, handle?: HandleElement): XYPosition {
5+
export function getHandlePosition(position: Position, rect: Rect, handle: HandleElement | null): XYPosition {
66
const x = (handle?.x ?? 0) + rect.x
77
const y = (handle?.y ?? 0) + rect.y
88
const width = handle?.width ?? rect.width
@@ -32,22 +32,26 @@ export function getHandlePosition(position: Position, rect: Rect, handle?: Handl
3232
}
3333
}
3434

35-
export function getHandle(bounds: HandleElement[] = [], handleId?: string | null): HandleElement | undefined {
36-
if (!bounds.length) return undefined
35+
export function getHandle(bounds: HandleElement[] = [], handleId?: string | null): HandleElement | null {
36+
if (!bounds.length) {
37+
return null
38+
}
3739

38-
let handle
39-
if (!handleId && bounds.length === 1) handle = bounds[0]
40-
else if (handleId) handle = bounds.find((d) => d.id === handleId)
40+
if (!handleId || bounds.length === 1) {
41+
return bounds[0]
42+
} else if (handleId) {
43+
return bounds.find((d) => d.id === handleId) || null
44+
}
4145

42-
return handle || bounds[0]
46+
return null
4347
}
4448

4549
export function getEdgePositions(
4650
sourceNode: GraphNode,
47-
sourceHandle: HandleElement | undefined,
51+
sourceHandle: HandleElement | null,
4852
sourcePosition: Position,
4953
targetNode: GraphNode,
50-
targetHandle: HandleElement | undefined,
54+
targetHandle: HandleElement | null,
5155
targetPosition: Position,
5256
): EdgePositions {
5357
const sourceHandlePos = getHandlePosition(

0 commit comments

Comments
 (0)