rete
packageSignal types produced by NodeEditor instance
type Root<Scheme extends BaseSchemes> =
| { data: Scheme["Node"]; type: "nodecreate" }
| { data: Scheme["Node"]; type: "nodecreated" }
| { data: Scheme["Node"]; type: "noderemove" }
| { data: Scheme["Node"]; type: "noderemoved" }
| { data: Scheme["Connection"]; type: "connectioncreate" }
| { data: Scheme["Connection"]; type: "connectioncreated" }
| { data: Scheme["Connection"]; type: "connectionremove" }
| { data: Scheme["Connection"]; type: "connectionremoved" }
| { type: "clear" }
| { type: "clearcancelled" }
| { type: "cleared" };
Parameter | Extends | Description |
---|---|---|
Scheme | BaseSchemes | The scheme type |
The NodeEditor class is the entry class. It is used to create and manage nodes and connections.
class NodeEditor<Scheme extends BaseSchemes>
Parameter | Extends | Description |
---|---|---|
Scheme | BaseSchemes | The scheme type |
Extends Scope<Root
Add a connection
addConnection(data: Scheme["Connection"]): Promise<boolean>
Emits connectioncreate
connectioncreated
Throws If the connection has already been added
Parameter | Type | Description |
---|---|---|
data | Scheme["Connection"] | The connection data |
Returns Promise<boolean>
Whether the connection was added
Add a node
addNode(data: Scheme["Node"]): Promise<boolean>
Emits nodecreate
nodecreated
Throws If the node has already been added
Parameter | Type | Description |
---|---|---|
data | Scheme["Node"] | The node data |
Returns Promise<boolean>
Whether the node was added
Clear all nodes and connections
clear(): Promise<boolean>
Emits clear
clearcancelled
cleared
Returns Promise<boolean>
Whether the editor was cleared
Get a connection by id
getConnection(id: Scheme["Connection"]["id"]): Scheme["Connection"]
Parameter | Type | Description |
---|---|---|
id | Scheme["Connection"]["id"] | The connection id |
Returns Scheme["Connection"]
The connection or undefined
Get all connections
getConnections(): Scheme["Connection"][]
Returns Scheme["Connection"][]
Copy of array with onnections
Get a node by id
getNode(id: Scheme["Node"]["id"]): Scheme["Node"]
Parameter | Type | Description |
---|---|---|
id | Scheme["Node"]["id"] | The node id |
Returns Scheme["Node"]
The node or undefined
Get all nodes
getNodes(): Scheme["Node"][]
Returns Scheme["Node"][]
Copy of array with nodes
Remove a connection
removeConnection(id: Scheme["Connection"]["id"]): Promise<boolean>
Emits connectionremove
connectionremoved
Throws If the connection cannot be found
Parameter | Type | Description |
---|---|---|
id | Scheme["Connection"]["id"] | The connection id |
Returns Promise<boolean>
Whether the connection was removed
Remove a node
removeNode(id: Scheme["Node"]["id"]): Promise<boolean>
Emits noderemove
noderemoved
Throws If the node cannot be found
Parameter | Type | Description |
---|---|---|
id | Scheme["Node"]["id"] | The node id |
Returns Promise<boolean>
Whether the node was removed
Contains classes for classic scheme such as Node, Input, Output, Control, Socket, Connection
The node class
class Node<Inputs extends { [key in string]?: Socket }, Outputs extends { [key in string]?: Socket }, Controls extends { [key in string]?: Control }>
Parameter | Extends | Description |
---|---|---|
Inputs | { [key in string]?: Socket } | |
Outputs | { [key in string]?: Socket } | |
Controls | { [key in string]?: Control } |
Implements NodeBase
Examples
new Node('math')
Node controls
controls: Controls;
Node id, unique string generated by getUID
function
id: string;
Node inputs
inputs: { [key in string | number | symbol]?: Input<Exclude<Inputs[key], undefined>> }
Node outputs
outputs: { [key in string | number | symbol]?: Output<Exclude<Outputs[key], undefined>> }
Whether the node is selected. Default is false
selected: boolean;
The connection class
class Connection<Source extends Node, Target extends Node>
Parameter | Extends | Description |
---|---|---|
Source | Node | |
Target | Node |
Implements ConnectionBase
constructor(source: Source, sourceOutput: keyof Source["outputs"], target: Target, targetInput: keyof Target["inputs"]): Connection<Source, Target>
Parameter | Type | Description |
---|---|---|
source | Source | Source node instance |
sourceOutput | keyof Source["outputs"] | Source node output key |
target | Target | Target node instance |
targetInput | keyof Target["inputs"] | Target node input key |
Returns Connection<Source, Target>
Connection id, unique string generated by getUID
function
id: string;
Source node id
source: string;
Source node output key
sourceOutput: keyof Source["outputs"]
Target node id
target: string;
Target node input key
targetInput: keyof Target["inputs"]
The socket class
class Socket
constructor(name: string): Socket
Parameter | Type | Description |
---|---|---|
name | string | Name of the socket |
Returns Socket
Name of the socket
name: string;
The input port class
class Input<S extends Socket>
Parameter | Extends | Description |
---|---|---|
S | Socket |
Extends Port
constructor(socket: S, label: string, multipleConnections: boolean): Input<S>
Parameter | Type | Description |
---|---|---|
socket | S | Socket instance |
label | string | Label of the input port |
multipleConnections | boolean | Whether the output port can have multiple connections. Default is false |
Returns Input<S>
Control instance
control: Control;
Port id, unique string generated by getUID
function
id: string;
Port index, used for sorting ports. Default is 0
index: number;
Label of the input port
label: string;
Whether the output port can have multiple connections. Default is false
multipleConnections: boolean;
Whether the control is visible. Can be managed dynamically by extensions. Default is true
showControl: boolean;
Socket instance
socket: S;
Add control to the input port
addControl(control: Control): void
Parameter | Type | Description |
---|---|---|
control | Control | Control instance |
Returns void
Remove control from the input port
removeControl(): void
Returns void
General control class
class Control
Extended by InputControl
Control id, unique string generated by getUID
function
id: string;
Control index, used for sorting controls. Default is 0
index: number;
The output port class
class Output<S extends Socket>
Parameter | Extends | Description |
---|---|---|
S | Socket |
Extends Port
constructor(socket: S, label: string, multipleConnections: boolean): Output<S>
Parameter | Type | Description |
---|---|---|
socket | S | Socket instance |
label | string | Label of the output port |
multipleConnections | boolean | Whether the output port can have multiple connections. Default is true |
Returns Output<S>
Port id, unique string generated by getUID
function
id: string;
Port index, used for sorting ports. Default is 0
index: number;
Label of the port
label: string;
Whether the output port can have multiple connections
multipleConnections: boolean;
Socket instance
socket: S;
The input control class
class InputControl<T extends "text" | "number", N extends unknown>
Parameter | Extends | Description |
---|---|---|
T | `"text" | "number"` |
N | unknown |
Extends Control
Examples
new InputControl('text', { readonly: true, initial: 'hello' })
constructor(type: T, options: InputControlOptions<N>): InputControl<T, N>
Parameter | Type | Description |
---|---|---|
type | T | Type of the control: text or number |
options | InputControlOptions<N> | Control options |
Returns InputControl<T, N>
Control id, unique string generated by getUID
function
id: string;
Control index, used for sorting controls. Default is 0
index: number;
Control options
options: InputControlOptions<N>;
Type of the control: text
or number
type: T;
Set control value
setValue(value: N): void
Parameter | Type | Description |
---|---|---|
value | N | Value to set |
Returns void
General port class
class Port<S extends Socket>
Parameter | Extends | Description |
---|---|---|
S | Socket |
constructor(socket: S, label: string, multipleConnections: boolean): Port<S>
Parameter | Type | Description |
---|---|---|
socket | S | Socket instance |
label | string | Label of the port |
multipleConnections | boolean | Whether the output port can have multiple connections |
Returns Port<S>
Port id, unique string generated by getUID
function
id: string;
Port index, used for sorting ports. Default is 0
index: number;
Label of the port
label: string;
Whether the output port can have multiple connections
multipleConnections: boolean;
Socket instance
socket: S;
Base class for all plugins and the core. Provides a signals mechanism to modify the data
class Scope<Produces extends unknown, Parents extends unknown[]>
Parameter | Extends | Description |
---|---|---|
Produces | unknown | |
Parents | unknown[] |
Extended by NodeEditor
A signal is a middleware chain that can be used to modify the data
class Signal<T extends unknown>
Parameter | Extends | Description |
---|---|---|
T | unknown | The data type |
The base schemes
type BaseSchemes = GetSchemes<NodeBase, ConnectionBase>;
The base connection type
type ConnectionBase = { id: ConnectionId; source: NodeId; target: NodeId };
Implemented by Connection
Connection id type
type ConnectionId = string;
Get the schemes
type GetSchemes<
NodeData extends NodeBase,
ConnectionData extends ConnectionBase,
> = { Connection: ConnectionData; Node: NodeData };
Parameter | Extends | Description |
---|---|---|
NodeData | NodeBase | |
ConnectionData | ConnectionBase |
Examples
GetSchemes<Node & { myProp: number }, Connection>
Validate the Scope signals and replace the parameter type with an error message if they are not assignable
type NestedScope<
S extends Scope<any, any[]>,
Current extends any[],
> = CanAssignEach<Current, S["__scope"]["parents"]>[number] extends true
? S
: "Parent signals do not satisfy the connected scope. Please use `.debug($ => $) for detailed assignment error";
Parameter | Extends | Description |
---|---|---|
S | Scope<any, any[]> | |
Current | any[] |
The base node type
type NodeBase = { id: NodeId };
Implemented by Node
Node id type
type NodeId = string;
type Pipe<T extends unknown> = (
data: T,
) => Promise<undefined | T> | undefined | T;
Parameter | Extends | Description |
---|---|---|
T | unknown | The data type |
getUID(): string
Returns string
A unique id