@schukai/monster 3.107.0 → 3.108.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.
@@ -12,59 +12,59 @@
12
12
  * SPDX-License-Identifier: AGPL-3.0
13
13
  */
14
14
 
15
- import {instanceSymbol} from "../../constants.mjs";
16
- import {internalSymbol} from "../../constants.mjs";
17
- import {buildMap,build as buildValue} from "../../data/buildmap.mjs";
18
- import {DeadMansSwitch} from "../../util/deadmansswitch.mjs";
19
- import {positionPopper} from "./util/floating-ui.mjs";
15
+ import { instanceSymbol } from "../../constants.mjs";
16
+ import { internalSymbol } from "../../constants.mjs";
17
+ import { buildMap, build as buildValue } from "../../data/buildmap.mjs";
18
+ import { DeadMansSwitch } from "../../util/deadmansswitch.mjs";
19
+ import { positionPopper } from "./util/floating-ui.mjs";
20
20
  import {
21
- addAttributeToken,
22
- findClosestByAttribute,
23
- removeAttributeToken,
21
+ addAttributeToken,
22
+ findClosestByAttribute,
23
+ removeAttributeToken,
24
24
  } from "../../dom/attributes.mjs";
25
- import {ATTRIBUTE_PREFIX, ATTRIBUTE_ROLE} from "../../dom/constants.mjs";
26
- import {CustomControl} from "../../dom/customcontrol.mjs";
25
+ import { ATTRIBUTE_PREFIX, ATTRIBUTE_ROLE } from "../../dom/constants.mjs";
26
+ import { CustomControl } from "../../dom/customcontrol.mjs";
27
27
  import {
28
- assembleMethodSymbol,
29
- getSlottedElements,
30
- registerCustomElement,
28
+ assembleMethodSymbol,
29
+ getSlottedElements,
30
+ registerCustomElement,
31
31
  } from "../../dom/customelement.mjs";
32
32
  import {
33
- findTargetElementFromEvent,
34
- fireCustomEvent,
35
- fireEvent,
33
+ findTargetElementFromEvent,
34
+ fireCustomEvent,
35
+ fireEvent,
36
36
  } from "../../dom/events.mjs";
37
- import {getDocument} from "../../dom/util.mjs";
38
- import {Formatter} from "../../text/formatter.mjs";
39
- import {getGlobal} from "../../types/global.mjs";
40
- import {ID} from "../../types/id.mjs";
37
+ import { getDocument } from "../../dom/util.mjs";
38
+ import { Formatter } from "../../text/formatter.mjs";
39
+ import { getGlobal } from "../../types/global.mjs";
40
+ import { ID } from "../../types/id.mjs";
41
41
  import {
42
- isArray,
43
- isFunction,
44
- isInteger,
45
- isIterable,
46
- isObject,
47
- isPrimitive,
48
- isString,
42
+ isArray,
43
+ isFunction,
44
+ isInteger,
45
+ isIterable,
46
+ isObject,
47
+ isPrimitive,
48
+ isString,
49
49
  } from "../../types/is.mjs";
50
- import {Observer} from "../../types/observer.mjs";
51
- import {ProxyObserver} from "../../types/proxyobserver.mjs";
52
- import {validateArray, validateString} from "../../types/validate.mjs";
53
- import {Processing} from "../../util/processing.mjs";
54
- import {STYLE_DISPLAY_MODE_BLOCK} from "./constants.mjs";
55
- import {SelectStyleSheet} from "./stylesheet/select.mjs";
50
+ import { Observer } from "../../types/observer.mjs";
51
+ import { ProxyObserver } from "../../types/proxyobserver.mjs";
52
+ import { validateArray, validateString } from "../../types/validate.mjs";
53
+ import { Processing } from "../../util/processing.mjs";
54
+ import { STYLE_DISPLAY_MODE_BLOCK } from "./constants.mjs";
55
+ import { SelectStyleSheet } from "./stylesheet/select.mjs";
56
56
  import {
57
- getDocumentTranslations,
58
- Translations,
57
+ getDocumentTranslations,
58
+ Translations,
59
59
  } from "../../i18n/translations.mjs";
60
- import {getLocaleOfDocument} from "../../dom/locale.mjs";
61
- import {addErrorAttribute, removeErrorAttribute} from "../../dom/error.mjs";
60
+ import { getLocaleOfDocument } from "../../dom/locale.mjs";
61
+ import { addErrorAttribute, removeErrorAttribute } from "../../dom/error.mjs";
62
62
 
63
63
  export {
64
- Select,
65
- popperElementSymbol,
66
- getSummaryTemplate,
67
- getSelectionTemplate,
64
+ Select,
65
+ popperElementSymbol,
66
+ getSummaryTemplate,
67
+ getSelectionTemplate,
68
68
  };
69
69
 
70
70
  /**
@@ -185,7 +185,7 @@ const popperFilterElementSymbol = Symbol("popperFilterElement");
185
185
  * @type {Symbol}
186
186
  */
187
187
  const popperFilterContainerElementSymbol = Symbol(
188
- "popperFilterContainerElement",
188
+ "popperFilterContainerElement",
189
189
  );
190
190
 
191
191
  /**
@@ -289,529 +289,526 @@ const FILTER_POSITION_INLINE = "inline";
289
289
  * @fires monster-changed
290
290
  */
