ng-virtual-list 14.4.0 → 14.4.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -219,20 +219,6 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.3.0", ngImpor
219
219
  }, changeDetection: ChangeDetectionStrategy.OnPush, template: "<ng-container *ngIf=\"data\">\r\n <li #listItem part=\"item\" class=\"ngvl-item__container\" [ngClass]=\"{'snapped': data.config.snapped,\r\n 'snapped-out': data.config.snappedOut}\">\r\n <ng-container *ngIf=\"itemRenderer\">\r\n <ng-container [ngTemplateOutlet]=\"itemRenderer\"\r\n [ngTemplateOutletContext]=\"{data: data.data || {}, config: data.config}\"></ng-container>\r\n </ng-container>\r\n </li>\r\n</ng-container>", styles: [":host{display:block;position:absolute;left:0;top:0;box-sizing:border-box;overflow:hidden}.ngvl-item__container{margin:0;padding:0;overflow:hidden;background-color:#fff;width:inherit;height:inherit}\n"] }]
220
220
  }], ctorParameters: function () { return [{ type: i0.ChangeDetectorRef }, { type: i0.ElementRef }]; } });
221
221
 
222
- const HORIZONTAL_ALIASES = [Directions.HORIZONTAL, 'horizontal'], VERTICAL_ALIASES = [Directions.VERTICAL, 'vertical'];
223
- /**
224
- * Determines the axis membership of a virtual list
225
- * @link https://github.com/DjonnyX/ng-virtual-list/blob/14.x/projects/ng-virtual-list/src/lib/utils/isDirection.ts
226
- * @author Evgenii Grebennikov
227
- * @email djonnyx@gmail.com
228
- */
229
- const isDirection = (src, expected) => {
230
- if (HORIZONTAL_ALIASES.includes(expected)) {
231
- return HORIZONTAL_ALIASES.includes(src);
232
- }
233
- return VERTICAL_ALIASES.includes(src);
234
- };
235
-
236
222
  /**
237
223
  * Simple debounce function.
238
224
  * @link https://github.com/DjonnyX/ng-virtual-list/blob/14.x/projects/ng-virtual-list/src/lib/utils/debounce.ts
@@ -280,138 +266,45 @@ const toggleClassName = (el, className, removeClassName) => {
280
266
  };
281
267
 
282
268
  /**
283
- * Tracks display items by property
284
- * @link https://github.com/DjonnyX/ng-virtual-list/blob/14.x/projects/ng-virtual-list/src/lib/utils/tracker.ts
269
+ * Scroll event.
270
+ * @link https://github.com/DjonnyX/ng-virtual-list/blob/14.x/projects/ng-virtual-list/src/lib/utils/scrollEvent.ts
285
271
  * @author Evgenii Grebennikov
286
272
  * @email djonnyx@gmail.com
287
273
  */
