feat(nodes): add option to pass a valid target pos / valid source pos func to nodes

* edge updater cannot discern a valid connection by itself so we allow an option to pass a valid connection func to nodes which will then be used to determine if updating connection is valid
* it is optional, by default all connections are valid

Signed-off-by: Braks <78412429+bcakmakoglu@users.noreply.github.com>
This commit is contained in:
Braks
2021-11-25 15:21:36 +01:00
parent 95fc013613
commit 9e941966a4
13 changed files with 83 additions and 42 deletions
+5 -1
View File
@@ -1,7 +1,7 @@
import { Component, CSSProperties, DefineComponent } from 'vue'
import { DraggableOptions } from '@braks/revue-draggable'
import { XYPosition, ElementId, Position, SnapGrid } from './flow'
import { HandleElement } from './components'
import { HandleElement, ValidConnectionFunc } from './components'
export interface VFInternals {
isDragging?: boolean
@@ -24,6 +24,8 @@ export interface NodeProps<T = any> {
targetPosition?: Position
sourcePosition?: Position
dragging?: boolean
isValidTargetPos?: ValidConnectionFunc
isValidSourcePos?: ValidConnectionFunc
}
export type NodeComponent = Component<NodeProps> | DefineComponent<NodeProps, any, any, any, any> | string
@@ -46,6 +48,8 @@ export interface Node<T = any> {
connectable?: boolean
dragHandle?: string
snapGrid?: SnapGrid
isValidTargetPos?: ValidConnectionFunc
isValidSourcePos?: ValidConnectionFunc
}
export interface GraphNode<T = any> extends Node<T> {