Skip to content

Custom Middleware Example

This example demonstrates how to create a custom middleware that implements read-only functionality for ngDiagram. Middlewares provide a powerful plugin architecture for extending diagram behavior by intercepting state changes before they reach the model.

import '@angular/compiler';
import { Component } from '@angular/core';
import { provideNgDiagram } from 'ng-diagram';
import { DiagramComponent } from './diagram.component';
/**
* Wrapper component that provides the ng-diagram-context
*/
@Component({
imports: [DiagramComponent],
providers: [provideNgDiagram()],
template: ` <diagram /> `,
styleUrl: './diagram-wrapper.component.scss',
})
export class DiagramWrapperComponent {}
  • Action Blocking: Block specific actions based on configuration.
  • Allowlist: Permit selective operations through an allowlist.
  • Operation Cancellation: Cancel operations to prevent unwanted state changes.
  • Logging: Log warnings for blocked actions.