1 | (function (global, factory) {
|
2 | typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@angular/core'), require('@angular/common'), require('primeng/api'), require('@angular/cdk/scrolling')) :
|
3 | typeof define === 'function' && define.amd ? define('primeng/virtualscroller', ['exports', '@angular/core', '@angular/common', 'primeng/api', '@angular/cdk/scrolling'], factory) :
|
4 | (global = global || self, factory((global.primeng = global.primeng || {}, global.primeng.virtualscroller = {}), global.ng.core, global.ng.common, global.primeng.api, global.ng.cdk.scrolling));
|
5 | }(this, (function (exports, core, common, api, scrolling) { 'use strict';
|
6 |
|
7 | var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
8 | var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
9 | if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
10 | else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
11 | return c > 3 && r && Object.defineProperty(target, key, r), r;
|
12 | };
|
13 | var __read = (this && this.__read) || function (o, n) {
|
14 | var m = typeof Symbol === "function" && o[Symbol.iterator];
|
15 | if (!m) return o;
|
16 | var i = m.call(o), r, ar = [], e;
|
17 | try {
|
18 | while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
19 | }
|
20 | catch (error) { e = { error: error }; }
|
21 | finally {
|
22 | try {
|
23 | if (r && !r.done && (m = i["return"])) m.call(i);
|
24 | }
|
25 | finally { if (e) throw e.error; }
|
26 | }
|
27 | return ar;
|
28 | };
|
29 | var __spread = (this && this.__spread) || function () {
|
30 | for (var ar = [], i = 0; i < arguments.length; i++) ar = ar.concat(__read(arguments[i]));
|
31 | return ar;
|
32 | };
|
33 | var VirtualScroller = (function () {
|
34 | function VirtualScroller(el) {
|
35 | this.el = el;
|
36 | this.cache = true;
|
37 | this.first = 0;
|
38 | this.trackBy = function (index, item) { return item; };
|
39 | this.onLazyLoad = new core.EventEmitter();
|
40 | this._totalRecords = 0;
|
41 | this.lazyValue = [];
|
42 | this.page = 0;
|
43 | }
|
44 | Object.defineProperty(VirtualScroller.prototype, "totalRecords", {
|
45 | get: function () {
|
46 | return this._totalRecords;
|
47 | },
|
48 | set: function (val) {
|
49 | this._totalRecords = val;
|
50 | this.lazyValue = Array.from({ length: this._totalRecords });
|
51 | this.onLazyLoad.emit(this.createLazyLoadMetadata());
|
52 | this.first = 0;
|
53 | this.scrollTo(0);
|
54 | },
|
55 | enumerable: true,
|
56 | configurable: true
|
57 | });
|
58 | Object.defineProperty(VirtualScroller.prototype, "value", {
|
59 | get: function () {
|
60 | return this.lazy ? this.lazyValue : this._value;
|
61 | },
|
62 | set: function (val) {
|
63 | if (this.lazy) {
|
64 | if (val) {
|
65 | var arr = this.cache ? __spread(this.lazyValue) : Array.from({ length: this._totalRecords });
|
66 | for (var i = this.first, j = 0; i < (this.first + this.rows); i++, j++) {
|
67 | arr[i] = val[j];
|
68 | }
|
69 | this.lazyValue = arr;
|
70 | }
|
71 | }
|
72 | else {
|
73 | this._value = val;
|
74 | }
|
75 | },
|
76 | enumerable: true,
|
77 | configurable: true
|
78 | });
|
79 | VirtualScroller.prototype.ngAfterContentInit = function () {
|
80 | var _this = this;
|
81 | this.templates.forEach(function (item) {
|
82 | switch (item.getType()) {
|
83 | case 'item':
|
84 | _this.itemTemplate = item.template;
|
85 | break;
|
86 | case 'loadingItem':
|
87 | _this.loadingItemTemplate = item.template;
|
88 | break;
|
89 | default:
|
90 | _this.itemTemplate = item.template;
|
91 | break;
|
92 | }
|
93 | });
|
94 | };
|
95 | VirtualScroller.prototype.onScrollIndexChange = function (index) {
|
96 | var p = Math.floor(index / this.rows);
|
97 | if (p !== this.page) {
|
98 | this.page = p;
|
99 | this.first = this.page * this.rows;
|
100 | this.onLazyLoad.emit(this.createLazyLoadMetadata());
|
101 | }
|
102 | };
|
103 | VirtualScroller.prototype.createLazyLoadMetadata = function () {
|
104 | return {
|
105 | first: this.first,
|
106 | rows: this.rows
|
107 | };
|
108 | };
|
109 | VirtualScroller.prototype.getBlockableElement = function () {
|
110 | return this.el.nativeElement.children[0];
|
111 | };
|
112 | VirtualScroller.prototype.scrollTo = function (index) {
|
113 | if (this.viewPortViewChild && this.viewPortViewChild['elementRef'] && this.viewPortViewChild['elementRef'].nativeElement) {
|
114 | this.viewPortViewChild['elementRef'].nativeElement.scrollTop = index * this.itemSize;
|
115 | }
|
116 | };
|
117 | VirtualScroller.ctorParameters = function () { return [
|
118 | { type: core.ElementRef }
|
119 | ]; };
|
120 | __decorate([
|
121 | core.Input()
|
122 | ], VirtualScroller.prototype, "itemSize", void 0);
|
123 | __decorate([
|
124 | core.Input()
|
125 | ], VirtualScroller.prototype, "style", void 0);
|
126 | __decorate([
|
127 | core.Input()
|
128 | ], VirtualScroller.prototype, "styleClass", void 0);
|
129 | __decorate([
|
130 | core.Input()
|
131 | ], VirtualScroller.prototype, "scrollHeight", void 0);
|
132 | __decorate([
|
133 | core.Input()
|
134 | ], VirtualScroller.prototype, "lazy", void 0);
|
135 | __decorate([
|
136 | core.Input()
|
137 | ], VirtualScroller.prototype, "cache", void 0);
|
138 | __decorate([
|
139 | core.Input()
|
140 | ], VirtualScroller.prototype, "rows", void 0);
|
141 | __decorate([
|
142 | core.Input()
|
143 | ], VirtualScroller.prototype, "first", void 0);
|
144 | __decorate([
|
145 | core.Input()
|
146 | ], VirtualScroller.prototype, "trackBy", void 0);
|
147 | __decorate([
|
148 | core.ContentChild(api.Header)
|
149 | ], VirtualScroller.prototype, "header", void 0);
|
150 | __decorate([
|
151 | core.ContentChild(api.Footer)
|
152 | ], VirtualScroller.prototype, "footer", void 0);
|
153 | __decorate([
|
154 | core.ContentChildren(api.PrimeTemplate)
|
155 | ], VirtualScroller.prototype, "templates", void 0);
|
156 | __decorate([
|
157 | core.ViewChild('viewport')
|
158 | ], VirtualScroller.prototype, "viewPortViewChild", void 0);
|
159 | __decorate([
|
160 | core.Output()
|
161 | ], VirtualScroller.prototype, "onLazyLoad", void 0);
|
162 | __decorate([
|
163 | core.Input()
|
164 | ], VirtualScroller.prototype, "totalRecords", null);
|
165 | __decorate([
|
166 | core.Input()
|
167 | ], VirtualScroller.prototype, "value", null);
|
168 | VirtualScroller = __decorate([
|
169 | core.Component({
|
170 | selector: 'p-virtualScroller',
|
171 | template: "\n <div [ngClass]=\"'ui-virtualscroller ui-widget'\" [ngStyle]=\"style\" [class]=\"styleClass\">\n <div class=\"ui-virtualscroller-header ui-widget-header ui-corner-top\" *ngIf=\"header\">\n <ng-content select=\"p-header\"></ng-content>\n </div>\n <div #content class=\"ui-virtualscroller-content ui-widget-content\">\n <ul class=\"ui-virtualscroller-list\">\n <cdk-virtual-scroll-viewport #viewport [ngStyle]=\"{'height': scrollHeight}\" [itemSize]=\"itemSize\" (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 <li [ngStyle]=\"{'height': itemSize + 'px'}\">\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 </li>\n </ng-container>\n </cdk-virtual-scroll-viewport>\n </ul>\n </div>\n <div class=\"ui-virtualscroller-footer ui-widget-header ui-corner-bottom\" *ngIf=\"footer\">\n <ng-content select=\"p-footer\"></ng-content>\n </div>\n </div>\n ",
|
172 | changeDetection: core.ChangeDetectionStrategy.Default
|
173 | })
|
174 | ], VirtualScroller);
|
175 | return VirtualScroller;
|
176 | }());
|
177 | var VirtualScrollerModule = (function () {
|
178 | function VirtualScrollerModule() {
|
179 | }
|
180 | VirtualScrollerModule = __decorate([
|
181 | core.NgModule({
|
182 | imports: [common.CommonModule, scrolling.ScrollingModule],
|
183 | exports: [VirtualScroller, api.SharedModule, scrolling.ScrollingModule],
|
184 | declarations: [VirtualScroller]
|
185 | })
|
186 | ], VirtualScrollerModule);
|
187 | return VirtualScrollerModule;
|
188 | }());
|
189 |
|
190 | exports.VirtualScroller = VirtualScroller;
|
191 | exports.VirtualScrollerModule = VirtualScrollerModule;
|
192 |
|
193 | Object.defineProperty(exports, '__esModule', { value: true });
|
194 |
|
195 | })));
|
196 |
|