inertia-bootstrap-forms 2.1.20 → 3.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (59) hide show
  1. package/README.fa.md +468 -0
  2. package/README.md +322 -714
  3. package/dist/inertia-bootstrap-forms.cjs.js +1 -0
  4. package/dist/inertia-bootstrap-forms.es.js +3524 -30
  5. package/index.d.ts +143 -507
  6. package/package.json +89 -70
  7. package/src/AmountInput.vue +81 -76
  8. package/src/CaptchaInput.vue +87 -88
  9. package/src/CheckboxButtonInput.vue +56 -69
  10. package/src/CheckboxInput.vue +60 -79
  11. package/src/CheckboxToggle.vue +53 -136
  12. package/src/ChipsInput.vue +157 -0
  13. package/src/ComboboxInput.vue +556 -0
  14. package/src/DropzoneInput.vue +125 -103
  15. package/src/EditorInput.vue +47 -106
  16. package/src/EmailInput.vue +16 -15
  17. package/src/FileInput.vue +189 -179
  18. package/src/FormAdornInput.vue +75 -0
  19. package/src/FormContainer.vue +288 -251
  20. package/src/FormField.vue +59 -0
  21. package/src/FormLabel.vue +27 -27
  22. package/src/GroupControl.vue +55 -53
  23. package/src/LocationInput.vue +79 -72
  24. package/src/MobileInput.vue +21 -13
  25. package/src/MultiQuantityInput.vue +109 -181
  26. package/src/OTPInput.vue +144 -76
  27. package/src/PasswordInput.vue +151 -17
  28. package/src/PersianDatePickerInput.vue +63 -166
  29. package/src/QuantityInput.vue +100 -119
  30. package/src/RangeInput.vue +96 -0
  31. package/src/SimpleUploader.vue +8 -143
  32. package/src/StarRatingInput.vue +114 -138
  33. package/src/SubmitButton.vue +39 -24
  34. package/src/SwitchInput.vue +58 -83
  35. package/src/TelInput.vue +86 -120
  36. package/src/TextAreaInput.vue +29 -33
  37. package/src/TextInput.vue +42 -51
  38. package/src/UppyInput.vue +237 -324
  39. package/src/composables/useBsInstance.js +66 -0
  40. package/src/composables/useChoice.js +34 -0
  41. package/src/composables/useDisposables.js +59 -0
  42. package/src/composables/useField.js +121 -0
  43. package/src/composables/useFormApi.js +12 -0
  44. package/src/i18n.js +120 -0
  45. package/src/index.js +123 -42
  46. package/src/utils/bootstrap.js +48 -0
  47. package/src/utils/digits.js +21 -0
  48. package/src/utils/http.js +15 -0
  49. package/dist/choices-KiM-I_0P.js +0 -2955
  50. package/dist/dropdown-yh2aQrbw-XuCU1v1F.js +0 -1543
  51. package/dist/index-BRtKc2RA.js +0 -604
  52. package/dist/index-_x4UqcXz.js +0 -4938
  53. package/dist/inertia-bootstrap-forms.umd.js +0 -19
  54. package/dist/range-slider-pips-DTDOg3Q9.js +0 -3506
  55. package/dist/style.css +0 -1
  56. package/src/css/from-select.scss +0 -384
  57. package/src/css/loader.gif +0 -0
  58. package/src/css/location.scss +0 -44
  59. package/src/css/simple-upload.scss +0 -54
