Classes A–R
Import these from @grafloria/engine.
Classes
AddGroupCommand
Also has every member of Command, listed on its own entry.
tsclass AddGroupCommand extends Command
Methods
constructor(private group: GroupModel)override execute(context: CommandContext): void— Execute the commandoverride undo(context: CommandContext): void— Undo the commandoverride canExecute(context: CommandContext): boolean— Check if command can be executedoverride canUndo(context: CommandContext): boolean— Check if command can be undoneoverride serialize(): SerializedCommand— Serialize commandoverride getDescription(): string— Get description for UI
AddLinkCommand
Also has every member of Command, listed on its own entry.
tsclass AddLinkCommand extends Command
Methods
constructor(private link: LinkModel)override execute(context: CommandContext): void— Execute the commandoverride undo(context: CommandContext): void— Undo the commandoverride canExecute(context: CommandContext): boolean— Check if command can be executedoverride canUndo(context: CommandContext): boolean— Check if command can be undoneoverride serialize(): SerializedCommand— Serialize commandoverride getDescription(): string— Get description for UI
AddNodeCommand
Also has every member of Command, listed on its own entry.
tsclass AddNodeCommand extends Command
Methods
constructor(private node: NodeModel)override execute(context: CommandContext): void— Execute the commandoverride undo(context: CommandContext): void— Undo the commandoverride canExecute(context: CommandContext): boolean— Check if command can be executedoverride canUndo(context: CommandContext): boolean— Check if command can be undoneoverride serialize(): SerializedCommand— Serialize commandoverride getDescription(): string— Get description for UI
AddPortCommand
Also has every member of Command, listed on its own entry.
tsclass AddPortCommand extends Command
Methods
constructor( private nodeId: string, port: PortModel )override execute(context: CommandContext): void— Execute the commandoverride undo(context: CommandContext): void— Undo the commandoverride canExecute(context: CommandContext): boolean— Check if command can be executedoverride serialize(): SerializedCommand— Serialize command
AddStrokeCommand
Also has every member of Command, listed on its own entry.
tsclass AddStrokeCommand extends Command
Methods
constructor(private readonly stroke: StrokeModel)override execute(context: CommandContext): void— Execute the commandoverride undo(context: CommandContext): void— Undo the commandoverride canExecute(context: CommandContext): boolean— Check if command can be executedoverride serialize(): SerializedCommand— Serialize command
AddToGroupCommand
Also has every member of Command, listed on its own entry.
tsclass AddToGroupCommand extends Command
Methods
constructor( private groupId: string, private entityId: string )override execute(context: CommandContext): void— Execute the commandoverride undo(context: CommandContext): void— Undo the commandoverride canExecute(context: CommandContext): boolean— Check if command can be executedoverride canUndo(context: CommandContext): boolean— Check if command can be undoneoverride serialize(): SerializedCommand— Serialize commandoverride getDescription(): string— Get description for UI
AlignCommand
Also has every member of Command, listed on its own entry.
Align the selected nodes to a shared edge or centre line.
tsclass AlignCommand extends MultiNodeArrangeCommand
Methods
constructor(nodeIds: string[], private readonly edge: AlignEdge)override getDescription(): string— Get description for UIoverride execute(context: CommandContext): void— Execute the commandoverride undo(context: CommandContext): void— Undo the commandoverride canExecute(context: CommandContext): boolean— Check if command can be executedoverride canUndo(context: CommandContext): boolean— Check if command can be undoneoverride serialize(): SerializedCommand— Serialize command
BatchCommand
Also has every member of Command, listed on its own entry.
tsclass BatchCommand extends Command
Methods
constructor( name: string, private commands: Command[] )async execute(context: CommandContext): Promise<void>— Execute the commandasync undo(context: CommandContext): Promise<void>— Undo the commandoverride canExecute(context: CommandContext): boolean— Check if command can be executedoverride canUndo(context: CommandContext): boolean— Check if command can be undoneoverride serialize(): SerializedCommand— Serialize commandoverride getDescription(): string— Get description for UIgetCommands(): ReadonlyArray<Command>— Get all commands in batchaddCommand(command: Command): void— Add command to batch
BringNodeToFrontCommand
Also has every member of Command, listed on its own entry.
Lift a node above every other node in the diagram.
tsclass BringNodeToFrontCommand extends NodeZOrderCommand
Methods
constructor(nodeId: string)override serialize(): SerializedCommand— Serialize commandoverride getDescription(): string— Get description for UIoverride execute(context: CommandContext): void— Execute the commandoverride undo(context: CommandContext): void— Undo the commandoverride canExecute(context: CommandContext): boolean— Check if command can be executedoverride canUndo(context: CommandContext): boolean— Check if command can be undone
CollapseGroupCommand
Also has every member of Command, listed on its own entry.
tsclass CollapseGroupCommand extends Command
Methods
constructor( private groupId: string, private options?: CollapseOptions )override execute(context: CommandContext): void— Execute the commandoverride undo(context: CommandContext): void— Undo the commandoverride canExecute(context: CommandContext): boolean— Check if command can be executedoverride canUndo(context: CommandContext): boolean— Check if command can be undoneoverride serialize(): SerializedCommand— Serialize commandoverride getDescription(): string— Get description for UI
Command
tsabstract class Command
Properties
| Name | Type | Default | Description |
|---|---|---|---|
id | string | ||
name | string | ||
timestamp | number |
Methods
constructor(name: string)abstract execute(context: CommandContext): void | Promise<void>— Execute the commandabstract undo(context: CommandContext): void | Promise<void>— Undo the commandredo(context: CommandContext): void | Promise<void>— Redo the command (default: re-execute)canExecute(context: CommandContext): boolean— Check if command can be executedcanUndo(context: CommandContext): boolean— Check if command can be undoneisUndoable(): boolean— Does this command belong on the undo stack AT ALL?
canUndo(context) is a state probe ("can I undo RIGHT NOW?") consulted at
undo time — many commands answer it from live diagram state. This is the
static declaration consulted at EXECUTE time: a non-mutating command
(Copy) answers false and never enters history. Recording one used to
poison the stack — undo() hit the entry, threw "Cannot undo command:
Copy", never decremented the index, and everything behind it became
permanently unreachable.
canMergeWith(other: Command): boolean— Check if can merge with another commandmergeWith(other: Command): Command— Merge with another commandabstract serialize(): SerializedCommand— Serialize commandgetDescription(): string— Get description for UI
CommandManager
tsclass CommandManager
Methods
constructor( private context: CommandContext, private eventBus: EventBus = context.eventBus )async execute(command: Command): Promise<void>— Execute a commandasync undo(): Promise<void>— Undo last commandasync redo(): Promise<void>— Redo commandbeginBatch(): void— Begin batch modeasync endBatch(name: string = 'Batch Operation'): Promise<void>— End batch mode: commit the queued commands as ONE BatchCommand through the normal execute() path — one history entry, one undo step (with reverse-order undo), and the same strict-validation gate as any other command. The old code looped executeCommand() directly, so a "batch" mutated the diagram while building NO history at all.
Note BatchCommand's existing gate contract: its canExecute() checks every queued command against the CURRENT (pre-batch) state, so a queue whose later commands only become executable after earlier ones ran is refused up front rather than applied halfway.
cancelBatch(): void— Cancel batchclear(): void— Clear historycanUndo(): boolean— Can undocanRedo(): boolean— Can redogetHistory(): ReadonlyArray<CommandHistoryEntry>— Get historygetUndoStack(): ReadonlyArray<Command>— Get undo stackgetRedoStack(): ReadonlyArray<Command>— Get redo stacksetMaxHistorySize(size: number): void— Set max history sizesetMergingEnabled(enabled: boolean): void— Enable/disable mergingsetMergingWindow(milliseconds: number): void— Set merging windowupdateContext(updates: Partial<CommandContext>): void— Update command context
CopyCommand
Also has every member of Command, listed on its own entry.
CopyCommand copies selected entities to clipboard
Features:
- Copies selected nodes
- Includes links between selected nodes
- Optionally includes groups containing selected nodes
- Non-destructive (doesn't modify diagram)
tsclass CopyCommand extends Command
Methods
constructor( private clipboard: ClipboardManager, private options: { includeGroups?: boolean; includeLinks?: boolean; } = {} )override execute(context: CommandContext): void— Execute the commandoverride undo(context: CommandContext): void— Undo the commandoverride canExecute(context: CommandContext): boolean— Check if command can be executedoverride canUndo(context: CommandContext): boolean— Check if command can be undoneoverride isUndoable(): boolean— Does this command belong on the undo stack AT ALL?
canUndo(context) is a state probe ("can I undo RIGHT NOW?") consulted at
undo time — many commands answer it from live diagram state. This is the
static declaration consulted at EXECUTE time: a non-mutating command
(Copy) answers false and never enters history. Recording one used to
poison the stack — undo() hit the entry, threw "Cannot undo command:
Copy", never decremented the index, and everything behind it became
permanently unreachable.
override serialize(): SerializedCommand— Serialize commandoverride getDescription(): string— Get description for UI
DeleteSelectionCommand
Also has every member of Command, listed on its own entry.
DeleteSelectionCommand deletes selected entities from diagram
Features:
- Deletes selected nodes, links, and groups
- Recursively deletes child nodes
- Removes links connected to deleted nodes
- Removes nodes from groups they belong to
- Stores all deleted data for undo
- Supports undo/redo
tsclass DeleteSelectionCommand extends Command
Methods
constructor( private options: { deleteChildren?: boolean; deleteLinks?: boolean; } = {} )override execute(context: CommandContext): void— Execute the commandoverride undo(context: CommandContext): void— Undo the commandoverride redo(context: CommandContext): void— Redo re-applies the RECORDED deletion instead of re-running execute().
The default Command.redo() calls execute(), which reads the LIVE
selection — but undo() restores the entities WITHOUT restoring the
selection, so a redo would find an empty selection and throw
No entities selected. Redo therefore removes exactly the entities this
command removed the first time. The recorded arrays are left intact, so the
command can be undone again afterwards (undo/redo/undo/redo all work).
override canExecute(context: CommandContext): boolean— Check if command can be executedoverride canUndo(context: CommandContext): boolean— Check if command can be undoneoverride serialize(): SerializedCommand— Serialize commandoverride getDescription(): string— Get description for UI
DistributeCommand
Also has every member of Command, listed on its own entry.
Space the selected nodes with EQUAL GAPS along an axis; the two extreme nodes stay put and the interior ones are redistributed between them.
tsclass DistributeCommand extends MultiNodeArrangeCommand
Methods
constructor(nodeIds: string[], private readonly axis: DistributeAxis)override getDescription(): string— Get description for UIoverride execute(context: CommandContext): void— Execute the commandoverride undo(context: CommandContext): void— Undo the commandoverride canExecute(context: CommandContext): boolean— Check if command can be executedoverride canUndo(context: CommandContext): boolean— Check if command can be undoneoverride serialize(): SerializedCommand— Serialize command
DuplicateCommand
Also has every member of Command, listed on its own entry.
DuplicateCommand duplicates selected entities in the diagram
Features:
- Generates new IDs for duplicated entities
- Remaps relationships (links, groups, hierarchy)
- Applies position offset
- Preserves all properties (transforms, layout configs, etc.)
- Supports undo/redo
- Similar to paste but operates directly on selection
tsclass DuplicateCommand extends Command
Methods
constructor( private options: { offset?: Point; selectDuplicated?: boolean; } = {} )override execute(context: CommandContext): void— Execute the commandoverride undo(context: CommandContext): void— Undo the commandoverride canExecute(context: CommandContext): boolean— Check if command can be executedoverride canUndo(context: CommandContext): boolean— Check if command can be undoneoverride serialize(): SerializedCommand— Serialize commandoverride getDescription(): string— Get description for UI
ExpandGroupCommand
Also has every member of Command, listed on its own entry.
tsclass ExpandGroupCommand extends Command
Methods
constructor(private groupId: string)override execute(context: CommandContext): void— Execute the commandoverride undo(context: CommandContext): void— Undo the commandoverride canExecute(context: CommandContext): boolean— Check if command can be executedoverride canUndo(context: CommandContext): boolean— Check if command can be undoneoverride serialize(): SerializedCommand— Serialize commandoverride getDescription(): string— Get description for UI
MacroCommand
Also has every member of Command, listed on its own entry.
tsclass MacroCommand extends Command
Methods
constructor(name: string)addStep(command: Command, delay?: number): void— Add step to macroaddSteps(commands: Command[]): void— Add multiple stepsasync execute(context: CommandContext): Promise<void>— Execute the commandasync undo(context: CommandContext): Promise<void>— Undo the commandoverride canExecute(context: CommandContext): boolean— Check if command can be executedoverride canUndo(context: CommandContext): boolean— Check if command can be undoneoverride serialize(): SerializedCommand— Serialize commandoverride getDescription(): string— Get description for UIgetSteps(): ReadonlyArray<MacroStep>— Get all steps in macroclear(): void— Clear all steps
MoveGroupCommand
Also has every member of Command, listed on its own entry.
tsclass MoveGroupCommand extends Command
Methods
constructor( private readonly nodeMoves: GroupNodeMove[], private readonly frameMoves: GroupFrameMove[] )override execute(context: CommandContext): void— Execute the commandoverride undo(context: CommandContext): void— Undo the commandoverride canExecute(context: CommandContext): boolean— Check if command can be executedoverride canUndo(context: CommandContext): boolean— Check if command can be undoneisNoop(): boolean— True when the gesture actually moved something (drop == press is a no-op).override serialize(): SerializedCommand— Serialize commandoverride getDescription(): string— Get description for UI
MoveNodeCommand
Also has every member of Command, listed on its own entry.
tsclass MoveNodeCommand extends Command
Methods
constructor( private nodeId: string, newPosition: Point, oldPosition?: Point, options: MoveNodeCommandOptions = {} )override execute(context: CommandContext): void— Execute the commandoverride undo(context: CommandContext): void— Undo the commandoverride canExecute(context: CommandContext): boolean— Check if command can be executedoverride canUndo(context: CommandContext): boolean— Check if command can be undoneoverride canMergeWith(other: Command): boolean— Check if can merge with another commandoverride mergeWith(other: Command): Command— Merge with another commandoverride serialize(): SerializedCommand— Serialize commandoverride getDescription(): string— Get description for UI
PasteCommand
Also has every member of Command, listed on its own entry.
PasteCommand pastes entities from clipboard into diagram
Features:
- Generates new IDs for pasted entities
- Remaps relationships (links, groups, hierarchy)
- Applies position offset
- Preserves all properties (transforms, layout configs, etc.)
- Supports undo/redo
tsclass PasteCommand extends Command
Methods
constructor( private clipboard: ClipboardManager, private options: { offset?: Point; selectPasted?: boolean; } = {} )override execute(context: CommandContext): void— Execute the commandoverride undo(context: CommandContext): void— Undo the commandoverride canExecute(context: CommandContext): boolean— Check if command can be executedoverride canUndo(context: CommandContext): boolean— Check if command can be undoneoverride serialize(): SerializedCommand— Serialize commandoverride getDescription(): string— Get description for UI
ReconnectLinkCommand
Also has every member of Command, listed on its own entry.
tsclass ReconnectLinkCommand extends Command
Methods
constructor( private linkId: string, private endpoint: LinkEndpoint, private newPortId: string, private newNodeId: string | undefined, private oldPortId: string, private oldNodeId: string | undefined )override execute(context: CommandContext): void— Execute the commandoverride undo(context: CommandContext): void— Undo the commandoverride serialize(): SerializedCommand— Serialize command
RemoveFromGroupCommand
Also has every member of Command, listed on its own entry.
tsclass RemoveFromGroupCommand extends Command
Methods
constructor( private groupId: string, private entityId: string )override execute(context: CommandContext): void— Execute the commandoverride undo(context: CommandContext): void— Undo the commandoverride canExecute(context: CommandContext): boolean— Check if command can be executedoverride canUndo(context: CommandContext): boolean— Check if command can be undoneoverride serialize(): SerializedCommand— Serialize commandoverride getDescription(): string— Get description for UI
RemoveGroupCommand
Also has every member of Command, listed on its own entry.
tsclass RemoveGroupCommand extends Command
Methods
constructor(private groupId: string)override execute(context: CommandContext): void— Execute the commandoverride undo(context: CommandContext): void— Undo the commandoverride canExecute(context: CommandContext): boolean— Check if command can be executedoverride canUndo(context: CommandContext): boolean— Check if command can be undoneoverride serialize(): SerializedCommand— Serialize commandoverride getDescription(): string— Get description for UI
RemoveLinkCommand
Also has every member of Command, listed on its own entry.
tsclass RemoveLinkCommand extends Command
Methods
constructor(private linkId: string)override execute(context: CommandContext): void— Execute the commandoverride undo(context: CommandContext): void— Undo the commandoverride canExecute(context: CommandContext): boolean— Check if command can be executedoverride canUndo(context: CommandContext): boolean— Check if command can be undoneoverride serialize(): SerializedCommand— Serialize commandoverride getDescription(): string— Get description for UI
RemoveNodeCommand
Also has every member of Command, listed on its own entry.
tsclass RemoveNodeCommand extends Command
Methods
constructor(private nodeId: string)override execute(context: CommandContext): void— Execute the commandoverride undo(context: CommandContext): void— Undo the commandoverride canExecute(context: CommandContext): boolean— Check if command can be executedoverride canUndo(context: CommandContext): boolean— Check if command can be undoneoverride serialize(): SerializedCommand— Serialize commandoverride getDescription(): string— Get description for UI
RemovePortCommand
Also has every member of Command, listed on its own entry.
tsclass RemovePortCommand extends Command
Methods
constructor( private nodeId: string, private portId: string )override execute(context: CommandContext): void— Execute the commandoverride undo(context: CommandContext): void— Undo the commandoverride canExecute(context: CommandContext): boolean— Check if command can be executedoverride serialize(): SerializedCommand— Serialize command
Was this page helpful?