license import { Location } from '@angular/common' ; import { ESCAPE } from '@angular/cdk/keycodes' ; import { OverlayRef } from '@angular/cdk/overlay' ; import { merge , Observable , Subject } from 'rxjs' ; import { filter , take } from 'rxjs/operators' ; import { MatBottomSheetContainer } from './bottom-sheet-container' ; /**
 * Reference to a bottom sheet dispatched from the bottom sheet service.
 */ export class MatBottomSheetRef < T = any , R = any > { /** Instance of the component making up the content of the bottom sheet. */ instance : T ; docs-private containerInstance : MatBottomSheetContainer ; /** Subject for notifying the user that the bottom sheet has been dismissed. */ private readonly _afterDismissed = new Subject < R | undefined > ( ) ; /** Subject for notifying the user that the bottom sheet has opened and appeared. */ private readonly _afterOpened = new Subject < void > ( ) ; /** Result to be passed down to the `afterDismissed` stream. */ private _result : R | undefined ; constructor ( containerInstance , private _overlayRef , _location ? ) { this . containerInstance = containerInstance ; containerInstance . _animationStateChanged . pipe ( filter ( event => event . phaseName === 'done' && event . toState === 'visible' ) , take ( 1 ) ) . subscribe ( ( ) => { this . _afterOpened . next ( ) ; this . _afterOpened . complete ( ) ; } ) ; containerInstance . _animationStateChanged . pipe ( filter ( event => event . phaseName === 'done' && event . toState === 'hidden' ) , take ( 1 ) ) . subscribe ( ( ) => { this . _overlayRef . dispose ( ) ; this . _afterDismissed . next ( this . _result ) ; this . _afterDismissed . complete ( ) ; } ) ; if ( ! containerInstance . bottomSheetConfig . disableClose ) { merge ( _overlayRef . backdropClick ( ) , _overlayRef . keydownEvents ( ) . pipe ( filter ( event => event . keyCode === ESCAPE ) ) ) . subscribe ( ( ) => this . dismiss ( ) ) ; } } param result dismiss ( result ? ) { if ( ! this . _afterDismissed . closed ) { this . containerInstance . _animationStateChanged . pipe ( filter ( event => event . phaseName === 'start' ) , take ( 1 ) ) . subscribe ( ( ) => this . _overlayRef . detachBackdrop ( ) ) ; this . _result = result ; this . containerInstance . exit ( ) ; } } /** Gets an observable that is notified when the bottom sheet is finished closing. */ afterDismissed ( ) { return this . _afterDismissed . asObservable ( ) ; } /** Gets an observable that is notified when the bottom sheet has opened and appeared. */ afterOpened ( ) { return this . _afterOpened . asObservable ( ) ; } /**
     * Gets an observable that emits when the overlay's backdrop has been clicked.
     */ backdropClick ( ) { return this . _overlayRef . backdropClick ( ) ; } /**
     * Gets an observable that emits when keydown events are targeted on the overlay.
     */ keydownEvents ( ) { return this . _overlayRef . keydownEvents ( ) ; } }