API for rete package - Rete.js

API for rete package

Root

editor.ts

Signal types produced by NodeEditor instance

ts
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" };
ParameterExtendsDescription
SchemeBaseSchemesThe scheme type

NodeEditor

editor.ts

The NodeEditor class is the entry class. It is used to create and manage nodes and connections.

ts
class NodeEditor<Scheme extends BaseSchemes>
ParameterExtendsDescription
SchemeBaseSchemesThe scheme type

Extends Scope<Root>

addConnection

editor.ts

Add a connection

ts
addConnection(data: Scheme["Connection"]): Promise<boolean>

Emits connectioncreate connectioncreated

Throws If the connection has already been added

ParameterTypeDescription
dataScheme["Connection"]The connection data

Returns Promise<boolean> Whether the connection was added

addNode

editor.ts

Add a node

ts
addNode(data: Scheme["Node"]): Promise<boolean>

Emits nodecreate nodecreated

Throws If the node has already been added

ParameterTypeDescription
dataScheme["Node"]The node data

Returns Promise<boolean> Whether the node was added

clear

editor.ts

Clear all nodes and connections

ts
clear(): Promise<boolean>

Emits clear clearcancelled cleared

Returns Promise<boolean> Whether the editor was cleared

getConnection

editor.ts

Get a connection by id

ts
getConnection(id: Scheme["Connection"]["id"]): Scheme["Connection"]
ParameterTypeDescription
idScheme["Connection"]["id"]The connection id

Returns Scheme["Connection"] The connection or undefined

getConnections

editor.ts

Get all connections

ts
getConnections(): Scheme["Connection"][]

Returns Scheme["Connection"][] Copy of array with onnections

getNode

editor.ts

Get a node by id

ts
getNode(id: Scheme["Node"]["id"]): Scheme["Node"]
ParameterTypeDescription
idScheme["Node"]["id"]The node id

Returns Scheme["Node"] The node or undefined

getNodes

editor.ts

Get all nodes

ts
getNodes(): Scheme["Node"][]

Returns Scheme["Node"][] Copy of array with nodes

removeConnection

editor.ts

Remove a connection

ts
removeConnection(id: Scheme["Connection"]["id"]): Promise<boolean>

Emits connectionremove connectionremoved

Throws If the connection cannot be found

ParameterTypeDescription
idScheme["Connection"]["id"]The connection id

Returns Promise<boolean> Whether the connection was removed

removeNode

editor.ts

Remove a node

ts
removeNode(id: Scheme["Node"]["id"]): Promise<boolean>

Emits noderemove noderemoved

Throws If the node cannot be found

ParameterTypeDescription
idScheme["Node"]["id"]The node id

Returns Promise<boolean> Whether the node was removed

ClassicPreset

presets/classic.ts

Contains classes for classic scheme such as Node, Input, Output, Control, Socket, Connection

Node

presets/classic.ts

The node class

ts
class Node<Inputs extends { [key in string]?: Socket }, Outputs extends { [key in string]?: Socket }, Controls extends { [key in string]?: Control }>
ParameterExtendsDescription
Inputs{ [key in string]?: Socket }
Outputs{ [key in string]?: Socket }
Controls{ [key in string]?: Control }

Implements NodeBase

Examples

ts
new Node('math')

controls

presets/classic.ts

Node controls

ts
controls: Controls;

id

presets/classic.ts

Node id, unique string generated by getUID function

ts
id: string;

inputs

presets/classic.ts

Node inputs

ts
inputs: { [key in string | number | symbol]?: Input<Exclude<Inputs[key], undefined>> }

outputs

presets/classic.ts

Node outputs

ts
outputs: { [key in string | number | symbol]?: Output<Exclude<Outputs[key], undefined>> }

selected

presets/classic.ts

Whether the node is selected. Default is false

ts
selected: boolean;

Connection

presets/classic.ts

The connection class

ts
class Connection<Source extends Node, Target extends Node>
ParameterExtendsDescription
SourceNode
TargetNode

Implements ConnectionBase

constructor

presets/classic.ts

ts
constructor(source: Source, sourceOutput: keyof Source["outputs"], target: Target, targetInput: keyof Target["inputs"]): Connection<Source, Target>
ParameterTypeDescription
sourceSourceSource node instance
sourceOutputkeyof Source["outputs"]Source node output key
targetTargetTarget node instance
targetInputkeyof Target["inputs"]Target node input key

Returns Connection<Source, Target>

id

presets/classic.ts

Connection id, unique string generated by getUID function

ts
id: string;

source

presets/classic.ts

Source node id

ts
source: string;

sourceOutput

presets/classic.ts

Source node output key

ts
sourceOutput: keyof Source["outputs"]

target

presets/classic.ts

Target node id

ts
target: string;

targetInput

presets/classic.ts

Target node input key

ts
targetInput: keyof Target["inputs"]

Socket

presets/classic.ts

The socket class

ts
class Socket

constructor

presets/classic.ts

ts
constructor(name: string): Socket
ParameterTypeDescription
namestringName of the socket

Returns Socket

name

presets/classic.ts

Name of the socket

ts
name: string;

Input

presets/classic.ts

The input port class

ts
class Input<S extends Socket>
ParameterExtendsDescription
SSocket

Extends Port

constructor

presets/classic.ts

ts
constructor(socket: S, label: string, multipleConnections: boolean): Input<S>
ParameterTypeDescription
socketSSocket instance
labelstringLabel of the input port
multipleConnectionsbooleanWhether the output port can have multiple connections. Default is false

Returns Input<S>

control

presets/classic.ts

Control instance

ts
control: Control;

