slim-select 3.1.4 → 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 +93 -77
- 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 +41 -25
- 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 +159 -143
- package/dist/vue/index.umd.js +1 -1
- package/package.json +10 -10
- package/src/slim-select/index.test.ts +86 -0
- package/src/slim-select/index.ts +2 -2
- package/src/slim-select/render.ts +20 -2
- package/src/slim-select/select.ts +14 -11
- package/src/slim-select/settings.test.ts +1 -0
- package/src/slim-select/settings.ts +2 -0
package/dist/slimselect.es.js
CHANGED
|
@@ -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 O(p, e = 50, t = !1) {
|
|
78
78
|
let s;
|
|
79
79
|
return function(...i) {
|
|
80
80
|
const l = self, a = () => {
|
|
@@ -330,9 +330,21 @@ class N {
|
|
|
330
330
|
}
|
|
331
331
|
}
|
|
332
332
|
close() {
|
|
333
|
-
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")
|
|
333
|
+
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
|
+
const e = this.getAnimationTiming();
|
|
335
|
+
setTimeout(() => {
|
|
334
336
|
this.main.main.classList.remove(this.classes.dirAbove, this.classes.dirBelow), this.content.main.classList.remove(this.classes.dirAbove, this.classes.dirBelow);
|
|
335
|
-
},
|
|
337
|
+
}, e);
|
|
338
|
+
}
|
|
339
|
+
getAnimationTiming() {
|
|
340
|
+
const t = getComputedStyle(this.content.main).getPropertyValue("--ss-animation-timing").trim();
|
|
341
|
+
if (t) {
|
|
342
|
+
if (t.endsWith("ms"))
|
|
343
|
+
return parseFloat(t);
|
|
344
|
+
if (t.endsWith("s"))
|
|
345
|
+
return parseFloat(t) * 1e3;
|
|
346
|
+
}
|
|
347
|
+
return 200;
|
|
336
348
|
}
|
|
337
349
|
updateClassStyles() {
|
|
338
350
|
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)
|
|
@@ -535,7 +547,7 @@ class N {
|
|
|
535
547
|
main: e,
|
|
536
548
|
input: t
|
|
537
549
|
};
|
|
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 =
|
|
550
|
+
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 = O((l) => {
|
|
539
551
|
this.callbacks.search(l.target.value);
|
|
540
552
|
}, 100), t.onkeydown = (l) => {
|
|
541
553
|
switch (l.key) {
|
|
@@ -597,7 +609,7 @@ class N {
|
|
|
597
609
|
return i;
|
|
598
610
|
}
|
|
599
611
|
searchFocus() {
|
|
600
|
-
this.content.search.input.focus();
|
|
612
|
+
this.content.search.input.focus({ preventScroll: !0 });
|
|
601
613
|
}
|
|
602
614
|
getOptions(e = !1, t = !1, s = !1) {
|
|
603
615
|
let i = "." + this.classes.option;
|
|
@@ -707,9 +719,9 @@ class N {
|
|
|
707
719
|
m.preventDefault(), m.stopPropagation();
|
|
708
720
|
const v = this.store.getSelected();
|
|
709
721
|
if (c) {
|
|
710
|
-
const w = v.filter((
|
|
722
|
+
const w = v.filter((S) => {
|
|
711
723
|
for (const b of s.options)
|
|
712
|
-
if (
|
|
724
|
+
if (S === b.id)
|
|
713
725
|
return !1;
|
|
714
726
|
return !0;
|
|
715
727
|
});
|
|
@@ -717,10 +729,10 @@ class N {
|
|
|
717
729
|
return;
|
|
718
730
|
} else {
|
|
719
731
|
let w = s.options.map((b) => b.id).filter((b) => b !== void 0);
|
|
720
|
-
const
|
|
732
|
+
const S = v.concat(w);
|
|
721
733
|
for (const b of s.options)
|
|
722
734
|
b.id && !this.store.getOptionByID(b.id) && this.callbacks.addOption(new u(b));
|
|
723
|
-
this.callbacks.setSelected(
|
|
735
|
+
this.callbacks.setSelected(S, !0);
|
|
724
736
|
return;
|
|
725
737
|
}
|
|
726
738
|
}), n.appendChild(o);
|
|
@@ -769,7 +781,7 @@ class N {
|
|
|
769
781
|
if (s.shiftKey && this.lastSelectedOption) {
|
|
770
782
|
const d = this.store.getDataOptions(), m = d.findIndex((w) => w.id === this.lastSelectedOption.id), v = d.findIndex((w) => w.id === e.id);
|
|
771
783
|
if (m >= 0 && v >= 0) {
|
|
772
|
-
const w = Math.min(m, v),
|
|
784
|
+
const w = Math.min(m, v), S = Math.max(m, v), y = d.slice(w, S + 1).filter((x) => !c.find((E) => E.id === x.id));
|
|
773
785
|
c.length + y.length <= this.settings.maxSelected ? r = c.concat(y) : r = c;
|
|
774
786
|
} else
|
|
775
787
|
r = c;
|
|
@@ -896,28 +908,30 @@ class M {
|
|
|
896
908
|
observeCall(e) {
|
|
897
909
|
if (!this.listen)
|
|
898
910
|
return;
|
|
899
|
-
let t = !1, s = !1, i = !1;
|
|
900
|
-
for (const
|
|
901
|
-
if (
|
|
902
|
-
for (const
|
|
903
|
-
if (
|
|
904
|
-
|
|
911
|
+
let t = !1, s = !1, i = !1, l = !1;
|
|
912
|
+
for (const a of e) {
|
|
913
|
+
if (a.target === this.select && (a.attributeName === "disabled" && (s = !0), a.attributeName === "class" && (t = !0), a.type === "childList")) {
|
|
914
|
+
for (const n of Array.from(a.addedNodes))
|
|
915
|
+
if (n.nodeName === "OPTION" && n.value === this.select.value) {
|
|
916
|
+
l = !0;
|
|
905
917
|
break;
|
|
906
918
|
}
|
|
907
919
|
i = !0;
|
|
908
920
|
}
|
|
909
|
-
(
|
|
921
|
+
(a.target.nodeName === "OPTGROUP" || a.target.nodeName === "OPTION") && (i = !0);
|
|
910
922
|
}
|
|
911
923
|
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
924
|
if (this.isUpdating) {
|
|
913
925
|
if (this.select.options.length > 0) {
|
|
914
|
-
const
|
|
915
|
-
|
|
926
|
+
const a = this.getData();
|
|
927
|
+
a.length > 0 && (this.pendingOptionsChange = a);
|
|
916
928
|
}
|
|
929
|
+
l && this.select.dispatchEvent(new Event("change"));
|
|
917
930
|
return;
|
|
918
931
|
}
|
|
919
932
|
this.changeListen(!1), this.onOptionsChange(this.getData()), this.changeListen(!0);
|
|
920
933
|
}
|
|
934
|
+
l && this.select.dispatchEvent(new Event("change"));
|
|
921
935
|
}
|
|
922
936
|
// From the select element pull optgroup and options into data
|
|
923
937
|
getData() {
|
|
@@ -1070,7 +1084,8 @@ class M {
|
|
|
1070
1084
|
if (l.__slimSelectLabelHandler)
|
|
1071
1085
|
return;
|
|
1072
1086
|
const a = (n) => {
|
|
1073
|
-
|
|
1087
|
+
const o = n.target;
|
|
1088
|
+
n.preventDefault(), o === l && this.onLabelClick && this.onLabelClick();
|
|
1074
1089
|
};
|
|
1075
1090
|
l.__slimSelectLabelHandler = a, l.addEventListener("click", a, { capture: !0, passive: !1 });
|
|
1076
1091
|
});
|
|
@@ -1113,6 +1128,7 @@ class P {
|
|
|
1113
1128
|
alwaysOpen;
|
|
1114
1129
|
showSearch;
|
|
1115
1130
|
focusSearch;
|
|
1131
|
+
keepSearch;
|
|
1116
1132
|
ariaLabel;
|
|
1117
1133
|
searchPlaceholder;
|
|
1118
1134
|
searchText;
|
|
@@ -1134,7 +1150,7 @@ class P {
|
|
|
1134
1150
|
maxValuesMessage;
|
|
1135
1151
|
addableText;
|
|
1136
1152
|
constructor(e) {
|
|
1137
|
-
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}';
|
|
1153
|
+
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}';
|
|
1138
1154
|
}
|
|
1139
1155
|
}
|
|
1140
1156
|
class I {
|
|
@@ -1172,7 +1188,7 @@ class I {
|
|
|
1172
1188
|
this.selectEl.dataset.ssid && this.destroy(), this.settings = new P(e.settings), this.cssClasses = new A(e.cssClasses);
|
|
1173
1189
|
const t = ["beforeOpen", "afterOpen", "beforeClose", "afterClose"];
|
|
1174
1190
|
for (const n in e.events)
|
|
1175
|
-
e.events.hasOwnProperty(n) && (t.indexOf(n) !== -1 ? this.events[n] =
|
|
1191
|
+
e.events.hasOwnProperty(n) && (t.indexOf(n) !== -1 ? this.events[n] = O(e.events[n], 100) : this.events[n] = e.events[n]);
|
|
1176
1192
|
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) => {
|
|
1177
1193
|
this.setSelected(n.map((o) => o.id));
|
|
1178
1194
|
}, this.select.onClassChange = (n) => {
|
|
@@ -1254,7 +1270,7 @@ class I {
|
|
|
1254
1270
|
}, 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
1271
|
}
|
|
1256
1272
|
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(() => {
|
|
1273
|
+
!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(() => {
|
|
1258
1274
|
this.events.afterClose && this.events.afterClose(), document.removeEventListener("click", this.documentClick);
|
|
1259
1275
|
}, this.settings.timeoutDelay), this.settings.intervalMove && clearInterval(this.settings.intervalMove));
|
|
1260
1276
|
}
|
|
@@ -1283,11 +1299,11 @@ class I {
|
|
|
1283
1299
|
destroy() {
|
|
1284
1300
|
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();
|
|
1285
1301
|
}
|
|
1286
|
-
windowResize =
|
|
1302
|
+
windowResize = O(() => {
|
|
1287
1303
|
!this.settings.isOpen && !this.settings.isFullOpen || this.render.moveContent();
|
|
1288
1304
|
});
|
|
1289
1305
|
// Event listener for window scrolling
|
|
1290
|
-
windowScroll =
|
|
1306
|
+
windowScroll = O(() => {
|
|
1291
1307
|
!this.settings.isOpen && !this.settings.isFullOpen || this.render.moveContent();
|
|
1292
1308
|
});
|
|
1293
1309
|
// Event listener for document click
|