import { Observable , Subject } from 'rxjs' ; import { AnimationEvent } from '@angular/animations' ; import { CdkPortalOutlet , ComponentPortal , TemplatePortal } from '@angular/cdk/portal' ; import { ChangeDetectorRef , ComponentRef , EmbeddedViewRef , EventEmitter } from '@angular/core' ; import { ThyAbstractOverlayConfig , ThyAbstractOverlayOptions } from './abstract-overlay.config' ; export function throwPopoverContentAlreadyAttachedError ( name ) { throw Error ( `Attempting to attach ${ name } content after content is already attached` ) ; } export abstract class ThyAbstractOverlayContainer < TData = unknown > { id ? : string ; animationState : string ; animationStateChanged = new EventEmitter < AnimationEvent > ( ) ; containerDestroy = new Subject < void > ( ) ; abstract config : ThyAbstractOverlayConfig < TData > ; /**portal outlet */ abstract portalOutlet : CdkPortalOutlet ; /**
     * Opening overlay animation done
     */ abstract animationOpeningDone : Observable < AnimationEvent > ; /**
     * Closing overlay animation done
     */ abstract animationClosingDone : Observable < AnimationEvent > ; /** Before attach content(TemplatePortal or ComponentPortal) portal to portalOutlet*/ abstract beforeAttachPortal ( ) ; /** Before detach content*/ beforeDetachPortal ( ) { } constructor ( private options , protected changeDetectorRef ) { } param portal attachTemplatePortal < C > ( portal ) { if ( this . portalOutlet . hasAttached ( ) ) { throwPopoverContentAlreadyAttachedError ( this . options . name ) ; } this . beforeAttachPortal ( ) ; return this . portalOutlet . attachTemplatePortal ( portal ) ; } param portal attachComponentPortal < T > ( portal ) { if ( this . portalOutlet . hasAttached ( ) ) { throwPopoverContentAlreadyAttachedError ( this . options . name ) ; } this . beforeAttachPortal ( ) ; return this . portalOutlet . attachComponentPortal ( portal ) ; } startExitAnimation ( ) { if ( this . options . animationEnabled ) { this . animationState = 'exit' ; } else { } this . beforeDetachPortal ( ) ; this . changeDetectorRef . markForCheck ( ) ; } destroy ( ) { this . containerDestroy . next ( ) ; } }