Skip to content

Events and permissions

Loading interactive example…Open in new tab ↗
Opening the live canvas…

The first card is protected by a host admission hook. Try deleting it with the button, or moving and editing it on the canvas. The second card and connection remain editable. A rejected command displays its reason and adds no undo entry. Change the connection, undo it, and redo it to compare an admitted operation.

DrawingConfiguration.hooks.beforeChange checks the candidate before publication. UI gestures, semantic commands and document imports share this boundary. The example protects one identity; a real host supplies its own authorization context. This local hook does not replace authorization on a remote server.

The change set is derived lazily and scans the documents when read. Avoid using this example as a performance policy for very large documents without profiling.

See Events and hooks and LLM documentation.

Source

dart
DiagramPolicyDecision protectFirstCard(DiagramChangeProposal proposal) {
  // This is host policy, not a second mutation path. The shared store applies
  // it to UI previews, commands, imports, undo and redo before publication.
  final changes = proposal.elements;
  if (changes.updatedIds.contains('card-0') ||
      changes.removedIds.contains('card-0')) {
    return const DiagramPolicyDecision.deny('The first card is protected.');
  }
  return const DiagramPolicyDecision.allow();
}