Version: 2.0.2 · React-free · Pure logic · 20 tests
The command pattern + undo/redo + shortcut parsing. Pure logic, no React, no UI. Every L3+ command (in designer) implements ICommand and registers with a CommandManager.
CommandArgs,CommandResultCommandManagerEvents—registered, unregistered, executed, undone, redone, clearedICommand<TArgs, TReturn>—name, label, group, shortcut, execute, optional undo, optional mergeable/mergeWindowMsICommandManagerCommandManagerOptions—historyLimit, autoMergeParsedShortcut,ShortcutBinder,ShortcutBinderOptions,ShortcutToken
parseShortcut(input)— supportsMod(Meta on macOS, Ctrl elsewhere),Ctrl,Meta,Shift,Alt.Mod+Zstyle.bindShortcuts(manager, options)— adds a globalkeydownlistener; SSR-safe (no-op ifwindowis undefined)isMacOS()
CommandManager(implementsICommandManager)
interface ICommand<TArgs = unknown, TReturn = unknown> {
name: string;
label?: string;
group?: string;
shortcut?: string;
execute(args: TArgs): TReturn | Promise<TReturn>;
undo?(args: TArgs, returnValue: TReturn): void | Promise<void>;
// Optional auto-merge for slider-style operations
mergeable?: boolean;
mergeWindowMs?: number; // default 500
}- Uses
@monbolc/lowcode-utils'sEmitterfor events CommandManagerkeeps two stacks (undoStack,redoStack); a newexecuteclears the redo stack- Auto-merge: when a command has
mergeable: trueand the top of the undo stack is the same name withinmergeWindowMs(default 500ms), update the top'sargsin place (keeping the originalreturnValueso undo restores the pre-window state). Critical forSetPropCommand(slider drag). - On undo/redo failure, the entry is restored to its original stack so the user can retry
unregisteralso prunes in-flight history entries for that command name
- 2 test files, 20 tests
manager.test.ts(14): registration, undo, redo, merge windows, history limit, events, prune-on-unregistershortcut.test.ts(6):parseShortcutcoverage
@monbolc/lowcode-types(workspace)@monbolc/lowcode-utils(workspace)
- ../packages/designer.md — the 5 commands that consume this
- ../COMPARISON-WITH-ALI.md — upstream
ali/plugin-command/is a near-direct port (3 files, 564 lines)