blob: a181f0b8178d7e737cf762c0501bf459289dc222 [file] [log] [blame]
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("@angular/common"),require("@angular/material/progress-bar"),require("@angular/material/progress-spinner"),require("@covalent/core/common"),require("@angular/cdk/portal"),require("@angular/cdk/overlay"),require("rxjs"),require("rxjs/operators"),require("@angular/core")):"function"==typeof define&&define.amd?define("@covalent/core/loading",["exports","@angular/common","@angular/material/progress-bar","@angular/material/progress-spinner","@covalent/core/common","@angular/cdk/portal","@angular/cdk/overlay","rxjs","rxjs/operators","@angular/core"],t):t((e.covalent=e.covalent||{},e.covalent.core=e.covalent.core||{},e.covalent.core.loading={}),e.ng.common,e.ng.material["progress-bar"],e.ng.material["progress-spinner"],e.covalent.core.common,e.ng.cdk.portal,e.ng.cdk.overlay,e.rxjs,e.rxjs.operators,e.ng.core)}(this,function(e,t,n,o,i,s,r,a,c,l){"use strict";var p=function(e,t){return(p=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)};var d={Circular:"circular",Linear:"linear"},u={Determinate:"determinate",Indeterminate:"indeterminate"},m={Overlay:"overlay",Replace:"replace"},h={FullScreen:"fullscreen",Overlay:"overlay",None:"none"},f=100,g=(Object.defineProperty(y.prototype,"mode",{get:function(){return this._mode},set:function(e){this._defaultMode=e},enumerable:!0,configurable:!0}),Object.defineProperty(y.prototype,"value",{get:function(){return this._value},set:function(e){this._value=e,this._changeDetectorRef.markForCheck()},enumerable:!0,configurable:!0}),y.prototype.ngDoCheck=function(){this.isOverlay()&&1<this._hostHeight()&&this.animation&&(this._setCircleDiameter(),this._changeDetectorRef.markForCheck())},y.prototype.getHeight=function(){return this.isOverlay()||this.isFullScreen()?undefined:this.height?this.height+"px":"150px"},y.prototype.getCircleDiameter=function(){return this._circleDiameter},y.prototype.getCircleStrokeWidth=function(){var e=this.getCircleDiameter()/10;return Math.abs(e)},y.prototype.isCircular=function(){return this.type===d.Circular},y.prototype.isLinear=function(){return this.type===d.Linear},y.prototype.isFullScreen=function(){return this.style===h.FullScreen},y.prototype.isOverlay=function(){return this.style===h.Overlay},y.prototype.animationComplete=function(e){e.fromState?this.outAnimationCompleted():this.inAnimationCompleted()},y.prototype.inAnimationCompleted=function(){this._animationIn.next(undefined)},y.prototype.outAnimationCompleted=function(){this.value=0,this._changeDetectorRef.markForCheck(),this._animationOut.next(undefined)},y.prototype.startInAnimation=function(){return this._mode=this._defaultMode,this._setCircleDiameter(),this.animation=!0,this._changeDetectorRef.markForCheck(),this._animationIn.asObservable()},y.prototype.startOutAnimation=function(){return this.animation=!1,this._mode=u.Determinate,this._changeDetectorRef.markForCheck(),this._animationOut.asObservable()},y.prototype._setCircleDiameter=function(){var e=f;this.height?e=this.height:this.height===undefined&&(e=this._hostHeight()),this._circleDiameter=e&&e<=f?Math.floor(e):f},y.prototype._hostHeight=function(){return this._elementRef.nativeElement?this._elementRef.nativeElement.getBoundingClientRect().height:0},y.decorators=[{type:l.Component,args:[{selector:"td-loading",template:'<div class="td-loading-wrapper"\n [style.min-height]="getHeight()"\n [class.td-overlay-circular]="(isOverlay() || isFullScreen()) && !isLinear()"\n [class.td-overlay]="isOverlay() || isFullScreen()" \n [class.td-fullscreen]="isFullScreen()">\n <div [@tdFadeInOut]="animation"\n (@tdFadeInOut.done)="animationComplete($event)"\n [style.min-height]="getHeight()"\n class="td-loading">\n <mat-progress-spinner *ngIf="isCircular()" \n [mode]="mode"\n [value]="value" \n [color]="color" \n [diameter]="getCircleDiameter()"\n [strokeWidth]="getCircleStrokeWidth()">\n </mat-progress-spinner>\n <mat-progress-bar *ngIf="isLinear()" \n [mode]="mode"\n [value]="value"\n [color]="color">\n </mat-progress-bar>\n </div>\n <ng-template [cdkPortalOutlet]="content"></ng-template>\n</div>',animations:[i.tdFadeInOutAnimation],styles:[".td-loading-wrapper{position:relative;display:block}.td-loading-wrapper.td-fullscreen{position:inherit}.td-loading-wrapper .td-loading{-webkit-box-sizing:border-box;box-sizing:border-box;display:-webkit-box;display:-ms-flexbox;display:flex;-webkit-box-orient:horizontal;-webkit-box-direction:normal;-ms-flex-direction:row;flex-direction:row;-webkit-box-align:center;-ms-flex-align:center;align-items:center;-ms-flex-line-pack:center;align-content:center;max-width:100%;-webkit-box-pack:center;-ms-flex-pack:center;justify-content:center;-webkit-box-flex:1;-ms-flex:1;flex:1}.td-loading-wrapper.td-overlay .td-loading{position:absolute;margin:0;top:0;left:0;right:0;z-index:1000}.td-loading-wrapper.td-overlay .td-loading mat-progress-bar{position:absolute;top:0;left:0;right:0}.td-loading-wrapper.td-overlay-circular .td-loading{bottom:0}"]}]}],y.ctorParameters=function(){return[{type:l.ElementRef},{type:l.ChangeDetectorRef}]},y);function y(e,t){this._elementRef=e,this._changeDetectorRef=t,this._animationIn=new a.Subject,this._animationOut=new a.Subject,this._mode=u.Indeterminate,this._defaultMode=u.Indeterminate,this._value=0,this._circleDiameter=f,this.animation=!1,this.style=h.None,this.type=d.Circular,this.color="primary"}var _=(v.prototype.createFullScreenComponent=function(n){var o=this;n.height=undefined,n.style=h.FullScreen;var i,r=this._initializeContext(),a=!1;return r.observable.pipe(c.distinctUntilChanged()).subscribe(function(e){if(0<e&&!a)a=!0,i=o._createOverlay(),r.componentRef=i.attach(new s.ComponentPortal(g)),o._mapOptions(n,r.componentRef.instance),r.componentRef.instance.startInAnimation(),r.componentRef.changeDetectorRef.detectChanges();else if(e<=0&&a){a=!1;var t=r.componentRef.instance.startOutAnimation().subscribe(function(){t.unsubscribe(),r.componentRef.destroy(),i.detach(),i.dispose()})}}),r},v.prototype.createOverlayComponent=function(e,t,n){e.height=undefined,e.style=h.Overlay;var o=this._createComponent(e),i=!1;return o.componentRef.instance.content=new s.TemplatePortal(n,t),t.clear(),t.insert(o.componentRef.hostView,0),o.observable.pipe(c.distinctUntilChanged()).subscribe(function(e){0<e&&!i?(i=!0,o.componentRef.instance.startInAnimation()):e<=0&&i&&(i=!1,o.componentRef.instance.startOutAnimation())}),o},v.prototype.createReplaceComponent=function(e,n,t,o){var i=t.elementRef.nativeElement;e.height=i.nextElementSibling?i.nextElementSibling.scrollHeight:undefined,e.style=h.None;var r=this._createComponent(e),a=!1,s=n.createEmbeddedView(t,o);return r.observable.pipe(c.distinctUntilChanged()).subscribe(function(e){if(0<e&&!a)a=!0,n.indexOf(r.componentRef.hostView)<0&&(n.detach(n.indexOf(s)),n.insert(r.componentRef.hostView,0)),r.componentRef.instance.startInAnimation();else if(e<=0&&a){a=!1;var t=r.componentRef.instance.startOutAnimation().subscribe(function(){t.unsubscribe(),n.indexOf(s)<0&&(n.detach(n.indexOf(r.componentRef.hostView)),n.insert(s,0)),s.detectChanges(),s.markForCheck()})}}),r},v.prototype._createOverlay=function(){var e=new r.OverlayConfig;return e.hasBackdrop=!1,e.positionStrategy=this._overlay.position().global().centerHorizontally().centerVertically(),this._overlay.create(e)},v.prototype._createComponent=function(e){var t=this._initializeContext();return t.componentRef=this._componentFactoryResolver.resolveComponentFactory(g).create(this._injector),this._mapOptions(e,t.componentRef.instance),t},v.prototype._initializeContext=function(){var e=new a.Subject;return{observable:e.asObservable(),subject:e,componentRef:undefined,times:0}},v.prototype._mapOptions=function(e,t){t.style=e.style,e.type!==undefined&&(t.type=e.type),e.height!==undefined&&(t.height=e.height),e.mode!==undefined&&(t.mode=e.mode),e.color!==undefined&&(t.color=e.color)},v.decorators=[{type:l.Injectable}],v.ctorParameters=function(){return[{type:l.ComponentFactoryResolver},{type:r.Overlay},{type:l.Injector}]},v);function v(e,t,n){this._componentFactoryResolver=e,this._overlay=t,this._injector=n}function b(e,t,n,o){return e||new _(t,n,o)}var x,C={provide:_,deps:[[new l.Optional,new l.SkipSelf,_],l.ComponentFactoryResolver,r.Overlay,l.Injector],useFactory:b},O=function V(e){if(this.name=e.name,!this.name)throw Error("Name is required for [TdLoading] configuration.");this.mode=e.mode?e.mode:u.Indeterminate,this.type=e.type?e.type:d.Circular,this.color=e.color?e.color:"primary"},R=(function N(e,t){function n(){this.constructor=e}p(e,t),e.prototype=null===t?Object.create(t):(n.prototype=t.prototype,new n)}(w,x=O),w);function w(e){var t=x.call(this,e)||this;return t.strategy=e.strategy?e.strategy:m.Replace,t}var k=(D.prototype.createComponent=function(e,t,n,o){var i=new R(e);if(this._context[i.name])throw Error("Name duplication: [TdLoading] directive has a name conflict with "+i.name+".");return i.strategy===m.Overlay?this._context[i.name]=this._loadingFactory.createOverlayComponent(i,t,n):this._context[i.name]=this._loadingFactory.createReplaceComponent(i,t,n,o),this._context[i.name]},D.prototype.create=function(e){var t=new O(e);this.removeComponent(t.name),this._context[t.name]=this._loadingFactory.createFullScreenComponent(t)},D.prototype.removeComponent=function(e){this._context[e]&&(this._context[e].subject.unsubscribe(),this._context[e].componentRef&&this._context[e].componentRef.destroy(),this._context[e]=undefined,delete this._context[e])},D.prototype.register=function(e,t){var n=this;return void 0===e&&(e="td-loading-main"),void 0===t&&(t=1),this._context[e]?(t=t<1?1:t,this._context[e].times+=t,this._context[e].subject.next(this._context[e].times),!0):(this._timeouts[e]?this._clearTimeout(e):this._timeouts[e]=setTimeout(function(){n.register(e,t)}),!1)},D.prototype.resolve=function(e,t){if(void 0===e&&(e="td-loading-main"),void 0===t&&(t=1),this._clearTimeout(e),this._context[e]){if(t=t<1?1:t,0<this._context[e].times){var n=this._context[e].times;n-=t,this._context[e].times=n<0?0:n}return this._context[e].subject.next(this._context[e].times),!0}return!1},D.prototype.resolveAll=function(e){return void 0===e&&(e="td-loading-main"),this._clearTimeout(e),!!this._context[e]&&(this._context[e].times=0,this._context[e].subject.next(this._context[e].times),!0)},D.prototype.setValue=function(e,t){if(this._context[e]){var n=this._context[e].componentRef.instance;if(n.mode===u.Determinate&&n.animation)return n.value=t,!0}return!1},D.prototype._clearTimeout=function(e){clearTimeout(this._timeouts[e]),delete this._timeouts[e]},D.decorators=[{type:l.Injectable}],D.ctorParameters=function(){return[{type:_}]},D);function D(e){this._loadingFactory=e,this._context={},this._timeouts={},this.create({name:"td-loading-main"})}function I(e,t){return e||new k(t)}var F={provide:k,deps:[[new l.Optional,new l.SkipSelf,k],_],useFactory:I},L=function q(){this.$implicit=undefined,this.tdLoading=undefined},S=0,j=(Object.defineProperty(A.prototype,"name",{set:function(e){this._name||e&&(this._name=e)},enumerable:!0,configurable:!0}),Object.defineProperty(A.prototype,"until",{set:function(e){this._name||(this._name="td-loading-until-"+S++),this._context.$implicit=this._context.tdLoading=e,e?this._loadingService.resolveAll(this._name):this._loadingService.register(this._name)},enumerable:!0,configurable:!0}),Object.defineProperty(A.prototype,"type",{set:function(e){switch(e){case d.Linear:this._type=d.Linear;break;default:this._type=d.Circular}},enumerable:!0,configurable:!0}),Object.defineProperty(A.prototype,"mode",{set:function(e){switch(e){case u.Determinate:this._mode=u.Determinate;break;default:this._mode=u.Indeterminate}},enumerable:!0,configurable:!0}),Object.defineProperty(A.prototype,"strategy",{set:function(e){switch(e){case m.Overlay:this._strategy=m.Overlay;break;default:this._strategy=m.Replace}},enumerable:!0,configurable:!0}),A.prototype.ngOnInit=function(){this._registerComponent()},A.prototype.ngOnDestroy=function(){this._loadingService.removeComponent(this._name),this._loadingRef=undefined},A.prototype._registerComponent=function(){if(!this._name)throw new Error("Name is needed to register loading directive");this._loadingRef||(this._loadingRef=this._loadingService.createComponent({name:this._name,type:this._type,mode:this._mode,color:this.color,strategy:this._strategy},this._viewContainerRef,this._templateRef,this._context))},A.decorators=[{type:l.Directive,args:[{selector:"[tdLoading]"}]}],A.ctorParameters=function(){return[{type:l.ViewContainerRef},{type:l.TemplateRef},{type:k}]},A.propDecorators={name:[{type:l.Input,args:["tdLoading"]}],until:[{type:l.Input,args:["tdLoadingUntil"]}],type:[{type:l.Input,args:["tdLoadingType"]}],mode:[{type:l.Input,args:["tdLoadingMode"]}],strategy:[{type:l.Input,args:["tdLoadingStrategy"]}],color:[{type:l.Input,args:["tdLoadingColor"]}]},A);function A(e,t,n){this._viewContainerRef=e,this._templateRef=t,this._loadingService=n,this._context=new L,this.color="primary"}var T=[g,j],P=[g],M=(E.decorators=[{type:l.NgModule,args:[{imports:[t.CommonModule,n.MatProgressBarModule,o.MatProgressSpinnerModule,r.OverlayModule,s.PortalModule],declarations:[T],exports:[T],providers:[C,F],entryComponents:[P]}]}],E);function E(){}e.CovalentLoadingModule=M,e.LoadingType=d,e.LoadingMode=u,e.LoadingStrategy=m,e.LoadingStyle=h,e.TD_CIRCLE_DIAMETER=f,e.TdLoadingComponent=g,e.TdLoadingContext=L,e.TdLoadingDirective=j,e.LOADING_PROVIDER_FACTORY=I,e.TdLoadingConfig=O,e.TdLoadingDirectiveConfig=R,e.TdLoadingService=k,e.LOADING_PROVIDER=F,e.LOADING_FACTORY_PROVIDER_FACTORY=b,e.TdLoadingFactory=_,e.LOADING_FACTORY_PROVIDER=C,Object.defineProperty(e,"__esModule",{value:!0})});
//# sourceMappingURL=covalent-core-loading.umd.min.js.map