Skip to content

Commit 4656c24

Browse files
authored
fix(cdk/overlay): remove circular dependency workarounds (#27190)
Removes the `OverlayReference` interface which was introduced as a workaround to avoid circular dependencies. Fixes #25650.
1 parent 87dd8fd commit 4656c24

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
}

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@
99
import {NgZone} from '@angular/core';
1010
import {Subscription} from 'rxjs';
1111
import {ScrollStrategy, getMatScrollStrategyAlreadyAttachedError} from './scroll-strategy';
12-
import {OverlayReference} from '../overlay-reference';
1312
import {ScrollDispatcher, ViewportRuler} from '@angular/cdk/scrolling';
1413
import {isElementScrolledOutsideView} from '../position/scroll-clip';
14+
import type {OverlayRef} from '../overlay-ref';
1515

1616
/**
1717
* Config options for the RepositionScrollStrategy.
@@ -29,7 +29,7 @@ export interface RepositionScrollStrategyConfig {
2929
*/
3030
export class RepositionScrollStrategy implements ScrollStrategy {
3131
private _scrollSubscription: Subscription | null = null;
32-
private _overlayRef: OverlayReference;
32+
private _overlayRef: OverlayRef;
3333

3434
constructor(
3535
private _scrollDispatcher: ScrollDispatcher,
@@ -39,7 +39,7 @@ export class RepositionScrollStrategy implements ScrollStrategy {
3939
) {}
4040

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

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
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
/**
1212
* Describes a strategy that will be used by an overlay to handle scroll events while it is open.
@@ -19,7 +19,7 @@ export interface ScrollStrategy {
1919
disable: () => void;
2020

2121
/** Attaches this `ScrollStrategy` to an overlay. */
22-
attach: (overlayRef: OverlayReference) => void;
22+
attach: (overlayRef: OverlayRef) => void;
2323

2424
/** Detaches the scroll strategy from the current overlay. */
2525
detach?: () => void;

tools/public_api_guard/cdk/overlay.md

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ import { Observable } from 'rxjs';
2727
import { OnChanges } from '@angular/core';
2828
import { OnDestroy } from '@angular/core';
2929
import { Platform } from '@angular/cdk/platform';
30-
import { Portal } from '@angular/cdk/portal';
3130
import { PortalOutlet } from '@angular/cdk/portal';
3231
import { ScrollDispatcher } from '@angular/cdk/scrolling';
3332
import { SimpleChanges } from '@angular/core';
@@ -110,7 +109,7 @@ export { CdkScrollable }
110109
// @public
111110
export class CloseScrollStrategy implements ScrollStrategy {
112111
constructor(_scrollDispatcher: ScrollDispatcher, _ngZone: NgZone, _viewportRuler: ViewportRuler, _config?: CloseScrollStrategyConfig | undefined);
113-
attach(overlayRef: OverlayReference): void;
112+
attach(overlayRef: OverlayRef): void;
114113
// (undocumented)
115114
detach(): void;
116115
disable(): void;
@@ -167,7 +166,7 @@ export class ConnectionPositionPair {
167166
export class FlexibleConnectedPositionStrategy implements PositionStrategy {
168167
constructor(connectedTo: FlexibleConnectedPositionStrategyOrigin, _viewportRuler: ViewportRuler, _document: Document, _platform: Platform, _overlayContainer: OverlayContainer);
169168
apply(): void;
170-
attach(overlayRef: OverlayReference): void;
169+
attach(overlayRef: OverlayRef): void;
171170
// (undocumented)
172171
detach(): void;
173172
dispose(): void;
@@ -213,7 +212,7 @@ export class FullscreenOverlayContainer extends OverlayContainer implements OnDe
213212
export class GlobalPositionStrategy implements PositionStrategy {
214213
apply(): void;
215214
// (undocumented)
216-
attach(overlayRef: OverlayReference): void;
215+
attach(overlayRef: OverlayRef): void;
217216
bottom(value?: string): this;
218217
centerHorizontally(offset?: string): this;
219218
centerVertically(offset?: string): this;
@@ -309,7 +308,7 @@ export class OverlayContainer implements OnDestroy {
309308
export class OverlayKeyboardDispatcher extends BaseOverlayDispatcher {
310309
constructor(document: any,
311310
_ngZone?: NgZone | undefined);
312-
add(overlayRef: OverlayReference): void;
311+
add(overlayRef: OverlayRef): void;
313312
protected detach(): void;
314313
// (undocumented)
315314
static ɵfac: i0.ɵɵFactoryDeclaration<OverlayKeyboardDispatcher, [null, { optional: true; }]>;
@@ -331,7 +330,7 @@ export class OverlayModule {
331330
export class OverlayOutsideClickDispatcher extends BaseOverlayDispatcher {
332331
constructor(document: any, _platform: Platform,
333332
_ngZone?: NgZone | undefined);
334-
add(overlayRef: OverlayReference): void;
333+
add(overlayRef: OverlayRef): void;
335334
protected detach(): void;
336335
// (undocumented)
337336
static ɵfac: i0.ɵɵFactoryDeclaration<OverlayOutsideClickDispatcher, [null, null, { optional: true; }]>;
@@ -351,7 +350,7 @@ export class OverlayPositionBuilder {
351350
}
352351

353352
// @public
354-
export class OverlayRef implements PortalOutlet, OverlayReference {
353+
export class OverlayRef implements PortalOutlet {
355354
constructor(_portalOutlet: PortalOutlet, _host: HTMLElement, _pane: HTMLElement, _config: ImmutableObject<OverlayConfig>, _ngZone: NgZone, _keyboardDispatcher: OverlayKeyboardDispatcher, _document: Document, _location: Location_2, _outsideClickDispatcher: OverlayOutsideClickDispatcher, _animationsDisabled?: boolean);
356355
addPanelClass(classes: string | string[]): void;
357356
// (undocumented)
@@ -403,15 +402,15 @@ export interface OverlaySizeConfig {
403402
// @public
404403
export interface PositionStrategy {
405404
apply(): void;
406-
attach(overlayRef: OverlayReference): void;
405+
attach(overlayRef: OverlayRef): void;
407406
detach?(): void;
408407
dispose(): void;
409408
}
410409

411410
// @public
412411
export class RepositionScrollStrategy implements ScrollStrategy {
413412
constructor(_scrollDispatcher: ScrollDispatcher, _viewportRuler: ViewportRuler, _ngZone: NgZone, _config?: RepositionScrollStrategyConfig | undefined);
414-
attach(overlayRef: OverlayReference): void;
413+
attach(overlayRef: OverlayRef): void;
415414
// (undocumented)
416415
detach(): void;
417416
disable(): void;
@@ -440,7 +439,7 @@ export class ScrollingVisibility {
440439

441440
// @public
442441
export interface ScrollStrategy {
443-
attach: (overlayRef: OverlayReference) => void;
442+
attach: (overlayRef: OverlayRef) => void;
444443
detach?: () => void;
445444
disable: () => void;
446445
enable: () => void;

0 commit comments

Comments
 (0)