chore(core): accept invalid handle id config

Signed-off-by: braks <78412429+bcakmakoglu@users.noreply.github.com>
This commit is contained in:
braks
2023-03-23 15:58:30 +01:00
committed by Braks
parent 17da28e614
commit f08af3fc0e
+13 -9
View File
@@ -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(