ng-virtual-list 18.2.0 → 18.3.1

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.
@@ -82,13 +82,22 @@ const SCROLL_END = 'scrollend';
82
82
  const CLASS_LIST_VERTICAL = 'vertical';
83
83
  const CLASS_LIST_HORIZONTAL = 'horizontal';
84
84
 
85
+ /**
86
+ * Virtual List Item Interface
87
+ * @link https://github.com/DjonnyX/ng-virtual-list/blob/18.x/projects/ng-virtual-list/src/lib/models/base-virtual-list-item-component.ts
88
+ * @author Evgenii Grebennikov
89
+ * @email djonnyx@gmail.com
90
+ */
91
+ class BaseVirtualListItemComponent {
92
+ }
93
+
85
94
  /**
86
95
  * Virtual list item component
87
96
  * @link https://github.com/DjonnyX/ng-virtual-list/blob/18.x/projects/ng-virtual-list/src/lib/components/ng-virtual-list-item.component.ts
88
97
  * @author Evgenii Grebennikov
89
98
  * @email djonnyx@gmail.com
90
99
  */
91
- class NgVirtualListItemComponent {
100
+ class NgVirtualListItemComponent extends BaseVirtualListItemComponent {
92
101
  static __nextId = 0;
93
102
  _id;
94
103
  get id() {
@@ -102,7 +111,7 @@ class NgVirtualListItemComponent {
102
111
  if (this._data === v) {
103
112
  return;
104
113
  }
105
- const data = this._data = v;
114
+ this._data = v;
106
115
  this.update();
107
116
  this.data.set(v);
108
117
  this._cdr.detectChanges();
@@ -131,6 +140,7 @@ class NgVirtualListItemComponent {
131
140
  return this._elementRef.nativeElement;
132
141
  }
133
142
  constructor() {
143
+ super();
134
144
  this._id = NgVirtualListItemComponent.__nextId = NgVirtualListItemComponent.__nextId === Number.MAX_SAFE_INTEGER
135
145
  ? 0 : NgVirtualListItemComponent.__nextId + 1;
136
146
  }
@@ -199,7 +209,7 @@ class NgVirtualListItemComponent {
199
209
  styles.zIndex = HIDDEN_ZINDEX;
200
210
  }
201
211
  static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "18.2.13", ngImport: i0, type: NgVirtualListItemComponent, deps: [], target: i0.ɵɵFactoryTarget.Component });
202
- static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "18.2.13", type: NgVirtualListItemComponent, selector: "ng-virtual-list-item", host: { classAttribute: "ngvl__item" }, ngImport: i0, template: "@let item = data();\r\n@let renderer = itemRenderer();\r\n\r\n@if (item) {\r\n <li #listItem part=\"item\" class=\"ngvl-item__container\" [ngClass]=\"{'snapped': item.config.snapped,\r\n 'snapped-out': item.config.snappedOut}\">\r\n @if (renderer) {\r\n <ng-container [ngTemplateOutlet]=\"renderer\"\r\n [ngTemplateOutletContext]=\"{data: item.data || {}, config: item.config}\" />\r\n }\r\n </li>\r\n}", styles: [":host{display:block;position:absolute;left:0;top:0;box-sizing:border-box;overflow:hidden;will-change:scroll-position}.ngvl-item__container{margin:0;padding:0;overflow:hidden;background-color:#fff;width:inherit;height:inherit}\n"], dependencies: [{ kind: "directive", type: i1.NgClass, selector: "[ngClass]", inputs: ["class", "ngClass"] }, { kind: "directive", type: i1.NgTemplateOutlet, selector: "[ngTemplateOutlet]", inputs: ["ngTemplateOutletContext", "ngTemplateOutlet", "ngTemplateOutletInjector"] }], changeDetection: i0.ChangeDetectionStrategy.OnPush });
212
+ static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "18.2.13", type: NgVirtualListItemComponent, selector: "ng-virtual-list-item", host: { classAttribute: "ngvl__item" }, usesInheritance: true, ngImport: i0, template: "@let item = data();\r\n@let renderer = itemRenderer();\r\n\r\n@if (item) {\r\n <li #listItem part=\"item\" class=\"ngvl-item__container\" [ngClass]=\"{'snapped': item.config.snapped,\r\n 'snapped-out': item.config.snappedOut}\">\r\n @if (renderer) {\r\n <ng-container [ngTemplateOutlet]=\"renderer\"\r\n [ngTemplateOutletContext]=\"{data: item.data || {}, config: item.config}\" />\r\n }\r\n </li>\r\n}", styles: [":host{display:block;position:absolute;left:0;top:0;box-sizing:border-box;overflow:hidden;will-change:scroll-position}.ngvl-item__container{margin:0;padding:0;overflow:hidden;background-color:#fff;width:inherit;height:inherit}\n"], dependencies: [{ kind: "directive", type: i1.NgClass, selector: "[ngClass]", inputs: ["class", "ngClass"] }, { kind: "directive", type: i1.NgTemplateOutlet, selector: "[ngTemplateOutlet]", inputs: ["ngTemplateOutletContext", "ngTemplateOutlet", "ngTemplateOutletInjector"] }], changeDetection: i0.ChangeDetectionStrategy.OnPush });
203
213
  }
