slim-select 2.13.1 → 3.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (55) hide show
  1. package/README.md +184 -43
  2. package/dist/index.d.ts +304 -52
  3. package/dist/react/index.d.ts +304 -0
  4. package/dist/react/index.js +1549 -0
  5. package/dist/react/index.umd.js +22 -0
  6. package/dist/slimselect.cjs.js +1 -2030
  7. package/dist/slimselect.css +1 -1
  8. package/dist/slimselect.css.map +1 -1
  9. package/dist/slimselect.es.js +1224 -2012
  10. package/dist/slimselect.umd.js +1 -2036
  11. package/dist/vue/index.d.ts +304 -0
  12. package/dist/vue/index.js +1341 -0
  13. package/dist/vue/index.umd.js +1 -0
  14. package/index.html +1 -0
  15. package/package.json +58 -36
  16. package/release.js +0 -7
  17. package/src/slim-select/accessibility.test.ts +782 -0
  18. package/src/slim-select/classes.test.ts +7 -6
  19. package/src/slim-select/classes.ts +8 -6
  20. package/src/slim-select/helpers.test.ts +10 -8
  21. package/src/slim-select/index.test.ts +509 -14
  22. package/src/slim-select/index.ts +58 -31
  23. package/src/slim-select/react/index.tsx +9 -0
  24. package/src/slim-select/react/react.tsx +112 -0
  25. package/src/slim-select/render.test.ts +479 -119
  26. package/src/slim-select/render.ts +213 -91
  27. package/src/slim-select/select.test.ts +28 -10
  28. package/src/slim-select/select.ts +35 -12
  29. package/src/slim-select/settings.test.ts +19 -8
  30. package/src/slim-select/settings.ts +2 -4
  31. package/src/slim-select/slimselect.scss +30 -15
  32. package/src/slim-select/store.test.ts +13 -16
  33. package/src/slim-select/store.ts +97 -86
  34. package/src/slim-select/vue/index.ts +9 -0
  35. package/src/slim-select/vue/vue.test.ts +832 -0
  36. package/src/slim-select/{vue.vue → vue/vue.vue} +45 -23
  37. package/tsconfig.json +6 -4
  38. package/{vite.config.mts → vite.config.docs.mts} +10 -0
  39. package/vite.config.lib.mts +42 -0
  40. package/vite.config.react.mts +40 -0
  41. package/vite.config.vue.mts +39 -0
  42. package/vitest.config.ts +29 -0
  43. package/dist/classes.d.ts +0 -43
  44. package/dist/helpers.d.ts +0 -5
  45. package/dist/render.d.ts +0 -81
  46. package/dist/select.d.ts +0 -30
  47. package/dist/settings.d.ts +0 -35
  48. package/dist/slimselect.global.js +0 -2033
  49. package/dist/slimselect.js +0 -2036
  50. package/dist/slimselect.min.js +0 -1
  51. package/dist/slimselect.umd.min.js +0 -1
  52. package/dist/store.d.ts +0 -84
  53. package/jest.config.js +0 -14
  54. package/src/slim-select/rollup.config.mjs +0 -127
  55. package/src/slim-select/tsconfig.json +0 -14
