blob: e3bd15bed1a3938a98ba77a5f89a92f9276d245c [file] [log] [blame]
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("@angular/core"),require("@angular/common"),require("@angular/cdk/portal"),require("@angular/cdk/overlay"),require("@angular/material/progress-bar"),require("@angular/material/progress-spinner"),require("@covalent/core/common"),require("rxjs"),require("rxjs/operators")):"function"==typeof define&&define.amd?define("@covalent/core/loading",["exports","@angular/core","@angular/common","@angular/cdk/portal","@angular/cdk/overlay","@angular/material/progress-bar","@angular/material/progress-spinner","@covalent/core/common","rxjs","rxjs/operators"],t):t(((e="undefined"!=typeof globalThis?globalThis:e||self).covalent=e.covalent||{},e.covalent.core=e.covalent.core||{},e.covalent.core.loading={}),e.ng.core,e.ng.common,e.ng.cdk.portal,e.ng.cdk.overlay,e.ng.material.progressBar,e.ng.material.progressSpinner,e.covalent.core.common,e.rxjs,e.rxjs.operators)}(this,(function(e,t,n,o,i,r,a,s,c,l){"use strict";
/*! *****************************************************************************
Copyright (c) Microsoft Corporation.
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
***************************************************************************** */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)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n])})(e,t)};Object.create;Object.create;var d={Circular:"circular",Linear:"linear"},h={Determinate:"determinate",Indeterminate:"indeterminate"},u={Overlay:"overlay",Replace:"replace"},m={FullScreen:"fullscreen",Overlay:"overlay",None:"none"},g=100,f=function(){function e(e,t){this._elementRef=e,this._changeDetectorRef=t,this._mode=h.Indeterminate,this._defaultMode=h.Indeterminate,this._value=0,this._circleDiameter=g,this.animation=!1,this.style=m.None,this.type=d.Circular,this.color="primary"}return Object.defineProperty(e.prototype,"mode",{get:function(){return this._mode},set:function(e){this._defaultMode=e},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"value",{get:function(){return this._value},set:function(e){this._value=e,this._changeDetectorRef.markForCheck()},enumerable:!1,configurable:!0}),e.prototype.ngDoCheck=function(){this.isOverlay()&&this._hostHeight()>1&&this.animation&&(this._setCircleDiameter(),this._changeDetectorRef.markForCheck())},e.prototype.getHeight=function(){return this.isOverlay()||this.isFullScreen()?void 0:this.height?this.height+"px":"150px"},e.prototype.getCircleDiameter=function(){return this._circleDiameter},e.prototype.getCircleStrokeWidth=function(){var e=this.getCircleDiameter()/10;return Math.abs(e)},e.prototype.isCircular=function(){return this.type===d.Circular},e.prototype.isLinear=function(){return this.type===d.Linear},e.prototype.isFullScreen=function(){return this.style===m.FullScreen},e.prototype.isOverlay=function(){return this.style===m.Overlay},e.prototype.show=function(){this._mode=this._defaultMode,this._setCircleDiameter(),this.animation=!0,this._changeDetectorRef.markForCheck()},e.prototype.hide=function(){this.animation=!1,this._mode=h.Determinate,this.value=0,this._changeDetectorRef.markForCheck()},e.prototype._setCircleDiameter=function(){var e=g;this.height?e=this.height:void 0===this.height&&(e=this._hostHeight()),this._circleDiameter=e&&e<=g?Math.floor(e):g},e.prototype._hostHeight=function(){return this._elementRef.nativeElement?this._elementRef.nativeElement.getBoundingClientRect().height:0},e}();f.decorators=[{type:t.Component,args:[{selector:"td-loading",template:'<div\n 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>\n <div [@tdFadeInOut]="animation" [style.min-height]="getHeight()" class="td-loading">\n <mat-progress-spinner\n *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()" [mode]="mode" [value]="value" [color]="color"></mat-progress-bar>\n </div>\n <ng-template [cdkPortalOutlet]="content"></ng-template>\n</div>\n',animations:[s.tdFadeInOutAnimation],styles:[".td-loading-wrapper{display:block;position:relative}.td-loading-wrapper.td-fullscreen{position:inherit}.td-loading-wrapper .td-loading{-ms-flex:1;-ms-flex-align:center;-ms-flex-direction:row;-ms-flex-line-pack:center;-ms-flex-pack:center;align-content:center;align-items:center;box-sizing:border-box;display:-ms-flexbox;display:flex;flex:1;flex-direction:row;justify-content:center;max-width:100%}.td-loading-wrapper.td-overlay .td-loading{left:0;margin:0;position:absolute;right:0;top:0;z-index:1000}.td-loading-wrapper.td-overlay .td-loading mat-progress-bar{left:0;position:absolute;right:0;top:0}.td-loading-wrapper.td-overlay-circular .td-loading{bottom:0}"]}]}],f.ctorParameters=function(){return[{type:t.ElementRef},{type:t.ChangeDetectorRef}]};var y=function(){function e(e,t,n){this._componentFactoryResolver=e,this._overlay=t,this._injector=n}return e.prototype.createFullScreenComponent=function(e){var t=this;e.height=void 0,e.style=m.FullScreen;var n,i=this._initializeContext(),r=!1;return i.observable.pipe(l.distinctUntilChanged()).subscribe((function(a){a>0&&!r?(r=!0,n=t._createOverlay(),i.componentRef=n.attach(new o.ComponentPortal(f)),t._mapOptions(e,i.componentRef.instance),i.componentRef.instance.show(),i.componentRef.changeDetectorRef.detectChanges()):a<=0&&r&&(r=!1,i.componentRef.instance.hide(),i.componentRef.destroy(),n.detach(),n.dispose())})),i},e.prototype.createOverlayComponent=function(e,t,n){e.height=void 0,e.style=m.Overlay;var i=this._createComponent(e),r=!1;return i.componentRef.instance.content=new o.TemplatePortal(n,t),t.clear(),t.insert(i.componentRef.hostView,0),i.observable.pipe(l.distinctUntilChanged()).subscribe((function(e){e>0&&!r?(r=!0,i.componentRef.instance.show()):e<=0&&r&&(r=!1,i.componentRef.instance.hide())})),i},e.prototype.createReplaceComponent=function(e,t,n,o){var i=n.elementRef.nativeElement;e.height=i.nextElementSibling?i.nextElementSibling.scrollHeight:void 0,e.style=m.None;var r=this._createComponent(e),a=!1,s=t.createEmbeddedView(n,o);return r.observable.pipe(l.distinctUntilChanged()).subscribe((function(e){if(e>0&&!a)a=!0,t.indexOf(r.componentRef.hostView)<0&&(t.detach(t.indexOf(s)),t.insert(r.componentRef.hostView,0)),r.componentRef.instance.show();else if(e<=0&&a){a=!1,r.componentRef.instance.hide(),t.indexOf(s)<0&&(t.detach(t.indexOf(r.componentRef.hostView)),t.insert(s,0)),s.detectChanges(),s.markForCheck()}})),r},e.prototype._createOverlay=function(){var e=new i.OverlayConfig;return e.hasBackdrop=!1,e.positionStrategy=this._overlay.position().global().centerHorizontally().centerVertically(),this._overlay.create(e)},e.prototype._createComponent=function(e){var t=this._initializeContext();return t.componentRef=this._componentFactoryResolver.resolveComponentFactory(f).create(this._injector),this._mapOptions(e,t.componentRef.instance),t},e.prototype._initializeContext=function(){var e=new c.Subject;return{observable:e.asObservable(),subject:e,componentRef:void 0,times:0}},e.prototype._mapOptions=function(e,t){t.style=e.style,void 0!==e.type&&(t.type=e.type),void 0!==e.height&&(t.height=e.height),void 0!==e.mode&&(t.mode=e.mode),void 0!==e.color&&(t.color=e.color)},e}();function v(e,t,n,o){return e||new y(t,n,o)}y.decorators=[{type:t.Injectable}],y.ctorParameters=function(){return[{type:t.ComponentFactoryResolver},{type:i.Overlay},{type:t.Injector}]};var _={provide:y,deps:[[new t.Optional,new t.SkipSelf,y],t.ComponentFactoryResolver,i.Overlay,t.Injector],useFactory:v};var b=function(e){if(this.name=e.name,!this.name)throw Error("Name is required for [TdLoading] configuration.");this.mode=e.mode?e.mode:h.Indeterminate,this.type=e.type?e.type:d.Circular,this.color=e.color?e.color:"primary"};var x=function(e){function t(t){var n=e.call(this,t)||this;return n.strategy=t.strategy?t.strategy:u.Replace,n}return function(e,t){function n(){this.constructor=e}p(e,t),e.prototype=null===t?Object.create(t):(n.prototype=t.prototype,new n)}(t,e),t}(b);var C=function(){function e(e){this._loadingFactory=e,this._context={},this._timeouts={},this.create({name:"td-loading-main"})}return e.prototype.createComponent=function(e,t,n,o){var i=new x(e);if(this._context[i.name])throw Error("Name duplication: [TdLoading] directive has a name conflict with "+i.name+".");return i.strategy===u.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]},e.prototype.create=function(e){var t=new b(e);this.removeComponent(t.name),this._context[t.name]=this._loadingFactory.createFullScreenComponent(t)},e.prototype.removeComponent=function(e){this._context[e]&&(this._context[e].subject.unsubscribe(),this._context[e].componentRef&&this._context[e].componentRef.destroy(),this._context[e]=void 0,delete this._context[e])},e.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)},e.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,this._context[e].times>0){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},e.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)},e.prototype.setValue=function(e,t){if(this._context[e]){var n=this._context[e].componentRef.instance;if(n.mode===h.Determinate&&n.animation)return n.value=t,!0}return!1},e.prototype._clearTimeout=function(e){clearTimeout(this._timeouts[e]),delete this._timeouts[e]},e}();function R(e,t){return e||new C(t)}C.decorators=[{type:t.Injectable}],C.ctorParameters=function(){return[{type:y}]};var O={provide:C,deps:[[new t.Optional,new t.SkipSelf,C],y],useFactory:R},w=function(){this.$implicit=void 0,this.tdLoading=void 0};var D=0,L=function(){function e(e,t,n){this._viewContainerRef=e,this._templateRef=t,this._loadingService=n,this._context=new w,this.color="primary"}return Object.defineProperty(e.prototype,"name",{set:function(e){!this._name&&e&&(this._name=e)},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"until",{set:function(e){this._name||(this._name="td-loading-until-"+D++),this._context.$implicit=this._context.tdLoading=e,e?this._loadingService.resolveAll(this._name):this._loadingService.register(this._name)},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"type",{set:function(e){this._type=e===d.Linear?d.Linear:d.Circular},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"mode",{set:function(e){this._mode=e===h.Determinate?h.Determinate:h.Indeterminate},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"strategy",{set:function(e){this._strategy=e===u.Overlay?u.Overlay:u.Replace},enumerable:!1,configurable:!0}),e.prototype.ngOnInit=function(){this._registerComponent()},e.prototype.ngOnDestroy=function(){this._loadingService.removeComponent(this._name),this._loadingRef=void 0},e.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))},e}();L.decorators=[{type:t.Directive,args:[{selector:"[tdLoading]"}]}],L.ctorParameters=function(){return[{type:t.ViewContainerRef},{type:t.TemplateRef},{type:C}]},L.propDecorators={name:[{type:t.Input,args:["tdLoading"]}],until:[{type:t.Input,args:["tdLoadingUntil"]}],type:[{type:t.Input,args:["tdLoadingType"]}],mode:[{type:t.Input,args:["tdLoadingMode"]}],strategy:[{type:t.Input,args:["tdLoadingStrategy"]}],color:[{type:t.Input,args:["tdLoadingColor"]}]};var j=[f,L],F=function(){};F.decorators=[{type:t.NgModule,args:[{imports:[n.CommonModule,r.MatProgressBarModule,a.MatProgressSpinnerModule,i.OverlayModule,o.PortalModule],declarations:[j],exports:[j],providers:[_,O]}]}],e.CovalentLoadingModule=F,e.LOADING_FACTORY_PROVIDER=_,e.LOADING_FACTORY_PROVIDER_FACTORY=v,e.LOADING_PROVIDER=O,e.LOADING_PROVIDER_FACTORY=R,e.LoadingMode=h,e.LoadingStrategy=u,e.LoadingStyle=m,e.LoadingType=d,e.TD_CIRCLE_DIAMETER=g,e.TdLoadingComponent=f,e.TdLoadingConfig=b,e.TdLoadingContext=w,e.TdLoadingDirective=L,e.TdLoadingDirectiveConfig=x,e.TdLoadingFactory=y,e.TdLoadingService=C,Object.defineProperty(e,"__esModule",{value:!0})}));
//# sourceMappingURL=covalent-core-loading.umd.min.js.map