UNPKG

@selenite/graph-editor

Version:

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

103 lines (102 loc) 4.32 kB
import type { SocketType } from '../plugins/typed-sockets'; import { ClassicPreset } from 'rete'; import type { SocketDatastructure, SocketValueWithDatastructure } from '../socket/Socket.svelte'; import type { HTMLInputAttributes } from 'svelte/elements'; export type ControlParams = { placeInHeader: boolean; }; export declare function applyParams<T extends object>(target: T, constructor: new () => T, params: Record<string, unknown>): void; /** * A control represents widgets the user can interact with. */ export declare class Control extends ClassicPreset.Control { placeInHeader: boolean; constructor(params?: Partial<ControlParams>); } /** * Supported types of input control. */ export declare const inputControlTypes: readonly ["text", "number", "checkbox", "textarea", "integer", "vector", "remote-file", "select", "group-name-ref"]; /** * Supported types of input control. */ export type InputControlType = (typeof inputControlTypes)[number]; export declare function isInputControlType(type: unknown): type is InputControlType; /** * Default values for each type of input control. */ export declare const defaultInputControlValues: { text: string; number: number; checkbox: boolean; textarea: string; integer: number; vector: { x: number; y: number; z: number; }; 'remote-file': string; select: string; 'group-name-ref': string; }; export declare const inputControlSocketType: Record<InputControlType, SocketType>; export declare const socketToControl: { readonly path: "remote-file"; readonly string: "text"; readonly integer: "integer"; readonly number: "number"; readonly boolean: "checkbox"; readonly vector: "vector"; readonly any: "text"; readonly groupNameRef: "group-name-ref"; }; export declare const socketTypesWithControl: SocketType[]; export type ControlOfSocket<S extends SocketType> = S extends keyof typeof socketToControl ? (typeof socketToControl)[S] : 'text'; export type SocketValueType<S extends SocketType> = S extends 'any' ? unknown : ControlOfSocket<S> extends InputControlType ? InputControlValueType<ControlOfSocket<S>> : unknown; export declare function assignControl(socketType: SocketType, default_?: InputControlType): InputControlType | undefined; /** * Type utility to get the value type of an input control based on its type. */ export type InputControlValueType<T extends InputControlType> = (typeof defaultInputControlValues)[T]; export type InputControlParams<T extends InputControlType, D extends SocketDatastructure = SocketDatastructure> = { type: T; datastructure: D; options?: string[]; initial?: SocketValueWithDatastructure<InputControlValueType<T>, D>; readonly?: boolean; props?: HTMLInputAttributes; onChange?: (value: InputControlValueType<T>) => void; label?: string; changeType?: (type: SocketType) => void; canChangeType?: boolean; socketType: SocketType; }; export declare function getDatastructure<T extends InputControlType, D extends SocketDatastructure>({ datastructure, type, values }: { datastructure: D; type: T; values?: InputControlValueType<T>[]; }): SocketValueWithDatastructure<InputControlValueType<T>, D>; export declare function getDatastructureValues<T, D extends SocketDatastructure>({ datastructure, data }: { datastructure: D; data: SocketValueWithDatastructure<T, D>; }): T[]; export declare class InputControl<T extends InputControlType = InputControlType, D extends SocketDatastructure = SocketDatastructure> extends Control { #private; readonly: boolean; onChange?: InputControlParams<T>['onChange']; label: string; type: "number" | "integer" | "vector" | "remote-file" | "text" | "checkbox" | "group-name-ref" | "textarea" | "select"; changeType?: (type: SocketType) => void; canChangeType: boolean; props: HTMLInputAttributes; options: string[] | undefined; autoType: boolean; constructor(params: InputControlParams<T, D>); get value(): SocketValueWithDatastructure<InputControlValueType<T>, D>; set value(v: SocketValueWithDatastructure<InputControlValueType<T>, D>); get socketType(): SocketType; set socketType(t: SocketType); get datastructure(): D; set datastructure(d: D); }