Skip to content

refactor(overlay): remove deprecated APIs for v11 #20511

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 23, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 1 addition & 29 deletions src/cdk/overlay/dispatchers/overlay-keyboard-dispatcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,7 @@
*/

import {DOCUMENT} from '@angular/common';
import {
Inject,
Injectable,
InjectionToken,
Optional,
SkipSelf,
} from '@angular/core';
import {Inject, Injectable} from '@angular/core';
import {OverlayReference} from '../overlay-reference';
import {BaseOverlayDispatcher} from './base-overlay-dispatcher';

Expand Down Expand Up @@ -67,25 +61,3 @@ export class OverlayKeyboardDispatcher extends BaseOverlayDispatcher {
}
}
}


/** @docs-private @deprecated @breaking-change 8.0.0 */
export function OVERLAY_KEYBOARD_DISPATCHER_PROVIDER_FACTORY(
dispatcher: OverlayKeyboardDispatcher, _document: any) {
return dispatcher || new OverlayKeyboardDispatcher(_document);
}

/** @docs-private @deprecated @breaking-change 8.0.0 */
export const OVERLAY_KEYBOARD_DISPATCHER_PROVIDER = {
// If there is already an OverlayKeyboardDispatcher available, use that.
// Otherwise, provide a new one.
provide: OverlayKeyboardDispatcher,
deps: [
[new Optional(), new SkipSelf(), OverlayKeyboardDispatcher],

// Coerce to `InjectionToken` so that the `deps` match the "shape"
// of the type expected by Angular
DOCUMENT as InjectionToken<any>
],
useFactory: OVERLAY_KEYBOARD_DISPATCHER_PROVIDER_FACTORY
};
8 changes: 1 addition & 7 deletions src/cdk/overlay/fullscreen-overlay-container.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,7 @@ export class FullscreenOverlayContainer extends OverlayContainer implements OnDe
private _fullScreenEventName: string | undefined;
private _fullScreenListener: () => void;

