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.
@@ -183,8 +183,14 @@ declare class Select {
183
183
  onClassChange?: (classes: string[]) => void;
184
184
  onDisabledChange?: (disabled: boolean) => void;
185
185
  onOptionsChange?: (data: (Option_2 | Optgroup)[]) => void;
186
+ onLabelClick?: () => void;
186
187
  private listen;
187
188
  private observer;
189
+ private isUpdating;
190
+ private pendingOptionsChange;
191
+ private preventNativeSelect;
192
+ private preventNativeSelectMousedown;
193
+ private preventNativeSelectFocus;
188
194
  constructor(select: HTMLSelectElement);
189
195
  enable(): void;
190
196
  disable(): void;
@@ -204,6 +210,8 @@ declare class Select {
204
210
  updateOptions(data: (Option_2 | Optgroup)[]): void;
205
211
  createOptgroup(optgroup: Optgroup): HTMLOptGroupElement;
206
212
  createOption(info: Option_2): HTMLOptionElement;
213
+ setupLabelHandlers(): void;
214
+ removeLabelHandlers(): void;
207
215
  destroy(): void;
208
216
  }
209
217
 
package/dist/vue/index.js CHANGED
@@ -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 y(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,12 +117,12 @@ 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
  }
124
124
  }
125
- class B {
125
+ class V {
126
126
  selectType = "single";
127
127
  // Main data set, never null
128
128
  data = [];
@@ -298,7 +298,7 @@ class B {
298
298
  }), t;
299
299
  }
300
300
  }
