@legendapp/list 3.0.0-beta.48 → 3.0.0-beta.49

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/react.mjs CHANGED
@@ -2062,7 +2062,7 @@ function getId(state, index) {
2062
2062
  }
2063
2063
 
2064
2064
  // src/core/addTotalSize.ts
2065
- function addTotalSize(ctx, key, add) {
2065
+ function addTotalSize(ctx, key, add, notifyTotalSize = true) {
2066
2066
  const state = ctx.state;
2067
2067
  const prevTotalSize = state.totalSize;
2068
2068
  let totalSize = state.totalSize;
@@ -2079,25 +2079,29 @@ function addTotalSize(ctx, key, add) {
2079
2079
  {
2080
2080
  state.pendingTotalSize = void 0;
2081
2081
  state.totalSize = totalSize;
2082
- set$(ctx, "totalSize", totalSize);
2082
+ if (notifyTotalSize) {
2083
+ set$(ctx, "totalSize", totalSize);
2084
+ }
2083
2085
  }
2086
+ } else if (notifyTotalSize && ctx.values.get("totalSize") !== totalSize) {
2087
+ set$(ctx, "totalSize", totalSize);
2084
2088
  }
2085
2089
  }
2086
2090
 
2087
2091
  // src/core/setSize.ts
2088
- function setSize(ctx, itemKey, size) {
2092
+ function setSize(ctx, itemKey, size, notifyTotalSize = true) {
2089
2093
  const state = ctx.state;
2090
2094
  const { sizes } = state;
2091
2095
  const previousSize = sizes.get(itemKey);
2092
2096
  const diff = previousSize !== void 0 ? size - previousSize : size;
2093
2097
  if (diff !== 0) {
2094
- addTotalSize(ctx, itemKey, diff);
2098
+ addTotalSize(ctx, itemKey, diff, notifyTotalSize);
2095
2099
  }
2096
2100
  sizes.set(itemKey, size);
2097
2101
  }
2098
2102
 
2099
2103
  // src/utils/getItemSize.ts
2100
- function getItemSize(ctx, key, index, data, useAverageSize, preferCachedSize) {
2104
+ function getItemSize(ctx, key, index, data, useAverageSize, preferCachedSize, notifyTotalSize) {
2101
2105
  var _a3, _b, _c;
2102
2106
  const state = ctx.state;
2103
2107
  const {
@@ -2143,7 +2147,7 @@ function getItemSize(ctx, key, index, data, useAverageSize, preferCachedSize) {
2143
2147
  if (size === void 0) {
2144
2148
  size = getEstimatedItemSize ? getEstimatedItemSize(data, index, itemType) : estimatedItemSize;
2145
2149
  }
2146
- setSize(ctx, key, size);
2150
+ setSize(ctx, key, size, notifyTotalSize);
2147
2151
  return size;
2148
2152
  }
2149
2153
  function getItemSizeAtIndex(ctx, index) {
@@ -2582,10 +2586,10 @@ function getMountedBufferedIndices(state) {
2582
2586
  function getMountedNoBufferIndices(state) {
2583
2587
  return getMountedIndicesInRange(state, state.startNoBuffer, state.endNoBuffer);
2584
2588
  }
2585
- function checkAllSizesKnown(state, indices = getMountedBufferedIndices(state)) {
2589
+ function checkAllSizesKnown(state, indices) {
2586
2590
  return indices.length > 0 && indices.every((index) => {
2587
2591
  const key = getId(state, index);
2588
- return state.sizesKnown.has(key);
2592
+ return key !== void 0 && state.sizesKnown.has(key);
2589
2593
  });
2590
2594
  }
2591
2595
 
@@ -3895,6 +3899,7 @@ function updateItemPositions(ctx, dataChanged, { startIndex, scrollBottomBuffere
3895
3899
  const maxVisibleArea = scrollBottomBuffered + 1e3;
3896
3900
  const useAverageSize = !getEstimatedItemSize;
3897
3901
  const preferCachedSize = !doMVCP || dataChanged || state.scrollAdjustHandler.getAdjust() !== 0 || ((_b = peek$(ctx, "scrollAdjustPending")) != null ? _b : 0) !== 0;
3902
+ const notifyTotalSizeWhileCachingSizes = false;
3898
3903
  let currentRowTop = 0;
3899
3904
  let column = 1;
3900
3905
  let maxSizeInRow = 0;
@@ -3922,7 +3927,15 @@ function updateItemPositions(ctx, dataChanged, { startIndex, scrollBottomBuffere
3922
3927
  const prevIndex = startIndex - 1;
3923
3928
  const prevId = getId(state, prevIndex);
3924
3929
  const prevPosition = (_c = positions[prevIndex]) != null ? _c : 0;
3925
- const prevSize = (_d = sizesKnown.get(prevId)) != null ? _d : getItemSize(ctx, prevId, prevIndex, data[prevIndex], useAverageSize, preferCachedSize);
3930
+ const prevSize = (_d = sizesKnown.get(prevId)) != null ? _d : getItemSize(
3931
+ ctx,
3932
+ prevId,
3933
+ prevIndex,
3934
+ data[prevIndex],
3935
+ useAverageSize,
3936
+ preferCachedSize,
3937
+ notifyTotalSizeWhileCachingSizes
3938
+ );
3926
3939
  currentRowTop = prevPosition + prevSize;
3927
3940
  }
3928
3941
  }
@@ -3955,7 +3968,7 @@ function updateItemPositions(ctx, dataChanged, { startIndex, scrollBottomBuffere
3955
3968
  maxSizeInRow = 0;
3956
3969
  }
3957
3970
  const knownSize = sizesKnown.get(id);
3958
- const size = knownSize !== void 0 ? knownSize : getItemSize(ctx, id, i, data[i], useAverageSize, preferCachedSize);
3971
+ const size = knownSize !== void 0 ? knownSize : getItemSize(ctx, id, i, data[i], useAverageSize, preferCachedSize, notifyTotalSizeWhileCachingSizes);
3959
3972
  if (IS_DEV && needsIndexByKey) {
3960
3973
  if (indexByKeyForChecking.has(id)) {
3961
3974
  console.error(
@@ -4430,7 +4443,7 @@ function handleStickyRecycling(ctx, stickyArray, scroll, drawDistance, currentSt
4430
4443
  function calculateItemsInView(ctx, params = {}) {
4431
4444
  const state = ctx.state;
4432
4445
  batchedUpdates(() => {
4433
- var _a3, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p;
4446
+ var _a3, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r;
4434
4447
  const {
4435
4448
  columns,
4436
4449
  columnSpans,
@@ -4719,6 +4732,7 @@ function calculateItemsInView(ctx, params = {}) {
4719
4732
  state.containerItemTypes.set(containerIndex, requiredItemTypes[idx]);
4720
4733
  }
4721
4734
  containerItemKeys.set(id, containerIndex);
4735
+ (_p = state.userScrollAnchorResetKeys) == null ? void 0 : _p.add(id);
4722
4736
  const containerSticky = `containerSticky${containerIndex}`;
4723
4737
  const isSticky = stickyIndicesSet.has(i);
4724
4738
  const isAlwaysRender = alwaysRenderSet.has(i);
@@ -4746,10 +4760,13 @@ function calculateItemsInView(ctx, params = {}) {
4746
4760
  }
4747
4761
  }
4748
4762
  }
4763
+ if (((_q = state.userScrollAnchorResetKeys) == null ? void 0 : _q.size) === 0) {
4764
+ state.userScrollAnchorResetKeys = void 0;
4765
+ }
4749
4766
  if (alwaysRenderArr.length > 0) {
4750
4767
  for (const index of alwaysRenderArr) {
4751
4768
  if (index < 0 || index >= dataLength) continue;
4752
- const id = (_p = idCache[index]) != null ? _p : getId(state, index);
4769
+ const id = (_r = idCache[index]) != null ? _r : getId(state, index);
4753
4770
  const containerIndex = containerItemKeys.get(id);
4754
4771
  if (containerIndex !== void 0) {
4755
4772
  state.stickyContainerPool.add(containerIndex);
@@ -5110,7 +5127,14 @@ function updateScroll(ctx, newScroll, forceUpdate) {
5110
5127
  (_a4 = state.triggerCalculateItemsInView) == null ? void 0 : _a4.call(state, { doMVCP: scrollingTo !== void 0 });
5111
5128
  checkThresholds(ctx);
5112
5129
  };
5113
- if (scrollLength > 0 && scrollingTo === void 0 && scrollDelta > scrollLength) {
5130
+ if (scrollLength > 0 && scrollingTo === void 0 && scrollDelta > scrollLength && !state.pendingNativeMVCPAdjust) {
5131
+ state.mvcpAnchorLock = void 0;
5132
+ state.pendingNativeMVCPAdjust = void 0;
5133
+ state.userScrollAnchorResetKeys = /* @__PURE__ */ new Set();
5134
+ if (state.queuedMVCPRecalculate !== void 0) {
5135
+ cancelAnimationFrame(state.queuedMVCPRecalculate);
5136
+ state.queuedMVCPRecalculate = void 0;
5137
+ }
5114
5138
  flushSync(runCalculateItems);
5115
5139
  } else {
5116
5140
  runCalculateItems();
@@ -5293,6 +5317,20 @@ function maybeUpdateAnchoredEndSpace(ctx) {
5293
5317
  // src/core/updateItemSize.ts
5294
5318
  function runOrScheduleMVCPRecalculate(ctx) {
5295
5319
  const state = ctx.state;
5320
+ if (state.userScrollAnchorResetKeys !== void 0) {
5321
+ if (state.queuedMVCPRecalculate !== void 0) {
5322
+ return;
5323
+ }
5324
+ state.queuedMVCPRecalculate = requestAnimationFrame(() => {
5325
+ var _a3;
5326
+ state.queuedMVCPRecalculate = void 0;
5327
+ calculateItemsInView(ctx);
5328
+ if (((_a3 = state.userScrollAnchorResetKeys) == null ? void 0 : _a3.size) === 0) {
5329
+ state.userScrollAnchorResetKeys = void 0;
5330
+ }
5331
+ });
5332
+ return;
5333
+ }
5296
5334
  {
5297
5335
  if (!state.mvcpAnchorLock) {
5298
5336
  if (state.queuedMVCPRecalculate !== void 0) {
@@ -5314,6 +5352,8 @@ function runOrScheduleMVCPRecalculate(ctx) {
5314
5352
  function updateItemSize(ctx, itemKey, sizeObj) {
5315
5353
  var _a3;
5316
5354
  const state = ctx.state;
5355
+ const userScrollAnchorResetKeys = state.userScrollAnchorResetKeys;
5356
+ const didMeasureUserScrollAnchorResetItem = !!(userScrollAnchorResetKeys == null ? void 0 : userScrollAnchorResetKeys.delete(itemKey));
5317
5357
  const {
5318
5358
  didContainersLayout,
5319
5359
  sizesKnown,
@@ -5392,10 +5432,12 @@ function updateItemSize(ctx, itemKey, sizeObj) {
5392
5432
  if (!cur || maxOtherAxisSize > cur) {
5393
5433
  set$(ctx, "otherAxisSize", maxOtherAxisSize);
5394
5434
  }
5395
- if (didContainersLayout || checkAllSizesKnown(state)) {
5435
+ if (didContainersLayout || checkAllSizesKnown(state, getMountedBufferedIndices(state))) {
5396
5436
  if (needsRecalculate) {
5397
5437
  state.scrollForNextCalculateItemsInView = void 0;
5398
5438
  runOrScheduleMVCPRecalculate(ctx);
5439
+ } else if (didMeasureUserScrollAnchorResetItem && (userScrollAnchorResetKeys == null ? void 0 : userScrollAnchorResetKeys.size) === 0) {
5440
+ state.userScrollAnchorResetKeys = void 0;
5399
5441
  }
5400
5442
  if (shouldMaintainScrollAtEnd) {
5401
5443
  if (maintainScrollAtEnd == null ? void 0 : maintainScrollAtEnd.onItemLayout) {