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