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