Delete Protection
Three layers of protection against deleting the wrong thing: Deletable and Selectable flags on each node and edge, a veto over a whole deletion with OnBeforeDelete, and the events that report what went - OnNodesDelete, OnEdgesDelete and OnDelete. Edges attached to a deleted node always go with 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
- Click the canvas and press Ctrl+A (Cmd+A on a Mac), or click Select all: everything is selected except Read-only, which cannot be selected at all.
- Press Delete or Backspace, or click Delete selected: Free and Child go and Locked stays. Edges e1 and e2 go, and so does the pinned edge e3 - it is not deletable itself, but it hung off Child. The footer lists each event that was raised.
- After a Reset, select only the pinned edge e3 and press Delete: nothing happens, and no event is raised.
- Reset puts the graph back. Escape clears the selection.
- Tick Veto deleting connected nodes, select Free and press Delete: the veto refuses, because edge e1 would go with it, and nothing is deleted. Selecting just the edge e1 still deletes it.
- Untick Ctrl+A selects all: the shortcut stops working, while the Select all button, which calls the API, still does.
How it works
Deletable(true) on aBlowNodeorBlowEdgekeeps it out of a deletion whenfalse- but an edge always goes with a node it is attached to, and a child node with its parent.Selectable(true) set tofalsemeans the element can never be selected, so the delete keys never reach it.DeleteKeys(Delete and Backspace) remove the selection whileDeleteKeyEnabledis on; when nothing selected is deletable, nothing happens.SelectAllKeyEnabled(true) binds Ctrl/Cmd+A toSelectAllAsync(), which selects every selectable, visible node and edge - the method the button calls.OnBeforeDeleteis a synchronousFunc<IReadOnlyList<BlowNode>, IReadOnlyList<BlowEdge>, bool>called with everything about to go, the cascaded edges included; returningfalsecancels the whole deletion. Not being anEventCallback, it does not re-render the page, so the page callsStateHasChangedto show its verdict.- After a deletion
OnNodesDeleteandOnEdgesDeletereport each kind as anIReadOnlyList(each only when it has something), thenOnDeletereports both as aBlowSelectionChange. DeleteElementsAsync(nodes, edges)deletes from code with the same rules, veto and events - the Delete selected button passes it the selected nodes and edges.