ngx-modialog-11
Version:
Modal / Dialog for Angular
16 lines (14 loc) • 19.8 kB
JavaScript
!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="undefined"!=typeof globalThis?globalThis: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";var s=/^(\$\$).*/;function a(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 c(e){return"$$"+e}function u(e,t,n){Object.defineProperty(e,t,{configurable:!1,enumerable:!1,writable:!1,value:n})}function p(e,t){Object.getOwnPropertyNames(t).forEach((function(n){return e[c(n)]=t[n]}))}function l(e,t,n){var r=this;void 0===n&&(n=!1),a.call(e,t);var o=c(t);u(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 f=function(){function e(e){this._fluentAssign=e instanceof d?e:new d}return e.prototype.setMethod=function(e,t){return l(this._fluentAssign,e),void 0!==t&&this._fluentAssign[e](t),this},Object.defineProperty(e.prototype,"fluentAssign",{get:function(){return this._fluentAssign},enumerable:!1,configurable:!0}),e}(),d=function(){function e(e,t,n){var r=this;Array.isArray(e)?e.forEach((function(e){return p(r,e)})):e&&p(this,e),Array.isArray(t)&&t.forEach((function(e){return l(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 f(e)},e.prototype.toJSON=function(){var e,t=this;return(e=this,Object.getOwnPropertyNames(e).filter((function(e){return s.test(e)})).map((function(e){return e.substr(2)}))).reduce((function(e,n){var r=c(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 y(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 h(e,t){return e.concat(t.filter((function(t){return-1===e.indexOf(t)})))}var m=function(){var e=this;this.promise=new Promise((function(t,n){e.resolve=t,e.reject=n}))};function v(){}function g(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)}
/*! *****************************************************************************
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 b=function(e,t){return(b=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 E(e,t){function n(){this.constructor=e}b(e,t),e.prototype=null===t?Object.create(t):(n.prototype=t.prototype,new 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 E(t,e),t}(Error),w=function(){function e(e,t){this.overlay=e,this.context=t,this._resultDeferred=new m,this._onDestroy=new n.Subject,this.onDestroy=this._onDestroy.asObservable()}return Object.defineProperty(e.prototype,"result",{get:function(){return this._resultDeferred.promise},enumerable:!1,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}();(O=e.DROP_IN_TYPE||(e.DROP_IN_TYPE={}))[O.alert=0]="alert",O[O.prompt=1]="prompt",O[O.confirm=2]="confirm";var R=function(){},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(e,t){t&&e.nativeElement&&t.overlayRef.instance.setClickBoundary(e.nativeElement)};j.decorators=[{type:t.Directive,args:[{selector:"[overlayDialogBoundary]"}]}],j.ctorParameters=function(){return[{type:t.ElementRef},{type:w}]};var 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:!1,configurable:!0}),e.prototype.ngOnDestroy=function(){this._targetKey&&k.delVCRef(this._targetKey,this.vcRef)},e}();x.decorators=[{type:t.Directive,args:[{selector:"[overlayTarget]"}]}],x.ctorParameters=function(){return[{type:t.ViewContainerRef}]},x.propDecorators={targetKey:[{type:t.Input,args:["overlayTarget"]}]};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=g(e);return t.changeDetectorRef.detectChanges(),t},e.prototype.onEnd=function(e){this.animationEnd.closed||this.animationEnd.next(e)},e}(),M=function(e){function t(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 E(t,e),t}(P);M.decorators=[{type:t.Component,args:[{selector:"css-backdrop",host:{"[attr.class]":"cssClass","[attr.style]":"styleStr"},encapsulation:t.ViewEncapsulation.None,template:""}]}],M.ctorParameters=function(){return[{type:t.ElementRef},{type:t.Renderer2}]};var N=function(e){function t(t,n,r){var o=e.call(this,n,r)||this;return o.dialog=t,o.activateAnimationListener(),o}return E(t,e),t}(P);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}]};var V=!("undefined"==typeof document||!document),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 E(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 m;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}(P);L.decorators=[{type:t.Component,args:[{selector:"modal-overlay",encapsulation:t.ViewEncapsulation.None,template:'<div #container>\r\n <ng-template #innerView></ng-template>\r\n</div>\r\n<ng-template #template let-ctx>\r\n <ng-container *ngComponentOutlet="ctx.component; injector: ctx.injector; content: ctx.projectableNodes"></ng-container>\r\n</ng-template>'}]}],L.ctorParameters=function(){return[{type:w},{type:t.ViewContainerRef},{type:t.ElementRef},{type:t.Renderer2}]},L.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"]]}]};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:!1,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}()),B=function(){function e(e,t){this._modalRenderer=e,this.injector=t}return Object.defineProperty(e.prototype,"stackLength",{get:function(){return T.length},enumerable:!1,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(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}),T.pushManaged(o,r),o},e}();B.decorators=[{type:t.Injectable}],B.ctorParameters=function(){return[{type:R},{type:t.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,n,r){var o=this;r||(r=this.injector);var i=g({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}();function I(e){return new Error("Unsupported Drop-In "+e)}$.decorators=[{type:t.Injectable}],$.ctorParameters=function(){return[{type:t.ApplicationRef},{type:t.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 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}(),H=!("undefined"==typeof document||!document),K={clickOutside:"click",mousedownOutside:"mousedown",mouseupOutside:"mouseup",mousemoveOutside:"mousemove"};var G=function(){function e(){H&&"function"==typeof document.addEventListener||(this.addEventListener=v)}return e.prototype.supports=function(e){return K.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(K[t],i,!1),o=function(){return document.removeEventListener(K[t],i,!1)};var i}),0),function(){o&&o()}}))},e}();G.decorators=[{type:t.Injectable}],G.ctorParameters=function(){return[]};var Y={inElement:!1,isBlocking:!0,keyboard:[27],supportsKey:function(e){return this.keyboard.indexOf(e)>-1}},q=["inElement","isBlocking","keyboard"],U=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=Y.keyboard)},e}(),z=function(e){function t(t,n,r){return e.call(this,y(Y,t||{}),h(q,n||[]),r||U)||this}return E(t,e),t.prototype.toOverlayConfig=function(e){return y(e||{},{context:this.toJSON()})},t}(d);var J={},W=["message"],Z=function(e){function t(){return null!==e&&e.apply(this,arguments)||this}return E(t,e),t}(U),Q=function(e){function t(t,n,r){return e.call(this,y(J,t||{}),h(W,n||[]),r)||this}return E(t,e),t}(z),X=["component"],ee=function(e){function t(){return null!==e&&e.apply(this,arguments)||this}return E(t,e),t}(Z),te=function(e){function t(t,n,r){return e.call(this,t||{},h(X,n||[]),r)||this}return E(t,e),t.prototype.$$beforeOpen=function(e){},t.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)},t}(Q),ne=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:$},{provide:i.EVENT_MANAGER_PLUGINS,useClass:G,multi:!0},{provide:t.ANALYZE_FOR_ENTRY_COMPONENTS,useValue:n||[],multi:!0}]}},e}();ne.decorators=[{type:t.NgModule,args:[{declarations:[L,M,N,j,x],imports:[o.CommonModule],exports:[M,N,j,x],providers:[B],entryComponents:[L,M,N]}]}],e.BaseDynamicComponent=P,e.CSSBackdrop=M,e.CSSDialogContainer=N,e.DEFAULT_VALUES=J,e.DOMOverlayRenderer=$,e.DialogBailOutError=_,e.DialogRef=w,e.FluentAssign=d,e.FluentAssignFactory=f,e.Modal=F,e.ModalContext=Z,e.ModalContextBuilder=Q,e.ModalModule=ne,e.ModalOpenContext=ee,e.ModalOpenContextBuilder=te,e.ModalOverlay=L,e.Overlay=B,e.OverlayContext=U,e.OverlayContextBuilder=z,e.OverlayDialogBoundary=j,e.OverlayRenderer=R,e.OverlayTarget=x,e.PromiseCompleter=m,e.arrayUnion=h,e.createComponent=g,e.extend=y,e.overlayConfigFactory=function(e,t,n){return new z(e,void 0,t).toOverlayConfig(n)},e.privateKey=c,e.setAssignAlias=function(e,t,n,r){if(void 0===r&&(r=!1),a.call(e,t),u(e,t,(function(t){return e[n](t),e})),!0===r){var o=c(t),i=c(n);Object.defineProperty(e,o,{configurable:!1,enumerable:!1,get:function(){return e[i]}})}},e.setAssignMethod=l,e.ɵa=G,Object.defineProperty(e,"__esModule",{value:!0})}));
//# sourceMappingURL=ngx-modialog-11.umd.min.js.map