added type docs for nodes & edges
This commit is contained in:
@@ -2,22 +2,40 @@ import { Position } from './utils';
|
|||||||
|
|
||||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||||
export type EdgeBase<EdgeData = any> = {
|
export type EdgeBase<EdgeData = any> = {
|
||||||
|
/** unique id of an edge */
|
||||||
id: string;
|
id: string;
|
||||||
|
/** type of an edge defined in edgeTypes */
|
||||||
type?: string;
|
type?: string;
|
||||||
|
/** id of source node */
|
||||||
source: string;
|
source: string;
|
||||||
|
/** id of target node */
|
||||||
target: string;
|
target: string;
|
||||||
|
/** id of source handle
|
||||||
|
* only needed if there are multiple handles per node
|
||||||
|
*/
|
||||||
sourceHandle?: string | null;
|
sourceHandle?: string | null;
|
||||||
|
/** id of target handle
|
||||||
|
* only needed if there are multiple handles per node
|
||||||
|
*/
|
||||||
targetHandle?: string | null;
|
targetHandle?: string | null;
|
||||||
animated?: boolean;
|
animated?: boolean;
|
||||||
hidden?: boolean;
|
hidden?: boolean;
|
||||||
deletable?: boolean;
|
deletable?: boolean;
|
||||||
selectable?: boolean;
|
selectable?: boolean;
|
||||||
|
/** arbitrary data passed to an edge */
|
||||||
data?: EdgeData;
|
data?: EdgeData;
|
||||||
selected?: boolean;
|
selected?: boolean;
|
||||||
|
/** set the marker on the beginning of an edge
|
||||||
|
* @example 'arrow', 'arrowclosed' or custom marker
|
||||||
|
*/
|
||||||
markerStart?: EdgeMarkerType;
|
markerStart?: EdgeMarkerType;
|
||||||
|
/** set the marker on the end of an edge
|
||||||
|
* @example 'arrow', 'arrowclosed' or custom marker
|
||||||
|
*/
|
||||||
markerEnd?: EdgeMarkerType;
|
markerEnd?: EdgeMarkerType;
|
||||||
zIndex?: number;
|
zIndex?: number;
|
||||||
ariaLabel?: string;
|
ariaLabel?: string;
|
||||||
|
/** padding around the edge where interaction is still possible */
|
||||||
interactionWidth?: number;
|
interactionWidth?: number;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -3,16 +3,34 @@ import { internalsSymbol } from '../constants';
|
|||||||
import type { XYPosition, Position, CoordinateExtent, HandleElement } from '.';
|
import type { XYPosition, Position, CoordinateExtent, HandleElement } from '.';
|
||||||
import { Optional } from '../utils/types';
|
import { Optional } from '../utils/types';
|
||||||
|
|
||||||
// this is stuff that all nodes share independent of the framework
|
/**
|
||||||
|
* Framework independent node data structure.
|
||||||
|
*
|
||||||
|
* @typeParam T - type of the node data
|
||||||
|
* @typeParam U - type of the node
|
||||||
|
*/
|
||||||
export type NodeBase<T = any, U extends string | undefined = string | undefined> = {
|
export type NodeBase<T = any, U extends string | undefined = string | undefined> = {
|
||||||
|
/** unique id of a node */
|
||||||
id: string;
|
id: string;
|
||||||
|
/** position of a node on the pane
|
||||||
|
* @example { x: 0, y: 0 }
|
||||||
|
*/
|
||||||
position: XYPosition;
|
position: XYPosition;
|
||||||
|
/** arbitrary data passed to a node */
|
||||||
data: T;
|
data: T;
|
||||||
|
/** type of node defined in nodeTypes */
|
||||||
type?: U;
|
type?: U;
|
||||||
|
/** only relevant for default, source, target nodeType. controls source position
|
||||||
|
* @example 'right', 'left', 'top', 'bottom'
|
||||||
|
*/
|
||||||
sourcePosition?: Position;
|
sourcePosition?: Position;
|
||||||
|
/** only relevant for default, source, target nodeType. controls target position
|
||||||
|
* @example 'right', 'left', 'top', 'bottom'
|
||||||
|
*/
|
||||||
targetPosition?: Position;
|
targetPosition?: Position;
|
||||||
hidden?: boolean;
|
hidden?: boolean;
|
||||||
selected?: boolean;
|
selected?: boolean;
|
||||||
|
/** is node being dragged */
|
||||||
dragging?: boolean;
|
dragging?: boolean;
|
||||||
draggable?: boolean;
|
draggable?: boolean;
|
||||||
selectable?: boolean;
|
selectable?: boolean;
|
||||||
@@ -21,11 +39,21 @@ export type NodeBase<T = any, U extends string | undefined = string | undefined>
|
|||||||
dragHandle?: string;
|
dragHandle?: string;
|
||||||
width?: number | null;
|
width?: number | null;
|
||||||
height?: number | null;
|
height?: number | null;
|
||||||
|
/** parent node id, used for creating sub-flows */
|
||||||
parentNode?: string;
|
parentNode?: string;
|
||||||
zIndex?: number;
|
zIndex?: number;
|
||||||
|
/** boundary a node can be moved in
|
||||||
|
* @example 'parent' or [[0, 0], [100, 100]]
|
||||||
|
*/
|
||||||
extent?: 'parent' | CoordinateExtent;
|
extent?: 'parent' | CoordinateExtent;
|
||||||
expandParent?: boolean;
|
expandParent?: boolean;
|
||||||
ariaLabel?: string;
|
ariaLabel?: string;
|
||||||
|
/** origin of the node relative to it's position
|
||||||
|
* @example
|
||||||
|
* [0.5, 0.5] // centers the node
|
||||||
|
* [0, 0] // top left
|
||||||
|
* [1, 1] // bottom right
|
||||||
|
*/
|
||||||
origin?: NodeOrigin;
|
origin?: NodeOrigin;
|
||||||
handles?: NodeHandle[];
|
handles?: NodeHandle[];
|
||||||
computed?: {
|
computed?: {
|
||||||
@@ -47,7 +75,14 @@ export type NodeBase<T = any, U extends string | undefined = string | undefined>
|
|||||||
};
|
};
|
||||||
|
|
||||||
// props that get passed to a custom node
|
// props that get passed to a custom node
|
||||||
|
/**
|
||||||
|
* The node data structure that gets used for the nodes prop.
|
||||||
|
*
|
||||||
|
* @public
|
||||||
|
* @param id - The id of the node.
|
||||||
|
*/
|
||||||
export type NodeProps<T = any> = {
|
export type NodeProps<T = any> = {
|
||||||
|
/** id of the node */
|
||||||
id: NodeBase['id'];
|
id: NodeBase['id'];
|
||||||
data: T;
|
data: T;
|
||||||
dragHandle: NodeBase['dragHandle'];
|
dragHandle: NodeBase['dragHandle'];
|
||||||
|
|||||||
Reference in New Issue
Block a user