@tanstack/virtual-core 3.19.13 → 3.19.14

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.
@@ -217,6 +217,8 @@ class Virtualizer {
217
217
  this.scrollOffset = null;
218
218
  this.scrollDirection = null;
219
219
  this._holdOffset = 0;
220
+ this._wheelTimer = null;
221
+ this._edgeFlushFrame = null;
220
222
  this._reportedOverscroll = false;
221
223
  this._trailing = 0;
222
224
  this._drawnListEnd = Infinity;
@@ -508,6 +510,16 @@ class Virtualizer {
508
510
  this.isScrolling = false;
509
511
  this.scrollDirection = null;
510
512
  this._holdOffset = 0;
513
+ if (this.targetWindow) {
514
+ if (this._wheelTimer !== null) {
515
+ this.targetWindow.clearTimeout(this._wheelTimer);
516
+ }
517
+ if (this._edgeFlushFrame !== null) {
518
+ this.targetWindow.cancelAnimationFrame(this._edgeFlushFrame);
519
+ }
520
+ }
521
+ this._wheelTimer = null;
522
+ this._edgeFlushFrame = null;
511
523
  this._reportedOverscroll = false;
512
524
  this._trailing = 0;
513
525
  this._clampedAdjustment = null;
@@ -618,6 +630,7 @@ class Virtualizer {
618
630
  this.scrollState = null;
619
631
  }
620
632
  this._flushHoldIfReady(true);
633
+ this._flushHoldAtTop();
621
634
  if (this.scrollState) {
622
635
  this.scheduleScrollReconcile();
623
636
  }
@@ -625,9 +638,23 @@ class Virtualizer {
625
638
  })
626
639
  );
627
640
  if ("addEventListener" in this.scrollElement) {
628
- this.unsubs.push(
629
- this._iosGesture.listen(this.scrollElement)
630
- );
641
+ const target = this.scrollElement;
642
+ this.unsubs.push(this._iosGesture.listen(target));
643
+ if (iosGesture.isWebKit()) {
644
+ const onWheel = () => {
645
+ const win = this.targetWindow;
646
+ if (win === null) return;
647
+ if (this._wheelTimer !== null) win.clearTimeout(this._wheelTimer);
648
+ this._wheelTimer = win.setTimeout(() => {
649
+ this._wheelTimer = null;
650
+ this._flushHoldIfReady(true);
651
+ this._retryClampedAdjustment();
652
+ }, 150);
653
+ this._flushHoldAtTop();
654
+ };
655
+ target.addEventListener("wheel", onWheel, addEventListenerOptions);
656
+ this.unsubs.push(() => target.removeEventListener("wheel", onWheel));
657
+ }
631
658
  }
632
659
  this._scrollToOffset(this.getScrollOffset());
633
660
  this._readTrailing(this._elementMaxScrollOffset());
@@ -705,7 +732,28 @@ class Virtualizer {
705
732
  }
706
733
  return null;
707
734
  };
708
- this._canWriteScroll = () => !(iosGesture.isIOSWebKit() && this._iosGesture.inMotion()) && !this._reportedOverscroll;
735
+ this._canWriteScroll = () => !(iosGesture.isIOSWebKit() && this._iosGesture.inMotion()) && !this._reportedOverscroll && this._wheelTimer === null;
736
+ this._holdAtTop = () => {
737
+ if (this._holdOffset === 0) return false;
738
+ const offset = this._readElementOffset();
739
+ return offset !== null && Math.min(offset, offset + this._holdOffset) < this.options.scrollMargin + 1;
740
+ };
741
+ this._flushHoldAtTop = () => {
742
+ const win = this.targetWindow;
743
+ if (win === null || this._wheelTimer === null || this._edgeFlushFrame !== null || !this._holdAtTop()) {
744
+ return;
745
+ }
746
+ this._edgeFlushFrame = win.requestAnimationFrame(() => {
747
+ this._edgeFlushFrame = win.requestAnimationFrame(() => {
748
+ this._edgeFlushFrame = null;
749
+ if (this._wheelTimer === null || !this._holdAtTop()) return;
750
+ win.clearTimeout(this._wheelTimer);
751
+ this._wheelTimer = null;
752
+ this._flushHoldIfReady(true);
753
+ this._retryClampedAdjustment();
754
+ });
755
+ });
756
+ };
709
757
  this._flushHoldIfReady = (sync) => {
710
758
  var _a;
711
759
  if (this._holdOffset === 0) return;
@@ -735,7 +783,7 @@ class Virtualizer {
735
783
  this.scrollOffset = null;
736
784
  return 0;
737
785
  }
738
- this.scrollOffset = this.scrollOffset ?? (typeof this.options.initialOffset === "function" ? this.options.initialOffset() : this.options.initialOffset);
786
+ this.scrollOffset = this.scrollOffset ?? (typeof this.options.initialOffset === "function" ? this.options.initialOffset(this) : this.options.initialOffset);
739
787
  return this.scrollOffset;
740
788
  };
741
789
  this.getMeasurementOptions = utils.memo(
@@ -1054,6 +1102,9 @@ class Virtualizer {
1054
1102
  this.resizeItem = (index, size) => {
1055
1103
  var _a, _b, _c;
1056
1104
  if (!this.isIndexInRange(index)) return;
1105
+ if (this.getMeasurementOptions() !== this.builtMeasurementOptions) {
1106
+ this.getMeasurements();
1107
+ }
1057
1108
  let startShift = 0;
1058
1109
  if ((_a = this._resizeBatch) == null ? void 0 : _a.sync) {
1059
1110
  if (this.canShiftFromPendingResizes()) {
@@ -1575,15 +1626,22 @@ class Virtualizer {
1575
1626
  // Every scroll command starts here: it becomes the in-flight command,
1576
1627
  // writes its first target and leaves reconcile to retarget and retire it.
1577
1628
  //
1578
- // Targets are layout offsets. A held correction is not dropped by a
1579
- // command: the write lands the element `_holdOffset` short of the target,
1580
- // under the rows exposed shifted by the same amount, and the flush moves
1581
- // both together once a write is possible.
1629
+ // Targets are layout offsets. A correction held for the wheel is written
1630
+ // before the command (below). One held for a touch or a bounce is not
1631
+ // dropped by a command: the write lands the element `_holdOffset` short
1632
+ // of the target, under the rows exposed shifted by the same amount, and
1633
+ // the flush moves both together once a write is possible.
1582
1634
  //
1583
1635
  // An index or end target that is already at its offset starts a smooth
1584
1636
  // scroll as landed; an offset target never does, so its first scroll
1585
1637
  // event is read as the user's (see the scroll handler in `_willUpdate`).
1586
1638
  _startScroll(target, offset, behavior, kind) {
1639
+ if (this._wheelTimer !== null && this.targetWindow) {
1640
+ this.targetWindow.clearTimeout(this._wheelTimer);
1641
+ this._wheelTimer = null;
1642
+ this.scrollState = null;
1643
+ this._flushHoldIfReady(true);
1644
+ }
1587
1645
  this.pendingScrollAnchor = null;
1588
1646
  this._clampedAdjustment = null;
1589
1647
  const tail = this._iosGesture.tail();