301
- class V {
301
+ class B {
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) {
@@ -706,22 +706,22 @@ class V {
706
706
  const u = document.createElementNS("http://www.w3.org/2000/svg", "path");
707
707
  u.setAttribute("d", this.classes.optgroupSelectAllCheck), d.appendChild(u), o.addEventListener("click", (g) => {
708
708
  g.preventDefault(), g.stopPropagation();
709
- const b = this.store.getSelected();
709
+ const v = this.store.getSelected();
710
710
  if (c) {
711
- const w = b.filter((O) => {
712
- for (const v of s.options)
713
- if (O === v.id)
711
+ const w = v.filter((S) => {
712
+ for (const b of s.options)
713
+ if (S === b.id)
714
714
  return !1;
715
715
  return !0;
716
716
  });
717
717
  this.callbacks.setSelected(w, !0);
718
718
  return;
719
719
  } else {
720
- let w = s.options.map((v) => v.id).filter((v) => v !== void 0);
721
- const O = b.concat(w);
722
- for (const v of s.options)
723
- v.id && !this.store.getOptionByID(v.id) && this.callbacks.addOption(new p(v));
724
- 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);
725
725
  return;
726
726
  }
727
727
  }), n.appendChild(o);
@@ -768,9 +768,9 @@ class V {
768
768
  if (this.settings.isMultiple) {
769
769
  const d = c.some((u) => u.id === a);
770
770
  if (s.shiftKey && this.lastSelectedOption) {
771
- const u = this.store.getDataOptions(), g = u.findIndex((w) => w.id === this.lastSelectedOption.id), b = u.findIndex((w) => w.id === e.id);
772
- if (g >= 0 && b >= 0) {
773
- 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));
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), L = u.slice(w, S + 1).filter((A) => !c.find((x) => x.id === A.id));
774
774
  c.length + L.length <= this.settings.maxSelected ? r = c.concat(L) : r = c;
775
775
  } else
776
776
  r = c;
@@ -802,8 +802,8 @@ class V {
802
802
  const d = document.createElement("span");
803
803
  c.split(r).forEach((u, g) => {
804
804
  if (u && r.test(u)) {
805
- const b = document.createElement("mark");
806
- 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);
807
807
  } else u && d.appendChild(document.createTextNode(u));
808
808
  }), o.parentNode?.replaceChild(d, o);
809
809
  }
@@ -845,9 +845,16 @@ class I {
845
845
  onClassChange;
846
846
  onDisabledChange;
847
847
  onOptionsChange;
848
+ onLabelClick;
848
849
  // Change observers
849
850
  listen = !1;
850
851
  observer = null;
852
+ isUpdating = !1;
853
+ pendingOptionsChange = null;
854
+ // Event handlers for preventing native select behavior (especially on iOS Safari)
855
+ preventNativeSelect = null;
856
+ preventNativeSelectMousedown = null;
857
+ preventNativeSelectFocus = null;
851
858
  constructor(e) {
852
859
  this.select = e, this.valueChange = this.valueChange.bind(this), this.select.addEventListener("change", this.valueChange, {
853
860
  // allow bubbling of event
@@ -861,10 +868,16 @@ class I {
861
868
  this.select.disabled = !0;
862
869
  }
863
870
  hideUI() {
864
- 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");
871
+ 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) => {
872
+ e.preventDefault(), e.stopPropagation(), e.stopImmediatePropagation();
873
+ }, this.preventNativeSelectMousedown = (e) => {
874
+ e.preventDefault(), e.stopPropagation(), e.stopImmediatePropagation();
875
+ }, this.preventNativeSelectFocus = (e) => {
876
+ e.preventDefault(), e.stopPropagation(), e.stopImmediatePropagation();
877
+ }, 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 }));
865
878
  }
866
879
  showUI() {
867
- 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");
880
+ 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);
868
881
  }
869
882
  changeListen(e) {
870
883
  this.listen = e, e && this.observer && this.observer.observe(this.select, {
@@ -896,7 +909,16 @@ class I {
896
909
  }
897
910
  (l.target.nodeName === "OPTGROUP" || l.target.nodeName === "OPTION") && (i = !0);
898
911
  }
899
- 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 && (this.changeListen(!1), this.onOptionsChange(this.getData()), this.changeListen(!0));
912
+ if (t && this.onClassChange && this.onClassChange(this.select.className.split(" ")), s && this.onDisabledChange && (this.changeListen(!1), this.onDisabledChange(this.select.disabled), this.changeListen(!0)), i && this.onOptionsChange) {
913
+ if (this.isUpdating) {
914
+ if (this.select.options.length > 0) {
915
+ const l = this.getData();
916
+ l.length > 0 && (this.pendingOptionsChange = l);
917
+ }
918
+ return;
919
+ }
920
+ this.changeListen(!1), this.onOptionsChange(this.getData()), this.changeListen(!0);
921
+ }
900
922
  }
901
923
  // From the select element pull optgroup and options into data
902
924
  getData() {
@@ -1008,10 +1030,15 @@ class I {
1008
1030
  })), this.changeListen(!0);
1009
1031
  }
1010
1032
  updateOptions(e) {
1011
- this.changeListen(!1), this.select.innerHTML = "";
1012
- for (const t of e)
1013
- t instanceof m && this.select.appendChild(this.createOptgroup(t)), t instanceof p && this.select.appendChild(this.createOption(t));
1014
- this.select.dispatchEvent(new Event("change", { bubbles: !0 })), this.changeListen(!0);
1033
+ if (!(!e || e.length === 0)) {
1034
+ this.isUpdating = !0, this.pendingOptionsChange = null, this.changeListen(!1), this.select.innerHTML = "";
1035
+ for (const t of e)
1036
+ t instanceof m && this.select.appendChild(this.createOptgroup(t)), t instanceof p && this.select.appendChild(this.createOption(t));
1037
+ if (this.select.dispatchEvent(new Event("change", { bubbles: !0 })), this.changeListen(!0), this.isUpdating = !1, this.pendingOptionsChange !== null) {
1038
+ const t = this.pendingOptionsChange;
1039
+ t.length > 0 && this.onOptionsChange ? (this.pendingOptionsChange = null, this.changeListen(!1), this.onOptionsChange(t), this.changeListen(!0)) : this.pendingOptionsChange = null;
1040
+ }
1041
+ }
1015
1042
  }
1016
1043
  createOptgroup(e) {
1017
1044
  const t = document.createElement("optgroup");
@@ -1028,8 +1055,48 @@ class I {
1028
1055
  t.setAttribute("data-" + P(s), e.data[s]);
1029
1056
  }), t;
1030
1057
  }
