@deepfuture/dui-components 0.0.12 → 0.0.14
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/_deprecated/center/center.js +2 -2
- package/_deprecated/hstack/hstack.js +79 -33
- package/_deprecated/page-inset/page-inset.js +104 -56
- package/_deprecated/vstack/vstack.js +61 -19
- package/accordion/accordion-item.js +217 -147
- package/accordion/accordion.js +214 -149
- package/alert-dialog/alert-dialog-close.js +2 -2
- package/alert-dialog/alert-dialog-popup.js +230 -166
- package/alert-dialog/alert-dialog-trigger.js +2 -2
- package/alert-dialog/alert-dialog.js +128 -73
- package/avatar/avatar.js +175 -115
- package/badge/badge.js +2 -2
- package/breadcrumb/breadcrumb-ellipsis.js +2 -2
- package/breadcrumb/breadcrumb-item.js +2 -2
- package/breadcrumb/breadcrumb-link.js +2 -2
- package/breadcrumb/breadcrumb-page.js +2 -2
- package/breadcrumb/breadcrumb-separator.js +2 -2
- package/breadcrumb/breadcrumb.js +2 -2
- package/button/button.js +109 -65
- package/calendar/calendar.js +368 -290
- package/checkbox/checkbox-group.js +146 -87
- package/checkbox/checkbox.js +232 -167
- package/collapsible/collapsible.js +210 -132
- package/combobox/combobox.js +318 -252
- package/command/command-empty.js +67 -25
- package/command/command-group.js +87 -47
- package/command/command-input.js +84 -44
- package/command/command-item.js +168 -124
- package/command/command-list.js +60 -18
- package/command/command-separator.js +2 -2
- package/command/command-shortcut.js +2 -2
- package/command/command.js +297 -232
- package/data-table/data-table.js +225 -153
- package/dialog/dialog-close.js +2 -2
- package/dialog/dialog-popup.js +247 -181
- package/dialog/dialog-trigger.js +2 -2
- package/dialog/dialog.js +128 -73
- package/dropzone/dropzone.js +310 -249
- package/icon/icon.js +2 -2
- package/input/input.js +204 -143
- package/link/link.js +62 -24
- package/menu/menu-item.js +66 -24
- package/menu/menu.js +189 -136
- package/menubar/menubar.js +142 -91
- package/number-field/number-field.js +277 -204
- package/package.json +2 -3
- package/popover/popover-close.js +2 -2
- package/popover/popover-popup.js +126 -76
- package/popover/popover-trigger.js +2 -2
- package/popover/popover.js +181 -120
- package/portal/portal.js +128 -86
- package/preview-card/preview-card-popup.js +114 -66
- package/preview-card/preview-card-trigger.js +2 -2
- package/preview-card/preview-card.js +211 -142
- package/progress/progress.js +91 -45
- package/radio/radio-group.js +153 -90
- package/radio/radio.js +137 -94
- package/scroll-area/scroll-area.js +382 -283
- package/select/select.js +260 -203
- package/separator/separator.js +60 -18
- package/sidebar/sidebar-content.js +2 -2
- package/sidebar/sidebar-footer.js +2 -2
- package/sidebar/sidebar-group-label.js +2 -2
- package/sidebar/sidebar-group.js +2 -2
- package/sidebar/sidebar-header.js +2 -2
- package/sidebar/sidebar-inset.js +2 -2
- package/sidebar/sidebar-menu-button.js +118 -74
- package/sidebar/sidebar-menu-item.js +2 -2
- package/sidebar/sidebar-menu.js +2 -2
- package/sidebar/sidebar-provider.js +202 -129
- package/sidebar/sidebar-separator.js +2 -2
- package/sidebar/sidebar-trigger.js +2 -2
- package/sidebar/sidebar.js +150 -85
- package/slider/slider.js +217 -159
- package/spinner/spinner.js +70 -28
- package/switch/switch.js +174 -111
- package/tabs/tab.js +89 -47
- package/tabs/tabs-indicator.js +2 -2
- package/tabs/tabs-list.js +92 -54
- package/tabs/tabs-panel.js +90 -44
- package/tabs/tabs.js +130 -71
- package/textarea/textarea.js +153 -95
- package/toggle/toggle-group.js +184 -125
- package/toggle/toggle.js +131 -76
- package/toolbar/toolbar.js +79 -33
- package/tooltip/tooltip-popup.js +108 -60
- package/tooltip/tooltip-trigger.js +93 -55
- package/tooltip/tooltip.js +225 -154
- package/trunc/trunc.js +78 -34
package/command/command.js
CHANGED
|
@@ -1,9 +1,41 @@
|
|
|
1
1
|
/** Ported from original DUI: deep-future-app/app/client/components/dui/command */
|
|
2
|
-
var
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
2
|
+
var __esDecorate = (this && this.__esDecorate) || function (ctor, descriptorIn, decorators, contextIn, initializers, extraInitializers) {
|
|
3
|
+
function accept(f) { if (f !== void 0 && typeof f !== "function") throw new TypeError("Function expected"); return f; }
|
|
4
|
+
var kind = contextIn.kind, key = kind === "getter" ? "get" : kind === "setter" ? "set" : "value";
|
|
5
|
+
var target = !descriptorIn && ctor ? contextIn["static"] ? ctor : ctor.prototype : null;
|
|
6
|
+
var descriptor = descriptorIn || (target ? Object.getOwnPropertyDescriptor(target, contextIn.name) : {});
|
|
7
|
+
var _, done = false;
|
|
8
|
+
for (var i = decorators.length - 1; i >= 0; i--) {
|
|
9
|
+
var context = {};
|
|
10
|
+
for (var p in contextIn) context[p] = p === "access" ? {} : contextIn[p];
|
|
11
|
+
for (var p in contextIn.access) context.access[p] = contextIn.access[p];
|
|
12
|
+
context.addInitializer = function (f) { if (done) throw new TypeError("Cannot add initializers after decoration has completed"); extraInitializers.push(accept(f || null)); };
|
|
13
|
+
var result = (0, decorators[i])(kind === "accessor" ? { get: descriptor.get, set: descriptor.set } : descriptor[key], context);
|
|
14
|
+
if (kind === "accessor") {
|
|
15
|
+
if (result === void 0) continue;
|
|
16
|
+
if (result === null || typeof result !== "object") throw new TypeError("Object expected");
|
|
17
|
+
if (_ = accept(result.get)) descriptor.get = _;
|
|
18
|
+
if (_ = accept(result.set)) descriptor.set = _;
|
|
19
|
+
if (_ = accept(result.init)) initializers.unshift(_);
|
|
20
|
+
}
|
|
21
|
+
else if (_ = accept(result)) {
|
|
22
|
+
if (kind === "field") initializers.unshift(_);
|
|
23
|
+
else descriptor[key] = _;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
if (target) Object.defineProperty(target, contextIn.name, descriptor);
|
|
27
|
+
done = true;
|
|
28
|
+
};
|
|
29
|
+
var __runInitializers = (this && this.__runInitializers) || function (thisArg, initializers, value) {
|
|
30
|
+
var useValue = arguments.length > 2;
|
|
31
|
+
for (var i = 0; i < initializers.length; i++) {
|
|
32
|
+
value = useValue ? initializers[i].call(thisArg, value) : initializers[i].call(thisArg);
|
|
33
|
+
}
|
|
34
|
+
return useValue ? value : void 0;
|
|
35
|
+
};
|
|
36
|
+
var __setFunctionName = (this && this.__setFunctionName) || function (f, name, prefix) {
|
|
37
|
+
if (typeof name === "symbol") name = name.description ? "[".concat(name.description, "]") : "";
|
|
38
|
+
return Object.defineProperty(f, "name", { configurable: true, value: prefix ? "".concat(prefix, " ", name) : name });
|
|
7
39
|
};
|
|
8
40
|
import { css, html, LitElement } from "lit";
|
|
9
41
|
import { property, state } from "lit/decorators.js";
|
|
@@ -33,246 +65,279 @@ const styles = css `
|
|
|
33
65
|
overflow: hidden;
|
|
34
66
|
}
|
|
35
67
|
`;
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
this
|
|
68
|
+
let DuiCommand = (() => {
|
|
69
|
+
let _classSuper = LitElement;
|
|
70
|
+
let _loop_decorators;
|
|
71
|
+
let _loop_initializers = [];
|
|
72
|
+
let _loop_extraInitializers = [];
|
|
73
|
+
let _shouldFilter_decorators;
|
|
74
|
+
let _shouldFilter_initializers = [];
|
|
75
|
+
let _shouldFilter_extraInitializers = [];
|
|
76
|
+
let _value_decorators;
|
|
77
|
+
let _value_initializers = [];
|
|
78
|
+
let _value_extraInitializers = [];
|
|
79
|
+
let _filter_decorators;
|
|
80
|
+
let _filter_initializers = [];
|
|
81
|
+
let _filter_extraInitializers = [];
|
|
82
|
+
let _private_search_decorators;
|
|
83
|
+
let _private_search_initializers = [];
|
|
84
|
+
let _private_search_extraInitializers = [];
|
|
85
|
+
let _private_search_descriptor;
|
|
86
|
+
let _private_selectedItemId_decorators;
|
|
87
|
+
let _private_selectedItemId_initializers = [];
|
|
88
|
+
let _private_selectedItemId_extraInitializers = [];
|
|
89
|
+
let _private_selectedItemId_descriptor;
|
|
90
|
+
let __ctx_decorators;
|
|
91
|
+
let __ctx_initializers = [];
|
|
92
|
+
let __ctx_extraInitializers = [];
|
|
93
|
+
return class DuiCommand extends _classSuper {
|
|
94
|
+
static {
|
|
95
|
+
const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(_classSuper[Symbol.metadata] ?? null) : void 0;
|
|
96
|
+
_loop_decorators = [property({ type: Boolean })];
|
|
97
|
+
_shouldFilter_decorators = [property({ type: Boolean, attribute: "should-filter" })];
|
|
98
|
+
_value_decorators = [property({ type: String })];
|
|
99
|
+
_filter_decorators = [property({ attribute: false })];
|
|
100
|
+
_private_search_decorators = [state()];
|
|
101
|
+
_private_selectedItemId_decorators = [state()];
|
|
102
|
+
__ctx_decorators = [provide({ context: commandContext }), state()];
|
|
103
|
+
__esDecorate(this, null, _loop_decorators, { kind: "accessor", name: "loop", static: false, private: false, access: { has: obj => "loop" in obj, get: obj => obj.loop, set: (obj, value) => { obj.loop = value; } }, metadata: _metadata }, _loop_initializers, _loop_extraInitializers);
|
|
104
|
+
__esDecorate(this, null, _shouldFilter_decorators, { kind: "accessor", name: "shouldFilter", static: false, private: false, access: { has: obj => "shouldFilter" in obj, get: obj => obj.shouldFilter, set: (obj, value) => { obj.shouldFilter = value; } }, metadata: _metadata }, _shouldFilter_initializers, _shouldFilter_extraInitializers);
|
|
105
|
+
__esDecorate(this, null, _value_decorators, { kind: "accessor", name: "value", static: false, private: false, access: { has: obj => "value" in obj, get: obj => obj.value, set: (obj, value) => { obj.value = value; } }, metadata: _metadata }, _value_initializers, _value_extraInitializers);
|
|
106
|
+
__esDecorate(this, null, _filter_decorators, { kind: "accessor", name: "filter", static: false, private: false, access: { has: obj => "filter" in obj, get: obj => obj.filter, set: (obj, value) => { obj.filter = value; } }, metadata: _metadata }, _filter_initializers, _filter_extraInitializers);
|
|
107
|
+
__esDecorate(this, _private_search_descriptor = { get: __setFunctionName(function () { return this.#search_accessor_storage; }, "#search", "get"), set: __setFunctionName(function (value) { this.#search_accessor_storage = value; }, "#search", "set") }, _private_search_decorators, { kind: "accessor", name: "#search", static: false, private: true, access: { has: obj => #search in obj, get: obj => obj.#search, set: (obj, value) => { obj.#search = value; } }, metadata: _metadata }, _private_search_initializers, _private_search_extraInitializers);
|
|
108
|
+
__esDecorate(this, _private_selectedItemId_descriptor = { get: __setFunctionName(function () { return this.#selectedItemId_accessor_storage; }, "#selectedItemId", "get"), set: __setFunctionName(function (value) { this.#selectedItemId_accessor_storage = value; }, "#selectedItemId", "set") }, _private_selectedItemId_decorators, { kind: "accessor", name: "#selectedItemId", static: false, private: true, access: { has: obj => #selectedItemId in obj, get: obj => obj.#selectedItemId, set: (obj, value) => { obj.#selectedItemId = value; } }, metadata: _metadata }, _private_selectedItemId_initializers, _private_selectedItemId_extraInitializers);
|
|
109
|
+
__esDecorate(this, null, __ctx_decorators, { kind: "accessor", name: "_ctx", static: false, private: false, access: { has: obj => "_ctx" in obj, get: obj => obj._ctx, set: (obj, value) => { obj._ctx = value; } }, metadata: _metadata }, __ctx_initializers, __ctx_extraInitializers);
|
|
110
|
+
if (_metadata) Object.defineProperty(this, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
|
|
73
111
|
}
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
112
|
+
static tagName = "dui-command";
|
|
113
|
+
static styles = [base, styles];
|
|
114
|
+
#loop_accessor_storage = __runInitializers(this, _loop_initializers, false);
|
|
115
|
+
/** Whether keyboard navigation wraps from last to first and vice versa. */
|
|
116
|
+
get loop() { return this.#loop_accessor_storage; }
|
|
117
|
+
set loop(value) { this.#loop_accessor_storage = value; }
|
|
118
|
+
#shouldFilter_accessor_storage = (__runInitializers(this, _loop_extraInitializers), __runInitializers(this, _shouldFilter_initializers, true));
|
|
119
|
+
/** Whether items should be filtered based on search text. */
|
|
120
|
+
get shouldFilter() { return this.#shouldFilter_accessor_storage; }
|
|
121
|
+
set shouldFilter(value) { this.#shouldFilter_accessor_storage = value; }
|
|
122
|
+
#value_accessor_storage = (__runInitializers(this, _shouldFilter_extraInitializers), __runInitializers(this, _value_initializers, undefined));
|
|
123
|
+
/** Controlled value — the currently selected item value. */
|
|
124
|
+
get value() { return this.#value_accessor_storage; }
|
|
125
|
+
set value(value) { this.#value_accessor_storage = value; }
|
|
126
|
+
#filter_accessor_storage = (__runInitializers(this, _value_extraInitializers), __runInitializers(this, _filter_initializers, undefined));
|
|
127
|
+
/** Custom filter function. */
|
|
128
|
+
get filter() { return this.#filter_accessor_storage; }
|
|
129
|
+
set filter(value) { this.#filter_accessor_storage = value; }
|
|
130
|
+
#search_accessor_storage = (__runInitializers(this, _filter_extraInitializers), __runInitializers(this, _private_search_initializers, ""));
|
|
131
|
+
get #search() { return _private_search_descriptor.get.call(this); }
|
|
132
|
+
set #search(value) { return _private_search_descriptor.set.call(this, value); }
|
|
133
|
+
#selectedItemId_accessor_storage = (__runInitializers(this, _private_search_extraInitializers), __runInitializers(this, _private_selectedItemId_initializers, undefined));
|
|
134
|
+
get #selectedItemId() { return _private_selectedItemId_descriptor.get.call(this); }
|
|
135
|
+
set #selectedItemId(value) { return _private_selectedItemId_descriptor.set.call(this, value); }
|
|
136
|
+
#items = (__runInitializers(this, _private_selectedItemId_extraInitializers), new Map());
|
|
137
|
+
#itemOrder = [];
|
|
138
|
+
#groups = new Set();
|
|
139
|
+
#scoresMap = new Map();
|
|
140
|
+
#listId = nextId();
|
|
141
|
+
#recomputeScores() {
|
|
142
|
+
this.#scoresMap.clear();
|
|
143
|
+
for (const [id, entry] of this.#items) {
|
|
144
|
+
const score = this.filter
|
|
145
|
+
? this.filter(entry.value, this.#search, entry.keywords)
|
|
146
|
+
: commandScore(this.#search, entry.value, entry.textContent, entry.keywords);
|
|
147
|
+
this.#scoresMap.set(id, score);
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
#getScore = (itemId) => {
|
|
86
151
|
if (!this.shouldFilter)
|
|
87
|
-
return
|
|
88
|
-
return
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
this.#itemOrder.push(entry.id);
|
|
152
|
+
return 1;
|
|
153
|
+
return this.#scoresMap.get(itemId) ?? 0;
|
|
154
|
+
};
|
|
155
|
+
#getVisibleItems() {
|
|
156
|
+
return this.#itemOrder
|
|
157
|
+
.map((id) => this.#items.get(id))
|
|
158
|
+
.filter((entry) => {
|
|
159
|
+
if (!entry)
|
|
160
|
+
return false;
|
|
161
|
+
if (!this.shouldFilter)
|
|
162
|
+
return true;
|
|
163
|
+
return (this.#scoresMap.get(entry.id) ?? 0) > 0;
|
|
164
|
+
});
|
|
101
165
|
}
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
if (
|
|
111
|
-
this.#
|
|
166
|
+
#getVisibleCount = () => {
|
|
167
|
+
return this.#getVisibleItems().length;
|
|
168
|
+
};
|
|
169
|
+
#getGroupVisibleCount = (groupId) => {
|
|
170
|
+
return this.#getVisibleItems().filter((e) => e.groupId === groupId).length;
|
|
171
|
+
};
|
|
172
|
+
#registerItem = (entry) => {
|
|
173
|
+
this.#items.set(entry.id, entry);
|
|
174
|
+
if (!this.#itemOrder.includes(entry.id)) {
|
|
175
|
+
this.#itemOrder.push(entry.id);
|
|
112
176
|
}
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
const score = this.filter
|
|
125
|
-
? this.filter(entry.value, this.#search, entry.keywords)
|
|
126
|
-
: commandScore(this.#search, entry.value, entry.textContent, entry.keywords);
|
|
127
|
-
this.#scoresMap.set(entry.id, score);
|
|
128
|
-
this.requestUpdate();
|
|
129
|
-
};
|
|
130
|
-
#registerGroup = (groupId) => {
|
|
131
|
-
this.#groups.add(groupId);
|
|
132
|
-
};
|
|
133
|
-
#unregisterGroup = (groupId) => {
|
|
134
|
-
this.#groups.delete(groupId);
|
|
135
|
-
};
|
|
136
|
-
#setSearch = (value) => {
|
|
137
|
-
this.#search = value;
|
|
138
|
-
this.#recomputeScores();
|
|
139
|
-
// Select first visible non-disabled item
|
|
140
|
-
const visible = this.#getVisibleItems();
|
|
141
|
-
const firstSelectable = visible.find((e) => !e.disabled);
|
|
142
|
-
this.#selectedItemId = firstSelectable?.id;
|
|
143
|
-
this.dispatchEvent(searchChangeEvent(value));
|
|
144
|
-
};
|
|
145
|
-
#selectItem = (id) => {
|
|
146
|
-
this.#selectedItemId = id;
|
|
147
|
-
};
|
|
148
|
-
#handleItemSelect = (value) => {
|
|
149
|
-
this.dispatchEvent(selectEvent(value));
|
|
150
|
-
};
|
|
151
|
-
#handleKeyDown = (event) => {
|
|
152
|
-
const visible = this.#getVisibleItems().filter((e) => !e.disabled);
|
|
153
|
-
if (visible.length === 0)
|
|
154
|
-
return;
|
|
155
|
-
const currentIndex = visible.findIndex((e) => e.id === this.#selectedItemId);
|
|
156
|
-
const selectByIndex = (index) => {
|
|
157
|
-
const item = visible[index];
|
|
158
|
-
if (item) {
|
|
159
|
-
this.#selectedItemId = item.id;
|
|
177
|
+
// Recompute scores for new item
|
|
178
|
+
const score = this.filter
|
|
179
|
+
? this.filter(entry.value, this.#search, entry.keywords)
|
|
180
|
+
: commandScore(this.#search, entry.value, entry.textContent, entry.keywords);
|
|
181
|
+
this.#scoresMap.set(entry.id, score);
|
|
182
|
+
// Auto-select first visible item if nothing selected
|
|
183
|
+
if (!this.#selectedItemId) {
|
|
184
|
+
const visible = this.#getVisibleItems();
|
|
185
|
+
if (visible.length > 0 && !visible[0].disabled) {
|
|
186
|
+
this.#selectedItemId = visible[0].id;
|
|
187
|
+
}
|
|
160
188
|
}
|
|
189
|
+
this.requestUpdate();
|
|
161
190
|
};
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
191
|
+
#unregisterItem = (id) => {
|
|
192
|
+
this.#items.delete(id);
|
|
193
|
+
this.#itemOrder = this.#itemOrder.filter((v) => v !== id);
|
|
194
|
+
this.#scoresMap.delete(id);
|
|
195
|
+
this.requestUpdate();
|
|
196
|
+
};
|
|
197
|
+
#updateItem = (entry) => {
|
|
198
|
+
this.#items.set(entry.id, entry);
|
|
199
|
+
const score = this.filter
|
|
200
|
+
? this.filter(entry.value, this.#search, entry.keywords)
|
|
201
|
+
: commandScore(this.#search, entry.value, entry.textContent, entry.keywords);
|
|
202
|
+
this.#scoresMap.set(entry.id, score);
|
|
203
|
+
this.requestUpdate();
|
|
204
|
+
};
|
|
205
|
+
#registerGroup = (groupId) => {
|
|
206
|
+
this.#groups.add(groupId);
|
|
207
|
+
};
|
|
208
|
+
#unregisterGroup = (groupId) => {
|
|
209
|
+
this.#groups.delete(groupId);
|
|
210
|
+
};
|
|
211
|
+
#setSearch = (value) => {
|
|
212
|
+
this.#search = value;
|
|
213
|
+
this.#recomputeScores();
|
|
214
|
+
// Select first visible non-disabled item
|
|
215
|
+
const visible = this.#getVisibleItems();
|
|
216
|
+
const firstSelectable = visible.find((e) => !e.disabled);
|
|
217
|
+
this.#selectedItemId = firstSelectable?.id;
|
|
218
|
+
this.dispatchEvent(searchChangeEvent(value));
|
|
219
|
+
};
|
|
220
|
+
#selectItem = (id) => {
|
|
221
|
+
this.#selectedItemId = id;
|
|
222
|
+
};
|
|
223
|
+
#handleItemSelect = (value) => {
|
|
224
|
+
this.dispatchEvent(selectEvent(value));
|
|
225
|
+
};
|
|
226
|
+
#handleKeyDown = (event) => {
|
|
227
|
+
const visible = this.#getVisibleItems().filter((e) => !e.disabled);
|
|
228
|
+
if (visible.length === 0)
|
|
229
|
+
return;
|
|
230
|
+
const currentIndex = visible.findIndex((e) => e.id === this.#selectedItemId);
|
|
231
|
+
const selectByIndex = (index) => {
|
|
232
|
+
const item = visible[index];
|
|
233
|
+
if (item) {
|
|
234
|
+
this.#selectedItemId = item.id;
|
|
175
235
|
}
|
|
176
|
-
|
|
177
|
-
|
|
236
|
+
};
|
|
237
|
+
switch (event.key) {
|
|
238
|
+
case "ArrowDown":
|
|
239
|
+
case "n":
|
|
240
|
+
case "j": {
|
|
241
|
+
// Ctrl+N and Ctrl+J for down
|
|
242
|
+
if (event.key !== "ArrowDown" &&
|
|
243
|
+
!event.ctrlKey &&
|
|
244
|
+
!event.metaKey) {
|
|
245
|
+
return;
|
|
246
|
+
}
|
|
247
|
+
event.preventDefault();
|
|
248
|
+
if (currentIndex < visible.length - 1) {
|
|
249
|
+
selectByIndex(currentIndex + 1);
|
|
250
|
+
}
|
|
251
|
+
else if (this.loop) {
|
|
252
|
+
selectByIndex(0);
|
|
253
|
+
}
|
|
254
|
+
break;
|
|
178
255
|
}
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
256
|
+
case "ArrowUp":
|
|
257
|
+
case "p":
|
|
258
|
+
case "k": {
|
|
259
|
+
// Ctrl+P and Ctrl+K for up
|
|
260
|
+
if (event.key !== "ArrowUp" &&
|
|
261
|
+
!event.ctrlKey &&
|
|
262
|
+
!event.metaKey) {
|
|
263
|
+
return;
|
|
264
|
+
}
|
|
265
|
+
event.preventDefault();
|
|
266
|
+
if (currentIndex > 0) {
|
|
267
|
+
selectByIndex(currentIndex - 1);
|
|
268
|
+
}
|
|
269
|
+
else if (this.loop) {
|
|
270
|
+
selectByIndex(visible.length - 1);
|
|
271
|
+
}
|
|
272
|
+
break;
|
|
189
273
|
}
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
selectByIndex(
|
|
274
|
+
case "Home": {
|
|
275
|
+
event.preventDefault();
|
|
276
|
+
selectByIndex(0);
|
|
277
|
+
break;
|
|
193
278
|
}
|
|
194
|
-
|
|
279
|
+
case "End": {
|
|
280
|
+
event.preventDefault();
|
|
195
281
|
selectByIndex(visible.length - 1);
|
|
282
|
+
break;
|
|
196
283
|
}
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
case "Enter": {
|
|
210
|
-
event.preventDefault();
|
|
211
|
-
const selected = visible.find((e) => e.id === this.#selectedItemId);
|
|
212
|
-
if (selected) {
|
|
213
|
-
this.#handleItemSelect(selected.value);
|
|
284
|
+
case "Enter": {
|
|
285
|
+
event.preventDefault();
|
|
286
|
+
const selected = visible.find((e) => e.id === this.#selectedItemId);
|
|
287
|
+
if (selected) {
|
|
288
|
+
this.#handleItemSelect(selected.value);
|
|
289
|
+
}
|
|
290
|
+
break;
|
|
291
|
+
}
|
|
292
|
+
case "Escape": {
|
|
293
|
+
event.preventDefault();
|
|
294
|
+
this.dispatchEvent(escapeEvent());
|
|
295
|
+
break;
|
|
214
296
|
}
|
|
215
|
-
break;
|
|
216
|
-
}
|
|
217
|
-
case "Escape": {
|
|
218
|
-
event.preventDefault();
|
|
219
|
-
this.dispatchEvent(escapeEvent());
|
|
220
|
-
break;
|
|
221
297
|
}
|
|
298
|
+
};
|
|
299
|
+
#_ctx_accessor_storage = __runInitializers(this, __ctx_initializers, this.#buildContext());
|
|
300
|
+
get _ctx() { return this.#_ctx_accessor_storage; }
|
|
301
|
+
set _ctx(value) { this.#_ctx_accessor_storage = value; }
|
|
302
|
+
#buildContext() {
|
|
303
|
+
return {
|
|
304
|
+
search: this.#search,
|
|
305
|
+
selectedItemId: this.#selectedItemId,
|
|
306
|
+
listId: this.#listId,
|
|
307
|
+
loop: this.loop,
|
|
308
|
+
shouldFilter: this.shouldFilter,
|
|
309
|
+
getScore: this.#getScore,
|
|
310
|
+
getVisibleCount: this.#getVisibleCount,
|
|
311
|
+
getGroupVisibleCount: this.#getGroupVisibleCount,
|
|
312
|
+
registerItem: this.#registerItem,
|
|
313
|
+
unregisterItem: this.#unregisterItem,
|
|
314
|
+
updateItem: this.#updateItem,
|
|
315
|
+
registerGroup: this.#registerGroup,
|
|
316
|
+
unregisterGroup: this.#unregisterGroup,
|
|
317
|
+
setSearch: this.#setSearch,
|
|
318
|
+
selectItem: this.#selectItem,
|
|
319
|
+
handleItemSelect: this.#handleItemSelect,
|
|
320
|
+
};
|
|
321
|
+
}
|
|
322
|
+
connectedCallback() {
|
|
323
|
+
super.connectedCallback();
|
|
324
|
+
this.addEventListener("keydown", this.#handleKeyDown);
|
|
325
|
+
this._ctx = this.#buildContext();
|
|
326
|
+
}
|
|
327
|
+
disconnectedCallback() {
|
|
328
|
+
super.disconnectedCallback();
|
|
329
|
+
this.removeEventListener("keydown", this.#handleKeyDown);
|
|
330
|
+
}
|
|
331
|
+
willUpdate() {
|
|
332
|
+
this._ctx = this.#buildContext();
|
|
333
|
+
}
|
|
334
|
+
render() {
|
|
335
|
+
return html `<slot></slot>`;
|
|
336
|
+
}
|
|
337
|
+
constructor() {
|
|
338
|
+
super(...arguments);
|
|
339
|
+
__runInitializers(this, __ctx_extraInitializers);
|
|
222
340
|
}
|
|
223
341
|
};
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
set _ctx(value) { this.#_ctx_accessor_storage = value; }
|
|
227
|
-
#buildContext() {
|
|
228
|
-
return {
|
|
229
|
-
search: this.#search,
|
|
230
|
-
selectedItemId: this.#selectedItemId,
|
|
231
|
-
listId: this.#listId,
|
|
232
|
-
loop: this.loop,
|
|
233
|
-
shouldFilter: this.shouldFilter,
|
|
234
|
-
getScore: this.#getScore,
|
|
235
|
-
getVisibleCount: this.#getVisibleCount,
|
|
236
|
-
getGroupVisibleCount: this.#getGroupVisibleCount,
|
|
237
|
-
registerItem: this.#registerItem,
|
|
238
|
-
unregisterItem: this.#unregisterItem,
|
|
239
|
-
updateItem: this.#updateItem,
|
|
240
|
-
registerGroup: this.#registerGroup,
|
|
241
|
-
unregisterGroup: this.#unregisterGroup,
|
|
242
|
-
setSearch: this.#setSearch,
|
|
243
|
-
selectItem: this.#selectItem,
|
|
244
|
-
handleItemSelect: this.#handleItemSelect,
|
|
245
|
-
};
|
|
246
|
-
}
|
|
247
|
-
connectedCallback() {
|
|
248
|
-
super.connectedCallback();
|
|
249
|
-
this.addEventListener("keydown", this.#handleKeyDown);
|
|
250
|
-
this._ctx = this.#buildContext();
|
|
251
|
-
}
|
|
252
|
-
disconnectedCallback() {
|
|
253
|
-
super.disconnectedCallback();
|
|
254
|
-
this.removeEventListener("keydown", this.#handleKeyDown);
|
|
255
|
-
}
|
|
256
|
-
willUpdate() {
|
|
257
|
-
this._ctx = this.#buildContext();
|
|
258
|
-
}
|
|
259
|
-
render() {
|
|
260
|
-
return html `<slot></slot>`;
|
|
261
|
-
}
|
|
262
|
-
}
|
|
263
|
-
__decorate([
|
|
264
|
-
property({ type: Boolean })
|
|
265
|
-
], DuiCommand.prototype, "loop", null);
|
|
266
|
-
__decorate([
|
|
267
|
-
property({ type: Boolean, attribute: "should-filter" })
|
|
268
|
-
], DuiCommand.prototype, "shouldFilter", null);
|
|
269
|
-
__decorate([
|
|
270
|
-
property({ type: String })
|
|
271
|
-
], DuiCommand.prototype, "value", null);
|
|
272
|
-
__decorate([
|
|
273
|
-
property({ attribute: false })
|
|
274
|
-
], DuiCommand.prototype, "filter", null);
|
|
275
|
-
__decorate([
|
|
276
|
-
provide({ context: commandContext }),
|
|
277
|
-
state()
|
|
278
|
-
], DuiCommand.prototype, "_ctx", null);
|
|
342
|
+
})();
|
|
343
|
+
export { DuiCommand };
|