288
- class Tracker {
289
- constructor(trackingPropertyName) {
290
- /**
291
- * display objects dictionary of indexes by id
292
- */
293
- this._displayObjectIndexMapById = {};
294
- /**
295
- * Dictionary displayItems propertyNameId by items propertyNameId
296
- */
297
- this._trackMap = {};
298
- this._trackingPropertyName = trackingPropertyName;
299
- }
300
- set displayObjectIndexMapById(v) {
301
- if (this._displayObjectIndexMapById === v) {
302
- return;
303
- }
304
- this._displayObjectIndexMapById = v;
305
- }
306
- get displayObjectIndexMapById() {
307
- return this._displayObjectIndexMapById;
308
- }
309
- get trackMap() {
310
- return this._trackMap;
311
- }
312
- set trackingPropertyName(v) {
313
- this._trackingPropertyName = v;
314
- }
315
- /**
316
- * tracking by propName
317
- */
318
- track(items, components, snapedComponent, direction) {
319
- var _a;
320
- if (!items) {
321
- return;
322
- }
323
- const idPropName = this._trackingPropertyName, untrackedItems = [...components], isDown = direction === 0 || direction === 1;
324
- let isRegularSnapped = false;
325
- for (let i = isDown ? 0 : items.length - 1, l = isDown ? items.length : 0; isDown ? i < l : i >= l; isDown ? i++ : i--) {
326
- const item = items[i], itemTrackingProperty = item[idPropName];
327
- if (this._trackMap) {
328
- if (this._trackMap.hasOwnProperty(itemTrackingProperty)) {
329
- const diId = this._trackMap[itemTrackingProperty], compIndex = this._displayObjectIndexMapById[diId], comp = components[compIndex];
330
- const compId = (_a = comp === null || comp === void 0 ? void 0 : comp.instance) === null || _a === void 0 ? void 0 : _a.id;
331
- if (comp !== undefined && compId === diId) {
332
- const indexByUntrackedItems = untrackedItems.findIndex(v => {
333
- return v.instance.id === compId;
334
- });
335
- if (indexByUntrackedItems > -1) {
336
- if (snapedComponent) {
337
- if (item['config']['snapped'] || item['config']['snappedOut']) {
338
- isRegularSnapped = true;
339
- snapedComponent.instance.item = item;
340
- snapedComponent.instance.show();
341
- }
342
- }
343
- comp.instance.item = item;
344
- if (snapedComponent) {
345
- if (item['config']['snapped'] || item['config']['snappedOut']) {
346
- comp.instance.hide();
347
- }
348
- else {
349
- comp.instance.show();
350
- }
351
- }
352
- else {
353
- comp.instance.show();
354
- }
355
- untrackedItems.splice(indexByUntrackedItems, 1);
356
- continue;
357
- }
358
- }
359
- delete this._trackMap[itemTrackingProperty];
360
- }
361
- }
362
- if (untrackedItems.length > 0) {
363
- const comp = untrackedItems.shift(), item = items[i];
364
- if (comp) {
365
- if (snapedComponent) {
366
- if (item['config']['snapped'] || item['config']['snappedOut']) {
367
- isRegularSnapped = true;
368
- snapedComponent.instance.item = item;
369
- snapedComponent.instance.show();
370
- }
371
- }
372
- comp.instance.item = item;
373
- if (snapedComponent) {
374
- if (item['config']['snapped'] || item['config']['snappedOut']) {
375
- comp.instance.hide();
376
- }
377
- else {
378
- comp.instance.show();
379
- }
380
- }
381
- else {
382
- comp.instance.show();
383
- }
384
- if (this._trackMap) {
385
- this._trackMap[itemTrackingProperty] = comp.instance.id;
386
- }
387
- }
388
- }
389
- }
390
- if (untrackedItems.length) {
391
- for (let i = 0, l = untrackedItems.length; i < l; i++) {
392
- const comp = untrackedItems[i];
393
- comp.instance.hide();
394
- }
395
- }
396
- if (!isRegularSnapped) {
397
- if (snapedComponent) {
398
- snapedComponent.instance.item = null;
399
- snapedComponent.instance.hide();
400
- }
401
- }
402
- }
403
- untrackComponentByIdProperty(component) {
404
- if (!component) {
405
- return;
406
- }
407
- const propertyIdName = this._trackingPropertyName;
408
- if (this._trackMap && component[propertyIdName] !== undefined) {
409
- delete this._trackMap[propertyIdName];
410
- }
411
- }
412
- dispose() {
413
- this._trackMap = null;
274
+ class ScrollEvent {
275
+ constructor(params) {
276
+ this._direction = 1;
277
+ this._scrollSize = 0;
278
+ this._scrollWeight = 0;
279
+ this._isVertical = true;
280
+ this._listSize = 0;
281
+ this._size = 0;
282
+ this._isStart = true;
283
+ this._isEnd = false;
284
+ this._delta = 0;
285
+ this._scrollDelta = 0;
286
+ const { direction, isVertical, container, list, delta, scrollDelta } = params;
287
+ this._direction = direction;
288
+ this._isVertical = isVertical;
289
+ this._scrollSize = isVertical ? container.scrollTop : container.scrollLeft;
290
+ this._scrollWeight = isVertical ? container.scrollHeight : container.scrollWidth;
291
+ this._listSize = isVertical ? list.offsetHeight : list.offsetWidth;
292
+ this._size = isVertical ? container.offsetHeight : container.offsetWidth;
293
+ this._isEnd = (this._scrollSize + this._size) === this._scrollWeight;
294
+ this._delta = delta;
295
+ this._scrollDelta = scrollDelta;
296
+ this._isStart = this._scrollSize === 0;
414
297
  }
298
+ get direction() { return this._direction; }
299
+ get scrollSize() { return this._scrollSize; }
300
+ get scrollWeight() { return this._scrollWeight; }
301
+ get isVertical() { return this._isVertical; }
302
+ get listSize() { return this._listSize; }
303
+ get size() { return this._size; }
304
+ get isStart() { return this._isStart; }
305
+ get isEnd() { return this._isEnd; }
306
+ get delta() { return this._delta; }
307
+ get scrollDelta() { return this._scrollDelta; }
415
308
  }
416
309
 
417
310
  /**
@@ -685,6 +578,141 @@ class CacheMap extends EventEmitter {
685
578
  }
686
579
  }
687
580
 
581
+ /**
582
+ * Tracks display items by property
583
+ * @link https://github.com/DjonnyX/ng-virtual-list/blob/14.x/projects/ng-virtual-list/src/lib/utils/tracker.ts
584
+ * @author Evgenii Grebennikov
585
+ * @email djonnyx@gmail.com
586
+ */
587
+ class Tracker {
588
+ constructor(trackingPropertyName) {
589
+ /**
590
+ * display objects dictionary of indexes by id
591
+ */
592
+ this._displayObjectIndexMapById = {};
593
+ /**
594
+ * Dictionary displayItems propertyNameId by items propertyNameId
595
+ */
596
+ this._trackMap = {};
597
+ this._trackingPropertyName = trackingPropertyName;
598
+ }
599
+ set displayObjectIndexMapById(v) {
600
+ if (this._displayObjectIndexMapById === v) {
601
+ return;
602
+ }
603
+ this._displayObjectIndexMapById = v;
604
+ }
605
+ get displayObjectIndexMapById() {
606
+ return this._displayObjectIndexMapById;
607
+ }
608
+ get trackMap() {
609
+ return this._trackMap;
610
+ }
611
+ set trackingPropertyName(v) {
612
+ this._trackingPropertyName = v;
613
+ }
614
+ /**
615
+ * tracking by propName
616
+ */
617
+ track(items, components, snapedComponent, direction) {
618
+ var _a;
619
+ if (!items) {
620
+ return;
621
+ }
622
+ const idPropName = this._trackingPropertyName, untrackedItems = [...components], isDown = direction === 0 || direction === 1;
623
+ let isRegularSnapped = false;
624
+ for (let i = isDown ? 0 : items.length - 1, l = isDown ? items.length : 0; isDown ? i < l : i >= l; isDown ? i++ : i--) {
625
+ const item = items[i], itemTrackingProperty = item[idPropName];
626
+ if (this._trackMap) {
627
+ if (this._trackMap.hasOwnProperty(itemTrackingProperty)) {
628
+ const diId = this._trackMap[itemTrackingProperty], compIndex = this._displayObjectIndexMapById[diId], comp = components[compIndex];
629
+ const compId = (_a = comp === null || comp === void 0 ? void 0 : comp.instance) === null || _a === void 0 ? void 0 : _a.id;
630
+ if (comp !== undefined && compId === diId) {
631
+ const indexByUntrackedItems = untrackedItems.findIndex(v => {
632
+ return v.instance.id === compId;
633
+ });
634
+ if (indexByUntrackedItems > -1) {
635
+ if (snapedComponent) {
636
+ if (item['config']['snapped'] || item['config']['snappedOut']) {
637
+ isRegularSnapped = true;
638
+ snapedComponent.instance.item = item;
639
+ snapedComponent.instance.show();
640
+ }
641
+ }
642
+ comp.instance.item = item;
643
+ if (snapedComponent) {
644
+ if (item['config']['snapped'] || item['config']['snappedOut']) {
645
+ comp.instance.hide();
646
+ }
647
+ else {
648
+ comp.instance.show();
649
+ }
650
+ }
651
+ else {
652
+ comp.instance.show();
653
+ }
654
+ untrackedItems.splice(indexByUntrackedItems, 1);
655
+ continue;
656
+ }
657
+ }
658
+ delete this._trackMap[itemTrackingProperty];
659
+ }
660
+ }
661
+ if (untrackedItems.length > 0) {
662
+ const comp = untrackedItems.shift(), item = items[i];
663
+ if (comp) {
664
+ if (snapedComponent) {
665
+ if (item['config']['snapped'] || item['config']['snappedOut']) {
666
+ isRegularSnapped = true;
667
+ snapedComponent.instance.item = item;
668
+ snapedComponent.instance.show();
669
+ }
670
+ }
671
+ comp.instance.item = item;
672
+ if (snapedComponent) {
673
+ if (item['config']['snapped'] || item['config']['snappedOut']) {
674
+ comp.instance.hide();
675
+ }
676
+ else {
677
+ comp.instance.show();
678
+ }
679
+ }
680
+ else {
681
+ comp.instance.show();
682
+ }
683
+ if (this._trackMap) {
684
+ this._trackMap[itemTrackingProperty] = comp.instance.id;
685
+ }
686
+ }
687
+ }
688
+ }
689
+ if (untrackedItems.length) {
690
+ for (let i = 0, l = untrackedItems.length; i < l; i++) {
691
+ const comp = untrackedItems[i];
692
+ comp.instance.hide();
693
+ }
694
+ }
695
+ if (!isRegularSnapped) {
696
+ if (snapedComponent) {
697
+ snapedComponent.instance.item = null;
698
+ snapedComponent.instance.hide();
699
+ }
700
+ }
701
+ }
702
+ untrackComponentByIdProperty(component) {
703
+ if (!component) {
704
+ return;
705
+ }
706
+ const propertyIdName = this._trackingPropertyName;
707
+ if (this._trackMap && component[propertyIdName] !== undefined) {
708
+ delete this._trackMap[propertyIdName];
709
+ }
710
+ }
711
+ dispose() {
712
+ this._trackMap = null;
713
+ }
714
+ }
715
+
688
716
  const DEFAULT_EXTRA = {
689
717
  extremumThreshold: 2,
690
718
  bufferSize: 10,
@@ -731,6 +759,7 @@ class TrackBox extends CacheMap {
731
759
  constructor(trackingPropertyName) {
732
760
  super();
733
761
  this._isSnappingMethodAdvanced = false;
762
+ this._trackingPropertyName = TRACK_BY_PROPERTY_NAME;
734
763
  this._deletedItemsMap = {};
735
764
  this._crudDetected = false;
736
765
  this._previousTotalSize = 0;
@@ -744,7 +773,8 @@ class TrackBox extends CacheMap {
744
773
  this._maxBufferSize = this._defaultBufferSize;
745
774
  this._resetBufferSizeTimeout = DEFAULT_RESET_BUFFER_SIZE_TIMEOUT;
746
775
  this._previousScrollSize = 0;
747
- this._tracker = new Tracker(trackingPropertyName);
776
+ this._trackingPropertyName = trackingPropertyName;
777
+ this.initialize();
748
778
  }
749
779
  set items(v) {
750
780
  if (this._items === v) {
@@ -774,7 +804,10 @@ class TrackBox extends CacheMap {
774
804
  * Set the trackBy property
775
805
  */
776
806
  set trackingPropertyName(v) {
777
- this._tracker.trackingPropertyName = v;
807
+ this._trackingPropertyName = this._tracker.trackingPropertyName = v;
808
+ }
809
+ initialize() {
810
+ this._tracker = new Tracker(this._trackingPropertyName);
778
811
  }
779
812
  set(id, bounds) {
780
813
  if (this._map.has(id)) {
@@ -1291,6 +1324,9 @@ class TrackBox extends CacheMap {
1291
1324
  if (snap) {
1292
1325
  const startIndex = itemsFromStartToScrollEnd + itemsOnDisplayLength - 1;
1293
1326
  for (let i = Math.min(startIndex, totalLength > 0 ? totalLength - 1 : 0), l = totalLength; i < l; i++) {
1327
+ if (!items[i]) {
1328
+ continue;
1329
+ }
1294
1330
  const id = items[i].id, sticky = stickyMap[id], size = dynamicSize
1295
1331
  ? ((_b = this.get(id)) === null || _b === void 0 ? void 0 : _b[sizeProperty]) || typicalItemSize
1296
1332
  : typicalItemSize;
@@ -1325,6 +1361,9 @@ class TrackBox extends CacheMap {
1325
1361
  if (i >= totalLength) {
1326
1362
  break;
1327
1363
  }
1364
+ if (!items[i]) {
1365
+ continue;
1366
+ }
1328
1367
  const id = items[i].id, size = dynamicSize ? ((_c = this.get(id)) === null || _c === void 0 ? void 0 : _c[sizeProperty]) || typicalItemSize : typicalItemSize;
1329
1368
  if (id !== (stickyItem === null || stickyItem === void 0 ? void 0 : stickyItem.id) && id !== (endStickyItem === null || endStickyItem === void 0 ? void 0 : endStickyItem.id)) {
1330
1369
  const snapped = snap && (stickyMap[id] === 1 && pos <= scrollSize || stickyMap[id] === 2 && pos >= scrollSize + boundsSize - size), measures = {
@@ -1443,48 +1482,6 @@ class TrackBox extends CacheMap {
1443
1482
  }
1444
1483
  }
1445
1484
 
1446
- /**
1447
- * Scroll event.
1448
- * @link https://github.com/DjonnyX/ng-virtual-list/blob/14.x/projects/ng-virtual-list/src/lib/utils/scrollEvent.ts
1449
- * @author Evgenii Grebennikov
1450
- * @email djonnyx@gmail.com
1451
- */
1452
- class ScrollEvent {
1453
- constructor(params) {
1454
- this._direction = 1;
1455
- this._scrollSize = 0;
1456
- this._scrollWeight = 0;
1457
- this._isVertical = true;
1458
- this._listSize = 0;
1459
- this._size = 0;
1460
- this._isStart = true;
1461
- this._isEnd = false;
1462
- this._delta = 0;
1463
- this._scrollDelta = 0;
1464
- const { direction, isVertical, container, list, delta, scrollDelta } = params;
1465
- this._direction = direction;
1466
- this._isVertical = isVertical;
1467
- this._scrollSize = isVertical ? container.scrollTop : container.scrollLeft;
1468
- this._scrollWeight = isVertical ? container.scrollHeight : container.scrollWidth;
1469
- this._listSize = isVertical ? list.offsetHeight : list.offsetWidth;
1470
- this._size = isVertical ? container.offsetHeight : container.offsetWidth;
1471
- this._isEnd = (this._scrollSize + this._size) === this._scrollWeight;
1472
- this._delta = delta;
1473
- this._scrollDelta = scrollDelta;
1474
- this._isStart = this._scrollSize === 0;
1475
- }
1476
- get direction() { return this._direction; }
1477
- get scrollSize() { return this._scrollSize; }
1478
- get scrollWeight() { return this._scrollWeight; }
1479
- get isVertical() { return this._isVertical; }
1480
- get listSize() { return this._listSize; }
1481
- get size() { return this._size; }
1482
- get isStart() { return this._isStart; }
1483
- get isEnd() { return this._isEnd; }
1484
- get delta() { return this._delta; }
1485
- get scrollDelta() { return this._scrollDelta; }
1486
- }
1487
-
1488
1485
  /**
1489
1486
  * Base disposable component
1490
1487
  * @link https://github.com/DjonnyX/ng-virtual-list/blob/14.x/projects/ng-virtual-list/src/lib/utils/disposableComponent.ts
@@ -1522,6 +1519,20 @@ const isSnappingMethodDefault = (method) => {
1522
1519
  const IS_FIREFOX = navigator.userAgent.toLowerCase().includes('firefox');
1523
1520
  const FIREFOX_SCROLLBAR_OVERLAP_SIZE = 12;
1524
1521
 
1522
+ const HORIZONTAL_ALIASES = [Directions.HORIZONTAL, 'horizontal'], VERTICAL_ALIASES = [Directions.VERTICAL, 'vertical'];
1523
+ /**
1524
+ * Determines the axis membership of a virtual list
1525
+ * @link https://github.com/DjonnyX/ng-virtual-list/blob/14.x/projects/ng-virtual-list/src/lib/utils/isDirection.ts
1526
+ * @author Evgenii Grebennikov
1527
+ * @email djonnyx@gmail.com
1528
+ */
1529
+ const isDirection = (src, expected) => {
1530
+ if (HORIZONTAL_ALIASES.includes(expected)) {
1531
+ return HORIZONTAL_ALIASES.includes(src);
1532
+ }
1533
+ return VERTICAL_ALIASES.includes(src);
1534
+ };
1535
+
1525
1536
  /**
1526
1537
  * Virtual list component.
1527
1538
  * Maximum performance for extremely large lists.
@@ -1747,7 +1758,10 @@ class NgVirtualListComponent extends DisposableComponent {
1747
1758
  }
1748
1759
  return of(displayItems);
1749
1760
  })).subscribe();
1750
- this.setupRenderer();
1761
+ const $itemRenderer = this.$itemRenderer;
1762
+ $itemRenderer.pipe(takeUntil(this._$unsubscribe), distinctUntilChanged(), filter(v => !!v), tap(v => {
1763
+ this._$renderer.next(v);
1764
+ })).subscribe();
1751
1765
  }
1752
1766
  /**
1753
1767
  * Readonly. Returns the unique identifier of the component.
@@ -1914,12 +1928,6 @@ class NgVirtualListComponent extends DisposableComponent {
1914
1928
  get snappingMethod() { return this._$snappingMethod.getValue(); }
1915
1929
  get isSnappingMethodAdvanced() { return this._isSnappingMethodAdvanced; }
1916
1930
  get $cacheVersion() { return this._$cacheVersion.asObservable(); }
1917
- setupRenderer() {
1918
- const $itemRenderer = this.$itemRenderer;
1919
- $itemRenderer.pipe(takeUntil(this._$unsubscribe), distinctUntilChanged(), filter(v => !!v), tap(v => {
1920
- this._$renderer.next(v);
1921
- })).subscribe();
1922
- }
1923
1931
  /** @internal */
1924
1932
  ngOnInit() {
1925
1933
  this.onInit();
@@ -2212,5 +2220,5 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.3.0", ngImpor
2212
2220
  * Generated bundle index. Do not edit.
2213
2221
  */
2214
2222
 
2215
- export { BaseVirtualListItemComponent, Directions, NgVirtualListComponent, NgVirtualListItemComponent, NgVirtualListModule, SnappingMethods };
2223
+ export { Directions, NgVirtualListComponent, NgVirtualListItemComponent, NgVirtualListModule, SnappingMethods };
2216
2224
  //# sourceMappingURL=ng-virtual-list.mjs.map