@schukai/monster 3.99.7 → 3.100.1

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