@limetech/lime-elements 33.14.0-next.9 → 34.0.0-next.4

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