slim-select 3.1.4 → 3.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -0
- package/dist/index.d.ts +8 -0
- package/dist/react/index.d.ts +8 -0
- package/dist/react/index.js +290 -226
- package/dist/react/index.umd.js +2 -2
- package/dist/slimselect.cjs.js +1 -1
- package/dist/slimselect.cjs.js.map +1 -1
- package/dist/slimselect.css +1 -1
- package/dist/slimselect.css.map +1 -1
- package/dist/slimselect.es.js +310 -246
- package/dist/slimselect.es.js.map +1 -1
- package/dist/slimselect.iife.js +1 -1
- package/dist/slimselect.iife.js.map +1 -1
- package/dist/slimselect.js +1 -1
- package/dist/slimselect.js.map +1 -1
- package/dist/vue/index.d.ts +8 -0
- package/dist/vue/index.js +346 -282
- package/dist/vue/index.umd.js +1 -1
- package/package.json +21 -20
- package/src/slim-select/classes.test.ts +3 -3
- package/src/slim-select/classes.ts +40 -34
- package/src/slim-select/index.test.ts +108 -1
- package/src/slim-select/index.ts +14 -2
- package/src/slim-select/render.ts +198 -117
- package/src/slim-select/select.ts +18 -11
- package/src/slim-select/settings.test.ts +1 -0
- package/src/slim-select/settings.ts +2 -0
- package/src/slim-select/slimselect.scss +5 -0
package/dist/slimselect.es.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
class
|
|
1
|
+
class L {
|
|
2
2
|
main;
|
|
3
3
|
// Placeholder
|
|
4
4
|
placeholder;
|
|
@@ -59,13 +59,18 @@ class A {
|
|
|
59
59
|
disabled;
|
|
60
60
|
hide;
|
|
61
61
|
constructor(e) {
|
|
62
|
-
e || (e = {})
|
|
62
|
+
e || (e = {});
|
|
63
|
+
let t = (s = "", i = "") => `${s} ${i}`.trim();
|
|
64
|
+
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.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.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 || "M60,10 L10,10 L10,90 L90,90 L90,50", this.optgroupSelectAllCheck = e.optgroupSelectAllCheck || "M30,45 L50,70 L90,10", 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.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);
|
|
65
|
+
}
|
|
66
|
+
getFirst(e) {
|
|
67
|
+
return this[e].split(" ")[0];
|
|
63
68
|
}
|
|
64
69
|
}
|
|
65
|
-
function
|
|
70
|
+
function y() {
|
|
66
71
|
return Math.random().toString(36).substring(2, 10);
|
|
67
72
|
}
|
|
68
|
-
function
|
|
73
|
+
function A(p, e) {
|
|
69
74
|
function t(i, l) {
|
|
70
75
|
return l && i && i.classList && i.classList.contains(l) || l && i && i.dataset && i.dataset.id && i.dataset.id === e ? i : null;
|
|
71
76
|
}
|
|
@@ -77,13 +82,13 @@ function T(p, e) {
|
|
|
77
82
|
function S(p, e = 50, t = !1) {
|
|
78
83
|
let s;
|
|
79
84
|
return function(...i) {
|
|
80
|
-
const l = self,
|
|
85
|
+
const l = self, n = () => {
|
|
81
86
|
s = null, t || p.apply(l, i);
|
|
82
|
-
},
|
|
83
|
-
clearTimeout(s), s = setTimeout(
|
|
87
|
+
}, a = t && !s;
|
|
88
|
+
clearTimeout(s), s = setTimeout(n, e), a && p.apply(l, i);
|
|
84
89
|
};
|
|
85
90
|
}
|
|
86
|
-
function
|
|
91
|
+
function O(p, e) {
|
|
87
92
|
return JSON.stringify(p) === JSON.stringify(e);
|
|
88
93
|
}
|
|
89
94
|
function D(p) {
|
|
@@ -105,7 +110,7 @@ class u {
|
|
|
105
110
|
data;
|
|
106
111
|
mandatory;
|
|
107
112
|
constructor(e) {
|
|
108
|
-
this.id = !e.id || e.id === "" ?
|
|
113
|
+
this.id = !e.id || e.id === "" ? y() : 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 : !1, this.selected = e.selected !== void 0 ? e.selected : !1, this.display = e.display !== void 0 ? e.display : !0, this.disabled = e.disabled !== void 0 ? e.disabled : !1, this.mandatory = e.mandatory !== void 0 ? e.mandatory : !1, this.placeholder = e.placeholder !== void 0 ? e.placeholder : !1, this.class = e.class || "", this.style = e.style || "", this.data = e.data || {};
|
|
109
114
|
}
|
|
110
115
|
}
|
|
111
116
|
class g {
|
|
@@ -116,7 +121,7 @@ class g {
|
|
|
116
121
|
closable;
|
|
117
122
|
options;
|
|
118
123
|
constructor(e) {
|
|
119
|
-
if (this.id = !e.id || e.id === "" ?
|
|
124
|
+
if (this.id = !e.id || e.id === "" ? y() : e.id, this.label = e.label || "", this.selectAll = e.selectAll === void 0 ? !1 : e.selectAll, this.selectAllText = e.selectAllText || "Select All", this.closable = e.closable || "off", this.options = [], e.options)
|
|
120
125
|
for (const t of e.options)
|
|
121
126
|
this.options.push(new u(t));
|
|
122
127
|
}
|
|
@@ -174,22 +179,22 @@ class k {
|
|
|
174
179
|
const s = this.partialToFullData(e);
|
|
175
180
|
if (t) {
|
|
176
181
|
const i = this.getSelectedOptions(), l = [];
|
|
177
|
-
i.forEach((
|
|
178
|
-
let
|
|
182
|
+
i.forEach((n) => {
|
|
183
|
+
let a = !1;
|
|
179
184
|
for (const o of s) {
|
|
180
|
-
if (o instanceof u && o.id ===
|
|
181
|
-
|
|
185
|
+
if (o instanceof u && o.id === n.id) {
|
|
186
|
+
a = !0;
|
|
182
187
|
break;
|
|
183
188
|
}
|
|
184
189
|
if (o instanceof g) {
|
|
185
|
-
for (const
|
|
186
|
-
if (
|
|
187
|
-
|
|
190
|
+
for (const h of o.options)
|
|
191
|
+
if (h.id === n.id) {
|
|
192
|
+
a = !0;
|
|
188
193
|
break;
|
|
189
194
|
}
|
|
190
195
|
}
|
|
191
196
|
}
|
|
192
|
-
|
|
197
|
+
a || l.push(n);
|
|
193
198
|
}), this.data = [...l, ...s];
|
|
194
199
|
} else
|
|
195
200
|
this.data = s;
|
|
@@ -217,18 +222,18 @@ class k {
|
|
|
217
222
|
setSelectedBy(e, t) {
|
|
218
223
|
let s = null, i = !1;
|
|
219
224
|
const l = [];
|
|
220
|
-
for (let
|
|
221
|
-
if (
|
|
222
|
-
for (let o of
|
|
225
|
+
for (let a of this.data) {
|
|
226
|
+
if (a instanceof g)
|
|
227
|
+
for (let o of a.options) {
|
|
223
228
|
s || (s = o);
|
|
224
|
-
let
|
|
225
|
-
o.selected = i ? !1 : t.includes(
|
|
229
|
+
let h = o[e] || "";
|
|
230
|
+
o.selected = i ? !1 : t.includes(h), o.selected && (l.push(o), this.selectType === "single" && (i = !0));
|
|
226
231
|
}
|
|
227
|
-
|
|
232
|
+
a instanceof u && (s || (s = a), a.selected = i ? !1 : t.includes(a[e]), a.selected && (l.push(a), this.selectType === "single" && (i = !0)));
|
|
228
233
|
}
|
|
229
234
|
this.selectType === "single" && s && !i && (s.selected = !0, l.push(s));
|
|
230
|
-
const
|
|
231
|
-
this.selectedOrder =
|
|
235
|
+
const n = t.map((a) => l.find((o) => o[e] === a)?.id || "");
|
|
236
|
+
this.selectedOrder = n;
|
|
232
237
|
}
|
|
233
238
|
getSelected() {
|
|
234
239
|
return this.getSelectedOptions().map((e) => e.id);
|
|
@@ -270,11 +275,11 @@ class k {
|
|
|
270
275
|
return this.data.forEach((i) => {
|
|
271
276
|
if (i instanceof g) {
|
|
272
277
|
let l = [];
|
|
273
|
-
if (i.options.forEach((
|
|
274
|
-
(!e || e(
|
|
278
|
+
if (i.options.forEach((a) => {
|
|
279
|
+
(!e || e(a)) && (t ? l.push(new u(a)) : s.push(new u(a)));
|
|
275
280
|
}), l.length > 0) {
|
|
276
|
-
let
|
|
277
|
-
|
|
281
|
+
let a = new g(i);
|
|
282
|
+
a.options = l, s.push(a);
|
|
278
283
|
}
|
|
279
284
|
}
|
|
280
285
|
i instanceof u && (!e || e(i)) && s.push(new u(i));
|
|
@@ -303,6 +308,8 @@ class N {
|
|
|
303
308
|
callbacks;
|
|
304
309
|
// Used to compute the range selection
|
|
305
310
|
lastSelectedOption;
|
|
311
|
+
// Timeout tracking for cleanup
|
|
312
|
+
closeAnimationTimeout = null;
|
|
306
313
|
// Elements
|
|
307
314
|
main;
|
|
308
315
|
content;
|
|
@@ -311,18 +318,35 @@ class N {
|
|
|
311
318
|
constructor(e, t, s, i) {
|
|
312
319
|
this.store = s, this.settings = e, this.classes = t, this.callbacks = i, this.lastSelectedOption = null, 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);
|
|
313
320
|
}
|
|
321
|
+
// Helper method to add classes that may contain spaces
|
|
322
|
+
// Splits by spaces and adds each class individually to avoid DOMException
|
|
323
|
+
addClasses(e, t) {
|
|
324
|
+
if (!t || t.trim() === "")
|
|
325
|
+
return;
|
|
326
|
+
const s = t.split(" ").filter((i) => i.trim() !== "");
|
|
327
|
+
for (const i of s)
|
|
328
|
+
e.classList.add(i.trim());
|
|
329
|
+
}
|
|
330
|
+
// Helper method to remove classes that may contain spaces
|
|
331
|
+
removeClasses(e, t) {
|
|
332
|
+
if (!t || t.trim() === "")
|
|
333
|
+
return;
|
|
334
|
+
const s = t.split(" ").filter((i) => i.trim() !== "");
|
|
335
|
+
for (const i of s)
|
|
336
|
+
e.classList.remove(i.trim());
|
|
337
|
+
}
|
|
314
338
|
// Remove disabled classes
|
|
315
339
|
enable() {
|
|
316
|
-
this.main.main
|
|
340
|
+
this.removeClasses(this.main.main, this.classes.disabled), this.main.main.setAttribute("aria-disabled", "false"), this.content.search.input.disabled = !1;
|
|
317
341
|
}
|
|
318
342
|
// Set disabled classes
|
|
319
343
|
disable() {
|
|
320
|
-
this.main.main
|
|
344
|
+
this.addClasses(this.main.main, this.classes.disabled), this.main.main.setAttribute("aria-disabled", "true"), this.content.search.input.disabled = !0;
|
|
321
345
|
}
|
|
322
346
|
open() {
|
|
323
|
-
this.main.arrow.path.setAttribute("d", this.classes.arrowOpen), this.main.main.setAttribute("aria-expanded", "true");
|
|
347
|
+
this.main.arrow.path.setAttribute("d", this.classes.arrowOpen), this.main.main.setAttribute("aria-expanded", "true"), this.closeAnimationTimeout && (clearTimeout(this.closeAnimationTimeout), this.closeAnimationTimeout = null);
|
|
324
348
|
const t = this.settings.openPosition === "up" ? this.classes.dirAbove : this.classes.dirBelow;
|
|
325
|
-
this.main.main
|
|
349
|
+
this.addClasses(this.main.main, t), this.addClasses(this.content.main, t), this.addClasses(this.content.main, this.classes.contentOpen), this.content.search.input.removeAttribute("aria-hidden"), this.moveContent();
|
|
326
350
|
const s = this.store.getSelectedOptions();
|
|
327
351
|
if (s.length) {
|
|
328
352
|
const i = s[s.length - 1].id, l = this.content.list.querySelector('[data-id="' + i + '"]');
|
|
@@ -330,12 +354,24 @@ class N {
|
|
|
330
354
|
}
|
|
331
355
|
}
|
|
332
356
|
close() {
|
|
333
|
-
this.main.main.setAttribute("aria-expanded", "false"), this.main.arrow.path.setAttribute("d", this.classes.arrowClose), this.content.main
|
|
334
|
-
|
|
335
|
-
|
|
357
|
+
this.main.main.setAttribute("aria-expanded", "false"), this.main.arrow.path.setAttribute("d", this.classes.arrowClose), this.removeClasses(this.content.main, this.classes.contentOpen), this.content.search.input.setAttribute("aria-hidden", "true"), this.main.main.removeAttribute("aria-activedescendant");
|
|
358
|
+
const e = this.getAnimationTiming();
|
|
359
|
+
this.closeAnimationTimeout = setTimeout(() => {
|
|
360
|
+
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), this.closeAnimationTimeout = null;
|
|
361
|
+
}, e);
|
|
362
|
+
}
|
|
363
|
+
getAnimationTiming() {
|
|
364
|
+
const t = getComputedStyle(this.content.main).getPropertyValue("--ss-animation-timing").trim();
|
|
365
|
+
if (t) {
|
|
366
|
+
if (t.endsWith("ms"))
|
|
367
|
+
return parseFloat(t);
|
|
368
|
+
if (t.endsWith("s"))
|
|
369
|
+
return parseFloat(t) * 1e3;
|
|
370
|
+
}
|
|
371
|
+
return 200;
|
|
336
372
|
}
|
|
337
373
|
updateClassStyles() {
|
|
338
|
-
if (this.main.main.className = "", this.main.main.removeAttribute("style"), this.content.main.className = "", this.content.main.removeAttribute("style"), this.main.main
|
|
374
|
+
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)
|
|
339
375
|
for (const e of this.settings.class)
|
|
340
376
|
e.trim() !== "" && (this.main.main.classList.add(e.trim()), this.content.main.classList.add(e.trim()));
|
|
341
377
|
(this.settings.contentPosition === "relative" || this.settings.contentPosition === "fixed") && this.content.main.classList.add("ss-" + this.settings.contentPosition);
|
|
@@ -346,37 +382,39 @@ class N {
|
|
|
346
382
|
}
|
|
347
383
|
mainDiv() {
|
|
348
384
|
const e = document.createElement("div");
|
|
349
|
-
e.dataset.id = this.settings.id, e.setAttribute("aria-label", this.settings.ariaLabel), e.tabIndex = 0, e.onkeydown = (
|
|
350
|
-
switch (
|
|
385
|
+
e.dataset.id = this.settings.id, e.setAttribute("aria-label", this.settings.ariaLabel), e.tabIndex = 0, e.onkeydown = (h) => {
|
|
386
|
+
switch (h.key) {
|
|
351
387
|
case "ArrowUp":
|
|
352
388
|
case "ArrowDown":
|
|
353
|
-
return this.callbacks.open(),
|
|
389
|
+
return this.callbacks.open(), h.key === "ArrowDown" ? this.highlight("down") : this.highlight("up"), !1;
|
|
354
390
|
case "Tab":
|
|
355
391
|
return this.callbacks.close(), !0;
|
|
356
392
|
// Continue doing normal tabbing
|
|
357
393
|
case "Enter":
|
|
358
394
|
case " ":
|
|
359
395
|
this.callbacks.open();
|
|
360
|
-
const r = this.content.list.querySelector(
|
|
396
|
+
const r = this.content.list.querySelector(
|
|
397
|
+
"." + this.classes.getFirst("highlighted")
|
|
398
|
+
);
|
|
361
399
|
return r && r.click(), !1;
|
|
362
400
|
case "Escape":
|
|
363
401
|
return this.callbacks.close(), !1;
|
|
364
402
|
}
|
|
365
|
-
return
|
|
366
|
-
}, e.onclick = (
|
|
403
|
+
return h.key.length === 1 && this.callbacks.open(), !0;
|
|
404
|
+
}, e.onclick = (h) => {
|
|
367
405
|
this.settings.disabled || (this.settings.isOpen ? this.callbacks.close() : this.callbacks.open());
|
|
368
406
|
};
|
|
369
407
|
const t = document.createElement("div");
|
|
370
|
-
|
|
408
|
+
this.addClasses(t, this.classes.values), e.appendChild(t);
|
|
371
409
|
const s = document.createElement("div");
|
|
372
|
-
|
|
410
|
+
this.addClasses(s, this.classes.deselect);
|
|
373
411
|
const i = this.store?.getSelectedOptions();
|
|
374
|
-
!this.settings.allowDeselect || this.settings.isMultiple && i && i.length <= 0 ?
|
|
375
|
-
if (
|
|
412
|
+
!this.settings.allowDeselect || this.settings.isMultiple && i && i.length <= 0 ? this.addClasses(s, this.classes.hide) : this.removeClasses(s, this.classes.hide), s.onclick = (h) => {
|
|
413
|
+
if (h.stopPropagation(), this.settings.disabled)
|
|
376
414
|
return;
|
|
377
415
|
let r = !0;
|
|
378
|
-
const
|
|
379
|
-
if (this.callbacks.beforeChange && (r = this.callbacks.beforeChange(f,
|
|
416
|
+
const c = this.store.getSelectedOptions(), f = [];
|
|
417
|
+
if (this.callbacks.beforeChange && (r = this.callbacks.beforeChange(f, c) === !0), r) {
|
|
380
418
|
if (this.settings.isMultiple)
|
|
381
419
|
this.callbacks.setSelected([], !1), this.updateDeselectAll();
|
|
382
420
|
else {
|
|
@@ -388,21 +426,21 @@ class N {
|
|
|
388
426
|
};
|
|
389
427
|
const l = document.createElementNS("http://www.w3.org/2000/svg", "svg");
|
|
390
428
|
l.setAttribute("viewBox", "0 0 100 100");
|
|
391
|
-
const
|
|
392
|
-
|
|
393
|
-
const
|
|
394
|
-
|
|
429
|
+
const n = document.createElementNS("http://www.w3.org/2000/svg", "path");
|
|
430
|
+
n.setAttribute("d", this.classes.deselectPath), l.appendChild(n), s.appendChild(l), e.appendChild(s);
|
|
431
|
+
const a = document.createElementNS("http://www.w3.org/2000/svg", "svg");
|
|
432
|
+
this.addClasses(a, this.classes.arrow), a.setAttribute("viewBox", "0 0 100 100");
|
|
395
433
|
const o = document.createElementNS("http://www.w3.org/2000/svg", "path");
|
|
396
|
-
return o.setAttribute("d", this.classes.arrowClose), this.settings.alwaysOpen &&
|
|
434
|
+
return o.setAttribute("d", this.classes.arrowClose), this.settings.alwaysOpen && this.addClasses(a, this.classes.hide), a.appendChild(o), e.appendChild(a), {
|
|
397
435
|
main: e,
|
|
398
436
|
values: t,
|
|
399
437
|
deselect: {
|
|
400
438
|
main: s,
|
|
401
439
|
svg: l,
|
|
402
|
-
path:
|
|
440
|
+
path: n
|
|
403
441
|
},
|
|
404
442
|
arrow: {
|
|
405
|
-
main:
|
|
443
|
+
main: a,
|
|
406
444
|
path: o
|
|
407
445
|
}
|
|
408
446
|
};
|
|
@@ -415,7 +453,7 @@ class N {
|
|
|
415
453
|
let t = this.settings.placeholderText;
|
|
416
454
|
e.length && (e[0].html !== "" ? t = e[0].html : e[0].text !== "" && (t = e[0].text));
|
|
417
455
|
const s = document.createElement("div");
|
|
418
|
-
return
|
|
456
|
+
return this.addClasses(s, this.classes.placeholder), s.innerHTML = t, s;
|
|
419
457
|
}
|
|
420
458
|
// Get selected values and append to multiSelected values container
|
|
421
459
|
// and remove those who shouldnt exist
|
|
@@ -432,9 +470,9 @@ class N {
|
|
|
432
470
|
this.main.values.innerHTML = this.placeholder().outerHTML;
|
|
433
471
|
else {
|
|
434
472
|
const s = document.createElement("div");
|
|
435
|
-
|
|
473
|
+
this.addClasses(s, this.classes.single), t.html ? s.innerHTML = t.html : s.innerText = t.text, this.main.values.innerHTML = s.outerHTML;
|
|
436
474
|
}
|
|
437
|
-
!this.settings.allowDeselect || !e.length ? this.main.deselect.main
|
|
475
|
+
!this.settings.allowDeselect || !e.length ? this.addClasses(this.main.deselect.main, this.classes.hide) : this.removeClasses(this.main.deselect.main, this.classes.hide);
|
|
438
476
|
}
|
|
439
477
|
renderMultipleValues() {
|
|
440
478
|
let e = this.main.values.childNodes, t = this.store.filter((i) => i.selected && i.display, !1);
|
|
@@ -442,62 +480,62 @@ class N {
|
|
|
442
480
|
this.main.values.innerHTML = this.placeholder().outerHTML;
|
|
443
481
|
return;
|
|
444
482
|
} else {
|
|
445
|
-
const i = this.main.values.querySelector("." + this.classes.placeholder);
|
|
483
|
+
const i = this.main.values.querySelector("." + this.classes.getFirst("placeholder"));
|
|
446
484
|
i && i.remove();
|
|
447
485
|
}
|
|
448
486
|
if (t.length > this.settings.maxValuesShown) {
|
|
449
487
|
const i = document.createElement("div");
|
|
450
|
-
|
|
488
|
+
this.addClasses(i, this.classes.max), i.textContent = this.settings.maxValuesMessage.replace("{number}", t.length.toString()), this.main.values.innerHTML = i.outerHTML;
|
|
451
489
|
return;
|
|
452
490
|
} else {
|
|
453
|
-
const i = this.main.values.querySelector("." + this.classes.max);
|
|
491
|
+
const i = this.main.values.querySelector("." + this.classes.getFirst("max"));
|
|
454
492
|
i && i.remove();
|
|
455
493
|
}
|
|
456
494
|
this.settings.keepOrder && (t = this.store.selectedOrderOptions(t));
|
|
457
495
|
let s = [];
|
|
458
496
|
for (let i = 0; i < e.length; i++) {
|
|
459
|
-
const l = e[i],
|
|
460
|
-
|
|
497
|
+
const l = e[i], n = l.getAttribute("data-id");
|
|
498
|
+
n && (t.filter((o) => o.id === n, !1).length || s.push(l));
|
|
461
499
|
}
|
|
462
500
|
for (const i of s)
|
|
463
|
-
|
|
501
|
+
this.addClasses(i, this.classes.valueOut), setTimeout(() => {
|
|
464
502
|
this.main.values.hasChildNodes() && this.main.values.contains(i) && this.main.values.removeChild(i);
|
|
465
503
|
}, 100);
|
|
466
504
|
e = this.main.values.childNodes;
|
|
467
505
|
for (let i = 0; i < t.length; i++) {
|
|
468
506
|
let l = !0;
|
|
469
|
-
for (let
|
|
470
|
-
t[i].id === String(e[
|
|
507
|
+
for (let n = 0; n < e.length; n++)
|
|
508
|
+
t[i].id === String(e[n].dataset.id) && (l = !1);
|
|
471
509
|
l && (this.settings.keepOrder ? this.main.values.appendChild(this.multipleValue(t[i])) : e.length === 0 ? this.main.values.appendChild(this.multipleValue(t[i])) : i === 0 ? this.main.values.insertBefore(this.multipleValue(t[i]), e[i]) : e[i - 1].insertAdjacentElement("afterend", this.multipleValue(t[i])));
|
|
472
510
|
}
|
|
473
511
|
}
|
|
474
512
|
multipleValue(e) {
|
|
475
513
|
const t = document.createElement("div");
|
|
476
|
-
|
|
514
|
+
this.addClasses(t, this.classes.value), t.dataset.id = e.id;
|
|
477
515
|
const s = document.createElement("div");
|
|
478
|
-
if (
|
|
516
|
+
if (this.addClasses(s, this.classes.valueText), s.textContent = e.text, t.appendChild(s), !e.mandatory) {
|
|
479
517
|
const i = document.createElement("div");
|
|
480
|
-
|
|
481
|
-
if (
|
|
518
|
+
this.addClasses(i, this.classes.valueDelete), i.setAttribute("tabindex", "0"), i.onclick = (a) => {
|
|
519
|
+
if (a.preventDefault(), a.stopPropagation(), this.settings.disabled)
|
|
482
520
|
return;
|
|
483
521
|
let o = !0;
|
|
484
|
-
const
|
|
485
|
-
if (!(this.settings.minSelected && r.length < this.settings.minSelected) && (this.callbacks.beforeChange && (o = this.callbacks.beforeChange(r,
|
|
486
|
-
let
|
|
522
|
+
const h = this.store.getSelectedOptions(), r = h.filter((c) => c.selected && c.id !== e.id, !0);
|
|
523
|
+
if (!(this.settings.minSelected && r.length < this.settings.minSelected) && (this.callbacks.beforeChange && (o = this.callbacks.beforeChange(r, h) === !0), o)) {
|
|
524
|
+
let c = [];
|
|
487
525
|
for (const f of r) {
|
|
488
526
|
if (f instanceof g)
|
|
489
527
|
for (const d of f.options)
|
|
490
|
-
d.id &&
|
|
491
|
-
f instanceof u &&
|
|
528
|
+
d.id && c.push(d.id);
|
|
529
|
+
f instanceof u && c.push(f.id);
|
|
492
530
|
}
|
|
493
|
-
this.callbacks.setSelected(
|
|
531
|
+
this.callbacks.setSelected(c, !1), this.settings.closeOnSelect && this.callbacks.close(), this.callbacks.afterChange && this.callbacks.afterChange(r), this.updateDeselectAll();
|
|
494
532
|
}
|
|
495
533
|
};
|
|
496
534
|
const l = document.createElementNS("http://www.w3.org/2000/svg", "svg");
|
|
497
535
|
l.setAttribute("viewBox", "0 0 100 100");
|
|
498
|
-
const
|
|
499
|
-
|
|
500
|
-
|
|
536
|
+
const n = document.createElementNS("http://www.w3.org/2000/svg", "path");
|
|
537
|
+
n.setAttribute("d", this.classes.optionDelete), l.appendChild(n), i.appendChild(l), t.appendChild(i), i.onkeydown = (a) => {
|
|
538
|
+
a.key === "Enter" && i.click();
|
|
501
539
|
};
|
|
502
540
|
}
|
|
503
541
|
return t;
|
|
@@ -530,12 +568,12 @@ class N {
|
|
|
530
568
|
}
|
|
531
569
|
searchDiv() {
|
|
532
570
|
const e = document.createElement("div"), t = document.createElement("input"), s = document.createElement("div");
|
|
533
|
-
|
|
571
|
+
this.addClasses(e, this.classes.search);
|
|
534
572
|
const i = {
|
|
535
573
|
main: e,
|
|
536
574
|
input: t
|
|
537
575
|
};
|
|
538
|
-
if (this.settings.showSearch || (
|
|
576
|
+
if (this.settings.showSearch || (this.addClasses(e, this.classes.hide), t.readOnly = !0), t.type = "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"), t.oninput = S((l) => {
|
|
539
577
|
this.callbacks.search(l.target.value);
|
|
540
578
|
}, 100), t.onkeydown = (l) => {
|
|
541
579
|
switch (l.key) {
|
|
@@ -548,28 +586,32 @@ class N {
|
|
|
548
586
|
case "Escape":
|
|
549
587
|
return this.callbacks.close(), !1;
|
|
550
588
|
case " ":
|
|
551
|
-
const
|
|
552
|
-
|
|
589
|
+
const n = this.content.list.querySelector(
|
|
590
|
+
"." + this.classes.getFirst("highlighted")
|
|
591
|
+
);
|
|
592
|
+
return n ? (n.click(), !1) : !0;
|
|
553
593
|
case "Enter":
|
|
554
|
-
const
|
|
555
|
-
|
|
594
|
+
const a = this.content.list.querySelector(
|
|
595
|
+
"." + this.classes.getFirst("highlighted")
|
|
596
|
+
);
|
|
597
|
+
return a ? (a.click(), !1) : this.callbacks.addable ? (s.click(), !1) : !0;
|
|
556
598
|
}
|
|
557
599
|
return !0;
|
|
558
600
|
}, e.appendChild(t), this.callbacks.addable) {
|
|
559
|
-
|
|
601
|
+
this.addClasses(s, this.classes.addable);
|
|
560
602
|
const l = document.createElementNS("http://www.w3.org/2000/svg", "svg");
|
|
561
603
|
l.setAttribute("viewBox", "0 0 100 100");
|
|
562
|
-
const
|
|
563
|
-
|
|
564
|
-
if (
|
|
604
|
+
const n = document.createElementNS("http://www.w3.org/2000/svg", "path");
|
|
605
|
+
n.setAttribute("d", this.classes.addablePath), l.appendChild(n), s.appendChild(l), s.onclick = (a) => {
|
|
606
|
+
if (a.preventDefault(), a.stopPropagation(), !this.callbacks.addable)
|
|
565
607
|
return;
|
|
566
608
|
const o = this.content.search.input.value.trim();
|
|
567
609
|
if (o === "") {
|
|
568
610
|
this.content.search.input.focus();
|
|
569
611
|
return;
|
|
570
612
|
}
|
|
571
|
-
const
|
|
572
|
-
let f = new u(
|
|
613
|
+
const h = (c) => {
|
|
614
|
+
let f = new u(c);
|
|
573
615
|
if (this.callbacks.addOption(f), this.settings.isMultiple) {
|
|
574
616
|
let d = this.store.getSelected();
|
|
575
617
|
d.push(f.id), this.callbacks.setSelected(d, !0);
|
|
@@ -579,92 +621,94 @@ class N {
|
|
|
579
621
|
this.callbacks.close();
|
|
580
622
|
}, 100);
|
|
581
623
|
}, r = this.callbacks.addable(o);
|
|
582
|
-
r === !1 || r === void 0 || r === null || (r instanceof Promise ? r.then((
|
|
583
|
-
typeof
|
|
584
|
-
text:
|
|
585
|
-
value:
|
|
586
|
-
}) : r instanceof Error ? this.renderError(r.message) : c
|
|
587
|
-
}) : typeof r == "string" ?
|
|
624
|
+
r === !1 || r === void 0 || r === null || (r instanceof Promise ? r.then((c) => {
|
|
625
|
+
typeof c == "string" ? h({
|
|
626
|
+
text: c,
|
|
627
|
+
value: c
|
|
628
|
+
}) : r instanceof Error ? this.renderError(r.message) : h(c);
|
|
629
|
+
}) : typeof r == "string" ? h({
|
|
588
630
|
text: r,
|
|
589
631
|
value: r
|
|
590
|
-
}) : r instanceof Error ? this.renderError(r.message) :
|
|
632
|
+
}) : r instanceof Error ? this.renderError(r.message) : h(r));
|
|
591
633
|
}, e.appendChild(s), i.addable = {
|
|
592
634
|
main: s,
|
|
593
635
|
svg: l,
|
|
594
|
-
path:
|
|
636
|
+
path: n
|
|
595
637
|
};
|
|
596
638
|
}
|
|
597
639
|
return i;
|
|
598
640
|
}
|
|
599
641
|
searchFocus() {
|
|
600
|
-
this.content.search.input.focus();
|
|
642
|
+
this.content.search.input.focus({ preventScroll: !0 });
|
|
601
643
|
}
|
|
602
644
|
getOptions(e = !1, t = !1, s = !1) {
|
|
603
|
-
let i = "." + this.classes.option;
|
|
604
|
-
return e && (i += ":not(." + this.classes.placeholder + ")"), t && (i += ":not(." + this.classes.disabled + ")"), s && (i += ":not(." + this.classes.hide + ")"), Array.from(this.content.list.querySelectorAll(i));
|
|
645
|
+
let i = "." + this.classes.getFirst("option");
|
|
646
|
+
return e && (i += ":not(." + this.classes.getFirst("placeholder") + ")"), t && (i += ":not(." + this.classes.getFirst("disabled") + ")"), s && (i += ":not(." + this.classes.getFirst("hide") + ")"), Array.from(this.content.list.querySelectorAll(i));
|
|
605
647
|
}
|
|
606
648
|
// highlightUp is used to highlight the previous option in the list
|
|
607
649
|
highlight(e) {
|
|
608
650
|
const t = this.getOptions(!0, !0, !0);
|
|
609
651
|
if (t.length === 0)
|
|
610
652
|
return;
|
|
611
|
-
if (t.length === 1 && !t[0].classList.contains(this.classes.highlighted)) {
|
|
612
|
-
t[0]
|
|
653
|
+
if (t.length === 1 && !t[0].classList.contains(this.classes.getFirst("highlighted"))) {
|
|
654
|
+
this.addClasses(t[0], this.classes.highlighted);
|
|
613
655
|
return;
|
|
614
656
|
}
|
|
615
657
|
let s = !1;
|
|
616
658
|
for (const l of t)
|
|
617
|
-
l.classList.contains(this.classes.highlighted) && (s = !0);
|
|
659
|
+
l.classList.contains(this.classes.getFirst("highlighted")) && (s = !0);
|
|
618
660
|
if (!s) {
|
|
619
661
|
for (const l of t)
|
|
620
|
-
if (l.classList.contains(this.classes.selected)) {
|
|
621
|
-
|
|
662
|
+
if (l.classList.contains(this.classes.getFirst("selected"))) {
|
|
663
|
+
this.addClasses(l, this.classes.highlighted);
|
|
622
664
|
break;
|
|
623
665
|
}
|
|
624
666
|
}
|
|
625
667
|
for (let l = 0; l < t.length; l++)
|
|
626
|
-
if (t[l].classList.contains(this.classes.highlighted)) {
|
|
627
|
-
const
|
|
628
|
-
|
|
629
|
-
const
|
|
630
|
-
if (
|
|
631
|
-
const r =
|
|
668
|
+
if (t[l].classList.contains(this.classes.getFirst("highlighted"))) {
|
|
669
|
+
const n = t[l];
|
|
670
|
+
this.removeClasses(n, this.classes.highlighted);
|
|
671
|
+
const a = n.parentElement;
|
|
672
|
+
if (a && a.classList.contains(this.classes.getFirst("mainOpen"))) {
|
|
673
|
+
const r = a.querySelector("." + this.classes.getFirst("optgroupLabel"));
|
|
632
674
|
r && r.click();
|
|
633
675
|
}
|
|
634
676
|
let o = t[e === "down" ? l + 1 < t.length ? l + 1 : 0 : l - 1 >= 0 ? l - 1 : t.length - 1];
|
|
635
|
-
|
|
636
|
-
const
|
|
637
|
-
if (
|
|
638
|
-
const r =
|
|
677
|
+
this.addClasses(o, this.classes.highlighted), this.ensureElementInView(this.content.list, o), o.id && this.main.main.setAttribute("aria-activedescendant", o.id);
|
|
678
|
+
const h = o.parentElement;
|
|
679
|
+
if (h && h.classList.contains(this.classes.getFirst("close"))) {
|
|
680
|
+
const r = h.querySelector(
|
|
681
|
+
"." + this.classes.getFirst("optgroupLabel")
|
|
682
|
+
);
|
|
639
683
|
r && r.click();
|
|
640
684
|
}
|
|
641
685
|
return;
|
|
642
686
|
}
|
|
643
687
|
const i = t[e === "down" ? 0 : t.length - 1];
|
|
644
|
-
|
|
688
|
+
this.addClasses(i, this.classes.highlighted), i.id && this.main.main.setAttribute("aria-activedescendant", i.id), this.ensureElementInView(this.content.list, i);
|
|
645
689
|
}
|
|
646
690
|
// Create main container that options will reside
|
|
647
691
|
listDiv() {
|
|
648
692
|
const e = document.createElement("div");
|
|
649
|
-
|
|
693
|
+
this.addClasses(e, this.classes.list);
|
|
650
694
|
const t = this.settings.id + "-list";
|
|
651
695
|
return e.id = t, e.dataset.id = t, e;
|
|
652
696
|
}
|
|
653
697
|
renderError(e) {
|
|
654
698
|
this.content.list.innerHTML = "";
|
|
655
699
|
const t = document.createElement("div");
|
|
656
|
-
|
|
700
|
+
this.addClasses(t, this.classes.error), t.textContent = e, this.content.list.appendChild(t);
|
|
657
701
|
}
|
|
658
702
|
renderSearching() {
|
|
659
703
|
this.content.list.innerHTML = "";
|
|
660
704
|
const e = document.createElement("div");
|
|
661
|
-
|
|
705
|
+
this.addClasses(e, this.classes.searching), e.textContent = this.settings.searchingText, this.content.list.appendChild(e);
|
|
662
706
|
}
|
|
663
707
|
// Take in data and add options to
|
|
664
708
|
renderOptions(e) {
|
|
665
709
|
if (this.content.list.innerHTML = "", e.length === 0) {
|
|
666
710
|
const s = document.createElement("div");
|
|
667
|
-
|
|
711
|
+
this.addClasses(s, this.classes.search), this.callbacks.addable ? s.innerHTML = this.settings.addableText.replace("{value}", this.content.search.input.value) : s.innerHTML = this.settings.searchText, this.content.list.appendChild(s);
|
|
668
712
|
return;
|
|
669
713
|
}
|
|
670
714
|
this.settings.allowDeselect && !this.settings.isMultiple && (this.store.filter((i) => i.placeholder, !1).length || this.store.addOption(
|
|
@@ -680,60 +724,60 @@ class N {
|
|
|
680
724
|
for (const s of e) {
|
|
681
725
|
if (s instanceof g) {
|
|
682
726
|
const i = document.createElement("div");
|
|
683
|
-
|
|
727
|
+
this.addClasses(i, this.classes.optgroup);
|
|
684
728
|
const l = document.createElement("div");
|
|
685
|
-
|
|
686
|
-
const a = document.createElement("div");
|
|
687
|
-
a.classList.add(this.classes.optgroupLabelText), a.textContent = s.label, l.appendChild(a);
|
|
729
|
+
this.addClasses(l, this.classes.optgroupLabel), i.appendChild(l);
|
|
688
730
|
const n = document.createElement("div");
|
|
689
|
-
|
|
731
|
+
this.addClasses(n, this.classes.optgroupLabelText), n.textContent = s.label, l.appendChild(n);
|
|
732
|
+
const a = document.createElement("div");
|
|
733
|
+
if (this.addClasses(a, this.classes.optgroupActions), l.appendChild(a), this.settings.isMultiple && s.selectAll) {
|
|
690
734
|
const o = document.createElement("div");
|
|
691
|
-
|
|
692
|
-
let
|
|
735
|
+
this.addClasses(o, this.classes.optgroupSelectAll);
|
|
736
|
+
let h = !0;
|
|
693
737
|
for (const m of s.options)
|
|
694
738
|
if (!m.selected) {
|
|
695
|
-
|
|
739
|
+
h = !1;
|
|
696
740
|
break;
|
|
697
741
|
}
|
|
698
|
-
|
|
742
|
+
h && this.addClasses(o, this.classes.selected);
|
|
699
743
|
const r = document.createElement("span");
|
|
700
744
|
r.textContent = s.selectAllText, o.appendChild(r);
|
|
701
|
-
const
|
|
702
|
-
|
|
745
|
+
const c = document.createElementNS("http://www.w3.org/2000/svg", "svg");
|
|
746
|
+
c.setAttribute("viewBox", "0 0 100 100"), o.appendChild(c);
|
|
703
747
|
const f = document.createElementNS("http://www.w3.org/2000/svg", "path");
|
|
704
|
-
f.setAttribute("d", this.classes.optgroupSelectAllBox),
|
|
748
|
+
f.setAttribute("d", this.classes.optgroupSelectAllBox), c.appendChild(f);
|
|
705
749
|
const d = document.createElementNS("http://www.w3.org/2000/svg", "path");
|
|
706
|
-
d.setAttribute("d", this.classes.optgroupSelectAllCheck),
|
|
750
|
+
d.setAttribute("d", this.classes.optgroupSelectAllCheck), c.appendChild(d), o.addEventListener("click", (m) => {
|
|
707
751
|
m.preventDefault(), m.stopPropagation();
|
|
708
752
|
const v = this.store.getSelected();
|
|
709
|
-
if (
|
|
710
|
-
const
|
|
753
|
+
if (h) {
|
|
754
|
+
const C = v.filter((w) => {
|
|
711
755
|
for (const b of s.options)
|
|
712
|
-
if (
|
|
756
|
+
if (w === b.id)
|
|
713
757
|
return !1;
|
|
714
758
|
return !0;
|
|
715
759
|
});
|
|
716
|
-
this.callbacks.setSelected(
|
|
760
|
+
this.callbacks.setSelected(C, !0);
|
|
717
761
|
return;
|
|
718
762
|
} else {
|
|
719
|
-
let
|
|
720
|
-
const
|
|
763
|
+
let C = s.options.map((b) => b.id).filter((b) => b !== void 0);
|
|
764
|
+
const w = v.concat(C);
|
|
721
765
|
for (const b of s.options)
|
|
722
766
|
b.id && !this.store.getOptionByID(b.id) && this.callbacks.addOption(new u(b));
|
|
723
|
-
this.callbacks.setSelected(
|
|
767
|
+
this.callbacks.setSelected(w, !0);
|
|
724
768
|
return;
|
|
725
769
|
}
|
|
726
|
-
}),
|
|
770
|
+
}), a.appendChild(o);
|
|
727
771
|
}
|
|
728
772
|
if (s.closable !== "off") {
|
|
729
773
|
const o = document.createElement("div");
|
|
730
|
-
|
|
731
|
-
const
|
|
732
|
-
|
|
774
|
+
this.addClasses(o, this.classes.optgroupClosable);
|
|
775
|
+
const h = document.createElementNS("http://www.w3.org/2000/svg", "svg");
|
|
776
|
+
h.setAttribute("viewBox", "0 0 100 100"), this.addClasses(h, this.classes.arrow), o.appendChild(h);
|
|
733
777
|
const r = document.createElementNS("http://www.w3.org/2000/svg", "path");
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
}),
|
|
778
|
+
h.appendChild(r), s.options.some((c) => c.selected) || this.content.search.input.value.trim() !== "" ? (this.addClasses(o, this.classes.mainOpen), r.setAttribute("d", this.classes.arrowOpen)) : s.closable === "open" ? (this.addClasses(i, this.classes.mainOpen), r.setAttribute("d", this.classes.arrowOpen)) : s.closable === "close" && (this.addClasses(i, this.classes.close), r.setAttribute("d", this.classes.arrowClose)), l.addEventListener("click", (c) => {
|
|
779
|
+
c.preventDefault(), c.stopPropagation(), i.classList.contains(this.classes.getFirst("close")) ? (this.removeClasses(i, this.classes.close), this.addClasses(i, this.classes.mainOpen), r.setAttribute("d", this.classes.arrowOpen)) : (this.removeClasses(i, this.classes.mainOpen), this.addClasses(i, this.classes.close), r.setAttribute("d", this.classes.arrowClose));
|
|
780
|
+
}), a.appendChild(o);
|
|
737
781
|
}
|
|
738
782
|
i.appendChild(l);
|
|
739
783
|
for (const o of s.options)
|
|
@@ -747,83 +791,99 @@ class N {
|
|
|
747
791
|
option(e) {
|
|
748
792
|
if (e.placeholder) {
|
|
749
793
|
const s = document.createElement("div");
|
|
750
|
-
return
|
|
794
|
+
return this.addClasses(s, this.classes.option), this.addClasses(s, this.classes.hide), s;
|
|
751
795
|
}
|
|
752
796
|
const t = document.createElement("div");
|
|
753
|
-
return t.dataset.id = e.id, t.id = this.settings.id + "-" + e.id,
|
|
797
|
+
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((s) => {
|
|
754
798
|
t.classList.add(s);
|
|
755
799
|
}), e.style && (t.style.cssText = e.style), this.settings.searchHighlight && this.content.search.input.value.trim() !== "" ? t.innerHTML = this.highlightText(
|
|
756
800
|
e.html !== "" ? e.html : e.text,
|
|
757
801
|
this.content.search.input.value,
|
|
758
802
|
this.classes.searchHighlighter
|
|
759
|
-
) : e.html !== "" ? t.innerHTML = e.html : t.textContent = e.text, this.settings.showOptionTooltips && t.textContent && t.setAttribute("title", t.textContent), e.display ||
|
|
803
|
+
) : e.html !== "" ? t.innerHTML = e.html : t.textContent = e.text, this.settings.showOptionTooltips && t.textContent && t.setAttribute("title", t.textContent), 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", (s) => {
|
|
760
804
|
s.preventDefault(), s.stopPropagation();
|
|
761
|
-
const i = this.store.getSelected(), l = s.currentTarget,
|
|
762
|
-
if (e.disabled || !this.settings.isMultiple && e.selected && !this.settings.allowDeselect || e.selected && e.mandatory || this.settings.isMultiple && this.settings.maxSelected <= i.length && !e.selected || this.settings.isMultiple && this.settings.minSelected >= i.length && e.selected && !
|
|
805
|
+
const i = this.store.getSelected(), l = s.currentTarget, n = String(l.dataset.id), a = s.ctrlKey || s.metaKey;
|
|
806
|
+
if (e.disabled || !this.settings.isMultiple && e.selected && !this.settings.allowDeselect || e.selected && e.mandatory || this.settings.isMultiple && this.settings.maxSelected <= i.length && !e.selected || this.settings.isMultiple && this.settings.minSelected >= i.length && e.selected && !a)
|
|
763
807
|
return;
|
|
764
808
|
let o = !1;
|
|
765
|
-
const
|
|
809
|
+
const h = this.store.getSelectedOptions();
|
|
766
810
|
let r = [];
|
|
767
811
|
if (this.settings.isMultiple) {
|
|
768
|
-
const
|
|
812
|
+
const c = h.some((d) => d.id === n);
|
|
769
813
|
if (s.shiftKey && this.lastSelectedOption) {
|
|
770
|
-
const d = this.store.getDataOptions(), m = d.findIndex((
|
|
814
|
+
const d = this.store.getDataOptions(), m = d.findIndex((C) => C.id === this.lastSelectedOption.id), v = d.findIndex((C) => C.id === e.id);
|
|
771
815
|
if (m >= 0 && v >= 0) {
|
|
772
|
-
const
|
|
773
|
-
|
|
816
|
+
const C = Math.min(m, v), w = Math.max(m, v), E = d.slice(C, w + 1).filter((x) => !h.find((T) => T.id === x.id));
|
|
817
|
+
h.length + E.length <= this.settings.maxSelected ? r = h.concat(E) : r = h;
|
|
774
818
|
} else
|
|
775
|
-
r =
|
|
776
|
-
} else
|
|
819
|
+
r = h;
|
|
820
|
+
} else a ? (c ? r = h.filter((d) => d.id !== n) : r = h.concat(e), this.lastSelectedOption = e) : (c ? r = h.filter((d) => d.id !== n) : r = h.concat(e), this.lastSelectedOption = e);
|
|
777
821
|
}
|
|
778
|
-
if (this.settings.isMultiple || (e.selected ? r = [] : r = [e]), this.callbacks.beforeChange || (o = !0), this.callbacks.beforeChange && (this.callbacks.beforeChange(r,
|
|
779
|
-
this.store.getOptionByID(
|
|
822
|
+
if (this.settings.isMultiple || (e.selected ? r = [] : r = [e]), this.callbacks.beforeChange || (o = !0), this.callbacks.beforeChange && (this.callbacks.beforeChange(r, h) === !1 ? o = !1 : o = !0), o) {
|
|
823
|
+
this.store.getOptionByID(n) || this.callbacks.addOption(e), this.callbacks.setSelected(
|
|
780
824
|
r.map((d) => d.id),
|
|
781
825
|
!1
|
|
782
826
|
);
|
|
783
|
-
const
|
|
784
|
-
this.settings.closeOnSelect && !(this.settings.isMultiple &&
|
|
827
|
+
const c = s.ctrlKey || s.metaKey || s.shiftKey;
|
|
828
|
+
this.settings.closeOnSelect && !(this.settings.isMultiple && c) && this.callbacks.close(), this.callbacks.afterChange && this.callbacks.afterChange(r);
|
|
785
829
|
}
|
|
786
830
|
}), t;
|
|
787
831
|
}
|
|
788
832
|
destroy() {
|
|
789
|
-
this.main.main.remove(), this.content.main.remove();
|
|
833
|
+
this.closeAnimationTimeout && (clearTimeout(this.closeAnimationTimeout), this.closeAnimationTimeout = null), this.main.main.remove(), this.content.main.remove();
|
|
790
834
|
}
|
|
791
835
|
highlightText(e, t, s) {
|
|
792
836
|
const i = t.trim();
|
|
793
837
|
if (i === "")
|
|
794
838
|
return e;
|
|
795
|
-
const l = i.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"),
|
|
796
|
-
|
|
797
|
-
const
|
|
839
|
+
const l = i.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"), n = document.createElement("div");
|
|
840
|
+
n.innerHTML = e;
|
|
841
|
+
const a = (o) => {
|
|
798
842
|
if (o.nodeType === Node.TEXT_NODE) {
|
|
799
|
-
const
|
|
800
|
-
if (r.test(
|
|
801
|
-
const
|
|
802
|
-
|
|
843
|
+
const h = o.textContent || "", r = new RegExp("(" + l + ")", "i");
|
|
844
|
+
if (r.test(h)) {
|
|
845
|
+
const c = document.createElement("span");
|
|
846
|
+
h.split(r).forEach((d, m) => {
|
|
803
847
|
if (d && r.test(d)) {
|
|
804
848
|
const v = document.createElement("mark");
|
|
805
|
-
v.className = s, v.textContent = d,
|
|
806
|
-
} else d &&
|
|
807
|
-
}), o.parentNode?.replaceChild(
|
|
849
|
+
v.className = s, v.textContent = d, c.appendChild(v);
|
|
850
|
+
} else d && c.appendChild(document.createTextNode(d));
|
|
851
|
+
}), o.parentNode?.replaceChild(c, o);
|
|
808
852
|
}
|
|
809
|
-
} else o.nodeType === Node.ELEMENT_NODE && Array.from(o.childNodes).forEach((
|
|
853
|
+
} else o.nodeType === Node.ELEMENT_NODE && Array.from(o.childNodes).forEach((h) => a(h));
|
|
810
854
|
};
|
|
811
|
-
return Array.from(
|
|
855
|
+
return Array.from(n.childNodes).forEach((o) => a(o)), n.innerHTML;
|
|
856
|
+
}
|
|
857
|
+
setContentDirection(e) {
|
|
858
|
+
const t = e === "above", s = t ? this.classes.dirAbove : this.classes.dirBelow, i = t ? this.classes.dirBelow : this.classes.dirAbove;
|
|
859
|
+
if (this.removeClasses(this.main.main, i), this.addClasses(this.main.main, s), this.removeClasses(this.content.main, i), this.addClasses(this.content.main, s), t) {
|
|
860
|
+
const l = this.main.main.offsetHeight, n = this.content.main.offsetHeight;
|
|
861
|
+
this.content.main.style.margin = "-" + (l + n - 1) + "px 0px 0px 0px";
|
|
862
|
+
} else
|
|
863
|
+
this.content.main.style.margin = "-1px 0px 0px 0px";
|
|
864
|
+
}
|
|
865
|
+
setContentPosition() {
|
|
866
|
+
if (this.settings.contentPosition === "relative")
|
|
867
|
+
return;
|
|
868
|
+
const e = this.main.main.getBoundingClientRect();
|
|
869
|
+
let t, s;
|
|
870
|
+
if (this.settings.contentPosition === "fixed")
|
|
871
|
+
t = e.top + e.height, s = e.left;
|
|
872
|
+
else {
|
|
873
|
+
const i = this.content.main.offsetParent, l = i ? i.getBoundingClientRect() : { top: 0, left: 0 };
|
|
874
|
+
t = e.top - l.top + e.height - (i?.clientTop || 0), s = e.left - l.left - (i?.clientLeft || 0);
|
|
875
|
+
}
|
|
876
|
+
this.content.main.style.top = t + "px", this.content.main.style.left = s + "px", this.content.main.style.width = e.width + "px";
|
|
812
877
|
}
|
|
813
878
|
moveContentAbove() {
|
|
814
|
-
|
|
815
|
-
this.main.main.classList.remove(this.classes.dirBelow), this.main.main.classList.add(this.classes.dirAbove), this.content.main.classList.remove(this.classes.dirBelow), this.content.main.classList.add(this.classes.dirAbove);
|
|
816
|
-
const s = this.main.main.getBoundingClientRect();
|
|
817
|
-
this.content.main.style.margin = "-" + (e + t - 1) + "px 0px 0px 0px", this.content.main.style.top = s.top + s.height + (this.settings.contentPosition === "fixed" ? 0 : window.scrollY) + "px", this.content.main.style.left = s.left + (this.settings.contentPosition === "fixed" ? 0 : window.scrollX) + "px", this.content.main.style.width = s.width + "px";
|
|
879
|
+
this.setContentDirection("above"), this.setContentPosition();
|
|
818
880
|
}
|
|
819
881
|
moveContentBelow() {
|
|
820
|
-
this.
|
|
821
|
-
const e = this.main.main.getBoundingClientRect();
|
|
822
|
-
this.content.main.style.margin = "-1px 0px 0px 0px", this.settings.contentPosition !== "relative" && (this.content.main.style.top = e.top + e.height + (this.settings.contentPosition === "fixed" ? 0 : window.scrollY) + "px", this.content.main.style.left = e.left + (this.settings.contentPosition === "fixed" ? 0 : window.scrollX) + "px", this.content.main.style.width = e.width + "px");
|
|
882
|
+
this.setContentDirection("below"), this.setContentPosition();
|
|
823
883
|
}
|
|
824
884
|
ensureElementInView(e, t) {
|
|
825
|
-
const s = e.scrollTop + e.offsetTop, i = s + e.clientHeight, l = t.offsetTop,
|
|
826
|
-
l < s ? e.scrollTop -= s - l :
|
|
885
|
+
const s = e.scrollTop + e.offsetTop, i = s + e.clientHeight, l = t.offsetTop, n = l + t.clientHeight;
|
|
886
|
+
l < s ? e.scrollTop -= s - l : n > i && (e.scrollTop += n - i);
|
|
827
887
|
}
|
|
828
888
|
putContent() {
|
|
829
889
|
const e = this.main.main.offsetHeight, t = this.main.main.getBoundingClientRect(), s = this.content.main.offsetHeight;
|
|
@@ -833,11 +893,11 @@ class N {
|
|
|
833
893
|
updateDeselectAll() {
|
|
834
894
|
if (!this.store || !this.settings)
|
|
835
895
|
return;
|
|
836
|
-
const e = this.store.getSelectedOptions(), t = e && e.length > 0, s = this.settings.isMultiple, i = this.settings.allowDeselect, l = this.main.deselect.main,
|
|
837
|
-
i && !(s && !t) ?
|
|
896
|
+
const e = this.store.getSelectedOptions(), t = e && e.length > 0, s = this.settings.isMultiple, i = this.settings.allowDeselect, l = this.main.deselect.main, n = this.classes.hide;
|
|
897
|
+
i && !(s && !t) ? this.removeClasses(l, n) : this.addClasses(l, n);
|
|
838
898
|
}
|
|
839
899
|
}
|
|
840
|
-
class
|
|
900
|
+
class P {
|
|
841
901
|
select;
|
|
842
902
|
// Mutation observer fields
|
|
843
903
|
onValueChange;
|
|
@@ -896,28 +956,30 @@ class M {
|
|
|
896
956
|
observeCall(e) {
|
|
897
957
|
if (!this.listen)
|
|
898
958
|
return;
|
|
899
|
-
let t = !1, s = !1, i = !1;
|
|
900
|
-
for (const
|
|
901
|
-
if (
|
|
902
|
-
for (const a of Array.from(
|
|
959
|
+
let t = !1, s = !1, i = !1, l = !1;
|
|
960
|
+
for (const n of e) {
|
|
961
|
+
if (n.target === this.select && (n.attributeName === "disabled" && (s = !0), n.attributeName === "class" && (t = !0), n.type === "childList")) {
|
|
962
|
+
for (const a of Array.from(n.addedNodes))
|
|
903
963
|
if (a.nodeName === "OPTION" && a.value === this.select.value) {
|
|
904
|
-
|
|
964
|
+
l = !0;
|
|
905
965
|
break;
|
|
906
966
|
}
|
|
907
967
|
i = !0;
|
|
908
968
|
}
|
|
909
|
-
(
|
|
969
|
+
(n.target.nodeName === "OPTGROUP" || n.target.nodeName === "OPTION") && (i = !0);
|
|
910
970
|
}
|
|
911
971
|
if (t && this.onClassChange && this.onClassChange(this.select.className.split(" ")), s && this.onDisabledChange && (this.changeListen(!1), this.onDisabledChange(this.select.disabled), this.changeListen(!0)), i && this.onOptionsChange) {
|
|
912
972
|
if (this.isUpdating) {
|
|
913
973
|
if (this.select.options.length > 0) {
|
|
914
|
-
const
|
|
915
|
-
|
|
974
|
+
const n = this.getData();
|
|
975
|
+
n.length > 0 && (this.pendingOptionsChange = n);
|
|
916
976
|
}
|
|
977
|
+
l && this.select.dispatchEvent(new Event("change"));
|
|
917
978
|
return;
|
|
918
979
|
}
|
|
919
980
|
this.changeListen(!1), this.onOptionsChange(this.getData()), this.changeListen(!0);
|
|
920
981
|
}
|
|
982
|
+
l && this.select.dispatchEvent(new Event("change"));
|
|
921
983
|
}
|
|
922
984
|
// From the select element pull optgroup and options into data
|
|
923
985
|
getData() {
|
|
@@ -967,8 +1029,8 @@ class M {
|
|
|
967
1029
|
const i = s.childNodes;
|
|
968
1030
|
for (const l of i)
|
|
969
1031
|
if (l.nodeName === "OPTION") {
|
|
970
|
-
const
|
|
971
|
-
|
|
1032
|
+
const n = l;
|
|
1033
|
+
n.selected && e.push(this.getDataFromOption(n));
|
|
972
1034
|
}
|
|
973
1035
|
}
|
|
974
1036
|
if (s.nodeName === "OPTION") {
|
|
@@ -987,10 +1049,10 @@ class M {
|
|
|
987
1049
|
for (const s of t) {
|
|
988
1050
|
if (s.nodeName === "OPTGROUP") {
|
|
989
1051
|
const l = s.childNodes;
|
|
990
|
-
for (const
|
|
991
|
-
if (
|
|
992
|
-
const
|
|
993
|
-
|
|
1052
|
+
for (const n of l)
|
|
1053
|
+
if (n.nodeName === "OPTION") {
|
|
1054
|
+
const a = n;
|
|
1055
|
+
a.selected = e.includes(a.id);
|
|
994
1056
|
}
|
|
995
1057
|
}
|
|
996
1058
|
if (s.nodeName === "OPTION") {
|
|
@@ -1010,10 +1072,10 @@ class M {
|
|
|
1010
1072
|
for (const s of t) {
|
|
1011
1073
|
if (s.nodeName === "OPTGROUP") {
|
|
1012
1074
|
const l = s.childNodes;
|
|
1013
|
-
for (const
|
|
1014
|
-
if (
|
|
1015
|
-
const
|
|
1016
|
-
|
|
1075
|
+
for (const n of l)
|
|
1076
|
+
if (n.nodeName === "OPTION") {
|
|
1077
|
+
const a = n;
|
|
1078
|
+
a.selected = e.includes(a.value);
|
|
1017
1079
|
}
|
|
1018
1080
|
}
|
|
1019
1081
|
if (s.nodeName === "OPTION") {
|
|
@@ -1057,7 +1119,7 @@ class M {
|
|
|
1057
1119
|
// Find and handle labels associated with this select
|
|
1058
1120
|
setupLabelHandlers() {
|
|
1059
1121
|
const e = [], t = this.select.id;
|
|
1060
|
-
t && document.querySelectorAll(`label[for="${t}"]`).forEach((
|
|
1122
|
+
t && document.querySelectorAll(`label[for="${t}"]`).forEach((n) => e.push(n));
|
|
1061
1123
|
let s = this.select.parentElement;
|
|
1062
1124
|
for (; s && s !== document.body; ) {
|
|
1063
1125
|
if (s.tagName === "LABEL") {
|
|
@@ -1069,16 +1131,17 @@ class M {
|
|
|
1069
1131
|
Array.from(new Set(e)).forEach((l) => {
|
|
1070
1132
|
if (l.__slimSelectLabelHandler)
|
|
1071
1133
|
return;
|
|
1072
|
-
const
|
|
1073
|
-
|
|
1134
|
+
const n = (a) => {
|
|
1135
|
+
const o = a.target, h = A(o, this.select.dataset.id);
|
|
1136
|
+
a.preventDefault(), !h && this.onLabelClick && this.onLabelClick();
|
|
1074
1137
|
};
|
|
1075
|
-
l.__slimSelectLabelHandler =
|
|
1138
|
+
l.__slimSelectLabelHandler = n, l.addEventListener("click", n, { capture: !0, passive: !1 });
|
|
1076
1139
|
});
|
|
1077
1140
|
}
|
|
1078
1141
|
// Remove label handlers
|
|
1079
1142
|
removeLabelHandlers() {
|
|
1080
1143
|
const e = [], t = this.select.id;
|
|
1081
|
-
t && document.querySelectorAll(`label[for="${t}"]`).forEach((
|
|
1144
|
+
t && document.querySelectorAll(`label[for="${t}"]`).forEach((n) => e.push(n));
|
|
1082
1145
|
let s = this.select.parentElement;
|
|
1083
1146
|
for (; s && s !== document.body; ) {
|
|
1084
1147
|
if (s.tagName === "LABEL") {
|
|
@@ -1088,15 +1151,15 @@ class M {
|
|
|
1088
1151
|
s = s.parentElement;
|
|
1089
1152
|
}
|
|
1090
1153
|
Array.from(new Set(e)).forEach((l) => {
|
|
1091
|
-
const
|
|
1092
|
-
|
|
1154
|
+
const n = l.__slimSelectLabelHandler;
|
|
1155
|
+
n && (l.removeEventListener("click", n, { capture: !0 }), delete l.__slimSelectLabelHandler);
|
|
1093
1156
|
});
|
|
1094
1157
|
}
|
|
1095
1158
|
destroy() {
|
|
1096
1159
|
this.changeListen(!1), this.select.removeEventListener("change", this.valueChange), this.preventNativeSelect && (this.select.removeEventListener("click", this.preventNativeSelect, { capture: !0 }), this.preventNativeSelect = null), this.preventNativeSelectMousedown && (this.select.removeEventListener("mousedown", this.preventNativeSelectMousedown, { capture: !0 }), this.preventNativeSelectMousedown = null), this.preventNativeSelectFocus && (this.select.removeEventListener("focus", this.preventNativeSelectFocus, { capture: !0 }), this.preventNativeSelectFocus = null), this.observer && (this.observer.disconnect(), this.observer = null), this.removeLabelHandlers(), delete this.select.dataset.id, this.showUI();
|
|
1097
1160
|
}
|
|
1098
1161
|
}
|
|
1099
|
-
class
|
|
1162
|
+
class M {
|
|
1100
1163
|
id = "";
|
|
1101
1164
|
// Primary ID for the select
|
|
1102
1165
|
style = "";
|
|
@@ -1113,6 +1176,7 @@ class P {
|
|
|
1113
1176
|
alwaysOpen;
|
|
1114
1177
|
showSearch;
|
|
1115
1178
|
focusSearch;
|
|
1179
|
+
keepSearch;
|
|
1116
1180
|
ariaLabel;
|
|
1117
1181
|
searchPlaceholder;
|
|
1118
1182
|
searchText;
|
|
@@ -1134,10 +1198,10 @@ class P {
|
|
|
1134
1198
|
maxValuesMessage;
|
|
1135
1199
|
addableText;
|
|
1136
1200
|
constructor(e) {
|
|
1137
|
-
e || (e = {}), this.id = "ss-" +
|
|
1201
|
+
e || (e = {}), this.id = "ss-" + y(), this.style = e.style || "", this.class = e.class || [], this.disabled = e.disabled !== void 0 ? e.disabled : !1, this.alwaysOpen = e.alwaysOpen !== void 0 ? e.alwaysOpen : !1, this.showSearch = e.showSearch !== void 0 ? e.showSearch : !0, this.focusSearch = e.focusSearch !== void 0 ? e.focusSearch : !0, this.keepSearch = e.keepSearch !== void 0 ? e.keepSearch : !1, this.ariaLabel = e.ariaLabel || "Combobox", this.searchPlaceholder = e.searchPlaceholder || "Search...", this.searchText = e.searchText || "No Results", this.searchingText = e.searchingText || "Searching...", this.searchHighlight = e.searchHighlight !== void 0 ? e.searchHighlight : !1, this.closeOnSelect = e.closeOnSelect !== void 0 ? e.closeOnSelect : !0, this.contentLocation = e.contentLocation || document.body, this.contentPosition = e.contentPosition || "absolute", this.openPosition = e.openPosition || "auto", this.placeholderText = e.placeholderText !== void 0 ? e.placeholderText : "Select Value", this.allowDeselect = e.allowDeselect !== void 0 ? e.allowDeselect : !1, this.hideSelected = e.hideSelected !== void 0 ? e.hideSelected : !1, this.keepOrder = e.keepOrder !== void 0 ? e.keepOrder : !1, this.showOptionTooltips = e.showOptionTooltips !== void 0 ? e.showOptionTooltips : !1, 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}';
|
|
1138
1202
|
}
|
|
1139
1203
|
}
|
|
1140
|
-
class
|
|
1204
|
+
class F {
|
|
1141
1205
|
selectEl;
|
|
1142
1206
|
// Classes
|
|
1143
1207
|
settings;
|
|
@@ -1169,18 +1233,18 @@ class I {
|
|
|
1169
1233
|
e.events && e.events.error && e.events.error(new Error("Element isnt of type select"));
|
|
1170
1234
|
return;
|
|
1171
1235
|
}
|
|
1172
|
-
this.selectEl.dataset.ssid && this.destroy(), this.settings = new
|
|
1236
|
+
this.selectEl.dataset.ssid && this.destroy(), this.settings = new M(e.settings), this.cssClasses = new L(e.cssClasses);
|
|
1173
1237
|
const t = ["beforeOpen", "afterOpen", "beforeClose", "afterClose"];
|
|
1174
|
-
for (const
|
|
1175
|
-
e.events.hasOwnProperty(
|
|
1176
|
-
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
|
|
1177
|
-
this.setSelected(
|
|
1178
|
-
}, this.select.onClassChange = (
|
|
1179
|
-
this.settings.class =
|
|
1180
|
-
}, this.select.onDisabledChange = (
|
|
1181
|
-
|
|
1182
|
-
}, this.select.onOptionsChange = (
|
|
1183
|
-
this.setData(
|
|
1238
|
+
for (const a in e.events)
|
|
1239
|
+
e.events.hasOwnProperty(a) && (t.indexOf(a) !== -1 ? this.events[a] = S(e.events[a], 100) : this.events[a] = e.events[a]);
|
|
1240
|
+
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 P(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.onValueChange = (a) => {
|
|
1241
|
+
this.setSelected(a.map((o) => o.id));
|
|
1242
|
+
}, this.select.onClassChange = (a) => {
|
|
1243
|
+
this.settings.class = a, this.render.updateClassStyles();
|
|
1244
|
+
}, this.select.onDisabledChange = (a) => {
|
|
1245
|
+
a ? this.disable() : this.enable();
|
|
1246
|
+
}, this.select.onOptionsChange = (a) => {
|
|
1247
|
+
this.setData(a || []);
|
|
1184
1248
|
}, this.select.onLabelClick = () => {
|
|
1185
1249
|
this.settings.disabled || (this.settings.isOpen ? this.close() : this.open());
|
|
1186
1250
|
};
|
|
@@ -1197,8 +1261,8 @@ class I {
|
|
|
1197
1261
|
afterChange: this.events.afterChange
|
|
1198
1262
|
};
|
|
1199
1263
|
this.render = new N(this.settings, this.cssClasses, this.store, i), this.render.renderValues(), this.render.renderOptions(this.store.getData());
|
|
1200
|
-
const l = this.selectEl.getAttribute("aria-label"),
|
|
1201
|
-
l ? this.render.main.main.setAttribute("aria-label", l) :
|
|
1264
|
+
const l = this.selectEl.getAttribute("aria-label"), n = this.selectEl.getAttribute("aria-labelledby");
|
|
1265
|
+
l ? this.render.main.main.setAttribute("aria-label", l) : n && this.render.main.main.setAttribute("aria-labelledby", n), this.selectEl.parentNode && this.selectEl.parentNode.insertBefore(this.render.main.main, this.selectEl.nextSibling), window.addEventListener("resize", this.windowResize, !1), this.settings.openPosition === "auto" && window.addEventListener("scroll", this.windowScroll, !1), document.addEventListener("visibilitychange", this.windowVisibilityChange), this.settings.disabled && this.disable(), this.settings.alwaysOpen && this.open(), this.select.setupLabelHandlers(), this.selectEl.slim = this;
|
|
1202
1266
|
}
|
|
1203
1267
|
// Set to enabled and remove disabled classes
|
|
1204
1268
|
enable() {
|
|
@@ -1219,7 +1283,7 @@ class I {
|
|
|
1219
1283
|
}
|
|
1220
1284
|
this.store.setData(e);
|
|
1221
1285
|
const i = this.store.getData();
|
|
1222
|
-
this.select.updateOptions(i), this.render.renderValues(), this.render.renderOptions(i), this.events.afterChange && !
|
|
1286
|
+
this.select.updateOptions(i), this.render.renderValues(), this.render.renderOptions(i), this.events.afterChange && !O(t, this.store.getSelected()) && this.events.afterChange(this.store.getSelectedOptions());
|
|
1223
1287
|
}
|
|
1224
1288
|
getSelected() {
|
|
1225
1289
|
let e = this.store.getSelectedOptions();
|
|
@@ -1230,31 +1294,31 @@ class I {
|
|
|
1230
1294
|
const s = this.store.getSelected(), i = this.store.getDataOptions();
|
|
1231
1295
|
e = Array.isArray(e) ? e : [e];
|
|
1232
1296
|
const l = [];
|
|
1233
|
-
for (const
|
|
1234
|
-
if (i.find((o) => o.id ==
|
|
1235
|
-
l.push(
|
|
1297
|
+
for (const a of e) {
|
|
1298
|
+
if (i.find((o) => o.id == a)) {
|
|
1299
|
+
l.push(a);
|
|
1236
1300
|
continue;
|
|
1237
1301
|
}
|
|
1238
|
-
for (const o of i.filter((
|
|
1302
|
+
for (const o of i.filter((h) => h.value == a))
|
|
1239
1303
|
l.push(o.id);
|
|
1240
1304
|
}
|
|
1241
1305
|
this.store.setSelectedBy("id", l);
|
|
1242
|
-
const
|
|
1243
|
-
this.select.updateOptions(
|
|
1306
|
+
const n = this.store.getData();
|
|
1307
|
+
this.select.updateOptions(n), this.render.renderValues(), this.render.content.search.input.value !== "" ? this.search(this.render.content.search.input.value) : this.render.renderOptions(n), t && this.events.afterChange && !O(s, this.store.getSelected()) && this.events.afterChange(this.store.getSelectedOptions());
|
|
1244
1308
|
}
|
|
1245
1309
|
addOption(e) {
|
|
1246
1310
|
const t = this.store.getSelected();
|
|
1247
1311
|
this.store.getDataOptions().some((i) => i.value === (e.value ?? e.text)) || this.store.addOption(e);
|
|
1248
1312
|
const s = this.store.getData();
|
|
1249
|
-
this.select.updateOptions(s), this.render.renderValues(), this.render.renderOptions(s), this.events.afterChange && !
|
|
1313
|
+
this.select.updateOptions(s), this.render.renderValues(), this.render.renderOptions(s), this.events.afterChange && !O(t, this.store.getSelected()) && this.events.afterChange(this.store.getSelectedOptions());
|
|
1250
1314
|
}
|
|
1251
1315
|
open() {
|
|
1252
|
-
this.settings.disabled || this.settings.isOpen || (this.events.beforeOpen && this.events.beforeOpen(), this.render.open(), this.settings.showSearch && this.settings.focusSearch && this.render.searchFocus(), this.settings.isOpen = !0, this.openTimeout = setTimeout(() => {
|
|
1316
|
+
this.settings.disabled || this.settings.isOpen || (this.closeTimeout && (clearTimeout(this.closeTimeout), this.closeTimeout = null), this.events.beforeOpen && this.events.beforeOpen(), this.render.open(), this.settings.showSearch && this.settings.focusSearch && this.render.searchFocus(), this.settings.isOpen = !0, this.openTimeout = setTimeout(() => {
|
|
1253
1317
|
this.events.afterOpen && this.events.afterOpen(), this.settings.isOpen && (this.settings.isFullOpen = !0), document.addEventListener("click", this.documentClick);
|
|
1254
1318
|
}, this.settings.timeoutDelay), this.settings.contentPosition === "absolute" && (this.settings.intervalMove && clearInterval(this.settings.intervalMove), this.settings.intervalMove = setInterval(this.render.moveContent.bind(this.render), 500)));
|
|
1255
1319
|
}
|
|
1256
1320
|
close(e = null) {
|
|
1257
|
-
!this.settings.isOpen || this.settings.alwaysOpen || (this.events.beforeClose && this.events.beforeClose(), this.render.close(), this.render.content.search.input.value !== "" && this.search(""), this.render.mainFocus(e), this.settings.isOpen = !1, this.settings.isFullOpen = !1, this.closeTimeout = setTimeout(() => {
|
|
1321
|
+
!this.settings.isOpen || this.settings.alwaysOpen || (this.openTimeout && (clearTimeout(this.openTimeout), this.openTimeout = null), this.events.beforeClose && this.events.beforeClose(), this.render.close(), !this.settings.keepSearch && this.render.content.search.input.value !== "" && this.search(""), this.render.mainFocus(e), this.settings.isOpen = !1, this.settings.isFullOpen = !1, this.closeTimeout = setTimeout(() => {
|
|
1258
1322
|
this.events.afterClose && this.events.afterClose(), document.removeEventListener("click", this.documentClick);
|
|
1259
1323
|
}, this.settings.timeoutDelay), this.settings.intervalMove && clearInterval(this.settings.intervalMove));
|
|
1260
1324
|
}
|
|
@@ -1292,7 +1356,7 @@ class I {
|
|
|
1292
1356
|
});
|
|
1293
1357
|
// Event listener for document click
|
|
1294
1358
|
documentClick = (e) => {
|
|
1295
|
-
this.settings.isOpen && e.target && !
|
|
1359
|
+
this.settings.isOpen && e.target && !A(e.target, this.settings.id) && this.close(e.type);
|
|
1296
1360
|
};
|
|
1297
1361
|
// Event Listener for window visibility change
|
|
1298
1362
|
windowVisibilityChange = () => {
|
|
@@ -1302,7 +1366,7 @@ class I {
|
|
|
1302
1366
|
export {
|
|
1303
1367
|
g as Optgroup,
|
|
1304
1368
|
u as Option,
|
|
1305
|
-
|
|
1306
|
-
|
|
1369
|
+
M as Settings,
|
|
1370
|
+
F as default
|
|
1307
1371
|
};
|
|
1308
1372
|
//# sourceMappingURL=slimselect.es.js.map
|