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