UNPKG

@angular/material

Version:
1,317 lines (1,310 loc) 65.3 kB
/** * @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 */ (function (global, factory) { typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@angular/animations'), require('@angular/cdk/a11y'), require('@angular/cdk/bidi'), require('@angular/cdk/coercion'), require('@angular/cdk/keycodes'), require('@angular/cdk/platform'), require('@angular/cdk/scrolling'), require('@angular/common'), require('@angular/core'), require('rxjs'), require('rxjs/operators'), require('@angular/platform-browser/animations'), require('@angular/material/core')) : typeof define === 'function' && define.amd ? define('@angular/material/sidenav', ['exports', '@angular/animations', '@angular/cdk/a11y', '@angular/cdk/bidi', '@angular/cdk/coercion', '@angular/cdk/keycodes', '@angular/cdk/platform', '@angular/cdk/scrolling', '@angular/common', '@angular/core', 'rxjs', 'rxjs/operators', '@angular/platform-browser/animations', '@angular/material/core'], factory) : (factory((global.ng = global.ng || {}, global.ng.material = global.ng.material || {}, global.ng.material.sidenav = {}),global.ng.animations,global.ng.cdk.a11y,global.ng.cdk.bidi,global.ng.cdk.coercion,global.ng.cdk.keycodes,global.ng.cdk.platform,global.ng.cdk.scrolling,global.ng.common,global.ng.core,global.rxjs,global.rxjs.operators,global.ng.platformBrowser.animations,global.ng.material.core)); }(this, (function (exports,animations,a11y,bidi,coercion,keycodes,platform,scrolling,common,core,rxjs,operators,animations$1,core$1) { 'use strict'; /*! ***************************************************************************** Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, MERCHANTABLITY OR NON-INFRINGEMENT. See the Apache Version 2.0 License for specific language governing permissions and limitations under the License. ***************************************************************************** */ /* global Reflect, Promise */ var extendStatics = function(d, b) { extendStatics = Object.setPrototypeOf || ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; return extendStatics(d, b); }; function __extends(d, b) { extendStatics(d, b); function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); } /** * @fileoverview added by tsickle * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ /** * Animations used by the Material drawers. * \@docs-private * @type {?} */ var matDrawerAnimations = { /** * Animation that slides a drawer in and out. */ transformDrawer: animations.trigger('transform', [ // We remove the `transform` here completely, rather than setting it to zero, because: // 1. Having a transform can cause elements with ripples or an animated // transform to shift around in Chrome with an RTL layout (see #10023). // 2. 3d transforms causes text to appear blurry on IE and Edge. animations.state('open, open-instant', animations.style({ 'transform': 'none', 'visibility': 'visible', })), animations.state('void', animations.style({ // Avoids the shadow showing up when closed in SSR. 'box-shadow': 'none', 'visibility': 'hidden', })), animations.transition('void => open-instant', animations.animate('0ms')), animations.transition('void <=> open, open-instant => void', animations.animate('400ms cubic-bezier(0.25, 0.8, 0.25, 1)')) ]) }; /** * @fileoverview added by tsickle * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ /** * Throws an exception when two MatDrawer are matching the same position. * \@docs-private * @param {?} position * @return {?} */ function throwMatDuplicatedDrawerError(position) { throw Error("A drawer was already declared for 'position=\"" + position + "\"'"); } /** * Configures whether drawers should use auto sizing by default. * @type {?} */ var MAT_DRAWER_DEFAULT_AUTOSIZE = new core.InjectionToken('MAT_DRAWER_DEFAULT_AUTOSIZE', { providedIn: 'root', factory: MAT_DRAWER_DEFAULT_AUTOSIZE_FACTORY, }); /** * \@docs-private * @return {?} */ function MAT_DRAWER_DEFAULT_AUTOSIZE_FACTORY() { return false; } var MatDrawerContent = /** @class */ (function (_super) { __extends(MatDrawerContent, _super); function MatDrawerContent(_changeDetectorRef, _container, elementRef, scrollDispatcher, ngZone) { var _this = _super.call(this, elementRef, scrollDispatcher, ngZone) || this; _this._changeDetectorRef = _changeDetectorRef; _this._container = _container; return _this; } /** * @return {?} */ MatDrawerContent.prototype.ngAfterContentInit = /** * @return {?} */ function () { var _this = this; this._container._contentMarginChanges.subscribe((/** * @return {?} */ function () { _this._changeDetectorRef.markForCheck(); })); }; MatDrawerContent.decorators = [ { type: core.Component, args: [{selector: 'mat-drawer-content', template: '<ng-content></ng-content>', host: { 'class': 'mat-drawer-content', '[style.margin-left.px]': '_container._contentMargins.left', '[style.margin-right.px]': '_container._contentMargins.right', }, changeDetection: core.ChangeDetectionStrategy.OnPush, encapsulation: core.ViewEncapsulation.None, },] }, ]; /** @nocollapse */ MatDrawerContent.ctorParameters = function () { return [ { type: core.ChangeDetectorRef }, { type: MatDrawerContainer, decorators: [{ type: core.Inject, args: [core.forwardRef((/** * @return {?} */ function () { return MatDrawerContainer; })),] }] }, { type: core.ElementRef }, { type: scrolling.ScrollDispatcher }, { type: core.NgZone } ]; }; return MatDrawerContent; }(scrolling.CdkScrollable)); /** * This component corresponds to a drawer that can be opened on the drawer container. */ var MatDrawer = /** @class */ (function () { function MatDrawer(_elementRef, _focusTrapFactory, _focusMonitor, _platform, _ngZone, _doc) { var _this = this; this._elementRef = _elementRef; this._focusTrapFactory = _focusTrapFactory; this._focusMonitor = _focusMonitor; this._platform = _platform; this._ngZone = _ngZone; this._doc = _doc; this._elementFocusedBeforeDrawerWasOpened = null; /** * Whether the drawer is initialized. Used for disabling the initial animation. */ this._enableAnimations = false; this._position = 'start'; this._mode = 'over'; this._disableClose = false; this._autoFocus = true; /** * Emits whenever the drawer has started animating. */ this._animationStarted = new rxjs.Subject(); /** * Emits whenever the drawer is done animating. */ this._animationEnd = new rxjs.Subject(); /** * Current state of the sidenav animation. */ // @HostBinding is used in the class as it is expected to be extended. Since @Component decorator // metadata is not inherited by child classes, instead the host binding data is defined in a way // that can be inherited. // tslint:disable:no-host-decorator-in-concrete this._animationState = 'void'; /** * Event emitted when the drawer open state is changed. */ this.openedChange = // Note this has to be async in order to avoid some issues with two-bindings (see #8872). new core.EventEmitter(/* isAsync */ true); /** * Emits when the component is destroyed. */ this._destroyed = new rxjs.Subject(); /** * Event emitted when the drawer's position changes. */ // tslint:disable-next-line:no-output-on-prefix this.onPositionChanged = new core.EventEmitter(); /** * An observable that emits when the drawer mode changes. This is used by the drawer container to * to know when to when the mode changes so it can adapt the margins on the content. */ this._modeChanged = new rxjs.Subject(); this._opened = false; this.openedChange.subscribe((/** * @param {?} opened * @return {?} */ function (opened) { if (opened) { if (_this._doc) { _this._elementFocusedBeforeDrawerWasOpened = (/** @type {?} */ (_this._doc.activeElement)); } if (_this._isFocusTrapEnabled && _this._focusTrap) { _this._trapFocus(); } } else { _this._restoreFocus(); } })); /** * Listen to `keydown` events outside the zone so that change detection is not run every * time a key is pressed. Instead we re-enter the zone only if the `ESC` key is pressed * and we don't have close disabled. */ this._ngZone.runOutsideAngular((/** * @return {?} */ function () { ((/** @type {?} */ (rxjs.fromEvent(_this._elementRef.nativeElement, 'keydown')))).pipe(operators.filter((/** * @param {?} event * @return {?} */ function (event) { return event.keyCode === keycodes.ESCAPE && !_this.disableClose && !keycodes.hasModifierKey(event); })), operators.takeUntil(_this._destroyed)).subscribe((/** * @param {?} event * @return {?} */ function (event) { return _this._ngZone.run((/** * @return {?} */ function () { _this.close(); event.stopPropagation(); event.preventDefault(); })); })); })); // We need a Subject with distinctUntilChanged, because the `done` event // fires twice on some browsers. See https://github.com/angular/angular/issues/24084 this._animationEnd.pipe(operators.distinctUntilChanged((/** * @param {?} x * @param {?} y * @return {?} */ function (x, y) { return x.fromState === y.fromState && x.toState === y.toState; }))).subscribe((/** * @param {?} event * @return {?} */ function (event) { var fromState = event.fromState, toState = event.toState; if ((toState.indexOf('open') === 0 && fromState === 'void') || (toState === 'void' && fromState.indexOf('open') === 0)) { _this.openedChange.emit(_this._opened); } })); } Object.defineProperty(MatDrawer.prototype, "position", { /** The side that the drawer is attached to. */ get: /** * The side that the drawer is attached to. * @return {?} */ function () { return this._position; }, set: /** * @param {?} value * @return {?} */ function (value) { // Make sure we have a valid value. value = value === 'end' ? 'end' : 'start'; if (value != this._position) { this._position = value; this.onPositionChanged.emit(); } }, enumerable: true, configurable: true }); Object.defineProperty(MatDrawer.prototype, "mode", { /** Mode of the drawer; one of 'over', 'push' or 'side'. */ get: /** * Mode of the drawer; one of 'over', 'push' or 'side'. * @return {?} */ function () { return this._mode; }, set: /** * @param {?} value * @return {?} */ function (value) { this._mode = value; this._updateFocusTrapState(); this._modeChanged.next(); }, enumerable: true, configurable: true }); Object.defineProperty(MatDrawer.prototype, "disableClose", { /** Whether the drawer can be closed with the escape key or by clicking on the backdrop. */ get: /** * Whether the drawer can be closed with the escape key or by clicking on the backdrop. * @return {?} */ function () { return this._disableClose; }, set: /** * @param {?} value * @return {?} */ function (value) { this._disableClose = coercion.coerceBooleanProperty(value); }, enumerable: true, configurable: true }); Object.defineProperty(MatDrawer.prototype, "autoFocus", { /** Whether the drawer should focus the first focusable element automatically when opened. */ get: /** * Whether the drawer should focus the first focusable element automatically when opened. * @return {?} */ function () { return this._autoFocus; }, set: /** * @param {?} value * @return {?} */ function (value) { this._autoFocus = coercion.coerceBooleanProperty(value); }, enumerable: true, configurable: true }); Object.defineProperty(MatDrawer.prototype, "_openedStream", { /** Event emitted when the drawer has been opened. */ get: /** * Event emitted when the drawer has been opened. * @return {?} */ function () { return this.openedChange.pipe(operators.filter((/** * @param {?} o * @return {?} */ function (o) { return o; })), operators.map((/** * @return {?} */ function () { }))); }, enumerable: true, configurable: true }); Object.defineProperty(MatDrawer.prototype, "openedStart", { /** Event emitted when the drawer has started opening. */ get: /** * Event emitted when the drawer has started opening. * @return {?} */ function () { return this._animationStarted.pipe(operators.filter((/** * @param {?} e * @return {?} */ function (e) { return e.fromState !== e.toState && e.toState.indexOf('open') === 0; })), operators.map((/** * @return {?} */ function () { }))); }, enumerable: true, configurable: true }); Object.defineProperty(MatDrawer.prototype, "_closedStream", { /** Event emitted when the drawer has been closed. */ get: /** * Event emitted when the drawer has been closed. * @return {?} */ function () { return this.openedChange.pipe(operators.filter((/** * @param {?} o * @return {?} */ function (o) { return !o; })), operators.map((/** * @return {?} */ function () { }))); }, enumerable: true, configurable: true }); Object.defineProperty(MatDrawer.prototype, "closedStart", { /** Event emitted when the drawer has started closing. */ get: /** * Event emitted when the drawer has started closing. * @return {?} */ function () { return this._animationStarted.pipe(operators.filter((/** * @param {?} e * @return {?} */ function (e) { return e.fromState !== e.toState && e.toState === 'void'; })), operators.map((/** * @return {?} */ function () { }))); }, enumerable: true, configurable: true }); Object.defineProperty(MatDrawer.prototype, "_isFocusTrapEnabled", { get: /** * @return {?} */ function () { // The focus trap is only enabled when the drawer is open in any mode other than side. return this.opened && this.mode !== 'side'; }, enumerable: true, configurable: true }); /** Traps focus inside the drawer. */ /** * Traps focus inside the drawer. * @private * @return {?} */ MatDrawer.prototype._trapFocus = /** * Traps focus inside the drawer. * @private * @return {?} */ function () { var _this = this; if (!this.autoFocus) { return; } this._focusTrap.focusInitialElementWhenReady().then((/** * @param {?} hasMovedFocus * @return {?} */ function (hasMovedFocus) { // If there were no focusable elements, focus the sidenav itself so the keyboard navigation // still works. We need to check that `focus` is a function due to Universal. if (!hasMovedFocus && typeof _this._elementRef.nativeElement.focus === 'function') { _this._elementRef.nativeElement.focus(); } })); }; /** * If focus is currently inside the drawer, restores it to where it was before the drawer * opened. */ /** * If focus is currently inside the drawer, restores it to where it was before the drawer * opened. * @private * @return {?} */ MatDrawer.prototype._restoreFocus = /** * If focus is currently inside the drawer, restores it to where it was before the drawer * opened. * @private * @return {?} */ function () { if (!this.autoFocus) { return; } /** @type {?} */ var activeEl = this._doc && this._doc.activeElement; if (activeEl && this._elementRef.nativeElement.contains(activeEl)) { if (this._elementFocusedBeforeDrawerWasOpened instanceof HTMLElement) { this._focusMonitor.focusVia(this._elementFocusedBeforeDrawerWasOpened, this._openedVia); } else { this._elementRef.nativeElement.blur(); } } this._elementFocusedBeforeDrawerWasOpened = null; this._openedVia = null; }; /** * @return {?} */ MatDrawer.prototype.ngAfterContentInit = /** * @return {?} */ function () { this._focusTrap = this._focusTrapFactory.create(this._elementRef.nativeElement); this._updateFocusTrapState(); }; /** * @return {?} */ MatDrawer.prototype.ngAfterContentChecked = /** * @return {?} */ function () { // Enable the animations after the lifecycle hooks have run, in order to avoid animating // drawers that are open by default. When we're on the server, we shouldn't enable the // animations, because we don't want the drawer to animate the first time the user sees // the page. if (this._platform.isBrowser) { this._enableAnimations = true; } }; /** * @return {?} */ MatDrawer.prototype.ngOnDestroy = /** * @return {?} */ function () { if (this._focusTrap) { this._focusTrap.destroy(); } this._animationStarted.complete(); this._animationEnd.complete(); this._modeChanged.complete(); this._destroyed.next(); this._destroyed.complete(); }; Object.defineProperty(MatDrawer.prototype, "opened", { /** * Whether the drawer is opened. We overload this because we trigger an event when it * starts or end. */ get: /** * Whether the drawer is opened. We overload this because we trigger an event when it * starts or end. * @return {?} */ function () { return this._opened; }, set: /** * @param {?} value * @return {?} */ function (value) { this.toggle(coercion.coerceBooleanProperty(value)); }, enumerable: true, configurable: true }); /** * Open the drawer. * @param openedVia Whether the drawer was opened by a key press, mouse click or programmatically. * Used for focus management after the sidenav is closed. */ /** * Open the drawer. * @param {?=} openedVia Whether the drawer was opened by a key press, mouse click or programmatically. * Used for focus management after the sidenav is closed. * @return {?} */ MatDrawer.prototype.open = /** * Open the drawer. * @param {?=} openedVia Whether the drawer was opened by a key press, mouse click or programmatically. * Used for focus management after the sidenav is closed. * @return {?} */ function (openedVia) { return this.toggle(true, openedVia); }; /** Close the drawer. */ /** * Close the drawer. * @return {?} */ MatDrawer.prototype.close = /** * Close the drawer. * @return {?} */ function () { return this.toggle(false); }; /** * Toggle this drawer. * @param isOpen Whether the drawer should be open. * @param openedVia Whether the drawer was opened by a key press, mouse click or programmatically. * Used for focus management after the sidenav is closed. */ /** * Toggle this drawer. * @param {?=} isOpen Whether the drawer should be open. * @param {?=} openedVia Whether the drawer was opened by a key press, mouse click or programmatically. * Used for focus management after the sidenav is closed. * @return {?} */ MatDrawer.prototype.toggle = /** * Toggle this drawer. * @param {?=} isOpen Whether the drawer should be open. * @param {?=} openedVia Whether the drawer was opened by a key press, mouse click or programmatically. * Used for focus management after the sidenav is closed. * @return {?} */ function (isOpen, openedVia) { var _this = this; if (isOpen === void 0) { isOpen = !this.opened; } if (openedVia === void 0) { openedVia = 'program'; } this._opened = isOpen; if (isOpen) { this._animationState = this._enableAnimations ? 'open' : 'open-instant'; this._openedVia = openedVia; } else { this._animationState = 'void'; this._restoreFocus(); } this._updateFocusTrapState(); return new Promise((/** * @param {?} resolve * @return {?} */ function (resolve) { _this.openedChange.pipe(operators.take(1)).subscribe((/** * @param {?} open * @return {?} */ function (open) { return resolve(open ? 'open' : 'close'); })); })); }; Object.defineProperty(MatDrawer.prototype, "_width", { get: /** * @return {?} */ function () { return this._elementRef.nativeElement ? (this._elementRef.nativeElement.offsetWidth || 0) : 0; }, enumerable: true, configurable: true }); /** Updates the enabled state of the focus trap. */ /** * Updates the enabled state of the focus trap. * @private * @return {?} */ MatDrawer.prototype._updateFocusTrapState = /** * Updates the enabled state of the focus trap. * @private * @return {?} */ function () { if (this._focusTrap) { this._focusTrap.enabled = this._isFocusTrapEnabled; } }; // We have to use a `HostListener` here in order to support both Ivy and ViewEngine. // In Ivy the `host` bindings will be merged when this class is extended, whereas in // ViewEngine they're overwritten. // TODO(crisbeto): we move this back into `host` once Ivy is turned on by default. // tslint:disable-next-line:no-host-decorator-in-concrete // We have to use a `HostListener` here in order to support both Ivy and ViewEngine. // In Ivy the `host` bindings will be merged when this class is extended, whereas in // ViewEngine they're overwritten. // TODO(crisbeto): we move this back into `host` once Ivy is turned on by default. // tslint:disable-next-line:no-host-decorator-in-concrete /** * @param {?} event * @return {?} */ MatDrawer.prototype._animationStartListener = // We have to use a `HostListener` here in order to support both Ivy and ViewEngine. // In Ivy the `host` bindings will be merged when this class is extended, whereas in // ViewEngine they're overwritten. // TODO(crisbeto): we move this back into `host` once Ivy is turned on by default. // tslint:disable-next-line:no-host-decorator-in-concrete /** * @param {?} event * @return {?} */ function (event) { this._animationStarted.next(event); }; // We have to use a `HostListener` here in order to support both Ivy and ViewEngine. // In Ivy the `host` bindings will be merged when this class is extended, whereas in // ViewEngine they're overwritten. // TODO(crisbeto): we move this back into `host` once Ivy is turned on by default. // tslint:disable-next-line:no-host-decorator-in-concrete // We have to use a `HostListener` here in order to support both Ivy and ViewEngine. // In Ivy the `host` bindings will be merged when this class is extended, whereas in // ViewEngine they're overwritten. // TODO(crisbeto): we move this back into `host` once Ivy is turned on by default. // tslint:disable-next-line:no-host-decorator-in-concrete /** * @param {?} event * @return {?} */ MatDrawer.prototype._animationDoneListener = // We have to use a `HostListener` here in order to support both Ivy and ViewEngine. // In Ivy the `host` bindings will be merged when this class is extended, whereas in // ViewEngine they're overwritten. // TODO(crisbeto): we move this back into `host` once Ivy is turned on by default. // tslint:disable-next-line:no-host-decorator-in-concrete /** * @param {?} event * @return {?} */ function (event) { this._animationEnd.next(event); }; MatDrawer.decorators = [ { type: core.Component, args: [{selector: 'mat-drawer', exportAs: 'matDrawer', template: "<div class=\"mat-drawer-inner-container\"><ng-content></ng-content></div>", animations: [matDrawerAnimations.transformDrawer], host: { 'class': 'mat-drawer', // must prevent the browser from aligning text based on value '[attr.align]': 'null', '[class.mat-drawer-end]': 'position === "end"', '[class.mat-drawer-over]': 'mode === "over"', '[class.mat-drawer-push]': 'mode === "push"', '[class.mat-drawer-side]': 'mode === "side"', '[class.mat-drawer-opened]': 'opened', 'tabIndex': '-1', }, changeDetection: core.ChangeDetectionStrategy.OnPush, encapsulation: core.ViewEncapsulation.None, },] }, ]; /** @nocollapse */ MatDrawer.ctorParameters = function () { return [ { type: core.ElementRef }, { type: a11y.FocusTrapFactory }, { type: a11y.FocusMonitor }, { type: platform.Platform }, { type: core.NgZone }, { type: undefined, decorators: [{ type: core.Optional }, { type: core.Inject, args: [common.DOCUMENT,] }] } ]; }; MatDrawer.propDecorators = { position: [{ type: core.Input }], mode: [{ type: core.Input }], disableClose: [{ type: core.Input }], autoFocus: [{ type: core.Input }], _animationState: [{ type: core.HostBinding, args: ['@transform',] }], openedChange: [{ type: core.Output }], _openedStream: [{ type: core.Output, args: ['opened',] }], openedStart: [{ type: core.Output }], _closedStream: [{ type: core.Output, args: ['closed',] }], closedStart: [{ type: core.Output }], onPositionChanged: [{ type: core.Output, args: ['positionChanged',] }], opened: [{ type: core.Input }], _animationStartListener: [{ type: core.HostListener, args: ['@transform.start', ['$event'],] }], _animationDoneListener: [{ type: core.HostListener, args: ['@transform.done', ['$event'],] }] }; return MatDrawer; }()); /** * `<mat-drawer-container>` component. * * This is the parent component to one or two `<mat-drawer>`s that validates the state internally * and coordinates the backdrop and content styling. */ var MatDrawerContainer = /** @class */ (function () { function MatDrawerContainer(_dir, _element, _ngZone, _changeDetectorRef, viewportRuler, defaultAutosize, _animationMode) { var _this = this; if (defaultAutosize === void 0) { defaultAutosize = false; } this._dir = _dir; this._element = _element; this._ngZone = _ngZone; this._changeDetectorRef = _changeDetectorRef; this._animationMode = _animationMode; /** * Event emitted when the drawer backdrop is clicked. */ this.backdropClick = new core.EventEmitter(); /** * Emits when the component is destroyed. */ this._destroyed = new rxjs.Subject(); /** * Emits on every ngDoCheck. Used for debouncing reflows. */ this._doCheckSubject = new rxjs.Subject(); /** * Margins to be applied to the content. These are used to push / shrink the drawer content when a * drawer is open. We use margin rather than transform even for push mode because transform breaks * fixed position elements inside of the transformed element. */ this._contentMargins = { left: null, right: null }; this._contentMarginChanges = new rxjs.Subject(); // If a `Dir` directive exists up the tree, listen direction changes // and update the left/right properties to point to the proper start/end. if (_dir) { _dir.change.pipe(operators.takeUntil(this._destroyed)).subscribe((/** * @return {?} */ function () { _this._validateDrawers(); _this.updateContentMargins(); })); } // Since the minimum width of the sidenav depends on the viewport width, // we need to recompute the margins if the viewport changes. viewportRuler.change() .pipe(operators.takeUntil(this._destroyed)) .subscribe((/** * @return {?} */ function () { return _this.updateContentMargins(); })); this._autosize = defaultAutosize; } Object.defineProperty(MatDrawerContainer.prototype, "start", { /** The drawer child with the `start` position. */ get: /** * The drawer child with the `start` position. * @return {?} */ function () { return this._start; }, enumerable: true, configurable: true }); Object.defineProperty(MatDrawerContainer.prototype, "end", { /** The drawer child with the `end` position. */ get: /** * The drawer child with the `end` position. * @return {?} */ function () { return this._end; }, enumerable: true, configurable: true }); Object.defineProperty(MatDrawerContainer.prototype, "autosize", { /** * Whether to automatically resize the container whenever * the size of any of its drawers changes. * * **Use at your own risk!** Enabling this option can cause layout thrashing by measuring * the drawers on every change detection cycle. Can be configured globally via the * `MAT_DRAWER_DEFAULT_AUTOSIZE` token. */ get: /** * Whether to automatically resize the container whenever * the size of any of its drawers changes. * * **Use at your own risk!** Enabling this option can cause layout thrashing by measuring * the drawers on every change detection cycle. Can be configured globally via the * `MAT_DRAWER_DEFAULT_AUTOSIZE` token. * @return {?} */ function () { return this._autosize; }, set: /** * @param {?} value * @return {?} */ function (value) { this._autosize = coercion.coerceBooleanProperty(value); }, enumerable: true, configurable: true }); Object.defineProperty(MatDrawerContainer.prototype, "hasBackdrop", { /** * Whether the drawer container should have a backdrop while one of the sidenavs is open. * If explicitly set to `true`, the backdrop will be enabled for drawers in the `side` * mode as well. */ get: /** * Whether the drawer container should have a backdrop while one of the sidenavs is open. * If explicitly set to `true`, the backdrop will be enabled for drawers in the `side` * mode as well. * @return {?} */ function () { if (this._backdropOverride == null) { return !this._start || this._start.mode !== 'side' || !this._end || this._end.mode !== 'side'; } return this._backdropOverride; }, set: /** * @param {?} value * @return {?} */ function (value) { this._backdropOverride = value == null ? null : coercion.coerceBooleanProperty(value); }, enumerable: true, configurable: true }); Object.defineProperty(MatDrawerContainer.prototype, "scrollable", { /** Reference to the CdkScrollable instance that wraps the scrollable content. */ get: /** * Reference to the CdkScrollable instance that wraps the scrollable content. * @return {?} */ function () { return this._userContent || this._content; }, enumerable: true, configurable: true }); /** * @return {?} */ MatDrawerContainer.prototype.ngAfterContentInit = /** * @return {?} */ function () { var _this = this; this._drawers.changes.pipe(operators.startWith(null)).subscribe((/** * @return {?} */ function () { _this._validateDrawers(); _this._drawers.forEach((/** * @param {?} drawer * @return {?} */ function (drawer) { _this._watchDrawerToggle(drawer); _this._watchDrawerPosition(drawer); _this._watchDrawerMode(drawer); })); if (!_this._drawers.length || _this._isDrawerOpen(_this._start) || _this._isDrawerOpen(_this._end)) { _this.updateContentMargins(); } _this._changeDetectorRef.markForCheck(); })); this._doCheckSubject.pipe(operators.debounceTime(10), // Arbitrary debounce time, less than a frame at 60fps operators.takeUntil(this._destroyed)).subscribe((/** * @return {?} */ function () { return _this.updateContentMargins(); })); }; /** * @return {?} */ MatDrawerContainer.prototype.ngOnDestroy = /** * @return {?} */ function () { this._contentMarginChanges.complete(); this._doCheckSubject.complete(); this._destroyed.next(); this._destroyed.complete(); }; /** Calls `open` of both start and end drawers */ /** * Calls `open` of both start and end drawers * @return {?} */ MatDrawerContainer.prototype.open = /** * Calls `open` of both start and end drawers * @return {?} */ function () { this._drawers.forEach((/** * @param {?} drawer * @return {?} */ function (drawer) { return drawer.open(); })); }; /** Calls `close` of both start and end drawers */ /** * Calls `close` of both start and end drawers * @return {?} */ MatDrawerContainer.prototype.close = /** * Calls `close` of both start and end drawers * @return {?} */ function () { this._drawers.forEach((/** * @param {?} drawer * @return {?} */ function (drawer) { return drawer.close(); })); }; /** * Recalculates and updates the inline styles for the content. Note that this should be used * sparingly, because it causes a reflow. */ /** * Recalculates and updates the inline styles for the content. Note that this should be used * sparingly, because it causes a reflow. * @return {?} */ MatDrawerContainer.prototype.updateContentMargins = /** * Recalculates and updates the inline styles for the content. Note that this should be used * sparingly, because it causes a reflow. * @return {?} */ function () { var _this = this; // 1. For drawers in `over` mode, they don't affect the content. // 2. For drawers in `side` mode they should shrink the content. We do this by adding to the // left margin (for left drawer) or right margin (for right the drawer). // 3. For drawers in `push` mode the should shift the content without resizing it. We do this by // adding to the left or right margin and simultaneously subtracting the same amount of // margin from the other side. /** @type {?} */ var left = 0; /** @type {?} */ var right = 0; if (this._left && this._left.opened) { if (this._left.mode == 'side') { left += this._left._width; } else if (this._left.mode == 'push') { /** @type {?} */ var width = this._left._width; left += width; right -= width; } } if (this._right && this._right.opened) { if (this._right.mode == 'side') { right += this._right._width; } else if (this._right.mode == 'push') { /** @type {?} */ var width = this._right._width; right += width; left -= width; } } // If either `right` or `left` is zero, don't set a style to the element. This // allows users to specify a custom size via CSS class in SSR scenarios where the // measured widths will always be zero. Note that we reset to `null` here, rather // than below, in order to ensure that the types in the `if` below are consistent. left = left || (/** @type {?} */ (null)); right = right || (/** @type {?} */ (null)); if (left !== this._contentMargins.left || right !== this._contentMargins.right) { this._contentMargins = { left: left, right: right }; // Pull back into the NgZone since in some cases we could be outside. We need to be careful // to do it only when something changed, otherwise we can end up hitting the zone too often. this._ngZone.run((/** * @return {?} */ function () { return _this._contentMarginChanges.next(_this._contentMargins); })); } }; /** * @return {?} */ MatDrawerContainer.prototype.ngDoCheck = /** * @return {?} */ function () { var _this = this; // If users opted into autosizing, do a check every change detection cycle. if (this._autosize && this._isPushed()) { // Run outside the NgZone, otherwise the debouncer will throw us into an infinite loop. this._ngZone.runOutsideAngular((/** * @return {?} */ function () { return _this._doCheckSubject.next(); })); } }; /** * Subscribes to drawer events in order to set a class on the main container element when the * drawer is open and the backdrop is visible. This ensures any overflow on the container element * is properly hidden. */ /** * Subscribes to drawer events in order to set a class on the main container element when the * drawer is open and the backdrop is visible. This ensures any overflow on the container element * is properly hidden. * @private * @param {?} drawer * @return {?} */ MatDrawerContainer.prototype._watchDrawerToggle = /** * Subscribes to drawer events in order to set a class on the main container element when the * drawer is open and the backdrop is visible. This ensures any overflow on the container element * is properly hidden. * @private * @param {?} drawer * @return {?} */ function (drawer) { var _this = this; drawer._animationStarted.pipe(operators.filter((/** * @param {?} event * @return {?} */ function (event) { return event.fromState !== event.toState; })), operators.takeUntil(this._drawers.changes)) .subscribe((/** * @param {?} event * @return {?} */ function (event) { // Set the transition class on the container so that the animations occur. This should not // be set initially because animations should only be triggered via a change in state. if (event.toState !== 'open-instant' && _this._animationMode !== 'NoopAnimations') { _this._element.nativeElement.classList.add('mat-drawer-transition'); } _this.updateContentMargins(); _this._changeDetectorRef.markForCheck(); })); if (drawer.mode !== 'side') { drawer.openedChange.pipe(operators.takeUntil(this._drawers.changes)).subscribe((/** * @return {?} */ function () { return _this._setContainerClass(drawer.opened); })); } }; /** * Subscribes to drawer onPositionChanged event in order to * re-validate drawers when the position changes. */ /** * Subscribes to drawer onPositionChanged event in order to * re-validate drawers when the position changes. * @private * @param {?} drawer * @return {?} */ MatDrawerContainer.prototype._watchDrawerPosition = /** * Subscribes to drawer onPositionChanged event in order to * re-validate drawers when the position changes. * @private * @param {?} drawer * @return {?} */ function (drawer) { var _this = this; if (!drawer) { return; } // NOTE: We need to wait for the microtask queue to be empty before validating, // since both drawers may be swapping positions at the same time. drawer.onPositionChanged.pipe(operators.takeUntil(this._drawers.changes)).subscribe((/** * @return {?} */ function () { _this._ngZone.onMicrotaskEmpty.asObservable().pipe(operators.take(1)).subscribe((/** * @return {?} */ function () { _this._validateDrawers(); })); })); }; /** Subscribes to changes in drawer mode so we can run change detection. */ /** * Subscribes to changes in drawer mode so we can run change detection. * @private * @param {?} drawer * @return {?} */ MatDrawerContainer.prototype._watchDrawerMode = /** * Subscribes to changes in drawer mode so we can run change detection. * @private * @param {?} drawer * @return {?} */ function (drawer) { var _this = this; if (drawer) { drawer._modeChanged.pipe(operators.takeUntil(rxjs.merge(this._drawers.changes, this._destroyed))) .subscribe((/** * @return {?} */ function () { _this.updateContentMargins(); _this._changeDetectorRef.markForCheck(); })); } }; /** Toggles the 'mat-drawer-opened' class on the main 'mat-drawer-container' element. */ /** * Toggles the 'mat-drawer-opened' class on the main 'mat-drawer-container' element. * @private * @param {?} isAdd * @return {?} */ MatDrawerContainer.prototype._setContainerClass = /** * Toggles the 'mat-drawer-opened' class on the main 'mat-drawer-container' element. * @private * @param {?} isAdd * @return {?} */ function (isAdd) { /** @type {?} */ var classList = this._element.nativeElement.classList; /** @type {?} */ var className = 'mat-drawer-container-has-open'; if (isAdd) { classList.add(className); } else { classList.remove(className); } }; /** Validate the state of the drawer children components. */ /** * Validate the state of the drawer children components. * @private * @return {?} */ MatDrawerContainer.prototype._validateDrawers = /** * Validate the state of the drawer children components. * @private * @return {?} */ function () { var _this = this; this._start = this._end = null; // Ensure that we have at most one start and one end drawer. this._drawers.forEach((/** * @param {?} drawer * @return {?} */ function (drawer) { if (drawer.position == 'end') { if (_this._end != null) { throwMatDuplicatedDrawerError('end'); } _this._end = drawer; } else { if (_this._start != null) { throwMatDuplicatedDrawerError('start'); } _this._start = drawer; } })); this._right = this._left = null; // Detect if we're LTR or RTL. if (this._dir && this._dir.value === 'rtl') { this._left = this._end; this._right = this._start; } else { this._left = this._start; this._right = this._end; } }; /** Whether the container is being pushed to the side by one of the drawers. */ /** * Whether the container is being pushed to the side by one of the drawers. * @private * @return {?} */ MatDrawerContainer.prototype._isPushed = /** * Whether the container is being pushed to the side by one of the drawers. * @private * @return {?} */ function () { return (this._isDrawerOpen(this._start) && this._start.mode != 'over') || (this._isDrawerOpen(this._end) && this._end.mode != 'over'); }; /** * @return {?} */ MatDrawerContainer.prototype._onBackdropClicked = /** * @return {?} */ function () { this.backdropClick.emit(); this._closeModalDrawer(); }; /** * @return {?} */ MatDrawerContainer.prototype._closeModalDrawer = /** * @return {?} */ function () { var _this = this; // Close all open drawers where closing is not disabled and the mode is not `side`. [this._start, this._end] .filter((/** * @param {?} drawer * @return {?} */ function (drawer) { return drawer && !drawer.disableClose && _this._canHaveBackdrop(drawer); })) .forEach((/** * @param {?} drawer * @return {?} */ function (drawer) { return (/** @type {?} */ (drawer)).close(); })); }; /** * @return {?} */ MatDrawerContainer.prototype._isShowingBackdrop = /** * @return {?} */ function () { return (this._isDrawerOpen(this._start) && this._canHaveBackdrop(this._start)) || (this._isDrawerOpen(this._end) && this._canHaveBackdrop(this._end)); }; /** * @private * @param {?} drawer * @return {?} */ MatDrawerContainer.prototype._canHaveBackdrop = /** * @private * @param {?} drawer * @return {?} */ function (drawer) { return drawer.mode !== 'side' || !!this._backdropOverride; }; /** * @private * @param {?} drawer * @return {?} */ MatDrawerContainer.prototype._isDrawer