import { ElementRef , HostListener , OnDestroy } from '@angular/core' ; import { Observable , Observer , Subject , BehaviorSubject } from 'rxjs' ; import { SimpleModalOptions } from './simple-modal-options' ; export interface OnDestroyLike { ngOnDestroy ( ) : void ; [ key ] : any ; } template T template T1 export abstract class SimpleModalComponent < T , T1 > { /**
     * Observer to return result from modal
     */ private observer : Observer < T1 > ; /**
     * Drag handle
     */ handle : ElementRef | undefined ; type { T1 } result : T1 ; /**
     * Dialog wrapper (modal placeholder)
     */ wrapper : ElementRef ; /**
     * ref of options for this component
     */ options : SimpleModalOptions ; /**
     * ready$ is when all animations and focusing have comleted
     */ _ready$ = new BehaviorSubject < boolean > ( false ) ; /**
     * Callback to the holders close function
     */ private closerCallback : ( component ) => Promise < any > = ( ) => Promise . resolve ( ) ; /**
     * Constructor
     */ constructor ( ) { } param { T } data mapDataObject ( data ) { data = data || < T > { } ; const keys = Object . keys ( data ) ; for ( let i = 0 , length = keys . length ; i < length ; i ++ ) { const key = keys [ i ] ; if ( data [ key ] && this [ key ] && typeof data [ key ] === 'object' && typeof this [ key ] === 'object' ) { Object . assign ( this [ key ] , data [ key ] ) ; } else { this [ key ] = data [ key ] ; } } } return { Observable < T1 > } setupObserver ( ) { return Observable . create ( observer => { this . observer = observer ; return ( ) => { this . close ( ) ; } ; } ) ; } param callback onClosing ( callback ) { this . closerCallback = callback ; } /**
     * Closes modal
     */ close ( ) { return this . closerCallback ( this ) . then ( v => { if ( this . observer ) { this . observer . next ( this . result ) ; this . observer . complete ( ) ; } return v ; } ) ; } param evt @ HostListener ( 'document:keydown.escape' , [ '$event' ] ) onKeydownHandler ( evt ) { if ( this . options && this . options . closeOnEscape ) { this . close ( ) ; } } get ready$ ( ) { return this . _ready$ . asObservable ( ) ; } markAsReady ( ) { this . _ready$ . next ( true ) ; } }