@ohos-ports/slim-select 0.0.0-stage → 4.7.0-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +353 -2
- package/dist/animations.d.ts +37 -0
- package/dist/classes.d.ts +52 -0
- package/dist/events.d.ts +26 -0
- package/dist/helpers.d.ts +24 -0
- package/dist/index.d.ts +62 -0
- package/dist/index.umd.d.ts +2 -0
- package/dist/lifecycle.d.ts +44 -0
- package/dist/mutations.d.ts +33 -0
- package/dist/react/index.d.ts +4 -0
- package/dist/react/index.js +2153 -0
- package/dist/react/index.umd.js +1 -0
- package/dist/react/react.d.ts +16 -0
- package/dist/react/react.test.d.ts +1 -0
- package/dist/react/slim-select/react/index.d.ts +4 -0
- package/dist/render.d.ts +207 -0
- package/dist/select.d.ts +47 -0
- package/dist/settings.d.ts +46 -0
- package/dist/slimselect.cjs +2 -0
- package/dist/slimselect.cjs.js.map +1 -0
- package/dist/slimselect.css +1 -0
- package/dist/slimselect.css.map +1 -0
- package/dist/slimselect.es.js +2100 -0
- package/dist/slimselect.es.js.map +1 -0
- package/dist/slimselect.iife.js +2 -0
- package/dist/slimselect.iife.js.map +1 -0
- package/dist/slimselect.js +2 -0
- package/dist/slimselect.js.map +1 -0
- package/dist/src/docs/helpers.d.ts +14 -0
- package/dist/src/docs/main.d.ts +0 -0
- package/dist/src/docs/nav.d.ts +20 -0
- package/dist/src/docs/router.d.ts +2 -0
- package/dist/src/docs/store.d.ts +12 -0
- package/dist/store.d.ts +62 -0
- package/dist/sync.d.ts +88 -0
- package/dist/vue/helpers.d.ts +2 -0
- package/dist/vue/index.d.ts +4 -0
- package/dist/vue/index.js +2226 -0
- package/dist/vue/index.umd.js +1 -0
- package/dist/vue/slim-select/vue/index.d.ts +4 -0
- package/package.json +101 -4
- package/src/slim-select/slimselect.scss +807 -0
|
@@ -0,0 +1,2153 @@
|
|
|
1
|
+
import { forwardRef as e, useEffect as t, useImperativeHandle as n, useRef as r, useState as i } from "react";
|
|
2
|
+
import { jsx as a } from "react/jsx-runtime";
|
|
3
|
+
// src/slim-select/classes.ts
|
|
4
|
+
var o = class {
|
|
5
|
+
main;
|
|
6
|
+
placeholder;
|
|
7
|
+
values;
|
|
8
|
+
single;
|
|
9
|
+
multiString;
|
|
10
|
+
max;
|
|
11
|
+
value;
|
|
12
|
+
valueText;
|
|
13
|
+
valueDelete;
|
|
14
|
+
valueOut;
|
|
15
|
+
deselect;
|
|
16
|
+
deselectPath;
|
|
17
|
+
arrow;
|
|
18
|
+
arrowClose;
|
|
19
|
+
arrowOpen;
|
|
20
|
+
content;
|
|
21
|
+
contentOpen;
|
|
22
|
+
dirAbove;
|
|
23
|
+
dirBelow;
|
|
24
|
+
search;
|
|
25
|
+
searchHighlighter;
|
|
26
|
+
searching;
|
|
27
|
+
status;
|
|
28
|
+
addable;
|
|
29
|
+
addablePath;
|
|
30
|
+
list;
|
|
31
|
+
optgroup;
|
|
32
|
+
optgroupLabel;
|
|
33
|
+
optgroupLabelText;
|
|
34
|
+
optgroupActions;
|
|
35
|
+
optgroupSelectAll;
|
|
36
|
+
optgroupSelectAllBox;
|
|
37
|
+
optgroupSelectAllCheck;
|
|
38
|
+
optgroupClosable;
|
|
39
|
+
option;
|
|
40
|
+
optionDelete;
|
|
41
|
+
highlighted;
|
|
42
|
+
modalOverlay;
|
|
43
|
+
modalDialog;
|
|
44
|
+
modalTitle;
|
|
45
|
+
modalClose;
|
|
46
|
+
modalContent;
|
|
47
|
+
mainOpen;
|
|
48
|
+
close;
|
|
49
|
+
selected;
|
|
50
|
+
error;
|
|
51
|
+
disabled;
|
|
52
|
+
hide;
|
|
53
|
+
constructor(e) {
|
|
54
|
+
e ||= {};
|
|
55
|
+
let t = (e = "", t = "") => `${e} ${t}`.trim();
|
|
56
|
+
this.main = t("ss-main", e.main), this.placeholder = t("ss-placeholder", e.placeholder), this.values = t("ss-values", e.values), this.single = t("ss-single", e.single), this.multiString = t("ss-multi-string", e.multiString), this.max = t("ss-max", e.max), this.value = t("ss-value", e.value), this.valueText = t("ss-value-text", e.valueText), this.valueDelete = t("ss-value-delete", e.valueDelete), this.valueOut = t("ss-value-out", e.valueOut), this.deselect = t("ss-deselect", e.deselect), this.deselectPath = e.deselectPath || "M10,10 L90,90 M10,90 L90,10", this.arrow = t("ss-arrow", e.arrow), this.arrowClose = e.arrowClose || "M10,30 L50,70 L90,30", this.arrowOpen = e.arrowOpen || "M10,70 L50,30 L90,70", this.content = t("ss-content", e.content), this.contentOpen = t("ss-open", e.contentOpen), this.dirAbove = t("ss-dir-above", e.dirAbove), this.dirBelow = t("ss-dir-below", e.dirBelow), this.search = t("ss-search", e.search), this.searchHighlighter = t("ss-search-highlight", e.searchHighlighter), this.searching = t("ss-searching", e.searching), this.status = t("ss-status", e.status), this.addable = t("ss-addable", e.addable), this.addablePath = e.addablePath || "M50,10 L50,90 M10,50 L90,50", this.list = t("ss-list", e.list), this.optgroup = t("ss-optgroup", e.optgroup), this.optgroupLabel = t("ss-optgroup-label", e.optgroupLabel), this.optgroupLabelText = t("ss-optgroup-label-text", e.optgroupLabelText), this.optgroupActions = t("ss-optgroup-actions", e.optgroupActions), this.optgroupSelectAll = t("ss-selectall", e.optgroupSelectAll), this.optgroupSelectAllBox = e.optgroupSelectAllBox || "M15,15 L85,15 L85,85 L15,85 Z", this.optgroupSelectAllCheck = e.optgroupSelectAllCheck || "M25,50 L42,68 L75,32", this.optgroupClosable = t("ss-closable", e.optgroupClosable), this.option = t("ss-option", e.option), this.optionDelete = e.optionDelete || "M10,10 L90,90 M10,90 L90,10", this.highlighted = t("ss-highlighted", e.highlighted), this.modalOverlay = t("ss-modal-overlay", e.modalOverlay), this.modalDialog = t("ss-modal-dialog", e.modalDialog), this.modalTitle = t("ss-modal-title", e.modalTitle), this.modalClose = t("ss-modal-close", e.modalClose), this.modalContent = t("ss-modal-content", e.modalContent), this.mainOpen = t("ss-open", e.mainOpen), this.close = t("ss-close", e.close), this.selected = t("ss-selected", e.selected), this.error = t("ss-error", e.error), this.disabled = t("ss-disabled", e.disabled), this.hide = t("ss-hide", e.hide);
|
|
57
|
+
}
|
|
58
|
+
getFirst(e) {
|
|
59
|
+
return this[e].split(" ")[0];
|
|
60
|
+
}
|
|
61
|
+
}, s = 200, c = ["transform", "opacity"];
|
|
62
|
+
function l(e, t = s) {
|
|
63
|
+
let n = e.trim();
|
|
64
|
+
if (!n) return t;
|
|
65
|
+
if (n.endsWith("ms")) {
|
|
66
|
+
let e = parseFloat(n);
|
|
67
|
+
return Number.isNaN(e) ? t : e;
|
|
68
|
+
}
|
|
69
|
+
if (n.endsWith("s")) {
|
|
70
|
+
let e = parseFloat(n);
|
|
71
|
+
return Number.isNaN(e) ? t : e * 1e3;
|
|
72
|
+
}
|
|
73
|
+
let r = parseFloat(n);
|
|
74
|
+
return Number.isNaN(r) ? t : r;
|
|
75
|
+
}
|
|
76
|
+
function u(e, t = s) {
|
|
77
|
+
return l(getComputedStyle(e).getPropertyValue("--ss-animation-timing").trim(), t);
|
|
78
|
+
}
|
|
79
|
+
function d(e, t, n = s) {
|
|
80
|
+
let r = u(e, n) + 50;
|
|
81
|
+
return t === void 0 ? r : Math.max(r, t);
|
|
82
|
+
}
|
|
83
|
+
function f() {
|
|
84
|
+
return typeof window > "u" || typeof window.matchMedia != "function" ? !1 : window.matchMedia("(prefers-reduced-motion: reduce)").matches;
|
|
85
|
+
}
|
|
86
|
+
function p(e) {
|
|
87
|
+
return e === void 0 ? null : new Set(Array.isArray(e) ? e : [e]);
|
|
88
|
+
}
|
|
89
|
+
function m(e, t, n = s, r) {
|
|
90
|
+
if (f() || r?.aborted) return Promise.resolve();
|
|
91
|
+
let i = p(t);
|
|
92
|
+
return new Promise((t) => {
|
|
93
|
+
let a = null, o = !1, s = () => {
|
|
94
|
+
o || (o = !0, e.removeEventListener("transitionend", l), r?.removeEventListener("abort", c), a && clearTimeout(a), t());
|
|
95
|
+
}, c = () => s(), l = (t) => {
|
|
96
|
+
t.target === e && (i && (!i.has(t.propertyName) || (i.delete(t.propertyName), i.size > 0)) || s());
|
|
97
|
+
};
|
|
98
|
+
r?.addEventListener("abort", c, { once: !0 }), e.addEventListener("transitionend", l), a = setTimeout(s, n);
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
function h(e, t, n = s, r) {
|
|
102
|
+
return f() || r?.aborted ? Promise.resolve() : new Promise((i) => {
|
|
103
|
+
let a = null, o = !1, s = () => {
|
|
104
|
+
o || (o = !0, e.removeEventListener("animationend", l), r?.removeEventListener("abort", c), a && clearTimeout(a), i());
|
|
105
|
+
}, c = () => s(), l = (n) => {
|
|
106
|
+
n.target === e && (t && n.animationName !== t || s());
|
|
107
|
+
};
|
|
108
|
+
r?.addEventListener("abort", c, { once: !0 }), e.addEventListener("animationend", l), a = setTimeout(s, n);
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
var g = class {
|
|
112
|
+
id = "";
|
|
113
|
+
style = "";
|
|
114
|
+
class = [];
|
|
115
|
+
isMultiple = !1;
|
|
116
|
+
isOpen = !1;
|
|
117
|
+
isFullOpen = !1;
|
|
118
|
+
disabled;
|
|
119
|
+
alwaysOpen;
|
|
120
|
+
showSearch;
|
|
121
|
+
focusSearch;
|
|
122
|
+
keepSearch;
|
|
123
|
+
ariaLabel;
|
|
124
|
+
searchPlaceholder;
|
|
125
|
+
searchText;
|
|
126
|
+
searchingText;
|
|
127
|
+
resultsText;
|
|
128
|
+
deselectText;
|
|
129
|
+
removeText;
|
|
130
|
+
searchHighlight;
|
|
131
|
+
closeOnSelect;
|
|
132
|
+
contentLocation;
|
|
133
|
+
contentPosition;
|
|
134
|
+
contentWidth;
|
|
135
|
+
openPosition;
|
|
136
|
+
placeholderText;
|
|
137
|
+
allowDeselect;
|
|
138
|
+
hideSelected;
|
|
139
|
+
multiString;
|
|
140
|
+
keepOrder;
|
|
141
|
+
showOptionTooltips;
|
|
142
|
+
minSelected;
|
|
143
|
+
maxSelected;
|
|
144
|
+
timeoutDelay;
|
|
145
|
+
maxValuesShown;
|
|
146
|
+
maxValuesMessage;
|
|
147
|
+
addableText;
|
|
148
|
+
selectAll;
|
|
149
|
+
selectAllText;
|
|
150
|
+
unselectAllText;
|
|
151
|
+
modal;
|
|
152
|
+
modalTitle;
|
|
153
|
+
constructor(e) {
|
|
154
|
+
e ||= {}, this.id = "ss-" + b(), this.style = e.style || "", this.class = e.class || [], this.disabled = e.disabled !== void 0 && e.disabled, this.alwaysOpen = e.alwaysOpen !== void 0 && e.alwaysOpen, this.showSearch = e.showSearch === void 0 || e.showSearch, this.focusSearch = e.focusSearch === void 0 ? typeof window > "u" || window.innerWidth >= 768 : e.focusSearch, this.keepSearch = e.keepSearch !== void 0 && e.keepSearch, this.ariaLabel = e.ariaLabel || "Combobox", this.searchPlaceholder = e.searchPlaceholder || "Search...", this.searchText = e.searchText || "No Results", this.searchingText = e.searchingText || "Searching...", this.resultsText = e.resultsText || "{count} results available", this.deselectText = e.deselectText || "Clear", this.removeText = e.removeText || "Remove", this.searchHighlight = e.searchHighlight !== void 0 && e.searchHighlight, this.closeOnSelect = e.closeOnSelect === void 0 || e.closeOnSelect, this.contentLocation = e.contentLocation || document.body, this.contentPosition = e.contentPosition || "absolute", this.contentWidth = e.contentWidth || "", this.openPosition = e.openPosition || "auto", this.placeholderText = e.placeholderText === void 0 ? "Select Value" : e.placeholderText, this.allowDeselect = e.allowDeselect !== void 0 && e.allowDeselect, this.hideSelected = e.hideSelected !== void 0 && e.hideSelected, this.multiString = e.multiString !== void 0 && e.multiString, this.keepOrder = e.keepOrder !== void 0 && e.keepOrder, this.showOptionTooltips = e.showOptionTooltips !== void 0 && e.showOptionTooltips, this.minSelected = e.minSelected || 0, this.maxSelected = e.maxSelected || 1e3, this.timeoutDelay = e.timeoutDelay || 200, this.maxValuesShown = e.maxValuesShown || 20, this.maxValuesMessage = e.maxValuesMessage || "{number} selected", this.addableText = e.addableText || "Press \"Enter\" to add {value}", this.selectAll = e.selectAll !== void 0 && e.selectAll, this.selectAllText = e.selectAllText || "Select All", this.unselectAllText = e.unselectAllText || "Unselect All", this.modal = e.modal || "mobile", this.modalTitle = e.modalTitle || "";
|
|
155
|
+
}
|
|
156
|
+
};
|
|
157
|
+
// src/slim-select/helpers.ts
|
|
158
|
+
function _(e) {
|
|
159
|
+
if (!e) return {};
|
|
160
|
+
let t = {};
|
|
161
|
+
for (let n of Object.keys(e)) {
|
|
162
|
+
let r = e[n];
|
|
163
|
+
r !== void 0 && (t[n] = r);
|
|
164
|
+
}
|
|
165
|
+
return t;
|
|
166
|
+
}
|
|
167
|
+
function v(e) {
|
|
168
|
+
let t = e.cloneNode(!0);
|
|
169
|
+
return t.querySelectorAll("select, option, optgroup, textarea, input, button").forEach((e) => e.remove()), t.textContent?.replace(/\s+/g, " ").trim() || "";
|
|
170
|
+
}
|
|
171
|
+
function y(e) {
|
|
172
|
+
if (e.labels && e.labels.length > 0) {
|
|
173
|
+
let t = Array.from(e.labels).map(v).filter(Boolean);
|
|
174
|
+
if (t.length > 0) return [...new Set(t)].join(" ");
|
|
175
|
+
}
|
|
176
|
+
return e.getAttribute("aria-label")?.trim() || "";
|
|
177
|
+
}
|
|
178
|
+
function b() {
|
|
179
|
+
return Math.random().toString(36).substring(2, 10);
|
|
180
|
+
}
|
|
181
|
+
function x(e, t) {
|
|
182
|
+
function n(e, n) {
|
|
183
|
+
return n && e && e.classList && e.classList.contains(n) || n && e && e.dataset && e.dataset.id && e.dataset.id === t ? e : null;
|
|
184
|
+
}
|
|
185
|
+
function r(e, t) {
|
|
186
|
+
return !e || e === document ? null : n(e, t) ? e : r(e.parentNode, t);
|
|
187
|
+
}
|
|
188
|
+
return n(e, t) || r(e, t);
|
|
189
|
+
}
|
|
190
|
+
function S(e, t = 50, n = !1) {
|
|
191
|
+
let r;
|
|
192
|
+
return function(...i) {
|
|
193
|
+
let a = self, o = () => {
|
|
194
|
+
r = null, n || e.apply(a, i);
|
|
195
|
+
}, s = n && !r;
|
|
196
|
+
clearTimeout(r), r = setTimeout(o, t), s && e.apply(a, i);
|
|
197
|
+
};
|
|
198
|
+
}
|
|
199
|
+
function C(e, t) {
|
|
200
|
+
if (e.length !== t.length) return !1;
|
|
201
|
+
let n = [...e].sort(), r = [...t].sort();
|
|
202
|
+
return n.every((e, t) => e === r[t]);
|
|
203
|
+
}
|
|
204
|
+
var w = [
|
|
205
|
+
"id",
|
|
206
|
+
"value",
|
|
207
|
+
"text",
|
|
208
|
+
"html",
|
|
209
|
+
"defaultSelected",
|
|
210
|
+
"selected",
|
|
211
|
+
"display",
|
|
212
|
+
"disabled",
|
|
213
|
+
"placeholder",
|
|
214
|
+
"class",
|
|
215
|
+
"style",
|
|
216
|
+
"mandatory"
|
|
217
|
+
];
|
|
218
|
+
function T(e, t) {
|
|
219
|
+
let n = Object.keys(e), r = Object.keys(t);
|
|
220
|
+
if (n.length !== r.length) return !1;
|
|
221
|
+
for (let r of n) if (e[r] !== t[r]) return !1;
|
|
222
|
+
return !0;
|
|
223
|
+
}
|
|
224
|
+
function E(e, t) {
|
|
225
|
+
switch (t) {
|
|
226
|
+
case "id": return e.id || "";
|
|
227
|
+
case "value": return e.value === void 0 ? e.text || "" : e.value || "";
|
|
228
|
+
case "text": return e.text || "";
|
|
229
|
+
case "html": return e.html || "";
|
|
230
|
+
case "defaultSelected": return e.defaultSelected ?? !1;
|
|
231
|
+
case "selected": return e.selected ?? !1;
|
|
232
|
+
case "display": return e.display ?? !0;
|
|
233
|
+
case "disabled": return e.disabled ?? !1;
|
|
234
|
+
case "placeholder": return e.placeholder ?? !1;
|
|
235
|
+
case "class": return e.class || "";
|
|
236
|
+
case "style": return e.style || "";
|
|
237
|
+
case "mandatory": return e.mandatory ?? !1;
|
|
238
|
+
default: return e.data || {};
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
function D(e) {
|
|
242
|
+
return !!e && typeof e == "object" && "label" in e && "options" in e;
|
|
243
|
+
}
|
|
244
|
+
function O(e, t) {
|
|
245
|
+
for (let n of w) if (E(e, n) !== E(t, n)) return !1;
|
|
246
|
+
return T(e.data || {}, t.data || {});
|
|
247
|
+
}
|
|
248
|
+
function k(e, t) {
|
|
249
|
+
let n = (e) => ({
|
|
250
|
+
id: e.id || "",
|
|
251
|
+
label: e.label || "",
|
|
252
|
+
selectAll: e.selectAll ?? !1,
|
|
253
|
+
closable: e.closable || "off"
|
|
254
|
+
}), r = n(e), i = n(t);
|
|
255
|
+
if (r.id !== i.id || r.label !== i.label || r.selectAll !== i.selectAll || r.closable !== i.closable) return !1;
|
|
256
|
+
let a = e.options || [], o = t.options || [];
|
|
257
|
+
if (a.length !== o.length) return !1;
|
|
258
|
+
for (let e = 0; e < a.length; e++) if (!O(a[e], o[e])) return !1;
|
|
259
|
+
return !0;
|
|
260
|
+
}
|
|
261
|
+
function A(e, t) {
|
|
262
|
+
if (e === t) return !0;
|
|
263
|
+
if (e.length !== t.length) return !1;
|
|
264
|
+
for (let n = 0; n < e.length; n++) {
|
|
265
|
+
let r = e[n], i = t[n], a = D(r);
|
|
266
|
+
if (a !== D(i)) return !1;
|
|
267
|
+
if (a) {
|
|
268
|
+
if (!k(r, i)) return !1;
|
|
269
|
+
} else if (!O(r, i)) return !1;
|
|
270
|
+
}
|
|
271
|
+
return !0;
|
|
272
|
+
}
|
|
273
|
+
function j(e) {
|
|
274
|
+
let t = e.replace(/[A-Z\u00C0-\u00D6\u00D8-\u00DE]/g, (e) => "-" + e.toLowerCase());
|
|
275
|
+
return e[0] === e[0].toUpperCase() ? t.substring(1) : t;
|
|
276
|
+
}
|
|
277
|
+
function M(e, t = typeof window < "u" ? window.innerWidth : 768) {
|
|
278
|
+
return e === "on" || e === "mobile" && t < 768;
|
|
279
|
+
}
|
|
280
|
+
// src/slim-select/events.ts
|
|
281
|
+
var N = class {
|
|
282
|
+
handlers;
|
|
283
|
+
attached = !1;
|
|
284
|
+
constructor(e) {
|
|
285
|
+
this.handlers = e;
|
|
286
|
+
}
|
|
287
|
+
attach(e) {
|
|
288
|
+
this.attached || (this.attached = !0, window.addEventListener("resize", this.resizeHandler, !1), e.listenScroll && window.addEventListener("scroll", this.scrollHandler, !1), document.addEventListener("visibilitychange", this.visibilityHandler));
|
|
289
|
+
}
|
|
290
|
+
attachDocumentClick() {
|
|
291
|
+
document.addEventListener("click", this.handlers.onDocumentClick);
|
|
292
|
+
}
|
|
293
|
+
detachDocumentClick() {
|
|
294
|
+
document.removeEventListener("click", this.handlers.onDocumentClick);
|
|
295
|
+
}
|
|
296
|
+
detach(e) {
|
|
297
|
+
this.attached && (this.attached = !1, this.detachDocumentClick(), window.removeEventListener("resize", this.resizeHandler, !1), e.listenScroll && window.removeEventListener("scroll", this.scrollHandler, !1), document.removeEventListener("visibilitychange", this.visibilityHandler));
|
|
298
|
+
}
|
|
299
|
+
resizeHandler = S(() => {
|
|
300
|
+
this.handlers.onWindowResize();
|
|
301
|
+
});
|
|
302
|
+
scrollHandler = S(() => {
|
|
303
|
+
this.handlers.onWindowScroll();
|
|
304
|
+
});
|
|
305
|
+
visibilityHandler = () => {
|
|
306
|
+
this.handlers.onVisibilityChange();
|
|
307
|
+
};
|
|
308
|
+
}, P = class {
|
|
309
|
+
handlers;
|
|
310
|
+
options;
|
|
311
|
+
state = "closed";
|
|
312
|
+
pendingTimer = null;
|
|
313
|
+
waitResolvers = [];
|
|
314
|
+
generation = 0;
|
|
315
|
+
animationAbort = null;
|
|
316
|
+
constructor(e, t) {
|
|
317
|
+
this.handlers = e, this.options = t;
|
|
318
|
+
}
|
|
319
|
+
get isOpen() {
|
|
320
|
+
return this.state === "opening" || this.state === "open";
|
|
321
|
+
}
|
|
322
|
+
get isFullOpen() {
|
|
323
|
+
return this.state === "open";
|
|
324
|
+
}
|
|
325
|
+
async requestOpen() {
|
|
326
|
+
if (this.state === "opening" || this.state === "open") return;
|
|
327
|
+
this.cancelPending();
|
|
328
|
+
let e = ++this.generation;
|
|
329
|
+
this.handlers.beforeOpen && this.handlers.beforeOpen(), this.state = "opening", await this.waitForPhase("open", e), e === this.generation ? (this.state = "open", this.handlers.afterOpen && this.handlers.afterOpen(), this.handlers.onOpenReady && this.handlers.onOpenReady()) : this.state === "opening" && (this.state = "closed");
|
|
330
|
+
}
|
|
331
|
+
async requestClose(e = {
|
|
332
|
+
source: "api",
|
|
333
|
+
selectionChanged: !1
|
|
334
|
+
}) {
|
|
335
|
+
if (this.state === "closed" || this.state === "closing" || this.handlers.beforeClose && this.handlers.beforeClose(e) === !1) return !1;
|
|
336
|
+
this.cancelPending();
|
|
337
|
+
let t = ++this.generation;
|
|
338
|
+
return this.handlers.onClose && this.handlers.onClose(e), this.state = "closing", await this.waitForPhase("close", t), t === this.generation && (this.state = "closed", this.handlers.afterClose && this.handlers.afterClose(), this.handlers.onCloseReady && this.handlers.onCloseReady(), !0);
|
|
339
|
+
}
|
|
340
|
+
cancelPending() {
|
|
341
|
+
this.generation++, this.animationAbort?.abort(), this.animationAbort = null, this.pendingTimer &&= (clearTimeout(this.pendingTimer), null);
|
|
342
|
+
let e = this.waitResolvers.splice(0);
|
|
343
|
+
for (let t of e) t();
|
|
344
|
+
}
|
|
345
|
+
destroy() {
|
|
346
|
+
this.cancelPending(), this.state = "closed";
|
|
347
|
+
}
|
|
348
|
+
waitForPhase(e, t) {
|
|
349
|
+
return new Promise((t) => {
|
|
350
|
+
let n = !1, r = () => {
|
|
351
|
+
if (n) return;
|
|
352
|
+
n = !0;
|
|
353
|
+
let e = this.waitResolvers.indexOf(r);
|
|
354
|
+
e !== -1 && this.waitResolvers.splice(e, 1), t();
|
|
355
|
+
};
|
|
356
|
+
if (this.waitResolvers.push(r), this.options.waitForAnimation) {
|
|
357
|
+
let t = new AbortController();
|
|
358
|
+
this.animationAbort = t, this.options.waitForAnimation(e, t.signal).catch(() => void 0).finally(() => {
|
|
359
|
+
this.animationAbort === t && (this.animationAbort = null), r();
|
|
360
|
+
});
|
|
361
|
+
} else this.pendingTimer = setTimeout(() => {
|
|
362
|
+
this.pendingTimer = null, r();
|
|
363
|
+
}, this.options.timeoutDelay);
|
|
364
|
+
}).then(() => {
|
|
365
|
+
this.generation;
|
|
366
|
+
});
|
|
367
|
+
}
|
|
368
|
+
}, F = class {
|
|
369
|
+
id;
|
|
370
|
+
value;
|
|
371
|
+
text;
|
|
372
|
+
html;
|
|
373
|
+
defaultSelected;
|
|
374
|
+
selected;
|
|
375
|
+
display;
|
|
376
|
+
disabled;
|
|
377
|
+
placeholder;
|
|
378
|
+
class;
|
|
379
|
+
style;
|
|
380
|
+
data;
|
|
381
|
+
mandatory;
|
|
382
|
+
constructor(e) {
|
|
383
|
+
this.id = !e.id || e.id === "" ? b() : e.id, this.value = e.value === void 0 ? e.text || "" : e.value || "", this.text = e.text || "", this.html = e.html || "", this.defaultSelected = e.defaultSelected !== void 0 && e.defaultSelected, this.selected = e.selected !== void 0 && e.selected, this.display = e.display === void 0 || e.display, this.disabled = e.disabled !== void 0 && e.disabled, this.mandatory = e.mandatory !== void 0 && e.mandatory, this.placeholder = e.placeholder !== void 0 && e.placeholder, this.class = e.class || "", this.style = e.style || "", this.data = _(e.data);
|
|
384
|
+
}
|
|
385
|
+
}, I = class {
|
|
386
|
+
id;
|
|
387
|
+
label;
|
|
388
|
+
selectAll;
|
|
389
|
+
closable;
|
|
390
|
+
options;
|
|
391
|
+
constructor(e) {
|
|
392
|
+
if (this.id = !e.id || e.id === "" ? b() : e.id, this.label = e.label || "", this.selectAll = e.selectAll !== void 0 && e.selectAll, this.closable = e.closable || "off", this.options = [], e.options) for (let t of e.options) this.options.push(new F(t));
|
|
393
|
+
}
|
|
394
|
+
}, L = class {
|
|
395
|
+
selectType = "single";
|
|
396
|
+
data = [];
|
|
397
|
+
selectedOrder = [];
|
|
398
|
+
catalog = null;
|
|
399
|
+
constructor(e, t) {
|
|
400
|
+
this.selectType = e, this.setData(t), this.snapshotCatalog();
|
|
401
|
+
}
|
|
402
|
+
validateDataArray(e) {
|
|
403
|
+
if (!Array.isArray(e)) return /* @__PURE__ */ Error("Data must be an array");
|
|
404
|
+
for (let t of e) if (t) {
|
|
405
|
+
if (t instanceof I || "label" in t) {
|
|
406
|
+
if (!("label" in t)) return /* @__PURE__ */ Error("Optgroup must have a label");
|
|
407
|
+
if ("options" in t && t.options) for (let e of t.options) {
|
|
408
|
+
let t = this.validateOption(e);
|
|
409
|
+
if (t) return t;
|
|
410
|
+
}
|
|
411
|
+
} else if (t instanceof F || "text" in t) {
|
|
412
|
+
let e = this.validateOption(t);
|
|
413
|
+
if (e) return e;
|
|
414
|
+
} else return /* @__PURE__ */ Error("Data object must be a valid optgroup or option");
|
|
415
|
+
}
|
|
416
|
+
return null;
|
|
417
|
+
}
|
|
418
|
+
validateOption(e) {
|
|
419
|
+
return "text" in e ? null : /* @__PURE__ */ Error("Option must have a text");
|
|
420
|
+
}
|
|
421
|
+
partialToFullData(e) {
|
|
422
|
+
let t = [];
|
|
423
|
+
return e.forEach((e) => {
|
|
424
|
+
if (e) {
|
|
425
|
+
if (e instanceof I || "label" in e) {
|
|
426
|
+
let n = [];
|
|
427
|
+
"options" in e && e.options && e.options.forEach((e) => {
|
|
428
|
+
n.push(new F(e));
|
|
429
|
+
}), n.length > 0 && t.push(new I(e));
|
|
430
|
+
}
|
|
431
|
+
(e instanceof F || "text" in e) && t.push(new F(e));
|
|
432
|
+
}
|
|
433
|
+
}), t;
|
|
434
|
+
}
|
|
435
|
+
snapshotCatalog() {
|
|
436
|
+
this.catalog = this.cloneData(this.data);
|
|
437
|
+
}
|
|
438
|
+
getCatalogData() {
|
|
439
|
+
return this.cloneData(this.catalog ?? this.data);
|
|
440
|
+
}
|
|
441
|
+
cloneData(e) {
|
|
442
|
+
return e.map((e) => e instanceof I ? new I({
|
|
443
|
+
id: e.id,
|
|
444
|
+
label: e.label,
|
|
445
|
+
selectAll: e.selectAll,
|
|
446
|
+
closable: e.closable,
|
|
447
|
+
options: e.options.map((e) => new F(e instanceof F ? { ...e } : e))
|
|
448
|
+
}) : new F({ ...e }));
|
|
449
|
+
}
|
|
450
|
+
optionMatchesSelected(e, t) {
|
|
451
|
+
return e.id === t.id || t.value !== "" && e.value !== "" && e.value === t.value;
|
|
452
|
+
}
|
|
453
|
+
findOptionInData(e, t) {
|
|
454
|
+
for (let n of e) if (n instanceof F) {
|
|
455
|
+
if (this.optionMatchesSelected(n, t)) return n;
|
|
456
|
+
} else for (let e of n.options) if (this.optionMatchesSelected(e, t)) return e;
|
|
457
|
+
return null;
|
|
458
|
+
}
|
|
459
|
+
setData(e, t = !1) {
|
|
460
|
+
let n = this.partialToFullData(e), r = [];
|
|
461
|
+
if (t) {
|
|
462
|
+
r = this.getSelectedOptions();
|
|
463
|
+
let e = [];
|
|
464
|
+
r.forEach((t) => {
|
|
465
|
+
this.findOptionInData(n, t) || e.push(t);
|
|
466
|
+
}), this.data = [...e, ...n];
|
|
467
|
+
let t = this.selectType === "single" && r.length === 0, i = r.map((e) => {
|
|
468
|
+
let t = this.findOptionInData(this.data, e);
|
|
469
|
+
return t ? t.id : e.id;
|
|
470
|
+
});
|
|
471
|
+
this.setSelectedBy("id", i, t);
|
|
472
|
+
} else this.data = n;
|
|
473
|
+
!t && this.selectType === "single" && this.setSelectedBy("id", this.getSelected(), !1);
|
|
474
|
+
}
|
|
475
|
+
getData(e = !0) {
|
|
476
|
+
return this.filter(null, !0, e);
|
|
477
|
+
}
|
|
478
|
+
getDataOptions(e = !0) {
|
|
479
|
+
return this.filter(null, !1, e);
|
|
480
|
+
}
|
|
481
|
+
addOption(e, t = !1) {
|
|
482
|
+
if (t) {
|
|
483
|
+
let t = [new F(e)];
|
|
484
|
+
this.setData(t.concat(this.getData()));
|
|
485
|
+
} else this.setData(this.getData().concat(new F(e)));
|
|
486
|
+
}
|
|
487
|
+
setSelectedBy(e, t, n = !1) {
|
|
488
|
+
let r = null, i = !1, a = [];
|
|
489
|
+
for (let n of this.data) {
|
|
490
|
+
if (n instanceof I) for (let o of n.options) {
|
|
491
|
+
r ||= o;
|
|
492
|
+
let n = o[e] || "";
|
|
493
|
+
o.selected = !i && t.includes(n), o.selected && (a.push(o), this.selectType === "single" && (i = !0));
|
|
494
|
+
}
|
|
495
|
+
n instanceof F && (r ||= n, n.selected = !i && t.includes(n[e]), n.selected && (a.push(n), this.selectType === "single" && (i = !0)));
|
|
496
|
+
}
|
|
497
|
+
this.selectType === "single" && r && !i && !n && (r.selected = !0, a.push(r));
|
|
498
|
+
let o = t.map((t) => a.find((n) => n[e] === t)?.id || "");
|
|
499
|
+
this.selectedOrder = o;
|
|
500
|
+
}
|
|
501
|
+
getSelected() {
|
|
502
|
+
return this.getSelectedOptions().map((e) => e.id);
|
|
503
|
+
}
|
|
504
|
+
getSelectedValues() {
|
|
505
|
+
return this.getSelectedOptions().map((e) => e.value);
|
|
506
|
+
}
|
|
507
|
+
getSelectedOptions() {
|
|
508
|
+
let e = [];
|
|
509
|
+
for (let t of this.data) if (t instanceof I) for (let n of t.options) n.selected && e.push(n);
|
|
510
|
+
else t.selected && e.push(t);
|
|
511
|
+
return e;
|
|
512
|
+
}
|
|
513
|
+
getOptgroupByID(e) {
|
|
514
|
+
for (let t of this.data) if (t instanceof I && t.id === e) return t;
|
|
515
|
+
return null;
|
|
516
|
+
}
|
|
517
|
+
getOptionByID(e) {
|
|
518
|
+
for (let t of this.data) if (t instanceof I) {
|
|
519
|
+
for (let n of t.options) if (n.id === e) return n;
|
|
520
|
+
} else if (t.id === e) return t;
|
|
521
|
+
return null;
|
|
522
|
+
}
|
|
523
|
+
getSelectType() {
|
|
524
|
+
return this.selectType;
|
|
525
|
+
}
|
|
526
|
+
getFirstOption() {
|
|
527
|
+
let e = null;
|
|
528
|
+
for (let t of this.data) if (t instanceof I ? e = t.options[0] : t instanceof F && (e = t), e) break;
|
|
529
|
+
return e;
|
|
530
|
+
}
|
|
531
|
+
search(e, t) {
|
|
532
|
+
return e = e.trim(), e === "" ? this.getData(!1) : this.filter((n) => t(n, e), !0, !1);
|
|
533
|
+
}
|
|
534
|
+
createOptgroupView(e, t) {
|
|
535
|
+
let n = new I({
|
|
536
|
+
id: e.id,
|
|
537
|
+
label: e.label,
|
|
538
|
+
selectAll: e.selectAll,
|
|
539
|
+
closable: e.closable,
|
|
540
|
+
options: []
|
|
541
|
+
});
|
|
542
|
+
return n.options = t, n;
|
|
543
|
+
}
|
|
544
|
+
filter(e, t, n = !0) {
|
|
545
|
+
let r = [];
|
|
546
|
+
return this.data.forEach((i) => {
|
|
547
|
+
if (i instanceof I) {
|
|
548
|
+
let a = [];
|
|
549
|
+
if (i.options.forEach((i) => {
|
|
550
|
+
(!e || e(i)) && (t ? a.push(n ? new F(i) : i) : r.push(n ? new F(i) : i));
|
|
551
|
+
}), a.length > 0) {
|
|
552
|
+
if (n) {
|
|
553
|
+
let e = new I(i);
|
|
554
|
+
e.options = a, r.push(e);
|
|
555
|
+
} else r.push(this.createOptgroupView(i, a));
|
|
556
|
+
}
|
|
557
|
+
}
|
|
558
|
+
i instanceof F && (!e || e(i)) && r.push(n ? new F(i) : i);
|
|
559
|
+
}), r;
|
|
560
|
+
}
|
|
561
|
+
selectedOrderOptions(e) {
|
|
562
|
+
let t = [];
|
|
563
|
+
return this.selectedOrder.forEach((n) => {
|
|
564
|
+
let r = e.find((e) => e.id === n);
|
|
565
|
+
r && t.push(r);
|
|
566
|
+
}), e.forEach((e) => {
|
|
567
|
+
let n = !1;
|
|
568
|
+
t.forEach((t) => {
|
|
569
|
+
e.id === t.id && (n = !0);
|
|
570
|
+
}), n || t.push(e);
|
|
571
|
+
}), t;
|
|
572
|
+
}
|
|
573
|
+
}, R = 1e3, z = class {
|
|
574
|
+
settings;
|
|
575
|
+
store;
|
|
576
|
+
callbacks;
|
|
577
|
+
lastSelectedOption;
|
|
578
|
+
lastRenderedOptions;
|
|
579
|
+
optionsListIsFullData = !1;
|
|
580
|
+
lastSearchFilterTerm = "";
|
|
581
|
+
main;
|
|
582
|
+
content;
|
|
583
|
+
classes;
|
|
584
|
+
positionObserver = null;
|
|
585
|
+
positionObserverRaf = 0;
|
|
586
|
+
lastObservedContentHeight = -1;
|
|
587
|
+
overflowShiftRaf = 0;
|
|
588
|
+
typeaheadQuery = "";
|
|
589
|
+
typeaheadTimer = null;
|
|
590
|
+
modalElements = null;
|
|
591
|
+
modalSessionActive = null;
|
|
592
|
+
bodyScrollLocked = !1;
|
|
593
|
+
savedBodyOverflow = "";
|
|
594
|
+
constructor(e, t, n, r) {
|
|
595
|
+
this.store = n, this.settings = e, this.classes = t, this.callbacks = r, this.lastSelectedOption = null, this.lastRenderedOptions = [], this.main = this.mainDiv(), this.content = this.contentDiv(), this.updateClassStyles(), this.updateAriaAttributes(), this.settings.contentPosition !== "relative" && (this.content.main.style.top = "-9999px", this.content.main.style.left = "-9999px", this.content.main.style.margin = "0", this.content.main.style.width = "auto"), this.settings.contentLocation && this.settings.contentLocation.appendChild(this.content.main), this.settings.modal !== "off" && !this.settings.alwaysOpen && (this.modalElements = this.createModalElements(), document.body.appendChild(this.modalElements.overlay));
|
|
596
|
+
}
|
|
597
|
+
requestClose(e, t) {
|
|
598
|
+
this.callbacks.close({
|
|
599
|
+
source: e,
|
|
600
|
+
option: t?.option,
|
|
601
|
+
selectionChanged: t?.selectionChanged ?? !1
|
|
602
|
+
});
|
|
603
|
+
}
|
|
604
|
+
selectionChanged(e, t) {
|
|
605
|
+
if (e.length !== t.length) return !0;
|
|
606
|
+
let n = e.map((e) => e.id).sort(), r = t.map((e) => e.id).sort();
|
|
607
|
+
return n.some((e, t) => e !== r[t]);
|
|
608
|
+
}
|
|
609
|
+
closeOnSingleSelectReclick(e) {
|
|
610
|
+
this.settings.closeOnSelect && this.requestClose("select", {
|
|
611
|
+
option: e,
|
|
612
|
+
selectionChanged: !1
|
|
613
|
+
});
|
|
614
|
+
}
|
|
615
|
+
addClasses(e, t) {
|
|
616
|
+
if (!t || t.trim() === "") return;
|
|
617
|
+
let n = t.split(" ").filter((e) => e.trim() !== "");
|
|
618
|
+
for (let t of n) e.classList.add(t.trim());
|
|
619
|
+
}
|
|
620
|
+
removeClasses(e, t) {
|
|
621
|
+
if (!t || t.trim() === "") return;
|
|
622
|
+
let n = t.split(" ").filter((e) => e.trim() !== "");
|
|
623
|
+
for (let t of n) e.classList.remove(t.trim());
|
|
624
|
+
}
|
|
625
|
+
enable() {
|
|
626
|
+
this.removeClasses(this.main.main, this.classes.disabled), this.main.main.setAttribute("aria-disabled", "false"), this.content.search.input.disabled = !1;
|
|
627
|
+
}
|
|
628
|
+
disable() {
|
|
629
|
+
this.addClasses(this.main.main, this.classes.disabled), this.main.main.setAttribute("aria-disabled", "true"), this.content.search.input.disabled = !0;
|
|
630
|
+
}
|
|
631
|
+
open() {
|
|
632
|
+
this.main.arrow.path.setAttribute("d", this.classes.arrowOpen), this.main.main.setAttribute("aria-expanded", "true");
|
|
633
|
+
let e = this.resolveModalView();
|
|
634
|
+
if (!e) {
|
|
635
|
+
let e = this.settings.openPosition === "up" ? this.classes.dirAbove : this.classes.dirBelow;
|
|
636
|
+
this.addClasses(this.main.main, e), this.addClasses(this.content.main, e);
|
|
637
|
+
}
|
|
638
|
+
this.addClasses(this.content.main, this.classes.contentOpen), this.content.search.input.removeAttribute("aria-hidden"), e ? this.showModal() : this.moveContent();
|
|
639
|
+
let t = this.store.getSelectedOptions();
|
|
640
|
+
if (t.length) {
|
|
641
|
+
let e = t[t.length - 1].id, n = this.content.list.querySelector("[data-id=\"" + e + "\"]");
|
|
642
|
+
n && this.ensureElementInView(this.content.list, n);
|
|
643
|
+
}
|
|
644
|
+
}
|
|
645
|
+
isModalViewActive() {
|
|
646
|
+
return this.modalSessionActive === !0;
|
|
647
|
+
}
|
|
648
|
+
resolveModalView() {
|
|
649
|
+
return this.settings.alwaysOpen || this.settings.modal === "off" || !this.modalElements ? !1 : (this.modalSessionActive === null && (this.modalSessionActive = M(this.settings.modal)), this.modalSessionActive);
|
|
650
|
+
}
|
|
651
|
+
createModalElements() {
|
|
652
|
+
let e = document.createElement("div");
|
|
653
|
+
this.addClasses(e, this.classes.modalOverlay), this.addClasses(e, this.classes.hide), e.dataset.id = this.settings.id;
|
|
654
|
+
let t = document.createElement("div");
|
|
655
|
+
this.addClasses(t, this.classes.modalDialog), t.setAttribute("role", "dialog"), t.setAttribute("aria-modal", "true");
|
|
656
|
+
let n = null;
|
|
657
|
+
this.settings.modalTitle ? (n = document.createElement("div"), this.addClasses(n, this.classes.modalTitle), n.id = `${this.settings.id}-modal-title`, n.textContent = this.settings.modalTitle, t.setAttribute("aria-labelledby", n.id)) : t.setAttribute("aria-label", this.settings.ariaLabel);
|
|
658
|
+
let r = document.createElement("button");
|
|
659
|
+
r.type = "button", this.addClasses(r, this.classes.modalClose), r.setAttribute("aria-label", "Close"), r.onclick = (e) => {
|
|
660
|
+
e.stopPropagation(), this.requestClose("modal");
|
|
661
|
+
};
|
|
662
|
+
let i = document.createElementNS("http://www.w3.org/2000/svg", "svg");
|
|
663
|
+
i.setAttribute("viewBox", "0 0 100 100");
|
|
664
|
+
let a = document.createElementNS("http://www.w3.org/2000/svg", "path");
|
|
665
|
+
return a.setAttribute("d", this.classes.deselectPath), i.appendChild(a), r.appendChild(i), e.onclick = (t) => {
|
|
666
|
+
t.target === e && this.requestClose("modal");
|
|
667
|
+
}, n && t.appendChild(n), e.appendChild(t), {
|
|
668
|
+
overlay: e,
|
|
669
|
+
dialog: t,
|
|
670
|
+
closeButton: r,
|
|
671
|
+
title: n
|
|
672
|
+
};
|
|
673
|
+
}
|
|
674
|
+
showModal() {
|
|
675
|
+
this.modalElements && (this.modalElements.dialog.appendChild(this.content.main), this.addClasses(this.content.main, this.classes.modalContent), this.content.main.appendChild(this.modalElements.closeButton), this.content.main.style.top = "", this.content.main.style.left = "", this.content.main.style.margin = "", this.content.main.style.width = "", this.removeClasses(this.modalElements.overlay, this.classes.hide), requestAnimationFrame(() => {
|
|
676
|
+
this.modalElements && this.addClasses(this.modalElements.overlay, this.classes.contentOpen);
|
|
677
|
+
}), this.lockBodyScroll());
|
|
678
|
+
}
|
|
679
|
+
lockBodyScroll() {
|
|
680
|
+
this.bodyScrollLocked ||= (this.savedBodyOverflow = document.body.style.overflow, document.body.style.overflow = "hidden", !0);
|
|
681
|
+
}
|
|
682
|
+
unlockBodyScroll() {
|
|
683
|
+
this.bodyScrollLocked && (document.body.style.overflow = this.savedBodyOverflow, this.bodyScrollLocked = !1, this.savedBodyOverflow = "");
|
|
684
|
+
}
|
|
685
|
+
restoreContentOffscreen() {
|
|
686
|
+
this.settings.contentLocation && this.settings.contentLocation.appendChild(this.content.main), this.settings.contentPosition !== "relative" && (this.content.main.style.top = "-9999px", this.content.main.style.left = "-9999px", this.content.main.style.margin = "0", this.content.main.style.width = "auto");
|
|
687
|
+
}
|
|
688
|
+
finalizeModalClose() {
|
|
689
|
+
this.modalElements && this.content.main.parentElement === this.modalElements.dialog && (this.addClasses(this.modalElements.overlay, this.classes.hide), this.removeClasses(this.modalElements.overlay, this.classes.contentOpen), this.removeClasses(this.content.main, this.classes.modalContent), this.modalElements.closeButton.remove(), this.restoreContentOffscreen(), this.unlockBodyScroll());
|
|
690
|
+
}
|
|
691
|
+
waitForAnimation(e, t) {
|
|
692
|
+
let n = d(this.content.main, this.settings.timeoutDelay);
|
|
693
|
+
return m(this.content.main, c, n, t);
|
|
694
|
+
}
|
|
695
|
+
close() {
|
|
696
|
+
this.main.main.setAttribute("aria-expanded", "false"), this.main.arrow.path.setAttribute("d", this.classes.arrowClose);
|
|
697
|
+
let e = this.modalSessionActive === !0;
|
|
698
|
+
this.removeClasses(this.content.main, this.classes.contentOpen), e || (this.removeClasses(this.main.main, this.classes.dirAbove), this.removeClasses(this.main.main, this.classes.dirBelow)), e && this.modalElements && this.removeClasses(this.modalElements.overlay, this.classes.contentOpen), this.modalSessionActive = null, this.content.search.input.setAttribute("aria-hidden", "true"), this.main.main.removeAttribute("aria-activedescendant"), this.clearValueChipHighlight();
|
|
699
|
+
}
|
|
700
|
+
clearDirectionClasses() {
|
|
701
|
+
this.removeClasses(this.main.main, this.classes.dirAbove), this.removeClasses(this.main.main, this.classes.dirBelow), this.removeClasses(this.content.main, this.classes.dirAbove), this.removeClasses(this.content.main, this.classes.dirBelow);
|
|
702
|
+
}
|
|
703
|
+
updateClassStyles() {
|
|
704
|
+
if (this.main.main.className = "", this.main.main.removeAttribute("style"), this.content.main.className = "", this.content.main.removeAttribute("style"), this.addClasses(this.main.main, this.classes.main), this.addClasses(this.content.main, this.classes.content), this.settings.style !== "" && (this.main.main.style.cssText = this.settings.style, this.content.main.style.cssText = this.settings.style), this.settings.class.length) for (let e of this.settings.class) e.trim() !== "" && (this.main.main.classList.add(e.trim()), this.content.main.classList.add(e.trim()));
|
|
705
|
+
(this.settings.contentPosition === "relative" || this.settings.contentPosition === "fixed") && this.content.main.classList.add("ss-" + this.settings.contentPosition);
|
|
706
|
+
}
|
|
707
|
+
updateTitle(e) {
|
|
708
|
+
e ? this.main.main.setAttribute("title", e) : this.main.main.removeAttribute("title");
|
|
709
|
+
}
|
|
710
|
+
updateAriaAttributes() {
|
|
711
|
+
let e = this.content.list.id;
|
|
712
|
+
this.main.main.role = "combobox", this.main.main.setAttribute("aria-haspopup", "listbox"), this.main.main.setAttribute("aria-controls", e), this.main.main.setAttribute("aria-expanded", "false"), this.content.list.setAttribute("role", "listbox"), this.content.list.setAttribute("aria-label", this.settings.ariaLabel + " listbox"), this.settings.isMultiple && this.content.list.setAttribute("aria-multiselectable", "true"), this.content.search.input.setAttribute("aria-controls", e);
|
|
713
|
+
}
|
|
714
|
+
mainDiv() {
|
|
715
|
+
let e = document.createElement("div");
|
|
716
|
+
e.dataset.id = this.settings.id, e.setAttribute("aria-label", this.settings.ariaLabel), e.tabIndex = 0, e.onkeydown = (e) => {
|
|
717
|
+
if (this.isTypeaheadKey(e)) return e.preventDefault(), this.callbacks.open(), this.typeahead(e.key), !1;
|
|
718
|
+
switch (e.key) {
|
|
719
|
+
case "ArrowUp":
|
|
720
|
+
case "ArrowDown": return this.clearTypeahead(), this.callbacks.open(), e.key === "ArrowDown" ? this.highlight("down") : this.highlight("up"), !1;
|
|
721
|
+
case "Tab": return this.clearTypeahead(), this.requestClose("tab"), !0;
|
|
722
|
+
case "Enter":
|
|
723
|
+
case " ":
|
|
724
|
+
this.clearTypeahead(), this.callbacks.open();
|
|
725
|
+
let t = this.content.list.querySelector("." + this.classes.getFirst("highlighted"));
|
|
726
|
+
return t && t.click(), !1;
|
|
727
|
+
case "Escape": return this.clearTypeahead(), this.requestClose("escape"), !1;
|
|
728
|
+
}
|
|
729
|
+
return e.key.length === 1 && this.callbacks.open(), !0;
|
|
730
|
+
}, e.onclick = (e) => {
|
|
731
|
+
this.settings.disabled || (this.settings.isOpen ? this.requestClose("toggle") : this.callbacks.open());
|
|
732
|
+
};
|
|
733
|
+
let t = document.createElement("div");
|
|
734
|
+
this.addClasses(t, this.classes.values), e.appendChild(t);
|
|
735
|
+
let n = document.createElement("div");
|
|
736
|
+
this.addClasses(n, this.classes.deselect), n.setAttribute("role", "button"), n.setAttribute("aria-label", this.settings.deselectText), n.setAttribute("tabindex", "0");
|
|
737
|
+
let r = this.store?.getSelectedOptions();
|
|
738
|
+
!this.settings.allowDeselect || this.settings.isMultiple && r && r.length <= 0 || this.isAtMinSelected() ? this.addClasses(n, this.classes.hide) : this.removeClasses(n, this.classes.hide), n.onclick = (e) => {
|
|
739
|
+
if (e.stopPropagation(), this.settings.disabled || this.settings.isMultiple && this.isAtMinSelected()) return;
|
|
740
|
+
let t = !0, n = this.store.getSelectedOptions(), r = [], i = "";
|
|
741
|
+
if (this.settings.isMultiple) {
|
|
742
|
+
let e = this.settings.minSelected, t = this.store.getSelected();
|
|
743
|
+
if (e > 0 && t.length > e) i = this.getMinimumSelectionIds(), r = n.filter((e) => i.includes(e.id));
|
|
744
|
+
else if (e <= 0) i = [];
|
|
745
|
+
else return;
|
|
746
|
+
}
|
|
747
|
+
if (this.callbacks.beforeChange && (t = this.callbacks.beforeChange(r, n) === !0), t) {
|
|
748
|
+
if (this.settings.isMultiple) this.callbacks.setSelected(i, !1), this.updateDeselectAll();
|
|
749
|
+
else {
|
|
750
|
+
let e = this.store.getFirstOption(), t = e ? e.id : "";
|
|
751
|
+
this.callbacks.setSelected(t, !1);
|
|
752
|
+
}
|
|
753
|
+
this.settings.closeOnSelect && this.requestClose("deselect", { selectionChanged: !0 }), this.callbacks.afterChange && this.callbacks.afterChange(this.store.getSelectedOptions());
|
|
754
|
+
}
|
|
755
|
+
}, n.onkeydown = (e) => {
|
|
756
|
+
(e.key === "Enter" || e.key === " ") && (e.preventDefault(), n.click());
|
|
757
|
+
};
|
|
758
|
+
let i = document.createElementNS("http://www.w3.org/2000/svg", "svg");
|
|
759
|
+
i.setAttribute("viewBox", "0 0 100 100");
|
|
760
|
+
let a = document.createElementNS("http://www.w3.org/2000/svg", "path");
|
|
761
|
+
a.setAttribute("d", this.classes.deselectPath), i.appendChild(a), n.appendChild(i), e.appendChild(n);
|
|
762
|
+
let o = document.createElementNS("http://www.w3.org/2000/svg", "svg");
|
|
763
|
+
this.addClasses(o, this.classes.arrow), o.setAttribute("viewBox", "0 0 100 100");
|
|
764
|
+
let s = document.createElementNS("http://www.w3.org/2000/svg", "path");
|
|
765
|
+
return s.setAttribute("d", this.classes.arrowClose), this.settings.alwaysOpen && this.addClasses(o, this.classes.hide), o.appendChild(s), e.appendChild(o), {
|
|
766
|
+
main: e,
|
|
767
|
+
values: t,
|
|
768
|
+
deselect: {
|
|
769
|
+
main: n,
|
|
770
|
+
svg: i,
|
|
771
|
+
path: a
|
|
772
|
+
},
|
|
773
|
+
arrow: {
|
|
774
|
+
main: o,
|
|
775
|
+
path: s
|
|
776
|
+
}
|
|
777
|
+
};
|
|
778
|
+
}
|
|
779
|
+
mainFocus(e) {
|
|
780
|
+
e !== "click" && this.main.main.focus({ preventScroll: !0 });
|
|
781
|
+
}
|
|
782
|
+
placeholder() {
|
|
783
|
+
let e = this.store.filter((e) => e.placeholder, !1, !1), t = this.settings.placeholderText;
|
|
784
|
+
e.length && (e[0].html === "" ? e[0].text !== "" && (t = e[0].text) : t = e[0].html);
|
|
785
|
+
let n = document.createElement("div");
|
|
786
|
+
return this.addClasses(n, this.classes.placeholder), n.innerHTML = t, n;
|
|
787
|
+
}
|
|
788
|
+
renderValues() {
|
|
789
|
+
this.settings.isMultiple ? (this.renderMultipleValues(), this.updateDeselectAll()) : this.renderSingleValue();
|
|
790
|
+
}
|
|
791
|
+
renderSingleValue() {
|
|
792
|
+
let e = this.store.filter((e) => e.selected && !e.placeholder, !1, !1), t = e.length > 0 ? e[0] : null;
|
|
793
|
+
if (!t) this.main.values.innerHTML = this.placeholder().outerHTML;
|
|
794
|
+
else {
|
|
795
|
+
let e = document.createElement("div");
|
|
796
|
+
this.addClasses(e, this.classes.single), t.html ? e.innerHTML = t.html : e.innerText = t.text, this.main.values.innerHTML = e.outerHTML;
|
|
797
|
+
}
|
|
798
|
+
!this.settings.allowDeselect || !e.length ? this.addClasses(this.main.deselect.main, this.classes.hide) : this.removeClasses(this.main.deselect.main, this.classes.hide);
|
|
799
|
+
}
|
|
800
|
+
renderMultipleValues() {
|
|
801
|
+
let e = this.main.values.childNodes, t = this.store.filter((e) => e.selected && e.display, !1, !1);
|
|
802
|
+
if (t.length === 0) {
|
|
803
|
+
this.main.values.innerHTML = this.placeholder().outerHTML;
|
|
804
|
+
return;
|
|
805
|
+
}
|
|
806
|
+
{
|
|
807
|
+
let e = this.main.values.querySelector("." + this.classes.getFirst("placeholder"));
|
|
808
|
+
e && e.remove();
|
|
809
|
+
}
|
|
810
|
+
if (this.settings.multiString) {
|
|
811
|
+
let e = t;
|
|
812
|
+
this.settings.keepOrder && (e = this.store.selectedOrderOptions(e));
|
|
813
|
+
let n = document.createElement("div");
|
|
814
|
+
this.addClasses(n, this.classes.multiString), n.textContent = e.map((e) => e.text).join(", "), this.settings.showOptionTooltips && n.setAttribute("title", n.textContent), this.main.values.innerHTML = n.outerHTML;
|
|
815
|
+
return;
|
|
816
|
+
}
|
|
817
|
+
if (t.length > this.settings.maxValuesShown) {
|
|
818
|
+
let e = document.createElement("div");
|
|
819
|
+
this.addClasses(e, this.classes.max), e.textContent = this.settings.maxValuesMessage.replace("{number}", t.length.toString()), this.main.values.innerHTML = e.outerHTML;
|
|
820
|
+
return;
|
|
821
|
+
}
|
|
822
|
+
{
|
|
823
|
+
let e = this.main.values.querySelector("." + this.classes.getFirst("max"));
|
|
824
|
+
e && e.remove();
|
|
825
|
+
}
|
|
826
|
+
this.settings.keepOrder && (t = this.store.selectedOrderOptions(t));
|
|
827
|
+
let n = [];
|
|
828
|
+
for (let r = 0; r < e.length; r++) {
|
|
829
|
+
let i = e[r], a = i.getAttribute("data-id");
|
|
830
|
+
a && (t.filter((e) => e.id === a, !1).length || n.push(i));
|
|
831
|
+
}
|
|
832
|
+
let r = d(this.content.main, this.settings.timeoutDelay);
|
|
833
|
+
for (let e of n) this.addClasses(e, this.classes.valueOut), h(e, "ss-valueOut", r).then(() => {
|
|
834
|
+
this.main.values.hasChildNodes() && this.main.values.contains(e) && this.main.values.removeChild(e);
|
|
835
|
+
});
|
|
836
|
+
e = this.main.values.childNodes;
|
|
837
|
+
for (let n = 0; n < t.length; n++) {
|
|
838
|
+
let r = !0;
|
|
839
|
+
for (let i = 0; i < e.length; i++) t[n].id === String(e[i].dataset.id) && (r = !1);
|
|
840
|
+
r && (this.settings.keepOrder || e.length === 0 ? this.main.values.appendChild(this.multipleValue(t[n])) : n === 0 ? this.main.values.insertBefore(this.multipleValue(t[n]), e[n]) : e[n - 1].insertAdjacentElement("afterend", this.multipleValue(t[n])));
|
|
841
|
+
}
|
|
842
|
+
this.updateMultipleValueDeleteVisibility();
|
|
843
|
+
}
|
|
844
|
+
isAtMinSelected() {
|
|
845
|
+
return this.settings.isMultiple && this.settings.minSelected > 0 && this.store.getSelectedOptions().length <= this.settings.minSelected;
|
|
846
|
+
}
|
|
847
|
+
getMinimumSelectionIds() {
|
|
848
|
+
let e = this.store.getSelectedOptions();
|
|
849
|
+
return this.settings.keepOrder && (e = this.store.selectedOrderOptions(e)), e.slice(0, this.settings.minSelected).map((e) => e.id);
|
|
850
|
+
}
|
|
851
|
+
getValueChips() {
|
|
852
|
+
return !this.settings.isMultiple || this.settings.multiString ? [] : Array.from(this.main.values.querySelectorAll("." + this.classes.getFirst("value"))).filter((e) => {
|
|
853
|
+
if (e.classList.contains(this.classes.getFirst("valueOut"))) return !1;
|
|
854
|
+
let t = e.querySelector("." + this.classes.getFirst("valueDelete"));
|
|
855
|
+
return !!t && !t.classList.contains(this.classes.getFirst("hide"));
|
|
856
|
+
});
|
|
857
|
+
}
|
|
858
|
+
getHighlightedValueChip() {
|
|
859
|
+
return this.getValueChips().find((e) => e.classList.contains(this.classes.getFirst("highlighted"))) ?? null;
|
|
860
|
+
}
|
|
861
|
+
clearValueChipHighlight() {
|
|
862
|
+
for (let e of Array.from(this.main.values.querySelectorAll("." + this.classes.getFirst("value")))) this.removeClasses(e, this.classes.highlighted);
|
|
863
|
+
}
|
|
864
|
+
highlightValueChip(e) {
|
|
865
|
+
this.clearValueChipHighlight(), e && this.addClasses(e, this.classes.highlighted);
|
|
866
|
+
}
|
|
867
|
+
navigateValueChips(e) {
|
|
868
|
+
let t = this.getValueChips();
|
|
869
|
+
if (t.length === 0) return !1;
|
|
870
|
+
let n = this.getHighlightedValueChip(), r = n ? t.indexOf(n) : -1;
|
|
871
|
+
return e === "left" ? (r === -1 ? this.highlightValueChip(t[t.length - 1]) : r > 0 && this.highlightValueChip(t[r - 1]), !0) : r !== -1 && (r < t.length - 1 ? this.highlightValueChip(t[r + 1]) : this.clearValueChipHighlight(), !0);
|
|
872
|
+
}
|
|
873
|
+
deleteValueChip() {
|
|
874
|
+
let e = this.getValueChips(), t = this.getHighlightedValueChip();
|
|
875
|
+
if (!t) return !1;
|
|
876
|
+
let n = t.querySelector("." + this.classes.getFirst("valueDelete"));
|
|
877
|
+
if (!n) return !1;
|
|
878
|
+
let r = e.indexOf(t), i = e[r - 1] ?? e[r + 1] ?? null;
|
|
879
|
+
return n.click(), i && i !== t && this.main.values.contains(i) ? this.highlightValueChip(i) : this.clearValueChipHighlight(), !0;
|
|
880
|
+
}
|
|
881
|
+
updateMultipleValueDeleteVisibility() {
|
|
882
|
+
if (!this.settings.isMultiple || this.settings.multiString) return;
|
|
883
|
+
let e = !this.isAtMinSelected(), t = this.main.values.querySelectorAll("." + this.classes.getFirst("valueDelete"));
|
|
884
|
+
for (let n of t) e ? this.removeClasses(n, this.classes.hide) : this.addClasses(n, this.classes.hide);
|
|
885
|
+
}
|
|
886
|
+
multipleValue(e) {
|
|
887
|
+
let t = document.createElement("div");
|
|
888
|
+
this.addClasses(t, this.classes.value), t.dataset.id = e.id;
|
|
889
|
+
let n = document.createElement("div");
|
|
890
|
+
if (this.addClasses(n, this.classes.valueText), n.textContent = e.text, t.appendChild(n), !e.mandatory) {
|
|
891
|
+
let n = document.createElement("div");
|
|
892
|
+
this.addClasses(n, this.classes.valueDelete), n.setAttribute("tabindex", "0"), n.setAttribute("role", "button"), n.setAttribute("aria-label", `${this.settings.removeText} ${e.text}`), this.isAtMinSelected() && this.addClasses(n, this.classes.hide), n.onclick = (t) => {
|
|
893
|
+
if (t.preventDefault(), t.stopPropagation(), this.settings.disabled) return;
|
|
894
|
+
let n = !0, r = this.store.getSelectedOptions(), i = r.filter((t) => t.selected && t.id !== e.id, !0);
|
|
895
|
+
if (!(this.settings.minSelected && i.length < this.settings.minSelected) && (this.callbacks.beforeChange && (n = this.callbacks.beforeChange(i, r) === !0), n)) {
|
|
896
|
+
let e = [];
|
|
897
|
+
for (let t of i) {
|
|
898
|
+
if (t instanceof I) for (let n of t.options) n.id && e.push(n.id);
|
|
899
|
+
t instanceof F && e.push(t.id);
|
|
900
|
+
}
|
|
901
|
+
this.callbacks.setSelected(e, !1), this.settings.closeOnSelect && this.requestClose("deselect", { selectionChanged: !0 }), this.callbacks.afterChange && this.callbacks.afterChange(i), this.updateDeselectAll(), this.updateMultipleValueDeleteVisibility();
|
|
902
|
+
}
|
|
903
|
+
};
|
|
904
|
+
let r = document.createElementNS("http://www.w3.org/2000/svg", "svg");
|
|
905
|
+
r.setAttribute("viewBox", "0 0 100 100");
|
|
906
|
+
let i = document.createElementNS("http://www.w3.org/2000/svg", "path");
|
|
907
|
+
i.setAttribute("d", this.classes.optionDelete), r.appendChild(i), n.appendChild(r), t.appendChild(n), n.onkeydown = (e) => {
|
|
908
|
+
e.key === "Enter" && n.click();
|
|
909
|
+
};
|
|
910
|
+
}
|
|
911
|
+
return t;
|
|
912
|
+
}
|
|
913
|
+
contentDiv() {
|
|
914
|
+
let e = document.createElement("div");
|
|
915
|
+
e.dataset.id = this.settings.id;
|
|
916
|
+
let t = this.searchDiv();
|
|
917
|
+
e.appendChild(t.main);
|
|
918
|
+
let n = document.createElement("div");
|
|
919
|
+
this.addClasses(n, this.classes.status), n.setAttribute("aria-live", "polite"), n.setAttribute("aria-atomic", "true"), n.setAttribute("role", "status"), e.appendChild(n);
|
|
920
|
+
let r = this.listDiv();
|
|
921
|
+
return e.appendChild(r), {
|
|
922
|
+
main: e,
|
|
923
|
+
search: t,
|
|
924
|
+
status: n,
|
|
925
|
+
list: r
|
|
926
|
+
};
|
|
927
|
+
}
|
|
928
|
+
announce(e) {
|
|
929
|
+
this.settings.showSearch && (this.content.status.textContent = e);
|
|
930
|
+
}
|
|
931
|
+
repositionOpenContent() {
|
|
932
|
+
this.settings.isOpen && !this.isModalViewActive() && this.settings.contentPosition !== "relative" && this.content.main.classList.contains(this.classes.getFirst("dirAbove")) && this.moveContentAbove();
|
|
933
|
+
}
|
|
934
|
+
moveContent() {
|
|
935
|
+
this.isModalViewActive() || (this.settings.contentPosition === "relative" || this.settings.openPosition === "down" ? this.moveContentBelow() : this.settings.openPosition === "up" || this.putContent() === "up" ? this.moveContentAbove() : this.moveContentBelow());
|
|
936
|
+
}
|
|
937
|
+
startPositionTracking() {
|
|
938
|
+
this.settings.contentPosition !== "absolute" || this.isModalViewActive() || (this.stopPositionTracking(), typeof ResizeObserver < "u" && (this.lastObservedContentHeight = -1, this.positionObserver = new ResizeObserver((e) => {
|
|
939
|
+
if (!this.settings.isOpen) return;
|
|
940
|
+
let t = !1, n = !1;
|
|
941
|
+
for (let r of e) if (r.target === this.content.main) {
|
|
942
|
+
let e = r.contentRect.height;
|
|
943
|
+
e !== this.lastObservedContentHeight && (this.lastObservedContentHeight = e, t = !0);
|
|
944
|
+
} else n = !0;
|
|
945
|
+
(t || n) && (cancelAnimationFrame(this.positionObserverRaf), this.positionObserverRaf = requestAnimationFrame(() => {
|
|
946
|
+
n ? this.moveContent() : this.repositionOpenContent();
|
|
947
|
+
}));
|
|
948
|
+
}), this.observePositionTargets()));
|
|
949
|
+
}
|
|
950
|
+
stopPositionTracking() {
|
|
951
|
+
cancelAnimationFrame(this.positionObserverRaf), this.positionObserver?.disconnect(), this.positionObserver = null, this.lastObservedContentHeight = -1, this.cancelOverflowShift();
|
|
952
|
+
}
|
|
953
|
+
observePositionTargets() {
|
|
954
|
+
if (!this.positionObserver) return;
|
|
955
|
+
let e = /* @__PURE__ */ new Set(), t = (t) => {
|
|
956
|
+
t && !e.has(t) && (e.add(t), this.positionObserver.observe(t));
|
|
957
|
+
};
|
|
958
|
+
t(this.main.main), t(this.content.main);
|
|
959
|
+
let n = this.main.main.parentElement, r = this.settings.contentLocation;
|
|
960
|
+
for (let e = 0; n && e < 8 && (t(n), n !== r); e++) n = n.parentElement;
|
|
961
|
+
}
|
|
962
|
+
searchDiv() {
|
|
963
|
+
let e = document.createElement("div"), t = document.createElement("input"), n = document.createElement("div");
|
|
964
|
+
this.addClasses(e, this.classes.search);
|
|
965
|
+
let r = {
|
|
966
|
+
main: e,
|
|
967
|
+
input: t
|
|
968
|
+
}, i = this.settings.selectAll && this.settings.isMultiple;
|
|
969
|
+
this.settings.showSearch || (t.readOnly = !0, i ? this.addClasses(t, this.classes.hide) : this.addClasses(e, this.classes.hide)), t.type = "search", t.id = `${this.settings.id}-search`, t.placeholder = this.settings.searchPlaceholder, t.tabIndex = -1, t.setAttribute("aria-label", this.settings.searchPlaceholder), t.setAttribute("aria-autocomplete", "list"), t.setAttribute("autocapitalize", "off"), t.setAttribute("autocomplete", "off"), t.setAttribute("autocorrect", "off"), t.setAttribute("aria-hidden", "true");
|
|
970
|
+
let a = S(() => {
|
|
971
|
+
this.callbacks.search(t.value);
|
|
972
|
+
}, 100);
|
|
973
|
+
if (t.oninput = (e) => {
|
|
974
|
+
e.target.value !== "" && this.clearValueChipHighlight(), a();
|
|
975
|
+
}, t.onkeydown = (e) => {
|
|
976
|
+
switch (e.key) {
|
|
977
|
+
case "ArrowUp":
|
|
978
|
+
case "ArrowDown": return this.clearValueChipHighlight(), e.key === "ArrowDown" ? this.highlight("down") : this.highlight("up"), !1;
|
|
979
|
+
case "ArrowLeft":
|
|
980
|
+
case "ArrowRight": return t.value !== "" || !this.navigateValueChips(e.key === "ArrowLeft" ? "left" : "right") || (e.preventDefault(), !1);
|
|
981
|
+
case "Backspace": return t.value === "" ? this.getHighlightedValueChip() ? !this.deleteValueChip() || (e.preventDefault(), !1) : !this.navigateValueChips("left") || (e.preventDefault(), !1) : !0;
|
|
982
|
+
case "Delete": return t.value !== "" || !this.deleteValueChip() || (e.preventDefault(), !1);
|
|
983
|
+
case "Tab": return this.requestClose("tab"), !0;
|
|
984
|
+
case "Escape": return this.requestClose("escape"), !1;
|
|
985
|
+
case "Enter":
|
|
986
|
+
let r = this.content.list.querySelector("." + this.classes.getFirst("highlighted"));
|
|
987
|
+
return r ? (r.click(), !1) : !this.callbacks.addable || (n.click(), !1);
|
|
988
|
+
}
|
|
989
|
+
return e.key.length === 1 && this.clearValueChipHighlight(), !0;
|
|
990
|
+
}, e.appendChild(t), i) {
|
|
991
|
+
let t = this.createSelectAllControl(() => this.toggleGlobalSelectAll());
|
|
992
|
+
e.appendChild(t), r.selectAll = t;
|
|
993
|
+
}
|
|
994
|
+
if (this.callbacks.addable) {
|
|
995
|
+
this.addClasses(n, this.classes.addable);
|
|
996
|
+
let t = document.createElementNS("http://www.w3.org/2000/svg", "svg");
|
|
997
|
+
t.setAttribute("viewBox", "0 0 100 100");
|
|
998
|
+
let i = document.createElementNS("http://www.w3.org/2000/svg", "path");
|
|
999
|
+
i.setAttribute("d", this.classes.addablePath), t.appendChild(i), n.appendChild(t), n.onclick = (e) => {
|
|
1000
|
+
if (e.preventDefault(), e.stopPropagation(), this.settings.disabled || !this.callbacks.addable) return;
|
|
1001
|
+
let t = this.content.search.input.value.trim();
|
|
1002
|
+
if (t === "") {
|
|
1003
|
+
this.content.search.input.focus();
|
|
1004
|
+
return;
|
|
1005
|
+
}
|
|
1006
|
+
let n = (e) => {
|
|
1007
|
+
let t = new F(e);
|
|
1008
|
+
if (this.callbacks.addOption(t), this.settings.isMultiple) {
|
|
1009
|
+
let e = this.store.getSelected();
|
|
1010
|
+
e.push(t.id), this.callbacks.setSelected(e, !0);
|
|
1011
|
+
} else this.callbacks.setSelected([t.id], !0);
|
|
1012
|
+
if (this.callbacks.clearSearch(), this.settings.closeOnSelect) {
|
|
1013
|
+
let e = u(this.content.main);
|
|
1014
|
+
setTimeout(() => {
|
|
1015
|
+
this.requestClose("select", { selectionChanged: !0 });
|
|
1016
|
+
}, e);
|
|
1017
|
+
}
|
|
1018
|
+
}, r = this.callbacks.addable(t);
|
|
1019
|
+
r !== !1 && r != null && (r instanceof Promise ? r.then((e) => {
|
|
1020
|
+
typeof e == "string" ? n({
|
|
1021
|
+
text: e,
|
|
1022
|
+
value: e
|
|
1023
|
+
}) : r instanceof Error ? this.renderError(r.message) : n(e);
|
|
1024
|
+
}) : typeof r == "string" ? n({
|
|
1025
|
+
text: r,
|
|
1026
|
+
value: r
|
|
1027
|
+
}) : r instanceof Error ? this.renderError(r.message) : n(r));
|
|
1028
|
+
}, e.appendChild(n), r.addable = {
|
|
1029
|
+
main: n,
|
|
1030
|
+
svg: t,
|
|
1031
|
+
path: i
|
|
1032
|
+
};
|
|
1033
|
+
}
|
|
1034
|
+
return r;
|
|
1035
|
+
}
|
|
1036
|
+
searchFocus() {
|
|
1037
|
+
this.content.search.input.focus({ preventScroll: !0 });
|
|
1038
|
+
}
|
|
1039
|
+
getOptions(e = !1, t = !1, n = !1) {
|
|
1040
|
+
let r = "." + this.classes.getFirst("option");
|
|
1041
|
+
return e && (r += ":not(." + this.classes.getFirst("placeholder") + ")"), t && (r += ":not(." + this.classes.getFirst("disabled") + ")"), n && (r += ":not(." + this.classes.getFirst("hide") + ")"), Array.from(this.content.list.querySelectorAll(r));
|
|
1042
|
+
}
|
|
1043
|
+
highlight(e) {
|
|
1044
|
+
let t = this.getOptions(!0, !0, !0);
|
|
1045
|
+
if (t.length === 0) return;
|
|
1046
|
+
if (t.length === 1 && !t[0].classList.contains(this.classes.getFirst("highlighted"))) {
|
|
1047
|
+
this.addClasses(t[0], this.classes.highlighted);
|
|
1048
|
+
return;
|
|
1049
|
+
}
|
|
1050
|
+
let n = !1;
|
|
1051
|
+
for (let e of t) e.classList.contains(this.classes.getFirst("highlighted")) && (n = !0);
|
|
1052
|
+
if (!n) {
|
|
1053
|
+
for (let e of t) if (e.classList.contains(this.classes.getFirst("selected"))) {
|
|
1054
|
+
this.addClasses(e, this.classes.highlighted);
|
|
1055
|
+
break;
|
|
1056
|
+
}
|
|
1057
|
+
}
|
|
1058
|
+
for (let n = 0; n < t.length; n++) if (t[n].classList.contains(this.classes.getFirst("highlighted"))) {
|
|
1059
|
+
let r = t[n];
|
|
1060
|
+
this.removeClasses(r, this.classes.highlighted);
|
|
1061
|
+
let i = r.parentElement;
|
|
1062
|
+
if (i && i.classList.contains(this.classes.getFirst("mainOpen"))) {
|
|
1063
|
+
let e = i.querySelector("." + this.classes.getFirst("optgroupLabel"));
|
|
1064
|
+
e && e.click();
|
|
1065
|
+
}
|
|
1066
|
+
let a = t[e === "down" ? n + 1 < t.length ? n + 1 : 0 : n - 1 >= 0 ? n - 1 : t.length - 1];
|
|
1067
|
+
this.addClasses(a, this.classes.highlighted), this.ensureElementInView(this.content.list, a), a.id && this.main.main.setAttribute("aria-activedescendant", a.id);
|
|
1068
|
+
let o = a.parentElement;
|
|
1069
|
+
if (o && o.classList.contains(this.classes.getFirst("close"))) {
|
|
1070
|
+
let e = o.querySelector("." + this.classes.getFirst("optgroupLabel"));
|
|
1071
|
+
e && e.click();
|
|
1072
|
+
}
|
|
1073
|
+
return;
|
|
1074
|
+
}
|
|
1075
|
+
let r = t[e === "down" ? 0 : t.length - 1];
|
|
1076
|
+
this.addClasses(r, this.classes.highlighted), r.id && this.main.main.setAttribute("aria-activedescendant", r.id), this.ensureElementInView(this.content.list, r);
|
|
1077
|
+
}
|
|
1078
|
+
isTypeaheadKey(e) {
|
|
1079
|
+
return this.settings.showSearch || this.settings.disabled || e.ctrlKey || e.metaKey || e.altKey || e.isComposing ? !1 : e.key.length === 1 && /[\p{L}\p{N}]/u.test(e.key);
|
|
1080
|
+
}
|
|
1081
|
+
typeahead(e) {
|
|
1082
|
+
let t = this.getOptions(!0, !0, !0);
|
|
1083
|
+
if (t.length === 0) return;
|
|
1084
|
+
let n = e.toLowerCase(), r = this.typeaheadQuery.length > 0 && [...this.typeaheadQuery].every((e) => e === n);
|
|
1085
|
+
this.typeaheadTimer !== null && clearTimeout(this.typeaheadTimer), this.typeaheadTimer = setTimeout(() => {
|
|
1086
|
+
this.typeaheadQuery = "", this.typeaheadTimer = null;
|
|
1087
|
+
}, R);
|
|
1088
|
+
let i = this.classes.getFirst("highlighted"), a = this.classes.getFirst("selected"), o = t.findIndex((e) => e.classList.contains(i));
|
|
1089
|
+
o < 0 && (o = t.findIndex((e) => e.classList.contains(a)));
|
|
1090
|
+
let s;
|
|
1091
|
+
r ? (this.typeaheadQuery = n, s = o >= 0 ? (o + 1) % t.length : 0) : (this.typeaheadQuery += n, s = o >= 0 ? o : 0);
|
|
1092
|
+
let c = this.findTypeaheadOption(t, this.typeaheadQuery, s);
|
|
1093
|
+
c && this.highlightOption(c);
|
|
1094
|
+
}
|
|
1095
|
+
findTypeaheadOption(e, t, n) {
|
|
1096
|
+
for (let r = 0; r < e.length; r++) {
|
|
1097
|
+
let i = e[(n + r) % e.length];
|
|
1098
|
+
if ((i.textContent || "").trim().toLowerCase().startsWith(t)) return i;
|
|
1099
|
+
}
|
|
1100
|
+
return null;
|
|
1101
|
+
}
|
|
1102
|
+
highlightOption(e) {
|
|
1103
|
+
let t = this.classes.getFirst("highlighted");
|
|
1104
|
+
this.content.list.querySelectorAll("." + t).forEach((t) => {
|
|
1105
|
+
t !== e && this.removeClasses(t, this.classes.highlighted);
|
|
1106
|
+
}), this.addClasses(e, this.classes.highlighted), e.id && this.main.main.setAttribute("aria-activedescendant", e.id);
|
|
1107
|
+
let n = e.parentElement;
|
|
1108
|
+
n && n.classList.contains(this.classes.getFirst("close")) && n.querySelector("." + this.classes.getFirst("optgroupLabel"))?.click(), this.ensureElementInView(this.content.list, e);
|
|
1109
|
+
}
|
|
1110
|
+
clearTypeahead() {
|
|
1111
|
+
this.typeaheadQuery = "", this.typeaheadTimer !== null && (clearTimeout(this.typeaheadTimer), this.typeaheadTimer = null);
|
|
1112
|
+
}
|
|
1113
|
+
listDiv() {
|
|
1114
|
+
let e = document.createElement("div");
|
|
1115
|
+
this.addClasses(e, this.classes.list);
|
|
1116
|
+
let t = this.settings.id + "-list";
|
|
1117
|
+
return e.id = t, e.dataset.id = t, e;
|
|
1118
|
+
}
|
|
1119
|
+
renderError(e) {
|
|
1120
|
+
this.optionsListIsFullData = !1, this.content.list.innerHTML = "";
|
|
1121
|
+
let t = document.createElement("div");
|
|
1122
|
+
this.addClasses(t, this.classes.error), t.textContent = e, this.content.list.appendChild(t), this.repositionOpenContent();
|
|
1123
|
+
}
|
|
1124
|
+
renderSearching() {
|
|
1125
|
+
this.optionsListIsFullData = !1, this.content.list.innerHTML = "";
|
|
1126
|
+
let e = document.createElement("div");
|
|
1127
|
+
this.addClasses(e, this.classes.searching), e.textContent = this.settings.searchingText, this.content.list.appendChild(e), this.announce(this.settings.searchingText), this.repositionOpenContent();
|
|
1128
|
+
}
|
|
1129
|
+
renderOptions(e) {
|
|
1130
|
+
this.lastSearchFilterTerm = "";
|
|
1131
|
+
let t = e.map((e) => e instanceof F ? [e] : e.options.map((e) => new F(e))).flat();
|
|
1132
|
+
if (this.lastRenderedOptions = t.filter((e) => !e.placeholder), this.content.list.innerHTML = "", this.lastRenderedOptions.length === 0) {
|
|
1133
|
+
this.optionsListIsFullData = !1;
|
|
1134
|
+
let e = document.createElement("div");
|
|
1135
|
+
if (this.addClasses(e, this.classes.search), this.callbacks.addable) {
|
|
1136
|
+
let t = this.settings.addableText.replace("{value}", this.content.search.input.value);
|
|
1137
|
+
e.innerHTML = t, this.announce(t);
|
|
1138
|
+
} else e.innerHTML = this.settings.searchText, this.announce(this.settings.searchText);
|
|
1139
|
+
this.content.list.appendChild(e), this.repositionOpenContent();
|
|
1140
|
+
return;
|
|
1141
|
+
}
|
|
1142
|
+
this.settings.allowDeselect && !this.settings.isMultiple && (this.store.filter((e) => e.placeholder, !1, !1).length || this.store.addOption(new F({
|
|
1143
|
+
text: "",
|
|
1144
|
+
value: "",
|
|
1145
|
+
selected: !1,
|
|
1146
|
+
placeholder: !0
|
|
1147
|
+
}), !0));
|
|
1148
|
+
let n = document.createDocumentFragment();
|
|
1149
|
+
for (let t of e) {
|
|
1150
|
+
if (t instanceof I) {
|
|
1151
|
+
let e = document.createElement("div");
|
|
1152
|
+
this.addClasses(e, this.classes.optgroup);
|
|
1153
|
+
let r = document.createElement("div");
|
|
1154
|
+
this.addClasses(r, this.classes.optgroupLabel), e.appendChild(r);
|
|
1155
|
+
let i = document.createElement("div");
|
|
1156
|
+
this.addClasses(i, this.classes.optgroupLabelText), i.textContent = t.label, r.appendChild(i);
|
|
1157
|
+
let a = document.createElement("div");
|
|
1158
|
+
if (this.addClasses(a, this.classes.optgroupActions), r.appendChild(a), this.settings.isMultiple && t.selectAll) {
|
|
1159
|
+
let e = this.createSelectAllControl(() => {
|
|
1160
|
+
let e = this.store.getSelected();
|
|
1161
|
+
if (this.isOptgroupAllSelected(t.options, new Set(e))) {
|
|
1162
|
+
let n = e.filter((e) => {
|
|
1163
|
+
for (let n of t.options) if (e === n.id) return !1;
|
|
1164
|
+
return !0;
|
|
1165
|
+
});
|
|
1166
|
+
this.callbacks.setSelected(n, !0);
|
|
1167
|
+
} else {
|
|
1168
|
+
let n = t.options.map((e) => e.id).filter((e) => e !== void 0), r = e.concat(n);
|
|
1169
|
+
for (let e of t.options) e.id && !this.store.getOptionByID(e.id) && this.callbacks.addOption(new F(e));
|
|
1170
|
+
this.callbacks.setSelected(r, !0);
|
|
1171
|
+
return;
|
|
1172
|
+
}
|
|
1173
|
+
}, this.isOptgroupAllSelected(t.options));
|
|
1174
|
+
a.appendChild(e);
|
|
1175
|
+
}
|
|
1176
|
+
if (t.closable !== "off") {
|
|
1177
|
+
let n = document.createElement("div");
|
|
1178
|
+
this.addClasses(n, this.classes.optgroupClosable);
|
|
1179
|
+
let i = document.createElementNS("http://www.w3.org/2000/svg", "svg");
|
|
1180
|
+
i.setAttribute("viewBox", "0 0 100 100"), this.addClasses(i, this.classes.arrow), n.appendChild(i);
|
|
1181
|
+
let o = document.createElementNS("http://www.w3.org/2000/svg", "path");
|
|
1182
|
+
i.appendChild(o), t.options.some((e) => e.selected) || this.content.search.input.value.trim() !== "" ? (this.addClasses(n, this.classes.mainOpen), o.setAttribute("d", this.classes.arrowOpen)) : t.closable === "open" ? (this.addClasses(e, this.classes.mainOpen), o.setAttribute("d", this.classes.arrowOpen)) : t.closable === "close" && (this.addClasses(e, this.classes.close), o.setAttribute("d", this.classes.arrowClose)), r.addEventListener("click", (t) => {
|
|
1183
|
+
t.preventDefault(), t.stopPropagation(), this.isClosableOptgroupOpen(e, n) ? (this.removeClasses(e, this.classes.mainOpen), this.removeClasses(n, this.classes.mainOpen), this.addClasses(e, this.classes.close), o.setAttribute("d", this.classes.arrowClose)) : (this.closeOtherClosableOptgroups(e), this.removeClasses(e, this.classes.close), this.removeClasses(n, this.classes.mainOpen), this.addClasses(e, this.classes.mainOpen), o.setAttribute("d", this.classes.arrowOpen)), this.repositionOpenContent();
|
|
1184
|
+
}), a.appendChild(n);
|
|
1185
|
+
}
|
|
1186
|
+
e.appendChild(r);
|
|
1187
|
+
for (let r of t.options) e.appendChild(this.option(new F(r))), n.appendChild(e);
|
|
1188
|
+
}
|
|
1189
|
+
t instanceof F && n.appendChild(this.option(t));
|
|
1190
|
+
}
|
|
1191
|
+
this.content.list.appendChild(n), this.setOptionsListFullData(e), this.announce(this.settings.resultsText.replace("{count}", String(this.lastRenderedOptions.length))), this.updateGlobalSelectAllState(), this.repositionOpenContent();
|
|
1192
|
+
}
|
|
1193
|
+
canFilterOptionsInPlace() {
|
|
1194
|
+
return this.optionsListIsFullData ? this.content.list.querySelector("." + this.classes.getFirst("option")) !== null : !1;
|
|
1195
|
+
}
|
|
1196
|
+
resetSearchFilterState() {
|
|
1197
|
+
this.lastSearchFilterTerm = "";
|
|
1198
|
+
}
|
|
1199
|
+
filterOptionsInPlace(e, t) {
|
|
1200
|
+
let n = e.trim();
|
|
1201
|
+
if (n === this.lastSearchFilterTerm) return;
|
|
1202
|
+
this.lastSearchFilterTerm = n;
|
|
1203
|
+
let r = [], i = this.content.list.querySelectorAll("." + this.classes.getFirst("option"));
|
|
1204
|
+
for (let e of i) {
|
|
1205
|
+
let i = e.dataset.id;
|
|
1206
|
+
if (!i) continue;
|
|
1207
|
+
let a = this.store.getOptionByID(i);
|
|
1208
|
+
if (!a) continue;
|
|
1209
|
+
let o = a.placeholder || !a.display || a.selected && this.settings.hideSelected, s = t(a, n);
|
|
1210
|
+
o || !s ? (this.addClasses(e, this.classes.hide), this.removeClasses(e, this.classes.highlighted)) : (this.removeClasses(e, this.classes.hide), this.setOptionElementContent(e, a, n), r.push(a)), a.selected ? (this.addClasses(e, this.classes.selected), e.setAttribute("aria-selected", "true")) : (this.removeClasses(e, this.classes.selected), e.setAttribute("aria-selected", "false"));
|
|
1211
|
+
}
|
|
1212
|
+
this.lastRenderedOptions = r, this.updateOptgroupVisibilityAfterSearch(n), r.length === 0 ? this.updateSearchResultsMessage(0, n) : (this.removeListSearchMessage(), this.announce(this.settings.resultsText.replace("{count}", String(r.length)))), this.updateOptgroupSelectAllStates(), this.updateGlobalSelectAllState(), this.repositionOpenContent();
|
|
1213
|
+
}
|
|
1214
|
+
setOptionsListFullData(e) {
|
|
1215
|
+
let t = this.store.getDataOptions(!1), n = e.map((e) => e instanceof F ? [e] : e.options.map((e) => new F(e))).flat();
|
|
1216
|
+
if (n.length !== t.length) {
|
|
1217
|
+
this.optionsListIsFullData = !1;
|
|
1218
|
+
return;
|
|
1219
|
+
}
|
|
1220
|
+
let r = new Set(t.map((e) => e.id));
|
|
1221
|
+
this.optionsListIsFullData = n.every((e) => r.has(e.id));
|
|
1222
|
+
}
|
|
1223
|
+
isClosableOptgroupOpen(e, t) {
|
|
1224
|
+
return e.classList.contains(this.classes.getFirst("close")) ? !1 : e.classList.contains(this.classes.getFirst("mainOpen")) || t.classList.contains(this.classes.getFirst("mainOpen"));
|
|
1225
|
+
}
|
|
1226
|
+
closeClosableOptgroup(e) {
|
|
1227
|
+
let t = e.querySelector("." + this.classes.getFirst("optgroupClosable"));
|
|
1228
|
+
if (!t || e.classList.contains(this.classes.getFirst("close"))) return;
|
|
1229
|
+
this.removeClasses(e, this.classes.mainOpen), this.removeClasses(t, this.classes.mainOpen), this.addClasses(e, this.classes.close);
|
|
1230
|
+
let n = t.querySelector("path");
|
|
1231
|
+
n && n.setAttribute("d", this.classes.arrowClose);
|
|
1232
|
+
}
|
|
1233
|
+
closeOtherClosableOptgroups(e) {
|
|
1234
|
+
let t = this.content.list.querySelectorAll("." + this.classes.getFirst("optgroup"));
|
|
1235
|
+
for (let n of t) n !== e && this.closeClosableOptgroup(n);
|
|
1236
|
+
}
|
|
1237
|
+
updateOptgroupVisibilityAfterSearch(e) {
|
|
1238
|
+
let t = this.content.list.querySelectorAll("." + this.classes.getFirst("optgroup"));
|
|
1239
|
+
for (let n of t) {
|
|
1240
|
+
let t = n.querySelectorAll("." + this.classes.getFirst("option")), r = !1;
|
|
1241
|
+
for (let e of t) if (!e.classList.contains(this.classes.getFirst("hide"))) {
|
|
1242
|
+
r = !0;
|
|
1243
|
+
break;
|
|
1244
|
+
}
|
|
1245
|
+
r ? (this.removeClasses(n, this.classes.hide), e !== "" && (this.removeClasses(n, this.classes.close), this.addClasses(n, this.classes.mainOpen))) : this.addClasses(n, this.classes.hide);
|
|
1246
|
+
}
|
|
1247
|
+
}
|
|
1248
|
+
updateSearchResultsMessage(e, t) {
|
|
1249
|
+
if (this.removeListSearchMessage(), e > 0) return;
|
|
1250
|
+
let n = document.createElement("div");
|
|
1251
|
+
if (this.addClasses(n, this.classes.search), this.callbacks.addable) {
|
|
1252
|
+
let e = this.settings.addableText.replace("{value}", t);
|
|
1253
|
+
n.innerHTML = e, this.announce(e);
|
|
1254
|
+
} else n.innerHTML = this.settings.searchText, this.announce(this.settings.searchText);
|
|
1255
|
+
this.content.list.appendChild(n);
|
|
1256
|
+
}
|
|
1257
|
+
removeListSearchMessage() {
|
|
1258
|
+
this.content.list.querySelectorAll("." + this.classes.getFirst("search")).forEach((e) => e.remove());
|
|
1259
|
+
}
|
|
1260
|
+
setOptionElementContent(e, t, n) {
|
|
1261
|
+
let r = n.trim();
|
|
1262
|
+
this.settings.searchHighlight && r !== "" ? e.innerHTML = this.highlightText(t.html === "" ? t.text : t.html, r, this.classes.searchHighlighter) : t.html === "" ? e.textContent = t.text : e.innerHTML = t.html, this.settings.showOptionTooltips && e.textContent ? e.setAttribute("title", e.textContent) : e.removeAttribute("title");
|
|
1263
|
+
}
|
|
1264
|
+
hasRenderedOptions() {
|
|
1265
|
+
return this.content.list.querySelector("." + this.classes.getFirst("option")) !== null;
|
|
1266
|
+
}
|
|
1267
|
+
canUpdateOptionSelectionInPlace() {
|
|
1268
|
+
return this.content.search.input.value.trim() === "" && this.hasRenderedOptions();
|
|
1269
|
+
}
|
|
1270
|
+
updateOptionSelection() {
|
|
1271
|
+
let e = new Set(this.store.getSelected()), t = this.content.list.querySelectorAll("." + this.classes.getFirst("option")), n = null;
|
|
1272
|
+
for (let r of t) {
|
|
1273
|
+
let t = r.dataset.id;
|
|
1274
|
+
if (!t) continue;
|
|
1275
|
+
let i = this.store.getOptionByID(t);
|
|
1276
|
+
if (!i) continue;
|
|
1277
|
+
let a = e.has(t);
|
|
1278
|
+
a ? (this.addClasses(r, this.classes.selected), r.setAttribute("aria-selected", "true"), n = r) : (this.removeClasses(r, this.classes.selected), r.setAttribute("aria-selected", "false")), this.settings.hideSelected && (a ? this.addClasses(r, this.classes.hide) : (this.removeClasses(r, this.classes.hide), i.display || this.addClasses(r, this.classes.hide)));
|
|
1279
|
+
}
|
|
1280
|
+
!this.settings.isMultiple && n ? this.main.main.setAttribute("aria-activedescendant", n.id) : !this.settings.isMultiple && e.size === 0 && this.main.main.removeAttribute("aria-activedescendant"), this.updateOptgroupSelectAllStates(), this.updateGlobalSelectAllState(), this.repositionOpenContent();
|
|
1281
|
+
}
|
|
1282
|
+
createSelectAllControl(e, t = !1) {
|
|
1283
|
+
let n = document.createElement("div");
|
|
1284
|
+
this.addClasses(n, this.classes.optgroupSelectAll), n.setAttribute("role", "checkbox"), n.setAttribute("aria-checked", t ? "true" : "false"), n.setAttribute("aria-label", this.selectAllLabel(t)), n.tabIndex = -1, t && this.addClasses(n, this.classes.selected);
|
|
1285
|
+
let r = document.createElement("span");
|
|
1286
|
+
r.textContent = this.selectAllLabel(t), n.appendChild(r);
|
|
1287
|
+
let i = document.createElementNS("http://www.w3.org/2000/svg", "svg");
|
|
1288
|
+
i.setAttribute("viewBox", "0 0 100 100"), i.setAttribute("aria-hidden", "true"), n.appendChild(i);
|
|
1289
|
+
let a = document.createElementNS("http://www.w3.org/2000/svg", "path");
|
|
1290
|
+
a.setAttribute("d", this.classes.optgroupSelectAllBox), i.appendChild(a);
|
|
1291
|
+
let o = document.createElementNS("http://www.w3.org/2000/svg", "path");
|
|
1292
|
+
return o.setAttribute("d", this.classes.optgroupSelectAllCheck), i.appendChild(o), n.addEventListener("click", (t) => {
|
|
1293
|
+
t.preventDefault(), t.stopPropagation(), this.settings.disabled || e();
|
|
1294
|
+
}), n;
|
|
1295
|
+
}
|
|
1296
|
+
getSelectableOptions() {
|
|
1297
|
+
return this.store.getDataOptions(!1).filter((e) => !e.disabled && !e.placeholder && e.display);
|
|
1298
|
+
}
|
|
1299
|
+
isGlobalAllSelected(e) {
|
|
1300
|
+
let t = this.getSelectableOptions();
|
|
1301
|
+
if (t.length === 0) return !1;
|
|
1302
|
+
let n = e || new Set(this.store.getSelected());
|
|
1303
|
+
for (let e of t) if (!n.has(e.id)) return !1;
|
|
1304
|
+
return !0;
|
|
1305
|
+
}
|
|
1306
|
+
toggleGlobalSelectAll() {
|
|
1307
|
+
let e = this.getSelectableOptions(), t = new Set(this.store.getSelected());
|
|
1308
|
+
if (this.isGlobalAllSelected(t)) {
|
|
1309
|
+
let t = new Set(e.map((e) => e.id)), n = this.store.getSelected().filter((e) => !t.has(e));
|
|
1310
|
+
this.callbacks.setSelected(n, !0);
|
|
1311
|
+
} else this.callbacks.setSelected(e.map((e) => e.id), !0);
|
|
1312
|
+
}
|
|
1313
|
+
updateGlobalSelectAllState() {
|
|
1314
|
+
let e = this.content.search.selectAll;
|
|
1315
|
+
if (!e || !this.settings.isMultiple || !this.settings.selectAll) return;
|
|
1316
|
+
let t = this.isGlobalAllSelected();
|
|
1317
|
+
t ? this.addClasses(e, this.classes.selected) : this.removeClasses(e, this.classes.selected), e.setAttribute("aria-checked", t ? "true" : "false"), e.setAttribute("aria-label", this.selectAllLabel(t));
|
|
1318
|
+
let n = e.querySelector("span");
|
|
1319
|
+
n && (n.textContent = this.selectAllLabel(t));
|
|
1320
|
+
}
|
|
1321
|
+
updateOptgroupSelectAllStates() {
|
|
1322
|
+
if (!this.settings.isMultiple) return;
|
|
1323
|
+
let e = new Set(this.store.getSelected()), t = this.content.list.querySelectorAll("." + this.classes.getFirst("optgroup"));
|
|
1324
|
+
for (let n of t) {
|
|
1325
|
+
let t = n.querySelector("." + this.classes.getFirst("optgroupSelectAll"));
|
|
1326
|
+
if (!t) continue;
|
|
1327
|
+
let r = n.querySelectorAll("." + this.classes.getFirst("option")), i = r.length > 0;
|
|
1328
|
+
for (let t of r) {
|
|
1329
|
+
let n = t.dataset.id;
|
|
1330
|
+
if (!n || !e.has(n)) {
|
|
1331
|
+
i = !1;
|
|
1332
|
+
break;
|
|
1333
|
+
}
|
|
1334
|
+
}
|
|
1335
|
+
i ? this.addClasses(t, this.classes.selected) : this.removeClasses(t, this.classes.selected), t.setAttribute("aria-checked", i ? "true" : "false"), t.setAttribute("aria-label", this.selectAllLabel(i));
|
|
1336
|
+
let a = t.querySelector("span");
|
|
1337
|
+
a && (a.textContent = this.selectAllLabel(i));
|
|
1338
|
+
}
|
|
1339
|
+
}
|
|
1340
|
+
selectAllLabel(e) {
|
|
1341
|
+
return e ? this.settings.unselectAllText : this.settings.selectAllText;
|
|
1342
|
+
}
|
|
1343
|
+
isOptgroupAllSelected(e, t) {
|
|
1344
|
+
if (e.length === 0) return !1;
|
|
1345
|
+
for (let n of e) if (!(t ? n.id && t.has(n.id) : n.selected)) return !1;
|
|
1346
|
+
return !0;
|
|
1347
|
+
}
|
|
1348
|
+
option(e) {
|
|
1349
|
+
if (e.placeholder) {
|
|
1350
|
+
let e = document.createElement("div");
|
|
1351
|
+
return this.addClasses(e, this.classes.option), this.addClasses(e, this.classes.hide), e;
|
|
1352
|
+
}
|
|
1353
|
+
let t = document.createElement("div");
|
|
1354
|
+
return t.dataset.id = e.id, t.id = this.settings.id + "-" + e.id, this.addClasses(t, this.classes.option), t.setAttribute("role", "option"), e.class && e.class.split(" ").forEach((e) => {
|
|
1355
|
+
t.classList.add(e);
|
|
1356
|
+
}), e.style && (t.style.cssText = e.style), this.setOptionElementContent(t, e, this.content.search.input.value), e.display || this.addClasses(t, this.classes.hide), e.disabled && this.addClasses(t, this.classes.disabled), e.selected && this.settings.hideSelected && this.addClasses(t, this.classes.hide), e.selected ? (this.addClasses(t, this.classes.selected), t.setAttribute("aria-selected", "true"), this.main.main.setAttribute("aria-activedescendant", t.id)) : (this.removeClasses(t, this.classes.selected), t.setAttribute("aria-selected", "false")), t.addEventListener("click", (t) => {
|
|
1357
|
+
t.preventDefault(), t.stopPropagation();
|
|
1358
|
+
let n = this.store.getSelected(), r = t.currentTarget, i = String(r.dataset.id), a = this.store.getOptionByID(i) ?? e, o = n.includes(i), s = t.ctrlKey || t.metaKey;
|
|
1359
|
+
if (this.settings.disabled || e.disabled) return;
|
|
1360
|
+
if (!this.settings.isMultiple && o && !this.settings.allowDeselect || o && a.mandatory) {
|
|
1361
|
+
this.closeOnSingleSelectReclick(a);
|
|
1362
|
+
return;
|
|
1363
|
+
}
|
|
1364
|
+
if (this.settings.isMultiple && this.settings.maxSelected <= n.length && !o || this.settings.isMultiple && this.settings.minSelected >= n.length && o && !s) return;
|
|
1365
|
+
let c = !1, l = this.store.getSelectedOptions(), u = [];
|
|
1366
|
+
if (this.settings.isMultiple) {
|
|
1367
|
+
let n = l.some((e) => e.id === i);
|
|
1368
|
+
if (t.shiftKey && this.lastSelectedOption) {
|
|
1369
|
+
let t = this.lastRenderedOptions, n = t.findIndex((e) => e.id === this.lastSelectedOption.id), r = t.findIndex((t) => t.id === e.id);
|
|
1370
|
+
if (n >= 0 && r >= 0) {
|
|
1371
|
+
let e = Math.min(n, r), i = Math.max(n, r), a = t.slice(e, i + 1).filter((e) => !l.find((t) => t.id === e.id));
|
|
1372
|
+
u = l.length + a.length <= this.settings.maxSelected ? l.concat(a) : l;
|
|
1373
|
+
} else u = l;
|
|
1374
|
+
} else u = n ? l.filter((e) => e.id !== i) : l.concat(a), this.lastSelectedOption = a;
|
|
1375
|
+
}
|
|
1376
|
+
if (this.settings.isMultiple || (u = o ? [] : [a]), this.callbacks.beforeChange || (c = !0), this.callbacks.beforeChange && (c = this.callbacks.beforeChange(u, l) !== !1), c) {
|
|
1377
|
+
this.store.getOptionByID(i) || this.callbacks.addOption(e), this.callbacks.setSelected(u.map((e) => e.id), !1);
|
|
1378
|
+
let n = t.ctrlKey || t.metaKey || t.shiftKey;
|
|
1379
|
+
this.settings.closeOnSelect && !(this.settings.isMultiple && n) && this.requestClose("select", {
|
|
1380
|
+
option: a,
|
|
1381
|
+
selectionChanged: this.selectionChanged(l, u)
|
|
1382
|
+
}), this.callbacks.afterChange && this.callbacks.afterChange(u);
|
|
1383
|
+
}
|
|
1384
|
+
}), t;
|
|
1385
|
+
}
|
|
1386
|
+
destroy() {
|
|
1387
|
+
this.clearTypeahead(), this.stopPositionTracking(), this.modalElements ? (this.unlockBodyScroll(), this.content.main.parentElement === this.modalElements.dialog && this.restoreContentOffscreen(), this.modalElements.overlay.remove(), this.modalElements = null) : this.bodyScrollLocked && this.unlockBodyScroll(), this.main.main.remove(), this.content.main.remove(), this.removeDetachedInstanceDom();
|
|
1388
|
+
}
|
|
1389
|
+
removeDetachedInstanceDom() {
|
|
1390
|
+
let e = this.settings.id, t = this.classes.getFirst("main"), n = this.classes.getFirst("content"), r = this.classes.getFirst("modalOverlay");
|
|
1391
|
+
document.querySelectorAll(`[data-id="${e}"]`).forEach((e) => {
|
|
1392
|
+
(e.classList.contains(t) || e.classList.contains(n) || e.classList.contains(r)) && e.remove();
|
|
1393
|
+
});
|
|
1394
|
+
}
|
|
1395
|
+
highlightText(e, t, n) {
|
|
1396
|
+
let r = t.trim();
|
|
1397
|
+
if (r === "") return e;
|
|
1398
|
+
let i = r.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"), a = document.createElement("div");
|
|
1399
|
+
a.innerHTML = e;
|
|
1400
|
+
let o = (e) => {
|
|
1401
|
+
if (e.nodeType === Node.TEXT_NODE) {
|
|
1402
|
+
let t = e.textContent || "", r = RegExp("(" + i + ")", "i");
|
|
1403
|
+
if (r.test(t)) {
|
|
1404
|
+
let i = document.createElement("span");
|
|
1405
|
+
t.split(r).forEach((e, t) => {
|
|
1406
|
+
if (e && r.test(e)) {
|
|
1407
|
+
let t = document.createElement("mark");
|
|
1408
|
+
t.className = n, t.textContent = e, i.appendChild(t);
|
|
1409
|
+
} else e && i.appendChild(document.createTextNode(e));
|
|
1410
|
+
}), e.parentNode?.replaceChild(i, e);
|
|
1411
|
+
}
|
|
1412
|
+
} else e.nodeType === Node.ELEMENT_NODE && Array.from(e.childNodes).forEach((e) => o(e));
|
|
1413
|
+
};
|
|
1414
|
+
return Array.from(a.childNodes).forEach((e) => o(e)), a.innerHTML;
|
|
1415
|
+
}
|
|
1416
|
+
setContentDirection(e) {
|
|
1417
|
+
let t = e === "above", n = t ? this.classes.dirAbove : this.classes.dirBelow, r = t ? this.classes.dirBelow : this.classes.dirAbove;
|
|
1418
|
+
if (this.removeClasses(this.main.main, r), this.addClasses(this.main.main, n), this.removeClasses(this.content.main, r), this.addClasses(this.content.main, n), t) {
|
|
1419
|
+
let e = this.main.main.offsetHeight, t = this.content.main.offsetHeight;
|
|
1420
|
+
this.content.main.style.margin = "-" + (e + t - 1) + "px 0px 0px 0px";
|
|
1421
|
+
} else this.content.main.style.margin = "-1px 0px 0px 0px";
|
|
1422
|
+
}
|
|
1423
|
+
setContentPosition() {
|
|
1424
|
+
let e = this.main.main.getBoundingClientRect();
|
|
1425
|
+
if (this.settings.contentPosition === "relative") {
|
|
1426
|
+
this.applyContentWidth(e);
|
|
1427
|
+
return;
|
|
1428
|
+
}
|
|
1429
|
+
this.cancelOverflowShift();
|
|
1430
|
+
let t, n;
|
|
1431
|
+
this.settings.contentPosition === "fixed" ? (t = e.top + e.height, n = e.left) : (t = e.top + window.scrollY + e.height, n = e.left + window.scrollX), this.content.main.style.top = t + "px", this.content.main.style.left = n + "px", this.applyContentWidth(e);
|
|
1432
|
+
let r = this.getKnownContentWidth(e);
|
|
1433
|
+
r === null ? this.overflowShiftRaf = requestAnimationFrame(() => {
|
|
1434
|
+
this.overflowShiftRaf = 0, this.applyOverflowShiftFromMeasure();
|
|
1435
|
+
}) : this.content.main.style.left = this.adjustLeftForOverflow(n, e.left, r) + "px";
|
|
1436
|
+
}
|
|
1437
|
+
applyContentWidth(e) {
|
|
1438
|
+
let t = this.settings.contentWidth;
|
|
1439
|
+
this.content.main.style.width = "", this.content.main.style.minWidth = "", this.content.main.style.maxWidth = "", t ? t === "auto" ? this.content.main.style.minWidth = e.width + "px" : t.startsWith(">") ? this.content.main.style.minWidth = t.slice(1) : t.startsWith("<") ? this.content.main.style.maxWidth = t.slice(1) : this.content.main.style.width = t : this.settings.contentPosition !== "relative" && (this.content.main.style.width = e.width + "px");
|
|
1440
|
+
}
|
|
1441
|
+
cancelOverflowShift() {
|
|
1442
|
+
this.overflowShiftRaf &&= (cancelAnimationFrame(this.overflowShiftRaf), 0);
|
|
1443
|
+
}
|
|
1444
|
+
getKnownContentWidth(e) {
|
|
1445
|
+
let t = this.settings.contentWidth;
|
|
1446
|
+
if (!t) return e.width;
|
|
1447
|
+
if (t.startsWith(">") || t.startsWith("<") || t.includes("%")) return null;
|
|
1448
|
+
let n = parseFloat(t);
|
|
1449
|
+
return Number.isNaN(n) ? null : n;
|
|
1450
|
+
}
|
|
1451
|
+
adjustLeftForOverflow(e, t, n) {
|
|
1452
|
+
let r = t + n;
|
|
1453
|
+
if (r <= window.innerWidth) return e;
|
|
1454
|
+
let i = e - (r - (window.innerWidth - 20));
|
|
1455
|
+
return this.settings.contentPosition === "fixed" ? Math.max(0, i) : Math.max(window.scrollX, i);
|
|
1456
|
+
}
|
|
1457
|
+
applyOverflowShiftFromMeasure() {
|
|
1458
|
+
let e = this.content.main.getBoundingClientRect().right;
|
|
1459
|
+
if (e <= window.innerWidth) return;
|
|
1460
|
+
let t = e - (window.innerWidth - 20), n = (parseFloat(this.content.main.style.left) || 0) - t;
|
|
1461
|
+
this.settings.contentPosition === "fixed" ? this.content.main.style.left = Math.max(0, n) + "px" : this.content.main.style.left = Math.max(window.scrollX, n) + "px";
|
|
1462
|
+
}
|
|
1463
|
+
moveContentAbove() {
|
|
1464
|
+
this.setContentDirection("above"), this.setContentPosition();
|
|
1465
|
+
}
|
|
1466
|
+
moveContentBelow() {
|
|
1467
|
+
this.setContentDirection("below"), this.setContentPosition();
|
|
1468
|
+
}
|
|
1469
|
+
ensureElementInView(e, t) {
|
|
1470
|
+
let n = e.scrollTop + e.offsetTop, r = n + e.clientHeight, i = t.offsetTop, a = i + t.clientHeight;
|
|
1471
|
+
i < n ? e.scrollTop -= n - i : a > r && (e.scrollTop += a - r);
|
|
1472
|
+
}
|
|
1473
|
+
putContent() {
|
|
1474
|
+
let e = this.main.main.offsetHeight, t = this.main.main.getBoundingClientRect(), n = this.content.main.offsetHeight;
|
|
1475
|
+
return window.innerHeight - (t.top + e) <= n && t.top > n ? "up" : "down";
|
|
1476
|
+
}
|
|
1477
|
+
updateDeselectAll() {
|
|
1478
|
+
if (!this.store || !this.settings) return;
|
|
1479
|
+
let e = this.store.getSelectedOptions(), t = e && e.length > 0, n = this.settings.isMultiple, r = this.settings.allowDeselect, i = this.isAtMinSelected(), a = this.main.deselect.main, o = this.classes.hide;
|
|
1480
|
+
r && (!n || t) && !i ? this.removeClasses(a, o) : this.addClasses(a, o);
|
|
1481
|
+
}
|
|
1482
|
+
};
|
|
1483
|
+
// src/slim-select/mutations.ts
|
|
1484
|
+
function B(e, t) {
|
|
1485
|
+
let n = {
|
|
1486
|
+
classChanged: !1,
|
|
1487
|
+
titleChanged: !1,
|
|
1488
|
+
disabledChanged: !1,
|
|
1489
|
+
optgroupOptionChanged: !1,
|
|
1490
|
+
selectionChanged: !1
|
|
1491
|
+
};
|
|
1492
|
+
for (let r of e) {
|
|
1493
|
+
if (r.target === t && (r.attributeName === "disabled" && (n.disabledChanged = !0), r.attributeName === "class" && (n.classChanged = !0), r.attributeName === "title" && (n.titleChanged = !0), r.type === "childList")) {
|
|
1494
|
+
for (let e of Array.from(r.addedNodes)) if (e.nodeName === "OPTION" && e.value === t.value) {
|
|
1495
|
+
n.selectionChanged = !0;
|
|
1496
|
+
break;
|
|
1497
|
+
}
|
|
1498
|
+
n.optgroupOptionChanged = !0;
|
|
1499
|
+
}
|
|
1500
|
+
(r.target.nodeName === "OPTGROUP" || r.target.nodeName === "OPTION") && (n.optgroupOptionChanged = !0);
|
|
1501
|
+
}
|
|
1502
|
+
return n;
|
|
1503
|
+
}
|
|
1504
|
+
// src/slim-select/select.ts
|
|
1505
|
+
var V = class {
|
|
1506
|
+
select;
|
|
1507
|
+
onValueChange;
|
|
1508
|
+
onClassChange;
|
|
1509
|
+
onTitleChange;
|
|
1510
|
+
onDisabledChange;
|
|
1511
|
+
onOptionsChange;
|
|
1512
|
+
onLabelClick;
|
|
1513
|
+
listen = !1;
|
|
1514
|
+
observer = null;
|
|
1515
|
+
isUpdating = !1;
|
|
1516
|
+
pendingOptionsChange = null;
|
|
1517
|
+
preventNativeSelect = null;
|
|
1518
|
+
preventNativeSelectMousedown = null;
|
|
1519
|
+
preventNativeSelectFocus = null;
|
|
1520
|
+
restoreAriaHiddenOnBlur = null;
|
|
1521
|
+
constructor(e) {
|
|
1522
|
+
this.select = e, this.valueChange = this.valueChange.bind(this), this.select.addEventListener("change", this.valueChange, { passive: !0 }), this.observer = new MutationObserver(this.observeCall.bind(this)), this.changeListen(!0);
|
|
1523
|
+
}
|
|
1524
|
+
enable() {
|
|
1525
|
+
this.select.disabled = !1;
|
|
1526
|
+
}
|
|
1527
|
+
disable() {
|
|
1528
|
+
this.select.disabled = !0;
|
|
1529
|
+
}
|
|
1530
|
+
hideUI() {
|
|
1531
|
+
this.select.tabIndex = -1, this.select.style.position = "absolute", this.select.style.width = "1px", this.select.style.height = "1px", this.select.style.opacity = "0", this.select.style.overflow = "hidden", this.select.style.pointerEvents = "none", this.select.style.margin = "0", this.select.style.padding = "0", this.select.style.borderWidth = "0", this.select.style.clipPath = "inset(50%)", document.activeElement !== this.select && this.select.setAttribute("aria-hidden", "true"), this.preventNativeSelect || (this.preventNativeSelect = (e) => {
|
|
1532
|
+
e.preventDefault(), e.stopPropagation(), e.stopImmediatePropagation();
|
|
1533
|
+
}, this.preventNativeSelectMousedown = (e) => {
|
|
1534
|
+
e.preventDefault(), e.stopPropagation(), e.stopImmediatePropagation();
|
|
1535
|
+
}, this.preventNativeSelectFocus = (e) => {
|
|
1536
|
+
this.select.removeAttribute("aria-hidden"), e.preventDefault(), e.stopPropagation(), e.stopImmediatePropagation();
|
|
1537
|
+
}, this.restoreAriaHiddenOnBlur = () => {
|
|
1538
|
+
this.select.setAttribute("aria-hidden", "true");
|
|
1539
|
+
}, this.select.addEventListener("click", this.preventNativeSelect, {
|
|
1540
|
+
capture: !0,
|
|
1541
|
+
passive: !1
|
|
1542
|
+
}), this.select.addEventListener("mousedown", this.preventNativeSelectMousedown, {
|
|
1543
|
+
capture: !0,
|
|
1544
|
+
passive: !1
|
|
1545
|
+
}), this.select.addEventListener("focus", this.preventNativeSelectFocus, {
|
|
1546
|
+
capture: !0,
|
|
1547
|
+
passive: !1
|
|
1548
|
+
}), this.select.addEventListener("blur", this.restoreAriaHiddenOnBlur, {
|
|
1549
|
+
capture: !0,
|
|
1550
|
+
passive: !0
|
|
1551
|
+
}));
|
|
1552
|
+
}
|
|
1553
|
+
showUI() {
|
|
1554
|
+
this.select.removeAttribute("tabindex"), this.select.style.position = "", this.select.style.width = "", this.select.style.height = "", this.select.style.opacity = "", this.select.style.overflow = "", this.select.style.pointerEvents = "", this.select.style.margin = "", this.select.style.padding = "", this.select.style.borderWidth = "", this.select.style.clipPath = "", this.select.removeAttribute("aria-hidden"), this.preventNativeSelect &&= (this.select.removeEventListener("click", this.preventNativeSelect, { capture: !0 }), null), this.preventNativeSelectMousedown &&= (this.select.removeEventListener("mousedown", this.preventNativeSelectMousedown, { capture: !0 }), null), this.preventNativeSelectFocus &&= (this.select.removeEventListener("focus", this.preventNativeSelectFocus, { capture: !0 }), null), this.restoreAriaHiddenOnBlur &&= (this.select.removeEventListener("blur", this.restoreAriaHiddenOnBlur, { capture: !0 }), null);
|
|
1555
|
+
}
|
|
1556
|
+
changeListen(e) {
|
|
1557
|
+
this.listen = e, e && this.observer && this.observer.observe(this.select, {
|
|
1558
|
+
subtree: !0,
|
|
1559
|
+
childList: !0,
|
|
1560
|
+
attributes: !0
|
|
1561
|
+
}), e || this.observer && this.observer.disconnect();
|
|
1562
|
+
}
|
|
1563
|
+
valueChange(e) {
|
|
1564
|
+
return this.listen && this.onValueChange && this.onValueChange(this.getSelectedOptions()), !0;
|
|
1565
|
+
}
|
|
1566
|
+
observeCall(e) {
|
|
1567
|
+
if (!this.listen) return;
|
|
1568
|
+
let { classChanged: t, titleChanged: n, disabledChanged: r, optgroupOptionChanged: i, selectionChanged: a } = B(e, this.select), o = a;
|
|
1569
|
+
if (t && this.onClassChange && this.onClassChange(this.select.className.split(" ")), n && this.onTitleChange && this.onTitleChange(this.select.getAttribute("title") || ""), r && this.onDisabledChange && (this.changeListen(!1), this.onDisabledChange(this.select.disabled), this.changeListen(!0)), i && this.clearLeftoverHiddenDisplay(e), i && this.onOptionsChange) {
|
|
1570
|
+
if (this.isUpdating) {
|
|
1571
|
+
if (this.select.options.length > 0) {
|
|
1572
|
+
let e = this.getData();
|
|
1573
|
+
e.length > 0 && (this.pendingOptionsChange = e);
|
|
1574
|
+
}
|
|
1575
|
+
o && this.select.dispatchEvent(new Event("change"));
|
|
1576
|
+
return;
|
|
1577
|
+
}
|
|
1578
|
+
this.changeListen(!1), this.onOptionsChange(this.getData()), this.changeListen(!0), o = !1;
|
|
1579
|
+
}
|
|
1580
|
+
o && this.select.dispatchEvent(new Event("change"));
|
|
1581
|
+
}
|
|
1582
|
+
getData() {
|
|
1583
|
+
let e = [], t = this.select.childNodes;
|
|
1584
|
+
for (let n of t) n.nodeName === "OPTGROUP" && e.push(this.getDataFromOptgroup(n)), n.nodeName === "OPTION" && e.push(this.getDataFromOption(n));
|
|
1585
|
+
return e;
|
|
1586
|
+
}
|
|
1587
|
+
getDataFromOptgroup(e) {
|
|
1588
|
+
let t = {
|
|
1589
|
+
id: e.id,
|
|
1590
|
+
label: e.label,
|
|
1591
|
+
selectAll: e.dataset ? e.dataset.selectall === "true" : !1,
|
|
1592
|
+
closable: e.dataset ? e.dataset.closable : "off",
|
|
1593
|
+
options: []
|
|
1594
|
+
}, n = e.childNodes;
|
|
1595
|
+
for (let e of n) e.nodeName === "OPTION" && t.options.push(this.getDataFromOption(e));
|
|
1596
|
+
return t;
|
|
1597
|
+
}
|
|
1598
|
+
clearLeftoverHiddenDisplay(e) {
|
|
1599
|
+
for (let t of e) {
|
|
1600
|
+
if (t.target.nodeName !== "OPTION" || t.attributeName !== "hidden") continue;
|
|
1601
|
+
let e = t.target;
|
|
1602
|
+
!e.hidden && e.style.display === "none" && (e.style.display = "");
|
|
1603
|
+
}
|
|
1604
|
+
}
|
|
1605
|
+
getDataFromOption(e) {
|
|
1606
|
+
let t = e.hidden || e.hasAttribute("hidden");
|
|
1607
|
+
return {
|
|
1608
|
+
id: e.id,
|
|
1609
|
+
value: e.value,
|
|
1610
|
+
text: e.text,
|
|
1611
|
+
html: e.dataset && e.dataset.html ? e.dataset.html : "",
|
|
1612
|
+
defaultSelected: e.defaultSelected,
|
|
1613
|
+
selected: e.selected,
|
|
1614
|
+
display: e.style.display !== "none" && !t,
|
|
1615
|
+
disabled: e.disabled,
|
|
1616
|
+
mandatory: e.dataset ? e.dataset.mandatory === "true" : !1,
|
|
1617
|
+
placeholder: e.dataset.placeholder === "true",
|
|
1618
|
+
class: e.className,
|
|
1619
|
+
style: e.style.cssText,
|
|
1620
|
+
data: _(e.dataset)
|
|
1621
|
+
};
|
|
1622
|
+
}
|
|
1623
|
+
getSelectedOptions() {
|
|
1624
|
+
let e = [], t = this.select.childNodes;
|
|
1625
|
+
for (let n of t) {
|
|
1626
|
+
if (n.nodeName === "OPTGROUP") {
|
|
1627
|
+
let t = n.childNodes;
|
|
1628
|
+
for (let n of t) if (n.nodeName === "OPTION") {
|
|
1629
|
+
let t = n;
|
|
1630
|
+
t.selected && e.push(this.getDataFromOption(t));
|
|
1631
|
+
}
|
|
1632
|
+
}
|
|
1633
|
+
if (n.nodeName === "OPTION") {
|
|
1634
|
+
let t = n;
|
|
1635
|
+
t.selected && e.push(this.getDataFromOption(t));
|
|
1636
|
+
}
|
|
1637
|
+
}
|
|
1638
|
+
return e;
|
|
1639
|
+
}
|
|
1640
|
+
getSelectedValues() {
|
|
1641
|
+
return this.getSelectedOptions().map((e) => e.value);
|
|
1642
|
+
}
|
|
1643
|
+
hasOptionValues(e) {
|
|
1644
|
+
if (e.length === 0) return !0;
|
|
1645
|
+
let t = new Set(Array.from(this.select.options).map((e) => e.value));
|
|
1646
|
+
return e.every((e) => t.has(e));
|
|
1647
|
+
}
|
|
1648
|
+
setSelected(e) {
|
|
1649
|
+
this.changeListen(!1);
|
|
1650
|
+
let t = this.select.childNodes;
|
|
1651
|
+
for (let n of t) {
|
|
1652
|
+
if (n.nodeName === "OPTGROUP") {
|
|
1653
|
+
let t = n.childNodes;
|
|
1654
|
+
for (let n of t) if (n.nodeName === "OPTION") {
|
|
1655
|
+
let t = n;
|
|
1656
|
+
t.selected = e.includes(t.id);
|
|
1657
|
+
}
|
|
1658
|
+
}
|
|
1659
|
+
if (n.nodeName === "OPTION") {
|
|
1660
|
+
let t = n;
|
|
1661
|
+
t.selected = e.includes(t.id);
|
|
1662
|
+
}
|
|
1663
|
+
}
|
|
1664
|
+
let n = this.getSelectedOptions();
|
|
1665
|
+
this.select.multiple || (this.select.value = n.length === 1 ? n[0].value : ""), this.select.dispatchEvent(new Event("change", { bubbles: !0 })), this.changeListen(!0);
|
|
1666
|
+
}
|
|
1667
|
+
setSelectedByValue(e) {
|
|
1668
|
+
this.changeListen(!1);
|
|
1669
|
+
let t = this.select.childNodes;
|
|
1670
|
+
for (let n of t) {
|
|
1671
|
+
if (n.nodeName === "OPTGROUP") {
|
|
1672
|
+
let t = n.childNodes;
|
|
1673
|
+
for (let n of t) if (n.nodeName === "OPTION") {
|
|
1674
|
+
let t = n;
|
|
1675
|
+
t.selected = e.includes(t.value);
|
|
1676
|
+
}
|
|
1677
|
+
}
|
|
1678
|
+
if (n.nodeName === "OPTION") {
|
|
1679
|
+
let t = n;
|
|
1680
|
+
t.selected = e.includes(t.value);
|
|
1681
|
+
}
|
|
1682
|
+
}
|
|
1683
|
+
let n = this.getSelectedOptions();
|
|
1684
|
+
this.select.multiple || (this.select.value = n.length === 1 ? n[0].value : ""), this.select.dispatchEvent(new Event("change", { bubbles: !0 })), this.changeListen(!0);
|
|
1685
|
+
}
|
|
1686
|
+
updateSelect(e, t, n) {
|
|
1687
|
+
this.changeListen(!1), e && (this.select.dataset.id = e), t && (this.select.style.cssText = t), n && (this.select.className = "", n.forEach((e) => {
|
|
1688
|
+
e.trim() !== "" && this.select.classList.add(e.trim());
|
|
1689
|
+
})), this.changeListen(!0);
|
|
1690
|
+
}
|
|
1691
|
+
updateOptions(e) {
|
|
1692
|
+
if (!e || e.length === 0) return;
|
|
1693
|
+
this.isUpdating = !0, this.pendingOptionsChange = null, this.changeListen(!1);
|
|
1694
|
+
let t = this.getSelectedValues();
|
|
1695
|
+
this.select.innerHTML = "";
|
|
1696
|
+
for (let t of e) t instanceof I && this.select.appendChild(this.createOptgroup(t)), t instanceof F && this.select.appendChild(this.createOption(t));
|
|
1697
|
+
if (C(t, this.getSelectedValues()) || this.select.dispatchEvent(new Event("change", { bubbles: !0 })), this.changeListen(!0), this.isUpdating = !1, this.pendingOptionsChange !== null) {
|
|
1698
|
+
let e = this.pendingOptionsChange;
|
|
1699
|
+
e.length > 0 && this.onOptionsChange ? (this.pendingOptionsChange = null, this.changeListen(!1), this.onOptionsChange(e), this.changeListen(!0)) : this.pendingOptionsChange = null;
|
|
1700
|
+
}
|
|
1701
|
+
}
|
|
1702
|
+
createOptgroup(e) {
|
|
1703
|
+
let t = document.createElement("optgroup");
|
|
1704
|
+
if (t.id = e.id, t.label = e.label, e.selectAll && (t.dataset.selectAll = "true"), e.closable !== "off" && (t.dataset.closable = e.closable), e.options) for (let n of e.options) t.appendChild(this.createOption(n));
|
|
1705
|
+
return t;
|
|
1706
|
+
}
|
|
1707
|
+
createOption(e) {
|
|
1708
|
+
let t = document.createElement("option");
|
|
1709
|
+
return t.id = e.id, t.value = e.value, t.textContent = e.text, e.html !== "" && t.setAttribute("data-html", e.html), t.defaultSelected = e.defaultSelected, t.selected = e.selected, e.disabled && (t.disabled = !0), t.hidden = !e.display, e.placeholder && t.setAttribute("data-placeholder", "true"), e.mandatory && t.setAttribute("data-mandatory", "true"), e.class && e.class.split(" ").forEach((e) => {
|
|
1710
|
+
t.classList.add(e);
|
|
1711
|
+
}), e.data && typeof e.data == "object" && Object.keys(e.data).forEach((n) => {
|
|
1712
|
+
t.setAttribute("data-" + j(n), e.data[n]);
|
|
1713
|
+
}), t;
|
|
1714
|
+
}
|
|
1715
|
+
setupLabelHandlers() {
|
|
1716
|
+
let e = [], t = this.select.id;
|
|
1717
|
+
t && document.querySelectorAll(`label[for="${t}"]`).forEach((t) => e.push(t));
|
|
1718
|
+
let n = this.select.parentElement;
|
|
1719
|
+
for (; n && n !== document.body;) {
|
|
1720
|
+
if (n.tagName === "LABEL") {
|
|
1721
|
+
e.push(n);
|
|
1722
|
+
break;
|
|
1723
|
+
}
|
|
1724
|
+
n = n.parentElement;
|
|
1725
|
+
}
|
|
1726
|
+
Array.from(new Set(e)).forEach((e) => {
|
|
1727
|
+
if (e.__slimSelectLabelHandler) return;
|
|
1728
|
+
let t = (e) => {
|
|
1729
|
+
let t = e.target, n = x(t, this.select.dataset.id);
|
|
1730
|
+
e.preventDefault(), !n && this.onLabelClick && this.onLabelClick();
|
|
1731
|
+
};
|
|
1732
|
+
e.__slimSelectLabelHandler = t, e.addEventListener("click", t, {
|
|
1733
|
+
capture: !0,
|
|
1734
|
+
passive: !1
|
|
1735
|
+
});
|
|
1736
|
+
});
|
|
1737
|
+
}
|
|
1738
|
+
removeLabelHandlers() {
|
|
1739
|
+
let e = [], t = this.select.id;
|
|
1740
|
+
t && document.querySelectorAll(`label[for="${t}"]`).forEach((t) => e.push(t));
|
|
1741
|
+
let n = this.select.parentElement;
|
|
1742
|
+
for (; n && n !== document.body;) {
|
|
1743
|
+
if (n.tagName === "LABEL") {
|
|
1744
|
+
e.push(n);
|
|
1745
|
+
break;
|
|
1746
|
+
}
|
|
1747
|
+
n = n.parentElement;
|
|
1748
|
+
}
|
|
1749
|
+
Array.from(new Set(e)).forEach((e) => {
|
|
1750
|
+
let t = e.__slimSelectLabelHandler;
|
|
1751
|
+
t && (e.removeEventListener("click", t, { capture: !0 }), delete e.__slimSelectLabelHandler);
|
|
1752
|
+
});
|
|
1753
|
+
}
|
|
1754
|
+
destroy() {
|
|
1755
|
+
this.changeListen(!1), this.select.removeEventListener("change", this.valueChange), this.preventNativeSelect &&= (this.select.removeEventListener("click", this.preventNativeSelect, { capture: !0 }), null), this.preventNativeSelectMousedown &&= (this.select.removeEventListener("mousedown", this.preventNativeSelectMousedown, { capture: !0 }), null), this.preventNativeSelectFocus &&= (this.select.removeEventListener("focus", this.preventNativeSelectFocus, { capture: !0 }), null), this.restoreAriaHiddenOnBlur &&= (this.select.removeEventListener("blur", this.restoreAriaHiddenOnBlur, { capture: !0 }), null), this.observer &&= (this.observer.disconnect(), null), this.removeLabelHandlers(), delete this.select.dataset.id, this.showUI();
|
|
1756
|
+
}
|
|
1757
|
+
};
|
|
1758
|
+
// src/slim-select/sync.ts
|
|
1759
|
+
function H(e, t) {
|
|
1760
|
+
return A(e.getData(!1), t);
|
|
1761
|
+
}
|
|
1762
|
+
function U(e, t) {
|
|
1763
|
+
let n = Array.isArray(t) ? t : [t], r = e.getDataOptions(!1), i = [];
|
|
1764
|
+
for (let e of n) if (r.find((t) => t.id == e)) i.push(e);
|
|
1765
|
+
else for (let t of r.filter((t) => t.value == e)) i.push(t.id);
|
|
1766
|
+
return i;
|
|
1767
|
+
}
|
|
1768
|
+
var W = class {
|
|
1769
|
+
deps;
|
|
1770
|
+
queue = [];
|
|
1771
|
+
flushScheduled = !1;
|
|
1772
|
+
isSyncing = !1;
|
|
1773
|
+
constructor(e) {
|
|
1774
|
+
this.deps = e;
|
|
1775
|
+
}
|
|
1776
|
+
enqueue(e) {
|
|
1777
|
+
this.queue.push(e), e.source === "native" ? this.flushScheduled || (this.flushScheduled = !0, queueMicrotask(() => this.flush())) : this.isSyncing || this.flush();
|
|
1778
|
+
}
|
|
1779
|
+
flush() {
|
|
1780
|
+
if (this.flushScheduled = !1, this.queue.length === 0) return;
|
|
1781
|
+
let e = this.coalesceBatch(this.queue);
|
|
1782
|
+
this.queue = [], this.isSyncing = !0;
|
|
1783
|
+
try {
|
|
1784
|
+
for (let t of e) this.applyChange(t);
|
|
1785
|
+
} finally {
|
|
1786
|
+
this.isSyncing = !1, this.queue.length > 0 && this.flush();
|
|
1787
|
+
}
|
|
1788
|
+
}
|
|
1789
|
+
coalesceBatch(e) {
|
|
1790
|
+
let t = e.some((e) => e.type === "structure"), n = e.some((e) => e.type === "addOption");
|
|
1791
|
+
if (t || n) {
|
|
1792
|
+
let t = e.filter((e) => e.type === "structure" || e.type === "addOption"), n = t[t.length - 1];
|
|
1793
|
+
return n?.type === "structure" ? [n] : t;
|
|
1794
|
+
}
|
|
1795
|
+
let r = e.filter((e) => e.type === "selection");
|
|
1796
|
+
return r.length > 0 ? [r[r.length - 1]] : e;
|
|
1797
|
+
}
|
|
1798
|
+
applyChange(e) {
|
|
1799
|
+
switch (e.type) {
|
|
1800
|
+
case "structure":
|
|
1801
|
+
this.applyStructure(e.data, e.source, e.preserveSelection, e.isSearchResult);
|
|
1802
|
+
break;
|
|
1803
|
+
case "selection":
|
|
1804
|
+
this.applySelection(e.values, e.source, e.runAfterChange !== !1);
|
|
1805
|
+
break;
|
|
1806
|
+
case "addOption": this.applyAddOption(e.option);
|
|
1807
|
+
}
|
|
1808
|
+
}
|
|
1809
|
+
applyStructure(e, t, n = !1, r = !1) {
|
|
1810
|
+
let { store: i, select: a, render: o, events: s } = this.deps;
|
|
1811
|
+
if (!r && H(i, e)) return;
|
|
1812
|
+
let c = i.getSelected(), l = i.validateDataArray(e);
|
|
1813
|
+
if (l) {
|
|
1814
|
+
s.error ? s.error(l) : this.deps.onError && this.deps.onError(l);
|
|
1815
|
+
return;
|
|
1816
|
+
}
|
|
1817
|
+
i.setData(e, n);
|
|
1818
|
+
let u = i.getData(!1);
|
|
1819
|
+
r || i.snapshotCatalog(), r || a.updateOptions(u), o.renderValues(), o.renderOptions(u), s.afterChange && !C(c, i.getSelected()) && s.afterChange(i.getSelectedOptions());
|
|
1820
|
+
}
|
|
1821
|
+
syncNativeSelection() {
|
|
1822
|
+
let { store: e, select: t } = this.deps, n = e.getSelectedOptions(), r = e.getSelectedValues();
|
|
1823
|
+
if (!t.hasOptionValues(r)) {
|
|
1824
|
+
if (n.length > 0) {
|
|
1825
|
+
t.updateOptions(n);
|
|
1826
|
+
return;
|
|
1827
|
+
}
|
|
1828
|
+
let r = e.getCatalogData().find((e) => e instanceof F && e.placeholder === !0);
|
|
1829
|
+
if (r) {
|
|
1830
|
+
t.updateOptions([new F({
|
|
1831
|
+
...r,
|
|
1832
|
+
selected: !0
|
|
1833
|
+
})]);
|
|
1834
|
+
return;
|
|
1835
|
+
}
|
|
1836
|
+
}
|
|
1837
|
+
t.setSelectedByValue(r);
|
|
1838
|
+
}
|
|
1839
|
+
applySelection(e, t, n) {
|
|
1840
|
+
let { store: r, select: i, render: a, events: o } = this.deps, s = r.getSelected(), c = U(r, e);
|
|
1841
|
+
if (C(s, c)) return;
|
|
1842
|
+
r.setSelectedBy("id", c), this.syncNativeSelection(), a.renderValues();
|
|
1843
|
+
let l = a.content.search.input.value.trim();
|
|
1844
|
+
l === "" ? a.canUpdateOptionSelectionInPlace() ? a.updateOptionSelection() : a.renderOptions(r.getData(!1)) : a.hasRenderedOptions() ? a.updateOptionSelection() : this.deps.search && this.deps.search(l), n && o.afterChange && !C(s, r.getSelected()) && o.afterChange(r.getSelectedOptions());
|
|
1845
|
+
}
|
|
1846
|
+
applyAddOption(e) {
|
|
1847
|
+
let { store: t, select: n, render: r, events: i } = this.deps, a = t.getSelected(), o = r.content.search.input.value.trim() !== "" && !!i.search, s = e.value ?? e.text ?? "", c = (e) => {
|
|
1848
|
+
for (let t of e) if (t instanceof I) {
|
|
1849
|
+
if (t.options.some((e) => (e.value ?? e.text) === s)) return !0;
|
|
1850
|
+
} else if ((t.value ?? t.text) === s) return !0;
|
|
1851
|
+
return !1;
|
|
1852
|
+
};
|
|
1853
|
+
if (!c(t.getData(!1))) {
|
|
1854
|
+
if (o) {
|
|
1855
|
+
let n = t.getCatalogData();
|
|
1856
|
+
c(n) || t.setData([...n, new F(e)], !0), t.snapshotCatalog();
|
|
1857
|
+
} else t.addOption(e), t.snapshotCatalog();
|
|
1858
|
+
}
|
|
1859
|
+
let l = t.getData(!1);
|
|
1860
|
+
if (o) {
|
|
1861
|
+
let e = t.getSelectedOptions();
|
|
1862
|
+
e.length > 0 && n.updateOptions(e);
|
|
1863
|
+
} else n.updateOptions(l);
|
|
1864
|
+
r.renderValues(), r.renderOptions(l), i.afterChange && !C(a, t.getSelected()) && i.afterChange(t.getSelectedOptions());
|
|
1865
|
+
}
|
|
1866
|
+
}, G = class {
|
|
1867
|
+
selectEl;
|
|
1868
|
+
settings;
|
|
1869
|
+
cssClasses;
|
|
1870
|
+
select;
|
|
1871
|
+
store;
|
|
1872
|
+
render;
|
|
1873
|
+
sync;
|
|
1874
|
+
lifecycle;
|
|
1875
|
+
globalEvents;
|
|
1876
|
+
searchGeneration = 0;
|
|
1877
|
+
events = {
|
|
1878
|
+
search: void 0,
|
|
1879
|
+
searchFilter: (e, t) => e.text.toLowerCase().indexOf(t.toLowerCase()) !== -1,
|
|
1880
|
+
addable: void 0,
|
|
1881
|
+
beforeChange: void 0,
|
|
1882
|
+
afterChange: void 0,
|
|
1883
|
+
beforeOpen: void 0,
|
|
1884
|
+
afterOpen: void 0,
|
|
1885
|
+
beforeClose: void 0,
|
|
1886
|
+
afterClose: void 0
|
|
1887
|
+
};
|
|
1888
|
+
constructor(e) {
|
|
1889
|
+
if (this.selectEl = typeof e.select == "string" ? document.querySelector(e.select) : e.select, !this.selectEl) {
|
|
1890
|
+
e.events && e.events.error && e.events.error(/* @__PURE__ */ Error("Could not find select element"));
|
|
1891
|
+
return;
|
|
1892
|
+
}
|
|
1893
|
+
if (this.selectEl.tagName !== "SELECT") {
|
|
1894
|
+
e.events && e.events.error && e.events.error(/* @__PURE__ */ Error("Element isnt of type select"));
|
|
1895
|
+
return;
|
|
1896
|
+
}
|
|
1897
|
+
this.selectEl.dataset.ssid && this.destroy(), this.settings = new g(e.settings), e.settings?.selectAll === void 0 && this.selectEl.dataset.selectall === "true" && (this.settings.selectAll = !0), this.cssClasses = new o(e.cssClasses);
|
|
1898
|
+
let t = [
|
|
1899
|
+
"beforeOpen",
|
|
1900
|
+
"afterOpen",
|
|
1901
|
+
"afterClose"
|
|
1902
|
+
];
|
|
1903
|
+
for (let n in e.events) e.events.hasOwnProperty(n) && (t.indexOf(n) === -1 ? this.events[n] = e.events[n] : this.events[n] = S(e.events[n], 100));
|
|
1904
|
+
this.settings.disabled = e.settings?.disabled ? e.settings.disabled : this.selectEl.disabled, this.settings.isMultiple = this.selectEl.multiple, this.settings.style = this.selectEl.style.cssText, this.settings.class = this.selectEl.className.split(" "), this.select = new V(this.selectEl), this.selectEl.id || (this.selectEl.id = this.settings.id), this.select.updateSelect(this.settings.id, this.settings.style, this.settings.class), this.select.hideUI(), this.select.onClassChange = (e) => {
|
|
1905
|
+
this.settings.class = e, this.render.updateClassStyles();
|
|
1906
|
+
}, this.select.onTitleChange = (e) => {
|
|
1907
|
+
this.render.updateTitle(e);
|
|
1908
|
+
}, this.select.onDisabledChange = (e) => {
|
|
1909
|
+
e ? this.disable() : this.enable();
|
|
1910
|
+
}, this.select.onLabelClick = () => {
|
|
1911
|
+
this.settings.disabled || (this.settings.isOpen ? this.close({
|
|
1912
|
+
source: "toggle",
|
|
1913
|
+
selectionChanged: !1
|
|
1914
|
+
}) : this.open());
|
|
1915
|
+
};
|
|
1916
|
+
let n = e.data ? e.data : this.select.getData();
|
|
1917
|
+
this.store = new L(this.settings.isMultiple ? "multiple" : "single", n), e.data && this.select.updateOptions(this.store.getData());
|
|
1918
|
+
let r = {
|
|
1919
|
+
open: this.open.bind(this),
|
|
1920
|
+
close: this.close.bind(this),
|
|
1921
|
+
addable: this.events.addable ? this.events.addable : void 0,
|
|
1922
|
+
setSelected: (e, t) => {
|
|
1923
|
+
this.sync.enqueue({
|
|
1924
|
+
type: "selection",
|
|
1925
|
+
values: e,
|
|
1926
|
+
source: "ui",
|
|
1927
|
+
runAfterChange: t
|
|
1928
|
+
});
|
|
1929
|
+
},
|
|
1930
|
+
addOption: (e) => {
|
|
1931
|
+
this.sync.enqueue({
|
|
1932
|
+
type: "addOption",
|
|
1933
|
+
option: e,
|
|
1934
|
+
source: "ui"
|
|
1935
|
+
});
|
|
1936
|
+
},
|
|
1937
|
+
search: this.search.bind(this),
|
|
1938
|
+
clearSearch: this.clearSearch.bind(this),
|
|
1939
|
+
beforeChange: this.events.beforeChange,
|
|
1940
|
+
afterChange: this.events.afterChange
|
|
1941
|
+
};
|
|
1942
|
+
this.settings.modalTitle = e.settings?.modalTitle ?? y(this.selectEl), this.render = new z(this.settings, this.cssClasses, this.store, r), this.settings.timeoutDelay = d(this.render.content.main, e.settings?.timeoutDelay), this.sync = new W({
|
|
1943
|
+
select: this.select,
|
|
1944
|
+
store: this.store,
|
|
1945
|
+
render: this.render,
|
|
1946
|
+
events: this.events,
|
|
1947
|
+
search: this.search.bind(this)
|
|
1948
|
+
}), this.select.onValueChange = (e) => {
|
|
1949
|
+
this.sync.enqueue({
|
|
1950
|
+
type: "selection",
|
|
1951
|
+
values: e.map((e) => e.id || e.value),
|
|
1952
|
+
source: "native"
|
|
1953
|
+
});
|
|
1954
|
+
}, this.select.onOptionsChange = (e) => {
|
|
1955
|
+
this.sync.enqueue({
|
|
1956
|
+
type: "structure",
|
|
1957
|
+
data: e || [],
|
|
1958
|
+
source: "native"
|
|
1959
|
+
});
|
|
1960
|
+
}, this.lifecycle = new P({
|
|
1961
|
+
beforeOpen: this.events.beforeOpen,
|
|
1962
|
+
afterOpen: this.events.afterOpen,
|
|
1963
|
+
beforeClose: (e) => this.events.beforeClose?.(e),
|
|
1964
|
+
onClose: (e) => this.applyClose(e),
|
|
1965
|
+
afterClose: () => {
|
|
1966
|
+
this.render.clearDirectionClasses(), this.render.finalizeModalClose(), this.events.afterClose && this.events.afterClose();
|
|
1967
|
+
},
|
|
1968
|
+
onOpenReady: () => this.globalEvents.attachDocumentClick(),
|
|
1969
|
+
onCloseReady: () => this.globalEvents.detachDocumentClick()
|
|
1970
|
+
}, {
|
|
1971
|
+
timeoutDelay: this.settings.timeoutDelay,
|
|
1972
|
+
waitForAnimation: (e, t) => this.render.waitForAnimation(e, t)
|
|
1973
|
+
}), this.globalEvents = new N({
|
|
1974
|
+
onDocumentClick: this.documentClick.bind(this),
|
|
1975
|
+
onWindowResize: () => {
|
|
1976
|
+
(this.settings.isOpen || this.settings.isFullOpen) && this.render.moveContent();
|
|
1977
|
+
},
|
|
1978
|
+
onWindowScroll: () => {
|
|
1979
|
+
(this.settings.isOpen || this.settings.isFullOpen) && this.render.moveContent();
|
|
1980
|
+
},
|
|
1981
|
+
onVisibilityChange: () => {
|
|
1982
|
+
document.hidden && this.close({
|
|
1983
|
+
source: "api",
|
|
1984
|
+
selectionChanged: !1
|
|
1985
|
+
});
|
|
1986
|
+
}
|
|
1987
|
+
}), this.render.renderValues(), this.render.renderOptions(this.store.getData(!1));
|
|
1988
|
+
let i = this.selectEl.getAttribute("aria-label"), a = this.selectEl.getAttribute("aria-labelledby");
|
|
1989
|
+
if (i) this.render.main.main.setAttribute("aria-label", i);
|
|
1990
|
+
else if (a) this.render.main.main.removeAttribute("aria-label"), this.render.main.main.setAttribute("aria-labelledby", a);
|
|
1991
|
+
else if (this.selectEl.labels && this.selectEl.labels.length > 0) {
|
|
1992
|
+
let e = Array.from(this.selectEl.labels).map((e, t) => (e.id ||= `${this.settings.id}-label-${t}`, e.id));
|
|
1993
|
+
this.render.main.main.removeAttribute("aria-label"), this.render.main.main.setAttribute("aria-labelledby", e.join(" "));
|
|
1994
|
+
}
|
|
1995
|
+
this.render.updateTitle(this.selectEl.getAttribute("title")), this.selectEl.parentNode && this.selectEl.parentNode.insertBefore(this.render.main.main, this.selectEl.nextSibling), this.globalEvents.attach({ listenScroll: this.settings.openPosition === "auto" }), this.settings.disabled && this.disable(), this.settings.alwaysOpen && this.open(), this.select.setupLabelHandlers(), this.selectEl.slim = this;
|
|
1996
|
+
}
|
|
1997
|
+
enable() {
|
|
1998
|
+
this.settings.disabled = !1, this.select.enable(), this.render.enable();
|
|
1999
|
+
}
|
|
2000
|
+
disable() {
|
|
2001
|
+
this.settings.disabled = !0, this.select.disable(), this.render.disable();
|
|
2002
|
+
}
|
|
2003
|
+
getData() {
|
|
2004
|
+
return this.store.getData();
|
|
2005
|
+
}
|
|
2006
|
+
setData(e) {
|
|
2007
|
+
this.sync.enqueue({
|
|
2008
|
+
type: "structure",
|
|
2009
|
+
data: e,
|
|
2010
|
+
source: "api"
|
|
2011
|
+
});
|
|
2012
|
+
}
|
|
2013
|
+
getSelected() {
|
|
2014
|
+
let e = this.store.getSelectedOptions();
|
|
2015
|
+
return this.settings.keepOrder && (e = this.store.selectedOrderOptions(e)), e.map((e) => e.value);
|
|
2016
|
+
}
|
|
2017
|
+
setSelected(e, t = !0) {
|
|
2018
|
+
this.sync.enqueue({
|
|
2019
|
+
type: "selection",
|
|
2020
|
+
values: e,
|
|
2021
|
+
source: "api",
|
|
2022
|
+
runAfterChange: t
|
|
2023
|
+
});
|
|
2024
|
+
}
|
|
2025
|
+
addOption(e) {
|
|
2026
|
+
this.sync.enqueue({
|
|
2027
|
+
type: "addOption",
|
|
2028
|
+
option: e,
|
|
2029
|
+
source: "api"
|
|
2030
|
+
});
|
|
2031
|
+
}
|
|
2032
|
+
open() {
|
|
2033
|
+
if (this.settings.disabled || this.settings.isOpen) return;
|
|
2034
|
+
this.lifecycle.cancelPending(), this.render.open(), this.settings.showSearch && this.settings.focusSearch && this.render.searchFocus(), this.settings.isOpen = !0, this.lifecycle.requestOpen().then(() => {
|
|
2035
|
+
this.settings.isOpen && (this.settings.isFullOpen = this.lifecycle.isFullOpen, this.settings.isOpen = this.lifecycle.isOpen);
|
|
2036
|
+
}), this.settings.contentPosition === "absolute" && !this.render.isModalViewActive() && this.render.startPositionTracking();
|
|
2037
|
+
let e = this.render.content.search.input.value.trim();
|
|
2038
|
+
e !== "" && this.search(e);
|
|
2039
|
+
}
|
|
2040
|
+
close(e = {
|
|
2041
|
+
source: "api",
|
|
2042
|
+
selectionChanged: !1
|
|
2043
|
+
}) {
|
|
2044
|
+
this.settings.isOpen && !this.settings.alwaysOpen && this.lifecycle.requestClose(e).then((e) => {
|
|
2045
|
+
e && (this.settings.isOpen || (this.settings.isOpen = this.lifecycle.isOpen, this.settings.isFullOpen = this.lifecycle.isFullOpen));
|
|
2046
|
+
});
|
|
2047
|
+
}
|
|
2048
|
+
applyClose(e) {
|
|
2049
|
+
this.render.close(), !this.settings.keepSearch && this.render.content.search.input.value !== "" && (this.sync.flush(), this.clearSearch());
|
|
2050
|
+
let t = e.source === "outside" || e.source === "toggle";
|
|
2051
|
+
this.render.mainFocus(t ? "click" : null), this.settings.isOpen = !1, this.settings.isFullOpen = !1, this.render.stopPositionTracking();
|
|
2052
|
+
}
|
|
2053
|
+
search(e) {
|
|
2054
|
+
let t = e.trim();
|
|
2055
|
+
t === "" ? this.render.content.search.input.value = "" : this.render.content.search.input.value !== e && (this.render.content.search.input.value = e), this.events.search ? this.runApiSearch(t) : t === "" ? this.clearSearch() : this.runLocalSearch(t);
|
|
2056
|
+
}
|
|
2057
|
+
clearSearch() {
|
|
2058
|
+
this.render.content.search.input.value = "", this.searchGeneration++, !this.events.search && this.render.canFilterOptionsInPlace() ? (this.render.filterOptionsInPlace("", this.events.searchFilter), this.render.resetSearchFilterState()) : (this.render.resetSearchFilterState(), this.sync.enqueue({
|
|
2059
|
+
type: "structure",
|
|
2060
|
+
data: this.store.getCatalogData(),
|
|
2061
|
+
source: "api",
|
|
2062
|
+
preserveSelection: !0
|
|
2063
|
+
}));
|
|
2064
|
+
}
|
|
2065
|
+
runLocalSearch(e) {
|
|
2066
|
+
if (this.render.canFilterOptionsInPlace()) {
|
|
2067
|
+
this.render.filterOptionsInPlace(e, this.events.searchFilter);
|
|
2068
|
+
return;
|
|
2069
|
+
}
|
|
2070
|
+
let t = this.store.search(e, this.events.searchFilter);
|
|
2071
|
+
this.render.renderOptions(t);
|
|
2072
|
+
}
|
|
2073
|
+
runApiSearch(e) {
|
|
2074
|
+
let t = ++this.searchGeneration;
|
|
2075
|
+
this.render.renderSearching();
|
|
2076
|
+
let n = this.events.search(e, this.store.getSelectedOptions(), this.store.getCatalogData()), r = (n) => {
|
|
2077
|
+
t === this.searchGeneration && this.render.content.search.input.value.trim() === e && this.sync.enqueue({
|
|
2078
|
+
type: "structure",
|
|
2079
|
+
data: n,
|
|
2080
|
+
source: "api",
|
|
2081
|
+
preserveSelection: !0,
|
|
2082
|
+
isSearchResult: !0
|
|
2083
|
+
});
|
|
2084
|
+
};
|
|
2085
|
+
n instanceof Promise ? n.then(r).catch((e) => {
|
|
2086
|
+
t === this.searchGeneration && this.render.renderError(typeof e == "string" ? e : e.message);
|
|
2087
|
+
}) : Array.isArray(n) ? r(n) : this.render.renderError("Search event must return a promise or an array of data");
|
|
2088
|
+
}
|
|
2089
|
+
destroy() {
|
|
2090
|
+
this.lifecycle.destroy(), this.render.stopPositionTracking(), this.globalEvents.detach({ listenScroll: this.settings.openPosition === "auto" }), this.store.setData([]), this.render.destroy(), this.select.destroy(), delete this.selectEl.slim;
|
|
2091
|
+
}
|
|
2092
|
+
documentClick(e) {
|
|
2093
|
+
this.settings.isOpen && e.target && !x(e.target, this.settings.id) && this.close({
|
|
2094
|
+
source: "outside",
|
|
2095
|
+
selectionChanged: !1
|
|
2096
|
+
});
|
|
2097
|
+
}
|
|
2098
|
+
}, K = e(({ data: e, settings: o, events: s, cssClasses: c, value: l, onChange: u, multiple: d }, f) => {
|
|
2099
|
+
let p = r(null), m = r(null), h = r(!0), g = r(l), _ = r(null), v = r(u), y = r(s), b = r(d), x = r(l), [S, C] = i(!1);
|
|
2100
|
+
t(() => {
|
|
2101
|
+
v.current = u;
|
|
2102
|
+
}, [u]), t(() => {
|
|
2103
|
+
y.current = s;
|
|
2104
|
+
}, [s]), t(() => {
|
|
2105
|
+
b.current = d;
|
|
2106
|
+
}, [d]), t(() => {
|
|
2107
|
+
x.current = l;
|
|
2108
|
+
}, [l]), n(f, () => ({ slimSelect: m.current }), [S]);
|
|
2109
|
+
let w = (e) => {
|
|
2110
|
+
let t = b.current;
|
|
2111
|
+
return typeof e == "string" ? t ? [e] : e : Array.isArray(e) ? t ? e : e[0] : t ? [] : "";
|
|
2112
|
+
}, T = (e, t = !1) => {
|
|
2113
|
+
if (!m.current || e === void 0) return;
|
|
2114
|
+
let n = w(e), r = m.current.getData().flatMap((e) => "label" in e ? e.options : [e]);
|
|
2115
|
+
if (!(Array.isArray(n) ? n.length > 0 && n.every((e) => r.some((t) => t.value === e)) : n !== "" && r.some((e) => e.value === n)) && !Array.isArray(n) && !r.some((e) => e.placeholder)) {
|
|
2116
|
+
let e = m.current.getData();
|
|
2117
|
+
m.current.setData([{
|
|
2118
|
+
value: "",
|
|
2119
|
+
text: "",
|
|
2120
|
+
placeholder: !0
|
|
2121
|
+
}].concat(e));
|
|
2122
|
+
}
|
|
2123
|
+
m.current.setSelected(n, t);
|
|
2124
|
+
}, E = (e) => {
|
|
2125
|
+
if (!m.current) return;
|
|
2126
|
+
let t = b.current ? e.map((e) => e.value) : e[0]?.value ?? "", n = m.current.getData().flatMap((e) => "label" in e ? e.options : [e]), r = g.current, i = r === void 0 ? !1 : Array.isArray(r) ? r.length > 0 && r.every((e) => n.some((t) => t.value === e)) : r !== "" && n.some((e) => e.value === r), a = Array.isArray(t) ? t.length > 0 && t.every((e) => n.some((t) => t.value === e)) : t !== "" && n.some((e) => e.value === t), o = Array.isArray(t) && Array.isArray(r) ? JSON.stringify(t.sort()) !== JSON.stringify(r.sort()) : r !== t;
|
|
2127
|
+
v.current && o && (i || a) && (v.current(t), g.current = t), y.current?.afterChange?.(e);
|
|
2128
|
+
};
|
|
2129
|
+
return t(() => {
|
|
2130
|
+
if (!p.current) return;
|
|
2131
|
+
let t = {
|
|
2132
|
+
select: p.current,
|
|
2133
|
+
data: e
|
|
2134
|
+
};
|
|
2135
|
+
return o && (t.settings = o), c && (t.cssClasses = c), t.events = {
|
|
2136
|
+
...s,
|
|
2137
|
+
afterChange: E
|
|
2138
|
+
}, m.current = new G(t), _.current = structuredClone(e), C(!0), x.current !== void 0 && T(x.current, !1), () => {
|
|
2139
|
+
C(!1), m.current &&= (m.current.destroy(), null);
|
|
2140
|
+
};
|
|
2141
|
+
}, []), t(() => {
|
|
2142
|
+
h.current ? (h.current = !1, g.current = l) : m.current && l !== void 0 && (g.current = l, T(l, !1));
|
|
2143
|
+
}, [l]), t(() => {
|
|
2144
|
+
m.current && !h.current && (_.current !== null && A(_.current, e) || (m.current.setData(e), _.current = structuredClone(e), x.current !== void 0 && T(x.current, !1)));
|
|
2145
|
+
}, [e]), /* @__PURE__ */ a("select", {
|
|
2146
|
+
ref: p,
|
|
2147
|
+
multiple: d
|
|
2148
|
+
});
|
|
2149
|
+
});
|
|
2150
|
+
K.displayName = "SlimSelect";
|
|
2151
|
+
// src/slim-select/react/index.tsx
|
|
2152
|
+
var q = K;
|
|
2153
|
+
export { I as Optgroup, F as Option, g as Settings, q as default };
|