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