291
291
  class Select extends CustomControl {
292
- /**
293
- *
294
- */
295
- constructor() {
296
- super();
297
- initOptionObserver.call(this);
298
- }
299
-
300
- /**
301
- * This method is called by the `instanceof` operator.
302
- * @return {Symbol}
303
- */
304
- static get [instanceSymbol]() {
305
- return Symbol.for("@schukai/monster/components/form/select@@instance");
306
- }
307
-
308
- /**
309
- * The current selection of the Select
310
- *
311
- * ```
312
- * e = document.querySelector('monster-select');
313
- * console.log(e.value)
314
- * // ↦ 1
315
- * // ↦ ['1','2']
316
- * ```
317
- *
318
- * @return {string}
319
- */
320
- get value() {
321
- return convertSelectionToValue.call(this, this.getOption("selection"));
322
- }
323
-
324
- /**
325
- * @see {@link https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/attachInternals}
326
- * @return {boolean}
327
- */
328
- static get formAssociated() {
329
- return true;
330
- }
331
-
332
- /**
333
- * Set selection
334
- *
335
- * ```
336
- * e = document.querySelector('monster-select');
337
- * e.value=1
338
- * ```
339
- *
340
- * @property {string|array} value
341
- * @throws {Error} unsupported type
342
- * @fires monster-selected this event is fired when the selection is set
343
- */
344
- set value(value) {
345
-
346
- const result = convertValueToSelection.call(this, value);
347
-
348
- setSelection
349
- .call(this, result.selection)
350
- .then(() => {
351
- })
352
- .catch((e) => {
353
- addErrorAttribute(this, e);
354
- });
355
- }
356
-
357
- /**
358
- * To set the options via the HTML tag, the attribute `data-monster-options` must be used.
359
- * @see {@link https://monsterjs.org/en/doc/#configurate-a-monster-control}
360
- *
361
- * The individual configuration values can be found in the table.
362
- *
363
- * @property {Object} toggleEventType List of event types to be observed for opening the dropdown
364
- * @property {boolean} delegatesFocus lorem [see mozilla.org](https://developer.mozilla.org/en-US/docs/Web/API/ShadowRoot/delegatesFocus)
365
- * @property {Object[]} options Selection of key identifier pairs available for selection and displayed in the dropdown.
366
- * @property {string} options[].label
367
- * @property {string} options[].value
368
- * @property {string} options[].visibility hidden or visible
369
- * @property {Array} selection Selected options
370
- * @property {Integer} showMaxOptions Maximum number of visible options before a scroll bar should be displayed.
371
- * @property {string} type Multiple (checkbox) or single selection (radio)
372
- * @property {string} name Name of the form field
373
- * @property {string} url Load options from server per url
374
- * @property {object} lookup Load options from server per url
375
- * @property {string} lookup.url Load options from server per url
376
- * @property {boolean} lookup.grouping Load all selected options from server per url at once (true) or one by one (false)
377
- * @property {Object} fetch Fetch [see Using Fetch mozilla.org](https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API/Using_Fetch)
378
- * @property {String} fetch.redirect
379
- * @property {String} fetch.method
380
- * @property {String} fetch.mode
381
- * @property {String} fetch.credentials
382
- * @property {Object} fetch.headers
383
- * @property {Object} labels
384
- * @property {string} labels.cannot-be-loaded cannot be loaded
385
- * @property {string} labels.no-options-available no options available
386
- * @property {string} labels.select-an-option select an option
387
- * @property {string} labels.no-option no option in the list, maybe you have to change the filter
388
- * @property {Object} features List with features
389
- * @property {Boolean} features.clearAll Display of a delete button to delete the entire selection
390
- * @property {Boolean} features.clear Display of a delete key for deleting the specific selection
391
- * @property {Boolean} features.lazyLoad Load options when first opening the dropdown. (Hint; lazylLoad is not supported with remote filter)
392
- * @property {Boolean} features.closeOnSelect Close the dropdown when an option is selected (since 3.54.0)
393
- * @property {Boolean} features.emptyValueIfNoOptions If no options are available, the selection is set to an empty array
394
- * @property {Boolean} features.storeFetchedData Store fetched data in the object
395
- * @property {Boolean} features.useStrictValueComparison Use strict value comparison for the selection
396
- * @property {string} filter.defaultValue Default filter value, if the filter is empty, if the default value is null, then no request is made
397
- * @property {Boolean} filter.mode Filter mode, values: options, remote, disabled (Hint; lazylLoad is not supported with remote filter, if you use remote filter, the lazyLoad is disabled)
398
- * @property {Object} templates Template definitions
399
- * @property {string} templates.main Main template
400
- * @property {string} templateMapping Mapping of the template placeholders
401
- * @property {string} templateMapping.selected Selected Template
402
- * @property {Object} popper [PopperJS Options](https://popper.js.org/docs/v2/)
403
- * @property {string} popper.placement PopperJS placement
404
- * @property {Object[]} modifiers PopperJS placement
405
- * @property {Object} mapping
406
- * @property {String} mapping.selector Path to select the appropriate entries
407
- * @property {String} mapping.labelTemplate template with the label placeholders in the form ${name}, where name is the key (**)
408
- * @property {String} mapping.valueTemplate template with the value placeholders in the form ${name}, where name is the key
409
- * @property {function|undefined} mapping.filter Filtering of values via a function
410
- * @property {Object} empty
411
- * @property {String} empty.defaultValueRadio Default value if you use radio buttons
412
- * @property {Array} empty.defaultValueCheckbox Default value if you use checkboxes
413
- * @property {Array} empty.equivalents Equivalents for empty values
414
- * @property {Object} formatter
415
- * @property {function|undefined} formatter.selection format selection label
416
- */
417
- get defaults() {
418
- return Object.assign(
419
- {},
420
- super.defaults,
421
- {
422
- toggleEventType: ["click", "touch"],
423
- delegatesFocus: false,
424
- options: [],
425
- selection: [],
426
- showMaxOptions: 10,
427
- type: "radio",
428
- name: new ID("s").toString(),
429
- features: {
430
- clearAll: true,
431
- clear: true,
432
- lazyLoad: false,
433
- closeOnSelect: false,
434
- emptyValueIfNoOptions: false,
435
- storeFetchedData: false,
436
- useStrictValueComparison: false,
437
- },
438
- url: null,
439
- lookup: {
440
- url: null,
441
- grouping: false,
442
- },
443
- labels: getTranslations(),
444
- messages: {
445
- control: null,
446
- selected: null,
447
- emptyOptions: null,
448
- },
449
- fetch: {
450
- redirect: "error",
451
- method: "GET",
452
- mode: "same-origin",
453
- credentials: "same-origin",
454
- headers: {
455
- accept: "application/json",
456
- },
457
- },
458
- filter: {
459
- defaultValue: null,
460
- mode: FILTER_MODE_DISABLED,
461
- position: FILTER_POSITION_INLINE,
462
- marker: {
463
- open: "{",
464
- close: "}",
465
- },
466
- },
467
- classes: {
468
- badge: "monster-badge-primary",
469
- statusOrRemoveBadge: "empty",
470
- },
471
- mapping: {
472
- selector: "*",
473
- labelTemplate: "",
474
- valueTemplate: "",
475
- filter: null,
476
- },
477
- empty: {
478
- defaultValueRadio: "",
479
- defaultValueCheckbox: [],
480
- equivalents: [undefined, null, "", NaN],
481
- },
482
- formatter: {
483
- selection: buildSelectionLabel,
484
- },
485
- templates: {
486
- main: getTemplate(),
487
- },
488
- templateMapping: {
489
- /** with the attribute `data-monster-selected-template` the template for the selected options can be defined. */
490
- selected: getSelectionTemplate(),
491
- },
492
-
493
- popper: {
494
- placement: "bottom",
495
- middleware: ["flip", "offset:1"],
496
- },
497
- },
498
- initOptionsFromArguments.call(this),
499
- );
500
- }
501
-
502
- /**
503
- * @return {Select}
504
- */
505
- [assembleMethodSymbol]() {
506
- const self = this;
507
- super[assembleMethodSymbol]();
508
-
509
- initControlReferences.call(self);
510
- initEventHandler.call(self);
511
-
512
- let lazyLoadFlag = self.getOption("features.lazyLoad", false);
513
- let remoteFilterFlag = getFilterMode.call(this) === FILTER_MODE_REMOTE;
514
-
515
- if (getFilterMode.call(this) === FILTER_MODE_REMOTE) {
516
- self.getOption("features.lazyLoad", false);
517
- if (lazyLoadFlag === true) {
518
- addErrorAttribute(this, "lazyLoad is not supported with remote filter");
519
- lazyLoadFlag = false;
520
- }
521
- }
522
-
523
- if (self.hasAttribute("value")) {
524
- new Processing(10, () => {
525
- const oldValue = self.value;
526
- const newValue = self.getAttribute("value");
527
- if (oldValue !== newValue) {
528
- self.value = newValue;
529
- }
530
- })
531
- .run()
532
- .catch((e) => {
533
- addErrorAttribute(this, e);
534
- });
535
- }
536
-
537
- if (self.getOption("url") !== null) {
538
- if (lazyLoadFlag || remoteFilterFlag) {
539
- lookupSelection.call(self);
540
- } else {
541
- self.fetch().catch((e) => {
542
- addErrorAttribute(self, e);
543
- });
544
- }
545
- }
546
-
547
- setTimeout(() => {
548
- let lastValue = self.value;
549
- self[internalSymbol].attachObserver(
550
- new Observer(function () {
551
- if (isObject(this) && this instanceof ProxyObserver) {
552
- const n = this.getSubject()?.options?.value;
553
-
554
- if (lastValue !== n && n !== undefined) {
555
- lastValue = n;
556
- setSelection
557
- .call(self, n)
558
- .then(() => {
559
- })
560
- .catch((e) => {
561
- addErrorAttribute(self, e);
562
- });
563
- }
564
- }
565
- }),
566
- );
567
-
568
- areOptionsAvailableAndInit.call(self);
569
- }, 0);
570
-
571
- return this;
572
- }
573
-
574
- /**
575
- *
576
- * @return {*}
577
- * @throws {Error} storeFetchedData is not enabled
578
- * @since 3.66.0
579
- */
580
- getLastFetchedData() {
581
- if (this.getOption("features.storeFetchedData") === false) {
582
- throw new Error("storeFetchedData is not enabled");
583
- }
584
-
585
- return this?.[lastFetchedDataSymbol];
586
- }
587
-
588
- /**
589
- * The Button.click() method simulates a click on the internal button element.
590
- *
591
- * @since 3.27.0
592
- * @see {@link https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/click}
593
- */
594
- click() {
595
- if (this.getOption("disabled") === true) {
596
- return;
597
- }
598
-
599
- toggle.call(this);
600
- }
601
-
602
- /**
603
- * The Button.focus() method sets focus on the internal button element.
604
- *
605
- * @since 3.27.0
606
- * @see {@link https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/focus}
607
- */
608
- focus(options) {
609
- if (this.getOption("disabled") === true) {
610
- return;
611
- }
612
-
613
- new Processing(() => {
614
- gatherState.call(this);
615
- focusFilter.call(this, options);
616
- })
617
- .run()
618
- .catch((e) => {
619
- addErrorAttribute(this, e);
620
- });
621
- }
622
-
623
- /**
624
- * The Button.blur() method removes focus from the internal button element.
625
- * @link https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/blur
626
- */
627
- blur() {
628
- new Processing(() => {
629
- gatherState.call(this);
630
- blurFilter.call(this);
631
- })
632
- .run()
633
- .catch((e) => {
634
- addErrorAttribute(this, e);
635
- });
636
- }
637
-
638
- /**
639
- * If no url is specified, the options are taken from the Component itself.
640
- *
641
- * @param {string|URL} url URL to fetch the options
642
- * @return {Promise}
643
- */
644
- fetch(url) {
645
- return fetchIt.call(this, url);
646
- }
647
-
648
- /**
649
- * @return {void}
650
- */
651
- connectedCallback() {
652
- super.connectedCallback();
653
- const document = getDocument();
654
-
655
- for (const [, type] of Object.entries(["click", "touch"])) {
656
- // close on outside ui-events
657
- document.addEventListener(type, this[closeEventHandler]);
658
- }
659
-
660
- parseSlotsToOptions.call(this);
661
- attachResizeObserver.call(this);
662
- updatePopper.call(this);
663
-
664
- new Processing(() => {
665
- gatherState.call(this);
666
- focusFilter.call(this);
667
- })
668
- .run()
669
- .catch((e) => {
670
- addErrorAttribute(this, e);
671
- });
672
- }
673
-
674
- /**
675
- * @return {void}
676
- */
677
- disconnectedCallback() {
678
- super.disconnectedCallback();
679
- const document = getDocument();
680
-
681
- // close on outside ui-events
682
- for (const [, type] of Object.entries(["click", "touch"])) {
683
- document.removeEventListener(type, this[closeEventHandler]);
684
- }
685
-
686
- disconnectResizeObserver.call(this);
687
- }
688
-
689
- /**
690
- * Import Select Options from dataset
691
- * Not to be confused with the control defaults/options
692
- *
693
- * @param {array|object|Map|Set} data
694
- * @return {Select}
695
- * @throws {Error} map is not iterable
696
- * @throws {Error} missing label configuration
697
- * @fires monster-options-set this event is fired when the options are set
698
- */
699
- importOptions(data) {
700
- const self = this;
701
- const mappingOptions = this.getOption("mapping", {});
702
- const selector = mappingOptions?.["selector"];
703
- const labelTemplate = mappingOptions?.["labelTemplate"];
704
- const valueTemplate = mappingOptions?.["valueTemplate"];
705
- let filter = mappingOptions?.["filter"];
706
-
707
- let flag = false;
708
- if (labelTemplate === "") {
709
- addErrorAttribute(this, "empty label template");
710
- flag = true;
711
- }
712
-
713
- if (valueTemplate === "") {
714
- addErrorAttribute(this, "empty value template");
715
- flag = true;
716
- }
717
-
718
- if (flag === true) {
719
- throw new Error("missing label configuration");
720
- }
721
- if (isString(filter) ) {
722
- if (0 === filter.indexOf('run:')) {
723
- const code = filter.replace('run:', '');
724
- filter = (m, v, k) => {
725
- const fkt = new Function('m', 'v', 'k', "control", code);
726
- return fkt(m, v, k, self);
727
- }
728
- } else if (0 === filter.indexOf('call:')) {
729
-
730
- const parts = filter.split(':');
731
- parts.shift(); // remove prefix
732
- const fkt = parts.shift();
733
-
734
- switch (fkt) {
735
- case "filterValueOfAttribute":
736
-
737
- const attribute = parts.shift();
738
- const attrValue = self.getAttribute(attribute);
739
-
740
- filter = (m, v, k) => {
741
- const mm = buildValue(m, valueTemplate);
742
- return mm != attrValue; // no type check, no !==
743
- }
744
- break;
745
-
746
- default:
747
- addErrorAttribute(this, new Error(`Unknown filter function ${fkt}`));
748
- }
749
- }
750
- }
751
-
752
- const map = buildMap(data, selector, labelTemplate, valueTemplate, filter);
753
-
754
- const options = [];
755
-
756
- if (!isIterable(map)) {
757
- throw new Error("map is not iterable");
758
- }
759
-
760
- const visibility = "visible";
761
-
762
- map.forEach((label, value) => {
763
- options.push({
764
- value,
765
- label,
766
- visibility,
767
- data: map.get(value),
768
- });
769
- });
770
-
771
- runAsOptionLengthChanged.call(this, map.size);
772
- this.setOption("options", options);
773
-
774
- fireCustomEvent(this, "monster-options-set", {
775
- options,
776
- });
777
-
778
- setTimeout(() => {
779
- setSelection
780
- .call(this, this.getOption("selection"))
781
- .then(() => {
782
- })
783
- .catch((e) => {
784
- addErrorAttribute(this, e);
785
- });
786
- }, 10);
787
-
788
- return this;
789
- }
790
-
791
- /**
792
- * @private
793
- * @return {Select}
794
- */
795
- calcAndSetOptionsDimension() {
796
- calcAndSetOptionsDimension.call(this);
797
- return this;
798
- }
799
-
800
- /**
801
- *
802
- * @return {string}
803
- */
804
- static getTag() {
805
- return "monster-select";
806
- }
807
-
808
- /**
809
- *
810
- * @return {CSSStyleSheet[]}
811
- */
812
- static getCSSStyleSheet() {
813
- return [SelectStyleSheet];
814
- }
292
+ /**
293
+ *
294
+ */
295
+ constructor() {
296
+ super();
297
+ initOptionObserver.call(this);
298
+ }
299
+
300
+ /**
301
+ * This method is called by the `instanceof` operator.
302
+ * @return {Symbol}
303
+ */
304
+ static get [instanceSymbol]() {
305
+ return Symbol.for("@schukai/monster/components/form/select@@instance");
306
+ }
307
+
308
+ /**
309
+ * The current selection of the Select
310
+ *
311
+ * ```
312
+ * e = document.querySelector('monster-select');
313
+ * console.log(e.value)
314
+ * // ↦ 1
315
+ * // ↦ ['1','2']
316
+ * ```
317
+ *
318
+ * @return {string}
319
+ */
320
+ get value() {
321
+ return convertSelectionToValue.call(this, this.getOption("selection"));
322
+ }
323
+
324
+ /**
325
+ * @see {@link https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/attachInternals}
326
+ * @return {boolean}
327
+ */
328
+ static get formAssociated() {
329
+ return true;
330
+ }
331
+
332
+ /**
333
+ * Set selection
334
+ *
335
+ * ```
336
+ * e = document.querySelector('monster-select');
337
+ * e.value=1
338
+ * ```
339
+ *
340
+ * @property {string|array} value
341
+ * @throws {Error} unsupported type
342
+ * @fires monster-selected this event is fired when the selection is set
343
+ */
344
+ set value(value) {
345
+ const result = convertValueToSelection.call(this, value);
346
+
347
+ setSelection
348
+ .call(this, result.selection)
349
+ .then(() => {})
350
+ .catch((e) => {
351
+ addErrorAttribute(this, e);
352
+ });
353
+ }
354
+
355
+ /**
356
+ * To set the options via the HTML tag, the attribute `data-monster-options` must be used.
357
+ * @see {@link https://monsterjs.org/en/doc/#configurate-a-monster-control}
358
+ *
359
+ * The individual configuration values can be found in the table.
360
+ *
361
+ * @property {Object} toggleEventType List of event types to be observed for opening the dropdown
362
+ * @property {boolean} delegatesFocus lorem [see mozilla.org](https://developer.mozilla.org/en-US/docs/Web/API/ShadowRoot/delegatesFocus)
363
+ * @property {Object[]} options Selection of key identifier pairs available for selection and displayed in the dropdown.
364
+ * @property {string} options[].label
365
+ * @property {string} options[].value
366
+ * @property {string} options[].visibility hidden or visible
367
+ * @property {Array} selection Selected options
368
+ * @property {Integer} showMaxOptions Maximum number of visible options before a scroll bar should be displayed.
369
+ * @property {string} type Multiple (checkbox) or single selection (radio)
370
+ * @property {string} name Name of the form field
371
+ * @property {string} url Load options from server per url
372
+ * @property {object} lookup Load options from server per url
373
+ * @property {string} lookup.url Load options from server per url
374
+ * @property {boolean} lookup.grouping Load all selected options from server per url at once (true) or one by one (false)
375
+ * @property {Object} fetch Fetch [see Using Fetch mozilla.org](https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API/Using_Fetch)
376
+ * @property {String} fetch.redirect
377
+ * @property {String} fetch.method
378
+ * @property {String} fetch.mode
379
+ * @property {String} fetch.credentials
380
+ * @property {Object} fetch.headers
381
+ * @property {Object} labels
382
+ * @property {string} labels.cannot-be-loaded cannot be loaded
383
+ * @property {string} labels.no-options-available no options available
384
+ * @property {string} labels.select-an-option select an option
385
+ * @property {string} labels.no-option no option in the list, maybe you have to change the filter
386
+ * @property {Object} features List with features
387
+ * @property {Boolean} features.clearAll Display of a delete button to delete the entire selection
388
+ * @property {Boolean} features.clear Display of a delete key for deleting the specific selection
389
+ * @property {Boolean} features.lazyLoad Load options when first opening the dropdown. (Hint; lazylLoad is not supported with remote filter)
390
+ * @property {Boolean} features.closeOnSelect Close the dropdown when an option is selected (since 3.54.0)
391
+ * @property {Boolean} features.emptyValueIfNoOptions If no options are available, the selection is set to an empty array
392
+ * @property {Boolean} features.storeFetchedData Store fetched data in the object
393
+ * @property {Boolean} features.useStrictValueComparison Use strict value comparison for the selection
394
+ * @property {string} filter.defaultValue Default filter value, if the filter is empty, if the default value is null, then no request is made
395
+ * @property {Boolean} filter.mode Filter mode, values: options, remote, disabled (Hint; lazylLoad is not supported with remote filter, if you use remote filter, the lazyLoad is disabled)
396
+ * @property {Object} templates Template definitions
397
+ * @property {string} templates.main Main template
398
+ * @property {string} templateMapping Mapping of the template placeholders
399
+ * @property {string} templateMapping.selected Selected Template
400
+ * @property {Object} popper [PopperJS Options](https://popper.js.org/docs/v2/)
401
+ * @property {string} popper.placement PopperJS placement
402
+ * @property {Object[]} modifiers PopperJS placement
403
+ * @property {Object} mapping
404
+ * @property {String} mapping.selector Path to select the appropriate entries
405
+ * @property {String} mapping.labelTemplate template with the label placeholders in the form ${name}, where name is the key (**)
406
+ * @property {String} mapping.valueTemplate template with the value placeholders in the form ${name}, where name is the key
407
+ * @property {function|undefined} mapping.filter Filtering of values via a function
408
+ * @property {Object} empty
409
+ * @property {String} empty.defaultValueRadio Default value if you use radio buttons
410
+ * @property {Array} empty.defaultValueCheckbox Default value if you use checkboxes
411
+ * @property {Array} empty.equivalents Equivalents for empty values
412
+ * @property {Object} formatter
413
+ * @property {function|undefined} formatter.selection format selection label
414
+ */
415
+ get defaults() {
416
+ return Object.assign(
417
+ {},
418
+ super.defaults,
419
+ {
420
+ toggleEventType: ["click", "touch"],
421
+ delegatesFocus: false,
422
+ options: [],
423
+ selection: [],
424
+ showMaxOptions: 10,
425
+ type: "radio",
426
+ name: new ID("s").toString(),
427
+ features: {
428
+ clearAll: true,
429
+ clear: true,
430
+ lazyLoad: false,
431
+ closeOnSelect: false,
432
+ emptyValueIfNoOptions: false,
433
+ storeFetchedData: false,
434
+ useStrictValueComparison: false,
435
+ },
436
+ url: null,
437
+ lookup: {
438
+ url: null,
439
+ grouping: false,
440
+ },
441
+ labels: getTranslations(),
442
+ messages: {
443
+ control: null,
444
+ selected: null,
445
+ emptyOptions: null,
446
+ },
447
+ fetch: {
448
+ redirect: "error",
449
+ method: "GET",
450
+ mode: "same-origin",
451
+ credentials: "same-origin",
452
+ headers: {
453
+ accept: "application/json",
454
+ },
455
+ },
456
+ filter: {
457
+ defaultValue: null,
458
+ mode: FILTER_MODE_DISABLED,
459
+ position: FILTER_POSITION_INLINE,
460
+ marker: {
461
+ open: "{",
462
+ close: "}",
463
+ },
464
+ },
465
+ classes: {
466
+ badge: "monster-badge-primary",
467
+ statusOrRemoveBadge: "empty",
468
+ },
469
+ mapping: {
470
+ selector: "*",
471
+ labelTemplate: "",
472
+ valueTemplate: "",
473
+ filter: null,
474
+ },
475
+ empty: {
476
+ defaultValueRadio: "",
477
+ defaultValueCheckbox: [],
478
+ equivalents: [undefined, null, "", NaN],
479
+ },
480
+ formatter: {
481
+ selection: buildSelectionLabel,
482
+ },
483
+ templates: {
484
+ main: getTemplate(),
485
+ },
486
+ templateMapping: {
487
+ /** with the attribute `data-monster-selected-template` the template for the selected options can be defined. */
488
+ selected: getSelectionTemplate(),
489
+ },
490
+
491
+ popper: {
492
+ placement: "bottom",
493
+ middleware: ["flip", "offset:1"],
494
+ },
495
+ },
496
+ initOptionsFromArguments.call(this),
497
+ );
498
+ }
499
+
500
+ /**
501
+ * @return {Select}
502
+ */
503
+ [assembleMethodSymbol]() {
504
+ const self = this;
505
+ super[assembleMethodSymbol]();
506
+
507
+ initControlReferences.call(self);
508
+ initEventHandler.call(self);
509
+
510
+ let lazyLoadFlag = self.getOption("features.lazyLoad", false);
511
+ let remoteFilterFlag = getFilterMode.call(this) === FILTER_MODE_REMOTE;
512
+
513
+ if (getFilterMode.call(this) === FILTER_MODE_REMOTE) {
514
+ self.getOption("features.lazyLoad", false);
515
+ if (lazyLoadFlag === true) {
516
+ addErrorAttribute(this, "lazyLoad is not supported with remote filter");
517
+ lazyLoadFlag = false;
518
+ }
519
+ }
520
+
521
+ if (self.hasAttribute("value")) {
522
+ new Processing(10, () => {
523
+ const oldValue = self.value;
524
+ const newValue = self.getAttribute("value");
525
+ if (oldValue !== newValue) {
526
+ self.value = newValue;
527
+ }
528
+ })
529
+ .run()
530
+ .catch((e) => {
531
+ addErrorAttribute(this, e);
532
+ });
533
+ }
534
+
535
+ if (self.getOption("url") !== null) {
536
+ if (lazyLoadFlag || remoteFilterFlag) {
537
+ lookupSelection.call(self);
538
+ } else {
539
+ self.fetch().catch((e) => {
540
+ addErrorAttribute(self, e);
541
+ });
542
+ }
543
+ }
544
+
545
+ setTimeout(() => {
546
+ let lastValue = self.value;
547
+ self[internalSymbol].attachObserver(
548
+ new Observer(function () {
549
+ if (isObject(this) && this instanceof ProxyObserver) {
550
+ const n = this.getSubject()?.options?.value;
551
+
552
+ if (lastValue !== n && n !== undefined) {
553
+ lastValue = n;
554
+ setSelection
555
+ .call(self, n)
556
+ .then(() => {})
557
+ .catch((e) => {
558
+ addErrorAttribute(self, e);
559
+ });
560
+ }
561
+ }
562
+ }),
563
+ );
564
+
565
+ areOptionsAvailableAndInit.call(self);
566
+ }, 0);
567
+
568
+ return this;
569
+ }
570
+
571
+ /**
572
+ *
573
+ * @return {*}
574
+ * @throws {Error} storeFetchedData is not enabled
575
+ * @since 3.66.0
576
+ */
577
+ getLastFetchedData() {
578
+ if (this.getOption("features.storeFetchedData") === false) {
579
+ throw new Error("storeFetchedData is not enabled");
580
+ }
581
+
582
+ return this?.[lastFetchedDataSymbol];
583
+ }
584
+
585
+ /**
586
+ * The Button.click() method simulates a click on the internal button element.
587
+ *
588
+ * @since 3.27.0
589
+ * @see {@link https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/click}
590
+ */
591
+ click() {
592
+ if (this.getOption("disabled") === true) {
593
+ return;
594
+ }
595
+
596
+ toggle.call(this);
597
+ }
598
+
599
+ /**
600
+ * The Button.focus() method sets focus on the internal button element.
601
+ *
602
+ * @since 3.27.0
603
+ * @see {@link https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/focus}
604
+ */
605
+ focus(options) {
606
+ if (this.getOption("disabled") === true) {
607
+ return;
608
+ }
609
+
610
+ new Processing(() => {
611
+ gatherState.call(this);
612
+ focusFilter.call(this, options);
613
+ })
614
+ .run()
615
+ .catch((e) => {
616
+ addErrorAttribute(this, e);
617
+ });
618
+ }
619
+
620
+ /**
621
+ * The Button.blur() method removes focus from the internal button element.
622
+ * @link https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/blur
623
+ */
624
+ blur() {
625
+ new Processing(() => {
626
+ gatherState.call(this);
627
+ blurFilter.call(this);
628
+ })
629
+ .run()
630
+ .catch((e) => {
631
+ addErrorAttribute(this, e);
632
+ });
633
+ }
634
+
635
+ /**
636
+ * If no url is specified, the options are taken from the Component itself.
637
+ *
638
+ * @param {string|URL} url URL to fetch the options
639
+ * @return {Promise}
640
+ */
641
+ fetch(url) {
642
+ return fetchIt.call(this, url);
643
+ }
644
+
645
+ /**
646
+ * @return {void}
647
+ */
648
+ connectedCallback() {
649
+ super.connectedCallback();
650
+ const document = getDocument();
651
+
652
+ for (const [, type] of Object.entries(["click", "touch"])) {
653
+ // close on outside ui-events
654
+ document.addEventListener(type, this[closeEventHandler]);
655
+ }
656
+
657
+ parseSlotsToOptions.call(this);
658
+ attachResizeObserver.call(this);
659
+ updatePopper.call(this);
660
+
661
+ new Processing(() => {
662
+ gatherState.call(this);
663
+ focusFilter.call(this);
664
+ })
665
+ .run()
666
+ .catch((e) => {
667
+ addErrorAttribute(this, e);
668
+ });
669
+ }
670
+
671
+ /**
672
+ * @return {void}
673
+ */
674
+ disconnectedCallback() {
675
+ super.disconnectedCallback();
676
+ const document = getDocument();
677
+
678
+ // close on outside ui-events
679
+ for (const [, type] of Object.entries(["click", "touch"])) {
680
+ document.removeEventListener(type, this[closeEventHandler]);
681
+ }
682
+
683
+ disconnectResizeObserver.call(this);
684
+ }
685
+
686
+ /**
687
+ * Import Select Options from dataset
688
+ * Not to be confused with the control defaults/options
689
+ *
690
+ * @param {array|object|Map|Set} data
691
+ * @return {Select}
692
+ * @throws {Error} map is not iterable
693
+ * @throws {Error} missing label configuration
694
+ * @fires monster-options-set this event is fired when the options are set
695
+ */
696
+ importOptions(data) {
697
+ const self = this;
698
+ const mappingOptions = this.getOption("mapping", {});
699
+ const selector = mappingOptions?.["selector"];
700
+ const labelTemplate = mappingOptions?.["labelTemplate"];
701
+ const valueTemplate = mappingOptions?.["valueTemplate"];
702
+ let filter = mappingOptions?.["filter"];
703
+
704
+ let flag = false;
705
+ if (labelTemplate === "") {
706
+ addErrorAttribute(this, "empty label template");
707
+ flag = true;
708
+ }
709
+
710
+ if (valueTemplate === "") {
711
+ addErrorAttribute(this, "empty value template");
712
+ flag = true;
713
+ }
714
+
715
+ if (flag === true) {
716
+ throw new Error("missing label configuration");
717
+ }
718
+ if (isString(filter)) {
719
+ if (0 === filter.indexOf("run:")) {
720
+ const code = filter.replace("run:", "");
721
+ filter = (m, v, k) => {
722
+ const fkt = new Function("m", "v", "k", "control", code);
723
+ return fkt(m, v, k, self);
724
+ };
725
+ } else if (0 === filter.indexOf("call:")) {
726
+ const parts = filter.split(":");
727
+ parts.shift(); // remove prefix
728
+ const fkt = parts.shift();
729
+
730
+ switch (fkt) {
731
+ case "filterValueOfAttribute":
732
+ const attribute = parts.shift();
733
+ const attrValue = self.getAttribute(attribute);
734
+
735
+ filter = (m, v, k) => {
736
+ const mm = buildValue(m, valueTemplate);
737
+ return mm != attrValue; // no type check, no !==
738
+ };
739
+ break;
740
+
741
+ default:
742
+ addErrorAttribute(
743
+ this,
744
+ new Error(`Unknown filter function ${fkt}`),
745
+ );
746
+ }
747
+ }
748
+ }
749
+
750
+ const map = buildMap(data, selector, labelTemplate, valueTemplate, filter);
751
+
752
+ const options = [];
753
+
754
+ if (!isIterable(map)) {
755
+ throw new Error("map is not iterable");
756
+ }
757
+
758
+ const visibility = "visible";
759
+
760
+ map.forEach((label, value) => {
761
+ options.push({
762
+ value,
763
+ label,
764
+ visibility,
765
+ data: map.get(value),
766
+ });
767
+ });
768
+
769
+ runAsOptionLengthChanged.call(this, map.size);
770
+ this.setOption("options", options);
771
+
772
+ fireCustomEvent(this, "monster-options-set", {
773
+ options,
774
+ });
775
+
776
+ setTimeout(() => {
777
+ setSelection
778
+ .call(this, this.getOption("selection"))
779
+ .then(() => {})
780
+ .catch((e) => {
781
+ addErrorAttribute(this, e);
782
+ });
783
+ }, 10);
784
+
785
+ return this;
786
+ }
787
+
788
+ /**
789
+ * @private
790
+ * @return {Select}
791
+ */
792
+ calcAndSetOptionsDimension() {
793
+ calcAndSetOptionsDimension.call(this);
794
+ return this;
795
+ }
796
+
797
+ /**
798
+ *
799
+ * @return {string}
800
+ */
801
+ static getTag() {
802
+ return "monster-select";
803
+ }
804
+
805
+ /**
806
+ *
807
+ * @return {CSSStyleSheet[]}
808
+ */
809
+ static getCSSStyleSheet() {
810
+ return [SelectStyleSheet];
811
+ }
815
812
  }
816
813
 
817
814
  /**
@@ -819,286 +816,286 @@ class Select extends CustomControl {
819
816
  * @returns {object}
820
817
  */
