slim-select 3.6.1 → 4.0.0

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