1058
+ // Find and handle labels associated with this select
1059
+ setupLabelHandlers() {
1060
+ const e = [], t = this.select.id;
1061
+ t && document.querySelectorAll(`label[for="${t}"]`).forEach((a) => e.push(a));
1062
+ let s = this.select.parentElement;
1063
+ for (; s && s !== document.body; ) {
1064
+ if (s.tagName === "LABEL") {
1065
+ e.push(s);
1066
+ break;
1067
+ }
1068
+ s = s.parentElement;
1069
+ }
1070
+ Array.from(new Set(e)).forEach((l) => {
1071
+ if (l.__slimSelectLabelHandler)
1072
+ return;
1073
+ const a = (n) => {
1074
+ n.preventDefault(), n.stopPropagation(), this.onLabelClick && setTimeout(() => {
1075
+ this.onLabelClick();
1076
+ }, 0);
1077
+ };
1078
+ l.__slimSelectLabelHandler = a, l.addEventListener("click", a, { capture: !0, passive: !1 });
1079
+ });
1080
+ }
1081
+ // Remove label handlers
1082
+ removeLabelHandlers() {
1083
+ const e = [], t = this.select.id;
1084
+ t && document.querySelectorAll(`label[for="${t}"]`).forEach((a) => e.push(a));
1085
+ let s = this.select.parentElement;
1086
+ for (; s && s !== document.body; ) {
1087
+ if (s.tagName === "LABEL") {
1088
+ e.push(s);
1089
+ break;
1090
+ }
1091
+ s = s.parentElement;
1092
+ }
1093
+ Array.from(new Set(e)).forEach((l) => {
1094
+ const a = l.__slimSelectLabelHandler;
1095
+ a && (l.removeEventListener("click", a, { capture: !0 }), delete l.__slimSelectLabelHandler);
1096
+ });
1097
+ }
1031
1098
  destroy() {
1032
- this.changeListen(!1), this.select.removeEventListener("change", this.valueChange), this.observer && (this.observer.disconnect(), this.observer = null), delete this.select.dataset.id, this.showUI();
1099
+ 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();
1033
1100
  }
1034
1101
  }
1035
1102
  class H {
@@ -1070,7 +1137,7 @@ class H {
1070
1137
  maxValuesMessage;
1071
1138
  addableText;
1072
1139
  constructor(e) {
1073
- 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}';
1140
+ e || (e = {}), this.id = "ss-" + C(), this.style = e.style || "", this.class = e.class || [], this.disabled = e.disabled !== void 0 ? e.disabled : !1, this.alwaysOpen = e.alwaysOpen !== void 0 ? e.alwaysOpen : !1, this.showSearch = e.showSearch !== void 0 ? e.showSearch : !0, this.focusSearch = e.focusSearch !== void 0 ? e.focusSearch : !0, this.ariaLabel = e.ariaLabel || "Combobox", this.searchPlaceholder = e.searchPlaceholder || "Search...", this.searchText = e.searchText || "No Results", this.searchingText = e.searchingText || "Searching...", this.searchHighlight = e.searchHighlight !== void 0 ? e.searchHighlight : !1, this.closeOnSelect = e.closeOnSelect !== void 0 ? e.closeOnSelect : !0, this.contentLocation = e.contentLocation || document.body, this.contentPosition = e.contentPosition || "absolute", this.openPosition = e.openPosition || "auto", this.placeholderText = e.placeholderText !== void 0 ? e.placeholderText : "Select Value", this.allowDeselect = e.allowDeselect !== void 0 ? e.allowDeselect : !1, this.hideSelected = e.hideSelected !== void 0 ? e.hideSelected : !1, this.keepOrder = e.keepOrder !== void 0 ? e.keepOrder : !1, this.showOptionTooltips = e.showOptionTooltips !== void 0 ? e.showOptionTooltips : !1, this.minSelected = e.minSelected || 0, this.maxSelected = e.maxSelected || 1e3, this.timeoutDelay = e.timeoutDelay || 200, this.maxValuesShown = e.maxValuesShown || 20, this.maxValuesMessage = e.maxValuesMessage || "{number} selected", this.addableText = e.addableText || 'Press "Enter" to add {value}';
1074
1141
  }
1075
1142
  }
