slim-select 3.0.6 → 3.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +4 -3
- package/dist/index.d.ts +8 -0
- package/dist/react/index.d.ts +8 -0
- package/dist/react/index.js +415 -328
- package/dist/react/index.umd.js +4 -4
- package/dist/slimselect.cjs.js +1 -1
- package/dist/slimselect.cjs.js.map +1 -1
- package/dist/slimselect.es.js +108 -39
- 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 +139 -54
- package/dist/vue/index.umd.js +1 -1
- package/package.json +2 -1
- package/src/slim-select/index.test.ts +356 -0
- package/src/slim-select/index.ts +17 -2
- package/src/slim-select/react/react.test.tsx +498 -0
- package/src/slim-select/react/react.tsx +102 -5
- package/src/slim-select/select.test.ts +234 -0
- package/src/slim-select/select.ts +196 -0
- package/src/slim-select/vue/vue.test.ts +259 -0
- package/src/slim-select/vue/vue.vue +85 -25
- package/vitest.config.ts +3 -2
package/dist/slimselect.es.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
class
|
|
1
|
+
class A {
|
|
2
2
|
main;
|
|
3
3
|
// Placeholder
|
|
4
4
|
placeholder;
|
|
@@ -62,7 +62,7 @@ class E {
|
|
|
62
62
|
e || (e = {}), this.main = e.main || "ss-main", this.placeholder = e.placeholder || "ss-placeholder", this.values = e.values || "ss-values", this.single = e.single || "ss-single", this.max = e.max || "ss-max", this.value = e.value || "ss-value", this.valueText = e.valueText || "ss-value-text", this.valueDelete = e.valueDelete || "ss-value-delete", this.valueOut = e.valueOut || "ss-value-out", this.deselect = e.deselect || "ss-deselect", this.deselectPath = e.deselectPath || "M10,10 L90,90 M10,90 L90,10", this.arrow = e.arrow || "ss-arrow", this.arrowClose = e.arrowClose || "M10,30 L50,70 L90,30", this.arrowOpen = e.arrowOpen || "M10,70 L50,30 L90,70", this.content = e.content || "ss-content", this.contentOpen = e.contentOpen || "ss-open", this.dirAbove = e.dirAbove || "ss-dir-above", this.dirBelow = e.dirBelow || "ss-dir-below", this.search = e.search || "ss-search", this.searchHighlighter = e.searchHighlighter || "ss-search-highlight", this.searching = e.searching || "ss-searching", this.addable = e.addable || "ss-addable", this.addablePath = e.addablePath || "M50,10 L50,90 M10,50 L90,50", this.list = e.list || "ss-list", this.optgroup = e.optgroup || "ss-optgroup", this.optgroupLabel = e.optgroupLabel || "ss-optgroup-label", this.optgroupLabelText = e.optgroupLabelText || "ss-optgroup-label-text", this.optgroupActions = e.optgroupActions || "ss-optgroup-actions", this.optgroupSelectAll = e.optgroupSelectAll || "ss-selectall", 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 = e.optgroupClosable || "ss-closable", this.option = e.option || "ss-option", this.optionDelete = e.optionDelete || "M10,10 L90,90 M10,90 L90,10", this.highlighted = e.highlighted || "ss-highlighted", this.mainOpen = e.mainOpen || "ss-open", this.close = e.close || "ss-close", this.selected = e.selected || "ss-selected", this.error = e.error || "ss-error", this.disabled = e.disabled || "ss-disabled", this.hide = e.hide || "ss-hide";
|
|
63
63
|
}
|
|
64
64
|
}
|
|
65
|
-
function
|
|
65
|
+
function C() {
|
|
66
66
|
return Math.random().toString(36).substring(2, 10);
|
|
67
67
|
}
|
|
68
68
|
function T(p, e) {
|
|
@@ -74,7 +74,7 @@ function T(p, e) {
|
|
|
74
74
|
}
|
|
75
75
|
return t(p, e) || s(p, e);
|
|
76
76
|
}
|
|
77
|
-
function
|
|
77
|
+
function S(p, e = 50, t = !1) {
|
|
78
78
|
let s;
|
|
79
79
|
return function(...i) {
|
|
80
80
|
const l = self, a = () => {
|
|
@@ -83,7 +83,7 @@ function C(p, e = 50, t = !1) {
|
|
|
83
83
|
clearTimeout(s), s = setTimeout(a, e), n && p.apply(l, i);
|
|
84
84
|
};
|
|
85
85
|
}
|
|
86
|
-
function
|
|
86
|
+
function L(p, e) {
|
|
87
87
|
return JSON.stringify(p) === JSON.stringify(e);
|
|
88
88
|
}
|
|
89
89
|
function D(p) {
|
|
@@ -105,7 +105,7 @@ class u {
|
|
|
105
105
|
data;
|
|
106
106
|
mandatory;
|
|
107
107
|
constructor(e) {
|
|
108
|
-
this.id = !e.id || e.id === "" ?
|
|
108
|
+
this.id = !e.id || e.id === "" ? C() : 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
109
|
}
|
|
110
110
|
}
|
|
111
111
|
class g {
|
|
@@ -116,7 +116,7 @@ class g {
|
|
|
116
116
|
closable;
|
|
117
117
|
options;
|
|
118
118
|
constructor(e) {
|
|
119
|
-
if (this.id = !e.id || e.id === "" ?
|
|
119
|
+
if (this.id = !e.id || e.id === "" ? C() : 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
120
|
for (const t of e.options)
|
|
121
121
|
this.options.push(new u(t));
|
|
122
122
|
}
|
|
@@ -535,7 +535,7 @@ class N {
|
|
|
535
535
|
main: e,
|
|
536
536
|
input: t
|
|
537
537
|
};
|
|
538
|
-
if (this.settings.showSearch || (e.classList.add(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 =
|
|
538
|
+
if (this.settings.showSearch || (e.classList.add(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
539
|
this.callbacks.search(l.target.value);
|
|
540
540
|
}, 100), t.onkeydown = (l) => {
|
|
541
541
|
switch (l.key) {
|
|
@@ -705,21 +705,21 @@ class N {
|
|
|
705
705
|
const d = document.createElementNS("http://www.w3.org/2000/svg", "path");
|
|
706
706
|
d.setAttribute("d", this.classes.optgroupSelectAllCheck), h.appendChild(d), o.addEventListener("click", (m) => {
|
|
707
707
|
m.preventDefault(), m.stopPropagation();
|
|
708
|
-
const
|
|
708
|
+
const v = this.store.getSelected();
|
|
709
709
|
if (c) {
|
|
710
|
-
const w =
|
|
711
|
-
for (const
|
|
712
|
-
if (O ===
|
|
710
|
+
const w = v.filter((O) => {
|
|
711
|
+
for (const b of s.options)
|
|
712
|
+
if (O === b.id)
|
|
713
713
|
return !1;
|
|
714
714
|
return !0;
|
|
715
715
|
});
|
|
716
716
|
this.callbacks.setSelected(w, !0);
|
|
717
717
|
return;
|
|
718
718
|
} else {
|
|
719
|
-
let w = s.options.map((
|
|
720
|
-
const O =
|
|
721
|
-
for (const
|
|
722
|
-
|
|
719
|
+
let w = s.options.map((b) => b.id).filter((b) => b !== void 0);
|
|
720
|
+
const O = v.concat(w);
|
|
721
|
+
for (const b of s.options)
|
|
722
|
+
b.id && !this.store.getOptionByID(b.id) && this.callbacks.addOption(new u(b));
|
|
723
723
|
this.callbacks.setSelected(O, !0);
|
|
724
724
|
return;
|
|
725
725
|
}
|
|
@@ -767,9 +767,9 @@ class N {
|
|
|
767
767
|
if (this.settings.isMultiple) {
|
|
768
768
|
const h = c.some((d) => d.id === a);
|
|
769
769
|
if (s.shiftKey && this.lastSelectedOption) {
|
|
770
|
-
const d = this.store.getDataOptions(), m = d.findIndex((w) => w.id === this.lastSelectedOption.id),
|
|
771
|
-
if (m >= 0 &&
|
|
772
|
-
const w = Math.min(m,
|
|
770
|
+
const d = this.store.getDataOptions(), m = d.findIndex((w) => w.id === this.lastSelectedOption.id), v = d.findIndex((w) => w.id === e.id);
|
|
771
|
+
if (m >= 0 && v >= 0) {
|
|
772
|
+
const w = Math.min(m, v), O = Math.max(m, v), y = d.slice(w, O + 1).filter((x) => !c.find((E) => E.id === x.id));
|
|
773
773
|
c.length + y.length <= this.settings.maxSelected ? r = c.concat(y) : r = c;
|
|
774
774
|
} else
|
|
775
775
|
r = c;
|
|
@@ -801,8 +801,8 @@ class N {
|
|
|
801
801
|
const h = document.createElement("span");
|
|
802
802
|
c.split(r).forEach((d, m) => {
|
|
803
803
|
if (d && r.test(d)) {
|
|
804
|
-
const
|
|
805
|
-
|
|
804
|
+
const v = document.createElement("mark");
|
|
805
|
+
v.className = s, v.textContent = d, h.appendChild(v);
|
|
806
806
|
} else d && h.appendChild(document.createTextNode(d));
|
|
807
807
|
}), o.parentNode?.replaceChild(h, o);
|
|
808
808
|
}
|
|
@@ -844,9 +844,16 @@ class M {
|
|
|
844
844
|
onClassChange;
|
|
845
845
|
onDisabledChange;
|
|
846
846
|
onOptionsChange;
|
|
847
|
+
onLabelClick;
|
|
847
848
|
// Change observers
|
|
848
849
|
listen = !1;
|
|
849
850
|
observer = null;
|
|
851
|
+
isUpdating = !1;
|
|
852
|
+
pendingOptionsChange = null;
|
|
853
|
+
// Event handlers for preventing native select behavior (especially on iOS Safari)
|
|
854
|
+
preventNativeSelect = null;
|
|
855
|
+
preventNativeSelectMousedown = null;
|
|
856
|
+
preventNativeSelectFocus = null;
|
|
850
857
|
constructor(e) {
|
|
851
858
|
this.select = e, this.valueChange = this.valueChange.bind(this), this.select.addEventListener("change", this.valueChange, {
|
|
852
859
|
// allow bubbling of event
|
|
@@ -860,10 +867,16 @@ class M {
|
|
|
860
867
|
this.select.disabled = !0;
|
|
861
868
|
}
|
|
862
869
|
hideUI() {
|
|
863
|
-
this.select.tabIndex = -1, this.select.style.position = "absolute", this.select.style.width = "1px", this.select.style.height = "1px", this.select.style.opacity = "0", this.select.style.overflow = "hidden", this.select.style.pointerEvents = "none", this.select.style.margin = "0", this.select.style.padding = "0", this.select.style.borderWidth = "0", this.select.style.clip = "rect(0 0 0 0)", this.select.setAttribute("aria-hidden", "true")
|
|
870
|
+
this.select.tabIndex = -1, this.select.style.position = "absolute", this.select.style.width = "1px", this.select.style.height = "1px", this.select.style.opacity = "0", this.select.style.overflow = "hidden", this.select.style.pointerEvents = "none", this.select.style.margin = "0", this.select.style.padding = "0", this.select.style.borderWidth = "0", this.select.style.clip = "rect(0 0 0 0)", this.select.setAttribute("aria-hidden", "true"), this.preventNativeSelect || (this.preventNativeSelect = (e) => {
|
|
871
|
+
e.preventDefault(), e.stopPropagation(), e.stopImmediatePropagation();
|
|
872
|
+
}, this.preventNativeSelectMousedown = (e) => {
|
|
873
|
+
e.preventDefault(), e.stopPropagation(), e.stopImmediatePropagation();
|
|
874
|
+
}, this.preventNativeSelectFocus = (e) => {
|
|
875
|
+
e.preventDefault(), e.stopPropagation(), e.stopImmediatePropagation();
|
|
876
|
+
}, this.select.addEventListener("click", this.preventNativeSelect, { capture: !0, passive: !1 }), this.select.addEventListener("mousedown", this.preventNativeSelectMousedown, { capture: !0, passive: !1 }), this.select.addEventListener("focus", this.preventNativeSelectFocus, { capture: !0, passive: !1 }));
|
|
864
877
|
}
|
|
865
878
|
showUI() {
|
|
866
|
-
this.select.removeAttribute("tabindex"), this.select.style.position = "", this.select.style.width = "", this.select.style.height = "", this.select.style.opacity = "", this.select.style.overflow = "", this.select.style.pointerEvents = "", this.select.style.margin = "", this.select.style.padding = "", this.select.style.borderWidth = "", this.select.style.clip = "", this.select.removeAttribute("aria-hidden");
|
|
879
|
+
this.select.removeAttribute("tabindex"), this.select.style.position = "", this.select.style.width = "", this.select.style.height = "", this.select.style.opacity = "", this.select.style.overflow = "", this.select.style.pointerEvents = "", this.select.style.margin = "", this.select.style.padding = "", this.select.style.borderWidth = "", this.select.style.clip = "", this.select.removeAttribute("aria-hidden"), 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);
|
|
867
880
|
}
|
|
868
881
|
changeListen(e) {
|
|
869
882
|
this.listen = e, e && this.observer && this.observer.observe(this.select, {
|
|
@@ -895,7 +908,16 @@ class M {
|
|
|
895
908
|
}
|
|
896
909
|
(l.target.nodeName === "OPTGROUP" || l.target.nodeName === "OPTION") && (i = !0);
|
|
897
910
|
}
|
|
898
|
-
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
|
|
911
|
+
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
|
+
if (this.isUpdating) {
|
|
913
|
+
if (this.select.options.length > 0) {
|
|
914
|
+
const l = this.getData();
|
|
915
|
+
l.length > 0 && (this.pendingOptionsChange = l);
|
|
916
|
+
}
|
|
917
|
+
return;
|
|
918
|
+
}
|
|
919
|
+
this.changeListen(!1), this.onOptionsChange(this.getData()), this.changeListen(!0);
|
|
920
|
+
}
|
|
899
921
|
}
|
|
900
922
|
// From the select element pull optgroup and options into data
|
|
901
923
|
getData() {
|
|
@@ -1007,10 +1029,15 @@ class M {
|
|
|
1007
1029
|
})), this.changeListen(!0);
|
|
1008
1030
|
}
|
|
1009
1031
|
updateOptions(e) {
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
1032
|
+
if (!(!e || e.length === 0)) {
|
|
1033
|
+
this.isUpdating = !0, this.pendingOptionsChange = null, this.changeListen(!1), this.select.innerHTML = "";
|
|
1034
|
+
for (const t of e)
|
|
1035
|
+
t instanceof g && this.select.appendChild(this.createOptgroup(t)), t instanceof u && this.select.appendChild(this.createOption(t));
|
|
1036
|
+
if (this.select.dispatchEvent(new Event("change", { bubbles: !0 })), this.changeListen(!0), this.isUpdating = !1, this.pendingOptionsChange !== null) {
|
|
1037
|
+
const t = this.pendingOptionsChange;
|
|
1038
|
+
t.length > 0 && this.onOptionsChange ? (this.pendingOptionsChange = null, this.changeListen(!1), this.onOptionsChange(t), this.changeListen(!0)) : this.pendingOptionsChange = null;
|
|
1039
|
+
}
|
|
1040
|
+
}
|
|
1014
1041
|
}
|
|
1015
1042
|
createOptgroup(e) {
|
|
1016
1043
|
const t = document.createElement("optgroup");
|
|
@@ -1027,8 +1054,48 @@ class M {
|
|
|
1027
1054
|
t.setAttribute("data-" + D(s), e.data[s]);
|
|
1028
1055
|
}), t;
|
|
1029
1056
|
}
|
|
1057
|
+
// Find and handle labels associated with this select
|
|
1058
|
+
setupLabelHandlers() {
|
|
1059
|
+
const e = [], t = this.select.id;
|
|
1060
|
+
t && document.querySelectorAll(`label[for="${t}"]`).forEach((a) => e.push(a));
|
|
1061
|
+
let s = this.select.parentElement;
|
|
1062
|
+
for (; s && s !== document.body; ) {
|
|
1063
|
+
if (s.tagName === "LABEL") {
|
|
1064
|
+
e.push(s);
|
|
1065
|
+
break;
|
|
1066
|
+
}
|
|
1067
|
+
s = s.parentElement;
|
|
1068
|
+
}
|
|
1069
|
+
Array.from(new Set(e)).forEach((l) => {
|
|
1070
|
+
if (l.__slimSelectLabelHandler)
|
|
1071
|
+
return;
|
|
1072
|
+
const a = (n) => {
|
|
1073
|
+
n.preventDefault(), n.stopPropagation(), this.onLabelClick && setTimeout(() => {
|
|
1074
|
+
this.onLabelClick();
|
|
1075
|
+
}, 0);
|
|
1076
|
+
};
|
|
1077
|
+
l.__slimSelectLabelHandler = a, l.addEventListener("click", a, { capture: !0, passive: !1 });
|
|
1078
|
+
});
|
|
1079
|
+
}
|
|
1080
|
+
// Remove label handlers
|
|
1081
|
+
removeLabelHandlers() {
|
|
1082
|
+
const e = [], t = this.select.id;
|
|
1083
|
+
t && document.querySelectorAll(`label[for="${t}"]`).forEach((a) => e.push(a));
|
|
1084
|
+
let s = this.select.parentElement;
|
|
1085
|
+
for (; s && s !== document.body; ) {
|
|
1086
|
+
if (s.tagName === "LABEL") {
|
|
1087
|
+
e.push(s);
|
|
1088
|
+
break;
|
|
1089
|
+
}
|
|
1090
|
+
s = s.parentElement;
|
|
1091
|
+
}
|
|
1092
|
+
Array.from(new Set(e)).forEach((l) => {
|
|
1093
|
+
const a = l.__slimSelectLabelHandler;
|
|
1094
|
+
a && (l.removeEventListener("click", a, { capture: !0 }), delete l.__slimSelectLabelHandler);
|
|
1095
|
+
});
|
|
1096
|
+
}
|
|
1030
1097
|
destroy() {
|
|
1031
|
-
this.changeListen(!1), this.select.removeEventListener("change", this.valueChange), this.observer && (this.observer.disconnect(), this.observer = null), delete this.select.dataset.id, this.showUI();
|
|
1098
|
+
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();
|
|
1032
1099
|
}
|
|
1033
1100
|
}
|
|
1034
1101
|
class P {
|
|
@@ -1069,7 +1136,7 @@ class P {
|
|
|
1069
1136
|
maxValuesMessage;
|
|
1070
1137
|
addableText;
|
|
1071
1138
|
constructor(e) {
|
|
1072
|
-
e || (e = {}), this.id = "ss-" +
|
|
1139
|
+
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}';
|
|
1073
1140
|
}
|
|
1074
1141
|
}
|
|
1075
1142
|
class I {
|
|
@@ -1104,18 +1171,20 @@ class I {
|
|
|
1104
1171
|
e.events && e.events.error && e.events.error(new Error("Element isnt of type select"));
|
|
1105
1172
|
return;
|
|
1106
1173
|
}
|
|
1107
|
-
this.selectEl.dataset.ssid && this.destroy(), this.settings = new P(e.settings), this.cssClasses = new
|
|
1174
|
+
this.selectEl.dataset.ssid && this.destroy(), this.settings = new P(e.settings), this.cssClasses = new A(e.cssClasses);
|
|
1108
1175
|
const t = ["beforeOpen", "afterOpen", "beforeClose", "afterClose"];
|
|
1109
1176
|
for (const n in e.events)
|
|
1110
|
-
e.events.hasOwnProperty(n) && (t.indexOf(n) !== -1 ? this.events[n] =
|
|
1111
|
-
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 M(this.selectEl), this.select.updateSelect(this.settings.id, this.settings.style, this.settings.class), this.select.hideUI(), this.select.onValueChange = (n) => {
|
|
1177
|
+
e.events.hasOwnProperty(n) && (t.indexOf(n) !== -1 ? this.events[n] = S(e.events[n], 100) : this.events[n] = e.events[n]);
|
|
1178
|
+
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 M(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 = (n) => {
|
|
1112
1179
|
this.setSelected(n.map((o) => o.id));
|
|
1113
1180
|
}, this.select.onClassChange = (n) => {
|
|
1114
1181
|
this.settings.class = n, this.render.updateClassStyles();
|
|
1115
1182
|
}, this.select.onDisabledChange = (n) => {
|
|
1116
1183
|
n ? this.disable() : this.enable();
|
|
1117
1184
|
}, this.select.onOptionsChange = (n) => {
|
|
1118
|
-
this.setData(n);
|
|
1185
|
+
this.setData(n || []);
|
|
1186
|
+
}, this.select.onLabelClick = () => {
|
|
1187
|
+
this.settings.disabled || this.open();
|
|
1119
1188
|
};
|
|
1120
1189
|
const s = e.data ? e.data : this.select.getData();
|
|
1121
1190
|
this.store = new k(this.settings.isMultiple ? "multiple" : "single", s), e.data && this.select.updateOptions(this.store.getData());
|
|
@@ -1131,7 +1200,7 @@ class I {
|
|
|
1131
1200
|
};
|
|
1132
1201
|
this.render = new N(this.settings, this.cssClasses, this.store, i), this.render.renderValues(), this.render.renderOptions(this.store.getData());
|
|
1133
1202
|
const l = this.selectEl.getAttribute("aria-label"), a = this.selectEl.getAttribute("aria-labelledby");
|
|
1134
|
-
l ? this.render.main.main.setAttribute("aria-label", l) : a && this.render.main.main.setAttribute("aria-labelledby", a), 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.selectEl.slim = this;
|
|
1203
|
+
l ? this.render.main.main.setAttribute("aria-label", l) : a && this.render.main.main.setAttribute("aria-labelledby", a), 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;
|
|
1135
1204
|
}
|
|
1136
1205
|
// Set to enabled and remove disabled classes
|
|
1137
1206
|
enable() {
|
|
@@ -1152,7 +1221,7 @@ class I {
|
|
|
1152
1221
|
}
|
|
1153
1222
|
this.store.setData(e);
|
|
1154
1223
|
const i = this.store.getData();
|
|
1155
|
-
this.select.updateOptions(i), this.render.renderValues(), this.render.renderOptions(i), this.events.afterChange && !
|
|
1224
|
+
this.select.updateOptions(i), this.render.renderValues(), this.render.renderOptions(i), this.events.afterChange && !L(t, this.store.getSelected()) && this.events.afterChange(this.store.getSelectedOptions());
|
|
1156
1225
|
}
|
|
1157
1226
|
getSelected() {
|
|
1158
1227
|
let e = this.store.getSelectedOptions();
|
|
@@ -1173,13 +1242,13 @@ class I {
|
|
|
1173
1242
|
}
|
|
1174
1243
|
this.store.setSelectedBy("id", l);
|
|
1175
1244
|
const a = this.store.getData();
|
|
1176
|
-
this.select.updateOptions(a), this.render.renderValues(), this.render.content.search.input.value !== "" ? this.search(this.render.content.search.input.value) : this.render.renderOptions(a), t && this.events.afterChange && !
|
|
1245
|
+
this.select.updateOptions(a), this.render.renderValues(), this.render.content.search.input.value !== "" ? this.search(this.render.content.search.input.value) : this.render.renderOptions(a), t && this.events.afterChange && !L(s, this.store.getSelected()) && this.events.afterChange(this.store.getSelectedOptions());
|
|
1177
1246
|
}
|
|
1178
1247
|
addOption(e) {
|
|
1179
1248
|
const t = this.store.getSelected();
|
|
1180
1249
|
this.store.getDataOptions().some((i) => i.value === (e.value ?? e.text)) || this.store.addOption(e);
|
|
1181
1250
|
const s = this.store.getData();
|
|
1182
|
-
this.select.updateOptions(s), this.render.renderValues(), this.render.renderOptions(s), this.events.afterChange && !
|
|
1251
|
+
this.select.updateOptions(s), this.render.renderValues(), this.render.renderOptions(s), this.events.afterChange && !L(t, this.store.getSelected()) && this.events.afterChange(this.store.getSelectedOptions());
|
|
1183
1252
|
}
|
|
1184
1253
|
open() {
|
|
1185
1254
|
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(() => {
|
|
@@ -1216,11 +1285,11 @@ class I {
|
|
|
1216
1285
|
destroy() {
|
|
1217
1286
|
this.openTimeout && (clearTimeout(this.openTimeout), this.openTimeout = null), this.closeTimeout && (clearTimeout(this.closeTimeout), this.closeTimeout = null), this.settings.intervalMove && (clearInterval(this.settings.intervalMove), this.settings.intervalMove = null), document.removeEventListener("click", this.documentClick), window.removeEventListener("resize", this.windowResize, !1), this.settings.openPosition === "auto" && window.removeEventListener("scroll", this.windowScroll, !1), document.removeEventListener("visibilitychange", this.windowVisibilityChange), this.store.setData([]), this.render.destroy(), this.select.destroy();
|
|
1218
1287
|
}
|
|
1219
|
-
windowResize =
|
|
1288
|
+
windowResize = S(() => {
|
|
1220
1289
|
!this.settings.isOpen && !this.settings.isFullOpen || this.render.moveContent();
|
|
1221
1290
|
});
|
|
1222
1291
|
// Event listener for window scrolling
|
|
1223
|
-
windowScroll =
|
|
1292
|
+
windowScroll = S(() => {
|
|
1224
1293
|
!this.settings.isOpen && !this.settings.isFullOpen || this.render.moveContent();
|
|
1225
1294
|
});
|
|
1226
1295
|
// Event listener for document click
|