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