constructor(
@Inject(DOCUMENT) _document: any,
/**
* @deprecated `platform` parameter to become required.
* @breaking-change 10.0.0
*/
platform?: Platform) {
constructor(@Inject(DOCUMENT) _document: any, platform: Platform) {
super(_document, platform);
}

Expand Down
41 changes: 4 additions & 37 deletions src/cdk/overlay/overlay-container.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,7 @@
*/

import {DOCUMENT} from '@angular/common';
import {
Inject,
Injectable,
InjectionToken,
OnDestroy,
Optional,
SkipSelf,
} from '@angular/core';
import {Inject, Injectable, OnDestroy} from '@angular/core';
import {Platform} from '@angular/cdk/platform';

/**
Expand All @@ -30,13 +23,7 @@ export class OverlayContainer implements OnDestroy {
protected _containerElement: HTMLElement;
protected _document: Document;

constructor(
@Inject(DOCUMENT) document: any,
/**
* @deprecated `platform` parameter to become required.
* @breaking-change 10.0.0
*/
protected _platform?: Platform) {
constructor(@Inject(DOCUMENT) document: any, protected _platform: Platform) {
this._document = document;
}

Expand Down Expand Up @@ -67,11 +54,9 @@ export class OverlayContainer implements OnDestroy {
* with the 'cdk-overlay-container' class on the document body.
*/
protected _createContainer(): void {
// @breaking-change 10.0.0 Remove null check for `_platform`.
const isBrowser = this._platform ? this._platform.isBrowser : typeof window !== 'undefined';
const containerClass = 'cdk-overlay-container';

if (isBrowser || isTestEnvironment) {
if (this._platform.isBrowser || isTestEnvironment) {
const oppositePlatformContainers =
this._document.querySelectorAll(`.${containerClass}[platform="server"], ` +
`.${containerClass}[platform="test"]`);
Expand All @@ -97,29 +82,11 @@ export class OverlayContainer implements OnDestroy {
// TODO(crisbeto): remove the test environment check once we have an overlay testing module.
if (isTestEnvironment) {
container.setAttribute('platform', 'test');
} else if (!isBrowser) {
} else if (!this._platform.isBrowser) {
container.setAttribute('platform', 'server');
}

this._document.body.appendChild(container);
this._containerElement = container;
}
}


/** @docs-private @deprecated @breaking-change 8.0.0 */
export function OVERLAY_CONTAINER_PROVIDER_FACTORY(parentContainer: OverlayContainer,
_document: any) {
return parentContainer || new OverlayContainer(_document);
}

/** @docs-private @deprecated @breaking-change 8.0.0 */
export const OVERLAY_CONTAINER_PROVIDER = {
// If there is already an OverlayContainer available, use that. Otherwise, provide a new one.
provide: OverlayContainer,
deps: [
[new Optional(), new SkipSelf(), OverlayContainer],
DOCUMENT as InjectionToken<any> // We need to use the InjectionToken somewhere to keep TS happy
],
useFactory: OVERLAY_CONTAINER_PROVIDER_FACTORY
};
7 changes: 0 additions & 7 deletions src/cdk/overlay/overlay-directives.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ import {
} from './position/flexible-connected-position-strategy';
import {
RepositionScrollStrategy,
RepositionScrollStrategyConfig,
ScrollStrategy,
} from './scroll/index';

Expand Down Expand Up @@ -74,12 +73,6 @@ const defaultPositionList: ConnectedPosition[] = [
export const CDK_CONNECTED_OVERLAY_SCROLL_STRATEGY =
new InjectionToken<() => ScrollStrategy>('cdk-connected-overlay-scroll-strategy');

/** @docs-private @deprecated @breaking-change 8.0.0 */
export function CDK_CONNECTED_OVERLAY_SCROLL_STRATEGY_FACTORY(overlay: Overlay):
() => ScrollStrategy {
return (config?: RepositionScrollStrategyConfig) => overlay.scrollStrategies.reposition(config);
}

/**
* Directive applied to an element to make it usable as an origin for an Overlay using a
* ConnectedPositionStrategy.
Expand Down
19 changes: 1 addition & 18 deletions src/cdk/overlay/overlay-module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,13 @@
import {BidiModule} from '@angular/cdk/bidi';
import {PortalModule} from '@angular/cdk/portal';
import {ScrollingModule} from '@angular/cdk/scrolling';
import {NgModule, Provider} from '@angular/core';
import {OVERLAY_KEYBOARD_DISPATCHER_PROVIDER} from './dispatchers/overlay-keyboard-dispatcher';
import {NgModule} from '@angular/core';
import {Overlay} from './overlay';
import {OVERLAY_CONTAINER_PROVIDER} from './overlay-container';
import {
CDK_CONNECTED_OVERLAY_SCROLL_STRATEGY_PROVIDER,
CdkConnectedOverlay,
CdkOverlayOrigin,
} from './overlay-directives';
import {OverlayPositionBuilder} from './position/overlay-position-builder';


@NgModule({
Expand All @@ -31,17 +28,3 @@ import {OverlayPositionBuilder} from './position/overlay-position-builder';
],
})
export class OverlayModule {}


/**
* @deprecated Use `OverlayModule` instead.
* @breaking-change 8.0.0
* @docs-private
*/
export const OVERLAY_PROVIDERS: Provider[] = [
Overlay,
OverlayPositionBuilder,
OVERLAY_KEYBOARD_DISPATCHER_PROVIDER,
OVERLAY_CONTAINER_PROVIDER,
CDK_CONNECTED_OVERLAY_SCROLL_STRATEGY_PROVIDER,
];
31 changes: 6 additions & 25 deletions src/cdk/overlay/overlay-ref.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,8 @@ export class OverlayRef implements PortalOutlet, OverlayReference {
private _ngZone: NgZone,
private _keyboardDispatcher: OverlayKeyboardDispatcher,
private _document: Document,
// @breaking-change 8.0.0 `_location` parameter to be made required.
private _location?: Location,
// @breaking-change 9.0.0 `_mouseClickDispatcher` parameter to be made required.
private _outsideClickDispatcher?: OverlayOutsideClickDispatcher) {
private _location: Location,
private _outsideClickDispatcher: OverlayOutsideClickDispatcher) {

if (_config.scrollStrategy) {
this._scrollStrategy = _config.scrollStrategy;
Expand Down Expand Up @@ -152,17 +150,11 @@ export class OverlayRef implements PortalOutlet, OverlayReference {
// Track this overlay by the keyboard dispatcher
this._keyboardDispatcher.add(this);

// @breaking-change 8.0.0 remove the null check for `_location`
// once the constructor parameter is made required.
if (this._config.disposeOnNavigation && this._location) {
if (this._config.disposeOnNavigation) {
this._locationChanges = this._location.subscribe(() => this.dispose());
}

// @breaking-change 9.0.0 remove the null check for `_mouseClickDispatcher`
if (this._outsideClickDispatcher) {
this._outsideClickDispatcher.add(this);
}

this._outsideClickDispatcher.add(this);
return attachResult;
}

Expand Down Expand Up @@ -201,15 +193,8 @@ export class OverlayRef implements PortalOutlet, OverlayReference {
// Keeping the host element in the DOM can cause scroll jank, because it still gets
// rendered, even though it's transparent and unclickable which is why we remove it.
this._detachContentWhenStable();

// Stop listening for location changes.
this._locationChanges.unsubscribe();

// @breaking-change 9.0.0 remove the null check for `_outsideClickDispatcher`
if (this._outsideClickDispatcher) {
this._outsideClickDispatcher.remove(this);
}

this._outsideClickDispatcher.remove(this);
return detachmentResult;
}

Expand All @@ -230,11 +215,7 @@ export class OverlayRef implements PortalOutlet, OverlayReference {
this._backdropClick.complete();
this._keydownEvents.complete();
this._outsidePointerEvents.complete();

// @breaking-change 9.0.0 remove the null check for `_outsideClickDispatcher`
if (this._outsideClickDispatcher) {
this._outsideClickDispatcher.remove(this);
}
this._outsideClickDispatcher.remove(this);

if (this._host && this._host.parentNode) {
this._host.parentNode.removeChild(this._host);
Expand Down
6 changes: 2 additions & 4 deletions src/cdk/overlay/overlay.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,8 @@ export class Overlay {
private _ngZone: NgZone,
@Inject(DOCUMENT) private _document: any,
private _directionality: Directionality,
// @breaking-change 8.0.0 `_location` parameter to be made required.
private _location?: Location,
// @breaking-change 9.0.0 `_outsideClickDispatcher` parameter to be made required.
private _outsideClickDispatcher?: OverlayOutsideClickDispatcher) { }
private _location: Location,
private _outsideClickDispatcher: OverlayOutsideClickDispatcher) { }

/**
* Creates an overlay.
Expand Down
4 changes: 4 additions & 0 deletions src/cdk/schematics/ng-update/data/constructor-checks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ export const constructorChecks: VersionChanges<ConstructorChecksUpgradeData> = {
{
pr: 'https://github.com/angular/components/pull/20572',
changes: ['CdkTreeNodePadding']
},
{
pr: 'https://github.com/angular/components/pull/20511',
changes: ['OverlayContainer', 'FullscreenOverlayContainer', 'OverlayRef', 'Overlay']
}
],
[TargetVersion.V10]: [
Expand Down
14 changes: 5 additions & 9 deletions tools/public_api_guard/cdk/overlay.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,7 @@ export declare type FlexibleConnectedPositionStrategyOrigin = ElementRef | Eleme
};

export declare class FullscreenOverlayContainer extends OverlayContainer implements OnDestroy {
constructor(_document: any,
platform?: Platform);
constructor(_document: any, platform: Platform);
protected _createContainer(): void;
getFullscreenElement(): Element;
ngOnDestroy(): void;
Expand Down Expand Up @@ -191,15 +190,13 @@ export interface OriginConnectionPosition {
export declare class Overlay {
scrollStrategies: ScrollStrategyOptions;
constructor(
scrollStrategies: ScrollStrategyOptions, _overlayContainer: OverlayContainer, _componentFactoryResolver: ComponentFactoryResolver, _positionBuilder: OverlayPositionBuilder, _keyboardDispatcher: OverlayKeyboardDispatcher, _injector: Injector, _ngZone: NgZone, _document: any, _directionality: Directionality, _location?: Location | undefined, _outsideClickDispatcher?: OverlayOutsideClickDispatcher | undefined);
scrollStrategies: ScrollStrategyOptions, _overlayContainer: OverlayContainer, _componentFactoryResolver: ComponentFactoryResolver, _positionBuilder: OverlayPositionBuilder, _keyboardDispatcher: OverlayKeyboardDispatcher, _injector: Injector, _ngZone: NgZone, _document: any, _directionality: Directionality, _location: Location, _outsideClickDispatcher: OverlayOutsideClickDispatcher);
create(config?: OverlayConfig): OverlayRef;
position(): OverlayPositionBuilder;
static ɵfac: i0.ɵɵFactoryDef<Overlay, never>;
static ɵprov: i0.ɵɵInjectableDef<Overlay>;
}

export declare const OVERLAY_PROVIDERS: Provider[];

export declare class OverlayConfig {
backdropClass?: string | string[];
direction?: Direction | Directionality;
Expand All @@ -225,9 +222,8 @@ export interface OverlayConnectionPosition {
export declare class OverlayContainer implements OnDestroy {
protected _containerElement: HTMLElement;
protected _document: Document;
protected _platform?: Platform | undefined;
constructor(document: any,
_platform?: Platform | undefined);
protected _platform: Platform;
constructor(document: any, _platform: Platform);
protected _createContainer(): void;
getContainerElement(): HTMLElement;
ngOnDestroy(): void;
Expand Down Expand Up @@ -271,7 +267,7 @@ export declare class OverlayRef implements PortalOutlet, OverlayReference {
get backdropElement(): HTMLElement | null;
get hostElement(): HTMLElement;
get overlayElement(): HTMLElement;
constructor(_portalOutlet: PortalOutlet, _host: HTMLElement, _pane: HTMLElement, _config: ImmutableObject<OverlayConfig>, _ngZone: NgZone, _keyboardDispatcher: OverlayKeyboardDispatcher, _document: Document, _location?: Location | undefined, _outsideClickDispatcher?: OverlayOutsideClickDispatcher | undefined);
constructor(_portalOutlet: PortalOutlet, _host: HTMLElement, _pane: HTMLElement, _config: ImmutableObject<OverlayConfig>, _ngZone: NgZone, _keyboardDispatcher: OverlayKeyboardDispatcher, _document: Document, _location: Location, _outsideClickDispatcher: OverlayOutsideClickDispatcher);
addPanelClass(classes: string | string[]): void;
attach<T>(portal: ComponentPortal<T>): ComponentRef<T>;
attach<T>(portal: TemplatePortal<T>): EmbeddedViewRef<T>;
Expand Down