@limetech/lime-elements 37.45.2 → 37.46.0

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