From 8b5afcc41ebd327b6e0c69e8af37aef55ee04e62 Mon Sep 17 00:00:00 2001 From: Kristiyan Kostadinov Date: Tue, 6 Aug 2019 22:00:00 +0300 Subject: [PATCH] build: add API goldens for portal (#16655) Adds API goldens for the portal package and fixes some compilation errors that showed up when I was trying to generate it. --- src/cdk/portal/dom-portal-outlet.ts | 6 ++ src/cdk/portal/portal-directives.ts | 25 ++++++- src/cdk/portal/portal.ts | 11 +++ src/cdk/portal/public-api.ts | 7 -- tools/public_api_guard/BUILD.bazel | 3 - tools/public_api_guard/cdk/portal.d.ts | 96 ++++++++++++++++++++++++++ 6 files changed, 136 insertions(+), 12 deletions(-) create mode 100644 tools/public_api_guard/cdk/portal.d.ts diff --git a/src/cdk/portal/dom-portal-outlet.ts b/src/cdk/portal/dom-portal-outlet.ts index d7eaadc79ed..39cbb799dae 100644 --- a/src/cdk/portal/dom-portal-outlet.ts +++ b/src/cdk/portal/dom-portal-outlet.ts @@ -108,3 +108,9 @@ export class DomPortalOutlet extends BasePortalOutlet { return (componentRef.hostView as EmbeddedViewRef).rootNodes[0] as HTMLElement; } } + +/** + * @deprecated Use `DomPortalOutlet` instead. + * @breaking-change 9.0.0 + */ +export class DomPortalHost extends DomPortalOutlet {} diff --git a/src/cdk/portal/portal-directives.ts b/src/cdk/portal/portal-directives.ts index fab3606fc84..461ce63fe46 100644 --- a/src/cdk/portal/portal-directives.ts +++ b/src/cdk/portal/portal-directives.ts @@ -36,6 +36,16 @@ export class CdkPortal extends TemplatePortal { } } +/** + * @deprecated Use `CdkPortal` instead. + * @breaking-change 9.0.0 + */ +@Directive({ + selector: '[cdk-portal], [cdkPortal], [portal]', + exportAs: 'cdkPortal', +}) +export class TemplatePortalDirective extends CdkPortal {} + /** * Possible attached references to the CdkPortalOutlet. */ @@ -158,9 +168,20 @@ export class CdkPortalOutlet extends BasePortalOutlet implements OnInit, OnDestr } } +/** + * @deprecated Use `CdkPortalOutlet` instead. + * @breaking-change 9.0.0 + */ +@Directive({ + selector: '[cdkPortalOutlet], [cdkPortalHost], [portalHost]', + exportAs: 'cdkPortalOutlet, cdkPortalHost', + inputs: ['portal: cdkPortalOutlet'] +}) +export class PortalHostDirective extends CdkPortalOutlet {} + @NgModule({ - exports: [CdkPortal, CdkPortalOutlet], - declarations: [CdkPortal, CdkPortalOutlet], + exports: [CdkPortal, CdkPortalOutlet, TemplatePortalDirective, PortalHostDirective], + declarations: [CdkPortal, CdkPortalOutlet, TemplatePortalDirective, PortalHostDirective], }) export class PortalModule {} diff --git a/src/cdk/portal/portal.ts b/src/cdk/portal/portal.ts index 0e71a788b54..1e807a64f35 100644 --- a/src/cdk/portal/portal.ts +++ b/src/cdk/portal/portal.ts @@ -169,6 +169,11 @@ export interface PortalOutlet { hasAttached(): boolean; } +/** + * @deprecated Use `PortalOutlet` instead. + * @breaking-change 9.0.0 + */ +export type PortalHost = PortalOutlet; /** * Partial implementation of PortalOutlet that handles attaching @@ -254,3 +259,9 @@ export abstract class BasePortalOutlet implements PortalOutlet { } } } + +/** + * @deprecated Use `BasePortalOutlet` instead. + * @breaking-change 9.0.0 + */ +export abstract class BasePortalHost extends BasePortalOutlet {} diff --git a/src/cdk/portal/public-api.ts b/src/cdk/portal/public-api.ts index fd47ee6ebf5..cd250e45975 100644 --- a/src/cdk/portal/public-api.ts +++ b/src/cdk/portal/public-api.ts @@ -10,10 +10,3 @@ export * from './portal'; export * from './dom-portal-outlet'; export * from './portal-directives'; export * from './portal-injector'; - -export {DomPortalOutlet as DomPortalHost} from './dom-portal-outlet'; -export { - CdkPortalOutlet as PortalHostDirective, - CdkPortal as TemplatePortalDirective, -} from './portal-directives'; -export {PortalOutlet as PortalHost, BasePortalOutlet as BasePortalHost} from './portal'; diff --git a/tools/public_api_guard/BUILD.bazel b/tools/public_api_guard/BUILD.bazel index 7bddbb150ba..0e943215811 100644 --- a/tools/public_api_guard/BUILD.bazel +++ b/tools/public_api_guard/BUILD.bazel @@ -2,8 +2,5 @@ package(default_visibility = ["//visibility:public"]) load(":generate-guard-tests.bzl", "generate_test_targets") -# TODO(devversion): All entry-points except the CDK portal are currently validated. This is -# because aliases are not supported by ts-api-guardian. Re-add once we found a solution for that. - # Generate the API guard test targets for each golden file in the current package. generate_test_targets(glob(["**/*.d.ts"])) diff --git a/tools/public_api_guard/cdk/portal.d.ts b/tools/public_api_guard/cdk/portal.d.ts new file mode 100644 index 00000000000..df9e669b2dd --- /dev/null +++ b/tools/public_api_guard/cdk/portal.d.ts @@ -0,0 +1,96 @@ +export declare abstract class BasePortalHost extends BasePortalOutlet { +} + +export declare abstract class BasePortalOutlet implements PortalOutlet { + protected _attachedPortal: Portal | null; + attach(portal: ComponentPortal): ComponentRef; + attach(portal: TemplatePortal): EmbeddedViewRef; + attach(portal: any): any; + abstract attachComponentPortal(portal: ComponentPortal): ComponentRef; + abstract attachTemplatePortal(portal: TemplatePortal): EmbeddedViewRef; + detach(): void; + dispose(): void; + hasAttached(): boolean; + setDisposeFn(fn: () => void): void; +} + +export declare class CdkPortal extends TemplatePortal { + constructor(templateRef: TemplateRef, viewContainerRef: ViewContainerRef); +} + +export declare class CdkPortalOutlet extends BasePortalOutlet implements OnInit, OnDestroy { + attached: EventEmitter; + readonly attachedRef: CdkPortalOutletAttachedRef; + portal: Portal | null; + constructor(_componentFactoryResolver: ComponentFactoryResolver, _viewContainerRef: ViewContainerRef); + attachComponentPortal(portal: ComponentPortal): ComponentRef; + attachTemplatePortal(portal: TemplatePortal): EmbeddedViewRef; + ngOnDestroy(): void; + ngOnInit(): void; +} + +export declare type CdkPortalOutletAttachedRef = ComponentRef | EmbeddedViewRef | null; + +export declare class ComponentPortal extends Portal> { + component: ComponentType; + componentFactoryResolver?: ComponentFactoryResolver | null; + injector?: Injector | null; + viewContainerRef?: ViewContainerRef | null; + constructor(component: ComponentType, viewContainerRef?: ViewContainerRef | null, injector?: Injector | null, componentFactoryResolver?: ComponentFactoryResolver | null); +} + +export interface ComponentType { + new (...args: any[]): T; +} + +export declare class DomPortalHost extends DomPortalOutlet { +} + +export declare class DomPortalOutlet extends BasePortalOutlet { + outletElement: Element; + constructor( + outletElement: Element, _componentFactoryResolver: ComponentFactoryResolver, _appRef: ApplicationRef, _defaultInjector: Injector); + attachComponentPortal(portal: ComponentPortal): ComponentRef; + attachTemplatePortal(portal: TemplatePortal): EmbeddedViewRef; + dispose(): void; +} + +export declare abstract class Portal { + readonly isAttached: boolean; + attach(host: PortalOutlet): T; + detach(): void; + setAttachedHost(host: PortalOutlet | null): void; +} + +export declare type PortalHost = PortalOutlet; + +export declare class PortalHostDirective extends CdkPortalOutlet { +} + +export declare class PortalInjector implements Injector { + constructor(_parentInjector: Injector, _customTokens: WeakMap); + get(token: any, notFoundValue?: any): any; +} + +export declare class PortalModule { +} + +export interface PortalOutlet { + attach(portal: Portal): any; + detach(): any; + dispose(): void; + hasAttached(): boolean; +} + +export declare class TemplatePortal extends Portal> { + context: C | undefined; + readonly origin: ElementRef; + templateRef: TemplateRef; + viewContainerRef: ViewContainerRef; + constructor(template: TemplateRef, viewContainerRef: ViewContainerRef, context?: C); + attach(host: PortalOutlet, context?: C | undefined): EmbeddedViewRef; + detach(): void; +} + +export declare class TemplatePortalDirective extends CdkPortal { +}