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