@webority/ui-elements 0.34.0 → 0.35.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/WuiAutocomplete-ByxnwJNQ.js +283 -0
- package/dist/WuiCommandPalette-CtZ04JxZ.js +130 -0
- package/dist/WuiConsentBanner-oVe-jxCO.js +399 -0
- package/dist/WuiContextMenu-Bx_U2X3t.js +211 -0
- package/dist/WuiCountrySelect-CUAwKnL9.js +28 -0
- package/dist/WuiDatePicker-DkNbc-z7.js +325 -0
- package/dist/WuiDateRange-BocnVO6L.js +233 -0
- package/dist/WuiDock-BSDY9g8Q.js +57 -0
- package/dist/WuiImageCrop-1yaAONTk.js +462 -0
- package/dist/WuiMultiSelect-BrCGRNCt.js +416 -0
- package/dist/WuiOtp-D8-4Pqil.js +128 -0
- package/dist/WuiPhone-BvbhiP2r.js +731 -0
- package/dist/WuiSelect-BXrpiuXG.js +214 -0
- package/dist/WuiSlider-BcU0psYf.js +256 -0
- package/dist/WuiSortable-JjJqstSU.js +280 -0
- package/dist/WuiTagInput-D1ay3OcL.js +158 -0
- package/dist/WuiTimePicker-C7n-VFGt.js +370 -0
- package/dist/WuiTour-R5O9l--J.js +205 -0
- package/dist/WuiTree-Ds-8tNgs.js +393 -0
- package/dist/WuiWizardStep-BU5w9_Ds.js +221 -0
- package/dist/anchorOverlay-DluGZ8ef.js +23 -0
- package/dist/calendarMath-BAF2Jkg_.js +42 -0
- package/dist/countries-B-M_LTgS.js +1234 -0
- package/dist/elementBase-Bg1xpvup.js +9 -0
- package/dist/elements/autocomplete.js +6 -0
- package/dist/elements/command-palette.js +6 -0
- package/dist/elements/consent-banner.js +6 -0
- package/dist/elements/context-menu.js +6 -0
- package/dist/elements/country-select.js +6 -0
- package/dist/elements/date-range.js +6 -0
- package/dist/elements/datepicker.js +6 -0
- package/dist/elements/dock.js +6 -0
- package/dist/elements/image-crop.js +6 -0
- package/dist/elements/kanban.js +6 -0
- package/dist/elements/multiselect.js +6 -0
- package/dist/elements/otp.js +6 -0
- package/dist/elements/phone.js +6 -0
- package/dist/elements/select.js +6 -0
- package/dist/elements/slider.js +6 -0
- package/dist/elements/sortable.js +6 -0
- package/dist/elements/status-icon.js +6 -0
- package/dist/elements/taginput.js +6 -0
- package/dist/elements/timepicker.js +6 -0
- package/dist/elements/tour.js +6 -0
- package/dist/elements/tree.js +6 -0
- package/dist/elements/wizard.js +5 -0
- package/dist/formMirror-jGf5M4gk.js +29 -0
- package/dist/formatters-DusKbTyV.js +138 -0
- package/dist/helpers.js +5 -0
- package/dist/iconGlyphs.g-Cpg1BUHm.js +215 -0
- package/dist/kanban-BeVAItir.js +972 -0
- package/dist/listboxKeyNav-zts_8d5e.js +36 -0
- package/dist/optionLabel-Dn-I7zyp.js +16 -0
- package/dist/statusIcons-C3zjycpa.js +37 -0
- package/dist/textMatch-DEUjlkdy.js +27 -0
- package/dist/themeTransition-BpCuMnjk.js +589 -0
- package/dist/tokenCommit-VWz-2jEf.js +20 -0
- package/dist/ui-elements.global.js +118 -129
- package/dist/ui-elements.js +253 -8864
- package/dist/ui-phone.global.js +14 -0
- package/dist/wuiHttp-m0yQadwQ.js +117 -0
- package/package.json +28 -3
|
@@ -0,0 +1,283 @@
|
|
|
1
|
+
import { t as e } from "./elementBase-Bg1xpvup.js";
|
|
2
|
+
import { n as t, r as n, t as r } from "./anchorOverlay-DluGZ8ef.js";
|
|
3
|
+
import { t as i } from "./formMirror-jGf5M4gk.js";
|
|
4
|
+
import { t as a } from "./iconGlyphs.g-Cpg1BUHm.js";
|
|
5
|
+
import { n as o, t as s } from "./listboxKeyNav-zts_8d5e.js";
|
|
6
|
+
import { n as c, r as l, t as u } from "./optionLabel-Dn-I7zyp.js";
|
|
7
|
+
//#region src/WuiAutocomplete.js
|
|
8
|
+
var d = class extends e {
|
|
9
|
+
static formAssociated = !0;
|
|
10
|
+
_accessibleName() {
|
|
11
|
+
return this.getAttribute("aria-label") || this.getAttribute("placeholder") || "Select";
|
|
12
|
+
}
|
|
13
|
+
static get observedAttributes() {
|
|
14
|
+
return [
|
|
15
|
+
"value",
|
|
16
|
+
"placeholder",
|
|
17
|
+
"disabled",
|
|
18
|
+
"min-chars",
|
|
19
|
+
"debounce",
|
|
20
|
+
"remote",
|
|
21
|
+
"size",
|
|
22
|
+
"aria-label",
|
|
23
|
+
"allow-custom",
|
|
24
|
+
"aria-invalid"
|
|
25
|
+
];
|
|
26
|
+
}
|
|
27
|
+
constructor() {
|
|
28
|
+
super(), this._value = "", this._label = "", this._optionsProp = null, this._loading = !1, this._active = -1, this._timer = null, this._reqSeq = 0, this._pendingSearch = null, this._typeahead = "", this._typeaheadTimer = null;
|
|
29
|
+
try {
|
|
30
|
+
this._internals = this.attachInternals();
|
|
31
|
+
} catch {
|
|
32
|
+
this._internals = null;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
connectedCallback() {
|
|
36
|
+
if (!this._rendered) {
|
|
37
|
+
this._defaultCaptured ||= (this._defaultValue = this._value, !0), this.render();
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
if (this._bindGlobal?.(), this._pendingSearch) {
|
|
41
|
+
let { query: e, seq: t } = this._pendingSearch;
|
|
42
|
+
clearTimeout(this._timer), this._timer = setTimeout(() => this._fireSearch(e, t), this._debounceMs);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
formResetCallback() {
|
|
46
|
+
this.value = this._defaultValue || "";
|
|
47
|
+
}
|
|
48
|
+
attributeChangedCallback(e, t, n) {
|
|
49
|
+
if (e === "value") {
|
|
50
|
+
this.value = n;
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
if (e === "aria-invalid") {
|
|
54
|
+
this._syncInvalid();
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
this._rendered && this.render();
|
|
58
|
+
}
|
|
59
|
+
_syncInvalid() {
|
|
60
|
+
let e = this.querySelector(".search-select-control");
|
|
61
|
+
e && (this.hasAttribute("aria-invalid") ? e.setAttribute("aria-invalid", "true") : e.removeAttribute("aria-invalid"));
|
|
62
|
+
}
|
|
63
|
+
get value() {
|
|
64
|
+
return this._value;
|
|
65
|
+
}
|
|
66
|
+
set value(e) {
|
|
67
|
+
this._value = e == null ? "" : String(e), i(this, this._value);
|
|
68
|
+
let t = this._readOptions().find((e) => String(e.value) === this._value);
|
|
69
|
+
this._label = t ? p(t.label) : "", this._syncInput(), this._renderOptions("");
|
|
70
|
+
}
|
|
71
|
+
set options(e) {
|
|
72
|
+
this._optionsProp = Array.isArray(e) ? e : [];
|
|
73
|
+
let t = this._readOptions().find((e) => String(e.value) === this._value);
|
|
74
|
+
t && (this._label = p(t.label)), this._renderOptions(), this._syncInput();
|
|
75
|
+
}
|
|
76
|
+
get options() {
|
|
77
|
+
return this._readOptions();
|
|
78
|
+
}
|
|
79
|
+
set loading(e) {
|
|
80
|
+
this._loading = !!e, this._renderLoading(), this._renderOptions();
|
|
81
|
+
}
|
|
82
|
+
get loading() {
|
|
83
|
+
return this._loading;
|
|
84
|
+
}
|
|
85
|
+
get _remote() {
|
|
86
|
+
return this.hasAttribute("remote");
|
|
87
|
+
}
|
|
88
|
+
get _allowCustom() {
|
|
89
|
+
return this.hasAttribute("allow-custom");
|
|
90
|
+
}
|
|
91
|
+
_matchesKnownOption(e) {
|
|
92
|
+
let t = e.toLowerCase();
|
|
93
|
+
return this._readOptions().some((e) => p(e.label).toLowerCase() === t || String(e.value ?? "").toLowerCase() === t);
|
|
94
|
+
}
|
|
95
|
+
get _minChars() {
|
|
96
|
+
return Math.max(0, Number(this.getAttribute("min-chars")) || +!!this._remote);
|
|
97
|
+
}
|
|
98
|
+
get _debounceMs() {
|
|
99
|
+
let e = this.getAttribute("debounce");
|
|
100
|
+
if (e == null || e === "") return 250;
|
|
101
|
+
let t = Number(e);
|
|
102
|
+
return Number.isFinite(t) && t >= 0 ? t : 250;
|
|
103
|
+
}
|
|
104
|
+
_snapshotDeclared() {
|
|
105
|
+
if (this._declared) return;
|
|
106
|
+
let e = [...this.querySelectorAll(":scope > wui-option")];
|
|
107
|
+
e.length && (this._declared = e.map((e) => ({
|
|
108
|
+
value: e.getAttribute("value") ?? e.textContent.trim(),
|
|
109
|
+
label: e.innerHTML,
|
|
110
|
+
icon: e.getAttribute("icon") || void 0,
|
|
111
|
+
[u]: !0,
|
|
112
|
+
selected: e.hasAttribute("selected")
|
|
113
|
+
})));
|
|
114
|
+
}
|
|
115
|
+
_readOptions() {
|
|
116
|
+
return this._optionsProp ? this._optionsProp : (this._snapshotDeclared(), this._declared || []);
|
|
117
|
+
}
|
|
118
|
+
render() {
|
|
119
|
+
this._snapshotDeclared();
|
|
120
|
+
let e = this.getAttribute("placeholder") || "Search…", t = this.getAttribute("size"), n = t === "sm" ? " search-select-sm" : t === "lg" ? " search-select-lg" : "";
|
|
121
|
+
this.id ||= `wui-autocomplete-${Math.random().toString(36).slice(2, 9)}`;
|
|
122
|
+
let r = `${this.id}-listbox`;
|
|
123
|
+
this._listboxId = r, this.innerHTML = `
|
|
124
|
+
<div class="search-select${n}">
|
|
125
|
+
<div class="input search-select-control search-select-ac" role="combobox" aria-haspopup="listbox" aria-expanded="false" aria-controls="${f(r)}" aria-label="${f(this._accessibleName())}"${this.hasAttribute("aria-invalid") ? " aria-invalid=\"true\"" : ""}>
|
|
126
|
+
<input class="search-select-input search-select-ac-input" placeholder="${f(e)}" aria-autocomplete="list" autocomplete="off"${this.hasAttribute("disabled") ? " disabled" : ""} />
|
|
127
|
+
<span class="search-select-spinner spinner-border spinner-border-sm" role="status" aria-hidden="true" hidden></span>
|
|
128
|
+
<button type="button" class="search-select-clear" aria-label="Clear" hidden>${a("x")}</button>
|
|
129
|
+
</div>
|
|
130
|
+
<div class="search-select-menu search-select-menu-fixed" role="listbox" id="${f(r)}" tabindex="-1" hidden>
|
|
131
|
+
<div class="search-select-options"></div>
|
|
132
|
+
<div class="search-select-empty" hidden>No matches</div>
|
|
133
|
+
<div class="search-select-hint" hidden>Type to search…</div>
|
|
134
|
+
</div>
|
|
135
|
+
</div>`, this._rendered = !0, i(this, this._value), this._wire(), this._syncInput(), this._renderOptions();
|
|
136
|
+
}
|
|
137
|
+
_refs() {
|
|
138
|
+
return {
|
|
139
|
+
control: this.querySelector(".search-select-control"),
|
|
140
|
+
input: this.querySelector(".search-select-ac-input"),
|
|
141
|
+
menu: this.querySelector(".search-select-menu"),
|
|
142
|
+
spinner: this.querySelector(".search-select-spinner"),
|
|
143
|
+
clear: this.querySelector(".search-select-clear"),
|
|
144
|
+
optionsWrap: this.querySelector(".search-select-options"),
|
|
145
|
+
empty: this.querySelector(".search-select-empty"),
|
|
146
|
+
hint: this.querySelector(".search-select-hint")
|
|
147
|
+
};
|
|
148
|
+
}
|
|
149
|
+
_optionEls() {
|
|
150
|
+
return [...this.querySelectorAll(".search-select-option")];
|
|
151
|
+
}
|
|
152
|
+
_syncInput() {
|
|
153
|
+
let { input: e, clear: t } = this._refs();
|
|
154
|
+
e && document.activeElement !== e && (e.value = this._label), t && (t.hidden = !this._value && !e?.value);
|
|
155
|
+
}
|
|
156
|
+
_renderLoading() {
|
|
157
|
+
let { spinner: e } = this._refs();
|
|
158
|
+
e && (e.hidden = !this._loading);
|
|
159
|
+
}
|
|
160
|
+
_renderOptions(e) {
|
|
161
|
+
let t = this._refs();
|
|
162
|
+
if (!t.optionsWrap) return;
|
|
163
|
+
let n = e ?? (t.input ? t.input.value : ""), r = n.trim().toLowerCase(), i = this._readOptions();
|
|
164
|
+
!this._remote && r && (i = i.filter((e) => p(e.label).toLowerCase().includes(r)));
|
|
165
|
+
let a = n.trim(), o = this._allowCustom && a && !this._matchesKnownOption(a) ? [...i, {
|
|
166
|
+
value: a,
|
|
167
|
+
custom: !0
|
|
168
|
+
}] : i, s = this._listboxId || `${this.id || "wui-autocomplete"}-listbox`;
|
|
169
|
+
t.optionsWrap.innerHTML = o.map((e, t) => {
|
|
170
|
+
let n = `${s}-opt-${t}`;
|
|
171
|
+
if (e.custom) {
|
|
172
|
+
let t = `Add “${c(e.value)}”`;
|
|
173
|
+
return `<button type="button" role="option" id="${f(n)}" class="search-select-option search-select-option-custom" data-value="${f(e.value)}" data-custom="true" aria-selected="false">${t}</button>`;
|
|
174
|
+
}
|
|
175
|
+
let r = String(e.value) === String(this._value);
|
|
176
|
+
return `<button type="button" role="option" id="${f(n)}" class="search-select-option${r ? " selected" : ""}" data-value="${f(e.value)}" aria-selected="${r}">${l(e)}</button>`;
|
|
177
|
+
}).join(""), this._active = -1, t.control?.removeAttribute("aria-activedescendant");
|
|
178
|
+
let u = r.length < this._minChars;
|
|
179
|
+
t.hint && (t.hint.hidden = !(this._remote && u && !i.length)), t.empty && (t.empty.hidden = this._loading || o.length > 0 || this._remote && u), this._reanchor?.();
|
|
180
|
+
}
|
|
181
|
+
_wire() {
|
|
182
|
+
this._teardown();
|
|
183
|
+
let e = this._refs();
|
|
184
|
+
if (!e.control || !e.input) return;
|
|
185
|
+
let a = () => r(e.control, e.menu, { matchWidth: !0 }), c = () => this._optionEls().filter((e) => !e.hidden), l = (t, { reveal: n = !0 } = {}) => {
|
|
186
|
+
let r = c();
|
|
187
|
+
this._active = t, o(e.optionsWrap, t >= 0 && r[t] || null), t >= 0 && r[t] ? (n && r[t].scrollIntoView({ block: "nearest" }), e.control.setAttribute("aria-activedescendant", r[t].id)) : e.control.removeAttribute("aria-activedescendant");
|
|
188
|
+
}, u = () => !e.menu.hidden, d = () => {
|
|
189
|
+
u() && a();
|
|
190
|
+
}, f = () => {
|
|
191
|
+
e.menu.hidden = !1, e.control.setAttribute("aria-expanded", "true"), e.control.classList.add("open"), a(), t(this, d), this._renderOptions();
|
|
192
|
+
}, m = () => {
|
|
193
|
+
e.menu.hidden = !0, e.control.setAttribute("aria-expanded", "false"), e.control.classList.remove("open"), l(-1), clearTimeout(this._typeaheadTimer), this._typeaheadTimer = null, this._typeahead = "", this._syncInput(), n(this);
|
|
194
|
+
}, h = (t) => {
|
|
195
|
+
let n = t.dataset.custom === "true";
|
|
196
|
+
this._value = t.dataset.value, this._label = n ? t.dataset.value : p(t.innerHTML), i(this, this._value), e.input.value = this._label, this.dispatchEvent(new CustomEvent("change", {
|
|
197
|
+
bubbles: !0,
|
|
198
|
+
detail: { isCustom: n }
|
|
199
|
+
})), m(), e.input.focus();
|
|
200
|
+
}, g = (t) => {
|
|
201
|
+
this._value = t, this._label = t, i(this, t), e.input.value = t, this.dispatchEvent(new CustomEvent("change", {
|
|
202
|
+
bubbles: !0,
|
|
203
|
+
detail: { isCustom: !0 }
|
|
204
|
+
})), m();
|
|
205
|
+
}, _ = () => {
|
|
206
|
+
let t = e.input.value;
|
|
207
|
+
if (e.clear && (e.clear.hidden = !t), u() || f(), this._remote) {
|
|
208
|
+
if (this._renderOptions(t), clearTimeout(this._timer), t.trim().length < this._minChars) {
|
|
209
|
+
this._pendingSearch = null;
|
|
210
|
+
return;
|
|
211
|
+
}
|
|
212
|
+
let e = ++this._reqSeq;
|
|
213
|
+
this._pendingSearch = {
|
|
214
|
+
query: t,
|
|
215
|
+
seq: e
|
|
216
|
+
}, this._timer = setTimeout(() => this._fireSearch(t, e), this._debounceMs);
|
|
217
|
+
} else this._renderOptions(t);
|
|
218
|
+
};
|
|
219
|
+
this._navHandler = s({
|
|
220
|
+
getVisibleOptions: c,
|
|
221
|
+
getActive: () => this._active,
|
|
222
|
+
setActive: (e) => l(e),
|
|
223
|
+
onEnter: (t, n) => {
|
|
224
|
+
if (n[this._active]) h(n[this._active]);
|
|
225
|
+
else if (this._allowCustom) {
|
|
226
|
+
let t = e.input.value.trim();
|
|
227
|
+
t && !this._matchesKnownOption(t) && g(t);
|
|
228
|
+
}
|
|
229
|
+
},
|
|
230
|
+
onEscape: () => {
|
|
231
|
+
this._navHandler.clearTypeahead(), m();
|
|
232
|
+
}
|
|
233
|
+
});
|
|
234
|
+
let v = (e) => {
|
|
235
|
+
let t = e.target?.tagName === "INPUT" || e.target?.tagName === "TEXTAREA";
|
|
236
|
+
if (e.key === "ArrowDown") {
|
|
237
|
+
e.preventDefault(), u() || f();
|
|
238
|
+
let t = c();
|
|
239
|
+
l(Math.min(this._active + 1, t.length - 1));
|
|
240
|
+
return;
|
|
241
|
+
} else if (e.key === "ArrowUp") {
|
|
242
|
+
e.preventDefault(), l(Math.max(this._active - 1, 0));
|
|
243
|
+
return;
|
|
244
|
+
} else if ((e.key === "Home" || e.key === "End" || e.key === "PageDown" || e.key === "PageUp") && (!u() || t)) return;
|
|
245
|
+
else if (e.key.length === 1 && (e.ctrlKey || e.metaKey || e.altKey || !u() || e.target?.tagName === "INPUT" || e.target?.tagName === "TEXTAREA") && (!u() || e.target?.tagName === "INPUT" || e.target?.tagName === "TEXTAREA")) return;
|
|
246
|
+
this._navHandler.handler(e);
|
|
247
|
+
};
|
|
248
|
+
e.input.addEventListener("focus", () => f()), e.input.addEventListener("input", _), e.input.addEventListener("keydown", v), e.menu.addEventListener("keydown", v), e.input.addEventListener("blur", (t) => {
|
|
249
|
+
if (!this._allowCustom || t.relatedTarget && this.contains(t.relatedTarget)) return;
|
|
250
|
+
let n = e.input.value.trim();
|
|
251
|
+
!n || n === this._label || this._matchesKnownOption(n) || g(n);
|
|
252
|
+
}), e.optionsWrap.addEventListener("click", (e) => {
|
|
253
|
+
let t = e.target.closest(".search-select-option");
|
|
254
|
+
t && h(t);
|
|
255
|
+
}), e.optionsWrap.addEventListener("mousemove", (e) => {
|
|
256
|
+
let t = e.target.closest(".search-select-option");
|
|
257
|
+
t && !t.classList.contains("is-active") && l(this._optionEls().indexOf(t), { reveal: !1 });
|
|
258
|
+
}), e.optionsWrap.addEventListener("mouseleave", () => l(-1)), e.clear?.addEventListener("click", () => {
|
|
259
|
+
this._value = "", this._label = "", i(this, ""), e.input.value = "", e.clear.hidden = !0, this._renderOptions(""), this.dispatchEvent(new Event("change", { bubbles: !0 })), e.input.focus();
|
|
260
|
+
}), this._bindGlobal = () => {
|
|
261
|
+
this._teardown(), this._onDocClick = (e) => {
|
|
262
|
+
u() && !this.contains(e.target) && m();
|
|
263
|
+
}, document.addEventListener("click", this._onDocClick), u() && t(this, d);
|
|
264
|
+
}, this._bindGlobal();
|
|
265
|
+
}
|
|
266
|
+
_fireSearch(e, t) {
|
|
267
|
+
this._pendingSearch = null, this.dispatchEvent(new CustomEvent("search", {
|
|
268
|
+
bubbles: !0,
|
|
269
|
+
detail: {
|
|
270
|
+
query: e,
|
|
271
|
+
seq: t
|
|
272
|
+
}
|
|
273
|
+
}));
|
|
274
|
+
}
|
|
275
|
+
_teardown() {
|
|
276
|
+
this._onDocClick &&= (document.removeEventListener("click", this._onDocClick), null), n(this), clearTimeout(this._timer), this._navHandler?.teardown();
|
|
277
|
+
}
|
|
278
|
+
disconnectedCallback() {
|
|
279
|
+
this._teardown();
|
|
280
|
+
}
|
|
281
|
+
}, f = (e) => String(e ?? "").replace(/&/g, "&").replace(/"/g, """).replace(/</g, "<"), p = (e) => String(e ?? "").replace(/<[^>]*>/g, "");
|
|
282
|
+
//#endregion
|
|
283
|
+
export { d as t };
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
import { t as e } from "./elementBase-Bg1xpvup.js";
|
|
2
|
+
import { n as t } from "./optionLabel-Dn-I7zyp.js";
|
|
3
|
+
import { t as n } from "./textMatch-DEUjlkdy.js";
|
|
4
|
+
//#region src/WuiCommandPalette.js
|
|
5
|
+
var r = "[role=\"option\"]", i = "No results", a = class extends e {
|
|
6
|
+
static get observedAttributes() {
|
|
7
|
+
return [
|
|
8
|
+
"filter",
|
|
9
|
+
"highlight",
|
|
10
|
+
"empty-text"
|
|
11
|
+
];
|
|
12
|
+
}
|
|
13
|
+
constructor() {
|
|
14
|
+
super(), this._activeId = null, this._lastQuery = null, this._lastIds = null, this._userChose = !1, this._onKeyDown = (e) => this._handleKeyDown(e), this._onClick = (e) => {
|
|
15
|
+
let t = this._optionFrom(e.target);
|
|
16
|
+
t && this._select(t);
|
|
17
|
+
}, this._onMouseDown = (e) => {
|
|
18
|
+
this._optionFrom(e.target, !0) && e.preventDefault();
|
|
19
|
+
}, this._onMouseMove = (e) => {
|
|
20
|
+
let t = this._optionFrom(e.target);
|
|
21
|
+
t && t.id !== this._activeId && (this._userChose = !0, this._setActive(t, !1));
|
|
22
|
+
}, this._onInput = (e) => {
|
|
23
|
+
!this.hasAttribute("filter") || e.target !== this._input() || (this._applyFilter(), this.refresh());
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
connectedCallback() {
|
|
27
|
+
this._teardown(), this.addEventListener("keydown", this._onKeyDown), this.addEventListener("click", this._onClick), this.addEventListener("mousedown", this._onMouseDown), this.addEventListener("mousemove", this._onMouseMove), this.addEventListener("input", this._onInput), this.hasAttribute("filter") && this._applyFilter(), this.refresh();
|
|
28
|
+
}
|
|
29
|
+
disconnectedCallback() {
|
|
30
|
+
this._teardown();
|
|
31
|
+
}
|
|
32
|
+
attributeChangedCallback() {
|
|
33
|
+
this.isConnected && (this.hasAttribute("filter") && this._applyFilter(), this.refresh());
|
|
34
|
+
}
|
|
35
|
+
get filter() {
|
|
36
|
+
return this.hasAttribute("filter");
|
|
37
|
+
}
|
|
38
|
+
set filter(e) {
|
|
39
|
+
this.toggleAttribute("filter", !!e);
|
|
40
|
+
}
|
|
41
|
+
get highlight() {
|
|
42
|
+
return this.getAttribute("highlight") !== "false";
|
|
43
|
+
}
|
|
44
|
+
set highlight(e) {
|
|
45
|
+
this.setAttribute("highlight", e ? "true" : "false");
|
|
46
|
+
}
|
|
47
|
+
get emptyText() {
|
|
48
|
+
return this.getAttribute("empty-text") ?? i;
|
|
49
|
+
}
|
|
50
|
+
set emptyText(e) {
|
|
51
|
+
this.setAttribute("empty-text", String(e ?? ""));
|
|
52
|
+
}
|
|
53
|
+
refresh() {
|
|
54
|
+
let e = this._input(), t = e ? e.value : "", n = t !== this._lastQuery;
|
|
55
|
+
this._lastQuery = t;
|
|
56
|
+
let r = this._selectableOptions(), i = r.map((e) => e.id).join("\n"), a = i !== this._lastIds;
|
|
57
|
+
this._lastIds = i;
|
|
58
|
+
let o = !n && (this._userChose || !a) ? r.find((e) => e.id === this._activeId) : null;
|
|
59
|
+
o || (this._userChose = !1), this._setActive(o ?? r[0] ?? null, n);
|
|
60
|
+
}
|
|
61
|
+
_input() {
|
|
62
|
+
return this.querySelector("[role=\"combobox\"]");
|
|
63
|
+
}
|
|
64
|
+
_optionFrom(e, t = !1) {
|
|
65
|
+
let n = e?.closest?.(r);
|
|
66
|
+
return n && this.contains(n) && !this._isHidden(n) && (t || !this._isDisabled(n)) ? n : null;
|
|
67
|
+
}
|
|
68
|
+
_isDisabled(e) {
|
|
69
|
+
return e.getAttribute("aria-disabled") === "true";
|
|
70
|
+
}
|
|
71
|
+
_isHidden(e) {
|
|
72
|
+
return e.hidden || !!e.closest("[role=\"group\"]")?.hidden;
|
|
73
|
+
}
|
|
74
|
+
_selectableOptions() {
|
|
75
|
+
return [...this.querySelectorAll(r)].filter((e) => !this._isHidden(e) && !this._isDisabled(e));
|
|
76
|
+
}
|
|
77
|
+
_setActive(e, t) {
|
|
78
|
+
this._activeId = e ? e.id : null;
|
|
79
|
+
for (let t of this.querySelectorAll(r)) t.setAttribute("aria-selected", t === e ? "true" : "false");
|
|
80
|
+
let n = this._input();
|
|
81
|
+
n && (e ? n.setAttribute("aria-activedescendant", e.id) : n.removeAttribute("aria-activedescendant")), e && t && e.scrollIntoView({ block: "nearest" });
|
|
82
|
+
}
|
|
83
|
+
_move(e) {
|
|
84
|
+
let t = this._selectableOptions();
|
|
85
|
+
if (!t.length) return;
|
|
86
|
+
let n = t.findIndex((e) => e.id === this._activeId), r = n < 0 ? e > 0 ? 0 : t.length - 1 : (n + e + t.length) % t.length;
|
|
87
|
+
this._userChose = !0, this._setActive(t[r], !0);
|
|
88
|
+
}
|
|
89
|
+
_handleKeyDown(e) {
|
|
90
|
+
if (e.target === this._input()) {
|
|
91
|
+
if (e.key === "ArrowDown" || e.key === "ArrowUp") e.preventDefault(), this._move(e.key === "ArrowDown" ? 1 : -1);
|
|
92
|
+
else if (e.key === "Enter" && !e.isComposing) {
|
|
93
|
+
let t = this._selectableOptions().find((e) => e.id === this._activeId);
|
|
94
|
+
if (!t) return;
|
|
95
|
+
e.preventDefault(), this._select(t);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
_select(e) {
|
|
100
|
+
this.dispatchEvent(new CustomEvent("wui-command-palette:select", {
|
|
101
|
+
bubbles: !0,
|
|
102
|
+
cancelable: !0,
|
|
103
|
+
detail: {
|
|
104
|
+
key: e.dataset.key ?? null,
|
|
105
|
+
groupKey: e.dataset.groupKey ?? null,
|
|
106
|
+
id: e.id
|
|
107
|
+
}
|
|
108
|
+
})) && e.dataset.href && this._navigate(e.dataset.href);
|
|
109
|
+
}
|
|
110
|
+
_navigate(e) {
|
|
111
|
+
window.location.assign(e);
|
|
112
|
+
}
|
|
113
|
+
_applyFilter() {
|
|
114
|
+
let e = this._input(), i = (e ? e.value : "").trim(), a = i.toLowerCase(), o = this.highlight, s = 0;
|
|
115
|
+
for (let e of this.querySelectorAll(r)) {
|
|
116
|
+
let r = e.querySelector(".wui-cmd-item-label"), c = e.dataset.label ?? r?.textContent ?? "", l = !a || c.toLowerCase().includes(a);
|
|
117
|
+
e.hidden = !l, l && s++, r && (r.innerHTML = n(c, o ? i : "").map((e) => e.match ? `<mark class="wui-cmd-mark">${t(e.text)}</mark>` : t(e.text)).join(""));
|
|
118
|
+
}
|
|
119
|
+
for (let e of this.querySelectorAll("[role=\"group\"]")) e.hidden = ![...e.querySelectorAll(r)].some((e) => !e.hidden);
|
|
120
|
+
let c = this.querySelector("[role=\"listbox\"]");
|
|
121
|
+
c && (c.hidden = s === 0);
|
|
122
|
+
let l = this.querySelector(".wui-cmd-empty");
|
|
123
|
+
l && (l.textContent = a && s === 0 ? this.emptyText : "");
|
|
124
|
+
}
|
|
125
|
+
_teardown() {
|
|
126
|
+
this.removeEventListener("keydown", this._onKeyDown), this.removeEventListener("click", this._onClick), this.removeEventListener("mousedown", this._onMouseDown), this.removeEventListener("mousemove", this._onMouseMove), this.removeEventListener("input", this._onInput);
|
|
127
|
+
}
|
|
128
|
+
};
|
|
129
|
+
//#endregion
|
|
130
|
+
export { a as t };
|