{"version":3,"file":"primeng-virtualscroller.umd.js","sources":["../../src/app/components/virtualscroller/virtualscroller.ts","../../src/app/components/virtualscroller/primeng-virtualscroller.ts"],"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        <div [ngClass]=\"'p-virtualscroller p-component'\" [ngStyle]=\"style\" [class]=\"styleClass\">\n            <div class=\"p-virtualscroller-header\" *ngIf=\"header || headerTemplate\">\n                <ng-content select=\"p-header\"></ng-content>\n                <ng-container *ngTemplateOutlet=\"headerTemplate\"></ng-container>\n            </div>\n            <div #content class=\"p-virtualscroller-content\">\n                <div class=\"p-virtualscroller-list\">\n                    <cdk-virtual-scroll-viewport #viewport [ngStyle]=\"{'height': scrollHeight}\" tabindex=\"0\" [itemSize]=\"itemSize\" [minBufferPx]=\"minBufferPx\" [maxBufferPx]=\"maxBufferPx\" (scrolledIndexChange)=\"onScrollIndexChange($event)\">\n                        <ng-container *cdkVirtualFor=\"let item of value; trackBy: trackBy; let i = index; let c = count; let f = first; let l = last; let e = even; let o = odd;\">\n                            <div [ngStyle]=\"{'height': itemSize + 'px'}\" class=\"p-virtualscroller-item\">\n                                <ng-container *ngTemplateOutlet=\"item ? itemTemplate : loadingItemTemplate; context: {$implicit: item, index: i, count: c, first: f, last: l, even: e, odd: o}\"></ng-container>\n                            </div>\n                        </ng-container>\n                    </cdk-virtual-scroll-viewport>\n                </div>\n            </div>\n            <div class=\"p-virtualscroller-footer\" *ngIf=\"footer || footerTemplate\">\n                <ng-content select=\"p-footer\"></ng-content>\n                <ng-container *ngTemplateOutlet=\"footerTemplate\"></ng-container>\n            </div>\n        </div>\n    `,\n    changeDetection: ChangeDetectionStrategy.Default,\n    encapsulation: ViewEncapsulation.None,\n    styleUrls: ['./virtualscroller.css']\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<any>;\n\n    @ViewChild(CdkVirtualScrollViewport) viewport: CdkVirtualScrollViewport;\n\n    @Output() onLazyLoad: EventEmitter<any> = new EventEmitter();\n\n    itemTemplate: TemplateRef<any>;\n\n    headerTemplate: TemplateRef<any>;\n\n    footerTemplate: TemplateRef<any>;\n\n    loadingItemTemplate: TemplateRef<any>;\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","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './public_api';\n"],"names":["EventEmitter","Header","Footer","PrimeTemplate","CdkVirtualScrollViewport","Component","ChangeDetectionStrategy","ViewEncapsulation","Input","ContentChild","ContentChildren","ViewChild","Output","CommonModule","ScrollingModule","SharedModule","NgModule"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;QAyFI,yBAAmB,EAAc;YAAd,OAAE,GAAF,EAAE,CAAY;YAlCxB,UAAK,GAAW,GAAG,CAAC;YAEpB,YAAO,GAAa,UAAC,K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