@limetech/lime-elements 40.4.1 → 40.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +18 -0
- package/dist/cjs/component-UyqdiWGc.js +1576 -0
- package/dist/cjs/lime-elements.cjs.js +1 -1
- package/dist/cjs/limel-action-bar_3.cjs.entry.js +1 -1
- package/dist/cjs/limel-ai-avatar.cjs.entry.js +1 -1
- package/dist/cjs/{limel-breadcrumbs_8.cjs.entry.js → limel-breadcrumbs_6.cjs.entry.js} +221 -2175
- package/dist/cjs/limel-callout.cjs.entry.js +1 -1
- package/dist/cjs/limel-chart.cjs.entry.js +1 -1
- package/dist/cjs/limel-chip-set.cjs.entry.js +1 -1
- package/dist/cjs/limel-chip_2.cjs.entry.js +1 -1
- package/dist/cjs/limel-code-diff.cjs.entry.js +1 -1
- package/dist/cjs/limel-code-editor.cjs.entry.js +1 -1
- package/dist/cjs/limel-collapsible-section.cjs.entry.js +1 -1
- package/dist/cjs/limel-drag-handle.cjs.entry.js +1 -1
- package/dist/cjs/limel-email-viewer.cjs.entry.js +1 -1
- package/dist/cjs/limel-file-viewer.cjs.entry.js +1 -1
- package/dist/cjs/limel-file.cjs.entry.js +1 -1
- package/dist/cjs/limel-flatpickr-adapter.cjs.entry.js +1 -1
- package/dist/cjs/limel-helper-line_3.cjs.entry.js +454 -0
- package/dist/cjs/limel-list-item.cjs.entry.js +1 -1
- package/dist/cjs/limel-pagination-jump.cjs.entry.js +182 -0
- package/dist/cjs/limel-pagination.cjs.entry.js +165 -126
- package/dist/cjs/limel-picker.cjs.entry.js +1 -1
- package/dist/cjs/limel-popover_2.cjs.entry.js +33 -25
- package/dist/cjs/limel-profile-picture.cjs.entry.js +1 -1
- package/dist/cjs/limel-prosemirror-adapter.cjs.entry.js +1 -1
- package/dist/cjs/limel-slider.cjs.entry.js +1 -1
- package/dist/cjs/limel-snackbar.cjs.entry.js +1 -1
- package/dist/cjs/limel-table.cjs.entry.js +1 -1
- package/dist/cjs/limel-text-editor-link-menu.cjs.entry.js +1 -1
- package/dist/cjs/loader.cjs.js +1 -1
- package/dist/cjs/pagination.util-B5zzH8vg.js +135 -0
- package/dist/cjs/{translations-C5T2-_rH.js → translations-DFFpR6AZ.js} +32 -0
- package/dist/collection/collection-manifest.json +1 -0
- package/dist/collection/components/menu/menu.js +44 -22
- package/dist/collection/components/pagination/jump/pagination-jump.css +11 -0
- package/dist/collection/components/pagination/jump/pagination-jump.js +331 -0
- package/dist/collection/components/pagination/pagination.css +8 -4
- package/dist/collection/components/pagination/pagination.js +167 -10
- package/dist/collection/components/pagination/pagination.util.js +25 -8
- package/dist/collection/components/popover/popover.js +33 -25
- package/dist/collection/translations/da.js +4 -0
- package/dist/collection/translations/de.js +4 -0
- package/dist/collection/translations/en.js +4 -0
- package/dist/collection/translations/fi.js +4 -0
- package/dist/collection/translations/fr.js +4 -0
- package/dist/collection/translations/nl.js +4 -0
- package/dist/collection/translations/no.js +4 -0
- package/dist/collection/translations/sv.js +4 -0
- package/dist/esm/component-B2Vy44Z3.js +1570 -0
- package/dist/esm/lime-elements.js +1 -1
- package/dist/esm/limel-action-bar_3.entry.js +1 -1
- package/dist/esm/limel-ai-avatar.entry.js +1 -1
- package/dist/esm/{limel-breadcrumbs_8.entry.js → limel-breadcrumbs_6.entry.js} +47 -1999
- package/dist/esm/limel-callout.entry.js +1 -1
- package/dist/esm/limel-chart.entry.js +1 -1
- package/dist/esm/limel-chip-set.entry.js +1 -1
- package/dist/esm/limel-chip_2.entry.js +1 -1
- package/dist/esm/limel-code-diff.entry.js +1 -1
- package/dist/esm/limel-code-editor.entry.js +1 -1
- package/dist/esm/limel-collapsible-section.entry.js +1 -1
- package/dist/esm/limel-drag-handle.entry.js +1 -1
- package/dist/esm/limel-email-viewer.entry.js +1 -1
- package/dist/esm/limel-file-viewer.entry.js +1 -1
- package/dist/esm/limel-file.entry.js +1 -1
- package/dist/esm/limel-flatpickr-adapter.entry.js +1 -1
- package/dist/esm/limel-helper-line_3.entry.js +450 -0
- package/dist/esm/limel-list-item.entry.js +1 -1
- package/dist/esm/limel-pagination-jump.entry.js +180 -0
- package/dist/esm/limel-pagination.entry.js +165 -126
- package/dist/esm/limel-picker.entry.js +1 -1
- package/dist/esm/limel-popover_2.entry.js +33 -25
- package/dist/esm/limel-profile-picture.entry.js +1 -1
- package/dist/esm/limel-prosemirror-adapter.entry.js +1 -1
- package/dist/esm/limel-slider.entry.js +1 -1
- package/dist/esm/limel-snackbar.entry.js +1 -1
- package/dist/esm/limel-table.entry.js +1 -1
- package/dist/esm/limel-text-editor-link-menu.entry.js +1 -1
- package/dist/esm/loader.js +1 -1
- package/dist/esm/pagination.util-CSC2LJ7P.js +132 -0
- package/dist/esm/{translations-Bwm2y2E4.js → translations-DMtX4tTX.js} +32 -0
- package/dist/lime-elements/lime-elements.esm.js +1 -1
- package/dist/lime-elements/{p-2bbdac10.entry.js → p-11a96a8c.entry.js} +1 -1
- package/dist/lime-elements/p-1dd86ad4.entry.js +1 -0
- package/dist/lime-elements/p-1e93473a.entry.js +1 -0
- package/dist/lime-elements/{p-a41b5ff3.entry.js → p-2e568c56.entry.js} +1 -1
- package/dist/lime-elements/{p-de631fc3.entry.js → p-2f57c3fa.entry.js} +1 -1
- package/dist/lime-elements/p-3735111e.entry.js +1 -0
- package/dist/lime-elements/{p-c823054d.entry.js → p-452b9b01.entry.js} +1 -1
- package/dist/lime-elements/{p-f333f12d.entry.js → p-4855dc9b.entry.js} +1 -1
- package/dist/lime-elements/{p-a462aeb7.entry.js → p-4902fb3f.entry.js} +1 -1
- package/dist/lime-elements/p-507cc8a1.entry.js +159 -0
- package/dist/lime-elements/{p-dadd2e17.entry.js → p-531b6a64.entry.js} +1 -1
- package/dist/lime-elements/{p-b194a212.entry.js → p-5698e493.entry.js} +1 -1
- package/dist/lime-elements/{p-65a9adfc.entry.js → p-67f02b69.entry.js} +1 -1
- package/dist/lime-elements/{p-1162dd39.entry.js → p-867681aa.entry.js} +1 -1
- package/dist/lime-elements/{p-f72ee01b.entry.js → p-90df3e1b.entry.js} +1 -1
- package/dist/lime-elements/{p-22f85b99.entry.js → p-955292eb.entry.js} +1 -1
- package/dist/lime-elements/{p-c2ff132c.entry.js → p-9b631363.entry.js} +1 -1
- package/dist/lime-elements/{p-8af3e4a1.entry.js → p-9d3437ac.entry.js} +1 -1
- package/dist/lime-elements/p-B8hoCfhT.js +1 -0
- package/dist/lime-elements/p-BwJGg-WI.js +89 -0
- package/dist/lime-elements/p-CSC2LJ7P.js +1 -0
- package/dist/lime-elements/p-a1de9bbe.entry.js +1 -0
- package/dist/lime-elements/{p-b5484494.entry.js → p-acba5700.entry.js} +1 -1
- package/dist/lime-elements/{p-f6361b03.entry.js → p-b8c76487.entry.js} +1 -1
- package/dist/lime-elements/{p-ac9c5c88.entry.js → p-cafec335.entry.js} +1 -1
- package/dist/lime-elements/{p-48928b4f.entry.js → p-d146feda.entry.js} +1 -1
- package/dist/lime-elements/{p-532ea234.entry.js → p-deceda00.entry.js} +1 -1
- package/dist/lime-elements/{p-e508771f.entry.js → p-f04f7c8e.entry.js} +1 -1
- package/dist/lime-elements/{p-51dc5f0b.entry.js → p-f3c108c9.entry.js} +1 -1
- package/dist/lime-elements/{p-24041bbb.entry.js → p-fbcd99a3.entry.js} +1 -1
- package/dist/types/components/menu/menu.d.ts +11 -0
- package/dist/types/components/pagination/jump/pagination-jump.d.ts +102 -0
- package/dist/types/components/pagination/pagination.d.ts +81 -0
- package/dist/types/components/pagination/pagination.util.d.ts +12 -2
- package/dist/types/components/popover/popover.d.ts +8 -1
- package/dist/types/components.d.ts +145 -0
- package/dist/types/translations/da.d.ts +4 -0
- package/dist/types/translations/de.d.ts +4 -0
- package/dist/types/translations/en.d.ts +4 -0
- package/dist/types/translations/fi.d.ts +4 -0
- package/dist/types/translations/fr.d.ts +4 -0
- package/dist/types/translations/nl.d.ts +4 -0
- package/dist/types/translations/no.d.ts +4 -0
- package/dist/types/translations/sv.d.ts +4 -0
- package/package.json +1 -1
- package/dist/cjs/limel-helper-line.cjs.entry.js +0 -42
- package/dist/esm/limel-helper-line.entry.js +0 -40
- package/dist/lime-elements/p-1a478498.entry.js +0 -248
- package/dist/lime-elements/p-4c65dee7.entry.js +0 -1
- package/dist/lime-elements/p-DAFuhe5e.js +0 -1
- package/dist/lime-elements/p-b4988a9b.entry.js +0 -1
- package/dist/lime-elements/p-f81dc23a.entry.js +0 -1
|
@@ -9,11 +9,12 @@ var linkHelper = require('./link-helper-DwlfFJVL.js');
|
|
|
9
9
|
var config = require('./config-dit--4m5.js');
|
|
10
10
|
var debounce = require('./debounce-DgDnRSlt.js');
|
|
11
11
|
var component = require('./component-CFk7Dfoi.js');
|
|
12
|
-
var ponyfill = require('./ponyfill-BgIFyUG5.js');
|
|
13
12
|
var focusTriggerElement = require('./focus-trigger-element-BfnJmxKO.js');
|
|
14
13
|
var hotkeys = require('./hotkeys-BtR8uxvl.js');
|
|
15
14
|
var isFunction = require('./isFunction-RSHwsz1x.js');
|
|
16
|
-
var
|
|
15
|
+
var ponyfill = require('./ponyfill-BgIFyUG5.js');
|
|
16
|
+
var component$1 = require('./component-UyqdiWGc.js');
|
|
17
|
+
var component$2 = require('./component-y8swlNNR.js');
|
|
17
18
|
var dom = require('./dom-BWMDM6En.js');
|
|
18
19
|
require('./isObject-B6Osvvqp.js');
|
|
19
20
|
require('./toNumber-v-1DEwWD.js');
|
|
@@ -526,2112 +527,201 @@ const InputField = class {
|
|
|
526
527
|
this.handleCloseMenu = () => {
|
|
527
528
|
this.showCompletions = false;
|
|
528
529
|
};
|
|
529
|
-
this.filterCompletions = (filter) => {
|
|
530
|
-
if (!filter) {
|
|
531
|
-
return this.completionsList;
|
|
532
|
-
}
|
|
533
|
-
return this.completionsList.filter((completion) => completion.text.toLowerCase().includes(filter.toLowerCase()));
|
|
534
|
-
};
|
|
535
|
-
this.handleInput = (event) => {
|
|
536
|
-
event.stopPropagation();
|
|
537
|
-
let value = event.target.value;
|
|
538
|
-
if (this.type === 'number') {
|
|
539
|
-
if (!value && event.data) {
|
|
540
|
-
event.stopPropagation();
|
|
541
|
-
return;
|
|
542
|
-
}
|
|
543
|
-
if (value) {
|
|
544
|
-
value = Number(value);
|
|
545
|
-
}
|
|
546
|
-
}
|
|
547
|
-
this.changeWaiting = true;
|
|
548
|
-
this.changeEmitter(value);
|
|
549
|
-
};
|
|
550
|
-
this.changeEmitter = debounce.debounce((value) => {
|
|
551
|
-
this.change.emit(value);
|
|
552
|
-
this.changeWaiting = false;
|
|
553
|
-
}, CHANGE_EVENT_DEBOUNCE_TIMEOUT);
|
|
554
|
-
this.handleChange = (event) => {
|
|
555
|
-
event.stopPropagation();
|
|
556
|
-
this.changeEmitter.flush();
|
|
557
|
-
};
|
|
558
|
-
this.handleIconClick = () => {
|
|
559
|
-
this.action.emit();
|
|
560
|
-
};
|
|
561
|
-
this.handleIconKeyPress = (event) => {
|
|
562
|
-
const isEnter = event.key === keycodes.ENTER;
|
|
563
|
-
const isSpace = event.key === keycodes.SPACE;
|
|
564
|
-
if (isSpace || isEnter) {
|
|
565
|
-
this.action.emit();
|
|
566
|
-
}
|
|
567
|
-
};
|
|
568
|
-
this.handleWheel = () => {
|
|
569
|
-
// This empty event handler is here to circumvent a bug.
|
|
570
|
-
// In some browsers (Chrome for example), hovering the input with
|
|
571
|
-
// the input focused, and scrolling, will both change the value
|
|
572
|
-
// AND scroll the page. We would prefer to never change the value
|
|
573
|
-
// on scroll, instead always scrolling the page, but since we
|
|
574
|
-
// haven't found a way to do that, this is the next best thing, as
|
|
575
|
-
// it prevents the page from being scrolled, but only in the
|
|
576
|
-
// circumstances when the value is changed by the scrolling.
|
|
577
|
-
// Please test THOROUGHLY if you remove this event handler 😄
|
|
578
|
-
};
|
|
579
|
-
this.portalId = randomString.createRandomString();
|
|
580
|
-
this.helperTextId = randomString.createRandomString();
|
|
581
|
-
this.labelId = randomString.createRandomString();
|
|
582
|
-
}
|
|
583
|
-
connectedCallback() {
|
|
584
|
-
this.initialize();
|
|
585
|
-
}
|
|
586
|
-
componentDidLoad() {
|
|
587
|
-
this.initialize();
|
|
588
|
-
}
|
|
589
|
-
disconnectedCallback() {
|
|
590
|
-
if (this.mdcTextField) {
|
|
591
|
-
this.mdcTextField.destroy();
|
|
592
|
-
}
|
|
593
|
-
this.restyleCompletionsDropDown.cancel();
|
|
594
|
-
window.removeEventListener('resize', this.layout);
|
|
595
|
-
this.limelInputField.removeEventListener('focus', this.setFocus);
|
|
596
|
-
}
|
|
597
|
-
componentDidUpdate() {
|
|
598
|
-
if (this.invalid) {
|
|
599
|
-
this.mdcTextField.valid = false;
|
|
600
|
-
}
|
|
601
|
-
else if (!this.wasInvalid) {
|
|
602
|
-
// Reset MDC's internal validity once the consumer no longer
|
|
603
|
-
// considers the field invalid and our own check hasn't
|
|
604
|
-
// flagged it either.
|
|
605
|
-
this.mdcTextField.valid = true;
|
|
606
|
-
}
|
|
607
|
-
this.mdcTextField.disabled = this.disabled || this.readonly;
|
|
608
|
-
}
|
|
609
|
-
/**
|
|
610
|
-
* Returns the start position of the current text selection.
|
|
611
|
-
* Returns `null` if the input element is not available or if
|
|
612
|
-
* the input type does not support selection (e.g., `number`).
|
|
613
|
-
*/
|
|
614
|
-
async getSelectionStart() {
|
|
615
|
-
var _a, _b;
|
|
616
|
-
try {
|
|
617
|
-
return (_b = (_a = this.inputElement) === null || _a === void 0 ? void 0 : _a.selectionStart) !== null && _b !== void 0 ? _b : null;
|
|
618
|
-
}
|
|
619
|
-
catch (_c) {
|
|
620
|
-
// Some input types (e.g., number) throw InvalidStateError
|
|
621
|
-
return null;
|
|
622
|
-
}
|
|
623
|
-
}
|
|
624
|
-
/**
|
|
625
|
-
* Returns the end position of the current text selection.
|
|
626
|
-
* Returns `null` if the input element is not available or if
|
|
627
|
-
* the input type does not support selection (e.g., `number`).
|
|
628
|
-
*/
|
|
629
|
-
async getSelectionEnd() {
|
|
630
|
-
var _a, _b;
|
|
631
|
-
try {
|
|
632
|
-
return (_b = (_a = this.inputElement) === null || _a === void 0 ? void 0 : _a.selectionEnd) !== null && _b !== void 0 ? _b : null;
|
|
633
|
-
}
|
|
634
|
-
catch (_c) {
|
|
635
|
-
// Some input types (e.g., number) throw InvalidStateError
|
|
636
|
-
return null;
|
|
637
|
-
}
|
|
638
|
-
}
|
|
639
|
-
/**
|
|
640
|
-
* Returns the direction of the current text selection.
|
|
641
|
-
* Can be `'forward'`, `'backward'`, or `'none'`.
|
|
642
|
-
* Returns `null` if the input element is not available or if
|
|
643
|
-
* the input type does not support selection (e.g., `number`).
|
|
644
|
-
*/
|
|
645
|
-
async getSelectionDirection() {
|
|
646
|
-
var _a, _b;
|
|
647
|
-
try {
|
|
648
|
-
return (_b = (_a = this.inputElement) === null || _a === void 0 ? void 0 : _a.selectionDirection) !== null && _b !== void 0 ? _b : null;
|
|
649
|
-
}
|
|
650
|
-
catch (_c) {
|
|
651
|
-
// Some input types (e.g., number) throw InvalidStateError
|
|
652
|
-
return null;
|
|
653
|
-
}
|
|
654
|
-
}
|
|
655
|
-
render() {
|
|
656
|
-
const properties = this.getAdditionalProps();
|
|
657
|
-
properties['aria-labelledby'] = this.labelId;
|
|
658
|
-
properties.class = 'mdc-text-field__input';
|
|
659
|
-
properties.ref = this.setInputElement;
|
|
660
|
-
properties.onInput = this.handleInput;
|
|
661
|
-
properties.onChange = this.handleChange;
|
|
662
|
-
properties.onFocus = this.onFocus;
|
|
663
|
-
properties.onBlur = this.onBlur;
|
|
664
|
-
properties.required = this.required;
|
|
665
|
-
properties.readonly = this.readonly;
|
|
666
|
-
properties.disabled = this.disabled || this.readonly;
|
|
667
|
-
let ariaControls = '';
|
|
668
|
-
if (this.hasHelperText()) {
|
|
669
|
-
ariaControls += this.helperTextId;
|
|
670
|
-
properties['aria-describedby'] = this.helperTextId;
|
|
671
|
-
}
|
|
672
|
-
if (this.renderAutocompleteList()) {
|
|
673
|
-
if (ariaControls) {
|
|
674
|
-
ariaControls += ' ';
|
|
675
|
-
}
|
|
676
|
-
ariaControls += this.portalId;
|
|
677
|
-
}
|
|
678
|
-
if (ariaControls) {
|
|
679
|
-
properties['aria-controls'] = ariaControls;
|
|
680
|
-
}
|
|
681
|
-
return (index.h(index.Host, { key: '9e509e181e05f451deadc92e052dc11075032f9a' }, index.h("limel-notched-outline", { key: '2f2307e2c7d96eec0c5753d27bf1fc76c9ad8eb2', labelId: this.labelId, label: this.label, required: this.required, invalid: this.invalid || this.isInvalid(), disabled: this.disabled, readonly: this.readonly, hasValue: !!this.value, hasLeadingIcon: !!this.leadingIcon }, index.h("label", { key: 'a21372b10d416423aea6ff9f318bf12ef8d4832a', slot: "content", class: this.getContainerClassList() }, this.renderLeadingIcon(), this.renderPrefix(), this.renderFormattedNumber(), this.renderInput(properties), this.renderSuffix(), this.renderTextarea(properties), this.renderTrailingLinkOrButton())), this.renderHelperLine(), this.renderAutocompleteList()));
|
|
682
|
-
}
|
|
683
|
-
valueWatcher(newValue) {
|
|
684
|
-
if (!this.mdcTextField) {
|
|
685
|
-
return;
|
|
686
|
-
}
|
|
687
|
-
if (this.changeWaiting) {
|
|
688
|
-
return;
|
|
689
|
-
}
|
|
690
|
-
if (this.type === 'number' &&
|
|
691
|
-
this.isFocused &&
|
|
692
|
-
Number(newValue) === Number(this.mdcTextField.value)) {
|
|
693
|
-
return;
|
|
694
|
-
}
|
|
695
|
-
if (newValue !== this.mdcTextField.value) {
|
|
696
|
-
this.mdcTextField.value = newValue || '';
|
|
697
|
-
}
|
|
698
|
-
if (this.wasInvalid) {
|
|
699
|
-
this.validate();
|
|
700
|
-
}
|
|
701
|
-
}
|
|
702
|
-
completionsWatcher() {
|
|
703
|
-
this.mapCompletions();
|
|
704
|
-
}
|
|
705
|
-
get validationMessage() {
|
|
706
|
-
var _a;
|
|
707
|
-
if (this.isInvalid() && !this.invalid) {
|
|
708
|
-
return ((_a = this.inputElement) === null || _a === void 0 ? void 0 : _a.validationMessage) || '';
|
|
709
|
-
}
|
|
710
|
-
return '';
|
|
711
|
-
}
|
|
712
|
-
static get delegatesFocus() { return true; }
|
|
713
|
-
get limelInputField() { return index.getElement(this); }
|
|
714
|
-
static get watchers() { return {
|
|
715
|
-
"value": [{
|
|
716
|
-
"valueWatcher": 0
|
|
717
|
-
}],
|
|
718
|
-
"completions": [{
|
|
719
|
-
"completionsWatcher": 0
|
|
720
|
-
}]
|
|
721
|
-
}; }
|
|
722
|
-
};
|
|
723
|
-
InputField.style = inputFieldCss();
|
|
724
|
-
|
|
725
|
-
/**
|
|
726
|
-
* @license
|
|
727
|
-
* Copyright 2018 Google Inc.
|
|
728
|
-
*
|
|
729
|
-
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
730
|
-
* of this software and associated documentation files (the "Software"), to deal
|
|
731
|
-
* in the Software without restriction, including without limitation the rights
|
|
732
|
-
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
733
|
-
* copies of the Software, and to permit persons to whom the Software is
|
|
734
|
-
* furnished to do so, subject to the following conditions:
|
|
735
|
-
*
|
|
736
|
-
* The above copyright notice and this permission notice shall be included in
|
|
737
|
-
* all copies or substantial portions of the Software.
|
|
738
|
-
*
|
|
739
|
-
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
740
|
-
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
741
|
-
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
742
|
-
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
743
|
-
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
744
|
-
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
745
|
-
* THE SOFTWARE.
|
|
746
|
-
*/
|
|
747
|
-
var _a, _b;
|
|
748
|
-
var cssClasses$2 = {
|
|
749
|
-
LIST_ITEM_ACTIVATED_CLASS: 'mdc-list-item--activated',
|
|
750
|
-
LIST_ITEM_CLASS: 'mdc-list-item',
|
|
751
|
-
LIST_ITEM_DISABLED_CLASS: 'mdc-list-item--disabled',
|
|
752
|
-
LIST_ITEM_SELECTED_CLASS: 'mdc-list-item--selected',
|
|
753
|
-
LIST_ITEM_TEXT_CLASS: 'mdc-list-item__text',
|
|
754
|
-
LIST_ITEM_PRIMARY_TEXT_CLASS: 'mdc-list-item__primary-text',
|
|
755
|
-
ROOT: 'mdc-list',
|
|
756
|
-
};
|
|
757
|
-
var evolutionClassNameMap = (_a = {},
|
|
758
|
-
_a["" + cssClasses$2.LIST_ITEM_ACTIVATED_CLASS] = 'mdc-list-item--activated',
|
|
759
|
-
_a["" + cssClasses$2.LIST_ITEM_CLASS] = 'mdc-list-item',
|
|
760
|
-
_a["" + cssClasses$2.LIST_ITEM_DISABLED_CLASS] = 'mdc-list-item--disabled',
|
|
761
|
-
_a["" + cssClasses$2.LIST_ITEM_SELECTED_CLASS] = 'mdc-list-item--selected',
|
|
762
|
-
_a["" + cssClasses$2.LIST_ITEM_PRIMARY_TEXT_CLASS] = 'mdc-list-item__primary-text',
|
|
763
|
-
_a["" + cssClasses$2.ROOT] = 'mdc-list',
|
|
764
|
-
_a);
|
|
765
|
-
var deprecatedClassNameMap = (_b = {},
|
|
766
|
-
_b["" + cssClasses$2.LIST_ITEM_ACTIVATED_CLASS] = 'mdc-deprecated-list-item--activated',
|
|
767
|
-
_b["" + cssClasses$2.LIST_ITEM_CLASS] = 'mdc-deprecated-list-item',
|
|
768
|
-
_b["" + cssClasses$2.LIST_ITEM_DISABLED_CLASS] = 'mdc-deprecated-list-item--disabled',
|
|
769
|
-
_b["" + cssClasses$2.LIST_ITEM_SELECTED_CLASS] = 'mdc-deprecated-list-item--selected',
|
|
770
|
-
_b["" + cssClasses$2.LIST_ITEM_TEXT_CLASS] = 'mdc-deprecated-list-item__text',
|
|
771
|
-
_b["" + cssClasses$2.LIST_ITEM_PRIMARY_TEXT_CLASS] = 'mdc-deprecated-list-item__primary-text',
|
|
772
|
-
_b["" + cssClasses$2.ROOT] = 'mdc-deprecated-list',
|
|
773
|
-
_b);
|
|
774
|
-
var strings$2 = {
|
|
775
|
-
ACTION_EVENT: 'MDCList:action',
|
|
776
|
-
ARIA_CHECKED: 'aria-checked',
|
|
777
|
-
ARIA_CHECKED_CHECKBOX_SELECTOR: '[role="checkbox"][aria-checked="true"]',
|
|
778
|
-
ARIA_CHECKED_RADIO_SELECTOR: '[role="radio"][aria-checked="true"]',
|
|
779
|
-
ARIA_CURRENT: 'aria-current',
|
|
780
|
-
ARIA_DISABLED: 'aria-disabled',
|
|
781
|
-
ARIA_ORIENTATION: 'aria-orientation',
|
|
782
|
-
ARIA_ORIENTATION_HORIZONTAL: 'horizontal',
|
|
783
|
-
ARIA_ROLE_CHECKBOX_SELECTOR: '[role="checkbox"]',
|
|
784
|
-
ARIA_SELECTED: 'aria-selected',
|
|
785
|
-
ARIA_INTERACTIVE_ROLES_SELECTOR: '[role="listbox"], [role="menu"]',
|
|
786
|
-
ARIA_MULTI_SELECTABLE_SELECTOR: '[aria-multiselectable="true"]',
|
|
787
|
-
CHECKBOX_RADIO_SELECTOR: 'input[type="checkbox"], input[type="radio"]',
|
|
788
|
-
CHECKBOX_SELECTOR: 'input[type="checkbox"]',
|
|
789
|
-
CHILD_ELEMENTS_TO_TOGGLE_TABINDEX: "\n ." + cssClasses$2.LIST_ITEM_CLASS + " button:not(:disabled),\n ." + cssClasses$2.LIST_ITEM_CLASS + " a,\n ." + deprecatedClassNameMap[cssClasses$2.LIST_ITEM_CLASS] + " button:not(:disabled),\n ." + deprecatedClassNameMap[cssClasses$2.LIST_ITEM_CLASS] + " a\n ",
|
|
790
|
-
DEPRECATED_SELECTOR: '.mdc-deprecated-list',
|
|
791
|
-
FOCUSABLE_CHILD_ELEMENTS: "\n ." + cssClasses$2.LIST_ITEM_CLASS + " button:not(:disabled),\n ." + cssClasses$2.LIST_ITEM_CLASS + " a,\n ." + cssClasses$2.LIST_ITEM_CLASS + " input[type=\"radio\"]:not(:disabled),\n ." + cssClasses$2.LIST_ITEM_CLASS + " input[type=\"checkbox\"]:not(:disabled),\n ." + deprecatedClassNameMap[cssClasses$2.LIST_ITEM_CLASS] + " button:not(:disabled),\n ." + deprecatedClassNameMap[cssClasses$2.LIST_ITEM_CLASS] + " a,\n ." + deprecatedClassNameMap[cssClasses$2.LIST_ITEM_CLASS] + " input[type=\"radio\"]:not(:disabled),\n ." + deprecatedClassNameMap[cssClasses$2.LIST_ITEM_CLASS] + " input[type=\"checkbox\"]:not(:disabled)\n ",
|
|
792
|
-
RADIO_SELECTOR: 'input[type="radio"]',
|
|
793
|
-
SELECTED_ITEM_SELECTOR: '[aria-selected="true"], [aria-current="true"]',
|
|
794
|
-
};
|
|
795
|
-
var numbers$2 = {
|
|
796
|
-
UNSET_INDEX: -1,
|
|
797
|
-
TYPEAHEAD_BUFFER_CLEAR_TIMEOUT_MS: 300
|
|
798
|
-
};
|
|
799
|
-
var evolutionAttribute = 'evolution';
|
|
800
|
-
|
|
801
|
-
/**
|
|
802
|
-
* @license
|
|
803
|
-
* Copyright 2020 Google Inc.
|
|
804
|
-
*
|
|
805
|
-
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
806
|
-
* of this software and associated documentation files (the "Software"), to deal
|
|
807
|
-
* in the Software without restriction, including without limitation the rights
|
|
808
|
-
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
809
|
-
* copies of the Software, and to permit persons to whom the Software is
|
|
810
|
-
* furnished to do so, subject to the following conditions:
|
|
811
|
-
*
|
|
812
|
-
* The above copyright notice and this permission notice shall be included in
|
|
813
|
-
* all copies or substantial portions of the Software.
|
|
814
|
-
*
|
|
815
|
-
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
816
|
-
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
817
|
-
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
818
|
-
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
819
|
-
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
820
|
-
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
821
|
-
* THE SOFTWARE.
|
|
822
|
-
*/
|
|
823
|
-
/**
|
|
824
|
-
* KEY provides normalized string values for keys.
|
|
825
|
-
*/
|
|
826
|
-
var KEY = {
|
|
827
|
-
UNKNOWN: 'Unknown',
|
|
828
|
-
BACKSPACE: 'Backspace',
|
|
829
|
-
ENTER: 'Enter',
|
|
830
|
-
SPACEBAR: 'Spacebar',
|
|
831
|
-
PAGE_UP: 'PageUp',
|
|
832
|
-
PAGE_DOWN: 'PageDown',
|
|
833
|
-
END: 'End',
|
|
834
|
-
HOME: 'Home',
|
|
835
|
-
ARROW_LEFT: 'ArrowLeft',
|
|
836
|
-
ARROW_UP: 'ArrowUp',
|
|
837
|
-
ARROW_RIGHT: 'ArrowRight',
|
|
838
|
-
ARROW_DOWN: 'ArrowDown',
|
|
839
|
-
DELETE: 'Delete',
|
|
840
|
-
ESCAPE: 'Escape',
|
|
841
|
-
TAB: 'Tab',
|
|
842
|
-
};
|
|
843
|
-
var normalizedKeys = new Set();
|
|
844
|
-
// IE11 has no support for new Map with iterable so we need to initialize this
|
|
845
|
-
// by hand.
|
|
846
|
-
normalizedKeys.add(KEY.BACKSPACE);
|
|
847
|
-
normalizedKeys.add(KEY.ENTER);
|
|
848
|
-
normalizedKeys.add(KEY.SPACEBAR);
|
|
849
|
-
normalizedKeys.add(KEY.PAGE_UP);
|
|
850
|
-
normalizedKeys.add(KEY.PAGE_DOWN);
|
|
851
|
-
normalizedKeys.add(KEY.END);
|
|
852
|
-
normalizedKeys.add(KEY.HOME);
|
|
853
|
-
normalizedKeys.add(KEY.ARROW_LEFT);
|
|
854
|
-
normalizedKeys.add(KEY.ARROW_UP);
|
|
855
|
-
normalizedKeys.add(KEY.ARROW_RIGHT);
|
|
856
|
-
normalizedKeys.add(KEY.ARROW_DOWN);
|
|
857
|
-
normalizedKeys.add(KEY.DELETE);
|
|
858
|
-
normalizedKeys.add(KEY.ESCAPE);
|
|
859
|
-
normalizedKeys.add(KEY.TAB);
|
|
860
|
-
var KEY_CODE = {
|
|
861
|
-
BACKSPACE: 8,
|
|
862
|
-
ENTER: 13,
|
|
863
|
-
SPACEBAR: 32,
|
|
864
|
-
PAGE_UP: 33,
|
|
865
|
-
PAGE_DOWN: 34,
|
|
866
|
-
END: 35,
|
|
867
|
-
HOME: 36,
|
|
868
|
-
ARROW_LEFT: 37,
|
|
869
|
-
ARROW_UP: 38,
|
|
870
|
-
ARROW_RIGHT: 39,
|
|
871
|
-
ARROW_DOWN: 40,
|
|
872
|
-
DELETE: 46,
|
|
873
|
-
ESCAPE: 27,
|
|
874
|
-
TAB: 9,
|
|
875
|
-
};
|
|
876
|
-
var mappedKeyCodes = new Map();
|
|
877
|
-
// IE11 has no support for new Map with iterable so we need to initialize this
|
|
878
|
-
// by hand.
|
|
879
|
-
mappedKeyCodes.set(KEY_CODE.BACKSPACE, KEY.BACKSPACE);
|
|
880
|
-
mappedKeyCodes.set(KEY_CODE.ENTER, KEY.ENTER);
|
|
881
|
-
mappedKeyCodes.set(KEY_CODE.SPACEBAR, KEY.SPACEBAR);
|
|
882
|
-
mappedKeyCodes.set(KEY_CODE.PAGE_UP, KEY.PAGE_UP);
|
|
883
|
-
mappedKeyCodes.set(KEY_CODE.PAGE_DOWN, KEY.PAGE_DOWN);
|
|
884
|
-
mappedKeyCodes.set(KEY_CODE.END, KEY.END);
|
|
885
|
-
mappedKeyCodes.set(KEY_CODE.HOME, KEY.HOME);
|
|
886
|
-
mappedKeyCodes.set(KEY_CODE.ARROW_LEFT, KEY.ARROW_LEFT);
|
|
887
|
-
mappedKeyCodes.set(KEY_CODE.ARROW_UP, KEY.ARROW_UP);
|
|
888
|
-
mappedKeyCodes.set(KEY_CODE.ARROW_RIGHT, KEY.ARROW_RIGHT);
|
|
889
|
-
mappedKeyCodes.set(KEY_CODE.ARROW_DOWN, KEY.ARROW_DOWN);
|
|
890
|
-
mappedKeyCodes.set(KEY_CODE.DELETE, KEY.DELETE);
|
|
891
|
-
mappedKeyCodes.set(KEY_CODE.ESCAPE, KEY.ESCAPE);
|
|
892
|
-
mappedKeyCodes.set(KEY_CODE.TAB, KEY.TAB);
|
|
893
|
-
var navigationKeys = new Set();
|
|
894
|
-
// IE11 has no support for new Set with iterable so we need to initialize this
|
|
895
|
-
// by hand.
|
|
896
|
-
navigationKeys.add(KEY.PAGE_UP);
|
|
897
|
-
navigationKeys.add(KEY.PAGE_DOWN);
|
|
898
|
-
navigationKeys.add(KEY.END);
|
|
899
|
-
navigationKeys.add(KEY.HOME);
|
|
900
|
-
navigationKeys.add(KEY.ARROW_LEFT);
|
|
901
|
-
navigationKeys.add(KEY.ARROW_UP);
|
|
902
|
-
navigationKeys.add(KEY.ARROW_RIGHT);
|
|
903
|
-
navigationKeys.add(KEY.ARROW_DOWN);
|
|
904
|
-
/**
|
|
905
|
-
* normalizeKey returns the normalized string for a navigational action.
|
|
906
|
-
*/
|
|
907
|
-
function normalizeKey(evt) {
|
|
908
|
-
var key = evt.key;
|
|
909
|
-
// If the event already has a normalized key, return it
|
|
910
|
-
if (normalizedKeys.has(key)) {
|
|
911
|
-
return key;
|
|
912
|
-
}
|
|
913
|
-
// tslint:disable-next-line:deprecation
|
|
914
|
-
var mappedKey = mappedKeyCodes.get(evt.keyCode);
|
|
915
|
-
if (mappedKey) {
|
|
916
|
-
return mappedKey;
|
|
917
|
-
}
|
|
918
|
-
return KEY.UNKNOWN;
|
|
919
|
-
}
|
|
920
|
-
|
|
921
|
-
/**
|
|
922
|
-
* @license
|
|
923
|
-
* Copyright 2020 Google Inc.
|
|
924
|
-
*
|
|
925
|
-
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
926
|
-
* of this software and associated documentation files (the "Software"), to deal
|
|
927
|
-
* in the Software without restriction, including without limitation the rights
|
|
928
|
-
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
929
|
-
* copies of the Software, and to permit persons to whom the Software is
|
|
930
|
-
* furnished to do so, subject to the following conditions:
|
|
931
|
-
*
|
|
932
|
-
* The above copyright notice and this permission notice shall be included in
|
|
933
|
-
* all copies or substantial portions of the Software.
|
|
934
|
-
*
|
|
935
|
-
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
936
|
-
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
937
|
-
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
938
|
-
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
939
|
-
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
940
|
-
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
941
|
-
* THE SOFTWARE.
|
|
942
|
-
*/
|
|
943
|
-
var ELEMENTS_KEY_ALLOWED_IN = ['input', 'button', 'textarea', 'select'];
|
|
944
|
-
/**
|
|
945
|
-
* Ensures that preventDefault is only called if the containing element
|
|
946
|
-
* doesn't consume the event, and it will cause an unintended scroll.
|
|
947
|
-
*
|
|
948
|
-
* @param evt keyboard event to be prevented.
|
|
949
|
-
*/
|
|
950
|
-
var preventDefaultEvent = function (evt) {
|
|
951
|
-
var target = evt.target;
|
|
952
|
-
if (!target) {
|
|
953
|
-
return;
|
|
954
|
-
}
|
|
955
|
-
var tagName = ("" + target.tagName).toLowerCase();
|
|
956
|
-
if (ELEMENTS_KEY_ALLOWED_IN.indexOf(tagName) === -1) {
|
|
957
|
-
evt.preventDefault();
|
|
958
|
-
}
|
|
959
|
-
};
|
|
960
|
-
|
|
961
|
-
/**
|
|
962
|
-
* @license
|
|
963
|
-
* Copyright 2020 Google Inc.
|
|
964
|
-
*
|
|
965
|
-
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
966
|
-
* of this software and associated documentation files (the "Software"), to deal
|
|
967
|
-
* in the Software without restriction, including without limitation the rights
|
|
968
|
-
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
969
|
-
* copies of the Software, and to permit persons to whom the Software is
|
|
970
|
-
* furnished to do so, subject to the following conditions:
|
|
971
|
-
*
|
|
972
|
-
* The above copyright notice and this permission notice shall be included in
|
|
973
|
-
* all copies or substantial portions of the Software.
|
|
974
|
-
*
|
|
975
|
-
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
976
|
-
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
977
|
-
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
978
|
-
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
979
|
-
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
980
|
-
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
981
|
-
* THE SOFTWARE.
|
|
982
|
-
*/
|
|
983
|
-
/**
|
|
984
|
-
* Initializes a state object for typeahead. Use the same reference for calls to
|
|
985
|
-
* typeahead functions.
|
|
986
|
-
*
|
|
987
|
-
* @return The current state of the typeahead process. Each state reference
|
|
988
|
-
* represents a typeahead instance as the reference is typically mutated
|
|
989
|
-
* in-place.
|
|
990
|
-
*/
|
|
991
|
-
function initState() {
|
|
992
|
-
var state = {
|
|
993
|
-
bufferClearTimeout: 0,
|
|
994
|
-
currentFirstChar: '',
|
|
995
|
-
sortedIndexCursor: 0,
|
|
996
|
-
typeaheadBuffer: '',
|
|
997
|
-
};
|
|
998
|
-
return state;
|
|
999
|
-
}
|
|
1000
|
-
/**
|
|
1001
|
-
* Initializes typeahead state by indexing the current list items by primary
|
|
1002
|
-
* text into the sortedIndexByFirstChar data structure.
|
|
1003
|
-
*
|
|
1004
|
-
* @param listItemCount numer of items in the list
|
|
1005
|
-
* @param getPrimaryTextByItemIndex function that returns the primary text at a
|
|
1006
|
-
* given index
|
|
1007
|
-
*
|
|
1008
|
-
* @return Map that maps the first character of the primary text to the full
|
|
1009
|
-
* list text and it's index
|
|
1010
|
-
*/
|
|
1011
|
-
function initSortedIndex(listItemCount, getPrimaryTextByItemIndex) {
|
|
1012
|
-
var sortedIndexByFirstChar = new Map();
|
|
1013
|
-
// Aggregate item text to index mapping
|
|
1014
|
-
for (var i = 0; i < listItemCount; i++) {
|
|
1015
|
-
var primaryText = getPrimaryTextByItemIndex(i).trim();
|
|
1016
|
-
if (!primaryText) {
|
|
1017
|
-
continue;
|
|
1018
|
-
}
|
|
1019
|
-
var firstChar = primaryText[0].toLowerCase();
|
|
1020
|
-
if (!sortedIndexByFirstChar.has(firstChar)) {
|
|
1021
|
-
sortedIndexByFirstChar.set(firstChar, []);
|
|
1022
|
-
}
|
|
1023
|
-
sortedIndexByFirstChar.get(firstChar).push({ text: primaryText.toLowerCase(), index: i });
|
|
1024
|
-
}
|
|
1025
|
-
// Sort the mapping
|
|
1026
|
-
// TODO(b/157162694): Investigate replacing forEach with Map.values()
|
|
1027
|
-
sortedIndexByFirstChar.forEach(function (values) {
|
|
1028
|
-
values.sort(function (first, second) {
|
|
1029
|
-
return first.index - second.index;
|
|
1030
|
-
});
|
|
1031
|
-
});
|
|
1032
|
-
return sortedIndexByFirstChar;
|
|
1033
|
-
}
|
|
1034
|
-
/**
|
|
1035
|
-
* Given the next desired character from the user, it attempts to find the next
|
|
1036
|
-
* list option matching the buffer. Wraps around if at the end of options.
|
|
1037
|
-
*
|
|
1038
|
-
* @param opts Options and accessors
|
|
1039
|
-
* - nextChar - the next character to match against items
|
|
1040
|
-
* - sortedIndexByFirstChar - output of `initSortedIndex(...)`
|
|
1041
|
-
* - focusedItemIndex - the index of the currently focused item
|
|
1042
|
-
* - focusItemAtIndex - function that focuses a list item at given index
|
|
1043
|
-
* - skipFocus - whether or not to focus the matched item
|
|
1044
|
-
* - isItemAtIndexDisabled - function that determines whether an item at a
|
|
1045
|
-
* given index is disabled
|
|
1046
|
-
* @param state The typeahead state instance. See `initState`.
|
|
1047
|
-
*
|
|
1048
|
-
* @return The index of the matched item, or -1 if no match.
|
|
1049
|
-
*/
|
|
1050
|
-
function matchItem(opts, state) {
|
|
1051
|
-
var nextChar = opts.nextChar, focusItemAtIndex = opts.focusItemAtIndex, sortedIndexByFirstChar = opts.sortedIndexByFirstChar, focusedItemIndex = opts.focusedItemIndex, skipFocus = opts.skipFocus, isItemAtIndexDisabled = opts.isItemAtIndexDisabled;
|
|
1052
|
-
clearTimeout(state.bufferClearTimeout);
|
|
1053
|
-
state.bufferClearTimeout = setTimeout(function () {
|
|
1054
|
-
clearBuffer(state);
|
|
1055
|
-
}, numbers$2.TYPEAHEAD_BUFFER_CLEAR_TIMEOUT_MS);
|
|
1056
|
-
state.typeaheadBuffer = state.typeaheadBuffer + nextChar;
|
|
1057
|
-
var index;
|
|
1058
|
-
if (state.typeaheadBuffer.length === 1) {
|
|
1059
|
-
index = matchFirstChar(sortedIndexByFirstChar, focusedItemIndex, isItemAtIndexDisabled, state);
|
|
1060
|
-
}
|
|
1061
|
-
else {
|
|
1062
|
-
index = matchAllChars(sortedIndexByFirstChar, isItemAtIndexDisabled, state);
|
|
1063
|
-
}
|
|
1064
|
-
if (index !== -1 && !skipFocus) {
|
|
1065
|
-
focusItemAtIndex(index);
|
|
1066
|
-
}
|
|
1067
|
-
return index;
|
|
1068
|
-
}
|
|
1069
|
-
/**
|
|
1070
|
-
* Matches the user's single input character in the buffer to the
|
|
1071
|
-
* next option that begins with such character. Wraps around if at
|
|
1072
|
-
* end of options. Returns -1 if no match is found.
|
|
1073
|
-
*/
|
|
1074
|
-
function matchFirstChar(sortedIndexByFirstChar, focusedItemIndex, isItemAtIndexDisabled, state) {
|
|
1075
|
-
var firstChar = state.typeaheadBuffer[0];
|
|
1076
|
-
var itemsMatchingFirstChar = sortedIndexByFirstChar.get(firstChar);
|
|
1077
|
-
if (!itemsMatchingFirstChar) {
|
|
1078
|
-
return -1;
|
|
1079
|
-
}
|
|
1080
|
-
// Has the same firstChar been recently matched?
|
|
1081
|
-
// Also, did starting index remain the same between key presses?
|
|
1082
|
-
// If both hold true, simply increment index.
|
|
1083
|
-
if (firstChar === state.currentFirstChar &&
|
|
1084
|
-
itemsMatchingFirstChar[state.sortedIndexCursor].index ===
|
|
1085
|
-
focusedItemIndex) {
|
|
1086
|
-
state.sortedIndexCursor =
|
|
1087
|
-
(state.sortedIndexCursor + 1) % itemsMatchingFirstChar.length;
|
|
1088
|
-
var newIndex = itemsMatchingFirstChar[state.sortedIndexCursor].index;
|
|
1089
|
-
if (!isItemAtIndexDisabled(newIndex)) {
|
|
1090
|
-
return newIndex;
|
|
1091
|
-
}
|
|
1092
|
-
}
|
|
1093
|
-
// If we're here, it means one of the following happened:
|
|
1094
|
-
// - either firstChar or startingIndex has changed, invalidating the
|
|
1095
|
-
// cursor.
|
|
1096
|
-
// - The next item of typeahead is disabled, so we have to look further.
|
|
1097
|
-
state.currentFirstChar = firstChar;
|
|
1098
|
-
var newCursorPosition = -1;
|
|
1099
|
-
var cursorPosition;
|
|
1100
|
-
// Find the first non-disabled item as a fallback.
|
|
1101
|
-
for (cursorPosition = 0; cursorPosition < itemsMatchingFirstChar.length; cursorPosition++) {
|
|
1102
|
-
if (!isItemAtIndexDisabled(itemsMatchingFirstChar[cursorPosition].index)) {
|
|
1103
|
-
newCursorPosition = cursorPosition;
|
|
1104
|
-
break;
|
|
1105
|
-
}
|
|
1106
|
-
}
|
|
1107
|
-
// Advance cursor to first item matching the firstChar that is positioned
|
|
1108
|
-
// after starting item. Cursor is unchanged from fallback if there's no
|
|
1109
|
-
// such item.
|
|
1110
|
-
for (; cursorPosition < itemsMatchingFirstChar.length; cursorPosition++) {
|
|
1111
|
-
if (itemsMatchingFirstChar[cursorPosition].index > focusedItemIndex &&
|
|
1112
|
-
!isItemAtIndexDisabled(itemsMatchingFirstChar[cursorPosition].index)) {
|
|
1113
|
-
newCursorPosition = cursorPosition;
|
|
1114
|
-
break;
|
|
1115
|
-
}
|
|
1116
|
-
}
|
|
1117
|
-
if (newCursorPosition !== -1) {
|
|
1118
|
-
state.sortedIndexCursor = newCursorPosition;
|
|
1119
|
-
return itemsMatchingFirstChar[state.sortedIndexCursor].index;
|
|
1120
|
-
}
|
|
1121
|
-
return -1;
|
|
1122
|
-
}
|
|
1123
|
-
/**
|
|
1124
|
-
* Attempts to find the next item that matches all of the typeahead buffer.
|
|
1125
|
-
* Wraps around if at end of options. Returns -1 if no match is found.
|
|
1126
|
-
*/
|
|
1127
|
-
function matchAllChars(sortedIndexByFirstChar, isItemAtIndexDisabled, state) {
|
|
1128
|
-
var firstChar = state.typeaheadBuffer[0];
|
|
1129
|
-
var itemsMatchingFirstChar = sortedIndexByFirstChar.get(firstChar);
|
|
1130
|
-
if (!itemsMatchingFirstChar) {
|
|
1131
|
-
return -1;
|
|
1132
|
-
}
|
|
1133
|
-
// Do nothing if text already matches
|
|
1134
|
-
var startingItem = itemsMatchingFirstChar[state.sortedIndexCursor];
|
|
1135
|
-
if (startingItem.text.lastIndexOf(state.typeaheadBuffer, 0) === 0 &&
|
|
1136
|
-
!isItemAtIndexDisabled(startingItem.index)) {
|
|
1137
|
-
return startingItem.index;
|
|
1138
|
-
}
|
|
1139
|
-
// Find next item that matches completely; if no match, we'll eventually
|
|
1140
|
-
// loop around to same position
|
|
1141
|
-
var cursorPosition = (state.sortedIndexCursor + 1) % itemsMatchingFirstChar.length;
|
|
1142
|
-
var nextCursorPosition = -1;
|
|
1143
|
-
while (cursorPosition !== state.sortedIndexCursor) {
|
|
1144
|
-
var currentItem = itemsMatchingFirstChar[cursorPosition];
|
|
1145
|
-
var matches = currentItem.text.lastIndexOf(state.typeaheadBuffer, 0) === 0;
|
|
1146
|
-
var isEnabled = !isItemAtIndexDisabled(currentItem.index);
|
|
1147
|
-
if (matches && isEnabled) {
|
|
1148
|
-
nextCursorPosition = cursorPosition;
|
|
1149
|
-
break;
|
|
1150
|
-
}
|
|
1151
|
-
cursorPosition = (cursorPosition + 1) % itemsMatchingFirstChar.length;
|
|
1152
|
-
}
|
|
1153
|
-
if (nextCursorPosition !== -1) {
|
|
1154
|
-
state.sortedIndexCursor = nextCursorPosition;
|
|
1155
|
-
return itemsMatchingFirstChar[state.sortedIndexCursor].index;
|
|
1156
|
-
}
|
|
1157
|
-
return -1;
|
|
1158
|
-
}
|
|
1159
|
-
/**
|
|
1160
|
-
* Whether or not the given typeahead instaance state is currently typing.
|
|
1161
|
-
*
|
|
1162
|
-
* @param state The typeahead state instance. See `initState`.
|
|
1163
|
-
*/
|
|
1164
|
-
function isTypingInProgress(state) {
|
|
1165
|
-
return state.typeaheadBuffer.length > 0;
|
|
1166
|
-
}
|
|
1167
|
-
/**
|
|
1168
|
-
* Clears the typeahaed buffer so that it resets item matching to the first
|
|
1169
|
-
* character.
|
|
1170
|
-
*
|
|
1171
|
-
* @param state The typeahead state instance. See `initState`.
|
|
1172
|
-
*/
|
|
1173
|
-
function clearBuffer(state) {
|
|
1174
|
-
state.typeaheadBuffer = '';
|
|
1175
|
-
}
|
|
1176
|
-
/**
|
|
1177
|
-
* Given a keydown event, it calculates whether or not to automatically focus a
|
|
1178
|
-
* list item depending on what was typed mimicing the typeahead functionality of
|
|
1179
|
-
* a standard <select> element that is open.
|
|
1180
|
-
*
|
|
1181
|
-
* @param opts Options and accessors
|
|
1182
|
-
* - event - the KeyboardEvent to handle and parse
|
|
1183
|
-
* - sortedIndexByFirstChar - output of `initSortedIndex(...)`
|
|
1184
|
-
* - focusedItemIndex - the index of the currently focused item
|
|
1185
|
-
* - focusItemAtIndex - function that focuses a list item at given index
|
|
1186
|
-
* - isItemAtFocusedIndexDisabled - whether or not the currently focused item
|
|
1187
|
-
* is disabled
|
|
1188
|
-
* - isTargetListItem - whether or not the event target is a list item
|
|
1189
|
-
* @param state The typeahead state instance. See `initState`.
|
|
1190
|
-
*
|
|
1191
|
-
* @returns index of the item matched by the keydown. -1 if not matched.
|
|
1192
|
-
*/
|
|
1193
|
-
function handleKeydown(opts, state) {
|
|
1194
|
-
var event = opts.event, isTargetListItem = opts.isTargetListItem, focusedItemIndex = opts.focusedItemIndex, focusItemAtIndex = opts.focusItemAtIndex, sortedIndexByFirstChar = opts.sortedIndexByFirstChar, isItemAtIndexDisabled = opts.isItemAtIndexDisabled;
|
|
1195
|
-
var isArrowLeft = normalizeKey(event) === 'ArrowLeft';
|
|
1196
|
-
var isArrowUp = normalizeKey(event) === 'ArrowUp';
|
|
1197
|
-
var isArrowRight = normalizeKey(event) === 'ArrowRight';
|
|
1198
|
-
var isArrowDown = normalizeKey(event) === 'ArrowDown';
|
|
1199
|
-
var isHome = normalizeKey(event) === 'Home';
|
|
1200
|
-
var isEnd = normalizeKey(event) === 'End';
|
|
1201
|
-
var isEnter = normalizeKey(event) === 'Enter';
|
|
1202
|
-
var isSpace = normalizeKey(event) === 'Spacebar';
|
|
1203
|
-
if (event.ctrlKey || event.metaKey || isArrowLeft || isArrowUp ||
|
|
1204
|
-
isArrowRight || isArrowDown || isHome || isEnd || isEnter) {
|
|
1205
|
-
return -1;
|
|
1206
|
-
}
|
|
1207
|
-
var isCharacterKey = !isSpace && event.key.length === 1;
|
|
1208
|
-
if (isCharacterKey) {
|
|
1209
|
-
preventDefaultEvent(event);
|
|
1210
|
-
var matchItemOpts = {
|
|
1211
|
-
focusItemAtIndex: focusItemAtIndex,
|
|
1212
|
-
focusedItemIndex: focusedItemIndex,
|
|
1213
|
-
nextChar: event.key.toLowerCase(),
|
|
1214
|
-
sortedIndexByFirstChar: sortedIndexByFirstChar,
|
|
1215
|
-
skipFocus: false,
|
|
1216
|
-
isItemAtIndexDisabled: isItemAtIndexDisabled,
|
|
1217
|
-
};
|
|
1218
|
-
return matchItem(matchItemOpts, state);
|
|
1219
|
-
}
|
|
1220
|
-
if (!isSpace) {
|
|
1221
|
-
return -1;
|
|
1222
|
-
}
|
|
1223
|
-
if (isTargetListItem) {
|
|
1224
|
-
preventDefaultEvent(event);
|
|
1225
|
-
}
|
|
1226
|
-
var typeaheadOnListItem = isTargetListItem && isTypingInProgress(state);
|
|
1227
|
-
if (typeaheadOnListItem) {
|
|
1228
|
-
var matchItemOpts = {
|
|
1229
|
-
focusItemAtIndex: focusItemAtIndex,
|
|
1230
|
-
focusedItemIndex: focusedItemIndex,
|
|
1231
|
-
nextChar: ' ',
|
|
1232
|
-
sortedIndexByFirstChar: sortedIndexByFirstChar,
|
|
1233
|
-
skipFocus: false,
|
|
1234
|
-
isItemAtIndexDisabled: isItemAtIndexDisabled,
|
|
1235
|
-
};
|
|
1236
|
-
// space participates in typeahead matching if in rapid typing mode
|
|
1237
|
-
return matchItem(matchItemOpts, state);
|
|
1238
|
-
}
|
|
1239
|
-
return -1;
|
|
1240
|
-
}
|
|
1241
|
-
|
|
1242
|
-
/**
|
|
1243
|
-
* @license
|
|
1244
|
-
* Copyright 2018 Google Inc.
|
|
1245
|
-
*
|
|
1246
|
-
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
1247
|
-
* of this software and associated documentation files (the "Software"), to deal
|
|
1248
|
-
* in the Software without restriction, including without limitation the rights
|
|
1249
|
-
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
1250
|
-
* copies of the Software, and to permit persons to whom the Software is
|
|
1251
|
-
* furnished to do so, subject to the following conditions:
|
|
1252
|
-
*
|
|
1253
|
-
* The above copyright notice and this permission notice shall be included in
|
|
1254
|
-
* all copies or substantial portions of the Software.
|
|
1255
|
-
*
|
|
1256
|
-
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
1257
|
-
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
1258
|
-
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
1259
|
-
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
1260
|
-
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
1261
|
-
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
1262
|
-
* THE SOFTWARE.
|
|
1263
|
-
*/
|
|
1264
|
-
function isNumberArray(selectedIndex) {
|
|
1265
|
-
return selectedIndex instanceof Array;
|
|
1266
|
-
}
|
|
1267
|
-
var MDCListFoundation = /** @class */ (function (_super) {
|
|
1268
|
-
ponyfill.__extends(MDCListFoundation, _super);
|
|
1269
|
-
function MDCListFoundation(adapter) {
|
|
1270
|
-
var _this = _super.call(this, ponyfill.__assign(ponyfill.__assign({}, MDCListFoundation.defaultAdapter), adapter)) || this;
|
|
1271
|
-
_this.wrapFocus = false;
|
|
1272
|
-
_this.isVertical = true;
|
|
1273
|
-
_this.isSingleSelectionList = false;
|
|
1274
|
-
_this.selectedIndex = numbers$2.UNSET_INDEX;
|
|
1275
|
-
_this.focusedItemIndex = numbers$2.UNSET_INDEX;
|
|
1276
|
-
_this.useActivatedClass = false;
|
|
1277
|
-
_this.useSelectedAttr = false;
|
|
1278
|
-
_this.ariaCurrentAttrValue = null;
|
|
1279
|
-
_this.isCheckboxList = false;
|
|
1280
|
-
_this.isRadioList = false;
|
|
1281
|
-
_this.hasTypeahead = false;
|
|
1282
|
-
// Transiently holds current typeahead prefix from user.
|
|
1283
|
-
_this.typeaheadState = initState();
|
|
1284
|
-
_this.sortedIndexByFirstChar = new Map();
|
|
1285
|
-
return _this;
|
|
1286
|
-
}
|
|
1287
|
-
Object.defineProperty(MDCListFoundation, "strings", {
|
|
1288
|
-
get: function () {
|
|
1289
|
-
return strings$2;
|
|
1290
|
-
},
|
|
1291
|
-
enumerable: false,
|
|
1292
|
-
configurable: true
|
|
1293
|
-
});
|
|
1294
|
-
Object.defineProperty(MDCListFoundation, "cssClasses", {
|
|
1295
|
-
get: function () {
|
|
1296
|
-
return cssClasses$2;
|
|
1297
|
-
},
|
|
1298
|
-
enumerable: false,
|
|
1299
|
-
configurable: true
|
|
1300
|
-
});
|
|
1301
|
-
Object.defineProperty(MDCListFoundation, "numbers", {
|
|
1302
|
-
get: function () {
|
|
1303
|
-
return numbers$2;
|
|
1304
|
-
},
|
|
1305
|
-
enumerable: false,
|
|
1306
|
-
configurable: true
|
|
1307
|
-
});
|
|
1308
|
-
Object.defineProperty(MDCListFoundation, "defaultAdapter", {
|
|
1309
|
-
get: function () {
|
|
1310
|
-
return {
|
|
1311
|
-
addClassForElementIndex: function () { return undefined; },
|
|
1312
|
-
focusItemAtIndex: function () { return undefined; },
|
|
1313
|
-
getAttributeForElementIndex: function () { return null; },
|
|
1314
|
-
getFocusedElementIndex: function () { return 0; },
|
|
1315
|
-
getListItemCount: function () { return 0; },
|
|
1316
|
-
hasCheckboxAtIndex: function () { return false; },
|
|
1317
|
-
hasRadioAtIndex: function () { return false; },
|
|
1318
|
-
isCheckboxCheckedAtIndex: function () { return false; },
|
|
1319
|
-
isFocusInsideList: function () { return false; },
|
|
1320
|
-
isRootFocused: function () { return false; },
|
|
1321
|
-
listItemAtIndexHasClass: function () { return false; },
|
|
1322
|
-
notifyAction: function () { return undefined; },
|
|
1323
|
-
removeClassForElementIndex: function () { return undefined; },
|
|
1324
|
-
setAttributeForElementIndex: function () { return undefined; },
|
|
1325
|
-
setCheckedCheckboxOrRadioAtIndex: function () { return undefined; },
|
|
1326
|
-
setTabIndexForListItemChildren: function () { return undefined; },
|
|
1327
|
-
getPrimaryTextAtIndex: function () { return ''; },
|
|
1328
|
-
};
|
|
1329
|
-
},
|
|
1330
|
-
enumerable: false,
|
|
1331
|
-
configurable: true
|
|
1332
|
-
});
|
|
1333
|
-
MDCListFoundation.prototype.layout = function () {
|
|
1334
|
-
if (this.adapter.getListItemCount() === 0) {
|
|
1335
|
-
return;
|
|
1336
|
-
}
|
|
1337
|
-
// TODO(b/172274142): consider all items when determining the list's type.
|
|
1338
|
-
if (this.adapter.hasCheckboxAtIndex(0)) {
|
|
1339
|
-
this.isCheckboxList = true;
|
|
1340
|
-
}
|
|
1341
|
-
else if (this.adapter.hasRadioAtIndex(0)) {
|
|
1342
|
-
this.isRadioList = true;
|
|
1343
|
-
}
|
|
1344
|
-
else {
|
|
1345
|
-
this.maybeInitializeSingleSelection();
|
|
1346
|
-
}
|
|
1347
|
-
if (this.hasTypeahead) {
|
|
1348
|
-
this.sortedIndexByFirstChar = this.typeaheadInitSortedIndex();
|
|
1349
|
-
}
|
|
1350
|
-
};
|
|
1351
|
-
/** Returns the index of the item that was last focused. */
|
|
1352
|
-
MDCListFoundation.prototype.getFocusedItemIndex = function () {
|
|
1353
|
-
return this.focusedItemIndex;
|
|
1354
|
-
};
|
|
1355
|
-
/** Toggles focus wrapping with keyboard navigation. */
|
|
1356
|
-
MDCListFoundation.prototype.setWrapFocus = function (value) {
|
|
1357
|
-
this.wrapFocus = value;
|
|
1358
|
-
};
|
|
1359
|
-
/**
|
|
1360
|
-
* Toggles orientation direction for keyboard navigation (true for vertical,
|
|
1361
|
-
* false for horizontal).
|
|
1362
|
-
*/
|
|
1363
|
-
MDCListFoundation.prototype.setVerticalOrientation = function (value) {
|
|
1364
|
-
this.isVertical = value;
|
|
1365
|
-
};
|
|
1366
|
-
/** Toggles single-selection behavior. */
|
|
1367
|
-
MDCListFoundation.prototype.setSingleSelection = function (value) {
|
|
1368
|
-
this.isSingleSelectionList = value;
|
|
1369
|
-
if (value) {
|
|
1370
|
-
this.maybeInitializeSingleSelection();
|
|
1371
|
-
this.selectedIndex = this.getSelectedIndexFromDOM();
|
|
1372
|
-
}
|
|
1373
|
-
};
|
|
1374
|
-
/**
|
|
1375
|
-
* Automatically determines whether the list is single selection list. If so,
|
|
1376
|
-
* initializes the internal state to match the selected item.
|
|
1377
|
-
*/
|
|
1378
|
-
MDCListFoundation.prototype.maybeInitializeSingleSelection = function () {
|
|
1379
|
-
var selectedItemIndex = this.getSelectedIndexFromDOM();
|
|
1380
|
-
if (selectedItemIndex === numbers$2.UNSET_INDEX)
|
|
1381
|
-
return;
|
|
1382
|
-
var hasActivatedClass = this.adapter.listItemAtIndexHasClass(selectedItemIndex, cssClasses$2.LIST_ITEM_ACTIVATED_CLASS);
|
|
1383
|
-
if (hasActivatedClass) {
|
|
1384
|
-
this.setUseActivatedClass(true);
|
|
1385
|
-
}
|
|
1386
|
-
this.isSingleSelectionList = true;
|
|
1387
|
-
this.selectedIndex = selectedItemIndex;
|
|
1388
|
-
};
|
|
1389
|
-
/** @return Index of the first selected item based on the DOM state. */
|
|
1390
|
-
MDCListFoundation.prototype.getSelectedIndexFromDOM = function () {
|
|
1391
|
-
var selectedIndex = numbers$2.UNSET_INDEX;
|
|
1392
|
-
var listItemsCount = this.adapter.getListItemCount();
|
|
1393
|
-
for (var i = 0; i < listItemsCount; i++) {
|
|
1394
|
-
var hasSelectedClass = this.adapter.listItemAtIndexHasClass(i, cssClasses$2.LIST_ITEM_SELECTED_CLASS);
|
|
1395
|
-
var hasActivatedClass = this.adapter.listItemAtIndexHasClass(i, cssClasses$2.LIST_ITEM_ACTIVATED_CLASS);
|
|
1396
|
-
if (!(hasSelectedClass || hasActivatedClass)) {
|
|
1397
|
-
continue;
|
|
1398
|
-
}
|
|
1399
|
-
selectedIndex = i;
|
|
1400
|
-
break;
|
|
1401
|
-
}
|
|
1402
|
-
return selectedIndex;
|
|
1403
|
-
};
|
|
1404
|
-
/**
|
|
1405
|
-
* Sets whether typeahead is enabled on the list.
|
|
1406
|
-
* @param hasTypeahead Whether typeahead is enabled.
|
|
1407
|
-
*/
|
|
1408
|
-
MDCListFoundation.prototype.setHasTypeahead = function (hasTypeahead) {
|
|
1409
|
-
this.hasTypeahead = hasTypeahead;
|
|
1410
|
-
if (hasTypeahead) {
|
|
1411
|
-
this.sortedIndexByFirstChar = this.typeaheadInitSortedIndex();
|
|
1412
|
-
}
|
|
1413
|
-
};
|
|
1414
|
-
/**
|
|
1415
|
-
* @return Whether typeahead is currently matching a user-specified prefix.
|
|
1416
|
-
*/
|
|
1417
|
-
MDCListFoundation.prototype.isTypeaheadInProgress = function () {
|
|
1418
|
-
return this.hasTypeahead &&
|
|
1419
|
-
isTypingInProgress(this.typeaheadState);
|
|
1420
|
-
};
|
|
1421
|
-
/** Toggle use of the "activated" CSS class. */
|
|
1422
|
-
MDCListFoundation.prototype.setUseActivatedClass = function (useActivated) {
|
|
1423
|
-
this.useActivatedClass = useActivated;
|
|
1424
|
-
};
|
|
1425
|
-
/**
|
|
1426
|
-
* Toggles use of the selected attribute (true for aria-selected, false for
|
|
1427
|
-
* aria-checked).
|
|
1428
|
-
*/
|
|
1429
|
-
MDCListFoundation.prototype.setUseSelectedAttribute = function (useSelected) {
|
|
1430
|
-
this.useSelectedAttr = useSelected;
|
|
1431
|
-
};
|
|
1432
|
-
MDCListFoundation.prototype.getSelectedIndex = function () {
|
|
1433
|
-
return this.selectedIndex;
|
|
1434
|
-
};
|
|
1435
|
-
MDCListFoundation.prototype.setSelectedIndex = function (index, _a) {
|
|
1436
|
-
var _b = _a === void 0 ? {} : _a, forceUpdate = _b.forceUpdate;
|
|
1437
|
-
if (!this.isIndexValid(index)) {
|
|
1438
|
-
return;
|
|
1439
|
-
}
|
|
1440
|
-
if (this.isCheckboxList) {
|
|
1441
|
-
this.setCheckboxAtIndex(index);
|
|
1442
|
-
}
|
|
1443
|
-
else if (this.isRadioList) {
|
|
1444
|
-
this.setRadioAtIndex(index);
|
|
1445
|
-
}
|
|
1446
|
-
else {
|
|
1447
|
-
this.setSingleSelectionAtIndex(index, { forceUpdate: forceUpdate });
|
|
1448
|
-
}
|
|
1449
|
-
};
|
|
1450
|
-
/**
|
|
1451
|
-
* Focus in handler for the list items.
|
|
1452
|
-
*/
|
|
1453
|
-
MDCListFoundation.prototype.handleFocusIn = function (listItemIndex) {
|
|
1454
|
-
if (listItemIndex >= 0) {
|
|
1455
|
-
this.focusedItemIndex = listItemIndex;
|
|
1456
|
-
this.adapter.setAttributeForElementIndex(listItemIndex, 'tabindex', '0');
|
|
1457
|
-
this.adapter.setTabIndexForListItemChildren(listItemIndex, '0');
|
|
1458
|
-
}
|
|
1459
|
-
};
|
|
1460
|
-
/**
|
|
1461
|
-
* Focus out handler for the list items.
|
|
1462
|
-
*/
|
|
1463
|
-
MDCListFoundation.prototype.handleFocusOut = function (listItemIndex) {
|
|
1464
|
-
var _this = this;
|
|
1465
|
-
if (listItemIndex >= 0) {
|
|
1466
|
-
this.adapter.setAttributeForElementIndex(listItemIndex, 'tabindex', '-1');
|
|
1467
|
-
this.adapter.setTabIndexForListItemChildren(listItemIndex, '-1');
|
|
1468
|
-
}
|
|
1469
|
-
/**
|
|
1470
|
-
* Between Focusout & Focusin some browsers do not have focus on any
|
|
1471
|
-
* element. Setting a delay to wait till the focus is moved to next element.
|
|
1472
|
-
*/
|
|
1473
|
-
setTimeout(function () {
|
|
1474
|
-
if (!_this.adapter.isFocusInsideList()) {
|
|
1475
|
-
_this.setTabindexToFirstSelectedOrFocusedItem();
|
|
1476
|
-
}
|
|
1477
|
-
}, 0);
|
|
1478
|
-
};
|
|
1479
|
-
/**
|
|
1480
|
-
* Key handler for the list.
|
|
1481
|
-
*/
|
|
1482
|
-
MDCListFoundation.prototype.handleKeydown = function (event, isRootListItem, listItemIndex) {
|
|
1483
|
-
var _this = this;
|
|
1484
|
-
var isArrowLeft = normalizeKey(event) === 'ArrowLeft';
|
|
1485
|
-
var isArrowUp = normalizeKey(event) === 'ArrowUp';
|
|
1486
|
-
var isArrowRight = normalizeKey(event) === 'ArrowRight';
|
|
1487
|
-
var isArrowDown = normalizeKey(event) === 'ArrowDown';
|
|
1488
|
-
var isHome = normalizeKey(event) === 'Home';
|
|
1489
|
-
var isEnd = normalizeKey(event) === 'End';
|
|
1490
|
-
var isEnter = normalizeKey(event) === 'Enter';
|
|
1491
|
-
var isSpace = normalizeKey(event) === 'Spacebar';
|
|
1492
|
-
// Have to check both upper and lower case, because having caps lock on
|
|
1493
|
-
// affects the value.
|
|
1494
|
-
var isLetterA = event.key === 'A' || event.key === 'a';
|
|
1495
|
-
if (this.adapter.isRootFocused()) {
|
|
1496
|
-
if (isArrowUp || isEnd) {
|
|
1497
|
-
event.preventDefault();
|
|
1498
|
-
this.focusLastElement();
|
|
1499
|
-
}
|
|
1500
|
-
else if (isArrowDown || isHome) {
|
|
1501
|
-
event.preventDefault();
|
|
1502
|
-
this.focusFirstElement();
|
|
1503
|
-
}
|
|
1504
|
-
if (this.hasTypeahead) {
|
|
1505
|
-
var handleKeydownOpts = {
|
|
1506
|
-
event: event,
|
|
1507
|
-
focusItemAtIndex: function (index) {
|
|
1508
|
-
_this.focusItemAtIndex(index);
|
|
1509
|
-
},
|
|
1510
|
-
focusedItemIndex: -1,
|
|
1511
|
-
isTargetListItem: isRootListItem,
|
|
1512
|
-
sortedIndexByFirstChar: this.sortedIndexByFirstChar,
|
|
1513
|
-
isItemAtIndexDisabled: function (index) {
|
|
1514
|
-
return _this.adapter.listItemAtIndexHasClass(index, cssClasses$2.LIST_ITEM_DISABLED_CLASS);
|
|
1515
|
-
},
|
|
1516
|
-
};
|
|
1517
|
-
handleKeydown(handleKeydownOpts, this.typeaheadState);
|
|
1518
|
-
}
|
|
1519
|
-
return;
|
|
1520
|
-
}
|
|
1521
|
-
var currentIndex = this.adapter.getFocusedElementIndex();
|
|
1522
|
-
if (currentIndex === -1) {
|
|
1523
|
-
currentIndex = listItemIndex;
|
|
1524
|
-
if (currentIndex < 0) {
|
|
1525
|
-
// If this event doesn't have a mdc-list-item ancestor from the
|
|
1526
|
-
// current list (not from a sublist), return early.
|
|
1527
|
-
return;
|
|
1528
|
-
}
|
|
1529
|
-
}
|
|
1530
|
-
if ((this.isVertical && isArrowDown) ||
|
|
1531
|
-
(!this.isVertical && isArrowRight)) {
|
|
1532
|
-
preventDefaultEvent(event);
|
|
1533
|
-
this.focusNextElement(currentIndex);
|
|
1534
|
-
}
|
|
1535
|
-
else if ((this.isVertical && isArrowUp) || (!this.isVertical && isArrowLeft)) {
|
|
1536
|
-
preventDefaultEvent(event);
|
|
1537
|
-
this.focusPrevElement(currentIndex);
|
|
1538
|
-
}
|
|
1539
|
-
else if (isHome) {
|
|
1540
|
-
preventDefaultEvent(event);
|
|
1541
|
-
this.focusFirstElement();
|
|
1542
|
-
}
|
|
1543
|
-
else if (isEnd) {
|
|
1544
|
-
preventDefaultEvent(event);
|
|
1545
|
-
this.focusLastElement();
|
|
1546
|
-
}
|
|
1547
|
-
else if (isLetterA && event.ctrlKey && this.isCheckboxList) {
|
|
1548
|
-
event.preventDefault();
|
|
1549
|
-
this.toggleAll(this.selectedIndex === numbers$2.UNSET_INDEX ?
|
|
1550
|
-
[] :
|
|
1551
|
-
this.selectedIndex);
|
|
1552
|
-
}
|
|
1553
|
-
else if (isEnter || isSpace) {
|
|
1554
|
-
if (isRootListItem) {
|
|
1555
|
-
// Return early if enter key is pressed on anchor element which triggers
|
|
1556
|
-
// synthetic MouseEvent event.
|
|
1557
|
-
var target = event.target;
|
|
1558
|
-
if (target && target.tagName === 'A' && isEnter) {
|
|
1559
|
-
return;
|
|
1560
|
-
}
|
|
1561
|
-
preventDefaultEvent(event);
|
|
1562
|
-
if (this.adapter.listItemAtIndexHasClass(currentIndex, cssClasses$2.LIST_ITEM_DISABLED_CLASS)) {
|
|
1563
|
-
return;
|
|
1564
|
-
}
|
|
1565
|
-
if (!this.isTypeaheadInProgress()) {
|
|
1566
|
-
if (this.isSelectableList()) {
|
|
1567
|
-
this.setSelectedIndexOnAction(currentIndex);
|
|
1568
|
-
}
|
|
1569
|
-
this.adapter.notifyAction(currentIndex);
|
|
1570
|
-
}
|
|
1571
|
-
}
|
|
1572
|
-
}
|
|
1573
|
-
if (this.hasTypeahead) {
|
|
1574
|
-
var handleKeydownOpts = {
|
|
1575
|
-
event: event,
|
|
1576
|
-
focusItemAtIndex: function (index) {
|
|
1577
|
-
_this.focusItemAtIndex(index);
|
|
1578
|
-
},
|
|
1579
|
-
focusedItemIndex: this.focusedItemIndex,
|
|
1580
|
-
isTargetListItem: isRootListItem,
|
|
1581
|
-
sortedIndexByFirstChar: this.sortedIndexByFirstChar,
|
|
1582
|
-
isItemAtIndexDisabled: function (index) { return _this.adapter.listItemAtIndexHasClass(index, cssClasses$2.LIST_ITEM_DISABLED_CLASS); },
|
|
1583
|
-
};
|
|
1584
|
-
handleKeydown(handleKeydownOpts, this.typeaheadState);
|
|
1585
|
-
}
|
|
1586
|
-
};
|
|
1587
|
-
/**
|
|
1588
|
-
* Click handler for the list.
|
|
1589
|
-
*/
|
|
1590
|
-
MDCListFoundation.prototype.handleClick = function (index, toggleCheckbox) {
|
|
1591
|
-
if (index === numbers$2.UNSET_INDEX) {
|
|
1592
|
-
return;
|
|
1593
|
-
}
|
|
1594
|
-
if (this.adapter.listItemAtIndexHasClass(index, cssClasses$2.LIST_ITEM_DISABLED_CLASS)) {
|
|
1595
|
-
return;
|
|
1596
|
-
}
|
|
1597
|
-
if (this.isSelectableList()) {
|
|
1598
|
-
this.setSelectedIndexOnAction(index, toggleCheckbox);
|
|
1599
|
-
}
|
|
1600
|
-
this.adapter.notifyAction(index);
|
|
1601
|
-
};
|
|
1602
|
-
/**
|
|
1603
|
-
* Focuses the next element on the list.
|
|
1604
|
-
*/
|
|
1605
|
-
MDCListFoundation.prototype.focusNextElement = function (index) {
|
|
1606
|
-
var count = this.adapter.getListItemCount();
|
|
1607
|
-
var nextIndex = index + 1;
|
|
1608
|
-
if (nextIndex >= count) {
|
|
1609
|
-
if (this.wrapFocus) {
|
|
1610
|
-
nextIndex = 0;
|
|
1611
|
-
}
|
|
1612
|
-
else {
|
|
1613
|
-
// Return early because last item is already focused.
|
|
1614
|
-
return index;
|
|
1615
|
-
}
|
|
1616
|
-
}
|
|
1617
|
-
this.focusItemAtIndex(nextIndex);
|
|
1618
|
-
return nextIndex;
|
|
1619
|
-
};
|
|
1620
|
-
/**
|
|
1621
|
-
* Focuses the previous element on the list.
|
|
1622
|
-
*/
|
|
1623
|
-
MDCListFoundation.prototype.focusPrevElement = function (index) {
|
|
1624
|
-
var prevIndex = index - 1;
|
|
1625
|
-
if (prevIndex < 0) {
|
|
1626
|
-
if (this.wrapFocus) {
|
|
1627
|
-
prevIndex = this.adapter.getListItemCount() - 1;
|
|
1628
|
-
}
|
|
1629
|
-
else {
|
|
1630
|
-
// Return early because first item is already focused.
|
|
1631
|
-
return index;
|
|
1632
|
-
}
|
|
1633
|
-
}
|
|
1634
|
-
this.focusItemAtIndex(prevIndex);
|
|
1635
|
-
return prevIndex;
|
|
1636
|
-
};
|
|
1637
|
-
MDCListFoundation.prototype.focusFirstElement = function () {
|
|
1638
|
-
this.focusItemAtIndex(0);
|
|
1639
|
-
return 0;
|
|
1640
|
-
};
|
|
1641
|
-
MDCListFoundation.prototype.focusLastElement = function () {
|
|
1642
|
-
var lastIndex = this.adapter.getListItemCount() - 1;
|
|
1643
|
-
this.focusItemAtIndex(lastIndex);
|
|
1644
|
-
return lastIndex;
|
|
1645
|
-
};
|
|
1646
|
-
MDCListFoundation.prototype.focusInitialElement = function () {
|
|
1647
|
-
var initialIndex = this.getFirstSelectedOrFocusedItemIndex();
|
|
1648
|
-
this.focusItemAtIndex(initialIndex);
|
|
1649
|
-
return initialIndex;
|
|
1650
|
-
};
|
|
1651
|
-
/**
|
|
1652
|
-
* @param itemIndex Index of the list item
|
|
1653
|
-
* @param isEnabled Sets the list item to enabled or disabled.
|
|
1654
|
-
*/
|
|
1655
|
-
MDCListFoundation.prototype.setEnabled = function (itemIndex, isEnabled) {
|
|
1656
|
-
if (!this.isIndexValid(itemIndex)) {
|
|
1657
|
-
return;
|
|
1658
|
-
}
|
|
1659
|
-
if (isEnabled) {
|
|
1660
|
-
this.adapter.removeClassForElementIndex(itemIndex, cssClasses$2.LIST_ITEM_DISABLED_CLASS);
|
|
1661
|
-
this.adapter.setAttributeForElementIndex(itemIndex, strings$2.ARIA_DISABLED, 'false');
|
|
1662
|
-
}
|
|
1663
|
-
else {
|
|
1664
|
-
this.adapter.addClassForElementIndex(itemIndex, cssClasses$2.LIST_ITEM_DISABLED_CLASS);
|
|
1665
|
-
this.adapter.setAttributeForElementIndex(itemIndex, strings$2.ARIA_DISABLED, 'true');
|
|
1666
|
-
}
|
|
1667
|
-
};
|
|
1668
|
-
MDCListFoundation.prototype.setSingleSelectionAtIndex = function (index, _a) {
|
|
1669
|
-
var _b = _a === void 0 ? {} : _a, forceUpdate = _b.forceUpdate;
|
|
1670
|
-
if (this.selectedIndex === index && !forceUpdate) {
|
|
1671
|
-
return;
|
|
1672
|
-
}
|
|
1673
|
-
var selectedClassName = cssClasses$2.LIST_ITEM_SELECTED_CLASS;
|
|
1674
|
-
if (this.useActivatedClass) {
|
|
1675
|
-
selectedClassName = cssClasses$2.LIST_ITEM_ACTIVATED_CLASS;
|
|
1676
|
-
}
|
|
1677
|
-
if (this.selectedIndex !== numbers$2.UNSET_INDEX) {
|
|
1678
|
-
this.adapter.removeClassForElementIndex(this.selectedIndex, selectedClassName);
|
|
1679
|
-
}
|
|
1680
|
-
this.setAriaForSingleSelectionAtIndex(index);
|
|
1681
|
-
this.setTabindexAtIndex(index);
|
|
1682
|
-
if (index !== numbers$2.UNSET_INDEX) {
|
|
1683
|
-
this.adapter.addClassForElementIndex(index, selectedClassName);
|
|
1684
|
-
}
|
|
1685
|
-
this.selectedIndex = index;
|
|
1686
|
-
};
|
|
1687
|
-
/**
|
|
1688
|
-
* Sets aria attribute for single selection at given index.
|
|
1689
|
-
*/
|
|
1690
|
-
MDCListFoundation.prototype.setAriaForSingleSelectionAtIndex = function (index) {
|
|
1691
|
-
// Detect the presence of aria-current and get the value only during list
|
|
1692
|
-
// initialization when it is in unset state.
|
|
1693
|
-
if (this.selectedIndex === numbers$2.UNSET_INDEX) {
|
|
1694
|
-
this.ariaCurrentAttrValue =
|
|
1695
|
-
this.adapter.getAttributeForElementIndex(index, strings$2.ARIA_CURRENT);
|
|
1696
|
-
}
|
|
1697
|
-
var isAriaCurrent = this.ariaCurrentAttrValue !== null;
|
|
1698
|
-
var ariaAttribute = isAriaCurrent ? strings$2.ARIA_CURRENT : strings$2.ARIA_SELECTED;
|
|
1699
|
-
if (this.selectedIndex !== numbers$2.UNSET_INDEX) {
|
|
1700
|
-
this.adapter.setAttributeForElementIndex(this.selectedIndex, ariaAttribute, 'false');
|
|
1701
|
-
}
|
|
1702
|
-
if (index !== numbers$2.UNSET_INDEX) {
|
|
1703
|
-
var ariaAttributeValue = isAriaCurrent ? this.ariaCurrentAttrValue : 'true';
|
|
1704
|
-
this.adapter.setAttributeForElementIndex(index, ariaAttribute, ariaAttributeValue);
|
|
1705
|
-
}
|
|
1706
|
-
};
|
|
1707
|
-
/**
|
|
1708
|
-
* Returns the attribute to use for indicating selection status.
|
|
1709
|
-
*/
|
|
1710
|
-
MDCListFoundation.prototype.getSelectionAttribute = function () {
|
|
1711
|
-
return this.useSelectedAttr ? strings$2.ARIA_SELECTED : strings$2.ARIA_CHECKED;
|
|
1712
|
-
};
|
|
1713
|
-
/**
|
|
1714
|
-
* Toggles radio at give index. Radio doesn't change the checked state if it
|
|
1715
|
-
* is already checked.
|
|
1716
|
-
*/
|
|
1717
|
-
MDCListFoundation.prototype.setRadioAtIndex = function (index) {
|
|
1718
|
-
var selectionAttribute = this.getSelectionAttribute();
|
|
1719
|
-
this.adapter.setCheckedCheckboxOrRadioAtIndex(index, true);
|
|
1720
|
-
if (this.selectedIndex !== numbers$2.UNSET_INDEX) {
|
|
1721
|
-
this.adapter.setAttributeForElementIndex(this.selectedIndex, selectionAttribute, 'false');
|
|
1722
|
-
}
|
|
1723
|
-
this.adapter.setAttributeForElementIndex(index, selectionAttribute, 'true');
|
|
1724
|
-
this.selectedIndex = index;
|
|
1725
|
-
};
|
|
1726
|
-
MDCListFoundation.prototype.setCheckboxAtIndex = function (index) {
|
|
1727
|
-
var selectionAttribute = this.getSelectionAttribute();
|
|
1728
|
-
for (var i = 0; i < this.adapter.getListItemCount(); i++) {
|
|
1729
|
-
var isChecked = false;
|
|
1730
|
-
if (index.indexOf(i) >= 0) {
|
|
1731
|
-
isChecked = true;
|
|
1732
|
-
}
|
|
1733
|
-
this.adapter.setCheckedCheckboxOrRadioAtIndex(i, isChecked);
|
|
1734
|
-
this.adapter.setAttributeForElementIndex(i, selectionAttribute, isChecked ? 'true' : 'false');
|
|
1735
|
-
}
|
|
1736
|
-
this.selectedIndex = index;
|
|
1737
|
-
};
|
|
1738
|
-
MDCListFoundation.prototype.setTabindexAtIndex = function (index) {
|
|
1739
|
-
if (this.focusedItemIndex === numbers$2.UNSET_INDEX && index !== 0) {
|
|
1740
|
-
// If some list item was selected set first list item's tabindex to -1.
|
|
1741
|
-
// Generally, tabindex is set to 0 on first list item of list that has no
|
|
1742
|
-
// preselected items.
|
|
1743
|
-
this.adapter.setAttributeForElementIndex(0, 'tabindex', '-1');
|
|
1744
|
-
}
|
|
1745
|
-
else if (this.focusedItemIndex >= 0 && this.focusedItemIndex !== index) {
|
|
1746
|
-
this.adapter.setAttributeForElementIndex(this.focusedItemIndex, 'tabindex', '-1');
|
|
1747
|
-
}
|
|
1748
|
-
// Set the previous selection's tabindex to -1. We need this because
|
|
1749
|
-
// in selection menus that are not visible, programmatically setting an
|
|
1750
|
-
// option will not change focus but will change where tabindex should be 0.
|
|
1751
|
-
if (!(this.selectedIndex instanceof Array) &&
|
|
1752
|
-
this.selectedIndex !== index) {
|
|
1753
|
-
this.adapter.setAttributeForElementIndex(this.selectedIndex, 'tabindex', '-1');
|
|
1754
|
-
}
|
|
1755
|
-
if (index !== numbers$2.UNSET_INDEX) {
|
|
1756
|
-
this.adapter.setAttributeForElementIndex(index, 'tabindex', '0');
|
|
1757
|
-
}
|
|
1758
|
-
};
|
|
1759
|
-
/**
|
|
1760
|
-
* @return Return true if it is single selectin list, checkbox list or radio
|
|
1761
|
-
* list.
|
|
1762
|
-
*/
|
|
1763
|
-
MDCListFoundation.prototype.isSelectableList = function () {
|
|
1764
|
-
return this.isSingleSelectionList || this.isCheckboxList ||
|
|
1765
|
-
this.isRadioList;
|
|
1766
|
-
};
|
|
1767
|
-
MDCListFoundation.prototype.setTabindexToFirstSelectedOrFocusedItem = function () {
|
|
1768
|
-
var targetIndex = this.getFirstSelectedOrFocusedItemIndex();
|
|
1769
|
-
this.setTabindexAtIndex(targetIndex);
|
|
1770
|
-
};
|
|
1771
|
-
MDCListFoundation.prototype.getFirstSelectedOrFocusedItemIndex = function () {
|
|
1772
|
-
// Action lists retain focus on the most recently focused item.
|
|
1773
|
-
if (!this.isSelectableList()) {
|
|
1774
|
-
return Math.max(this.focusedItemIndex, 0);
|
|
1775
|
-
}
|
|
1776
|
-
// Single-selection lists focus the selected item.
|
|
1777
|
-
if (typeof this.selectedIndex === 'number' &&
|
|
1778
|
-
this.selectedIndex !== numbers$2.UNSET_INDEX) {
|
|
1779
|
-
return this.selectedIndex;
|
|
1780
|
-
}
|
|
1781
|
-
// Multiple-selection lists focus the first selected item.
|
|
1782
|
-
if (isNumberArray(this.selectedIndex) && this.selectedIndex.length > 0) {
|
|
1783
|
-
return this.selectedIndex.reduce(function (minIndex, currentIndex) { return Math.min(minIndex, currentIndex); });
|
|
1784
|
-
}
|
|
1785
|
-
// Selection lists without a selection focus the first item.
|
|
1786
|
-
return 0;
|
|
1787
|
-
};
|
|
1788
|
-
MDCListFoundation.prototype.isIndexValid = function (index) {
|
|
1789
|
-
var _this = this;
|
|
1790
|
-
if (index instanceof Array) {
|
|
1791
|
-
if (!this.isCheckboxList) {
|
|
1792
|
-
throw new Error('MDCListFoundation: Array of index is only supported for checkbox based list');
|
|
1793
|
-
}
|
|
1794
|
-
if (index.length === 0) {
|
|
1795
|
-
return true;
|
|
1796
|
-
}
|
|
1797
|
-
else {
|
|
1798
|
-
return index.some(function (i) { return _this.isIndexInRange(i); });
|
|
1799
|
-
}
|
|
1800
|
-
}
|
|
1801
|
-
else if (typeof index === 'number') {
|
|
1802
|
-
if (this.isCheckboxList) {
|
|
1803
|
-
throw new Error("MDCListFoundation: Expected array of index for checkbox based list but got number: " + index);
|
|
1804
|
-
}
|
|
1805
|
-
return this.isIndexInRange(index) ||
|
|
1806
|
-
this.isSingleSelectionList && index === numbers$2.UNSET_INDEX;
|
|
1807
|
-
}
|
|
1808
|
-
else {
|
|
1809
|
-
return false;
|
|
1810
|
-
}
|
|
1811
|
-
};
|
|
1812
|
-
MDCListFoundation.prototype.isIndexInRange = function (index) {
|
|
1813
|
-
var listSize = this.adapter.getListItemCount();
|
|
1814
|
-
return index >= 0 && index < listSize;
|
|
1815
|
-
};
|
|
1816
|
-
/**
|
|
1817
|
-
* Sets selected index on user action, toggles checkbox / radio based on
|
|
1818
|
-
* toggleCheckbox value. User interaction should not toggle list item(s) when
|
|
1819
|
-
* disabled.
|
|
1820
|
-
*/
|
|
1821
|
-
MDCListFoundation.prototype.setSelectedIndexOnAction = function (index, toggleCheckbox) {
|
|
1822
|
-
if (toggleCheckbox === void 0) { toggleCheckbox = true; }
|
|
1823
|
-
if (this.isCheckboxList) {
|
|
1824
|
-
this.toggleCheckboxAtIndex(index, toggleCheckbox);
|
|
1825
|
-
}
|
|
1826
|
-
else {
|
|
1827
|
-
this.setSelectedIndex(index);
|
|
1828
|
-
}
|
|
1829
|
-
};
|
|
1830
|
-
MDCListFoundation.prototype.toggleCheckboxAtIndex = function (index, toggleCheckbox) {
|
|
1831
|
-
var selectionAttribute = this.getSelectionAttribute();
|
|
1832
|
-
var isChecked = this.adapter.isCheckboxCheckedAtIndex(index);
|
|
1833
|
-
if (toggleCheckbox) {
|
|
1834
|
-
isChecked = !isChecked;
|
|
1835
|
-
this.adapter.setCheckedCheckboxOrRadioAtIndex(index, isChecked);
|
|
1836
|
-
}
|
|
1837
|
-
this.adapter.setAttributeForElementIndex(index, selectionAttribute, isChecked ? 'true' : 'false');
|
|
1838
|
-
// If none of the checkbox items are selected and selectedIndex is not
|
|
1839
|
-
// initialized then provide a default value.
|
|
1840
|
-
var selectedIndexes = this.selectedIndex === numbers$2.UNSET_INDEX ?
|
|
1841
|
-
[] :
|
|
1842
|
-
this.selectedIndex.slice();
|
|
1843
|
-
if (isChecked) {
|
|
1844
|
-
selectedIndexes.push(index);
|
|
1845
|
-
}
|
|
1846
|
-
else {
|
|
1847
|
-
selectedIndexes = selectedIndexes.filter(function (i) { return i !== index; });
|
|
1848
|
-
}
|
|
1849
|
-
this.selectedIndex = selectedIndexes;
|
|
1850
|
-
};
|
|
1851
|
-
MDCListFoundation.prototype.focusItemAtIndex = function (index) {
|
|
1852
|
-
this.adapter.focusItemAtIndex(index);
|
|
1853
|
-
this.focusedItemIndex = index;
|
|
1854
|
-
};
|
|
1855
|
-
MDCListFoundation.prototype.toggleAll = function (currentlySelectedIndexes) {
|
|
1856
|
-
var count = this.adapter.getListItemCount();
|
|
1857
|
-
// If all items are selected, deselect everything.
|
|
1858
|
-
if (currentlySelectedIndexes.length === count) {
|
|
1859
|
-
this.setCheckboxAtIndex([]);
|
|
1860
|
-
}
|
|
1861
|
-
else {
|
|
1862
|
-
// Otherwise select all enabled options.
|
|
1863
|
-
var allIndexes = [];
|
|
1864
|
-
for (var i = 0; i < count; i++) {
|
|
1865
|
-
if (!this.adapter.listItemAtIndexHasClass(i, cssClasses$2.LIST_ITEM_DISABLED_CLASS) ||
|
|
1866
|
-
currentlySelectedIndexes.indexOf(i) > -1) {
|
|
1867
|
-
allIndexes.push(i);
|
|
1868
|
-
}
|
|
1869
|
-
}
|
|
1870
|
-
this.setCheckboxAtIndex(allIndexes);
|
|
1871
|
-
}
|
|
1872
|
-
};
|
|
1873
|
-
/**
|
|
1874
|
-
* Given the next desired character from the user, adds it to the typeahead
|
|
1875
|
-
* buffer. Then, attempts to find the next option matching the buffer. Wraps
|
|
1876
|
-
* around if at the end of options.
|
|
1877
|
-
*
|
|
1878
|
-
* @param nextChar The next character to add to the prefix buffer.
|
|
1879
|
-
* @param startingIndex The index from which to start matching. Only relevant
|
|
1880
|
-
* when starting a new match sequence. To start a new match sequence,
|
|
1881
|
-
* clear the buffer using `clearTypeaheadBuffer`, or wait for the buffer
|
|
1882
|
-
* to clear after a set interval defined in list foundation. Defaults to
|
|
1883
|
-
* the currently focused index.
|
|
1884
|
-
* @return The index of the matched item, or -1 if no match.
|
|
1885
|
-
*/
|
|
1886
|
-
MDCListFoundation.prototype.typeaheadMatchItem = function (nextChar, startingIndex, skipFocus) {
|
|
1887
|
-
var _this = this;
|
|
1888
|
-
if (skipFocus === void 0) { skipFocus = false; }
|
|
1889
|
-
var opts = {
|
|
1890
|
-
focusItemAtIndex: function (index) {
|
|
1891
|
-
_this.focusItemAtIndex(index);
|
|
1892
|
-
},
|
|
1893
|
-
focusedItemIndex: startingIndex ? startingIndex : this.focusedItemIndex,
|
|
1894
|
-
nextChar: nextChar,
|
|
1895
|
-
sortedIndexByFirstChar: this.sortedIndexByFirstChar,
|
|
1896
|
-
skipFocus: skipFocus,
|
|
1897
|
-
isItemAtIndexDisabled: function (index) { return _this.adapter.listItemAtIndexHasClass(index, cssClasses$2.LIST_ITEM_DISABLED_CLASS); }
|
|
1898
|
-
};
|
|
1899
|
-
return matchItem(opts, this.typeaheadState);
|
|
1900
|
-
};
|
|
1901
|
-
/**
|
|
1902
|
-
* Initializes the MDCListTextAndIndex data structure by indexing the current
|
|
1903
|
-
* list items by primary text.
|
|
1904
|
-
*
|
|
1905
|
-
* @return The primary texts of all the list items sorted by first character.
|
|
1906
|
-
*/
|
|
1907
|
-
MDCListFoundation.prototype.typeaheadInitSortedIndex = function () {
|
|
1908
|
-
return initSortedIndex(this.adapter.getListItemCount(), this.adapter.getPrimaryTextAtIndex);
|
|
1909
|
-
};
|
|
1910
|
-
/**
|
|
1911
|
-
* Clears the typeahead buffer.
|
|
1912
|
-
*/
|
|
1913
|
-
MDCListFoundation.prototype.clearTypeaheadBuffer = function () {
|
|
1914
|
-
clearBuffer(this.typeaheadState);
|
|
1915
|
-
};
|
|
1916
|
-
return MDCListFoundation;
|
|
1917
|
-
}(ponyfill.MDCFoundation));
|
|
1918
|
-
|
|
1919
|
-
/**
|
|
1920
|
-
* @license
|
|
1921
|
-
* Copyright 2018 Google Inc.
|
|
1922
|
-
*
|
|
1923
|
-
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
1924
|
-
* of this software and associated documentation files (the "Software"), to deal
|
|
1925
|
-
* in the Software without restriction, including without limitation the rights
|
|
1926
|
-
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
1927
|
-
* copies of the Software, and to permit persons to whom the Software is
|
|
1928
|
-
* furnished to do so, subject to the following conditions:
|
|
1929
|
-
*
|
|
1930
|
-
* The above copyright notice and this permission notice shall be included in
|
|
1931
|
-
* all copies or substantial portions of the Software.
|
|
1932
|
-
*
|
|
1933
|
-
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
1934
|
-
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
1935
|
-
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
1936
|
-
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
1937
|
-
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
1938
|
-
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
1939
|
-
* THE SOFTWARE.
|
|
1940
|
-
*/
|
|
1941
|
-
var MDCList = /** @class */ (function (_super) {
|
|
1942
|
-
ponyfill.__extends(MDCList, _super);
|
|
1943
|
-
function MDCList() {
|
|
1944
|
-
return _super !== null && _super.apply(this, arguments) || this;
|
|
1945
|
-
}
|
|
1946
|
-
Object.defineProperty(MDCList.prototype, "vertical", {
|
|
1947
|
-
set: function (value) {
|
|
1948
|
-
this.foundation.setVerticalOrientation(value);
|
|
1949
|
-
},
|
|
1950
|
-
enumerable: false,
|
|
1951
|
-
configurable: true
|
|
1952
|
-
});
|
|
1953
|
-
Object.defineProperty(MDCList.prototype, "listElements", {
|
|
1954
|
-
get: function () {
|
|
1955
|
-
return Array.from(this.root.querySelectorAll("." + this.classNameMap[cssClasses$2.LIST_ITEM_CLASS]));
|
|
1956
|
-
},
|
|
1957
|
-
enumerable: false,
|
|
1958
|
-
configurable: true
|
|
1959
|
-
});
|
|
1960
|
-
Object.defineProperty(MDCList.prototype, "wrapFocus", {
|
|
1961
|
-
set: function (value) {
|
|
1962
|
-
this.foundation.setWrapFocus(value);
|
|
1963
|
-
},
|
|
1964
|
-
enumerable: false,
|
|
1965
|
-
configurable: true
|
|
1966
|
-
});
|
|
1967
|
-
Object.defineProperty(MDCList.prototype, "typeaheadInProgress", {
|
|
1968
|
-
/**
|
|
1969
|
-
* @return Whether typeahead is currently matching a user-specified prefix.
|
|
1970
|
-
*/
|
|
1971
|
-
get: function () {
|
|
1972
|
-
return this.foundation.isTypeaheadInProgress();
|
|
1973
|
-
},
|
|
1974
|
-
enumerable: false,
|
|
1975
|
-
configurable: true
|
|
1976
|
-
});
|
|
1977
|
-
Object.defineProperty(MDCList.prototype, "hasTypeahead", {
|
|
1978
|
-
/**
|
|
1979
|
-
* Sets whether typeahead functionality is enabled on the list.
|
|
1980
|
-
* @param hasTypeahead Whether typeahead is enabled.
|
|
1981
|
-
*/
|
|
1982
|
-
set: function (hasTypeahead) {
|
|
1983
|
-
this.foundation.setHasTypeahead(hasTypeahead);
|
|
1984
|
-
},
|
|
1985
|
-
enumerable: false,
|
|
1986
|
-
configurable: true
|
|
1987
|
-
});
|
|
1988
|
-
Object.defineProperty(MDCList.prototype, "singleSelection", {
|
|
1989
|
-
set: function (isSingleSelectionList) {
|
|
1990
|
-
this.foundation.setSingleSelection(isSingleSelectionList);
|
|
1991
|
-
},
|
|
1992
|
-
enumerable: false,
|
|
1993
|
-
configurable: true
|
|
1994
|
-
});
|
|
1995
|
-
Object.defineProperty(MDCList.prototype, "selectedIndex", {
|
|
1996
|
-
get: function () {
|
|
1997
|
-
return this.foundation.getSelectedIndex();
|
|
1998
|
-
},
|
|
1999
|
-
set: function (index) {
|
|
2000
|
-
this.foundation.setSelectedIndex(index);
|
|
2001
|
-
},
|
|
2002
|
-
enumerable: false,
|
|
2003
|
-
configurable: true
|
|
2004
|
-
});
|
|
2005
|
-
MDCList.attachTo = function (root) {
|
|
2006
|
-
return new MDCList(root);
|
|
2007
|
-
};
|
|
2008
|
-
MDCList.prototype.initialSyncWithDOM = function () {
|
|
2009
|
-
this.isEvolutionEnabled =
|
|
2010
|
-
evolutionAttribute in this.root.dataset;
|
|
2011
|
-
if (this.isEvolutionEnabled) {
|
|
2012
|
-
this.classNameMap = evolutionClassNameMap;
|
|
2013
|
-
}
|
|
2014
|
-
else if (ponyfill.matches(this.root, strings$2.DEPRECATED_SELECTOR)) {
|
|
2015
|
-
this.classNameMap = deprecatedClassNameMap;
|
|
2016
|
-
}
|
|
2017
|
-
else {
|
|
2018
|
-
this.classNameMap =
|
|
2019
|
-
Object.values(cssClasses$2)
|
|
2020
|
-
.reduce(function (obj, className) {
|
|
2021
|
-
obj[className] = className;
|
|
2022
|
-
return obj;
|
|
2023
|
-
}, {});
|
|
2024
|
-
}
|
|
2025
|
-
this.handleClick = this.handleClickEvent.bind(this);
|
|
2026
|
-
this.handleKeydown = this.handleKeydownEvent.bind(this);
|
|
2027
|
-
this.focusInEventListener = this.handleFocusInEvent.bind(this);
|
|
2028
|
-
this.focusOutEventListener = this.handleFocusOutEvent.bind(this);
|
|
2029
|
-
this.listen('keydown', this.handleKeydown);
|
|
2030
|
-
this.listen('click', this.handleClick);
|
|
2031
|
-
this.listen('focusin', this.focusInEventListener);
|
|
2032
|
-
this.listen('focusout', this.focusOutEventListener);
|
|
2033
|
-
this.layout();
|
|
2034
|
-
this.initializeListType();
|
|
2035
|
-
this.ensureFocusable();
|
|
2036
|
-
};
|
|
2037
|
-
MDCList.prototype.destroy = function () {
|
|
2038
|
-
this.unlisten('keydown', this.handleKeydown);
|
|
2039
|
-
this.unlisten('click', this.handleClick);
|
|
2040
|
-
this.unlisten('focusin', this.focusInEventListener);
|
|
2041
|
-
this.unlisten('focusout', this.focusOutEventListener);
|
|
2042
|
-
};
|
|
2043
|
-
MDCList.prototype.layout = function () {
|
|
2044
|
-
var direction = this.root.getAttribute(strings$2.ARIA_ORIENTATION);
|
|
2045
|
-
this.vertical = direction !== strings$2.ARIA_ORIENTATION_HORIZONTAL;
|
|
2046
|
-
var itemSelector = "." + this.classNameMap[cssClasses$2.LIST_ITEM_CLASS] + ":not([tabindex])";
|
|
2047
|
-
var childSelector = strings$2.FOCUSABLE_CHILD_ELEMENTS;
|
|
2048
|
-
// List items need to have at least tabindex=-1 to be focusable.
|
|
2049
|
-
var itemEls = this.root.querySelectorAll(itemSelector);
|
|
2050
|
-
if (itemEls.length) {
|
|
2051
|
-
Array.prototype.forEach.call(itemEls, function (el) {
|
|
2052
|
-
el.setAttribute('tabindex', '-1');
|
|
2053
|
-
});
|
|
2054
|
-
}
|
|
2055
|
-
// Child button/a elements are not tabbable until the list item is focused.
|
|
2056
|
-
var focusableChildEls = this.root.querySelectorAll(childSelector);
|
|
2057
|
-
if (focusableChildEls.length) {
|
|
2058
|
-
Array.prototype.forEach.call(focusableChildEls, function (el) {
|
|
2059
|
-
el.setAttribute('tabindex', '-1');
|
|
2060
|
-
});
|
|
2061
|
-
}
|
|
2062
|
-
if (this.isEvolutionEnabled) {
|
|
2063
|
-
this.foundation.setUseSelectedAttribute(true);
|
|
2064
|
-
}
|
|
2065
|
-
this.foundation.layout();
|
|
2066
|
-
};
|
|
2067
|
-
/**
|
|
2068
|
-
* Extracts the primary text from a list item.
|
|
2069
|
-
* @param item The list item element.
|
|
2070
|
-
* @return The primary text in the element.
|
|
2071
|
-
*/
|
|
2072
|
-
MDCList.prototype.getPrimaryText = function (item) {
|
|
2073
|
-
var _a;
|
|
2074
|
-
var primaryText = item.querySelector("." + this.classNameMap[cssClasses$2.LIST_ITEM_PRIMARY_TEXT_CLASS]);
|
|
2075
|
-
if (this.isEvolutionEnabled || primaryText) {
|
|
2076
|
-
return (_a = primaryText === null || primaryText === void 0 ? void 0 : primaryText.textContent) !== null && _a !== void 0 ? _a : '';
|
|
2077
|
-
}
|
|
2078
|
-
var singleLineText = item.querySelector("." + this.classNameMap[cssClasses$2.LIST_ITEM_TEXT_CLASS]);
|
|
2079
|
-
return (singleLineText && singleLineText.textContent) || '';
|
|
2080
|
-
};
|
|
2081
|
-
/**
|
|
2082
|
-
* Initialize selectedIndex value based on pre-selected list items.
|
|
2083
|
-
*/
|
|
2084
|
-
MDCList.prototype.initializeListType = function () {
|
|
2085
|
-
var _this = this;
|
|
2086
|
-
this.isInteractive =
|
|
2087
|
-
ponyfill.matches(this.root, strings$2.ARIA_INTERACTIVE_ROLES_SELECTOR);
|
|
2088
|
-
if (this.isEvolutionEnabled && this.isInteractive) {
|
|
2089
|
-
var selection = Array.from(this.root.querySelectorAll(strings$2.SELECTED_ITEM_SELECTOR), function (listItem) { return _this.listElements.indexOf(listItem); });
|
|
2090
|
-
if (ponyfill.matches(this.root, strings$2.ARIA_MULTI_SELECTABLE_SELECTOR)) {
|
|
2091
|
-
this.selectedIndex = selection;
|
|
2092
|
-
}
|
|
2093
|
-
else if (selection.length > 0) {
|
|
2094
|
-
this.selectedIndex = selection[0];
|
|
2095
|
-
}
|
|
2096
|
-
return;
|
|
2097
|
-
}
|
|
2098
|
-
var checkboxListItems = this.root.querySelectorAll(strings$2.ARIA_ROLE_CHECKBOX_SELECTOR);
|
|
2099
|
-
var radioSelectedListItem = this.root.querySelector(strings$2.ARIA_CHECKED_RADIO_SELECTOR);
|
|
2100
|
-
if (checkboxListItems.length) {
|
|
2101
|
-
var preselectedItems = this.root.querySelectorAll(strings$2.ARIA_CHECKED_CHECKBOX_SELECTOR);
|
|
2102
|
-
this.selectedIndex = Array.from(preselectedItems, function (listItem) { return _this.listElements.indexOf(listItem); });
|
|
2103
|
-
}
|
|
2104
|
-
else if (radioSelectedListItem) {
|
|
2105
|
-
this.selectedIndex = this.listElements.indexOf(radioSelectedListItem);
|
|
2106
|
-
}
|
|
2107
|
-
};
|
|
2108
|
-
/**
|
|
2109
|
-
* Updates the list item at itemIndex to the desired isEnabled state.
|
|
2110
|
-
* @param itemIndex Index of the list item
|
|
2111
|
-
* @param isEnabled Sets the list item to enabled or disabled.
|
|
2112
|
-
*/
|
|
2113
|
-
MDCList.prototype.setEnabled = function (itemIndex, isEnabled) {
|
|
2114
|
-
this.foundation.setEnabled(itemIndex, isEnabled);
|
|
2115
|
-
};
|
|
2116
|
-
/**
|
|
2117
|
-
* Given the next desired character from the user, adds it to the typeahead
|
|
2118
|
-
* buffer. Then, attempts to find the next option matching the buffer. Wraps
|
|
2119
|
-
* around if at the end of options.
|
|
2120
|
-
*
|
|
2121
|
-
* @param nextChar The next character to add to the prefix buffer.
|
|
2122
|
-
* @param startingIndex The index from which to start matching. Defaults to
|
|
2123
|
-
* the currently focused index.
|
|
2124
|
-
* @return The index of the matched item.
|
|
2125
|
-
*/
|
|
2126
|
-
MDCList.prototype.typeaheadMatchItem = function (nextChar, startingIndex) {
|
|
2127
|
-
return this.foundation.typeaheadMatchItem(nextChar, startingIndex, /** skipFocus */ true);
|
|
2128
|
-
};
|
|
2129
|
-
MDCList.prototype.getDefaultFoundation = function () {
|
|
2130
|
-
var _this = this;
|
|
2131
|
-
// DO NOT INLINE this variable. For backward compatibility, foundations take
|
|
2132
|
-
// a Partial<MDCFooAdapter>. To ensure we don't accidentally omit any
|
|
2133
|
-
// methods, we need a separate, strongly typed adapter variable.
|
|
2134
|
-
var adapter = {
|
|
2135
|
-
addClassForElementIndex: function (index, className) {
|
|
2136
|
-
var element = _this.listElements[index];
|
|
2137
|
-
if (element) {
|
|
2138
|
-
element.classList.add(_this.classNameMap[className]);
|
|
2139
|
-
}
|
|
2140
|
-
},
|
|
2141
|
-
focusItemAtIndex: function (index) {
|
|
2142
|
-
var element = _this.listElements[index];
|
|
2143
|
-
if (element) {
|
|
2144
|
-
element.focus();
|
|
2145
|
-
}
|
|
2146
|
-
},
|
|
2147
|
-
getAttributeForElementIndex: function (index, attr) {
|
|
2148
|
-
return _this.listElements[index].getAttribute(attr);
|
|
2149
|
-
},
|
|
2150
|
-
getFocusedElementIndex: function () {
|
|
2151
|
-
return _this.listElements.indexOf(document.activeElement);
|
|
2152
|
-
},
|
|
2153
|
-
getListItemCount: function () { return _this.listElements.length; },
|
|
2154
|
-
getPrimaryTextAtIndex: function (index) {
|
|
2155
|
-
return _this.getPrimaryText(_this.listElements[index]);
|
|
2156
|
-
},
|
|
2157
|
-
hasCheckboxAtIndex: function (index) {
|
|
2158
|
-
var listItem = _this.listElements[index];
|
|
2159
|
-
return !!listItem.querySelector(strings$2.CHECKBOX_SELECTOR);
|
|
2160
|
-
},
|
|
2161
|
-
hasRadioAtIndex: function (index) {
|
|
2162
|
-
var listItem = _this.listElements[index];
|
|
2163
|
-
return !!listItem.querySelector(strings$2.RADIO_SELECTOR);
|
|
2164
|
-
},
|
|
2165
|
-
isCheckboxCheckedAtIndex: function (index) {
|
|
2166
|
-
var listItem = _this.listElements[index];
|
|
2167
|
-
var toggleEl = listItem.querySelector(strings$2.CHECKBOX_SELECTOR);
|
|
2168
|
-
return toggleEl.checked;
|
|
2169
|
-
},
|
|
2170
|
-
isFocusInsideList: function () {
|
|
2171
|
-
return _this.root !== document.activeElement &&
|
|
2172
|
-
_this.root.contains(document.activeElement);
|
|
2173
|
-
},
|
|
2174
|
-
isRootFocused: function () { return document.activeElement === _this.root; },
|
|
2175
|
-
listItemAtIndexHasClass: function (index, className) {
|
|
2176
|
-
return _this.listElements[index].classList.contains(_this.classNameMap[className]);
|
|
2177
|
-
},
|
|
2178
|
-
notifyAction: function (index) {
|
|
2179
|
-
_this.emit(strings$2.ACTION_EVENT, { index: index }, /** shouldBubble */ true);
|
|
2180
|
-
},
|
|
2181
|
-
removeClassForElementIndex: function (index, className) {
|
|
2182
|
-
var element = _this.listElements[index];
|
|
2183
|
-
if (element) {
|
|
2184
|
-
element.classList.remove(_this.classNameMap[className]);
|
|
2185
|
-
}
|
|
2186
|
-
},
|
|
2187
|
-
setAttributeForElementIndex: function (index, attr, value) {
|
|
2188
|
-
var element = _this.listElements[index];
|
|
2189
|
-
if (element) {
|
|
2190
|
-
element.setAttribute(attr, value);
|
|
2191
|
-
}
|
|
2192
|
-
},
|
|
2193
|
-
setCheckedCheckboxOrRadioAtIndex: function (index, isChecked) {
|
|
2194
|
-
var listItem = _this.listElements[index];
|
|
2195
|
-
var toggleEl = listItem.querySelector(strings$2.CHECKBOX_RADIO_SELECTOR);
|
|
2196
|
-
toggleEl.checked = isChecked;
|
|
2197
|
-
var event = document.createEvent('Event');
|
|
2198
|
-
event.initEvent('change', true, true);
|
|
2199
|
-
toggleEl.dispatchEvent(event);
|
|
2200
|
-
},
|
|
2201
|
-
setTabIndexForListItemChildren: function (listItemIndex, tabIndexValue) {
|
|
2202
|
-
var element = _this.listElements[listItemIndex];
|
|
2203
|
-
var selector = strings$2.CHILD_ELEMENTS_TO_TOGGLE_TABINDEX;
|
|
2204
|
-
Array.prototype.forEach.call(element.querySelectorAll(selector), function (el) {
|
|
2205
|
-
el.setAttribute('tabindex', tabIndexValue);
|
|
2206
|
-
});
|
|
2207
|
-
},
|
|
2208
|
-
};
|
|
2209
|
-
return new MDCListFoundation(adapter);
|
|
2210
|
-
};
|
|
2211
|
-
/**
|
|
2212
|
-
* Ensures that at least one item is focusable if the list is interactive and
|
|
2213
|
-
* doesn't specify a suitable tabindex.
|
|
2214
|
-
*/
|
|
2215
|
-
MDCList.prototype.ensureFocusable = function () {
|
|
2216
|
-
if (this.isEvolutionEnabled && this.isInteractive) {
|
|
2217
|
-
if (!this.root.querySelector("." + this.classNameMap[cssClasses$2.LIST_ITEM_CLASS] + "[tabindex=\"0\"]")) {
|
|
2218
|
-
var index = this.initialFocusIndex();
|
|
2219
|
-
if (index !== -1) {
|
|
2220
|
-
this.listElements[index].tabIndex = 0;
|
|
2221
|
-
}
|
|
2222
|
-
}
|
|
2223
|
-
}
|
|
2224
|
-
};
|
|
2225
|
-
MDCList.prototype.initialFocusIndex = function () {
|
|
2226
|
-
if (this.selectedIndex instanceof Array && this.selectedIndex.length > 0) {
|
|
2227
|
-
return this.selectedIndex[0];
|
|
2228
|
-
}
|
|
2229
|
-
if (typeof this.selectedIndex === 'number' &&
|
|
2230
|
-
this.selectedIndex !== numbers$2.UNSET_INDEX) {
|
|
2231
|
-
return this.selectedIndex;
|
|
2232
|
-
}
|
|
2233
|
-
var el = this.root.querySelector("." + this.classNameMap[cssClasses$2.LIST_ITEM_CLASS] + ":not(." + this.classNameMap[cssClasses$2.LIST_ITEM_DISABLED_CLASS] + ")");
|
|
2234
|
-
if (el === null) {
|
|
2235
|
-
return -1;
|
|
2236
|
-
}
|
|
2237
|
-
return this.getListItemIndex(el);
|
|
2238
|
-
};
|
|
2239
|
-
/**
|
|
2240
|
-
* Used to figure out which list item this event is targetting. Or returns -1
|
|
2241
|
-
* if there is no list item
|
|
2242
|
-
*/
|
|
2243
|
-
MDCList.prototype.getListItemIndex = function (el) {
|
|
2244
|
-
var nearestParent = ponyfill.closest(el, "." + this.classNameMap[cssClasses$2.LIST_ITEM_CLASS] + ", ." + this.classNameMap[cssClasses$2.ROOT]);
|
|
2245
|
-
// Get the index of the element if it is a list item.
|
|
2246
|
-
if (nearestParent &&
|
|
2247
|
-
ponyfill.matches(nearestParent, "." + this.classNameMap[cssClasses$2.LIST_ITEM_CLASS])) {
|
|
2248
|
-
return this.listElements.indexOf(nearestParent);
|
|
2249
|
-
}
|
|
2250
|
-
return -1;
|
|
2251
|
-
};
|
|
2252
|
-
/**
|
|
2253
|
-
* Used to figure out which element was clicked before sending the event to
|
|
2254
|
-
* the foundation.
|
|
2255
|
-
*/
|
|
2256
|
-
MDCList.prototype.handleFocusInEvent = function (evt) {
|
|
2257
|
-
var index = this.getListItemIndex(evt.target);
|
|
2258
|
-
this.foundation.handleFocusIn(index);
|
|
2259
|
-
};
|
|
2260
|
-
/**
|
|
2261
|
-
* Used to figure out which element was clicked before sending the event to
|
|
2262
|
-
* the foundation.
|
|
2263
|
-
*/
|
|
2264
|
-
MDCList.prototype.handleFocusOutEvent = function (evt) {
|
|
2265
|
-
var index = this.getListItemIndex(evt.target);
|
|
2266
|
-
this.foundation.handleFocusOut(index);
|
|
2267
|
-
};
|
|
2268
|
-
/**
|
|
2269
|
-
* Used to figure out which element was focused when keydown event occurred
|
|
2270
|
-
* before sending the event to the foundation.
|
|
2271
|
-
*/
|
|
2272
|
-
MDCList.prototype.handleKeydownEvent = function (evt) {
|
|
2273
|
-
var index = this.getListItemIndex(evt.target);
|
|
2274
|
-
var target = evt.target;
|
|
2275
|
-
this.foundation.handleKeydown(evt, target.classList.contains(this.classNameMap[cssClasses$2.LIST_ITEM_CLASS]), index);
|
|
2276
|
-
};
|
|
2277
|
-
/**
|
|
2278
|
-
* Used to figure out which element was clicked before sending the event to
|
|
2279
|
-
* the foundation.
|
|
2280
|
-
*/
|
|
2281
|
-
MDCList.prototype.handleClickEvent = function (evt) {
|
|
2282
|
-
var index = this.getListItemIndex(evt.target);
|
|
2283
|
-
var target = evt.target;
|
|
2284
|
-
// Toggle the checkbox only if it's not the target of the event, or the
|
|
2285
|
-
// checkbox will have 2 change events.
|
|
2286
|
-
var toggleCheckbox = !ponyfill.matches(target, strings$2.CHECKBOX_RADIO_SELECTOR);
|
|
2287
|
-
this.foundation.handleClick(index, toggleCheckbox);
|
|
2288
|
-
};
|
|
2289
|
-
return MDCList;
|
|
2290
|
-
}(ponyfill.MDCComponent));
|
|
2291
|
-
|
|
2292
|
-
class ListRenderer {
|
|
2293
|
-
constructor() {
|
|
2294
|
-
this.defaultConfig = {
|
|
2295
|
-
isOpen: true,
|
|
2296
|
-
badgeIcons: false,
|
|
2297
|
-
};
|
|
2298
|
-
/**
|
|
2299
|
-
* `aria-orientation` is valid for `listbox` and `radiogroup`,
|
|
2300
|
-
* but not for group (used for checkboxes).
|
|
2301
|
-
* @param role
|
|
2302
|
-
*/
|
|
2303
|
-
this.getAriaOrientation = (role) => {
|
|
2304
|
-
if (role === 'listbox' || role === 'radiogroup') {
|
|
2305
|
-
return 'vertical';
|
|
2306
|
-
}
|
|
2307
|
-
else {
|
|
2308
|
-
return null;
|
|
2309
|
-
}
|
|
2310
|
-
};
|
|
2311
|
-
/**
|
|
2312
|
-
* Determine which ListItem should have the `tab-index` attribute set,
|
|
2313
|
-
* and return the index at which that ListItem is located in `items`.
|
|
2314
|
-
* Returns `undefined` if no item should have the attribute set.
|
|
2315
|
-
* See https://github.com/material-components/material-components-web/tree/e66a43a75fef4f9179e24856649518e15e279a04/packages/mdc-list#accessibility
|
|
2316
|
-
*
|
|
2317
|
-
* @param items - the items of the list, including any `ListSeparator`:s
|
|
2318
|
-
* @returns the index as per the description
|
|
2319
|
-
*/
|
|
2320
|
-
this.getIndexForWhichToApplyTabIndex = (items) => {
|
|
2321
|
-
let result;
|
|
2322
|
-
for (let i = 0, max = items.length; i < max; i += 1) {
|
|
2323
|
-
if ('separator' in items[i]) ;
|
|
2324
|
-
else {
|
|
2325
|
-
const item = items[i];
|
|
2326
|
-
if (item.disabled) {
|
|
2327
|
-
// Skip disabled items - they should never get tabindex
|
|
2328
|
-
continue;
|
|
2329
|
-
}
|
|
2330
|
-
if (item.selected) {
|
|
2331
|
-
result = i;
|
|
2332
|
-
break;
|
|
2333
|
-
}
|
|
2334
|
-
if (result === undefined) {
|
|
2335
|
-
result = i;
|
|
2336
|
-
// Do NOT break, as any later item with
|
|
2337
|
-
// `selected=true` should get the tab-index instead!
|
|
2338
|
-
}
|
|
2339
|
-
}
|
|
2340
|
-
}
|
|
2341
|
-
return result;
|
|
2342
|
-
};
|
|
2343
|
-
/**
|
|
2344
|
-
* Render a single list item
|
|
2345
|
-
*
|
|
2346
|
-
* @param item - the item to render
|
|
2347
|
-
* @param index - the index the item had in the `items` array
|
|
2348
|
-
* @returns the list item
|
|
2349
|
-
*/
|
|
2350
|
-
this.renderListItem = (item, index$1) => {
|
|
2351
|
-
var _a;
|
|
2352
|
-
if ('separator' in item) {
|
|
2353
|
-
return (index.h("li", { class: "mdc-deprecated-list-divider", role: "separator", key: `sep-${index$1}` }, this.renderTextForSeparator(item), index.h("div", { class: "limel-list-divider-line" })));
|
|
2354
|
-
}
|
|
2355
|
-
const attributes = {};
|
|
2356
|
-
if (index$1 === this.applyTabIndexToItemAtIndex) {
|
|
2357
|
-
attributes.tabindex = '0';
|
|
2358
|
-
}
|
|
2359
|
-
let itemType;
|
|
2360
|
-
if (this.config.type === 'radio' || this.config.type === 'checkbox') {
|
|
2361
|
-
itemType = this.config.type;
|
|
2362
|
-
}
|
|
2363
|
-
else if (this.config.type === 'selectable') {
|
|
2364
|
-
itemType = 'option';
|
|
2365
|
-
}
|
|
2366
|
-
else {
|
|
2367
|
-
itemType = 'listitem';
|
|
2368
|
-
}
|
|
2369
|
-
const key = (_a = item.id) !== null && _a !== void 0 ? _a : `item-${index$1}`;
|
|
2370
|
-
const classNames = {
|
|
2371
|
-
'mdc-deprecated-list-item': true, // required for keyboard navigation with arrow keys
|
|
2372
|
-
'mdc-deprecated-list-item--disabled': !!item.disabled, // MDC’s foundation checks for the disabled class before toggling selected state
|
|
2373
|
-
};
|
|
2374
|
-
return (index.h("limel-list-item", Object.assign({ key: key, class: classNames }, attributes, { "data-index": index$1, type: itemType, text: item.text, secondaryText: item.secondaryText, icon: item.icon, image: item.image, primaryComponent: item.primaryComponent, badgeIcon: this.config.badgeIcons, iconSize: this.config.iconSize, selected: item.selected, disabled: item.disabled, actions: item.actions })));
|
|
2375
|
-
};
|
|
2376
|
-
this.renderTextForSeparator = (item) => {
|
|
2377
|
-
if ('text' in item) {
|
|
2378
|
-
return index.h("h2", { class: "limel-list-divider-title" }, item.text);
|
|
2379
|
-
}
|
|
2380
|
-
};
|
|
2381
|
-
}
|
|
2382
|
-
render(items, config = {}) {
|
|
2383
|
-
items = items || [];
|
|
2384
|
-
this.config = Object.assign(Object.assign({}, this.defaultConfig), config);
|
|
2385
|
-
let role;
|
|
2386
|
-
switch (this.config.type) {
|
|
2387
|
-
case 'checkbox': {
|
|
2388
|
-
role = 'group';
|
|
2389
|
-
break;
|
|
2390
|
-
}
|
|
2391
|
-
case 'radio': {
|
|
2392
|
-
role = 'radiogroup';
|
|
2393
|
-
break;
|
|
2394
|
-
}
|
|
2395
|
-
default: {
|
|
2396
|
-
role = 'listbox';
|
|
2397
|
-
}
|
|
2398
|
-
}
|
|
2399
|
-
this.applyTabIndexToItemAtIndex =
|
|
2400
|
-
this.getIndexForWhichToApplyTabIndex(items);
|
|
2401
|
-
return (index.h("ul", { class: "mdc-deprecated-list", role: role, "aria-orientation": this.getAriaOrientation(role) }, items.map(this.renderListItem)));
|
|
2402
|
-
}
|
|
2403
|
-
}
|
|
2404
|
-
|
|
2405
|
-
const listCss = () => `@charset "UTF-8";:host(.has-striped-rows) .mdc-deprecated-list{border:1px solid rgb(var(--contrast-400))}:host(.has-striped-rows) limel-list-item:not([disabled]):not([disabled=true]):not(:hover):nth-child(even),:host(.has-striped-rows.has-interactive-items) limel-list-item:not([disabled]):not([disabled=true]):not(:hover):nth-child(even){background-color:var(--list-background-color-of-odd-interactive-items, rgb(var(--contrast-200)))}:host(.has-striped-rows) limel-list-item:not([disabled]):not([disabled=true]):not(:hover):nth-child(odd),:host(.has-striped-rows.has-interactive-items) limel-list-item:not([disabled]):not([disabled=true]):not(:hover):nth-child(odd){background-color:var(--list-background-color-of-even-interactive-items, rgb(var(--contrast-100)))}:host(.has-interactive-items) limel-list-item:not([disabled]):not([disabled=true]){transition:color var(--limel-clickable-transition-speed, 0.4s) ease, background-color var(--limel-clickable-transition-speed, 0.4s) ease, box-shadow var(--limel-clickable-transform-speed, 0.4s) ease, transform var(--limel-clickable-transform-speed, 0.4s) var(--limel-clickable-transform-timing-function, ease);cursor:pointer;color:var(--limel-theme-on-surface-color);background-color:transparent}:host(.has-interactive-items) limel-list-item:not([disabled]):not([disabled=true]):hover,:host(.has-interactive-items) limel-list-item:not([disabled]):not([disabled=true]):focus,:host(.has-interactive-items) limel-list-item:not([disabled]):not([disabled=true]):focus-visible{will-change:color, background-color, box-shadow, transform}:host(.has-interactive-items) limel-list-item:not([disabled]):not([disabled=true]):hover,:host(.has-interactive-items) limel-list-item:not([disabled]):not([disabled=true]):focus-visible{transform:translate3d(0, 0.01rem, 0);color:var(--limel-theme-on-surface-color);background-color:var(--lime-elevated-surface-background-color)}:host(.has-interactive-items) limel-list-item:not([disabled]):not([disabled=true]):hover{box-shadow:var(--button-shadow-hovered)}:host(.has-interactive-items) limel-list-item:not([disabled]):not([disabled=true]):active{--limel-clickable-transform-timing-function:cubic-bezier( 0.83, -0.15, 0.49, 1.16 );transform:translate3d(0, 0.05rem, 0);box-shadow:var(--button-shadow-pressed)}:host(.has-interactive-items) limel-list-item:not([disabled]):not([disabled=true]):hover,:host(.has-interactive-items) limel-list-item:not([disabled]):not([disabled=true]):active{--limel-clickable-transition-speed:0.2s;--limel-clickable-transform-speed:0.16s}:host(.has-grid-layout){--gap:var(--list-grid-gap, 0.5rem);padding:var(--gap);}:host(.has-grid-layout) .mdc-deprecated-list{display:grid;gap:var(--gap);grid-template-columns:repeat(auto-fit, minmax(min(100%, max(var(--list-grid-item-max-width, 10rem) - var(--gap), var(--list-grid-item-min-width, 7.5rem))), 1fr));max-width:var(--list-grid-max-width, 100%)}:host(.has-grid-layout) .mdc-deprecated-list limel-list-item{border-radius:var(--limel-list-border-radius) !important}:host(.has-grid-layout) .mdc-deprecated-list-divider{grid-column:1/-1}:host(.static-actions-list){z-index:1;background-color:var(--limel-theme-surface-background-color)}:host(.has-position-sticky){position:sticky;box-shadow:0 0 0.75rem 0.5rem var(--limel-theme-surface-background-color)}:host(.has-position-sticky.is-on-top){top:0}:host(.has-position-sticky.is-at-bottom){bottom:0}:host(.is-on-top){border-bottom:1px solid rgb(var(--contrast-400));margin-bottom:0.5rem;padding-bottom:0.25rem}:host(.is-at-bottom){border-top:1px solid rgb(var(--contrast-400));margin-top:0.5rem;padding-top:0.25rem}:host(limel-list){--limel-list-border-radius:0.5rem;display:block;isolation:isolate}:host([hidden]){display:none}ul{--mdc-theme-text-icon-on-background:var( --icon-color, rgb(var(--contrast-900)) );margin:var(--list-margin, 0.25rem);border-radius:var(--limel-list-border-radius);padding:0;list-style:none}.mdc-deprecated-list-divider{border-bottom-color:transparent;display:flex;align-items:center;gap:0.75rem;height:auto;padding:0 0.25rem;margin-bottom:0.5rem}.mdc-deprecated-list-divider:not(:first-child){margin-top:0.75rem}:host(.has-striped-rows) .mdc-deprecated-list-divider{margin-top:0.5rem}.limel-list-divider-line{background-color:rgb(var(--contrast-400));height:0.125rem;border-radius:1rem;min-width:1rem;flex-grow:1}.limel-list-divider-title{all:unset;overflow:hidden;white-space:nowrap;text-overflow:ellipsis;color:rgb(var(--contrast-900));font-size:var(--limel-theme-default-small-font-size)}`;
|
|
2406
|
-
|
|
2407
|
-
const { ACTION_EVENT } = strings$2;
|
|
2408
|
-
const List = class {
|
|
2409
|
-
constructor(hostRef) {
|
|
2410
|
-
index.registerInstance(this, hostRef);
|
|
2411
|
-
this.change = index.createEvent(this, "change", 7);
|
|
2412
|
-
this.select = index.createEvent(this, "select", 7);
|
|
2413
|
-
this.interact = index.createEvent(this, "interact", 7);
|
|
2414
|
-
/**
|
|
2415
|
-
* Size of the icons in the list
|
|
2416
|
-
*/
|
|
2417
|
-
this.iconSize = 'small';
|
|
2418
|
-
/**
|
|
2419
|
-
* By default, lists will display 3 lines of text, and then truncate the rest.
|
|
2420
|
-
* Consumers can increase or decrease this number by specifying
|
|
2421
|
-
* `maxLinesSecondaryText`. If consumer enters zero or negative
|
|
2422
|
-
* numbers we default to 1; and if they type decimals we round up.
|
|
2423
|
-
*/
|
|
2424
|
-
this.maxLinesSecondaryText = 3;
|
|
2425
|
-
this.listRenderer = new ListRenderer();
|
|
2426
|
-
this.setup = () => {
|
|
2427
|
-
this.setupList();
|
|
2428
|
-
this.setupListeners();
|
|
2429
|
-
};
|
|
2430
|
-
this.setupList = () => {
|
|
2431
|
-
if (this.mdcList) {
|
|
2432
|
-
this.teardown();
|
|
2433
|
-
this.mdcList = null;
|
|
2434
|
-
}
|
|
2435
|
-
const element = this.element.shadowRoot.querySelector('.mdc-deprecated-list');
|
|
2436
|
-
if (!element) {
|
|
2437
|
-
return;
|
|
2438
|
-
}
|
|
2439
|
-
this.listElement = element;
|
|
2440
|
-
this.listElement.removeEventListener('mousedown', this.handleItemMouseDown);
|
|
2441
|
-
this.listElement.addEventListener('mousedown', this.handleItemMouseDown);
|
|
2442
|
-
this.mdcList = new MDCList(element);
|
|
2443
|
-
// NOTE: This has no effect. It is kept as a marker rather than
|
|
2444
|
-
// removed, so that its absence isn't mistaken for an oversight.
|
|
2445
|
-
//
|
|
2446
|
-
// MDC indexes each row for typeahead by looking for
|
|
2447
|
-
// `.mdc-deprecated-list-item__primary-text` inside it, while
|
|
2448
|
-
// `limel-list-item` renders its label as `<span class="label">`. MDC
|
|
2449
|
-
// therefore builds an empty index, and typing does nothing.
|
|
2450
|
-
//
|
|
2451
|
-
// Do not "fix" this by adding MDC's class name to `limel-list-item`.
|
|
2452
|
-
// That revives MDC's typeahead along with three behaviors that cannot
|
|
2453
|
-
// be configured from the outside: a hard coded 300ms buffer, `Enter`
|
|
2454
|
-
// being ignored for as long as that buffer lives (its `notifyAction`
|
|
2455
|
-
// is guarded by `isTypeaheadInProgress`), and the space bar being
|
|
2456
|
-
// excluded from matches. It would also collide with `limel-menu`,
|
|
2457
|
-
// where single characters are used as item hotkeys.
|
|
2458
|
-
//
|
|
2459
|
-
// `limel-select` implements its own typeahead instead, see
|
|
2460
|
-
// `src/util/typeahead.ts`. It intercepts typed characters in the
|
|
2461
|
-
// capture phase on this very element, so they never reach MDC.
|
|
2462
|
-
this.mdcList.hasTypeahead = true;
|
|
2463
|
-
};
|
|
2464
|
-
/**
|
|
2465
|
-
* Focus the pressed list item directly, without scrolling.
|
|
2466
|
-
*
|
|
2467
|
-
* Since the list uses `delegatesFocus`, pressing a non-focusable part of
|
|
2468
|
-
* a list item (e.g. its text) would otherwise delegate focus to the first
|
|
2469
|
-
* focusable row, scrolling it into view. In a scrolled list that moves the
|
|
2470
|
-
* pressed row out from under the pointer before the click completes, so the
|
|
2471
|
-
* click lands on empty space and no item gets selected.
|
|
2472
|
-
*
|
|
2473
|
-
* Bound to `mousedown` only (not `pointerdown`) so a touch-drag to scroll
|
|
2474
|
-
* that starts on a row is not blocked by `preventDefault`.
|
|
2475
|
-
*
|
|
2476
|
-
* @param event - the mousedown event
|
|
2477
|
-
*/
|
|
2478
|
-
this.handleItemMouseDown = (event) => {
|
|
2479
|
-
var _a;
|
|
2480
|
-
const target = event.target;
|
|
2481
|
-
const itemElement = (_a = target === null || target === void 0 ? void 0 : target.closest) === null || _a === void 0 ? void 0 : _a.call(target, '.mdc-deprecated-list-item');
|
|
2482
|
-
if (!itemElement) {
|
|
2483
|
-
return;
|
|
2484
|
-
}
|
|
2485
|
-
// Suppress the default focus delegation (and its scroll) for any row,
|
|
2486
|
-
// but only move focus to interactive (non-disabled) rows.
|
|
2487
|
-
event.preventDefault();
|
|
2488
|
-
if (!itemElement.classList.contains('mdc-deprecated-list-item--disabled')) {
|
|
2489
|
-
itemElement.focus({ preventScroll: true });
|
|
2490
|
-
}
|
|
2491
|
-
};
|
|
2492
|
-
this.setupListeners = () => {
|
|
2493
|
-
if (!this.mdcList) {
|
|
2494
|
-
return;
|
|
2495
|
-
}
|
|
2496
|
-
this.mdcList.unlisten(ACTION_EVENT, this.handleAction);
|
|
2497
|
-
this.selectable = ['selectable', 'radio', 'checkbox'].includes(this.type);
|
|
2498
|
-
this.multiple = this.type === 'checkbox';
|
|
2499
|
-
if (!this.selectable) {
|
|
2500
|
-
return;
|
|
2501
|
-
}
|
|
2502
|
-
this.mdcList.listen(ACTION_EVENT, this.handleAction);
|
|
2503
|
-
this.mdcList.singleSelection = !this.multiple;
|
|
2504
|
-
};
|
|
2505
|
-
this.teardown = () => {
|
|
2506
|
-
var _a, _b, _c;
|
|
2507
|
-
(_a = this.listElement) === null || _a === void 0 ? void 0 : _a.removeEventListener('mousedown', this.handleItemMouseDown);
|
|
2508
|
-
(_b = this.mdcList) === null || _b === void 0 ? void 0 : _b.unlisten(ACTION_EVENT, this.handleAction);
|
|
2509
|
-
(_c = this.mdcList) === null || _c === void 0 ? void 0 : _c.destroy();
|
|
2510
|
-
};
|
|
2511
|
-
this.handleAction = (event) => {
|
|
2512
|
-
if (!this.multiple) {
|
|
2513
|
-
this.handleSingleSelect(event.detail.index);
|
|
2514
|
-
return;
|
|
2515
|
-
}
|
|
2516
|
-
this.handleMultiSelect(event.detail.index);
|
|
2517
|
-
};
|
|
2518
|
-
this.handleSingleSelect = (index) => {
|
|
2519
|
-
const listItems = this.items.filter(this.isListItem);
|
|
2520
|
-
if (listItems[index].disabled) {
|
|
2521
|
-
return;
|
|
530
|
+
this.filterCompletions = (filter) => {
|
|
531
|
+
if (!filter) {
|
|
532
|
+
return this.completionsList;
|
|
2522
533
|
}
|
|
2523
|
-
|
|
2524
|
-
|
|
2525
|
-
|
|
2526
|
-
|
|
2527
|
-
|
|
2528
|
-
|
|
2529
|
-
|
|
534
|
+
return this.completionsList.filter((completion) => completion.text.toLowerCase().includes(filter.toLowerCase()));
|
|
535
|
+
};
|
|
536
|
+
this.handleInput = (event) => {
|
|
537
|
+
event.stopPropagation();
|
|
538
|
+
let value = event.target.value;
|
|
539
|
+
if (this.type === 'number') {
|
|
540
|
+
if (!value && event.data) {
|
|
541
|
+
event.stopPropagation();
|
|
542
|
+
return;
|
|
543
|
+
}
|
|
544
|
+
if (value) {
|
|
545
|
+
value = Number(value);
|
|
2530
546
|
}
|
|
2531
|
-
interactedItem = Object.assign(Object.assign({}, selectedItem), { selected: false });
|
|
2532
|
-
this.change.emit(interactedItem);
|
|
2533
|
-
}
|
|
2534
|
-
if (listItems[index] !== selectedItem) {
|
|
2535
|
-
interactedItem = Object.assign(Object.assign({}, listItems[index]), { selected: true });
|
|
2536
|
-
this.change.emit(interactedItem);
|
|
2537
547
|
}
|
|
2538
|
-
this.
|
|
548
|
+
this.changeWaiting = true;
|
|
549
|
+
this.changeEmitter(value);
|
|
2539
550
|
};
|
|
2540
|
-
this.
|
|
2541
|
-
|
|
2542
|
-
|
|
2543
|
-
|
|
551
|
+
this.changeEmitter = debounce.debounce((value) => {
|
|
552
|
+
this.change.emit(value);
|
|
553
|
+
this.changeWaiting = false;
|
|
554
|
+
}, CHANGE_EVENT_DEBOUNCE_TIMEOUT);
|
|
555
|
+
this.handleChange = (event) => {
|
|
556
|
+
event.stopPropagation();
|
|
557
|
+
this.changeEmitter.flush();
|
|
558
|
+
};
|
|
559
|
+
this.handleIconClick = () => {
|
|
560
|
+
this.action.emit();
|
|
561
|
+
};
|
|
562
|
+
this.handleIconKeyPress = (event) => {
|
|
563
|
+
const isEnter = event.key === keycodes.ENTER;
|
|
564
|
+
const isSpace = event.key === keycodes.SPACE;
|
|
565
|
+
if (isSpace || isEnter) {
|
|
566
|
+
this.action.emit();
|
|
2544
567
|
}
|
|
2545
|
-
const selectedItems = listItems
|
|
2546
|
-
.filter((item, listIndex) => {
|
|
2547
|
-
if (listIndex === index) {
|
|
2548
|
-
// This is the item that was selected or deselected,
|
|
2549
|
-
// so we negate its previous selection status.
|
|
2550
|
-
return !item.selected;
|
|
2551
|
-
}
|
|
2552
|
-
// This is an item that didn't change, so we keep its selection status.
|
|
2553
|
-
return item.selected;
|
|
2554
|
-
})
|
|
2555
|
-
.map((item) => {
|
|
2556
|
-
return Object.assign(Object.assign({}, item), { selected: true });
|
|
2557
|
-
});
|
|
2558
|
-
this.change.emit(selectedItems);
|
|
2559
|
-
this.interact.emit(Object.assign({}, selectedItems[index]));
|
|
2560
568
|
};
|
|
2561
|
-
this.
|
|
2562
|
-
|
|
569
|
+
this.handleWheel = () => {
|
|
570
|
+
// This empty event handler is here to circumvent a bug.
|
|
571
|
+
// In some browsers (Chrome for example), hovering the input with
|
|
572
|
+
// the input focused, and scrolling, will both change the value
|
|
573
|
+
// AND scroll the page. We would prefer to never change the value
|
|
574
|
+
// on scroll, instead always scrolling the page, but since we
|
|
575
|
+
// haven't found a way to do that, this is the next best thing, as
|
|
576
|
+
// it prevents the page from being scrolled, but only in the
|
|
577
|
+
// circumstances when the value is changed by the scrolling.
|
|
578
|
+
// Please test THOROUGHLY if you remove this event handler 😄
|
|
2563
579
|
};
|
|
580
|
+
this.portalId = randomString.createRandomString();
|
|
581
|
+
this.helperTextId = randomString.createRandomString();
|
|
582
|
+
this.labelId = randomString.createRandomString();
|
|
2564
583
|
}
|
|
2565
584
|
connectedCallback() {
|
|
2566
|
-
this.
|
|
585
|
+
this.initialize();
|
|
586
|
+
}
|
|
587
|
+
componentDidLoad() {
|
|
588
|
+
this.initialize();
|
|
2567
589
|
}
|
|
2568
590
|
disconnectedCallback() {
|
|
2569
|
-
this.
|
|
591
|
+
if (this.mdcTextField) {
|
|
592
|
+
this.mdcTextField.destroy();
|
|
593
|
+
}
|
|
594
|
+
this.restyleCompletionsDropDown.cancel();
|
|
595
|
+
window.removeEventListener('resize', this.layout);
|
|
596
|
+
this.limelInputField.removeEventListener('focus', this.setFocus);
|
|
2570
597
|
}
|
|
2571
|
-
|
|
2572
|
-
this.
|
|
2573
|
-
|
|
598
|
+
componentDidUpdate() {
|
|
599
|
+
if (this.invalid) {
|
|
600
|
+
this.mdcTextField.valid = false;
|
|
601
|
+
}
|
|
602
|
+
else if (!this.wasInvalid) {
|
|
603
|
+
// Reset MDC's internal validity once the consumer no longer
|
|
604
|
+
// considers the field invalid and our own check hasn't
|
|
605
|
+
// flagged it either.
|
|
606
|
+
this.mdcTextField.valid = true;
|
|
607
|
+
}
|
|
608
|
+
this.mdcTextField.disabled = this.disabled || this.readonly;
|
|
2574
609
|
}
|
|
2575
|
-
|
|
2576
|
-
|
|
2577
|
-
|
|
2578
|
-
|
|
2579
|
-
|
|
2580
|
-
|
|
2581
|
-
|
|
2582
|
-
|
|
2583
|
-
|
|
2584
|
-
|
|
610
|
+
/**
|
|
611
|
+
* Returns the start position of the current text selection.
|
|
612
|
+
* Returns `null` if the input element is not available or if
|
|
613
|
+
* the input type does not support selection (e.g., `number`).
|
|
614
|
+
*/
|
|
615
|
+
async getSelectionStart() {
|
|
616
|
+
var _a, _b;
|
|
617
|
+
try {
|
|
618
|
+
return (_b = (_a = this.inputElement) === null || _a === void 0 ? void 0 : _a.selectionStart) !== null && _b !== void 0 ? _b : null;
|
|
619
|
+
}
|
|
620
|
+
catch (_c) {
|
|
621
|
+
// Some input types (e.g., number) throw InvalidStateError
|
|
622
|
+
return null;
|
|
2585
623
|
}
|
|
2586
|
-
const html = this.listRenderer.render(this.items, this.config);
|
|
2587
|
-
return (index.h(index.Host, { key: 'f15badb0936caf891cd8bd272ef5d3224645c3c7', style: {
|
|
2588
|
-
'--maxLinesSecondaryText': `${maxLinesSecondaryText}`,
|
|
2589
|
-
} }, html));
|
|
2590
624
|
}
|
|
2591
|
-
|
|
2592
|
-
|
|
625
|
+
/**
|
|
626
|
+
* Returns the end position of the current text selection.
|
|
627
|
+
* Returns `null` if the input element is not available or if
|
|
628
|
+
* the input type does not support selection (e.g., `number`).
|
|
629
|
+
*/
|
|
630
|
+
async getSelectionEnd() {
|
|
631
|
+
var _a, _b;
|
|
632
|
+
try {
|
|
633
|
+
return (_b = (_a = this.inputElement) === null || _a === void 0 ? void 0 : _a.selectionEnd) !== null && _b !== void 0 ? _b : null;
|
|
634
|
+
}
|
|
635
|
+
catch (_c) {
|
|
636
|
+
// Some input types (e.g., number) throw InvalidStateError
|
|
637
|
+
return null;
|
|
638
|
+
}
|
|
2593
639
|
}
|
|
2594
|
-
|
|
2595
|
-
|
|
2596
|
-
|
|
640
|
+
/**
|
|
641
|
+
* Returns the direction of the current text selection.
|
|
642
|
+
* Can be `'forward'`, `'backward'`, or `'none'`.
|
|
643
|
+
* Returns `null` if the input element is not available or if
|
|
644
|
+
* the input type does not support selection (e.g., `number`).
|
|
645
|
+
*/
|
|
646
|
+
async getSelectionDirection() {
|
|
647
|
+
var _a, _b;
|
|
648
|
+
try {
|
|
649
|
+
return (_b = (_a = this.inputElement) === null || _a === void 0 ? void 0 : _a.selectionDirection) !== null && _b !== void 0 ? _b : null;
|
|
2597
650
|
}
|
|
2598
|
-
|
|
2599
|
-
|
|
2600
|
-
|
|
2601
|
-
|
|
2602
|
-
|
|
2603
|
-
|
|
2604
|
-
|
|
2605
|
-
|
|
2606
|
-
|
|
2607
|
-
|
|
2608
|
-
|
|
2609
|
-
|
|
2610
|
-
|
|
2611
|
-
|
|
2612
|
-
|
|
2613
|
-
|
|
651
|
+
catch (_c) {
|
|
652
|
+
// Some input types (e.g., number) throw InvalidStateError
|
|
653
|
+
return null;
|
|
654
|
+
}
|
|
655
|
+
}
|
|
656
|
+
render() {
|
|
657
|
+
const properties = this.getAdditionalProps();
|
|
658
|
+
properties['aria-labelledby'] = this.labelId;
|
|
659
|
+
properties.class = 'mdc-text-field__input';
|
|
660
|
+
properties.ref = this.setInputElement;
|
|
661
|
+
properties.onInput = this.handleInput;
|
|
662
|
+
properties.onChange = this.handleChange;
|
|
663
|
+
properties.onFocus = this.onFocus;
|
|
664
|
+
properties.onBlur = this.onBlur;
|
|
665
|
+
properties.required = this.required;
|
|
666
|
+
properties.readonly = this.readonly;
|
|
667
|
+
properties.disabled = this.disabled || this.readonly;
|
|
668
|
+
let ariaControls = '';
|
|
669
|
+
if (this.hasHelperText()) {
|
|
670
|
+
ariaControls += this.helperTextId;
|
|
671
|
+
properties['aria-describedby'] = this.helperTextId;
|
|
672
|
+
}
|
|
673
|
+
if (this.renderAutocompleteList()) {
|
|
674
|
+
if (ariaControls) {
|
|
675
|
+
ariaControls += ' ';
|
|
2614
676
|
}
|
|
2615
|
-
|
|
677
|
+
ariaControls += this.portalId;
|
|
678
|
+
}
|
|
679
|
+
if (ariaControls) {
|
|
680
|
+
properties['aria-controls'] = ariaControls;
|
|
681
|
+
}
|
|
682
|
+
return (index.h(index.Host, { key: '9e509e181e05f451deadc92e052dc11075032f9a' }, index.h("limel-notched-outline", { key: '2f2307e2c7d96eec0c5753d27bf1fc76c9ad8eb2', labelId: this.labelId, label: this.label, required: this.required, invalid: this.invalid || this.isInvalid(), disabled: this.disabled, readonly: this.readonly, hasValue: !!this.value, hasLeadingIcon: !!this.leadingIcon }, index.h("label", { key: 'a21372b10d416423aea6ff9f318bf12ef8d4832a', slot: "content", class: this.getContainerClassList() }, this.renderLeadingIcon(), this.renderPrefix(), this.renderFormattedNumber(), this.renderInput(properties), this.renderSuffix(), this.renderTextarea(properties), this.renderTrailingLinkOrButton())), this.renderHelperLine(), this.renderAutocompleteList()));
|
|
2616
683
|
}
|
|
2617
|
-
|
|
684
|
+
valueWatcher(newValue) {
|
|
685
|
+
if (!this.mdcTextField) {
|
|
686
|
+
return;
|
|
687
|
+
}
|
|
688
|
+
if (this.changeWaiting) {
|
|
689
|
+
return;
|
|
690
|
+
}
|
|
691
|
+
if (this.type === 'number' &&
|
|
692
|
+
this.isFocused &&
|
|
693
|
+
Number(newValue) === Number(this.mdcTextField.value)) {
|
|
694
|
+
return;
|
|
695
|
+
}
|
|
696
|
+
if (newValue !== this.mdcTextField.value) {
|
|
697
|
+
this.mdcTextField.value = newValue || '';
|
|
698
|
+
}
|
|
699
|
+
if (this.wasInvalid) {
|
|
700
|
+
this.validate();
|
|
701
|
+
}
|
|
702
|
+
}
|
|
703
|
+
completionsWatcher() {
|
|
704
|
+
this.mapCompletions();
|
|
705
|
+
}
|
|
706
|
+
get validationMessage() {
|
|
2618
707
|
var _a;
|
|
2619
|
-
if (
|
|
2620
|
-
|
|
708
|
+
if (this.isInvalid() && !this.invalid) {
|
|
709
|
+
return ((_a = this.inputElement) === null || _a === void 0 ? void 0 : _a.validationMessage) || '';
|
|
2621
710
|
}
|
|
711
|
+
return '';
|
|
2622
712
|
}
|
|
2623
713
|
static get delegatesFocus() { return true; }
|
|
2624
|
-
get
|
|
714
|
+
get limelInputField() { return index.getElement(this); }
|
|
2625
715
|
static get watchers() { return {
|
|
2626
|
-
"
|
|
2627
|
-
"
|
|
716
|
+
"value": [{
|
|
717
|
+
"valueWatcher": 0
|
|
2628
718
|
}],
|
|
2629
|
-
"
|
|
2630
|
-
"
|
|
719
|
+
"completions": [{
|
|
720
|
+
"completionsWatcher": 0
|
|
2631
721
|
}]
|
|
2632
722
|
}; }
|
|
2633
723
|
};
|
|
2634
|
-
|
|
724
|
+
InputField.style = inputFieldCss();
|
|
2635
725
|
|
|
2636
726
|
const menuCss = () => `:host(limel-menu){isolation:isolate;position:relative;display:inline-block;--badge-background-color:var( --notification-badge-background-color, rgb(var(--color-red-default)) );--badge-text-color:var( --notification-badge-text-color, rgb(var(--color-white)) )}:host([hidden]){display:none}.menu__trigger{border-color:transparent;border-width:1px;border-style:solid;background:none;color:rgb(var(--contrast-800));height:2.25rem}.menu__trigger-enabled:hover{border-color:rgb(var(--contrast-800));color:rgb(var(--contrast-1100))}.mdc-menu-surface--anchor{position:relative}limel-badge{position:absolute;top:-0.25rem;right:-0.25rem}`;
|
|
2637
727
|
|
|
@@ -2698,6 +788,7 @@ const Menu = class {
|
|
|
2698
788
|
this.keepOpenOnSelect = false;
|
|
2699
789
|
this.shouldRestoreFocusOnClose = false;
|
|
2700
790
|
this.normalizedHotkeyCache = new Map();
|
|
791
|
+
this.triggersDisabledByMenu = new WeakSet();
|
|
2701
792
|
this.cachedSubMenuSource = null;
|
|
2702
793
|
this.cachedSubMenuItems = null;
|
|
2703
794
|
this.handleDocumentKeyDown = (event) => {
|
|
@@ -2977,20 +1068,32 @@ const Menu = class {
|
|
|
2977
1068
|
this.handleSelect(parent);
|
|
2978
1069
|
};
|
|
2979
1070
|
this.setTriggerAttributes = (element) => {
|
|
2980
|
-
|
|
2981
|
-
|
|
2982
|
-
|
|
2983
|
-
|
|
2984
|
-
|
|
2985
|
-
|
|
2986
|
-
|
|
2987
|
-
|
|
2988
|
-
|
|
2989
|
-
|
|
2990
|
-
|
|
2991
|
-
|
|
2992
|
-
|
|
1071
|
+
element.setAttribute('aria-haspopup', 'true');
|
|
1072
|
+
element.setAttribute('aria-controls', this.portalId);
|
|
1073
|
+
element.setAttribute('role', 'button');
|
|
1074
|
+
// `aria-expanded` is needed even when the menu is closed. Without
|
|
1075
|
+
// it, the trigger reads as an ordinary button to a screen reader.
|
|
1076
|
+
element.setAttribute('aria-expanded', String(this.open));
|
|
1077
|
+
this.setTriggerDisabled(element);
|
|
1078
|
+
};
|
|
1079
|
+
/**
|
|
1080
|
+
* `disabled` has to be removed rather than set to `false`, because the
|
|
1081
|
+
* presence of the attribute is what disables the element. Only the one the
|
|
1082
|
+
* menu put there may go: a consumer can disable their own trigger, and
|
|
1083
|
+
* stripping that attribute would re-enable it on every render.
|
|
1084
|
+
* @param element - the slotted trigger element
|
|
1085
|
+
*/
|
|
1086
|
+
this.setTriggerDisabled = (element) => {
|
|
1087
|
+
if (this.disabled) {
|
|
1088
|
+
if (!element.hasAttribute('disabled')) {
|
|
1089
|
+
element.setAttribute('disabled', 'true');
|
|
1090
|
+
this.triggersDisabledByMenu.add(element);
|
|
2993
1091
|
}
|
|
1092
|
+
return;
|
|
1093
|
+
}
|
|
1094
|
+
if (this.triggersDisabledByMenu.has(element)) {
|
|
1095
|
+
element.removeAttribute('disabled');
|
|
1096
|
+
this.triggersDisabledByMenu.delete(element);
|
|
2994
1097
|
}
|
|
2995
1098
|
};
|
|
2996
1099
|
this.onClose = () => {
|
|
@@ -3193,7 +1296,7 @@ const Menu = class {
|
|
|
3193
1296
|
const cssProperties = this.getCssProperties();
|
|
3194
1297
|
const dropdownZIndex = getComputedStyle(this.host).getPropertyValue('--dropdown-z-index');
|
|
3195
1298
|
const menuSurfaceWidth = this.getMenuSurfaceWidth(cssProperties['--menu-surface-width']);
|
|
3196
|
-
return (index.h("div", { key: '
|
|
1299
|
+
return (index.h("div", { key: 'c66307a5cc7257e2b394f0b5d56d6fbc6fce18b1', class: "mdc-menu-surface--anchor", onClick: this.onTriggerClick }, index.h("slot", { key: '7c37448e29deaee202f74d3288d21697529c82b5', ref: this.setTriggerRef, name: "trigger" }), this.renderNotificationBadge(), index.h("limel-portal", { key: 'f7f1b14ae5c6e19fa8e9651c2a847db0bb246427', visible: this.open, containerId: this.portalId, openDirection: this.openDirection, position: "absolute", containerStyle: { 'z-index': dropdownZIndex } }, index.h("limel-menu-surface", { key: 'c2fd7257bfe8ccf820b8aabc6a8959f6d5d1cd2f', open: this.open, onDismiss: this.onClose, style: Object.assign(Object.assign({}, cssProperties), { '--menu-surface-width': menuSurfaceWidth, '--limel-menu-surface-display': 'flex', '--limel-menu-surface-flex-direction': 'column' }), class: {
|
|
3197
1300
|
'has-grid-layout': this.gridLayout,
|
|
3198
1301
|
} }, this.renderSearchField(), this.renderBreadcrumb(), this.renderLoader(), this.renderEmptyMessage(), this.renderMenuList()))));
|
|
3199
1302
|
}
|
|
@@ -3203,24 +1306,33 @@ const Menu = class {
|
|
|
3203
1306
|
this.setFocus();
|
|
3204
1307
|
}
|
|
3205
1308
|
connectedCallback() {
|
|
3206
|
-
|
|
3207
|
-
document.addEventListener('keydown', this.handleDocumentKeyDown, true);
|
|
3208
|
-
}
|
|
1309
|
+
this.setupGlobalHandlers();
|
|
3209
1310
|
}
|
|
3210
1311
|
disconnectedCallback() {
|
|
3211
|
-
|
|
1312
|
+
this.teardownGlobalHandlers();
|
|
3212
1313
|
}
|
|
3213
1314
|
openWatcher(newValue) {
|
|
3214
|
-
|
|
3215
|
-
if (
|
|
3216
|
-
document.addEventListener('keydown', this.handleDocumentKeyDown, true);
|
|
1315
|
+
this.setupGlobalHandlers();
|
|
1316
|
+
if (newValue) {
|
|
3217
1317
|
this.setFocus();
|
|
3218
1318
|
}
|
|
3219
1319
|
else {
|
|
3220
|
-
document.removeEventListener('keydown', this.handleDocumentKeyDown, true);
|
|
3221
1320
|
this.clearSearch();
|
|
3222
1321
|
}
|
|
3223
1322
|
}
|
|
1323
|
+
setupGlobalHandlers() {
|
|
1324
|
+
// Stencil keeps firing `@Watch` on a detached instance, so `open` can
|
|
1325
|
+
// still flip after `disconnectedCallback` has run. Listening then
|
|
1326
|
+
// would leave a listener behind that no disconnect takes down.
|
|
1327
|
+
if (!this.open || !this.host.isConnected) {
|
|
1328
|
+
this.teardownGlobalHandlers();
|
|
1329
|
+
return;
|
|
1330
|
+
}
|
|
1331
|
+
document.addEventListener('keydown', this.handleDocumentKeyDown, true);
|
|
1332
|
+
}
|
|
1333
|
+
teardownGlobalHandlers() {
|
|
1334
|
+
document.removeEventListener('keydown', this.handleDocumentKeyDown, true);
|
|
1335
|
+
}
|
|
3224
1336
|
isFromTextInput(event) {
|
|
3225
1337
|
const path = typeof event.composedPath === 'function'
|
|
3226
1338
|
? event.composedPath()
|
|
@@ -4508,11 +2620,11 @@ var MDCMenuFoundation = /** @class */ (function (_super) {
|
|
|
4508
2620
|
MDCMenuFoundation.prototype.setEnabled = function (index, isEnabled) {
|
|
4509
2621
|
this.validatedIndex(index);
|
|
4510
2622
|
if (isEnabled) {
|
|
4511
|
-
this.adapter.removeClassFromElementAtIndex(index,
|
|
2623
|
+
this.adapter.removeClassFromElementAtIndex(index, component$1.cssClasses.LIST_ITEM_DISABLED_CLASS);
|
|
4512
2624
|
this.adapter.addAttributeToElementAtIndex(index, strings.ARIA_DISABLED_ATTR, 'false');
|
|
4513
2625
|
}
|
|
4514
2626
|
else {
|
|
4515
|
-
this.adapter.addClassToElementAtIndex(index,
|
|
2627
|
+
this.adapter.addClassToElementAtIndex(index, component$1.cssClasses.LIST_ITEM_DISABLED_CLASS);
|
|
4516
2628
|
this.adapter.addAttributeToElementAtIndex(index, strings.ARIA_DISABLED_ATTR, 'true');
|
|
4517
2629
|
}
|
|
4518
2630
|
};
|
|
@@ -4558,7 +2670,7 @@ var MDCMenu = /** @class */ (function (_super) {
|
|
|
4558
2670
|
};
|
|
4559
2671
|
MDCMenu.prototype.initialize = function (menuSurfaceFactory, listFactory) {
|
|
4560
2672
|
if (menuSurfaceFactory === void 0) { menuSurfaceFactory = function (el) { return new MDCMenuSurface(el); }; }
|
|
4561
|
-
if (listFactory === void 0) { listFactory = function (el) { return new MDCList(el); }; }
|
|
2673
|
+
if (listFactory === void 0) { listFactory = function (el) { return new component$1.MDCList(el); }; }
|
|
4562
2674
|
this.menuSurfaceFactory = menuSurfaceFactory;
|
|
4563
2675
|
this.listFactory = listFactory;
|
|
4564
2676
|
};
|
|
@@ -4584,7 +2696,7 @@ var MDCMenu = /** @class */ (function (_super) {
|
|
|
4584
2696
|
};
|
|
4585
2697
|
this.menuSurface.listen(MDCMenuSurfaceFoundation.strings.OPENED_EVENT, this.handleMenuSurfaceOpened);
|
|
4586
2698
|
this.listen('keydown', this.handleKeydown);
|
|
4587
|
-
this.listen(MDCListFoundation.strings.ACTION_EVENT, this.handleItemAction);
|
|
2699
|
+
this.listen(component$1.MDCListFoundation.strings.ACTION_EVENT, this.handleItemAction);
|
|
4588
2700
|
};
|
|
4589
2701
|
MDCMenu.prototype.destroy = function () {
|
|
4590
2702
|
if (this.list) {
|
|
@@ -4593,7 +2705,7 @@ var MDCMenu = /** @class */ (function (_super) {
|
|
|
4593
2705
|
this.menuSurface.destroy();
|
|
4594
2706
|
this.menuSurface.unlisten(MDCMenuSurfaceFoundation.strings.OPENED_EVENT, this.handleMenuSurfaceOpened);
|
|
4595
2707
|
this.unlisten('keydown', this.handleKeydown);
|
|
4596
|
-
this.unlisten(MDCListFoundation.strings.ACTION_EVENT, this.handleItemAction);
|
|
2708
|
+
this.unlisten(component$1.MDCListFoundation.strings.ACTION_EVENT, this.handleItemAction);
|
|
4597
2709
|
_super.prototype.destroy.call(this);
|
|
4598
2710
|
};
|
|
4599
2711
|
Object.defineProperty(MDCMenu.prototype, "open", {
|
|
@@ -4708,7 +2820,7 @@ var MDCMenu = /** @class */ (function (_super) {
|
|
|
4708
2820
|
* radio lists, and an array of numbers for checkbox lists.
|
|
4709
2821
|
*/
|
|
4710
2822
|
get: function () {
|
|
4711
|
-
return this.list ? this.list.selectedIndex :
|
|
2823
|
+
return this.list ? this.list.selectedIndex : component$1.numbers.UNSET_INDEX;
|
|
4712
2824
|
},
|
|
4713
2825
|
/**
|
|
4714
2826
|
* Sets the selected index of the list. Only applicable to select menus.
|
|
@@ -4990,7 +3102,7 @@ const MenuList = class {
|
|
|
4990
3102
|
this.mdcMenu.wrapFocus = true;
|
|
4991
3103
|
// eslint-disable-next-line sonarjs/constructor-for-side-effects
|
|
4992
3104
|
for (const item of this.mdcMenu.items)
|
|
4993
|
-
new component$
|
|
3105
|
+
new component$2.MDCRipple(item);
|
|
4994
3106
|
};
|
|
4995
3107
|
this.setupListeners = () => {
|
|
4996
3108
|
if (!this.mdcMenu) {
|
|
@@ -5178,70 +3290,6 @@ const MenuSurface = class {
|
|
|
5178
3290
|
};
|
|
5179
3291
|
MenuSurface.style = menuSurfaceCss();
|
|
5180
3292
|
|
|
5181
|
-
const notchedOutlineCss = () => `@charset "UTF-8";*,*:before,*:after{box-sizing:border-box}limel-notched-outline{--limel-notched-outline-border-color:rgba(var(--contrast-700), 0.65);--limel-notched-outline-background-color:rgba(var(--contrast-200), 0.5);display:block;width:100%;height:fit-content}.limel-notched-outline{position:relative;width:100%;height:100%}.limel-notched-outline [slot=content]{background-color:var(--limel-notched-outline-background-color);border-radius:var(--limel-notched-outline-border-radius, 0.25rem)}.limel-notched-outline--outlines{pointer-events:none;position:absolute;inset:0;z-index:var(--limel-notched-outline-z-index, 0);display:flex}.limel-notched-outline--leading-outline,.limel-notched-outline--notch,.limel-notched-outline--trailing-outline{transition:border-color 0.2s ease;border-width:1px;border-style:solid;border-color:var(--limel-notched-outline-border-color)}.limel-notched-outline--leading-outline{flex-shrink:0;width:0.75rem;border-right-width:0;border-top-left-radius:var(--limel-notched-outline-border-radius, 0.25rem);border-bottom-left-radius:var(--limel-notched-outline-border-radius, 0.25rem)}.limel-notched-outline--notch{flex-shrink:0;position:relative;z-index:2;border-top-color:var(--limel-notched-outline-notch-border-top-color, var(--limel-notched-outline-border-color));border-right-width:0;border-left-width:0;max-width:calc(100% - 1.5rem)}.limel-notched-outline--notch label{all:unset;overflow:hidden;white-space:nowrap;text-overflow:ellipsis;position:relative;transition:color 0.2s ease, font-size 0.2s ease, transform 0.12s cubic-bezier(0.4, 0, 0.2, 1);transform:translate3d(var(--limel-notched-outline-label-transform-x, 0), var(--limel-notched-outline-label-transform-y, 0.62rem), 0);display:block;padding:0 0.25rem;color:var(--limel-notched-outline-label-color, rgba(var(--contrast-1200), 1));font-size:var(--limel-notched-outline-label-font-size, var(--limel-theme-default-font-size));letter-spacing:var(--mdc-typography-subtitle1-letter-spacing, 0.009375em);line-height:normal}.limel-notched-outline--notch label:after{position:absolute;right:0;padding:0 0.25rem}.limel-notched-outline--trailing-outline{flex-grow:1;border-left-width:0;border-top-right-radius:var(--limel-notched-outline-border-radius, 0.25rem);border-bottom-right-radius:var(--limel-notched-outline-border-radius, 0.25rem)}.limel-notched-outline--empty-readonly-value .lime-looks-like-input-value{line-height:1.75rem;-moz-osx-font-smoothing:grayscale;-webkit-font-smoothing:antialiased;color:rgba(var(--contrast-1400), 1);font-size:var(--limel-theme-default-font-size);font-weight:400;font-family:inherit;letter-spacing:0.009375em}.mdc-text-field--disabled .limel-notched-outline--empty-readonly-value .lime-looks-like-input-value{cursor:not-allowed;opacity:0.4}.limel-notched-outline--empty-readonly-value{position:absolute;top:0.62rem;left:1rem}limel-notched-outline:not([disabled]:not([disabled=false])):hover{--limel-notched-outline-border-color:rgba(var(--contrast-700), 1);--limel-notched-outline-background-color:rgba(var(--contrast-200), 1)}limel-notched-outline:not([disabled]:not([disabled=false])):has([slot=content]:focus-visible),limel-notched-outline:not([disabled]:not([disabled=false])):has([slot=content]:focus-within){--limel-notched-outline-border-color:var(--lime-primary-color, var(--limel-theme-primary-color));--limel-notched-outline-background-color:rgba(var(--contrast-100), 0.8)}limel-notched-outline[disabled]:not([disabled=false]){--limel-notched-outline-label-color:rgba(var(--contrast-1200), 0.5)}limel-notched-outline[required]:not([required=false]) .limel-notched-outline--notch label{padding-right:0.75rem}limel-notched-outline[required]:not([required=false]) .limel-notched-outline--notch label:after{content:"*";scale:1.3}limel-notched-outline[invalid]:not([invalid=false]):not([disabled]:not([disabled=false])){--limel-notched-outline-border-color:var( --limel-theme-error-text-color )}limel-notched-outline[invalid]:not([invalid=false]):not([disabled]:not([disabled=false])):hover{--limel-notched-outline-border-color:var( --limel-theme-error-color )}limel-notched-outline[invalid]:not([invalid=false]) .limel-notched-outline--notch label:after{color:var(--limel-theme-error-text-color)}limel-notched-outline[readonly]:not([readonly=false]){--limel-notched-outline-border-color:transparent !important;--limel-notched-outline-background-color:transparent !important}limel-notched-outline[readonly]:not([readonly=false]) .limel-notched-outline--notch label{transition-duration:0s}limel-notched-outline[has-leading-icon]:not([has-leading-icon=false]):not([has-floating-label]):not([has-value]){--limel-notched-outline-label-transform-x:1.25rem}limel-notched-outline[has-leading-icon] .limel-notched-outline--empty-readonly-value{left:2.25rem}limel-notched-outline:not([disabled]:not([disabled=false])):hover label,limel-notched-outline:not([disabled]:not([disabled=false])):focus label,limel-notched-outline:not([disabled]:not([disabled=false])):focus-within label{will-change:color, transform, font-size}limel-notched-outline:not([disabled]:not([disabled=false])):has([slot=content]:focus-visible),limel-notched-outline:not([disabled]:not([disabled=false])):has([slot=content]:focus-within){--limel-notched-outline-label-font-size:0.65rem;--limel-notched-outline-label-transform-x:0;--limel-notched-outline-label-transform-y:calc(-50% - 0.09375rem);--limel-notched-outline-notch-border-top-color:transparent}limel-notched-outline[has-floating-label],limel-notched-outline[has-value]:not([has-value=false]),limel-notched-outline[readonly]:not([has-value]:not([has-value=true])){--limel-notched-outline-label-font-size:0.65rem;--limel-notched-outline-label-transform-x:0;--limel-notched-outline-label-transform-y:calc(-50% - 0.09375rem);--limel-notched-outline-notch-border-top-color:transparent}`;
|
|
5182
|
-
|
|
5183
|
-
const NotchedOutline = class {
|
|
5184
|
-
constructor(hostRef) {
|
|
5185
|
-
index.registerInstance(this, hostRef);
|
|
5186
|
-
/**
|
|
5187
|
-
* Set to `true` when the input element is required.
|
|
5188
|
-
* This applies proper visual styles, such as inclusion of an asterisk
|
|
5189
|
-
* beside the label.
|
|
5190
|
-
*/
|
|
5191
|
-
this.required = false;
|
|
5192
|
-
/**
|
|
5193
|
-
* Set to `true` when the input element is readonly.
|
|
5194
|
-
* This applies proper visual styles, such as making the outline transparent.
|
|
5195
|
-
*/
|
|
5196
|
-
this.readonly = false;
|
|
5197
|
-
/**
|
|
5198
|
-
* Set to `true` to indicate that the current value of the input element is
|
|
5199
|
-
* invalid. This applies proper visual styles, such as making the outlines red.
|
|
5200
|
-
*/
|
|
5201
|
-
this.invalid = false;
|
|
5202
|
-
/**
|
|
5203
|
-
* Set to `true` to indicate that the input element is
|
|
5204
|
-
* disabled. This applies proper visual styles, such as making the outlines
|
|
5205
|
-
* and the label transparent.
|
|
5206
|
-
*/
|
|
5207
|
-
this.disabled = false;
|
|
5208
|
-
/**
|
|
5209
|
-
* Set to `true` when the user has entered a value for the input element,
|
|
5210
|
-
* shrinking the label in size, and visually rendering it above the entered value.
|
|
5211
|
-
*/
|
|
5212
|
-
this.hasValue = false;
|
|
5213
|
-
/**
|
|
5214
|
-
* Set to `true` when the consumer element displays a leading icon.
|
|
5215
|
-
* This applies proper visual styles, such as rendering the label
|
|
5216
|
-
* correctly placed beside the leading icon.
|
|
5217
|
-
*/
|
|
5218
|
-
this.hasLeadingIcon = false;
|
|
5219
|
-
/**
|
|
5220
|
-
* Set to `true` when the consumer element needs to render the
|
|
5221
|
-
* label above the input element, despite existence of a `value`.
|
|
5222
|
-
* For example in the `text-editor` or `limel-select`,
|
|
5223
|
-
* where the default layout requires a floating label.
|
|
5224
|
-
*/
|
|
5225
|
-
this.hasFloatingLabel = false;
|
|
5226
|
-
}
|
|
5227
|
-
render() {
|
|
5228
|
-
return (index.h("div", { key: '928b12e7565dd3a827b29e57dfb94cbd668feb91', class: "limel-notched-outline" }, index.h("slot", { key: 'ae0a6205b1e8aeed3edea040a198ba7faebecc85', name: "content" }), index.h("span", { key: '84b1fd4feb65005eea9280717dd2cb6d74fc513c', class: "limel-notched-outline--outlines", "aria-hidden": "true" }, index.h("span", { key: '4ae9c02d23197109c5ea0721a4f1abfab802822e', class: "limel-notched-outline--leading-outline" }), this.renderLabel(), index.h("span", { key: 'd7b70aa632b22b7b639bf208ea57fd39a82884e3', class: "limel-notched-outline--trailing-outline" }), this.renderEmptyReadonlyValue())));
|
|
5229
|
-
}
|
|
5230
|
-
renderLabel() {
|
|
5231
|
-
if (!this.label) {
|
|
5232
|
-
return;
|
|
5233
|
-
}
|
|
5234
|
-
return (index.h("span", { class: "limel-notched-outline--notch" }, index.h("label", { htmlFor: this.labelId }, this.label)));
|
|
5235
|
-
}
|
|
5236
|
-
renderEmptyReadonlyValue() {
|
|
5237
|
-
if (!this.readonly || this.hasValue) {
|
|
5238
|
-
return;
|
|
5239
|
-
}
|
|
5240
|
-
return (index.h("span", { class: "limel-notched-outline--empty-readonly-value", "aria-hidden": "true" }, "\u2013"));
|
|
5241
|
-
}
|
|
5242
|
-
};
|
|
5243
|
-
NotchedOutline.style = notchedOutlineCss();
|
|
5244
|
-
|
|
5245
3293
|
const spinnerCss = () => `:host(limel-spinner){display:block}@keyframes spin{50%{transform:rotate(180deg)}100%{transform:rotate(720deg)}}@keyframes fade-in-the-spinner{0%{transform:scale(0.7);opacity:0}100%{transform:scale(1);opacity:1}}@keyframes animate-colored-circles{5%{stroke-dashoffset:0}10%,100%{stroke-dashoffset:63}}:host([hidden]){display:none}:host{box-sizing:border-box;display:flex;align-items:center;justify-content:center;height:1.5rem;width:1.5rem;transform:translate3d(0, 0, 0);animation:fade-in-the-spinner 0.5s ease forwards}:host([size=x-small]){height:2rem;width:2rem}:host([size=small]){height:2.125rem;width:2.125rem}:host([size=medium]){height:2.75rem;width:2.75rem}:host([size=large]){height:4rem;width:4rem}.spinner{animation:spin 1s linear infinite;transform-origin:center}.color{animation:animate-colored-circles 10s linear infinite;fill:none;stroke-dasharray:63;stroke-dashoffset:63;stroke-linecap:round;stroke-width:4}.color.thick{stroke-width:10}.color:nth-child(1){stroke:var(--spinner-color-1, rgb(var(--lime-brand-color-lime-green)))}.color:nth-child(2){stroke:var(--spinner-color-2, rgb(var(--lime-brand-color-ocean-teal)));animation-delay:1s}.color:nth-child(3){stroke:var(--spinner-color-3, rgb(var(--lime-brand-color-aqua)));animation-delay:2s}.color:nth-child(4){stroke:var(--spinner-color-4, rgb(var(--lime-brand-color-bubble-gum)));animation-delay:3s}.color:nth-child(5){stroke:var(--spinner-color-5, rgb(var(--lime-brand-color-sunny-orange)));animation-delay:4s}.color:nth-child(6){stroke:var(--spinner-color-6, rgb(var(--lime-brand-color-lime-green)));animation-delay:5s}.color:nth-child(7){stroke:var(--spinner-color-7, rgb(var(--lime-brand-color-ocean-teal)));animation-delay:6s}.color:nth-child(8){stroke:var(--spinner-color-8, rgb(var(--lime-brand-color-aqua)));animation-delay:7s}.color:nth-child(9){stroke:var(--spinner-color-9, rgb(var(--lime-brand-color-bubble-gum)));animation-delay:8s}.color:nth-child(10){stroke:var(--spinner-color-10, rgb(var(--contrast-700)));animation-delay:9s}.outline{stroke:rgba(var(--lime-brand-color-light-grey), 0.3);fill:none;stroke-linecap:round;stroke-width:4}.outline.thick{stroke-width:10}`;
|
|
5246
3294
|
|
|
5247
3295
|
const Spinner = class {
|
|
@@ -5270,9 +3318,7 @@ Spinner.style = spinnerCss();
|
|
|
5270
3318
|
|
|
5271
3319
|
exports.limel_breadcrumbs = Breadcrumbs;
|
|
5272
3320
|
exports.limel_input_field = InputField;
|
|
5273
|
-
exports.limel_list = List;
|
|
5274
3321
|
exports.limel_menu = Menu;
|
|
5275
3322
|
exports.limel_menu_list = MenuList;
|
|
5276
3323
|
exports.limel_menu_surface = MenuSurface;
|
|
5277
|
-
exports.limel_notched_outline = NotchedOutline;
|
|
5278
3324
|
exports.limel_spinner = Spinner;
|