@angular/cdk-experimental 14.0.0-next.1 → 14.0.0-next.12

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