/** * @license * Copyright Google LLC All Rights Reserved. * * Use of this source code is governed by an MIT-style license that can be * found in the LICENSE file at https://angular.io/license */ import { Directionality } from '@angular/cdk/bidi'; import { Overlay, OverlayConfig, OverlayContainer, } from '@angular/cdk/overlay'; import { ComponentPortal, TemplatePortal } from '@angular/cdk/portal'; import { Location } from '@angular/common'; import { Directive, Inject, Injectable, InjectFlags, InjectionToken, Injector, Optional, SkipSelf, TemplateRef, Type, } from '@angular/core'; import { defer, of as observableOf, Subject } from 'rxjs'; import { startWith } from 'rxjs/operators'; import { MatDialogConfig } from './dialog-config'; import { MatDialogContainer } from './dialog-container'; import { MatDialogRef } from './dialog-ref'; /** Injection token that can be used to access the data that was passed in to a dialog. */ export const MAT_DIALOG_DATA = new InjectionToken('MatDialogData'); /** Injection token that can be used to specify default dialog options. */ export const MAT_DIALOG_DEFAULT_OPTIONS = new InjectionToken('mat-dialog-default-options'); /** Injection token that determines the scroll handling while the dialog is open. */ export const MAT_DIALOG_SCROLL_STRATEGY = new InjectionToken('mat-dialog-scroll-strategy'); /** @docs-private */ export function MAT_DIALOG_SCROLL_STRATEGY_FACTORY(overlay) { return () => overlay.scrollStrategies.block(); } /** @docs-private */ export function MAT_DIALOG_SCROLL_STRATEGY_PROVIDER_FACTORY(overlay) { return () => overlay.scrollStrategies.block(); } /** @docs-private */ export const MAT_DIALOG_SCROLL_STRATEGY_PROVIDER = { provide: MAT_DIALOG_SCROLL_STRATEGY, deps: [Overlay], useFactory: MAT_DIALOG_SCROLL_STRATEGY_PROVIDER_FACTORY, }; /** * Base class for dialog services. The base dialog service allows * for arbitrary dialog refs and dialog container components. */ export class _MatDialogBase { constructor(_overlay, _injector, _defaultOptions, _parentDialog, _overlayContainer, scrollStrategy, _dialogRefConstructor, _dialogContainerType, _dialogDataToken) { this._overlay = _overlay; this._injector = _injector; this._defaultOptions = _defaultOptions; this._parentDialog = _parentDialog; this._overlayContainer = _overlayContainer; this._dialogRefConstructor = _dialogRefConstructor; this._dialogContainerType = _dialogContainerType; this._dialogDataToken = _dialogDataToken; this._openDialogsAtThisLevel = []; this._afterAllClosedAtThisLevel = new Subject(); this._afterOpenedAtThisLevel = new Subject(); this._ariaHiddenElements = new Map(); // TODO (jelbourn): tighten the typing right-hand side of this expression. /** * Stream that emits when all open dialog have finished closing. * Will emit on subscribe if there are no open dialogs to begin with. */ this.afterAllClosed = defer(() => this.openDialogs.length ? this._getAfterAllClosed() : this._getAfterAllClosed().pipe(startWith(undefined))); this._scrollStrategy = scrollStrategy; } /** Keeps track of the currently-open dialogs. */ get openDialogs() { return this._parentDialog ? this._parentDialog.openDialogs : this._openDialogsAtThisLevel; } /** Stream that emits when a dialog has been opened. */ get afterOpened() { return this._parentDialog ? this._parentDialog.afterOpened : this._afterOpenedAtThisLevel; } _getAfterAllClosed() { const parent = this._parentDialog; return parent ? parent._getAfterAllClosed() : this._afterAllClosedAtThisLevel; } open(componentOrTemplateRef, config) { config = _applyConfigDefaults(config, this._defaultOptions || new MatDialogConfig()); if (config.id && this.getDialogById(config.id) && (typeof ngDevMode === 'undefined' || ngDevMode)) { throw Error(`Dialog with id "${config.id}" exists already. The dialog id must be unique.`); } const overlayRef = this._createOverlay(config); const dialogContainer = this._attachDialogContainer(overlayRef, config); const dialogRef = this._attachDialogContent(componentOrTemplateRef, dialogContainer, overlayRef, config); // If this is the first dialog that we're opening, hide all the non-overlay content. if (!this.openDialogs.length) { this._hideNonDialogContentFromAssistiveTechnology(); } this.openDialogs.push(dialogRef); dialogRef.afterClosed().subscribe(() => this._removeOpenDialog(dialogRef)); this.afterOpened.next(dialogRef); // Notify the dialog container that the content has been attached. dialogContainer._initializeWithAttachedContent(); return dialogRef; } /** * Closes all of the currently-open dialogs. */ closeAll() { this._closeDialogs(this.openDialogs); } /** * Finds an open dialog by its id. * @param id ID to use when looking up the dialog. */ getDialogById(id) { return this.openDialogs.find(dialog => dialog.id === id); } ngOnDestroy() { // Only close the dialogs at this level on destroy // since the parent service may still be active. this._closeDialogs(this._openDialogsAtThisLevel); this._afterAllClosedAtThisLevel.complete(); this._afterOpenedAtThisLevel.complete(); } /** * Creates the overlay into which the dialog will be loaded. * @param config The dialog configuration. * @returns A promise resolving to the OverlayRef for the created overlay. */ _createOverlay(config) { const overlayConfig = this._getOverlayConfig(config); return this._overlay.create(overlayConfig); } /** * Creates an overlay config from a dialog config. * @param dialogConfig The dialog configuration. * @returns The overlay configuration. */ _getOverlayConfig(dialogConfig) { const state = new OverlayConfig({ positionStrategy: this._overlay.position().global(), scrollStrategy: dialogConfig.scrollStrategy || this._scrollStrategy(), panelClass: dialogConfig.panelClass, hasBackdrop: dialogConfig.hasBackdrop, direction: dialogConfig.direction, minWidth: dialogConfig.minWidth, minHeight: dialogConfig.minHeight, maxWidth: dialogConfig.maxWidth, maxHeight: dialogConfig.maxHeight, disposeOnNavigation: dialogConfig.closeOnNavigation }); if (dialogConfig.backdropClass) { state.backdropClass = dialogConfig.backdropClass; } return state; } /** * Attaches a dialog container to a dialog's already-created overlay. * @param overlay Reference to the dialog's underlying overlay. * @param config The dialog configuration. * @returns A promise resolving to a ComponentRef for the attached container. */ _attachDialogContainer(overlay, config) { const userInjector = config && config.viewContainerRef && config.viewContainerRef.injector; const injector = Injector.create({ parent: userInjector || this._injector, providers: [{ provide: MatDialogConfig, useValue: config }] }); const containerPortal = new ComponentPortal(this._dialogContainerType, config.viewContainerRef, injector, config.componentFactoryResolver); const containerRef = overlay.attach(containerPortal); return containerRef.instance; } /** * Attaches the user-provided component to the already-created dialog container. * @param componentOrTemplateRef The type of component being loaded into the dialog, * or a TemplateRef to instantiate as the content. * @param dialogContainer Reference to the wrapping dialog container. * @param overlayRef Reference to the overlay in which the dialog resides. * @param config The dialog configuration. * @returns A promise resolving to the MatDialogRef that should be returned to the user. */ _attachDialogContent(componentOrTemplateRef, dialogContainer, overlayRef, config) { // Create a reference to the dialog we're creating in order to give the user a handle // to modify and close it. const dialogRef = new this._dialogRefConstructor(overlayRef, dialogContainer, config.id); if (componentOrTemplateRef instanceof TemplateRef) { dialogContainer.attachTemplatePortal(new TemplatePortal(componentOrTemplateRef, null, { $implicit: config.data, dialogRef })); } else { const injector = this._createInjector(config, dialogRef, dialogContainer); const contentRef = dialogContainer.attachComponentPortal(new ComponentPortal(componentOrTemplateRef, config.viewContainerRef, injector)); dialogRef.componentInstance = contentRef.instance; } dialogRef .updateSize(config.width, config.height) .updatePosition(config.position); return dialogRef; } /** * Creates a custom injector to be used inside the dialog. This allows a component loaded inside * of a dialog to close itself and, optionally, to return a value. * @param config Config object that is used to construct the dialog. * @param dialogRef Reference to the dialog. * @param dialogContainer Dialog container element that wraps all of the contents. * @returns The custom injector that can be used inside the dialog. */ _createInjector(config, dialogRef, dialogContainer) { const userInjector = config && config.viewContainerRef && config.viewContainerRef.injector; // The dialog container should be provided as the dialog container and the dialog's // content are created out of the same `ViewContainerRef` and as such, are siblings // for injector purposes. To allow the hierarchy that is expected, the dialog // container is explicitly provided in the injector. const providers = [ { provide: this._dialogContainerType, useValue: dialogContainer }, { provide: this._dialogDataToken, useValue: config.data }, { provide: this._dialogRefConstructor, useValue: dialogRef } ]; if (config.direction && (!userInjector || !userInjector.get(Directionality, null, InjectFlags.Optional))) { providers.push({ provide: Directionality, useValue: { value: config.direction, change: observableOf() } }); } return Injector.create({ parent: userInjector || this._injector, providers }); } /** * Removes a dialog from the array of open dialogs. * @param dialogRef Dialog to be removed. */ _removeOpenDialog(dialogRef) { const index = this.openDialogs.indexOf(dialogRef); if (index > -1) { this.openDialogs.splice(index, 1); // If all the dialogs were closed, remove/restore the `aria-hidden` // to a the siblings and emit to the `afterAllClosed` stream. if (!this.openDialogs.length) { this._ariaHiddenElements.forEach((previousValue, element) => { if (previousValue) { element.setAttribute('aria-hidden', previousValue); } else { element.removeAttribute('aria-hidden'); } }); this._ariaHiddenElements.clear(); this._getAfterAllClosed().next(); } } } /** * Hides all of the content that isn't an overlay from assistive technology. */ _hideNonDialogContentFromAssistiveTechnology() { const overlayContainer = this._overlayContainer.getContainerElement(); // Ensure that the overlay container is attached to the DOM. if (overlayContainer.parentElement) { const siblings = overlayContainer.parentElement.children; for (let i = siblings.length - 1; i > -1; i--) { let sibling = siblings[i]; if (sibling !== overlayContainer && sibling.nodeName !== 'SCRIPT' && sibling.nodeName !== 'STYLE' && !sibling.hasAttribute('aria-live')) { this._ariaHiddenElements.set(sibling, sibling.getAttribute('aria-hidden')); sibling.setAttribute('aria-hidden', 'true'); } } } } /** Closes all of the dialogs in an array. */ _closeDialogs(dialogs) { let i = dialogs.length; while (i--) { // The `_openDialogs` property isn't updated after close until the rxjs subscription // runs on the next microtask, in addition to modifying the array as we're going // through it. We loop through all of them and call close without assuming that // they'll be removed from the list instantaneously. dialogs[i].close(); } } } _MatDialogBase.decorators = [ { type: Directive } ]; _MatDialogBase.ctorParameters = () => [ { type: Overlay }, { type: Injector }, { type: undefined }, { type: undefined }, { type: OverlayContainer }, { type: undefined }, { type: Type }, { type: Type }, { type: InjectionToken } ]; /** * Service to open Material Design modal dialogs. */ export class MatDialog extends _MatDialogBase { constructor(overlay, injector, /** * @deprecated `_location` parameter to be removed. * @breaking-change 10.0.0 */ location, defaultOptions, scrollStrategy, parentDialog, overlayContainer) { super(overlay, injector, defaultOptions, parentDialog, overlayContainer, scrollStrategy, MatDialogRef, MatDialogContainer, MAT_DIALOG_DATA); } } MatDialog.decorators = [ { type: Injectable } ]; MatDialog.ctorParameters = () => [ { type: Overlay }, { type: Injector }, { type: Location, decorators: [{ type: Optional }] }, { type: MatDialogConfig, decorators: [{ type: Optional }, { type: Inject, args: [MAT_DIALOG_DEFAULT_OPTIONS,] }] }, { type: undefined, decorators: [{ type: Inject, args: [MAT_DIALOG_SCROLL_STRATEGY,] }] }, { type: MatDialog, decorators: [{ type: Optional }, { type: SkipSelf }] }, { type: OverlayContainer } ]; /** * Applies default options to the dialog config. * @param config Config to be modified. * @param defaultOptions Default options provided. * @returns The new configuration object. */ function _applyConfigDefaults(config, defaultOptions) { return Object.assign(Object.assign({}, defaultOpt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