@omegagrid/commands 0.8.4 → 0.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/adapters/adapter.d.ts +19 -0
- package/dist/adapters/adapter.d.ts.map +1 -0
- package/dist/adapters/adapter.js +23 -0
- package/dist/adapters/adapter.js.map +1 -0
- package/dist/adapters/commandsFlowAdapter.d.ts +25 -0
- package/dist/adapters/commandsFlowAdapter.d.ts.map +1 -0
- package/dist/adapters/commandsFlowAdapter.js +61 -0
- package/dist/adapters/commandsFlowAdapter.js.map +1 -0
- package/dist/adapters/index.d.ts +3 -0
- package/dist/adapters/index.d.ts.map +1 -0
- package/dist/adapters/index.js +3 -0
- package/dist/adapters/index.js.map +1 -0
- package/dist/commandManager.d.ts +34 -0
- package/dist/commandManager.d.ts.map +1 -0
- package/dist/commandManager.js +101 -0
- package/dist/commandManager.js.map +1 -0
- package/dist/common.d.ts +5 -0
- package/dist/common.d.ts.map +1 -0
- package/dist/common.js +18 -0
- package/dist/common.js.map +1 -0
- package/dist/constants.d.ts +2 -0
- package/dist/constants.d.ts.map +1 -1
- package/dist/constants.js +1 -0
- package/dist/constants.js.map +1 -1
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -1
- package/dist/model/commands.d.ts +54 -22
- package/dist/model/commands.d.ts.map +1 -1
- package/dist/model/commands.js +71 -52
- package/dist/model/commands.js.map +1 -1
- package/dist/model/index.d.ts +0 -1
- package/dist/model/index.d.ts.map +1 -1
- package/dist/model/index.js +0 -1
- package/dist/model/index.js.map +1 -1
- package/dist/model/options.d.ts +6 -2
- package/dist/model/options.d.ts.map +1 -1
- package/dist/model/options.js +5 -1
- package/dist/model/options.js.map +1 -1
- package/dist/ui/commandWindow.d.ts +40 -27
- package/dist/ui/commandWindow.d.ts.map +1 -1
- package/dist/ui/commandWindow.js +249 -170
- package/dist/ui/commandWindow.js.map +1 -1
- package/dist/ui/commandWindow.style.d.ts.map +1 -1
- package/dist/ui/commandWindow.style.js +71 -9
- package/dist/ui/commandWindow.style.js.map +1 -1
- package/dist/ui/floatingCommandWindow.d.ts +7 -0
- package/dist/ui/floatingCommandWindow.d.ts.map +1 -0
- package/dist/ui/floatingCommandWindow.js +41 -0
- package/dist/ui/floatingCommandWindow.js.map +1 -0
- package/package.json +4 -2
- package/dist/model/adapter.d.ts +0 -9
- package/dist/model/adapter.d.ts.map +0 -1
- package/dist/model/adapter.js +0 -7
- package/dist/model/adapter.js.map +0 -1
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { ComponentAdapter, ComponentId } from "@omegagrid/core";
|
|
2
|
+
import { CommandSource, CommandGroupSource, CommandsSection, Command } from "../model/commands";
|
|
3
|
+
import { Options } from "../model/options";
|
|
4
|
+
import { CommandWindow } from "../ui";
|
|
5
|
+
export type CommandQuery = {
|
|
6
|
+
sectionId?: ComponentId;
|
|
7
|
+
groupId?: ComponentId;
|
|
8
|
+
filter?: string;
|
|
9
|
+
switches?: string[];
|
|
10
|
+
};
|
|
11
|
+
export declare abstract class CommandsAdapter extends ComponentAdapter<CommandWindow> {
|
|
12
|
+
protected filterCommands(commands: CommandSource[], query: CommandQuery): CommandSource[];
|
|
13
|
+
getGroups(_query?: CommandQuery): CommandGroupSource[] | Promise<CommandGroupSource[]>;
|
|
14
|
+
getCommands(_query: CommandQuery): CommandSource[] | Promise<CommandSource[]>;
|
|
15
|
+
getSections(_query?: CommandQuery): CommandsSection[] | Promise<CommandsSection[]>;
|
|
16
|
+
getOptions(): Options | Promise<Options> | null;
|
|
17
|
+
exec(_command: Command, _value?: string): void;
|
|
18
|
+
}
|
|
19
|
+
//# sourceMappingURL=adapter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"adapter.d.ts","sourceRoot":"","sources":["../../src/adapters/adapter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,WAAW,EAAS,MAAM,iBAAiB,CAAC;AACvE,OAAO,EAAE,aAAa,EAAE,kBAAkB,EAAE,eAAe,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAChG,OAAO,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAC3C,OAAO,EAAE,aAAa,EAAE,MAAM,OAAO,CAAC;AAEtC,MAAM,MAAM,YAAY,GAAG;IAC1B,SAAS,CAAC,EAAE,WAAW,CAAC;IACxB,OAAO,CAAC,EAAE,WAAW,CAAC;IACtB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAC;CACpB,CAAA;AAED,8BAAsB,eAAgB,SAAQ,gBAAgB,CAAC,aAAa,CAAC;IAE5E,SAAS,CAAC,cAAc,CAAC,QAAQ,EAAE,aAAa,EAAE,EAAE,KAAK,EAAE,YAAY,GAAG,aAAa,EAAE;IAMzF,SAAS,CAAC,MAAM,CAAC,EAAE,YAAY,GAAG,kBAAkB,EAAE,GAAC,OAAO,CAAC,kBAAkB,EAAE,CAAC;IAIpF,WAAW,CAAC,MAAM,EAAE,YAAY,GAAG,aAAa,EAAE,GAAC,OAAO,CAAC,aAAa,EAAE,CAAC;IAI3E,WAAW,CAAC,MAAM,CAAC,EAAE,YAAY,GAAG,eAAe,EAAE,GAAC,OAAO,CAAC,eAAe,EAAE,CAAC;IAIhF,UAAU,IAAI,OAAO,GAAC,OAAO,CAAC,OAAO,CAAC,GAAC,IAAI;IAI3C,IAAI,CAAC,QAAQ,EAAE,OAAO,EAAE,MAAM,CAAC,EAAE,MAAM;CAEvC"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { ComponentAdapter, utils } from "@omegagrid/core";
|
|
2
|
+
export class CommandsAdapter extends ComponentAdapter {
|
|
3
|
+
filterCommands(commands, query) {
|
|
4
|
+
if (!commands)
|
|
5
|
+
return [];
|
|
6
|
+
const filterRegex = query?.filter == null ? null : new RegExp(utils.escapeRegExp(query.filter), 'i');
|
|
7
|
+
return filterRegex == null ? commands : commands.filter(c => filterRegex.test(c.id || c.name || ''));
|
|
8
|
+
}
|
|
9
|
+
getGroups(_query) {
|
|
10
|
+
return [];
|
|
11
|
+
}
|
|
12
|
+
getCommands(_query) {
|
|
13
|
+
return [];
|
|
14
|
+
}
|
|
15
|
+
getSections(_query) {
|
|
16
|
+
return [{ id: 'default' }];
|
|
17
|
+
}
|
|
18
|
+
getOptions() {
|
|
19
|
+
return null;
|
|
20
|
+
}
|
|
21
|
+
exec(_command, _value) { }
|
|
22
|
+
}
|
|
23
|
+
//# sourceMappingURL=adapter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"adapter.js","sourceRoot":"","sources":["../../src/adapters/adapter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAe,KAAK,EAAE,MAAM,iBAAiB,CAAC;AAYvE,MAAM,OAAgB,eAAgB,SAAQ,gBAA+B;IAElE,cAAc,CAAC,QAAyB,EAAE,KAAmB;QACtE,IAAI,CAAC,QAAQ;YAAE,OAAO,EAAE,CAAC;QACzB,MAAM,WAAW,GAAG,KAAK,EAAE,MAAM,IAAI,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,MAAM,CAAC,KAAK,CAAC,YAAY,CAAC,KAAK,CAAC,MAAM,CAAC,EAAE,GAAG,CAAC,CAAC;QACrG,OAAO,WAAW,IAAI,IAAI,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,IAAI,CAAC,CAAC,IAAI,IAAI,EAAE,CAAC,CAAC,CAAC;IACtG,CAAC;IAED,SAAS,CAAC,MAAqB;QAC9B,OAAO,EAAE,CAAC;IACX,CAAC;IAED,WAAW,CAAC,MAAoB;QAC/B,OAAO,EAAE,CAAC;IACX,CAAC;IAED,WAAW,CAAC,MAAqB;QAChC,OAAO,CAAC,EAAC,EAAE,EAAE,SAAS,EAAC,CAAC,CAAC;IAC1B,CAAC;IAED,UAAU;QACT,OAAO,IAAI,CAAC;IACb,CAAC;IAED,IAAI,CAAC,QAAiB,EAAE,MAAe,IAAI,CAAC;CAE5C","sourcesContent":["import { ComponentAdapter, ComponentId, utils } from \"@omegagrid/core\";\nimport { CommandSource, CommandGroupSource, CommandsSection, Command } from \"../model/commands\";\nimport { Options } from \"../model/options\";\nimport { CommandWindow } from \"../ui\";\n\nexport type CommandQuery = {\n\tsectionId?: ComponentId,\n\tgroupId?: ComponentId,\n\tfilter?: string,\n\tswitches?: string[],\n}\n\nexport abstract class CommandsAdapter extends ComponentAdapter<CommandWindow> {\n\n\tprotected filterCommands(commands: CommandSource[], query: CommandQuery): CommandSource[] {\n\t\tif (!commands) return [];\n\t\tconst filterRegex = query?.filter == null ? null : new RegExp(utils.escapeRegExp(query.filter), 'i');\n\t\treturn filterRegex == null ? commands : commands.filter(c => filterRegex.test(c.id || c.name || ''));\n\t}\n\t\n\tgetGroups(_query?: CommandQuery): CommandGroupSource[]|Promise<CommandGroupSource[]> {\n\t\treturn [];\n\t}\n\t\n\tgetCommands(_query: CommandQuery): CommandSource[]|Promise<CommandSource[]> {\n\t\treturn [];\n\t}\n\n\tgetSections(_query?: CommandQuery): CommandsSection[]|Promise<CommandsSection[]> {\n\t\treturn [{id: 'default'}];\n\t}\n\n\tgetOptions(): Options|Promise<Options>|null {\n\t\treturn null;\n\t}\n\n\texec(_command: Command, _value?: string) { }\n\n}"]}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { CommandSource, Command, CommandMode } from "../model/commands";
|
|
2
|
+
import { Options } from "../model/options";
|
|
3
|
+
import { CommandQuery, CommandsAdapter } from "./adapter";
|
|
4
|
+
export type FlowCommandSource = CommandSource & {
|
|
5
|
+
next?: {
|
|
6
|
+
commands: FlowCommandSource[];
|
|
7
|
+
mode?: CommandMode;
|
|
8
|
+
text?: string;
|
|
9
|
+
};
|
|
10
|
+
};
|
|
11
|
+
export declare class CommandsFlowAdapter extends CommandsAdapter {
|
|
12
|
+
readonly map: Map<string, FlowCommandSource>;
|
|
13
|
+
private commandChain;
|
|
14
|
+
private _originalText;
|
|
15
|
+
private _originalMode;
|
|
16
|
+
private _commands;
|
|
17
|
+
get commands(): FlowCommandSource[];
|
|
18
|
+
set commands(value: FlowCommandSource[]);
|
|
19
|
+
constructor(commands: FlowCommandSource[]);
|
|
20
|
+
getCommands(query: CommandQuery): CommandSource[] | Promise<CommandSource[]>;
|
|
21
|
+
exec(command: Command, _value?: string): void;
|
|
22
|
+
reset(): void;
|
|
23
|
+
getOptions(): Options | Promise<Options> | null;
|
|
24
|
+
}
|
|
25
|
+
//# sourceMappingURL=commandsFlowAdapter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"commandsFlowAdapter.d.ts","sourceRoot":"","sources":["../../src/adapters/commandsFlowAdapter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AACxE,OAAO,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAC3C,OAAO,EAAE,YAAY,EAAE,eAAe,EAAE,MAAM,WAAW,CAAC;AAE1D,MAAM,MAAM,iBAAiB,GAAG,aAAa,GAAG;IAC/C,IAAI,CAAC,EAAE;QACN,QAAQ,EAAE,iBAAiB,EAAE,CAAC;QAC9B,IAAI,CAAC,EAAE,WAAW,CAAC;QACnB,IAAI,CAAC,EAAE,MAAM,CAAC;KACd,CAAC;CACF,CAAA;AAED,qBAAa,mBAAoB,SAAQ,eAAe;IAEvD,QAAQ,CAAC,GAAG,iCAAwC;IACpD,OAAO,CAAC,YAAY,CAAiB;IACrC,OAAO,CAAC,aAAa,CAAS;IAC9B,OAAO,CAAC,aAAa,CAAc;IAEnC,OAAO,CAAC,SAAS,CAA2B;IAC5C,IAAI,QAAQ,IAGQ,iBAAiB,EAAE,CADtC;IACD,IAAI,QAAQ,CAAC,KAAK,EAAE,iBAAiB,EAAE,EAUtC;gBAEW,QAAQ,EAAE,iBAAiB,EAAE;IAKzC,WAAW,CAAC,KAAK,EAAE,YAAY,GAAG,aAAa,EAAE,GAAC,OAAO,CAAC,aAAa,EAAE,CAAC;IAM1E,IAAI,CAAC,OAAO,EAAE,OAAO,EAAE,MAAM,CAAC,EAAE,MAAM;IAetC,KAAK;IAUL,UAAU,IAAI,OAAO,GAAC,OAAO,CAAC,OAAO,CAAC,GAAC,IAAI;CAI3C"}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { CommandsAdapter } from "./adapter";
|
|
2
|
+
export class CommandsFlowAdapter extends CommandsAdapter {
|
|
3
|
+
get commands() {
|
|
4
|
+
return this._commands;
|
|
5
|
+
}
|
|
6
|
+
set commands(value) {
|
|
7
|
+
this._commands = value;
|
|
8
|
+
this.map.clear();
|
|
9
|
+
const map = (commands) => {
|
|
10
|
+
commands.forEach(c => {
|
|
11
|
+
this.map.set(c.id ?? c.name, c);
|
|
12
|
+
if (c.next?.commands)
|
|
13
|
+
map(c.next.commands);
|
|
14
|
+
});
|
|
15
|
+
};
|
|
16
|
+
map(this._commands);
|
|
17
|
+
}
|
|
18
|
+
constructor(commands) {
|
|
19
|
+
super();
|
|
20
|
+
this.map = new Map();
|
|
21
|
+
this.commandChain = [];
|
|
22
|
+
this._commands = [];
|
|
23
|
+
this.commands = commands;
|
|
24
|
+
}
|
|
25
|
+
getCommands(query) {
|
|
26
|
+
const lastCommand = this.commandChain.length ? this.commandChain[this.commandChain.length - 1] : null;
|
|
27
|
+
const nextCommands = lastCommand ? this.map.get(lastCommand.id)?.next?.commands : null;
|
|
28
|
+
return this.filterCommands(nextCommands ? nextCommands : this.commands, query);
|
|
29
|
+
}
|
|
30
|
+
exec(command, _value) {
|
|
31
|
+
const next = this.map.get(command.id)?.next;
|
|
32
|
+
if (next?.commands?.length) {
|
|
33
|
+
this.commandChain.push(command);
|
|
34
|
+
if (this._originalText == null)
|
|
35
|
+
this._originalText = this.component.text;
|
|
36
|
+
if (this._originalMode == null)
|
|
37
|
+
this._originalMode = this.component.mode;
|
|
38
|
+
if (next.text != null)
|
|
39
|
+
this.component.text = next.text;
|
|
40
|
+
if (next.mode != null)
|
|
41
|
+
this.component.mode = next.mode;
|
|
42
|
+
}
|
|
43
|
+
else {
|
|
44
|
+
this.reset();
|
|
45
|
+
}
|
|
46
|
+
this.component.updateCommands();
|
|
47
|
+
}
|
|
48
|
+
reset() {
|
|
49
|
+
this.commandChain = [];
|
|
50
|
+
if (this.component) {
|
|
51
|
+
this.component.text = this._originalText;
|
|
52
|
+
this.component.mode = this._originalMode;
|
|
53
|
+
}
|
|
54
|
+
this._originalText = null;
|
|
55
|
+
this._originalMode = null;
|
|
56
|
+
}
|
|
57
|
+
getOptions() {
|
|
58
|
+
return null;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
//# sourceMappingURL=commandsFlowAdapter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"commandsFlowAdapter.js","sourceRoot":"","sources":["../../src/adapters/commandsFlowAdapter.ts"],"names":[],"mappings":"AAEA,OAAO,EAAgB,eAAe,EAAE,MAAM,WAAW,CAAC;AAU1D,MAAM,OAAO,mBAAoB,SAAQ,eAAe;IAQvD,IAAI,QAAQ;QACX,OAAO,IAAI,CAAC,SAAS,CAAC;IACvB,CAAC;IACD,IAAI,QAAQ,CAAC,KAA0B;QACtC,IAAI,CAAC,SAAS,GAAG,KAAK,CAAC;QACvB,IAAI,CAAC,GAAG,CAAC,KAAK,EAAE,CAAC;QACjB,MAAM,GAAG,GAAG,CAAC,QAA6B,EAAE,EAAE;YAC7C,QAAQ,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE;gBACpB,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,IAAI,CAAC,CAAC,IAAI,EA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IAAI,IAAI;gBAAE,IAAI,CAAC,aAAa,GAAG,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC;YACzE,IAAI,IAAI,CAAC,aAAa,IAAI,IAAI;gBAAE,IAAI,CAAC,aAAa,GAAG,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC;YACzE,IAAI,IAAI,CAAC,IAAI,IAAI,IAAI;gBAAE,IAAI,CAAC,SAAS,CAAC,IAAI,GAAG,IAAI,CAAC,IAAI,CAAC;YACvD,IAAI,IAAI,CAAC,IAAI,IAAI,IAAI;gBAAE,IAAI,CAAC,SAAS,CAAC,IAAI,GAAG,IAAI,CAAC,IAAI,CAAC;QACxD,CAAC;aAAM,CAAC;YACP,IAAI,CAAC,KAAK,EAAE,CAAC;QACd,CAAC;QAED,IAAI,CAAC,SAAS,CAAC,cAAc,EAAE,CAAC;IACjC,CAAC;IAED,KAAK;QACJ,IAAI,CAAC,YAAY,GAAG,EAAE,CAAC;QACvB,IAAI,IAAI,CAAC,SAAS,EAAE,CAAC;YACpB,IAAI,CAAC,SAAS,CAAC,IAAI,GAAG,IAAI,CAAC,aAAa,CAAC;YACzC,IAAI,CAAC,SAAS,CAAC,IAAI,GAAG,IAAI,CAAC,aAAa,CAAC;QAC1C,CAAC;QACD,IAAI,CAAC,aAAa,GAAG,IAAI,CAAC;QAC1B,IAAI,CAAC,aAAa,GAAG,IAAI,CAAC;IAC3B,CAAC;IAED,UAAU;QACT,OAAO,IAAI,CAAC;IACb,CAAC;CAED","sourcesContent":["import { CommandSource, Command, CommandMode } from \"../model/commands\";\nimport { Options } from \"../model/options\";\nimport { CommandQuery, CommandsAdapter } from \"./adapter\";\n\nexport type FlowCommandSource = CommandSource & {\n\tnext?: {\n\t\tcommands: FlowCommandSource[];\n\t\tmode?: CommandMode;\n\t\ttext?: string;\n\t};\n}\n\nexport class CommandsFlowAdapter extends CommandsAdapter {\n\n\treadonly map = new Map<string, FlowCommandSource>();\n\tprivate commandChain: Command[] = [];\n\tprivate _originalText: string;\n\tprivate _originalMode: CommandMode;\n\n\tprivate _commands: FlowCommandSource[] = [];\n\tget commands() {\n\t\treturn this._commands;\n\t}\n\tset commands(value: FlowCommandSource[]) {\n\t\tthis._commands = value;\n\t\tthis.map.clear();\n\t\tconst map = (commands: FlowCommandSource[]) => {\n\t\t\tcommands.forEach(c => {\n\t\t\t\tthis.map.set(c.id ?? c.name, c);\n\t\t\t\tif (c.next?.commands) map(c.next.commands);\n\t\t\t});\n\t\t};\n\t\tmap(this._commands);\n\t}\n\n\tconstructor(commands: FlowCommandSource[]) {\n\t\tsuper();\n\t\tthis.commands = commands;\n\t}\n\t\t\n\tgetCommands(query: CommandQuery): CommandSource[]|Promise<CommandSource[]> {\n\t\tconst lastCommand = this.commandChain.length ? this.commandChain[this.commandChain.length - 1] : null;\n\t\tconst nextCommands = lastCommand ? this.map.get(lastCommand.id)?.next?.commands : null;\n\t\treturn this.filterCommands(nextCommands ? nextCommands : this.commands, query);\n\t}\n\n\texec(command: Command, _value?: string) {\n\t\tconst next = this.map.get(command.id)?.next;\n\t\tif (next?.commands?.length) {\n\t\t\tthis.commandChain.push(command);\n\t\t\tif (this._originalText == null) this._originalText = this.component.text;\n\t\t\tif (this._originalMode == null) this._originalMode = this.component.mode;\n\t\t\tif (next.text != null) this.component.text = next.text;\n\t\t\tif (next.mode != null) this.component.mode = next.mode;\n\t\t} else {\n\t\t\tthis.reset();\n\t\t}\n\n\t\tthis.component.updateCommands();\n\t}\n\n\treset() {\n\t\tthis.commandChain = [];\n\t\tif (this.component) {\n\t\t\tthis.component.text = this._originalText;\n\t\t\tthis.component.mode = this._originalMode;\n\t\t}\n\t\tthis._originalText = null;\n\t\tthis._originalMode = null;\n\t}\n\n\tgetOptions(): Options|Promise<Options>|null {\n\t\treturn null;\n\t}\n\n}"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/adapters/index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAC;AAC1B,cAAc,uBAAuB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/adapters/index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAC;AAC1B,cAAc,uBAAuB,CAAC","sourcesContent":["export * from './adapter';\nexport * from './commandsFlowAdapter';"]}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { FloatingWindow } from "@omegagrid/core";
|
|
2
|
+
import { Command, CommandMode, CommandSource } from "./model";
|
|
3
|
+
import { CommandWindow } from "./ui";
|
|
4
|
+
import { LitElement } from "lit";
|
|
5
|
+
import { CommonCommandType } from "./common";
|
|
6
|
+
import { CommandsFlowAdapter, FlowCommandSource } from "./adapters";
|
|
7
|
+
export type OpenCommandsOptions = {
|
|
8
|
+
value?: string;
|
|
9
|
+
text?: string;
|
|
10
|
+
mode?: CommandMode;
|
|
11
|
+
content: CommandSource[] | CommonCommandType;
|
|
12
|
+
};
|
|
13
|
+
export declare class CommandManager {
|
|
14
|
+
readonly target: LitElement;
|
|
15
|
+
private _menu;
|
|
16
|
+
private _menuContainer;
|
|
17
|
+
private _resolveCallback;
|
|
18
|
+
private _rejectCallback;
|
|
19
|
+
private _adapter;
|
|
20
|
+
private _commands;
|
|
21
|
+
get commands(): FlowCommandSource[];
|
|
22
|
+
constructor(target: LitElement);
|
|
23
|
+
clear(): void;
|
|
24
|
+
add(commands: FlowCommandSource | FlowCommandSource[]): void;
|
|
25
|
+
get adapter(): CommandsFlowAdapter;
|
|
26
|
+
private cleanCallbacks;
|
|
27
|
+
private _onExec;
|
|
28
|
+
get menu(): CommandWindow;
|
|
29
|
+
get menuContainer(): FloatingWindow;
|
|
30
|
+
open(options?: OpenCommandsOptions): Promise<Command | null>;
|
|
31
|
+
close(): void;
|
|
32
|
+
updatePosition(): void;
|
|
33
|
+
}
|
|
34
|
+
//# sourceMappingURL=commandManager.d.ts.map
|
|
@@ -0,0 +1 @@
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OL,cAAc;CAMd"}
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import { dom, log } from "@omegagrid/core";
|
|
2
|
+
import { createCommands } from "./common";
|
|
3
|
+
import { CommandsFlowAdapter } from "./adapters";
|
|
4
|
+
export class CommandManager {
|
|
5
|
+
get commands() {
|
|
6
|
+
return this._commands;
|
|
7
|
+
}
|
|
8
|
+
constructor(target) {
|
|
9
|
+
this.target = target;
|
|
10
|
+
this._commands = [];
|
|
11
|
+
this._onExec = (e) => {
|
|
12
|
+
log.getLogger().info(`trigger command: ${e.command.id}`);
|
|
13
|
+
if (this._resolveCallback)
|
|
14
|
+
this._resolveCallback(e.command);
|
|
15
|
+
this._resolveCallback = null;
|
|
16
|
+
this._rejectCallback = null;
|
|
17
|
+
if (this.adapter.map.get(e.command.id)?.next == null) {
|
|
18
|
+
this.close();
|
|
19
|
+
}
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
clear() {
|
|
23
|
+
this._commands = [];
|
|
24
|
+
this._adapter = null;
|
|
25
|
+
}
|
|
26
|
+
add(commands) {
|
|
27
|
+
this._commands.push(...(Array.isArray(commands) ? commands : [commands]));
|
|
28
|
+
this._adapter = null;
|
|
29
|
+
}
|
|
30
|
+
get adapter() {
|
|
31
|
+
if (this._adapter)
|
|
32
|
+
return this._adapter;
|
|
33
|
+
this._adapter = new CommandsFlowAdapter(this._commands);
|
|
34
|
+
return this._adapter;
|
|
35
|
+
}
|
|
36
|
+
cleanCallbacks() {
|
|
37
|
+
if (this._rejectCallback)
|
|
38
|
+
this._rejectCallback();
|
|
39
|
+
this._resolveCallback = null;
|
|
40
|
+
this._rejectCallback = null;
|
|
41
|
+
}
|
|
42
|
+
get menu() {
|
|
43
|
+
return this._menu ?? (this._menu = dom.createElement('og-commands', {
|
|
44
|
+
listeners: [['command.exec', this._onExec]]
|
|
45
|
+
}));
|
|
46
|
+
}
|
|
47
|
+
get menuContainer() {
|
|
48
|
+
if (this._menuContainer)
|
|
49
|
+
return this._menuContainer;
|
|
50
|
+
this._menuContainer = dom.createElement('og-floating-window', {
|
|
51
|
+
style: { zIndex: '100000' },
|
|
52
|
+
listeners: [['hide', () => {
|
|
53
|
+
this.target?.focus();
|
|
54
|
+
this.adapter?.reset();
|
|
55
|
+
}]]
|
|
56
|
+
});
|
|
57
|
+
this.menu.slot = 'content';
|
|
58
|
+
this._menuContainer.appendChild(this.menu);
|
|
59
|
+
return this._menuContainer;
|
|
60
|
+
}
|
|
61
|
+
async open(options) {
|
|
62
|
+
log.getLogger().info('open menu');
|
|
63
|
+
this.target.shadowRoot.appendChild(this.menuContainer);
|
|
64
|
+
this.menuContainer.show();
|
|
65
|
+
options ?? (options = { content: null });
|
|
66
|
+
this.menu.text = options.text;
|
|
67
|
+
this.menu.value = options.value;
|
|
68
|
+
this.menu.mode = options.mode || 'search';
|
|
69
|
+
if (Array.isArray(options.content)) {
|
|
70
|
+
this.menu.commands = options.content;
|
|
71
|
+
this.menu.adapter = null;
|
|
72
|
+
}
|
|
73
|
+
else if (typeof options.content === 'string') {
|
|
74
|
+
this.menu.commands = createCommands(options.content);
|
|
75
|
+
this.menu.adapter = null;
|
|
76
|
+
}
|
|
77
|
+
else {
|
|
78
|
+
this.menu.commands = null;
|
|
79
|
+
this.menu.adapter = this.adapter;
|
|
80
|
+
}
|
|
81
|
+
await this.menu.updateComplete;
|
|
82
|
+
this.menu.focus();
|
|
83
|
+
this.updatePosition();
|
|
84
|
+
return new Promise((resolve, reject) => {
|
|
85
|
+
this._resolveCallback = resolve;
|
|
86
|
+
this._rejectCallback = reject;
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
close() {
|
|
90
|
+
this.menuContainer.hide(false);
|
|
91
|
+
this.menuContainer.remove();
|
|
92
|
+
this.cleanCallbacks();
|
|
93
|
+
this.target?.focus();
|
|
94
|
+
}
|
|
95
|
+
updatePosition() {
|
|
96
|
+
dom.setSize(this.menuContainer, { w: 0.9 * this.target.clientWidth });
|
|
97
|
+
dom.setCenterPosition(this.menuContainer, this.target, { horizontal: true, vertical: false });
|
|
98
|
+
dom.setPosition(this.menuContainer, { t: 50 });
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
//# sourceMappingURL=commandManager.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"commandManager.js","sourceRoot":"","sources":["../src/commandManager.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAkB,GAAG,EAAE,MAAM,iBAAiB,CAAC;AAI3D,OAAO,EAAE,cAAc,EAAqB,MAAM,UAAU,CAAC;AAC7D,OAAO,EAAE,mBAAmB,EAAqB,MAAM,YAAY,CAAC;AASpE,MAAM,OAAO,cAAc;IAS1B,IAAI,QAAQ;QACX,OAAO,IAAI,CAAC,SAAS,CAAC;IACvB,CAAC;IAED,YAAqB,MAAkB;QAAlB,WAAM,GAAN,MAAM,CAAY;QAN/B,cAAS,GAAwB,EAAE,CAAC;QA8BpC,YAAO,GAAG,CAAC,CAAe,EAAE,EAAE;YACrC,GAAG,CAAC,SAAS,EAAE,CAAC,IAAI,CAAC,oBAAoB,CAAC,CAAC,OAAO,CAAC,EAAE,EAAE,CAAC,CAAC;YACzD,IAAI,IAAI,CAAC,gBAAgB;gBAAE,IAAI,CAAC,gBAAgB,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC;YAC5D,IAAI,CAAC,gBAAgB,GAAG,IAAI,CAAC;YAC7B,IAAI,CAAC,eAAe,GAAG,IAAI,CAAC;YAE5B,IAAI,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC,OAAO,CAAC,EAAE,CAAC,EAAE,IAAI,IAAI,IAAI,EAAE,CAAC;gBACtD,IAAI,CAAC,KAAK,EAAE,CAAC;YACd,CAAC;QACF,CAAC,CAAA;IAjC0C,CAAC;IAE5C,KAAK;QACJ,IAAI,CAAC,SAAS,GAAG,EAAE,CAAC;QACpB,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC;I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C;YAC1B,IAAI,CAAC,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC,OAAO,CAAC;QAClC,CAAC;QAED,MAAM,IAAI,CAAC,IAAI,CAAC,cAAc,CAAC;QAC/B,IAAI,CAAC,IAAI,CAAC,KAAK,EAAE,CAAC;QAElB,IAAI,CAAC,cAAc,EAAE,CAAC;QAEtB,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;YACtC,IAAI,CAAC,gBAAgB,GAAG,OAAO,CAAC;YAChC,IAAI,CAAC,eAAe,GAAG,MAAM,CAAC;QAC/B,CAAC,CAAC,CAAC;IACJ,CAAC;IAED,KAAK;QACJ,IAAI,CAAC,aAAa,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QAC/B,IAAI,CAAC,aAAa,CAAC,MAAM,EAAE,CAAC;QAC5B,IAAI,CAAC,cAAc,EAAE,CAAC;QACtB,IAAI,CAAC,MAAM,EAAE,KAAK,EAAE,CAAC;IACtB,CAAC;IAED,cAAc;QACb,GAAG,CAAC,OAAO,CAAC,IAAI,CAAC,aAAa,EAAE,EAAC,CAAC,EAAE,GAAG,GAAG,IAAI,CAAC,MAAM,CAAC,WAAW,EAAC,CAAC,CAAC;QACpE,GAAG,CAAC,iBAAiB,CAAC,IAAI,CAAC,aAAa,EAAE,IAAI,CAAC,MAAM,EAAE,EAAC,UAAU,EAAE,IAAI,EAAE,QAAQ,EAAE,KAAK,EAAC,CAAC,CAAC;QAC5F,GAAG,CAAC,WAAW,CAAC,IAAI,CAAC,aAAa,EAAE,EAAC,CAAC,EAAE,EAAE,EAAC,CAAC,CAAC;IAC9C,CAAC;CAED","sourcesContent":["import { dom, FloatingWindow, log } from \"@omegagrid/core\";\nimport { Command, CommandMode, CommandSource } from \"./model\";\nimport { CommandEvent, CommandWindow } from \"./ui\";\nimport { LitElement } from \"lit\";\nimport { createCommands, CommonCommandType } from \"./common\";\nimport { CommandsFlowAdapter, FlowCommandSource } from \"./adapters\";\n\nexport type OpenCommandsOptions = {\n value?: string;\n text?: string;\n mode?: CommandMode;\n content: CommandSource[] | CommonCommandType;\n}\n\nexport class CommandManager {\n\n\tprivate _menu: CommandWindow;\n\tprivate _menuContainer: FloatingWindow;\n\tprivate _resolveCallback: (command: Command|null) => void;\n\tprivate _rejectCallback: () => void;\n\tprivate _adapter: CommandsFlowAdapter;\n\tprivate _commands: FlowCommandSource[] = [];\n\n\tget commands() {\n\t\treturn this._commands;\n\t}\n\t\n\tconstructor(readonly target: LitElement) { }\n\n\tclear() {\n\t\tthis._commands = [];\n\t\tthis._adapter = null;\n\t}\n\n\tadd(commands: FlowCommandSource|FlowCommandSource[]) {\n\t\tthis._commands.push(...(Array.isArray(commands) ? commands : [commands]));\n\t\tthis._adapter = null;\n\t}\n\n\tget adapter() {\n\t\tif (this._adapter) return this._adapter;\n\t\tthis._adapter = new CommandsFlowAdapter(this._commands);\n\t\treturn this._adapter;\n\t}\n\n\tprivate cleanCallbacks() {\n\t\tif (this._rejectCallback) this._rejectCallback();\n\t\tthis._resolveCallback = null;\n\t\tthis._rejectCallback = null;\n\t}\n\n\tprivate _onExec = (e: CommandEvent) => {\n\t\tlog.getLogger().info(`trigger command: ${e.command.id}`);\n\t\tif (this._resolveCallback) this._resolveCallback(e.command);\n\t\tthis._resolveCallback = null;\n\t\tthis._rejectCallback = null;\n\n\t\tif (this.adapter.map.get(e.command.id)?.next == null) {\n\t\t\tthis.close();\n\t\t}\n\t}\n\n\tget menu() {\n\t\treturn this._menu ?? (this._menu = dom.createElement<CommandWindow>('og-commands', {\n\t\t\tlisteners: [['command.exec', this._onExec]]\n\t\t}));\n\t}\n\t\n\tget menuContainer() {\n\t\tif (this._menuContainer) return this._menuContainer;\n\t\tthis._menuContainer = dom.createElement<FloatingWindow>('og-floating-window', {\n\t\t\tstyle: {zIndex: '100000'},\n\t\t\tlisteners: [['hide', () => {\n\t\t\t\tthis.target?.focus();\n\t\t\t\tthis.adapter?.reset();\n\t\t\t}]]\n\t\t});\n\t\tthis.menu.slot = 'content';\n\t\tthis._menuContainer.appendChild(this.menu);\n\t\treturn this._menuContainer;\n\t}\n\n\tasync open(options?: OpenCommandsOptions): Promise<Command|null> {\n\t\tlog.getLogger().info('open menu');\n\t\tthis.target.shadowRoot.appendChild(this.menuContainer);\n\t\tthis.menuContainer.show();\n\t\toptions ??= {content: null};\n\n\t\tthis.menu.text = options.text;\n\t\tthis.menu.value = options.value;\n\t\tthis.menu.mode = options.mode || 'search';\n\n\t\tif (Array.isArray(options.content)) {\n\t\t\tthis.menu.commands = options.content;\n\t\t\tthis.menu.adapter = null;\n\t\t} else if (typeof options.content === 'string') {\n\t\t\tthis.menu.commands = createCommands(options.content);\n\t\t\tthis.menu.adapter = null;\n\t\t} else {\n\t\t\tthis.menu.commands = null;\n\t\t\tthis.menu.adapter = this.adapter;\n\t\t}\n\n\t\tawait this.menu.updateComplete;\n\t\tthis.menu.focus();\n\n\t\tthis.updatePosition();\n\n\t\treturn new Promise((resolve, reject) => {\n\t\t\tthis._resolveCallback = resolve;\n\t\t\tthis._rejectCallback = reject;\n\t\t});\n\t}\n\n\tclose() {\n\t\tthis.menuContainer.hide(false);\n\t\tthis.menuContainer.remove();\n\t\tthis.cleanCallbacks();\n\t\tthis.target?.focus();\n\t}\n\n\tupdatePosition() {\n\t\tdom.setSize(this.menuContainer, {w: 0.9 * this.target.clientWidth});\n\t\tdom.setCenterPosition(this.menuContainer, this.target, {horizontal: true, vertical: false});\n\t\tdom.setPosition(this.menuContainer, {t: 50});\n\t}\n\n}"]}
|
package/dist/common.d.ts
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { CommandFunction, CommandSource } from '@omegagrid/commands';
|
|
2
|
+
export type CommonCommandType = 'yes_no' | 'apply' | 'ok';
|
|
3
|
+
export declare const commandFactories: Record<CommonCommandType, (exec?: CommandFunction) => CommandSource[]>;
|
|
4
|
+
export declare const createCommands: (type: CommonCommandType, exec?: CommandFunction) => CommandSource[];
|
|
5
|
+
//# sourceMappingURL=common.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"common.d.ts","sourceRoot":"","sources":["../src/common.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAErE,MAAM,MAAM,iBAAiB,GAAG,QAAQ,GAAG,OAAO,GAAG,IAAI,CAAC;AAE1D,eAAO,MAAM,gBAAgB,EAAE,MAAM,CAAC,iBAAiB,EAAE,CAAC,IAAI,CAAC,EAAE,eAAe,KAAK,aAAa,EAAE,CAanG,CAAC;AAEF,eAAO,MAAM,cAAc,GAAI,MAAM,iBAAiB,EAAE,OAAO,eAAe,KAAG,aAAa,EAE7F,CAAC"}
|
package/dist/common.js
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export const commandFactories = {
|
|
2
|
+
'yes_no': (exec) => [
|
|
3
|
+
{ id: 'Y', name: 'Yes', exec },
|
|
4
|
+
{ id: 'N', name: 'No', exec }
|
|
5
|
+
],
|
|
6
|
+
'apply': (exec) => [
|
|
7
|
+
{ id: 'apply', name: 'Apply', exec },
|
|
8
|
+
{ id: 'cancel', name: 'Cancel' }
|
|
9
|
+
],
|
|
10
|
+
'ok': (exec) => [
|
|
11
|
+
{ id: 'ok', name: 'OK', exec },
|
|
12
|
+
{ id: 'cancel', name: 'Cancel' }
|
|
13
|
+
]
|
|
14
|
+
};
|
|
15
|
+
export const createCommands = (type, exec) => {
|
|
16
|
+
return commandFactories[type](exec);
|
|
17
|
+
};
|
|
18
|
+
//# sourceMappingURL=common.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"common.js","sourceRoot":"","sources":["../src/common.ts"],"names":[],"mappings":"AAIA,MAAM,CAAC,MAAM,gBAAgB,GAA2E;IACvG,QAAQ,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC;QACnB,EAAC,EAAE,EAAE,GAAG,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAC;QAC5B,EAAC,EAAE,EAAE,GAAG,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAC;KAC3B;IACD,OAAO,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC;QAClB,EAAC,EAAE,EAAE,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,EAAC;QAClC,EAAC,EAAE,EAAE,QAAQ,EAAE,IAAI,EAAE,QAAQ,EAAC;KAC9B;IACD,IAAI,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC;QACf,EAAC,EAAE,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAC;QAC5B,EAAC,EAAE,EAAE,QAAQ,EAAE,IAAI,EAAE,QAAQ,EAAC;KAC9B;CACD,CAAC;AAEF,MAAM,CAAC,MAAM,cAAc,GAAG,CAAC,IAAuB,EAAE,IAAsB,EAAmB,EAAE;IAClG,OAAO,gBAAgB,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,CAAC;AACrC,CAAC,CAAC","sourcesContent":["import { CommandFunction, CommandSource } from '@omegagrid/commands';\n\nexport type CommonCommandType = 'yes_no' | 'apply' | 'ok';\n\nexport const commandFactories: Record<CommonCommandType, (exec?: CommandFunction) => CommandSource[]> = {\n\t'yes_no': (exec) => [\n\t\t{id: 'Y', name: 'Yes', exec},\n\t\t{id: 'N', name: 'No', exec}\n\t],\n\t'apply': (exec) => [\n\t\t{id: 'apply', name: 'Apply', exec},\n\t\t{id: 'cancel', name: 'Cancel'}\n\t],\n\t'ok': (exec) => [\n\t\t{id: 'ok', name: 'OK', exec},\n\t\t{id: 'cancel', name: 'Cancel'}\n\t]\n};\n\nexport const createCommands = (type: CommonCommandType, exec?: CommandFunction): CommandSource[] => {\n\treturn commandFactories[type](exec);\n};\n"]}
|
package/dist/constants.d.ts
CHANGED
|
@@ -41,7 +41,9 @@ declare const _default: {
|
|
|
41
41
|
DEFAULT_NUMBER_FORMAT: string;
|
|
42
42
|
BUTTON_HEIGHT: number;
|
|
43
43
|
FONT_SIZE: number;
|
|
44
|
+
FLOATING_WINDOW_MAX_WIDTH: number;
|
|
44
45
|
COMMAND_WINDOW_MAX_WIDTH: number;
|
|
46
|
+
COMMAND_ITEM_HEIGHT: number;
|
|
45
47
|
};
|
|
46
48
|
export default _default;
|
|
47
49
|
//# sourceMappingURL=constants.d.ts.map
|
package/dist/constants.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEA,wBAIC"}
|
package/dist/constants.js
CHANGED
package/dist/constants.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,IAAI,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAE7D,eAAe;IACd,wBAAwB,EAAE,GAAG;IAC7B,GAAG,aAAa;CAChB,CAAA","sourcesContent":["import { constants as coreConstants } from '@omegagrid/core';\n\nexport default {\n\tCOMMAND_WINDOW_MAX_WIDTH: 500,\n\t...coreConstants\n}"]}
|
|
1
|
+
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,IAAI,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAE7D,eAAe;IACd,wBAAwB,EAAE,GAAG;IAC7B,mBAAmB,EAAE,EAAE;IACvB,GAAG,aAAa;CAChB,CAAA","sourcesContent":["import { constants as coreConstants } from '@omegagrid/core';\n\nexport default {\n\tCOMMAND_WINDOW_MAX_WIDTH: 500,\n\tCOMMAND_ITEM_HEIGHT: 22,\n\t...coreConstants\n}"]}
|
package/dist/index.d.ts
CHANGED
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,MAAM,CAAC;AACrB,cAAc,SAAS,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,MAAM,CAAC;AACrB,cAAc,SAAS,CAAC;AACxB,cAAc,YAAY,CAAC;AAC3B,cAAc,kBAAkB,CAAC;AACjC,cAAc,UAAU,CAAC"}
|
package/dist/index.js
CHANGED
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,MAAM,CAAC;AACrB,cAAc,SAAS,CAAC;AACxB,2BAA2B","sourcesContent":["export * from './ui';\nexport * from './model';\n// export * from './types';"]}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,MAAM,CAAC;AACrB,cAAc,SAAS,CAAC;AACxB,cAAc,YAAY,CAAC;AAC3B,cAAc,kBAAkB,CAAC;AACjC,cAAc,UAAU,CAAC;AACzB,2BAA2B","sourcesContent":["export * from './ui';\nexport * from './model';\nexport * from './adapters';\nexport * from './commandManager';\nexport * from './common';\n// export * from './types';"]}
|
package/dist/model/commands.d.ts
CHANGED
|
@@ -1,34 +1,66 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
1
|
+
import { CustomProperties, IconSpec } from "@omegagrid/core";
|
|
2
|
+
import { TabItem } from "@omegagrid/tabs";
|
|
3
|
+
export type CommandSectionSwitch = {
|
|
4
|
+
key: string;
|
|
5
|
+
value: string;
|
|
6
|
+
checked?: boolean;
|
|
7
|
+
icon?: IconSpec | string;
|
|
8
|
+
};
|
|
9
|
+
export type CommandsSection = TabItem & {
|
|
10
|
+
placeholder?: string;
|
|
11
|
+
triggerCommand?: string;
|
|
12
|
+
switches?: CommandSectionSwitch[];
|
|
13
|
+
};
|
|
14
|
+
export type CommandMode = 'search' | 'input' | 'none';
|
|
15
|
+
export type CommandInput = {
|
|
16
|
+
id: string;
|
|
17
|
+
value?: string;
|
|
18
|
+
};
|
|
19
|
+
export type CommandFunction = (command: Command, value?: string) => void | Promise<void>;
|
|
20
|
+
export type CommandSource = {
|
|
21
|
+
id?: string;
|
|
22
|
+
name?: string;
|
|
23
|
+
value?: string;
|
|
24
|
+
group?: string;
|
|
25
|
+
exec?: CommandFunction;
|
|
26
|
+
props?: CustomProperties;
|
|
27
|
+
};
|
|
10
28
|
export declare class Command {
|
|
29
|
+
id: string;
|
|
30
|
+
name: string;
|
|
31
|
+
group: string;
|
|
32
|
+
props: CustomProperties;
|
|
33
|
+
private _exec;
|
|
34
|
+
constructor(source?: CommandSource);
|
|
35
|
+
populate(source: CommandSource): void;
|
|
36
|
+
getSourceData(): CommandSource;
|
|
37
|
+
exec(value?: string): void | Promise<void>;
|
|
38
|
+
}
|
|
39
|
+
export type CommandGroupSource = {
|
|
40
|
+
id: string;
|
|
41
|
+
name?: string;
|
|
42
|
+
commands?: CommandSource[];
|
|
43
|
+
};
|
|
44
|
+
export declare class CommandGroup {
|
|
45
|
+
readonly commands: Map<string, Command>;
|
|
11
46
|
readonly id: string;
|
|
12
47
|
readonly name: string;
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
constructor(options: Partial<Command>);
|
|
18
|
-
exec(...params: string[]): void;
|
|
48
|
+
open: boolean;
|
|
49
|
+
constructor(source: CommandGroupSource);
|
|
50
|
+
addCommand(command: Command | CommandSource): void;
|
|
51
|
+
getSourceData(): CommandGroupSource;
|
|
19
52
|
}
|
|
20
53
|
export declare class Commands {
|
|
21
|
-
readonly
|
|
54
|
+
readonly groups: Map<string, CommandGroup>;
|
|
22
55
|
get count(): number;
|
|
23
|
-
constructor(commands?:
|
|
56
|
+
constructor(commands?: CommandSource[]);
|
|
24
57
|
clear(): this;
|
|
25
|
-
|
|
58
|
+
registerGroup(group: CommandGroupSource): CommandGroup;
|
|
26
59
|
removeSection(sectionId: string): void;
|
|
27
|
-
register(command:
|
|
60
|
+
register(command: Command | CommandSource): void;
|
|
28
61
|
remove(name: string): void;
|
|
29
62
|
get(name: string): Command;
|
|
30
|
-
exec(
|
|
31
|
-
filter(term?: string,
|
|
32
|
-
merge(commands: Commands): Commands;
|
|
63
|
+
exec(id: string, value?: string): void | Promise<void>;
|
|
64
|
+
filter(term?: string, includeGroups?: boolean, emptyGroups?: boolean): (CommandGroup | Command)[];
|
|
33
65
|
}
|
|
34
66
|
//# sourceMappingURL=commands.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"commands.d.ts","sourceRoot":"","sources":["../../src/model/commands.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"commands.d.ts","sourceRoot":"","sources":["../../src/model/commands.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,QAAQ,EAAS,MAAM,iBAAiB,CAAC;AACpE,OAAO,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAE1C,MAAM,MAAM,oBAAoB,GAAG;IAClC,GAAG,EAAE,MAAM,CAAC;IACZ,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,IAAI,CAAC,EAAE,QAAQ,GAAC,MAAM,CAAC;CACvB,CAAA;AAED,MAAM,MAAM,eAAe,GAAG,OAAO,GAAG;IACvC,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,EAAE,oBAAoB,EAAE,CAAC;CAClC,CAAA;AAED,MAAM,MAA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