forked from alibaba/lowcode-engine
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathcommand.ts
More file actions
56 lines (47 loc) · 1.74 KB
/
command.ts
File metadata and controls
56 lines (47 loc) · 1.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import {
IPublicApiCommand,
IPublicModelPluginContext,
IPublicTypeCommand,
IPublicTypeCommandHandlerArgs,
IPublicTypeListCommand,
} from '@felce/lowcode-types';
import { commandSymbol, pluginContextSymbol } from '../symbols';
import { ICommand, ICommandOptions } from '@felce/lowcode-editor-core';
const optionsSymbol = Symbol('options');
const commandScopeSet = new Set<string>();
export class Command implements IPublicApiCommand {
[commandSymbol]: ICommand;
[optionsSymbol]?: ICommandOptions;
[pluginContextSymbol]?: IPublicModelPluginContext;
constructor(
innerCommand: ICommand,
pluginContext?: IPublicModelPluginContext,
options?: ICommandOptions,
) {
this[commandSymbol] = innerCommand;
this[optionsSymbol] = options;
this[pluginContextSymbol] = pluginContext;
const commandScope = options?.commandScope;
if (commandScope && commandScopeSet.has(commandScope)) {
throw new Error(`Command scope "${commandScope}" has been registered.`);
}
}
registerCommand(command: IPublicTypeCommand): void {
this[commandSymbol].registerCommand(command, this[optionsSymbol]);
}
batchExecuteCommand(commands: { name: string; args: IPublicTypeCommandHandlerArgs }[]): void {
this[commandSymbol].batchExecuteCommand(commands, this[pluginContextSymbol]);
}
executeCommand(name: string, args: IPublicTypeCommandHandlerArgs): void {
this[commandSymbol].executeCommand(name, args);
}
listCommands(): IPublicTypeListCommand[] {
return this[commandSymbol].listCommands();
}
unregisterCommand(name: string): void {
this[commandSymbol].unregisterCommand(name);
}
onCommandError(callback: (name: string, error: Error) => void): void {
this[commandSymbol].onCommandError(callback);
}
}