ng-virtual-list 14.3.1 → 14.3.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.
@@ -846,14 +846,14 @@ class TrackBox extends CacheMap {
846
846
  */
847
847
  getItemPosition(id, stickyMap, options) {
848
848
  const opt = { fromItemId: id, stickyMap, ...options };
849
- const { scrollSize } = this.recalculateMetrics({
849
+ const { scrollSize, isFromItemIdFound } = this.recalculateMetrics({
850
850
  ...opt,
851
851
  dynamicSize: this._crudDetected || opt.dynamicSize,
852
852
  previousTotalSize: this._previousTotalSize,
853
853
  crudDetected: this._crudDetected,
854
854
  deletedItemsMap: this._deletedItemsMap,
855
855
  });
856
- return scrollSize;
856
+ return isFromItemIdFound ? scrollSize : -1;
857
857
  }
858
858
  /**
859
859
  * Updates the collection of display objects
@@ -962,7 +962,7 @@ class TrackBox extends CacheMap {
962
962
  else {
963
963
  leftItemsOffset = rightItemsOffset = itemsOffset;
964
964
  }
965
- let itemsFromStartToScrollEnd = -1, itemsFromDisplayEndToOffsetEnd = 0, itemsFromStartToDisplayEnd = -1, leftItemLength = 0, rightItemLength = 0, leftItemsWeight = 0, rightItemsWeight = 0, leftHiddenItemsWeight = 0, totalItemsToDisplayEndWeight = 0, leftSizeOfAddedItems = 0, leftSizeOfUpdatedItems = 0, leftSizeOfDeletedItems = 0, itemById = undefined, itemByIdPos = 0, targetDisplayItemIndex = -1, isTargetInOverscroll = false, actualScrollSize = itemByIdPos, totalSize = 0, startIndex;
965
+ let itemsFromStartToScrollEnd = -1, itemsFromDisplayEndToOffsetEnd = 0, itemsFromStartToDisplayEnd = -1, leftItemLength = 0, rightItemLength = 0, leftItemsWeight = 0, rightItemsWeight = 0, leftHiddenItemsWeight = 0, totalItemsToDisplayEndWeight = 0, leftSizeOfAddedItems = 0, leftSizeOfUpdatedItems = 0, leftSizeOfDeletedItems = 0, itemById = undefined, itemByIdPos = 0, targetDisplayItemIndex = -1, isTargetInOverscroll = false, actualScrollSize = itemByIdPos, totalSize = 0, startIndex, isFromItemIdFound = false;
966
966
  // If the list is dynamic or there are new elements in the collection, then it switches to the long algorithm.
967
967
  if (dynamicSize) {
968
968
  let y = 0, stickyCollectionItem = undefined, stickyComponentSize = 0;
@@ -1002,6 +1002,7 @@ class TrackBox extends CacheMap {
1002
1002
  stickyCollectionItem = collectionItem;
1003
1003
  }
1004
1004
  if (id === fromItemId) {
1005
+ isFromItemIdFound = true;
1005
1006
  targetDisplayItemIndex = i;
1006
1007
  if (stickyCollectionItem && stickyMap) {
1007
1008
  const { num } = this.getElementNumToEnd(i, collection, map, typicalItemSize, size, isVertical);
@@ -1177,6 +1178,7 @@ class TrackBox extends CacheMap {
1177
1178
  totalLength,
1178
1179
  totalSize,
1179
1180
  typicalItemSize,
1181
+ isFromItemIdFound,
1180
1182
  };
1181
1183
  return metrics;
1182
1184
  }
@@ -1941,6 +1943,10 @@ class NgVirtualListComponent extends DisposableComponent {
1941
1943
  itemsOffset: this.itemsOffset, scrollSize: (isVertical ? container.nativeElement.scrollTop : container.nativeElement.scrollLeft) + delta,
1942
1944
  snap: this.snap, fromItemId: id, enabledBufferOptimization: this.enabledBufferOptimization,
1943
1945
  }, scrollSize = this._trackBox.getItemPosition(id, stickyMap, opts), params = { [isVertical ? TOP_PROP_NAME : LEFT_PROP_NAME]: scrollSize, behavior };
1946
+ if (scrollSize === -1) {
1947
+ container.nativeElement.addEventListener(SCROLL, this._onScrollHandler);
1948
+ return;
1949
+ }
1944
1950
  this._trackBox.clearDelta();
1945
1951
  if (container) {
1946
1952
  const { displayItems, totalSize } = this._trackBox.updateCollection(items, stickyMap, {
@@ -1952,6 +1958,10 @@ class NgVirtualListComponent extends DisposableComponent {
1952
1958
  this.createDisplayComponentsIfNeed(displayItems);
1953
1959
  this.tracking();
1954
1960
  const _scrollSize = this._trackBox.getItemPosition(id, stickyMap, { ...opts, scrollSize: actualScrollSize, fromItemId: id });
1961
+ if (_scrollSize === -1) {
1962
+ container.nativeElement.addEventListener(SCROLL, this._onScrollHandler);
1963
+ return;
1964
+ }
1955
1965
  const notChanged = actualScrollSize === _scrollSize;
1956
1966
  if (!notChanged || iteration < MAX_SCROLL_TO_ITERATIONS) {
1957
1967
  this.clearScrollToRepeatExecutionTimeout();
@@ -1968,9 +1978,12 @@ class NgVirtualListComponent extends DisposableComponent {
1968
1978
  this._$scrollSize.next(scrollSize);
1969
1979
  }
1970
1980
  else {
1971
- const index = items.findIndex(item => item.id === id), scrollSize = index * this.itemSize;
1972
- const params = { [this._isVertical ? TOP_PROP_NAME : LEFT_PROP_NAME]: scrollSize, behavior };
1973
- container.nativeElement.scrollTo(params);
1981
+ const index = items.findIndex(item => item.id === id);
1982
+ if (index > -1) {
1983
+ const scrollSize = index * this.itemSize;
1984
+ const params = { [this._isVertical ? TOP_PROP_NAME : LEFT_PROP_NAME]: scrollSize, behavior };
1985
+ container.nativeElement.scrollTo(params);
1986
+ }
1974
1987
  }
1975
1988
  }
1976
1989
  }