Skip to content
D
Documentation

Commands — classes a–s

reference
8 min readUpdated

Classes A–S

Import these from @grafloria/engine.

Classes

AddGroupCommand

ts
class AddGroupCommand extends Command

Methods

  • constructor(private group: GroupModel)
  • override execute(context: CommandContext): void — Execute the command
  • override undo(context: CommandContext): void — Undo the command
  • override canExecute(context: CommandContext): boolean — Check if command can be executed
  • override canUndo(context: CommandContext): boolean — Check if command can be undone
  • override serialize(): SerializedCommand — Serialize command
  • override getDescription(): string — Get description for UI

AddLinkCommand

ts
class AddLinkCommand extends Command

Methods

  • constructor(private link: LinkModel)
  • override execute(context: CommandContext): void — Execute the command
  • override undo(context: CommandContext): void — Undo the command
  • override canExecute(context: CommandContext): boolean — Check if command can be executed
  • override canUndo(context: CommandContext): boolean — Check if command can be undone
  • override serialize(): SerializedCommand — Serialize command
  • override getDescription(): string — Get description for UI

AddNodeCommand

ts
class AddNodeCommand extends Command

Methods

  • constructor(private node: NodeModel)
  • override execute(context: CommandContext): void — Execute the command
  • override undo(context: CommandContext): void — Undo the command
  • override canExecute(context: CommandContext): boolean — Check if command can be executed
  • override canUndo(context: CommandContext): boolean — Check if command can be undone
  • override serialize(): SerializedCommand — Serialize command
  • override getDescription(): string — Get description for UI

AddPortCommand

ts
class AddPortCommand extends Command

Methods

  • constructor( private nodeId: string, port: PortModel )
  • override execute(context: CommandContext): void — Execute the command
  • override undo(context: CommandContext): void — Undo the command
  • override canExecute(context: CommandContext): boolean — Check if command can be executed
  • override serialize(): SerializedCommand — Serialize command

AddStrokeCommand

ts
class AddStrokeCommand extends Command

Methods

  • constructor(private readonly stroke: StrokeModel)
  • override execute(context: CommandContext): void — Execute the command
  • override undo(context: CommandContext): void — Undo the command
  • override canExecute(context: CommandContext): boolean — Check if command can be executed
  • override serialize(): SerializedCommand — Serialize command

AddToGroupCommand

ts
class AddToGroupCommand extends Command

Methods

  • constructor( private groupId: string, private entityId: string )
  • override execute(context: CommandContext): void — Execute the command
  • override undo(context: CommandContext): void — Undo the command
  • override canExecute(context: CommandContext): boolean — Check if command can be executed
  • override canUndo(context: CommandContext): boolean — Check if command can be undone
  • override serialize(): SerializedCommand — Serialize command
  • override getDescription(): string — Get description for UI

AlignCommand

Align the selected nodes to a shared edge or centre line.

ts
class AlignCommand extends MultiNodeArrangeCommand

Methods

  • constructor(nodeIds: string[], private readonly edge: AlignEdge)
  • override getDescription(): string — Get description for UI

BatchCommand

ts
class BatchCommand extends Command

Methods

  • constructor( name: string, private commands: Command[] )
  • async execute(context: CommandContext): Promise<void> — Execute the command
  • async undo(context: CommandContext): Promise<void> — Undo the command
  • override canExecute(context: CommandContext): boolean — Check if command can be executed
  • override canUndo(context: CommandContext): boolean — Check if command can be undone
  • override serialize(): SerializedCommand — Serialize command
  • override getDescription(): string — Get description for UI
  • getCommands(): ReadonlyArray<Command> — Get all commands in batch
  • addCommand(command: Command): void — Add command to batch

BringNodeToFrontCommand

Lift a node above every other node in the diagram.

ts
class BringNodeToFrontCommand extends NodeZOrderCommand

Methods

  • constructor(nodeId: string)
  • override serialize(): SerializedCommand — Serialize command
  • override getDescription(): string — Get description for UI

