slim-select 3.0.5 → 3.1.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.
@@ -151,7 +151,6 @@ declare class Render {
151
151
  moveContent(): void;
152
152
  searchDiv(): Search;
153
153
  searchFocus(): void;
154
- clearSearch(): void;
155
154
  getOptions(notPlaceholder?: boolean, notDisabled?: boolean, notHidden?: boolean): HTMLDivElement[];
156
155
  highlight(dir: 'up' | 'down'): void;
157
156
  listDiv(): HTMLDivElement;
@@ -184,8 +183,12 @@ declare class Select {
184
183
  onClassChange?: (classes: string[]) => void;
185
184
  onDisabledChange?: (disabled: boolean) => void;
186
185
  onOptionsChange?: (data: (Option_2 | Optgroup)[]) => void;
186
+ onLabelClick?: () => void;
187
187
  private listen;
188
188
  private observer;
189
+ private preventNativeSelect;
190
+ private preventNativeSelectMousedown;
191
+ private preventNativeSelectFocus;
189
192
  constructor(select: HTMLSelectElement);
190
193
  enable(): void;
191
194
  disable(): void;
@@ -205,6 +208,8 @@ declare class Select {
205
208
  updateOptions(data: (Option_2 | Optgroup)[]): void;
206
209
  createOptgroup(optgroup: Optgroup): HTMLOptGroupElement;
207
210
  createOption(info: Option_2): HTMLOptionElement;
211
+ setupLabelHandlers(): void;
212
+ removeLabelHandlers(): void;
208
213
  destroy(): void;
209
214
  }
210
215
 
package/dist/vue/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import { defineComponent as E, createElementBlock as T, openBlock as D, renderSlot as k } from "vue";
1
+ import { defineComponent as A, createElementBlock as T, openBlock as D, renderSlot as k } from "vue";
2
2
  class N {
3
3
  main;
4
4
  // Placeholder
@@ -63,7 +63,7 @@ class N {
63
63
  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";
64
64
  }
65
65
  }
66
- function y() {
66
+ function C() {
67
67
  return Math.random().toString(36).substring(2, 10);
68
68
  }
69
69
  function M(h, e) {
@@ -75,7 +75,7 @@ function M(h, e) {
75
75
  }
76
76
  return t(h, e) || s(h, e);
77
77
  }
78
- function S(h, e = 50, t = !1) {
78
+ function O(h, e = 50, t = !1) {
79
79
  let s;
80
80
  return function(...i) {
81
81
  const l = self, a = () => {
@@ -84,7 +84,7 @@ function S(h, e = 50, t = !1) {
84
84
  clearTimeout(s), s = setTimeout(a, e), n && h.apply(l, i);
85
85
  };
86
86
  }
87
- function C(h, e) {
87
+ function L(h, e) {
88
88
  return JSON.stringify(h) === JSON.stringify(e);
89
89
  }
90
90
  function P(h) {
@@ -106,7 +106,7 @@ class p {
106
106
  data;
107
107
  mandatory;
108
108
  constructor(e) {
109
- this.id = !e.id || e.id === "" ? y() : e.id, this.value = e.value === void 0 ? e.text || "" : e.value || "", this.text = e.text || "", this.html = e.html || "", this.defaultSelected = e.defaultSelected !== void 0 ? e.defaultSelected : !1, this.selected = e.selected !== void 0 ? e.selected : !1, this.display = e.display !== void 0 ? e.display : !0, this.disabled = e.disabled !== void 0 ? e.disabled : !1, this.mandatory = e.mandatory !== void 0 ? e.mandatory : !1, this.placeholder = e.placeholder !== void 0 ? e.placeholder : !1, this.class = e.class || "", this.style = e.style || "", this.data = e.data || {};
109
+ 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 || {};
110
110
  }
111
111
  }
112
112
  class m {
@@ -117,7 +117,7 @@ class m {
117
117
  closable;
118
118
  options;
119
119
  constructor(e) {
120
- if (this.id = !e.id || e.id === "" ? y() : e.id, this.label = e.label || "", this.selectAll = e.selectAll === void 0 ? !1 : e.selectAll, this.selectAllText = e.selectAllText || "Select All", this.closable = e.closable || "off", this.options = [], e.options)
120
+ 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)
121
121
  for (const t of e.options)
122
122
  this.options.push(new p(t));
123
123
  }
@@ -298,7 +298,7 @@ class B {
298
298
  }), t;
299
299
  }
300
300
  }
301
- class V {
301
+ class I {
302
302
  settings;
303
303
  store;
304
304
  callbacks;
@@ -536,7 +536,7 @@ class V {
536
536
  main: e,
537
537
  input: t
538
538
  };
539
- 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
+ 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) => {
540
540
  this.callbacks.search(l.target.value);
541
541
  }, 100), t.onkeydown = (l) => {
542
542
  switch (l.key) {
@@ -600,9 +600,6 @@ class V {
600
600
  searchFocus() {
601
601
  this.content.search.input.focus();
602
602
  }
603
- clearSearch() {
604
- this.content.search.input.value = "";
605
- }
606
603
  getOptions(e = !1, t = !1, s = !1) {
607
604
  let i = "." + this.classes.option;
608
605
  return e && (i += ":not(." + this.classes.placeholder + ")"), t && (i += ":not(." + this.classes.disabled + ")"), s && (i += ":not(." + this.classes.hide + ")"), Array.from(this.content.list.querySelectorAll(i));
@@ -709,22 +706,22 @@ class V {
709
706
  const u = document.createElementNS("http://www.w3.org/2000/svg", "path");
710
707
  u.setAttribute("d", this.classes.optgroupSelectAllCheck), d.appendChild(u), o.addEventListener("click", (g) => {
711
708
  g.preventDefault(), g.stopPropagation();
712
- const b = this.store.getSelected();
709
+ const v = this.store.getSelected();
713
710
  if (c) {
714
- const w = b.filter((O) => {
715
- for (const v of s.options)
716
- if (O === v.id)
711
+ const w = v.filter((S) => {
712
+ for (const b of s.options)
713
+ if (S === b.id)
717
714
  return !1;
718
715
  return !0;
719
716
  });
720
717
  this.callbacks.setSelected(w, !0);
721
718
  return;
722
719
  } else {
723
- let w = s.options.map((v) => v.id).filter((v) => v !== void 0);
724
- const O = b.concat(w);
725
- for (const v of s.options)
726
- v.id && !this.store.getOptionByID(v.id) && this.callbacks.addOption(new p(v));
727
- this.callbacks.setSelected(O, !0);
720
+ let w = s.options.map((b) => b.id).filter((b) => b !== void 0);
721
+ const S = v.concat(w);
722
+ for (const b of s.options)
723
+ b.id && !this.store.getOptionByID(b.id) && this.callbacks.addOption(new p(b));
724
+ this.callbacks.setSelected(S, !0);
728
725
  return;
729
726
  }
730
727
  }), n.appendChild(o);
@@ -763,7 +760,7 @@ class V {
763
760
  ) : 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) => {
764
761
  s.preventDefault(), s.stopPropagation();
765
762
  const i = this.store.getSelected(), l = s.currentTarget, a = String(l.dataset.id), n = s.ctrlKey || s.metaKey;
766
- if (e.disabled || !this.settings.isMultiple && e.selected && !this.settings.allowDeselect || this.settings.isMultiple && this.settings.maxSelected <= i.length && !e.selected || this.settings.isMultiple && this.settings.minSelected >= i.length && e.selected && !n)
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 && !n)
767
764
  return;
768
765
  let o = !1;
769
766
  const c = this.store.getSelectedOptions();
@@ -771,10 +768,10 @@ class V {
771
768
  if (this.settings.isMultiple) {
772
769
  const d = c.some((u) => u.id === a);
773
770
  if (s.shiftKey && this.lastSelectedOption) {
774
- const u = this.store.getDataOptions(), g = u.findIndex((w) => w.id === this.lastSelectedOption.id), b = u.findIndex((w) => w.id === e.id);
775
- if (g >= 0 && b >= 0) {
776
- const w = Math.min(g, b), O = Math.max(g, b), L = u.slice(w, O + 1).filter((x) => !c.find((A) => A.id === x.id));
777
- c.length + L.length <= this.settings.maxSelected ? r = c.concat(L) : r = c;
771
+ const u = this.store.getDataOptions(), g = u.findIndex((w) => w.id === this.lastSelectedOption.id), v = u.findIndex((w) => w.id === e.id);
772
+ if (g >= 0 && v >= 0) {
773
+ const w = Math.min(g, v), S = Math.max(g, v), y = u.slice(w, S + 1).filter((E) => !c.find((x) => x.id === E.id));
774
+ c.length + y.length <= this.settings.maxSelected ? r = c.concat(y) : r = c;
778
775
  } else
779
776
  r = c;
780
777
  } else n ? (d ? r = c.filter((u) => u.id !== a) : r = c.concat(e), this.lastSelectedOption = e) : (d ? r = c.filter((u) => u.id !== a) : r = c.concat(e), this.lastSelectedOption = e);
@@ -805,8 +802,8 @@ class V {
805
802
  const d = document.createElement("span");
806
803
  c.split(r).forEach((u, g) => {
807
804
  if (u && r.test(u)) {
808
- const b = document.createElement("mark");
809
- b.className = s, b.textContent = u, d.appendChild(b);
805
+ const v = document.createElement("mark");
806
+ v.className = s, v.textContent = u, d.appendChild(v);
810
807
  } else u && d.appendChild(document.createTextNode(u));
811
808
  }), o.parentNode?.replaceChild(d, o);
812
809
  }
@@ -841,16 +838,21 @@ class V {
841
838
  i && !(s && !t) ? l.classList.remove(a) : l.classList.add(a);
842
839
  }
843
840
  }
844
- class I {
841
+ class H {
845
842
  select;
846
843
  // Mutation observer fields
847
844
  onValueChange;
848
845
  onClassChange;
849
846
  onDisabledChange;
850
847
  onOptionsChange;
848
+ onLabelClick;
851
849
  // Change observers
852
850
  listen = !1;
853
851
  observer = null;
852
+ // Event handlers for preventing native select behavior (especially on iOS Safari)
853
+ preventNativeSelect = null;
854
+ preventNativeSelectMousedown = null;
855
+ preventNativeSelectFocus = null;
854
856
  constructor(e) {
855
857
  this.select = e, this.valueChange = this.valueChange.bind(this), this.select.addEventListener("change", this.valueChange, {
856
858
  // allow bubbling of event
@@ -864,10 +866,16 @@ class I {
864
866
  this.select.disabled = !0;
865
867
  }
866
868
  hideUI() {
867
- 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");
869
+ 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) => {
870
+ e.preventDefault(), e.stopPropagation(), e.stopImmediatePropagation();
871
+ }, this.preventNativeSelectMousedown = (e) => {
872
+ e.preventDefault(), e.stopPropagation(), e.stopImmediatePropagation();
873
+ }, this.preventNativeSelectFocus = (e) => {
874
+ e.preventDefault(), e.stopPropagation(), e.stopImmediatePropagation();
875
+ }, 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 }));
868
876
  }
869
877
  showUI() {
870
- 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");
878
+ 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);
871
879
  }
872
880
  changeListen(e) {
873
881
  this.listen = e, e && this.observer && this.observer.observe(this.select, {
@@ -1031,11 +1039,51 @@ class I {
1031
1039
  t.setAttribute("data-" + P(s), e.data[s]);
1032
1040
  }), t;
1033
1041
  }
1042
+ // Find and handle labels associated with this select
1043
+ setupLabelHandlers() {
1044
+ const e = [], t = this.select.id;
1045
+ t && document.querySelectorAll(`label[for="${t}"]`).forEach((a) => e.push(a));
1046
+ let s = this.select.parentElement;
1047
+ for (; s && s !== document.body; ) {
1048
+ if (s.tagName === "LABEL") {
1049
+ e.push(s);
1050
+ break;
1051
+ }
1052
+ s = s.parentElement;
1053
+ }
1054
+ Array.from(new Set(e)).forEach((l) => {
1055
+ if (l.__slimSelectLabelHandler)
1056
+ return;
1057
+ const a = (n) => {
1058
+ n.preventDefault(), n.stopPropagation(), this.onLabelClick && setTimeout(() => {
1059
+ this.onLabelClick();
1060
+ }, 0);
1061
+ };
1062
+ l.__slimSelectLabelHandler = a, l.addEventListener("click", a, { capture: !0, passive: !1 });
1063
+ });
1064
+ }
1065
+ // Remove label handlers
1066
+ removeLabelHandlers() {
1067
+ const e = [], t = this.select.id;
1068
+ t && document.querySelectorAll(`label[for="${t}"]`).forEach((a) => e.push(a));
1069
+ let s = this.select.parentElement;
1070
+ for (; s && s !== document.body; ) {
1071
+ if (s.tagName === "LABEL") {
1072
+ e.push(s);
1073
+ break;
1074
+ }
1075
+ s = s.parentElement;
1076
+ }
1077
+ Array.from(new Set(e)).forEach((l) => {
1078
+ const a = l.__slimSelectLabelHandler;
1079
+ a && (l.removeEventListener("click", a, { capture: !0 }), delete l.__slimSelectLabelHandler);
1080
+ });
1081
+ }
1034
1082
  destroy() {
1035
- this.changeListen(!1), this.select.removeEventListener("change", this.valueChange), this.observer && (this.observer.disconnect(), this.observer = null), delete this.select.dataset.id, this.showUI();
1083
+ 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();
1036
1084
  }
1037
1085
  }
1038
- class H {
1086
+ class V {
1039
1087
  id = "";
1040
1088
  // Primary ID for the select
1041
1089
  style = "";
@@ -1073,7 +1121,7 @@ class H {
1073
1121
  maxValuesMessage;
1074
1122
  addableText;
1075
1123
  constructor(e) {
1076
- e || (e = {}), this.id = "ss-" + y(), this.style = e.style || "", this.class = e.class || [], this.disabled = e.disabled !== void 0 ? e.disabled : !1, this.alwaysOpen = e.alwaysOpen !== void 0 ? e.alwaysOpen : !1, this.showSearch = e.showSearch !== void 0 ? e.showSearch : !0, this.focusSearch = e.focusSearch !== void 0 ? e.focusSearch : !0, this.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}';
1124
+ 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}';
1077
1125
  }
1078
1126
  }
1079
1127
  let F = class {
@@ -1108,11 +1156,11 @@ let F = class {
1108
1156
  e.events && e.events.error && e.events.error(new Error("Element isnt of type select"));
1109
1157
  return;
1110
1158
  }
1111
- this.selectEl.dataset.ssid && this.destroy(), this.settings = new H(e.settings), this.cssClasses = new N(e.cssClasses);
1159
+ this.selectEl.dataset.ssid && this.destroy(), this.settings = new V(e.settings), this.cssClasses = new N(e.cssClasses);
1112
1160
  const t = ["beforeOpen", "afterOpen", "beforeClose", "afterClose"];
1113
1161
  for (const n in e.events)
1114
- e.events.hasOwnProperty(n) && (t.indexOf(n) !== -1 ? this.events[n] = S(e.events[n], 100) : this.events[n] = e.events[n]);
1115
- 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.select.updateSelect(this.settings.id, this.settings.style, this.settings.class), this.select.hideUI(), this.select.onValueChange = (n) => {
1162
+ e.events.hasOwnProperty(n) && (t.indexOf(n) !== -1 ? this.events[n] = O(e.events[n], 100) : this.events[n] = e.events[n]);
1163
+ 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 H(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) => {
1116
1164
  this.setSelected(n.map((o) => o.id));
1117
1165
  }, this.select.onClassChange = (n) => {
1118
1166
  this.settings.class = n, this.render.updateClassStyles();
@@ -1120,6 +1168,8 @@ let F = class {
1120
1168
  n ? this.disable() : this.enable();
1121
1169
  }, this.select.onOptionsChange = (n) => {
1122
1170
  this.setData(n);
1171
+ }, this.select.onLabelClick = () => {
1172
+ this.settings.disabled || this.open();
1123
1173
  };
1124
1174
  const s = e.data ? e.data : this.select.getData();
1125
1175
  this.store = new B(this.settings.isMultiple ? "multiple" : "single", s), e.data && this.select.updateOptions(this.store.getData());
@@ -1133,9 +1183,9 @@ let F = class {
1133
1183
  beforeChange: this.events.beforeChange,
1134
1184
  afterChange: this.events.afterChange
1135
1185
  };
1136
- this.render = new V(this.settings, this.cssClasses, this.store, i), this.render.renderValues(), this.render.renderOptions(this.store.getData());
1186
+ this.render = new I(this.settings, this.cssClasses, this.store, i), this.render.renderValues(), this.render.renderOptions(this.store.getData());
1137
1187
  const l = this.selectEl.getAttribute("aria-label"), a = this.selectEl.getAttribute("aria-labelledby");
1138
- 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;
1188
+ 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;
1139
1189
  }
1140
1190
  // Set to enabled and remove disabled classes
1141
1191
  enable() {
@@ -1156,7 +1206,7 @@ let F = class {
1156
1206
  }
1157
1207
  this.store.setData(e);
1158
1208
  const i = this.store.getData();
1159
- this.select.updateOptions(i), this.render.renderValues(), this.render.renderOptions(i), this.events.afterChange && !C(t, this.store.getSelected()) && this.events.afterChange(this.store.getSelectedOptions());
1209
+ 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());
1160
1210
  }
1161
1211
  getSelected() {
1162
1212
  let e = this.store.getSelectedOptions();
@@ -1177,13 +1227,13 @@ let F = class {
1177
1227
  }
1178
1228
  this.store.setSelectedBy("id", l);
1179
1229
  const a = this.store.getData();
1180
- 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 && !C(s, this.store.getSelected()) && this.events.afterChange(this.store.getSelectedOptions());
1230
+ 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());
1181
1231
  }
1182
1232
  addOption(e) {
1183
1233
  const t = this.store.getSelected();
1184
1234
  this.store.getDataOptions().some((i) => i.value === (e.value ?? e.text)) || this.store.addOption(e);
1185
1235
  const s = this.store.getData();
1186
- this.select.updateOptions(s), this.render.renderValues(), this.render.renderOptions(s), this.events.afterChange && !C(t, this.store.getSelected()) && this.events.afterChange(this.store.getSelectedOptions());
1236
+ 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());
1187
1237
  }
1188
1238
  open() {
1189
1239
  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(() => {
@@ -1191,13 +1241,17 @@ let F = class {
1191
1241
  }, 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)));
1192
1242
  }
1193
1243
  close(e = null) {
1194
- !this.settings.isOpen || this.settings.alwaysOpen || (this.events.beforeClose && this.events.beforeClose(), this.render.close(), this.render.clearSearch(), this.render.mainFocus(e), this.settings.isOpen = !1, this.settings.isFullOpen = !1, this.closeTimeout = setTimeout(() => {
1244
+ !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(() => {
1195
1245
  this.events.afterClose && this.events.afterClose(), document.removeEventListener("click", this.documentClick);
1196
1246
  }, this.settings.timeoutDelay), this.settings.intervalMove && clearInterval(this.settings.intervalMove));
1197
1247
  }
1198
1248
  // Take in string value and search current options
1199
1249
  search(e) {
1200
- if (this.render.content.search.input.value !== e && (this.render.content.search.input.value = e), !this.events.search) {
1250
+ if (this.render.content.search.input.value !== e && (this.render.content.search.input.value = e), e === "") {
1251
+ this.render.renderOptions(this.store.getData());
1252
+ return;
1253
+ }
1254
+ if (!this.events.search) {
1201
1255
  const s = e === "" ? this.store.getData() : this.store.search(e, this.events.searchFilter);
1202
1256
  this.render.renderOptions(s);
1203
1257
  return;
@@ -1216,11 +1270,11 @@ let F = class {
1216
1270
  destroy() {
1217
1271
  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
1272
  }
1219
- windowResize = S(() => {
1273
+ windowResize = O(() => {
1220
1274
  !this.settings.isOpen && !this.settings.isFullOpen || this.render.moveContent();
1221
1275
  });
1222
1276
  // Event listener for window scrolling
1223
- windowScroll = S(() => {
1277
+ windowScroll = O(() => {
1224
1278
  !this.settings.isOpen && !this.settings.isFullOpen || this.render.moveContent();
1225
1279
  });
1226
1280
  // Event listener for document click
@@ -1232,7 +1286,7 @@ let F = class {
1232
1286
  document.hidden && this.close();
1233
1287
  };
1234
1288
  };
1235
- const R = E({
1289
+ const R = A({
1236
1290
  name: "SlimSelect",
1237
1291
  props: {
1238
1292
  modelValue: {
@@ -1320,24 +1374,24 @@ const R = E({
1320
1374
  return typeof h == "string" ? e ? [h] : h : Array.isArray(h) ? e ? h : h[0] : e ? [] : "";
1321
1375
  }
1322
1376
  }
1323
- }), $ = (h, e) => {
1377
+ }), _ = (h, e) => {
1324
1378
  const t = h.__vccOpts || h;
1325
1379
  for (const [s, i] of e)
1326
1380
  t[s] = i;
1327
1381
  return t;
1328
- }, U = ["multiple"];
1329
- function q(h, e, t, s, i, l) {
1382
+ }, q = ["multiple"];
1383
+ function $(h, e, t, s, i, l) {
1330
1384
  return D(), T("select", {
1331
1385
  multiple: h.multiple,
1332
1386
  ref: "slim"
1333
1387
  }, [
1334
1388
  k(h.$slots, "default")
1335
- ], 8, U);
1389
+ ], 8, q);
1336
1390
  }
1337
- const z = /* @__PURE__ */ $(R, [["render", q]]);
1391
+ const z = /* @__PURE__ */ _(R, [["render", $]]);
1338
1392
  export {
1339
1393
  m as Optgroup,
1340
1394
  p as Option,
1341
- H as Settings,
1395
+ V as Settings,
1342
1396
  z as default
1343
1397
  };