Skip to content

Commit ed0de40

Browse files
crisbetoandrewseguin
authored andcommitted
refactor(overlay): avoid circular type references (#9907)
Currently there is a circular type reference between `OverlayRef`, `PositionStrategy`/`ScrollStrategy` and `OverlayConfig` which can cause issues with some build tools. These changes introduce the `OverlayRefBase` type to avoid the circular reference. Fixes #9491.
1 parent 8063c26 commit ed0de40

8 files changed

+48
-21
lines changed

src/cdk/overlay/overlay-reference.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/**
2+
* @license
3+
* Copyright Google LLC All Rights Reserved.
4+
*
5+
* Use of this source code is governed by an MIT-style license that can be
6+
* found in the LICENSE file at https://angular.io/license
7+
*/
8+
9+
import {Portal} from '@angular/cdk/portal';
10+
import {Direction, Directionality} from '@angular/cdk/bidi';
11+
12+
/**
13+
* Basic interface for an overlay. Used to avoid circular type references between
14+
* `OverlayRef`, `PositionStrategy` and `ScrollStrategy`, and `OverlayConfig`.
15+
* @docs-private
16+
*/
17+
export interface OverlayReference {
18+
attach: (portal: Portal<any>) => any;
19+
detach: () => any;
20+
dispose: () => void;
21+
overlayElement: HTMLElement;
22+
hostElement: HTMLElement;
23+
getConfig: () => any;
24+
hasAttached: () => boolean;
25+
updateSize: (config: any) => void;
26+
updatePosition: () => void;
27+
getDirection: () => Direction;
28+
setDirection: (dir: Direction | Directionality) => void;
29+
}

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

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import {Direction} from '@angular/cdk/bidi';
1010
import {CdkScrollable, ViewportRuler} from '@angular/cdk/scrolling';
1111
import {ElementRef} from '@angular/core';
1212
import {Observable} from 'rxjs';
13-
import {OverlayRef} from '../overlay-ref';
1413
import {
1514
ConnectedOverlayPositionChange,
1615
ConnectionPositionPair,
@@ -20,7 +19,7 @@ import {
2019
import {FlexibleConnectedPositionStrategy} from './flexible-connected-position-strategy';
2120
import {PositionStrategy} from './position-strategy';
2221
import {Platform} from '@angular/cdk/platform';
23-
22+
import {OverlayReference} from '../overlay-reference';
2423

2524
/**
2625
* A strategy for positioning overlays. Using this strategy, an overlay is given an
@@ -39,7 +38,7 @@ export class ConnectedPositionStrategy implements PositionStrategy {
3938
_positionStrategy: FlexibleConnectedPositionStrategy;
4039

4140
/** The overlay to which this strategy is attached. */
42-
private _overlayRef: OverlayRef;
41+
private _overlayRef: OverlayReference;
4342

4443
private _direction: Direction | null;
4544

@@ -84,7 +83,7 @@ export class ConnectedPositionStrategy implements PositionStrategy {
8483
}
8584

8685
/** Attach this position strategy to an overlay. */
87-
attach(overlayRef: OverlayRef): void {
86+
attach(overlayRef: OverlayReference): void {
8887
this._overlayRef = overlayRef;
8988
this._positionStrategy.attach(overlayRef);
9089

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import {
1717
validateVerticalPosition,
1818
} from './connected-position';
1919
import {Observable, Subscription, Subject} from 'rxjs';
20-
import {OverlayRef} from '../overlay-ref';
20+
import {OverlayReference} from '../overlay-reference';
2121
import {isElementScrolledOutsideView, isElementClippedByScrolling} from './scroll-clip';
2222
import {coerceCssPixelValue} from '@angular/cdk/coercion';
2323
import {Platform} from '@angular/cdk/platform';
@@ -34,7 +34,7 @@ import {Platform} from '@angular/cdk/platform';
3434
*/
3535
export class FlexibleConnectedPositionStrategy implements PositionStrategy {
3636
/** The overlay to which this strategy is attached. */
37-
private _overlayRef: OverlayRef;
37+
private _overlayRef: OverlayReference;
3838

3939
/** Whether we're performing the very first positioning of the overlay. */
4040
private _isInitialRender = true;
@@ -137,7 +137,7 @@ export class FlexibleConnectedPositionStrategy implements PositionStrategy {
137137
}
138138

139139
/** Attaches this position strategy to an overlay. */
140-
attach(overlayRef: OverlayRef): void {
140+
attach(overlayRef: OverlayReference): void {
141141
if (this._overlayRef && overlayRef !== this._overlayRef) {
142142
throw Error('This position strategy is already attached to an overlay');
143143
}

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*/
88

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

1212

1313
/**
@@ -18,7 +18,7 @@ import {OverlayRef} from '../overlay-ref';
1818
*/
1919
export class GlobalPositionStrategy implements PositionStrategy {
2020
/** The overlay to which this strategy is attached. */
21-
private _overlayRef: OverlayRef;
21+
private _overlayRef: OverlayReference;
2222
private _cssPosition: string = 'static';
2323
private _topOffset: string = '';
2424
private _bottomOffset: string = '';
@@ -29,7 +29,7 @@ export class GlobalPositionStrategy implements PositionStrategy {
2929
private _width: string = '';
3030
private _height: string = '';
3131

32-
attach(overlayRef: OverlayRef): void {
32+
attach(overlayRef: OverlayReference): void {
3333
const config = overlayRef.getConfig();
3434

3535
this._overlayRef = overlayRef;

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

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

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

1211
/** Strategy for setting the position on an overlay. */
1312
export interface PositionStrategy {
1413
/** Attaches this position strategy to an overlay. */
15-
attach(overlayRef: OverlayRef): void;
14+
attach(overlayRef: OverlayReference): void;
1615

1716
/** Updates the position of the overlay element. */
1817
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,7 +7,7 @@
77
*/
88
import {NgZone} from '@angular/core';
99
import {ScrollStrategy, getMatScrollStrategyAlreadyAttachedError} from './scroll-strategy';
10-
import {OverlayRef} from '../overlay-ref';
10+
import {OverlayReference} from '../overlay-reference';
1111
import {Subscription} from 'rxjs';
1212
import {ScrollDispatcher, ViewportRuler} from '@angular/cdk/scrolling';
1313

@@ -24,7 +24,7 @@ export interface CloseScrollStrategyConfig {
2424
*/
2525
export class CloseScrollStrategy implements ScrollStrategy {
2626
private _scrollSubscription: Subscription|null = null;
27-
private _overlayRef: OverlayRef;
27+
private _overlayRef: OverlayReference;
2828
private _initialScrollPosition: number;
2929

3030
constructor(
@@ -34,7 +34,7 @@ export class CloseScrollStrategy implements ScrollStrategy {
3434
private _config?: CloseScrollStrategyConfig) {}
3535

3636
/** Attaches this scroll strategy to an overlay. */
37-
attach(overlayRef: OverlayRef) {
37+
attach(overlayRef: OverlayReference) {
3838
if (this._overlayRef) {
3939
throw getMatScrollStrategyAlreadyAttachedError();
4040
}

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

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

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

3434
constructor(
3535
private _scrollDispatcher: ScrollDispatcher,
@@ -38,7 +38,7 @@ export class RepositionScrollStrategy implements ScrollStrategy {
3838
private _config?: RepositionScrollStrategyConfig) { }
3939

4040
/** Attaches this scroll strategy to an overlay. */
41-
attach(overlayRef: OverlayRef) {
41+
attach(overlayRef: OverlayReference) {
4242
if (this._overlayRef) {
4343
throw getMatScrollStrategyAlreadyAttachedError();
4444
}

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 {OverlayRef} from '../overlay-ref';
9+
import {OverlayReference} from '../overlay-reference';
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: OverlayRef) => void;
22+
attach: (overlayRef: OverlayReference) => void;
2323
}
2424

2525
/**

0 commit comments

Comments
 (0)