CollapseGroupCommand

ts
class CollapseGroupCommand extends Command

Methods

  • constructor( private groupId: string, private options?: CollapseOptions )
  • override execute(context: CommandContext): void — Execute the command
  • override undo(context: CommandContext): void — Undo the command
  • override canExecute(context: CommandContext): boolean — Check if command can be executed
  • override canUndo(context: CommandContext): boolean — Check if command can be undone
  • override serialize(): SerializedCommand — Serialize command
  • override getDescription(): string — Get description for UI

Command

ts
abstract class Command

Properties

NameTypeDefaultDescription
idstring
namestring
timestampnumber

Methods

  • constructor(name: string)
  • abstract execute(context: CommandContext): void | Promise<void> — Execute the command
  • abstract undo(context: CommandContext): void | Promise<void> — Undo the command
  • redo(context: CommandContext): void | Promise<void> — Redo the command (default: re-execute)
  • canExecute(context: CommandContext): boolean — Check if command can be executed
  • canUndo(context: CommandContext): boolean — Check if command can be undone
  • 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.

  • canMergeWith(other: Command): boolean — Check if can merge with another command
  • mergeWith(other: Command): Command — Merge with another command
  • abstract serialize(): SerializedCommand — Serialize command
  • getDescription(): string — Get description for UI

CommandManager

ts
class CommandManager

Methods

  • constructor( private context: CommandContext, private eventBus: EventBus = context.eventBus )
  • async execute(command: Command): Promise<void> — Execute a command
  • async undo(): Promise<void> — Undo last command
  • async redo(): Promise<void> — Redo command
  • beginBatch(): void — Begin batch mode
  • async 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 batch
  • clear(): void — Clear history
  • canUndo(): boolean — Can undo
  • canRedo(): boolean — Can redo
  • getHistory(): ReadonlyArray<CommandHistoryEntry> — Get history
  • getUndoStack(): ReadonlyArray<Command> — Get undo stack
  • getRedoStack(): ReadonlyArray<Command> — Get redo stack
  • setMaxHistorySize(size: number): void — Set max history size
  • setMergingEnabled(enabled: boolean): void — Enable/disable merging
  • setMergingWindow(milliseconds: number): void — Set merging window
  • updateContext(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)
ts
class 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 command
  • override undo(context: CommandContext): void — Undo the command
  • override canExecute(context: CommandContext): boolean — Check if command can be executed
  • override canUndo(context: CommandContext): boolean — Check if command can be undone
  • override 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 command
  • override 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.

ts
class 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
ts
class 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 command
  • override undo(context: CommandContext): void — Undo the command
  • override canExecute(context: CommandContext): boolean — Check if command can be executed
  • override canUndo(context: CommandContext): boolean — Check if command can be undone
  • override serialize(): SerializedCommand — Serialize command
  • override getDescription(): string — Get description for UI

ExpandGroupCommand

ts
class ExpandGroupCommand extends Command

Methods

  • constructor(private groupId: string)
  • override execute(context: CommandContext): void — Execute the command
  • override undo(context: CommandContext): void — Undo the command
  • override canExecute(context: CommandContext): boolean — Check if command can be executed
  • override canUndo(context: CommandContext): boolean — Check if command can be undone
  • override serialize(): SerializedCommand — Serialize command
  • override getDescription(): string — Get description for UI

MacroCommand

ts
class MacroCommand extends Command

Methods

  • constructor(name: string)
  • addStep(command: Command, delay?: number): void — Add step to macro
  • addSteps(commands: Command[]): void — Add multiple steps
  • async execute(context: CommandContext): Promise<void> — Execute the command
  • async undo(context: CommandContext): Promise<void> — Undo the command
  • override canExecute(context: CommandContext): boolean — Check if command can be executed
  • override canUndo(context: CommandContext): boolean — Check if command can be undone
  • override serialize(): SerializedCommand — Serialize command
  • override getDescription(): string — Get description for UI
  • getSteps(): ReadonlyArray<MacroStep> — Get all steps in macro
  • clear(): void — Clear all steps

