slim-select 3.6.1 → 4.0.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.
@@ -1,9 +1,7 @@
1
- import { forwardRef as e, useEffect as t, useImperativeHandle as n, useRef as r } from "react";
2
- //#region \0rolldown/runtime.js
3
- var i = (e, t) => () => (t || (e((t = { exports: {} }).exports, t), e = null), t.exports), a = /* @__PURE__ */ ((e) => typeof require < "u" ? require : typeof Proxy < "u" ? new Proxy(e, { get: (e, t) => (typeof require < "u" ? require : e)[t] }) : e)(function(e) {
4
- if (typeof require < "u") return require.apply(this, arguments);
5
- throw Error("Calling `require` for \"" + e + "\" in an environment that doesn't expose the `require` function. See https://rolldown.rs/in-depth/bundling-cjs#require-external-modules for more details.");
6
- }), o = class {
1
+ import { forwardRef as e, useEffect as t, useImperativeHandle as n, useRef as r, useState as i } from "react";
2
+ import { jsx as a } from "react/jsx-runtime";
3
+ //#region src/slim-select/classes.ts
4
+ var o = class {
7
5
  main;
8
6
  placeholder;
9
7
  values;
@@ -41,6 +39,11 @@ var i = (e, t) => () => (t || (e((t = { exports: {} }).exports, t), e = null), t
41
39
  option;
42
40
  optionDelete;
43
41
  highlighted;
42
+ modalOverlay;
43
+ modalDialog;
44
+ modalTitle;
45
+ modalClose;
46
+ modalContent;
44
47
  mainOpen;
45
48
  close;
46
49
  selected;
@@ -50,18 +53,132 @@ var i = (e, t) => () => (t || (e((t = { exports: {} }).exports, t), e = null), t
50
53
  constructor(e) {
51
54
  e ||= {};
52
55
  let t = (e = "", t = "") => `${e} ${t}`.trim();
53
- this.main = t("ss-main", e.main), this.placeholder = t("ss-placeholder", e.placeholder), this.values = t("ss-values", e.values), this.single = t("ss-single", e.single), this.multiString = t("ss-multi-string", e.multiString), this.max = t("ss-max", e.max), this.value = t("ss-value", e.value), this.valueText = t("ss-value-text", e.valueText), this.valueDelete = t("ss-value-delete", e.valueDelete), this.valueOut = t("ss-value-out", e.valueOut), this.deselect = t("ss-deselect", e.deselect), this.deselectPath = e.deselectPath || "M10,10 L90,90 M10,90 L90,10", this.arrow = t("ss-arrow", e.arrow), this.arrowClose = e.arrowClose || "M10,30 L50,70 L90,30", this.arrowOpen = e.arrowOpen || "M10,70 L50,30 L90,70", this.content = t("ss-content", e.content), this.contentOpen = t("ss-open", e.contentOpen), this.dirAbove = t("ss-dir-above", e.dirAbove), this.dirBelow = t("ss-dir-below", e.dirBelow), this.search = t("ss-search", e.search), this.searchHighlighter = t("ss-search-highlight", e.searchHighlighter), this.searching = t("ss-searching", e.searching), this.status = t("ss-status", e.status), this.addable = t("ss-addable", e.addable), this.addablePath = e.addablePath || "M50,10 L50,90 M10,50 L90,50", this.list = t("ss-list", e.list), this.optgroup = t("ss-optgroup", e.optgroup), this.optgroupLabel = t("ss-optgroup-label", e.optgroupLabel), this.optgroupLabelText = t("ss-optgroup-label-text", e.optgroupLabelText), this.optgroupActions = t("ss-optgroup-actions", e.optgroupActions), this.optgroupSelectAll = t("ss-selectall", e.optgroupSelectAll), 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 = t("ss-closable", e.optgroupClosable), this.option = t("ss-option", e.option), this.optionDelete = e.optionDelete || "M10,10 L90,90 M10,90 L90,10", this.highlighted = t("ss-highlighted", e.highlighted), this.mainOpen = t("ss-open", e.mainOpen), this.close = t("ss-close", e.close), this.selected = t("ss-selected", e.selected), this.error = t("ss-error", e.error), this.disabled = t("ss-disabled", e.disabled), this.hide = t("ss-hide", e.hide);
56
+ this.main = t("ss-main", e.main), this.placeholder = t("ss-placeholder", e.placeholder), this.values = t("ss-values", e.values), this.single = t("ss-single", e.single), this.multiString = t("ss-multi-string", e.multiString), this.max = t("ss-max", e.max), this.value = t("ss-value", e.value), this.valueText = t("ss-value-text", e.valueText), this.valueDelete = t("ss-value-delete", e.valueDelete), this.valueOut = t("ss-value-out", e.valueOut), this.deselect = t("ss-deselect", e.deselect), this.deselectPath = e.deselectPath || "M10,10 L90,90 M10,90 L90,10", this.arrow = t("ss-arrow", e.arrow), this.arrowClose = e.arrowClose || "M10,30 L50,70 L90,30", this.arrowOpen = e.arrowOpen || "M10,70 L50,30 L90,70", this.content = t("ss-content", e.content), this.contentOpen = t("ss-open", e.contentOpen), this.dirAbove = t("ss-dir-above", e.dirAbove), this.dirBelow = t("ss-dir-below", e.dirBelow), this.search = t("ss-search", e.search), this.searchHighlighter = t("ss-search-highlight", e.searchHighlighter), this.searching = t("ss-searching", e.searching), this.status = t("ss-status", e.status), this.addable = t("ss-addable", e.addable), this.addablePath = e.addablePath || "M50,10 L50,90 M10,50 L90,50", this.list = t("ss-list", e.list), this.optgroup = t("ss-optgroup", e.optgroup), this.optgroupLabel = t("ss-optgroup-label", e.optgroupLabel), this.optgroupLabelText = t("ss-optgroup-label-text", e.optgroupLabelText), this.optgroupActions = t("ss-optgroup-actions", e.optgroupActions), this.optgroupSelectAll = t("ss-selectall", e.optgroupSelectAll), 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 = t("ss-closable", e.optgroupClosable), this.option = t("ss-option", e.option), this.optionDelete = e.optionDelete || "M10,10 L90,90 M10,90 L90,10", this.highlighted = t("ss-highlighted", e.highlighted), this.modalOverlay = t("ss-modal-overlay", e.modalOverlay), this.modalDialog = t("ss-modal-dialog", e.modalDialog), this.modalTitle = t("ss-modal-title", e.modalTitle), this.modalClose = t("ss-modal-close", e.modalClose), this.modalContent = t("ss-modal-content", e.modalContent), this.mainOpen = t("ss-open", e.mainOpen), this.close = t("ss-close", e.close), this.selected = t("ss-selected", e.selected), this.error = t("ss-error", e.error), this.disabled = t("ss-disabled", e.disabled), this.hide = t("ss-hide", e.hide);
54
57
  }
55
58
  getFirst(e) {
56
59
  return this[e].split(" ")[0];
57
60
  }
61
+ }, s = 200, c = ["transform", "opacity"];
62
+ function l(e, t = s) {
63
+ let n = e.trim();
64
+ if (!n) return t;
65
+ if (n.endsWith("ms")) {
66
+ let e = parseFloat(n);
67
+ return Number.isNaN(e) ? t : e;
68
+ }
69
+ if (n.endsWith("s")) {
70
+ let e = parseFloat(n);
71
+ return Number.isNaN(e) ? t : e * 1e3;
72
+ }
73
+ let r = parseFloat(n);
74
+ return Number.isNaN(r) ? t : r;
75
+ }
76
+ function u(e, t = s) {
77
+ return l(getComputedStyle(e).getPropertyValue("--ss-animation-timing").trim(), t);
78
+ }
79
+ function d(e, t, n = s) {
80
+ let r = u(e, n) + 50;
81
+ return t === void 0 ? r : Math.max(r, t);
82
+ }
83
+ function f() {
84
+ return typeof window > "u" || typeof window.matchMedia != "function" ? !1 : window.matchMedia("(prefers-reduced-motion: reduce)").matches;
85
+ }
86
+ function p(e) {
87
+ return e === void 0 ? null : new Set(Array.isArray(e) ? e : [e]);
88
+ }
89
+ function m(e, t, n = s, r) {
90
+ if (f() || r?.aborted) return Promise.resolve();
91
+ let i = p(t);
92
+ return new Promise((t) => {
93
+ let a = null, o = !1, s = () => {
94
+ o || (o = !0, e.removeEventListener("transitionend", l), r?.removeEventListener("abort", c), a && clearTimeout(a), t());
95
+ }, c = () => s(), l = (t) => {
96
+ t.target === e && (i && (!i.has(t.propertyName) || (i.delete(t.propertyName), i.size > 0)) || s());
97
+ };
98
+ r?.addEventListener("abort", c, { once: !0 }), e.addEventListener("transitionend", l), a = setTimeout(s, n);
99
+ });
100
+ }
101
+ function h(e, t, n = s, r) {
102
+ return f() || r?.aborted ? Promise.resolve() : new Promise((i) => {
103
+ let a = null, o = !1, s = () => {
104
+ o || (o = !0, e.removeEventListener("animationend", l), r?.removeEventListener("abort", c), a && clearTimeout(a), i());
105
+ }, c = () => s(), l = (n) => {
106
+ n.target === e && (t && n.animationName !== t || s());
107
+ };
108
+ r?.addEventListener("abort", c, { once: !0 }), e.addEventListener("animationend", l), a = setTimeout(s, n);
109
+ });
110
+ }
111
+ //#endregion
112
+ //#region src/slim-select/settings.ts
113
+ var g = class {
114
+ id = "";
115
+ style = "";
116
+ class = [];
117
+ isMultiple = !1;
118
+ isOpen = !1;
119
+ isFullOpen = !1;
120
+ disabled;
121
+ alwaysOpen;
122
+ showSearch;
123
+ focusSearch;
124
+ keepSearch;
125
+ ariaLabel;
126
+ searchPlaceholder;
127
+ searchText;
128
+ searchingText;
129
+ resultsText;
130
+ deselectText;
131
+ removeText;
132
+ searchHighlight;
133
+ closeOnSelect;
134
+ contentLocation;
135
+ contentPosition;
136
+ contentWidth;
137
+ openPosition;
138
+ placeholderText;
139
+ allowDeselect;
140
+ hideSelected;
141
+ multiString;
142
+ keepOrder;
143
+ showOptionTooltips;
144
+ minSelected;
145
+ maxSelected;
146
+ timeoutDelay;
147
+ maxValuesShown;
148
+ maxValuesMessage;
149
+ addableText;
150
+ modal;
151
+ modalTitle;
152
+ constructor(e) {
153
+ e ||= {}, this.id = "ss-" + b(), this.style = e.style || "", this.class = e.class || [], this.disabled = e.disabled === void 0 ? !1 : e.disabled, this.alwaysOpen = e.alwaysOpen === void 0 ? !1 : e.alwaysOpen, this.showSearch = e.showSearch === void 0 ? !0 : e.showSearch, this.focusSearch = e.focusSearch === void 0 ? !0 : e.focusSearch, this.keepSearch = e.keepSearch === void 0 ? !1 : e.keepSearch, this.ariaLabel = e.ariaLabel || "Combobox", this.searchPlaceholder = e.searchPlaceholder || "Search...", this.searchText = e.searchText || "No Results", this.searchingText = e.searchingText || "Searching...", this.resultsText = e.resultsText || "{count} results available", this.deselectText = e.deselectText || "Clear", this.removeText = e.removeText || "Remove", this.searchHighlight = e.searchHighlight === void 0 ? !1 : e.searchHighlight, this.closeOnSelect = e.closeOnSelect === void 0 ? !0 : e.closeOnSelect, 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 ? "Select Value" : e.placeholderText, this.allowDeselect = e.allowDeselect === void 0 ? !1 : e.allowDeselect, this.hideSelected = e.hideSelected === void 0 ? !1 : e.hideSelected, this.multiString = e.multiString === void 0 ? !1 : e.multiString, this.keepOrder = e.keepOrder === void 0 ? !1 : e.keepOrder, this.showOptionTooltips = e.showOptionTooltips === void 0 ? !1 : e.showOptionTooltips, 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}", this.modal = e.modal || "mobile", this.modalTitle = e.modalTitle || "";
154
+ }
58
155
  };
59
156
  //#endregion
60
157
  //#region src/slim-select/helpers.ts
61
- function s() {
158
+ function _(e) {
159
+ if (!e) return {};
160
+ let t = {};
161
+ for (let n of Object.keys(e)) {
162
+ let r = e[n];
163
+ r !== void 0 && (t[n] = r);
164
+ }
165
+ return t;
166
+ }
167
+ function v(e) {
168
+ let t = e.cloneNode(!0);
169
+ return t.querySelectorAll("select, option, optgroup, textarea, input, button").forEach((e) => e.remove()), t.textContent?.replace(/\s+/g, " ").trim() || "";
170
+ }
171
+ function y(e) {
172
+ if (e.labels && e.labels.length > 0) {
173
+ let t = Array.from(e.labels).map(v).filter(Boolean);
174
+ if (t.length > 0) return [...new Set(t)].join(" ");
175
+ }
176
+ return e.getAttribute("aria-label")?.trim() || "";
177
+ }
178
+ function b() {
62
179
  return Math.random().toString(36).substring(2, 10);
63
180
  }
64
- function c(e, t) {
181
+ function x(e, t) {
65
182
  function n(e, n) {
66
183
  return n && e && e.classList && e.classList.contains(n) || n && e && e.dataset && e.dataset.id && e.dataset.id === t ? e : null;
67
184
  }
@@ -70,7 +187,7 @@ function c(e, t) {
70
187
  }
71
188
  return n(e, t) || r(e, t);
72
189
  }
73
- function l(e, t = 50, n = !1) {
190
+ function S(e, t = 50, n = !1) {
74
191
  let r;
75
192
  return function(...i) {
76
193
  let a = self, o = () => {
@@ -79,16 +196,180 @@ function l(e, t = 50, n = !1) {
79
196
  clearTimeout(r), r = setTimeout(o, t), s && e.apply(a, i);
80
197
  };
81
198
  }
82
- function u(e, t) {
83
- return JSON.stringify(e) === JSON.stringify(t);
199
+ function C(e, t) {
200
+ if (e.length !== t.length) return !1;
201
+ let n = [...e].sort(), r = [...t].sort();
202
+ return n.every((e, t) => e === r[t]);
203
+ }
204
+ var w = [
205
+ "id",
206
+ "value",
207
+ "text",
208
+ "html",
209
+ "defaultSelected",
210
+ "selected",
211
+ "display",
212
+ "disabled",
213
+ "placeholder",
214
+ "class",
215
+ "style",
216
+ "mandatory"
217
+ ];
218
+ function T(e, t) {
219
+ let n = Object.keys(e), r = Object.keys(t);
220
+ if (n.length !== r.length) return !1;
221
+ for (let r of n) if (e[r] !== t[r]) return !1;
222
+ return !0;
223
+ }
224
+ function E(e, t) {
225
+ switch (t) {
226
+ case "id": return e.id || "";
227
+ case "value": return e.value === void 0 ? e.text || "" : e.value || "";
228
+ case "text": return e.text || "";
229
+ case "html": return e.html || "";
230
+ case "defaultSelected": return e.defaultSelected ?? !1;
231
+ case "selected": return e.selected ?? !1;
232
+ case "display": return e.display ?? !0;
233
+ case "disabled": return e.disabled ?? !1;
234
+ case "placeholder": return e.placeholder ?? !1;
235
+ case "class": return e.class || "";
236
+ case "style": return e.style || "";
237
+ case "mandatory": return e.mandatory ?? !1;
238
+ default: return e.data || {};
239
+ }
240
+ }
241
+ function D(e) {
242
+ return !!e && typeof e == "object" && "label" in e && "options" in e;
243
+ }
244
+ function O(e, t) {
245
+ for (let n of w) if (E(e, n) !== E(t, n)) return !1;
246
+ return T(e.data || {}, t.data || {});
84
247
  }
85
- function d(e) {
248
+ function k(e, t) {
249
+ let n = (e) => ({
250
+ id: e.id || "",
251
+ label: e.label || "",
252
+ selectAll: e.selectAll ?? !1,
253
+ closable: e.closable || "off"
254
+ }), r = n(e), i = n(t);
255
+ if (r.id !== i.id || r.label !== i.label || r.selectAll !== i.selectAll || r.closable !== i.closable) return !1;
256
+ let a = e.options || [], o = t.options || [];
257
+ if (a.length !== o.length) return !1;
258
+ for (let e = 0; e < a.length; e++) if (!O(a[e], o[e])) return !1;
259
+ return !0;
260
+ }
261
+ function A(e, t) {
262
+ if (e === t) return !0;
263
+ if (e.length !== t.length) return !1;
264
+ for (let n = 0; n < e.length; n++) {
265
+ let r = e[n], i = t[n], a = D(r);
266
+ if (a !== D(i)) return !1;
267
+ if (a) {
268
+ if (!k(r, i)) return !1;
269
+ continue;
270
+ }
271
+ if (!O(r, i)) return !1;
272
+ }
273
+ return !0;
274
+ }
275
+ function j(e) {
86
276
  let t = e.replace(/[A-Z\u00C0-\u00D6\u00D8-\u00DE]/g, (e) => "-" + e.toLowerCase());
87
277
  return e[0] === e[0].toUpperCase() ? t.substring(1) : t;
88
278
  }
279
+ function M(e, t = typeof window < "u" ? window.innerWidth : 768) {
280
+ return e === "on" ? !0 : e === "mobile" ? t < 768 : !1;
281
+ }
89
282
  //#endregion
90
- //#region src/slim-select/store.ts
91
- var f = class {
283
+ //#region src/slim-select/events.ts
284
+ var N = class {
285
+ handlers;
286
+ attached = !1;
287
+ constructor(e) {
288
+ this.handlers = e;
289
+ }
290
+ attach(e) {
291
+ this.attached || (this.attached = !0, window.addEventListener("resize", this.resizeHandler, !1), e.listenScroll && window.addEventListener("scroll", this.scrollHandler, !1), document.addEventListener("visibilitychange", this.visibilityHandler));
292
+ }
293
+ attachDocumentClick() {
294
+ document.addEventListener("click", this.handlers.onDocumentClick);
295
+ }
296
+ detachDocumentClick() {
297
+ document.removeEventListener("click", this.handlers.onDocumentClick);
298
+ }
299
+ detach(e) {
300
+ this.attached && (this.attached = !1, this.detachDocumentClick(), window.removeEventListener("resize", this.resizeHandler, !1), e.listenScroll && window.removeEventListener("scroll", this.scrollHandler, !1), document.removeEventListener("visibilitychange", this.visibilityHandler));
301
+ }
302
+ resizeHandler = S(() => {
303
+ this.handlers.onWindowResize();
304
+ });
305
+ scrollHandler = S(() => {
306
+ this.handlers.onWindowScroll();
307
+ });
308
+ visibilityHandler = () => {
309
+ this.handlers.onVisibilityChange();
310
+ };
311
+ }, P = class {
312
+ handlers;
313
+ options;
314
+ state = "closed";
315
+ pendingTimer = null;
316
+ waitResolvers = [];
317
+ generation = 0;
318
+ animationAbort = null;
319
+ constructor(e, t) {
320
+ this.handlers = e, this.options = t;
321
+ }
322
+ get isOpen() {
323
+ return this.state === "opening" || this.state === "open";
324
+ }
325
+ get isFullOpen() {
326
+ return this.state === "open";
327
+ }
328
+ async requestOpen() {
329
+ if (this.state === "opening" || this.state === "open") return;
330
+ this.cancelPending();
331
+ let e = ++this.generation;
332
+ if (this.handlers.beforeOpen && this.handlers.beforeOpen(), this.state = "opening", await this.waitForPhase("open", e), e !== this.generation) {
333
+ this.state === "opening" && (this.state = "closed");
334
+ return;
335
+ }
336
+ this.state = "open", this.handlers.afterOpen && this.handlers.afterOpen(), this.handlers.onOpenReady && this.handlers.onOpenReady();
337
+ }
338
+ async requestClose() {
339
+ if (this.state === "closed" || this.state === "closing") return;
340
+ this.cancelPending();
341
+ let e = ++this.generation;
342
+ this.handlers.beforeClose && this.handlers.beforeClose(), this.state = "closing", await this.waitForPhase("close", e), e === this.generation && (this.state = "closed", this.handlers.afterClose && this.handlers.afterClose(), this.handlers.onCloseReady && this.handlers.onCloseReady());
343
+ }
344
+ cancelPending() {
345
+ this.generation++, this.animationAbort?.abort(), this.animationAbort = null, this.pendingTimer &&= (clearTimeout(this.pendingTimer), null);
346
+ let e = this.waitResolvers.splice(0);
347
+ for (let t of e) t();
348
+ }
349
+ destroy() {
350
+ this.cancelPending(), this.state = "closed";
351
+ }
352
+ waitForPhase(e, t) {
353
+ return new Promise((t) => {
354
+ let n = !1, r = () => {
355
+ if (n) return;
356
+ n = !0;
357
+ let e = this.waitResolvers.indexOf(r);
358
+ e !== -1 && this.waitResolvers.splice(e, 1), t();
359
+ };
360
+ if (this.waitResolvers.push(r), this.options.waitForAnimation) {
361
+ let t = new AbortController();
362
+ this.animationAbort = t, this.options.waitForAnimation(e, t.signal).catch(() => void 0).finally(() => {
363
+ this.animationAbort === t && (this.animationAbort = null), r();
364
+ });
365
+ } else this.pendingTimer = setTimeout(() => {
366
+ this.pendingTimer = null, r();
367
+ }, this.options.timeoutDelay);
368
+ }).then(() => {
369
+ this.generation;
370
+ });
371
+ }
372
+ }, F = class {
92
373
  id;
93
374
  value;
94
375
  text;
@@ -103,34 +384,34 @@ var f = class {
103
384
  data;
104
385
  mandatory;
105
386
  constructor(e) {
106
- this.id = !e.id || e.id === "" ? s() : 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 ? !1 : e.defaultSelected, this.selected = e.selected === void 0 ? !1 : e.selected, this.display = e.display === void 0 ? !0 : e.display, this.disabled = e.disabled === void 0 ? !1 : e.disabled, this.mandatory = e.mandatory === void 0 ? !1 : e.mandatory, this.placeholder = e.placeholder === void 0 ? !1 : e.placeholder, this.class = e.class || "", this.style = e.style || "", this.data = e.data || {};
387
+ this.id = !e.id || e.id === "" ? b() : 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 ? !1 : e.defaultSelected, this.selected = e.selected === void 0 ? !1 : e.selected, this.display = e.display === void 0 ? !0 : e.display, this.disabled = e.disabled === void 0 ? !1 : e.disabled, this.mandatory = e.mandatory === void 0 ? !1 : e.mandatory, this.placeholder = e.placeholder === void 0 ? !1 : e.placeholder, this.class = e.class || "", this.style = e.style || "", this.data = _(e.data);
107
388
  }
108
- }, p = class {
389
+ }, I = class {
109
390
  id;
110
391
  label;
111
392
  selectAll;
112
- selectAllText;
113
393
  closable;
114
394
  options;
115
395
  constructor(e) {
116
- if (this.id = !e.id || e.id === "" ? s() : 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) for (let t of e.options) this.options.push(new f(t));
396
+ if (this.id = !e.id || e.id === "" ? b() : e.id, this.label = e.label || "", this.selectAll = e.selectAll === void 0 ? !1 : e.selectAll, this.closable = e.closable || "off", this.options = [], e.options) for (let t of e.options) this.options.push(new F(t));
117
397
  }
118
- }, m = class {
398
+ }, L = class {
119
399
  selectType = "single";
120
400
  data = [];
121
401
  selectedOrder = [];
402
+ catalog = null;
122
403
  constructor(e, t) {
123
- this.selectType = e, this.setData(t);
404
+ this.selectType = e, this.setData(t), this.snapshotCatalog();
124
405
  }
125
406
  validateDataArray(e) {
126
407
  if (!Array.isArray(e)) return /* @__PURE__ */ Error("Data must be an array");
127
- for (let t of e) if (t) if (t instanceof p || "label" in t) {
408
+ for (let t of e) if (t) if (t instanceof I || "label" in t) {
128
409
  if (!("label" in t)) return /* @__PURE__ */ Error("Optgroup must have a label");
129
410
  if ("options" in t && t.options) for (let e of t.options) {
130
411
  let t = this.validateOption(e);
131
412
  if (t) return t;
132
413
  }
133
- } else if (t instanceof f || "text" in t) {
414
+ } else if (t instanceof F || "text" in t) {
134
415
  let e = this.validateOption(t);
135
416
  if (e) return e;
136
417
  } else return /* @__PURE__ */ Error("Data object must be a valid optgroup or option");
@@ -143,64 +424,81 @@ var f = class {
143
424
  let t = [];
144
425
  return e.forEach((e) => {
145
426
  if (e) {
146
- if (e instanceof p || "label" in e) {
427
+ if (e instanceof I || "label" in e) {
147
428
  let n = [];
148
429
  "options" in e && e.options && e.options.forEach((e) => {
149
- n.push(new f(e));
150
- }), n.length > 0 && t.push(new p(e));
430
+ n.push(new F(e));
431
+ }), n.length > 0 && t.push(new I(e));
151
432
  }
152
- (e instanceof f || "text" in e) && t.push(new f(e));
433
+ (e instanceof F || "text" in e) && t.push(new F(e));
153
434
  }
154
435
  }), t;
155
436
  }
437
+ snapshotCatalog() {
438
+ this.catalog = this.cloneData(this.data);
439
+ }
440
+ getCatalogData() {
441
+ return this.cloneData(this.catalog ?? this.data);
442
+ }
443
+ cloneData(e) {
444
+ return e.map((e) => e instanceof I ? new I({
445
+ id: e.id,
446
+ label: e.label,
447
+ selectAll: e.selectAll,
448
+ closable: e.closable,
449
+ options: e.options.map((e) => new F(e instanceof F ? { ...e } : e))
450
+ }) : new F({ ...e }));
451
+ }
452
+ optionMatchesSelected(e, t) {
453
+ return e.id === t.id ? !0 : t.value !== "" && e.value !== "" && e.value === t.value;
454
+ }
455
+ findOptionInData(e, t) {
456
+ for (let n of e) {
457
+ if (n instanceof F) {
458
+ if (this.optionMatchesSelected(n, t)) return n;
459
+ continue;
460
+ }
461
+ for (let e of n.options) if (this.optionMatchesSelected(e, t)) return e;
462
+ }
463
+ return null;
464
+ }
156
465
  setData(e, t = !1) {
157
466
  let n = this.partialToFullData(e), r = [];
158
467
  if (t) {
159
468
  r = this.getSelectedOptions();
160
469
  let e = [];
161
470
  r.forEach((t) => {
162
- let r = !1;
163
- for (let e of n) {
164
- if (e instanceof f && e.id === t.id) {
165
- r = !0;
166
- break;
167
- }
168
- if (e instanceof p) {
169
- for (let n of e.options) if (n.id === t.id) {
170
- r = !0;
171
- break;
172
- }
173
- }
174
- }
175
- r || e.push(t);
471
+ this.findOptionInData(n, t) || e.push(t);
176
472
  }), this.data = [...e, ...n];
473
+ let t = this.selectType === "single" && r.length === 0, i = r.map((e) => {
474
+ let t = this.findOptionInData(this.data, e);
475
+ return t ? t.id : e.id;
476
+ });
477
+ this.setSelectedBy("id", i, t);
177
478
  } else this.data = n;
178
- if (this.selectType === "single") {
179
- let e = t && r.length === 0;
180
- this.setSelectedBy("id", this.getSelected(), e);
181
- }
479
+ !t && this.selectType === "single" && this.setSelectedBy("id", this.getSelected(), !1);
182
480
  }
183
- getData() {
184
- return this.filter(null, !0);
481
+ getData(e = !0) {
482
+ return this.filter(null, !0, e);
185
483
  }
186
- getDataOptions() {
187
- return this.filter(null, !1);
484
+ getDataOptions(e = !0) {
485
+ return this.filter(null, !1, e);
188
486
  }
189
487
  addOption(e, t = !1) {
190
488
  if (t) {
191
- let t = [new f(e)];
489
+ let t = [new F(e)];
192
490
  this.setData(t.concat(this.getData()));
193
- } else this.setData(this.getData().concat(new f(e)));
491
+ } else this.setData(this.getData().concat(new F(e)));
194
492
  }
195
493
  setSelectedBy(e, t, n = !1) {
196
494
  let r = null, i = !1, a = [];
197
495
  for (let n of this.data) {
198
- if (n instanceof p) for (let o of n.options) {
496
+ if (n instanceof I) for (let o of n.options) {
199
497
  r ||= o;
200
498
  let n = o[e] || "";
201
499
  o.selected = i ? !1 : t.includes(n), o.selected && (a.push(o), this.selectType === "single" && (i = !0));
202
500
  }
203
- n instanceof f && (r ||= n, n.selected = i ? !1 : t.includes(n[e]), n.selected && (a.push(n), this.selectType === "single" && (i = !0)));
501
+ n instanceof F && (r ||= n, n.selected = i ? !1 : t.includes(n[e]), n.selected && (a.push(n), this.selectType === "single" && (i = !0)));
204
502
  }
205
503
  this.selectType === "single" && r && !i && !n && (r.selected = !0, a.push(r));
206
504
  let o = t.map((t) => a.find((n) => n[e] === t)?.id || "");
@@ -213,41 +511,56 @@ var f = class {
213
511
  return this.getSelectedOptions().map((e) => e.value);
214
512
  }
215
513
  getSelectedOptions() {
216
- return this.filter((e) => e.selected, !1);
514
+ let e = [];
515
+ for (let t of this.data) if (t instanceof I) for (let n of t.options) n.selected && e.push(n);
516
+ else t.selected && e.push(t);
517
+ return e;
217
518
  }
218
519
  getOptgroupByID(e) {
219
- for (let t of this.data) if (t instanceof p && t.id === e) return t;
520
+ for (let t of this.data) if (t instanceof I && t.id === e) return t;
220
521
  return null;
221
522
  }
222
523
  getOptionByID(e) {
223
- let t = this.filter((t) => t.id === e, !1);
224
- return t.length ? t[0] : null;
524
+ for (let t of this.data) if (t instanceof I) {
525
+ for (let n of t.options) if (n.id === e) return n;
526
+ } else if (t.id === e) return t;
527
+ return null;
225
528
  }
226
529
  getSelectType() {
227
530
  return this.selectType;
228
531
  }
229
532
  getFirstOption() {
230
533
  let e = null;
231
- for (let t of this.data) if (t instanceof p ? e = t.options[0] : t instanceof f && (e = t), e) break;
534
+ for (let t of this.data) if (t instanceof I ? e = t.options[0] : t instanceof F && (e = t), e) break;
232
535
  return e;
233
536
  }
234
537
  search(e, t) {
235
- return e = e.trim(), e === "" ? this.getData() : this.filter((n) => t(n, e), !0);
538
+ return e = e.trim(), e === "" ? this.getData(!1) : this.filter((n) => t(n, e), !0, !1);
236
539
  }
237
- filter(e, t) {
238
- let n = [];
239
- return this.data.forEach((r) => {
240
- if (r instanceof p) {
241
- let i = [];
242
- if (r.options.forEach((r) => {
243
- (!e || e(r)) && (t ? i.push(new f(r)) : n.push(new f(r)));
244
- }), i.length > 0) {
245
- let e = new p(r);
246
- e.options = i, n.push(e);
247
- }
540
+ createOptgroupView(e, t) {
541
+ let n = new I({
542
+ id: e.id,
543
+ label: e.label,
544
+ selectAll: e.selectAll,
545
+ closable: e.closable,
546
+ options: []
547
+ });
548
+ return n.options = t, n;
549
+ }
550
+ filter(e, t, n = !0) {
551
+ let r = [];
552
+ return this.data.forEach((i) => {
553
+ if (i instanceof I) {
554
+ let a = [];
555
+ if (i.options.forEach((i) => {
556
+ (!e || e(i)) && (t ? a.push(n ? new F(i) : i) : r.push(n ? new F(i) : i));
557
+ }), a.length > 0) if (n) {
558
+ let e = new I(i);
559
+ e.options = a, r.push(e);
560
+ } else r.push(this.createOptgroupView(i, a));
248
561
  }
249
- r instanceof f && (!e || e(r)) && n.push(new f(r));
250
- }), n;
562
+ i instanceof F && (!e || e(i)) && r.push(n ? new F(i) : i);
563
+ }), r;
251
564
  }
252
565
  selectedOrderOptions(e) {
253
566
  let t = [];
@@ -264,18 +577,25 @@ var f = class {
264
577
  }), n || t.push(e);
265
578
  }), t;
266
579
  }
267
- }, h = class {
580
+ }, R = class {
268
581
  settings;
269
582
  store;
270
583
  callbacks;
271
584
  lastSelectedOption;
272
585
  lastRenderedOptions;
273
- closeAnimationTimeout = null;
586
+ optionsListIsFullData = !1;
587
+ lastSearchFilterTerm = "";
274
588
  main;
275
589
  content;
276
590
  classes;
591
+ positionObserver = null;
592
+ positionObserverRaf = 0;
593
+ modalElements = null;
594
+ modalSessionActive = null;
595
+ bodyScrollLocked = !1;
596
+ savedBodyOverflow = "";
277
597
  constructor(e, t, n, r) {
278
- this.store = n, this.settings = e, this.classes = t, this.callbacks = r, 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);
598
+ this.store = n, this.settings = e, this.classes = t, this.callbacks = r, 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), this.settings.modal !== "off" && !this.settings.alwaysOpen && (this.modalElements = this.createModalElements(), document.body.appendChild(this.modalElements.overlay));
279
599
  }
280
600
  addClasses(e, t) {
281
601
  if (!t || t.trim() === "") return;
@@ -294,29 +614,76 @@ var f = class {
294
614
  this.addClasses(this.main.main, this.classes.disabled), this.main.main.setAttribute("aria-disabled", "true"), this.content.search.input.disabled = !0;
295
615
  }
296
616
  open() {
297
- this.main.arrow.path.setAttribute("d", this.classes.arrowOpen), this.main.main.setAttribute("aria-expanded", "true"), this.closeAnimationTimeout &&= (clearTimeout(this.closeAnimationTimeout), null);
298
- let e = this.settings.openPosition === "up" ? this.classes.dirAbove : this.classes.dirBelow;
299
- this.addClasses(this.main.main, e), this.addClasses(this.content.main, e), this.addClasses(this.content.main, this.classes.contentOpen), this.content.search.input.removeAttribute("aria-hidden"), this.moveContent();
617
+ this.main.arrow.path.setAttribute("d", this.classes.arrowOpen), this.main.main.setAttribute("aria-expanded", "true");
618
+ let e = this.resolveModalView();
619
+ if (!e) {
620
+ let e = this.settings.openPosition === "up" ? this.classes.dirAbove : this.classes.dirBelow;
621
+ this.addClasses(this.main.main, e), this.addClasses(this.content.main, e);
622
+ }
623
+ this.addClasses(this.content.main, this.classes.contentOpen), this.content.search.input.removeAttribute("aria-hidden"), e ? this.showModal() : this.moveContent();
300
624
  let t = this.store.getSelectedOptions();
301
625
  if (t.length) {
302
626
  let e = t[t.length - 1].id, n = this.content.list.querySelector("[data-id=\"" + e + "\"]");
303
627
  n && this.ensureElementInView(this.content.list, n);
304
628
  }
305
629
  }
630
+ isModalViewActive() {
631
+ return this.modalSessionActive === !0;
632
+ }
633
+ resolveModalView() {
634
+ return this.settings.alwaysOpen || this.settings.modal === "off" || !this.modalElements ? !1 : (this.modalSessionActive === null && (this.modalSessionActive = M(this.settings.modal)), this.modalSessionActive);
635
+ }
636
+ createModalElements() {
637
+ let e = document.createElement("div");
638
+ this.addClasses(e, this.classes.modalOverlay), this.addClasses(e, this.classes.hide), e.dataset.id = this.settings.id;
639
+ let t = document.createElement("div");
640
+ this.addClasses(t, this.classes.modalDialog), t.setAttribute("role", "dialog"), t.setAttribute("aria-modal", "true");
641
+ let n = null;
642
+ this.settings.modalTitle ? (n = document.createElement("div"), this.addClasses(n, this.classes.modalTitle), n.id = `${this.settings.id}-modal-title`, n.textContent = this.settings.modalTitle, t.setAttribute("aria-labelledby", n.id)) : t.setAttribute("aria-label", this.settings.ariaLabel);
643
+ let r = document.createElement("button");
644
+ r.type = "button", this.addClasses(r, this.classes.modalClose), r.setAttribute("aria-label", "Close"), r.onclick = (e) => {
645
+ e.stopPropagation(), this.callbacks.close();
646
+ };
647
+ let i = document.createElementNS("http://www.w3.org/2000/svg", "svg");
648
+ i.setAttribute("viewBox", "0 0 100 100");
649
+ let a = document.createElementNS("http://www.w3.org/2000/svg", "path");
650
+ return a.setAttribute("d", this.classes.deselectPath), i.appendChild(a), r.appendChild(i), e.onclick = (t) => {
651
+ t.target === e && this.callbacks.close();
652
+ }, n && t.appendChild(n), e.appendChild(t), {
653
+ overlay: e,
654
+ dialog: t,
655
+ closeButton: r,
656
+ title: n
657
+ };
658
+ }
659
+ showModal() {
660
+ this.modalElements && (this.modalElements.dialog.appendChild(this.content.main), this.addClasses(this.content.main, this.classes.modalContent), this.content.main.appendChild(this.modalElements.closeButton), this.content.main.style.top = "", this.content.main.style.left = "", this.content.main.style.margin = "", this.content.main.style.width = "", this.removeClasses(this.modalElements.overlay, this.classes.hide), requestAnimationFrame(() => {
661
+ this.modalElements && this.addClasses(this.modalElements.overlay, this.classes.contentOpen);
662
+ }), this.lockBodyScroll());
663
+ }
664
+ lockBodyScroll() {
665
+ this.bodyScrollLocked ||= (this.savedBodyOverflow = document.body.style.overflow, document.body.style.overflow = "hidden", !0);
666
+ }
667
+ unlockBodyScroll() {
668
+ this.bodyScrollLocked && (document.body.style.overflow = this.savedBodyOverflow, this.bodyScrollLocked = !1, this.savedBodyOverflow = "");
669
+ }
670
+ restoreContentOffscreen() {
671
+ this.settings.contentLocation && this.settings.contentLocation.appendChild(this.content.main), 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");
672
+ }
673
+ finalizeModalClose() {
674
+ this.modalElements && this.content.main.parentElement === this.modalElements.dialog && (this.addClasses(this.modalElements.overlay, this.classes.hide), this.removeClasses(this.modalElements.overlay, this.classes.contentOpen), this.removeClasses(this.content.main, this.classes.modalContent), this.restoreContentOffscreen(), this.unlockBodyScroll());
675
+ }
676
+ waitForAnimation(e, t) {
677
+ let n = d(this.content.main, this.settings.timeoutDelay);
678
+ return m(this.content.main, c, n, t);
679
+ }
306
680
  close() {
307
- this.main.main.setAttribute("aria-expanded", "false"), this.main.arrow.path.setAttribute("d", this.classes.arrowClose), this.removeClasses(this.content.main, this.classes.contentOpen), this.content.search.input.setAttribute("aria-hidden", "true"), this.main.main.removeAttribute("aria-activedescendant");
308
- let e = this.getAnimationTiming();
309
- this.closeAnimationTimeout = setTimeout(() => {
310
- this.removeClasses(this.main.main, this.classes.dirAbove), this.removeClasses(this.main.main, this.classes.dirBelow), this.removeClasses(this.content.main, this.classes.dirAbove), this.removeClasses(this.content.main, this.classes.dirBelow), this.closeAnimationTimeout = null;
311
- }, e);
312
- }
313
- getAnimationTiming() {
314
- let e = getComputedStyle(this.content.main).getPropertyValue("--ss-animation-timing").trim();
315
- if (e) {
316
- if (e.endsWith("ms")) return parseFloat(e);
317
- if (e.endsWith("s")) return parseFloat(e) * 1e3;
318
- }
319
- return 200;
681
+ this.main.main.setAttribute("aria-expanded", "false"), this.main.arrow.path.setAttribute("d", this.classes.arrowClose);
682
+ let e = this.modalSessionActive === !0;
683
+ this.removeClasses(this.content.main, this.classes.contentOpen), e || (this.removeClasses(this.main.main, this.classes.dirAbove), this.removeClasses(this.main.main, this.classes.dirBelow)), e && this.modalElements && this.removeClasses(this.modalElements.overlay, this.classes.contentOpen), this.modalSessionActive = null, this.content.search.input.setAttribute("aria-hidden", "true"), this.main.main.removeAttribute("aria-activedescendant");
684
+ }
685
+ clearDirectionClasses() {
686
+ this.removeClasses(this.main.main, this.classes.dirAbove), this.removeClasses(this.main.main, this.classes.dirBelow), this.removeClasses(this.content.main, this.classes.dirAbove), this.removeClasses(this.content.main, this.classes.dirBelow);
320
687
  }
321
688
  updateClassStyles() {
322
689
  if (this.main.main.className = "", this.main.main.removeAttribute("style"), this.content.main.className = "", this.content.main.removeAttribute("style"), this.addClasses(this.main.main, this.classes.main), this.addClasses(this.content.main, 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) for (let e of this.settings.class) e.trim() !== "" && (this.main.main.classList.add(e.trim()), this.content.main.classList.add(e.trim()));
@@ -349,11 +716,17 @@ var f = class {
349
716
  let n = document.createElement("div");
350
717
  this.addClasses(n, this.classes.deselect), n.setAttribute("role", "button"), n.setAttribute("aria-label", this.settings.deselectText), n.setAttribute("tabindex", "0");
351
718
  let r = this.store?.getSelectedOptions();
352
- !this.settings.allowDeselect || this.settings.isMultiple && r && r.length <= 0 ? this.addClasses(n, this.classes.hide) : this.removeClasses(n, this.classes.hide), n.onclick = (e) => {
353
- if (e.stopPropagation(), this.settings.disabled) return;
354
- let t = !0, n = this.store.getSelectedOptions();
355
- if (this.callbacks.beforeChange && (t = this.callbacks.beforeChange([], n) === !0), t) {
356
- if (this.settings.isMultiple) this.callbacks.setSelected([], !1), this.updateDeselectAll();
719
+ !this.settings.allowDeselect || this.settings.isMultiple && r && r.length <= 0 || this.isAtMinSelected() ? this.addClasses(n, this.classes.hide) : this.removeClasses(n, this.classes.hide), n.onclick = (e) => {
720
+ if (e.stopPropagation(), this.settings.disabled || this.settings.isMultiple && this.isAtMinSelected()) return;
721
+ let t = !0, n = this.store.getSelectedOptions(), r = [], i = "";
722
+ if (this.settings.isMultiple) {
723
+ let e = this.settings.minSelected, t = this.store.getSelected();
724
+ if (e > 0 && t.length > e) i = this.getMinimumSelectionIds(), r = n.filter((e) => i.includes(e.id));
725
+ else if (e <= 0) i = [];
726
+ else return;
727
+ }
728
+ if (this.callbacks.beforeChange && (t = this.callbacks.beforeChange(r, n) === !0), t) {
729
+ if (this.settings.isMultiple) this.callbacks.setSelected(i, !1), this.updateDeselectAll();
357
730
  else {
358
731
  let e = this.store.getFirstOption(), t = e ? e.id : "";
359
732
  this.callbacks.setSelected(t, !1);
@@ -388,7 +761,7 @@ var f = class {
388
761
  e !== "click" && this.main.main.focus({ preventScroll: !0 });
389
762
  }
390
763
  placeholder() {
391
- let e = this.store.filter((e) => e.placeholder, !1), t = this.settings.placeholderText;
764
+ let e = this.store.filter((e) => e.placeholder, !1, !1), t = this.settings.placeholderText;
392
765
  e.length && (e[0].html === "" ? e[0].text !== "" && (t = e[0].text) : t = e[0].html);
393
766
  let n = document.createElement("div");
394
767
  return this.addClasses(n, this.classes.placeholder), n.innerHTML = t, n;
@@ -401,7 +774,7 @@ var f = class {
401
774
  this.renderMultipleValues(), this.updateDeselectAll();
402
775
  }
403
776
  renderSingleValue() {
404
- let e = this.store.filter((e) => e.selected && !e.placeholder, !1), t = e.length > 0 ? e[0] : null;
777
+ let e = this.store.filter((e) => e.selected && !e.placeholder, !1, !1), t = e.length > 0 ? e[0] : null;
405
778
  if (!t) this.main.values.innerHTML = this.placeholder().outerHTML;
406
779
  else {
407
780
  let e = document.createElement("div");
@@ -410,7 +783,7 @@ var f = class {
410
783
  !this.settings.allowDeselect || !e.length ? this.addClasses(this.main.deselect.main, this.classes.hide) : this.removeClasses(this.main.deselect.main, this.classes.hide);
411
784
  }
412
785
  renderMultipleValues() {
413
- let e = this.main.values.childNodes, t = this.store.filter((e) => e.selected && e.display, !1);
786
+ let e = this.main.values.childNodes, t = this.store.filter((e) => e.selected && e.display, !1, !1);
414
787
  if (t.length === 0) {
415
788
  this.main.values.innerHTML = this.placeholder().outerHTML;
416
789
  return;
@@ -439,15 +812,29 @@ var f = class {
439
812
  let i = e[r], a = i.getAttribute("data-id");
440
813
  a && (t.filter((e) => e.id === a, !1).length || n.push(i));
441
814
  }
442
- for (let e of n) this.addClasses(e, this.classes.valueOut), setTimeout(() => {
815
+ let r = d(this.content.main, this.settings.timeoutDelay);
816
+ for (let e of n) this.addClasses(e, this.classes.valueOut), h(e, "ss-valueOut", r).then(() => {
443
817
  this.main.values.hasChildNodes() && this.main.values.contains(e) && this.main.values.removeChild(e);
444
- }, 100);
818
+ });
445
819
  e = this.main.values.childNodes;
446
820
  for (let n = 0; n < t.length; n++) {
447
821
  let r = !0;
448
822
  for (let i = 0; i < e.length; i++) t[n].id === String(e[i].dataset.id) && (r = !1);
449
823
  r && (this.settings.keepOrder || e.length === 0 ? this.main.values.appendChild(this.multipleValue(t[n])) : n === 0 ? this.main.values.insertBefore(this.multipleValue(t[n]), e[n]) : e[n - 1].insertAdjacentElement("afterend", this.multipleValue(t[n])));
450
824
  }
825
+ this.updateMultipleValueDeleteVisibility();
826
+ }
827
+ isAtMinSelected() {
828
+ return this.settings.isMultiple && this.settings.minSelected > 0 && this.store.getSelectedOptions().length <= this.settings.minSelected;
829
+ }
830
+ getMinimumSelectionIds() {
831
+ let e = this.store.getSelectedOptions();
832
+ return this.settings.keepOrder && (e = this.store.selectedOrderOptions(e)), e.slice(0, this.settings.minSelected).map((e) => e.id);
833
+ }
834
+ updateMultipleValueDeleteVisibility() {
835
+ if (!this.settings.isMultiple || this.settings.multiString) return;
836
+ let e = !this.isAtMinSelected(), t = this.main.values.querySelectorAll("." + this.classes.getFirst("valueDelete"));
837
+ for (let n of t) e ? this.removeClasses(n, this.classes.hide) : this.addClasses(n, this.classes.hide);
451
838
  }
452
839
  multipleValue(e) {
453
840
  let t = document.createElement("div");
@@ -455,16 +842,16 @@ var f = class {
455
842
  let n = document.createElement("div");
456
843
  if (this.addClasses(n, this.classes.valueText), n.textContent = e.text, t.appendChild(n), !e.mandatory) {
457
844
  let n = document.createElement("div");
458
- this.addClasses(n, this.classes.valueDelete), n.setAttribute("tabindex", "0"), n.setAttribute("role", "button"), n.setAttribute("aria-label", `${this.settings.removeText} ${e.text}`), n.onclick = (t) => {
845
+ this.addClasses(n, this.classes.valueDelete), n.setAttribute("tabindex", "0"), n.setAttribute("role", "button"), n.setAttribute("aria-label", `${this.settings.removeText} ${e.text}`), this.isAtMinSelected() && this.addClasses(n, this.classes.hide), n.onclick = (t) => {
459
846
  if (t.preventDefault(), t.stopPropagation(), this.settings.disabled) return;
460
847
  let n = !0, r = this.store.getSelectedOptions(), i = r.filter((t) => t.selected && t.id !== e.id, !0);
461
848
  if (!(this.settings.minSelected && i.length < this.settings.minSelected) && (this.callbacks.beforeChange && (n = this.callbacks.beforeChange(i, r) === !0), n)) {
462
849
  let e = [];
463
850
  for (let t of i) {
464
- if (t instanceof p) for (let n of t.options) n.id && e.push(n.id);
465
- t instanceof f && e.push(t.id);
851
+ if (t instanceof I) for (let n of t.options) n.id && e.push(n.id);
852
+ t instanceof F && e.push(t.id);
466
853
  }
467
- this.callbacks.setSelected(e, !1), this.settings.closeOnSelect && this.callbacks.close(), this.callbacks.afterChange && this.callbacks.afterChange(i), this.updateDeselectAll();
854
+ this.callbacks.setSelected(e, !1), this.settings.closeOnSelect && this.callbacks.close(), this.callbacks.afterChange && this.callbacks.afterChange(i), this.updateDeselectAll(), this.updateMultipleValueDeleteVisibility();
468
855
  }
469
856
  };
470
857
  let r = document.createElementNS("http://www.w3.org/2000/svg", "svg");
@@ -495,18 +882,39 @@ var f = class {
495
882
  this.settings.showSearch && (this.content.status.textContent = e);
496
883
  }
497
884
  moveContent() {
498
- if (this.settings.contentPosition === "relative") {
499
- this.moveContentBelow();
500
- return;
501
- }
502
- if (this.settings.openPosition === "down") {
503
- this.moveContentBelow();
504
- return;
505
- } else if (this.settings.openPosition === "up") {
506
- this.moveContentAbove();
507
- return;
885
+ if (!this.isModalViewActive()) {
886
+ if (this.settings.contentPosition === "relative") {
887
+ this.moveContentBelow();
888
+ return;
889
+ }
890
+ if (this.settings.openPosition === "down") {
891
+ this.moveContentBelow();
892
+ return;
893
+ } else if (this.settings.openPosition === "up") {
894
+ this.moveContentAbove();
895
+ return;
896
+ }
897
+ this.putContent() === "up" ? this.moveContentAbove() : this.moveContentBelow();
508
898
  }
509
- this.putContent() === "up" ? this.moveContentAbove() : this.moveContentBelow();
899
+ }
900
+ startPositionTracking() {
901
+ this.settings.contentPosition !== "absolute" || this.isModalViewActive() || (this.stopPositionTracking(), !(typeof ResizeObserver > "u") && (this.positionObserver = new ResizeObserver(() => {
902
+ this.settings.isOpen && (cancelAnimationFrame(this.positionObserverRaf), this.positionObserverRaf = requestAnimationFrame(() => {
903
+ this.moveContent();
904
+ }));
905
+ }), this.observePositionTargets()));
906
+ }
907
+ stopPositionTracking() {
908
+ cancelAnimationFrame(this.positionObserverRaf), this.positionObserver?.disconnect(), this.positionObserver = null;
909
+ }
910
+ observePositionTargets() {
911
+ if (!this.positionObserver) return;
912
+ let e = /* @__PURE__ */ new Set(), t = (t) => {
913
+ !t || e.has(t) || (e.add(t), this.positionObserver.observe(t));
914
+ };
915
+ t(this.main.main), t(this.content.main);
916
+ let n = this.main.main.parentElement, r = this.settings.contentLocation;
917
+ for (let e = 0; n && e < 8 && (t(n), n !== r); e++) n = n.parentElement;
510
918
  }
511
919
  searchDiv() {
512
920
  let e = document.createElement("div"), t = document.createElement("input"), n = document.createElement("div");
@@ -515,7 +923,7 @@ var f = class {
515
923
  main: e,
516
924
  input: t
517
925
  };
518
- if (this.settings.showSearch || (this.addClasses(e, 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 = l((e) => {
926
+ if (this.settings.showSearch || (this.addClasses(e, 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((e) => {
519
927
  this.callbacks.search(e.target.value);
520
928
  }, 100), t.onkeydown = (e) => {
521
929
  switch (e.key) {
@@ -544,14 +952,17 @@ var f = class {
544
952
  return;
545
953
  }
546
954
  let n = (e) => {
547
- let t = new f(e);
955
+ let t = new F(e);
548
956
  if (this.callbacks.addOption(t), this.settings.isMultiple) {
549
957
  let e = this.store.getSelected();
550
958
  e.push(t.id), this.callbacks.setSelected(e, !0);
551
959
  } else this.callbacks.setSelected([t.id], !0);
552
- this.callbacks.search(""), this.settings.closeOnSelect && setTimeout(() => {
553
- this.callbacks.close();
554
- }, 100);
960
+ if (this.callbacks.search(""), this.settings.closeOnSelect) {
961
+ let e = u(this.content.main);
962
+ setTimeout(() => {
963
+ this.callbacks.close();
964
+ }, e);
965
+ }
555
966
  }, r = this.callbacks.addable(t);
556
967
  r === !1 || r == null || (r instanceof Promise ? r.then((e) => {
557
968
  typeof e == "string" ? n({
@@ -619,17 +1030,18 @@ var f = class {
619
1030
  return e.id = t, e.dataset.id = t, e;
620
1031
  }
621
1032
  renderError(e) {
622
- this.content.list.innerHTML = "";
1033
+ this.optionsListIsFullData = !1, this.content.list.innerHTML = "";
623
1034
  let t = document.createElement("div");
624
1035
  this.addClasses(t, this.classes.error), t.textContent = e, this.content.list.appendChild(t);
625
1036
  }
626
1037
  renderSearching() {
627
- this.content.list.innerHTML = "";
1038
+ this.optionsListIsFullData = !1, this.content.list.innerHTML = "";
628
1039
  let e = document.createElement("div");
629
1040
  this.addClasses(e, this.classes.searching), e.textContent = this.settings.searchingText, this.content.list.appendChild(e), this.announce(this.settings.searchingText);
630
1041
  }
631
1042
  renderOptions(e) {
632
- if (this.lastRenderedOptions = e.map((e) => e instanceof f ? [e] : e.options.map((e) => new f(e))).flat(), this.content.list.innerHTML = "", e.length === 0) {
1043
+ if (this.lastSearchFilterTerm = "", this.lastRenderedOptions = e.map((e) => e instanceof F ? [e] : e.options.map((e) => new F(e))).flat(), this.content.list.innerHTML = "", e.length === 0) {
1044
+ this.optionsListIsFullData = !1;
633
1045
  let e = document.createElement("div");
634
1046
  if (this.addClasses(e, this.classes.search), this.callbacks.addable) {
635
1047
  let t = this.settings.addableText.replace("{value}", this.content.search.input.value);
@@ -638,7 +1050,7 @@ var f = class {
638
1050
  this.content.list.appendChild(e);
639
1051
  return;
640
1052
  }
641
- this.settings.allowDeselect && !this.settings.isMultiple && (this.store.filter((e) => e.placeholder, !1).length || this.store.addOption(new f({
1053
+ this.settings.allowDeselect && !this.settings.isMultiple && (this.store.filter((e) => e.placeholder, !1, !1).length || this.store.addOption(new F({
642
1054
  text: "",
643
1055
  value: "",
644
1056
  selected: !1,
@@ -646,7 +1058,7 @@ var f = class {
646
1058
  }), !0));
647
1059
  let t = document.createDocumentFragment();
648
1060
  for (let n of e) {
649
- if (n instanceof p) {
1061
+ if (n instanceof I) {
650
1062
  let e = document.createElement("div");
651
1063
  this.addClasses(e, this.classes.optgroup);
652
1064
  let r = document.createElement("div");
@@ -657,14 +1069,10 @@ var f = class {
657
1069
  if (this.addClasses(a, this.classes.optgroupActions), r.appendChild(a), this.settings.isMultiple && n.selectAll) {
658
1070
  let e = document.createElement("div");
659
1071
  this.addClasses(e, this.classes.optgroupSelectAll);
660
- let t = !0;
661
- for (let e of n.options) if (!e.selected) {
662
- t = !1;
663
- break;
664
- }
1072
+ let t = this.isOptgroupAllSelected(n.options);
665
1073
  t && this.addClasses(e, this.classes.selected);
666
1074
  let r = document.createElement("span");
667
- r.textContent = n.selectAllText, e.appendChild(r);
1075
+ r.textContent = this.optgroupSelectAllLabel(t), e.appendChild(r);
668
1076
  let i = document.createElementNS("http://www.w3.org/2000/svg", "svg");
669
1077
  i.setAttribute("viewBox", "0 0 100 100"), e.appendChild(i);
670
1078
  let o = document.createElementNS("http://www.w3.org/2000/svg", "path");
@@ -672,18 +1080,18 @@ var f = class {
672
1080
  let s = document.createElementNS("http://www.w3.org/2000/svg", "path");
673
1081
  s.setAttribute("d", this.classes.optgroupSelectAllCheck), i.appendChild(s), e.addEventListener("click", (e) => {
674
1082
  e.preventDefault(), e.stopPropagation();
675
- let r = this.store.getSelected();
676
- if (t) {
677
- let e = r.filter((e) => {
1083
+ let t = this.store.getSelected();
1084
+ if (this.isOptgroupAllSelected(n.options, new Set(t))) {
1085
+ let e = t.filter((e) => {
678
1086
  for (let t of n.options) if (e === t.id) return !1;
679
1087
  return !0;
680
1088
  });
681
1089
  this.callbacks.setSelected(e, !0);
682
1090
  return;
683
1091
  } else {
684
- let e = n.options.map((e) => e.id).filter((e) => e !== void 0), t = r.concat(e);
685
- for (let e of n.options) e.id && !this.store.getOptionByID(e.id) && this.callbacks.addOption(new f(e));
686
- this.callbacks.setSelected(t, !0);
1092
+ let e = n.options.map((e) => e.id).filter((e) => e !== void 0), r = t.concat(e);
1093
+ for (let e of n.options) e.id && !this.store.getOptionByID(e.id) && this.callbacks.addOption(new F(e));
1094
+ this.callbacks.setSelected(r, !0);
687
1095
  return;
688
1096
  }
689
1097
  }), a.appendChild(e);
@@ -694,16 +1102,136 @@ var f = class {
694
1102
  let i = document.createElementNS("http://www.w3.org/2000/svg", "svg");
695
1103
  i.setAttribute("viewBox", "0 0 100 100"), this.addClasses(i, this.classes.arrow), t.appendChild(i);
696
1104
  let o = document.createElementNS("http://www.w3.org/2000/svg", "path");
697
- i.appendChild(o), n.options.some((e) => e.selected) || this.content.search.input.value.trim() !== "" ? (this.addClasses(t, this.classes.mainOpen), o.setAttribute("d", this.classes.arrowOpen)) : n.closable === "open" ? (this.addClasses(e, this.classes.mainOpen), o.setAttribute("d", this.classes.arrowOpen)) : n.closable === "close" && (this.addClasses(e, this.classes.close), o.setAttribute("d", this.classes.arrowClose)), r.addEventListener("click", (t) => {
698
- t.preventDefault(), t.stopPropagation(), e.classList.contains(this.classes.getFirst("close")) ? (this.removeClasses(e, this.classes.close), this.addClasses(e, this.classes.mainOpen), o.setAttribute("d", this.classes.arrowOpen)) : (this.removeClasses(e, this.classes.mainOpen), this.addClasses(e, this.classes.close), o.setAttribute("d", this.classes.arrowClose));
1105
+ i.appendChild(o), n.options.some((e) => e.selected) || this.content.search.input.value.trim() !== "" ? (this.addClasses(t, this.classes.mainOpen), o.setAttribute("d", this.classes.arrowOpen)) : n.closable === "open" ? (this.addClasses(e, this.classes.mainOpen), o.setAttribute("d", this.classes.arrowOpen)) : n.closable === "close" && (this.addClasses(e, this.classes.close), o.setAttribute("d", this.classes.arrowClose)), r.addEventListener("click", (n) => {
1106
+ n.preventDefault(), n.stopPropagation(), this.isClosableOptgroupOpen(e, t) ? (this.removeClasses(e, this.classes.mainOpen), this.removeClasses(t, this.classes.mainOpen), this.addClasses(e, this.classes.close), o.setAttribute("d", this.classes.arrowClose)) : (this.closeOtherClosableOptgroups(e), this.removeClasses(e, this.classes.close), this.removeClasses(t, this.classes.mainOpen), this.addClasses(e, this.classes.mainOpen), o.setAttribute("d", this.classes.arrowOpen));
699
1107
  }), a.appendChild(t);
700
1108
  }
701
1109
  e.appendChild(r);
702
- for (let r of n.options) e.appendChild(this.option(new f(r))), t.appendChild(e);
1110
+ for (let r of n.options) e.appendChild(this.option(new F(r))), t.appendChild(e);
1111
+ }
1112
+ n instanceof F && t.appendChild(this.option(n));
1113
+ }
1114
+ this.content.list.appendChild(t), this.setOptionsListFullData(e), this.announce(this.settings.resultsText.replace("{count}", String(this.lastRenderedOptions.length)));
1115
+ }
1116
+ canFilterOptionsInPlace() {
1117
+ return this.optionsListIsFullData ? this.content.list.querySelector("." + this.classes.getFirst("option")) !== null : !1;
1118
+ }
1119
+ resetSearchFilterState() {
1120
+ this.lastSearchFilterTerm = "";
1121
+ }
1122
+ filterOptionsInPlace(e, t) {
1123
+ let n = e.trim();
1124
+ if (n === this.lastSearchFilterTerm) return;
1125
+ this.lastSearchFilterTerm = n;
1126
+ let r = [], i = this.content.list.querySelectorAll("." + this.classes.getFirst("option"));
1127
+ for (let e of i) {
1128
+ let i = e.dataset.id;
1129
+ if (!i) continue;
1130
+ let a = this.store.getOptionByID(i);
1131
+ if (!a) continue;
1132
+ let o = a.placeholder || !a.display || a.selected && this.settings.hideSelected, s = t(a, n);
1133
+ o || !s ? (this.addClasses(e, this.classes.hide), this.removeClasses(e, this.classes.highlighted)) : (this.removeClasses(e, this.classes.hide), this.setOptionElementContent(e, a, n), r.push(a)), a.selected ? (this.addClasses(e, this.classes.selected), e.setAttribute("aria-selected", "true")) : (this.removeClasses(e, this.classes.selected), e.setAttribute("aria-selected", "false"));
1134
+ }
1135
+ this.lastRenderedOptions = r, this.updateOptgroupVisibilityAfterSearch(n), r.length === 0 ? this.updateSearchResultsMessage(0, n) : (this.removeListSearchMessage(), this.announce(this.settings.resultsText.replace("{count}", String(r.length)))), this.updateOptgroupSelectAllStates();
1136
+ }
1137
+ setOptionsListFullData(e) {
1138
+ let t = this.store.getDataOptions(!1), n = e.map((e) => e instanceof F ? [e] : e.options.map((e) => new F(e))).flat();
1139
+ if (n.length !== t.length) {
1140
+ this.optionsListIsFullData = !1;
1141
+ return;
1142
+ }
1143
+ let r = new Set(t.map((e) => e.id));
1144
+ this.optionsListIsFullData = n.every((e) => r.has(e.id));
1145
+ }
1146
+ isClosableOptgroupOpen(e, t) {
1147
+ return e.classList.contains(this.classes.getFirst("close")) ? !1 : e.classList.contains(this.classes.getFirst("mainOpen")) || t.classList.contains(this.classes.getFirst("mainOpen"));
1148
+ }
1149
+ closeClosableOptgroup(e) {
1150
+ let t = e.querySelector("." + this.classes.getFirst("optgroupClosable"));
1151
+ if (!t || e.classList.contains(this.classes.getFirst("close"))) return;
1152
+ this.removeClasses(e, this.classes.mainOpen), this.removeClasses(t, this.classes.mainOpen), this.addClasses(e, this.classes.close);
1153
+ let n = t.querySelector("path");
1154
+ n && n.setAttribute("d", this.classes.arrowClose);
1155
+ }
1156
+ closeOtherClosableOptgroups(e) {
1157
+ let t = this.content.list.querySelectorAll("." + this.classes.getFirst("optgroup"));
1158
+ for (let n of t) n !== e && this.closeClosableOptgroup(n);
1159
+ }
1160
+ updateOptgroupVisibilityAfterSearch(e) {
1161
+ let t = this.content.list.querySelectorAll("." + this.classes.getFirst("optgroup"));
1162
+ for (let n of t) {
1163
+ let t = n.querySelectorAll("." + this.classes.getFirst("option")), r = !1;
1164
+ for (let e of t) if (!e.classList.contains(this.classes.getFirst("hide"))) {
1165
+ r = !0;
1166
+ break;
1167
+ }
1168
+ if (!r) {
1169
+ this.addClasses(n, this.classes.hide);
1170
+ continue;
703
1171
  }
704
- n instanceof f && t.appendChild(this.option(n));
1172
+ this.removeClasses(n, this.classes.hide), e !== "" && (this.removeClasses(n, this.classes.close), this.addClasses(n, this.classes.mainOpen));
705
1173
  }
706
- this.content.list.appendChild(t), this.announce(this.settings.resultsText.replace("{count}", String(this.lastRenderedOptions.length)));
1174
+ }
1175
+ updateSearchResultsMessage(e, t) {
1176
+ if (this.removeListSearchMessage(), e > 0) return;
1177
+ let n = document.createElement("div");
1178
+ if (this.addClasses(n, this.classes.search), this.callbacks.addable) {
1179
+ let e = this.settings.addableText.replace("{value}", t);
1180
+ n.innerHTML = e, this.announce(e);
1181
+ } else n.innerHTML = this.settings.searchText, this.announce(this.settings.searchText);
1182
+ this.content.list.appendChild(n);
1183
+ }
1184
+ removeListSearchMessage() {
1185
+ this.content.list.querySelectorAll("." + this.classes.getFirst("search")).forEach((e) => e.remove());
1186
+ }
1187
+ setOptionElementContent(e, t, n) {
1188
+ let r = n.trim();
1189
+ this.settings.searchHighlight && r !== "" ? e.innerHTML = this.highlightText(t.html === "" ? t.text : t.html, r, this.classes.searchHighlighter) : t.html === "" ? e.textContent = t.text : e.innerHTML = t.html, this.settings.showOptionTooltips && e.textContent ? e.setAttribute("title", e.textContent) : e.removeAttribute("title");
1190
+ }
1191
+ hasRenderedOptions() {
1192
+ return this.content.list.querySelector("." + this.classes.getFirst("option")) !== null;
1193
+ }
1194
+ canUpdateOptionSelectionInPlace() {
1195
+ return this.content.search.input.value.trim() === "" ? this.hasRenderedOptions() : !1;
1196
+ }
1197
+ updateOptionSelection() {
1198
+ let e = new Set(this.store.getSelected()), t = this.content.list.querySelectorAll("." + this.classes.getFirst("option")), n = null;
1199
+ for (let r of t) {
1200
+ let t = r.dataset.id;
1201
+ if (!t) continue;
1202
+ let i = this.store.getOptionByID(t);
1203
+ if (!i) continue;
1204
+ let a = e.has(t);
1205
+ a ? (this.addClasses(r, this.classes.selected), r.setAttribute("aria-selected", "true"), n = r) : (this.removeClasses(r, this.classes.selected), r.setAttribute("aria-selected", "false")), this.settings.hideSelected && (a ? this.addClasses(r, this.classes.hide) : (this.removeClasses(r, this.classes.hide), i.display || this.addClasses(r, this.classes.hide)));
1206
+ }
1207
+ !this.settings.isMultiple && n ? this.main.main.setAttribute("aria-activedescendant", n.id) : !this.settings.isMultiple && e.size === 0 && this.main.main.removeAttribute("aria-activedescendant"), this.updateOptgroupSelectAllStates();
1208
+ }
1209
+ updateOptgroupSelectAllStates() {
1210
+ if (!this.settings.isMultiple) return;
1211
+ let e = new Set(this.store.getSelected()), t = this.content.list.querySelectorAll("." + this.classes.getFirst("optgroup"));
1212
+ for (let n of t) {
1213
+ let t = n.querySelector("." + this.classes.getFirst("optgroupSelectAll"));
1214
+ if (!t) continue;
1215
+ let r = n.querySelectorAll("." + this.classes.getFirst("option")), i = r.length > 0;
1216
+ for (let t of r) {
1217
+ let n = t.dataset.id;
1218
+ if (!n || !e.has(n)) {
1219
+ i = !1;
1220
+ break;
1221
+ }
1222
+ }
1223
+ i ? this.addClasses(t, this.classes.selected) : this.removeClasses(t, this.classes.selected);
1224
+ let a = t.querySelector("span");
1225
+ a && (a.textContent = this.optgroupSelectAllLabel(i));
1226
+ }
1227
+ }
1228
+ optgroupSelectAllLabel(e) {
1229
+ return e ? "Unselect All" : "Select All";
1230
+ }
1231
+ isOptgroupAllSelected(e, t) {
1232
+ if (e.length === 0) return !1;
1233
+ for (let n of e) if (!(t ? n.id && t.has(n.id) : n.selected)) return !1;
1234
+ return !0;
707
1235
  }
708
1236
  option(e) {
709
1237
  if (e.placeholder) {
@@ -713,7 +1241,7 @@ var f = class {
713
1241
  let t = document.createElement("div");
714
1242
  return t.dataset.id = e.id, t.id = this.settings.id + "-" + e.id, this.addClasses(t, this.classes.option), t.setAttribute("role", "option"), e.class && e.class.split(" ").forEach((e) => {
715
1243
  t.classList.add(e);
716
- }), e.style && (t.style.cssText = e.style), this.settings.searchHighlight && this.content.search.input.value.trim() !== "" ? t.innerHTML = this.highlightText(e.html === "" ? e.text : e.html, this.content.search.input.value, this.classes.searchHighlighter) : e.html === "" ? t.textContent = e.text : t.innerHTML = e.html, this.settings.showOptionTooltips && t.textContent && t.setAttribute("title", t.textContent), e.display || this.addClasses(t, this.classes.hide), e.disabled && this.addClasses(t, this.classes.disabled), e.selected && this.settings.hideSelected && this.addClasses(t, this.classes.hide), e.selected ? (this.addClasses(t, this.classes.selected), t.setAttribute("aria-selected", "true"), this.main.main.setAttribute("aria-activedescendant", t.id)) : (this.removeClasses(t, this.classes.selected), t.setAttribute("aria-selected", "false")), t.addEventListener("click", (t) => {
1244
+ }), e.style && (t.style.cssText = e.style), this.setOptionElementContent(t, e, this.content.search.input.value), e.display || this.addClasses(t, this.classes.hide), e.disabled && this.addClasses(t, this.classes.disabled), e.selected && this.settings.hideSelected && this.addClasses(t, this.classes.hide), e.selected ? (this.addClasses(t, this.classes.selected), t.setAttribute("aria-selected", "true"), this.main.main.setAttribute("aria-activedescendant", t.id)) : (this.removeClasses(t, this.classes.selected), t.setAttribute("aria-selected", "false")), t.addEventListener("click", (t) => {
717
1245
  t.preventDefault(), t.stopPropagation();
718
1246
  let n = this.store.getSelected(), r = t.currentTarget, i = String(r.dataset.id), a = t.ctrlKey || t.metaKey;
719
1247
  if (e.disabled || !this.settings.isMultiple && e.selected && !this.settings.allowDeselect || e.selected && e.mandatory || this.settings.isMultiple && this.settings.maxSelected <= n.length && !e.selected || this.settings.isMultiple && this.settings.minSelected >= n.length && e.selected && !a) return;
@@ -736,7 +1264,7 @@ var f = class {
736
1264
  }), t;
737
1265
  }
738
1266
  destroy() {
739
- this.closeAnimationTimeout &&= (clearTimeout(this.closeAnimationTimeout), null), this.main.main.remove(), this.content.main.remove();
1267
+ this.stopPositionTracking(), this.modalElements &&= (this.unlockBodyScroll(), this.content.main.parentElement === this.modalElements.dialog && this.restoreContentOffscreen(), this.modalElements.overlay.remove(), null), this.main.main.remove(), this.content.main.remove();
740
1268
  }
741
1269
  highlightText(e, t, n) {
742
1270
  let r = t.trim();
@@ -804,10 +1332,34 @@ var f = class {
804
1332
  }
805
1333
  updateDeselectAll() {
806
1334
  if (!this.store || !this.settings) return;
807
- let e = this.store.getSelectedOptions(), t = e && e.length > 0, n = this.settings.isMultiple, r = this.settings.allowDeselect, i = this.main.deselect.main, a = this.classes.hide;
808
- r && !(n && !t) ? this.removeClasses(i, a) : this.addClasses(i, a);
1335
+ 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;
1336
+ r && !(n && !t) && !i ? this.removeClasses(a, o) : this.addClasses(a, o);
1337
+ }
1338
+ };
1339
+ //#endregion
1340
+ //#region src/slim-select/mutations.ts
1341
+ function z(e, t) {
1342
+ let n = {
1343
+ classChanged: !1,
1344
+ disabledChanged: !1,
1345
+ optgroupOptionChanged: !1,
1346
+ selectionChanged: !1
1347
+ };
1348
+ for (let r of e) {
1349
+ if (r.target === t && (r.attributeName === "disabled" && (n.disabledChanged = !0), r.attributeName === "class" && (n.classChanged = !0), r.type === "childList")) {
1350
+ for (let e of Array.from(r.addedNodes)) if (e.nodeName === "OPTION" && e.value === t.value) {
1351
+ n.selectionChanged = !0;
1352
+ break;
1353
+ }
1354
+ n.optgroupOptionChanged = !0;
1355
+ }
1356
+ (r.target.nodeName === "OPTGROUP" || r.target.nodeName === "OPTION") && (n.optgroupOptionChanged = !0);
809
1357
  }
810
- }, g = class {
1358
+ return n;
1359
+ }
1360
+ //#endregion
1361
+ //#region src/slim-select/select.ts
1362
+ var B = class {
811
1363
  select;
812
1364
  onValueChange;
813
1365
  onClassChange;
@@ -869,29 +1421,19 @@ var f = class {
869
1421
  }
870
1422
  observeCall(e) {
871
1423
  if (!this.listen) return;
872
- let t = !1, n = !1, r = !1, i = !1;
873
- for (let a of e) {
874
- if (a.target === this.select && (a.attributeName === "disabled" && (n = !0), a.attributeName === "class" && (t = !0), a.type === "childList")) {
875
- for (let e of Array.from(a.addedNodes)) if (e.nodeName === "OPTION" && e.value === this.select.value) {
876
- i = !0;
877
- break;
878
- }
879
- r = !0;
880
- }
881
- (a.target.nodeName === "OPTGROUP" || a.target.nodeName === "OPTION") && (r = !0);
882
- }
1424
+ let { classChanged: t, disabledChanged: n, optgroupOptionChanged: r, selectionChanged: i } = z(e, this.select), a = i;
883
1425
  if (t && this.onClassChange && this.onClassChange(this.select.className.split(" ")), n && this.onDisabledChange && (this.changeListen(!1), this.onDisabledChange(this.select.disabled), this.changeListen(!0)), r && this.onOptionsChange) {
884
1426
  if (this.isUpdating) {
885
1427
  if (this.select.options.length > 0) {
886
1428
  let e = this.getData();
887
1429
  e.length > 0 && (this.pendingOptionsChange = e);
888
1430
  }
889
- i && this.select.dispatchEvent(new Event("change"));
1431
+ a && this.select.dispatchEvent(new Event("change"));
890
1432
  return;
891
1433
  }
892
- this.changeListen(!1), this.onOptionsChange(this.getData()), this.changeListen(!0);
1434
+ this.changeListen(!1), this.onOptionsChange(this.getData()), this.changeListen(!0), a = !1;
893
1435
  }
894
- i && this.select.dispatchEvent(new Event("change"));
1436
+ a && this.select.dispatchEvent(new Event("change"));
895
1437
  }
896
1438
  getData() {
897
1439
  let e = [], t = this.select.childNodes;
@@ -903,7 +1445,6 @@ var f = class {
903
1445
  id: e.id,
904
1446
  label: e.label,
905
1447
  selectAll: e.dataset ? e.dataset.selectall === "true" : !1,
906
- selectAllText: e.dataset ? e.dataset.selectalltext : "Select all",
907
1448
  closable: e.dataset ? e.dataset.closable : "off",
908
1449
  options: []
909
1450
  }, n = e.childNodes;
@@ -924,7 +1465,7 @@ var f = class {
924
1465
  placeholder: e.dataset.placeholder === "true",
925
1466
  class: e.className,
926
1467
  style: e.style.cssText,
927
- data: e.dataset
1468
+ data: _(e.dataset)
928
1469
  };
929
1470
  }
930
1471
  getSelectedOptions() {
@@ -963,7 +1504,8 @@ var f = class {
963
1504
  t.selected = e.includes(t.id);
964
1505
  }
965
1506
  }
966
- this.changeListen(!0);
1507
+ let n = this.getSelectedOptions();
1508
+ this.select.multiple || (this.select.value = n.length === 1 ? n[0].value : ""), this.changeListen(!0);
967
1509
  }
968
1510
  setSelectedByValue(e) {
969
1511
  this.changeListen(!1);
@@ -981,7 +1523,8 @@ var f = class {
981
1523
  t.selected = e.includes(t.value);
982
1524
  }
983
1525
  }
984
- this.changeListen(!0);
1526
+ let n = this.getSelectedOptions();
1527
+ this.select.multiple || (this.select.value = n.length === 1 ? n[0].value : ""), this.changeListen(!0);
985
1528
  }
986
1529
  updateSelect(e, t, n) {
987
1530
  this.changeListen(!1), e && (this.select.dataset.id = e), t && (this.select.style.cssText = t), n && (this.select.className = "", n.forEach((e) => {
@@ -991,7 +1534,7 @@ var f = class {
991
1534
  updateOptions(e) {
992
1535
  if (!(!e || e.length === 0)) {
993
1536
  this.isUpdating = !0, this.pendingOptionsChange = null, this.changeListen(!1), this.select.innerHTML = "";
994
- for (let t of e) t instanceof p && this.select.appendChild(this.createOptgroup(t)), t instanceof f && this.select.appendChild(this.createOption(t));
1537
+ for (let t of e) t instanceof I && this.select.appendChild(this.createOptgroup(t)), t instanceof F && this.select.appendChild(this.createOption(t));
995
1538
  if (this.select.dispatchEvent(new Event("change", { bubbles: !0 })), this.changeListen(!0), this.isUpdating = !1, this.pendingOptionsChange !== null) {
996
1539
  let e = this.pendingOptionsChange;
997
1540
  e.length > 0 && this.onOptionsChange ? (this.pendingOptionsChange = null, this.changeListen(!1), this.onOptionsChange(e), this.changeListen(!0)) : this.pendingOptionsChange = null;
@@ -1008,7 +1551,7 @@ var f = class {
1008
1551
  return t.id = e.id, t.value = e.value, t.textContent = e.text, e.html !== "" && t.setAttribute("data-html", e.html), t.defaultSelected = e.defaultSelected, t.selected = e.selected, e.disabled && (t.disabled = !0), e.display || (t.style.display = "none"), e.placeholder && t.setAttribute("data-placeholder", "true"), e.mandatory && t.setAttribute("data-mandatory", "true"), e.class && e.class.split(" ").forEach((e) => {
1009
1552
  t.classList.add(e);
1010
1553
  }), e.data && typeof e.data == "object" && Object.keys(e.data).forEach((n) => {
1011
- t.setAttribute("data-" + d(n), e.data[n]);
1554
+ t.setAttribute("data-" + j(n), e.data[n]);
1012
1555
  }), t;
1013
1556
  }
1014
1557
  setupLabelHandlers() {
@@ -1025,7 +1568,7 @@ var f = class {
1025
1568
  Array.from(new Set(e)).forEach((e) => {
1026
1569
  if (e.__slimSelectLabelHandler) return;
1027
1570
  let t = (e) => {
1028
- let t = e.target, n = c(t, this.select.dataset.id);
1571
+ let t = e.target, n = x(t, this.select.dataset.id);
1029
1572
  e.preventDefault(), !n && this.onLabelClick && this.onLabelClick();
1030
1573
  };
1031
1574
  e.__slimSelectLabelHandler = t, e.addEventListener("click", t, {
@@ -1053,56 +1596,118 @@ var f = class {
1053
1596
  destroy() {
1054
1597
  this.changeListen(!1), this.select.removeEventListener("change", this.valueChange), this.preventNativeSelect &&= (this.select.removeEventListener("click", this.preventNativeSelect, { capture: !0 }), null), this.preventNativeSelectMousedown &&= (this.select.removeEventListener("mousedown", this.preventNativeSelectMousedown, { capture: !0 }), null), this.preventNativeSelectFocus &&= (this.select.removeEventListener("focus", this.preventNativeSelectFocus, { capture: !0 }), null), this.restoreAriaHiddenOnBlur &&= (this.select.removeEventListener("blur", this.restoreAriaHiddenOnBlur, { capture: !0 }), null), this.observer &&= (this.observer.disconnect(), null), this.removeLabelHandlers(), delete this.select.dataset.id, this.showUI();
1055
1598
  }
1056
- }, _ = class {
1057
- id = "";
1058
- style = "";
1059
- class = [];
1060
- isMultiple = !1;
1061
- isOpen = !1;
1062
- isFullOpen = !1;
1063
- intervalMove = null;
1064
- disabled;
1065
- alwaysOpen;
1066
- showSearch;
1067
- focusSearch;
1068
- keepSearch;
1069
- ariaLabel;
1070
- searchPlaceholder;
1071
- searchText;
1072
- searchingText;
1073
- resultsText;
1074
- deselectText;
1075
- removeText;
1076
- searchHighlight;
1077
- closeOnSelect;
1078
- contentLocation;
1079
- contentPosition;
1080
- contentWidth;
1081
- openPosition;
1082
- placeholderText;
1083
- allowDeselect;
1084
- hideSelected;
1085
- multiString;
1086
- keepOrder;
1087
- showOptionTooltips;
1088
- minSelected;
1089
- maxSelected;
1090
- timeoutDelay;
1091
- maxValuesShown;
1092
- maxValuesMessage;
1093
- addableText;
1599
+ };
1600
+ //#endregion
1601
+ //#region src/slim-select/sync.ts
1602
+ function V(e, t) {
1603
+ return A(e.getData(!1), t);
1604
+ }
1605
+ function H(e, t) {
1606
+ let n = Array.isArray(t) ? t : [t], r = e.getDataOptions(!1), i = [];
1607
+ for (let e of n) {
1608
+ if (r.find((t) => t.id == e)) {
1609
+ i.push(e);
1610
+ continue;
1611
+ }
1612
+ for (let t of r.filter((t) => t.value == e)) i.push(t.id);
1613
+ }
1614
+ return i;
1615
+ }
1616
+ var U = class {
1617
+ deps;
1618
+ queue = [];
1619
+ flushScheduled = !1;
1620
+ isSyncing = !1;
1094
1621
  constructor(e) {
1095
- e ||= {}, this.id = "ss-" + s(), this.style = e.style || "", this.class = e.class || [], this.disabled = e.disabled === void 0 ? !1 : e.disabled, this.alwaysOpen = e.alwaysOpen === void 0 ? !1 : e.alwaysOpen, this.showSearch = e.showSearch === void 0 ? !0 : e.showSearch, this.focusSearch = e.focusSearch === void 0 ? !0 : e.focusSearch, this.keepSearch = e.keepSearch === void 0 ? !1 : e.keepSearch, this.ariaLabel = e.ariaLabel || "Combobox", this.searchPlaceholder = e.searchPlaceholder || "Search...", this.searchText = e.searchText || "No Results", this.searchingText = e.searchingText || "Searching...", this.resultsText = e.resultsText || "{count} results available", this.deselectText = e.deselectText || "Clear", this.removeText = e.removeText || "Remove", this.searchHighlight = e.searchHighlight === void 0 ? !1 : e.searchHighlight, this.closeOnSelect = e.closeOnSelect === void 0 ? !0 : e.closeOnSelect, 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 ? "Select Value" : e.placeholderText, this.allowDeselect = e.allowDeselect === void 0 ? !1 : e.allowDeselect, this.hideSelected = e.hideSelected === void 0 ? !1 : e.hideSelected, this.multiString = e.multiString === void 0 ? !1 : e.multiString, this.keepOrder = e.keepOrder === void 0 ? !1 : e.keepOrder, this.showOptionTooltips = e.showOptionTooltips === void 0 ? !1 : e.showOptionTooltips, 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}";
1622
+ this.deps = e;
1623
+ }
1624
+ enqueue(e) {
1625
+ if (this.queue.push(e), e.source === "native") {
1626
+ this.flushScheduled || (this.flushScheduled = !0, queueMicrotask(() => this.flush()));
1627
+ return;
1628
+ }
1629
+ this.isSyncing || this.flush();
1630
+ }
1631
+ flush() {
1632
+ if (this.flushScheduled = !1, this.queue.length === 0) return;
1633
+ let e = this.coalesceBatch(this.queue);
1634
+ this.queue = [], this.isSyncing = !0;
1635
+ try {
1636
+ for (let t of e) this.applyChange(t);
1637
+ } finally {
1638
+ this.isSyncing = !1, this.queue.length > 0 && this.flush();
1639
+ }
1640
+ }
1641
+ coalesceBatch(e) {
1642
+ let t = e.some((e) => e.type === "structure"), n = e.some((e) => e.type === "addOption");
1643
+ if (t || n) {
1644
+ let t = e.filter((e) => e.type === "structure" || e.type === "addOption"), n = t[t.length - 1];
1645
+ return n?.type === "structure" ? [n] : t;
1646
+ }
1647
+ let r = e.filter((e) => e.type === "selection");
1648
+ return r.length > 0 ? [r[r.length - 1]] : e;
1096
1649
  }
1097
- }, v = class {
1650
+ applyChange(e) {
1651
+ switch (e.type) {
1652
+ case "structure":
1653
+ this.applyStructure(e.data, e.source, e.preserveSelection, e.isSearchResult);
1654
+ break;
1655
+ case "selection":
1656
+ this.applySelection(e.values, e.source, e.runAfterChange !== !1);
1657
+ break;
1658
+ case "addOption":
1659
+ this.applyAddOption(e.option);
1660
+ break;
1661
+ }
1662
+ }
1663
+ applyStructure(e, t, n = !1, r = !1) {
1664
+ let { store: i, select: a, render: o, events: s } = this.deps;
1665
+ if (V(i, e)) return;
1666
+ let c = i.getSelected(), l = i.validateDataArray(e);
1667
+ if (l) {
1668
+ s.error ? s.error(l) : this.deps.onError && this.deps.onError(l);
1669
+ return;
1670
+ }
1671
+ i.setData(e, n);
1672
+ let u = i.getData(!1);
1673
+ r || i.snapshotCatalog(), a.updateOptions(u), o.renderValues(), o.renderOptions(u), s.afterChange && !C(c, i.getSelected()) && s.afterChange(i.getSelectedOptions());
1674
+ }
1675
+ applySelection(e, t, n) {
1676
+ let { store: r, select: i, render: a, events: o } = this.deps, s = r.getSelected(), c = H(r, e);
1677
+ if (C(s, c)) return;
1678
+ r.setSelectedBy("id", c), i.setSelectedByValue(r.getSelectedValues()), a.renderValues();
1679
+ let l = a.content.search.input.value.trim();
1680
+ l === "" ? a.canUpdateOptionSelectionInPlace() ? a.updateOptionSelection() : a.renderOptions(r.getData(!1)) : a.hasRenderedOptions() ? a.updateOptionSelection() : this.deps.search && this.deps.search(l), n && o.afterChange && !C(s, r.getSelected()) && o.afterChange(r.getSelectedOptions());
1681
+ }
1682
+ applyAddOption(e) {
1683
+ let { store: t, select: n, render: r, events: i } = this.deps, a = t.getSelected(), o = r.content.search.input.value.trim() !== "" && !!this.deps.search, s = e.value ?? e.text ?? "", c = (e) => {
1684
+ for (let t of e) {
1685
+ if (t instanceof I) {
1686
+ if (t.options.some((e) => (e.value ?? e.text) === s)) return !0;
1687
+ continue;
1688
+ }
1689
+ if ((t.value ?? t.text) === s) return !0;
1690
+ }
1691
+ return !1;
1692
+ };
1693
+ if (!c(t.getData(!1))) if (o) {
1694
+ let n = t.getCatalogData();
1695
+ c(n) || t.setData([...n, new F(e)], !0), t.snapshotCatalog();
1696
+ } else t.addOption(e), t.snapshotCatalog();
1697
+ let l = t.getData(!1);
1698
+ n.updateOptions(l), r.renderValues(), r.renderOptions(l), i.afterChange && !C(a, t.getSelected()) && i.afterChange(t.getSelectedOptions());
1699
+ }
1700
+ }, W = class {
1098
1701
  selectEl;
1099
1702
  settings;
1100
1703
  cssClasses;
1101
1704
  select;
1102
1705
  store;
1103
1706
  render;
1104
- openTimeout = null;
1105
- closeTimeout = null;
1707
+ sync;
1708
+ lifecycle;
1709
+ globalEvents;
1710
+ searchGeneration = 0;
1106
1711
  events = {
1107
1712
  search: void 0,
1108
1713
  searchFilter: (e, t) => e.text.toLowerCase().indexOf(t.toLowerCase()) !== -1,
@@ -1123,38 +1728,88 @@ var f = class {
1123
1728
  e.events && e.events.error && e.events.error(/* @__PURE__ */ Error("Element isnt of type select"));
1124
1729
  return;
1125
1730
  }
1126
- this.selectEl.dataset.ssid && this.destroy(), this.settings = new _(e.settings), this.cssClasses = new o(e.cssClasses);
1731
+ this.selectEl.dataset.ssid && this.destroy(), this.settings = new g(e.settings), this.cssClasses = new o(e.cssClasses);
1127
1732
  let t = [
1128
1733
  "beforeOpen",
1129
1734
  "afterOpen",
1130
1735
  "beforeClose",
1131
1736
  "afterClose"
1132
1737
  ];
1133
- for (let n in e.events) e.events.hasOwnProperty(n) && (t.indexOf(n) === -1 ? this.events[n] = e.events[n] : this.events[n] = l(e.events[n], 100));
1134
- 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 g(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 = (e) => {
1135
- this.setSelected(e.map((e) => e.id));
1136
- }, this.select.onClassChange = (e) => {
1738
+ for (let n in e.events) e.events.hasOwnProperty(n) && (t.indexOf(n) === -1 ? this.events[n] = e.events[n] : this.events[n] = S(e.events[n], 100));
1739
+ 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 B(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.onClassChange = (e) => {
1137
1740
  this.settings.class = e, this.render.updateClassStyles();
1138
1741
  }, this.select.onDisabledChange = (e) => {
1139
1742
  e ? this.disable() : this.enable();
1140
- }, this.select.onOptionsChange = (e) => {
1141
- this.setData(e || []);
1142
1743
  }, this.select.onLabelClick = () => {
1143
1744
  this.settings.disabled || (this.settings.isOpen ? this.close() : this.open());
1144
1745
  };
1145
1746
  let n = e.data ? e.data : this.select.getData();
1146
- this.store = new m(this.settings.isMultiple ? "multiple" : "single", n), e.data && this.select.updateOptions(this.store.getData());
1747
+ this.store = new L(this.settings.isMultiple ? "multiple" : "single", n), e.data && this.select.updateOptions(this.store.getData());
1147
1748
  let r = {
1148
1749
  open: this.open.bind(this),
1149
1750
  close: this.close.bind(this),
1150
1751
  addable: this.events.addable ? this.events.addable : void 0,
1151
- setSelected: this.setSelected.bind(this),
1152
- addOption: this.addOption.bind(this),
1752
+ setSelected: (e, t) => {
1753
+ this.sync.enqueue({
1754
+ type: "selection",
1755
+ values: e,
1756
+ source: "ui",
1757
+ runAfterChange: t
1758
+ });
1759
+ },
1760
+ addOption: (e) => {
1761
+ this.sync.enqueue({
1762
+ type: "addOption",
1763
+ option: e,
1764
+ source: "ui"
1765
+ });
1766
+ },
1153
1767
  search: this.search.bind(this),
1154
1768
  beforeChange: this.events.beforeChange,
1155
1769
  afterChange: this.events.afterChange
1156
1770
  };
1157
- this.render = new h(this.settings, this.cssClasses, this.store, r), this.render.renderValues(), this.render.renderOptions(this.store.getData());
1771
+ this.settings.modalTitle = e.settings?.modalTitle ?? y(this.selectEl), this.render = new R(this.settings, this.cssClasses, this.store, r), this.settings.timeoutDelay = d(this.render.content.main, e.settings?.timeoutDelay), this.sync = new U({
1772
+ select: this.select,
1773
+ store: this.store,
1774
+ render: this.render,
1775
+ events: this.events,
1776
+ search: this.search.bind(this)
1777
+ }), this.select.onValueChange = (e) => {
1778
+ this.sync.enqueue({
1779
+ type: "selection",
1780
+ values: e.map((e) => e.id),
1781
+ source: "native"
1782
+ });
1783
+ }, this.select.onOptionsChange = (e) => {
1784
+ this.sync.enqueue({
1785
+ type: "structure",
1786
+ data: e || [],
1787
+ source: "native"
1788
+ });
1789
+ }, this.lifecycle = new P({
1790
+ beforeOpen: this.events.beforeOpen,
1791
+ afterOpen: this.events.afterOpen,
1792
+ beforeClose: this.events.beforeClose,
1793
+ afterClose: () => {
1794
+ this.render.clearDirectionClasses(), this.render.finalizeModalClose(), this.events.afterClose && this.events.afterClose();
1795
+ },
1796
+ onOpenReady: () => this.globalEvents.attachDocumentClick(),
1797
+ onCloseReady: () => this.globalEvents.detachDocumentClick()
1798
+ }, {
1799
+ timeoutDelay: this.settings.timeoutDelay,
1800
+ waitForAnimation: (e, t) => this.render.waitForAnimation(e, t)
1801
+ }), this.globalEvents = new N({
1802
+ onDocumentClick: this.documentClick.bind(this),
1803
+ onWindowResize: () => {
1804
+ !this.settings.isOpen && !this.settings.isFullOpen || this.render.moveContent();
1805
+ },
1806
+ onWindowScroll: () => {
1807
+ !this.settings.isOpen && !this.settings.isFullOpen || this.render.moveContent();
1808
+ },
1809
+ onVisibilityChange: () => {
1810
+ document.hidden && this.close();
1811
+ }
1812
+ }), this.render.renderValues(), this.render.renderOptions(this.store.getData(!1));
1158
1813
  let i = this.selectEl.getAttribute("aria-label"), a = this.selectEl.getAttribute("aria-labelledby");
1159
1814
  if (i) this.render.main.main.setAttribute("aria-label", i);
1160
1815
  else if (a) this.render.main.main.removeAttribute("aria-label"), this.render.main.main.setAttribute("aria-labelledby", a);
@@ -1162,7 +1817,7 @@ var f = class {
1162
1817
  let e = Array.from(this.selectEl.labels).map((e, t) => (e.id ||= `${this.settings.id}-label-${t}`, e.id));
1163
1818
  this.render.main.main.removeAttribute("aria-label"), this.render.main.main.setAttribute("aria-labelledby", e.join(" "));
1164
1819
  }
1165
- 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;
1820
+ this.selectEl.parentNode && this.selectEl.parentNode.insertBefore(this.render.main.main, this.selectEl.nextSibling), this.globalEvents.attach({ listenScroll: this.settings.openPosition === "auto" }), this.settings.disabled && this.disable(), this.settings.alwaysOpen && this.open(), this.select.setupLabelHandlers(), this.selectEl.slim = this;
1166
1821
  }
1167
1822
  enable() {
1168
1823
  this.settings.disabled = !1, this.select.enable(), this.render.enable();
@@ -1174,309 +1829,165 @@ var f = class {
1174
1829
  return this.store.getData();
1175
1830
  }
1176
1831
  setData(e) {
1177
- let t = this.store.getSelected(), n = this.store.validateDataArray(e);
1178
- if (n) {
1179
- this.events.error && this.events.error(n);
1180
- return;
1181
- }
1182
- this.store.setData(e);
1183
- let r = this.store.getData();
1184
- this.select.updateOptions(r), this.render.renderValues(), this.render.renderOptions(r), this.events.afterChange && !u(t, this.store.getSelected()) && this.events.afterChange(this.store.getSelectedOptions());
1832
+ this.sync.enqueue({
1833
+ type: "structure",
1834
+ data: e,
1835
+ source: "api"
1836
+ });
1185
1837
  }
1186
1838
  getSelected() {
1187
1839
  let e = this.store.getSelectedOptions();
1188
1840
  return this.settings.keepOrder && (e = this.store.selectedOrderOptions(e)), e.map((e) => e.value);
1189
1841
  }
1190
1842
  setSelected(e, t = !0) {
1191
- let n = this.store.getSelected(), r = this.store.getDataOptions();
1192
- e = Array.isArray(e) ? e : [e];
1193
- let i = [];
1194
- for (let t of e) {
1195
- if (r.find((e) => e.id == t)) {
1196
- i.push(t);
1197
- continue;
1198
- }
1199
- for (let e of r.filter((e) => e.value == t)) i.push(e.id);
1200
- }
1201
- this.store.setSelectedBy("id", i);
1202
- let a = this.store.getData();
1203
- this.select.updateOptions(a), this.render.renderValues(), this.render.content.search.input.value === "" ? this.render.renderOptions(a) : this.search(this.render.content.search.input.value), t && this.events.afterChange && !u(n, this.store.getSelected()) && this.events.afterChange(this.store.getSelectedOptions());
1843
+ this.sync.enqueue({
1844
+ type: "selection",
1845
+ values: e,
1846
+ source: "api",
1847
+ runAfterChange: t
1848
+ });
1204
1849
  }
1205
1850
  addOption(e) {
1206
- let t = this.store.getSelected();
1207
- this.store.getDataOptions().some((t) => t.value === (e.value ?? e.text)) || this.store.addOption(e);
1208
- let n = this.store.getData();
1209
- this.select.updateOptions(n), this.render.renderValues(), this.render.renderOptions(n), this.events.afterChange && !u(t, this.store.getSelected()) && this.events.afterChange(this.store.getSelectedOptions());
1851
+ this.sync.enqueue({
1852
+ type: "addOption",
1853
+ option: e,
1854
+ source: "api"
1855
+ });
1210
1856
  }
1211
1857
  open() {
1212
- this.settings.disabled || this.settings.isOpen || (this.closeTimeout &&= (clearTimeout(this.closeTimeout), null), 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(() => {
1213
- this.events.afterOpen && this.events.afterOpen(), this.settings.isOpen && (this.settings.isFullOpen = !0), document.addEventListener("click", this.documentClick);
1214
- }, 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)));
1858
+ if (this.settings.disabled || this.settings.isOpen) return;
1859
+ this.lifecycle.cancelPending(), this.render.open(), this.settings.showSearch && this.settings.focusSearch && this.render.searchFocus(), this.settings.isOpen = !0, this.lifecycle.requestOpen().then(() => {
1860
+ this.settings.isOpen && (this.settings.isFullOpen = this.lifecycle.isFullOpen, this.settings.isOpen = this.lifecycle.isOpen);
1861
+ }), this.settings.contentPosition === "absolute" && !this.render.isModalViewActive() && this.render.startPositionTracking();
1862
+ let e = this.render.content.search.input.value.trim();
1863
+ e !== "" && this.search(e);
1215
1864
  }
1216
1865
  close(e = null) {
1217
- !this.settings.isOpen || this.settings.alwaysOpen || (this.openTimeout &&= (clearTimeout(this.openTimeout), null), 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(() => {
1218
- this.events.afterClose && this.events.afterClose(), document.removeEventListener("click", this.documentClick);
1219
- }, this.settings.timeoutDelay), this.settings.intervalMove && clearInterval(this.settings.intervalMove));
1866
+ !this.settings.isOpen || this.settings.alwaysOpen || (this.lifecycle.cancelPending(), this.render.close(), !this.settings.keepSearch && this.render.content.search.input.value !== "" && (this.sync.flush(), this.search("")), this.render.mainFocus(e), this.settings.isOpen = !1, this.settings.isFullOpen = !1, this.lifecycle.requestClose().then(() => {
1867
+ this.settings.isOpen || (this.settings.isOpen = this.lifecycle.isOpen, this.settings.isFullOpen = this.lifecycle.isFullOpen);
1868
+ }), this.render.stopPositionTracking());
1220
1869
  }
1221
1870
  search(e) {
1222
- if (this.render.content.search.input.value !== e && (this.render.content.search.input.value = e), e === "") {
1223
- this.render.renderOptions(this.store.getData());
1871
+ let t = e.trim();
1872
+ if (this.render.content.search.input.value !== t && (this.render.content.search.input.value = t), t === "") {
1873
+ this.clearSearch();
1224
1874
  return;
1225
1875
  }
1226
- if (!this.events.search) {
1227
- let t = e === "" ? this.store.getData() : this.store.search(e, this.events.searchFilter);
1228
- this.render.renderOptions(t);
1876
+ if (this.events.search) {
1877
+ this.runApiSearch(t);
1229
1878
  return;
1230
1879
  }
1231
- this.render.renderSearching();
1232
- let t = this.events.search(e, this.store.getSelectedOptions());
1233
- if (t instanceof Promise) {
1234
- t.then((e) => {
1235
- this.store.setData(e, !0), this.select.updateOptions(this.store.getData()), this.render.renderOptions(this.store.getData());
1236
- }).catch((e) => {
1237
- this.render.renderError(typeof e == "string" ? e : e.message);
1238
- });
1880
+ this.runLocalSearch(t);
1881
+ }
1882
+ clearSearch() {
1883
+ if (this.searchGeneration++, !this.events.search && this.render.canFilterOptionsInPlace()) {
1884
+ this.render.filterOptionsInPlace("", this.events.searchFilter), this.render.resetSearchFilterState();
1239
1885
  return;
1240
- } else Array.isArray(t) ? (this.store.setData(t, !0), this.select.updateOptions(this.store.getData()), this.render.renderOptions(this.store.getData())) : this.render.renderError("Search event must return a promise or an array of data");
1886
+ }
1887
+ this.render.resetSearchFilterState(), this.sync.enqueue({
1888
+ type: "structure",
1889
+ data: this.store.getCatalogData(),
1890
+ source: "api",
1891
+ preserveSelection: !0
1892
+ });
1241
1893
  }
1242
- destroy() {
1243
- this.openTimeout &&= (clearTimeout(this.openTimeout), null), this.closeTimeout &&= (clearTimeout(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();
1894
+ runLocalSearch(e) {
1895
+ if (this.render.canFilterOptionsInPlace()) {
1896
+ this.render.filterOptionsInPlace(e, this.events.searchFilter);
1897
+ return;
1898
+ }
1899
+ let t = this.store.search(e, this.events.searchFilter);
1900
+ this.render.renderOptions(t);
1244
1901
  }
1245
- windowResize = l(() => {
1246
- !this.settings.isOpen && !this.settings.isFullOpen || this.render.moveContent();
1247
- });
1248
- windowScroll = l(() => {
1249
- !this.settings.isOpen && !this.settings.isFullOpen || this.render.moveContent();
1250
- });
1251
- documentClick = (e) => {
1252
- this.settings.isOpen && e.target && !c(e.target, this.settings.id) && this.close(e.type);
1253
- };
1254
- windowVisibilityChange = () => {
1255
- document.hidden && this.close();
1256
- };
1257
- }, y = /* @__PURE__ */ i(((e) => {
1258
- var t = Symbol.for("react.transitional.element"), n = Symbol.for("react.fragment");
1259
- function r(e, n, r) {
1260
- var i = null;
1261
- if (r !== void 0 && (i = "" + r), n.key !== void 0 && (i = "" + n.key), "key" in n) for (var a in r = {}, n) a !== "key" && (r[a] = n[a]);
1262
- else r = n;
1263
- return n = r.ref, {
1264
- $$typeof: t,
1265
- type: e,
1266
- key: i,
1267
- ref: n === void 0 ? null : n,
1268
- props: r
1902
+ runApiSearch(e) {
1903
+ let t = ++this.searchGeneration;
1904
+ this.render.renderSearching();
1905
+ let n = this.events.search(e, this.store.getSelectedOptions(), this.store.getCatalogData()), r = (n) => {
1906
+ t === this.searchGeneration && this.render.content.search.input.value.trim() === e && this.sync.enqueue({
1907
+ type: "structure",
1908
+ data: n,
1909
+ source: "api",
1910
+ preserveSelection: !0,
1911
+ isSearchResult: !0
1912
+ });
1269
1913
  };
1270
- }
1271
- e.Fragment = n, e.jsx = r, e.jsxs = r;
1272
- })), b = /* @__PURE__ */ i(((e) => {
1273
- process.env.NODE_ENV !== "production" && (function() {
1274
- function t(e) {
1275
- if (e == null) return null;
1276
- if (typeof e == "function") return e.$$typeof === k ? null : e.displayName || e.name || null;
1277
- if (typeof e == "string") return e;
1278
- switch (e) {
1279
- case v: return "Fragment";
1280
- case b: return "Profiler";
1281
- case y: return "StrictMode";
1282
- case w: return "Suspense";
1283
- case T: return "SuspenseList";
1284
- case O: return "Activity";
1285
- }
1286
- if (typeof e == "object") switch (typeof e.tag == "number" && console.error("Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."), e.$$typeof) {
1287
- case _: return "Portal";
1288
- case S: return e.displayName || "Context";
1289
- case x: return (e._context.displayName || "Context") + ".Consumer";
1290
- case C:
1291
- var n = e.render;
1292
- return e = e.displayName, e ||= (e = n.displayName || n.name || "", e === "" ? "ForwardRef" : "ForwardRef(" + e + ")"), e;
1293
- case E: return n = e.displayName || null, n === null ? t(e.type) || "Memo" : n;
1294
- case D:
1295
- n = e._payload, e = e._init;
1296
- try {
1297
- return t(e(n));
1298
- } catch {}
1299
- }
1300
- return null;
1301
- }
1302
- function n(e) {
1303
- return "" + e;
1304
- }
1305
- function r(e) {
1306
- try {
1307
- n(e);
1308
- var t = !1;
1309
- } catch {
1310
- t = !0;
1311
- }
1312
- if (t) {
1313
- t = console;
1314
- var r = t.error, i = typeof Symbol == "function" && Symbol.toStringTag && e[Symbol.toStringTag] || e.constructor.name || "Object";
1315
- return r.call(t, "The provided key is an unsupported type %s. This value must be coerced to a string before using it here.", i), n(e);
1316
- }
1317
- }
1318
- function i(e) {
1319
- if (e === v) return "<>";
1320
- if (typeof e == "object" && e && e.$$typeof === D) return "<...>";
1321
- try {
1322
- var n = t(e);
1323
- return n ? "<" + n + ">" : "<...>";
1324
- } catch {
1325
- return "<...>";
1326
- }
1327
- }
1328
- function o() {
1329
- var e = A.A;
1330
- return e === null ? null : e.getOwner();
1331
- }
1332
- function s() {
1333
- return Error("react-stack-top-frame");
1334
- }
1335
- function c(e) {
1336
- if (j.call(e, "key")) {
1337
- var t = Object.getOwnPropertyDescriptor(e, "key").get;
1338
- if (t && t.isReactWarning) return !1;
1339
- }
1340
- return e.key !== void 0;
1341
- }
1342
- function l(e, t) {
1343
- function n() {
1344
- P || (P = !0, console.error("%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)", t));
1345
- }
1346
- n.isReactWarning = !0, Object.defineProperty(e, "key", {
1347
- get: n,
1348
- configurable: !0
1914
+ if (n instanceof Promise) {
1915
+ n.then(r).catch((e) => {
1916
+ t === this.searchGeneration && this.render.renderError(typeof e == "string" ? e : e.message);
1349
1917
  });
1918
+ return;
1350
1919
  }
1351
- function u() {
1352
- var e = t(this.type);
1353
- return F[e] || (F[e] = !0, console.error("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.")), e = this.props.ref, e === void 0 ? null : e;
1354
- }
1355
- function d(e, t, n, r, i, a) {
1356
- var o = n.ref;
1357
- return e = {
1358
- $$typeof: g,
1359
- type: e,
1360
- key: t,
1361
- props: n,
1362
- _owner: r
1363
- }, (o === void 0 ? null : o) === null ? Object.defineProperty(e, "ref", {
1364
- enumerable: !1,
1365
- value: null
1366
- }) : Object.defineProperty(e, "ref", {
1367
- enumerable: !1,
1368
- get: u
1369
- }), e._store = {}, Object.defineProperty(e._store, "validated", {
1370
- configurable: !1,
1371
- enumerable: !1,
1372
- writable: !0,
1373
- value: 0
1374
- }), Object.defineProperty(e, "_debugInfo", {
1375
- configurable: !1,
1376
- enumerable: !1,
1377
- writable: !0,
1378
- value: null
1379
- }), Object.defineProperty(e, "_debugStack", {
1380
- configurable: !1,
1381
- enumerable: !1,
1382
- writable: !0,
1383
- value: i
1384
- }), Object.defineProperty(e, "_debugTask", {
1385
- configurable: !1,
1386
- enumerable: !1,
1387
- writable: !0,
1388
- value: a
1389
- }), Object.freeze && (Object.freeze(e.props), Object.freeze(e)), e;
1390
- }
1391
- function f(e, n, i, a, s, u) {
1392
- var f = n.children;
1393
- if (f !== void 0) if (a) if (M(f)) {
1394
- for (a = 0; a < f.length; a++) p(f[a]);
1395
- Object.freeze && Object.freeze(f);
1396
- } else console.error("React.jsx: Static children should always be an array. You are likely explicitly calling React.jsxs or React.jsxDEV. Use the Babel transform instead.");
1397
- else p(f);
1398
- if (j.call(n, "key")) {
1399
- f = t(e);
1400
- var m = Object.keys(n).filter(function(e) {
1401
- return e !== "key";
1402
- });
1403
- a = 0 < m.length ? "{key: someKey, " + m.join(": ..., ") + ": ...}" : "{key: someKey}", R[f + a] || (m = 0 < m.length ? "{" + m.join(": ..., ") + ": ...}" : "{}", console.error("A props object containing a \"key\" prop is being spread into JSX:\n let props = %s;\n <%s {...props} />\nReact keys must be passed directly to JSX without using spread:\n let props = %s;\n <%s key={someKey} {...props} />", a, f, m, f), R[f + a] = !0);
1404
- }
1405
- if (f = null, i !== void 0 && (r(i), f = "" + i), c(n) && (r(n.key), f = "" + n.key), "key" in n) for (var h in i = {}, n) h !== "key" && (i[h] = n[h]);
1406
- else i = n;
1407
- return f && l(i, typeof e == "function" ? e.displayName || e.name || "Unknown" : e), d(e, f, i, o(), s, u);
1408
- }
1409
- function p(e) {
1410
- m(e) ? e._store && (e._store.validated = 1) : typeof e == "object" && e && e.$$typeof === D && (e._payload.status === "fulfilled" ? m(e._payload.value) && e._payload.value._store && (e._payload.value._store.validated = 1) : e._store && (e._store.validated = 1));
1411
- }
1412
- function m(e) {
1413
- return typeof e == "object" && !!e && e.$$typeof === g;
1920
+ if (Array.isArray(n)) {
1921
+ r(n);
1922
+ return;
1414
1923
  }
1415
- var h = a("react"), g = Symbol.for("react.transitional.element"), _ = Symbol.for("react.portal"), v = Symbol.for("react.fragment"), y = Symbol.for("react.strict_mode"), b = Symbol.for("react.profiler"), x = Symbol.for("react.consumer"), S = Symbol.for("react.context"), C = Symbol.for("react.forward_ref"), w = Symbol.for("react.suspense"), T = Symbol.for("react.suspense_list"), E = Symbol.for("react.memo"), D = Symbol.for("react.lazy"), O = Symbol.for("react.activity"), k = Symbol.for("react.client.reference"), A = h.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE, j = Object.prototype.hasOwnProperty, M = Array.isArray, N = console.createTask ? console.createTask : function() {
1416
- return null;
1417
- };
1418
- h = { react_stack_bottom_frame: function(e) {
1419
- return e();
1420
- } };
1421
- var P, F = {}, I = h.react_stack_bottom_frame.bind(h, s)(), L = N(i(s)), R = {};
1422
- e.Fragment = v, e.jsx = function(e, t, n) {
1423
- var r = 1e4 > A.recentlyCreatedOwnerStacks++;
1424
- return f(e, t, n, !1, r ? Error("react-stack-top-frame") : I, r ? N(i(e)) : L);
1425
- }, e.jsxs = function(e, t, n) {
1426
- var r = 1e4 > A.recentlyCreatedOwnerStacks++;
1427
- return f(e, t, n, !0, r ? Error("react-stack-top-frame") : I, r ? N(i(e)) : L);
1428
- };
1429
- })();
1430
- })), x = (/* @__PURE__ */ i(((e, t) => {
1431
- process.env.NODE_ENV === "production" ? t.exports = y() : t.exports = b();
1432
- })))(), S = e(({ data: e, settings: i, events: a, cssClasses: o, value: s, onChange: c, children: l, multiple: u }, d) => {
1433
- let f = r(null), p = r(null), m = r(!0), h = r(s);
1434
- n(d, () => ({ slimSelect: p.current }));
1435
- let g = (e) => typeof e == "string" ? u ? [e] : e : Array.isArray(e) ? u ? e : e[0] : u ? [] : "", _ = (e, t = !1) => {
1436
- if (!p.current || e === void 0) return;
1437
- let n = g(e), r = p.current.getData().flatMap((e) => "label" in e ? e.options : [e]);
1924
+ this.render.renderError("Search event must return a promise or an array of data");
1925
+ }
1926
+ destroy() {
1927
+ this.lifecycle.destroy(), this.render.stopPositionTracking(), this.globalEvents.detach({ listenScroll: this.settings.openPosition === "auto" }), this.store.setData([]), this.render.destroy(), this.select.destroy();
1928
+ }
1929
+ documentClick(e) {
1930
+ this.settings.isOpen && e.target && !x(e.target, this.settings.id) && this.close(e.type);
1931
+ }
1932
+ }, G = e(({ data: e, settings: o, events: s, cssClasses: c, value: l, onChange: u, multiple: d }, f) => {
1933
+ let p = r(null), m = r(null), h = r(!0), g = r(l), _ = r(null), v = r(u), y = r(s), b = r(d), x = r(l), [S, C] = i(!1);
1934
+ t(() => {
1935
+ v.current = u;
1936
+ }, [u]), t(() => {
1937
+ y.current = s;
1938
+ }, [s]), t(() => {
1939
+ b.current = d;
1940
+ }, [d]), t(() => {
1941
+ x.current = l;
1942
+ }, [l]), n(f, () => ({ slimSelect: m.current }), [S]);
1943
+ let w = (e) => {
1944
+ let t = b.current;
1945
+ return typeof e == "string" ? t ? [e] : e : Array.isArray(e) ? t ? e : e[0] : t ? [] : "";
1946
+ }, T = (e, t = !1) => {
1947
+ if (!m.current || e === void 0) return;
1948
+ let n = w(e), r = m.current.getData().flatMap((e) => "label" in e ? e.options : [e]);
1438
1949
  if (!(Array.isArray(n) ? n.length > 0 && n.every((e) => r.some((t) => t.value === e)) : n !== "" && r.some((e) => e.value === n)) && !Array.isArray(n) && !r.some((e) => e.placeholder)) {
1439
- let e = p.current.getData();
1440
- p.current.setData([{
1950
+ let e = m.current.getData();
1951
+ m.current.setData([{
1441
1952
  value: "",
1442
1953
  text: "",
1443
1954
  placeholder: !0
1444
1955
  }].concat(e));
1445
1956
  }
1446
- p.current.setSelected(n, t);
1957
+ m.current.setSelected(n, t);
1958
+ }, E = (e) => {
1959
+ if (!m.current) return;
1960
+ let t = b.current ? e.map((e) => e.value) : e[0]?.value ?? "", n = m.current.getData().flatMap((e) => "label" in e ? e.options : [e]), r = g.current, i = r === void 0 ? !1 : Array.isArray(r) ? r.length > 0 && r.every((e) => n.some((t) => t.value === e)) : r !== "" && n.some((e) => e.value === r), a = Array.isArray(t) ? t.length > 0 && t.every((e) => n.some((t) => t.value === e)) : t !== "" && n.some((e) => e.value === t), o = Array.isArray(t) && Array.isArray(r) ? JSON.stringify(t.sort()) !== JSON.stringify(r.sort()) : r !== t;
1961
+ v.current && o && (i || a) && (v.current(t), g.current = t), y.current?.afterChange?.(e);
1447
1962
  };
1448
1963
  return t(() => {
1449
- if (!f.current) return;
1450
- let t = { select: f.current };
1451
- e && (t.data = e), i && (t.settings = i), o && (t.cssClasses = o);
1452
- let n = a?.afterChange;
1453
- return t.events = {
1454
- ...a,
1455
- afterChange: (e) => {
1456
- if (!p.current) return;
1457
- let t = u ? e.map((e) => e.value) : e[0]?.value ?? "", r = p.current.getData().flatMap((e) => "label" in e ? e.options : [e]), i = h.current, a = i === void 0 ? !1 : Array.isArray(i) ? i.length > 0 && i.every((e) => r.some((t) => t.value === e)) : i !== "" && r.some((e) => e.value === i), o = Array.isArray(t) ? t.length > 0 && t.every((e) => r.some((t) => t.value === e)) : t !== "" && r.some((e) => e.value === t), s = Array.isArray(t) && Array.isArray(i) ? JSON.stringify(t.sort()) !== JSON.stringify(i.sort()) : i !== t;
1458
- c && s && (a || o) && (c(t), h.current = t), n && n(e);
1459
- }
1460
- }, p.current = new v(t), s !== void 0 && _(s, !1), () => {
1461
- p.current &&= (p.current.destroy(), null);
1964
+ if (!p.current) return;
1965
+ let t = {
1966
+ select: p.current,
1967
+ data: e
1968
+ };
1969
+ return o && (t.settings = o), c && (t.cssClasses = c), t.events = {
1970
+ ...s,
1971
+ afterChange: E
1972
+ }, m.current = new W(t), _.current = structuredClone(e), C(!0), x.current !== void 0 && T(x.current, !1), () => {
1973
+ C(!1), m.current &&= (m.current.destroy(), null);
1462
1974
  };
1463
1975
  }, []), t(() => {
1464
- if (m.current) {
1465
- m.current = !1, h.current = s;
1976
+ if (h.current) {
1977
+ h.current = !1, g.current = l;
1466
1978
  return;
1467
1979
  }
1468
- p.current && s !== void 0 && (h.current = s, _(s, !1));
1469
- }, [s]), t(() => {
1470
- p.current && e && !m.current && (p.current.setData(e), s !== void 0 && _(s, !1));
1471
- }, [e]), /* @__PURE__ */ (0, x.jsx)("select", {
1472
- ref: f,
1473
- multiple: u,
1474
- children: l
1980
+ m.current && l !== void 0 && (g.current = l, T(l, !1));
1981
+ }, [l]), t(() => {
1982
+ !m.current || h.current || _.current !== null && A(_.current, e) || (m.current.setData(e), _.current = structuredClone(e), x.current !== void 0 && T(x.current, !1));
1983
+ }, [e]), /* @__PURE__ */ a("select", {
1984
+ ref: p,
1985
+ multiple: d
1475
1986
  });
1476
1987
  });
1477
- S.displayName = "SlimSelect";
1988
+ G.displayName = "SlimSelect";
1478
1989
  //#endregion
1479
1990
  //#region src/slim-select/react/index.tsx
1480
- var C = S;
1991
+ var K = G;
1481
1992
  //#endregion
1482
- export { p as Optgroup, f as Option, _ as Settings, C as default };
1993
+ export { I as Optgroup, F as Option, g as Settings, K as default };