5
5
* Use of this source code is governed by an MIT-style license that can be
6
6
* found in the LICENSE file at https://angular.io/license
7
7
*/
8
- import { FocusTrap , FocusTrapFactory } from '@angular/cdk/a11y' ;
9
- import { Overlay , OverlayRef , PositionStrategy } from '@angular/cdk/overlay' ;
8
+ import { FocusTrap } from '@angular/cdk/a11y' ;
9
+ import { OverlayRef , PositionStrategy } from '@angular/cdk/overlay' ;
10
10
import { TemplatePortal } from '@angular/cdk/portal' ;
11
- import { ScrollDispatcher , ViewportRuler } from '@angular/cdk/scrolling' ;
12
11
import {
13
12
AfterViewInit ,
14
13
Directive ,
@@ -25,14 +24,14 @@ import {debounceTime, filter, map, mapTo, startWith, takeUntil} from 'rxjs/opera
25
24
26
25
import { CELL_SELECTOR , EDIT_PANE_CLASS , EDIT_PANE_SELECTOR , ROW_SELECTOR } from './constants' ;
27
26
import { EditEventDispatcher } from './edit-event-dispatcher' ;
27
+ import { EditServices } from './edit-services' ;
28
28
import { FocusDispatcher } from './focus-dispatcher' ;
29
29
import {
30
30
FocusEscapeNotifier ,
31
31
FocusEscapeNotifierDirection ,
32
32
FocusEscapeNotifierFactory
33
33
} from './focus-escape-notifier' ;
34
34
import { closest } from './polyfill' ;
35
- import { PopoverEditPositionStrategyFactory } from './popover-edit-position-strategy-factory' ;
36
35
37
36
/**
38
37
* Describes the number of columns before and after the originating cell that the
@@ -57,7 +56,7 @@ const DEFAULT_MOUSE_MOVE_DELAY_MS = 30;
57
56
*/
58
57
@Directive ( {
59
58
selector : 'table[editable], cdk-table[editable], mat-table[editable]' ,
60
- providers : [ EditEventDispatcher ] ,
59
+ providers : [ EditEventDispatcher , EditServices ] ,
61
60
} )
62
61
export class CdkEditable implements AfterViewInit , OnDestroy {
63
62
protected readonly destroyed = new ReplaySubject < void > ( ) ;
@@ -161,15 +160,8 @@ export class CdkPopoverEdit<C> implements AfterViewInit, OnDestroy {
161
160
protected readonly destroyed = new ReplaySubject < void > ( ) ;
162
161
163
162
constructor (
164
- protected readonly editEventDispatcher : EditEventDispatcher ,
165
- protected readonly elementRef : ElementRef ,
166
- protected readonly focusTrapFactory : FocusTrapFactory ,
167
- protected readonly ngZone : NgZone ,
168
- protected readonly overlay : Overlay ,
169
- protected readonly positionFactory : PopoverEditPositionStrategyFactory ,
170
- protected readonly scrollDispatcher : ScrollDispatcher ,
171
- protected readonly viewContainerRef : ViewContainerRef ,
172
- protected readonly viewportRuler : ViewportRuler ) { }
163
+ protected readonly services : EditServices , protected readonly elementRef : ElementRef ,
164
+ protected readonly viewContainerRef : ViewContainerRef ) { }
173
165
174
166
ngAfterViewInit ( ) : void {
175
167
this . _startListeningToEditEvents ( ) ;
@@ -185,18 +177,18 @@ export class CdkPopoverEdit<C> implements AfterViewInit, OnDestroy {
185
177
}
186
178
187
179
protected initFocusTrap ( ) : void {
188
- this . focusTrap = this . focusTrapFactory . create ( this . overlayRef ! . overlayElement ) ;
180
+ this . focusTrap = this . services . focusTrapFactory . create ( this . overlayRef ! . overlayElement ) ;
189
181
}
190
182
191
183
protected closeEditOverlay ( ) : void {
192
- this . editEventDispatcher . doneEditingCell ( this . elementRef . nativeElement ! ) ;
184
+ this . services . editEventDispatcher . doneEditingCell ( this . elementRef . nativeElement ! ) ;
193
185
}
194
186
195
187
private _startListeningToEditEvents ( ) : void {
196
- this . editEventDispatcher . editingCell ( this . elementRef . nativeElement ! )
188
+ this . services . editEventDispatcher . editingCell ( this . elementRef . nativeElement ! )
197
189
. pipe ( takeUntil ( this . destroyed ) )
198
190
. subscribe ( ( open ) => {
199
- this . ngZone . run ( ( ) => {
191
+ this . services . ngZone . run ( ( ) => {
200
192
if ( open && this . template ) {
201
193
if ( ! this . overlayRef ) {
202
194
this . _createEditOverlay ( ) ;
@@ -209,15 +201,15 @@ export class CdkPopoverEdit<C> implements AfterViewInit, OnDestroy {
209
201
this . overlayRef . detach ( ) ;
210
202
}
211
203
} ) ;
212
- } ) ;
204
+ } ) ;
213
205
}
214
206
215
207
private _createEditOverlay ( ) : void {
216
- this . overlayRef = this . overlay . create ( {
208
+ this . overlayRef = this . services . overlay . create ( {
217
209
disposeOnNavigation : true ,
218
210
panelClass : EDIT_PANE_CLASS ,
219
211
positionStrategy : this . _getPositionStrategy ( ) ,
220
- scrollStrategy : this . overlay . scrollStrategies . reposition ( ) ,
212
+ scrollStrategy : this . services . overlay . scrollStrategies . reposition ( ) ,
221
213
} ) ;
222
214
223
215
this . initFocusTrap ( ) ;
@@ -235,7 +227,7 @@ export class CdkPopoverEdit<C> implements AfterViewInit, OnDestroy {
235
227
236
228
// Update the size of the popup initially and on subsequent changes to
237
229
// scroll position and viewport size.
238
- merge ( this . scrollDispatcher . scrolled ( ) , this . viewportRuler . change ( ) )
230
+ merge ( this . services . scrollDispatcher . scrolled ( ) , this . services . viewportRuler . change ( ) )
239
231
. pipe (
240
232
startWith ( null ) ,
241
233
takeUntil ( this . overlayRef ! . detachments ( ) ) ,
@@ -262,11 +254,12 @@ export class CdkPopoverEdit<C> implements AfterViewInit, OnDestroy {
262
254
}
263
255
264
256
private _getPositionStrategy ( ) : PositionStrategy {
265
- return this . positionFactory . positionStrategyForCells ( this . _getOverlayCells ( ) ) ;
257
+ return this . services . positionFactory . positionStrategyForCells ( this . _getOverlayCells ( ) ) ;
266
258
}
267
259
268
260
private _updateOverlaySize ( ) : void {
269
- this . overlayRef ! . updateSize ( this . positionFactory . sizeConfigForCells ( this . _getOverlayCells ( ) ) ) ;
261
+ this . overlayRef ! . updateSize (
262
+ this . services . positionFactory . sizeConfigForCells ( this . _getOverlayCells ( ) ) ) ;
270
263
}
271
264
272
265
private _maybeReturnFocusToCell ( ) : void {
@@ -294,35 +287,17 @@ export class CdkPopoverEditTabOut<C> extends CdkPopoverEdit<C> {
294
287
protected focusTrap ?: FocusEscapeNotifier ;
295
288
296
289
constructor (
297
- editEventDispatcher : EditEventDispatcher ,
298
- elementRef : ElementRef ,
299
- focusTrapFactory : FocusTrapFactory ,
300
- ngZone : NgZone ,
301
- overlay : Overlay ,
302
- positionFactory : PopoverEditPositionStrategyFactory ,
303
- scrollDispatcher : ScrollDispatcher ,
304
- viewContainerRef : ViewContainerRef ,
305
- viewportRuler : ViewportRuler ,
306
- protected readonly focusEscapeNotifierFactory : FocusEscapeNotifierFactory ,
307
- protected readonly focusDispatcher : FocusDispatcher ) {
308
- super (
309
- editEventDispatcher ,
310
- elementRef ,
311
- focusTrapFactory ,
312
- ngZone ,
313
- overlay ,
314
- positionFactory ,
315
- scrollDispatcher ,
316
- viewContainerRef ,
317
- viewportRuler ) ;
290
+ elementRef : ElementRef , viewContainerRef : ViewContainerRef , services : EditServices ,
291
+ protected readonly focusEscapeNotifierFactory : FocusEscapeNotifierFactory ) {
292
+ super ( services , elementRef , viewContainerRef ) ;
318
293
}
319
294
320
295
protected initFocusTrap ( ) : void {
321
296
this . focusTrap = this . focusEscapeNotifierFactory . create ( this . overlayRef ! . overlayElement ) ;
322
297
323
298
this . focusTrap . escapes ( ) . pipe ( takeUntil ( this . destroyed ) ) . subscribe ( direction => {
324
- this . editEventDispatcher . editRef ! . tabOut ( ) ;
325
- this . focusDispatcher . moveFocusHorizontally (
299
+ this . services . editEventDispatcher . editRef ! . tabOut ( ) ;
300
+ this . services . focusDispatcher . moveFocusHorizontally (
326
301
closest ( this . elementRef . nativeElement ! , CELL_SELECTOR ) as HTMLElement ,
327
302
direction === FocusEscapeNotifierDirection . START ? - 1 : 1 ) ;
328
303
@@ -355,12 +330,9 @@ export class CdkRowHoverContent implements AfterViewInit, OnDestroy {
355
330
protected viewRef : EmbeddedViewRef < any > | null = null ;
356
331
357
332
constructor (
358
- protected readonly elementRef : ElementRef ,
359
- protected readonly editEventDispatcher : EditEventDispatcher ,
360
- protected readonly ngZone : NgZone ,
333
+ protected readonly services : EditServices , protected readonly elementRef : ElementRef ,
361
334
protected readonly templateRef : TemplateRef < any > ,
362
- protected readonly viewContainerRef : ViewContainerRef
363
- ) { }
335
+ protected readonly viewContainerRef : ViewContainerRef ) { }
364
336
365
337
ngAfterViewInit ( ) : void {
366
338
this . _listenForHoverEvents ( ) ;
@@ -376,10 +348,10 @@ export class CdkRowHoverContent implements AfterViewInit, OnDestroy {
376
348
}
377
349
378
350
private _listenForHoverEvents ( ) : void {
379
- this . editEventDispatcher . hoveringOnRow ( this . elementRef . nativeElement ! )
351
+ this . services . editEventDispatcher . hoveringOnRow ( this . elementRef . nativeElement ! )
380
352
. pipe ( takeUntil ( this . destroyed ) )
381
353
. subscribe ( isHovering => {
382
- this . ngZone . run ( ( ) => {
354
+ this . services . ngZone . run ( ( ) => {
383
355
if ( isHovering ) {
384
356
if ( ! this . viewRef ) {
385
357
// Not doing any positioning in CDK version. Material version
0 commit comments