1 | "use strict";
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 | Object.defineProperty(exports, "__esModule", { value: true });
|
18 | exports.SelectionCommandHandler = void 0;
|
19 | class SelectionCommandHandler {
|
20 | constructor(selectionService, toSelection, options) {
|
21 | this.selectionService = selectionService;
|
22 | this.toSelection = toSelection;
|
23 | this.options = options;
|
24 | }
|
25 | execute(...args) {
|
26 | const selection = this.getSelection(...args);
|
27 | return selection ? this.options.execute(selection, ...args) : undefined;
|
28 | }
|
29 | isVisible(...args) {
|
30 | const selection = this.getSelection(...args);
|
31 | return !!selection && (!this.options.isVisible || this.options.isVisible(selection, ...args));
|
32 | }
|
33 | isEnabled(...args) {
|
34 | const selection = this.getSelection(...args);
|
35 | return !!selection && (!this.options.isEnabled || this.options.isEnabled(selection, ...args));
|
36 | }
|
37 | isMulti() {
|
38 | return this.options && !!this.options.multi;
|
39 | }
|
40 | getSelection(...args) {
|
41 | const givenSelection = args.length && this.toSelection(args[0]);
|
42 | if (givenSelection) {
|
43 | return this.isMulti() ? [givenSelection] : givenSelection;
|
44 | }
|
45 | const globalSelection = this.getSingleSelection(this.selectionService.selection);
|
46 | if (this.isMulti()) {
|
47 | return this.getMultiSelection(globalSelection);
|
48 | }
|
49 | return this.getSingleSelection(globalSelection);
|
50 | }
|
51 | getSingleSelection(arg) {
|
52 | let selection = this.toSelection(arg);
|
53 | if (selection) {
|
54 | return selection;
|
55 | }
|
56 | if (Array.isArray(arg)) {
|
57 | for (const element of arg) {
|
58 | selection = this.toSelection(element);
|
59 | if (selection) {
|
60 | return selection;
|
61 | }
|
62 | }
|
63 | }
|
64 | return undefined;
|
65 | }
|
66 | getMultiSelection(arg) {
|
67 | let selection = this.toSelection(arg);
|
68 | if (selection) {
|
69 | return [selection];
|
70 | }
|
71 | const result = [];
|
72 | if (Array.isArray(arg)) {
|
73 | for (const element of arg) {
|
74 | selection = this.toSelection(element);
|
75 | if (selection) {
|
76 | result.push(selection);
|
77 | }
|
78 | }
|
79 | }
|
80 | return result.length ? result : undefined;
|
81 | }
|
82 | }
|
83 | exports.SelectionCommandHandler = SelectionCommandHandler;
|
84 |
|
\ | No newline at end of file |