From a9539ff691306c08fd9d28457c0fb813a6d527f1 Mon Sep 17 00:00:00 2001 From: Ni55aN Date: Wed, 19 Jul 2023 14:10:48 +0300 Subject: [PATCH] docs: classic preset docs --- src/presets/classic.ts | 109 +++++++++++++++++++++++++++++++++++++++-- 1 file changed, 106 insertions(+), 3 deletions(-) diff --git a/src/presets/classic.ts b/src/presets/classic.ts index d970a41..acfa1d5 100644 --- a/src/presets/classic.ts +++ b/src/presets/classic.ts @@ -11,8 +11,13 @@ type PortId = string /** * The socket class + * @priority 7 */ export class Socket { + /** + * @constructor + * @param name Name of the socket + */ constructor(public name: string) { } @@ -22,9 +27,21 @@ export class Socket { * General port class */ export class Port { + /** + * Port id, unique string generated by `getUID` function + */ id: PortId + /** + * Port index, used for sorting ports. Default is `0` + */ index?: number + /** + * @constructor + * @param socket Socket instance + * @param label Label of the port + * @param multipleConnections Whether the output port can have multiple connections + */ constructor(public socket: S, public label?: string, public multipleConnections?: boolean) { this.id = getUID() } @@ -32,16 +49,40 @@ export class Port { /** * The input port class + * @priority 6 */ export class Input extends Port { + /** + * Control instance + */ control: Control | null = null + /** + * Whether the control is visible. Can be managed dynamically by extensions. Default is `true` + */ showControl = true + /** + * @constructor + * @param socket Socket instance + * @param label Label of the input port + * @param multipleConnections Whether the output port can have multiple connections. Default is `false` + */ + constructor(public socket: S, public label?: string, public multipleConnections?: boolean) { + super(socket, label, multipleConnections) + } + + /** + * Add control to the input port + * @param control Control instance + */ addControl(control: Control) { if (this.control) throw new Error('control already added for this input') this.control = control } + /** + * Remove control from the input port + */ removeControl() { this.control = null } @@ -49,8 +90,15 @@ export class Input extends Port { /** * The output port class + * @priority 5 */ export class Output extends Port { + /** + * @constructor + * @param socket Socket instance + * @param label Label of the output port + * @param multipleConnections Whether the output port can have multiple connections. Default is `true` + */ constructor(socket: S, label?: string, multipleConnections?: boolean) { super(socket, label, multipleConnections !== false) } @@ -58,9 +106,16 @@ export class Output extends Port { /** * General control class + * @priority 5 */ export class Control { + /** + * Control id, unique string generated by `getUID` function + */ id: string + /** + * Control index, used for sorting controls. Default is `0` + */ index?: number constructor() { @@ -68,9 +123,15 @@ export class Control { } } +/** + * Input control options + */ type InputControlOptions = { + /** Whether the control is readonly. Default is `false` */ readonly?: boolean, + /** Initial value of the control */ initial?: N, + /** Callback function that is called when the control value changes */ change?: (value: N) => void } /** @@ -81,6 +142,11 @@ export class InputControl) { super() this.id = getUID() @@ -89,6 +155,10 @@ export class InputControl implements NodeBase { + /** + * Node id, unique string generated by `getUID` function + */ id: NodeBase['id'] + /** + * Node inputs + */ inputs: { [key in keyof Inputs]?: Input> } = {} + /** + * Node outputs + */ outputs: { [key in keyof Outputs]?: Output> } = {} + /** + * Node controls + */ controls: Controls = {} as Controls + /** + * Whether the node is selected. Default is `false` + */ selected?: boolean constructor(public label: string) { @@ -160,14 +243,34 @@ export class Node< } } +/** + * The connection class + * @priority 9 + */ export class Connection< Source extends Node, Target extends Node > implements ConnectionBase { + /** + * Connection id, unique string generated by `getUID` function + */ id: ConnectionBase['id'] + /** + * Source node id + */ source: NodeBase['id'] + /** + * Target node id + */ target: NodeBase['id'] + /** + * @constructor + * @param source Source node instance + * @param sourceOutput Source node output key + * @param target Target node instance + * @param targetInput Target node input key + */ constructor( source: Source, public sourceOutput: keyof Source['outputs'],