821
818
  function getTranslations() {
822
- const locale = getLocaleOfDocument();
823
- switch (locale.language) {
824
- case "de":
825
- return {
826
- "cannot-be-loaded": "Kann nicht geladen werden",
827
- "no-options-available": "Keine Optionen verfügbar.",
828
- "click-to-load-options": "Klicken, um Optionen zu laden.",
829
- "select-an-option": "Wähle eine Option",
830
- "summary-text": {
831
- zero: "Keine Einträge ausgewählt",
832
- one: '<span class="monster-badge-primary-pill">1</span> Eintrag ausgewählt',
833
- other:
834
- '<span class="monster-badge-primary-pill">${count}</span> Einträge ausgewählt',
835
- },
836
- "no-options": "Leider gibt es keine Optionen in der Liste.",
837
- "no-options-found":
838
- "Keine Optionen in der Liste verfügbar. Bitte ändern Sie den Filter.",
839
- };
840
- case "fr":
841
- return {
842
- "cannot-be-loaded": "Impossible de charger",
843
- "no-options-available": "Aucune option disponible.",
844
- "click-to-load-options": "Cliquez pour charger les options.",
845
- "select-an-option": "Sélectionnez une option",
846
- "summary-text": {
847
- zero: "Aucune entrée sélectionnée",
848
- one: '<span class="monster-badge-primary-pill">1</span> entrée sélectionnée',
849
- other:
850
- '<span class="monster-badge-primary-pill">${count}</span> entrées sélectionnées',
851
- },
852
- "no-options":
853
- "Malheureusement, il n'y a pas d'options disponibles dans la liste.",
854
- "no-options-found":
855
- "Aucune option disponible dans la liste. Veuillez modifier le filtre.",
856
- };
857
-
858
- case "sp":
859
- return {
860
- "cannot-be-loaded": "No se puede cargar",
861
- "no-options-available": "No hay opciones disponibles.",
862
- "click-to-load-options": "Haga clic para cargar opciones.",
863
- "select-an-option": "Seleccione una opción",
864
- "summary-text": {
865
- zero: "No se seleccionaron entradas",
866
- one: '<span class="monster-badge-primary-pill">1</span> entrada seleccionada',
867
- other:
868
- '<span class="monster-badge-primary-pill">${count}</span> entradas seleccionadas',
869
- },
870
- "no-options":
871
- "Desafortunadamente, no hay opciones disponibles en la lista.",
872
- "no-options-found":
873
- "No hay opciones disponibles en la lista. Considere modificar el filtro.",
874
- };
875
- case "it":
876
- return {
877
- "cannot-be-loaded": "Non può essere caricato",
878
- "no-options-available": "Nessuna opzione disponibile.",
879
- "click-to-load-options": "Clicca per caricare le opzioni.",
880
- "select-an-option": "Seleziona un'opzione",
881
- "summary-text": {
882
- zero: "Nessuna voce selezionata",
883
- one: '<span class="monster-badge-primary-pill">1</span> voce selezionata',
884
- other:
885
- '<span class="monster-badge-primary-pill">${count}</span> voci selezionate',
886
- },
887
- "no-options": "Purtroppo, non ci sono opzioni disponibili nella lista.",
888
- "no-options-found":
889
- "Nessuna opzione disponibile nella lista. Si prega di modificare il filtro.",
890
- };
891
- case "pl":
892
- return {
893
- "cannot-be-loaded": "Nie można załadować",
894
- "no-options-available": "Brak dostępnych opcji.",
895
- "click-to-load-options": "Kliknij, aby załadować opcje.",
896
- "select-an-option": "Wybierz opcję",
897
- "summary-text": {
898
- zero: "Nie wybrano żadnych wpisów",
899
- one: '<span class="monster-badge-primary-pill">1</span> wpis został wybrany',
900
- other:
901
- '<span class="monster-badge-primary-pill">${count}</span> wpisy zostały wybrane',
902
- },
903
- "no-options": "Niestety, nie ma dostępnych opcji na liście.",
904
- "no-options-found":
905
- "Brak dostępnych opcji na liście. Rozważ zmianę filtra.",
906
- };
907
- case "no":
908
- return {
909
- "cannot-be-loaded": "Kan ikke lastes",
910
- "no-options-available": "Ingen alternativer tilgjengelig.",
911
- "click-to-load-options": "Klikk for å laste alternativer.",
912
- "select-an-option": "Velg et alternativ",
913
- "summary-text": {
914
- zero: "Ingen oppføringer ble valgt",
915
- one: '<span class="monster-badge-primary-pill">1</span> oppføring valgt',
916
- other:
917
- '<span class="monster-badge-primary-pill">${count}</span> oppføringer valgt',
918
- },
919
- "no-options":
920
- "Dessverre er det ingen alternativer tilgjengelig i listen.",
921
- "no-options-found":
922
- "Ingen alternativer tilgjengelig på listen. Vurder å endre filteret.",
923
- };
924
-
925
- case "dk":
926
- return {
927
- "cannot-be-loaded": "Kan ikke indlæses",
928
- "no-options-available": "Ingen muligheder tilgængelige.",
929
- "click-to-load-options": "Klik for at indlæse muligheder.",
930
- "select-an-option": "Vælg en mulighed",
931
- "summary-text": {
932
- zero: "Ingen indlæg blev valgt",
933
- one: '<span class="monster-badge-primary-pill">1</span> indlæg blev valgt',
934
- other:
935
- '<span class="monster-badge-primary-pill">${count}</span> indlæg blev valgt',
936
- },
937
- "no-options":
938
- "Desværre er der ingen muligheder tilgængelige på listen.",
939
- "no-options-found":
940
- "Ingen muligheder tilgængelige på listen. Overvej at ændre filteret.",
941
- };
942
- case "sw":
943
- return {
944
- "cannot-be-loaded": "Kan inte laddas",
945
- "no-options-available": "Inga alternativ tillgängliga.",
946
- "click-to-load-options": "Klicka för att ladda alternativ.",
947
- "select-an-option": "Välj ett alternativ",
948
- "summary-text": {
949
- zero: "Inga poster valdes",
950
- one: '<span class="monster-badge-primary-pill">1</span> post valdes',
951
- other:
952
- '<span class="monster-badge-primary-pill">${count}</span> poster valdes',
953
- },
954
- "no-options": "Tyvärr finns det inga alternativ tillgängliga i listan.",
955
- "no-options-found":
956
- "Inga alternativ finns tillgängliga i listan. Överväg att modifiera filtret.",
957
- };
958
-
959
- default:
960
- case "en":
961
- return {
962
- "cannot-be-loaded": "Cannot be loaded",
963
- "no-options-available": "No options available.",
964
- "click-to-load-options": "Click to load options.",
965
- "select-an-option": "Select an option",
966
- "summary-text": {
967
- zero: "No entries were selected",
968
- one: '<span class="monster-badge-primary-pill">1</span> entry was selected',
969
- other:
970
- '<span class="monster-badge-primary-pill">${count}</span> entries were selected',
971
- },
972
- "no-options":
973
- "Unfortunately, there are no options available in the list.",
974
- "no-options-found":
975
- "No options are available in the list. Please consider modifying the filter.",
976
- };
977
- }
819
+ const locale = getLocaleOfDocument();
820
+ switch (locale.language) {
821
+ case "de":
822
+ return {
823
+ "cannot-be-loaded": "Kann nicht geladen werden",
824
+ "no-options-available": "Keine Optionen verfügbar.",
825
+ "click-to-load-options": "Klicken, um Optionen zu laden.",
826
+ "select-an-option": "Wähle eine Option",
827
+ "summary-text": {
828
+ zero: "Keine Einträge ausgewählt",
829
+ one: '<span class="monster-badge-primary-pill">1</span> Eintrag ausgewählt',
830
+ other:
831
+ '<span class="monster-badge-primary-pill">${count}</span> Einträge ausgewählt',
832
+ },
833
+ "no-options": "Leider gibt es keine Optionen in der Liste.",
834
+ "no-options-found":
835
+ "Keine Optionen in der Liste verfügbar. Bitte ändern Sie den Filter.",
836
+ };
837
+ case "fr":
838
+ return {
839
+ "cannot-be-loaded": "Impossible de charger",
840
+ "no-options-available": "Aucune option disponible.",
841
+ "click-to-load-options": "Cliquez pour charger les options.",
842
+ "select-an-option": "Sélectionnez une option",
843
+ "summary-text": {
844
+ zero: "Aucune entrée sélectionnée",
845
+ one: '<span class="monster-badge-primary-pill">1</span> entrée sélectionnée',
846
+ other:
847
+ '<span class="monster-badge-primary-pill">${count}</span> entrées sélectionnées',
848
+ },
849
+ "no-options":
850
+ "Malheureusement, il n'y a pas d'options disponibles dans la liste.",
851
+ "no-options-found":
852
+ "Aucune option disponible dans la liste. Veuillez modifier le filtre.",
853
+ };
854
+
855
+ case "sp":
856
+ return {
857
+ "cannot-be-loaded": "No se puede cargar",
858
+ "no-options-available": "No hay opciones disponibles.",
859
+ "click-to-load-options": "Haga clic para cargar opciones.",
860
+ "select-an-option": "Seleccione una opción",
861
+ "summary-text": {
862
+ zero: "No se seleccionaron entradas",
863
+ one: '<span class="monster-badge-primary-pill">1</span> entrada seleccionada',
864
+ other:
865
+ '<span class="monster-badge-primary-pill">${count}</span> entradas seleccionadas',
866
+ },
867
+ "no-options":
868
+ "Desafortunadamente, no hay opciones disponibles en la lista.",
869
+ "no-options-found":
870
+ "No hay opciones disponibles en la lista. Considere modificar el filtro.",
871
+ };
872
+ case "it":
873
+ return {
874
+ "cannot-be-loaded": "Non può essere caricato",
875
+ "no-options-available": "Nessuna opzione disponibile.",
876
+ "click-to-load-options": "Clicca per caricare le opzioni.",
877
+ "select-an-option": "Seleziona un'opzione",
878
+ "summary-text": {
879
+ zero: "Nessuna voce selezionata",
880
+ one: '<span class="monster-badge-primary-pill">1</span> voce selezionata',
881
+ other:
882
+ '<span class="monster-badge-primary-pill">${count}</span> voci selezionate',
883
+ },
884
+ "no-options": "Purtroppo, non ci sono opzioni disponibili nella lista.",
885
+ "no-options-found":
886
+ "Nessuna opzione disponibile nella lista. Si prega di modificare il filtro.",
887
+ };
888
+ case "pl":
889
+ return {
890
+ "cannot-be-loaded": "Nie można załadować",
891
+ "no-options-available": "Brak dostępnych opcji.",
892
+ "click-to-load-options": "Kliknij, aby załadować opcje.",
893
+ "select-an-option": "Wybierz opcję",
894
+ "summary-text": {
895
+ zero: "Nie wybrano żadnych wpisów",
896
+ one: '<span class="monster-badge-primary-pill">1</span> wpis został wybrany',
897
+ other:
898
+ '<span class="monster-badge-primary-pill">${count}</span> wpisy zostały wybrane',
899
+ },
900
+ "no-options": "Niestety, nie ma dostępnych opcji na liście.",
901
+ "no-options-found":
902
+ "Brak dostępnych opcji na liście. Rozważ zmianę filtra.",
903
+ };
904
+ case "no":
905
+ return {
906
+ "cannot-be-loaded": "Kan ikke lastes",
907
+ "no-options-available": "Ingen alternativer tilgjengelig.",
908
+ "click-to-load-options": "Klikk for å laste alternativer.",
909
+ "select-an-option": "Velg et alternativ",
910
+ "summary-text": {
911
+ zero: "Ingen oppføringer ble valgt",
912
+ one: '<span class="monster-badge-primary-pill">1</span> oppføring valgt',
913
+ other:
914
+ '<span class="monster-badge-primary-pill">${count}</span> oppføringer valgt',
915
+ },
916
+ "no-options":
917
+ "Dessverre er det ingen alternativer tilgjengelig i listen.",
918
+ "no-options-found":
919
+ "Ingen alternativer tilgjengelig på listen. Vurder å endre filteret.",
920
+ };
921
+
922
+ case "dk":
923
+ return {
924
+ "cannot-be-loaded": "Kan ikke indlæses",
925
+ "no-options-available": "Ingen muligheder tilgængelige.",
926
+ "click-to-load-options": "Klik for at indlæse muligheder.",
927
+ "select-an-option": "Vælg en mulighed",
928
+ "summary-text": {
929
+ zero: "Ingen indlæg blev valgt",
930
+ one: '<span class="monster-badge-primary-pill">1</span> indlæg blev valgt',
931
+ other:
932
+ '<span class="monster-badge-primary-pill">${count}</span> indlæg blev valgt',
933
+ },
934
+ "no-options":
935
+ "Desværre er der ingen muligheder tilgængelige på listen.",
936
+ "no-options-found":
937
+ "Ingen muligheder tilgængelige på listen. Overvej at ændre filteret.",
938
+ };
939
+ case "sw":
940
+ return {
941
+ "cannot-be-loaded": "Kan inte laddas",
942
+ "no-options-available": "Inga alternativ tillgängliga.",
943
+ "click-to-load-options": "Klicka för att ladda alternativ.",
944
+ "select-an-option": "Välj ett alternativ",
945
+ "summary-text": {
946
+ zero: "Inga poster valdes",
947
+ one: '<span class="monster-badge-primary-pill">1</span> post valdes',
948
+ other:
949
+ '<span class="monster-badge-primary-pill">${count}</span> poster valdes',
950
+ },
951
+ "no-options": "Tyvärr finns det inga alternativ tillgängliga i listan.",
952
+ "no-options-found":
953
+ "Inga alternativ finns tillgängliga i listan. Överväg att modifiera filtret.",
954
+ };
955
+
956
+ default:
957
+ case "en":
958
+ return {
959
+ "cannot-be-loaded": "Cannot be loaded",
960
+ "no-options-available": "No options available.",
961
+ "click-to-load-options": "Click to load options.",
962
+ "select-an-option": "Select an option",
963
+ "summary-text": {
964
+ zero: "No entries were selected",
965
+ one: '<span class="monster-badge-primary-pill">1</span> entry was selected',
966
+ other:
967
+ '<span class="monster-badge-primary-pill">${count}</span> entries were selected',
968
+ },
969
+ "no-options":
970
+ "Unfortunately, there are no options available in the list.",
971
+ "no-options-found":
972
+ "No options are available in the list. Please consider modifying the filter.",
973
+ };
974
+ }
978
975
  }
979
976
 
980
977
  /**
981
978
  * @private
982
979
  */
983
980
  function lookupSelection() {
984
- const self = this;
985
-
986
- setTimeout(() => {
987
- const selection = self.getOption("selection");
988
- if (selection.length === 0) {
989
- return;
990
- }
991
-
992
- if (self[isLoadingSymbol] === true) {
993
- return;
994
- }
995
-
996
- if (self[lazyLoadDoneSymbol] === true) {
997
- return;
998
- }
999
-
1000
- let url = self.getOption("url");
1001
- let lookupUrl = self.getOption("lookup.url");
1002
- if (lookupUrl !== null) {
1003
- url = lookupUrl;
1004
- }
1005
-
1006
- if (this.getOption("lookup.grouping") === true) {
1007
- filterFromRemoteByValue
1008
- .call(
1009
- self,
1010
- url,
1011
- selection.map((s) => s?.["value"]),
1012
- )
1013
- .catch((e) => {
1014
- addErrorAttribute(self, e);
1015
- });
1016
- return;
1017
- }
1018
-
1019
- for (const s of selection) {
1020
- if (s?.["value"]) {
1021
- filterFromRemoteByValue.call(self, url, s?.["value"]).catch((e) => {
1022
- addErrorAttribute(self, e);
1023
- });
1024
- }
1025
- }
1026
- }, 100);
981
+ const self = this;
982
+
983
+ setTimeout(() => {
984
+ const selection = self.getOption("selection");
985
+ if (selection.length === 0) {
986
+ return;
987
+ }
988
+
989
+ if (self[isLoadingSymbol] === true) {
990
+ return;
991
+ }
992
+
993
+ if (self[lazyLoadDoneSymbol] === true) {
994
+ return;
995
+ }
996
+
997
+ let url = self.getOption("url");
998
+ let lookupUrl = self.getOption("lookup.url");
999
+ if (lookupUrl !== null) {
1000
+ url = lookupUrl;
1001
+ }
1002
+
1003
+ if (this.getOption("lookup.grouping") === true) {
1004
+ filterFromRemoteByValue
1005
+ .call(
1006
+ self,
1007
+ url,
1008
+ selection.map((s) => s?.["value"]),
1009
+ )
1010
+ .catch((e) => {
1011
+ addErrorAttribute(self, e);
1012
+ });
1013
+ return;
1014
+ }
1015
+
1016
+ for (const s of selection) {
1017
+ if (s?.["value"]) {
1018
+ filterFromRemoteByValue.call(self, url, s?.["value"]).catch((e) => {
1019
+ addErrorAttribute(self, e);
1020
+ });
1021
+ }
1022
+ }
1023
+ }, 100);
1027
1024
  }
1028
1025
 
1029
1026
  function fetchIt(url, controlOptions) {
1030
- if (url instanceof URL) {
1031
- url = url.toString();
1032
- }
1033
-
1034
- if (url !== undefined && url !== null) {
1035
- url = validateString(url);
1036
- } else {
1037
- url = this.getOption("url");
1038
- if (url === null) {
1039
- return Promise.reject(new Error("No url defined"));
1040
- }
1041
- }
1042
-
1043
- return new Promise((resolve, reject) => {
1044
- setStatusOrRemoveBadges.call(this, "loading");
1045
-
1046
- new Processing(10, () => {
1047
- fetchData
1048
- .call(this, url)
1049
- .then((map) => {
1050
- if (
1051
- isObject(map) ||
1052
- isArray(map) ||
1053
- map instanceof Set ||
1054
- map instanceof Map
1055
- ) {
1056
- try {
1057
- this.importOptions(map);
1058
- } catch (e) {
1059
- setStatusOrRemoveBadges.call(this, "error");
1060
- reject(e);
1061
- return;
1062
- }
1063
-
1064
- this[lastFetchedDataSymbol] = map;
1065
-
1066
- let result;
1067
- const selection = this.getOption("selection");
1068
- let newValue = [];
1069
- if (selection) {
1070
- newValue = selection;
1071
- } else if (this.hasAttribute("value")) {
1072
- newValue = this.getAttribute("value");
1073
- }
1074
-
1075
- result = setSelection.call(this, newValue);
1076
-
1077
- requestAnimationFrame(() => {
1078
- checkOptionState.call(this);
1079
- setStatusOrRemoveBadges.call(this, "closed");
1080
- updatePopper.call(this);
1081
- resolve(result);
1082
- });
1083
-
1084
- return;
1085
- }
1086
-
1087
- setStatusOrRemoveBadges.call(this, "error");
1088
- reject(new Error("invalid response"));
1089
- })
1090
- .catch((e) => {
1091
- setStatusOrRemoveBadges.call(this, "error");
1092
- reject(e);
1093
- });
1094
- })
1095
- .run()
1096
- .catch((e) => {
1097
- setStatusOrRemoveBadges.call(this, "error");
1098
- addErrorAttribute(this, e);
1099
- reject(e);
1100
- });
1101
- });
1027
+ if (url instanceof URL) {
1028
+ url = url.toString();
1029
+ }
1030
+
1031
+ if (url !== undefined && url !== null) {
1032
+ url = validateString(url);
1033
+ } else {
1034
+ url = this.getOption("url");
1035
+ if (url === null) {
1036
+ return Promise.reject(new Error("No url defined"));
1037
+ }
1038
+ }
1039
+
1040
+ return new Promise((resolve, reject) => {
1041
+ setStatusOrRemoveBadges.call(this, "loading");
1042
+
1043
+ new Processing(10, () => {
1044
+ fetchData
1045
+ .call(this, url)
1046
+ .then((map) => {
1047
+ if (
1048
+ isObject(map) ||
1049
+ isArray(map) ||
1050
+ map instanceof Set ||
1051
+ map instanceof Map
1052
+ ) {
1053
+ try {
1054
+ this.importOptions(map);
1055
+ } catch (e) {
1056
+ setStatusOrRemoveBadges.call(this, "error");
1057
+ reject(e);
1058
+ return;
1059
+ }
1060
+
1061
+ this[lastFetchedDataSymbol] = map;
1062
+
1063
+ let result;
1064
+ const selection = this.getOption("selection");
1065
+ let newValue = [];
1066
+ if (selection) {
1067
+ newValue = selection;
1068
+ } else if (this.hasAttribute("value")) {
1069
+ newValue = this.getAttribute("value");
1070
+ }
1071
+
1072
+ result = setSelection.call(this, newValue);
1073
+
1074
+ requestAnimationFrame(() => {
1075
+ checkOptionState.call(this);
1076
+ setStatusOrRemoveBadges.call(this, "closed");
1077
+ updatePopper.call(this);
1078
+ resolve(result);
1079
+ });
1080
+
1081
+ return;
1082
+ }
1083
+
1084
+ setStatusOrRemoveBadges.call(this, "error");
1085
+ reject(new Error("invalid response"));
1086
+ })
1087
+ .catch((e) => {
1088
+ setStatusOrRemoveBadges.call(this, "error");
1089
+ reject(e);
1090
+ });
1091
+ })
1092
+ .run()
1093
+ .catch((e) => {
1094
+ setStatusOrRemoveBadges.call(this, "error");
1095
+ addErrorAttribute(this, e);
1096
+ reject(e);
1097
+ });
1098
+ });
1102
1099
  }
1103
1100
 
1104
1101
  /**
@@ -1113,68 +1110,66 @@ function fetchIt(url, controlOptions) {
1113
1110
  * @return {object}
1114
1111
  */
1115
1112
  function initOptionsFromArguments() {
1116
- const options = {};
1117
-
1118
- const template = this.getAttribute("data-monster-selected-template");
1119
- if (isString(template)) {
1120
- if (!options["templateMapping"]) options["templateMapping"] = {};
1121
-
1122
- switch (template) {
1123
- case "summary":
1124
- case "default":
1125
- options["templateMapping"]["selected"] = getSummaryTemplate();
1126
- break;
1127
- case "selected":
1128
- options["templateMapping"]["selected"] = getSelectionTemplate();
1129
- break;
1130
- default:
1131
- addErrorAttribute(this, "invalid template, use summary or selected");
1132
- }
1133
- }
1134
-
1135
- return options;
1113
+ const options = {};
1114
+
1115
+ const template = this.getAttribute("data-monster-selected-template");
1116
+ if (isString(template)) {
1117
+ if (!options["templateMapping"]) options["templateMapping"] = {};
1118
+
1119
+ switch (template) {
1120
+ case "summary":
1121
+ case "default":
1122
+ options["templateMapping"]["selected"] = getSummaryTemplate();
1123
+ break;
1124
+ case "selected":
1125
+ options["templateMapping"]["selected"] = getSelectionTemplate();
1126
+ break;
1127
+ default:
1128
+ addErrorAttribute(this, "invalid template, use summary or selected");
1129
+ }
1130
+ }
1131
+
1132
+ return options;
1136
1133
  }
1137
1134
 
1138
1135
  /**
1139
1136
  * @private
1140
1137
  */
1141
1138
  function attachResizeObserver() {
1142
- // against flickering
1143
- this[resizeObserverSymbol] = new ResizeObserver((entries) => {
1144
- if (this[timerCallbackSymbol] instanceof DeadMansSwitch) {
1145
- try {
1146
- this[timerCallbackSymbol].touch();
1147
- return;
1148
- } catch (e) {
1149
- delete this[timerCallbackSymbol];
1150
- }
1151
- }
1152
-
1153
- this[timerCallbackSymbol] = new DeadMansSwitch(200, () => {
1154
- updatePopper.call(this);
1155
- delete this[timerCallbackSymbol];
1156
- });
1157
- });
1158
-
1159
-
1160
- let parent = this.parentNode;
1161
- while (!(parent instanceof HTMLElement) && parent !== null) {
1162
- parent = parent.parentNode;
1163
- }
1164
-
1165
- if (parent instanceof HTMLElement) {
1166
- this[resizeObserverSymbol].observe(parent);
1167
- }
1168
-
1139
+ // against flickering
1140
+ this[resizeObserverSymbol] = new ResizeObserver((entries) => {
1141
+ if (this[timerCallbackSymbol] instanceof DeadMansSwitch) {
1142
+ try {
1143
+ this[timerCallbackSymbol].touch();
1144
+ return;
1145
+ } catch (e) {
1146
+ delete this[timerCallbackSymbol];
1147
+ }
1148
+ }
1149
+
1150
+ this[timerCallbackSymbol] = new DeadMansSwitch(200, () => {
1151
+ updatePopper.call(this);
1152
+ delete this[timerCallbackSymbol];
1153
+ });
1154
+ });
1155
+
1156
+ let parent = this.parentNode;
1157
+ while (!(parent instanceof HTMLElement) && parent !== null) {
1158
+ parent = parent.parentNode;
1159
+ }
1160
+
1161
+ if (parent instanceof HTMLElement) {
1162
+ this[resizeObserverSymbol].observe(parent);
1163
+ }
1169
1164
  }