204
214
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.2.13", ngImport: i0, type: NgVirtualListItemComponent, decorators: [{
205
215
  type: Component,
@@ -1106,7 +1116,7 @@ class TrackBox extends CacheMap {
1106
1116
  }
1107
1117
  }
1108
1118
  if (deletedItemsMap.hasOwnProperty(i)) {
1109
- const bounds = deletedItemsMap[i], size = bounds[sizeProperty] ?? typicalItemSize;
1119
+ const bounds = deletedItemsMap[i], size = bounds?.[sizeProperty] ?? typicalItemSize;
1110
1120
  if (y < scrollSize - size) {
1111
1121
  leftSizeOfDeletedItems += size;
1112
1122
  }
@@ -1197,6 +1207,9 @@ class TrackBox extends CacheMap {
1197
1207
  let pos = startPosition, renderItems = renderItemsLength, stickyItem, nextSticky, stickyItemIndex = -1, stickyItemSize = 0, endStickyItem, nextEndSticky, endStickyItemIndex = -1, endStickyItemSize = 0;
1198
1208
  if (snap) {
1199
1209
  for (let i = Math.min(itemsFromStartToScrollEnd > 0 ? itemsFromStartToScrollEnd : 0, totalLength - 1); i >= 0; i--) {
1210
+ if (!items[i]) {
1211
+ continue;
1212
+ }
1200
1213
  const id = items[i].id, sticky = stickyMap[id], size = dynamicSize ? this.get(id)?.[sizeProperty] || typicalItemSize : typicalItemSize;
1201
1214
  if (sticky === 1) {
1202
1215
  const measures = {
@@ -1489,6 +1502,7 @@ class NgVirtualListComponent {
1489
1502
  * Rendering element template.
1490
1503
  */
1491
1504
  itemRenderer = input.required();
1505
+ _itemRenderer = signal(undefined);
1492
1506
  /**
1493
1507
  * Dictionary zIndex by id of the list element. If the value is not set or equal to 0,
1494
1508
  * then a simple element is displayed, if the value is greater than 0, then the sticky position mode is enabled for the element.
@@ -1597,10 +1611,18 @@ class NgVirtualListComponent {
1597
1611
  * The name of the property by which tracking is performed
1598
1612
  */
1599
1613
  trackBy = input(TRACK_BY_PROPERTY_NAME);
1614
+ /**
1615
+ * Base class of the element component
1616
+ */
1617
+ _itemComponentClass = NgVirtualListItemComponent;
1618
+ /**
1619
+ * Base class trackBox
1620
+ */
1621
+ _trackBoxClass = TrackBox;
1600
1622
  /**
1601
1623
  * Dictionary of element sizes by their id
1602
1624
  */
1603
- _trackBox = new TrackBox(this.trackBy());
1625
+ _trackBox = new this._trackBoxClass(this.trackBy());
1604
1626
  _onTrackBoxChangeHandler = (v) => {
1605
1627
  this._cacheVersion.set(v);
1606
1628
  };
@@ -1657,12 +1679,19 @@ class NgVirtualListComponent {
1657
1679
  }
1658
1680
  return of(displayItems);
1659
1681
  })).subscribe();
1660
- combineLatest([this.$initialized, toObservable(this.itemRenderer)]).pipe(takeUntilDestroyed(), distinctUntilChanged(), filter(([initialized]) => !!initialized), tap(([, itemRenderer]) => {
1661
- this.resetRenderers(itemRenderer);
1662
- }));
1682
+ this.setupRenderer();
1683
+ }
1684
+ setupRenderer() {
1685
+ const $itemRenderer = toObservable(this.itemRenderer);
1686
+ $itemRenderer.pipe(takeUntilDestroyed(), distinctUntilChanged(), filter(v => !!v), tap(v => {
1687
+ this._itemRenderer.set(v);
1688
+ })).subscribe();
1663
1689
  }
1664
1690
  /** @internal */
1665
1691
  ngOnInit() {
1692
+ this.onInit();
1693
+ }
1694
+ onInit() {
1666
1695
  this._initialized.set(true);
1667
1696
  }
1668
1697
  listenCacheChangesIfNeed(value) {
@@ -1692,7 +1721,7 @@ class NgVirtualListComponent {
1692
1721
  }
1693
1722
  if (this._isSnappingMethodAdvanced && this.snap()) {
1694
1723
  if (!this._snapedDisplayComponent && this._snapContainerRef) {
1695
- const comp = this._snapContainerRef.createComponent(NgVirtualListItemComponent);
1724
+ const comp = this._snapContainerRef.createComponent(this._itemComponentClass);
1696
1725
  comp.instance.regular = true;
1697
1726
  this._snapedDisplayComponent = comp;
1698
1727
  this._trackBox.snapedDisplayComponent = this._snapedDisplayComponent;
@@ -1705,7 +1734,7 @@ class NgVirtualListComponent {
1705
1734
  const maxLength = displayItems.length, components = this._displayComponents;
1706
1735
  while (components.length < maxLength) {
1707
1736
  if (_listContainerRef) {
1708
- const comp = _listContainerRef.createComponent(NgVirtualListItemComponent);
1737
+ const comp = _listContainerRef.createComponent(this._itemComponentClass);
1709
1738
  components.push(comp);
1710
1739
  this._componentsResizeObserver.observe(comp.instance.element);
1711
1740
  }
@@ -1721,13 +1750,13 @@ class NgVirtualListComponent {
1721
1750
  const item = components[i];
1722
1751
  if (item) {
1723
1752
  const id = item.instance.id;
1724
- item.instance.renderer = itemRenderer || this.itemRenderer();
1753
+ item.instance.renderer = itemRenderer || this._itemRenderer();
1725
1754
  doMap[id] = i;
1726
1755
  }
1727
1756
  }
1728
1757
  if (this._isSnappingMethodAdvanced && this.snap() && this._snapedDisplayComponent && this._snapContainerRef) {
1729
1758
  const comp = this._snapedDisplayComponent;
1730
- comp.instance.renderer = itemRenderer || this.itemRenderer();
1759
+ comp.instance.renderer = itemRenderer || this._itemRenderer();
1731
1760
  }
1732
1761
  this._trackBox.setDisplayObjectIndexMapById(doMap);
1733
1762
  }
@@ -1845,6 +1874,9 @@ class NgVirtualListComponent {
1845
1874
  };
1846
1875
  /** @internal */
1847
1876
  ngAfterViewInit() {
1877
+ this.afterViewInit();
1878
+ }
1879
+ afterViewInit() {
1848
1880
  const containerEl = this._container();
1849
1881
  if (containerEl) {
1850
1882
  // for direction calculation
@@ -1858,6 +1890,9 @@ class NgVirtualListComponent {
1858
1890
  }
1859
1891
  /** @internal */
1860
1892
  ngOnDestroy() {
1893
+ this.dispose();
1894
+ }
1895
+ dispose() {
1861
1896
  this.clearScrollToRepeatExecutionTimeout();
1862
1897
  if (this._trackBox) {
1863
1898
  this._trackBox.dispose();
@@ -1924,5 +1959,5 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.2.13", ngImpo
1924
1959
  * Generated bundle index. Do not edit.
1925
1960
  */
1926
1961
 
1927
- export { Directions, NgVirtualListComponent, NgVirtualListModule, SnappingMethods };
1962
+ export { BaseVirtualListItemComponent, Directions, NgVirtualListComponent, NgVirtualListItemComponent, NgVirtualListModule, SnappingMethods };
1928
1963
  //# sourceMappingURL=ng-virtual-list.mjs.map