chore(docs): Add comments
This commit is contained in:
@@ -2,13 +2,6 @@ import { XYPosition, Dimensions } from './flow'
|
|||||||
import { NodeHandleBounds, Node, GraphNode, CoordinateExtent } from './node'
|
import { NodeHandleBounds, Node, GraphNode, CoordinateExtent } from './node'
|
||||||
import { Edge } from './edge'
|
import { Edge } from './edge'
|
||||||
|
|
||||||
export type CreatePositionChangeParams = {
|
|
||||||
node: GraphNode
|
|
||||||
nodeExtent: CoordinateExtent
|
|
||||||
diff?: XYPosition
|
|
||||||
dragging?: boolean
|
|
||||||
}
|
|
||||||
|
|
||||||
export type NodeDimensionChange = {
|
export type NodeDimensionChange = {
|
||||||
id: string
|
id: string
|
||||||
type: 'dimensions'
|
type: 'dimensions'
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ export type DefaultEdgeTypes = { [key in 'default' | 'straight' | 'smoothstep' |
|
|||||||
export type DefaultNodeTypes = { [key in 'input' | 'output' | 'default']: NodeComponent }
|
export type DefaultNodeTypes = { [key in 'input' | 'output' | 'default']: NodeComponent }
|
||||||
|
|
||||||
export interface BackgroundProps {
|
export interface BackgroundProps {
|
||||||
/** The background pattern */
|
/** The background pattern variant, {@link BackgroundVariant} */
|
||||||
variant?: BackgroundVariant
|
variant?: BackgroundVariant
|
||||||
/** Background pattern gap */
|
/** Background pattern gap */
|
||||||
gap?: number
|
gap?: number
|
||||||
@@ -61,6 +61,7 @@ export interface ControlEvents {
|
|||||||
(event: 'interaction-change', active: boolean): void
|
(event: 'interaction-change', active: boolean): void
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** expects a node and returns a color value */
|
||||||
export type StringFunc<N = any> = (node: Node<N> | GraphNode<N>) => string
|
export type StringFunc<N = any> = (node: Node<N> | GraphNode<N>) => string
|
||||||
export type ShapeRendering = 'inherit' | 'auto' | 'geometricPrecision' | 'optimizeSpeed' | 'crispEdges' | undefined
|
export type ShapeRendering = 'inherit' | 'auto' | 'geometricPrecision' | 'optimizeSpeed' | 'crispEdges' | undefined
|
||||||
|
|
||||||
@@ -79,6 +80,7 @@ export interface MiniMapProps<N = any> {
|
|||||||
maskColor?: string
|
maskColor?: string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** these props are passed to mini map node slots */
|
||||||
export interface MiniMapNodeProps {
|
export interface MiniMapNodeProps {
|
||||||
position: XYPosition
|
position: XYPosition
|
||||||
dimensions: Dimensions
|
dimensions: Dimensions
|
||||||
@@ -89,6 +91,7 @@ export interface MiniMapNodeProps {
|
|||||||
strokeWidth?: number
|
strokeWidth?: number
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** these props are passed to edge texts */
|
||||||
export interface EdgeTextProps extends HTMLAttributes {
|
export interface EdgeTextProps extends HTMLAttributes {
|
||||||
x: number
|
x: number
|
||||||
y: number
|
y: number
|
||||||
|
|||||||
@@ -39,12 +39,6 @@ export enum ConnectionMode {
|
|||||||
Loose = 'loose',
|
Loose = 'loose',
|
||||||
}
|
}
|
||||||
|
|
||||||
export type SetConnectionId = {
|
|
||||||
connectionNodeId: string | undefined
|
|
||||||
connectionHandleId: string | undefined
|
|
||||||
connectionHandleType: HandleType | undefined
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface ConnectionLineProps<N = any> {
|
export interface ConnectionLineProps<N = any> {
|
||||||
/** Source X position of the connection line */
|
/** Source X position of the connection line */
|
||||||
sourceX: number
|
sourceX: number
|
||||||
@@ -58,7 +52,9 @@ export interface ConnectionLineProps<N = any> {
|
|||||||
targetY: number
|
targetY: number
|
||||||
/** Target position of the connection line */
|
/** Target position of the connection line */
|
||||||
targetPosition: Position
|
targetPosition: Position
|
||||||
|
/** the shape of the connection line when active */
|
||||||
connectionLineType: ConnectionLineType
|
connectionLineType: ConnectionLineType
|
||||||
|
/** extra styles */
|
||||||
connectionLineStyle: CSSProperties
|
connectionLineStyle: CSSProperties
|
||||||
/** All currently stored nodes */
|
/** All currently stored nodes */
|
||||||
nodes: GraphNode<N>[]
|
nodes: GraphNode<N>[]
|
||||||
|
|||||||
+9
-6
@@ -30,7 +30,7 @@ export interface EdgeMarker {
|
|||||||
|
|
||||||
export interface MarkerProps {
|
export interface MarkerProps {
|
||||||
id: string
|
id: string
|
||||||
type: MarkerType
|
type: MarkerType | string
|
||||||
color?: string
|
color?: string
|
||||||
width?: number
|
width?: number
|
||||||
height?: number
|
height?: number
|
||||||
@@ -88,6 +88,7 @@ export interface EdgePositions {
|
|||||||
targetY: number
|
targetY: number
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Internal edge type */
|
||||||
export type GraphEdge<T = any, N = T> = Edge<T> & {
|
export type GraphEdge<T = any, N = T> = Edge<T> & {
|
||||||
sourceNode: GraphNode<N>
|
sourceNode: GraphNode<N>
|
||||||
targetNode: GraphNode<N>
|
targetNode: GraphNode<N>
|
||||||
@@ -95,10 +96,11 @@ export type GraphEdge<T = any, N = T> = Edge<T> & {
|
|||||||
z?: number
|
z?: number
|
||||||
} & EdgePositions
|
} & EdgePositions
|
||||||
|
|
||||||
|
/** these props are passed to edge components */
|
||||||
export interface EdgeProps<Data = any> {
|
export interface EdgeProps<Data = any> {
|
||||||
id: string
|
id: string
|
||||||
sourceNode: any
|
sourceNode: GraphNode
|
||||||
targetNode: any
|
targetNode: GraphNode
|
||||||
label?:
|
label?:
|
||||||
| string
|
| string
|
||||||
| {
|
| {
|
||||||
@@ -121,7 +123,7 @@ export interface EdgeProps<Data = any> {
|
|||||||
target: string
|
target: string
|
||||||
sourceHandle?: string
|
sourceHandle?: string
|
||||||
targetHandle?: string
|
targetHandle?: string
|
||||||
labelStyle?: any
|
labelStyle?: CSSProperties
|
||||||
labelShowBg?: boolean
|
labelShowBg?: boolean
|
||||||
labelBgStyle?: any
|
labelBgStyle?: any
|
||||||
labelBgPadding?: [number, number]
|
labelBgPadding?: [number, number]
|
||||||
@@ -133,10 +135,11 @@ export interface EdgeProps<Data = any> {
|
|||||||
curvature?: number
|
curvature?: number
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** these props are passed to smooth step edges */
|
||||||
export interface SmoothStepEdgeProps<Data = any> extends EdgeProps<Data> {
|
export interface SmoothStepEdgeProps<Data = any> extends EdgeProps<Data> {
|
||||||
id: string
|
id: string
|
||||||
sourceNode: any
|
sourceNode: GraphNode
|
||||||
targetNode: any
|
targetNode: GraphNode
|
||||||
label?:
|
label?:
|
||||||
| string
|
| string
|
||||||
| {
|
| {
|
||||||
|
|||||||
@@ -5,8 +5,11 @@ import { ConnectionLineType, ConnectionMode } from './connection'
|
|||||||
import { KeyCode, PanOnScrollMode, UseZoomPanHelper } from './zoom'
|
import { KeyCode, PanOnScrollMode, UseZoomPanHelper } from './zoom'
|
||||||
import { DefaultEdgeTypes, DefaultNodeTypes, EdgeComponent, NodeComponent } from './components'
|
import { DefaultEdgeTypes, DefaultNodeTypes, EdgeComponent, NodeComponent } from './components'
|
||||||
|
|
||||||
|
/** an internal element */
|
||||||
export type FlowElement<N = any, E = any> = GraphNode<N> | GraphEdge<E>
|
export type FlowElement<N = any, E = any> = GraphNode<N> | GraphEdge<E>
|
||||||
export type FlowElements<N = any, E = any> = FlowElement<N, E>[]
|
export type FlowElements<N = any, E = any> = FlowElement<N, E>[]
|
||||||
|
|
||||||
|
/** base element props */
|
||||||
export interface Element<Data = any> {
|
export interface Element<Data = any> {
|
||||||
id: string
|
id: string
|
||||||
label?:
|
label?:
|
||||||
@@ -23,8 +26,10 @@ export interface Element<Data = any> {
|
|||||||
}
|
}
|
||||||
export type Elements<N = any, E = any> = (Node<N> | Edge<E>)[]
|
export type Elements<N = any, E = any> = (Node<N> | Edge<E>)[]
|
||||||
|
|
||||||
|
/** Transform x, y, z */
|
||||||
export type Transform = [number, number, number]
|
export type Transform = [number, number, number]
|
||||||
|
|
||||||
|
/** Handle Positions */
|
||||||
export enum Position {
|
export enum Position {
|
||||||
Left = 'left',
|
Left = 'left',
|
||||||
Top = 'top',
|
Top = 'top',
|
||||||
|
|||||||
+18
-2
@@ -10,41 +10,55 @@ export type NodeHandleBounds = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export interface Node<T = any> extends Element<T> {
|
export interface Node<T = any> extends Element<T> {
|
||||||
|
/** node position x, y */
|
||||||
position: XYPosition
|
position: XYPosition
|
||||||
|
/** node type, can be a default type or a custom type */
|
||||||
type?: keyof DefaultNodeTypes | string
|
type?: keyof DefaultNodeTypes | string
|
||||||
|
/** handle position */
|
||||||
targetPosition?: Position
|
targetPosition?: Position
|
||||||
|
/** handle position */
|
||||||
sourcePosition?: Position
|
sourcePosition?: Position
|
||||||
draggable?: boolean
|
draggable?: boolean
|
||||||
selectable?: boolean
|
selectable?: boolean
|
||||||
connectable?: boolean
|
connectable?: boolean
|
||||||
dragHandle?: string
|
dragHandle?: string
|
||||||
|
/** move on grid */
|
||||||
snapGrid?: SnapGrid
|
snapGrid?: SnapGrid
|
||||||
|
/** called when used as target for new connection */
|
||||||
isValidTargetPos?: ValidConnectionFunc
|
isValidTargetPos?: ValidConnectionFunc
|
||||||
|
/** called when used as source for new connection */
|
||||||
isValidSourcePos?: ValidConnectionFunc
|
isValidSourcePos?: ValidConnectionFunc
|
||||||
|
/** define node extent, i.e. area in which node can be moved */
|
||||||
extent?: 'parent' | CoordinateExtent
|
extent?: 'parent' | CoordinateExtent
|
||||||
|
/** expands parent area to fit child node */
|
||||||
expandParent?: boolean
|
expandParent?: boolean
|
||||||
|
/** define node as a child node by setting a parent node id */
|
||||||
parentNode?: string
|
parentNode?: string
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface GraphNode<T = any> extends Node<T> {
|
export interface GraphNode<T = any> extends Node<T> {
|
||||||
|
/** absolute position in relation to parent elements + z-index */
|
||||||
computedPosition: XYZPosition
|
computedPosition: XYZPosition
|
||||||
handleBounds: NodeHandleBounds
|
handleBounds: NodeHandleBounds
|
||||||
|
/** node width, height */
|
||||||
dimensions: Dimensions
|
dimensions: Dimensions
|
||||||
isParent: boolean
|
isParent: boolean
|
||||||
selected: boolean
|
selected: boolean
|
||||||
dragging: boolean
|
dragging: boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** these props are passed to node components */
|
||||||
export interface NodeProps<T = any> {
|
export interface NodeProps<T = any> {
|
||||||
id: string
|
id: string
|
||||||
|
/** node DOM-element */
|
||||||
nodeElement: HTMLDivElement
|
nodeElement: HTMLDivElement
|
||||||
type: string
|
type: string
|
||||||
data: T
|
data: T
|
||||||
selected: boolean
|
selected: boolean
|
||||||
connectable: boolean
|
connectable: boolean
|
||||||
/** computed position is the position relative to the node's extent (i.e. parent or CoordinateExtent) */
|
/** absolute position in relation to parent elements + z-index */
|
||||||
computedPosition: XYZPosition
|
computedPosition: XYZPosition
|
||||||
/** x and y position on the graph */
|
/** x, y position */
|
||||||
position: XYPosition
|
position: XYPosition
|
||||||
/** node dimensions (width, height) */
|
/** node dimensions (width, height) */
|
||||||
dimensions: Dimensions
|
dimensions: Dimensions
|
||||||
@@ -54,7 +68,9 @@ export interface NodeProps<T = any> {
|
|||||||
props?: any
|
props?: any
|
||||||
component: any
|
component: any
|
||||||
}
|
}
|
||||||
|
/** called when used as target for new connection */
|
||||||
isValidTargetPos?: ValidConnectionFunc
|
isValidTargetPos?: ValidConnectionFunc
|
||||||
|
/** called when used as source for new connection */
|
||||||
isValidSourcePos?: ValidConnectionFunc
|
isValidSourcePos?: ValidConnectionFunc
|
||||||
parentNode?: string
|
parentNode?: string
|
||||||
dragging: boolean
|
dragging: boolean
|
||||||
|
|||||||
@@ -10,10 +10,13 @@ import { NodeChange, EdgeChange } from './changes'
|
|||||||
import { StartHandle, HandleType } from './handle'
|
import { StartHandle, HandleType } from './handle'
|
||||||
|
|
||||||
export interface State<N = any, E = N> extends Omit<FlowOptions<N, E>, 'id' | 'modelValue'> {
|
export interface State<N = any, E = N> extends Omit<FlowOptions<N, E>, 'id' | 'modelValue'> {
|
||||||
|
/** Event hooks, you can manipulate the triggers on your own peril */
|
||||||
hooks: FlowHooks<N, E>
|
hooks: FlowHooks<N, E>
|
||||||
instance: FlowInstance<N, E> | null
|
instance: FlowInstance<N, E> | null
|
||||||
|
|
||||||
|
/** all stored nodes */
|
||||||
nodes: GraphNode<N>[]
|
nodes: GraphNode<N>[]
|
||||||
|
/** all stored edges */
|
||||||
edges: GraphEdge<E>[]
|
edges: GraphEdge<E>[]
|
||||||
|
|
||||||
d3Zoom: D3Zoom | null
|
d3Zoom: D3Zoom | null
|
||||||
@@ -24,7 +27,9 @@ export interface State<N = any, E = N> extends Omit<FlowOptions<N, E>, 'id' | 'm
|
|||||||
defaultZoom: number
|
defaultZoom: number
|
||||||
translateExtent: CoordinateExtent
|
translateExtent: CoordinateExtent
|
||||||
nodeExtent: CoordinateExtent
|
nodeExtent: CoordinateExtent
|
||||||
|
/** zoom pane dimensions */
|
||||||
dimensions: Dimensions
|
dimensions: Dimensions
|
||||||
|
/** transform x, y, z */
|
||||||
transform: Transform
|
transform: Transform
|
||||||
onlyRenderVisibleElements: boolean
|
onlyRenderVisibleElements: boolean
|
||||||
defaultPosition: [number, number]
|
defaultPosition: [number, number]
|
||||||
@@ -83,9 +88,13 @@ export interface State<N = any, E = N> extends Omit<FlowOptions<N, E>, 'id' | 'm
|
|||||||
export interface Actions<N = any, E = N> {
|
export interface Actions<N = any, E = N> {
|
||||||
/** @deprecated use setNodes / setEdges instead */
|
/** @deprecated use setNodes / setEdges instead */
|
||||||
setElements: (elements: Elements<N, E>, extent?: CoordinateExtent) => void
|
setElements: (elements: Elements<N, E>, extent?: CoordinateExtent) => void
|
||||||
|
/** parses nodes and re-sets the state */
|
||||||
setNodes: (nodes: Node<N>[], extent?: CoordinateExtent) => void
|
setNodes: (nodes: Node<N>[], extent?: CoordinateExtent) => void
|
||||||
|
/** parses edges and re-sets the state */
|
||||||
setEdges: (edges: Edge<E>[]) => void
|
setEdges: (edges: Edge<E>[]) => void
|
||||||
|
/** parses nodes and adds to state */
|
||||||
addNodes: <NA = N>(nodes: Node<NA>[], extent?: CoordinateExtent) => void
|
addNodes: <NA = N>(nodes: Node<NA>[], extent?: CoordinateExtent) => void
|
||||||
|
/** parses edges and adds to state */
|
||||||
addEdges: <EA = E>(edgesOrConnections: (Edge<EA> | Connection)[]) => void
|
addEdges: <EA = E>(edgesOrConnections: (Edge<EA> | Connection)[]) => void
|
||||||
updateEdge: <EU = E>(oldEdge: GraphEdge<EU>, newConnection: Connection) => boolean
|
updateEdge: <EU = E>(oldEdge: GraphEdge<EU>, newConnection: Connection) => boolean
|
||||||
applyEdgeChanges: <ED = E>(changes: EdgeChange[]) => GraphEdge<ED>[]
|
applyEdgeChanges: <ED = E>(changes: EdgeChange[]) => GraphEdge<ED>[]
|
||||||
@@ -113,7 +122,9 @@ export interface Actions<N = any, E = N> {
|
|||||||
export interface Getters<N = any, E = N> {
|
export interface Getters<N = any, E = N> {
|
||||||
getEdgeTypes: Record<keyof DefaultEdgeTypes | string, EdgeComponent>
|
getEdgeTypes: Record<keyof DefaultEdgeTypes | string, EdgeComponent>
|
||||||
getNodeTypes: Record<keyof DefaultNodeTypes | string, NodeComponent>
|
getNodeTypes: Record<keyof DefaultNodeTypes | string, NodeComponent>
|
||||||
|
/** filters hidden nodes */
|
||||||
getNodes: GraphNode<N>[]
|
getNodes: GraphNode<N>[]
|
||||||
|
/** filters hidden edges */
|
||||||
getEdges: GraphEdge<E>[]
|
getEdges: GraphEdge<E>[]
|
||||||
getNode: (id: string) => GraphNode<N> | undefined
|
getNode: (id: string) => GraphNode<N> | undefined
|
||||||
getEdge: (id: string) => GraphEdge<E> | undefined
|
getEdge: (id: string) => GraphEdge<E> | undefined
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
import { clampPosition, isGraphNode } from './graph'
|
import { clampPosition, isGraphNode } from './graph'
|
||||||
import {
|
import {
|
||||||
CreatePositionChangeParams,
|
|
||||||
EdgeChange,
|
EdgeChange,
|
||||||
EdgeSelectionChange,
|
EdgeSelectionChange,
|
||||||
ElementChange,
|
ElementChange,
|
||||||
@@ -11,8 +10,17 @@ import {
|
|||||||
NodeSelectionChange,
|
NodeSelectionChange,
|
||||||
NodePositionChange,
|
NodePositionChange,
|
||||||
Getters,
|
Getters,
|
||||||
|
CoordinateExtent,
|
||||||
|
XYPosition,
|
||||||
} from '~/types'
|
} from '~/types'
|
||||||
|
|
||||||
|
type CreatePositionChangeParams = {
|
||||||
|
node: GraphNode
|
||||||
|
nodeExtent: CoordinateExtent
|
||||||
|
diff?: XYPosition
|
||||||
|
dragging?: boolean
|
||||||
|
}
|
||||||
|
|
||||||
function handleParentExpand(updateItem: GraphNode, getNode: Getters['getNode']) {
|
function handleParentExpand(updateItem: GraphNode, getNode: Getters['getNode']) {
|
||||||
const parent = updateItem.parentNode ? getNode(updateItem.parentNode) : undefined
|
const parent = updateItem.parentNode ? getNode(updateItem.parentNode) : undefined
|
||||||
if (parent) {
|
if (parent) {
|
||||||
|
|||||||
Reference in New Issue
Block a user