{"version":3,"sources":["../../src/app/components/virtualscroller/virtualscroller.ts"],"names":["VirtualScroller","el","this","delay","trackBy","index","item","onLazyLoad","EventEmitter","_totalRecords","page","_first","Object","defineProperty","prototype","val","console","log","_cache","ngAfterContentInit","_this","templates","forEach","getType","itemTemplate","template","loadingItemTemplate","headerTemplate","footerTemplate","onScrollIndexChange","lazy","virtualScrollTimeout","clearTimeout","setTimeout","Math","floor","rows","virtualScrollOffset","virtualScrollChunkSize","virtualPage","emit","first","getBlockableElement","nativeElement","children","scrollTo","mode","scrollToIndex","viewport","Component","args","selector","changeDetection","ChangeDetectionStrategy","Default","encapsulation","ViewEncapsulation","None","ElementRef","Input","ContentChild","Header","Footer","ContentChildren","PrimeTemplate","ViewChild","CdkVirtualScrollViewport","Output","NgModule","imports","CommonModule","ScrollingModule","exports","SharedModule","declarations"],"mappings":"yjBAwFI,SAAAA,EAAmBC,GAAAC,KAAAD,GAAAA,EAlCVC,KAAAC,MAAgB,IAEhBD,KAAAE,QAAoB,SAACC,EAAeC,GAAc,OAAAA,GAUjDJ,KAAAK,WAAgC,IAAIC,EAAAA,aAU9CN,KAAAO,cAAwB,EAExBP,KAAAQ,KAAe,EAEfR,KAAAS,OAAiB,SAUjBC,OAAAC,eAAab,EAAAc,UAAA,eAAY,KAAzB,WACI,OAAOZ,KAAKO,mBAEhB,SAAiBM,GACbb,KAAKO,cAAgBM,EACrBC,QAAQC,IAAI,0HAGhBL,OAAAC,eAAab,EAAAc,UAAA,QAAK,KAAlB,WACI,OAAOZ,KAAKS,YAEhB,SAAUI,GACNb,KAAKS,OAASI,EACdC,QAAQC,IAAI,wHAGhBL,OAAAC,eAAab,EAAAc,UAAA,QAAK,KAAlB,WACI,OAAOZ,KAAKgB,YAEhB,SAAUH,GACNb,KAAKgB,OAASH,EACdC,QAAQC,IAAI,4EAGhBjB,EAAAc,UAAAK,mBAAA,WAAA,IAAAC,EAAAlB,KACIA,KAAKmB,UAAUC,SAAQ,SAAChB,GACpB,OAAOA,E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BAEAA,EAAAA,qBAEAA,EAAAA,uBAEAA,EAAAA,sBAEAC,EAAAA,aAAYV,KAAA,CAACW,EAAAA,wBAEbD,EAAAA,aAAYV,KAAA,CAACY,EAAAA,2BAEbC,EAAAA,gBAAeb,KAAA,CAACc,EAAAA,iCAEhBC,EAAAA,UAASf,KAAA,CAACgB,EAAAA,8CAEVC,EAAAA,6BAwBAR,EAAAA,qBAQAA,EAAAA,qBAQAA,EAAAA,eA0EL,iCALCS,EAAAA,SAAQlB,KAAA,CAAC,CACNmB,QAAS,CAACC,EAAAA,aAAaC,EAAAA,iBACvBC,QAAS,CAACxE,EAAgByE,EAAAA,aAAaF,EAAAA,iBACvCG,aAAc,CAAC1E","sourcesContent":["import {NgModule,Component,ElementRef,AfterContentInit,Input,Output,ViewChild,EventEmitter,ContentChild,ContentChildren,QueryList,TemplateRef,ChangeDetectionStrategy, ViewEncapsulation} from '@angular/core';\nimport {CommonModule} from '@angular/common';\nimport {Header,Footer,PrimeTemplate,SharedModule} from 'primeng/api';\nimport {ScrollingModule,CdkVirtualScrollViewport} from '@angular/cdk/scrolling';\nimport {BlockableUI} from 'primeng/api';\n\n@Component({\n selector: 'p-virtualScroller',\n template:`\n
\n
\n \n \n
\n
\n
\n \n \n
\n \n
\n
\n
\n
\n
\n
\n \n \n
\n
\n `,\n changeDetection: ChangeDetectionStrategy.Default,\n encapsulation: ViewEncapsulation.None\n})\nexport class VirtualScroller implements AfterContentInit,BlockableUI {\n\n @Input() value: any[];\n\n @Input() itemSize: number; \n\n @Input() style: any;\n\n @Input() styleClass: string;\n \n @Input() scrollHeight: any;\n\n @Input() lazy: boolean;\n\n @Input() rows: number;\n\n @Input() minBufferPx: number;\n\n @Input() maxBufferPx: number;\n\n @Input() delay: number = 250;\n \n @Input() trackBy: Function = (index: number, item: any) => item;\n \n @ContentChild(Header) header: Header;\n\n @ContentChild(Footer) footer: Footer;\n \n @ContentChildren(PrimeTemplate) templates: QueryList;\n\n @ViewChild(CdkVirtualScrollViewport) viewport: CdkVirtualScrollViewport;\n\n @Output() onLazyLoad: EventEmitter = new EventEmitter();\n\n itemTemplate: TemplateRef;\n\n headerTemplate: TemplateRef;\n\n footerTemplate: TemplateRef;\n\n loadingItemTemplate: TemplateRef;\n\n _totalRecords: number = 0;\n\n page: number = 0;\n\n _first: number = 0;\n\n _cache: boolean;\n\n virtualScrollTimeout: any;\n\n virtualPage: number;\n\n constructor(public el: ElementRef) {}\n\n @Input() get totalRecords(): number {\n return this._totalRecords;\n }\n set totalRecords(val: number) {\n this._totalRecords = val;\n console.log(\"totalRecords is deprecated, provide a value with the length of virtual items instead.\");\n }\n\n @Input() get first(): number {\n return this._first;\n }\n set first(val:number) {\n this._first = val;\n console.log(\"first property is deprecated, use scrollToIndex function to scroll a specific item.\");\n }\n\n @Input() get cache(): boolean {\n return this._cache;\n }\n set cache(val: boolean) {\n this._cache = val;\n console.log(\"cache is deprecated as it is always on.\");\n }\n\n ngAfterContentInit() {\n this.templates.forEach((item) => {\n switch(item.getType()) {\n case 'item':\n this.itemTemplate = item.template;\n break;\n\n case 'loadingItem':\n this.loadingItemTemplate = item.template;\n break;\n\n case 'header':\n this.headerTemplate = item.template;\n break;\n\n case 'footer':\n this.footerTemplate = item.template;\n break;\n \n default:\n this.itemTemplate = item.template;\n break;\n }\n });\n }\n\n onScrollIndexChange(index: number) {\n if (this.lazy) {\n if (this.virtualScrollTimeout) {\n clearTimeout(this.virtualScrollTimeout);\n }\n\n this.virtualScrollTimeout = setTimeout(() => {\n let page = Math.floor(index / this.rows);\n let virtualScrollOffset = page === 0 ? 0 : (page - 1) * this.rows;\n let virtualScrollChunkSize = page === 0 ? this.rows * 2 : this.rows * 3;\n \n if (page !== this.virtualPage) {\n this.virtualPage = page;\n this.onLazyLoad.emit({first: virtualScrollOffset, rows: virtualScrollChunkSize});\n }\n }, this.delay);\n }\n }\n\n getBlockableElement(): HTMLElement {\n return this.el.nativeElement.children[0];\n }\n\n //@deprecated\n scrollTo(index: number, mode?: ScrollBehavior): void {\n this.scrollToIndex(index, mode);\n }\n\n scrollToIndex(index: number, mode?: ScrollBehavior): void {\n if (this.viewport) {\n this.viewport.scrollToIndex(index, mode);\n }\n }\n}\n\n@NgModule({\n imports: [CommonModule,ScrollingModule],\n exports: [VirtualScroller,SharedModule,ScrollingModule],\n declarations: [VirtualScroller]\n})\nexport class VirtualScrollerModule { }\n\n"]}