@angular/cdk-experimental 14.0.0-next.9 → 14.0.0-rc.2

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 (212) hide show
  1. package/column-resize/index.d.ts +419 -6
  2. package/combobox/index.d.ts +123 -8
  3. package/esm2020/column-resize/column-resize-directives/column-resize-flex.mjs +4 -4
  4. package/esm2020/column-resize/column-resize-directives/column-resize.mjs +4 -4
  5. package/esm2020/column-resize/column-resize-directives/default-enabled-column-resize-flex.mjs +4 -4
  6. package/esm2020/column-resize/column-resize-directives/default-enabled-column-resize.mjs +4 -4
  7. package/esm2020/column-resize/column-resize-module.mjs +9 -9
  8. package/esm2020/column-resize/column-resize-notifier.mjs +7 -7
  9. package/esm2020/column-resize/column-resize.mjs +4 -4
  10. package/esm2020/column-resize/column-size-store.mjs +4 -4
  11. package/esm2020/column-resize/event-dispatcher.mjs +4 -4
  12. package/esm2020/column-resize/overlay-handle.mjs +4 -4
  13. package/esm2020/column-resize/resizable.mjs +4 -4
  14. package/esm2020/column-resize/resize-strategy.mjs +10 -10
  15. package/esm2020/combobox/combobox-module.mjs +5 -5
  16. package/esm2020/combobox/combobox-popup.mjs +4 -4
  17. package/esm2020/combobox/combobox.mjs +4 -4
  18. package/esm2020/listbox/listbox-module.mjs +5 -5
  19. package/esm2020/listbox/listbox.mjs +7 -7
  20. package/esm2020/popover-edit/edit-event-dispatcher.mjs +7 -7
  21. package/esm2020/popover-edit/edit-ref.mjs +4 -4
  22. package/esm2020/popover-edit/edit-services.mjs +4 -4
  23. package/esm2020/popover-edit/focus-dispatcher.mjs +4 -4
  24. package/esm2020/popover-edit/focus-escape-notifier.mjs +6 -6
  25. package/esm2020/popover-edit/lens-directives.mjs +10 -10
  26. package/esm2020/popover-edit/popover-edit-module.mjs +6 -6
  27. package/esm2020/popover-edit/popover-edit-position-strategy-factory.mjs +7 -7
  28. package/esm2020/popover-edit/table-directives.mjs +19 -19
  29. package/esm2020/scrolling/auto-size-virtual-scroll.mjs +4 -4
  30. package/esm2020/scrolling/scrolling-module.mjs +5 -5
  31. package/esm2020/selection/row-selection.mjs +4 -4
  32. package/esm2020/selection/select-all.mjs +4 -4
  33. package/esm2020/selection/selection-column.mjs +10 -10
  34. package/esm2020/selection/selection-module.mjs +5 -5
  35. package/esm2020/selection/selection-toggle.mjs +4 -4
  36. package/esm2020/selection/selection.mjs +4 -4
  37. package/esm2020/table-scroll-container/table-scroll-container-module.mjs +5 -5
  38. package/esm2020/table-scroll-container/table-scroll-container.mjs +4 -4
  39. package/esm2020/version.mjs +1 -1
  40. package/fesm2015/cdk-experimental.mjs +1 -1
  41. package/fesm2015/cdk-experimental.mjs.map +1 -1
  42. package/fesm2015/column-resize.mjs +50 -50
  43. package/fesm2015/column-resize.mjs.map +1 -1
  44. package/fesm2015/combobox.mjs +10 -10
  45. package/fesm2015/combobox.mjs.map +1 -1
  46. package/fesm2015/listbox.mjs +10 -10
  47. package/fesm2015/listbox.mjs.map +1 -1
  48. package/fesm2015/popover-edit.mjs +58 -58
  49. package/fesm2015/popover-edit.mjs.map +1 -1
  50. package/fesm2015/scrolling.mjs +7 -7
  51. package/fesm2015/scrolling.mjs.map +1 -1
  52. package/fesm2015/selection.mjs +23 -23
  53. package/fesm2015/selection.mjs.map +1 -1
  54. package/fesm2015/table-scroll-container.mjs +7 -7
  55. package/fesm2015/table-scroll-container.mjs.map +1 -1
  56. package/fesm2020/cdk-experimental.mjs +1 -1
  57. package/fesm2020/cdk-experimental.mjs.map +1 -1
  58. package/fesm2020/column-resize.mjs +50 -50
  59. package/fesm2020/column-resize.mjs.map +1 -1
  60. package/fesm2020/combobox.mjs +10 -10
  61. package/fesm2020/combobox.mjs.map +1 -1
  62. package/fesm2020/listbox.mjs +10 -10
  63. package/fesm2020/listbox.mjs.map +1 -1
  64. package/fesm2020/popover-edit.mjs +58 -58
  65. package/fesm2020/popover-edit.mjs.map +1 -1
  66. package/fesm2020/scrolling.mjs +7 -7
  67. package/fesm2020/scrolling.mjs.map +1 -1
  68. package/fesm2020/selection.mjs +23 -23
  69. package/fesm2020/selection.mjs.map +1 -1
  70. package/fesm2020/table-scroll-container.mjs +7 -7
  71. package/fesm2020/table-scroll-container.mjs.map +1 -1
  72. package/index.d.ts +6 -8
  73. package/listbox/index.d.ts +197 -8
  74. package/package.json +9 -25
  75. package/popover-edit/index.d.ts +532 -5
  76. package/scrolling/index.d.ts +173 -6
  77. package/selection/index.d.ts +273 -5
  78. package/table-scroll-container/index.d.ts +61 -5
  79. package/column-resize/column-resize-directives/column-resize-flex.d.ts +0 -28
  80. package/column-resize/column-resize-directives/column-resize.d.ts +0 -28
  81. package/column-resize/column-resize-directives/constants.d.ts +0 -10
  82. package/column-resize/column-resize-directives/default-enabled-column-resize-flex.d.ts +0 -28
  83. package/column-resize/column-resize-directives/default-enabled-column-resize.d.ts +0 -28
  84. package/column-resize/column-resize-module.d.ts +0 -23
  85. package/column-resize/column-resize-notifier.d.ts +0 -49
  86. package/column-resize/column-resize.d.ts +0 -39
  87. package/column-resize/column-resize_public_index.d.ts +0 -4
  88. package/column-resize/column-size-store.d.ts +0 -12
  89. package/column-resize/event-dispatcher.d.ts +0 -44
  90. package/column-resize/overlay-handle.d.ts +0 -43
  91. package/column-resize/package.json +0 -9
  92. package/column-resize/public-api.d.ts +0 -20
  93. package/column-resize/resizable.d.ts +0 -69
  94. package/column-resize/resize-ref.d.ts +0 -17
  95. package/column-resize/resize-strategy.d.ts +0 -83
  96. package/column-resize/selectors.d.ts +0 -10
  97. package/combobox/combobox-module.d.ts +0 -9
  98. package/combobox/combobox-popup.d.ts +0 -27
  99. package/combobox/combobox.d.ts +0 -68
  100. package/combobox/combobox_public_index.d.ts +0 -4
  101. package/combobox/package.json +0 -9
  102. package/combobox/public-api.d.ts +0 -10
  103. package/dialog/dialog-config.d.ts +0 -82
  104. package/dialog/dialog-container.d.ts +0 -99
  105. package/dialog/dialog-injectors.d.ts +0 -30
  106. package/dialog/dialog-module.d.ts +0 -10
  107. package/dialog/dialog-ref.d.ts +0 -57
  108. package/dialog/dialog.d.ts +0 -100
  109. package/dialog/dialog_public_index.d.ts +0 -4
  110. package/dialog/index.d.ts +0 -8
  111. package/dialog/package.json +0 -9
  112. package/dialog/public-api.d.ts +0 -13
  113. package/esm2020/dialog/dialog-config.mjs +0 -43
  114. package/esm2020/dialog/dialog-container.mjs +0 -300
  115. package/esm2020/dialog/dialog-injectors.mjs +0 -30
  116. package/esm2020/dialog/dialog-module.mjs +0 -56
  117. package/esm2020/dialog/dialog-ref.mjs +0 -116
  118. package/esm2020/dialog/dialog.mjs +0 -252
  119. package/esm2020/dialog/dialog_public_index.mjs +0 -5
  120. package/esm2020/dialog/index.mjs +0 -9
  121. package/esm2020/dialog/public-api.mjs +0 -14
  122. package/esm2020/menu/context-menu.mjs +0 -222
  123. package/esm2020/menu/index.mjs +0 -9
  124. package/esm2020/menu/menu-aim.mjs +0 -199
  125. package/esm2020/menu/menu-bar.mjs +0 -164
  126. package/esm2020/menu/menu-base.mjs +0 -129
  127. package/esm2020/menu/menu-errors.mjs +0 -22
  128. package/esm2020/menu/menu-group.mjs +0 -68
  129. package/esm2020/menu/menu-interface.mjs +0 -11
  130. package/esm2020/menu/menu-item-checkbox.mjs +0 -48
  131. package/esm2020/menu/menu-item-radio.mjs +0 -95
  132. package/esm2020/menu/menu-item-selectable.mjs +0 -57
  133. package/esm2020/menu/menu-item-trigger.mjs +0 -276
  134. package/esm2020/menu/menu-item.mjs +0 -250
  135. package/esm2020/menu/menu-module.mjs +0 -60
  136. package/esm2020/menu/menu-stack.mjs +0 -131
  137. package/esm2020/menu/menu-trigger.mjs +0 -70
  138. package/esm2020/menu/menu.mjs +0 -204
  139. package/esm2020/menu/menu_public_index.mjs +0 -5
  140. package/esm2020/menu/pointer-focus-tracker.mjs +0 -49
  141. package/esm2020/menu/public-api.mjs +0 -21
  142. package/fesm2015/dialog.mjs +0 -803
  143. package/fesm2015/dialog.mjs.map +0 -1
  144. package/fesm2015/menu.mjs +0 -1983
  145. package/fesm2015/menu.mjs.map +0 -1
  146. package/fesm2020/dialog.mjs +0 -797
  147. package/fesm2020/dialog.mjs.map +0 -1
  148. package/fesm2020/menu.mjs +0 -1954
  149. package/fesm2020/menu.mjs.map +0 -1
  150. package/listbox/listbox-module.d.ts +0 -7
  151. package/listbox/listbox.d.ts +0 -172
  152. package/listbox/listbox_public_index.d.ts +0 -4
  153. package/listbox/package.json +0 -9
  154. package/listbox/public-api.d.ts +0 -9
  155. package/menu/context-menu.d.ts +0 -84
  156. package/menu/index.d.ts +0 -8
  157. package/menu/menu-aim.d.ts +0 -96
  158. package/menu/menu-bar.d.ts +0 -47
  159. package/menu/menu-base.d.ts +0 -64
  160. package/menu/menu-errors.d.ts +0 -17
  161. package/menu/menu-group.d.ts +0 -33
  162. package/menu/menu-interface.d.ts +0 -23
  163. package/menu/menu-item-checkbox.d.ts +0 -12
  164. package/menu/menu-item-radio.d.ts +0 -36
  165. package/menu/menu-item-selectable.d.ts +0 -31
  166. package/menu/menu-item-trigger.d.ts +0 -89
  167. package/menu/menu-item.d.ts +0 -105
  168. package/menu/menu-module.d.ts +0 -16
  169. package/menu/menu-stack.d.ts +0 -94
  170. package/menu/menu-trigger.d.ts +0 -48
  171. package/menu/menu.d.ts +0 -57
  172. package/menu/menu_public_index.d.ts +0 -4
  173. package/menu/package.json +0 -9
  174. package/menu/pointer-focus-tracker.d.ts +0 -44
  175. package/menu/public-api.d.ts +0 -20
  176. package/popover-edit/constants.d.ts +0 -19
  177. package/popover-edit/edit-event-dispatcher.d.ts +0 -99
  178. package/popover-edit/edit-ref.d.ts +0 -52
  179. package/popover-edit/edit-services.d.ts +0 -37
  180. package/popover-edit/focus-dispatcher.d.ts +0 -31
  181. package/popover-edit/focus-escape-notifier.d.ts +0 -40
  182. package/popover-edit/form-value-container.d.ts +0 -24
  183. package/popover-edit/lens-directives.d.ts +0 -82
  184. package/popover-edit/package.json +0 -9
  185. package/popover-edit/polyfill.d.ts +0 -9
  186. package/popover-edit/popover-edit-module.d.ts +0 -9
  187. package/popover-edit/popover-edit-position-strategy-factory.d.ts +0 -42
  188. package/popover-edit/popover-edit_public_index.d.ts +0 -4
  189. package/popover-edit/public-api.d.ts +0 -17
  190. package/popover-edit/table-directives.d.ts +0 -150
  191. package/public-api.d.ts +0 -8
  192. package/scrolling/auto-size-virtual-scroll.d.ts +0 -160
  193. package/scrolling/package.json +0 -9
  194. package/scrolling/public-api.d.ts +0 -9
  195. package/scrolling/scrolling-module.d.ts +0 -7
  196. package/scrolling/scrolling_public_index.d.ts +0 -4
  197. package/selection/package.json +0 -9
  198. package/selection/public-api.d.ts +0 -14
  199. package/selection/row-selection.d.ts +0 -27
  200. package/selection/select-all.d.ts +0 -52
  201. package/selection/selection-column.d.ts +0 -34
  202. package/selection/selection-module.d.ts +0 -13
  203. package/selection/selection-set.d.ts +0 -56
  204. package/selection/selection-toggle.d.ts +0 -46
  205. package/selection/selection.d.ts +0 -65
  206. package/selection/selection_public_index.d.ts +0 -4
  207. package/table-scroll-container/package.json +0 -9
  208. package/table-scroll-container/public-api.d.ts +0 -9
  209. package/table-scroll-container/table-scroll-container-module.d.ts +0 -7
  210. package/table-scroll-container/table-scroll-container.d.ts +0 -53
  211. package/table-scroll-container/table-scroll-container_public_index.d.ts +0 -4
  212. package/version.d.ts +0 -10
