@limetech/lime-elements 40.4.2 → 40.5.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (131) hide show
  1. package/CHANGELOG.md +14 -0
  2. package/dist/cjs/component-UyqdiWGc.js +1576 -0
  3. package/dist/cjs/lime-elements.cjs.js +1 -1
  4. package/dist/cjs/limel-action-bar_3.cjs.entry.js +1 -1
  5. package/dist/cjs/limel-ai-avatar.cjs.entry.js +1 -1
  6. package/dist/cjs/{limel-breadcrumbs_8.cjs.entry.js → limel-breadcrumbs_6.cjs.entry.js} +188 -2164
  7. package/dist/cjs/limel-callout.cjs.entry.js +1 -1
  8. package/dist/cjs/limel-chart.cjs.entry.js +1 -1
  9. package/dist/cjs/limel-chip-set.cjs.entry.js +1 -1
  10. package/dist/cjs/limel-chip_2.cjs.entry.js +1 -1
  11. package/dist/cjs/limel-code-diff.cjs.entry.js +1 -1
  12. package/dist/cjs/limel-code-editor.cjs.entry.js +1 -1
  13. package/dist/cjs/limel-collapsible-section.cjs.entry.js +1 -1
  14. package/dist/cjs/limel-drag-handle.cjs.entry.js +1 -1
  15. package/dist/cjs/limel-email-viewer.cjs.entry.js +1 -1
  16. package/dist/cjs/limel-file-viewer.cjs.entry.js +1 -1
  17. package/dist/cjs/limel-file.cjs.entry.js +1 -1
  18. package/dist/cjs/limel-flatpickr-adapter.cjs.entry.js +1 -1
  19. package/dist/cjs/limel-helper-line_3.cjs.entry.js +454 -0
  20. package/dist/cjs/limel-hotkey_4.cjs.entry.js +26 -5
  21. package/dist/cjs/limel-list-item.cjs.entry.js +1 -1
  22. package/dist/cjs/limel-pagination-jump.cjs.entry.js +182 -0
  23. package/dist/cjs/limel-pagination.cjs.entry.js +165 -126
  24. package/dist/cjs/limel-picker.cjs.entry.js +1 -1
  25. package/dist/cjs/limel-profile-picture.cjs.entry.js +1 -1
  26. package/dist/cjs/limel-prosemirror-adapter.cjs.entry.js +1 -1
  27. package/dist/cjs/limel-slider.cjs.entry.js +1 -1
  28. package/dist/cjs/limel-snackbar.cjs.entry.js +1 -1
  29. package/dist/cjs/limel-table.cjs.entry.js +1 -1
  30. package/dist/cjs/limel-text-editor-link-menu.cjs.entry.js +1 -1
  31. package/dist/cjs/loader.cjs.js +1 -1
  32. package/dist/cjs/pagination.util-B5zzH8vg.js +135 -0
  33. package/dist/cjs/{translations-C5T2-_rH.js → translations-DFFpR6AZ.js} +32 -0
  34. package/dist/collection/collection-manifest.json +1 -0
  35. package/dist/collection/components/pagination/jump/pagination-jump.css +11 -0
  36. package/dist/collection/components/pagination/jump/pagination-jump.js +331 -0
  37. package/dist/collection/components/pagination/pagination.css +8 -4
  38. package/dist/collection/components/pagination/pagination.js +167 -10
  39. package/dist/collection/components/pagination/pagination.util.js +25 -8
  40. package/dist/collection/components/portal/portal.js +26 -5
  41. package/dist/collection/translations/da.js +4 -0
  42. package/dist/collection/translations/de.js +4 -0
  43. package/dist/collection/translations/en.js +4 -0
  44. package/dist/collection/translations/fi.js +4 -0
  45. package/dist/collection/translations/fr.js +4 -0
  46. package/dist/collection/translations/nl.js +4 -0
  47. package/dist/collection/translations/no.js +4 -0
  48. package/dist/collection/translations/sv.js +4 -0
  49. package/dist/esm/component-B2Vy44Z3.js +1570 -0
  50. package/dist/esm/lime-elements.js +1 -1
  51. package/dist/esm/limel-action-bar_3.entry.js +1 -1
  52. package/dist/esm/limel-ai-avatar.entry.js +1 -1
  53. package/dist/esm/{limel-breadcrumbs_8.entry.js → limel-breadcrumbs_6.entry.js} +3 -1977
  54. package/dist/esm/limel-callout.entry.js +1 -1
  55. package/dist/esm/limel-chart.entry.js +1 -1
  56. package/dist/esm/limel-chip-set.entry.js +1 -1
  57. package/dist/esm/limel-chip_2.entry.js +1 -1
  58. package/dist/esm/limel-code-diff.entry.js +1 -1
  59. package/dist/esm/limel-code-editor.entry.js +1 -1
  60. package/dist/esm/limel-collapsible-section.entry.js +1 -1
  61. package/dist/esm/limel-drag-handle.entry.js +1 -1
  62. package/dist/esm/limel-email-viewer.entry.js +1 -1
  63. package/dist/esm/limel-file-viewer.entry.js +1 -1
  64. package/dist/esm/limel-file.entry.js +1 -1
  65. package/dist/esm/limel-flatpickr-adapter.entry.js +1 -1
  66. package/dist/esm/limel-helper-line_3.entry.js +450 -0
  67. package/dist/esm/limel-hotkey_4.entry.js +26 -5
  68. package/dist/esm/limel-list-item.entry.js +1 -1
  69. package/dist/esm/limel-pagination-jump.entry.js +180 -0
  70. package/dist/esm/limel-pagination.entry.js +165 -126
  71. package/dist/esm/limel-picker.entry.js +1 -1
  72. package/dist/esm/limel-profile-picture.entry.js +1 -1
  73. package/dist/esm/limel-prosemirror-adapter.entry.js +1 -1
  74. package/dist/esm/limel-slider.entry.js +1 -1
  75. package/dist/esm/limel-snackbar.entry.js +1 -1
  76. package/dist/esm/limel-table.entry.js +1 -1
  77. package/dist/esm/limel-text-editor-link-menu.entry.js +1 -1
  78. package/dist/esm/loader.js +1 -1
  79. package/dist/esm/pagination.util-CSC2LJ7P.js +132 -0
  80. package/dist/esm/{translations-Bwm2y2E4.js → translations-DMtX4tTX.js} +32 -0
  81. package/dist/lime-elements/lime-elements.esm.js +1 -1
  82. package/dist/lime-elements/{p-2bbdac10.entry.js → p-11a96a8c.entry.js} +1 -1
  83. package/dist/lime-elements/p-1e93473a.entry.js +1 -0
  84. package/dist/lime-elements/{p-6b7ff8e0.entry.js → p-2daf0482.entry.js} +1 -1
  85. package/dist/lime-elements/{p-a41b5ff3.entry.js → p-2e568c56.entry.js} +1 -1
  86. package/dist/lime-elements/{p-de631fc3.entry.js → p-2f57c3fa.entry.js} +1 -1
  87. package/dist/lime-elements/p-3735111e.entry.js +1 -0
  88. package/dist/lime-elements/{p-c823054d.entry.js → p-452b9b01.entry.js} +1 -1
  89. package/dist/lime-elements/{p-f333f12d.entry.js → p-4855dc9b.entry.js} +1 -1
  90. package/dist/lime-elements/{p-a462aeb7.entry.js → p-4902fb3f.entry.js} +1 -1
  91. package/dist/lime-elements/p-507cc8a1.entry.js +159 -0
  92. package/dist/lime-elements/{p-dadd2e17.entry.js → p-531b6a64.entry.js} +1 -1
  93. package/dist/lime-elements/{p-b194a212.entry.js → p-5698e493.entry.js} +1 -1
  94. package/dist/lime-elements/{p-65a9adfc.entry.js → p-67f02b69.entry.js} +1 -1
  95. package/dist/lime-elements/{p-1162dd39.entry.js → p-867681aa.entry.js} +1 -1
  96. package/dist/lime-elements/{p-f72ee01b.entry.js → p-90df3e1b.entry.js} +1 -1
  97. package/dist/lime-elements/{p-22f85b99.entry.js → p-955292eb.entry.js} +1 -1
  98. package/dist/lime-elements/{p-c2ff132c.entry.js → p-9b631363.entry.js} +1 -1
  99. package/dist/lime-elements/{p-8af3e4a1.entry.js → p-9d3437ac.entry.js} +1 -1
  100. package/dist/lime-elements/p-B8hoCfhT.js +1 -0
  101. package/dist/lime-elements/p-BwJGg-WI.js +89 -0
  102. package/dist/lime-elements/p-CSC2LJ7P.js +1 -0
  103. package/dist/lime-elements/p-a1de9bbe.entry.js +1 -0
  104. package/dist/lime-elements/{p-b5484494.entry.js → p-acba5700.entry.js} +1 -1
  105. package/dist/lime-elements/{p-f6361b03.entry.js → p-b8c76487.entry.js} +1 -1
  106. package/dist/lime-elements/{p-ac9c5c88.entry.js → p-cafec335.entry.js} +1 -1
  107. package/dist/lime-elements/{p-48928b4f.entry.js → p-d146feda.entry.js} +1 -1
  108. package/dist/lime-elements/{p-532ea234.entry.js → p-deceda00.entry.js} +1 -1
  109. package/dist/lime-elements/{p-e508771f.entry.js → p-f04f7c8e.entry.js} +1 -1
  110. package/dist/lime-elements/{p-51dc5f0b.entry.js → p-f3c108c9.entry.js} +1 -1
  111. package/dist/lime-elements/{p-24041bbb.entry.js → p-fbcd99a3.entry.js} +1 -1
  112. package/dist/types/components/pagination/jump/pagination-jump.d.ts +102 -0
  113. package/dist/types/components/pagination/pagination.d.ts +81 -0
  114. package/dist/types/components/pagination/pagination.util.d.ts +12 -2
  115. package/dist/types/components/portal/portal.d.ts +3 -0
  116. package/dist/types/components.d.ts +145 -0
  117. package/dist/types/translations/da.d.ts +4 -0
  118. package/dist/types/translations/de.d.ts +4 -0
  119. package/dist/types/translations/en.d.ts +4 -0
  120. package/dist/types/translations/fi.d.ts +4 -0
  121. package/dist/types/translations/fr.d.ts +4 -0
  122. package/dist/types/translations/nl.d.ts +4 -0
  123. package/dist/types/translations/no.d.ts +4 -0
  124. package/dist/types/translations/sv.d.ts +4 -0
  125. package/package.json +1 -1
  126. package/dist/cjs/limel-helper-line.cjs.entry.js +0 -42
  127. package/dist/esm/limel-helper-line.entry.js +0 -40
  128. package/dist/lime-elements/p-497b7be1.entry.js +0 -248
  129. package/dist/lime-elements/p-DAFuhe5e.js +0 -1
  130. package/dist/lime-elements/p-b4988a9b.entry.js +0 -1
  131. package/dist/lime-elements/p-f81dc23a.entry.js +0 -1
