@limetech/lime-elements 37.68.0 → 37.69.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 (73) hide show
  1. package/CHANGELOG.md +16 -0
  2. package/dist/cjs/lime-elements.cjs.js +1 -1
  3. package/dist/cjs/limel-action-bar-item_2.cjs.entry.js +122 -0
  4. package/dist/cjs/limel-action-bar-item_2.cjs.entry.js.map +1 -0
  5. package/dist/cjs/{limel-action-bar_4.cjs.entry.js → limel-action-bar_2.cjs.entry.js} +1 -115
  6. package/dist/cjs/limel-action-bar_2.cjs.entry.js.map +1 -0
  7. package/dist/cjs/{limel-breadcrumbs_5.cjs.entry.js → limel-breadcrumbs_7.cjs.entry.js} +3344 -407
  8. package/dist/cjs/limel-breadcrumbs_7.cjs.entry.js.map +1 -0
  9. package/dist/cjs/limel-card.cjs.entry.js +85 -0
  10. package/dist/cjs/limel-card.cjs.entry.js.map +1 -0
  11. package/dist/cjs/limel-dynamic-label_2.cjs.entry.js +91 -0
  12. package/dist/cjs/limel-dynamic-label_2.cjs.entry.js.map +1 -0
  13. package/dist/cjs/limel-prosemirror-adapter.cjs.entry.js +12 -4
  14. package/dist/cjs/limel-prosemirror-adapter.cjs.entry.js.map +1 -1
  15. package/dist/cjs/loader.cjs.js +1 -1
  16. package/dist/collection/collection-manifest.json +1 -0
  17. package/dist/collection/components/card/card.css +202 -0
  18. package/dist/collection/components/card/card.js +282 -0
  19. package/dist/collection/components/card/card.js.map +1 -0
  20. package/dist/collection/components/text-editor/prosemirror-adapter/plugins/trigger/factory.js +12 -4
  21. package/dist/collection/components/text-editor/prosemirror-adapter/plugins/trigger/factory.js.map +1 -1
  22. package/dist/esm/lime-elements.js +1 -1
  23. package/dist/esm/limel-action-bar-item_2.entry.js +117 -0
  24. package/dist/esm/limel-action-bar-item_2.entry.js.map +1 -0
  25. package/dist/esm/{limel-action-bar_4.entry.js → limel-action-bar_2.entry.js} +2 -114
  26. package/dist/esm/limel-action-bar_2.entry.js.map +1 -0
  27. package/dist/esm/{limel-breadcrumbs_5.entry.js → limel-breadcrumbs_7.entry.js} +3333 -398
  28. package/dist/esm/limel-breadcrumbs_7.entry.js.map +1 -0
  29. package/dist/esm/limel-card.entry.js +81 -0
  30. package/dist/esm/limel-card.entry.js.map +1 -0
  31. package/dist/esm/limel-dynamic-label_2.entry.js +86 -0
  32. package/dist/esm/limel-dynamic-label_2.entry.js.map +1 -0
  33. package/dist/esm/limel-prosemirror-adapter.entry.js +12 -4
  34. package/dist/esm/limel-prosemirror-adapter.entry.js.map +1 -1
  35. package/dist/esm/loader.js +1 -1
  36. package/dist/lime-elements/lime-elements.esm.js +1 -1
  37. package/dist/lime-elements/lime-elements.esm.js.map +1 -1
  38. package/dist/lime-elements/p-18b068c9.entry.js +2 -0
  39. package/dist/lime-elements/p-18b068c9.entry.js.map +1 -0
  40. package/dist/lime-elements/{p-9d2f6454.entry.js → p-617cfacf.entry.js} +2 -2
  41. package/dist/lime-elements/p-617cfacf.entry.js.map +1 -0
  42. package/dist/lime-elements/p-7f9e0f52.entry.js +2 -0
  43. package/dist/lime-elements/p-7f9e0f52.entry.js.map +1 -0
  44. package/dist/lime-elements/p-97ae94e0.entry.js +266 -0
  45. package/dist/lime-elements/p-97ae94e0.entry.js.map +1 -0
  46. package/dist/lime-elements/p-9f8aa8e7.entry.js +2 -0
  47. package/dist/lime-elements/p-9f8aa8e7.entry.js.map +1 -0
  48. package/dist/lime-elements/p-a8e24972.entry.js +2 -0
  49. package/dist/lime-elements/p-a8e24972.entry.js.map +1 -0
  50. package/dist/types/components/card/card.d.ts +75 -0
  51. package/dist/types/components.d.ts +143 -4
  52. package/package.json +1 -1
  53. package/dist/cjs/component-864afce0.js +0 -2447
  54. package/dist/cjs/component-864afce0.js.map +0 -1
  55. package/dist/cjs/limel-action-bar_4.cjs.entry.js.map +0 -1
  56. package/dist/cjs/limel-breadcrumbs_5.cjs.entry.js.map +0 -1
  57. package/dist/cjs/limel-dynamic-label_4.cjs.entry.js +0 -600
  58. package/dist/cjs/limel-dynamic-label_4.cjs.entry.js.map +0 -1
  59. package/dist/esm/component-5e233629.js +0 -2439
  60. package/dist/esm/component-5e233629.js.map +0 -1
  61. package/dist/esm/limel-action-bar_4.entry.js.map +0 -1
  62. package/dist/esm/limel-breadcrumbs_5.entry.js.map +0 -1
  63. package/dist/esm/limel-dynamic-label_4.entry.js +0 -593
  64. package/dist/esm/limel-dynamic-label_4.entry.js.map +0 -1
  65. package/dist/lime-elements/p-589ba37a.entry.js +0 -2
  66. package/dist/lime-elements/p-589ba37a.entry.js.map +0 -1
  67. package/dist/lime-elements/p-9d2f6454.entry.js.map +0 -1
  68. package/dist/lime-elements/p-b9b0853b.entry.js +0 -68
  69. package/dist/lime-elements/p-b9b0853b.entry.js.map +0 -1
  70. package/dist/lime-elements/p-bd261424.entry.js +0 -2
  71. package/dist/lime-elements/p-bd261424.entry.js.map +0 -1
  72. package/dist/lime-elements/p-d528606a.js +0 -200
  73. package/dist/lime-elements/p-d528606a.js.map +0 -1
