slim-select 3.4.2 → 3.4.3

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.
package/dist/index.d.ts CHANGED
@@ -131,6 +131,7 @@ declare class Render {
131
131
  store: Store;
132
132
  callbacks: Callbacks;
133
133
  private lastSelectedOption;
134
+ private lastRenderedOptions;
134
135
  private closeAnimationTimeout;
135
136
  main: Main;
136
137
  content: Content;
@@ -131,6 +131,7 @@ declare class Render {
131
131
  store: Store;
132
132
  callbacks: Callbacks;
133
133
  private lastSelectedOption;
134
+ private lastRenderedOptions;
134
135
  private closeAnimationTimeout;
135
136
  main: Main;
136
137
  content: Content;
@@ -55,7 +55,7 @@ function de() {
55
55
  return a.displayName || "Context";
56
56
  case k:
57
57
  return (a._context.displayName || "Context") + ".Consumer";
58
- case b:
58
+ case C:
59
59
  var u = a.render;
60
60
  return a = a.displayName, a || (a = u.displayName || u.name || "", a = a !== "" ? "ForwardRef(" + a + ")" : "ForwardRef"), a;
61
61
  case B:
@@ -81,8 +81,8 @@ function de() {
81
81
  }
82
82
  if (u) {
83
83
  u = console;
84
- var C = u.error, O = typeof Symbol == "function" && Symbol.toStringTag && a[Symbol.toStringTag] || a.constructor.name || "Object";
85
- return C.call(
84
+ var w = u.error, O = typeof Symbol == "function" && Symbol.toStringTag && a[Symbol.toStringTag] || a.constructor.name || "Object";
85
+ return w.call(
86
86
  u,
87
87
  "The provided key is an unsupported type %s. This value must be coerced to a string before using it here.",
88
88
  O
@@ -115,14 +115,14 @@ function de() {
115
115
  return a.key !== void 0;
116
116
  }
117
117
  function r(a, u) {
118
- function C() {
118
+ function w() {
119
119
  G || (G = !0, console.error(
120
120
  "%s: `key` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://react.dev/link/special-props)",
121
121
  u
122
122
  ));
123
123
  }
124
- C.isReactWarning = !0, Object.defineProperty(a, "key", {
125
- get: C,
124
+ w.isReactWarning = !0, Object.defineProperty(a, "key", {
125
+ get: w,
126
126
  configurable: !0
127
127
  });
128
128
  }
@@ -132,13 +132,13 @@ function de() {
132
132
  "Accessing element.ref was removed in React 19. ref is now a regular prop. It will be removed from the JSX Element type in a future release."
133
133
  )), a = this.props.ref, a !== void 0 ? a : null;
134
134
  }
135
- function h(a, u, C, O, F, U) {
136
- var y = C.ref;
135
+ function h(a, u, w, O, F, U) {
136
+ var y = w.ref;
137
137
  return a = {
138
138
  $$typeof: E,
139
139
  type: a,
140
140
  key: u,
141
- props: C,
141
+ props: w,
142
142
  _owner: O
143
143
  }, (y !== void 0 ? y : null) !== null ? Object.defineProperty(a, "ref", {
144
144
  enumerable: !1,
@@ -165,7 +165,7 @@ function de() {
165
165
  value: U
166
166
  }), Object.freeze && (Object.freeze(a.props), Object.freeze(a)), a;
167
167
  }
168
- function o(a, u, C, O, F, U) {
168
+ function o(a, u, w, O, F, U) {
169
169
  var y = u.children;
170
170
  if (y !== void 0)
171
171
  if (O)
@@ -196,18 +196,18 @@ React keys must be passed directly to JSX without using spread:
196
196
  y
197
197
  ), Q[y + O] = !0);
198
198
  }
199
- if (y = null, C !== void 0 && (t(C), y = "" + C), l(u) && (t(u.key), y = "" + u.key), "key" in u) {
200
- C = {};
199
+ if (y = null, w !== void 0 && (t(w), y = "" + w), l(u) && (t(u.key), y = "" + u.key), "key" in u) {
200
+ w = {};
201
201
  for (var W in u)
202
- W !== "key" && (C[W] = u[W]);
203
- } else C = u;
202
+ W !== "key" && (w[W] = u[W]);
203
+ } else w = u;
204
204
  return y && r(
205
- C,
205
+ w,
206
206
  typeof a == "function" ? a.displayName || a.name || "Unknown" : a
207
207
  ), h(
208
208
  a,
209
209
  y,
210
- C,
210
+ w,
211
211
  i(),
212
212
  F,
213
213
  U
@@ -219,7 +219,7 @@ React keys must be passed directly to JSX without using spread:
219
219
  function m(a) {
220
220
  return typeof a == "object" && a !== null && a.$$typeof === E;
221
221
  }
222
- var f = re, E = /* @__PURE__ */ Symbol.for("react.transitional.element"), g = /* @__PURE__ */ Symbol.for("react.portal"), A = /* @__PURE__ */ Symbol.for("react.fragment"), S = /* @__PURE__ */ Symbol.for("react.strict_mode"), v = /* @__PURE__ */ Symbol.for("react.profiler"), k = /* @__PURE__ */ Symbol.for("react.consumer"), L = /* @__PURE__ */ Symbol.for("react.context"), b = /* @__PURE__ */ Symbol.for("react.forward_ref"), D = /* @__PURE__ */ Symbol.for("react.suspense"), P = /* @__PURE__ */ Symbol.for("react.suspense_list"), B = /* @__PURE__ */ Symbol.for("react.memo"), T = /* @__PURE__ */ Symbol.for("react.lazy"), R = /* @__PURE__ */ Symbol.for("react.activity"), ne = /* @__PURE__ */ Symbol.for("react.client.reference"), j = f.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE, J = Object.prototype.hasOwnProperty, le = Array.isArray, q = console.createTask ? console.createTask : function() {
222
+ var f = re, E = /* @__PURE__ */ Symbol.for("react.transitional.element"), g = /* @__PURE__ */ Symbol.for("react.portal"), A = /* @__PURE__ */ Symbol.for("react.fragment"), S = /* @__PURE__ */ Symbol.for("react.strict_mode"), v = /* @__PURE__ */ Symbol.for("react.profiler"), k = /* @__PURE__ */ Symbol.for("react.consumer"), L = /* @__PURE__ */ Symbol.for("react.context"), C = /* @__PURE__ */ Symbol.for("react.forward_ref"), D = /* @__PURE__ */ Symbol.for("react.suspense"), P = /* @__PURE__ */ Symbol.for("react.suspense_list"), B = /* @__PURE__ */ Symbol.for("react.memo"), T = /* @__PURE__ */ Symbol.for("react.lazy"), R = /* @__PURE__ */ Symbol.for("react.activity"), ne = /* @__PURE__ */ Symbol.for("react.client.reference"), j = f.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE, J = Object.prototype.hasOwnProperty, le = Array.isArray, q = console.createTask ? console.createTask : function() {
223
223
  return null;
224
224
  };
225
225
  f = {
@@ -231,22 +231,22 @@ React keys must be passed directly to JSX without using spread:
231
231
  f,
232
232
  n
233
233
  )(), Z = q(s(n)), Q = {};
234
- _.Fragment = A, _.jsx = function(a, u, C) {
234
+ _.Fragment = A, _.jsx = function(a, u, w) {
235
235
  var O = 1e4 > j.recentlyCreatedOwnerStacks++;
236
236
  return o(
237
237
  a,
238
238
  u,
239
- C,
239
+ w,
240
240
  !1,
241
241
  O ? Error("react-stack-top-frame") : K,
242
242
  O ? q(s(a)) : Z
243
243
  );
244
- }, _.jsxs = function(a, u, C) {
244
+ }, _.jsxs = function(a, u, w) {
245
245
  var O = 1e4 > j.recentlyCreatedOwnerStacks++;
246
246
  return o(
247
247
  a,
248
248
  u,
249
- C,
249
+ w,
250
250
  !0,
251
251
  O ? Error("react-stack-top-frame") : K,
252
252
  O ? q(s(a)) : Z
@@ -356,7 +356,7 @@ function me(p) {
356
356
  const e = p.replace(/[A-Z\u00C0-\u00D6\u00D8-\u00DE]/g, (t) => "-" + t.toLowerCase());
357
357
  return p[0] === p[0].toUpperCase() ? e.substring(1) : e;
358
358
  }
359
- class w {
359
+ class b {
360
360
  id;
361
361
  value;
362
362
  text;
@@ -384,7 +384,7 @@ class x {
384
384
  constructor(e) {
385
385
  if (this.id = !e.id || e.id === "" ? z() : 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)
386
386
  for (const t of e.options)
387
- this.options.push(new w(t));
387
+ this.options.push(new b(t));
388
388
  }
389
389
  }
390
390
  class ge {
@@ -410,7 +410,7 @@ class ge {
410
410
  if (i)
411
411
  return i;
412
412
  }
413
- } else if (t instanceof w || "text" in t) {
413
+ } else if (t instanceof b || "text" in t) {
414
414
  const s = this.validateOption(t);
415
415
  if (s)
416
416
  return s;
@@ -429,10 +429,10 @@ class ge {
429
429
  if (s instanceof x || "label" in s) {
430
430
  let i = [];
431
431
  "options" in s && s.options && s.options.forEach((n) => {
432
- i.push(new w(n));
432
+ i.push(new b(n));
433
433
  }), i.length > 0 && t.push(new x(s));
434
434
  }
435
- (s instanceof w || "text" in s) && t.push(new w(s));
435
+ (s instanceof b || "text" in s) && t.push(new b(s));
436
436
  }
437
437
  }), t;
438
438
  }
@@ -445,7 +445,7 @@ class ge {
445
445
  i.forEach((l) => {
446
446
  let r = !1;
447
447
  for (const c of s) {
448
- if (c instanceof w && c.id === l.id) {
448
+ if (c instanceof b && c.id === l.id) {
449
449
  r = !0;
450
450
  break;
451
451
  }
@@ -477,10 +477,10 @@ class ge {
477
477
  }
478
478
  addOption(e, t = !1) {
479
479
  if (t) {
480
- let s = [new w(e)];
480
+ let s = [new b(e)];
481
481
  this.setData(s.concat(this.getData()));
482
482
  } else
483
- this.setData(this.getData().concat(new w(e)));
483
+ this.setData(this.getData().concat(new b(e)));
484
484
  }
485
485
  // Pass in an array of id that will loop through
486
486
  // each option and set the selected property to true
@@ -496,7 +496,7 @@ class ge {
496
496
  let o = h[e] || "";
497
497
  h.selected = n ? !1 : t.includes(o), h.selected && (l.push(h), this.selectType === "single" && (n = !0));
498
498
  }
499
- c instanceof w && (i || (i = c), c.selected = n ? !1 : t.includes(c[e]), c.selected && (l.push(c), this.selectType === "single" && (n = !0)));
499
+ c instanceof b && (i || (i = c), c.selected = n ? !1 : t.includes(c[e]), c.selected && (l.push(c), this.selectType === "single" && (n = !0)));
500
500
  }
501
501
  this.selectType === "single" && i && !n && !s && (i.selected = !0, l.push(i));
502
502
  const r = t.map((c) => l.find((h) => h[e] === c)?.id || "");
@@ -527,7 +527,7 @@ class ge {
527
527
  getFirstOption() {
528
528
  let e = null;
529
529
  for (let t of this.data)
530
- if (t instanceof x ? e = t.options[0] : t instanceof w && (e = t), e)
530
+ if (t instanceof x ? e = t.options[0] : t instanceof b && (e = t), e)
531
531
  break;
532
532
  return e;
533
533
  }
@@ -543,13 +543,13 @@ class ge {
543
543
  if (i instanceof x) {
544
544
  let n = [];
545
545
  if (i.options.forEach((r) => {
546
- (!e || e(r)) && (t ? n.push(new w(r)) : s.push(new w(r)));
546
+ (!e || e(r)) && (t ? n.push(new b(r)) : s.push(new b(r)));
547
547
  }), n.length > 0) {
548
548
  let r = new x(i);
549
549
  r.options = n, s.push(r);
550
550
  }
551
551
  }
552
- i instanceof w && (!e || e(i)) && s.push(new w(i));
552
+ i instanceof b && (!e || e(i)) && s.push(new b(i));
553
553
  }), s;
554
554
  }
555
555
  // Take in an array of options and reoder them based upon the selected order
@@ -575,6 +575,7 @@ class ve {
575
575
  callbacks;
576
576
  // Used to compute the range selection
577
577
  lastSelectedOption;
578
+ lastRenderedOptions;
578
579
  // Timeout tracking for cleanup
579
580
  closeAnimationTimeout = null;
580
581
  // Elements
@@ -583,7 +584,7 @@ class ve {
583
584
  // Classes
584
585
  classes;
585
586
  constructor(e, t, s, i) {
586
- this.store = s, this.settings = e, this.classes = t, this.callbacks = i, this.lastSelectedOption = null, this.main = this.mainDiv(), this.content = this.contentDiv(), this.updateClassStyles(), this.updateAriaAttributes(), this.settings.contentPosition !== "relative" && (this.content.main.style.top = "-9999px", this.content.main.style.left = "-9999px", this.content.main.style.margin = "0", this.content.main.style.width = "auto"), this.settings.contentLocation && this.settings.contentLocation.appendChild(this.content.main);
587
+ this.store = s, this.settings = e, this.classes = t, this.callbacks = i, this.lastSelectedOption = null, this.lastRenderedOptions = [], this.main = this.mainDiv(), this.content = this.contentDiv(), this.updateClassStyles(), this.updateAriaAttributes(), this.settings.contentPosition !== "relative" && (this.content.main.style.top = "-9999px", this.content.main.style.left = "-9999px", this.content.main.style.margin = "0", this.content.main.style.width = "auto"), this.settings.contentLocation && this.settings.contentLocation.appendChild(this.content.main);
587
588
  }
588
589
  // Helper method to add classes that may contain spaces
589
590
  // Splits by spaces and adds each class individually to avoid DOMException
@@ -793,7 +794,7 @@ class ve {
793
794
  if (m instanceof x)
794
795
  for (const f of m.options)
795
796
  f.id && d.push(f.id);
796
- m instanceof w && d.push(m.id);
797
+ m instanceof b && d.push(m.id);
797
798
  }
798
799
  this.callbacks.setSelected(d, !1), this.settings.closeOnSelect && this.callbacks.close(), this.callbacks.afterChange && this.callbacks.afterChange(o), this.updateDeselectAll();
799
800
  }
@@ -878,7 +879,7 @@ class ve {
878
879
  return;
879
880
  }
880
881
  const h = (d) => {
881
- let m = new w(d);
882
+ let m = new b(d);
882
883
  if (this.callbacks.addOption(m), this.settings.isMultiple) {
883
884
  let f = this.store.getSelected();
884
885
  f.push(m.id), this.callbacks.setSelected(f, !0);
@@ -973,13 +974,13 @@ class ve {
973
974
  }
974
975
  // Take in data and add options to
975
976
  renderOptions(e) {
976
- if (this.content.list.innerHTML = "", e.length === 0) {
977
+ if (this.lastRenderedOptions = e.map((s) => s instanceof b ? [s] : s.options.map((i) => new b(i))).flat(), this.content.list.innerHTML = "", e.length === 0) {
977
978
  const s = document.createElement("div");
978
979
  this.addClasses(s, this.classes.search), this.callbacks.addable ? s.innerHTML = this.settings.addableText.replace("{value}", this.content.search.input.value) : s.innerHTML = this.settings.searchText, this.content.list.appendChild(s);
979
980
  return;
980
981
  }
981
982
  this.settings.allowDeselect && !this.settings.isMultiple && (this.store.filter((i) => i.placeholder, !1).length || this.store.addOption(
982
- new w({
983
+ new b({
983
984
  text: "",
984
985
  value: "",
985
986
  selected: !1,
@@ -1030,7 +1031,7 @@ class ve {
1030
1031
  let A = s.options.map((v) => v.id).filter((v) => v !== void 0);
1031
1032
  const S = g.concat(A);
1032
1033
  for (const v of s.options)
1033
- v.id && !this.store.getOptionByID(v.id) && this.callbacks.addOption(new w(v));
1034
+ v.id && !this.store.getOptionByID(v.id) && this.callbacks.addOption(new b(v));
1034
1035
  this.callbacks.setSelected(S, !0);
1035
1036
  return;
1036
1037
  }
@@ -1048,9 +1049,9 @@ class ve {
1048
1049
  }
1049
1050
  i.appendChild(n);
1050
1051
  for (const c of s.options)
1051
- i.appendChild(this.option(new w(c))), t.appendChild(i);
1052
+ i.appendChild(this.option(new b(c))), t.appendChild(i);
1052
1053
  }
1053
- s instanceof w && t.appendChild(this.option(s));
1054
+ s instanceof b && t.appendChild(this.option(s));
1054
1055
  }
1055
1056
  this.content.list.appendChild(t);
1056
1057
  }
@@ -1078,9 +1079,9 @@ class ve {
1078
1079
  if (this.settings.isMultiple) {
1079
1080
  const d = h.some((f) => f.id === l);
1080
1081
  if (s.shiftKey && this.lastSelectedOption) {
1081
- const f = this.store.getDataOptions(), E = f.findIndex((A) => A.id === this.lastSelectedOption.id), g = f.findIndex((A) => A.id === e.id);
1082
+ const f = this.lastRenderedOptions, E = f.findIndex((A) => A.id === this.lastSelectedOption.id), g = f.findIndex((A) => A.id === e.id);
1082
1083
  if (E >= 0 && g >= 0) {
1083
- const A = Math.min(E, g), S = Math.max(E, g), k = f.slice(A, S + 1).filter((L) => !h.find((b) => b.id === L.id));
1084
+ const A = Math.min(E, g), S = Math.max(E, g), k = f.slice(A, S + 1).filter((L) => !h.find((C) => C.id === L.id));
1084
1085
  h.length + k.length <= this.settings.maxSelected ? o = h.concat(k) : o = h;
1085
1086
  } else
1086
1087
  o = h;
@@ -1372,7 +1373,7 @@ class be {
1372
1373
  if (!(!e || e.length === 0)) {
1373
1374
  this.isUpdating = !0, this.pendingOptionsChange = null, this.changeListen(!1), this.select.innerHTML = "";
1374
1375
  for (const t of e)
1375
- t instanceof x && this.select.appendChild(this.createOptgroup(t)), t instanceof w && this.select.appendChild(this.createOption(t));
1376
+ t instanceof x && this.select.appendChild(this.createOptgroup(t)), t instanceof b && this.select.appendChild(this.createOption(t));
1376
1377
  if (this.select.dispatchEvent(new Event("change", { bubbles: !0 })), this.changeListen(!0), this.isUpdating = !1, this.pendingOptionsChange !== null) {
1377
1378
  const t = this.pendingOptionsChange;
1378
1379
  t.length > 0 && this.onOptionsChange ? (this.pendingOptionsChange = null, this.changeListen(!1), this.onOptionsChange(t), this.changeListen(!0)) : this.pendingOptionsChange = null;
@@ -1651,8 +1652,8 @@ const Se = oe(
1651
1652
  const f = (g) => typeof g == "string" ? r ? [g] : g : Array.isArray(g) ? r ? g : g[0] : r ? [] : "", E = (g, A = !1) => {
1652
1653
  if (!o.current || g === void 0)
1653
1654
  return;
1654
- const S = f(g), k = o.current.getData().flatMap((b) => "label" in b ? b.options : [b]);
1655
- if (!(Array.isArray(S) ? S.length > 0 && S.every((b) => k.some((D) => D.value === b)) : S !== "" && k.some((b) => b.value === S)) && !Array.isArray(S) && !k.some((D) => D.placeholder)) {
1655
+ const S = f(g), k = o.current.getData().flatMap((C) => "label" in C ? C.options : [C]);
1656
+ if (!(Array.isArray(S) ? S.length > 0 && S.every((C) => k.some((D) => D.value === C)) : S !== "" && k.some((C) => C.value === S)) && !Array.isArray(S) && !k.some((D) => D.placeholder)) {
1656
1657
  const D = o.current.getData(), P = {
1657
1658
  value: "",
1658
1659
  text: "",
@@ -1675,7 +1676,7 @@ const Se = oe(
1675
1676
  if (!o.current) return;
1676
1677
  const v = r ? S.map((T) => T.value) : S[0]?.value ?? "", L = o.current.getData().flatMap(
1677
1678
  (T) => "label" in T ? T.options : [T]
1678
- ), b = m.current, D = b === void 0 ? !1 : Array.isArray(b) ? b.length > 0 && b.every((T) => L.some((R) => R.value === T)) : b !== "" && L.some((T) => T.value === b), P = Array.isArray(v) ? v.length > 0 && v.every((T) => L.some((R) => R.value === T)) : v !== "" && L.some((T) => T.value === v), B = Array.isArray(v) && Array.isArray(b) ? JSON.stringify(v.sort()) !== JSON.stringify(b.sort()) : b !== v;
1679
+ ), C = m.current, D = C === void 0 ? !1 : Array.isArray(C) ? C.length > 0 && C.every((T) => L.some((R) => R.value === T)) : C !== "" && L.some((T) => T.value === C), P = Array.isArray(v) ? v.length > 0 && v.every((T) => L.some((R) => R.value === T)) : v !== "" && L.some((T) => T.value === v), B = Array.isArray(v) && Array.isArray(C) ? JSON.stringify(v.sort()) !== JSON.stringify(C.sort()) : C !== v;
1679
1680
  n && B && (D || P) && (n(v), m.current = v), A && A(S);
1680
1681
  }
1681
1682
  }, o.current = new we(g), i !== void 0 && E(i, !1), () => {
@@ -1695,7 +1696,7 @@ const Se = oe(
1695
1696
  Se.displayName = "SlimSelect";
1696
1697
  export {
1697
1698
  x as Optgroup,
1698
- w as Option,
1699
+ b as Option,
1699
1700
  Ce as Settings,
1700
1701
  Se as default
1701
1702
  };