slim-select 4.2.4 → 4.4.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.
@@ -944,7 +944,7 @@ var O = class {
944
944
  this.settings.showSearch && (this.content.status.textContent = e);
945
945
  }
946
946
  repositionOpenContent() {
947
- !this.settings.isOpen || this.isModalViewActive() || this.settings.contentPosition !== "relative" && this.content.main.classList.contains(this.classes.getFirst("dirAbove")) && this.moveContentAbove();
947
+ this.settings.isOpen && !this.isModalViewActive() && this.settings.contentPosition !== "relative" && this.content.main.classList.contains(this.classes.getFirst("dirAbove")) && this.moveContentAbove();
948
948
  }
949
949
  moveContent() {
950
950
  if (!this.isModalViewActive()) {
@@ -964,14 +964,14 @@ var O = class {
964
964
  }
965
965
  }
966
966
  startPositionTracking() {
967
- this.settings.contentPosition !== "absolute" || this.isModalViewActive() || (this.stopPositionTracking(), !(typeof ResizeObserver > "u") && (this.lastObservedContentHeight = -1, this.positionObserver = new ResizeObserver((e) => {
967
+ this.settings.contentPosition !== "absolute" || this.isModalViewActive() || (this.stopPositionTracking(), typeof ResizeObserver < "u" && (this.lastObservedContentHeight = -1, this.positionObserver = new ResizeObserver((e) => {
968
968
  if (!this.settings.isOpen) return;
969
969
  let t = !1, n = !1;
970
970
  for (let r of e) if (r.target === this.content.main) {
971
971
  let e = r.contentRect.height;
972
972
  e !== this.lastObservedContentHeight && (this.lastObservedContentHeight = e, t = !0);
973
973
  } else n = !0;
974
- !t && !n || (cancelAnimationFrame(this.positionObserverRaf), this.positionObserverRaf = requestAnimationFrame(() => {
974
+ (t || n) && (cancelAnimationFrame(this.positionObserverRaf), this.positionObserverRaf = requestAnimationFrame(() => {
975
975
  n ? this.moveContent() : this.repositionOpenContent();
976
976
  }));
977
977
  }), this.observePositionTargets()));
@@ -982,7 +982,7 @@ var O = class {
982
982
  observePositionTargets() {
983
983
  if (!this.positionObserver) return;
984
984
  let e = /* @__PURE__ */ new Set(), t = (t) => {
985
- !t || e.has(t) || (e.add(t), this.positionObserver.observe(t));
985
+ t && !e.has(t) && (e.add(t), this.positionObserver.observe(t));
986
986
  };
987
987
  t(this.main.main), t(this.content.main);
988
988
  let n = this.main.main.parentElement, r = this.settings.contentLocation;
@@ -1038,7 +1038,7 @@ var O = class {
1038
1038
  let e = this.store.getSelected();
1039
1039
  e.push(t.id), this.callbacks.setSelected(e, !0);
1040
1040
  } else this.callbacks.setSelected([t.id], !0);
1041
- if (this.callbacks.search(""), this.settings.closeOnSelect) {
1041
+ if (this.callbacks.clearSearch(), this.settings.closeOnSelect) {
1042
1042
  let e = i(this.content.main);
1043
1043
  setTimeout(() => {
1044
1044
  this.requestClose("select", { selectionChanged: !0 });
@@ -1448,7 +1448,7 @@ var O = class {
1448
1448
  this.settings.contentPosition !== "relative" && (this.content.main.style.width = e.width + "px");
1449
1449
  return;
1450
1450
  }
1451
- t.startsWith(">") ? this.content.main.style.minWidth = t.slice(1) : t.startsWith("<") ? this.content.main.style.maxWidth = t.slice(1) : this.content.main.style.width = t;
1451
+ t === "auto" ? this.content.main.style.minWidth = e.width + "px" : t.startsWith(">") ? this.content.main.style.minWidth = t.slice(1) : t.startsWith("<") ? this.content.main.style.maxWidth = t.slice(1) : this.content.main.style.width = t;
1452
1452
  }
1453
1453
  cancelOverflowShift() {
1454
1454
  this.overflowShiftRaf &&= (cancelAnimationFrame(this.overflowShiftRaf), 0);
@@ -1489,7 +1489,7 @@ var O = class {
1489
1489
  updateDeselectAll() {
1490
1490
  if (!this.store || !this.settings) return;
1491
1491
  let e = this.store.getSelectedOptions(), t = e && e.length > 0, n = this.settings.isMultiple, r = this.settings.allowDeselect, i = this.isAtMinSelected(), a = this.main.deselect.main, o = this.classes.hide;
1492
- r && !(n && !t) && !i ? this.removeClasses(a, o) : this.addClasses(a, o);
1492
+ r && (!n || t) && !i ? this.removeClasses(a, o) : this.addClasses(a, o);
1493
1493
  }
1494
1494
  };
1495
1495
  //#endregion
@@ -1959,6 +1959,7 @@ var R = class {
1959
1959
  });
1960
1960
  },
1961
1961
  search: this.search.bind(this),
1962
+ clearSearch: this.clearSearch.bind(this),
1962
1963
  beforeChange: this.events.beforeChange,
1963
1964
  afterChange: this.events.afterChange
1964
1965
  };
@@ -1996,10 +1997,10 @@ var R = class {
1996
1997
  }), this.globalEvents = new O({
1997
1998
  onDocumentClick: this.documentClick.bind(this),
1998
1999
  onWindowResize: () => {
1999
- !this.settings.isOpen && !this.settings.isFullOpen || this.render.moveContent();
2000
+ (this.settings.isOpen || this.settings.isFullOpen) && this.render.moveContent();
2000
2001
  },
2001
2002
  onWindowScroll: () => {
2002
- !this.settings.isOpen && !this.settings.isFullOpen || this.render.moveContent();
2003
+ (this.settings.isOpen || this.settings.isFullOpen) && this.render.moveContent();
2003
2004
  },
2004
2005
  onVisibilityChange: () => {
2005
2006
  document.hidden && this.close({
@@ -2064,29 +2065,29 @@ var R = class {
2064
2065
  source: "api",
2065
2066
  selectionChanged: !1
2066
2067
  }) {
2067
- !this.settings.isOpen || this.settings.alwaysOpen || this.lifecycle.requestClose(e).then((e) => {
2068
+ this.settings.isOpen && !this.settings.alwaysOpen && this.lifecycle.requestClose(e).then((e) => {
2068
2069
  e && (this.settings.isOpen || (this.settings.isOpen = this.lifecycle.isOpen, this.settings.isFullOpen = this.lifecycle.isFullOpen));
2069
2070
  });
2070
2071
  }
2071
2072
  applyClose(e) {
2072
- this.render.close(), !this.settings.keepSearch && this.render.content.search.input.value !== "" && (this.sync.flush(), this.search(""));
2073
+ this.render.close(), !this.settings.keepSearch && this.render.content.search.input.value !== "" && (this.sync.flush(), this.clearSearch());
2073
2074
  let t = e.source === "outside" || e.source === "toggle";
2074
2075
  this.render.mainFocus(t ? "click" : null), this.settings.isOpen = !1, this.settings.isFullOpen = !1, this.render.stopPositionTracking();
2075
2076
  }
2076
2077
  search(e) {
2077
2078
  let t = e.trim();
2078
- if (t === "") {
2079
- this.render.content.search.input.value = "", this.clearSearch();
2079
+ if (t === "" ? this.render.content.search.input.value = "" : this.render.content.search.input.value !== e && (this.render.content.search.input.value = e), this.events.search) {
2080
+ this.runApiSearch(t);
2080
2081
  return;
2081
2082
  }
2082
- if (this.render.content.search.input.value !== e && (this.render.content.search.input.value = e), this.events.search) {
2083
- this.runApiSearch(t);
2083
+ if (t === "") {
2084
+ this.clearSearch();
2084
2085
  return;
2085
2086
  }
2086
2087
  this.runLocalSearch(t);
2087
2088
  }
2088
2089
  clearSearch() {
2089
- if (this.searchGeneration++, !this.events.search && this.render.canFilterOptionsInPlace()) {
2090
+ if (this.render.content.search.input.value = "", this.searchGeneration++, !this.events.search && this.render.canFilterOptionsInPlace()) {
2090
2091
  this.render.filterOptionsInPlace("", this.events.searchFilter), this.render.resetSearchFilterState();
2091
2092
  return;
2092
2093
  }