@@ -1,2447 +0,0 @@
1
- 'use strict';
2
-
3
- const ponyfill = require('./ponyfill-63966294.js');
4
- const util = require('./util-b0f5741e.js');
5
-
6
- /**
7
- * @license
8
- * Copyright 2018 Google Inc.
9
- *
10
- * Permission is hereby granted, free of charge, to any person obtaining a copy
11
- * of this software and associated documentation files (the "Software"), to deal
12
- * in the Software without restriction, including without limitation the rights
13
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
14
- * copies of the Software, and to permit persons to whom the Software is
15
- * furnished to do so, subject to the following conditions:
16
- *
17
- * The above copyright notice and this permission notice shall be included in
18
- * all copies or substantial portions of the Software.
19
- *
20
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
23
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
25
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
26
- * THE SOFTWARE.
27
- */
28
- var cssClasses$1 = {
29
- ANCHOR: 'mdc-menu-surface--anchor',
30
- ANIMATING_CLOSED: 'mdc-menu-surface--animating-closed',
31
- ANIMATING_OPEN: 'mdc-menu-surface--animating-open',
32
- FIXED: 'mdc-menu-surface--fixed',
33
- IS_OPEN_BELOW: 'mdc-menu-surface--is-open-below',
34
- OPEN: 'mdc-menu-surface--open',
35
- ROOT: 'mdc-menu-surface',
36
- };
37
- // tslint:disable:object-literal-sort-keys
38
- var strings$1 = {
39
- CLOSED_EVENT: 'MDCMenuSurface:closed',
40
- CLOSING_EVENT: 'MDCMenuSurface:closing',
41
- OPENED_EVENT: 'MDCMenuSurface:opened',
42
- FOCUSABLE_ELEMENTS: [
43
- 'button:not(:disabled)',
44
- '[href]:not([aria-disabled="true"])',
45
- 'input:not(:disabled)',
46
- 'select:not(:disabled)',
47
- 'textarea:not(:disabled)',
48
- '[tabindex]:not([tabindex="-1"]):not([aria-disabled="true"])',
49
- ].join(', '),
50
- };
51
- // tslint:enable:object-literal-sort-keys
52
- var numbers$1 = {
53
- /** Total duration of menu-surface open animation. */
54
- TRANSITION_OPEN_DURATION: 120,
55
- /** Total duration of menu-surface close animation. */
56
- TRANSITION_CLOSE_DURATION: 75,
57
- /**
58
- * Margin left to the edge of the viewport when menu-surface is at maximum
59
- * possible height. Also used as a viewport margin.
60
- */
61
- MARGIN_TO_EDGE: 32,
62
- /**
63
- * Ratio of anchor width to menu-surface width for switching from corner
64
- * positioning to center positioning.
65
- */
66
- ANCHOR_TO_MENU_SURFACE_WIDTH_RATIO: 0.67,
67
- /**
68
- * Amount of time to wait before restoring focus when closing the menu
69
- * surface. This is important because if a touch event triggered the menu
70
- * close, and the subsequent mouse event occurs after focus is restored, then
71
- * the restored focus would be lost.
72
- */
73
- TOUCH_EVENT_WAIT_MS: 30,
74
- };
75
- /**
76
- * Enum for bits in the {@see Corner) bitmap.
77
- */
78
- var CornerBit;
79
- (function (CornerBit) {
80
- CornerBit[CornerBit["BOTTOM"] = 1] = "BOTTOM";
81
- CornerBit[CornerBit["CENTER"] = 2] = "CENTER";
82
- CornerBit[CornerBit["RIGHT"] = 4] = "RIGHT";
83
- CornerBit[CornerBit["FLIP_RTL"] = 8] = "FLIP_RTL";
84
- })(CornerBit || (CornerBit = {}));
85
- /**
86
- * Enum for representing an element corner for positioning the menu-surface.
87
- *
88
- * The START constants map to LEFT if element directionality is left
89
- * to right and RIGHT if the directionality is right to left.
90
- * Likewise END maps to RIGHT or LEFT depending on the directionality.
91
- */
92
- exports.Corner = void 0;
93
- (function (Corner) {
94
- Corner[Corner["TOP_LEFT"] = 0] = "TOP_LEFT";
95
- Corner[Corner["TOP_RIGHT"] = 4] = "TOP_RIGHT";
96
- Corner[Corner["BOTTOM_LEFT"] = 1] = "BOTTOM_LEFT";
97
- Corner[Corner["BOTTOM_RIGHT"] = 5] = "BOTTOM_RIGHT";
98
- Corner[Corner["TOP_START"] = 8] = "TOP_START";
99
- Corner[Corner["TOP_END"] = 12] = "TOP_END";
100
- Corner[Corner["BOTTOM_START"] = 9] = "BOTTOM_START";
101
- Corner[Corner["BOTTOM_END"] = 13] = "BOTTOM_END";
102
- })(exports.Corner || (exports.Corner = {}));
103
-
104
- /**
105
- * @license
106
- * Copyright 2018 Google Inc.
107
- *
108
- * Permission is hereby granted, free of charge, to any person obtaining a copy
109
- * of this software and associated documentation files (the "Software"), to deal
110
- * in the Software without restriction, including without limitation the rights
111
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
112
- * copies of the Software, and to permit persons to whom the Software is
113
- * furnished to do so, subject to the following conditions:
114
- *
115
- * The above copyright notice and this permission notice shall be included in
116
- * all copies or substantial portions of the Software.
117
- *
118
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
119
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
120
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
121
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
122
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
123
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
124
- * THE SOFTWARE.
125
- */
126
- var _a, _b;
127
- var cssClasses = {
128
- LIST_ITEM_ACTIVATED_CLASS: 'mdc-list-item--activated',
129
- LIST_ITEM_CLASS: 'mdc-list-item',
130
- LIST_ITEM_DISABLED_CLASS: 'mdc-list-item--disabled',
131
- LIST_ITEM_SELECTED_CLASS: 'mdc-list-item--selected',
132
- LIST_ITEM_TEXT_CLASS: 'mdc-list-item__text',
133
- LIST_ITEM_PRIMARY_TEXT_CLASS: 'mdc-list-item__primary-text',
134
- ROOT: 'mdc-list',
135
- };
136
- var evolutionClassNameMap = (_a = {},
137
- _a["" + cssClasses.LIST_ITEM_ACTIVATED_CLASS] = 'mdc-list-item--activated',
138
- _a["" + cssClasses.LIST_ITEM_CLASS] = 'mdc-list-item',
139
- _a["" + cssClasses.LIST_ITEM_DISABLED_CLASS] = 'mdc-list-item--disabled',
140
- _a["" + cssClasses.LIST_ITEM_SELECTED_CLASS] = 'mdc-list-item--selected',
141
- _a["" + cssClasses.LIST_ITEM_PRIMARY_TEXT_CLASS] = 'mdc-list-item__primary-text',
142
- _a["" + cssClasses.ROOT] = 'mdc-list',
143
- _a);
144
- var deprecatedClassNameMap = (_b = {},
145
- _b["" + cssClasses.LIST_ITEM_ACTIVATED_CLASS] = 'mdc-deprecated-list-item--activated',
146
- _b["" + cssClasses.LIST_ITEM_CLASS] = 'mdc-deprecated-list-item',
147
- _b["" + cssClasses.LIST_ITEM_DISABLED_CLASS] = 'mdc-deprecated-list-item--disabled',
148
- _b["" + cssClasses.LIST_ITEM_SELECTED_CLASS] = 'mdc-deprecated-list-item--selected',
149
- _b["" + cssClasses.LIST_ITEM_TEXT_CLASS] = 'mdc-deprecated-list-item__text',
150
- _b["" + cssClasses.LIST_ITEM_PRIMARY_TEXT_CLASS] = 'mdc-deprecated-list-item__primary-text',
151
- _b["" + cssClasses.ROOT] = 'mdc-deprecated-list',
152
- _b);
153
- var strings = {
154
- ACTION_EVENT: 'MDCList:action',
155
- ARIA_CHECKED: 'aria-checked',
156
- ARIA_CHECKED_CHECKBOX_SELECTOR: '[role="checkbox"][aria-checked="true"]',
157
- ARIA_CHECKED_RADIO_SELECTOR: '[role="radio"][aria-checked="true"]',
158
- ARIA_CURRENT: 'aria-current',
159
- ARIA_DISABLED: 'aria-disabled',
160
- ARIA_ORIENTATION: 'aria-orientation',
161
- ARIA_ORIENTATION_HORIZONTAL: 'horizontal',
162
- ARIA_ROLE_CHECKBOX_SELECTOR: '[role="checkbox"]',
163
- ARIA_SELECTED: 'aria-selected',
164
- ARIA_INTERACTIVE_ROLES_SELECTOR: '[role="listbox"], [role="menu"]',
165
- ARIA_MULTI_SELECTABLE_SELECTOR: '[aria-multiselectable="true"]',
166
- CHECKBOX_RADIO_SELECTOR: 'input[type="checkbox"], input[type="radio"]',
167
- CHECKBOX_SELECTOR: 'input[type="checkbox"]',
168
- 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 ",
169
- DEPRECATED_SELECTOR: '.mdc-deprecated-list',
170
- 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 ",
171
- RADIO_SELECTOR: 'input[type="radio"]',
172
- SELECTED_ITEM_SELECTOR: '[aria-selected="true"], [aria-current="true"]',
173
- };
174
- var numbers = {
175
- UNSET_INDEX: -1,
176
- TYPEAHEAD_BUFFER_CLEAR_TIMEOUT_MS: 300
177
- };
178
- var evolutionAttribute = 'evolution';
179
-
180
- /**
181
- * @license
182
- * Copyright 2020 Google Inc.
183
- *
184
- * Permission is hereby granted, free of charge, to any person obtaining a copy
185
- * of this software and associated documentation files (the "Software"), to deal
186
- * in the Software without restriction, including without limitation the rights
187
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
188
- * copies of the Software, and to permit persons to whom the Software is
189
- * furnished to do so, subject to the following conditions:
190
- *
191
- * The above copyright notice and this permission notice shall be included in
192
- * all copies or substantial portions of the Software.
193
- *
194
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
195
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
196
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
197
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
198
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
199
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
200
- * THE SOFTWARE.
201
- */
202
- /**
203
- * KEY provides normalized string values for keys.
204
- */
205
- var KEY = {
206
- UNKNOWN: 'Unknown',
207
- BACKSPACE: 'Backspace',
208
- ENTER: 'Enter',
209
- SPACEBAR: 'Spacebar',
210
- PAGE_UP: 'PageUp',
211
- PAGE_DOWN: 'PageDown',
212
- END: 'End',
213
- HOME: 'Home',
214
- ARROW_LEFT: 'ArrowLeft',
215
- ARROW_UP: 'ArrowUp',
216
- ARROW_RIGHT: 'ArrowRight',
217
- ARROW_DOWN: 'ArrowDown',
218
- DELETE: 'Delete',
219
- ESCAPE: 'Escape',
220
- TAB: 'Tab',
221
- };
222
- var normalizedKeys = new Set();
223
- // IE11 has no support for new Map with iterable so we need to initialize this
224
- // by hand.
225
- normalizedKeys.add(KEY.BACKSPACE);
226
- normalizedKeys.add(KEY.ENTER);
227
- normalizedKeys.add(KEY.SPACEBAR);
228
- normalizedKeys.add(KEY.PAGE_UP);
229
- normalizedKeys.add(KEY.PAGE_DOWN);
230
- normalizedKeys.add(KEY.END);
231
- normalizedKeys.add(KEY.HOME);
232
- normalizedKeys.add(KEY.ARROW_LEFT);
233
- normalizedKeys.add(KEY.ARROW_UP);
234
- normalizedKeys.add(KEY.ARROW_RIGHT);
235
- normalizedKeys.add(KEY.ARROW_DOWN);
236
- normalizedKeys.add(KEY.DELETE);
237
- normalizedKeys.add(KEY.ESCAPE);
238
- normalizedKeys.add(KEY.TAB);
239
- var KEY_CODE = {
240
- BACKSPACE: 8,
241
- ENTER: 13,
242
- SPACEBAR: 32,
243
- PAGE_UP: 33,
244
- PAGE_DOWN: 34,
245
- END: 35,
246
- HOME: 36,
247
- ARROW_LEFT: 37,
248
- ARROW_UP: 38,
249
- ARROW_RIGHT: 39,
250
- ARROW_DOWN: 40,
251
- DELETE: 46,
252
- ESCAPE: 27,
253
- TAB: 9,
254
- };
255
- var mappedKeyCodes = new Map();
256
- // IE11 has no support for new Map with iterable so we need to initialize this
257
- // by hand.
258
- mappedKeyCodes.set(KEY_CODE.BACKSPACE, KEY.BACKSPACE);
259
- mappedKeyCodes.set(KEY_CODE.ENTER, KEY.ENTER);
260
- mappedKeyCodes.set(KEY_CODE.SPACEBAR, KEY.SPACEBAR);
261
- mappedKeyCodes.set(KEY_CODE.PAGE_UP, KEY.PAGE_UP);
262
- mappedKeyCodes.set(KEY_CODE.PAGE_DOWN, KEY.PAGE_DOWN);
263
- mappedKeyCodes.set(KEY_CODE.END, KEY.END);
264
- mappedKeyCodes.set(KEY_CODE.HOME, KEY.HOME);
265
- mappedKeyCodes.set(KEY_CODE.ARROW_LEFT, KEY.ARROW_LEFT);
266
- mappedKeyCodes.set(KEY_CODE.ARROW_UP, KEY.ARROW_UP);
267
- mappedKeyCodes.set(KEY_CODE.ARROW_RIGHT, KEY.ARROW_RIGHT);
268
- mappedKeyCodes.set(KEY_CODE.ARROW_DOWN, KEY.ARROW_DOWN);
269
- mappedKeyCodes.set(KEY_CODE.DELETE, KEY.DELETE);
270
- mappedKeyCodes.set(KEY_CODE.ESCAPE, KEY.ESCAPE);
271
- mappedKeyCodes.set(KEY_CODE.TAB, KEY.TAB);
272
- var navigationKeys = new Set();
273
- // IE11 has no support for new Set with iterable so we need to initialize this
274
- // by hand.
275
- navigationKeys.add(KEY.PAGE_UP);
276
- navigationKeys.add(KEY.PAGE_DOWN);
277
- navigationKeys.add(KEY.END);
278
- navigationKeys.add(KEY.HOME);
279
- navigationKeys.add(KEY.ARROW_LEFT);
280
- navigationKeys.add(KEY.ARROW_UP);
281
- navigationKeys.add(KEY.ARROW_RIGHT);
282
- navigationKeys.add(KEY.ARROW_DOWN);
283
- /**
284
- * normalizeKey returns the normalized string for a navigational action.
285
- */
286
- function normalizeKey(evt) {
287
- var key = evt.key;
288
- // If the event already has a normalized key, return it
289
- if (normalizedKeys.has(key)) {
290
- return key;
291
- }
292
- // tslint:disable-next-line:deprecation
293
- var mappedKey = mappedKeyCodes.get(evt.keyCode);
294
- if (mappedKey) {
295
- return mappedKey;
296
- }
297
- return KEY.UNKNOWN;
298
- }
299
-
300
- /**
301
- * @license
302
- * Copyright 2020 Google Inc.
303
- *
304
- * Permission is hereby granted, free of charge, to any person obtaining a copy
305
- * of this software and associated documentation files (the "Software"), to deal
306
- * in the Software without restriction, including without limitation the rights
307
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
308
- * copies of the Software, and to permit persons to whom the Software is
309
- * furnished to do so, subject to the following conditions:
310
- *
311
- * The above copyright notice and this permission notice shall be included in
312
- * all copies or substantial portions of the Software.
313
- *
314
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
315
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
316
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
317
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
318
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
319
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
320
- * THE SOFTWARE.
321
- */
322
- var ELEMENTS_KEY_ALLOWED_IN = ['input', 'button', 'textarea', 'select'];
323
- /**
324
- * Ensures that preventDefault is only called if the containing element
325
- * doesn't consume the event, and it will cause an unintended scroll.
326
- *
327
- * @param evt keyboard event to be prevented.
328
- */
329
- var preventDefaultEvent = function (evt) {
330
- var target = evt.target;
331
- if (!target) {
332
- return;
333
- }
334
- var tagName = ("" + target.tagName).toLowerCase();
335
- if (ELEMENTS_KEY_ALLOWED_IN.indexOf(tagName) === -1) {
336
- evt.preventDefault();
337
- }
338
- };
339
-
340
- /**
341
- * @license
342
- * Copyright 2020 Google Inc.
343
- *
344
- * Permission is hereby granted, free of charge, to any person obtaining a copy
345
- * of this software and associated documentation files (the "Software"), to deal
346
- * in the Software without restriction, including without limitation the rights
347
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
348
- * copies of the Software, and to permit persons to whom the Software is
349
- * furnished to do so, subject to the following conditions:
350
- *
351
- * The above copyright notice and this permission notice shall be included in
352
- * all copies or substantial portions of the Software.
353
- *
354
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
355
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
356
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
357
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
358
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
359
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
360
- * THE SOFTWARE.
361
- */
362
- /**
363
- * Initializes a state object for typeahead. Use the same reference for calls to
364
- * typeahead functions.
365
- *
366
- * @return The current state of the typeahead process. Each state reference
367
- * represents a typeahead instance as the reference is typically mutated
368
- * in-place.
369
- */
370
- function initState() {
371
- var state = {
372
- bufferClearTimeout: 0,
373
- currentFirstChar: '',
374
- sortedIndexCursor: 0,
375
- typeaheadBuffer: '',
376
- };
377
- return state;
378
- }
379
- /**
380
- * Initializes typeahead state by indexing the current list items by primary
381
- * text into the sortedIndexByFirstChar data structure.
382
- *
383
- * @param listItemCount numer of items in the list
384
- * @param getPrimaryTextByItemIndex function that returns the primary text at a
385
- * given index
386
- *
387
- * @return Map that maps the first character of the primary text to the full
388
- * list text and it's index
389
- */
390
- function initSortedIndex(listItemCount, getPrimaryTextByItemIndex) {
391
- var sortedIndexByFirstChar = new Map();
392
- // Aggregate item text to index mapping
393
- for (var i = 0; i < listItemCount; i++) {
394
- var primaryText = getPrimaryTextByItemIndex(i).trim();
395
- if (!primaryText) {
396
- continue;
397
- }
398
- var firstChar = primaryText[0].toLowerCase();
399
- if (!sortedIndexByFirstChar.has(firstChar)) {
400
- sortedIndexByFirstChar.set(firstChar, []);
401
- }
402
- sortedIndexByFirstChar.get(firstChar).push({ text: primaryText.toLowerCase(), index: i });
403
- }
404
- // Sort the mapping
405
- // TODO(b/157162694): Investigate replacing forEach with Map.values()
406
- sortedIndexByFirstChar.forEach(function (values) {
407
- values.sort(function (first, second) {
408
- return first.index - second.index;
409
- });
410
- });
411
- return sortedIndexByFirstChar;
412
- }
413
- /**
414
- * Given the next desired character from the user, it attempts to find the next
415
- * list option matching the buffer. Wraps around if at the end of options.
416
- *
417
- * @param opts Options and accessors
418
- * - nextChar - the next character to match against items
419
- * - sortedIndexByFirstChar - output of `initSortedIndex(...)`
420
- * - focusedItemIndex - the index of the currently focused item
421
- * - focusItemAtIndex - function that focuses a list item at given index
422
- * - skipFocus - whether or not to focus the matched item
423
- * - isItemAtIndexDisabled - function that determines whether an item at a
424
- * given index is disabled
425
- * @param state The typeahead state instance. See `initState`.
426
- *
427
- * @return The index of the matched item, or -1 if no match.
428
- */
429
- function matchItem(opts, state) {
430
- var nextChar = opts.nextChar, focusItemAtIndex = opts.focusItemAtIndex, sortedIndexByFirstChar = opts.sortedIndexByFirstChar, focusedItemIndex = opts.focusedItemIndex, skipFocus = opts.skipFocus, isItemAtIndexDisabled = opts.isItemAtIndexDisabled;
431
- clearTimeout(state.bufferClearTimeout);
432
- state.bufferClearTimeout = setTimeout(function () {
433
- clearBuffer(state);
434
- }, numbers.TYPEAHEAD_BUFFER_CLEAR_TIMEOUT_MS);
435
- state.typeaheadBuffer = state.typeaheadBuffer + nextChar;
436
- var index;
437
- if (state.typeaheadBuffer.length === 1) {
438
- index = matchFirstChar(sortedIndexByFirstChar, focusedItemIndex, isItemAtIndexDisabled, state);
439
- }
440
- else {
441
- index = matchAllChars(sortedIndexByFirstChar, isItemAtIndexDisabled, state);
442
- }
443
- if (index !== -1 && !skipFocus) {
444
- focusItemAtIndex(index);
445
- }
446
- return index;
447
- }
448
- /**
449
- * Matches the user's single input character in the buffer to the
450
- * next option that begins with such character. Wraps around if at
451
- * end of options. Returns -1 if no match is found.
452
- */
453
- function matchFirstChar(sortedIndexByFirstChar, focusedItemIndex, isItemAtIndexDisabled, state) {
454
- var firstChar = state.typeaheadBuffer[0];
455
- var itemsMatchingFirstChar = sortedIndexByFirstChar.get(firstChar);
456
- if (!itemsMatchingFirstChar) {
457
- return -1;
458
- }
459
- // Has the same firstChar been recently matched?
460
- // Also, did starting index remain the same between key presses?
461
- // If both hold true, simply increment index.
462
- if (firstChar === state.currentFirstChar &&
463
- itemsMatchingFirstChar[state.sortedIndexCursor].index ===
464
- focusedItemIndex) {
465
- state.sortedIndexCursor =
466
- (state.sortedIndexCursor + 1) % itemsMatchingFirstChar.length;
467
- var newIndex = itemsMatchingFirstChar[state.sortedIndexCursor].index;
468
- if (!isItemAtIndexDisabled(newIndex)) {
469
- return newIndex;
470
- }
471
- }
472
- // If we're here, it means one of the following happened:
473
- // - either firstChar or startingIndex has changed, invalidating the
474
- // cursor.
475
- // - The next item of typeahead is disabled, so we have to look further.
476
- state.currentFirstChar = firstChar;
477
- var newCursorPosition = -1;
478
- var cursorPosition;
479
- // Find the first non-disabled item as a fallback.
480
- for (cursorPosition = 0; cursorPosition < itemsMatchingFirstChar.length; cursorPosition++) {
481
- if (!isItemAtIndexDisabled(itemsMatchingFirstChar[cursorPosition].index)) {
482
- newCursorPosition = cursorPosition;
483
- break;
484
- }
485
- }
486
- // Advance cursor to first item matching the firstChar that is positioned
487
- // after starting item. Cursor is unchanged from fallback if there's no
488
- // such item.
489
- for (; cursorPosition < itemsMatchingFirstChar.length; cursorPosition++) {
490
- if (itemsMatchingFirstChar[cursorPosition].index > focusedItemIndex &&
491
- !isItemAtIndexDisabled(itemsMatchingFirstChar[cursorPosition].index)) {
492
- newCursorPosition = cursorPosition;
493
- break;
494
- }
495
- }
496
- if (newCursorPosition !== -1) {
497
- state.sortedIndexCursor = newCursorPosition;
498
- return itemsMatchingFirstChar[state.sortedIndexCursor].index;
499
- }
500
- return -1;
501
- }
502
- /**
503
- * Attempts to find the next item that matches all of the typeahead buffer.
504
- * Wraps around if at end of options. Returns -1 if no match is found.
505
- */
506
- function matchAllChars(sortedIndexByFirstChar, isItemAtIndexDisabled, state) {
507
- var firstChar = state.typeaheadBuffer[0];
508
- var itemsMatchingFirstChar = sortedIndexByFirstChar.get(firstChar);
509
- if (!itemsMatchingFirstChar) {
510
- return -1;
511
- }
512
- // Do nothing if text already matches
513
- var startingItem = itemsMatchingFirstChar[state.sortedIndexCursor];
514
- if (startingItem.text.lastIndexOf(state.typeaheadBuffer, 0) === 0 &&
515
- !isItemAtIndexDisabled(startingItem.index)) {
516
- return startingItem.index;
517
- }
518
- // Find next item that matches completely; if no match, we'll eventually
519
- // loop around to same position
520
- var cursorPosition = (state.sortedIndexCursor + 1) % itemsMatchingFirstChar.length;
521
- var nextCursorPosition = -1;
522
- while (cursorPosition !== state.sortedIndexCursor) {
523
- var currentItem = itemsMatchingFirstChar[cursorPosition];
524
- var matches = currentItem.text.lastIndexOf(state.typeaheadBuffer, 0) === 0;
525
- var isEnabled = !isItemAtIndexDisabled(currentItem.index);
526
- if (matches && isEnabled) {
527
- nextCursorPosition = cursorPosition;
528
- break;
529
- }
530
- cursorPosition = (cursorPosition + 1) % itemsMatchingFirstChar.length;
531
- }
532
- if (nextCursorPosition !== -1) {
533
- state.sortedIndexCursor = nextCursorPosition;
534
- return itemsMatchingFirstChar[state.sortedIndexCursor].index;
535
- }
536
- return -1;
537
- }
538
- /**
539
- * Whether or not the given typeahead instaance state is currently typing.
540
- *
541
- * @param state The typeahead state instance. See `initState`.
542
- */
543
- function isTypingInProgress(state) {
544
- return state.typeaheadBuffer.length > 0;
545
- }
546
- /**
547
- * Clears the typeahaed buffer so that it resets item matching to the first
548
- * character.
549
- *
550
- * @param state The typeahead state instance. See `initState`.
551
- */
552
- function clearBuffer(state) {
553
- state.typeaheadBuffer = '';
554
- }
555
- /**
556
- * Given a keydown event, it calculates whether or not to automatically focus a
557
- * list item depending on what was typed mimicing the typeahead functionality of
558
- * a standard <select> element that is open.
559
- *
560
- * @param opts Options and accessors
561
- * - event - the KeyboardEvent to handle and parse
562
- * - sortedIndexByFirstChar - output of `initSortedIndex(...)`
563
- * - focusedItemIndex - the index of the currently focused item
564
- * - focusItemAtIndex - function that focuses a list item at given index
565
- * - isItemAtFocusedIndexDisabled - whether or not the currently focused item
566
- * is disabled
567
- * - isTargetListItem - whether or not the event target is a list item
568
- * @param state The typeahead state instance. See `initState`.
569
- *
570
- * @returns index of the item matched by the keydown. -1 if not matched.
571
- */
572
- function handleKeydown(opts, state) {
573
- var event = opts.event, isTargetListItem = opts.isTargetListItem, focusedItemIndex = opts.focusedItemIndex, focusItemAtIndex = opts.focusItemAtIndex, sortedIndexByFirstChar = opts.sortedIndexByFirstChar, isItemAtIndexDisabled = opts.isItemAtIndexDisabled;
574
- var isArrowLeft = normalizeKey(event) === 'ArrowLeft';
575
- var isArrowUp = normalizeKey(event) === 'ArrowUp';
576
- var isArrowRight = normalizeKey(event) === 'ArrowRight';
577
- var isArrowDown = normalizeKey(event) === 'ArrowDown';
578
- var isHome = normalizeKey(event) === 'Home';
579
- var isEnd = normalizeKey(event) === 'End';
580
- var isEnter = normalizeKey(event) === 'Enter';
581
- var isSpace = normalizeKey(event) === 'Spacebar';
582
- if (event.ctrlKey || event.metaKey || isArrowLeft || isArrowUp ||
583
- isArrowRight || isArrowDown || isHome || isEnd || isEnter) {
584
- return -1;
585
- }
586
- var isCharacterKey = !isSpace && event.key.length === 1;
587
- if (isCharacterKey) {
588
- preventDefaultEvent(event);
589
- var matchItemOpts = {
590
- focusItemAtIndex: focusItemAtIndex,
591
- focusedItemIndex: focusedItemIndex,
592
- nextChar: event.key.toLowerCase(),
593
- sortedIndexByFirstChar: sortedIndexByFirstChar,
594
- skipFocus: false,
595
- isItemAtIndexDisabled: isItemAtIndexDisabled,
596
- };
597
- return matchItem(matchItemOpts, state);
598
- }
599
- if (!isSpace) {
600
- return -1;
601
- }
602
- if (isTargetListItem) {
603
- preventDefaultEvent(event);
604
- }
605
- var typeaheadOnListItem = isTargetListItem && isTypingInProgress(state);
606
- if (typeaheadOnListItem) {
607
- var matchItemOpts = {
608
- focusItemAtIndex: focusItemAtIndex,
609
- focusedItemIndex: focusedItemIndex,
610
- nextChar: ' ',
611
- sortedIndexByFirstChar: sortedIndexByFirstChar,
612
- skipFocus: false,
613
- isItemAtIndexDisabled: isItemAtIndexDisabled,
614
- };
615
- // space participates in typeahead matching if in rapid typing mode
616
- return matchItem(matchItemOpts, state);
617
- }
618
- return -1;
619
- }
620
-
621
- /**
622
- * @license
623
- * Copyright 2018 Google Inc.
624
- *
625
- * Permission is hereby granted, free of charge, to any person obtaining a copy
626
- * of this software and associated documentation files (the "Software"), to deal
627
- * in the Software without restriction, including without limitation the rights
628
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
629
- * copies of the Software, and to permit persons to whom the Software is
630
- * furnished to do so, subject to the following conditions:
631
- *
632
- * The above copyright notice and this permission notice shall be included in
633
- * all copies or substantial portions of the Software.
634
- *
635
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
636
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
637
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
638
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
639
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
640
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
641
- * THE SOFTWARE.
642
- */
643
- function isNumberArray(selectedIndex) {
644
- return selectedIndex instanceof Array;
645
- }
646
- var MDCListFoundation = /** @class */ (function (_super) {
647
- ponyfill.__extends(MDCListFoundation, _super);
648
- function MDCListFoundation(adapter) {
649
- var _this = _super.call(this, ponyfill.__assign(ponyfill.__assign({}, MDCListFoundation.defaultAdapter), adapter)) || this;
650
- _this.wrapFocus = false;
651
- _this.isVertical = true;
652
- _this.isSingleSelectionList = false;
653
- _this.selectedIndex = numbers.UNSET_INDEX;
654
- _this.focusedItemIndex = numbers.UNSET_INDEX;
655
- _this.useActivatedClass = false;
656
- _this.useSelectedAttr = false;
657
- _this.ariaCurrentAttrValue = null;
658
- _this.isCheckboxList = false;
659
- _this.isRadioList = false;
660
- _this.hasTypeahead = false;
661
- // Transiently holds current typeahead prefix from user.
662
- _this.typeaheadState = initState();
663
- _this.sortedIndexByFirstChar = new Map();
664
- return _this;
665
- }
666
- Object.defineProperty(MDCListFoundation, "strings", {
667
- get: function () {
668
- return strings;
669
- },
670
- enumerable: false,
671
- configurable: true
672
- });
673
- Object.defineProperty(MDCListFoundation, "cssClasses", {
674
- get: function () {
675
- return cssClasses;
676
- },
677
- enumerable: false,
678
- configurable: true
679
- });
680
- Object.defineProperty(MDCListFoundation, "numbers", {
681
- get: function () {
682
- return numbers;
683
- },
684
- enumerable: false,
685
- configurable: true
686
- });
687
- Object.defineProperty(MDCListFoundation, "defaultAdapter", {
688
- get: function () {
689
- return {
690
- addClassForElementIndex: function () { return undefined; },
691
- focusItemAtIndex: function () { return undefined; },
692
- getAttributeForElementIndex: function () { return null; },
693
- getFocusedElementIndex: function () { return 0; },
694
- getListItemCount: function () { return 0; },
695
- hasCheckboxAtIndex: function () { return false; },
696
- hasRadioAtIndex: function () { return false; },
697
- isCheckboxCheckedAtIndex: function () { return false; },
698
- isFocusInsideList: function () { return false; },
699
- isRootFocused: function () { return false; },
700
- listItemAtIndexHasClass: function () { return false; },
701
- notifyAction: function () { return undefined; },
702
- removeClassForElementIndex: function () { return undefined; },
703
- setAttributeForElementIndex: function () { return undefined; },
704
- setCheckedCheckboxOrRadioAtIndex: function () { return undefined; },
705
- setTabIndexForListItemChildren: function () { return undefined; },
706
- getPrimaryTextAtIndex: function () { return ''; },
707
- };
708
- },
709
- enumerable: false,
710
- configurable: true
711
- });
712
- MDCListFoundation.prototype.layout = function () {
713
- if (this.adapter.getListItemCount() === 0) {
714
- return;
715
- }
716
- // TODO(b/172274142): consider all items when determining the list's type.
717
- if (this.adapter.hasCheckboxAtIndex(0)) {
718
- this.isCheckboxList = true;
719
- }
720
- else if (this.adapter.hasRadioAtIndex(0)) {
721
- this.isRadioList = true;
722
- }
723
- else {
724
- this.maybeInitializeSingleSelection();
725
- }
726
- if (this.hasTypeahead) {
727
- this.sortedIndexByFirstChar = this.typeaheadInitSortedIndex();
728
- }
729
- };
730
- /** Returns the index of the item that was last focused. */
731
- MDCListFoundation.prototype.getFocusedItemIndex = function () {
732
- return this.focusedItemIndex;
733
- };
734
- /** Toggles focus wrapping with keyboard navigation. */
735
- MDCListFoundation.prototype.setWrapFocus = function (value) {
736
- this.wrapFocus = value;
737
- };
738
- /**
739
- * Toggles orientation direction for keyboard navigation (true for vertical,
740
- * false for horizontal).
741
- */
742
- MDCListFoundation.prototype.setVerticalOrientation = function (value) {
743
- this.isVertical = value;
744
- };
745
- /** Toggles single-selection behavior. */
746
- MDCListFoundation.prototype.setSingleSelection = function (value) {
747
- this.isSingleSelectionList = value;
748
- if (value) {
749
- this.maybeInitializeSingleSelection();
750
- this.selectedIndex = this.getSelectedIndexFromDOM();
751
- }
752
- };
753
- /**
754
- * Automatically determines whether the list is single selection list. If so,
755
- * initializes the internal state to match the selected item.
756
- */
757
- MDCListFoundation.prototype.maybeInitializeSingleSelection = function () {
758
- var selectedItemIndex = this.getSelectedIndexFromDOM();
759
- if (selectedItemIndex === numbers.UNSET_INDEX)
760
- return;
761
- var hasActivatedClass = this.adapter.listItemAtIndexHasClass(selectedItemIndex, cssClasses.LIST_ITEM_ACTIVATED_CLASS);
762
- if (hasActivatedClass) {
763
- this.setUseActivatedClass(true);
764
- }
765
- this.isSingleSelectionList = true;
766
- this.selectedIndex = selectedItemIndex;
767
- };
768
- /** @return Index of the first selected item based on the DOM state. */
769
- MDCListFoundation.prototype.getSelectedIndexFromDOM = function () {
770
- var selectedIndex = numbers.UNSET_INDEX;
771
- var listItemsCount = this.adapter.getListItemCount();
772
- for (var i = 0; i < listItemsCount; i++) {
773
- var hasSelectedClass = this.adapter.listItemAtIndexHasClass(i, cssClasses.LIST_ITEM_SELECTED_CLASS);
774
- var hasActivatedClass = this.adapter.listItemAtIndexHasClass(i, cssClasses.LIST_ITEM_ACTIVATED_CLASS);
775
- if (!(hasSelectedClass || hasActivatedClass)) {
776
- continue;
777
- }
778
- selectedIndex = i;
779
- break;
780
- }
781
- return selectedIndex;
782
- };
783
- /**
784
- * Sets whether typeahead is enabled on the list.
785
- * @param hasTypeahead Whether typeahead is enabled.
786
- */
787
- MDCListFoundation.prototype.setHasTypeahead = function (hasTypeahead) {
788
- this.hasTypeahead = hasTypeahead;
789
- if (hasTypeahead) {
790
- this.sortedIndexByFirstChar = this.typeaheadInitSortedIndex();
791
- }
792
- };
793
- /**
794
- * @return Whether typeahead is currently matching a user-specified prefix.
795
- */
796
- MDCListFoundation.prototype.isTypeaheadInProgress = function () {
797
- return this.hasTypeahead &&
798
- isTypingInProgress(this.typeaheadState);
799
- };
800
- /** Toggle use of the "activated" CSS class. */
801
- MDCListFoundation.prototype.setUseActivatedClass = function (useActivated) {
802
- this.useActivatedClass = useActivated;
803
- };
804
- /**
805
- * Toggles use of the selected attribute (true for aria-selected, false for
806
- * aria-checked).
807
- */
808
- MDCListFoundation.prototype.setUseSelectedAttribute = function (useSelected) {
809
- this.useSelectedAttr = useSelected;
810
- };
811
- MDCListFoundation.prototype.getSelectedIndex = function () {
812
- return this.selectedIndex;
813
- };
814
- MDCListFoundation.prototype.setSelectedIndex = function (index, _a) {
815
- var _b = _a === void 0 ? {} : _a, forceUpdate = _b.forceUpdate;
816
- if (!this.isIndexValid(index)) {
817
- return;
818
- }
819
- if (this.isCheckboxList) {
820
- this.setCheckboxAtIndex(index);
821
- }
822
- else if (this.isRadioList) {
823
- this.setRadioAtIndex(index);
824
- }
825
- else {
826
- this.setSingleSelectionAtIndex(index, { forceUpdate: forceUpdate });
827
- }
828
- };
829
- /**
830
- * Focus in handler for the list items.
831
- */
832
- MDCListFoundation.prototype.handleFocusIn = function (listItemIndex) {
833
- if (listItemIndex >= 0) {
834
- this.focusedItemIndex = listItemIndex;
835
- this.adapter.setAttributeForElementIndex(listItemIndex, 'tabindex', '0');
836
- this.adapter.setTabIndexForListItemChildren(listItemIndex, '0');
837
- }
838
- };
839
- /**
840
- * Focus out handler for the list items.
841
- */
842
- MDCListFoundation.prototype.handleFocusOut = function (listItemIndex) {
843
- var _this = this;
844
- if (listItemIndex >= 0) {
845
- this.adapter.setAttributeForElementIndex(listItemIndex, 'tabindex', '-1');
846
- this.adapter.setTabIndexForListItemChildren(listItemIndex, '-1');
847
- }
848
- /**
849
- * Between Focusout & Focusin some browsers do not have focus on any
850
- * element. Setting a delay to wait till the focus is moved to next element.
851
- */
852
- setTimeout(function () {
853
- if (!_this.adapter.isFocusInsideList()) {
854
- _this.setTabindexToFirstSelectedOrFocusedItem();
855
- }
856
- }, 0);
857
- };
858
- /**
859
- * Key handler for the list.
860
- */
861
- MDCListFoundation.prototype.handleKeydown = function (event, isRootListItem, listItemIndex) {
862
- var _this = this;
863
- var isArrowLeft = normalizeKey(event) === 'ArrowLeft';
864
- var isArrowUp = normalizeKey(event) === 'ArrowUp';
865
- var isArrowRight = normalizeKey(event) === 'ArrowRight';
866
- var isArrowDown = normalizeKey(event) === 'ArrowDown';
867
- var isHome = normalizeKey(event) === 'Home';
868
- var isEnd = normalizeKey(event) === 'End';
869
- var isEnter = normalizeKey(event) === 'Enter';
870
- var isSpace = normalizeKey(event) === 'Spacebar';
871
- // Have to check both upper and lower case, because having caps lock on
872
- // affects the value.
873
- var isLetterA = event.key === 'A' || event.key === 'a';
874
- if (this.adapter.isRootFocused()) {
875
- if (isArrowUp || isEnd) {
876
- event.preventDefault();
877
- this.focusLastElement();
878
- }
879
- else if (isArrowDown || isHome) {
880
- event.preventDefault();
881
- this.focusFirstElement();
882
- }
883
- if (this.hasTypeahead) {
884
- var handleKeydownOpts = {
885
- event: event,
886
- focusItemAtIndex: function (index) {
887
- _this.focusItemAtIndex(index);
888
- },
889
- focusedItemIndex: -1,
890
- isTargetListItem: isRootListItem,
891
- sortedIndexByFirstChar: this.sortedIndexByFirstChar,
892
- isItemAtIndexDisabled: function (index) {
893
- return _this.adapter.listItemAtIndexHasClass(index, cssClasses.LIST_ITEM_DISABLED_CLASS);
894
- },
895
- };
896
- handleKeydown(handleKeydownOpts, this.typeaheadState);
897
- }
898
- return;
899
- }
900
- var currentIndex = this.adapter.getFocusedElementIndex();
901
- if (currentIndex === -1) {
902
- currentIndex = listItemIndex;
903
- if (currentIndex < 0) {
904
- // If this event doesn't have a mdc-list-item ancestor from the
905
- // current list (not from a sublist), return early.
906
- return;
907
- }
908
- }
909
- if ((this.isVertical && isArrowDown) ||
910
- (!this.isVertical && isArrowRight)) {
911
- preventDefaultEvent(event);
912
- this.focusNextElement(currentIndex);
913
- }
914
- else if ((this.isVertical && isArrowUp) || (!this.isVertical && isArrowLeft)) {
915
- preventDefaultEvent(event);
916
- this.focusPrevElement(currentIndex);
917
- }
918
- else if (isHome) {
919
- preventDefaultEvent(event);
920
- this.focusFirstElement();
921
- }
922
- else if (isEnd) {
923
- preventDefaultEvent(event);
924
- this.focusLastElement();
925
- }
926
- else if (isLetterA && event.ctrlKey && this.isCheckboxList) {
927
- event.preventDefault();
928
- this.toggleAll(this.selectedIndex === numbers.UNSET_INDEX ?
929
- [] :
930
- this.selectedIndex);
931
- }
932
- else if (isEnter || isSpace) {
933
- if (isRootListItem) {
934
- // Return early if enter key is pressed on anchor element which triggers
935
- // synthetic MouseEvent event.
936
- var target = event.target;
937
- if (target && target.tagName === 'A' && isEnter) {
938
- return;
939
- }
940
- preventDefaultEvent(event);
941
- if (this.adapter.listItemAtIndexHasClass(currentIndex, cssClasses.LIST_ITEM_DISABLED_CLASS)) {
942
- return;
943
- }
944
- if (!this.isTypeaheadInProgress()) {
945
- if (this.isSelectableList()) {
946
- this.setSelectedIndexOnAction(currentIndex);
947
- }
948
- this.adapter.notifyAction(currentIndex);
949
- }
950
- }
951
- }
952
- if (this.hasTypeahead) {
953
- var handleKeydownOpts = {
954
- event: event,
955
- focusItemAtIndex: function (index) {
956
- _this.focusItemAtIndex(index);
957
- },
958
- focusedItemIndex: this.focusedItemIndex,
959
- isTargetListItem: isRootListItem,
960
- sortedIndexByFirstChar: this.sortedIndexByFirstChar,
961
- isItemAtIndexDisabled: function (index) { return _this.adapter.listItemAtIndexHasClass(index, cssClasses.LIST_ITEM_DISABLED_CLASS); },
962
- };
963
- handleKeydown(handleKeydownOpts, this.typeaheadState);
964
- }
965
- };
966
- /**
967
- * Click handler for the list.
968
- */
969
- MDCListFoundation.prototype.handleClick = function (index, toggleCheckbox) {
970
- if (index === numbers.UNSET_INDEX) {
971
- return;
972
- }
973
- if (this.adapter.listItemAtIndexHasClass(index, cssClasses.LIST_ITEM_DISABLED_CLASS)) {
974
- return;
975
- }
976
- if (this.isSelectableList()) {
977
- this.setSelectedIndexOnAction(index, toggleCheckbox);
978
- }
979
- this.adapter.notifyAction(index);
980
- };
981
- /**
982
- * Focuses the next element on the list.
983
- */
984
- MDCListFoundation.prototype.focusNextElement = function (index) {
985
- var count = this.adapter.getListItemCount();
986
- var nextIndex = index + 1;
987
- if (nextIndex >= count) {
988
- if (this.wrapFocus) {
989
- nextIndex = 0;
990
- }
991
- else {
992
- // Return early because last item is already focused.
993
- return index;
994
- }
995
- }
996
- this.focusItemAtIndex(nextIndex);
997
- return nextIndex;
998
- };
999
- /**
1000
- * Focuses the previous element on the list.
1001
- */
1002
- MDCListFoundation.prototype.focusPrevElement = function (index) {
1003
- var prevIndex = index - 1;
1004
- if (prevIndex < 0) {
1005
- if (this.wrapFocus) {
1006
- prevIndex = this.adapter.getListItemCount() - 1;
1007
- }
1008
- else {
1009
- // Return early because first item is already focused.
1010
- return index;
1011
- }
1012
- }
1013
- this.focusItemAtIndex(prevIndex);
1014
- return prevIndex;
1015
- };
1016
- MDCListFoundation.prototype.focusFirstElement = function () {
1017
- this.focusItemAtIndex(0);
1018
- return 0;
1019
- };
1020
- MDCListFoundation.prototype.focusLastElement = function () {
1021
- var lastIndex = this.adapter.getListItemCount() - 1;
1022
- this.focusItemAtIndex(lastIndex);
1023
- return lastIndex;
1024
- };
1025
- MDCListFoundation.prototype.focusInitialElement = function () {
1026
- var initialIndex = this.getFirstSelectedOrFocusedItemIndex();
1027
- this.focusItemAtIndex(initialIndex);
1028
- return initialIndex;
1029
- };
1030
- /**
1031
- * @param itemIndex Index of the list item
1032
- * @param isEnabled Sets the list item to enabled or disabled.
1033
- */
1034
- MDCListFoundation.prototype.setEnabled = function (itemIndex, isEnabled) {
1035
- if (!this.isIndexValid(itemIndex)) {
1036
- return;
1037
- }
1038
- if (isEnabled) {
1039
- this.adapter.removeClassForElementIndex(itemIndex, cssClasses.LIST_ITEM_DISABLED_CLASS);
1040
- this.adapter.setAttributeForElementIndex(itemIndex, strings.ARIA_DISABLED, 'false');
1041
- }
1042
- else {
1043
- this.adapter.addClassForElementIndex(itemIndex, cssClasses.LIST_ITEM_DISABLED_CLASS);
1044
- this.adapter.setAttributeForElementIndex(itemIndex, strings.ARIA_DISABLED, 'true');
1045
- }
1046
- };
1047
- MDCListFoundation.prototype.setSingleSelectionAtIndex = function (index, _a) {
1048
- var _b = _a === void 0 ? {} : _a, forceUpdate = _b.forceUpdate;
1049
- if (this.selectedIndex === index && !forceUpdate) {
1050
- return;
1051
- }
1052
- var selectedClassName = cssClasses.LIST_ITEM_SELECTED_CLASS;
1053
- if (this.useActivatedClass) {
1054
- selectedClassName = cssClasses.LIST_ITEM_ACTIVATED_CLASS;
1055
- }
1056
- if (this.selectedIndex !== numbers.UNSET_INDEX) {
1057
- this.adapter.removeClassForElementIndex(this.selectedIndex, selectedClassName);
1058
- }
1059
- this.setAriaForSingleSelectionAtIndex(index);
1060
- this.setTabindexAtIndex(index);
1061
- if (index !== numbers.UNSET_INDEX) {
1062
- this.adapter.addClassForElementIndex(index, selectedClassName);
1063
- }
1064
- this.selectedIndex = index;
1065
- };
1066
- /**
1067
- * Sets aria attribute for single selection at given index.
1068
- */
1069
- MDCListFoundation.prototype.setAriaForSingleSelectionAtIndex = function (index) {
1070
- // Detect the presence of aria-current and get the value only during list
1071
- // initialization when it is in unset state.
1072
- if (this.selectedIndex === numbers.UNSET_INDEX) {
1073
- this.ariaCurrentAttrValue =
1074
- this.adapter.getAttributeForElementIndex(index, strings.ARIA_CURRENT);
1075
- }
1076
- var isAriaCurrent = this.ariaCurrentAttrValue !== null;
1077
- var ariaAttribute = isAriaCurrent ? strings.ARIA_CURRENT : strings.ARIA_SELECTED;
1078
- if (this.selectedIndex !== numbers.UNSET_INDEX) {
1079
- this.adapter.setAttributeForElementIndex(this.selectedIndex, ariaAttribute, 'false');
1080
- }
1081
- if (index !== numbers.UNSET_INDEX) {
1082
- var ariaAttributeValue = isAriaCurrent ? this.ariaCurrentAttrValue : 'true';
1083
- this.adapter.setAttributeForElementIndex(index, ariaAttribute, ariaAttributeValue);
1084
- }
1085
- };
1086
- /**
1087
- * Returns the attribute to use for indicating selection status.
1088
- */
1089
- MDCListFoundation.prototype.getSelectionAttribute = function () {
1090
- return this.useSelectedAttr ? strings.ARIA_SELECTED : strings.ARIA_CHECKED;
1091
- };
1092
- /**
1093
- * Toggles radio at give index. Radio doesn't change the checked state if it
1094
- * is already checked.
1095
- */
1096
- MDCListFoundation.prototype.setRadioAtIndex = function (index) {
1097
- var selectionAttribute = this.getSelectionAttribute();
1098
- this.adapter.setCheckedCheckboxOrRadioAtIndex(index, true);
1099
- if (this.selectedIndex !== numbers.UNSET_INDEX) {
1100
- this.adapter.setAttributeForElementIndex(this.selectedIndex, selectionAttribute, 'false');
1101
- }
1102
- this.adapter.setAttributeForElementIndex(index, selectionAttribute, 'true');
1103
- this.selectedIndex = index;
1104
- };
1105
- MDCListFoundation.prototype.setCheckboxAtIndex = function (index) {
1106
- var selectionAttribute = this.getSelectionAttribute();
1107
- for (var i = 0; i < this.adapter.getListItemCount(); i++) {
1108
- var isChecked = false;
1109
- if (index.indexOf(i) >= 0) {
1110
- isChecked = true;
1111
- }
1112
- this.adapter.setCheckedCheckboxOrRadioAtIndex(i, isChecked);
1113
- this.adapter.setAttributeForElementIndex(i, selectionAttribute, isChecked ? 'true' : 'false');
1114
- }
1115
- this.selectedIndex = index;
1116
- };
1117
- MDCListFoundation.prototype.setTabindexAtIndex = function (index) {
1118
- if (this.focusedItemIndex === numbers.UNSET_INDEX && index !== 0) {
1119
- // If some list item was selected set first list item's tabindex to -1.
1120
- // Generally, tabindex is set to 0 on first list item of list that has no
1121
- // preselected items.
1122
- this.adapter.setAttributeForElementIndex(0, 'tabindex', '-1');
1123
- }
1124
- else if (this.focusedItemIndex >= 0 && this.focusedItemIndex !== index) {
1125
- this.adapter.setAttributeForElementIndex(this.focusedItemIndex, 'tabindex', '-1');
1126
- }
1127
- // Set the previous selection's tabindex to -1. We need this because
1128
- // in selection menus that are not visible, programmatically setting an
1129
- // option will not change focus but will change where tabindex should be 0.
1130
- if (!(this.selectedIndex instanceof Array) &&
1131
- this.selectedIndex !== index) {
1132
- this.adapter.setAttributeForElementIndex(this.selectedIndex, 'tabindex', '-1');
1133
- }
1134
- if (index !== numbers.UNSET_INDEX) {
1135
- this.adapter.setAttributeForElementIndex(index, 'tabindex', '0');
1136
- }
1137
- };
1138
- /**
1139
- * @return Return true if it is single selectin list, checkbox list or radio
1140
- * list.
1141
- */
1142
- MDCListFoundation.prototype.isSelectableList = function () {
1143
- return this.isSingleSelectionList || this.isCheckboxList ||
1144
- this.isRadioList;
1145
- };
1146
- MDCListFoundation.prototype.setTabindexToFirstSelectedOrFocusedItem = function () {
1147
- var targetIndex = this.getFirstSelectedOrFocusedItemIndex();
1148
- this.setTabindexAtIndex(targetIndex);
1149
- };
1150
- MDCListFoundation.prototype.getFirstSelectedOrFocusedItemIndex = function () {
1151
- // Action lists retain focus on the most recently focused item.
1152
- if (!this.isSelectableList()) {
1153
- return Math.max(this.focusedItemIndex, 0);
1154
- }
1155
- // Single-selection lists focus the selected item.
1156
- if (typeof this.selectedIndex === 'number' &&
1157
- this.selectedIndex !== numbers.UNSET_INDEX) {
1158
- return this.selectedIndex;
1159
- }
1160
- // Multiple-selection lists focus the first selected item.
1161
- if (isNumberArray(this.selectedIndex) && this.selectedIndex.length > 0) {
1162
- return this.selectedIndex.reduce(function (minIndex, currentIndex) { return Math.min(minIndex, currentIndex); });
1163
- }
1164
- // Selection lists without a selection focus the first item.
1165
- return 0;
1166
- };
1167
- MDCListFoundation.prototype.isIndexValid = function (index) {
1168
- var _this = this;
1169
- if (index instanceof Array) {
1170
- if (!this.isCheckboxList) {
1171
- throw new Error('MDCListFoundation: Array of index is only supported for checkbox based list');
1172
- }
1173
- if (index.length === 0) {
1174
- return true;
1175
- }
1176
- else {
1177
- return index.some(function (i) { return _this.isIndexInRange(i); });
1178
- }
1179
- }
1180
- else if (typeof index === 'number') {
1181
- if (this.isCheckboxList) {
1182
- throw new Error("MDCListFoundation: Expected array of index for checkbox based list but got number: " + index);
1183
- }
1184
- return this.isIndexInRange(index) ||
1185
- this.isSingleSelectionList && index === numbers.UNSET_INDEX;
1186
- }
1187
- else {
1188
- return false;
1189
- }
1190
- };
1191
- MDCListFoundation.prototype.isIndexInRange = function (index) {
1192
- var listSize = this.adapter.getListItemCount();
1193
- return index >= 0 && index < listSize;
1194
- };
1195
- /**
1196
- * Sets selected index on user action, toggles checkbox / radio based on
1197
- * toggleCheckbox value. User interaction should not toggle list item(s) when
1198
- * disabled.
1199
- */
1200
- MDCListFoundation.prototype.setSelectedIndexOnAction = function (index, toggleCheckbox) {
1201
- if (toggleCheckbox === void 0) { toggleCheckbox = true; }
1202
- if (this.isCheckboxList) {
1203
- this.toggleCheckboxAtIndex(index, toggleCheckbox);
1204
- }
1205
- else {
1206
- this.setSelectedIndex(index);
1207
- }
1208
- };
1209
- MDCListFoundation.prototype.toggleCheckboxAtIndex = function (index, toggleCheckbox) {
1210
- var selectionAttribute = this.getSelectionAttribute();
1211
- var isChecked = this.adapter.isCheckboxCheckedAtIndex(index);
1212
- if (toggleCheckbox) {
1213
- isChecked = !isChecked;
1214
- this.adapter.setCheckedCheckboxOrRadioAtIndex(index, isChecked);
1215
- }
1216
- this.adapter.setAttributeForElementIndex(index, selectionAttribute, isChecked ? 'true' : 'false');
1217
- // If none of the checkbox items are selected and selectedIndex is not
1218
- // initialized then provide a default value.
1219
- var selectedIndexes = this.selectedIndex === numbers.UNSET_INDEX ?
1220
- [] :
1221
- this.selectedIndex.slice();
1222
- if (isChecked) {
1223
- selectedIndexes.push(index);
1224
- }
1225
- else {
1226
- selectedIndexes = selectedIndexes.filter(function (i) { return i !== index; });
1227
- }
1228
- this.selectedIndex = selectedIndexes;
1229
- };
1230
- MDCListFoundation.prototype.focusItemAtIndex = function (index) {
1231
- this.adapter.focusItemAtIndex(index);
1232
- this.focusedItemIndex = index;
1233
- };
1234
- MDCListFoundation.prototype.toggleAll = function (currentlySelectedIndexes) {
1235
- var count = this.adapter.getListItemCount();
1236
- // If all items are selected, deselect everything.
1237
- if (currentlySelectedIndexes.length === count) {
1238
- this.setCheckboxAtIndex([]);
1239
- }
1240
- else {
1241
- // Otherwise select all enabled options.
1242
- var allIndexes = [];
1243
- for (var i = 0; i < count; i++) {
1244
- if (!this.adapter.listItemAtIndexHasClass(i, cssClasses.LIST_ITEM_DISABLED_CLASS) ||
1245
- currentlySelectedIndexes.indexOf(i) > -1) {
1246
- allIndexes.push(i);
1247
- }
1248
- }
1249
- this.setCheckboxAtIndex(allIndexes);
1250
- }
1251
- };
1252
- /**
1253
- * Given the next desired character from the user, adds it to the typeahead
1254
- * buffer. Then, attempts to find the next option matching the buffer. Wraps
1255
- * around if at the end of options.
1256
- *
1257
- * @param nextChar The next character to add to the prefix buffer.
1258
- * @param startingIndex The index from which to start matching. Only relevant
1259
- * when starting a new match sequence. To start a new match sequence,
1260
- * clear the buffer using `clearTypeaheadBuffer`, or wait for the buffer
1261
- * to clear after a set interval defined in list foundation. Defaults to
1262
- * the currently focused index.
1263
- * @return The index of the matched item, or -1 if no match.
1264
- */
1265
- MDCListFoundation.prototype.typeaheadMatchItem = function (nextChar, startingIndex, skipFocus) {
1266
- var _this = this;
1267
- if (skipFocus === void 0) { skipFocus = false; }
1268
- var opts = {
1269
- focusItemAtIndex: function (index) {
1270
- _this.focusItemAtIndex(index);
1271
- },
1272
- focusedItemIndex: startingIndex ? startingIndex : this.focusedItemIndex,
1273
- nextChar: nextChar,
1274
- sortedIndexByFirstChar: this.sortedIndexByFirstChar,
1275
- skipFocus: skipFocus,
1276
- isItemAtIndexDisabled: function (index) { return _this.adapter.listItemAtIndexHasClass(index, cssClasses.LIST_ITEM_DISABLED_CLASS); }
1277
- };
1278
- return matchItem(opts, this.typeaheadState);
1279
- };
1280
- /**
1281
- * Initializes the MDCListTextAndIndex data structure by indexing the current
1282
- * list items by primary text.
1283
- *
1284
- * @return The primary texts of all the list items sorted by first character.
1285
- */
1286
- MDCListFoundation.prototype.typeaheadInitSortedIndex = function () {
1287
- return initSortedIndex(this.adapter.getListItemCount(), this.adapter.getPrimaryTextAtIndex);
1288
- };
1289
- /**
1290
- * Clears the typeahead buffer.
1291
- */
1292
- MDCListFoundation.prototype.clearTypeaheadBuffer = function () {
1293
- clearBuffer(this.typeaheadState);
1294
- };
1295
- return MDCListFoundation;
1296
- }(ponyfill.MDCFoundation));
1297
-
1298
- /**
1299
- * @license
1300
- * Copyright 2018 Google Inc.
1301
- *
1302
- * Permission is hereby granted, free of charge, to any person obtaining a copy
1303
- * of this software and associated documentation files (the "Software"), to deal
1304
- * in the Software without restriction, including without limitation the rights
1305
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
1306
- * copies of the Software, and to permit persons to whom the Software is
1307
- * furnished to do so, subject to the following conditions:
1308
- *
1309
- * The above copyright notice and this permission notice shall be included in
1310
- * all copies or substantial portions of the Software.
1311
- *
1312
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
1313
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
1314
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
1315
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
1316
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
1317
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
1318
- * THE SOFTWARE.
1319
- */
1320
- var MDCList = /** @class */ (function (_super) {
1321
- ponyfill.__extends(MDCList, _super);
1322
- function MDCList() {
1323
- return _super !== null && _super.apply(this, arguments) || this;
1324
- }
1325
- Object.defineProperty(MDCList.prototype, "vertical", {
1326
- set: function (value) {
1327
- this.foundation.setVerticalOrientation(value);
1328
- },
1329
- enumerable: false,
1330
- configurable: true
1331
- });
1332
- Object.defineProperty(MDCList.prototype, "listElements", {
1333
- get: function () {
1334
- return Array.from(this.root.querySelectorAll("." + this.classNameMap[cssClasses.LIST_ITEM_CLASS]));
1335
- },
1336
- enumerable: false,
1337
- configurable: true
1338
- });
1339
- Object.defineProperty(MDCList.prototype, "wrapFocus", {
1340
- set: function (value) {
1341
- this.foundation.setWrapFocus(value);
1342
- },
1343
- enumerable: false,
1344
- configurable: true
1345
- });
1346
- Object.defineProperty(MDCList.prototype, "typeaheadInProgress", {
1347
- /**
1348
- * @return Whether typeahead is currently matching a user-specified prefix.
1349
- */
1350
- get: function () {
1351
- return this.foundation.isTypeaheadInProgress();
1352
- },
1353
- enumerable: false,
1354
- configurable: true
1355
- });
1356
- Object.defineProperty(MDCList.prototype, "hasTypeahead", {
1357
- /**
1358
- * Sets whether typeahead functionality is enabled on the list.
1359
- * @param hasTypeahead Whether typeahead is enabled.
1360
- */
1361
- set: function (hasTypeahead) {
1362
- this.foundation.setHasTypeahead(hasTypeahead);
1363
- },
1364
- enumerable: false,
1365
- configurable: true
1366
- });
1367
- Object.defineProperty(MDCList.prototype, "singleSelection", {
1368
- set: function (isSingleSelectionList) {
1369
- this.foundation.setSingleSelection(isSingleSelectionList);
1370
- },
1371
- enumerable: false,
1372
- configurable: true
1373
- });
1374
- Object.defineProperty(MDCList.prototype, "selectedIndex", {
1375
- get: function () {
1376
- return this.foundation.getSelectedIndex();
1377
- },
1378
- set: function (index) {
1379
- this.foundation.setSelectedIndex(index);
1380
- },
1381
- enumerable: false,
1382
- configurable: true
1383
- });
1384
- MDCList.attachTo = function (root) {
1385
- return new MDCList(root);
1386
- };
1387
- MDCList.prototype.initialSyncWithDOM = function () {
1388
- this.isEvolutionEnabled =
1389
- evolutionAttribute in this.root.dataset;
1390
- if (this.isEvolutionEnabled) {
1391
- this.classNameMap = evolutionClassNameMap;
1392
- }
1393
- else if (ponyfill.matches(this.root, strings.DEPRECATED_SELECTOR)) {
1394
- this.classNameMap = deprecatedClassNameMap;
1395
- }
1396
- else {
1397
- this.classNameMap =
1398
- Object.values(cssClasses)
1399
- .reduce(function (obj, className) {
1400
- obj[className] = className;
1401
- return obj;
1402
- }, {});
1403
- }
1404
- this.handleClick = this.handleClickEvent.bind(this);
1405
- this.handleKeydown = this.handleKeydownEvent.bind(this);
1406
- this.focusInEventListener = this.handleFocusInEvent.bind(this);
1407
- this.focusOutEventListener = this.handleFocusOutEvent.bind(this);
1408
- this.listen('keydown', this.handleKeydown);
1409
- this.listen('click', this.handleClick);
1410
- this.listen('focusin', this.focusInEventListener);
1411
- this.listen('focusout', this.focusOutEventListener);
1412
- this.layout();
1413
- this.initializeListType();
1414
- this.ensureFocusable();
1415
- };
1416
- MDCList.prototype.destroy = function () {
1417
- this.unlisten('keydown', this.handleKeydown);
1418
- this.unlisten('click', this.handleClick);
1419
- this.unlisten('focusin', this.focusInEventListener);
1420
- this.unlisten('focusout', this.focusOutEventListener);
1421
- };
1422
- MDCList.prototype.layout = function () {
1423
- var direction = this.root.getAttribute(strings.ARIA_ORIENTATION);
1424
- this.vertical = direction !== strings.ARIA_ORIENTATION_HORIZONTAL;
1425
- var itemSelector = "." + this.classNameMap[cssClasses.LIST_ITEM_CLASS] + ":not([tabindex])";
1426
- var childSelector = strings.FOCUSABLE_CHILD_ELEMENTS;
1427
- // List items need to have at least tabindex=-1 to be focusable.
1428
- var itemEls = this.root.querySelectorAll(itemSelector);
1429
- if (itemEls.length) {
1430
- Array.prototype.forEach.call(itemEls, function (el) {
1431
- el.setAttribute('tabindex', '-1');
1432
- });
1433
- }
1434
- // Child button/a elements are not tabbable until the list item is focused.
1435
- var focusableChildEls = this.root.querySelectorAll(childSelector);
1436
- if (focusableChildEls.length) {
1437
- Array.prototype.forEach.call(focusableChildEls, function (el) {
1438
- el.setAttribute('tabindex', '-1');
1439
- });
1440
- }
1441
- if (this.isEvolutionEnabled) {
1442
- this.foundation.setUseSelectedAttribute(true);
1443
- }
1444
- this.foundation.layout();
1445
- };
1446
- /**
1447
- * Extracts the primary text from a list item.
1448
- * @param item The list item element.
1449
- * @return The primary text in the element.
1450
- */
1451
- MDCList.prototype.getPrimaryText = function (item) {
1452
- var _a;
1453
- var primaryText = item.querySelector("." + this.classNameMap[cssClasses.LIST_ITEM_PRIMARY_TEXT_CLASS]);
1454
- if (this.isEvolutionEnabled || primaryText) {
1455
- return (_a = primaryText === null || primaryText === void 0 ? void 0 : primaryText.textContent) !== null && _a !== void 0 ? _a : '';
1456
- }
1457
- var singleLineText = item.querySelector("." + this.classNameMap[cssClasses.LIST_ITEM_TEXT_CLASS]);
1458
- return (singleLineText && singleLineText.textContent) || '';
1459
- };
1460
- /**
1461
- * Initialize selectedIndex value based on pre-selected list items.
1462
- */
1463
- MDCList.prototype.initializeListType = function () {
1464
- var _this = this;
1465
- this.isInteractive =
1466
- ponyfill.matches(this.root, strings.ARIA_INTERACTIVE_ROLES_SELECTOR);
1467
- if (this.isEvolutionEnabled && this.isInteractive) {
1468
- var selection = Array.from(this.root.querySelectorAll(strings.SELECTED_ITEM_SELECTOR), function (listItem) { return _this.listElements.indexOf(listItem); });
1469
- if (ponyfill.matches(this.root, strings.ARIA_MULTI_SELECTABLE_SELECTOR)) {
1470
- this.selectedIndex = selection;
1471
- }
1472
- else if (selection.length > 0) {
1473
- this.selectedIndex = selection[0];
1474
- }
1475
- return;
1476
- }
1477
- var checkboxListItems = this.root.querySelectorAll(strings.ARIA_ROLE_CHECKBOX_SELECTOR);
1478
- var radioSelectedListItem = this.root.querySelector(strings.ARIA_CHECKED_RADIO_SELECTOR);
1479
- if (checkboxListItems.length) {
1480
- var preselectedItems = this.root.querySelectorAll(strings.ARIA_CHECKED_CHECKBOX_SELECTOR);
1481
- this.selectedIndex = Array.from(preselectedItems, function (listItem) { return _this.listElements.indexOf(listItem); });
1482
- }
1483
- else if (radioSelectedListItem) {
1484
- this.selectedIndex = this.listElements.indexOf(radioSelectedListItem);
1485
- }
1486
- };
1487
- /**
1488
- * Updates the list item at itemIndex to the desired isEnabled state.
1489
- * @param itemIndex Index of the list item
1490
- * @param isEnabled Sets the list item to enabled or disabled.
1491
- */
1492
- MDCList.prototype.setEnabled = function (itemIndex, isEnabled) {
1493
- this.foundation.setEnabled(itemIndex, isEnabled);
1494
- };
1495
- /**
1496
- * Given the next desired character from the user, adds it to the typeahead
1497
- * buffer. Then, attempts to find the next option matching the buffer. Wraps
1498
- * around if at the end of options.
1499
- *
1500
- * @param nextChar The next character to add to the prefix buffer.
1501
- * @param startingIndex The index from which to start matching. Defaults to
1502
- * the currently focused index.
1503
- * @return The index of the matched item.
1504
- */
1505
- MDCList.prototype.typeaheadMatchItem = function (nextChar, startingIndex) {
1506
- return this.foundation.typeaheadMatchItem(nextChar, startingIndex, /** skipFocus */ true);
1507
- };
1508
- MDCList.prototype.getDefaultFoundation = function () {
1509
- var _this = this;
1510
- // DO NOT INLINE this variable. For backward compatibility, foundations take
1511
- // a Partial<MDCFooAdapter>. To ensure we don't accidentally omit any
1512
- // methods, we need a separate, strongly typed adapter variable.
1513
- var adapter = {
1514
- addClassForElementIndex: function (index, className) {
1515
- var element = _this.listElements[index];
1516
- if (element) {
1517
- element.classList.add(_this.classNameMap[className]);
1518
- }
1519
- },
1520
- focusItemAtIndex: function (index) {
1521
- var element = _this.listElements[index];
1522
- if (element) {
1523
- element.focus();
1524
- }
1525
- },
1526
- getAttributeForElementIndex: function (index, attr) {
1527
- return _this.listElements[index].getAttribute(attr);
1528
- },
1529
- getFocusedElementIndex: function () {
1530
- return _this.listElements.indexOf(document.activeElement);
1531
- },
1532
- getListItemCount: function () { return _this.listElements.length; },
1533
- getPrimaryTextAtIndex: function (index) {
1534
- return _this.getPrimaryText(_this.listElements[index]);
1535
- },
1536
- hasCheckboxAtIndex: function (index) {
1537
- var listItem = _this.listElements[index];
1538
- return !!listItem.querySelector(strings.CHECKBOX_SELECTOR);
1539
- },
1540
- hasRadioAtIndex: function (index) {
1541
- var listItem = _this.listElements[index];
1542
- return !!listItem.querySelector(strings.RADIO_SELECTOR);
1543
- },
1544
- isCheckboxCheckedAtIndex: function (index) {
1545
- var listItem = _this.listElements[index];
1546
- var toggleEl = listItem.querySelector(strings.CHECKBOX_SELECTOR);
1547
- return toggleEl.checked;
1548
- },
1549
- isFocusInsideList: function () {
1550
- return _this.root !== document.activeElement &&
1551
- _this.root.contains(document.activeElement);
1552
- },
1553
- isRootFocused: function () { return document.activeElement === _this.root; },
1554
- listItemAtIndexHasClass: function (index, className) {
1555
- return _this.listElements[index].classList.contains(_this.classNameMap[className]);
1556
- },
1557
- notifyAction: function (index) {
1558
- _this.emit(strings.ACTION_EVENT, { index: index }, /** shouldBubble */ true);
1559
- },
1560
- removeClassForElementIndex: function (index, className) {
1561
- var element = _this.listElements[index];
1562
- if (element) {
1563
- element.classList.remove(_this.classNameMap[className]);
1564
- }
1565
- },
1566
- setAttributeForElementIndex: function (index, attr, value) {
1567
- var element = _this.listElements[index];
1568
- if (element) {
1569
- element.setAttribute(attr, value);
1570
- }
1571
- },
1572
- setCheckedCheckboxOrRadioAtIndex: function (index, isChecked) {
1573
- var listItem = _this.listElements[index];
1574
- var toggleEl = listItem.querySelector(strings.CHECKBOX_RADIO_SELECTOR);
1575
- toggleEl.checked = isChecked;
1576
- var event = document.createEvent('Event');
1577
- event.initEvent('change', true, true);
1578
- toggleEl.dispatchEvent(event);
1579
- },
1580
- setTabIndexForListItemChildren: function (listItemIndex, tabIndexValue) {
1581
- var element = _this.listElements[listItemIndex];
1582
- var selector = strings.CHILD_ELEMENTS_TO_TOGGLE_TABINDEX;
1583
- Array.prototype.forEach.call(element.querySelectorAll(selector), function (el) {
1584
- el.setAttribute('tabindex', tabIndexValue);
1585
- });
1586
- },
1587
- };
1588
- return new MDCListFoundation(adapter);
1589
- };
1590
- /**
1591
- * Ensures that at least one item is focusable if the list is interactive and
1592
- * doesn't specify a suitable tabindex.
1593
- */
1594
- MDCList.prototype.ensureFocusable = function () {
1595
- if (this.isEvolutionEnabled && this.isInteractive) {
1596
- if (!this.root.querySelector("." + this.classNameMap[cssClasses.LIST_ITEM_CLASS] + "[tabindex=\"0\"]")) {
1597
- var index = this.initialFocusIndex();
1598
- if (index !== -1) {
1599
- this.listElements[index].tabIndex = 0;
1600
- }
1601
- }
1602
- }
1603
- };
1604
- MDCList.prototype.initialFocusIndex = function () {
1605
- if (this.selectedIndex instanceof Array && this.selectedIndex.length > 0) {
1606
- return this.selectedIndex[0];
1607
- }
1608
- if (typeof this.selectedIndex === 'number' &&
1609
- this.selectedIndex !== numbers.UNSET_INDEX) {
1610
- return this.selectedIndex;
1611
- }
1612
- var el = this.root.querySelector("." + this.classNameMap[cssClasses.LIST_ITEM_CLASS] + ":not(." + this.classNameMap[cssClasses.LIST_ITEM_DISABLED_CLASS] + ")");
1613
- if (el === null) {
1614
- return -1;
1615
- }
1616
- return this.getListItemIndex(el);
1617
- };
1618
- /**
1619
- * Used to figure out which list item this event is targetting. Or returns -1
1620
- * if there is no list item
1621
- */
1622
- MDCList.prototype.getListItemIndex = function (el) {
1623
- var nearestParent = ponyfill.closest(el, "." + this.classNameMap[cssClasses.LIST_ITEM_CLASS] + ", ." + this.classNameMap[cssClasses.ROOT]);
1624
- // Get the index of the element if it is a list item.
1625
- if (nearestParent &&
1626
- ponyfill.matches(nearestParent, "." + this.classNameMap[cssClasses.LIST_ITEM_CLASS])) {
1627
- return this.listElements.indexOf(nearestParent);
1628
- }
1629
- return -1;
1630
- };
1631
- /**
1632
- * Used to figure out which element was clicked before sending the event to
1633
- * the foundation.
1634
- */
1635
- MDCList.prototype.handleFocusInEvent = function (evt) {
1636
- var index = this.getListItemIndex(evt.target);
1637
- this.foundation.handleFocusIn(index);
1638
- };
1639
- /**
1640
- * Used to figure out which element was clicked before sending the event to
1641
- * the foundation.
1642
- */
1643
- MDCList.prototype.handleFocusOutEvent = function (evt) {
1644
- var index = this.getListItemIndex(evt.target);
1645
- this.foundation.handleFocusOut(index);
1646
- };
1647
- /**
1648
- * Used to figure out which element was focused when keydown event occurred
1649
- * before sending the event to the foundation.
1650
- */
1651
- MDCList.prototype.handleKeydownEvent = function (evt) {
1652
- var index = this.getListItemIndex(evt.target);
1653
- var target = evt.target;
1654
- this.foundation.handleKeydown(evt, target.classList.contains(this.classNameMap[cssClasses.LIST_ITEM_CLASS]), index);
1655
- };
1656
- /**
1657
- * Used to figure out which element was clicked before sending the event to
1658
- * the foundation.
1659
- */
1660
- MDCList.prototype.handleClickEvent = function (evt) {
1661
- var index = this.getListItemIndex(evt.target);
1662
- var target = evt.target;
1663
- // Toggle the checkbox only if it's not the target of the event, or the
1664
- // checkbox will have 2 change events.
1665
- var toggleCheckbox = !ponyfill.matches(target, strings.CHECKBOX_RADIO_SELECTOR);
1666
- this.foundation.handleClick(index, toggleCheckbox);
1667
- };
1668
- return MDCList;
1669
- }(ponyfill.MDCComponent));
1670
-
1671
- /**
1672
- * @license
1673
- * Copyright 2018 Google Inc.
1674
- *
1675
- * Permission is hereby granted, free of charge, to any person obtaining a copy
1676
- * of this software and associated documentation files (the "Software"), to deal
1677
- * in the Software without restriction, including without limitation the rights
1678
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
1679
- * copies of the Software, and to permit persons to whom the Software is
1680
- * furnished to do so, subject to the following conditions:
1681
- *
1682
- * The above copyright notice and this permission notice shall be included in
1683
- * all copies or substantial portions of the Software.
1684
- *
1685
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
1686
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
1687
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
1688
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
1689
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
1690
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
1691
- * THE SOFTWARE.
1692
- */
1693
- var MDCMenuSurfaceFoundation = /** @class */ (function (_super) {
1694
- ponyfill.__extends(MDCMenuSurfaceFoundation, _super);
1695
- function MDCMenuSurfaceFoundation(adapter) {
1696
- var _this = _super.call(this, ponyfill.__assign(ponyfill.__assign({}, MDCMenuSurfaceFoundation.defaultAdapter), adapter)) || this;
1697
- _this.isSurfaceOpen = false;
1698
- _this.isQuickOpen = false;
1699
- _this.isHoistedElement = false;
1700
- _this.isFixedPosition = false;
1701
- _this.isHorizontallyCenteredOnViewport = false;
1702
- _this.maxHeight = 0;
1703
- _this.openAnimationEndTimerId = 0;
1704
- _this.closeAnimationEndTimerId = 0;
1705
- _this.animationRequestId = 0;
1706
- _this.anchorCorner = exports.Corner.TOP_START;
1707
- /**
1708
- * Corner of the menu surface to which menu surface is attached to anchor.
1709
- *
1710
- * Anchor corner --->+----------+
1711
- * | ANCHOR |
1712
- * +----------+
1713
- * Origin corner --->+--------------+
1714
- * | |
1715
- * | |
1716
- * | MENU SURFACE |
1717
- * | |
1718
- * | |
1719
- * +--------------+
1720
- */
1721
- _this.originCorner = exports.Corner.TOP_START;
1722
- _this.anchorMargin = { top: 0, right: 0, bottom: 0, left: 0 };
1723
- _this.position = { x: 0, y: 0 };
1724
- return _this;
1725
- }
1726
- Object.defineProperty(MDCMenuSurfaceFoundation, "cssClasses", {
1727
- get: function () {
1728
- return cssClasses$1;
1729
- },
1730
- enumerable: false,
1731
- configurable: true
1732
- });
1733
- Object.defineProperty(MDCMenuSurfaceFoundation, "strings", {
1734
- get: function () {
1735
- return strings$1;
1736
- },
1737
- enumerable: false,
1738
- configurable: true
1739
- });
1740
- Object.defineProperty(MDCMenuSurfaceFoundation, "numbers", {
1741
- get: function () {
1742
- return numbers$1;
1743
- },
1744
- enumerable: false,
1745
- configurable: true
1746
- });
1747
- Object.defineProperty(MDCMenuSurfaceFoundation, "Corner", {
1748
- get: function () {
1749
- return exports.Corner;
1750
- },
1751
- enumerable: false,
1752
- configurable: true
1753
- });
1754
- Object.defineProperty(MDCMenuSurfaceFoundation, "defaultAdapter", {
1755
- /**
1756
- * @see {@link MDCMenuSurfaceAdapter} for typing information on parameters and return types.
1757
- */
1758
- get: function () {
1759
- // tslint:disable:object-literal-sort-keys Methods should be in the same order as the adapter interface.
1760
- return {
1761
- addClass: function () { return undefined; },
1762
- removeClass: function () { return undefined; },
1763
- hasClass: function () { return false; },
1764
- hasAnchor: function () { return false; },
1765
- isElementInContainer: function () { return false; },
1766
- isFocused: function () { return false; },
1767
- isRtl: function () { return false; },
1768
- getInnerDimensions: function () { return ({ height: 0, width: 0 }); },
1769
- getAnchorDimensions: function () { return null; },
1770
- getWindowDimensions: function () { return ({ height: 0, width: 0 }); },
1771
- getBodyDimensions: function () { return ({ height: 0, width: 0 }); },
1772
- getWindowScroll: function () { return ({ x: 0, y: 0 }); },
1773
- setPosition: function () { return undefined; },
1774
- setMaxHeight: function () { return undefined; },
1775
- setTransformOrigin: function () { return undefined; },
1776
- saveFocus: function () { return undefined; },
1777
- restoreFocus: function () { return undefined; },
1778
- notifyClose: function () { return undefined; },
1779
- notifyOpen: function () { return undefined; },
1780
- notifyClosing: function () { return undefined; },
1781
- };
1782
- // tslint:enable:object-literal-sort-keys
1783
- },
1784
- enumerable: false,
1785
- configurable: true
1786
- });
1787
- MDCMenuSurfaceFoundation.prototype.init = function () {
1788
- var _a = MDCMenuSurfaceFoundation.cssClasses, ROOT = _a.ROOT, OPEN = _a.OPEN;
1789
- if (!this.adapter.hasClass(ROOT)) {
1790
- throw new Error(ROOT + " class required in root element.");
1791
- }
1792
- if (this.adapter.hasClass(OPEN)) {
1793
- this.isSurfaceOpen = true;
1794
- }
1795
- };
1796
- MDCMenuSurfaceFoundation.prototype.destroy = function () {
1797
- clearTimeout(this.openAnimationEndTimerId);
1798
- clearTimeout(this.closeAnimationEndTimerId);
1799
- // Cancel any currently running animations.
1800
- cancelAnimationFrame(this.animationRequestId);
1801
- };
1802
- /**
1803
- * @param corner Default anchor corner alignment of top-left menu surface
1804
- * corner.
1805
- */
1806
- MDCMenuSurfaceFoundation.prototype.setAnchorCorner = function (corner) {
1807
- this.anchorCorner = corner;
1808
- };
1809
- /**
1810
- * Flip menu corner horizontally.
1811
- */
1812
- MDCMenuSurfaceFoundation.prototype.flipCornerHorizontally = function () {
1813
- this.originCorner = this.originCorner ^ CornerBit.RIGHT;
1814
- };
1815
- /**
1816
- * @param margin Set of margin values from anchor.
1817
- */
1818
- MDCMenuSurfaceFoundation.prototype.setAnchorMargin = function (margin) {
1819
- this.anchorMargin.top = margin.top || 0;
1820
- this.anchorMargin.right = margin.right || 0;
1821
- this.anchorMargin.bottom = margin.bottom || 0;
1822
- this.anchorMargin.left = margin.left || 0;
1823
- };
1824
- /** Used to indicate if the menu-surface is hoisted to the body. */
1825
- MDCMenuSurfaceFoundation.prototype.setIsHoisted = function (isHoisted) {
1826
- this.isHoistedElement = isHoisted;
1827
- };
1828
- /**
1829
- * Used to set the menu-surface calculations based on a fixed position menu.
1830
- */
1831
- MDCMenuSurfaceFoundation.prototype.setFixedPosition = function (isFixedPosition) {
1832
- this.isFixedPosition = isFixedPosition;
1833
- };
1834
- /**
1835
- * @return Returns true if menu is in fixed (`position: fixed`) position.
1836
- */
1837
- MDCMenuSurfaceFoundation.prototype.isFixed = function () {
1838
- return this.isFixedPosition;
1839
- };
1840
- /** Sets the menu-surface position on the page. */
1841
- MDCMenuSurfaceFoundation.prototype.setAbsolutePosition = function (x, y) {
1842
- this.position.x = this.isFinite(x) ? x : 0;
1843
- this.position.y = this.isFinite(y) ? y : 0;
1844
- };
1845
- /** Sets whether menu-surface should be horizontally centered to viewport. */
1846
- MDCMenuSurfaceFoundation.prototype.setIsHorizontallyCenteredOnViewport = function (isCentered) {
1847
- this.isHorizontallyCenteredOnViewport = isCentered;
1848
- };
1849
- MDCMenuSurfaceFoundation.prototype.setQuickOpen = function (quickOpen) {
1850
- this.isQuickOpen = quickOpen;
1851
- };
1852
- /**
1853
- * Sets maximum menu-surface height on open.
1854
- * @param maxHeight The desired max-height. Set to 0 (default) to
1855
- * automatically calculate max height based on available viewport space.
1856
- */
1857
- MDCMenuSurfaceFoundation.prototype.setMaxHeight = function (maxHeight) {
1858
- this.maxHeight = maxHeight;
1859
- };
1860
- MDCMenuSurfaceFoundation.prototype.isOpen = function () {
1861
- return this.isSurfaceOpen;
1862
- };
1863
- /**
1864
- * Open the menu surface.
1865
- */
1866
- MDCMenuSurfaceFoundation.prototype.open = function () {
1867
- var _this = this;
1868
- if (this.isSurfaceOpen) {
1869
- return;
1870
- }
1871
- this.adapter.saveFocus();
1872
- if (this.isQuickOpen) {
1873
- this.isSurfaceOpen = true;
1874
- this.adapter.addClass(MDCMenuSurfaceFoundation.cssClasses.OPEN);
1875
- this.dimensions = this.adapter.getInnerDimensions();
1876
- this.autoposition();
1877
- this.adapter.notifyOpen();
1878
- }
1879
- else {
1880
- this.adapter.addClass(MDCMenuSurfaceFoundation.cssClasses.ANIMATING_OPEN);
1881
- this.animationRequestId = requestAnimationFrame(function () {
1882
- _this.dimensions = _this.adapter.getInnerDimensions();
1883
- _this.autoposition();
1884
- _this.adapter.addClass(MDCMenuSurfaceFoundation.cssClasses.OPEN);
1885
- _this.openAnimationEndTimerId = setTimeout(function () {
1886
- _this.openAnimationEndTimerId = 0;
1887
- _this.adapter.removeClass(MDCMenuSurfaceFoundation.cssClasses.ANIMATING_OPEN);
1888
- _this.adapter.notifyOpen();
1889
- }, numbers$1.TRANSITION_OPEN_DURATION);
1890
- });
1891
- this.isSurfaceOpen = true;
1892
- }
1893
- };
1894
- /**
1895
- * Closes the menu surface.
1896
- */
1897
- MDCMenuSurfaceFoundation.prototype.close = function (skipRestoreFocus) {
1898
- var _this = this;
1899
- if (skipRestoreFocus === void 0) { skipRestoreFocus = false; }
1900
- if (!this.isSurfaceOpen) {
1901
- return;
1902
- }
1903
- this.adapter.notifyClosing();
1904
- if (this.isQuickOpen) {
1905
- this.isSurfaceOpen = false;
1906
- if (!skipRestoreFocus) {
1907
- this.maybeRestoreFocus();
1908
- }
1909
- this.adapter.removeClass(MDCMenuSurfaceFoundation.cssClasses.OPEN);
1910
- this.adapter.removeClass(MDCMenuSurfaceFoundation.cssClasses.IS_OPEN_BELOW);
1911
- this.adapter.notifyClose();
1912
- return;
1913
- }
1914
- this.adapter.addClass(MDCMenuSurfaceFoundation.cssClasses.ANIMATING_CLOSED);
1915
- requestAnimationFrame(function () {
1916
- _this.adapter.removeClass(MDCMenuSurfaceFoundation.cssClasses.OPEN);
1917
- _this.adapter.removeClass(MDCMenuSurfaceFoundation.cssClasses.IS_OPEN_BELOW);
1918
- _this.closeAnimationEndTimerId = setTimeout(function () {
1919
- _this.closeAnimationEndTimerId = 0;
1920
- _this.adapter.removeClass(MDCMenuSurfaceFoundation.cssClasses.ANIMATING_CLOSED);
1921
- _this.adapter.notifyClose();
1922
- }, numbers$1.TRANSITION_CLOSE_DURATION);
1923
- });
1924
- this.isSurfaceOpen = false;
1925
- if (!skipRestoreFocus) {
1926
- this.maybeRestoreFocus();
1927
- }
1928
- };
1929
- /** Handle clicks and close if not within menu-surface element. */
1930
- MDCMenuSurfaceFoundation.prototype.handleBodyClick = function (evt) {
1931
- var el = evt.target;
1932
- if (this.adapter.isElementInContainer(el)) {
1933
- return;
1934
- }
1935
- this.close();
1936
- };
1937
- /** Handle keys that close the surface. */
1938
- MDCMenuSurfaceFoundation.prototype.handleKeydown = function (evt) {
1939
- var keyCode = evt.keyCode, key = evt.key;
1940
- var isEscape = key === 'Escape' || keyCode === 27;
1941
- if (isEscape) {
1942
- this.close();
1943
- }
1944
- };
1945
- MDCMenuSurfaceFoundation.prototype.autoposition = function () {
1946
- var _a;
1947
- // Compute measurements for autoposition methods reuse.
1948
- this.measurements = this.getAutoLayoutmeasurements();
1949
- var corner = this.getoriginCorner();
1950
- var maxMenuSurfaceHeight = this.getMenuSurfaceMaxHeight(corner);
1951
- var verticalAlignment = this.hasBit(corner, CornerBit.BOTTOM) ? 'bottom' : 'top';
1952
- var horizontalAlignment = this.hasBit(corner, CornerBit.RIGHT) ? 'right' : 'left';
1953
- var horizontalOffset = this.getHorizontalOriginOffset(corner);
1954
- var verticalOffset = this.getVerticalOriginOffset(corner);
1955
- var _b = this.measurements, anchorSize = _b.anchorSize, surfaceSize = _b.surfaceSize;
1956
- var position = (_a = {},
1957
- _a[horizontalAlignment] = horizontalOffset,
1958
- _a[verticalAlignment] = verticalOffset,
1959
- _a);
1960
- // Center align when anchor width is comparable or greater than menu
1961
- // surface, otherwise keep corner.
1962
- if (anchorSize.width / surfaceSize.width >
1963
- numbers$1.ANCHOR_TO_MENU_SURFACE_WIDTH_RATIO) {
1964
- horizontalAlignment = 'center';
1965
- }
1966
- // If the menu-surface has been hoisted to the body, it's no longer relative
1967
- // to the anchor element
1968
- if (this.isHoistedElement || this.isFixedPosition) {
1969
- this.adjustPositionForHoistedElement(position);
1970
- }
1971
- this.adapter.setTransformOrigin(horizontalAlignment + " " + verticalAlignment);
1972
- this.adapter.setPosition(position);
1973
- this.adapter.setMaxHeight(maxMenuSurfaceHeight ? maxMenuSurfaceHeight + 'px' : '');
1974
- // If it is opened from the top then add is-open-below class
1975
- if (!this.hasBit(corner, CornerBit.BOTTOM)) {
1976
- this.adapter.addClass(MDCMenuSurfaceFoundation.cssClasses.IS_OPEN_BELOW);
1977
- }
1978
- };
1979
- /**
1980
- * @return Measurements used to position menu surface popup.
1981
- */
1982
- MDCMenuSurfaceFoundation.prototype.getAutoLayoutmeasurements = function () {
1983
- var anchorRect = this.adapter.getAnchorDimensions();
1984
- var bodySize = this.adapter.getBodyDimensions();
1985
- var viewportSize = this.adapter.getWindowDimensions();
1986
- var windowScroll = this.adapter.getWindowScroll();
1987
- if (!anchorRect) {
1988
- // tslint:disable:object-literal-sort-keys Positional properties are more readable when they're grouped together
1989
- anchorRect = {
1990
- top: this.position.y,
1991
- right: this.position.x,
1992
- bottom: this.position.y,
1993
- left: this.position.x,
1994
- width: 0,
1995
- height: 0,
1996
- };
1997
- // tslint:enable:object-literal-sort-keys
1998
- }
1999
- return {
2000
- anchorSize: anchorRect,
2001
- bodySize: bodySize,
2002
- surfaceSize: this.dimensions,
2003
- viewportDistance: {
2004
- // tslint:disable:object-literal-sort-keys Positional properties are more readable when they're grouped together
2005
- top: anchorRect.top,
2006
- right: viewportSize.width - anchorRect.right,
2007
- bottom: viewportSize.height - anchorRect.bottom,
2008
- left: anchorRect.left,
2009
- // tslint:enable:object-literal-sort-keys
2010
- },
2011
- viewportSize: viewportSize,
2012
- windowScroll: windowScroll,
2013
- };
2014
- };
2015
- /**
2016
- * Computes the corner of the anchor from which to animate and position the
2017
- * menu surface.
2018
- *
2019
- * Only LEFT or RIGHT bit is used to position the menu surface ignoring RTL
2020
- * context. E.g., menu surface will be positioned from right side on TOP_END.
2021
- */
2022
- MDCMenuSurfaceFoundation.prototype.getoriginCorner = function () {
2023
- var corner = this.originCorner;
2024
- var _a = this.measurements, viewportDistance = _a.viewportDistance, anchorSize = _a.anchorSize, surfaceSize = _a.surfaceSize;
2025
- var MARGIN_TO_EDGE = MDCMenuSurfaceFoundation.numbers.MARGIN_TO_EDGE;
2026
- var isAnchoredToBottom = this.hasBit(this.anchorCorner, CornerBit.BOTTOM);
2027
- var availableTop;
2028
- var availableBottom;
2029
- if (isAnchoredToBottom) {
2030
- availableTop =
2031
- viewportDistance.top - MARGIN_TO_EDGE + this.anchorMargin.bottom;
2032
- availableBottom =
2033
- viewportDistance.bottom - MARGIN_TO_EDGE - this.anchorMargin.bottom;
2034
- }
2035
- else {
2036
- availableTop =
2037
- viewportDistance.top - MARGIN_TO_EDGE + this.anchorMargin.top;
2038
- availableBottom = viewportDistance.bottom - MARGIN_TO_EDGE +
2039
- anchorSize.height - this.anchorMargin.top;
2040
- }
2041
- var isAvailableBottom = availableBottom - surfaceSize.height > 0;
2042
- if (!isAvailableBottom && availableTop > availableBottom) {
2043
- // Attach bottom side of surface to the anchor.
2044
- corner = this.setBit(corner, CornerBit.BOTTOM);
2045
- }
2046
- var isRtl = this.adapter.isRtl();
2047
- var isFlipRtl = this.hasBit(this.anchorCorner, CornerBit.FLIP_RTL);
2048
- var hasRightBit = this.hasBit(this.anchorCorner, CornerBit.RIGHT) ||
2049
- this.hasBit(corner, CornerBit.RIGHT);
2050
- // Whether surface attached to right side of anchor element.
2051
- var isAnchoredToRight = false;
2052
- // Anchored to start
2053
- if (isRtl && isFlipRtl) {
2054
- isAnchoredToRight = !hasRightBit;
2055
- }
2056
- else {
2057
- // Anchored to right
2058
- isAnchoredToRight = hasRightBit;
2059
- }
2060
- var availableLeft;
2061
- var availableRight;
2062
- if (isAnchoredToRight) {
2063
- availableLeft =
2064
- viewportDistance.left + anchorSize.width + this.anchorMargin.right;
2065
- availableRight = viewportDistance.right - this.anchorMargin.right;
2066
- }
2067
- else {
2068
- availableLeft = viewportDistance.left + this.anchorMargin.left;
2069
- availableRight =
2070
- viewportDistance.right + anchorSize.width - this.anchorMargin.left;
2071
- }
2072
- var isAvailableLeft = availableLeft - surfaceSize.width > 0;
2073
- var isAvailableRight = availableRight - surfaceSize.width > 0;
2074
- var isOriginCornerAlignedToEnd = this.hasBit(corner, CornerBit.FLIP_RTL) &&
2075
- this.hasBit(corner, CornerBit.RIGHT);
2076
- if (isAvailableRight && isOriginCornerAlignedToEnd && isRtl ||
2077
- !isAvailableLeft && isOriginCornerAlignedToEnd) {
2078
- // Attach left side of surface to the anchor.
2079
- corner = this.unsetBit(corner, CornerBit.RIGHT);
2080
- }
2081
- else if (isAvailableLeft && isAnchoredToRight && isRtl ||
2082
- (isAvailableLeft && !isAnchoredToRight && hasRightBit) ||
2083
- (!isAvailableRight && availableLeft >= availableRight)) {
2084
- // Attach right side of surface to the anchor.
2085
- corner = this.setBit(corner, CornerBit.RIGHT);
2086
- }
2087
- return corner;
2088
- };
2089
- /**
2090
- * @param corner Origin corner of the menu surface.
2091
- * @return Maximum height of the menu surface, based on available space. 0
2092
- * indicates should not be set.
2093
- */
2094
- MDCMenuSurfaceFoundation.prototype.getMenuSurfaceMaxHeight = function (corner) {
2095
- if (this.maxHeight > 0) {
2096
- return this.maxHeight;
2097
- }
2098
- var viewportDistance = this.measurements.viewportDistance;
2099
- var maxHeight = 0;
2100
- var isBottomAligned = this.hasBit(corner, CornerBit.BOTTOM);
2101
- var isBottomAnchored = this.hasBit(this.anchorCorner, CornerBit.BOTTOM);
2102
- var MARGIN_TO_EDGE = MDCMenuSurfaceFoundation.numbers.MARGIN_TO_EDGE;
2103
- // When maximum height is not specified, it is handled from CSS.
2104
- if (isBottomAligned) {
2105
- maxHeight = viewportDistance.top + this.anchorMargin.top - MARGIN_TO_EDGE;
2106
- if (!isBottomAnchored) {
2107
- maxHeight += this.measurements.anchorSize.height;
2108
- }
2109
- }
2110
- else {
2111
- maxHeight = viewportDistance.bottom - this.anchorMargin.bottom +
2112
- this.measurements.anchorSize.height - MARGIN_TO_EDGE;
2113
- if (isBottomAnchored) {
2114
- maxHeight -= this.measurements.anchorSize.height;
2115
- }
2116
- }
2117
- return maxHeight;
2118
- };
2119
- /**
2120
- * @param corner Origin corner of the menu surface.
2121
- * @return Horizontal offset of menu surface origin corner from corresponding
2122
- * anchor corner.
2123
- */
2124
- MDCMenuSurfaceFoundation.prototype.getHorizontalOriginOffset = function (corner) {
2125
- var anchorSize = this.measurements.anchorSize;
2126
- // isRightAligned corresponds to using the 'right' property on the surface.
2127
- var isRightAligned = this.hasBit(corner, CornerBit.RIGHT);
2128
- var avoidHorizontalOverlap = this.hasBit(this.anchorCorner, CornerBit.RIGHT);
2129
- if (isRightAligned) {
2130
- var rightOffset = avoidHorizontalOverlap ?
2131
- anchorSize.width - this.anchorMargin.left :
2132
- this.anchorMargin.right;
2133
- // For hoisted or fixed elements, adjust the offset by the difference
2134
- // between viewport width and body width so when we calculate the right
2135
- // value (`adjustPositionForHoistedElement`) based on the element
2136
- // position, the right property is correct.
2137
- if (this.isHoistedElement || this.isFixedPosition) {
2138
- return rightOffset -
2139
- (this.measurements.viewportSize.width -
2140
- this.measurements.bodySize.width);
2141
- }
2142
- return rightOffset;
2143
- }
2144
- return avoidHorizontalOverlap ? anchorSize.width - this.anchorMargin.right :
2145
- this.anchorMargin.left;
2146
- };
2147
- /**
2148
- * @param corner Origin corner of the menu surface.
2149
- * @return Vertical offset of menu surface origin corner from corresponding
2150
- * anchor corner.
2151
- */
2152
- MDCMenuSurfaceFoundation.prototype.getVerticalOriginOffset = function (corner) {
2153
- var anchorSize = this.measurements.anchorSize;
2154
- var isBottomAligned = this.hasBit(corner, CornerBit.BOTTOM);
2155
- var avoidVerticalOverlap = this.hasBit(this.anchorCorner, CornerBit.BOTTOM);
2156
- var y = 0;
2157
- if (isBottomAligned) {
2158
- y = avoidVerticalOverlap ? anchorSize.height - this.anchorMargin.top :
2159
- -this.anchorMargin.bottom;
2160
- }
2161
- else {
2162
- y = avoidVerticalOverlap ?
2163
- (anchorSize.height + this.anchorMargin.bottom) :
2164
- this.anchorMargin.top;
2165
- }
2166
- return y;
2167
- };
2168
- /**
2169
- * Calculates the offsets for positioning the menu-surface when the
2170
- * menu-surface has been hoisted to the body.
2171
- */
2172
- MDCMenuSurfaceFoundation.prototype.adjustPositionForHoistedElement = function (position) {
2173
- var e_1, _a;
2174
- var _b = this.measurements, windowScroll = _b.windowScroll, viewportDistance = _b.viewportDistance, surfaceSize = _b.surfaceSize, viewportSize = _b.viewportSize;
2175
- var props = Object.keys(position);
2176
- try {
2177
- for (var props_1 = ponyfill.__values(props), props_1_1 = props_1.next(); !props_1_1.done; props_1_1 = props_1.next()) {
2178
- var prop = props_1_1.value;
2179
- var value = position[prop] || 0;
2180
- if (this.isHorizontallyCenteredOnViewport &&
2181
- (prop === 'left' || prop === 'right')) {
2182
- position[prop] = (viewportSize.width - surfaceSize.width) / 2;
2183
- continue;
2184
- }
2185
- // Hoisted surfaces need to have the anchor elements location on the page
2186
- // added to the position properties for proper alignment on the body.
2187
- value += viewportDistance[prop];
2188
- // Surfaces that are absolutely positioned need to have additional
2189
- // calculations for scroll and bottom positioning.
2190
- if (!this.isFixedPosition) {
2191
- if (prop === 'top') {
2192
- value += windowScroll.y;
2193
- }
2194
- else if (prop === 'bottom') {
2195
- value -= windowScroll.y;
2196
- }
2197
- else if (prop === 'left') {
2198
- value += windowScroll.x;
2199
- }
2200
- else { // prop === 'right'
2201
- value -= windowScroll.x;
2202
- }
2203
- }
2204
- position[prop] = value;
2205
- }
2206
- }
2207
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
2208
- finally {
2209
- try {
2210
- if (props_1_1 && !props_1_1.done && (_a = props_1.return)) _a.call(props_1);
2211
- }
2212
- finally { if (e_1) throw e_1.error; }
2213
- }
2214
- };
2215
- /**
2216
- * The last focused element when the menu surface was opened should regain
2217
- * focus, if the user is focused on or within the menu surface when it is
2218
- * closed.
2219
- */
2220
- MDCMenuSurfaceFoundation.prototype.maybeRestoreFocus = function () {
2221
- var _this = this;
2222
- var isRootFocused = this.adapter.isFocused();
2223
- var childHasFocus = document.activeElement &&
2224
- this.adapter.isElementInContainer(document.activeElement);
2225
- if (isRootFocused || childHasFocus) {
2226
- // Wait before restoring focus when closing the menu surface. This is
2227
- // important because if a touch event triggered the menu close, and the
2228
- // subsequent mouse event occurs after focus is restored, then the
2229
- // restored focus would be lost.
2230
- setTimeout(function () {
2231
- _this.adapter.restoreFocus();
2232
- }, numbers$1.TOUCH_EVENT_WAIT_MS);
2233
- }
2234
- };
2235
- MDCMenuSurfaceFoundation.prototype.hasBit = function (corner, bit) {
2236
- return Boolean(corner & bit); // tslint:disable-line:no-bitwise
2237
- };
2238
- MDCMenuSurfaceFoundation.prototype.setBit = function (corner, bit) {
2239
- return corner | bit; // tslint:disable-line:no-bitwise
2240
- };
2241
- MDCMenuSurfaceFoundation.prototype.unsetBit = function (corner, bit) {
2242
- return corner ^ bit;
2243
- };
2244
- /**
2245
- * isFinite that doesn't force conversion to number type.
2246
- * Equivalent to Number.isFinite in ES2015, which is not supported in IE.
2247
- */
2248
- MDCMenuSurfaceFoundation.prototype.isFinite = function (num) {
2249
- return typeof num === 'number' && isFinite(num);
2250
- };
2251
- return MDCMenuSurfaceFoundation;
2252
- }(ponyfill.MDCFoundation));
2253
-
2254
- /**
2255
- * @license
2256
- * Copyright 2018 Google Inc.
2257
- *
2258
- * Permission is hereby granted, free of charge, to any person obtaining a copy
2259
- * of this software and associated documentation files (the "Software"), to deal
2260
- * in the Software without restriction, including without limitation the rights
2261
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
2262
- * copies of the Software, and to permit persons to whom the Software is
2263
- * furnished to do so, subject to the following conditions:
2264
- *
2265
- * The above copyright notice and this permission notice shall be included in
2266
- * all copies or substantial portions of the Software.
2267
- *
2268
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
2269
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
2270
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
2271
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
2272
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
2273
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
2274
- * THE SOFTWARE.
2275
- */
2276
- var MDCMenuSurface = /** @class */ (function (_super) {
2277
- ponyfill.__extends(MDCMenuSurface, _super);
2278
- function MDCMenuSurface() {
2279
- return _super !== null && _super.apply(this, arguments) || this;
2280
- }
2281
- MDCMenuSurface.attachTo = function (root) {
2282
- return new MDCMenuSurface(root);
2283
- };
2284
- MDCMenuSurface.prototype.initialSyncWithDOM = function () {
2285
- var _this = this;
2286
- var parentEl = this.root.parentElement;
2287
- this.anchorElement = parentEl && parentEl.classList.contains(cssClasses$1.ANCHOR) ? parentEl : null;
2288
- if (this.root.classList.contains(cssClasses$1.FIXED)) {
2289
- this.setFixedPosition(true);
2290
- }
2291
- this.handleKeydown = function (event) {
2292
- _this.foundation.handleKeydown(event);
2293
- };
2294
- this.handleBodyClick = function (event) {
2295
- _this.foundation.handleBodyClick(event);
2296
- };
2297
- // capture so that no race between handleBodyClick and quickOpen when
2298
- // menusurface opened on button click which registers this listener
2299
- this.registerBodyClickListener = function () {
2300
- document.body.addEventListener('click', _this.handleBodyClick, { capture: true });
2301
- };
2302
- this.deregisterBodyClickListener = function () {
2303
- document.body.removeEventListener('click', _this.handleBodyClick, { capture: true });
2304
- };
2305
- this.listen('keydown', this.handleKeydown);
2306
- this.listen(strings$1.OPENED_EVENT, this.registerBodyClickListener);
2307
- this.listen(strings$1.CLOSED_EVENT, this.deregisterBodyClickListener);
2308
- };
2309
- MDCMenuSurface.prototype.destroy = function () {
2310
- this.unlisten('keydown', this.handleKeydown);
2311
- this.unlisten(strings$1.OPENED_EVENT, this.registerBodyClickListener);
2312
- this.unlisten(strings$1.CLOSED_EVENT, this.deregisterBodyClickListener);
2313
- _super.prototype.destroy.call(this);
2314
- };
2315
- MDCMenuSurface.prototype.isOpen = function () {
2316
- return this.foundation.isOpen();
2317
- };
2318
- MDCMenuSurface.prototype.open = function () {
2319
- this.foundation.open();
2320
- };
2321
- MDCMenuSurface.prototype.close = function (skipRestoreFocus) {
2322
- if (skipRestoreFocus === void 0) { skipRestoreFocus = false; }
2323
- this.foundation.close(skipRestoreFocus);
2324
- };
2325
- Object.defineProperty(MDCMenuSurface.prototype, "quickOpen", {
2326
- set: function (quickOpen) {
2327
- this.foundation.setQuickOpen(quickOpen);
2328
- },
2329
- enumerable: false,
2330
- configurable: true
2331
- });
2332
- /** Sets the foundation to use page offsets for an positioning when the menu is hoisted to the body. */
2333
- MDCMenuSurface.prototype.setIsHoisted = function (isHoisted) {
2334
- this.foundation.setIsHoisted(isHoisted);
2335
- };
2336
- /** Sets the element that the menu-surface is anchored to. */
2337
- MDCMenuSurface.prototype.setMenuSurfaceAnchorElement = function (element) {
2338
- this.anchorElement = element;
2339
- };
2340
- /** Sets the menu-surface to position: fixed. */
2341
- MDCMenuSurface.prototype.setFixedPosition = function (isFixed) {
2342
- if (isFixed) {
2343
- this.root.classList.add(cssClasses$1.FIXED);
2344
- }
2345
- else {
2346
- this.root.classList.remove(cssClasses$1.FIXED);
2347
- }
2348
- this.foundation.setFixedPosition(isFixed);
2349
- };
2350
- /** Sets the absolute x/y position to position based on. Requires the menu to be hoisted. */
2351
- MDCMenuSurface.prototype.setAbsolutePosition = function (x, y) {
2352
- this.foundation.setAbsolutePosition(x, y);
2353
- this.setIsHoisted(true);
2354
- };
2355
- /**
2356
- * @param corner Default anchor corner alignment of top-left surface corner.
2357
- */
2358
- MDCMenuSurface.prototype.setAnchorCorner = function (corner) {
2359
- this.foundation.setAnchorCorner(corner);
2360
- };
2361
- MDCMenuSurface.prototype.setAnchorMargin = function (margin) {
2362
- this.foundation.setAnchorMargin(margin);
2363
- };
2364
- MDCMenuSurface.prototype.getDefaultFoundation = function () {
2365
- var _this = this;
2366
- // DO NOT INLINE this variable. For backward compatibility, foundations take a Partial<MDCFooAdapter>.
2367
- // To ensure we don't accidentally omit any methods, we need a separate, strongly typed adapter variable.
2368
- // tslint:disable:object-literal-sort-keys Methods should be in the same order as the adapter interface.
2369
- var adapter = {
2370
- addClass: function (className) { return _this.root.classList.add(className); },
2371
- removeClass: function (className) { return _this.root.classList.remove(className); },
2372
- hasClass: function (className) { return _this.root.classList.contains(className); },
2373
- hasAnchor: function () { return !!_this.anchorElement; },
2374
- notifyClose: function () {
2375
- return _this.emit(MDCMenuSurfaceFoundation.strings.CLOSED_EVENT, {});
2376
- },
2377
- notifyClosing: function () {
2378
- _this.emit(MDCMenuSurfaceFoundation.strings.CLOSING_EVENT, {});
2379
- },
2380
- notifyOpen: function () {
2381
- return _this.emit(MDCMenuSurfaceFoundation.strings.OPENED_EVENT, {});
2382
- },
2383
- isElementInContainer: function (el) { return _this.root.contains(el); },
2384
- isRtl: function () {
2385
- return getComputedStyle(_this.root).getPropertyValue('direction') === 'rtl';
2386
- },
2387
- setTransformOrigin: function (origin) {
2388
- var propertyName = util.getCorrectPropertyName(window, 'transform') + "-origin";
2389
- _this.root.style.setProperty(propertyName, origin);
2390
- },
2391
- isFocused: function () { return document.activeElement === _this.root; },
2392
- saveFocus: function () {
2393
- _this.previousFocus =
2394
- document.activeElement;
2395
- },
2396
- restoreFocus: function () {
2397
- if (_this.root.contains(document.activeElement)) {
2398
- if (_this.previousFocus && _this.previousFocus.focus) {
2399
- _this.previousFocus.focus();
2400
- }
2401
- }
2402
- },
2403
- getInnerDimensions: function () {
2404
- return {
2405
- width: _this.root.offsetWidth,
2406
- height: _this.root.offsetHeight
2407
- };
2408
- },
2409
- getAnchorDimensions: function () { return _this.anchorElement ?
2410
- _this.anchorElement.getBoundingClientRect() :
2411
- null; },
2412
- getWindowDimensions: function () {
2413
- return { width: window.innerWidth, height: window.innerHeight };
2414
- },
2415
- getBodyDimensions: function () {
2416
- return { width: document.body.clientWidth, height: document.body.clientHeight };
2417
- },
2418
- getWindowScroll: function () {
2419
- return { x: window.pageXOffset, y: window.pageYOffset };
2420
- },
2421
- setPosition: function (position) {
2422
- var rootHTML = _this.root;
2423
- rootHTML.style.left = 'left' in position ? position.left + "px" : '';
2424
- rootHTML.style.right = 'right' in position ? position.right + "px" : '';
2425
- rootHTML.style.top = 'top' in position ? position.top + "px" : '';
2426
- rootHTML.style.bottom =
2427
- 'bottom' in position ? position.bottom + "px" : '';
2428
- },
2429
- setMaxHeight: function (height) {
2430
- _this.root.style.maxHeight = height;
2431
- },
2432
- };
2433
- // tslint:enable:object-literal-sort-keys
2434
- return new MDCMenuSurfaceFoundation(adapter);
2435
- };
2436
- return MDCMenuSurface;
2437
- }(ponyfill.MDCComponent));
2438
-
2439
- exports.MDCList = MDCList;
2440
- exports.MDCListFoundation = MDCListFoundation;
2441
- exports.MDCMenuSurface = MDCMenuSurface;
2442
- exports.MDCMenuSurfaceFoundation = MDCMenuSurfaceFoundation;
2443
- exports.cssClasses = cssClasses;
2444
- exports.numbers = numbers;
2445
- exports.strings = strings;
2446
-
2447
- //# sourceMappingURL=component-864afce0.js.map