@schukai/monster 3.56.1 → 3.57.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +32 -0
- package/example/components/form/toggle-switch.mjs +7 -0
- package/package.json +1 -1
- package/source/components/form/button.mjs +3 -3
- package/source/components/form/select.mjs +1773 -1745
- package/source/components/form/style/select.pcss +1 -1
- package/source/components/form/style/toggle-switch.pcss +74 -0
- package/source/components/form/stylesheet/select.mjs +1 -1
- package/source/components/form/stylesheet/toggle-switch.mjs +27 -0
- package/source/components/form/toggle-switch.mjs +427 -0
- package/source/data/transformer.mjs +33 -1
- package/source/dom/attributes.mjs +1 -1
- package/source/dom/customcontrol.mjs +6 -2
- package/source/dom/customelement.mjs +909 -864
- package/source/dom/updater.mjs +754 -732
- package/source/dom/util/set-option-from-attribute.mjs +2 -1
- package/source/monster.mjs +5 -0
- package/source/types/version.mjs +1 -1
- package/test/cases/components/form/select.mjs +1 -1
- package/test/cases/components/form/toggle-switch.mjs +310 -0
- package/test/cases/components/form/tree-select.mjs +1 -8
- package/test/cases/data/transformer.mjs +16 -0
- package/test/cases/dom/customcontrol.mjs +53 -8
- package/test/cases/dom/customelement-initfromscripthost.mjs +0 -4
- package/test/cases/dom/customelement.mjs +30 -26
- package/test/cases/dom/updater.mjs +14 -3
- package/test/cases/monster.mjs +1 -1
- package/test/util/jsdom.mjs +9 -10
- package/test/web/test.html +2 -2
- package/test/web/tests.js +3044 -1023
@@ -4,61 +4,61 @@
|
|
4
4
|
* This file is licensed under the AGPLv3 License.
|
5
5
|
* License text available at https://www.gnu.org/licenses/agpl-3.0.en.html
|
6
6
|
*/
|
7
|
-
import {
|
8
|
-
import {
|
9
|
-
import {
|
10
|
-
import {
|
11
|
-
import {
|
7
|
+
import {instanceSymbol} from "../../constants.mjs";
|
8
|
+
import {internalSymbol} from "../../constants.mjs";
|
9
|
+
import {buildMap} from "../../data/buildmap.mjs";
|
10
|
+
import {DeadMansSwitch} from "../../util/deadmansswitch.mjs";
|
11
|
+
import {positionPopper} from "./util/floating-ui.mjs";
|
12
12
|
import {
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
addAttributeToken,
|
14
|
+
findClosestByAttribute,
|
15
|
+
removeAttributeToken,
|
16
16
|
} from "../../dom/attributes.mjs";
|
17
17
|
import {
|
18
|
-
|
19
|
-
|
20
|
-
|
18
|
+
ATTRIBUTE_ERRORMESSAGE,
|
19
|
+
ATTRIBUTE_PREFIX,
|
20
|
+
ATTRIBUTE_ROLE,
|
21
21
|
} from "../../dom/constants.mjs";
|
22
|
-
import {
|
22
|
+
import {CustomControl} from "../../dom/customcontrol.mjs";
|
23
23
|
import {
|
24
|
-
|
25
|
-
|
26
|
-
|
24
|
+
assembleMethodSymbol,
|
25
|
+
getSlottedElements,
|
26
|
+
registerCustomElement, updaterTransformerMethodsSymbol,
|
27
27
|
} from "../../dom/customelement.mjs";
|
28
28
|
import {
|
29
|
-
|
30
|
-
|
31
|
-
|
29
|
+
findTargetElementFromEvent,
|
30
|
+
fireCustomEvent,
|
31
|
+
fireEvent,
|
32
32
|
} from "../../dom/events.mjs";
|
33
|
-
import {
|
34
|
-
import {
|
35
|
-
import {
|
36
|
-
import {
|
33
|
+
import {getDocument} from "../../dom/util.mjs";
|
34
|
+
import {Formatter} from "../../text/formatter.mjs";
|
35
|
+
import {getGlobal} from "../../types/global.mjs";
|
36
|
+
import {ID} from "../../types/id.mjs";
|
37
37
|
import {
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
38
|
+
isArray,
|
39
|
+
isFunction,
|
40
|
+
isInteger,
|
41
|
+
isIterable,
|
42
|
+
isObject,
|
43
|
+
isPrimitive,
|
44
|
+
isString,
|
45
45
|
} from "../../types/is.mjs";
|
46
|
-
import {
|
47
|
-
import {
|
48
|
-
import {
|
49
|
-
import {
|
50
|
-
import {
|
51
|
-
import {
|
46
|
+
import {Observer} from "../../types/observer.mjs";
|
47
|
+
import {ProxyObserver} from "../../types/proxyobserver.mjs";
|
48
|
+
import {validateArray, validateString} from "../../types/validate.mjs";
|
49
|
+
import {Processing} from "../../util/processing.mjs";
|
50
|
+
import {STYLE_DISPLAY_MODE_BLOCK} from "./constants.mjs";
|
51
|
+
import {SelectStyleSheet} from "./stylesheet/select.mjs";
|
52
52
|
import {
|
53
|
-
|
54
|
-
|
53
|
+
getDocumentTranslations,
|
54
|
+
Translations,
|
55
55
|
} from "../../i18n/translations.mjs";
|
56
56
|
|
57
57
|
export {
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
58
|
+
Select,
|
59
|
+
popperElementSymbol,
|
60
|
+
getSummaryTemplate,
|
61
|
+
getSelectionTemplate,
|
62
62
|
};
|
63
63
|
|
64
64
|
/**
|
@@ -178,7 +178,7 @@ const popperFilterElementSymbol = Symbol("popperFilterElement");
|
|
178
178
|
* @type {symbol}
|
179
179
|
*/
|
180
180
|
const popperFilterContainerElementSymbol = Symbol(
|
181
|
-
|
181
|
+
"popperFilterContainerElement",
|
182
182
|
);
|
183
183
|
|
184
184
|
/**
|
@@ -314,476 +314,482 @@ const FILTER_POSITION_INLINE = "inline";
|
|
314
314
|
* @fires Monster.Components.Form.event:monster-changed
|
315
315
|
*/
|
316
316
|
class Select extends CustomControl {
|
317
|
-
|
318
|
-
|
319
|
-
|
320
|
-
|
321
|
-
|
322
|
-
|
323
|
-
|
324
|
-
|
325
|
-
|
326
|
-
|
327
|
-
|
328
|
-
|
329
|
-
|
330
|
-
|
331
|
-
|
332
|
-
|
333
|
-
|
334
|
-
|
335
|
-
|
336
|
-
|
337
|
-
|
338
|
-
|
339
|
-
|
340
|
-
|
341
|
-
|
342
|
-
|
343
|
-
|
344
|
-
|
345
|
-
|
346
|
-
|
347
|
-
|
348
|
-
|
349
|
-
|
350
|
-
|
351
|
-
|
352
|
-
|
353
|
-
|
354
|
-
|
355
|
-
|
356
|
-
|
357
|
-
|
358
|
-
|
359
|
-
|
360
|
-
|
361
|
-
|
362
|
-
|
363
|
-
|
364
|
-
|
365
|
-
|
366
|
-
|
367
|
-
|
368
|
-
|
369
|
-
|
370
|
-
|
371
|
-
|
372
|
-
|
373
|
-
|
374
|
-
|
375
|
-
|
376
|
-
|
377
|
-
|
378
|
-
|
379
|
-
|
380
|
-
|
381
|
-
|
382
|
-
|
383
|
-
|
384
|
-
|
385
|
-
|
386
|
-
|
387
|
-
|
388
|
-
|
389
|
-
|
390
|
-
|
391
|
-
|
392
|
-
|
393
|
-
|
394
|
-
|
395
|
-
|
396
|
-
|
397
|
-
|
398
|
-
|
399
|
-
|
400
|
-
|
401
|
-
|
402
|
-
|
403
|
-
|
404
|
-
|
405
|
-
|
406
|
-
|
407
|
-
|
408
|
-
|
409
|
-
|
410
|
-
|
411
|
-
|
412
|
-
|
413
|
-
|
414
|
-
|
415
|
-
|
416
|
-
|
417
|
-
|
418
|
-
|
419
|
-
|
420
|
-
|
421
|
-
|
422
|
-
|
423
|
-
|
424
|
-
|
425
|
-
|
426
|
-
|
427
|
-
|
428
|
-
|
429
|
-
|
430
|
-
|
431
|
-
|
432
|
-
|
433
|
-
|
434
|
-
|
435
|
-
|
436
|
-
|
437
|
-
|
438
|
-
|
439
|
-
|
440
|
-
|
441
|
-
|
442
|
-
|
443
|
-
|
444
|
-
|
445
|
-
|
446
|
-
|
447
|
-
|
448
|
-
|
449
|
-
|
450
|
-
|
451
|
-
|
452
|
-
|
453
|
-
|
454
|
-
|
455
|
-
|
456
|
-
|
457
|
-
|
458
|
-
|
459
|
-
|
460
|
-
|
461
|
-
|
462
|
-
|
463
|
-
|
464
|
-
|
465
|
-
|
466
|
-
|
467
|
-
|
468
|
-
|
469
|
-
|
470
|
-
|
471
|
-
|
472
|
-
|
473
|
-
|
474
|
-
|
475
|
-
|
476
|
-
|
477
|
-
|
478
|
-
|
479
|
-
|
480
|
-
|
481
|
-
|
482
|
-
|
483
|
-
|
484
|
-
|
485
|
-
|
486
|
-
|
487
|
-
|
488
|
-
|
489
|
-
|
490
|
-
|
491
|
-
|
492
|
-
|
493
|
-
|
494
|
-
|
495
|
-
|
496
|
-
|
497
|
-
|
498
|
-
|
499
|
-
|
500
|
-
|
501
|
-
|
502
|
-
|
503
|
-
|
504
|
-
|
505
|
-
|
506
|
-
|
507
|
-
|
508
|
-
|
509
|
-
|
510
|
-
|
511
|
-
|
512
|
-
|
513
|
-
|
514
|
-
|
515
|
-
|
516
|
-
|
517
|
-
|
518
|
-
|
519
|
-
|
520
|
-
|
521
|
-
|
522
|
-
|
523
|
-
|
524
|
-
|
525
|
-
|
526
|
-
|
527
|
-
|
528
|
-
|
529
|
-
|
530
|
-
|
531
|
-
|
532
|
-
|
533
|
-
|
534
|
-
|
535
|
-
|
536
|
-
|
537
|
-
|
538
|
-
|
539
|
-
|
540
|
-
|
541
|
-
|
542
|
-
|
543
|
-
|
544
|
-
|
545
|
-
|
546
|
-
|
547
|
-
|
548
|
-
|
549
|
-
|
550
|
-
|
551
|
-
|
552
|
-
|
553
|
-
|
554
|
-
|
555
|
-
|
556
|
-
|
557
|
-
|
558
|
-
|
559
|
-
|
560
|
-
|
561
|
-
|
562
|
-
|
563
|
-
|
564
|
-
|
565
|
-
|
566
|
-
|
567
|
-
|
568
|
-
|
569
|
-
|
570
|
-
|
571
|
-
|
572
|
-
|
573
|
-
|
574
|
-
|
575
|
-
|
576
|
-
|
577
|
-
|
578
|
-
|
579
|
-
|
580
|
-
|
581
|
-
|
582
|
-
|
583
|
-
|
584
|
-
|
585
|
-
|
586
|
-
|
587
|
-
|
588
|
-
|
589
|
-
|
590
|
-
|
591
|
-
|
592
|
-
|
593
|
-
|
594
|
-
|
595
|
-
|
596
|
-
|
597
|
-
|
598
|
-
|
599
|
-
|
600
|
-
|
601
|
-
|
602
|
-
|
603
|
-
|
604
|
-
|
605
|
-
|
606
|
-
|
607
|
-
|
608
|
-
|
609
|
-
|
610
|
-
|
611
|
-
|
612
|
-
|
613
|
-
|
614
|
-
|
615
|
-
|
616
|
-
|
617
|
-
|
618
|
-
|
619
|
-
|
620
|
-
|
621
|
-
|
622
|
-
|
623
|
-
|
624
|
-
|
625
|
-
|
626
|
-
|
627
|
-
|
628
|
-
|
629
|
-
|
630
|
-
|
631
|
-
|
632
|
-
|
633
|
-
|
634
|
-
|
635
|
-
|
636
|
-
|
637
|
-
|
638
|
-
|
639
|
-
|
640
|
-
|
641
|
-
|
642
|
-
|
643
|
-
|
644
|
-
|
645
|
-
|
646
|
-
|
647
|
-
|
648
|
-
|
649
|
-
|
650
|
-
|
651
|
-
|
652
|
-
|
653
|
-
|
654
|
-
|
655
|
-
|
656
|
-
|
657
|
-
|
658
|
-
|
659
|
-
|
660
|
-
|
661
|
-
|
662
|
-
|
663
|
-
|
664
|
-
|
665
|
-
|
666
|
-
|
667
|
-
|
668
|
-
|
669
|
-
|
670
|
-
|
671
|
-
|
672
|
-
|
673
|
-
|
674
|
-
|
675
|
-
|
676
|
-
|
677
|
-
|
678
|
-
|
679
|
-
|
680
|
-
|
681
|
-
|
682
|
-
|
683
|
-
|
684
|
-
|
685
|
-
|
686
|
-
|
687
|
-
|
688
|
-
|
689
|
-
|
690
|
-
|
691
|
-
|
692
|
-
|
693
|
-
|
694
|
-
|
695
|
-
|
696
|
-
|
697
|
-
|
698
|
-
|
699
|
-
|
700
|
-
|
701
|
-
|
702
|
-
|
703
|
-
|
704
|
-
|
705
|
-
|
706
|
-
|
707
|
-
|
708
|
-
|
709
|
-
|
710
|
-
|
711
|
-
|
712
|
-
|
713
|
-
|
714
|
-
|
715
|
-
|
716
|
-
|
717
|
-
|
718
|
-
|
719
|
-
|
720
|
-
|
721
|
-
|
722
|
-
|
723
|
-
|
724
|
-
|
725
|
-
|
726
|
-
|
727
|
-
|
728
|
-
|
729
|
-
|
730
|
-
|
731
|
-
|
732
|
-
|
733
|
-
|
734
|
-
|
735
|
-
|
736
|
-
|
737
|
-
|
738
|
-
|
739
|
-
|
740
|
-
|
741
|
-
|
742
|
-
|
743
|
-
|
744
|
-
|
745
|
-
|
746
|
-
|
747
|
-
|
748
|
-
|
749
|
-
|
750
|
-
|
751
|
-
|
752
|
-
|
753
|
-
|
754
|
-
|
755
|
-
|
756
|
-
|
757
|
-
|
758
|
-
|
759
|
-
|
760
|
-
|
761
|
-
|
762
|
-
|
763
|
-
|
764
|
-
|
765
|
-
|
766
|
-
|
767
|
-
|
768
|
-
|
769
|
-
|
770
|
-
|
771
|
-
|
772
|
-
|
773
|
-
|
774
|
-
|
775
|
-
|
776
|
-
|
777
|
-
|
778
|
-
|
779
|
-
|
780
|
-
|
781
|
-
|
782
|
-
|
783
|
-
|
784
|
-
|
785
|
-
|
786
|
-
|
317
|
+
/**
|
318
|
+
* @extends CustomControl
|
319
|
+
*/
|
320
|
+
constructor() {
|
321
|
+
super();
|
322
|
+
initOptionObserver.call(this);
|
323
|
+
}
|
324
|
+
|
325
|
+
/**
|
326
|
+
* This method is called by the `instanceof` operator.
|
327
|
+
* @returns {symbol}
|
328
|
+
* @since 2.1.0
|
329
|
+
*/
|
330
|
+
static get [instanceSymbol]() {
|
331
|
+
return Symbol.for("@schukai/monster/components/form/select@@instance");
|
332
|
+
}
|
333
|
+
|
334
|
+
/**
|
335
|
+
* The current selection of the Select
|
336
|
+
*
|
337
|
+
* ```
|
338
|
+
* e = document.querySelector('monster-select');
|
339
|
+
* console.log(e.value)
|
340
|
+
* // ↦ 1
|
341
|
+
* // ↦ ['1','2']
|
342
|
+
* ```
|
343
|
+
*
|
344
|
+
* @property {string|array}
|
345
|
+
*/
|
346
|
+
get value() {
|
347
|
+
return convertSelectionToValue.call(this, this.getOption("selection"));
|
348
|
+
}
|
349
|
+
|
350
|
+
/**
|
351
|
+
* @see {@link https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/attachInternals}
|
352
|
+
* @return {boolean}
|
353
|
+
*/
|
354
|
+
static get formAssociated() {
|
355
|
+
return true;
|
356
|
+
}
|
357
|
+
|
358
|
+
/**
|
359
|
+
* Set selection
|
360
|
+
*
|
361
|
+
* ```
|
362
|
+
* e = document.querySelector('monster-select');
|
363
|
+
* e.value=1
|
364
|
+
* ```
|
365
|
+
*
|
366
|
+
* @property {string|array} value
|
367
|
+
* @since 1.2.0
|
368
|
+
* @throws {Error} unsupported type
|
369
|
+
*/
|
370
|
+
set value(value) {
|
371
|
+
const result = convertValueToSelection.call(this, value);
|
372
|
+
setSelection
|
373
|
+
.call(this, result.selection)
|
374
|
+
.then(() => {
|
375
|
+
})
|
376
|
+
.catch((e) => {
|
377
|
+
addAttributeToken(this, ATTRIBUTE_ERRORMESSAGE, e.message);
|
378
|
+
});
|
379
|
+
|
380
|
+
}
|
381
|
+
|
382
|
+
/**
|
383
|
+
* To set the options via the html tag the attribute `data-monster-options` must be used.
|
384
|
+
* @see {@link https://monsterjs.org/en/doc/#configurate-a-monster-control}
|
385
|
+
*
|
386
|
+
* The individual configuration values can be found in the table.
|
387
|
+
*
|
388
|
+
* @property {Object} toggleEventType=click,touch List of event types to be observed for opening the dropdown
|
389
|
+
* @property {boolean} delegatesFocus=false lorem [see mozilla.org](https://developer.mozilla.org/en-US/docs/Web/API/ShadowRoot/delegatesFocus)
|
390
|
+
* @property {Object[]} options Selection of key identifier pairs available for selection and displayed in the dropdown.
|
391
|
+
* @property {string} options[].label Label
|
392
|
+
* @property {string} options[].value Value
|
393
|
+
* @property {string} options[].visibility hidden or visible
|
394
|
+
* @property {Array} selection Selected options
|
395
|
+
* @property {Integer} showMaxOptions=10 Maximum number of visible options before a scroll bar should be displayed.
|
396
|
+
* @property {string} type=radio Multiple (checkbox) or single selection (radio)
|
397
|
+
* @property {string} name=(random id) Name of the form field
|
398
|
+
* @property {string} url Load options from server per url
|
399
|
+
* @property {Object} fetch Fetch [see Using Fetch mozilla.org](https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API/Using_Fetch)
|
400
|
+
* @property {String} fetch.redirect=error
|
401
|
+
* @property {String} fetch.method=GET
|
402
|
+
* @property {String} fetch.mode=same-origin
|
403
|
+
* @property {String} fetch.credentials=same-origin
|
404
|
+
* @property {Object} fetch.headers={"accept":"application/json"}}
|
405
|
+
* @property {Object} labels
|
406
|
+
* @property {string} labels.cannot-be-loaded cannot be loaded
|
407
|
+
* @property {string} labels.no-options-available no options available
|
408
|
+
* @property {string} labels.select-an-option select an option
|
409
|
+
* @property {string} labels.no-option no option in the list, maybe you have to change the filter
|
410
|
+
* @property {Object} features List with features
|
411
|
+
* @property {Boolean} features.clearAll=true Display of a delete button to delete the entire selection
|
412
|
+
* @property {Boolean} features.clear=true Display of a delete key for deleting the specific selection
|
413
|
+
* @property {Boolean} features.lazyLoad=false Load options when first opening the dropdown
|
414
|
+
* @property {Boolean} features.closeOnSelect=false Close the dropdown when an option is selected (since 3.54.0)
|
415
|
+
* @property {Boolean} filter.defaultValue=* Default filter value, if the filter is empty
|
416
|
+
* @property {Boolean} filter.mode=options Filter mode, values: options, remote, disabled
|
417
|
+
* @property {Object} templates Template definitions
|
418
|
+
* @property {string} templates.main Main template
|
419
|
+
* @property {string} templateMapping Mapping of the template placeholders
|
420
|
+
* @property {string} templateMapping.selected Selected Template
|
421
|
+
* @property {Object} popper [PopperJS Options](https://popper.js.org/docs/v2/)
|
422
|
+
* @property {string} popper.placement=bottom PopperJS placement
|
423
|
+
* @property {Object[]} modifiers={name:offset} PopperJS placement
|
424
|
+
* @property {Object} mapping
|
425
|
+
* @property {String} mapping.selector=* Path to select the appropriate entries
|
426
|
+
* @property {String} mapping.labelTemplate="" template with the label placeholders in the form ${name}, where name is the key (**)
|
427
|
+
* @property {String} mapping.valueTemplate="" template with the value placeholders in the form ${name}, where name is the key
|
428
|
+
* @property {Monster.Components.Form~exampleFilterCallback|undefined} mapping.filter Filtering of values via a function
|
429
|
+
* @property {Object} formatter
|
430
|
+
* @property {Monster.Components.Form~formatterSelectionCallback|undefined} formatter.selection format selection label
|
431
|
+
*/
|
432
|
+
get defaults() {
|
433
|
+
return Object.assign(
|
434
|
+
{},
|
435
|
+
super.defaults,
|
436
|
+
{
|
437
|
+
toggleEventType: ["click", "touch"],
|
438
|
+
delegatesFocus: false,
|
439
|
+
options: [],
|
440
|
+
selection: [],
|
441
|
+
showMaxOptions: 10,
|
442
|
+
type: "radio",
|
443
|
+
name: new ID("s").toString(),
|
444
|
+
features: {
|
445
|
+
clearAll: true,
|
446
|
+
clear: true,
|
447
|
+
lazyLoad: false,
|
448
|
+
closeOnSelect: false,
|
449
|
+
},
|
450
|
+
url: null,
|
451
|
+
labels: {
|
452
|
+
"cannot-be-loaded": "Cannot be loaded",
|
453
|
+
"no-options-available": noOptionsAvailableMessage,
|
454
|
+
"click-to-load-options": clickToLoadOptionsMessage,
|
455
|
+
"select-an-option": "Select an option",
|
456
|
+
"summary-text": {
|
457
|
+
zero: "No entries were selected",
|
458
|
+
one: '<span class="monster-badge-primary-pill">1</span> entry was selected',
|
459
|
+
other:
|
460
|
+
'<span class="monster-badge-primary-pill">${count}</span> entries were selected',
|
461
|
+
},
|
462
|
+
"no-options":
|
463
|
+
"Unfortunately, there are no options available in the list.",
|
464
|
+
"no-options-found":
|
465
|
+
"No options are available in the list. Please consider modifying the filter.",
|
466
|
+
},
|
467
|
+
messages: {
|
468
|
+
control: null,
|
469
|
+
selected: null,
|
470
|
+
emptyOptions: null,
|
471
|
+
},
|
472
|
+
fetch: {
|
473
|
+
redirect: "error",
|
474
|
+
method: "GET",
|
475
|
+
mode: "same-origin",
|
476
|
+
credentials: "same-origin",
|
477
|
+
headers: {
|
478
|
+
accept: "application/json",
|
479
|
+
},
|
480
|
+
},
|
481
|
+
filter: {
|
482
|
+
defaultValue: "*",
|
483
|
+
mode: FILTER_MODE_DISABLED,
|
484
|
+
position: FILTER_POSITION_INLINE,
|
485
|
+
},
|
486
|
+
classes: {
|
487
|
+
badge: "monster-badge-primary",
|
488
|
+
statusOrRemoveBadge: "empty",
|
489
|
+
},
|
490
|
+
mapping: {
|
491
|
+
selector: "*",
|
492
|
+
labelTemplate: "",
|
493
|
+
valueTemplate: "",
|
494
|
+
filter: null,
|
495
|
+
},
|
496
|
+
formatter: {
|
497
|
+
selection: buildSelectionLabel,
|
498
|
+
},
|
499
|
+
templates: {
|
500
|
+
main: getTemplate(),
|
501
|
+
},
|
502
|
+
templateMapping: {
|
503
|
+
/** with the attribute `data-monster-selected-template` the template for the selected options can be defined. */
|
504
|
+
selected: getSelectionTemplate(),
|
505
|
+
},
|
506
|
+
|
507
|
+
popper: {
|
508
|
+
placement: "bottom",
|
509
|
+
middleware: ["flip", "offset:1"],
|
510
|
+
},
|
511
|
+
},
|
512
|
+
initOptionsFromArguments.call(this),
|
513
|
+
);
|
514
|
+
}
|
515
|
+
|
516
|
+
/**
|
517
|
+
* @return {Monster.Components.Form.Select}
|
518
|
+
*/
|
519
|
+
[assembleMethodSymbol]() {
|
520
|
+
const self = this;
|
521
|
+
super[assembleMethodSymbol]();
|
522
|
+
|
523
|
+
initControlReferences.call(self);
|
524
|
+
initEventHandler.call(self);
|
525
|
+
|
526
|
+
const lazyLoadFlag = self.getOption("features.lazyLoad");
|
527
|
+
|
528
|
+
if (self.getOption("url") !== null && !lazyLoadFlag) {
|
529
|
+
setStatusOrRemoveBadges.call(this, "loading");
|
530
|
+
|
531
|
+
new Processing(200, () => {
|
532
|
+
this.fetch()
|
533
|
+
.then(() => {
|
534
|
+
setTimeout(() => {
|
535
|
+
let result;
|
536
|
+
if (self.hasAttribute("value")) {
|
537
|
+
result = setSelection.call(self, self.getAttribute("value"));
|
538
|
+
} else {
|
539
|
+
result = setSelection.call(self, []);
|
540
|
+
}
|
541
|
+
|
542
|
+
result
|
543
|
+
.then(() => {
|
544
|
+
})
|
545
|
+
.catch((e) => {
|
546
|
+
addAttributeToken(self, ATTRIBUTE_ERRORMESSAGE, `${e}`);
|
547
|
+
});
|
548
|
+
}, 100);
|
549
|
+
})
|
550
|
+
.catch((e) => {
|
551
|
+
addAttributeToken(this, ATTRIBUTE_ERRORMESSAGE, e.message);
|
552
|
+
setStatusOrRemoveBadges.call(this, "error");
|
553
|
+
});
|
554
|
+
})
|
555
|
+
.run()
|
556
|
+
.catch((e) => {
|
557
|
+
addAttributeToken(this, ATTRIBUTE_ERRORMESSAGE, e.message);
|
558
|
+
});
|
559
|
+
}
|
560
|
+
|
561
|
+
let lastValue = self.value;
|
562
|
+
self[internalSymbol].attachObserver(
|
563
|
+
|
564
|
+
new Observer(function () {
|
565
|
+
|
566
|
+
if (isObject(this) && this instanceof ProxyObserver) {
|
567
|
+
const n = this.getSubject()?.options?.value;
|
568
|
+
|
569
|
+
if (lastValue !== n) {
|
570
|
+
lastValue = n;
|
571
|
+
setSelection
|
572
|
+
.call(self, n)
|
573
|
+
.then(() => {
|
574
|
+
})
|
575
|
+
.catch((e) => {
|
576
|
+
addAttributeToken(self, ATTRIBUTE_ERRORMESSAGE, `${e}`);
|
577
|
+
});
|
578
|
+
}
|
579
|
+
}
|
580
|
+
}),
|
581
|
+
);
|
582
|
+
|
583
|
+
areOptionsAvailableAndInit.call(self);
|
584
|
+
|
585
|
+
return this;
|
586
|
+
}
|
587
|
+
|
588
|
+
/**
|
589
|
+
* The Button.click() method simulates a click on the internal button element.
|
590
|
+
*
|
591
|
+
* @since 3.27.0
|
592
|
+
* @see {@link https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/click}
|
593
|
+
*/
|
594
|
+
click() {
|
595
|
+
if (this.getOption("disabled") === true) {
|
596
|
+
return;
|
597
|
+
}
|
598
|
+
|
599
|
+
toggle.call(this);
|
600
|
+
}
|
601
|
+
|
602
|
+
/**
|
603
|
+
* The Button.focus() method sets focus on the internal button element.
|
604
|
+
*
|
605
|
+
* @since 3.27.0
|
606
|
+
* @see {@link https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/focus}
|
607
|
+
*/
|
608
|
+
focus(options) {
|
609
|
+
if (this.getOption("disabled") === true) {
|
610
|
+
return;
|
611
|
+
}
|
612
|
+
|
613
|
+
new Processing(() => {
|
614
|
+
gatherState.call(this);
|
615
|
+
focusFilter.call(this, options);
|
616
|
+
})
|
617
|
+
.run()
|
618
|
+
.catch((e) => {
|
619
|
+
addAttributeToken(this, ATTRIBUTE_ERRORMESSAGE, `${e}`);
|
620
|
+
});
|
621
|
+
}
|
622
|
+
|
623
|
+
/**
|
624
|
+
* The Button.blur() method removes focus from the internal button element.
|
625
|
+
* @link https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/blur
|
626
|
+
*/
|
627
|
+
blur() {
|
628
|
+
new Processing(() => {
|
629
|
+
gatherState.call(this);
|
630
|
+
blurFilter.call(this);
|
631
|
+
})
|
632
|
+
.run()
|
633
|
+
.catch((e) => {
|
634
|
+
addAttributeToken(this, ATTRIBUTE_ERRORMESSAGE, `${e}`);
|
635
|
+
});
|
636
|
+
}
|
637
|
+
|
638
|
+
/**
|
639
|
+
* If no url is specified, the options are taken from the Component itself.
|
640
|
+
*
|
641
|
+
* @param {string|URL} url URL to fetch the options
|
642
|
+
* @return {Promise}
|
643
|
+
*/
|
644
|
+
fetch(url) {
|
645
|
+
if (url instanceof URL) {
|
646
|
+
url = url.toString();
|
647
|
+
}
|
648
|
+
|
649
|
+
if (url !== undefined && url !== null) {
|
650
|
+
url = validateString(url);
|
651
|
+
}
|
652
|
+
|
653
|
+
return new Promise((resolve, reject) => {
|
654
|
+
const response = fetchData.call(this, url).then((map) => {
|
655
|
+
if (
|
656
|
+
isObject(map) ||
|
657
|
+
isArray(map) ||
|
658
|
+
map instanceof Set ||
|
659
|
+
map instanceof Map
|
660
|
+
) {
|
661
|
+
this.importOptions(map);
|
662
|
+
setTimeout(() => {
|
663
|
+
resolve();
|
664
|
+
}, 10);
|
665
|
+
return;
|
666
|
+
}
|
667
|
+
|
668
|
+
reject(new Error("invalid response"));
|
669
|
+
});
|
670
|
+
});
|
671
|
+
}
|
672
|
+
|
673
|
+
/**
|
674
|
+
* @return {void}
|
675
|
+
*/
|
676
|
+
connectedCallback() {
|
677
|
+
super.connectedCallback();
|
678
|
+
const document = getDocument();
|
679
|
+
|
680
|
+
for (const [, type] of Object.entries(["click", "touch"])) {
|
681
|
+
// close on outside ui-events
|
682
|
+
document.addEventListener(type, this[closeEventHandler]);
|
683
|
+
}
|
684
|
+
|
685
|
+
parseSlotsToOptions.call(this);
|
686
|
+
attachResizeObserver.call(this);
|
687
|
+
updatePopper.call(this);
|
688
|
+
|
689
|
+
new Processing(() => {
|
690
|
+
gatherState.call(this);
|
691
|
+
focusFilter.call(this);
|
692
|
+
}).run();
|
693
|
+
}
|
694
|
+
|
695
|
+
/**
|
696
|
+
* @return {void}
|
697
|
+
*/
|
698
|
+
disconnectedCallback() {
|
699
|
+
super.disconnectedCallback();
|
700
|
+
const document = getDocument();
|
701
|
+
|
702
|
+
// close on outside ui-events
|
703
|
+
for (const [, type] of Object.entries(["click", "touch"])) {
|
704
|
+
document.removeEventListener(type, this[closeEventHandler]);
|
705
|
+
}
|
706
|
+
|
707
|
+
disconnectResizeObserver.call(this);
|
708
|
+
}
|
709
|
+
|
710
|
+
/**
|
711
|
+
* Import Select Options from dataset
|
712
|
+
* Not to be confused with the control defaults/options
|
713
|
+
*
|
714
|
+
* @since 0.16.0
|
715
|
+
* @param {array|object|Map|Set} data
|
716
|
+
* @return {Select}
|
717
|
+
* @throws {Error} map is not iterable
|
718
|
+
* @throws {Error} missing label configuration
|
719
|
+
*/
|
720
|
+
importOptions(data) {
|
721
|
+
const mappingOptions = this.getOption("mapping", {});
|
722
|
+
const selector = mappingOptions?.["selector"];
|
723
|
+
const labelTemplate = mappingOptions?.["labelTemplate"];
|
724
|
+
const valueTemplate = mappingOptions?.["valueTemplate"];
|
725
|
+
const filter = mappingOptions?.["filter"];
|
726
|
+
|
727
|
+
let flag = false;
|
728
|
+
if (labelTemplate === "") {
|
729
|
+
addAttributeToken(this, ATTRIBUTE_ERRORMESSAGE, "empty label template");
|
730
|
+
flag = true;
|
731
|
+
}
|
732
|
+
|
733
|
+
if (valueTemplate === "") {
|
734
|
+
addAttributeToken(this, ATTRIBUTE_ERRORMESSAGE, "empty value template");
|
735
|
+
flag = true;
|
736
|
+
}
|
737
|
+
|
738
|
+
if (flag === true) {
|
739
|
+
throw new Error("missing label configuration");
|
740
|
+
}
|
741
|
+
|
742
|
+
const map = buildMap(data, selector, labelTemplate, valueTemplate, filter);
|
743
|
+
|
744
|
+
const options = [];
|
745
|
+
if (!isIterable(map)) {
|
746
|
+
throw new Error("map is not iterable");
|
747
|
+
}
|
748
|
+
|
749
|
+
const visibility = "visible";
|
750
|
+
|
751
|
+
map.forEach((label, value) => {
|
752
|
+
options.push({
|
753
|
+
value,
|
754
|
+
label,
|
755
|
+
visibility,
|
756
|
+
});
|
757
|
+
});
|
758
|
+
|
759
|
+
runAsOptionLengthChanged.call(this, map.size);
|
760
|
+
this.setOption("options", options);
|
761
|
+
|
762
|
+
fireCustomEvent(this, "monster-options-set", {
|
763
|
+
options,
|
764
|
+
});
|
765
|
+
|
766
|
+
return this;
|
767
|
+
}
|
768
|
+
|
769
|
+
/**
|
770
|
+
* @private
|
771
|
+
* @return {Monster.Components.Form.Select}
|
772
|
+
*/
|
773
|
+
calcAndSetOptionsDimension() {
|
774
|
+
calcAndSetOptionsDimension.call(this);
|
775
|
+
return this;
|
776
|
+
}
|
777
|
+
|
778
|
+
/**
|
779
|
+
*
|
780
|
+
* @return {string}
|
781
|
+
*/
|
782
|
+
static getTag() {
|
783
|
+
return "monster-select";
|
784
|
+
}
|
785
|
+
|
786
|
+
/**
|
787
|
+
*
|
788
|
+
* @return {CSSStyleSheet[]}
|
789
|
+
*/
|
790
|
+
static getCSSStyleSheet() {
|
791
|
+
return [SelectStyleSheet];
|
792
|
+
}
|
787
793
|
}
|
788
794
|
|
789
795
|
/**
|
@@ -798,64 +804,64 @@ class Select extends CustomControl {
|
|
798
804
|
* @return {object}
|
799
805
|
*/
|
800
806
|
function initOptionsFromArguments() {
|
801
|
-
|
802
|
-
|
803
|
-
|
804
|
-
|
805
|
-
|
806
|
-
|
807
|
-
|
808
|
-
|
809
|
-
|
810
|
-
|
811
|
-
|
812
|
-
|
813
|
-
|
814
|
-
|
815
|
-
|
816
|
-
|
817
|
-
|
818
|
-
|
819
|
-
|
820
|
-
|
821
|
-
|
822
|
-
|
823
|
-
|
824
|
-
|
807
|
+
const options = {};
|
808
|
+
|
809
|
+
const template = this.getAttribute("data-monster-selected-template");
|
810
|
+
if (isString(template)) {
|
811
|
+
if (!options["templateMapping"]) options["templateMapping"] = {};
|
812
|
+
|
813
|
+
switch (template) {
|
814
|
+
case "summary":
|
815
|
+
case "default":
|
816
|
+
options["templateMapping"]["selected"] = getSummaryTemplate();
|
817
|
+
break;
|
818
|
+
case "selected":
|
819
|
+
options["templateMapping"]["selected"] = getSelectionTemplate();
|
820
|
+
break;
|
821
|
+
default:
|
822
|
+
addAttributeToken(
|
823
|
+
this,
|
824
|
+
ATTRIBUTE_ERRORMESSAGE,
|
825
|
+
"invalid template, use summary or selected",
|
826
|
+
);
|
827
|
+
}
|
828
|
+
}
|
829
|
+
|
830
|
+
return options;
|
825
831
|
}
|
826
832
|
|
827
833
|
/**
|
828
834
|
* @private
|
829
835
|
*/
|
830
836
|
function attachResizeObserver() {
|
831
|
-
|
832
|
-
|
833
|
-
|
834
|
-
|
835
|
-
|
836
|
-
|
837
|
-
|
838
|
-
|
839
|
-
|
840
|
-
|
841
|
-
|
842
|
-
|
843
|
-
|
844
|
-
|
845
|
-
|
846
|
-
|
847
|
-
|
848
|
-
|
837
|
+
// against flickering
|
838
|
+
this[resizeObserverSymbol] = new ResizeObserver((entries) => {
|
839
|
+
if (this[timerCallbackSymbol] instanceof DeadMansSwitch) {
|
840
|
+
try {
|
841
|
+
this[timerCallbackSymbol].touch();
|
842
|
+
return;
|
843
|
+
} catch (e) {
|
844
|
+
delete this[timerCallbackSymbol];
|
845
|
+
}
|
846
|
+
}
|
847
|
+
|
848
|
+
this[timerCallbackSymbol] = new DeadMansSwitch(200, () => {
|
849
|
+
updatePopper.call(this);
|
850
|
+
delete this[timerCallbackSymbol];
|
851
|
+
});
|
852
|
+
});
|
853
|
+
|
854
|
+
this[resizeObserverSymbol].observe(this.parentElement);
|
849
855
|
}
|
850
856
|
|
851
857
|
function disconnectResizeObserver() {
|
852
|
-
|
853
|
-
|
854
|
-
|
858
|
+
if (this[resizeObserverSymbol] instanceof ResizeObserver) {
|
859
|
+
this[resizeObserverSymbol].disconnect();
|
860
|
+
}
|
855
861
|
}
|
856
862
|
|
857
863
|
function getSelectionTemplate() {
|
858
|
-
|
864
|
+
return `<div data-monster-role="selection"
|
859
865
|
data-monster-insert="selection path:selection" role="search"
|
860
866
|
><input type="text" role="searchbox"
|
861
867
|
part="inline-filter" name="inline-filter"
|
@@ -867,7 +873,7 @@ function getSelectionTemplate() {
|
|
867
873
|
}
|
868
874
|
|
869
875
|
function getSummaryTemplate() {
|
870
|
-
|
876
|
+
return `<div data-monster-role="selection" role="search">
|
871
877
|
<input type="text" role="searchbox"
|
872
878
|
part="inline-filter" name="inline-filter"
|
873
879
|
data-monster-role="filter"
|
@@ -883,35 +889,35 @@ function getSummaryTemplate() {
|
|
883
889
|
* @private
|
884
890
|
*/
|
885
891
|
function parseSlotsToOptions() {
|
886
|
-
|
887
|
-
|
888
|
-
|
889
|
-
|
890
|
-
|
891
|
-
|
892
|
-
|
893
|
-
|
894
|
-
|
895
|
-
|
896
|
-
|
897
|
-
|
898
|
-
|
899
|
-
|
900
|
-
|
901
|
-
|
902
|
-
|
903
|
-
|
904
|
-
|
905
|
-
|
906
|
-
|
907
|
-
|
908
|
-
|
909
|
-
|
910
|
-
|
911
|
-
|
912
|
-
|
913
|
-
|
914
|
-
|
892
|
+
let options = this.getOption("options");
|
893
|
+
if (!isIterable(options)) {
|
894
|
+
options = [];
|
895
|
+
}
|
896
|
+
|
897
|
+
let counter = 1;
|
898
|
+
getSlottedElements.call(this, "div").forEach((node) => {
|
899
|
+
let value = (counter++).toString();
|
900
|
+
let visibility = "visible";
|
901
|
+
|
902
|
+
if (node.hasAttribute("data-monster-value")) {
|
903
|
+
value = node.getAttribute("data-monster-value");
|
904
|
+
}
|
905
|
+
|
906
|
+
if (node.style.display === "none") {
|
907
|
+
visibility = "hidden";
|
908
|
+
}
|
909
|
+
|
910
|
+
const label = node.outerHTML;
|
911
|
+
|
912
|
+
options.push({
|
913
|
+
value,
|
914
|
+
label,
|
915
|
+
visibility,
|
916
|
+
});
|
917
|
+
});
|
918
|
+
|
919
|
+
runAsOptionLengthChanged.call(this, options.length);
|
920
|
+
this.setOption("options", options);
|
915
921
|
}
|
916
922
|
|
917
923
|
/**
|
@@ -921,39 +927,39 @@ function parseSlotsToOptions() {
|
|
921
927
|
* @param {int} targetLength
|
922
928
|
*/
|
923
929
|
function runAsOptionLengthChanged(targetLength) {
|
924
|
-
|
925
|
-
|
926
|
-
|
927
|
-
|
928
|
-
|
929
|
-
|
930
|
-
|
931
|
-
|
932
|
-
|
933
|
-
|
934
|
-
|
935
|
-
|
936
|
-
|
937
|
-
|
938
|
-
|
939
|
-
|
940
|
-
|
941
|
-
|
942
|
-
|
943
|
-
|
944
|
-
|
945
|
-
|
946
|
-
|
947
|
-
|
948
|
-
|
949
|
-
|
950
|
-
|
951
|
-
|
952
|
-
|
953
|
-
|
954
|
-
|
955
|
-
|
956
|
-
|
930
|
+
const self = this;
|
931
|
+
|
932
|
+
if (!self[optionsElementSymbol]) {
|
933
|
+
return;
|
934
|
+
}
|
935
|
+
|
936
|
+
const callback = function (mutationsList, observer) {
|
937
|
+
const run = false;
|
938
|
+
for (const mutation of mutationsList) {
|
939
|
+
if (mutation.type === "childList") {
|
940
|
+
const run = true;
|
941
|
+
break;
|
942
|
+
}
|
943
|
+
}
|
944
|
+
|
945
|
+
if (run === true) {
|
946
|
+
const nodes = self[optionsElementSymbol].querySelectorAll(
|
947
|
+
`div[${ATTRIBUTE_ROLE}=option]`,
|
948
|
+
);
|
949
|
+
|
950
|
+
if (nodes.length === targetLength) {
|
951
|
+
checkOptionState.call(self);
|
952
|
+
observer.disconnect();
|
953
|
+
}
|
954
|
+
}
|
955
|
+
};
|
956
|
+
|
957
|
+
const observer = new MutationObserver(callback);
|
958
|
+
observer.observe(self[optionsElementSymbol], {
|
959
|
+
attributes: false,
|
960
|
+
childList: true,
|
961
|
+
subtree: true,
|
962
|
+
});
|
957
963
|
}
|
958
964
|
|
959
965
|
/**
|
@@ -962,18 +968,18 @@ function runAsOptionLengthChanged(targetLength) {
|
|
962
968
|
* @return {*}
|
963
969
|
*/
|
964
970
|
function buildSelectionLabel(value) {
|
965
|
-
|
966
|
-
|
967
|
-
|
968
|
-
|
969
|
-
|
970
|
-
|
971
|
-
|
972
|
-
|
973
|
-
|
974
|
-
|
975
|
-
|
976
|
-
|
971
|
+
const options = this.getOption("options");
|
972
|
+
|
973
|
+
for (let i = 0; i < options.length; i++) {
|
974
|
+
const o = options?.[i];
|
975
|
+
if (isObject(o) && o?.["value"] === value) {
|
976
|
+
return o?.["label"];
|
977
|
+
} else if (isPrimitive(o) && o === value) {
|
978
|
+
return o;
|
979
|
+
}
|
980
|
+
}
|
981
|
+
|
982
|
+
return undefined;
|
977
983
|
}
|
978
984
|
|
979
985
|
/**
|
@@ -983,17 +989,17 @@ function buildSelectionLabel(value) {
|
|
983
989
|
* @throws {Error} no value found
|
984
990
|
*/
|
985
991
|
function getSelectionLabel(value) {
|
986
|
-
|
987
|
-
|
988
|
-
|
989
|
-
|
990
|
-
|
992
|
+
const callback = this.getOption("formatter.selection");
|
993
|
+
if (isFunction(callback)) {
|
994
|
+
const label = callback.call(this, value);
|
995
|
+
if (isString(label)) return label;
|
996
|
+
}
|
991
997
|
|
992
|
-
|
993
|
-
|
994
|
-
|
998
|
+
if (isString(value) || isInteger(value)) {
|
999
|
+
return `${value}`;
|
1000
|
+
}
|
995
1001
|
|
996
|
-
|
1002
|
+
return this.getOption("labels.cannot-be-loaded", value);
|
997
1003
|
}
|
998
1004
|
|
999
1005
|
/**
|
@@ -1001,16 +1007,25 @@ function getSelectionLabel(value) {
|
|
1001
1007
|
* @param {Event} event
|
1002
1008
|
*/
|
1003
1009
|
function handleToggleKeyboardEvents(event) {
|
1004
|
-
|
1005
|
-
|
1006
|
-
|
1007
|
-
|
1008
|
-
|
1009
|
-
|
1010
|
-
|
1011
|
-
|
1012
|
-
|
1013
|
-
|
1010
|
+
switch (event?.["code"]) {
|
1011
|
+
case "Escape":
|
1012
|
+
toggle.call(this);
|
1013
|
+
event.preventDefault();
|
1014
|
+
break;
|
1015
|
+
case "Space":
|
1016
|
+
toggle.call(this);
|
1017
|
+
event.preventDefault();
|
1018
|
+
break;
|
1019
|
+
case "ArrowDown":
|
1020
|
+
show.call(this);
|
1021
|
+
activateCurrentOption.call(this, FOCUS_DIRECTION_DOWN);
|
1022
|
+
event.preventDefault();
|
1023
|
+
break;
|
1024
|
+
case "ArrowUp":
|
1025
|
+
hide.call(this);
|
1026
|
+
event.preventDefault();
|
1027
|
+
break;
|
1028
|
+
}
|
1014
1029
|
}
|
1015
1030
|
|
1016
1031
|
/**
|
@@ -1020,35 +1035,38 @@ function handleToggleKeyboardEvents(event) {
|
|
1020
1035
|
* @this CustomElement
|
1021
1036
|
*/
|
1022
1037
|
function initOptionObserver() {
|
1023
|
-
|
1024
|
-
|
1025
|
-
|
1026
|
-
|
1027
|
-
|
1028
|
-
|
1029
|
-
|
1030
|
-
|
1031
|
-
|
1032
|
-
|
1033
|
-
|
1034
|
-
|
1035
|
-
|
1036
|
-
|
1037
|
-
|
1038
|
-
|
1038
|
+
const self = this;
|
1039
|
+
|
1040
|
+
self.attachObserver(
|
1041
|
+
new Observer(function () {
|
1042
|
+
new Processing(() => {
|
1043
|
+
try {
|
1044
|
+
self.updateI18n();
|
1045
|
+
} catch (e) {
|
1046
|
+
}
|
1047
|
+
try {
|
1048
|
+
areOptionsAvailableAndInit.call(self);
|
1049
|
+
} catch (e) {
|
1050
|
+
}
|
1051
|
+
|
1052
|
+
setSummaryAndControlText.call(self);
|
1053
|
+
}).run();
|
1054
|
+
}),
|
1055
|
+
);
|
1039
1056
|
}
|
1040
1057
|
|
1041
1058
|
function getDefaultTranslation() {
|
1042
|
-
|
1043
|
-
|
1044
|
-
|
1059
|
+
const translation = new Translations("en").assignTranslations(
|
1060
|
+
this.getOption("labels", {}),
|
1061
|
+
);
|
1045
1062
|
|
1046
|
-
|
1047
|
-
|
1048
|
-
|
1049
|
-
|
1063
|
+
try {
|
1064
|
+
const doc = getDocumentTranslations();
|
1065
|
+
translation.locale = doc.locale;
|
1066
|
+
} catch (e) {
|
1067
|
+
}
|
1050
1068
|
|
1051
|
-
|
1069
|
+
return translation;
|
1052
1070
|
}
|
1053
1071
|
|
1054
1072
|
/**
|
@@ -1056,36 +1074,36 @@ function getDefaultTranslation() {
|
|
1056
1074
|
* @returns {string|*}
|
1057
1075
|
*/
|
1058
1076
|
function setSummaryAndControlText() {
|
1059
|
-
|
1060
|
-
|
1061
|
-
|
1062
|
-
|
1063
|
-
|
1064
|
-
|
1065
|
-
|
1066
|
-
|
1067
|
-
|
1068
|
-
|
1069
|
-
|
1070
|
-
|
1071
|
-
|
1072
|
-
|
1073
|
-
|
1074
|
-
|
1075
|
-
|
1076
|
-
|
1077
|
-
|
1078
|
-
|
1079
|
-
|
1080
|
-
|
1081
|
-
|
1082
|
-
|
1083
|
-
|
1084
|
-
|
1085
|
-
|
1086
|
-
|
1087
|
-
|
1088
|
-
|
1077
|
+
const translations = getDefaultTranslation.call(this);
|
1078
|
+
const selections = this.getOption("selection");
|
1079
|
+
|
1080
|
+
const text = translations.getPluralRuleText(
|
1081
|
+
"summary-text",
|
1082
|
+
selections.length,
|
1083
|
+
"",
|
1084
|
+
);
|
1085
|
+
|
1086
|
+
const selectedText = new Formatter({
|
1087
|
+
count: String(selections.length),
|
1088
|
+
}).format(text);
|
1089
|
+
|
1090
|
+
this.setOption("messages.selected", selectedText);
|
1091
|
+
|
1092
|
+
const current = this.getOption("messages.control");
|
1093
|
+
const msg = this.getOption("labels.select-an-option");
|
1094
|
+
|
1095
|
+
if (
|
1096
|
+
current === "" ||
|
1097
|
+
current === undefined ||
|
1098
|
+
current === msg ||
|
1099
|
+
current === null
|
1100
|
+
) {
|
1101
|
+
if (selections === undefined || selections.length === 0) {
|
1102
|
+
this.setOption("messages.control", msg);
|
1103
|
+
} else {
|
1104
|
+
this.setOption("messages.control", "");
|
1105
|
+
}
|
1106
|
+
}
|
1089
1107
|
}
|
1090
1108
|
|
1091
1109
|
/**
|
@@ -1093,9 +1111,9 @@ function setSummaryAndControlText() {
|
|
1093
1111
|
* @return {NodeList}
|
1094
1112
|
*/
|
1095
1113
|
function getOptionElements() {
|
1096
|
-
|
1097
|
-
|
1098
|
-
|
1114
|
+
return this[optionsElementSymbol].querySelectorAll(
|
1115
|
+
`[${ATTRIBUTE_ROLE}=option]`,
|
1116
|
+
);
|
1099
1117
|
}
|
1100
1118
|
|
1101
1119
|
/**
|
@@ -1121,82 +1139,82 @@ function getOptionElements() {
|
|
1121
1139
|
* @private
|
1122
1140
|
*/
|
1123
1141
|
function calcAndSetOptionsDimension() {
|
1124
|
-
|
1125
|
-
|
1126
|
-
|
1127
|
-
|
1128
|
-
|
1129
|
-
|
1130
|
-
|
1131
|
-
|
1132
|
-
|
1133
|
-
|
1134
|
-
|
1135
|
-
|
1136
|
-
|
1137
|
-
|
1138
|
-
|
1139
|
-
|
1140
|
-
|
1141
|
-
|
1142
|
-
|
1143
|
-
|
1144
|
-
|
1145
|
-
|
1146
|
-
|
1147
|
-
|
1148
|
-
|
1149
|
-
|
1150
|
-
|
1151
|
-
|
1152
|
-
|
1153
|
-
|
1154
|
-
|
1155
|
-
|
1156
|
-
|
1157
|
-
|
1158
|
-
|
1159
|
-
|
1160
|
-
|
1161
|
-
|
1162
|
-
|
1163
|
-
|
1164
|
-
|
1165
|
-
|
1166
|
-
|
1167
|
-
|
1168
|
-
|
1169
|
-
|
1170
|
-
|
1171
|
-
|
1172
|
-
|
1173
|
-
|
1174
|
-
|
1175
|
-
|
1176
|
-
|
1177
|
-
|
1178
|
-
|
1179
|
-
|
1180
|
-
|
1181
|
-
|
1182
|
-
|
1183
|
-
|
1184
|
-
|
1185
|
-
|
1186
|
-
|
1187
|
-
|
1188
|
-
|
1189
|
-
|
1190
|
-
|
1191
|
-
|
1192
|
-
|
1193
|
-
|
1194
|
-
|
1195
|
-
|
1196
|
-
|
1197
|
-
|
1198
|
-
|
1199
|
-
|
1142
|
+
const options = getOptionElements.call(this);
|
1143
|
+
const container = this[optionsElementSymbol];
|
1144
|
+
if (!(container instanceof HTMLElement && options instanceof NodeList)) {
|
1145
|
+
return;
|
1146
|
+
}
|
1147
|
+
|
1148
|
+
let visible = 0;
|
1149
|
+
let optionHeight = 0;
|
1150
|
+
const max = this.getOption("showMaxOptions", 10);
|
1151
|
+
|
1152
|
+
let scrollFlag = false;
|
1153
|
+
for (const [, option] of Object.entries(options)) {
|
1154
|
+
const computedStyle = getGlobal().getComputedStyle(option);
|
1155
|
+
if (computedStyle.display === "none") continue;
|
1156
|
+
|
1157
|
+
let h = option.getBoundingClientRect().height;
|
1158
|
+
h += parseInt(computedStyle.getPropertyValue("margin-top"), 10);
|
1159
|
+
h += parseInt(computedStyle.getPropertyValue("margin-bottom"), 10);
|
1160
|
+
optionHeight += h;
|
1161
|
+
|
1162
|
+
visible++;
|
1163
|
+
|
1164
|
+
if (visible > max) {
|
1165
|
+
break;
|
1166
|
+
}
|
1167
|
+
}
|
1168
|
+
|
1169
|
+
if (visible > max) {
|
1170
|
+
visible = max;
|
1171
|
+
scrollFlag = true;
|
1172
|
+
}
|
1173
|
+
|
1174
|
+
if (visible === 0) {
|
1175
|
+
if (this.getOption("options").length === 0) {
|
1176
|
+
this.setOption(
|
1177
|
+
"messages.emptyOptions",
|
1178
|
+
this.getOption("labels.no-options-available"),
|
1179
|
+
);
|
1180
|
+
} else {
|
1181
|
+
if (this.getOption("filter.mode") === FILTER_MODE_DISABLED) {
|
1182
|
+
this.setOption(
|
1183
|
+
"messages.emptyOptions",
|
1184
|
+
this.getOption("labels.no-options-available"),
|
1185
|
+
);
|
1186
|
+
} else {
|
1187
|
+
this.setOption(
|
1188
|
+
"messages.emptyOptions",
|
1189
|
+
this.getOption("labels.no-options-found"),
|
1190
|
+
);
|
1191
|
+
}
|
1192
|
+
}
|
1193
|
+
this[noOptionsAvailableElementSymbol].classList.remove("d-none");
|
1194
|
+
} else {
|
1195
|
+
this[noOptionsAvailableElementSymbol].classList.add("d-none");
|
1196
|
+
}
|
1197
|
+
|
1198
|
+
const styles = getGlobal().getComputedStyle(this[optionsElementSymbol]);
|
1199
|
+
let padding = parseInt(styles.getPropertyValue("padding-top"), 10);
|
1200
|
+
padding += parseInt(styles.getPropertyValue("padding-bottom"), 10);
|
1201
|
+
|
1202
|
+
let margin = parseInt(styles.getPropertyValue("margin-top"), 10);
|
1203
|
+
margin += parseInt(styles.getPropertyValue("margin-bottom"), 10);
|
1204
|
+
|
1205
|
+
const containerHeight = optionHeight + padding + margin;
|
1206
|
+
container.style.height = `${containerHeight}px`;
|
1207
|
+
|
1208
|
+
if (scrollFlag === true) {
|
1209
|
+
container.style.overflowY = "scroll";
|
1210
|
+
} else {
|
1211
|
+
container.style.overflowY = "auto";
|
1212
|
+
}
|
1213
|
+
|
1214
|
+
const domRect = this[controlElementSymbol].getBoundingClientRect();
|
1215
|
+
|
1216
|
+
this[popperElementSymbol].style.width = `${domRect.width}px`;
|
1217
|
+
container.style.overflowX = "auto";
|
1200
1218
|
}
|
1201
1219
|
|
1202
1220
|
/**
|
@@ -1205,118 +1223,124 @@ function calcAndSetOptionsDimension() {
|
|
1205
1223
|
* @throws {Error} no shadow-root is defined
|
1206
1224
|
*/
|
1207
1225
|
function activateCurrentOption(direction) {
|
1208
|
-
|
1209
|
-
|
1210
|
-
|
1211
|
-
|
1212
|
-
|
1213
|
-
|
1214
|
-
|
1215
|
-
|
1216
|
-
|
1217
|
-
|
1218
|
-
|
1219
|
-
|
1220
|
-
|
1221
|
-
|
1222
|
-
|
1223
|
-
|
1224
|
-
|
1225
|
-
|
1226
|
-
|
1227
|
-
|
1228
|
-
|
1229
|
-
|
1230
|
-
|
1231
|
-
|
1232
|
-
|
1233
|
-
|
1234
|
-
|
1235
|
-
|
1236
|
-
|
1237
|
-
|
1238
|
-
|
1239
|
-
|
1240
|
-
|
1241
|
-
|
1242
|
-
|
1243
|
-
|
1244
|
-
|
1245
|
-
|
1246
|
-
|
1247
|
-
|
1248
|
-
|
1249
|
-
|
1250
|
-
|
1251
|
-
|
1252
|
-
|
1253
|
-
|
1254
|
-
|
1255
|
-
|
1256
|
-
|
1257
|
-
|
1258
|
-
|
1259
|
-
|
1260
|
-
|
1261
|
-
|
1262
|
-
|
1263
|
-
|
1264
|
-
|
1265
|
-
|
1266
|
-
|
1267
|
-
|
1268
|
-
|
1269
|
-
|
1226
|
+
if (!this.shadowRoot) {
|
1227
|
+
throw new Error("no shadow-root is defined");
|
1228
|
+
}
|
1229
|
+
|
1230
|
+
let focused = this.shadowRoot.querySelector(`[${ATTRIBUTE_PREFIX}focused]`);
|
1231
|
+
|
1232
|
+
if (
|
1233
|
+
!(focused instanceof HTMLElement) ||
|
1234
|
+
focused.matches("[data-monster-visibility=hidden]")
|
1235
|
+
) {
|
1236
|
+
for (const [, e] of Object.entries(
|
1237
|
+
this.shadowRoot.querySelectorAll(`[${ATTRIBUTE_ROLE}=option]`),
|
1238
|
+
)) {
|
1239
|
+
if (e.matches("[data-monster-visibility=visible]")) {
|
1240
|
+
focused = e;
|
1241
|
+
break;
|
1242
|
+
}
|
1243
|
+
}
|
1244
|
+
} else {
|
1245
|
+
if (direction === FOCUS_DIRECTION_DOWN) {
|
1246
|
+
while (focused.nextSibling) {
|
1247
|
+
focused = focused.nextSibling;
|
1248
|
+
|
1249
|
+
if (
|
1250
|
+
focused instanceof HTMLElement &&
|
1251
|
+
focused.hasAttribute(ATTRIBUTE_ROLE) &&
|
1252
|
+
focused.getAttribute(ATTRIBUTE_ROLE) === "option" &&
|
1253
|
+
focused.matches("[data-monster-visibility=visible]") &&
|
1254
|
+
focused.matches(":not([data-monster-filtered=true])")
|
1255
|
+
) {
|
1256
|
+
break;
|
1257
|
+
}
|
1258
|
+
}
|
1259
|
+
} else {
|
1260
|
+
let found = false;
|
1261
|
+
while (focused.previousSibling) {
|
1262
|
+
focused = focused.previousSibling;
|
1263
|
+
if (
|
1264
|
+
focused instanceof HTMLElement &&
|
1265
|
+
focused.hasAttribute(ATTRIBUTE_ROLE) &&
|
1266
|
+
focused.getAttribute(ATTRIBUTE_ROLE) === "option" &&
|
1267
|
+
focused.matches("[data-monster-visibility=visible]") &&
|
1268
|
+
focused.matches(":not([data-monster-filtered=true])")
|
1269
|
+
) {
|
1270
|
+
found = true;
|
1271
|
+
break;
|
1272
|
+
}
|
1273
|
+
}
|
1274
|
+
if (found === false) {
|
1275
|
+
focusFilter.call(this);
|
1276
|
+
}
|
1277
|
+
}
|
1278
|
+
}
|
1279
|
+
|
1280
|
+
new Processing(() => {
|
1281
|
+
if (focused instanceof HTMLElement) {
|
1282
|
+
this.shadowRoot
|
1283
|
+
.querySelectorAll(`[${ATTRIBUTE_PREFIX}focused]`)
|
1284
|
+
.forEach((e) => {
|
1285
|
+
e.removeAttribute(`${ATTRIBUTE_PREFIX}focused`);
|
1286
|
+
});
|
1287
|
+
|
1288
|
+
focused.focus();
|
1289
|
+
focused.setAttribute(`${ATTRIBUTE_PREFIX}focused`, true);
|
1290
|
+
}
|
1291
|
+
}).run().catch((e) => {
|
1292
|
+
addAttributeToken(this, ATTRIBUTE_ERRORMESSAGE, e.message);
|
1293
|
+
});
|
1270
1294
|
}
|
1271
1295
|
|
1272
1296
|
/**
|
1273
1297
|
* @private
|
1274
1298
|
*/
|
1275
1299
|
function filterOptions() {
|
1276
|
-
|
1277
|
-
|
1278
|
-
|
1279
|
-
|
1280
|
-
|
1281
|
-
|
1282
|
-
|
1283
|
-
|
1284
|
-
|
1285
|
-
|
1286
|
-
|
1287
|
-
|
1288
|
-
|
1289
|
-
|
1290
|
-
|
1291
|
-
|
1292
|
-
|
1293
|
-
|
1294
|
-
|
1295
|
-
|
1296
|
-
|
1297
|
-
|
1298
|
-
|
1299
|
-
|
1300
|
-
|
1301
|
-
|
1302
|
-
|
1303
|
-
|
1304
|
-
|
1305
|
-
|
1306
|
-
|
1307
|
-
|
1308
|
-
|
1309
|
-
|
1310
|
-
|
1311
|
-
|
1312
|
-
|
1313
|
-
|
1314
|
-
|
1315
|
-
|
1316
|
-
|
1317
|
-
|
1318
|
-
|
1319
|
-
|
1300
|
+
new Processing(() => {
|
1301
|
+
let filterValue;
|
1302
|
+
|
1303
|
+
switch (this.getOption("filter.position")) {
|
1304
|
+
case FILTER_POSITION_INLINE:
|
1305
|
+
if (this[inlineFilterElementSymbol] instanceof HTMLElement) {
|
1306
|
+
filterValue = this[inlineFilterElementSymbol].value.toLowerCase();
|
1307
|
+
} else {
|
1308
|
+
return;
|
1309
|
+
}
|
1310
|
+
|
1311
|
+
break;
|
1312
|
+
case FILTER_POSITION_POPPER:
|
1313
|
+
default:
|
1314
|
+
if (this[popperFilterElementSymbol] instanceof HTMLInputElement) {
|
1315
|
+
filterValue = this[popperFilterElementSymbol].value.toLowerCase();
|
1316
|
+
} else {
|
1317
|
+
return;
|
1318
|
+
}
|
1319
|
+
}
|
1320
|
+
|
1321
|
+
const options = this.getOption("options");
|
1322
|
+
for (const [i, option] of Object.entries(options)) {
|
1323
|
+
if (option.label.toLowerCase().indexOf(filterValue) === -1) {
|
1324
|
+
this.setOption(`options.${i}.filtered`, "true");
|
1325
|
+
} else {
|
1326
|
+
this.setOption(`options.${i}.filtered`, undefined);
|
1327
|
+
}
|
1328
|
+
}
|
1329
|
+
})
|
1330
|
+
.run()
|
1331
|
+
.then(() => {
|
1332
|
+
new Processing(100, () => {
|
1333
|
+
calcAndSetOptionsDimension.call(this);
|
1334
|
+
focusFilter.call(this);
|
1335
|
+
})
|
1336
|
+
.run()
|
1337
|
+
.catch((e) => {
|
1338
|
+
addAttributeToken(this, ATTRIBUTE_ERRORMESSAGE, e.message);
|
1339
|
+
});
|
1340
|
+
})
|
1341
|
+
.catch((e) => {
|
1342
|
+
addAttributeToken(this, ATTRIBUTE_ERRORMESSAGE, e.message);
|
1343
|
+
});
|
1320
1344
|
}
|
1321
1345
|
|
1322
1346
|
/**
|
@@ -1324,37 +1348,37 @@ function filterOptions() {
|
|
1324
1348
|
* @param {Event} event
|
1325
1349
|
*/
|
1326
1350
|
function handleFilterKeyboardEvents(event) {
|
1327
|
-
|
1328
|
-
|
1329
|
-
|
1330
|
-
|
1331
|
-
|
1332
|
-
|
1333
|
-
|
1334
|
-
|
1335
|
-
|
1336
|
-
|
1337
|
-
|
1338
|
-
|
1339
|
-
|
1340
|
-
|
1341
|
-
|
1342
|
-
|
1343
|
-
|
1344
|
-
|
1345
|
-
|
1346
|
-
|
1347
|
-
|
1348
|
-
|
1349
|
-
|
1350
|
-
|
1351
|
-
|
1352
|
-
|
1353
|
-
|
1354
|
-
|
1355
|
-
|
1356
|
-
|
1357
|
-
|
1351
|
+
const shiftKey = event?.["shiftKey"];
|
1352
|
+
|
1353
|
+
switch (event?.["code"]) {
|
1354
|
+
case "Tab":
|
1355
|
+
activateCurrentOption.call(this, FOCUS_DIRECTION_DOWN);
|
1356
|
+
event.preventDefault();
|
1357
|
+
break;
|
1358
|
+
case "Escape":
|
1359
|
+
toggle.call(this);
|
1360
|
+
event.preventDefault();
|
1361
|
+
break;
|
1362
|
+
case "Tab" && shiftKey === true:
|
1363
|
+
case "ArrowUp":
|
1364
|
+
activateCurrentOption.call(this, FOCUS_DIRECTION_UP);
|
1365
|
+
event.preventDefault();
|
1366
|
+
break;
|
1367
|
+
case "Tab" && !shiftKey:
|
1368
|
+
case "ArrowDown":
|
1369
|
+
activateCurrentOption.call(this, FOCUS_DIRECTION_DOWN);
|
1370
|
+
event.preventDefault();
|
1371
|
+
break;
|
1372
|
+
default:
|
1373
|
+
if (
|
1374
|
+
this.getOption("features.lazyLoad") === true &&
|
1375
|
+
this[lazyLoadDoneSymbol] !== true
|
1376
|
+
) {
|
1377
|
+
this.click();
|
1378
|
+
}
|
1379
|
+
|
1380
|
+
handleFilterKeyEvents.call(this);
|
1381
|
+
}
|
1358
1382
|
}
|
1359
1383
|
|
1360
1384
|
/**
|
@@ -1373,63 +1397,63 @@ function handleFilterKeyboardEvents(event) {
|
|
1373
1397
|
* @returns {void} This method does not return anything.
|
1374
1398
|
*/
|
1375
1399
|
function handleFilterKeyEvents() {
|
1376
|
-
|
1377
|
-
|
1378
|
-
|
1379
|
-
|
1380
|
-
|
1381
|
-
|
1382
|
-
|
1383
|
-
|
1384
|
-
|
1385
|
-
|
1386
|
-
|
1387
|
-
|
1388
|
-
|
1389
|
-
|
1390
|
-
|
1391
|
-
|
1392
|
-
|
1393
|
-
|
1394
|
-
|
1395
|
-
|
1400
|
+
if (this[keyFilterEventSymbol] instanceof DeadMansSwitch) {
|
1401
|
+
try {
|
1402
|
+
this[keyFilterEventSymbol].touch();
|
1403
|
+
return;
|
1404
|
+
} catch (e) {
|
1405
|
+
delete this[keyFilterEventSymbol];
|
1406
|
+
}
|
1407
|
+
}
|
1408
|
+
|
1409
|
+
this[keyFilterEventSymbol] = new DeadMansSwitch(200, () => {
|
1410
|
+
if (this.getOption("filter.mode") !== FILTER_MODE_REMOTE) {
|
1411
|
+
filterOptions.call(this);
|
1412
|
+
} else {
|
1413
|
+
filterFromRemote.call(this).catch((e) => {
|
1414
|
+
addAttributeToken(this, ATTRIBUTE_ERRORMESSAGE, e.message);
|
1415
|
+
});
|
1416
|
+
}
|
1417
|
+
|
1418
|
+
delete this[keyFilterEventSymbol];
|
1419
|
+
});
|
1396
1420
|
}
|
1397
1421
|
|
1398
1422
|
/**
|
1399
1423
|
* @private
|
1400
1424
|
*/
|
1401
1425
|
function filterFromRemote() {
|
1402
|
-
|
1403
|
-
|
1404
|
-
|
1405
|
-
|
1406
|
-
|
1407
|
-
|
1408
|
-
|
1409
|
-
|
1410
|
-
|
1411
|
-
|
1412
|
-
|
1413
|
-
|
1414
|
-
|
1415
|
-
|
1416
|
-
|
1417
|
-
|
1418
|
-
|
1419
|
-
|
1420
|
-
|
1421
|
-
|
1422
|
-
|
1423
|
-
|
1424
|
-
|
1425
|
-
|
1426
|
-
|
1427
|
-
|
1428
|
-
|
1429
|
-
|
1430
|
-
|
1431
|
-
|
1432
|
-
|
1426
|
+
if (!(this[inlineFilterElementSymbol] instanceof HTMLElement)) {
|
1427
|
+
return;
|
1428
|
+
}
|
1429
|
+
|
1430
|
+
const optionUrl = this.getOption("url");
|
1431
|
+
if (!optionUrl) {
|
1432
|
+
addAttributeToken(
|
1433
|
+
this,
|
1434
|
+
ATTRIBUTE_ERRORMESSAGE,
|
1435
|
+
"Missing URL for Remote Filter.",
|
1436
|
+
);
|
1437
|
+
return;
|
1438
|
+
}
|
1439
|
+
|
1440
|
+
return new Processing(() => {
|
1441
|
+
const filterValue = encodeURI(
|
1442
|
+
this[inlineFilterElementSymbol].value.toLowerCase(),
|
1443
|
+
);
|
1444
|
+
let url = optionUrl;
|
1445
|
+
if (filterValue.length > 0) {
|
1446
|
+
url = new Formatter({filter: filterValue}).format(optionUrl);
|
1447
|
+
}
|
1448
|
+
|
1449
|
+
this.fetch(url)
|
1450
|
+
.then(() => {
|
1451
|
+
checkOptionState.call(this);
|
1452
|
+
})
|
1453
|
+
.catch((e) => {
|
1454
|
+
throw e;
|
1455
|
+
});
|
1456
|
+
}).run();
|
1433
1457
|
}
|
1434
1458
|
|
1435
1459
|
/**
|
@@ -1438,45 +1462,45 @@ function filterFromRemote() {
|
|
1438
1462
|
* @private
|
1439
1463
|
*/
|
1440
1464
|
function handleOptionKeyboardEvents(event) {
|
1441
|
-
|
1442
|
-
|
1443
|
-
|
1444
|
-
|
1445
|
-
|
1446
|
-
|
1447
|
-
|
1448
|
-
|
1449
|
-
|
1450
|
-
|
1451
|
-
|
1452
|
-
|
1453
|
-
|
1454
|
-
|
1455
|
-
|
1456
|
-
|
1457
|
-
|
1458
|
-
|
1459
|
-
|
1460
|
-
|
1461
|
-
|
1462
|
-
|
1463
|
-
|
1464
|
-
|
1465
|
-
|
1466
|
-
|
1467
|
-
|
1468
|
-
|
1469
|
-
|
1470
|
-
|
1471
|
-
|
1472
|
-
|
1473
|
-
|
1474
|
-
|
1475
|
-
|
1476
|
-
|
1477
|
-
|
1478
|
-
|
1479
|
-
|
1465
|
+
const shiftKey = event?.["shiftKey"];
|
1466
|
+
|
1467
|
+
switch (event?.["code"]) {
|
1468
|
+
case "Escape":
|
1469
|
+
toggle.call(this);
|
1470
|
+
event.preventDefault();
|
1471
|
+
break;
|
1472
|
+
case "Enter":
|
1473
|
+
case "Space":
|
1474
|
+
const path = event.composedPath();
|
1475
|
+
const element = path?.[0];
|
1476
|
+
|
1477
|
+
fireEvent(element.getElementsByTagName("input"), "click");
|
1478
|
+
event.preventDefault();
|
1479
|
+
break;
|
1480
|
+
|
1481
|
+
case "Tab" && shiftKey === true:
|
1482
|
+
case "ArrowUp":
|
1483
|
+
activateCurrentOption.call(this, FOCUS_DIRECTION_UP);
|
1484
|
+
event.preventDefault();
|
1485
|
+
break;
|
1486
|
+
|
1487
|
+
case "Tab" && !shiftKey:
|
1488
|
+
case "ArrowLeft":
|
1489
|
+
case "ArrowRight":
|
1490
|
+
// handled by tree select
|
1491
|
+
break;
|
1492
|
+
case "ArrowDown":
|
1493
|
+
activateCurrentOption.call(this, FOCUS_DIRECTION_DOWN);
|
1494
|
+
event.preventDefault();
|
1495
|
+
break;
|
1496
|
+
default:
|
1497
|
+
const p = event.composedPath();
|
1498
|
+
if (p?.[0] instanceof HTMLInputElement) {
|
1499
|
+
return;
|
1500
|
+
}
|
1501
|
+
focusFilter.call(this);
|
1502
|
+
break;
|
1503
|
+
}
|
1480
1504
|
}
|
1481
1505
|
|
1482
1506
|
/**
|
@@ -1484,33 +1508,33 @@ function handleOptionKeyboardEvents(event) {
|
|
1484
1508
|
* @returns {string}
|
1485
1509
|
*/
|
1486
1510
|
function getFilterMode() {
|
1487
|
-
|
1488
|
-
|
1489
|
-
|
1490
|
-
|
1491
|
-
|
1492
|
-
|
1493
|
-
|
1494
|
-
|
1511
|
+
switch (this.getOption("filter.mode")) {
|
1512
|
+
case FILTER_MODE_OPTIONS:
|
1513
|
+
return FILTER_MODE_OPTIONS;
|
1514
|
+
case FILTER_MODE_REMOTE:
|
1515
|
+
return FILTER_MODE_REMOTE;
|
1516
|
+
default:
|
1517
|
+
return FILTER_MODE_DISABLED;
|
1518
|
+
}
|
1495
1519
|
}
|
1496
1520
|
|
1497
1521
|
/**
|
1498
1522
|
* @private
|
1499
1523
|
*/
|
1500
1524
|
function blurFilter() {
|
1501
|
-
|
1502
|
-
|
1503
|
-
|
1525
|
+
if (!(this[inlineFilterElementSymbol] instanceof HTMLElement)) {
|
1526
|
+
return;
|
1527
|
+
}
|
1504
1528
|
|
1505
|
-
|
1506
|
-
|
1507
|
-
|
1529
|
+
if (getFilterMode.call(this) === FILTER_MODE_DISABLED) {
|
1530
|
+
return;
|
1531
|
+
}
|
1508
1532
|
|
1509
|
-
|
1510
|
-
|
1533
|
+
this[popperFilterContainerElementSymbol].classList.remove("active");
|
1534
|
+
this[popperFilterContainerElementSymbol].blur();
|
1511
1535
|
|
1512
|
-
|
1513
|
-
|
1536
|
+
this[inlineFilterElementSymbol].classList.remove("active");
|
1537
|
+
this[inlineFilterElementSymbol].blur();
|
1514
1538
|
}
|
1515
1539
|
|
1516
1540
|
/**
|
@@ -1518,29 +1542,29 @@ function blurFilter() {
|
|
1518
1542
|
* @param focusOptions
|
1519
1543
|
*/
|
1520
1544
|
function focusPopperFilter(focusOptions) {
|
1521
|
-
|
1522
|
-
|
1523
|
-
|
1524
|
-
|
1525
|
-
|
1526
|
-
|
1527
|
-
|
1528
|
-
|
1529
|
-
|
1530
|
-
|
1531
|
-
|
1532
|
-
|
1533
|
-
|
1534
|
-
|
1535
|
-
|
1536
|
-
|
1537
|
-
|
1538
|
-
|
1539
|
-
|
1540
|
-
|
1541
|
-
|
1542
|
-
|
1543
|
-
|
1545
|
+
this[popperFilterContainerElementSymbol].classList.remove("d-none");
|
1546
|
+
this[popperFilterElementSymbol].classList.add("active");
|
1547
|
+
this[inlineFilterElementSymbol].classList.remove("active");
|
1548
|
+
this[inlineFilterElementSymbol].classList.add("d-none");
|
1549
|
+
|
1550
|
+
if (!(this[popperFilterElementSymbol] instanceof HTMLElement)) {
|
1551
|
+
addAttributeToken(
|
1552
|
+
this,
|
1553
|
+
ATTRIBUTE_ERRORMESSAGE,
|
1554
|
+
"Missing Popper Filter Element.",
|
1555
|
+
);
|
1556
|
+
return;
|
1557
|
+
}
|
1558
|
+
|
1559
|
+
// visibility is set to visible, because focus() does not work on invisible elements
|
1560
|
+
// and the class definition is assigned later in the processing
|
1561
|
+
setTimeout(() => {
|
1562
|
+
if (focusOptions === undefined || focusOptions === null) {
|
1563
|
+
this[popperFilterElementSymbol].focus();
|
1564
|
+
} else {
|
1565
|
+
this[popperFilterElementSymbol].focus(focusOptions);
|
1566
|
+
}
|
1567
|
+
}, 100);
|
1544
1568
|
}
|
1545
1569
|
|
1546
1570
|
/**
|
@@ -1548,44 +1572,44 @@ function focusPopperFilter(focusOptions) {
|
|
1548
1572
|
* @param focusOptions
|
1549
1573
|
*/
|
1550
1574
|
function focusInlineFilter(focusOptions) {
|
1551
|
-
|
1552
|
-
|
1553
|
-
|
1554
|
-
|
1555
|
-
|
1556
|
-
|
1557
|
-
|
1558
|
-
|
1559
|
-
|
1560
|
-
|
1561
|
-
|
1562
|
-
|
1563
|
-
|
1564
|
-
|
1565
|
-
|
1566
|
-
|
1567
|
-
|
1568
|
-
|
1569
|
-
|
1570
|
-
|
1571
|
-
|
1575
|
+
const options = this.getOption("options");
|
1576
|
+
if (
|
1577
|
+
(!isArray(options) || options.length === 0) &&
|
1578
|
+
this.getOption("filter.mode") !== FILTER_MODE_REMOTE
|
1579
|
+
) {
|
1580
|
+
return;
|
1581
|
+
}
|
1582
|
+
|
1583
|
+
this[popperFilterContainerElementSymbol].classList.add("d-none");
|
1584
|
+
this[inlineFilterElementSymbol].classList.add("active");
|
1585
|
+
this[inlineFilterElementSymbol].classList.remove("d-none");
|
1586
|
+
|
1587
|
+
// visibility is set to visible, because focus() does not work on invisible elements
|
1588
|
+
// and the class definition is assigned later in the processing
|
1589
|
+
setTimeout(() => {
|
1590
|
+
if (focusOptions === undefined || focusOptions === null) {
|
1591
|
+
this[inlineFilterElementSymbol].focus();
|
1592
|
+
} else {
|
1593
|
+
this[inlineFilterElementSymbol].focus(focusOptions);
|
1594
|
+
}
|
1595
|
+
}, 100);
|
1572
1596
|
}
|
1573
1597
|
|
1574
1598
|
/**
|
1575
1599
|
* @private
|
1576
1600
|
*/
|
1577
1601
|
function focusFilter(focusOptions) {
|
1578
|
-
|
1579
|
-
|
1580
|
-
|
1581
|
-
|
1582
|
-
|
1602
|
+
if (getFilterMode.call(this) === FILTER_MODE_DISABLED) {
|
1603
|
+
this[popperFilterContainerElementSymbol].classList.add("d-none");
|
1604
|
+
this[inlineFilterElementSymbol].classList.add("d-none");
|
1605
|
+
return;
|
1606
|
+
}
|
1583
1607
|
|
1584
|
-
|
1585
|
-
|
1586
|
-
|
1608
|
+
if (this.getOption("filter.position") === FILTER_POSITION_INLINE) {
|
1609
|
+
return focusInlineFilter.call(this, focusOptions);
|
1610
|
+
}
|
1587
1611
|
|
1588
|
-
|
1612
|
+
return focusPopperFilter.call(this, focusOptions);
|
1589
1613
|
}
|
1590
1614
|
|
1591
1615
|
/**
|
@@ -1595,38 +1619,39 @@ function focusFilter(focusOptions) {
|
|
1595
1619
|
* @throws {Error} unsupported type
|
1596
1620
|
*/
|
1597
1621
|
function gatherState() {
|
1598
|
-
|
1599
|
-
|
1600
|
-
|
1601
|
-
|
1602
|
-
|
1603
|
-
|
1604
|
-
|
1605
|
-
|
1606
|
-
|
1607
|
-
|
1608
|
-
|
1609
|
-
|
1610
|
-
|
1611
|
-
|
1612
|
-
|
1613
|
-
|
1614
|
-
|
1615
|
-
|
1616
|
-
|
1617
|
-
|
1618
|
-
|
1619
|
-
|
1620
|
-
|
1621
|
-
|
1622
|
-
|
1623
|
-
|
1624
|
-
|
1625
|
-
|
1626
|
-
|
1627
|
-
|
1628
|
-
|
1629
|
-
|
1622
|
+
const type = this.getOption("type");
|
1623
|
+
if (["radio", "checkbox"].indexOf(type) === -1) {
|
1624
|
+
throw new Error("unsupported type");
|
1625
|
+
}
|
1626
|
+
|
1627
|
+
if (!this.shadowRoot) {
|
1628
|
+
throw new Error("no shadow-root is defined");
|
1629
|
+
}
|
1630
|
+
|
1631
|
+
const selection = [];
|
1632
|
+
const elements = this.shadowRoot.querySelectorAll(
|
1633
|
+
`input[type=${type}]:checked`,
|
1634
|
+
);
|
1635
|
+
for (const e of elements) {
|
1636
|
+
selection.push({
|
1637
|
+
label: getSelectionLabel.call(this, e.value),
|
1638
|
+
value: e.value,
|
1639
|
+
});
|
1640
|
+
}
|
1641
|
+
|
1642
|
+
setSelection
|
1643
|
+
.call(this, selection)
|
1644
|
+
.then(() => {
|
1645
|
+
})
|
1646
|
+
.catch((e) => {
|
1647
|
+
addAttributeToken(this, ATTRIBUTE_ERRORMESSAGE, `${e}`);
|
1648
|
+
});
|
1649
|
+
|
1650
|
+
if (this.getOption("features.closeOnSelect") === true) {
|
1651
|
+
toggle.call(this);
|
1652
|
+
}
|
1653
|
+
|
1654
|
+
return this;
|
1630
1655
|
}
|
1631
1656
|
|
1632
1657
|
/**
|
@@ -1635,117 +1660,118 @@ function gatherState() {
|
|
1635
1660
|
* @throws {Error} unsupported type
|
1636
1661
|
*/
|
1637
1662
|
function clearSelection() {
|
1638
|
-
|
1639
|
-
|
1640
|
-
|
1641
|
-
|
1642
|
-
|
1643
|
-
|
1644
|
-
|
1645
|
-
|
1646
|
-
|
1647
|
-
|
1648
|
-
|
1649
|
-
|
1650
|
-
|
1651
|
-
|
1652
|
-
|
1663
|
+
const type = this.getOption("type");
|
1664
|
+
if (["radio", "checkbox"].indexOf(type) === -1) {
|
1665
|
+
throw new Error("unsupported type");
|
1666
|
+
}
|
1667
|
+
|
1668
|
+
if (!this.shadowRoot) {
|
1669
|
+
throw new Error("no shadow-root is defined");
|
1670
|
+
}
|
1671
|
+
|
1672
|
+
setSelection
|
1673
|
+
.call(this, [])
|
1674
|
+
.then(() => {
|
1675
|
+
})
|
1676
|
+
.catch((e) => {
|
1677
|
+
addAttributeToken(this, ATTRIBUTE_ERRORMESSAGE, `${e}`);
|
1678
|
+
});
|
1653
1679
|
}
|
1654
1680
|
|
1655
1681
|
/**
|
1656
1682
|
* @private
|
1657
1683
|
*/
|
1658
1684
|
function areOptionsAvailableAndInit() {
|
1659
|
-
|
1660
|
-
|
1661
|
-
|
1662
|
-
|
1663
|
-
|
1664
|
-
|
1665
|
-
|
1666
|
-
|
1667
|
-
|
1668
|
-
|
1669
|
-
|
1670
|
-
|
1671
|
-
|
1672
|
-
|
1673
|
-
|
1674
|
-
|
1675
|
-
|
1676
|
-
|
1677
|
-
|
1678
|
-
|
1679
|
-
|
1680
|
-
|
1681
|
-
|
1682
|
-
|
1683
|
-
|
1684
|
-
|
1685
|
-
|
1686
|
-
|
1687
|
-
|
1688
|
-
|
1689
|
-
|
1690
|
-
|
1691
|
-
|
1692
|
-
|
1693
|
-
|
1694
|
-
|
1695
|
-
|
1696
|
-
|
1697
|
-
|
1698
|
-
|
1699
|
-
|
1700
|
-
|
1701
|
-
|
1702
|
-
|
1703
|
-
|
1704
|
-
|
1705
|
-
|
1706
|
-
|
1707
|
-
|
1708
|
-
|
1709
|
-
|
1710
|
-
|
1711
|
-
|
1712
|
-
|
1713
|
-
|
1714
|
-
|
1715
|
-
|
1716
|
-
|
1717
|
-
|
1718
|
-
|
1719
|
-
|
1720
|
-
|
1721
|
-
|
1722
|
-
|
1723
|
-
|
1724
|
-
|
1725
|
-
|
1726
|
-
|
1727
|
-
|
1728
|
-
|
1729
|
-
|
1730
|
-
|
1731
|
-
|
1732
|
-
|
1733
|
-
|
1734
|
-
|
1735
|
-
|
1736
|
-
|
1737
|
-
|
1738
|
-
|
1739
|
-
|
1740
|
-
|
1741
|
-
|
1742
|
-
|
1743
|
-
|
1744
|
-
|
1745
|
-
|
1746
|
-
|
1747
|
-
|
1748
|
-
|
1685
|
+
// prevent multiple calls
|
1686
|
+
if (this[areOptionsAvailableAndInitSymbol] === undefined) {
|
1687
|
+
this[areOptionsAvailableAndInitSymbol] = 0;
|
1688
|
+
}
|
1689
|
+
|
1690
|
+
if (this[areOptionsAvailableAndInitSymbol] > 0) {
|
1691
|
+
this[areOptionsAvailableAndInitSymbol]--;
|
1692
|
+
return true;
|
1693
|
+
}
|
1694
|
+
|
1695
|
+
this[areOptionsAvailableAndInitSymbol]++;
|
1696
|
+
|
1697
|
+
const options = this.getOption("options");
|
1698
|
+
|
1699
|
+
if (
|
1700
|
+
options === undefined ||
|
1701
|
+
options === null ||
|
1702
|
+
(isArray(options) && options.length === 0)
|
1703
|
+
) {
|
1704
|
+
setStatusOrRemoveBadges.call(this, "empty");
|
1705
|
+
|
1706
|
+
hide.call(this);
|
1707
|
+
|
1708
|
+
let msg = this.getOption("labels.no-options-available");
|
1709
|
+
|
1710
|
+
if (
|
1711
|
+
this.getOption("url") !== null &&
|
1712
|
+
this.getOption("features.lazyLoad") === true &&
|
1713
|
+
this[lazyLoadDoneSymbol] !== true
|
1714
|
+
) {
|
1715
|
+
msg = this.getOption("labels.click-to-load-options");
|
1716
|
+
}
|
1717
|
+
|
1718
|
+
this.setOption("messages.control", msg);
|
1719
|
+
this.setOption("messages.summary", "");
|
1720
|
+
this.setOption("selection", []);
|
1721
|
+
addAttributeToken(this, ATTRIBUTE_ERRORMESSAGE, noOptionsAvailableMessage);
|
1722
|
+
return false;
|
1723
|
+
}
|
1724
|
+
|
1725
|
+
const selections = this.getOption("selection");
|
1726
|
+
if (
|
1727
|
+
selections === undefined ||
|
1728
|
+
selections === null ||
|
1729
|
+
selections.length === 0
|
1730
|
+
) {
|
1731
|
+
this.setOption(
|
1732
|
+
"messages.control",
|
1733
|
+
this.getOption("labels.select-an-option"),
|
1734
|
+
);
|
1735
|
+
} else {
|
1736
|
+
this.setOption("messages.control", "");
|
1737
|
+
}
|
1738
|
+
|
1739
|
+
this.setOption("messages.summary", setSummaryAndControlText.call(this));
|
1740
|
+
|
1741
|
+
let updated = false;
|
1742
|
+
let valueCounter = 1;
|
1743
|
+
for (const option of options) {
|
1744
|
+
if (option?.visibility === undefined) {
|
1745
|
+
option.visibility = "visible";
|
1746
|
+
updated = true;
|
1747
|
+
}
|
1748
|
+
|
1749
|
+
if (option?.value === undefined && option?.label === undefined) {
|
1750
|
+
option.value = `${valueCounter++}`;
|
1751
|
+
option.label = option.value;
|
1752
|
+
updated = true;
|
1753
|
+
continue;
|
1754
|
+
}
|
1755
|
+
|
1756
|
+
if (option?.value === undefined) {
|
1757
|
+
option.value = option.label;
|
1758
|
+
updated = true;
|
1759
|
+
}
|
1760
|
+
|
1761
|
+
if (option?.label === undefined) {
|
1762
|
+
option.label = option.value;
|
1763
|
+
updated = true;
|
1764
|
+
}
|
1765
|
+
}
|
1766
|
+
|
1767
|
+
if (updated) {
|
1768
|
+
this.setOption("options", options);
|
1769
|
+
}
|
1770
|
+
|
1771
|
+
setStatusOrRemoveBadges.call(this, "status");
|
1772
|
+
|
1773
|
+
removeAttributeToken(this, ATTRIBUTE_ERRORMESSAGE, noOptionsAvailableMessage);
|
1774
|
+
return true;
|
1749
1775
|
}
|
1750
1776
|
|
1751
1777
|
/**
|
@@ -1753,30 +1779,30 @@ function areOptionsAvailableAndInit() {
|
|
1753
1779
|
* @throws {Error} no shadow-root is defined
|
1754
1780
|
*/
|
1755
1781
|
function checkOptionState() {
|
1756
|
-
|
1757
|
-
|
1758
|
-
|
1759
|
-
|
1760
|
-
|
1761
|
-
|
1762
|
-
|
1763
|
-
|
1764
|
-
|
1765
|
-
|
1766
|
-
|
1767
|
-
|
1768
|
-
|
1769
|
-
|
1770
|
-
|
1771
|
-
|
1772
|
-
|
1773
|
-
|
1774
|
-
|
1775
|
-
|
1776
|
-
|
1777
|
-
|
1778
|
-
|
1779
|
-
|
1782
|
+
if (!this.shadowRoot) {
|
1783
|
+
throw new Error("no shadow-root is defined");
|
1784
|
+
}
|
1785
|
+
|
1786
|
+
const elements = this.shadowRoot.querySelectorAll(
|
1787
|
+
`[${ATTRIBUTE_ROLE}=option] input`,
|
1788
|
+
);
|
1789
|
+
|
1790
|
+
let selection = this.getOption("selection");
|
1791
|
+
if (!isArray(selection)) {
|
1792
|
+
selection = [];
|
1793
|
+
}
|
1794
|
+
|
1795
|
+
const checkedValues = selection.map((a) => {
|
1796
|
+
return a.value;
|
1797
|
+
});
|
1798
|
+
|
1799
|
+
for (const e of elements) {
|
1800
|
+
if (checkedValues.indexOf(e.value) !== -1) {
|
1801
|
+
if (e.checked !== true) e.checked = true;
|
1802
|
+
} else {
|
1803
|
+
if (e.checked !== false) e.checked = false;
|
1804
|
+
}
|
1805
|
+
}
|
1780
1806
|
}
|
1781
1807
|
|
1782
1808
|
/**
|
@@ -1785,41 +1811,41 @@ function checkOptionState() {
|
|
1785
1811
|
* @return {Object}
|
1786
1812
|
*/
|
1787
1813
|
function convertValueToSelection(value) {
|
1788
|
-
|
1789
|
-
|
1790
|
-
|
1791
|
-
|
1792
|
-
|
1793
|
-
|
1794
|
-
|
1795
|
-
|
1796
|
-
|
1797
|
-
|
1798
|
-
|
1799
|
-
|
1800
|
-
|
1801
|
-
|
1802
|
-
|
1803
|
-
|
1804
|
-
|
1805
|
-
|
1806
|
-
|
1807
|
-
|
1808
|
-
|
1809
|
-
|
1810
|
-
|
1811
|
-
|
1812
|
-
|
1813
|
-
|
1814
|
-
|
1815
|
-
|
1816
|
-
|
1817
|
-
|
1818
|
-
|
1819
|
-
|
1820
|
-
|
1821
|
-
|
1822
|
-
|
1814
|
+
const selection = [];
|
1815
|
+
|
1816
|
+
if (isString(value)) {
|
1817
|
+
value = value
|
1818
|
+
.split(",")
|
1819
|
+
.map((a) => {
|
1820
|
+
return a.trim();
|
1821
|
+
})
|
1822
|
+
.filter((a) => {
|
1823
|
+
return a !== "";
|
1824
|
+
});
|
1825
|
+
}
|
1826
|
+
|
1827
|
+
if (isString(value) || isInteger(value)) {
|
1828
|
+
selection.push({
|
1829
|
+
label: getSelectionLabel.call(this, value),
|
1830
|
+
value: value,
|
1831
|
+
});
|
1832
|
+
} else if (isArray(value)) {
|
1833
|
+
for (const v of value) {
|
1834
|
+
selection.push({
|
1835
|
+
label: getSelectionLabel.call(this, v),
|
1836
|
+
value: v,
|
1837
|
+
});
|
1838
|
+
}
|
1839
|
+
|
1840
|
+
value = value.join(",");
|
1841
|
+
} else {
|
1842
|
+
throw new Error("unsupported type");
|
1843
|
+
}
|
1844
|
+
|
1845
|
+
return {
|
1846
|
+
selection: selection,
|
1847
|
+
value: value,
|
1848
|
+
};
|
1823
1849
|
}
|
1824
1850
|
|
1825
1851
|
/**
|
@@ -1828,22 +1854,22 @@ function convertValueToSelection(value) {
|
|
1828
1854
|
* @return {string}
|
1829
1855
|
*/
|
1830
1856
|
function convertSelectionToValue(selection) {
|
1831
|
-
|
1832
|
-
|
1833
|
-
|
1834
|
-
|
1835
|
-
|
1836
|
-
|
1837
|
-
|
1838
|
-
|
1839
|
-
|
1840
|
-
|
1841
|
-
|
1842
|
-
|
1843
|
-
|
1844
|
-
|
1845
|
-
|
1846
|
-
|
1857
|
+
const value = [];
|
1858
|
+
|
1859
|
+
if (isArray(selection)) {
|
1860
|
+
for (const obj of selection) {
|
1861
|
+
const v = obj?.["value"];
|
1862
|
+
if (v !== undefined) value.push(v);
|
1863
|
+
}
|
1864
|
+
}
|
1865
|
+
|
1866
|
+
if (value.length === 0) {
|
1867
|
+
return "";
|
1868
|
+
} else if (value.length === 1) {
|
1869
|
+
return value.pop();
|
1870
|
+
}
|
1871
|
+
|
1872
|
+
return value.join(",");
|
1847
1873
|
}
|
1848
1874
|
|
1849
1875
|
/**
|
@@ -1853,54 +1879,56 @@ function convertSelectionToValue(selection) {
|
|
1853
1879
|
* @throws {Error} no shadow-root is defined
|
1854
1880
|
*/
|
1855
1881
|
function setSelection(selection) {
|
1856
|
-
|
1857
|
-
|
1858
|
-
|
1859
|
-
|
1860
|
-
|
1861
|
-
|
1862
|
-
|
1863
|
-
|
1864
|
-
|
1865
|
-
|
1866
|
-
|
1867
|
-
|
1868
|
-
|
1869
|
-
|
1870
|
-
|
1871
|
-
|
1872
|
-
|
1873
|
-
|
1874
|
-
|
1875
|
-
|
1876
|
-
|
1877
|
-
|
1878
|
-
|
1879
|
-
|
1880
|
-
|
1881
|
-
|
1882
|
-
|
1883
|
-
|
1884
|
-
|
1885
|
-
|
1886
|
-
|
1887
|
-
|
1888
|
-
|
1889
|
-
|
1890
|
-
|
1891
|
-
|
1892
|
-
|
1893
|
-
|
1894
|
-
|
1895
|
-
|
1896
|
-
|
1897
|
-
|
1898
|
-
|
1899
|
-
|
1900
|
-
|
1901
|
-
|
1902
|
-
|
1903
|
-
|
1882
|
+
if (isString(selection)) {
|
1883
|
+
const result = convertValueToSelection.call(this, selection);
|
1884
|
+
selection = result?.selection;
|
1885
|
+
} else if (selection === undefined) {
|
1886
|
+
selection = [];
|
1887
|
+
}
|
1888
|
+
|
1889
|
+
this.setOption("selection", validateArray(selection));
|
1890
|
+
checkOptionState.call(this);
|
1891
|
+
|
1892
|
+
try {
|
1893
|
+
this?.setFormValue(this.value);
|
1894
|
+
} catch (e) {
|
1895
|
+
addAttributeToken(this, ATTRIBUTE_ERRORMESSAGE, e.message);
|
1896
|
+
}
|
1897
|
+
|
1898
|
+
fireCustomEvent(this, "monster-selected", {
|
1899
|
+
selection,
|
1900
|
+
});
|
1901
|
+
|
1902
|
+
return new Processing(() => {
|
1903
|
+
const CLASSNAME = "selected";
|
1904
|
+
|
1905
|
+
if (!this.shadowRoot) {
|
1906
|
+
throw new Error("no shadow-root is defined");
|
1907
|
+
}
|
1908
|
+
|
1909
|
+
const notSelected = this.shadowRoot.querySelectorAll(":not(:checked)");
|
1910
|
+
|
1911
|
+
if (notSelected) {
|
1912
|
+
notSelected.forEach((node) => {
|
1913
|
+
const parent = node.closest(`[${ATTRIBUTE_ROLE}=option]`);
|
1914
|
+
if (parent) {
|
1915
|
+
parent.classList.remove(CLASSNAME);
|
1916
|
+
}
|
1917
|
+
});
|
1918
|
+
}
|
1919
|
+
|
1920
|
+
const selected = this.shadowRoot.querySelectorAll(":checked");
|
1921
|
+
if (selected) {
|
1922
|
+
selected.forEach((node) => {
|
1923
|
+
const parent = node.closest(`[${ATTRIBUTE_ROLE}=option]`);
|
1924
|
+
if (parent) {
|
1925
|
+
parent.classList.add(CLASSNAME);
|
1926
|
+
}
|
1927
|
+
});
|
1928
|
+
}
|
1929
|
+
}).run().catch((e) => {
|
1930
|
+
addAttributeToken(this, ATTRIBUTE_ERRORMESSAGE, e.message);
|
1931
|
+
});
|
1904
1932
|
}
|
1905
1933
|
|
1906
1934
|
/**
|
@@ -1910,134 +1938,132 @@ function setSelection(selection) {
|
|
1910
1938
|
* @throws {TypeError} the result cannot be parsed
|
1911
1939
|
* @throws {TypeError} unsupported response
|
1912
1940
|
*/
|
1913
|
-
function fetchData(url) {
|
1914
|
-
|
1915
|
-
|
1916
|
-
|
1917
|
-
|
1918
|
-
|
1919
|
-
|
1920
|
-
|
1921
|
-
|
1922
|
-
|
1923
|
-
|
1924
|
-
|
1925
|
-
|
1926
|
-
|
1927
|
-
|
1928
|
-
|
1929
|
-
|
1930
|
-
|
1931
|
-
|
1932
|
-
|
1933
|
-
|
1934
|
-
|
1935
|
-
|
1936
|
-
|
1937
|
-
|
1938
|
-
|
1939
|
-
|
1940
|
-
|
1941
|
-
|
1942
|
-
|
1943
|
-
|
1944
|
-
|
1945
|
-
|
1941
|
+
function fetchData(url) {
|
1942
|
+
|
1943
|
+
if (!url) url = this.getOption("url");
|
1944
|
+
if (!url) return Promise.resolve();
|
1945
|
+
|
1946
|
+
const fetchOptions = this.getOption("fetch", {});
|
1947
|
+
|
1948
|
+
setStatusOrRemoveBadges.call(this, "loading");
|
1949
|
+
url = new Formatter({filter: this.getOption("filter.defaultValue")}).format(
|
1950
|
+
url,
|
1951
|
+
);
|
1952
|
+
|
1953
|
+
const global = getGlobal();
|
1954
|
+
return global
|
1955
|
+
.fetch(url, fetchOptions)
|
1956
|
+
.then((response) => {
|
1957
|
+
const contentType = response.headers.get("content-type");
|
1958
|
+
if (contentType && contentType.indexOf("application/json") !== -1) {
|
1959
|
+
return response.text();
|
1960
|
+
}
|
1961
|
+
|
1962
|
+
throw new TypeError(`unsupported response ${contentType}`);
|
1963
|
+
})
|
1964
|
+
.then((text) => {
|
1965
|
+
try {
|
1966
|
+
return Promise.resolve(JSON.parse(String(text)));
|
1967
|
+
} catch (e) {
|
1968
|
+
throw new TypeError("the result cannot be parsed");
|
1969
|
+
}
|
1970
|
+
})
|
1971
|
+
.catch((e) => {
|
1972
|
+
throw e;
|
1973
|
+
});
|
1946
1974
|
}
|
1947
1975
|
|
1948
1976
|
/**
|
1949
1977
|
* @private
|
1950
1978
|
*/
|
1951
1979
|
function hide() {
|
1952
|
-
|
1953
|
-
|
1954
|
-
|
1980
|
+
this[popperElementSymbol].style.display = "none";
|
1981
|
+
setStatusOrRemoveBadges.call(this, "status");
|
1982
|
+
removeAttributeToken(this[controlElementSymbol], "class", "open");
|
1955
1983
|
}
|
1956
1984
|
|
1957
1985
|
/**
|
1958
1986
|
* @private
|
1959
1987
|
*/
|
1960
|
-
function show() {
|
1961
|
-
|
1962
|
-
|
1963
|
-
|
1964
|
-
|
1965
|
-
|
1966
|
-
|
1967
|
-
|
1968
|
-
|
1969
|
-
|
1970
|
-
|
1971
|
-
|
1972
|
-
|
1973
|
-
|
1974
|
-
|
1975
|
-
|
1976
|
-
|
1977
|
-
|
1978
|
-
|
1979
|
-
|
1980
|
-
|
1981
|
-
|
1982
|
-
|
1983
|
-
|
1984
|
-
|
1985
|
-
|
1986
|
-
|
1987
|
-
|
1988
|
-
|
1989
|
-
|
1990
|
-
|
1991
|
-
|
1992
|
-
|
1993
|
-
|
1994
|
-
|
1995
|
-
|
1996
|
-
|
1997
|
-
|
1998
|
-
|
1999
|
-
|
2000
|
-
|
2001
|
-
|
2002
|
-
|
2003
|
-
|
2004
|
-
|
2005
|
-
|
2006
|
-
|
2007
|
-
|
2008
|
-
|
2009
|
-
|
2010
|
-
|
2011
|
-
|
2012
|
-
|
2013
|
-
|
2014
|
-
|
2015
|
-
|
2016
|
-
|
2017
|
-
|
2018
|
-
|
2019
|
-
|
2020
|
-
|
2021
|
-
|
2022
|
-
|
2023
|
-
|
2024
|
-
|
2025
|
-
|
2026
|
-
|
2027
|
-
|
2028
|
-
addAttributeToken(this, ATTRIBUTE_ERRORMESSAGE, e.message);
|
2029
|
-
});
|
1988
|
+
function show() {
|
1989
|
+
|
1990
|
+
if (this.getOption("disabled", undefined) === true) {
|
1991
|
+
return;
|
1992
|
+
}
|
1993
|
+
|
1994
|
+
if (this[popperElementSymbol].style.display === STYLE_DISPLAY_MODE_BLOCK) {
|
1995
|
+
return;
|
1996
|
+
}
|
1997
|
+
|
1998
|
+
focusFilter.call(this);
|
1999
|
+
|
2000
|
+
const lazyLoadFlag =
|
2001
|
+
this.getOption("features.lazyLoad") && this[lazyLoadDoneSymbol] !== true;
|
2002
|
+
|
2003
|
+
if (lazyLoadFlag === true) {
|
2004
|
+
this[lazyLoadDoneSymbol] = true;
|
2005
|
+
setStatusOrRemoveBadges.call(this, "loading");
|
2006
|
+
|
2007
|
+
new Processing(200, () => {
|
2008
|
+
this.fetch()
|
2009
|
+
.then(() => {
|
2010
|
+
setTimeout(() => {
|
2011
|
+
let result;
|
2012
|
+
if (this.hasAttribute("value")) {
|
2013
|
+
result = setSelection.call(this, this.getAttribute("value"));
|
2014
|
+
} else {
|
2015
|
+
result = setSelection.call(this, []);
|
2016
|
+
}
|
2017
|
+
|
2018
|
+
result
|
2019
|
+
.then(() => {
|
2020
|
+
show.call(this);
|
2021
|
+
})
|
2022
|
+
.catch((e) => {
|
2023
|
+
addAttributeToken(this, ATTRIBUTE_ERRORMESSAGE, `${e}`);
|
2024
|
+
});
|
2025
|
+
}, 100);
|
2026
|
+
})
|
2027
|
+
.catch((e) => {
|
2028
|
+
addAttributeToken(this, ATTRIBUTE_ERRORMESSAGE, e.message);
|
2029
|
+
setStatusOrRemoveBadges.call(this, "error");
|
2030
|
+
});
|
2031
|
+
})
|
2032
|
+
.run()
|
2033
|
+
.catch((e) => {
|
2034
|
+
addAttributeToken(this, ATTRIBUTE_ERRORMESSAGE, e.message);
|
2035
|
+
});
|
2036
|
+
|
2037
|
+
return;
|
2038
|
+
}
|
2039
|
+
|
2040
|
+
this[popperElementSymbol].style.visibility = "hidden";
|
2041
|
+
this[popperElementSymbol].style.display = STYLE_DISPLAY_MODE_BLOCK;
|
2042
|
+
setStatusOrRemoveBadges.call(this, "open");
|
2043
|
+
|
2044
|
+
addAttributeToken(this[controlElementSymbol], "class", "open");
|
2045
|
+
|
2046
|
+
new Processing(() => {
|
2047
|
+
calcAndSetOptionsDimension.call(this);
|
2048
|
+
focusFilter.call(this);
|
2049
|
+
this[popperElementSymbol].style.removeProperty("visibility");
|
2050
|
+
updatePopper.call(this);
|
2051
|
+
})
|
2052
|
+
.run()
|
2053
|
+
.catch((e) => {
|
2054
|
+
addAttributeToken(this, ATTRIBUTE_ERRORMESSAGE, e.message);
|
2055
|
+
});
|
2030
2056
|
}
|
2031
2057
|
|
2032
2058
|
/**
|
2033
2059
|
* @private
|
2034
2060
|
*/
|
2035
2061
|
function toggle() {
|
2036
|
-
|
2037
|
-
|
2038
|
-
|
2039
|
-
|
2040
|
-
|
2062
|
+
if (this[popperElementSymbol].style.display === STYLE_DISPLAY_MODE_BLOCK) {
|
2063
|
+
hide.call(this);
|
2064
|
+
} else {
|
2065
|
+
show.call(this);
|
2066
|
+
}
|
2041
2067
|
}
|
2042
2068
|
|
2043
2069
|
/**
|
@@ -2046,244 +2072,245 @@ function toggle() {
|
|
2046
2072
|
* @fires Monster.Components.Form.event:monster-selection-cleared
|
2047
2073
|
*/
|
2048
2074
|
function initEventHandler() {
|
2049
|
-
|
2050
|
-
|
2051
|
-
|
2052
|
-
|
2053
|
-
|
2054
|
-
|
2055
|
-
|
2056
|
-
|
2057
|
-
|
2058
|
-
|
2059
|
-
|
2060
|
-
|
2061
|
-
|
2062
|
-
|
2063
|
-
|
2064
|
-
|
2065
|
-
|
2066
|
-
|
2067
|
-
|
2068
|
-
|
2069
|
-
|
2070
|
-
|
2071
|
-
|
2072
|
-
|
2073
|
-
|
2074
|
-
|
2075
|
-
|
2076
|
-
|
2077
|
-
|
2078
|
-
|
2079
|
-
|
2080
|
-
|
2081
|
-
|
2082
|
-
|
2083
|
-
|
2084
|
-
|
2085
|
-
|
2086
|
-
|
2087
|
-
|
2088
|
-
|
2089
|
-
|
2090
|
-
|
2091
|
-
|
2092
|
-
|
2093
|
-
|
2094
|
-
|
2095
|
-
|
2096
|
-
|
2097
|
-
|
2098
|
-
|
2099
|
-
|
2100
|
-
|
2101
|
-
|
2102
|
-
|
2103
|
-
|
2104
|
-
|
2105
|
-
|
2106
|
-
|
2107
|
-
|
2108
|
-
|
2109
|
-
|
2110
|
-
|
2111
|
-
|
2112
|
-
|
2113
|
-
|
2114
|
-
|
2115
|
-
|
2116
|
-
|
2117
|
-
|
2118
|
-
|
2119
|
-
|
2120
|
-
|
2121
|
-
|
2122
|
-
|
2123
|
-
|
2124
|
-
|
2125
|
-
|
2126
|
-
|
2127
|
-
|
2128
|
-
|
2129
|
-
|
2130
|
-
|
2131
|
-
|
2132
|
-
|
2133
|
-
|
2134
|
-
|
2135
|
-
|
2136
|
-
|
2137
|
-
|
2138
|
-
|
2139
|
-
|
2140
|
-
|
2141
|
-
|
2142
|
-
|
2143
|
-
|
2144
|
-
|
2145
|
-
|
2146
|
-
|
2147
|
-
|
2148
|
-
|
2149
|
-
|
2150
|
-
|
2151
|
-
|
2152
|
-
|
2153
|
-
|
2154
|
-
|
2155
|
-
|
2156
|
-
|
2157
|
-
|
2158
|
-
|
2159
|
-
|
2160
|
-
|
2161
|
-
|
2162
|
-
|
2163
|
-
|
2164
|
-
|
2165
|
-
|
2166
|
-
|
2167
|
-
|
2168
|
-
|
2169
|
-
|
2170
|
-
|
2171
|
-
|
2172
|
-
|
2173
|
-
|
2174
|
-
|
2175
|
-
|
2176
|
-
|
2177
|
-
|
2178
|
-
|
2179
|
-
|
2180
|
-
|
2181
|
-
|
2182
|
-
|
2183
|
-
|
2184
|
-
|
2185
|
-
|
2186
|
-
|
2187
|
-
|
2188
|
-
|
2189
|
-
|
2190
|
-
|
2191
|
-
|
2192
|
-
|
2193
|
-
|
2194
|
-
|
2195
|
-
|
2196
|
-
|
2197
|
-
|
2198
|
-
|
2199
|
-
|
2200
|
-
|
2201
|
-
|
2202
|
-
|
2203
|
-
|
2204
|
-
|
2205
|
-
|
2206
|
-
|
2207
|
-
|
2208
|
-
|
2209
|
-
|
2210
|
-
|
2211
|
-
|
2212
|
-
|
2213
|
-
|
2214
|
-
|
2215
|
-
|
2216
|
-
|
2217
|
-
|
2218
|
-
|
2219
|
-
|
2220
|
-
|
2221
|
-
|
2222
|
-
|
2223
|
-
|
2224
|
-
|
2225
|
-
|
2226
|
-
|
2227
|
-
|
2228
|
-
|
2229
|
-
|
2230
|
-
|
2075
|
+
const self = this;
|
2076
|
+
|
2077
|
+
/**
|
2078
|
+
* @param {Event} event
|
2079
|
+
*/
|
2080
|
+
self[clearOptionEventHandler] = (event) => {
|
2081
|
+
const element = findTargetElementFromEvent(
|
2082
|
+
event,
|
2083
|
+
ATTRIBUTE_ROLE,
|
2084
|
+
"remove-badge",
|
2085
|
+
);
|
2086
|
+
|
2087
|
+
if (element instanceof HTMLElement) {
|
2088
|
+
const badge = findClosestByAttribute(element, ATTRIBUTE_ROLE, "badge");
|
2089
|
+
if (badge instanceof HTMLElement) {
|
2090
|
+
const value = badge.getAttribute(`${ATTRIBUTE_PREFIX}value`);
|
2091
|
+
|
2092
|
+
let selection = self.getOption("selection");
|
2093
|
+
selection = selection.filter((b) => {
|
2094
|
+
return value !== b.value;
|
2095
|
+
});
|
2096
|
+
|
2097
|
+
setSelection
|
2098
|
+
.call(self, selection)
|
2099
|
+
.then(() => {
|
2100
|
+
fireCustomEvent(self, "monster-selection-removed", {
|
2101
|
+
value,
|
2102
|
+
});
|
2103
|
+
})
|
2104
|
+
.catch((e) => {
|
2105
|
+
addAttributeToken(self, ATTRIBUTE_ERRORMESSAGE, e.message);
|
2106
|
+
});
|
2107
|
+
}
|
2108
|
+
}
|
2109
|
+
};
|
2110
|
+
|
2111
|
+
/**
|
2112
|
+
* @param {Event} event
|
2113
|
+
*/
|
2114
|
+
self[closeEventHandler] = (event) => {
|
2115
|
+
const path = event.composedPath();
|
2116
|
+
|
2117
|
+
for (const [, element] of Object.entries(path)) {
|
2118
|
+
if (element === self) {
|
2119
|
+
return;
|
2120
|
+
}
|
2121
|
+
}
|
2122
|
+
hide.call(self);
|
2123
|
+
};
|
2124
|
+
|
2125
|
+
/**
|
2126
|
+
* @param {Event} event
|
2127
|
+
*/
|
2128
|
+
self[inputEventHandler] = (event) => {
|
2129
|
+
const path = event.composedPath();
|
2130
|
+
const element = path?.[0];
|
2131
|
+
|
2132
|
+
if (element instanceof HTMLElement) {
|
2133
|
+
if (
|
2134
|
+
element.hasAttribute(ATTRIBUTE_ROLE) &&
|
2135
|
+
element.getAttribute(ATTRIBUTE_ROLE) === "option-control"
|
2136
|
+
) {
|
2137
|
+
fireCustomEvent(self, "monster-change", {
|
2138
|
+
type: event.type,
|
2139
|
+
value: element.value,
|
2140
|
+
checked: element.checked,
|
2141
|
+
});
|
2142
|
+
} else if (
|
2143
|
+
element.hasAttribute(ATTRIBUTE_ROLE) &&
|
2144
|
+
element.getAttribute(ATTRIBUTE_ROLE) === "filter"
|
2145
|
+
) {
|
2146
|
+
}
|
2147
|
+
}
|
2148
|
+
};
|
2149
|
+
|
2150
|
+
/**
|
2151
|
+
* @param {Event} event
|
2152
|
+
*/
|
2153
|
+
self[changeEventHandler] = (event) => {
|
2154
|
+
gatherState.call(self);
|
2155
|
+
fireCustomEvent(self, "monster-changed", event?.detail);
|
2156
|
+
};
|
2157
|
+
|
2158
|
+
self[keyEventHandler] = (event) => {
|
2159
|
+
const path = event.composedPath();
|
2160
|
+
const element = path.shift();
|
2161
|
+
|
2162
|
+
let role;
|
2163
|
+
|
2164
|
+
if (element instanceof HTMLElement) {
|
2165
|
+
if (element.hasAttribute(ATTRIBUTE_ROLE)) {
|
2166
|
+
role = element.getAttribute(ATTRIBUTE_ROLE);
|
2167
|
+
} else if (element === this) {
|
2168
|
+
show.call(this);
|
2169
|
+
// focusFilter.call(self);
|
2170
|
+
} else {
|
2171
|
+
const e = element.closest(`[${ATTRIBUTE_ROLE}]`);
|
2172
|
+
if (e instanceof HTMLElement && e.hasAttribute(ATTRIBUTE_ROLE)) {
|
2173
|
+
role = e.getAttribute(ATTRIBUTE_ROLE);
|
2174
|
+
}
|
2175
|
+
}
|
2176
|
+
} else {
|
2177
|
+
return;
|
2178
|
+
}
|
2179
|
+
|
2180
|
+
switch (role) {
|
2181
|
+
case "filter":
|
2182
|
+
handleFilterKeyboardEvents.call(self, event);
|
2183
|
+
break;
|
2184
|
+
case "option-label":
|
2185
|
+
case "option-control":
|
2186
|
+
case "option":
|
2187
|
+
handleOptionKeyboardEvents.call(self, event);
|
2188
|
+
break;
|
2189
|
+
case "control":
|
2190
|
+
case "toggle":
|
2191
|
+
handleToggleKeyboardEvents.call(self, event);
|
2192
|
+
break;
|
2193
|
+
}
|
2194
|
+
};
|
2195
|
+
|
2196
|
+
const types = self.getOption("toggleEventType", ["click"]);
|
2197
|
+
|
2198
|
+
for (const [, type] of Object.entries(types)) {
|
2199
|
+
self[controlElementSymbol]
|
2200
|
+
.querySelector(`[${ATTRIBUTE_ROLE}="container"]`)
|
2201
|
+
.addEventListener(type, function (event) {
|
2202
|
+
const element = findTargetElementFromEvent(
|
2203
|
+
event,
|
2204
|
+
ATTRIBUTE_ROLE,
|
2205
|
+
"remove-badge",
|
2206
|
+
);
|
2207
|
+
if (element instanceof HTMLElement) {
|
2208
|
+
return;
|
2209
|
+
}
|
2210
|
+
|
2211
|
+
toggle.call(self);
|
2212
|
+
});
|
2213
|
+
|
2214
|
+
self[controlElementSymbol]
|
2215
|
+
.querySelector(`[${ATTRIBUTE_ROLE}="status-or-remove-badges"]`)
|
2216
|
+
.addEventListener(type, function (event) {
|
2217
|
+
if (self.getOption("disabled", undefined) === true) {
|
2218
|
+
return;
|
2219
|
+
}
|
2220
|
+
|
2221
|
+
const path = event.composedPath();
|
2222
|
+
const element = path?.[0];
|
2223
|
+
if (element instanceof HTMLElement) {
|
2224
|
+
const control = element.closest(
|
2225
|
+
`[${ATTRIBUTE_ROLE}="status-or-remove-badges"]`,
|
2226
|
+
);
|
2227
|
+
if (control instanceof HTMLElement) {
|
2228
|
+
if (control.classList.contains("clear")) {
|
2229
|
+
clearSelection.call(self);
|
2230
|
+
|
2231
|
+
fireCustomEvent(self, "monster-selection-cleared", {});
|
2232
|
+
} else {
|
2233
|
+
const element = findTargetElementFromEvent(
|
2234
|
+
event,
|
2235
|
+
ATTRIBUTE_ROLE,
|
2236
|
+
"remove-badge",
|
2237
|
+
);
|
2238
|
+
if (element instanceof HTMLElement) {
|
2239
|
+
return;
|
2240
|
+
}
|
2241
|
+
|
2242
|
+
toggle.call(self);
|
2243
|
+
}
|
2244
|
+
}
|
2245
|
+
}
|
2246
|
+
});
|
2247
|
+
|
2248
|
+
// badge, selection
|
2249
|
+
self.addEventListener(type, self[clearOptionEventHandler]);
|
2250
|
+
}
|
2251
|
+
|
2252
|
+
self.addEventListener("monster-change", self[changeEventHandler]);
|
2253
|
+
self.addEventListener("input", self[inputEventHandler]);
|
2254
|
+
self.addEventListener("keydown", self[keyEventHandler]);
|
2255
|
+
|
2256
|
+
return self;
|
2231
2257
|
}
|
2232
2258
|
|
2233
2259
|
/**
|
2234
2260
|
* @private
|
2235
2261
|
* @return {Select}
|
2236
2262
|
*/
|
2237
|
-
function setStatusOrRemoveBadges(suggestion) {
|
2238
|
-
|
2239
|
-
|
2240
|
-
|
2241
|
-
|
2242
|
-
|
2243
|
-
|
2244
|
-
|
2245
|
-
|
2246
|
-
|
2247
|
-
|
2248
|
-
|
2249
|
-
|
2250
|
-
|
2251
|
-
|
2252
|
-
|
2253
|
-
|
2254
|
-
|
2255
|
-
|
2256
|
-
|
2257
|
-
|
2258
|
-
|
2259
|
-
|
2260
|
-
|
2261
|
-
|
2262
|
-
|
2263
|
-
|
2264
|
-
|
2265
|
-
|
2266
|
-
|
2267
|
-
|
2268
|
-
|
2269
|
-
|
2270
|
-
|
2271
|
-
|
2272
|
-
|
2273
|
-
|
2274
|
-
|
2275
|
-
|
2276
|
-
|
2277
|
-
|
2278
|
-
|
2279
|
-
|
2280
|
-
|
2281
|
-
|
2282
|
-
|
2283
|
-
|
2284
|
-
|
2285
|
-
|
2286
|
-
|
2263
|
+
function setStatusOrRemoveBadges(suggestion) {
|
2264
|
+
|
2265
|
+
setTimeout(() => {
|
2266
|
+
const selection = this.getOption("selection");
|
2267
|
+
const clearAllFlag =
|
2268
|
+
isArray(selection) &&
|
2269
|
+
selection.length > 0 &&
|
2270
|
+
this.getOption("features.clearAll") === true;
|
2271
|
+
|
2272
|
+
const current = this.getOption("classes.statusOrRemoveBadge");
|
2273
|
+
|
2274
|
+
if (clearAllFlag) {
|
2275
|
+
if (current !== "clear") {
|
2276
|
+
this.setOption("classes.statusOrRemoveBadge", "clear");
|
2277
|
+
}
|
2278
|
+
return;
|
2279
|
+
}
|
2280
|
+
|
2281
|
+
if (suggestion === "loading") {
|
2282
|
+
if (current !== "loading") {
|
2283
|
+
this.setOption("classes.statusOrRemoveBadge", "loading");
|
2284
|
+
}
|
2285
|
+
return;
|
2286
|
+
}
|
2287
|
+
|
2288
|
+
if (this[controlElementSymbol].classList.contains("open")) {
|
2289
|
+
if (current !== "open") {
|
2290
|
+
this.setOption("classes.statusOrRemoveBadge", "open");
|
2291
|
+
}
|
2292
|
+
return;
|
2293
|
+
}
|
2294
|
+
|
2295
|
+
const options = this.getOption("options");
|
2296
|
+
if (
|
2297
|
+
options === undefined ||
|
2298
|
+
options === null ||
|
2299
|
+
(isArray(options) && options.length === 0)
|
2300
|
+
) {
|
2301
|
+
if (current !== "empty") {
|
2302
|
+
this.setOption("classes.statusOrRemoveBadge", "empty");
|
2303
|
+
}
|
2304
|
+
return;
|
2305
|
+
}
|
2306
|
+
|
2307
|
+
if (suggestion) {
|
2308
|
+
if (current !== suggestion) {
|
2309
|
+
this.setOption("classes.statusOrRemoveBadge", suggestion);
|
2310
|
+
}
|
2311
|
+
return;
|
2312
|
+
}
|
2313
|
+
}, 2);
|
2287
2314
|
}
|
2288
2315
|
|
2289
2316
|
/**
|
@@ -2292,68 +2319,68 @@ function setStatusOrRemoveBadges(suggestion) {;
|
|
2292
2319
|
* @throws {Error} no shadow-root is defined
|
2293
2320
|
*/
|
2294
2321
|
function initControlReferences() {
|
2295
|
-
|
2296
|
-
|
2297
|
-
|
2298
|
-
|
2299
|
-
|
2300
|
-
|
2301
|
-
|
2302
|
-
|
2303
|
-
|
2304
|
-
|
2305
|
-
|
2306
|
-
|
2307
|
-
|
2308
|
-
|
2309
|
-
|
2310
|
-
|
2311
|
-
|
2312
|
-
|
2313
|
-
|
2314
|
-
|
2315
|
-
|
2316
|
-
|
2317
|
-
|
2318
|
-
|
2319
|
-
|
2320
|
-
|
2321
|
-
|
2322
|
-
|
2323
|
-
|
2324
|
-
|
2325
|
-
|
2326
|
-
|
2327
|
-
|
2322
|
+
if (!this.shadowRoot) {
|
2323
|
+
throw new Error("no shadow-root is defined");
|
2324
|
+
}
|
2325
|
+
|
2326
|
+
this[controlElementSymbol] = this.shadowRoot.querySelector(
|
2327
|
+
`[${ATTRIBUTE_ROLE}=control]`,
|
2328
|
+
);
|
2329
|
+
this[selectionElementSymbol] = this.shadowRoot.querySelector(
|
2330
|
+
`[${ATTRIBUTE_ROLE}=selection]`,
|
2331
|
+
);
|
2332
|
+
this[containerElementSymbol] = this.shadowRoot.querySelector(
|
2333
|
+
`[${ATTRIBUTE_ROLE}=container]`,
|
2334
|
+
);
|
2335
|
+
this[popperElementSymbol] = this.shadowRoot.querySelector(
|
2336
|
+
`[${ATTRIBUTE_ROLE}=popper]`,
|
2337
|
+
);
|
2338
|
+
this[inlineFilterElementSymbol] = this.shadowRoot.querySelector(
|
2339
|
+
`[${ATTRIBUTE_ROLE}=filter][name="inline-filter"]`,
|
2340
|
+
);
|
2341
|
+
this[popperFilterElementSymbol] = this.shadowRoot.querySelector(
|
2342
|
+
`[${ATTRIBUTE_ROLE}=filter][name="popper-filter"]`,
|
2343
|
+
);
|
2344
|
+
this[popperFilterContainerElementSymbol] =
|
2345
|
+
this[popperFilterElementSymbol].parentElement;
|
2346
|
+
this[optionsElementSymbol] = this.shadowRoot.querySelector(
|
2347
|
+
`[${ATTRIBUTE_ROLE}=options]`,
|
2348
|
+
);
|
2349
|
+
this[noOptionsAvailableElementSymbol] = this.shadowRoot.querySelector(
|
2350
|
+
`[${ATTRIBUTE_ROLE}="no-options"]`,
|
2351
|
+
);
|
2352
|
+
this[statusOrRemoveBadgesElementSymbol] = this.shadowRoot.querySelector(
|
2353
|
+
`[${ATTRIBUTE_ROLE}=status-or-remove-badges]`,
|
2354
|
+
);
|
2328
2355
|
}
|
2329
2356
|
|
2330
2357
|
/**
|
2331
2358
|
* @private
|
2332
2359
|
*/
|
2333
2360
|
function updatePopper() {
|
2334
|
-
|
2335
|
-
|
2336
|
-
|
2337
|
-
|
2338
|
-
|
2339
|
-
|
2340
|
-
|
2341
|
-
|
2342
|
-
|
2343
|
-
|
2344
|
-
|
2345
|
-
|
2346
|
-
|
2347
|
-
|
2348
|
-
|
2349
|
-
|
2350
|
-
|
2351
|
-
|
2352
|
-
|
2353
|
-
|
2354
|
-
|
2355
|
-
|
2356
|
-
|
2361
|
+
if (this[popperElementSymbol].style.display !== STYLE_DISPLAY_MODE_BLOCK) {
|
2362
|
+
return;
|
2363
|
+
}
|
2364
|
+
|
2365
|
+
if (this.getOption("disabled", false) === true) {
|
2366
|
+
return;
|
2367
|
+
}
|
2368
|
+
|
2369
|
+
new Processing(() => {
|
2370
|
+
calcAndSetOptionsDimension.call(this);
|
2371
|
+
positionPopper.call(
|
2372
|
+
this,
|
2373
|
+
this[controlElementSymbol],
|
2374
|
+
this[popperElementSymbol],
|
2375
|
+
this.getOption("popper", {}),
|
2376
|
+
);
|
2377
|
+
})
|
2378
|
+
.run()
|
2379
|
+
.catch((e) => {
|
2380
|
+
addAttributeToken(this, ATTRIBUTE_ERRORMESSAGE, e.message);
|
2381
|
+
});
|
2382
|
+
|
2383
|
+
return this;
|
2357
2384
|
}
|
2358
2385
|
|
2359
2386
|
/**
|
@@ -2361,8 +2388,8 @@ function updatePopper() {
|
|
2361
2388
|
* @return {string}
|
2362
2389
|
*/
|
2363
2390
|
function getTemplate() {
|
2364
|
-
|
2365
|
-
|
2391
|
+
// language=HTML
|
2392
|
+
return `
|
2366
2393
|
<template id="options">
|
2367
2394
|
<div data-monster-role="option" tabindex="-1"
|
2368
2395
|
data-monster-attributes="
|
@@ -2378,7 +2405,8 @@ function getTemplate() {
|
|
2378
2405
|
part path:type | prefix:option- | suffix: form,
|
2379
2406
|
class path:options.class
|
2380
2407
|
" tabindex="-1">
|
2381
|
-
<div data-monster-replace="path:options | index:label"
|
2408
|
+
<div data-monster-replace="path:options | index:label"
|
2409
|
+
part="option-label"></div>
|
2382
2410
|
</label>
|
2383
2411
|
</div>
|
2384
2412
|
</template>
|