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