Merge pull request #3796 from xyflow/improve-type-docs

Improve type docs
This commit is contained in:
Moritz Klack
2024-01-16 18:11:03 +01:00
committed by GitHub
20 changed files with 842 additions and 7 deletions
+18
View File
@@ -2,22 +2,40 @@ import { Position } from './utils';
// eslint-disable-next-line @typescript-eslint/no-explicit-any
export type EdgeBase<EdgeData = any> = {
/** Unique id of an edge */
id: string;
/** Type of an edge defined in edgeTypes */
type?: string;
/** Id of source node */
source: string;
/** Id of target node */
target: string;
/** Id of source handle
* only needed if there are multiple handles per node
*/
sourceHandle?: string | null;
/** Id of target handle
* only needed if there are multiple handles per node
*/
targetHandle?: string | null;
animated?: boolean;
hidden?: boolean;
deletable?: boolean;
selectable?: boolean;
/** Arbitrary data passed to an edge */
data?: EdgeData;
selected?: boolean;
/** Set the marker on the beginning of an edge
* @example 'arrow', 'arrowclosed' or custom marker
*/
markerStart?: EdgeMarkerType;
/** Set the marker on the end of an edge
* @example 'arrow', 'arrowclosed' or custom marker
*/
markerEnd?: EdgeMarkerType;
zIndex?: number;
ariaLabel?: string;
/** Padding around the edge where interaction is still possible */
interactionWidth?: number;
};
+17
View File
@@ -27,12 +27,29 @@ export type ConnectionHandle = {
};
export type HandleProps = {
/** Type of the handle
* @example HandleType.Source, HandleType.Target
*/
type: HandleType;
/** Position of the handle
* @example Position.TopLeft, Position.TopRight,
* Position.BottomLeft, Position.BottomRight
*/
position: Position;
/** Should you be able to connect to/from this handle */
isConnectable?: boolean;
/** Should you be able to connect from this handle */
isConnectableStart?: boolean;
/** Should you be able to connect to this handle */
isConnectableEnd?: boolean;
/** Callback called when connection is made */
onConnect?: OnConnect;
/** Callback if connection is valid
* @remarks connection becomes an edge if isValidConnection returns true
*/
isValidConnection?: IsValidConnection;
/** Id of the handle
* @remarks optional if there is only one handle of this type
*/
id?: string;
};
+37 -2
View File
@@ -3,16 +3,34 @@ import { internalsSymbol } from '../constants';
import type { XYPosition, Position, CoordinateExtent, HandleElement } from '.';
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> = {
/** Unique id of a node */
id: string;
/** Position of a node on the pane
* @example { x: 0, y: 0 }
*/
position: XYPosition;
/** Arbitrary data passed to a node */
data: T;
/** Type of node defined in nodeTypes */
type?: U;
/** Only relevant for default, source, target nodeType. controls source position
* @example 'right', 'left', 'top', 'bottom'
*/
sourcePosition?: Position;
/** Only relevant for default, source, target nodeType. controls target position
* @example 'right', 'left', 'top', 'bottom'
*/
targetPosition?: Position;
hidden?: boolean;
selected?: boolean;
/** True, if node is being dragged */
dragging?: boolean;
draggable?: boolean;
selectable?: boolean;
@@ -21,11 +39,21 @@ export type NodeBase<T = any, U extends string | undefined = string | undefined>
dragHandle?: string;
width?: number | null;
height?: number | null;
/** Parent node id, used for creating sub-flows */
parentNode?: string;
zIndex?: number;
/** Boundary a node can be moved in
* @example 'parent' or [[0, 0], [100, 100]]
*/
extent?: 'parent' | CoordinateExtent;
expandParent?: boolean;
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;
handles?: NodeHandle[];
computed?: {
@@ -34,7 +62,7 @@ export type NodeBase<T = any, U extends string | undefined = string | undefined>
positionAbsolute?: XYPosition;
};
// only used internally
// Only used internally
[internalsSymbol]?: {
z?: number;
handleBounds?: NodeHandleBounds;
@@ -47,7 +75,14 @@ export type NodeBase<T = any, U extends string | undefined = string | undefined>
};
// 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> = {
/** Id of the node */
id: NodeBase['id'];
data: T;
dragHandle: NodeBase['dragHandle'];