slim-select 3.1.3 → 3.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -74,7 +74,7 @@ function T(p, e) {
74
74
  }
75
75
  return t(p, e) || s(p, e);
76
76
  }
77
- function S(p, e = 50, t = !1) {
77
+ function O(p, e = 50, t = !1) {
78
78
  let s;
79
79
  return function(...i) {
80
80
  const l = self, a = () => {
@@ -330,9 +330,21 @@ class N {
330
330
  }
331
331
  }
332
332
  close() {
333
- this.main.main.setAttribute("aria-expanded", "false"), this.main.arrow.path.setAttribute("d", this.classes.arrowClose), this.content.main.classList.remove(this.classes.contentOpen), this.content.search.input.setAttribute("aria-hidden", "true"), this.main.main.removeAttribute("aria-activedescendant"), setTimeout(() => {
333
+ this.main.main.setAttribute("aria-expanded", "false"), this.main.arrow.path.setAttribute("d", this.classes.arrowClose), this.content.main.classList.remove(this.classes.contentOpen), this.content.search.input.setAttribute("aria-hidden", "true"), this.main.main.removeAttribute("aria-activedescendant");
334
+ const e = this.getAnimationTiming();
335
+ setTimeout(() => {
334
336
  this.main.main.classList.remove(this.classes.dirAbove, this.classes.dirBelow), this.content.main.classList.remove(this.classes.dirAbove, this.classes.dirBelow);
335
- }, 100);
337
+ }, e);
338
+ }
339
+ getAnimationTiming() {
340
+ const t = getComputedStyle(this.content.main).getPropertyValue("--ss-animation-timing").trim();
341
+ if (t) {
342
+ if (t.endsWith("ms"))
343
+ return parseFloat(t);
344
+ if (t.endsWith("s"))
345
+ return parseFloat(t) * 1e3;
346
+ }
347
+ return 200;
336
348
  }
337
349
  updateClassStyles() {
338
350
  if (this.main.main.className = "", this.main.main.removeAttribute("style"), this.content.main.className = "", this.content.main.removeAttribute("style"), this.main.main.classList.add(this.classes.main), this.content.main.classList.add(this.classes.content), this.settings.style !== "" && (this.main.main.style.cssText = this.settings.style, this.content.main.style.cssText = this.settings.style), this.settings.class.length)
@@ -535,7 +547,7 @@ class N {
535
547
  main: e,
536
548
  input: t
537
549
  };
538
- if (this.settings.showSearch || (e.classList.add(this.classes.hide), t.readOnly = !0), t.type = "search", t.placeholder = this.settings.searchPlaceholder, t.tabIndex = -1, t.setAttribute("aria-label", this.settings.searchPlaceholder), t.setAttribute("aria-autocomplete", "list"), t.setAttribute("autocapitalize", "off"), t.setAttribute("autocomplete", "off"), t.setAttribute("autocorrect", "off"), t.setAttribute("aria-hidden", "true"), t.oninput = S((l) => {
550
+ if (this.settings.showSearch || (e.classList.add(this.classes.hide), t.readOnly = !0), t.type = "search", t.placeholder = this.settings.searchPlaceholder, t.tabIndex = -1, t.setAttribute("aria-label", this.settings.searchPlaceholder), t.setAttribute("aria-autocomplete", "list"), t.setAttribute("autocapitalize", "off"), t.setAttribute("autocomplete", "off"), t.setAttribute("autocorrect", "off"), t.setAttribute("aria-hidden", "true"), t.oninput = O((l) => {
539
551
  this.callbacks.search(l.target.value);
540
552
  }, 100), t.onkeydown = (l) => {
541
553
  switch (l.key) {
@@ -597,7 +609,7 @@ class N {
597
609
  return i;
598
610
  }
599
611
  searchFocus() {
600
- this.content.search.input.focus();
612
+ this.content.search.input.focus({ preventScroll: !0 });
601
613
  }
602
614
  getOptions(e = !1, t = !1, s = !1) {
603
615
  let i = "." + this.classes.option;
@@ -707,9 +719,9 @@ class N {
707
719
  m.preventDefault(), m.stopPropagation();
708
720
  const v = this.store.getSelected();
709
721
  if (c) {
710
- const w = v.filter((O) => {
722
+ const w = v.filter((S) => {
711
723
  for (const b of s.options)
712
- if (O === b.id)
724
+ if (S === b.id)
713
725
  return !1;
714
726
  return !0;
715
727
  });
@@ -717,10 +729,10 @@ class N {
717
729
  return;
718
730
  } else {
719
731
  let w = s.options.map((b) => b.id).filter((b) => b !== void 0);
720
- const O = v.concat(w);
732
+ const S = v.concat(w);
721
733
  for (const b of s.options)
722
734
  b.id && !this.store.getOptionByID(b.id) && this.callbacks.addOption(new u(b));
723
- this.callbacks.setSelected(O, !0);
735
+ this.callbacks.setSelected(S, !0);
724
736
  return;
725
737
  }
726
738
  }), n.appendChild(o);
@@ -769,7 +781,7 @@ class N {
769
781
  if (s.shiftKey && this.lastSelectedOption) {
770
782
  const d = this.store.getDataOptions(), m = d.findIndex((w) => w.id === this.lastSelectedOption.id), v = d.findIndex((w) => w.id === e.id);
771
783
  if (m >= 0 && v >= 0) {
772
- const w = Math.min(m, v), O = Math.max(m, v), y = d.slice(w, O + 1).filter((x) => !c.find((E) => E.id === x.id));
784
+ const w = Math.min(m, v), S = Math.max(m, v), y = d.slice(w, S + 1).filter((x) => !c.find((E) => E.id === x.id));
773
785
  c.length + y.length <= this.settings.maxSelected ? r = c.concat(y) : r = c;
774
786
  } else
775
787
  r = c;
@@ -896,28 +908,30 @@ class M {
896
908
  observeCall(e) {
897
909
  if (!this.listen)
898
910
  return;
899
- let t = !1, s = !1, i = !1;
900
- for (const l of e) {
901
- if (l.target === this.select && (l.attributeName === "disabled" && (s = !0), l.attributeName === "class" && (t = !0), l.type === "childList")) {
902
- for (const a of Array.from(l.addedNodes))
903
- if (a.nodeName === "OPTION" && a.value === this.select.value) {
904
- this.select.dispatchEvent(new Event("change"));
911
+ let t = !1, s = !1, i = !1, l = !1;
912
+ for (const a of e) {
913
+ if (a.target === this.select && (a.attributeName === "disabled" && (s = !0), a.attributeName === "class" && (t = !0), a.type === "childList")) {
914
+ for (const n of Array.from(a.addedNodes))
915
+ if (n.nodeName === "OPTION" && n.value === this.select.value) {
916
+ l = !0;
905
917
  break;
906
918
  }
907
919
  i = !0;
908
920
  }
909
- (l.target.nodeName === "OPTGROUP" || l.target.nodeName === "OPTION") && (i = !0);
921
+ (a.target.nodeName === "OPTGROUP" || a.target.nodeName === "OPTION") && (i = !0);
910
922
  }
911
923
  if (t && this.onClassChange && this.onClassChange(this.select.className.split(" ")), s && this.onDisabledChange && (this.changeListen(!1), this.onDisabledChange(this.select.disabled), this.changeListen(!0)), i && this.onOptionsChange) {
912
924
  if (this.isUpdating) {
913
925
  if (this.select.options.length > 0) {
914
- const l = this.getData();
915
- l.length > 0 && (this.pendingOptionsChange = l);
926
+ const a = this.getData();
927
+ a.length > 0 && (this.pendingOptionsChange = a);
916
928
  }
929
+ l && this.select.dispatchEvent(new Event("change"));
917
930
  return;
918
931
  }
919
932
  this.changeListen(!1), this.onOptionsChange(this.getData()), this.changeListen(!0);
920
933
  }
934
+ l && this.select.dispatchEvent(new Event("change"));
921
935
  }
922
936
  // From the select element pull optgroup and options into data
923
937
  getData() {
@@ -1070,9 +1084,8 @@ class M {
1070
1084
  if (l.__slimSelectLabelHandler)
1071
1085
  return;
1072
1086
  const a = (n) => {
1073
- n.preventDefault(), n.stopPropagation(), this.onLabelClick && setTimeout(() => {
1074
- this.onLabelClick();
1075
- }, 0);
1087
+ const o = n.target;
1088
+ n.preventDefault(), o === l && this.onLabelClick && this.onLabelClick();
1076
1089
  };
1077
1090
  l.__slimSelectLabelHandler = a, l.addEventListener("click", a, { capture: !0, passive: !1 });
1078
1091
  });
@@ -1115,6 +1128,7 @@ class P {
1115
1128
  alwaysOpen;
1116
1129
  showSearch;
1117
1130
  focusSearch;
1131
+ keepSearch;
1118
1132
  ariaLabel;
1119
1133
  searchPlaceholder;
1120
1134
  searchText;
@@ -1136,7 +1150,7 @@ class P {
1136
1150
  maxValuesMessage;
1137
1151
  addableText;
1138
1152
  constructor(e) {
1139
- e || (e = {}), this.id = "ss-" + C(), this.style = e.style || "", this.class = e.class || [], this.disabled = e.disabled !== void 0 ? e.disabled : !1, this.alwaysOpen = e.alwaysOpen !== void 0 ? e.alwaysOpen : !1, this.showSearch = e.showSearch !== void 0 ? e.showSearch : !0, this.focusSearch = e.focusSearch !== void 0 ? e.focusSearch : !0, this.ariaLabel = e.ariaLabel || "Combobox", this.searchPlaceholder = e.searchPlaceholder || "Search...", this.searchText = e.searchText || "No Results", this.searchingText = e.searchingText || "Searching...", this.searchHighlight = e.searchHighlight !== void 0 ? e.searchHighlight : !1, this.closeOnSelect = e.closeOnSelect !== void 0 ? e.closeOnSelect : !0, this.contentLocation = e.contentLocation || document.body, this.contentPosition = e.contentPosition || "absolute", this.openPosition = e.openPosition || "auto", this.placeholderText = e.placeholderText !== void 0 ? e.placeholderText : "Select Value", this.allowDeselect = e.allowDeselect !== void 0 ? e.allowDeselect : !1, this.hideSelected = e.hideSelected !== void 0 ? e.hideSelected : !1, this.keepOrder = e.keepOrder !== void 0 ? e.keepOrder : !1, this.showOptionTooltips = e.showOptionTooltips !== void 0 ? e.showOptionTooltips : !1, this.minSelected = e.minSelected || 0, this.maxSelected = e.maxSelected || 1e3, this.timeoutDelay = e.timeoutDelay || 200, this.maxValuesShown = e.maxValuesShown || 20, this.maxValuesMessage = e.maxValuesMessage || "{number} selected", this.addableText = e.addableText || 'Press "Enter" to add {value}';
1153
+ e || (e = {}), this.id = "ss-" + C(), this.style = e.style || "", this.class = e.class || [], this.disabled = e.disabled !== void 0 ? e.disabled : !1, this.alwaysOpen = e.alwaysOpen !== void 0 ? e.alwaysOpen : !1, this.showSearch = e.showSearch !== void 0 ? e.showSearch : !0, this.focusSearch = e.focusSearch !== void 0 ? e.focusSearch : !0, this.keepSearch = e.keepSearch !== void 0 ? e.keepSearch : !1, this.ariaLabel = e.ariaLabel || "Combobox", this.searchPlaceholder = e.searchPlaceholder || "Search...", this.searchText = e.searchText || "No Results", this.searchingText = e.searchingText || "Searching...", this.searchHighlight = e.searchHighlight !== void 0 ? e.searchHighlight : !1, this.closeOnSelect = e.closeOnSelect !== void 0 ? e.closeOnSelect : !0, this.contentLocation = e.contentLocation || document.body, this.contentPosition = e.contentPosition || "absolute", this.openPosition = e.openPosition || "auto", this.placeholderText = e.placeholderText !== void 0 ? e.placeholderText : "Select Value", this.allowDeselect = e.allowDeselect !== void 0 ? e.allowDeselect : !1, this.hideSelected = e.hideSelected !== void 0 ? e.hideSelected : !1, this.keepOrder = e.keepOrder !== void 0 ? e.keepOrder : !1, this.showOptionTooltips = e.showOptionTooltips !== void 0 ? e.showOptionTooltips : !1, this.minSelected = e.minSelected || 0, this.maxSelected = e.maxSelected || 1e3, this.timeoutDelay = e.timeoutDelay || 200, this.maxValuesShown = e.maxValuesShown || 20, this.maxValuesMessage = e.maxValuesMessage || "{number} selected", this.addableText = e.addableText || 'Press "Enter" to add {value}';
1140
1154
  }
1141
1155
  }
1142
1156
  class I {
@@ -1174,7 +1188,7 @@ class I {
1174
1188
  this.selectEl.dataset.ssid && this.destroy(), this.settings = new P(e.settings), this.cssClasses = new A(e.cssClasses);
1175
1189
  const t = ["beforeOpen", "afterOpen", "beforeClose", "afterClose"];
1176
1190
  for (const n in e.events)
1177
- e.events.hasOwnProperty(n) && (t.indexOf(n) !== -1 ? this.events[n] = S(e.events[n], 100) : this.events[n] = e.events[n]);
1191
+ e.events.hasOwnProperty(n) && (t.indexOf(n) !== -1 ? this.events[n] = O(e.events[n], 100) : this.events[n] = e.events[n]);
1178
1192
  this.settings.disabled = e.settings?.disabled ? e.settings.disabled : this.selectEl.disabled, this.settings.isMultiple = this.selectEl.multiple, this.settings.style = this.selectEl.style.cssText, this.settings.class = this.selectEl.className.split(" "), this.select = new M(this.selectEl), this.selectEl.id || (this.selectEl.id = this.settings.id), this.select.updateSelect(this.settings.id, this.settings.style, this.settings.class), this.select.hideUI(), this.select.onValueChange = (n) => {
1179
1193
  this.setSelected(n.map((o) => o.id));
1180
1194
  }, this.select.onClassChange = (n) => {
@@ -1184,7 +1198,7 @@ class I {
1184
1198
  }, this.select.onOptionsChange = (n) => {
1185
1199
  this.setData(n || []);
1186
1200
  }, this.select.onLabelClick = () => {
1187
- this.settings.disabled || this.open();
1201
+ this.settings.disabled || (this.settings.isOpen ? this.close() : this.open());
1188
1202
  };
1189
1203
  const s = e.data ? e.data : this.select.getData();
1190
1204
  this.store = new k(this.settings.isMultiple ? "multiple" : "single", s), e.data && this.select.updateOptions(this.store.getData());
@@ -1256,7 +1270,7 @@ class I {
1256
1270
  }, this.settings.timeoutDelay), this.settings.contentPosition === "absolute" && (this.settings.intervalMove && clearInterval(this.settings.intervalMove), this.settings.intervalMove = setInterval(this.render.moveContent.bind(this.render), 500)));
1257
1271
  }
1258
1272
  close(e = null) {
1259
- !this.settings.isOpen || this.settings.alwaysOpen || (this.events.beforeClose && this.events.beforeClose(), this.render.close(), this.render.content.search.input.value !== "" && this.search(""), this.render.mainFocus(e), this.settings.isOpen = !1, this.settings.isFullOpen = !1, this.closeTimeout = setTimeout(() => {
1273
+ !this.settings.isOpen || this.settings.alwaysOpen || (this.events.beforeClose && this.events.beforeClose(), this.render.close(), !this.settings.keepSearch && this.render.content.search.input.value !== "" && this.search(""), this.render.mainFocus(e), this.settings.isOpen = !1, this.settings.isFullOpen = !1, this.closeTimeout = setTimeout(() => {
1260
1274
  this.events.afterClose && this.events.afterClose(), document.removeEventListener("click", this.documentClick);
1261
1275
  }, this.settings.timeoutDelay), this.settings.intervalMove && clearInterval(this.settings.intervalMove));
1262
1276
  }
@@ -1285,11 +1299,11 @@ class I {
1285
1299
  destroy() {
1286
1300
  this.openTimeout && (clearTimeout(this.openTimeout), this.openTimeout = null), this.closeTimeout && (clearTimeout(this.closeTimeout), this.closeTimeout = null), this.settings.intervalMove && (clearInterval(this.settings.intervalMove), this.settings.intervalMove = null), document.removeEventListener("click", this.documentClick), window.removeEventListener("resize", this.windowResize, !1), this.settings.openPosition === "auto" && window.removeEventListener("scroll", this.windowScroll, !1), document.removeEventListener("visibilitychange", this.windowVisibilityChange), this.store.setData([]), this.render.destroy(), this.select.destroy();
1287
1301
  }
1288
- windowResize = S(() => {
1302
+ windowResize = O(() => {
1289
1303
  !this.settings.isOpen && !this.settings.isFullOpen || this.render.moveContent();
1290
1304
  });
1291
1305
  // Event listener for window scrolling
1292
- windowScroll = S(() => {
1306
+ windowScroll = O(() => {
1293
1307
  !this.settings.isOpen && !this.settings.isFullOpen || this.render.moveContent();
1294
1308
  });
1295
1309
  // Event listener for document click