UNPKG

ngx-modialog-7

Version:
16 lines (14 loc) 19.8 kB
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("@angular/core"),require("rxjs"),require("rxjs/operators"),require("@angular/common"),require("@angular/platform-browser")):"function"==typeof define&&define.amd?define("ngxModialog",["exports","@angular/core","rxjs","rxjs/operators","@angular/common","@angular/platform-browser"],t):t((e=e||self).ngxModialog={},e.ng.core,e.rxjs,e.rxjs.operators,e.ng.common,e.ng.platformBrowser)}(this,(function(e,t,n,r,o,i){"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 a=function(e,t){return(a=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var n in t)t.hasOwnProperty(n)&&(e[n]=t[n])})(e,t)};function s(e,t){function n(){this.constructor=e}a(e,t),e.prototype=null===t?Object.create(t):(n.prototype=t.prototype,new n)}var c=/^(\$\$).*/;function u(e){if(!e)throw new Error("Illegal method name. Empty method name is not allowed");if(e in this)throw new Error("A member name '"+e+"' already defined.")}function p(e){return"$$"+e}function f(e,t,n){Object.defineProperty(e,t,{configurable:!1,enumerable:!1,writable:!1,value:n})}function l(e,t){Object.getOwnPropertyNames(t).forEach((function(n){return e[p(n)]=t[n]}))}function d(e,t,n){var r=this;void 0===n&&(n=!1),u.call(e,t);var o=p(t);f(e,t,(function(i){if(n&&r.hasOwnProperty(o))throw new Error("Overriding config property '"+t+"' is not allowed.");return e[o]=i,e}))}var y=function(){function e(e){this._fluentAssign=e instanceof h?e:new h}return e.prototype.setMethod=function(e,t){return d(this._fluentAssign,e),void 0!==t&&this._fluentAssign[e](t),this},Object.defineProperty(e.prototype,"fluentAssign",{get:function(){return this._fluentAssign},enumerable:!0,configurable:!0}),e}();var h=function(){function e(e,t,n){var r=this;Array.isArray(e)?e.forEach((function(e){return l(r,e)})):e&&l(this,e),Array.isArray(t)&&t.forEach((function(e){return d(r,e)})),n&&(this.__fluent$base__=n)}return e.compose=function(t,n){return e.composeWith(new e(t,n))},e.composeWith=function(e){return new y(e)},e.prototype.toJSON=function(){var e,t=this;return(e=this,Object.getOwnPropertyNames(e).filter((function(e){return c.test(e)})).map((function(e){return e.substr(2)}))).reduce((function(e,n){var r=p(n),o=Object.getOwnPropertyDescriptor(t,r);return o?Object.defineProperty(e,n,o):e[n]=t[r],e}),this.__fluent$base__?new this.__fluent$base__:{})},e}();function m(e,t){var n={};for(var r in e)e.hasOwnProperty(r)&&(n[r]=e[r]);for(var r in t)t.hasOwnProperty(r)&&(n[r]=t[r]);return n}function v(e,t){return e.concat(t.filter((function(t){return-1===e.indexOf(t)})))}var g=function(){var e=this;this.promise=new Promise((function(t,n){e.resolve=t,e.reject=n}))};function b(){}function E(e){var n=e.injector||e.vcRef.injector,r=n.get(t.ComponentFactoryResolver).resolveComponentFactory(e.component);return e.vcRef?e.vcRef.createComponent(r,e.vcRef.length,n,e.projectableNodes):r.create(n)}var O=function(e){function t(t){var n=e.call(this)||this;return t||(t="Dialog was forced to close by an unknown source."),n.message=t,n}return s(t,e),t}(Error),w=function(){function e(e,t){this.overlay=e,this.context=t,this._resultDeferred=new g,this._onDestroy=new n.Subject,this.onDestroy=this._onDestroy.asObservable()}return Object.defineProperty(e.prototype,"result",{get:function(){return this._resultDeferred.promise},enumerable:!0,configurable:!0}),e.prototype.setCloseGuard=function(e){this.closeGuard=e},e.prototype.close=function(e){var t=this;void 0===e&&(e=null);var n=function(){t.destroy(),t._resultDeferred.resolve(e)};this._fireHook("beforeClose").then((function(e){return!0!==e&&n()})).catch(n)},e.prototype.dismiss=function(){var e=this,t=function(){e.destroy(),e._resultDeferred.promise.catch((function(){})),e._resultDeferred.reject()};this._fireHook("beforeDismiss").then((function(e){return!0!==e&&t()})).catch(t)},e.prototype.bailOut=function(){!0!==this.destroyed&&(this.destroyed=!0,this._onDestroy.next(null),this._onDestroy.complete(),this._resultDeferred.reject(new O))},e.prototype.destroy=function(){var e=this;!0!==this.destroyed&&(this.destroyed=!0,"function"==typeof this.overlayRef.instance.canDestroy?this.overlayRef.instance.canDestroy().catch((function(){})).then((function(){return e._destroy()})):this._destroy())},e.prototype._destroy=function(){this._onDestroy.next(null),this._onDestroy.complete(),this.overlayRef.destroy()},e.prototype._fireHook=function(e){var t=this.closeGuard,n=t&&"function"==typeof t[e]&&t[e];return Promise.resolve(!!n&&n.call(t))},e}();var _={alert:0,prompt:1,confirm:2};_[_.alert]="alert",_[_.prompt]="prompt",_[_.confirm]="confirm";var R=function(){};var C={};var k={getVCRef:function(e){return C[e]?C[e].slice():[]},setVCRef:function(e,t){C.hasOwnProperty(e)||(C[e]=[]),C[e].push(t)},delVCRef:function(e,t){if(t){var n=C[e]||[],r=n.indexOf(t);r>-1&&n.splice(r,1)}else C[e]=[]}},j=function(){function e(e,t){t&&e.nativeElement&&t.overlayRef.instance.setClickBoundary(e.nativeElement)}return e.decorators=[{type:t.Directive,args:[{selector:"[overlayDialogBoundary]"}]}],e.ctorParameters=function(){return[{type:t.ElementRef},{type:w}]},e}(),x=function(){function e(e){this.vcRef=e}return Object.defineProperty(e.prototype,"targetKey",{set:function(e){this._targetKey=e,e&&k.setVCRef(e,this.vcRef)},enumerable:!0,configurable:!0}),e.prototype.ngOnDestroy=function(){this._targetKey&&k.delVCRef(this._targetKey,this.vcRef)},e.decorators=[{type:t.Directive,args:[{selector:"[overlayTarget]"}]}],e.ctorParameters=function(){return[{type:t.ViewContainerRef}]},e.propDecorators={targetKey:[{type:t.Input,args:["overlayTarget"]}]},e}();var D=["webkit","moz","MS","o",""];function A(e,t,n){D.forEach((function(r){t.addEventListener(r?r+e:e.toLowerCase(),n,!1)}))}var P=function(){function e(e,t){this.el=e,this.renderer=t}return e.prototype.activateAnimationListener=function(){var e=this;this.animationEnd||(this.animationEnd=new n.Subject,this.animationEnd$=this.animationEnd.asObservable(),A("TransitionEnd",this.el.nativeElement,(function(t){return e.onEnd(t)})),A("AnimationEnd",this.el.nativeElement,(function(t){return e.onEnd(t)})))},e.prototype.setStyle=function(e,t){return this.renderer.setStyle(this.el.nativeElement,e,t),this},e.prototype.forceReflow=function(){this.el.nativeElement.offsetWidth},e.prototype.addClass=function(e,t){var n=this;void 0===t&&(t=!1),e.split(" ").forEach((function(e){return n.renderer.addClass(n.el.nativeElement,e)})),t&&this.forceReflow()},e.prototype.removeClass=function(e,t){var n=this;void 0===t&&(t=!1),e.split(" ").forEach((function(e){return n.renderer.removeClass(n.el.nativeElement,e)})),t&&this.forceReflow()},e.prototype.ngOnDestroy=function(){this.animationEnd&&!this.animationEnd.closed&&this.animationEnd.complete()},e.prototype.myAnimationEnd$=function(){var e=this;return this.animationEnd$.pipe(r.filter((function(t){return t.target===e.el.nativeElement})))},e.prototype._addComponent=function(e){var t=E(e);return t.changeDetectorRef.detectChanges(),t},e.prototype.onEnd=function(e){this.animationEnd.closed||this.animationEnd.next(e)},e}();var M=function(e){function n(t,n){var r=e.call(this,t,n)||this;r.activateAnimationListener();var o={position:"absolute",top:0,left:0,width:"100%",height:"100%"};return Object.keys(o).forEach((function(e){return r.setStyle(e,o[e])})),r}return s(n,e),n.decorators=[{type:t.Component,args:[{selector:"css-backdrop",host:{"[attr.class]":"cssClass","[attr.style]":"styleStr"},encapsulation:t.ViewEncapsulation.None,template:""}]}],n.ctorParameters=function(){return[{type:t.ElementRef},{type:t.Renderer2}]},n}(P);var N=function(e){function n(t,n,r){var o=e.call(this,n,r)||this;return o.dialog=t,o.activateAnimationListener(),o}return s(n,e),n.decorators=[{type:t.Component,args:[{selector:"css-dialog-container",host:{tabindex:"-1",role:"dialog"},encapsulation:t.ViewEncapsulation.None,template:"\n <ng-content></ng-content>"}]}],n.ctorParameters=function(){return[{type:w},{type:t.ElementRef},{type:t.Renderer2}]},n}(P);var V=!("undefined"==typeof document||!document);var L=function(e){function n(t,n,r,o){var i=e.call(this,r,o)||this;return i.dialogRef=t,i.vcr=n,i.activateAnimationListener(),i}return s(n,e),n.prototype.getProjectables=function(e){return"string"==typeof e?[[this.renderer.createText(""+e)]]:e instanceof t.TemplateRef?[this.vcr.createEmbeddedView(e,{$implicit:this.dialogRef.context,dialogRef:this.dialogRef}).rootNodes]:[this.embedComponent({component:e}).rootNodes]},n.prototype.embedComponent=function(e){var t=e;return this.vcr.createEmbeddedView(this.template,{$implicit:t})},n.prototype.addComponent=function(t,n){return void 0===n&&(n=[]),e.prototype._addComponent.call(this,{component:t,vcRef:this.innerVcr,projectableNodes:n})},n.prototype.fullscreen=function(){var e=this,t={position:"fixed",top:0,left:0,bottom:0,right:0,"z-index":1500};Object.keys(t).forEach((function(n){return e.setStyle(n,t[n])}))},n.prototype.insideElement=function(){var e=this,t={position:"absolute",overflow:"hidden",width:"100%",height:"100%",top:0,left:0,bottom:0,right:0};Object.keys(t).forEach((function(n){return e.setStyle(n,t[n])}))},n.prototype.setContainerStyle=function(e,t){return this.renderer.setStyle(this.container.nativeElement,e,t),this},n.prototype.setClickBoundary=function(e){var t,n=this,r=function(e){return t=e.target},o=function(r){if(!n.dialogRef.context.isBlocking&&n.dialogRef.overlay.isTopMost(n.dialogRef)){var o=r.target;if(o!==t){do{if(o===e)return}while(o.parentNode&&(o=o.parentNode));n.dialogRef.dismiss()}}};V&&(this.dialogRef.onDestroy.subscribe((function(){e.removeEventListener("click",r,!1),e.removeEventListener("touchstart",r,!1),document.removeEventListener("click",o,!1),document.removeEventListener("touchend",o,!1)})),setTimeout((function(){e.addEventListener("mousedown",r,!1),e.addEventListener("touchstart",o,!1),document.addEventListener("click",o,!1),document.addEventListener("touchend",o,!1)})))},n.prototype.canDestroy=function(){var e=new g;if(Array.isArray(this.beforeDestroyHandlers)){var t=setTimeout((function(){t=null,e.reject()}),1e3),n=function(){null!==t&&(clearTimeout(t),e.resolve())};Promise.all(this.beforeDestroyHandlers.map((function(e){return e()}))).then(n).catch(n)}else e.resolve();return e.promise},n.prototype.beforeDestroy=function(e){this.beforeDestroyHandlers||(this.beforeDestroyHandlers=[]),this.beforeDestroyHandlers.push(e)},n.prototype.documentKeypress=function(e){var t,n;this.dialogRef.overlay.isTopMost(this.dialogRef)&&(t=e.keyCode,n=this.dialogRef.context.keyboard,(Array.isArray(n)?n.indexOf(t)>-1:null!==n)&&this.dialogRef.dismiss())},n.prototype.ngOnDestroy=function(){e.prototype.ngOnDestroy.call(this),!0!==this.dialogRef.destroyed&&this.dialogRef.bailOut()},n.decorators=[{type:t.Component,args:[{selector:"modal-overlay",encapsulation:t.ViewEncapsulation.None,template:'<div #container>\n <ng-template #innerView></ng-template>\n</div>\n<ng-template #template let-ctx>\n <ng-container *ngComponentOutlet="ctx.component; injector: ctx.injector; content: ctx.projectableNodes"></ng-container>\n</ng-template>'}]}],n.ctorParameters=function(){return[{type:w},{type:t.ViewContainerRef},{type:t.ElementRef},{type:t.Renderer2}]},n.propDecorators={container:[{type:t.ViewChild,args:["container",{read:t.ElementRef,static:!0}]}],innerVcr:[{type:t.ViewChild,args:["innerView",{read:t.ViewContainerRef,static:!0}]}],template:[{type:t.ViewChild,args:["template",{static:!0}]}],documentKeypress:[{type:t.HostListener,args:["body:keydown",["$event"]]}]},n}(P);var S={},T=function(){function e(){this._stack=[],this._stackMap=new Map}return Object.defineProperty(e.prototype,"length",{get:function(){return this._stack.length},enumerable:!0,configurable:!0}),e.prototype.closeAll=function(e){void 0===e&&(e=null);for(var t=0,n=this._stack.length;t<n;t++)this._stack.pop().close(e)},e.prototype.push=function(e,t){-1===this._stack.indexOf(e)&&(this._stack.push(e),this._stackMap.set(e,t||S))},e.prototype.pushManaged=function(e,t){var n=this;this.push(e,t),e.onDestroy.subscribe((function(){return n.remove(e)}))},e.prototype.pop=function(){var e=this._stack.pop();return this._stackMap.delete(e),e},e.prototype.remove=function(e){var t=this.indexOf(e);t>-1&&(this._stack.splice(t,1),this._stackMap.delete(e))},e.prototype.index=function(e){return this._stack[e]},e.prototype.indexOf=function(e){return this._stack.indexOf(e)},e.prototype.groupOf=function(e){return this._stackMap.get(e)},e.prototype.groupBy=function(e){var t=[];return e&&this._stackMap.forEach((function(n,r){n===e&&t.push(r)})),t},e.prototype.groupLength=function(e){var t=0;return e&&this._stackMap.forEach((function(n){n===e&&t++})),t},e}();var B=new T,$=function(){function e(e,t){this._modalRenderer=e,this.injector=t}return Object.defineProperty(e.prototype,"stackLength",{get:function(){return B.length},enumerable:!0,configurable:!0}),e.prototype.isTopMost=function(e){return B.indexOf(e)===B.length-1},e.prototype.stackPosition=function(e){return B.indexOf(e)},e.prototype.groupStackLength=function(e){return B.groupLength(B.groupOf(e))},e.prototype.closeAll=function(e){void 0===e&&(e=null),B.closeAll(e)},e.prototype.open=function(e,t){var n=this,r=e.viewContainer;return("string"==typeof r?k.getVCRef(r):Array.isArray(r)?r:r?[r]:[null]).map((function(r){return n.createOverlay(e.renderer||n._modalRenderer,r,e,t)}))},e.prototype.createOverlay=function(e,t,n,r){n.context&&n.context.normalize(),n.injector||(n.injector=this.injector);var o=new w(this,n.context||{});o.inElement=n.context&&!!n.context.inElement;var i=e.render(o,t,n.injector);return Object.defineProperty(o,"overlayRef",{value:i}),B.pushManaged(o,r),o},e.decorators=[{type:t.Injectable}],e.ctorParameters=function(){return[{type:R},{type:t.Injector}]},e}();var I=function(){function e(e,t){this.appRef=e,this.injector=t,this.isDoc=!("undefined"==typeof document||!document)}return e.prototype.render=function(e,n,r){var o=this;r||(r=this.injector);var i=E({component:L,vcRef:n,injector:t.Injector.create({providers:[{provide:w,useValue:e}],parent:r})});return n||(this.appRef.attachView(i.hostView),e.onDestroy.subscribe((function(){return o.appRef.detachView(i.hostView)}))),n&&e.inElement?n.element.nativeElement.appendChild(i.location.nativeElement):this.isDoc&&document.body.appendChild(i.location.nativeElement),i},e.decorators=[{type:t.Injectable}],e.ctorParameters=function(){return[{type:t.ApplicationRef},{type:t.Injector}]},e}();function F(e){return new Error("Unsupported Drop-In "+e)}var H=function(){function e(e){this.overlay=e}return e.prototype.alert=function(){throw F("alert")},e.prototype.prompt=function(){throw F("prompt")},e.prototype.confirm=function(){throw F("confirm")},e.prototype.open=function(e,t){t=t||{};var n=this.overlay.open(t,this.constructor);return n.length>1&&console.warn("Attempt to open more then 1 overlay detected.\n Multiple modal copies are not supported at the moment,\n only the first viewContainer will display."),this.create(n[0],e)},e.prototype.createBackdrop=function(e,t){return e.overlayRef.instance.addComponent(t)},e.prototype.createContainer=function(e,t,n){var r=e.overlayRef.instance.getProjectables(n);return e.overlayRef.instance.addComponent(t,r)},e}();var K=!("undefined"==typeof document||!document),G={clickOutside:"click",mousedownOutside:"mousedown",mouseupOutside:"mouseup",mousemoveOutside:"mousemove"};var q=function(){function e(){K&&"function"==typeof document.addEventListener||(this.addEventListener=b)}return e.prototype.supports=function(e){return G.hasOwnProperty(e)},e.prototype.addEventListener=function(e,t,n){var r=this.manager.getZone();return r.runOutsideAngular((function(){var o;return setTimeout((function(){return i=function(e,t){return function(n){var r=n.target;do{if(r===e)return}while(r.parentNode&&(r=r.parentNode));t(n)}}(e,(function(e){return r.runGuarded((function(){return n(e)}))})),document.addEventListener(G[t],i,!1),o=function(){return document.removeEventListener(G[t],i,!1)};var i}),0),function(){o&&o()}}))},e.decorators=[{type:t.Injectable}],e.ctorParameters=function(){return[]},e}();var U={inElement:!1,isBlocking:!0,keyboard:[27],supportsKey:function(e){return this.keyboard.indexOf(e)>-1}},Y=["inElement","isBlocking","keyboard"],z=function(){function e(){}return e.prototype.normalize=function(){!1!==this.isBlocking&&(this.isBlocking=!0),null===this.keyboard?this.keyboard=[]:"number"==typeof this.keyboard?this.keyboard=[this.keyboard]:Array.isArray(this.keyboard)||(this.keyboard=U.keyboard)},e}();var J=function(e){function t(t,n,r){return e.call(this,m(U,t||{}),v(Y,n||[]),r||z)||this}return s(t,e),t.prototype.toOverlayConfig=function(e){return m(e||{},{context:this.toJSON()})},t}(h);var W={},Z=["message"],Q=function(e){function t(){return null!==e&&e.apply(this,arguments)||this}return s(t,e),t}(z);var X=function(e){function t(t,n,r){return e.call(this,m(W,t||{}),v(Z,n||[]),r)||this}return s(t,e),t}(J);var ee=["component"],te=function(e){function t(){return null!==e&&e.apply(this,arguments)||this}return s(t,e),t}(Q);var ne=function(e){function t(t,n,r){return e.call(this,t||{},v(ee,n||[]),r)||this}return s(t,e),t.prototype.$$beforeOpen=function(e){},t.prototype.open=function(e){var t=this.toJSON();if(!(t.modal instanceof H))return Promise.reject(new Error("Configuration Error: modal service not set."));this.$$beforeOpen(t);var n={context:t,viewContainer:e};return t.modal.open(t.component,n)},t}(X);var re=function(){function e(){}return e.withComponents=function(n){return{ngModule:e,providers:[{provide:t.ANALYZE_FOR_ENTRY_COMPONENTS,useValue:n,multi:!0}]}},e.forRoot=function(n){return{ngModule:e,providers:[{provide:R,useClass:I},{provide:i.EVENT_MANAGER_PLUGINS,useClass:q,multi:!0},{provide:t.ANALYZE_FOR_ENTRY_COMPONENTS,useValue:n||[],multi:!0}]}},e.decorators=[{type:t.NgModule,args:[{declarations:[L,M,N,j,x],imports:[o.CommonModule],exports:[M,N,j,x],providers:[$],entryComponents:[L,M,N]}]}],e}();e.BaseDynamicComponent=P,e.CSSBackdrop=M,e.CSSDialogContainer=N,e.DEFAULT_VALUES=W,e.DOMOverlayRenderer=I,e.DROP_IN_TYPE=_,e.DialogBailOutError=O,e.DialogRef=w,e.FluentAssign=h,e.FluentAssignFactory=y,e.Modal=H,e.ModalContext=Q,e.ModalContextBuilder=X,e.ModalModule=re,e.ModalOpenContext=te,e.ModalOpenContextBuilder=ne,e.ModalOverlay=L,e.Overlay=$,e.OverlayContext=z,e.OverlayContextBuilder=J,e.OverlayDialogBoundary=j,e.OverlayRenderer=R,e.OverlayTarget=x,e.PromiseCompleter=g,e.arrayUnion=v,e.createComponent=E,e.extend=m,e.overlayConfigFactory=function(e,t,n){return new J(e,void 0,t).toOverlayConfig(n)},e.privateKey=p,e.setAssignAlias=function(e,t,n,r){if(void 0===r&&(r=!1),u.call(e,t),f(e,t,(function(t){return e[n](t),e})),!0===r){var o=p(t),i=p(n);Object.defineProperty(e,o,{configurable:!1,enumerable:!1,get:function(){return e[i]}})}},e.setAssignMethod=d,e.ɵa=q,Object.defineProperty(e,"__esModule",{value:!0})})); //# sourceMappingURL=ngx-modialog-7.umd.min.js.map