slim-select 3.3.0 → 3.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.
@@ -70,7 +70,7 @@ class L {
70
70
  function y() {
71
71
  return Math.random().toString(36).substring(2, 10);
72
72
  }
73
- function A(p, e) {
73
+ function x(p, e) {
74
74
  function t(i, l) {
75
75
  return l && i && i.classList && i.classList.contains(l) || l && i && i.dataset && i.dataset.id && i.dataset.id === e ? i : null;
76
76
  }
@@ -113,7 +113,7 @@ class u {
113
113
  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 || {};
114
114
  }
115
115
  }
116
- class g {
116
+ class m {
117
117
  id;
118
118
  label;
119
119
  selectAll;
@@ -140,7 +140,7 @@ class k {
140
140
  return new Error("Data must be an array");
141
141
  for (let t of e)
142
142
  if (t)
143
- if (t instanceof g || "label" in t) {
143
+ if (t instanceof m || "label" in t) {
144
144
  if (!("label" in t))
145
145
  return new Error("Optgroup must have a label");
146
146
  if ("options" in t && t.options)
@@ -165,11 +165,11 @@ class k {
165
165
  let t = [];
166
166
  return e.forEach((s) => {
167
167
  if (s) {
168
- if (s instanceof g || "label" in s) {
168
+ if (s instanceof m || "label" in s) {
169
169
  let i = [];
170
170
  "options" in s && s.options && s.options.forEach((l) => {
171
171
  i.push(new u(l));
172
- }), i.length > 0 && t.push(new g(s));
172
+ }), i.length > 0 && t.push(new m(s));
173
173
  }
174
174
  (s instanceof u || "text" in s) && t.push(new u(s));
175
175
  }
@@ -186,7 +186,7 @@ class k {
186
186
  a = !0;
187
187
  break;
188
188
  }
189
- if (o instanceof g) {
189
+ if (o instanceof m) {
190
190
  for (const h of o.options)
191
191
  if (h.id === n.id) {
192
192
  a = !0;
@@ -223,7 +223,7 @@ class k {
223
223
  let s = null, i = !1;
224
224
  const l = [];
225
225
  for (let a of this.data) {
226
- if (a instanceof g)
226
+ if (a instanceof m)
227
227
  for (let o of a.options) {
228
228
  s || (s = o);
229
229
  let h = o[e] || "";
@@ -246,7 +246,7 @@ class k {
246
246
  }
247
247
  getOptgroupByID(e) {
248
248
  for (let t of this.data)
249
- if (t instanceof g && t.id === e)
249
+ if (t instanceof m && t.id === e)
250
250
  return t;
251
251
  return null;
252
252
  }
@@ -260,7 +260,7 @@ class k {
260
260
  getFirstOption() {
261
261
  let e = null;
262
262
  for (let t of this.data)
263
- if (t instanceof g ? e = t.options[0] : t instanceof u && (e = t), e)
263
+ if (t instanceof m ? e = t.options[0] : t instanceof u && (e = t), e)
264
264
  break;
265
265
  return e;
266
266
  }
@@ -273,12 +273,12 @@ class k {
273
273
  filter(e, t) {
274
274
  const s = [];
275
275
  return this.data.forEach((i) => {
276
- if (i instanceof g) {
276
+ if (i instanceof m) {
277
277
  let l = [];
278
278
  if (i.options.forEach((a) => {
279
279
  (!e || e(a)) && (t ? l.push(new u(a)) : s.push(new u(a)));
280
280
  }), l.length > 0) {
281
- let a = new g(i);
281
+ let a = new m(i);
282
282
  a.options = l, s.push(a);
283
283
  }
284
284
  }
@@ -418,8 +418,8 @@ class N {
418
418
  if (this.settings.isMultiple)
419
419
  this.callbacks.setSelected([], !1), this.updateDeselectAll();
420
420
  else {
421
- const d = this.store.getFirstOption(), m = d ? d.id : "";
422
- this.callbacks.setSelected(m, !1);
421
+ const d = this.store.getFirstOption(), g = d ? d.id : "";
422
+ this.callbacks.setSelected(g, !1);
423
423
  }
424
424
  this.settings.closeOnSelect && this.callbacks.close(), this.callbacks.afterChange && this.callbacks.afterChange(this.store.getSelectedOptions());
425
425
  }
@@ -523,7 +523,7 @@ class N {
523
523
  if (!(this.settings.minSelected && r.length < this.settings.minSelected) && (this.callbacks.beforeChange && (o = this.callbacks.beforeChange(r, h) === !0), o)) {
524
524
  let c = [];
525
525
  for (const f of r) {
526
- if (f instanceof g)
526
+ if (f instanceof m)
527
527
  for (const d of f.options)
528
528
  d.id && c.push(d.id);
529
529
  f instanceof u && c.push(f.id);
@@ -722,7 +722,7 @@ class N {
722
722
  ));
723
723
  const t = document.createDocumentFragment();
724
724
  for (const s of e) {
725
- if (s instanceof g) {
725
+ if (s instanceof m) {
726
726
  const i = document.createElement("div");
727
727
  this.addClasses(i, this.classes.optgroup);
728
728
  const l = document.createElement("div");
@@ -734,8 +734,8 @@ class N {
734
734
  const o = document.createElement("div");
735
735
  this.addClasses(o, this.classes.optgroupSelectAll);
736
736
  let h = !0;
737
- for (const m of s.options)
738
- if (!m.selected) {
737
+ for (const g of s.options)
738
+ if (!g.selected) {
739
739
  h = !1;
740
740
  break;
741
741
  }
@@ -747,8 +747,8 @@ class N {
747
747
  const f = document.createElementNS("http://www.w3.org/2000/svg", "path");
748
748
  f.setAttribute("d", this.classes.optgroupSelectAllBox), c.appendChild(f);
749
749
  const d = document.createElementNS("http://www.w3.org/2000/svg", "path");
750
- d.setAttribute("d", this.classes.optgroupSelectAllCheck), c.appendChild(d), o.addEventListener("click", (m) => {
751
- m.preventDefault(), m.stopPropagation();
750
+ d.setAttribute("d", this.classes.optgroupSelectAllCheck), c.appendChild(d), o.addEventListener("click", (g) => {
751
+ g.preventDefault(), g.stopPropagation();
752
752
  const v = this.store.getSelected();
753
753
  if (h) {
754
754
  const C = v.filter((w) => {
@@ -811,9 +811,9 @@ class N {
811
811
  if (this.settings.isMultiple) {
812
812
  const c = h.some((d) => d.id === n);
813
813
  if (s.shiftKey && this.lastSelectedOption) {
814
- const d = this.store.getDataOptions(), m = d.findIndex((C) => C.id === this.lastSelectedOption.id), v = d.findIndex((C) => C.id === e.id);
815
- if (m >= 0 && v >= 0) {
816
- const C = Math.min(m, v), w = Math.max(m, v), E = d.slice(C, w + 1).filter((x) => !h.find((T) => T.id === x.id));
814
+ const d = this.store.getDataOptions(), g = d.findIndex((C) => C.id === this.lastSelectedOption.id), v = d.findIndex((C) => C.id === e.id);
815
+ if (g >= 0 && v >= 0) {
816
+ const C = Math.min(g, v), w = Math.max(g, v), E = d.slice(C, w + 1).filter((A) => !h.find((T) => T.id === A.id));
817
817
  h.length + E.length <= this.settings.maxSelected ? r = h.concat(E) : r = h;
818
818
  } else
819
819
  r = h;
@@ -843,7 +843,7 @@ class N {
843
843
  const h = o.textContent || "", r = new RegExp("(" + l + ")", "i");
844
844
  if (r.test(h)) {
845
845
  const c = document.createElement("span");
846
- h.split(r).forEach((d, m) => {
846
+ h.split(r).forEach((d, g) => {
847
847
  if (d && r.test(d)) {
848
848
  const v = document.createElement("mark");
849
849
  v.className = s, v.textContent = d, c.appendChild(v);
@@ -867,13 +867,9 @@ class N {
867
867
  return;
868
868
  const e = this.main.main.getBoundingClientRect();
869
869
  let t, s;
870
- if (this.settings.contentPosition === "fixed")
871
- t = e.top + e.height, s = e.left;
872
- else {
873
- const i = this.content.main.offsetParent, l = i ? i.getBoundingClientRect() : { top: 0, left: 0 };
874
- t = e.top - l.top + e.height - (i?.clientTop || 0), s = e.left - l.left - (i?.clientLeft || 0);
875
- }
876
- this.content.main.style.top = t + "px", this.content.main.style.left = s + "px", this.content.main.style.width = e.width + "px";
870
+ this.settings.contentPosition === "fixed" ? (t = e.top + e.height, s = e.left) : (t = e.top + window.scrollY + e.height, s = e.left + window.scrollX), this.content.main.style.top = t + "px", this.content.main.style.left = s + "px";
871
+ const i = this.settings.contentWidth;
872
+ this.content.main.style.width = "", this.content.main.style.minWidth = "", this.content.main.style.maxWidth = "", i ? i.startsWith(">") ? this.content.main.style.minWidth = i.slice(1) : i.startsWith("<") ? this.content.main.style.maxWidth = i.slice(1) : this.content.main.style.width = i : this.content.main.style.width = e.width + "px";
877
873
  }
878
874
  moveContentAbove() {
879
875
  this.setContentDirection("above"), this.setContentPosition();
@@ -897,7 +893,7 @@ class N {
897
893
  i && !(s && !t) ? this.removeClasses(l, n) : this.addClasses(l, n);
898
894
  }
899
895
  }
900
- class P {
896
+ class M {
901
897
  select;
902
898
  // Mutation observer fields
903
899
  onValueChange;
@@ -1094,7 +1090,7 @@ class P {
1094
1090
  if (!(!e || e.length === 0)) {
1095
1091
  this.isUpdating = !0, this.pendingOptionsChange = null, this.changeListen(!1), this.select.innerHTML = "";
1096
1092
  for (const t of e)
1097
- t instanceof g && this.select.appendChild(this.createOptgroup(t)), t instanceof u && this.select.appendChild(this.createOption(t));
1093
+ t instanceof m && this.select.appendChild(this.createOptgroup(t)), t instanceof u && this.select.appendChild(this.createOption(t));
1098
1094
  if (this.select.dispatchEvent(new Event("change", { bubbles: !0 })), this.changeListen(!0), this.isUpdating = !1, this.pendingOptionsChange !== null) {
1099
1095
  const t = this.pendingOptionsChange;
1100
1096
  t.length > 0 && this.onOptionsChange ? (this.pendingOptionsChange = null, this.changeListen(!1), this.onOptionsChange(t), this.changeListen(!0)) : this.pendingOptionsChange = null;
@@ -1132,7 +1128,7 @@ class P {
1132
1128
  if (l.__slimSelectLabelHandler)
1133
1129
  return;
1134
1130
  const n = (a) => {
1135
- const o = a.target, h = A(o, this.select.dataset.id);
1131
+ const o = a.target, h = x(o, this.select.dataset.id);
1136
1132
  a.preventDefault(), !h && this.onLabelClick && this.onLabelClick();
1137
1133
  };
1138
1134
  l.__slimSelectLabelHandler = n, l.addEventListener("click", n, { capture: !0, passive: !1 });
@@ -1159,7 +1155,7 @@ class P {
1159
1155
  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();
1160
1156
  }
1161
1157
  }
1162
- class M {
1158
+ class P {
1163
1159
  id = "";
1164
1160
  // Primary ID for the select
1165
1161
  style = "";
@@ -1185,6 +1181,7 @@ class M {
1185
1181
  closeOnSelect;
1186
1182
  contentLocation;
1187
1183
  contentPosition;
1184
+ contentWidth;
1188
1185
  openPosition;
1189
1186
  placeholderText;
1190
1187
  allowDeselect;
@@ -1198,7 +1195,7 @@ class M {
1198
1195
  maxValuesMessage;
1199
1196
  addableText;
1200
1197
  constructor(e) {
1201
- 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.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}';
1198
+ 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.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.contentWidth = e.contentWidth || "", 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}';
1202
1199
  }
1203
1200
  }
1204
1201
  class F {
@@ -1233,11 +1230,11 @@ class F {
1233
1230
  e.events && e.events.error && e.events.error(new Error("Element isnt of type select"));
1234
1231
  return;
1235
1232
  }
1236
- this.selectEl.dataset.ssid && this.destroy(), this.settings = new M(e.settings), this.cssClasses = new L(e.cssClasses);
1233
+ this.selectEl.dataset.ssid && this.destroy(), this.settings = new P(e.settings), this.cssClasses = new L(e.cssClasses);
1237
1234
  const t = ["beforeOpen", "afterOpen", "beforeClose", "afterClose"];
1238
1235
  for (const a in e.events)
1239
1236
  e.events.hasOwnProperty(a) && (t.indexOf(a) !== -1 ? this.events[a] = S(e.events[a], 100) : this.events[a] = e.events[a]);
1240
- 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 P(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 = (a) => {
1237
+ 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 = (a) => {
1241
1238
  this.setSelected(a.map((o) => o.id));
1242
1239
  }, this.select.onClassChange = (a) => {
1243
1240
  this.settings.class = a, this.render.updateClassStyles();
@@ -1356,7 +1353,7 @@ class F {
1356
1353
  });
1357
1354
  // Event listener for document click
1358
1355
  documentClick = (e) => {
1359
- this.settings.isOpen && e.target && !A(e.target, this.settings.id) && this.close(e.type);
1356
+ this.settings.isOpen && e.target && !x(e.target, this.settings.id) && this.close(e.type);
1360
1357
  };
1361
1358
  // Event Listener for window visibility change
1362
1359
  windowVisibilityChange = () => {
@@ -1364,9 +1361,9 @@ class F {
1364
1361
  };
1365
1362
  }
1366
1363
  export {
1367
- g as Optgroup,
1364
+ m as Optgroup,
1368
1365
  u as Option,
1369
- M as Settings,
1366
+ P as Settings,
1370
1367
  F as default
1371
1368
  };
1372
1369
  //# sourceMappingURL=slimselect.es.js.map