@@ -0,0 +1,1549 @@
1
+ import ae, { forwardRef as re, useRef as F, useImperativeHandle as oe, useEffect as j } from "react";
2
+ var P = { exports: {} }, T = {};
3
+ /**
4
+ * @license React
5
+ * react-jsx-runtime.production.js
6
+ *
7
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
8
+ *
9
+ * This source code is licensed under the MIT license found in the
10
+ * LICENSE file in the root directory of this source tree.
11
+ */
12
+ var X;
13
+ function ce() {
14
+ if (X) return T;
15
+ X = 1;
16
+ var p = Symbol.for("react.transitional.element"), e = Symbol.for("react.fragment");
17
+ function t(s, i, l) {
18
+ var r = null;
19
+ if (l !== void 0 && (r = "" + l), i.key !== void 0 && (r = "" + i.key), "key" in i) {
20
+ l = {};
21
+ for (var a in i)
22
+ a !== "key" && (l[a] = i[a]);
23
+ } else l = i;
24
+ return i = l.ref, {
25
+ $$typeof: p,
26
+ type: s,
27
+ key: r,
28
+ ref: i !== void 0 ? i : null,
29
+ props: l
30
+ };
31
+ }
32
+ return T.Fragment = e, T.jsx = t, T.jsxs = t, T;
33
+ }
34
+ var A = {};
35
+ /**
36
+ * @license React
37
+ * react-jsx-runtime.development.js
38
+ *
39
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
40
+ *
41
+ * This source code is licensed under the MIT license found in the
42
+ * LICENSE file in the root directory of this source tree.
43
+ */
44
+ var K;
45
+ function he() {
46
+ return K || (K = 1, process.env.NODE_ENV !== "production" && function() {
47
+ function p(n) {
48
+ if (n == null) return null;
49
+ if (typeof n == "function")
50
+ return n.$$typeof === ie ? null : n.displayName || n.name || null;
51
+ if (typeof n == "string") return n;
52
+ switch (n) {
53
+ case S:
54
+ return "Fragment";
55
+ case E:
56
+ return "Profiler";
57
+ case x:
58
+ return "StrictMode";
59
+ case Q:
60
+ return "Suspense";
61
+ case ee:
62
+ return "SuspenseList";
63
+ case se:
64
+ return "Activity";
65
+ }
66
+ if (typeof n == "object")
67
+ switch (typeof n.tag == "number" && console.error(
68
+ "Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."
69
+ ), n.$$typeof) {
70
+ case C:
71
+ return "Portal";
72
+ case R:
73
+ return n.displayName || "Context";
74
+ case k:
75
+ return (n._context.displayName || "Context") + ".Consumer";
76
+ case M:
77
+ var u = n.render;
78
+ return n = n.displayName, n || (n = u.displayName || u.name || "", n = n !== "" ? "ForwardRef(" + n + ")" : "ForwardRef"), n;
79
+ case te:
80
+ return u = n.displayName || null, u !== null ? u : p(n.type) || "Memo";
81
+ case _:
82
+ u = n._payload, n = n._init;
83
+ try {
84
+ return p(n(u));
85
+ } catch {
86
+ }
87
+ }
88
+ return null;
89
+ }
90
+ function e(n) {
91
+ return "" + n;
92
+ }
93
+ function t(n) {
94
+ try {
95
+ e(n);
96
+ var u = !1;
97
+ } catch {
98
+ u = !0;
99
+ }
100
+ if (u) {
101
+ u = console;
102
+ var g = u.error, v = typeof Symbol == "function" && Symbol.toStringTag && n[Symbol.toStringTag] || n.constructor.name || "Object";
103
+ return g.call(
104
+ u,
105
+ "The provided key is an unsupported type %s. This value must be coerced to a string before using it here.",
106
+ v
107
+ ), e(n);
108
+ }
109
+ }
110
+ function s(n) {
111
+ if (n === S) return "<>";
112
+ if (typeof n == "object" && n !== null && n.$$typeof === _)
113
+ return "<...>";
114
+ try {
115
+ var u = p(n);
116
+ return u ? "<" + u + ">" : "<...>";
117
+ } catch {
118
+ return "<...>";
119
+ }
120
+ }
121
+ function i() {
122
+ var n = I.A;
123
+ return n === null ? null : n.getOwner();
124
+ }
125
+ function l() {
126
+ return Error("react-stack-top-frame");
127
+ }
128
+ function r(n) {
129
+ if (q.call(n, "key")) {
130
+ var u = Object.getOwnPropertyDescriptor(n, "key").get;
131
+ if (u && u.isReactWarning) return !1;
132
+ }
133
+ return n.key !== void 0;
134
+ }
135
+ function a(n, u) {
136
+ function g() {
137
+ $ || ($ = !0, console.error(
138
+ "%s: `key` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://react.dev/link/special-props)",
139
+ u
140
+ ));
141
+ }
142
+ g.isReactWarning = !0, Object.defineProperty(n, "key", {
143
+ get: g,
144
+ configurable: !0
145
+ });
146
+ }
147
+ function c() {
148
+ var n = p(this.type);
149
+ return z[n] || (z[n] = !0, console.error(
150
+ "Accessing element.ref was removed in React 19. ref is now a regular prop. It will be removed from the JSX Element type in a future release."
151
+ )), n = this.props.ref, n !== void 0 ? n : null;
152
+ }
153
+ function h(n, u, g, v, D, B) {
154
+ var w = g.ref;
155
+ return n = {
156
+ $$typeof: O,
157
+ type: n,
158
+ key: u,
159
+ props: g,
160
+ _owner: v
161
+ }, (w !== void 0 ? w : null) !== null ? Object.defineProperty(n, "ref", {
162
+ enumerable: !1,
163
+ get: c
164
+ }) : Object.defineProperty(n, "ref", { enumerable: !1, value: null }), n._store = {}, Object.defineProperty(n._store, "validated", {
165
+ configurable: !1,
166
+ enumerable: !1,
167
+ writable: !0,
168
+ value: 0
169
+ }), Object.defineProperty(n, "_debugInfo", {
170
+ configurable: !1,
171
+ enumerable: !1,
172
+ writable: !0,
173
+ value: null
174
+ }), Object.defineProperty(n, "_debugStack", {
175
+ configurable: !1,
176
+ enumerable: !1,
177
+ writable: !0,
178
+ value: D
179
+ }), Object.defineProperty(n, "_debugTask", {
180
+ configurable: !1,
181
+ enumerable: !1,
182
+ writable: !0,
183
+ value: B
184
+ }), Object.freeze && (Object.freeze(n.props), Object.freeze(n)), n;
185
+ }
186
+ function o(n, u, g, v, D, B) {
187
+ var w = u.children;
188
+ if (w !== void 0)
189
+ if (v)
190
+ if (le(w)) {
191
+ for (v = 0; v < w.length; v++)
192
+ d(w[v]);
193
+ Object.freeze && Object.freeze(w);
194
+ } else
195
+ console.error(
196
+ "React.jsx: Static children should always be an array. You are likely explicitly calling React.jsxs or React.jsxDEV. Use the Babel transform instead."
197
+ );
198
+ else d(w);
199
+ if (q.call(u, "key")) {
200
+ w = p(n);
201
+ var L = Object.keys(u).filter(function(ne) {
202
+ return ne !== "key";
203
+ });
204
+ v = 0 < L.length ? "{key: someKey, " + L.join(": ..., ") + ": ...}" : "{key: someKey}", J[w + v] || (L = 0 < L.length ? "{" + L.join(": ..., ") + ": ...}" : "{}", console.error(
205
+ `A props object containing a "key" prop is being spread into JSX:
206
+ let props = %s;
207
+ <%s {...props} />
208
+ React keys must be passed directly to JSX without using spread:
209
+ let props = %s;
210
+ <%s key={someKey} {...props} />`,
211
+ v,
212
+ w,
213
+ L,
214
+ w
215
+ ), J[w + v] = !0);
216
+ }
217
+ if (w = null, g !== void 0 && (t(g), w = "" + g), r(u) && (t(u.key), w = "" + u.key), "key" in u) {
218
+ g = {};
219
+ for (var H in u)
220
+ H !== "key" && (g[H] = u[H]);
221
+ } else g = u;
222
+ return w && a(
223
+ g,
224
+ typeof n == "function" ? n.displayName || n.name || "Unknown" : n
225
+ ), h(
226
+ n,
227
+ w,
228
+ g,
229
+ i(),
230
+ D,
231
+ B
232
+ );
233
+ }
234
+ function d(n) {
235
+ m(n) ? n._store && (n._store.validated = 1) : typeof n == "object" && n !== null && n.$$typeof === _ && (n._payload.status === "fulfilled" ? m(n._payload.value) && n._payload.value._store && (n._payload.value._store.validated = 1) : n._store && (n._store.validated = 1));
236
+ }
237
+ function m(n) {
238
+ return typeof n == "object" && n !== null && n.$$typeof === O;
239
+ }
240
+ var f = ae, O = Symbol.for("react.transitional.element"), C = Symbol.for("react.portal"), S = Symbol.for("react.fragment"), x = Symbol.for("react.strict_mode"), E = Symbol.for("react.profiler"), k = Symbol.for("react.consumer"), R = Symbol.for("react.context"), M = Symbol.for("react.forward_ref"), Q = Symbol.for("react.suspense"), ee = Symbol.for("react.suspense_list"), te = Symbol.for("react.memo"), _ = Symbol.for("react.lazy"), se = Symbol.for("react.activity"), ie = Symbol.for("react.client.reference"), I = f.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE, q = Object.prototype.hasOwnProperty, le = Array.isArray, V = console.createTask ? console.createTask : function() {
241
+ return null;
242
+ };
243
+ f = {
244
+ react_stack_bottom_frame: function(n) {
245
+ return n();
246
+ }
247
+ };
248
+ var $, z = {}, W = f.react_stack_bottom_frame.bind(
249
+ f,
250
+ l
251
+ )(), G = V(s(l)), J = {};
252
+ A.Fragment = S, A.jsx = function(n, u, g) {
253
+ var v = 1e4 > I.recentlyCreatedOwnerStacks++;
254
+ return o(
255
+ n,
256
+ u,
257
+ g,
258
+ !1,
259
+ v ? Error("react-stack-top-frame") : W,
260
+ v ? V(s(n)) : G
261
+ );
262
+ }, A.jsxs = function(n, u, g) {
263
+ var v = 1e4 > I.recentlyCreatedOwnerStacks++;
264
+ return o(
265
+ n,
266
+ u,
267
+ g,
268
+ !0,
269
+ v ? Error("react-stack-top-frame") : W,
270
+ v ? V(s(n)) : G
271
+ );
272
+ };
273
+ }()), A;
274
+ }
275
+ var Z;
276
+ function de() {
277
+ return Z || (Z = 1, process.env.NODE_ENV === "production" ? P.exports = ce() : P.exports = he()), P.exports;
278
+ }
279
+ var ue = de();
280
+ class fe {
281
+ main;
282
+ // Placeholder
283
+ placeholder;
284
+ // Values
285
+ values;
286
+ single;
287
+ max;
288
+ value;
289
+ valueText;
290
+ valueDelete;
291
+ valueOut;
292
+ // Deselect
293
+ deselect;
294
+ deselectPath;
295
+ // Not a class but whatever
296
+ // Arrow
297
+ arrow;
298
+ arrowClose;
299
+ // Not a class but whatever
300
+ arrowOpen;
301
+ // Not a class but whatever
302
+ // Content
303
+ content;
304
+ contentOpen;
305
+ dirAbove;
306
+ dirBelow;
307
+ // Search
308
+ search;
309
+ searchHighlighter;
310
+ searching;
311
+ addable;
312
+ addablePath;
313
+ // Not a class but whatever
314
+ // List optgroups/options
315
+ list;
316
+ // Optgroup
317
+ optgroup;
318
+ optgroupLabel;
319
+ optgroupLabelText;
320
+ optgroupActions;
321
+ optgroupSelectAll;
322
+ // optgroup select all
323
+ optgroupSelectAllBox;
324
+ // Not a class but whatever
325
+ optgroupSelectAllCheck;
326
+ // Not a class but whatever
327
+ optgroupClosable;
328
+ // Option
329
+ option;
330
+ optionDelete;
331
+ // Not a class but whatever
332
+ highlighted;
333
+ // Misc
334
+ mainOpen;
335
+ close;
336
+ selected;
337
+ error;
338
+ disabled;
339
+ hide;
340
+ constructor(e) {
341
+ e || (e = {}), this.main = e.main || "ss-main", this.placeholder = e.placeholder || "ss-placeholder", this.values = e.values || "ss-values", this.single = e.single || "ss-single", this.max = e.max || "ss-max", this.value = e.value || "ss-value", this.valueText = e.valueText || "ss-value-text", this.valueDelete = e.valueDelete || "ss-value-delete", this.valueOut = e.valueOut || "ss-value-out", this.deselect = e.deselect || "ss-deselect", this.deselectPath = e.deselectPath || "M10,10 L90,90 M10,90 L90,10", this.arrow = e.arrow || "ss-arrow", this.arrowClose = e.arrowClose || "M10,30 L50,70 L90,30", this.arrowOpen = e.arrowOpen || "M10,70 L50,30 L90,70", this.content = e.content || "ss-content", this.contentOpen = e.contentOpen || "ss-open", this.dirAbove = e.dirAbove || "ss-dir-above", this.dirBelow = e.dirBelow || "ss-dir-below", this.search = e.search || "ss-search", this.searchHighlighter = e.searchHighlighter || "ss-search-highlight", this.searching = e.searching || "ss-searching", this.addable = e.addable || "ss-addable", this.addablePath = e.addablePath || "M50,10 L50,90 M10,50 L90,50", this.list = e.list || "ss-list", this.optgroup = e.optgroup || "ss-optgroup", this.optgroupLabel = e.optgroupLabel || "ss-optgroup-label", this.optgroupLabelText = e.optgroupLabelText || "ss-optgroup-label-text", this.optgroupActions = e.optgroupActions || "ss-optgroup-actions", this.optgroupSelectAll = e.optgroupSelectAll || "ss-selectall", 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 = e.optgroupClosable || "ss-closable", this.option = e.option || "ss-option", this.optionDelete = e.optionDelete || "M10,10 L90,90 M10,90 L90,10", this.highlighted = e.highlighted || "ss-highlighted", this.mainOpen = e.mainOpen || "ss-open", this.close = e.close || "ss-close", this.selected = e.selected || "ss-selected", this.error = e.error || "ss-error", this.disabled = e.disabled || "ss-disabled", this.hide = e.hide || "ss-hide";
342
+ }
343
+ }
344
+ function Y() {
345
+ return Math.random().toString(36).substring(2, 10);
346
+ }
347
+ function pe(p, e) {
348
+ function t(i, l) {
349
+ return l && i && i.classList && i.classList.contains(l) || l && i && i.dataset && i.dataset.id && i.dataset.id === e ? i : null;
350
+ }
351
+ function s(i, l) {
352
+ return !i || i === document ? null : t(i, l) ? i : s(i.parentNode, l);
353
+ }
354
+ return t(p, e) || s(p, e);
355
+ }
356
+ function N(p, e = 50, t = !1) {
357
+ let s;
358
+ return function(...i) {
359
+ const l = self, r = () => {
360
+ s = null, t || p.apply(l, i);
361
+ }, a = t && !s;
362
+ clearTimeout(s), s = setTimeout(r, e), a && p.apply(l, i);
363
+ };
364
+ }
365
+ function U(p, e) {
366
+ return JSON.stringify(p) === JSON.stringify(e);
367
+ }
368
+ function me(p) {
369
+ const e = p.replace(/[A-Z\u00C0-\u00D6\u00D8-\u00DE]/g, (t) => "-" + t.toLowerCase());
370
+ return p[0] === p[0].toUpperCase() ? e.substring(1) : e;
371
+ }
372
+ class b {
373
+ id;
374
+ value;
375
+ text;
376
+ html;
377
+ defaultSelected;
378
+ selected;
379
+ display;
380
+ disabled;
381
+ placeholder;
382
+ class;
383
+ style;
384
+ data;
385
+ mandatory;
386
+ constructor(e) {
387
+ this.id = !e.id || e.id === "" ? Y() : e.id, this.value = e.value === void 0 ? e.text || "" : e.value || "", this.text = e.text || "", this.html = e.html || "", this.defaultSelected = e.defaultSelected !== void 0 ? e.defaultSelected : !1, this.selected = e.selected !== void 0 ? e.selected : !1, this.display = e.display !== void 0 ? e.display : !0, this.disabled = e.disabled !== void 0 ? e.disabled : !1, this.mandatory = e.mandatory !== void 0 ? e.mandatory : !1, this.placeholder = e.placeholder !== void 0 ? e.placeholder : !1, this.class = e.class || "", this.style = e.style || "", this.data = e.data || {};
388
+ }
389
+ }
390
+ class y {
391
+ id;
392
+ label;
393
+ selectAll;
394
+ selectAllText;
395
+ closable;
396
+ options;
397
+ constructor(e) {
398
+ if (this.id = !e.id || e.id === "" ? Y() : e.id, this.label = e.label || "", this.selectAll = e.selectAll === void 0 ? !1 : e.selectAll, this.selectAllText = e.selectAllText || "Select All", this.closable = e.closable || "off", this.options = [], e.options)
399
+ for (const t of e.options)
400
+ this.options.push(new b(t));
401
+ }
402
+ }
403
+ class ge {
404
+ selectType = "single";
405
+ // Main data set, never null
406
+ data = [];
407
+ selectedOrder = [];
408
+ constructor(e, t) {
409
+ this.selectType = e, this.setData(t);
410
+ }
411
+ // Validate DataArrayPartial
412
+ validateDataArray(e) {
413
+ if (!Array.isArray(e))
414
+ return new Error("Data must be an array");
415
+ for (let t of e)
416
+ if (t)
417
+ if (t instanceof y || "label" in t) {
418
+ if (!("label" in t))
419
+ return new Error("Optgroup must have a label");
420
+ if ("options" in t && t.options)
421
+ for (let s of t.options) {
422
+ const i = this.validateOption(s);
423
+ if (i)
424
+ return i;
425
+ }
426
+ } else if (t instanceof b || "text" in t) {
427
+ const s = this.validateOption(t);
428
+ if (s)
429
+ return s;
430
+ } else
431
+ return new Error("Data object must be a valid optgroup or option");
432
+ return null;
433
+ }
434
+ // Validate Option
435
+ validateOption(e) {
436
+ return "text" in e ? null : new Error("Option must have a text");
437
+ }
438
+ partialToFullData(e) {
439
+ let t = [];
440
+ return e.forEach((s) => {
441
+ if (s) {
442
+ if (s instanceof y || "label" in s) {
443
+ let i = [];
444
+ "options" in s && s.options && s.options.forEach((l) => {
445
+ i.push(new b(l));
446
+ }), i.length > 0 && t.push(new y(s));
447
+ }
448
+ (s instanceof b || "text" in s) && t.push(new b(s));
449
+ }
450
+ }), t;
451
+ }
452
+ setData(e, t = !1) {
453
+ const s = this.partialToFullData(e);
454
+ if (t) {
455
+ const i = this.getSelectedOptions(), l = [];
456
+ i.forEach((r) => {
457
+ let a = !1;
458
+ for (const c of s) {
459
+ if (c instanceof b && c.id === r.id) {
460
+ a = !0;
461
+ break;
462
+ }
463
+ if (c instanceof y) {
464
+ for (const h of c.options)
465
+ if (h.id === r.id) {
466
+ a = !0;
467
+ break;
468
+ }
469
+ }
470
+ }
471
+ a || l.push(r);
472
+ }), this.data = [...l, ...s];
473
+ } else
474
+ this.data = s;
475
+ this.selectType === "single" && this.setSelectedBy("id", this.getSelected());
476
+ }
477
+ // Get data will return all the data
478
+ getData() {
479
+ return this.filter(null, !0);
480
+ }
481
+ // Get data options will return the data as a
482
+ // flat array of just options
483
+ getDataOptions() {
484
+ return this.filter(null, !1);
485
+ }
486
+ addOption(e, t = !1) {
487
+ if (t) {
488
+ let s = [new b(e)];
489
+ this.setData(s.concat(this.getData()));
490
+ } else
491
+ this.setData(this.getData().concat(new b(e)));
492
+ }
493
+ // Pass in an array of id that will loop through
494
+ // each option and set the selected property to true
495
+ // but also clean selected by determining selectType
496
+ setSelectedBy(e, t) {
497
+ let s = null, i = !1;
498
+ const l = [];
499
+ for (let a of this.data) {
500
+ if (a instanceof y)
501
+ for (let c of a.options) {
502
+ s || (s = c);
503
+ let h = c[e] || "";
504
+ c.selected = i ? !1 : t.includes(h), c.selected && (l.push(c), this.selectType === "single" && (i = !0));
505
+ }
506
+ a instanceof b && (s || (s = a), a.selected = i ? !1 : t.includes(a[e]), a.selected && (l.push(a), this.selectType === "single" && (i = !0)));
507
+ }
508
+ this.selectType === "single" && s && !i && (s.selected = !0, l.push(s));
509
+ const r = t.map((a) => l.find((c) => c[e] === a)?.id || "");
510
+ this.selectedOrder = r;
511
+ }
512
+ getSelected() {
513
+ return this.getSelectedOptions().map((e) => e.id);
514
+ }
515
+ getSelectedValues() {
516
+ return this.getSelectedOptions().map((e) => e.value);
517
+ }
518
+ getSelectedOptions() {
519
+ return this.filter((e) => e.selected, !1);
520
+ }
521
+ getOptgroupByID(e) {
522
+ for (let t of this.data)
523
+ if (t instanceof y && t.id === e)
524
+ return t;
525
+ return null;
526
+ }
527
+ getOptionByID(e) {
528
+ let t = this.filter((s) => s.id === e, !1);
529
+ return t.length ? t[0] : null;
530
+ }
531
+ getSelectType() {
532
+ return this.selectType;
533
+ }
534
+ getFirstOption() {
535
+ let e = null;
536
+ for (let t of this.data)
537
+ if (t instanceof y ? e = t.options[0] : t instanceof b && (e = t), e)
538
+ break;
539
+ return e;
540
+ }
541
+ // Take in search string and return filtered list of values
542
+ search(e, t) {
543
+ return e = e.trim(), e === "" ? this.getData() : this.filter((s) => t(s, e), !0);
544
+ }
545
+ // Filter takes in a function that will be used to filter the data
546
+ // This will also keep optgroups of sub options meet the filter requirements
547
+ filter(e, t) {
548
+ const s = [];
549
+ return this.data.forEach((i) => {
550
+ if (i instanceof y) {
551
+ let l = [];
552
+ if (i.options.forEach((a) => {
553
+ (!e || e(a)) && (t ? l.push(new b(a)) : s.push(new b(a)));
554
+ }), l.length > 0) {
555
+ let a = new y(i);
556
+ a.options = l, s.push(a);
557
+ }
558
+ }
559
+ i instanceof b && (!e || e(i)) && s.push(new b(i));
560
+ }), s;
561
+ }
562
+ // Take in an array of options and reoder them based upon the selected order
563
+ selectedOrderOptions(e) {
564
+ const t = [];
565
+ return this.selectedOrder.forEach((s) => {
566
+ const i = e.find((l) => l.id === s);
567
+ i && t.push(i);
568
+ }), e.forEach((s) => {
569
+ let i = !1;
570
+ t.forEach((l) => {
571
+ if (s.id === l.id) {
572
+ i = !0;
573
+ return;
574
+ }
575
+ }), i || t.push(s);
576
+ }), t;
577
+ }
578
+ }
579
+ class be {
580
+ settings;
581
+ store;
582
+ callbacks;
583
+ // Used to compute the range selection
584
+ lastSelectedOption;
585
+ // Elements
586
+ main;
587
+ content;
588
+ // Classes
589
+ classes;
590
+ constructor(e, t, s, i) {
591
+ this.store = s, this.settings = e, this.classes = t, this.callbacks = i, this.lastSelectedOption = null, this.main = this.mainDiv(), this.content = this.contentDiv(), this.updateClassStyles(), this.updateAriaAttributes(), this.settings.contentLocation && this.settings.contentLocation.appendChild(this.content.main);
592
+ }
593
+ // Remove disabled classes
594
+ enable() {
595
+ this.main.main.classList.remove(this.classes.disabled), this.main.main.setAttribute("aria-disabled", "false"), this.content.search.input.disabled = !1;
596
+ }
597
+ // Set disabled classes
598
+ disable() {
599
+ this.main.main.classList.add(this.classes.disabled), this.main.main.setAttribute("aria-disabled", "true"), this.content.search.input.disabled = !0;
600
+ }
601
+ open() {
602
+ this.main.arrow.path.setAttribute("d", this.classes.arrowOpen), this.main.main.setAttribute("aria-expanded", "true");
603
+ const t = this.settings.openPosition === "up" ? this.classes.dirAbove : this.classes.dirBelow;
604
+ this.main.main.classList.add(t), this.content.main.classList.add(t), this.content.main.classList.add(this.classes.contentOpen), this.content.search.input.removeAttribute("aria-hidden"), this.moveContent();
605
+ const s = this.store.getSelectedOptions();
606
+ if (s.length) {
607
+ const i = s[s.length - 1].id, l = this.content.list.querySelector('[data-id="' + i + '"]');
608
+ l && this.ensureElementInView(this.content.list, l);
609
+ }
610
+ }
611
+ close() {
612
+ this.main.main.setAttribute("aria-expanded", "false"), this.main.arrow.path.setAttribute("d", this.classes.arrowClose), this.content.main.classList.remove(this.classes.contentOpen), this.content.search.input.setAttribute("aria-hidden", "true"), this.main.main.removeAttribute("aria-activedescendant");
613
+ }
614
+ updateClassStyles() {
615
+ if (this.main.main.className = "", this.main.main.removeAttribute("style"), this.content.main.className = "", this.content.main.removeAttribute("style"), this.main.main.classList.add(this.classes.main), this.content.main.classList.add(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)
616
+ for (const e of this.settings.class)
617
+ e.trim() !== "" && (this.main.main.classList.add(e.trim()), this.content.main.classList.add(e.trim()));
618
+ (this.settings.contentPosition === "relative" || this.settings.contentPosition === "fixed") && this.content.main.classList.add("ss-" + this.settings.contentPosition);
619
+ }
620
+ updateAriaAttributes() {
621
+ const e = this.content.list.id;
622
+ 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);
623
+ }
624
+ mainDiv() {
625
+ const e = document.createElement("div");
626
+ e.dataset.id = this.settings.id, e.setAttribute("aria-label", this.settings.ariaLabel), e.tabIndex = 0, e.onkeydown = (h) => {
627
+ switch (h.key) {
628
+ case "ArrowUp":
629
+ case "ArrowDown":
630
+ return this.callbacks.open(), h.key === "ArrowDown" ? this.highlight("down") : this.highlight("up"), !1;
631
+ case "Tab":
632
+ return this.callbacks.close(), !0;
633
+ // Continue doing normal tabbing
634
+ case "Enter":
635
+ case " ":
636
+ this.callbacks.open();
637
+ const o = this.content.list.querySelector("." + this.classes.highlighted);
638
+ return o && o.click(), !1;
639
+ case "Escape":
640
+ return this.callbacks.close(), !1;
641
+ }
642
+ return h.key.length === 1 && this.callbacks.open(), !0;
643
+ }, e.onclick = (h) => {
644
+ this.settings.disabled || (this.settings.isOpen ? this.callbacks.close() : this.callbacks.open());
645
+ };
646
+ const t = document.createElement("div");
647
+ t.classList.add(this.classes.values), e.appendChild(t);
648
+ const s = document.createElement("div");
649
+ s.classList.add(this.classes.deselect);
650
+ const i = this.store?.getSelectedOptions();
651
+ !this.settings.allowDeselect || this.settings.isMultiple && i && i.length <= 0 ? s.classList.add(this.classes.hide) : s.classList.remove(this.classes.hide), s.onclick = (h) => {
652
+ if (h.stopPropagation(), this.settings.disabled)
653
+ return;
654
+ let o = !0;
655
+ const d = this.store.getSelectedOptions(), m = [];
656
+ if (this.callbacks.beforeChange && (o = this.callbacks.beforeChange(m, d) === !0), o) {
657
+ if (this.settings.isMultiple)
658
+ this.callbacks.setSelected([], !1), this.updateDeselectAll();
659
+ else {
660
+ const f = this.store.getFirstOption(), O = f ? f.id : "";
661
+ this.callbacks.setSelected(O, !1);
662
+ }
663
+ this.settings.closeOnSelect && this.callbacks.close(), this.callbacks.afterChange && this.callbacks.afterChange(this.store.getSelectedOptions());
664
+ }
665
+ };
666
+ const l = document.createElementNS("http://www.w3.org/2000/svg", "svg");
667
+ l.setAttribute("viewBox", "0 0 100 100");
668
+ const r = document.createElementNS("http://www.w3.org/2000/svg", "path");
669
+ r.setAttribute("d", this.classes.deselectPath), l.appendChild(r), s.appendChild(l), e.appendChild(s);
670
+ const a = document.createElementNS("http://www.w3.org/2000/svg", "svg");
671
+ a.classList.add(this.classes.arrow), a.setAttribute("viewBox", "0 0 100 100");
672
+ const c = document.createElementNS("http://www.w3.org/2000/svg", "path");
673
+ return c.setAttribute("d", this.classes.arrowClose), this.settings.alwaysOpen && a.classList.add(this.classes.hide), a.appendChild(c), e.appendChild(a), {
674
+ main: e,
675
+ values: t,
676
+ deselect: {
677
+ main: s,
678
+ svg: l,
679
+ path: r
680
+ },
681
+ arrow: {
682
+ main: a,
683
+ path: c
684
+ }
685
+ };
686
+ }
687
+ mainFocus(e) {
688
+ e !== "click" && this.main.main.focus({ preventScroll: !0 });
689
+ }
690
+ placeholder() {
691
+ const e = this.store.filter((i) => i.placeholder, !1);
692
+ let t = this.settings.placeholderText;
693
+ e.length && (e[0].html !== "" ? t = e[0].html : e[0].text !== "" && (t = e[0].text));
694
+ const s = document.createElement("div");
695
+ return s.classList.add(this.classes.placeholder), s.innerHTML = t, s;
696
+ }
697
+ // Get selected values and append to multiSelected values container
698
+ // and remove those who shouldnt exist
699
+ renderValues() {
700
+ if (!this.settings.isMultiple) {
701
+ this.renderSingleValue();
702
+ return;
703
+ }
704
+ this.renderMultipleValues(), this.updateDeselectAll();
705
+ }
706
+ renderSingleValue() {
707
+ const e = this.store.filter((s) => s.selected && !s.placeholder, !1), t = e.length > 0 ? e[0] : null;
708
+ if (!t)
709
+ this.main.values.innerHTML = this.placeholder().outerHTML;
710
+ else {
711
+ const s = document.createElement("div");
712
+ s.classList.add(this.classes.single), t.html ? s.innerHTML = t.html : s.innerText = t.text, this.main.values.innerHTML = s.outerHTML;
713
+ }
714
+ !this.settings.allowDeselect || !e.length ? this.main.deselect.main.classList.add(this.classes.hide) : this.main.deselect.main.classList.remove(this.classes.hide);
715
+ }
716
+ renderMultipleValues() {
717
+ let e = this.main.values.childNodes, t = this.store.filter((i) => i.selected && i.display, !1);
718
+ if (t.length === 0) {
719
+ this.main.values.innerHTML = this.placeholder().outerHTML;
720
+ return;
721
+ } else {
722
+ const i = this.main.values.querySelector("." + this.classes.placeholder);
723
+ i && i.remove();
724
+ }
725
+ if (t.length > this.settings.maxValuesShown) {
726
+ const i = document.createElement("div");
727
+ i.classList.add(this.classes.max), i.textContent = this.settings.maxValuesMessage.replace("{number}", t.length.toString()), this.main.values.innerHTML = i.outerHTML;
728
+ return;
729
+ } else {
730
+ const i = this.main.values.querySelector("." + this.classes.max);
731
+ i && i.remove();
732
+ }
733
+ this.settings.keepOrder && (t = this.store.selectedOrderOptions(t));
734
+ let s = [];
735
+ for (let i = 0; i < e.length; i++) {
736
+ const l = e[i], r = l.getAttribute("data-id");
737
+ r && (t.filter((c) => c.id === r, !1).length || s.push(l));
738
+ }
739
+ for (const i of s)
740
+ i.classList.add(this.classes.valueOut), setTimeout(() => {
741
+ this.main.values.hasChildNodes() && this.main.values.contains(i) && this.main.values.removeChild(i);
742
+ }, 100);
743
+ e = this.main.values.childNodes;
744
+ for (let i = 0; i < t.length; i++) {
745
+ let l = !0;
746
+ for (let r = 0; r < e.length; r++)
747
+ t[i].id === String(e[r].dataset.id) && (l = !1);
748
+ l && (this.settings.keepOrder ? this.main.values.appendChild(this.multipleValue(t[i])) : e.length === 0 ? this.main.values.appendChild(this.multipleValue(t[i])) : i === 0 ? this.main.values.insertBefore(this.multipleValue(t[i]), e[i]) : e[i - 1].insertAdjacentElement("afterend", this.multipleValue(t[i])));
749
+ }
750
+ }
751
+ multipleValue(e) {
752
+ const t = document.createElement("div");
753
+ t.classList.add(this.classes.value), t.dataset.id = e.id;
754
+ const s = document.createElement("div");
755
+ if (s.classList.add(this.classes.valueText), s.textContent = e.text, t.appendChild(s), !e.mandatory) {
756
+ const i = document.createElement("div");
757
+ i.classList.add(this.classes.valueDelete), i.setAttribute("tabindex", "0"), i.onclick = (a) => {
758
+ if (a.preventDefault(), a.stopPropagation(), this.settings.disabled)
759
+ return;
760
+ let c = !0;
761
+ const h = this.store.getSelectedOptions(), o = h.filter((d) => d.selected && d.id !== e.id, !0);
762
+ if (!(this.settings.minSelected && o.length < this.settings.minSelected) && (this.callbacks.beforeChange && (c = this.callbacks.beforeChange(o, h) === !0), c)) {
763
+ let d = [];
764
+ for (const m of o) {
765
+ if (m instanceof y)
766
+ for (const f of m.options)
767
+ f.id && d.push(f.id);
768
+ m instanceof b && d.push(m.id);
769
+ }
770
+ this.callbacks.setSelected(d, !1), this.settings.closeOnSelect && this.callbacks.close(), this.callbacks.afterChange && this.callbacks.afterChange(o), this.updateDeselectAll();
771
+ }
772
+ };
773
+ const l = document.createElementNS("http://www.w3.org/2000/svg", "svg");
774
+ l.setAttribute("viewBox", "0 0 100 100");
775
+ const r = document.createElementNS("http://www.w3.org/2000/svg", "path");
776
+ r.setAttribute("d", this.classes.optionDelete), l.appendChild(r), i.appendChild(l), t.appendChild(i), i.onkeydown = (a) => {
777
+ a.key === "Enter" && i.click();
778
+ };
779
+ }
780
+ return t;
781
+ }
782
+ contentDiv() {
783
+ const e = document.createElement("div");
784
+ e.dataset.id = this.settings.id;
785
+ const t = this.searchDiv();
786
+ e.appendChild(t.main);
787
+ const s = this.listDiv();
788
+ return e.appendChild(s), {
789
+ main: e,
790
+ search: t,
791
+ list: s
792
+ };
793
+ }
794
+ moveContent() {
795
+ if (this.settings.contentPosition === "relative") {
796
+ this.moveContentBelow();
797
+ return;
798
+ }
799
+ if (this.settings.openPosition === "down") {
800
+ this.moveContentBelow();
801
+ return;
802
+ } else if (this.settings.openPosition === "up") {
803
+ this.moveContentAbove();
804
+ return;
805
+ }
806
+ this.putContent() === "up" ? this.moveContentAbove() : this.moveContentBelow();
807
+ }
808
+ searchDiv() {
809
+ const e = document.createElement("div"), t = document.createElement("input"), s = document.createElement("div");
810
+ e.classList.add(this.classes.search);
811
+ const i = {
812
+ main: e,
813
+ input: t
814
+ };
815
+ if (this.settings.showSearch || (e.classList.add(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 = N((l) => {
816
+ this.callbacks.search(l.target.value);
817
+ }, 100), t.onkeydown = (l) => {
818
+ switch (l.key) {
819
+ case "ArrowUp":
820
+ case "ArrowDown":
821
+ return l.key === "ArrowDown" ? this.highlight("down") : this.highlight("up"), !1;
822
+ case "Tab":
823
+ return this.callbacks.close(), !0;
824
+ // Continue doing normal tabbing
825
+ case "Escape":
826
+ return this.callbacks.close(), !1;
827
+ case " ":
828
+ const r = this.content.list.querySelector("." + this.classes.highlighted);
829
+ return r ? (r.click(), !1) : !0;
830
+ case "Enter":
831
+ const a = this.content.list.querySelector("." + this.classes.highlighted);
832
+ return a ? (a.click(), !1) : this.callbacks.addable ? (s.click(), !1) : !0;
833
+ }
834
+ return !0;
835
+ }, e.appendChild(t), this.callbacks.addable) {
836
+ s.classList.add(this.classes.addable);
837
+ const l = document.createElementNS("http://www.w3.org/2000/svg", "svg");
838
+ l.setAttribute("viewBox", "0 0 100 100");
839
+ const r = document.createElementNS("http://www.w3.org/2000/svg", "path");
840
+ r.setAttribute("d", this.classes.addablePath), l.appendChild(r), s.appendChild(l), s.onclick = (a) => {
841
+ if (a.preventDefault(), a.stopPropagation(), !this.callbacks.addable)
842
+ return;
843
+ const c = this.content.search.input.value.trim();
844
+ if (c === "") {
845
+ this.content.search.input.focus();
846
+ return;
847
+ }
848
+ const h = (d) => {
849
+ let m = new b(d);
850
+ if (this.callbacks.addOption(m), this.settings.isMultiple) {
851
+ let f = this.store.getSelected();
852
+ f.push(m.id), this.callbacks.setSelected(f, !0);
853
+ } else
854
+ this.callbacks.setSelected([m.id], !0);
855
+ this.callbacks.search(""), this.settings.closeOnSelect && setTimeout(() => {
856
+ this.callbacks.close();
857
+ }, 100);
858
+ }, o = this.callbacks.addable(c);
859
+ o === !1 || o === void 0 || o === null || (o instanceof Promise ? o.then((d) => {
860
+ typeof d == "string" ? h({
861
+ text: d,
862
+ value: d
863
+ }) : o instanceof Error ? this.renderError(o.message) : h(d);
864
+ }) : typeof o == "string" ? h({
865
+ text: o,
866
+ value: o
867
+ }) : o instanceof Error ? this.renderError(o.message) : h(o));
868
+ }, e.appendChild(s), i.addable = {
869
+ main: s,
870
+ svg: l,
871
+ path: r
872
+ };
873
+ }
874
+ return i;
875
+ }
876
+ searchFocus() {
877
+ this.content.search.input.focus();
878
+ }
879
+ clearSearch() {
880
+ this.content.search.input.value = "";
881
+ }
882
+ getOptions(e = !1, t = !1, s = !1) {
883
+ let i = "." + this.classes.option;
884
+ return e && (i += ":not(." + this.classes.placeholder + ")"), t && (i += ":not(." + this.classes.disabled + ")"), s && (i += ":not(." + this.classes.hide + ")"), Array.from(this.content.list.querySelectorAll(i));
885
+ }
886
+ // highlightUp is used to highlight the previous option in the list
887
+ highlight(e) {
888
+ const t = this.getOptions(!0, !0, !0);
889
+ if (t.length === 0)
890
+ return;
891
+ if (t.length === 1 && !t[0].classList.contains(this.classes.highlighted)) {
892
+ t[0].classList.add(this.classes.highlighted);
893
+ return;
894
+ }
895
+ let s = !1;
896
+ for (const l of t)
897
+ l.classList.contains(this.classes.highlighted) && (s = !0);
898
+ if (!s) {
899
+ for (const l of t)
900
+ if (l.classList.contains(this.classes.selected)) {
901
+ l.classList.add(this.classes.highlighted);
902
+ break;
903
+ }
904
+ }
905
+ for (let l = 0; l < t.length; l++)
906
+ if (t[l].classList.contains(this.classes.highlighted)) {
907
+ const r = t[l];
908
+ r.classList.remove(this.classes.highlighted);
909
+ const a = r.parentElement;
910
+ if (a && a.classList.contains(this.classes.mainOpen)) {
911
+ const o = a.querySelector("." + this.classes.optgroupLabel);
912
+ o && o.click();
913
+ }
914
+ let c = t[e === "down" ? l + 1 < t.length ? l + 1 : 0 : l - 1 >= 0 ? l - 1 : t.length - 1];
915
+ c.classList.add(this.classes.highlighted), this.ensureElementInView(this.content.list, c), c.id && this.main.main.setAttribute("aria-activedescendant", c.id);
916
+ const h = c.parentElement;
917
+ if (h && h.classList.contains(this.classes.close)) {
918
+ const o = h.querySelector("." + this.classes.optgroupLabel);
919
+ o && o.click();
920
+ }
921
+ return;
922
+ }
923
+ const i = t[e === "down" ? 0 : t.length - 1];
924
+ i.classList.add(this.classes.highlighted), i.id && this.main.main.setAttribute("aria-activedescendant", i.id), this.ensureElementInView(this.content.list, i);
925
+ }
926
+ // Create main container that options will reside
927
+ listDiv() {
928
+ const e = document.createElement("div");
929
+ e.classList.add(this.classes.list);
930
+ const t = this.settings.id + "-list";
931
+ return e.id = t, e.dataset.id = t, e;
932
+ }
933
+ renderError(e) {
934
+ this.content.list.innerHTML = "";
935
+ const t = document.createElement("div");
936
+ t.classList.add(this.classes.error), t.textContent = e, this.content.list.appendChild(t);
937
+ }
938
+ renderSearching() {
939
+ this.content.list.innerHTML = "";
940
+ const e = document.createElement("div");
941
+ e.classList.add(this.classes.searching), e.textContent = this.settings.searchingText, this.content.list.appendChild(e);
942
+ }
943
+ // Take in data and add options to
944
+ renderOptions(e) {
945
+ if (this.content.list.innerHTML = "", e.length === 0) {
946
+ const s = document.createElement("div");
947
+ s.classList.add(this.classes.search), this.callbacks.addable ? s.innerHTML = this.settings.addableText.replace("{value}", this.content.search.input.value) : s.innerHTML = this.settings.searchText, this.content.list.appendChild(s);
948
+ return;
949
+ }
950
+ this.settings.allowDeselect && !this.settings.isMultiple && (this.store.filter((i) => i.placeholder, !1).length || this.store.addOption(
951
+ new b({
952
+ text: "",
953
+ value: "",
954
+ selected: !1,
955
+ placeholder: !0
956
+ }),
957
+ !0
958
+ ));
959
+ const t = document.createDocumentFragment();
960
+ for (const s of e) {
961
+ if (s instanceof y) {
962
+ const i = document.createElement("div");
963
+ i.classList.add(this.classes.optgroup);
964
+ const l = document.createElement("div");
965
+ l.classList.add(this.classes.optgroupLabel), i.appendChild(l);
966
+ const r = document.createElement("div");
967
+ r.classList.add(this.classes.optgroupLabelText), r.textContent = s.label, l.appendChild(r);
968
+ const a = document.createElement("div");
969
+ if (a.classList.add(this.classes.optgroupActions), l.appendChild(a), this.settings.isMultiple && s.selectAll) {
970
+ const c = document.createElement("div");
971
+ c.classList.add(this.classes.optgroupSelectAll);
972
+ let h = !0;
973
+ for (const O of s.options)
974
+ if (!O.selected) {
975
+ h = !1;
976
+ break;
977
+ }
978
+ h && c.classList.add(this.classes.selected);
979
+ const o = document.createElement("span");
980
+ o.textContent = s.selectAllText, c.appendChild(o);
981
+ const d = document.createElementNS("http://www.w3.org/2000/svg", "svg");
982
+ d.setAttribute("viewBox", "0 0 100 100"), c.appendChild(d);
983
+ const m = document.createElementNS("http://www.w3.org/2000/svg", "path");
984
+ m.setAttribute("d", this.classes.optgroupSelectAllBox), d.appendChild(m);
985
+ const f = document.createElementNS("http://www.w3.org/2000/svg", "path");
986
+ f.setAttribute("d", this.classes.optgroupSelectAllCheck), d.appendChild(f), c.addEventListener("click", (O) => {
987
+ O.preventDefault(), O.stopPropagation();
988
+ const C = this.store.getSelected();
989
+ if (h) {
990
+ const S = C.filter((x) => {
991
+ for (const E of s.options)
992
+ if (x === E.id)
993
+ return !1;
994
+ return !0;
995
+ });
996
+ this.callbacks.setSelected(S, !0);
997
+ return;
998
+ } else {
999
+ let S = s.options.map((E) => E.id).filter((E) => E !== void 0);
1000
+ const x = C.concat(S);
1001
+ for (const E of s.options)
1002
+ E.id && !this.store.getOptionByID(E.id) && this.callbacks.addOption(new b(E));
1003
+ this.callbacks.setSelected(x, !0);
1004
+ return;
1005
+ }
1006
+ }), a.appendChild(c);
1007
+ }
1008
+ if (s.closable !== "off") {
1009
+ const c = document.createElement("div");
1010
+ c.classList.add(this.classes.optgroupClosable);
1011
+ const h = document.createElementNS("http://www.w3.org/2000/svg", "svg");
1012
+ h.setAttribute("viewBox", "0 0 100 100"), h.classList.add(this.classes.arrow), c.appendChild(h);
1013
+ const o = document.createElementNS("http://www.w3.org/2000/svg", "path");
1014
+ h.appendChild(o), s.options.some((d) => d.selected) || this.content.search.input.value.trim() !== "" ? (c.classList.add(this.classes.mainOpen), o.setAttribute("d", this.classes.arrowOpen)) : s.closable === "open" ? (i.classList.add(this.classes.mainOpen), o.setAttribute("d", this.classes.arrowOpen)) : s.closable === "close" && (i.classList.add(this.classes.close), o.setAttribute("d", this.classes.arrowClose)), l.addEventListener("click", (d) => {
1015
+ d.preventDefault(), d.stopPropagation(), i.classList.contains(this.classes.close) ? (i.classList.remove(this.classes.close), i.classList.add(this.classes.mainOpen), o.setAttribute("d", this.classes.arrowOpen)) : (i.classList.remove(this.classes.mainOpen), i.classList.add(this.classes.close), o.setAttribute("d", this.classes.arrowClose));
1016
+ }), a.appendChild(c);
1017
+ }
1018
+ i.appendChild(l);
1019
+ for (const c of s.options)
1020
+ i.appendChild(this.option(new b(c))), t.appendChild(i);
1021
+ }
1022
+ s instanceof b && t.appendChild(this.option(s));
1023
+ }
1024
+ this.content.list.appendChild(t);
1025
+ }
1026
+ // Create option div element
1027
+ option(e) {
1028
+ if (e.placeholder) {
1029
+ const s = document.createElement("div");
1030
+ return s.classList.add(this.classes.option), s.classList.add(this.classes.hide), s;
1031
+ }
1032
+ const t = document.createElement("div");
1033
+ return t.dataset.id = e.id, t.id = this.settings.id + "-" + e.id, t.classList.add(this.classes.option), t.setAttribute("role", "option"), e.class && e.class.split(" ").forEach((s) => {
1034
+ t.classList.add(s);
1035
+ }), e.style && (t.style.cssText = e.style), this.settings.searchHighlight && this.content.search.input.value.trim() !== "" ? t.innerHTML = this.highlightText(
1036
+ e.html !== "" ? e.html : e.text,
1037
+ this.content.search.input.value,
1038
+ this.classes.searchHighlighter
1039
+ ) : e.html !== "" ? t.innerHTML = e.html : t.textContent = e.text, this.settings.showOptionTooltips && t.textContent && t.setAttribute("title", t.textContent), e.display || t.classList.add(this.classes.hide), e.disabled && t.classList.add(this.classes.disabled), e.selected && this.settings.hideSelected && t.classList.add(this.classes.hide), e.selected ? (t.classList.add(this.classes.selected), t.setAttribute("aria-selected", "true"), this.main.main.setAttribute("aria-activedescendant", t.id)) : (t.classList.remove(this.classes.selected), t.setAttribute("aria-selected", "false")), t.addEventListener("click", (s) => {
1040
+ s.preventDefault(), s.stopPropagation();
1041
+ const i = this.store.getSelected(), l = s.currentTarget, r = String(l.dataset.id), a = s.ctrlKey || s.metaKey;
1042
+ if (e.disabled || !this.settings.isMultiple && e.selected && !this.settings.allowDeselect || this.settings.isMultiple && this.settings.maxSelected <= i.length && !e.selected || this.settings.isMultiple && this.settings.minSelected >= i.length && e.selected && !a)
1043
+ return;
1044
+ let c = !1;
1045
+ const h = this.store.getSelectedOptions();
1046
+ let o = [];
1047
+ if (this.settings.isMultiple) {
1048
+ const d = h.some((f) => f.id === r);
1049
+ if (s.shiftKey && this.lastSelectedOption) {
1050
+ const f = this.store.getDataOptions(), O = f.findIndex((S) => S.id === this.lastSelectedOption.id), C = f.findIndex((S) => S.id === e.id);
1051
+ if (O >= 0 && C >= 0) {
1052
+ const S = Math.min(O, C), x = Math.max(O, C), k = f.slice(S, x + 1).filter((R) => !h.find((M) => M.id === R.id));
1053
+ h.length + k.length <= this.settings.maxSelected ? o = h.concat(k) : o = h;
1054
+ } else
1055
+ o = h;
1056
+ } else a ? (d ? o = h.filter((f) => f.id !== r) : o = h.concat(e), this.lastSelectedOption = e) : (d ? o = h.filter((f) => f.id !== r) : o = h.concat(e), this.lastSelectedOption = e);
1057
+ }
1058
+ if (this.settings.isMultiple || (e.selected ? o = [] : o = [e]), this.callbacks.beforeChange || (c = !0), this.callbacks.beforeChange && (this.callbacks.beforeChange(o, h) === !1 ? c = !1 : c = !0), c) {
1059
+ this.store.getOptionByID(r) || this.callbacks.addOption(e), this.callbacks.setSelected(
1060
+ o.map((f) => f.id),
1061
+ !1
1062
+ );
1063
+ const d = s.ctrlKey || s.metaKey || s.shiftKey;
1064
+ this.settings.closeOnSelect && !(this.settings.isMultiple && d) && this.callbacks.close(), this.callbacks.afterChange && this.callbacks.afterChange(o);
1065
+ }
1066
+ }), t;
1067
+ }
1068
+ destroy() {
1069
+ this.main.main.remove(), this.content.main.remove();
1070
+ }
1071
+ highlightText(e, t, s) {
1072
+ const i = t.trim();
1073
+ if (i === "")
1074
+ return e;
1075
+ const l = i.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"), r = document.createElement("div");
1076
+ r.innerHTML = e;
1077
+ const a = (c) => {
1078
+ if (c.nodeType === Node.TEXT_NODE) {
1079
+ const h = c.textContent || "", o = new RegExp("(" + l + ")", "i");
1080
+ if (o.test(h)) {
1081
+ const d = document.createElement("span");
1082
+ h.split(o).forEach((f, O) => {
1083
+ if (f && o.test(f)) {
1084
+ const C = document.createElement("mark");
1085
+ C.className = s, C.textContent = f, d.appendChild(C);
1086
+ } else f && d.appendChild(document.createTextNode(f));
1087
+ }), c.parentNode?.replaceChild(d, c);
1088
+ }
1089
+ } else c.nodeType === Node.ELEMENT_NODE && Array.from(c.childNodes).forEach((h) => a(h));
1090
+ };
1091
+ return Array.from(r.childNodes).forEach((c) => a(c)), r.innerHTML;
1092
+ }
1093
+ moveContentAbove() {
1094
+ const e = this.main.main.offsetHeight, t = this.content.main.offsetHeight;
1095
+ this.main.main.classList.remove(this.classes.dirBelow), this.main.main.classList.add(this.classes.dirAbove), this.content.main.classList.remove(this.classes.dirBelow), this.content.main.classList.add(this.classes.dirAbove);
1096
+ const s = this.main.main.getBoundingClientRect();
1097
+ this.content.main.style.margin = "-" + (e + t - 1) + "px 0px 0px 0px", this.content.main.style.top = s.top + s.height + (this.settings.contentPosition === "fixed" ? 0 : window.scrollY) + "px", this.content.main.style.left = s.left + (this.settings.contentPosition === "fixed" ? 0 : window.scrollX) + "px", this.content.main.style.width = s.width + "px";
1098
+ }
1099
+ moveContentBelow() {
1100
+ this.main.main.classList.remove(this.classes.dirAbove), this.main.main.classList.add(this.classes.dirBelow), this.content.main.classList.remove(this.classes.dirAbove), this.content.main.classList.add(this.classes.dirBelow);
1101
+ const e = this.main.main.getBoundingClientRect();
1102
+ this.content.main.style.margin = "-1px 0px 0px 0px", this.settings.contentPosition !== "relative" && (this.content.main.style.top = e.top + e.height + (this.settings.contentPosition === "fixed" ? 0 : window.scrollY) + "px", this.content.main.style.left = e.left + (this.settings.contentPosition === "fixed" ? 0 : window.scrollX) + "px", this.content.main.style.width = e.width + "px");
1103
+ }
1104
+ ensureElementInView(e, t) {
1105
+ const s = e.scrollTop + e.offsetTop, i = s + e.clientHeight, l = t.offsetTop, r = l + t.clientHeight;
1106
+ l < s ? e.scrollTop -= s - l : r > i && (e.scrollTop += r - i);
1107
+ }
1108
+ putContent() {
1109
+ const e = this.main.main.offsetHeight, t = this.main.main.getBoundingClientRect(), s = this.content.main.offsetHeight;
1110
+ return window.innerHeight - (t.top + e) <= s && t.top > s ? "up" : "down";
1111
+ }
1112
+ // Updates deselect based on item count and allowDeselect setting
1113
+ updateDeselectAll() {
1114
+ if (!this.store || !this.settings)
1115
+ return;
1116
+ const e = this.store.getSelectedOptions(), t = e && e.length > 0, s = this.settings.isMultiple, i = this.settings.allowDeselect, l = this.main.deselect.main, r = this.classes.hide;
1117
+ i && !(s && !t) ? l.classList.remove(r) : l.classList.add(r);
1118
+ }
1119
+ }
1120
+ class ve {
1121
+ select;
1122
+ // Mutation observer fields
1123
+ onValueChange;
1124
+ onClassChange;
1125
+ onDisabledChange;
1126
+ onOptionsChange;
1127
+ // Change observers
1128
+ listen = !1;
1129
+ observer = null;
1130
+ constructor(e) {
1131
+ this.select = e, this.valueChange = this.valueChange.bind(this), this.select.addEventListener("change", this.valueChange, {
1132
+ // allow bubbling of event
1133
+ passive: !0
1134
+ }), this.observer = new MutationObserver(this.observeCall.bind(this)), this.changeListen(!0);
1135
+ }
1136
+ enable() {
1137
+ this.select.disabled = !1;
1138
+ }
1139
+ disable() {
1140
+ this.select.disabled = !0;
1141
+ }
1142
+ hideUI() {
1143
+ this.select.tabIndex = -1, this.select.style.position = "absolute", this.select.style.width = "1px", this.select.style.height = "1px", this.select.style.opacity = "0", this.select.style.overflow = "hidden", this.select.style.pointerEvents = "none", this.select.style.margin = "0", this.select.style.padding = "0", this.select.style.borderWidth = "0", this.select.style.clip = "rect(0 0 0 0)", this.select.setAttribute("aria-hidden", "true");
1144
+ }
1145
+ showUI() {
1146
+ this.select.removeAttribute("tabindex"), this.select.style.position = "", this.select.style.width = "", this.select.style.height = "", this.select.style.opacity = "", this.select.style.overflow = "", this.select.style.pointerEvents = "", this.select.style.margin = "", this.select.style.padding = "", this.select.style.borderWidth = "", this.select.style.clip = "", this.select.removeAttribute("aria-hidden");
1147
+ }
1148
+ changeListen(e) {
1149
+ this.listen = e, e && this.observer && this.observer.observe(this.select, {
1150
+ subtree: !0,
1151
+ // subtree for optgroups options
1152
+ childList: !0,
1153
+ // children changes
1154
+ attributes: !0
1155
+ // attributes changes
1156
+ }), e || this.observer && this.observer.disconnect();
1157
+ }
1158
+ // This function get triggers when the select value changes
1159
+ // and will call the onValueChange function if it exists
1160
+ valueChange(e) {
1161
+ return this.listen && this.onValueChange && this.onValueChange(this.getSelectedOptions()), !0;
1162
+ }
1163
+ observeCall(e) {
1164
+ if (!this.listen)
1165
+ return;
1166
+ let t = !1, s = !1, i = !1;
1167
+ for (const l of e) {
1168
+ if (l.target === this.select && (l.attributeName === "disabled" && (s = !0), l.attributeName === "class" && (t = !0), l.type === "childList")) {
1169
+ for (const r of Array.from(l.addedNodes))
1170
+ if (r.nodeName === "OPTION" && r.value === this.select.value) {
1171
+ this.select.dispatchEvent(new Event("change"));
1172
+ break;
1173
+ }
1174
+ i = !0;
1175
+ }
1176
+ (l.target.nodeName === "OPTGROUP" || l.target.nodeName === "OPTION") && (i = !0);
1177
+ }
1178
+ t && this.onClassChange && this.onClassChange(this.select.className.split(" ")), s && this.onDisabledChange && (this.changeListen(!1), this.onDisabledChange(this.select.disabled), this.changeListen(!0)), i && this.onOptionsChange && (this.changeListen(!1), this.onOptionsChange(this.getData()), this.changeListen(!0));
1179
+ }
1180
+ // From the select element pull optgroup and options into data
1181
+ getData() {
1182
+ let e = [];
1183
+ const t = this.select.childNodes;
1184
+ for (const s of t)
1185
+ s.nodeName === "OPTGROUP" && e.push(this.getDataFromOptgroup(s)), s.nodeName === "OPTION" && e.push(this.getDataFromOption(s));
1186
+ return e;
1187
+ }
1188
+ getDataFromOptgroup(e) {
1189
+ let t = {
1190
+ id: e.id,
1191
+ label: e.label,
1192
+ selectAll: e.dataset ? e.dataset.selectall === "true" : !1,
1193
+ selectAllText: e.dataset ? e.dataset.selectalltext : "Select all",
1194
+ closable: e.dataset ? e.dataset.closable : "off",
1195
+ options: []
1196
+ };
1197
+ const s = e.childNodes;
1198
+ for (const i of s)
1199
+ i.nodeName === "OPTION" && t.options.push(this.getDataFromOption(i));
1200
+ return t;
1201
+ }
1202
+ // From passed in option pull pieces of usable information
1203
+ getDataFromOption(e) {
1204
+ return {
1205
+ id: e.id,
1206
+ value: e.value,
1207
+ text: e.text,
1208
+ html: e.dataset && e.dataset.html ? e.dataset.html : "",
1209
+ defaultSelected: e.defaultSelected,
1210
+ selected: e.selected,
1211
+ display: e.style.display !== "none",
1212
+ disabled: e.disabled,
1213
+ mandatory: e.dataset ? e.dataset.mandatory === "true" : !1,
1214
+ placeholder: e.dataset.placeholder === "true",
1215
+ class: e.className,
1216
+ style: e.style.cssText,
1217
+ data: e.dataset
1218
+ };
1219
+ }
1220
+ getSelectedOptions() {
1221
+ let e = [];
1222
+ const t = this.select.childNodes;
1223
+ for (const s of t) {
1224
+ if (s.nodeName === "OPTGROUP") {
1225
+ const i = s.childNodes;
1226
+ for (const l of i)
1227
+ if (l.nodeName === "OPTION") {
1228
+ const r = l;
1229
+ r.selected && e.push(this.getDataFromOption(r));
1230
+ }
1231
+ }
1232
+ if (s.nodeName === "OPTION") {
1233
+ const i = s;
1234
+ i.selected && e.push(this.getDataFromOption(i));
1235
+ }
1236
+ }
1237
+ return e;
1238
+ }
1239
+ getSelectedValues() {
1240
+ return this.getSelectedOptions().map((e) => e.value);
1241
+ }
1242
+ setSelected(e) {
1243
+ this.changeListen(!1);
1244
+ const t = this.select.childNodes;
1245
+ for (const s of t) {
1246
+ if (s.nodeName === "OPTGROUP") {
1247
+ const l = s.childNodes;
1248
+ for (const r of l)
1249
+ if (r.nodeName === "OPTION") {
1250
+ const a = r;
1251
+ a.selected = e.includes(a.id);
1252
+ }
1253
+ }
1254
+ if (s.nodeName === "OPTION") {
1255
+ const i = s;
1256
+ i.selected = e.includes(i.id);
1257
+ }
1258
+ }
1259
+ this.changeListen(!0);
1260
+ }
1261
+ // Set selected options by value instead of id
1262
+ // This is useful when the id is not known
1263
+ // and only the value is known
1264
+ // but the value is not unique and can be duplicated
1265
+ setSelectedByValue(e) {
1266
+ this.changeListen(!1);
1267
+ const t = this.select.childNodes;
1268
+ for (const s of t) {
1269
+ if (s.nodeName === "OPTGROUP") {
1270
+ const l = s.childNodes;
1271
+ for (const r of l)
1272
+ if (r.nodeName === "OPTION") {
1273
+ const a = r;
1274
+ a.selected = e.includes(a.value);
1275
+ }
1276
+ }
1277
+ if (s.nodeName === "OPTION") {
1278
+ const i = s;
1279
+ i.selected = e.includes(i.value);
1280
+ }
1281
+ }
1282
+ this.changeListen(!0);
1283
+ }
1284
+ updateSelect(e, t, s) {
1285
+ this.changeListen(!1), e && (this.select.dataset.id = e), t && (this.select.style.cssText = t), s && (this.select.className = "", s.forEach((i) => {
1286
+ i.trim() !== "" && this.select.classList.add(i.trim());
1287
+ })), this.changeListen(!0);
1288
+ }
1289
+ updateOptions(e) {
1290
+ this.changeListen(!1), this.select.innerHTML = "";
1291
+ for (const t of e)
1292
+ t instanceof y && this.select.appendChild(this.createOptgroup(t)), t instanceof b && this.select.appendChild(this.createOption(t));
1293
+ this.select.dispatchEvent(new Event("change", { bubbles: !0 })), this.changeListen(!0);
1294
+ }
1295
+ createOptgroup(e) {
1296
+ const t = document.createElement("optgroup");
1297
+ 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)
1298
+ for (const s of e.options)
1299
+ t.appendChild(this.createOption(s));
1300
+ return t;
1301
+ }
1302
+ createOption(e) {
1303
+ const t = document.createElement("option");
1304
+ 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((s) => {
1305
+ t.classList.add(s);
1306
+ }), e.data && typeof e.data == "object" && Object.keys(e.data).forEach((s) => {
1307
+ t.setAttribute("data-" + me(s), e.data[s]);
1308
+ }), t;
1309
+ }
1310
+ destroy() {
1311
+ this.changeListen(!1), this.select.removeEventListener("change", this.valueChange), this.observer && (this.observer.disconnect(), this.observer = null), delete this.select.dataset.id, this.showUI();
1312
+ }
1313
+ }
1314
+ class we {
1315
+ id = "";
1316
+ // Primary ID for the select
1317
+ style = "";
1318
+ // Style attribute from the select element
1319
+ class = [];
1320
+ // Class attribute from the select element
1321
+ // Dynamic settings
1322
+ isMultiple = !1;
1323
+ isOpen = !1;
1324
+ isFullOpen = !1;
1325
+ intervalMove = null;
1326
+ // Fields set from constructor
1327
+ disabled;
1328
+ alwaysOpen;
1329
+ showSearch;
1330
+ focusSearch;
1331
+ ariaLabel;
1332
+ searchPlaceholder;
1333
+ searchText;
1334
+ searchingText;
1335
+ searchHighlight;
1336
+ closeOnSelect;
1337
+ contentLocation;
1338
+ contentPosition;
1339
+ openPosition;
1340
+ placeholderText;
1341
+ allowDeselect;
1342
+ hideSelected;
1343
+ keepOrder;
1344
+ showOptionTooltips;
1345
+ minSelected;
1346
+ maxSelected;
1347
+ timeoutDelay;
1348
+ maxValuesShown;
1349
+ maxValuesMessage;
1350
+ addableText;
1351
+ constructor(e) {
1352
+ e || (e = {}), this.id = "ss-" + Y(), this.style = e.style || "", this.class = e.class || [], this.disabled = e.disabled !== void 0 ? e.disabled : !1, this.alwaysOpen = e.alwaysOpen !== void 0 ? e.alwaysOpen : !1, this.showSearch = e.showSearch !== void 0 ? e.showSearch : !0, this.focusSearch = e.focusSearch !== void 0 ? e.focusSearch : !0, this.ariaLabel = e.ariaLabel || "Combobox", this.searchPlaceholder = e.searchPlaceholder || "Search", this.searchText = e.searchText || "No Results", this.searchingText = e.searchingText || "Searching...", this.searchHighlight = e.searchHighlight !== void 0 ? e.searchHighlight : !1, this.closeOnSelect = e.closeOnSelect !== void 0 ? e.closeOnSelect : !0, this.contentLocation = e.contentLocation || document.body, this.contentPosition = e.contentPosition || "absolute", this.openPosition = e.openPosition || "auto", this.placeholderText = e.placeholderText !== void 0 ? e.placeholderText : "Select Value", this.allowDeselect = e.allowDeselect !== void 0 ? e.allowDeselect : !1, this.hideSelected = e.hideSelected !== void 0 ? e.hideSelected : !1, this.keepOrder = e.keepOrder !== void 0 ? e.keepOrder : !1, this.showOptionTooltips = e.showOptionTooltips !== void 0 ? e.showOptionTooltips : !1, 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}';
1353
+ }
1354
+ }
1355
+ let Oe = class {
1356
+ selectEl;
1357
+ // Classes
1358
+ settings;
1359
+ cssClasses;
1360
+ select;
1361
+ store;
1362
+ render;
1363
+ // Timeout tracking for cleanup
1364
+ openTimeout = null;
1365
+ closeTimeout = null;
1366
+ // Events
1367
+ events = {
1368
+ search: void 0,
1369
+ searchFilter: (e, t) => e.text.toLowerCase().indexOf(t.toLowerCase()) !== -1,
1370
+ addable: void 0,
1371
+ beforeChange: void 0,
1372
+ afterChange: void 0,
1373
+ beforeOpen: void 0,
1374
+ afterOpen: void 0,
1375
+ beforeClose: void 0,
1376
+ afterClose: void 0
1377
+ };
1378
+ constructor(e) {
1379
+ if (this.selectEl = typeof e.select == "string" ? document.querySelector(e.select) : e.select, !this.selectEl) {
1380
+ e.events && e.events.error && e.events.error(new Error("Could not find select element"));
1381
+ return;
1382
+ }
1383
+ if (this.selectEl.tagName !== "SELECT") {
1384
+ e.events && e.events.error && e.events.error(new Error("Element isnt of type select"));
1385
+ return;
1386
+ }
1387
+ this.selectEl.dataset.ssid && this.destroy(), this.settings = new we(e.settings), this.cssClasses = new fe(e.cssClasses);
1388
+ const t = ["beforeOpen", "afterOpen", "beforeClose", "afterClose"];
1389
+ for (const a in e.events)
1390
+ e.events.hasOwnProperty(a) && (t.indexOf(a) !== -1 ? this.events[a] = N(e.events[a], 100) : this.events[a] = e.events[a]);
1391
+ 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 ve(this.selectEl), this.select.updateSelect(this.settings.id, this.settings.style, this.settings.class), this.select.hideUI(), this.select.onValueChange = (a) => {
1392
+ this.setSelected(a.map((c) => c.id));
1393
+ }, this.select.onClassChange = (a) => {
1394
+ this.settings.class = a, this.render.updateClassStyles();
1395
+ }, this.select.onDisabledChange = (a) => {
1396
+ a ? this.disable() : this.enable();
1397
+ }, this.select.onOptionsChange = (a) => {
1398
+ this.setData(a);
1399
+ };
1400
+ const s = e.data ? e.data : this.select.getData();
1401
+ this.store = new ge(this.settings.isMultiple ? "multiple" : "single", s), e.data && this.select.updateOptions(this.store.getData());
1402
+ const i = {
1403
+ open: this.open.bind(this),
1404
+ close: this.close.bind(this),
1405
+ addable: this.events.addable ? this.events.addable : void 0,
1406
+ setSelected: this.setSelected.bind(this),
1407
+ addOption: this.addOption.bind(this),
1408
+ search: this.search.bind(this),
1409
+ beforeChange: this.events.beforeChange,
1410
+ afterChange: this.events.afterChange
1411
+ };
1412
+ this.render = new be(this.settings, this.cssClasses, this.store, i), this.render.renderValues(), this.render.renderOptions(this.store.getData());
1413
+ const l = this.selectEl.getAttribute("aria-label"), r = this.selectEl.getAttribute("aria-labelledby");
1414
+ l ? this.render.main.main.setAttribute("aria-label", l) : r && this.render.main.main.setAttribute("aria-labelledby", r), this.selectEl.parentNode && this.selectEl.parentNode.insertBefore(this.render.main.main, this.selectEl.nextSibling), window.addEventListener("resize", this.windowResize, !1), this.settings.openPosition === "auto" && window.addEventListener("scroll", this.windowScroll, !1), document.addEventListener("visibilitychange", this.windowVisibilityChange), this.settings.disabled && this.disable(), this.settings.alwaysOpen && this.open(), this.selectEl.slim = this;
1415
+ }
1416
+ // Set to enabled and remove disabled classes
1417
+ enable() {
1418
+ this.settings.disabled = !1, this.select.enable(), this.render.enable();
1419
+ }
1420
+ // Set to disabled and add disabled classes
1421
+ disable() {
1422
+ this.settings.disabled = !0, this.select.disable(), this.render.disable();
1423
+ }
1424
+ getData() {
1425
+ return this.store.getData();
1426
+ }
1427
+ setData(e) {
1428
+ const t = this.store.getSelected(), s = this.store.validateDataArray(e);
1429
+ if (s) {
1430
+ this.events.error && this.events.error(s);
1431
+ return;
1432
+ }
1433
+ this.store.setData(e);
1434
+ const i = this.store.getData();
1435
+ this.select.updateOptions(i), this.render.renderValues(), this.render.renderOptions(i), this.events.afterChange && !U(t, this.store.getSelected()) && this.events.afterChange(this.store.getSelectedOptions());
1436
+ }
1437
+ getSelected() {
1438
+ let e = this.store.getSelectedOptions();
1439
+ return this.settings.keepOrder && (e = this.store.selectedOrderOptions(e)), e.map((t) => t.value);
1440
+ }
1441
+ // Will take in a string or array of strings and set the selected by either the id or value
1442
+ setSelected(e, t = !0) {
1443
+ const s = this.store.getSelected(), i = this.store.getDataOptions();
1444
+ e = Array.isArray(e) ? e : [e];
1445
+ const l = [];
1446
+ for (const a of e) {
1447
+ if (i.find((c) => c.id == a)) {
1448
+ l.push(a);
1449
+ continue;
1450
+ }
1451
+ for (const c of i.filter((h) => h.value == a))
1452
+ l.push(c.id);
1453
+ }
1454
+ this.store.setSelectedBy("id", l);
1455
+ const r = this.store.getData();
1456
+ this.select.updateOptions(r), this.render.renderValues(), this.render.content.search.input.value !== "" ? this.search(this.render.content.search.input.value) : this.render.renderOptions(r), t && this.events.afterChange && !U(s, this.store.getSelected()) && this.events.afterChange(this.store.getSelectedOptions());
1457
+ }
1458
+ addOption(e) {
1459
+ const t = this.store.getSelected();
1460
+ this.store.getDataOptions().some((i) => i.value === (e.value ?? e.text)) || this.store.addOption(e);
1461
+ const s = this.store.getData();
1462
+ this.select.updateOptions(s), this.render.renderValues(), this.render.renderOptions(s), this.events.afterChange && !U(t, this.store.getSelected()) && this.events.afterChange(this.store.getSelectedOptions());
1463
+ }
1464
+ open() {
1465
+ this.settings.disabled || this.settings.isOpen || (this.events.beforeOpen && this.events.beforeOpen(), this.render.open(), this.settings.showSearch && this.settings.focusSearch && this.render.searchFocus(), this.settings.isOpen = !0, this.openTimeout = setTimeout(() => {
1466
+ this.events.afterOpen && this.events.afterOpen(), this.settings.isOpen && (this.settings.isFullOpen = !0), document.addEventListener("click", this.documentClick);
1467
+ }, this.settings.timeoutDelay), this.settings.contentPosition === "absolute" && (this.settings.intervalMove && clearInterval(this.settings.intervalMove), this.settings.intervalMove = setInterval(this.render.moveContent.bind(this.render), 500)));
1468
+ }
1469
+ close(e = null) {
1470
+ !this.settings.isOpen || this.settings.alwaysOpen || (this.events.beforeClose && this.events.beforeClose(), this.render.close(), this.render.clearSearch(), this.render.mainFocus(e), this.settings.isOpen = !1, this.settings.isFullOpen = !1, this.closeTimeout = setTimeout(() => {
1471
+ this.events.afterClose && this.events.afterClose(), document.removeEventListener("click", this.documentClick);
1472
+ }, this.settings.timeoutDelay), this.settings.intervalMove && clearInterval(this.settings.intervalMove));
1473
+ }
1474
+ // Take in string value and search current options
1475
+ search(e) {
1476
+ if (this.render.content.search.input.value !== e && (this.render.content.search.input.value = e), !this.events.search) {
1477
+ const s = e === "" ? this.store.getData() : this.store.search(e, this.events.searchFilter);
1478
+ this.render.renderOptions(s);
1479
+ return;
1480
+ }
1481
+ this.render.renderSearching();
1482
+ const t = this.events.search(e, this.store.getSelectedOptions());
1483
+ if (t instanceof Promise) {
1484
+ t.then((s) => {
1485
+ this.store.setData(s, !0), this.select.updateOptions(this.store.getData()), this.render.renderOptions(this.store.getData());
1486
+ }).catch((s) => {
1487
+ this.render.renderError(typeof s == "string" ? s : s.message);
1488
+ });
1489
+ return;
1490
+ } else Array.isArray(t) ? (this.store.setData(t, !0), this.select.updateOptions(this.store.getData()), this.render.renderOptions(this.store.getData())) : this.render.renderError("Search event must return a promise or an array of data");
1491
+ }
1492
+ destroy() {
1493
+ this.openTimeout && (clearTimeout(this.openTimeout), this.openTimeout = null), this.closeTimeout && (clearTimeout(this.closeTimeout), this.closeTimeout = null), this.settings.intervalMove && (clearInterval(this.settings.intervalMove), this.settings.intervalMove = null), document.removeEventListener("click", this.documentClick), window.removeEventListener("resize", this.windowResize, !1), this.settings.openPosition === "auto" && window.removeEventListener("scroll", this.windowScroll, !1), document.removeEventListener("visibilitychange", this.windowVisibilityChange), this.store.setData([]), this.render.destroy(), this.select.destroy();
1494
+ }
1495
+ windowResize = N(() => {
1496
+ !this.settings.isOpen && !this.settings.isFullOpen || this.render.moveContent();
1497
+ });
1498
+ // Event listener for window scrolling
1499
+ windowScroll = N(() => {
1500
+ !this.settings.isOpen && !this.settings.isFullOpen || this.render.moveContent();
1501
+ });
1502
+ // Event listener for document click
1503
+ documentClick = (e) => {
1504
+ this.settings.isOpen && e.target && !pe(e.target, this.settings.id) && this.close(e.type);
1505
+ };
1506
+ // Event Listener for window visibility change
1507
+ windowVisibilityChange = () => {
1508
+ document.hidden && this.close();
1509
+ };
1510
+ };
1511
+ const Se = re(
1512
+ ({ data: p, settings: e, events: t, cssClasses: s, value: i, onChange: l, children: r, multiple: a }, c) => {
1513
+ const h = F(null), o = F(null), d = F(!0);
1514
+ return oe(c, () => ({
1515
+ slimSelect: o.current
1516
+ })), j(() => {
1517
+ if (!h.current) return;
1518
+ const m = {
1519
+ select: h.current
1520
+ };
1521
+ p && (m.data = p), e && (m.settings = e), s && (m.cssClasses = s);
1522
+ const f = t?.afterChange;
1523
+ return m.events = {
1524
+ ...t,
1525
+ afterChange: (O) => {
1526
+ const C = a ? O.map((S) => S.value) : O[0]?.value ?? "";
1527
+ l && l(C), f && f(O);
1528
+ }
1529
+ }, o.current = new Oe(m), i !== void 0 && o.current.setSelected(i, !1), () => {
1530
+ o.current && (o.current.destroy(), o.current = null);
1531
+ };
1532
+ }, []), j(() => {
1533
+ if (d.current) {
1534
+ d.current = !1;
1535
+ return;
1536
+ }
1537
+ o.current && i !== void 0 && o.current.setSelected(i, !1);
1538
+ }, [i]), j(() => {
1539
+ o.current && p && !d.current && o.current.setData(p);
1540
+ }, [p]), /* @__PURE__ */ ue.jsx("select", { ref: h, multiple: a, children: r });
1541
+ }
1542
+ );
1543
+ Se.displayName = "SlimSelect";
1544
+ export {
1545
+ y as Optgroup,
1546
+ b as Option,
1547
+ we as Settings,
1548
+ Se as default
1549
+ };