@omegagrid/commands 0.8.4 → 0.9.1
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 +100 -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 +246 -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 +72 -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,251 @@ 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
|
+
this.updateCommands();
|
|
129
|
+
this.focus();
|
|
130
|
+
};
|
|
131
|
+
this._onDropdownChange = (e) => {
|
|
132
|
+
this.activeSectionIndex = this.sections.findIndex(s => s.id === this.dropdown.value);
|
|
133
|
+
if (this.activeSection?.triggerCommand != null) {
|
|
134
|
+
//this.input.value = this.activeSection?.triggerCommand + ' ';
|
|
135
|
+
this.updateCommands();
|
|
141
136
|
}
|
|
137
|
+
this.focus();
|
|
142
138
|
};
|
|
143
139
|
this._onSelect = (e) => {
|
|
144
140
|
const item = this.visibleItems[e.index];
|
|
145
141
|
if (item instanceof Command) {
|
|
146
142
|
if (this.mode == 'search')
|
|
147
143
|
this.input.value = item.name;
|
|
148
|
-
if (e.trigger == ListSelectTrigger.Click || e.trigger == ListSelectTrigger.Enter)
|
|
144
|
+
if (e.trigger == ListSelectTrigger.Click || e.trigger == ListSelectTrigger.Enter) {
|
|
149
145
|
this.exec();
|
|
146
|
+
}
|
|
150
147
|
}
|
|
151
148
|
else {
|
|
152
149
|
this.input.value = '';
|
|
153
150
|
if (e.trigger == ListSelectTrigger.Click || e.trigger == ListSelectTrigger.Enter) {
|
|
154
|
-
this.
|
|
151
|
+
this.toggleGroup(item.id);
|
|
155
152
|
}
|
|
156
153
|
}
|
|
157
154
|
setTimeout(() => this.input.focus());
|
|
158
155
|
};
|
|
159
|
-
this._itemRenderer = (div, index) => {
|
|
160
|
-
return this.visibleItems[index] instanceof
|
|
161
|
-
? this.
|
|
162
|
-
: this._commandRenderer(div, this.visibleItems[index]);
|
|
156
|
+
this._itemRenderer = (div, index, opts) => {
|
|
157
|
+
return this.visibleItems[index] instanceof CommandGroup
|
|
158
|
+
? this._groupRenderer(div, this.visibleItems[index], opts)
|
|
159
|
+
: this._commandRenderer(div, this.visibleItems[index], opts);
|
|
163
160
|
};
|
|
161
|
+
this.renderTabs = () => this.sections?.length > 1 ? html `
|
|
162
|
+
<og-container
|
|
163
|
+
.horizontalSliderPosition="${this.sectionPosition == 'top' ? 'bottom' : 'top'}"
|
|
164
|
+
scrollMode="horizontal"
|
|
165
|
+
sliderSize="4">
|
|
166
|
+
<og-tabs
|
|
167
|
+
slot="content"
|
|
168
|
+
class="tabs"
|
|
169
|
+
tabSize="stretch"
|
|
170
|
+
tabAlign="center"
|
|
171
|
+
style="${styleMap({ borderTop: this.sectionPosition == 'bottom' ? '1px solid var(--og-border)' : '' })}"
|
|
172
|
+
@tab.select="${this._onSectionSelect}"
|
|
173
|
+
.position="${this.sectionPosition == 'top' ? 'top' : 'bottom'}"
|
|
174
|
+
.selectedIndex="${this.activeSectionIndex}"
|
|
175
|
+
.items="${this.sections.map(section => ({ ...section, title: this.getSectionTitle(section) }))}">
|
|
176
|
+
</og-tabs>
|
|
177
|
+
</og-container>
|
|
178
|
+
` : '';
|
|
179
|
+
this.renderDropdown = () => this.sections?.length > 1 ? html `
|
|
180
|
+
<og-dropdown-list
|
|
181
|
+
color="transparent"
|
|
182
|
+
.value="${this.activeSection?.id}"
|
|
183
|
+
@change="${this._onDropdownChange}"
|
|
184
|
+
.items="${this.sections.map(section => ({
|
|
185
|
+
k: section.id,
|
|
186
|
+
v: this.getSectionTitle(section),
|
|
187
|
+
icon: section.icon
|
|
188
|
+
}))}">
|
|
189
|
+
</og-dropdown-list>
|
|
190
|
+
` : '';
|
|
191
|
+
this.renderSwitches = () => this.activeSection?.switches?.length > 0 ? html `
|
|
192
|
+
<div class="switches">
|
|
193
|
+
${this.activeSection.switches.map((s) => html `
|
|
194
|
+
<og-button
|
|
195
|
+
type="toggle"
|
|
196
|
+
.text="${s.value}"
|
|
197
|
+
.state="${s.checked ? 'checked' : 'unchecked'}"
|
|
198
|
+
@click="${(e) => {
|
|
199
|
+
s.checked = e.target.state === 'checked';
|
|
200
|
+
this.focus();
|
|
201
|
+
this.updateCommands();
|
|
202
|
+
}}">
|
|
203
|
+
</og-button>
|
|
204
|
+
`)}
|
|
205
|
+
</div>
|
|
206
|
+
` : '';
|
|
164
207
|
this.render = () => html `
|
|
165
208
|
<div class="input">
|
|
166
|
-
|
|
209
|
+
${this.sectionPosition == 'left' ? this.renderDropdown() : ''}
|
|
210
|
+
|
|
211
|
+
<input
|
|
167
212
|
type="text"
|
|
213
|
+
@input="${this._onInput}"
|
|
168
214
|
.placeholder="${this.placeholder}"
|
|
169
|
-
.value="${this.value}">
|
|
215
|
+
.value="${this.value ?? ''}">
|
|
216
|
+
|
|
217
|
+
${this.sectionPosition == 'right' ? this.renderDropdown() : ''}
|
|
170
218
|
</div>
|
|
171
219
|
|
|
220
|
+
${this.sectionPosition != 'bottom' ? this.renderSwitches() : ''}
|
|
221
|
+
|
|
172
222
|
${this.text != null ? html `<div class="text">${this.text}</div>` : ''}
|
|
173
|
-
|
|
223
|
+
|
|
224
|
+
${this.sectionPosition == 'top' ? this.renderTabs() : ''}
|
|
225
|
+
|
|
226
|
+
${this.noResults ? html `
|
|
227
|
+
<div class="no-results">${msg('No results found')}</div>
|
|
228
|
+
` : ''}
|
|
229
|
+
|
|
174
230
|
<div class="list">
|
|
175
|
-
<og-list
|
|
231
|
+
<og-list
|
|
232
|
+
arrowEvents
|
|
176
233
|
maxHeight="300"
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
lineHeight="
|
|
180
|
-
|
|
234
|
+
?dynamicItemHeight="${this.options?.commandRenderer != null}"
|
|
235
|
+
.customStyle="${[this.options?.itemStyle, itemStyle]}"
|
|
236
|
+
.lineHeight="${this.options.itemHeight - 2}"
|
|
237
|
+
.itemHeight="${this.options.itemHeight}"
|
|
238
|
+
.itemRenderer="${this._itemRenderer}"
|
|
239
|
+
@select="${this._onSelect}">
|
|
181
240
|
</og-list>
|
|
182
241
|
</div>
|
|
242
|
+
|
|
243
|
+
${this.sectionPosition == 'bottom' ? this.renderSwitches() : ''}
|
|
244
|
+
|
|
245
|
+
${this.sectionPosition == 'bottom' ? this.renderTabs() : ''}
|
|
183
246
|
`;
|
|
184
247
|
this.addEventListener('click', e => e.stopPropagation());
|
|
185
|
-
this.addEventListener('keyup', this._onKeyUp);
|
|
186
248
|
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
249
|
}
|
|
212
250
|
connectedCallback() {
|
|
213
251
|
super.connectedCallback();
|
|
214
252
|
this.tabIndex = 0;
|
|
215
253
|
}
|
|
254
|
+
focus() {
|
|
255
|
+
this.input?.focus();
|
|
256
|
+
}
|
|
257
|
+
clearFilter(updateCommands = true) {
|
|
258
|
+
this.input.value = '';
|
|
259
|
+
this.focus();
|
|
260
|
+
if (updateCommands)
|
|
261
|
+
this.updateCommands();
|
|
262
|
+
}
|
|
216
263
|
async willUpdate(props) {
|
|
217
264
|
if (props.has('adapter') && this.adapter) {
|
|
218
|
-
|
|
265
|
+
this.adapter.attach(this);
|
|
266
|
+
const [sections, options] = await Promise.all([this.adapter.getSections(), this.adapter.getOptions()]);
|
|
267
|
+
this.sections = sections;
|
|
219
268
|
if (options)
|
|
220
|
-
this.options = options;
|
|
269
|
+
this.options = initOptions(options, this.options);
|
|
270
|
+
}
|
|
271
|
+
else if (props.has('commands') && this.commands) {
|
|
272
|
+
this.model.clear();
|
|
273
|
+
this.commands.forEach(c => this.model.register(c));
|
|
221
274
|
}
|
|
222
275
|
if (this.options) {
|
|
223
276
|
if (this.options.commandRenderer)
|
|
224
277
|
this._commandRenderer = this.options.commandRenderer;
|
|
225
|
-
if (this.options.
|
|
226
|
-
this.
|
|
278
|
+
if (this.options.groupRenderer)
|
|
279
|
+
this._groupRenderer = this.options.groupRenderer;
|
|
227
280
|
}
|
|
228
281
|
}
|
|
229
282
|
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'))
|
|
283
|
+
if (props.has('commands') || props.has('adapter') || props.has('model')) {
|
|
240
284
|
await this.updateCommands();
|
|
241
|
-
|
|
242
|
-
}
|
|
243
|
-
firstUpdated() {
|
|
244
|
-
this.list.itemRenderer = this._itemRenderer;
|
|
245
|
-
this.list.addEventListener('select', this._onSelect);
|
|
285
|
+
}
|
|
246
286
|
}
|
|
247
287
|
async updateCommands() {
|
|
248
288
|
if (this.adapter) {
|
|
249
|
-
this.
|
|
250
|
-
const
|
|
251
|
-
|
|
252
|
-
|
|
289
|
+
this.model.clear();
|
|
290
|
+
const switches = this.activeSection?.switches?.filter(s => s.checked).map(s => s.key) || [];
|
|
291
|
+
const [groups, commands] = (await Promise.all([this.adapter.getGroups({
|
|
292
|
+
sectionId: this.activeSection?.id,
|
|
293
|
+
filter: this.filterValue,
|
|
294
|
+
switches
|
|
295
|
+
}), this.adapter.getCommands({
|
|
296
|
+
sectionId: this.activeSection?.id,
|
|
297
|
+
filter: this.filterValue,
|
|
298
|
+
switches
|
|
299
|
+
})]));
|
|
300
|
+
groups?.forEach(group => this.model.registerGroup(group));
|
|
301
|
+
commands?.forEach(command => this.model.register(command));
|
|
302
|
+
this.visibleItems = this.model.filter(null, this.showGroups, true);
|
|
253
303
|
}
|
|
254
304
|
else {
|
|
255
|
-
this.visibleItems = this.
|
|
305
|
+
this.visibleItems = this.model.filter(this.filterValue, this.showGroups);
|
|
256
306
|
}
|
|
307
|
+
this.placeholder = this.activeSection?.placeholder || '';
|
|
308
|
+
this.list.reset();
|
|
257
309
|
this.list.size = this.visibleItems.length;
|
|
258
|
-
this.list.selectedIndex = this.
|
|
310
|
+
this.list.selectedIndex = this.visibleItems.findIndex(item => item instanceof Command) ?? 0;
|
|
259
311
|
this.list.renderItems(true);
|
|
312
|
+
this.noResults = this.visibleItems.length == 0;
|
|
260
313
|
await this.list.updateComplete;
|
|
261
314
|
}
|
|
262
|
-
async
|
|
263
|
-
const
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
315
|
+
async toggleGroup(groupId) {
|
|
316
|
+
const group = this.model.groups.get(groupId);
|
|
317
|
+
this.list.reset();
|
|
318
|
+
if (group.open) {
|
|
319
|
+
group.open = false;
|
|
320
|
+
this.visibleItems = this.model.filter(this.filterValue, this.showGroups, true);
|
|
267
321
|
this.list.size = this.visibleItems.length;
|
|
268
322
|
}
|
|
269
323
|
else {
|
|
270
|
-
|
|
324
|
+
group.open = true;
|
|
271
325
|
if (this.adapter) {
|
|
272
|
-
const commands = (await Promise.all([this.adapter.getCommands(
|
|
326
|
+
const commands = (await Promise.all([this.adapter.getCommands({
|
|
327
|
+
sectionId: this.activeSection?.id,
|
|
328
|
+
groupId,
|
|
329
|
+
filter: this.filterValue
|
|
330
|
+
})]))[0];
|
|
273
331
|
if (commands.length > 0) {
|
|
274
|
-
|
|
275
|
-
commands.forEach(c =>
|
|
332
|
+
group.commands.clear();
|
|
333
|
+
commands.forEach(c => {
|
|
334
|
+
if (!c.group || c.group == groupId)
|
|
335
|
+
group.addCommand(c);
|
|
336
|
+
});
|
|
276
337
|
}
|
|
277
|
-
this.visibleItems = this.
|
|
338
|
+
this.visibleItems = this.model.filter(null, this.showGroups, true);
|
|
278
339
|
}
|
|
279
340
|
else {
|
|
280
|
-
this.visibleItems = this.
|
|
341
|
+
this.visibleItems = this.model.filter(this.filterValue, this.showGroups, true);
|
|
281
342
|
}
|
|
282
343
|
}
|
|
283
344
|
this.list.size = this.visibleItems.length;
|
|
284
345
|
}
|
|
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
|
-
}
|
|
346
|
+
getSectionTitle(section) {
|
|
347
|
+
return (section.title ?? section.id) + (section.triggerCommand ? ` (${section.triggerCommand})` : '');
|
|
293
348
|
}
|
|
294
349
|
};
|
|
295
350
|
CommandWindow.styles = [style];
|
|
@@ -302,11 +357,14 @@ __decorate([
|
|
|
302
357
|
__decorate([
|
|
303
358
|
property({ type: String })
|
|
304
359
|
], CommandWindow.prototype, "value", void 0);
|
|
360
|
+
__decorate([
|
|
361
|
+
property({ type: String, reflect: true })
|
|
362
|
+
], CommandWindow.prototype, "sectionPosition", void 0);
|
|
305
363
|
__decorate([
|
|
306
364
|
property({ type: String })
|
|
307
365
|
], CommandWindow.prototype, "text", void 0);
|
|
308
366
|
__decorate([
|
|
309
|
-
property({ type:
|
|
367
|
+
property({ type: Array })
|
|
310
368
|
], CommandWindow.prototype, "commands", void 0);
|
|
311
369
|
__decorate([
|
|
312
370
|
property({ type: Object })
|
|
@@ -314,15 +372,33 @@ __decorate([
|
|
|
314
372
|
__decorate([
|
|
315
373
|
property({ type: Object })
|
|
316
374
|
], CommandWindow.prototype, "target", void 0);
|
|
317
|
-
__decorate([
|
|
318
|
-
property({ type: String })
|
|
319
|
-
], CommandWindow.prototype, "triggerKey", void 0);
|
|
320
375
|
__decorate([
|
|
321
376
|
property({ type: String })
|
|
322
377
|
], CommandWindow.prototype, "placeholder", void 0);
|
|
323
378
|
__decorate([
|
|
324
379
|
property({ type: Boolean })
|
|
325
|
-
], CommandWindow.prototype, "
|
|
380
|
+
], CommandWindow.prototype, "showGroups", void 0);
|
|
381
|
+
__decorate([
|
|
382
|
+
property({ type: Object })
|
|
383
|
+
], CommandWindow.prototype, "model", void 0);
|
|
384
|
+
__decorate([
|
|
385
|
+
state()
|
|
386
|
+
], CommandWindow.prototype, "sections", void 0);
|
|
387
|
+
__decorate([
|
|
388
|
+
state()
|
|
389
|
+
], CommandWindow.prototype, "activeSectionIndex", void 0);
|
|
390
|
+
__decorate([
|
|
391
|
+
state()
|
|
392
|
+
], CommandWindow.prototype, "noResults", void 0);
|
|
393
|
+
__decorate([
|
|
394
|
+
query('og-list')
|
|
395
|
+
], CommandWindow.prototype, "list", void 0);
|
|
396
|
+
__decorate([
|
|
397
|
+
query('input')
|
|
398
|
+
], CommandWindow.prototype, "input", void 0);
|
|
399
|
+
__decorate([
|
|
400
|
+
query('og-dropdown-list')
|
|
401
|
+
], CommandWindow.prototype, "dropdown", void 0);
|
|
326
402
|
CommandWindow = __decorate([
|
|
327
403
|
customElement('og-commands')
|
|
328
404
|
], CommandWindow);
|