slim-select 4.0.0 → 4.0.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.
- package/README.md +0 -1
- package/dist/vue/helpers.d.ts +2 -0
- package/dist/vue/index.js +154 -132
- package/dist/vue/index.umd.js +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -11,7 +11,6 @@ Vue and React wrappers.
|
|
|
11
11
|
[](https://www.npmjs.com/package/slim-select)
|
|
12
12
|

|
|
13
13
|

|
|
14
|
-
[](https://snyk.io/advisor/npm-package/slim-select)
|
|
15
14
|
|
|
16
15
|

|
|
17
16
|
|
package/dist/vue/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { createElementBlock as e, defineComponent as t,
|
|
1
|
+
import { createElementBlock as e, defineComponent as t, isReactive as n, isRef as r, openBlock as i, toRaw as a, unref as o } from "vue";
|
|
2
2
|
//#region src/slim-select/classes.ts
|
|
3
|
-
var
|
|
3
|
+
var s = class {
|
|
4
4
|
main;
|
|
5
5
|
placeholder;
|
|
6
6
|
values;
|
|
@@ -57,8 +57,8 @@ var i = class {
|
|
|
57
57
|
getFirst(e) {
|
|
58
58
|
return this[e].split(" ")[0];
|
|
59
59
|
}
|
|
60
|
-
},
|
|
61
|
-
function
|
|
60
|
+
}, c = 200, l = ["transform", "opacity"];
|
|
61
|
+
function u(e, t = c) {
|
|
62
62
|
let n = e.trim();
|
|
63
63
|
if (!n) return t;
|
|
64
64
|
if (n.endsWith("ms")) {
|
|
@@ -72,22 +72,22 @@ function s(e, t = a) {
|
|
|
72
72
|
let r = parseFloat(n);
|
|
73
73
|
return Number.isNaN(r) ? t : r;
|
|
74
74
|
}
|
|
75
|
-
function
|
|
76
|
-
return
|
|
75
|
+
function d(e, t = c) {
|
|
76
|
+
return u(getComputedStyle(e).getPropertyValue("--ss-animation-timing").trim(), t);
|
|
77
77
|
}
|
|
78
|
-
function
|
|
79
|
-
let r =
|
|
78
|
+
function f(e, t, n = c) {
|
|
79
|
+
let r = d(e, n) + 50;
|
|
80
80
|
return t === void 0 ? r : Math.max(r, t);
|
|
81
81
|
}
|
|
82
|
-
function
|
|
82
|
+
function p() {
|
|
83
83
|
return typeof window > "u" || typeof window.matchMedia != "function" ? !1 : window.matchMedia("(prefers-reduced-motion: reduce)").matches;
|
|
84
84
|
}
|
|
85
|
-
function
|
|
85
|
+
function m(e) {
|
|
86
86
|
return e === void 0 ? null : new Set(Array.isArray(e) ? e : [e]);
|
|
87
87
|
}
|
|
88
|
-
function
|
|
89
|
-
if (
|
|
90
|
-
let i =
|
|
88
|
+
function h(e, t, n = c, r) {
|
|
89
|
+
if (p() || r?.aborted) return Promise.resolve();
|
|
90
|
+
let i = m(t);
|
|
91
91
|
return new Promise((t) => {
|
|
92
92
|
let a = null, o = !1, s = () => {
|
|
93
93
|
o || (o = !0, e.removeEventListener("transitionend", l), r?.removeEventListener("abort", c), a && clearTimeout(a), t());
|
|
@@ -97,8 +97,8 @@ function f(e, t, n = a, r) {
|
|
|
97
97
|
r?.addEventListener("abort", c, { once: !0 }), e.addEventListener("transitionend", l), a = setTimeout(s, n);
|
|
98
98
|
});
|
|
99
99
|
}
|
|
100
|
-
function
|
|
101
|
-
return
|
|
100
|
+
function g(e, t, n = c, r) {
|
|
101
|
+
return p() || r?.aborted ? Promise.resolve() : new Promise((i) => {
|
|
102
102
|
let a = null, o = !1, s = () => {
|
|
103
103
|
o || (o = !0, e.removeEventListener("animationend", l), r?.removeEventListener("abort", c), a && clearTimeout(a), i());
|
|
104
104
|
}, c = () => s(), l = (n) => {
|
|
@@ -109,7 +109,7 @@ function p(e, t, n = a, r) {
|
|
|
109
109
|
}
|
|
110
110
|
//#endregion
|
|
111
111
|
//#region src/slim-select/settings.ts
|
|
112
|
-
var
|
|
112
|
+
var _ = class {
|
|
113
113
|
id = "";
|
|
114
114
|
style = "";
|
|
115
115
|
class = [];
|
|
@@ -149,12 +149,12 @@ var m = class {
|
|
|
149
149
|
modal;
|
|
150
150
|
modalTitle;
|
|
151
151
|
constructor(e) {
|
|
152
|
-
e ||= {}, this.id = "ss-" +
|
|
152
|
+
e ||= {}, this.id = "ss-" + x(), this.style = e.style || "", this.class = e.class || [], this.disabled = e.disabled === void 0 ? !1 : e.disabled, this.alwaysOpen = e.alwaysOpen === void 0 ? !1 : e.alwaysOpen, this.showSearch = e.showSearch === void 0 ? !0 : e.showSearch, this.focusSearch = e.focusSearch === void 0 ? !0 : e.focusSearch, this.keepSearch = e.keepSearch === void 0 ? !1 : e.keepSearch, this.ariaLabel = e.ariaLabel || "Combobox", this.searchPlaceholder = e.searchPlaceholder || "Search...", this.searchText = e.searchText || "No Results", this.searchingText = e.searchingText || "Searching...", this.resultsText = e.resultsText || "{count} results available", this.deselectText = e.deselectText || "Clear", this.removeText = e.removeText || "Remove", this.searchHighlight = e.searchHighlight === void 0 ? !1 : e.searchHighlight, this.closeOnSelect = e.closeOnSelect === void 0 ? !0 : e.closeOnSelect, this.contentLocation = e.contentLocation || document.body, this.contentPosition = e.contentPosition || "absolute", this.contentWidth = e.contentWidth || "", this.openPosition = e.openPosition || "auto", this.placeholderText = e.placeholderText === void 0 ? "Select Value" : e.placeholderText, this.allowDeselect = e.allowDeselect === void 0 ? !1 : e.allowDeselect, this.hideSelected = e.hideSelected === void 0 ? !1 : e.hideSelected, this.multiString = e.multiString === void 0 ? !1 : e.multiString, this.keepOrder = e.keepOrder === void 0 ? !1 : e.keepOrder, this.showOptionTooltips = e.showOptionTooltips === void 0 ? !1 : e.showOptionTooltips, this.minSelected = e.minSelected || 0, this.maxSelected = e.maxSelected || 1e3, this.timeoutDelay = e.timeoutDelay || 200, this.maxValuesShown = e.maxValuesShown || 20, this.maxValuesMessage = e.maxValuesMessage || "{number} selected", this.addableText = e.addableText || "Press \"Enter\" to add {value}", this.modal = e.modal || "mobile", this.modalTitle = e.modalTitle || "";
|
|
153
153
|
}
|
|
154
154
|
};
|
|
155
155
|
//#endregion
|
|
156
156
|
//#region src/slim-select/helpers.ts
|
|
157
|
-
function
|
|
157
|
+
function v(e) {
|
|
158
158
|
if (!e) return {};
|
|
159
159
|
let t = {};
|
|
160
160
|
for (let n of Object.keys(e)) {
|
|
@@ -163,21 +163,21 @@ function h(e) {
|
|
|
163
163
|
}
|
|
164
164
|
return t;
|
|
165
165
|
}
|
|
166
|
-
function
|
|
166
|
+
function y(e) {
|
|
167
167
|
let t = e.cloneNode(!0);
|
|
168
168
|
return t.querySelectorAll("select, option, optgroup, textarea, input, button").forEach((e) => e.remove()), t.textContent?.replace(/\s+/g, " ").trim() || "";
|
|
169
169
|
}
|
|
170
|
-
function
|
|
170
|
+
function b(e) {
|
|
171
171
|
if (e.labels && e.labels.length > 0) {
|
|
172
|
-
let t = Array.from(e.labels).map(
|
|
172
|
+
let t = Array.from(e.labels).map(y).filter(Boolean);
|
|
173
173
|
if (t.length > 0) return [...new Set(t)].join(" ");
|
|
174
174
|
}
|
|
175
175
|
return e.getAttribute("aria-label")?.trim() || "";
|
|
176
176
|
}
|
|
177
|
-
function
|
|
177
|
+
function x() {
|
|
178
178
|
return Math.random().toString(36).substring(2, 10);
|
|
179
179
|
}
|
|
180
|
-
function
|
|
180
|
+
function S(e, t) {
|
|
181
181
|
function n(e, n) {
|
|
182
182
|
return n && e && e.classList && e.classList.contains(n) || n && e && e.dataset && e.dataset.id && e.dataset.id === t ? e : null;
|
|
183
183
|
}
|
|
@@ -186,7 +186,7 @@ function y(e, t) {
|
|
|
186
186
|
}
|
|
187
187
|
return n(e, t) || r(e, t);
|
|
188
188
|
}
|
|
189
|
-
function
|
|
189
|
+
function C(e, t = 50, n = !1) {
|
|
190
190
|
let r;
|
|
191
191
|
return function(...i) {
|
|
192
192
|
let a = self, o = () => {
|
|
@@ -195,12 +195,12 @@ function b(e, t = 50, n = !1) {
|
|
|
195
195
|
clearTimeout(r), r = setTimeout(o, t), s && e.apply(a, i);
|
|
196
196
|
};
|
|
197
197
|
}
|
|
198
|
-
function
|
|
198
|
+
function w(e, t) {
|
|
199
199
|
if (e.length !== t.length) return !1;
|
|
200
200
|
let n = [...e].sort(), r = [...t].sort();
|
|
201
201
|
return n.every((e, t) => e === r[t]);
|
|
202
202
|
}
|
|
203
|
-
var
|
|
203
|
+
var T = [
|
|
204
204
|
"id",
|
|
205
205
|
"value",
|
|
206
206
|
"text",
|
|
@@ -214,13 +214,13 @@ var S = [
|
|
|
214
214
|
"style",
|
|
215
215
|
"mandatory"
|
|
216
216
|
];
|
|
217
|
-
function
|
|
217
|
+
function E(e, t) {
|
|
218
218
|
let n = Object.keys(e), r = Object.keys(t);
|
|
219
219
|
if (n.length !== r.length) return !1;
|
|
220
220
|
for (let r of n) if (e[r] !== t[r]) return !1;
|
|
221
221
|
return !0;
|
|
222
222
|
}
|
|
223
|
-
function
|
|
223
|
+
function D(e, t) {
|
|
224
224
|
switch (t) {
|
|
225
225
|
case "id": return e.id || "";
|
|
226
226
|
case "value": return e.value === void 0 ? e.text || "" : e.value || "";
|
|
@@ -237,14 +237,14 @@ function w(e, t) {
|
|
|
237
237
|
default: return e.data || {};
|
|
238
238
|
}
|
|
239
239
|
}
|
|
240
|
-
function
|
|
240
|
+
function O(e) {
|
|
241
241
|
return !!e && typeof e == "object" && "label" in e && "options" in e;
|
|
242
242
|
}
|
|
243
|
-
function
|
|
244
|
-
for (let n of
|
|
245
|
-
return
|
|
243
|
+
function k(e, t) {
|
|
244
|
+
for (let n of T) if (D(e, n) !== D(t, n)) return !1;
|
|
245
|
+
return E(e.data || {}, t.data || {});
|
|
246
246
|
}
|
|
247
|
-
function
|
|
247
|
+
function A(e, t) {
|
|
248
248
|
let n = (e) => ({
|
|
249
249
|
id: e.id || "",
|
|
250
250
|
label: e.label || "",
|
|
@@ -254,33 +254,33 @@ function D(e, t) {
|
|
|
254
254
|
if (r.id !== i.id || r.label !== i.label || r.selectAll !== i.selectAll || r.closable !== i.closable) return !1;
|
|
255
255
|
let a = e.options || [], o = t.options || [];
|
|
256
256
|
if (a.length !== o.length) return !1;
|
|
257
|
-
for (let e = 0; e < a.length; e++) if (!
|
|
257
|
+
for (let e = 0; e < a.length; e++) if (!k(a[e], o[e])) return !1;
|
|
258
258
|
return !0;
|
|
259
259
|
}
|
|
260
|
-
function
|
|
260
|
+
function j(e, t) {
|
|
261
261
|
if (e === t) return !0;
|
|
262
262
|
if (e.length !== t.length) return !1;
|
|
263
263
|
for (let n = 0; n < e.length; n++) {
|
|
264
|
-
let r = e[n], i = t[n], a =
|
|
265
|
-
if (a !==
|
|
264
|
+
let r = e[n], i = t[n], a = O(r);
|
|
265
|
+
if (a !== O(i)) return !1;
|
|
266
266
|
if (a) {
|
|
267
|
-
if (!
|
|
267
|
+
if (!A(r, i)) return !1;
|
|
268
268
|
continue;
|
|
269
269
|
}
|
|
270
|
-
if (!
|
|
270
|
+
if (!k(r, i)) return !1;
|
|
271
271
|
}
|
|
272
272
|
return !0;
|
|
273
273
|
}
|
|
274
|
-
function
|
|
274
|
+
function M(e) {
|
|
275
275
|
let t = e.replace(/[A-Z\u00C0-\u00D6\u00D8-\u00DE]/g, (e) => "-" + e.toLowerCase());
|
|
276
276
|
return e[0] === e[0].toUpperCase() ? t.substring(1) : t;
|
|
277
277
|
}
|
|
278
|
-
function
|
|
278
|
+
function N(e, t = typeof window < "u" ? window.innerWidth : 768) {
|
|
279
279
|
return e === "on" ? !0 : e === "mobile" ? t < 768 : !1;
|
|
280
280
|
}
|
|
281
281
|
//#endregion
|
|
282
282
|
//#region src/slim-select/events.ts
|
|
283
|
-
var
|
|
283
|
+
var P = class {
|
|
284
284
|
handlers;
|
|
285
285
|
attached = !1;
|
|
286
286
|
constructor(e) {
|
|
@@ -298,16 +298,16 @@ var j = class {
|
|
|
298
298
|
detach(e) {
|
|
299
299
|
this.attached && (this.attached = !1, this.detachDocumentClick(), window.removeEventListener("resize", this.resizeHandler, !1), e.listenScroll && window.removeEventListener("scroll", this.scrollHandler, !1), document.removeEventListener("visibilitychange", this.visibilityHandler));
|
|
300
300
|
}
|
|
301
|
-
resizeHandler =
|
|
301
|
+
resizeHandler = C(() => {
|
|
302
302
|
this.handlers.onWindowResize();
|
|
303
303
|
});
|
|
304
|
-
scrollHandler =
|
|
304
|
+
scrollHandler = C(() => {
|
|
305
305
|
this.handlers.onWindowScroll();
|
|
306
306
|
});
|
|
307
307
|
visibilityHandler = () => {
|
|
308
308
|
this.handlers.onVisibilityChange();
|
|
309
309
|
};
|
|
310
|
-
},
|
|
310
|
+
}, F = class {
|
|
311
311
|
handlers;
|
|
312
312
|
options;
|
|
313
313
|
state = "closed";
|
|
@@ -368,7 +368,7 @@ var j = class {
|
|
|
368
368
|
this.generation;
|
|
369
369
|
});
|
|
370
370
|
}
|
|
371
|
-
},
|
|
371
|
+
}, I = class {
|
|
372
372
|
id;
|
|
373
373
|
value;
|
|
374
374
|
text;
|
|
@@ -383,18 +383,18 @@ var j = class {
|
|
|
383
383
|
data;
|
|
384
384
|
mandatory;
|
|
385
385
|
constructor(e) {
|
|
386
|
-
this.id = !e.id || e.id === "" ?
|
|
386
|
+
this.id = !e.id || e.id === "" ? x() : e.id, this.value = e.value === void 0 ? e.text || "" : e.value || "", this.text = e.text || "", this.html = e.html || "", this.defaultSelected = e.defaultSelected === void 0 ? !1 : e.defaultSelected, this.selected = e.selected === void 0 ? !1 : e.selected, this.display = e.display === void 0 ? !0 : e.display, this.disabled = e.disabled === void 0 ? !1 : e.disabled, this.mandatory = e.mandatory === void 0 ? !1 : e.mandatory, this.placeholder = e.placeholder === void 0 ? !1 : e.placeholder, this.class = e.class || "", this.style = e.style || "", this.data = v(e.data);
|
|
387
387
|
}
|
|
388
|
-
},
|
|
388
|
+
}, L = class {
|
|
389
389
|
id;
|
|
390
390
|
label;
|
|
391
391
|
selectAll;
|
|
392
392
|
closable;
|
|
393
393
|
options;
|
|
394
394
|
constructor(e) {
|
|
395
|
-
if (this.id = !e.id || e.id === "" ?
|
|
395
|
+
if (this.id = !e.id || e.id === "" ? x() : e.id, this.label = e.label || "", this.selectAll = e.selectAll === void 0 ? !1 : e.selectAll, this.closable = e.closable || "off", this.options = [], e.options) for (let t of e.options) this.options.push(new I(t));
|
|
396
396
|
}
|
|
397
|
-
},
|
|
397
|
+
}, R = class {
|
|
398
398
|
selectType = "single";
|
|
399
399
|
data = [];
|
|
400
400
|
selectedOrder = [];
|
|
@@ -404,13 +404,13 @@ var j = class {
|
|
|
404
404
|
}
|
|
405
405
|
validateDataArray(e) {
|
|
406
406
|
if (!Array.isArray(e)) return /* @__PURE__ */ Error("Data must be an array");
|
|
407
|
-
for (let t of e) if (t) if (t instanceof
|
|
407
|
+
for (let t of e) if (t) if (t instanceof L || "label" in t) {
|
|
408
408
|
if (!("label" in t)) return /* @__PURE__ */ Error("Optgroup must have a label");
|
|
409
409
|
if ("options" in t && t.options) for (let e of t.options) {
|
|
410
410
|
let t = this.validateOption(e);
|
|
411
411
|
if (t) return t;
|
|
412
412
|
}
|
|
413
|
-
} else if (t instanceof
|
|
413
|
+
} else if (t instanceof I || "text" in t) {
|
|
414
414
|
let e = this.validateOption(t);
|
|
415
415
|
if (e) return e;
|
|
416
416
|
} else return /* @__PURE__ */ Error("Data object must be a valid optgroup or option");
|
|
@@ -423,13 +423,13 @@ var j = class {
|
|
|
423
423
|
let t = [];
|
|
424
424
|
return e.forEach((e) => {
|
|
425
425
|
if (e) {
|
|
426
|
-
if (e instanceof
|
|
426
|
+
if (e instanceof L || "label" in e) {
|
|
427
427
|
let n = [];
|
|
428
428
|
"options" in e && e.options && e.options.forEach((e) => {
|
|
429
|
-
n.push(new
|
|
430
|
-
}), n.length > 0 && t.push(new
|
|
429
|
+
n.push(new I(e));
|
|
430
|
+
}), n.length > 0 && t.push(new L(e));
|
|
431
431
|
}
|
|
432
|
-
(e instanceof
|
|
432
|
+
(e instanceof I || "text" in e) && t.push(new I(e));
|
|
433
433
|
}
|
|
434
434
|
}), t;
|
|
435
435
|
}
|
|
@@ -440,20 +440,20 @@ var j = class {
|
|
|
440
440
|
return this.cloneData(this.catalog ?? this.data);
|
|
441
441
|
}
|
|
442
442
|
cloneData(e) {
|
|
443
|
-
return e.map((e) => e instanceof
|
|
443
|
+
return e.map((e) => e instanceof L ? new L({
|
|
444
444
|
id: e.id,
|
|
445
445
|
label: e.label,
|
|
446
446
|
selectAll: e.selectAll,
|
|
447
447
|
closable: e.closable,
|
|
448
|
-
options: e.options.map((e) => new
|
|
449
|
-
}) : new
|
|
448
|
+
options: e.options.map((e) => new I(e instanceof I ? { ...e } : e))
|
|
449
|
+
}) : new I({ ...e }));
|
|
450
450
|
}
|
|
451
451
|
optionMatchesSelected(e, t) {
|
|
452
452
|
return e.id === t.id ? !0 : t.value !== "" && e.value !== "" && e.value === t.value;
|
|
453
453
|
}
|
|
454
454
|
findOptionInData(e, t) {
|
|
455
455
|
for (let n of e) {
|
|
456
|
-
if (n instanceof
|
|
456
|
+
if (n instanceof I) {
|
|
457
457
|
if (this.optionMatchesSelected(n, t)) return n;
|
|
458
458
|
continue;
|
|
459
459
|
}
|
|
@@ -485,19 +485,19 @@ var j = class {
|
|
|
485
485
|
}
|
|
486
486
|
addOption(e, t = !1) {
|
|
487
487
|
if (t) {
|
|
488
|
-
let t = [new
|
|
488
|
+
let t = [new I(e)];
|
|
489
489
|
this.setData(t.concat(this.getData()));
|
|
490
|
-
} else this.setData(this.getData().concat(new
|
|
490
|
+
} else this.setData(this.getData().concat(new I(e)));
|
|
491
491
|
}
|
|
492
492
|
setSelectedBy(e, t, n = !1) {
|
|
493
493
|
let r = null, i = !1, a = [];
|
|
494
494
|
for (let n of this.data) {
|
|
495
|
-
if (n instanceof
|
|
495
|
+
if (n instanceof L) for (let o of n.options) {
|
|
496
496
|
r ||= o;
|
|
497
497
|
let n = o[e] || "";
|
|
498
498
|
o.selected = i ? !1 : t.includes(n), o.selected && (a.push(o), this.selectType === "single" && (i = !0));
|
|
499
499
|
}
|
|
500
|
-
n instanceof
|
|
500
|
+
n instanceof I && (r ||= n, n.selected = i ? !1 : t.includes(n[e]), n.selected && (a.push(n), this.selectType === "single" && (i = !0)));
|
|
501
501
|
}
|
|
502
502
|
this.selectType === "single" && r && !i && !n && (r.selected = !0, a.push(r));
|
|
503
503
|
let o = t.map((t) => a.find((n) => n[e] === t)?.id || "");
|
|
@@ -511,16 +511,16 @@ var j = class {
|
|
|
511
511
|
}
|
|
512
512
|
getSelectedOptions() {
|
|
513
513
|
let e = [];
|
|
514
|
-
for (let t of this.data) if (t instanceof
|
|
514
|
+
for (let t of this.data) if (t instanceof L) for (let n of t.options) n.selected && e.push(n);
|
|
515
515
|
else t.selected && e.push(t);
|
|
516
516
|
return e;
|
|
517
517
|
}
|
|
518
518
|
getOptgroupByID(e) {
|
|
519
|
-
for (let t of this.data) if (t instanceof
|
|
519
|
+
for (let t of this.data) if (t instanceof L && t.id === e) return t;
|
|
520
520
|
return null;
|
|
521
521
|
}
|
|
522
522
|
getOptionByID(e) {
|
|
523
|
-
for (let t of this.data) if (t instanceof
|
|
523
|
+
for (let t of this.data) if (t instanceof L) {
|
|
524
524
|
for (let n of t.options) if (n.id === e) return n;
|
|
525
525
|
} else if (t.id === e) return t;
|
|
526
526
|
return null;
|
|
@@ -530,14 +530,14 @@ var j = class {
|
|
|
530
530
|
}
|
|
531
531
|
getFirstOption() {
|
|
532
532
|
let e = null;
|
|
533
|
-
for (let t of this.data) if (t instanceof
|
|
533
|
+
for (let t of this.data) if (t instanceof L ? e = t.options[0] : t instanceof I && (e = t), e) break;
|
|
534
534
|
return e;
|
|
535
535
|
}
|
|
536
536
|
search(e, t) {
|
|
537
537
|
return e = e.trim(), e === "" ? this.getData(!1) : this.filter((n) => t(n, e), !0, !1);
|
|
538
538
|
}
|
|
539
539
|
createOptgroupView(e, t) {
|
|
540
|
-
let n = new
|
|
540
|
+
let n = new L({
|
|
541
541
|
id: e.id,
|
|
542
542
|
label: e.label,
|
|
543
543
|
selectAll: e.selectAll,
|
|
@@ -549,16 +549,16 @@ var j = class {
|
|
|
549
549
|
filter(e, t, n = !0) {
|
|
550
550
|
let r = [];
|
|
551
551
|
return this.data.forEach((i) => {
|
|
552
|
-
if (i instanceof
|
|
552
|
+
if (i instanceof L) {
|
|
553
553
|
let a = [];
|
|
554
554
|
if (i.options.forEach((i) => {
|
|
555
|
-
(!e || e(i)) && (t ? a.push(n ? new
|
|
555
|
+
(!e || e(i)) && (t ? a.push(n ? new I(i) : i) : r.push(n ? new I(i) : i));
|
|
556
556
|
}), a.length > 0) if (n) {
|
|
557
|
-
let e = new
|
|
557
|
+
let e = new L(i);
|
|
558
558
|
e.options = a, r.push(e);
|
|
559
559
|
} else r.push(this.createOptgroupView(i, a));
|
|
560
560
|
}
|
|
561
|
-
i instanceof
|
|
561
|
+
i instanceof I && (!e || e(i)) && r.push(n ? new I(i) : i);
|
|
562
562
|
}), r;
|
|
563
563
|
}
|
|
564
564
|
selectedOrderOptions(e) {
|
|
@@ -576,7 +576,7 @@ var j = class {
|
|
|
576
576
|
}), n || t.push(e);
|
|
577
577
|
}), t;
|
|
578
578
|
}
|
|
579
|
-
},
|
|
579
|
+
}, z = class {
|
|
580
580
|
settings;
|
|
581
581
|
store;
|
|
582
582
|
callbacks;
|
|
@@ -630,7 +630,7 @@ var j = class {
|
|
|
630
630
|
return this.modalSessionActive === !0;
|
|
631
631
|
}
|
|
632
632
|
resolveModalView() {
|
|
633
|
-
return this.settings.alwaysOpen || this.settings.modal === "off" || !this.modalElements ? !1 : (this.modalSessionActive === null && (this.modalSessionActive =
|
|
633
|
+
return this.settings.alwaysOpen || this.settings.modal === "off" || !this.modalElements ? !1 : (this.modalSessionActive === null && (this.modalSessionActive = N(this.settings.modal)), this.modalSessionActive);
|
|
634
634
|
}
|
|
635
635
|
createModalElements() {
|
|
636
636
|
let e = document.createElement("div");
|
|
@@ -673,8 +673,8 @@ var j = class {
|
|
|
673
673
|
this.modalElements && this.content.main.parentElement === this.modalElements.dialog && (this.addClasses(this.modalElements.overlay, this.classes.hide), this.removeClasses(this.modalElements.overlay, this.classes.contentOpen), this.removeClasses(this.content.main, this.classes.modalContent), this.restoreContentOffscreen(), this.unlockBodyScroll());
|
|
674
674
|
}
|
|
675
675
|
waitForAnimation(e, t) {
|
|
676
|
-
let n =
|
|
677
|
-
return
|
|
676
|
+
let n = f(this.content.main, this.settings.timeoutDelay);
|
|
677
|
+
return h(this.content.main, l, n, t);
|
|
678
678
|
}
|
|
679
679
|
close() {
|
|
680
680
|
this.main.main.setAttribute("aria-expanded", "false"), this.main.arrow.path.setAttribute("d", this.classes.arrowClose);
|
|
@@ -811,8 +811,8 @@ var j = class {
|
|
|
811
811
|
let i = e[r], a = i.getAttribute("data-id");
|
|
812
812
|
a && (t.filter((e) => e.id === a, !1).length || n.push(i));
|
|
813
813
|
}
|
|
814
|
-
let r =
|
|
815
|
-
for (let e of n) this.addClasses(e, this.classes.valueOut),
|
|
814
|
+
let r = f(this.content.main, this.settings.timeoutDelay);
|
|
815
|
+
for (let e of n) this.addClasses(e, this.classes.valueOut), g(e, "ss-valueOut", r).then(() => {
|
|
816
816
|
this.main.values.hasChildNodes() && this.main.values.contains(e) && this.main.values.removeChild(e);
|
|
817
817
|
});
|
|
818
818
|
e = this.main.values.childNodes;
|
|
@@ -847,8 +847,8 @@ var j = class {
|
|
|
847
847
|
if (!(this.settings.minSelected && i.length < this.settings.minSelected) && (this.callbacks.beforeChange && (n = this.callbacks.beforeChange(i, r) === !0), n)) {
|
|
848
848
|
let e = [];
|
|
849
849
|
for (let t of i) {
|
|
850
|
-
if (t instanceof
|
|
851
|
-
t instanceof
|
|
850
|
+
if (t instanceof L) for (let n of t.options) n.id && e.push(n.id);
|
|
851
|
+
t instanceof I && e.push(t.id);
|
|
852
852
|
}
|
|
853
853
|
this.callbacks.setSelected(e, !1), this.settings.closeOnSelect && this.callbacks.close(), this.callbacks.afterChange && this.callbacks.afterChange(i), this.updateDeselectAll(), this.updateMultipleValueDeleteVisibility();
|
|
854
854
|
}
|
|
@@ -922,7 +922,7 @@ var j = class {
|
|
|
922
922
|
main: e,
|
|
923
923
|
input: t
|
|
924
924
|
};
|
|
925
|
-
if (this.settings.showSearch || (this.addClasses(e, this.classes.hide), t.readOnly = !0), t.type = "search", t.placeholder = this.settings.searchPlaceholder, t.tabIndex = -1, t.setAttribute("aria-label", this.settings.searchPlaceholder), t.setAttribute("aria-autocomplete", "list"), t.setAttribute("autocapitalize", "off"), t.setAttribute("autocomplete", "off"), t.setAttribute("autocorrect", "off"), t.setAttribute("aria-hidden", "true"), t.oninput =
|
|
925
|
+
if (this.settings.showSearch || (this.addClasses(e, this.classes.hide), t.readOnly = !0), t.type = "search", t.placeholder = this.settings.searchPlaceholder, t.tabIndex = -1, t.setAttribute("aria-label", this.settings.searchPlaceholder), t.setAttribute("aria-autocomplete", "list"), t.setAttribute("autocapitalize", "off"), t.setAttribute("autocomplete", "off"), t.setAttribute("autocorrect", "off"), t.setAttribute("aria-hidden", "true"), t.oninput = C((e) => {
|
|
926
926
|
this.callbacks.search(e.target.value);
|
|
927
927
|
}, 100), t.onkeydown = (e) => {
|
|
928
928
|
switch (e.key) {
|
|
@@ -951,13 +951,13 @@ var j = class {
|
|
|
951
951
|
return;
|
|
952
952
|
}
|
|
953
953
|
let n = (e) => {
|
|
954
|
-
let t = new
|
|
954
|
+
let t = new I(e);
|
|
955
955
|
if (this.callbacks.addOption(t), this.settings.isMultiple) {
|
|
956
956
|
let e = this.store.getSelected();
|
|
957
957
|
e.push(t.id), this.callbacks.setSelected(e, !0);
|
|
958
958
|
} else this.callbacks.setSelected([t.id], !0);
|
|
959
959
|
if (this.callbacks.search(""), this.settings.closeOnSelect) {
|
|
960
|
-
let e =
|
|
960
|
+
let e = d(this.content.main);
|
|
961
961
|
setTimeout(() => {
|
|
962
962
|
this.callbacks.close();
|
|
963
963
|
}, e);
|
|
@@ -1039,7 +1039,7 @@ var j = class {
|
|
|
1039
1039
|
this.addClasses(e, this.classes.searching), e.textContent = this.settings.searchingText, this.content.list.appendChild(e), this.announce(this.settings.searchingText);
|
|
1040
1040
|
}
|
|
1041
1041
|
renderOptions(e) {
|
|
1042
|
-
if (this.lastSearchFilterTerm = "", this.lastRenderedOptions = e.map((e) => e instanceof
|
|
1042
|
+
if (this.lastSearchFilterTerm = "", this.lastRenderedOptions = e.map((e) => e instanceof I ? [e] : e.options.map((e) => new I(e))).flat(), this.content.list.innerHTML = "", e.length === 0) {
|
|
1043
1043
|
this.optionsListIsFullData = !1;
|
|
1044
1044
|
let e = document.createElement("div");
|
|
1045
1045
|
if (this.addClasses(e, this.classes.search), this.callbacks.addable) {
|
|
@@ -1049,7 +1049,7 @@ var j = class {
|
|
|
1049
1049
|
this.content.list.appendChild(e);
|
|
1050
1050
|
return;
|
|
1051
1051
|
}
|
|
1052
|
-
this.settings.allowDeselect && !this.settings.isMultiple && (this.store.filter((e) => e.placeholder, !1, !1).length || this.store.addOption(new
|
|
1052
|
+
this.settings.allowDeselect && !this.settings.isMultiple && (this.store.filter((e) => e.placeholder, !1, !1).length || this.store.addOption(new I({
|
|
1053
1053
|
text: "",
|
|
1054
1054
|
value: "",
|
|
1055
1055
|
selected: !1,
|
|
@@ -1057,7 +1057,7 @@ var j = class {
|
|
|
1057
1057
|
}), !0));
|
|
1058
1058
|
let t = document.createDocumentFragment();
|
|
1059
1059
|
for (let n of e) {
|
|
1060
|
-
if (n instanceof
|
|
1060
|
+
if (n instanceof L) {
|
|
1061
1061
|
let e = document.createElement("div");
|
|
1062
1062
|
this.addClasses(e, this.classes.optgroup);
|
|
1063
1063
|
let r = document.createElement("div");
|
|
@@ -1089,7 +1089,7 @@ var j = class {
|
|
|
1089
1089
|
return;
|
|
1090
1090
|
} else {
|
|
1091
1091
|
let e = n.options.map((e) => e.id).filter((e) => e !== void 0), r = t.concat(e);
|
|
1092
|
-
for (let e of n.options) e.id && !this.store.getOptionByID(e.id) && this.callbacks.addOption(new
|
|
1092
|
+
for (let e of n.options) e.id && !this.store.getOptionByID(e.id) && this.callbacks.addOption(new I(e));
|
|
1093
1093
|
this.callbacks.setSelected(r, !0);
|
|
1094
1094
|
return;
|
|
1095
1095
|
}
|
|
@@ -1106,9 +1106,9 @@ var j = class {
|
|
|
1106
1106
|
}), a.appendChild(t);
|
|
1107
1107
|
}
|
|
1108
1108
|
e.appendChild(r);
|
|
1109
|
-
for (let r of n.options) e.appendChild(this.option(new
|
|
1109
|
+
for (let r of n.options) e.appendChild(this.option(new I(r))), t.appendChild(e);
|
|
1110
1110
|
}
|
|
1111
|
-
n instanceof
|
|
1111
|
+
n instanceof I && t.appendChild(this.option(n));
|
|
1112
1112
|
}
|
|
1113
1113
|
this.content.list.appendChild(t), this.setOptionsListFullData(e), this.announce(this.settings.resultsText.replace("{count}", String(this.lastRenderedOptions.length)));
|
|
1114
1114
|
}
|
|
@@ -1134,7 +1134,7 @@ var j = class {
|
|
|
1134
1134
|
this.lastRenderedOptions = r, this.updateOptgroupVisibilityAfterSearch(n), r.length === 0 ? this.updateSearchResultsMessage(0, n) : (this.removeListSearchMessage(), this.announce(this.settings.resultsText.replace("{count}", String(r.length)))), this.updateOptgroupSelectAllStates();
|
|
1135
1135
|
}
|
|
1136
1136
|
setOptionsListFullData(e) {
|
|
1137
|
-
let t = this.store.getDataOptions(!1), n = e.map((e) => e instanceof
|
|
1137
|
+
let t = this.store.getDataOptions(!1), n = e.map((e) => e instanceof I ? [e] : e.options.map((e) => new I(e))).flat();
|
|
1138
1138
|
if (n.length !== t.length) {
|
|
1139
1139
|
this.optionsListIsFullData = !1;
|
|
1140
1140
|
return;
|
|
@@ -1337,7 +1337,7 @@ var j = class {
|
|
|
1337
1337
|
};
|
|
1338
1338
|
//#endregion
|
|
1339
1339
|
//#region src/slim-select/mutations.ts
|
|
1340
|
-
function
|
|
1340
|
+
function B(e, t) {
|
|
1341
1341
|
let n = {
|
|
1342
1342
|
classChanged: !1,
|
|
1343
1343
|
disabledChanged: !1,
|
|
@@ -1358,7 +1358,7 @@ function L(e, t) {
|
|
|
1358
1358
|
}
|
|
1359
1359
|
//#endregion
|
|
1360
1360
|
//#region src/slim-select/select.ts
|
|
1361
|
-
var
|
|
1361
|
+
var V = class {
|
|
1362
1362
|
select;
|
|
1363
1363
|
onValueChange;
|
|
1364
1364
|
onClassChange;
|
|
@@ -1420,7 +1420,7 @@ var R = class {
|
|
|
1420
1420
|
}
|
|
1421
1421
|
observeCall(e) {
|
|
1422
1422
|
if (!this.listen) return;
|
|
1423
|
-
let { classChanged: t, disabledChanged: n, optgroupOptionChanged: r, selectionChanged: i } =
|
|
1423
|
+
let { classChanged: t, disabledChanged: n, optgroupOptionChanged: r, selectionChanged: i } = B(e, this.select), a = i;
|
|
1424
1424
|
if (t && this.onClassChange && this.onClassChange(this.select.className.split(" ")), n && this.onDisabledChange && (this.changeListen(!1), this.onDisabledChange(this.select.disabled), this.changeListen(!0)), r && this.onOptionsChange) {
|
|
1425
1425
|
if (this.isUpdating) {
|
|
1426
1426
|
if (this.select.options.length > 0) {
|
|
@@ -1464,7 +1464,7 @@ var R = class {
|
|
|
1464
1464
|
placeholder: e.dataset.placeholder === "true",
|
|
1465
1465
|
class: e.className,
|
|
1466
1466
|
style: e.style.cssText,
|
|
1467
|
-
data:
|
|
1467
|
+
data: v(e.dataset)
|
|
1468
1468
|
};
|
|
1469
1469
|
}
|
|
1470
1470
|
getSelectedOptions() {
|
|
@@ -1533,7 +1533,7 @@ var R = class {
|
|
|
1533
1533
|
updateOptions(e) {
|
|
1534
1534
|
if (!(!e || e.length === 0)) {
|
|
1535
1535
|
this.isUpdating = !0, this.pendingOptionsChange = null, this.changeListen(!1), this.select.innerHTML = "";
|
|
1536
|
-
for (let t of e) t instanceof
|
|
1536
|
+
for (let t of e) t instanceof L && this.select.appendChild(this.createOptgroup(t)), t instanceof I && this.select.appendChild(this.createOption(t));
|
|
1537
1537
|
if (this.select.dispatchEvent(new Event("change", { bubbles: !0 })), this.changeListen(!0), this.isUpdating = !1, this.pendingOptionsChange !== null) {
|
|
1538
1538
|
let e = this.pendingOptionsChange;
|
|
1539
1539
|
e.length > 0 && this.onOptionsChange ? (this.pendingOptionsChange = null, this.changeListen(!1), this.onOptionsChange(e), this.changeListen(!0)) : this.pendingOptionsChange = null;
|
|
@@ -1550,7 +1550,7 @@ var R = class {
|
|
|
1550
1550
|
return t.id = e.id, t.value = e.value, t.textContent = e.text, e.html !== "" && t.setAttribute("data-html", e.html), t.defaultSelected = e.defaultSelected, t.selected = e.selected, e.disabled && (t.disabled = !0), e.display || (t.style.display = "none"), e.placeholder && t.setAttribute("data-placeholder", "true"), e.mandatory && t.setAttribute("data-mandatory", "true"), e.class && e.class.split(" ").forEach((e) => {
|
|
1551
1551
|
t.classList.add(e);
|
|
1552
1552
|
}), e.data && typeof e.data == "object" && Object.keys(e.data).forEach((n) => {
|
|
1553
|
-
t.setAttribute("data-" +
|
|
1553
|
+
t.setAttribute("data-" + M(n), e.data[n]);
|
|
1554
1554
|
}), t;
|
|
1555
1555
|
}
|
|
1556
1556
|
setupLabelHandlers() {
|
|
@@ -1567,7 +1567,7 @@ var R = class {
|
|
|
1567
1567
|
Array.from(new Set(e)).forEach((e) => {
|
|
1568
1568
|
if (e.__slimSelectLabelHandler) return;
|
|
1569
1569
|
let t = (e) => {
|
|
1570
|
-
let t = e.target, n =
|
|
1570
|
+
let t = e.target, n = S(t, this.select.dataset.id);
|
|
1571
1571
|
e.preventDefault(), !n && this.onLabelClick && this.onLabelClick();
|
|
1572
1572
|
};
|
|
1573
1573
|
e.__slimSelectLabelHandler = t, e.addEventListener("click", t, {
|
|
@@ -1598,10 +1598,10 @@ var R = class {
|
|
|
1598
1598
|
};
|
|
1599
1599
|
//#endregion
|
|
1600
1600
|
//#region src/slim-select/sync.ts
|
|
1601
|
-
function
|
|
1602
|
-
return
|
|
1601
|
+
function H(e, t) {
|
|
1602
|
+
return j(e.getData(!1), t);
|
|
1603
1603
|
}
|
|
1604
|
-
function
|
|
1604
|
+
function U(e, t) {
|
|
1605
1605
|
let n = Array.isArray(t) ? t : [t], r = e.getDataOptions(!1), i = [];
|
|
1606
1606
|
for (let e of n) {
|
|
1607
1607
|
if (r.find((t) => t.id == e)) {
|
|
@@ -1612,7 +1612,7 @@ function B(e, t) {
|
|
|
1612
1612
|
}
|
|
1613
1613
|
return i;
|
|
1614
1614
|
}
|
|
1615
|
-
var
|
|
1615
|
+
var W = class {
|
|
1616
1616
|
deps;
|
|
1617
1617
|
queue = [];
|
|
1618
1618
|
flushScheduled = !1;
|
|
@@ -1661,7 +1661,7 @@ var V = class {
|
|
|
1661
1661
|
}
|
|
1662
1662
|
applyStructure(e, t, n = !1, r = !1) {
|
|
1663
1663
|
let { store: i, select: a, render: o, events: s } = this.deps;
|
|
1664
|
-
if (
|
|
1664
|
+
if (H(i, e)) return;
|
|
1665
1665
|
let c = i.getSelected(), l = i.validateDataArray(e);
|
|
1666
1666
|
if (l) {
|
|
1667
1667
|
s.error ? s.error(l) : this.deps.onError && this.deps.onError(l);
|
|
@@ -1669,19 +1669,19 @@ var V = class {
|
|
|
1669
1669
|
}
|
|
1670
1670
|
i.setData(e, n);
|
|
1671
1671
|
let u = i.getData(!1);
|
|
1672
|
-
r || i.snapshotCatalog(), a.updateOptions(u), o.renderValues(), o.renderOptions(u), s.afterChange && !
|
|
1672
|
+
r || i.snapshotCatalog(), a.updateOptions(u), o.renderValues(), o.renderOptions(u), s.afterChange && !w(c, i.getSelected()) && s.afterChange(i.getSelectedOptions());
|
|
1673
1673
|
}
|
|
1674
1674
|
applySelection(e, t, n) {
|
|
1675
|
-
let { store: r, select: i, render: a, events: o } = this.deps, s = r.getSelected(), c =
|
|
1676
|
-
if (
|
|
1675
|
+
let { store: r, select: i, render: a, events: o } = this.deps, s = r.getSelected(), c = U(r, e);
|
|
1676
|
+
if (w(s, c)) return;
|
|
1677
1677
|
r.setSelectedBy("id", c), i.setSelectedByValue(r.getSelectedValues()), a.renderValues();
|
|
1678
1678
|
let l = a.content.search.input.value.trim();
|
|
1679
|
-
l === "" ? a.canUpdateOptionSelectionInPlace() ? a.updateOptionSelection() : a.renderOptions(r.getData(!1)) : a.hasRenderedOptions() ? a.updateOptionSelection() : this.deps.search && this.deps.search(l), n && o.afterChange && !
|
|
1679
|
+
l === "" ? a.canUpdateOptionSelectionInPlace() ? a.updateOptionSelection() : a.renderOptions(r.getData(!1)) : a.hasRenderedOptions() ? a.updateOptionSelection() : this.deps.search && this.deps.search(l), n && o.afterChange && !w(s, r.getSelected()) && o.afterChange(r.getSelectedOptions());
|
|
1680
1680
|
}
|
|
1681
1681
|
applyAddOption(e) {
|
|
1682
1682
|
let { store: t, select: n, render: r, events: i } = this.deps, a = t.getSelected(), o = r.content.search.input.value.trim() !== "" && !!this.deps.search, s = e.value ?? e.text ?? "", c = (e) => {
|
|
1683
1683
|
for (let t of e) {
|
|
1684
|
-
if (t instanceof
|
|
1684
|
+
if (t instanceof L) {
|
|
1685
1685
|
if (t.options.some((e) => (e.value ?? e.text) === s)) return !0;
|
|
1686
1686
|
continue;
|
|
1687
1687
|
}
|
|
@@ -1691,12 +1691,12 @@ var V = class {
|
|
|
1691
1691
|
};
|
|
1692
1692
|
if (!c(t.getData(!1))) if (o) {
|
|
1693
1693
|
let n = t.getCatalogData();
|
|
1694
|
-
c(n) || t.setData([...n, new
|
|
1694
|
+
c(n) || t.setData([...n, new I(e)], !0), t.snapshotCatalog();
|
|
1695
1695
|
} else t.addOption(e), t.snapshotCatalog();
|
|
1696
1696
|
let l = t.getData(!1);
|
|
1697
|
-
n.updateOptions(l), r.renderValues(), r.renderOptions(l), i.afterChange && !
|
|
1697
|
+
n.updateOptions(l), r.renderValues(), r.renderOptions(l), i.afterChange && !w(a, t.getSelected()) && i.afterChange(t.getSelectedOptions());
|
|
1698
1698
|
}
|
|
1699
|
-
},
|
|
1699
|
+
}, G = class {
|
|
1700
1700
|
selectEl;
|
|
1701
1701
|
settings;
|
|
1702
1702
|
cssClasses;
|
|
@@ -1727,15 +1727,15 @@ var V = class {
|
|
|
1727
1727
|
e.events && e.events.error && e.events.error(/* @__PURE__ */ Error("Element isnt of type select"));
|
|
1728
1728
|
return;
|
|
1729
1729
|
}
|
|
1730
|
-
this.selectEl.dataset.ssid && this.destroy(), this.settings = new
|
|
1730
|
+
this.selectEl.dataset.ssid && this.destroy(), this.settings = new _(e.settings), this.cssClasses = new s(e.cssClasses);
|
|
1731
1731
|
let t = [
|
|
1732
1732
|
"beforeOpen",
|
|
1733
1733
|
"afterOpen",
|
|
1734
1734
|
"beforeClose",
|
|
1735
1735
|
"afterClose"
|
|
1736
1736
|
];
|
|
1737
|
-
for (let n in e.events) e.events.hasOwnProperty(n) && (t.indexOf(n) === -1 ? this.events[n] = e.events[n] : this.events[n] =
|
|
1738
|
-
this.settings.disabled = e.settings?.disabled ? e.settings.disabled : this.selectEl.disabled, this.settings.isMultiple = this.selectEl.multiple, this.settings.style = this.selectEl.style.cssText, this.settings.class = this.selectEl.className.split(" "), this.select = new
|
|
1737
|
+
for (let n in e.events) e.events.hasOwnProperty(n) && (t.indexOf(n) === -1 ? this.events[n] = e.events[n] : this.events[n] = C(e.events[n], 100));
|
|
1738
|
+
this.settings.disabled = e.settings?.disabled ? e.settings.disabled : this.selectEl.disabled, this.settings.isMultiple = this.selectEl.multiple, this.settings.style = this.selectEl.style.cssText, this.settings.class = this.selectEl.className.split(" "), this.select = new V(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) => {
|
|
1739
1739
|
this.settings.class = e, this.render.updateClassStyles();
|
|
1740
1740
|
}, this.select.onDisabledChange = (e) => {
|
|
1741
1741
|
e ? this.disable() : this.enable();
|
|
@@ -1743,7 +1743,7 @@ var V = class {
|
|
|
1743
1743
|
this.settings.disabled || (this.settings.isOpen ? this.close() : this.open());
|
|
1744
1744
|
};
|
|
1745
1745
|
let n = e.data ? e.data : this.select.getData();
|
|
1746
|
-
this.store = new
|
|
1746
|
+
this.store = new R(this.settings.isMultiple ? "multiple" : "single", n), e.data && this.select.updateOptions(this.store.getData());
|
|
1747
1747
|
let r = {
|
|
1748
1748
|
open: this.open.bind(this),
|
|
1749
1749
|
close: this.close.bind(this),
|
|
@@ -1767,7 +1767,7 @@ var V = class {
|
|
|
1767
1767
|
beforeChange: this.events.beforeChange,
|
|
1768
1768
|
afterChange: this.events.afterChange
|
|
1769
1769
|
};
|
|
1770
|
-
this.settings.modalTitle = e.settings?.modalTitle ??
|
|
1770
|
+
this.settings.modalTitle = e.settings?.modalTitle ?? b(this.selectEl), this.render = new z(this.settings, this.cssClasses, this.store, r), this.settings.timeoutDelay = f(this.render.content.main, e.settings?.timeoutDelay), this.sync = new W({
|
|
1771
1771
|
select: this.select,
|
|
1772
1772
|
store: this.store,
|
|
1773
1773
|
render: this.render,
|
|
@@ -1785,7 +1785,7 @@ var V = class {
|
|
|
1785
1785
|
data: e || [],
|
|
1786
1786
|
source: "native"
|
|
1787
1787
|
});
|
|
1788
|
-
}, this.lifecycle = new
|
|
1788
|
+
}, this.lifecycle = new F({
|
|
1789
1789
|
beforeOpen: this.events.beforeOpen,
|
|
1790
1790
|
afterOpen: this.events.afterOpen,
|
|
1791
1791
|
beforeClose: this.events.beforeClose,
|
|
@@ -1797,7 +1797,7 @@ var V = class {
|
|
|
1797
1797
|
}, {
|
|
1798
1798
|
timeoutDelay: this.settings.timeoutDelay,
|
|
1799
1799
|
waitForAnimation: (e, t) => this.render.waitForAnimation(e, t)
|
|
1800
|
-
}), this.globalEvents = new
|
|
1800
|
+
}), this.globalEvents = new P({
|
|
1801
1801
|
onDocumentClick: this.documentClick.bind(this),
|
|
1802
1802
|
onWindowResize: () => {
|
|
1803
1803
|
!this.settings.isOpen && !this.settings.isFullOpen || this.render.moveContent();
|
|
@@ -1809,9 +1809,9 @@ var V = class {
|
|
|
1809
1809
|
document.hidden && this.close();
|
|
1810
1810
|
}
|
|
1811
1811
|
}), this.render.renderValues(), this.render.renderOptions(this.store.getData(!1));
|
|
1812
|
-
let
|
|
1813
|
-
if (
|
|
1814
|
-
else if (
|
|
1812
|
+
let i = this.selectEl.getAttribute("aria-label"), a = this.selectEl.getAttribute("aria-labelledby");
|
|
1813
|
+
if (i) this.render.main.main.setAttribute("aria-label", i);
|
|
1814
|
+
else if (a) this.render.main.main.removeAttribute("aria-label"), this.render.main.main.setAttribute("aria-labelledby", a);
|
|
1815
1815
|
else if (this.selectEl.labels && this.selectEl.labels.length > 0) {
|
|
1816
1816
|
let e = Array.from(this.selectEl.labels).map((e, t) => (e.id ||= `${this.settings.id}-label-${t}`, e.id));
|
|
1817
1817
|
this.render.main.main.removeAttribute("aria-label"), this.render.main.main.setAttribute("aria-labelledby", e.join(" "));
|
|
@@ -1926,9 +1926,31 @@ var V = class {
|
|
|
1926
1926
|
this.lifecycle.destroy(), this.render.stopPositionTracking(), this.globalEvents.detach({ listenScroll: this.settings.openPosition === "auto" }), this.store.setData([]), this.render.destroy(), this.select.destroy();
|
|
1927
1927
|
}
|
|
1928
1928
|
documentClick(e) {
|
|
1929
|
-
this.settings.isOpen && e.target && !
|
|
1929
|
+
this.settings.isOpen && e.target && !S(e.target, this.settings.id) && this.close(e.type);
|
|
1930
1930
|
}
|
|
1931
|
-
}
|
|
1931
|
+
};
|
|
1932
|
+
//#endregion
|
|
1933
|
+
//#region src/slim-select/vue/helpers.ts
|
|
1934
|
+
function K(e) {
|
|
1935
|
+
let t = /* @__PURE__ */ new WeakMap(), i = (e) => {
|
|
1936
|
+
if (r(e) && (e = o(e)), n(e) && (e = a(e)), typeof e != "object" || !e) return e;
|
|
1937
|
+
if (t.has(e)) return t.get(e);
|
|
1938
|
+
if (Array.isArray(e)) {
|
|
1939
|
+
let n = [];
|
|
1940
|
+
t.set(e, n);
|
|
1941
|
+
for (let t of e) n.push(i(t));
|
|
1942
|
+
return n;
|
|
1943
|
+
}
|
|
1944
|
+
let s = {};
|
|
1945
|
+
t.set(e, s);
|
|
1946
|
+
for (let t of Object.keys(e)) s[t] = i(e[t]);
|
|
1947
|
+
return s;
|
|
1948
|
+
};
|
|
1949
|
+
return i(e);
|
|
1950
|
+
}
|
|
1951
|
+
//#endregion
|
|
1952
|
+
//#region src/slim-select/vue/vue.vue?vue&type=script&lang.ts
|
|
1953
|
+
var q = t({
|
|
1932
1954
|
name: "SlimSelect",
|
|
1933
1955
|
props: {
|
|
1934
1956
|
modelValue: { type: [
|
|
@@ -1969,7 +1991,7 @@ var V = class {
|
|
|
1969
1991
|
afterChange: (e) => {
|
|
1970
1992
|
this.handleAfterChange(e, t);
|
|
1971
1993
|
}
|
|
1972
|
-
}, this.slim = new
|
|
1994
|
+
}, this.slim = new G(e), this.lastAppliedData = structuredClone(K(this.data)), this.syncModelValueToSlimSelect(!1);
|
|
1973
1995
|
},
|
|
1974
1996
|
beforeUnmount() {
|
|
1975
1997
|
this.slim && this.slim.destroy();
|
|
@@ -1980,7 +2002,7 @@ var V = class {
|
|
|
1980
2002
|
} },
|
|
1981
2003
|
data: {
|
|
1982
2004
|
handler: function(e) {
|
|
1983
|
-
this.slim && (this.lastAppliedData !== null &&
|
|
2005
|
+
this.slim && (this.lastAppliedData !== null && j(this.lastAppliedData, a(e)) || (this.slim.setData(e), this.lastAppliedData = structuredClone(K(e)), this.syncModelValueToSlimSelect(!1)));
|
|
1984
2006
|
},
|
|
1985
2007
|
deep: !0
|
|
1986
2008
|
}
|
|
@@ -2020,19 +2042,19 @@ var V = class {
|
|
|
2020
2042
|
this.slim.setSelected(t, e);
|
|
2021
2043
|
}
|
|
2022
2044
|
}
|
|
2023
|
-
}),
|
|
2045
|
+
}), J = (e, t) => {
|
|
2024
2046
|
let n = e.__vccOpts || e;
|
|
2025
2047
|
for (let [e, r] of t) n[e] = r;
|
|
2026
2048
|
return n;
|
|
2027
|
-
},
|
|
2028
|
-
function
|
|
2029
|
-
return
|
|
2049
|
+
}, Y = ["multiple"];
|
|
2050
|
+
function X(t, n, r, a, o, s) {
|
|
2051
|
+
return i(), e("select", {
|
|
2030
2052
|
multiple: t.multiple,
|
|
2031
2053
|
ref: "slim"
|
|
2032
|
-
}, null, 8,
|
|
2054
|
+
}, null, 8, Y);
|
|
2033
2055
|
}
|
|
2034
2056
|
//#endregion
|
|
2035
2057
|
//#region src/slim-select/vue/index.ts
|
|
2036
|
-
var
|
|
2058
|
+
var Z = /* @__PURE__ */ J(q, [["render", X]]);
|
|
2037
2059
|
//#endregion
|
|
2038
|
-
export {
|
|
2060
|
+
export { L as Optgroup, I as Option, _ as Settings, Z as default };
|
package/dist/vue/index.umd.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(e,t){typeof exports==`object`&&typeof module<`u`?t(exports,require("vue")):typeof define==`function`&&define.amd?define([`exports`,`vue`],t):(e=typeof globalThis<`u`?globalThis:e||self,t(e.SlimSelectVue={},e.Vue))})(this,function(e,t){Object.defineProperties(e,{__esModule:{value:!0},[Symbol.toStringTag]:{value:`Module`}});var n=class{main;placeholder;values;single;multiString;max;value;valueText;valueDelete;valueOut;deselect;deselectPath;arrow;arrowClose;arrowOpen;content;contentOpen;dirAbove;dirBelow;search;searchHighlighter;searching;status;addable;addablePath;list;optgroup;optgroupLabel;optgroupLabelText;optgroupActions;optgroupSelectAll;optgroupSelectAllBox;optgroupSelectAllCheck;optgroupClosable;option;optionDelete;highlighted;modalOverlay;modalDialog;modalTitle;modalClose;modalContent;mainOpen;close;selected;error;disabled;hide;constructor(e){e||={};let t=(e=``,t=``)=>`${e} ${t}`.trim();this.main=t(`ss-main`,e.main),this.placeholder=t(`ss-placeholder`,e.placeholder),this.values=t(`ss-values`,e.values),this.single=t(`ss-single`,e.single),this.multiString=t(`ss-multi-string`,e.multiString),this.max=t(`ss-max`,e.max),this.value=t(`ss-value`,e.value),this.valueText=t(`ss-value-text`,e.valueText),this.valueDelete=t(`ss-value-delete`,e.valueDelete),this.valueOut=t(`ss-value-out`,e.valueOut),this.deselect=t(`ss-deselect`,e.deselect),this.deselectPath=e.deselectPath||`M10,10 L90,90 M10,90 L90,10`,this.arrow=t(`ss-arrow`,e.arrow),this.arrowClose=e.arrowClose||`M10,30 L50,70 L90,30`,this.arrowOpen=e.arrowOpen||`M10,70 L50,30 L90,70`,this.content=t(`ss-content`,e.content),this.contentOpen=t(`ss-open`,e.contentOpen),this.dirAbove=t(`ss-dir-above`,e.dirAbove),this.dirBelow=t(`ss-dir-below`,e.dirBelow),this.search=t(`ss-search`,e.search),this.searchHighlighter=t(`ss-search-highlight`,e.searchHighlighter),this.searching=t(`ss-searching`,e.searching),this.status=t(`ss-status`,e.status),this.addable=t(`ss-addable`,e.addable),this.addablePath=e.addablePath||`M50,10 L50,90 M10,50 L90,50`,this.list=t(`ss-list`,e.list),this.optgroup=t(`ss-optgroup`,e.optgroup),this.optgroupLabel=t(`ss-optgroup-label`,e.optgroupLabel),this.optgroupLabelText=t(`ss-optgroup-label-text`,e.optgroupLabelText),this.optgroupActions=t(`ss-optgroup-actions`,e.optgroupActions),this.optgroupSelectAll=t(`ss-selectall`,e.optgroupSelectAll),this.optgroupSelectAllBox=e.optgroupSelectAllBox||`M60,10 L10,10 L10,90 L90,90 L90,50`,this.optgroupSelectAllCheck=e.optgroupSelectAllCheck||`M30,45 L50,70 L90,10`,this.optgroupClosable=t(`ss-closable`,e.optgroupClosable),this.option=t(`ss-option`,e.option),this.optionDelete=e.optionDelete||`M10,10 L90,90 M10,90 L90,10`,this.highlighted=t(`ss-highlighted`,e.highlighted),this.modalOverlay=t(`ss-modal-overlay`,e.modalOverlay),this.modalDialog=t(`ss-modal-dialog`,e.modalDialog),this.modalTitle=t(`ss-modal-title`,e.modalTitle),this.modalClose=t(`ss-modal-close`,e.modalClose),this.modalContent=t(`ss-modal-content`,e.modalContent),this.mainOpen=t(`ss-open`,e.mainOpen),this.close=t(`ss-close`,e.close),this.selected=t(`ss-selected`,e.selected),this.error=t(`ss-error`,e.error),this.disabled=t(`ss-disabled`,e.disabled),this.hide=t(`ss-hide`,e.hide)}getFirst(e){return this[e].split(` `)[0]}},r=200,i=[`transform`,`opacity`];function a(e,t=r){let n=e.trim();if(!n)return t;if(n.endsWith(`ms`)){let e=parseFloat(n);return Number.isNaN(e)?t:e}if(n.endsWith(`s`)){let e=parseFloat(n);return Number.isNaN(e)?t:e*1e3}let i=parseFloat(n);return Number.isNaN(i)?t:i}function o(e,t=r){return a(getComputedStyle(e).getPropertyValue(`--ss-animation-timing`).trim(),t)}function s(e,t,n=r){let i=o(e,n)+50;return t===void 0?i:Math.max(i,t)}function c(){return typeof window>`u`||typeof window.matchMedia!=`function`?!1:window.matchMedia(`(prefers-reduced-motion: reduce)`).matches}function l(e){return e===void 0?null:new Set(Array.isArray(e)?e:[e])}function u(e,t,n=r,i){if(c()||i?.aborted)return Promise.resolve();let a=l(t);return new Promise(t=>{let r=null,o=!1,s=()=>{o||(o=!0,e.removeEventListener(`transitionend`,l),i?.removeEventListener(`abort`,c),r&&clearTimeout(r),t())},c=()=>s(),l=t=>{t.target===e&&(a&&(!a.has(t.propertyName)||(a.delete(t.propertyName),a.size>0))||s())};i?.addEventListener(`abort`,c,{once:!0}),e.addEventListener(`transitionend`,l),r=setTimeout(s,n)})}function d(e,t,n=r,i){return c()||i?.aborted?Promise.resolve():new Promise(r=>{let a=null,o=!1,s=()=>{o||(o=!0,e.removeEventListener(`animationend`,l),i?.removeEventListener(`abort`,c),a&&clearTimeout(a),r())},c=()=>s(),l=n=>{n.target===e&&(t&&n.animationName!==t||s())};i?.addEventListener(`abort`,c,{once:!0}),e.addEventListener(`animationend`,l),a=setTimeout(s,n)})}var f=class{id=``;style=``;class=[];isMultiple=!1;isOpen=!1;isFullOpen=!1;disabled;alwaysOpen;showSearch;focusSearch;keepSearch;ariaLabel;searchPlaceholder;searchText;searchingText;resultsText;deselectText;removeText;searchHighlight;closeOnSelect;contentLocation;contentPosition;contentWidth;openPosition;placeholderText;allowDeselect;hideSelected;multiString;keepOrder;showOptionTooltips;minSelected;maxSelected;timeoutDelay;maxValuesShown;maxValuesMessage;addableText;modal;modalTitle;constructor(e){e||={},this.id=`ss-`+g(),this.style=e.style||``,this.class=e.class||[],this.disabled=e.disabled===void 0?!1:e.disabled,this.alwaysOpen=e.alwaysOpen===void 0?!1:e.alwaysOpen,this.showSearch=e.showSearch===void 0?!0:e.showSearch,this.focusSearch=e.focusSearch===void 0?!0:e.focusSearch,this.keepSearch=e.keepSearch===void 0?!1:e.keepSearch,this.ariaLabel=e.ariaLabel||`Combobox`,this.searchPlaceholder=e.searchPlaceholder||`Search...`,this.searchText=e.searchText||`No Results`,this.searchingText=e.searchingText||`Searching...`,this.resultsText=e.resultsText||`{count} results available`,this.deselectText=e.deselectText||`Clear`,this.removeText=e.removeText||`Remove`,this.searchHighlight=e.searchHighlight===void 0?!1:e.searchHighlight,this.closeOnSelect=e.closeOnSelect===void 0?!0:e.closeOnSelect,this.contentLocation=e.contentLocation||document.body,this.contentPosition=e.contentPosition||`absolute`,this.contentWidth=e.contentWidth||``,this.openPosition=e.openPosition||`auto`,this.placeholderText=e.placeholderText===void 0?`Select Value`:e.placeholderText,this.allowDeselect=e.allowDeselect===void 0?!1:e.allowDeselect,this.hideSelected=e.hideSelected===void 0?!1:e.hideSelected,this.multiString=e.multiString===void 0?!1:e.multiString,this.keepOrder=e.keepOrder===void 0?!1:e.keepOrder,this.showOptionTooltips=e.showOptionTooltips===void 0?!1:e.showOptionTooltips,this.minSelected=e.minSelected||0,this.maxSelected=e.maxSelected||1e3,this.timeoutDelay=e.timeoutDelay||200,this.maxValuesShown=e.maxValuesShown||20,this.maxValuesMessage=e.maxValuesMessage||`{number} selected`,this.addableText=e.addableText||`Press "Enter" to add {value}`,this.modal=e.modal||`mobile`,this.modalTitle=e.modalTitle||``}};function p(e){if(!e)return{};let t={};for(let n of Object.keys(e)){let r=e[n];r!==void 0&&(t[n]=r)}return t}function m(e){let t=e.cloneNode(!0);return t.querySelectorAll(`select, option, optgroup, textarea, input, button`).forEach(e=>e.remove()),t.textContent?.replace(/\s+/g,` `).trim()||``}function h(e){if(e.labels&&e.labels.length>0){let t=Array.from(e.labels).map(m).filter(Boolean);if(t.length>0)return[...new Set(t)].join(` `)}return e.getAttribute(`aria-label`)?.trim()||``}function g(){return Math.random().toString(36).substring(2,10)}function _(e,t){function n(e,n){return n&&e&&e.classList&&e.classList.contains(n)||n&&e&&e.dataset&&e.dataset.id&&e.dataset.id===t?e:null}function r(e,t){return!e||e===document?null:n(e,t)?e:r(e.parentNode,t)}return n(e,t)||r(e,t)}function v(e,t=50,n=!1){let r;return function(...i){let a=self,o=()=>{r=null,n||e.apply(a,i)},s=n&&!r;clearTimeout(r),r=setTimeout(o,t),s&&e.apply(a,i)}}function y(e,t){if(e.length!==t.length)return!1;let n=[...e].sort(),r=[...t].sort();return n.every((e,t)=>e===r[t])}var b=[`id`,`value`,`text`,`html`,`defaultSelected`,`selected`,`display`,`disabled`,`placeholder`,`class`,`style`,`mandatory`];function x(e,t){let n=Object.keys(e),r=Object.keys(t);if(n.length!==r.length)return!1;for(let r of n)if(e[r]!==t[r])return!1;return!0}function S(e,t){switch(t){case`id`:return e.id||``;case`value`:return e.value===void 0?e.text||``:e.value||``;case`text`:return e.text||``;case`html`:return e.html||``;case`defaultSelected`:return e.defaultSelected??!1;case`selected`:return e.selected??!1;case`display`:return e.display??!0;case`disabled`:return e.disabled??!1;case`placeholder`:return e.placeholder??!1;case`class`:return e.class||``;case`style`:return e.style||``;case`mandatory`:return e.mandatory??!1;default:return e.data||{}}}function C(e){return!!e&&typeof e==`object`&&`label`in e&&`options`in e}function w(e,t){for(let n of b)if(S(e,n)!==S(t,n))return!1;return x(e.data||{},t.data||{})}function T(e,t){let n=e=>({id:e.id||``,label:e.label||``,selectAll:e.selectAll??!1,closable:e.closable||`off`}),r=n(e),i=n(t);if(r.id!==i.id||r.label!==i.label||r.selectAll!==i.selectAll||r.closable!==i.closable)return!1;let a=e.options||[],o=t.options||[];if(a.length!==o.length)return!1;for(let e=0;e<a.length;e++)if(!w(a[e],o[e]))return!1;return!0}function E(e,t){if(e===t)return!0;if(e.length!==t.length)return!1;for(let n=0;n<e.length;n++){let r=e[n],i=t[n],a=C(r);if(a!==C(i))return!1;if(a){if(!T(r,i))return!1;continue}if(!w(r,i))return!1}return!0}function D(e){let t=e.replace(/[A-Z\u00C0-\u00D6\u00D8-\u00DE]/g,e=>`-`+e.toLowerCase());return e[0]===e[0].toUpperCase()?t.substring(1):t}function O(e,t=typeof window<`u`?window.innerWidth:768){return e===`on`?!0:e===`mobile`?t<768:!1}var k=class{handlers;attached=!1;constructor(e){this.handlers=e}attach(e){this.attached||(this.attached=!0,window.addEventListener(`resize`,this.resizeHandler,!1),e.listenScroll&&window.addEventListener(`scroll`,this.scrollHandler,!1),document.addEventListener(`visibilitychange`,this.visibilityHandler))}attachDocumentClick(){document.addEventListener(`click`,this.handlers.onDocumentClick)}detachDocumentClick(){document.removeEventListener(`click`,this.handlers.onDocumentClick)}detach(e){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))}resizeHandler=v(()=>{this.handlers.onWindowResize()});scrollHandler=v(()=>{this.handlers.onWindowScroll()});visibilityHandler=()=>{this.handlers.onVisibilityChange()}},A=class{handlers;options;state=`closed`;pendingTimer=null;waitResolvers=[];generation=0;animationAbort=null;constructor(e,t){this.handlers=e,this.options=t}get isOpen(){return this.state===`opening`||this.state===`open`}get isFullOpen(){return this.state===`open`}async requestOpen(){if(this.state===`opening`||this.state===`open`)return;this.cancelPending();let e=++this.generation;if(this.handlers.beforeOpen&&this.handlers.beforeOpen(),this.state=`opening`,await this.waitForPhase(`open`,e),e!==this.generation){this.state===`opening`&&(this.state=`closed`);return}this.state=`open`,this.handlers.afterOpen&&this.handlers.afterOpen(),this.handlers.onOpenReady&&this.handlers.onOpenReady()}async requestClose(){if(this.state===`closed`||this.state===`closing`)return;this.cancelPending();let e=++this.generation;this.handlers.beforeClose&&this.handlers.beforeClose(),this.state=`closing`,await this.waitForPhase(`close`,e),e===this.generation&&(this.state=`closed`,this.handlers.afterClose&&this.handlers.afterClose(),this.handlers.onCloseReady&&this.handlers.onCloseReady())}cancelPending(){this.generation++,this.animationAbort?.abort(),this.animationAbort=null,this.pendingTimer&&=(clearTimeout(this.pendingTimer),null);let e=this.waitResolvers.splice(0);for(let t of e)t()}destroy(){this.cancelPending(),this.state=`closed`}waitForPhase(e,t){return new Promise(t=>{let n=!1,r=()=>{if(n)return;n=!0;let e=this.waitResolvers.indexOf(r);e!==-1&&this.waitResolvers.splice(e,1),t()};if(this.waitResolvers.push(r),this.options.waitForAnimation){let t=new AbortController;this.animationAbort=t,this.options.waitForAnimation(e,t.signal).catch(()=>void 0).finally(()=>{this.animationAbort===t&&(this.animationAbort=null),r()})}else this.pendingTimer=setTimeout(()=>{this.pendingTimer=null,r()},this.options.timeoutDelay)}).then(()=>{this.generation})}},j=class{id;value;text;html;defaultSelected;selected;display;disabled;placeholder;class;style;data;mandatory;constructor(e){this.id=!e.id||e.id===``?g():e.id,this.value=e.value===void 0?e.text||``:e.value||``,this.text=e.text||``,this.html=e.html||``,this.defaultSelected=e.defaultSelected===void 0?!1:e.defaultSelected,this.selected=e.selected===void 0?!1:e.selected,this.display=e.display===void 0?!0:e.display,this.disabled=e.disabled===void 0?!1:e.disabled,this.mandatory=e.mandatory===void 0?!1:e.mandatory,this.placeholder=e.placeholder===void 0?!1:e.placeholder,this.class=e.class||``,this.style=e.style||``,this.data=p(e.data)}},M=class{id;label;selectAll;closable;options;constructor(e){if(this.id=!e.id||e.id===``?g():e.id,this.label=e.label||``,this.selectAll=e.selectAll===void 0?!1:e.selectAll,this.closable=e.closable||`off`,this.options=[],e.options)for(let t of e.options)this.options.push(new j(t))}},N=class{selectType=`single`;data=[];selectedOrder=[];catalog=null;constructor(e,t){this.selectType=e,this.setData(t),this.snapshotCatalog()}validateDataArray(e){if(!Array.isArray(e))return Error(`Data must be an array`);for(let t of e)if(t)if(t instanceof M||`label`in t){if(!(`label`in t))return Error(`Optgroup must have a label`);if(`options`in t&&t.options)for(let e of t.options){let t=this.validateOption(e);if(t)return t}}else if(t instanceof j||`text`in t){let e=this.validateOption(t);if(e)return e}else return Error(`Data object must be a valid optgroup or option`);return null}validateOption(e){return`text`in e?null:Error(`Option must have a text`)}partialToFullData(e){let t=[];return e.forEach(e=>{if(e){if(e instanceof M||`label`in e){let n=[];`options`in e&&e.options&&e.options.forEach(e=>{n.push(new j(e))}),n.length>0&&t.push(new M(e))}(e instanceof j||`text`in e)&&t.push(new j(e))}}),t}snapshotCatalog(){this.catalog=this.cloneData(this.data)}getCatalogData(){return this.cloneData(this.catalog??this.data)}cloneData(e){return e.map(e=>e instanceof M?new M({id:e.id,label:e.label,selectAll:e.selectAll,closable:e.closable,options:e.options.map(e=>new j(e instanceof j?{...e}:e))}):new j({...e}))}optionMatchesSelected(e,t){return e.id===t.id?!0:t.value!==``&&e.value!==``&&e.value===t.value}findOptionInData(e,t){for(let n of e){if(n instanceof j){if(this.optionMatchesSelected(n,t))return n;continue}for(let e of n.options)if(this.optionMatchesSelected(e,t))return e}return null}setData(e,t=!1){let n=this.partialToFullData(e),r=[];if(t){r=this.getSelectedOptions();let e=[];r.forEach(t=>{this.findOptionInData(n,t)||e.push(t)}),this.data=[...e,...n];let t=this.selectType===`single`&&r.length===0,i=r.map(e=>{let t=this.findOptionInData(this.data,e);return t?t.id:e.id});this.setSelectedBy(`id`,i,t)}else this.data=n;!t&&this.selectType===`single`&&this.setSelectedBy(`id`,this.getSelected(),!1)}getData(e=!0){return this.filter(null,!0,e)}getDataOptions(e=!0){return this.filter(null,!1,e)}addOption(e,t=!1){if(t){let t=[new j(e)];this.setData(t.concat(this.getData()))}else this.setData(this.getData().concat(new j(e)))}setSelectedBy(e,t,n=!1){let r=null,i=!1,a=[];for(let n of this.data){if(n instanceof M)for(let o of n.options){r||=o;let n=o[e]||``;o.selected=i?!1:t.includes(n),o.selected&&(a.push(o),this.selectType===`single`&&(i=!0))}n instanceof j&&(r||=n,n.selected=i?!1:t.includes(n[e]),n.selected&&(a.push(n),this.selectType===`single`&&(i=!0)))}this.selectType===`single`&&r&&!i&&!n&&(r.selected=!0,a.push(r));let o=t.map(t=>a.find(n=>n[e]===t)?.id||``);this.selectedOrder=o}getSelected(){return this.getSelectedOptions().map(e=>e.id)}getSelectedValues(){return this.getSelectedOptions().map(e=>e.value)}getSelectedOptions(){let e=[];for(let t of this.data)if(t instanceof M)for(let n of t.options)n.selected&&e.push(n);else t.selected&&e.push(t);return e}getOptgroupByID(e){for(let t of this.data)if(t instanceof M&&t.id===e)return t;return null}getOptionByID(e){for(let t of this.data)if(t instanceof M){for(let n of t.options)if(n.id===e)return n}else if(t.id===e)return t;return null}getSelectType(){return this.selectType}getFirstOption(){let e=null;for(let t of this.data)if(t instanceof M?e=t.options[0]:t instanceof j&&(e=t),e)break;return e}search(e,t){return e=e.trim(),e===``?this.getData(!1):this.filter(n=>t(n,e),!0,!1)}createOptgroupView(e,t){let n=new M({id:e.id,label:e.label,selectAll:e.selectAll,closable:e.closable,options:[]});return n.options=t,n}filter(e,t,n=!0){let r=[];return this.data.forEach(i=>{if(i instanceof M){let a=[];if(i.options.forEach(i=>{(!e||e(i))&&(t?a.push(n?new j(i):i):r.push(n?new j(i):i))}),a.length>0)if(n){let e=new M(i);e.options=a,r.push(e)}else r.push(this.createOptgroupView(i,a))}i instanceof j&&(!e||e(i))&&r.push(n?new j(i):i)}),r}selectedOrderOptions(e){let t=[];return this.selectedOrder.forEach(n=>{let r=e.find(e=>e.id===n);r&&t.push(r)}),e.forEach(e=>{let n=!1;t.forEach(t=>{if(e.id===t.id){n=!0;return}}),n||t.push(e)}),t}},P=class{settings;store;callbacks;lastSelectedOption;lastRenderedOptions;optionsListIsFullData=!1;lastSearchFilterTerm=``;main;content;classes;positionObserver=null;positionObserverRaf=0;modalElements=null;modalSessionActive=null;bodyScrollLocked=!1;savedBodyOverflow=``;constructor(e,t,n,r){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))}addClasses(e,t){if(!t||t.trim()===``)return;let n=t.split(` `).filter(e=>e.trim()!==``);for(let t of n)e.classList.add(t.trim())}removeClasses(e,t){if(!t||t.trim()===``)return;let n=t.split(` `).filter(e=>e.trim()!==``);for(let t of n)e.classList.remove(t.trim())}enable(){this.removeClasses(this.main.main,this.classes.disabled),this.main.main.setAttribute(`aria-disabled`,`false`),this.content.search.input.disabled=!1}disable(){this.addClasses(this.main.main,this.classes.disabled),this.main.main.setAttribute(`aria-disabled`,`true`),this.content.search.input.disabled=!0}open(){this.main.arrow.path.setAttribute(`d`,this.classes.arrowOpen),this.main.main.setAttribute(`aria-expanded`,`true`);let e=this.resolveModalView();if(!e){let e=this.settings.openPosition===`up`?this.classes.dirAbove:this.classes.dirBelow;this.addClasses(this.main.main,e),this.addClasses(this.content.main,e)}this.addClasses(this.content.main,this.classes.contentOpen),this.content.search.input.removeAttribute(`aria-hidden`),e?this.showModal():this.moveContent();let t=this.store.getSelectedOptions();if(t.length){let e=t[t.length-1].id,n=this.content.list.querySelector(`[data-id="`+e+`"]`);n&&this.ensureElementInView(this.content.list,n)}}isModalViewActive(){return this.modalSessionActive===!0}resolveModalView(){return this.settings.alwaysOpen||this.settings.modal===`off`||!this.modalElements?!1:(this.modalSessionActive===null&&(this.modalSessionActive=O(this.settings.modal)),this.modalSessionActive)}createModalElements(){let e=document.createElement(`div`);this.addClasses(e,this.classes.modalOverlay),this.addClasses(e,this.classes.hide),e.dataset.id=this.settings.id;let t=document.createElement(`div`);this.addClasses(t,this.classes.modalDialog),t.setAttribute(`role`,`dialog`),t.setAttribute(`aria-modal`,`true`);let n=null;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);let r=document.createElement(`button`);r.type=`button`,this.addClasses(r,this.classes.modalClose),r.setAttribute(`aria-label`,`Close`),r.onclick=e=>{e.stopPropagation(),this.callbacks.close()};let i=document.createElementNS(`http://www.w3.org/2000/svg`,`svg`);i.setAttribute(`viewBox`,`0 0 100 100`);let a=document.createElementNS(`http://www.w3.org/2000/svg`,`path`);return a.setAttribute(`d`,this.classes.deselectPath),i.appendChild(a),r.appendChild(i),e.onclick=t=>{t.target===e&&this.callbacks.close()},n&&t.appendChild(n),e.appendChild(t),{overlay:e,dialog:t,closeButton:r,title:n}}showModal(){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(()=>{this.modalElements&&this.addClasses(this.modalElements.overlay,this.classes.contentOpen)}),this.lockBodyScroll())}lockBodyScroll(){this.bodyScrollLocked||=(this.savedBodyOverflow=document.body.style.overflow,document.body.style.overflow=`hidden`,!0)}unlockBodyScroll(){this.bodyScrollLocked&&(document.body.style.overflow=this.savedBodyOverflow,this.bodyScrollLocked=!1,this.savedBodyOverflow=``)}restoreContentOffscreen(){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`)}finalizeModalClose(){this.modalElements&&this.content.main.parentElement===this.modalElements.dialog&&(this.addClasses(this.modalElements.overlay,this.classes.hide),this.removeClasses(this.modalElements.overlay,this.classes.contentOpen),this.removeClasses(this.content.main,this.classes.modalContent),this.restoreContentOffscreen(),this.unlockBodyScroll())}waitForAnimation(e,t){let n=s(this.content.main,this.settings.timeoutDelay);return u(this.content.main,i,n,t)}close(){this.main.main.setAttribute(`aria-expanded`,`false`),this.main.arrow.path.setAttribute(`d`,this.classes.arrowClose);let e=this.modalSessionActive===!0;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`)}clearDirectionClasses(){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)}updateClassStyles(){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()));(this.settings.contentPosition===`relative`||this.settings.contentPosition===`fixed`)&&this.content.main.classList.add(`ss-`+this.settings.contentPosition)}updateAriaAttributes(){let e=this.content.list.id;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)}mainDiv(){let e=document.createElement(`div`);e.dataset.id=this.settings.id,e.setAttribute(`aria-label`,this.settings.ariaLabel),e.tabIndex=0,e.onkeydown=e=>{switch(e.key){case`ArrowUp`:case`ArrowDown`:return this.callbacks.open(),e.key===`ArrowDown`?this.highlight(`down`):this.highlight(`up`),!1;case`Tab`:return this.callbacks.close(),!0;case`Enter`:case` `:this.callbacks.open();let t=this.content.list.querySelector(`.`+this.classes.getFirst(`highlighted`));return t&&t.click(),!1;case`Escape`:return this.callbacks.close(),!1}return e.key.length===1&&this.callbacks.open(),!0},e.onclick=e=>{this.settings.disabled||(this.settings.isOpen?this.callbacks.close():this.callbacks.open())};let t=document.createElement(`div`);this.addClasses(t,this.classes.values),e.appendChild(t);let n=document.createElement(`div`);this.addClasses(n,this.classes.deselect),n.setAttribute(`role`,`button`),n.setAttribute(`aria-label`,this.settings.deselectText),n.setAttribute(`tabindex`,`0`);let r=this.store?.getSelectedOptions();!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=>{if(e.stopPropagation(),this.settings.disabled||this.settings.isMultiple&&this.isAtMinSelected())return;let t=!0,n=this.store.getSelectedOptions(),r=[],i=``;if(this.settings.isMultiple){let e=this.settings.minSelected,t=this.store.getSelected();if(e>0&&t.length>e)i=this.getMinimumSelectionIds(),r=n.filter(e=>i.includes(e.id));else if(e<=0)i=[];else return}if(this.callbacks.beforeChange&&(t=this.callbacks.beforeChange(r,n)===!0),t){if(this.settings.isMultiple)this.callbacks.setSelected(i,!1),this.updateDeselectAll();else{let e=this.store.getFirstOption(),t=e?e.id:``;this.callbacks.setSelected(t,!1)}this.settings.closeOnSelect&&this.callbacks.close(),this.callbacks.afterChange&&this.callbacks.afterChange(this.store.getSelectedOptions())}},n.onkeydown=e=>{(e.key===`Enter`||e.key===` `)&&(e.preventDefault(),n.click())};let i=document.createElementNS(`http://www.w3.org/2000/svg`,`svg`);i.setAttribute(`viewBox`,`0 0 100 100`);let a=document.createElementNS(`http://www.w3.org/2000/svg`,`path`);a.setAttribute(`d`,this.classes.deselectPath),i.appendChild(a),n.appendChild(i),e.appendChild(n);let o=document.createElementNS(`http://www.w3.org/2000/svg`,`svg`);this.addClasses(o,this.classes.arrow),o.setAttribute(`viewBox`,`0 0 100 100`);let s=document.createElementNS(`http://www.w3.org/2000/svg`,`path`);return s.setAttribute(`d`,this.classes.arrowClose),this.settings.alwaysOpen&&this.addClasses(o,this.classes.hide),o.appendChild(s),e.appendChild(o),{main:e,values:t,deselect:{main:n,svg:i,path:a},arrow:{main:o,path:s}}}mainFocus(e){e!==`click`&&this.main.main.focus({preventScroll:!0})}placeholder(){let e=this.store.filter(e=>e.placeholder,!1,!1),t=this.settings.placeholderText;e.length&&(e[0].html===``?e[0].text!==``&&(t=e[0].text):t=e[0].html);let n=document.createElement(`div`);return this.addClasses(n,this.classes.placeholder),n.innerHTML=t,n}renderValues(){if(!this.settings.isMultiple){this.renderSingleValue();return}this.renderMultipleValues(),this.updateDeselectAll()}renderSingleValue(){let e=this.store.filter(e=>e.selected&&!e.placeholder,!1,!1),t=e.length>0?e[0]:null;if(!t)this.main.values.innerHTML=this.placeholder().outerHTML;else{let e=document.createElement(`div`);this.addClasses(e,this.classes.single),t.html?e.innerHTML=t.html:e.innerText=t.text,this.main.values.innerHTML=e.outerHTML}!this.settings.allowDeselect||!e.length?this.addClasses(this.main.deselect.main,this.classes.hide):this.removeClasses(this.main.deselect.main,this.classes.hide)}renderMultipleValues(){let e=this.main.values.childNodes,t=this.store.filter(e=>e.selected&&e.display,!1,!1);if(t.length===0){this.main.values.innerHTML=this.placeholder().outerHTML;return}else{let e=this.main.values.querySelector(`.`+this.classes.getFirst(`placeholder`));e&&e.remove()}if(this.settings.multiString){let e=t;this.settings.keepOrder&&(e=this.store.selectedOrderOptions(e));let n=document.createElement(`div`);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;return}if(t.length>this.settings.maxValuesShown){let e=document.createElement(`div`);this.addClasses(e,this.classes.max),e.textContent=this.settings.maxValuesMessage.replace(`{number}`,t.length.toString()),this.main.values.innerHTML=e.outerHTML;return}else{let e=this.main.values.querySelector(`.`+this.classes.getFirst(`max`));e&&e.remove()}this.settings.keepOrder&&(t=this.store.selectedOrderOptions(t));let n=[];for(let r=0;r<e.length;r++){let i=e[r],a=i.getAttribute(`data-id`);a&&(t.filter(e=>e.id===a,!1).length||n.push(i))}let r=s(this.content.main,this.settings.timeoutDelay);for(let e of n)this.addClasses(e,this.classes.valueOut),d(e,`ss-valueOut`,r).then(()=>{this.main.values.hasChildNodes()&&this.main.values.contains(e)&&this.main.values.removeChild(e)});e=this.main.values.childNodes;for(let n=0;n<t.length;n++){let r=!0;for(let i=0;i<e.length;i++)t[n].id===String(e[i].dataset.id)&&(r=!1);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])))}this.updateMultipleValueDeleteVisibility()}isAtMinSelected(){return this.settings.isMultiple&&this.settings.minSelected>0&&this.store.getSelectedOptions().length<=this.settings.minSelected}getMinimumSelectionIds(){let e=this.store.getSelectedOptions();return this.settings.keepOrder&&(e=this.store.selectedOrderOptions(e)),e.slice(0,this.settings.minSelected).map(e=>e.id)}updateMultipleValueDeleteVisibility(){if(!this.settings.isMultiple||this.settings.multiString)return;let e=!this.isAtMinSelected(),t=this.main.values.querySelectorAll(`.`+this.classes.getFirst(`valueDelete`));for(let n of t)e?this.removeClasses(n,this.classes.hide):this.addClasses(n,this.classes.hide)}multipleValue(e){let t=document.createElement(`div`);this.addClasses(t,this.classes.value),t.dataset.id=e.id;let n=document.createElement(`div`);if(this.addClasses(n,this.classes.valueText),n.textContent=e.text,t.appendChild(n),!e.mandatory){let n=document.createElement(`div`);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=>{if(t.preventDefault(),t.stopPropagation(),this.settings.disabled)return;let n=!0,r=this.store.getSelectedOptions(),i=r.filter(t=>t.selected&&t.id!==e.id,!0);if(!(this.settings.minSelected&&i.length<this.settings.minSelected)&&(this.callbacks.beforeChange&&(n=this.callbacks.beforeChange(i,r)===!0),n)){let e=[];for(let t of i){if(t instanceof M)for(let n of t.options)n.id&&e.push(n.id);t instanceof j&&e.push(t.id)}this.callbacks.setSelected(e,!1),this.settings.closeOnSelect&&this.callbacks.close(),this.callbacks.afterChange&&this.callbacks.afterChange(i),this.updateDeselectAll(),this.updateMultipleValueDeleteVisibility()}};let r=document.createElementNS(`http://www.w3.org/2000/svg`,`svg`);r.setAttribute(`viewBox`,`0 0 100 100`);let i=document.createElementNS(`http://www.w3.org/2000/svg`,`path`);i.setAttribute(`d`,this.classes.optionDelete),r.appendChild(i),n.appendChild(r),t.appendChild(n),n.onkeydown=e=>{e.key===`Enter`&&n.click()}}return t}contentDiv(){let e=document.createElement(`div`);e.dataset.id=this.settings.id;let t=this.searchDiv();e.appendChild(t.main);let n=document.createElement(`div`);this.addClasses(n,this.classes.status),n.setAttribute(`aria-live`,`polite`),n.setAttribute(`aria-atomic`,`true`),n.setAttribute(`role`,`status`),e.appendChild(n);let r=this.listDiv();return e.appendChild(r),{main:e,search:t,status:n,list:r}}announce(e){this.settings.showSearch&&(this.content.status.textContent=e)}moveContent(){if(!this.isModalViewActive()){if(this.settings.contentPosition===`relative`){this.moveContentBelow();return}if(this.settings.openPosition===`down`){this.moveContentBelow();return}else if(this.settings.openPosition===`up`){this.moveContentAbove();return}this.putContent()===`up`?this.moveContentAbove():this.moveContentBelow()}}startPositionTracking(){this.settings.contentPosition!==`absolute`||this.isModalViewActive()||(this.stopPositionTracking(),!(typeof ResizeObserver>`u`)&&(this.positionObserver=new ResizeObserver(()=>{this.settings.isOpen&&(cancelAnimationFrame(this.positionObserverRaf),this.positionObserverRaf=requestAnimationFrame(()=>{this.moveContent()}))}),this.observePositionTargets()))}stopPositionTracking(){cancelAnimationFrame(this.positionObserverRaf),this.positionObserver?.disconnect(),this.positionObserver=null}observePositionTargets(){if(!this.positionObserver)return;let e=new Set,t=t=>{!t||e.has(t)||(e.add(t),this.positionObserver.observe(t))};t(this.main.main),t(this.content.main);let n=this.main.main.parentElement,r=this.settings.contentLocation;for(let e=0;n&&e<8&&(t(n),n!==r);e++)n=n.parentElement}searchDiv(){let e=document.createElement(`div`),t=document.createElement(`input`),n=document.createElement(`div`);this.addClasses(e,this.classes.search);let r={main:e,input:t};if(this.settings.showSearch||(this.addClasses(e,this.classes.hide),t.readOnly=!0),t.type=`search`,t.placeholder=this.settings.searchPlaceholder,t.tabIndex=-1,t.setAttribute(`aria-label`,this.settings.searchPlaceholder),t.setAttribute(`aria-autocomplete`,`list`),t.setAttribute(`autocapitalize`,`off`),t.setAttribute(`autocomplete`,`off`),t.setAttribute(`autocorrect`,`off`),t.setAttribute(`aria-hidden`,`true`),t.oninput=v(e=>{this.callbacks.search(e.target.value)},100),t.onkeydown=e=>{switch(e.key){case`ArrowUp`:case`ArrowDown`:return e.key===`ArrowDown`?this.highlight(`down`):this.highlight(`up`),!1;case`Tab`:return this.callbacks.close(),!0;case`Escape`:return this.callbacks.close(),!1;case` `:let t=this.content.list.querySelector(`.`+this.classes.getFirst(`highlighted`));return t?(t.click(),!1):!0;case`Enter`:let r=this.content.list.querySelector(`.`+this.classes.getFirst(`highlighted`));return r?(r.click(),!1):this.callbacks.addable?(n.click(),!1):!0}return!0},e.appendChild(t),this.callbacks.addable){this.addClasses(n,this.classes.addable);let t=document.createElementNS(`http://www.w3.org/2000/svg`,`svg`);t.setAttribute(`viewBox`,`0 0 100 100`);let i=document.createElementNS(`http://www.w3.org/2000/svg`,`path`);i.setAttribute(`d`,this.classes.addablePath),t.appendChild(i),n.appendChild(t),n.onclick=e=>{if(e.preventDefault(),e.stopPropagation(),!this.callbacks.addable)return;let t=this.content.search.input.value.trim();if(t===``){this.content.search.input.focus();return}let n=e=>{let t=new j(e);if(this.callbacks.addOption(t),this.settings.isMultiple){let e=this.store.getSelected();e.push(t.id),this.callbacks.setSelected(e,!0)}else this.callbacks.setSelected([t.id],!0);if(this.callbacks.search(``),this.settings.closeOnSelect){let e=o(this.content.main);setTimeout(()=>{this.callbacks.close()},e)}},r=this.callbacks.addable(t);r===!1||r==null||(r instanceof Promise?r.then(e=>{typeof e==`string`?n({text:e,value:e}):r instanceof Error?this.renderError(r.message):n(e)}):typeof r==`string`?n({text:r,value:r}):r instanceof Error?this.renderError(r.message):n(r))},e.appendChild(n),r.addable={main:n,svg:t,path:i}}return r}searchFocus(){this.content.search.input.focus({preventScroll:!0})}getOptions(e=!1,t=!1,n=!1){let r=`.`+this.classes.getFirst(`option`);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))}highlight(e){let t=this.getOptions(!0,!0,!0);if(t.length===0)return;if(t.length===1&&!t[0].classList.contains(this.classes.getFirst(`highlighted`))){this.addClasses(t[0],this.classes.highlighted);return}let n=!1;for(let e of t)e.classList.contains(this.classes.getFirst(`highlighted`))&&(n=!0);if(!n){for(let e of t)if(e.classList.contains(this.classes.getFirst(`selected`))){this.addClasses(e,this.classes.highlighted);break}}for(let n=0;n<t.length;n++)if(t[n].classList.contains(this.classes.getFirst(`highlighted`))){let r=t[n];this.removeClasses(r,this.classes.highlighted);let i=r.parentElement;if(i&&i.classList.contains(this.classes.getFirst(`mainOpen`))){let e=i.querySelector(`.`+this.classes.getFirst(`optgroupLabel`));e&&e.click()}let a=t[e===`down`?n+1<t.length?n+1:0:n-1>=0?n-1:t.length-1];this.addClasses(a,this.classes.highlighted),this.ensureElementInView(this.content.list,a),a.id&&this.main.main.setAttribute(`aria-activedescendant`,a.id);let o=a.parentElement;if(o&&o.classList.contains(this.classes.getFirst(`close`))){let e=o.querySelector(`.`+this.classes.getFirst(`optgroupLabel`));e&&e.click()}return}let r=t[e===`down`?0:t.length-1];this.addClasses(r,this.classes.highlighted),r.id&&this.main.main.setAttribute(`aria-activedescendant`,r.id),this.ensureElementInView(this.content.list,r)}listDiv(){let e=document.createElement(`div`);this.addClasses(e,this.classes.list);let t=this.settings.id+`-list`;return e.id=t,e.dataset.id=t,e}renderError(e){this.optionsListIsFullData=!1,this.content.list.innerHTML=``;let t=document.createElement(`div`);this.addClasses(t,this.classes.error),t.textContent=e,this.content.list.appendChild(t)}renderSearching(){this.optionsListIsFullData=!1,this.content.list.innerHTML=``;let e=document.createElement(`div`);this.addClasses(e,this.classes.searching),e.textContent=this.settings.searchingText,this.content.list.appendChild(e),this.announce(this.settings.searchingText)}renderOptions(e){if(this.lastSearchFilterTerm=``,this.lastRenderedOptions=e.map(e=>e instanceof j?[e]:e.options.map(e=>new j(e))).flat(),this.content.list.innerHTML=``,e.length===0){this.optionsListIsFullData=!1;let e=document.createElement(`div`);if(this.addClasses(e,this.classes.search),this.callbacks.addable){let t=this.settings.addableText.replace(`{value}`,this.content.search.input.value);e.innerHTML=t,this.announce(t)}else e.innerHTML=this.settings.searchText,this.announce(this.settings.searchText);this.content.list.appendChild(e);return}this.settings.allowDeselect&&!this.settings.isMultiple&&(this.store.filter(e=>e.placeholder,!1,!1).length||this.store.addOption(new j({text:``,value:``,selected:!1,placeholder:!0}),!0));let t=document.createDocumentFragment();for(let n of e){if(n instanceof M){let e=document.createElement(`div`);this.addClasses(e,this.classes.optgroup);let r=document.createElement(`div`);this.addClasses(r,this.classes.optgroupLabel),e.appendChild(r);let i=document.createElement(`div`);this.addClasses(i,this.classes.optgroupLabelText),i.textContent=n.label,r.appendChild(i);let a=document.createElement(`div`);if(this.addClasses(a,this.classes.optgroupActions),r.appendChild(a),this.settings.isMultiple&&n.selectAll){let e=document.createElement(`div`);this.addClasses(e,this.classes.optgroupSelectAll);let t=this.isOptgroupAllSelected(n.options);t&&this.addClasses(e,this.classes.selected);let r=document.createElement(`span`);r.textContent=this.optgroupSelectAllLabel(t),e.appendChild(r);let i=document.createElementNS(`http://www.w3.org/2000/svg`,`svg`);i.setAttribute(`viewBox`,`0 0 100 100`),e.appendChild(i);let o=document.createElementNS(`http://www.w3.org/2000/svg`,`path`);o.setAttribute(`d`,this.classes.optgroupSelectAllBox),i.appendChild(o);let s=document.createElementNS(`http://www.w3.org/2000/svg`,`path`);s.setAttribute(`d`,this.classes.optgroupSelectAllCheck),i.appendChild(s),e.addEventListener(`click`,e=>{e.preventDefault(),e.stopPropagation();let t=this.store.getSelected();if(this.isOptgroupAllSelected(n.options,new Set(t))){let e=t.filter(e=>{for(let t of n.options)if(e===t.id)return!1;return!0});this.callbacks.setSelected(e,!0);return}else{let e=n.options.map(e=>e.id).filter(e=>e!==void 0),r=t.concat(e);for(let e of n.options)e.id&&!this.store.getOptionByID(e.id)&&this.callbacks.addOption(new j(e));this.callbacks.setSelected(r,!0);return}}),a.appendChild(e)}if(n.closable!==`off`){let t=document.createElement(`div`);this.addClasses(t,this.classes.optgroupClosable);let i=document.createElementNS(`http://www.w3.org/2000/svg`,`svg`);i.setAttribute(`viewBox`,`0 0 100 100`),this.addClasses(i,this.classes.arrow),t.appendChild(i);let o=document.createElementNS(`http://www.w3.org/2000/svg`,`path`);i.appendChild(o),n.options.some(e=>e.selected)||this.content.search.input.value.trim()!==``?(this.addClasses(t,this.classes.mainOpen),o.setAttribute(`d`,this.classes.arrowOpen)):n.closable===`open`?(this.addClasses(e,this.classes.mainOpen),o.setAttribute(`d`,this.classes.arrowOpen)):n.closable===`close`&&(this.addClasses(e,this.classes.close),o.setAttribute(`d`,this.classes.arrowClose)),r.addEventListener(`click`,n=>{n.preventDefault(),n.stopPropagation(),this.isClosableOptgroupOpen(e,t)?(this.removeClasses(e,this.classes.mainOpen),this.removeClasses(t,this.classes.mainOpen),this.addClasses(e,this.classes.close),o.setAttribute(`d`,this.classes.arrowClose)):(this.closeOtherClosableOptgroups(e),this.removeClasses(e,this.classes.close),this.removeClasses(t,this.classes.mainOpen),this.addClasses(e,this.classes.mainOpen),o.setAttribute(`d`,this.classes.arrowOpen))}),a.appendChild(t)}e.appendChild(r);for(let r of n.options)e.appendChild(this.option(new j(r))),t.appendChild(e)}n instanceof j&&t.appendChild(this.option(n))}this.content.list.appendChild(t),this.setOptionsListFullData(e),this.announce(this.settings.resultsText.replace(`{count}`,String(this.lastRenderedOptions.length)))}canFilterOptionsInPlace(){return this.optionsListIsFullData?this.content.list.querySelector(`.`+this.classes.getFirst(`option`))!==null:!1}resetSearchFilterState(){this.lastSearchFilterTerm=``}filterOptionsInPlace(e,t){let n=e.trim();if(n===this.lastSearchFilterTerm)return;this.lastSearchFilterTerm=n;let r=[],i=this.content.list.querySelectorAll(`.`+this.classes.getFirst(`option`));for(let e of i){let i=e.dataset.id;if(!i)continue;let a=this.store.getOptionByID(i);if(!a)continue;let o=a.placeholder||!a.display||a.selected&&this.settings.hideSelected,s=t(a,n);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`))}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()}setOptionsListFullData(e){let t=this.store.getDataOptions(!1),n=e.map(e=>e instanceof j?[e]:e.options.map(e=>new j(e))).flat();if(n.length!==t.length){this.optionsListIsFullData=!1;return}let r=new Set(t.map(e=>e.id));this.optionsListIsFullData=n.every(e=>r.has(e.id))}isClosableOptgroupOpen(e,t){return e.classList.contains(this.classes.getFirst(`close`))?!1:e.classList.contains(this.classes.getFirst(`mainOpen`))||t.classList.contains(this.classes.getFirst(`mainOpen`))}closeClosableOptgroup(e){let t=e.querySelector(`.`+this.classes.getFirst(`optgroupClosable`));if(!t||e.classList.contains(this.classes.getFirst(`close`)))return;this.removeClasses(e,this.classes.mainOpen),this.removeClasses(t,this.classes.mainOpen),this.addClasses(e,this.classes.close);let n=t.querySelector(`path`);n&&n.setAttribute(`d`,this.classes.arrowClose)}closeOtherClosableOptgroups(e){let t=this.content.list.querySelectorAll(`.`+this.classes.getFirst(`optgroup`));for(let n of t)n!==e&&this.closeClosableOptgroup(n)}updateOptgroupVisibilityAfterSearch(e){let t=this.content.list.querySelectorAll(`.`+this.classes.getFirst(`optgroup`));for(let n of t){let t=n.querySelectorAll(`.`+this.classes.getFirst(`option`)),r=!1;for(let e of t)if(!e.classList.contains(this.classes.getFirst(`hide`))){r=!0;break}if(!r){this.addClasses(n,this.classes.hide);continue}this.removeClasses(n,this.classes.hide),e!==``&&(this.removeClasses(n,this.classes.close),this.addClasses(n,this.classes.mainOpen))}}updateSearchResultsMessage(e,t){if(this.removeListSearchMessage(),e>0)return;let n=document.createElement(`div`);if(this.addClasses(n,this.classes.search),this.callbacks.addable){let e=this.settings.addableText.replace(`{value}`,t);n.innerHTML=e,this.announce(e)}else n.innerHTML=this.settings.searchText,this.announce(this.settings.searchText);this.content.list.appendChild(n)}removeListSearchMessage(){this.content.list.querySelectorAll(`.`+this.classes.getFirst(`search`)).forEach(e=>e.remove())}setOptionElementContent(e,t,n){let r=n.trim();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`)}hasRenderedOptions(){return this.content.list.querySelector(`.`+this.classes.getFirst(`option`))!==null}canUpdateOptionSelectionInPlace(){return this.content.search.input.value.trim()===``?this.hasRenderedOptions():!1}updateOptionSelection(){let e=new Set(this.store.getSelected()),t=this.content.list.querySelectorAll(`.`+this.classes.getFirst(`option`)),n=null;for(let r of t){let t=r.dataset.id;if(!t)continue;let i=this.store.getOptionByID(t);if(!i)continue;let a=e.has(t);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)))}!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()}updateOptgroupSelectAllStates(){if(!this.settings.isMultiple)return;let e=new Set(this.store.getSelected()),t=this.content.list.querySelectorAll(`.`+this.classes.getFirst(`optgroup`));for(let n of t){let t=n.querySelector(`.`+this.classes.getFirst(`optgroupSelectAll`));if(!t)continue;let r=n.querySelectorAll(`.`+this.classes.getFirst(`option`)),i=r.length>0;for(let t of r){let n=t.dataset.id;if(!n||!e.has(n)){i=!1;break}}i?this.addClasses(t,this.classes.selected):this.removeClasses(t,this.classes.selected);let a=t.querySelector(`span`);a&&(a.textContent=this.optgroupSelectAllLabel(i))}}optgroupSelectAllLabel(e){return e?`Unselect All`:`Select All`}isOptgroupAllSelected(e,t){if(e.length===0)return!1;for(let n of e)if(!(t?n.id&&t.has(n.id):n.selected))return!1;return!0}option(e){if(e.placeholder){let e=document.createElement(`div`);return this.addClasses(e,this.classes.option),this.addClasses(e,this.classes.hide),e}let t=document.createElement(`div`);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=>{t.classList.add(e)}),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=>{t.preventDefault(),t.stopPropagation();let n=this.store.getSelected(),r=t.currentTarget,i=String(r.dataset.id),a=t.ctrlKey||t.metaKey;if(e.disabled||!this.settings.isMultiple&&e.selected&&!this.settings.allowDeselect||e.selected&&e.mandatory||this.settings.isMultiple&&this.settings.maxSelected<=n.length&&!e.selected||this.settings.isMultiple&&this.settings.minSelected>=n.length&&e.selected&&!a)return;let o=!1,s=this.store.getSelectedOptions(),c=[];if(this.settings.isMultiple){let n=s.some(e=>e.id===i);if(t.shiftKey&&this.lastSelectedOption){let t=this.lastRenderedOptions,n=t.findIndex(e=>e.id===this.lastSelectedOption.id),r=t.findIndex(t=>t.id===e.id);if(n>=0&&r>=0){let e=Math.min(n,r),i=Math.max(n,r),a=t.slice(e,i+1).filter(e=>!s.find(t=>t.id===e.id));c=s.length+a.length<=this.settings.maxSelected?s.concat(a):s}else c=s}else c=n?s.filter(e=>e.id!==i):s.concat(e),this.lastSelectedOption=e}if(this.settings.isMultiple||(c=e.selected?[]:[e]),this.callbacks.beforeChange||(o=!0),this.callbacks.beforeChange&&(o=this.callbacks.beforeChange(c,s)!==!1),o){this.store.getOptionByID(i)||this.callbacks.addOption(e),this.callbacks.setSelected(c.map(e=>e.id),!1);let n=t.ctrlKey||t.metaKey||t.shiftKey;this.settings.closeOnSelect&&!(this.settings.isMultiple&&n)&&this.callbacks.close(),this.callbacks.afterChange&&this.callbacks.afterChange(c)}}),t}destroy(){this.stopPositionTracking(),this.modalElements&&=(this.unlockBodyScroll(),this.content.main.parentElement===this.modalElements.dialog&&this.restoreContentOffscreen(),this.modalElements.overlay.remove(),null),this.main.main.remove(),this.content.main.remove()}highlightText(e,t,n){let r=t.trim();if(r===``)return e;let i=r.replace(/[.*+?^${}()|[\]\\]/g,`\\$&`),a=document.createElement(`div`);a.innerHTML=e;let o=e=>{if(e.nodeType===Node.TEXT_NODE){let t=e.textContent||``,r=RegExp(`(`+i+`)`,`i`);if(r.test(t)){let i=document.createElement(`span`);t.split(r).forEach((e,t)=>{if(e&&r.test(e)){let t=document.createElement(`mark`);t.className=n,t.textContent=e,i.appendChild(t)}else e&&i.appendChild(document.createTextNode(e))}),e.parentNode?.replaceChild(i,e)}}else e.nodeType===Node.ELEMENT_NODE&&Array.from(e.childNodes).forEach(e=>o(e))};return Array.from(a.childNodes).forEach(e=>o(e)),a.innerHTML}setContentDirection(e){let t=e===`above`,n=t?this.classes.dirAbove:this.classes.dirBelow,r=t?this.classes.dirBelow:this.classes.dirAbove;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){let e=this.main.main.offsetHeight,t=this.content.main.offsetHeight;this.content.main.style.margin=`-`+(e+t-1)+`px 0px 0px 0px`}else this.content.main.style.margin=`-1px 0px 0px 0px`}setContentPosition(){if(this.settings.contentPosition===`relative`)return;let e=this.main.main.getBoundingClientRect(),t,n;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`;let r=this.settings.contentWidth;this.content.main.style.width=``,this.content.main.style.minWidth=``,this.content.main.style.maxWidth=``,r?r.startsWith(`>`)?this.content.main.style.minWidth=r.slice(1):r.startsWith(`<`)?this.content.main.style.maxWidth=r.slice(1):this.content.main.style.width=r:this.content.main.style.width=e.width+`px`;let i=window.innerWidth-20,a=()=>{let e=this.content.main.getBoundingClientRect().right;if(e<=i)return;let t=e-i,n=parseFloat(this.content.main.style.left)||0;if(this.settings.contentPosition===`fixed`){let e=Math.max(20,n-t);this.content.main.style.left=e+`px`}else{let e=Math.max(window.scrollX+20,n-t);this.content.main.style.left=e+`px`}};requestAnimationFrame(()=>{a(),requestAnimationFrame(a)})}moveContentAbove(){this.setContentDirection(`above`),this.setContentPosition()}moveContentBelow(){this.setContentDirection(`below`),this.setContentPosition()}ensureElementInView(e,t){let n=e.scrollTop+e.offsetTop,r=n+e.clientHeight,i=t.offsetTop,a=i+t.clientHeight;i<n?e.scrollTop-=n-i:a>r&&(e.scrollTop+=a-r)}putContent(){let e=this.main.main.offsetHeight,t=this.main.main.getBoundingClientRect(),n=this.content.main.offsetHeight;return window.innerHeight-(t.top+e)<=n&&t.top>n?`up`:`down`}updateDeselectAll(){if(!this.store||!this.settings)return;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;r&&!(n&&!t)&&!i?this.removeClasses(a,o):this.addClasses(a,o)}};function F(e,t){let n={classChanged:!1,disabledChanged:!1,optgroupOptionChanged:!1,selectionChanged:!1};for(let r of e){if(r.target===t&&(r.attributeName===`disabled`&&(n.disabledChanged=!0),r.attributeName===`class`&&(n.classChanged=!0),r.type===`childList`)){for(let e of Array.from(r.addedNodes))if(e.nodeName===`OPTION`&&e.value===t.value){n.selectionChanged=!0;break}n.optgroupOptionChanged=!0}(r.target.nodeName===`OPTGROUP`||r.target.nodeName===`OPTION`)&&(n.optgroupOptionChanged=!0)}return n}var I=class{select;onValueChange;onClassChange;onDisabledChange;onOptionsChange;onLabelClick;listen=!1;observer=null;isUpdating=!1;pendingOptionsChange=null;preventNativeSelect=null;preventNativeSelectMousedown=null;preventNativeSelectFocus=null;restoreAriaHiddenOnBlur=null;constructor(e){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)}enable(){this.select.disabled=!1}disable(){this.select.disabled=!0}hideUI(){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=>{e.preventDefault(),e.stopPropagation(),e.stopImmediatePropagation()},this.preventNativeSelectMousedown=e=>{e.preventDefault(),e.stopPropagation(),e.stopImmediatePropagation()},this.preventNativeSelectFocus=e=>{this.select.removeAttribute(`aria-hidden`),e.preventDefault(),e.stopPropagation(),e.stopImmediatePropagation()},this.restoreAriaHiddenOnBlur=()=>{this.select.setAttribute(`aria-hidden`,`true`)},this.select.addEventListener(`click`,this.preventNativeSelect,{capture:!0,passive:!1}),this.select.addEventListener(`mousedown`,this.preventNativeSelectMousedown,{capture:!0,passive:!1}),this.select.addEventListener(`focus`,this.preventNativeSelectFocus,{capture:!0,passive:!1}),this.select.addEventListener(`blur`,this.restoreAriaHiddenOnBlur,{capture:!0,passive:!0}))}showUI(){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)}changeListen(e){this.listen=e,e&&this.observer&&this.observer.observe(this.select,{subtree:!0,childList:!0,attributes:!0}),e||this.observer&&this.observer.disconnect()}valueChange(e){return this.listen&&this.onValueChange&&this.onValueChange(this.getSelectedOptions()),!0}observeCall(e){if(!this.listen)return;let{classChanged:t,disabledChanged:n,optgroupOptionChanged:r,selectionChanged:i}=F(e,this.select),a=i;if(t&&this.onClassChange&&this.onClassChange(this.select.className.split(` `)),n&&this.onDisabledChange&&(this.changeListen(!1),this.onDisabledChange(this.select.disabled),this.changeListen(!0)),r&&this.onOptionsChange){if(this.isUpdating){if(this.select.options.length>0){let e=this.getData();e.length>0&&(this.pendingOptionsChange=e)}a&&this.select.dispatchEvent(new Event(`change`));return}this.changeListen(!1),this.onOptionsChange(this.getData()),this.changeListen(!0),a=!1}a&&this.select.dispatchEvent(new Event(`change`))}getData(){let e=[],t=this.select.childNodes;for(let n of t)n.nodeName===`OPTGROUP`&&e.push(this.getDataFromOptgroup(n)),n.nodeName===`OPTION`&&e.push(this.getDataFromOption(n));return e}getDataFromOptgroup(e){let t={id:e.id,label:e.label,selectAll:e.dataset?e.dataset.selectall===`true`:!1,closable:e.dataset?e.dataset.closable:`off`,options:[]},n=e.childNodes;for(let e of n)e.nodeName===`OPTION`&&t.options.push(this.getDataFromOption(e));return t}getDataFromOption(e){return{id:e.id,value:e.value,text:e.text,html:e.dataset&&e.dataset.html?e.dataset.html:``,defaultSelected:e.defaultSelected,selected:e.selected,display:e.style.display!==`none`,disabled:e.disabled,mandatory:e.dataset?e.dataset.mandatory===`true`:!1,placeholder:e.dataset.placeholder===`true`,class:e.className,style:e.style.cssText,data:p(e.dataset)}}getSelectedOptions(){let e=[],t=this.select.childNodes;for(let n of t){if(n.nodeName===`OPTGROUP`){let t=n.childNodes;for(let n of t)if(n.nodeName===`OPTION`){let t=n;t.selected&&e.push(this.getDataFromOption(t))}}if(n.nodeName===`OPTION`){let t=n;t.selected&&e.push(this.getDataFromOption(t))}}return e}getSelectedValues(){return this.getSelectedOptions().map(e=>e.value)}setSelected(e){this.changeListen(!1);let t=this.select.childNodes;for(let n of t){if(n.nodeName===`OPTGROUP`){let t=n.childNodes;for(let n of t)if(n.nodeName===`OPTION`){let t=n;t.selected=e.includes(t.id)}}if(n.nodeName===`OPTION`){let t=n;t.selected=e.includes(t.id)}}let n=this.getSelectedOptions();this.select.multiple||(this.select.value=n.length===1?n[0].value:``),this.changeListen(!0)}setSelectedByValue(e){this.changeListen(!1);let t=this.select.childNodes;for(let n of t){if(n.nodeName===`OPTGROUP`){let t=n.childNodes;for(let n of t)if(n.nodeName===`OPTION`){let t=n;t.selected=e.includes(t.value)}}if(n.nodeName===`OPTION`){let t=n;t.selected=e.includes(t.value)}}let n=this.getSelectedOptions();this.select.multiple||(this.select.value=n.length===1?n[0].value:``),this.changeListen(!0)}updateSelect(e,t,n){this.changeListen(!1),e&&(this.select.dataset.id=e),t&&(this.select.style.cssText=t),n&&(this.select.className=``,n.forEach(e=>{e.trim()!==``&&this.select.classList.add(e.trim())})),this.changeListen(!0)}updateOptions(e){if(!(!e||e.length===0)){this.isUpdating=!0,this.pendingOptionsChange=null,this.changeListen(!1),this.select.innerHTML=``;for(let t of e)t instanceof M&&this.select.appendChild(this.createOptgroup(t)),t instanceof j&&this.select.appendChild(this.createOption(t));if(this.select.dispatchEvent(new Event(`change`,{bubbles:!0})),this.changeListen(!0),this.isUpdating=!1,this.pendingOptionsChange!==null){let e=this.pendingOptionsChange;e.length>0&&this.onOptionsChange?(this.pendingOptionsChange=null,this.changeListen(!1),this.onOptionsChange(e),this.changeListen(!0)):this.pendingOptionsChange=null}}}createOptgroup(e){let t=document.createElement(`optgroup`);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));return t}createOption(e){let t=document.createElement(`option`);return t.id=e.id,t.value=e.value,t.textContent=e.text,e.html!==``&&t.setAttribute(`data-html`,e.html),t.defaultSelected=e.defaultSelected,t.selected=e.selected,e.disabled&&(t.disabled=!0),e.display||(t.style.display=`none`),e.placeholder&&t.setAttribute(`data-placeholder`,`true`),e.mandatory&&t.setAttribute(`data-mandatory`,`true`),e.class&&e.class.split(` `).forEach(e=>{t.classList.add(e)}),e.data&&typeof e.data==`object`&&Object.keys(e.data).forEach(n=>{t.setAttribute(`data-`+D(n),e.data[n])}),t}setupLabelHandlers(){let e=[],t=this.select.id;t&&document.querySelectorAll(`label[for="${t}"]`).forEach(t=>e.push(t));let n=this.select.parentElement;for(;n&&n!==document.body;){if(n.tagName===`LABEL`){e.push(n);break}n=n.parentElement}Array.from(new Set(e)).forEach(e=>{if(e.__slimSelectLabelHandler)return;let t=e=>{let t=e.target,n=_(t,this.select.dataset.id);e.preventDefault(),!n&&this.onLabelClick&&this.onLabelClick()};e.__slimSelectLabelHandler=t,e.addEventListener(`click`,t,{capture:!0,passive:!1})})}removeLabelHandlers(){let e=[],t=this.select.id;t&&document.querySelectorAll(`label[for="${t}"]`).forEach(t=>e.push(t));let n=this.select.parentElement;for(;n&&n!==document.body;){if(n.tagName===`LABEL`){e.push(n);break}n=n.parentElement}Array.from(new Set(e)).forEach(e=>{let t=e.__slimSelectLabelHandler;t&&(e.removeEventListener(`click`,t,{capture:!0}),delete e.__slimSelectLabelHandler)})}destroy(){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()}};function L(e,t){return E(e.getData(!1),t)}function R(e,t){let n=Array.isArray(t)?t:[t],r=e.getDataOptions(!1),i=[];for(let e of n){if(r.find(t=>t.id==e)){i.push(e);continue}for(let t of r.filter(t=>t.value==e))i.push(t.id)}return i}var z=class{deps;queue=[];flushScheduled=!1;isSyncing=!1;constructor(e){this.deps=e}enqueue(e){if(this.queue.push(e),e.source===`native`){this.flushScheduled||(this.flushScheduled=!0,queueMicrotask(()=>this.flush()));return}this.isSyncing||this.flush()}flush(){if(this.flushScheduled=!1,this.queue.length===0)return;let e=this.coalesceBatch(this.queue);this.queue=[],this.isSyncing=!0;try{for(let t of e)this.applyChange(t)}finally{this.isSyncing=!1,this.queue.length>0&&this.flush()}}coalesceBatch(e){let t=e.some(e=>e.type===`structure`),n=e.some(e=>e.type===`addOption`);if(t||n){let t=e.filter(e=>e.type===`structure`||e.type===`addOption`),n=t[t.length-1];return n?.type===`structure`?[n]:t}let r=e.filter(e=>e.type===`selection`);return r.length>0?[r[r.length-1]]:e}applyChange(e){switch(e.type){case`structure`:this.applyStructure(e.data,e.source,e.preserveSelection,e.isSearchResult);break;case`selection`:this.applySelection(e.values,e.source,e.runAfterChange!==!1);break;case`addOption`:this.applyAddOption(e.option);break}}applyStructure(e,t,n=!1,r=!1){let{store:i,select:a,render:o,events:s}=this.deps;if(L(i,e))return;let c=i.getSelected(),l=i.validateDataArray(e);if(l){s.error?s.error(l):this.deps.onError&&this.deps.onError(l);return}i.setData(e,n);let u=i.getData(!1);r||i.snapshotCatalog(),a.updateOptions(u),o.renderValues(),o.renderOptions(u),s.afterChange&&!y(c,i.getSelected())&&s.afterChange(i.getSelectedOptions())}applySelection(e,t,n){let{store:r,select:i,render:a,events:o}=this.deps,s=r.getSelected(),c=R(r,e);if(y(s,c))return;r.setSelectedBy(`id`,c),i.setSelectedByValue(r.getSelectedValues()),a.renderValues();let l=a.content.search.input.value.trim();l===``?a.canUpdateOptionSelectionInPlace()?a.updateOptionSelection():a.renderOptions(r.getData(!1)):a.hasRenderedOptions()?a.updateOptionSelection():this.deps.search&&this.deps.search(l),n&&o.afterChange&&!y(s,r.getSelected())&&o.afterChange(r.getSelectedOptions())}applyAddOption(e){let{store:t,select:n,render:r,events:i}=this.deps,a=t.getSelected(),o=r.content.search.input.value.trim()!==``&&!!this.deps.search,s=e.value??e.text??``,c=e=>{for(let t of e){if(t instanceof M){if(t.options.some(e=>(e.value??e.text)===s))return!0;continue}if((t.value??t.text)===s)return!0}return!1};if(!c(t.getData(!1)))if(o){let n=t.getCatalogData();c(n)||t.setData([...n,new j(e)],!0),t.snapshotCatalog()}else t.addOption(e),t.snapshotCatalog();let l=t.getData(!1);n.updateOptions(l),r.renderValues(),r.renderOptions(l),i.afterChange&&!y(a,t.getSelected())&&i.afterChange(t.getSelectedOptions())}},B=class{selectEl;settings;cssClasses;select;store;render;sync;lifecycle;globalEvents;searchGeneration=0;events={search:void 0,searchFilter:(e,t)=>e.text.toLowerCase().indexOf(t.toLowerCase())!==-1,addable:void 0,beforeChange:void 0,afterChange:void 0,beforeOpen:void 0,afterOpen:void 0,beforeClose:void 0,afterClose:void 0};constructor(e){if(this.selectEl=typeof e.select==`string`?document.querySelector(e.select):e.select,!this.selectEl){e.events&&e.events.error&&e.events.error(Error(`Could not find select element`));return}if(this.selectEl.tagName!==`SELECT`){e.events&&e.events.error&&e.events.error(Error(`Element isnt of type select`));return}this.selectEl.dataset.ssid&&this.destroy(),this.settings=new f(e.settings),this.cssClasses=new n(e.cssClasses);let t=[`beforeOpen`,`afterOpen`,`beforeClose`,`afterClose`];for(let n in e.events)e.events.hasOwnProperty(n)&&(t.indexOf(n)===-1?this.events[n]=e.events[n]:this.events[n]=v(e.events[n],100));this.settings.disabled=e.settings?.disabled?e.settings.disabled:this.selectEl.disabled,this.settings.isMultiple=this.selectEl.multiple,this.settings.style=this.selectEl.style.cssText,this.settings.class=this.selectEl.className.split(` `),this.select=new 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=>{this.settings.class=e,this.render.updateClassStyles()},this.select.onDisabledChange=e=>{e?this.disable():this.enable()},this.select.onLabelClick=()=>{this.settings.disabled||(this.settings.isOpen?this.close():this.open())};let r=e.data?e.data:this.select.getData();this.store=new N(this.settings.isMultiple?`multiple`:`single`,r),e.data&&this.select.updateOptions(this.store.getData());let i={open:this.open.bind(this),close:this.close.bind(this),addable:this.events.addable?this.events.addable:void 0,setSelected:(e,t)=>{this.sync.enqueue({type:`selection`,values:e,source:`ui`,runAfterChange:t})},addOption:e=>{this.sync.enqueue({type:`addOption`,option:e,source:`ui`})},search:this.search.bind(this),beforeChange:this.events.beforeChange,afterChange:this.events.afterChange};this.settings.modalTitle=e.settings?.modalTitle??h(this.selectEl),this.render=new P(this.settings,this.cssClasses,this.store,i),this.settings.timeoutDelay=s(this.render.content.main,e.settings?.timeoutDelay),this.sync=new z({select:this.select,store:this.store,render:this.render,events:this.events,search:this.search.bind(this)}),this.select.onValueChange=e=>{this.sync.enqueue({type:`selection`,values:e.map(e=>e.id),source:`native`})},this.select.onOptionsChange=e=>{this.sync.enqueue({type:`structure`,data:e||[],source:`native`})},this.lifecycle=new A({beforeOpen:this.events.beforeOpen,afterOpen:this.events.afterOpen,beforeClose:this.events.beforeClose,afterClose:()=>{this.render.clearDirectionClasses(),this.render.finalizeModalClose(),this.events.afterClose&&this.events.afterClose()},onOpenReady:()=>this.globalEvents.attachDocumentClick(),onCloseReady:()=>this.globalEvents.detachDocumentClick()},{timeoutDelay:this.settings.timeoutDelay,waitForAnimation:(e,t)=>this.render.waitForAnimation(e,t)}),this.globalEvents=new k({onDocumentClick:this.documentClick.bind(this),onWindowResize:()=>{!this.settings.isOpen&&!this.settings.isFullOpen||this.render.moveContent()},onWindowScroll:()=>{!this.settings.isOpen&&!this.settings.isFullOpen||this.render.moveContent()},onVisibilityChange:()=>{document.hidden&&this.close()}}),this.render.renderValues(),this.render.renderOptions(this.store.getData(!1));let a=this.selectEl.getAttribute(`aria-label`),o=this.selectEl.getAttribute(`aria-labelledby`);if(a)this.render.main.main.setAttribute(`aria-label`,a);else if(o)this.render.main.main.removeAttribute(`aria-label`),this.render.main.main.setAttribute(`aria-labelledby`,o);else if(this.selectEl.labels&&this.selectEl.labels.length>0){let e=Array.from(this.selectEl.labels).map((e,t)=>(e.id||=`${this.settings.id}-label-${t}`,e.id));this.render.main.main.removeAttribute(`aria-label`),this.render.main.main.setAttribute(`aria-labelledby`,e.join(` `))}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}enable(){this.settings.disabled=!1,this.select.enable(),this.render.enable()}disable(){this.settings.disabled=!0,this.select.disable(),this.render.disable()}getData(){return this.store.getData()}setData(e){this.sync.enqueue({type:`structure`,data:e,source:`api`})}getSelected(){let e=this.store.getSelectedOptions();return this.settings.keepOrder&&(e=this.store.selectedOrderOptions(e)),e.map(e=>e.value)}setSelected(e,t=!0){this.sync.enqueue({type:`selection`,values:e,source:`api`,runAfterChange:t})}addOption(e){this.sync.enqueue({type:`addOption`,option:e,source:`api`})}open(){if(this.settings.disabled||this.settings.isOpen)return;this.lifecycle.cancelPending(),this.render.open(),this.settings.showSearch&&this.settings.focusSearch&&this.render.searchFocus(),this.settings.isOpen=!0,this.lifecycle.requestOpen().then(()=>{this.settings.isOpen&&(this.settings.isFullOpen=this.lifecycle.isFullOpen,this.settings.isOpen=this.lifecycle.isOpen)}),this.settings.contentPosition===`absolute`&&!this.render.isModalViewActive()&&this.render.startPositionTracking();let e=this.render.content.search.input.value.trim();e!==``&&this.search(e)}close(e=null){!this.settings.isOpen||this.settings.alwaysOpen||(this.lifecycle.cancelPending(),this.render.close(),!this.settings.keepSearch&&this.render.content.search.input.value!==``&&(this.sync.flush(),this.search(``)),this.render.mainFocus(e),this.settings.isOpen=!1,this.settings.isFullOpen=!1,this.lifecycle.requestClose().then(()=>{this.settings.isOpen||(this.settings.isOpen=this.lifecycle.isOpen,this.settings.isFullOpen=this.lifecycle.isFullOpen)}),this.render.stopPositionTracking())}search(e){let t=e.trim();if(this.render.content.search.input.value!==t&&(this.render.content.search.input.value=t),t===``){this.clearSearch();return}if(this.events.search){this.runApiSearch(t);return}this.runLocalSearch(t)}clearSearch(){if(this.searchGeneration++,!this.events.search&&this.render.canFilterOptionsInPlace()){this.render.filterOptionsInPlace(``,this.events.searchFilter),this.render.resetSearchFilterState();return}this.render.resetSearchFilterState(),this.sync.enqueue({type:`structure`,data:this.store.getCatalogData(),source:`api`,preserveSelection:!0})}runLocalSearch(e){if(this.render.canFilterOptionsInPlace()){this.render.filterOptionsInPlace(e,this.events.searchFilter);return}let t=this.store.search(e,this.events.searchFilter);this.render.renderOptions(t)}runApiSearch(e){let t=++this.searchGeneration;this.render.renderSearching();let n=this.events.search(e,this.store.getSelectedOptions(),this.store.getCatalogData()),r=n=>{t===this.searchGeneration&&this.render.content.search.input.value.trim()===e&&this.sync.enqueue({type:`structure`,data:n,source:`api`,preserveSelection:!0,isSearchResult:!0})};if(n instanceof Promise){n.then(r).catch(e=>{t===this.searchGeneration&&this.render.renderError(typeof e==`string`?e:e.message)});return}if(Array.isArray(n)){r(n);return}this.render.renderError(`Search event must return a promise or an array of data`)}destroy(){this.lifecycle.destroy(),this.render.stopPositionTracking(),this.globalEvents.detach({listenScroll:this.settings.openPosition===`auto`}),this.store.setData([]),this.render.destroy(),this.select.destroy()}documentClick(e){this.settings.isOpen&&e.target&&!_(e.target,this.settings.id)&&this.close(e.type)}},V=(0,t.defineComponent)({name:`SlimSelect`,props:{modelValue:{type:[String,Array,void 0]},multiple:{type:Boolean,default:!1},data:{type:Array,required:!0},settings:{type:Object},events:{type:Object,default:()=>({})}},emits:[`update:modelValue`],data(){return{slim:null,lastAppliedData:null}},mounted(){let e={select:this.$refs.slim,data:this.data};this.settings&&(e.settings=this.settings);let n=this.events?.afterChange;e.events={...this.events,afterChange:e=>{this.handleAfterChange(e,n)}},this.slim=new B(e),this.lastAppliedData=structuredClone((0,t.toRaw)(this.data)),this.syncModelValueToSlimSelect(!1)},beforeUnmount(){this.slim&&this.slim.destroy()},watch:{modelValue:{handler:function(e){this.slim&&this.syncModelValueToSlimSelect(!1)}},data:{handler:function(e){this.slim&&(this.lastAppliedData!==null&&E(this.lastAppliedData,(0,t.toRaw)(e))||(this.slim.setData(e),this.lastAppliedData=structuredClone((0,t.toRaw)(e)),this.syncModelValueToSlimSelect(!1)))},deep:!0}},computed:{value:{get(){return this.getCleanValue(this.$props.modelValue)},set(e){this.$emit(`update:modelValue`,e)}}},methods:{getSlimSelect(){return this.slim},handleAfterChange(e,t){if(!this.slim)return;let n=this.multiple?e.map(e=>e.value):e.length>0?e[0].value:``,r=this.getCleanValue(this.$props.modelValue),i=this.slim.store.getDataOptions(!1),a=Array.isArray(r)?r.length>0&&r.every(e=>i.some(t=>t.value===e)):r!==``&&i.some(e=>e.value===r),o=Array.isArray(n)?n.length>0&&n.every(e=>i.some(t=>t.value===e)):n!==``&&i.some(e=>e.value===n);(Array.isArray(n)&&Array.isArray(this.value)?JSON.stringify(n.sort())!==JSON.stringify(this.value.sort()):this.value!==n)&&(a||o)&&(this.value=n),t&&t(e)},getCleanValue(e){let t=this.$props.multiple;return typeof e==`string`?t?[e]:e:Array.isArray(e)?t?e:e[0]:t?[]:``},syncModelValueToSlimSelect(e=!1){if(!this.slim||this.$props.modelValue===void 0)return;let t=this.getCleanValue(this.$props.modelValue),n=this.slim.getData().flatMap(e=>`label`in e?e.options:[e]);if(!(Array.isArray(t)?t.length>0&&t.every(e=>n.some(t=>t.value===e)):t!==``&&n.some(e=>e.value===t))&&!Array.isArray(t)&&!n.some(e=>e.placeholder)){let e=this.slim.getData();this.slim.setData([{value:``,text:``,placeholder:!0}].concat(e))}this.slim.setSelected(t,e)}}}),H=(e,t)=>{let n=e.__vccOpts||e;for(let[e,r]of t)n[e]=r;return n},U=[`multiple`];function W(e,n,r,i,a,o){return(0,t.openBlock)(),(0,t.createElementBlock)(`select`,{multiple:e.multiple,ref:`slim`},null,8,U)}var G=H(V,[[`render`,W]]);e.Optgroup=M,e.Option=j,e.Settings=f,e.default=G});
|
|
1
|
+
(function(e,t){typeof exports==`object`&&typeof module<`u`?t(exports,require("vue")):typeof define==`function`&&define.amd?define([`exports`,`vue`],t):(e=typeof globalThis<`u`?globalThis:e||self,t(e.SlimSelectVue={},e.Vue))})(this,function(e,t){Object.defineProperties(e,{__esModule:{value:!0},[Symbol.toStringTag]:{value:`Module`}});var n=class{main;placeholder;values;single;multiString;max;value;valueText;valueDelete;valueOut;deselect;deselectPath;arrow;arrowClose;arrowOpen;content;contentOpen;dirAbove;dirBelow;search;searchHighlighter;searching;status;addable;addablePath;list;optgroup;optgroupLabel;optgroupLabelText;optgroupActions;optgroupSelectAll;optgroupSelectAllBox;optgroupSelectAllCheck;optgroupClosable;option;optionDelete;highlighted;modalOverlay;modalDialog;modalTitle;modalClose;modalContent;mainOpen;close;selected;error;disabled;hide;constructor(e){e||={};let t=(e=``,t=``)=>`${e} ${t}`.trim();this.main=t(`ss-main`,e.main),this.placeholder=t(`ss-placeholder`,e.placeholder),this.values=t(`ss-values`,e.values),this.single=t(`ss-single`,e.single),this.multiString=t(`ss-multi-string`,e.multiString),this.max=t(`ss-max`,e.max),this.value=t(`ss-value`,e.value),this.valueText=t(`ss-value-text`,e.valueText),this.valueDelete=t(`ss-value-delete`,e.valueDelete),this.valueOut=t(`ss-value-out`,e.valueOut),this.deselect=t(`ss-deselect`,e.deselect),this.deselectPath=e.deselectPath||`M10,10 L90,90 M10,90 L90,10`,this.arrow=t(`ss-arrow`,e.arrow),this.arrowClose=e.arrowClose||`M10,30 L50,70 L90,30`,this.arrowOpen=e.arrowOpen||`M10,70 L50,30 L90,70`,this.content=t(`ss-content`,e.content),this.contentOpen=t(`ss-open`,e.contentOpen),this.dirAbove=t(`ss-dir-above`,e.dirAbove),this.dirBelow=t(`ss-dir-below`,e.dirBelow),this.search=t(`ss-search`,e.search),this.searchHighlighter=t(`ss-search-highlight`,e.searchHighlighter),this.searching=t(`ss-searching`,e.searching),this.status=t(`ss-status`,e.status),this.addable=t(`ss-addable`,e.addable),this.addablePath=e.addablePath||`M50,10 L50,90 M10,50 L90,50`,this.list=t(`ss-list`,e.list),this.optgroup=t(`ss-optgroup`,e.optgroup),this.optgroupLabel=t(`ss-optgroup-label`,e.optgroupLabel),this.optgroupLabelText=t(`ss-optgroup-label-text`,e.optgroupLabelText),this.optgroupActions=t(`ss-optgroup-actions`,e.optgroupActions),this.optgroupSelectAll=t(`ss-selectall`,e.optgroupSelectAll),this.optgroupSelectAllBox=e.optgroupSelectAllBox||`M60,10 L10,10 L10,90 L90,90 L90,50`,this.optgroupSelectAllCheck=e.optgroupSelectAllCheck||`M30,45 L50,70 L90,10`,this.optgroupClosable=t(`ss-closable`,e.optgroupClosable),this.option=t(`ss-option`,e.option),this.optionDelete=e.optionDelete||`M10,10 L90,90 M10,90 L90,10`,this.highlighted=t(`ss-highlighted`,e.highlighted),this.modalOverlay=t(`ss-modal-overlay`,e.modalOverlay),this.modalDialog=t(`ss-modal-dialog`,e.modalDialog),this.modalTitle=t(`ss-modal-title`,e.modalTitle),this.modalClose=t(`ss-modal-close`,e.modalClose),this.modalContent=t(`ss-modal-content`,e.modalContent),this.mainOpen=t(`ss-open`,e.mainOpen),this.close=t(`ss-close`,e.close),this.selected=t(`ss-selected`,e.selected),this.error=t(`ss-error`,e.error),this.disabled=t(`ss-disabled`,e.disabled),this.hide=t(`ss-hide`,e.hide)}getFirst(e){return this[e].split(` `)[0]}},r=200,i=[`transform`,`opacity`];function a(e,t=r){let n=e.trim();if(!n)return t;if(n.endsWith(`ms`)){let e=parseFloat(n);return Number.isNaN(e)?t:e}if(n.endsWith(`s`)){let e=parseFloat(n);return Number.isNaN(e)?t:e*1e3}let i=parseFloat(n);return Number.isNaN(i)?t:i}function o(e,t=r){return a(getComputedStyle(e).getPropertyValue(`--ss-animation-timing`).trim(),t)}function s(e,t,n=r){let i=o(e,n)+50;return t===void 0?i:Math.max(i,t)}function c(){return typeof window>`u`||typeof window.matchMedia!=`function`?!1:window.matchMedia(`(prefers-reduced-motion: reduce)`).matches}function l(e){return e===void 0?null:new Set(Array.isArray(e)?e:[e])}function u(e,t,n=r,i){if(c()||i?.aborted)return Promise.resolve();let a=l(t);return new Promise(t=>{let r=null,o=!1,s=()=>{o||(o=!0,e.removeEventListener(`transitionend`,l),i?.removeEventListener(`abort`,c),r&&clearTimeout(r),t())},c=()=>s(),l=t=>{t.target===e&&(a&&(!a.has(t.propertyName)||(a.delete(t.propertyName),a.size>0))||s())};i?.addEventListener(`abort`,c,{once:!0}),e.addEventListener(`transitionend`,l),r=setTimeout(s,n)})}function d(e,t,n=r,i){return c()||i?.aborted?Promise.resolve():new Promise(r=>{let a=null,o=!1,s=()=>{o||(o=!0,e.removeEventListener(`animationend`,l),i?.removeEventListener(`abort`,c),a&&clearTimeout(a),r())},c=()=>s(),l=n=>{n.target===e&&(t&&n.animationName!==t||s())};i?.addEventListener(`abort`,c,{once:!0}),e.addEventListener(`animationend`,l),a=setTimeout(s,n)})}var f=class{id=``;style=``;class=[];isMultiple=!1;isOpen=!1;isFullOpen=!1;disabled;alwaysOpen;showSearch;focusSearch;keepSearch;ariaLabel;searchPlaceholder;searchText;searchingText;resultsText;deselectText;removeText;searchHighlight;closeOnSelect;contentLocation;contentPosition;contentWidth;openPosition;placeholderText;allowDeselect;hideSelected;multiString;keepOrder;showOptionTooltips;minSelected;maxSelected;timeoutDelay;maxValuesShown;maxValuesMessage;addableText;modal;modalTitle;constructor(e){e||={},this.id=`ss-`+g(),this.style=e.style||``,this.class=e.class||[],this.disabled=e.disabled===void 0?!1:e.disabled,this.alwaysOpen=e.alwaysOpen===void 0?!1:e.alwaysOpen,this.showSearch=e.showSearch===void 0?!0:e.showSearch,this.focusSearch=e.focusSearch===void 0?!0:e.focusSearch,this.keepSearch=e.keepSearch===void 0?!1:e.keepSearch,this.ariaLabel=e.ariaLabel||`Combobox`,this.searchPlaceholder=e.searchPlaceholder||`Search...`,this.searchText=e.searchText||`No Results`,this.searchingText=e.searchingText||`Searching...`,this.resultsText=e.resultsText||`{count} results available`,this.deselectText=e.deselectText||`Clear`,this.removeText=e.removeText||`Remove`,this.searchHighlight=e.searchHighlight===void 0?!1:e.searchHighlight,this.closeOnSelect=e.closeOnSelect===void 0?!0:e.closeOnSelect,this.contentLocation=e.contentLocation||document.body,this.contentPosition=e.contentPosition||`absolute`,this.contentWidth=e.contentWidth||``,this.openPosition=e.openPosition||`auto`,this.placeholderText=e.placeholderText===void 0?`Select Value`:e.placeholderText,this.allowDeselect=e.allowDeselect===void 0?!1:e.allowDeselect,this.hideSelected=e.hideSelected===void 0?!1:e.hideSelected,this.multiString=e.multiString===void 0?!1:e.multiString,this.keepOrder=e.keepOrder===void 0?!1:e.keepOrder,this.showOptionTooltips=e.showOptionTooltips===void 0?!1:e.showOptionTooltips,this.minSelected=e.minSelected||0,this.maxSelected=e.maxSelected||1e3,this.timeoutDelay=e.timeoutDelay||200,this.maxValuesShown=e.maxValuesShown||20,this.maxValuesMessage=e.maxValuesMessage||`{number} selected`,this.addableText=e.addableText||`Press "Enter" to add {value}`,this.modal=e.modal||`mobile`,this.modalTitle=e.modalTitle||``}};function p(e){if(!e)return{};let t={};for(let n of Object.keys(e)){let r=e[n];r!==void 0&&(t[n]=r)}return t}function m(e){let t=e.cloneNode(!0);return t.querySelectorAll(`select, option, optgroup, textarea, input, button`).forEach(e=>e.remove()),t.textContent?.replace(/\s+/g,` `).trim()||``}function h(e){if(e.labels&&e.labels.length>0){let t=Array.from(e.labels).map(m).filter(Boolean);if(t.length>0)return[...new Set(t)].join(` `)}return e.getAttribute(`aria-label`)?.trim()||``}function g(){return Math.random().toString(36).substring(2,10)}function _(e,t){function n(e,n){return n&&e&&e.classList&&e.classList.contains(n)||n&&e&&e.dataset&&e.dataset.id&&e.dataset.id===t?e:null}function r(e,t){return!e||e===document?null:n(e,t)?e:r(e.parentNode,t)}return n(e,t)||r(e,t)}function v(e,t=50,n=!1){let r;return function(...i){let a=self,o=()=>{r=null,n||e.apply(a,i)},s=n&&!r;clearTimeout(r),r=setTimeout(o,t),s&&e.apply(a,i)}}function y(e,t){if(e.length!==t.length)return!1;let n=[...e].sort(),r=[...t].sort();return n.every((e,t)=>e===r[t])}var b=[`id`,`value`,`text`,`html`,`defaultSelected`,`selected`,`display`,`disabled`,`placeholder`,`class`,`style`,`mandatory`];function x(e,t){let n=Object.keys(e),r=Object.keys(t);if(n.length!==r.length)return!1;for(let r of n)if(e[r]!==t[r])return!1;return!0}function S(e,t){switch(t){case`id`:return e.id||``;case`value`:return e.value===void 0?e.text||``:e.value||``;case`text`:return e.text||``;case`html`:return e.html||``;case`defaultSelected`:return e.defaultSelected??!1;case`selected`:return e.selected??!1;case`display`:return e.display??!0;case`disabled`:return e.disabled??!1;case`placeholder`:return e.placeholder??!1;case`class`:return e.class||``;case`style`:return e.style||``;case`mandatory`:return e.mandatory??!1;default:return e.data||{}}}function C(e){return!!e&&typeof e==`object`&&`label`in e&&`options`in e}function w(e,t){for(let n of b)if(S(e,n)!==S(t,n))return!1;return x(e.data||{},t.data||{})}function T(e,t){let n=e=>({id:e.id||``,label:e.label||``,selectAll:e.selectAll??!1,closable:e.closable||`off`}),r=n(e),i=n(t);if(r.id!==i.id||r.label!==i.label||r.selectAll!==i.selectAll||r.closable!==i.closable)return!1;let a=e.options||[],o=t.options||[];if(a.length!==o.length)return!1;for(let e=0;e<a.length;e++)if(!w(a[e],o[e]))return!1;return!0}function E(e,t){if(e===t)return!0;if(e.length!==t.length)return!1;for(let n=0;n<e.length;n++){let r=e[n],i=t[n],a=C(r);if(a!==C(i))return!1;if(a){if(!T(r,i))return!1;continue}if(!w(r,i))return!1}return!0}function D(e){let t=e.replace(/[A-Z\u00C0-\u00D6\u00D8-\u00DE]/g,e=>`-`+e.toLowerCase());return e[0]===e[0].toUpperCase()?t.substring(1):t}function O(e,t=typeof window<`u`?window.innerWidth:768){return e===`on`?!0:e===`mobile`?t<768:!1}var k=class{handlers;attached=!1;constructor(e){this.handlers=e}attach(e){this.attached||(this.attached=!0,window.addEventListener(`resize`,this.resizeHandler,!1),e.listenScroll&&window.addEventListener(`scroll`,this.scrollHandler,!1),document.addEventListener(`visibilitychange`,this.visibilityHandler))}attachDocumentClick(){document.addEventListener(`click`,this.handlers.onDocumentClick)}detachDocumentClick(){document.removeEventListener(`click`,this.handlers.onDocumentClick)}detach(e){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))}resizeHandler=v(()=>{this.handlers.onWindowResize()});scrollHandler=v(()=>{this.handlers.onWindowScroll()});visibilityHandler=()=>{this.handlers.onVisibilityChange()}},A=class{handlers;options;state=`closed`;pendingTimer=null;waitResolvers=[];generation=0;animationAbort=null;constructor(e,t){this.handlers=e,this.options=t}get isOpen(){return this.state===`opening`||this.state===`open`}get isFullOpen(){return this.state===`open`}async requestOpen(){if(this.state===`opening`||this.state===`open`)return;this.cancelPending();let e=++this.generation;if(this.handlers.beforeOpen&&this.handlers.beforeOpen(),this.state=`opening`,await this.waitForPhase(`open`,e),e!==this.generation){this.state===`opening`&&(this.state=`closed`);return}this.state=`open`,this.handlers.afterOpen&&this.handlers.afterOpen(),this.handlers.onOpenReady&&this.handlers.onOpenReady()}async requestClose(){if(this.state===`closed`||this.state===`closing`)return;this.cancelPending();let e=++this.generation;this.handlers.beforeClose&&this.handlers.beforeClose(),this.state=`closing`,await this.waitForPhase(`close`,e),e===this.generation&&(this.state=`closed`,this.handlers.afterClose&&this.handlers.afterClose(),this.handlers.onCloseReady&&this.handlers.onCloseReady())}cancelPending(){this.generation++,this.animationAbort?.abort(),this.animationAbort=null,this.pendingTimer&&=(clearTimeout(this.pendingTimer),null);let e=this.waitResolvers.splice(0);for(let t of e)t()}destroy(){this.cancelPending(),this.state=`closed`}waitForPhase(e,t){return new Promise(t=>{let n=!1,r=()=>{if(n)return;n=!0;let e=this.waitResolvers.indexOf(r);e!==-1&&this.waitResolvers.splice(e,1),t()};if(this.waitResolvers.push(r),this.options.waitForAnimation){let t=new AbortController;this.animationAbort=t,this.options.waitForAnimation(e,t.signal).catch(()=>void 0).finally(()=>{this.animationAbort===t&&(this.animationAbort=null),r()})}else this.pendingTimer=setTimeout(()=>{this.pendingTimer=null,r()},this.options.timeoutDelay)}).then(()=>{this.generation})}},j=class{id;value;text;html;defaultSelected;selected;display;disabled;placeholder;class;style;data;mandatory;constructor(e){this.id=!e.id||e.id===``?g():e.id,this.value=e.value===void 0?e.text||``:e.value||``,this.text=e.text||``,this.html=e.html||``,this.defaultSelected=e.defaultSelected===void 0?!1:e.defaultSelected,this.selected=e.selected===void 0?!1:e.selected,this.display=e.display===void 0?!0:e.display,this.disabled=e.disabled===void 0?!1:e.disabled,this.mandatory=e.mandatory===void 0?!1:e.mandatory,this.placeholder=e.placeholder===void 0?!1:e.placeholder,this.class=e.class||``,this.style=e.style||``,this.data=p(e.data)}},M=class{id;label;selectAll;closable;options;constructor(e){if(this.id=!e.id||e.id===``?g():e.id,this.label=e.label||``,this.selectAll=e.selectAll===void 0?!1:e.selectAll,this.closable=e.closable||`off`,this.options=[],e.options)for(let t of e.options)this.options.push(new j(t))}},N=class{selectType=`single`;data=[];selectedOrder=[];catalog=null;constructor(e,t){this.selectType=e,this.setData(t),this.snapshotCatalog()}validateDataArray(e){if(!Array.isArray(e))return Error(`Data must be an array`);for(let t of e)if(t)if(t instanceof M||`label`in t){if(!(`label`in t))return Error(`Optgroup must have a label`);if(`options`in t&&t.options)for(let e of t.options){let t=this.validateOption(e);if(t)return t}}else if(t instanceof j||`text`in t){let e=this.validateOption(t);if(e)return e}else return Error(`Data object must be a valid optgroup or option`);return null}validateOption(e){return`text`in e?null:Error(`Option must have a text`)}partialToFullData(e){let t=[];return e.forEach(e=>{if(e){if(e instanceof M||`label`in e){let n=[];`options`in e&&e.options&&e.options.forEach(e=>{n.push(new j(e))}),n.length>0&&t.push(new M(e))}(e instanceof j||`text`in e)&&t.push(new j(e))}}),t}snapshotCatalog(){this.catalog=this.cloneData(this.data)}getCatalogData(){return this.cloneData(this.catalog??this.data)}cloneData(e){return e.map(e=>e instanceof M?new M({id:e.id,label:e.label,selectAll:e.selectAll,closable:e.closable,options:e.options.map(e=>new j(e instanceof j?{...e}:e))}):new j({...e}))}optionMatchesSelected(e,t){return e.id===t.id?!0:t.value!==``&&e.value!==``&&e.value===t.value}findOptionInData(e,t){for(let n of e){if(n instanceof j){if(this.optionMatchesSelected(n,t))return n;continue}for(let e of n.options)if(this.optionMatchesSelected(e,t))return e}return null}setData(e,t=!1){let n=this.partialToFullData(e),r=[];if(t){r=this.getSelectedOptions();let e=[];r.forEach(t=>{this.findOptionInData(n,t)||e.push(t)}),this.data=[...e,...n];let t=this.selectType===`single`&&r.length===0,i=r.map(e=>{let t=this.findOptionInData(this.data,e);return t?t.id:e.id});this.setSelectedBy(`id`,i,t)}else this.data=n;!t&&this.selectType===`single`&&this.setSelectedBy(`id`,this.getSelected(),!1)}getData(e=!0){return this.filter(null,!0,e)}getDataOptions(e=!0){return this.filter(null,!1,e)}addOption(e,t=!1){if(t){let t=[new j(e)];this.setData(t.concat(this.getData()))}else this.setData(this.getData().concat(new j(e)))}setSelectedBy(e,t,n=!1){let r=null,i=!1,a=[];for(let n of this.data){if(n instanceof M)for(let o of n.options){r||=o;let n=o[e]||``;o.selected=i?!1:t.includes(n),o.selected&&(a.push(o),this.selectType===`single`&&(i=!0))}n instanceof j&&(r||=n,n.selected=i?!1:t.includes(n[e]),n.selected&&(a.push(n),this.selectType===`single`&&(i=!0)))}this.selectType===`single`&&r&&!i&&!n&&(r.selected=!0,a.push(r));let o=t.map(t=>a.find(n=>n[e]===t)?.id||``);this.selectedOrder=o}getSelected(){return this.getSelectedOptions().map(e=>e.id)}getSelectedValues(){return this.getSelectedOptions().map(e=>e.value)}getSelectedOptions(){let e=[];for(let t of this.data)if(t instanceof M)for(let n of t.options)n.selected&&e.push(n);else t.selected&&e.push(t);return e}getOptgroupByID(e){for(let t of this.data)if(t instanceof M&&t.id===e)return t;return null}getOptionByID(e){for(let t of this.data)if(t instanceof M){for(let n of t.options)if(n.id===e)return n}else if(t.id===e)return t;return null}getSelectType(){return this.selectType}getFirstOption(){let e=null;for(let t of this.data)if(t instanceof M?e=t.options[0]:t instanceof j&&(e=t),e)break;return e}search(e,t){return e=e.trim(),e===``?this.getData(!1):this.filter(n=>t(n,e),!0,!1)}createOptgroupView(e,t){let n=new M({id:e.id,label:e.label,selectAll:e.selectAll,closable:e.closable,options:[]});return n.options=t,n}filter(e,t,n=!0){let r=[];return this.data.forEach(i=>{if(i instanceof M){let a=[];if(i.options.forEach(i=>{(!e||e(i))&&(t?a.push(n?new j(i):i):r.push(n?new j(i):i))}),a.length>0)if(n){let e=new M(i);e.options=a,r.push(e)}else r.push(this.createOptgroupView(i,a))}i instanceof j&&(!e||e(i))&&r.push(n?new j(i):i)}),r}selectedOrderOptions(e){let t=[];return this.selectedOrder.forEach(n=>{let r=e.find(e=>e.id===n);r&&t.push(r)}),e.forEach(e=>{let n=!1;t.forEach(t=>{if(e.id===t.id){n=!0;return}}),n||t.push(e)}),t}},P=class{settings;store;callbacks;lastSelectedOption;lastRenderedOptions;optionsListIsFullData=!1;lastSearchFilterTerm=``;main;content;classes;positionObserver=null;positionObserverRaf=0;modalElements=null;modalSessionActive=null;bodyScrollLocked=!1;savedBodyOverflow=``;constructor(e,t,n,r){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))}addClasses(e,t){if(!t||t.trim()===``)return;let n=t.split(` `).filter(e=>e.trim()!==``);for(let t of n)e.classList.add(t.trim())}removeClasses(e,t){if(!t||t.trim()===``)return;let n=t.split(` `).filter(e=>e.trim()!==``);for(let t of n)e.classList.remove(t.trim())}enable(){this.removeClasses(this.main.main,this.classes.disabled),this.main.main.setAttribute(`aria-disabled`,`false`),this.content.search.input.disabled=!1}disable(){this.addClasses(this.main.main,this.classes.disabled),this.main.main.setAttribute(`aria-disabled`,`true`),this.content.search.input.disabled=!0}open(){this.main.arrow.path.setAttribute(`d`,this.classes.arrowOpen),this.main.main.setAttribute(`aria-expanded`,`true`);let e=this.resolveModalView();if(!e){let e=this.settings.openPosition===`up`?this.classes.dirAbove:this.classes.dirBelow;this.addClasses(this.main.main,e),this.addClasses(this.content.main,e)}this.addClasses(this.content.main,this.classes.contentOpen),this.content.search.input.removeAttribute(`aria-hidden`),e?this.showModal():this.moveContent();let t=this.store.getSelectedOptions();if(t.length){let e=t[t.length-1].id,n=this.content.list.querySelector(`[data-id="`+e+`"]`);n&&this.ensureElementInView(this.content.list,n)}}isModalViewActive(){return this.modalSessionActive===!0}resolveModalView(){return this.settings.alwaysOpen||this.settings.modal===`off`||!this.modalElements?!1:(this.modalSessionActive===null&&(this.modalSessionActive=O(this.settings.modal)),this.modalSessionActive)}createModalElements(){let e=document.createElement(`div`);this.addClasses(e,this.classes.modalOverlay),this.addClasses(e,this.classes.hide),e.dataset.id=this.settings.id;let t=document.createElement(`div`);this.addClasses(t,this.classes.modalDialog),t.setAttribute(`role`,`dialog`),t.setAttribute(`aria-modal`,`true`);let n=null;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);let r=document.createElement(`button`);r.type=`button`,this.addClasses(r,this.classes.modalClose),r.setAttribute(`aria-label`,`Close`),r.onclick=e=>{e.stopPropagation(),this.callbacks.close()};let i=document.createElementNS(`http://www.w3.org/2000/svg`,`svg`);i.setAttribute(`viewBox`,`0 0 100 100`);let a=document.createElementNS(`http://www.w3.org/2000/svg`,`path`);return a.setAttribute(`d`,this.classes.deselectPath),i.appendChild(a),r.appendChild(i),e.onclick=t=>{t.target===e&&this.callbacks.close()},n&&t.appendChild(n),e.appendChild(t),{overlay:e,dialog:t,closeButton:r,title:n}}showModal(){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(()=>{this.modalElements&&this.addClasses(this.modalElements.overlay,this.classes.contentOpen)}),this.lockBodyScroll())}lockBodyScroll(){this.bodyScrollLocked||=(this.savedBodyOverflow=document.body.style.overflow,document.body.style.overflow=`hidden`,!0)}unlockBodyScroll(){this.bodyScrollLocked&&(document.body.style.overflow=this.savedBodyOverflow,this.bodyScrollLocked=!1,this.savedBodyOverflow=``)}restoreContentOffscreen(){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`)}finalizeModalClose(){this.modalElements&&this.content.main.parentElement===this.modalElements.dialog&&(this.addClasses(this.modalElements.overlay,this.classes.hide),this.removeClasses(this.modalElements.overlay,this.classes.contentOpen),this.removeClasses(this.content.main,this.classes.modalContent),this.restoreContentOffscreen(),this.unlockBodyScroll())}waitForAnimation(e,t){let n=s(this.content.main,this.settings.timeoutDelay);return u(this.content.main,i,n,t)}close(){this.main.main.setAttribute(`aria-expanded`,`false`),this.main.arrow.path.setAttribute(`d`,this.classes.arrowClose);let e=this.modalSessionActive===!0;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`)}clearDirectionClasses(){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)}updateClassStyles(){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()));(this.settings.contentPosition===`relative`||this.settings.contentPosition===`fixed`)&&this.content.main.classList.add(`ss-`+this.settings.contentPosition)}updateAriaAttributes(){let e=this.content.list.id;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)}mainDiv(){let e=document.createElement(`div`);e.dataset.id=this.settings.id,e.setAttribute(`aria-label`,this.settings.ariaLabel),e.tabIndex=0,e.onkeydown=e=>{switch(e.key){case`ArrowUp`:case`ArrowDown`:return this.callbacks.open(),e.key===`ArrowDown`?this.highlight(`down`):this.highlight(`up`),!1;case`Tab`:return this.callbacks.close(),!0;case`Enter`:case` `:this.callbacks.open();let t=this.content.list.querySelector(`.`+this.classes.getFirst(`highlighted`));return t&&t.click(),!1;case`Escape`:return this.callbacks.close(),!1}return e.key.length===1&&this.callbacks.open(),!0},e.onclick=e=>{this.settings.disabled||(this.settings.isOpen?this.callbacks.close():this.callbacks.open())};let t=document.createElement(`div`);this.addClasses(t,this.classes.values),e.appendChild(t);let n=document.createElement(`div`);this.addClasses(n,this.classes.deselect),n.setAttribute(`role`,`button`),n.setAttribute(`aria-label`,this.settings.deselectText),n.setAttribute(`tabindex`,`0`);let r=this.store?.getSelectedOptions();!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=>{if(e.stopPropagation(),this.settings.disabled||this.settings.isMultiple&&this.isAtMinSelected())return;let t=!0,n=this.store.getSelectedOptions(),r=[],i=``;if(this.settings.isMultiple){let e=this.settings.minSelected,t=this.store.getSelected();if(e>0&&t.length>e)i=this.getMinimumSelectionIds(),r=n.filter(e=>i.includes(e.id));else if(e<=0)i=[];else return}if(this.callbacks.beforeChange&&(t=this.callbacks.beforeChange(r,n)===!0),t){if(this.settings.isMultiple)this.callbacks.setSelected(i,!1),this.updateDeselectAll();else{let e=this.store.getFirstOption(),t=e?e.id:``;this.callbacks.setSelected(t,!1)}this.settings.closeOnSelect&&this.callbacks.close(),this.callbacks.afterChange&&this.callbacks.afterChange(this.store.getSelectedOptions())}},n.onkeydown=e=>{(e.key===`Enter`||e.key===` `)&&(e.preventDefault(),n.click())};let i=document.createElementNS(`http://www.w3.org/2000/svg`,`svg`);i.setAttribute(`viewBox`,`0 0 100 100`);let a=document.createElementNS(`http://www.w3.org/2000/svg`,`path`);a.setAttribute(`d`,this.classes.deselectPath),i.appendChild(a),n.appendChild(i),e.appendChild(n);let o=document.createElementNS(`http://www.w3.org/2000/svg`,`svg`);this.addClasses(o,this.classes.arrow),o.setAttribute(`viewBox`,`0 0 100 100`);let s=document.createElementNS(`http://www.w3.org/2000/svg`,`path`);return s.setAttribute(`d`,this.classes.arrowClose),this.settings.alwaysOpen&&this.addClasses(o,this.classes.hide),o.appendChild(s),e.appendChild(o),{main:e,values:t,deselect:{main:n,svg:i,path:a},arrow:{main:o,path:s}}}mainFocus(e){e!==`click`&&this.main.main.focus({preventScroll:!0})}placeholder(){let e=this.store.filter(e=>e.placeholder,!1,!1),t=this.settings.placeholderText;e.length&&(e[0].html===``?e[0].text!==``&&(t=e[0].text):t=e[0].html);let n=document.createElement(`div`);return this.addClasses(n,this.classes.placeholder),n.innerHTML=t,n}renderValues(){if(!this.settings.isMultiple){this.renderSingleValue();return}this.renderMultipleValues(),this.updateDeselectAll()}renderSingleValue(){let e=this.store.filter(e=>e.selected&&!e.placeholder,!1,!1),t=e.length>0?e[0]:null;if(!t)this.main.values.innerHTML=this.placeholder().outerHTML;else{let e=document.createElement(`div`);this.addClasses(e,this.classes.single),t.html?e.innerHTML=t.html:e.innerText=t.text,this.main.values.innerHTML=e.outerHTML}!this.settings.allowDeselect||!e.length?this.addClasses(this.main.deselect.main,this.classes.hide):this.removeClasses(this.main.deselect.main,this.classes.hide)}renderMultipleValues(){let e=this.main.values.childNodes,t=this.store.filter(e=>e.selected&&e.display,!1,!1);if(t.length===0){this.main.values.innerHTML=this.placeholder().outerHTML;return}else{let e=this.main.values.querySelector(`.`+this.classes.getFirst(`placeholder`));e&&e.remove()}if(this.settings.multiString){let e=t;this.settings.keepOrder&&(e=this.store.selectedOrderOptions(e));let n=document.createElement(`div`);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;return}if(t.length>this.settings.maxValuesShown){let e=document.createElement(`div`);this.addClasses(e,this.classes.max),e.textContent=this.settings.maxValuesMessage.replace(`{number}`,t.length.toString()),this.main.values.innerHTML=e.outerHTML;return}else{let e=this.main.values.querySelector(`.`+this.classes.getFirst(`max`));e&&e.remove()}this.settings.keepOrder&&(t=this.store.selectedOrderOptions(t));let n=[];for(let r=0;r<e.length;r++){let i=e[r],a=i.getAttribute(`data-id`);a&&(t.filter(e=>e.id===a,!1).length||n.push(i))}let r=s(this.content.main,this.settings.timeoutDelay);for(let e of n)this.addClasses(e,this.classes.valueOut),d(e,`ss-valueOut`,r).then(()=>{this.main.values.hasChildNodes()&&this.main.values.contains(e)&&this.main.values.removeChild(e)});e=this.main.values.childNodes;for(let n=0;n<t.length;n++){let r=!0;for(let i=0;i<e.length;i++)t[n].id===String(e[i].dataset.id)&&(r=!1);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])))}this.updateMultipleValueDeleteVisibility()}isAtMinSelected(){return this.settings.isMultiple&&this.settings.minSelected>0&&this.store.getSelectedOptions().length<=this.settings.minSelected}getMinimumSelectionIds(){let e=this.store.getSelectedOptions();return this.settings.keepOrder&&(e=this.store.selectedOrderOptions(e)),e.slice(0,this.settings.minSelected).map(e=>e.id)}updateMultipleValueDeleteVisibility(){if(!this.settings.isMultiple||this.settings.multiString)return;let e=!this.isAtMinSelected(),t=this.main.values.querySelectorAll(`.`+this.classes.getFirst(`valueDelete`));for(let n of t)e?this.removeClasses(n,this.classes.hide):this.addClasses(n,this.classes.hide)}multipleValue(e){let t=document.createElement(`div`);this.addClasses(t,this.classes.value),t.dataset.id=e.id;let n=document.createElement(`div`);if(this.addClasses(n,this.classes.valueText),n.textContent=e.text,t.appendChild(n),!e.mandatory){let n=document.createElement(`div`);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=>{if(t.preventDefault(),t.stopPropagation(),this.settings.disabled)return;let n=!0,r=this.store.getSelectedOptions(),i=r.filter(t=>t.selected&&t.id!==e.id,!0);if(!(this.settings.minSelected&&i.length<this.settings.minSelected)&&(this.callbacks.beforeChange&&(n=this.callbacks.beforeChange(i,r)===!0),n)){let e=[];for(let t of i){if(t instanceof M)for(let n of t.options)n.id&&e.push(n.id);t instanceof j&&e.push(t.id)}this.callbacks.setSelected(e,!1),this.settings.closeOnSelect&&this.callbacks.close(),this.callbacks.afterChange&&this.callbacks.afterChange(i),this.updateDeselectAll(),this.updateMultipleValueDeleteVisibility()}};let r=document.createElementNS(`http://www.w3.org/2000/svg`,`svg`);r.setAttribute(`viewBox`,`0 0 100 100`);let i=document.createElementNS(`http://www.w3.org/2000/svg`,`path`);i.setAttribute(`d`,this.classes.optionDelete),r.appendChild(i),n.appendChild(r),t.appendChild(n),n.onkeydown=e=>{e.key===`Enter`&&n.click()}}return t}contentDiv(){let e=document.createElement(`div`);e.dataset.id=this.settings.id;let t=this.searchDiv();e.appendChild(t.main);let n=document.createElement(`div`);this.addClasses(n,this.classes.status),n.setAttribute(`aria-live`,`polite`),n.setAttribute(`aria-atomic`,`true`),n.setAttribute(`role`,`status`),e.appendChild(n);let r=this.listDiv();return e.appendChild(r),{main:e,search:t,status:n,list:r}}announce(e){this.settings.showSearch&&(this.content.status.textContent=e)}moveContent(){if(!this.isModalViewActive()){if(this.settings.contentPosition===`relative`){this.moveContentBelow();return}if(this.settings.openPosition===`down`){this.moveContentBelow();return}else if(this.settings.openPosition===`up`){this.moveContentAbove();return}this.putContent()===`up`?this.moveContentAbove():this.moveContentBelow()}}startPositionTracking(){this.settings.contentPosition!==`absolute`||this.isModalViewActive()||(this.stopPositionTracking(),!(typeof ResizeObserver>`u`)&&(this.positionObserver=new ResizeObserver(()=>{this.settings.isOpen&&(cancelAnimationFrame(this.positionObserverRaf),this.positionObserverRaf=requestAnimationFrame(()=>{this.moveContent()}))}),this.observePositionTargets()))}stopPositionTracking(){cancelAnimationFrame(this.positionObserverRaf),this.positionObserver?.disconnect(),this.positionObserver=null}observePositionTargets(){if(!this.positionObserver)return;let e=new Set,t=t=>{!t||e.has(t)||(e.add(t),this.positionObserver.observe(t))};t(this.main.main),t(this.content.main);let n=this.main.main.parentElement,r=this.settings.contentLocation;for(let e=0;n&&e<8&&(t(n),n!==r);e++)n=n.parentElement}searchDiv(){let e=document.createElement(`div`),t=document.createElement(`input`),n=document.createElement(`div`);this.addClasses(e,this.classes.search);let r={main:e,input:t};if(this.settings.showSearch||(this.addClasses(e,this.classes.hide),t.readOnly=!0),t.type=`search`,t.placeholder=this.settings.searchPlaceholder,t.tabIndex=-1,t.setAttribute(`aria-label`,this.settings.searchPlaceholder),t.setAttribute(`aria-autocomplete`,`list`),t.setAttribute(`autocapitalize`,`off`),t.setAttribute(`autocomplete`,`off`),t.setAttribute(`autocorrect`,`off`),t.setAttribute(`aria-hidden`,`true`),t.oninput=v(e=>{this.callbacks.search(e.target.value)},100),t.onkeydown=e=>{switch(e.key){case`ArrowUp`:case`ArrowDown`:return e.key===`ArrowDown`?this.highlight(`down`):this.highlight(`up`),!1;case`Tab`:return this.callbacks.close(),!0;case`Escape`:return this.callbacks.close(),!1;case` `:let t=this.content.list.querySelector(`.`+this.classes.getFirst(`highlighted`));return t?(t.click(),!1):!0;case`Enter`:let r=this.content.list.querySelector(`.`+this.classes.getFirst(`highlighted`));return r?(r.click(),!1):this.callbacks.addable?(n.click(),!1):!0}return!0},e.appendChild(t),this.callbacks.addable){this.addClasses(n,this.classes.addable);let t=document.createElementNS(`http://www.w3.org/2000/svg`,`svg`);t.setAttribute(`viewBox`,`0 0 100 100`);let i=document.createElementNS(`http://www.w3.org/2000/svg`,`path`);i.setAttribute(`d`,this.classes.addablePath),t.appendChild(i),n.appendChild(t),n.onclick=e=>{if(e.preventDefault(),e.stopPropagation(),!this.callbacks.addable)return;let t=this.content.search.input.value.trim();if(t===``){this.content.search.input.focus();return}let n=e=>{let t=new j(e);if(this.callbacks.addOption(t),this.settings.isMultiple){let e=this.store.getSelected();e.push(t.id),this.callbacks.setSelected(e,!0)}else this.callbacks.setSelected([t.id],!0);if(this.callbacks.search(``),this.settings.closeOnSelect){let e=o(this.content.main);setTimeout(()=>{this.callbacks.close()},e)}},r=this.callbacks.addable(t);r===!1||r==null||(r instanceof Promise?r.then(e=>{typeof e==`string`?n({text:e,value:e}):r instanceof Error?this.renderError(r.message):n(e)}):typeof r==`string`?n({text:r,value:r}):r instanceof Error?this.renderError(r.message):n(r))},e.appendChild(n),r.addable={main:n,svg:t,path:i}}return r}searchFocus(){this.content.search.input.focus({preventScroll:!0})}getOptions(e=!1,t=!1,n=!1){let r=`.`+this.classes.getFirst(`option`);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))}highlight(e){let t=this.getOptions(!0,!0,!0);if(t.length===0)return;if(t.length===1&&!t[0].classList.contains(this.classes.getFirst(`highlighted`))){this.addClasses(t[0],this.classes.highlighted);return}let n=!1;for(let e of t)e.classList.contains(this.classes.getFirst(`highlighted`))&&(n=!0);if(!n){for(let e of t)if(e.classList.contains(this.classes.getFirst(`selected`))){this.addClasses(e,this.classes.highlighted);break}}for(let n=0;n<t.length;n++)if(t[n].classList.contains(this.classes.getFirst(`highlighted`))){let r=t[n];this.removeClasses(r,this.classes.highlighted);let i=r.parentElement;if(i&&i.classList.contains(this.classes.getFirst(`mainOpen`))){let e=i.querySelector(`.`+this.classes.getFirst(`optgroupLabel`));e&&e.click()}let a=t[e===`down`?n+1<t.length?n+1:0:n-1>=0?n-1:t.length-1];this.addClasses(a,this.classes.highlighted),this.ensureElementInView(this.content.list,a),a.id&&this.main.main.setAttribute(`aria-activedescendant`,a.id);let o=a.parentElement;if(o&&o.classList.contains(this.classes.getFirst(`close`))){let e=o.querySelector(`.`+this.classes.getFirst(`optgroupLabel`));e&&e.click()}return}let r=t[e===`down`?0:t.length-1];this.addClasses(r,this.classes.highlighted),r.id&&this.main.main.setAttribute(`aria-activedescendant`,r.id),this.ensureElementInView(this.content.list,r)}listDiv(){let e=document.createElement(`div`);this.addClasses(e,this.classes.list);let t=this.settings.id+`-list`;return e.id=t,e.dataset.id=t,e}renderError(e){this.optionsListIsFullData=!1,this.content.list.innerHTML=``;let t=document.createElement(`div`);this.addClasses(t,this.classes.error),t.textContent=e,this.content.list.appendChild(t)}renderSearching(){this.optionsListIsFullData=!1,this.content.list.innerHTML=``;let e=document.createElement(`div`);this.addClasses(e,this.classes.searching),e.textContent=this.settings.searchingText,this.content.list.appendChild(e),this.announce(this.settings.searchingText)}renderOptions(e){if(this.lastSearchFilterTerm=``,this.lastRenderedOptions=e.map(e=>e instanceof j?[e]:e.options.map(e=>new j(e))).flat(),this.content.list.innerHTML=``,e.length===0){this.optionsListIsFullData=!1;let e=document.createElement(`div`);if(this.addClasses(e,this.classes.search),this.callbacks.addable){let t=this.settings.addableText.replace(`{value}`,this.content.search.input.value);e.innerHTML=t,this.announce(t)}else e.innerHTML=this.settings.searchText,this.announce(this.settings.searchText);this.content.list.appendChild(e);return}this.settings.allowDeselect&&!this.settings.isMultiple&&(this.store.filter(e=>e.placeholder,!1,!1).length||this.store.addOption(new j({text:``,value:``,selected:!1,placeholder:!0}),!0));let t=document.createDocumentFragment();for(let n of e){if(n instanceof M){let e=document.createElement(`div`);this.addClasses(e,this.classes.optgroup);let r=document.createElement(`div`);this.addClasses(r,this.classes.optgroupLabel),e.appendChild(r);let i=document.createElement(`div`);this.addClasses(i,this.classes.optgroupLabelText),i.textContent=n.label,r.appendChild(i);let a=document.createElement(`div`);if(this.addClasses(a,this.classes.optgroupActions),r.appendChild(a),this.settings.isMultiple&&n.selectAll){let e=document.createElement(`div`);this.addClasses(e,this.classes.optgroupSelectAll);let t=this.isOptgroupAllSelected(n.options);t&&this.addClasses(e,this.classes.selected);let r=document.createElement(`span`);r.textContent=this.optgroupSelectAllLabel(t),e.appendChild(r);let i=document.createElementNS(`http://www.w3.org/2000/svg`,`svg`);i.setAttribute(`viewBox`,`0 0 100 100`),e.appendChild(i);let o=document.createElementNS(`http://www.w3.org/2000/svg`,`path`);o.setAttribute(`d`,this.classes.optgroupSelectAllBox),i.appendChild(o);let s=document.createElementNS(`http://www.w3.org/2000/svg`,`path`);s.setAttribute(`d`,this.classes.optgroupSelectAllCheck),i.appendChild(s),e.addEventListener(`click`,e=>{e.preventDefault(),e.stopPropagation();let t=this.store.getSelected();if(this.isOptgroupAllSelected(n.options,new Set(t))){let e=t.filter(e=>{for(let t of n.options)if(e===t.id)return!1;return!0});this.callbacks.setSelected(e,!0);return}else{let e=n.options.map(e=>e.id).filter(e=>e!==void 0),r=t.concat(e);for(let e of n.options)e.id&&!this.store.getOptionByID(e.id)&&this.callbacks.addOption(new j(e));this.callbacks.setSelected(r,!0);return}}),a.appendChild(e)}if(n.closable!==`off`){let t=document.createElement(`div`);this.addClasses(t,this.classes.optgroupClosable);let i=document.createElementNS(`http://www.w3.org/2000/svg`,`svg`);i.setAttribute(`viewBox`,`0 0 100 100`),this.addClasses(i,this.classes.arrow),t.appendChild(i);let o=document.createElementNS(`http://www.w3.org/2000/svg`,`path`);i.appendChild(o),n.options.some(e=>e.selected)||this.content.search.input.value.trim()!==``?(this.addClasses(t,this.classes.mainOpen),o.setAttribute(`d`,this.classes.arrowOpen)):n.closable===`open`?(this.addClasses(e,this.classes.mainOpen),o.setAttribute(`d`,this.classes.arrowOpen)):n.closable===`close`&&(this.addClasses(e,this.classes.close),o.setAttribute(`d`,this.classes.arrowClose)),r.addEventListener(`click`,n=>{n.preventDefault(),n.stopPropagation(),this.isClosableOptgroupOpen(e,t)?(this.removeClasses(e,this.classes.mainOpen),this.removeClasses(t,this.classes.mainOpen),this.addClasses(e,this.classes.close),o.setAttribute(`d`,this.classes.arrowClose)):(this.closeOtherClosableOptgroups(e),this.removeClasses(e,this.classes.close),this.removeClasses(t,this.classes.mainOpen),this.addClasses(e,this.classes.mainOpen),o.setAttribute(`d`,this.classes.arrowOpen))}),a.appendChild(t)}e.appendChild(r);for(let r of n.options)e.appendChild(this.option(new j(r))),t.appendChild(e)}n instanceof j&&t.appendChild(this.option(n))}this.content.list.appendChild(t),this.setOptionsListFullData(e),this.announce(this.settings.resultsText.replace(`{count}`,String(this.lastRenderedOptions.length)))}canFilterOptionsInPlace(){return this.optionsListIsFullData?this.content.list.querySelector(`.`+this.classes.getFirst(`option`))!==null:!1}resetSearchFilterState(){this.lastSearchFilterTerm=``}filterOptionsInPlace(e,t){let n=e.trim();if(n===this.lastSearchFilterTerm)return;this.lastSearchFilterTerm=n;let r=[],i=this.content.list.querySelectorAll(`.`+this.classes.getFirst(`option`));for(let e of i){let i=e.dataset.id;if(!i)continue;let a=this.store.getOptionByID(i);if(!a)continue;let o=a.placeholder||!a.display||a.selected&&this.settings.hideSelected,s=t(a,n);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`))}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()}setOptionsListFullData(e){let t=this.store.getDataOptions(!1),n=e.map(e=>e instanceof j?[e]:e.options.map(e=>new j(e))).flat();if(n.length!==t.length){this.optionsListIsFullData=!1;return}let r=new Set(t.map(e=>e.id));this.optionsListIsFullData=n.every(e=>r.has(e.id))}isClosableOptgroupOpen(e,t){return e.classList.contains(this.classes.getFirst(`close`))?!1:e.classList.contains(this.classes.getFirst(`mainOpen`))||t.classList.contains(this.classes.getFirst(`mainOpen`))}closeClosableOptgroup(e){let t=e.querySelector(`.`+this.classes.getFirst(`optgroupClosable`));if(!t||e.classList.contains(this.classes.getFirst(`close`)))return;this.removeClasses(e,this.classes.mainOpen),this.removeClasses(t,this.classes.mainOpen),this.addClasses(e,this.classes.close);let n=t.querySelector(`path`);n&&n.setAttribute(`d`,this.classes.arrowClose)}closeOtherClosableOptgroups(e){let t=this.content.list.querySelectorAll(`.`+this.classes.getFirst(`optgroup`));for(let n of t)n!==e&&this.closeClosableOptgroup(n)}updateOptgroupVisibilityAfterSearch(e){let t=this.content.list.querySelectorAll(`.`+this.classes.getFirst(`optgroup`));for(let n of t){let t=n.querySelectorAll(`.`+this.classes.getFirst(`option`)),r=!1;for(let e of t)if(!e.classList.contains(this.classes.getFirst(`hide`))){r=!0;break}if(!r){this.addClasses(n,this.classes.hide);continue}this.removeClasses(n,this.classes.hide),e!==``&&(this.removeClasses(n,this.classes.close),this.addClasses(n,this.classes.mainOpen))}}updateSearchResultsMessage(e,t){if(this.removeListSearchMessage(),e>0)return;let n=document.createElement(`div`);if(this.addClasses(n,this.classes.search),this.callbacks.addable){let e=this.settings.addableText.replace(`{value}`,t);n.innerHTML=e,this.announce(e)}else n.innerHTML=this.settings.searchText,this.announce(this.settings.searchText);this.content.list.appendChild(n)}removeListSearchMessage(){this.content.list.querySelectorAll(`.`+this.classes.getFirst(`search`)).forEach(e=>e.remove())}setOptionElementContent(e,t,n){let r=n.trim();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`)}hasRenderedOptions(){return this.content.list.querySelector(`.`+this.classes.getFirst(`option`))!==null}canUpdateOptionSelectionInPlace(){return this.content.search.input.value.trim()===``?this.hasRenderedOptions():!1}updateOptionSelection(){let e=new Set(this.store.getSelected()),t=this.content.list.querySelectorAll(`.`+this.classes.getFirst(`option`)),n=null;for(let r of t){let t=r.dataset.id;if(!t)continue;let i=this.store.getOptionByID(t);if(!i)continue;let a=e.has(t);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)))}!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()}updateOptgroupSelectAllStates(){if(!this.settings.isMultiple)return;let e=new Set(this.store.getSelected()),t=this.content.list.querySelectorAll(`.`+this.classes.getFirst(`optgroup`));for(let n of t){let t=n.querySelector(`.`+this.classes.getFirst(`optgroupSelectAll`));if(!t)continue;let r=n.querySelectorAll(`.`+this.classes.getFirst(`option`)),i=r.length>0;for(let t of r){let n=t.dataset.id;if(!n||!e.has(n)){i=!1;break}}i?this.addClasses(t,this.classes.selected):this.removeClasses(t,this.classes.selected);let a=t.querySelector(`span`);a&&(a.textContent=this.optgroupSelectAllLabel(i))}}optgroupSelectAllLabel(e){return e?`Unselect All`:`Select All`}isOptgroupAllSelected(e,t){if(e.length===0)return!1;for(let n of e)if(!(t?n.id&&t.has(n.id):n.selected))return!1;return!0}option(e){if(e.placeholder){let e=document.createElement(`div`);return this.addClasses(e,this.classes.option),this.addClasses(e,this.classes.hide),e}let t=document.createElement(`div`);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=>{t.classList.add(e)}),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=>{t.preventDefault(),t.stopPropagation();let n=this.store.getSelected(),r=t.currentTarget,i=String(r.dataset.id),a=t.ctrlKey||t.metaKey;if(e.disabled||!this.settings.isMultiple&&e.selected&&!this.settings.allowDeselect||e.selected&&e.mandatory||this.settings.isMultiple&&this.settings.maxSelected<=n.length&&!e.selected||this.settings.isMultiple&&this.settings.minSelected>=n.length&&e.selected&&!a)return;let o=!1,s=this.store.getSelectedOptions(),c=[];if(this.settings.isMultiple){let n=s.some(e=>e.id===i);if(t.shiftKey&&this.lastSelectedOption){let t=this.lastRenderedOptions,n=t.findIndex(e=>e.id===this.lastSelectedOption.id),r=t.findIndex(t=>t.id===e.id);if(n>=0&&r>=0){let e=Math.min(n,r),i=Math.max(n,r),a=t.slice(e,i+1).filter(e=>!s.find(t=>t.id===e.id));c=s.length+a.length<=this.settings.maxSelected?s.concat(a):s}else c=s}else c=n?s.filter(e=>e.id!==i):s.concat(e),this.lastSelectedOption=e}if(this.settings.isMultiple||(c=e.selected?[]:[e]),this.callbacks.beforeChange||(o=!0),this.callbacks.beforeChange&&(o=this.callbacks.beforeChange(c,s)!==!1),o){this.store.getOptionByID(i)||this.callbacks.addOption(e),this.callbacks.setSelected(c.map(e=>e.id),!1);let n=t.ctrlKey||t.metaKey||t.shiftKey;this.settings.closeOnSelect&&!(this.settings.isMultiple&&n)&&this.callbacks.close(),this.callbacks.afterChange&&this.callbacks.afterChange(c)}}),t}destroy(){this.stopPositionTracking(),this.modalElements&&=(this.unlockBodyScroll(),this.content.main.parentElement===this.modalElements.dialog&&this.restoreContentOffscreen(),this.modalElements.overlay.remove(),null),this.main.main.remove(),this.content.main.remove()}highlightText(e,t,n){let r=t.trim();if(r===``)return e;let i=r.replace(/[.*+?^${}()|[\]\\]/g,`\\$&`),a=document.createElement(`div`);a.innerHTML=e;let o=e=>{if(e.nodeType===Node.TEXT_NODE){let t=e.textContent||``,r=RegExp(`(`+i+`)`,`i`);if(r.test(t)){let i=document.createElement(`span`);t.split(r).forEach((e,t)=>{if(e&&r.test(e)){let t=document.createElement(`mark`);t.className=n,t.textContent=e,i.appendChild(t)}else e&&i.appendChild(document.createTextNode(e))}),e.parentNode?.replaceChild(i,e)}}else e.nodeType===Node.ELEMENT_NODE&&Array.from(e.childNodes).forEach(e=>o(e))};return Array.from(a.childNodes).forEach(e=>o(e)),a.innerHTML}setContentDirection(e){let t=e===`above`,n=t?this.classes.dirAbove:this.classes.dirBelow,r=t?this.classes.dirBelow:this.classes.dirAbove;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){let e=this.main.main.offsetHeight,t=this.content.main.offsetHeight;this.content.main.style.margin=`-`+(e+t-1)+`px 0px 0px 0px`}else this.content.main.style.margin=`-1px 0px 0px 0px`}setContentPosition(){if(this.settings.contentPosition===`relative`)return;let e=this.main.main.getBoundingClientRect(),t,n;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`;let r=this.settings.contentWidth;this.content.main.style.width=``,this.content.main.style.minWidth=``,this.content.main.style.maxWidth=``,r?r.startsWith(`>`)?this.content.main.style.minWidth=r.slice(1):r.startsWith(`<`)?this.content.main.style.maxWidth=r.slice(1):this.content.main.style.width=r:this.content.main.style.width=e.width+`px`;let i=window.innerWidth-20,a=()=>{let e=this.content.main.getBoundingClientRect().right;if(e<=i)return;let t=e-i,n=parseFloat(this.content.main.style.left)||0;if(this.settings.contentPosition===`fixed`){let e=Math.max(20,n-t);this.content.main.style.left=e+`px`}else{let e=Math.max(window.scrollX+20,n-t);this.content.main.style.left=e+`px`}};requestAnimationFrame(()=>{a(),requestAnimationFrame(a)})}moveContentAbove(){this.setContentDirection(`above`),this.setContentPosition()}moveContentBelow(){this.setContentDirection(`below`),this.setContentPosition()}ensureElementInView(e,t){let n=e.scrollTop+e.offsetTop,r=n+e.clientHeight,i=t.offsetTop,a=i+t.clientHeight;i<n?e.scrollTop-=n-i:a>r&&(e.scrollTop+=a-r)}putContent(){let e=this.main.main.offsetHeight,t=this.main.main.getBoundingClientRect(),n=this.content.main.offsetHeight;return window.innerHeight-(t.top+e)<=n&&t.top>n?`up`:`down`}updateDeselectAll(){if(!this.store||!this.settings)return;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;r&&!(n&&!t)&&!i?this.removeClasses(a,o):this.addClasses(a,o)}};function F(e,t){let n={classChanged:!1,disabledChanged:!1,optgroupOptionChanged:!1,selectionChanged:!1};for(let r of e){if(r.target===t&&(r.attributeName===`disabled`&&(n.disabledChanged=!0),r.attributeName===`class`&&(n.classChanged=!0),r.type===`childList`)){for(let e of Array.from(r.addedNodes))if(e.nodeName===`OPTION`&&e.value===t.value){n.selectionChanged=!0;break}n.optgroupOptionChanged=!0}(r.target.nodeName===`OPTGROUP`||r.target.nodeName===`OPTION`)&&(n.optgroupOptionChanged=!0)}return n}var I=class{select;onValueChange;onClassChange;onDisabledChange;onOptionsChange;onLabelClick;listen=!1;observer=null;isUpdating=!1;pendingOptionsChange=null;preventNativeSelect=null;preventNativeSelectMousedown=null;preventNativeSelectFocus=null;restoreAriaHiddenOnBlur=null;constructor(e){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)}enable(){this.select.disabled=!1}disable(){this.select.disabled=!0}hideUI(){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=>{e.preventDefault(),e.stopPropagation(),e.stopImmediatePropagation()},this.preventNativeSelectMousedown=e=>{e.preventDefault(),e.stopPropagation(),e.stopImmediatePropagation()},this.preventNativeSelectFocus=e=>{this.select.removeAttribute(`aria-hidden`),e.preventDefault(),e.stopPropagation(),e.stopImmediatePropagation()},this.restoreAriaHiddenOnBlur=()=>{this.select.setAttribute(`aria-hidden`,`true`)},this.select.addEventListener(`click`,this.preventNativeSelect,{capture:!0,passive:!1}),this.select.addEventListener(`mousedown`,this.preventNativeSelectMousedown,{capture:!0,passive:!1}),this.select.addEventListener(`focus`,this.preventNativeSelectFocus,{capture:!0,passive:!1}),this.select.addEventListener(`blur`,this.restoreAriaHiddenOnBlur,{capture:!0,passive:!0}))}showUI(){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)}changeListen(e){this.listen=e,e&&this.observer&&this.observer.observe(this.select,{subtree:!0,childList:!0,attributes:!0}),e||this.observer&&this.observer.disconnect()}valueChange(e){return this.listen&&this.onValueChange&&this.onValueChange(this.getSelectedOptions()),!0}observeCall(e){if(!this.listen)return;let{classChanged:t,disabledChanged:n,optgroupOptionChanged:r,selectionChanged:i}=F(e,this.select),a=i;if(t&&this.onClassChange&&this.onClassChange(this.select.className.split(` `)),n&&this.onDisabledChange&&(this.changeListen(!1),this.onDisabledChange(this.select.disabled),this.changeListen(!0)),r&&this.onOptionsChange){if(this.isUpdating){if(this.select.options.length>0){let e=this.getData();e.length>0&&(this.pendingOptionsChange=e)}a&&this.select.dispatchEvent(new Event(`change`));return}this.changeListen(!1),this.onOptionsChange(this.getData()),this.changeListen(!0),a=!1}a&&this.select.dispatchEvent(new Event(`change`))}getData(){let e=[],t=this.select.childNodes;for(let n of t)n.nodeName===`OPTGROUP`&&e.push(this.getDataFromOptgroup(n)),n.nodeName===`OPTION`&&e.push(this.getDataFromOption(n));return e}getDataFromOptgroup(e){let t={id:e.id,label:e.label,selectAll:e.dataset?e.dataset.selectall===`true`:!1,closable:e.dataset?e.dataset.closable:`off`,options:[]},n=e.childNodes;for(let e of n)e.nodeName===`OPTION`&&t.options.push(this.getDataFromOption(e));return t}getDataFromOption(e){return{id:e.id,value:e.value,text:e.text,html:e.dataset&&e.dataset.html?e.dataset.html:``,defaultSelected:e.defaultSelected,selected:e.selected,display:e.style.display!==`none`,disabled:e.disabled,mandatory:e.dataset?e.dataset.mandatory===`true`:!1,placeholder:e.dataset.placeholder===`true`,class:e.className,style:e.style.cssText,data:p(e.dataset)}}getSelectedOptions(){let e=[],t=this.select.childNodes;for(let n of t){if(n.nodeName===`OPTGROUP`){let t=n.childNodes;for(let n of t)if(n.nodeName===`OPTION`){let t=n;t.selected&&e.push(this.getDataFromOption(t))}}if(n.nodeName===`OPTION`){let t=n;t.selected&&e.push(this.getDataFromOption(t))}}return e}getSelectedValues(){return this.getSelectedOptions().map(e=>e.value)}setSelected(e){this.changeListen(!1);let t=this.select.childNodes;for(let n of t){if(n.nodeName===`OPTGROUP`){let t=n.childNodes;for(let n of t)if(n.nodeName===`OPTION`){let t=n;t.selected=e.includes(t.id)}}if(n.nodeName===`OPTION`){let t=n;t.selected=e.includes(t.id)}}let n=this.getSelectedOptions();this.select.multiple||(this.select.value=n.length===1?n[0].value:``),this.changeListen(!0)}setSelectedByValue(e){this.changeListen(!1);let t=this.select.childNodes;for(let n of t){if(n.nodeName===`OPTGROUP`){let t=n.childNodes;for(let n of t)if(n.nodeName===`OPTION`){let t=n;t.selected=e.includes(t.value)}}if(n.nodeName===`OPTION`){let t=n;t.selected=e.includes(t.value)}}let n=this.getSelectedOptions();this.select.multiple||(this.select.value=n.length===1?n[0].value:``),this.changeListen(!0)}updateSelect(e,t,n){this.changeListen(!1),e&&(this.select.dataset.id=e),t&&(this.select.style.cssText=t),n&&(this.select.className=``,n.forEach(e=>{e.trim()!==``&&this.select.classList.add(e.trim())})),this.changeListen(!0)}updateOptions(e){if(!(!e||e.length===0)){this.isUpdating=!0,this.pendingOptionsChange=null,this.changeListen(!1),this.select.innerHTML=``;for(let t of e)t instanceof M&&this.select.appendChild(this.createOptgroup(t)),t instanceof j&&this.select.appendChild(this.createOption(t));if(this.select.dispatchEvent(new Event(`change`,{bubbles:!0})),this.changeListen(!0),this.isUpdating=!1,this.pendingOptionsChange!==null){let e=this.pendingOptionsChange;e.length>0&&this.onOptionsChange?(this.pendingOptionsChange=null,this.changeListen(!1),this.onOptionsChange(e),this.changeListen(!0)):this.pendingOptionsChange=null}}}createOptgroup(e){let t=document.createElement(`optgroup`);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));return t}createOption(e){let t=document.createElement(`option`);return t.id=e.id,t.value=e.value,t.textContent=e.text,e.html!==``&&t.setAttribute(`data-html`,e.html),t.defaultSelected=e.defaultSelected,t.selected=e.selected,e.disabled&&(t.disabled=!0),e.display||(t.style.display=`none`),e.placeholder&&t.setAttribute(`data-placeholder`,`true`),e.mandatory&&t.setAttribute(`data-mandatory`,`true`),e.class&&e.class.split(` `).forEach(e=>{t.classList.add(e)}),e.data&&typeof e.data==`object`&&Object.keys(e.data).forEach(n=>{t.setAttribute(`data-`+D(n),e.data[n])}),t}setupLabelHandlers(){let e=[],t=this.select.id;t&&document.querySelectorAll(`label[for="${t}"]`).forEach(t=>e.push(t));let n=this.select.parentElement;for(;n&&n!==document.body;){if(n.tagName===`LABEL`){e.push(n);break}n=n.parentElement}Array.from(new Set(e)).forEach(e=>{if(e.__slimSelectLabelHandler)return;let t=e=>{let t=e.target,n=_(t,this.select.dataset.id);e.preventDefault(),!n&&this.onLabelClick&&this.onLabelClick()};e.__slimSelectLabelHandler=t,e.addEventListener(`click`,t,{capture:!0,passive:!1})})}removeLabelHandlers(){let e=[],t=this.select.id;t&&document.querySelectorAll(`label[for="${t}"]`).forEach(t=>e.push(t));let n=this.select.parentElement;for(;n&&n!==document.body;){if(n.tagName===`LABEL`){e.push(n);break}n=n.parentElement}Array.from(new Set(e)).forEach(e=>{let t=e.__slimSelectLabelHandler;t&&(e.removeEventListener(`click`,t,{capture:!0}),delete e.__slimSelectLabelHandler)})}destroy(){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()}};function L(e,t){return E(e.getData(!1),t)}function R(e,t){let n=Array.isArray(t)?t:[t],r=e.getDataOptions(!1),i=[];for(let e of n){if(r.find(t=>t.id==e)){i.push(e);continue}for(let t of r.filter(t=>t.value==e))i.push(t.id)}return i}var z=class{deps;queue=[];flushScheduled=!1;isSyncing=!1;constructor(e){this.deps=e}enqueue(e){if(this.queue.push(e),e.source===`native`){this.flushScheduled||(this.flushScheduled=!0,queueMicrotask(()=>this.flush()));return}this.isSyncing||this.flush()}flush(){if(this.flushScheduled=!1,this.queue.length===0)return;let e=this.coalesceBatch(this.queue);this.queue=[],this.isSyncing=!0;try{for(let t of e)this.applyChange(t)}finally{this.isSyncing=!1,this.queue.length>0&&this.flush()}}coalesceBatch(e){let t=e.some(e=>e.type===`structure`),n=e.some(e=>e.type===`addOption`);if(t||n){let t=e.filter(e=>e.type===`structure`||e.type===`addOption`),n=t[t.length-1];return n?.type===`structure`?[n]:t}let r=e.filter(e=>e.type===`selection`);return r.length>0?[r[r.length-1]]:e}applyChange(e){switch(e.type){case`structure`:this.applyStructure(e.data,e.source,e.preserveSelection,e.isSearchResult);break;case`selection`:this.applySelection(e.values,e.source,e.runAfterChange!==!1);break;case`addOption`:this.applyAddOption(e.option);break}}applyStructure(e,t,n=!1,r=!1){let{store:i,select:a,render:o,events:s}=this.deps;if(L(i,e))return;let c=i.getSelected(),l=i.validateDataArray(e);if(l){s.error?s.error(l):this.deps.onError&&this.deps.onError(l);return}i.setData(e,n);let u=i.getData(!1);r||i.snapshotCatalog(),a.updateOptions(u),o.renderValues(),o.renderOptions(u),s.afterChange&&!y(c,i.getSelected())&&s.afterChange(i.getSelectedOptions())}applySelection(e,t,n){let{store:r,select:i,render:a,events:o}=this.deps,s=r.getSelected(),c=R(r,e);if(y(s,c))return;r.setSelectedBy(`id`,c),i.setSelectedByValue(r.getSelectedValues()),a.renderValues();let l=a.content.search.input.value.trim();l===``?a.canUpdateOptionSelectionInPlace()?a.updateOptionSelection():a.renderOptions(r.getData(!1)):a.hasRenderedOptions()?a.updateOptionSelection():this.deps.search&&this.deps.search(l),n&&o.afterChange&&!y(s,r.getSelected())&&o.afterChange(r.getSelectedOptions())}applyAddOption(e){let{store:t,select:n,render:r,events:i}=this.deps,a=t.getSelected(),o=r.content.search.input.value.trim()!==``&&!!this.deps.search,s=e.value??e.text??``,c=e=>{for(let t of e){if(t instanceof M){if(t.options.some(e=>(e.value??e.text)===s))return!0;continue}if((t.value??t.text)===s)return!0}return!1};if(!c(t.getData(!1)))if(o){let n=t.getCatalogData();c(n)||t.setData([...n,new j(e)],!0),t.snapshotCatalog()}else t.addOption(e),t.snapshotCatalog();let l=t.getData(!1);n.updateOptions(l),r.renderValues(),r.renderOptions(l),i.afterChange&&!y(a,t.getSelected())&&i.afterChange(t.getSelectedOptions())}},B=class{selectEl;settings;cssClasses;select;store;render;sync;lifecycle;globalEvents;searchGeneration=0;events={search:void 0,searchFilter:(e,t)=>e.text.toLowerCase().indexOf(t.toLowerCase())!==-1,addable:void 0,beforeChange:void 0,afterChange:void 0,beforeOpen:void 0,afterOpen:void 0,beforeClose:void 0,afterClose:void 0};constructor(e){if(this.selectEl=typeof e.select==`string`?document.querySelector(e.select):e.select,!this.selectEl){e.events&&e.events.error&&e.events.error(Error(`Could not find select element`));return}if(this.selectEl.tagName!==`SELECT`){e.events&&e.events.error&&e.events.error(Error(`Element isnt of type select`));return}this.selectEl.dataset.ssid&&this.destroy(),this.settings=new f(e.settings),this.cssClasses=new n(e.cssClasses);let t=[`beforeOpen`,`afterOpen`,`beforeClose`,`afterClose`];for(let n in e.events)e.events.hasOwnProperty(n)&&(t.indexOf(n)===-1?this.events[n]=e.events[n]:this.events[n]=v(e.events[n],100));this.settings.disabled=e.settings?.disabled?e.settings.disabled:this.selectEl.disabled,this.settings.isMultiple=this.selectEl.multiple,this.settings.style=this.selectEl.style.cssText,this.settings.class=this.selectEl.className.split(` `),this.select=new 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=>{this.settings.class=e,this.render.updateClassStyles()},this.select.onDisabledChange=e=>{e?this.disable():this.enable()},this.select.onLabelClick=()=>{this.settings.disabled||(this.settings.isOpen?this.close():this.open())};let r=e.data?e.data:this.select.getData();this.store=new N(this.settings.isMultiple?`multiple`:`single`,r),e.data&&this.select.updateOptions(this.store.getData());let i={open:this.open.bind(this),close:this.close.bind(this),addable:this.events.addable?this.events.addable:void 0,setSelected:(e,t)=>{this.sync.enqueue({type:`selection`,values:e,source:`ui`,runAfterChange:t})},addOption:e=>{this.sync.enqueue({type:`addOption`,option:e,source:`ui`})},search:this.search.bind(this),beforeChange:this.events.beforeChange,afterChange:this.events.afterChange};this.settings.modalTitle=e.settings?.modalTitle??h(this.selectEl),this.render=new P(this.settings,this.cssClasses,this.store,i),this.settings.timeoutDelay=s(this.render.content.main,e.settings?.timeoutDelay),this.sync=new z({select:this.select,store:this.store,render:this.render,events:this.events,search:this.search.bind(this)}),this.select.onValueChange=e=>{this.sync.enqueue({type:`selection`,values:e.map(e=>e.id),source:`native`})},this.select.onOptionsChange=e=>{this.sync.enqueue({type:`structure`,data:e||[],source:`native`})},this.lifecycle=new A({beforeOpen:this.events.beforeOpen,afterOpen:this.events.afterOpen,beforeClose:this.events.beforeClose,afterClose:()=>{this.render.clearDirectionClasses(),this.render.finalizeModalClose(),this.events.afterClose&&this.events.afterClose()},onOpenReady:()=>this.globalEvents.attachDocumentClick(),onCloseReady:()=>this.globalEvents.detachDocumentClick()},{timeoutDelay:this.settings.timeoutDelay,waitForAnimation:(e,t)=>this.render.waitForAnimation(e,t)}),this.globalEvents=new k({onDocumentClick:this.documentClick.bind(this),onWindowResize:()=>{!this.settings.isOpen&&!this.settings.isFullOpen||this.render.moveContent()},onWindowScroll:()=>{!this.settings.isOpen&&!this.settings.isFullOpen||this.render.moveContent()},onVisibilityChange:()=>{document.hidden&&this.close()}}),this.render.renderValues(),this.render.renderOptions(this.store.getData(!1));let a=this.selectEl.getAttribute(`aria-label`),o=this.selectEl.getAttribute(`aria-labelledby`);if(a)this.render.main.main.setAttribute(`aria-label`,a);else if(o)this.render.main.main.removeAttribute(`aria-label`),this.render.main.main.setAttribute(`aria-labelledby`,o);else if(this.selectEl.labels&&this.selectEl.labels.length>0){let e=Array.from(this.selectEl.labels).map((e,t)=>(e.id||=`${this.settings.id}-label-${t}`,e.id));this.render.main.main.removeAttribute(`aria-label`),this.render.main.main.setAttribute(`aria-labelledby`,e.join(` `))}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}enable(){this.settings.disabled=!1,this.select.enable(),this.render.enable()}disable(){this.settings.disabled=!0,this.select.disable(),this.render.disable()}getData(){return this.store.getData()}setData(e){this.sync.enqueue({type:`structure`,data:e,source:`api`})}getSelected(){let e=this.store.getSelectedOptions();return this.settings.keepOrder&&(e=this.store.selectedOrderOptions(e)),e.map(e=>e.value)}setSelected(e,t=!0){this.sync.enqueue({type:`selection`,values:e,source:`api`,runAfterChange:t})}addOption(e){this.sync.enqueue({type:`addOption`,option:e,source:`api`})}open(){if(this.settings.disabled||this.settings.isOpen)return;this.lifecycle.cancelPending(),this.render.open(),this.settings.showSearch&&this.settings.focusSearch&&this.render.searchFocus(),this.settings.isOpen=!0,this.lifecycle.requestOpen().then(()=>{this.settings.isOpen&&(this.settings.isFullOpen=this.lifecycle.isFullOpen,this.settings.isOpen=this.lifecycle.isOpen)}),this.settings.contentPosition===`absolute`&&!this.render.isModalViewActive()&&this.render.startPositionTracking();let e=this.render.content.search.input.value.trim();e!==``&&this.search(e)}close(e=null){!this.settings.isOpen||this.settings.alwaysOpen||(this.lifecycle.cancelPending(),this.render.close(),!this.settings.keepSearch&&this.render.content.search.input.value!==``&&(this.sync.flush(),this.search(``)),this.render.mainFocus(e),this.settings.isOpen=!1,this.settings.isFullOpen=!1,this.lifecycle.requestClose().then(()=>{this.settings.isOpen||(this.settings.isOpen=this.lifecycle.isOpen,this.settings.isFullOpen=this.lifecycle.isFullOpen)}),this.render.stopPositionTracking())}search(e){let t=e.trim();if(this.render.content.search.input.value!==t&&(this.render.content.search.input.value=t),t===``){this.clearSearch();return}if(this.events.search){this.runApiSearch(t);return}this.runLocalSearch(t)}clearSearch(){if(this.searchGeneration++,!this.events.search&&this.render.canFilterOptionsInPlace()){this.render.filterOptionsInPlace(``,this.events.searchFilter),this.render.resetSearchFilterState();return}this.render.resetSearchFilterState(),this.sync.enqueue({type:`structure`,data:this.store.getCatalogData(),source:`api`,preserveSelection:!0})}runLocalSearch(e){if(this.render.canFilterOptionsInPlace()){this.render.filterOptionsInPlace(e,this.events.searchFilter);return}let t=this.store.search(e,this.events.searchFilter);this.render.renderOptions(t)}runApiSearch(e){let t=++this.searchGeneration;this.render.renderSearching();let n=this.events.search(e,this.store.getSelectedOptions(),this.store.getCatalogData()),r=n=>{t===this.searchGeneration&&this.render.content.search.input.value.trim()===e&&this.sync.enqueue({type:`structure`,data:n,source:`api`,preserveSelection:!0,isSearchResult:!0})};if(n instanceof Promise){n.then(r).catch(e=>{t===this.searchGeneration&&this.render.renderError(typeof e==`string`?e:e.message)});return}if(Array.isArray(n)){r(n);return}this.render.renderError(`Search event must return a promise or an array of data`)}destroy(){this.lifecycle.destroy(),this.render.stopPositionTracking(),this.globalEvents.detach({listenScroll:this.settings.openPosition===`auto`}),this.store.setData([]),this.render.destroy(),this.select.destroy()}documentClick(e){this.settings.isOpen&&e.target&&!_(e.target,this.settings.id)&&this.close(e.type)}};function V(e){let n=new WeakMap,r=e=>{if((0,t.isRef)(e)&&(e=(0,t.unref)(e)),(0,t.isReactive)(e)&&(e=(0,t.toRaw)(e)),typeof e!=`object`||!e)return e;if(n.has(e))return n.get(e);if(Array.isArray(e)){let t=[];n.set(e,t);for(let n of e)t.push(r(n));return t}let i={};n.set(e,i);for(let t of Object.keys(e))i[t]=r(e[t]);return i};return r(e)}var H=(0,t.defineComponent)({name:`SlimSelect`,props:{modelValue:{type:[String,Array,void 0]},multiple:{type:Boolean,default:!1},data:{type:Array,required:!0},settings:{type:Object},events:{type:Object,default:()=>({})}},emits:[`update:modelValue`],data(){return{slim:null,lastAppliedData:null}},mounted(){let e={select:this.$refs.slim,data:this.data};this.settings&&(e.settings=this.settings);let t=this.events?.afterChange;e.events={...this.events,afterChange:e=>{this.handleAfterChange(e,t)}},this.slim=new B(e),this.lastAppliedData=structuredClone(V(this.data)),this.syncModelValueToSlimSelect(!1)},beforeUnmount(){this.slim&&this.slim.destroy()},watch:{modelValue:{handler:function(e){this.slim&&this.syncModelValueToSlimSelect(!1)}},data:{handler:function(e){this.slim&&(this.lastAppliedData!==null&&E(this.lastAppliedData,(0,t.toRaw)(e))||(this.slim.setData(e),this.lastAppliedData=structuredClone(V(e)),this.syncModelValueToSlimSelect(!1)))},deep:!0}},computed:{value:{get(){return this.getCleanValue(this.$props.modelValue)},set(e){this.$emit(`update:modelValue`,e)}}},methods:{getSlimSelect(){return this.slim},handleAfterChange(e,t){if(!this.slim)return;let n=this.multiple?e.map(e=>e.value):e.length>0?e[0].value:``,r=this.getCleanValue(this.$props.modelValue),i=this.slim.store.getDataOptions(!1),a=Array.isArray(r)?r.length>0&&r.every(e=>i.some(t=>t.value===e)):r!==``&&i.some(e=>e.value===r),o=Array.isArray(n)?n.length>0&&n.every(e=>i.some(t=>t.value===e)):n!==``&&i.some(e=>e.value===n);(Array.isArray(n)&&Array.isArray(this.value)?JSON.stringify(n.sort())!==JSON.stringify(this.value.sort()):this.value!==n)&&(a||o)&&(this.value=n),t&&t(e)},getCleanValue(e){let t=this.$props.multiple;return typeof e==`string`?t?[e]:e:Array.isArray(e)?t?e:e[0]:t?[]:``},syncModelValueToSlimSelect(e=!1){if(!this.slim||this.$props.modelValue===void 0)return;let t=this.getCleanValue(this.$props.modelValue),n=this.slim.getData().flatMap(e=>`label`in e?e.options:[e]);if(!(Array.isArray(t)?t.length>0&&t.every(e=>n.some(t=>t.value===e)):t!==``&&n.some(e=>e.value===t))&&!Array.isArray(t)&&!n.some(e=>e.placeholder)){let e=this.slim.getData();this.slim.setData([{value:``,text:``,placeholder:!0}].concat(e))}this.slim.setSelected(t,e)}}}),U=(e,t)=>{let n=e.__vccOpts||e;for(let[e,r]of t)n[e]=r;return n},W=[`multiple`];function G(e,n,r,i,a,o){return(0,t.openBlock)(),(0,t.createElementBlock)(`select`,{multiple:e.multiple,ref:`slim`},null,8,W)}var K=U(H,[[`render`,G]]);e.Optgroup=M,e.Option=j,e.Settings=f,e.default=K});
|
package/package.json
CHANGED