| /** |
| * @license |
| * Copyright Google LLC All Rights Reserved. |
| * |
| * Use of this source code is governed by an MIT-style license that can be |
| * found in the LICENSE file at https://angular.io/license |
| */ |
| import { animate, state, style, transition, trigger } from '@angular/animations'; |
| import { FocusMonitor, FocusTrapFactory } from '@angular/cdk/a11y'; |
| import { Directionality } from '@angular/cdk/bidi'; |
| import { coerceBooleanProperty, coerceNumberProperty } from '@angular/cdk/coercion'; |
| import { ESCAPE, hasModifierKey } from '@angular/cdk/keycodes'; |
| import { Platform, PlatformModule } from '@angular/cdk/platform'; |
| import { CdkScrollable, ScrollDispatcher, ViewportRuler, ScrollingModule } from '@angular/cdk/scrolling'; |
| import { DOCUMENT, CommonModule } from '@angular/common'; |
| import { ChangeDetectionStrategy, ChangeDetectorRef, Component, ContentChild, ContentChildren, ElementRef, EventEmitter, forwardRef, Inject, InjectionToken, Input, NgZone, Optional, Output, ViewChild, ViewEncapsulation, HostListener, HostBinding, NgModule } from '@angular/core'; |
| import { fromEvent, merge, Subject } from 'rxjs'; |
| import { debounceTime, filter, map, startWith, take, takeUntil, distinctUntilChanged } from 'rxjs/operators'; |
| import { ANIMATION_MODULE_TYPE } from '@angular/platform-browser/animations'; |
| import { MatCommonModule } from '@angular/material/core'; |
| |
| /** |
| * @fileoverview added by tsickle |
| * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc |
| */ |
| /** |
| * Animations used by the Material drawers. |
| * \@docs-private |
| * @type {?} |
| */ |
| const matDrawerAnimations = { |
| /** |
| * Animation that slides a drawer in and out. |
| */ |
| transformDrawer: 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. |
| state('open, open-instant', style({ |
| 'transform': 'none', |
| 'visibility': 'visible', |
| })), |
| state('void', style({ |
| // Avoids the shadow showing up when closed in SSR. |
| 'box-shadow': 'none', |
| 'visibility': 'hidden', |
| })), |
| transition('void => open-instant', animate('0ms')), |
| transition('void <=> open, open-instant => void', 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 {?} |
| */ |
| const MAT_DRAWER_DEFAULT_AUTOSIZE = new InjectionToken('MAT_DRAWER_DEFAULT_AUTOSIZE', { |
| providedIn: 'root', |
| factory: MAT_DRAWER_DEFAULT_AUTOSIZE_FACTORY, |
| }); |
| /** |
| * \@docs-private |
| * @return {?} |
| */ |
| function MAT_DRAWER_DEFAULT_AUTOSIZE_FACTORY() { |
| return false; |
| } |
| class MatDrawerContent extends CdkScrollable { |
| /** |
| * @param {?} _changeDetectorRef |
| * @param {?} _container |
| * @param {?} elementRef |
| * @param {?} scrollDispatcher |
| * @param {?} ngZone |
| */ |
| constructor(_changeDetectorRef, _container, elementRef, scrollDispatcher, ngZone) { |
| super(elementRef, scrollDispatcher, ngZone); |
| this._changeDetectorRef = _changeDetectorRef; |
| this._container = _container; |
| } |
| /** |
| * @return {?} |
| */ |
| ngAfterContentInit() { |
| this._container._contentMarginChanges.subscribe((/** |
| * @return {?} |
| */ |
| () => { |
| this._changeDetectorRef.markForCheck(); |
| })); |
| } |
| } |
| MatDrawerContent.decorators = [ |
| { type: 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: ChangeDetectionStrategy.OnPush, |
| encapsulation: ViewEncapsulation.None, |
| },] }, |
| ]; |
| /** @nocollapse */ |
| MatDrawerContent.ctorParameters = () => [ |
| { type: ChangeDetectorRef }, |
| { type: MatDrawerContainer, decorators: [{ type: Inject, args: [forwardRef((/** |
| * @return {?} |
| */ |
| () => MatDrawerContainer)),] }] }, |
| { type: ElementRef }, |
| { type: ScrollDispatcher }, |
| { type: NgZone } |
| ]; |
| /** |
| * This component corresponds to a drawer that can be opened on the drawer container. |
| */ |
| class MatDrawer { |
| /** |
| * @param {?} _elementRef |
| * @param {?} _focusTrapFactory |
| * @param {?} _focusMonitor |
| * @param {?} _platform |
| * @param {?} _ngZone |
| * @param {?} _doc |
| */ |
| constructor(_elementRef, _focusTrapFactory, _focusMonitor, _platform, _ngZone, _doc) { |
| 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 Subject(); |
| /** |
| * Emits whenever the drawer is done animating. |
| */ |
| this._animationEnd = new 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 EventEmitter(/* isAsync */ true); |
| /** |
| * Emits when the component is destroyed. |
| */ |
| this._destroyed = new Subject(); |
| /** |
| * Event emitted when the drawer's position changes. |
| */ |
| // tslint:disable-next-line:no-output-on-prefix |
| this.onPositionChanged = new 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 Subject(); |
| this._opened = false; |
| this.openedChange.subscribe((/** |
| * @param {?} opened |
| * @return {?} |
| */ |
| (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 {?} |
| */ |
| () => { |
| ((/** @type {?} */ (fromEvent(this._elementRef.nativeElement, 'keydown')))).pipe(filter((/** |
| * @param {?} event |
| * @return {?} |
| */ |
| event => { |
| return event.keyCode === ESCAPE && !this.disableClose && !hasModifierKey(event); |
| })), takeUntil(this._destroyed)).subscribe((/** |
| * @param {?} event |
| * @return {?} |
| */ |
| event => this._ngZone.run((/** |
| * @return {?} |
| */ |
| () => { |
| 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(distinctUntilChanged((/** |
| * @param {?} x |
| * @param {?} y |
| * @return {?} |
| */ |
| (x, y) => { |
| return x.fromState === y.fromState && x.toState === y.toState; |
| }))).subscribe((/** |
| * @param {?} event |
| * @return {?} |
| */ |
| (event) => { |
| const { fromState, toState } = event; |
| if ((toState.indexOf('open') === 0 && fromState === 'void') || |
| (toState === 'void' && fromState.indexOf('open') === 0)) { |
| this.openedChange.emit(this._opened); |
| } |
| })); |
| } |
| /** |
| * The side that the drawer is attached to. |
| * @return {?} |
| */ |
| get position() { return this._position; } |
| /** |
| * @param {?} value |
| * @return {?} |
| */ |
| set position(value) { |
| // Make sure we have a valid value. |
| value = value === 'end' ? 'end' : 'start'; |
| if (value != this._position) { |
| this._position = value; |
| this.onPositionChanged.emit(); |
| } |
| } |
| /** |
| * Mode of the drawer; one of 'over', 'push' or 'side'. |
| * @return {?} |
| */ |
| get mode() { return this._mode; } |
| /** |
| * @param {?} value |
| * @return {?} |
| */ |
| set mode(value) { |
| this._mode = value; |
| this._modeChanged.next(); |
| } |
| /** |
| * Whether the drawer can be closed with the escape key or by clicking on the backdrop. |
| * @return {?} |
| */ |
| get disableClose() { return this._disableClose; } |
| /** |
| * @param {?} value |
| * @return {?} |
| */ |
| set disableClose(value) { this._disableClose = coerceBooleanProperty(value); } |
| /** |
| * Whether the drawer should focus the first focusable element automatically when opened. |
| * @return {?} |
| */ |
| get autoFocus() { return this._autoFocus; } |
| /** |
| * @param {?} value |
| * @return {?} |
| */ |
| set autoFocus(value) { this._autoFocus = coerceBooleanProperty(value); } |
| /** |
| * Event emitted when the drawer has been opened. |
| * @return {?} |
| */ |
| get _openedStream() { |
| return this.openedChange.pipe(filter((/** |
| * @param {?} o |
| * @return {?} |
| */ |
| o => o)), map((/** |
| * @return {?} |
| */ |
| () => { }))); |
| } |
| /** |
| * Event emitted when the drawer has started opening. |
| * @return {?} |
| */ |
| get openedStart() { |
| return this._animationStarted.pipe(filter((/** |
| * @param {?} e |
| * @return {?} |
| */ |
| e => e.fromState !== e.toState && e.toState.indexOf('open') === 0)), map((/** |
| * @return {?} |
| */ |
| () => { }))); |
| } |
| /** |
| * Event emitted when the drawer has been closed. |
| * @return {?} |
| */ |
| get _closedStream() { |
| return this.openedChange.pipe(filter((/** |
| * @param {?} o |
| * @return {?} |
| */ |
| o => !o)), map((/** |
| * @return {?} |
| */ |
| () => { }))); |
| } |
| /** |
| * Event emitted when the drawer has started closing. |
| * @return {?} |
| */ |
| get closedStart() { |
| return this._animationStarted.pipe(filter((/** |
| * @param {?} e |
| * @return {?} |
| */ |
| e => e.fromState !== e.toState && e.toState === 'void')), map((/** |
| * @return {?} |
| */ |
| () => { }))); |
| } |
| /** |
| * @return {?} |
| */ |
| get _isFocusTrapEnabled() { |
| // The focus trap is only enabled when the drawer is open in any mode other than side. |
| return this.opened && this.mode !== 'side'; |
| } |
| /** |
| * Traps focus inside the drawer. |
| * @private |
| * @return {?} |
| */ |
| _trapFocus() { |
| if (!this.autoFocus) { |
| return; |
| } |
| this._focusTrap.focusInitialElementWhenReady().then((/** |
| * @param {?} hasMovedFocus |
| * @return {?} |
| */ |
| 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. |
| * @private |
| * @return {?} |
| */ |
| _restoreFocus() { |
| if (!this.autoFocus) { |
| return; |
| } |
| /** @type {?} */ |
| const 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 {?} |
| */ |
| ngAfterContentInit() { |
| this._focusTrap = this._focusTrapFactory.create(this._elementRef.nativeElement); |
| this._focusTrap.enabled = this._isFocusTrapEnabled; |
| } |
| /** |
| * @return {?} |
| */ |
| ngAfterContentChecked() { |
| // 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 {?} |
| */ |
| ngOnDestroy() { |
| if (this._focusTrap) { |
| this._focusTrap.destroy(); |
| } |
| this._animationStarted.complete(); |
| this._animationEnd.complete(); |
| this._modeChanged.complete(); |
| this._destroyed.next(); |
| this._destroyed.complete(); |
| } |
| /** |
| * Whether the drawer is opened. We overload this because we trigger an event when it |
| * starts or end. |
| * @return {?} |
| */ |
| get opened() { return this._opened; } |
| /** |
| * @param {?} value |
| * @return {?} |
| */ |
| set opened(value) { this.toggle(coerceBooleanProperty(value)); } |
| /** |
| * 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 {?} |
| */ |
| open(openedVia) { |
| return this.toggle(true, openedVia); |
| } |
| /** |
| * Close the drawer. |
| * @return {?} |
| */ |
| close() { |
| 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. |
| * @return {?} |
| */ |
| toggle(isOpen = !this.opened, openedVia = 'program') { |
| this._opened = isOpen; |
| if (isOpen) { |
| this._animationState = this._enableAnimations ? 'open' : 'open-instant'; |
| this._openedVia = openedVia; |
| } |
| else { |
| this._animationState = 'void'; |
| this._restoreFocus(); |
| } |
| if (this._focusTrap) { |
| this._focusTrap.enabled = this._isFocusTrapEnabled; |
| } |
| return new Promise((/** |
| * @param {?} resolve |
| * @return {?} |
| */ |
| resolve => { |
| this.openedChange.pipe(take(1)).subscribe((/** |
| * @param {?} open |
| * @return {?} |
| */ |
| open => resolve(open ? 'open' : 'close'))); |
| })); |
| } |
| /** |
| * @return {?} |
| */ |
| get _width() { |
| return this._elementRef.nativeElement ? (this._elementRef.nativeElement.offsetWidth || 0) : 0; |
| } |
| // 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 overwritte. |
| // 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 {?} |
| */ |
| _animationStartListener(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 overwritte. |
| // 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 {?} |
| */ |
| _animationDoneListener(event) { |
| this._animationEnd.next(event); |
| } |
| } |
| MatDrawer.decorators = [ |
| { type: 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"', |
| 'tabIndex': '-1', |
| }, |
| changeDetection: ChangeDetectionStrategy.OnPush, |
| encapsulation: ViewEncapsulation.None, |
| },] }, |
| ]; |
| /** @nocollapse */ |
| MatDrawer.ctorParameters = () => [ |
| { type: ElementRef }, |
| { type: FocusTrapFactory }, |
| { type: FocusMonitor }, |
| { type: Platform }, |
| { type: NgZone }, |
| { type: undefined, decorators: [{ type: Optional }, { type: Inject, args: [DOCUMENT,] }] } |
| ]; |
| MatDrawer.propDecorators = { |
| position: [{ type: Input }], |
| mode: [{ type: Input }], |
| disableClose: [{ type: Input }], |
| autoFocus: [{ type: Input }], |
| _animationState: [{ type: HostBinding, args: ['@transform',] }], |
| openedChange: [{ type: Output }], |
| _openedStream: [{ type: Output, args: ['opened',] }], |
| openedStart: [{ type: Output }], |
| _closedStream: [{ type: Output, args: ['closed',] }], |
| closedStart: [{ type: Output }], |
| onPositionChanged: [{ type: Output, args: ['positionChanged',] }], |
| opened: [{ type: Input }], |
| _animationStartListener: [{ type: HostListener, args: ['@transform.start', ['$event'],] }], |
| _animationDoneListener: [{ type: HostListener, args: ['@transform.done', ['$event'],] }] |
| }; |
| /** |
| * `<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. |
| */ |
| class MatDrawerContainer { |
| /** |
| * @param {?} _dir |
| * @param {?} _element |
| * @param {?} _ngZone |
| * @param {?} _changeDetectorRef |
| * @param {?} viewportRuler |
| * @param {?=} defaultAutosize |
| * @param {?=} _animationMode |
| */ |
| constructor(_dir, _element, _ngZone, _changeDetectorRef, viewportRuler, defaultAutosize = false, _animationMode) { |
| 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 EventEmitter(); |
| /** |
| * Emits when the component is destroyed. |
| */ |
| this._destroyed = new Subject(); |
| /** |
| * Emits on every ngDoCheck. Used for debouncing reflows. |
| */ |
| this._doCheckSubject = new 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 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(takeUntil(this._destroyed)).subscribe((/** |
| * @return {?} |
| */ |
| () => { |
| 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(takeUntil(this._destroyed)) |
| .subscribe((/** |
| * @return {?} |
| */ |
| () => this.updateContentMargins())); |
| this._autosize = defaultAutosize; |
| } |
| /** |
| * The drawer child with the `start` position. |
| * @return {?} |
| */ |
| get start() { return this._start; } |
| /** |
| * The drawer child with the `end` position. |
| * @return {?} |
| */ |
| get end() { return this._end; } |
| /** |
| * 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 {?} |
| */ |
| get autosize() { return this._autosize; } |
| /** |
| * @param {?} value |
| * @return {?} |
| */ |
| set autosize(value) { this._autosize = coerceBooleanProperty(value); } |
| /** |
| * 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 {?} |
| */ |
| get hasBackdrop() { |
| if (this._backdropOverride == null) { |
| return !this._start || this._start.mode !== 'side' || !this._end || this._end.mode !== 'side'; |
| } |
| return this._backdropOverride; |
| } |
| /** |
| * @param {?} value |
| * @return {?} |
| */ |
| set hasBackdrop(value) { |
| this._backdropOverride = value == null ? null : coerceBooleanProperty(value); |
| } |
| /** |
| * Reference to the CdkScrollable instance that wraps the scrollable content. |
| * @return {?} |
| */ |
| get scrollable() { |
| return this._userContent || this._content; |
| } |
| /** |
| * @return {?} |
| */ |
| ngAfterContentInit() { |
| this._drawers.changes.pipe(startWith(null)).subscribe((/** |
| * @return {?} |
| */ |
| () => { |
| this._validateDrawers(); |
| this._drawers.forEach((/** |
| * @param {?} drawer |
| * @return {?} |
| */ |
| (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(debounceTime(10), // Arbitrary debounce time, less than a frame at 60fps |
| takeUntil(this._destroyed)).subscribe((/** |
| * @return {?} |
| */ |
| () => this.updateContentMargins())); |
| } |
| /** |
| * @return {?} |
| */ |
| ngOnDestroy() { |
| this._contentMarginChanges.complete(); |
| this._doCheckSubject.complete(); |
| this._destroyed.next(); |
| this._destroyed.complete(); |
| } |
| /** |
| * Calls `open` of both start and end drawers |
| * @return {?} |
| */ |
| open() { |
| this._drawers.forEach((/** |
| * @param {?} drawer |
| * @return {?} |
| */ |
| drawer => drawer.open())); |
| } |
| /** |
| * Calls `close` of both start and end drawers |
| * @return {?} |
| */ |
| close() { |
| this._drawers.forEach((/** |
| * @param {?} drawer |
| * @return {?} |
| */ |
| drawer => drawer.close())); |
| } |
| /** |
| * Recalculates and updates the inline styles for the content. Note that this should be used |
| * sparingly, because it causes a reflow. |
| * @return {?} |
| */ |
| updateContentMargins() { |
| // 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 {?} */ |
| let left = 0; |
| /** @type {?} */ |
| let right = 0; |
| if (this._left && this._left.opened) { |
| if (this._left.mode == 'side') { |
| left += this._left._width; |
| } |
| else if (this._left.mode == 'push') { |
| /** @type {?} */ |
| const 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 {?} */ |
| const 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, 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 {?} |
| */ |
| () => this._contentMarginChanges.next(this._contentMargins))); |
| } |
| } |
| /** |
| * @return {?} |
| */ |
| ngDoCheck() { |
| // 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 {?} |
| */ |
| () => 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. |
| * @private |
| * @param {?} drawer |
| * @return {?} |
| */ |
| _watchDrawerToggle(drawer) { |
| drawer._animationStarted.pipe(filter((/** |
| * @param {?} event |
| * @return {?} |
| */ |
| (event) => event.fromState !== event.toState)), takeUntil(this._drawers.changes)) |
| .subscribe((/** |
| * @param {?} event |
| * @return {?} |
| */ |
| (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(takeUntil(this._drawers.changes)).subscribe((/** |
| * @return {?} |
| */ |
| () => this._setContainerClass(drawer.opened))); |
| } |
| } |
| /** |
| * Subscribes to drawer onPositionChanged event in order to |
| * re-validate drawers when the position changes. |
| * @private |
| * @param {?} drawer |
| * @return {?} |
| */ |
| _watchDrawerPosition(drawer) { |
| 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(takeUntil(this._drawers.changes)).subscribe((/** |
| * @return {?} |
| */ |
| () => { |
| this._ngZone.onMicrotaskEmpty.asObservable().pipe(take(1)).subscribe((/** |
| * @return {?} |
| */ |
| () => { |
| this._validateDrawers(); |
| })); |
| })); |
| } |
| /** |
| * Subscribes to changes in drawer mode so we can run change detection. |
| * @private |
| * @param {?} drawer |
| * @return {?} |
| */ |
| _watchDrawerMode(drawer) { |
| if (drawer) { |
| drawer._modeChanged.pipe(takeUntil(merge(this._drawers.changes, this._destroyed))) |
| .subscribe((/** |
| * @return {?} |
| */ |
| () => { |
| this.updateContentMargins(); |
| this._changeDetectorRef.markForCheck(); |
| })); |
| } |
| } |
| /** |
| * Toggles the 'mat-drawer-opened' class on the main 'mat-drawer-container' element. |
| * @private |
| * @param {?} isAdd |
| * @return {?} |
| */ |
| _setContainerClass(isAdd) { |
| if (isAdd) { |
| this._element.nativeElement.classList.add('mat-drawer-opened'); |
| } |
| else { |
| this._element.nativeElement.classList.remove('mat-drawer-opened'); |
| } |
| } |
| /** |
| * Validate the state of the drawer children components. |
| * @private |
| * @return {?} |
| */ |
| _validateDrawers() { |
| this._start = this._end = null; |
| // Ensure that we have at most one start and one end drawer. |
| this._drawers.forEach((/** |
| * @param {?} drawer |
| * @return {?} |
| */ |
| 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. |
| * @private |
| * @return {?} |
| */ |
| _isPushed() { |
| return (this._isDrawerOpen(this._start) && this._start.mode != 'over') || |
| (this._isDrawerOpen(this._end) && this._end.mode != 'over'); |
| } |
| /** |
| * @return {?} |
| */ |
| _onBackdropClicked() { |
| this.backdropClick.emit(); |
| this._closeModalDrawer(); |
| } |
| /** |
| * @return {?} |
| */ |
| _closeModalDrawer() { |
| // Close all open drawers where closing is not disabled and the mode is not `side`. |
| [this._start, this._end] |
| .filter((/** |
| * @param {?} drawer |
| * @return {?} |
| */ |
| drawer => drawer && !drawer.disableClose && this._canHaveBackdrop(drawer))) |
| .forEach((/** |
| * @param {?} drawer |
| * @return {?} |
| */ |
| drawer => (/** @type {?} */ (drawer)).close())); |
| } |
| /** |
| * @return {?} |
| */ |
| _isShowingBackdrop() { |
| return (this._isDrawerOpen(this._start) && this._canHaveBackdrop(this._start)) || |
| (this._isDrawerOpen(this._end) && this._canHaveBackdrop(this._end)); |
| } |
| /** |
| * @private |
| * @param {?} drawer |
| * @return {?} |
| */ |
| _canHaveBackdrop(drawer) { |
| return drawer.mode !== 'side' || !!this._backdropOverride; |
| } |
| /** |
| * @private |
| * @param {?} drawer |
| * @return {?} |
| */ |
| _isDrawerOpen(drawer) { |
| return drawer != null && drawer.opened; |
| } |
| } |
| MatDrawerContainer.decorators = [ |
| { type: Component, args: [{selector: 'mat-drawer-container', |
| exportAs: 'matDrawerContainer', |
| template: "<div class=\"mat-drawer-backdrop\" (click)=\"_onBackdropClicked()\" *ngIf=\"hasBackdrop\" [class.mat-drawer-shown]=\"_isShowingBackdrop()\"></div><ng-content select=\"mat-drawer\"></ng-content><ng-content select=\"mat-drawer-content\"></ng-content><mat-drawer-content *ngIf=\"!_content\"><ng-content></ng-content></mat-drawer-content>", |
| styles: [".mat-drawer-container{position:relative;z-index:1;box-sizing:border-box;-webkit-overflow-scrolling:touch;display:block;overflow:hidden}.mat-drawer-container[fullscreen]{top:0;left:0;right:0;bottom:0;position:absolute}.mat-drawer-container[fullscreen].mat-drawer-opened{overflow:hidden}.mat-drawer-container.mat-drawer-container-explicit-backdrop .mat-drawer-side{z-index:3}.mat-drawer-container.ng-animate-disabled .mat-drawer-backdrop,.mat-drawer-container.ng-animate-disabled .mat-drawer-content,.ng-animate-disabled .mat-drawer-container .mat-drawer-backdrop,.ng-animate-disabled .mat-drawer-container .mat-drawer-content{transition:none}.mat-drawer-backdrop{top:0;left:0;right:0;bottom:0;position:absolute;display:block;z-index:3;visibility:hidden}.mat-drawer-backdrop.mat-drawer-shown{visibility:visible}.mat-drawer-transition .mat-drawer-backdrop{transition-duration:.4s;transition-timing-function:cubic-bezier(.25,.8,.25,1);transition-property:background-color,visibility}@media (-ms-high-contrast:active){.mat-drawer-backdrop{opacity:.5}}.mat-drawer-content{position:relative;z-index:1;display:block;height:100%;overflow:auto}.mat-drawer-transition .mat-drawer-content{transition-duration:.4s;transition-timing-function:cubic-bezier(.25,.8,.25,1);transition-property:transform,margin-left,margin-right}.mat-drawer{position:relative;z-index:4;display:block;position:absolute;top:0;bottom:0;z-index:3;outline:0;box-sizing:border-box;overflow-y:auto;transform:translate3d(-100%,0,0)}@media (-ms-high-contrast:active){.mat-drawer,[dir=rtl] .mat-drawer.mat-drawer-end{border-right:solid 1px currentColor}}@media (-ms-high-contrast:active){.mat-drawer.mat-drawer-end,[dir=rtl] .mat-drawer{border-left:solid 1px currentColor;border-right:none}}.mat-drawer.mat-drawer-side{z-index:2}.mat-drawer.mat-drawer-end{right:0;transform:translate3d(100%,0,0)}[dir=rtl] .mat-drawer{transform:translate3d(100%,0,0)}[dir=rtl] .mat-drawer.mat-drawer-end{left:0;right:auto;transform:translate3d(-100%,0,0)}.mat-drawer-inner-container{width:100%;height:100%;overflow:auto;-webkit-overflow-scrolling:touch}.mat-sidenav-fixed{position:fixed}"], |
| host: { |
| 'class': 'mat-drawer-container', |
| '[class.mat-drawer-container-explicit-backdrop]': '_backdropOverride', |
| }, |
| changeDetection: ChangeDetectionStrategy.OnPush, |
| encapsulation: ViewEncapsulation.None, |
| },] }, |
| ]; |
| /** @nocollapse */ |
| MatDrawerContainer.ctorParameters = () => [ |
| { type: Directionality, decorators: [{ type: Optional }] }, |
| { type: ElementRef }, |
| { type: NgZone }, |
| { type: ChangeDetectorRef }, |
| { type: ViewportRuler }, |
| { type: undefined, decorators: [{ type: Inject, args: [MAT_DRAWER_DEFAULT_AUTOSIZE,] }] }, |
| { type: String, decorators: [{ type: Optional }, { type: Inject, args: [ANIMATION_MODULE_TYPE,] }] } |
| ]; |
| MatDrawerContainer.propDecorators = { |
| _drawers: [{ type: ContentChildren, args: [MatDrawer,] }], |
| _content: [{ type: ContentChild, args: [MatDrawerContent, { static: false },] }], |
| _userContent: [{ type: ViewChild, args: [MatDrawerContent, { static: false },] }], |
| autosize: [{ type: Input }], |
| hasBackdrop: [{ type: Input }], |
| backdropClick: [{ type: Output }] |
| }; |
| |
| /** |
| * @fileoverview added by tsickle |
| * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc |
| */ |
| class MatSidenavContent extends MatDrawerContent { |
| /** |
| * @param {?} changeDetectorRef |
| * @param {?} container |
| * @param {?} elementRef |
| * @param {?} scrollDispatcher |
| * @param {?} ngZone |
| */ |
| constructor(changeDetectorRef, container, elementRef, scrollDispatcher, ngZone) { |
| super(changeDetectorRef, container, elementRef, scrollDispatcher, ngZone); |
| } |
| } |
| MatSidenavContent.decorators = [ |
| { type: Component, args: [{selector: 'mat-sidenav-content', |
| template: '<ng-content></ng-content>', |
| host: { |
| 'class': 'mat-drawer-content mat-sidenav-content', |
| '[style.margin-left.px]': '_container._contentMargins.left', |
| '[style.margin-right.px]': '_container._contentMargins.right', |
| }, |
| changeDetection: ChangeDetectionStrategy.OnPush, |
| encapsulation: ViewEncapsulation.None, |
| },] }, |
| ]; |
| /** @nocollapse */ |
| MatSidenavContent.ctorParameters = () => [ |
| { type: ChangeDetectorRef }, |
| { type: MatSidenavContainer, decorators: [{ type: Inject, args: [forwardRef((/** |
| * @return {?} |
| */ |
| () => MatSidenavContainer)),] }] }, |
| { type: ElementRef }, |
| { type: ScrollDispatcher }, |
| { type: NgZone } |
| ]; |
| class MatSidenav extends MatDrawer { |
| constructor() { |
| super(...arguments); |
| this._fixedInViewport = false; |
| this._fixedTopGap = 0; |
| this._fixedBottomGap = 0; |
| } |
| /** |
| * Whether the sidenav is fixed in the viewport. |
| * @return {?} |
| */ |
| get fixedInViewport() { return this._fixedInViewport; } |
| /** |
| * @param {?} value |
| * @return {?} |
| */ |
| set fixedInViewport(value) { this._fixedInViewport = coerceBooleanProperty(value); } |
| /** |
| * The gap between the top of the sidenav and the top of the viewport when the sidenav is in fixed |
| * mode. |
| * @return {?} |
| */ |
| get fixedTopGap() { return this._fixedTopGap; } |
| /** |
| * @param {?} value |
| * @return {?} |
| */ |
| set fixedTopGap(value) { this._fixedTopGap = coerceNumberProperty(value); } |
| /** |
| * The gap between the bottom of the sidenav and the bottom of the viewport when the sidenav is in |
| * fixed mode. |
| * @return {?} |
| */ |
| get fixedBottomGap() { return this._fixedBottomGap; } |
| /** |
| * @param {?} value |
| * @return {?} |
| */ |
| set fixedBottomGap(value) { this._fixedBottomGap = coerceNumberProperty(value); } |
| } |
| MatSidenav.decorators = [ |
| { type: Component, args: [{selector: 'mat-sidenav', |
| exportAs: 'matSidenav', |
| template: "<div class=\"mat-drawer-inner-container\"><ng-content></ng-content></div>", |
| animations: [matDrawerAnimations.transformDrawer], |
| host: { |
| 'class': 'mat-drawer mat-sidenav', |
| 'tabIndex': '-1', |
| // 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-sidenav-fixed]': 'fixedInViewport', |
| '[style.top.px]': 'fixedInViewport ? fixedTopGap : null', |
| '[style.bottom.px]': 'fixedInViewport ? fixedBottomGap : null', |
| }, |
| changeDetection: ChangeDetectionStrategy.OnPush, |
| encapsulation: ViewEncapsulation.None, |
| },] }, |
| ]; |
| MatSidenav.propDecorators = { |
| fixedInViewport: [{ type: Input }], |
| fixedTopGap: [{ type: Input }], |
| fixedBottomGap: [{ type: Input }] |
| }; |
| class MatSidenavContainer extends MatDrawerContainer { |
| } |
| MatSidenavContainer.decorators = [ |
| { type: Component, args: [{selector: 'mat-sidenav-container', |
| exportAs: 'matSidenavContainer', |
| template: "<div class=\"mat-drawer-backdrop\" (click)=\"_onBackdropClicked()\" *ngIf=\"hasBackdrop\" [class.mat-drawer-shown]=\"_isShowingBackdrop()\"></div><ng-content select=\"mat-sidenav\"></ng-content><ng-content select=\"mat-sidenav-content\"></ng-content><mat-sidenav-content *ngIf=\"!_content\" cdkScrollable><ng-content></ng-content></mat-sidenav-content>", |
| styles: [".mat-drawer-container{position:relative;z-index:1;box-sizing:border-box;-webkit-overflow-scrolling:touch;display:block;overflow:hidden}.mat-drawer-container[fullscreen]{top:0;left:0;right:0;bottom:0;position:absolute}.mat-drawer-container[fullscreen].mat-drawer-opened{overflow:hidden}.mat-drawer-container.mat-drawer-container-explicit-backdrop .mat-drawer-side{z-index:3}.mat-drawer-container.ng-animate-disabled .mat-drawer-backdrop,.mat-drawer-container.ng-animate-disabled .mat-drawer-content,.ng-animate-disabled .mat-drawer-container .mat-drawer-backdrop,.ng-animate-disabled .mat-drawer-container .mat-drawer-content{transition:none}.mat-drawer-backdrop{top:0;left:0;right:0;bottom:0;position:absolute;display:block;z-index:3;visibility:hidden}.mat-drawer-backdrop.mat-drawer-shown{visibility:visible}.mat-drawer-transition .mat-drawer-backdrop{transition-duration:.4s;transition-timing-function:cubic-bezier(.25,.8,.25,1);transition-property:background-color,visibility}@media (-ms-high-contrast:active){.mat-drawer-backdrop{opacity:.5}}.mat-drawer-content{position:relative;z-index:1;display:block;height:100%;overflow:auto}.mat-drawer-transition .mat-drawer-content{transition-duration:.4s;transition-timing-function:cubic-bezier(.25,.8,.25,1);transition-property:transform,margin-left,margin-right}.mat-drawer{position:relative;z-index:4;display:block;position:absolute;top:0;bottom:0;z-index:3;outline:0;box-sizing:border-box;overflow-y:auto;transform:translate3d(-100%,0,0)}@media (-ms-high-contrast:active){.mat-drawer,[dir=rtl] .mat-drawer.mat-drawer-end{border-right:solid 1px currentColor}}@media (-ms-high-contrast:active){.mat-drawer.mat-drawer-end,[dir=rtl] .mat-drawer{border-left:solid 1px currentColor;border-right:none}}.mat-drawer.mat-drawer-side{z-index:2}.mat-drawer.mat-drawer-end{right:0;transform:translate3d(100%,0,0)}[dir=rtl] .mat-drawer{transform:translate3d(100%,0,0)}[dir=rtl] .mat-drawer.mat-drawer-end{left:0;right:auto;transform:translate3d(-100%,0,0)}.mat-drawer-inner-container{width:100%;height:100%;overflow:auto;-webkit-overflow-scrolling:touch}.mat-sidenav-fixed{position:fixed}"], |
| host: { |
| 'class': 'mat-drawer-container mat-sidenav-container', |
| '[class.mat-drawer-container-explicit-backdrop]': '_backdropOverride', |
| }, |
| changeDetection: ChangeDetectionStrategy.OnPush, |
| encapsulation: ViewEncapsulation.None, |
| },] }, |
| ]; |
| MatSidenavContainer.propDecorators = { |
| _drawers: [{ type: ContentChildren, args: [MatSidenav,] }], |
| _content: [{ type: ContentChild, args: [MatSidenavContent, { static: false },] }] |
| }; |
| |
| /** |
| * @fileoverview added by tsickle |
| * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc |
| */ |
| class MatSidenavModule { |
| } |
| MatSidenavModule.decorators = [ |
| { type: NgModule, args: [{ |
| imports: [ |
| CommonModule, |
| MatCommonModule, |
| ScrollingModule, |
| PlatformModule, |
| ], |
| exports: [ |
| MatCommonModule, |
| MatDrawer, |
| MatDrawerContainer, |
| MatDrawerContent, |
| MatSidenav, |
| MatSidenavContainer, |
| MatSidenavContent, |
| ], |
| declarations: [ |
| MatDrawer, |
| MatDrawerContainer, |
| MatDrawerContent, |
| MatSidenav, |
| MatSidenavContainer, |
| MatSidenavContent, |
| ], |
| },] }, |
| ]; |
| |
| /** |
| * @fileoverview added by tsickle |
| * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc |
| */ |
| |
| /** |
| * @fileoverview added by tsickle |
| * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc |
| */ |
| |
| export { MatSidenavModule, throwMatDuplicatedDrawerError, MAT_DRAWER_DEFAULT_AUTOSIZE_FACTORY, MAT_DRAWER_DEFAULT_AUTOSIZE, MatDrawerContent, MatDrawer, MatDrawerContainer, MatSidenavContent, MatSidenav, MatSidenavContainer, matDrawerAnimations }; |
| //# sourceMappingURL=sidenav.js.map |