modalicious
Version:
A modal service for Angular
2 lines • 7.79 kB
JavaScript
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("@angular/core"),require("@angular/common"),require("@angular/animations")):"function"==typeof define&&define.amd?define("modalicious",["exports","@angular/core","@angular/common","@angular/animations"],t):t((e=e||self).modalicious={},e.ng.core,e.ng.common,e.ng.animations)}(this,function(e,t,o,n){"use strict";function i(e,t,o,n){var i,r=arguments.length,a=r<3?t:null===n?n=Object.getOwnPropertyDescriptor(t,o):n;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)a=Reflect.decorate(e,t,o,n);else for(var c=e.length-1;c>=0;c--)(i=e[c])&&(a=(r<3?i(a):r>3?i(t,o,a):i(t,o))||a);return r>3&&a&&Object.defineProperty(t,o,a),a}function r(e,t){if("object"==typeof Reflect&&"function"==typeof Reflect.metadata)return Reflect.metadata(e,t)}function a(e,t,o,n){return new(o||(o=Promise))(function(i,r){function a(e){try{s(n.next(e))}catch(e){r(e)}}function c(e){try{s(n.throw(e))}catch(e){r(e)}}function s(e){e.done?i(e.value):new o(function(t){t(e.value)}).then(a,c)}s((n=n.apply(e,t||[])).next())})}function c(e,t){var o,n,i,r,a={label:0,sent:function(){if(1&i[0])throw i[1];return i[1]},trys:[],ops:[]};return r={next:c(0),throw:c(1),return:c(2)},"function"==typeof Symbol&&(r[Symbol.iterator]=function(){return this}),r;function c(r){return function(c){return function(r){if(o)throw new TypeError("Generator is already executing.");for(;a;)try{if(o=1,n&&(i=2&r[0]?n.return:r[0]?n.throw||((i=n.return)&&i.call(n),0):n.next)&&!(i=i.call(n,r[1])).done)return i;switch(n=0,i&&(r=[2&r[0],i.value]),r[0]){case 0:case 1:i=r;break;case 4:return a.label++,{value:r[1],done:!1};case 5:a.label++,n=r[1],r=[0];continue;case 7:r=a.ops.pop(),a.trys.pop();continue;default:if(!(i=(i=a.trys).length>0&&i[i.length-1])&&(6===r[0]||2===r[0])){a=0;continue}if(3===r[0]&&(!i||r[1]>i[0]&&r[1]<i[3])){a.label=r[1];break}if(6===r[0]&&a.label<i[1]){a.label=i[1],i=r;break}if(i&&a.label<i[2]){a.label=i[2],a.ops.push(r);break}i[2]&&a.ops.pop(),a.trys.pop();continue}r=t.call(e,a)}catch(e){r=[6,e],n=0}finally{o=i=0}if(5&r[0])throw r[1];return{value:r[0]?r[1]:void 0,done:!0}}([r,c])}}}function s(e,t){var o="function"==typeof Symbol&&e[Symbol.iterator];if(!o)return e;var n,i,r=o.call(e),a=[];try{for(;(void 0===t||t-- >0)&&!(n=r.next()).done;)a.push(n.value)}catch(e){i={error:e}}finally{try{n&&!n.done&&(o=r.return)&&o.call(r)}finally{if(i)throw i.error}}return a}function l(){for(var e=[],t=0;t<arguments.length;t++)e=e.concat(s(arguments[t]));return e}var u=function(){function e(e){this.viewContainerRef=e}return e=i([t.Directive({selector:"[mod-modal-host]"}),r("design:paramtypes",[t.ViewContainerRef])],e)}(),d=function(e,t){this.cancel=e,this.resolve=t},p=function(){function e(e){this.modalInstanceService=e,this.useFixedPosition=!1,this.showContent=!1,this.showBackdrop=!0}return Object.defineProperty(e.prototype,"backdrop",{get:function(){return this.showBackdrop?"active":"inactive"},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"content",{get:function(){return this.showContent?"visible":"hidden"},enumerable:!0,configurable:!0}),e.prototype.onKeyDown=function(e){"Escape"===e.key&&(this.modalInstanceService.cancel("Escape key hit"),e.preventDefault())},Object.defineProperty(e.prototype,"positionStyle",{get:function(){return this.useFixedPosition?"fixed":"absolute"},enumerable:!0,configurable:!0}),e.prototype.ngAfterViewInit=function(){var e=this;setTimeout(function(){e.showContent=!0},50)},e.prototype.hide=function(){var e=this;return new Promise(function(t){e.showBackdrop=!1,setTimeout(function(){t()},200)})},i([t.Input(),r("design:type",Boolean)],e.prototype,"useFixedPosition",void 0),i([t.ViewChild(u,{static:!0}),r("design:type",u)],e.prototype,"modalHost",void 0),i([t.HostListener("keydown",["$event"]),r("design:type",Function),r("design:paramtypes",[KeyboardEvent]),r("design:returntype",void 0)],e.prototype,"onKeyDown",null),i([t.HostBinding("style.position"),r("design:type",Object),r("design:paramtypes",[])],e.prototype,"positionStyle",null),e=i([t.Component({selector:"mod-modal-container",template:'<div class="mod-modal-table" [@backdrop]="backdrop">\r\n <div class="mod-modal-table-cell">\r\n <div class="mod-modal-content" [@content]="content">\r\n <ng-template mod-modal-host></ng-template>\r\n </div>\r\n </div>\r\n</div>\r\n',animations:[n.trigger("backdrop",[n.state("inactive",n.style({opacity:0})),n.state("active",n.style({backgroundColor:"rgba(0, 0, 0, .85)",opacity:1})),n.transition("void => active",[n.style({backgroundColor:"rgba(0,0,0,0)"}),n.animate("50ms ease-in")]),n.transition("active => inactive",[n.animate("150ms ease-out")])]),n.trigger("content",[n.state("hidden",n.style({opacity:0,transform:"translateY(50px)"})),n.state("visible",n.style({opacity:1,transform:"translateY(0)"})),n.transition("hidden => visible",[n.animate("150ms ease-in")])])],styles:[":host{overflow-x:hidden;overflow-y:auto;left:0;top:0;right:0;bottom:0;display:block;background-color:rgba(0,0,0,0)}:host .mod-modal-table-cell{display:table-cell;vertical-align:middle;text-align:center;padding:0}:host .mod-modal-table{width:100%;height:100%;display:table}:host .mod-modal-content{display:inline-block;width:100%}"]}),r("design:paramtypes",[d])],e)}(),f=function(){function e(e,t){this.factoryResolver=e,this.appRef=t}return e.prototype.setModalPositioning=function(e){this.defaultToFixedPositioning=e},e.prototype.setRootViewContainerRef=function(e){this.rootViewContainer=e},e.prototype.show=function(e,o){var n=this;if(void 0===o&&(o=[]),!this.rootViewContainer)throw new Error("Modalicious: You must call setRootViewContainerRef on ModalService from your root component before calling ModalService.show()");return new Promise(function(i,r){var s,u=n.factoryResolver.resolveComponentFactory(p),f=function(){return a(n,void 0,void 0,function(){return c(this,function(e){switch(e.label){case 0:return[4,s.instance.hide()];case 1:return e.sent(),this.appRef.detachView(s.hostView),s.destroy(),[2]}})})},y=new d(function(e){return a(n,void 0,void 0,function(){return c(this,function(t){switch(t.label){case 0:return[4,f()];case 1:return t.sent(),r(e),[2]}})})},function(e){return a(n,void 0,void 0,function(){return c(this,function(t){switch(t.label){case 0:return[4,f()];case 1:return t.sent(),i(e),[2]}})})});function m(){return y}var v=t.Injector.create({providers:[{provide:d,useFactory:m,deps:[]}],parent:n.rootViewContainer.parentInjector});s=u.create(v),n.defaultToFixedPositioning&&(s.instance.useFixedPosition=!0);var h=s.instance.modalHost.viewContainerRef,b=n.factoryResolver.resolveComponentFactory(e),g=t.Injector.create({providers:l([{provide:d,useFactory:m,deps:[]}],o),parent:n.rootViewContainer.parentInjector}),w=b.create(g);h.insert(w.hostView),n.rootViewContainer.insert(s.hostView)})},e=i([t.Injectable(),r("design:paramtypes",[t.ComponentFactoryResolver,t.ApplicationRef])],e)}(),y=function(){function e(e){this.modalInstance=e,this.value=null}return e.prototype.close=function(){this.modalInstance.resolve(this.value)},i([t.Input("mod-modal-close"),r("design:type",Object)],e.prototype,"value",void 0),i([t.HostListener("click"),r("design:type",Function),r("design:paramtypes",[]),r("design:returntype",void 0)],e.prototype,"close",null),e=i([t.Directive({selector:"[mod-modal-close]"}),r("design:paramtypes",[d])],e)}(),m=function(){function e(){}var n;return n=e,e.forRoot=function(){return{ngModule:n,providers:[f]}},e=n=i([t.NgModule({imports:[o.CommonModule],entryComponents:[p],declarations:[p,u,y],exports:[y]})],e)}();e.ModalCloseDirective=y,e.ModalInstanceService=d,e.ModalService=f,e.ModaliciousModule=m,e.ɵa=p,e.ɵb=u,Object.defineProperty(e,"__esModule",{value:!0})});
//# sourceMappingURL=modalicious.umd.min.js.map