@ohos-ports/slim-select 0.0.0-stage → 4.7.0-beta.1

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.
Files changed (43) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +353 -2
  3. package/dist/animations.d.ts +37 -0
  4. package/dist/classes.d.ts +52 -0
  5. package/dist/events.d.ts +26 -0
  6. package/dist/helpers.d.ts +24 -0
  7. package/dist/index.d.ts +62 -0
  8. package/dist/index.umd.d.ts +2 -0
  9. package/dist/lifecycle.d.ts +44 -0
  10. package/dist/mutations.d.ts +33 -0
  11. package/dist/react/index.d.ts +4 -0
  12. package/dist/react/index.js +2153 -0
  13. package/dist/react/index.umd.js +1 -0
  14. package/dist/react/react.d.ts +16 -0
  15. package/dist/react/react.test.d.ts +1 -0
  16. package/dist/react/slim-select/react/index.d.ts +4 -0
  17. package/dist/render.d.ts +207 -0
  18. package/dist/select.d.ts +47 -0
  19. package/dist/settings.d.ts +46 -0
  20. package/dist/slimselect.cjs +2 -0
  21. package/dist/slimselect.cjs.js.map +1 -0
  22. package/dist/slimselect.css +1 -0
  23. package/dist/slimselect.css.map +1 -0
  24. package/dist/slimselect.es.js +2100 -0
  25. package/dist/slimselect.es.js.map +1 -0
  26. package/dist/slimselect.iife.js +2 -0
  27. package/dist/slimselect.iife.js.map +1 -0
  28. package/dist/slimselect.js +2 -0
  29. package/dist/slimselect.js.map +1 -0
  30. package/dist/src/docs/helpers.d.ts +14 -0
  31. package/dist/src/docs/main.d.ts +0 -0
  32. package/dist/src/docs/nav.d.ts +20 -0
  33. package/dist/src/docs/router.d.ts +2 -0
  34. package/dist/src/docs/store.d.ts +12 -0
  35. package/dist/store.d.ts +62 -0
  36. package/dist/sync.d.ts +88 -0
  37. package/dist/vue/helpers.d.ts +2 -0
  38. package/dist/vue/index.d.ts +4 -0
  39. package/dist/vue/index.js +2226 -0
  40. package/dist/vue/index.umd.js +1 -0
  41. package/dist/vue/slim-select/vue/index.d.ts +4 -0
  42. package/package.json +101 -4
  43. package/src/slim-select/slimselect.scss +807 -0
