| !function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("@angular/core"),require("@angular/common"),require("@angular/cdk/portal"),require("@angular/platform-browser"),require("rxjs"),require("rxjs/operators")):"function"==typeof define&&define.amd?define("@covalent/core/virtual-scroll",["exports","@angular/core","@angular/common","@angular/cdk/portal","@angular/platform-browser","rxjs","rxjs/operators"],e):e(((t="undefined"!=typeof globalThis?globalThis:t||self).covalent=t.covalent||{},t.covalent.core=t.covalent.core||{},t.covalent.core["virtual-scroll"]={}),t.ng.core,t.ng.common,t.ng.cdk.portal,t.ng.platformBrowser,t.rxjs,t.rxjs.operators)}(this,(function(t,e,o,r,i,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)Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o])})(t,e)};Object.create;Object.create;var l=function(t){function e(e,o){return t.call(this,e,o)||this}return function(t,e){function o(){this.constructor=t}s(t,e),t.prototype=null===e?Object.create(e):(o.prototype=e.prototype,new o)}(e,t),e}(r.TemplatePortalDirective);l.decorators=[{type:e.Directive,args:[{selector:"[tdVirtualScrollRow]"}]}],l.ctorParameters=function(){return[{type:e.TemplateRef},{type:e.ViewContainerRef}]};var c=function(){function t(t,o,r,i){this._elementRef=t,this._domSanitizer=o,this._renderer=r,this._changeDetectorRef=i,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 e.EventEmitter,this.trackBy=function(t,e){return e}}return Object.defineProperty(t.prototype,"data",{get:function(){return this._data},set:function(t){this._data=t,this._initialized&&this._calculateVirtualRows(),this._changeDetectorRef.markForCheck()},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"virtualData",{get:function(){return this._virtualData},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"rowHeight",{get:function(){return this._rows&&this._rows.toArray()[0]?this._rows.toArray()[0].nativeElement.getBoundingClientRect().height:0},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"totalHeight",{get:function(){return this._totalHeight},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"fromRow",{get:function(){return this._fromRow},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"toRow",{get:function(){return this._toRow},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"offsetTransform",{get:function(){return this._offsetTransform},enumerable:!1,configurable:!0}),t.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})})))},t.prototype.ngAfterViewChecked=function(){var t=this._elementRef.nativeElement.getBoundingClientRect().height;this._hostHeight!==t&&(this._hostHeight=t,this._initialized&&this._calculateVirtualRows())},t.prototype.ngOnDestroy=function(){this._subs&&this._subs.forEach((function(t){t.unsubscribe()}))},t.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()}},t.prototype.refresh=function(){this._calculateVirtualRows()},t.prototype.scrollTo=function(t){this._elementRef.nativeElement.scrollTop=t*this.rowHeight,this._changeDetectorRef.markForCheck()},t.prototype.scrollToStart=function(){this.scrollTo(0),this._changeDetectorRef.markForCheck()},t.prototype.scrollToEnd=function(){this.scrollTo(this.totalHeight/this.rowHeight),this._changeDetectorRef.markForCheck()},t.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=e>0?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()}))},t}();c.decorators=[{type:e.Component,args:[{selector:"td-virtual-scroll-container",template:'<div [style.height.px]="totalHeight"></div>\n<div [style.transform]="offsetTransform" [style.position]="\'absolute\'" [style.width.%]="100">\n <ng-template let-row let-index="index" ngFor [ngForOf]="virtualData" [ngForTrackBy]="trackBy">\n <div #rowElement [style.width.%]="100">\n <ng-template\n *ngIf="_rowTemplate"\n [ngTemplateOutlet]="_rowTemplate.templateRef"\n [ngTemplateOutletContext]="{\n 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 }"\n ></ng-template>\n </div>\n </ng-template>\n</div>\n',changeDetection:e.ChangeDetectionStrategy.OnPush,styles:[":host{display:block;height:100%;overflow:auto;position:relative;width:100%}"]}]}],c.ctorParameters=function(){return[{type:e.ElementRef},{type:i.DomSanitizer},{type:e.Renderer2},{type:e.ChangeDetectorRef}]},c.propDecorators={data:[{type:e.Input,args:["data"]}],bottom:[{type:e.Output}],_rows:[{type:e.ViewChildren,args:["rowElement"]}],_rowTemplate:[{type:e.ContentChild,args:[l]}],trackBy:[{type:e.Input}],handleScroll:[{type:e.HostListener,args:["scroll",["$event"]]}]};var h=[l,c],u=function(){};u.decorators=[{type:e.NgModule,args:[{imports:[o.CommonModule],declarations:[h],exports:[h]}]}],t.CovalentVirtualScrollModule=u,t.TdVirtualScrollContainerComponent=c,t.TdVirtualScrollRowDirective=l,Object.defineProperty(t,"__esModule",{value:!0})})); |