Import it from @grafloria/angular.
Angular service wrapper for engine ModeManager. Provides reactive API using RxJS observables.
Features:
- Reactive mode state (BehaviorSubject)
- Mode transition guards
- Mode history tracking
- Mode-specific viewport settings
- Before/after hooks
- Mode analytics
ts@Injectable({ providedIn: 'root' })
export class ModeManagerService implements OnDestroy
Properties
| Name | Type | Default | Description |
|---|---|---|---|
mode$ | Observable of current diagram mode. Emits whenever mode changes. | ||
modeChanged$ | Observable of mode change events. Emits { previousMode, currentMode } on every mode change. |
Methods
ngOnDestroy(): voidgetMode(): DiagramMode— Get current diagram mode.setMode(mode: DiagramMode): void— Set diagram mode. Mode change may be blocked by guards.isDesignerMode(): boolean— Check if in designer mode.isRunningMode(): boolean— Check if in running mode.isViewMode(): boolean— Check if in view mode.isDebugMode(): boolean— Check if in debug mode.isPresentationMode(): boolean— Check if in presentation mode.isReadOnlyMode(): boolean— Check if in read-only mode (any mode except designer).addModeGuard(name: string, guard: ModeGuardFunction): void— Add mode transition guard. Guards can prevent mode changes based on custom logic.removeModeGuard(name: string): void— Remove mode transition guard.clearModeGuards(): void— Clear all mode transition guards.configureModeViewport(mode: DiagramMode, settings: ModeViewportSettings): void— Configure viewport settings for specific mode.getModeViewportSettings(mode: DiagramMode): ModeViewportSettings— Get viewport settings for specific mode.getModeHistory(): ModeHistoryEntry[]— Get mode history. Returns array of mode entries with timestamps and durations.clearModeHistory(): void— Clear mode history (keeps current mode only).previousMode(): void— Navigate to previous mode in history.nextMode(): void— Navigate to next mode in history.pushMode(mode: DiagramMode): void— Push current mode onto stack and switch to new mode. Useful for temporary mode switches.popMode(): void— Pop mode from stack and return to previous mode.getModeAnalytics(): ModeAnalytics— Get mode analytics (time spent in each mode).beforeModeChange(hook: ModeChangeHook): () => void— Register before mode change hook. Hook can prevent mode change by returning false.afterModeChange(hook: ModeChangeHook): () => void— Register after mode change hook.
Example
typescriptconstructor(private modeManager: ModeManagerService) {}
ngOnInit() {
// Subscribe to mode changes
this.modeManager.mode$.subscribe(mode => {
console.log('Current mode:', mode);
});
// Switch to running mode
this.modeManager.setMode(DiagramMode.RUNNING);
}
Was this page helpful?