@@ -0,0 +1,1570 @@
1
+ import { _ as __extends, a as __assign, M as MDCFoundation, m as matches, d as closest, c as MDCComponent } from './ponyfill-ChRGk668.js';
2
+
3
+ /**
4
+ * @license
5
+ * Copyright 2018 Google Inc.
6
+ *
7
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
8
+ * of this software and associated documentation files (the "Software"), to deal
9
+ * in the Software without restriction, including without limitation the rights
10
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11
+ * copies of the Software, and to permit persons to whom the Software is
12
+ * furnished to do so, subject to the following conditions:
13
+ *
14
+ * The above copyright notice and this permission notice shall be included in
15
+ * all copies or substantial portions of the Software.
16
+ *
17
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23
+ * THE SOFTWARE.
24
+ */
25
+ var _a, _b;
26
+ var cssClasses = {
27
+ LIST_ITEM_ACTIVATED_CLASS: 'mdc-list-item--activated',
28
+ LIST_ITEM_CLASS: 'mdc-list-item',
29
+ LIST_ITEM_DISABLED_CLASS: 'mdc-list-item--disabled',
30
+ LIST_ITEM_SELECTED_CLASS: 'mdc-list-item--selected',
31
+ LIST_ITEM_TEXT_CLASS: 'mdc-list-item__text',
32
+ LIST_ITEM_PRIMARY_TEXT_CLASS: 'mdc-list-item__primary-text',
33
+ ROOT: 'mdc-list',
34
+ };
35
+ var evolutionClassNameMap = (_a = {},
36
+ _a["" + cssClasses.LIST_ITEM_ACTIVATED_CLASS] = 'mdc-list-item--activated',
37
+ _a["" + cssClasses.LIST_ITEM_CLASS] = 'mdc-list-item',
38
+ _a["" + cssClasses.LIST_ITEM_DISABLED_CLASS] = 'mdc-list-item--disabled',
39
+ _a["" + cssClasses.LIST_ITEM_SELECTED_CLASS] = 'mdc-list-item--selected',
40
+ _a["" + cssClasses.LIST_ITEM_PRIMARY_TEXT_CLASS] = 'mdc-list-item__primary-text',
41
+ _a["" + cssClasses.ROOT] = 'mdc-list',
42
+ _a);
43
+ var deprecatedClassNameMap = (_b = {},
44
+ _b["" + cssClasses.LIST_ITEM_ACTIVATED_CLASS] = 'mdc-deprecated-list-item--activated',
45
+ _b["" + cssClasses.LIST_ITEM_CLASS] = 'mdc-deprecated-list-item',
46
+ _b["" + cssClasses.LIST_ITEM_DISABLED_CLASS] = 'mdc-deprecated-list-item--disabled',
47
+ _b["" + cssClasses.LIST_ITEM_SELECTED_CLASS] = 'mdc-deprecated-list-item--selected',
48
+ _b["" + cssClasses.LIST_ITEM_TEXT_CLASS] = 'mdc-deprecated-list-item__text',
49
+ _b["" + cssClasses.LIST_ITEM_PRIMARY_TEXT_CLASS] = 'mdc-deprecated-list-item__primary-text',
50
+ _b["" + cssClasses.ROOT] = 'mdc-deprecated-list',
51
+ _b);
52
+ var strings = {
53
+ ACTION_EVENT: 'MDCList:action',
54
+ ARIA_CHECKED: 'aria-checked',
55
+ ARIA_CHECKED_CHECKBOX_SELECTOR: '[role="checkbox"][aria-checked="true"]',
56
+ ARIA_CHECKED_RADIO_SELECTOR: '[role="radio"][aria-checked="true"]',
57
+ ARIA_CURRENT: 'aria-current',
58
+ ARIA_DISABLED: 'aria-disabled',
59
+ ARIA_ORIENTATION: 'aria-orientation',
60
+ ARIA_ORIENTATION_HORIZONTAL: 'horizontal',
61
+ ARIA_ROLE_CHECKBOX_SELECTOR: '[role="checkbox"]',
62
+ ARIA_SELECTED: 'aria-selected',
63
+ ARIA_INTERACTIVE_ROLES_SELECTOR: '[role="listbox"], [role="menu"]',
64
+ ARIA_MULTI_SELECTABLE_SELECTOR: '[aria-multiselectable="true"]',
65
+ CHECKBOX_RADIO_SELECTOR: 'input[type="checkbox"], input[type="radio"]',
66
+ CHECKBOX_SELECTOR: 'input[type="checkbox"]',
67
+ CHILD_ELEMENTS_TO_TOGGLE_TABINDEX: "\n ." + cssClasses.LIST_ITEM_CLASS + " button:not(:disabled),\n ." + cssClasses.LIST_ITEM_CLASS + " a,\n ." + deprecatedClassNameMap[cssClasses.LIST_ITEM_CLASS] + " button:not(:disabled),\n ." + deprecatedClassNameMap[cssClasses.LIST_ITEM_CLASS] + " a\n ",
68
+ DEPRECATED_SELECTOR: '.mdc-deprecated-list',
69
+ FOCUSABLE_CHILD_ELEMENTS: "\n ." + cssClasses.LIST_ITEM_CLASS + " button:not(:disabled),\n ." + cssClasses.LIST_ITEM_CLASS + " a,\n ." + cssClasses.LIST_ITEM_CLASS + " input[type=\"radio\"]:not(:disabled),\n ." + cssClasses.LIST_ITEM_CLASS + " input[type=\"checkbox\"]:not(:disabled),\n ." + deprecatedClassNameMap[cssClasses.LIST_ITEM_CLASS] + " button:not(:disabled),\n ." + deprecatedClassNameMap[cssClasses.LIST_ITEM_CLASS] + " a,\n ." + deprecatedClassNameMap[cssClasses.LIST_ITEM_CLASS] + " input[type=\"radio\"]:not(:disabled),\n ." + deprecatedClassNameMap[cssClasses.LIST_ITEM_CLASS] + " input[type=\"checkbox\"]:not(:disabled)\n ",
70
+ RADIO_SELECTOR: 'input[type="radio"]',
71
+ SELECTED_ITEM_SELECTOR: '[aria-selected="true"], [aria-current="true"]',
72
+ };
73
+ var numbers = {
74
+ UNSET_INDEX: -1,
75
+ TYPEAHEAD_BUFFER_CLEAR_TIMEOUT_MS: 300
76
+ };
77
+ var evolutionAttribute = 'evolution';
78
+
79
+ /**
80
+ * @license
81
+ * Copyright 2020 Google Inc.
82
+ *
83
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
84
+ * of this software and associated documentation files (the "Software"), to deal
85
+ * in the Software without restriction, including without limitation the rights
86
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
87
+ * copies of the Software, and to permit persons to whom the Software is
88
+ * furnished to do so, subject to the following conditions:
89
+ *
90
+ * The above copyright notice and this permission notice shall be included in
91
+ * all copies or substantial portions of the Software.
92
+ *
93
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
94
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
95
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
96
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
97
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
98
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
99
+ * THE SOFTWARE.
100
+ */
101
+ /**
102
+ * KEY provides normalized string values for keys.
103
+ */
104
+ var KEY = {
105
+ UNKNOWN: 'Unknown',
106
+ BACKSPACE: 'Backspace',
107
+ ENTER: 'Enter',
108
+ SPACEBAR: 'Spacebar',
109
+ PAGE_UP: 'PageUp',
110
+ PAGE_DOWN: 'PageDown',
111
+ END: 'End',
112
+ HOME: 'Home',
113
+ ARROW_LEFT: 'ArrowLeft',
114
+ ARROW_UP: 'ArrowUp',
115
+ ARROW_RIGHT: 'ArrowRight',
116
+ ARROW_DOWN: 'ArrowDown',
117
+ DELETE: 'Delete',
118
+ ESCAPE: 'Escape',
119
+ TAB: 'Tab',
120
+ };
121
+ var normalizedKeys = new Set();
122
+ // IE11 has no support for new Map with iterable so we need to initialize this
123
+ // by hand.
124
+ normalizedKeys.add(KEY.BACKSPACE);
125
+ normalizedKeys.add(KEY.ENTER);
126
+ normalizedKeys.add(KEY.SPACEBAR);
127
+ normalizedKeys.add(KEY.PAGE_UP);
128
+ normalizedKeys.add(KEY.PAGE_DOWN);
129
+ normalizedKeys.add(KEY.END);
130
+ normalizedKeys.add(KEY.HOME);
131
+ normalizedKeys.add(KEY.ARROW_LEFT);
132
+ normalizedKeys.add(KEY.ARROW_UP);
133
+ normalizedKeys.add(KEY.ARROW_RIGHT);
134
+ normalizedKeys.add(KEY.ARROW_DOWN);
135
+ normalizedKeys.add(KEY.DELETE);
136
+ normalizedKeys.add(KEY.ESCAPE);
137
+ normalizedKeys.add(KEY.TAB);
138
+ var KEY_CODE = {
139
+ BACKSPACE: 8,
140
+ ENTER: 13,
141
+ SPACEBAR: 32,
142
+ PAGE_UP: 33,
143
+ PAGE_DOWN: 34,
144
+ END: 35,
145
+ HOME: 36,
146
+ ARROW_LEFT: 37,
147
+ ARROW_UP: 38,
148
+ ARROW_RIGHT: 39,
149
+ ARROW_DOWN: 40,
150
+ DELETE: 46,
151
+ ESCAPE: 27,
152
+ TAB: 9,
153
+ };
154
+ var mappedKeyCodes = new Map();
155
+ // IE11 has no support for new Map with iterable so we need to initialize this
156
+ // by hand.
157
+ mappedKeyCodes.set(KEY_CODE.BACKSPACE, KEY.BACKSPACE);
158
+ mappedKeyCodes.set(KEY_CODE.ENTER, KEY.ENTER);
159
+ mappedKeyCodes.set(KEY_CODE.SPACEBAR, KEY.SPACEBAR);
160
+ mappedKeyCodes.set(KEY_CODE.PAGE_UP, KEY.PAGE_UP);
161
+ mappedKeyCodes.set(KEY_CODE.PAGE_DOWN, KEY.PAGE_DOWN);
162
+ mappedKeyCodes.set(KEY_CODE.END, KEY.END);
163
+ mappedKeyCodes.set(KEY_CODE.HOME, KEY.HOME);
164
+ mappedKeyCodes.set(KEY_CODE.ARROW_LEFT, KEY.ARROW_LEFT);
165
+ mappedKeyCodes.set(KEY_CODE.ARROW_UP, KEY.ARROW_UP);
166
+ mappedKeyCodes.set(KEY_CODE.ARROW_RIGHT, KEY.ARROW_RIGHT);
167
+ mappedKeyCodes.set(KEY_CODE.ARROW_DOWN, KEY.ARROW_DOWN);
168
+ mappedKeyCodes.set(KEY_CODE.DELETE, KEY.DELETE);
169
+ mappedKeyCodes.set(KEY_CODE.ESCAPE, KEY.ESCAPE);
170
+ mappedKeyCodes.set(KEY_CODE.TAB, KEY.TAB);
171
+ var navigationKeys = new Set();
172
+ // IE11 has no support for new Set with iterable so we need to initialize this
173
+ // by hand.
174
+ navigationKeys.add(KEY.PAGE_UP);
175
+ navigationKeys.add(KEY.PAGE_DOWN);
176
+ navigationKeys.add(KEY.END);
177
+ navigationKeys.add(KEY.HOME);
178
+ navigationKeys.add(KEY.ARROW_LEFT);
179
+ navigationKeys.add(KEY.ARROW_UP);
180
+ navigationKeys.add(KEY.ARROW_RIGHT);
181
+ navigationKeys.add(KEY.ARROW_DOWN);
182
+ /**
183
+ * normalizeKey returns the normalized string for a navigational action.
184
+ */
185
+ function normalizeKey(evt) {
186
+ var key = evt.key;
187
+ // If the event already has a normalized key, return it
188
+ if (normalizedKeys.has(key)) {
189
+ return key;
190
+ }
191
+ // tslint:disable-next-line:deprecation
192
+ var mappedKey = mappedKeyCodes.get(evt.keyCode);
193
+ if (mappedKey) {
194
+ return mappedKey;
195
+ }
196
+ return KEY.UNKNOWN;
197
+ }
198
+
199
+ /**
200
+ * @license
201
+ * Copyright 2020 Google Inc.
202
+ *
203
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
204
+ * of this software and associated documentation files (the "Software"), to deal
205
+ * in the Software without restriction, including without limitation the rights
206
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
207
+ * copies of the Software, and to permit persons to whom the Software is
208
+ * furnished to do so, subject to the following conditions:
209
+ *
210
+ * The above copyright notice and this permission notice shall be included in
211
+ * all copies or substantial portions of the Software.
212
+ *
213
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
214
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
215
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
216
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
217
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
218
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
219
+ * THE SOFTWARE.
220
+ */
221
+ var ELEMENTS_KEY_ALLOWED_IN = ['input', 'button', 'textarea', 'select'];
222
+ /**
223
+ * Ensures that preventDefault is only called if the containing element
224
+ * doesn't consume the event, and it will cause an unintended scroll.
225
+ *
226
+ * @param evt keyboard event to be prevented.
227
+ */
228
+ var preventDefaultEvent = function (evt) {
229
+ var target = evt.target;
230
+ if (!target) {
231
+ return;
232
+ }
233
+ var tagName = ("" + target.tagName).toLowerCase();
234
+ if (ELEMENTS_KEY_ALLOWED_IN.indexOf(tagName) === -1) {
235
+ evt.preventDefault();
236
+ }
237
+ };
238
+
239
+ /**
240
+ * @license
241
+ * Copyright 2020 Google Inc.
242
+ *
243
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
244
+ * of this software and associated documentation files (the "Software"), to deal
245
+ * in the Software without restriction, including without limitation the rights
246
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
247
+ * copies of the Software, and to permit persons to whom the Software is
248
+ * furnished to do so, subject to the following conditions:
249
+ *
250
+ * The above copyright notice and this permission notice shall be included in
251
+ * all copies or substantial portions of the Software.
252
+ *
253
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
254
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
255
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
256
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
257
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
258
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
259
+ * THE SOFTWARE.
260
+ */
261
+ /**
262
+ * Initializes a state object for typeahead. Use the same reference for calls to
263
+ * typeahead functions.
264
+ *
265
+ * @return The current state of the typeahead process. Each state reference
266
+ * represents a typeahead instance as the reference is typically mutated
267
+ * in-place.
268
+ */
269
+ function initState() {
270
+ var state = {
271
+ bufferClearTimeout: 0,
272
+ currentFirstChar: '',
273
+ sortedIndexCursor: 0,
274
+ typeaheadBuffer: '',
275
+ };
276
+ return state;
277
+ }
278
+ /**
279
+ * Initializes typeahead state by indexing the current list items by primary
280
+ * text into the sortedIndexByFirstChar data structure.
281
+ *
282
+ * @param listItemCount numer of items in the list
283
+ * @param getPrimaryTextByItemIndex function that returns the primary text at a
284
+ * given index
285
+ *
286
+ * @return Map that maps the first character of the primary text to the full
287
+ * list text and it's index
288
+ */
289
+ function initSortedIndex(listItemCount, getPrimaryTextByItemIndex) {
290
+ var sortedIndexByFirstChar = new Map();
291
+ // Aggregate item text to index mapping
292
+ for (var i = 0; i < listItemCount; i++) {
293
+ var primaryText = getPrimaryTextByItemIndex(i).trim();
294
+ if (!primaryText) {
295
+ continue;
296
+ }
297
+ var firstChar = primaryText[0].toLowerCase();
298
+ if (!sortedIndexByFirstChar.has(firstChar)) {
299
+ sortedIndexByFirstChar.set(firstChar, []);
300
+ }
301
+ sortedIndexByFirstChar.get(firstChar).push({ text: primaryText.toLowerCase(), index: i });
302
+ }
303
+ // Sort the mapping
304
+ // TODO(b/157162694): Investigate replacing forEach with Map.values()
305
+ sortedIndexByFirstChar.forEach(function (values) {
306
+ values.sort(function (first, second) {
307
+ return first.index - second.index;
308
+ });
309
+ });
310
+ return sortedIndexByFirstChar;
311
+ }
312
+ /**
313
+ * Given the next desired character from the user, it attempts to find the next
314
+ * list option matching the buffer. Wraps around if at the end of options.
315
+ *
316
+ * @param opts Options and accessors
317
+ * - nextChar - the next character to match against items
318
+ * - sortedIndexByFirstChar - output of `initSortedIndex(...)`
319
+ * - focusedItemIndex - the index of the currently focused item
320
+ * - focusItemAtIndex - function that focuses a list item at given index
321
+ * - skipFocus - whether or not to focus the matched item
322
+ * - isItemAtIndexDisabled - function that determines whether an item at a
323
+ * given index is disabled
324
+ * @param state The typeahead state instance. See `initState`.
325
+ *
326
+ * @return The index of the matched item, or -1 if no match.
327
+ */
328
+ function matchItem(opts, state) {
329
+ var nextChar = opts.nextChar, focusItemAtIndex = opts.focusItemAtIndex, sortedIndexByFirstChar = opts.sortedIndexByFirstChar, focusedItemIndex = opts.focusedItemIndex, skipFocus = opts.skipFocus, isItemAtIndexDisabled = opts.isItemAtIndexDisabled;
330
+ clearTimeout(state.bufferClearTimeout);
331
+ state.bufferClearTimeout = setTimeout(function () {
332
+ clearBuffer(state);
333
+ }, numbers.TYPEAHEAD_BUFFER_CLEAR_TIMEOUT_MS);
334
+ state.typeaheadBuffer = state.typeaheadBuffer + nextChar;
335
+ var index;
336
+ if (state.typeaheadBuffer.length === 1) {
337
+ index = matchFirstChar(sortedIndexByFirstChar, focusedItemIndex, isItemAtIndexDisabled, state);
338
+ }
339
+ else {
340
+ index = matchAllChars(sortedIndexByFirstChar, isItemAtIndexDisabled, state);
341
+ }
342
+ if (index !== -1 && !skipFocus) {
343
+ focusItemAtIndex(index);
344
+ }
345
+ return index;
346
+ }
347
+ /**
348
+ * Matches the user's single input character in the buffer to the
349
+ * next option that begins with such character. Wraps around if at
350
+ * end of options. Returns -1 if no match is found.
351
+ */
352
+ function matchFirstChar(sortedIndexByFirstChar, focusedItemIndex, isItemAtIndexDisabled, state) {
353
+ var firstChar = state.typeaheadBuffer[0];
354
+ var itemsMatchingFirstChar = sortedIndexByFirstChar.get(firstChar);
355
+ if (!itemsMatchingFirstChar) {
356
+ return -1;
357
+ }
358
+ // Has the same firstChar been recently matched?
359
+ // Also, did starting index remain the same between key presses?
360
+ // If both hold true, simply increment index.
361
+ if (firstChar === state.currentFirstChar &&
362
+ itemsMatchingFirstChar[state.sortedIndexCursor].index ===
363
+ focusedItemIndex) {
364
+ state.sortedIndexCursor =
365
+ (state.sortedIndexCursor + 1) % itemsMatchingFirstChar.length;
366
+ var newIndex = itemsMatchingFirstChar[state.sortedIndexCursor].index;
367
+ if (!isItemAtIndexDisabled(newIndex)) {
368
+ return newIndex;
369
+ }
370
+ }
371
+ // If we're here, it means one of the following happened:
372
+ // - either firstChar or startingIndex has changed, invalidating the
373
+ // cursor.
374
+ // - The next item of typeahead is disabled, so we have to look further.
375
+ state.currentFirstChar = firstChar;
376
+ var newCursorPosition = -1;
377
+ var cursorPosition;
378
+ // Find the first non-disabled item as a fallback.
379
+ for (cursorPosition = 0; cursorPosition < itemsMatchingFirstChar.length; cursorPosition++) {
380
+ if (!isItemAtIndexDisabled(itemsMatchingFirstChar[cursorPosition].index)) {
381
+ newCursorPosition = cursorPosition;
382
+ break;
383
+ }
384
+ }
385
+ // Advance cursor to first item matching the firstChar that is positioned
386
+ // after starting item. Cursor is unchanged from fallback if there's no
387
+ // such item.
388
+ for (; cursorPosition < itemsMatchingFirstChar.length; cursorPosition++) {
389
+ if (itemsMatchingFirstChar[cursorPosition].index > focusedItemIndex &&
390
+ !isItemAtIndexDisabled(itemsMatchingFirstChar[cursorPosition].index)) {
391
+ newCursorPosition = cursorPosition;
392
+ break;
393
+ }
394
+ }
395
+ if (newCursorPosition !== -1) {
396
+ state.sortedIndexCursor = newCursorPosition;
397
+ return itemsMatchingFirstChar[state.sortedIndexCursor].index;
398
+ }
399
+ return -1;
400
+ }
401
+ /**
402
+ * Attempts to find the next item that matches all of the typeahead buffer.
403
+ * Wraps around if at end of options. Returns -1 if no match is found.
404
+ */
405
+ function matchAllChars(sortedIndexByFirstChar, isItemAtIndexDisabled, state) {
406
+ var firstChar = state.typeaheadBuffer[0];
407
+ var itemsMatchingFirstChar = sortedIndexByFirstChar.get(firstChar);
408
+ if (!itemsMatchingFirstChar) {
409
+ return -1;
410
+ }
411
+ // Do nothing if text already matches
412
+ var startingItem = itemsMatchingFirstChar[state.sortedIndexCursor];
413
+ if (startingItem.text.lastIndexOf(state.typeaheadBuffer, 0) === 0 &&
414
+ !isItemAtIndexDisabled(startingItem.index)) {
415
+ return startingItem.index;
416
+ }
417
+ // Find next item that matches completely; if no match, we'll eventually
418
+ // loop around to same position
419
+ var cursorPosition = (state.sortedIndexCursor + 1) % itemsMatchingFirstChar.length;
420
+ var nextCursorPosition = -1;
421
+ while (cursorPosition !== state.sortedIndexCursor) {
422
+ var currentItem = itemsMatchingFirstChar[cursorPosition];
423
+ var matches = currentItem.text.lastIndexOf(state.typeaheadBuffer, 0) === 0;
424
+ var isEnabled = !isItemAtIndexDisabled(currentItem.index);
425
+ if (matches && isEnabled) {
426
+ nextCursorPosition = cursorPosition;
427
+ break;
428
+ }
429
+ cursorPosition = (cursorPosition + 1) % itemsMatchingFirstChar.length;
430
+ }
431
+ if (nextCursorPosition !== -1) {
432
+ state.sortedIndexCursor = nextCursorPosition;
433
+ return itemsMatchingFirstChar[state.sortedIndexCursor].index;
434
+ }
435
+ return -1;
436
+ }
437
+ /**
438
+ * Whether or not the given typeahead instaance state is currently typing.
439
+ *
440
+ * @param state The typeahead state instance. See `initState`.
441
+ */
442
+ function isTypingInProgress(state) {
443
+ return state.typeaheadBuffer.length > 0;
444
+ }
445
+ /**
446
+ * Clears the typeahaed buffer so that it resets item matching to the first
447
+ * character.
448
+ *
449
+ * @param state The typeahead state instance. See `initState`.
450
+ */
451
+ function clearBuffer(state) {
452
+ state.typeaheadBuffer = '';
453
+ }
454
+ /**
455
+ * Given a keydown event, it calculates whether or not to automatically focus a
456
+ * list item depending on what was typed mimicing the typeahead functionality of
457
+ * a standard <select> element that is open.
458
+ *
459
+ * @param opts Options and accessors
460
+ * - event - the KeyboardEvent to handle and parse
461
+ * - sortedIndexByFirstChar - output of `initSortedIndex(...)`
462
+ * - focusedItemIndex - the index of the currently focused item
463
+ * - focusItemAtIndex - function that focuses a list item at given index
464
+ * - isItemAtFocusedIndexDisabled - whether or not the currently focused item
465
+ * is disabled
466
+ * - isTargetListItem - whether or not the event target is a list item
467
+ * @param state The typeahead state instance. See `initState`.
468
+ *
469
+ * @returns index of the item matched by the keydown. -1 if not matched.
470
+ */
471
+ function handleKeydown(opts, state) {
472
+ var event = opts.event, isTargetListItem = opts.isTargetListItem, focusedItemIndex = opts.focusedItemIndex, focusItemAtIndex = opts.focusItemAtIndex, sortedIndexByFirstChar = opts.sortedIndexByFirstChar, isItemAtIndexDisabled = opts.isItemAtIndexDisabled;
473
+ var isArrowLeft = normalizeKey(event) === 'ArrowLeft';
474
+ var isArrowUp = normalizeKey(event) === 'ArrowUp';
475
+ var isArrowRight = normalizeKey(event) === 'ArrowRight';
476
+ var isArrowDown = normalizeKey(event) === 'ArrowDown';
477
+ var isHome = normalizeKey(event) === 'Home';
478
+ var isEnd = normalizeKey(event) === 'End';
479
+ var isEnter = normalizeKey(event) === 'Enter';
480
+ var isSpace = normalizeKey(event) === 'Spacebar';
481
+ if (event.ctrlKey || event.metaKey || isArrowLeft || isArrowUp ||
482
+ isArrowRight || isArrowDown || isHome || isEnd || isEnter) {
483
+ return -1;
484
+ }
485
+ var isCharacterKey = !isSpace && event.key.length === 1;
486
+ if (isCharacterKey) {
487
+ preventDefaultEvent(event);
488
+ var matchItemOpts = {
489
+ focusItemAtIndex: focusItemAtIndex,
490
+ focusedItemIndex: focusedItemIndex,
491
+ nextChar: event.key.toLowerCase(),
492
+ sortedIndexByFirstChar: sortedIndexByFirstChar,
493
+ skipFocus: false,
494
+ isItemAtIndexDisabled: isItemAtIndexDisabled,
495
+ };
496
+ return matchItem(matchItemOpts, state);
497
+ }
498
+ if (!isSpace) {
499
+ return -1;
500
+ }
501
+ if (isTargetListItem) {
502
+ preventDefaultEvent(event);
503
+ }
504
+ var typeaheadOnListItem = isTargetListItem && isTypingInProgress(state);
505
+ if (typeaheadOnListItem) {
506
+ var matchItemOpts = {
507
+ focusItemAtIndex: focusItemAtIndex,
508
+ focusedItemIndex: focusedItemIndex,
509
+ nextChar: ' ',
510
+ sortedIndexByFirstChar: sortedIndexByFirstChar,
511
+ skipFocus: false,
512
+ isItemAtIndexDisabled: isItemAtIndexDisabled,
513
+ };
514
+ // space participates in typeahead matching if in rapid typing mode
515
+ return matchItem(matchItemOpts, state);
516
+ }
517
+ return -1;
518
+ }
519
+
520
+ /**
521
+ * @license
522
+ * Copyright 2018 Google Inc.
523
+ *
524
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
525
+ * of this software and associated documentation files (the "Software"), to deal
526
+ * in the Software without restriction, including without limitation the rights
527
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
528
+ * copies of the Software, and to permit persons to whom the Software is
529
+ * furnished to do so, subject to the following conditions:
530
+ *
531
+ * The above copyright notice and this permission notice shall be included in
532
+ * all copies or substantial portions of the Software.
533
+ *
534
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
535
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
536
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
537
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
538
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
539
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
540
+ * THE SOFTWARE.
541
+ */
542
+ function isNumberArray(selectedIndex) {
543
+ return selectedIndex instanceof Array;
544
+ }
545
+ var MDCListFoundation = /** @class */ (function (_super) {
546
+ __extends(MDCListFoundation, _super);
547
+ function MDCListFoundation(adapter) {
548
+ var _this = _super.call(this, __assign(__assign({}, MDCListFoundation.defaultAdapter), adapter)) || this;
549
+ _this.wrapFocus = false;
550
+ _this.isVertical = true;
551
+ _this.isSingleSelectionList = false;
552
+ _this.selectedIndex = numbers.UNSET_INDEX;
553
+ _this.focusedItemIndex = numbers.UNSET_INDEX;
554
+ _this.useActivatedClass = false;
555
+ _this.useSelectedAttr = false;
556
+ _this.ariaCurrentAttrValue = null;
557
+ _this.isCheckboxList = false;
558
+ _this.isRadioList = false;
559
+ _this.hasTypeahead = false;
560
+ // Transiently holds current typeahead prefix from user.
561
+ _this.typeaheadState = initState();
562
+ _this.sortedIndexByFirstChar = new Map();
563
+ return _this;
564
+ }
565
+ Object.defineProperty(MDCListFoundation, "strings", {
566
+ get: function () {
567
+ return strings;
568
+ },
569
+ enumerable: false,
570
+ configurable: true
571
+ });
572
+ Object.defineProperty(MDCListFoundation, "cssClasses", {
573
+ get: function () {
574
+ return cssClasses;
575
+ },
576
+ enumerable: false,
577
+ configurable: true
578
+ });
579
+ Object.defineProperty(MDCListFoundation, "numbers", {
580
+ get: function () {
581
+ return numbers;
582
+ },
583
+ enumerable: false,
584
+ configurable: true
585
+ });
586
+ Object.defineProperty(MDCListFoundation, "defaultAdapter", {
587
+ get: function () {
588
+ return {
589
+ addClassForElementIndex: function () { return undefined; },
590
+ focusItemAtIndex: function () { return undefined; },
591
+ getAttributeForElementIndex: function () { return null; },
592
+ getFocusedElementIndex: function () { return 0; },
593
+ getListItemCount: function () { return 0; },
594
+ hasCheckboxAtIndex: function () { return false; },
595
+ hasRadioAtIndex: function () { return false; },
596
+ isCheckboxCheckedAtIndex: function () { return false; },
597
+ isFocusInsideList: function () { return false; },
598
+ isRootFocused: function () { return false; },
599
+ listItemAtIndexHasClass: function () { return false; },
600
+ notifyAction: function () { return undefined; },
601
+ removeClassForElementIndex: function () { return undefined; },
602
+ setAttributeForElementIndex: function () { return undefined; },
603
+ setCheckedCheckboxOrRadioAtIndex: function () { return undefined; },
604
+ setTabIndexForListItemChildren: function () { return undefined; },
605
+ getPrimaryTextAtIndex: function () { return ''; },
606
+ };
607
+ },
608
+ enumerable: false,
609
+ configurable: true
610
+ });
611
+ MDCListFoundation.prototype.layout = function () {
612
+ if (this.adapter.getListItemCount() === 0) {
613
+ return;
614
+ }
615
+ // TODO(b/172274142): consider all items when determining the list's type.
616
+ if (this.adapter.hasCheckboxAtIndex(0)) {
617
+ this.isCheckboxList = true;
618
+ }
619
+ else if (this.adapter.hasRadioAtIndex(0)) {
620
+ this.isRadioList = true;
621
+ }
622
+ else {
623
+ this.maybeInitializeSingleSelection();
624
+ }
625
+ if (this.hasTypeahead) {
626
+ this.sortedIndexByFirstChar = this.typeaheadInitSortedIndex();
627
+ }
628
+ };
629
+ /** Returns the index of the item that was last focused. */
630
+ MDCListFoundation.prototype.getFocusedItemIndex = function () {
631
+ return this.focusedItemIndex;
632
+ };
633
+ /** Toggles focus wrapping with keyboard navigation. */
634
+ MDCListFoundation.prototype.setWrapFocus = function (value) {
635
+ this.wrapFocus = value;
636
+ };
637
+ /**
638
+ * Toggles orientation direction for keyboard navigation (true for vertical,
639
+ * false for horizontal).
640
+ */
641
+ MDCListFoundation.prototype.setVerticalOrientation = function (value) {
642
+ this.isVertical = value;
643
+ };
644
+ /** Toggles single-selection behavior. */
645
+ MDCListFoundation.prototype.setSingleSelection = function (value) {
646
+ this.isSingleSelectionList = value;
647
+ if (value) {
648
+ this.maybeInitializeSingleSelection();
649
+ this.selectedIndex = this.getSelectedIndexFromDOM();
650
+ }
651
+ };
652
+ /**
653
+ * Automatically determines whether the list is single selection list. If so,
654
+ * initializes the internal state to match the selected item.
655
+ */
656
+ MDCListFoundation.prototype.maybeInitializeSingleSelection = function () {
657
+ var selectedItemIndex = this.getSelectedIndexFromDOM();
658
+ if (selectedItemIndex === numbers.UNSET_INDEX)
659
+ return;
660
+ var hasActivatedClass = this.adapter.listItemAtIndexHasClass(selectedItemIndex, cssClasses.LIST_ITEM_ACTIVATED_CLASS);
661
+ if (hasActivatedClass) {
662
+ this.setUseActivatedClass(true);
663
+ }
664
+ this.isSingleSelectionList = true;
665
+ this.selectedIndex = selectedItemIndex;
666
+ };
667
+ /** @return Index of the first selected item based on the DOM state. */
668
+ MDCListFoundation.prototype.getSelectedIndexFromDOM = function () {
669
+ var selectedIndex = numbers.UNSET_INDEX;
670
+ var listItemsCount = this.adapter.getListItemCount();
671
+ for (var i = 0; i < listItemsCount; i++) {
672
+ var hasSelectedClass = this.adapter.listItemAtIndexHasClass(i, cssClasses.LIST_ITEM_SELECTED_CLASS);
673
+ var hasActivatedClass = this.adapter.listItemAtIndexHasClass(i, cssClasses.LIST_ITEM_ACTIVATED_CLASS);
674
+ if (!(hasSelectedClass || hasActivatedClass)) {
675
+ continue;
676
+ }
677
+ selectedIndex = i;
678
+ break;
679
+ }
680
+ return selectedIndex;
681
+ };
682
+ /**
683
+ * Sets whether typeahead is enabled on the list.
684
+ * @param hasTypeahead Whether typeahead is enabled.
685
+ */
686
+ MDCListFoundation.prototype.setHasTypeahead = function (hasTypeahead) {
687
+ this.hasTypeahead = hasTypeahead;
688
+ if (hasTypeahead) {
689
+ this.sortedIndexByFirstChar = this.typeaheadInitSortedIndex();
690
+ }
691
+ };
692
+ /**
693
+ * @return Whether typeahead is currently matching a user-specified prefix.
694
+ */
695
+ MDCListFoundation.prototype.isTypeaheadInProgress = function () {
696
+ return this.hasTypeahead &&
697
+ isTypingInProgress(this.typeaheadState);
698
+ };
699
+ /** Toggle use of the "activated" CSS class. */
700
+ MDCListFoundation.prototype.setUseActivatedClass = function (useActivated) {
701
+ this.useActivatedClass = useActivated;
702
+ };
703
+ /**
704
+ * Toggles use of the selected attribute (true for aria-selected, false for
705
+ * aria-checked).
706
+ */
707
+ MDCListFoundation.prototype.setUseSelectedAttribute = function (useSelected) {
708
+ this.useSelectedAttr = useSelected;
709
+ };
710
+ MDCListFoundation.prototype.getSelectedIndex = function () {
711
+ return this.selectedIndex;
712
+ };
713
+ MDCListFoundation.prototype.setSelectedIndex = function (index, _a) {
714
+ var _b = _a === void 0 ? {} : _a, forceUpdate = _b.forceUpdate;
715
+ if (!this.isIndexValid(index)) {
716
+ return;
717
+ }
718
+ if (this.isCheckboxList) {
719
+ this.setCheckboxAtIndex(index);
720
+ }
721
+ else if (this.isRadioList) {
722
+ this.setRadioAtIndex(index);
723
+ }
724
+ else {
725
+ this.setSingleSelectionAtIndex(index, { forceUpdate: forceUpdate });
726
+ }
727
+ };
728
+ /**
729
+ * Focus in handler for the list items.
730
+ */
731
+ MDCListFoundation.prototype.handleFocusIn = function (listItemIndex) {
732
+ if (listItemIndex >= 0) {
733
+ this.focusedItemIndex = listItemIndex;
734
+ this.adapter.setAttributeForElementIndex(listItemIndex, 'tabindex', '0');
735
+ this.adapter.setTabIndexForListItemChildren(listItemIndex, '0');
736
+ }
737
+ };
738
+ /**
739
+ * Focus out handler for the list items.
740
+ */
741
+ MDCListFoundation.prototype.handleFocusOut = function (listItemIndex) {
742
+ var _this = this;
743
+ if (listItemIndex >= 0) {
744
+ this.adapter.setAttributeForElementIndex(listItemIndex, 'tabindex', '-1');
745
+ this.adapter.setTabIndexForListItemChildren(listItemIndex, '-1');
746
+ }
747
+ /**
748
+ * Between Focusout & Focusin some browsers do not have focus on any
749
+ * element. Setting a delay to wait till the focus is moved to next element.
750
+ */
751
+ setTimeout(function () {
752
+ if (!_this.adapter.isFocusInsideList()) {
753
+ _this.setTabindexToFirstSelectedOrFocusedItem();
754
+ }
755
+ }, 0);
756
+ };
757
+ /**
758
+ * Key handler for the list.
759
+ */
760
+ MDCListFoundation.prototype.handleKeydown = function (event, isRootListItem, listItemIndex) {
761
+ var _this = this;
762
+ var isArrowLeft = normalizeKey(event) === 'ArrowLeft';
763
+ var isArrowUp = normalizeKey(event) === 'ArrowUp';
764
+ var isArrowRight = normalizeKey(event) === 'ArrowRight';
765
+ var isArrowDown = normalizeKey(event) === 'ArrowDown';
766
+ var isHome = normalizeKey(event) === 'Home';
767
+ var isEnd = normalizeKey(event) === 'End';
768
+ var isEnter = normalizeKey(event) === 'Enter';
769
+ var isSpace = normalizeKey(event) === 'Spacebar';
770
+ // Have to check both upper and lower case, because having caps lock on
771
+ // affects the value.
772
+ var isLetterA = event.key === 'A' || event.key === 'a';
773
+ if (this.adapter.isRootFocused()) {
774
+ if (isArrowUp || isEnd) {
775
+ event.preventDefault();
776
+ this.focusLastElement();
777
+ }
778
+ else if (isArrowDown || isHome) {
779
+ event.preventDefault();
780
+ this.focusFirstElement();
781
+ }
782
+ if (this.hasTypeahead) {
783
+ var handleKeydownOpts = {
784
+ event: event,
785
+ focusItemAtIndex: function (index) {
786
+ _this.focusItemAtIndex(index);
787
+ },
788
+ focusedItemIndex: -1,
789
+ isTargetListItem: isRootListItem,
790
+ sortedIndexByFirstChar: this.sortedIndexByFirstChar,
791
+ isItemAtIndexDisabled: function (index) {
792
+ return _this.adapter.listItemAtIndexHasClass(index, cssClasses.LIST_ITEM_DISABLED_CLASS);
793
+ },
794
+ };
795
+ handleKeydown(handleKeydownOpts, this.typeaheadState);
796
+ }
797
+ return;
798
+ }
799
+ var currentIndex = this.adapter.getFocusedElementIndex();
800
+ if (currentIndex === -1) {
801
+ currentIndex = listItemIndex;
802
+ if (currentIndex < 0) {
803
+ // If this event doesn't have a mdc-list-item ancestor from the
804
+ // current list (not from a sublist), return early.
805
+ return;
806
+ }
807
+ }
808
+ if ((this.isVertical && isArrowDown) ||
809
+ (!this.isVertical && isArrowRight)) {
810
+ preventDefaultEvent(event);
811
+ this.focusNextElement(currentIndex);
812
+ }
813
+ else if ((this.isVertical && isArrowUp) || (!this.isVertical && isArrowLeft)) {
814
+ preventDefaultEvent(event);
815
+ this.focusPrevElement(currentIndex);
816
+ }
817
+ else if (isHome) {
818
+ preventDefaultEvent(event);
819
+ this.focusFirstElement();
820
+ }
821
+ else if (isEnd) {
822
+ preventDefaultEvent(event);
823
+ this.focusLastElement();
824
+ }
825
+ else if (isLetterA && event.ctrlKey && this.isCheckboxList) {
826
+ event.preventDefault();
827
+ this.toggleAll(this.selectedIndex === numbers.UNSET_INDEX ?
828
+ [] :
829
+ this.selectedIndex);
830
+ }
831
+ else if (isEnter || isSpace) {
832
+ if (isRootListItem) {
833
+ // Return early if enter key is pressed on anchor element which triggers
834
+ // synthetic MouseEvent event.
835
+ var target = event.target;
836
+ if (target && target.tagName === 'A' && isEnter) {
837
+ return;
838
+ }
839
+ preventDefaultEvent(event);
840
+ if (this.adapter.listItemAtIndexHasClass(currentIndex, cssClasses.LIST_ITEM_DISABLED_CLASS)) {
841
+ return;
842
+ }
843
+ if (!this.isTypeaheadInProgress()) {
844
+ if (this.isSelectableList()) {
845
+ this.setSelectedIndexOnAction(currentIndex);
846
+ }
847
+ this.adapter.notifyAction(currentIndex);
848
+ }
849
+ }
850
+ }
851
+ if (this.hasTypeahead) {
852
+ var handleKeydownOpts = {
853
+ event: event,
854
+ focusItemAtIndex: function (index) {
855
+ _this.focusItemAtIndex(index);
856
+ },
857
+ focusedItemIndex: this.focusedItemIndex,
858
+ isTargetListItem: isRootListItem,
859
+ sortedIndexByFirstChar: this.sortedIndexByFirstChar,
860
+ isItemAtIndexDisabled: function (index) { return _this.adapter.listItemAtIndexHasClass(index, cssClasses.LIST_ITEM_DISABLED_CLASS); },
861
+ };
862
+ handleKeydown(handleKeydownOpts, this.typeaheadState);
863
+ }
864
+ };
865
+ /**
866
+ * Click handler for the list.
867
+ */
868
+ MDCListFoundation.prototype.handleClick = function (index, toggleCheckbox) {
869
+ if (index === numbers.UNSET_INDEX) {
870
+ return;
871
+ }
872
+ if (this.adapter.listItemAtIndexHasClass(index, cssClasses.LIST_ITEM_DISABLED_CLASS)) {
873
+ return;
874
+ }
875
+ if (this.isSelectableList()) {
876
+ this.setSelectedIndexOnAction(index, toggleCheckbox);
877
+ }
878
+ this.adapter.notifyAction(index);
879
+ };
880
+ /**
881
+ * Focuses the next element on the list.
882
+ */
883
+ MDCListFoundation.prototype.focusNextElement = function (index) {
884
+ var count = this.adapter.getListItemCount();
885
+ var nextIndex = index + 1;
886
+ if (nextIndex >= count) {
887
+ if (this.wrapFocus) {
888
+ nextIndex = 0;
889
+ }
890
+ else {
891
+ // Return early because last item is already focused.
892
+ return index;
893
+ }
894
+ }
895
+ this.focusItemAtIndex(nextIndex);
896
+ return nextIndex;
897
+ };
898
+ /**
899
+ * Focuses the previous element on the list.
900
+ */
901
+ MDCListFoundation.prototype.focusPrevElement = function (index) {
902
+ var prevIndex = index - 1;
903
+ if (prevIndex < 0) {
904
+ if (this.wrapFocus) {
905
+ prevIndex = this.adapter.getListItemCount() - 1;
906
+ }
907
+ else {
908
+ // Return early because first item is already focused.
909
+ return index;
910
+ }
911
+ }
912
+ this.focusItemAtIndex(prevIndex);
913
+ return prevIndex;
914
+ };
915
+ MDCListFoundation.prototype.focusFirstElement = function () {
916
+ this.focusItemAtIndex(0);
917
+ return 0;
918
+ };
919
+ MDCListFoundation.prototype.focusLastElement = function () {
920
+ var lastIndex = this.adapter.getListItemCount() - 1;
921
+ this.focusItemAtIndex(lastIndex);
922
+ return lastIndex;
923
+ };
924
+ MDCListFoundation.prototype.focusInitialElement = function () {
925
+ var initialIndex = this.getFirstSelectedOrFocusedItemIndex();
926
+ this.focusItemAtIndex(initialIndex);
927
+ return initialIndex;
928
+ };
929
+ /**
930
+ * @param itemIndex Index of the list item
931
+ * @param isEnabled Sets the list item to enabled or disabled.
932
+ */
933
+ MDCListFoundation.prototype.setEnabled = function (itemIndex, isEnabled) {
934
+ if (!this.isIndexValid(itemIndex)) {
935
+ return;
936
+ }
937
+ if (isEnabled) {
938
+ this.adapter.removeClassForElementIndex(itemIndex, cssClasses.LIST_ITEM_DISABLED_CLASS);
939
+ this.adapter.setAttributeForElementIndex(itemIndex, strings.ARIA_DISABLED, 'false');
940
+ }
941
+ else {
942
+ this.adapter.addClassForElementIndex(itemIndex, cssClasses.LIST_ITEM_DISABLED_CLASS);
943
+ this.adapter.setAttributeForElementIndex(itemIndex, strings.ARIA_DISABLED, 'true');
944
+ }
945
+ };
946
+ MDCListFoundation.prototype.setSingleSelectionAtIndex = function (index, _a) {
947
+ var _b = _a === void 0 ? {} : _a, forceUpdate = _b.forceUpdate;
948
+ if (this.selectedIndex === index && !forceUpdate) {
949
+ return;
950
+ }
951
+ var selectedClassName = cssClasses.LIST_ITEM_SELECTED_CLASS;
952
+ if (this.useActivatedClass) {
953
+ selectedClassName = cssClasses.LIST_ITEM_ACTIVATED_CLASS;
954
+ }
955
+ if (this.selectedIndex !== numbers.UNSET_INDEX) {
956
+ this.adapter.removeClassForElementIndex(this.selectedIndex, selectedClassName);
957
+ }
958
+ this.setAriaForSingleSelectionAtIndex(index);
959
+ this.setTabindexAtIndex(index);
960
+ if (index !== numbers.UNSET_INDEX) {
961
+ this.adapter.addClassForElementIndex(index, selectedClassName);
962
+ }
963
+ this.selectedIndex = index;
964
+ };
965
+ /**
966
+ * Sets aria attribute for single selection at given index.
967
+ */
968
+ MDCListFoundation.prototype.setAriaForSingleSelectionAtIndex = function (index) {
969
+ // Detect the presence of aria-current and get the value only during list
970
+ // initialization when it is in unset state.
971
+ if (this.selectedIndex === numbers.UNSET_INDEX) {
972
+ this.ariaCurrentAttrValue =
973
+ this.adapter.getAttributeForElementIndex(index, strings.ARIA_CURRENT);
974
+ }
975
+ var isAriaCurrent = this.ariaCurrentAttrValue !== null;
976
+ var ariaAttribute = isAriaCurrent ? strings.ARIA_CURRENT : strings.ARIA_SELECTED;
977
+ if (this.selectedIndex !== numbers.UNSET_INDEX) {
978
+ this.adapter.setAttributeForElementIndex(this.selectedIndex, ariaAttribute, 'false');
979
+ }
980
+ if (index !== numbers.UNSET_INDEX) {
981
+ var ariaAttributeValue = isAriaCurrent ? this.ariaCurrentAttrValue : 'true';
982
+ this.adapter.setAttributeForElementIndex(index, ariaAttribute, ariaAttributeValue);
983
+ }
984
+ };
985
+ /**
986
+ * Returns the attribute to use for indicating selection status.
987
+ */
988
+ MDCListFoundation.prototype.getSelectionAttribute = function () {
989
+ return this.useSelectedAttr ? strings.ARIA_SELECTED : strings.ARIA_CHECKED;
990
+ };
991
+ /**
992
+ * Toggles radio at give index. Radio doesn't change the checked state if it
993
+ * is already checked.
994
+ */
995
+ MDCListFoundation.prototype.setRadioAtIndex = function (index) {
996
+ var selectionAttribute = this.getSelectionAttribute();
997
+ this.adapter.setCheckedCheckboxOrRadioAtIndex(index, true);
998
+ if (this.selectedIndex !== numbers.UNSET_INDEX) {
999
+ this.adapter.setAttributeForElementIndex(this.selectedIndex, selectionAttribute, 'false');
1000
+ }
1001
+ this.adapter.setAttributeForElementIndex(index, selectionAttribute, 'true');
1002
+ this.selectedIndex = index;
1003
+ };
1004
+ MDCListFoundation.prototype.setCheckboxAtIndex = function (index) {
1005
+ var selectionAttribute = this.getSelectionAttribute();
1006
+ for (var i = 0; i < this.adapter.getListItemCount(); i++) {
1007
+ var isChecked = false;
1008
+ if (index.indexOf(i) >= 0) {
1009
+ isChecked = true;
1010
+ }
1011
+ this.adapter.setCheckedCheckboxOrRadioAtIndex(i, isChecked);
1012
+ this.adapter.setAttributeForElementIndex(i, selectionAttribute, isChecked ? 'true' : 'false');
1013
+ }
1014
+ this.selectedIndex = index;
1015
+ };
1016
+ MDCListFoundation.prototype.setTabindexAtIndex = function (index) {
1017
+ if (this.focusedItemIndex === numbers.UNSET_INDEX && index !== 0) {
1018
+ // If some list item was selected set first list item's tabindex to -1.
1019
+ // Generally, tabindex is set to 0 on first list item of list that has no
1020
+ // preselected items.
1021
+ this.adapter.setAttributeForElementIndex(0, 'tabindex', '-1');
1022
+ }
1023
+ else if (this.focusedItemIndex >= 0 && this.focusedItemIndex !== index) {
1024
+ this.adapter.setAttributeForElementIndex(this.focusedItemIndex, 'tabindex', '-1');
1025
+ }
1026
+ // Set the previous selection's tabindex to -1. We need this because
1027
+ // in selection menus that are not visible, programmatically setting an
1028
+ // option will not change focus but will change where tabindex should be 0.
1029
+ if (!(this.selectedIndex instanceof Array) &&
1030
+ this.selectedIndex !== index) {
1031
+ this.adapter.setAttributeForElementIndex(this.selectedIndex, 'tabindex', '-1');
1032
+ }
1033
+ if (index !== numbers.UNSET_INDEX) {
1034
+ this.adapter.setAttributeForElementIndex(index, 'tabindex', '0');
1035
+ }
1036
+ };
1037
+ /**
1038
+ * @return Return true if it is single selectin list, checkbox list or radio
1039
+ * list.
1040
+ */
1041
+ MDCListFoundation.prototype.isSelectableList = function () {
1042
+ return this.isSingleSelectionList || this.isCheckboxList ||
1043
+ this.isRadioList;
1044
+ };
1045
+ MDCListFoundation.prototype.setTabindexToFirstSelectedOrFocusedItem = function () {
1046
+ var targetIndex = this.getFirstSelectedOrFocusedItemIndex();
1047
+ this.setTabindexAtIndex(targetIndex);
1048
+ };
1049
+ MDCListFoundation.prototype.getFirstSelectedOrFocusedItemIndex = function () {
1050
+ // Action lists retain focus on the most recently focused item.
1051
+ if (!this.isSelectableList()) {
1052
+ return Math.max(this.focusedItemIndex, 0);
1053
+ }
1054
+ // Single-selection lists focus the selected item.
1055
+ if (typeof this.selectedIndex === 'number' &&
1056
+ this.selectedIndex !== numbers.UNSET_INDEX) {
1057
+ return this.selectedIndex;
1058
+ }
1059
+ // Multiple-selection lists focus the first selected item.
1060
+ if (isNumberArray(this.selectedIndex) && this.selectedIndex.length > 0) {
1061
+ return this.selectedIndex.reduce(function (minIndex, currentIndex) { return Math.min(minIndex, currentIndex); });
1062
+ }
1063
+ // Selection lists without a selection focus the first item.
1064
+ return 0;
1065
+ };
1066
+ MDCListFoundation.prototype.isIndexValid = function (index) {
1067
+ var _this = this;
1068
+ if (index instanceof Array) {
1069
+ if (!this.isCheckboxList) {
1070
+ throw new Error('MDCListFoundation: Array of index is only supported for checkbox based list');
1071
+ }
1072
+ if (index.length === 0) {
1073
+ return true;
1074
+ }
1075
+ else {
1076
+ return index.some(function (i) { return _this.isIndexInRange(i); });
1077
+ }
1078
+ }
1079
+ else if (typeof index === 'number') {
1080
+ if (this.isCheckboxList) {
1081
+ throw new Error("MDCListFoundation: Expected array of index for checkbox based list but got number: " + index);
1082
+ }
1083
+ return this.isIndexInRange(index) ||
1084
+ this.isSingleSelectionList && index === numbers.UNSET_INDEX;
1085
+ }
1086
+ else {
1087
+ return false;
1088
+ }
1089
+ };
1090
+ MDCListFoundation.prototype.isIndexInRange = function (index) {
1091
+ var listSize = this.adapter.getListItemCount();
1092
+ return index >= 0 && index < listSize;
1093
+ };
1094
+ /**
1095
+ * Sets selected index on user action, toggles checkbox / radio based on
1096
+ * toggleCheckbox value. User interaction should not toggle list item(s) when
1097
+ * disabled.
1098
+ */
1099
+ MDCListFoundation.prototype.setSelectedIndexOnAction = function (index, toggleCheckbox) {
1100
+ if (toggleCheckbox === void 0) { toggleCheckbox = true; }
1101
+ if (this.isCheckboxList) {
1102
+ this.toggleCheckboxAtIndex(index, toggleCheckbox);
1103
+ }
1104
+ else {
1105
+ this.setSelectedIndex(index);
1106
+ }
1107
+ };
1108
+ MDCListFoundation.prototype.toggleCheckboxAtIndex = function (index, toggleCheckbox) {
1109
+ var selectionAttribute = this.getSelectionAttribute();
1110
+ var isChecked = this.adapter.isCheckboxCheckedAtIndex(index);
1111
+ if (toggleCheckbox) {
1112
+ isChecked = !isChecked;
1113
+ this.adapter.setCheckedCheckboxOrRadioAtIndex(index, isChecked);
1114
+ }
1115
+ this.adapter.setAttributeForElementIndex(index, selectionAttribute, isChecked ? 'true' : 'false');
1116
+ // If none of the checkbox items are selected and selectedIndex is not
1117
+ // initialized then provide a default value.
1118
+ var selectedIndexes = this.selectedIndex === numbers.UNSET_INDEX ?
1119
+ [] :
1120
+ this.selectedIndex.slice();
1121
+ if (isChecked) {
1122
+ selectedIndexes.push(index);
1123
+ }
1124
+ else {
1125
+ selectedIndexes = selectedIndexes.filter(function (i) { return i !== index; });
1126
+ }
1127
+ this.selectedIndex = selectedIndexes;
1128
+ };
1129
+ MDCListFoundation.prototype.focusItemAtIndex = function (index) {
1130
+ this.adapter.focusItemAtIndex(index);
1131
+ this.focusedItemIndex = index;
1132
+ };
1133
+ MDCListFoundation.prototype.toggleAll = function (currentlySelectedIndexes) {
1134
+ var count = this.adapter.getListItemCount();
1135
+ // If all items are selected, deselect everything.
1136
+ if (currentlySelectedIndexes.length === count) {
1137
+ this.setCheckboxAtIndex([]);
1138
+ }
1139
+ else {
1140
+ // Otherwise select all enabled options.
1141
+ var allIndexes = [];
1142
+ for (var i = 0; i < count; i++) {
1143
+ if (!this.adapter.listItemAtIndexHasClass(i, cssClasses.LIST_ITEM_DISABLED_CLASS) ||
1144
+ currentlySelectedIndexes.indexOf(i) > -1) {
1145
+ allIndexes.push(i);
1146
+ }
1147
+ }
1148
+ this.setCheckboxAtIndex(allIndexes);
1149
+ }
1150
+ };
1151
+ /**
1152
+ * Given the next desired character from the user, adds it to the typeahead
1153
+ * buffer. Then, attempts to find the next option matching the buffer. Wraps
1154
+ * around if at the end of options.
1155
+ *
1156
+ * @param nextChar The next character to add to the prefix buffer.
1157
+ * @param startingIndex The index from which to start matching. Only relevant
1158
+ * when starting a new match sequence. To start a new match sequence,
1159
+ * clear the buffer using `clearTypeaheadBuffer`, or wait for the buffer
1160
+ * to clear after a set interval defined in list foundation. Defaults to
1161
+ * the currently focused index.
1162
+ * @return The index of the matched item, or -1 if no match.
1163
+ */
1164
+ MDCListFoundation.prototype.typeaheadMatchItem = function (nextChar, startingIndex, skipFocus) {
1165
+ var _this = this;
1166
+ if (skipFocus === void 0) { skipFocus = false; }
1167
+ var opts = {
1168
+ focusItemAtIndex: function (index) {
1169
+ _this.focusItemAtIndex(index);
1170
+ },
1171
+ focusedItemIndex: startingIndex ? startingIndex : this.focusedItemIndex,
1172
+ nextChar: nextChar,
1173
+ sortedIndexByFirstChar: this.sortedIndexByFirstChar,
1174
+ skipFocus: skipFocus,
1175
+ isItemAtIndexDisabled: function (index) { return _this.adapter.listItemAtIndexHasClass(index, cssClasses.LIST_ITEM_DISABLED_CLASS); }
1176
+ };
1177
+ return matchItem(opts, this.typeaheadState);
1178
+ };
1179
+ /**
1180
+ * Initializes the MDCListTextAndIndex data structure by indexing the current
1181
+ * list items by primary text.
1182
+ *
1183
+ * @return The primary texts of all the list items sorted by first character.
1184
+ */
1185
+ MDCListFoundation.prototype.typeaheadInitSortedIndex = function () {
1186
+ return initSortedIndex(this.adapter.getListItemCount(), this.adapter.getPrimaryTextAtIndex);
1187
+ };
1188
+ /**
1189
+ * Clears the typeahead buffer.
1190
+ */
1191
+ MDCListFoundation.prototype.clearTypeaheadBuffer = function () {
1192
+ clearBuffer(this.typeaheadState);
1193
+ };
1194
+ return MDCListFoundation;
1195
+ }(MDCFoundation));
1196
+
1197
+ /**
1198
+ * @license
1199
+ * Copyright 2018 Google Inc.
1200
+ *
1201
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
1202
+ * of this software and associated documentation files (the "Software"), to deal
1203
+ * in the Software without restriction, including without limitation the rights
1204
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
1205
+ * copies of the Software, and to permit persons to whom the Software is
1206
+ * furnished to do so, subject to the following conditions:
1207
+ *
1208
+ * The above copyright notice and this permission notice shall be included in
1209
+ * all copies or substantial portions of the Software.
1210
+ *
1211
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
1212
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
1213
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
1214
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
1215
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
1216
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
1217
+ * THE SOFTWARE.
1218
+ */
1219
+ var MDCList = /** @class */ (function (_super) {
1220
+ __extends(MDCList, _super);
1221
+ function MDCList() {
1222
+ return _super !== null && _super.apply(this, arguments) || this;
1223
+ }
1224
+ Object.defineProperty(MDCList.prototype, "vertical", {
1225
+ set: function (value) {
1226
+ this.foundation.setVerticalOrientation(value);
1227
+ },
1228
+ enumerable: false,
1229
+ configurable: true
1230
+ });
1231
+ Object.defineProperty(MDCList.prototype, "listElements", {
1232
+ get: function () {
1233
+ return Array.from(this.root.querySelectorAll("." + this.classNameMap[cssClasses.LIST_ITEM_CLASS]));
1234
+ },
1235
+ enumerable: false,
1236
+ configurable: true
1237
+ });
1238
+ Object.defineProperty(MDCList.prototype, "wrapFocus", {
1239
+ set: function (value) {
1240
+ this.foundation.setWrapFocus(value);
1241
+ },
1242
+ enumerable: false,
1243
+ configurable: true
1244
+ });
1245
+ Object.defineProperty(MDCList.prototype, "typeaheadInProgress", {
1246
+ /**
1247
+ * @return Whether typeahead is currently matching a user-specified prefix.
1248
+ */
1249
+ get: function () {
1250
+ return this.foundation.isTypeaheadInProgress();
1251
+ },
1252
+ enumerable: false,
1253
+ configurable: true
1254
+ });
1255
+ Object.defineProperty(MDCList.prototype, "hasTypeahead", {
1256
+ /**
1257
+ * Sets whether typeahead functionality is enabled on the list.
1258
+ * @param hasTypeahead Whether typeahead is enabled.
1259
+ */
1260
+ set: function (hasTypeahead) {
1261
+ this.foundation.setHasTypeahead(hasTypeahead);
1262
+ },
1263
+ enumerable: false,
1264
+ configurable: true
1265
+ });
1266
+ Object.defineProperty(MDCList.prototype, "singleSelection", {
1267
+ set: function (isSingleSelectionList) {
1268
+ this.foundation.setSingleSelection(isSingleSelectionList);
1269
+ },
1270
+ enumerable: false,
1271
+ configurable: true
1272
+ });
1273
+ Object.defineProperty(MDCList.prototype, "selectedIndex", {
1274
+ get: function () {
1275
+ return this.foundation.getSelectedIndex();
1276
+ },
1277
+ set: function (index) {
1278
+ this.foundation.setSelectedIndex(index);
1279
+ },
1280
+ enumerable: false,
1281
+ configurable: true
1282
+ });
1283
+ MDCList.attachTo = function (root) {
1284
+ return new MDCList(root);
1285
+ };
1286
+ MDCList.prototype.initialSyncWithDOM = function () {
1287
+ this.isEvolutionEnabled =
1288
+ evolutionAttribute in this.root.dataset;
1289
+ if (this.isEvolutionEnabled) {
1290
+ this.classNameMap = evolutionClassNameMap;
1291
+ }
1292
+ else if (matches(this.root, strings.DEPRECATED_SELECTOR)) {
1293
+ this.classNameMap = deprecatedClassNameMap;
1294
+ }
1295
+ else {
1296
+ this.classNameMap =
1297
+ Object.values(cssClasses)
1298
+ .reduce(function (obj, className) {
1299
+ obj[className] = className;
1300
+ return obj;
1301
+ }, {});
1302
+ }
1303
+ this.handleClick = this.handleClickEvent.bind(this);
1304
+ this.handleKeydown = this.handleKeydownEvent.bind(this);
1305
+ this.focusInEventListener = this.handleFocusInEvent.bind(this);
1306
+ this.focusOutEventListener = this.handleFocusOutEvent.bind(this);
1307
+ this.listen('keydown', this.handleKeydown);
1308
+ this.listen('click', this.handleClick);
1309
+ this.listen('focusin', this.focusInEventListener);
1310
+ this.listen('focusout', this.focusOutEventListener);
1311
+ this.layout();
1312
+ this.initializeListType();
1313
+ this.ensureFocusable();
1314
+ };
1315
+ MDCList.prototype.destroy = function () {
1316
+ this.unlisten('keydown', this.handleKeydown);
1317
+ this.unlisten('click', this.handleClick);
1318
+ this.unlisten('focusin', this.focusInEventListener);
1319
+ this.unlisten('focusout', this.focusOutEventListener);
1320
+ };
1321
+ MDCList.prototype.layout = function () {
1322
+ var direction = this.root.getAttribute(strings.ARIA_ORIENTATION);
1323
+ this.vertical = direction !== strings.ARIA_ORIENTATION_HORIZONTAL;
1324
+ var itemSelector = "." + this.classNameMap[cssClasses.LIST_ITEM_CLASS] + ":not([tabindex])";
1325
+ var childSelector = strings.FOCUSABLE_CHILD_ELEMENTS;
1326
+ // List items need to have at least tabindex=-1 to be focusable.
1327
+ var itemEls = this.root.querySelectorAll(itemSelector);
1328
+ if (itemEls.length) {
1329
+ Array.prototype.forEach.call(itemEls, function (el) {
1330
+ el.setAttribute('tabindex', '-1');
1331
+ });
1332
+ }
1333
+ // Child button/a elements are not tabbable until the list item is focused.
1334
+ var focusableChildEls = this.root.querySelectorAll(childSelector);
1335
+ if (focusableChildEls.length) {
1336
+ Array.prototype.forEach.call(focusableChildEls, function (el) {
1337
+ el.setAttribute('tabindex', '-1');
1338
+ });
1339
+ }
1340
+ if (this.isEvolutionEnabled) {
1341
+ this.foundation.setUseSelectedAttribute(true);
1342
+ }
1343
+ this.foundation.layout();
1344
+ };
1345
+ /**
1346
+ * Extracts the primary text from a list item.
1347
+ * @param item The list item element.
1348
+ * @return The primary text in the element.
1349
+ */
1350
+ MDCList.prototype.getPrimaryText = function (item) {
1351
+ var _a;
1352
+ var primaryText = item.querySelector("." + this.classNameMap[cssClasses.LIST_ITEM_PRIMARY_TEXT_CLASS]);
1353
+ if (this.isEvolutionEnabled || primaryText) {
1354
+ return (_a = primaryText === null || primaryText === void 0 ? void 0 : primaryText.textContent) !== null && _a !== void 0 ? _a : '';
1355
+ }
1356
+ var singleLineText = item.querySelector("." + this.classNameMap[cssClasses.LIST_ITEM_TEXT_CLASS]);
1357
+ return (singleLineText && singleLineText.textContent) || '';
1358
+ };
1359
+ /**
1360
+ * Initialize selectedIndex value based on pre-selected list items.
1361
+ */
1362
+ MDCList.prototype.initializeListType = function () {
1363
+ var _this = this;
1364
+ this.isInteractive =
1365
+ matches(this.root, strings.ARIA_INTERACTIVE_ROLES_SELECTOR);
1366
+ if (this.isEvolutionEnabled && this.isInteractive) {
1367
+ var selection = Array.from(this.root.querySelectorAll(strings.SELECTED_ITEM_SELECTOR), function (listItem) { return _this.listElements.indexOf(listItem); });
1368
+ if (matches(this.root, strings.ARIA_MULTI_SELECTABLE_SELECTOR)) {
1369
+ this.selectedIndex = selection;
1370
+ }
1371
+ else if (selection.length > 0) {
1372
+ this.selectedIndex = selection[0];
1373
+ }
1374
+ return;
1375
+ }
1376
+ var checkboxListItems = this.root.querySelectorAll(strings.ARIA_ROLE_CHECKBOX_SELECTOR);
1377
+ var radioSelectedListItem = this.root.querySelector(strings.ARIA_CHECKED_RADIO_SELECTOR);
1378
+ if (checkboxListItems.length) {
1379
+ var preselectedItems = this.root.querySelectorAll(strings.ARIA_CHECKED_CHECKBOX_SELECTOR);
1380
+ this.selectedIndex = Array.from(preselectedItems, function (listItem) { return _this.listElements.indexOf(listItem); });
1381
+ }
1382
+ else if (radioSelectedListItem) {
1383
+ this.selectedIndex = this.listElements.indexOf(radioSelectedListItem);
1384
+ }
1385
+ };
1386
+ /**
1387
+ * Updates the list item at itemIndex to the desired isEnabled state.
1388
+ * @param itemIndex Index of the list item
1389
+ * @param isEnabled Sets the list item to enabled or disabled.
1390
+ */
1391
+ MDCList.prototype.setEnabled = function (itemIndex, isEnabled) {
1392
+ this.foundation.setEnabled(itemIndex, isEnabled);
1393
+ };
1394
+ /**
1395
+ * Given the next desired character from the user, adds it to the typeahead
1396
+ * buffer. Then, attempts to find the next option matching the buffer. Wraps
1397
+ * around if at the end of options.
1398
+ *
1399
+ * @param nextChar The next character to add to the prefix buffer.
1400
+ * @param startingIndex The index from which to start matching. Defaults to
1401
+ * the currently focused index.
1402
+ * @return The index of the matched item.
1403
+ */
1404
+ MDCList.prototype.typeaheadMatchItem = function (nextChar, startingIndex) {
1405
+ return this.foundation.typeaheadMatchItem(nextChar, startingIndex, /** skipFocus */ true);
1406
+ };
1407
+ MDCList.prototype.getDefaultFoundation = function () {
1408
+ var _this = this;
1409
+ // DO NOT INLINE this variable. For backward compatibility, foundations take
1410
+ // a Partial<MDCFooAdapter>. To ensure we don't accidentally omit any
1411
+ // methods, we need a separate, strongly typed adapter variable.
1412
+ var adapter = {
1413
+ addClassForElementIndex: function (index, className) {
1414
+ var element = _this.listElements[index];
1415
+ if (element) {
1416
+ element.classList.add(_this.classNameMap[className]);
1417
+ }
1418
+ },
1419
+ focusItemAtIndex: function (index) {
1420
+ var element = _this.listElements[index];
1421
+ if (element) {
1422
+ element.focus();
1423
+ }
1424
+ },
1425
+ getAttributeForElementIndex: function (index, attr) {
1426
+ return _this.listElements[index].getAttribute(attr);
1427
+ },
1428
+ getFocusedElementIndex: function () {
1429
+ return _this.listElements.indexOf(document.activeElement);
1430
+ },
1431
+ getListItemCount: function () { return _this.listElements.length; },
1432
+ getPrimaryTextAtIndex: function (index) {
1433
+ return _this.getPrimaryText(_this.listElements[index]);
1434
+ },
1435
+ hasCheckboxAtIndex: function (index) {
1436
+ var listItem = _this.listElements[index];
1437
+ return !!listItem.querySelector(strings.CHECKBOX_SELECTOR);
1438
+ },
1439
+ hasRadioAtIndex: function (index) {
1440
+ var listItem = _this.listElements[index];
1441
+ return !!listItem.querySelector(strings.RADIO_SELECTOR);
1442
+ },
1443
+ isCheckboxCheckedAtIndex: function (index) {
1444
+ var listItem = _this.listElements[index];
1445
+ var toggleEl = listItem.querySelector(strings.CHECKBOX_SELECTOR);
1446
+ return toggleEl.checked;
1447
+ },
1448
+ isFocusInsideList: function () {
1449
+ return _this.root !== document.activeElement &&
1450
+ _this.root.contains(document.activeElement);
1451
+ },
1452
+ isRootFocused: function () { return document.activeElement === _this.root; },
1453
+ listItemAtIndexHasClass: function (index, className) {
1454
+ return _this.listElements[index].classList.contains(_this.classNameMap[className]);
1455
+ },
1456
+ notifyAction: function (index) {
1457
+ _this.emit(strings.ACTION_EVENT, { index: index }, /** shouldBubble */ true);
1458
+ },
1459
+ removeClassForElementIndex: function (index, className) {
1460
+ var element = _this.listElements[index];
1461
+ if (element) {
1462
+ element.classList.remove(_this.classNameMap[className]);
1463
+ }
1464
+ },
1465
+ setAttributeForElementIndex: function (index, attr, value) {
1466
+ var element = _this.listElements[index];
1467
+ if (element) {
1468
+ element.setAttribute(attr, value);
1469
+ }
1470
+ },
1471
+ setCheckedCheckboxOrRadioAtIndex: function (index, isChecked) {
1472
+ var listItem = _this.listElements[index];
1473
+ var toggleEl = listItem.querySelector(strings.CHECKBOX_RADIO_SELECTOR);
1474
+ toggleEl.checked = isChecked;
1475
+ var event = document.createEvent('Event');
1476
+ event.initEvent('change', true, true);
1477
+ toggleEl.dispatchEvent(event);
1478
+ },
1479
+ setTabIndexForListItemChildren: function (listItemIndex, tabIndexValue) {
1480
+ var element = _this.listElements[listItemIndex];
1481
+ var selector = strings.CHILD_ELEMENTS_TO_TOGGLE_TABINDEX;
1482
+ Array.prototype.forEach.call(element.querySelectorAll(selector), function (el) {
1483
+ el.setAttribute('tabindex', tabIndexValue);
1484
+ });
1485
+ },
1486
+ };
1487
+ return new MDCListFoundation(adapter);
1488
+ };
1489
+ /**
1490
+ * Ensures that at least one item is focusable if the list is interactive and
1491
+ * doesn't specify a suitable tabindex.
1492
+ */
1493
+ MDCList.prototype.ensureFocusable = function () {
1494
+ if (this.isEvolutionEnabled && this.isInteractive) {
1495
+ if (!this.root.querySelector("." + this.classNameMap[cssClasses.LIST_ITEM_CLASS] + "[tabindex=\"0\"]")) {
1496
+ var index = this.initialFocusIndex();
1497
+ if (index !== -1) {
1498
+ this.listElements[index].tabIndex = 0;
1499
+ }
1500
+ }
1501
+ }
1502
+ };
1503
+ MDCList.prototype.initialFocusIndex = function () {
1504
+ if (this.selectedIndex instanceof Array && this.selectedIndex.length > 0) {
1505
+ return this.selectedIndex[0];
1506
+ }
1507
+ if (typeof this.selectedIndex === 'number' &&
1508
+ this.selectedIndex !== numbers.UNSET_INDEX) {
1509
+ return this.selectedIndex;
1510
+ }
1511
+ var el = this.root.querySelector("." + this.classNameMap[cssClasses.LIST_ITEM_CLASS] + ":not(." + this.classNameMap[cssClasses.LIST_ITEM_DISABLED_CLASS] + ")");
1512
+ if (el === null) {
1513
+ return -1;
1514
+ }
1515
+ return this.getListItemIndex(el);
1516
+ };
1517
+ /**
1518
+ * Used to figure out which list item this event is targetting. Or returns -1
1519
+ * if there is no list item
1520
+ */
1521
+ MDCList.prototype.getListItemIndex = function (el) {
1522
+ var nearestParent = closest(el, "." + this.classNameMap[cssClasses.LIST_ITEM_CLASS] + ", ." + this.classNameMap[cssClasses.ROOT]);
1523
+ // Get the index of the element if it is a list item.
1524
+ if (nearestParent &&
1525
+ matches(nearestParent, "." + this.classNameMap[cssClasses.LIST_ITEM_CLASS])) {
1526
+ return this.listElements.indexOf(nearestParent);
1527
+ }
1528
+ return -1;
1529
+ };
1530
+ /**
1531
+ * Used to figure out which element was clicked before sending the event to
1532
+ * the foundation.
1533
+ */
1534
+ MDCList.prototype.handleFocusInEvent = function (evt) {
1535
+ var index = this.getListItemIndex(evt.target);
1536
+ this.foundation.handleFocusIn(index);
1537
+ };
1538
+ /**
1539
+ * Used to figure out which element was clicked before sending the event to
1540
+ * the foundation.
1541
+ */
1542
+ MDCList.prototype.handleFocusOutEvent = function (evt) {
1543
+ var index = this.getListItemIndex(evt.target);
1544
+ this.foundation.handleFocusOut(index);
1545
+ };
1546
+ /**
1547
+ * Used to figure out which element was focused when keydown event occurred
1548
+ * before sending the event to the foundation.
1549
+ */
1550
+ MDCList.prototype.handleKeydownEvent = function (evt) {
1551
+ var index = this.getListItemIndex(evt.target);
1552
+ var target = evt.target;
1553
+ this.foundation.handleKeydown(evt, target.classList.contains(this.classNameMap[cssClasses.LIST_ITEM_CLASS]), index);
1554
+ };
1555
+ /**
1556
+ * Used to figure out which element was clicked before sending the event to
1557
+ * the foundation.
1558
+ */
1559
+ MDCList.prototype.handleClickEvent = function (evt) {
1560
+ var index = this.getListItemIndex(evt.target);
1561
+ var target = evt.target;
1562
+ // Toggle the checkbox only if it's not the target of the event, or the
1563
+ // checkbox will have 2 change events.
1564
+ var toggleCheckbox = !matches(target, strings.CHECKBOX_RADIO_SELECTOR);
1565
+ this.foundation.handleClick(index, toggleCheckbox);
1566
+ };
1567
+ return MDCList;
1568
+ }(MDCComponent));
1569
+
1570
+ export { MDCListFoundation as M, MDCList as a, cssClasses as c, numbers as n, strings as s };