1076
1143
  let F = class {
@@ -1108,18 +1175,20 @@ let F = class {
1108
1175
  this.selectEl.dataset.ssid && this.destroy(), this.settings = new H(e.settings), this.cssClasses = new N(e.cssClasses);
1109
1176
  const t = ["beforeOpen", "afterOpen", "beforeClose", "afterClose"];
1110
1177
  for (const n in e.events)
1111
- e.events.hasOwnProperty(n) && (t.indexOf(n) !== -1 ? this.events[n] = S(e.events[n], 100) : this.events[n] = e.events[n]);
1112
- 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) => {
1178
+ e.events.hasOwnProperty(n) && (t.indexOf(n) !== -1 ? this.events[n] = O(e.events[n], 100) : this.events[n] = e.events[n]);
1179
+ this.settings.disabled = e.settings?.disabled ? e.settings.disabled : this.selectEl.disabled, this.settings.isMultiple = this.selectEl.multiple, this.settings.style = this.selectEl.style.cssText, this.settings.class = this.selectEl.className.split(" "), this.select = new I(this.selectEl), this.selectEl.id || (this.selectEl.id = this.settings.id), this.select.updateSelect(this.settings.id, this.settings.style, this.settings.class), this.select.hideUI(), this.select.onValueChange = (n) => {
1113
1180
  this.setSelected(n.map((o) => o.id));
1114
1181
  }, this.select.onClassChange = (n) => {
1115
1182
  this.settings.class = n, this.render.updateClassStyles();
1116
1183
  }, this.select.onDisabledChange = (n) => {
1117
1184
  n ? this.disable() : this.enable();
1118
1185
  }, this.select.onOptionsChange = (n) => {
1119
- this.setData(n);
1186
+ this.setData(n || []);
1187
+ }, this.select.onLabelClick = () => {
1188
+ this.settings.disabled || this.open();
1120
1189
  };
1121
1190
  const s = e.data ? e.data : this.select.getData();
1122
- this.store = new B(this.settings.isMultiple ? "multiple" : "single", s), e.data && this.select.updateOptions(this.store.getData());
1191
+ this.store = new V(this.settings.isMultiple ? "multiple" : "single", s), e.data && this.select.updateOptions(this.store.getData());
1123
1192
  const i = {
1124
1193
  open: this.open.bind(this),
1125
1194
  close: this.close.bind(this),
@@ -1130,9 +1199,9 @@ let F = class {
1130
1199
  beforeChange: this.events.beforeChange,
1131
1200
  afterChange: this.events.afterChange
1132
1201
  };
1133
- this.render = new V(this.settings, this.cssClasses, this.store, i), this.render.renderValues(), this.render.renderOptions(this.store.getData());
1202
+ this.render = new B(this.settings, this.cssClasses, this.store, i), this.render.renderValues(), this.render.renderOptions(this.store.getData());
1134
1203
  const l = this.selectEl.getAttribute("aria-label"), a = this.selectEl.getAttribute("aria-labelledby");
1135
- 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;
1204
+ 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;
1136
1205
  }
1137
1206
  // Set to enabled and remove disabled classes
1138
1207
  enable() {
@@ -1153,7 +1222,7 @@ let F = class {
1153
1222
  }
1154
1223
  this.store.setData(e);
1155
1224
  const i = this.store.getData();
1156
- 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());
1225
+ this.select.updateOptions(i), this.render.renderValues(), this.render.renderOptions(i), this.events.afterChange && !y(t, this.store.getSelected()) && this.events.afterChange(this.store.getSelectedOptions());
1157
1226
  }
1158
1227
  getSelected() {
1159
1228
  let e = this.store.getSelectedOptions();
@@ -1174,13 +1243,13 @@ let F = class {
1174
1243
  }
1175
1244
  this.store.setSelectedBy("id", l);
1176
1245
  const a = this.store.getData();
1177
- 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());
1246
+ 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 && !y(s, this.store.getSelected()) && this.events.afterChange(this.store.getSelectedOptions());
1178
1247
  }
1179
1248
  addOption(e) {
1180
1249
  const t = this.store.getSelected();
1181
1250
  this.store.getDataOptions().some((i) => i.value === (e.value ?? e.text)) || this.store.addOption(e);
1182
1251
  const s = this.store.getData();
1183
- 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());
1252
+ this.select.updateOptions(s), this.render.renderValues(), this.render.renderOptions(s), this.events.afterChange && !y(t, this.store.getSelected()) && this.events.afterChange(this.store.getSelectedOptions());
1184
1253
  }
