NodeView
Description
The NodeView component renders interactive node-based flows. It is used to define and display nodes with customizable inputs and outputs to build flow-based interfaces. Use NodeView when you need to visually represent and interact with configurable node graphs.
Usage
Instantiate a NodeView using the static helper method from the Tesserae.UI class. Once instantiated, you can define nodes using methods like DefineNode for static nodes or DefineDynamicNode for nodes that update their outputs based on inputs. Additionally, you can monitor changes in the node graph through the OnChange method.
Below is a simple example that creates a node with a text input and a text output:
API reference
public class NodeView : IComponentA NodeView component that provides a visual node-based editor (based on BaklavaJS).
Constructors
Methods
public NodeView OnChange(Action<NodeView> onChange)Adds a change event handler to the node view.
Parameters
- onChange
- The event handler.
Returns
The current instance of the type.
public NodeView Register<T>() where T : INodeView, new()Registers a new node type (static or dynamic) based on the provided class type that implements INodeView.
Type Parameters
- T
- The node type.
Returns
The current instance of the type.
public NodeView DefineNode(string nodeTypeName, Action<InterfaceBuilder> buildNode)Defines a new static node type.
Parameters
- nodeTypeName
- The name of the node type.
- buildNode
- An action to build the node interface.
Returns
The current instance of the type.
public NodeView DefineDynamicNode(string nodeTypeName, Action<InterfaceBuilder> buildBaseNode, Action<InputsState, OutputsState, InterfaceBuilder> onUpdate)Defines a new dynamic node type.
Parameters
- nodeTypeName
- The name of the node type.
- buildBaseNode
- An action to build the base node interface.
- onUpdate
- An action to perform when the node needs updating.
Returns
The current instance of the type.
public HTMLElement Render()Renders the node view.
Returns
The rendered HTMLElement.
public NodeViewGraphState GetState()Gets the current state of the node graph.
Returns
The graph state.
public string GetJsonState(bool formated = false)Gets the current state of the node graph as a JSON string.
Parameters
- formated
- Whether to format the JSON string.
Returns
The JSON string.
public void SetState(string stateJson)Sets the state of the node graph from a JSON string.
Parameters
- stateJson
- The JSON string representing the graph state.
public interface INodeInputpublic interface INodeOutputpublic interface INodeInput<T> : INodeInputpublic interface INodeOutput<T> : INodeOutputSamples
NodeView Sample Usage
The sample below demonstrates how to create a NodeView with multiple nodes, including a dynamic node whose outputs are generated based on an input value. It also shows how to attach a change listener that updates a text area with the current state in JSON format.