license import { Direction } from '@angular/cdk/bidi' ; import { CdkScrollable , ViewportRuler } from '@angular/cdk/scrolling' ; import { ElementRef } from '@angular/core' ; import { Observable } from 'rxjs' ; import { ConnectedOverlayPositionChange , ConnectionPositionPair , OriginConnectionPosition , OverlayConnectionPosition , } from './connected-position' ; import { FlexibleConnectedPositionStrategy } from './flexible-connected-position-strategy' ; import { PositionStrategy } from './position-strategy' ; import { Platform } from '@angular/cdk/platform' ; import { OverlayReference } from '../overlay-reference' ; deprecated breaking-change export class ConnectedPositionStrategy implements PositionStrategy { docs-private _positionStrategy : FlexibleConnectedPositionStrategy ; /** The overlay to which this strategy is attached. */ private _overlayRef : OverlayReference ; private _direction : Direction | null ; /** Whether the we're dealing with an RTL context */ get _isRtl ( ) { return this . _overlayRef . getDirection ( ) === 'rtl' ; } /** Ordered list of preferred positions, from most to least desirable. */ _preferredPositions : ConnectionPositionPair [ ] = [ ] ; /** Emits an event when the connection point changes. */ get onPositionChange ( ) : Observable < ConnectedOverlayPositionChange > { return this . _positionStrategy . positionChanges ; } constructor ( originPos , overlayPos , connectedTo , viewportRuler , document , platform ? ) { this . _positionStrategy = new FlexibleConnectedPositionStrategy ( connectedTo , viewportRuler , document , platform ) . withFlexibleDimensions ( false ) . withPush ( false ) . withViewportMargin ( 0 ) ; this . withFallbackPosition ( originPos , overlayPos ) ; } /** Ordered list of preferred positions, from most to least desirable. */ get positions ( ) : ConnectionPositionPair [ ] { return this . _preferredPositions ; } /** Attach this position strategy to an overlay. */ attach ( overlayRef ) { this . _overlayRef = overlayRef ; this . _positionStrategy . attach ( overlayRef ) ; if ( this . _direction ) { overlayRef . setDirection ( this . _direction ) ; this . _direction = null ; } } /** Disposes all resources used by the position strategy. */ dispose ( ) { this . _positionStrategy . dispose ( ) ; } docs-private detach ( ) { this . _positionStrategy . detach ( ) ; } docs-private apply ( ) { this . _positionStrategy . apply ( ) ; } /**
     * Re-positions the overlay element with the trigger in its last calculated position,
     * even if a position higher in the "preferred positions" list would now fit. This
     * allows one to re-align the panel without changing the orientation of the panel.
     */ recalculateLastPosition ( ) { this . _positionStrategy . reapplyLastPosition ( ) ; } /**
     * Sets the list of Scrollable containers that host the origin element so that
     * on reposition we can evaluate if it or the overlay has been clipped or outside view. Every
     * Scrollable must be an ancestor element of the strategy's origin element.
     */ withScrollableContainers ( scrollables ) { this . _positionStrategy . withScrollableContainers ( scrollables ) ; } param originPos param overlayPos withFallbackPosition ( originPos , overlayPos , offsetX ? , offsetY ? ) { const position = new ConnectionPositionPair ( originPos , overlayPos , offsetX , offsetY ) ; this . _preferredPositions . push ( position ) ; this . _positionStrategy . withPositions ( this . _preferredPositions ) ; return this ; } param dir withDirection ( dir ) { if ( this . _overlayRef ) { this . _overlayRef . setDirection ( dir ) ; } else { this . _direction = dir ; } return this ; } param offset withOffsetX ( offset ) { this . _positionStrategy . withDefaultOffsetX ( offset ) ; return this ; } param offset withOffsetY ( offset ) { this . _positionStrategy . withDefaultOffsetY ( offset ) ; return this ; } param isLocked withLockedPosition ( isLocked ) { this . _positionStrategy . withLockedPosition ( isLocked ) ; return this ; } param positions withPositions ( positions ) { this . _preferredPositions = positions . slice ( ) ; this . _positionStrategy . withPositions ( this . _preferredPositions ) ; return this ; } param origin setOrigin ( origin ) { this . _positionStrategy . setOrigin ( origin ) ; return this ; } }