Framework
Spatial node editor
Import from bedform/Spatial/NodeEditor or use Spatial.NodeEditor. Place an
Editor inside a spatial View using the usual Canvas-backed renderer and
interaction router. The editor renders Node and
Edge widgets from the graph you pass in. Node coordinates and dimensions are
layout pixels, measured from the parent's content origin.
import { Text, View } from "bedform/Spatial/Components";
import { Editor } from "bedform/Spatial/NodeEditor";
import type { GraphEdgeProps, NodeProps } from "bedform/Spatial/NodeEditor";
import { useState } from "bedform/Spatial/React";
function RecipeGraph() {
const [position, setPosition] = useState({ X: 16, Y: 24 });
const [edges, setEdges] = useState<ReadonlyArray<GraphEdgeProps>>([]);
const nodes: ReadonlyArray<NodeProps> = [
{
Id: "ore",
Title: "Iron ore",
Position: position,
OnMove: setPosition,
children: <Text>Raw input</Text>
},
{
Id: "furnace",
Title: "Furnace",
Position: { X: 160, Y: 48 },
children: <Text>Smelt</Text>
}
];
return <View Dimension="minecraft:overworld" Width={280} Height={112}>
<Editor Nodes={nodes} Edges={edges}
OnConnect={link => setEdges(current => [
...current,
{ ...link, Id: JSON.stringify([link.Source, link.Target]) }
])}
OnReconnect={(id, link) => setEdges(current =>
current.map(edge => edge.Id === id ? { ...edge, ...link } : edge))}
/>
</View>;
}- Nodes have a beveled Minecraft frame, a title and a body for spatial widgets.
Use the title to select a node through
OnSelect. SetSelectedto show the green title and bring the node forward.Layeroverrides that default. - With a registered gesture item, hold Use on the title to move the node or on
the corner grip to resize it. Supply
OnMoveorOnResizeand apply its proposed geometry to the node. The grip appears whenOnResizeis supplied. - Use a port, then use a second port to connect them. The first port turns
yellow. Use it again to cancel. Nodes have one input on the left and one
output on the right by default. Custom
Handlescan sit on any side. - Strict mode pairs an output with an input regardless of which you click
first. Loose mode also pairs ports of the same type. In either mode, the
editor checks port availability and duplicate endpoint pairs before calling
your optional
IsValidConnection. - Edges follow both ports when nodes move or resize. Use
Routeto choose"bezier"(default),"straight"or"step". WithOnEdgeSelect, Use the center marker to select the edge. WithOnReconnect, Use the green source grip or blue target grip and then Use the replacement port. Use the same grip again to cancel. The graph changes when you updateEdges. - An edge's
SourceandTargetname node IDs and optional handle IDs. An omitted handle selects the first matching port. An edge with a hidden, removed or unresolved endpoint disappears until both ports resolve.
Import point-based Edge from bedform/Spatial/NodeEditor as well. It still
accepts explicit Bézier Points and OnEndpointChange for world-space
connections without a graph. General-purpose Path lives in
bedform/Spatial/Components.
The graph model follows rataflow's nodes, handles and connections. Minecraft Use and held-item gestures provide the in-world interactions.