1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 | class SemanticCommand {
|
9 | constructor() {
|
10 | this._commands = new Array();
|
11 | }
|
12 | |
13 |
|
14 |
|
15 |
|
16 |
|
17 | add(command) {
|
18 | if (this._commands.map(c => c.id).includes(command.id)) {
|
19 | throw Error(`Command ${command.id} is already defined.`);
|
20 | }
|
21 | this._commands.push({
|
22 | isEnabled: () => true,
|
23 | rank: SemanticCommand.DEFAULT_RANK,
|
24 | ...command
|
25 | });
|
26 | }
|
27 | |
28 |
|
29 |
|
30 |
|
31 |
|
32 |
|
33 |
|
34 | getActiveCommandId(widget) {
|
35 | var _a;
|
36 | const commands = this._commands
|
37 | .filter(c => c.isEnabled(widget))
|
38 | .sort((a, b) => {
|
39 | const rankDelta = a.rank - b.rank;
|
40 | return rankDelta || (a.id < b.id ? -1 : 1);
|
41 | });
|
42 | const command = (_a = commands[0]) !== null && _a !== void 0 ? _a : { id: null };
|
43 | return command.id;
|
44 | }
|
45 | }
|
46 |
|
47 |
|
48 |
|
49 | SemanticCommand.DEFAULT_RANK = 500;
|
50 | export { SemanticCommand };
|
51 |
|
\ | No newline at end of file |