@omegagrid/commands 0.8.3 → 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
package/dist/ui/commandWindow.js
CHANGED
|
@@ -4,14 +4,14 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
4
4
|
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
5
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
6
|
};
|
|
7
|
-
import { Commands, Command,
|
|
8
|
-
import {
|
|
7
|
+
import { Commands, Command, CommandGroup, initOptions } from "../model";
|
|
8
|
+
import { ListSelectTrigger } from "@omegagrid/core";
|
|
9
9
|
import { LitElement, html } from 'lit';
|
|
10
|
-
import { customElement, property } from 'lit/decorators.js';
|
|
11
|
-
import { createRef, ref } from 'lit/directives/ref.js';
|
|
10
|
+
import { customElement, property, query, state } from 'lit/decorators.js';
|
|
12
11
|
import { debounce } from "ts-debounce";
|
|
13
12
|
import { style, itemStyle } from "./commandWindow.style";
|
|
14
|
-
import
|
|
13
|
+
import { styleMap } from "lit-html/directives/style-map.js";
|
|
14
|
+
import { msg } from "@omegagrid/localize";
|
|
15
15
|
export class CommandEvent extends Event {
|
|
16
16
|
constructor(type, args) {
|
|
17
17
|
super(`command.${type}`, { bubbles: true, composed: true });
|
|
@@ -20,86 +20,75 @@ export class CommandEvent extends Event {
|
|
|
20
20
|
}
|
|
21
21
|
}
|
|
22
22
|
let CommandWindow = class CommandWindow extends LitElement {
|
|
23
|
-
get
|
|
23
|
+
get activeSection() { return this.sections?.[this.activeSectionIndex]; }
|
|
24
24
|
get inputValue() { return this.input?.value ?? ''; }
|
|
25
|
-
get
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
if (this.mode == 'search') {
|
|
35
|
-
const command = this.commands.get(tokens[0])
|
|
36
|
-
?? this.visibleItems.find(item => item instanceof Command && item.name == tokens[0]);
|
|
37
|
-
if (!command)
|
|
38
|
-
return;
|
|
39
|
-
if (tokens.length - 1 < command.requiredParams) {
|
|
40
|
-
tokens.push('');
|
|
41
|
-
this.input.value = tokens.join(' > ');
|
|
42
|
-
this.input.focus();
|
|
43
|
-
}
|
|
44
|
-
else {
|
|
45
|
-
tokens.shift();
|
|
46
|
-
command.exec(...tokens);
|
|
47
|
-
if (dispatchEvent)
|
|
48
|
-
this.dispatchEvent(new CommandEvent('exec', {
|
|
49
|
-
command,
|
|
50
|
-
value: this.inputValue
|
|
51
|
-
}));
|
|
52
|
-
this.close();
|
|
53
|
-
}
|
|
25
|
+
get parsedInput() {
|
|
26
|
+
const input = this.inputValue;
|
|
27
|
+
const chunks = input.split(' ', 2);
|
|
28
|
+
if (chunks.length > 1) {
|
|
29
|
+
const section = (this.sections ?? []).findIndex(s => s?.triggerCommand == chunks[0]);
|
|
30
|
+
const value = section > -1 ? chunks[1] ?? '' : input;
|
|
31
|
+
return { section, value };
|
|
54
32
|
}
|
|
55
33
|
else {
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
34
|
+
return { section: -1, value: input };
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
get filterValue() {
|
|
38
|
+
return this.mode == 'search' ? this.parsedInput?.value ?? '' : '';
|
|
39
|
+
}
|
|
40
|
+
async exec(dispatchEvent = true) {
|
|
41
|
+
const input = this.parsedInput;
|
|
42
|
+
const command = this.visibleItems[this.list.selectedIndex];
|
|
43
|
+
if (!(command instanceof Command))
|
|
44
|
+
return;
|
|
45
|
+
this.clearFilter(false);
|
|
46
|
+
command.exec(input.value);
|
|
47
|
+
if (this.adapter) {
|
|
48
|
+
this.adapter.exec(command, input.value);
|
|
65
49
|
}
|
|
50
|
+
if (dispatchEvent)
|
|
51
|
+
this.dispatchEvent(new CommandEvent('exec', {
|
|
52
|
+
command: command,
|
|
53
|
+
section: this.sections.find(s => s.id === input.section),
|
|
54
|
+
value: input.value
|
|
55
|
+
}));
|
|
66
56
|
}
|
|
67
57
|
constructor() {
|
|
68
58
|
super();
|
|
69
|
-
this.
|
|
70
|
-
this.listRef = createRef();
|
|
59
|
+
this.options = initOptions();
|
|
71
60
|
/**
|
|
72
61
|
* search = commands are filtered by input value
|
|
73
62
|
* input = commands are not filtered, input is used to enter custom value
|
|
74
63
|
* none = no input, only command list is shown
|
|
75
64
|
*/
|
|
76
65
|
this.mode = 'search';
|
|
77
|
-
this.
|
|
78
|
-
this.triggerKey = 'F1';
|
|
66
|
+
this.sectionPosition = 'right';
|
|
79
67
|
this.placeholder = '';
|
|
80
|
-
this.
|
|
81
|
-
this.
|
|
68
|
+
this.showGroups = false;
|
|
69
|
+
this.model = new Commands();
|
|
70
|
+
this.sections = [{ id: 'default' }];
|
|
71
|
+
this.activeSectionIndex = 0;
|
|
72
|
+
this.noResults = false;
|
|
82
73
|
this._commandRenderer = (div, command) => {
|
|
83
|
-
return html
|
|
84
|
-
<div class="command">
|
|
85
|
-
${command.name}
|
|
86
|
-
</div>
|
|
87
|
-
`;
|
|
74
|
+
return html `<div class="command">${command.name}</div>`;
|
|
88
75
|
};
|
|
89
|
-
this.
|
|
76
|
+
this._groupRenderer = (div, group) => {
|
|
90
77
|
return html `
|
|
91
|
-
<div class="
|
|
92
|
-
<div class="
|
|
93
|
-
<og-icon icon="angle-${
|
|
78
|
+
<div class="group" @mousedown="${(e) => e.preventDefault()}">
|
|
79
|
+
<div class="group-toggle">
|
|
80
|
+
<og-icon icon="angle-${group.open ? 'down' : 'right'}"></og-icon>
|
|
94
81
|
</div>
|
|
95
|
-
|
|
96
|
-
|
|
82
|
+
|
|
83
|
+
<div class="group-text">
|
|
84
|
+
${group.name}
|
|
97
85
|
</div>
|
|
98
86
|
</div>
|
|
99
87
|
`;
|
|
100
88
|
};
|
|
101
89
|
this._onKeyDown = (e) => {
|
|
102
|
-
e.
|
|
90
|
+
if (e.key != 'Escape')
|
|
91
|
+
e.stopPropagation();
|
|
103
92
|
switch (e.key) {
|
|
104
93
|
case 'ArrowDown':
|
|
105
94
|
e.preventDefault();
|
|
@@ -111,185 +100,254 @@ let CommandWindow = class CommandWindow extends LitElement {
|
|
|
111
100
|
break;
|
|
112
101
|
case 'Enter':
|
|
113
102
|
e.preventDefault();
|
|
114
|
-
if (this.visibleItems[this.list.selectedIndex] instanceof
|
|
115
|
-
this.
|
|
103
|
+
if (this.visibleItems[this.list.selectedIndex] instanceof CommandGroup)
|
|
104
|
+
this.toggleGroup(this.visibleItems[this.list.selectedIndex].id);
|
|
116
105
|
else
|
|
117
106
|
this.exec();
|
|
118
107
|
break;
|
|
119
|
-
case 'Escape':
|
|
120
|
-
case this.triggerKey:
|
|
121
|
-
e.preventDefault();
|
|
122
|
-
this.close();
|
|
123
|
-
break;
|
|
124
108
|
}
|
|
125
109
|
};
|
|
126
|
-
this.
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
}
|
|
110
|
+
this._debounceInput = debounce(() => {
|
|
111
|
+
if (this.mode != 'search')
|
|
112
|
+
return;
|
|
113
|
+
const input = this.parsedInput;
|
|
114
|
+
if (input.section > -1) {
|
|
115
|
+
this.activeSectionIndex = input.section;
|
|
116
|
+
this.input.value = '';
|
|
134
117
|
}
|
|
118
|
+
this.updateCommands();
|
|
135
119
|
});
|
|
136
|
-
this.
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
120
|
+
this._onInput = (e) => {
|
|
121
|
+
e.stopPropagation();
|
|
122
|
+
this._debounceInput();
|
|
123
|
+
};
|
|
124
|
+
this._onSectionSelect = (e) => {
|
|
125
|
+
if (this.activeSectionIndex == e.index)
|
|
126
|
+
return;
|
|
127
|
+
this.activeSectionIndex = e.index;
|
|
128
|
+
if (this.activeSection?.triggerCommand != null) {
|
|
129
|
+
//this.input.value = this.activeSection?.triggerCommand + ' ';
|
|
130
|
+
this.updateCommands();
|
|
131
|
+
}
|
|
132
|
+
this.focus();
|
|
133
|
+
};
|
|
134
|
+
this._onDropdownChange = (e) => {
|
|
135
|
+
this.activeSectionIndex = this.sections.findIndex(s => s.id === this.dropdown.value);
|
|
136
|
+
if (this.activeSection?.triggerCommand != null) {
|
|
137
|
+
//this.input.value = this.activeSection?.triggerCommand + ' ';
|
|
138
|
+
this.updateCommands();
|
|
141
139
|
}
|
|
140
|
+
this.focus();
|
|
142
141
|
};
|
|
143
142
|
this._onSelect = (e) => {
|
|
144
143
|
const item = this.visibleItems[e.index];
|
|
145
144
|
if (item instanceof Command) {
|
|
146
145
|
if (this.mode == 'search')
|
|
147
146
|
this.input.value = item.name;
|
|
148
|
-
if (e.trigger == ListSelectTrigger.Click || e.trigger == ListSelectTrigger.Enter)
|
|
147
|
+
if (e.trigger == ListSelectTrigger.Click || e.trigger == ListSelectTrigger.Enter) {
|
|
149
148
|
this.exec();
|
|
149
|
+
}
|
|
150
150
|
}
|
|
151
151
|
else {
|
|
152
152
|
this.input.value = '';
|
|
153
153
|
if (e.trigger == ListSelectTrigger.Click || e.trigger == ListSelectTrigger.Enter) {
|
|
154
|
-
this.
|
|
154
|
+
this.toggleGroup(item.id);
|
|
155
155
|
}
|
|
156
156
|
}
|
|
157
157
|
setTimeout(() => this.input.focus());
|
|
158
158
|
};
|
|
159
|
-
this._itemRenderer = (div, index) => {
|
|
160
|
-
return this.visibleItems[index] instanceof
|
|
161
|
-
? this.
|
|
162
|
-
: this._commandRenderer(div, this.visibleItems[index]);
|
|
159
|
+
this._itemRenderer = (div, index, opts) => {
|
|
160
|
+
return this.visibleItems[index] instanceof CommandGroup
|
|
161
|
+
? this._groupRenderer(div, this.visibleItems[index], opts)
|
|
162
|
+
: this._commandRenderer(div, this.visibleItems[index], opts);
|
|
163
163
|
};
|
|
164
|
+
this.renderTabs = () => this.sections?.length > 1 ? html `
|
|
165
|
+
<og-container
|
|
166
|
+
.horizontalSliderPosition="${this.sectionPosition == 'top' ? 'bottom' : 'top'}"
|
|
167
|
+
scrollMode="horizontal"
|
|
168
|
+
sliderSize="4">
|
|
169
|
+
<og-tabs
|
|
170
|
+
slot="content"
|
|
171
|
+
class="tabs"
|
|
172
|
+
tabSize="stretch"
|
|
173
|
+
tabAlign="center"
|
|
174
|
+
style="${styleMap({ borderTop: this.sectionPosition == 'bottom' ? '1px solid var(--og-border)' : '' })}"
|
|
175
|
+
@tab.select="${this._onSectionSelect}"
|
|
176
|
+
.position="${this.sectionPosition == 'top' ? 'top' : 'bottom'}"
|
|
177
|
+
.selectedIndex="${this.activeSectionIndex}"
|
|
178
|
+
.items="${this.sections.map(section => ({ ...section, title: this.getSectionTitle(section) }))}">
|
|
179
|
+
</og-tabs>
|
|
180
|
+
</og-container>
|
|
181
|
+
` : '';
|
|
182
|
+
this.renderDropdown = () => this.sections?.length > 1 ? html `
|
|
183
|
+
<og-dropdown-list
|
|
184
|
+
color="transparent"
|
|
185
|
+
.value="${this.activeSection?.id}"
|
|
186
|
+
@change="${this._onDropdownChange}"
|
|
187
|
+
.items="${this.sections.map(section => ({
|
|
188
|
+
k: section.id,
|
|
189
|
+
v: this.getSectionTitle(section),
|
|
190
|
+
icon: section.icon
|
|
191
|
+
}))}">
|
|
192
|
+
</og-dropdown-list>
|
|
193
|
+
` : '';
|
|
194
|
+
this.renderSwitches = () => this.activeSection?.switches?.length > 0 ? html `
|
|
195
|
+
<div class="switches">
|
|
196
|
+
${this.activeSection.switches.map((s) => html `
|
|
197
|
+
<og-button
|
|
198
|
+
type="toggle"
|
|
199
|
+
.text="${s.value}"
|
|
200
|
+
.state="${s.checked ? 'checked' : 'unchecked'}"
|
|
201
|
+
@click="${(e) => {
|
|
202
|
+
s.checked = e.target.state === 'checked';
|
|
203
|
+
this.focus();
|
|
204
|
+
this.updateCommands();
|
|
205
|
+
}}">
|
|
206
|
+
</og-button>
|
|
207
|
+
`)}
|
|
208
|
+
</div>
|
|
209
|
+
` : '';
|
|
164
210
|
this.render = () => html `
|
|
165
211
|
<div class="input">
|
|
166
|
-
|
|
212
|
+
${this.sectionPosition == 'left' ? this.renderDropdown() : ''}
|
|
213
|
+
|
|
214
|
+
<input
|
|
167
215
|
type="text"
|
|
216
|
+
@input="${this._onInput}"
|
|
168
217
|
.placeholder="${this.placeholder}"
|
|
169
|
-
.value="${this.value}">
|
|
218
|
+
.value="${this.value ?? ''}">
|
|
219
|
+
|
|
220
|
+
${this.sectionPosition == 'right' ? this.renderDropdown() : ''}
|
|
170
221
|
</div>
|
|
171
222
|
|
|
223
|
+
${this.sectionPosition != 'bottom' ? this.renderSwitches() : ''}
|
|
224
|
+
|
|
172
225
|
${this.text != null ? html `<div class="text">${this.text}</div>` : ''}
|
|
173
|
-
|
|
226
|
+
|
|
227
|
+
${this.sectionPosition == 'top' ? this.renderTabs() : ''}
|
|
228
|
+
|
|
229
|
+
${this.noResults ? html `
|
|
230
|
+
<div class="no-results">${msg('No results found')}</div>
|
|
231
|
+
` : ''}
|
|
232
|
+
|
|
174
233
|
<div class="list">
|
|
175
|
-
<og-list
|
|
234
|
+
<og-list
|
|
235
|
+
arrowEvents
|
|
176
236
|
maxHeight="300"
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
lineHeight="
|
|
180
|
-
|
|
237
|
+
?dynamicItemHeight="${this.options?.commandRenderer != null}"
|
|
238
|
+
.customStyle="${[this.options?.itemStyle, itemStyle]}"
|
|
239
|
+
.lineHeight="${this.options.itemHeight - 2}"
|
|
240
|
+
.itemHeight="${this.options.itemHeight}"
|
|
241
|
+
.itemRenderer="${this._itemRenderer}"
|
|
242
|
+
@select="${this._onSelect}">
|
|
181
243
|
</og-list>
|
|
182
244
|
</div>
|
|
245
|
+
|
|
246
|
+
${this.sectionPosition == 'bottom' ? this.renderSwitches() : ''}
|
|
247
|
+
|
|
248
|
+
${this.sectionPosition == 'bottom' ? this.renderTabs() : ''}
|
|
183
249
|
`;
|
|
184
250
|
this.addEventListener('click', e => e.stopPropagation());
|
|
185
|
-
this.addEventListener('keyup', this._onKeyUp);
|
|
186
251
|
this.addEventListener('keydown', this._onKeyDown);
|
|
187
|
-
this.addEventListener('blur', () => this.close());
|
|
188
|
-
}
|
|
189
|
-
async open(dispatchEvent = true) {
|
|
190
|
-
if (!this.target)
|
|
191
|
-
throw new Error('target element not set');
|
|
192
|
-
dom.showElement(this);
|
|
193
|
-
this.input.value = this.value ?? '';
|
|
194
|
-
if (this.requireUpdateCommands) {
|
|
195
|
-
this.requireUpdateCommands = false;
|
|
196
|
-
await this.updateCommands();
|
|
197
|
-
}
|
|
198
|
-
this.input.focus();
|
|
199
|
-
this.visibleItems = this.commands.filter(null, this.showSections);
|
|
200
|
-
this.updatePosition();
|
|
201
|
-
if (dispatchEvent)
|
|
202
|
-
this.dispatchEvent(new CommandEvent('open'));
|
|
203
|
-
}
|
|
204
|
-
close(dispatchEvent = true) {
|
|
205
|
-
if (this.target) {
|
|
206
|
-
dom.hideElement(this);
|
|
207
|
-
this.target.focus();
|
|
208
|
-
if (dispatchEvent)
|
|
209
|
-
this.dispatchEvent(new CommandEvent('close'));
|
|
210
|
-
}
|
|
211
252
|
}
|
|
212
253
|
connectedCallback() {
|
|
213
254
|
super.connectedCallback();
|
|
214
255
|
this.tabIndex = 0;
|
|
215
256
|
}
|
|
257
|
+
focus() {
|
|
258
|
+
this.input?.focus();
|
|
259
|
+
}
|
|
260
|
+
clearFilter(updateCommands = true) {
|
|
261
|
+
this.input.value = '';
|
|
262
|
+
this.focus();
|
|
263
|
+
if (updateCommands)
|
|
264
|
+
this.updateCommands();
|
|
265
|
+
}
|
|
216
266
|
async willUpdate(props) {
|
|
217
267
|
if (props.has('adapter') && this.adapter) {
|
|
218
|
-
|
|
268
|
+
this.adapter.attach(this);
|
|
269
|
+
const [sections, options] = await Promise.all([this.adapter.getSections(), this.adapter.getOptions()]);
|
|
270
|
+
this.sections = sections;
|
|
219
271
|
if (options)
|
|
220
|
-
this.options = options;
|
|
272
|
+
this.options = initOptions(options, this.options);
|
|
273
|
+
}
|
|
274
|
+
else if (props.has('commands') && this.commands) {
|
|
275
|
+
this.model.clear();
|
|
276
|
+
this.commands.forEach(c => this.model.register(c));
|
|
221
277
|
}
|
|
222
278
|
if (this.options) {
|
|
223
279
|
if (this.options.commandRenderer)
|
|
224
280
|
this._commandRenderer = this.options.commandRenderer;
|
|
225
|
-
if (this.options.
|
|
226
|
-
this.
|
|
281
|
+
if (this.options.groupRenderer)
|
|
282
|
+
this._groupRenderer = this.options.groupRenderer;
|
|
227
283
|
}
|
|
228
284
|
}
|
|
229
285
|
async updated(props) {
|
|
230
|
-
if (props.has('
|
|
231
|
-
const oldTarget = props.get('target');
|
|
232
|
-
if (oldTarget)
|
|
233
|
-
oldTarget.removeEventListener('keydown', this._onTargetKeyDown);
|
|
234
|
-
if (this.target)
|
|
235
|
-
this.target.addEventListener('keydown', this._onTargetKeyDown);
|
|
236
|
-
}
|
|
237
|
-
if (props.has('adapter'))
|
|
238
|
-
this.requireUpdateCommands = true;
|
|
239
|
-
if (props.has('commands'))
|
|
286
|
+
if (props.has('commands') || props.has('adapter') || props.has('model')) {
|
|
240
287
|
await this.updateCommands();
|
|
241
|
-
|
|
242
|
-
}
|
|
243
|
-
firstUpdated() {
|
|
244
|
-
this.list.itemRenderer = this._itemRenderer;
|
|
245
|
-
this.list.addEventListener('select', this._onSelect);
|
|
288
|
+
}
|
|
246
289
|
}
|
|
247
290
|
async updateCommands() {
|
|
248
291
|
if (this.adapter) {
|
|
249
|
-
this.
|
|
250
|
-
const
|
|
251
|
-
|
|
252
|
-
|
|
292
|
+
this.model.clear();
|
|
293
|
+
const switches = this.activeSection?.switches?.filter(s => s.checked).map(s => s.key) || [];
|
|
294
|
+
const [groups, commands] = (await Promise.all([this.adapter.getGroups({
|
|
295
|
+
sectionId: this.activeSection?.id,
|
|
296
|
+
filter: this.filterValue,
|
|
297
|
+
switches
|
|
298
|
+
}), this.adapter.getCommands({
|
|
299
|
+
sectionId: this.activeSection?.id,
|
|
300
|
+
filter: this.filterValue,
|
|
301
|
+
switches
|
|
302
|
+
})]));
|
|
303
|
+
groups?.forEach(group => this.model.registerGroup(group));
|
|
304
|
+
commands?.forEach(command => this.model.register(command));
|
|
305
|
+
this.visibleItems = this.model.filter(null, this.showGroups, true);
|
|
253
306
|
}
|
|
254
307
|
else {
|
|
255
|
-
this.visibleItems = this.
|
|
308
|
+
this.visibleItems = this.model.filter(this.filterValue, this.showGroups);
|
|
256
309
|
}
|
|
310
|
+
this.placeholder = this.activeSection?.placeholder || '';
|
|
311
|
+
this.list.reset();
|
|
257
312
|
this.list.size = this.visibleItems.length;
|
|
258
|
-
this.list.selectedIndex = this.
|
|
313
|
+
this.list.selectedIndex = this.visibleItems.findIndex(item => item instanceof Command) ?? 0;
|
|
259
314
|
this.list.renderItems(true);
|
|
315
|
+
this.noResults = this.visibleItems.length == 0;
|
|
260
316
|
await this.list.updateComplete;
|
|
261
317
|
}
|
|
262
|
-
async
|
|
263
|
-
const
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
318
|
+
async toggleGroup(groupId) {
|
|
319
|
+
const group = this.model.groups.get(groupId);
|
|
320
|
+
this.list.reset();
|
|
321
|
+
if (group.open) {
|
|
322
|
+
group.open = false;
|
|
323
|
+
this.visibleItems = this.model.filter(this.filterValue, this.showGroups, true);
|
|
267
324
|
this.list.size = this.visibleItems.length;
|
|
268
325
|
}
|
|
269
326
|
else {
|
|
270
|
-
|
|
327
|
+
group.open = true;
|
|
271
328
|
if (this.adapter) {
|
|
272
|
-
const commands = (await Promise.all([this.adapter.getCommands(
|
|
329
|
+
const commands = (await Promise.all([this.adapter.getCommands({
|
|
330
|
+
sectionId: this.activeSection?.id,
|
|
331
|
+
groupId,
|
|
332
|
+
filter: this.filterValue
|
|
333
|
+
})]))[0];
|
|
273
334
|
if (commands.length > 0) {
|
|
274
|
-
|
|
275
|
-
commands.forEach(c =>
|
|
335
|
+
group.commands.clear();
|
|
336
|
+
commands.forEach(c => {
|
|
337
|
+
if (!c.group || c.group == groupId)
|
|
338
|
+
group.addCommand(c);
|
|
339
|
+
});
|
|
276
340
|
}
|
|
277
|
-
this.visibleItems = this.
|
|
341
|
+
this.visibleItems = this.model.filter(null, this.showGroups, true);
|
|
278
342
|
}
|
|
279
343
|
else {
|
|
280
|
-
this.visibleItems = this.
|
|
344
|
+
this.visibleItems = this.model.filter(this.filterValue, this.showGroups, true);
|
|
281
345
|
}
|
|
282
346
|
}
|
|
283
347
|
this.list.size = this.visibleItems.length;
|
|
284
348
|
}
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
dom.setSize(this, {
|
|
288
|
-
w: Math.min(constants.COMMAND_WINDOW_MAX_WIDTH, 0.9 * this.target.clientWidth)
|
|
289
|
-
});
|
|
290
|
-
dom.setCenterPosition(this, this.target, { horizontal: true, vertical: false });
|
|
291
|
-
dom.setPosition(this, { t: 100 });
|
|
292
|
-
}
|
|
349
|
+
getSectionTitle(section) {
|
|
350
|
+
return (section.title ?? section.id) + (section.triggerCommand ? ` (${section.triggerCommand})` : '');
|
|
293
351
|
}
|
|
294
352
|
};
|
|
295
353
|
CommandWindow.styles = [style];
|
|
@@ -302,11 +360,14 @@ __decorate([
|
|
|
302
360
|
__decorate([
|
|
303
361
|
property({ type: String })
|
|
304
362
|
], CommandWindow.prototype, "value", void 0);
|
|
363
|
+
__decorate([
|
|
364
|
+
property({ type: String, reflect: true })
|
|
365
|
+
], CommandWindow.prototype, "sectionPosition", void 0);
|
|
305
366
|
__decorate([
|
|
306
367
|
property({ type: String })
|
|
307
368
|
], CommandWindow.prototype, "text", void 0);
|
|
308
369
|
__decorate([
|
|
309
|
-
property({ type:
|
|
370
|
+
property({ type: Array })
|
|
310
371
|
], CommandWindow.prototype, "commands", void 0);
|
|
311
372
|
__decorate([
|
|
312
373
|
property({ type: Object })
|
|
@@ -314,15 +375,33 @@ __decorate([
|
|
|
314
375
|
__decorate([
|
|
315
376
|
property({ type: Object })
|
|
316
377
|
], CommandWindow.prototype, "target", void 0);
|
|
317
|
-
__decorate([
|
|
318
|
-
property({ type: String })
|
|
319
|
-
], CommandWindow.prototype, "triggerKey", void 0);
|
|
320
378
|
__decorate([
|
|
321
379
|
property({ type: String })
|
|
322
380
|
], CommandWindow.prototype, "placeholder", void 0);
|
|
323
381
|
__decorate([
|
|
324
382
|
property({ type: Boolean })
|
|
325
|
-
], CommandWindow.prototype, "
|
|
383
|
+
], CommandWindow.prototype, "showGroups", void 0);
|
|
384
|
+
__decorate([
|
|
385
|
+
property({ type: Object })
|
|
386
|
+
], CommandWindow.prototype, "model", void 0);
|
|
387
|
+
__decorate([
|
|
388
|
+
state()
|
|
389
|
+
], CommandWindow.prototype, "sections", void 0);
|
|
390
|
+
__decorate([
|
|
391
|
+
state()
|
|
392
|
+
], CommandWindow.prototype, "activeSectionIndex", void 0);
|
|
393
|
+
__decorate([
|
|
394
|
+
state()
|
|
395
|
+
], CommandWindow.prototype, "noResults", void 0);
|
|
396
|
+
__decorate([
|
|
397
|
+
query('og-list')
|
|
398
|
+
], CommandWindow.prototype, "list", void 0);
|
|
399
|
+
__decorate([
|
|
400
|
+
query('input')
|
|
401
|
+
], CommandWindow.prototype, "input", void 0);
|
|
402
|
+
__decorate([
|
|
403
|
+
query('og-dropdown-list')
|
|
404
|
+
], CommandWindow.prototype, "dropdown", void 0);
|
|
326
405
|
CommandWindow = __decorate([
|
|
327
406
|
customElement('og-commands')
|
|
328
407
|
], CommandWindow);
|