blob: 4c5451c5ab51d28ade170934ede49b689beeb030 [file] [log] [blame]
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("@angular/common"),require("@angular/cdk/portal"),require("@angular/core"),require("@angular/platform-browser"),require("rxjs"),require("rxjs/operators")):"function"==typeof define&&define.amd?define("@covalent/core/virtual-scroll",["exports","@angular/common","@angular/cdk/portal","@angular/core","@angular/platform-browser","rxjs","rxjs/operators"],e):e((t.covalent=t.covalent||{},t.covalent.core=t.covalent.core||{},t.covalent.core["virtual-scroll"]={}),t.ng.common,t.ng.cdk.portal,t.ng.core,t.ng.platformBrowser,t.rxjs,t.rxjs.operators)}(this,function(t,e,o,i,r,n,a){"use strict";var s=function(t,e){return(s=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var o in e)e.hasOwnProperty(o)&&(t[o]=e[o])})(t,e)};var l,c=(function d(t,e){function o(){this.constructor=t}s(t,e),t.prototype=null===e?Object.create(e):(o.prototype=e.prototype,new o)}(h,l=o.TemplatePortalDirective),h.decorators=[{type:i.Directive,args:[{selector:"[tdVirtualScrollRow]"}]}],h.ctorParameters=function(){return[{type:i.TemplateRef},{type:i.ViewContainerRef}]},h);function h(t,e){return l.call(this,t,e)||this}var u=(Object.defineProperty(f.prototype,"data",{get:function(){return this._data},set:function(t){this._data=t,this._initialized&&this._calculateVirtualRows(),this._changeDetectorRef.markForCheck()},enumerable:!0,configurable:!0}),Object.defineProperty(f.prototype,"virtualData",{get:function(){return this._virtualData},enumerable:!0,configurable:!0}),Object.defineProperty(f.prototype,"rowHeight",{get:function(){return this._rows&&this._rows.toArray()[0]?this._rows.toArray()[0].nativeElement.getBoundingClientRect().height:0},enumerable:!0,configurable:!0}),Object.defineProperty(f.prototype,"totalHeight",{get:function(){return this._totalHeight},enumerable:!0,configurable:!0}),Object.defineProperty(f.prototype,"fromRow",{get:function(){return this._fromRow},enumerable:!0,configurable:!0}),Object.defineProperty(f.prototype,"toRow",{get:function(){return this._toRow},enumerable:!0,configurable:!0}),Object.defineProperty(f.prototype,"offsetTransform",{get:function(){return this._offsetTransform},enumerable:!0,configurable:!0}),f.prototype.ngAfterViewInit=function(){var t=this;this._subs.push(this._rows.changes.subscribe(function(){t._calculateVirtualRows()})),this._initialized=!0,this._calculateVirtualRows(),this._subs.push(this._bottom.pipe(a.debounceTime(200)).subscribe(function(){t.bottom.emit({lastRow:t._data[t._data.length-1],lastIndex:t.toRow})}))},f.prototype.ngAfterViewChecked=function(){var t=this._elementRef.nativeElement.getBoundingClientRect().height;this._hostHeight!==t&&(this._hostHeight=t,this._initialized&&this._calculateVirtualRows())},f.prototype.ngOnDestroy=function(){this._subs&&this._subs.forEach(function(t){t.unsubscribe()})},f.prototype.handleScroll=function(t){var e=t.target;if(e){var o=e.scrollTop;this._scrollVerticalOffset!==o&&(this._scrollVerticalOffset=o,this._initialized&&this._calculateVirtualRows()),this._initialized&&this._data.length*this.rowHeight-(o+this._hostHeight)==0&&this._bottom.next()}},f.prototype.refresh=function(){this._calculateVirtualRows()},f.prototype.scrollTo=function(t){this._elementRef.nativeElement.scrollTop=t*this.rowHeight,this._changeDetectorRef.markForCheck()},f.prototype.scrollToStart=function(){this.scrollTo(0),this._changeDetectorRef.markForCheck()},f.prototype.scrollToEnd=function(){this.scrollTo(this.totalHeight/this.rowHeight),this._changeDetectorRef.markForCheck()},f.prototype._calculateVirtualRows=function(){var t=this;if(this._data){this._totalHeight=this._data.length*this.rowHeight;var e=Math.floor(this._scrollVerticalOffset/this.rowHeight)-2;this._fromRow=0<e?e:0;var o=Math.floor(this._hostHeight/this.rowHeight)+4+this.fromRow;isFinite(o)&&o>this._data.length?o=this._data.length:isFinite(o)||(o=2),this._toRow=o}else this._totalHeight=0,this._fromRow=0,this._toRow=0;var r=0;this._scrollVerticalOffset>2*this.rowHeight&&(r=this.fromRow*this.rowHeight),this._offsetTransform=this._domSanitizer.bypassSecurityTrustStyle("translateY("+(r-this.totalHeight)+"px)"),this._data&&(this._virtualData=this.data.slice(this.fromRow,this.toRow)),Promise.resolve().then(function(){t._changeDetectorRef.markForCheck()})},f.decorators=[{type:i.Component,args:[{selector:"td-virtual-scroll-container",template:'<div [style.height.px]="totalHeight"></div>\n<div [style.transform]="offsetTransform"\n [style.position]="\'absolute\'"\n [style.width.%]="100">\n <ng-template let-row\n let-index="index"\n ngFor\n [ngForOf]="virtualData"\n [ngForTrackBy]="trackBy">\n <div #rowElement\n [style.width.%]="100">\n <ng-template *ngIf="_rowTemplate"\n [ngTemplateOutlet]="_rowTemplate.templateRef"\n [ngTemplateOutletContext]="{row: row,\n index: (fromRow + index),\n first: (fromRow + index) === 0,\n last: (fromRow + index) === (data.length - 1),\n odd: ((fromRow + index + 1) % 2) === 1,\n even: ((fromRow + index + 1) % 2) === 0}">\n </ng-template>\n </div>\n </ng-template>\n</div>',changeDetection:i.ChangeDetectionStrategy.OnPush,styles:[":host{display:block;height:100%;width:100%;overflow:auto;position:relative}"]}]}],f.ctorParameters=function(){return[{type:i.ElementRef},{type:r.DomSanitizer},{type:i.Renderer2},{type:i.ChangeDetectorRef}]},f.propDecorators={data:[{type:i.Input,args:["data"]}],bottom:[{type:i.Output}],_rows:[{type:i.ViewChildren,args:["rowElement"]}],_rowTemplate:[{type:i.ContentChild,args:[c]}],trackBy:[{type:i.Input,args:["trackBy"]}],handleScroll:[{type:i.HostListener,args:["scroll",["$event"]]}]},f);function f(t,e,o,r){this._elementRef=t,this._domSanitizer=e,this._renderer=o,this._changeDetectorRef=r,this._subs=[],this._bottom=new n.Subject,this._initialized=!1,this._totalHeight=0,this._hostHeight=0,this._scrollVerticalOffset=0,this._fromRow=0,this._toRow=0,this.bottom=new i.EventEmitter,this.trackBy=function(t,e){return e}}var p=[c,u],g=(_.decorators=[{type:i.NgModule,args:[{imports:[e.CommonModule],declarations:[p],exports:[p]}]}],_);function _(){}t.CovalentVirtualScrollModule=g,t.TdVirtualScrollContainerComponent=u,t.TdVirtualScrollRowDirective=c,Object.defineProperty(t,"__esModule",{value:!0})});
//# sourceMappingURL=covalent-core-virtual-scroll.umd.min.js.map