ng-virtual-list 19.11.1 → 19.11.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.
@@ -275,6 +275,7 @@ const PART_ITEM_FOCUSED = ' item-focused';
275
275
  const MIN_PIXELS_FOR_PREVENT_SNAPPING = 10;
276
276
  const MAX_VELOCITY_FOR_SCROLL_QUALITY_OPTIMIZATION_LVL1 = 74;
277
277
  const MAX_VELOCITY_FOR_SCROLL_QUALITY_OPTIMIZATION_LVL2 = 500;
278
+ const MAX_NUMBERS_OF_SKIPS_FOR_QUALITY_OPTIMIZATION_LVL1 = 4;
278
279
  const RANGE_DISPLAY_ITEMS_END_OFFSET = 20;
279
280
  const PREPARE_ITERATIONS = 1;
280
281
  const PREPARATION_REUPDATE_LENGTH = 0;
@@ -1078,6 +1079,7 @@ class TrackBox extends CacheMap {
1078
1079
  _resetBufferSizeTimer;
1079
1080
  _isReseted = true;
1080
1081
  _prerenderedCache = null;
1082
+ _newItems = [];
1081
1083
  lifeCircle() {
1082
1084
  this.fireChangeIfNeed();
1083
1085
  this.fireTick();
@@ -1104,6 +1106,7 @@ class TrackBox extends CacheMap {
1104
1106
  updateCache(previousCollection, currentCollection, itemSize) {
1105
1107
  const trackBy = this._trackingPropertyName;
1106
1108
  let crudDetected = false;
1109
+ this._newItems = [];
1107
1110
  if (!currentCollection || currentCollection.length === 0) {
1108
1111
  if (previousCollection) {
1109
1112
  // deleted
@@ -1171,6 +1174,7 @@ class TrackBox extends CacheMap {
1171
1174
  const item = currentCollection[i], id = item[trackBy];
1172
1175
  if (item && !deletedMap.hasOwnProperty(id) && !updatedMap.hasOwnProperty(id) &&
1173
1176
  !notChangedMap.hasOwnProperty(id)) {
1177
+ this._newItems.push(id);
1174
1178
  // added
1175
1179
  crudDetected = true;
1176
1180
  this._map.set(id, { width: itemSize, height: itemSize, method: ItemDisplayMethods.CREATE });
@@ -1338,7 +1342,7 @@ class TrackBox extends CacheMap {
1338
1342
  }
1339
1343
  }
1340
1344
  }
1341
- let y = this._scrollStartOffset, stickyCollectionItem = undefined, stickyComponentSize = 0;
1345
+ let y = this._scrollStartOffset, stickyComponentSize = 0;
1342
1346
  for (let i = 0, l = collection.length; i < l; i++) {
1343
1347
  const ii = i + 1, collectionItem = collection[i], id = collectionItem[trackBy];
1344
1348
  let componentSize = 0, componentSizeDelta = 0, itemDisplayMethod = ItemDisplayMethods.NOT_CHANGED;
@@ -1346,7 +1350,7 @@ class TrackBox extends CacheMap {
1346
1350
  const cache = map.get(id);
1347
1351
  componentSize = cache[sizeProperty] > 0 ? cache[sizeProperty] : typicalItemSize;
1348
1352
  itemDisplayMethod = cache?.method ?? ItemDisplayMethods.UPDATE;
1349
- const isItemNew = cache?.[IS_NEW] ?? (this._isLazy && isStart && !this._isReseted);
1353
+ const isItemNew = this._newItems.indexOf(id) > -1 || (this._isLazy && isStart && !this._isReseted);
1350
1354
  isNew = isItemNew;
1351
1355
  if (isNew) {
1352
1356
  isUpdating = true;
@@ -1384,7 +1388,6 @@ class TrackBox extends CacheMap {
1384
1388
  if (itemById === undefined) {
1385
1389
  if (id !== fromItemId && id === stickyItemId && itemConfigMap?.[id]?.sticky === 1) {
1386
1390
  stickyComponentSize = componentSize;
1387
- stickyCollectionItem = collectionItem;
1388
1391
  y -= stickyComponentSize;
1389
1392
  }
1390
1393
  if (id === fromItemId) {
@@ -1528,9 +1531,6 @@ class TrackBox extends CacheMap {
1528
1531
  refreshCache(cache) {
1529
1532
  this._prerenderedCache = cache;
1530
1533
  }
1531
- clearDeltaDirection() {
1532
- this.clearScrollDirectionCache();
1533
- }
1534
1534
  clearDelta(clearDirectionDetector = false) {
1535
1535
  this._delta = this._deltaOfNewItems = 0;
1536
1536
  if (clearDirectionDetector) {
@@ -1853,6 +1853,9 @@ class TrackBox extends CacheMap {
1853
1853
  this._prerenderedCache = null;
1854
1854
  }
1855
1855
  }
1856
+ resetCacheChunkInfo() {
1857
+ this._newItems = [];
1858
+ }
1856
1859
  cacheClean() {
1857
1860
  this._map.clear();
1858
1861
  this._snapshot.clear();
@@ -5735,8 +5738,8 @@ class NgVirtualListComponent {
5735
5738
  $fireUpdate.pipe(takeUntilDestroyed(), tap(userAction => {
5736
5739
  hasUserAction = userAction;
5737
5740
  })).subscribe();
5738
- let renderStabilizerPrevScrollStateVersion = EMPTY_SCROLL_STATE_VERSION, renderStabilizerUpdateIterations = 0;
5739
5741
  const $update = this.$update, renderStabilizer = (options) => {
5742
+ let renderStabilizerPrevScrollStateVersion = EMPTY_SCROLL_STATE_VERSION, renderStabilizerUpdateIterations = 0;
5740
5743
  const prepareIterations = options?.prepareIterations ?? PREPARE_ITERATIONS, prepareReupdateLength = options?.prepareReupdateLength ?? PREPARATION_REUPDATE_LENGTH;
5741
5744
  return of(null).pipe(takeUntilDestroyed(this._destroyRef), switchMap$1(() => {
5742
5745
  renderStabilizerPrevScrollStateVersion = EMPTY_SCROLL_STATE_VERSION;
@@ -5769,6 +5772,9 @@ class NgVirtualListComponent {
5769
5772
  }), $updateItemsRenderStabilizer = renderStabilizer({
5770
5773
  prepareIterations: PREPARE_ITERATIONS_FOR_UPDATE_ITEMS,
5771
5774
  prepareReupdateLength: PREPARATION_REUPDATE_LENGTH_FOR_UPDATE_ITEMS,
5775
+ }), $chunkLoadingRenderStabilizer = renderStabilizer({
5776
+ prepareIterations: PREPARE_ITERATIONS_FOR_UPDATE_ITEMS,
5777
+ prepareReupdateLength: PREPARATION_REUPDATE_LENGTH_FOR_UPDATE_ITEMS,
5772
5778
  }), $collapseItemsRenderStabilizer = renderStabilizer({
5773
5779
  prepareIterations: PREPARE_ITERATIONS_FOR_COLLAPSE_ITEMS,
5774
5780
  prepareReupdateLength: PREPARATION_REUPDATE_LENGTH_FOR_COLLAPSE_ITEMS,
@@ -6042,11 +6048,26 @@ class NgVirtualListComponent {
6042
6048
  this._$fireUpdate.next(true);
6043
6049
  }));
6044
6050
  })).subscribe();
6051
+ let isChunkLoading = false;
6045
6052
  const $loading = toObservable(this.loading);
6046
6053
  $loading.pipe(takeUntilDestroyed(), distinctUntilChanged(), skip(1), filter$1(v => !v), switchMap$1(() => {
6047
- return $actualItems.pipe(takeUntilDestroyed(this._destroyRef), debounceTime(100), take(1), tap(() => {
6048
- this._scrollerComponent()?.refreshScrollbar();
6049
- }));
6054
+ isChunkLoading = true;
6055
+ const scrollbar = this._scrollerComponent();
6056
+ if (!!scrollbar) {
6057
+ scrollbar.stopScrollbar();
6058
+ scrollbar.refreshScrollbar();
6059
+ }
6060
+ return $actualItems.pipe(takeUntilDestroyed(this._destroyRef), take(1), tap(() => {
6061
+ this._$fireUpdateNextFrame.next(true);
6062
+ }), switchMap$1(() => $chunkLoadingRenderStabilizer.pipe(takeUntilDestroyed(this._destroyRef), take(1), tap(() => {
6063
+ isChunkLoading = false;
6064
+ this._trackBox.resetCacheChunkInfo();
6065
+ const scrollbar = this._scrollerComponent();
6066
+ if (!!scrollbar) {
6067
+ scrollbar.stopScrollbar();
6068
+ scrollbar.refreshScrollbar();
6069
+ }
6070
+ }))));
6050
6071
  })).subscribe();
6051
6072
  $loading.pipe(takeUntilDestroyed(), skip(1), distinctUntilChanged(), tap(v => {
6052
6073
  if (v) {
@@ -6064,7 +6085,7 @@ class NgVirtualListComponent {
6064
6085
  const scroller = this._scrollerComponent();
6065
6086
  let totalSize = 0;
6066
6087
  if (scroller) {
6067
- const collapsable = collapsedIds.length > 0, cachable = this.cachable, cached = this._cached, waitingCache = cachable && !cached, emitUpdate = !this._readyForShow || waitingCache || collapsable;
6088
+ const collapsable = collapsedIds.length > 0, cachable = this.cachable, cached = this._cached, waitingCache = cachable && !cached, emitUpdate = !this._readyForShow || waitingCache || collapsable || isChunkLoading;
6068
6089
  if (this._readyForShow || (cachable && cached)) {
6069
6090
  const currentScrollSize = (isVertical ? scroller.scrollTop ?? 0 : scroller.scrollLeft ?? 0), fireUpdate = emitUpdate || reupdate || (!optimization && !userAction) || this._$scrollingTo.getValue();
6070
6091
  let actualScrollSize = !this._readyForShow && snapScrollToEnd ? (isVertical ? scroller.scrollHeight ?? 0 : scroller.scrollWidth ?? 0) :
@@ -6138,23 +6159,22 @@ class NgVirtualListComponent {
6138
6159
  this._trackBox.isScrollEnd;
6139
6160
  return;
6140
6161
  }
6141
- if (scrollPositionAfterUpdate >= 0 && scrollPositionAfterUpdate < roundedMaxPositionAfterUpdate) {
6142
- if (scrollSize !== roundedMaxPositionAfterUpdate || currentScrollSize !== scrollPositionAfterUpdate) {
6143
- this._trackBox.clearDelta();
6144
- if (this._readyForShow) {
6145
- this.emitScrollEvent(true, false, userAction);
6146
- }
6147
- const params = {
6148
- [isVertical ? TOP_PROP_NAME : LEFT_PROP_NAME]: scrollPositionAfterUpdate, blending: true, userAction,
6149
- fireUpdate, behavior: BEHAVIOR_INSTANT, duration: this.animationParams().scrollToItem,
6150
- };
6151
- scroller.scrollTo(params);
6152
- if (emitUpdate) {
6153
- this._$update.next(this.getScrollStateVersion(totalSize, this._isVertical ? scroller.scrollTop : scroller.scrollLeft, cacheVersion));
6154
- }
6162
+ if ((scrollPositionAfterUpdate >= 0 && scrollPositionAfterUpdate < roundedMaxPositionAfterUpdate) ||
6163
+ (scrollSize !== roundedMaxPositionAfterUpdate || currentScrollSize !== scrollPositionAfterUpdate)) {
6164
+ this._trackBox.clearDelta();
6165
+ if (this._readyForShow) {
6166
+ this.emitScrollEvent(true, false, userAction);
6167
+ }
6168
+ const params = {
6169
+ [isVertical ? TOP_PROP_NAME : LEFT_PROP_NAME]: scrollPositionAfterUpdate, blending: true, userAction,
6170
+ fireUpdate, behavior: BEHAVIOR_INSTANT, duration: this.animationParams().scrollToItem,
6171
+ };
6172
+ scroller.scrollTo(params);
6173
+ if (emitUpdate) {
6174
+ this._$update.next(this.getScrollStateVersion(totalSize, this._isVertical ? scroller.scrollTop : scroller.scrollLeft, cacheVersion));
6155
6175
  }
6156
- return;
6157
6176
  }
6177
+ return;
6158
6178
  }
6159
6179
  if (emitUpdate) {
6160
6180
  this._$update.next(this.getScrollStateVersion(totalSize, this._isVertical ? scroller.scrollTop : scroller.scrollLeft, cacheVersion));
@@ -6162,7 +6182,7 @@ class NgVirtualListComponent {
6162
6182
  }
6163
6183
  };
6164
6184
  let prevItems = [];
6165
- const debouncedUpdate = debounce(update, 0);
6185
+ const debouncedUpdate = debounce(update, 0, MAX_NUMBERS_OF_SKIPS_FOR_QUALITY_OPTIMIZATION_LVL1);
6166
6186
  $viewInit.pipe(takeUntilDestroyed(), filter$1(v => !!v), switchMap$1(() => {
6167
6187
  return combineLatest([$snapScrollToStart, $snapScrollToEnd, $bounds, $listBounds, $scrollEndOffset, $actualItems, $itemConfigMap, $scrollSize, $itemSize,
6168
6188
  $collapsedItemIds, $bufferSize, $maxBufferSize, $snap, $isVertical, $dynamicSize, $enabledBufferOptimization, $cacheVersion, this.$fireUpdate,