source: trip-planner-front/node_modules/@angular/material/fesm2015/sidenav.js

Last change on this file was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 44.3 KB
Line 
1import { Platform, PlatformModule } from '@angular/cdk/platform';
2import { CdkScrollable, ScrollDispatcher, ViewportRuler, CdkScrollableModule } from '@angular/cdk/scrolling';
3import { DOCUMENT, CommonModule } from '@angular/common';
4import { InjectionToken, Component, ChangeDetectionStrategy, ViewEncapsulation, ChangeDetectorRef, Inject, forwardRef, ElementRef, NgZone, EventEmitter, Optional, Input, HostBinding, Output, HostListener, QueryList, ContentChildren, ContentChild, ViewChild, NgModule } from '@angular/core';
5import { MatCommonModule } from '@angular/material/core';
6import { FocusTrapFactory, FocusMonitor } from '@angular/cdk/a11y';
7import { Directionality } from '@angular/cdk/bidi';
8import { coerceBooleanProperty, coerceNumberProperty } from '@angular/cdk/coercion';
9import { ESCAPE, hasModifierKey } from '@angular/cdk/keycodes';
10import { Subject, fromEvent, merge } from 'rxjs';
11import { filter, map, mapTo, takeUntil, distinctUntilChanged, take, startWith, debounceTime } from 'rxjs/operators';
12import { trigger, state, style, transition, animate } from '@angular/animations';
13import { ANIMATION_MODULE_TYPE } from '@angular/platform-browser/animations';
14
15/**
16 * @license
17 * Copyright Google LLC All Rights Reserved.
18 *
19 * Use of this source code is governed by an MIT-style license that can be
20 * found in the LICENSE file at https://angular.io/license
21 */
22/**
23 * Animations used by the Material drawers.
24 * @docs-private
25 */
26const matDrawerAnimations = {
27 /** Animation that slides a drawer in and out. */
28 transformDrawer: trigger('transform', [
29 // We remove the `transform` here completely, rather than setting it to zero, because:
30 // 1. Having a transform can cause elements with ripples or an animated
31 // transform to shift around in Chrome with an RTL layout (see #10023).
32 // 2. 3d transforms causes text to appear blurry on IE and Edge.
33 state('open, open-instant', style({
34 'transform': 'none',
35 'visibility': 'visible',
36 })),
37 state('void', style({
38 // Avoids the shadow showing up when closed in SSR.
39 'box-shadow': 'none',
40 'visibility': 'hidden',
41 })),
42 transition('void => open-instant', animate('0ms')),
43 transition('void <=> open, open-instant => void', animate('400ms cubic-bezier(0.25, 0.8, 0.25, 1)'))
44 ])
45};
46
47/**
48 * Throws an exception when two MatDrawer are matching the same position.
49 * @docs-private
50 */
51function throwMatDuplicatedDrawerError(position) {
52 throw Error(`A drawer was already declared for 'position="${position}"'`);
53}
54/** Configures whether drawers should use auto sizing by default. */
55const MAT_DRAWER_DEFAULT_AUTOSIZE = new InjectionToken('MAT_DRAWER_DEFAULT_AUTOSIZE', {
56 providedIn: 'root',
57 factory: MAT_DRAWER_DEFAULT_AUTOSIZE_FACTORY,
58});
59/**
60 * Used to provide a drawer container to a drawer while avoiding circular references.
61 * @docs-private
62 */
63const MAT_DRAWER_CONTAINER = new InjectionToken('MAT_DRAWER_CONTAINER');
64/** @docs-private */
65function MAT_DRAWER_DEFAULT_AUTOSIZE_FACTORY() {
66 return false;
67}
68class MatDrawerContent extends CdkScrollable {
69 constructor(_changeDetectorRef, _container, elementRef, scrollDispatcher, ngZone) {
70 super(elementRef, scrollDispatcher, ngZone);
71 this._changeDetectorRef = _changeDetectorRef;
72 this._container = _container;
73 }
74 ngAfterContentInit() {
75 this._container._contentMarginChanges.subscribe(() => {
76 this._changeDetectorRef.markForCheck();
77 });
78 }
79}
80MatDrawerContent.decorators = [
81 { type: Component, args: [{
82 selector: 'mat-drawer-content',
83 template: '<ng-content></ng-content>',
84 host: {
85 'class': 'mat-drawer-content',
86 '[style.margin-left.px]': '_container._contentMargins.left',
87 '[style.margin-right.px]': '_container._contentMargins.right',
88 },
89 changeDetection: ChangeDetectionStrategy.OnPush,
90 encapsulation: ViewEncapsulation.None
91 },] }
92];
93MatDrawerContent.ctorParameters = () => [
94 { type: ChangeDetectorRef },
95 { type: MatDrawerContainer, decorators: [{ type: Inject, args: [forwardRef(() => MatDrawerContainer),] }] },
96 { type: ElementRef },
97 { type: ScrollDispatcher },
98 { type: NgZone }
99];
100/**
101 * This component corresponds to a drawer that can be opened on the drawer container.
102 */
103class MatDrawer {
104 constructor(_elementRef, _focusTrapFactory, _focusMonitor, _platform, _ngZone, _doc, _container) {
105 this._elementRef = _elementRef;
106 this._focusTrapFactory = _focusTrapFactory;
107 this._focusMonitor = _focusMonitor;
108 this._platform = _platform;
109 this._ngZone = _ngZone;
110 this._doc = _doc;
111 this._container = _container;
112 this._elementFocusedBeforeDrawerWasOpened = null;
113 /** Whether the drawer is initialized. Used for disabling the initial animation. */
114 this._enableAnimations = false;
115 this._position = 'start';
116 this._mode = 'over';
117 this._disableClose = false;
118 this._opened = false;
119 /** Emits whenever the drawer has started animating. */
120 this._animationStarted = new Subject();
121 /** Emits whenever the drawer is done animating. */
122 this._animationEnd = new Subject();
123 /** Current state of the sidenav animation. */
124 // @HostBinding is used in the class as it is expected to be extended. Since @Component decorator
125 // metadata is not inherited by child classes, instead the host binding data is defined in a way
126 // that can be inherited.
127 // tslint:disable-next-line:no-host-decorator-in-concrete
128 this._animationState = 'void';
129 /** Event emitted when the drawer open state is changed. */
130 this.openedChange =
131 // Note this has to be async in order to avoid some issues with two-bindings (see #8872).
132 new EventEmitter(/* isAsync */ true);
133 /** Event emitted when the drawer has been opened. */
134 this._openedStream = this.openedChange.pipe(filter(o => o), map(() => { }));
135 /** Event emitted when the drawer has started opening. */
136 this.openedStart = this._animationStarted.pipe(filter(e => e.fromState !== e.toState && e.toState.indexOf('open') === 0), mapTo(undefined));
137 /** Event emitted when the drawer has been closed. */
138 this._closedStream = this.openedChange.pipe(filter(o => !o), map(() => { }));
139 /** Event emitted when the drawer has started closing. */
140 this.closedStart = this._animationStarted.pipe(filter(e => e.fromState !== e.toState && e.toState === 'void'), mapTo(undefined));
141 /** Emits when the component is destroyed. */
142 this._destroyed = new Subject();
143 /** Event emitted when the drawer's position changes. */
144 // tslint:disable-next-line:no-output-on-prefix
145 this.onPositionChanged = new EventEmitter();
146 /**
147 * An observable that emits when the drawer mode changes. This is used by the drawer container to
148 * to know when to when the mode changes so it can adapt the margins on the content.
149 */
150 this._modeChanged = new Subject();
151 this.openedChange.subscribe((opened) => {
152 if (opened) {
153 if (this._doc) {
154 this._elementFocusedBeforeDrawerWasOpened = this._doc.activeElement;
155 }
156 this._takeFocus();
157 }
158 else if (this._isFocusWithinDrawer()) {
159 this._restoreFocus();
160 }
161 });
162 /**
163 * Listen to `keydown` events outside the zone so that change detection is not run every
164 * time a key is pressed. Instead we re-enter the zone only if the `ESC` key is pressed
165 * and we don't have close disabled.
166 */
167 this._ngZone.runOutsideAngular(() => {
168 fromEvent(this._elementRef.nativeElement, 'keydown').pipe(filter(event => {
169 return event.keyCode === ESCAPE && !this.disableClose && !hasModifierKey(event);
170 }), takeUntil(this._destroyed)).subscribe(event => this._ngZone.run(() => {
171 this.close();
172 event.stopPropagation();
173 event.preventDefault();
174 }));
175 });
176 // We need a Subject with distinctUntilChanged, because the `done` event
177 // fires twice on some browsers. See https://github.com/angular/angular/issues/24084
178 this._animationEnd.pipe(distinctUntilChanged((x, y) => {
179 return x.fromState === y.fromState && x.toState === y.toState;
180 })).subscribe((event) => {
181 const { fromState, toState } = event;
182 if ((toState.indexOf('open') === 0 && fromState === 'void') ||
183 (toState === 'void' && fromState.indexOf('open') === 0)) {
184 this.openedChange.emit(this._opened);
185 }
186 });
187 }
188 /** The side that the drawer is attached to. */
189 get position() { return this._position; }
190 set position(value) {
191 // Make sure we have a valid value.
192 value = value === 'end' ? 'end' : 'start';
193 if (value != this._position) {
194 this._position = value;
195 this.onPositionChanged.emit();
196 }
197 }
198 /** Mode of the drawer; one of 'over', 'push' or 'side'. */
199 get mode() { return this._mode; }
200 set mode(value) {
201 this._mode = value;
202 this._updateFocusTrapState();
203 this._modeChanged.next();
204 }
205 /** Whether the drawer can be closed with the escape key or by clicking on the backdrop. */
206 get disableClose() { return this._disableClose; }
207 set disableClose(value) { this._disableClose = coerceBooleanProperty(value); }
208 /**
209 * Whether the drawer should focus the first focusable element automatically when opened.
210 * Defaults to false in when `mode` is set to `side`, otherwise defaults to `true`. If explicitly
211 * enabled, focus will be moved into the sidenav in `side` mode as well.
212 */
213 get autoFocus() {
214 const value = this._autoFocus;
215 // Note that usually we disable auto focusing in `side` mode, because we don't know how the
216 // sidenav is being used, but in some cases it still makes sense to do it. If the consumer
217 // explicitly enabled `autoFocus`, we take it as them always wanting to enable it.
218 return value == null ? this.mode !== 'side' : value;
219 }
220 set autoFocus(value) { this._autoFocus = coerceBooleanProperty(value); }
221 /**
222 * Whether the drawer is opened. We overload this because we trigger an event when it
223 * starts or end.
224 */
225 get opened() { return this._opened; }
226 set opened(value) { this.toggle(coerceBooleanProperty(value)); }
227 /**
228 * Moves focus into the drawer. Note that this works even if
229 * the focus trap is disabled in `side` mode.
230 */
231 _takeFocus() {
232 if (!this.autoFocus || !this._focusTrap) {
233 return;
234 }
235 this._focusTrap.focusInitialElementWhenReady().then(hasMovedFocus => {
236 // If there were no focusable elements, focus the sidenav itself so the keyboard navigation
237 // still works. We need to check that `focus` is a function due to Universal.
238 if (!hasMovedFocus && typeof this._elementRef.nativeElement.focus === 'function') {
239 this._elementRef.nativeElement.focus();
240 }
241 });
242 }
243 /**
244 * Restores focus to the element that was originally focused when the drawer opened.
245 * If no element was focused at that time, the focus will be restored to the drawer.
246 */
247 _restoreFocus() {
248 if (!this.autoFocus) {
249 return;
250 }
251 // Note that we don't check via `instanceof HTMLElement` so that we can cover SVGs as well.
252 if (this._elementFocusedBeforeDrawerWasOpened) {
253 this._focusMonitor.focusVia(this._elementFocusedBeforeDrawerWasOpened, this._openedVia);
254 }
255 else {
256 this._elementRef.nativeElement.blur();
257 }
258 this._elementFocusedBeforeDrawerWasOpened = null;
259 this._openedVia = null;
260 }
261 /** Whether focus is currently within the drawer. */
262 _isFocusWithinDrawer() {
263 var _a;
264 const activeEl = (_a = this._doc) === null || _a === void 0 ? void 0 : _a.activeElement;
265 return !!activeEl && this._elementRef.nativeElement.contains(activeEl);
266 }
267 ngAfterContentInit() {
268 this._focusTrap = this._focusTrapFactory.create(this._elementRef.nativeElement);
269 this._updateFocusTrapState();
270 }
271 ngAfterContentChecked() {
272 // Enable the animations after the lifecycle hooks have run, in order to avoid animating
273 // drawers that are open by default. When we're on the server, we shouldn't enable the
274 // animations, because we don't want the drawer to animate the first time the user sees
275 // the page.
276 if (this._platform.isBrowser) {
277 this._enableAnimations = true;
278 }
279 }
280 ngOnDestroy() {
281 if (this._focusTrap) {
282 this._focusTrap.destroy();
283 }
284 this._animationStarted.complete();
285 this._animationEnd.complete();
286 this._modeChanged.complete();
287 this._destroyed.next();
288 this._destroyed.complete();
289 }
290 /**
291 * Open the drawer.
292 * @param openedVia Whether the drawer was opened by a key press, mouse click or programmatically.
293 * Used for focus management after the sidenav is closed.
294 */
295 open(openedVia) {
296 return this.toggle(true, openedVia);
297 }
298 /** Close the drawer. */
299 close() {
300 return this.toggle(false);
301 }
302 /** Closes the drawer with context that the backdrop was clicked. */
303 _closeViaBackdropClick() {
304 // If the drawer is closed upon a backdrop click, we always want to restore focus. We
305 // don't need to check whether focus is currently in the drawer, as clicking on the
306 // backdrop causes blurring of the active element.
307 return this._setOpen(/* isOpen */ false, /* restoreFocus */ true);
308 }
309 /**
310 * Toggle this drawer.
311 * @param isOpen Whether the drawer should be open.
312 * @param openedVia Whether the drawer was opened by a key press, mouse click or programmatically.
313 * Used for focus management after the sidenav is closed.
314 */
315 toggle(isOpen = !this.opened, openedVia) {
316 // If the focus is currently inside the drawer content and we are closing the drawer,
317 // restore the focus to the initially focused element (when the drawer opened).
318 return this._setOpen(isOpen, /* restoreFocus */ !isOpen && this._isFocusWithinDrawer(), openedVia);
319 }
320 /**
321 * Toggles the opened state of the drawer.
322 * @param isOpen Whether the drawer should open or close.
323 * @param restoreFocus Whether focus should be restored on close.
324 * @param openedVia Focus origin that can be optionally set when opening a drawer. The
325 * origin will be used later when focus is restored on drawer close.
326 */
327 _setOpen(isOpen, restoreFocus, openedVia = 'program') {
328 this._opened = isOpen;
329 if (isOpen) {
330 this._animationState = this._enableAnimations ? 'open' : 'open-instant';
331 this._openedVia = openedVia;
332 }
333 else {
334 this._animationState = 'void';
335 if (restoreFocus) {
336 this._restoreFocus();
337 }
338 }
339 this._updateFocusTrapState();
340 return new Promise(resolve => {
341 this.openedChange.pipe(take(1)).subscribe(open => resolve(open ? 'open' : 'close'));
342 });
343 }
344 _getWidth() {
345 return this._elementRef.nativeElement ? (this._elementRef.nativeElement.offsetWidth || 0) : 0;
346 }
347 /** Updates the enabled state of the focus trap. */
348 _updateFocusTrapState() {
349 if (this._focusTrap) {
350 // The focus trap is only enabled when the drawer is open in any mode other than side.
351 this._focusTrap.enabled = this.opened && this.mode !== 'side';
352 }
353 }
354 // We have to use a `HostListener` here in order to support both Ivy and ViewEngine.
355 // In Ivy the `host` bindings will be merged when this class is extended, whereas in
356 // ViewEngine they're overwritten.
357 // TODO(crisbeto): we move this back into `host` once Ivy is turned on by default.
358 // tslint:disable-next-line:no-host-decorator-in-concrete
359 _animationStartListener(event) {
360 this._animationStarted.next(event);
361 }
362 // We have to use a `HostListener` here in order to support both Ivy and ViewEngine.
363 // In Ivy the `host` bindings will be merged when this class is extended, whereas in
364 // ViewEngine they're overwritten.
365 // TODO(crisbeto): we move this back into `host` once Ivy is turned on by default.
366 // tslint:disable-next-line:no-host-decorator-in-concrete
367 _animationDoneListener(event) {
368 this._animationEnd.next(event);
369 }
370}
371MatDrawer.decorators = [
372 { type: Component, args: [{
373 selector: 'mat-drawer',
374 exportAs: 'matDrawer',
375 template: "<div class=\"mat-drawer-inner-container\" cdkScrollable>\r\n <ng-content></ng-content>\r\n</div>\r\n",
376 animations: [matDrawerAnimations.transformDrawer],
377 host: {
378 'class': 'mat-drawer',
379 // must prevent the browser from aligning text based on value
380 '[attr.align]': 'null',
381 '[class.mat-drawer-end]': 'position === "end"',
382 '[class.mat-drawer-over]': 'mode === "over"',
383 '[class.mat-drawer-push]': 'mode === "push"',
384 '[class.mat-drawer-side]': 'mode === "side"',
385 '[class.mat-drawer-opened]': 'opened',
386 'tabIndex': '-1',
387 },
388 changeDetection: ChangeDetectionStrategy.OnPush,
389 encapsulation: ViewEncapsulation.None
390 },] }
391];
392MatDrawer.ctorParameters = () => [
393 { type: ElementRef },
394 { type: FocusTrapFactory },
395 { type: FocusMonitor },
396 { type: Platform },
397 { type: NgZone },
398 { type: undefined, decorators: [{ type: Optional }, { type: Inject, args: [DOCUMENT,] }] },
399 { type: MatDrawerContainer, decorators: [{ type: Optional }, { type: Inject, args: [MAT_DRAWER_CONTAINER,] }] }
400];
401MatDrawer.propDecorators = {
402 position: [{ type: Input }],
403 mode: [{ type: Input }],
404 disableClose: [{ type: Input }],
405 autoFocus: [{ type: Input }],
406 opened: [{ type: Input }],
407 _animationState: [{ type: HostBinding, args: ['@transform',] }],
408 openedChange: [{ type: Output }],
409 _openedStream: [{ type: Output, args: ['opened',] }],
410 openedStart: [{ type: Output }],
411 _closedStream: [{ type: Output, args: ['closed',] }],
412 closedStart: [{ type: Output }],
413 onPositionChanged: [{ type: Output, args: ['positionChanged',] }],
414 _animationStartListener: [{ type: HostListener, args: ['@transform.start', ['$event'],] }],
415 _animationDoneListener: [{ type: HostListener, args: ['@transform.done', ['$event'],] }]
416};
417/**
418 * `<mat-drawer-container>` component.
419 *
420 * This is the parent component to one or two `<mat-drawer>`s that validates the state internally
421 * and coordinates the backdrop and content styling.
422 */
423class MatDrawerContainer {
424 constructor(_dir, _element, _ngZone, _changeDetectorRef, viewportRuler, defaultAutosize = false, _animationMode) {
425 this._dir = _dir;
426 this._element = _element;
427 this._ngZone = _ngZone;
428 this._changeDetectorRef = _changeDetectorRef;
429 this._animationMode = _animationMode;
430 /** Drawers that belong to this container. */
431 this._drawers = new QueryList();
432 /** Event emitted when the drawer backdrop is clicked. */
433 this.backdropClick = new EventEmitter();
434 /** Emits when the component is destroyed. */
435 this._destroyed = new Subject();
436 /** Emits on every ngDoCheck. Used for debouncing reflows. */
437 this._doCheckSubject = new Subject();
438 /**
439 * Margins to be applied to the content. These are used to push / shrink the drawer content when a
440 * drawer is open. We use margin rather than transform even for push mode because transform breaks
441 * fixed position elements inside of the transformed element.
442 */
443 this._contentMargins = { left: null, right: null };
444 this._contentMarginChanges = new Subject();
445 // If a `Dir` directive exists up the tree, listen direction changes
446 // and update the left/right properties to point to the proper start/end.
447 if (_dir) {
448 _dir.change.pipe(takeUntil(this._destroyed)).subscribe(() => {
449 this._validateDrawers();
450 this.updateContentMargins();
451 });
452 }
453 // Since the minimum width of the sidenav depends on the viewport width,
454 // we need to recompute the margins if the viewport changes.
455 viewportRuler.change()
456 .pipe(takeUntil(this._destroyed))
457 .subscribe(() => this.updateContentMargins());
458 this._autosize = defaultAutosize;
459 }
460 /** The drawer child with the `start` position. */
461 get start() { return this._start; }
462 /** The drawer child with the `end` position. */
463 get end() { return this._end; }
464 /**
465 * Whether to automatically resize the container whenever
466 * the size of any of its drawers changes.
467 *
468 * **Use at your own risk!** Enabling this option can cause layout thrashing by measuring
469 * the drawers on every change detection cycle. Can be configured globally via the
470 * `MAT_DRAWER_DEFAULT_AUTOSIZE` token.
471 */
472 get autosize() { return this._autosize; }
473 set autosize(value) { this._autosize = coerceBooleanProperty(value); }
474 /**
475 * Whether the drawer container should have a backdrop while one of the sidenavs is open.
476 * If explicitly set to `true`, the backdrop will be enabled for drawers in the `side`
477 * mode as well.
478 */
479 get hasBackdrop() {
480 if (this._backdropOverride == null) {
481 return !this._start || this._start.mode !== 'side' || !this._end || this._end.mode !== 'side';
482 }
483 return this._backdropOverride;
484 }
485 set hasBackdrop(value) {
486 this._backdropOverride = value == null ? null : coerceBooleanProperty(value);
487 }
488 /** Reference to the CdkScrollable instance that wraps the scrollable content. */
489 get scrollable() {
490 return this._userContent || this._content;
491 }
492 ngAfterContentInit() {
493 this._allDrawers.changes
494 .pipe(startWith(this._allDrawers), takeUntil(this._destroyed))
495 .subscribe((drawer) => {
496 this._drawers.reset(drawer.filter(item => !item._container || item._container === this));
497 this._drawers.notifyOnChanges();
498 });
499 this._drawers.changes.pipe(startWith(null)).subscribe(() => {
500 this._validateDrawers();
501 this._drawers.forEach((drawer) => {
502 this._watchDrawerToggle(drawer);
503 this._watchDrawerPosition(drawer);
504 this._watchDrawerMode(drawer);
505 });
506 if (!this._drawers.length ||
507 this._isDrawerOpen(this._start) ||
508 this._isDrawerOpen(this._end)) {
509 this.updateContentMargins();
510 }
511 this._changeDetectorRef.markForCheck();
512 });
513 // Avoid hitting the NgZone through the debounce timeout.
514 this._ngZone.runOutsideAngular(() => {
515 this._doCheckSubject.pipe(debounceTime(10), // Arbitrary debounce time, less than a frame at 60fps
516 takeUntil(this._destroyed)).subscribe(() => this.updateContentMargins());
517 });
518 }
519 ngOnDestroy() {
520 this._contentMarginChanges.complete();
521 this._doCheckSubject.complete();
522 this._drawers.destroy();
523 this._destroyed.next();
524 this._destroyed.complete();
525 }
526 /** Calls `open` of both start and end drawers */
527 open() {
528 this._drawers.forEach(drawer => drawer.open());
529 }
530 /** Calls `close` of both start and end drawers */
531 close() {
532 this._drawers.forEach(drawer => drawer.close());
533 }
534 /**
535 * Recalculates and updates the inline styles for the content. Note that this should be used
536 * sparingly, because it causes a reflow.
537 */
538 updateContentMargins() {
539 // 1. For drawers in `over` mode, they don't affect the content.
540 // 2. For drawers in `side` mode they should shrink the content. We do this by adding to the
541 // left margin (for left drawer) or right margin (for right the drawer).
542 // 3. For drawers in `push` mode the should shift the content without resizing it. We do this by
543 // adding to the left or right margin and simultaneously subtracting the same amount of
544 // margin from the other side.
545 let left = 0;
546 let right = 0;
547 if (this._left && this._left.opened) {
548 if (this._left.mode == 'side') {
549 left += this._left._getWidth();
550 }
551 else if (this._left.mode == 'push') {
552 const width = this._left._getWidth();
553 left += width;
554 right -= width;
555 }
556 }
557 if (this._right && this._right.opened) {
558 if (this._right.mode == 'side') {
559 right += this._right._getWidth();
560 }
561 else if (this._right.mode == 'push') {
562 const width = this._right._getWidth();
563 right += width;
564 left -= width;
565 }
566 }
567 // If either `right` or `left` is zero, don't set a style to the element. This
568 // allows users to specify a custom size via CSS class in SSR scenarios where the
569 // measured widths will always be zero. Note that we reset to `null` here, rather
570 // than below, in order to ensure that the types in the `if` below are consistent.
571 left = left || null;
572 right = right || null;
573 if (left !== this._contentMargins.left || right !== this._contentMargins.right) {
574 this._contentMargins = { left, right };
575 // Pull back into the NgZone since in some cases we could be outside. We need to be careful
576 // to do it only when something changed, otherwise we can end up hitting the zone too often.
577 this._ngZone.run(() => this._contentMarginChanges.next(this._contentMargins));
578 }
579 }
580 ngDoCheck() {
581 // If users opted into autosizing, do a check every change detection cycle.
582 if (this._autosize && this._isPushed()) {
583 // Run outside the NgZone, otherwise the debouncer will throw us into an infinite loop.
584 this._ngZone.runOutsideAngular(() => this._doCheckSubject.next());
585 }
586 }
587 /**
588 * Subscribes to drawer events in order to set a class on the main container element when the
589 * drawer is open and the backdrop is visible. This ensures any overflow on the container element
590 * is properly hidden.
591 */
592 _watchDrawerToggle(drawer) {
593 drawer._animationStarted.pipe(filter((event) => event.fromState !== event.toState), takeUntil(this._drawers.changes))
594 .subscribe((event) => {
595 // Set the transition class on the container so that the animations occur. This should not
596 // be set initially because animations should only be triggered via a change in state.
597 if (event.toState !== 'open-instant' && this._animationMode !== 'NoopAnimations') {
598 this._element.nativeElement.classList.add('mat-drawer-transition');
599 }
600 this.updateContentMargins();
601 this._changeDetectorRef.markForCheck();
602 });
603 if (drawer.mode !== 'side') {
604 drawer.openedChange.pipe(takeUntil(this._drawers.changes)).subscribe(() => this._setContainerClass(drawer.opened));
605 }
606 }
607 /**
608 * Subscribes to drawer onPositionChanged event in order to
609 * re-validate drawers when the position changes.
610 */
611 _watchDrawerPosition(drawer) {
612 if (!drawer) {
613 return;
614 }
615 // NOTE: We need to wait for the microtask queue to be empty before validating,
616 // since both drawers may be swapping positions at the same time.
617 drawer.onPositionChanged.pipe(takeUntil(this._drawers.changes)).subscribe(() => {
618 this._ngZone.onMicrotaskEmpty.pipe(take(1)).subscribe(() => {
619 this._validateDrawers();
620 });
621 });
622 }
623 /** Subscribes to changes in drawer mode so we can run change detection. */
624 _watchDrawerMode(drawer) {
625 if (drawer) {
626 drawer._modeChanged.pipe(takeUntil(merge(this._drawers.changes, this._destroyed)))
627 .subscribe(() => {
628 this.updateContentMargins();
629 this._changeDetectorRef.markForCheck();
630 });
631 }
632 }
633 /** Toggles the 'mat-drawer-opened' class on the main 'mat-drawer-container' element. */
634 _setContainerClass(isAdd) {
635 const classList = this._element.nativeElement.classList;
636 const className = 'mat-drawer-container-has-open';
637 if (isAdd) {
638 classList.add(className);
639 }
640 else {
641 classList.remove(className);
642 }
643 }
644 /** Validate the state of the drawer children components. */
645 _validateDrawers() {
646 this._start = this._end = null;
647 // Ensure that we have at most one start and one end drawer.
648 this._drawers.forEach(drawer => {
649 if (drawer.position == 'end') {
650 if (this._end != null && (typeof ngDevMode === 'undefined' || ngDevMode)) {
651 throwMatDuplicatedDrawerError('end');
652 }
653 this._end = drawer;
654 }
655 else {
656 if (this._start != null && (typeof ngDevMode === 'undefined' || ngDevMode)) {
657 throwMatDuplicatedDrawerError('start');
658 }
659 this._start = drawer;
660 }
661 });
662 this._right = this._left = null;
663 // Detect if we're LTR or RTL.
664 if (this._dir && this._dir.value === 'rtl') {
665 this._left = this._end;
666 this._right = this._start;
667 }
668 else {
669 this._left = this._start;
670 this._right = this._end;
671 }
672 }
673 /** Whether the container is being pushed to the side by one of the drawers. */
674 _isPushed() {
675 return (this._isDrawerOpen(this._start) && this._start.mode != 'over') ||
676 (this._isDrawerOpen(this._end) && this._end.mode != 'over');
677 }
678 _onBackdropClicked() {
679 this.backdropClick.emit();
680 this._closeModalDrawersViaBackdrop();
681 }
682 _closeModalDrawersViaBackdrop() {
683 // Close all open drawers where closing is not disabled and the mode is not `side`.
684 [this._start, this._end]
685 .filter(drawer => drawer && !drawer.disableClose && this._canHaveBackdrop(drawer))
686 .forEach(drawer => drawer._closeViaBackdropClick());
687 }
688 _isShowingBackdrop() {
689 return (this._isDrawerOpen(this._start) && this._canHaveBackdrop(this._start)) ||
690 (this._isDrawerOpen(this._end) && this._canHaveBackdrop(this._end));
691 }
692 _canHaveBackdrop(drawer) {
693 return drawer.mode !== 'side' || !!this._backdropOverride;
694 }
695 _isDrawerOpen(drawer) {
696 return drawer != null && drawer.opened;
697 }
698}
699MatDrawerContainer.decorators = [
700 { type: Component, args: [{
701 selector: 'mat-drawer-container',
702 exportAs: 'matDrawerContainer',
703 template: "<div class=\"mat-drawer-backdrop\" (click)=\"_onBackdropClicked()\" *ngIf=\"hasBackdrop\"\n [class.mat-drawer-shown]=\"_isShowingBackdrop()\"></div>\n\n<ng-content select=\"mat-drawer\"></ng-content>\n\n<ng-content select=\"mat-drawer-content\">\n</ng-content>\n<mat-drawer-content *ngIf=\"!_content\">\n <ng-content></ng-content>\n</mat-drawer-content>\n",
704 host: {
705 'class': 'mat-drawer-container',
706 '[class.mat-drawer-container-explicit-backdrop]': '_backdropOverride',
707 },
708 changeDetection: ChangeDetectionStrategy.OnPush,
709 encapsulation: ViewEncapsulation.None,
710 providers: [{
711 provide: MAT_DRAWER_CONTAINER,
712 useExisting: MatDrawerContainer
713 }],
714 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-container-has-open{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:400ms;transition-timing-function:cubic-bezier(0.25, 0.8, 0.25, 1);transition-property:background-color,visibility}.cdk-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:400ms;transition-timing-function:cubic-bezier(0.25, 0.8, 0.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)}.cdk-high-contrast-active .mat-drawer,.cdk-high-contrast-active [dir=rtl] .mat-drawer.mat-drawer-end{border-right:solid 1px currentColor}.cdk-high-contrast-active [dir=rtl] .mat-drawer,.cdk-high-contrast-active .mat-drawer.mat-drawer-end{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}\n"]
715 },] }
716];
717MatDrawerContainer.ctorParameters = () => [
718 { type: Directionality, decorators: [{ type: Optional }] },
719 { type: ElementRef },
720 { type: NgZone },
721 { type: ChangeDetectorRef },
722 { type: ViewportRuler },
723 { type: undefined, decorators: [{ type: Inject, args: [MAT_DRAWER_DEFAULT_AUTOSIZE,] }] },
724 { type: String, decorators: [{ type: Optional }, { type: Inject, args: [ANIMATION_MODULE_TYPE,] }] }
725];
726MatDrawerContainer.propDecorators = {
727 _allDrawers: [{ type: ContentChildren, args: [MatDrawer, {
728 // We need to use `descendants: true`, because Ivy will no longer match
729 // indirect descendants if it's left as false.
730 descendants: true
731 },] }],
732 _content: [{ type: ContentChild, args: [MatDrawerContent,] }],
733 _userContent: [{ type: ViewChild, args: [MatDrawerContent,] }],
734 autosize: [{ type: Input }],
735 hasBackdrop: [{ type: Input }],
736 backdropClick: [{ type: Output }]
737};
738
739/**
740 * @license
741 * Copyright Google LLC All Rights Reserved.
742 *
743 * Use of this source code is governed by an MIT-style license that can be
744 * found in the LICENSE file at https://angular.io/license
745 */
746class MatSidenavContent extends MatDrawerContent {
747 constructor(changeDetectorRef, container, elementRef, scrollDispatcher, ngZone) {
748 super(changeDetectorRef, container, elementRef, scrollDispatcher, ngZone);
749 }
750}
751MatSidenavContent.decorators = [
752 { type: Component, args: [{
753 selector: 'mat-sidenav-content',
754 template: '<ng-content></ng-content>',
755 host: {
756 'class': 'mat-drawer-content mat-sidenav-content',
757 '[style.margin-left.px]': '_container._contentMargins.left',
758 '[style.margin-right.px]': '_container._contentMargins.right',
759 },
760 changeDetection: ChangeDetectionStrategy.OnPush,
761 encapsulation: ViewEncapsulation.None
762 },] }
763];
764MatSidenavContent.ctorParameters = () => [
765 { type: ChangeDetectorRef },
766 { type: MatSidenavContainer, decorators: [{ type: Inject, args: [forwardRef(() => MatSidenavContainer),] }] },
767 { type: ElementRef },
768 { type: ScrollDispatcher },
769 { type: NgZone }
770];
771class MatSidenav extends MatDrawer {
772 constructor() {
773 super(...arguments);
774 this._fixedInViewport = false;
775 this._fixedTopGap = 0;
776 this._fixedBottomGap = 0;
777 }
778 /** Whether the sidenav is fixed in the viewport. */
779 get fixedInViewport() { return this._fixedInViewport; }
780 set fixedInViewport(value) { this._fixedInViewport = coerceBooleanProperty(value); }
781 /**
782 * The gap between the top of the sidenav and the top of the viewport when the sidenav is in fixed
783 * mode.
784 */
785 get fixedTopGap() { return this._fixedTopGap; }
786 set fixedTopGap(value) { this._fixedTopGap = coerceNumberProperty(value); }
787 /**
788 * The gap between the bottom of the sidenav and the bottom of the viewport when the sidenav is in
789 * fixed mode.
790 */
791 get fixedBottomGap() { return this._fixedBottomGap; }
792 set fixedBottomGap(value) { this._fixedBottomGap = coerceNumberProperty(value); }
793}
794MatSidenav.decorators = [
795 { type: Component, args: [{
796 selector: 'mat-sidenav',
797 exportAs: 'matSidenav',
798 template: "<div class=\"mat-drawer-inner-container\" cdkScrollable>\r\n <ng-content></ng-content>\r\n</div>\r\n",
799 animations: [matDrawerAnimations.transformDrawer],
800 host: {
801 'class': 'mat-drawer mat-sidenav',
802 'tabIndex': '-1',
803 // must prevent the browser from aligning text based on value
804 '[attr.align]': 'null',
805 '[class.mat-drawer-end]': 'position === "end"',
806 '[class.mat-drawer-over]': 'mode === "over"',
807 '[class.mat-drawer-push]': 'mode === "push"',
808 '[class.mat-drawer-side]': 'mode === "side"',
809 '[class.mat-drawer-opened]': 'opened',
810 '[class.mat-sidenav-fixed]': 'fixedInViewport',
811 '[style.top.px]': 'fixedInViewport ? fixedTopGap : null',
812 '[style.bottom.px]': 'fixedInViewport ? fixedBottomGap : null',
813 },
814 changeDetection: ChangeDetectionStrategy.OnPush,
815 encapsulation: ViewEncapsulation.None
816 },] }
817];
818MatSidenav.propDecorators = {
819 fixedInViewport: [{ type: Input }],
820 fixedTopGap: [{ type: Input }],
821 fixedBottomGap: [{ type: Input }]
822};
823class MatSidenavContainer extends MatDrawerContainer {
824}
825MatSidenavContainer.decorators = [
826 { type: Component, args: [{
827 selector: 'mat-sidenav-container',
828 exportAs: 'matSidenavContainer',
829 template: "<div class=\"mat-drawer-backdrop\" (click)=\"_onBackdropClicked()\" *ngIf=\"hasBackdrop\"\n [class.mat-drawer-shown]=\"_isShowingBackdrop()\"></div>\n\n<ng-content select=\"mat-sidenav\"></ng-content>\n\n<ng-content select=\"mat-sidenav-content\">\n</ng-content>\n<mat-sidenav-content *ngIf=\"!_content\" cdkScrollable>\n <ng-content></ng-content>\n</mat-sidenav-content>\n",
830 host: {
831 'class': 'mat-drawer-container mat-sidenav-container',
832 '[class.mat-drawer-container-explicit-backdrop]': '_backdropOverride',
833 },
834 changeDetection: ChangeDetectionStrategy.OnPush,
835 encapsulation: ViewEncapsulation.None,
836 providers: [{
837 provide: MAT_DRAWER_CONTAINER,
838 useExisting: MatSidenavContainer
839 }],
840 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-container-has-open{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:400ms;transition-timing-function:cubic-bezier(0.25, 0.8, 0.25, 1);transition-property:background-color,visibility}.cdk-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:400ms;transition-timing-function:cubic-bezier(0.25, 0.8, 0.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)}.cdk-high-contrast-active .mat-drawer,.cdk-high-contrast-active [dir=rtl] .mat-drawer.mat-drawer-end{border-right:solid 1px currentColor}.cdk-high-contrast-active [dir=rtl] .mat-drawer,.cdk-high-contrast-active .mat-drawer.mat-drawer-end{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}\n"]
841 },] }
842];
843MatSidenavContainer.propDecorators = {
844 _allDrawers: [{ type: ContentChildren, args: [MatSidenav, {
845 // We need to use `descendants: true`, because Ivy will no longer match
846 // indirect descendants if it's left as false.
847 descendants: true
848 },] }],
849 _content: [{ type: ContentChild, args: [MatSidenavContent,] }]
850};
851
852/**
853 * @license
854 * Copyright Google LLC All Rights Reserved.
855 *
856 * Use of this source code is governed by an MIT-style license that can be
857 * found in the LICENSE file at https://angular.io/license
858 */
859class MatSidenavModule {
860}
861MatSidenavModule.decorators = [
862 { type: NgModule, args: [{
863 imports: [
864 CommonModule,
865 MatCommonModule,
866 PlatformModule,
867 CdkScrollableModule,
868 ],
869 exports: [
870 CdkScrollableModule,
871 MatCommonModule,
872 MatDrawer,
873 MatDrawerContainer,
874 MatDrawerContent,
875 MatSidenav,
876 MatSidenavContainer,
877 MatSidenavContent,
878 ],
879 declarations: [
880 MatDrawer,
881 MatDrawerContainer,
882 MatDrawerContent,
883 MatSidenav,
884 MatSidenavContainer,
885 MatSidenavContent,
886 ],
887 },] }
888];
889
890/**
891 * @license
892 * Copyright Google LLC All Rights Reserved.
893 *
894 * Use of this source code is governed by an MIT-style license that can be
895 * found in the LICENSE file at https://angular.io/license
896 */
897
898/**
899 * Generated bundle index. Do not edit.
900 */
901
902export { MAT_DRAWER_DEFAULT_AUTOSIZE, MAT_DRAWER_DEFAULT_AUTOSIZE_FACTORY, MatDrawer, MatDrawerContainer, MatDrawerContent, MatSidenav, MatSidenavContainer, MatSidenavContent, MatSidenavModule, matDrawerAnimations, throwMatDuplicatedDrawerError, MAT_DRAWER_CONTAINER as ɵangular_material_src_material_sidenav_sidenav_a };
903//# sourceMappingURL=sidenav.js.map
Note: See TracBrowser for help on using the repository browser.