@mhmo91/schmancy 0.2.198 → 0.2.199
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/autocomplete-87RcHRRv.js +324 -0
- package/dist/autocomplete-87RcHRRv.js.map +1 -0
- package/dist/autocomplete-B4F-i4IH.cjs +73 -0
- package/dist/autocomplete-B4F-i4IH.cjs.map +1 -0
- package/dist/autocomplete.cjs +1 -1
- package/dist/autocomplete.js +1 -1
- package/dist/{avatar-COYuuamy.cjs → avatar-DI6tP5aD.cjs} +2 -2
- package/dist/{avatar-COYuuamy.cjs.map → avatar-DI6tP5aD.cjs.map} +1 -1
- package/dist/{avatar-CTMclGHR.js → avatar-Dx-kdZaM.js} +2 -2
- package/dist/{avatar-CTMclGHR.js.map → avatar-Dx-kdZaM.js.map} +1 -1
- package/dist/badge.cjs +1 -1
- package/dist/badge.js +1 -1
- package/dist/card.cjs +1 -1
- package/dist/card.js +1 -1
- package/dist/content-drawer.cjs +1 -1
- package/dist/content-drawer.js +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.js +2 -2
- package/dist/nav-drawer.cjs +1 -1
- package/dist/nav-drawer.js +1 -1
- package/dist/teleport.cjs +1 -1
- package/dist/teleport.js +1 -1
- package/package.json +1 -1
- package/types/src/autocomplete/autocomplete.d.ts +18 -108
- package/types/src/utils/search.d.ts +1 -1
- package/dist/autocomplete-B36XAOQm.cjs +0 -56
- package/dist/autocomplete-B36XAOQm.cjs.map +0 -1
- package/dist/autocomplete-BD8oV6Se.js +0 -259
- package/dist/autocomplete-BD8oV6Se.js.map +0 -1
|
@@ -0,0 +1,324 @@
|
|
|
1
|
+
import { BehaviorSubject as S, Subject as O, fromEvent as E, combineLatest as L, timer as y, of as j, EMPTY as N, merge as z } from "rxjs";
|
|
2
|
+
import { classMap as H } from "lit/directives/class-map.js";
|
|
3
|
+
import "lit/directives/style-map.js";
|
|
4
|
+
import { $ as B } from "./litElement.mixin-BKgKxczr.js";
|
|
5
|
+
import "./tailwind.mixin-k9HTphsu.js";
|
|
6
|
+
import { html as M } from "lit";
|
|
7
|
+
import { property as _, state as R, query as I, queryAssignedElements as F, customElement as U } from "lit/decorators.js";
|
|
8
|
+
import { createRef as W, ref as K } from "lit/directives/ref.js";
|
|
9
|
+
import { tap as h, takeUntil as v, distinctUntilChanged as q, debounceTime as Y, withLatestFrom as C, take as w, filter as x, switchMap as A, startWith as G, map as T } from "rxjs/operators";
|
|
10
|
+
function D(e, t) {
|
|
11
|
+
if (!e || !t) return 0;
|
|
12
|
+
if (e === t) return 1;
|
|
13
|
+
const i = e.toLowerCase().trim(), s = t.toLowerCase().trim();
|
|
14
|
+
if (i === s) return 1;
|
|
15
|
+
if (s.startsWith(i))
|
|
16
|
+
return 0.95 + 0.05 * (i.length / s.length);
|
|
17
|
+
const n = s.split(/[\s\-_]+/);
|
|
18
|
+
for (const u of n) if (u.startsWith(i))
|
|
19
|
+
return 0.85 * (1 - n.indexOf(u) / n.length * 0.1);
|
|
20
|
+
if (s.includes(i))
|
|
21
|
+
return 0.7 * (1 - s.indexOf(i) / s.length * 0.2);
|
|
22
|
+
if (function(u, d) {
|
|
23
|
+
let a = 0, l = 0;
|
|
24
|
+
for (; a < u.length && l < d.length; ) u[a] === d[l] && a++, l++;
|
|
25
|
+
return a === u.length;
|
|
26
|
+
}(i, s)) return 0.5;
|
|
27
|
+
const o = function(u, d) {
|
|
28
|
+
if (u.length < 2 || d.length < 2) return 0;
|
|
29
|
+
const a = P(u), l = P(d);
|
|
30
|
+
let $ = 0;
|
|
31
|
+
const g = new Array(l.length).fill(!1);
|
|
32
|
+
for (const k of a) for (let V = 0; V < l.length; V++) if (!g[V] && l[V] === k) {
|
|
33
|
+
$++, g[V] = !0;
|
|
34
|
+
break;
|
|
35
|
+
}
|
|
36
|
+
return 2 * $ / (a.length + l.length);
|
|
37
|
+
}(i, s), r = Math.max(i.length, s.length), m = function(u, d) {
|
|
38
|
+
if (u.length === 0) return d.length;
|
|
39
|
+
if (d.length === 0) return u.length;
|
|
40
|
+
const a = [];
|
|
41
|
+
for (let l = 0; l <= d.length; l++) a[l] = [l];
|
|
42
|
+
for (let l = 0; l <= u.length; l++) a[0][l] = l;
|
|
43
|
+
for (let l = 1; l <= d.length; l++) for (let $ = 1; $ <= u.length; $++) {
|
|
44
|
+
const g = u[$ - 1] === d[l - 1] ? 0 : 1;
|
|
45
|
+
a[l][$] = Math.min(a[l - 1][$] + 1, a[l][$ - 1] + 1, a[l - 1][$ - 1] + g);
|
|
46
|
+
}
|
|
47
|
+
return a[d.length][u.length];
|
|
48
|
+
}(i, s), f = r ? 1 - m / r : 0, b = function(u, d) {
|
|
49
|
+
const a = (g) => g.split("").reduce((k, V) => (k[V] = (k[V] || 0) + 1, k), {}), l = a(u), $ = a(d);
|
|
50
|
+
return Object.keys(l).every((g) => ($[g] || 0) >= l[g]);
|
|
51
|
+
}(i, s) ? 0.3 : 0;
|
|
52
|
+
return Math.max(0.4 * o, 0.4 * f, b);
|
|
53
|
+
}
|
|
54
|
+
function P(e) {
|
|
55
|
+
const t = [];
|
|
56
|
+
for (let i = 0; i < e.length - 1; i++) t.push(e.substring(i, i + 2));
|
|
57
|
+
return t;
|
|
58
|
+
}
|
|
59
|
+
var J = Object.defineProperty, Q = Object.getOwnPropertyDescriptor, c = (e, t, i, s) => {
|
|
60
|
+
for (var n, o = s > 1 ? void 0 : s ? Q(t, i) : t, r = e.length - 1; r >= 0; r--) (n = e[r]) && (o = (s ? n(t, i, o) : n(o)) || o);
|
|
61
|
+
return s && o && J(t, i, o), o;
|
|
62
|
+
};
|
|
63
|
+
let p = class extends B(":host{display:block;border:unset!important;line-height:unset!important;background:unset!important;padding:unset!important;font-size:unset!important;box-shadow:unset!important}:host:focus{box-shadow:unset!important}") {
|
|
64
|
+
constructor() {
|
|
65
|
+
super(...arguments), this.required = !1, this.placeholder = "", this.label = "", this.name = "", this.maxHeight = "300px", this.multi = !1, this.description = "", this.size = "md", this.autocomplete = "on", this.debounceMs = 200, this.similarityThreshold = 0.3, this._open = !1, this._inputValue = "", this._visibleOptionsCount = 0, this._hasResults = !0, this._inputElementRef = W(), this._selectedValue$ = new S(""), this._selectedValues$ = new S([]), this._inputValue$ = new S(""), this._open$ = new S(!1), this._options$ = new S([]), this._optionSelect$ = new O(), this._documentClick$ = new O(), this._checkAutofill$ = new O();
|
|
66
|
+
}
|
|
67
|
+
get values() {
|
|
68
|
+
return [...this._selectedValues$.value];
|
|
69
|
+
}
|
|
70
|
+
set values(e) {
|
|
71
|
+
this._selectedValues$.next(Array.isArray(e) ? [...e] : []);
|
|
72
|
+
}
|
|
73
|
+
get value() {
|
|
74
|
+
return this.multi ? this._selectedValues$.value.join(",") : this._selectedValue$.value;
|
|
75
|
+
}
|
|
76
|
+
set value(e) {
|
|
77
|
+
this.multi ? this._selectedValues$.next(e ? e.split(",").map((t) => t.trim()).filter(Boolean) : []) : this._selectedValue$.next(e);
|
|
78
|
+
}
|
|
79
|
+
connectedCallback() {
|
|
80
|
+
super.connectedCallback(), this.id || (this.id = `sch-autocomplete-${Math.random().toString(36).slice(2, 9)}`), this._setupAutocompleteLogic(), this._setupDocumentClickHandler(), this._setupAutofillDetection();
|
|
81
|
+
}
|
|
82
|
+
_setupAutocompleteLogic() {
|
|
83
|
+
this._options$.pipe(h((e) => {
|
|
84
|
+
e.forEach((t, i) => {
|
|
85
|
+
t.setAttribute("role", "option"), t.tabIndex = -1, t.id || (t.id = `${this.id}-option-${i}`), t.hasAttribute("data-event-bound") || (E(t, "click").pipe(h((s) => s.stopPropagation()), v(this.disconnecting)).subscribe(() => this._optionSelect$.next(t)), t.setAttribute("data-event-bound", "true"));
|
|
86
|
+
});
|
|
87
|
+
}), v(this.disconnecting)).subscribe(), L([this._selectedValue$, this._selectedValues$, this._options$]).pipe(h(([e, t, i]) => {
|
|
88
|
+
i.forEach((s) => {
|
|
89
|
+
s.selected = this.multi ? t.includes(s.value) : s.value === e, s.setAttribute("aria-selected", String(s.selected));
|
|
90
|
+
});
|
|
91
|
+
}), v(this.disconnecting)).subscribe(), this._inputValue$.pipe(q(), Y(this.debounceMs), C(this._options$, this._open$), h(([e, t, i]) => {
|
|
92
|
+
if (!i) return;
|
|
93
|
+
const s = e.trim();
|
|
94
|
+
if (s) {
|
|
95
|
+
const n = t.map((r) => {
|
|
96
|
+
const m = r.label || r.textContent || "", f = r.value, b = D(s, m), u = D(s, f);
|
|
97
|
+
return { option: r, score: Math.max(1.1 * b, u) };
|
|
98
|
+
});
|
|
99
|
+
n.sort((r, m) => m.score - r.score);
|
|
100
|
+
let o = 0;
|
|
101
|
+
n.forEach((r, m) => {
|
|
102
|
+
const { option: f, score: b } = r;
|
|
103
|
+
b < this.similarityThreshold ? f.hidden = !0 : (f.hidden = !1, o++, f.style.order = String(m));
|
|
104
|
+
}), this._visibleOptionsCount = o, this._hasResults = o > 0;
|
|
105
|
+
} else t.forEach((n) => {
|
|
106
|
+
n.hidden = !1, n.style.order = "0";
|
|
107
|
+
}), this._visibleOptionsCount = t.length, this._hasResults = !0;
|
|
108
|
+
this._announceToScreenReader(this._visibleOptionsCount > 0 ? `${this._visibleOptionsCount} option${this._visibleOptionsCount === 1 ? "" : "s"} available.` : "No results found.");
|
|
109
|
+
}), v(this.disconnecting)).subscribe(), this._optionSelect$.pipe(C(this._selectedValue$, this._selectedValues$), h(([e, t, i]) => {
|
|
110
|
+
if (this.multi) {
|
|
111
|
+
const s = i.indexOf(e.value), n = s > -1 ? [...i.slice(0, s), ...i.slice(s + 1)] : [...i, e.value];
|
|
112
|
+
this._selectedValues$.next(n), this._inputValue$.next(""), this._inputValue = "";
|
|
113
|
+
const o = this._getSelectedLabels();
|
|
114
|
+
this._announceToScreenReader(o.length > 0 ? `Selected: ${o.join(", ")}` : "No options selected");
|
|
115
|
+
} else this._selectedValue$.next(e.value), this._open$.next(!1), this._open = !1, this._inputValue = e.label || e.textContent || "", this._inputValue$.next(this._inputValue), y(100).pipe(h(() => {
|
|
116
|
+
var s;
|
|
117
|
+
return (s = this._inputElementRef.value) == null ? void 0 : s.blur();
|
|
118
|
+
}), w(1)).subscribe(), this._announceToScreenReader(`Selected: ${e.label || e.textContent}`);
|
|
119
|
+
}), h(() => this._fireChangeEvent()), v(this.disconnecting)).subscribe(), L([this._open$, this._selectedValue$, this._selectedValues$, this._options$]).pipe(x(() => !this._open$.value), h(([, e, t, i]) => {
|
|
120
|
+
if (this.multi) {
|
|
121
|
+
const s = i.filter((n) => t.includes(n.value)).map((n) => n.label || n.textContent || "");
|
|
122
|
+
this._inputValue = s.join(", ");
|
|
123
|
+
} else {
|
|
124
|
+
const s = i.find((n) => n.value === e);
|
|
125
|
+
this._inputValue = s && (s.label || s.textContent) || "";
|
|
126
|
+
}
|
|
127
|
+
this._inputValue$.next(this._inputValue);
|
|
128
|
+
}), v(this.disconnecting)).subscribe(), this._open$.pipe(h((e) => this._open = e), v(this.disconnecting)).subscribe();
|
|
129
|
+
}
|
|
130
|
+
_setupDocumentClickHandler() {
|
|
131
|
+
this._documentClick$.pipe(x((e) => !e.composedPath().includes(this)), x((e) => !this._options.some((t) => e.composedPath().includes(t))), x(() => this._open), h(() => {
|
|
132
|
+
this._open$.next(!1), this._updateInputDisplay();
|
|
133
|
+
}), v(this.disconnecting)).subscribe(), this._open$.pipe(q(), A((e) => e ? y(10).pipe(h(() => document.addEventListener("click", (t) => this._documentClick$.next(t))), A(() => N)) : j(null).pipe(h(() => document.removeEventListener("click", (t) => this._documentClick$.next(t))))), v(this.disconnecting)).subscribe();
|
|
134
|
+
}
|
|
135
|
+
_setupAutofillDetection() {
|
|
136
|
+
z(y(100, 500).pipe(w(10)), this._checkAutofill$, y(100).pipe(A(() => E(window, "load").pipe(G(null))))).pipe(T(() => {
|
|
137
|
+
var t, i;
|
|
138
|
+
const e = this._inputElementRef.value;
|
|
139
|
+
return e ? ((t = e.shadowRoot) == null ? void 0 : t.querySelector("input")) || e.querySelector("input") || ((i = e._inputRef) == null ? void 0 : i.value) : null;
|
|
140
|
+
}), x((e) => !!e), T((e) => e.value), x((e) => !!e && e.trim().length > 0), q(), C(this._options$), h(([e, t]) => {
|
|
141
|
+
let i = null, s = 0;
|
|
142
|
+
if (t.forEach((n) => {
|
|
143
|
+
const o = n.label || n.textContent || "", r = n.value, m = D(e, o), f = D(e, r), b = Math.max(m, f);
|
|
144
|
+
b > s && b >= this.similarityThreshold && (s = b, i = n);
|
|
145
|
+
}), i) {
|
|
146
|
+
this.multi ? this._selectedValues$.next([i.value]) : this._selectedValue$.next(i.value);
|
|
147
|
+
const n = i.label || i.textContent || "";
|
|
148
|
+
this._inputValue = n, this._inputValue$.next(n);
|
|
149
|
+
const o = this._inputElementRef.value;
|
|
150
|
+
o && (o.value = n), this._open$.next(!1), this._fireChangeEvent(), this._announceToScreenReader(`Autofilled: ${n}`);
|
|
151
|
+
}
|
|
152
|
+
}), v(this.disconnecting)).subscribe(), y(100).pipe(T(() => {
|
|
153
|
+
var t, i;
|
|
154
|
+
const e = this._inputElementRef.value;
|
|
155
|
+
return e ? ((t = e.shadowRoot) == null ? void 0 : t.querySelector("input")) || e.querySelector("input") || ((i = e._inputRef) == null ? void 0 : i.value) : null;
|
|
156
|
+
}), x((e) => !!e), A((e) => E(e, "animationstart").pipe(x((t) => t.animationName === "onAutoFillStart"), h(() => {
|
|
157
|
+
y(100).pipe(h(() => this._checkAutofill$.next()), w(1)).subscribe();
|
|
158
|
+
}))), v(this.disconnecting)).subscribe();
|
|
159
|
+
}
|
|
160
|
+
_updateInputDisplay() {
|
|
161
|
+
j(null).pipe(C(this._selectedValue$, this._selectedValues$, this._options$, this._open$), h(([, e, t, i, s]) => {
|
|
162
|
+
if (this._inputElementRef.value && (!s || !this.multi)) {
|
|
163
|
+
if (this.multi) {
|
|
164
|
+
const n = i.filter((o) => t.includes(o.value)).map((o) => o.label || o.textContent || "");
|
|
165
|
+
this._inputValue = n.join(", ");
|
|
166
|
+
} else {
|
|
167
|
+
const n = i.find((o) => o.value === e);
|
|
168
|
+
this._inputValue = n && (n.label || n.textContent) || "";
|
|
169
|
+
}
|
|
170
|
+
this._inputValue$.next(this._inputValue), this._inputElementRef.value.value = this._inputValue;
|
|
171
|
+
}
|
|
172
|
+
}), w(1)).subscribe();
|
|
173
|
+
}
|
|
174
|
+
_getSelectedLabels() {
|
|
175
|
+
return this._options.filter((e) => this.multi ? this._selectedValues$.value.includes(e.value) : e.value === this._selectedValue$.value).map((e) => e.label || e.textContent || "");
|
|
176
|
+
}
|
|
177
|
+
_announceToScreenReader(e) {
|
|
178
|
+
var i;
|
|
179
|
+
const t = (i = this.shadowRoot) == null ? void 0 : i.querySelector("#live-status");
|
|
180
|
+
t && (t.textContent = e);
|
|
181
|
+
}
|
|
182
|
+
_fireChangeEvent() {
|
|
183
|
+
const e = { value: this.value };
|
|
184
|
+
this.multi && (e.values = [...this._selectedValues$.value]), this.dispatchEvent(new CustomEvent("change", { detail: e, bubbles: !0, composed: !0 }));
|
|
185
|
+
}
|
|
186
|
+
checkValidity() {
|
|
187
|
+
return !this.required || (this.multi ? this._selectedValues$.value.length > 0 : !!this._selectedValue$.value);
|
|
188
|
+
}
|
|
189
|
+
reportValidity() {
|
|
190
|
+
return this._inputElementRef.value ? this._inputElementRef.value.reportValidity() : this.checkValidity();
|
|
191
|
+
}
|
|
192
|
+
firstUpdated() {
|
|
193
|
+
y(200).pipe(h(() => this._checkAutofill$.next()), w(1)).subscribe(), this._options$.pipe(x((e) => e.length > 0), h(() => this._checkAutofill$.next()), v(this.disconnecting)).subscribe();
|
|
194
|
+
}
|
|
195
|
+
render() {
|
|
196
|
+
var t;
|
|
197
|
+
const e = `${this.id}-desc`;
|
|
198
|
+
return M`
|
|
199
|
+
<div class="relative">
|
|
200
|
+
<!-- Screen reader live region -->
|
|
201
|
+
<div id="live-status" role="status" aria-live="polite" class="sr-only"></div>
|
|
202
|
+
|
|
203
|
+
<!-- Description -->
|
|
204
|
+
${this.description ? M`<div id="${e}" class="sr-only">${this.description}</div>` : ""}
|
|
205
|
+
|
|
206
|
+
<!-- Input -->
|
|
207
|
+
<slot name="trigger">
|
|
208
|
+
<sch-input
|
|
209
|
+
.size=${this.size}
|
|
210
|
+
${K(this._inputElementRef)}
|
|
211
|
+
id="autocomplete-input"
|
|
212
|
+
class="w-full"
|
|
213
|
+
.name=${this.name || ((t = this.label) == null ? void 0 : t.toLowerCase().replace(/\s+/g, "-"))}
|
|
214
|
+
.label=${this.label}
|
|
215
|
+
.placeholder=${this.placeholder}
|
|
216
|
+
.required=${this.required}
|
|
217
|
+
.value=${this._inputValue}
|
|
218
|
+
type="text"
|
|
219
|
+
autocomplete=${this.autocomplete}
|
|
220
|
+
clickable
|
|
221
|
+
role="combobox"
|
|
222
|
+
aria-autocomplete="list"
|
|
223
|
+
aria-haspopup="listbox"
|
|
224
|
+
aria-controls="options"
|
|
225
|
+
aria-expanded=${this._open}
|
|
226
|
+
aria-describedby=${this.description ? e : void 0}
|
|
227
|
+
@input=${(i) => {
|
|
228
|
+
const s = i.target.value;
|
|
229
|
+
this._inputValue = s, this._inputValue$.next(s);
|
|
230
|
+
}}
|
|
231
|
+
@focus=${(i) => {
|
|
232
|
+
i.stopPropagation();
|
|
233
|
+
const s = this.multi ? this._selectedValues$.value.length > 0 : !!this._selectedValue$.value;
|
|
234
|
+
this.multi && !s && (this._inputValue = "", this._inputValue$.next(""), this._inputElementRef.value && (this._inputElementRef.value.value = "")), this._open$.next(!0);
|
|
235
|
+
}}
|
|
236
|
+
@click=${(i) => {
|
|
237
|
+
i.stopPropagation(), this._open$.next(!0);
|
|
238
|
+
}}
|
|
239
|
+
@keydown=${(i) => {
|
|
240
|
+
this._handleKeyDown(i);
|
|
241
|
+
}}
|
|
242
|
+
>
|
|
243
|
+
</sch-input>
|
|
244
|
+
</slot>
|
|
245
|
+
|
|
246
|
+
<!-- Options dropdown -->
|
|
247
|
+
<ul
|
|
248
|
+
id="options"
|
|
249
|
+
class=${H({ absolute: !0, "z-[1000]": !0, "mt-1": !0, "w-full": !0, "rounded-md": !0, "shadow-md": !0, "overflow-auto": !0, "min-w-full": !0, "bg-surface-low": !0, flex: !0, "flex-col": !0 })}
|
|
250
|
+
role="listbox"
|
|
251
|
+
aria-multiselectable=${this.multi ? "true" : "false"}
|
|
252
|
+
aria-label=${`${this.label || "Options"} dropdown`}
|
|
253
|
+
?hidden=${!this._open}
|
|
254
|
+
style="max-height: ${this.maxHeight}; display: ${this._open ? "flex" : "none"};"
|
|
255
|
+
@slotchange=${() => {
|
|
256
|
+
this._options$.next(this._options), y(100).pipe(h(() => this._checkAutofill$.next()), w(1)).subscribe();
|
|
257
|
+
}}
|
|
258
|
+
>
|
|
259
|
+
<slot></slot>
|
|
260
|
+
${this._hasResults ? "" : M`
|
|
261
|
+
<li class="px-3 py-2 text-sm text-muted">No results found</li>
|
|
262
|
+
`}
|
|
263
|
+
</ul>
|
|
264
|
+
</div>
|
|
265
|
+
|
|
266
|
+
<style>
|
|
267
|
+
:host {
|
|
268
|
+
display: block;
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
@keyframes onAutoFillStart {
|
|
272
|
+
from {/**/}
|
|
273
|
+
to {/**/}
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
sch-input::part(input):-webkit-autofill,
|
|
277
|
+
sch-input input:-webkit-autofill {
|
|
278
|
+
animation-name: onAutoFillStart;
|
|
279
|
+
animation-duration: 1ms;
|
|
280
|
+
}
|
|
281
|
+
</style>
|
|
282
|
+
`;
|
|
283
|
+
}
|
|
284
|
+
_handleKeyDown(e) {
|
|
285
|
+
E(document, "keydown").pipe(w(1), C(this._open$, this._options$), h(([t, i, s]) => {
|
|
286
|
+
var m, f, b, u, d;
|
|
287
|
+
if (!i && (t.key === "ArrowDown" || t.key === "Enter")) return t.preventDefault(), this._open$.next(!0), void y(10).pipe(h(() => {
|
|
288
|
+
const a = s.find((l) => !l.hidden);
|
|
289
|
+
a == null || a.focus();
|
|
290
|
+
}), w(1)).subscribe();
|
|
291
|
+
if (!i) return;
|
|
292
|
+
const n = s.filter((a) => !a.hidden).sort((a, l) => parseInt(a.style.order || "0") - parseInt(l.style.order || "0")), o = n.find((a) => a === document.activeElement), r = o ? n.indexOf(o) : -1;
|
|
293
|
+
switch (t.key) {
|
|
294
|
+
case "Escape":
|
|
295
|
+
t.preventDefault(), this._open$.next(!1), this._updateInputDisplay(), (m = this._inputElementRef.value) == null || m.focus();
|
|
296
|
+
break;
|
|
297
|
+
case "Tab":
|
|
298
|
+
this._open$.next(!1), this._updateInputDisplay();
|
|
299
|
+
break;
|
|
300
|
+
case "ArrowDown":
|
|
301
|
+
t.preventDefault();
|
|
302
|
+
const a = r < n.length - 1 ? r + 1 : 0;
|
|
303
|
+
(f = n[a]) == null || f.focus();
|
|
304
|
+
break;
|
|
305
|
+
case "ArrowUp":
|
|
306
|
+
t.preventDefault();
|
|
307
|
+
const l = r > 0 ? r - 1 : n.length - 1;
|
|
308
|
+
(b = n[l]) == null || b.focus();
|
|
309
|
+
break;
|
|
310
|
+
case "Home":
|
|
311
|
+
t.preventDefault(), (u = n[0]) == null || u.focus();
|
|
312
|
+
break;
|
|
313
|
+
case "End":
|
|
314
|
+
t.preventDefault(), (d = n[n.length - 1]) == null || d.focus();
|
|
315
|
+
break;
|
|
316
|
+
case "Enter":
|
|
317
|
+
case " ":
|
|
318
|
+
o && (t.preventDefault(), this._optionSelect$.next(o));
|
|
319
|
+
}
|
|
320
|
+
})).subscribe();
|
|
321
|
+
}
|
|
322
|
+
};
|
|
323
|
+
c([_({ type: Boolean })], p.prototype, "required", 2), c([_({ type: String })], p.prototype, "placeholder", 2), c([_({ type: String, reflect: !0 })], p.prototype, "label", 2), c([_({ type: String })], p.prototype, "name", 2), c([_({ type: String })], p.prototype, "maxHeight", 2), c([_({ type: Boolean })], p.prototype, "multi", 2), c([_({ type: String })], p.prototype, "description", 2), c([_({ type: String, reflect: !0 })], p.prototype, "size", 2), c([_({ type: String })], p.prototype, "autocomplete", 2), c([_({ type: Number })], p.prototype, "debounceMs", 2), c([_({ type: Number })], p.prototype, "similarityThreshold", 2), c([_({ type: Array })], p.prototype, "values", 1), c([_({ type: String, reflect: !0 })], p.prototype, "value", 1), c([R()], p.prototype, "_open", 2), c([R()], p.prototype, "_inputValue", 2), c([R()], p.prototype, "_visibleOptionsCount", 2), c([R()], p.prototype, "_hasResults", 2), c([I("#options")], p.prototype, "_listbox", 2), c([I("sch-input")], p.prototype, "_input", 2), c([F({ flatten: !0 })], p.prototype, "_options", 2), p = c([U("schmancy-autocomplete")], p);
|
|
324
|
+
//# sourceMappingURL=autocomplete-87RcHRRv.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"autocomplete-87RcHRRv.js","sources":["../src/utils/search.ts","../src/autocomplete/autocomplete.ts"],"sourcesContent":["/**\n * Calculate similarity score between two strings.\n * Returns a value between 0 (no match) and 1 (exact match).\n * Optimized for autocomplete with prioritization of start matches and whole words.\n *\n * @param query The search query string\n * @param target The target string to compare against\n * @returns A similarity score from 0 to 1\n */\nexport function similarity(query: string, target: string): number {\n\t// Handle edge cases\n\tif (!query || !target) return 0\n\tif (query === target) return 1\n\n\t// Normalize strings for comparison\n\tconst normalizedQuery = query.toLowerCase().trim()\n\tconst normalizedTarget = target.toLowerCase().trim()\n\n\t// 1. Exact match (case-insensitive)\n\tif (normalizedQuery === normalizedTarget) return 1\n\n\t// 2. Target starts with query (highest priority for autocomplete)\n\tif (normalizedTarget.startsWith(normalizedQuery)) {\n\t\t// Give higher score to shorter targets (more precise matches)\n\t\tconst lengthRatio = normalizedQuery.length / normalizedTarget.length\n\t\treturn 0.95 + (lengthRatio * 0.05) // Score between 0.95 and 1.0\n\t}\n\n\t// 3. Word boundary match (query matches start of any word in target)\n\tconst words = normalizedTarget.split(/[\\s\\-_]+/)\n\tfor (const word of words) {\n\t\tif (word.startsWith(normalizedQuery)) {\n\t\t\t// Score based on which word matched (earlier words score higher)\n\t\t\tconst wordIndex = words.indexOf(word)\n\t\t\tconst wordPositionScore = 1 - (wordIndex / words.length) * 0.1\n\t\t\treturn 0.85 * wordPositionScore // Score between 0.765 and 0.85\n\t\t}\n\t}\n\n\t// 4. Direct substring match (query appears anywhere in target)\n\tif (normalizedTarget.includes(normalizedQuery)) {\n\t\t// Score based on position (earlier position scores higher)\n\t\tconst position = normalizedTarget.indexOf(normalizedQuery)\n\t\tconst positionScore = 1 - (position / normalizedTarget.length) * 0.2\n\t\treturn 0.7 * positionScore // Score between 0.56 and 0.7\n\t}\n\n\t// 5. Subsequence check (all query chars appear in order)\n\tif (isSubsequence(normalizedQuery, normalizedTarget)) {\n\t\treturn 0.5\n\t}\n\n\t// 6. Fuzzy matching for typos\n\t// 6a. Dice coefficient (good for similar words)\n\tconst diceScore = diceCoefficient(normalizedQuery, normalizedTarget)\n\t\n\t// 6b. Levenshtein distance (good for typos)\n\tconst maxLength = Math.max(normalizedQuery.length, normalizedTarget.length)\n\tconst levenshteinDistance = calculateLevenshtein(normalizedQuery, normalizedTarget)\n\tconst levenshteinScore = maxLength ? 1 - levenshteinDistance / maxLength : 0\n\n\t// 6c. Character frequency match (anagram-like)\n\tconst anagramScore = hasAllCharacters(normalizedQuery, normalizedTarget) ? 0.3 : 0\n\n\t// Combine fuzzy scores with weights\n\tconst fuzzyScore = Math.max(\n\t\tdiceScore * 0.4,\n\t\tlevenshteinScore * 0.4,\n\t\tanagramScore\n\t)\n\n\treturn fuzzyScore\n}\n\n// Keep the rest of the helper functions as they are...\n/**\n * Check if string 'sub' is a subsequence of string 'str'.\n * All characters in 'sub' must appear in order in 'str'.\n */\nfunction isSubsequence(sub: string, str: string): boolean {\n\tlet i = 0,\n\t\tj = 0\n\twhile (i < sub.length && j < str.length) {\n\t\tif (sub[i] === str[j]) i++\n\t\tj++\n\t}\n\treturn i === sub.length\n}\n\n/**\n * Check if all characters in 'query' are present in 'target'.\n * For example, \"aovc\" matches \"avocados\" (anagram subset matching).\n */\nfunction hasAllCharacters(query: string, target: string): boolean {\n\tconst countChars = (s: string): Record<string, number> => {\n\t\treturn s.split('').reduce(\n\t\t\t(acc, char) => {\n\t\t\t\tacc[char] = (acc[char] || 0) + 1\n\t\t\t\treturn acc\n\t\t\t},\n\t\t\t{} as Record<string, number>,\n\t\t)\n\t}\n\n\tconst queryCount = countChars(query)\n\tconst targetCount = countChars(target)\n\n\treturn Object.keys(queryCount).every(char => (targetCount[char] || 0) >= queryCount[char])\n}\n\n/**\n * Generate bigrams for a string.\n * A bigram is a sequence of two adjacent characters.\n */\nfunction getBigrams(s: string): string[] {\n\tconst bigrams = []\n\tfor (let i = 0; i < s.length - 1; i++) {\n\t\tbigrams.push(s.substring(i, i + 2))\n\t}\n\treturn bigrams\n}\n\n/**\n * Compute Dice's coefficient for two strings based on bigrams.\n * Returns a value between 0 (no similarity) and 1 (perfect match).\n */\nfunction diceCoefficient(s1: string, s2: string): number {\n\tif (s1.length < 2 || s2.length < 2) return 0\n\n\tconst bigrams1 = getBigrams(s1)\n\tconst bigrams2 = getBigrams(s2)\n\n\tlet intersection = 0\n\tconst used = new Array(bigrams2.length).fill(false)\n\n\tfor (const bigram of bigrams1) {\n\t\tfor (let i = 0; i < bigrams2.length; i++) {\n\t\t\tif (!used[i] && bigrams2[i] === bigram) {\n\t\t\t\tintersection++\n\t\t\t\tused[i] = true\n\t\t\t\tbreak\n\t\t\t}\n\t\t}\n\t}\n\n\treturn (2 * intersection) / (bigrams1.length + bigrams2.length)\n}\n\n/**\n * Calculate Levenshtein distance between two strings.\n */\nfunction calculateLevenshtein(a: string, b: string): number {\n\tif (a.length === 0) return b.length\n\tif (b.length === 0) return a.length\n\n\tconst matrix: number[][] = []\n\n\t// Initialize the matrix\n\tfor (let i = 0; i <= b.length; i++) {\n\t\tmatrix[i] = [i]\n\t}\n\tfor (let j = 0; j <= a.length; j++) {\n\t\tmatrix[0][j] = j\n\t}\n\n\t// Calculate distances\n\tfor (let i = 1; i <= b.length; i++) {\n\t\tfor (let j = 1; j <= a.length; j++) {\n\t\t\tconst cost = a[j - 1] === b[i - 1] ? 0 : 1\n\t\t\tmatrix[i][j] = Math.min(\n\t\t\t\tmatrix[i - 1][j] + 1, // deletion\n\t\t\t\tmatrix[i][j - 1] + 1, // insertion\n\t\t\t\tmatrix[i - 1][j - 1] + cost, // substitution\n\t\t\t)\n\t\t}\n\t}\n\n\treturn matrix[b.length][a.length]\n}\n","import { $LitElement } from '@mixins/index'\nimport { InputSize } from '@schmancy/input'\nimport SchmancyInputV2 from '@schmancy/input/input-v2'\nimport SchmancyOption from '@schmancy/option/option'\nimport { html } from 'lit'\nimport { customElement, property, query, queryAssignedElements, state } from 'lit/decorators.js'\nimport { classMap } from 'lit/directives/class-map.js'\nimport { createRef, ref } from 'lit/directives/ref.js'\nimport {\n BehaviorSubject,\n combineLatest,\n EMPTY,\n fromEvent,\n merge,\n of,\n Subject,\n timer\n} from 'rxjs'\nimport {\n debounceTime,\n distinctUntilChanged,\n filter,\n map,\n startWith,\n switchMap,\n take,\n takeUntil,\n tap,\n withLatestFrom\n} from 'rxjs/operators'\nimport style from './autocomplete.scss?inline'\n\n// Import the similarity function (or include it inline)\nimport { similarity } from '../utils/search'\n\nexport type SchmancyAutocompleteChangeEvent = CustomEvent<{\n value: string | string[]\n values?: string[]\n}>\n\ninterface FilteredOption {\n option: SchmancyOption\n score: number\n}\n\n@customElement('schmancy-autocomplete')\nexport default class SchmancyAutocomplete extends $LitElement(style) {\n // Public API properties\n @property({ type: Boolean }) required = false\n @property({ type: String }) placeholder = ''\n @property({ type: String, reflect: true }) label = ''\n @property({ type: String }) name = ''\n @property({ type: String }) maxHeight = '300px'\n @property({ type: Boolean }) multi = false\n @property({ type: String }) description = ''\n @property({ type: String, reflect: true }) size: InputSize = 'md'\n @property({ type: String }) autocomplete = 'on'\n @property({ type: Number }) debounceMs = 200\n @property({ type: Number }) similarityThreshold = 0.3 // Minimum similarity score to show option\n\n // Values property for multi-select mode\n @property({ type: Array })\n get values() {\n return [...this._selectedValues$.value]\n }\n set values(vals: string[]) {\n this._selectedValues$.next(Array.isArray(vals) ? [...vals] : [])\n }\n\n // Value property\n @property({ type: String, reflect: true })\n get value() {\n return this.multi \n ? this._selectedValues$.value.join(',')\n : this._selectedValue$.value\n }\n set value(val: string) {\n if (this.multi) {\n this._selectedValues$.next(\n val ? val.split(',').map(v => v.trim()).filter(Boolean) : []\n )\n } else {\n this._selectedValue$.next(val)\n }\n }\n\n // State\n @state() private _open = false\n @state() private _inputValue = ''\n @state() private _visibleOptionsCount = 0\n @state() private _hasResults = true\n\n // DOM references\n @query('#options') _listbox!: HTMLUListElement\n @query('sch-input') _input!: SchmancyInputV2\n @queryAssignedElements({ flatten: true }) private _options!: SchmancyOption[]\n private _inputElementRef = createRef<HTMLInputElement>()\n\n // RxJS Subjects\n private _selectedValue$ = new BehaviorSubject<string>('')\n private _selectedValues$ = new BehaviorSubject<string[]>([])\n private _inputValue$ = new BehaviorSubject<string>('')\n private _open$ = new BehaviorSubject<boolean>(false)\n private _options$ = new BehaviorSubject<SchmancyOption[]>([])\n private _optionSelect$ = new Subject<SchmancyOption>()\n private _documentClick$ = new Subject<MouseEvent>()\n private _checkAutofill$ = new Subject<void>()\n\n connectedCallback() {\n super.connectedCallback()\n \n if (!this.id) {\n this.id = `sch-autocomplete-${Math.random().toString(36).slice(2, 9)}`\n }\n\n this._setupAutocompleteLogic()\n this._setupDocumentClickHandler()\n this._setupAutofillDetection()\n }\n\n private _setupAutocompleteLogic() {\n // Options management pipeline\n this._options$.pipe(\n tap(options => {\n options.forEach((option, index) => {\n option.setAttribute('role', 'option')\n option.tabIndex = -1\n if (!option.id) {\n option.id = `${this.id}-option-${index}`\n }\n if (!option.hasAttribute('data-event-bound')) {\n fromEvent(option, 'click').pipe(\n tap(e => e.stopPropagation()),\n takeUntil(this.disconnecting)\n ).subscribe(() => this._optionSelect$.next(option))\n option.setAttribute('data-event-bound', 'true')\n }\n })\n }),\n takeUntil(this.disconnecting)\n ).subscribe()\n\n // Selection sync pipeline\n combineLatest([\n this._selectedValue$,\n this._selectedValues$,\n this._options$\n ]).pipe(\n tap(([selectedValue, selectedValues, options]) => {\n options.forEach(option => {\n option.selected = this.multi \n ? selectedValues.includes(option.value)\n : option.value === selectedValue\n option.setAttribute('aria-selected', String(option.selected))\n })\n }),\n takeUntil(this.disconnecting)\n ).subscribe()\n\n // Enhanced fuzzy filtering pipeline\n this._inputValue$.pipe(\n distinctUntilChanged(),\n debounceTime(this.debounceMs),\n withLatestFrom(this._options$, this._open$),\n tap(([searchTerm, options, isOpen]) => {\n if (!isOpen) return\n\n const term = searchTerm.trim()\n \n if (!term) {\n // Show all options if no search term\n options.forEach(option => {\n option.hidden = false\n option.style.order = '0' // Reset order\n })\n this._visibleOptionsCount = options.length\n this._hasResults = true\n } else {\n // Calculate similarity scores for all options\n const scoredOptions: FilteredOption[] = options.map(option => {\n // Get text to search in (prioritize label, then textContent, then value)\n const optionLabel = option.label || option.textContent || ''\n const optionValue = option.value\n \n // Calculate similarity scores for both label and value\n const labelScore = similarity(term, optionLabel)\n const valueScore = similarity(term, optionValue)\n \n // Use the higher score (prioritizing label matches)\n const score = Math.max(labelScore * 1.1, valueScore) // Slight boost for label matches\n \n return { option, score }\n })\n \n // Sort by score (highest first)\n scoredOptions.sort((a, b) => b.score - a.score)\n \n // Apply visibility and ordering\n let visibleCount = 0\n scoredOptions.forEach((item, index) => {\n const { option, score } = item\n \n // Hide options below threshold\n if (score < this.similarityThreshold) {\n option.hidden = true\n } else {\n option.hidden = false\n visibleCount++\n // Use CSS order to sort visible options by relevance\n option.style.order = String(index)\n }\n })\n \n this._visibleOptionsCount = visibleCount\n this._hasResults = visibleCount > 0\n }\n \n this._announceToScreenReader(\n this._visibleOptionsCount > 0 \n ? `${this._visibleOptionsCount} option${this._visibleOptionsCount === 1 ? '' : 's'} available.`\n : 'No results found.'\n )\n }),\n takeUntil(this.disconnecting)\n ).subscribe()\n\n // Option selection pipeline\n this._optionSelect$.pipe(\n withLatestFrom(this._selectedValue$, this._selectedValues$),\n tap(([option, _, currentValues]) => {\n if (this.multi) {\n const index = currentValues.indexOf(option.value)\n const newValues = index > -1\n ? [...currentValues.slice(0, index), ...currentValues.slice(index + 1)]\n : [...currentValues, option.value]\n this._selectedValues$.next(newValues)\n \n this._inputValue$.next('')\n this._inputValue = ''\n \n const labels = this._getSelectedLabels()\n this._announceToScreenReader(\n labels.length > 0 \n ? `Selected: ${labels.join(', ')}`\n : 'No options selected'\n )\n } else {\n this._selectedValue$.next(option.value)\n this._open$.next(false)\n this._open = false\n \n this._inputValue = option.label || option.textContent || ''\n this._inputValue$.next(this._inputValue)\n \n timer(100).pipe(\n tap(() => this._inputElementRef.value?.blur()),\n take(1)\n ).subscribe()\n \n this._announceToScreenReader(`Selected: ${option.label || option.textContent}`)\n }\n }),\n tap(() => this._fireChangeEvent()),\n takeUntil(this.disconnecting)\n ).subscribe()\n\n // Display update pipeline\n combineLatest([\n this._open$,\n this._selectedValue$,\n this._selectedValues$,\n this._options$\n ]).pipe(\n filter(() => !this._open$.value),\n tap(([, selectedValue, selectedValues, options]) => {\n if (this.multi) {\n const labels = options\n .filter(opt => selectedValues.includes(opt.value))\n .map(opt => opt.label || opt.textContent || '')\n this._inputValue = labels.join(', ')\n } else {\n const option = options.find(opt => opt.value === selectedValue)\n this._inputValue = option ? option.label || option.textContent || '' : ''\n }\n this._inputValue$.next(this._inputValue)\n }),\n takeUntil(this.disconnecting)\n ).subscribe()\n\n // Open state sync\n this._open$.pipe(\n tap(open => this._open = open),\n takeUntil(this.disconnecting)\n ).subscribe()\n }\n\n private _setupDocumentClickHandler() {\n this._documentClick$.pipe(\n filter(e => !e.composedPath().includes(this)),\n filter(e => !this._options.some(opt => e.composedPath().includes(opt))),\n filter(() => this._open),\n tap(() => {\n this._open$.next(false)\n this._updateInputDisplay()\n }),\n takeUntil(this.disconnecting)\n ).subscribe()\n\n this._open$.pipe(\n distinctUntilChanged(),\n switchMap(open => \n open \n ? timer(10).pipe(\n tap(() => document.addEventListener('click', e => this._documentClick$.next(e))),\n switchMap(() => EMPTY)\n )\n : of(null).pipe(\n tap(() => document.removeEventListener('click', e => this._documentClick$.next(e)))\n )\n ),\n takeUntil(this.disconnecting)\n ).subscribe()\n }\n\n private _setupAutofillDetection() {\n // Enhanced autofill detection with fuzzy matching\n merge(\n timer(100, 500).pipe(take(10)),\n this._checkAutofill$,\n timer(100).pipe(\n switchMap(() => \n fromEvent(window, 'load').pipe(startWith(null))\n )\n )\n ).pipe(\n map(() => {\n const schInput = this._inputElementRef.value\n if (!schInput) return null\n return schInput.shadowRoot?.querySelector('input') || \n schInput.querySelector('input') ||\n (schInput as any)._inputRef?.value\n }),\n filter(input => !!input),\n map(input => (input as HTMLInputElement).value),\n filter(value => !!value && value.trim().length > 0),\n distinctUntilChanged(),\n withLatestFrom(this._options$),\n tap(([autofilledValue, options]) => {\n console.log('Autofill detected:', autofilledValue)\n \n // Use fuzzy matching to find best matching option\n let bestMatch: SchmancyOption | null = null\n let bestScore = 0\n \n options.forEach(option => {\n const optionLabel = option.label || option.textContent || ''\n const optionValue = option.value\n \n // Calculate similarity scores\n const labelScore = similarity(autofilledValue, optionLabel)\n const valueScore = similarity(autofilledValue, optionValue)\n \n // Use the higher score\n const score = Math.max(labelScore, valueScore)\n \n // Keep track of best match\n if (score > bestScore && score >= this.similarityThreshold) {\n bestScore = score\n bestMatch = option\n }\n })\n\n if (bestMatch) {\n console.log('Found matching option:', bestMatch.value, 'with score:', bestScore)\n \n // Select the option\n if (this.multi) {\n this._selectedValues$.next([bestMatch.value])\n } else {\n this._selectedValue$.next(bestMatch.value)\n }\n \n // Update input to show the label\n const displayValue = bestMatch.label || bestMatch.textContent || ''\n this._inputValue = displayValue\n this._inputValue$.next(displayValue)\n \n // Update the actual input element\n const input = this._inputElementRef.value\n if (input) {\n input.value = displayValue\n }\n \n // Close dropdown if open\n this._open$.next(false)\n \n // Fire change event\n this._fireChangeEvent()\n \n // Announce to screen reader\n this._announceToScreenReader(`Autofilled: ${displayValue}`)\n }\n }),\n takeUntil(this.disconnecting)\n ).subscribe()\n\n // Chrome autofill animation detection\n timer(100).pipe(\n map(() => {\n const schInput = this._inputElementRef.value\n if (!schInput) return null\n return schInput.shadowRoot?.querySelector('input') || \n schInput.querySelector('input') ||\n (schInput as any)._inputRef?.value\n }),\n filter(input => !!input),\n switchMap(input => {\n return fromEvent<AnimationEvent>(input!, 'animationstart').pipe(\n filter(e => e.animationName === 'onAutoFillStart'),\n tap(() => {\n console.log('Chrome autofill animation detected')\n timer(100).pipe(\n tap(() => this._checkAutofill$.next()),\n take(1)\n ).subscribe()\n })\n )\n }),\n takeUntil(this.disconnecting)\n ).subscribe()\n }\n\n private _updateInputDisplay() {\n of(null).pipe(\n withLatestFrom(\n this._selectedValue$,\n this._selectedValues$,\n this._options$,\n this._open$\n ),\n tap(([, selectedValue, selectedValues, options, isOpen]) => {\n if (!this._inputElementRef.value) return\n\n if (!isOpen || !this.multi) {\n if (this.multi) {\n const labels = options\n .filter(opt => selectedValues.includes(opt.value))\n .map(opt => opt.label || opt.textContent || '')\n this._inputValue = labels.join(', ')\n } else {\n const option = options.find(opt => opt.value === selectedValue)\n this._inputValue = option ? option.label || option.textContent || '' : ''\n }\n this._inputValue$.next(this._inputValue)\n this._inputElementRef.value.value = this._inputValue\n }\n }),\n take(1)\n ).subscribe()\n }\n\n private _getSelectedLabels(): string[] {\n return this._options\n .filter(option => \n this.multi \n ? this._selectedValues$.value.includes(option.value)\n : option.value === this._selectedValue$.value\n )\n .map(option => option.label || option.textContent || '')\n }\n\n private _announceToScreenReader(message: string) {\n const liveRegion = this.shadowRoot?.querySelector('#live-status')\n if (liveRegion) {\n liveRegion.textContent = message\n }\n }\n\n private _fireChangeEvent() {\n const detail: SchmancyAutocompleteChangeEvent['detail'] = {\n value: this.value,\n }\n\n if (this.multi) {\n detail.values = [...this._selectedValues$.value]\n }\n\n this.dispatchEvent(\n new CustomEvent<SchmancyAutocompleteChangeEvent['detail']>('change', {\n detail,\n bubbles: true,\n composed: true,\n })\n )\n }\n\n public checkValidity(): boolean {\n if (!this.required) return true\n return this.multi \n ? this._selectedValues$.value.length > 0 \n : Boolean(this._selectedValue$.value)\n }\n\n public reportValidity(): boolean {\n if (this._inputElementRef.value) {\n return this._inputElementRef.value.reportValidity()\n }\n return this.checkValidity()\n }\n\n firstUpdated() {\n timer(200).pipe(\n tap(() => this._checkAutofill$.next()),\n take(1)\n ).subscribe()\n \n this._options$.pipe(\n filter(options => options.length > 0),\n tap(() => this._checkAutofill$.next()),\n takeUntil(this.disconnecting)\n ).subscribe()\n }\n\n render() {\n const descriptionId = `${this.id}-desc`\n\n return html`\n <div class=\"relative\">\n <!-- Screen reader live region -->\n <div id=\"live-status\" role=\"status\" aria-live=\"polite\" class=\"sr-only\"></div>\n\n <!-- Description -->\n ${this.description ? html`<div id=\"${descriptionId}\" class=\"sr-only\">${this.description}</div>` : ''}\n\n <!-- Input -->\n <slot name=\"trigger\">\n <sch-input\n .size=${this.size}\n ${ref(this._inputElementRef)}\n id=\"autocomplete-input\"\n class=\"w-full\"\n .name=${this.name || this.label?.toLowerCase().replace(/\\s+/g, '-')}\n .label=${this.label}\n .placeholder=${this.placeholder}\n .required=${this.required}\n .value=${this._inputValue}\n type=\"text\"\n autocomplete=${this.autocomplete}\n clickable\n role=\"combobox\"\n aria-autocomplete=\"list\"\n aria-haspopup=\"listbox\"\n aria-controls=\"options\"\n aria-expanded=${this._open}\n aria-describedby=${this.description ? descriptionId : undefined}\n @input=${(e: Event) => {\n const value = (e.target as HTMLInputElement).value\n this._inputValue = value\n this._inputValue$.next(value)\n }}\n @focus=${(e: FocusEvent) => {\n e.stopPropagation()\n \n const hasSelection = this.multi \n ? this._selectedValues$.value.length > 0\n : !!this._selectedValue$.value\n \n if (this.multi && !hasSelection) {\n this._inputValue = ''\n this._inputValue$.next('')\n if (this._inputElementRef.value) {\n this._inputElementRef.value.value = ''\n }\n }\n \n this._open$.next(true)\n }}\n @click=${(e: MouseEvent) => {\n e.stopPropagation()\n this._open$.next(true)\n }}\n @keydown=${(e: KeyboardEvent) => {\n this._handleKeyDown(e)\n }}\n >\n </sch-input>\n </slot>\n\n <!-- Options dropdown -->\n <ul\n id=\"options\"\n class=${classMap({\n 'absolute': true,\n 'z-[1000]': true,\n 'mt-1': true,\n 'w-full': true,\n 'rounded-md': true,\n 'shadow-md': true,\n 'overflow-auto': true,\n 'min-w-full': true,\n 'bg-surface-low': true,\n 'flex': true,\n 'flex-col': true, // Enable flexbox for ordering\n })}\n role=\"listbox\"\n aria-multiselectable=${this.multi ? 'true' : 'false'}\n aria-label=${`${this.label || 'Options'} dropdown`}\n ?hidden=${!this._open}\n style=\"max-height: ${this.maxHeight}; display: ${this._open ? 'flex' : 'none'};\"\n @slotchange=${() => {\n this._options$.next(this._options)\n timer(100).pipe(\n tap(() => this._checkAutofill$.next()),\n take(1)\n ).subscribe()\n }}\n >\n <slot></slot>\n ${!this._hasResults ? html`\n <li class=\"px-3 py-2 text-sm text-muted\">No results found</li>\n ` : ''}\n </ul>\n </div>\n\n <style>\n :host {\n display: block;\n }\n\n @keyframes onAutoFillStart {\n from {/**/}\n to {/**/}\n }\n\n sch-input::part(input):-webkit-autofill,\n sch-input input:-webkit-autofill {\n animation-name: onAutoFillStart;\n animation-duration: 1ms;\n }\n </style>\n `\n }\n\n private _handleKeyDown(_e: KeyboardEvent) {\n fromEvent<KeyboardEvent>(document, 'keydown').pipe(\n take(1),\n withLatestFrom(this._open$, this._options$),\n tap(([event, isOpen, options]) => {\n if (!isOpen && (event.key === 'ArrowDown' || event.key === 'Enter')) {\n event.preventDefault()\n this._open$.next(true)\n \n timer(10).pipe(\n tap(() => {\n const firstVisible = options.find(opt => !opt.hidden)\n firstVisible?.focus()\n }),\n take(1)\n ).subscribe()\n return\n }\n\n if (!isOpen) return\n\n const visibleOptions = options.filter(opt => !opt.hidden)\n .sort((a, b) => parseInt(a.style.order || '0') - parseInt(b.style.order || '0'))\n \n const focusedOption = visibleOptions.find(opt => opt === document.activeElement)\n const currentIndex = focusedOption ? visibleOptions.indexOf(focusedOption) : -1\n\n switch (event.key) {\n case 'Escape':\n event.preventDefault()\n this._open$.next(false)\n this._updateInputDisplay()\n this._inputElementRef.value?.focus()\n break\n\n case 'Tab':\n this._open$.next(false)\n this._updateInputDisplay()\n break\n\n case 'ArrowDown':\n event.preventDefault()\n const nextIndex = currentIndex < visibleOptions.length - 1 ? currentIndex + 1 : 0\n visibleOptions[nextIndex]?.focus()\n break\n\n case 'ArrowUp':\n event.preventDefault()\n const prevIndex = currentIndex > 0 ? currentIndex - 1 : visibleOptions.length - 1\n visibleOptions[prevIndex]?.focus()\n break\n\n case 'Home':\n event.preventDefault()\n visibleOptions[0]?.focus()\n break\n\n case 'End':\n event.preventDefault()\n visibleOptions[visibleOptions.length - 1]?.focus()\n break\n\n case 'Enter':\n case ' ':\n if (focusedOption) {\n event.preventDefault()\n this._optionSelect$.next(focusedOption)\n }\n break\n }\n })\n ).subscribe()\n }\n}\n\n\n\ndeclare global {\n interface HTMLElementTagNameMap {\n 'schmancy-autocomplete': SchmancyAutocomplete\n }\n}"],"names":["similarity","query","target","normalizedQuery","toLowerCase","trim","normalizedTarget","startsWith","length","words","split","word","indexOf","includes","sub","str","i","j","diceScore","s1","s2","bigrams1","getBigrams","bigrams2","intersection","used","Array","fill","bigram","maxLength","Math","max","levenshteinDistance","a","b","matrix","cost","min","levenshteinScore","anagramScore","countChars","s","reduce","acc","char","queryCount","targetCount","Object","keys","every","bigrams","push","substring","SchmancyAutocomplete","$LitElement","constructor","super","arguments","this","required","placeholder","label","name","maxHeight","multi","description","size","autocomplete","debounceMs","similarityThreshold","_open","_inputValue","_visibleOptionsCount","_hasResults","_inputElementRef","createRef","_selectedValue$","BehaviorSubject","_selectedValues$","_inputValue$","_open$","_options$","_optionSelect$","Subject","_documentClick$","_checkAutofill$","value","values","vals","next","isArray","join","val","map","v","filter","Boolean","connectedCallback","id","random","toString","slice","_setupAutocompleteLogic","_setupDocumentClickHandler","_setupAutofillDetection","pipe","tap","options","forEach","option","index","setAttribute","tabIndex","hasAttribute","fromEvent","e","stopPropagation","takeUntil","disconnecting","subscribe","combineLatest","selectedValue","selectedValues","selected","String","distinctUntilChanged","debounceTime","withLatestFrom","searchTerm","isOpen","term","scoredOptions","optionLabel","textContent","optionValue","labelScore","valueScore","score","sort","visibleCount","item","hidden","style","order","_announceToScreenReader","_","currentValues","newValues","labels","_getSelectedLabels","timer","blur","take","_fireChangeEvent","opt","find","open","composedPath","_options","some","_updateInputDisplay","switchMap","document","addEventListener","EMPTY","of","removeEventListener","merge","window","startWith","schInput","shadowRoot","querySelector","_inputRef","input","autofilledValue","bestMatch","bestScore","displayValue","animationName","message","liveRegion","detail","dispatchEvent","CustomEvent","bubbles","composed","reportValidity","checkValidity","firstUpdated","descriptionId","html","ref","replace","hasSelection","_handleKeyDown","classMap","absolute","flex","_e","event","key","preventDefault","firstVisible","focus","visibleOptions","parseInt","focusedOption","activeElement","currentIndex","nextIndex","prevIndex","__decorateClass","property","type","prototype","reflect","Number","state","queryAssignedElements","flatten","customElement"],"mappings":";;;;;;;;;AASgB,SAAAA,EAAWC,GAAeC,GAEzC;AAAA,MAAA,CAAKD,MAAUC,EAAe,QAAA;AAC1B,MAAAD,MAAUC,EAAe,QAAA;AAG7B,QAAMC,IAAkBF,EAAMG,YAAAA,EAAcC,QACtCC,IAAmBJ,EAAOE,cAAcC,KAG1C;AAAA,MAAAF,MAAoBG,EAAyB,QAAA;AAG7C,MAAAA,EAAiBC,WAAWJ,CAAkB;AAGjD,WAAO,OAAsB,QADTA,EAAgBK,SAASF,EAAiBE;AAKzD,QAAAC,IAAQH,EAAiBI,MAAM,UAAA;AACrC,aAAWC,KAAQF,EACd,KAAAE,EAAKJ,WAAWJ;AAInB,WAAO,QADmB,IADRM,EAAMG,QAAQD,CAAAA,IACWF,EAAMD,SAAU;AAMzD,MAAAF,EAAiBO,SAASV,CAAAA;AAI7B,WAAO,OADe,IADLG,EAAiBM,QAAQT,KACJG,EAAiBE,SAAU;AAK9D,MA+BL,SA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,CAAhBM,EA3CgBrK,CAAAA,GAAAA,EA2CAkK,WAAA,wBAAA,CAAA,GACAH,EAAA,CAAhBM,EAAAA,CAAAA,GA5CgBrK,EA4CAkK,WAAA,eAAA,IAGEH,EAAA,CAAlBnN,EAAM,UA/CUoD,CAAAA,GAAAA,EA+CEkK,WAAA,YAAA,CAAA,GACCH,EAAA,CAAnBnN,EAAM,eAhDUoD,EAgDGkK,WAAA,UAAA,CAC8BH,GAAAA,EAAA,CAAjDO,EAAsB,EAAEC,YAjDRvK,CAAAA,CAAAA,GAAAA,EAiDiCkK,WAAA,YAAA,CAAA,GAjDjClK,IAArB+J,EAAA,CADCS,EAAc,uBACMxK,CAAAA,GAAAA,CAAAA;"}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
"use strict";const u=require("rxjs"),E=require("lit/directives/class-map.js");require("lit/directives/style-map.js");const C=require("./litElement.mixin-0pIFA8ru.cjs");require("./tailwind.mixin-DFxMrwgk.cjs");const V=require("lit"),d=require("lit/decorators.js"),w=require("lit/directives/ref.js"),e=require("rxjs/operators");function k(t,i){if(!t||!i)return 0;if(t===i)return 1;const s=t.toLowerCase().trim(),n=i.toLowerCase().trim();if(s===n)return 1;if(n.startsWith(s))return .95+.05*(s.length/n.length);const l=n.split(/[\s\-_]+/);for(const p of l)if(p.startsWith(s))return .85*(1-l.indexOf(p)/l.length*.1);if(n.includes(s))return .7*(1-n.indexOf(s)/n.length*.2);if(function(p,m){let r=0,o=0;for(;r<p.length&&o<m.length;)p[r]===m[o]&&r++,o++;return r===p.length}(s,n))return .5;const a=function(p,m){if(p.length<2||m.length<2)return 0;const r=S(p),o=S(m);let v=0;const y=new Array(o.length).fill(!1);for(const x of r)for(let g=0;g<o.length;g++)if(!y[g]&&o[g]===x){v++,y[g]=!0;break}return 2*v/(r.length+o.length)}(s,n),h=Math.max(s.length,n.length),f=function(p,m){if(p.length===0)return m.length;if(m.length===0)return p.length;const r=[];for(let o=0;o<=m.length;o++)r[o]=[o];for(let o=0;o<=p.length;o++)r[0][o]=o;for(let o=1;o<=m.length;o++)for(let v=1;v<=p.length;v++){const y=p[v-1]===m[o-1]?0:1;r[o][v]=Math.min(r[o-1][v]+1,r[o][v-1]+1,r[o-1][v-1]+y)}return r[m.length][p.length]}(s,n),b=h?1-f/h:0,$=function(p,m){const r=y=>y.split("").reduce((x,g)=>(x[g]=(x[g]||0)+1,x),{}),o=r(p),v=r(m);return Object.keys(o).every(y=>(v[y]||0)>=o[y])}(s,n)?.3:0;return Math.max(.4*a,.4*b,$)}function S(t){const i=[];for(let s=0;s<t.length-1;s++)i.push(t.substring(s,s+2));return i}var R=Object.defineProperty,A=Object.getOwnPropertyDescriptor,_=(t,i,s,n)=>{for(var l,a=n>1?void 0:n?A(i,s):i,h=t.length-1;h>=0;h--)(l=t[h])&&(a=(n?l(i,s,a):l(a))||a);return n&&a&&R(i,s,a),a};let c=class extends C.$LitElement(":host{display:block;border:unset!important;line-height:unset!important;background:unset!important;padding:unset!important;font-size:unset!important;box-shadow:unset!important}:host:focus{box-shadow:unset!important}"){constructor(){super(...arguments),this.required=!1,this.placeholder="",this.label="",this.name="",this.maxHeight="300px",this.multi=!1,this.description="",this.size="md",this.autocomplete="on",this.debounceMs=200,this.similarityThreshold=.3,this._open=!1,this._inputValue="",this._visibleOptionsCount=0,this._hasResults=!0,this._inputElementRef=w.createRef(),this._selectedValue$=new u.BehaviorSubject(""),this._selectedValues$=new u.BehaviorSubject([]),this._inputValue$=new u.BehaviorSubject(""),this._open$=new u.BehaviorSubject(!1),this._options$=new u.BehaviorSubject([]),this._optionSelect$=new u.Subject,this._documentClick$=new u.Subject,this._checkAutofill$=new u.Subject}get values(){return[...this._selectedValues$.value]}set values(t){this._selectedValues$.next(Array.isArray(t)?[...t]:[])}get value(){return this.multi?this._selectedValues$.value.join(","):this._selectedValue$.value}set value(t){this.multi?this._selectedValues$.next(t?t.split(",").map(i=>i.trim()).filter(Boolean):[]):this._selectedValue$.next(t)}connectedCallback(){super.connectedCallback(),this.id||(this.id=`sch-autocomplete-${Math.random().toString(36).slice(2,9)}`),this._setupAutocompleteLogic(),this._setupDocumentClickHandler(),this._setupAutofillDetection()}_setupAutocompleteLogic(){this._options$.pipe(e.tap(t=>{t.forEach((i,s)=>{i.setAttribute("role","option"),i.tabIndex=-1,i.id||(i.id=`${this.id}-option-${s}`),i.hasAttribute("data-event-bound")||(u.fromEvent(i,"click").pipe(e.tap(n=>n.stopPropagation()),e.takeUntil(this.disconnecting)).subscribe(()=>this._optionSelect$.next(i)),i.setAttribute("data-event-bound","true"))})}),e.takeUntil(this.disconnecting)).subscribe(),u.combineLatest([this._selectedValue$,this._selectedValues$,this._options$]).pipe(e.tap(([t,i,s])=>{s.forEach(n=>{n.selected=this.multi?i.includes(n.value):n.value===t,n.setAttribute("aria-selected",String(n.selected))})}),e.takeUntil(this.disconnecting)).subscribe(),this._inputValue$.pipe(e.distinctUntilChanged(),e.debounceTime(this.debounceMs),e.withLatestFrom(this._options$,this._open$),e.tap(([t,i,s])=>{if(!s)return;const n=t.trim();if(n){const l=i.map(h=>{const f=h.label||h.textContent||"",b=h.value,$=k(n,f),p=k(n,b);return{option:h,score:Math.max(1.1*$,p)}});l.sort((h,f)=>f.score-h.score);let a=0;l.forEach((h,f)=>{const{option:b,score:$}=h;$<this.similarityThreshold?b.hidden=!0:(b.hidden=!1,a++,b.style.order=String(f))}),this._visibleOptionsCount=a,this._hasResults=a>0}else i.forEach(l=>{l.hidden=!1,l.style.order="0"}),this._visibleOptionsCount=i.length,this._hasResults=!0;this._announceToScreenReader(this._visibleOptionsCount>0?`${this._visibleOptionsCount} option${this._visibleOptionsCount===1?"":"s"} available.`:"No results found.")}),e.takeUntil(this.disconnecting)).subscribe(),this._optionSelect$.pipe(e.withLatestFrom(this._selectedValue$,this._selectedValues$),e.tap(([t,i,s])=>{if(this.multi){const n=s.indexOf(t.value),l=n>-1?[...s.slice(0,n),...s.slice(n+1)]:[...s,t.value];this._selectedValues$.next(l),this._inputValue$.next(""),this._inputValue="";const a=this._getSelectedLabels();this._announceToScreenReader(a.length>0?`Selected: ${a.join(", ")}`:"No options selected")}else this._selectedValue$.next(t.value),this._open$.next(!1),this._open=!1,this._inputValue=t.label||t.textContent||"",this._inputValue$.next(this._inputValue),u.timer(100).pipe(e.tap(()=>{var n;return(n=this._inputElementRef.value)==null?void 0:n.blur()}),e.take(1)).subscribe(),this._announceToScreenReader(`Selected: ${t.label||t.textContent}`)}),e.tap(()=>this._fireChangeEvent()),e.takeUntil(this.disconnecting)).subscribe(),u.combineLatest([this._open$,this._selectedValue$,this._selectedValues$,this._options$]).pipe(e.filter(()=>!this._open$.value),e.tap(([,t,i,s])=>{if(this.multi){const n=s.filter(l=>i.includes(l.value)).map(l=>l.label||l.textContent||"");this._inputValue=n.join(", ")}else{const n=s.find(l=>l.value===t);this._inputValue=n&&(n.label||n.textContent)||""}this._inputValue$.next(this._inputValue)}),e.takeUntil(this.disconnecting)).subscribe(),this._open$.pipe(e.tap(t=>this._open=t),e.takeUntil(this.disconnecting)).subscribe()}_setupDocumentClickHandler(){this._documentClick$.pipe(e.filter(t=>!t.composedPath().includes(this)),e.filter(t=>!this._options.some(i=>t.composedPath().includes(i))),e.filter(()=>this._open),e.tap(()=>{this._open$.next(!1),this._updateInputDisplay()}),e.takeUntil(this.disconnecting)).subscribe(),this._open$.pipe(e.distinctUntilChanged(),e.switchMap(t=>t?u.timer(10).pipe(e.tap(()=>document.addEventListener("click",i=>this._documentClick$.next(i))),e.switchMap(()=>u.EMPTY)):u.of(null).pipe(e.tap(()=>document.removeEventListener("click",i=>this._documentClick$.next(i))))),e.takeUntil(this.disconnecting)).subscribe()}_setupAutofillDetection(){u.merge(u.timer(100,500).pipe(e.take(10)),this._checkAutofill$,u.timer(100).pipe(e.switchMap(()=>u.fromEvent(window,"load").pipe(e.startWith(null))))).pipe(e.map(()=>{var i,s;const t=this._inputElementRef.value;return t?((i=t.shadowRoot)==null?void 0:i.querySelector("input"))||t.querySelector("input")||((s=t._inputRef)==null?void 0:s.value):null}),e.filter(t=>!!t),e.map(t=>t.value),e.filter(t=>!!t&&t.trim().length>0),e.distinctUntilChanged(),e.withLatestFrom(this._options$),e.tap(([t,i])=>{let s=null,n=0;if(i.forEach(l=>{const a=l.label||l.textContent||"",h=l.value,f=k(t,a),b=k(t,h),$=Math.max(f,b);$>n&&$>=this.similarityThreshold&&(n=$,s=l)}),s){this.multi?this._selectedValues$.next([s.value]):this._selectedValue$.next(s.value);const l=s.label||s.textContent||"";this._inputValue=l,this._inputValue$.next(l);const a=this._inputElementRef.value;a&&(a.value=l),this._open$.next(!1),this._fireChangeEvent(),this._announceToScreenReader(`Autofilled: ${l}`)}}),e.takeUntil(this.disconnecting)).subscribe(),u.timer(100).pipe(e.map(()=>{var i,s;const t=this._inputElementRef.value;return t?((i=t.shadowRoot)==null?void 0:i.querySelector("input"))||t.querySelector("input")||((s=t._inputRef)==null?void 0:s.value):null}),e.filter(t=>!!t),e.switchMap(t=>u.fromEvent(t,"animationstart").pipe(e.filter(i=>i.animationName==="onAutoFillStart"),e.tap(()=>{u.timer(100).pipe(e.tap(()=>this._checkAutofill$.next()),e.take(1)).subscribe()}))),e.takeUntil(this.disconnecting)).subscribe()}_updateInputDisplay(){u.of(null).pipe(e.withLatestFrom(this._selectedValue$,this._selectedValues$,this._options$,this._open$),e.tap(([,t,i,s,n])=>{if(this._inputElementRef.value&&(!n||!this.multi)){if(this.multi){const l=s.filter(a=>i.includes(a.value)).map(a=>a.label||a.textContent||"");this._inputValue=l.join(", ")}else{const l=s.find(a=>a.value===t);this._inputValue=l&&(l.label||l.textContent)||""}this._inputValue$.next(this._inputValue),this._inputElementRef.value.value=this._inputValue}}),e.take(1)).subscribe()}_getSelectedLabels(){return this._options.filter(t=>this.multi?this._selectedValues$.value.includes(t.value):t.value===this._selectedValue$.value).map(t=>t.label||t.textContent||"")}_announceToScreenReader(t){var s;const i=(s=this.shadowRoot)==null?void 0:s.querySelector("#live-status");i&&(i.textContent=t)}_fireChangeEvent(){const t={value:this.value};this.multi&&(t.values=[...this._selectedValues$.value]),this.dispatchEvent(new CustomEvent("change",{detail:t,bubbles:!0,composed:!0}))}checkValidity(){return!this.required||(this.multi?this._selectedValues$.value.length>0:!!this._selectedValue$.value)}reportValidity(){return this._inputElementRef.value?this._inputElementRef.value.reportValidity():this.checkValidity()}firstUpdated(){u.timer(200).pipe(e.tap(()=>this._checkAutofill$.next()),e.take(1)).subscribe(),this._options$.pipe(e.filter(t=>t.length>0),e.tap(()=>this._checkAutofill$.next()),e.takeUntil(this.disconnecting)).subscribe()}render(){var i;const t=`${this.id}-desc`;return V.html`
|
|
2
|
+
<div class="relative">
|
|
3
|
+
<!-- Screen reader live region -->
|
|
4
|
+
<div id="live-status" role="status" aria-live="polite" class="sr-only"></div>
|
|
5
|
+
|
|
6
|
+
<!-- Description -->
|
|
7
|
+
${this.description?V.html`<div id="${t}" class="sr-only">${this.description}</div>`:""}
|
|
8
|
+
|
|
9
|
+
<!-- Input -->
|
|
10
|
+
<slot name="trigger">
|
|
11
|
+
<sch-input
|
|
12
|
+
.size=${this.size}
|
|
13
|
+
${w.ref(this._inputElementRef)}
|
|
14
|
+
id="autocomplete-input"
|
|
15
|
+
class="w-full"
|
|
16
|
+
.name=${this.name||((i=this.label)==null?void 0:i.toLowerCase().replace(/\s+/g,"-"))}
|
|
17
|
+
.label=${this.label}
|
|
18
|
+
.placeholder=${this.placeholder}
|
|
19
|
+
.required=${this.required}
|
|
20
|
+
.value=${this._inputValue}
|
|
21
|
+
type="text"
|
|
22
|
+
autocomplete=${this.autocomplete}
|
|
23
|
+
clickable
|
|
24
|
+
role="combobox"
|
|
25
|
+
aria-autocomplete="list"
|
|
26
|
+
aria-haspopup="listbox"
|
|
27
|
+
aria-controls="options"
|
|
28
|
+
aria-expanded=${this._open}
|
|
29
|
+
aria-describedby=${this.description?t:void 0}
|
|
30
|
+
@input=${s=>{const n=s.target.value;this._inputValue=n,this._inputValue$.next(n)}}
|
|
31
|
+
@focus=${s=>{s.stopPropagation();const n=this.multi?this._selectedValues$.value.length>0:!!this._selectedValue$.value;this.multi&&!n&&(this._inputValue="",this._inputValue$.next(""),this._inputElementRef.value&&(this._inputElementRef.value.value="")),this._open$.next(!0)}}
|
|
32
|
+
@click=${s=>{s.stopPropagation(),this._open$.next(!0)}}
|
|
33
|
+
@keydown=${s=>{this._handleKeyDown(s)}}
|
|
34
|
+
>
|
|
35
|
+
</sch-input>
|
|
36
|
+
</slot>
|
|
37
|
+
|
|
38
|
+
<!-- Options dropdown -->
|
|
39
|
+
<ul
|
|
40
|
+
id="options"
|
|
41
|
+
class=${E.classMap({absolute:!0,"z-[1000]":!0,"mt-1":!0,"w-full":!0,"rounded-md":!0,"shadow-md":!0,"overflow-auto":!0,"min-w-full":!0,"bg-surface-low":!0,flex:!0,"flex-col":!0})}
|
|
42
|
+
role="listbox"
|
|
43
|
+
aria-multiselectable=${this.multi?"true":"false"}
|
|
44
|
+
aria-label=${`${this.label||"Options"} dropdown`}
|
|
45
|
+
?hidden=${!this._open}
|
|
46
|
+
style="max-height: ${this.maxHeight}; display: ${this._open?"flex":"none"};"
|
|
47
|
+
@slotchange=${()=>{this._options$.next(this._options),u.timer(100).pipe(e.tap(()=>this._checkAutofill$.next()),e.take(1)).subscribe()}}
|
|
48
|
+
>
|
|
49
|
+
<slot></slot>
|
|
50
|
+
${this._hasResults?"":V.html`
|
|
51
|
+
<li class="px-3 py-2 text-sm text-muted">No results found</li>
|
|
52
|
+
`}
|
|
53
|
+
</ul>
|
|
54
|
+
</div>
|
|
55
|
+
|
|
56
|
+
<style>
|
|
57
|
+
:host {
|
|
58
|
+
display: block;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
@keyframes onAutoFillStart {
|
|
62
|
+
from {/**/}
|
|
63
|
+
to {/**/}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
sch-input::part(input):-webkit-autofill,
|
|
67
|
+
sch-input input:-webkit-autofill {
|
|
68
|
+
animation-name: onAutoFillStart;
|
|
69
|
+
animation-duration: 1ms;
|
|
70
|
+
}
|
|
71
|
+
</style>
|
|
72
|
+
`}_handleKeyDown(t){u.fromEvent(document,"keydown").pipe(e.take(1),e.withLatestFrom(this._open$,this._options$),e.tap(([i,s,n])=>{var f,b,$,p,m;if(!s&&(i.key==="ArrowDown"||i.key==="Enter"))return i.preventDefault(),this._open$.next(!0),void u.timer(10).pipe(e.tap(()=>{const r=n.find(o=>!o.hidden);r==null||r.focus()}),e.take(1)).subscribe();if(!s)return;const l=n.filter(r=>!r.hidden).sort((r,o)=>parseInt(r.style.order||"0")-parseInt(o.style.order||"0")),a=l.find(r=>r===document.activeElement),h=a?l.indexOf(a):-1;switch(i.key){case"Escape":i.preventDefault(),this._open$.next(!1),this._updateInputDisplay(),(f=this._inputElementRef.value)==null||f.focus();break;case"Tab":this._open$.next(!1),this._updateInputDisplay();break;case"ArrowDown":i.preventDefault();const r=h<l.length-1?h+1:0;(b=l[r])==null||b.focus();break;case"ArrowUp":i.preventDefault();const o=h>0?h-1:l.length-1;($=l[o])==null||$.focus();break;case"Home":i.preventDefault(),(p=l[0])==null||p.focus();break;case"End":i.preventDefault(),(m=l[l.length-1])==null||m.focus();break;case"Enter":case" ":a&&(i.preventDefault(),this._optionSelect$.next(a))}})).subscribe()}};_([d.property({type:Boolean})],c.prototype,"required",2),_([d.property({type:String})],c.prototype,"placeholder",2),_([d.property({type:String,reflect:!0})],c.prototype,"label",2),_([d.property({type:String})],c.prototype,"name",2),_([d.property({type:String})],c.prototype,"maxHeight",2),_([d.property({type:Boolean})],c.prototype,"multi",2),_([d.property({type:String})],c.prototype,"description",2),_([d.property({type:String,reflect:!0})],c.prototype,"size",2),_([d.property({type:String})],c.prototype,"autocomplete",2),_([d.property({type:Number})],c.prototype,"debounceMs",2),_([d.property({type:Number})],c.prototype,"similarityThreshold",2),_([d.property({type:Array})],c.prototype,"values",1),_([d.property({type:String,reflect:!0})],c.prototype,"value",1),_([d.state()],c.prototype,"_open",2),_([d.state()],c.prototype,"_inputValue",2),_([d.state()],c.prototype,"_visibleOptionsCount",2),_([d.state()],c.prototype,"_hasResults",2),_([d.query("#options")],c.prototype,"_listbox",2),_([d.query("sch-input")],c.prototype,"_input",2),_([d.queryAssignedElements({flatten:!0})],c.prototype,"_options",2),c=_([d.customElement("schmancy-autocomplete")],c);
|
|
73
|
+
//# sourceMappingURL=autocomplete-B4F-i4IH.cjs.map
|