8
8
9
9
import {
10
10
Directive ,
11
- EventEmitter ,
12
11
Inject ,
13
12
Injectable ,
14
13
Injector ,
15
14
Input ,
16
15
OnDestroy ,
17
16
Optional ,
18
- Output ,
19
- TemplateRef ,
20
17
ViewContainerRef ,
21
18
} from '@angular/core' ;
22
19
import { Directionality } from '@angular/cdk/bidi' ;
23
20
import {
24
- ConnectedPosition ,
25
21
FlexibleConnectedPositionStrategy ,
26
22
Overlay ,
27
23
OverlayConfig ,
28
- OverlayRef ,
29
24
STANDARD_DROPDOWN_BELOW_POSITIONS ,
30
25
} from '@angular/cdk/overlay' ;
31
26
import { Portal , TemplatePortal } from '@angular/cdk/portal' ;
32
27
import { BooleanInput , coerceBooleanProperty } from '@angular/cdk/coercion' ;
33
- import { merge , partition , Subject } from 'rxjs' ;
28
+ import { merge , partition } from 'rxjs' ;
34
29
import { skip , takeUntil } from 'rxjs/operators' ;
35
30
import { MENU_STACK , MenuStack } from './menu-stack' ;
36
31
import { isClickInsideMenuOverlay } from './menu-item-trigger' ;
@@ -76,25 +71,14 @@ export type ContextMenuCoordinates = {x: number; y: number};
76
71
host : {
77
72
'(contextmenu)' : '_openOnContextMenu($event)' ,
78
73
} ,
74
+ inputs : [ '_menuTemplateRef: cdkContextMenuTriggerFor' , 'menuPosition: cdkContextMenuPosition' ] ,
75
+ outputs : [ 'opened: cdkContextMenuOpened' , 'closed: cdkContextMenuClosed' ] ,
79
76
providers : [
80
77
{ provide : MENU_TRIGGER , useExisting : CdkContextMenuTrigger } ,
81
78
{ provide : MENU_STACK , useClass : MenuStack } ,
82
79
] ,
83
80
} )
84
81
export class CdkContextMenuTrigger extends MenuTrigger implements OnDestroy {
85
- /** Template reference variable to the menu to open on right click. */
86
- @Input ( 'cdkContextMenuTriggerFor' )
87
- private _menuTemplateRef : TemplateRef < unknown > ;
88
-
89
- /** A list of preferred menu positions to be used when constructing the `FlexibleConnectedPositionStrategy` for this trigger's menu. */
90
- @Input ( 'cdkMenuPosition' ) menuPosition : ConnectedPosition [ ] ;
91
-
92
- /** Emits when the attached menu is requested to open. */
93
- @Output ( 'cdkContextMenuOpened' ) readonly opened : EventEmitter < void > = new EventEmitter ( ) ;
94
-
95
- /** Emits when the attached menu is requested to close. */
96
- @Output ( 'cdkContextMenuClosed' ) readonly closed : EventEmitter < void > = new EventEmitter ( ) ;
97
-
98
82
/** Whether the context menu should be disabled. */
99
83
@Input ( 'cdkContextMenuDisabled' )
100
84
get disabled ( ) : boolean {
@@ -105,18 +89,6 @@ export class CdkContextMenuTrigger extends MenuTrigger implements OnDestroy {
105
89
}
106
90
private _disabled = false ;
107
91
108
- /** A reference to the overlay which manages the triggered menu. */
109
- private _overlayRef : OverlayRef | null = null ;
110
-
111
- /** The content of the menu panel opened by this trigger. */
112
- private _menuPortal : TemplatePortal ;
113
-
114
- /** Emits when the element is destroyed. */
115
- private readonly _destroyed = new Subject < void > ( ) ;
116
-
117
- /** Emits when the outside pointer events listener on the overlay should be stopped. */
118
- private readonly _stopOutsideClicksListener = merge ( this . closed , this . _destroyed ) ;
119
-
120
92
constructor (
121
93
injector : Injector ,
122
94
protected readonly _viewContainerRef : ViewContainerRef ,
@@ -199,11 +171,6 @@ export class CdkContextMenuTrigger extends MenuTrigger implements OnDestroy {
199
171
}
200
172
}
201
173
202
- /** Whether the attached menu is open. */
203
- isOpen ( ) {
204
- return ! ! this . _overlayRef ?. hasAttached ( ) ;
205
- }
206
-
207
174
/**
208
175
* Get the configuration object used to create the overlay.
209
176
* @param coordinates the location to place the opened menu
@@ -277,19 +244,4 @@ export class CdkContextMenuTrigger extends MenuTrigger implements OnDestroy {
277
244
} ) ;
278
245
}
279
246
}
280
-
281
- ngOnDestroy ( ) {
282
- this . _destroyOverlay ( ) ;
283
-
284
- this . _destroyed . next ( ) ;
285
- this . _destroyed . complete ( ) ;
286
- }
287
-
288
- /** Destroy and unset the overlay reference it if exists. */
289
- private _destroyOverlay ( ) {
290
- if ( this . _overlayRef ) {
291
- this . _overlayRef . dispose ( ) ;
292
- this . _overlayRef = null ;
293
- }
294
- }
295
247
}
0 commit comments