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