Skip to content

Commit 3d4a9d1

Browse files
committed
fix(cdk/overlay): remove circular dependency workarounds (#27190)
Removes the `OverlayReference` interface which was introduced as a workaround to avoid circular dependencies. Fixes #25650. (cherry picked from commit 4656c24)
1 parent 6a6d126 commit 3d4a9d1

13 files changed

+36
-79
lines changed

src/cdk/overlay/dispatchers/base-overlay-dispatcher.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
import {DOCUMENT} from '@angular/common';
1010
import {Inject, Injectable, OnDestroy} from '@angular/core';
11-
import {OverlayReference} from '../overlay-reference';
11+
import type {OverlayRef} from '../overlay-ref';
1212

1313
/**
1414
* Service for dispatching events that land on the body to appropriate overlay ref,
@@ -18,7 +18,7 @@ import {OverlayReference} from '../overlay-reference';
1818
@Injectable({providedIn: 'root'})
1919
export abstract class BaseOverlayDispatcher implements OnDestroy {
2020
/** Currently attached overlays in the order they were attached. */
21-
_attachedOverlays: OverlayReference[] = [];
21+
_attachedOverlays: OverlayRef[] = [];
2222

2323
protected _document: Document;
2424
protected _isAttached: boolean;
@@ -32,14 +32,14 @@ export abstract class BaseOverlayDispatcher implements OnDestroy {
3232
}
3333

3434
/** Add a new overlay to the list of attached overlay refs. */
35-
add(overlayRef: OverlayReference): void {
35+
add(overlayRef: OverlayRef): void {
3636
// Ensure that we don't get the same overlay multiple times.
3737
this.remove(overlayRef);
3838
this._attachedOverlays.push(overlayRef);
3939
}
4040

4141
/** Remove an overlay from the list of attached overlay refs. */
42-
remove(overlayRef: OverlayReference): void {
42+
remove(overlayRef: OverlayRef): void {
4343
const index = this._attachedOverlays.indexOf(overlayRef);
4444

4545
if (index > -1) {

src/cdk/overlay/dispatchers/overlay-keyboard-dispatcher.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88

99
import {DOCUMENT} from '@angular/common';
1010
import {Inject, Injectable, NgZone, Optional} from '@angular/core';
11-
import {OverlayReference} from '../overlay-reference';
1211
import {BaseOverlayDispatcher} from './base-overlay-dispatcher';
12+
import type {OverlayRef} from '../overlay-ref';
1313

1414
/**
1515
* Service for dispatching keyboard events that land on the body to appropriate overlay ref,
@@ -27,7 +27,7 @@ export class OverlayKeyboardDispatcher extends BaseOverlayDispatcher {
2727
}
2828

2929
/** Add a new overlay to the list of attached overlay refs. */
30-
override add(overlayRef: OverlayReference): void {
30+
override add(overlayRef: OverlayRef): void {
3131
super.add(overlayRef);
3232

3333
// Lazily start dispatcher once first overlay is added

src/cdk/overlay/dispatchers/overlay-outside-click-dispatcher.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@
88

99
import {DOCUMENT} from '@angular/common';
1010
import {Inject, Injectable, NgZone, Optional} from '@angular/core';
11-
import {OverlayReference} from '../overlay-reference';
1211
import {Platform, _getEventTarget} from '@angular/cdk/platform';
1312
import {BaseOverlayDispatcher} from './base-overlay-dispatcher';
13+
import type {OverlayRef} from '../overlay-ref';
1414

1515
/**
1616
* Service for dispatching mouse click events that land on the body to appropriate overlay ref,
@@ -33,7 +33,7 @@ export class OverlayOutsideClickDispatcher extends BaseOverlayDispatcher {
3333
}
3434

3535
/** Add a new overlay to the list of attached overlay refs. */
36-
override add(overlayRef: OverlayReference): void {
36+
override add(overlayRef: OverlayRef): void {
3737
super.add(overlayRef);
3838

3939
// Safari on iOS does not generate click events for non-interactive

src/cdk/overlay/overlay-ref.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ import {OverlayKeyboardDispatcher} from './dispatchers/overlay-keyboard-dispatch
1616
import {OverlayOutsideClickDispatcher} from './dispatchers/overlay-outside-click-dispatcher';
1717
import {OverlayConfig} from './overlay-config';
1818
import {coerceCssPixelValue, coerceArray} from '@angular/cdk/coercion';
19-
import {OverlayReference} from './overlay-reference';
2019
import {PositionStrategy} from './position/position-strategy';
2120
import {ScrollStrategy} from './scroll';
2221

@@ -29,7 +28,7 @@ export type ImmutableObject<T> = {
2928
* Reference to an overlay that has been created with the Overlay service.
3029
* Used to manipulate or dispose of said overlay.
3130
*/
32-
export class OverlayRef implements PortalOutlet, OverlayReference {
31+
export class OverlayRef implements PortalOutlet {
3332
private _backdropElement: HTMLElement | null = null;
3433
private _backdropTimeout: number | undefined;
3534
private readonly _backdropClick = new Subject<MouseEvent>();

src/cdk/overlay/overlay-reference.ts

Lines changed: 0 additions & 40 deletions
This file was deleted.

src/cdk/overlay/overlay.spec.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ import {
3030
PositionStrategy,
3131
ScrollStrategy,
3232
} from './index';
33-
import {OverlayReference} from './overlay-reference';
3433
import {NoopAnimationsModule} from '@angular/platform-browser/animations';
3534

3635
describe('Overlay', () => {
@@ -1148,9 +1147,9 @@ class FakePositionStrategy implements PositionStrategy {
11481147

11491148
class FakeScrollStrategy implements ScrollStrategy {
11501149
isEnabled = false;
1151-
overlayRef: OverlayReference;
1150+
overlayRef: OverlayRef;
11521151

1153-
attach(overlayRef: OverlayReference) {
1152+
attach(overlayRef: OverlayRef) {
11541153
this.overlayRef = overlayRef;
11551154
}
11561155

src/cdk/overlay/position/flexible-connected-position-strategy.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@ import {
1717
validateVerticalPosition,
1818
} from './connected-position';
1919
import {Observable, Subscription, Subject} from 'rxjs';
20-
import {OverlayReference} from '../overlay-reference';
2120
import {isElementScrolledOutsideView, isElementClippedByScrolling} from './scroll-clip';
2221
import {coerceCssPixelValue, coerceArray} from '@angular/cdk/coercion';
2322
import {Platform} from '@angular/cdk/platform';
2423
import {OverlayContainer} from '../overlay-container';
24+
import {OverlayRef} from '../overlay-ref';
2525

2626
// TODO: refactor clipping detection into a separate thing (part of scrolling module)
2727
// TODO: doesn't handle both flexible width and height when it has to scroll along both axis.
@@ -53,7 +53,7 @@ type Dimensions = Omit<ClientRect, 'x' | 'y' | 'toJSON'>;
5353
*/
5454
export class FlexibleConnectedPositionStrategy implements PositionStrategy {
5555
/** The overlay to which this strategy is attached. */
56-
private _overlayRef: OverlayReference;
56+
private _overlayRef: OverlayRef;
5757

5858
/** Whether we're performing the very first positioning of the overlay. */
5959
private _isInitialRender: boolean;
@@ -155,7 +155,7 @@ export class FlexibleConnectedPositionStrategy implements PositionStrategy {
155155
}
156156

157157
/** Attaches this position strategy to an overlay. */
158-
attach(overlayRef: OverlayReference): void {
158+
attach(overlayRef: OverlayRef): void {
159159
if (
160160
this._overlayRef &&
161161
overlayRef !== this._overlayRef &&

src/cdk/overlay/position/global-position-strategy.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
* found in the LICENSE file at https://angular.io/license
77
*/
88

9+
import {OverlayRef} from '../overlay-ref';
910
import {PositionStrategy} from './position-strategy';
10-
import {OverlayReference} from '../overlay-reference';
1111

1212
/** Class to be added to the overlay pane wrapper. */
1313
const wrapperClass = 'cdk-global-overlay-wrapper';
@@ -20,7 +20,7 @@ const wrapperClass = 'cdk-global-overlay-wrapper';
2020
*/
2121
export class GlobalPositionStrategy implements PositionStrategy {
2222
/** The overlay to which this strategy is attached. */
23-
private _overlayRef: OverlayReference;
23+
private _overlayRef: OverlayRef;
2424
private _cssPosition = 'static';
2525
private _topOffset = '';
2626
private _bottomOffset = '';
@@ -31,7 +31,7 @@ export class GlobalPositionStrategy implements PositionStrategy {
3131
private _height = '';
3232
private _isDisposed = false;
3333

34-
attach(overlayRef: OverlayReference): void {
34+
attach(overlayRef: OverlayRef): void {
3535
const config = overlayRef.getConfig();
3636

3737
this._overlayRef = overlayRef;

src/cdk/overlay/position/position-strategy.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@
66
* found in the LICENSE file at https://angular.io/license
77
*/
88

9-
import {OverlayReference} from '../overlay-reference';
9+
import type {OverlayRef} from '../overlay-ref';
1010

1111
/** Strategy for setting the position on an overlay. */
1212
export interface PositionStrategy {
1313
/** Attaches this position strategy to an overlay. */
14-
attach(overlayRef: OverlayReference): void;
14+
attach(overlayRef: OverlayRef): void;
1515

1616
/** Updates the position of the overlay element. */
1717
apply(): void;

src/cdk/overlay/scroll/close-scroll-strategy.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@
77
*/
88
import {NgZone} from '@angular/core';
99
import {ScrollStrategy, getMatScrollStrategyAlreadyAttachedError} from './scroll-strategy';
10-
import {OverlayReference} from '../overlay-reference';
1110
import {Subscription} from 'rxjs';
1211
import {ScrollDispatcher, ViewportRuler} from '@angular/cdk/scrolling';
1312
import {filter} from 'rxjs/operators';
13+
import type {OverlayRef} from '../overlay-ref';
1414

1515
/**
1616
* Config options for the CloseScrollStrategy.
@@ -25,7 +25,7 @@ export interface CloseScrollStrategyConfig {
2525
*/
2626
export class CloseScrollStrategy implements ScrollStrategy {
2727
private _scrollSubscription: Subscription | null = null;
28-
private _overlayRef: OverlayReference;
28+
private _overlayRef: OverlayRef;
2929
private _initialScrollPosition: number;
3030

3131
constructor(
@@ -36,7 +36,7 @@ export class CloseScrollStrategy implements ScrollStrategy {
3636
) {}
3737

3838
/** Attaches this scroll strategy to an overlay. */
39-
attach(overlayRef: OverlayReference) {
39+
attach(overlayRef: OverlayRef) {
4040
if (this._overlayRef && (typeof ngDevMode === 'undefined' || ngDevMode)) {
4141
throw getMatScrollStrategyAlreadyAttachedError();
4242
}

0 commit comments

Comments
 (0)