source: trip-planner-front/node_modules/@angular/material/fesm2015/snack-bar.js@ fa375fe

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

initial commit

  • Property mode set to 100644
File size: 30.2 KB
RevLine 
[6a3a178]1import * as i1 from '@angular/cdk/overlay';
2import { OverlayModule, OverlayConfig, Overlay } from '@angular/cdk/overlay';
3import { BasePortalOutlet, CdkPortalOutlet, PortalModule, ComponentPortal, TemplatePortal } from '@angular/cdk/portal';
4import { CommonModule } from '@angular/common';
5import * as i0 from '@angular/core';
6import { InjectionToken, Component, ViewEncapsulation, ChangeDetectionStrategy, Inject, NgZone, ElementRef, ChangeDetectorRef, ViewChild, NgModule, Injector, TemplateRef, Injectable, Optional, SkipSelf } from '@angular/core';
7import { MatCommonModule } from '@angular/material/core';
8import { MatButtonModule } from '@angular/material/button';
9import { Subject } from 'rxjs';
10import { Platform } from '@angular/cdk/platform';
11import { take, takeUntil } from 'rxjs/operators';
12import { trigger, state, style, transition, animate } from '@angular/animations';
13import * as i2 from '@angular/cdk/a11y';
14import { LiveAnnouncer } from '@angular/cdk/a11y';
15import * as i3 from '@angular/cdk/layout';
16import { Breakpoints, BreakpointObserver } from '@angular/cdk/layout';
17
18/**
19 * @license
20 * Copyright Google LLC All Rights Reserved.
21 *
22 * Use of this source code is governed by an MIT-style license that can be
23 * found in the LICENSE file at https://angular.io/license
24 */
25/** Injection token that can be used to access the data that was passed in to a snack bar. */
26const MAT_SNACK_BAR_DATA = new InjectionToken('MatSnackBarData');
27/**
28 * Configuration used when opening a snack-bar.
29 */
30class MatSnackBarConfig {
31 constructor() {
32 /** The politeness level for the MatAriaLiveAnnouncer announcement. */
33 this.politeness = 'assertive';
34 /**
35 * Message to be announced by the LiveAnnouncer. When opening a snackbar without a custom
36 * component or template, the announcement message will default to the specified message.
37 */
38 this.announcementMessage = '';
39 /** The length of time in milliseconds to wait before automatically dismissing the snack bar. */
40 this.duration = 0;
41 /** Data being injected into the child component. */
42 this.data = null;
43 /** The horizontal position to place the snack bar. */
44 this.horizontalPosition = 'center';
45 /** The vertical position to place the snack bar. */
46 this.verticalPosition = 'bottom';
47 }
48}
49
50/**
51 * @license
52 * Copyright Google LLC All Rights Reserved.
53 *
54 * Use of this source code is governed by an MIT-style license that can be
55 * found in the LICENSE file at https://angular.io/license
56 */
57/** Maximum amount of milliseconds that can be passed into setTimeout. */
58const MAX_TIMEOUT = Math.pow(2, 31) - 1;
59/**
60 * Reference to a snack bar dispatched from the snack bar service.
61 */
62class MatSnackBarRef {
63 constructor(containerInstance, _overlayRef) {
64 this._overlayRef = _overlayRef;
65 /** Subject for notifying the user that the snack bar has been dismissed. */
66 this._afterDismissed = new Subject();
67 /** Subject for notifying the user that the snack bar has opened and appeared. */
68 this._afterOpened = new Subject();
69 /** Subject for notifying the user that the snack bar action was called. */
70 this._onAction = new Subject();
71 /** Whether the snack bar was dismissed using the action button. */
72 this._dismissedByAction = false;
73 this.containerInstance = containerInstance;
74 // Dismiss snackbar on action.
75 this.onAction().subscribe(() => this.dismiss());
76 containerInstance._onExit.subscribe(() => this._finishDismiss());
77 }
78 /** Dismisses the snack bar. */
79 dismiss() {
80 if (!this._afterDismissed.closed) {
81 this.containerInstance.exit();
82 }
83 clearTimeout(this._durationTimeoutId);
84 }
85 /** Marks the snackbar action clicked. */
86 dismissWithAction() {
87 if (!this._onAction.closed) {
88 this._dismissedByAction = true;
89 this._onAction.next();
90 this._onAction.complete();
91 }
92 clearTimeout(this._durationTimeoutId);
93 }
94 /**
95 * Marks the snackbar action clicked.
96 * @deprecated Use `dismissWithAction` instead.
97 * @breaking-change 8.0.0
98 */
99 closeWithAction() {
100 this.dismissWithAction();
101 }
102 /** Dismisses the snack bar after some duration */
103 _dismissAfter(duration) {
104 // Note that we need to cap the duration to the maximum value for setTimeout, because
105 // it'll revert to 1 if somebody passes in something greater (e.g. `Infinity`). See #17234.
106 this._durationTimeoutId = setTimeout(() => this.dismiss(), Math.min(duration, MAX_TIMEOUT));
107 }
108 /** Marks the snackbar as opened */
109 _open() {
110 if (!this._afterOpened.closed) {
111 this._afterOpened.next();
112 this._afterOpened.complete();
113 }
114 }
115 /** Cleans up the DOM after closing. */
116 _finishDismiss() {
117 this._overlayRef.dispose();
118 if (!this._onAction.closed) {
119 this._onAction.complete();
120 }
121 this._afterDismissed.next({ dismissedByAction: this._dismissedByAction });
122 this._afterDismissed.complete();
123 this._dismissedByAction = false;
124 }
125 /** Gets an observable that is notified when the snack bar is finished closing. */
126 afterDismissed() {
127 return this._afterDismissed;
128 }
129 /** Gets an observable that is notified when the snack bar has opened and appeared. */
130 afterOpened() {
131 return this.containerInstance._onEnter;
132 }
133 /** Gets an observable that is notified when the snack bar action is called. */
134 onAction() {
135 return this._onAction;
136 }
137}
138
139/**
140 * @license
141 * Copyright Google LLC All Rights Reserved.
142 *
143 * Use of this source code is governed by an MIT-style license that can be
144 * found in the LICENSE file at https://angular.io/license
145 */
146/**
147 * A component used to open as the default snack bar, matching material spec.
148 * This should only be used internally by the snack bar service.
149 */
150class SimpleSnackBar {
151 constructor(snackBarRef, data) {
152 this.snackBarRef = snackBarRef;
153 this.data = data;
154 }
155 /** Performs the action on the snack bar. */
156 action() {
157 this.snackBarRef.dismissWithAction();
158 }
159 /** If the action button should be shown. */
160 get hasAction() {
161 return !!this.data.action;
162 }
163}
164SimpleSnackBar.decorators = [
165 { type: Component, args: [{
166 selector: 'simple-snack-bar',
167 template: "<span>{{data.message}}</span>\n<div class=\"mat-simple-snackbar-action\" *ngIf=\"hasAction\">\n <button mat-button (click)=\"action()\">{{data.action}}</button>\n</div>\n",
168 encapsulation: ViewEncapsulation.None,
169 changeDetection: ChangeDetectionStrategy.OnPush,
170 host: {
171 'class': 'mat-simple-snackbar',
172 },
173 styles: [".mat-simple-snackbar{display:flex;justify-content:space-between;align-items:center;line-height:20px;opacity:1}.mat-simple-snackbar-action{flex-shrink:0;margin:-8px -8px -8px 8px}.mat-simple-snackbar-action button{max-height:36px;min-width:0}[dir=rtl] .mat-simple-snackbar-action{margin-left:-8px;margin-right:8px}\n"]
174 },] }
175];
176SimpleSnackBar.ctorParameters = () => [
177 { type: MatSnackBarRef },
178 { type: undefined, decorators: [{ type: Inject, args: [MAT_SNACK_BAR_DATA,] }] }
179];
180
181/**
182 * @license
183 * Copyright Google LLC All Rights Reserved.
184 *
185 * Use of this source code is governed by an MIT-style license that can be
186 * found in the LICENSE file at https://angular.io/license
187 */
188/**
189 * Animations used by the Material snack bar.
190 * @docs-private
191 */
192const matSnackBarAnimations = {
193 /** Animation that shows and hides a snack bar. */
194 snackBarState: trigger('state', [
195 state('void, hidden', style({
196 transform: 'scale(0.8)',
197 opacity: 0,
198 })),
199 state('visible', style({
200 transform: 'scale(1)',
201 opacity: 1,
202 })),
203 transition('* => visible', animate('150ms cubic-bezier(0, 0, 0.2, 1)')),
204 transition('* => void, * => hidden', animate('75ms cubic-bezier(0.4, 0.0, 1, 1)', style({
205 opacity: 0
206 }))),
207 ])
208};
209
210/**
211 * @license
212 * Copyright Google LLC All Rights Reserved.
213 *
214 * Use of this source code is governed by an MIT-style license that can be
215 * found in the LICENSE file at https://angular.io/license
216 */
217/**
218 * Internal component that wraps user-provided snack bar content.
219 * @docs-private
220 */
221class MatSnackBarContainer extends BasePortalOutlet {
222 constructor(_ngZone, _elementRef, _changeDetectorRef, _platform,
223 /** The snack bar configuration. */
224 snackBarConfig) {
225 super();
226 this._ngZone = _ngZone;
227 this._elementRef = _elementRef;
228 this._changeDetectorRef = _changeDetectorRef;
229 this._platform = _platform;
230 this.snackBarConfig = snackBarConfig;
231 /** The number of milliseconds to wait before announcing the snack bar's content. */
232 this._announceDelay = 150;
233 /** Whether the component has been destroyed. */
234 this._destroyed = false;
235 /** Subject for notifying that the snack bar has announced to screen readers. */
236 this._onAnnounce = new Subject();
237 /** Subject for notifying that the snack bar has exited from view. */
238 this._onExit = new Subject();
239 /** Subject for notifying that the snack bar has finished entering the view. */
240 this._onEnter = new Subject();
241 /** The state of the snack bar animations. */
242 this._animationState = 'void';
243 /**
244 * Attaches a DOM portal to the snack bar container.
245 * @deprecated To be turned into a method.
246 * @breaking-change 10.0.0
247 */
248 this.attachDomPortal = (portal) => {
249 this._assertNotAttached();
250 this._applySnackBarClasses();
251 return this._portalOutlet.attachDomPortal(portal);
252 };
253 // Use aria-live rather than a live role like 'alert' or 'status'
254 // because NVDA and JAWS have show inconsistent behavior with live roles.
255 if (snackBarConfig.politeness === 'assertive' && !snackBarConfig.announcementMessage) {
256 this._live = 'assertive';
257 }
258 else if (snackBarConfig.politeness === 'off') {
259 this._live = 'off';
260 }
261 else {
262 this._live = 'polite';
263 }
264 // Only set role for Firefox. Set role based on aria-live because setting role="alert" implies
265 // aria-live="assertive" which may cause issues if aria-live is set to "polite" above.
266 if (this._platform.FIREFOX) {
267 if (this._live === 'polite') {
268 this._role = 'status';
269 }
270 if (this._live === 'assertive') {
271 this._role = 'alert';
272 }
273 }
274 }
275 /** Attach a component portal as content to this snack bar container. */
276 attachComponentPortal(portal) {
277 this._assertNotAttached();
278 this._applySnackBarClasses();
279 return this._portalOutlet.attachComponentPortal(portal);
280 }
281 /** Attach a template portal as content to this snack bar container. */
282 attachTemplatePortal(portal) {
283 this._assertNotAttached();
284 this._applySnackBarClasses();
285 return this._portalOutlet.attachTemplatePortal(portal);
286 }
287 /** Handle end of animations, updating the state of the snackbar. */
288 onAnimationEnd(event) {
289 const { fromState, toState } = event;
290 if ((toState === 'void' && fromState !== 'void') || toState === 'hidden') {
291 this._completeExit();
292 }
293 if (toState === 'visible') {
294 // Note: we shouldn't use `this` inside the zone callback,
295 // because it can cause a memory leak.
296 const onEnter = this._onEnter;
297 this._ngZone.run(() => {
298 onEnter.next();
299 onEnter.complete();
300 });
301 }
302 }
303 /** Begin animation of snack bar entrance into view. */
304 enter() {
305 if (!this._destroyed) {
306 this._animationState = 'visible';
307 this._changeDetectorRef.detectChanges();
308 this._screenReaderAnnounce();
309 }
310 }
311 /** Begin animation of the snack bar exiting from view. */
312 exit() {
313 // Note: this one transitions to `hidden`, rather than `void`, in order to handle the case
314 // where multiple snack bars are opened in quick succession (e.g. two consecutive calls to
315 // `MatSnackBar.open`).
316 this._animationState = 'hidden';
317 // Mark this element with an 'exit' attribute to indicate that the snackbar has
318 // been dismissed and will soon be removed from the DOM. This is used by the snackbar
319 // test harness.
320 this._elementRef.nativeElement.setAttribute('mat-exit', '');
321 // If the snack bar hasn't been announced by the time it exits it wouldn't have been open
322 // long enough to visually read it either, so clear the timeout for announcing.
323 clearTimeout(this._announceTimeoutId);
324 return this._onExit;
325 }
326 /** Makes sure the exit callbacks have been invoked when the element is destroyed. */
327 ngOnDestroy() {
328 this._destroyed = true;
329 this._completeExit();
330 }
331 /**
332 * Waits for the zone to settle before removing the element. Helps prevent
333 * errors where we end up removing an element which is in the middle of an animation.
334 */
335 _completeExit() {
336 this._ngZone.onMicrotaskEmpty.pipe(take(1)).subscribe(() => {
337 this._onExit.next();
338 this._onExit.complete();
339 });
340 }
341 /** Applies the various positioning and user-configured CSS classes to the snack bar. */
342 _applySnackBarClasses() {
343 const element = this._elementRef.nativeElement;
344 const panelClasses = this.snackBarConfig.panelClass;
345 if (panelClasses) {
346 if (Array.isArray(panelClasses)) {
347 // Note that we can't use a spread here, because IE doesn't support multiple arguments.
348 panelClasses.forEach(cssClass => element.classList.add(cssClass));
349 }
350 else {
351 element.classList.add(panelClasses);
352 }
353 }
354 if (this.snackBarConfig.horizontalPosition === 'center') {
355 element.classList.add('mat-snack-bar-center');
356 }
357 if (this.snackBarConfig.verticalPosition === 'top') {
358 element.classList.add('mat-snack-bar-top');
359 }
360 }
361 /** Asserts that no content is already attached to the container. */
362 _assertNotAttached() {
363 if (this._portalOutlet.hasAttached() && (typeof ngDevMode === 'undefined' || ngDevMode)) {
364 throw Error('Attempting to attach snack bar content after content is already attached');
365 }
366 }
367 /**
368 * Starts a timeout to move the snack bar content to the live region so screen readers will
369 * announce it.
370 */
371 _screenReaderAnnounce() {
372 if (!this._announceTimeoutId) {
373 this._ngZone.runOutsideAngular(() => {
374 this._announceTimeoutId = setTimeout(() => {
375 const inertElement = this._elementRef.nativeElement.querySelector('[aria-hidden]');
376 const liveElement = this._elementRef.nativeElement.querySelector('[aria-live]');
377 if (inertElement && liveElement) {
378 // If an element in the snack bar content is focused before being moved
379 // track it and restore focus after moving to the live region.
380 let focusedElement = null;
381 if (this._platform.isBrowser &&
382 document.activeElement instanceof HTMLElement &&
383 inertElement.contains(document.activeElement)) {
384 focusedElement = document.activeElement;
385 }
386 inertElement.removeAttribute('aria-hidden');
387 liveElement.appendChild(inertElement);
388 focusedElement === null || focusedElement === void 0 ? void 0 : focusedElement.focus();
389 this._onAnnounce.next();
390 this._onAnnounce.complete();
391 }
392 }, this._announceDelay);
393 });
394 }
395 }
396}
397MatSnackBarContainer.decorators = [
398 { type: Component, args: [{
399 selector: 'snack-bar-container',
400 template: "<!-- Initially holds the snack bar content, will be empty after announcing to screen readers. -->\n<div aria-hidden=\"true\">\n <ng-template cdkPortalOutlet></ng-template>\n</div>\n\n<!-- Will receive the snack bar content from the non-live div, move will happen a short delay after opening -->\n<div [attr.aria-live]=\"_live\" [attr.role]=\"_role\"></div>\n",
401 // In Ivy embedded views will be change detected from their declaration place, rather than
402 // where they were stamped out. This means that we can't have the snack bar container be OnPush,
403 // because it might cause snack bars that were opened from a template not to be out of date.
404 // tslint:disable-next-line:validate-decorators
405 changeDetection: ChangeDetectionStrategy.Default,
406 encapsulation: ViewEncapsulation.None,
407 animations: [matSnackBarAnimations.snackBarState],
408 host: {
409 'class': 'mat-snack-bar-container',
410 '[@state]': '_animationState',
411 '(@state.done)': 'onAnimationEnd($event)'
412 },
413 styles: [".mat-snack-bar-container{border-radius:4px;box-sizing:border-box;display:block;margin:24px;max-width:33vw;min-width:344px;padding:14px 16px;min-height:48px;transform-origin:center}.cdk-high-contrast-active .mat-snack-bar-container{border:solid 1px}.mat-snack-bar-handset{width:100%}.mat-snack-bar-handset .mat-snack-bar-container{margin:8px;max-width:100%;min-width:0;width:100%}\n"]
414 },] }
415];
416MatSnackBarContainer.ctorParameters = () => [
417 { type: NgZone },
418 { type: ElementRef },
419 { type: ChangeDetectorRef },
420 { type: Platform },
421 { type: MatSnackBarConfig }
422];
423MatSnackBarContainer.propDecorators = {
424 _portalOutlet: [{ type: ViewChild, args: [CdkPortalOutlet, { static: true },] }]
425};
426
427/**
428 * @license
429 * Copyright Google LLC All Rights Reserved.
430 *
431 * Use of this source code is governed by an MIT-style license that can be
432 * found in the LICENSE file at https://angular.io/license
433 */
434class MatSnackBarModule {
435}
436MatSnackBarModule.decorators = [
437 { type: NgModule, args: [{
438 imports: [
439 OverlayModule,
440 PortalModule,
441 CommonModule,
442 MatButtonModule,
443 MatCommonModule,
444 ],
445 exports: [MatSnackBarContainer, MatCommonModule],
446 declarations: [MatSnackBarContainer, SimpleSnackBar],
447 entryComponents: [MatSnackBarContainer, SimpleSnackBar],
448 },] }
449];
450
451/**
452 * @license
453 * Copyright Google LLC All Rights Reserved.
454 *
455 * Use of this source code is governed by an MIT-style license that can be
456 * found in the LICENSE file at https://angular.io/license
457 */
458/** Injection token that can be used to specify default snack bar. */
459const MAT_SNACK_BAR_DEFAULT_OPTIONS = new InjectionToken('mat-snack-bar-default-options', {
460 providedIn: 'root',
461 factory: MAT_SNACK_BAR_DEFAULT_OPTIONS_FACTORY,
462});
463/** @docs-private */
464function MAT_SNACK_BAR_DEFAULT_OPTIONS_FACTORY() {
465 return new MatSnackBarConfig();
466}
467/**
468 * Service to dispatch Material Design snack bar messages.
469 */
470class MatSnackBar {
471 constructor(_overlay, _live, _injector, _breakpointObserver, _parentSnackBar, _defaultConfig) {
472 this._overlay = _overlay;
473 this._live = _live;
474 this._injector = _injector;
475 this._breakpointObserver = _breakpointObserver;
476 this._parentSnackBar = _parentSnackBar;
477 this._defaultConfig = _defaultConfig;
478 /**
479 * Reference to the current snack bar in the view *at this level* (in the Angular injector tree).
480 * If there is a parent snack-bar service, all operations should delegate to that parent
481 * via `_openedSnackBarRef`.
482 */
483 this._snackBarRefAtThisLevel = null;
484 /** The component that should be rendered as the snack bar's simple component. */
485 this.simpleSnackBarComponent = SimpleSnackBar;
486 /** The container component that attaches the provided template or component. */
487 this.snackBarContainerComponent = MatSnackBarContainer;
488 /** The CSS class to apply for handset mode. */
489 this.handsetCssClass = 'mat-snack-bar-handset';
490 }
491 /** Reference to the currently opened snackbar at *any* level. */
492 get _openedSnackBarRef() {
493 const parent = this._parentSnackBar;
494 return parent ? parent._openedSnackBarRef : this._snackBarRefAtThisLevel;
495 }
496 set _openedSnackBarRef(value) {
497 if (this._parentSnackBar) {
498 this._parentSnackBar._openedSnackBarRef = value;
499 }
500 else {
501 this._snackBarRefAtThisLevel = value;
502 }
503 }
504 /**
505 * Creates and dispatches a snack bar with a custom component for the content, removing any
506 * currently opened snack bars.
507 *
508 * @param component Component to be instantiated.
509 * @param config Extra configuration for the snack bar.
510 */
511 openFromComponent(component, config) {
512 return this._attach(component, config);
513 }
514 /**
515 * Creates and dispatches a snack bar with a custom template for the content, removing any
516 * currently opened snack bars.
517 *
518 * @param template Template to be instantiated.
519 * @param config Extra configuration for the snack bar.
520 */
521 openFromTemplate(template, config) {
522 return this._attach(template, config);
523 }
524 /**
525 * Opens a snackbar with a message and an optional action.
526 * @param message The message to show in the snackbar.
527 * @param action The label for the snackbar action.
528 * @param config Additional configuration options for the snackbar.
529 */
530 open(message, action = '', config) {
531 const _config = Object.assign(Object.assign({}, this._defaultConfig), config);
532 // Since the user doesn't have access to the component, we can
533 // override the data to pass in our own message and action.
534 _config.data = { message, action };
535 // Since the snack bar has `role="alert"`, we don't
536 // want to announce the same message twice.
537 if (_config.announcementMessage === message) {
538 _config.announcementMessage = undefined;
539 }
540 return this.openFromComponent(this.simpleSnackBarComponent, _config);
541 }
542 /**
543 * Dismisses the currently-visible snack bar.
544 */
545 dismiss() {
546 if (this._openedSnackBarRef) {
547 this._openedSnackBarRef.dismiss();
548 }
549 }
550 ngOnDestroy() {
551 // Only dismiss the snack bar at the current level on destroy.
552 if (this._snackBarRefAtThisLevel) {
553 this._snackBarRefAtThisLevel.dismiss();
554 }
555 }
556 /**
557 * Attaches the snack bar container component to the overlay.
558 */
559 _attachSnackBarContainer(overlayRef, config) {
560 const userInjector = config && config.viewContainerRef && config.viewContainerRef.injector;
561 const injector = Injector.create({
562 parent: userInjector || this._injector,
563 providers: [{ provide: MatSnackBarConfig, useValue: config }]
564 });
565 const containerPortal = new ComponentPortal(this.snackBarContainerComponent, config.viewContainerRef, injector);
566 const containerRef = overlayRef.attach(containerPortal);
567 containerRef.instance.snackBarConfig = config;
568 return containerRef.instance;
569 }
570 /**
571 * Places a new component or a template as the content of the snack bar container.
572 */
573 _attach(content, userConfig) {
574 const config = Object.assign(Object.assign(Object.assign({}, new MatSnackBarConfig()), this._defaultConfig), userConfig);
575 const overlayRef = this._createOverlay(config);
576 const container = this._attachSnackBarContainer(overlayRef, config);
577 const snackBarRef = new MatSnackBarRef(container, overlayRef);
578 if (content instanceof TemplateRef) {
579 const portal = new TemplatePortal(content, null, {
580 $implicit: config.data,
581 snackBarRef
582 });
583 snackBarRef.instance = container.attachTemplatePortal(portal);
584 }
585 else {
586 const injector = this._createInjector(config, snackBarRef);
587 const portal = new ComponentPortal(content, undefined, injector);
588 const contentRef = container.attachComponentPortal(portal);
589 // We can't pass this via the injector, because the injector is created earlier.
590 snackBarRef.instance = contentRef.instance;
591 }
592 // Subscribe to the breakpoint observer and attach the mat-snack-bar-handset class as
593 // appropriate. This class is applied to the overlay element because the overlay must expand to
594 // fill the width of the screen for full width snackbars.
595 this._breakpointObserver.observe(Breakpoints.HandsetPortrait).pipe(takeUntil(overlayRef.detachments())).subscribe(state => {
596 const classList = overlayRef.overlayElement.classList;
597 state.matches ? classList.add(this.handsetCssClass) : classList.remove(this.handsetCssClass);
598 });
599 if (config.announcementMessage) {
600 // Wait until the snack bar contents have been announced then deliver this message.
601 container._onAnnounce.subscribe(() => {
602 this._live.announce(config.announcementMessage, config.politeness);
603 });
604 }
605 this._animateSnackBar(snackBarRef, config);
606 this._openedSnackBarRef = snackBarRef;
607 return this._openedSnackBarRef;
608 }
609 /** Animates the old snack bar out and the new one in. */
610 _animateSnackBar(snackBarRef, config) {
611 // When the snackbar is dismissed, clear the reference to it.
612 snackBarRef.afterDismissed().subscribe(() => {
613 // Clear the snackbar ref if it hasn't already been replaced by a newer snackbar.
614 if (this._openedSnackBarRef == snackBarRef) {
615 this._openedSnackBarRef = null;
616 }
617 if (config.announcementMessage) {
618 this._live.clear();
619 }
620 });
621 if (this._openedSnackBarRef) {
622 // If a snack bar is already in view, dismiss it and enter the
623 // new snack bar after exit animation is complete.
624 this._openedSnackBarRef.afterDismissed().subscribe(() => {
625 snackBarRef.containerInstance.enter();
626 });
627 this._openedSnackBarRef.dismiss();
628 }
629 else {
630 // If no snack bar is in view, enter the new snack bar.
631 snackBarRef.containerInstance.enter();
632 }
633 // If a dismiss timeout is provided, set up dismiss based on after the snackbar is opened.
634 if (config.duration && config.duration > 0) {
635 snackBarRef.afterOpened().subscribe(() => snackBarRef._dismissAfter(config.duration));
636 }
637 }
638 /**
639 * Creates a new overlay and places it in the correct location.
640 * @param config The user-specified snack bar config.
641 */
642 _createOverlay(config) {
643 const overlayConfig = new OverlayConfig();
644 overlayConfig.direction = config.direction;
645 let positionStrategy = this._overlay.position().global();
646 // Set horizontal position.
647 const isRtl = config.direction === 'rtl';
648 const isLeft = (config.horizontalPosition === 'left' ||
649 (config.horizontalPosition === 'start' && !isRtl) ||
650 (config.horizontalPosition === 'end' && isRtl));
651 const isRight = !isLeft && config.horizontalPosition !== 'center';
652 if (isLeft) {
653 positionStrategy.left('0');
654 }
655 else if (isRight) {
656 positionStrategy.right('0');
657 }
658 else {
659 positionStrategy.centerHorizontally();
660 }
661 // Set horizontal position.
662 if (config.verticalPosition === 'top') {
663 positionStrategy.top('0');
664 }
665 else {
666 positionStrategy.bottom('0');
667 }
668 overlayConfig.positionStrategy = positionStrategy;
669 return this._overlay.create(overlayConfig);
670 }
671 /**
672 * Creates an injector to be used inside of a snack bar component.
673 * @param config Config that was used to create the snack bar.
674 * @param snackBarRef Reference to the snack bar.
675 */
676 _createInjector(config, snackBarRef) {
677 const userInjector = config && config.viewContainerRef && config.viewContainerRef.injector;
678 return Injector.create({
679 parent: userInjector || this._injector,
680 providers: [
681 { provide: MatSnackBarRef, useValue: snackBarRef },
682 { provide: MAT_SNACK_BAR_DATA, useValue: config.data }
683 ]
684 });
685 }
686}
687MatSnackBar.ɵprov = i0.ɵɵdefineInjectable({ factory: function MatSnackBar_Factory() { return new MatSnackBar(i0.ɵɵinject(i1.Overlay), i0.ɵɵinject(i2.LiveAnnouncer), i0.ɵɵinject(i0.INJECTOR), i0.ɵɵinject(i3.BreakpointObserver), i0.ɵɵinject(MatSnackBar, 12), i0.ɵɵinject(MAT_SNACK_BAR_DEFAULT_OPTIONS)); }, token: MatSnackBar, providedIn: MatSnackBarModule });
688MatSnackBar.decorators = [
689 { type: Injectable, args: [{ providedIn: MatSnackBarModule },] }
690];
691MatSnackBar.ctorParameters = () => [
692 { type: Overlay },
693 { type: LiveAnnouncer },
694 { type: Injector },
695 { type: BreakpointObserver },
696 { type: MatSnackBar, decorators: [{ type: Optional }, { type: SkipSelf }] },
697 { type: MatSnackBarConfig, decorators: [{ type: Inject, args: [MAT_SNACK_BAR_DEFAULT_OPTIONS,] }] }
698];
699
700/**
701 * @license
702 * Copyright Google LLC All Rights Reserved.
703 *
704 * Use of this source code is governed by an MIT-style license that can be
705 * found in the LICENSE file at https://angular.io/license
706 */
707
708/**
709 * Generated bundle index. Do not edit.
710 */
711
712export { MAT_SNACK_BAR_DATA, MAT_SNACK_BAR_DEFAULT_OPTIONS, MAT_SNACK_BAR_DEFAULT_OPTIONS_FACTORY, MatSnackBar, MatSnackBarConfig, MatSnackBarContainer, MatSnackBarModule, MatSnackBarRef, SimpleSnackBar, matSnackBarAnimations };
713//# sourceMappingURL=snack-bar.js.map
Note: See TracBrowser for help on using the repository browser.