Skip to content

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.

e1e2e3 pinned
Free
deletable · selectable
Locked
locked · selectable
Read-only
deletable · read-only
Child
deletable · selectable
bit Blow

Try 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 a BlowNode or BlowEdge keeps it out of a deletion when false - but an edge always goes with a node it is attached to, and a child node with its parent.
  • Selectable (true) set to false means the element can never be selected, so the delete keys never reach it.
  • DeleteKeys (Delete and Backspace) remove the selection while DeleteKeyEnabled is on; when nothing selected is deletable, nothing happens.
  • SelectAllKeyEnabled (true) binds Ctrl/Cmd+A to SelectAllAsync(), which selects every selectable, visible node and edge - the method the button calls.
  • OnBeforeDelete is a synchronous Func<IReadOnlyList<BlowNode>, IReadOnlyList<BlowEdge>, bool> called with everything about to go, the cascaded edges included; returning false cancels the whole deletion. Not being an EventCallback, it does not re-render the page, so the page calls StateHasChanged to show its verdict.
  • After a deletion OnNodesDelete and OnEdgesDelete report each kind as an IReadOnlyList (each only when it has something), then OnDelete reports both as a BlowSelectionChange.
  • DeleteElementsAsync(nodes, edges) deletes from code with the same rules, veto and events - the Delete selected button passes it the selected nodes and edges.
An unhandled error has occurred. Reload 🗙