rete
packageSignal types produced by NodeEditor instance
tstype 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.
tsclass NodeEditor<Scheme extends BaseSchemes>
Parameter | Extends | Description |
---|---|---|
Scheme | BaseSchemes | The scheme type |
Extends Scope<Root<Scheme>>
Add a connection
tsaddConnection(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
tsaddNode(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
tsclear(): Promise<boolean>
Emits clear
clearcancelled
cleared
Returns Promise<boolean>
Whether the editor was cleared
Get a connection by id
tsgetConnection(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
tsgetConnections(): Scheme["Connection"][]
Returns Scheme["Connection"][]
Copy of array with onnections
Get a node by id
tsgetNode(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
tsgetNodes(): Scheme["Node"][]
Returns Scheme["Node"][]
Copy of array with nodes
Remove a connection
tsremoveConnection(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
tsremoveNode(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
tsclass 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
tsnew Node('math')
Node controls
tscontrols: Controls;
Node id, unique string generated by getUID
function
tsid: string;
Node inputs
tsinputs: { [key in string | number | symbol]?: Input<Exclude<Inputs[key], undefined>> }
Node outputs
tsoutputs: { [key in string | number | symbol]?: Output<Exclude<Outputs[key], undefined>> }
Whether the node is selected. Default is false
tsselected: boolean;
The connection class
tsclass Connection<Source extends Node, Target extends Node>
Parameter | Extends | Description |
---|---|---|
Source | Node | |
Target | Node |
Implements ConnectionBase
tsconstructor(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
tsid: string;
Source node id
tssource: string;
Source node output key
tssourceOutput: keyof Source["outputs"]
Target node id
tstarget: string;
Target node input key
tstargetInput: keyof Target["inputs"]
The socket class
tsclass Socket
tsconstructor(name: string): Socket
Parameter | Type | Description |
---|---|---|
name | string | Name of the socket |
Returns Socket
Name of the socket
tsname: string;
The input port class
tsclass Input<S extends Socket>
Parameter | Extends | Description |
---|---|---|
S | Socket |
Extends Port<S>
tsconstructor(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
tscontrol: Control;
Port id, unique string generated by getUID
function
tsid: string;
Port index, used for sorting ports. Default is 0
tsindex: number;
Label of the input port
tslabel: string;
Whether the output port can have multiple connections. Default is false
tsmultipleConnections: boolean;
Whether the control is visible. Can be managed dynamically by extensions. Default is true
tsshowControl: boolean;
Socket instance
tssocket: S;
Add control to the input port
tsaddControl(control: Control): void
Parameter | Type | Description |
---|---|---|
control | Control | Control instance |
Returns void
Remove control from the input port
tsremoveControl(): void
Returns void
General control class
tsclass Control
Extended by InputControl
Control id, unique string generated by getUID
function
tsid: string;
Control index, used for sorting controls. Default is 0
tsindex: number;
The output port class
tsclass Output<S extends Socket>
Parameter | Extends | Description |
---|---|---|
S | Socket |
Extends Port<S>
tsconstructor(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
tsid: string;
Port index, used for sorting ports. Default is 0
tsindex: number;
Label of the port
tslabel: string;
Whether the output port can have multiple connections
tsmultipleConnections: boolean;
Socket instance
tssocket: S;
The input control class
tsclass InputControl<T extends "text" | "number", N extends unknown>
Parameter | Extends | Description |
---|---|---|
T | `"text" | "number"` |
N | unknown |
Extends Control
Examples
tsnew InputControl('text', { readonly: true, initial: 'hello' })
tsconstructor(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
tsid: string;
Control index, used for sorting controls. Default is 0
tsindex: number;
Control options
tsoptions: InputControlOptions<N>;
Type of the control: text
or number
tstype: T;
Set control value
tssetValue(value: N): void
Parameter | Type | Description |
---|---|---|
value | N | Value to set |
Returns void
General port class
tsclass Port<S extends Socket>
Parameter | Extends | Description |
---|---|---|
S | Socket |
tsconstructor(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
tsid: string;
Port index, used for sorting ports. Default is 0
tsindex: number;
Label of the port
tslabel: string;
Whether the output port can have multiple connections
tsmultipleConnections: boolean;
Socket instance
tssocket: S;
Base class for all plugins and the core. Provides a signals mechanism to modify the data
tsclass 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
tsclass Signal<T extends unknown>
Parameter | Extends | Description |
---|---|---|
T | unknown | The data type |
The base schemes
tstype BaseSchemes = GetSchemes<NodeBase, ConnectionBase>;
The base connection type
tstype ConnectionBase = { id: ConnectionId; source: NodeId; target: NodeId };
Implemented by Connection
Connection id type
tstype ConnectionId = string;
Get the schemes
tstype GetSchemes< NodeData extends NodeBase, ConnectionData extends ConnectionBase, > = { Connection: ConnectionData; Node: NodeData };
Parameter | Extends | Description |
---|---|---|
NodeData | NodeBase | |
ConnectionData | ConnectionBase |
Examples
tsGetSchemes<Node & { myProp: number }, Connection>
Validate the Scope signals and replace the parameter type with an error message if they are not assignable
tstype 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
tstype NodeBase = { id: NodeId };
Implemented by Node
Node id type
tstype NodeId = string;
tstype Pipe<T extends unknown> = ( data: T, ) => Promise<undefined | T> | undefined | T;
Parameter | Extends | Description |
---|---|---|
T | unknown | The data type |
tsgetUID(): string
Returns string
A unique id