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

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.js CHANGED
@@ -4232,7 +4232,7 @@ function computeViewability(state, ctx, viewabilityConfig, containerId, key, scr
4232
4232
  }
4233
4233
  function checkIsViewable(state, ctx, viewabilityConfig, containerId, key, scrollSize, item, index) {
4234
4234
  let value = ctx.mapViewabilityAmountValues.get(containerId);
4235
- if (!value || value.key !== key) {
4235
+ if (!value || value.key !== key || value.index !== index) {
4236
4236
  value = computeViewability(state, ctx, viewabilityConfig, containerId, key, scrollSize, item, index);
4237
4237
  }
4238
4238
  return value.isViewable;
@@ -4247,7 +4247,7 @@ var unstableBatchedUpdates = ReactDOM__namespace.unstable_batchedUpdates;
4247
4247
  var batchedUpdates = typeof unstableBatchedUpdates === "function" ? unstableBatchedUpdates : (fn) => fn();
4248
4248
 
4249
4249
  // src/utils/findAvailableContainers.ts
4250
- function findAvailableContainers(ctx, numNeeded, startBuffered, endBuffered, pendingRemoval, requiredItemTypes, needNewContainers) {
4250
+ function findAvailableContainers(ctx, numNeeded, startBuffered, endBuffered, pendingRemoval, requiredItemTypes, needNewContainers, protectedKeys) {
4251
4251
  const numContainers = peek$(ctx, "numContainers");
4252
4252
  const state = ctx.state;
4253
4253
  const { stickyContainerPool, containerItemTypes } = state;
@@ -4315,6 +4315,7 @@ function findAvailableContainers(ctx, numNeeded, startBuffered, endBuffered, pen
4315
4315
  }
4316
4316
  const key = peek$(ctx, `containerItemKey${u}`);
4317
4317
  if (key === void 0) continue;
4318
+ if ((protectedKeys == null ? void 0 : protectedKeys.has(key)) && state.indexByKey.has(key)) continue;
4318
4319
  const index = state.indexByKey.get(key);
4319
4320
  const isOutOfView = index < startBuffered || index > endBuffered;
4320
4321
  if (isOutOfView) {
@@ -4450,7 +4451,7 @@ function handleStickyRecycling(ctx, stickyArray, scroll, drawDistance, currentSt
4450
4451
  function calculateItemsInView(ctx, params = {}) {
4451
4452
  const state = ctx.state;
4452
4453
  batchedUpdates(() => {
4453
- var _a3, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n;
4454
+ var _a3, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p;
4454
4455
  const {
4455
4456
  columns,
4456
4457
  columnSpans,
@@ -4552,17 +4553,31 @@ function calculateItemsInView(ctx, params = {}) {
4552
4553
  if (minIndexSizeChanged !== void 0) {
4553
4554
  state.minIndexSizeChanged = void 0;
4554
4555
  }
4556
+ let protectedContainerKeys;
4557
+ if (dataChanged && doMVCP && state.props.maintainVisibleContentPosition.data && state.didContainersLayout && state.idsInView.length > 0) {
4558
+ const shouldRestorePosition = state.props.maintainVisibleContentPosition.shouldRestorePosition;
4559
+ protectedContainerKeys = /* @__PURE__ */ new Set();
4560
+ for (const id of state.idsInView) {
4561
+ const index = indexByKey.get(id);
4562
+ if (index === void 0) continue;
4563
+ if (shouldRestorePosition && !shouldRestorePosition(data[index], index, data)) continue;
4564
+ protectedContainerKeys.add(id);
4565
+ }
4566
+ }
4567
+ const scrollBeforeMVCP = state.scroll;
4568
+ const scrollAdjustPendingBeforeMVCP = (_e = peek$(ctx, "scrollAdjustPending")) != null ? _e : 0;
4555
4569
  checkMVCP == null ? void 0 : checkMVCP();
4570
+ const didMVCPAdjustScroll = !!checkMVCP && (state.scroll !== scrollBeforeMVCP || ((_f = peek$(ctx, "scrollAdjustPending")) != null ? _f : 0) !== scrollAdjustPendingBeforeMVCP);
4556
4571
  let startNoBuffer = null;
4557
4572
  let startBuffered = null;
4558
4573
  let startBufferedId = null;
4559
4574
  let endNoBuffer = null;
4560
4575
  let endBuffered = null;
4561
- let loopStart = (_e = suppressInitialScrollSideEffects ? bootstrapInitialScrollState == null ? void 0 : bootstrapInitialScrollState.targetIndexSeed : void 0) != null ? _e : !dataChanged && startBufferedIdOrig ? indexByKey.get(startBufferedIdOrig) || 0 : 0;
4576
+ let loopStart = (_g = suppressInitialScrollSideEffects ? bootstrapInitialScrollState == null ? void 0 : bootstrapInitialScrollState.targetIndexSeed : void 0) != null ? _g : !dataChanged && startBufferedIdOrig ? indexByKey.get(startBufferedIdOrig) || 0 : 0;
4562
4577
  for (let i = loopStart; i >= 0; i--) {
4563
- const id = (_f = idCache[i]) != null ? _f : getId(state, i);
4578
+ const id = (_h = idCache[i]) != null ? _h : getId(state, i);
4564
4579
  const top = positions[i];
4565
- const size = (_g = sizes.get(id)) != null ? _g : getItemSize(ctx, id, i, data[i]);
4580
+ const size = (_i = sizes.get(id)) != null ? _i : getItemSize(ctx, id, i, data[i]);
4566
4581
  const bottom = top + size;
4567
4582
  if (bottom > scroll - scrollBufferTop) {
4568
4583
  loopStart = i;
@@ -4593,8 +4608,8 @@ function calculateItemsInView(ctx, params = {}) {
4593
4608
  let firstFullyOnScreenIndex;
4594
4609
  const dataLength = data.length;
4595
4610
  for (let i = Math.max(0, loopStart); i < dataLength && (!foundEnd || i <= maxIndexRendered); i++) {
4596
- const id = (_h = idCache[i]) != null ? _h : getId(state, i);
4597
- const size = (_i = sizes.get(id)) != null ? _i : getItemSize(ctx, id, i, data[i]);
4611
+ const id = (_j = idCache[i]) != null ? _j : getId(state, i);
4612
+ const size = (_k = sizes.get(id)) != null ? _k : getItemSize(ctx, id, i, data[i]);
4598
4613
  const top = positions[i];
4599
4614
  if (!foundEnd) {
4600
4615
  if (startNoBuffer === null && top + size > scroll) {
@@ -4633,7 +4648,7 @@ function calculateItemsInView(ctx, params = {}) {
4633
4648
  const firstVisibleAnchorIndex = firstFullyOnScreenIndex != null ? firstFullyOnScreenIndex : startNoBuffer;
4634
4649
  if (firstVisibleAnchorIndex !== null && firstVisibleAnchorIndex !== void 0 && endNoBuffer !== null) {
4635
4650
  for (let i = firstVisibleAnchorIndex; i <= endNoBuffer; i++) {
4636
- const id = (_j = idCache[i]) != null ? _j : getId(state, i);
4651
+ const id = (_l = idCache[i]) != null ? _l : getId(state, i);
4637
4652
  idsInView.push(id);
4638
4653
  }
4639
4654
  }
@@ -4666,7 +4681,7 @@ function calculateItemsInView(ctx, params = {}) {
4666
4681
  const needNewContainers = [];
4667
4682
  const needNewContainersSet = /* @__PURE__ */ new Set();
4668
4683
  for (let i = startBuffered; i <= endBuffered; i++) {
4669
- const id = (_k = idCache[i]) != null ? _k : getId(state, i);
4684
+ const id = (_m = idCache[i]) != null ? _m : getId(state, i);
4670
4685
  if (!containerItemKeys.has(id)) {
4671
4686
  needNewContainersSet.add(i);
4672
4687
  needNewContainers.push(i);
@@ -4675,7 +4690,7 @@ function calculateItemsInView(ctx, params = {}) {
4675
4690
  if (alwaysRenderArr.length > 0) {
4676
4691
  for (const index of alwaysRenderArr) {
4677
4692
  if (index < 0 || index >= dataLength) continue;
4678
- const id = (_l = idCache[index]) != null ? _l : getId(state, index);
4693
+ const id = (_n = idCache[index]) != null ? _n : getId(state, index);
4679
4694
  if (id && !containerItemKeys.has(id) && !needNewContainersSet.has(index)) {
4680
4695
  needNewContainersSet.add(index);
4681
4696
  needNewContainers.push(index);
@@ -4708,12 +4723,13 @@ function calculateItemsInView(ctx, params = {}) {
4708
4723
  endBuffered,
4709
4724
  pendingRemoval,
4710
4725
  requiredItemTypes,
4711
- needNewContainers
4726
+ needNewContainers,
4727
+ protectedContainerKeys
4712
4728
  );
4713
4729
  for (let idx = 0; idx < needNewContainers.length; idx++) {
4714
4730
  const i = needNewContainers[idx];
4715
4731
  const containerIndex = availableContainers[idx];
4716
- const id = (_m = idCache[i]) != null ? _m : getId(state, i);
4732
+ const id = (_o = idCache[i]) != null ? _o : getId(state, i);
4717
4733
  const oldKey = peek$(ctx, `containerItemKey${containerIndex}`);
4718
4734
  if (oldKey && oldKey !== id) {
4719
4735
  containerItemKeys.delete(oldKey);
@@ -4754,7 +4770,7 @@ function calculateItemsInView(ctx, params = {}) {
4754
4770
  if (alwaysRenderArr.length > 0) {
4755
4771
  for (const index of alwaysRenderArr) {
4756
4772
  if (index < 0 || index >= dataLength) continue;
4757
- const id = (_n = idCache[index]) != null ? _n : getId(state, index);
4773
+ const id = (_p = idCache[index]) != null ? _p : getId(state, index);
4758
4774
  const containerIndex = containerItemKeys.get(id);
4759
4775
  if (containerIndex !== void 0) {
4760
4776
  state.stickyContainerPool.add(containerIndex);
@@ -4815,16 +4831,18 @@ function calculateItemsInView(ctx, params = {}) {
4815
4831
  handleInitialScrollLayoutReady(ctx);
4816
4832
  }
4817
4833
  if (viewabilityConfigCallbackPairs && startNoBuffer !== null && endNoBuffer !== null) {
4818
- updateViewableItems(
4819
- ctx.state,
4820
- ctx,
4821
- viewabilityConfigCallbackPairs,
4822
- scrollLength,
4823
- startNoBuffer,
4824
- endNoBuffer,
4825
- startBuffered != null ? startBuffered : startNoBuffer,
4826
- endBuffered != null ? endBuffered : endNoBuffer
4827
- );
4834
+ if (!didMVCPAdjustScroll) {
4835
+ updateViewableItems(
4836
+ ctx.state,
4837
+ ctx,
4838
+ viewabilityConfigCallbackPairs,
4839
+ scrollLength,
4840
+ startNoBuffer,
4841
+ endNoBuffer,
4842
+ startBuffered != null ? startBuffered : startNoBuffer,
4843
+ endBuffered != null ? endBuffered : endNoBuffer
4844
+ );
4845
+ }
4828
4846
  }
4829
4847
  if (onStickyHeaderChange && stickyIndicesArr.length > 0 && nextActiveStickyIndex !== void 0 && nextActiveStickyIndex !== previousStickyIndex) {
4830
4848
  const item = data[nextActiveStickyIndex];
package/react.mjs CHANGED
@@ -4211,7 +4211,7 @@ function computeViewability(state, ctx, viewabilityConfig, containerId, key, scr
4211
4211
  }
4212
4212
  function checkIsViewable(state, ctx, viewabilityConfig, containerId, key, scrollSize, item, index) {
4213
4213
  let value = ctx.mapViewabilityAmountValues.get(containerId);
4214
- if (!value || value.key !== key) {
4214
+ if (!value || value.key !== key || value.index !== index) {
4215
4215
  value = computeViewability(state, ctx, viewabilityConfig, containerId, key, scrollSize, item, index);
4216
4216
  }
4217
4217
  return value.isViewable;
@@ -4226,7 +4226,7 @@ var unstableBatchedUpdates = ReactDOM.unstable_batchedUpdates;
4226
4226
  var batchedUpdates = typeof unstableBatchedUpdates === "function" ? unstableBatchedUpdates : (fn) => fn();
4227
4227
 
4228
4228
  // src/utils/findAvailableContainers.ts
4229
- function findAvailableContainers(ctx, numNeeded, startBuffered, endBuffered, pendingRemoval, requiredItemTypes, needNewContainers) {
4229
+ function findAvailableContainers(ctx, numNeeded, startBuffered, endBuffered, pendingRemoval, requiredItemTypes, needNewContainers, protectedKeys) {
4230
4230
  const numContainers = peek$(ctx, "numContainers");
4231
4231
  const state = ctx.state;
4232
4232
  const { stickyContainerPool, containerItemTypes } = state;
@@ -4294,6 +4294,7 @@ function findAvailableContainers(ctx, numNeeded, startBuffered, endBuffered, pen
4294
4294
  }
4295
4295
  const key = peek$(ctx, `containerItemKey${u}`);
4296
4296
  if (key === void 0) continue;
4297
+ if ((protectedKeys == null ? void 0 : protectedKeys.has(key)) && state.indexByKey.has(key)) continue;
4297
4298
  const index = state.indexByKey.get(key);
4298
4299
  const isOutOfView = index < startBuffered || index > endBuffered;
4299
4300
  if (isOutOfView) {
@@ -4429,7 +4430,7 @@ function handleStickyRecycling(ctx, stickyArray, scroll, drawDistance, currentSt
4429
4430
  function calculateItemsInView(ctx, params = {}) {
4430
4431
  const state = ctx.state;
4431
4432
  batchedUpdates(() => {
4432
- var _a3, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n;
4433
+ var _a3, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p;
4433
4434
  const {
4434
4435
  columns,
4435
4436
  columnSpans,
@@ -4531,17 +4532,31 @@ function calculateItemsInView(ctx, params = {}) {
4531
4532
  if (minIndexSizeChanged !== void 0) {
4532
4533
  state.minIndexSizeChanged = void 0;
4533
4534
  }
4535
+ let protectedContainerKeys;
4536
+ if (dataChanged && doMVCP && state.props.maintainVisibleContentPosition.data && state.didContainersLayout && state.idsInView.length > 0) {
4537
+ const shouldRestorePosition = state.props.maintainVisibleContentPosition.shouldRestorePosition;
4538
+ protectedContainerKeys = /* @__PURE__ */ new Set();
4539
+ for (const id of state.idsInView) {
4540
+ const index = indexByKey.get(id);
4541
+ if (index === void 0) continue;
4542
+ if (shouldRestorePosition && !shouldRestorePosition(data[index], index, data)) continue;
4543
+ protectedContainerKeys.add(id);
4544
+ }
4545
+ }
4546
+ const scrollBeforeMVCP = state.scroll;
4547
+ const scrollAdjustPendingBeforeMVCP = (_e = peek$(ctx, "scrollAdjustPending")) != null ? _e : 0;
4534
4548
  checkMVCP == null ? void 0 : checkMVCP();
4549
+ const didMVCPAdjustScroll = !!checkMVCP && (state.scroll !== scrollBeforeMVCP || ((_f = peek$(ctx, "scrollAdjustPending")) != null ? _f : 0) !== scrollAdjustPendingBeforeMVCP);
4535
4550
  let startNoBuffer = null;
4536
4551
  let startBuffered = null;
4537
4552
  let startBufferedId = null;
4538
4553
  let endNoBuffer = null;
4539
4554
  let endBuffered = null;
4540
- let loopStart = (_e = suppressInitialScrollSideEffects ? bootstrapInitialScrollState == null ? void 0 : bootstrapInitialScrollState.targetIndexSeed : void 0) != null ? _e : !dataChanged && startBufferedIdOrig ? indexByKey.get(startBufferedIdOrig) || 0 : 0;
4555
+ let loopStart = (_g = suppressInitialScrollSideEffects ? bootstrapInitialScrollState == null ? void 0 : bootstrapInitialScrollState.targetIndexSeed : void 0) != null ? _g : !dataChanged && startBufferedIdOrig ? indexByKey.get(startBufferedIdOrig) || 0 : 0;
4541
4556
  for (let i = loopStart; i >= 0; i--) {
4542
- const id = (_f = idCache[i]) != null ? _f : getId(state, i);
4557
+ const id = (_h = idCache[i]) != null ? _h : getId(state, i);
4543
4558
  const top = positions[i];
4544
- const size = (_g = sizes.get(id)) != null ? _g : getItemSize(ctx, id, i, data[i]);
4559
+ const size = (_i = sizes.get(id)) != null ? _i : getItemSize(ctx, id, i, data[i]);
4545
4560
  const bottom = top + size;
4546
4561
  if (bottom > scroll - scrollBufferTop) {
4547
4562
  loopStart = i;
@@ -4572,8 +4587,8 @@ function calculateItemsInView(ctx, params = {}) {
4572
4587
  let firstFullyOnScreenIndex;
4573
4588
  const dataLength = data.length;
4574
4589
  for (let i = Math.max(0, loopStart); i < dataLength && (!foundEnd || i <= maxIndexRendered); i++) {
4575
- const id = (_h = idCache[i]) != null ? _h : getId(state, i);
4576
- const size = (_i = sizes.get(id)) != null ? _i : getItemSize(ctx, id, i, data[i]);
4590
+ const id = (_j = idCache[i]) != null ? _j : getId(state, i);
4591
+ const size = (_k = sizes.get(id)) != null ? _k : getItemSize(ctx, id, i, data[i]);
4577
4592
  const top = positions[i];
4578
4593
  if (!foundEnd) {
4579
4594
  if (startNoBuffer === null && top + size > scroll) {
@@ -4612,7 +4627,7 @@ function calculateItemsInView(ctx, params = {}) {
4612
4627
  const firstVisibleAnchorIndex = firstFullyOnScreenIndex != null ? firstFullyOnScreenIndex : startNoBuffer;
4613
4628
  if (firstVisibleAnchorIndex !== null && firstVisibleAnchorIndex !== void 0 && endNoBuffer !== null) {
4614
4629
  for (let i = firstVisibleAnchorIndex; i <= endNoBuffer; i++) {
4615
- const id = (_j = idCache[i]) != null ? _j : getId(state, i);
4630
+ const id = (_l = idCache[i]) != null ? _l : getId(state, i);
4616
4631
  idsInView.push(id);
4617
4632
  }
4618
4633
  }
@@ -4645,7 +4660,7 @@ function calculateItemsInView(ctx, params = {}) {
4645
4660
  const needNewContainers = [];
4646
4661
  const needNewContainersSet = /* @__PURE__ */ new Set();
4647
4662
  for (let i = startBuffered; i <= endBuffered; i++) {
4648
- const id = (_k = idCache[i]) != null ? _k : getId(state, i);
4663
+ const id = (_m = idCache[i]) != null ? _m : getId(state, i);
4649
4664
  if (!containerItemKeys.has(id)) {
4650
4665
  needNewContainersSet.add(i);
4651
4666
  needNewContainers.push(i);
@@ -4654,7 +4669,7 @@ function calculateItemsInView(ctx, params = {}) {
4654
4669
  if (alwaysRenderArr.length > 0) {
4655
4670
  for (const index of alwaysRenderArr) {
4656
4671
  if (index < 0 || index >= dataLength) continue;
4657
- const id = (_l = idCache[index]) != null ? _l : getId(state, index);
4672
+ const id = (_n = idCache[index]) != null ? _n : getId(state, index);
4658
4673
  if (id && !containerItemKeys.has(id) && !needNewContainersSet.has(index)) {
4659
4674
  needNewContainersSet.add(index);
4660
4675
  needNewContainers.push(index);
@@ -4687,12 +4702,13 @@ function calculateItemsInView(ctx, params = {}) {
4687
4702
  endBuffered,
4688
4703
  pendingRemoval,
4689
4704
  requiredItemTypes,
4690
- needNewContainers
4705
+ needNewContainers,
4706
+ protectedContainerKeys
4691
4707
  );
4692
4708
  for (let idx = 0; idx < needNewContainers.length; idx++) {
4693
4709
  const i = needNewContainers[idx];
4694
4710
  const containerIndex = availableContainers[idx];
4695
- const id = (_m = idCache[i]) != null ? _m : getId(state, i);
4711
+ const id = (_o = idCache[i]) != null ? _o : getId(state, i);
4696
4712
  const oldKey = peek$(ctx, `containerItemKey${containerIndex}`);
4697
4713
  if (oldKey && oldKey !== id) {
4698
4714
  containerItemKeys.delete(oldKey);
@@ -4733,7 +4749,7 @@ function calculateItemsInView(ctx, params = {}) {
4733
4749
  if (alwaysRenderArr.length > 0) {
4734
4750
  for (const index of alwaysRenderArr) {
4735
4751
  if (index < 0 || index >= dataLength) continue;
4736
- const id = (_n = idCache[index]) != null ? _n : getId(state, index);
4752
+ const id = (_p = idCache[index]) != null ? _p : getId(state, index);
4737
4753
  const containerIndex = containerItemKeys.get(id);
4738
4754
  if (containerIndex !== void 0) {
4739
4755
  state.stickyContainerPool.add(containerIndex);
@@ -4794,16 +4810,18 @@ function calculateItemsInView(ctx, params = {}) {
4794
4810
  handleInitialScrollLayoutReady(ctx);
4795
4811
  }
4796
4812
  if (viewabilityConfigCallbackPairs && startNoBuffer !== null && endNoBuffer !== null) {
4797
- updateViewableItems(
4798
- ctx.state,
4799
- ctx,
4800
- viewabilityConfigCallbackPairs,
4801
- scrollLength,
4802
- startNoBuffer,
4803
- endNoBuffer,
4804
- startBuffered != null ? startBuffered : startNoBuffer,
4805
- endBuffered != null ? endBuffered : endNoBuffer
4806
- );
4813
+ if (!didMVCPAdjustScroll) {
4814
+ updateViewableItems(
4815
+ ctx.state,
4816
+ ctx,
4817
+ viewabilityConfigCallbackPairs,
4818
+ scrollLength,
4819
+ startNoBuffer,
4820
+ endNoBuffer,
4821
+ startBuffered != null ? startBuffered : startNoBuffer,
4822
+ endBuffered != null ? endBuffered : endNoBuffer
4823
+ );
4824
+ }
4807
4825
  }
4808
4826
  if (onStickyHeaderChange && stickyIndicesArr.length > 0 && nextActiveStickyIndex !== void 0 && nextActiveStickyIndex !== previousStickyIndex) {
4809
4827
  const item = data[nextActiveStickyIndex];