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