material-dialog.umd.js 60 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588
  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. (function (global, factory) {
  9. typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@angular/animations'), require('@angular/core'), require('@angular/common'), require('@angular/cdk/portal'), require('@angular/cdk/a11y'), require('@angular/cdk/keycodes'), require('rxjs'), require('rxjs/operators'), require('@angular/cdk/bidi'), require('@angular/cdk/overlay'), require('@angular/material/core')) :
  10. typeof define === 'function' && define.amd ? define('@angular/material/dialog', ['exports', '@angular/animations', '@angular/core', '@angular/common', '@angular/cdk/portal', '@angular/cdk/a11y', '@angular/cdk/keycodes', 'rxjs', 'rxjs/operators', '@angular/cdk/bidi', '@angular/cdk/overlay', '@angular/material/core'], factory) :
  11. (factory((global.ng = global.ng || {}, global.ng.material = global.ng.material || {}, global.ng.material.dialog = {}),global.ng.animations,global.ng.core,global.ng.common,global.ng.cdk.portal,global.ng.cdk.a11y,global.ng.cdk.keycodes,global.rxjs,global.rxjs.operators,global.ng.cdk.bidi,global.ng.cdk.overlay,global.ng.material.core));
  12. }(this, (function (exports,animations,core,common,portal,a11y,keycodes,rxjs,operators,bidi,overlay,core$1) { 'use strict';
  13. /*! *****************************************************************************
  14. Copyright (c) Microsoft Corporation. All rights reserved.
  15. Licensed under the Apache License, Version 2.0 (the "License"); you may not use
  16. this file except in compliance with the License. You may obtain a copy of the
  17. License at http://www.apache.org/licenses/LICENSE-2.0
  18. THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  19. KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
  20. WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
  21. MERCHANTABLITY OR NON-INFRINGEMENT.
  22. See the Apache Version 2.0 License for specific language governing permissions
  23. and limitations under the License.
  24. ***************************************************************************** */
  25. /* global Reflect, Promise */
  26. var extendStatics = function(d, b) {
  27. extendStatics = Object.setPrototypeOf ||
  28. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  29. function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
  30. return extendStatics(d, b);
  31. };
  32. function __extends(d, b) {
  33. extendStatics(d, b);
  34. function __() { this.constructor = d; }
  35. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  36. }
  37. var __assign = function() {
  38. __assign = Object.assign || function __assign(t) {
  39. for (var s, i = 1, n = arguments.length; i < n; i++) {
  40. s = arguments[i];
  41. for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
  42. }
  43. return t;
  44. };
  45. return __assign.apply(this, arguments);
  46. };
  47. /**
  48. * @fileoverview added by tsickle
  49. * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
  50. */
  51. /**
  52. * Configuration for opening a modal dialog with the MatDialog service.
  53. * @template D
  54. */
  55. var /**
  56. * Configuration for opening a modal dialog with the MatDialog service.
  57. * @template D
  58. */
  59. MatDialogConfig = /** @class */ (function () {
  60. function MatDialogConfig() {
  61. /**
  62. * The ARIA role of the dialog element.
  63. */
  64. this.role = 'dialog';
  65. /**
  66. * Custom class for the overlay pane.
  67. */
  68. this.panelClass = '';
  69. /**
  70. * Whether the dialog has a backdrop.
  71. */
  72. this.hasBackdrop = true;
  73. /**
  74. * Custom class for the backdrop,
  75. */
  76. this.backdropClass = '';
  77. /**
  78. * Whether the user can use escape or clicking on the backdrop to close the modal.
  79. */
  80. this.disableClose = false;
  81. /**
  82. * Width of the dialog.
  83. */
  84. this.width = '';
  85. /**
  86. * Height of the dialog.
  87. */
  88. this.height = '';
  89. /**
  90. * Max-width of the dialog. If a number is provided, pixel units are assumed. Defaults to 80vw
  91. */
  92. this.maxWidth = '80vw';
  93. /**
  94. * Data being injected into the child component.
  95. */
  96. this.data = null;
  97. /**
  98. * ID of the element that describes the dialog.
  99. */
  100. this.ariaDescribedBy = null;
  101. /**
  102. * ID of the element that labels the dialog.
  103. */
  104. this.ariaLabelledBy = null;
  105. /**
  106. * Aria label to assign to the dialog element
  107. */
  108. this.ariaLabel = null;
  109. /**
  110. * Whether the dialog should focus the first focusable element on open.
  111. */
  112. this.autoFocus = true;
  113. /**
  114. * Whether the dialog should restore focus to the
  115. * previously-focused element, after it's closed.
  116. */
  117. this.restoreFocus = true;
  118. /**
  119. * Whether the dialog should close when the user goes backwards/forwards in history.
  120. * Note that this usually doesn't include clicking on links (unless the user is using
  121. * the `HashLocationStrategy`).
  122. */
  123. this.closeOnNavigation = true;
  124. // TODO(jelbourn): add configuration for lifecycle hooks, ARIA labelling.
  125. }
  126. return MatDialogConfig;
  127. }());
  128. /**
  129. * @fileoverview added by tsickle
  130. * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
  131. */
  132. /** @type {?} */
  133. var animationBody = [
  134. // Note: The `enter` animation transitions to `transform: none`, because for some reason
  135. // specifying the transform explicitly, causes IE both to blur the dialog content and
  136. // decimate the animation performance. Leaving it as `none` solves both issues.
  137. animations.state('void, exit', animations.style({ opacity: 0, transform: 'scale(0.7)' })),
  138. animations.state('enter', animations.style({ transform: 'none' })),
  139. animations.transition('* => enter', animations.animate('150ms cubic-bezier(0, 0, 0.2, 1)', animations.style({ transform: 'none', opacity: 1 }))),
  140. animations.transition('* => void, * => exit', animations.animate('75ms cubic-bezier(0.4, 0.0, 0.2, 1)', animations.style({ opacity: 0 }))),
  141. ];
  142. /**
  143. * Animations used by MatDialog.
  144. * \@docs-private
  145. * @type {?}
  146. */
  147. var matDialogAnimations = {
  148. /**
  149. * Animation that is applied on the dialog container by defalt.
  150. */
  151. dialogContainer: animations.trigger('dialogContainer', animationBody),
  152. /**
  153. * @deprecated \@breaking-change 8.0.0 Use `matDialogAnimations.dialogContainer` instead.
  154. */
  155. slideDialog: animations.trigger('slideDialog', animationBody)
  156. };
  157. /**
  158. * @fileoverview added by tsickle
  159. * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
  160. */
  161. /**
  162. * Throws an exception for the case when a ComponentPortal is
  163. * attached to a DomPortalOutlet without an origin.
  164. * \@docs-private
  165. * @return {?}
  166. */
  167. function throwMatDialogContentAlreadyAttachedError() {
  168. throw Error('Attempting to attach dialog content after content is already attached');
  169. }
  170. /**
  171. * Internal component that wraps user-provided dialog content.
  172. * Animation is based on https://material.io/guidelines/motion/choreography.html.
  173. * \@docs-private
  174. */
  175. var MatDialogContainer = /** @class */ (function (_super) {
  176. __extends(MatDialogContainer, _super);
  177. function MatDialogContainer(_elementRef, _focusTrapFactory, _changeDetectorRef, _document, _config) {
  178. var _this = _super.call(this) || this;
  179. _this._elementRef = _elementRef;
  180. _this._focusTrapFactory = _focusTrapFactory;
  181. _this._changeDetectorRef = _changeDetectorRef;
  182. _this._document = _document;
  183. _this._config = _config;
  184. /**
  185. * Element that was focused before the dialog was opened. Save this to restore upon close.
  186. */
  187. _this._elementFocusedBeforeDialogWasOpened = null;
  188. /**
  189. * State of the dialog animation.
  190. */
  191. _this._state = 'enter';
  192. /**
  193. * Emits when an animation state changes.
  194. */
  195. _this._animationStateChanged = new core.EventEmitter();
  196. _this._ariaLabelledBy = _config.ariaLabelledBy || null;
  197. return _this;
  198. }
  199. /**
  200. * Attach a ComponentPortal as content to this dialog container.
  201. * @param portal Portal to be attached as the dialog content.
  202. */
  203. /**
  204. * Attach a ComponentPortal as content to this dialog container.
  205. * @template T
  206. * @param {?} portal Portal to be attached as the dialog content.
  207. * @return {?}
  208. */
  209. MatDialogContainer.prototype.attachComponentPortal = /**
  210. * Attach a ComponentPortal as content to this dialog container.
  211. * @template T
  212. * @param {?} portal Portal to be attached as the dialog content.
  213. * @return {?}
  214. */
  215. function (portal$$1) {
  216. if (this._portalOutlet.hasAttached()) {
  217. throwMatDialogContentAlreadyAttachedError();
  218. }
  219. this._savePreviouslyFocusedElement();
  220. return this._portalOutlet.attachComponentPortal(portal$$1);
  221. };
  222. /**
  223. * Attach a TemplatePortal as content to this dialog container.
  224. * @param portal Portal to be attached as the dialog content.
  225. */
  226. /**
  227. * Attach a TemplatePortal as content to this dialog container.
  228. * @template C
  229. * @param {?} portal Portal to be attached as the dialog content.
  230. * @return {?}
  231. */
  232. MatDialogContainer.prototype.attachTemplatePortal = /**
  233. * Attach a TemplatePortal as content to this dialog container.
  234. * @template C
  235. * @param {?} portal Portal to be attached as the dialog content.
  236. * @return {?}
  237. */
  238. function (portal$$1) {
  239. if (this._portalOutlet.hasAttached()) {
  240. throwMatDialogContentAlreadyAttachedError();
  241. }
  242. this._savePreviouslyFocusedElement();
  243. return this._portalOutlet.attachTemplatePortal(portal$$1);
  244. };
  245. /** Moves the focus inside the focus trap. */
  246. /**
  247. * Moves the focus inside the focus trap.
  248. * @private
  249. * @return {?}
  250. */
  251. MatDialogContainer.prototype._trapFocus = /**
  252. * Moves the focus inside the focus trap.
  253. * @private
  254. * @return {?}
  255. */
  256. function () {
  257. /** @type {?} */
  258. var element = this._elementRef.nativeElement;
  259. if (!this._focusTrap) {
  260. this._focusTrap = this._focusTrapFactory.create(element);
  261. }
  262. // If we were to attempt to focus immediately, then the content of the dialog would not yet be
  263. // ready in instances where change detection has to run first. To deal with this, we simply
  264. // wait for the microtask queue to be empty.
  265. if (this._config.autoFocus) {
  266. this._focusTrap.focusInitialElementWhenReady();
  267. }
  268. else {
  269. /** @type {?} */
  270. var activeElement = this._document.activeElement;
  271. // Otherwise ensure that focus is on the dialog container. It's possible that a different
  272. // component tried to move focus while the open animation was running. See:
  273. // https://github.com/angular/components/issues/16215. Note that we only want to do this
  274. // if the focus isn't inside the dialog already, because it's possible that the consumer
  275. // turned off `autoFocus` in order to move focus themselves.
  276. if (activeElement !== element && !element.contains(activeElement)) {
  277. element.focus();
  278. }
  279. }
  280. };
  281. /** Restores focus to the element that was focused before the dialog opened. */
  282. /**
  283. * Restores focus to the element that was focused before the dialog opened.
  284. * @private
  285. * @return {?}
  286. */
  287. MatDialogContainer.prototype._restoreFocus = /**
  288. * Restores focus to the element that was focused before the dialog opened.
  289. * @private
  290. * @return {?}
  291. */
  292. function () {
  293. /** @type {?} */
  294. var toFocus = this._elementFocusedBeforeDialogWasOpened;
  295. // We need the extra check, because IE can set the `activeElement` to null in some cases.
  296. if (this._config.restoreFocus && toFocus && typeof toFocus.focus === 'function') {
  297. toFocus.focus();
  298. }
  299. if (this._focusTrap) {
  300. this._focusTrap.destroy();
  301. }
  302. };
  303. /** Saves a reference to the element that was focused before the dialog was opened. */
  304. /**
  305. * Saves a reference to the element that was focused before the dialog was opened.
  306. * @private
  307. * @return {?}
  308. */
  309. MatDialogContainer.prototype._savePreviouslyFocusedElement = /**
  310. * Saves a reference to the element that was focused before the dialog was opened.
  311. * @private
  312. * @return {?}
  313. */
  314. function () {
  315. var _this = this;
  316. if (this._document) {
  317. this._elementFocusedBeforeDialogWasOpened = (/** @type {?} */ (this._document.activeElement));
  318. // Note that there is no focus method when rendering on the server.
  319. if (this._elementRef.nativeElement.focus) {
  320. // Move focus onto the dialog immediately in order to prevent the user from accidentally
  321. // opening multiple dialogs at the same time. Needs to be async, because the element
  322. // may not be focusable immediately.
  323. Promise.resolve().then((/**
  324. * @return {?}
  325. */
  326. function () { return _this._elementRef.nativeElement.focus(); }));
  327. }
  328. }
  329. };
  330. /** Callback, invoked whenever an animation on the host completes. */
  331. /**
  332. * Callback, invoked whenever an animation on the host completes.
  333. * @param {?} event
  334. * @return {?}
  335. */
  336. MatDialogContainer.prototype._onAnimationDone = /**
  337. * Callback, invoked whenever an animation on the host completes.
  338. * @param {?} event
  339. * @return {?}
  340. */
  341. function (event) {
  342. if (event.toState === 'enter') {
  343. this._trapFocus();
  344. }
  345. else if (event.toState === 'exit') {
  346. this._restoreFocus();
  347. }
  348. this._animationStateChanged.emit(event);
  349. };
  350. /** Callback, invoked when an animation on the host starts. */
  351. /**
  352. * Callback, invoked when an animation on the host starts.
  353. * @param {?} event
  354. * @return {?}
  355. */
  356. MatDialogContainer.prototype._onAnimationStart = /**
  357. * Callback, invoked when an animation on the host starts.
  358. * @param {?} event
  359. * @return {?}
  360. */
  361. function (event) {
  362. this._animationStateChanged.emit(event);
  363. };
  364. /** Starts the dialog exit animation. */
  365. /**
  366. * Starts the dialog exit animation.
  367. * @return {?}
  368. */
  369. MatDialogContainer.prototype._startExitAnimation = /**
  370. * Starts the dialog exit animation.
  371. * @return {?}
  372. */
  373. function () {
  374. this._state = 'exit';
  375. // Mark the container for check so it can react if the
  376. // view container is using OnPush change detection.
  377. this._changeDetectorRef.markForCheck();
  378. };
  379. MatDialogContainer.decorators = [
  380. { type: core.Component, args: [{selector: 'mat-dialog-container',
  381. template: "<ng-template cdkPortalOutlet></ng-template>",
  382. styles: [".mat-dialog-container{display:block;padding:24px;border-radius:4px;box-sizing:border-box;overflow:auto;outline:0;width:100%;height:100%;min-height:inherit;max-height:inherit}@media (-ms-high-contrast:active){.mat-dialog-container{outline:solid 1px}}.mat-dialog-content{display:block;margin:0 -24px;padding:0 24px;max-height:65vh;overflow:auto;-webkit-overflow-scrolling:touch}.mat-dialog-title{margin:0 0 20px;display:block}.mat-dialog-actions{padding:8px 0;display:flex;flex-wrap:wrap;min-height:52px;align-items:center;margin-bottom:-24px}.mat-dialog-actions[align=end]{justify-content:flex-end}.mat-dialog-actions[align=center]{justify-content:center}.mat-dialog-actions .mat-button-base+.mat-button-base{margin-left:8px}[dir=rtl] .mat-dialog-actions .mat-button-base+.mat-button-base{margin-left:0;margin-right:8px}"],
  383. encapsulation: core.ViewEncapsulation.None,
  384. // Using OnPush for dialogs caused some G3 sync issues. Disabled until we can track them down.
  385. // tslint:disable-next-line:validate-decorators
  386. changeDetection: core.ChangeDetectionStrategy.Default,
  387. animations: [matDialogAnimations.dialogContainer],
  388. host: {
  389. 'class': 'mat-dialog-container',
  390. 'tabindex': '-1',
  391. 'aria-modal': 'true',
  392. '[attr.id]': '_id',
  393. '[attr.role]': '_config.role',
  394. '[attr.aria-labelledby]': '_config.ariaLabel ? null : _ariaLabelledBy',
  395. '[attr.aria-label]': '_config.ariaLabel',
  396. '[attr.aria-describedby]': '_config.ariaDescribedBy || null',
  397. '[@dialogContainer]': '_state',
  398. '(@dialogContainer.start)': '_onAnimationStart($event)',
  399. '(@dialogContainer.done)': '_onAnimationDone($event)',
  400. },
  401. },] },
  402. ];
  403. /** @nocollapse */
  404. MatDialogContainer.ctorParameters = function () { return [
  405. { type: core.ElementRef },
  406. { type: a11y.FocusTrapFactory },
  407. { type: core.ChangeDetectorRef },
  408. { type: undefined, decorators: [{ type: core.Optional }, { type: core.Inject, args: [common.DOCUMENT,] }] },
  409. { type: MatDialogConfig }
  410. ]; };
  411. MatDialogContainer.propDecorators = {
  412. _portalOutlet: [{ type: core.ViewChild, args: [portal.CdkPortalOutlet, { static: true },] }]
  413. };
  414. return MatDialogContainer;
  415. }(portal.BasePortalOutlet));
  416. /**
  417. * @fileoverview added by tsickle
  418. * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
  419. */
  420. // TODO(jelbourn): resizing
  421. // Counter for unique dialog ids.
  422. /** @type {?} */
  423. var uniqueId = 0;
  424. /**
  425. * Reference to a dialog opened via the MatDialog service.
  426. * @template T, R
  427. */
  428. var /**
  429. * Reference to a dialog opened via the MatDialog service.
  430. * @template T, R
  431. */
  432. MatDialogRef = /** @class */ (function () {
  433. function MatDialogRef(_overlayRef, _containerInstance,
  434. // @breaking-change 8.0.0 `_location` parameter to be removed.
  435. _location, id) {
  436. var _this = this;
  437. if (id === void 0) { id = "mat-dialog-" + uniqueId++; }
  438. this._overlayRef = _overlayRef;
  439. this._containerInstance = _containerInstance;
  440. this.id = id;
  441. /**
  442. * Whether the user is allowed to close the dialog.
  443. */
  444. this.disableClose = this._containerInstance._config.disableClose;
  445. /**
  446. * Subject for notifying the user that the dialog has finished opening.
  447. */
  448. this._afterOpened = new rxjs.Subject();
  449. /**
  450. * Subject for notifying the user that the dialog has finished closing.
  451. */
  452. this._afterClosed = new rxjs.Subject();
  453. /**
  454. * Subject for notifying the user that the dialog has started closing.
  455. */
  456. this._beforeClosed = new rxjs.Subject();
  457. // Pass the id along to the container.
  458. _containerInstance._id = id;
  459. // Emit when opening animation completes
  460. _containerInstance._animationStateChanged.pipe(operators.filter((/**
  461. * @param {?} event
  462. * @return {?}
  463. */
  464. function (event) { return event.phaseName === 'done' && event.toState === 'enter'; })), operators.take(1))
  465. .subscribe((/**
  466. * @return {?}
  467. */
  468. function () {
  469. _this._afterOpened.next();
  470. _this._afterOpened.complete();
  471. }));
  472. // Dispose overlay when closing animation is complete
  473. _containerInstance._animationStateChanged.pipe(operators.filter((/**
  474. * @param {?} event
  475. * @return {?}
  476. */
  477. function (event) { return event.phaseName === 'done' && event.toState === 'exit'; })), operators.take(1)).subscribe((/**
  478. * @return {?}
  479. */
  480. function () {
  481. clearTimeout(_this._closeFallbackTimeout);
  482. _this._overlayRef.dispose();
  483. }));
  484. _overlayRef.detachments().subscribe((/**
  485. * @return {?}
  486. */
  487. function () {
  488. _this._beforeClosed.next(_this._result);
  489. _this._beforeClosed.complete();
  490. _this._afterClosed.next(_this._result);
  491. _this._afterClosed.complete();
  492. _this.componentInstance = (/** @type {?} */ (null));
  493. _this._overlayRef.dispose();
  494. }));
  495. _overlayRef.keydownEvents()
  496. .pipe(operators.filter((/**
  497. * @param {?} event
  498. * @return {?}
  499. */
  500. function (event) {
  501. return event.keyCode === keycodes.ESCAPE && !_this.disableClose && !keycodes.hasModifierKey(event);
  502. })))
  503. .subscribe((/**
  504. * @param {?} event
  505. * @return {?}
  506. */
  507. function (event) {
  508. event.preventDefault();
  509. _this.close();
  510. }));
  511. }
  512. /**
  513. * Close the dialog.
  514. * @param dialogResult Optional result to return to the dialog opener.
  515. */
  516. /**
  517. * Close the dialog.
  518. * @param {?=} dialogResult Optional result to return to the dialog opener.
  519. * @return {?}
  520. */
  521. MatDialogRef.prototype.close = /**
  522. * Close the dialog.
  523. * @param {?=} dialogResult Optional result to return to the dialog opener.
  524. * @return {?}
  525. */
  526. function (dialogResult) {
  527. var _this = this;
  528. this._result = dialogResult;
  529. // Transition the backdrop in parallel to the dialog.
  530. this._containerInstance._animationStateChanged.pipe(operators.filter((/**
  531. * @param {?} event
  532. * @return {?}
  533. */
  534. function (event) { return event.phaseName === 'start'; })), operators.take(1))
  535. .subscribe((/**
  536. * @param {?} event
  537. * @return {?}
  538. */
  539. function (event) {
  540. _this._beforeClosed.next(dialogResult);
  541. _this._beforeClosed.complete();
  542. _this._overlayRef.detachBackdrop();
  543. // The logic that disposes of the overlay depends on the exit animation completing, however
  544. // it isn't guaranteed if the parent view is destroyed while it's running. Add a fallback
  545. // timeout which will clean everything up if the animation hasn't fired within the specified
  546. // amount of time plus 100ms. We don't need to run this outside the NgZone, because for the
  547. // vast majority of cases the timeout will have been cleared before it has the chance to fire.
  548. _this._closeFallbackTimeout = setTimeout((/**
  549. * @return {?}
  550. */
  551. function () {
  552. _this._overlayRef.dispose();
  553. }), event.totalTime + 100);
  554. }));
  555. this._containerInstance._startExitAnimation();
  556. };
  557. /**
  558. * Gets an observable that is notified when the dialog is finished opening.
  559. */
  560. /**
  561. * Gets an observable that is notified when the dialog is finished opening.
  562. * @return {?}
  563. */
  564. MatDialogRef.prototype.afterOpened = /**
  565. * Gets an observable that is notified when the dialog is finished opening.
  566. * @return {?}
  567. */
  568. function () {
  569. return this._afterOpened.asObservable();
  570. };
  571. /**
  572. * Gets an observable that is notified when the dialog is finished closing.
  573. */
  574. /**
  575. * Gets an observable that is notified when the dialog is finished closing.
  576. * @return {?}
  577. */
  578. MatDialogRef.prototype.afterClosed = /**
  579. * Gets an observable that is notified when the dialog is finished closing.
  580. * @return {?}
  581. */
  582. function () {
  583. return this._afterClosed.asObservable();
  584. };
  585. /**
  586. * Gets an observable that is notified when the dialog has started closing.
  587. */
  588. /**
  589. * Gets an observable that is notified when the dialog has started closing.
  590. * @return {?}
  591. */
  592. MatDialogRef.prototype.beforeClosed = /**
  593. * Gets an observable that is notified when the dialog has started closing.
  594. * @return {?}
  595. */
  596. function () {
  597. return this._beforeClosed.asObservable();
  598. };
  599. /**
  600. * Gets an observable that emits when the overlay's backdrop has been clicked.
  601. */
  602. /**
  603. * Gets an observable that emits when the overlay's backdrop has been clicked.
  604. * @return {?}
  605. */
  606. MatDialogRef.prototype.backdropClick = /**
  607. * Gets an observable that emits when the overlay's backdrop has been clicked.
  608. * @return {?}
  609. */
  610. function () {
  611. return this._overlayRef.backdropClick();
  612. };
  613. /**
  614. * Gets an observable that emits when keydown events are targeted on the overlay.
  615. */
  616. /**
  617. * Gets an observable that emits when keydown events are targeted on the overlay.
  618. * @return {?}
  619. */
  620. MatDialogRef.prototype.keydownEvents = /**
  621. * Gets an observable that emits when keydown events are targeted on the overlay.
  622. * @return {?}
  623. */
  624. function () {
  625. return this._overlayRef.keydownEvents();
  626. };
  627. /**
  628. * Updates the dialog's position.
  629. * @param position New dialog position.
  630. */
  631. /**
  632. * Updates the dialog's position.
  633. * @template THIS
  634. * @this {THIS}
  635. * @param {?=} position New dialog position.
  636. * @return {THIS}
  637. */
  638. MatDialogRef.prototype.updatePosition = /**
  639. * Updates the dialog's position.
  640. * @template THIS
  641. * @this {THIS}
  642. * @param {?=} position New dialog position.
  643. * @return {THIS}
  644. */
  645. function (position) {
  646. /** @type {?} */
  647. var strategy = (/** @type {?} */ (this))._getPositionStrategy();
  648. if (position && (position.left || position.right)) {
  649. position.left ? strategy.left(position.left) : strategy.right(position.right);
  650. }
  651. else {
  652. strategy.centerHorizontally();
  653. }
  654. if (position && (position.top || position.bottom)) {
  655. position.top ? strategy.top(position.top) : strategy.bottom(position.bottom);
  656. }
  657. else {
  658. strategy.centerVertically();
  659. }
  660. (/** @type {?} */ (this))._overlayRef.updatePosition();
  661. return (/** @type {?} */ (this));
  662. };
  663. /**
  664. * Updates the dialog's width and height.
  665. * @param width New width of the dialog.
  666. * @param height New height of the dialog.
  667. */
  668. /**
  669. * Updates the dialog's width and height.
  670. * @template THIS
  671. * @this {THIS}
  672. * @param {?=} width New width of the dialog.
  673. * @param {?=} height New height of the dialog.
  674. * @return {THIS}
  675. */
  676. MatDialogRef.prototype.updateSize = /**
  677. * Updates the dialog's width and height.
  678. * @template THIS
  679. * @this {THIS}
  680. * @param {?=} width New width of the dialog.
  681. * @param {?=} height New height of the dialog.
  682. * @return {THIS}
  683. */
  684. function (width, height) {
  685. if (width === void 0) { width = ''; }
  686. if (height === void 0) { height = ''; }
  687. (/** @type {?} */ (this))._getPositionStrategy().width(width).height(height);
  688. (/** @type {?} */ (this))._overlayRef.updatePosition();
  689. return (/** @type {?} */ (this));
  690. };
  691. /** Add a CSS class or an array of classes to the overlay pane. */
  692. /**
  693. * Add a CSS class or an array of classes to the overlay pane.
  694. * @template THIS
  695. * @this {THIS}
  696. * @param {?} classes
  697. * @return {THIS}
  698. */
  699. MatDialogRef.prototype.addPanelClass = /**
  700. * Add a CSS class or an array of classes to the overlay pane.
  701. * @template THIS
  702. * @this {THIS}
  703. * @param {?} classes
  704. * @return {THIS}
  705. */
  706. function (classes) {
  707. (/** @type {?} */ (this))._overlayRef.addPanelClass(classes);
  708. return (/** @type {?} */ (this));
  709. };
  710. /** Remove a CSS class or an array of classes from the overlay pane. */
  711. /**
  712. * Remove a CSS class or an array of classes from the overlay pane.
  713. * @template THIS
  714. * @this {THIS}
  715. * @param {?} classes
  716. * @return {THIS}
  717. */
  718. MatDialogRef.prototype.removePanelClass = /**
  719. * Remove a CSS class or an array of classes from the overlay pane.
  720. * @template THIS
  721. * @this {THIS}
  722. * @param {?} classes
  723. * @return {THIS}
  724. */
  725. function (classes) {
  726. (/** @type {?} */ (this))._overlayRef.removePanelClass(classes);
  727. return (/** @type {?} */ (this));
  728. };
  729. /**
  730. * Gets an observable that is notified when the dialog is finished opening.
  731. * @deprecated Use `afterOpened` instead.
  732. * @breaking-change 8.0.0
  733. */
  734. /**
  735. * Gets an observable that is notified when the dialog is finished opening.
  736. * @deprecated Use `afterOpened` instead.
  737. * \@breaking-change 8.0.0
  738. * @return {?}
  739. */
  740. MatDialogRef.prototype.afterOpen = /**
  741. * Gets an observable that is notified when the dialog is finished opening.
  742. * @deprecated Use `afterOpened` instead.
  743. * \@breaking-change 8.0.0
  744. * @return {?}
  745. */
  746. function () {
  747. return this.afterOpened();
  748. };
  749. /**
  750. * Gets an observable that is notified when the dialog has started closing.
  751. * @deprecated Use `beforeClosed` instead.
  752. * @breaking-change 8.0.0
  753. */
  754. /**
  755. * Gets an observable that is notified when the dialog has started closing.
  756. * @deprecated Use `beforeClosed` instead.
  757. * \@breaking-change 8.0.0
  758. * @return {?}
  759. */
  760. MatDialogRef.prototype.beforeClose = /**
  761. * Gets an observable that is notified when the dialog has started closing.
  762. * @deprecated Use `beforeClosed` instead.
  763. * \@breaking-change 8.0.0
  764. * @return {?}
  765. */
  766. function () {
  767. return this.beforeClosed();
  768. };
  769. /** Fetches the position strategy object from the overlay ref. */
  770. /**
  771. * Fetches the position strategy object from the overlay ref.
  772. * @private
  773. * @return {?}
  774. */
  775. MatDialogRef.prototype._getPositionStrategy = /**
  776. * Fetches the position strategy object from the overlay ref.
  777. * @private
  778. * @return {?}
  779. */
  780. function () {
  781. return (/** @type {?} */ (this._overlayRef.getConfig().positionStrategy));
  782. };
  783. return MatDialogRef;
  784. }());
  785. /**
  786. * @fileoverview added by tsickle
  787. * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
  788. */
  789. /**
  790. * Injection token that can be used to access the data that was passed in to a dialog.
  791. * @type {?}
  792. */
  793. var MAT_DIALOG_DATA = new core.InjectionToken('MatDialogData');
  794. /**
  795. * Injection token that can be used to specify default dialog options.
  796. * @type {?}
  797. */
  798. var MAT_DIALOG_DEFAULT_OPTIONS = new core.InjectionToken('mat-dialog-default-options');
  799. /**
  800. * Injection token that determines the scroll handling while the dialog is open.
  801. * @type {?}
  802. */
  803. var MAT_DIALOG_SCROLL_STRATEGY = new core.InjectionToken('mat-dialog-scroll-strategy');
  804. /**
  805. * \@docs-private
  806. * @param {?} overlay
  807. * @return {?}
  808. */
  809. function MAT_DIALOG_SCROLL_STRATEGY_FACTORY(overlay$$1) {
  810. return (/**
  811. * @return {?}
  812. */
  813. function () { return overlay$$1.scrollStrategies.block(); });
  814. }
  815. /**
  816. * \@docs-private
  817. * @param {?} overlay
  818. * @return {?}
  819. */
  820. function MAT_DIALOG_SCROLL_STRATEGY_PROVIDER_FACTORY(overlay$$1) {
  821. return (/**
  822. * @return {?}
  823. */
  824. function () { return overlay$$1.scrollStrategies.block(); });
  825. }
  826. /**
  827. * \@docs-private
  828. * @type {?}
  829. */
  830. var MAT_DIALOG_SCROLL_STRATEGY_PROVIDER = {
  831. provide: MAT_DIALOG_SCROLL_STRATEGY,
  832. deps: [overlay.Overlay],
  833. useFactory: MAT_DIALOG_SCROLL_STRATEGY_PROVIDER_FACTORY,
  834. };
  835. /**
  836. * Service to open Material Design modal dialogs.
  837. */
  838. var MatDialog = /** @class */ (function () {
  839. function MatDialog(_overlay, _injector, _location, _defaultOptions, scrollStrategy, _parentDialog, _overlayContainer) {
  840. var _this = this;
  841. this._overlay = _overlay;
  842. this._injector = _injector;
  843. this._location = _location;
  844. this._defaultOptions = _defaultOptions;
  845. this._parentDialog = _parentDialog;
  846. this._overlayContainer = _overlayContainer;
  847. this._openDialogsAtThisLevel = [];
  848. this._afterAllClosedAtThisLevel = new rxjs.Subject();
  849. this._afterOpenedAtThisLevel = new rxjs.Subject();
  850. this._ariaHiddenElements = new Map();
  851. // TODO (jelbourn): tighten the typing right-hand side of this expression.
  852. /**
  853. * Stream that emits when all open dialog have finished closing.
  854. * Will emit on subscribe if there are no open dialogs to begin with.
  855. */
  856. this.afterAllClosed = (/** @type {?} */ (rxjs.defer((/**
  857. * @return {?}
  858. */
  859. function () { return _this.openDialogs.length ?
  860. _this._afterAllClosed :
  861. _this._afterAllClosed.pipe(operators.startWith(undefined)); }))));
  862. this._scrollStrategy = scrollStrategy;
  863. }
  864. Object.defineProperty(MatDialog.prototype, "openDialogs", {
  865. /** Keeps track of the currently-open dialogs. */
  866. get: /**
  867. * Keeps track of the currently-open dialogs.
  868. * @return {?}
  869. */
  870. function () {
  871. return this._parentDialog ? this._parentDialog.openDialogs : this._openDialogsAtThisLevel;
  872. },
  873. enumerable: true,
  874. configurable: true
  875. });
  876. Object.defineProperty(MatDialog.prototype, "afterOpened", {
  877. /** Stream that emits when a dialog has been opened. */
  878. get: /**
  879. * Stream that emits when a dialog has been opened.
  880. * @return {?}
  881. */
  882. function () {
  883. return this._parentDialog ? this._parentDialog.afterOpened : this._afterOpenedAtThisLevel;
  884. },
  885. enumerable: true,
  886. configurable: true
  887. });
  888. Object.defineProperty(MatDialog.prototype, "afterOpen", {
  889. /**
  890. * Stream that emits when a dialog has been opened.
  891. * @deprecated Use `afterOpened` instead.
  892. * @breaking-change 8.0.0
  893. */
  894. get: /**
  895. * Stream that emits when a dialog has been opened.
  896. * @deprecated Use `afterOpened` instead.
  897. * \@breaking-change 8.0.0
  898. * @return {?}
  899. */
  900. function () {
  901. return this.afterOpened;
  902. },
  903. enumerable: true,
  904. configurable: true
  905. });
  906. Object.defineProperty(MatDialog.prototype, "_afterAllClosed", {
  907. get: /**
  908. * @return {?}
  909. */
  910. function () {
  911. /** @type {?} */
  912. var parent = this._parentDialog;
  913. return parent ? parent._afterAllClosed : this._afterAllClosedAtThisLevel;
  914. },
  915. enumerable: true,
  916. configurable: true
  917. });
  918. /**
  919. * Opens a modal dialog containing the given component.
  920. * @param componentOrTemplateRef Type of the component to load into the dialog,
  921. * or a TemplateRef to instantiate as the dialog content.
  922. * @param config Extra configuration options.
  923. * @returns Reference to the newly-opened dialog.
  924. */
  925. /**
  926. * Opens a modal dialog containing the given component.
  927. * @template T, D, R
  928. * @param {?} componentOrTemplateRef Type of the component to load into the dialog,
  929. * or a TemplateRef to instantiate as the dialog content.
  930. * @param {?=} config Extra configuration options.
  931. * @return {?} Reference to the newly-opened dialog.
  932. */
  933. MatDialog.prototype.open = /**
  934. * Opens a modal dialog containing the given component.
  935. * @template T, D, R
  936. * @param {?} componentOrTemplateRef Type of the component to load into the dialog,
  937. * or a TemplateRef to instantiate as the dialog content.
  938. * @param {?=} config Extra configuration options.
  939. * @return {?} Reference to the newly-opened dialog.
  940. */
  941. function (componentOrTemplateRef, config) {
  942. var _this = this;
  943. config = _applyConfigDefaults(config, this._defaultOptions || new MatDialogConfig());
  944. if (config.id && this.getDialogById(config.id)) {
  945. throw Error("Dialog with id \"" + config.id + "\" exists already. The dialog id must be unique.");
  946. }
  947. /** @type {?} */
  948. var overlayRef = this._createOverlay(config);
  949. /** @type {?} */
  950. var dialogContainer = this._attachDialogContainer(overlayRef, config);
  951. /** @type {?} */
  952. var dialogRef = this._attachDialogContent(componentOrTemplateRef, dialogContainer, overlayRef, config);
  953. // If this is the first dialog that we're opening, hide all the non-overlay content.
  954. if (!this.openDialogs.length) {
  955. this._hideNonDialogContentFromAssistiveTechnology();
  956. }
  957. this.openDialogs.push(dialogRef);
  958. dialogRef.afterClosed().subscribe((/**
  959. * @return {?}
  960. */
  961. function () { return _this._removeOpenDialog(dialogRef); }));
  962. this.afterOpened.next(dialogRef);
  963. return dialogRef;
  964. };
  965. /**
  966. * Closes all of the currently-open dialogs.
  967. */
  968. /**
  969. * Closes all of the currently-open dialogs.
  970. * @return {?}
  971. */
  972. MatDialog.prototype.closeAll = /**
  973. * Closes all of the currently-open dialogs.
  974. * @return {?}
  975. */
  976. function () {
  977. this._closeDialogs(this.openDialogs);
  978. };
  979. /**
  980. * Finds an open dialog by its id.
  981. * @param id ID to use when looking up the dialog.
  982. */
  983. /**
  984. * Finds an open dialog by its id.
  985. * @param {?} id ID to use when looking up the dialog.
  986. * @return {?}
  987. */
  988. MatDialog.prototype.getDialogById = /**
  989. * Finds an open dialog by its id.
  990. * @param {?} id ID to use when looking up the dialog.
  991. * @return {?}
  992. */
  993. function (id) {
  994. return this.openDialogs.find((/**
  995. * @param {?} dialog
  996. * @return {?}
  997. */
  998. function (dialog) { return dialog.id === id; }));
  999. };
  1000. /**
  1001. * @return {?}
  1002. */
  1003. MatDialog.prototype.ngOnDestroy = /**
  1004. * @return {?}
  1005. */
  1006. function () {
  1007. // Only close the dialogs at this level on destroy
  1008. // since the parent service may still be active.
  1009. this._closeDialogs(this._openDialogsAtThisLevel);
  1010. this._afterAllClosedAtThisLevel.complete();
  1011. this._afterOpenedAtThisLevel.complete();
  1012. };
  1013. /**
  1014. * Creates the overlay into which the dialog will be loaded.
  1015. * @param config The dialog configuration.
  1016. * @returns A promise resolving to the OverlayRef for the created overlay.
  1017. */
  1018. /**
  1019. * Creates the overlay into which the dialog will be loaded.
  1020. * @private
  1021. * @param {?} config The dialog configuration.
  1022. * @return {?} A promise resolving to the OverlayRef for the created overlay.
  1023. */
  1024. MatDialog.prototype._createOverlay = /**
  1025. * Creates the overlay into which the dialog will be loaded.
  1026. * @private
  1027. * @param {?} config The dialog configuration.
  1028. * @return {?} A promise resolving to the OverlayRef for the created overlay.
  1029. */
  1030. function (config) {
  1031. /** @type {?} */
  1032. var overlayConfig = this._getOverlayConfig(config);
  1033. return this._overlay.create(overlayConfig);
  1034. };
  1035. /**
  1036. * Creates an overlay config from a dialog config.
  1037. * @param dialogConfig The dialog configuration.
  1038. * @returns The overlay configuration.
  1039. */
  1040. /**
  1041. * Creates an overlay config from a dialog config.
  1042. * @private
  1043. * @param {?} dialogConfig The dialog configuration.
  1044. * @return {?} The overlay configuration.
  1045. */
  1046. MatDialog.prototype._getOverlayConfig = /**
  1047. * Creates an overlay config from a dialog config.
  1048. * @private
  1049. * @param {?} dialogConfig The dialog configuration.
  1050. * @return {?} The overlay configuration.
  1051. */
  1052. function (dialogConfig) {
  1053. /** @type {?} */
  1054. var state$$1 = new overlay.OverlayConfig({
  1055. positionStrategy: this._overlay.position().global(),
  1056. scrollStrategy: dialogConfig.scrollStrategy || this._scrollStrategy(),
  1057. panelClass: dialogConfig.panelClass,
  1058. hasBackdrop: dialogConfig.hasBackdrop,
  1059. direction: dialogConfig.direction,
  1060. minWidth: dialogConfig.minWidth,
  1061. minHeight: dialogConfig.minHeight,
  1062. maxWidth: dialogConfig.maxWidth,
  1063. maxHeight: dialogConfig.maxHeight,
  1064. disposeOnNavigation: dialogConfig.closeOnNavigation
  1065. });
  1066. if (dialogConfig.backdropClass) {
  1067. state$$1.backdropClass = dialogConfig.backdropClass;
  1068. }
  1069. return state$$1;
  1070. };
  1071. /**
  1072. * Attaches an MatDialogContainer to a dialog's already-created overlay.
  1073. * @param overlay Reference to the dialog's underlying overlay.
  1074. * @param config The dialog configuration.
  1075. * @returns A promise resolving to a ComponentRef for the attached container.
  1076. */
  1077. /**
  1078. * Attaches an MatDialogContainer to a dialog's already-created overlay.
  1079. * @private
  1080. * @param {?} overlay Reference to the dialog's underlying overlay.
  1081. * @param {?} config The dialog configuration.
  1082. * @return {?} A promise resolving to a ComponentRef for the attached container.
  1083. */
  1084. MatDialog.prototype._attachDialogContainer = /**
  1085. * Attaches an MatDialogContainer to a dialog's already-created overlay.
  1086. * @private
  1087. * @param {?} overlay Reference to the dialog's underlying overlay.
  1088. * @param {?} config The dialog configuration.
  1089. * @return {?} A promise resolving to a ComponentRef for the attached container.
  1090. */
  1091. function (overlay$$1, config) {
  1092. /** @type {?} */
  1093. var userInjector = config && config.viewContainerRef && config.viewContainerRef.injector;
  1094. /** @type {?} */
  1095. var injector = new portal.PortalInjector(userInjector || this._injector, new WeakMap([
  1096. [MatDialogConfig, config]
  1097. ]));
  1098. /** @type {?} */
  1099. var containerPortal = new portal.ComponentPortal(MatDialogContainer, config.viewContainerRef, injector);
  1100. /** @type {?} */
  1101. var containerRef = overlay$$1.attach(containerPortal);
  1102. return containerRef.instance;
  1103. };
  1104. /**
  1105. * Attaches the user-provided component to the already-created MatDialogContainer.
  1106. * @param componentOrTemplateRef The type of component being loaded into the dialog,
  1107. * or a TemplateRef to instantiate as the content.
  1108. * @param dialogContainer Reference to the wrapping MatDialogContainer.
  1109. * @param overlayRef Reference to the overlay in which the dialog resides.
  1110. * @param config The dialog configuration.
  1111. * @returns A promise resolving to the MatDialogRef that should be returned to the user.
  1112. */
  1113. /**
  1114. * Attaches the user-provided component to the already-created MatDialogContainer.
  1115. * @private
  1116. * @template T, R
  1117. * @param {?} componentOrTemplateRef The type of component being loaded into the dialog,
  1118. * or a TemplateRef to instantiate as the content.
  1119. * @param {?} dialogContainer Reference to the wrapping MatDialogContainer.
  1120. * @param {?} overlayRef Reference to the overlay in which the dialog resides.
  1121. * @param {?} config The dialog configuration.
  1122. * @return {?} A promise resolving to the MatDialogRef that should be returned to the user.
  1123. */
  1124. MatDialog.prototype._attachDialogContent = /**
  1125. * Attaches the user-provided component to the already-created MatDialogContainer.
  1126. * @private
  1127. * @template T, R
  1128. * @param {?} componentOrTemplateRef The type of component being loaded into the dialog,
  1129. * or a TemplateRef to instantiate as the content.
  1130. * @param {?} dialogContainer Reference to the wrapping MatDialogContainer.
  1131. * @param {?} overlayRef Reference to the overlay in which the dialog resides.
  1132. * @param {?} config The dialog configuration.
  1133. * @return {?} A promise resolving to the MatDialogRef that should be returned to the user.
  1134. */
  1135. function (componentOrTemplateRef, dialogContainer, overlayRef, config) {
  1136. // Create a reference to the dialog we're creating in order to give the user a handle
  1137. // to modify and close it.
  1138. /** @type {?} */
  1139. var dialogRef = new MatDialogRef(overlayRef, dialogContainer, this._location, config.id);
  1140. // When the dialog backdrop is clicked, we want to close it.
  1141. if (config.hasBackdrop) {
  1142. overlayRef.backdropClick().subscribe((/**
  1143. * @return {?}
  1144. */
  1145. function () {
  1146. if (!dialogRef.disableClose) {
  1147. dialogRef.close();
  1148. }
  1149. }));
  1150. }
  1151. if (componentOrTemplateRef instanceof core.TemplateRef) {
  1152. dialogContainer.attachTemplatePortal(new portal.TemplatePortal(componentOrTemplateRef, (/** @type {?} */ (null)), (/** @type {?} */ ({ $implicit: config.data, dialogRef: dialogRef }))));
  1153. }
  1154. else {
  1155. /** @type {?} */
  1156. var injector = this._createInjector(config, dialogRef, dialogContainer);
  1157. /** @type {?} */
  1158. var contentRef = dialogContainer.attachComponentPortal(new portal.ComponentPortal(componentOrTemplateRef, undefined, injector));
  1159. dialogRef.componentInstance = contentRef.instance;
  1160. }
  1161. dialogRef
  1162. .updateSize(config.width, config.height)
  1163. .updatePosition(config.position);
  1164. return dialogRef;
  1165. };
  1166. /**
  1167. * Creates a custom injector to be used inside the dialog. This allows a component loaded inside
  1168. * of a dialog to close itself and, optionally, to return a value.
  1169. * @param config Config object that is used to construct the dialog.
  1170. * @param dialogRef Reference to the dialog.
  1171. * @param container Dialog container element that wraps all of the contents.
  1172. * @returns The custom injector that can be used inside the dialog.
  1173. */
  1174. /**
  1175. * Creates a custom injector to be used inside the dialog. This allows a component loaded inside
  1176. * of a dialog to close itself and, optionally, to return a value.
  1177. * @private
  1178. * @template T
  1179. * @param {?} config Config object that is used to construct the dialog.
  1180. * @param {?} dialogRef Reference to the dialog.
  1181. * @param {?} dialogContainer
  1182. * @return {?} The custom injector that can be used inside the dialog.
  1183. */
  1184. MatDialog.prototype._createInjector = /**
  1185. * Creates a custom injector to be used inside the dialog. This allows a component loaded inside
  1186. * of a dialog to close itself and, optionally, to return a value.
  1187. * @private
  1188. * @template T
  1189. * @param {?} config Config object that is used to construct the dialog.
  1190. * @param {?} dialogRef Reference to the dialog.
  1191. * @param {?} dialogContainer
  1192. * @return {?} The custom injector that can be used inside the dialog.
  1193. */
  1194. function (config, dialogRef, dialogContainer) {
  1195. /** @type {?} */
  1196. var userInjector = config && config.viewContainerRef && config.viewContainerRef.injector;
  1197. // The MatDialogContainer is injected in the portal as the MatDialogContainer and the dialog's
  1198. // content are created out of the same ViewContainerRef and as such, are siblings for injector
  1199. // purposes. To allow the hierarchy that is expected, the MatDialogContainer is explicitly
  1200. // added to the injection tokens.
  1201. /** @type {?} */
  1202. var injectionTokens = new WeakMap([
  1203. [MatDialogContainer, dialogContainer],
  1204. [MAT_DIALOG_DATA, config.data],
  1205. [MatDialogRef, dialogRef]
  1206. ]);
  1207. if (config.direction &&
  1208. (!userInjector || !userInjector.get(bidi.Directionality, null))) {
  1209. injectionTokens.set(bidi.Directionality, {
  1210. value: config.direction,
  1211. change: rxjs.of()
  1212. });
  1213. }
  1214. return new portal.PortalInjector(userInjector || this._injector, injectionTokens);
  1215. };
  1216. /**
  1217. * Removes a dialog from the array of open dialogs.
  1218. * @param dialogRef Dialog to be removed.
  1219. */
  1220. /**
  1221. * Removes a dialog from the array of open dialogs.
  1222. * @private
  1223. * @param {?} dialogRef Dialog to be removed.
  1224. * @return {?}
  1225. */
  1226. MatDialog.prototype._removeOpenDialog = /**
  1227. * Removes a dialog from the array of open dialogs.
  1228. * @private
  1229. * @param {?} dialogRef Dialog to be removed.
  1230. * @return {?}
  1231. */
  1232. function (dialogRef) {
  1233. /** @type {?} */
  1234. var index = this.openDialogs.indexOf(dialogRef);
  1235. if (index > -1) {
  1236. this.openDialogs.splice(index, 1);
  1237. // If all the dialogs were closed, remove/restore the `aria-hidden`
  1238. // to a the siblings and emit to the `afterAllClosed` stream.
  1239. if (!this.openDialogs.length) {
  1240. this._ariaHiddenElements.forEach((/**
  1241. * @param {?} previousValue
  1242. * @param {?} element
  1243. * @return {?}
  1244. */
  1245. function (previousValue, element) {
  1246. if (previousValue) {
  1247. element.setAttribute('aria-hidden', previousValue);
  1248. }
  1249. else {
  1250. element.removeAttribute('aria-hidden');
  1251. }
  1252. }));
  1253. this._ariaHiddenElements.clear();
  1254. this._afterAllClosed.next();
  1255. }
  1256. }
  1257. };
  1258. /**
  1259. * Hides all of the content that isn't an overlay from assistive technology.
  1260. */
  1261. /**
  1262. * Hides all of the content that isn't an overlay from assistive technology.
  1263. * @private
  1264. * @return {?}
  1265. */
  1266. MatDialog.prototype._hideNonDialogContentFromAssistiveTechnology = /**
  1267. * Hides all of the content that isn't an overlay from assistive technology.
  1268. * @private
  1269. * @return {?}
  1270. */
  1271. function () {
  1272. /** @type {?} */
  1273. var overlayContainer = this._overlayContainer.getContainerElement();
  1274. // Ensure that the overlay container is attached to the DOM.
  1275. if (overlayContainer.parentElement) {
  1276. /** @type {?} */
  1277. var siblings = overlayContainer.parentElement.children;
  1278. for (var i = siblings.length - 1; i > -1; i--) {
  1279. /** @type {?} */
  1280. var sibling = siblings[i];
  1281. if (sibling !== overlayContainer &&
  1282. sibling.nodeName !== 'SCRIPT' &&
  1283. sibling.nodeName !== 'STYLE' &&
  1284. !sibling.hasAttribute('aria-live')) {
  1285. this._ariaHiddenElements.set(sibling, sibling.getAttribute('aria-hidden'));
  1286. sibling.setAttribute('aria-hidden', 'true');
  1287. }
  1288. }
  1289. }
  1290. };
  1291. /** Closes all of the dialogs in an array. */
  1292. /**
  1293. * Closes all of the dialogs in an array.
  1294. * @private
  1295. * @param {?} dialogs
  1296. * @return {?}
  1297. */
  1298. MatDialog.prototype._closeDialogs = /**
  1299. * Closes all of the dialogs in an array.
  1300. * @private
  1301. * @param {?} dialogs
  1302. * @return {?}
  1303. */
  1304. function (dialogs) {
  1305. /** @type {?} */
  1306. var i = dialogs.length;
  1307. while (i--) {
  1308. // The `_openDialogs` property isn't updated after close until the rxjs subscription
  1309. // runs on the next microtask, in addition to modifying the array as we're going
  1310. // through it. We loop through all of them and call close without assuming that
  1311. // they'll be removed from the list instantaneously.
  1312. dialogs[i].close();
  1313. }
  1314. };
  1315. MatDialog.decorators = [
  1316. { type: core.Injectable },
  1317. ];
  1318. /** @nocollapse */
  1319. MatDialog.ctorParameters = function () { return [
  1320. { type: overlay.Overlay },
  1321. { type: core.Injector },
  1322. { type: common.Location, decorators: [{ type: core.Optional }] },
  1323. { type: MatDialogConfig, decorators: [{ type: core.Optional }, { type: core.Inject, args: [MAT_DIALOG_DEFAULT_OPTIONS,] }] },
  1324. { type: undefined, decorators: [{ type: core.Inject, args: [MAT_DIALOG_SCROLL_STRATEGY,] }] },
  1325. { type: MatDialog, decorators: [{ type: core.Optional }, { type: core.SkipSelf }] },
  1326. { type: overlay.OverlayContainer }
  1327. ]; };
  1328. return MatDialog;
  1329. }());
  1330. /**
  1331. * Applies default options to the dialog config.
  1332. * @param {?=} config Config to be modified.
  1333. * @param {?=} defaultOptions Default options provided.
  1334. * @return {?} The new configuration object.
  1335. */
  1336. function _applyConfigDefaults(config, defaultOptions) {
  1337. return __assign({}, defaultOptions, config);
  1338. }
  1339. /**
  1340. * @fileoverview added by tsickle
  1341. * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
  1342. */
  1343. /**
  1344. * Counter used to generate unique IDs for dialog elements.
  1345. * @type {?}
  1346. */
  1347. var dialogElementUid = 0;
  1348. /**
  1349. * Button that will close the current dialog.
  1350. */
  1351. var MatDialogClose = /** @class */ (function () {
  1352. function MatDialogClose(dialogRef, _elementRef, _dialog) {
  1353. this.dialogRef = dialogRef;
  1354. this._elementRef = _elementRef;
  1355. this._dialog = _dialog;
  1356. }
  1357. /**
  1358. * @return {?}
  1359. */
  1360. MatDialogClose.prototype.ngOnInit = /**
  1361. * @return {?}
  1362. */
  1363. function () {
  1364. if (!this.dialogRef) {
  1365. // When this directive is included in a dialog via TemplateRef (rather than being
  1366. // in a Component), the DialogRef isn't available via injection because embedded
  1367. // views cannot be given a custom injector. Instead, we look up the DialogRef by
  1368. // ID. This must occur in `onInit`, as the ID binding for the dialog container won't
  1369. // be resolved at constructor time.
  1370. this.dialogRef = (/** @type {?} */ (getClosestDialog(this._elementRef, this._dialog.openDialogs)));
  1371. }
  1372. };
  1373. /**
  1374. * @param {?} changes
  1375. * @return {?}
  1376. */
  1377. MatDialogClose.prototype.ngOnChanges = /**
  1378. * @param {?} changes
  1379. * @return {?}
  1380. */
  1381. function (changes) {
  1382. /** @type {?} */
  1383. var proxiedChange = changes['_matDialogClose'] || changes['_matDialogCloseResult'];
  1384. if (proxiedChange) {
  1385. this.dialogResult = proxiedChange.currentValue;
  1386. }
  1387. };
  1388. MatDialogClose.decorators = [
  1389. { type: core.Directive, args: [{
  1390. selector: '[mat-dialog-close], [matDialogClose]',
  1391. exportAs: 'matDialogClose',
  1392. host: {
  1393. '(click)': 'dialogRef.close(dialogResult)',
  1394. '[attr.aria-label]': 'ariaLabel || null',
  1395. 'type': 'button',
  1396. }
  1397. },] },
  1398. ];
  1399. /** @nocollapse */
  1400. MatDialogClose.ctorParameters = function () { return [
  1401. { type: MatDialogRef, decorators: [{ type: core.Optional }] },
  1402. { type: core.ElementRef },
  1403. { type: MatDialog }
  1404. ]; };
  1405. MatDialogClose.propDecorators = {
  1406. ariaLabel: [{ type: core.Input, args: ['aria-label',] }],
  1407. dialogResult: [{ type: core.Input, args: ['mat-dialog-close',] }],
  1408. _matDialogClose: [{ type: core.Input, args: ['matDialogClose',] }]
  1409. };
  1410. return MatDialogClose;
  1411. }());
  1412. /**
  1413. * Title of a dialog element. Stays fixed to the top of the dialog when scrolling.
  1414. */
  1415. var MatDialogTitle = /** @class */ (function () {
  1416. function MatDialogTitle(_dialogRef, _elementRef, _dialog) {
  1417. this._dialogRef = _dialogRef;
  1418. this._elementRef = _elementRef;
  1419. this._dialog = _dialog;
  1420. this.id = "mat-dialog-title-" + dialogElementUid++;
  1421. }
  1422. /**
  1423. * @return {?}
  1424. */
  1425. MatDialogTitle.prototype.ngOnInit = /**
  1426. * @return {?}
  1427. */
  1428. function () {
  1429. var _this = this;
  1430. if (!this._dialogRef) {
  1431. this._dialogRef = (/** @type {?} */ (getClosestDialog(this._elementRef, this._dialog.openDialogs)));
  1432. }
  1433. if (this._dialogRef) {
  1434. Promise.resolve().then((/**
  1435. * @return {?}
  1436. */
  1437. function () {
  1438. /** @type {?} */
  1439. var container = _this._dialogRef._containerInstance;
  1440. if (container && !container._ariaLabelledBy) {
  1441. container._ariaLabelledBy = _this.id;
  1442. }
  1443. }));
  1444. }
  1445. };
  1446. MatDialogTitle.decorators = [
  1447. { type: core.Directive, args: [{
  1448. selector: '[mat-dialog-title], [matDialogTitle]',
  1449. exportAs: 'matDialogTitle',
  1450. host: {
  1451. 'class': 'mat-dialog-title',
  1452. '[id]': 'id',
  1453. },
  1454. },] },
  1455. ];
  1456. /** @nocollapse */
  1457. MatDialogTitle.ctorParameters = function () { return [
  1458. { type: MatDialogRef, decorators: [{ type: core.Optional }] },
  1459. { type: core.ElementRef },
  1460. { type: MatDialog }
  1461. ]; };
  1462. MatDialogTitle.propDecorators = {
  1463. id: [{ type: core.Input }]
  1464. };
  1465. return MatDialogTitle;
  1466. }());
  1467. /**
  1468. * Scrollable content container of a dialog.
  1469. */
  1470. var MatDialogContent = /** @class */ (function () {
  1471. function MatDialogContent() {
  1472. }
  1473. MatDialogContent.decorators = [
  1474. { type: core.Directive, args: [{
  1475. selector: "[mat-dialog-content], mat-dialog-content, [matDialogContent]",
  1476. host: { 'class': 'mat-dialog-content' }
  1477. },] },
  1478. ];
  1479. return MatDialogContent;
  1480. }());
  1481. /**
  1482. * Container for the bottom action buttons in a dialog.
  1483. * Stays fixed to the bottom when scrolling.
  1484. */
  1485. var MatDialogActions = /** @class */ (function () {
  1486. function MatDialogActions() {
  1487. }
  1488. MatDialogActions.decorators = [
  1489. { type: core.Directive, args: [{
  1490. selector: "[mat-dialog-actions], mat-dialog-actions, [matDialogActions]",
  1491. host: { 'class': 'mat-dialog-actions' }
  1492. },] },
  1493. ];
  1494. return MatDialogActions;
  1495. }());
  1496. /**
  1497. * Finds the closest MatDialogRef to an element by looking at the DOM.
  1498. * @param {?} element Element relative to which to look for a dialog.
  1499. * @param {?} openDialogs References to the currently-open dialogs.
  1500. * @return {?}
  1501. */
  1502. function getClosestDialog(element, openDialogs) {
  1503. /** @type {?} */
  1504. var parent = element.nativeElement.parentElement;
  1505. while (parent && !parent.classList.contains('mat-dialog-container')) {
  1506. parent = parent.parentElement;
  1507. }
  1508. return parent ? openDialogs.find((/**
  1509. * @param {?} dialog
  1510. * @return {?}
  1511. */
  1512. function (dialog) { return dialog.id === (/** @type {?} */ (parent)).id; })) : null;
  1513. }
  1514. /**
  1515. * @fileoverview added by tsickle
  1516. * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
  1517. */
  1518. var MatDialogModule = /** @class */ (function () {
  1519. function MatDialogModule() {
  1520. }
  1521. MatDialogModule.decorators = [
  1522. { type: core.NgModule, args: [{
  1523. imports: [
  1524. common.CommonModule,
  1525. overlay.OverlayModule,
  1526. portal.PortalModule,
  1527. core$1.MatCommonModule,
  1528. ],
  1529. exports: [
  1530. MatDialogContainer,
  1531. MatDialogClose,
  1532. MatDialogTitle,
  1533. MatDialogContent,
  1534. MatDialogActions,
  1535. core$1.MatCommonModule,
  1536. ],
  1537. declarations: [
  1538. MatDialogContainer,
  1539. MatDialogClose,
  1540. MatDialogTitle,
  1541. MatDialogActions,
  1542. MatDialogContent,
  1543. ],
  1544. providers: [
  1545. MatDialog,
  1546. MAT_DIALOG_SCROLL_STRATEGY_PROVIDER,
  1547. ],
  1548. entryComponents: [MatDialogContainer],
  1549. },] },
  1550. ];
  1551. return MatDialogModule;
  1552. }());
  1553. exports.MatDialogModule = MatDialogModule;
  1554. exports.MAT_DIALOG_SCROLL_STRATEGY_FACTORY = MAT_DIALOG_SCROLL_STRATEGY_FACTORY;
  1555. exports.MAT_DIALOG_SCROLL_STRATEGY_PROVIDER_FACTORY = MAT_DIALOG_SCROLL_STRATEGY_PROVIDER_FACTORY;
  1556. exports.MAT_DIALOG_DATA = MAT_DIALOG_DATA;
  1557. exports.MAT_DIALOG_DEFAULT_OPTIONS = MAT_DIALOG_DEFAULT_OPTIONS;
  1558. exports.MAT_DIALOG_SCROLL_STRATEGY = MAT_DIALOG_SCROLL_STRATEGY;
  1559. exports.MAT_DIALOG_SCROLL_STRATEGY_PROVIDER = MAT_DIALOG_SCROLL_STRATEGY_PROVIDER;
  1560. exports.MatDialog = MatDialog;
  1561. exports.throwMatDialogContentAlreadyAttachedError = throwMatDialogContentAlreadyAttachedError;
  1562. exports.MatDialogContainer = MatDialogContainer;
  1563. exports.MatDialogClose = MatDialogClose;
  1564. exports.MatDialogTitle = MatDialogTitle;
  1565. exports.MatDialogContent = MatDialogContent;
  1566. exports.MatDialogActions = MatDialogActions;
  1567. exports.MatDialogConfig = MatDialogConfig;
  1568. exports.MatDialogRef = MatDialogRef;
  1569. exports.matDialogAnimations = matDialogAnimations;
  1570. Object.defineProperty(exports, '__esModule', { value: true });
  1571. })));
  1572. //# sourceMappingURL=material-dialog.umd.js.map