@angular-mdc/web
Version:
22 lines (20 loc) • 17.2 kB
JavaScript
/**
* @license
* Copyright (c) Dominic Carretto
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://github.com/trimox/angular-mdc-web/blob/master/LICENSE
*/
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("@angular/core"),require("@angular/cdk/overlay"),require("@angular/cdk/portal"),require("@angular/cdk/platform"),require("rxjs"),require("rxjs/operators"),require("@angular-mdc/web/base"),require("@angular/cdk/coercion"),require("@angular-mdc/web/button"),require("@angular-mdc/web/ripple"),require("@angular-mdc/web/dom"),require("@material/dialog"),require("@angular/common"),require("@angular/cdk/a11y")):"function"==typeof define&&define.amd?define("@angular-mdc/web/dialog",["exports","@angular/core","@angular/cdk/overlay","@angular/cdk/portal","@angular/cdk/platform","rxjs","rxjs/operators","@angular-mdc/web/base","@angular/cdk/coercion","@angular-mdc/web/button","@angular-mdc/web/ripple","@angular-mdc/web/dom","@material/dialog","@angular/common","@angular/cdk/a11y"],e):e(((t=t||self).ng=t.ng||{},t.ng.web=t.ng.web||{},t.ng.web.dialog={}),t.ng.core,t.ng.cdk.overlay,t.ng.cdk.portal,t.ng.cdk.platform,t.rxjs,t.rxjs.operators,t.ng.web.base,t.ng.cdk.coercion,t.ng.web.button,t.ng.web.ripple,t.ng.web.dom,t.mdc.dialog,t.ng.common,t.ng.cdk.a11y)}(this,(function(t,e,o,n,r,i,a,c,s,l,u,d,p,f,g){"use strict";
/*! *****************************************************************************
Copyright (c) Microsoft Corporation. All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License"); you may not use
this file except in compliance with the License. You may obtain a copy of the
License at http://www.apache.org/licenses/LICENSE-2.0
THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
MERCHANTABLITY OR NON-INFRINGEMENT.
See the Apache Version 2.0 License for specific language governing permissions
and limitations under the License.
***************************************************************************** */var h=function(t,e){return(h=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var o in e)e.hasOwnProperty(o)&&(t[o]=e[o])})(t,e)};function m(t,e){function o(){this.constructor=t}h(t,e),t.prototype=null===e?Object.create(e):(o.prototype=e.prototype,new o)}var _=function(){return(_=Object.assign||function(t){for(var e,o=1,n=arguments.length;o<n;o++)for(var r in e=arguments[o])Object.prototype.hasOwnProperty.call(e,r)&&(t[r]=e[r]);return t}).apply(this,arguments)},y=function(){function t(t){this.elementRef=t,this._action=""}return Object.defineProperty(t.prototype,"action",{get:function(){return this._action},set:function(t){t&&(this._action=t,this.elementRef.nativeElement.setAttribute("data-mdc-dialog-action",this._action))},enumerable:!0,configurable:!0}),t.decorators=[{type:e.Directive,args:[{selector:"[mdcDialogAction]"}]}],t.ctorParameters=function(){return[{type:e.ElementRef}]},t.propDecorators={action:[{type:e.Input,args:["mdcDialogAction"]}]},t}(),v=function(){function t(t){this.elementRef=t}return t.decorators=[{type:e.Directive,args:[{selector:"mdc-dialog-scrim",host:{class:"mdc-dialog__scrim"}}]}],t.ctorParameters=function(){return[{type:e.ElementRef}]},t}(),b=function(){function t(t){this.elementRef=t}return t.decorators=[{type:e.Directive,args:[{selector:"[mdcDialogContainer], mdc-dialog-container",host:{class:"mdc-dialog__container"}}]}],t.ctorParameters=function(){return[{type:e.ElementRef}]},t}(),D=function(){function t(t){this.elementRef=t}return t.decorators=[{type:e.Directive,args:[{selector:"[mdcDialogSurface], mdc-dialog-surface",host:{class:"mdc-dialog__surface"}}]}],t.ctorParameters=function(){return[{type:e.ElementRef}]},t}(),C=function(){function t(t){this.elementRef=t}return t.decorators=[{type:e.Directive,args:[{selector:"[mdcDialogTitle], mdc-dialog-title",host:{class:"mdc-dialog__title"}}]}],t.ctorParameters=function(){return[{type:e.ElementRef}]},t}(),O=function(){function t(t){this.elementRef=t}return t.decorators=[{type:e.Directive,args:[{selector:"[mdcDialogContent], mdc-dialog-content",host:{class:"mdc-dialog__content"}}]}],t.ctorParameters=function(){return[{type:e.ElementRef}]},t}(),w=function(){function t(t){this.elementRef=t,this._stacked=!1}return Object.defineProperty(t.prototype,"stacked",{get:function(){return this._stacked},set:function(t){this._stacked=s.coerceBooleanProperty(t)},enumerable:!0,configurable:!0}),t.decorators=[{type:e.Component,args:[{selector:"mdc-dialog-actions, [mdcDialogActions]",template:"<ng-content></ng-content>",exportAs:"mdcDialogActions",host:{class:"mdc-dialog__actions","[class.mdc-dialog--stacked]":"stacked"},encapsulation:e.ViewEncapsulation.None,changeDetection:e.ChangeDetectionStrategy.OnPush}]}],t.ctorParameters=function(){return[{type:e.ElementRef}]},t.propDecorators={stacked:[{type:e.Input}]},t}(),A=function(t){function o(){var e=null!==t&&t.apply(this,arguments)||this;return e._default=!1,e}return m(o,t),Object.defineProperty(o.prototype,"default",{get:function(){return this._default},set:function(t){this._default=s.coerceBooleanProperty(t)},enumerable:!0,configurable:!0}),o.decorators=[{type:e.Component,args:[{selector:"[mdcDialogButton]",exportAs:"mdcDialogButton",host:{class:"mdc-dialog__button","[class.mdc-button]":"true","[class.mdc-dialog__button--default]":"default"},template:'\n <div class="mdc-button__ripple"></div>\n <ng-content></ng-content>',providers:[u.MdcRipple],encapsulation:e.ViewEncapsulation.None,changeDetection:e.ChangeDetectionStrategy.OnPush}]}],o.propDecorators={default:[{type:e.Input}]},o}(l.MdcButton),E=0,P=function(){function t(t,e,o){var n=this;void 0===o&&(o="mdc-dialog-"+E++),this._overlayRef=t,this._portalInstance=e,this.id=o,this._afterOpened=new i.Subject,this._beforeClosed=new i.Subject,this._afterClosed=new i.Subject,e._id=o,t.detachments().subscribe((function(){n._beforeClosed.next(n._result),n._beforeClosed.complete(),n._afterClosed.next(n._result),n._afterClosed.complete(),n.componentInstance=null,n._overlayRef.dispose()}))}return t.prototype.close=function(t){this._result=t,this._overlayRef.dispose()},t.prototype.opened=function(){this._afterOpened.closed||(this._afterOpened.next(),this._afterOpened.complete())},t.prototype.afterOpened=function(){return this._afterOpened.asObservable()},t.prototype.beforeClosed=function(){return this._beforeClosed.asObservable()},t.prototype.afterClosed=function(){return this._afterClosed.asObservable()},t}(),R=["resize","orientationchange"],k=function(t){function o(e,o,n,r){var a=t.call(this,n)||this;return a._ngZone=e,a._platform=o,a.elementRef=n,a.dialogRef=r,a._destroy=new i.Subject,a._scrollable=!0,a._layoutEventSubscription=null,a.config=r._portalInstance._config,a}return m(o,t),Object.defineProperty(o.prototype,"layoutEvents",{get:function(){return i.merge.apply(void 0,R.map((function(t){return i.fromEvent(window,t)})))},enumerable:!0,configurable:!0}),o.prototype.getDefaultFoundation=function(){var t=this,e={addClass:function(e){return t._getDialog().classList.add(e)},removeClass:function(e){return t._getDialog().classList.remove(e)},getInitialFocusEl:function(){return t._platform.isBrowser?document.querySelector("[cdkFocusInitial]"):null},hasClass:function(e){return t._getDialog().classList.contains(e)},addBodyClass:function(e){t._platform.isBrowser&&document.body.classList.add(e)},removeBodyClass:function(e){t._platform.isBrowser&&document.body.classList.remove(e)},eventTargetMatches:function(t,e){return d.matches(t,e)},trapFocus:function(){},releaseFocus:function(){},isContentScrollable:function(){return!!t._content&&t._scrollable&&p.util.isScrollable(t._content.elementRef.nativeElement)},areButtonsStacked:function(){return p.util.areTopsMisaligned(t._buttons)},getActionFromEvent:function(t){var e=d.closest(t.target,"["+p.strings.ACTION_ATTRIBUTE+"]");return e&&e.getAttribute(p.strings.ACTION_ATTRIBUTE)},clickDefaultButton:function(){var e,o,n;null===(n=null===(o=null===(e=t._buttons.find((function(t){return t.default})))||void 0===e?void 0:e.elementRef)||void 0===o?void 0:o.nativeElement)||void 0===n||n.click()},reverseButtons:function(){t._buttons.toArray().reverse(),t._buttons.forEach((function(t){return t.getHostElement().parentElement.appendChild(t.getHostElement())}))},notifyOpened:function(){return t.dialogRef.opened()},notifyOpening:function(){},notifyClosed:function(e){return t._closeDialogByRef(e)},notifyClosing:function(){}};return new p.MDCDialogFoundation(e)},o.prototype.ngAfterViewInit=function(){this._foundation=this.getDefaultFoundation(),this._initialize(),this._loadListeners(),this._foundation.open()},o.prototype._initialize=function(){this._scrollable=!!this.config.scrollable,this.config.clickOutsideToClose||this._foundation.setScrimClickAction(""),this.config.escapeToClose||this._foundation.setEscapeKeyAction(""),this.config.buttonsStacked||this._foundation.setAutoStackButtons(!1)},o.prototype.ngOnDestroy=function(){var t,e;this._destroy.next(),this._destroy.complete(),null===(t=this._layoutEventSubscription)||void 0===t||t.unsubscribe(),null===(e=this._foundation)||void 0===e||e.destroy()},o.prototype.layout=function(){this._foundation.layout()},o.prototype._onKeydown=function(t){this._foundation.handleKeydown(t)},o.prototype._onClick=function(t){this._foundation.handleClick(t)},o.prototype._closeDialogByRef=function(t){this.dialogRef.close(t)},o.prototype._loadListeners=function(){var t=this;this._layoutEventSubscription=this.layoutEvents.pipe().subscribe((function(){return t.layout()})),this._platform.isBrowser&&this._ngZone.runOutsideAngular((function(){return i.fromEvent(document,"keydown").pipe(a.takeUntil(t._destroy)).subscribe((function(e){return t._ngZone.run((function(){return t._foundation.handleDocumentKeydown(e)}))}))}))},o.prototype._getDialog=function(){return this._elementRef.nativeElement},o.decorators=[{type:e.Component,args:[{selector:"mdc-dialog",exportAs:"mdc-dialog",host:{"[attr.id]":"config?.id",role:"alertdialog",class:"mdc-dialog","[attr.aria-modal]":"true","[attr.aria-labelledby]":"config?.ariaLabel","[attr.aria-label]":"config?.ariaLabel","[attr.aria-describedby]":"config?.ariaDescribedBy || null","(click)":"_onClick($event)","(keydown)":"_onKeydown($event)"},template:"\n <mdc-dialog-scrim></mdc-dialog-scrim>\n <ng-content></ng-content>",encapsulation:e.ViewEncapsulation.None,changeDetection:e.ChangeDetectionStrategy.OnPush}]}],o.ctorParameters=function(){return[{type:e.NgZone},{type:r.Platform},{type:e.ElementRef},{type:P}]},o.propDecorators={_surface:[{type:e.ContentChild,args:[D,{static:!1}]}],_content:[{type:e.ContentChild,args:[O,{static:!1}]}],_buttons:[{type:e.ContentChildren,args:[A,{descendants:!0}]}]},o}(c.MDCComponent),T=function(){this.ariaDescribedBy=null,this.ariaLabel=null,this.escapeToClose=!0,this.clickOutsideToClose=!0,this.scrollable=!0,this.buttonsStacked=!0,this.autoFocus=!0,this.restoreFocus=!0,this.data=null};function j(){throw Error("Attempting to attach dialog content after content is already attached")}var M=function(t){function o(e,o,n,r){var a=t.call(this)||this;return a._elementRef=e,a._focusTrapFactory=o,a._document=n,a._config=r,a._elementFocusedBeforeDialogWasOpened=null,a._afterExit=new i.Subject,a}return m(o,t),o.prototype.attachComponentPortal=function(t){return this._portalOutlet.hasAttached()&&j(),this._savePreviouslyFocusedElement(),this._portalOutlet.attachComponentPortal(t)},o.prototype.attachTemplatePortal=function(t){return this._portalOutlet.hasAttached()&&j(),this._savePreviouslyFocusedElement(),this._portalOutlet.attachTemplatePortal(t)},o.prototype.trapFocus=function(){var t=this._elementRef.nativeElement;if(this._focusTrap||(this._focusTrap=this._focusTrapFactory.create(t)),this._config.autoFocus)this._focusTrap.focusInitialElementWhenReady();else{var e=this._document.activeElement;e===t||t.contains(e)||t.focus()}},o.prototype.restoreFocus=function(){var t=this._elementFocusedBeforeDialogWasOpened;this._config.restoreFocus&&t&&"function"==typeof t.focus&&t.focus(),this._focusTrap&&this._focusTrap.destroy()},o.prototype._savePreviouslyFocusedElement=function(){var t=this;this._document&&(this._elementFocusedBeforeDialogWasOpened=this._document.activeElement,this._elementRef.nativeElement.focus&&Promise.resolve().then((function(){return t._elementRef.nativeElement.focus()})))},o.decorators=[{type:e.Component,args:[{selector:"mdc-dialog-portal",host:{"[attr.id]":"_id"},template:"<ng-template cdkPortalOutlet></ng-template>",encapsulation:e.ViewEncapsulation.None}]}],o.ctorParameters=function(){return[{type:e.ElementRef},{type:g.FocusTrapFactory},{type:void 0,decorators:[{type:e.Optional},{type:e.Inject,args:[f.DOCUMENT]}]},{type:T}]},o.propDecorators={_portalOutlet:[{type:e.ViewChild,args:[n.CdkPortalOutlet,{static:!0}]}]},o}(n.BasePortalOutlet),I=new e.InjectionToken("MdcDialogData"),B=new e.InjectionToken("mdc-dialog-default-options"),F=function(){function t(t,e,o,n){var r=this;this._overlay=t,this._injector=e,this._defaultOptions=o,this._parentDialog=n,this._openDialogsAtThisLevel=[],this._afterAllClosedAtThisLevel=new i.Subject,this._afterOpenedAtThisLevel=new i.Subject,this._ariaHiddenElements=new Map,this.afterAllClosed=i.defer((function(){return r.openDialogs.length?r._afterAllClosed:r._afterAllClosed.pipe(a.startWith(void 0))}))}return Object.defineProperty(t.prototype,"openDialogs",{get:function(){return this._parentDialog?this._parentDialog.openDialogs:this._openDialogsAtThisLevel},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"afterOpened",{get:function(){return this._parentDialog?this._parentDialog.afterOpened:this._afterOpenedAtThisLevel},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"_afterAllClosed",{get:function(){var t=this._parentDialog;return t?t._afterAllClosed:this._afterAllClosedAtThisLevel},enumerable:!0,configurable:!0}),t.prototype.open=function(t,e){var o=this;if((e=function(t,e){return _(_({},e),t)}(e,this._defaultOptions||new T)).id&&this.getDialogById(e.id))throw Error('Dialog with id "'+e.id+'" exists already. The dialog id must be unique.');var n=this._createOverlay(),r=this._attachDialogContainer(n,e),i=this._attachDialogContent(t,r,n,e);return this.openDialogs.push(i),i.afterClosed().subscribe((function(){return o._removeOpenDialog(i,r)})),this.afterOpened.next(i),i},t.prototype.closeAll=function(){this._closeDialogs(this.openDialogs)},t.prototype.getDialogById=function(t){return this.openDialogs.find((function(e){return e.id===t}))},t.prototype.ngOnDestroy=function(){this._closeDialogs(this._openDialogsAtThisLevel),this._afterAllClosedAtThisLevel.complete(),this._afterOpenedAtThisLevel.complete()},t.prototype._createOverlay=function(){return this._overlay.create()},t.prototype._attachDialogContainer=function(t,e){var o=e&&e.viewContainerRef&&e.viewContainerRef.injector,r=new n.PortalInjector(o||this._injector,new WeakMap([[T,e]])),i=new n.ComponentPortal(M,e.viewContainerRef,r,e.componentFactoryResolver);return t.attach(i).instance},t.prototype._attachDialogContent=function(t,o,r,i){var a=new P(r,o,i.id);if(t instanceof e.TemplateRef)o.attachTemplatePortal(new n.TemplatePortal(t,null,{$implicit:i.data,dialogRef:a}));else{var c=this._createInjector(i,a,o),s=o.attachComponentPortal(new n.ComponentPortal(t,i.viewContainerRef,c));a.componentInstance=s.instance}return a},t.prototype._createInjector=function(t,e,o){var r=t&&t.viewContainerRef&&t.viewContainerRef.injector;o.trapFocus();var i=new WeakMap([[M,o],[I,t.data],[P,e]]);return new n.PortalInjector(r||this._injector,i)},t.prototype._removeOpenDialog=function(t,e){var o=this.openDialogs.indexOf(t);o>-1&&(e.restoreFocus(),this.openDialogs.splice(o,1),this.openDialogs.length||(this._ariaHiddenElements.forEach((function(t,e){t?e.setAttribute("aria-hidden",t):e.removeAttribute("aria-hidden")})),this._ariaHiddenElements.clear(),this._afterAllClosed.next()))},t.prototype._closeDialogs=function(t){for(var e=t.length;e--;)t[e].close()},t.decorators=[{type:e.Injectable}],t.ctorParameters=function(){return[{type:o.Overlay},{type:e.Injector},{type:T,decorators:[{type:e.Optional},{type:e.Inject,args:[B]}]},{type:t,decorators:[{type:e.Optional},{type:e.SkipSelf}]}]},t}();var S=[y,w,A,k,b,M,O,v,D,D,C],x=function(){function t(){}return t.decorators=[{type:e.NgModule,args:[{imports:[o.OverlayModule,n.PortalModule],exports:S,declarations:S,providers:[F],entryComponents:[M,k]}]}],t}();t.MDC_DIALOG_DATA=I,t.MDC_DIALOG_DEFAULT_OPTIONS=B,t.MdcDialog=F,t.MdcDialogAction=y,t.MdcDialogActions=w,t.MdcDialogButton=A,t.MdcDialogComponent=k,t.MdcDialogConfig=T,t.MdcDialogContainer=b,t.MdcDialogContent=O,t.MdcDialogModule=x,t.MdcDialogPortal=M,t.MdcDialogRef=P,t.MdcDialogScrim=v,t.MdcDialogSurface=D,t.MdcDialogTitle=C,t.throwMdcDialogContentAlreadyAttachedError=j,Object.defineProperty(t,"__esModule",{value:!0})}));