@@ -0,0 +1,2100 @@
1
+ // src/slim-select/classes.ts
2
+ var e = class {
3
+ main;
4
+ placeholder;
5
+ values;
6
+ single;
7
+ multiString;
8
+ max;
9
+ value;
10
+ valueText;
11
+ valueDelete;
12
+ valueOut;
13
+ deselect;
14
+ deselectPath;
15
+ arrow;
16
+ arrowClose;
17
+ arrowOpen;
18
+ content;
19
+ contentOpen;
20
+ dirAbove;
21
+ dirBelow;
22
+ search;
23
+ searchHighlighter;
24
+ searching;
25
+ status;
26
+ addable;
27
+ addablePath;
28
+ list;
29
+ optgroup;
30
+ optgroupLabel;
31
+ optgroupLabelText;
32
+ optgroupActions;
33
+ optgroupSelectAll;
34
+ optgroupSelectAllBox;
35
+ optgroupSelectAllCheck;
36
+ optgroupClosable;
37
+ option;
38
+ optionDelete;
39
+ highlighted;
40
+ modalOverlay;
41
+ modalDialog;
42
+ modalTitle;
43
+ modalClose;
44
+ modalContent;
45
+ mainOpen;
46
+ close;
47
+ selected;
48
+ error;
49
+ disabled;
50
+ hide;
51
+ constructor(e) {
52
+ e ||= {};
53
+ let t = (e = "", t = "") => `${e} ${t}`.trim();
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 || "M15,15 L85,15 L85,85 L15,85 Z", this.optgroupSelectAllCheck = e.optgroupSelectAllCheck || "M25,50 L42,68 L75,32", 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);
55
+ }
56
+ getFirst(e) {
57
+ return this[e].split(" ")[0];
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
+ // src/slim-select/settings.ts
110
+ var u = 768, d = class {
111
+ id = "";
112
+ style = "";
113
+ class = [];
114
+ isMultiple = !1;
115
+ isOpen = !1;
116
+ isFullOpen = !1;
117
+ disabled;
118
+ alwaysOpen;
119
+ showSearch;
120
+ focusSearch;
121
+ keepSearch;
122
+ ariaLabel;
123
+ searchPlaceholder;
124
+ searchText;
125
+ searchingText;
126
+ resultsText;
127
+ deselectText;
128
+ removeText;
129
+ searchHighlight;
130
+ closeOnSelect;
131
+ contentLocation;
132
+ contentPosition;
133
+ contentWidth;
134
+ openPosition;
135
+ placeholderText;
136
+ allowDeselect;
137
+ hideSelected;
138
+ multiString;
139
+ keepOrder;
140
+ showOptionTooltips;
141
+ minSelected;
142
+ maxSelected;
143
+ timeoutDelay;
144
+ maxValuesShown;
145
+ maxValuesMessage;
146
+ addableText;
147
+ selectAll;
148
+ selectAllText;
149
+ unselectAllText;
150
+ modal;
151
+ modalTitle;
152
+ constructor(e) {
153
+ e ||= {}, this.id = "ss-" + h(), this.style = e.style || "", this.class = e.class || [], this.disabled = e.disabled !== void 0 && e.disabled, this.alwaysOpen = e.alwaysOpen !== void 0 && e.alwaysOpen, this.showSearch = e.showSearch === void 0 || e.showSearch, this.focusSearch = e.focusSearch === void 0 ? typeof window > "u" || window.innerWidth >= 768 : e.focusSearch, this.keepSearch = e.keepSearch !== void 0 && 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 && e.searchHighlight, this.closeOnSelect = e.closeOnSelect === void 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 && e.allowDeselect, this.hideSelected = e.hideSelected !== void 0 && e.hideSelected, this.multiString = e.multiString !== void 0 && e.multiString, this.keepOrder = e.keepOrder !== void 0 && e.keepOrder, this.showOptionTooltips = e.showOptionTooltips !== void 0 && 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.selectAll = e.selectAll !== void 0 && e.selectAll, this.selectAllText = e.selectAllText || "Select All", this.unselectAllText = e.unselectAllText || "Unselect All", this.modal = e.modal || "mobile", this.modalTitle = e.modalTitle || "";
154
+ }
155
+ };
156
+ // src/slim-select/helpers.ts
157
+ function f(e) {
158
+ if (!e) return {};
159
+ let t = {};
160
+ for (let n of Object.keys(e)) {
161
+ let r = e[n];
162
+ r !== void 0 && (t[n] = r);
163
+ }
164
+ return t;
165
+ }
166
+ function p(e) {
167
+ let t = e.cloneNode(!0);
168
+ return t.querySelectorAll("select, option, optgroup, textarea, input, button").forEach((e) => e.remove()), t.textContent?.replace(/\s+/g, " ").trim() || "";
169
+ }
170
+ function m(e) {
171
+ if (e.labels && e.labels.length > 0) {
172
+ let t = Array.from(e.labels).map(p).filter(Boolean);
173
+ if (t.length > 0) return [...new Set(t)].join(" ");
174
+ }
175
+ return e.getAttribute("aria-label")?.trim() || "";
176
+ }
177
+ function h() {
178
+ return Math.random().toString(36).substring(2, 10);
179
+ }
180
+ function g(e, t) {
181
+ function n(e, n) {
182
+ return n && e && e.classList && e.classList.contains(n) || n && e && e.dataset && e.dataset.id && e.dataset.id === t ? e : null;
183
+ }
184
+ function r(e, t) {
185
+ return !e || e === document ? null : n(e, t) ? e : r(e.parentNode, t);
186
+ }
187
+ return n(e, t) || r(e, t);
188
+ }
189
+ function _(e, t = 50, n = !1) {
190
+ let r;
191
+ return function(...i) {
192
+ let a = self, o = () => {
193
+ r = null, n || e.apply(a, i);
194
+ }, s = n && !r;
195
+ clearTimeout(r), r = setTimeout(o, t), s && e.apply(a, i);
196
+ };
197
+ }
198
+ function v(e, t) {
199
+ if (e.length !== t.length) return !1;
200
+ let n = [...e].sort(), r = [...t].sort();
201
+ return n.every((e, t) => e === r[t]);
202
+ }
203
+ var y = [
204
+ "id",
205
+ "value",
206
+ "text",
207
+ "html",
208
+ "defaultSelected",
209
+ "selected",
210
+ "display",
211
+ "disabled",
212
+ "placeholder",
213
+ "class",
214
+ "style",
215
+ "mandatory"
216
+ ];
217
+ function b(e, t) {
218
+ let n = Object.keys(e), r = Object.keys(t);
219
+ if (n.length !== r.length) return !1;
220
+ for (let r of n) if (e[r] !== t[r]) return !1;
221
+ return !0;
222
+ }
223
+ function x(e, t) {
224
+ switch (t) {
225
+ case "id": return e.id || "";
226
+ case "value": return e.value === void 0 ? e.text || "" : e.value || "";
227
+ case "text": return e.text || "";
228
+ case "html": return e.html || "";
229
+ case "defaultSelected": return e.defaultSelected ?? !1;
230
+ case "selected": return e.selected ?? !1;
231
+ case "display": return e.display ?? !0;
232
+ case "disabled": return e.disabled ?? !1;
233
+ case "placeholder": return e.placeholder ?? !1;
234
+ case "class": return e.class || "";
235
+ case "style": return e.style || "";
236
+ case "mandatory": return e.mandatory ?? !1;
237
+ default: return e.data || {};
238
+ }
239
+ }
240
+ function S(e) {
241
+ return !!e && typeof e == "object" && "label" in e && "options" in e;
242
+ }
243
+ function C(e, t) {
244
+ for (let n of y) if (x(e, n) !== x(t, n)) return !1;
245
+ return b(e.data || {}, t.data || {});
246
+ }
247
+ function w(e, t) {
248
+ let n = (e) => ({
249
+ id: e.id || "",
250
+ label: e.label || "",
251
+ selectAll: e.selectAll ?? !1,
252
+ closable: e.closable || "off"
253
+ }), r = n(e), i = n(t);
254
+ if (r.id !== i.id || r.label !== i.label || r.selectAll !== i.selectAll || r.closable !== i.closable) return !1;
255
+ let a = e.options || [], o = t.options || [];
256
+ if (a.length !== o.length) return !1;
257
+ for (let e = 0; e < a.length; e++) if (!C(a[e], o[e])) return !1;
258
+ return !0;
259
+ }
260
+ function T(e, t) {
261
+ if (e === t) return !0;
262
+ if (e.length !== t.length) return !1;
263
+ for (let n = 0; n < e.length; n++) {
264
+ let r = e[n], i = t[n], a = S(r);
265
+ if (a !== S(i)) return !1;
266
+ if (a) {
267
+ if (!w(r, i)) return !1;
268
+ } else if (!C(r, i)) return !1;
269
+ }
270
+ return !0;
271
+ }
272
+ function E(e) {
273
+ let t = e.replace(/[A-Z\u00C0-\u00D6\u00D8-\u00DE]/g, (e) => "-" + e.toLowerCase());
274
+ return e[0] === e[0].toUpperCase() ? t.substring(1) : t;
275
+ }
276
+ function D(e, t = typeof window < "u" ? window.innerWidth : 768) {
277
+ return e === "on" || e === "mobile" && t < 768;
278
+ }
279
+ // src/slim-select/events.ts
280
+ var O = class {
281
+ handlers;
282
+ attached = !1;
283
+ constructor(e) {
284
+ this.handlers = e;
285
+ }
286
+ attach(e) {
287
+ this.attached || (this.attached = !0, window.addEventListener("resize", this.resizeHandler, !1), e.listenScroll && window.addEventListener("scroll", this.scrollHandler, !1), document.addEventListener("visibilitychange", this.visibilityHandler));
288
+ }
289
+ attachDocumentClick() {
290
+ document.addEventListener("click", this.handlers.onDocumentClick);
291
+ }
292
+ detachDocumentClick() {
293
+ document.removeEventListener("click", this.handlers.onDocumentClick);
294
+ }
295
+ detach(e) {
296
+ 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));
297
+ }
298
+ resizeHandler = _(() => {
299
+ this.handlers.onWindowResize();
300
+ });
301
+ scrollHandler = _(() => {
302
+ this.handlers.onWindowScroll();
303
+ });
304
+ visibilityHandler = () => {
305
+ this.handlers.onVisibilityChange();
306
+ };
307
+ }, k = class {
308
+ handlers;
309
+ options;
310
+ state = "closed";
311
+ pendingTimer = null;
312
+ waitResolvers = [];
313
+ generation = 0;
314
+ animationAbort = null;
315
+ constructor(e, t) {
316
+ this.handlers = e, this.options = t;
317
+ }
318
+ get isOpen() {
319
+ return this.state === "opening" || this.state === "open";
320
+ }
321
+ get isFullOpen() {
322
+ return this.state === "open";
323
+ }
324
+ async requestOpen() {
325
+ if (this.state === "opening" || this.state === "open") return;
326
+ this.cancelPending();
327
+ let e = ++this.generation;
328
+ this.handlers.beforeOpen && this.handlers.beforeOpen(), this.state = "opening", await this.waitForPhase("open", e), e === this.generation ? (this.state = "open", this.handlers.afterOpen && this.handlers.afterOpen(), this.handlers.onOpenReady && this.handlers.onOpenReady()) : this.state === "opening" && (this.state = "closed");
329
+ }
330
+ async requestClose(e = {
331
+ source: "api",
332
+ selectionChanged: !1
333
+ }) {
334
+ if (this.state === "closed" || this.state === "closing" || this.handlers.beforeClose && this.handlers.beforeClose(e) === !1) return !1;
335
+ this.cancelPending();
336
+ let t = ++this.generation;
337
+ return this.handlers.onClose && this.handlers.onClose(e), this.state = "closing", await this.waitForPhase("close", t), t === this.generation && (this.state = "closed", this.handlers.afterClose && this.handlers.afterClose(), this.handlers.onCloseReady && this.handlers.onCloseReady(), !0);
338
+ }
339
+ cancelPending() {
340
+ this.generation++, this.animationAbort?.abort(), this.animationAbort = null, this.pendingTimer &&= (clearTimeout(this.pendingTimer), null);
341
+ let e = this.waitResolvers.splice(0);
342
+ for (let t of e) t();
343
+ }
344
+ destroy() {
345
+ this.cancelPending(), this.state = "closed";
346
+ }
347
+ waitForPhase(e, t) {
348
+ return new Promise((t) => {
349
+ let n = !1, r = () => {
350
+ if (n) return;
351
+ n = !0;
352
+ let e = this.waitResolvers.indexOf(r);
353
+ e !== -1 && this.waitResolvers.splice(e, 1), t();
354
+ };
355
+ if (this.waitResolvers.push(r), this.options.waitForAnimation) {
356
+ let t = new AbortController();
357
+ this.animationAbort = t, this.options.waitForAnimation(e, t.signal).catch(() => void 0).finally(() => {
358
+ this.animationAbort === t && (this.animationAbort = null), r();
359
+ });
360
+ } else this.pendingTimer = setTimeout(() => {
361
+ this.pendingTimer = null, r();
362
+ }, this.options.timeoutDelay);
363
+ }).then(() => {
364
+ this.generation;
365
+ });
366
+ }
367
+ }, A = class {
368
+ id;
369
+ value;
370
+ text;
371
+ html;
372
+ defaultSelected;
373
+ selected;
374
+ display;
375
+ disabled;
376
+ placeholder;
377
+ class;
378
+ style;
379
+ data;
380
+ mandatory;
381
+ constructor(e) {
382
+ 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 && e.defaultSelected, this.selected = e.selected !== void 0 && e.selected, this.display = e.display === void 0 || e.display, this.disabled = e.disabled !== void 0 && e.disabled, this.mandatory = e.mandatory !== void 0 && e.mandatory, this.placeholder = e.placeholder !== void 0 && e.placeholder, this.class = e.class || "", this.style = e.style || "", this.data = f(e.data);
383
+ }
384
+ }, j = class {
385
+ id;
386
+ label;
387
+ selectAll;
388
+ closable;
389
+ options;
390
+ constructor(e) {
391
+ if (this.id = !e.id || e.id === "" ? h() : e.id, this.label = e.label || "", this.selectAll = e.selectAll !== void 0 && e.selectAll, this.closable = e.closable || "off", this.options = [], e.options) for (let t of e.options) this.options.push(new A(t));
392
+ }
393
+ }, M = class {
394
+ selectType = "single";
395
+ data = [];
396
+ selectedOrder = [];
397
+ catalog = null;
398
+ constructor(e, t) {
399
+ this.selectType = e, this.setData(t), this.snapshotCatalog();
400
+ }
401
+ validateDataArray(e) {
402
+ if (!Array.isArray(e)) return /* @__PURE__ */ Error("Data must be an array");
403
+ for (let t of e) if (t) {
404
+ if (t instanceof j || "label" in t) {
405
+ if (!("label" in t)) return /* @__PURE__ */ Error("Optgroup must have a label");
406
+ if ("options" in t && t.options) for (let e of t.options) {
407
+ let t = this.validateOption(e);
408
+ if (t) return t;
409
+ }
410
+ } else if (t instanceof A || "text" in t) {
411
+ let e = this.validateOption(t);
412
+ if (e) return e;
413
+ } else return /* @__PURE__ */ Error("Data object must be a valid optgroup or option");
414
+ }
415
+ return null;
416
+ }
417
+ validateOption(e) {
418
+ return "text" in e ? null : /* @__PURE__ */ Error("Option must have a text");
419
+ }
420
+ partialToFullData(e) {
421
+ let t = [];
422
+ return e.forEach((e) => {
423
+ if (e) {
424
+ if (e instanceof j || "label" in e) {
425
+ let n = [];
426
+ "options" in e && e.options && e.options.forEach((e) => {
427
+ n.push(new A(e));
428
+ }), n.length > 0 && t.push(new j(e));
429
+ }
430
+ (e instanceof A || "text" in e) && t.push(new A(e));
431
+ }
432
+ }), t;
433
+ }
434
+ snapshotCatalog() {
435
+ this.catalog = this.cloneData(this.data);
436
+ }
437
+ getCatalogData() {
438
+ return this.cloneData(this.catalog ?? this.data);
439
+ }
440
+ cloneData(e) {
441
+ return e.map((e) => e instanceof j ? new j({
442
+ id: e.id,
443
+ label: e.label,
444
+ selectAll: e.selectAll,
445
+ closable: e.closable,
446
+ options: e.options.map((e) => new A(e instanceof A ? { ...e } : e))
447
+ }) : new A({ ...e }));
448
+ }
449
+ optionMatchesSelected(e, t) {
450
+ return e.id === t.id || t.value !== "" && e.value !== "" && e.value === t.value;
451
+ }
452
+ findOptionInData(e, t) {
453
+ for (let n of e) if (n instanceof A) {
454
+ if (this.optionMatchesSelected(n, t)) return n;
455
+ } else for (let e of n.options) if (this.optionMatchesSelected(e, t)) return e;
456
+ return null;
457
+ }
458
+ setData(e, t = !1) {
459
+ let n = this.partialToFullData(e), r = [];
460
+ if (t) {
461
+ r = this.getSelectedOptions();
462
+ let e = [];
463
+ r.forEach((t) => {
464
+ this.findOptionInData(n, t) || e.push(t);
465
+ }), this.data = [...e, ...n];
466
+ let t = this.selectType === "single" && r.length === 0, i = r.map((e) => {
467
+ let t = this.findOptionInData(this.data, e);
468
+ return t ? t.id : e.id;
469
+ });
470
+ this.setSelectedBy("id", i, t);
471
+ } else this.data = n;
472
+ !t && this.selectType === "single" && this.setSelectedBy("id", this.getSelected(), !1);
473
+ }
474
+ getData(e = !0) {
475
+ return this.filter(null, !0, e);
476
+ }
477
+ getDataOptions(e = !0) {
478
+ return this.filter(null, !1, e);
479
+ }
480
+ addOption(e, t = !1) {
481
+ if (t) {
482
+ let t = [new A(e)];
483
+ this.setData(t.concat(this.getData()));
484
+ } else this.setData(this.getData().concat(new A(e)));
485
+ }
486
+ setSelectedBy(e, t, n = !1) {
487
+ let r = null, i = !1, a = [];
488
+ for (let n of this.data) {
489
+ if (n instanceof j) for (let o of n.options) {
490
+ r ||= o;
491
+ let n = o[e] || "";
492
+ o.selected = !i && t.includes(n), o.selected && (a.push(o), this.selectType === "single" && (i = !0));
493
+ }
494
+ n instanceof A && (r ||= n, n.selected = !i && t.includes(n[e]), n.selected && (a.push(n), this.selectType === "single" && (i = !0)));
495
+ }
496
+ this.selectType === "single" && r && !i && !n && (r.selected = !0, a.push(r));
497
+ let o = t.map((t) => a.find((n) => n[e] === t)?.id || "");
498
+ this.selectedOrder = o;
499
+ }
500
+ getSelected() {
501
+ return this.getSelectedOptions().map((e) => e.id);
502
+ }
503
+ getSelectedValues() {
504
+ return this.getSelectedOptions().map((e) => e.value);
505
+ }
506
+ getSelectedOptions() {
507
+ let e = [];
508
+ for (let t of this.data) if (t instanceof j) for (let n of t.options) n.selected && e.push(n);
509
+ else t.selected && e.push(t);
510
+ return e;
511
+ }
512
+ getOptgroupByID(e) {
513
+ for (let t of this.data) if (t instanceof j && t.id === e) return t;
514
+ return null;
515
+ }
516
+ getOptionByID(e) {
517
+ for (let t of this.data) if (t instanceof j) {
518
+ for (let n of t.options) if (n.id === e) return n;
519
+ } else if (t.id === e) return t;
520
+ return null;
521
+ }
522
+ getSelectType() {
523
+ return this.selectType;
524
+ }
525
+ getFirstOption() {
526
+ let e = null;
527
+ for (let t of this.data) if (t instanceof j ? e = t.options[0] : t instanceof A && (e = t), e) break;
528
+ return e;
529
+ }
530
+ search(e, t) {
531
+ return e = e.trim(), e === "" ? this.getData(!1) : this.filter((n) => t(n, e), !0, !1);
532
+ }
533
+ createOptgroupView(e, t) {
534
+ let n = new j({
535
+ id: e.id,
536
+ label: e.label,
537
+ selectAll: e.selectAll,
538
+ closable: e.closable,
539
+ options: []
540
+ });
541
+ return n.options = t, n;
542
+ }
543
+ filter(e, t, n = !0) {
544
+ let r = [];
545
+ return this.data.forEach((i) => {
546
+ if (i instanceof j) {
547
+ let a = [];
548
+ if (i.options.forEach((i) => {
549
+ (!e || e(i)) && (t ? a.push(n ? new A(i) : i) : r.push(n ? new A(i) : i));
550
+ }), a.length > 0) {
551
+ if (n) {
552
+ let e = new j(i);
553
+ e.options = a, r.push(e);
554
+ } else r.push(this.createOptgroupView(i, a));
555
+ }
556
+ }
557
+ i instanceof A && (!e || e(i)) && r.push(n ? new A(i) : i);
558
+ }), r;
559
+ }
560
+ selectedOrderOptions(e) {
561
+ let t = [];
562
+ return this.selectedOrder.forEach((n) => {
563
+ let r = e.find((e) => e.id === n);
564
+ r && t.push(r);
565
+ }), e.forEach((e) => {
566
+ let n = !1;
567
+ t.forEach((t) => {
568
+ e.id === t.id && (n = !0);
569
+ }), n || t.push(e);
570
+ }), t;
571
+ }
572
+ }, N = 1e3, P = class {
573
+ settings;
574
+ store;
575
+ callbacks;
576
+ lastSelectedOption;
577
+ lastRenderedOptions;
578
+ optionsListIsFullData = !1;
579
+ lastSearchFilterTerm = "";
580
+ main;
581
+ content;
582
+ classes;
583
+ positionObserver = null;
584
+ positionObserverRaf = 0;
585
+ lastObservedContentHeight = -1;
586
+ overflowShiftRaf = 0;
587
+ typeaheadQuery = "";
588
+ typeaheadTimer = null;
589
+ modalElements = null;
590
+ modalSessionActive = null;
591
+ bodyScrollLocked = !1;
592
+ savedBodyOverflow = "";
593
+ constructor(e, t, n, r) {
594
+ 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));
595
+ }
596
+ requestClose(e, t) {
597
+ this.callbacks.close({
598
+ source: e,
599
+ option: t?.option,
600
+ selectionChanged: t?.selectionChanged ?? !1
601
+ });
602
+ }
603
+ selectionChanged(e, t) {
604
+ if (e.length !== t.length) return !0;
605
+ let n = e.map((e) => e.id).sort(), r = t.map((e) => e.id).sort();
606
+ return n.some((e, t) => e !== r[t]);
607
+ }
608
+ closeOnSingleSelectReclick(e) {
609
+ this.settings.closeOnSelect && this.requestClose("select", {
610
+ option: e,
611
+ selectionChanged: !1
612
+ });
613
+ }
614
+ addClasses(e, t) {
615
+ if (!t || t.trim() === "") return;
616
+ let n = t.split(" ").filter((e) => e.trim() !== "");
617
+ for (let t of n) e.classList.add(t.trim());
618
+ }
619
+ removeClasses(e, t) {
620
+ if (!t || t.trim() === "") return;
621
+ let n = t.split(" ").filter((e) => e.trim() !== "");
622
+ for (let t of n) e.classList.remove(t.trim());
623
+ }
624
+ enable() {
625
+ this.removeClasses(this.main.main, this.classes.disabled), this.main.main.setAttribute("aria-disabled", "false"), this.content.search.input.disabled = !1;
626
+ }
627
+ disable() {
628
+ this.addClasses(this.main.main, this.classes.disabled), this.main.main.setAttribute("aria-disabled", "true"), this.content.search.input.disabled = !0;
629
+ }
630
+ open() {
631
+ this.main.arrow.path.setAttribute("d", this.classes.arrowOpen), this.main.main.setAttribute("aria-expanded", "true");
632
+ let e = this.resolveModalView();
633
+ if (!e) {
634
+ let e = this.settings.openPosition === "up" ? this.classes.dirAbove : this.classes.dirBelow;
635
+ this.addClasses(this.main.main, e), this.addClasses(this.content.main, e);
636
+ }
637
+ this.addClasses(this.content.main, this.classes.contentOpen), this.content.search.input.removeAttribute("aria-hidden"), e ? this.showModal() : this.moveContent();
638
+ let t = this.store.getSelectedOptions();
639
+ if (t.length) {
640
+ let e = t[t.length - 1].id, n = this.content.list.querySelector("[data-id=\"" + e + "\"]");
641
+ n && this.ensureElementInView(this.content.list, n);
642
+ }
643
+ }
644
+ isModalViewActive() {
645
+ return this.modalSessionActive === !0;
646
+ }
647
+ resolveModalView() {
648
+ return this.settings.alwaysOpen || this.settings.modal === "off" || !this.modalElements ? !1 : (this.modalSessionActive === null && (this.modalSessionActive = D(this.settings.modal)), this.modalSessionActive);
649
+ }
650
+ createModalElements() {
651
+ let e = document.createElement("div");
652
+ this.addClasses(e, this.classes.modalOverlay), this.addClasses(e, this.classes.hide), e.dataset.id = this.settings.id;
653
+ let t = document.createElement("div");
654
+ this.addClasses(t, this.classes.modalDialog), t.setAttribute("role", "dialog"), t.setAttribute("aria-modal", "true");
655
+ let n = null;
656
+ 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);
657
+ let r = document.createElement("button");
658
+ r.type = "button", this.addClasses(r, this.classes.modalClose), r.setAttribute("aria-label", "Close"), r.onclick = (e) => {
659
+ e.stopPropagation(), this.requestClose("modal");
660
+ };
661
+ let i = document.createElementNS("http://www.w3.org/2000/svg", "svg");
662
+ i.setAttribute("viewBox", "0 0 100 100");
663
+ let a = document.createElementNS("http://www.w3.org/2000/svg", "path");
664
+ return a.setAttribute("d", this.classes.deselectPath), i.appendChild(a), r.appendChild(i), e.onclick = (t) => {
665
+ t.target === e && this.requestClose("modal");
666
+ }, n && t.appendChild(n), e.appendChild(t), {
667
+ overlay: e,
668
+ dialog: t,
669
+ closeButton: r,
670
+ title: n
671
+ };
672
+ }
673
+ showModal() {
674
+ 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(() => {
675
+ this.modalElements && this.addClasses(this.modalElements.overlay, this.classes.contentOpen);
676
+ }), this.lockBodyScroll());
677
+ }
678
+ lockBodyScroll() {
679
+ this.bodyScrollLocked ||= (this.savedBodyOverflow = document.body.style.overflow, document.body.style.overflow = "hidden", !0);
680
+ }
681
+ unlockBodyScroll() {
682
+ this.bodyScrollLocked && (document.body.style.overflow = this.savedBodyOverflow, this.bodyScrollLocked = !1, this.savedBodyOverflow = "");
683
+ }
684
+ restoreContentOffscreen() {
685
+ 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");
686
+ }
687
+ finalizeModalClose() {
688
+ 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.modalElements.closeButton.remove(), this.restoreContentOffscreen(), this.unlockBodyScroll());
689
+ }
690
+ waitForAnimation(e, t) {
691
+ let r = a(this.content.main, this.settings.timeoutDelay);
692
+ return c(this.content.main, n, r, t);
693
+ }
694
+ close() {
695
+ this.main.main.setAttribute("aria-expanded", "false"), this.main.arrow.path.setAttribute("d", this.classes.arrowClose);
696
+ let e = this.modalSessionActive === !0;
697
+ 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"), this.clearValueChipHighlight();
698
+ }
699
+ clearDirectionClasses() {
700
+ 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);
701
+ }
702
+ updateClassStyles() {
703
+ 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()));
704
+ (this.settings.contentPosition === "relative" || this.settings.contentPosition === "fixed") && this.content.main.classList.add("ss-" + this.settings.contentPosition);
705
+ }
706
+ updateTitle(e) {
707
+ e ? this.main.main.setAttribute("title", e) : this.main.main.removeAttribute("title");
708
+ }
709
+ updateAriaAttributes() {
710
+ let e = this.content.list.id;
711
+ this.main.main.role = "combobox", this.main.main.setAttribute("aria-haspopup", "listbox"), this.main.main.setAttribute("aria-controls", e), this.main.main.setAttribute("aria-expanded", "false"), this.content.list.setAttribute("role", "listbox"), this.content.list.setAttribute("aria-label", this.settings.ariaLabel + " listbox"), this.settings.isMultiple && this.content.list.setAttribute("aria-multiselectable", "true"), this.content.search.input.setAttribute("aria-controls", e);
712
+ }
713
+ mainDiv() {
714
+ let e = document.createElement("div");
715
+ e.dataset.id = this.settings.id, e.setAttribute("aria-label", this.settings.ariaLabel), e.tabIndex = 0, e.onkeydown = (e) => {
716
+ if (this.isTypeaheadKey(e)) return e.preventDefault(), this.callbacks.open(), this.typeahead(e.key), !1;
717
+ switch (e.key) {
718
+ case "ArrowUp":
719
+ case "ArrowDown": return this.clearTypeahead(), this.callbacks.open(), e.key === "ArrowDown" ? this.highlight("down") : this.highlight("up"), !1;
720
+ case "Tab": return this.clearTypeahead(), this.requestClose("tab"), !0;
721
+ case "Enter":
722
+ case " ":
723
+ this.clearTypeahead(), this.callbacks.open();
724
+ let t = this.content.list.querySelector("." + this.classes.getFirst("highlighted"));
725
+ return t && t.click(), !1;
726
+ case "Escape": return this.clearTypeahead(), this.requestClose("escape"), !1;
727
+ }
728
+ return e.key.length === 1 && this.callbacks.open(), !0;
729
+ }, e.onclick = (e) => {
730
+ this.settings.disabled || (this.settings.isOpen ? this.requestClose("toggle") : this.callbacks.open());
731
+ };
732
+ let t = document.createElement("div");
733
+ this.addClasses(t, this.classes.values), e.appendChild(t);
734
+ let n = document.createElement("div");
735
+ this.addClasses(n, this.classes.deselect), n.setAttribute("role", "button"), n.setAttribute("aria-label", this.settings.deselectText), n.setAttribute("tabindex", "0");
736
+ let r = this.store?.getSelectedOptions();
737
+ !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) => {
738
+ if (e.stopPropagation(), this.settings.disabled || this.settings.isMultiple && this.isAtMinSelected()) return;
739
+ let t = !0, n = this.store.getSelectedOptions(), r = [], i = "";
740
+ if (this.settings.isMultiple) {
741
+ let e = this.settings.minSelected, t = this.store.getSelected();
742
+ if (e > 0 && t.length > e) i = this.getMinimumSelectionIds(), r = n.filter((e) => i.includes(e.id));
743
+ else if (e <= 0) i = [];
744
+ else return;
745
+ }
746
+ if (this.callbacks.beforeChange && (t = this.callbacks.beforeChange(r, n) === !0), t) {
747
+ if (this.settings.isMultiple) this.callbacks.setSelected(i, !1), this.updateDeselectAll();
748
+ else {
749
+ let e = this.store.getFirstOption(), t = e ? e.id : "";
750
+ this.callbacks.setSelected(t, !1);
751
+ }
752
+ this.settings.closeOnSelect && this.requestClose("deselect", { selectionChanged: !0 }), this.callbacks.afterChange && this.callbacks.afterChange(this.store.getSelectedOptions());
753
+ }
754
+ }, n.onkeydown = (e) => {
755
+ (e.key === "Enter" || e.key === " ") && (e.preventDefault(), n.click());
756
+ };
757
+ let i = document.createElementNS("http://www.w3.org/2000/svg", "svg");
758
+ i.setAttribute("viewBox", "0 0 100 100");
759
+ let a = document.createElementNS("http://www.w3.org/2000/svg", "path");
760
+ a.setAttribute("d", this.classes.deselectPath), i.appendChild(a), n.appendChild(i), e.appendChild(n);
761
+ let o = document.createElementNS("http://www.w3.org/2000/svg", "svg");
762
+ this.addClasses(o, this.classes.arrow), o.setAttribute("viewBox", "0 0 100 100");
763
+ let s = document.createElementNS("http://www.w3.org/2000/svg", "path");
764
+ return s.setAttribute("d", this.classes.arrowClose), this.settings.alwaysOpen && this.addClasses(o, this.classes.hide), o.appendChild(s), e.appendChild(o), {
765
+ main: e,
766
+ values: t,
767
+ deselect: {
768
+ main: n,
769
+ svg: i,
770
+ path: a
771
+ },
772
+ arrow: {
773
+ main: o,
774
+ path: s
775
+ }
776
+ };
777
+ }
778
+ mainFocus(e) {
779
+ e !== "click" && this.main.main.focus({ preventScroll: !0 });
780
+ }
781
+ placeholder() {
782
+ let e = this.store.filter((e) => e.placeholder, !1, !1), t = this.settings.placeholderText;
783
+ e.length && (e[0].html === "" ? e[0].text !== "" && (t = e[0].text) : t = e[0].html);
784
+ let n = document.createElement("div");
785
+ return this.addClasses(n, this.classes.placeholder), n.innerHTML = t, n;
786
+ }
787
+ renderValues() {
788
+ this.settings.isMultiple ? (this.renderMultipleValues(), this.updateDeselectAll()) : this.renderSingleValue();
789
+ }
790
+ renderSingleValue() {
791
+ let e = this.store.filter((e) => e.selected && !e.placeholder, !1, !1), t = e.length > 0 ? e[0] : null;
792
+ if (!t) this.main.values.innerHTML = this.placeholder().outerHTML;
793
+ else {
794
+ let e = document.createElement("div");
795
+ this.addClasses(e, this.classes.single), t.html ? e.innerHTML = t.html : e.innerText = t.text, this.main.values.innerHTML = e.outerHTML;
796
+ }
797
+ !this.settings.allowDeselect || !e.length ? this.addClasses(this.main.deselect.main, this.classes.hide) : this.removeClasses(this.main.deselect.main, this.classes.hide);
798
+ }
799
+ renderMultipleValues() {
800
+ let e = this.main.values.childNodes, t = this.store.filter((e) => e.selected && e.display, !1, !1);
801
+ if (t.length === 0) {
802
+ this.main.values.innerHTML = this.placeholder().outerHTML;
803
+ return;
804
+ }
805
+ {
806
+ let e = this.main.values.querySelector("." + this.classes.getFirst("placeholder"));
807
+ e && e.remove();
808
+ }
809
+ if (this.settings.multiString) {
810
+ let e = t;
811
+ this.settings.keepOrder && (e = this.store.selectedOrderOptions(e));
812
+ let n = document.createElement("div");
813
+ this.addClasses(n, this.classes.multiString), n.textContent = e.map((e) => e.text).join(", "), this.settings.showOptionTooltips && n.setAttribute("title", n.textContent), this.main.values.innerHTML = n.outerHTML;
814
+ return;
815
+ }
816
+ if (t.length > this.settings.maxValuesShown) {
817
+ let e = document.createElement("div");
818
+ this.addClasses(e, this.classes.max), e.textContent = this.settings.maxValuesMessage.replace("{number}", t.length.toString()), this.main.values.innerHTML = e.outerHTML;
819
+ return;
820
+ }
821
+ {
822
+ let e = this.main.values.querySelector("." + this.classes.getFirst("max"));
823
+ e && e.remove();
824
+ }
825
+ this.settings.keepOrder && (t = this.store.selectedOrderOptions(t));
826
+ let n = [];
827
+ for (let r = 0; r < e.length; r++) {
828
+ let i = e[r], a = i.getAttribute("data-id");
829
+ a && (t.filter((e) => e.id === a, !1).length || n.push(i));
830
+ }
831
+ let r = a(this.content.main, this.settings.timeoutDelay);
832
+ for (let e of n) this.addClasses(e, this.classes.valueOut), l(e, "ss-valueOut", r).then(() => {
833
+ this.main.values.hasChildNodes() && this.main.values.contains(e) && this.main.values.removeChild(e);
834
+ });
835
+ e = this.main.values.childNodes;
836
+ for (let n = 0; n < t.length; n++) {
837
+ let r = !0;
838
+ for (let i = 0; i < e.length; i++) t[n].id === String(e[i].dataset.id) && (r = !1);
839
+ 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])));
840
+ }
841
+ this.updateMultipleValueDeleteVisibility();
842
+ }
843
+ isAtMinSelected() {
844
+ return this.settings.isMultiple && this.settings.minSelected > 0 && this.store.getSelectedOptions().length <= this.settings.minSelected;
845
+ }
846
+ getMinimumSelectionIds() {
847
+ let e = this.store.getSelectedOptions();
848
+ return this.settings.keepOrder && (e = this.store.selectedOrderOptions(e)), e.slice(0, this.settings.minSelected).map((e) => e.id);
849
+ }
850
+ getValueChips() {
851
+ return !this.settings.isMultiple || this.settings.multiString ? [] : Array.from(this.main.values.querySelectorAll("." + this.classes.getFirst("value"))).filter((e) => {
852
+ if (e.classList.contains(this.classes.getFirst("valueOut"))) return !1;
853
+ let t = e.querySelector("." + this.classes.getFirst("valueDelete"));
854
+ return !!t && !t.classList.contains(this.classes.getFirst("hide"));
855
+ });
856
+ }
857
+ getHighlightedValueChip() {
858
+ return this.getValueChips().find((e) => e.classList.contains(this.classes.getFirst("highlighted"))) ?? null;
859
+ }
860
+ clearValueChipHighlight() {
861
+ for (let e of Array.from(this.main.values.querySelectorAll("." + this.classes.getFirst("value")))) this.removeClasses(e, this.classes.highlighted);
862
+ }
863
+ highlightValueChip(e) {
864
+ this.clearValueChipHighlight(), e && this.addClasses(e, this.classes.highlighted);
865
+ }
866
+ navigateValueChips(e) {
867
+ let t = this.getValueChips();
868
+ if (t.length === 0) return !1;
869
+ let n = this.getHighlightedValueChip(), r = n ? t.indexOf(n) : -1;
870
+ return e === "left" ? (r === -1 ? this.highlightValueChip(t[t.length - 1]) : r > 0 && this.highlightValueChip(t[r - 1]), !0) : r !== -1 && (r < t.length - 1 ? this.highlightValueChip(t[r + 1]) : this.clearValueChipHighlight(), !0);
871
+ }
872
+ deleteValueChip() {
873
+ let e = this.getValueChips(), t = this.getHighlightedValueChip();
874
+ if (!t) return !1;
875
+ let n = t.querySelector("." + this.classes.getFirst("valueDelete"));
876
+ if (!n) return !1;
877
+ let r = e.indexOf(t), i = e[r - 1] ?? e[r + 1] ?? null;
878
+ return n.click(), i && i !== t && this.main.values.contains(i) ? this.highlightValueChip(i) : this.clearValueChipHighlight(), !0;
879
+ }
880
+ updateMultipleValueDeleteVisibility() {
881
+ if (!this.settings.isMultiple || this.settings.multiString) return;
882
+ let e = !this.isAtMinSelected(), t = this.main.values.querySelectorAll("." + this.classes.getFirst("valueDelete"));
883
+ for (let n of t) e ? this.removeClasses(n, this.classes.hide) : this.addClasses(n, this.classes.hide);
884
+ }
885
+ multipleValue(e) {
886
+ let t = document.createElement("div");
887
+ this.addClasses(t, this.classes.value), t.dataset.id = e.id;
888
+ let n = document.createElement("div");
889
+ if (this.addClasses(n, this.classes.valueText), n.textContent = e.text, t.appendChild(n), !e.mandatory) {
890
+ let n = document.createElement("div");
891
+ 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) => {
892
+ if (t.preventDefault(), t.stopPropagation(), this.settings.disabled) return;
893
+ let n = !0, r = this.store.getSelectedOptions(), i = r.filter((t) => t.selected && t.id !== e.id, !0);
894
+ if (!(this.settings.minSelected && i.length < this.settings.minSelected) && (this.callbacks.beforeChange && (n = this.callbacks.beforeChange(i, r) === !0), n)) {
895
+ let e = [];
896
+ for (let t of i) {
897
+ if (t instanceof j) for (let n of t.options) n.id && e.push(n.id);
898
+ t instanceof A && e.push(t.id);
899
+ }
900
+ this.callbacks.setSelected(e, !1), this.settings.closeOnSelect && this.requestClose("deselect", { selectionChanged: !0 }), this.callbacks.afterChange && this.callbacks.afterChange(i), this.updateDeselectAll(), this.updateMultipleValueDeleteVisibility();
901
+ }
902
+ };
903
+ let r = document.createElementNS("http://www.w3.org/2000/svg", "svg");
904
+ r.setAttribute("viewBox", "0 0 100 100");
905
+ let i = document.createElementNS("http://www.w3.org/2000/svg", "path");
906
+ i.setAttribute("d", this.classes.optionDelete), r.appendChild(i), n.appendChild(r), t.appendChild(n), n.onkeydown = (e) => {
907
+ e.key === "Enter" && n.click();
908
+ };
909
+ }
910
+ return t;
911
+ }
912
+ contentDiv() {
913
+ let e = document.createElement("div");
914
+ e.dataset.id = this.settings.id;
915
+ let t = this.searchDiv();
916
+ e.appendChild(t.main);
917
+ let n = document.createElement("div");
918
+ this.addClasses(n, this.classes.status), n.setAttribute("aria-live", "polite"), n.setAttribute("aria-atomic", "true"), n.setAttribute("role", "status"), e.appendChild(n);
919
+ let r = this.listDiv();
920
+ return e.appendChild(r), {
921
+ main: e,
922
+ search: t,
923
+ status: n,
924
+ list: r
925
+ };
926
+ }
927
+ announce(e) {
928
+ this.settings.showSearch && (this.content.status.textContent = e);
929
+ }
930
+ repositionOpenContent() {
931
+ this.settings.isOpen && !this.isModalViewActive() && this.settings.contentPosition !== "relative" && this.content.main.classList.contains(this.classes.getFirst("dirAbove")) && this.moveContentAbove();
932
+ }
933
+ moveContent() {
934
+ this.isModalViewActive() || (this.settings.contentPosition === "relative" || this.settings.openPosition === "down" ? this.moveContentBelow() : this.settings.openPosition === "up" || this.putContent() === "up" ? this.moveContentAbove() : this.moveContentBelow());
935
+ }
936
+ startPositionTracking() {
937
+ this.settings.contentPosition !== "absolute" || this.isModalViewActive() || (this.stopPositionTracking(), typeof ResizeObserver < "u" && (this.lastObservedContentHeight = -1, this.positionObserver = new ResizeObserver((e) => {
938
+ if (!this.settings.isOpen) return;
939
+ let t = !1, n = !1;
940
+ for (let r of e) if (r.target === this.content.main) {
941
+ let e = r.contentRect.height;
942
+ e !== this.lastObservedContentHeight && (this.lastObservedContentHeight = e, t = !0);
943
+ } else n = !0;
944
+ (t || n) && (cancelAnimationFrame(this.positionObserverRaf), this.positionObserverRaf = requestAnimationFrame(() => {
945
+ n ? this.moveContent() : this.repositionOpenContent();
946
+ }));
947
+ }), this.observePositionTargets()));
948
+ }
949
+ stopPositionTracking() {
950
+ cancelAnimationFrame(this.positionObserverRaf), this.positionObserver?.disconnect(), this.positionObserver = null, this.lastObservedContentHeight = -1, this.cancelOverflowShift();
951
+ }
952
+ observePositionTargets() {
953
+ if (!this.positionObserver) return;
954
+ let e = /* @__PURE__ */ new Set(), t = (t) => {
955
+ t && !e.has(t) && (e.add(t), this.positionObserver.observe(t));
956
+ };
957
+ t(this.main.main), t(this.content.main);
958
+ let n = this.main.main.parentElement, r = this.settings.contentLocation;
959
+ for (let e = 0; n && e < 8 && (t(n), n !== r); e++) n = n.parentElement;
960
+ }
961
+ searchDiv() {
962
+ let e = document.createElement("div"), t = document.createElement("input"), n = document.createElement("div");
963
+ this.addClasses(e, this.classes.search);
964
+ let r = {
965
+ main: e,
966
+ input: t
967
+ }, a = this.settings.selectAll && this.settings.isMultiple;
968
+ this.settings.showSearch || (t.readOnly = !0, a ? this.addClasses(t, this.classes.hide) : this.addClasses(e, this.classes.hide)), t.type = "search", t.id = `${this.settings.id}-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");
969
+ let o = _(() => {
970
+ this.callbacks.search(t.value);
971
+ }, 100);
972
+ if (t.oninput = (e) => {
973
+ e.target.value !== "" && this.clearValueChipHighlight(), o();
974
+ }, t.onkeydown = (e) => {
975
+ switch (e.key) {
976
+ case "ArrowUp":
977
+ case "ArrowDown": return this.clearValueChipHighlight(), e.key === "ArrowDown" ? this.highlight("down") : this.highlight("up"), !1;
978
+ case "ArrowLeft":
979
+ case "ArrowRight": return t.value !== "" || !this.navigateValueChips(e.key === "ArrowLeft" ? "left" : "right") || (e.preventDefault(), !1);
980
+ case "Backspace": return t.value === "" ? this.getHighlightedValueChip() ? !this.deleteValueChip() || (e.preventDefault(), !1) : !this.navigateValueChips("left") || (e.preventDefault(), !1) : !0;
981
+ case "Delete": return t.value !== "" || !this.deleteValueChip() || (e.preventDefault(), !1);
982
+ case "Tab": return this.requestClose("tab"), !0;
983
+ case "Escape": return this.requestClose("escape"), !1;
984
+ case "Enter":
985
+ let r = this.content.list.querySelector("." + this.classes.getFirst("highlighted"));
986
+ return r ? (r.click(), !1) : !this.callbacks.addable || (n.click(), !1);
987
+ }
988
+ return e.key.length === 1 && this.clearValueChipHighlight(), !0;
989
+ }, e.appendChild(t), a) {
990
+ let t = this.createSelectAllControl(() => this.toggleGlobalSelectAll());
991
+ e.appendChild(t), r.selectAll = t;
992
+ }
993
+ if (this.callbacks.addable) {
994
+ this.addClasses(n, this.classes.addable);
995
+ let t = document.createElementNS("http://www.w3.org/2000/svg", "svg");
996
+ t.setAttribute("viewBox", "0 0 100 100");
997
+ let a = document.createElementNS("http://www.w3.org/2000/svg", "path");
998
+ a.setAttribute("d", this.classes.addablePath), t.appendChild(a), n.appendChild(t), n.onclick = (e) => {
999
+ if (e.preventDefault(), e.stopPropagation(), this.settings.disabled || !this.callbacks.addable) return;
1000
+ let t = this.content.search.input.value.trim();
1001
+ if (t === "") {
1002
+ this.content.search.input.focus();
1003
+ return;
1004
+ }
1005
+ let n = (e) => {
1006
+ let t = new A(e);
1007
+ if (this.callbacks.addOption(t), this.settings.isMultiple) {
1008
+ let e = this.store.getSelected();
1009
+ e.push(t.id), this.callbacks.setSelected(e, !0);
1010
+ } else this.callbacks.setSelected([t.id], !0);
1011
+ if (this.callbacks.clearSearch(), this.settings.closeOnSelect) {
1012
+ let e = i(this.content.main);
1013
+ setTimeout(() => {
1014
+ this.requestClose("select", { selectionChanged: !0 });
1015
+ }, e);
1016
+ }
1017
+ }, r = this.callbacks.addable(t);
1018
+ r !== !1 && r != null && (r instanceof Promise ? r.then((e) => {
1019
+ typeof e == "string" ? n({
1020
+ text: e,
1021
+ value: e
1022
+ }) : r instanceof Error ? this.renderError(r.message) : n(e);
1023
+ }) : typeof r == "string" ? n({
1024
+ text: r,
1025
+ value: r
1026
+ }) : r instanceof Error ? this.renderError(r.message) : n(r));
1027
+ }, e.appendChild(n), r.addable = {
1028
+ main: n,
1029
+ svg: t,
1030
+ path: a
1031
+ };
1032
+ }
1033
+ return r;
1034
+ }
1035
+ searchFocus() {
1036
+ this.content.search.input.focus({ preventScroll: !0 });
1037
+ }
1038
+ getOptions(e = !1, t = !1, n = !1) {
1039
+ let r = "." + this.classes.getFirst("option");
1040
+ return e && (r += ":not(." + this.classes.getFirst("placeholder") + ")"), t && (r += ":not(." + this.classes.getFirst("disabled") + ")"), n && (r += ":not(." + this.classes.getFirst("hide") + ")"), Array.from(this.content.list.querySelectorAll(r));
1041
+ }
1042
+ highlight(e) {
1043
+ let t = this.getOptions(!0, !0, !0);
1044
+ if (t.length === 0) return;
1045
+ if (t.length === 1 && !t[0].classList.contains(this.classes.getFirst("highlighted"))) {
1046
+ this.addClasses(t[0], this.classes.highlighted);
1047
+ return;
1048
+ }
1049
+ let n = !1;
1050
+ for (let e of t) e.classList.contains(this.classes.getFirst("highlighted")) && (n = !0);
1051
+ if (!n) {
1052
+ for (let e of t) if (e.classList.contains(this.classes.getFirst("selected"))) {
1053
+ this.addClasses(e, this.classes.highlighted);
1054
+ break;
1055
+ }
1056
+ }
1057
+ for (let n = 0; n < t.length; n++) if (t[n].classList.contains(this.classes.getFirst("highlighted"))) {
1058
+ let r = t[n];
1059
+ this.removeClasses(r, this.classes.highlighted);
1060
+ let i = r.parentElement;
1061
+ if (i && i.classList.contains(this.classes.getFirst("mainOpen"))) {
1062
+ let e = i.querySelector("." + this.classes.getFirst("optgroupLabel"));
1063
+ e && e.click();
1064
+ }
1065
+ let a = t[e === "down" ? n + 1 < t.length ? n + 1 : 0 : n - 1 >= 0 ? n - 1 : t.length - 1];
1066
+ this.addClasses(a, this.classes.highlighted), this.ensureElementInView(this.content.list, a), a.id && this.main.main.setAttribute("aria-activedescendant", a.id);
1067
+ let o = a.parentElement;
1068
+ if (o && o.classList.contains(this.classes.getFirst("close"))) {
1069
+ let e = o.querySelector("." + this.classes.getFirst("optgroupLabel"));
1070
+ e && e.click();
1071
+ }
1072
+ return;
1073
+ }
1074
+ let r = t[e === "down" ? 0 : t.length - 1];
1075
+ this.addClasses(r, this.classes.highlighted), r.id && this.main.main.setAttribute("aria-activedescendant", r.id), this.ensureElementInView(this.content.list, r);
1076
+ }
1077
+ isTypeaheadKey(e) {
1078
+ return this.settings.showSearch || this.settings.disabled || e.ctrlKey || e.metaKey || e.altKey || e.isComposing ? !1 : e.key.length === 1 && /[\p{L}\p{N}]/u.test(e.key);
1079
+ }
1080
+ typeahead(e) {
1081
+ let t = this.getOptions(!0, !0, !0);
1082
+ if (t.length === 0) return;
1083
+ let n = e.toLowerCase(), r = this.typeaheadQuery.length > 0 && [...this.typeaheadQuery].every((e) => e === n);
1084
+ this.typeaheadTimer !== null && clearTimeout(this.typeaheadTimer), this.typeaheadTimer = setTimeout(() => {
1085
+ this.typeaheadQuery = "", this.typeaheadTimer = null;
1086
+ }, N);
1087
+ let i = this.classes.getFirst("highlighted"), a = this.classes.getFirst("selected"), o = t.findIndex((e) => e.classList.contains(i));
1088
+ o < 0 && (o = t.findIndex((e) => e.classList.contains(a)));
1089
+ let s;
1090
+ r ? (this.typeaheadQuery = n, s = o >= 0 ? (o + 1) % t.length : 0) : (this.typeaheadQuery += n, s = o >= 0 ? o : 0);
1091
+ let c = this.findTypeaheadOption(t, this.typeaheadQuery, s);
1092
+ c && this.highlightOption(c);
1093
+ }
1094
+ findTypeaheadOption(e, t, n) {
1095
+ for (let r = 0; r < e.length; r++) {
1096
+ let i = e[(n + r) % e.length];
1097
+ if ((i.textContent || "").trim().toLowerCase().startsWith(t)) return i;
1098
+ }
1099
+ return null;
1100
+ }
1101
+ highlightOption(e) {
1102
+ let t = this.classes.getFirst("highlighted");
1103
+ this.content.list.querySelectorAll("." + t).forEach((t) => {
1104
+ t !== e && this.removeClasses(t, this.classes.highlighted);
1105
+ }), this.addClasses(e, this.classes.highlighted), e.id && this.main.main.setAttribute("aria-activedescendant", e.id);
1106
+ let n = e.parentElement;
1107
+ n && n.classList.contains(this.classes.getFirst("close")) && n.querySelector("." + this.classes.getFirst("optgroupLabel"))?.click(), this.ensureElementInView(this.content.list, e);
1108
+ }
1109
+ clearTypeahead() {
1110
+ this.typeaheadQuery = "", this.typeaheadTimer !== null && (clearTimeout(this.typeaheadTimer), this.typeaheadTimer = null);
1111
+ }
1112
+ listDiv() {
1113
+ let e = document.createElement("div");
1114
+ this.addClasses(e, this.classes.list);
1115
+ let t = this.settings.id + "-list";
1116
+ return e.id = t, e.dataset.id = t, e;
1117
+ }
1118
+ renderError(e) {
1119
+ this.optionsListIsFullData = !1, this.content.list.innerHTML = "";
1120
+ let t = document.createElement("div");
1121
+ this.addClasses(t, this.classes.error), t.textContent = e, this.content.list.appendChild(t), this.repositionOpenContent();
1122
+ }
1123
+ renderSearching() {
1124
+ this.optionsListIsFullData = !1, this.content.list.innerHTML = "";
1125
+ let e = document.createElement("div");
1126
+ this.addClasses(e, this.classes.searching), e.textContent = this.settings.searchingText, this.content.list.appendChild(e), this.announce(this.settings.searchingText), this.repositionOpenContent();
1127
+ }
1128
+ renderOptions(e) {
1129
+ this.lastSearchFilterTerm = "";
1130
+ let t = e.map((e) => e instanceof A ? [e] : e.options.map((e) => new A(e))).flat();
1131
+ if (this.lastRenderedOptions = t.filter((e) => !e.placeholder), this.content.list.innerHTML = "", this.lastRenderedOptions.length === 0) {
1132
+ this.optionsListIsFullData = !1;
1133
+ let e = document.createElement("div");
1134
+ if (this.addClasses(e, this.classes.search), this.callbacks.addable) {
1135
+ let t = this.settings.addableText.replace("{value}", this.content.search.input.value);
1136
+ e.innerHTML = t, this.announce(t);
1137
+ } else e.innerHTML = this.settings.searchText, this.announce(this.settings.searchText);
1138
+ this.content.list.appendChild(e), this.repositionOpenContent();
1139
+ return;
1140
+ }
1141
+ this.settings.allowDeselect && !this.settings.isMultiple && (this.store.filter((e) => e.placeholder, !1, !1).length || this.store.addOption(new A({
1142
+ text: "",
1143
+ value: "",
1144
+ selected: !1,
1145
+ placeholder: !0
1146
+ }), !0));
1147
+ let n = document.createDocumentFragment();
1148
+ for (let t of e) {
1149
+ if (t instanceof j) {
1150
+ let e = document.createElement("div");
1151
+ this.addClasses(e, this.classes.optgroup);
1152
+ let r = document.createElement("div");
1153
+ this.addClasses(r, this.classes.optgroupLabel), e.appendChild(r);
1154
+ let i = document.createElement("div");
1155
+ this.addClasses(i, this.classes.optgroupLabelText), i.textContent = t.label, r.appendChild(i);
1156
+ let a = document.createElement("div");
1157
+ if (this.addClasses(a, this.classes.optgroupActions), r.appendChild(a), this.settings.isMultiple && t.selectAll) {
1158
+ let e = this.createSelectAllControl(() => {
1159
+ let e = this.store.getSelected();
1160
+ if (this.isOptgroupAllSelected(t.options, new Set(e))) {
1161
+ let n = e.filter((e) => {
1162
+ for (let n of t.options) if (e === n.id) return !1;
1163
+ return !0;
1164
+ });
1165
+ this.callbacks.setSelected(n, !0);
1166
+ } else {
1167
+ let n = t.options.map((e) => e.id).filter((e) => e !== void 0), r = e.concat(n);
1168
+ for (let e of t.options) e.id && !this.store.getOptionByID(e.id) && this.callbacks.addOption(new A(e));
1169
+ this.callbacks.setSelected(r, !0);
1170
+ return;
1171
+ }
1172
+ }, this.isOptgroupAllSelected(t.options));
1173
+ a.appendChild(e);
1174
+ }
1175
+ if (t.closable !== "off") {
1176
+ let n = document.createElement("div");
1177
+ this.addClasses(n, this.classes.optgroupClosable);
1178
+ let i = document.createElementNS("http://www.w3.org/2000/svg", "svg");
1179
+ i.setAttribute("viewBox", "0 0 100 100"), this.addClasses(i, this.classes.arrow), n.appendChild(i);
1180
+ let o = document.createElementNS("http://www.w3.org/2000/svg", "path");
1181
+ i.appendChild(o), t.options.some((e) => e.selected) || this.content.search.input.value.trim() !== "" ? (this.addClasses(n, this.classes.mainOpen), o.setAttribute("d", this.classes.arrowOpen)) : t.closable === "open" ? (this.addClasses(e, this.classes.mainOpen), o.setAttribute("d", this.classes.arrowOpen)) : t.closable === "close" && (this.addClasses(e, this.classes.close), o.setAttribute("d", this.classes.arrowClose)), r.addEventListener("click", (t) => {
1182
+ t.preventDefault(), t.stopPropagation(), this.isClosableOptgroupOpen(e, n) ? (this.removeClasses(e, this.classes.mainOpen), this.removeClasses(n, 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(n, this.classes.mainOpen), this.addClasses(e, this.classes.mainOpen), o.setAttribute("d", this.classes.arrowOpen)), this.repositionOpenContent();
1183
+ }), a.appendChild(n);
1184
+ }
1185
+ e.appendChild(r);
1186
+ for (let r of t.options) e.appendChild(this.option(new A(r))), n.appendChild(e);
1187
+ }
1188
+ t instanceof A && n.appendChild(this.option(t));
1189
+ }
1190
+ this.content.list.appendChild(n), this.setOptionsListFullData(e), this.announce(this.settings.resultsText.replace("{count}", String(this.lastRenderedOptions.length))), this.updateGlobalSelectAllState(), this.repositionOpenContent();
1191
+ }
1192
+ canFilterOptionsInPlace() {
1193
+ return this.optionsListIsFullData ? this.content.list.querySelector("." + this.classes.getFirst("option")) !== null : !1;
1194
+ }
1195
+ resetSearchFilterState() {
1196
+ this.lastSearchFilterTerm = "";
1197
+ }
1198
+ filterOptionsInPlace(e, t) {
1199
+ let n = e.trim();
1200
+ if (n === this.lastSearchFilterTerm) return;
1201
+ this.lastSearchFilterTerm = n;
1202
+ let r = [], i = this.content.list.querySelectorAll("." + this.classes.getFirst("option"));
1203
+ for (let e of i) {
1204
+ let i = e.dataset.id;
1205
+ if (!i) continue;
1206
+ let a = this.store.getOptionByID(i);
1207
+ if (!a) continue;
1208
+ let o = a.placeholder || !a.display || a.selected && this.settings.hideSelected, s = t(a, n);
1209
+ 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"));
1210
+ }
1211
+ 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(), this.updateGlobalSelectAllState(), this.repositionOpenContent();
1212
+ }
1213
+ setOptionsListFullData(e) {
1214
+ let t = this.store.getDataOptions(!1), n = e.map((e) => e instanceof A ? [e] : e.options.map((e) => new A(e))).flat();
1215
+ if (n.length !== t.length) {
1216
+ this.optionsListIsFullData = !1;
1217
+ return;
1218
+ }
1219
+ let r = new Set(t.map((e) => e.id));
1220
+ this.optionsListIsFullData = n.every((e) => r.has(e.id));
1221
+ }
1222
+ isClosableOptgroupOpen(e, t) {
1223
+ return e.classList.contains(this.classes.getFirst("close")) ? !1 : e.classList.contains(this.classes.getFirst("mainOpen")) || t.classList.contains(this.classes.getFirst("mainOpen"));
1224
+ }
1225
+ closeClosableOptgroup(e) {
1226
+ let t = e.querySelector("." + this.classes.getFirst("optgroupClosable"));
1227
+ if (!t || e.classList.contains(this.classes.getFirst("close"))) return;
1228
+ this.removeClasses(e, this.classes.mainOpen), this.removeClasses(t, this.classes.mainOpen), this.addClasses(e, this.classes.close);
1229
+ let n = t.querySelector("path");
1230
+ n && n.setAttribute("d", this.classes.arrowClose);
1231
+ }
1232
+ closeOtherClosableOptgroups(e) {
1233
+ let t = this.content.list.querySelectorAll("." + this.classes.getFirst("optgroup"));
1234
+ for (let n of t) n !== e && this.closeClosableOptgroup(n);
1235
+ }
1236
+ updateOptgroupVisibilityAfterSearch(e) {
1237
+ let t = this.content.list.querySelectorAll("." + this.classes.getFirst("optgroup"));
1238
+ for (let n of t) {
1239
+ let t = n.querySelectorAll("." + this.classes.getFirst("option")), r = !1;
1240
+ for (let e of t) if (!e.classList.contains(this.classes.getFirst("hide"))) {
1241
+ r = !0;
1242
+ break;
1243
+ }
1244
+ r ? (this.removeClasses(n, this.classes.hide), e !== "" && (this.removeClasses(n, this.classes.close), this.addClasses(n, this.classes.mainOpen))) : this.addClasses(n, this.classes.hide);
1245
+ }
1246
+ }
1247
+ updateSearchResultsMessage(e, t) {
1248
+ if (this.removeListSearchMessage(), e > 0) return;
1249
+ let n = document.createElement("div");
1250
+ if (this.addClasses(n, this.classes.search), this.callbacks.addable) {
1251
+ let e = this.settings.addableText.replace("{value}", t);
1252
+ n.innerHTML = e, this.announce(e);
1253
+ } else n.innerHTML = this.settings.searchText, this.announce(this.settings.searchText);
1254
+ this.content.list.appendChild(n);
1255
+ }
1256
+ removeListSearchMessage() {
1257
+ this.content.list.querySelectorAll("." + this.classes.getFirst("search")).forEach((e) => e.remove());
1258
+ }
1259
+ setOptionElementContent(e, t, n) {
1260
+ let r = n.trim();
1261
+ 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");
1262
+ }
1263
+ hasRenderedOptions() {
1264
+ return this.content.list.querySelector("." + this.classes.getFirst("option")) !== null;
1265
+ }
1266
+ canUpdateOptionSelectionInPlace() {
1267
+ return this.content.search.input.value.trim() === "" && this.hasRenderedOptions();
1268
+ }
1269
+ updateOptionSelection() {
1270
+ let e = new Set(this.store.getSelected()), t = this.content.list.querySelectorAll("." + this.classes.getFirst("option")), n = null;
1271
+ for (let r of t) {
1272
+ let t = r.dataset.id;
1273
+ if (!t) continue;
1274
+ let i = this.store.getOptionByID(t);
1275
+ if (!i) continue;
1276
+ let a = e.has(t);
1277
+ 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)));
1278
+ }
1279
+ !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(), this.updateGlobalSelectAllState(), this.repositionOpenContent();
1280
+ }
1281
+ createSelectAllControl(e, t = !1) {
1282
+ let n = document.createElement("div");
1283
+ this.addClasses(n, this.classes.optgroupSelectAll), n.setAttribute("role", "checkbox"), n.setAttribute("aria-checked", t ? "true" : "false"), n.setAttribute("aria-label", this.selectAllLabel(t)), n.tabIndex = -1, t && this.addClasses(n, this.classes.selected);
1284
+ let r = document.createElement("span");
1285
+ r.textContent = this.selectAllLabel(t), n.appendChild(r);
1286
+ let i = document.createElementNS("http://www.w3.org/2000/svg", "svg");
1287
+ i.setAttribute("viewBox", "0 0 100 100"), i.setAttribute("aria-hidden", "true"), n.appendChild(i);
1288
+ let a = document.createElementNS("http://www.w3.org/2000/svg", "path");
1289
+ a.setAttribute("d", this.classes.optgroupSelectAllBox), i.appendChild(a);
1290
+ let o = document.createElementNS("http://www.w3.org/2000/svg", "path");
1291
+ return o.setAttribute("d", this.classes.optgroupSelectAllCheck), i.appendChild(o), n.addEventListener("click", (t) => {
1292
+ t.preventDefault(), t.stopPropagation(), this.settings.disabled || e();
1293
+ }), n;
1294
+ }
1295
+ getSelectableOptions() {
1296
+ return this.store.getDataOptions(!1).filter((e) => !e.disabled && !e.placeholder && e.display);
1297
+ }
1298
+ isGlobalAllSelected(e) {
1299
+ let t = this.getSelectableOptions();
1300
+ if (t.length === 0) return !1;
1301
+ let n = e || new Set(this.store.getSelected());
1302
+ for (let e of t) if (!n.has(e.id)) return !1;
1303
+ return !0;
1304
+ }
1305
+ toggleGlobalSelectAll() {
1306
+ let e = this.getSelectableOptions(), t = new Set(this.store.getSelected());
1307
+ if (this.isGlobalAllSelected(t)) {
1308
+ let t = new Set(e.map((e) => e.id)), n = this.store.getSelected().filter((e) => !t.has(e));
1309
+ this.callbacks.setSelected(n, !0);
1310
+ } else this.callbacks.setSelected(e.map((e) => e.id), !0);
1311
+ }
1312
+ updateGlobalSelectAllState() {
1313
+ let e = this.content.search.selectAll;
1314
+ if (!e || !this.settings.isMultiple || !this.settings.selectAll) return;
1315
+ let t = this.isGlobalAllSelected();
1316
+ t ? this.addClasses(e, this.classes.selected) : this.removeClasses(e, this.classes.selected), e.setAttribute("aria-checked", t ? "true" : "false"), e.setAttribute("aria-label", this.selectAllLabel(t));
1317
+ let n = e.querySelector("span");
1318
+ n && (n.textContent = this.selectAllLabel(t));
1319
+ }
1320
+ updateOptgroupSelectAllStates() {
1321
+ if (!this.settings.isMultiple) return;
1322
+ let e = new Set(this.store.getSelected()), t = this.content.list.querySelectorAll("." + this.classes.getFirst("optgroup"));
1323
+ for (let n of t) {
1324
+ let t = n.querySelector("." + this.classes.getFirst("optgroupSelectAll"));
1325
+ if (!t) continue;
1326
+ let r = n.querySelectorAll("." + this.classes.getFirst("option")), i = r.length > 0;
1327
+ for (let t of r) {
1328
+ let n = t.dataset.id;
1329
+ if (!n || !e.has(n)) {
1330
+ i = !1;
1331
+ break;
1332
+ }
1333
+ }
1334
+ i ? this.addClasses(t, this.classes.selected) : this.removeClasses(t, this.classes.selected), t.setAttribute("aria-checked", i ? "true" : "false"), t.setAttribute("aria-label", this.selectAllLabel(i));
1335
+ let a = t.querySelector("span");
1336
+ a && (a.textContent = this.selectAllLabel(i));
1337
+ }
1338
+ }
1339
+ selectAllLabel(e) {
1340
+ return e ? this.settings.unselectAllText : this.settings.selectAllText;
1341
+ }
1342
+ isOptgroupAllSelected(e, t) {
1343
+ if (e.length === 0) return !1;
1344
+ for (let n of e) if (!(t ? n.id && t.has(n.id) : n.selected)) return !1;
1345
+ return !0;
1346
+ }
1347
+ option(e) {
1348
+ if (e.placeholder) {
1349
+ let e = document.createElement("div");
1350
+ return this.addClasses(e, this.classes.option), this.addClasses(e, this.classes.hide), e;
1351
+ }
1352
+ let t = document.createElement("div");
1353
+ 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) => {
1354
+ t.classList.add(e);
1355
+ }), 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) => {
1356
+ t.preventDefault(), t.stopPropagation();
1357
+ let n = this.store.getSelected(), r = t.currentTarget, i = String(r.dataset.id), a = this.store.getOptionByID(i) ?? e, o = n.includes(i), s = t.ctrlKey || t.metaKey;
1358
+ if (this.settings.disabled || e.disabled) return;
1359
+ if (!this.settings.isMultiple && o && !this.settings.allowDeselect || o && a.mandatory) {
1360
+ this.closeOnSingleSelectReclick(a);
1361
+ return;
1362
+ }
1363
+ if (this.settings.isMultiple && this.settings.maxSelected <= n.length && !o || this.settings.isMultiple && this.settings.minSelected >= n.length && o && !s) return;
1364
+ let c = !1, l = this.store.getSelectedOptions(), u = [];
1365
+ if (this.settings.isMultiple) {
1366
+ let n = l.some((e) => e.id === i);
1367
+ if (t.shiftKey && this.lastSelectedOption) {
1368
+ let t = this.lastRenderedOptions, n = t.findIndex((e) => e.id === this.lastSelectedOption.id), r = t.findIndex((t) => t.id === e.id);
1369
+ if (n >= 0 && r >= 0) {
1370
+ let e = Math.min(n, r), i = Math.max(n, r), a = t.slice(e, i + 1).filter((e) => !l.find((t) => t.id === e.id));
1371
+ u = l.length + a.length <= this.settings.maxSelected ? l.concat(a) : l;
1372
+ } else u = l;
1373
+ } else u = n ? l.filter((e) => e.id !== i) : l.concat(a), this.lastSelectedOption = a;
1374
+ }
1375
+ if (this.settings.isMultiple || (u = o ? [] : [a]), this.callbacks.beforeChange || (c = !0), this.callbacks.beforeChange && (c = this.callbacks.beforeChange(u, l) !== !1), c) {
1376
+ this.store.getOptionByID(i) || this.callbacks.addOption(e), this.callbacks.setSelected(u.map((e) => e.id), !1);
1377
+ let n = t.ctrlKey || t.metaKey || t.shiftKey;
1378
+ this.settings.closeOnSelect && !(this.settings.isMultiple && n) && this.requestClose("select", {
1379
+ option: a,
1380
+ selectionChanged: this.selectionChanged(l, u)
1381
+ }), this.callbacks.afterChange && this.callbacks.afterChange(u);
1382
+ }
1383
+ }), t;
1384
+ }
1385
+ destroy() {
1386
+ this.clearTypeahead(), this.stopPositionTracking(), this.modalElements ? (this.unlockBodyScroll(), this.content.main.parentElement === this.modalElements.dialog && this.restoreContentOffscreen(), this.modalElements.overlay.remove(), this.modalElements = null) : this.bodyScrollLocked && this.unlockBodyScroll(), this.main.main.remove(), this.content.main.remove(), this.removeDetachedInstanceDom();
1387
+ }
1388
+ removeDetachedInstanceDom() {
1389
+ let e = this.settings.id, t = this.classes.getFirst("main"), n = this.classes.getFirst("content"), r = this.classes.getFirst("modalOverlay");
1390
+ document.querySelectorAll(`[data-id="${e}"]`).forEach((e) => {
1391
+ (e.classList.contains(t) || e.classList.contains(n) || e.classList.contains(r)) && e.remove();
1392
+ });
1393
+ }
1394
+ highlightText(e, t, n) {
1395
+ let r = t.trim();
1396
+ if (r === "") return e;
1397
+ let i = r.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"), a = document.createElement("div");
1398
+ a.innerHTML = e;
1399
+ let o = (e) => {
1400
+ if (e.nodeType === Node.TEXT_NODE) {
1401
+ let t = e.textContent || "", r = RegExp("(" + i + ")", "i");
1402
+ if (r.test(t)) {
1403
+ let i = document.createElement("span");
1404
+ t.split(r).forEach((e, t) => {
1405
+ if (e && r.test(e)) {
1406
+ let t = document.createElement("mark");
1407
+ t.className = n, t.textContent = e, i.appendChild(t);
1408
+ } else e && i.appendChild(document.createTextNode(e));
1409
+ }), e.parentNode?.replaceChild(i, e);
1410
+ }
1411
+ } else e.nodeType === Node.ELEMENT_NODE && Array.from(e.childNodes).forEach((e) => o(e));
1412
+ };
1413
+ return Array.from(a.childNodes).forEach((e) => o(e)), a.innerHTML;
1414
+ }
1415
+ setContentDirection(e) {
1416
+ let t = e === "above", n = t ? this.classes.dirAbove : this.classes.dirBelow, r = t ? this.classes.dirBelow : this.classes.dirAbove;
1417
+ if (this.removeClasses(this.main.main, r), this.addClasses(this.main.main, n), this.removeClasses(this.content.main, r), this.addClasses(this.content.main, n), t) {
1418
+ let e = this.main.main.offsetHeight, t = this.content.main.offsetHeight;
1419
+ this.content.main.style.margin = "-" + (e + t - 1) + "px 0px 0px 0px";
1420
+ } else this.content.main.style.margin = "-1px 0px 0px 0px";
1421
+ }
1422
+ setContentPosition() {
1423
+ let e = this.main.main.getBoundingClientRect();
1424
+ if (this.settings.contentPosition === "relative") {
1425
+ this.applyContentWidth(e);
1426
+ return;
1427
+ }
1428
+ this.cancelOverflowShift();
1429
+ let t, n;
1430
+ this.settings.contentPosition === "fixed" ? (t = e.top + e.height, n = e.left) : (t = e.top + window.scrollY + e.height, n = e.left + window.scrollX), this.content.main.style.top = t + "px", this.content.main.style.left = n + "px", this.applyContentWidth(e);
1431
+ let r = this.getKnownContentWidth(e);
1432
+ r === null ? this.overflowShiftRaf = requestAnimationFrame(() => {
1433
+ this.overflowShiftRaf = 0, this.applyOverflowShiftFromMeasure();
1434
+ }) : this.content.main.style.left = this.adjustLeftForOverflow(n, e.left, r) + "px";
1435
+ }
1436
+ applyContentWidth(e) {
1437
+ let t = this.settings.contentWidth;
1438
+ this.content.main.style.width = "", this.content.main.style.minWidth = "", this.content.main.style.maxWidth = "", t ? t === "auto" ? this.content.main.style.minWidth = e.width + "px" : t.startsWith(">") ? this.content.main.style.minWidth = t.slice(1) : t.startsWith("<") ? this.content.main.style.maxWidth = t.slice(1) : this.content.main.style.width = t : this.settings.contentPosition !== "relative" && (this.content.main.style.width = e.width + "px");
1439
+ }
1440
+ cancelOverflowShift() {
1441
+ this.overflowShiftRaf &&= (cancelAnimationFrame(this.overflowShiftRaf), 0);
1442
+ }
1443
+ getKnownContentWidth(e) {
1444
+ let t = this.settings.contentWidth;
1445
+ if (!t) return e.width;
1446
+ if (t.startsWith(">") || t.startsWith("<") || t.includes("%")) return null;
1447
+ let n = parseFloat(t);
1448
+ return Number.isNaN(n) ? null : n;
1449
+ }
1450
+ adjustLeftForOverflow(e, t, n) {
1451
+ let r = t + n;
1452
+ if (r <= window.innerWidth) return e;
1453
+ let i = e - (r - (window.innerWidth - 20));
1454
+ return this.settings.contentPosition === "fixed" ? Math.max(0, i) : Math.max(window.scrollX, i);
1455
+ }
1456
+ applyOverflowShiftFromMeasure() {
1457
+ let e = this.content.main.getBoundingClientRect().right;
1458
+ if (e <= window.innerWidth) return;
1459
+ let t = e - (window.innerWidth - 20), n = (parseFloat(this.content.main.style.left) || 0) - t;
1460
+ this.settings.contentPosition === "fixed" ? this.content.main.style.left = Math.max(0, n) + "px" : this.content.main.style.left = Math.max(window.scrollX, n) + "px";
1461
+ }
1462
+ moveContentAbove() {
1463
+ this.setContentDirection("above"), this.setContentPosition();
1464
+ }
1465
+ moveContentBelow() {
1466
+ this.setContentDirection("below"), this.setContentPosition();
1467
+ }
1468
+ ensureElementInView(e, t) {
1469
+ let n = e.scrollTop + e.offsetTop, r = n + e.clientHeight, i = t.offsetTop, a = i + t.clientHeight;
1470
+ i < n ? e.scrollTop -= n - i : a > r && (e.scrollTop += a - r);
1471
+ }
1472
+ putContent() {
1473
+ let e = this.main.main.offsetHeight, t = this.main.main.getBoundingClientRect(), n = this.content.main.offsetHeight;
1474
+ return window.innerHeight - (t.top + e) <= n && t.top > n ? "up" : "down";
1475
+ }
1476
+ updateDeselectAll() {
1477
+ if (!this.store || !this.settings) return;
1478
+ 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;
1479
+ r && (!n || t) && !i ? this.removeClasses(a, o) : this.addClasses(a, o);
1480
+ }
1481
+ };
1482
+ // src/slim-select/mutations.ts
1483
+ function F(e, t) {
1484
+ let n = {
1485
+ classChanged: !1,
1486
+ titleChanged: !1,
1487
+ disabledChanged: !1,
1488
+ optgroupOptionChanged: !1,
1489
+ selectionChanged: !1
1490
+ };
1491
+ for (let r of e) {
1492
+ if (r.target === t && (r.attributeName === "disabled" && (n.disabledChanged = !0), r.attributeName === "class" && (n.classChanged = !0), r.attributeName === "title" && (n.titleChanged = !0), r.type === "childList")) {
1493
+ for (let e of Array.from(r.addedNodes)) if (e.nodeName === "OPTION" && e.value === t.value) {
1494
+ n.selectionChanged = !0;
1495
+ break;
1496
+ }
1497
+ n.optgroupOptionChanged = !0;
1498
+ }
1499
+ (r.target.nodeName === "OPTGROUP" || r.target.nodeName === "OPTION") && (n.optgroupOptionChanged = !0);
1500
+ }
1501
+ return n;
1502
+ }
1503
+ // src/slim-select/select.ts
1504
+ var I = class {
1505
+ select;
1506
+ onValueChange;
1507
+ onClassChange;
1508
+ onTitleChange;
1509
+ onDisabledChange;
1510
+ onOptionsChange;
1511
+ onLabelClick;
1512
+ listen = !1;
1513
+ observer = null;
1514
+ isUpdating = !1;
1515
+ pendingOptionsChange = null;
1516
+ preventNativeSelect = null;
1517
+ preventNativeSelectMousedown = null;
1518
+ preventNativeSelectFocus = null;
1519
+ restoreAriaHiddenOnBlur = null;
1520
+ constructor(e) {
1521
+ this.select = e, this.valueChange = this.valueChange.bind(this), this.select.addEventListener("change", this.valueChange, { passive: !0 }), this.observer = new MutationObserver(this.observeCall.bind(this)), this.changeListen(!0);
1522
+ }
1523
+ enable() {
1524
+ this.select.disabled = !1;
1525
+ }
1526
+ disable() {
1527
+ this.select.disabled = !0;
1528
+ }
1529
+ hideUI() {
1530
+ this.select.tabIndex = -1, this.select.style.position = "absolute", this.select.style.width = "1px", this.select.style.height = "1px", this.select.style.opacity = "0", this.select.style.overflow = "hidden", this.select.style.pointerEvents = "none", this.select.style.margin = "0", this.select.style.padding = "0", this.select.style.borderWidth = "0", this.select.style.clipPath = "inset(50%)", document.activeElement !== this.select && this.select.setAttribute("aria-hidden", "true"), this.preventNativeSelect || (this.preventNativeSelect = (e) => {
1531
+ e.preventDefault(), e.stopPropagation(), e.stopImmediatePropagation();
1532
+ }, this.preventNativeSelectMousedown = (e) => {
1533
+ e.preventDefault(), e.stopPropagation(), e.stopImmediatePropagation();
1534
+ }, this.preventNativeSelectFocus = (e) => {
1535
+ this.select.removeAttribute("aria-hidden"), e.preventDefault(), e.stopPropagation(), e.stopImmediatePropagation();
1536
+ }, this.restoreAriaHiddenOnBlur = () => {
1537
+ this.select.setAttribute("aria-hidden", "true");
1538
+ }, this.select.addEventListener("click", this.preventNativeSelect, {
1539
+ capture: !0,
1540
+ passive: !1
1541
+ }), this.select.addEventListener("mousedown", this.preventNativeSelectMousedown, {
1542
+ capture: !0,
1543
+ passive: !1
1544
+ }), this.select.addEventListener("focus", this.preventNativeSelectFocus, {
1545
+ capture: !0,
1546
+ passive: !1
1547
+ }), this.select.addEventListener("blur", this.restoreAriaHiddenOnBlur, {
1548
+ capture: !0,
1549
+ passive: !0
1550
+ }));
1551
+ }
1552
+ showUI() {
1553
+ this.select.removeAttribute("tabindex"), this.select.style.position = "", this.select.style.width = "", this.select.style.height = "", this.select.style.opacity = "", this.select.style.overflow = "", this.select.style.pointerEvents = "", this.select.style.margin = "", this.select.style.padding = "", this.select.style.borderWidth = "", this.select.style.clipPath = "", this.select.removeAttribute("aria-hidden"), this.preventNativeSelect &&= (this.select.removeEventListener("click", this.preventNativeSelect, { capture: !0 }), null), this.preventNativeSelectMousedown &&= (this.select.removeEventListener("mousedown", this.preventNativeSelectMousedown, { capture: !0 }), null), this.preventNativeSelectFocus &&= (this.select.removeEventListener("focus", this.preventNativeSelectFocus, { capture: !0 }), null), this.restoreAriaHiddenOnBlur &&= (this.select.removeEventListener("blur", this.restoreAriaHiddenOnBlur, { capture: !0 }), null);
1554
+ }
1555
+ changeListen(e) {
1556
+ this.listen = e, e && this.observer && this.observer.observe(this.select, {
1557
+ subtree: !0,
1558
+ childList: !0,
1559
+ attributes: !0
1560
+ }), e || this.observer && this.observer.disconnect();
1561
+ }
1562
+ valueChange(e) {
1563
+ return this.listen && this.onValueChange && this.onValueChange(this.getSelectedOptions()), !0;
1564
+ }
1565
+ observeCall(e) {
1566
+ if (!this.listen) return;
1567
+ let { classChanged: t, titleChanged: n, disabledChanged: r, optgroupOptionChanged: i, selectionChanged: a } = F(e, this.select), o = a;
1568
+ if (t && this.onClassChange && this.onClassChange(this.select.className.split(" ")), n && this.onTitleChange && this.onTitleChange(this.select.getAttribute("title") || ""), r && this.onDisabledChange && (this.changeListen(!1), this.onDisabledChange(this.select.disabled), this.changeListen(!0)), i && this.clearLeftoverHiddenDisplay(e), i && this.onOptionsChange) {
1569
+ if (this.isUpdating) {
1570
+ if (this.select.options.length > 0) {
1571
+ let e = this.getData();
1572
+ e.length > 0 && (this.pendingOptionsChange = e);
1573
+ }
1574
+ o && this.select.dispatchEvent(new Event("change"));
1575
+ return;
1576
+ }
1577
+ this.changeListen(!1), this.onOptionsChange(this.getData()), this.changeListen(!0), o = !1;
1578
+ }
1579
+ o && this.select.dispatchEvent(new Event("change"));
1580
+ }
1581
+ getData() {
1582
+ let e = [], t = this.select.childNodes;
1583
+ for (let n of t) n.nodeName === "OPTGROUP" && e.push(this.getDataFromOptgroup(n)), n.nodeName === "OPTION" && e.push(this.getDataFromOption(n));
1584
+ return e;
1585
+ }
1586
+ getDataFromOptgroup(e) {
1587
+ let t = {
1588
+ id: e.id,
1589
+ label: e.label,
1590
+ selectAll: e.dataset ? e.dataset.selectall === "true" : !1,
1591
+ closable: e.dataset ? e.dataset.closable : "off",
1592
+ options: []
1593
+ }, n = e.childNodes;
1594
+ for (let e of n) e.nodeName === "OPTION" && t.options.push(this.getDataFromOption(e));
1595
+ return t;
1596
+ }
1597
+ clearLeftoverHiddenDisplay(e) {
1598
+ for (let t of e) {
1599
+ if (t.target.nodeName !== "OPTION" || t.attributeName !== "hidden") continue;
1600
+ let e = t.target;
1601
+ !e.hidden && e.style.display === "none" && (e.style.display = "");
1602
+ }
1603
+ }
1604
+ getDataFromOption(e) {
1605
+ let t = e.hidden || e.hasAttribute("hidden");
1606
+ return {
1607
+ id: e.id,
1608
+ value: e.value,
1609
+ text: e.text,
1610
+ html: e.dataset && e.dataset.html ? e.dataset.html : "",
1611
+ defaultSelected: e.defaultSelected,
1612
+ selected: e.selected,
1613
+ display: e.style.display !== "none" && !t,
1614
+ disabled: e.disabled,
1615
+ mandatory: e.dataset ? e.dataset.mandatory === "true" : !1,
1616
+ placeholder: e.dataset.placeholder === "true",
1617
+ class: e.className,
1618
+ style: e.style.cssText,
1619
+ data: f(e.dataset)
1620
+ };
1621
+ }
1622
+ getSelectedOptions() {
1623
+ let e = [], t = this.select.childNodes;
1624
+ for (let n of t) {
1625
+ if (n.nodeName === "OPTGROUP") {
1626
+ let t = n.childNodes;
1627
+ for (let n of t) if (n.nodeName === "OPTION") {
1628
+ let t = n;
1629
+ t.selected && e.push(this.getDataFromOption(t));
1630
+ }
1631
+ }
1632
+ if (n.nodeName === "OPTION") {
1633
+ let t = n;
1634
+ t.selected && e.push(this.getDataFromOption(t));
1635
+ }
1636
+ }
1637
+ return e;
1638
+ }
1639
+ getSelectedValues() {
1640
+ return this.getSelectedOptions().map((e) => e.value);
1641
+ }
1642
+ hasOptionValues(e) {
1643
+ if (e.length === 0) return !0;
1644
+ let t = new Set(Array.from(this.select.options).map((e) => e.value));
1645
+ return e.every((e) => t.has(e));
1646
+ }
1647
+ setSelected(e) {
1648
+ this.changeListen(!1);
1649
+ let t = this.select.childNodes;
1650
+ for (let n of t) {
1651
+ if (n.nodeName === "OPTGROUP") {
1652
+ let t = n.childNodes;
1653
+ for (let n of t) if (n.nodeName === "OPTION") {
1654
+ let t = n;
1655
+ t.selected = e.includes(t.id);
1656
+ }
1657
+ }
1658
+ if (n.nodeName === "OPTION") {
1659
+ let t = n;
1660
+ t.selected = e.includes(t.id);
1661
+ }
1662
+ }
1663
+ let n = this.getSelectedOptions();
1664
+ this.select.multiple || (this.select.value = n.length === 1 ? n[0].value : ""), this.select.dispatchEvent(new Event("change", { bubbles: !0 })), this.changeListen(!0);
1665
+ }
1666
+ setSelectedByValue(e) {
1667
+ this.changeListen(!1);
1668
+ let t = this.select.childNodes;
1669
+ for (let n of t) {
1670
+ if (n.nodeName === "OPTGROUP") {
1671
+ let t = n.childNodes;
1672
+ for (let n of t) if (n.nodeName === "OPTION") {
1673
+ let t = n;
1674
+ t.selected = e.includes(t.value);
1675
+ }
1676
+ }
1677
+ if (n.nodeName === "OPTION") {
1678
+ let t = n;
1679
+ t.selected = e.includes(t.value);
1680
+ }
1681
+ }
1682
+ let n = this.getSelectedOptions();
1683
+ this.select.multiple || (this.select.value = n.length === 1 ? n[0].value : ""), this.select.dispatchEvent(new Event("change", { bubbles: !0 })), this.changeListen(!0);
1684
+ }
1685
+ updateSelect(e, t, n) {
1686
+ this.changeListen(!1), e && (this.select.dataset.id = e), t && (this.select.style.cssText = t), n && (this.select.className = "", n.forEach((e) => {
1687
+ e.trim() !== "" && this.select.classList.add(e.trim());
1688
+ })), this.changeListen(!0);
1689
+ }
1690
+ updateOptions(e) {
1691
+ if (!e || e.length === 0) return;
1692
+ this.isUpdating = !0, this.pendingOptionsChange = null, this.changeListen(!1);
1693
+ let t = this.getSelectedValues();
1694
+ this.select.innerHTML = "";
1695
+ for (let t of e) t instanceof j && this.select.appendChild(this.createOptgroup(t)), t instanceof A && this.select.appendChild(this.createOption(t));
1696
+ if (v(t, this.getSelectedValues()) || this.select.dispatchEvent(new Event("change", { bubbles: !0 })), this.changeListen(!0), this.isUpdating = !1, this.pendingOptionsChange !== null) {
1697
+ let e = this.pendingOptionsChange;
1698
+ e.length > 0 && this.onOptionsChange ? (this.pendingOptionsChange = null, this.changeListen(!1), this.onOptionsChange(e), this.changeListen(!0)) : this.pendingOptionsChange = null;
1699
+ }
1700
+ }
1701
+ createOptgroup(e) {
1702
+ let t = document.createElement("optgroup");
1703
+ if (t.id = e.id, t.label = e.label, e.selectAll && (t.dataset.selectAll = "true"), e.closable !== "off" && (t.dataset.closable = e.closable), e.options) for (let n of e.options) t.appendChild(this.createOption(n));
1704
+ return t;
1705
+ }
1706
+ createOption(e) {
1707
+ let t = document.createElement("option");
1708
+ 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), t.hidden = !e.display, e.placeholder && t.setAttribute("data-placeholder", "true"), e.mandatory && t.setAttribute("data-mandatory", "true"), e.class && e.class.split(" ").forEach((e) => {
1709
+ t.classList.add(e);
1710
+ }), e.data && typeof e.data == "object" && Object.keys(e.data).forEach((n) => {
1711
+ t.setAttribute("data-" + E(n), e.data[n]);
1712
+ }), t;
1713
+ }
1714
+ setupLabelHandlers() {
1715
+ let e = [], t = this.select.id;
1716
+ t && document.querySelectorAll(`label[for="${t}"]`).forEach((t) => e.push(t));
1717
+ let n = this.select.parentElement;
1718
+ for (; n && n !== document.body;) {
1719
+ if (n.tagName === "LABEL") {
1720
+ e.push(n);
1721
+ break;
1722
+ }
1723
+ n = n.parentElement;
1724
+ }
1725
+ Array.from(new Set(e)).forEach((e) => {
1726
+ if (e.__slimSelectLabelHandler) return;
1727
+ let t = (e) => {
1728
+ let t = e.target, n = g(t, this.select.dataset.id);
1729
+ e.preventDefault(), !n && this.onLabelClick && this.onLabelClick();
1730
+ };
1731
+ e.__slimSelectLabelHandler = t, e.addEventListener("click", t, {
1732
+ capture: !0,
1733
+ passive: !1
1734
+ });
1735
+ });
1736
+ }
1737
+ removeLabelHandlers() {
1738
+ let e = [], t = this.select.id;
1739
+ t && document.querySelectorAll(`label[for="${t}"]`).forEach((t) => e.push(t));
1740
+ let n = this.select.parentElement;
1741
+ for (; n && n !== document.body;) {
1742
+ if (n.tagName === "LABEL") {
1743
+ e.push(n);
1744
+ break;
1745
+ }
1746
+ n = n.parentElement;
1747
+ }
1748
+ Array.from(new Set(e)).forEach((e) => {
1749
+ let t = e.__slimSelectLabelHandler;
1750
+ t && (e.removeEventListener("click", t, { capture: !0 }), delete e.__slimSelectLabelHandler);
1751
+ });
1752
+ }
1753
+ destroy() {
1754
+ 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();
1755
+ }
1756
+ };
1757
+ // src/slim-select/sync.ts
1758
+ function L(e, t) {
1759
+ return T(e.getData(!1), t);
1760
+ }
1761
+ function R(e, t) {
1762
+ let n = Array.isArray(t) ? t : [t], r = e.getDataOptions(!1), i = [];
1763
+ for (let e of n) if (r.find((t) => t.id == e)) i.push(e);
1764
+ else for (let t of r.filter((t) => t.value == e)) i.push(t.id);
1765
+ return i;
1766
+ }
1767
+ var z = class {
1768
+ deps;
1769
+ queue = [];
1770
+ flushScheduled = !1;
1771
+ isSyncing = !1;
1772
+ constructor(e) {
1773
+ this.deps = e;
1774
+ }
1775
+ enqueue(e) {
1776
+ this.queue.push(e), e.source === "native" ? this.flushScheduled || (this.flushScheduled = !0, queueMicrotask(() => this.flush())) : this.isSyncing || this.flush();
1777
+ }
1778
+ flush() {
1779
+ if (this.flushScheduled = !1, this.queue.length === 0) return;
1780
+ let e = this.coalesceBatch(this.queue);
1781
+ this.queue = [], this.isSyncing = !0;
1782
+ try {
1783
+ for (let t of e) this.applyChange(t);
1784
+ } finally {
1785
+ this.isSyncing = !1, this.queue.length > 0 && this.flush();
1786
+ }
1787
+ }
1788
+ coalesceBatch(e) {
1789
+ let t = e.some((e) => e.type === "structure"), n = e.some((e) => e.type === "addOption");
1790
+ if (t || n) {
1791
+ let t = e.filter((e) => e.type === "structure" || e.type === "addOption"), n = t[t.length - 1];
1792
+ return n?.type === "structure" ? [n] : t;
1793
+ }
1794
+ let r = e.filter((e) => e.type === "selection");
1795
+ return r.length > 0 ? [r[r.length - 1]] : e;
1796
+ }
1797
+ applyChange(e) {
1798
+ switch (e.type) {
1799
+ case "structure":
1800
+ this.applyStructure(e.data, e.source, e.preserveSelection, e.isSearchResult);
1801
+ break;
1802
+ case "selection":
1803
+ this.applySelection(e.values, e.source, e.runAfterChange !== !1);
1804
+ break;
1805
+ case "addOption": this.applyAddOption(e.option);
1806
+ }
1807
+ }
1808
+ applyStructure(e, t, n = !1, r = !1) {
1809
+ let { store: i, select: a, render: o, events: s } = this.deps;
1810
+ if (!r && L(i, e)) return;
1811
+ let c = i.getSelected(), l = i.validateDataArray(e);
1812
+ if (l) {
1813
+ s.error ? s.error(l) : this.deps.onError && this.deps.onError(l);
1814
+ return;
1815
+ }
1816
+ i.setData(e, n);
1817
+ let u = i.getData(!1);
1818
+ r || i.snapshotCatalog(), r || a.updateOptions(u), o.renderValues(), o.renderOptions(u), s.afterChange && !v(c, i.getSelected()) && s.afterChange(i.getSelectedOptions());
1819
+ }
1820
+ syncNativeSelection() {
1821
+ let { store: e, select: t } = this.deps, n = e.getSelectedOptions(), r = e.getSelectedValues();
1822
+ if (!t.hasOptionValues(r)) {
1823
+ if (n.length > 0) {
1824
+ t.updateOptions(n);
1825
+ return;
1826
+ }
1827
+ let r = e.getCatalogData().find((e) => e instanceof A && e.placeholder === !0);
1828
+ if (r) {
1829
+ t.updateOptions([new A({
1830
+ ...r,
1831
+ selected: !0
1832
+ })]);
1833
+ return;
1834
+ }
1835
+ }
1836
+ t.setSelectedByValue(r);
1837
+ }
1838
+ applySelection(e, t, n) {
1839
+ let { store: r, select: i, render: a, events: o } = this.deps, s = r.getSelected(), c = R(r, e);
1840
+ if (v(s, c)) return;
1841
+ r.setSelectedBy("id", c), this.syncNativeSelection(), a.renderValues();
1842
+ let l = a.content.search.input.value.trim();
1843
+ 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());
1844
+ }
1845
+ applyAddOption(e) {
1846
+ let { store: t, select: n, render: r, events: i } = this.deps, a = t.getSelected(), o = r.content.search.input.value.trim() !== "" && !!i.search, s = e.value ?? e.text ?? "", c = (e) => {
1847
+ for (let t of e) if (t instanceof j) {
1848
+ if (t.options.some((e) => (e.value ?? e.text) === s)) return !0;
1849
+ } else if ((t.value ?? t.text) === s) return !0;
1850
+ return !1;
1851
+ };
1852
+ if (!c(t.getData(!1))) {
1853
+ if (o) {
1854
+ let n = t.getCatalogData();
1855
+ c(n) || t.setData([...n, new A(e)], !0), t.snapshotCatalog();
1856
+ } else t.addOption(e), t.snapshotCatalog();
1857
+ }
1858
+ let l = t.getData(!1);
1859
+ if (o) {
1860
+ let e = t.getSelectedOptions();
1861
+ e.length > 0 && n.updateOptions(e);
1862
+ } else n.updateOptions(l);
1863
+ r.renderValues(), r.renderOptions(l), i.afterChange && !v(a, t.getSelected()) && i.afterChange(t.getSelectedOptions());
1864
+ }
1865
+ }, B = class {
1866
+ selectEl;
1867
+ settings;
1868
+ cssClasses;
1869
+ select;
1870
+ store;
1871
+ render;
1872
+ sync;
1873
+ lifecycle;
1874
+ globalEvents;
1875
+ searchGeneration = 0;
1876
+ events = {
1877
+ search: void 0,
1878
+ searchFilter: (e, t) => e.text.toLowerCase().indexOf(t.toLowerCase()) !== -1,
1879
+ addable: void 0,
1880
+ beforeChange: void 0,
1881
+ afterChange: void 0,
1882
+ beforeOpen: void 0,
1883
+ afterOpen: void 0,
1884
+ beforeClose: void 0,
1885
+ afterClose: void 0
1886
+ };
1887
+ constructor(t) {
1888
+ if (this.selectEl = typeof t.select == "string" ? document.querySelector(t.select) : t.select, !this.selectEl) {
1889
+ t.events && t.events.error && t.events.error(/* @__PURE__ */ Error("Could not find select element"));
1890
+ return;
1891
+ }
1892
+ if (this.selectEl.tagName !== "SELECT") {
1893
+ t.events && t.events.error && t.events.error(/* @__PURE__ */ Error("Element isnt of type select"));
1894
+ return;
1895
+ }
1896
+ this.selectEl.dataset.ssid && this.destroy(), this.settings = new d(t.settings), t.settings?.selectAll === void 0 && this.selectEl.dataset.selectall === "true" && (this.settings.selectAll = !0), this.cssClasses = new e(t.cssClasses);
1897
+ let n = [
1898
+ "beforeOpen",
1899
+ "afterOpen",
1900
+ "afterClose"
1901
+ ];
1902
+ 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));
1903
+ 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 I(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) => {
1904
+ this.settings.class = e, this.render.updateClassStyles();
1905
+ }, this.select.onTitleChange = (e) => {
1906
+ this.render.updateTitle(e);
1907
+ }, this.select.onDisabledChange = (e) => {
1908
+ e ? this.disable() : this.enable();
1909
+ }, this.select.onLabelClick = () => {
1910
+ this.settings.disabled || (this.settings.isOpen ? this.close({
1911
+ source: "toggle",
1912
+ selectionChanged: !1
1913
+ }) : this.open());
1914
+ };
1915
+ let r = t.data ? t.data : this.select.getData();
1916
+ this.store = new M(this.settings.isMultiple ? "multiple" : "single", r), t.data && this.select.updateOptions(this.store.getData());
1917
+ let i = {
1918
+ open: this.open.bind(this),
1919
+ close: this.close.bind(this),
1920
+ addable: this.events.addable ? this.events.addable : void 0,
1921
+ setSelected: (e, t) => {
1922
+ this.sync.enqueue({
1923
+ type: "selection",
1924
+ values: e,
1925
+ source: "ui",
1926
+ runAfterChange: t
1927
+ });
1928
+ },
1929
+ addOption: (e) => {
1930
+ this.sync.enqueue({
1931
+ type: "addOption",
1932
+ option: e,
1933
+ source: "ui"
1934
+ });
1935
+ },
1936
+ search: this.search.bind(this),
1937
+ clearSearch: this.clearSearch.bind(this),
1938
+ beforeChange: this.events.beforeChange,
1939
+ afterChange: this.events.afterChange
1940
+ };
1941
+ this.settings.modalTitle = t.settings?.modalTitle ?? m(this.selectEl), this.render = new P(this.settings, this.cssClasses, this.store, i), this.settings.timeoutDelay = a(this.render.content.main, t.settings?.timeoutDelay), this.sync = new z({
1942
+ select: this.select,
1943
+ store: this.store,
1944
+ render: this.render,
1945
+ events: this.events,
1946
+ search: this.search.bind(this)
1947
+ }), this.select.onValueChange = (e) => {
1948
+ this.sync.enqueue({
1949
+ type: "selection",
1950
+ values: e.map((e) => e.id || e.value),
1951
+ source: "native"
1952
+ });
1953
+ }, this.select.onOptionsChange = (e) => {
1954
+ this.sync.enqueue({
1955
+ type: "structure",
1956
+ data: e || [],
1957
+ source: "native"
1958
+ });
1959
+ }, this.lifecycle = new k({
1960
+ beforeOpen: this.events.beforeOpen,
1961
+ afterOpen: this.events.afterOpen,
1962
+ beforeClose: (e) => this.events.beforeClose?.(e),
1963
+ onClose: (e) => this.applyClose(e),
1964
+ afterClose: () => {
1965
+ this.render.clearDirectionClasses(), this.render.finalizeModalClose(), this.events.afterClose && this.events.afterClose();
1966
+ },
1967
+ onOpenReady: () => this.globalEvents.attachDocumentClick(),
1968
+ onCloseReady: () => this.globalEvents.detachDocumentClick()
1969
+ }, {
1970
+ timeoutDelay: this.settings.timeoutDelay,
1971
+ waitForAnimation: (e, t) => this.render.waitForAnimation(e, t)
1972
+ }), this.globalEvents = new O({
1973
+ onDocumentClick: this.documentClick.bind(this),
1974
+ onWindowResize: () => {
1975
+ (this.settings.isOpen || this.settings.isFullOpen) && this.render.moveContent();
1976
+ },
1977
+ onWindowScroll: () => {
1978
+ (this.settings.isOpen || this.settings.isFullOpen) && this.render.moveContent();
1979
+ },
1980
+ onVisibilityChange: () => {
1981
+ document.hidden && this.close({
1982
+ source: "api",
1983
+ selectionChanged: !1
1984
+ });
1985
+ }
1986
+ }), this.render.renderValues(), this.render.renderOptions(this.store.getData(!1));
1987
+ let o = this.selectEl.getAttribute("aria-label"), s = this.selectEl.getAttribute("aria-labelledby");
1988
+ if (o) this.render.main.main.setAttribute("aria-label", o);
1989
+ else if (s) this.render.main.main.removeAttribute("aria-label"), this.render.main.main.setAttribute("aria-labelledby", s);
1990
+ else if (this.selectEl.labels && this.selectEl.labels.length > 0) {
1991
+ let e = Array.from(this.selectEl.labels).map((e, t) => (e.id ||= `${this.settings.id}-label-${t}`, e.id));
1992
+ this.render.main.main.removeAttribute("aria-label"), this.render.main.main.setAttribute("aria-labelledby", e.join(" "));
1993
+ }
1994
+ this.render.updateTitle(this.selectEl.getAttribute("title")), 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;
1995
+ }
1996
+ enable() {
1997
+ this.settings.disabled = !1, this.select.enable(), this.render.enable();
1998
+ }
1999
+ disable() {
2000
+ this.settings.disabled = !0, this.select.disable(), this.render.disable();
2001
+ }
2002
+ getData() {
2003
+ return this.store.getData();
2004
+ }
2005
+ setData(e) {
2006
+ this.sync.enqueue({
2007
+ type: "structure",
2008
+ data: e,
2009
+ source: "api"
2010
+ });
2011
+ }
2012
+ getSelected() {
2013
+ let e = this.store.getSelectedOptions();
2014
+ return this.settings.keepOrder && (e = this.store.selectedOrderOptions(e)), e.map((e) => e.value);
2015
+ }
2016
+ setSelected(e, t = !0) {
2017
+ this.sync.enqueue({
2018
+ type: "selection",
2019
+ values: e,
2020
+ source: "api",
2021
+ runAfterChange: t
2022
+ });
2023
+ }
2024
+ addOption(e) {
2025
+ this.sync.enqueue({
2026
+ type: "addOption",
2027
+ option: e,
2028
+ source: "api"
2029
+ });
2030
+ }
2031
+ open() {
2032
+ if (this.settings.disabled || this.settings.isOpen) return;
2033
+ this.lifecycle.cancelPending(), this.render.open(), this.settings.showSearch && this.settings.focusSearch && this.render.searchFocus(), this.settings.isOpen = !0, this.lifecycle.requestOpen().then(() => {
2034
+ this.settings.isOpen && (this.settings.isFullOpen = this.lifecycle.isFullOpen, this.settings.isOpen = this.lifecycle.isOpen);
2035
+ }), this.settings.contentPosition === "absolute" && !this.render.isModalViewActive() && this.render.startPositionTracking();
2036
+ let e = this.render.content.search.input.value.trim();
2037
+ e !== "" && this.search(e);
2038
+ }
2039
+ close(e = {
2040
+ source: "api",
2041
+ selectionChanged: !1
2042
+ }) {
2043
+ this.settings.isOpen && !this.settings.alwaysOpen && this.lifecycle.requestClose(e).then((e) => {
2044
+ e && (this.settings.isOpen || (this.settings.isOpen = this.lifecycle.isOpen, this.settings.isFullOpen = this.lifecycle.isFullOpen));
2045
+ });
2046
+ }
2047
+ applyClose(e) {
2048
+ this.render.close(), !this.settings.keepSearch && this.render.content.search.input.value !== "" && (this.sync.flush(), this.clearSearch());
2049
+ let t = e.source === "outside" || e.source === "toggle";
2050
+ this.render.mainFocus(t ? "click" : null), this.settings.isOpen = !1, this.settings.isFullOpen = !1, this.render.stopPositionTracking();
2051
+ }
2052
+ search(e) {
2053
+ let t = e.trim();
2054
+ t === "" ? this.render.content.search.input.value = "" : this.render.content.search.input.value !== e && (this.render.content.search.input.value = e), this.events.search ? this.runApiSearch(t) : t === "" ? this.clearSearch() : this.runLocalSearch(t);
2055
+ }
2056
+ clearSearch() {
2057
+ this.render.content.search.input.value = "", this.searchGeneration++, !this.events.search && this.render.canFilterOptionsInPlace() ? (this.render.filterOptionsInPlace("", this.events.searchFilter), this.render.resetSearchFilterState()) : (this.render.resetSearchFilterState(), this.sync.enqueue({
2058
+ type: "structure",
2059
+ data: this.store.getCatalogData(),
2060
+ source: "api",
2061
+ preserveSelection: !0
2062
+ }));
2063
+ }
2064
+ runLocalSearch(e) {
2065
+ if (this.render.canFilterOptionsInPlace()) {
2066
+ this.render.filterOptionsInPlace(e, this.events.searchFilter);
2067
+ return;
2068
+ }
2069
+ let t = this.store.search(e, this.events.searchFilter);
2070
+ this.render.renderOptions(t);
2071
+ }
2072
+ runApiSearch(e) {
2073
+ let t = ++this.searchGeneration;
2074
+ this.render.renderSearching();
2075
+ let n = this.events.search(e, this.store.getSelectedOptions(), this.store.getCatalogData()), r = (n) => {
2076
+ t === this.searchGeneration && this.render.content.search.input.value.trim() === e && this.sync.enqueue({
2077
+ type: "structure",
2078
+ data: n,
2079
+ source: "api",
2080
+ preserveSelection: !0,
2081
+ isSearchResult: !0
2082
+ });
2083
+ };
2084
+ n instanceof Promise ? n.then(r).catch((e) => {
2085
+ t === this.searchGeneration && this.render.renderError(typeof e == "string" ? e : e.message);
2086
+ }) : Array.isArray(n) ? r(n) : this.render.renderError("Search event must return a promise or an array of data");
2087
+ }
2088
+ destroy() {
2089
+ this.lifecycle.destroy(), this.render.stopPositionTracking(), this.globalEvents.detach({ listenScroll: this.settings.openPosition === "auto" }), this.store.setData([]), this.render.destroy(), this.select.destroy(), delete this.selectEl.slim;
2090
+ }
2091
+ documentClick(e) {
2092
+ this.settings.isOpen && e.target && !g(e.target, this.settings.id) && this.close({
2093
+ source: "outside",
2094
+ selectionChanged: !1
2095
+ });
2096
+ }
2097
+ };
2098
+ export { u as MODAL_MOBILE_BREAKPOINT, j as Optgroup, A as Option, d as Settings, B as default };
2099
+
2100
+ //# sourceMappingURL=slimselect.es.js.map