Provider
A sidebar outside the canvas reads the graph and drives the flow - what wrapping a flow in ReactFlowProvider is for in React. Blazor needs no provider: the node and edge lists are already shared state, and a reference to the canvas can be handed to whatever needs to call it.
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 adds the next node to the grid, and the view glides out to keep every node in sight.
- Connect last two joins the two newest nodes; pressing it again adds nothing, since they are already joined.
- Fit view fits the whole graph into the pane.
- Press a node's name in the list: the view moves to that node, selects it and gives it keyboard focus, so the arrow keys move it straight away.
- Work on the canvas - click to select, drag from a handle to connect, press Delete - and the counts and the list follow: the sidebar marks the selected nodes.
How it works
- The sidebar is ordinary markup beside the
BlowCanvas, not inside it. Its counts and its list read the sameList<BlowNode>andList<BlowEdge>the canvas was given and edits in place. OnInithands over the canvas reference once it has rendered and measured; the sidebar's buttons are disabled until then.@refdoes the same job. To reach the canvas from another component, pass the reference down as a parameter or a cascading value - the part React's provider plays.NodesChanged,EdgesChangedandOnSelectionChangere-render the page after each completed edit and each change of selection - once when a drag is released, not on every pointer move - so the sidebar stays in step.- Add node and Connect last two call
AddNodesandAddEdges, thenFitViewAsync(300)eases the view over 300 ms to fit what is there now. - A name in the list calls
FocusNodeAsync(id, select: true, durationMs: 300): it centres the view on the node, makes it the selection and moves keyboard focus to it.