1185
1254
  open() {
1186
1255
  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(() => {
@@ -1217,11 +1286,11 @@ let F = class {
1217
1286
  destroy() {
1218
1287
  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();
1219
1288
  }
1220
- windowResize = S(() => {
1289
+ windowResize = O(() => {
1221
1290
  !this.settings.isOpen && !this.settings.isFullOpen || this.render.moveContent();
1222
1291
  });
1223
1292
  // Event listener for window scrolling
1224
- windowScroll = S(() => {
1293
+ windowScroll = O(() => {
1225
1294
  !this.settings.isOpen && !this.settings.isFullOpen || this.render.moveContent();
1226
1295
  });
1227
1296
  // Event listener for document click
@@ -1271,18 +1340,15 @@ const R = E({
1271
1340
  const t = this.events?.afterChange;
1272
1341
  e.events = {
1273
1342
  ...this.events,
1274
- afterChange: (i) => {
1275
- const l = this.multiple ? i.map((a) => a.value) : i.length > 0 ? i[0].value : "";
1276
- this.value !== l && (this.value = l), t && t(i);
1343
+ afterChange: (s) => {
1344
+ this.handleAfterChange(s, t);
1277
1345
  }
1278
- }, this.slim = new F(e);
1279
- let s = this.$props.multiple ? this.slim.getSelected() : this.slim.getSelected()[0];
1280
- this.value !== s && this.slim.setSelected(this.value, !1);
1346
+ }, this.slim = new F(e), this.syncModelValueToSlimSelect(!1);
1281
1347
  },
1282
1348
  updated() {
1283
1349
  if (this.slim && !this.data) {
1284
1350
  const h = this.slim.getSelected(), e = Array.isArray(this.value) ? this.value : [this.value];
1285
- JSON.stringify(h.sort()) !== JSON.stringify(e.sort()) && this.slim.setSelected(this.value, !1);
1351
+ JSON.stringify(h.sort()) !== JSON.stringify(e.sort()) && this.syncModelValueToSlimSelect(!1);
1286
1352
  }
1287
1353
  },
1288
1354
  beforeUnmount() {
@@ -1291,7 +1357,7 @@ const R = E({
1291
1357
  watch: {
1292
1358
  modelValue: {
1293
1359
  handler: function(h) {
1294
- this.slim && this.slim.setSelected(this.getCleanValue(h), !1);
1360
+ this.slim && this.syncModelValueToSlimSelect(!1);
1295
1361
  }
1296
1362
  },
1297
1363
  data: {
@@ -1316,26 +1382,45 @@ const R = E({
1316
1382
  getSlimSelect() {
1317
1383
  return this.slim;
1318
1384
  },
1385
+ handleAfterChange(h, e) {
1386
+ if (!this.slim) return;
1387
+ const t = this.multiple ? h.map((o) => o.value) : h.length > 0 ? h[0].value : "", s = this.getCleanValue(this.$props.modelValue), i = this.slim.store.getDataOptions(), l = Array.isArray(s) ? s.length > 0 && s.every((o) => i.some((c) => c.value === o)) : s !== "" && i.some((o) => o.value === s), a = Array.isArray(t) ? t.length > 0 && t.every((o) => i.some((c) => c.value === o)) : t !== "" && i.some((o) => o.value === t);
1388
+ (Array.isArray(t) && Array.isArray(this.value) ? JSON.stringify(t.sort()) !== JSON.stringify(this.value.sort()) : this.value !== t) && (l || a) && (this.value = t), e && e(h);
1389
+ },
1319
1390
  getCleanValue(h) {
1320
1391
  const e = this.$props.multiple;
1321
1392
  return typeof h == "string" ? e ? [h] : h : Array.isArray(h) ? e ? h : h[0] : e ? [] : "";
1393
+ },
1394
+ syncModelValueToSlimSelect(h = !1) {
1395
+ if (!this.slim || this.$props.modelValue === void 0)
1396
+ return;
1397
+ const e = this.getCleanValue(this.$props.modelValue), s = this.slim.getData().flatMap((l) => "label" in l ? l.options : [l]);
1398
+ if (!(Array.isArray(e) ? e.length > 0 && e.every((l) => s.some((a) => a.value === l)) : e !== "" && s.some((l) => l.value === e)) && !Array.isArray(e) && !s.some((a) => a.placeholder)) {
1399
+ const a = this.slim.getData(), n = {
1400
+ value: "",
1401
+ text: "",
1402
+ placeholder: !0
1403
+ };
1404
+ this.slim.setData([n].concat(a));
1405
+ }
1406
+ this.slim.setSelected(e, h);
1322
1407
  }
1323
1408
  }
1324
- }), $ = (h, e) => {
1409
+ }), _ = (h, e) => {
1325
1410
  const t = h.__vccOpts || h;
1326
1411
  for (const [s, i] of e)
1327
1412
  t[s] = i;
1328
1413
  return t;
1329
- }, U = ["multiple"];
1414
+ }, $ = ["multiple"];
1330
1415
  function q(h, e, t, s, i, l) {
1331
1416
  return D(), T("select", {
1332
1417
  multiple: h.multiple,
1333
1418
  ref: "slim"
1334
1419
  }, [
1335
1420
  k(h.$slots, "default")
1336
- ], 8, U);
1421
+ ], 8, $);
1337
1422
  }
1338
- const z = /* @__PURE__ */ $(R, [["render", q]]);
1423
+ const z = /* @__PURE__ */ _(R, [["render", q]]);
1339
1424
  export {
1340
1425
  m as Optgroup,
1341
1426
  p as Option,