MoveGroupCommand

ts
class MoveGroupCommand extends Command

Methods

  • constructor( private readonly nodeMoves: GroupNodeMove[], private readonly frameMoves: GroupFrameMove[] )
  • override execute(context: CommandContext): void — Execute the command
  • override undo(context: CommandContext): void — Undo the command
  • override canExecute(context: CommandContext): boolean — Check if command can be executed
  • override canUndo(context: CommandContext): boolean — Check if command can be undone
  • isNoop(): boolean — True when the gesture actually moved something (drop == press is a no-op).
  • override serialize(): SerializedCommand — Serialize command
  • override getDescription(): string — Get description for UI

MoveNodeCommand

ts
class MoveNodeCommand extends Command

Methods

  • constructor( private nodeId: string, newPosition: Point, oldPosition?: Point, options: MoveNodeCommandOptions = {} )
  • override execute(context: CommandContext): void — Execute the command
  • override undo(context: CommandContext): void — Undo the command
  • override canExecute(context: CommandContext): boolean — Check if command can be executed
  • override canUndo(context: CommandContext): boolean — Check if command can be undone
  • override canMergeWith(other: Command): boolean — Check if can merge with another command
  • override mergeWith(other: Command): Command — Merge with another command
  • override serialize(): SerializedCommand — Serialize command
  • override 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
ts
class 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 command
  • override undo(context: CommandContext): void — Undo the command
  • override canExecute(context: CommandContext): boolean — Check if command can be executed
  • override canUndo(context: CommandContext): boolean — Check if command can be undone
  • override serialize(): SerializedCommand — Serialize command
  • override getDescription(): string — Get description for UI

ReconnectLinkCommand

ts
class 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 command
  • override undo(context: CommandContext): void — Undo the command
  • override serialize(): SerializedCommand — Serialize command

RemoveFromGroupCommand

ts
class RemoveFromGroupCommand extends Command

Methods

  • constructor( private groupId: string, private entityId: string )
  • override execute(context: CommandContext): void — Execute the command
  • override undo(context: CommandContext): void — Undo the command
  • override canExecute(context: CommandContext): boolean — Check if command can be executed
  • override canUndo(context: CommandContext): boolean — Check if command can be undone
  • override serialize(): SerializedCommand — Serialize command
  • override getDescription(): string — Get description for UI

RemoveGroupCommand

ts
class RemoveGroupCommand extends Command

Methods

  • constructor(private groupId: string)
  • override execute(context: CommandContext): void — Execute the command
  • override undo(context: CommandContext): void — Undo the command
  • override canExecute(context: CommandContext): boolean — Check if command can be executed
  • override canUndo(context: CommandContext): boolean — Check if command can be undone
  • override serialize(): SerializedCommand — Serialize command
  • override getDescription(): string — Get description for UI

RemoveLinkCommand

ts
class RemoveLinkCommand extends Command

Methods

  • constructor(private linkId: string)
  • override execute(context: CommandContext): void — Execute the command
  • override undo(context: CommandContext): void — Undo the command
  • override canExecute(context: CommandContext): boolean — Check if command can be executed
  • override canUndo(context: CommandContext): boolean — Check if command can be undone
  • override serialize(): SerializedCommand — Serialize command
  • override getDescription(): string — Get description for UI

RemoveNodeCommand

ts
class RemoveNodeCommand extends Command

Methods

  • constructor(private nodeId: string)
  • override execute(context: CommandContext): void — Execute the command
  • override undo(context: CommandContext): void — Undo the command
  • override canExecute(context: CommandContext): boolean — Check if command can be executed
  • override canUndo(context: CommandContext): boolean — Check if command can be undone
  • override serialize(): SerializedCommand — Serialize command
  • override getDescription(): string — Get description for UI

RemovePortCommand

ts
class RemovePortCommand extends Command

