blob: 382980220196845d3dd73c6d09c762bcb4261e36 [file] [log] [blame]
{"version":3,"file":"covalent-core-virtual-scroll.js.map","sources":["ng://@covalent/core/virtual-scroll/virtual-scroll-row.directive.ts","ng://@covalent/core/virtual-scroll/virtual-scroll-container.component.ts","ng://@covalent/core/virtual-scroll/virtual-scroll.module.ts"],"sourcesContent":["import { Directive, TemplateRef, ViewContainerRef } from '@angular/core';\nimport { TemplatePortalDirective } from '@angular/cdk/portal';\n\n@Directive({selector: '[tdVirtualScrollRow]'})\nexport class TdVirtualScrollRowDirective extends TemplatePortalDirective {\n\n constructor(templateRef: TemplateRef<any>,\n viewContainerRef: ViewContainerRef) {\n super(templateRef, viewContainerRef);\n }\n \n}\n","import { Component, Directive, Input, Output, EventEmitter, ContentChild, AfterViewInit, ViewChild,\n ChangeDetectionStrategy, ChangeDetectorRef, QueryList, ViewChildren, ElementRef, HostListener,\n Renderer2, AfterViewChecked, OnDestroy, TrackByFunction } from '@angular/core';\nimport { DomSanitizer, SafeStyle } from '@angular/platform-browser';\n\nimport { Subscription, Subject } from 'rxjs';\nimport { debounceTime } from 'rxjs/operators';\n\nimport { TdVirtualScrollRowDirective } from './virtual-scroll-row.directive';\n\nconst TD_VIRTUAL_OFFSET: number = 2;\nconst SCROLL_DEBOUNCE: number = 200;\n\nexport interface ITdVirtualScrollBottomEvent {\n lastRow: any;\n lastIndex: number;\n}\n\n@Component({\n selector: 'td-virtual-scroll-container',\n styleUrls: ['./virtual-scroll-container.component.scss' ],\n templateUrl: './virtual-scroll-container.component.html',\n changeDetection: ChangeDetectionStrategy.OnPush,\n})\nexport class TdVirtualScrollContainerComponent implements AfterViewInit, AfterViewChecked, OnDestroy {\n\n private _subs: Subscription[] = [];\n private _bottom: Subject<any> = new Subject();\n private _initialized: boolean = false;\n\n private _totalHeight: number = 0;\n private _hostHeight: number = 0;\n private _scrollVerticalOffset: number = 0;\n private _offsetTransform: SafeStyle;\n\n private _fromRow: number = 0;\n private _toRow: number = 0;\n\n private _data: any[];\n private _virtualData: any[];\n\n /**\n * data: any[]\n * List of items to virtually iterate on.\n */\n @Input('data')\n set data(data: any[]) {\n this._data = data;\n if (this._initialized) {\n this._calculateVirtualRows();\n }\n this._changeDetectorRef.markForCheck();\n }\n get data(): any[] {\n return this._data;\n }\n\n get virtualData(): any[] {\n return this._virtualData;\n }\n\n /**\n * bottom: function\n * Method to be executed when user scrolled to the last item of the list.\n * An [ITdVirtualScrollBottomEvent] event is emitted\n */\n @Output() bottom: EventEmitter<ITdVirtualScrollBottomEvent> = new EventEmitter<ITdVirtualScrollBottomEvent>();\n\n @ViewChildren('rowElement') _rows: QueryList<ElementRef>;\n\n @ContentChild(TdVirtualScrollRowDirective) _rowTemplate: TdVirtualScrollRowDirective;\n\n get rowHeight(): number {\n if (this._rows && this._rows.toArray()[0]) {\n return this._rows.toArray()[0].nativeElement.getBoundingClientRect().height;\n }\n return 0;\n }\n\n get totalHeight(): number {\n return this._totalHeight;\n }\n\n get fromRow(): number {\n return this._fromRow;\n }\n\n get toRow(): number {\n return this._toRow;\n }\n\n get offsetTransform(): SafeStyle {\n return this._offsetTransform;\n }\n\n constructor(private _elementRef: ElementRef,\n private _domSanitizer: DomSanitizer,\n private _renderer: Renderer2,\n private _changeDetectorRef: ChangeDetectorRef) {}\n\n ngAfterViewInit(): void {\n this._subs.push(this._rows.changes.subscribe(() => {\n this._calculateVirtualRows();\n }));\n this._initialized = true;\n this._calculateVirtualRows();\n\n this._subs.push(this._bottom.pipe(\n debounceTime(SCROLL_DEBOUNCE),\n ).subscribe(() => {\n this.bottom.emit({\n lastRow: this._data[this._data.length - 1],\n lastIndex: this.toRow,\n });\n }));\n }\n\n ngAfterViewChecked(): void {\n let newHostHeight: number = this._elementRef.nativeElement.getBoundingClientRect().height;\n if (this._hostHeight !== newHostHeight) {\n this._hostHeight = newHostHeight;\n if (this._initialized) {\n this._calculateVirtualRows();\n }\n }\n }\n\n ngOnDestroy(): void {\n if (this._subs) {\n this._subs.forEach((sub: Subscription) => {\n sub.unsubscribe();\n });\n }\n }\n\n /**\n * trackBy?: TrackByFunction\n * This accepts the same trackBy function [ngFor] does.\n * https://angular.io/api/core/TrackByFunction\n */\n @Input('trackBy') trackBy: TrackByFunction<any> = (index: number, item: any) => {\n return item;\n }\n\n @HostListener('scroll', ['$event'])\n handleScroll(event: Event): void {\n let element: HTMLElement = (<HTMLElement>event.target);\n if (element) {\n let verticalScroll: number = element.scrollTop;\n if (this._scrollVerticalOffset !== verticalScroll) {\n this._scrollVerticalOffset = verticalScroll;\n if (this._initialized) {\n this._calculateVirtualRows();\n }\n }\n if (this._initialized) {\n // check to see if bottom was hit to throw the bottom event\n if ((this._data.length * this.rowHeight) - (verticalScroll + this._hostHeight) === 0) {\n this._bottom.next();\n }\n }\n }\n }\n\n /**\n * Method to refresh and recalculate the virtual rows\n * e.g. after changing the [data] content\n */\n refresh(): void {\n this._calculateVirtualRows();\n }\n\n /**\n * Method to scroll to a specific row of the list.\n */\n scrollTo(row: number): void {\n this._elementRef.nativeElement.scrollTop = row * this.rowHeight;\n this._changeDetectorRef.markForCheck();\n }\n\n /**\n * Method to scroll to the start of the list.\n */\n scrollToStart(): void {\n this.scrollTo(0);\n this._changeDetectorRef.markForCheck();\n }\n\n /**\n * Method to scroll to the end of the list.\n */\n scrollToEnd(): void {\n this.scrollTo(this.totalHeight / this.rowHeight);\n this._changeDetectorRef.markForCheck();\n }\n\n private _calculateVirtualRows(): void {\n if (this._data) {\n this._totalHeight = this._data.length * this.rowHeight;\n let fromRow: number = Math.floor((this._scrollVerticalOffset / this.rowHeight)) - TD_VIRTUAL_OFFSET;\n this._fromRow = fromRow > 0 ? fromRow : 0;\n let range: number = Math.floor((this._hostHeight / this.rowHeight)) + (TD_VIRTUAL_OFFSET * 2);\n let toRow: number = range + this.fromRow;\n if (isFinite(toRow) && toRow > this._data.length) {\n toRow = this._data.length;\n } else if (!isFinite(toRow)) {\n toRow = TD_VIRTUAL_OFFSET;\n }\n this._toRow = toRow;\n } else {\n this._totalHeight = 0;\n this._fromRow = 0;\n this._toRow = 0;\n }\n\n let offset: number = 0;\n if (this._scrollVerticalOffset > (TD_VIRTUAL_OFFSET * this.rowHeight)) {\n offset = this.fromRow * this.rowHeight;\n }\n\n this._offsetTransform = this._domSanitizer.bypassSecurityTrustStyle('translateY(' + (offset - this.totalHeight) + 'px)');\n if (this._data) {\n this._virtualData = this.data.slice(this.fromRow, this.toRow);\n }\n\n // mark for check at the end of the queue so we are sure\n // that the changes will be marked\n Promise.resolve().then(() => {\n this._changeDetectorRef.markForCheck();\n });\n }\n}\n","import { NgModule, Type } from '@angular/core';\nimport { CommonModule } from '@angular/common';\n\nimport { TdVirtualScrollRowDirective } from './virtual-scroll-row.directive';\nimport { TdVirtualScrollContainerComponent } from './virtual-scroll-container.component';\n\nconst TD_VIRTUAL_SCROLL: Type<any>[] = [\n TdVirtualScrollRowDirective,\n TdVirtualScrollContainerComponent,\n];\n\n@NgModule({\n imports: [\n CommonModule,\n ],\n declarations: [\n TD_VIRTUAL_SCROLL,\n ],\n exports: [\n TD_VIRTUAL_SCROLL,\n ],\n})\nexport class CovalentVirtualScrollModule {\n\n}\n"],"names":["tslib_1.__extends"],"mappings":";;;;;;;;;;;;;IAIiDA,+CAAuB;IAEtE,qCAAY,WAA6B,EAC7B,gBAAkC;eAC5C,kBAAM,WAAW,EAAE,gBAAgB,CAAC;KACrC;;gBANF,SAAS,SAAC,EAAC,QAAQ,EAAE,sBAAsB,EAAC;;;;gBAHzB,WAAW;gBAAE,gBAAgB;;IAWjD,kCAAC;CAAA,CAPgD,uBAAuB;;;;;;ACJxE;IAUM,iBAAiB,GAAW,CAAC;;IAC7B,eAAe,GAAW,GAAG;;IAoFjC,2CAAoB,WAAuB,EACvB,aAA2B,EAC3B,SAAoB,EACpB,kBAAqC;QAHrC,gBAAW,GAAX,WAAW,CAAY;QACvB,kBAAa,GAAb,aAAa,CAAc;QAC3B,cAAS,GAAT,SAAS,CAAW;QACpB,uBAAkB,GAAlB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