package/fesm2020/menu.mjs DELETED
@@ -1,1954 +0,0 @@
1
- import * as i0 from '@angular/core';
2
- import { InjectionToken, Optional, SkipSelf, Inject, Injectable, Directive, EventEmitter, Injector, Self, Input, Output, ContentChildren, NgModule } from '@angular/core';
3
- import * as i1 from '@angular/cdk/overlay';
4
- import { OverlayConfig, STANDARD_DROPDOWN_BELOW_POSITIONS, STANDARD_DROPDOWN_ADJACENT_POSITIONS, OverlayModule } from '@angular/cdk/overlay';
5
- import { UP_ARROW, DOWN_ARROW, LEFT_ARROW, RIGHT_ARROW, ENTER, SPACE, TAB, ESCAPE, hasModifierKey } from '@angular/cdk/keycodes';
6
- import * as i1$1 from '@angular/cdk/bidi';
7
- import { filter, takeUntil, startWith, mergeMap, mapTo, mergeAll, switchMap, take, skip } from 'rxjs/operators';
8
- import * as i1$2 from '@angular/cdk/collections';
9
- import { UniqueSelectionDispatcher } from '@angular/cdk/collections';
10
- import { coerceBooleanProperty } from '@angular/cdk/coercion';
11
- import { Subject, fromEvent, merge, defer, partition } from 'rxjs';
12
- import { TemplatePortal } from '@angular/cdk/portal';
13
- import { FocusKeyManager } from '@angular/cdk/a11y';
14
-
15
- /**
16
- * @license
17
- * Copyright Google LLC All Rights Reserved.
18
- *
19
- * Use of this source code is governed by an MIT-style license that can be
20
- * found in the LICENSE file at https://angular.io/license
21
- */
22
- /** Injection token used to return classes implementing the Menu interface */
23
- const CDK_MENU = new InjectionToken('cdk-menu');
24
-
25
- /**
26
- * @license
27
- * Copyright Google LLC All Rights Reserved.
28
- *
29
- * Use of this source code is governed by an MIT-style license that can be
30
- * found in the LICENSE file at https://angular.io/license
31
- */
32
- /** Injection token used for an implementation of MenuStack. */
33
- const MENU_STACK = new InjectionToken('cdk-menu-stack');
34
- /** A provider that provides the parent menu stack, or a new menu stack if there is no parent one. */
35
- const PARENT_OR_NEW_MENU_STACK_PROVIDER = {
36
- provide: MENU_STACK,
37
- deps: [[new Optional(), new SkipSelf(), new Inject(MENU_STACK)]],
38
- useFactory: (parentMenuStack) => parentMenuStack || new MenuStack(),
39
- };
40
- /** A provider that provides the parent menu stack, or a new menu stack if there is no parent one. */
41
- const PARENT_OR_NEW_INLINE_MENU_STACK_PROVIDER = {
42
- provide: MENU_STACK,
43
- deps: [[new Optional(), new SkipSelf(), new Inject(MENU_STACK)]],
44
- useFactory: (parentMenuStack) => parentMenuStack || MenuStack.inline(),
45
- };
46
- /**
47
- * MenuStack allows subscribers to listen for close events (when a MenuStackItem is popped off
48
- * of the stack) in order to perform closing actions. Upon the MenuStack being empty it emits
49
- * from the `empty` observable specifying the next focus action which the listener should perform
50
- * as requested by the closer.
51
- */
52
- class MenuStack {
53
- constructor() {
54
- /** All MenuStackItems tracked by this MenuStack. */
55
- this._elements = [];
56
- /** Emits the element which was popped off of the stack when requested by a closer. */
57
- this._close = new Subject();
58
- /** Emits once the MenuStack has become empty after popping off elements. */
59
- this._empty = new Subject();
60
- /** Observable which emits the MenuStackItem which has been requested to close. */
61
- this.closed = this._close;
62
- /**
63
- * Observable which emits when the MenuStack is empty after popping off the last element. It
64
- * emits a FocusNext event which specifies the action the closer has requested the listener
65
- * perform.
66
- */
67
- this.emptied = this._empty;
68
- this._hasInlineMenu = false;
69
- }
70
- static inline() {
71
- const stack = new MenuStack();
72
- stack._hasInlineMenu = true;
73
- return stack;
74
- }
75
- /** @param menu the MenuStackItem to put on the stack. */
76
- push(menu) {
77
- this._elements.push(menu);
78
- }
79
- /**
80
- * Pop items off of the stack up to and including `lastItem` and emit each on the close
81
- * observable. If the stack is empty or `lastItem` is not on the stack it does nothing.
82
- * @param lastItem the last item to pop off the stack.
83
- * @param focusNext the event to emit on the `empty` observable if the method call resulted in an
84
- * empty stack. Does not emit if the stack was initially empty or if `lastItem` was not on the
85
- * stack.
86
- */
87
- close(lastItem, focusNext) {
88
- if (this._elements.indexOf(lastItem) >= 0) {
89
- let poppedElement;
90
- do {
91
- poppedElement = this._elements.pop();
92
- this._close.next(poppedElement);
93
- } while (poppedElement !== lastItem);
94
- if (this.isEmpty()) {
95
- this._empty.next(focusNext);
96
- }
97
- }
98
- }
99
- /**
100
- * Pop items off of the stack up to but excluding `lastItem` and emit each on the close
101
- * observable. If the stack is empty or `lastItem` is not on the stack it does nothing.
102
- * @param lastItem the element which should be left on the stack
103
- * @return whether or not an item was removed from the stack
104
- */
105
- closeSubMenuOf(lastItem) {
106
- let removed = false;
107
- if (this._elements.indexOf(lastItem) >= 0) {
108
- removed = this.peek() !== lastItem;
109
- while (this.peek() !== lastItem) {
110
- this._close.next(this._elements.pop());
111
- }
112
- }
113
- return removed;
114
- }
115
- /**
116
- * Pop off all MenuStackItems and emit each one on the `close` observable one by one.
117
- * @param focusNext the event to emit on the `empty` observable once the stack is emptied. Does
118
- * not emit if the stack was initially empty.
119
- */
120
- closeAll(focusNext) {
121
- if (!this.isEmpty()) {
122
- while (!this.isEmpty()) {
123
- const menuStackItem = this._elements.pop();
124
- if (menuStackItem) {
125
- this._close.next(menuStackItem);
126
- }
127
- }
128
- this._empty.next(focusNext);
129
- }
130
- }
131
- /** Return true if this stack is empty. */
132
- isEmpty() {
133
- return !this._elements.length;
134
- }
135
- /** Return the length of the stack. */
136
- length() {
137
- return this._elements.length;
138
- }
139
- /** Get the top most element on the stack. */
140
- peek() {
141
- return this._elements[this._elements.length - 1];
142
- }
143
- hasInlineMenu() {
144
- return this._hasInlineMenu;
145
- }
146
- }
147
- MenuStack.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.0.0-next.9", ngImport: i0, type: MenuStack, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
148
- MenuStack.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "14.0.0-next.9", ngImport: i0, type: MenuStack });
149
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.0.0-next.9", ngImport: i0, type: MenuStack, decorators: [{
150
- type: Injectable
151
- }] });
152
-
153
- /**
154
- * @license
155
- * Copyright Google LLC All Rights Reserved.
156
- *
157
- * Use of this source code is governed by an MIT-style license that can be
158
- * found in the LICENSE file at https://angular.io/license
159
- */
160
- /**
161
- * Throws an exception when an instance of the PointerFocusTracker is not provided.
162
- * @docs-private
163
- */
164
- function throwMissingPointerFocusTracker() {
165
- throw Error('expected an instance of PointerFocusTracker to be provided');
166
- }
167
- /**
168
- * Throws an exception when a reference to the parent menu is not provided.
169
- * @docs-private
170
- */
171
- function throwMissingMenuReference() {
172
- throw Error('expected a reference to the parent menu');
173
- }
174
-
175
- /**
176
- * @license
177
- * Copyright Google LLC All Rights Reserved.
178
- *
179
- * Use of this source code is governed by an MIT-style license that can be
180
- * found in the LICENSE file at https://angular.io/license
181
- */
182
- /** Injection token used for an implementation of MenuAim. */
183
- const MENU_AIM = new InjectionToken('cdk-menu-aim');
184
- /** Capture every nth mouse move event. */
185
- const MOUSE_MOVE_SAMPLE_FREQUENCY = 3;
186
- /** The number of mouse move events to track. */
187
- const NUM_POINTS = 5;
188
- /**
189
- * How long to wait before closing a sibling menu if a user stops short of the submenu they were
190
- * predicted to go into.
191
- */
192
- const CLOSE_DELAY = 300;
193
- /** Calculate the slope between point a and b. */
194
- function getSlope(a, b) {
195
- return (b.y - a.y) / (b.x - a.x);
196
- }
197
- /** Calculate the y intercept for the given point and slope. */
198
- function getYIntercept(point, slope) {
199
- return point.y - slope * point.x;
200
- }
201
- /**
202
- * Whether the given mouse trajectory line defined by the slope and y intercept falls within the
203
- * submenu as defined by `submenuPoints`
204
- * @param submenuPoints the submenu DOMRect points.
205
- * @param m the slope of the trajectory line.
206
- * @param b the y intercept of the trajectory line.
207
- *
208
- * @return true if any point on the line falls within the submenu.
209
- */
210
- function isWithinSubmenu(submenuPoints, m, b) {
211
- const { left, right, top, bottom } = submenuPoints;
212
- // Check for intersection with each edge of the submenu (left, right, top, bottom)
213
- // by fixing one coordinate to that edge's coordinate (either x or y) and checking if the
214
- // other coordinate is within bounds.
215
- return ((m * left + b >= top && m * left + b <= bottom) ||
216
- (m * right + b >= top && m * right + b <= bottom) ||
217
- ((top - b) / m >= left && (top - b) / m <= right) ||
218
- ((bottom - b) / m >= left && (bottom - b) / m <= right));
219
- }
220
- /**
221
- * TargetMenuAim predicts if a user is moving into a submenu. It calculates the
222
- * trajectory of the user's mouse movement in the current menu to determine if the
223
- * mouse is moving towards an open submenu.
224
- *
225
- * The determination is made by calculating the slope of the users last NUM_POINTS moves where each
226
- * pair of points determines if the trajectory line points into the submenu. It uses consensus
227
- * approach by checking if at least NUM_POINTS / 2 pairs determine that the user is moving towards
228
- * to submenu.
229
- */
230
- class TargetMenuAim {
231
- constructor(_ngZone) {
232
- this._ngZone = _ngZone;
233
- /** The last NUM_POINTS mouse move events. */
234
- this._points = [];
235
- /** Emits when this service is destroyed. */
236
- this._destroyed = new Subject();
237
- }
238
- /** Set the Menu and its PointerFocusTracker. */
239
- initialize(menu, pointerTracker) {
240
- this._menu = menu;
241
- this._pointerTracker = pointerTracker;
242
- this._subscribeToMouseMoves();
243
- }
244
- /**
245
- * Calls the `doToggle` callback when it is deemed that the user is not moving towards
246
- * the submenu.
247
- * @param doToggle the function called when the user is not moving towards the submenu.
248
- */
249
- toggle(doToggle) {
250
- // If the menu is horizontal the sub-menus open below and there is no risk of premature
251
- // closing of any sub-menus therefore we automatically resolve the callback.
252
- if (this._menu.orientation === 'horizontal') {
253
- doToggle();
254
- }
255
- this._checkConfigured();
256
- const siblingItemIsWaiting = !!this._timeoutId;
257
- const hasPoints = this._points.length > 1;
258
- if (hasPoints && !siblingItemIsWaiting) {
259
- if (this._isMovingToSubmenu()) {
260
- this._startTimeout(doToggle);
261
- }
262
- else {
263
- doToggle();
264
- }
265
- }
266
- else if (!siblingItemIsWaiting) {
267
- doToggle();
268
- }
269
- }
270
- /**
271
- * Start the delayed toggle handler if one isn't running already.
272
- *
273
- * The delayed toggle handler executes the `doToggle` callback after some period of time iff the
274
- * users mouse is on an item in the current menu.
275
- */
276
- _startTimeout(doToggle) {
277
- // If the users mouse is moving towards a submenu we don't want to immediately resolve.
278
- // Wait for some period of time before determining if the previous menu should close in
279
- // cases where the user may have moved towards the submenu but stopped on a sibling menu
280
- // item intentionally.
281
- const timeoutId = setTimeout(() => {
282
- // Resolve if the user is currently moused over some element in the root menu
283
- if (this._pointerTracker.activeElement && timeoutId === this._timeoutId) {
284
- doToggle();
285
- }
286
- this._timeoutId = null;
287
- }, CLOSE_DELAY);
288
- this._timeoutId = timeoutId;
289
- }
290
- /** Whether the user is heading towards the open submenu. */
291
- _isMovingToSubmenu() {
292
- const submenuPoints = this._getSubmenuBounds();
293
- if (!submenuPoints) {
294
- return false;
295
- }
296
- let numMoving = 0;
297
- const currPoint = this._points[this._points.length - 1];
298
- // start from the second last point and calculate the slope between each point and the last
299
- // point.
300
- for (let i = this._points.length - 2; i >= 0; i--) {
301
- const previous = this._points[i];
302
- const slope = getSlope(currPoint, previous);
303
- if (isWithinSubmenu(submenuPoints, slope, getYIntercept(currPoint, slope))) {
304
- numMoving++;
305
- }
306
- }
307
- return numMoving >= Math.floor(NUM_POINTS / 2);
308
- }
309
- /** Get the bounding DOMRect for the open submenu. */
310
- _getSubmenuBounds() {
311
- return this._pointerTracker?.previousElement
312
- ?.getMenu()
313
- ?._elementRef.nativeElement.getBoundingClientRect();
314
- }
315
- /**
316
- * Check if a reference to the PointerFocusTracker and menu element is provided.
317
- * @throws an error if neither reference is provided.
318
- */
319
- _checkConfigured() {
320
- if (typeof ngDevMode === 'undefined' || ngDevMode) {
321
- if (!this._pointerTracker) {
322
- throwMissingPointerFocusTracker();
323
- }
324
- if (!this._menu) {
325
- throwMissingMenuReference();
326
- }
327
- }
328
- }
329
- /** Subscribe to the root menus mouse move events and update the tracked mouse points. */
330
- _subscribeToMouseMoves() {
331
- this._ngZone.runOutsideAngular(() => {
332
- fromEvent(this._menu._elementRef.nativeElement, 'mousemove')
333
- .pipe(filter((_, index) => index % MOUSE_MOVE_SAMPLE_FREQUENCY === 0), takeUntil(this._destroyed))
334
- .subscribe((event) => {
335
- this._points.push({ x: event.clientX, y: event.clientY });
336
- if (this._points.length > NUM_POINTS) {
337
- this._points.shift();
338
- }
339
- });
340
- });
341
- }
342
- ngOnDestroy() {
343
- this._destroyed.next();
344
- this._destroyed.complete();
345
- }
346
- }
347
- TargetMenuAim.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.0.0-next.9", ngImport: i0, type: TargetMenuAim, deps: [{ token: i0.NgZone }], target: i0.ɵɵFactoryTarget.Injectable });
348
- TargetMenuAim.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "14.0.0-next.9", ngImport: i0, type: TargetMenuAim });
349
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.0.0-next.9", ngImport: i0, type: TargetMenuAim, decorators: [{
350
- type: Injectable
351
- }], ctorParameters: function () { return [{ type: i0.NgZone }]; } });
352
- /**
353
- * CdkTargetMenuAim is a provider for the TargetMenuAim service. It should be added to an
354
- * element with either the `cdkMenu` or `cdkMenuBar` directive and child menu items.
355
- */
356
- class CdkTargetMenuAim {
357
- }
358
- CdkTargetMenuAim.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.0.0-next.9", ngImport: i0, type: CdkTargetMenuAim, deps: [], target: i0.ɵɵFactoryTarget.Directive });
359
- CdkTargetMenuAim.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "12.0.0", version: "14.0.0-next.9", type: CdkTargetMenuAim, selector: "[cdkTargetMenuAim]", providers: [{ provide: MENU_AIM, useClass: TargetMenuAim }], exportAs: ["cdkTargetMenuAim"], ngImport: i0 });
360
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.0.0-next.9", ngImport: i0, type: CdkTargetMenuAim, decorators: [{
361
- type: Directive,
362
- args: [{
363
- selector: '[cdkTargetMenuAim]',
364
- exportAs: 'cdkTargetMenuAim',
365
- providers: [{ provide: MENU_AIM, useClass: TargetMenuAim }],
366
- }]
367
- }] });
368
-
369
- /**
370
- * @license
371
- * Copyright Google LLC All Rights Reserved.
372
- *
373
- * Use of this source code is governed by an MIT-style license that can be
374
- * found in the LICENSE file at https://angular.io/license
375
- */
376
- /** Injection token used for an implementation of MenuStack. */
377
- const MENU_TRIGGER = new InjectionToken('cdk-menu-trigger');
378
- class MenuTrigger {
379
- constructor(injector, menuStack) {
380
- this.injector = injector;
381
- this.menuStack = menuStack;
382
- /** Emits when the attached menu is requested to open */
383
- this.opened = new EventEmitter();
384
- /** Emits when the attached menu is requested to close */
385
- this.closed = new EventEmitter();
386
- /** A reference to the overlay which manages the triggered menu */
387
- this._overlayRef = null;
388
- /** Emits when this trigger is destroyed. */
389
- this._destroyed = new Subject();
390
- /** Emits when the outside pointer events listener on the overlay should be stopped. */
391
- this._stopOutsideClicksListener = merge(this.closed, this._destroyed);
392
- }
393
- ngOnDestroy() {
394
- this._destroyOverlay();
395
- this._destroyed.next();
396
- this._destroyed.complete();
397
- }
398
- /** Whether the attached menu is open. */
399
- isOpen() {
400
- return !!this._overlayRef?.hasAttached();
401
- }
402
- registerChildMenu(child) {
403
- this.childMenu = child;
404
- }
405
- getChildMenuInjector() {
406
- this._childMenuInjector =
407
- this._childMenuInjector ||
408
- Injector.create({
409
- providers: [
410
- { provide: MENU_TRIGGER, useValue: this },
411
- { provide: MENU_STACK, useValue: this.menuStack },
412
- ],
413
- parent: this.injector,
414
- });
415
- return this._childMenuInjector;
416
- }
417
- /** Destroy and unset the overlay reference it if exists */
418
- _destroyOverlay() {
419
- if (this._overlayRef) {
420
- this._overlayRef.dispose();
421
- this._overlayRef = null;
422
- }
423
- }
424
- }
425
- MenuTrigger.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.0.0-next.9", ngImport: i0, type: MenuTrigger, deps: [{ token: i0.Injector }, { token: MENU_STACK }], target: i0.ɵɵFactoryTarget.Directive });
426
- MenuTrigger.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "12.0.0", version: "14.0.0-next.9", type: MenuTrigger, ngImport: i0 });
427
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.0.0-next.9", ngImport: i0, type: MenuTrigger, decorators: [{
428
- type: Directive
429
- }], ctorParameters: function () { return [{ type: i0.Injector }, { type: MenuStack, decorators: [{
430
- type: Inject,
431
- args: [MENU_STACK]
432
- }] }]; } });
433
-
434
- /**
435
- * @license
436
- * Copyright Google LLC All Rights Reserved.
437
- *
438
- * Use of this source code is governed by an MIT-style license that can be
439
- * found in the LICENSE file at https://angular.io/license
440
- */
441
- /**
442
- * Whether the target element is a menu item to be ignored by the overlay background click handler.
443
- */
444
- function isClickInsideMenuOverlay(target) {
445
- while (target?.parentElement) {
446
- const isOpenTrigger = target.getAttribute('aria-expanded') === 'true' &&
447
- target.classList.contains('cdk-menu-trigger');
448
- const isOverlayMenu = target.classList.contains('cdk-menu') && !target.classList.contains('cdk-menu-inline');
449
- if (isOpenTrigger || isOverlayMenu) {
450
- return true;
451
- }
452
- target = target.parentElement;
453
- }
454
- return false;
455
- }
456
- /**
457
- * A directive to be combined with CdkMenuItem which opens the Menu it is bound to. If the
458
- * element is in a top level MenuBar it will open the menu on click, or if a sibling is already
459
- * opened it will open on hover. If it is inside of a Menu it will open the attached Submenu on
460
- * hover regardless of its sibling state.
461
- *
462
- * The directive must be placed along with the `cdkMenuItem` directive in order to enable full
463
- * functionality.
464
- */
465
- class CdkMenuItemTrigger extends MenuTrigger {
466
- constructor(injector, _elementRef, _viewContainerRef, _overlay, _ngZone, menuStack, _parentMenu, _menuAim, _directionality) {
467
- super(injector, menuStack);
468
- this._elementRef = _elementRef;
469
- this._viewContainerRef = _viewContainerRef;
470
- this._overlay = _overlay;
471
- this._ngZone = _ngZone;
472
- this._parentMenu = _parentMenu;
473
- this._menuAim = _menuAim;
474
- this._directionality = _directionality;
475
- this._registerCloseHandler();
476
- this._subscribeToMouseEnter();
477
- }
478
- /** Open/close the attached menu if the trigger has been configured with one */
479
- toggle() {
480
- this.isOpen() ? this.close() : this.open();
481
- }
482
- /** Open the attached menu. */
483
- open() {
484
- if (!this.isOpen()) {
485
- this.opened.next();
486
- this._overlayRef = this._overlayRef || this._overlay.create(this._getOverlayConfig());
487
- this._overlayRef.attach(this._getPortal());
488
- this._subscribeToOutsideClicks();
489
- }
490
- }
491
- /** Close the opened menu. */
492
- close() {
493
- if (this.isOpen()) {
494
- this.closed.next();
495
- this._overlayRef.detach();
496
- }
497
- this._closeSiblingTriggers();
498
- }
499
- /**
500
- * Get a reference to the rendered Menu if the Menu is open and it is visible in the DOM.
501
- * @return the menu if it is open, otherwise undefined.
502
- */
503
- getMenu() {
504
- return this.childMenu;
505
- }
506
- /**
507
- * Subscribe to the mouseenter events and close any sibling menu items if this element is moused
508
- * into.
509
- */
510
- _subscribeToMouseEnter() {
511
- // Closes any sibling menu items and opens the menu associated with this trigger.
512
- const toggleMenus = () => this._ngZone.run(() => {
513
- this._closeSiblingTriggers();
514
- this.open();
515
- });
516
- this._ngZone.runOutsideAngular(() => {
517
- fromEvent(this._elementRef.nativeElement, 'mouseenter')
518
- .pipe(filter(() => !this.menuStack.isEmpty() && !this.isOpen()), takeUntil(this._destroyed))
519
- .subscribe(() => {
520
- if (this._menuAim) {
521
- this._menuAim.toggle(toggleMenus);
522
- }
523
- else {
524
- toggleMenus();
525
- }
526
- });
527
- });
528
- }
529
- /**
530
- * Handles keyboard events for the menu item, specifically opening/closing the attached menu and
531
- * focusing the appropriate submenu item.
532
- * @param event the keyboard event to handle
533
- */
534
- _toggleOnKeydown(event) {
535
- const keyCode = event.keyCode;
536
- switch (keyCode) {
537
- case SPACE:
538
- case ENTER:
539
- event.preventDefault();
540
- this.toggle();
541
- this.childMenu?.focusFirstItem('keyboard');
542
- break;
543
- case RIGHT_ARROW:
544
- if (this._parentMenu && this._isParentVertical() && this._directionality?.value !== 'rtl') {
545
- event.preventDefault();
546
- this.open();
547
- this.childMenu?.focusFirstItem('keyboard');
548
- }
549
- break;
550
- case LEFT_ARROW:
551
- if (this._parentMenu && this._isParentVertical() && this._directionality?.value === 'rtl') {
552
- event.preventDefault();
553
- this.open();
554
- this.childMenu?.focusFirstItem('keyboard');
555
- }
556
- break;
557
- case DOWN_ARROW:
558
- case UP_ARROW:
559
- if (!this._isParentVertical()) {
560
- event.preventDefault();
561
- this.open();
562
- keyCode === DOWN_ARROW
563
- ? this.childMenu?.focusFirstItem('keyboard')
564
- : this.childMenu?.focusLastItem('keyboard');
565
- }
566
- break;
567
- }
568
- }
569
- /** Close out any sibling menu trigger menus. */
570
- _closeSiblingTriggers() {
571
- if (this._parentMenu) {
572
- // If nothing was removed from the stack and the last element is not the parent item
573
- // that means that the parent menu is a menu bar since we don't put the menu bar on the
574
- // stack
575
- const isParentMenuBar = !this.menuStack.closeSubMenuOf(this._parentMenu) &&
576
- this.menuStack.peek() !== this._parentMenu;
577
- if (isParentMenuBar) {
578
- this.menuStack.closeAll();
579
- }
580
- }
581
- else {
582
- this.menuStack.closeAll();
583
- }
584
- }
585
- /** Get the configuration object used to create the overlay */
586
- _getOverlayConfig() {
587
- return new OverlayConfig({
588
- positionStrategy: this._getOverlayPositionStrategy(),
589
- scrollStrategy: this._overlay.scrollStrategies.block(),
590
- direction: this._directionality,
591
- });
592
- }
593
- /** Build the position strategy for the overlay which specifies where to place the menu */
594
- _getOverlayPositionStrategy() {
595
- return this._overlay
596
- .position()
597
- .flexibleConnectedTo(this._elementRef)
598
- .withPositions(this._getOverlayPositions());
599
- }
600
- /** Determine and return where to position the opened menu relative to the menu item */
601
- _getOverlayPositions() {
602
- return (this.menuPosition ??
603
- (!this._parentMenu || this._parentMenu.orientation === 'horizontal'
604
- ? STANDARD_DROPDOWN_BELOW_POSITIONS
605
- : STANDARD_DROPDOWN_ADJACENT_POSITIONS));
606
- }
607
- /**
608
- * Get the portal to be attached to the overlay which contains the menu. Allows for the menu
609
- * content to change dynamically and be reflected in the application.
610
- */
611
- _getPortal() {
612
- const hasMenuContentChanged = this._menuTemplateRef !== this._menuPortal?.templateRef;
613
- if (this._menuTemplateRef && (!this._menuPortal || hasMenuContentChanged)) {
614
- this._menuPortal = new TemplatePortal(this._menuTemplateRef, this._viewContainerRef, undefined, this.getChildMenuInjector());
615
- }
616
- return this._menuPortal;
617
- }
618
- /**
619
- * @return true if if the enclosing parent menu is configured in a vertical orientation.
620
- */
621
- _isParentVertical() {
622
- return this._parentMenu?.orientation === 'vertical';
623
- }
624
- /**
625
- * Subscribe to the MenuStack close events if this is a standalone trigger and close out the menu
626
- * this triggers when requested.
627
- */
628
- _registerCloseHandler() {
629
- if (!this._parentMenu) {
630
- this.menuStack.closed.pipe(takeUntil(this._destroyed)).subscribe(item => {
631
- if (item === this.childMenu) {
632
- this.close();
633
- }
634
- });
635
- }
636
- }
637
- /**
638
- * Subscribe to the overlays outside pointer events stream and handle closing out the stack if a
639
- * click occurs outside the menus.
640
- */
641
- _subscribeToOutsideClicks() {
642
- if (this._overlayRef) {
643
- this._overlayRef
644
- .outsidePointerEvents()
645
- .pipe(takeUntil(this._stopOutsideClicksListener))
646
- .subscribe(event => {
647
- if (!isClickInsideMenuOverlay(event.target)) {
648
- this.menuStack.closeAll();
649
- }
650
- });
651
- }
652
- }
653
- }
654
- CdkMenuItemTrigger.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.0.0-next.9", ngImport: i0, type: CdkMenuItemTrigger, deps: [{ token: i0.Injector }, { token: i0.ElementRef }, { token: i0.ViewContainerRef }, { token: i1.Overlay }, { token: i0.NgZone }, { token: MENU_STACK }, { token: CDK_MENU, optional: true }, { token: MENU_AIM, optional: true }, { token: i1$1.Directionality, optional: true }], target: i0.ɵɵFactoryTarget.Directive });
655
- CdkMenuItemTrigger.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "12.0.0", version: "14.0.0-next.9", type: CdkMenuItemTrigger, selector: "[cdkMenuTriggerFor]", inputs: { _menuTemplateRef: ["cdkMenuTriggerFor", "_menuTemplateRef"], menuPosition: ["cdkMenuPosition", "menuPosition"] }, outputs: { opened: "cdkMenuOpened", closed: "cdkMenuClosed" }, host: { attributes: { "aria-haspopup": "menu" }, listeners: { "keydown": "_toggleOnKeydown($event)", "click": "toggle()" }, properties: { "attr.aria-expanded": "isOpen()" }, classAttribute: "cdk-menu-trigger" }, providers: [
656
- { provide: MENU_TRIGGER, useExisting: CdkMenuItemTrigger },
657
- PARENT_OR_NEW_MENU_STACK_PROVIDER,
658
- ], exportAs: ["cdkMenuTriggerFor"], usesInheritance: true, ngImport: i0 });
659
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.0.0-next.9", ngImport: i0, type: CdkMenuItemTrigger, decorators: [{
660
- type: Directive,
661
- args: [{
662
- selector: '[cdkMenuTriggerFor]',
663
- exportAs: 'cdkMenuTriggerFor',
664
- host: {
665
- 'class': 'cdk-menu-trigger',
666
- 'aria-haspopup': 'menu',
667
- '(keydown)': '_toggleOnKeydown($event)',
668
- '(click)': 'toggle()',
669
- '[attr.aria-expanded]': 'isOpen()',
670
- },
671
- inputs: ['_menuTemplateRef: cdkMenuTriggerFor', 'menuPosition: cdkMenuPosition'],
672
- outputs: ['opened: cdkMenuOpened', 'closed: cdkMenuClosed'],
673
- providers: [
674
- { provide: MENU_TRIGGER, useExisting: CdkMenuItemTrigger },
675
- PARENT_OR_NEW_MENU_STACK_PROVIDER,
676
- ],
677
- }]
678
- }], ctorParameters: function () { return [{ type: i0.Injector }, { type: i0.ElementRef }, { type: i0.ViewContainerRef }, { type: i1.Overlay }, { type: i0.NgZone }, { type: MenuStack, decorators: [{
679
- type: Inject,
680
- args: [MENU_STACK]
681
- }] }, { type: undefined, decorators: [{
682
- type: Optional
683
- }, {
684
- type: Inject,
685
- args: [CDK_MENU]
686
- }] }, { type: undefined, decorators: [{
687
- type: Optional
688
- }, {
689
- type: Inject,
690
- args: [MENU_AIM]
691
- }] }, { type: i1$1.Directionality, decorators: [{
692
- type: Optional
693
- }] }]; } });
694
-
695
- /**
696
- * @license
697
- * Copyright Google LLC All Rights Reserved.
698
- *
699
- * Use of this source code is governed by an MIT-style license that can be
700
- * found in the LICENSE file at https://angular.io/license
701
- */
702
- /**
703
- * Directive which provides the ability for an element to be focused and navigated to using the
704
- * keyboard when residing in a CdkMenu, CdkMenuBar, or CdkMenuGroup. It performs user defined
705
- * behavior when clicked.
706
- */
707
- class CdkMenuItem {
708
- constructor(_elementRef, _ngZone, _menuStack, _parentMenu, _menuAim, _dir,
709
- /** Reference to the CdkMenuItemTrigger directive if one is added to the same element */
710
- // `CdkMenuItem` is commonly used in combination with a `CdkMenuItemTrigger`.
711
- // tslint:disable-next-line: lightweight-tokens
712
- _menuTrigger) {
713
- this._elementRef = _elementRef;
714
- this._ngZone = _ngZone;
715
- this._menuStack = _menuStack;
716
- this._parentMenu = _parentMenu;
717
- this._menuAim = _menuAim;
718
- this._dir = _dir;
719
- this._menuTrigger = _menuTrigger;
720
- this._disabled = false;
721
- /**
722
- * If this MenuItem is a regular MenuItem, outputs when it is triggered by a keyboard or mouse
723
- * event.
724
- */
725
- this.triggered = new EventEmitter();
726
- /**
727
- * The tabindex for this menu item managed internally and used for implementing roving a
728
- * tab index.
729
- */
730
- this._tabindex = -1;
731
- /** Emits when the menu item is destroyed. */
732
- this._destroyed = new Subject();
733
- this._setupMouseEnter();
734
- if (this._isStandaloneItem()) {
735
- this._tabindex = 0;
736
- }
737
- }
738
- /** Whether the CdkMenuItem is disabled - defaults to false */
739
- get disabled() {
740
- return this._disabled;
741
- }
742
- set disabled(value) {
743
- this._disabled = coerceBooleanProperty(value);
744
- }
745
- /** Place focus on the element. */
746
- focus() {
747
- this._elementRef.nativeElement.focus();
748
- }
749
- /** Reset the _tabindex to -1. */
750
- _resetTabIndex() {
751
- if (!this._isStandaloneItem()) {
752
- this._tabindex = -1;
753
- }
754
- }
755
- /**
756
- * Set the tab index to 0 if not disabled and it's a focus event, or a mouse enter if this element
757
- * is not in a menu bar.
758
- */
759
- _setTabIndex(event) {
760
- if (this.disabled) {
761
- return;
762
- }
763
- // don't set the tabindex if there are no open sibling or parent menus
764
- if (!event || !this._menuStack.isEmpty()) {
765
- this._tabindex = 0;
766
- }
767
- }
768
- /** Whether this menu item is standalone or within a menu or menu bar. */
769
- _isStandaloneItem() {
770
- return !this._parentMenu;
771
- }
772
- /**
773
- * If the menu item is not disabled and the element does not have a menu trigger attached, emit
774
- * on the cdkMenuItemTriggered emitter and close all open menus.
775
- */
776
- trigger() {
777
- if (!this.disabled && !this.hasMenu()) {
778
- this.triggered.next();
779
- this._menuStack.closeAll();
780
- }
781
- }
782
- /** Whether the menu item opens a menu. */
783
- hasMenu() {
784
- return !!this._menuTrigger;
785
- }
786
- /** Return true if this MenuItem has an attached menu and it is open. */
787
- isMenuOpen() {
788
- return !!this._menuTrigger?.isOpen();
789
- }
790
- /**
791
- * Get a reference to the rendered Menu if the Menu is open and it is visible in the DOM.
792
- * @return the menu if it is open, otherwise undefined.
793
- */
794
- getMenu() {
795
- return this._menuTrigger?.getMenu();
796
- }
797
- /** Get the MenuItemTrigger associated with this element. */
798
- getMenuTrigger() {
799
- return this._menuTrigger;
800
- }
801
- /** Get the label for this element which is required by the FocusableOption interface. */
802
- getLabel() {
803
- return this.typeahead || this._elementRef.nativeElement.textContent?.trim() || '';
804
- }
805
- /**
806
- * Handles keyboard events for the menu item, specifically either triggering the user defined
807
- * callback or opening/closing the current menu based on whether the left or right arrow key was
808
- * pressed.
809
- * @param event the keyboard event to handle
810
- */
811
- _onKeydown(event) {
812
- switch (event.keyCode) {
813
- case SPACE:
814
- case ENTER:
815
- event.preventDefault();
816
- this.trigger();
817
- break;
818
- case RIGHT_ARROW:
819
- if (this._parentMenu && this._isParentVertical()) {
820
- if (this._dir?.value === 'rtl') {
821
- if (this._menuStack.hasInlineMenu() || this._menuStack.length() > 1) {
822
- event.preventDefault();
823
- this._menuStack.close(this._parentMenu, 1 /* previousItem */);
824
- }
825
- }
826
- else if (!this.hasMenu()) {
827
- if (this._menuStack.hasInlineMenu()) {
828
- event.preventDefault();
829
- this._menuStack.closeAll(0 /* nextItem */);
830
- }
831
- }
832
- }
833
- break;
834
- case LEFT_ARROW:
835
- if (this._parentMenu && this._isParentVertical()) {
836
- if (this._dir?.value !== 'rtl') {
837
- if (this._menuStack.hasInlineMenu() || this._menuStack.length() > 1) {
838
- event.preventDefault();
839
- this._menuStack.close(this._parentMenu, 1 /* previousItem */);
840
- }
841
- }
842
- else if (!this.hasMenu()) {
843
- if (this._menuStack.hasInlineMenu()) {
844
- event.preventDefault();
845
- this._menuStack.closeAll(0 /* nextItem */);
846
- }
847
- }
848
- }
849
- break;
850
- }
851
- }
852
- /**
853
- * Subscribe to the mouseenter events and close any sibling menu items if this element is moused
854
- * into.
855
- */
856
- _setupMouseEnter() {
857
- if (!this._isStandaloneItem()) {
858
- const closeOpenSiblings = () => this._ngZone.run(() => this._menuStack.closeSubMenuOf(this._parentMenu));
859
- this._ngZone.runOutsideAngular(() => fromEvent(this._elementRef.nativeElement, 'mouseenter')
860
- .pipe(filter(() => !this._menuStack.isEmpty() && !this.hasMenu()), takeUntil(this._destroyed))
861
- .subscribe(() => {
862
- if (this._menuAim) {
863
- this._menuAim.toggle(closeOpenSiblings);
864
- }
865
- else {
866
- closeOpenSiblings();
867
- }
868
- }));
869
- }
870
- }
871
- /**
872
- * Return true if the enclosing parent menu is configured in a horizontal orientation, false
873
- * otherwise or if no parent.
874
- */
875
- _isParentVertical() {
876
- return this._parentMenu?.orientation === 'vertical';
877
- }
878
- ngOnDestroy() {
879
- this._destroyed.next();
880
- }
881
- }
882
- CdkMenuItem.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.0.0-next.9", ngImport: i0, type: CdkMenuItem, deps: [{ token: i0.ElementRef }, { token: i0.NgZone }, { token: MENU_STACK }, { token: CDK_MENU, optional: true }, { token: MENU_AIM, optional: true }, { token: i1$1.Directionality, optional: true }, { token: CdkMenuItemTrigger, optional: true, self: true }], target: i0.ɵɵFactoryTarget.Directive });
883
- CdkMenuItem.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "12.0.0", version: "14.0.0-next.9", type: CdkMenuItem, selector: "[cdkMenuItem]", inputs: { disabled: "disabled", typeahead: "typeahead" }, outputs: { triggered: "cdkMenuItemTriggered" }, host: { attributes: { "type": "button", "role": "menuitem" }, listeners: { "blur": "_resetTabIndex()", "mouseout": "_resetTabIndex()", "focus": "_setTabIndex()", "mouseenter": "_setTabIndex($event)", "click": "trigger()", "keydown": "_onKeydown($event)" }, properties: { "tabindex": "_tabindex", "attr.aria-disabled": "disabled || null" }, classAttribute: "cdk-menu-item" }, exportAs: ["cdkMenuItem"], ngImport: i0 });
884
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.0.0-next.9", ngImport: i0, type: CdkMenuItem, decorators: [{
885
- type: Directive,
886
- args: [{
887
- selector: '[cdkMenuItem]',
888
- exportAs: 'cdkMenuItem',
889
- host: {
890
- '[tabindex]': '_tabindex',
891
- 'type': 'button',
892
- 'role': 'menuitem',
893
- 'class': 'cdk-menu-item',
894
- '[attr.aria-disabled]': 'disabled || null',
895
- '(blur)': '_resetTabIndex()',
896
- '(mouseout)': '_resetTabIndex()',
897
- '(focus)': '_setTabIndex()',
898
- '(mouseenter)': '_setTabIndex($event)',
899
- '(click)': 'trigger()',
900
- '(keydown)': '_onKeydown($event)',
901
- },
902
- }]
903
- }], ctorParameters: function () { return [{ type: i0.ElementRef }, { type: i0.NgZone }, { type: MenuStack, decorators: [{
904
- type: Inject,
905
- args: [MENU_STACK]
906
- }] }, { type: undefined, decorators: [{
907
- type: Optional
908
- }, {
909
- type: Inject,
910
- args: [CDK_MENU]
911
- }] }, { type: undefined, decorators: [{
912
- type: Optional
913
- }, {
914
- type: Inject,
915
- args: [MENU_AIM]
916
- }] }, { type: i1$1.Directionality, decorators: [{
917
- type: Optional
918
- }] }, { type: CdkMenuItemTrigger, decorators: [{
919
- type: Self
920
- }, {
921
- type: Optional
922
- }] }]; }, propDecorators: { disabled: [{
923
- type: Input
924
- }], typeahead: [{
925
- type: Input
926
- }], triggered: [{
927
- type: Output,
928
- args: ['cdkMenuItemTriggered']
929
- }] } });
930
-
931
- /**
932
- * @license
933
- * Copyright Google LLC All Rights Reserved.
934
- *
935
- * Use of this source code is governed by an MIT-style license that can be
936
- * found in the LICENSE file at https://angular.io/license
937
- */
938
- /** Counter used to set a unique id and name for a selectable item */
939
- let nextId = 0;
940
- /**
941
- * Base class providing checked state for MenuItems along with outputting a clicked event when the
942
- * element is triggered. It provides functionality for selectable elements.
943
- */
944
- class CdkMenuItemSelectable extends CdkMenuItem {
945
- constructor() {
946
- super(...arguments);
947
- /** Event emitted when the selectable item is clicked */
948
- this.toggled = new EventEmitter();
949
- this._checked = false;
950
- /** The name of the selectable element with a default value */
951
- this.name = `cdk-selectable-item-${nextId++}`;
952
- /** The id of the selectable element with a default value */
953
- this.id = `cdk-selectable-item-${nextId++}`;
954
- }
955
- /** Whether the element is checked */
956
- get checked() {
957
- return this._checked;
958
- }
959
- set checked(value) {
960
- this._checked = coerceBooleanProperty(value);
961
- }
962
- /** If the element is not disabled emit the click event */
963
- trigger() {
964
- if (!this.disabled) {
965
- this.toggled.next(this);
966
- }
967
- }
968
- }
969
- CdkMenuItemSelectable.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.0.0-next.9", ngImport: i0, type: CdkMenuItemSelectable, deps: null, target: i0.ɵɵFactoryTarget.Directive });
970
- CdkMenuItemSelectable.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "12.0.0", version: "14.0.0-next.9", type: CdkMenuItemSelectable, inputs: { checked: "checked", name: "name", id: "id" }, outputs: { toggled: "cdkMenuItemToggled" }, usesInheritance: true, ngImport: i0 });
971
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.0.0-next.9", ngImport: i0, type: CdkMenuItemSelectable, decorators: [{
972
- type: Directive
973
- }], propDecorators: { toggled: [{
974
- type: Output,
975
- args: ['cdkMenuItemToggled']
976
- }], checked: [{
977
- type: Input
978
- }], name: [{
979
- type: Input
980
- }], id: [{
981
- type: Input
982
- }] } });
983
-
984
- /**
985
- * @license
986
- * Copyright Google LLC All Rights Reserved.
987
- *
988
- * Use of this source code is governed by an MIT-style license that can be
989
- * found in the LICENSE file at https://angular.io/license
990
- */
991
- /**
992
- * Directive which acts as a grouping container for `CdkMenuItem` instances with
993
- * `role="menuitemradio"`, similar to a `role="radiogroup"` element.
994
- */
995
- class CdkMenuGroup {
996
- constructor() {
997
- /** Emits the element when checkbox or radiobutton state changed */
998
- this.change = new EventEmitter();
999
- /** Emits when the _selectableItems QueryList triggers a change */
1000
- this._selectableChanges = new EventEmitter();
1001
- }
1002
- ngAfterContentInit() {
1003
- this._registerMenuSelectionListeners();
1004
- }
1005
- ngOnDestroy() {
1006
- this._selectableChanges.next();
1007
- this._selectableChanges.complete();
1008
- }
1009
- /**
1010
- * Register the child selectable elements with the change emitter and ensure any new child
1011
- * elements do so as well.
1012
- */
1013
- _registerMenuSelectionListeners() {
1014
- this._selectableItems.forEach(selectable => this._registerClickListener(selectable));
1015
- this._selectableItems.changes.subscribe((selectableItems) => {
1016
- this._selectableChanges.next();
1017
- selectableItems.forEach(selectable => this._registerClickListener(selectable));
1018
- });
1019
- }
1020
- /** Register each selectable to emit on the change Emitter when clicked */
1021
- _registerClickListener(selectable) {
1022
- selectable.toggled
1023
- .pipe(takeUntil(this._selectableChanges))
1024
- .subscribe(() => this.change.next(selectable));
1025
- }
1026
- }
1027
- CdkMenuGroup.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.0.0-next.9", ngImport: i0, type: CdkMenuGroup, deps: [], target: i0.ɵɵFactoryTarget.Directive });
1028
- CdkMenuGroup.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "12.0.0", version: "14.0.0-next.9", type: CdkMenuGroup, selector: "[cdkMenuGroup]", outputs: { change: "change" }, host: { attributes: { "role": "group" }, classAttribute: "cdk-menu-group" }, providers: [{ provide: UniqueSelectionDispatcher, useClass: UniqueSelectionDispatcher }], queries: [{ propertyName: "_selectableItems", predicate: CdkMenuItemSelectable, descendants: true }], exportAs: ["cdkMenuGroup"], ngImport: i0 });
1029
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.0.0-next.9", ngImport: i0, type: CdkMenuGroup, decorators: [{
1030
- type: Directive,
1031
- args: [{
1032
- selector: '[cdkMenuGroup]',
1033
- exportAs: 'cdkMenuGroup',
1034
- host: {
1035
- 'role': 'group',
1036
- 'class': 'cdk-menu-group',
1037
- },
1038
- providers: [{ provide: UniqueSelectionDispatcher, useClass: UniqueSelectionDispatcher }],
1039
- }]
1040
- }], propDecorators: { change: [{
1041
- type: Output
1042
- }], _selectableItems: [{
1043
- type: ContentChildren,
1044
- args: [CdkMenuItemSelectable, { descendants: true }]
1045
- }] } });
1046
-
1047
- /**
1048
- * @license
1049
- * Copyright Google LLC All Rights Reserved.
1050
- *
1051
- * Use of this source code is governed by an MIT-style license that can be
1052
- * found in the LICENSE file at https://angular.io/license
1053
- */
1054
- /**
1055
- * PointerFocusTracker keeps track of the currently active item under mouse focus. It also has
1056
- * observables which emit when the users mouse enters and leaves a tracked element.
1057
- */
1058
- class PointerFocusTracker {
1059
- constructor(_items) {
1060
- this._items = _items;
1061
- /** Emits when an element is moused into. */
1062
- this.entered = this._getItemPointerEntries();
1063
- /** Emits when an element is moused out. */
1064
- this.exited = this._getItemPointerExits();
1065
- /** Emits when this is destroyed. */
1066
- this._destroyed = new Subject();
1067
- this.entered.subscribe(element => (this.activeElement = element));
1068
- this.exited.subscribe(() => {
1069
- this.previousElement = this.activeElement;
1070
- this.activeElement = undefined;
1071
- });
1072
- }
1073
- /**
1074
- * Gets a stream of pointer (mouse) entries into the given items.
1075
- * This should typically run outside the Angular zone.
1076
- */
1077
- _getItemPointerEntries() {
1078
- return defer(() => this._items.changes.pipe(startWith(this._items), mergeMap((list) => list.map(element => fromEvent(element._elementRef.nativeElement, 'mouseenter').pipe(mapTo(element), takeUntil(this._items.changes)))), mergeAll()));
1079
- }
1080
- /**
1081
- * Gets a stream of pointer (mouse) exits out of the given items.
1082
- * This should typically run outside the Angular zone.
1083
- */
1084
- _getItemPointerExits() {
1085
- return defer(() => this._items.changes.pipe(startWith(this._items), mergeMap((list) => list.map(element => fromEvent(element._elementRef.nativeElement, 'mouseout').pipe(mapTo(element), takeUntil(this._items.changes)))), mergeAll()));
1086
- }
1087
- /** Stop the managers listeners. */
1088
- destroy() {
1089
- this._destroyed.next();
1090
- this._destroyed.complete();
1091
- }
1092
- }
1093
-
1094
- /**
1095
- * @license
1096
- * Copyright Google LLC All Rights Reserved.
1097
- *
1098
- * Use of this source code is governed by an MIT-style license that can be
1099
- * found in the LICENSE file at https://angular.io/license
1100
- */
1101
- class CdkMenuBase extends CdkMenuGroup {
1102
- constructor(_elementRef, menuStack, dir) {
1103
- super();
1104
- this._elementRef = _elementRef;
1105
- this.menuStack = menuStack;
1106
- this.dir = dir;
1107
- /**
1108
- * Sets the aria-orientation attribute and determines where menus will be opened.
1109
- * Does not affect styling/layout.
1110
- */
1111
- this.orientation = 'vertical';
1112
- /** Emits when the MenuBar is destroyed. */
1113
- this.destroyed = new Subject();
1114
- }
1115
- ngAfterContentInit() {
1116
- super.ngAfterContentInit();
1117
- this._setKeyManager();
1118
- this._subscribeToMenuOpen();
1119
- this._subscribeToMenuStackClosed();
1120
- }
1121
- ngOnDestroy() {
1122
- super.ngOnDestroy();
1123
- this.destroyed.next();
1124
- this.destroyed.complete();
1125
- }
1126
- /** Place focus on the first MenuItem in the menu and set the focus origin. */
1127
- focusFirstItem(focusOrigin = 'program') {
1128
- this.keyManager.setFocusOrigin(focusOrigin);
1129
- this.keyManager.setFirstItemActive();
1130
- }
1131
- /** Place focus on the last MenuItem in the menu and set the focus origin. */
1132
- focusLastItem(focusOrigin = 'program') {
1133
- this.keyManager.setFocusOrigin(focusOrigin);
1134
- this.keyManager.setLastItemActive();
1135
- }
1136
- /** Return true if this menu has been configured in a horizontal orientation. */
1137
- isHorizontal() {
1138
- return this.orientation === 'horizontal';
1139
- }
1140
- /** Return true if the MenuBar has an open submenu. */
1141
- hasOpenSubmenu() {
1142
- return !!this.openItem;
1143
- }
1144
- /**
1145
- * Close the open menu if the current active item opened the requested MenuStackItem.
1146
- * @param item the MenuStackItem requested to be closed.
1147
- */
1148
- closeOpenMenu(menu) {
1149
- const keyManager = this.keyManager;
1150
- const trigger = this.openItem;
1151
- if (menu === trigger?.getMenuTrigger()?.getMenu()) {
1152
- trigger?.getMenuTrigger()?.close();
1153
- // If the user has moused over a sibling item we want to focus the element under mouse focus
1154
- // not the trigger which previously opened the now closed menu.
1155
- if (trigger) {
1156
- keyManager.setActiveItem(this.pointerTracker?.activeElement || trigger);
1157
- }
1158
- }
1159
- }
1160
- /** Setup the FocusKeyManager with the correct orientation for the menu. */
1161
- _setKeyManager() {
1162
- this.keyManager = new FocusKeyManager(this.items).withWrap().withTypeAhead().withHomeAndEnd();
1163
- if (this.isHorizontal()) {
1164
- this.keyManager.withHorizontalOrientation(this.dir?.value || 'ltr');
1165
- }
1166
- else {
1167
- this.keyManager.withVerticalOrientation();
1168
- }
1169
- }
1170
- /**
1171
- * Subscribe to the menu trigger's open events in order to track the trigger which opened the menu
1172
- * and stop tracking it when the menu is closed.
1173
- */
1174
- _subscribeToMenuOpen() {
1175
- const exitCondition = merge(this.items.changes, this.destroyed);
1176
- this.items.changes
1177
- .pipe(startWith(this.items), mergeMap((list) => list
1178
- .filter(item => item.hasMenu())
1179
- .map(item => item.getMenuTrigger().opened.pipe(mapTo(item), takeUntil(exitCondition)))), mergeAll(), switchMap((item) => {
1180
- this.openItem = item;
1181
- return item.getMenuTrigger().closed;
1182
- }), takeUntil(this.destroyed))
1183
- .subscribe(() => (this.openItem = undefined));
1184
- }
1185
- /** Subscribe to the MenuStack close and empty observables. */
1186
- _subscribeToMenuStackClosed() {
1187
- this.menuStack.closed
1188
- .pipe(takeUntil(this.destroyed))
1189
- .subscribe(item => this.closeOpenMenu(item));
1190
- }
1191
- }
1192
- CdkMenuBase.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.0.0-next.9", ngImport: i0, type: CdkMenuBase, deps: [{ token: i0.ElementRef }, { token: MENU_STACK }, { token: i1$1.Directionality, optional: true }], target: i0.ɵɵFactoryTarget.Directive });
1193
- CdkMenuBase.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "12.0.0", version: "14.0.0-next.9", type: CdkMenuBase, host: { listeners: { "focus": "focusFirstItem()" }, properties: { "attr.aria-orientation": "orientation" } }, queries: [{ propertyName: "items", predicate: CdkMenuItem, descendants: true }], usesInheritance: true, ngImport: i0 });
1194
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.0.0-next.9", ngImport: i0, type: CdkMenuBase, decorators: [{
1195
- type: Directive,
1196
- args: [{
1197
- host: {
1198
- '[attr.aria-orientation]': 'orientation',
1199
- '(focus)': 'focusFirstItem()',
1200
- },
1201
- }]
1202
- }], ctorParameters: function () { return [{ type: i0.ElementRef }, { type: MenuStack, decorators: [{
1203
- type: Inject,
1204
- args: [MENU_STACK]
1205
- }] }, { type: i1$1.Directionality, decorators: [{
1206
- type: Optional
1207
- }] }]; }, propDecorators: { items: [{
1208
- type: ContentChildren,
1209
- args: [CdkMenuItem, { descendants: true }]
1210
- }] } });
1211
-
1212
- /**
1213
- * @license
1214
- * Copyright Google LLC All Rights Reserved.
1215
- *
1216
- * Use of this source code is governed by an MIT-style license that can be
1217
- * found in the LICENSE file at https://angular.io/license
1218
- */
1219
- /**
1220
- * Directive which configures the element as a Menu which should contain child elements marked as
1221
- * CdkMenuItem or CdkMenuGroup. Sets the appropriate role and aria-attributes for a menu and
1222
- * contains accessible keyboard and mouse handling logic.
1223
- *
1224
- * It also acts as a RadioGroup for elements marked with role `menuitemradio`.
1225
- */
1226
- class CdkMenu extends CdkMenuBase {
1227
- constructor(_ngZone, elementRef, menuStack, _parentTrigger, _menuAim, dir) {
1228
- super(elementRef, menuStack, dir);
1229
- this._ngZone = _ngZone;
1230
- this._parentTrigger = _parentTrigger;
1231
- this._menuAim = _menuAim;
1232
- /** Event emitted when the menu is closed. */
1233
- this.closed = new EventEmitter();
1234
- this.destroyed.subscribe(this.closed);
1235
- if (!this._isInline()) {
1236
- this.menuStack.push(this);
1237
- }
1238
- this._parentTrigger?.registerChildMenu(this);
1239
- }
1240
- ngAfterContentInit() {
1241
- super.ngAfterContentInit();
1242
- this._completeChangeEmitter();
1243
- this._subscribeToMenuStackEmptied();
1244
- this._subscribeToMouseManager();
1245
- this._menuAim?.initialize(this, this.pointerTracker);
1246
- }
1247
- ngOnDestroy() {
1248
- super.ngOnDestroy();
1249
- this.closed.complete();
1250
- this.pointerTracker?.destroy();
1251
- }
1252
- /** Handle keyboard events for the Menu. */
1253
- _handleKeyEvent(event) {
1254
- const keyManager = this.keyManager;
1255
- switch (event.keyCode) {
1256
- case LEFT_ARROW:
1257
- case RIGHT_ARROW:
1258
- if (this.isHorizontal()) {
1259
- event.preventDefault();
1260
- keyManager.setFocusOrigin('keyboard');
1261
- keyManager.onKeydown(event);
1262
- }
1263
- break;
1264
- case UP_ARROW:
1265
- case DOWN_ARROW:
1266
- if (!this.isHorizontal()) {
1267
- event.preventDefault();
1268
- keyManager.setFocusOrigin('keyboard');
1269
- keyManager.onKeydown(event);
1270
- }
1271
- break;
1272
- case ESCAPE:
1273
- if (!hasModifierKey(event)) {
1274
- event.preventDefault();
1275
- this.menuStack.close(this, 2 /* currentItem */);
1276
- }
1277
- break;
1278
- case TAB:
1279
- this.menuStack.closeAll();
1280
- break;
1281
- default:
1282
- keyManager.onKeydown(event);
1283
- }
1284
- }
1285
- /**
1286
- * Complete the change emitter if there are any nested MenuGroups or register to complete the
1287
- * change emitter if a MenuGroup is rendered at some point
1288
- */
1289
- // TODO(mmalerba): This doesnt' quite work. It causes change events to stop
1290
- // firing for radio items directly in the menu if a second group of options
1291
- // is added in a menu-group.
1292
- _completeChangeEmitter() {
1293
- if (this._hasNestedGroups()) {
1294
- this.change.complete();
1295
- }
1296
- else {
1297
- this._nestedGroups.changes.pipe(take(1)).subscribe(() => this.change.complete());
1298
- }
1299
- }
1300
- /** Return true if there are nested CdkMenuGroup elements within the Menu */
1301
- _hasNestedGroups() {
1302
- // view engine has a bug where @ContentChildren will return the current element
1303
- // along with children if the selectors match - not just the children.
1304
- // Here, if there is at least one element, we check to see if the first element is a CdkMenu in
1305
- // order to ensure that we return true iff there are child CdkMenuGroup elements.
1306
- return this._nestedGroups.length > 0 && !(this._nestedGroups.first instanceof CdkMenu);
1307
- }
1308
- /**
1309
- * Set the PointerFocusTracker and ensure that when mouse focus changes the key manager is updated
1310
- * with the latest menu item under mouse focus.
1311
- */
1312
- _subscribeToMouseManager() {
1313
- this._ngZone.runOutsideAngular(() => {
1314
- this.pointerTracker = new PointerFocusTracker(this.items);
1315
- this.pointerTracker.entered
1316
- .pipe(takeUntil(this.closed))
1317
- .subscribe(item => this.keyManager.setActiveItem(item));
1318
- });
1319
- }
1320
- /** Set focus the either the current, previous or next item based on the FocusNext event. */
1321
- _toggleMenuFocus(event) {
1322
- const keyManager = this.keyManager;
1323
- switch (event) {
1324
- case 0 /* nextItem */:
1325
- keyManager.setFocusOrigin('keyboard');
1326
- keyManager.setNextItemActive();
1327
- break;
1328
- case 1 /* previousItem */:
1329
- keyManager.setFocusOrigin('keyboard');
1330
- keyManager.setPreviousItemActive();
1331
- break;
1332
- case 2 /* currentItem */:
1333
- if (keyManager.activeItem) {
1334
- keyManager.setFocusOrigin('keyboard');
1335
- keyManager.setActiveItem(keyManager.activeItem);
1336
- }
1337
- break;
1338
- }
1339
- }
1340
- /**
1341
- * Return true if this menu is an inline menu. That is, it does not exist in a pop-up and is
1342
- * always visible in the dom.
1343
- */
1344
- _isInline() {
1345
- return !this._parentTrigger;
1346
- }
1347
- _subscribeToMenuStackEmptied() {
1348
- this.menuStack.emptied
1349
- .pipe(takeUntil(this.destroyed))
1350
- .subscribe(event => this._toggleMenuFocus(event));
1351
- }
1352
- }
1353
- CdkMenu.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.0.0-next.9", ngImport: i0, type: CdkMenu, deps: [{ token: i0.NgZone }, { token: i0.ElementRef }, { token: MENU_STACK }, { token: MENU_TRIGGER, optional: true }, { token: MENU_AIM, optional: true, self: true }, { token: i1$1.Directionality, optional: true }], target: i0.ɵɵFactoryTarget.Directive });
1354
- CdkMenu.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "12.0.0", version: "14.0.0-next.9", type: CdkMenu, selector: "[cdkMenu]", outputs: { closed: "closed" }, host: { attributes: { "role": "menu" }, listeners: { "keydown": "_handleKeyEvent($event)" }, properties: { "tabindex": "_isInline() ? 0 : null", "class.cdk-menu-inline": "_isInline()" }, classAttribute: "cdk-menu" }, providers: [
1355
- { provide: CdkMenuGroup, useExisting: CdkMenu },
1356
- { provide: CDK_MENU, useExisting: CdkMenu },
1357
- PARENT_OR_NEW_INLINE_MENU_STACK_PROVIDER,
1358
- ], queries: [{ propertyName: "_nestedGroups", predicate: CdkMenuGroup, descendants: true }], exportAs: ["cdkMenu"], usesInheritance: true, ngImport: i0 });
1359
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.0.0-next.9", ngImport: i0, type: CdkMenu, decorators: [{
1360
- type: Directive,
1361
- args: [{
1362
- selector: '[cdkMenu]',
1363
- exportAs: 'cdkMenu',
1364
- host: {
1365
- 'role': 'menu',
1366
- 'class': 'cdk-menu',
1367
- '[tabindex]': '_isInline() ? 0 : null',
1368
- '[class.cdk-menu-inline]': '_isInline()',
1369
- '(keydown)': '_handleKeyEvent($event)',
1370
- },
1371
- providers: [
1372
- { provide: CdkMenuGroup, useExisting: CdkMenu },
1373
- { provide: CDK_MENU, useExisting: CdkMenu },
1374
- PARENT_OR_NEW_INLINE_MENU_STACK_PROVIDER,
1375
- ],
1376
- }]
1377
- }], ctorParameters: function () { return [{ type: i0.NgZone }, { type: i0.ElementRef }, { type: MenuStack, decorators: [{
1378
- type: Inject,
1379
- args: [MENU_STACK]
1380
- }] }, { type: MenuTrigger, decorators: [{
1381
- type: Optional
1382
- }, {
1383
- type: Inject,
1384
- args: [MENU_TRIGGER]
1385
- }] }, { type: undefined, decorators: [{
1386
- type: Self
1387
- }, {
1388
- type: Optional
1389
- }, {
1390
- type: Inject,
1391
- args: [MENU_AIM]
1392
- }] }, { type: i1$1.Directionality, decorators: [{
1393
- type: Optional
1394
- }] }]; }, propDecorators: { closed: [{
1395
- type: Output
1396
- }], _nestedGroups: [{
1397
- type: ContentChildren,
1398
- args: [CdkMenuGroup, { descendants: true }]
1399
- }] } });
1400
-
1401
- /**
1402
- * @license
1403
- * Copyright Google LLC All Rights Reserved.
1404
- *
1405
- * Use of this source code is governed by an MIT-style license that can be
1406
- * found in the LICENSE file at https://angular.io/license
1407
- */
1408
- /**
1409
- * Directive applied to an element which configures it as a MenuBar by setting the appropriate
1410
- * role, aria attributes, and accessible keyboard and mouse handling logic. The component that
1411
- * this directive is applied to should contain components marked with CdkMenuItem.
1412
- *
1413
- */
1414
- class CdkMenuBar extends CdkMenuBase {
1415
- constructor(_ngZone, elementRef, menuStack, _menuAim, dir) {
1416
- super(elementRef, menuStack, dir);
1417
- this._ngZone = _ngZone;
1418
- this._menuAim = _menuAim;
1419
- this.orientation = 'horizontal';
1420
- }
1421
- ngAfterContentInit() {
1422
- super.ngAfterContentInit();
1423
- this._subscribeToMenuStackEmptied();
1424
- this._subscribeToMouseManager();
1425
- this._menuAim?.initialize(this, this.pointerTracker);
1426
- }
1427
- ngOnDestroy() {
1428
- super.ngOnDestroy();
1429
- this.pointerTracker?.destroy();
1430
- }
1431
- /**
1432
- * Handle keyboard events, specifically changing the focused element and/or toggling the active
1433
- * items menu.
1434
- * @param event the KeyboardEvent to handle.
1435
- */
1436
- _handleKeyEvent(event) {
1437
- const keyManager = this.keyManager;
1438
- switch (event.keyCode) {
1439
- case UP_ARROW:
1440
- case DOWN_ARROW:
1441
- case LEFT_ARROW:
1442
- case RIGHT_ARROW:
1443
- const horizontalArrows = event.keyCode === LEFT_ARROW || event.keyCode === RIGHT_ARROW;
1444
- // For a horizontal menu if the left/right keys were clicked, or a vertical menu if the
1445
- // up/down keys were clicked: if the current menu is open, close it then focus and open the
1446
- // next menu.
1447
- if ((this.isHorizontal() && horizontalArrows) ||
1448
- (!this.isHorizontal() && !horizontalArrows)) {
1449
- event.preventDefault();
1450
- const prevIsOpen = keyManager.activeItem?.isMenuOpen();
1451
- keyManager.activeItem?.getMenuTrigger()?.close();
1452
- keyManager.setFocusOrigin('keyboard');
1453
- keyManager.onKeydown(event);
1454
- if (prevIsOpen) {
1455
- keyManager.activeItem?.getMenuTrigger()?.open();
1456
- }
1457
- }
1458
- break;
1459
- case ESCAPE:
1460
- event.preventDefault();
1461
- keyManager.activeItem?.getMenuTrigger()?.close();
1462
- break;
1463
- case TAB:
1464
- keyManager.activeItem?.getMenuTrigger()?.close();
1465
- break;
1466
- default:
1467
- keyManager.onKeydown(event);
1468
- }
1469
- }
1470
- /**
1471
- * Set the PointerFocusTracker and ensure that when mouse focus changes the key manager is updated
1472
- * with the latest menu item under mouse focus.
1473
- */
1474
- _subscribeToMouseManager() {
1475
- this._ngZone.runOutsideAngular(() => {
1476
- this.pointerTracker = new PointerFocusTracker(this.items);
1477
- this.pointerTracker.entered.pipe(takeUntil(this.destroyed)).subscribe(item => {
1478
- if (this.hasOpenSubmenu()) {
1479
- this.keyManager.setActiveItem(item);
1480
- }
1481
- });
1482
- });
1483
- }
1484
- /**
1485
- * Set focus to either the current, previous or next item based on the FocusNext event, then
1486
- * open the previous or next item.
1487
- */
1488
- _toggleOpenMenu(event) {
1489
- const keyManager = this.keyManager;
1490
- switch (event) {
1491
- case 0 /* nextItem */:
1492
- keyManager.setFocusOrigin('keyboard');
1493
- keyManager.setNextItemActive();
1494
- keyManager.activeItem?.getMenuTrigger()?.open();
1495
- break;
1496
- case 1 /* previousItem */:
1497
- keyManager.setFocusOrigin('keyboard');
1498
- keyManager.setPreviousItemActive();
1499
- keyManager.activeItem?.getMenuTrigger()?.open();
1500
- break;
1501
- case 2 /* currentItem */:
1502
- if (keyManager.activeItem) {
1503
- keyManager.setFocusOrigin('keyboard');
1504
- keyManager.setActiveItem(keyManager.activeItem);
1505
- }
1506
- break;
1507
- }
1508
- }
1509
- _subscribeToMenuStackEmptied() {
1510
- this.menuStack?.emptied
1511
- .pipe(takeUntil(this.destroyed))
1512
- .subscribe(event => this._toggleOpenMenu(event));
1513
- }
1514
- }
1515
- CdkMenuBar.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.0.0-next.9", ngImport: i0, type: CdkMenuBar, deps: [{ token: i0.NgZone }, { token: i0.ElementRef }, { token: MENU_STACK }, { token: MENU_AIM, optional: true, self: true }, { token: i1$1.Directionality, optional: true }], target: i0.ɵɵFactoryTarget.Directive });
1516
- CdkMenuBar.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "12.0.0", version: "14.0.0-next.9", type: CdkMenuBar, selector: "[cdkMenuBar]", host: { attributes: { "role": "menubar", "tabindex": "0" }, listeners: { "keydown": "_handleKeyEvent($event)" }, classAttribute: "cdk-menu-bar" }, providers: [
1517
- { provide: CdkMenuGroup, useExisting: CdkMenuBar },
1518
- { provide: CDK_MENU, useExisting: CdkMenuBar },
1519
- { provide: MENU_STACK, useFactory: () => MenuStack.inline() },
1520
- ], exportAs: ["cdkMenuBar"], usesInheritance: true, ngImport: i0 });
1521
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.0.0-next.9", ngImport: i0, type: CdkMenuBar, decorators: [{
1522
- type: Directive,
1523
- args: [{
1524
- selector: '[cdkMenuBar]',
1525
- exportAs: 'cdkMenuBar',
1526
- host: {
1527
- 'role': 'menubar',
1528
- 'class': 'cdk-menu-bar',
1529
- 'tabindex': '0',
1530
- '(keydown)': '_handleKeyEvent($event)',
1531
- },
1532
- providers: [
1533
- { provide: CdkMenuGroup, useExisting: CdkMenuBar },
1534
- { provide: CDK_MENU, useExisting: CdkMenuBar },
1535
- { provide: MENU_STACK, useFactory: () => MenuStack.inline() },
1536
- ],
1537
- }]
1538
- }], ctorParameters: function () { return [{ type: i0.NgZone }, { type: i0.ElementRef }, { type: MenuStack, decorators: [{
1539
- type: Inject,
1540
- args: [MENU_STACK]
1541
- }] }, { type: undefined, decorators: [{
1542
- type: Self
1543
- }, {
1544
- type: Optional
1545
- }, {
1546
- type: Inject,
1547
- args: [MENU_AIM]
1548
- }] }, { type: i1$1.Directionality, decorators: [{
1549
- type: Optional
1550
- }] }]; } });
1551
-
1552
- /**
1553
- * @license
1554
- * Copyright Google LLC All Rights Reserved.
1555
- *
1556
- * Use of this source code is governed by an MIT-style license that can be
1557
- * found in the LICENSE file at https://angular.io/license
1558
- */
1559
- /**
1560
- * A directive providing behavior for the "menuitemradio" ARIA role, which behaves similarly to
1561
- * a conventional radio-button. Any sibling `CdkMenuItemRadio` instances within the same `CdkMenu`
1562
- * or `CdkMenuGroup` comprise a radio group with unique selection enforced.
1563
- */
1564
- class CdkMenuItemRadio extends CdkMenuItemSelectable {
1565
- constructor(_selectionDispatcher, element, ngZone, menuStack, parentMenu, menuAim, dir,
1566
- /** Reference to the CdkMenuItemTrigger directive if one is added to the same element */
1567
- // `CdkMenuItemRadio` is commonly used in combination with a `CdkMenuItemTrigger`.
1568
- // tslint:disable-next-line: lightweight-tokens
1569
- menuTrigger) {
1570
- super(element, ngZone, menuStack, parentMenu, menuAim, dir, menuTrigger);
1571
- this._selectionDispatcher = _selectionDispatcher;
1572
- this._registerDispatcherListener();
1573
- }
1574
- /** Configure the unique selection dispatcher listener in order to toggle the checked state */
1575
- _registerDispatcherListener() {
1576
- this._removeDispatcherListener = this._selectionDispatcher.listen((id, name) => (this.checked = this.id === id && this.name === name));
1577
- }
1578
- /** Toggles the checked state of the radio-button. */
1579
- trigger() {
1580
- super.trigger();
1581
- if (!this.disabled) {
1582
- this._selectionDispatcher.notify(this.id, this.name);
1583
- }
1584
- }
1585
- ngOnDestroy() {
1586
- super.ngOnDestroy();
1587
- this._removeDispatcherListener();
1588
- }
1589
- }
1590
- CdkMenuItemRadio.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.0.0-next.9", ngImport: i0, type: CdkMenuItemRadio, deps: [{ token: i1$2.UniqueSelectionDispatcher }, { token: i0.ElementRef }, { token: i0.NgZone }, { token: MENU_STACK }, { token: CDK_MENU, optional: true }, { token: MENU_AIM, optional: true }, { token: i1$1.Directionality, optional: true }, { token: CdkMenuItemTrigger, optional: true, self: true }], target: i0.ɵɵFactoryTarget.Directive });
1591
- CdkMenuItemRadio.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "12.0.0", version: "14.0.0-next.9", type: CdkMenuItemRadio, selector: "[cdkMenuItemRadio]", host: { attributes: { "type": "button", "role": "menuitemradio" }, properties: { "tabindex": "_tabindex", "attr.aria-checked": "checked || null", "attr.aria-disabled": "disabled || null" } }, providers: [
1592
- { provide: CdkMenuItemSelectable, useExisting: CdkMenuItemRadio },
1593
- { provide: CdkMenuItem, useExisting: CdkMenuItemSelectable },
1594
- ], exportAs: ["cdkMenuItemRadio"], usesInheritance: true, ngImport: i0 });
1595
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.0.0-next.9", ngImport: i0, type: CdkMenuItemRadio, decorators: [{
1596
- type: Directive,
1597
- args: [{
1598
- selector: '[cdkMenuItemRadio]',
1599
- exportAs: 'cdkMenuItemRadio',
1600
- host: {
1601
- '[tabindex]': '_tabindex',
1602
- 'type': 'button',
1603
- 'role': 'menuitemradio',
1604
- '[attr.aria-checked]': 'checked || null',
1605
- '[attr.aria-disabled]': 'disabled || null',
1606
- },
1607
- providers: [
1608
- { provide: CdkMenuItemSelectable, useExisting: CdkMenuItemRadio },
1609
- { provide: CdkMenuItem, useExisting: CdkMenuItemSelectable },
1610
- ],
1611
- }]
1612
- }], ctorParameters: function () { return [{ type: i1$2.UniqueSelectionDispatcher }, { type: i0.ElementRef }, { type: i0.NgZone }, { type: MenuStack, decorators: [{
1613
- type: Inject,
1614
- args: [MENU_STACK]
1615
- }] }, { type: undefined, decorators: [{
1616
- type: Optional
1617
- }, {
1618
- type: Inject,
1619
- args: [CDK_MENU]
1620
- }] }, { type: undefined, decorators: [{
1621
- type: Optional
1622
- }, {
1623
- type: Inject,
1624
- args: [MENU_AIM]
1625
- }] }, { type: i1$1.Directionality, decorators: [{
1626
- type: Optional
1627
- }] }, { type: CdkMenuItemTrigger, decorators: [{
1628
- type: Self
1629
- }, {
1630
- type: Optional
1631
- }] }]; } });
1632
-
1633
- /**
1634
- * @license
1635
- * Copyright Google LLC All Rights Reserved.
1636
- *
1637
- * Use of this source code is governed by an MIT-style license that can be
1638
- * found in the LICENSE file at https://angular.io/license
1639
- */
1640
- /**
1641
- * A directive providing behavior for the "menuitemcheckbox" ARIA role, which behaves similarly to a
1642
- * conventional checkbox.
1643
- */
1644
- class CdkMenuItemCheckbox extends CdkMenuItemSelectable {
1645
- /** Toggle the checked state of the checkbox. */
1646
- trigger() {
1647
- super.trigger();
1648
- if (!this.disabled) {
1649
- this.checked = !this.checked;
1650
- }
1651
- }
1652
- }
1653
- CdkMenuItemCheckbox.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.0.0-next.9", ngImport: i0, type: CdkMenuItemCheckbox, deps: null, target: i0.ɵɵFactoryTarget.Directive });
1654
- CdkMenuItemCheckbox.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "12.0.0", version: "14.0.0-next.9", type: CdkMenuItemCheckbox, selector: "[cdkMenuItemCheckbox]", host: { attributes: { "type": "button", "role": "menuitemcheckbox" }, properties: { "tabindex": "_tabindex", "attr.aria-checked": "checked || null", "attr.aria-disabled": "disabled || null" } }, providers: [
1655
- { provide: CdkMenuItemSelectable, useExisting: CdkMenuItemCheckbox },
1656
- { provide: CdkMenuItem, useExisting: CdkMenuItemSelectable },
1657
- ], exportAs: ["cdkMenuItemCheckbox"], usesInheritance: true, ngImport: i0 });
1658
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.0.0-next.9", ngImport: i0, type: CdkMenuItemCheckbox, decorators: [{
1659
- type: Directive,
1660
- args: [{
1661
- selector: '[cdkMenuItemCheckbox]',
1662
- exportAs: 'cdkMenuItemCheckbox',
1663
- host: {
1664
- '[tabindex]': '_tabindex',
1665
- 'type': 'button',
1666
- 'role': 'menuitemcheckbox',
1667
- '[attr.aria-checked]': 'checked || null',
1668
- '[attr.aria-disabled]': 'disabled || null',
1669
- },
1670
- providers: [
1671
- { provide: CdkMenuItemSelectable, useExisting: CdkMenuItemCheckbox },
1672
- { provide: CdkMenuItem, useExisting: CdkMenuItemSelectable },
1673
- ],
1674
- }]
1675
- }] });
1676
-
1677
- /**
1678
- * @license
1679
- * Copyright Google LLC All Rights Reserved.
1680
- *
1681
- * Use of this source code is governed by an MIT-style license that can be
1682
- * found in the LICENSE file at https://angular.io/license
1683
- */
1684
- // In cases where the first menu item in the context menu is a trigger the submenu opens on a
1685
- // hover event. We offset the context menu 2px by default to prevent this from occurring.
1686
- const CONTEXT_MENU_POSITIONS = STANDARD_DROPDOWN_BELOW_POSITIONS.map(position => {
1687
- const offsetX = position.overlayX === 'start' ? 2 : -2;
1688
- const offsetY = position.overlayY === 'top' ? 2 : -2;
1689
- return { ...position, offsetX, offsetY };
1690
- });
1691
- /** Tracks the last open context menu trigger across the entire application. */
1692
- class ContextMenuTracker {
1693
- /**
1694
- * Close the previous open context menu and set the given one as being open.
1695
- * @param trigger the trigger for the currently open Context Menu.
1696
- */
1697
- update(trigger) {
1698
- if (ContextMenuTracker._openContextMenuTrigger !== trigger) {
1699
- ContextMenuTracker._openContextMenuTrigger?.close();
1700
- ContextMenuTracker._openContextMenuTrigger = trigger;
1701
- }
1702
- }
1703
- }
1704
- ContextMenuTracker.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.0.0-next.9", ngImport: i0, type: ContextMenuTracker, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
1705
- ContextMenuTracker.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "14.0.0-next.9", ngImport: i0, type: ContextMenuTracker, providedIn: 'root' });
1706
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.0.0-next.9", ngImport: i0, type: ContextMenuTracker, decorators: [{
1707
- type: Injectable,
1708
- args: [{ providedIn: 'root' }]
1709
- }] });
1710
- /**
1711
- * A directive which when placed on some element opens a the Menu it is bound to when a user
1712
- * right-clicks within that element. It is aware of nested Context Menus and the lowest level
1713
- * non-disabled context menu will trigger.
1714
- */
1715
- class CdkContextMenuTrigger extends MenuTrigger {
1716
- constructor(injector, _viewContainerRef, _overlay, _contextMenuTracker, menuStack, _directionality) {
1717
- super(injector, menuStack);
1718
- this._viewContainerRef = _viewContainerRef;
1719
- this._overlay = _overlay;
1720
- this._contextMenuTracker = _contextMenuTracker;
1721
- this._directionality = _directionality;
1722
- this._disabled = false;
1723
- this._setMenuStackListener();
1724
- }
1725
- /** Whether the context menu should be disabled. */
1726
- get disabled() {
1727
- return this._disabled;
1728
- }
1729
- set disabled(value) {
1730
- this._disabled = coerceBooleanProperty(value);
1731
- }
1732
- /**
1733
- * Open the attached menu at the specified location.
1734
- * @param coordinates where to open the context menu
1735
- */
1736
- open(coordinates) {
1737
- this._open(coordinates, false);
1738
- }
1739
- _open(coordinates, ignoreFirstOutsideAuxClick) {
1740
- if (this.disabled) {
1741
- return;
1742
- }
1743
- else if (this.isOpen()) {
1744
- // since we're moving this menu we need to close any submenus first otherwise they end up
1745
- // disconnected from this one.
1746
- this.menuStack.closeSubMenuOf(this.childMenu);
1747
- this._overlayRef.getConfig().positionStrategy.setOrigin(coordinates);
1748
- this._overlayRef.updatePosition();
1749
- }
1750
- else {
1751
- this.opened.next();
1752
- if (this._overlayRef) {
1753
- this._overlayRef.getConfig().positionStrategy.setOrigin(coordinates);
1754
- this._overlayRef.updatePosition();
1755
- }
1756
- else {
1757
- this._overlayRef = this._overlay.create(this._getOverlayConfig(coordinates));
1758
- }
1759
- this._overlayRef.attach(this._getMenuContent());
1760
- this._subscribeToOutsideClicks(ignoreFirstOutsideAuxClick);
1761
- }
1762
- }
1763
- /** Close the opened menu. */
1764
- close() {
1765
- this.menuStack.closeAll();
1766
- }
1767
- /**
1768
- * Open the context menu and close any previously open menus.
1769
- * @param event the mouse event which opens the context menu.
1770
- */
1771
- _openOnContextMenu(event) {
1772
- if (!this.disabled) {
1773
- // Prevent the native context menu from opening because we're opening a custom one.
1774
- event.preventDefault();
1775
- // Stop event propagation to ensure that only the closest enabled context menu opens.
1776
- // Otherwise, any context menus attached to containing elements would *also* open,
1777
- // resulting in multiple stacked context menus being displayed.
1778
- event.stopPropagation();
1779
- this._contextMenuTracker.update(this);
1780
- this._open({ x: event.clientX, y: event.clientY }, true);
1781
- // A context menu can be triggered via a mouse right click or a keyboard shortcut.
1782
- if (event.button === 2) {
1783
- this.childMenu?.focusFirstItem('mouse');
1784
- }
1785
- else if (event.button === 0) {
1786
- this.childMenu?.focusFirstItem('keyboard');
1787
- }
1788
- else {
1789
- this.childMenu?.focusFirstItem('program');
1790
- }
1791
- }
1792
- }
1793
- /**
1794
- * Get the configuration object used to create the overlay.
1795
- * @param coordinates the location to place the opened menu
1796
- */
1797
- _getOverlayConfig(coordinates) {
1798
- return new OverlayConfig({
1799
- positionStrategy: this._getOverlayPositionStrategy(coordinates),
1800
- scrollStrategy: this._overlay.scrollStrategies.block(),
1801
- direction: this._directionality,
1802
- });
1803
- }
1804
- /**
1805
- * Build the position strategy for the overlay which specifies where to place the menu.
1806
- * @param coordinates the location to place the opened menu
1807
- */
1808
- _getOverlayPositionStrategy(coordinates) {
1809
- return this._overlay
1810
- .position()
1811
- .flexibleConnectedTo(coordinates)
1812
- .withPositions(this.menuPosition ?? CONTEXT_MENU_POSITIONS);
1813
- }
1814
- /**
1815
- * Get the portal to be attached to the overlay which contains the menu. Allows for the menu
1816
- * content to change dynamically and be reflected in the application.
1817
- */
1818
- _getMenuContent() {
1819
- const hasMenuContentChanged = this._menuTemplateRef !== this._menuPortal?.templateRef;
1820
- if (this._menuTemplateRef && (!this._menuPortal || hasMenuContentChanged)) {
1821
- this._menuPortal = new TemplatePortal(this._menuTemplateRef, this._viewContainerRef, undefined, this.getChildMenuInjector());
1822
- }
1823
- return this._menuPortal;
1824
- }
1825
- /** Subscribe to the menu stack close events and close this menu when requested. */
1826
- _setMenuStackListener() {
1827
- this.menuStack.closed.pipe(takeUntil(this._destroyed)).subscribe(item => {
1828
- if (item === this.childMenu && this.isOpen()) {
1829
- this.closed.next();
1830
- this._overlayRef.detach();
1831
- }
1832
- });
1833
- }
1834
- /**
1835
- * Subscribe to the overlays outside pointer events stream and handle closing out the stack if a
1836
- * click occurs outside the menus.
1837
- */
1838
- _subscribeToOutsideClicks(ignoreFirstAuxClick) {
1839
- if (this._overlayRef) {
1840
- let outsideClicks = this._overlayRef.outsidePointerEvents();
1841
- // If the menu was triggered by the `contextmenu` event, skip the first `auxclick` event
1842
- // because it fires when the mouse is released on the same click that opened the menu.
1843
- if (ignoreFirstAuxClick) {
1844
- const [auxClicks, nonAuxClicks] = partition(outsideClicks, ({ type }) => type === 'auxclick');
1845
- outsideClicks = merge(nonAuxClicks, auxClicks.pipe(skip(1)));
1846
- }
1847
- outsideClicks.pipe(takeUntil(this._stopOutsideClicksListener)).subscribe(event => {
1848
- if (!isClickInsideMenuOverlay(event.target)) {
1849
- this.menuStack.closeAll();
1850
- }
1851
- });
1852
- }
1853
- }
1854
- }
1855
- CdkContextMenuTrigger.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.0.0-next.9", ngImport: i0, type: CdkContextMenuTrigger, deps: [{ token: i0.Injector }, { token: i0.ViewContainerRef }, { token: i1.Overlay }, { token: ContextMenuTracker }, { token: MENU_STACK }, { token: i1$1.Directionality, optional: true }], target: i0.ɵɵFactoryTarget.Directive });
1856
- CdkContextMenuTrigger.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "12.0.0", version: "14.0.0-next.9", type: CdkContextMenuTrigger, selector: "[cdkContextMenuTriggerFor]", inputs: { _menuTemplateRef: ["cdkContextMenuTriggerFor", "_menuTemplateRef"], menuPosition: ["cdkContextMenuPosition", "menuPosition"], disabled: ["cdkContextMenuDisabled", "disabled"] }, outputs: { opened: "cdkContextMenuOpened", closed: "cdkContextMenuClosed" }, host: { listeners: { "contextmenu": "_openOnContextMenu($event)" } }, providers: [
1857
- { provide: MENU_TRIGGER, useExisting: CdkContextMenuTrigger },
1858
- { provide: MENU_STACK, useClass: MenuStack },
1859
- ], exportAs: ["cdkContextMenuTriggerFor"], usesInheritance: true, ngImport: i0 });
1860
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.0.0-next.9", ngImport: i0, type: CdkContextMenuTrigger, decorators: [{
1861
- type: Directive,
1862
- args: [{
1863
- selector: '[cdkContextMenuTriggerFor]',
1864
- exportAs: 'cdkContextMenuTriggerFor',
1865
- host: {
1866
- '(contextmenu)': '_openOnContextMenu($event)',
1867
- },
1868
- inputs: ['_menuTemplateRef: cdkContextMenuTriggerFor', 'menuPosition: cdkContextMenuPosition'],
1869
- outputs: ['opened: cdkContextMenuOpened', 'closed: cdkContextMenuClosed'],
1870
- providers: [
1871
- { provide: MENU_TRIGGER, useExisting: CdkContextMenuTrigger },
1872
- { provide: MENU_STACK, useClass: MenuStack },
1873
- ],
1874
- }]
1875
- }], ctorParameters: function () { return [{ type: i0.Injector }, { type: i0.ViewContainerRef }, { type: i1.Overlay }, { type: ContextMenuTracker }, { type: MenuStack, decorators: [{
1876
- type: Inject,
1877
- args: [MENU_STACK]
1878
- }] }, { type: i1$1.Directionality, decorators: [{
1879
- type: Optional
1880
- }] }]; }, propDecorators: { disabled: [{
1881
- type: Input,
1882
- args: ['cdkContextMenuDisabled']
1883
- }] } });
1884
-
1885
- /**
1886
- * @license
1887
- * Copyright Google LLC All Rights Reserved.
1888
- *
1889
- * Use of this source code is governed by an MIT-style license that can be
1890
- * found in the LICENSE file at https://angular.io/license
1891
- */
1892
- const EXPORTED_DECLARATIONS = [
1893
- CdkMenuBar,
1894
- CdkMenu,
1895
- CdkMenuItem,
1896
- CdkMenuItemRadio,
1897
- CdkMenuItemCheckbox,
1898
- CdkMenuItemTrigger,
1899
- CdkMenuGroup,
1900
- CdkContextMenuTrigger,
1901
- CdkTargetMenuAim,
1902
- ];
1903
- class CdkMenuModule {
1904
- }
1905
- CdkMenuModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.0.0-next.9", ngImport: i0, type: CdkMenuModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
1906
- CdkMenuModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "12.0.0", version: "14.0.0-next.9", ngImport: i0, type: CdkMenuModule, declarations: [CdkMenuBar,
1907
- CdkMenu,
1908
- CdkMenuItem,
1909
- CdkMenuItemRadio,
1910
- CdkMenuItemCheckbox,
1911
- CdkMenuItemTrigger,
1912
- CdkMenuGroup,
1913
- CdkContextMenuTrigger,
1914
- CdkTargetMenuAim], imports: [OverlayModule], exports: [CdkMenuBar,
1915
- CdkMenu,
1916
- CdkMenuItem,
1917
- CdkMenuItemRadio,
1918
- CdkMenuItemCheckbox,
1919
- CdkMenuItemTrigger,
1920
- CdkMenuGroup,
1921
- CdkContextMenuTrigger,
1922
- CdkTargetMenuAim] });
1923
- CdkMenuModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "14.0.0-next.9", ngImport: i0, type: CdkMenuModule, imports: [[OverlayModule]] });
1924
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.0.0-next.9", ngImport: i0, type: CdkMenuModule, decorators: [{
1925
- type: NgModule,
1926
- args: [{
1927
- imports: [OverlayModule],
1928
- exports: EXPORTED_DECLARATIONS,
1929
- declarations: EXPORTED_DECLARATIONS,
1930
- }]
1931
- }] });
1932
-
1933
- /**
1934
- * @license
1935
- * Copyright Google LLC All Rights Reserved.
1936
- *
1937
- * Use of this source code is governed by an MIT-style license that can be
1938
- * found in the LICENSE file at https://angular.io/license
1939
- */
1940
-
1941
- /**
1942
- * @license
1943
- * Copyright Google LLC All Rights Reserved.
1944
- *
1945
- * Use of this source code is governed by an MIT-style license that can be
1946
- * found in the LICENSE file at https://angular.io/license
1947
- */
1948
-
1949
- /**
1950
- * Generated bundle index. Do not edit.
1951
- */
1952
-
1953
- export { CDK_MENU, CdkContextMenuTrigger, CdkMenu, CdkMenuBar, CdkMenuGroup, CdkMenuItem, CdkMenuItemCheckbox, CdkMenuItemRadio, CdkMenuItemTrigger, CdkMenuModule, CdkTargetMenuAim, ContextMenuTracker, MENU_AIM, MENU_STACK, MENU_TRIGGER, MenuStack, MenuTrigger, TargetMenuAim, isClickInsideMenuOverlay };
1954
- //# sourceMappingURL=menu.mjs.map