Methods

  • constructor( private nodeId: string, private portId: string )
  • override execute(context: CommandContext): void — Execute the command
  • override undo(context: CommandContext): void — Undo the command
  • override canExecute(context: CommandContext): boolean — Check if command can be executed
  • override serialize(): SerializedCommand — Serialize command

RemoveStrokesCommand

One eraser SWEEP — however many strokes it crossed — is ONE undo step.

ts
class RemoveStrokesCommand extends Command

Methods

  • constructor(private readonly strokeIds: readonly string[])
  • override execute(context: CommandContext): void — Execute the command
  • override undo(context: CommandContext): void — Undo the command
  • override canExecute(context: CommandContext): boolean — Check if command can be executed
  • override serialize(): SerializedCommand — Serialize command

ResizeNodeCommand

ts
class ResizeNodeCommand extends Command

Methods

  • constructor( private nodeId: string, newSize: Size, oldSize?: Size )
  • override execute(context: CommandContext): void — Execute the command
  • override undo(context: CommandContext): void — Undo the command
  • override canExecute(context: CommandContext): boolean — Check if command can be executed
  • override canUndo(context: CommandContext): boolean — Check if command can be undone
  • override canMergeWith(other: Command): boolean — Check if can merge with another command
  • override mergeWith(other: Command): Command — Merge with another command
  • override serialize(): SerializedCommand — Serialize command
  • override 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.

ts
class RotateNodeCommand extends Command

Methods

  • constructor( private nodeId: string, newRotation: number, oldRotation?: number, options: RotateNodeCommandOptions = {} )
  • override execute(context: CommandContext): void — Execute the command
  • override undo(context: CommandContext): void — Undo the command
  • override canExecute(context: CommandContext): boolean — Check if command can be executed
  • override canUndo(context: CommandContext): boolean — Check if command can be undone
  • override canMergeWith(other: Command): boolean — Check if can merge with another command
  • override mergeWith(other: Command): Command — Merge with another command
  • override serialize(): SerializedCommand — Serialize command
  • override getDescription(): string — Get description for UI

SendNodeToBackCommand

Drop a node behind every other node in the diagram.

ts
class SendNodeToBackCommand extends NodeZOrderCommand

Methods

  • constructor(nodeId: string)
  • override serialize(): SerializedCommand — Serialize command
  • override getDescription(): string — Get description for UI

SetFlexItemCommand

ts
class SetFlexItemCommand extends Command

Methods

  • constructor( private nodeId: string, private flexConfig: FlexItemConfig )
  • override execute(context: CommandContext): void — Execute the command
  • override undo(context: CommandContext): void — Undo the command
  • override canExecute(context: CommandContext): boolean — Check if command can be executed
  • override canUndo(context: CommandContext): boolean — Check if command can be undone
  • override serialize(): SerializedCommand — Serialize command
  • override getDescription(): string — Get description for UI

SetGridItemCommand

ts
class SetGridItemCommand extends Command

Methods

  • constructor( private nodeId: string, private gridConfig: GridItemConfig )
  • override execute(context: CommandContext): void — Execute the command
  • override undo(context: CommandContext): void — Undo the command
  • override canExecute(context: CommandContext): boolean — Check if command can be executed
  • override canUndo(context: CommandContext): boolean — Check if command can be undone
  • override serialize(): SerializedCommand — Serialize command
  • override getDescription(): string — Get description for UI

SetLayoutCommand

ts
class SetLayoutCommand extends Command

Methods

  • constructor( private groupId: string, private layoutType: 'flexbox' | 'grid', private layoutConfig: LayoutConfig )
  • override execute(context: CommandContext): void — Execute the command
  • override undo(context: CommandContext): void — Undo the command
  • override canExecute(context: CommandContext): boolean — Check if command can be executed
  • override canUndo(context: CommandContext): boolean — Check if command can be undone
  • override serialize(): SerializedCommand — Serialize command
  • override getDescription(): string — Get description for UI

Was this page helpful?