Classes A–S
Import these from @grafloria/engine.
Classes
AddGroupCommand
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
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
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
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
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
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
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 UI
BatchCommand
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
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 UI
CollapseGroupCommand
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
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; // Include groups (default: false) includeLinks?: boolean; // Include links between copied nodes (default: true) } = {} )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
DistributeCommand
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 UI
DuplicateCommand
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; // Position offset (default: {x: 20, y: 20}) selectDuplicated?: boolean; // Select duplicated entities (default: true) } = {} )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
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
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
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
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
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; // Position offset (default: {x: 20, y: 20}) selectPasted?: boolean; // Select pasted entities (default: true) } = {} )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
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
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
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
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
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
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
RemoveStrokesCommand
One eraser SWEEP — however many strokes it crossed — is ONE undo step.
tsclass RemoveStrokesCommand extends Command
Methods
constructor(private readonly strokeIds: readonly 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
ResizeNodeCommand
tsclass ResizeNodeCommand extends Command
Methods
constructor( private nodeId: string, newSize: Size, oldSize?: Size )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
RotateNodeCommand
Rotate a node to an absolute angle (degrees), undoable.
Mirrors {@link ResizeNodeCommand }: oldRotation is captured on first execute
when the caller did not supply it, so a command built from a live gesture (the
model already sits at its final angle) still restores the pre-gesture angle.
tsclass RotateNodeCommand extends Command
Methods
constructor( private nodeId: string, newRotation: number, oldRotation?: number, options: RotateNodeCommandOptions = {} )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
SendNodeToBackCommand
Drop a node behind every other node in the diagram.
tsclass SendNodeToBackCommand extends NodeZOrderCommand
Methods
constructor(nodeId: string)override serialize(): SerializedCommand— Serialize commandoverride getDescription(): string— Get description for UI
SetFlexItemCommand
tsclass SetFlexItemCommand extends Command
Methods
constructor( private nodeId: string, private flexConfig: FlexItemConfig )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
SetGridItemCommand
tsclass SetGridItemCommand extends Command
Methods
constructor( private nodeId: string, private gridConfig: GridItemConfig )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
SetLayoutCommand
tsclass SetLayoutCommand extends Command
Methods
constructor( private groupId: string, private layoutType: 'flexbox' | 'grid', private layoutConfig: LayoutConfig )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
Was this page helpful?