overlay-ref.d.ts 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. /**
  2. * @license
  3. * Copyright Google LLC All Rights Reserved.
  4. *
  5. * Use of this source code is governed by an MIT-style license that can be
  6. * found in the LICENSE file at https://angular.io/license
  7. */
  8. import { Direction, Directionality } from '@angular/cdk/bidi';
  9. import { ComponentPortal, PortalOutlet, TemplatePortal } from '@angular/cdk/portal';
  10. import { ComponentRef, EmbeddedViewRef, NgZone } from '@angular/core';
  11. import { Location } from '@angular/common';
  12. import { Observable, Subject } from 'rxjs';
  13. import { OverlayKeyboardDispatcher } from './keyboard/overlay-keyboard-dispatcher';
  14. import { OverlayConfig } from './overlay-config';
  15. import { OverlayReference } from './overlay-reference';
  16. import { PositionStrategy } from './position/position-strategy';
  17. import { ScrollStrategy } from './scroll';
  18. /** An object where all of its properties cannot be written. */
  19. export declare type ImmutableObject<T> = {
  20. readonly [P in keyof T]: T[P];
  21. };
  22. /**
  23. * Reference to an overlay that has been created with the Overlay service.
  24. * Used to manipulate or dispose of said overlay.
  25. */
  26. export declare class OverlayRef implements PortalOutlet, OverlayReference {
  27. private _portalOutlet;
  28. private _host;
  29. private _pane;
  30. private _config;
  31. private _ngZone;
  32. private _keyboardDispatcher;
  33. private _document;
  34. private _location?;
  35. private _backdropElement;
  36. private _backdropClick;
  37. private _attachments;
  38. private _detachments;
  39. private _positionStrategy;
  40. private _scrollStrategy;
  41. private _locationChanges;
  42. private _backdropClickHandler;
  43. /**
  44. * Reference to the parent of the `_host` at the time it was detached. Used to restore
  45. * the `_host` to its original position in the DOM when it gets re-attached.
  46. */
  47. private _previousHostParent;
  48. private _keydownEventsObservable;
  49. /** Stream of keydown events dispatched to this overlay. */
  50. _keydownEvents: Subject<KeyboardEvent>;
  51. /** Amount of subscriptions to the keydown events. */
  52. _keydownEventSubscriptions: number;
  53. constructor(_portalOutlet: PortalOutlet, _host: HTMLElement, _pane: HTMLElement, _config: ImmutableObject<OverlayConfig>, _ngZone: NgZone, _keyboardDispatcher: OverlayKeyboardDispatcher, _document: Document, _location?: Location | undefined);
  54. /** The overlay's HTML element */
  55. readonly overlayElement: HTMLElement;
  56. /** The overlay's backdrop HTML element. */
  57. readonly backdropElement: HTMLElement | null;
  58. /**
  59. * Wrapper around the panel element. Can be used for advanced
  60. * positioning where a wrapper with specific styling is
  61. * required around the overlay pane.
  62. */
  63. readonly hostElement: HTMLElement;
  64. attach<T>(portal: ComponentPortal<T>): ComponentRef<T>;
  65. attach<T>(portal: TemplatePortal<T>): EmbeddedViewRef<T>;
  66. attach(portal: any): any;
  67. /**
  68. * Detaches an overlay from a portal.
  69. * @returns The portal detachment result.
  70. */
  71. detach(): any;
  72. /** Cleans up the overlay from the DOM. */
  73. dispose(): void;
  74. /** Whether the overlay has attached content. */
  75. hasAttached(): boolean;
  76. /** Gets an observable that emits when the backdrop has been clicked. */
  77. backdropClick(): Observable<MouseEvent>;
  78. /** Gets an observable that emits when the overlay has been attached. */
  79. attachments(): Observable<void>;
  80. /** Gets an observable that emits when the overlay has been detached. */
  81. detachments(): Observable<void>;
  82. /** Gets an observable of keydown events targeted to this overlay. */
  83. keydownEvents(): Observable<KeyboardEvent>;
  84. /** Gets the current overlay configuration, which is immutable. */
  85. getConfig(): OverlayConfig;
  86. /** Updates the position of the overlay based on the position strategy. */
  87. updatePosition(): void;
  88. /** Switches to a new position strategy and updates the overlay position. */
  89. updatePositionStrategy(strategy: PositionStrategy): void;
  90. /** Update the size properties of the overlay. */
  91. updateSize(sizeConfig: OverlaySizeConfig): void;
  92. /** Sets the LTR/RTL direction for the overlay. */
  93. setDirection(dir: Direction | Directionality): void;
  94. /** Add a CSS class or an array of classes to the overlay pane. */
  95. addPanelClass(classes: string | string[]): void;
  96. /** Remove a CSS class or an array of classes from the overlay pane. */
  97. removePanelClass(classes: string | string[]): void;
  98. /**
  99. * Returns the layout direction of the overlay panel.
  100. */
  101. getDirection(): Direction;
  102. /** Switches to a new scroll strategy. */
  103. updateScrollStrategy(strategy: ScrollStrategy): void;
  104. /** Updates the text direction of the overlay panel. */
  105. private _updateElementDirection;
  106. /** Updates the size of the overlay element based on the overlay config. */
  107. private _updateElementSize;
  108. /** Toggles the pointer events for the overlay pane element. */
  109. private _togglePointerEvents;
  110. /** Attaches a backdrop for this overlay. */
  111. private _attachBackdrop;
  112. /**
  113. * Updates the stacking order of the element, moving it to the top if necessary.
  114. * This is required in cases where one overlay was detached, while another one,
  115. * that should be behind it, was destroyed. The next time both of them are opened,
  116. * the stacking will be wrong, because the detached element's pane will still be
  117. * in its original DOM position.
  118. */
  119. private _updateStackingOrder;
  120. /** Detaches the backdrop (if any) associated with the overlay. */
  121. detachBackdrop(): void;
  122. /** Toggles a single CSS class or an array of classes on an element. */
  123. private _toggleClasses;
  124. /** Detaches the overlay content next time the zone stabilizes. */
  125. private _detachContentWhenStable;
  126. /** Disposes of a scroll strategy. */
  127. private _disposeScrollStrategy;
  128. }
  129. /** Size properties for an overlay. */
  130. export interface OverlaySizeConfig {
  131. width?: number | string;
  132. height?: number | string;
  133. minWidth?: number | string;
  134. minHeight?: number | string;
  135. maxWidth?: number | string;
  136. maxHeight?: number | string;
  137. }