External Store
The graph lives in a store object outside any component, the Redux or Zustand pattern: the toolbar dispatches actions to it, the canvas draws its lists, and every change - from an action or from an edit on the canvas - goes through the store, which tells its subscribers to re-render.
Press Tab to move between the nodes and edges of the diagram.
Press Enter or Space to select it, Shift with Enter to add it to the selection, the arrow keys to move the selected nodes, Delete to remove them and Escape to clear the selection. Press C to start a connection from it.
Press Enter or Space to select it, Delete to remove it and Escape to clear the selection. Press C to move its end to another node.
bit BlowTry it
- Add node dispatches
AddNode: the store appends a node, the canvas draws it and the view glides out to include it. - Connect random dispatches
ConnectRandom, which joins two nodes that are not yet joined - or logs that every pair already is. - Reset replaces the store's state with a single root node.
- Edit on the canvas - drag a node, drag from a handle to connect two, select something and press Delete - and each edit arrives in the log as a
CanvasEditedaction with what kind of edit it was, while the readout follows.
How it works
FlowStoreis a plain class holding theNodesandEdgeslists, aDispatch(action)method that changes them, and aChangedevent raised after every action. The page subscribes inOnInitializedand unsubscribes inDispose; any number of components could do the same.- The canvas is handed the store's lists as
NodesandEdges. Reset hands it new list instances; the canvas reads whatever lists it is given on its next render, so a store that replaces its state rather than mutating it works as well. - A user edit changes the lists directly - the canvas always edits the lists it was given in place.
OnGraphChangedis raised once per completed edit with aBlowGraphChange, and the page turns it into aCanvasEditedaction carrying the change'sLabel(move,connect,delete, ...), so the store and its subscribers hear of every edit in one place. - Add node calls
FitViewAsync(300)on the canvas after dispatching, since a new node may land outside the view the graph was fitted to.