@@ -1,2955 +0,0 @@
1
- /*! choices.js v11.1.0 | © 2025 Josh Johnson | https://github.com/jshjohnson/Choices#readme */
2
- var oe = function(i, e) {
3
- return oe = Object.setPrototypeOf || {
4
- __proto__: []
5
- } instanceof Array && function(t, s) {
6
- t.__proto__ = s;
7
- } || function(t, s) {
8
- for (var n in s) Object.prototype.hasOwnProperty.call(s, n) && (t[n] = s[n]);
9
- }, oe(i, e);
10
- };
11
- function Pe(i, e) {
12
- if (typeof e != "function" && e !== null) throw new TypeError("Class extends value " + String(e) + " is not a constructor or null");
13
- oe(i, e);
14
- function t() {
15
- this.constructor = i;
16
- }
17
- i.prototype = e === null ? Object.create(e) : (t.prototype = e.prototype, new t());
18
- }
19
- var A = function() {
20
- return A = Object.assign || function(e) {
21
- for (var t, s = 1, n = arguments.length; s < n; s++) {
22
- t = arguments[s];
23
- for (var r in t) Object.prototype.hasOwnProperty.call(t, r) && (e[r] = t[r]);
24
- }
25
- return e;
26
- }, A.apply(this, arguments);
27
- };
28
- function ze(i, e, t) {
29
- for (var s = 0, n = e.length, r; s < n; s++)
30
- (r || !(s in e)) && (r || (r = Array.prototype.slice.call(e, 0, s)), r[s] = e[s]);
31
- return i.concat(r || Array.prototype.slice.call(e));
32
- }
33
- var b = {
34
- ADD_CHOICE: "ADD_CHOICE",
35
- REMOVE_CHOICE: "REMOVE_CHOICE",
36
- FILTER_CHOICES: "FILTER_CHOICES",
37
- ACTIVATE_CHOICES: "ACTIVATE_CHOICES",
38
- CLEAR_CHOICES: "CLEAR_CHOICES",
39
- ADD_GROUP: "ADD_GROUP",
40
- ADD_ITEM: "ADD_ITEM",
41
- REMOVE_ITEM: "REMOVE_ITEM",
42
- HIGHLIGHT_ITEM: "HIGHLIGHT_ITEM"
43
- }, w = {
44
- showDropdown: "showDropdown",
45
- hideDropdown: "hideDropdown",
46
- change: "change",
47
- choice: "choice",
48
- search: "search",
49
- addItem: "addItem",
50
- removeItem: "removeItem",
51
- highlightItem: "highlightItem",
52
- highlightChoice: "highlightChoice",
53
- unhighlightItem: "unhighlightItem"
54
- }, C = {
55
- TAB_KEY: 9,
56
- SHIFT_KEY: 16,
57
- BACK_KEY: 46,
58
- DELETE_KEY: 8,
59
- ENTER_KEY: 13,
60
- A_KEY: 65,
61
- ESC_KEY: 27,
62
- UP_KEY: 38,
63
- DOWN_KEY: 40,
64
- PAGE_UP_KEY: 33,
65
- PAGE_DOWN_KEY: 34
66
- }, Xe = ["fuseOptions", "classNames"], R = {
67
- Text: "text",
68
- SelectOne: "select-one",
69
- SelectMultiple: "select-multiple"
70
- }, _e = function(i) {
71
- return {
72
- type: b.ADD_CHOICE,
73
- choice: i
74
- };
75
- }, Je = function(i) {
76
- return {
77
- type: b.REMOVE_CHOICE,
78
- choice: i
79
- };
80
- }, Qe = function(i) {
81
- return {
82
- type: b.FILTER_CHOICES,
83
- results: i
84
- };
85
- }, Ze = function(i) {
86
- return {
87
- type: b.ACTIVATE_CHOICES,
88
- active: i
89
- };
90
- }, et = function(i) {
91
- return {
92
- type: b.ADD_GROUP,
93
- group: i
94
- };
95
- }, ge = function(i) {
96
- return {
97
- type: b.ADD_ITEM,
98
- item: i
99
- };
100
- }, ye = function(i) {
101
- return {
102
- type: b.REMOVE_ITEM,
103
- item: i
104
- };
105
- }, X = function(i, e) {
106
- return {
107
- type: b.HIGHLIGHT_ITEM,
108
- item: i,
109
- highlighted: e
110
- };
111
- }, tt = function(i, e) {
112
- return Math.floor(Math.random() * (e - i) + i);
113
- }, be = function(i) {
114
- return Array.from({ length: i }, function() {
115
- return tt(0, 36).toString(36);
116
- }).join("");
117
- }, it = function(i, e) {
118
- var t = i.id || i.name && "".concat(i.name, "-").concat(be(2)) || be(4);
119
- return t = t.replace(/(:|\.|\[|\]|,)/g, ""), t = "".concat(e, "-").concat(t), t;
120
- }, st = function(i, e, t) {
121
- t === void 0 && (t = 1);
122
- for (var s = "".concat(t > 0 ? "next" : "previous", "ElementSibling"), n = i[s]; n; ) {
123
- if (n.matches(e))
124
- return n;
125
- n = n[s];
126
- }
127
- return null;
128
- }, nt = function(i, e, t) {
129
- t === void 0 && (t = 1);
130
- var s;
131
- return t > 0 ? s = e.scrollTop + e.offsetHeight >= i.offsetTop + i.offsetHeight : s = i.offsetTop >= e.scrollTop, s;
132
- }, Z = function(i) {
133
- if (typeof i != "string") {
134
- if (i == null)
135
- return "";
136
- if (typeof i == "object") {
137
- if ("raw" in i)
138
- return Z(i.raw);
139
- if ("trusted" in i)
140
- return i.trusted;
141
- }
142
- return i;
143
- }
144
- return i.replace(/&/g, "&amp;").replace(/>/g, "&gt;").replace(/</g, "&lt;").replace(/'/g, "&#039;").replace(/"/g, "&quot;");
145
- }, rt = function() {
146
- var i = document.createElement("div");
147
- return function(e) {
148
- i.innerHTML = e.trim();
149
- for (var t = i.children[0]; i.firstChild; )
150
- i.removeChild(i.firstChild);
151
- return t;
152
- };
153
- }(), q = function(i, e) {
154
- return typeof i == "function" ? i(Z(e), e) : i;
155
- }, Ee = function(i) {
156
- return typeof i == "function" ? i() : i;
157
- }, V = function(i) {
158
- if (typeof i == "string")
159
- return i;
160
- if (typeof i == "object") {
161
- if ("trusted" in i)
162
- return i.trusted;
163
- if ("raw" in i)
164
- return i.raw;
165
- }
166
- return "";
167
- }, Fe = function(i) {
168
- if (typeof i == "string")
169
- return i;
170
- if (typeof i == "object") {
171
- if ("escaped" in i)
172
- return i.escaped;
173
- if ("trusted" in i)
174
- return i.trusted;
175
- }
176
- return "";
177
- }, fe = function(i, e) {
178
- return i ? Fe(e) : Z(e);
179
- }, N = function(i, e, t) {
180
- i.innerHTML = fe(e, t);
181
- }, ot = function(i, e) {
182
- var t = i.value, s = i.label, n = s === void 0 ? t : s, r = e.value, o = e.label, a = o === void 0 ? r : o;
183
- return V(n).localeCompare(V(a), [], {
184
- sensitivity: "base",
185
- ignorePunctuation: !0,
186
- numeric: !0
187
- });
188
- }, at = function(i, e) {
189
- return i.rank - e.rank;
190
- }, lt = function(i, e, t) {
191
- t === void 0 && (t = null);
192
- var s = new CustomEvent(e, {
193
- detail: t,
194
- bubbles: !0,
195
- cancelable: !0
196
- });
197
- return i.dispatchEvent(s);
198
- }, ct = function(i, e) {
199
- var t = Object.keys(i).sort(), s = Object.keys(e).sort();
200
- return t.filter(function(n) {
201
- return s.indexOf(n) < 0;
202
- });
203
- }, ee = function(i) {
204
- return Array.isArray(i) ? i : [i];
205
- }, U = function(i) {
206
- return i && Array.isArray(i) ? i.map(function(e) {
207
- return ".".concat(e);
208
- }).join("") : ".".concat(i);
209
- }, _ = function(i, e) {
210
- var t;
211
- (t = i.classList).add.apply(t, ee(e));
212
- }, L = function(i, e) {
213
- var t;
214
- (t = i.classList).remove.apply(t, ee(e));
215
- }, ht = function(i) {
216
- if (typeof i < "u")
217
- try {
218
- return JSON.parse(i);
219
- } catch {
220
- return i;
221
- }
222
- return {};
223
- }, ut = function(i, e, t) {
224
- var s = i.itemEl;
225
- s && (L(s, t), _(s, e));
226
- }, dt = (
227
- /** @class */
228
- function() {
229
- function i(e) {
230
- var t = e.element, s = e.type, n = e.classNames;
231
- this.element = t, this.classNames = n, this.type = s, this.isActive = !1;
232
- }
233
- return i.prototype.show = function() {
234
- return _(this.element, this.classNames.activeState), this.element.setAttribute("aria-expanded", "true"), this.isActive = !0, this;
235
- }, i.prototype.hide = function() {
236
- return L(this.element, this.classNames.activeState), this.element.setAttribute("aria-expanded", "false"), this.isActive = !1, this;
237
- }, i;
238
- }()
239
- ), Ce = (
240
- /** @class */
241
- function() {
242
- function i(e) {
243
- var t = e.element, s = e.type, n = e.classNames, r = e.position;
244
- this.element = t, this.classNames = n, this.type = s, this.position = r, this.isOpen = !1, this.isFlipped = !1, this.isDisabled = !1, this.isLoading = !1;
245
- }
246
- return i.prototype.shouldFlip = function(e, t) {
247
- var s = !1;
248
- return this.position === "auto" ? s = this.element.getBoundingClientRect().top - t >= 0 && !window.matchMedia("(min-height: ".concat(e + 1, "px)")).matches : this.position === "top" && (s = !0), s;
249
- }, i.prototype.setActiveDescendant = function(e) {
250
- this.element.setAttribute("aria-activedescendant", e);
251
- }, i.prototype.removeActiveDescendant = function() {
252
- this.element.removeAttribute("aria-activedescendant");
253
- }, i.prototype.open = function(e, t) {
254
- _(this.element, this.classNames.openState), this.element.setAttribute("aria-expanded", "true"), this.isOpen = !0, this.shouldFlip(e, t) && (_(this.element, this.classNames.flippedState), this.isFlipped = !0);
255
- }, i.prototype.close = function() {
256
- L(this.element, this.classNames.openState), this.element.setAttribute("aria-expanded", "false"), this.removeActiveDescendant(), this.isOpen = !1, this.isFlipped && (L(this.element, this.classNames.flippedState), this.isFlipped = !1);
257
- }, i.prototype.addFocusState = function() {
258
- _(this.element, this.classNames.focusState);
259
- }, i.prototype.removeFocusState = function() {
260
- L(this.element, this.classNames.focusState);
261
- }, i.prototype.enable = function() {
262
- L(this.element, this.classNames.disabledState), this.element.removeAttribute("aria-disabled"), this.type === R.SelectOne && this.element.setAttribute("tabindex", "0"), this.isDisabled = !1;
263
- }, i.prototype.disable = function() {
264
- _(this.element, this.classNames.disabledState), this.element.setAttribute("aria-disabled", "true"), this.type === R.SelectOne && this.element.setAttribute("tabindex", "-1"), this.isDisabled = !0;
265
- }, i.prototype.wrap = function(e) {
266
- var t = this.element, s = e.parentNode;
267
- s && (e.nextSibling ? s.insertBefore(t, e.nextSibling) : s.appendChild(t)), t.appendChild(e);
268
- }, i.prototype.unwrap = function(e) {
269
- var t = this.element, s = t.parentNode;
270
- s && (s.insertBefore(e, t), s.removeChild(t));
271
- }, i.prototype.addLoadingState = function() {
272
- _(this.element, this.classNames.loadingState), this.element.setAttribute("aria-busy", "true"), this.isLoading = !0;
273
- }, i.prototype.removeLoadingState = function() {
274
- L(this.element, this.classNames.loadingState), this.element.removeAttribute("aria-busy"), this.isLoading = !1;
275
- }, i;
276
- }()
277
- ), ft = (
278
- /** @class */
279
- function() {
280
- function i(e) {
281
- var t = e.element, s = e.type, n = e.classNames, r = e.preventPaste;
282
- this.element = t, this.type = s, this.classNames = n, this.preventPaste = r, this.isFocussed = this.element.isEqualNode(document.activeElement), this.isDisabled = t.disabled, this._onPaste = this._onPaste.bind(this), this._onInput = this._onInput.bind(this), this._onFocus = this._onFocus.bind(this), this._onBlur = this._onBlur.bind(this);
283
- }
284
- return Object.defineProperty(i.prototype, "placeholder", {
285
- set: function(e) {
286
- this.element.placeholder = e;
287
- },
288
- enumerable: !1,
289
- configurable: !0
290
- }), Object.defineProperty(i.prototype, "value", {
291
- get: function() {
292
- return this.element.value;
293
- },
294
- set: function(e) {
295
- this.element.value = e;
296
- },
297
- enumerable: !1,
298
- configurable: !0
299
- }), i.prototype.addEventListeners = function() {
300
- var e = this.element;
301
- e.addEventListener("paste", this._onPaste), e.addEventListener("input", this._onInput, {
302
- passive: !0
303
- }), e.addEventListener("focus", this._onFocus, {
304
- passive: !0
305
- }), e.addEventListener("blur", this._onBlur, {
306
- passive: !0
307
- });
308
- }, i.prototype.removeEventListeners = function() {
309
- var e = this.element;
310
- e.removeEventListener("input", this._onInput), e.removeEventListener("paste", this._onPaste), e.removeEventListener("focus", this._onFocus), e.removeEventListener("blur", this._onBlur);
311
- }, i.prototype.enable = function() {
312
- var e = this.element;
313
- e.removeAttribute("disabled"), this.isDisabled = !1;
314
- }, i.prototype.disable = function() {
315
- var e = this.element;
316
- e.setAttribute("disabled", ""), this.isDisabled = !0;
317
- }, i.prototype.focus = function() {
318
- this.isFocussed || this.element.focus();
319
- }, i.prototype.blur = function() {
320
- this.isFocussed && this.element.blur();
321
- }, i.prototype.clear = function(e) {
322
- return e === void 0 && (e = !0), this.element.value = "", e && this.setWidth(), this;
323
- }, i.prototype.setWidth = function() {
324
- var e = this.element;
325
- e.style.minWidth = "".concat(e.placeholder.length + 1, "ch"), e.style.width = "".concat(e.value.length + 1, "ch");
326
- }, i.prototype.setActiveDescendant = function(e) {
327
- this.element.setAttribute("aria-activedescendant", e);
328
- }, i.prototype.removeActiveDescendant = function() {
329
- this.element.removeAttribute("aria-activedescendant");
330
- }, i.prototype._onInput = function() {
331
- this.type !== R.SelectOne && this.setWidth();
332
- }, i.prototype._onPaste = function(e) {
333
- this.preventPaste && e.preventDefault();
334
- }, i.prototype._onFocus = function() {
335
- this.isFocussed = !0;
336
- }, i.prototype._onBlur = function() {
337
- this.isFocussed = !1;
338
- }, i;
339
- }()
340
- ), pt = 4, Se = (
341
- /** @class */
342
- function() {
343
- function i(e) {
344
- var t = e.element;
345
- this.element = t, this.scrollPos = this.element.scrollTop, this.height = this.element.offsetHeight;
346
- }
347
- return i.prototype.prepend = function(e) {
348
- var t = this.element.firstElementChild;
349
- t ? this.element.insertBefore(e, t) : this.element.append(e);
350
- }, i.prototype.scrollToTop = function() {
351
- this.element.scrollTop = 0;
352
- }, i.prototype.scrollToChildElement = function(e, t) {
353
- var s = this;
354
- if (e) {
355
- var n = this.element.offsetHeight, r = this.element.scrollTop + n, o = e.offsetHeight, a = e.offsetTop + o, l = t > 0 ? this.element.scrollTop + a - r : e.offsetTop;
356
- requestAnimationFrame(function() {
357
- s._animateScroll(l, t);
358
- });
359
- }
360
- }, i.prototype._scrollDown = function(e, t, s) {
361
- var n = (s - e) / t, r = n > 1 ? n : 1;
362
- this.element.scrollTop = e + r;
363
- }, i.prototype._scrollUp = function(e, t, s) {
364
- var n = (e - s) / t, r = n > 1 ? n : 1;
365
- this.element.scrollTop = e - r;
366
- }, i.prototype._animateScroll = function(e, t) {
367
- var s = this, n = pt, r = this.element.scrollTop, o = !1;
368
- t > 0 ? (this._scrollDown(r, n, e), r < e && (o = !0)) : (this._scrollUp(r, n, e), r > e && (o = !0)), o && requestAnimationFrame(function() {
369
- s._animateScroll(e, t);
370
- });
371
- }, i;
372
- }()
373
- ), ke = (
374
- /** @class */
375
- function() {
376
- function i(e) {
377
- var t = e.element, s = e.classNames;
378
- this.element = t, this.classNames = s, this.isDisabled = !1;
379
- }
380
- return Object.defineProperty(i.prototype, "isActive", {
381
- get: function() {
382
- return this.element.dataset.choice === "active";
383
- },
384
- enumerable: !1,
385
- configurable: !0
386
- }), Object.defineProperty(i.prototype, "dir", {
387
- get: function() {
388
- return this.element.dir;
389
- },
390
- enumerable: !1,
391
- configurable: !0
392
- }), Object.defineProperty(i.prototype, "value", {
393
- get: function() {
394
- return this.element.value;
395
- },
396
- set: function(e) {
397
- this.element.setAttribute("value", e), this.element.value = e;
398
- },
399
- enumerable: !1,
400
- configurable: !0
401
- }), i.prototype.conceal = function() {
402
- var e = this.element;
403
- _(e, this.classNames.input), e.hidden = !0, e.tabIndex = -1;
404
- var t = e.getAttribute("style");
405
- t && e.setAttribute("data-choice-orig-style", t), e.setAttribute("data-choice", "active");
406
- }, i.prototype.reveal = function() {
407
- var e = this.element;
408
- L(e, this.classNames.input), e.hidden = !1, e.removeAttribute("tabindex");
409
- var t = e.getAttribute("data-choice-orig-style");
410
- t ? (e.removeAttribute("data-choice-orig-style"), e.setAttribute("style", t)) : e.removeAttribute("style"), e.removeAttribute("data-choice");
411
- }, i.prototype.enable = function() {
412
- this.element.removeAttribute("disabled"), this.element.disabled = !1, this.isDisabled = !1;
413
- }, i.prototype.disable = function() {
414
- this.element.setAttribute("disabled", ""), this.element.disabled = !0, this.isDisabled = !0;
415
- }, i.prototype.triggerEvent = function(e, t) {
416
- lt(this.element, e, t || {});
417
- }, i;
418
- }()
419
- ), mt = (
420
- /** @class */
421
- function(i) {
422
- Pe(e, i);
423
- function e() {
424
- return i !== null && i.apply(this, arguments) || this;
425
- }
426
- return e;
427
- }(ke)
428
- ), Y = function(i, e) {
429
- return e === void 0 && (e = !0), typeof i > "u" ? e : !!i;
430
- }, Re = function(i) {
431
- if (typeof i == "string" && (i = i.split(" ").filter(function(e) {
432
- return e.length;
433
- })), Array.isArray(i) && i.length)
434
- return i;
435
- }, M = function(i, e, t) {
436
- if (t === void 0 && (t = !0), typeof i == "string") {
437
- var s = Z(i), n = t || s === i ? i : { escaped: s, raw: i }, r = M({
438
- value: i,
439
- label: n,
440
- selected: !0
441
- }, !1);
442
- return r;
443
- }
444
- var o = i;
445
- if ("choices" in o) {
446
- if (!e)
447
- throw new TypeError("optGroup is not allowed");
448
- var a = o, l = a.choices.map(function(f) {
449
- return M(f, !1);
450
- }), h = {
451
- id: 0,
452
- // actual ID will be assigned during _addGroup
453
- label: V(a.label) || a.value,
454
- active: !!l.length,
455
- disabled: !!a.disabled,
456
- choices: l
457
- };
458
- return h;
459
- }
460
- var c = o, u = {
461
- id: 0,
462
- // actual ID will be assigned during _addChoice
463
- group: null,
464
- // actual group will be assigned during _addGroup but before _addChoice
465
- score: 0,
466
- // used in search
467
- rank: 0,
468
- // used in search, stable sort order
469
- value: c.value,
470
- label: c.label || c.value,
471
- active: Y(c.active),
472
- selected: Y(c.selected, !1),
473
- disabled: Y(c.disabled, !1),
474
- placeholder: Y(c.placeholder, !1),
475
- highlighted: !1,
476
- labelClass: Re(c.labelClass),
477
- labelDescription: c.labelDescription,
478
- customProperties: c.customProperties
479
- };
480
- return u;
481
- }, vt = function(i) {
482
- return i.tagName === "INPUT";
483
- }, Ke = function(i) {
484
- return i.tagName === "SELECT";
485
- }, _t = function(i) {
486
- return i.tagName === "OPTION";
487
- }, gt = function(i) {
488
- return i.tagName === "OPTGROUP";
489
- }, yt = (
490
- /** @class */
491
- function(i) {
492
- Pe(e, i);
493
- function e(t) {
494
- var s = t.element, n = t.classNames, r = t.template, o = t.extractPlaceholder, a = i.call(this, { element: s, classNames: n }) || this;
495
- return a.template = r, a.extractPlaceholder = o, a;
496
- }
497
- return Object.defineProperty(e.prototype, "placeholderOption", {
498
- get: function() {
499
- return this.element.querySelector('option[value=""]') || // Backward compatibility layer for the non-standard placeholder attribute supported in older versions.
500
- this.element.querySelector("option[placeholder]");
501
- },
502
- enumerable: !1,
503
- configurable: !0
504
- }), e.prototype.addOptions = function(t) {
505
- var s = this, n = document.createDocumentFragment();
506
- t.forEach(function(r) {
507
- var o = r;
508
- if (!o.element) {
509
- var a = s.template(o);
510
- n.appendChild(a), o.element = a;
511
- }
512
- }), this.element.appendChild(n);
513
- }, e.prototype.optionsAsChoices = function() {
514
- var t = this, s = [];
515
- return this.element.querySelectorAll(":scope > option, :scope > optgroup").forEach(function(n) {
516
- _t(n) ? s.push(t._optionToChoice(n)) : gt(n) && s.push(t._optgroupToChoice(n));
517
- }), s;
518
- }, e.prototype._optionToChoice = function(t) {
519
- return !t.hasAttribute("value") && t.hasAttribute("placeholder") && (t.setAttribute("value", ""), t.value = ""), {
520
- id: 0,
521
- group: null,
522
- score: 0,
523
- rank: 0,
524
- value: t.value,
525
- // https://developer.mozilla.org/en-US/docs/Web/HTML/Element/option
526
- // This attribute is text for the label indicating the meaning of the option. If the `label` attribute isn't defined, its value is that of the element text content (ie `innerText`).
527
- label: t.label,
528
- element: t,
529
- active: !0,
530
- // this returns true if nothing is selected on initial load, which will break placeholder support
531
- selected: this.extractPlaceholder ? t.selected : t.hasAttribute("selected"),
532
- disabled: t.disabled,
533
- highlighted: !1,
534
- placeholder: this.extractPlaceholder && (!t.value || t.hasAttribute("placeholder")),
535
- labelClass: typeof t.dataset.labelClass < "u" ? Re(t.dataset.labelClass) : void 0,
536
- labelDescription: typeof t.dataset.labelDescription < "u" ? t.dataset.labelDescription : void 0,
537
- customProperties: ht(t.dataset.customProperties)
538
- };
539
- }, e.prototype._optgroupToChoice = function(t) {
540
- var s = this, n = t.querySelectorAll("option"), r = Array.from(n).map(function(o) {
541
- return s._optionToChoice(o);
542
- });
543
- return {
544
- id: 0,
545
- label: t.label || "",
546
- element: t,
547
- active: !!r.length,
548
- disabled: t.disabled,
549
- choices: r
550
- };
551
- }, e;
552
- }(ke)
553
- ), bt = {
554
- containerOuter: ["choices"],
555
- containerInner: ["choices__inner"],
556
- input: ["choices__input"],
557
- inputCloned: ["choices__input--cloned"],
558
- list: ["choices__list"],
559
- listItems: ["choices__list--multiple"],
560
- listSingle: ["choices__list--single"],
561
- listDropdown: ["choices__list--dropdown"],
562
- item: ["choices__item"],
563
- itemSelectable: ["choices__item--selectable"],
564
- itemDisabled: ["choices__item--disabled"],
565
- itemChoice: ["choices__item--choice"],
566
- description: ["choices__description"],
567
- placeholder: ["choices__placeholder"],
568
- group: ["choices__group"],
569
- groupHeading: ["choices__heading"],
570
- button: ["choices__button"],
571
- activeState: ["is-active"],
572
- focusState: ["is-focused"],
573
- openState: ["is-open"],
574
- disabledState: ["is-disabled"],
575
- highlightedState: ["is-highlighted"],
576
- selectedState: ["is-selected"],
577
- flippedState: ["is-flipped"],
578
- loadingState: ["is-loading"],
579
- notice: ["choices__notice"],
580
- addChoice: ["choices__item--selectable", "add-choice"],
581
- noResults: ["has-no-results"],
582
- noChoices: ["has-no-choices"]
583
- }, Ie = {
584
- items: [],
585
- choices: [],
586
- silent: !1,
587
- renderChoiceLimit: -1,
588
- maxItemCount: -1,
589
- closeDropdownOnSelect: "auto",
590
- singleModeForMultiSelect: !1,
591
- addChoices: !1,
592
- addItems: !0,
593
- addItemFilter: function(i) {
594
- return !!i && i !== "";
595
- },
596
- removeItems: !0,
597
- removeItemButton: !1,
598
- removeItemButtonAlignLeft: !1,
599
- editItems: !1,
600
- allowHTML: !1,
601
- allowHtmlUserInput: !1,
602
- duplicateItemsAllowed: !0,
603
- delimiter: ",",
604
- paste: !0,
605
- searchEnabled: !0,
606
- searchChoices: !0,
607
- searchFloor: 1,
608
- searchResultLimit: 4,
609
- searchFields: ["label", "value"],
610
- position: "auto",
611
- resetScrollPosition: !0,
612
- shouldSort: !0,
613
- shouldSortItems: !1,
614
- sorter: ot,
615
- shadowRoot: null,
616
- placeholder: !0,
617
- placeholderValue: null,
618
- searchPlaceholderValue: null,
619
- prependValue: null,
620
- appendValue: null,
621
- renderSelectedChoices: "auto",
622
- loadingText: "Loading...",
623
- noResultsText: "No results found",
624
- noChoicesText: "No choices to choose from",
625
- itemSelectText: "Press to select",
626
- uniqueItemText: "Only unique values can be added",
627
- customAddItemText: "Only values matching specific conditions can be added",
628
- addItemText: function(i) {
629
- return 'Press Enter to add <b>"'.concat(i, '"</b>');
630
- },
631
- removeItemIconText: function() {
632
- return "Remove item";
633
- },
634
- removeItemLabelText: function(i) {
635
- return "Remove item: ".concat(i);
636
- },
637
- maxItemText: function(i) {
638
- return "Only ".concat(i, " values can be added");
639
- },
640
- valueComparer: function(i, e) {
641
- return i === e;
642
- },
643
- fuseOptions: {
644
- includeScore: !0
645
- },
646
- labelId: "",
647
- callbackOnInit: null,
648
- callbackOnCreateTemplates: null,
649
- classNames: bt,
650
- appendGroupInSearch: !1
651
- }, we = function(i) {
652
- var e = i.itemEl;
653
- e && (e.remove(), i.itemEl = void 0);
654
- };
655
- function Et(i, e, t) {
656
- var s = i, n = !0;
657
- switch (e.type) {
658
- case b.ADD_ITEM: {
659
- e.item.selected = !0;
660
- var r = e.item.element;
661
- r && (r.selected = !0, r.setAttribute("selected", "")), s.push(e.item);
662
- break;
663
- }
664
- case b.REMOVE_ITEM: {
665
- e.item.selected = !1;
666
- var r = e.item.element;
667
- if (r) {
668
- r.selected = !1, r.removeAttribute("selected");
669
- var o = r.parentElement;
670
- o && Ke(o) && o.type === R.SelectOne && (o.value = "");
671
- }
672
- we(e.item), s = s.filter(function(c) {
673
- return c.id !== e.item.id;
674
- });
675
- break;
676
- }
677
- case b.REMOVE_CHOICE: {
678
- we(e.choice), s = s.filter(function(h) {
679
- return h.id !== e.choice.id;
680
- });
681
- break;
682
- }
683
- case b.HIGHLIGHT_ITEM: {
684
- var a = e.highlighted, l = s.find(function(h) {
685
- return h.id === e.item.id;
686
- });
687
- l && l.highlighted !== a && (l.highlighted = a, t && ut(l, a ? t.classNames.highlightedState : t.classNames.selectedState, a ? t.classNames.selectedState : t.classNames.highlightedState));
688
- break;
689
- }
690
- default: {
691
- n = !1;
692
- break;
693
- }
694
- }
695
- return { state: s, update: n };
696
- }
697
- function Ct(i, e) {
698
- var t = i, s = !0;
699
- switch (e.type) {
700
- case b.ADD_GROUP: {
701
- t.push(e.group);
702
- break;
703
- }
704
- case b.CLEAR_CHOICES: {
705
- t = [];
706
- break;
707
- }
708
- default: {
709
- s = !1;
710
- break;
711
- }
712
- }
713
- return { state: t, update: s };
714
- }
715
- function St(i, e, t) {
716
- var s = i, n = !0;
717
- switch (e.type) {
718
- case b.ADD_CHOICE: {
719
- s.push(e.choice);
720
- break;
721
- }
722
- case b.REMOVE_CHOICE: {
723
- e.choice.choiceEl = void 0, e.choice.group && (e.choice.group.choices = e.choice.group.choices.filter(function(o) {
724
- return o.id !== e.choice.id;
725
- })), s = s.filter(function(o) {
726
- return o.id !== e.choice.id;
727
- });
728
- break;
729
- }
730
- case b.ADD_ITEM:
731
- case b.REMOVE_ITEM: {
732
- e.item.choiceEl = void 0;
733
- break;
734
- }
735
- case b.FILTER_CHOICES: {
736
- var r = [];
737
- e.results.forEach(function(o) {
738
- r[o.item.id] = o;
739
- }), s.forEach(function(o) {
740
- var a = r[o.id];
741
- a !== void 0 ? (o.score = a.score, o.rank = a.rank, o.active = !0) : (o.score = 0, o.rank = 0, o.active = !1), t && t.appendGroupInSearch && (o.choiceEl = void 0);
742
- });
743
- break;
744
- }
745
- case b.ACTIVATE_CHOICES: {
746
- s.forEach(function(o) {
747
- o.active = e.active, t && t.appendGroupInSearch && (o.choiceEl = void 0);
748
- });
749
- break;
750
- }
751
- case b.CLEAR_CHOICES: {
752
- s = [];
753
- break;
754
- }
755
- default: {
756
- n = !1;
757
- break;
758
- }
759
- }
760
- return { state: s, update: n };
761
- }
762
- var Ae = {
763
- groups: Ct,
764
- items: Et,
765
- choices: St
766
- }, It = (
767
- /** @class */
768
- function() {
769
- function i(e) {
770
- this._state = this.defaultState, this._listeners = [], this._txn = 0, this._context = e;
771
- }
772
- return Object.defineProperty(i.prototype, "defaultState", {
773
- // eslint-disable-next-line class-methods-use-this
774
- get: function() {
775
- return {
776
- groups: [],
777
- items: [],
778
- choices: []
779
- };
780
- },
781
- enumerable: !1,
782
- configurable: !0
783
- }), i.prototype.changeSet = function(e) {
784
- return {
785
- groups: e,
786
- items: e,
787
- choices: e
788
- };
789
- }, i.prototype.reset = function() {
790
- this._state = this.defaultState;
791
- var e = this.changeSet(!0);
792
- this._txn ? this._changeSet = e : this._listeners.forEach(function(t) {
793
- return t(e);
794
- });
795
- }, i.prototype.subscribe = function(e) {
796
- return this._listeners.push(e), this;
797
- }, i.prototype.dispatch = function(e) {
798
- var t = this, s = this._state, n = !1, r = this._changeSet || this.changeSet(!1);
799
- Object.keys(Ae).forEach(function(o) {
800
- var a = Ae[o](s[o], e, t._context);
801
- a.update && (n = !0, r[o] = !0, s[o] = a.state);
802
- }), n && (this._txn ? this._changeSet = r : this._listeners.forEach(function(o) {
803
- return o(r);
804
- }));
805
- }, i.prototype.withTxn = function(e) {
806
- this._txn++;
807
- try {
808
- e();
809
- } finally {
810
- if (this._txn = Math.max(0, this._txn - 1), !this._txn) {
811
- var t = this._changeSet;
812
- t && (this._changeSet = void 0, this._listeners.forEach(function(s) {
813
- return s(t);
814
- }));
815
- }
816
- }
817
- }, Object.defineProperty(i.prototype, "state", {
818
- /**
819
- * Get store object
820
- */
821
- get: function() {
822
- return this._state;
823
- },
824
- enumerable: !1,
825
- configurable: !0
826
- }), Object.defineProperty(i.prototype, "items", {
827
- /**
828
- * Get items from store
829
- */
830
- get: function() {
831
- return this.state.items;
832
- },
833
- enumerable: !1,
834
- configurable: !0
835
- }), Object.defineProperty(i.prototype, "highlightedActiveItems", {
836
- /**
837
- * Get highlighted items from store
838
- */
839
- get: function() {
840
- return this.items.filter(function(e) {
841
- return e.active && e.highlighted;
842
- });
843
- },
844
- enumerable: !1,
845
- configurable: !0
846
- }), Object.defineProperty(i.prototype, "choices", {
847
- /**
848
- * Get choices from store
849
- */
850
- get: function() {
851
- return this.state.choices;
852
- },
853
- enumerable: !1,
854
- configurable: !0
855
- }), Object.defineProperty(i.prototype, "activeChoices", {
856
- /**
857
- * Get active choices from store
858
- */
859
- get: function() {
860
- return this.choices.filter(function(e) {
861
- return e.active;
862
- });
863
- },
864
- enumerable: !1,
865
- configurable: !0
866
- }), Object.defineProperty(i.prototype, "searchableChoices", {
867
- /**
868
- * Get choices that can be searched (excluding placeholders or disabled choices)
869
- */
870
- get: function() {
871
- return this.choices.filter(function(e) {
872
- return !e.disabled && !e.placeholder;
873
- });
874
- },
875
- enumerable: !1,
876
- configurable: !0
877
- }), Object.defineProperty(i.prototype, "groups", {
878
- /**
879
- * Get groups from store
880
- */
881
- get: function() {
882
- return this.state.groups;
883
- },
884
- enumerable: !1,
885
- configurable: !0
886
- }), Object.defineProperty(i.prototype, "activeGroups", {
887
- /**
888
- * Get active groups from store
889
- */
890
- get: function() {
891
- var e = this;
892
- return this.state.groups.filter(function(t) {
893
- var s = t.active && !t.disabled, n = e.state.choices.some(function(r) {
894
- return r.active && !r.disabled;
895
- });
896
- return s && n;
897
- }, []);
898
- },
899
- enumerable: !1,
900
- configurable: !0
901
- }), i.prototype.inTxn = function() {
902
- return this._txn > 0;
903
- }, i.prototype.getChoiceById = function(e) {
904
- return this.activeChoices.find(function(t) {
905
- return t.id === e;
906
- });
907
- }, i.prototype.getGroupById = function(e) {
908
- return this.groups.find(function(t) {
909
- return t.id === e;
910
- });
911
- }, i;
912
- }()
913
- ), E = {
914
- noChoices: "no-choices",
915
- noResults: "no-results",
916
- addChoice: "add-choice",
917
- generic: ""
918
- };
919
- function wt(i, e, t) {
920
- return (e = Ot(e)) in i ? Object.defineProperty(i, e, {
921
- value: t,
922
- enumerable: !0,
923
- configurable: !0,
924
- writable: !0
925
- }) : i[e] = t, i;
926
- }
927
- function Oe(i, e) {
928
- var t = Object.keys(i);
929
- if (Object.getOwnPropertySymbols) {
930
- var s = Object.getOwnPropertySymbols(i);
931
- e && (s = s.filter(function(n) {
932
- return Object.getOwnPropertyDescriptor(i, n).enumerable;
933
- })), t.push.apply(t, s);
934
- }
935
- return t;
936
- }
937
- function G(i) {
938
- for (var e = 1; e < arguments.length; e++) {
939
- var t = arguments[e] != null ? arguments[e] : {};
940
- e % 2 ? Oe(Object(t), !0).forEach(function(s) {
941
- wt(i, s, t[s]);
942
- }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(i, Object.getOwnPropertyDescriptors(t)) : Oe(Object(t)).forEach(function(s) {
943
- Object.defineProperty(i, s, Object.getOwnPropertyDescriptor(t, s));
944
- });
945
- }
946
- return i;
947
- }
948
- function At(i, e) {
949
- if (typeof i != "object" || !i) return i;
950
- var t = i[Symbol.toPrimitive];
951
- if (t !== void 0) {
952
- var s = t.call(i, e);
953
- if (typeof s != "object") return s;
954
- throw new TypeError("@@toPrimitive must return a primitive value.");
955
- }
956
- return (e === "string" ? String : Number)(i);
957
- }
958
- function Ot(i) {
959
- var e = At(i, "string");
960
- return typeof e == "symbol" ? e : e + "";
961
- }
962
- function P(i) {
963
- return Array.isArray ? Array.isArray(i) : Ve(i) === "[object Array]";
964
- }
965
- function Tt(i) {
966
- if (typeof i == "string")
967
- return i;
968
- let e = i + "";
969
- return e == "0" && 1 / i == -1 / 0 ? "-0" : e;
970
- }
971
- function xt(i) {
972
- return i == null ? "" : Tt(i);
973
- }
974
- function D(i) {
975
- return typeof i == "string";
976
- }
977
- function He(i) {
978
- return typeof i == "number";
979
- }
980
- function Mt(i) {
981
- return i === !0 || i === !1 || Lt(i) && Ve(i) == "[object Boolean]";
982
- }
983
- function je(i) {
984
- return typeof i == "object";
985
- }
986
- function Lt(i) {
987
- return je(i) && i !== null;
988
- }
989
- function O(i) {
990
- return i != null;
991
- }
992
- function se(i) {
993
- return !i.trim().length;
994
- }
995
- function Ve(i) {
996
- return i == null ? i === void 0 ? "[object Undefined]" : "[object Null]" : Object.prototype.toString.call(i);
997
- }
998
- const Dt = "Incorrect 'index' type", Nt = (i) => `Invalid value for key ${i}`, Pt = (i) => `Pattern length exceeds max of ${i}.`, Ft = (i) => `Missing ${i} property in key`, kt = (i) => `Property 'weight' in key '${i}' must be a positive integer`, Te = Object.prototype.hasOwnProperty;
999
- class Rt {
1000
- constructor(e) {
1001
- this._keys = [], this._keyMap = {};
1002
- let t = 0;
1003
- e.forEach((s) => {
1004
- let n = Be(s);
1005
- this._keys.push(n), this._keyMap[n.id] = n, t += n.weight;
1006
- }), this._keys.forEach((s) => {
1007
- s.weight /= t;
1008
- });
1009
- }
1010
- get(e) {
1011
- return this._keyMap[e];
1012
- }
1013
- keys() {
1014
- return this._keys;
1015
- }
1016
- toJSON() {
1017
- return JSON.stringify(this._keys);
1018
- }
1019
- }
1020
- function Be(i) {
1021
- let e = null, t = null, s = null, n = 1, r = null;
1022
- if (D(i) || P(i))
1023
- s = i, e = xe(i), t = ae(i);
1024
- else {
1025
- if (!Te.call(i, "name"))
1026
- throw new Error(Ft("name"));
1027
- const o = i.name;
1028
- if (s = o, Te.call(i, "weight") && (n = i.weight, n <= 0))
1029
- throw new Error(kt(o));
1030
- e = xe(o), t = ae(o), r = i.getFn;
1031
- }
1032
- return {
1033
- path: e,
1034
- id: t,
1035
- weight: n,
1036
- src: s,
1037
- getFn: r
1038
- };
1039
- }
1040
- function xe(i) {
1041
- return P(i) ? i : i.split(".");
1042
- }
1043
- function ae(i) {
1044
- return P(i) ? i.join(".") : i;
1045
- }
1046
- function Kt(i, e) {
1047
- let t = [], s = !1;
1048
- const n = (r, o, a) => {
1049
- if (O(r))
1050
- if (!o[a])
1051
- t.push(r);
1052
- else {
1053
- let l = o[a];
1054
- const h = r[l];
1055
- if (!O(h))
1056
- return;
1057
- if (a === o.length - 1 && (D(h) || He(h) || Mt(h)))
1058
- t.push(xt(h));
1059
- else if (P(h)) {
1060
- s = !0;
1061
- for (let c = 0, u = h.length; c < u; c += 1)
1062
- n(h[c], o, a + 1);
1063
- } else o.length && n(h, o, a + 1);
1064
- }
1065
- };
1066
- return n(i, D(e) ? e.split(".") : e, 0), s ? t : t[0];
1067
- }
1068
- const Ht = {
1069
- // Whether the matches should be included in the result set. When `true`, each record in the result
1070
- // set will include the indices of the matched characters.
1071
- // These can consequently be used for highlighting purposes.
1072
- includeMatches: !1,
1073
- // When `true`, the matching function will continue to the end of a search pattern even if
1074
- // a perfect match has already been located in the string.
1075
- findAllMatches: !1,
1076
- // Minimum number of characters that must be matched before a result is considered a match
1077
- minMatchCharLength: 1
1078
- }, jt = {
1079
- // When `true`, the algorithm continues searching to the end of the input even if a perfect
1080
- // match is found before the end of the same input.
1081
- isCaseSensitive: !1,
1082
- // When true, the matching function will continue to the end of a search pattern even if
1083
- includeScore: !1,
1084
- // List of properties that will be searched. This also supports nested properties.
1085
- keys: [],
1086
- // Whether to sort the result list, by score
1087
- shouldSort: !0,
1088
- // Default sort function: sort by ascending score, ascending index
1089
- sortFn: (i, e) => i.score === e.score ? i.idx < e.idx ? -1 : 1 : i.score < e.score ? -1 : 1
1090
- }, Vt = {
1091
- // Approximately where in the text is the pattern expected to be found?
1092
- location: 0,
1093
- // At what point does the match algorithm give up. A threshold of '0.0' requires a perfect match
1094
- // (of both letters and location), a threshold of '1.0' would match anything.
1095
- threshold: 0.6,
1096
- // Determines how close the match must be to the fuzzy location (specified above).
1097
- // An exact letter match which is 'distance' characters away from the fuzzy location
1098
- // would score as a complete mismatch. A distance of '0' requires the match be at
1099
- // the exact location specified, a threshold of '1000' would require a perfect match
1100
- // to be within 800 characters of the fuzzy location to be found using a 0.8 threshold.
1101
- distance: 100
1102
- }, Bt = {
1103
- // When `true`, it enables the use of unix-like search commands
1104
- useExtendedSearch: !1,
1105
- // The get function to use when fetching an object's properties.
1106
- // The default will search nested paths *ie foo.bar.baz*
1107
- getFn: Kt,
1108
- // When `true`, search will ignore `location` and `distance`, so it won't matter
1109
- // where in the string the pattern appears.
1110
- // More info: https://fusejs.io/concepts/scoring-theory.html#fuzziness-score
1111
- ignoreLocation: !1,
1112
- // When `true`, the calculation for the relevance score (used for sorting) will
1113
- // ignore the field-length norm.
1114
- // More info: https://fusejs.io/concepts/scoring-theory.html#field-length-norm
1115
- ignoreFieldNorm: !1,
1116
- // The weight to determine how much field length norm effects scoring.
1117
- fieldNormWeight: 1
1118
- };
1119
- var v = G(G(G(G({}, jt), Ht), Vt), Bt);
1120
- const Gt = /[^ ]+/g;
1121
- function Wt(i = 1, e = 3) {
1122
- const t = /* @__PURE__ */ new Map(), s = Math.pow(10, e);
1123
- return {
1124
- get(n) {
1125
- const r = n.match(Gt).length;
1126
- if (t.has(r))
1127
- return t.get(r);
1128
- const o = 1 / Math.pow(r, 0.5 * i), a = parseFloat(Math.round(o * s) / s);
1129
- return t.set(r, a), a;
1130
- },
1131
- clear() {
1132
- t.clear();
1133
- }
1134
- };
1135
- }
1136
- class pe {
1137
- constructor({
1138
- getFn: e = v.getFn,
1139
- fieldNormWeight: t = v.fieldNormWeight
1140
- } = {}) {
1141
- this.norm = Wt(t, 3), this.getFn = e, this.isCreated = !1, this.setIndexRecords();
1142
- }
1143
- setSources(e = []) {
1144
- this.docs = e;
1145
- }
1146
- setIndexRecords(e = []) {
1147
- this.records = e;
1148
- }
1149
- setKeys(e = []) {
1150
- this.keys = e, this._keysMap = {}, e.forEach((t, s) => {
1151
- this._keysMap[t.id] = s;
1152
- });
1153
- }
1154
- create() {
1155
- this.isCreated || !this.docs.length || (this.isCreated = !0, D(this.docs[0]) ? this.docs.forEach((e, t) => {
1156
- this._addString(e, t);
1157
- }) : this.docs.forEach((e, t) => {
1158
- this._addObject(e, t);
1159
- }), this.norm.clear());
1160
- }
1161
- // Adds a doc to the end of the index
1162
- add(e) {
1163
- const t = this.size();
1164
- D(e) ? this._addString(e, t) : this._addObject(e, t);
1165
- }
1166
- // Removes the doc at the specified index of the index
1167
- removeAt(e) {
1168
- this.records.splice(e, 1);
1169
- for (let t = e, s = this.size(); t < s; t += 1)
1170
- this.records[t].i -= 1;
1171
- }
1172
- getValueForItemAtKeyId(e, t) {
1173
- return e[this._keysMap[t]];
1174
- }
1175
- size() {
1176
- return this.records.length;
1177
- }
1178
- _addString(e, t) {
1179
- if (!O(e) || se(e))
1180
- return;
1181
- let s = {
1182
- v: e,
1183
- i: t,
1184
- n: this.norm.get(e)
1185
- };
1186
- this.records.push(s);
1187
- }
1188
- _addObject(e, t) {
1189
- let s = {
1190
- i: t,
1191
- $: {}
1192
- };
1193
- this.keys.forEach((n, r) => {
1194
- let o = n.getFn ? n.getFn(e) : this.getFn(e, n.path);
1195
- if (O(o)) {
1196
- if (P(o)) {
1197
- let a = [];
1198
- const l = [{
1199
- nestedArrIndex: -1,
1200
- value: o
1201
- }];
1202
- for (; l.length; ) {
1203
- const {
1204
- nestedArrIndex: h,
1205
- value: c
1206
- } = l.pop();
1207
- if (O(c))
1208
- if (D(c) && !se(c)) {
1209
- let u = {
1210
- v: c,
1211
- i: h,
1212
- n: this.norm.get(c)
1213
- };
1214
- a.push(u);
1215
- } else P(c) && c.forEach((u, f) => {
1216
- l.push({
1217
- nestedArrIndex: f,
1218
- value: u
1219
- });
1220
- });
1221
- }
1222
- s.$[r] = a;
1223
- } else if (D(o) && !se(o)) {
1224
- let a = {
1225
- v: o,
1226
- n: this.norm.get(o)
1227
- };
1228
- s.$[r] = a;
1229
- }
1230
- }
1231
- }), this.records.push(s);
1232
- }
1233
- toJSON() {
1234
- return {
1235
- keys: this.keys,
1236
- records: this.records
1237
- };
1238
- }
1239
- }
1240
- function Ge(i, e, {
1241
- getFn: t = v.getFn,
1242
- fieldNormWeight: s = v.fieldNormWeight
1243
- } = {}) {
1244
- const n = new pe({
1245
- getFn: t,
1246
- fieldNormWeight: s
1247
- });
1248
- return n.setKeys(i.map(Be)), n.setSources(e), n.create(), n;
1249
- }
1250
- function Ut(i, {
1251
- getFn: e = v.getFn,
1252
- fieldNormWeight: t = v.fieldNormWeight
1253
- } = {}) {
1254
- const {
1255
- keys: s,
1256
- records: n
1257
- } = i, r = new pe({
1258
- getFn: e,
1259
- fieldNormWeight: t
1260
- });
1261
- return r.setKeys(s), r.setIndexRecords(n), r;
1262
- }
1263
- function J(i, {
1264
- errors: e = 0,
1265
- currentLocation: t = 0,
1266
- expectedLocation: s = 0,
1267
- distance: n = v.distance,
1268
- ignoreLocation: r = v.ignoreLocation
1269
- } = {}) {
1270
- const o = e / i.length;
1271
- if (r)
1272
- return o;
1273
- const a = Math.abs(s - t);
1274
- return n ? o + a / n : a ? 1 : o;
1275
- }
1276
- function $t(i = [], e = v.minMatchCharLength) {
1277
- let t = [], s = -1, n = -1, r = 0;
1278
- for (let o = i.length; r < o; r += 1) {
1279
- let a = i[r];
1280
- a && s === -1 ? s = r : !a && s !== -1 && (n = r - 1, n - s + 1 >= e && t.push([s, n]), s = -1);
1281
- }
1282
- return i[r - 1] && r - s >= e && t.push([s, r - 1]), t;
1283
- }
1284
- const j = 32;
1285
- function Yt(i, e, t, {
1286
- location: s = v.location,
1287
- distance: n = v.distance,
1288
- threshold: r = v.threshold,
1289
- findAllMatches: o = v.findAllMatches,
1290
- minMatchCharLength: a = v.minMatchCharLength,
1291
- includeMatches: l = v.includeMatches,
1292
- ignoreLocation: h = v.ignoreLocation
1293
- } = {}) {
1294
- if (e.length > j)
1295
- throw new Error(Pt(j));
1296
- const c = e.length, u = i.length, f = Math.max(0, Math.min(s, u));
1297
- let m = r, d = f;
1298
- const p = a > 1 || l, y = p ? Array(u) : [];
1299
- let g;
1300
- for (; (g = i.indexOf(e, d)) > -1; ) {
1301
- let T = J(e, {
1302
- currentLocation: g,
1303
- expectedLocation: f,
1304
- distance: n,
1305
- ignoreLocation: h
1306
- });
1307
- if (m = Math.min(T, m), d = g + c, p) {
1308
- let F = 0;
1309
- for (; F < c; )
1310
- y[g + F] = 1, F += 1;
1311
- }
1312
- }
1313
- d = -1;
1314
- let S = [], I = 1, H = c + u;
1315
- const qe = 1 << c - 1;
1316
- for (let T = 0; T < c; T += 1) {
1317
- let F = 0, k = H;
1318
- for (; F < k; )
1319
- J(e, {
1320
- errors: T,
1321
- currentLocation: f + k,
1322
- expectedLocation: f,
1323
- distance: n,
1324
- ignoreLocation: h
1325
- }) <= m ? F = k : H = k, k = Math.floor((H - F) / 2 + F);
1326
- H = k;
1327
- let me = Math.max(1, f - k + 1), ie = o ? u : Math.min(f + k, u) + c, B = Array(ie + 2);
1328
- B[ie + 1] = (1 << T) - 1;
1329
- for (let x = ie; x >= me; x -= 1) {
1330
- let z = x - 1, ve = t[i.charAt(z)];
1331
- if (p && (y[z] = +!!ve), B[x] = (B[x + 1] << 1 | 1) & ve, T && (B[x] |= (S[x + 1] | S[x]) << 1 | 1 | S[x + 1]), B[x] & qe && (I = J(e, {
1332
- errors: T,
1333
- currentLocation: z,
1334
- expectedLocation: f,
1335
- distance: n,
1336
- ignoreLocation: h
1337
- }), I <= m)) {
1338
- if (m = I, d = z, d <= f)
1339
- break;
1340
- me = Math.max(1, 2 * f - d);
1341
- }
1342
- }
1343
- if (J(e, {
1344
- errors: T + 1,
1345
- currentLocation: f,
1346
- expectedLocation: f,
1347
- distance: n,
1348
- ignoreLocation: h
1349
- }) > m)
1350
- break;
1351
- S = B;
1352
- }
1353
- const te = {
1354
- isMatch: d >= 0,
1355
- // Count exact matches (those with a score of 0) to be "almost" exact
1356
- score: Math.max(1e-3, I)
1357
- };
1358
- if (p) {
1359
- const T = $t(y, a);
1360
- T.length ? l && (te.indices = T) : te.isMatch = !1;
1361
- }
1362
- return te;
1363
- }
1364
- function qt(i) {
1365
- let e = {};
1366
- for (let t = 0, s = i.length; t < s; t += 1) {
1367
- const n = i.charAt(t);
1368
- e[n] = (e[n] || 0) | 1 << s - t - 1;
1369
- }
1370
- return e;
1371
- }
1372
- class We {
1373
- constructor(e, {
1374
- location: t = v.location,
1375
- threshold: s = v.threshold,
1376
- distance: n = v.distance,
1377
- includeMatches: r = v.includeMatches,
1378
- findAllMatches: o = v.findAllMatches,
1379
- minMatchCharLength: a = v.minMatchCharLength,
1380
- isCaseSensitive: l = v.isCaseSensitive,
1381
- ignoreLocation: h = v.ignoreLocation
1382
- } = {}) {
1383
- if (this.options = {
1384
- location: t,
1385
- threshold: s,
1386
- distance: n,
1387
- includeMatches: r,
1388
- findAllMatches: o,
1389
- minMatchCharLength: a,
1390
- isCaseSensitive: l,
1391
- ignoreLocation: h
1392
- }, this.pattern = l ? e : e.toLowerCase(), this.chunks = [], !this.pattern.length)
1393
- return;
1394
- const c = (f, m) => {
1395
- this.chunks.push({
1396
- pattern: f,
1397
- alphabet: qt(f),
1398
- startIndex: m
1399
- });
1400
- }, u = this.pattern.length;
1401
- if (u > j) {
1402
- let f = 0;
1403
- const m = u % j, d = u - m;
1404
- for (; f < d; )
1405
- c(this.pattern.substr(f, j), f), f += j;
1406
- if (m) {
1407
- const p = u - j;
1408
- c(this.pattern.substr(p), p);
1409
- }
1410
- } else
1411
- c(this.pattern, 0);
1412
- }
1413
- searchIn(e) {
1414
- const {
1415
- isCaseSensitive: t,
1416
- includeMatches: s
1417
- } = this.options;
1418
- if (t || (e = e.toLowerCase()), this.pattern === e) {
1419
- let d = {
1420
- isMatch: !0,
1421
- score: 0
1422
- };
1423
- return s && (d.indices = [[0, e.length - 1]]), d;
1424
- }
1425
- const {
1426
- location: n,
1427
- distance: r,
1428
- threshold: o,
1429
- findAllMatches: a,
1430
- minMatchCharLength: l,
1431
- ignoreLocation: h
1432
- } = this.options;
1433
- let c = [], u = 0, f = !1;
1434
- this.chunks.forEach(({
1435
- pattern: d,
1436
- alphabet: p,
1437
- startIndex: y
1438
- }) => {
1439
- const {
1440
- isMatch: g,
1441
- score: S,
1442
- indices: I
1443
- } = Yt(e, d, p, {
1444
- location: n + y,
1445
- distance: r,
1446
- threshold: o,
1447
- findAllMatches: a,
1448
- minMatchCharLength: l,
1449
- includeMatches: s,
1450
- ignoreLocation: h
1451
- });
1452
- g && (f = !0), u += S, g && I && (c = [...c, ...I]);
1453
- });
1454
- let m = {
1455
- isMatch: f,
1456
- score: f ? u / this.chunks.length : 1
1457
- };
1458
- return f && s && (m.indices = c), m;
1459
- }
1460
- }
1461
- class K {
1462
- constructor(e) {
1463
- this.pattern = e;
1464
- }
1465
- static isMultiMatch(e) {
1466
- return Me(e, this.multiRegex);
1467
- }
1468
- static isSingleMatch(e) {
1469
- return Me(e, this.singleRegex);
1470
- }
1471
- search() {
1472
- }
1473
- }
1474
- function Me(i, e) {
1475
- const t = i.match(e);
1476
- return t ? t[1] : null;
1477
- }
1478
- class zt extends K {
1479
- constructor(e) {
1480
- super(e);
1481
- }
1482
- static get type() {
1483
- return "exact";
1484
- }
1485
- static get multiRegex() {
1486
- return /^="(.*)"$/;
1487
- }
1488
- static get singleRegex() {
1489
- return /^=(.*)$/;
1490
- }
1491
- search(e) {
1492
- const t = e === this.pattern;
1493
- return {
1494
- isMatch: t,
1495
- score: t ? 0 : 1,
1496
- indices: [0, this.pattern.length - 1]
1497
- };
1498
- }
1499
- }
1500
- class Xt extends K {
1501
- constructor(e) {
1502
- super(e);
1503
- }
1504
- static get type() {
1505
- return "inverse-exact";
1506
- }
1507
- static get multiRegex() {
1508
- return /^!"(.*)"$/;
1509
- }
1510
- static get singleRegex() {
1511
- return /^!(.*)$/;
1512
- }
1513
- search(e) {
1514
- const s = e.indexOf(this.pattern) === -1;
1515
- return {
1516
- isMatch: s,
1517
- score: s ? 0 : 1,
1518
- indices: [0, e.length - 1]
1519
- };
1520
- }
1521
- }
1522
- class Jt extends K {
1523
- constructor(e) {
1524
- super(e);
1525
- }
1526
- static get type() {
1527
- return "prefix-exact";
1528
- }
1529
- static get multiRegex() {
1530
- return /^\^"(.*)"$/;
1531
- }
1532
- static get singleRegex() {
1533
- return /^\^(.*)$/;
1534
- }
1535
- search(e) {
1536
- const t = e.startsWith(this.pattern);
1537
- return {
1538
- isMatch: t,
1539
- score: t ? 0 : 1,
1540
- indices: [0, this.pattern.length - 1]
1541
- };
1542
- }
1543
- }
1544
- class Qt extends K {
1545
- constructor(e) {
1546
- super(e);
1547
- }
1548
- static get type() {
1549
- return "inverse-prefix-exact";
1550
- }
1551
- static get multiRegex() {
1552
- return /^!\^"(.*)"$/;
1553
- }
1554
- static get singleRegex() {
1555
- return /^!\^(.*)$/;
1556
- }
1557
- search(e) {
1558
- const t = !e.startsWith(this.pattern);
1559
- return {
1560
- isMatch: t,
1561
- score: t ? 0 : 1,
1562
- indices: [0, e.length - 1]
1563
- };
1564
- }
1565
- }
1566
- class Zt extends K {
1567
- constructor(e) {
1568
- super(e);
1569
- }
1570
- static get type() {
1571
- return "suffix-exact";
1572
- }
1573
- static get multiRegex() {
1574
- return /^"(.*)"\$$/;
1575
- }
1576
- static get singleRegex() {
1577
- return /^(.*)\$$/;
1578
- }
1579
- search(e) {
1580
- const t = e.endsWith(this.pattern);
1581
- return {
1582
- isMatch: t,
1583
- score: t ? 0 : 1,
1584
- indices: [e.length - this.pattern.length, e.length - 1]
1585
- };
1586
- }
1587
- }
1588
- class ei extends K {
1589
- constructor(e) {
1590
- super(e);
1591
- }
1592
- static get type() {
1593
- return "inverse-suffix-exact";
1594
- }
1595
- static get multiRegex() {
1596
- return /^!"(.*)"\$$/;
1597
- }
1598
- static get singleRegex() {
1599
- return /^!(.*)\$$/;
1600
- }
1601
- search(e) {
1602
- const t = !e.endsWith(this.pattern);
1603
- return {
1604
- isMatch: t,
1605
- score: t ? 0 : 1,
1606
- indices: [0, e.length - 1]
1607
- };
1608
- }
1609
- }
1610
- class Ue extends K {
1611
- constructor(e, {
1612
- location: t = v.location,
1613
- threshold: s = v.threshold,
1614
- distance: n = v.distance,
1615
- includeMatches: r = v.includeMatches,
1616
- findAllMatches: o = v.findAllMatches,
1617
- minMatchCharLength: a = v.minMatchCharLength,
1618
- isCaseSensitive: l = v.isCaseSensitive,
1619
- ignoreLocation: h = v.ignoreLocation
1620
- } = {}) {
1621
- super(e), this._bitapSearch = new We(e, {
1622
- location: t,
1623
- threshold: s,
1624
- distance: n,
1625
- includeMatches: r,
1626
- findAllMatches: o,
1627
- minMatchCharLength: a,
1628
- isCaseSensitive: l,
1629
- ignoreLocation: h
1630
- });
1631
- }
1632
- static get type() {
1633
- return "fuzzy";
1634
- }
1635
- static get multiRegex() {
1636
- return /^"(.*)"$/;
1637
- }
1638
- static get singleRegex() {
1639
- return /^(.*)$/;
1640
- }
1641
- search(e) {
1642
- return this._bitapSearch.searchIn(e);
1643
- }
1644
- }
1645
- class $e extends K {
1646
- constructor(e) {
1647
- super(e);
1648
- }
1649
- static get type() {
1650
- return "include";
1651
- }
1652
- static get multiRegex() {
1653
- return /^'"(.*)"$/;
1654
- }
1655
- static get singleRegex() {
1656
- return /^'(.*)$/;
1657
- }
1658
- search(e) {
1659
- let t = 0, s;
1660
- const n = [], r = this.pattern.length;
1661
- for (; (s = e.indexOf(this.pattern, t)) > -1; )
1662
- t = s + r, n.push([s, t - 1]);
1663
- const o = !!n.length;
1664
- return {
1665
- isMatch: o,
1666
- score: o ? 0 : 1,
1667
- indices: n
1668
- };
1669
- }
1670
- }
1671
- const le = [zt, $e, Jt, Qt, ei, Zt, Xt, Ue], Le = le.length, ti = / +(?=(?:[^\"]*\"[^\"]*\")*[^\"]*$)/, ii = "|";
1672
- function si(i, e = {}) {
1673
- return i.split(ii).map((t) => {
1674
- let s = t.trim().split(ti).filter((r) => r && !!r.trim()), n = [];
1675
- for (let r = 0, o = s.length; r < o; r += 1) {
1676
- const a = s[r];
1677
- let l = !1, h = -1;
1678
- for (; !l && ++h < Le; ) {
1679
- const c = le[h];
1680
- let u = c.isMultiMatch(a);
1681
- u && (n.push(new c(u, e)), l = !0);
1682
- }
1683
- if (!l)
1684
- for (h = -1; ++h < Le; ) {
1685
- const c = le[h];
1686
- let u = c.isSingleMatch(a);
1687
- if (u) {
1688
- n.push(new c(u, e));
1689
- break;
1690
- }
1691
- }
1692
- }
1693
- return n;
1694
- });
1695
- }
1696
- const ni = /* @__PURE__ */ new Set([Ue.type, $e.type]);
1697
- class ri {
1698
- constructor(e, {
1699
- isCaseSensitive: t = v.isCaseSensitive,
1700
- includeMatches: s = v.includeMatches,
1701
- minMatchCharLength: n = v.minMatchCharLength,
1702
- ignoreLocation: r = v.ignoreLocation,
1703
- findAllMatches: o = v.findAllMatches,
1704
- location: a = v.location,
1705
- threshold: l = v.threshold,
1706
- distance: h = v.distance
1707
- } = {}) {
1708
- this.query = null, this.options = {
1709
- isCaseSensitive: t,
1710
- includeMatches: s,
1711
- minMatchCharLength: n,
1712
- findAllMatches: o,
1713
- ignoreLocation: r,
1714
- location: a,
1715
- threshold: l,
1716
- distance: h
1717
- }, this.pattern = t ? e : e.toLowerCase(), this.query = si(this.pattern, this.options);
1718
- }
1719
- static condition(e, t) {
1720
- return t.useExtendedSearch;
1721
- }
1722
- searchIn(e) {
1723
- const t = this.query;
1724
- if (!t)
1725
- return {
1726
- isMatch: !1,
1727
- score: 1
1728
- };
1729
- const {
1730
- includeMatches: s,
1731
- isCaseSensitive: n
1732
- } = this.options;
1733
- e = n ? e : e.toLowerCase();
1734
- let r = 0, o = [], a = 0;
1735
- for (let l = 0, h = t.length; l < h; l += 1) {
1736
- const c = t[l];
1737
- o.length = 0, r = 0;
1738
- for (let u = 0, f = c.length; u < f; u += 1) {
1739
- const m = c[u], {
1740
- isMatch: d,
1741
- indices: p,
1742
- score: y
1743
- } = m.search(e);
1744
- if (d) {
1745
- if (r += 1, a += y, s) {
1746
- const g = m.constructor.type;
1747
- ni.has(g) ? o = [...o, ...p] : o.push(p);
1748
- }
1749
- } else {
1750
- a = 0, r = 0, o.length = 0;
1751
- break;
1752
- }
1753
- }
1754
- if (r) {
1755
- let u = {
1756
- isMatch: !0,
1757
- score: a / r
1758
- };
1759
- return s && (u.indices = o), u;
1760
- }
1761
- }
1762
- return {
1763
- isMatch: !1,
1764
- score: 1
1765
- };
1766
- }
1767
- }
1768
- const ce = [];
1769
- function oi(...i) {
1770
- ce.push(...i);
1771
- }
1772
- function he(i, e) {
1773
- for (let t = 0, s = ce.length; t < s; t += 1) {
1774
- let n = ce[t];
1775
- if (n.condition(i, e))
1776
- return new n(i, e);
1777
- }
1778
- return new We(i, e);
1779
- }
1780
- const Q = {
1781
- AND: "$and",
1782
- OR: "$or"
1783
- }, ue = {
1784
- PATH: "$path",
1785
- PATTERN: "$val"
1786
- }, de = (i) => !!(i[Q.AND] || i[Q.OR]), ai = (i) => !!i[ue.PATH], li = (i) => !P(i) && je(i) && !de(i), De = (i) => ({
1787
- [Q.AND]: Object.keys(i).map((e) => ({
1788
- [e]: i[e]
1789
- }))
1790
- });
1791
- function Ye(i, e, {
1792
- auto: t = !0
1793
- } = {}) {
1794
- const s = (n) => {
1795
- let r = Object.keys(n);
1796
- const o = ai(n);
1797
- if (!o && r.length > 1 && !de(n))
1798
- return s(De(n));
1799
- if (li(n)) {
1800
- const l = o ? n[ue.PATH] : r[0], h = o ? n[ue.PATTERN] : n[l];
1801
- if (!D(h))
1802
- throw new Error(Nt(l));
1803
- const c = {
1804
- keyId: ae(l),
1805
- pattern: h
1806
- };
1807
- return t && (c.searcher = he(h, e)), c;
1808
- }
1809
- let a = {
1810
- children: [],
1811
- operator: r[0]
1812
- };
1813
- return r.forEach((l) => {
1814
- const h = n[l];
1815
- P(h) && h.forEach((c) => {
1816
- a.children.push(s(c));
1817
- });
1818
- }), a;
1819
- };
1820
- return de(i) || (i = De(i)), s(i);
1821
- }
1822
- function ci(i, {
1823
- ignoreFieldNorm: e = v.ignoreFieldNorm
1824
- }) {
1825
- i.forEach((t) => {
1826
- let s = 1;
1827
- t.matches.forEach(({
1828
- key: n,
1829
- norm: r,
1830
- score: o
1831
- }) => {
1832
- const a = n ? n.weight : null;
1833
- s *= Math.pow(o === 0 && a ? Number.EPSILON : o, (a || 1) * (e ? 1 : r));
1834
- }), t.score = s;
1835
- });
1836
- }
1837
- function hi(i, e) {
1838
- const t = i.matches;
1839
- e.matches = [], O(t) && t.forEach((s) => {
1840
- if (!O(s.indices) || !s.indices.length)
1841
- return;
1842
- const {
1843
- indices: n,
1844
- value: r
1845
- } = s;
1846
- let o = {
1847
- indices: n,
1848
- value: r
1849
- };
1850
- s.key && (o.key = s.key.src), s.idx > -1 && (o.refIndex = s.idx), e.matches.push(o);
1851
- });
1852
- }
1853
- function ui(i, e) {
1854
- e.score = i.score;
1855
- }
1856
- function di(i, e, {
1857
- includeMatches: t = v.includeMatches,
1858
- includeScore: s = v.includeScore
1859
- } = {}) {
1860
- const n = [];
1861
- return t && n.push(hi), s && n.push(ui), i.map((r) => {
1862
- const {
1863
- idx: o
1864
- } = r, a = {
1865
- item: e[o],
1866
- refIndex: o
1867
- };
1868
- return n.length && n.forEach((l) => {
1869
- l(r, a);
1870
- }), a;
1871
- });
1872
- }
1873
- class W {
1874
- constructor(e, t = {}, s) {
1875
- this.options = G(G({}, v), t), this.options.useExtendedSearch, this._keyStore = new Rt(this.options.keys), this.setCollection(e, s);
1876
- }
1877
- setCollection(e, t) {
1878
- if (this._docs = e, t && !(t instanceof pe))
1879
- throw new Error(Dt);
1880
- this._myIndex = t || Ge(this.options.keys, this._docs, {
1881
- getFn: this.options.getFn,
1882
- fieldNormWeight: this.options.fieldNormWeight
1883
- });
1884
- }
1885
- add(e) {
1886
- O(e) && (this._docs.push(e), this._myIndex.add(e));
1887
- }
1888
- remove(e = () => !1) {
1889
- const t = [];
1890
- for (let s = 0, n = this._docs.length; s < n; s += 1) {
1891
- const r = this._docs[s];
1892
- e(r, s) && (this.removeAt(s), s -= 1, n -= 1, t.push(r));
1893
- }
1894
- return t;
1895
- }
1896
- removeAt(e) {
1897
- this._docs.splice(e, 1), this._myIndex.removeAt(e);
1898
- }
1899
- getIndex() {
1900
- return this._myIndex;
1901
- }
1902
- search(e, {
1903
- limit: t = -1
1904
- } = {}) {
1905
- const {
1906
- includeMatches: s,
1907
- includeScore: n,
1908
- shouldSort: r,
1909
- sortFn: o,
1910
- ignoreFieldNorm: a
1911
- } = this.options;
1912
- let l = D(e) ? D(this._docs[0]) ? this._searchStringList(e) : this._searchObjectList(e) : this._searchLogical(e);
1913
- return ci(l, {
1914
- ignoreFieldNorm: a
1915
- }), r && l.sort(o), He(t) && t > -1 && (l = l.slice(0, t)), di(l, this._docs, {
1916
- includeMatches: s,
1917
- includeScore: n
1918
- });
1919
- }
1920
- _searchStringList(e) {
1921
- const t = he(e, this.options), {
1922
- records: s
1923
- } = this._myIndex, n = [];
1924
- return s.forEach(({
1925
- v: r,
1926
- i: o,
1927
- n: a
1928
- }) => {
1929
- if (!O(r))
1930
- return;
1931
- const {
1932
- isMatch: l,
1933
- score: h,
1934
- indices: c
1935
- } = t.searchIn(r);
1936
- l && n.push({
1937
- item: r,
1938
- idx: o,
1939
- matches: [{
1940
- score: h,
1941
- value: r,
1942
- norm: a,
1943
- indices: c
1944
- }]
1945
- });
1946
- }), n;
1947
- }
1948
- _searchLogical(e) {
1949
- const t = Ye(e, this.options), s = (a, l, h) => {
1950
- if (!a.children) {
1951
- const {
1952
- keyId: u,
1953
- searcher: f
1954
- } = a, m = this._findMatches({
1955
- key: this._keyStore.get(u),
1956
- value: this._myIndex.getValueForItemAtKeyId(l, u),
1957
- searcher: f
1958
- });
1959
- return m && m.length ? [{
1960
- idx: h,
1961
- item: l,
1962
- matches: m
1963
- }] : [];
1964
- }
1965
- const c = [];
1966
- for (let u = 0, f = a.children.length; u < f; u += 1) {
1967
- const m = a.children[u], d = s(m, l, h);
1968
- if (d.length)
1969
- c.push(...d);
1970
- else if (a.operator === Q.AND)
1971
- return [];
1972
- }
1973
- return c;
1974
- }, n = this._myIndex.records, r = {}, o = [];
1975
- return n.forEach(({
1976
- $: a,
1977
- i: l
1978
- }) => {
1979
- if (O(a)) {
1980
- let h = s(t, a, l);
1981
- h.length && (r[l] || (r[l] = {
1982
- idx: l,
1983
- item: a,
1984
- matches: []
1985
- }, o.push(r[l])), h.forEach(({
1986
- matches: c
1987
- }) => {
1988
- r[l].matches.push(...c);
1989
- }));
1990
- }
1991
- }), o;
1992
- }
1993
- _searchObjectList(e) {
1994
- const t = he(e, this.options), {
1995
- keys: s,
1996
- records: n
1997
- } = this._myIndex, r = [];
1998
- return n.forEach(({
1999
- $: o,
2000
- i: a
2001
- }) => {
2002
- if (!O(o))
2003
- return;
2004
- let l = [];
2005
- s.forEach((h, c) => {
2006
- l.push(...this._findMatches({
2007
- key: h,
2008
- value: o[c],
2009
- searcher: t
2010
- }));
2011
- }), l.length && r.push({
2012
- idx: a,
2013
- item: o,
2014
- matches: l
2015
- });
2016
- }), r;
2017
- }
2018
- _findMatches({
2019
- key: e,
2020
- value: t,
2021
- searcher: s
2022
- }) {
2023
- if (!O(t))
2024
- return [];
2025
- let n = [];
2026
- if (P(t))
2027
- t.forEach(({
2028
- v: r,
2029
- i: o,
2030
- n: a
2031
- }) => {
2032
- if (!O(r))
2033
- return;
2034
- const {
2035
- isMatch: l,
2036
- score: h,
2037
- indices: c
2038
- } = s.searchIn(r);
2039
- l && n.push({
2040
- score: h,
2041
- key: e,
2042
- value: r,
2043
- idx: o,
2044
- norm: a,
2045
- indices: c
2046
- });
2047
- });
2048
- else {
2049
- const {
2050
- v: r,
2051
- n: o
2052
- } = t, {
2053
- isMatch: a,
2054
- score: l,
2055
- indices: h
2056
- } = s.searchIn(r);
2057
- a && n.push({
2058
- score: l,
2059
- key: e,
2060
- value: r,
2061
- norm: o,
2062
- indices: h
2063
- });
2064
- }
2065
- return n;
2066
- }
2067
- }
2068
- W.version = "7.0.0";
2069
- W.createIndex = Ge;
2070
- W.parseIndex = Ut;
2071
- W.config = v;
2072
- W.parseQuery = Ye;
2073
- oi(ri);
2074
- var fi = (
2075
- /** @class */
2076
- function() {
2077
- function i(e) {
2078
- this._haystack = [], this._fuseOptions = A(A({}, e.fuseOptions), { keys: ze([], e.searchFields), includeMatches: !0 });
2079
- }
2080
- return i.prototype.index = function(e) {
2081
- this._haystack = e, this._fuse && this._fuse.setCollection(e);
2082
- }, i.prototype.reset = function() {
2083
- this._haystack = [], this._fuse = void 0;
2084
- }, i.prototype.isEmptyIndex = function() {
2085
- return !this._haystack.length;
2086
- }, i.prototype.search = function(e) {
2087
- this._fuse || (this._fuse = new W(this._haystack, this._fuseOptions));
2088
- var t = this._fuse.search(e);
2089
- return t.map(function(s, n) {
2090
- return {
2091
- item: s.item,
2092
- score: s.score || 0,
2093
- rank: n + 1
2094
- // If value.score is used for sorting, this can create non-stable sorts!
2095
- };
2096
- });
2097
- }, i;
2098
- }()
2099
- );
2100
- function pi(i) {
2101
- return new fi(i);
2102
- }
2103
- var mi = function(i) {
2104
- for (var e in i)
2105
- if (Object.prototype.hasOwnProperty.call(i, e))
2106
- return !1;
2107
- return !0;
2108
- }, ne = function(i, e, t) {
2109
- var s = i.dataset, n = e.customProperties, r = e.labelClass, o = e.labelDescription;
2110
- r && (s.labelClass = ee(r).join(" ")), o && (s.labelDescription = o), t && n && (typeof n == "string" ? s.customProperties = n : typeof n == "object" && !mi(n) && (s.customProperties = JSON.stringify(n)));
2111
- }, Ne = function(i, e, t) {
2112
- var s = e && i.querySelector("label[for='".concat(e, "']")), n = s && s.innerText;
2113
- n && t.setAttribute("aria-label", n);
2114
- }, vi = {
2115
- containerOuter: function(i, e, t, s, n, r, o) {
2116
- var a = i.classNames.containerOuter, l = document.createElement("div");
2117
- return _(l, a), l.dataset.type = r, e && (l.dir = e), s && (l.tabIndex = 0), t && (l.setAttribute("role", n ? "combobox" : "listbox"), n ? l.setAttribute("aria-autocomplete", "list") : o || Ne(this._docRoot, this.passedElement.element.id, l), l.setAttribute("aria-haspopup", "true"), l.setAttribute("aria-expanded", "false")), o && l.setAttribute("aria-labelledby", o), l;
2118
- },
2119
- containerInner: function(i) {
2120
- var e = i.classNames.containerInner, t = document.createElement("div");
2121
- return _(t, e), t;
2122
- },
2123
- itemList: function(i, e) {
2124
- var t = i.searchEnabled, s = i.classNames, n = s.list, r = s.listSingle, o = s.listItems, a = document.createElement("div");
2125
- return _(a, n), _(a, e ? r : o), this._isSelectElement && t && a.setAttribute("role", "listbox"), a;
2126
- },
2127
- placeholder: function(i, e) {
2128
- var t = i.allowHTML, s = i.classNames.placeholder, n = document.createElement("div");
2129
- return _(n, s), N(n, t, e), n;
2130
- },
2131
- item: function(i, e, t) {
2132
- var s = i.allowHTML, n = i.removeItemButtonAlignLeft, r = i.removeItemIconText, o = i.removeItemLabelText, a = i.classNames, l = a.item, h = a.button, c = a.highlightedState, u = a.itemSelectable, f = a.placeholder, m = V(e.value), d = document.createElement("div");
2133
- if (_(d, l), e.labelClass) {
2134
- var p = document.createElement("span");
2135
- N(p, s, e.label), _(p, e.labelClass), d.appendChild(p);
2136
- } else
2137
- N(d, s, e.label);
2138
- if (d.dataset.item = "", d.dataset.id = e.id, d.dataset.value = m, ne(d, e, !0), (e.disabled || this.containerOuter.isDisabled) && d.setAttribute("aria-disabled", "true"), this._isSelectElement && (d.setAttribute("aria-selected", "true"), d.setAttribute("role", "option")), e.placeholder && (_(d, f), d.dataset.placeholder = ""), _(d, e.highlighted ? c : u), t) {
2139
- e.disabled && L(d, u), d.dataset.deletable = "";
2140
- var y = document.createElement("button");
2141
- y.type = "button", _(y, h), N(y, !0, q(r, e.value));
2142
- var g = q(o, e.value);
2143
- g && y.setAttribute("aria-label", g), y.dataset.button = "", n ? d.insertAdjacentElement("afterbegin", y) : d.appendChild(y);
2144
- }
2145
- return d;
2146
- },
2147
- choiceList: function(i, e) {
2148
- var t = i.classNames.list, s = document.createElement("div");
2149
- return _(s, t), e || s.setAttribute("aria-multiselectable", "true"), s.setAttribute("role", "listbox"), s;
2150
- },
2151
- choiceGroup: function(i, e) {
2152
- var t = i.allowHTML, s = i.classNames, n = s.group, r = s.groupHeading, o = s.itemDisabled, a = e.id, l = e.label, h = e.disabled, c = V(l), u = document.createElement("div");
2153
- _(u, n), h && _(u, o), u.setAttribute("role", "group"), u.dataset.group = "", u.dataset.id = a, u.dataset.value = c, h && u.setAttribute("aria-disabled", "true");
2154
- var f = document.createElement("div");
2155
- return _(f, r), N(f, t, l || ""), u.appendChild(f), u;
2156
- },
2157
- choice: function(i, e, t, s) {
2158
- var n = i.allowHTML, r = i.classNames, o = r.item, a = r.itemChoice, l = r.itemSelectable, h = r.selectedState, c = r.itemDisabled, u = r.description, f = r.placeholder, m = e.label, d = V(e.value), p = document.createElement("div");
2159
- p.id = e.elementId, _(p, o), _(p, a), s && typeof m == "string" && (m = fe(n, m), m += " (".concat(s, ")"), m = { trusted: m });
2160
- var y = p;
2161
- if (e.labelClass) {
2162
- var g = document.createElement("span");
2163
- N(g, n, m), _(g, e.labelClass), y = g, p.appendChild(g);
2164
- } else
2165
- N(p, n, m);
2166
- if (e.labelDescription) {
2167
- var S = "".concat(e.elementId, "-description");
2168
- y.setAttribute("aria-describedby", S);
2169
- var I = document.createElement("span");
2170
- N(I, n, e.labelDescription), I.id = S, _(I, u), p.appendChild(I);
2171
- }
2172
- return e.selected && _(p, h), e.placeholder && _(p, f), p.setAttribute("role", e.group ? "treeitem" : "option"), p.dataset.choice = "", p.dataset.id = e.id, p.dataset.value = d, t && (p.dataset.selectText = t), e.group && (p.dataset.groupId = "".concat(e.group.id)), ne(p, e, !1), e.disabled ? (_(p, c), p.dataset.choiceDisabled = "", p.setAttribute("aria-disabled", "true")) : (_(p, l), p.dataset.choiceSelectable = ""), p;
2173
- },
2174
- input: function(i, e) {
2175
- var t = i.classNames, s = t.input, n = t.inputCloned, r = i.labelId, o = document.createElement("input");
2176
- return o.type = "search", _(o, s), _(o, n), o.autocomplete = "off", o.autocapitalize = "off", o.spellcheck = !1, o.setAttribute("aria-autocomplete", "list"), e ? o.setAttribute("aria-label", e) : r || Ne(this._docRoot, this.passedElement.element.id, o), o;
2177
- },
2178
- dropdown: function(i) {
2179
- var e = i.classNames, t = e.list, s = e.listDropdown, n = document.createElement("div");
2180
- return _(n, t), _(n, s), n.setAttribute("aria-expanded", "false"), n;
2181
- },
2182
- notice: function(i, e, t) {
2183
- var s = i.classNames, n = s.item, r = s.itemChoice, o = s.addChoice, a = s.noResults, l = s.noChoices, h = s.notice;
2184
- t === void 0 && (t = E.generic);
2185
- var c = document.createElement("div");
2186
- switch (N(c, !0, e), _(c, n), _(c, r), _(c, h), t) {
2187
- case E.addChoice:
2188
- _(c, o);
2189
- break;
2190
- case E.noResults:
2191
- _(c, a);
2192
- break;
2193
- case E.noChoices:
2194
- _(c, l);
2195
- break;
2196
- }
2197
- return t === E.addChoice && (c.dataset.choiceSelectable = "", c.dataset.choice = ""), c;
2198
- },
2199
- option: function(i) {
2200
- var e = V(i.label), t = new Option(e, i.value, !1, i.selected);
2201
- return ne(t, i, !0), t.disabled = i.disabled, i.selected && t.setAttribute("selected", ""), t;
2202
- }
2203
- }, _i = "-ms-scroll-limit" in document.documentElement.style && "-ms-ime-align" in document.documentElement.style, gi = {}, re = function(i) {
2204
- if (i)
2205
- return i.dataset.id ? parseInt(i.dataset.id, 10) : void 0;
2206
- }, $ = "[data-choice-selectable]", bi = (
2207
- /** @class */
2208
- function() {
2209
- function i(e, t) {
2210
- e === void 0 && (e = "[data-choice]"), t === void 0 && (t = {});
2211
- var s = this;
2212
- this.initialisedOK = void 0, this._hasNonChoicePlaceholder = !1, this._lastAddedChoiceId = 0, this._lastAddedGroupId = 0;
2213
- var n = i.defaults;
2214
- this.config = A(A(A({}, n.allOptions), n.options), t), Xe.forEach(function(g) {
2215
- s.config[g] = A(A(A({}, n.allOptions[g]), n.options[g]), t[g]);
2216
- });
2217
- var r = this.config;
2218
- r.silent || this._validateConfig();
2219
- var o = r.shadowRoot || document.documentElement;
2220
- this._docRoot = o;
2221
- var a = typeof e == "string" ? o.querySelector(e) : e;
2222
- if (!a || typeof a != "object" || !(vt(a) || Ke(a)))
2223
- throw TypeError(!a && typeof e == "string" ? "Selector ".concat(e, " failed to find an element") : "Expected one of the following types text|select-one|select-multiple");
2224
- var l = a.type, h = l === R.Text;
2225
- (h || r.maxItemCount !== 1) && (r.singleModeForMultiSelect = !1), r.singleModeForMultiSelect && (l = R.SelectMultiple);
2226
- var c = l === R.SelectOne, u = l === R.SelectMultiple, f = c || u;
2227
- if (this._elementType = l, this._isTextElement = h, this._isSelectOneElement = c, this._isSelectMultipleElement = u, this._isSelectElement = c || u, this._canAddUserChoices = h && r.addItems || f && r.addChoices, typeof r.renderSelectedChoices != "boolean" && (r.renderSelectedChoices = r.renderSelectedChoices === "always" || c), r.closeDropdownOnSelect === "auto" ? r.closeDropdownOnSelect = h || c || r.singleModeForMultiSelect : r.closeDropdownOnSelect = Y(r.closeDropdownOnSelect), r.placeholder && (r.placeholderValue ? this._hasNonChoicePlaceholder = !0 : a.dataset.placeholder && (this._hasNonChoicePlaceholder = !0, r.placeholderValue = a.dataset.placeholder)), t.addItemFilter && typeof t.addItemFilter != "function") {
2228
- var m = t.addItemFilter instanceof RegExp ? t.addItemFilter : new RegExp(t.addItemFilter);
2229
- r.addItemFilter = m.test.bind(m);
2230
- }
2231
- if (this._isTextElement)
2232
- this.passedElement = new mt({
2233
- element: a,
2234
- classNames: r.classNames
2235
- });
2236
- else {
2237
- var d = a;
2238
- this.passedElement = new yt({
2239
- element: d,
2240
- classNames: r.classNames,
2241
- template: function(g) {
2242
- return s._templates.option(g);
2243
- },
2244
- extractPlaceholder: r.placeholder && !this._hasNonChoicePlaceholder
2245
- });
2246
- }
2247
- if (this.initialised = !1, this._store = new It(r), this._currentValue = "", r.searchEnabled = !h && r.searchEnabled || u, this._canSearch = r.searchEnabled, this._isScrollingOnIe = !1, this._highlightPosition = 0, this._wasTap = !0, this._placeholderValue = this._generatePlaceholderValue(), this._baseId = it(a, "choices-"), this._direction = a.dir, !this._direction) {
2248
- var p = window.getComputedStyle(a).direction, y = window.getComputedStyle(document.documentElement).direction;
2249
- p !== y && (this._direction = p);
2250
- }
2251
- if (this._idNames = {
2252
- itemChoice: "item-choice"
2253
- }, this._templates = n.templates, this._render = this._render.bind(this), this._onFocus = this._onFocus.bind(this), this._onBlur = this._onBlur.bind(this), this._onKeyUp = this._onKeyUp.bind(this), this._onKeyDown = this._onKeyDown.bind(this), this._onInput = this._onInput.bind(this), this._onClick = this._onClick.bind(this), this._onTouchMove = this._onTouchMove.bind(this), this._onTouchEnd = this._onTouchEnd.bind(this), this._onMouseDown = this._onMouseDown.bind(this), this._onMouseOver = this._onMouseOver.bind(this), this._onFormReset = this._onFormReset.bind(this), this._onSelectKey = this._onSelectKey.bind(this), this._onEnterKey = this._onEnterKey.bind(this), this._onEscapeKey = this._onEscapeKey.bind(this), this._onDirectionKey = this._onDirectionKey.bind(this), this._onDeleteKey = this._onDeleteKey.bind(this), this.passedElement.isActive) {
2254
- r.silent || console.warn("Trying to initialise Choices on element already initialised", { element: e }), this.initialised = !0, this.initialisedOK = !1;
2255
- return;
2256
- }
2257
- this.init(), this._initialItems = this._store.items.map(function(g) {
2258
- return g.value;
2259
- });
2260
- }
2261
- return Object.defineProperty(i, "defaults", {
2262
- get: function() {
2263
- return Object.preventExtensions({
2264
- get options() {
2265
- return gi;
2266
- },
2267
- get allOptions() {
2268
- return Ie;
2269
- },
2270
- get templates() {
2271
- return vi;
2272
- }
2273
- });
2274
- },
2275
- enumerable: !1,
2276
- configurable: !0
2277
- }), i.prototype.init = function() {
2278
- if (!(this.initialised || this.initialisedOK !== void 0)) {
2279
- this._searcher = pi(this.config), this._loadChoices(), this._createTemplates(), this._createElements(), this._createStructure(), this._isTextElement && !this.config.addItems || this.passedElement.element.hasAttribute("disabled") || this.passedElement.element.closest("fieldset:disabled") ? this.disable() : (this.enable(), this._addEventListeners()), this._initStore(), this.initialised = !0, this.initialisedOK = !0;
2280
- var e = this.config.callbackOnInit;
2281
- typeof e == "function" && e.call(this);
2282
- }
2283
- }, i.prototype.destroy = function() {
2284
- this.initialised && (this._removeEventListeners(), this.passedElement.reveal(), this.containerOuter.unwrap(this.passedElement.element), this._store._listeners = [], this.clearStore(!1), this._stopSearch(), this._templates = i.defaults.templates, this.initialised = !1, this.initialisedOK = void 0);
2285
- }, i.prototype.enable = function() {
2286
- return this.passedElement.isDisabled && this.passedElement.enable(), this.containerOuter.isDisabled && (this._addEventListeners(), this.input.enable(), this.containerOuter.enable()), this;
2287
- }, i.prototype.disable = function() {
2288
- return this.passedElement.isDisabled || this.passedElement.disable(), this.containerOuter.isDisabled || (this._removeEventListeners(), this.input.disable(), this.containerOuter.disable()), this;
2289
- }, i.prototype.highlightItem = function(e, t) {
2290
- if (t === void 0 && (t = !0), !e || !e.id)
2291
- return this;
2292
- var s = this._store.items.find(function(n) {
2293
- return n.id === e.id;
2294
- });
2295
- return !s || s.highlighted ? this : (this._store.dispatch(X(s, !0)), t && this.passedElement.triggerEvent(w.highlightItem, this._getChoiceForOutput(s)), this);
2296
- }, i.prototype.unhighlightItem = function(e, t) {
2297
- if (t === void 0 && (t = !0), !e || !e.id)
2298
- return this;
2299
- var s = this._store.items.find(function(n) {
2300
- return n.id === e.id;
2301
- });
2302
- return !s || !s.highlighted ? this : (this._store.dispatch(X(s, !1)), t && this.passedElement.triggerEvent(w.unhighlightItem, this._getChoiceForOutput(s)), this);
2303
- }, i.prototype.highlightAll = function() {
2304
- var e = this;
2305
- return this._store.withTxn(function() {
2306
- e._store.items.forEach(function(t) {
2307
- t.highlighted || (e._store.dispatch(X(t, !0)), e.passedElement.triggerEvent(w.highlightItem, e._getChoiceForOutput(t)));
2308
- });
2309
- }), this;
2310
- }, i.prototype.unhighlightAll = function() {
2311
- var e = this;
2312
- return this._store.withTxn(function() {
2313
- e._store.items.forEach(function(t) {
2314
- t.highlighted && (e._store.dispatch(X(t, !1)), e.passedElement.triggerEvent(w.highlightItem, e._getChoiceForOutput(t)));
2315
- });
2316
- }), this;
2317
- }, i.prototype.removeActiveItemsByValue = function(e) {
2318
- var t = this;
2319
- return this._store.withTxn(function() {
2320
- t._store.items.filter(function(s) {
2321
- return s.value === e;
2322
- }).forEach(function(s) {
2323
- return t._removeItem(s);
2324
- });
2325
- }), this;
2326
- }, i.prototype.removeActiveItems = function(e) {
2327
- var t = this;
2328
- return this._store.withTxn(function() {
2329
- t._store.items.filter(function(s) {
2330
- var n = s.id;
2331
- return n !== e;
2332
- }).forEach(function(s) {
2333
- return t._removeItem(s);
2334
- });
2335
- }), this;
2336
- }, i.prototype.removeHighlightedItems = function(e) {
2337
- var t = this;
2338
- return e === void 0 && (e = !1), this._store.withTxn(function() {
2339
- t._store.highlightedActiveItems.forEach(function(s) {
2340
- t._removeItem(s), e && t._triggerChange(s.value);
2341
- });
2342
- }), this;
2343
- }, i.prototype.showDropdown = function(e) {
2344
- var t = this;
2345
- return this.dropdown.isActive ? this : (e === void 0 && (e = !this._canSearch), requestAnimationFrame(function() {
2346
- t.dropdown.show();
2347
- var s = t.dropdown.element.getBoundingClientRect();
2348
- t.containerOuter.open(s.bottom, s.height), e || t.input.focus(), t.passedElement.triggerEvent(w.showDropdown);
2349
- }), this);
2350
- }, i.prototype.hideDropdown = function(e) {
2351
- var t = this;
2352
- return this.dropdown.isActive ? (requestAnimationFrame(function() {
2353
- t.dropdown.hide(), t.containerOuter.close(), !e && t._canSearch && (t.input.removeActiveDescendant(), t.input.blur()), t.passedElement.triggerEvent(w.hideDropdown);
2354
- }), this) : this;
2355
- }, i.prototype.getValue = function(e) {
2356
- var t = this, s = this._store.items.map(function(n) {
2357
- return e ? n.value : t._getChoiceForOutput(n);
2358
- });
2359
- return this._isSelectOneElement || this.config.singleModeForMultiSelect ? s[0] : s;
2360
- }, i.prototype.setValue = function(e) {
2361
- var t = this;
2362
- return this.initialisedOK ? (this._store.withTxn(function() {
2363
- e.forEach(function(s) {
2364
- s && t._addChoice(M(s, !1));
2365
- });
2366
- }), this._searcher.reset(), this) : (this._warnChoicesInitFailed("setValue"), this);
2367
- }, i.prototype.setChoiceByValue = function(e) {
2368
- var t = this;
2369
- return this.initialisedOK ? this._isTextElement ? this : (this._store.withTxn(function() {
2370
- var s = Array.isArray(e) ? e : [e];
2371
- s.forEach(function(n) {
2372
- return t._findAndSelectChoiceByValue(n);
2373
- }), t.unhighlightAll();
2374
- }), this._searcher.reset(), this) : (this._warnChoicesInitFailed("setChoiceByValue"), this);
2375
- }, i.prototype.setChoices = function(e, t, s, n, r, o) {
2376
- var a = this;
2377
- if (e === void 0 && (e = []), t === void 0 && (t = "value"), s === void 0 && (s = "label"), n === void 0 && (n = !1), r === void 0 && (r = !0), o === void 0 && (o = !1), !this.initialisedOK)
2378
- return this._warnChoicesInitFailed("setChoices"), this;
2379
- if (!this._isSelectElement)
2380
- throw new TypeError("setChoices can't be used with INPUT based Choices");
2381
- if (typeof t != "string" || !t)
2382
- throw new TypeError("value parameter must be a name of 'value' field in passed objects");
2383
- if (typeof e == "function") {
2384
- var l = e(this);
2385
- if (typeof Promise == "function" && l instanceof Promise)
2386
- return new Promise(function(h) {
2387
- return requestAnimationFrame(h);
2388
- }).then(function() {
2389
- return a._handleLoadingState(!0);
2390
- }).then(function() {
2391
- return l;
2392
- }).then(function(h) {
2393
- return a.setChoices(h, t, s, n, r, o);
2394
- }).catch(function(h) {
2395
- a.config.silent || console.error(h);
2396
- }).then(function() {
2397
- return a._handleLoadingState(!1);
2398
- }).then(function() {
2399
- return a;
2400
- });
2401
- if (!Array.isArray(l))
2402
- throw new TypeError(".setChoices first argument function must return either array of choices or Promise, got: ".concat(typeof l));
2403
- return this.setChoices(l, t, s, !1);
2404
- }
2405
- if (!Array.isArray(e))
2406
- throw new TypeError(".setChoices must be called either with array of choices with a function resulting into Promise of array of choices");
2407
- return this.containerOuter.removeLoadingState(), this._store.withTxn(function() {
2408
- r && (a._isSearching = !1), n && a.clearChoices(!0, o);
2409
- var h = t === "value", c = s === "label";
2410
- e.forEach(function(u) {
2411
- if ("choices" in u) {
2412
- var f = u;
2413
- c || (f = A(A({}, f), { label: f[s] })), a._addGroup(M(f, !0));
2414
- } else {
2415
- var m = u;
2416
- (!c || !h) && (m = A(A({}, m), { value: m[t], label: m[s] }));
2417
- var d = M(m, !1);
2418
- a._addChoice(d), d.placeholder && !a._hasNonChoicePlaceholder && (a._placeholderValue = Fe(d.label));
2419
- }
2420
- }), a.unhighlightAll();
2421
- }), this._searcher.reset(), this;
2422
- }, i.prototype.refresh = function(e, t, s) {
2423
- var n = this;
2424
- return e === void 0 && (e = !1), t === void 0 && (t = !1), s === void 0 && (s = !1), this._isSelectElement ? (this._store.withTxn(function() {
2425
- var r = n.passedElement.optionsAsChoices(), o = {};
2426
- s || n._store.items.forEach(function(l) {
2427
- l.id && l.active && l.selected && (o[l.value] = !0);
2428
- }), n.clearStore(!1);
2429
- var a = function(l) {
2430
- s ? n._store.dispatch(ye(l)) : o[l.value] && (l.selected = !0);
2431
- };
2432
- r.forEach(function(l) {
2433
- if ("choices" in l) {
2434
- l.choices.forEach(a);
2435
- return;
2436
- }
2437
- a(l);
2438
- }), n._addPredefinedChoices(r, t, e), n._isSearching && n._searchChoices(n.input.value);
2439
- }), this) : (this.config.silent || console.warn("refresh method can only be used on choices backed by a <select> element"), this);
2440
- }, i.prototype.removeChoice = function(e) {
2441
- var t = this._store.choices.find(function(s) {
2442
- return s.value === e;
2443
- });
2444
- return t ? (this._clearNotice(), this._store.dispatch(Je(t)), this._searcher.reset(), t.selected && this.passedElement.triggerEvent(w.removeItem, this._getChoiceForOutput(t)), this) : this;
2445
- }, i.prototype.clearChoices = function(e, t) {
2446
- var s = this;
2447
- return e === void 0 && (e = !0), t === void 0 && (t = !1), e && (t ? this.passedElement.element.replaceChildren("") : this.passedElement.element.querySelectorAll(":not([selected])").forEach(function(n) {
2448
- n.remove();
2449
- })), this.itemList.element.replaceChildren(""), this.choiceList.element.replaceChildren(""), this._clearNotice(), this._store.withTxn(function() {
2450
- var n = t ? [] : s._store.items;
2451
- s._store.reset(), n.forEach(function(r) {
2452
- s._store.dispatch(_e(r)), s._store.dispatch(ge(r));
2453
- });
2454
- }), this._searcher.reset(), this;
2455
- }, i.prototype.clearStore = function(e) {
2456
- return e === void 0 && (e = !0), this.clearChoices(e, !0), this._stopSearch(), this._lastAddedChoiceId = 0, this._lastAddedGroupId = 0, this;
2457
- }, i.prototype.clearInput = function() {
2458
- var e = !this._isSelectOneElement;
2459
- return this.input.clear(e), this._stopSearch(), this;
2460
- }, i.prototype._validateConfig = function() {
2461
- var e = this.config, t = ct(e, Ie);
2462
- t.length && console.warn("Unknown config option(s) passed", t.join(", ")), e.allowHTML && e.allowHtmlUserInput && (e.addItems && console.warn("Warning: allowHTML/allowHtmlUserInput/addItems all being true is strongly not recommended and may lead to XSS attacks"), e.addChoices && console.warn("Warning: allowHTML/allowHtmlUserInput/addChoices all being true is strongly not recommended and may lead to XSS attacks"));
2463
- }, i.prototype._render = function(e) {
2464
- e === void 0 && (e = { choices: !0, groups: !0, items: !0 }), !this._store.inTxn() && (this._isSelectElement && (e.choices || e.groups) && this._renderChoices(), e.items && this._renderItems());
2465
- }, i.prototype._renderChoices = function() {
2466
- var e = this;
2467
- if (this._canAddItems()) {
2468
- var t = this, s = t.config, n = t._isSearching, r = this._store, o = r.activeGroups, a = r.activeChoices, l = 0;
2469
- if (n && s.searchResultLimit > 0 ? l = s.searchResultLimit : s.renderChoiceLimit > 0 && (l = s.renderChoiceLimit), this._isSelectElement) {
2470
- var h = a.filter(function(d) {
2471
- return !d.element;
2472
- });
2473
- h.length && this.passedElement.addOptions(h);
2474
- }
2475
- var c = document.createDocumentFragment(), u = function(d) {
2476
- return d.filter(function(p) {
2477
- return !p.placeholder && (n ? !!p.rank : s.renderSelectedChoices || !p.selected);
2478
- });
2479
- }, f = !1, m = function(d, p, y) {
2480
- n ? d.sort(at) : s.shouldSort && d.sort(s.sorter);
2481
- var g = d.length;
2482
- g = !p && l && g > l ? l : g, g--, d.every(function(S, I) {
2483
- var H = S.choiceEl || e._templates.choice(s, S, s.itemSelectText, y);
2484
- return S.choiceEl = H, c.appendChild(H), (n || !S.selected) && (f = !0), I < g;
2485
- });
2486
- };
2487
- a.length && (s.resetScrollPosition && requestAnimationFrame(function() {
2488
- return e.choiceList.scrollToTop();
2489
- }), !this._hasNonChoicePlaceholder && !n && this._isSelectOneElement && m(a.filter(function(d) {
2490
- return d.placeholder && !d.group;
2491
- }), !1, void 0), o.length && !n ? (s.shouldSort && o.sort(s.sorter), m(a.filter(function(d) {
2492
- return !d.placeholder && !d.group;
2493
- }), !1, void 0), o.forEach(function(d) {
2494
- var p = u(d.choices);
2495
- if (p.length) {
2496
- if (d.label) {
2497
- var y = d.groupEl || e._templates.choiceGroup(e.config, d);
2498
- d.groupEl = y, y.remove(), c.appendChild(y);
2499
- }
2500
- m(p, !0, s.appendGroupInSearch && n ? d.label : void 0);
2501
- }
2502
- })) : m(u(a), !1, void 0)), !f && (n || !c.children.length || !s.renderSelectedChoices) && (this._notice || (this._notice = {
2503
- text: Ee(n ? s.noResultsText : s.noChoicesText),
2504
- type: n ? E.noResults : E.noChoices
2505
- }), c.replaceChildren("")), this._renderNotice(c), this.choiceList.element.replaceChildren(c), f && this._highlightChoice();
2506
- }
2507
- }, i.prototype._renderItems = function() {
2508
- var e = this, t = this._store.items || [], s = this.itemList.element, n = this.config, r = document.createDocumentFragment(), o = function(u) {
2509
- return s.querySelector('[data-item][data-id="'.concat(u.id, '"]'));
2510
- }, a = function(u) {
2511
- var f = u.itemEl;
2512
- f && f.parentElement || (f = o(u) || e._templates.item(n, u, n.removeItemButton), u.itemEl = f, r.appendChild(f));
2513
- };
2514
- t.forEach(a);
2515
- var l = !!r.childNodes.length;
2516
- if (this._isSelectOneElement) {
2517
- var h = s.children.length;
2518
- if (l || h > 1) {
2519
- var c = s.querySelector(U(n.classNames.placeholder));
2520
- c && c.remove();
2521
- } else !l && !h && this._placeholderValue && (l = !0, a(M({
2522
- selected: !0,
2523
- value: "",
2524
- label: this._placeholderValue,
2525
- placeholder: !0
2526
- }, !1)));
2527
- }
2528
- l && (s.append(r), n.shouldSortItems && !this._isSelectOneElement && (t.sort(n.sorter), t.forEach(function(u) {
2529
- var f = o(u);
2530
- f && (f.remove(), r.append(f));
2531
- }), s.append(r))), this._isTextElement && (this.passedElement.value = t.map(function(u) {
2532
- var f = u.value;
2533
- return f;
2534
- }).join(n.delimiter));
2535
- }, i.prototype._displayNotice = function(e, t, s) {
2536
- s === void 0 && (s = !0);
2537
- var n = this._notice;
2538
- if (n && (n.type === t && n.text === e || n.type === E.addChoice && (t === E.noResults || t === E.noChoices))) {
2539
- s && this.showDropdown(!0);
2540
- return;
2541
- }
2542
- this._clearNotice(), this._notice = e ? {
2543
- text: e,
2544
- type: t
2545
- } : void 0, this._renderNotice(), s && e && this.showDropdown(!0);
2546
- }, i.prototype._clearNotice = function() {
2547
- if (this._notice) {
2548
- var e = this.choiceList.element.querySelector(U(this.config.classNames.notice));
2549
- e && e.remove(), this._notice = void 0;
2550
- }
2551
- }, i.prototype._renderNotice = function(e) {
2552
- var t = this._notice;
2553
- if (t) {
2554
- var s = this._templates.notice(this.config, t.text, t.type);
2555
- e ? e.append(s) : this.choiceList.prepend(s);
2556
- }
2557
- }, i.prototype._getChoiceForOutput = function(e, t) {
2558
- return {
2559
- id: e.id,
2560
- highlighted: e.highlighted,
2561
- labelClass: e.labelClass,
2562
- labelDescription: e.labelDescription,
2563
- customProperties: e.customProperties,
2564
- disabled: e.disabled,
2565
- active: e.active,
2566
- label: e.label,
2567
- placeholder: e.placeholder,
2568
- value: e.value,
2569
- groupValue: e.group ? e.group.label : void 0,
2570
- element: e.element,
2571
- keyCode: t
2572
- };
2573
- }, i.prototype._triggerChange = function(e) {
2574
- e != null && this.passedElement.triggerEvent(w.change, {
2575
- value: e
2576
- });
2577
- }, i.prototype._handleButtonAction = function(e) {
2578
- var t = this, s = this._store.items;
2579
- if (!(!s.length || !this.config.removeItems || !this.config.removeItemButton)) {
2580
- var n = e && re(e.parentElement), r = n && s.find(function(o) {
2581
- return o.id === n;
2582
- });
2583
- r && this._store.withTxn(function() {
2584
- if (t._removeItem(r), t._triggerChange(r.value), t._isSelectOneElement && !t._hasNonChoicePlaceholder) {
2585
- var o = (t.config.shouldSort ? t._store.choices.reverse() : t._store.choices).find(function(a) {
2586
- return a.placeholder;
2587
- });
2588
- o && (t._addItem(o), t.unhighlightAll(), o.value && t._triggerChange(o.value));
2589
- }
2590
- });
2591
- }
2592
- }, i.prototype._handleItemAction = function(e, t) {
2593
- var s = this;
2594
- t === void 0 && (t = !1);
2595
- var n = this._store.items;
2596
- if (!(!n.length || !this.config.removeItems || this._isSelectOneElement)) {
2597
- var r = re(e);
2598
- r && (n.forEach(function(o) {
2599
- o.id === r && !o.highlighted ? s.highlightItem(o) : !t && o.highlighted && s.unhighlightItem(o);
2600
- }), this.input.focus());
2601
- }
2602
- }, i.prototype._handleChoiceAction = function(e) {
2603
- var t = this, s = re(e), n = s && this._store.getChoiceById(s);
2604
- if (!n || n.disabled)
2605
- return !1;
2606
- var r = this.dropdown.isActive;
2607
- if (!n.selected) {
2608
- if (!this._canAddItems())
2609
- return !0;
2610
- this._store.withTxn(function() {
2611
- t._addItem(n, !0, !0), t.clearInput(), t.unhighlightAll();
2612
- }), this._triggerChange(n.value);
2613
- }
2614
- return r && this.config.closeDropdownOnSelect && (this.hideDropdown(!0), this.containerOuter.element.focus()), !0;
2615
- }, i.prototype._handleBackspace = function(e) {
2616
- var t = this.config;
2617
- if (!(!t.removeItems || !e.length)) {
2618
- var s = e[e.length - 1], n = e.some(function(r) {
2619
- return r.highlighted;
2620
- });
2621
- t.editItems && !n && s ? (this.input.value = s.value, this.input.setWidth(), this._removeItem(s), this._triggerChange(s.value)) : (n || this.highlightItem(s, !1), this.removeHighlightedItems(!0));
2622
- }
2623
- }, i.prototype._loadChoices = function() {
2624
- var e, t = this, s = this.config;
2625
- if (this._isTextElement) {
2626
- if (this._presetChoices = s.items.map(function(o) {
2627
- return M(o, !1);
2628
- }), this.passedElement.value) {
2629
- var n = this.passedElement.value.split(s.delimiter).map(function(o) {
2630
- return M(o, !1, t.config.allowHtmlUserInput);
2631
- });
2632
- this._presetChoices = this._presetChoices.concat(n);
2633
- }
2634
- this._presetChoices.forEach(function(o) {
2635
- o.selected = !0;
2636
- });
2637
- } else if (this._isSelectElement) {
2638
- this._presetChoices = s.choices.map(function(o) {
2639
- return M(o, !0);
2640
- });
2641
- var r = this.passedElement.optionsAsChoices();
2642
- r && (e = this._presetChoices).push.apply(e, r);
2643
- }
2644
- }, i.prototype._handleLoadingState = function(e) {
2645
- e === void 0 && (e = !0);
2646
- var t = this.itemList.element;
2647
- e ? (this.disable(), this.containerOuter.addLoadingState(), this._isSelectOneElement ? t.replaceChildren(this._templates.placeholder(this.config, this.config.loadingText)) : this.input.placeholder = this.config.loadingText) : (this.enable(), this.containerOuter.removeLoadingState(), this._isSelectOneElement ? (t.replaceChildren(""), this._render()) : this.input.placeholder = this._placeholderValue || "");
2648
- }, i.prototype._handleSearch = function(e) {
2649
- if (this.input.isFocussed)
2650
- if (e !== null && typeof e < "u" && e.length >= this.config.searchFloor) {
2651
- var t = this.config.searchChoices ? this._searchChoices(e) : 0;
2652
- t !== null && this.passedElement.triggerEvent(w.search, {
2653
- value: e,
2654
- resultCount: t
2655
- });
2656
- } else this._store.choices.some(function(s) {
2657
- return !s.active;
2658
- }) && this._stopSearch();
2659
- }, i.prototype._canAddItems = function() {
2660
- var e = this.config, t = e.maxItemCount, s = e.maxItemText;
2661
- return !e.singleModeForMultiSelect && t > 0 && t <= this._store.items.length ? (this.choiceList.element.replaceChildren(""), this._notice = void 0, this._displayNotice(typeof s == "function" ? s(t) : s, E.addChoice), !1) : (this._notice && this._notice.type === E.addChoice && this._clearNotice(), !0);
2662
- }, i.prototype._canCreateItem = function(e) {
2663
- var t = this.config, s = !0, n = "";
2664
- if (s && typeof t.addItemFilter == "function" && !t.addItemFilter(e) && (s = !1, n = q(t.customAddItemText, e)), s) {
2665
- var r = this._store.choices.find(function(o) {
2666
- return t.valueComparer(o.value, e);
2667
- });
2668
- if (r) {
2669
- if (this._isSelectElement)
2670
- return this._displayNotice("", E.addChoice), !1;
2671
- t.duplicateItemsAllowed || (s = !1, n = q(t.uniqueItemText, e));
2672
- }
2673
- }
2674
- return s && (n = q(t.addItemText, e)), n && this._displayNotice(n, E.addChoice), s;
2675
- }, i.prototype._searchChoices = function(e) {
2676
- var t = e.trim().replace(/\s{2,}/, " ");
2677
- if (!t.length || t === this._currentValue)
2678
- return null;
2679
- var s = this._searcher;
2680
- s.isEmptyIndex() && s.index(this._store.searchableChoices);
2681
- var n = s.search(t);
2682
- this._currentValue = t, this._highlightPosition = 0, this._isSearching = !0;
2683
- var r = this._notice, o = r && r.type;
2684
- return o !== E.addChoice && (n.length ? this._clearNotice() : this._displayNotice(Ee(this.config.noResultsText), E.noResults)), this._store.dispatch(Qe(n)), n.length;
2685
- }, i.prototype._stopSearch = function() {
2686
- this._isSearching && (this._currentValue = "", this._isSearching = !1, this._clearNotice(), this._store.dispatch(Ze(!0)), this.passedElement.triggerEvent(w.search, {
2687
- value: "",
2688
- resultCount: 0
2689
- }));
2690
- }, i.prototype._addEventListeners = function() {
2691
- var e = this._docRoot, t = this.containerOuter.element, s = this.input.element;
2692
- e.addEventListener("touchend", this._onTouchEnd, !0), t.addEventListener("keydown", this._onKeyDown, !0), t.addEventListener("mousedown", this._onMouseDown, !0), e.addEventListener("click", this._onClick, { passive: !0 }), e.addEventListener("touchmove", this._onTouchMove, {
2693
- passive: !0
2694
- }), this.dropdown.element.addEventListener("mouseover", this._onMouseOver, {
2695
- passive: !0
2696
- }), this._isSelectOneElement && (t.addEventListener("focus", this._onFocus, {
2697
- passive: !0
2698
- }), t.addEventListener("blur", this._onBlur, {
2699
- passive: !0
2700
- })), s.addEventListener("keyup", this._onKeyUp, {
2701
- passive: !0
2702
- }), s.addEventListener("input", this._onInput, {
2703
- passive: !0
2704
- }), s.addEventListener("focus", this._onFocus, {
2705
- passive: !0
2706
- }), s.addEventListener("blur", this._onBlur, {
2707
- passive: !0
2708
- }), s.form && s.form.addEventListener("reset", this._onFormReset, {
2709
- passive: !0
2710
- }), this.input.addEventListeners();
2711
- }, i.prototype._removeEventListeners = function() {
2712
- var e = this._docRoot, t = this.containerOuter.element, s = this.input.element;
2713
- e.removeEventListener("touchend", this._onTouchEnd, !0), t.removeEventListener("keydown", this._onKeyDown, !0), t.removeEventListener("mousedown", this._onMouseDown, !0), e.removeEventListener("click", this._onClick), e.removeEventListener("touchmove", this._onTouchMove), this.dropdown.element.removeEventListener("mouseover", this._onMouseOver), this._isSelectOneElement && (t.removeEventListener("focus", this._onFocus), t.removeEventListener("blur", this._onBlur)), s.removeEventListener("keyup", this._onKeyUp), s.removeEventListener("input", this._onInput), s.removeEventListener("focus", this._onFocus), s.removeEventListener("blur", this._onBlur), s.form && s.form.removeEventListener("reset", this._onFormReset), this.input.removeEventListeners();
2714
- }, i.prototype._onKeyDown = function(e) {
2715
- var t = e.keyCode, s = this.dropdown.isActive, n = e.key.length === 1 || e.key.length === 2 && e.key.charCodeAt(0) >= 55296 || e.key === "Unidentified";
2716
- switch (!this._isTextElement && !s && t !== C.ESC_KEY && t !== C.TAB_KEY && t !== C.SHIFT_KEY && (this.showDropdown(), !this.input.isFocussed && n && (this.input.value += e.key, e.key === " " && e.preventDefault())), t) {
2717
- case C.A_KEY:
2718
- return this._onSelectKey(e, this.itemList.element.hasChildNodes());
2719
- case C.ENTER_KEY:
2720
- return this._onEnterKey(e, s);
2721
- case C.ESC_KEY:
2722
- return this._onEscapeKey(e, s);
2723
- case C.UP_KEY:
2724
- case C.PAGE_UP_KEY:
2725
- case C.DOWN_KEY:
2726
- case C.PAGE_DOWN_KEY:
2727
- return this._onDirectionKey(e, s);
2728
- case C.DELETE_KEY:
2729
- case C.BACK_KEY:
2730
- return this._onDeleteKey(e, this._store.items, this.input.isFocussed);
2731
- }
2732
- }, i.prototype._onKeyUp = function() {
2733
- this._canSearch = this.config.searchEnabled;
2734
- }, i.prototype._onInput = function() {
2735
- var e = this.input.value;
2736
- if (!e) {
2737
- this._isTextElement ? this.hideDropdown(!0) : this._stopSearch();
2738
- return;
2739
- }
2740
- this._canAddItems() && (this._canSearch && this._handleSearch(e), this._canAddUserChoices && (this._canCreateItem(e), this._isSelectElement && (this._highlightPosition = 0, this._highlightChoice())));
2741
- }, i.prototype._onSelectKey = function(e, t) {
2742
- if ((e.ctrlKey || e.metaKey) && t) {
2743
- this._canSearch = !1;
2744
- var s = this.config.removeItems && !this.input.value && this.input.element === document.activeElement;
2745
- s && this.highlightAll();
2746
- }
2747
- }, i.prototype._onEnterKey = function(e, t) {
2748
- var s = this, n = this.input.value, r = e.target;
2749
- if (e.preventDefault(), r && r.hasAttribute("data-button")) {
2750
- this._handleButtonAction(r);
2751
- return;
2752
- }
2753
- if (!t) {
2754
- (this._isSelectElement || this._notice) && this.showDropdown();
2755
- return;
2756
- }
2757
- var o = this.dropdown.element.querySelector(U(this.config.classNames.highlightedState));
2758
- if (!(o && this._handleChoiceAction(o))) {
2759
- if (!r || !n) {
2760
- this.hideDropdown(!0);
2761
- return;
2762
- }
2763
- if (this._canAddItems()) {
2764
- var a = !1;
2765
- this._store.withTxn(function() {
2766
- if (a = s._findAndSelectChoiceByValue(n, !0), !a) {
2767
- if (!s._canAddUserChoices || !s._canCreateItem(n))
2768
- return;
2769
- s._addChoice(M(n, !1, s.config.allowHtmlUserInput), !0, !0), a = !0;
2770
- }
2771
- s.clearInput(), s.unhighlightAll();
2772
- }), a && (this._triggerChange(n), this.config.closeDropdownOnSelect && this.hideDropdown(!0));
2773
- }
2774
- }
2775
- }, i.prototype._onEscapeKey = function(e, t) {
2776
- t && (e.stopPropagation(), this.hideDropdown(!0), this._stopSearch(), this.containerOuter.element.focus());
2777
- }, i.prototype._onDirectionKey = function(e, t) {
2778
- var s = e.keyCode;
2779
- if (t || this._isSelectOneElement) {
2780
- this.showDropdown(), this._canSearch = !1;
2781
- var n = s === C.DOWN_KEY || s === C.PAGE_DOWN_KEY ? 1 : -1, r = e.metaKey || s === C.PAGE_DOWN_KEY || s === C.PAGE_UP_KEY, o = void 0;
2782
- if (r)
2783
- n > 0 ? o = this.dropdown.element.querySelector("".concat($, ":last-of-type")) : o = this.dropdown.element.querySelector($);
2784
- else {
2785
- var a = this.dropdown.element.querySelector(U(this.config.classNames.highlightedState));
2786
- a ? o = st(a, $, n) : o = this.dropdown.element.querySelector($);
2787
- }
2788
- o && (nt(o, this.choiceList.element, n) || this.choiceList.scrollToChildElement(o, n), this._highlightChoice(o)), e.preventDefault();
2789
- }
2790
- }, i.prototype._onDeleteKey = function(e, t, s) {
2791
- !this._isSelectOneElement && !e.target.value && s && (this._handleBackspace(t), e.preventDefault());
2792
- }, i.prototype._onTouchMove = function() {
2793
- this._wasTap && (this._wasTap = !1);
2794
- }, i.prototype._onTouchEnd = function(e) {
2795
- var t = (e || e.touches[0]).target, s = this._wasTap && this.containerOuter.element.contains(t);
2796
- if (s) {
2797
- var n = t === this.containerOuter.element || t === this.containerInner.element;
2798
- n && (this._isTextElement ? this.input.focus() : this._isSelectMultipleElement && this.showDropdown()), e.stopPropagation();
2799
- }
2800
- this._wasTap = !0;
2801
- }, i.prototype._onMouseDown = function(e) {
2802
- var t = e.target;
2803
- if (t instanceof HTMLElement) {
2804
- if (_i && this.choiceList.element.contains(t)) {
2805
- var s = this.choiceList.element.firstElementChild;
2806
- this._isScrollingOnIe = this._direction === "ltr" ? e.offsetX >= s.offsetWidth : e.offsetX < s.offsetLeft;
2807
- }
2808
- if (t !== this.input.element) {
2809
- var n = t.closest("[data-button],[data-item],[data-choice]");
2810
- n instanceof HTMLElement && ("button" in n.dataset ? this._handleButtonAction(n) : "item" in n.dataset ? this._handleItemAction(n, e.shiftKey) : "choice" in n.dataset && this._handleChoiceAction(n)), e.preventDefault();
2811
- }
2812
- }
2813
- }, i.prototype._onMouseOver = function(e) {
2814
- var t = e.target;
2815
- t instanceof HTMLElement && "choice" in t.dataset && this._highlightChoice(t);
2816
- }, i.prototype._onClick = function(e) {
2817
- var t = e.target, s = this.containerOuter, n = s.element.contains(t);
2818
- n ? !this.dropdown.isActive && !s.isDisabled ? this._isTextElement ? document.activeElement !== this.input.element && this.input.focus() : (this.showDropdown(), s.element.focus()) : this._isSelectOneElement && t !== this.input.element && !this.dropdown.element.contains(t) && this.hideDropdown() : (s.removeFocusState(), this.hideDropdown(!0), this.unhighlightAll());
2819
- }, i.prototype._onFocus = function(e) {
2820
- var t = e.target, s = this.containerOuter, n = t && s.element.contains(t);
2821
- if (n) {
2822
- var r = t === this.input.element;
2823
- this._isTextElement ? r && s.addFocusState() : this._isSelectMultipleElement ? r && (this.showDropdown(!0), s.addFocusState()) : (s.addFocusState(), r && this.showDropdown(!0));
2824
- }
2825
- }, i.prototype._onBlur = function(e) {
2826
- var t = e.target, s = this.containerOuter, n = t && s.element.contains(t);
2827
- n && !this._isScrollingOnIe ? t === this.input.element ? (s.removeFocusState(), this.hideDropdown(!0), (this._isTextElement || this._isSelectMultipleElement) && this.unhighlightAll()) : t === this.containerOuter.element && (s.removeFocusState(), this._canSearch || this.hideDropdown(!0)) : (this._isScrollingOnIe = !1, this.input.element.focus());
2828
- }, i.prototype._onFormReset = function() {
2829
- var e = this;
2830
- this._store.withTxn(function() {
2831
- e.clearInput(), e.hideDropdown(), e.refresh(!1, !1, !0), e._initialItems.length && e.setChoiceByValue(e._initialItems);
2832
- });
2833
- }, i.prototype._highlightChoice = function(e) {
2834
- e === void 0 && (e = null);
2835
- var t = Array.from(this.dropdown.element.querySelectorAll($));
2836
- if (t.length) {
2837
- var s = e, n = this.config.classNames.highlightedState, r = Array.from(this.dropdown.element.querySelectorAll(U(n)));
2838
- r.forEach(function(o) {
2839
- L(o, n), o.setAttribute("aria-selected", "false");
2840
- }), s ? this._highlightPosition = t.indexOf(s) : (t.length > this._highlightPosition ? s = t[this._highlightPosition] : s = t[t.length - 1], s || (s = t[0])), _(s, n), s.setAttribute("aria-selected", "true"), this.passedElement.triggerEvent(w.highlightChoice, {
2841
- el: s
2842
- }), this.dropdown.isActive && (this.input.setActiveDescendant(s.id), this.containerOuter.setActiveDescendant(s.id));
2843
- }
2844
- }, i.prototype._addItem = function(e, t, s) {
2845
- if (t === void 0 && (t = !0), s === void 0 && (s = !1), !e.id)
2846
- throw new TypeError("item.id must be set before _addItem is called for a choice/item");
2847
- (this.config.singleModeForMultiSelect || this._isSelectOneElement) && this.removeActiveItems(e.id), this._store.dispatch(ge(e)), t && (this.passedElement.triggerEvent(w.addItem, this._getChoiceForOutput(e)), s && this.passedElement.triggerEvent(w.choice, this._getChoiceForOutput(e)));
2848
- }, i.prototype._removeItem = function(e) {
2849
- if (e.id) {
2850
- this._store.dispatch(ye(e));
2851
- var t = this._notice;
2852
- t && t.type === E.noChoices && this._clearNotice(), this.passedElement.triggerEvent(w.removeItem, this._getChoiceForOutput(e));
2853
- }
2854
- }, i.prototype._addChoice = function(e, t, s) {
2855
- if (t === void 0 && (t = !0), s === void 0 && (s = !1), e.id)
2856
- throw new TypeError("Can not re-add a choice which has already been added");
2857
- var n = this.config;
2858
- if (!(!n.duplicateItemsAllowed && this._store.choices.find(function(a) {
2859
- return n.valueComparer(a.value, e.value);
2860
- }))) {
2861
- this._lastAddedChoiceId++, e.id = this._lastAddedChoiceId, e.elementId = "".concat(this._baseId, "-").concat(this._idNames.itemChoice, "-").concat(e.id);
2862
- var r = n.prependValue, o = n.appendValue;
2863
- r && (e.value = r + e.value), o && (e.value += o.toString()), (r || o) && e.element && (e.element.value = e.value), this._clearNotice(), this._store.dispatch(_e(e)), e.selected && this._addItem(e, t, s);
2864
- }
2865
- }, i.prototype._addGroup = function(e, t) {
2866
- var s = this;
2867
- if (t === void 0 && (t = !0), e.id)
2868
- throw new TypeError("Can not re-add a group which has already been added");
2869
- this._store.dispatch(et(e)), e.choices && (this._lastAddedGroupId++, e.id = this._lastAddedGroupId, e.choices.forEach(function(n) {
2870
- n.group = e, e.disabled && (n.disabled = !0), s._addChoice(n, t);
2871
- }));
2872
- }, i.prototype._createTemplates = function() {
2873
- var e = this, t = this.config.callbackOnCreateTemplates, s = {};
2874
- typeof t == "function" && (s = t.call(this, rt, fe, ee));
2875
- var n = {};
2876
- Object.keys(this._templates).forEach(function(r) {
2877
- r in s ? n[r] = s[r].bind(e) : n[r] = e._templates[r].bind(e);
2878
- }), this._templates = n;
2879
- }, i.prototype._createElements = function() {
2880
- var e = this._templates, t = this, s = t.config, n = t._isSelectOneElement, r = s.position, o = s.classNames, a = this._elementType;
2881
- this.containerOuter = new Ce({
2882
- element: e.containerOuter(s, this._direction, this._isSelectElement, n, s.searchEnabled, a, s.labelId),
2883
- classNames: o,
2884
- type: a,
2885
- position: r
2886
- }), this.containerInner = new Ce({
2887
- element: e.containerInner(s),
2888
- classNames: o,
2889
- type: a,
2890
- position: r
2891
- }), this.input = new ft({
2892
- element: e.input(s, this._placeholderValue),
2893
- classNames: o,
2894
- type: a,
2895
- preventPaste: !s.paste
2896
- }), this.choiceList = new Se({
2897
- element: e.choiceList(s, n)
2898
- }), this.itemList = new Se({
2899
- element: e.itemList(s, n)
2900
- }), this.dropdown = new dt({
2901
- element: e.dropdown(s),
2902
- classNames: o,
2903
- type: a
2904
- });
2905
- }, i.prototype._createStructure = function() {
2906
- var e = this, t = e.containerInner, s = e.containerOuter, n = e.passedElement, r = this.dropdown.element;
2907
- n.conceal(), t.wrap(n.element), s.wrap(t.element), this._isSelectOneElement ? this.input.placeholder = this.config.searchPlaceholderValue || "" : (this._placeholderValue && (this.input.placeholder = this._placeholderValue), this.input.setWidth()), s.element.appendChild(t.element), s.element.appendChild(r), t.element.appendChild(this.itemList.element), r.appendChild(this.choiceList.element), this._isSelectOneElement ? this.config.searchEnabled && r.insertBefore(this.input.element, r.firstChild) : t.element.appendChild(this.input.element), this._highlightPosition = 0, this._isSearching = !1;
2908
- }, i.prototype._initStore = function() {
2909
- var e = this;
2910
- this._store.subscribe(this._render).withTxn(function() {
2911
- e._addPredefinedChoices(e._presetChoices, e._isSelectOneElement && !e._hasNonChoicePlaceholder, !1);
2912
- }), (!this._store.choices.length || this._isSelectOneElement && this._hasNonChoicePlaceholder) && this._render();
2913
- }, i.prototype._addPredefinedChoices = function(e, t, s) {
2914
- var n = this;
2915
- if (t === void 0 && (t = !1), s === void 0 && (s = !0), t) {
2916
- var r = e.findIndex(function(o) {
2917
- return o.selected;
2918
- }) === -1;
2919
- r && e.some(function(o) {
2920
- return o.disabled || "choices" in o ? !1 : (o.selected = !0, !0);
2921
- });
2922
- }
2923
- e.forEach(function(o) {
2924
- "choices" in o ? n._isSelectElement && n._addGroup(o, s) : n._addChoice(o, s);
2925
- });
2926
- }, i.prototype._findAndSelectChoiceByValue = function(e, t) {
2927
- var s = this;
2928
- t === void 0 && (t = !1);
2929
- var n = this._store.choices.find(function(r) {
2930
- return s.config.valueComparer(r.value, e);
2931
- });
2932
- return n && !n.disabled && !n.selected ? (this._addItem(n, !0, t), !0) : !1;
2933
- }, i.prototype._generatePlaceholderValue = function() {
2934
- var e = this.config;
2935
- if (!e.placeholder)
2936
- return null;
2937
- if (this._hasNonChoicePlaceholder)
2938
- return e.placeholderValue;
2939
- if (this._isSelectElement) {
2940
- var t = this.passedElement.placeholderOption;
2941
- return t ? t.text : null;
2942
- }
2943
- return null;
2944
- }, i.prototype._warnChoicesInitFailed = function(e) {
2945
- if (!this.config.silent)
2946
- if (this.initialised) {
2947
- if (!this.initialisedOK)
2948
- throw new TypeError("".concat(e, " called for an element which has multiple instances of Choices initialised on it"));
2949
- } else throw new TypeError("".concat(e, " called on a non-initialised instance of Choices"));
2950
- }, i.version = "11.1.0", i;
2951
- }()
2952
- );
2953
- export {
2954
- bi as default
2955
- };