import * as react from 'react'; import react__default, { JSXElementConstructor, CSSProperties, ComponentType, ReactNode, ReactElement } from 'react'; import { Node, Edge, NodeChange, EdgeChange, ReactFlowProps, Position, HandleType } from '@xyflow/react'; import * as zustand_traditional from 'zustand/traditional'; import * as zustand from 'zustand'; type InputSlots = { Handle?: JSXElementConstructor; }; type BaseInputProps = { onFocus: () => void; onBlur: () => void; slots?: InputSlots; }; interface NodeFocusState { node: Node; isFocused: boolean; onFocus: () => void; onBlur: () => void; } interface NodeBodySlots { bodyTop?: react__default.ComponentType; bodyBottom?: react__default.ComponentType; inputs: react__default.JSX.Element[]; outputs: react__default.JSX.Element[]; } interface NodeBodyProps extends NodeFocusState { slots: NodeBodySlots; isFocused: boolean; onFocus: () => void; onBlur: () => void; } interface IGraphConfig { /** * Keybindings for the graph editor */ keybindings?: KeyBindings; /** * Configures the different types of values supported by the node inputs and outputs */ valueTypes: ValueTypes; /** * Groups of nodes that can be used to organize the node palette, allowing styling * and configuring the colors of the nodes as a group. */ nodeKinds: NodeKindTypes; /** * The nodes types that are registered and can be created in the graph */ nodeTypes: NodeTypes; } type KeyBindings = { save: string[]; copy: string[]; paste: string[]; delete: string[]; }; type ValueTypes = { [key: string]: ValueTypeConfig; }; type NodeKindTypes = { [name: string]: NodeKindConfig; }; type NodeTypes = { [key: string]: NodeConfig; }; /** * The different types of values that can be used for node inputs and outputs. */ interface ValueTypeConfigBase { name: string; color: string; /** * The shape to use for the input/output handle attached to the node. */ shape?: 'diamond' | 'diamondDot' | 'circle'; /** * Indicates that this is a custom input element and should not be rendered using * the config-based rendering system */ custom?: boolean; } interface ValueTypeConfigOptions extends ValueTypeConfigBase { inputEditor: 'options' | 'buttonGroup'; options: Option[]; defaultValue: Option['value']; } interface ValueTypeConfigText extends ValueTypeConfigBase { inputEditor: 'text' | 'date' | 'time' | 'datetime-local' | 'month' | 'week' | 'url' | 'email' | 'tel' | 'password' | 'search' | 'color' | 'email'; defaultValue: string; } interface ValueTypeConfigNumber extends ValueTypeConfigBase { inputEditor: 'number' | 'range' | 'decimal'; defaultValue: number; } interface ValueTypeConfigCheckbox extends ValueTypeConfigBase { inputEditor: 'checkbox'; defaultValue: boolean; } interface ValueTypeConfigCustom extends ValueTypeConfigBase { inputEditor: string; } interface ValueTypeConfigNoInput extends ValueTypeConfigBase { inputEditor: null | undefined; } type ValueTypeConfig = ValueTypeConfigOptions | ValueTypeConfigText | ValueTypeConfigNumber | ValueTypeConfigCheckbox | ValueTypeConfigNoInput | ValueTypeConfigCustom; interface Option { name: string; value: string; } interface NodeKindConfig { name: string; color: string; } interface NodeConfig { kind: keyof IGraphConfig['nodeKinds']; name: string; inputs?: NodeInputConfig[]; outputs?: NodeOutputConfig[]; /** * These styles are applied to the node's div element. This can be used to * configure node widths, background, etc. */ style?: CSSProperties; /** * Node is a custom node and should not be rendered using the config-based * rendering system */ custom?: boolean; } interface NodeInputConfig { name: string; id: string; valueType: Extract; isArray?: boolean; defaultValue?: any; isConstant?: boolean; /** * The group that this input belongs to. When specified, this input and * any other inputs with this group name will be rendered under a collapsable * accordion. */ inputGroup?: string; } interface NodeOutputConfig { name: string; id: string; valueType: string; isArray?: boolean; } type WithType = T & { type: K; }; type InputProps = BaseInputProps & NodeInputConfig & ValueTypeConfig; interface CustomNodeProps extends NodeFocusState { node: Node; slots: NodeBodySlots; } declare class GraphConfig { readonly valueTypes: ValueTypes; readonly keybindings: KeyBindings; readonly nodeKinds: { [key: string]: NodeKindConfig; }; private readonly nodeTypes; private customNodes; private inputs; constructor(props?: Partial); validate(): GraphConfig; registerCustomNode(name: string, type: string, kind: string, node: JSXElementConstructor, inputs: NodeInputConfig[], outputs: NodeOutputConfig[]): void; registerInput(type: string, input: JSXElementConstructor, valueType: Omit): void; customNode(type: string): JSXElementConstructor; /** * Accepts a value type and returns the input component that should be used to * render the input for that value type. * @param valueType */ getInputComponent(valueType: string): JSXElementConstructor | null; nodeConfigs(): WithType[]; getNodeConfig(type: string): NodeConfig; nodeConfigsByKind(kind: string): WithType[]; nodeKindConfigs(): WithType[]; getRegisteredNodeTypes(): { type: string; name: string; nodes: { type: string; name: string; }[]; }[]; getNodeKindConfig(nodeType: T): NodeKindConfig; valueType(type: T): ValueTypeConfig; getInputConfig(input: NodeInputConfig): NodeInputConfig & ValueTypeConfig; getOutputConfig(output: NodeOutputConfig): NodeOutputConfig & ValueTypeConfig; getNodeComponents(buildNode: (config: GraphConfig, node: NodeConfig, type: string) => JSXElementConstructor): Record>; } declare abstract class LayoutEngine { abstract name(): string; abstract apply(nodes: Node[], edges: Edge[]): Node[]; constructor(); } declare namespace Graph { type Node = Omit & { data: NodeData; }; type NodeData = Data & { internal: NodeInternals; }; type NodeInputOutput = { id: string; name: string; valueType: string; }; type NodeInternals = { inputs: NodeInputOutput[]; outputs: NodeInputOutput[]; }; type Edge = Omit & { data?: { targetHandle: { name: string; valueType: string; }; }; }; } type NodeHeaderProps = { defaultTitle: string; color: string; collapsed?: boolean; toggleCollapsed?: () => void; }; /** * Location in the node's `data` object where the header value is stored. */ declare const HEADER_FIELD_NAME = "__header"; declare const NodeHeader: react.MemoExoticComponent<({ defaultTitle, color, collapsed, toggleCollapsed }: NodeHeaderProps) => JSX.Element>; type GraphSlots = { header: ComponentType; body: ComponentType; wrapper: ComponentType; bodyTop?: ComponentType; bodyBottom?: ComponentType; }; type GraphStore = GraphStoreActions & { config: GraphConfig; nodes: Graph.Node[]; edges: Graph.Edge[]; slots: GraphSlots; }; type SerializeFunc = () => string; type DeserializeFunc = (serialized: string) => void; type GraphStoreActions = { onNodesChange: (changes: NodeChange[]) => void; onEdgesChange: (changes: EdgeChange[]) => void; addNode: (node: Node | Graph.Node) => void; removeNode: (node: string | Node | Graph.Node) => void; updateNode: (node: Partial & { id: string; }) => void; updateNodeData: (nodeId: string, data: Record) => void; getNode: (nodeId: string) => Graph.Node | undefined; addEdge: (edge: Edge | Graph.Edge) => void; removeEdge: (edge: string | Edge | Graph.Edge) => void; updateEdge: (edge: Partial & { id: string; }) => void; getEdge: (edgeId: string) => Graph.Edge | undefined; serialize: SerializeFunc; deserialize: DeserializeFunc; }; declare const NodeGraphEditor: react.ForwardRefExoticComponent & { onSave?: ((data: any) => void) | undefined; config: GraphConfig; slots?: Partial | undefined; } & react.RefAttributes>; type FlowProps = ReactFlowProps & { backgroundStyles?: CSSProperties; /** * The default layout engine to use when nodes are provided without positions. */ layoutEngine?: LayoutEngine; }; type NodeGraphHandle = { layout: (engine?: LayoutEngine) => void; serialize: SerializeFunc; deserialize: DeserializeFunc; addNode: (node: Node) => void; removeNode: (node: Node) => void; updateNode: (node: Partial & { id: string; }) => void; updateNodeData: (nodeId: string, data: Record) => void; getNode: (nodeId: string) => Node | undefined; addEdge: (edge: Edge) => void; removeEdge: (edge: Edge) => void; updateEdge: (edge: Partial & { id: string; }) => void; getEdge: (edgeId: string) => Edge | undefined; }; declare function useBuildGraphConfig(config: IGraphConfig, extensions?: (config: GraphConfig) => void): GraphConfig; declare function useNodeFieldValue(field: string, defaultValue?: T): [T, (value: T) => void]; declare function useNodesEdges(nodeId: string): Edge[]; declare function useNodeCollapsed(): [boolean, () => void]; type HandleProps = Pick & Pick & { style?: CSSProperties; position: Position; handleType: HandleType; }; declare const Handle: react.MemoExoticComponent<({ style, ...props }: HandleProps) => JSX.Element>; type NodeContainerProps = { node: Node; draggable?: boolean; styles?: CSSProperties; children?: ReactElement | ReactElement[]; }; declare function NodeContainer({ draggable, node, styles, children, }: NodeContainerProps): globalThis.JSX.Element; type NodeInputFieldProps = BaseInputProps & Pick & React.InputHTMLAttributes; declare const NodeInputField: ({ onFocus, onBlur, type, isConstant, slots, id, defaultValue, ...props }: NodeInputFieldProps) => JSX.Element; type NodeCheckboxFieldProps = BaseInputProps & NodeInputConfig & ValueTypeConfig; declare const NodeCheckboxField: react.MemoExoticComponent<({ isConstant, slots, ...props }: NodeCheckboxFieldProps) => JSX.Element>; type NodeSelectFieldProps = BaseInputProps & NodeInputConfig & ValueTypeConfigOptions; declare const NodeSelectField: react.MemoExoticComponent<({ options, isConstant, slots, ...props }: NodeSelectFieldProps) => JSX.Element>; type NodeDenseLinkedFieldProps = NodeInputConfig & Pick; declare const NodeDenseLinkedField: react.MemoExoticComponent<(props: NodeDenseLinkedFieldProps) => JSX.Element>; type NodeLinkedFieldProps = NodeInputConfig & Pick; declare const NodeLinkedField: react.MemoExoticComponent<(props: NodeLinkedFieldProps) => JSX.Element>; type NodeOutputFieldProps = NodeOutputConfig; declare const NodeOutputField: react.MemoExoticComponent<(props: NodeOutputFieldProps) => JSX.Element>; type CreateGraphStoreProps = { config: GraphConfig; nodes: Graph.Node[]; edges: Graph.Edge[]; slots?: Partial; }; declare function createGraphStore({ config, nodes, edges, slots, }: CreateGraphStoreProps): zustand_traditional.UseBoundStoreWithEqualityFn, "setState"> & { setState(partial: GraphStore | Partial | ((state: GraphStore) => GraphStore | Partial), replace?: boolean | undefined, action?: A | undefined): void; }>; type ContextType = ReturnType | null; declare const GraphContext: react.Context; type ExtractState = GraphStore; declare function useGraphStore(selector: (state: GraphStore) => StateSlice, equalityFn?: (a: StateSlice, b: StateSlice) => boolean): StateSlice; declare function useGraphApi(): NonNullable; type GraphProviderProps = { children: ReactNode; config: GraphConfig; initialNodes?: Graph.Node[]; initialEdges?: Graph.Edge[]; slots?: Partial; }; declare function GraphProvider({ children, config, initialNodes, initialEdges, slots, }: GraphProviderProps): JSX.Element; declare class DagreLayoutEngine extends LayoutEngine { name(): string; apply(nodes: Node[], edges: Edge[]): Node[]; } declare class PipelineLayoutEngine extends LayoutEngine { name(): string; apply(nodes: Node[], edges: Edge[]): Node[]; } declare class PipelineCenteredLayoutEngine extends LayoutEngine { name(): string; apply(nodes: Node[], edges: Edge[]): Node[]; } export { DagreLayoutEngine, GraphConfig, GraphContext, GraphProvider, HEADER_FIELD_NAME, Handle, type InputProps, LayoutEngine, NodeCheckboxField, NodeContainer, NodeDenseLinkedField, NodeGraphEditor, type NodeGraphHandle, NodeHeader, NodeInputField, NodeLinkedField, NodeOutputField, NodeSelectField, PipelineCenteredLayoutEngine, PipelineLayoutEngine, useBuildGraphConfig, useGraphApi, useGraphStore, useNodeCollapsed, useNodeFieldValue, useNodesEdges };