Import these from @grafloria/engine.
Functions
isValidDiagramMode
Type guard to check if a string is a valid DiagramMode
tsfunction isValidDiagramMode(mode: string): mode is DiagramMode
Classes
DiagramEngine
tsclass DiagramEngine
Properties
| Name | Type | Default | Description |
|---|---|---|---|
eventBus | EventBus | ||
store | DiagramStore | ||
commandManager | CommandManager | ||
pluginManager | PluginManager | ||
typeRegistry | TypeRegistry | ||
validationEngine | ValidationEngine | ||
serializer | DiagramSerializer | ||
performanceMonitor | PerformanceMonitor | ||
modeManager | ModeManager | ||
clipboardManager | ClipboardManager | ||
selectionManager | SelectionManager | ||
routingEngine | RoutingEngine | ||
templateRegistry | TemplateRegistry |
Methods
constructor(config: DiagramEngineConfig = {})getDiagram(): DiagramModel | null— Get current diagramgetConfig(): DiagramEngineConfig— Get configurationgetInteractionConfig(): InteractionConfig— Get interaction configuration Returns the current interaction mode settingssetInteractionConfig(config: Partial<InteractionConfig>): void— Set interaction configuration Updates interaction mode settings and emits eventgetConnectionStateManager(): ConnectionStateManager— Get connection state manager Used for managing connection drag operationsgetReconnectionPreview(): ReconnectionPreview | null— Current endpoint-reconnection preview, or null when no endpoint is being dragged. The renderer reads this to draw a ghost link.setReconnectionPreview(preview: ReconnectionPreview | null): void— Set (or clear, with null) the endpoint-reconnection preview. Called by the interaction layer on start/move/end of an endpoint drag. Does not emit — the interaction layer already triggers re-render.getProximityPreview(): ProximityPreview | null— The proximity-connect proposal the renderer draws as a live wire, or null.setProximityPreview(preview: ProximityPreview | null): void— Set (or clear, with null) the proximity-connect proposal. Does not emit — the node drag that drives it already triggers re-renders.getSnapGuides(): SnapGuideSegment[] | null— The live snap-guide segments a node drag is showing, or null.setSnapGuides(guides: SnapGuideSegment[] | null): void— Set (or clear, with null) the live snap guides. Does not emit — the node drag that drives them already triggers re-renders.getRoutingEngine(): RoutingEngine— Get routing engine Used for calculating link paths with various algorithmsenableLiveRerouting(): void— Enable live rerouting Automatically updates link paths when nodes move or resizedisableLiveRerouting(): void— Disable live reroutinggetLiveReroutingEngine(): LiveReroutingEngine | null— Get live rerouting enginesetDiagram(diagram: DiagramModel | null): void— Set diagramcreateDiagram(name: string = 'Untitled'): DiagramModel— Create new diagramclearDiagram(): void— Clear diagramasync addNode(config: { type: string; position: Point; size?: Size; data?: any; }): Promise<NodeModel>— Add node (from config) Add node (pre-created NodeModel) Add node implementationasync addNode(node: NodeModel): Promise<NodeModel>— Add node (from config) Add node (pre-created NodeModel) Add node implementationasync addNode(configOrNode: { type: string; position: Point; size?: Size; data?: any } | NodeModel): Promise<NodeModel>— Add node (from config) Add node (pre-created NodeModel) Add node implementationasync removeNode(nodeId: string): Promise<void>— Remove nodeasync addLink(config: { sourcePortId: string; targetPortId: string; type?: string; data?: any; }): Promise<LinkModel>— Add linkasync removeLink(linkId: string): Promise<void>— Remove linkasync addGroup(config: { name: string }): Promise<GroupModel>— Add groupasync removeGroup(groupId: string): Promise<void>— Remove groupasync addToGroup(groupId: string, entityId: string): Promise<void>— Add entity to groupasync removeFromGroup(groupId: string, entityId: string): Promise<void>— Remove entity from groupasync expandGroup(groupId: string): Promise<void>— Expand groupasync collapseGroup(groupId: string, options?: CollapseOptions): Promise<void>— Collapse groupgetGroup(groupId: string): GroupModel | undefined— Get group by IDgetGroups(): GroupModel[]— Get all groupsasync setLayout( groupId: string, layoutType: 'flexbox' | 'grid', layoutConfig: LayoutConfig ): Promise<void>— Set layout configuration on a groupasync clearLayout(groupId: string): Promise<void>— Clear layout configuration from a groupgetLayout(groupId: string): { type: LayoutType; config?: LayoutConfig } | undefined— Get layout configuration from a groupasync setFlexItem(nodeId: string, flexConfig: FlexItemConfig): Promise<void>— Set flex item configuration on a nodeasync setGridItem(nodeId: string, gridConfig: GridItemConfig): Promise<void>— Set grid item configuration on a nodeasync copy(options?: { includeGroups?: boolean; includeLinks?: boolean }): Promise<void>— Copy selected entities to clipboardasync paste(options?: { offset?: Point; selectPasted?: boolean }): Promise<void>— Paste entities from clipboardasync duplicate(options?: { offset?: Point; selectDuplicated?: boolean }): Promise<void>— Duplicate selected entitiesasync deleteSelection(options?: { deleteChildren?: boolean; deleteLinks?: boolean }): Promise<void>— Delete selected entitiesgetClipboardData()— Get clipboard datahasClipboardData(): boolean— Check if clipboard has dataclearClipboard(): void— Clear clipboardgetClipboardStats()— Get clipboard statisticsvalidateDiagram(options?: { validateTypes?: boolean; validateConnections?: boolean; validatePorts?: boolean; strict?: boolean }): ValidationResult— Validate the entire diagramvalidateNode(nodeId: string, options?: { validateTypes?: boolean; validateConnections?: boolean; validatePorts?: boolean; strict?: boolean }): ValidationResult— Validate a specific nodevalidateLink(linkId: string, options?: { validateTypes?: boolean; validateConnections?: boolean; validatePorts?: boolean; strict?: boolean }): ValidationResult— Validate a specific linkvalidatePort(portId: string, nodeId: string, options?: { validateTypes?: boolean; validateConnections?: boolean; validatePorts?: boolean; strict?: boolean }): ValidationResult— Validate a specific portvalidateLayout(groupId: string, options?: { strict?: boolean }): ValidationResult— Validate layout configuration for a groupregisterNodeType(definition: NodeTypeDefinition): void— Register a node type definitionregisterPortType(definition: PortTypeDefinition): void— Register a port type definitionregisterLinkType(definition: LinkTypeDefinition): void— Register a link type definitionregisterGroupType(definition: GroupTypeDefinition): void— Register a group type definitionenableRealTimeValidation(): void— Enable real-time validationdisableRealTimeValidation(): void— Disable real-time validationisRealTimeValidationEnabled(): boolean— Check if real-time validation is enabledselectNodes(nodeIds: string[]): void— Select nodesselectLinks(linkIds: string[]): void— Select linksclearSelection(): void— Clear selectionasync undo(): Promise<void>— Undoasync redo(): Promise<void>— RedocanUndo(): boolean— Can undocanRedo(): boolean— Can redovalidate(): ValidationResult— Validate diagramserialize(): SerializedDiagram | null— Serialize diagram (with mode)deserialize(data: SerializedDiagram, options?: import('../models/DiagramModel').DiagramLoadOptions): DiagramModel— Deserialize diagram (with mode)loadFromJSON( json: string | SerializedDiagram, options?: import('../models/DiagramModel').DiagramLoadOptions ): DiagramModel— Load diagram from JSON (with mode)saveToJSON(): string | null— Save diagram to JSONasync registerPlugin(plugin: Plugin): Promise<void>— Register a plugin AND bring it to life.getPlugin(name: string): Plugin | undefined— Get pluginsetViewport(viewport: Viewport): void— Set viewportsetZoom(zoom: number): void— Set zoomgetPerformanceReport(): PerformanceReport— Get performance reportgetMode(): DiagramMode— Get current diagram modesetMode(mode: DiagramMode): void— Set diagram modeisDesignerMode(): boolean— Check if in designer modeisRunningMode(): boolean— Check if in running modeisViewMode(): boolean— Check if in view modeisDebugMode(): boolean— Check if in debug modeisPresentationMode(): boolean— Check if in presentation modeisReadOnlyMode(): boolean— Check if in read-only mode (any mode except designer)addModeGuard(name: string, guard: ModeGuardFunction): void— Add mode transition guardremoveModeGuard(name: string): void— Remove mode transition guardclearModeGuards(): void— Clear all mode transition guardsconfigureModeViewport(mode: DiagramMode, settings: ModeViewportSettings): void— Configure viewport settings for specific modegetModeViewportSettings(mode: DiagramMode): ModeViewportSettings— Get viewport settings for specific modegetModeHistory(): ModeHistoryEntry[]— Get mode historyclearModeHistory(): void— Clear mode historypreviousMode(): void— Navigate to previous modenextMode(): void— Navigate to next modepushMode(mode: DiagramMode): void— Push mode onto stack (save current, switch to new)popMode(): void— Pop mode from stack (return to previous)getModeAnalytics(): ModeAnalytics— Get mode analyticsbeforeModeChange(hook: ModeChangeHook): () => void— Register before mode change hookafterModeChange(hook: ModeChangeHook): () => void— Register after mode change hookgetLinkBehaviorForMode(baseBehavior: Partial<{ deletable: boolean; selectable: boolean }>): { deletable: boolean; selectable: boolean; }— Get link behavior adjusted for current modeinitialize(): void— Initialize the enginegetStore(): DiagramStore— Get the storeon(event: string, listener: (...args: any[]) => void): void— Subscribe to eventsoff(event: string, listener: (...args: any[]) => void): void— Unsubscribe from eventsdestroy(): void— Destroy enginerefreshGroupObstacles(): void— Reconcile the shared ObstacleMap with the diagram's GROUP state, idempotently:setLayoutService(service: { applyLayout(diagram: DiagramModel, config: any): Promise<any>; }): void— Set layout service for diagram layoutsgetLayoutRegistry(): LayoutRegistry— The named-algorithm registry, with the built-ins already registered.async layout( name: string = DEFAULT_LAYOUT_NAME, options: UnifiedLayoutOptions = {} ): Promise<UnifiedLayoutResult>— Lay out the whole diagram.async layoutIncremental( options: IncrementalOptions & { name?: string } & UnifiedLayoutOptions = {} ): Promise<UnifiedLayoutResult & { movement: MovementReport; tween: TweenPlan }>— Mental-map-preserving incremental layout.setLayoutPort(port?: LayoutPort): void— Run layout off the main thread.async applyLayout(config: { adapter: string | any; options?: any; animate?: boolean; animationDuration?: number; fit?: boolean; canvasDimensions?: { width: number; height: number }; }): Promise<{ nodePositions: Map<string, { x: number; y: number }>; bounds: { x: number; y: number; width: number; height: number }; metadata?: any; }>— Apply layout to current diagramasync applyDagreLayout( options?: { rankdir?: 'TB' | 'BT' | 'LR' | 'RL'; align?: 'UL' | 'UR' | 'DL' | 'DR'; nodesep?: number; edgesep?: number; ranksep?: number; marginx?: number; marginy?: number; ranker?: 'network-simplex' | 'tight-tree' | 'longest-path'; }, canvasDimensions?: { width: number; height: number } ): Promise<any>— Quick helper: Apply Dagre layoutasync applyELKLayout( options?: { algorithm?: 'layered' | 'force' | 'stress' | 'mrtree' | 'radial' | 'disco'; 'elk.direction'?: 'RIGHT' | 'LEFT' | 'DOWN' | 'UP'; 'elk.spacing.nodeNode'?: number; [key: string]: any; }, canvasDimensions?: { width: number; height: number } ): Promise<any>— Quick helper: Apply ELK layoutdispose(): void— Cleanup and dispose of all resources Should be called when the engine is no longer needed
Interfaces
DiagramEngineConfig
tsinterface DiagramEngineConfig
Properties
| Name | Type | Default | Description |
|---|---|---|---|
plugins? | Plugin[] | ||
mode? | DiagramMode | ||
performance? | { enableMonitoring?: boolean; enableProfiling?: boolean; warnThreshold?: number; } | ||
validation? | { realTime?: boolean; strict?: boolean; } | ||
history? | { maxCommands?: number; maxSnapshots?: number; } | ||
interaction? | Partial<InteractionConfig> |
ModeChangeEvent
Mode change event payload
tsinterface ModeChangeEvent
Properties
| Name | Type | Default | Description |
|---|---|---|---|
previousMode | DiagramMode | ||
currentMode | DiagramMode |
ProximityPreview
The port pair a proximity-connect DROP would link, while a node drag is inside the radius. The renderer reads this to draw the proposed wire itself, not only the two ports. Same seam shape as {@link ReconnectionPreview}: interaction layer writes, renderer reads, cleared on drop/cancel.
tsinterface ProximityPreview
Properties
| Name | Type | Default | Description |
|---|---|---|---|
sourceNodeId | string | ||
sourcePortId | string | ||
targetNodeId | string | ||
targetPortId | string |
ReconnectionPreview
Transient state for the endpoint-reconnection live preview. Set by the interaction layer while an endpoint handle is being dragged; read by the renderer to draw a ghost link from the stationary endpoint to the cursor. Deliberately separate from {@link ConnectionStateManager} (which owns NEW-link creation) so the two previews never double-render.
tsinterface ReconnectionPreview
Properties
| Name | Type | Default | Description |
|---|---|---|---|
linkId | string | Id of the link whose endpoint is being reconnected. | |
endpoint | 'source' | 'target' | Which endpoint the cursor is dragging (the OTHER end stays fixed). | |
mousePoint | Point | Current cursor position in world coordinates. | |
isValid | boolean | Whether the port/node currently under the cursor is a valid drop target. |
SnapGuideSegment
One drawable snap-guide segment, in world coordinates. The interaction layer computes alignment / equal-spacing guides during a node drag and publishes them here; the renderer draws them as dashed overlay lines (spacing segments may carry a gap label). Cleared (null) when the drag ends or nothing is within snapping distance.
tsinterface SnapGuideSegment
Properties
| Name | Type | Default | Description |
|---|---|---|---|
x1 | number | ||
y1 | number | ||
x2 | number | ||
y2 | number | ||
kind | 'alignment' | 'spacing' | ||
label? | string |
Enums
DiagramMode
Diagram mode enum - defines the operational mode of the diagram engine
tsenum DiagramMode
Members
DESIGNER = 'designer'— Designer mode - Full editing capabilities (default) - All node/link operations enabled - Create, edit, delete, move, resize nodes - Create and delete linksRUNNING = 'running'— Running mode - Execution/simulation mode - Editing disabled - Nodes selectable for execution flow visualization - No structural changes allowedVIEW = 'view'— View mode - Read-only viewing - All editing disabled - Nodes selectable for inspection - Pure viewing experienceDEBUG = 'debug'— Debug mode - Debugging mode - Similar to running but with debug capabilities - Breakpoints, step-through, inspection - No structural changes allowedPRESENTATION = 'presentation'— Presentation mode - Clean presentation view - All editing disabled - Nodes selectable for navigation - Clean UI without clutter
Was this page helpful?