ng-virtual-list 14.3.0 → 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.
- package/esm2020/lib/components/ng-virtual-list-item.component.mjs +1 -1
- package/esm2020/lib/ng-virtual-list.component.mjs +15 -4
- package/esm2020/lib/utils/trackBox.mjs +10 -5
- package/fesm2015/ng-virtual-list.mjs +23 -7
- package/fesm2015/ng-virtual-list.mjs.map +1 -1
- package/fesm2020/ng-virtual-list.mjs +23 -7
- package/fesm2020/ng-virtual-list.mjs.map +1 -1
- package/lib/components/ng-virtual-list-item.component.d.ts +5 -5
- package/lib/utils/trackBox.d.ts +1 -0
- package/package.json +1 -1
|
@@ -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);
|
|
@@ -1108,7 +1109,7 @@ class TrackBox extends CacheMap {
|
|
|
1108
1109
|
}
|
|
1109
1110
|
}
|
|
1110
1111
|
if (deletedItemsMap.hasOwnProperty(i)) {
|
|
1111
|
-
const bounds = deletedItemsMap[i], size = bounds[sizeProperty] ?? typicalItemSize;
|
|
1112
|
+
const bounds = deletedItemsMap[i], size = bounds?.[sizeProperty] ?? typicalItemSize;
|
|
1112
1113
|
if (y < scrollSize - size) {
|
|
1113
1114
|
leftSizeOfDeletedItems += size;
|
|
1114
1115
|
}
|
|
@@ -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
|
}
|
|
@@ -1199,6 +1201,9 @@ class TrackBox extends CacheMap {
|
|
|
1199
1201
|
let pos = startPosition, renderItems = renderItemsLength, stickyItem, nextSticky, stickyItemIndex = -1, stickyItemSize = 0, endStickyItem, nextEndSticky, endStickyItemIndex = -1, endStickyItemSize = 0;
|
|
1200
1202
|
if (snap) {
|
|
1201
1203
|
for (let i = Math.min(itemsFromStartToScrollEnd > 0 ? itemsFromStartToScrollEnd : 0, totalLength - 1); i >= 0; i--) {
|
|
1204
|
+
if (!items[i]) {
|
|
1205
|
+
continue;
|
|
1206
|
+
}
|
|
1202
1207
|
const id = items[i].id, sticky = stickyMap[id], size = dynamicSize ? this.get(id)?.[sizeProperty] || typicalItemSize : typicalItemSize;
|
|
1203
1208
|
if (sticky === 1) {
|
|
1204
1209
|
const measures = {
|
|
@@ -1938,6 +1943,10 @@ class NgVirtualListComponent extends DisposableComponent {
|
|
|
1938
1943
|
itemsOffset: this.itemsOffset, scrollSize: (isVertical ? container.nativeElement.scrollTop : container.nativeElement.scrollLeft) + delta,
|
|
1939
1944
|
snap: this.snap, fromItemId: id, enabledBufferOptimization: this.enabledBufferOptimization,
|
|
1940
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
|
+
}
|
|
1941
1950
|
this._trackBox.clearDelta();
|
|
1942
1951
|
if (container) {
|
|
1943
1952
|
const { displayItems, totalSize } = this._trackBox.updateCollection(items, stickyMap, {
|
|
@@ -1949,6 +1958,10 @@ class NgVirtualListComponent extends DisposableComponent {
|
|
|
1949
1958
|
this.createDisplayComponentsIfNeed(displayItems);
|
|
1950
1959
|
this.tracking();
|
|
1951
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
|
+
}
|
|
1952
1965
|
const notChanged = actualScrollSize === _scrollSize;
|
|
1953
1966
|
if (!notChanged || iteration < MAX_SCROLL_TO_ITERATIONS) {
|
|
1954
1967
|
this.clearScrollToRepeatExecutionTimeout();
|
|
@@ -1965,9 +1978,12 @@ class NgVirtualListComponent extends DisposableComponent {
|
|
|
1965
1978
|
this._$scrollSize.next(scrollSize);
|
|
1966
1979
|
}
|
|
1967
1980
|
else {
|
|
1968
|
-
const index = items.findIndex(item => item.id === id)
|
|
1969
|
-
|
|
1970
|
-
|
|
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
|
+
}
|
|
1971
1987
|
}
|
|
1972
1988
|
}
|
|
1973
1989
|
}
|