id

presets/classic.ts

Port id, unique string generated by getUID function

ts
id: string;

index

presets/classic.ts

Port index, used for sorting ports. Default is 0

ts
index: number;

label

presets/classic.ts

Label of the input port

ts
label: string;

multipleConnections

presets/classic.ts

Whether the output port can have multiple connections. Default is false

ts
multipleConnections: boolean;

showControl

presets/classic.ts

Whether the control is visible. Can be managed dynamically by extensions. Default is true

ts
showControl: boolean;

socket

presets/classic.ts

Socket instance

ts
socket: S;

addControl

presets/classic.ts

Add control to the input port

ts
addControl(control: Control): void
ParameterTypeDescription
controlControlControl instance

Returns void

removeControl

presets/classic.ts

Remove control from the input port

ts
removeControl(): void

Returns void

Control

presets/classic.ts

General control class

ts
class Control

Extended by InputControl

id

presets/classic.ts

Control id, unique string generated by getUID function

ts
id: string;

index

presets/classic.ts

Control index, used for sorting controls. Default is 0

ts
index: number;

Output

presets/classic.ts

The output port class

ts
class Output<S extends Socket>
ParameterExtendsDescription
SSocket

Extends Port

constructor

presets/classic.ts

ts
constructor(socket: S, label: string, multipleConnections: boolean): Output<S>
ParameterTypeDescription
socketSSocket instance
labelstringLabel of the output port
multipleConnectionsbooleanWhether the output port can have multiple connections. Default is true

Returns Output<S>

id

presets/classic.ts

Port id, unique string generated by getUID function

ts
id: string;

index

presets/classic.ts

Port index, used for sorting ports. Default is 0

ts
index: number;

label

presets/classic.ts

Label of the port

ts
label: string;

multipleConnections

presets/classic.ts

Whether the output port can have multiple connections

ts
multipleConnections: boolean;

socket

presets/classic.ts

Socket instance

ts
socket: S;

InputControl

presets/classic.ts

The input control class

ts
class InputControl<T extends "text" | "number", N extends unknown>
ParameterExtendsDescription
T`"text""number"`
Nunknown

Extends Control

Examples

ts
new InputControl('text', { readonly: true, initial: 'hello' })

constructor

presets/classic.ts

ts
constructor(type: T, options: InputControlOptions<N>): InputControl<T, N>
ParameterTypeDescription
typeTType of the control: text or number
optionsInputControlOptions<N>Control options

Returns InputControl<T, N>

id

presets/classic.ts

Control id, unique string generated by getUID function

ts
id: string;

index

presets/classic.ts

Control index, used for sorting controls. Default is 0

ts
index: number;

options

presets/classic.ts

Control options

ts
options: InputControlOptions<N>;

type

presets/classic.ts

Type of the control: text or number

ts
type: T;

setValue

presets/classic.ts

Set control value

ts
setValue(value: N): void
ParameterTypeDescription
valueNValue to set

Returns void

Port

presets/classic.ts

General port class

ts
class Port<S extends Socket>
ParameterExtendsDescription
SSocket

Extended by Input, Output

constructor

presets/classic.ts

ts
constructor(socket: S, label: string, multipleConnections: boolean): Port<S>
ParameterTypeDescription
socketSSocket instance
labelstringLabel of the port
multipleConnectionsbooleanWhether the output port can have multiple connections

Returns Port<S>

id

presets/classic.ts

Port id, unique string generated by getUID function

ts
id: string;

index

presets/classic.ts

Port index, used for sorting ports. Default is 0

ts
index: number;

label

presets/classic.ts

Label of the port

ts
label: string;

multipleConnections

presets/classic.ts

Whether the output port can have multiple connections

ts
multipleConnections: boolean;

socket

presets/classic.ts

Socket instance

ts
socket: S;

Scope

scope.ts

Base class for all plugins and the core. Provides a signals mechanism to modify the data

ts
class Scope<Produces extends unknown, Parents extends unknown[]>
ParameterExtendsDescription
Producesunknown
Parentsunknown[]

Extended by NodeEditor

Signal

scope.ts

A signal is a middleware chain that can be used to modify the data

ts
class Signal<T extends unknown>
ParameterExtendsDescription
TunknownThe data type

BaseSchemes

types.ts

The base schemes

ts
type BaseSchemes = GetSchemes<NodeBase, ConnectionBase>;

ConnectionBase

types.ts

The base connection type

ts
type ConnectionBase = { id: ConnectionId; source: NodeId; target: NodeId };

Implemented by Connection

ConnectionId

types.ts

Connection id type

ts
type ConnectionId = string;

GetSchemes

types.ts

Get the schemes

ts
type GetSchemes<
  NodeData extends NodeBase,
  ConnectionData extends ConnectionBase,
> = { Connection: ConnectionData; Node: NodeData };
ParameterExtendsDescription
NodeDataNodeBase
ConnectionDataConnectionBase

Examples

ts
GetSchemes<Node & { myProp: number }, Connection>

NestedScope

scope.ts

Validate the Scope signals and replace the parameter type with an error message if they are not assignable

ts
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";
ParameterExtendsDescription
SScope<any, any[]>
Currentany[]

NodeBase

types.ts

The base node type

ts
type NodeBase = { id: NodeId };

Implemented by Node

NodeId

types.ts

Node id type

ts
type NodeId = string;

Pipe

scope.ts

ts
type Pipe<T extends unknown> = (
  data: T,
) => Promise<undefined | T> | undefined | T;
ParameterExtendsDescription
TunknownThe data type

getUID

utils.ts

ts
getUID(): string

Returns string A unique id