chore(core): accept invalid handle id config
Signed-off-by: braks <78412429+bcakmakoglu@users.noreply.github.com>
This commit is contained in:
@@ -2,7 +2,7 @@ import { isNumber } from '@vueuse/core'
|
|||||||
import type { Actions, EdgePositions, GraphEdge, GraphNode, HandleElement, Rect, ViewportTransform, XYPosition } from '~/types'
|
import type { Actions, EdgePositions, GraphEdge, GraphNode, HandleElement, Rect, ViewportTransform, XYPosition } from '~/types'
|
||||||
import { Position } 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 x = (handle?.x ?? 0) + rect.x
|
||||||
const y = (handle?.y ?? 0) + rect.y
|
const y = (handle?.y ?? 0) + rect.y
|
||||||
const width = handle?.width ?? rect.width
|
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 {
|
export function getHandle(bounds: HandleElement[] = [], handleId?: string | null): HandleElement | null {
|
||||||
if (!bounds.length) return undefined
|
if (!bounds.length) {
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
|
||||||
let handle
|
if (!handleId || bounds.length === 1) {
|
||||||
if (!handleId && bounds.length === 1) handle = bounds[0]
|
return bounds[0]
|
||||||
else if (handleId) handle = bounds.find((d) => d.id === handleId)
|
} else if (handleId) {
|
||||||
|
return bounds.find((d) => d.id === handleId) || null
|
||||||
|
}
|
||||||
|
|
||||||
return handle || bounds[0]
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getEdgePositions(
|
export function getEdgePositions(
|
||||||
sourceNode: GraphNode,
|
sourceNode: GraphNode,
|
||||||
sourceHandle: HandleElement | undefined,
|
sourceHandle: HandleElement | null,
|
||||||
sourcePosition: Position,
|
sourcePosition: Position,
|
||||||
targetNode: GraphNode,
|
targetNode: GraphNode,
|
||||||
targetHandle: HandleElement | undefined,
|
targetHandle: HandleElement | null,
|
||||||
targetPosition: Position,
|
targetPosition: Position,
|
||||||
): EdgePositions {
|
): EdgePositions {
|
||||||
const sourceHandlePos = getHandlePosition(
|
const sourceHandlePos = getHandlePosition(
|
||||||
|
|||||||
Reference in New Issue
Block a user