@tanstack/virtual-core 3.19.1 → 3.19.3
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/dist/cjs/index.cjs +139 -134
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs/index.d.cts +7 -5
- package/dist/esm/index.d.ts +7 -5
- package/dist/esm/index.js +139 -134
- package/dist/esm/index.js.map +1 -1
- package/package.json +1 -1
- package/src/index.ts +239 -217
package/dist/cjs/index.cjs
CHANGED
|
@@ -165,6 +165,9 @@ const scrollWithAdjustments = (offset, {
|
|
|
165
165
|
};
|
|
166
166
|
const windowScroll = scrollWithAdjustments;
|
|
167
167
|
const elementScroll = scrollWithAdjustments;
|
|
168
|
+
const initialScrollPhase = (behavior, atTarget) => behavior === "smooth" ? atTarget ? "smoothLanded" : "smooth" : "instant";
|
|
169
|
+
const isSmoothScroll = (state) => (state == null ? void 0 : state.phase) === "smooth" || (state == null ? void 0 : state.phase) === "smoothLanded";
|
|
170
|
+
const isAnimating = (state) => state.phase === "smooth" || state.phase === "smoothFinishing";
|
|
168
171
|
function isAppendWithTrim(prevCount, nextCount, getPreviousKey, getNextKey) {
|
|
169
172
|
if (nextCount === 0) return false;
|
|
170
173
|
const firstKey = getNextKey(0);
|
|
@@ -206,12 +209,9 @@ class Virtualizer {
|
|
|
206
209
|
this.scrollRect = null;
|
|
207
210
|
this.scrollOffset = null;
|
|
208
211
|
this.scrollDirection = null;
|
|
209
|
-
this.scrollAdjustments = 0;
|
|
210
212
|
this._iosDeferredAdjustment = 0;
|
|
211
|
-
this.
|
|
212
|
-
this.
|
|
213
|
-
this._iosTouchEndTimerId = null;
|
|
214
|
-
this._intendedScrollOffset = null;
|
|
213
|
+
this._iosTouch = null;
|
|
214
|
+
this.pendingWrite = null;
|
|
215
215
|
this._clampedAdjustment = null;
|
|
216
216
|
this.elementsCache = /* @__PURE__ */ new Map();
|
|
217
217
|
this._resizeBatch = null;
|
|
@@ -355,8 +355,7 @@ class Virtualizer {
|
|
|
355
355
|
this.pendingMin = 0;
|
|
356
356
|
this.itemSizeCacheVersion++;
|
|
357
357
|
}
|
|
358
|
-
let
|
|
359
|
-
let anchorDelta = 0;
|
|
358
|
+
let anchorDelta = null;
|
|
360
359
|
if (anchor && this.scrollOffset !== null) {
|
|
361
360
|
const [anchorKey, anchorOffset] = anchor;
|
|
362
361
|
const newMeasurements = this.getMeasurements();
|
|
@@ -372,18 +371,14 @@ class Virtualizer {
|
|
|
372
371
|
if (!followOnAppend && newOffset !== this.scrollOffset) {
|
|
373
372
|
anchorDelta = newOffset - this.scrollOffset;
|
|
374
373
|
this.scrollOffset = newOffset;
|
|
375
|
-
anchorResolved = true;
|
|
376
374
|
}
|
|
377
375
|
}
|
|
378
376
|
}
|
|
379
377
|
}
|
|
380
|
-
if (
|
|
381
|
-
this.pendingScrollAnchor =
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
followOnAppend,
|
|
385
|
-
anchorDelta
|
|
386
|
-
];
|
|
378
|
+
if (followOnAppend) {
|
|
379
|
+
this.pendingScrollAnchor = { kind: "follow", behavior: followOnAppend };
|
|
380
|
+
} else if (anchorDelta !== null) {
|
|
381
|
+
this.pendingScrollAnchor = { kind: "anchor", delta: anchorDelta };
|
|
387
382
|
}
|
|
388
383
|
};
|
|
389
384
|
this.notify = (sync) => {
|
|
@@ -424,9 +419,9 @@ class Virtualizer {
|
|
|
424
419
|
this.isScrolling = false;
|
|
425
420
|
this.scrollDirection = null;
|
|
426
421
|
this._iosDeferredAdjustment = 0;
|
|
427
|
-
this.
|
|
428
|
-
this._iosJustTouchEnded = false;
|
|
422
|
+
this._endIosTouch();
|
|
429
423
|
this._clampedAdjustment = null;
|
|
424
|
+
this.pendingWrite = null;
|
|
430
425
|
this.scrollElement = null;
|
|
431
426
|
this.targetWindow = null;
|
|
432
427
|
};
|
|
@@ -436,7 +431,7 @@ class Virtualizer {
|
|
|
436
431
|
};
|
|
437
432
|
};
|
|
438
433
|
this._willUpdate = () => {
|
|
439
|
-
var _a
|
|
434
|
+
var _a;
|
|
440
435
|
const scrollElement = this.options.enabled ? this.options.getScrollElement() : null;
|
|
441
436
|
if (this.scrollElement !== scrollElement) {
|
|
442
437
|
this.cleanup();
|
|
@@ -462,11 +457,12 @@ class Virtualizer {
|
|
|
462
457
|
this.unsubs.push(
|
|
463
458
|
this.options.observeElementOffset(this, (offset, isScrolling) => {
|
|
464
459
|
var _a2;
|
|
465
|
-
if (isScrolling && this.
|
|
460
|
+
if (isScrolling && this.pendingWrite === null && offset === this.scrollOffset) {
|
|
466
461
|
return;
|
|
467
462
|
}
|
|
468
|
-
|
|
469
|
-
|
|
463
|
+
const pending = this.pendingWrite;
|
|
464
|
+
if (pending !== null && Math.abs(offset - pending.target) < 1.5) {
|
|
465
|
+
offset = pending.target;
|
|
470
466
|
} else if (((_a2 = this.scrollState) == null ? void 0 : _a2.index) != null && // A non-smooth write lands at once, so any other scroll event is
|
|
471
467
|
// the user's, even before reconcile saw the target reached (the
|
|
472
468
|
// target may keep moving, or iOS ignored the write under a
|
|
@@ -478,17 +474,15 @@ class Virtualizer {
|
|
|
478
474
|
// like the user and the scroll stops at the max. That needs the
|
|
479
475
|
// sizer re-rendered before the scroll event, which browsers have
|
|
480
476
|
// not been seen to do (pinned by a `.fails` test).
|
|
481
|
-
//
|
|
482
|
-
// it only
|
|
483
|
-
(this.scrollState
|
|
477
|
+
// While a smooth scroll's animation may still report, its events
|
|
478
|
+
// look like a user's, so it yields only once it has landed.
|
|
479
|
+
!isAnimating(this.scrollState) && !utils.approxEqual(offset, this.scrollState.lastTargetOffset) && !utils.approxEqual(offset, this.getScrollStateTarget(this.scrollState)) && (this._clampedAdjustment === null || Math.abs(offset - this._clampedAdjustment.maxAtWrite) >= 1.5)) {
|
|
484
480
|
this.scrollState = null;
|
|
485
481
|
}
|
|
486
|
-
this.
|
|
487
|
-
if (this.scrollState) this.scrollState.writtenOffset = null;
|
|
482
|
+
this.pendingWrite = null;
|
|
488
483
|
if (this._clampedAdjustment !== null && Math.abs(offset - this._clampedAdjustment.maxAtWrite) >= 1.5) {
|
|
489
484
|
this._clampedAdjustment = null;
|
|
490
485
|
}
|
|
491
|
-
this.scrollAdjustments = 0;
|
|
492
486
|
const prevOffset = this.getScrollOffset();
|
|
493
487
|
this.scrollDirection = isScrolling ? prevOffset === offset ? this.scrollDirection : prevOffset < offset ? "forward" : "backward" : null;
|
|
494
488
|
this.scrollOffset = offset;
|
|
@@ -503,24 +497,22 @@ class Virtualizer {
|
|
|
503
497
|
if ("addEventListener" in this.scrollElement) {
|
|
504
498
|
const scrollEl = this.scrollElement;
|
|
505
499
|
const onTouchStart = () => {
|
|
506
|
-
this.
|
|
507
|
-
this.
|
|
508
|
-
if (this._iosTouchEndTimerId !== null && this.targetWindow != null) {
|
|
509
|
-
this.targetWindow.clearTimeout(this._iosTouchEndTimerId);
|
|
510
|
-
this._iosTouchEndTimerId = null;
|
|
511
|
-
}
|
|
500
|
+
this._endIosTouch();
|
|
501
|
+
this._iosTouch = { phase: "down" };
|
|
512
502
|
};
|
|
513
503
|
const onTouchEnd = () => {
|
|
514
|
-
this.
|
|
504
|
+
this._endIosTouch();
|
|
515
505
|
if (!isIOSWebKit() || this.targetWindow == null) {
|
|
516
506
|
return;
|
|
517
507
|
}
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
this.
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
508
|
+
const tail = {
|
|
509
|
+
phase: "tail",
|
|
510
|
+
timerId: this.targetWindow.setTimeout(() => {
|
|
511
|
+
if (this._iosTouch === tail) this._iosTouch = null;
|
|
512
|
+
this._flushIosDeferredIfReady();
|
|
513
|
+
}, 150)
|
|
514
|
+
};
|
|
515
|
+
this._iosTouch = tail;
|
|
524
516
|
};
|
|
525
517
|
scrollEl.addEventListener(
|
|
526
518
|
"touchstart",
|
|
@@ -532,13 +524,16 @@ class Virtualizer {
|
|
|
532
524
|
onTouchEnd,
|
|
533
525
|
addEventListenerOptions
|
|
534
526
|
);
|
|
527
|
+
scrollEl.addEventListener(
|
|
528
|
+
"touchcancel",
|
|
529
|
+
onTouchEnd,
|
|
530
|
+
addEventListenerOptions
|
|
531
|
+
);
|
|
535
532
|
this.unsubs.push(() => {
|
|
536
533
|
scrollEl.removeEventListener("touchstart", onTouchStart);
|
|
537
534
|
scrollEl.removeEventListener("touchend", onTouchEnd);
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
this._iosTouchEndTimerId = null;
|
|
541
|
-
}
|
|
535
|
+
scrollEl.removeEventListener("touchcancel", onTouchEnd);
|
|
536
|
+
this._endIosTouch();
|
|
542
537
|
});
|
|
543
538
|
}
|
|
544
539
|
this._scrollToOffset(this.getScrollOffset(), {
|
|
@@ -549,14 +544,11 @@ class Virtualizer {
|
|
|
549
544
|
const anchor = this.pendingScrollAnchor;
|
|
550
545
|
this.pendingScrollAnchor = null;
|
|
551
546
|
if (anchor && this.scrollElement && this.options.enabled) {
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
}
|
|
558
|
-
} else if (((_b = this.scrollState) == null ? void 0 : _b.behavior) === "smooth" && !utils.approxEqual(
|
|
559
|
-
this.getScrollOffset() - anchorDelta,
|
|
547
|
+
if (anchor.kind === "anchor") {
|
|
548
|
+
if (isIOSWebKit() && this._iosInMotion()) {
|
|
549
|
+
this._iosDeferredAdjustment += anchor.delta;
|
|
550
|
+
} else if (isSmoothScroll(this.scrollState) && !utils.approxEqual(
|
|
551
|
+
this.getScrollOffset() - anchor.delta,
|
|
560
552
|
this.scrollState.lastTargetOffset
|
|
561
553
|
)) ;
|
|
562
554
|
else {
|
|
@@ -565,9 +557,8 @@ class Virtualizer {
|
|
|
565
557
|
behavior: void 0
|
|
566
558
|
});
|
|
567
559
|
}
|
|
568
|
-
}
|
|
569
|
-
|
|
570
|
-
this.scrollToEnd({ behavior: followOnAppend });
|
|
560
|
+
} else {
|
|
561
|
+
this.scrollToEnd({ behavior: anchor.behavior });
|
|
571
562
|
}
|
|
572
563
|
}
|
|
573
564
|
this._retryClampedAdjustment();
|
|
@@ -586,11 +577,17 @@ class Virtualizer {
|
|
|
586
577
|
});
|
|
587
578
|
}
|
|
588
579
|
};
|
|
580
|
+
this._iosInMotion = () => this.isScrolling || this._iosTouch !== null;
|
|
581
|
+
this._endIosTouch = () => {
|
|
582
|
+
var _a;
|
|
583
|
+
if (((_a = this._iosTouch) == null ? void 0 : _a.phase) === "tail" && this.targetWindow != null) {
|
|
584
|
+
this.targetWindow.clearTimeout(this._iosTouch.timerId);
|
|
585
|
+
}
|
|
586
|
+
this._iosTouch = null;
|
|
587
|
+
};
|
|
589
588
|
this._flushIosDeferredIfReady = () => {
|
|
590
589
|
if (this._iosDeferredAdjustment === 0) return;
|
|
591
|
-
if (this.
|
|
592
|
-
if (this._iosTouching) return;
|
|
593
|
-
if (this._iosJustTouchEnded) return;
|
|
590
|
+
if (this._iosInMotion()) return;
|
|
594
591
|
const cur = this.getScrollOffset();
|
|
595
592
|
const max = this.getMaxScrollOffset();
|
|
596
593
|
if (cur < 0 || cur > max) return;
|
|
@@ -601,7 +598,7 @@ class Virtualizer {
|
|
|
601
598
|
const delta = this._iosDeferredAdjustment;
|
|
602
599
|
this._iosDeferredAdjustment = 0;
|
|
603
600
|
this._scrollToOffset(cur, {
|
|
604
|
-
adjustments: this.scrollAdjustments
|
|
601
|
+
adjustments: this.scrollAdjustments + delta,
|
|
605
602
|
behavior: void 0
|
|
606
603
|
});
|
|
607
604
|
};
|
|
@@ -880,7 +877,7 @@ class Virtualizer {
|
|
|
880
877
|
};
|
|
881
878
|
this.shouldMeasureDuringScroll = (index) => {
|
|
882
879
|
var _a;
|
|
883
|
-
if (!this.scrollState
|
|
880
|
+
if (!isSmoothScroll(this.scrollState)) {
|
|
884
881
|
return true;
|
|
885
882
|
}
|
|
886
883
|
const scrollIndex = this.scrollState.index ?? ((_a = this.getVirtualItemForOffset(this.scrollState.lastTargetOffset)) == null ? void 0 : _a.index);
|
|
@@ -924,7 +921,7 @@ class Virtualizer {
|
|
|
924
921
|
}
|
|
925
922
|
};
|
|
926
923
|
this.resizeItem = (index, size) => {
|
|
927
|
-
var _a, _b, _c
|
|
924
|
+
var _a, _b, _c;
|
|
928
925
|
if (!this.isIndexInRange(index)) return;
|
|
929
926
|
if ((_a = this._resizeBatch) == null ? void 0 : _a.sync) this.getMeasurements();
|
|
930
927
|
let cachedSize;
|
|
@@ -945,7 +942,7 @@ class Virtualizer {
|
|
|
945
942
|
const itemSize = this.itemSizeCache.get(key) ?? cachedSize;
|
|
946
943
|
const delta = size - itemSize;
|
|
947
944
|
if (delta !== 0) {
|
|
948
|
-
const wasAtEnd = this.options.anchorTo === "end" && (
|
|
945
|
+
const wasAtEnd = this.options.anchorTo === "end" && !isSmoothScroll(this.scrollState) && this.getVirtualDistanceFromEnd() <= this.options.scrollEndThreshold;
|
|
949
946
|
const prevTotalSize = wasAtEnd ? this.getTotalSize() : 0;
|
|
950
947
|
const scrollOffsetWithAdj = this.getScrollOffset() + this.scrollAdjustments;
|
|
951
948
|
const isFirstMeasure = !this.itemSizeCache.has(key);
|
|
@@ -964,7 +961,7 @@ class Virtualizer {
|
|
|
964
961
|
// scrolling up" cascade.
|
|
965
962
|
itemStart + itemSize <= scrollOffsetWithAdj && this.scrollDirection !== "backward"
|
|
966
963
|
);
|
|
967
|
-
const shouldAdjustScroll = (
|
|
964
|
+
const shouldAdjustScroll = !isSmoothScroll(this.scrollState) && (this.shouldAdjustScrollPositionOnItemSizeChange !== void 0 ? this.shouldAdjustScrollPositionOnItemSizeChange(
|
|
968
965
|
// The callback expects a VirtualItem; build one lazily only
|
|
969
966
|
// when the consumer actually supplied a custom predicate.
|
|
970
967
|
this.measurementsCache[index] ?? {
|
|
@@ -983,8 +980,9 @@ class Virtualizer {
|
|
|
983
980
|
}
|
|
984
981
|
this.itemSizeCache.set(key, size);
|
|
985
982
|
this.itemSizeCacheVersion++;
|
|
986
|
-
const
|
|
987
|
-
|
|
983
|
+
const writtenOffset = this.getCommandWrittenOffset();
|
|
984
|
+
const awaitingCommandReadBack = writtenOffset !== null && !utils.approxEqual(
|
|
985
|
+
writtenOffset,
|
|
988
986
|
this.getScrollOffset() + this.scrollAdjustments
|
|
989
987
|
);
|
|
990
988
|
let adjustedSync = false;
|
|
@@ -999,7 +997,7 @@ class Virtualizer {
|
|
|
999
997
|
}
|
|
1000
998
|
if (this._resizeBatch) {
|
|
1001
999
|
this._resizeBatch.notify = true;
|
|
1002
|
-
(
|
|
1000
|
+
(_c = this._resizeBatch).sync || (_c.sync = adjustedSync);
|
|
1003
1001
|
return;
|
|
1004
1002
|
}
|
|
1005
1003
|
this.notify(adjustedSync);
|
|
@@ -1101,84 +1099,46 @@ class Virtualizer {
|
|
|
1101
1099
|
];
|
|
1102
1100
|
};
|
|
1103
1101
|
this.scrollToOffset = (toOffset, { align = "start", behavior = "auto" } = {}) => {
|
|
1104
|
-
this.
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
this.scrollState = {
|
|
1108
|
-
index: null,
|
|
1109
|
-
align,
|
|
1102
|
+
this._startScroll(
|
|
1103
|
+
{ index: null, align },
|
|
1104
|
+
this.getOffsetForAlignment(toOffset, align),
|
|
1110
1105
|
behavior,
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
stableFrames: 0,
|
|
1114
|
-
hasReachedTarget: false,
|
|
1115
|
-
startedSmooth: behavior === "smooth"
|
|
1116
|
-
};
|
|
1117
|
-
this._scrollToOffset(offset, { adjustments: void 0, behavior });
|
|
1118
|
-
this.scheduleScrollReconcile();
|
|
1106
|
+
"absolute"
|
|
1107
|
+
);
|
|
1119
1108
|
};
|
|
1120
1109
|
this.scrollToIndex = (index, {
|
|
1121
1110
|
align: initialAlign = "auto",
|
|
1122
1111
|
behavior = "auto"
|
|
1123
1112
|
} = {}) => {
|
|
1124
|
-
this._iosDeferredAdjustment = 0;
|
|
1125
1113
|
index = Math.max(0, Math.min(index, this.options.count - 1));
|
|
1126
1114
|
const offsetInfo = this.getOffsetForIndex(index, initialAlign);
|
|
1127
1115
|
if (!offsetInfo) {
|
|
1116
|
+
this._iosDeferredAdjustment = 0;
|
|
1128
1117
|
return;
|
|
1129
1118
|
}
|
|
1130
1119
|
const [offset, align] = offsetInfo;
|
|
1131
|
-
|
|
1132
|
-
this.scrollState = {
|
|
1133
|
-
index,
|
|
1134
|
-
align,
|
|
1135
|
-
behavior,
|
|
1136
|
-
startedAt: now,
|
|
1137
|
-
lastTargetOffset: offset,
|
|
1138
|
-
stableFrames: 0,
|
|
1139
|
-
hasReachedTarget: utils.approxEqual(offset, this.getScrollOffset()),
|
|
1140
|
-
startedSmooth: behavior === "smooth"
|
|
1141
|
-
};
|
|
1142
|
-
this._scrollToOffset(offset, { adjustments: void 0, behavior });
|
|
1143
|
-
this.scheduleScrollReconcile();
|
|
1120
|
+
this._startScroll({ index, align }, offset, behavior, "absolute");
|
|
1144
1121
|
};
|
|
1145
1122
|
this.scrollBy = (delta, { behavior = "auto" } = {}) => {
|
|
1146
|
-
var _a;
|
|
1147
1123
|
const offset = this.getOffsetForAlignment(
|
|
1148
|
-
(
|
|
1124
|
+
(this.getCommandWrittenOffset() ?? this.getScrollOffset()) + delta,
|
|
1149
1125
|
"start"
|
|
1150
1126
|
);
|
|
1151
|
-
|
|
1152
|
-
|
|
1153
|
-
|
|
1154
|
-
align: "start",
|
|
1127
|
+
this._startScroll(
|
|
1128
|
+
{ index: null, align: "start" },
|
|
1129
|
+
offset,
|
|
1155
1130
|
behavior,
|
|
1156
|
-
|
|
1157
|
-
|
|
1158
|
-
stableFrames: 0,
|
|
1159
|
-
hasReachedTarget: false,
|
|
1160
|
-
startedSmooth: behavior === "smooth"
|
|
1161
|
-
};
|
|
1162
|
-
this._scrollToOffset(offset, { adjustments: void 0, behavior });
|
|
1163
|
-
this.scheduleScrollReconcile();
|
|
1131
|
+
"relative"
|
|
1132
|
+
);
|
|
1164
1133
|
};
|
|
1165
1134
|
this.scrollToEnd = ({ behavior = "auto" } = {}) => {
|
|
1166
1135
|
if (this.options.count > 0) {
|
|
1167
|
-
this.
|
|
1168
|
-
|
|
1169
|
-
|
|
1170
|
-
index: this.options.count - 1,
|
|
1171
|
-
align: "end",
|
|
1136
|
+
this._startScroll(
|
|
1137
|
+
{ index: this.options.count - 1, align: "end", toEnd: true },
|
|
1138
|
+
Math.max(this.getMaxScrollOffset(), 0),
|
|
1172
1139
|
behavior,
|
|
1173
|
-
|
|
1174
|
-
|
|
1175
|
-
lastTargetOffset: offset,
|
|
1176
|
-
stableFrames: 0,
|
|
1177
|
-
hasReachedTarget: utils.approxEqual(offset, this.getScrollOffset()),
|
|
1178
|
-
startedSmooth: behavior === "smooth"
|
|
1179
|
-
};
|
|
1180
|
-
this._scrollToOffset(offset, { adjustments: void 0, behavior });
|
|
1181
|
-
this.scheduleScrollReconcile();
|
|
1140
|
+
"absolute"
|
|
1141
|
+
);
|
|
1182
1142
|
return;
|
|
1183
1143
|
}
|
|
1184
1144
|
this.scrollToOffset(Math.max(this.getTotalSize() - this.getSize(), 0), {
|
|
@@ -1245,12 +1205,14 @@ class Virtualizer {
|
|
|
1245
1205
|
adjustments,
|
|
1246
1206
|
behavior
|
|
1247
1207
|
}) => {
|
|
1248
|
-
this.
|
|
1249
|
-
|
|
1250
|
-
|
|
1251
|
-
|
|
1208
|
+
this.pendingWrite = {
|
|
1209
|
+
target: offset + (adjustments ?? 0),
|
|
1210
|
+
smooth: behavior === "smooth",
|
|
1211
|
+
adjustments: adjustments ?? this.scrollAdjustments
|
|
1212
|
+
};
|
|
1252
1213
|
this.options.scrollToFn(offset, { behavior, adjustments }, this);
|
|
1253
1214
|
};
|
|
1215
|
+
this.getCommandWrittenOffset = () => this.scrollState !== null && this.pendingWrite !== null && !this.pendingWrite.smooth ? this.pendingWrite.target : null;
|
|
1254
1216
|
this.measure = () => {
|
|
1255
1217
|
this.pendingMin = null;
|
|
1256
1218
|
this.itemSizeCache.clear();
|
|
@@ -1260,6 +1222,13 @@ class Virtualizer {
|
|
|
1260
1222
|
};
|
|
1261
1223
|
this.setOptions(opts);
|
|
1262
1224
|
}
|
|
1225
|
+
// Size compensation written to the element but not yet reflected in
|
|
1226
|
+
// `scrollOffset`: the element is expected at `scrollOffset +
|
|
1227
|
+
// scrollAdjustments` until the next scroll event reports it.
|
|
1228
|
+
get scrollAdjustments() {
|
|
1229
|
+
var _a;
|
|
1230
|
+
return ((_a = this.pendingWrite) == null ? void 0 : _a.adjustments) ?? 0;
|
|
1231
|
+
}
|
|
1263
1232
|
// Returns `true` when it performed a synchronous `scrollTop` write this
|
|
1264
1233
|
// tick, `false` when the delta was zero or the write was deferred (iOS).
|
|
1265
1234
|
// `resizeItem` uses that to decide whether the follow-up `notify` must be
|
|
@@ -1270,7 +1239,7 @@ class Virtualizer {
|
|
|
1270
1239
|
if (process.env.NODE_ENV !== "production" && this.options.debug) {
|
|
1271
1240
|
console.info("correction", delta);
|
|
1272
1241
|
}
|
|
1273
|
-
if (isIOSWebKit() &&
|
|
1242
|
+
if (isIOSWebKit() && this._iosInMotion()) {
|
|
1274
1243
|
if (((_a = this.scrollState) == null ? void 0 : _a.index) == null) {
|
|
1275
1244
|
this._iosDeferredAdjustment += delta;
|
|
1276
1245
|
}
|
|
@@ -1281,13 +1250,13 @@ class Virtualizer {
|
|
|
1281
1250
|
const maxAtWrite = el !== null && ("scrollHeight" in el || "document" in el) ? this.getMaxScrollOffset() : null;
|
|
1282
1251
|
this._clampedAdjustment = maxAtWrite !== null && target > maxAtWrite + 0.5 ? { target, maxAtWrite } : null;
|
|
1283
1252
|
this._scrollToOffset(this.getScrollOffset(), {
|
|
1284
|
-
adjustments: this.scrollAdjustments
|
|
1253
|
+
adjustments: this.scrollAdjustments + delta,
|
|
1285
1254
|
behavior
|
|
1286
1255
|
});
|
|
1287
1256
|
if (this.scrollOffset !== null) {
|
|
1288
1257
|
this.scrollOffset += this.scrollAdjustments;
|
|
1289
1258
|
if (this.scrollOffset < 0) this.scrollOffset = 0;
|
|
1290
|
-
this.
|
|
1259
|
+
if (this.pendingWrite) this.pendingWrite.adjustments = 0;
|
|
1291
1260
|
}
|
|
1292
1261
|
return true;
|
|
1293
1262
|
}
|
|
@@ -1321,7 +1290,11 @@ class Virtualizer {
|
|
|
1321
1290
|
const STABLE_FRAMES = this.scrollState.index == null ? 1 : this.options.useAnimationFrameWithResizeObserver ? 3 : 2;
|
|
1322
1291
|
const targetChanged = targetOffset !== this.scrollState.lastTargetOffset;
|
|
1323
1292
|
if (!targetChanged && utils.approxEqual(targetOffset, this.getScrollOffset())) {
|
|
1324
|
-
this.scrollState.
|
|
1293
|
+
if (this.scrollState.phase === "smooth") {
|
|
1294
|
+
this.scrollState.phase = "smoothLanded";
|
|
1295
|
+
} else if (this.scrollState.phase === "smoothFinishing") {
|
|
1296
|
+
this.scrollState.phase = "instant";
|
|
1297
|
+
}
|
|
1325
1298
|
this.scrollState.stableFrames++;
|
|
1326
1299
|
if (this.scrollState.stableFrames >= STABLE_FRAMES) {
|
|
1327
1300
|
if (this.getScrollOffset() !== targetOffset) {
|
|
@@ -1338,12 +1311,14 @@ class Virtualizer {
|
|
|
1338
1311
|
if (targetChanged) {
|
|
1339
1312
|
const viewport = this.getSize() || 600;
|
|
1340
1313
|
const distance = Math.abs(targetOffset - this.getScrollOffset());
|
|
1341
|
-
const keepSmooth = this.scrollState
|
|
1314
|
+
const keepSmooth = isSmoothScroll(this.scrollState) && distance > viewport;
|
|
1342
1315
|
this.scrollState.lastTargetOffset = targetOffset;
|
|
1343
1316
|
if (keepSmooth) {
|
|
1344
|
-
this.scrollState.
|
|
1345
|
-
} else {
|
|
1346
|
-
this.scrollState.
|
|
1317
|
+
this.scrollState.phase = "smooth";
|
|
1318
|
+
} else if (this.scrollState.phase === "smooth") {
|
|
1319
|
+
this.scrollState.phase = "smoothFinishing";
|
|
1320
|
+
} else if (this.scrollState.phase === "smoothLanded") {
|
|
1321
|
+
this.scrollState.phase = "instant";
|
|
1347
1322
|
}
|
|
1348
1323
|
this._scrollToOffset(targetOffset, {
|
|
1349
1324
|
adjustments: void 0,
|
|
@@ -1353,6 +1328,36 @@ class Virtualizer {
|
|
|
1353
1328
|
}
|
|
1354
1329
|
this.scheduleScrollReconcile();
|
|
1355
1330
|
}
|
|
1331
|
+
// Every scroll command starts here: it becomes the in-flight command,
|
|
1332
|
+
// writes its first target and leaves reconcile to retarget and retire it.
|
|
1333
|
+
//
|
|
1334
|
+
// An absolute command derives its target from current measurements, so
|
|
1335
|
+
// any iOS-deferred compensation still pending is stale by definition —
|
|
1336
|
+
// the command already accounts for the measurements the delta was
|
|
1337
|
+
// compensating for. Drop it so _flushIosDeferredIfReady doesn't replay it
|
|
1338
|
+
// onto the just-established position. A relative command (scrollBy)
|
|
1339
|
+
// builds on the current offset, so it keeps the deferral.
|
|
1340
|
+
//
|
|
1341
|
+
// An index or end target that is already at its offset starts a smooth
|
|
1342
|
+
// scroll as landed; an offset target never does, so its first scroll
|
|
1343
|
+
// event is read as the user's (see the scroll handler in `_willUpdate`).
|
|
1344
|
+
_startScroll(target, offset, behavior, kind) {
|
|
1345
|
+
if (kind === "absolute") {
|
|
1346
|
+
this._iosDeferredAdjustment = 0;
|
|
1347
|
+
}
|
|
1348
|
+
this.scrollState = {
|
|
1349
|
+
...target,
|
|
1350
|
+
startedAt: this.now(),
|
|
1351
|
+
lastTargetOffset: offset,
|
|
1352
|
+
stableFrames: 0,
|
|
1353
|
+
phase: initialScrollPhase(
|
|
1354
|
+
behavior,
|
|
1355
|
+
target.index != null && utils.approxEqual(offset, this.getScrollOffset())
|
|
1356
|
+
)
|
|
1357
|
+
};
|
|
1358
|
+
this._scrollToOffset(offset, { adjustments: void 0, behavior });
|
|
1359
|
+
this.scheduleScrollReconcile();
|
|
1360
|
+
}
|
|
1356
1361
|
}
|
|
1357
1362
|
const findNearestBinarySearch = (low, high, getCurrentValue, value) => {
|
|
1358
1363
|
while (low <= high) {
|