@@ -2,7 +2,7 @@ import { isNumber } from '@vueuse/core'
2
2
import type { Actions , EdgePositions , GraphEdge , GraphNode , HandleElement , Rect , ViewportTransform , XYPosition } from '~/types'
3
3
import { Position } from '~/types'
4
4
5
- export function getHandlePosition ( position : Position , rect : Rect , handle ? : HandleElement ) : XYPosition {
5
+ export function getHandlePosition ( position : Position , rect : Rect , handle : HandleElement | null ) : XYPosition {
6
6
const x = ( handle ?. x ?? 0 ) + rect . x
7
7
const y = ( handle ?. y ?? 0 ) + rect . y
8
8
const width = handle ?. width ?? rect . width
@@ -32,22 +32,26 @@ export function getHandlePosition(position: Position, rect: Rect, handle?: Handl
32
32
}
33
33
}
34
34
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
+ }
37
39
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
+ }
41
45
42
- return handle || bounds [ 0 ]
46
+ return null
43
47
}
44
48
45
49
export function getEdgePositions (
46
50
sourceNode : GraphNode ,
47
- sourceHandle : HandleElement | undefined ,
51
+ sourceHandle : HandleElement | null ,
48
52
sourcePosition : Position ,
49
53
targetNode : GraphNode ,
50
- targetHandle : HandleElement | undefined ,
54
+ targetHandle : HandleElement | null ,
51
55
targetPosition : Position ,
52
56
) : EdgePositions {
53
57
const sourceHandlePos = getHandlePosition (
0 commit comments