slim-select 4.0.7 → 4.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 +3 -0
- package/dist/react/index.js +151 -66
- package/dist/react/index.umd.js +1 -1
- package/dist/render.d.ts +18 -1
- package/dist/settings.d.ts +3 -0
- 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 +151 -66
- 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.js +151 -66
- package/dist/vue/index.umd.js +1 -1
- package/package.json +20 -20
- package/src/slim-select/slimselect.scss +89 -51
package/README.md
CHANGED
|
@@ -190,6 +190,9 @@ new SlimSelect({
|
|
|
190
190
|
maxValuesShown: 20,
|
|
191
191
|
maxValuesMessage: '{number} selected',
|
|
192
192
|
addableText: 'Press "Enter" to add {value}',
|
|
193
|
+
selectAll: false, // Multi-select: checkbox next to search
|
|
194
|
+
selectAllText: 'Select All',
|
|
195
|
+
unselectAllText: 'Unselect All',
|
|
193
196
|
modal: 'mobile', // 'off' | 'on' | 'mobile'
|
|
194
197
|
modalTitle: '' // Header above the option list in modal view
|
|
195
198
|
}
|
package/dist/react/index.js
CHANGED
|
@@ -53,7 +53,7 @@ var o = class {
|
|
|
53
53
|
constructor(e) {
|
|
54
54
|
e ||= {};
|
|
55
55
|
let t = (e = "", t = "") => `${e} ${t}`.trim();
|
|
56
|
-
this.main = t("ss-main", e.main), this.placeholder = t("ss-placeholder", e.placeholder), this.values = t("ss-values", e.values), this.single = t("ss-single", e.single), this.multiString = t("ss-multi-string", e.multiString), this.max = t("ss-max", e.max), this.value = t("ss-value", e.value), this.valueText = t("ss-value-text", e.valueText), this.valueDelete = t("ss-value-delete", e.valueDelete), this.valueOut = t("ss-value-out", e.valueOut), this.deselect = t("ss-deselect", e.deselect), this.deselectPath = e.deselectPath || "M10,10 L90,90 M10,90 L90,10", this.arrow = t("ss-arrow", e.arrow), this.arrowClose = e.arrowClose || "M10,30 L50,70 L90,30", this.arrowOpen = e.arrowOpen || "M10,70 L50,30 L90,70", this.content = t("ss-content", e.content), this.contentOpen = t("ss-open", e.contentOpen), this.dirAbove = t("ss-dir-above", e.dirAbove), this.dirBelow = t("ss-dir-below", e.dirBelow), this.search = t("ss-search", e.search), this.searchHighlighter = t("ss-search-highlight", e.searchHighlighter), this.searching = t("ss-searching", e.searching), this.status = t("ss-status", e.status), this.addable = t("ss-addable", e.addable), this.addablePath = e.addablePath || "M50,10 L50,90 M10,50 L90,50", this.list = t("ss-list", e.list), this.optgroup = t("ss-optgroup", e.optgroup), this.optgroupLabel = t("ss-optgroup-label", e.optgroupLabel), this.optgroupLabelText = t("ss-optgroup-label-text", e.optgroupLabelText), this.optgroupActions = t("ss-optgroup-actions", e.optgroupActions), this.optgroupSelectAll = t("ss-selectall", e.optgroupSelectAll), this.optgroupSelectAllBox = e.optgroupSelectAllBox || "
|
|
56
|
+
this.main = t("ss-main", e.main), this.placeholder = t("ss-placeholder", e.placeholder), this.values = t("ss-values", e.values), this.single = t("ss-single", e.single), this.multiString = t("ss-multi-string", e.multiString), this.max = t("ss-max", e.max), this.value = t("ss-value", e.value), this.valueText = t("ss-value-text", e.valueText), this.valueDelete = t("ss-value-delete", e.valueDelete), this.valueOut = t("ss-value-out", e.valueOut), this.deselect = t("ss-deselect", e.deselect), this.deselectPath = e.deselectPath || "M10,10 L90,90 M10,90 L90,10", this.arrow = t("ss-arrow", e.arrow), this.arrowClose = e.arrowClose || "M10,30 L50,70 L90,30", this.arrowOpen = e.arrowOpen || "M10,70 L50,30 L90,70", this.content = t("ss-content", e.content), this.contentOpen = t("ss-open", e.contentOpen), this.dirAbove = t("ss-dir-above", e.dirAbove), this.dirBelow = t("ss-dir-below", e.dirBelow), this.search = t("ss-search", e.search), this.searchHighlighter = t("ss-search-highlight", e.searchHighlighter), this.searching = t("ss-searching", e.searching), this.status = t("ss-status", e.status), this.addable = t("ss-addable", e.addable), this.addablePath = e.addablePath || "M50,10 L50,90 M10,50 L90,50", this.list = t("ss-list", e.list), this.optgroup = t("ss-optgroup", e.optgroup), this.optgroupLabel = t("ss-optgroup-label", e.optgroupLabel), this.optgroupLabelText = t("ss-optgroup-label-text", e.optgroupLabelText), this.optgroupActions = t("ss-optgroup-actions", e.optgroupActions), this.optgroupSelectAll = t("ss-selectall", e.optgroupSelectAll), this.optgroupSelectAllBox = e.optgroupSelectAllBox || "M15,15 L85,15 L85,85 L15,85 Z", this.optgroupSelectAllCheck = e.optgroupSelectAllCheck || "M25,50 L42,68 L75,32", this.optgroupClosable = t("ss-closable", e.optgroupClosable), this.option = t("ss-option", e.option), this.optionDelete = e.optionDelete || "M10,10 L90,90 M10,90 L90,10", this.highlighted = t("ss-highlighted", e.highlighted), this.modalOverlay = t("ss-modal-overlay", e.modalOverlay), this.modalDialog = t("ss-modal-dialog", e.modalDialog), this.modalTitle = t("ss-modal-title", e.modalTitle), this.modalClose = t("ss-modal-close", e.modalClose), this.modalContent = t("ss-modal-content", e.modalContent), this.mainOpen = t("ss-open", e.mainOpen), this.close = t("ss-close", e.close), this.selected = t("ss-selected", e.selected), this.error = t("ss-error", e.error), this.disabled = t("ss-disabled", e.disabled), this.hide = t("ss-hide", e.hide);
|
|
57
57
|
}
|
|
58
58
|
getFirst(e) {
|
|
59
59
|
return this[e].split(" ")[0];
|
|
@@ -147,10 +147,13 @@ var g = class {
|
|
|
147
147
|
maxValuesShown;
|
|
148
148
|
maxValuesMessage;
|
|
149
149
|
addableText;
|
|
150
|
+
selectAll;
|
|
151
|
+
selectAllText;
|
|
152
|
+
unselectAllText;
|
|
150
153
|
modal;
|
|
151
154
|
modalTitle;
|
|
152
155
|
constructor(e) {
|
|
153
|
-
e ||= {}, this.id = "ss-" + b(), this.style = e.style || "", this.class = e.class || [], this.disabled = e.disabled !== void 0 && e.disabled, this.alwaysOpen = e.alwaysOpen !== void 0 && e.alwaysOpen, this.showSearch = e.showSearch === void 0 || e.showSearch, this.focusSearch = e.focusSearch === void 0 || e.focusSearch, this.keepSearch = e.keepSearch !== void 0 && e.keepSearch, this.ariaLabel = e.ariaLabel || "Combobox", this.searchPlaceholder = e.searchPlaceholder || "Search...", this.searchText = e.searchText || "No Results", this.searchingText = e.searchingText || "Searching...", this.resultsText = e.resultsText || "{count} results available", this.deselectText = e.deselectText || "Clear", this.removeText = e.removeText || "Remove", this.searchHighlight = e.searchHighlight !== void 0 && e.searchHighlight, this.closeOnSelect = e.closeOnSelect === void 0 || e.closeOnSelect, this.contentLocation = e.contentLocation || document.body, this.contentPosition = e.contentPosition || "absolute", this.contentWidth = e.contentWidth || "", this.openPosition = e.openPosition || "auto", this.placeholderText = e.placeholderText === void 0 ? "Select Value" : e.placeholderText, this.allowDeselect = e.allowDeselect !== void 0 && e.allowDeselect, this.hideSelected = e.hideSelected !== void 0 && e.hideSelected, this.multiString = e.multiString !== void 0 && e.multiString, this.keepOrder = e.keepOrder !== void 0 && e.keepOrder, this.showOptionTooltips = e.showOptionTooltips !== void 0 && e.showOptionTooltips, this.minSelected = e.minSelected || 0, this.maxSelected = e.maxSelected || 1e3, this.timeoutDelay = e.timeoutDelay || 200, this.maxValuesShown = e.maxValuesShown || 20, this.maxValuesMessage = e.maxValuesMessage || "{number} selected", this.addableText = e.addableText || "Press \"Enter\" to add {value}", this.modal = e.modal || "mobile", this.modalTitle = e.modalTitle || "";
|
|
156
|
+
e ||= {}, this.id = "ss-" + b(), this.style = e.style || "", this.class = e.class || [], this.disabled = e.disabled !== void 0 && e.disabled, this.alwaysOpen = e.alwaysOpen !== void 0 && e.alwaysOpen, this.showSearch = e.showSearch === void 0 || e.showSearch, this.focusSearch = e.focusSearch === void 0 || e.focusSearch, this.keepSearch = e.keepSearch !== void 0 && e.keepSearch, this.ariaLabel = e.ariaLabel || "Combobox", this.searchPlaceholder = e.searchPlaceholder || "Search...", this.searchText = e.searchText || "No Results", this.searchingText = e.searchingText || "Searching...", this.resultsText = e.resultsText || "{count} results available", this.deselectText = e.deselectText || "Clear", this.removeText = e.removeText || "Remove", this.searchHighlight = e.searchHighlight !== void 0 && e.searchHighlight, this.closeOnSelect = e.closeOnSelect === void 0 || e.closeOnSelect, this.contentLocation = e.contentLocation || document.body, this.contentPosition = e.contentPosition || "absolute", this.contentWidth = e.contentWidth || "", this.openPosition = e.openPosition || "auto", this.placeholderText = e.placeholderText === void 0 ? "Select Value" : e.placeholderText, this.allowDeselect = e.allowDeselect !== void 0 && e.allowDeselect, this.hideSelected = e.hideSelected !== void 0 && e.hideSelected, this.multiString = e.multiString !== void 0 && e.multiString, this.keepOrder = e.keepOrder !== void 0 && e.keepOrder, this.showOptionTooltips = e.showOptionTooltips !== void 0 && e.showOptionTooltips, this.minSelected = e.minSelected || 0, this.maxSelected = e.maxSelected || 1e3, this.timeoutDelay = e.timeoutDelay || 200, this.maxValuesShown = e.maxValuesShown || 20, this.maxValuesMessage = e.maxValuesMessage || "{number} selected", this.addableText = e.addableText || "Press \"Enter\" to add {value}", this.selectAll = e.selectAll !== void 0 && e.selectAll, this.selectAllText = e.selectAllText || "Select All", this.unselectAllText = e.unselectAllText || "Unselect All", this.modal = e.modal || "mobile", this.modalTitle = e.modalTitle || "";
|
|
154
157
|
}
|
|
155
158
|
};
|
|
156
159
|
//#endregion
|
|
@@ -342,7 +345,7 @@ var N = class {
|
|
|
342
345
|
if (this.state === "closed" || this.state === "closing" || this.handlers.beforeClose && this.handlers.beforeClose(e) === !1) return !1;
|
|
343
346
|
this.cancelPending();
|
|
344
347
|
let t = ++this.generation;
|
|
345
|
-
return this.handlers.onClose && this.handlers.onClose(e), this.state = "closing", await this.waitForPhase("close", t), t === this.generation
|
|
348
|
+
return this.handlers.onClose && this.handlers.onClose(e), this.state = "closing", await this.waitForPhase("close", t), t === this.generation && (this.state = "closed", this.handlers.afterClose && this.handlers.afterClose(), this.handlers.onCloseReady && this.handlers.onCloseReady(), !0);
|
|
346
349
|
}
|
|
347
350
|
cancelPending() {
|
|
348
351
|
this.generation++, this.animationAbort?.abort(), this.animationAbort = null, this.pendingTimer &&= (clearTimeout(this.pendingTimer), null);
|
|
@@ -408,16 +411,18 @@ var N = class {
|
|
|
408
411
|
}
|
|
409
412
|
validateDataArray(e) {
|
|
410
413
|
if (!Array.isArray(e)) return /* @__PURE__ */ Error("Data must be an array");
|
|
411
|
-
for (let t of e) if (t)
|
|
412
|
-
if (
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
414
|
+
for (let t of e) if (t) {
|
|
415
|
+
if (t instanceof I || "label" in t) {
|
|
416
|
+
if (!("label" in t)) return /* @__PURE__ */ Error("Optgroup must have a label");
|
|
417
|
+
if ("options" in t && t.options) for (let e of t.options) {
|
|
418
|
+
let t = this.validateOption(e);
|
|
419
|
+
if (t) return t;
|
|
420
|
+
}
|
|
421
|
+
} else if (t instanceof F || "text" in t) {
|
|
422
|
+
let e = this.validateOption(t);
|
|
423
|
+
if (e) return e;
|
|
424
|
+
} else return /* @__PURE__ */ Error("Data object must be a valid optgroup or option");
|
|
425
|
+
}
|
|
421
426
|
return null;
|
|
422
427
|
}
|
|
423
428
|
validateOption(e) {
|
|
@@ -557,10 +562,12 @@ var N = class {
|
|
|
557
562
|
let a = [];
|
|
558
563
|
if (i.options.forEach((i) => {
|
|
559
564
|
(!e || e(i)) && (t ? a.push(n ? new F(i) : i) : r.push(n ? new F(i) : i));
|
|
560
|
-
}), a.length > 0)
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
565
|
+
}), a.length > 0) {
|
|
566
|
+
if (n) {
|
|
567
|
+
let e = new I(i);
|
|
568
|
+
e.options = a, r.push(e);
|
|
569
|
+
} else r.push(this.createOptgroupView(i, a));
|
|
570
|
+
}
|
|
564
571
|
}
|
|
565
572
|
i instanceof F && (!e || e(i)) && r.push(n ? new F(i) : i);
|
|
566
573
|
}), r;
|
|
@@ -702,7 +709,7 @@ var N = class {
|
|
|
702
709
|
close() {
|
|
703
710
|
this.main.main.setAttribute("aria-expanded", "false"), this.main.arrow.path.setAttribute("d", this.classes.arrowClose);
|
|
704
711
|
let e = this.modalSessionActive === !0;
|
|
705
|
-
this.removeClasses(this.content.main, this.classes.contentOpen), e || (this.removeClasses(this.main.main, this.classes.dirAbove), this.removeClasses(this.main.main, this.classes.dirBelow)), e && this.modalElements && this.removeClasses(this.modalElements.overlay, this.classes.contentOpen), this.modalSessionActive = null, this.content.search.input.setAttribute("aria-hidden", "true"), this.main.main.removeAttribute("aria-activedescendant");
|
|
712
|
+
this.removeClasses(this.content.main, this.classes.contentOpen), e || (this.removeClasses(this.main.main, this.classes.dirAbove), this.removeClasses(this.main.main, this.classes.dirBelow)), e && this.modalElements && this.removeClasses(this.modalElements.overlay, this.classes.contentOpen), this.modalSessionActive = null, this.content.search.input.setAttribute("aria-hidden", "true"), this.main.main.removeAttribute("aria-activedescendant"), this.clearValueChipHighlight();
|
|
706
713
|
}
|
|
707
714
|
clearDirectionClasses() {
|
|
708
715
|
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);
|
|
@@ -809,7 +816,8 @@ var N = class {
|
|
|
809
816
|
if (t.length === 0) {
|
|
810
817
|
this.main.values.innerHTML = this.placeholder().outerHTML;
|
|
811
818
|
return;
|
|
812
|
-
}
|
|
819
|
+
}
|
|
820
|
+
{
|
|
813
821
|
let e = this.main.values.querySelector("." + this.classes.getFirst("placeholder"));
|
|
814
822
|
e && e.remove();
|
|
815
823
|
}
|
|
@@ -824,7 +832,8 @@ var N = class {
|
|
|
824
832
|
let e = document.createElement("div");
|
|
825
833
|
this.addClasses(e, this.classes.max), e.textContent = this.settings.maxValuesMessage.replace("{number}", t.length.toString()), this.main.values.innerHTML = e.outerHTML;
|
|
826
834
|
return;
|
|
827
|
-
}
|
|
835
|
+
}
|
|
836
|
+
{
|
|
828
837
|
let e = this.main.values.querySelector("." + this.classes.getFirst("max"));
|
|
829
838
|
e && e.remove();
|
|
830
839
|
}
|
|
@@ -853,6 +862,38 @@ var N = class {
|
|
|
853
862
|
let e = this.store.getSelectedOptions();
|
|
854
863
|
return this.settings.keepOrder && (e = this.store.selectedOrderOptions(e)), e.slice(0, this.settings.minSelected).map((e) => e.id);
|
|
855
864
|
}
|
|
865
|
+
getValueChips() {
|
|
866
|
+
return !this.settings.isMultiple || this.settings.multiString ? [] : Array.from(this.main.values.querySelectorAll("." + this.classes.getFirst("value"))).filter((e) => {
|
|
867
|
+
if (e.classList.contains(this.classes.getFirst("valueOut"))) return !1;
|
|
868
|
+
let t = e.querySelector("." + this.classes.getFirst("valueDelete"));
|
|
869
|
+
return !!t && !t.classList.contains(this.classes.getFirst("hide"));
|
|
870
|
+
});
|
|
871
|
+
}
|
|
872
|
+
getHighlightedValueChip() {
|
|
873
|
+
return this.getValueChips().find((e) => e.classList.contains(this.classes.getFirst("highlighted"))) ?? null;
|
|
874
|
+
}
|
|
875
|
+
clearValueChipHighlight() {
|
|
876
|
+
for (let e of Array.from(this.main.values.querySelectorAll("." + this.classes.getFirst("value")))) this.removeClasses(e, this.classes.highlighted);
|
|
877
|
+
}
|
|
878
|
+
highlightValueChip(e) {
|
|
879
|
+
this.clearValueChipHighlight(), e && this.addClasses(e, this.classes.highlighted);
|
|
880
|
+
}
|
|
881
|
+
navigateValueChips(e) {
|
|
882
|
+
let t = this.getValueChips();
|
|
883
|
+
if (t.length === 0) return !1;
|
|
884
|
+
let n = this.getHighlightedValueChip(), r = n ? t.indexOf(n) : -1;
|
|
885
|
+
return e === "left" ? (r === -1 ? this.highlightValueChip(t[t.length - 1]) : r > 0 && this.highlightValueChip(t[r - 1]), !0) : r !== -1 && (r < t.length - 1 ? this.highlightValueChip(t[r + 1]) : this.clearValueChipHighlight(), !0);
|
|
886
|
+
}
|
|
887
|
+
deleteValueChip(e = !1) {
|
|
888
|
+
let t = this.getValueChips();
|
|
889
|
+
if (t.length === 0) return !1;
|
|
890
|
+
let n = this.getHighlightedValueChip();
|
|
891
|
+
if (e && !n) return !1;
|
|
892
|
+
let r = n ?? t[t.length - 1], i = r.querySelector("." + this.classes.getFirst("valueDelete"));
|
|
893
|
+
if (!i) return !1;
|
|
894
|
+
let a = t.indexOf(r), o = n ? t[a - 1] ?? t[a + 1] ?? null : null;
|
|
895
|
+
return i.click(), o && o !== r && this.main.values.contains(o) ? this.highlightValueChip(o) : this.clearValueChipHighlight(), !0;
|
|
896
|
+
}
|
|
856
897
|
updateMultipleValueDeleteVisibility() {
|
|
857
898
|
if (!this.settings.isMultiple || this.settings.multiString) return;
|
|
858
899
|
let e = !this.isAtMinSelected(), t = this.main.values.querySelectorAll("." + this.classes.getFirst("valueDelete"));
|
|
@@ -912,7 +953,8 @@ var N = class {
|
|
|
912
953
|
if (this.settings.openPosition === "down") {
|
|
913
954
|
this.moveContentBelow();
|
|
914
955
|
return;
|
|
915
|
-
}
|
|
956
|
+
}
|
|
957
|
+
if (this.settings.openPosition === "up") {
|
|
916
958
|
this.moveContentAbove();
|
|
917
959
|
return;
|
|
918
960
|
}
|
|
@@ -944,21 +986,33 @@ var N = class {
|
|
|
944
986
|
let r = {
|
|
945
987
|
main: e,
|
|
946
988
|
input: t
|
|
947
|
-
};
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
989
|
+
}, i = this.settings.selectAll && this.settings.isMultiple;
|
|
990
|
+
this.settings.showSearch || (t.readOnly = !0, i ? this.addClasses(t, this.classes.hide) : this.addClasses(e, this.classes.hide)), t.type = "search", t.id = `${this.settings.id}-search`, t.placeholder = this.settings.searchPlaceholder, t.tabIndex = -1, t.setAttribute("aria-label", this.settings.searchPlaceholder), t.setAttribute("aria-autocomplete", "list"), t.setAttribute("autocapitalize", "off"), t.setAttribute("autocomplete", "off"), t.setAttribute("autocorrect", "off"), t.setAttribute("aria-hidden", "true");
|
|
991
|
+
let a = S(() => {
|
|
992
|
+
this.callbacks.search(t.value);
|
|
993
|
+
}, 100);
|
|
994
|
+
if (t.oninput = (e) => {
|
|
995
|
+
e.target.value !== "" && this.clearValueChipHighlight(), a();
|
|
996
|
+
}, t.onkeydown = (e) => {
|
|
951
997
|
switch (e.key) {
|
|
952
998
|
case "ArrowUp":
|
|
953
|
-
case "ArrowDown": return e.key === "ArrowDown" ? this.highlight("down") : this.highlight("up"), !1;
|
|
999
|
+
case "ArrowDown": return this.clearValueChipHighlight(), e.key === "ArrowDown" ? this.highlight("down") : this.highlight("up"), !1;
|
|
1000
|
+
case "ArrowLeft":
|
|
1001
|
+
case "ArrowRight": return t.value !== "" || !this.navigateValueChips(e.key === "ArrowLeft" ? "left" : "right") || (e.preventDefault(), !1);
|
|
1002
|
+
case "Backspace": return t.value !== "" || !this.deleteValueChip() || (e.preventDefault(), !1);
|
|
1003
|
+
case "Delete": return t.value !== "" || !this.getHighlightedValueChip() || !this.deleteValueChip(!0) || (e.preventDefault(), !1);
|
|
954
1004
|
case "Tab": return this.requestClose("tab"), !0;
|
|
955
1005
|
case "Escape": return this.requestClose("escape"), !1;
|
|
956
1006
|
case "Enter":
|
|
957
|
-
let
|
|
958
|
-
return
|
|
1007
|
+
let r = this.content.list.querySelector("." + this.classes.getFirst("highlighted"));
|
|
1008
|
+
return r ? (r.click(), !1) : !this.callbacks.addable || (n.click(), !1);
|
|
959
1009
|
}
|
|
960
|
-
return !0;
|
|
961
|
-
}, e.appendChild(t),
|
|
1010
|
+
return e.key.length === 1 && this.clearValueChipHighlight(), !0;
|
|
1011
|
+
}, e.appendChild(t), i) {
|
|
1012
|
+
let t = this.createSelectAllControl(() => this.toggleGlobalSelectAll());
|
|
1013
|
+
e.appendChild(t), r.selectAll = t;
|
|
1014
|
+
}
|
|
1015
|
+
if (this.callbacks.addable) {
|
|
962
1016
|
this.addClasses(n, this.classes.addable);
|
|
963
1017
|
let t = document.createElementNS("http://www.w3.org/2000/svg", "svg");
|
|
964
1018
|
t.setAttribute("viewBox", "0 0 100 100");
|
|
@@ -983,7 +1037,7 @@ var N = class {
|
|
|
983
1037
|
}, e);
|
|
984
1038
|
}
|
|
985
1039
|
}, r = this.callbacks.addable(t);
|
|
986
|
-
r
|
|
1040
|
+
r !== !1 && r != null && (r instanceof Promise ? r.then((e) => {
|
|
987
1041
|
typeof e == "string" ? n({
|
|
988
1042
|
text: e,
|
|
989
1043
|
value: e
|
|
@@ -1086,34 +1140,24 @@ var N = class {
|
|
|
1086
1140
|
this.addClasses(i, this.classes.optgroupLabelText), i.textContent = n.label, r.appendChild(i);
|
|
1087
1141
|
let a = document.createElement("div");
|
|
1088
1142
|
if (this.addClasses(a, this.classes.optgroupActions), r.appendChild(a), this.settings.isMultiple && n.selectAll) {
|
|
1089
|
-
let e =
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
let r = document.createElement("span");
|
|
1094
|
-
r.textContent = this.optgroupSelectAllLabel(t), e.appendChild(r);
|
|
1095
|
-
let i = document.createElementNS("http://www.w3.org/2000/svg", "svg");
|
|
1096
|
-
i.setAttribute("viewBox", "0 0 100 100"), e.appendChild(i);
|
|
1097
|
-
let o = document.createElementNS("http://www.w3.org/2000/svg", "path");
|
|
1098
|
-
o.setAttribute("d", this.classes.optgroupSelectAllBox), i.appendChild(o);
|
|
1099
|
-
let s = document.createElementNS("http://www.w3.org/2000/svg", "path");
|
|
1100
|
-
s.setAttribute("d", this.classes.optgroupSelectAllCheck), i.appendChild(s), e.addEventListener("click", (e) => {
|
|
1101
|
-
e.preventDefault(), e.stopPropagation();
|
|
1102
|
-
let t = this.store.getSelected();
|
|
1103
|
-
if (this.isOptgroupAllSelected(n.options, new Set(t))) {
|
|
1104
|
-
let e = t.filter((e) => {
|
|
1143
|
+
let e = this.createSelectAllControl(() => {
|
|
1144
|
+
let e = this.store.getSelected();
|
|
1145
|
+
if (this.isOptgroupAllSelected(n.options, new Set(e))) {
|
|
1146
|
+
let t = e.filter((e) => {
|
|
1105
1147
|
for (let t of n.options) if (e === t.id) return !1;
|
|
1106
1148
|
return !0;
|
|
1107
1149
|
});
|
|
1108
|
-
this.callbacks.setSelected(
|
|
1150
|
+
this.callbacks.setSelected(t, !0);
|
|
1109
1151
|
return;
|
|
1110
|
-
}
|
|
1111
|
-
|
|
1152
|
+
}
|
|
1153
|
+
{
|
|
1154
|
+
let t = n.options.map((e) => e.id).filter((e) => e !== void 0), r = e.concat(t);
|
|
1112
1155
|
for (let e of n.options) e.id && !this.store.getOptionByID(e.id) && this.callbacks.addOption(new F(e));
|
|
1113
1156
|
this.callbacks.setSelected(r, !0);
|
|
1114
1157
|
return;
|
|
1115
1158
|
}
|
|
1116
|
-
}
|
|
1159
|
+
}, this.isOptgroupAllSelected(n.options));
|
|
1160
|
+
a.appendChild(e);
|
|
1117
1161
|
}
|
|
1118
1162
|
if (n.closable !== "off") {
|
|
1119
1163
|
let t = document.createElement("div");
|
|
@@ -1130,7 +1174,7 @@ var N = class {
|
|
|
1130
1174
|
}
|
|
1131
1175
|
n instanceof F && t.appendChild(this.option(n));
|
|
1132
1176
|
}
|
|
1133
|
-
this.content.list.appendChild(t), this.setOptionsListFullData(e), this.announce(this.settings.resultsText.replace("{count}", String(this.lastRenderedOptions.length)));
|
|
1177
|
+
this.content.list.appendChild(t), this.setOptionsListFullData(e), this.announce(this.settings.resultsText.replace("{count}", String(this.lastRenderedOptions.length))), this.updateGlobalSelectAllState();
|
|
1134
1178
|
}
|
|
1135
1179
|
canFilterOptionsInPlace() {
|
|
1136
1180
|
return this.optionsListIsFullData ? this.content.list.querySelector("." + this.classes.getFirst("option")) !== null : !1;
|
|
@@ -1151,7 +1195,7 @@ var N = class {
|
|
|
1151
1195
|
let o = a.placeholder || !a.display || a.selected && this.settings.hideSelected, s = t(a, n);
|
|
1152
1196
|
o || !s ? (this.addClasses(e, this.classes.hide), this.removeClasses(e, this.classes.highlighted)) : (this.removeClasses(e, this.classes.hide), this.setOptionElementContent(e, a, n), r.push(a)), a.selected ? (this.addClasses(e, this.classes.selected), e.setAttribute("aria-selected", "true")) : (this.removeClasses(e, this.classes.selected), e.setAttribute("aria-selected", "false"));
|
|
1153
1197
|
}
|
|
1154
|
-
this.lastRenderedOptions = r, this.updateOptgroupVisibilityAfterSearch(n), r.length === 0 ? this.updateSearchResultsMessage(0, n) : (this.removeListSearchMessage(), this.announce(this.settings.resultsText.replace("{count}", String(r.length)))), this.updateOptgroupSelectAllStates();
|
|
1198
|
+
this.lastRenderedOptions = r, this.updateOptgroupVisibilityAfterSearch(n), r.length === 0 ? this.updateSearchResultsMessage(0, n) : (this.removeListSearchMessage(), this.announce(this.settings.resultsText.replace("{count}", String(r.length)))), this.updateOptgroupSelectAllStates(), this.updateGlobalSelectAllState();
|
|
1155
1199
|
}
|
|
1156
1200
|
setOptionsListFullData(e) {
|
|
1157
1201
|
let t = this.store.getDataOptions(!1), n = e.map((e) => e instanceof F ? [e] : e.options.map((e) => new F(e))).flat();
|
|
@@ -1223,7 +1267,48 @@ var N = class {
|
|
|
1223
1267
|
let a = e.has(t);
|
|
1224
1268
|
a ? (this.addClasses(r, this.classes.selected), r.setAttribute("aria-selected", "true"), n = r) : (this.removeClasses(r, this.classes.selected), r.setAttribute("aria-selected", "false")), this.settings.hideSelected && (a ? this.addClasses(r, this.classes.hide) : (this.removeClasses(r, this.classes.hide), i.display || this.addClasses(r, this.classes.hide)));
|
|
1225
1269
|
}
|
|
1226
|
-
!this.settings.isMultiple && n ? this.main.main.setAttribute("aria-activedescendant", n.id) : !this.settings.isMultiple && e.size === 0 && this.main.main.removeAttribute("aria-activedescendant"), this.updateOptgroupSelectAllStates();
|
|
1270
|
+
!this.settings.isMultiple && n ? this.main.main.setAttribute("aria-activedescendant", n.id) : !this.settings.isMultiple && e.size === 0 && this.main.main.removeAttribute("aria-activedescendant"), this.updateOptgroupSelectAllStates(), this.updateGlobalSelectAllState();
|
|
1271
|
+
}
|
|
1272
|
+
createSelectAllControl(e, t = !1) {
|
|
1273
|
+
let n = document.createElement("div");
|
|
1274
|
+
this.addClasses(n, this.classes.optgroupSelectAll), n.setAttribute("role", "checkbox"), n.setAttribute("aria-checked", t ? "true" : "false"), n.setAttribute("aria-label", this.selectAllLabel(t)), n.tabIndex = -1, t && this.addClasses(n, this.classes.selected);
|
|
1275
|
+
let r = document.createElement("span");
|
|
1276
|
+
r.textContent = this.selectAllLabel(t), n.appendChild(r);
|
|
1277
|
+
let i = document.createElementNS("http://www.w3.org/2000/svg", "svg");
|
|
1278
|
+
i.setAttribute("viewBox", "0 0 100 100"), i.setAttribute("aria-hidden", "true"), n.appendChild(i);
|
|
1279
|
+
let a = document.createElementNS("http://www.w3.org/2000/svg", "path");
|
|
1280
|
+
a.setAttribute("d", this.classes.optgroupSelectAllBox), i.appendChild(a);
|
|
1281
|
+
let o = document.createElementNS("http://www.w3.org/2000/svg", "path");
|
|
1282
|
+
return o.setAttribute("d", this.classes.optgroupSelectAllCheck), i.appendChild(o), n.addEventListener("click", (t) => {
|
|
1283
|
+
t.preventDefault(), t.stopPropagation(), e();
|
|
1284
|
+
}), n;
|
|
1285
|
+
}
|
|
1286
|
+
getSelectableOptions() {
|
|
1287
|
+
return this.store.getDataOptions(!1).filter((e) => !e.disabled && !e.placeholder && e.display);
|
|
1288
|
+
}
|
|
1289
|
+
isGlobalAllSelected(e) {
|
|
1290
|
+
let t = this.getSelectableOptions();
|
|
1291
|
+
if (t.length === 0) return !1;
|
|
1292
|
+
let n = e || new Set(this.store.getSelected());
|
|
1293
|
+
for (let e of t) if (!n.has(e.id)) return !1;
|
|
1294
|
+
return !0;
|
|
1295
|
+
}
|
|
1296
|
+
toggleGlobalSelectAll() {
|
|
1297
|
+
let e = this.getSelectableOptions(), t = new Set(this.store.getSelected());
|
|
1298
|
+
if (this.isGlobalAllSelected(t)) {
|
|
1299
|
+
let t = new Set(e.map((e) => e.id)), n = this.store.getSelected().filter((e) => !t.has(e));
|
|
1300
|
+
this.callbacks.setSelected(n, !0);
|
|
1301
|
+
return;
|
|
1302
|
+
}
|
|
1303
|
+
this.callbacks.setSelected(e.map((e) => e.id), !0);
|
|
1304
|
+
}
|
|
1305
|
+
updateGlobalSelectAllState() {
|
|
1306
|
+
let e = this.content.search.selectAll;
|
|
1307
|
+
if (!e || !this.settings.isMultiple || !this.settings.selectAll) return;
|
|
1308
|
+
let t = this.isGlobalAllSelected();
|
|
1309
|
+
t ? this.addClasses(e, this.classes.selected) : this.removeClasses(e, this.classes.selected), e.setAttribute("aria-checked", t ? "true" : "false"), e.setAttribute("aria-label", this.selectAllLabel(t));
|
|
1310
|
+
let n = e.querySelector("span");
|
|
1311
|
+
n && (n.textContent = this.selectAllLabel(t));
|
|
1227
1312
|
}
|
|
1228
1313
|
updateOptgroupSelectAllStates() {
|
|
1229
1314
|
if (!this.settings.isMultiple) return;
|
|
@@ -1239,13 +1324,13 @@ var N = class {
|
|
|
1239
1324
|
break;
|
|
1240
1325
|
}
|
|
1241
1326
|
}
|
|
1242
|
-
i ? this.addClasses(t, this.classes.selected) : this.removeClasses(t, this.classes.selected);
|
|
1327
|
+
i ? this.addClasses(t, this.classes.selected) : this.removeClasses(t, this.classes.selected), t.setAttribute("aria-checked", i ? "true" : "false"), t.setAttribute("aria-label", this.selectAllLabel(i));
|
|
1243
1328
|
let a = t.querySelector("span");
|
|
1244
|
-
a && (a.textContent = this.
|
|
1329
|
+
a && (a.textContent = this.selectAllLabel(i));
|
|
1245
1330
|
}
|
|
1246
1331
|
}
|
|
1247
|
-
|
|
1248
|
-
return e ?
|
|
1332
|
+
selectAllLabel(e) {
|
|
1333
|
+
return e ? this.settings.unselectAllText : this.settings.selectAllText;
|
|
1249
1334
|
}
|
|
1250
1335
|
isOptgroupAllSelected(e, t) {
|
|
1251
1336
|
if (e.length === 0) return !1;
|
|
@@ -1724,9 +1809,7 @@ var U = class {
|
|
|
1724
1809
|
case "selection":
|
|
1725
1810
|
this.applySelection(e.values, e.source, e.runAfterChange !== !1);
|
|
1726
1811
|
break;
|
|
1727
|
-
case "addOption":
|
|
1728
|
-
this.applyAddOption(e.option);
|
|
1729
|
-
break;
|
|
1812
|
+
case "addOption": this.applyAddOption(e.option);
|
|
1730
1813
|
}
|
|
1731
1814
|
}
|
|
1732
1815
|
applyStructure(e, t, n = !1, r = !1) {
|
|
@@ -1777,10 +1860,12 @@ var U = class {
|
|
|
1777
1860
|
}
|
|
1778
1861
|
return !1;
|
|
1779
1862
|
};
|
|
1780
|
-
if (!c(t.getData(!1)))
|
|
1781
|
-
|
|
1782
|
-
|
|
1783
|
-
|
|
1863
|
+
if (!c(t.getData(!1))) {
|
|
1864
|
+
if (o) {
|
|
1865
|
+
let n = t.getCatalogData();
|
|
1866
|
+
c(n) || t.setData([...n, new F(e)], !0), t.snapshotCatalog();
|
|
1867
|
+
} else t.addOption(e), t.snapshotCatalog();
|
|
1868
|
+
}
|
|
1784
1869
|
let l = t.getData(!1);
|
|
1785
1870
|
if (o) {
|
|
1786
1871
|
let e = t.getSelectedOptions();
|
|
@@ -1819,7 +1904,7 @@ var U = class {
|
|
|
1819
1904
|
e.events && e.events.error && e.events.error(/* @__PURE__ */ Error("Element isnt of type select"));
|
|
1820
1905
|
return;
|
|
1821
1906
|
}
|
|
1822
|
-
this.selectEl.dataset.ssid && this.destroy(), this.settings = new g(e.settings), this.cssClasses = new o(e.cssClasses);
|
|
1907
|
+
this.selectEl.dataset.ssid && this.destroy(), this.settings = new g(e.settings), e.settings?.selectAll === void 0 && this.selectEl.dataset.selectall === "true" && (this.settings.selectAll = !0), this.cssClasses = new o(e.cssClasses);
|
|
1823
1908
|
let t = [
|
|
1824
1909
|
"beforeOpen",
|
|
1825
1910
|
"afterOpen",
|