slim-select 3.1.3 → 3.2.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 +2 -0
- package/dist/react/index.d.ts +2 -0
- package/dist/react/index.js +50 -36
- 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.es.js +42 -28
- 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 +2 -0
- package/dist/vue/index.js +138 -124
- package/dist/vue/index.umd.js +1 -1
- package/package.json +10 -10
- package/src/slim-select/index.test.ts +253 -0
- package/src/slim-select/index.ts +5 -4
- package/src/slim-select/render.ts +20 -2
- package/src/slim-select/select.ts +17 -9
- package/src/slim-select/settings.test.ts +1 -0
- package/src/slim-select/settings.ts +2 -0
package/dist/vue/index.d.ts
CHANGED
|
@@ -138,6 +138,7 @@ declare class Render {
|
|
|
138
138
|
disable(): void;
|
|
139
139
|
open(): void;
|
|
140
140
|
close(): void;
|
|
141
|
+
private getAnimationTiming;
|
|
141
142
|
updateClassStyles(): void;
|
|
142
143
|
updateAriaAttributes(): void;
|
|
143
144
|
mainDiv(): Main;
|
|
@@ -227,6 +228,7 @@ export declare class Settings {
|
|
|
227
228
|
alwaysOpen: boolean;
|
|
228
229
|
showSearch: boolean;
|
|
229
230
|
focusSearch: boolean;
|
|
231
|
+
keepSearch: boolean;
|
|
230
232
|
ariaLabel: string;
|
|
231
233
|
searchPlaceholder: string;
|
|
232
234
|
searchText: string;
|
package/dist/vue/index.js
CHANGED
|
@@ -78,10 +78,10 @@ function M(h, e) {
|
|
|
78
78
|
function O(h, e = 50, t = !1) {
|
|
79
79
|
let s;
|
|
80
80
|
return function(...i) {
|
|
81
|
-
const l = self,
|
|
81
|
+
const l = self, n = () => {
|
|
82
82
|
s = null, t || h.apply(l, i);
|
|
83
|
-
},
|
|
84
|
-
clearTimeout(s), s = setTimeout(
|
|
83
|
+
}, a = t && !s;
|
|
84
|
+
clearTimeout(s), s = setTimeout(n, e), a && h.apply(l, i);
|
|
85
85
|
};
|
|
86
86
|
}
|
|
87
87
|
function y(h, e) {
|
|
@@ -175,22 +175,22 @@ class V {
|
|
|
175
175
|
const s = this.partialToFullData(e);
|
|
176
176
|
if (t) {
|
|
177
177
|
const i = this.getSelectedOptions(), l = [];
|
|
178
|
-
i.forEach((
|
|
179
|
-
let
|
|
178
|
+
i.forEach((n) => {
|
|
179
|
+
let a = !1;
|
|
180
180
|
for (const o of s) {
|
|
181
|
-
if (o instanceof p && o.id ===
|
|
182
|
-
|
|
181
|
+
if (o instanceof p && o.id === n.id) {
|
|
182
|
+
a = !0;
|
|
183
183
|
break;
|
|
184
184
|
}
|
|
185
185
|
if (o instanceof m) {
|
|
186
186
|
for (const c of o.options)
|
|
187
|
-
if (c.id ===
|
|
188
|
-
|
|
187
|
+
if (c.id === n.id) {
|
|
188
|
+
a = !0;
|
|
189
189
|
break;
|
|
190
190
|
}
|
|
191
191
|
}
|
|
192
192
|
}
|
|
193
|
-
|
|
193
|
+
a || l.push(n);
|
|
194
194
|
}), this.data = [...l, ...s];
|
|
195
195
|
} else
|
|
196
196
|
this.data = s;
|
|
@@ -218,18 +218,18 @@ class V {
|
|
|
218
218
|
setSelectedBy(e, t) {
|
|
219
219
|
let s = null, i = !1;
|
|
220
220
|
const l = [];
|
|
221
|
-
for (let
|
|
222
|
-
if (
|
|
223
|
-
for (let o of
|
|
221
|
+
for (let a of this.data) {
|
|
222
|
+
if (a instanceof m)
|
|
223
|
+
for (let o of a.options) {
|
|
224
224
|
s || (s = o);
|
|
225
225
|
let c = o[e] || "";
|
|
226
226
|
o.selected = i ? !1 : t.includes(c), o.selected && (l.push(o), this.selectType === "single" && (i = !0));
|
|
227
227
|
}
|
|
228
|
-
|
|
228
|
+
a instanceof p && (s || (s = a), a.selected = i ? !1 : t.includes(a[e]), a.selected && (l.push(a), this.selectType === "single" && (i = !0)));
|
|
229
229
|
}
|
|
230
230
|
this.selectType === "single" && s && !i && (s.selected = !0, l.push(s));
|
|
231
|
-
const
|
|
232
|
-
this.selectedOrder =
|
|
231
|
+
const n = t.map((a) => l.find((o) => o[e] === a)?.id || "");
|
|
232
|
+
this.selectedOrder = n;
|
|
233
233
|
}
|
|
234
234
|
getSelected() {
|
|
235
235
|
return this.getSelectedOptions().map((e) => e.id);
|
|
@@ -271,11 +271,11 @@ class V {
|
|
|
271
271
|
return this.data.forEach((i) => {
|
|
272
272
|
if (i instanceof m) {
|
|
273
273
|
let l = [];
|
|
274
|
-
if (i.options.forEach((
|
|
275
|
-
(!e || e(
|
|
274
|
+
if (i.options.forEach((a) => {
|
|
275
|
+
(!e || e(a)) && (t ? l.push(new p(a)) : s.push(new p(a)));
|
|
276
276
|
}), l.length > 0) {
|
|
277
|
-
let
|
|
278
|
-
|
|
277
|
+
let a = new m(i);
|
|
278
|
+
a.options = l, s.push(a);
|
|
279
279
|
}
|
|
280
280
|
}
|
|
281
281
|
i instanceof p && (!e || e(i)) && s.push(new p(i));
|
|
@@ -331,9 +331,21 @@ class B {
|
|
|
331
331
|
}
|
|
332
332
|
}
|
|
333
333
|
close() {
|
|
334
|
-
this.main.main.setAttribute("aria-expanded", "false"), this.main.arrow.path.setAttribute("d", this.classes.arrowClose), this.content.main.classList.remove(this.classes.contentOpen), this.content.search.input.setAttribute("aria-hidden", "true"), this.main.main.removeAttribute("aria-activedescendant")
|
|
334
|
+
this.main.main.setAttribute("aria-expanded", "false"), this.main.arrow.path.setAttribute("d", this.classes.arrowClose), this.content.main.classList.remove(this.classes.contentOpen), this.content.search.input.setAttribute("aria-hidden", "true"), this.main.main.removeAttribute("aria-activedescendant");
|
|
335
|
+
const e = this.getAnimationTiming();
|
|
336
|
+
setTimeout(() => {
|
|
335
337
|
this.main.main.classList.remove(this.classes.dirAbove, this.classes.dirBelow), this.content.main.classList.remove(this.classes.dirAbove, this.classes.dirBelow);
|
|
336
|
-
},
|
|
338
|
+
}, e);
|
|
339
|
+
}
|
|
340
|
+
getAnimationTiming() {
|
|
341
|
+
const t = getComputedStyle(this.content.main).getPropertyValue("--ss-animation-timing").trim();
|
|
342
|
+
if (t) {
|
|
343
|
+
if (t.endsWith("ms"))
|
|
344
|
+
return parseFloat(t);
|
|
345
|
+
if (t.endsWith("s"))
|
|
346
|
+
return parseFloat(t) * 1e3;
|
|
347
|
+
}
|
|
348
|
+
return 200;
|
|
337
349
|
}
|
|
338
350
|
updateClassStyles() {
|
|
339
351
|
if (this.main.main.className = "", this.main.main.removeAttribute("style"), this.content.main.className = "", this.content.main.removeAttribute("style"), this.main.main.classList.add(this.classes.main), this.content.main.classList.add(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)
|
|
@@ -389,21 +401,21 @@ class B {
|
|
|
389
401
|
};
|
|
390
402
|
const l = document.createElementNS("http://www.w3.org/2000/svg", "svg");
|
|
391
403
|
l.setAttribute("viewBox", "0 0 100 100");
|
|
392
|
-
const
|
|
393
|
-
|
|
394
|
-
const
|
|
395
|
-
|
|
404
|
+
const n = document.createElementNS("http://www.w3.org/2000/svg", "path");
|
|
405
|
+
n.setAttribute("d", this.classes.deselectPath), l.appendChild(n), s.appendChild(l), e.appendChild(s);
|
|
406
|
+
const a = document.createElementNS("http://www.w3.org/2000/svg", "svg");
|
|
407
|
+
a.classList.add(this.classes.arrow), a.setAttribute("viewBox", "0 0 100 100");
|
|
396
408
|
const o = document.createElementNS("http://www.w3.org/2000/svg", "path");
|
|
397
|
-
return o.setAttribute("d", this.classes.arrowClose), this.settings.alwaysOpen &&
|
|
409
|
+
return o.setAttribute("d", this.classes.arrowClose), this.settings.alwaysOpen && a.classList.add(this.classes.hide), a.appendChild(o), e.appendChild(a), {
|
|
398
410
|
main: e,
|
|
399
411
|
values: t,
|
|
400
412
|
deselect: {
|
|
401
413
|
main: s,
|
|
402
414
|
svg: l,
|
|
403
|
-
path:
|
|
415
|
+
path: n
|
|
404
416
|
},
|
|
405
417
|
arrow: {
|
|
406
|
-
main:
|
|
418
|
+
main: a,
|
|
407
419
|
path: o
|
|
408
420
|
}
|
|
409
421
|
};
|
|
@@ -457,8 +469,8 @@ class B {
|
|
|
457
469
|
this.settings.keepOrder && (t = this.store.selectedOrderOptions(t));
|
|
458
470
|
let s = [];
|
|
459
471
|
for (let i = 0; i < e.length; i++) {
|
|
460
|
-
const l = e[i],
|
|
461
|
-
|
|
472
|
+
const l = e[i], n = l.getAttribute("data-id");
|
|
473
|
+
n && (t.filter((o) => o.id === n, !1).length || s.push(l));
|
|
462
474
|
}
|
|
463
475
|
for (const i of s)
|
|
464
476
|
i.classList.add(this.classes.valueOut), setTimeout(() => {
|
|
@@ -467,8 +479,8 @@ class B {
|
|
|
467
479
|
e = this.main.values.childNodes;
|
|
468
480
|
for (let i = 0; i < t.length; i++) {
|
|
469
481
|
let l = !0;
|
|
470
|
-
for (let
|
|
471
|
-
t[i].id === String(e[
|
|
482
|
+
for (let n = 0; n < e.length; n++)
|
|
483
|
+
t[i].id === String(e[n].dataset.id) && (l = !1);
|
|
472
484
|
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])));
|
|
473
485
|
}
|
|
474
486
|
}
|
|
@@ -478,8 +490,8 @@ class B {
|
|
|
478
490
|
const s = document.createElement("div");
|
|
479
491
|
if (s.classList.add(this.classes.valueText), s.textContent = e.text, t.appendChild(s), !e.mandatory) {
|
|
480
492
|
const i = document.createElement("div");
|
|
481
|
-
i.classList.add(this.classes.valueDelete), i.setAttribute("tabindex", "0"), i.onclick = (
|
|
482
|
-
if (
|
|
493
|
+
i.classList.add(this.classes.valueDelete), i.setAttribute("tabindex", "0"), i.onclick = (a) => {
|
|
494
|
+
if (a.preventDefault(), a.stopPropagation(), this.settings.disabled)
|
|
483
495
|
return;
|
|
484
496
|
let o = !0;
|
|
485
497
|
const c = this.store.getSelectedOptions(), r = c.filter((d) => d.selected && d.id !== e.id, !0);
|
|
@@ -496,9 +508,9 @@ class B {
|
|
|
496
508
|
};
|
|
497
509
|
const l = document.createElementNS("http://www.w3.org/2000/svg", "svg");
|
|
498
510
|
l.setAttribute("viewBox", "0 0 100 100");
|
|
499
|
-
const
|
|
500
|
-
|
|
501
|
-
|
|
511
|
+
const n = document.createElementNS("http://www.w3.org/2000/svg", "path");
|
|
512
|
+
n.setAttribute("d", this.classes.optionDelete), l.appendChild(n), i.appendChild(l), t.appendChild(i), i.onkeydown = (a) => {
|
|
513
|
+
a.key === "Enter" && i.click();
|
|
502
514
|
};
|
|
503
515
|
}
|
|
504
516
|
return t;
|
|
@@ -549,20 +561,20 @@ class B {
|
|
|
549
561
|
case "Escape":
|
|
550
562
|
return this.callbacks.close(), !1;
|
|
551
563
|
case " ":
|
|
552
|
-
const a = this.content.list.querySelector("." + this.classes.highlighted);
|
|
553
|
-
return a ? (a.click(), !1) : !0;
|
|
554
|
-
case "Enter":
|
|
555
564
|
const n = this.content.list.querySelector("." + this.classes.highlighted);
|
|
556
|
-
return n ? (n.click(), !1) :
|
|
565
|
+
return n ? (n.click(), !1) : !0;
|
|
566
|
+
case "Enter":
|
|
567
|
+
const a = this.content.list.querySelector("." + this.classes.highlighted);
|
|
568
|
+
return a ? (a.click(), !1) : this.callbacks.addable ? (s.click(), !1) : !0;
|
|
557
569
|
}
|
|
558
570
|
return !0;
|
|
559
571
|
}, e.appendChild(t), this.callbacks.addable) {
|
|
560
572
|
s.classList.add(this.classes.addable);
|
|
561
573
|
const l = document.createElementNS("http://www.w3.org/2000/svg", "svg");
|
|
562
574
|
l.setAttribute("viewBox", "0 0 100 100");
|
|
563
|
-
const
|
|
564
|
-
|
|
565
|
-
if (
|
|
575
|
+
const n = document.createElementNS("http://www.w3.org/2000/svg", "path");
|
|
576
|
+
n.setAttribute("d", this.classes.addablePath), l.appendChild(n), s.appendChild(l), s.onclick = (a) => {
|
|
577
|
+
if (a.preventDefault(), a.stopPropagation(), !this.callbacks.addable)
|
|
566
578
|
return;
|
|
567
579
|
const o = this.content.search.input.value.trim();
|
|
568
580
|
if (o === "") {
|
|
@@ -592,13 +604,13 @@ class B {
|
|
|
592
604
|
}, e.appendChild(s), i.addable = {
|
|
593
605
|
main: s,
|
|
594
606
|
svg: l,
|
|
595
|
-
path:
|
|
607
|
+
path: n
|
|
596
608
|
};
|
|
597
609
|
}
|
|
598
610
|
return i;
|
|
599
611
|
}
|
|
600
612
|
searchFocus() {
|
|
601
|
-
this.content.search.input.focus();
|
|
613
|
+
this.content.search.input.focus({ preventScroll: !0 });
|
|
602
614
|
}
|
|
603
615
|
getOptions(e = !1, t = !1, s = !1) {
|
|
604
616
|
let i = "." + this.classes.option;
|
|
@@ -625,11 +637,11 @@ class B {
|
|
|
625
637
|
}
|
|
626
638
|
for (let l = 0; l < t.length; l++)
|
|
627
639
|
if (t[l].classList.contains(this.classes.highlighted)) {
|
|
628
|
-
const
|
|
629
|
-
|
|
630
|
-
const
|
|
631
|
-
if (
|
|
632
|
-
const r =
|
|
640
|
+
const n = t[l];
|
|
641
|
+
n.classList.remove(this.classes.highlighted);
|
|
642
|
+
const a = n.parentElement;
|
|
643
|
+
if (a && a.classList.contains(this.classes.mainOpen)) {
|
|
644
|
+
const r = a.querySelector("." + this.classes.optgroupLabel);
|
|
633
645
|
r && r.click();
|
|
634
646
|
}
|
|
635
647
|
let o = t[e === "down" ? l + 1 < t.length ? l + 1 : 0 : l - 1 >= 0 ? l - 1 : t.length - 1];
|
|
@@ -684,10 +696,10 @@ class B {
|
|
|
684
696
|
i.classList.add(this.classes.optgroup);
|
|
685
697
|
const l = document.createElement("div");
|
|
686
698
|
l.classList.add(this.classes.optgroupLabel), i.appendChild(l);
|
|
687
|
-
const a = document.createElement("div");
|
|
688
|
-
a.classList.add(this.classes.optgroupLabelText), a.textContent = s.label, l.appendChild(a);
|
|
689
699
|
const n = document.createElement("div");
|
|
690
|
-
|
|
700
|
+
n.classList.add(this.classes.optgroupLabelText), n.textContent = s.label, l.appendChild(n);
|
|
701
|
+
const a = document.createElement("div");
|
|
702
|
+
if (a.classList.add(this.classes.optgroupActions), l.appendChild(a), this.settings.isMultiple && s.selectAll) {
|
|
691
703
|
const o = document.createElement("div");
|
|
692
704
|
o.classList.add(this.classes.optgroupSelectAll);
|
|
693
705
|
let c = !0;
|
|
@@ -724,7 +736,7 @@ class B {
|
|
|
724
736
|
this.callbacks.setSelected(S, !0);
|
|
725
737
|
return;
|
|
726
738
|
}
|
|
727
|
-
}),
|
|
739
|
+
}), a.appendChild(o);
|
|
728
740
|
}
|
|
729
741
|
if (s.closable !== "off") {
|
|
730
742
|
const o = document.createElement("div");
|
|
@@ -734,7 +746,7 @@ class B {
|
|
|
734
746
|
const r = document.createElementNS("http://www.w3.org/2000/svg", "path");
|
|
735
747
|
c.appendChild(r), s.options.some((d) => d.selected) || this.content.search.input.value.trim() !== "" ? (o.classList.add(this.classes.mainOpen), r.setAttribute("d", this.classes.arrowOpen)) : s.closable === "open" ? (i.classList.add(this.classes.mainOpen), r.setAttribute("d", this.classes.arrowOpen)) : s.closable === "close" && (i.classList.add(this.classes.close), r.setAttribute("d", this.classes.arrowClose)), l.addEventListener("click", (d) => {
|
|
736
748
|
d.preventDefault(), d.stopPropagation(), i.classList.contains(this.classes.close) ? (i.classList.remove(this.classes.close), i.classList.add(this.classes.mainOpen), r.setAttribute("d", this.classes.arrowOpen)) : (i.classList.remove(this.classes.mainOpen), i.classList.add(this.classes.close), r.setAttribute("d", this.classes.arrowClose));
|
|
737
|
-
}),
|
|
749
|
+
}), a.appendChild(o);
|
|
738
750
|
}
|
|
739
751
|
i.appendChild(l);
|
|
740
752
|
for (const o of s.options)
|
|
@@ -759,14 +771,14 @@ class B {
|
|
|
759
771
|
this.classes.searchHighlighter
|
|
760
772
|
) : e.html !== "" ? t.innerHTML = e.html : t.textContent = e.text, this.settings.showOptionTooltips && t.textContent && t.setAttribute("title", t.textContent), e.display || t.classList.add(this.classes.hide), e.disabled && t.classList.add(this.classes.disabled), e.selected && this.settings.hideSelected && t.classList.add(this.classes.hide), e.selected ? (t.classList.add(this.classes.selected), t.setAttribute("aria-selected", "true"), this.main.main.setAttribute("aria-activedescendant", t.id)) : (t.classList.remove(this.classes.selected), t.setAttribute("aria-selected", "false")), t.addEventListener("click", (s) => {
|
|
761
773
|
s.preventDefault(), s.stopPropagation();
|
|
762
|
-
const i = this.store.getSelected(), l = s.currentTarget,
|
|
763
|
-
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 && !
|
|
774
|
+
const i = this.store.getSelected(), l = s.currentTarget, n = String(l.dataset.id), a = s.ctrlKey || s.metaKey;
|
|
775
|
+
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)
|
|
764
776
|
return;
|
|
765
777
|
let o = !1;
|
|
766
778
|
const c = this.store.getSelectedOptions();
|
|
767
779
|
let r = [];
|
|
768
780
|
if (this.settings.isMultiple) {
|
|
769
|
-
const d = c.some((u) => u.id ===
|
|
781
|
+
const d = c.some((u) => u.id === n);
|
|
770
782
|
if (s.shiftKey && this.lastSelectedOption) {
|
|
771
783
|
const u = this.store.getDataOptions(), g = u.findIndex((w) => w.id === this.lastSelectedOption.id), v = u.findIndex((w) => w.id === e.id);
|
|
772
784
|
if (g >= 0 && v >= 0) {
|
|
@@ -774,10 +786,10 @@ class B {
|
|
|
774
786
|
c.length + L.length <= this.settings.maxSelected ? r = c.concat(L) : r = c;
|
|
775
787
|
} else
|
|
776
788
|
r = c;
|
|
777
|
-
} else
|
|
789
|
+
} else a ? (d ? r = c.filter((u) => u.id !== n) : r = c.concat(e), this.lastSelectedOption = e) : (d ? r = c.filter((u) => u.id !== n) : r = c.concat(e), this.lastSelectedOption = e);
|
|
778
790
|
}
|
|
779
791
|
if (this.settings.isMultiple || (e.selected ? r = [] : r = [e]), this.callbacks.beforeChange || (o = !0), this.callbacks.beforeChange && (this.callbacks.beforeChange(r, c) === !1 ? o = !1 : o = !0), o) {
|
|
780
|
-
this.store.getOptionByID(
|
|
792
|
+
this.store.getOptionByID(n) || this.callbacks.addOption(e), this.callbacks.setSelected(
|
|
781
793
|
r.map((u) => u.id),
|
|
782
794
|
!1
|
|
783
795
|
);
|
|
@@ -793,9 +805,9 @@ class B {
|
|
|
793
805
|
const i = t.trim();
|
|
794
806
|
if (i === "")
|
|
795
807
|
return e;
|
|
796
|
-
const l = i.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"),
|
|
797
|
-
|
|
798
|
-
const
|
|
808
|
+
const l = i.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"), n = document.createElement("div");
|
|
809
|
+
n.innerHTML = e;
|
|
810
|
+
const a = (o) => {
|
|
799
811
|
if (o.nodeType === Node.TEXT_NODE) {
|
|
800
812
|
const c = o.textContent || "", r = new RegExp("(" + l + ")", "i");
|
|
801
813
|
if (r.test(c)) {
|
|
@@ -807,9 +819,9 @@ class B {
|
|
|
807
819
|
} else u && d.appendChild(document.createTextNode(u));
|
|
808
820
|
}), o.parentNode?.replaceChild(d, o);
|
|
809
821
|
}
|
|
810
|
-
} else o.nodeType === Node.ELEMENT_NODE && Array.from(o.childNodes).forEach((c) =>
|
|
822
|
+
} else o.nodeType === Node.ELEMENT_NODE && Array.from(o.childNodes).forEach((c) => a(c));
|
|
811
823
|
};
|
|
812
|
-
return Array.from(
|
|
824
|
+
return Array.from(n.childNodes).forEach((o) => a(o)), n.innerHTML;
|
|
813
825
|
}
|
|
814
826
|
moveContentAbove() {
|
|
815
827
|
const e = this.main.main.offsetHeight, t = this.content.main.offsetHeight;
|
|
@@ -823,8 +835,8 @@ class B {
|
|
|
823
835
|
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");
|
|
824
836
|
}
|
|
825
837
|
ensureElementInView(e, t) {
|
|
826
|
-
const s = e.scrollTop + e.offsetTop, i = s + e.clientHeight, l = t.offsetTop,
|
|
827
|
-
l < s ? e.scrollTop -= s - l :
|
|
838
|
+
const s = e.scrollTop + e.offsetTop, i = s + e.clientHeight, l = t.offsetTop, n = l + t.clientHeight;
|
|
839
|
+
l < s ? e.scrollTop -= s - l : n > i && (e.scrollTop += n - i);
|
|
828
840
|
}
|
|
829
841
|
putContent() {
|
|
830
842
|
const e = this.main.main.offsetHeight, t = this.main.main.getBoundingClientRect(), s = this.content.main.offsetHeight;
|
|
@@ -834,8 +846,8 @@ class B {
|
|
|
834
846
|
updateDeselectAll() {
|
|
835
847
|
if (!this.store || !this.settings)
|
|
836
848
|
return;
|
|
837
|
-
const e = this.store.getSelectedOptions(), t = e && e.length > 0, s = this.settings.isMultiple, i = this.settings.allowDeselect, l = this.main.deselect.main,
|
|
838
|
-
i && !(s && !t) ? l.classList.remove(
|
|
849
|
+
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;
|
|
850
|
+
i && !(s && !t) ? l.classList.remove(n) : l.classList.add(n);
|
|
839
851
|
}
|
|
840
852
|
}
|
|
841
853
|
class I {
|
|
@@ -897,28 +909,30 @@ class I {
|
|
|
897
909
|
observeCall(e) {
|
|
898
910
|
if (!this.listen)
|
|
899
911
|
return;
|
|
900
|
-
let t = !1, s = !1, i = !1;
|
|
901
|
-
for (const
|
|
902
|
-
if (
|
|
903
|
-
for (const a of Array.from(
|
|
912
|
+
let t = !1, s = !1, i = !1, l = !1;
|
|
913
|
+
for (const n of e) {
|
|
914
|
+
if (n.target === this.select && (n.attributeName === "disabled" && (s = !0), n.attributeName === "class" && (t = !0), n.type === "childList")) {
|
|
915
|
+
for (const a of Array.from(n.addedNodes))
|
|
904
916
|
if (a.nodeName === "OPTION" && a.value === this.select.value) {
|
|
905
|
-
|
|
917
|
+
l = !0;
|
|
906
918
|
break;
|
|
907
919
|
}
|
|
908
920
|
i = !0;
|
|
909
921
|
}
|
|
910
|
-
(
|
|
922
|
+
(n.target.nodeName === "OPTGROUP" || n.target.nodeName === "OPTION") && (i = !0);
|
|
911
923
|
}
|
|
912
924
|
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) {
|
|
913
925
|
if (this.isUpdating) {
|
|
914
926
|
if (this.select.options.length > 0) {
|
|
915
|
-
const
|
|
916
|
-
|
|
927
|
+
const n = this.getData();
|
|
928
|
+
n.length > 0 && (this.pendingOptionsChange = n);
|
|
917
929
|
}
|
|
930
|
+
l && this.select.dispatchEvent(new Event("change"));
|
|
918
931
|
return;
|
|
919
932
|
}
|
|
920
933
|
this.changeListen(!1), this.onOptionsChange(this.getData()), this.changeListen(!0);
|
|
921
934
|
}
|
|
935
|
+
l && this.select.dispatchEvent(new Event("change"));
|
|
922
936
|
}
|
|
923
937
|
// From the select element pull optgroup and options into data
|
|
924
938
|
getData() {
|
|
@@ -968,8 +982,8 @@ class I {
|
|
|
968
982
|
const i = s.childNodes;
|
|
969
983
|
for (const l of i)
|
|
970
984
|
if (l.nodeName === "OPTION") {
|
|
971
|
-
const
|
|
972
|
-
|
|
985
|
+
const n = l;
|
|
986
|
+
n.selected && e.push(this.getDataFromOption(n));
|
|
973
987
|
}
|
|
974
988
|
}
|
|
975
989
|
if (s.nodeName === "OPTION") {
|
|
@@ -988,10 +1002,10 @@ class I {
|
|
|
988
1002
|
for (const s of t) {
|
|
989
1003
|
if (s.nodeName === "OPTGROUP") {
|
|
990
1004
|
const l = s.childNodes;
|
|
991
|
-
for (const
|
|
992
|
-
if (
|
|
993
|
-
const
|
|
994
|
-
|
|
1005
|
+
for (const n of l)
|
|
1006
|
+
if (n.nodeName === "OPTION") {
|
|
1007
|
+
const a = n;
|
|
1008
|
+
a.selected = e.includes(a.id);
|
|
995
1009
|
}
|
|
996
1010
|
}
|
|
997
1011
|
if (s.nodeName === "OPTION") {
|
|
@@ -1011,10 +1025,10 @@ class I {
|
|
|
1011
1025
|
for (const s of t) {
|
|
1012
1026
|
if (s.nodeName === "OPTGROUP") {
|
|
1013
1027
|
const l = s.childNodes;
|
|
1014
|
-
for (const
|
|
1015
|
-
if (
|
|
1016
|
-
const
|
|
1017
|
-
|
|
1028
|
+
for (const n of l)
|
|
1029
|
+
if (n.nodeName === "OPTION") {
|
|
1030
|
+
const a = n;
|
|
1031
|
+
a.selected = e.includes(a.value);
|
|
1018
1032
|
}
|
|
1019
1033
|
}
|
|
1020
1034
|
if (s.nodeName === "OPTION") {
|
|
@@ -1058,7 +1072,7 @@ class I {
|
|
|
1058
1072
|
// Find and handle labels associated with this select
|
|
1059
1073
|
setupLabelHandlers() {
|
|
1060
1074
|
const e = [], t = this.select.id;
|
|
1061
|
-
t && document.querySelectorAll(`label[for="${t}"]`).forEach((
|
|
1075
|
+
t && document.querySelectorAll(`label[for="${t}"]`).forEach((n) => e.push(n));
|
|
1062
1076
|
let s = this.select.parentElement;
|
|
1063
1077
|
for (; s && s !== document.body; ) {
|
|
1064
1078
|
if (s.tagName === "LABEL") {
|
|
@@ -1070,18 +1084,17 @@ class I {
|
|
|
1070
1084
|
Array.from(new Set(e)).forEach((l) => {
|
|
1071
1085
|
if (l.__slimSelectLabelHandler)
|
|
1072
1086
|
return;
|
|
1073
|
-
const
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
}, 0);
|
|
1087
|
+
const n = (a) => {
|
|
1088
|
+
const o = a.target;
|
|
1089
|
+
a.preventDefault(), o === l && this.onLabelClick && this.onLabelClick();
|
|
1077
1090
|
};
|
|
1078
|
-
l.__slimSelectLabelHandler =
|
|
1091
|
+
l.__slimSelectLabelHandler = n, l.addEventListener("click", n, { capture: !0, passive: !1 });
|
|
1079
1092
|
});
|
|
1080
1093
|
}
|
|
1081
1094
|
// Remove label handlers
|
|
1082
1095
|
removeLabelHandlers() {
|
|
1083
1096
|
const e = [], t = this.select.id;
|
|
1084
|
-
t && document.querySelectorAll(`label[for="${t}"]`).forEach((
|
|
1097
|
+
t && document.querySelectorAll(`label[for="${t}"]`).forEach((n) => e.push(n));
|
|
1085
1098
|
let s = this.select.parentElement;
|
|
1086
1099
|
for (; s && s !== document.body; ) {
|
|
1087
1100
|
if (s.tagName === "LABEL") {
|
|
@@ -1091,8 +1104,8 @@ class I {
|
|
|
1091
1104
|
s = s.parentElement;
|
|
1092
1105
|
}
|
|
1093
1106
|
Array.from(new Set(e)).forEach((l) => {
|
|
1094
|
-
const
|
|
1095
|
-
|
|
1107
|
+
const n = l.__slimSelectLabelHandler;
|
|
1108
|
+
n && (l.removeEventListener("click", n, { capture: !0 }), delete l.__slimSelectLabelHandler);
|
|
1096
1109
|
});
|
|
1097
1110
|
}
|
|
1098
1111
|
destroy() {
|
|
@@ -1116,6 +1129,7 @@ class H {
|
|
|
1116
1129
|
alwaysOpen;
|
|
1117
1130
|
showSearch;
|
|
1118
1131
|
focusSearch;
|
|
1132
|
+
keepSearch;
|
|
1119
1133
|
ariaLabel;
|
|
1120
1134
|
searchPlaceholder;
|
|
1121
1135
|
searchText;
|
|
@@ -1137,7 +1151,7 @@ class H {
|
|
|
1137
1151
|
maxValuesMessage;
|
|
1138
1152
|
addableText;
|
|
1139
1153
|
constructor(e) {
|
|
1140
|
-
e || (e = {}), this.id = "ss-" + C(), 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.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}';
|
|
1154
|
+
e || (e = {}), this.id = "ss-" + C(), 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}';
|
|
1141
1155
|
}
|
|
1142
1156
|
}
|
|
1143
1157
|
let F = class {
|
|
@@ -1174,18 +1188,18 @@ let F = class {
|
|
|
1174
1188
|
}
|
|
1175
1189
|
this.selectEl.dataset.ssid && this.destroy(), this.settings = new H(e.settings), this.cssClasses = new N(e.cssClasses);
|
|
1176
1190
|
const t = ["beforeOpen", "afterOpen", "beforeClose", "afterClose"];
|
|
1177
|
-
for (const
|
|
1178
|
-
e.events.hasOwnProperty(
|
|
1179
|
-
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 I(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 = (
|
|
1180
|
-
this.setSelected(
|
|
1181
|
-
}, this.select.onClassChange = (
|
|
1182
|
-
this.settings.class =
|
|
1183
|
-
}, this.select.onDisabledChange = (
|
|
1184
|
-
|
|
1185
|
-
}, this.select.onOptionsChange = (
|
|
1186
|
-
this.setData(
|
|
1191
|
+
for (const a in e.events)
|
|
1192
|
+
e.events.hasOwnProperty(a) && (t.indexOf(a) !== -1 ? this.events[a] = O(e.events[a], 100) : this.events[a] = e.events[a]);
|
|
1193
|
+
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 I(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) => {
|
|
1194
|
+
this.setSelected(a.map((o) => o.id));
|
|
1195
|
+
}, this.select.onClassChange = (a) => {
|
|
1196
|
+
this.settings.class = a, this.render.updateClassStyles();
|
|
1197
|
+
}, this.select.onDisabledChange = (a) => {
|
|
1198
|
+
a ? this.disable() : this.enable();
|
|
1199
|
+
}, this.select.onOptionsChange = (a) => {
|
|
1200
|
+
this.setData(a || []);
|
|
1187
1201
|
}, this.select.onLabelClick = () => {
|
|
1188
|
-
this.settings.disabled || this.open();
|
|
1202
|
+
this.settings.disabled || (this.settings.isOpen ? this.close() : this.open());
|
|
1189
1203
|
};
|
|
1190
1204
|
const s = e.data ? e.data : this.select.getData();
|
|
1191
1205
|
this.store = new V(this.settings.isMultiple ? "multiple" : "single", s), e.data && this.select.updateOptions(this.store.getData());
|
|
@@ -1200,8 +1214,8 @@ let F = class {
|
|
|
1200
1214
|
afterChange: this.events.afterChange
|
|
1201
1215
|
};
|
|
1202
1216
|
this.render = new B(this.settings, this.cssClasses, this.store, i), this.render.renderValues(), this.render.renderOptions(this.store.getData());
|
|
1203
|
-
const l = this.selectEl.getAttribute("aria-label"),
|
|
1204
|
-
l ? this.render.main.main.setAttribute("aria-label", l) :
|
|
1217
|
+
const l = this.selectEl.getAttribute("aria-label"), n = this.selectEl.getAttribute("aria-labelledby");
|
|
1218
|
+
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;
|
|
1205
1219
|
}
|
|
1206
1220
|
// Set to enabled and remove disabled classes
|
|
1207
1221
|
enable() {
|
|
@@ -1233,17 +1247,17 @@ let F = class {
|
|
|
1233
1247
|
const s = this.store.getSelected(), i = this.store.getDataOptions();
|
|
1234
1248
|
e = Array.isArray(e) ? e : [e];
|
|
1235
1249
|
const l = [];
|
|
1236
|
-
for (const
|
|
1237
|
-
if (i.find((o) => o.id ==
|
|
1238
|
-
l.push(
|
|
1250
|
+
for (const a of e) {
|
|
1251
|
+
if (i.find((o) => o.id == a)) {
|
|
1252
|
+
l.push(a);
|
|
1239
1253
|
continue;
|
|
1240
1254
|
}
|
|
1241
|
-
for (const o of i.filter((c) => c.value ==
|
|
1255
|
+
for (const o of i.filter((c) => c.value == a))
|
|
1242
1256
|
l.push(o.id);
|
|
1243
1257
|
}
|
|
1244
1258
|
this.store.setSelectedBy("id", l);
|
|
1245
|
-
const
|
|
1246
|
-
this.select.updateOptions(
|
|
1259
|
+
const n = this.store.getData();
|
|
1260
|
+
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 && !y(s, this.store.getSelected()) && this.events.afterChange(this.store.getSelectedOptions());
|
|
1247
1261
|
}
|
|
1248
1262
|
addOption(e) {
|
|
1249
1263
|
const t = this.store.getSelected();
|
|
@@ -1257,7 +1271,7 @@ let F = class {
|
|
|
1257
1271
|
}, 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)));
|
|
1258
1272
|
}
|
|
1259
1273
|
close(e = null) {
|
|
1260
|
-
!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(() => {
|
|
1274
|
+
!this.settings.isOpen || this.settings.alwaysOpen || (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(() => {
|
|
1261
1275
|
this.events.afterClose && this.events.afterClose(), document.removeEventListener("click", this.documentClick);
|
|
1262
1276
|
}, this.settings.timeoutDelay), this.settings.intervalMove && clearInterval(this.settings.intervalMove));
|
|
1263
1277
|
}
|
|
@@ -1384,8 +1398,8 @@ const R = E({
|
|
|
1384
1398
|
},
|
|
1385
1399
|
handleAfterChange(h, e) {
|
|
1386
1400
|
if (!this.slim) return;
|
|
1387
|
-
const t = this.multiple ? h.map((o) => o.value) : h.length > 0 ? h[0].value : "", s = this.getCleanValue(this.$props.modelValue), i = this.slim.store.getDataOptions(), l = Array.isArray(s) ? s.length > 0 && s.every((o) => i.some((c) => c.value === o)) : s !== "" && i.some((o) => o.value === s),
|
|
1388
|
-
(Array.isArray(t) && Array.isArray(this.value) ? JSON.stringify(t.sort()) !== JSON.stringify(this.value.sort()) : this.value !== t) && (l ||
|
|
1401
|
+
const t = this.multiple ? h.map((o) => o.value) : h.length > 0 ? h[0].value : "", s = this.getCleanValue(this.$props.modelValue), i = this.slim.store.getDataOptions(), l = Array.isArray(s) ? s.length > 0 && s.every((o) => i.some((c) => c.value === o)) : s !== "" && i.some((o) => o.value === s), n = Array.isArray(t) ? t.length > 0 && t.every((o) => i.some((c) => c.value === o)) : t !== "" && i.some((o) => o.value === t);
|
|
1402
|
+
(Array.isArray(t) && Array.isArray(this.value) ? JSON.stringify(t.sort()) !== JSON.stringify(this.value.sort()) : this.value !== t) && (l || n) && (this.value = t), e && e(h);
|
|
1389
1403
|
},
|
|
1390
1404
|
getCleanValue(h) {
|
|
1391
1405
|
const e = this.$props.multiple;
|
|
@@ -1395,13 +1409,13 @@ const R = E({
|
|
|
1395
1409
|
if (!this.slim || this.$props.modelValue === void 0)
|
|
1396
1410
|
return;
|
|
1397
1411
|
const e = this.getCleanValue(this.$props.modelValue), s = this.slim.getData().flatMap((l) => "label" in l ? l.options : [l]);
|
|
1398
|
-
if (!(Array.isArray(e) ? e.length > 0 && e.every((l) => s.some((
|
|
1399
|
-
const
|
|
1412
|
+
if (!(Array.isArray(e) ? e.length > 0 && e.every((l) => s.some((n) => n.value === l)) : e !== "" && s.some((l) => l.value === e)) && !Array.isArray(e) && !s.some((n) => n.placeholder)) {
|
|
1413
|
+
const n = this.slim.getData(), a = {
|
|
1400
1414
|
value: "",
|
|
1401
1415
|
text: "",
|
|
1402
1416
|
placeholder: !0
|
|
1403
1417
|
};
|
|
1404
|
-
this.slim.setData([
|
|
1418
|
+
this.slim.setData([a].concat(n));
|
|
1405
1419
|
}
|
|
1406
1420
|
this.slim.setSelected(e, h);
|
|
1407
1421
|
}
|