UNPKG

@selenite/graph-editor

Version:

A graph editor for visual programming, based on rete and svelte.

164 lines (163 loc) 7.6 kB
import { NodeEditor as BaseNodeEditor } from 'rete'; import { Connection, Node } from '../nodes'; import type { Variable } from '../variables'; import { type Readable } from 'svelte/store'; import { NodeFactory } from './NodeFactory.svelte'; import { SvelteMap, SvelteSet } from 'svelte/reactivity'; import { type SaveData } from '@selenite/commons'; import type { Schemes } from '../schemes'; export type CommentSaveData = { id: string; text: string; links: string[]; }; export type NodeEditorSaveData = SaveData<NodeEditor>; /** * A graph editor for visual programming. * * A low level class that manages nodes and connections. */ export declare class NodeEditor extends BaseNodeEditor<Schemes> { #private; factory?: NodeFactory; get area(): import("rete-area-plugin").AreaPlugin<Schemes, import("..").AreaExtra> | undefined; variables: Record<string, Variable>; previewedNodes: SvelteSet<Node<Record<string, import("../socket").Socket<import("../plugins/typed-sockets").SocketType, "scalar" | "array">>, { [x: string]: import("../socket").Socket<import("../plugins/typed-sockets").SocketType, "scalar" | "array">; }, { [x: string]: import("../control").Control; }, Record<string, unknown>, Record<string, unknown>>>; setName(name: string): void; readonly name = "Node Editor"; set graphId(id: string | undefined); get graphId(): string; get graphName(): string; set graphName(n: string); nameStore: Readable<string>; onChangeNameListeners: ((name: string) => void)[]; addOnChangeNameListener(listener: (name: string) => void): void; id: string; nodesMap: SvelteMap<string, Node<Record<string, import("../socket").Socket<import("../plugins/typed-sockets").SocketType, "scalar" | "array">>, { [x: string]: import("../socket").Socket<import("../plugins/typed-sockets").SocketType, "scalar" | "array">; }, { [x: string]: import("../control").Control; }, Record<string, unknown>, Record<string, unknown>>>; connectionsMap: SvelteMap<string, Connection<Node<Record<string, import("../socket").Socket<import("../plugins/typed-sockets").SocketType, "scalar" | "array">>, { [x: string]: import("../socket").Socket<import("../plugins/typed-sockets").SocketType, "scalar" | "array">; }, { [x: string]: import("../control").Control; }, Record<string, unknown>, Record<string, unknown>>, Node<Record<string, import("../socket").Socket<import("../plugins/typed-sockets").SocketType, "scalar" | "array">>, { [x: string]: import("../socket").Socket<import("../plugins/typed-sockets").SocketType, "scalar" | "array">; }, { [x: string]: import("../control").Control; }, Record<string, unknown>, Record<string, unknown>>>>; get nodes(): Node<Record<string, import("../socket").Socket<import("../plugins/typed-sockets").SocketType, "scalar" | "array">>, { [x: string]: import("../socket").Socket<import("../plugins/typed-sockets").SocketType, "scalar" | "array">; }, { [x: string]: import("../control").Control; }, Record<string, unknown>, Record<string, unknown>>[]; selectedInputs: { node: Node<Record<string, import("../socket").Socket<import("../plugins/typed-sockets").SocketType, "scalar" | "array">>, { [x: string]: import("../socket").Socket<import("../plugins/typed-sockets").SocketType, "scalar" | "array">; }, { [x: string]: import("../control").Control; }, Record<string, unknown>, Record<string, unknown>>; selected: [string, import("../socket").Input<import("../socket").Socket<import("../plugins/typed-sockets").SocketType, "scalar" | "array">>][]; }[]; selectedOutputs: { node: Node<Record<string, import("../socket").Socket<import("../plugins/typed-sockets").SocketType, "scalar" | "array">>, { [x: string]: import("../socket").Socket<import("../plugins/typed-sockets").SocketType, "scalar" | "array">; }, { [x: string]: import("../control").Control; }, Record<string, unknown>, Record<string, unknown>>; selected: [string, import("../socket").Output<import("../socket").Socket<import("../plugins/typed-sockets").SocketType, "scalar" | "array">>][]; }[]; get connections(): Connection<Node<Record<string, import("../socket").Socket<import("../plugins/typed-sockets").SocketType, "scalar" | "array">>, { [x: string]: import("../socket").Socket<import("../plugins/typed-sockets").SocketType, "scalar" | "array">; }, { [x: string]: import("../control").Control; }, Record<string, unknown>, Record<string, unknown>>, Node<Record<string, import("../socket").Socket<import("../plugins/typed-sockets").SocketType, "scalar" | "array">>, { [x: string]: import("../socket").Socket<import("../plugins/typed-sockets").SocketType, "scalar" | "array">; }, { [x: string]: import("../control").Control; }, Record<string, unknown>, Record<string, unknown>>>[]; constructor({ id }?: { id?: string; }); /** * Gets a node by id. * @param id - id of the node * @returns The node or undefined */ getNode(id: string): Node | undefined; /** * Gets all nodes. * @returns An array of all nodes in the editor */ getNodes(): Node[]; /** * Gets a connection by id. * @param id - id of the connection * @returns The connection or undefined */ getConnection(id: string): Connection | undefined; /** * Gets all connections. * @returns An array of all connections in the editor */ getConnections(): Connection[]; /** * Returns whether the editor has a node with the given id. * @param id - id of the node to check for */ hasNode(id: string): boolean; /** * Returns whether the editor has a node. * @param node - node to check for */ hasNode(node: Node): boolean; /** * Returns whether the editor has a connection with the given id. * @param id - id of the connection to check for */ hasConnection(id: string): boolean; /** * Returns whether the editor has a connection. * @param connection - connection to check for */ hasConnection(connection: Connection): boolean; /** * Adds a node to the editor. * @param node - node to add * @returns Whether the node was added */ addNode(node: Node): Promise<boolean>; /** * Adds a connection to the editor. * @param conn - connection to add * @returns Whether the connection was added */ addConnection(conn: Connection): Promise<boolean>; addExecConnection(source: Node, target: Node): Promise<boolean>; addNewConnection(source: Node | string, sourceOutput: string, target: Node | string, targetInput: string): Promise<Connection | undefined>; removeNode(id: string): Promise<boolean>; removeNode(node: Node): Promise<boolean>; removeConnection(id: string): Promise<boolean>; removeConnection(conn: Connection): Promise<boolean>; clearing: boolean; clear(): Promise<boolean>; toJSON(): { editorName: string; graphName: string; id: string | undefined; variables: Record<string, Variable> | Variable[]; previewedNodes: string[]; nodes: import("../nodes").NodeSaveData[]; connections: import("../nodes").ConnectionSaveData[]; comments: { id: string; text: string; links: string[]; }[]; }; }