@selenite/graph-editor
Version:
A graph editor for visual programming, based on rete and svelte.
180 lines (179 loc) • 8.7 kB
TypeScript
import { AreaExtensions, AreaPlugin } from 'rete-area-plugin';
import type { NodeEditor, NodeEditorSaveData } from './NodeEditor.svelte';
import type { AreaExtra } from '../area/AreaExtra';
import type { Schemes } from '../schemes';
import { ControlFlowEngine, DataflowEngine } from 'rete-engine';
import { Connection, Node, type NodeSaveData } from '../nodes/Node.svelte';
import { type Readable, type Writable } from 'svelte/store';
import { PythonDataflowEngine } from '../engine/PythonDataflowEngine';
import type { MakutuClassRepository } from '../../backend-interaction/types';
import type { AutoArrangePlugin } from 'rete-auto-arrange-plugin';
import type { CommentPlugin } from '../plugins/CommentPlugin';
import type { HistoryPlugin } from '../plugins/history';
import { type ConnectionPathType } from '../connection-path';
import type { NotificationsManager } from '../plugins/notifications';
import { Rect, XmlSchema, type SaveData } from '@selenite/commons';
import { Modal } from '@selenite/commons';
import type { BaseComponent, ComponentParams, ComponentSupportInterface } from '../components';
import { NodeLayout } from './NodeLayout';
import { NodeSelection as NodeSelector, type SelectOptions, type SelectorEntity } from './NodeSelection.svelte';
import { NodeStorage } from '../storage';
import { CodeIntegration } from './CodeIntegration.svelte';
import type { ConnectionPlugin } from '../setup/ConnectionSetup';
import { SvelteMap, SvelteSet } from 'svelte/reactivity';
import { NodeSearch } from './NodeSearch.svelte';
type WithoutFactory<T> = Omit<T, 'factory'>;
export declare class NodeFactory implements ComponentSupportInterface {
#private;
components: BaseComponent[];
addComponentByClass<P extends Record<string, unknown>, C extends BaseComponent>(componentClass: new (params: P) => C, params: Omit<P, keyof ComponentParams>): C;
minimapEnabled: boolean;
notifications: NotificationsManager;
readonly connectionPathType: Writable<ConnectionPathType>;
surfaceRect: Rect;
lastSelectedNode: 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>> | undefined;
editor: NodeEditor;
get 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>>>;
modalStore: Readable<Modal>;
private state;
id: string;
useState<T = unknown>(id: string, key: string, value?: T): {
value: T;
get: () => T;
set: (value: T) => void;
};
getState<T>(id: string, key: string, initial?: T): T;
setState(id: string, key: string, value: unknown): void;
lastAddedNode?: Node;
addNode<T extends Node, Params = Record<string, unknown>>(nodeClass: new (params: Params) => T, params?: WithoutFactory<Params>): Promise<T>;
addNodes(nodes: (Node | SaveData<Node>)[]): Promise<void>;
getNodes(): Node[];
get storage(): NodeStorage;
readonly pythonDataflowEngine: PythonDataflowEngine<Schemes>;
loadNode(nodeSaveData: NodeSaveData): Promise<Node>;
effetRootCleanup: (() => void) | undefined;
private cleanup;
destroyArea(): void;
destroy(): void;
/**
* Moves the view to the center of the nodes, with a zoom such that all nodes are visible.
* @param nodes - Nodes to center the view on. If not provided, all nodes are used.
*/
centerView(nodes?: Node[]): Promise<void> | undefined;
openGraphForm(defaultName?: string): Promise<void>;
/**
* Loads a graph from a save.
* @param editorSaveData - Save data to load.
*/
loadGraph(editorSaveData: NodeEditorSaveData): Promise<void>;
get area(): AreaPlugin<Schemes, AreaExtra> | undefined;
transform: {
zoom: number;
};
set area(area: AreaPlugin<Schemes, AreaExtra> | undefined);
readonly makutuClasses?: MakutuClassRepository;
readonly dataflowEngine: DataflowEngine<Schemes>;
private readonly controlflowEngine;
selector: NodeSelector;
get selection(): NodeSelector;
search: NodeSearch;
arrange?: AutoArrangePlugin<Schemes>;
history: HistoryPlugin<Schemes> | undefined;
connectionPlugin?: ConnectionPlugin;
comment: CommentPlugin<Schemes, AreaExtra> | undefined;
get xmlSchemas(): SvelteMap<string, XmlSchema>;
reactivateDataflowTimeout: NodeJS.Timeout | null;
/**
* Nodes in the editor.
*/
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>>[];
/**
* Connections in the editor.
*/
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>>>[];
/**
* Executes callback without running dataflow engines.
*
* It is useful to execute multiple operations without unnecessarily running dataflow engines.
* @param callback Callback to execute
*/
bulkOperation(callback: () => void | Promise<void>): Promise<void>;
/**
* Removes all nodes and connections from the editor.
*/
clear(): Promise<void>;
layout: NodeLayout;
codeIntegration: CodeIntegration;
constructor(params: {
editor: NodeEditor;
area?: AreaPlugin<Schemes, AreaExtra>;
makutuClasses?: MakutuClassRepository;
arrange?: AutoArrangePlugin<Schemes>;
history?: HistoryPlugin<Schemes>;
comment?: CommentPlugin<Schemes, AreaExtra>;
accumulating?: ReturnType<typeof AreaExtensions.accumulateOnCtrl>;
xmlSchemas?: Record<string, XmlSchema | undefined>;
});
commentSelectedNodes(params?: {
text?: string;
}): void;
/** Delete all selected elements */
deleteSelectedElements(): Promise<void>;
/**
* Removes a node from the editor, as well as its connections.
* @param target node or node id
*/
removeNode(target: string | Node): Promise<void>;
enable(): void;
disable(): void;
getNode(id: string): Node | undefined;
create<T extends Node>(type: new () => T): T;
getEditor(): NodeEditor;
getControlFlowEngine(): ControlFlowEngine<Schemes>;
getArea(): AreaPlugin<Schemes, AreaExtra> | undefined;
resetSuccessors(node: Node): void;
downloadGraph(): void;
loadFromFile(): void;
lastSearchNodeIndex: number;
/**
* Finds a node whose label or name matches the query.
* Repeated calls will cycle through the nodes.
* @param query
* @returns found node or undefined
*/
findNode(query: string): Node | undefined;
focusNode(node?: Node): void;
focusNodes(nodes?: Node[], options?: AreaExtensions.ZoomAt): void;
select(entity: SelectorEntity, options?: SelectOptions): void;
selectConnection(id: string): void;
selectAll(): void;
unselectAll(): void;
dataflowCache: SvelteMap<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>>, Record<string, unknown>>;
runDataflowEngines(): Promise<void>;
resetDataflow(node?: Node): Promise<void>;
}
export {};