UNPKG

@ndbx/runtime

Version:

The `@ndbx/runtime` package provides a runtime environment to embed NodeBox visualizations directly into React applications. NodeBox is a powerful tool for creating interactive and generative visualizations, and this runtime allows you to integrate those

108 lines (107 loc) 3.37 kB
import { Item, Port as IPort, PortType, Parameter as IParameter, ParameterType, ParameterValue, Choice, PortValue, LiteralValue, WidgetType, ContextGlobals, Section } from "./types"; import Context from "./context"; type ParameterChoices = string[] | string[][]; export declare function parseChoices(choices: string[] | string[][]): Choice[]; export declare function defaultValueForType(type: ParameterType): LiteralValue; export declare function defaultWidgetForType(type: ParameterType): WidgetType; export declare function createExpressionContext(_cx: Context, globals: ContextGlobals): ContextGlobals; declare class Parameter implements IParameter { node: RuntimeNode; type: ParameterType; widget: WidgetType; name: string; label: string; section?: string; defaultValue: LiteralValue; choices?: Choice[]; min: number; max: number; step: number; constructor(node: RuntimeNode, name: string, type: ParameterType, defaultValue?: LiteralValue | undefined, choices?: Choice[]); get value(): unknown; get fn(): (d: Record<string, any>) => unknown; get timeDependent(): boolean; } declare class Port implements IPort { node: RuntimeNode; type: PortType; name: string; _value: PortValue; constructor(node: RuntimeNode, name: string, type: PortType); get value(): PortValue; set(value: PortValue): void; } export default class RuntimeNode { cx: Context; nodeId: string; nodeFn: Item; inputPorts: Port[]; outputPorts: Port[]; parameters: Parameter[]; values: Record<string, ParameterValue>; _timeDependent: boolean; dirty: boolean; globals: ContextGlobals | null; sections: Section[]; _currentSection?: string; message?: string; constructor(cx: Context, nodeId: string, nodeFn: Item); get timeDependent(): boolean; set timeDependent(value: boolean); numberIn({ name, value, min, max, step, }: { name: string; value: LiteralValue | undefined; min?: number; max?: number; step?: number; }): Parameter; stringIn({ name, value, widget, choices, }: { name: string; value: LiteralValue | undefined; widget?: WidgetType; choices?: ParameterChoices; }): Parameter; booleanIn({ name, value }: { name: string; value: LiteralValue | undefined; }): Parameter; colorIn({ name, value }: { name: string; value: LiteralValue | undefined; }): Parameter; choiceIn({ name, value, choices }: { name: string; value: LiteralValue | undefined; choices: Choice[]; }): Parameter; fileIn({ name, value }: { name: string; value: LiteralValue | undefined; }): Parameter; tableIn({ name }: { name: string; }): Port; shapeIn({ name }: { name: string; }): Port; specIn({ name }: { name: string; }): Port; tableOut({ name }: { name: string; }): Port; shapeOut({ name }: { name: string; }): Port; specOut({ name }: { name: string; }): Port; pushSection({ name, collapsed }: { name: string; collapsed: boolean; }): void; popSection(): void; onRender(_cx: Context): void; onChange(_cx: Context, _parameterName: string): void; } export {};