1170
1165
 
1171
1166
  /**
1172
1167
  * @private
1173
1168
  */
1174
1169
  function disconnectResizeObserver() {
1175
- if (this[resizeObserverSymbol] instanceof ResizeObserver) {
1176
- this[resizeObserverSymbol].disconnect();
1177
- }
1170
+ if (this[resizeObserverSymbol] instanceof ResizeObserver) {
1171
+ this[resizeObserverSymbol].disconnect();
1172
+ }
1178
1173
  }
1179
1174
 
1180
1175
  /**
@@ -1182,7 +1177,7 @@ function disconnectResizeObserver() {
1182
1177
  * @returns {string}
1183
1178
  */
1184
1179
  function getSelectionTemplate() {
1185
- return `<div data-monster-role="selection" part="selection"
1180
+ return `<div data-monster-role="selection" part="selection"
1186
1181
  data-monster-insert="selection path:selection" role="search"
1187
1182
  ><input type="text" role="searchbox"
1188
1183
  part="inline-filter" name="inline-filter"
@@ -1198,7 +1193,7 @@ function getSelectionTemplate() {
1198
1193
  * @returns {string}
1199
1194
  */
1200
1195
  function getSummaryTemplate() {
1201
- return `<div data-monster-role="selection" role="search" part="summary">
1196
+ return `<div data-monster-role="selection" role="search" part="summary">
1202
1197
  <input type="text" role="searchbox"
1203
1198
  part="inline-filter" name="inline-filter"
1204
1199
  data-monster-role="filter"
@@ -1214,35 +1209,35 @@ function getSummaryTemplate() {
1214
1209
  * @private
1215
1210
  */
1216
1211
  function parseSlotsToOptions() {
1217
- let options = this.getOption("options");
1218
- if (!isIterable(options)) {
1219
- options = [];
1220
- }
1221
-
1222
- let counter = 1;
1223
- getSlottedElements.call(this, "div").forEach((node) => {
1224
- let value = (counter++).toString();
1225
- let visibility = "visible";
1226
-
1227
- if (node.hasAttribute("data-monster-value")) {
1228
- value = node.getAttribute("data-monster-value");
1229
- }
1230
-
1231
- let label = node.outerHTML;
1232
-
1233
- if (node.style.display === "none") {
1234
- visibility = "hidden";
1235
- }
1236
-
1237
- options.push({
1238
- value,
1239
- label,
1240
- visibility,
1241
- });
1242
- });
1243
-
1244
- runAsOptionLengthChanged.call(this, options.length);
1245
- this.setOption("options", options);
1212
+ let options = this.getOption("options");
1213
+ if (!isIterable(options)) {
1214
+ options = [];
1215
+ }
1216
+
1217
+ let counter = 1;
1218
+ getSlottedElements.call(this, "div").forEach((node) => {
1219
+ let value = (counter++).toString();
1220
+ let visibility = "visible";
1221
+
1222
+ if (node.hasAttribute("data-monster-value")) {
1223
+ value = node.getAttribute("data-monster-value");
1224
+ }
1225
+
1226
+ let label = node.outerHTML;
1227
+
1228
+ if (node.style.display === "none") {
1229
+ visibility = "hidden";
1230
+ }
1231
+
1232
+ options.push({
1233
+ value,
1234
+ label,
1235
+ visibility,
1236
+ });
1237
+ });
1238
+
1239
+ runAsOptionLengthChanged.call(this, options.length);
1240
+ this.setOption("options", options);
1246
1241
  }
1247
1242
 
1248
1243
  /**
@@ -1252,39 +1247,39 @@ function parseSlotsToOptions() {
1252
1247
  * @param {int} targetLength
1253
1248
  */
1254
1249
  function runAsOptionLengthChanged(targetLength) {
1255
- const self = this;
1256
-
1257
- if (!self[optionsElementSymbol]) {
1258
- return;
1259
- }
1260
-
1261
- const callback = function (mutationsList, observer) {
1262
- const run = false;
1263
- for (const mutation of mutationsList) {
1264
- if (mutation.type === "childList") {
1265
- const run = true;
1266
- break;
1267
- }
1268
- }
1269
-
1270
- if (run === true) {
1271
- const nodes = self[optionsElementSymbol].querySelectorAll(
1272
- `div[${ATTRIBUTE_ROLE}=option]`,
1273
- );
1274
-
1275
- if (nodes.length === targetLength) {
1276
- checkOptionState.call(self);
1277
- observer.disconnect();
1278
- }
1279
- }
1280
- };
1281
-
1282
- const observer = new MutationObserver(callback);
1283
- observer.observe(self[optionsElementSymbol], {
1284
- attributes: false,
1285
- childList: true,
1286
- subtree: true,
1287
- });
1250
+ const self = this;
1251
+
1252
+ if (!self[optionsElementSymbol]) {
1253
+ return;
1254
+ }
1255
+
1256
+ const callback = function (mutationsList, observer) {
1257
+ const run = false;
1258
+ for (const mutation of mutationsList) {
1259
+ if (mutation.type === "childList") {
1260
+ const run = true;
1261
+ break;
1262
+ }
1263
+ }
1264
+
1265
+ if (run === true) {
1266
+ const nodes = self[optionsElementSymbol].querySelectorAll(
1267
+ `div[${ATTRIBUTE_ROLE}=option]`,
1268
+ );
1269
+
1270
+ if (nodes.length === targetLength) {
1271
+ checkOptionState.call(self);
1272
+ observer.disconnect();
1273
+ }
1274
+ }
1275
+ };
1276
+
1277
+ const observer = new MutationObserver(callback);
1278
+ observer.observe(self[optionsElementSymbol], {
1279
+ attributes: false,
1280
+ childList: true,
1281
+ subtree: true,
1282
+ });
1288
1283
  }
1289
1284
 
1290
1285
  /**
@@ -1293,38 +1288,38 @@ function runAsOptionLengthChanged(targetLength) {
1293
1288
  * @return {*}
1294
1289
  */
1295
1290
  function buildSelectionLabel(value) {
1296
- const options = this.getOption("options");
1297
-
1298
- for (let i = 0; i < options.length; i++) {
1299
- let o = options?.[i];
1300
- let l, v, v2;
1301
-
1302
- if (this.getOption("features.useStrictValueComparison") === true) {
1303
- v = value;
1304
- } else {
1305
- v = `${value}`;
1306
- }
1307
-
1308
- if (isPrimitive(o) && o === value) {
1309
- return o;
1310
- } else if (!isObject(o)) {
1311
- continue;
1312
- }
1313
-
1314
- if (this.getOption("features.useStrictValueComparison") === true) {
1315
- l = o?.["label"];
1316
- v2 = o?.["value"];
1317
- } else {
1318
- l = `${o?.["label"]}`;
1319
- v2 = `${o?.["value"]}`;
1320
- }
1321
-
1322
- if (v2 === v) {
1323
- return l;
1324
- }
1325
- }
1326
-
1327
- return undefined;
1291
+ const options = this.getOption("options");
1292
+
1293
+ for (let i = 0; i < options.length; i++) {
1294
+ let o = options?.[i];
1295
+ let l, v, v2;
1296
+
1297
+ if (this.getOption("features.useStrictValueComparison") === true) {
1298
+ v = value;
1299
+ } else {
1300
+ v = `${value}`;
1301
+ }
1302
+
1303
+ if (isPrimitive(o) && o === value) {
1304
+ return o;
1305
+ } else if (!isObject(o)) {
1306
+ continue;
1307
+ }
1308
+
1309
+ if (this.getOption("features.useStrictValueComparison") === true) {
1310
+ l = o?.["label"];
1311
+ v2 = o?.["value"];
1312
+ } else {
1313
+ l = `${o?.["label"]}`;
1314
+ v2 = `${o?.["value"]}`;
1315
+ }
1316
+
1317
+ if (v2 === v) {
1318
+ return l;
1319
+ }
1320
+ }
1321
+
1322
+ return undefined;
1328
1323
  }
1329
1324
 
1330
1325
  /**
@@ -1334,17 +1329,17 @@ function buildSelectionLabel(value) {
1334
1329
  * @throws {Error} no value found
1335
1330
  */
1336
1331
  function getSelectionLabel(value) {
1337
- const callback = this.getOption("formatter.selection");
1338
- if (isFunction(callback)) {
1339
- const label = callback.call(this, value);
1340
- if (isString(label)) return label;
1341
- }
1332
+ const callback = this.getOption("formatter.selection");
1333
+ if (isFunction(callback)) {
1334
+ const label = callback.call(this, value);
1335
+ if (isString(label)) return label;
1336
+ }
1342
1337
 
1343
- if (isString(value) || isInteger(value)) {
1344
- return `${value}`;
1345
- }
1338
+ if (isString(value) || isInteger(value)) {
1339
+ return `${value}`;
1340
+ }
1346
1341
 
1347
- return this.getOption("labels.cannot-be-loaded", value);
1342
+ return this.getOption("labels.cannot-be-loaded", value);
1348
1343
  }
1349
1344
 
1350
1345
  /**
@@ -1352,25 +1347,25 @@ function getSelectionLabel(value) {
1352
1347
  * @param {Event} event
1353
1348
  */
1354
1349
  function handleToggleKeyboardEvents(event) {
1355
- switch (event?.["code"]) {
1356
- case "Escape":
1357
- toggle.call(this);
1358
- event.preventDefault();
1359
- break;
1360
- case "Space":
1361
- toggle.call(this);
1362
- event.preventDefault();
1363
- break;
1364
- case "ArrowDown":
1365
- show.call(this);
1366
- activateCurrentOption.call(this, FOCUS_DIRECTION_DOWN);
1367
- event.preventDefault();
1368
- break;
1369
- case "ArrowUp":
1370
- hide.call(this);
1371
- event.preventDefault();
1372
- break;
1373
- }
1350
+ switch (event?.["code"]) {
1351
+ case "Escape":
1352
+ toggle.call(this);
1353
+ event.preventDefault();
1354
+ break;
1355
+ case "Space":
1356
+ toggle.call(this);
1357
+ event.preventDefault();
1358
+ break;
1359
+ case "ArrowDown":
1360
+ show.call(this);
1361
+ activateCurrentOption.call(this, FOCUS_DIRECTION_DOWN);
1362
+ event.preventDefault();
1363
+ break;
1364
+ case "ArrowUp":
1365
+ hide.call(this);
1366
+ event.preventDefault();
1367
+ break;
1368
+ }
1374
1369
  }
1375
1370
 
1376
1371
  /**
@@ -1380,28 +1375,28 @@ function handleToggleKeyboardEvents(event) {
1380
1375
  * @this CustomElement
1381
1376
  */
1382
1377
  function initOptionObserver() {
1383
- const self = this;
1384
-
1385
- self.attachObserver(
1386
- new Observer(function () {
1387
- new Processing(() => {
1388
- try {
1389
- self.updateI18n();
1390
- } catch (e) {
1391
- addErrorAttribute(self, e);
1392
- setStatusOrRemoveBadges.call(self, "error");
1393
- }
1394
- try {
1395
- areOptionsAvailableAndInit.call(self);
1396
- } catch (e) {
1397
- addErrorAttribute(self, e);
1398
- setStatusOrRemoveBadges.call(self, "error");
1399
- }
1400
-
1401
- setSummaryAndControlText.call(self);
1402
- }).run();
1403
- }),
1404
- );
1378
+ const self = this;
1379
+
1380
+ self.attachObserver(
1381
+ new Observer(function () {
1382
+ new Processing(() => {
1383
+ try {
1384
+ self.updateI18n();
1385
+ } catch (e) {
1386
+ addErrorAttribute(self, e);
1387
+ setStatusOrRemoveBadges.call(self, "error");
1388
+ }
1389
+ try {
1390
+ areOptionsAvailableAndInit.call(self);
1391
+ } catch (e) {
1392
+ addErrorAttribute(self, e);
1393
+ setStatusOrRemoveBadges.call(self, "error");
1394
+ }
1395
+
1396
+ setSummaryAndControlText.call(self);
1397
+ }).run();
1398
+ }),
1399
+ );
1405
1400
  }
1406
1401
 
1407
1402
  /**
@@ -1409,17 +1404,16 @@ function initOptionObserver() {
1409
1404
  * @returns {Translations}
1410
1405
  */
1411
1406
  function getDefaultTranslation() {
1412
- const translation = new Translations("en").assignTranslations(
1413
- this.getOption("labels", {}),
1414
- );
1407
+ const translation = new Translations("en").assignTranslations(
1408
+ this.getOption("labels", {}),
1409
+ );
1415
1410
 
1416
- try {
1417
- const doc = getDocumentTranslations();
1418
- translation.locale = doc.locale;
1419
- } catch (e) {
1420
- }
1411
+ try {
1412
+ const doc = getDocumentTranslations();
1413
+ translation.locale = doc.locale;
1414
+ } catch (e) {}
1421
1415
 
1422
- return translation;
1416
+ return translation;
1423
1417
  }
1424
1418
 
1425
1419
  /**
@@ -1427,36 +1421,36 @@ function getDefaultTranslation() {
1427
1421
  * @return {string|*}
1428
1422
  */
1429
1423
  function setSummaryAndControlText() {
1430
- const translations = getDefaultTranslation.call(this);
1431
- const selections = this.getOption("selection");
1432
-
1433
- const text = translations.getPluralRuleText(
1434
- "summary-text",
1435
- selections.length,
1436
- "",
1437
- );
1438
-
1439
- const selectedText = new Formatter({
1440
- count: String(selections.length),
1441
- }).format(text);
1442
-
1443
- this.setOption("messages.selected", selectedText);
1444
-
1445
- const current = this.getOption("messages.control");
1446
- const msg = this.getOption("labels.select-an-option");
1447
-
1448
- if (
1449
- current === "" ||
1450
- current === undefined ||
1451
- current === msg ||
1452
- current === null
1453
- ) {
1454
- if (selections.length === 0) {
1455
- this.setOption("messages.control", msg);
1456
- } else {
1457
- this.setOption("messages.control", "");
1458
- }
1459
- }
1424
+ const translations = getDefaultTranslation.call(this);
1425
+ const selections = this.getOption("selection");
1426
+
1427
+ const text = translations.getPluralRuleText(
1428
+ "summary-text",
1429
+ selections.length,
1430
+ "",
1431
+ );
1432
+
1433
+ const selectedText = new Formatter({
1434
+ count: String(selections.length),
1435
+ }).format(text);
1436
+
1437
+ this.setOption("messages.selected", selectedText);
1438
+
1439
+ const current = this.getOption("messages.control");
1440
+ const msg = this.getOption("labels.select-an-option");
1441
+
1442
+ if (
1443
+ current === "" ||
1444
+ current === undefined ||
1445
+ current === msg ||
1446
+ current === null
1447
+ ) {
1448
+ if (selections.length === 0) {
1449
+ this.setOption("messages.control", msg);
1450
+ } else {
1451
+ this.setOption("messages.control", "");
1452
+ }
1453
+ }
1460
1454
  }
1461
1455
 
1462
1456
  /**
@@ -1464,9 +1458,9 @@ function setSummaryAndControlText() {
1464
1458
  * @return {NodeList}
1465
1459
  */
1466
1460
  function getOptionElements() {
1467
- return this[optionsElementSymbol].querySelectorAll(
1468
- `[${ATTRIBUTE_ROLE}=option]`,
1469
- );
1461
+ return this[optionsElementSymbol].querySelectorAll(
1462
+ `[${ATTRIBUTE_ROLE}=option]`,
1463
+ );
1470
1464
  }
1471
1465
 
1472
1466
  /**
@@ -1490,75 +1484,75 @@ function getOptionElements() {
1490
1484
  * @private
1491
1485
  */
1492
1486
  function calcAndSetOptionsDimension() {
1493
- const options = getOptionElements.call(this);
1494
- const container = this[optionsElementSymbol];
1495
- if (!(container instanceof HTMLElement && options instanceof NodeList)) {
1496
- return;
1497
- }
1498
-
1499
- let visible = 0;
1500
- let optionHeight = 0;
1501
- const max = this.getOption("showMaxOptions", 10);
1502
-
1503
- let scrollFlag = false;
1504
- for (const [, option] of Object.entries(options)) {
1505
- const computedStyle = getGlobal().getComputedStyle(option);
1506
- if (computedStyle.display === "none") continue;
1507
-
1508
- let h = option.getBoundingClientRect().height;
1509
- h += parseInt(computedStyle.getPropertyValue("margin-top"), 10);
1510
- h += parseInt(computedStyle.getPropertyValue("margin-bottom"), 10);
1511
- optionHeight += h;
1512
-
1513
- visible++;
1514
-
1515
- if (visible > max) {
1516
- break;
1517
- }
1518
- }
1519
-
1520
- if (visible > max) {
1521
- visible = max;
1522
- scrollFlag = true;
1523
- }
1524
-
1525
- if (visible === 0) {
1526
- if (getFilterMode.call(this) === FILTER_MODE_DISABLED) {
1527
- this.setOption(
1528
- "messages.emptyOptions",
1529
- this.getOption("labels.no-options-available"),
1530
- );
1531
- } else {
1532
- this.setOption(
1533
- "messages.emptyOptions",
1534
- this.getOption("labels.no-options-found"),
1535
- );
1536
- }
1537
- this[noOptionsAvailableElementSymbol].classList.remove("d-none");
1538
- } else {
1539
- this[noOptionsAvailableElementSymbol].classList.add("d-none");
1540
- }
1541
-
1542
- const styles = getGlobal().getComputedStyle(this[optionsElementSymbol]);
1543
- let padding = parseInt(styles.getPropertyValue("padding-top"), 10);
1544
- padding += parseInt(styles.getPropertyValue("padding-bottom"), 10);
1545
-
1546
- let margin = parseInt(styles.getPropertyValue("margin-top"), 10);
1547
- margin += parseInt(styles.getPropertyValue("margin-bottom"), 10);
1548
-
1549
- const containerHeight = optionHeight + padding + margin;
1550
- container.style.height = `${containerHeight}px`;
1551
-
1552
- if (scrollFlag === true) {
1553
- container.style.overflowY = "scroll";
1554
- } else {
1555
- container.style.overflowY = "auto";
1556
- }
1557
-
1558
- const domRect = this[controlElementSymbol].getBoundingClientRect();
1559
-
1560
- this[popperElementSymbol].style.width = `${domRect.width}px`;
1561
- container.style.overflowX = "auto";
1487
+ const options = getOptionElements.call(this);
1488
+ const container = this[optionsElementSymbol];
1489
+ if (!(container instanceof HTMLElement && options instanceof NodeList)) {
1490
+ return;
1491
+ }
1492
+
1493
+ let visible = 0;
1494
+ let optionHeight = 0;
1495
+ const max = this.getOption("showMaxOptions", 10);
1496
+
1497
+ let scrollFlag = false;
1498
+ for (const [, option] of Object.entries(options)) {
1499
+ const computedStyle = getGlobal().getComputedStyle(option);
1500
+ if (computedStyle.display === "none") continue;
1501
+
1502
+ let h = option.getBoundingClientRect().height;
1503
+ h += parseInt(computedStyle.getPropertyValue("margin-top"), 10);
1504
+ h += parseInt(computedStyle.getPropertyValue("margin-bottom"), 10);
1505
+ optionHeight += h;
1506
+
1507
+ visible++;
1508
+
1509
+ if (visible > max) {
1510
+ break;
1511
+ }
1512
+ }
1513
+
1514
+ if (visible > max) {
1515
+ visible = max;
1516
+ scrollFlag = true;
1517
+ }
1518
+
1519
+ if (visible === 0) {
1520
+ if (getFilterMode.call(this) === FILTER_MODE_DISABLED) {
1521
+ this.setOption(
1522
+ "messages.emptyOptions",
1523
+ this.getOption("labels.no-options-available"),
1524
+ );
1525
+ } else {
1526
+ this.setOption(
1527
+ "messages.emptyOptions",
1528
+ this.getOption("labels.no-options-found"),
1529
+ );
1530
+ }
1531
+ this[noOptionsAvailableElementSymbol].classList.remove("d-none");
1532
+ } else {
1533
+ this[noOptionsAvailableElementSymbol].classList.add("d-none");
1534
+ }
1535
+
1536
+ const styles = getGlobal().getComputedStyle(this[optionsElementSymbol]);
1537
+ let padding = parseInt(styles.getPropertyValue("padding-top"), 10);
1538
+ padding += parseInt(styles.getPropertyValue("padding-bottom"), 10);
1539
+
1540
+ let margin = parseInt(styles.getPropertyValue("margin-top"), 10);
1541
+ margin += parseInt(styles.getPropertyValue("margin-bottom"), 10);
1542
+
1543
+ const containerHeight = optionHeight + padding + margin;
1544
+ container.style.height = `${containerHeight}px`;
1545
+
1546
+ if (scrollFlag === true) {
1547
+ container.style.overflowY = "scroll";
1548
+ } else {
1549
+ container.style.overflowY = "auto";
1550
+ }
1551
+
1552
+ const domRect = this[controlElementSymbol].getBoundingClientRect();
1553
+
1554
+ this[popperElementSymbol].style.width = `${domRect.width}px`;
1555
+ container.style.overflowX = "auto";
1562
1556
  }
1563
1557
 
1564
1558
  /**
@@ -1567,126 +1561,126 @@ function calcAndSetOptionsDimension() {
1567
1561
  * @throws {Error} no shadow-root is defined
1568
1562
  */
1569
1563
  function activateCurrentOption(direction) {
1570
- if (!this.shadowRoot) {
1571
- throw new Error("no shadow-root is defined");
1572
- }
1573
-
1574
- let focused = this.shadowRoot.querySelector(`[${ATTRIBUTE_PREFIX}focused]`);
1575
-
1576
- if (
1577
- !(focused instanceof HTMLElement) ||
1578
- focused.matches("[data-monster-visibility=hidden]")
1579
- ) {
1580
- for (const [, e] of Object.entries(
1581
- this.shadowRoot.querySelectorAll(`[${ATTRIBUTE_ROLE}=option]`),
1582
- )) {
1583
- if (e.matches("[data-monster-visibility=visible]")) {
1584
- focused = e;
1585
- break;
1586
- }
1587
- }
1588
- } else {
1589
- if (direction === FOCUS_DIRECTION_DOWN) {
1590
- while (focused.nextSibling) {
1591
- focused = focused.nextSibling;
1592
-
1593
- if (
1594
- focused instanceof HTMLElement &&
1595
- focused.hasAttribute(ATTRIBUTE_ROLE) &&
1596
- focused.getAttribute(ATTRIBUTE_ROLE) === "option" &&
1597
- focused.matches("[data-monster-visibility=visible]") &&
1598
- focused.matches(":not([data-monster-filtered=true])")
1599
- ) {
1600
- break;
1601
- }
1602
- }
1603
- } else {
1604
- let found = false;
1605
- while (focused.previousSibling) {
1606
- focused = focused.previousSibling;
1607
- if (
1608
- focused instanceof HTMLElement &&
1609
- focused.hasAttribute(ATTRIBUTE_ROLE) &&
1610
- focused.getAttribute(ATTRIBUTE_ROLE) === "option" &&
1611
- focused.matches("[data-monster-visibility=visible]") &&
1612
- focused.matches(":not([data-monster-filtered=true])")
1613
- ) {
1614
- found = true;
1615
- break;
1616
- }
1617
- }
1618
- if (found === false) {
1619
- focusFilter.call(this);
1620
- }
1621
- }
1622
- }
1623
-
1624
- new Processing(() => {
1625
- if (focused instanceof HTMLElement) {
1626
- this.shadowRoot
1627
- .querySelectorAll(`[${ATTRIBUTE_PREFIX}focused]`)
1628
- .forEach((e) => {
1629
- e.removeAttribute(`${ATTRIBUTE_PREFIX}focused`);
1630
- });
1631
-
1632
- focused.focus();
1633
- focused.setAttribute(`${ATTRIBUTE_PREFIX}focused`, true);
1634
- }
1635
- })
1636
- .run()
1637
- .catch((e) => {
1638
- addErrorAttribute(this, e);
1639
- });
1564
+ if (!this.shadowRoot) {
1565
+ throw new Error("no shadow-root is defined");
1566
+ }
1567
+
1568
+ let focused = this.shadowRoot.querySelector(`[${ATTRIBUTE_PREFIX}focused]`);
1569
+
1570
+ if (
1571
+ !(focused instanceof HTMLElement) ||
1572
+ focused.matches("[data-monster-visibility=hidden]")
1573
+ ) {
1574
+ for (const [, e] of Object.entries(
1575
+ this.shadowRoot.querySelectorAll(`[${ATTRIBUTE_ROLE}=option]`),
1576
+ )) {
1577
+ if (e.matches("[data-monster-visibility=visible]")) {
1578
+ focused = e;
1579
+ break;
1580
+ }
1581
+ }
1582
+ } else {
1583
+ if (direction === FOCUS_DIRECTION_DOWN) {
1584
+ while (focused.nextSibling) {
1585
+ focused = focused.nextSibling;
1586
+
1587
+ if (
1588
+ focused instanceof HTMLElement &&
1589
+ focused.hasAttribute(ATTRIBUTE_ROLE) &&
1590
+ focused.getAttribute(ATTRIBUTE_ROLE) === "option" &&
1591
+ focused.matches("[data-monster-visibility=visible]") &&
1592
+ focused.matches(":not([data-monster-filtered=true])")
1593
+ ) {
1594
+ break;
1595
+ }
1596
+ }
1597
+ } else {
1598
+ let found = false;
1599
+ while (focused.previousSibling) {
1600
+ focused = focused.previousSibling;
1601
+ if (
1602
+ focused instanceof HTMLElement &&
1603
+ focused.hasAttribute(ATTRIBUTE_ROLE) &&
1604
+ focused.getAttribute(ATTRIBUTE_ROLE) === "option" &&
1605
+ focused.matches("[data-monster-visibility=visible]") &&
1606
+ focused.matches(":not([data-monster-filtered=true])")
1607
+ ) {
1608
+ found = true;
1609
+ break;
1610
+ }
1611
+ }
1612
+ if (found === false) {
1613
+ focusFilter.call(this);
1614
+ }
1615
+ }
1616
+ }
1617
+
1618
+ new Processing(() => {
1619
+ if (focused instanceof HTMLElement) {
1620
+ this.shadowRoot
1621
+ .querySelectorAll(`[${ATTRIBUTE_PREFIX}focused]`)
1622
+ .forEach((e) => {
1623
+ e.removeAttribute(`${ATTRIBUTE_PREFIX}focused`);
1624
+ });
1625
+
1626
+ focused.focus();
1627
+ focused.setAttribute(`${ATTRIBUTE_PREFIX}focused`, true);
1628
+ }
1629
+ })
1630
+ .run()
1631
+ .catch((e) => {
1632
+ addErrorAttribute(this, e);
1633
+ });
1640
1634
  }
1641
1635
 
1642
1636
  /**
1643
1637
  * @private
1644
1638
  */
1645
1639
  function filterOptions() {
1646
- new Processing(() => {
1647
- let filterValue;
1648
-
1649
- switch (this.getOption("filter.position")) {
1650
- case FILTER_POSITION_INLINE:
1651
- if (this[inlineFilterElementSymbol] instanceof HTMLElement) {
1652
- filterValue = this[inlineFilterElementSymbol].value.toLowerCase();
1653
- } else {
1654
- return;
1655
- }
1656
-
1657
- break;
1658
- case FILTER_POSITION_POPPER:
1659
- default:
1660
- if (this[popperFilterElementSymbol] instanceof HTMLInputElement) {
1661
- filterValue = this[popperFilterElementSymbol].value.toLowerCase();
1662
- } else {
1663
- return;
1664
- }
1665
- }
1666
-
1667
- const options = this.getOption("options");
1668
- for (const [i, option] of Object.entries(options)) {
1669
- if (option.label.toLowerCase().indexOf(filterValue) === -1) {
1670
- this.setOption(`options.${i}.filtered`, "true");
1671
- } else {
1672
- this.setOption(`options.${i}.filtered`, undefined);
1673
- }
1674
- }
1675
- })
1676
- .run()
1677
- .then(() => {
1678
- new Processing(100, () => {
1679
- calcAndSetOptionsDimension.call(this);
1680
- focusFilter.call(this);
1681
- })
1682
- .run()
1683
- .catch((e) => {
1684
- addErrorAttribute(this, e);
1685
- });
1686
- })
1687
- .catch((e) => {
1688
- addErrorAttribute(this, e);
1689
- });
1640
+ new Processing(() => {
1641
+ let filterValue;
1642
+
1643
+ switch (this.getOption("filter.position")) {
1644
+ case FILTER_POSITION_INLINE:
1645
+ if (this[inlineFilterElementSymbol] instanceof HTMLElement) {
1646
+ filterValue = this[inlineFilterElementSymbol].value.toLowerCase();
1647
+ } else {
1648
+ return;
1649
+ }
1650
+
1651
+ break;
1652
+ case FILTER_POSITION_POPPER:
1653
+ default:
1654
+ if (this[popperFilterElementSymbol] instanceof HTMLInputElement) {
1655
+ filterValue = this[popperFilterElementSymbol].value.toLowerCase();
1656
+ } else {
1657
+ return;
1658
+ }
1659
+ }
1660
+
1661
+ const options = this.getOption("options");
1662
+ for (const [i, option] of Object.entries(options)) {
1663
+ if (option.label.toLowerCase().indexOf(filterValue) === -1) {
1664
+ this.setOption(`options.${i}.filtered`, "true");
1665
+ } else {
1666
+ this.setOption(`options.${i}.filtered`, undefined);
1667
+ }
1668
+ }
1669
+ })
1670
+ .run()
1671
+ .then(() => {
1672
+ new Processing(100, () => {
1673
+ calcAndSetOptionsDimension.call(this);
1674
+ focusFilter.call(this);
1675
+ })
1676
+ .run()
1677
+ .catch((e) => {
1678
+ addErrorAttribute(this, e);
1679
+ });
1680
+ })
1681
+ .catch((e) => {
1682
+ addErrorAttribute(this, e);
1683
+ });
1690
1684
  }
1691
1685
 
1692
1686
  /**
@@ -1694,37 +1688,37 @@ function filterOptions() {
1694
1688
  * @param {Event} event
1695
1689
  */
1696
1690
  function handleFilterKeyboardEvents(event) {
1697
- const shiftKey = event?.["shiftKey"];
1698
-
1699
- switch (event?.["code"]) {
1700
- case "Tab":
1701
- activateCurrentOption.call(this, FOCUS_DIRECTION_DOWN);
1702
- event.preventDefault();
1703
- break;
1704
- case "Escape":
1705
- toggle.call(this);
1706
- event.preventDefault();
1707
- break;
1708
- case "Tab" && shiftKey === true:
1709
- case "ArrowUp":
1710
- activateCurrentOption.call(this, FOCUS_DIRECTION_UP);
1711
- event.preventDefault();
1712
- break;
1713
- case "Tab" && !shiftKey:
1714
- case "ArrowDown":
1715
- activateCurrentOption.call(this, FOCUS_DIRECTION_DOWN);
1716
- event.preventDefault();
1717
- break;
1718
- default:
1719
- if (
1720
- this.getOption("features.lazyLoad") === true &&
1721
- this[lazyLoadDoneSymbol] !== true
1722
- ) {
1723
- this.click();
1724
- }
1725
-
1726
- handleFilterKeyEvents.call(this);
1727
- }
1691
+ const shiftKey = event?.["shiftKey"];
1692
+
1693
+ switch (event?.["code"]) {
1694
+ case "Tab":
1695
+ activateCurrentOption.call(this, FOCUS_DIRECTION_DOWN);
1696
+ event.preventDefault();
1697
+ break;
1698
+ case "Escape":
1699
+ toggle.call(this);
1700
+ event.preventDefault();
1701
+ break;
1702
+ case "Tab" && shiftKey === true:
1703
+ case "ArrowUp":
1704
+ activateCurrentOption.call(this, FOCUS_DIRECTION_UP);
1705
+ event.preventDefault();
1706
+ break;
1707
+ case "Tab" && !shiftKey:
1708
+ case "ArrowDown":
1709
+ activateCurrentOption.call(this, FOCUS_DIRECTION_DOWN);
1710
+ event.preventDefault();
1711
+ break;
1712
+ default:
1713
+ if (
1714
+ this.getOption("features.lazyLoad") === true &&
1715
+ this[lazyLoadDoneSymbol] !== true
1716
+ ) {
1717
+ this.click();
1718
+ }
1719
+
1720
+ handleFilterKeyEvents.call(this);
1721
+ }
1728
1722
  }
1729
1723
 
1730
1724
  /**
@@ -1738,86 +1732,86 @@ function handleFilterKeyboardEvents(event) {
1738
1732
  * @return {void} This method does not return anything.
1739
1733
  */
1740
1734
  function handleFilterKeyEvents() {
1741
- if (this[keyFilterEventSymbol] instanceof DeadMansSwitch) {
1742
- try {
1743
- this[keyFilterEventSymbol].touch();
1744
- return;
1745
- } catch (e) {
1746
- delete this[keyFilterEventSymbol];
1747
- }
1748
- }
1749
-
1750
- this[keyFilterEventSymbol] = new DeadMansSwitch(200, () => {
1751
- if (getFilterMode.call(this) !== FILTER_MODE_REMOTE) {
1752
- filterOptions.call(this);
1753
- } else {
1754
- filterFromRemote.call(this).catch((e) => {
1755
- addErrorAttribute(this, e);
1756
- });
1757
- }
1758
-
1759
- delete this[keyFilterEventSymbol];
1760
- });
1735
+ if (this[keyFilterEventSymbol] instanceof DeadMansSwitch) {
1736
+ try {
1737
+ this[keyFilterEventSymbol].touch();
1738
+ return;
1739
+ } catch (e) {
1740
+ delete this[keyFilterEventSymbol];
1741
+ }
1742
+ }
1743
+
1744
+ this[keyFilterEventSymbol] = new DeadMansSwitch(200, () => {
1745
+ if (getFilterMode.call(this) !== FILTER_MODE_REMOTE) {
1746
+ filterOptions.call(this);
1747
+ } else {
1748
+ filterFromRemote.call(this).catch((e) => {
1749
+ addErrorAttribute(this, e);
1750
+ });
1751
+ }
1752
+
1753
+ delete this[keyFilterEventSymbol];
1754
+ });
1761
1755
  }
1762
1756
 
1763
1757
  /**
1764
1758
  * @private
1765
1759
  */
1766
1760
  function filterFromRemote() {
1767
- if (
1768
- !(this[inlineFilterElementSymbol] instanceof HTMLElement) &&
1769
- !(this[popperFilterElementSymbol] instanceof HTMLElement)
1770
- ) {
1771
- return;
1772
- }
1773
-
1774
- show.call(this);
1775
-
1776
- const url = this.getOption("url");
1777
- if (!url) {
1778
- addErrorAttribute(this, "Missing URL for Remote Filter.");
1779
- return;
1780
- }
1781
-
1782
- let filterValue;
1783
-
1784
- switch (this.getOption("filter.position")) {
1785
- case FILTER_POSITION_INLINE:
1786
- if (this[inlineFilterElementSymbol] instanceof HTMLElement) {
1787
- filterValue = this[inlineFilterElementSymbol].value.toLowerCase();
1788
- }
1789
-
1790
- break;
1791
- case FILTER_POSITION_POPPER:
1792
- default:
1793
- if (this[popperFilterElementSymbol] instanceof HTMLInputElement) {
1794
- filterValue = this[popperFilterElementSymbol].value.toLowerCase();
1795
- }
1796
- }
1797
-
1798
- return filterFromRemoteByValue.call(this, url, filterValue);
1761
+ if (
1762
+ !(this[inlineFilterElementSymbol] instanceof HTMLElement) &&
1763
+ !(this[popperFilterElementSymbol] instanceof HTMLElement)
1764
+ ) {
1765
+ return;
1766
+ }
1767
+
1768
+ show.call(this);
1769
+
1770
+ const url = this.getOption("url");
1771
+ if (!url) {
1772
+ addErrorAttribute(this, "Missing URL for Remote Filter.");
1773
+ return;
1774
+ }
1775
+
1776
+ let filterValue;
1777
+
1778
+ switch (this.getOption("filter.position")) {
1779
+ case FILTER_POSITION_INLINE:
1780
+ if (this[inlineFilterElementSymbol] instanceof HTMLElement) {
1781
+ filterValue = this[inlineFilterElementSymbol].value.toLowerCase();
1782
+ }
1783
+
1784
+ break;
1785
+ case FILTER_POSITION_POPPER:
1786
+ default:
1787
+ if (this[popperFilterElementSymbol] instanceof HTMLInputElement) {
1788
+ filterValue = this[popperFilterElementSymbol].value.toLowerCase();
1789
+ }
1790
+ }
1791
+
1792
+ return filterFromRemoteByValue.call(this, url, filterValue);
1799
1793
  }
1800
1794
 
1801
1795
  function formatURL(url, value) {
1802
- if (value === undefined || value === null || value === "") {
1803
- value = this.getOption("filter.defaultValue");
1804
- if (value === undefined || value === null || value === "") {
1805
- value = disabledRequestMarker.toString();
1806
- }
1807
- }
1808
-
1809
- const formatter = new Formatter({filter: encodeURI(value)});
1810
- const openMarker = this.getOption("filter.marker.open");
1811
- let closeMarker = this.getOption("filter.marker.close");
1812
- if (!closeMarker) {
1813
- closeMarker = openMarker;
1814
- }
1815
-
1816
- if (openMarker && closeMarker) {
1817
- formatter.setMarker(openMarker, closeMarker);
1818
- }
1819
-
1820
- return formatter.format(url);
1796
+ if (value === undefined || value === null || value === "") {
1797
+ value = this.getOption("filter.defaultValue");
1798
+ if (value === undefined || value === null || value === "") {
1799
+ value = disabledRequestMarker.toString();
1800
+ }
1801
+ }
1802
+
1803
+ const formatter = new Formatter({ filter: encodeURI(value) });
1804
+ const openMarker = this.getOption("filter.marker.open");
1805
+ let closeMarker = this.getOption("filter.marker.close");
1806
+ if (!closeMarker) {
1807
+ closeMarker = openMarker;
1808
+ }
1809
+
1810
+ if (openMarker && closeMarker) {
1811
+ formatter.setMarker(openMarker, closeMarker);
1812
+ }
1813
+
1814
+ return formatter.format(url);
1821
1815
  }
1822
1816
 
1823
1817
  /**
@@ -1827,28 +1821,28 @@ function formatURL(url, value) {
1827
1821
  * @returns {Promise<unknown>}
1828
1822
  */
1829
1823
  function filterFromRemoteByValue(optionUrl, value) {
1830
- return new Processing(() => {
1831
- let url = formatURL.call(this, optionUrl, value);
1832
- if (url.indexOf(disabledRequestMarker.toString()) !== -1) {
1833
- return;
1834
- }
1835
-
1836
- fetchIt
1837
- .call(this, url, {
1838
- disableHiding: true,
1839
- })
1840
- .then(() => {
1841
- checkOptionState.call(this);
1842
- show.call(this);
1843
- })
1844
- .catch((e) => {
1845
- throw e;
1846
- });
1847
- })
1848
- .run()
1849
- .catch((e) => {
1850
- throw e;
1851
- });
1824
+ return new Processing(() => {
1825
+ let url = formatURL.call(this, optionUrl, value);
1826
+ if (url.indexOf(disabledRequestMarker.toString()) !== -1) {
1827
+ return;
1828
+ }
1829
+
1830
+ fetchIt
1831
+ .call(this, url, {
1832
+ disableHiding: true,
1833
+ })
1834
+ .then(() => {
1835
+ checkOptionState.call(this);
1836
+ show.call(this);
1837
+ })
1838
+ .catch((e) => {
1839
+ throw e;
1840
+ });
1841
+ })
1842
+ .run()
1843
+ .catch((e) => {
1844
+ throw e;
1845
+ });
1852
1846
  }
1853
1847
 
1854
1848
  /**
@@ -1856,50 +1850,50 @@ function filterFromRemoteByValue(optionUrl, value) {
1856
1850
  * @private
1857
1851
  */
1858
1852
  function handleOptionKeyboardEvents(event) {
1859
- const shiftKey = event?.["shiftKey"];
1860
-
1861
- switch (event?.["code"]) {
1862
- case "Escape":
1863
- toggle.call(this);
1864
- event.preventDefault();
1865
- break;
1866
- case "Enter":
1867
- case "Space":
1868
- const path = event.composedPath();
1869
- const element = path?.[0];
1870
- if (element instanceof HTMLElement) {
1871
- const input = element.getElementsByTagName("input");
1872
- if (!input) {
1873
- return;
1874
- }
1875
- fireEvent(input, "click");
1876
- }
1877
- event.preventDefault();
1878
- break;
1879
-
1880
- case "Tab" && shiftKey === true:
1881
- case "ArrowUp":
1882
- activateCurrentOption.call(this, FOCUS_DIRECTION_UP);
1883
- event.preventDefault();
1884
- break;
1885
-
1886
- case "Tab" && !shiftKey:
1887
- case "ArrowLeft":
1888
- case "ArrowRight":
1889
- // handled by tree select
1890
- break;
1891
- case "ArrowDown":
1892
- activateCurrentOption.call(this, FOCUS_DIRECTION_DOWN);
1893
- event.preventDefault();
1894
- break;
1895
- default:
1896
- const p = event.composedPath();
1897
- if (p?.[0] instanceof HTMLInputElement) {
1898
- return;
1899
- }
1900
- focusFilter.call(this);
1901
- break;
1902
- }
1853
+ const shiftKey = event?.["shiftKey"];
1854
+
1855
+ switch (event?.["code"]) {
1856
+ case "Escape":
1857
+ toggle.call(this);
1858
+ event.preventDefault();
1859
+ break;
1860
+ case "Enter":
1861
+ case "Space":
1862
+ const path = event.composedPath();
1863
+ const element = path?.[0];
1864
+ if (element instanceof HTMLElement) {
1865
+ const input = element.getElementsByTagName("input");
1866
+ if (!input) {
1867
+ return;
1868
+ }
1869
+ fireEvent(input, "click");
1870
+ }
1871
+ event.preventDefault();
1872
+ break;
1873
+
1874
+ case "Tab" && shiftKey === true:
1875
+ case "ArrowUp":
1876
+ activateCurrentOption.call(this, FOCUS_DIRECTION_UP);
1877
+ event.preventDefault();
1878
+ break;
1879
+
1880
+ case "Tab" && !shiftKey:
1881
+ case "ArrowLeft":
1882
+ case "ArrowRight":
1883
+ // handled by tree select
1884
+ break;
1885
+ case "ArrowDown":
1886
+ activateCurrentOption.call(this, FOCUS_DIRECTION_DOWN);
1887
+ event.preventDefault();
1888
+ break;
1889
+ default:
1890
+ const p = event.composedPath();
1891
+ if (p?.[0] instanceof HTMLInputElement) {
1892
+ return;
1893
+ }
1894
+ focusFilter.call(this);
1895
+ break;
1896
+ }
1903
1897
  }
1904
1898
 
1905
1899
  /**
@@ -1907,33 +1901,33 @@ function handleOptionKeyboardEvents(event) {
1907
1901
  * @return {string}
1908
1902
  */
1909
1903
  function getFilterMode() {
1910
- switch (this.getOption("filter.mode")) {
1911
- case FILTER_MODE_OPTIONS:
1912
- return FILTER_MODE_OPTIONS;
1913
- case FILTER_MODE_REMOTE:
1914
- return FILTER_MODE_REMOTE;
1915
- default:
1916
- return FILTER_MODE_DISABLED;
1917
- }
1904
+ switch (this.getOption("filter.mode")) {
1905
+ case FILTER_MODE_OPTIONS:
1906
+ return FILTER_MODE_OPTIONS;
1907
+ case FILTER_MODE_REMOTE:
1908
+ return FILTER_MODE_REMOTE;
1909
+ default:
1910
+ return FILTER_MODE_DISABLED;
1911
+ }
1918
1912
  }
1919
1913
 
1920
1914
  /**
1921
1915
  * @private
1922
1916
  */
1923
1917
  function blurFilter() {
1924
- if (!(this[inlineFilterElementSymbol] instanceof HTMLElement)) {
1925
- return;
1926
- }
1918
+ if (!(this[inlineFilterElementSymbol] instanceof HTMLElement)) {
1919
+ return;
1920
+ }
1927
1921
 
1928
- if (getFilterMode.call(this) === FILTER_MODE_DISABLED) {
1929
- return;
1930
- }
1922
+ if (getFilterMode.call(this) === FILTER_MODE_DISABLED) {
1923
+ return;
1924
+ }
1931
1925
 
1932
- this[popperFilterContainerElementSymbol].classList.remove("active");
1933
- this[popperFilterContainerElementSymbol].blur();
1926
+ this[popperFilterContainerElementSymbol].classList.remove("active");
1927
+ this[popperFilterContainerElementSymbol].blur();
1934
1928
 
1935
- this[inlineFilterElementSymbol].classList.remove("active");
1936
- this[inlineFilterElementSymbol].blur();
1929
+ this[inlineFilterElementSymbol].classList.remove("active");
1930
+ this[inlineFilterElementSymbol].blur();
1937
1931
  }
1938
1932
 
1939
1933
  /**
@@ -1941,25 +1935,25 @@ function blurFilter() {
1941
1935
  * @param focusOptions
1942
1936
  */
1943
1937
  function focusPopperFilter(focusOptions) {
1944
- this[popperFilterContainerElementSymbol].classList.remove("d-none");
1945
- this[popperFilterElementSymbol].classList.add("active");
1946
- this[inlineFilterElementSymbol].classList.remove("active");
1947
- this[inlineFilterElementSymbol].classList.add("d-none");
1948
-
1949
- if (!(this[popperFilterElementSymbol] instanceof HTMLElement)) {
1950
- addErrorAttribute(this, "Missing Popper Filter Element.");
1951
- return;
1952
- }
1953
-
1954
- // visibility is set to visible, because focus() does not work on invisible elements
1955
- // and the class definition is assigned later in the processing
1956
- setTimeout(() => {
1957
- if (focusOptions === undefined || focusOptions === null) {
1958
- this[popperFilterElementSymbol].focus();
1959
- } else {
1960
- this[popperFilterElementSymbol].focus(focusOptions);
1961
- }
1962
- }, 100);
1938
+ this[popperFilterContainerElementSymbol].classList.remove("d-none");
1939
+ this[popperFilterElementSymbol].classList.add("active");
1940
+ this[inlineFilterElementSymbol].classList.remove("active");
1941
+ this[inlineFilterElementSymbol].classList.add("d-none");
1942
+
1943
+ if (!(this[popperFilterElementSymbol] instanceof HTMLElement)) {
1944
+ addErrorAttribute(this, "Missing Popper Filter Element.");
1945
+ return;
1946
+ }
1947
+
1948
+ // visibility is set to visible, because focus() does not work on invisible elements
1949
+ // and the class definition is assigned later in the processing
1950
+ setTimeout(() => {
1951
+ if (focusOptions === undefined || focusOptions === null) {
1952
+ this[popperFilterElementSymbol].focus();
1953
+ } else {
1954
+ this[popperFilterElementSymbol].focus(focusOptions);
1955
+ }
1956
+ }, 100);
1963
1957
  }
1964
1958
 
1965
1959
  /**
@@ -1967,44 +1961,44 @@ function focusPopperFilter(focusOptions) {
1967
1961
  * @param focusOptions
1968
1962
  */
1969
1963
  function focusInlineFilter(focusOptions) {
1970
- const options = this.getOption("options");
1971
- if (
1972
- (!isArray(options) || options.length === 0) &&
1973
- getFilterMode.call(this) !== FILTER_MODE_REMOTE
1974
- ) {
1975
- return;
1976
- }
1977
-
1978
- this[popperFilterContainerElementSymbol].classList.add("d-none");
1979
- this[inlineFilterElementSymbol].classList.add("active");
1980
- this[inlineFilterElementSymbol].classList.remove("d-none");
1981
-
1982
- // visibility is set to visible, because focus() does not work on invisible elements
1983
- // and the class definition is assigned later in the processing
1984
- setTimeout(() => {
1985
- if (focusOptions === undefined || focusOptions === null) {
1986
- this[inlineFilterElementSymbol].focus();
1987
- } else {
1988
- this[inlineFilterElementSymbol].focus(focusOptions);
1989
- }
1990
- }, 100);
1964
+ const options = this.getOption("options");
1965
+ if (
1966
+ (!isArray(options) || options.length === 0) &&
1967
+ getFilterMode.call(this) !== FILTER_MODE_REMOTE
1968
+ ) {
1969
+ return;
1970
+ }
1971
+
1972
+ this[popperFilterContainerElementSymbol].classList.add("d-none");
1973
+ this[inlineFilterElementSymbol].classList.add("active");
1974
+ this[inlineFilterElementSymbol].classList.remove("d-none");
1975
+
1976
+ // visibility is set to visible, because focus() does not work on invisible elements
1977
+ // and the class definition is assigned later in the processing
1978
+ setTimeout(() => {
1979
+ if (focusOptions === undefined || focusOptions === null) {
1980
+ this[inlineFilterElementSymbol].focus();
1981
+ } else {
1982
+ this[inlineFilterElementSymbol].focus(focusOptions);
1983
+ }
1984
+ }, 100);
1991
1985
  }
1992
1986
 
1993
1987
  /**
1994
1988
  * @private
1995
1989
  */
1996
1990
  function focusFilter(focusOptions) {
1997
- if (getFilterMode.call(this) === FILTER_MODE_DISABLED) {
1998
- this[popperFilterContainerElementSymbol].classList.add("d-none");
1999
- this[inlineFilterElementSymbol].classList.add("d-none");
2000
- return;
2001
- }
1991
+ if (getFilterMode.call(this) === FILTER_MODE_DISABLED) {
1992
+ this[popperFilterContainerElementSymbol].classList.add("d-none");
1993
+ this[inlineFilterElementSymbol].classList.add("d-none");
1994
+ return;
1995
+ }
2002
1996
 
2003
- if (this.getOption("filter.position") === FILTER_POSITION_INLINE) {
2004
- return focusInlineFilter.call(this, focusOptions);
2005
- }
1997
+ if (this.getOption("filter.position") === FILTER_POSITION_INLINE) {
1998
+ return focusInlineFilter.call(this, focusOptions);
1999
+ }
2006
2000
 
2007
- return focusPopperFilter.call(this, focusOptions);
2001
+ return focusPopperFilter.call(this, focusOptions);
2008
2002
  }
2009
2003
 
2010
2004
  /**
@@ -2014,40 +2008,39 @@ function focusFilter(focusOptions) {
2014
2008
  * @throws {Error} unsupported type
2015
2009
  */
2016
2010
  function gatherState() {
2017
- const type = this.getOption("type");
2018
- if (["radio", "checkbox"].indexOf(type) === -1) {
2019
- throw new Error("unsupported type");
2020
- }
2021
-
2022
- if (!this.shadowRoot) {
2023
- throw new Error("no shadow-root is defined");
2024
- }
2025
-
2026
- const selection = [];
2027
- const elements = this.shadowRoot.querySelectorAll(
2028
- `input[type=${type}]:checked`,
2029
- );
2030
-
2031
- for (const e of elements) {
2032
- selection.push({
2033
- label: getSelectionLabel.call(this, e.value),
2034
- value: e.value,
2035
- });
2036
- }
2037
-
2038
- setSelection
2039
- .call(this, selection)
2040
- .then(() => {
2041
- })
2042
- .catch((e) => {
2043
- addErrorAttribute(this, e);
2044
- });
2045
-
2046
- if (this.getOption("features.closeOnSelect") === true) {
2047
- toggle.call(this);
2048
- }
2049
-
2050
- return this;
2011
+ const type = this.getOption("type");
2012
+ if (["radio", "checkbox"].indexOf(type) === -1) {
2013
+ throw new Error("unsupported type");
2014
+ }
2015
+
2016
+ if (!this.shadowRoot) {
2017
+ throw new Error("no shadow-root is defined");
2018
+ }
2019
+
2020
+ const selection = [];
2021
+ const elements = this.shadowRoot.querySelectorAll(
2022
+ `input[type=${type}]:checked`,
2023
+ );
2024
+
2025
+ for (const e of elements) {
2026
+ selection.push({
2027
+ label: getSelectionLabel.call(this, e.value),
2028
+ value: e.value,
2029
+ });
2030
+ }
2031
+
2032
+ setSelection
2033
+ .call(this, selection)
2034
+ .then(() => {})
2035
+ .catch((e) => {
2036
+ addErrorAttribute(this, e);
2037
+ });
2038
+
2039
+ if (this.getOption("features.closeOnSelect") === true) {
2040
+ toggle.call(this);
2041
+ }
2042
+
2043
+ return this;
2051
2044
  }
2052
2045
 
2053
2046
  /**
@@ -2056,121 +2049,120 @@ function gatherState() {
2056
2049
  * @throws {Error} unsupported type
2057
2050
  */
2058
2051
  function clearSelection() {
2059
- const type = this.getOption("type");
2060
- if (["radio", "checkbox"].indexOf(type) === -1) {
2061
- throw new Error("unsupported type");
2062
- }
2063
-
2064
- if (!this.shadowRoot) {
2065
- throw new Error("no shadow-root is defined");
2066
- }
2067
-
2068
- setSelection
2069
- .call(this, [])
2070
- .then(() => {
2071
- })
2072
- .catch((e) => {
2073
- addErrorAttribute(this, e);
2074
- });
2052
+ const type = this.getOption("type");
2053
+ if (["radio", "checkbox"].indexOf(type) === -1) {
2054
+ throw new Error("unsupported type");
2055
+ }
2056
+
2057
+ if (!this.shadowRoot) {
2058
+ throw new Error("no shadow-root is defined");
2059
+ }
2060
+
2061
+ setSelection
2062
+ .call(this, [])
2063
+ .then(() => {})
2064
+ .catch((e) => {
2065
+ addErrorAttribute(this, e);
2066
+ });
2075
2067
  }
2076
2068
 
2077
2069
  /**
2078
2070
  * @private
2079
2071
  */
2080
2072
  function areOptionsAvailableAndInit() {
2081
- // prevent multiple calls
2082
- if (this[areOptionsAvailableAndInitSymbol] === undefined) {
2083
- this[areOptionsAvailableAndInitSymbol] = 0;
2084
- }
2085
-
2086
- if (this[areOptionsAvailableAndInitSymbol] > 0) {
2087
- this[areOptionsAvailableAndInitSymbol]--;
2088
- return true;
2089
- }
2090
-
2091
- this[areOptionsAvailableAndInitSymbol]++;
2092
-
2093
- const options = this.getOption("options");
2094
-
2095
- if (
2096
- options === undefined ||
2097
- options === null ||
2098
- (isArray(options) && options.length === 0)
2099
- ) {
2100
- setStatusOrRemoveBadges.call(this, "empty");
2101
-
2102
- // hide.call(this);
2103
-
2104
- let msg = this.getOption("labels.no-options-available");
2105
-
2106
- if (
2107
- this.getOption("url") !== null &&
2108
- this.getOption("features.lazyLoad") === true &&
2109
- this[lazyLoadDoneSymbol] !== true
2110
- ) {
2111
- msg = this.getOption("labels.click-to-load-options");
2112
- }
2113
-
2114
- this.setOption("messages.control", msg);
2115
- this.setOption("messages.summary", "");
2116
-
2117
- if (this.getOption("features.emptyValueIfNoOptions") === true) {
2118
- this.value = "";
2119
- }
2120
- addErrorAttribute(this, "No options available.");
2121
- return false;
2122
- }
2123
-
2124
- const selections = this.getOption("selection");
2125
- if (
2126
- selections === undefined ||
2127
- selections === null ||
2128
- selections.length === 0
2129
- ) {
2130
- this.setOption(
2131
- "messages.control",
2132
- this.getOption("labels.select-an-option"),
2133
- );
2134
- } else {
2135
- this.setOption("messages.control", "");
2136
- }
2137
-
2138
- this.setOption("messages.summary", setSummaryAndControlText.call(this));
2139
-
2140
- let updated = false;
2141
- let valueCounter = 1;
2142
- for (const option of options) {
2143
- if (option?.visibility === undefined) {
2144
- option.visibility = "visible";
2145
- updated = true;
2146
- }
2147
-
2148
- if (option?.value === undefined && option?.label === undefined) {
2149
- option.value = `${valueCounter++}`;
2150
- option.label = option.value;
2151
- updated = true;
2152
- continue;
2153
- }
2154
-
2155
- if (option?.value === undefined) {
2156
- option.value = option.label;
2157
- updated = true;
2158
- }
2159
-
2160
- if (option?.label === undefined) {
2161
- option.label = option.value;
2162
- updated = true;
2163
- }
2164
- }
2165
-
2166
- if (updated) {
2167
- this.setOption("options", options);
2168
- }
2169
-
2170
- setStatusOrRemoveBadges.call(this);
2171
-
2172
- removeErrorAttribute(this, "No options available.");
2173
- return true;
2073
+ // prevent multiple calls
2074
+ if (this[areOptionsAvailableAndInitSymbol] === undefined) {
2075
+ this[areOptionsAvailableAndInitSymbol] = 0;
2076
+ }
2077
+
2078
+ if (this[areOptionsAvailableAndInitSymbol] > 0) {
2079
+ this[areOptionsAvailableAndInitSymbol]--;
2080
+ return true;
2081
+ }
2082
+
2083
+ this[areOptionsAvailableAndInitSymbol]++;
2084
+
2085
+ const options = this.getOption("options");
2086
+
2087
+ if (
2088
+ options === undefined ||
2089
+ options === null ||
2090
+ (isArray(options) && options.length === 0)
2091
+ ) {
2092
+ setStatusOrRemoveBadges.call(this, "empty");
2093
+
2094
+ // hide.call(this);
2095
+
2096
+ let msg = this.getOption("labels.no-options-available");
2097
+
2098
+ if (
2099
+ this.getOption("url") !== null &&
2100
+ this.getOption("features.lazyLoad") === true &&
2101
+ this[lazyLoadDoneSymbol] !== true
2102
+ ) {
2103
+ msg = this.getOption("labels.click-to-load-options");
2104
+ }
2105
+
2106
+ this.setOption("messages.control", msg);
2107
+ this.setOption("messages.summary", "");
2108
+
2109
+ if (this.getOption("features.emptyValueIfNoOptions") === true) {
2110
+ this.value = "";
2111
+ }
2112
+ addErrorAttribute(this, "No options available.");
2113
+ return false;
2114
+ }
2115
+
2116
+ const selections = this.getOption("selection");
2117
+ if (
2118
+ selections === undefined ||
2119
+ selections === null ||
2120
+ selections.length === 0
2121
+ ) {
2122
+ this.setOption(
2123
+ "messages.control",
2124
+ this.getOption("labels.select-an-option"),
2125
+ );
2126
+ } else {
2127
+ this.setOption("messages.control", "");
2128
+ }
2129
+
2130
+ this.setOption("messages.summary", setSummaryAndControlText.call(this));
2131
+
2132
+ let updated = false;
2133
+ let valueCounter = 1;
2134
+ for (const option of options) {
2135
+ if (option?.visibility === undefined) {
2136
+ option.visibility = "visible";
2137
+ updated = true;
2138
+ }
2139
+
2140
+ if (option?.value === undefined && option?.label === undefined) {
2141
+ option.value = `${valueCounter++}`;
2142
+ option.label = option.value;
2143
+ updated = true;
2144
+ continue;
2145
+ }
2146
+
2147
+ if (option?.value === undefined) {
2148
+ option.value = option.label;
2149
+ updated = true;
2150
+ }
2151
+
2152
+ if (option?.label === undefined) {
2153
+ option.label = option.value;
2154
+ updated = true;
2155
+ }
2156
+ }
2157
+
2158
+ if (updated) {
2159
+ this.setOption("options", options);
2160
+ }
2161
+
2162
+ setStatusOrRemoveBadges.call(this);
2163
+
2164
+ removeErrorAttribute(this, "No options available.");
2165
+ return true;
2174
2166
  }
2175
2167
 
2176
2168
  /**
@@ -2178,30 +2170,30 @@ function areOptionsAvailableAndInit() {
2178
2170
  * @throws {Error} no shadow-root is defined
2179
2171
  */
2180
2172
  function checkOptionState() {
2181
- if (!this.shadowRoot) {
2182
- throw new Error("no shadow-root is defined");
2183
- }
2184
-
2185
- const elements = this.shadowRoot.querySelectorAll(
2186
- `[${ATTRIBUTE_ROLE}=option] input`,
2187
- );
2188
-
2189
- let selection = this.getOption("selection");
2190
- if (!isArray(selection)) {
2191
- selection = [];
2192
- }
2193
-
2194
- const checkedValues = selection.map((a) => {
2195
- return a.value;
2196
- });
2197
-
2198
- for (const e of elements) {
2199
- if (checkedValues.indexOf(e.value) !== -1) {
2200
- if (e.checked !== true) e.checked = true;
2201
- } else {
2202
- if (e.checked !== false) e.checked = false;
2203
- }
2204
- }
2173
+ if (!this.shadowRoot) {
2174
+ throw new Error("no shadow-root is defined");
2175
+ }
2176
+
2177
+ const elements = this.shadowRoot.querySelectorAll(
2178
+ `[${ATTRIBUTE_ROLE}=option] input`,
2179
+ );
2180
+
2181
+ let selection = this.getOption("selection");
2182
+ if (!isArray(selection)) {
2183
+ selection = [];
2184
+ }
2185
+
2186
+ const checkedValues = selection.map((a) => {
2187
+ return a.value;
2188
+ });
2189
+
2190
+ for (const e of elements) {
2191
+ if (checkedValues.indexOf(e.value) !== -1) {
2192
+ if (e.checked !== true) e.checked = true;
2193
+ } else {
2194
+ if (e.checked !== false) e.checked = false;
2195
+ }
2196
+ }
2205
2197
  }
2206
2198
 
2207
2199
  /**
@@ -2210,41 +2202,41 @@ function checkOptionState() {
2210
2202
  * @return {Object}
2211
2203
  */
2212
2204
  function convertValueToSelection(value) {
2213
- const selection = [];
2214
-
2215
- if (isString(value)) {
2216
- value = value
2217
- .split(",")
2218
- .map((a) => {
2219
- return a.trim();
2220
- })
2221
- .filter((a) => {
2222
- return a !== "";
2223
- });
2224
- }
2225
-
2226
- if (isString(value) || isInteger(value)) {
2227
- selection.push({
2228
- label: getSelectionLabel.call(this, value),
2229
- value: value,
2230
- });
2231
- } else if (isArray(value)) {
2232
- for (const v of value) {
2233
- selection.push({
2234
- label: getSelectionLabel.call(this, v),
2235
- value: v,
2236
- });
2237
- }
2238
-
2239
- value = value.join(",");
2240
- } else {
2241
- throw new Error("unsupported type");
2242
- }
2243
-
2244
- return {
2245
- selection: selection,
2246
- value: value,
2247
- };
2205
+ const selection = [];
2206
+
2207
+ if (isString(value)) {
2208
+ value = value
2209
+ .split(",")
2210
+ .map((a) => {
2211
+ return a.trim();
2212
+ })
2213
+ .filter((a) => {
2214
+ return a !== "";
2215
+ });
2216
+ }
2217
+
2218
+ if (isString(value) || isInteger(value)) {
2219
+ selection.push({
2220
+ label: getSelectionLabel.call(this, value),
2221
+ value: value,
2222
+ });
2223
+ } else if (isArray(value)) {
2224
+ for (const v of value) {
2225
+ selection.push({
2226
+ label: getSelectionLabel.call(this, v),
2227
+ value: v,
2228
+ });
2229
+ }
2230
+
2231
+ value = value.join(",");
2232
+ } else {
2233
+ throw new Error("unsupported type");
2234
+ }
2235
+
2236
+ return {
2237
+ selection: selection,
2238
+ value: value,
2239
+ };
2248
2240
  }
2249
2241
 
2250
2242
  /**
@@ -2253,25 +2245,25 @@ function convertValueToSelection(value) {
2253
2245
  * @return {string}
2254
2246
  */
2255
2247
  function convertSelectionToValue(selection) {
2256
- const value = [];
2257
-
2258
- if (isArray(selection)) {
2259
- for (const obj of selection) {
2260
- const v = obj?.["value"];
2261
- if (v !== undefined) value.push(`${v}`);
2262
- }
2263
- }
2264
-
2265
- if (value.length === 0) {
2266
- return "";
2267
- } else if (value.length === 1) {
2268
- const v = value.pop();
2269
- if (v === undefined) return "";
2270
- if (v === null) return "";
2271
- return `${v}`;
2272
- }
2273
-
2274
- return value.join(",");
2248
+ const value = [];
2249
+
2250
+ if (isArray(selection)) {
2251
+ for (const obj of selection) {
2252
+ const v = obj?.["value"];
2253
+ if (v !== undefined) value.push(`${v}`);
2254
+ }
2255
+ }
2256
+
2257
+ if (value.length === 0) {
2258
+ return "";
2259
+ } else if (value.length === 1) {
2260
+ const v = value.pop();
2261
+ if (v === undefined) return "";
2262
+ if (v === null) return "";
2263
+ return `${v}`;
2264
+ }
2265
+
2266
+ return value.join(",");
2275
2267
  }
2276
2268
 
2277
2269
  /**
@@ -2280,16 +2272,15 @@ function convertSelectionToValue(selection) {
2280
2272
  * @returns {boolean}
2281
2273
  */
2282
2274
  function isValueIsEmpty(value) {
2283
- let equivalents = this.getOption("empty.equivalents");
2284
- if (!isArray(equivalents)) {
2285
- if (equivalents === undefined) {
2286
- return false;
2287
- }
2288
- equivalents = [equivalents];
2289
- }
2290
-
2291
- return equivalents.indexOf(value) !== -1;
2292
-
2275
+ let equivalents = this.getOption("empty.equivalents");
2276
+ if (!isArray(equivalents)) {
2277
+ if (equivalents === undefined) {
2278
+ return false;
2279
+ }
2280
+ equivalents = [equivalents];
2281
+ }
2282
+
2283
+ return equivalents.indexOf(value) !== -1;
2293
2284
  }
2294
2285
 
2295
2286
  /**
@@ -2298,19 +2289,18 @@ function isValueIsEmpty(value) {
2298
2289
  * @returns {*}
2299
2290
  */
2300
2291
  function isValueIsEmptyThenGetNormalize(value) {
2301
- let emptyDefault = null
2302
- if (this.getOption("type") === "checkbox") {
2303
- emptyDefault = this.getOption("empty.defaultValueCheckbox");
2304
- } else {
2305
- emptyDefault = this.getOption("empty.defaultValueRadio");
2306
- }
2307
-
2308
- if (isValueIsEmpty.call(this, value)) {
2309
- return emptyDefault;
2310
- }
2311
-
2312
- return value;
2313
-
2292
+ let emptyDefault = null;
2293
+ if (this.getOption("type") === "checkbox") {
2294
+ emptyDefault = this.getOption("empty.defaultValueCheckbox");
2295
+ } else {
2296
+ emptyDefault = this.getOption("empty.defaultValueRadio");
2297
+ }
2298
+
2299
+ if (isValueIsEmpty.call(this, value)) {
2300
+ return emptyDefault;
2301
+ }
2302
+
2303
+ return value;
2314
2304
  }
2315
2305
 
2316
2306
  /**
@@ -2319,99 +2309,97 @@ function isValueIsEmptyThenGetNormalize(value) {
2319
2309
  * @returns {Promise<unknown | void>}
2320
2310
  */
2321
2311
  function setSelection(selection) {
2322
- const self = this;
2323
-
2324
- selection = isValueIsEmptyThenGetNormalize.call(this, selection);
2325
-
2326
- if (isString(selection) || isInteger(selection)) {
2327
- const result = convertValueToSelection.call(this, selection);
2328
- selection = result?.selection;
2329
- }
2330
-
2331
- validateArray(selection);
2332
-
2333
- let resultSelection = [];
2334
- for (let i = 0; i < selection.length; i++) {
2335
-
2336
- if (isValueIsEmpty.call(this, selection[i].value)) {
2337
- continue
2338
- }
2339
-
2340
- let l = getSelectionLabel.call(this, selection[i].value);
2341
- if (l === selection[i].value) {
2342
- l = selection[i].label;
2343
- }
2344
-
2345
- resultSelection.push({
2346
- label: l,
2347
- value: selection[i].value,
2348
- });
2349
- }
2350
-
2351
- selection = resultSelection;
2352
-
2353
- this.setOption("selection", selection);
2354
-
2355
- checkOptionState.call(this);
2356
- setSummaryAndControlText.call(this);
2357
-
2358
- try {
2359
- this?.setFormValue(this.value);
2360
- } catch (e) {
2361
- addErrorAttribute(this, e);
2362
- }
2363
-
2364
- fireCustomEvent(this, "monster-selected", {
2365
- selection,
2366
- });
2367
-
2368
- fireEvent(this, "change"); // https://gitlab.schukai.com/oss/libraries/javascript/monster/-/issues/291
2369
-
2370
- if(this[runLookupOnceSymbol] !== true && selection.length > 0) {
2371
-
2372
- this[runLookupOnceSymbol] = true
2373
-
2374
- const lazyLoadFlag =
2375
- this.getOption("features.lazyLoad") && this[lazyLoadDoneSymbol] !== true;
2376
- let remoteFilterFlag = getFilterMode.call(this) === FILTER_MODE_REMOTE;
2377
- if (lazyLoadFlag || remoteFilterFlag) {
2378
- lookupSelection.call(self);
2379
- }
2380
- }
2381
-
2382
- return new Processing(() => {
2383
- const CLASSNAME = "selected";
2384
-
2385
- if (!this.shadowRoot) {
2386
- throw new Error("no shadow-root is defined");
2387
- }
2388
-
2389
- const notSelected = this.shadowRoot.querySelectorAll(":not(:checked)");
2390
-
2391
- if (notSelected) {
2392
- notSelected.forEach((node) => {
2393
- const parent = node.closest(`[${ATTRIBUTE_ROLE}=option]`);
2394
- if (parent) {
2395
- parent.classList.remove(CLASSNAME);
2396
- }
2397
- });
2398
- }
2399
-
2400
- const selected = this.shadowRoot.querySelectorAll(":checked");
2401
-
2402
- if (selected) {
2403
- selected.forEach((node) => {
2404
- const parent = node.closest(`[${ATTRIBUTE_ROLE}=option]`);
2405
- if (parent) {
2406
- parent.classList.add(CLASSNAME);
2407
- }
2408
- });
2409
- }
2410
- })
2411
- .run()
2412
- .catch((e) => {
2413
- addErrorAttribute(this, e);
2414
- });
2312
+ const self = this;
2313
+
2314
+ selection = isValueIsEmptyThenGetNormalize.call(this, selection);
2315
+
2316
+ if (isString(selection) || isInteger(selection)) {
2317
+ const result = convertValueToSelection.call(this, selection);
2318
+ selection = result?.selection;
2319
+ }
2320
+
2321
+ validateArray(selection);
2322
+
2323
+ let resultSelection = [];
2324
+ for (let i = 0; i < selection.length; i++) {
2325
+ if (isValueIsEmpty.call(this, selection[i].value)) {
2326
+ continue;
2327
+ }
2328
+
2329
+ let l = getSelectionLabel.call(this, selection[i].value);
2330
+ if (l === selection[i].value) {
2331
+ l = selection[i].label;
2332
+ }
2333
+
2334
+ resultSelection.push({
2335
+ label: l,
2336
+ value: selection[i].value,
2337
+ });
2338
+ }
2339
+
2340
+ selection = resultSelection;
2341
+
2342
+ this.setOption("selection", selection);
2343
+
2344
+ checkOptionState.call(this);
2345
+ setSummaryAndControlText.call(this);
2346
+
2347
+ try {
2348
+ this?.setFormValue(this.value);
2349
+ } catch (e) {
2350
+ addErrorAttribute(this, e);
2351
+ }
2352
+
2353
+ fireCustomEvent(this, "monster-selected", {
2354
+ selection,
2355
+ });
2356
+
2357
+ fireEvent(this, "change"); // https://gitlab.schukai.com/oss/libraries/javascript/monster/-/issues/291
2358
+
2359
+ if (this[runLookupOnceSymbol] !== true && selection.length > 0) {
2360
+ this[runLookupOnceSymbol] = true;
2361
+
2362
+ const lazyLoadFlag =
2363
+ this.getOption("features.lazyLoad") && this[lazyLoadDoneSymbol] !== true;
2364
+ let remoteFilterFlag = getFilterMode.call(this) === FILTER_MODE_REMOTE;
2365
+ if (lazyLoadFlag || remoteFilterFlag) {
2366
+ lookupSelection.call(self);
2367
+ }
2368
+ }
2369
+
2370
+ return new Processing(() => {
2371
+ const CLASSNAME = "selected";
2372
+
2373
+ if (!this.shadowRoot) {
2374
+ throw new Error("no shadow-root is defined");
2375
+ }
2376
+
2377
+ const notSelected = this.shadowRoot.querySelectorAll(":not(:checked)");
2378
+
2379
+ if (notSelected) {
2380
+ notSelected.forEach((node) => {
2381
+ const parent = node.closest(`[${ATTRIBUTE_ROLE}=option]`);
2382
+ if (parent) {
2383
+ parent.classList.remove(CLASSNAME);
2384
+ }
2385
+ });
2386
+ }
2387
+
2388
+ const selected = this.shadowRoot.querySelectorAll(":checked");
2389
+
2390
+ if (selected) {
2391
+ selected.forEach((node) => {
2392
+ const parent = node.closest(`[${ATTRIBUTE_ROLE}=option]`);
2393
+ if (parent) {
2394
+ parent.classList.add(CLASSNAME);
2395
+ }
2396
+ });
2397
+ }
2398
+ })
2399
+ .run()
2400
+ .catch((e) => {
2401
+ addErrorAttribute(this, e);
2402
+ });
2415
2403
  }
2416
2404
 
2417
2405
  /**
@@ -2422,139 +2410,139 @@ function setSelection(selection) {
2422
2410
  * @throws {TypeError} unsupported response
2423
2411
  */
2424
2412
  function fetchData(url) {
2425
- const self = this;
2426
- if (!url) url = this.getOption("url");
2427
- if (!url) return Promise.resolve();
2428
-
2429
- const fetchOptions = this.getOption("fetch", {});
2430
-
2431
- let delayWatch = false;
2432
-
2433
- // if fetch short time, do not show loading badge, because of flickering
2434
- requestAnimationFrame(() => {
2435
- if (delayWatch === true) return;
2436
- setStatusOrRemoveBadges.call(this, "loading");
2437
- delayWatch = true;
2438
- });
2439
-
2440
- url = formatURL.call(this, url);
2441
-
2442
- self[isLoadingSymbol] = true;
2443
- const global = getGlobal();
2444
- return global
2445
- .fetch(url, fetchOptions)
2446
- .then((response) => {
2447
- self[isLoadingSymbol] = false;
2448
- delayWatch = true;
2449
- const contentType = response.headers.get("content-type");
2450
- if (contentType && contentType.indexOf("application/json") !== -1) {
2451
- return response.text();
2452
- }
2453
-
2454
- throw new TypeError(`unsupported response ${contentType}`);
2455
- })
2456
- .then((text) => {
2457
- try {
2458
- return Promise.resolve(JSON.parse(String(text)));
2459
- } catch (e) {
2460
- throw new TypeError("the result cannot be parsed, check the URL");
2461
- }
2462
- })
2463
- .catch((e) => {
2464
- self[isLoadingSymbol] = false;
2465
- delayWatch = true;
2466
- throw e;
2467
- });
2413
+ const self = this;
2414
+ if (!url) url = this.getOption("url");
2415
+ if (!url) return Promise.resolve();
2416
+
2417
+ const fetchOptions = this.getOption("fetch", {});
2418
+
2419
+ let delayWatch = false;
2420
+
2421
+ // if fetch short time, do not show loading badge, because of flickering
2422
+ requestAnimationFrame(() => {
2423
+ if (delayWatch === true) return;
2424
+ setStatusOrRemoveBadges.call(this, "loading");
2425
+ delayWatch = true;
2426
+ });
2427
+
2428
+ url = formatURL.call(this, url);
2429
+
2430
+ self[isLoadingSymbol] = true;
2431
+ const global = getGlobal();
2432
+ return global
2433
+ .fetch(url, fetchOptions)
2434
+ .then((response) => {
2435
+ self[isLoadingSymbol] = false;
2436
+ delayWatch = true;
2437
+ const contentType = response.headers.get("content-type");
2438
+ if (contentType && contentType.indexOf("application/json") !== -1) {
2439
+ return response.text();
2440
+ }
2441
+
2442
+ throw new TypeError(`unsupported response ${contentType}`);
2443
+ })
2444
+ .then((text) => {
2445
+ try {
2446
+ return Promise.resolve(JSON.parse(String(text)));
2447
+ } catch (e) {
2448
+ throw new TypeError("the result cannot be parsed, check the URL");
2449
+ }
2450
+ })
2451
+ .catch((e) => {
2452
+ self[isLoadingSymbol] = false;
2453
+ delayWatch = true;
2454
+ throw e;
2455
+ });
2468
2456
  }
2469
2457
 
2470
2458
  /**
2471
2459
  * @private
2472
2460
  */
2473
2461
  function hide() {
2474
- this[popperElementSymbol].style.display = "none";
2475
- setStatusOrRemoveBadges.call(this, "closed");
2476
- removeAttributeToken(this[controlElementSymbol], "class", "open");
2462
+ this[popperElementSymbol].style.display = "none";
2463
+ setStatusOrRemoveBadges.call(this, "closed");
2464
+ removeAttributeToken(this[controlElementSymbol], "class", "open");
2477
2465
  }
2478
2466
 
2479
2467
  /**
2480
2468
  * @private
2481
2469
  */
2482
2470
  function show() {
2483
- if (this.getOption("disabled", undefined) === true) {
2484
- return;
2485
- }
2486
-
2487
- if (this[popperElementSymbol].style.display === STYLE_DISPLAY_MODE_BLOCK) {
2488
- return;
2489
- }
2490
-
2491
- focusFilter.call(this);
2492
-
2493
- const lazyLoadFlag =
2494
- this.getOption("features.lazyLoad") && this[lazyLoadDoneSymbol] !== true;
2495
-
2496
- if (lazyLoadFlag === true) {
2497
- this[lazyLoadDoneSymbol] = true;
2498
- setStatusOrRemoveBadges.call(this, "loading");
2499
-
2500
- new Processing(200, () => {
2501
- this.fetch()
2502
- .then(() => {
2503
- checkOptionState.call(this);
2504
- requestAnimationFrame(() => {
2505
- show.call(this);
2506
- });
2507
- })
2508
- .catch((e) => {
2509
- addErrorAttribute(this, e);
2510
- setStatusOrRemoveBadges.call(this, "error");
2511
- });
2512
- })
2513
- .run()
2514
- .catch((e) => {
2515
- addErrorAttribute(this, e);
2516
- setStatusOrRemoveBadges.call(this, "error");
2517
- });
2518
-
2519
- return;
2520
- }
2521
-
2522
- const hasPopperFilterFlag =
2523
- this.getOption("filter.position") === FILTER_POSITION_POPPER &&
2524
- getFilterMode.call(this) !== FILTER_MODE_DISABLED;
2525
-
2526
- const options = getOptionElements.call(this);
2527
- if (options.length === 0 && hasPopperFilterFlag === false) {
2528
- return;
2529
- }
2530
-
2531
- this[popperElementSymbol].style.visibility = "hidden";
2532
- this[popperElementSymbol].style.display = STYLE_DISPLAY_MODE_BLOCK;
2533
- setStatusOrRemoveBadges.call(this, "open");
2534
-
2535
- addAttributeToken(this[controlElementSymbol], "class", "open");
2536
-
2537
- new Processing(() => {
2538
- calcAndSetOptionsDimension.call(this);
2539
- focusFilter.call(this);
2540
- this[popperElementSymbol].style.removeProperty("visibility");
2541
- updatePopper.call(this);
2542
- })
2543
- .run()
2544
- .catch((e) => {
2545
- addErrorAttribute(this, e);
2546
- });
2471
+ if (this.getOption("disabled", undefined) === true) {
2472
+ return;
2473
+ }
2474
+
2475
+ if (this[popperElementSymbol].style.display === STYLE_DISPLAY_MODE_BLOCK) {
2476
+ return;
2477
+ }
2478
+
2479
+ focusFilter.call(this);
2480
+
2481
+ const lazyLoadFlag =
2482
+ this.getOption("features.lazyLoad") && this[lazyLoadDoneSymbol] !== true;
2483
+
2484
+ if (lazyLoadFlag === true) {
2485
+ this[lazyLoadDoneSymbol] = true;
2486
+ setStatusOrRemoveBadges.call(this, "loading");
2487
+
2488
+ new Processing(200, () => {
2489
+ this.fetch()
2490
+ .then(() => {
2491
+ checkOptionState.call(this);
2492
+ requestAnimationFrame(() => {
2493
+ show.call(this);
2494
+ });
2495
+ })
2496
+ .catch((e) => {
2497
+ addErrorAttribute(this, e);
2498
+ setStatusOrRemoveBadges.call(this, "error");
2499
+ });
2500
+ })
2501
+ .run()
2502
+ .catch((e) => {
2503
+ addErrorAttribute(this, e);
2504
+ setStatusOrRemoveBadges.call(this, "error");
2505
+ });
2506
+
2507
+ return;
2508
+ }
2509
+
2510
+ const hasPopperFilterFlag =
2511
+ this.getOption("filter.position") === FILTER_POSITION_POPPER &&
2512
+ getFilterMode.call(this) !== FILTER_MODE_DISABLED;
2513
+
2514
+ const options = getOptionElements.call(this);
2515
+ if (options.length === 0 && hasPopperFilterFlag === false) {
2516
+ return;
2517
+ }
2518
+
2519
+ this[popperElementSymbol].style.visibility = "hidden";
2520
+ this[popperElementSymbol].style.display = STYLE_DISPLAY_MODE_BLOCK;
2521
+ setStatusOrRemoveBadges.call(this, "open");
2522
+
2523
+ addAttributeToken(this[controlElementSymbol], "class", "open");
2524
+
2525
+ new Processing(() => {
2526
+ calcAndSetOptionsDimension.call(this);
2527
+ focusFilter.call(this);
2528
+ this[popperElementSymbol].style.removeProperty("visibility");
2529
+ updatePopper.call(this);
2530
+ })
2531
+ .run()
2532
+ .catch((e) => {
2533
+ addErrorAttribute(this, e);
2534
+ });
2547
2535
  }
2548
2536
 
2549
2537
  /**
2550
2538
  * @private
2551
2539
  */
2552
2540
  function toggle() {
2553
- if (this[popperElementSymbol].style.display === STYLE_DISPLAY_MODE_BLOCK) {
2554
- hide.call(this);
2555
- } else {
2556
- show.call(this);
2557
- }
2541
+ if (this[popperElementSymbol].style.display === STYLE_DISPLAY_MODE_BLOCK) {
2542
+ hide.call(this);
2543
+ } else {
2544
+ show.call(this);
2545
+ }
2558
2546
  }
2559
2547
 
2560
2548
  /**
@@ -2563,188 +2551,188 @@ function toggle() {
2563
2551
  * @fires monster-selection-cleared
2564
2552
  */
2565
2553
  function initEventHandler() {
2566
- const self = this;
2567
-
2568
- /**
2569
- * @param {Event} event
2570
- */
2571
- self[clearOptionEventHandler] = (event) => {
2572
- const element = findTargetElementFromEvent(
2573
- event,
2574
- ATTRIBUTE_ROLE,
2575
- "remove-badge",
2576
- );
2577
-
2578
- if (element instanceof HTMLElement) {
2579
- const badge = findClosestByAttribute(element, ATTRIBUTE_ROLE, "badge");
2580
- if (badge instanceof HTMLElement) {
2581
- const value = badge.getAttribute(`${ATTRIBUTE_PREFIX}value`);
2582
-
2583
- let selection = self.getOption("selection");
2584
- selection = selection.filter((b) => {
2585
- return value !== b.value;
2586
- });
2587
-
2588
- setSelection
2589
- .call(self, selection)
2590
- .then(() => {
2591
- fireCustomEvent(self, "monster-selection-removed", {
2592
- value,
2593
- });
2594
- })
2595
- .catch((e) => {
2596
- addErrorAttribute(self, e);
2597
- });
2598
- }
2599
- }
2600
- };
2601
-
2602
- /**
2603
- * @param {Event} event
2604
- */
2605
- self[closeEventHandler] = (event) => {
2606
- const path = event.composedPath();
2607
-
2608
- for (const [, element] of Object.entries(path)) {
2609
- if (element === self) {
2610
- return;
2611
- }
2612
- }
2613
- hide.call(self);
2614
- };
2615
-
2616
- /**
2617
- * @param {Event} event
2618
- */
2619
- self[inputEventHandler] = (event) => {
2620
- const path = event.composedPath();
2621
- const element = path?.[0];
2622
-
2623
- if (element instanceof HTMLElement) {
2624
- if (
2625
- element.hasAttribute(ATTRIBUTE_ROLE) &&
2626
- element.getAttribute(ATTRIBUTE_ROLE) === "option-control"
2627
- ) {
2628
- fireCustomEvent(self, "monster-change", {
2629
- type: event.type,
2630
- value: element.value,
2631
- checked: element.checked,
2632
- });
2633
- } else if (
2634
- element.hasAttribute(ATTRIBUTE_ROLE) &&
2635
- element.getAttribute(ATTRIBUTE_ROLE) === "filter"
2636
- ) {
2637
- }
2638
- }
2639
- };
2640
-
2641
- /**
2642
- * @param {Event} event
2643
- */
2644
- self[changeEventHandler] = (event) => {
2645
- gatherState.call(self);
2646
- fireCustomEvent(self, "monster-changed", event?.detail);
2647
- };
2648
-
2649
- self[keyEventHandler] = (event) => {
2650
- const path = event.composedPath();
2651
- const element = path.shift();
2652
-
2653
- let role;
2654
-
2655
- if (element instanceof HTMLElement) {
2656
- if (element.hasAttribute(ATTRIBUTE_ROLE)) {
2657
- role = element.getAttribute(ATTRIBUTE_ROLE);
2658
- } else if (element === this) {
2659
- show.call(this);
2660
- // focusFilter.call(self);
2661
- } else {
2662
- const e = element.closest(`[${ATTRIBUTE_ROLE}]`);
2663
- if (e instanceof HTMLElement && e.hasAttribute(ATTRIBUTE_ROLE)) {
2664
- role = e.getAttribute(ATTRIBUTE_ROLE);
2665
- }
2666
- }
2667
- } else {
2668
- return;
2669
- }
2670
-
2671
- switch (role) {
2672
- case "filter":
2673
- handleFilterKeyboardEvents.call(self, event);
2674
- break;
2675
- case "option-label":
2676
- case "option-control":
2677
- case "option":
2678
- handleOptionKeyboardEvents.call(self, event);
2679
- break;
2680
- case "control":
2681
- case "toggle":
2682
- handleToggleKeyboardEvents.call(self, event);
2683
- break;
2684
- }
2685
- };
2686
-
2687
- const types = self.getOption("toggleEventType", ["click"]);
2688
-
2689
- for (const [, type] of Object.entries(types)) {
2690
- self[controlElementSymbol]
2691
- .querySelector(`[${ATTRIBUTE_ROLE}="container"]`)
2692
- .addEventListener(type, function (event) {
2693
- const element = findTargetElementFromEvent(
2694
- event,
2695
- ATTRIBUTE_ROLE,
2696
- "remove-badge",
2697
- );
2698
- if (element instanceof HTMLElement) {
2699
- return;
2700
- }
2701
-
2702
- toggle.call(self);
2703
- });
2704
-
2705
- self[controlElementSymbol]
2706
- .querySelector(`[${ATTRIBUTE_ROLE}="status-or-remove-badges"]`)
2707
- .addEventListener(type, function (event) {
2708
- if (self.getOption("disabled", undefined) === true) {
2709
- return;
2710
- }
2711
-
2712
- const path = event.composedPath();
2713
- const element = path?.[0];
2714
- if (element instanceof HTMLElement) {
2715
- const control = element.closest(
2716
- `[${ATTRIBUTE_ROLE}="status-or-remove-badges"]`,
2717
- );
2718
- if (control instanceof HTMLElement) {
2719
- if (control.classList.contains("clear")) {
2720
- clearSelection.call(self);
2721
-
2722
- fireCustomEvent(self, "monster-selection-cleared", {});
2723
- } else {
2724
- const element = findTargetElementFromEvent(
2725
- event,
2726
- ATTRIBUTE_ROLE,
2727
- "remove-badge",
2728
- );
2729
- if (element instanceof HTMLElement) {
2730
- return;
2731
- }
2732
-
2733
- toggle.call(self);
2734
- }
2735
- }
2736
- }
2737
- });
2738
-
2739
- // badge, selection
2740
- self.addEventListener(type, self[clearOptionEventHandler]);
2741
- }
2742
-
2743
- self.addEventListener("monster-change", self[changeEventHandler]);
2744
- self.addEventListener("input", self[inputEventHandler]);
2745
- self.addEventListener("keydown", self[keyEventHandler]);
2746
-
2747
- return self;
2554
+ const self = this;
2555
+
2556
+ /**
2557
+ * @param {Event} event
2558
+ */
2559
+ self[clearOptionEventHandler] = (event) => {
2560
+ const element = findTargetElementFromEvent(
2561
+ event,
2562
+ ATTRIBUTE_ROLE,
2563
+ "remove-badge",
2564
+ );
2565
+
2566
+ if (element instanceof HTMLElement) {
2567
+ const badge = findClosestByAttribute(element, ATTRIBUTE_ROLE, "badge");
2568
+ if (badge instanceof HTMLElement) {
2569
+ const value = badge.getAttribute(`${ATTRIBUTE_PREFIX}value`);
2570
+
2571
+ let selection = self.getOption("selection");
2572
+ selection = selection.filter((b) => {
2573
+ return value !== b.value;
2574
+ });
2575
+
2576
+ setSelection
2577
+ .call(self, selection)
2578
+ .then(() => {
2579
+ fireCustomEvent(self, "monster-selection-removed", {
2580
+ value,
2581
+ });
2582
+ })
2583
+ .catch((e) => {
2584
+ addErrorAttribute(self, e);
2585
+ });
2586
+ }
2587
+ }
2588
+ };
2589
+
2590
+ /**
2591
+ * @param {Event} event
2592
+ */
2593
+ self[closeEventHandler] = (event) => {
2594
+ const path = event.composedPath();
2595
+
2596
+ for (const [, element] of Object.entries(path)) {
2597
+ if (element === self) {
2598
+ return;
2599
+ }
2600
+ }
2601
+ hide.call(self);
2602
+ };
2603
+
2604
+ /**
2605
+ * @param {Event} event
2606
+ */
2607
+ self[inputEventHandler] = (event) => {
2608
+ const path = event.composedPath();
2609
+ const element = path?.[0];
2610
+
2611
+ if (element instanceof HTMLElement) {
2612
+ if (
2613
+ element.hasAttribute(ATTRIBUTE_ROLE) &&
2614
+ element.getAttribute(ATTRIBUTE_ROLE) === "option-control"
2615
+ ) {
2616
+ fireCustomEvent(self, "monster-change", {
2617
+ type: event.type,
2618
+ value: element.value,
2619
+ checked: element.checked,
2620
+ });
2621
+ } else if (
2622
+ element.hasAttribute(ATTRIBUTE_ROLE) &&
2623
+ element.getAttribute(ATTRIBUTE_ROLE) === "filter"
2624
+ ) {
2625
+ }
2626
+ }
2627
+ };
2628
+
2629
+ /**
2630
+ * @param {Event} event
2631
+ */
2632
+ self[changeEventHandler] = (event) => {
2633
+ gatherState.call(self);
2634
+ fireCustomEvent(self, "monster-changed", event?.detail);
2635
+ };
2636
+
2637
+ self[keyEventHandler] = (event) => {
2638
+ const path = event.composedPath();
2639
+ const element = path.shift();
2640
+
2641
+ let role;
2642
+
2643
+ if (element instanceof HTMLElement) {
2644
+ if (element.hasAttribute(ATTRIBUTE_ROLE)) {
2645
+ role = element.getAttribute(ATTRIBUTE_ROLE);
2646
+ } else if (element === this) {
2647
+ show.call(this);
2648
+ // focusFilter.call(self);
2649
+ } else {
2650
+ const e = element.closest(`[${ATTRIBUTE_ROLE}]`);
2651
+ if (e instanceof HTMLElement && e.hasAttribute(ATTRIBUTE_ROLE)) {
2652
+ role = e.getAttribute(ATTRIBUTE_ROLE);
2653
+ }
2654
+ }
2655
+ } else {
2656
+ return;
2657
+ }
2658
+
2659
+ switch (role) {
2660
+ case "filter":
2661
+ handleFilterKeyboardEvents.call(self, event);
2662
+ break;
2663
+ case "option-label":
2664
+ case "option-control":
2665
+ case "option":
2666
+ handleOptionKeyboardEvents.call(self, event);
2667
+ break;
2668
+ case "control":
2669
+ case "toggle":
2670
+ handleToggleKeyboardEvents.call(self, event);
2671
+ break;
2672
+ }
2673
+ };
2674
+
2675
+ const types = self.getOption("toggleEventType", ["click"]);
2676
+
2677
+ for (const [, type] of Object.entries(types)) {
2678
+ self[controlElementSymbol]
2679
+ .querySelector(`[${ATTRIBUTE_ROLE}="container"]`)
2680
+ .addEventListener(type, function (event) {
2681
+ const element = findTargetElementFromEvent(
2682
+ event,
2683
+ ATTRIBUTE_ROLE,
2684
+ "remove-badge",
2685
+ );
2686
+ if (element instanceof HTMLElement) {
2687
+ return;
2688
+ }
2689
+
2690
+ toggle.call(self);
2691
+ });
2692
+
2693
+ self[controlElementSymbol]
2694
+ .querySelector(`[${ATTRIBUTE_ROLE}="status-or-remove-badges"]`)
2695
+ .addEventListener(type, function (event) {
2696
+ if (self.getOption("disabled", undefined) === true) {
2697
+ return;
2698
+ }
2699
+
2700
+ const path = event.composedPath();
2701
+ const element = path?.[0];
2702
+ if (element instanceof HTMLElement) {
2703
+ const control = element.closest(
2704
+ `[${ATTRIBUTE_ROLE}="status-or-remove-badges"]`,
2705
+ );
2706
+ if (control instanceof HTMLElement) {
2707
+ if (control.classList.contains("clear")) {
2708
+ clearSelection.call(self);
2709
+
2710
+ fireCustomEvent(self, "monster-selection-cleared", {});
2711
+ } else {
2712
+ const element = findTargetElementFromEvent(
2713
+ event,
2714
+ ATTRIBUTE_ROLE,
2715
+ "remove-badge",
2716
+ );
2717
+ if (element instanceof HTMLElement) {
2718
+ return;
2719
+ }
2720
+
2721
+ toggle.call(self);
2722
+ }
2723
+ }
2724
+ }
2725
+ });
2726
+
2727
+ // badge, selection
2728
+ self.addEventListener(type, self[clearOptionEventHandler]);
2729
+ }
2730
+
2731
+ self.addEventListener("monster-change", self[changeEventHandler]);
2732
+ self.addEventListener("input", self[inputEventHandler]);
2733
+ self.addEventListener("keydown", self[keyEventHandler]);
2734
+
2735
+ return self;
2748
2736
  }
2749
2737
 
2750
2738
  /**
@@ -2752,70 +2740,70 @@ function initEventHandler() {
2752
2740
  * @return {Select}
2753
2741
  */
2754
2742
  function setStatusOrRemoveBadges(suggestion) {
2755
- requestAnimationFrame(() => {
2756
- const selection = this.getOption("selection");
2757
-
2758
- const clearAllFlag =
2759
- isArray(selection) &&
2760
- selection.length > 0 &&
2761
- this.getOption("features.clearAll") === true;
2762
-
2763
- const current = this.getOption("classes.statusOrRemoveBadge");
2764
-
2765
- if (suggestion === "error") {
2766
- if (current !== "error") {
2767
- this.setOption("classes.statusOrRemoveBadge", "error");
2768
- }
2769
- return;
2770
- }
2771
-
2772
- if (this[isLoadingSymbol] === true) {
2773
- if (current !== "loading") {
2774
- this.setOption("classes.statusOrRemoveBadge", "loading");
2775
- }
2776
- return;
2777
- }
2778
-
2779
- if (suggestion === "loading") {
2780
- if (current !== "loading") {
2781
- this.setOption("classes.statusOrRemoveBadge", "loading");
2782
- }
2783
- return;
2784
- }
2785
-
2786
- if (clearAllFlag) {
2787
- if (current !== "clear") {
2788
- this.setOption("classes.statusOrRemoveBadge", "clear");
2789
- }
2790
- return;
2791
- }
2792
-
2793
- if (this[controlElementSymbol].classList.contains("open")) {
2794
- if (current !== "open") {
2795
- this.setOption("classes.statusOrRemoveBadge", "open");
2796
- }
2797
- return;
2798
- }
2799
-
2800
- const options = this.getOption("options");
2801
- if (
2802
- options === undefined ||
2803
- options === null ||
2804
- (isArray(options) && options.length === 0)
2805
- ) {
2806
- if (current !== "empty") {
2807
- this.setOption("classes.statusOrRemoveBadge", "empty");
2808
- }
2809
- return;
2810
- }
2811
-
2812
- if (suggestion) {
2813
- if (current !== suggestion) {
2814
- this.setOption("classes.statusOrRemoveBadge", suggestion);
2815
- }
2816
- return;
2817
- }
2818
- });
2743
+ requestAnimationFrame(() => {
2744
+ const selection = this.getOption("selection");
2745
+
2746
+ const clearAllFlag =
2747
+ isArray(selection) &&
2748
+ selection.length > 0 &&
2749
+ this.getOption("features.clearAll") === true;
2750
+
2751
+ const current = this.getOption("classes.statusOrRemoveBadge");
2752
+
2753
+ if (suggestion === "error") {
2754
+ if (current !== "error") {
2755
+ this.setOption("classes.statusOrRemoveBadge", "error");
2756
+ }
2757
+ return;
2758
+ }
2759
+
2760
+ if (this[isLoadingSymbol] === true) {
2761
+ if (current !== "loading") {
2762
+ this.setOption("classes.statusOrRemoveBadge", "loading");
2763
+ }
2764
+ return;
2765
+ }
2766
+
2767
+ if (suggestion === "loading") {
2768
+ if (current !== "loading") {
2769
+ this.setOption("classes.statusOrRemoveBadge", "loading");
2770
+ }
2771
+ return;
2772
+ }
2773
+
2774
+ if (clearAllFlag) {
2775
+ if (current !== "clear") {
2776
+ this.setOption("classes.statusOrRemoveBadge", "clear");
2777
+ }
2778
+ return;
2779
+ }
2780
+
2781
+ if (this[controlElementSymbol].classList.contains("open")) {
2782
+ if (current !== "open") {
2783
+ this.setOption("classes.statusOrRemoveBadge", "open");
2784
+ }
2785
+ return;
2786
+ }
2787
+
2788
+ const options = this.getOption("options");
2789
+ if (
2790
+ options === undefined ||
2791
+ options === null ||
2792
+ (isArray(options) && options.length === 0)
2793
+ ) {
2794
+ if (current !== "empty") {
2795
+ this.setOption("classes.statusOrRemoveBadge", "empty");
2796
+ }
2797
+ return;
2798
+ }
2799
+
2800
+ if (suggestion) {
2801
+ if (current !== suggestion) {
2802
+ this.setOption("classes.statusOrRemoveBadge", suggestion);
2803
+ }
2804
+ return;
2805
+ }
2806
+ });
2819
2807
  }
2820
2808
 
2821
2809
  /**
@@ -2824,68 +2812,68 @@ function setStatusOrRemoveBadges(suggestion) {
2824
2812
  * @throws {Error} no shadow-root is defined
2825
2813
  */
2826
2814
  function initControlReferences() {
2827
- if (!this.shadowRoot) {
2828
- throw new Error("no shadow-root is defined");
2829
- }
2830
-
2831
- this[controlElementSymbol] = this.shadowRoot.querySelector(
2832
- `[${ATTRIBUTE_ROLE}=control]`,
2833
- );
2834
- this[selectionElementSymbol] = this.shadowRoot.querySelector(
2835
- `[${ATTRIBUTE_ROLE}=selection]`,
2836
- );
2837
- this[containerElementSymbol] = this.shadowRoot.querySelector(
2838
- `[${ATTRIBUTE_ROLE}=container]`,
2839
- );
2840
- this[popperElementSymbol] = this.shadowRoot.querySelector(
2841
- `[${ATTRIBUTE_ROLE}=popper]`,
2842
- );
2843
- this[inlineFilterElementSymbol] = this.shadowRoot.querySelector(
2844
- `[${ATTRIBUTE_ROLE}=filter][name="inline-filter"]`,
2845
- );
2846
- this[popperFilterElementSymbol] = this.shadowRoot.querySelector(
2847
- `[${ATTRIBUTE_ROLE}=filter][name="popper-filter"]`,
2848
- );
2849
- this[popperFilterContainerElementSymbol] =
2850
- this[popperFilterElementSymbol].parentElement;
2851
- this[optionsElementSymbol] = this.shadowRoot.querySelector(
2852
- `[${ATTRIBUTE_ROLE}=options]`,
2853
- );
2854
- this[noOptionsAvailableElementSymbol] = this.shadowRoot.querySelector(
2855
- `[${ATTRIBUTE_ROLE}="no-options"]`,
2856
- );
2857
- this[statusOrRemoveBadgesElementSymbol] = this.shadowRoot.querySelector(
2858
- `[${ATTRIBUTE_ROLE}=status-or-remove-badges]`,
2859
- );
2815
+ if (!this.shadowRoot) {
2816
+ throw new Error("no shadow-root is defined");
2817
+ }
2818
+
2819
+ this[controlElementSymbol] = this.shadowRoot.querySelector(
2820
+ `[${ATTRIBUTE_ROLE}=control]`,
2821
+ );
2822
+ this[selectionElementSymbol] = this.shadowRoot.querySelector(
2823
+ `[${ATTRIBUTE_ROLE}=selection]`,
2824
+ );
2825
+ this[containerElementSymbol] = this.shadowRoot.querySelector(
2826
+ `[${ATTRIBUTE_ROLE}=container]`,
2827
+ );
2828
+ this[popperElementSymbol] = this.shadowRoot.querySelector(
2829
+ `[${ATTRIBUTE_ROLE}=popper]`,
2830
+ );
2831
+ this[inlineFilterElementSymbol] = this.shadowRoot.querySelector(
2832
+ `[${ATTRIBUTE_ROLE}=filter][name="inline-filter"]`,
2833
+ );
2834
+ this[popperFilterElementSymbol] = this.shadowRoot.querySelector(
2835
+ `[${ATTRIBUTE_ROLE}=filter][name="popper-filter"]`,
2836
+ );
2837
+ this[popperFilterContainerElementSymbol] =
2838
+ this[popperFilterElementSymbol].parentElement;
2839
+ this[optionsElementSymbol] = this.shadowRoot.querySelector(
2840
+ `[${ATTRIBUTE_ROLE}=options]`,
2841
+ );
2842
+ this[noOptionsAvailableElementSymbol] = this.shadowRoot.querySelector(
2843
+ `[${ATTRIBUTE_ROLE}="no-options"]`,
2844
+ );
2845
+ this[statusOrRemoveBadgesElementSymbol] = this.shadowRoot.querySelector(
2846
+ `[${ATTRIBUTE_ROLE}=status-or-remove-badges]`,
2847
+ );
2860
2848
  }
2861
2849
 
2862
2850
  /**
2863
2851
  * @private
2864
2852
  */
2865
2853
  function updatePopper() {
2866
- if (this[popperElementSymbol].style.display !== STYLE_DISPLAY_MODE_BLOCK) {
2867
- return;
2868
- }
2869
-
2870
- if (this.getOption("disabled", false) === true) {
2871
- return;
2872
- }
2873
-
2874
- new Processing(() => {
2875
- calcAndSetOptionsDimension.call(this);
2876
- positionPopper.call(
2877
- this,
2878
- this[controlElementSymbol],
2879
- this[popperElementSymbol],
2880
- this.getOption("popper", {}),
2881
- );
2882
- })
2883
- .run()
2884
- .catch((e) => {
2885
- addErrorAttribute(this, e);
2886
- });
2887
-
2888
- return this;
2854
+ if (this[popperElementSymbol].style.display !== STYLE_DISPLAY_MODE_BLOCK) {
2855
+ return;
2856
+ }
2857
+
2858
+ if (this.getOption("disabled", false) === true) {
2859
+ return;
2860
+ }
2861
+
2862
+ new Processing(() => {
2863
+ calcAndSetOptionsDimension.call(this);
2864
+ positionPopper.call(
2865
+ this,
2866
+ this[controlElementSymbol],
2867
+ this[popperElementSymbol],
2868
+ this.getOption("popper", {}),
2869
+ );
2870
+ })
2871
+ .run()
2872
+ .catch((e) => {
2873
+ addErrorAttribute(this, e);
2874
+ });
2875
+
2876
+ return this;
2889
2877
  }
2890
2878
 
2891
2879
  /**
@@ -2893,8 +2881,8 @@ function updatePopper() {
2893
2881
  * @return {string}
2894
2882
  */
2895
2883
  function getTemplate() {
2896
- // language=HTML
2897
- return `
2884
+ // language=HTML
2885
+ return `
2898
2886
  <template id="options">
2899
2887
  <div data-monster-role="option" tabindex="-1"
2900
2888
  data-monster-attributes="