@tanstack/virtual-core 3.19.11 → 3.19.12
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 +45 -13
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs/index.d.cts +7 -1
- package/dist/cjs/scroll-classifier.cjs +14 -2
- package/dist/cjs/scroll-classifier.cjs.map +1 -1
- package/dist/cjs/scroll-classifier.d.cts +3 -2
- package/dist/esm/index.d.ts +7 -1
- package/dist/esm/index.js +45 -13
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/scroll-classifier.d.ts +3 -2
- package/dist/esm/scroll-classifier.js +14 -2
- package/dist/esm/scroll-classifier.js.map +1 -1
- package/package.json +1 -1
- package/src/index.ts +92 -16
- package/src/scroll-classifier.ts +31 -3
package/dist/cjs/index.cjs
CHANGED
|
@@ -214,6 +214,8 @@ class Virtualizer {
|
|
|
214
214
|
this.scrollDirection = null;
|
|
215
215
|
this._holdOffset = 0;
|
|
216
216
|
this._reportedOverscroll = false;
|
|
217
|
+
this._trailing = 0;
|
|
218
|
+
this._drawnListEnd = Infinity;
|
|
217
219
|
this._iosGesture = new iosGesture.IosGesture({
|
|
218
220
|
getWindow: () => this.targetWindow,
|
|
219
221
|
now: () => this.now(),
|
|
@@ -248,6 +250,7 @@ class Virtualizer {
|
|
|
248
250
|
});
|
|
249
251
|
this._lastElementOffset = null;
|
|
250
252
|
this.pendingWrite = null;
|
|
253
|
+
this._ownWriteAt = null;
|
|
251
254
|
this._clampedAdjustment = null;
|
|
252
255
|
this.elementsCache = /* @__PURE__ */ new Map();
|
|
253
256
|
this._resizeBatch = null;
|
|
@@ -456,7 +459,7 @@ class Virtualizer {
|
|
|
456
459
|
this.pendingScrollAnchor = { kind: "anchor", delta: anchorDelta };
|
|
457
460
|
} else {
|
|
458
461
|
this._holdOffset += anchorDelta;
|
|
459
|
-
this.
|
|
462
|
+
this._followAnchor(anchorDelta);
|
|
460
463
|
}
|
|
461
464
|
}
|
|
462
465
|
};
|
|
@@ -502,8 +505,10 @@ class Virtualizer {
|
|
|
502
505
|
this.scrollDirection = null;
|
|
503
506
|
this._holdOffset = 0;
|
|
504
507
|
this._reportedOverscroll = false;
|
|
508
|
+
this._trailing = 0;
|
|
505
509
|
this._clampedAdjustment = null;
|
|
506
510
|
this.pendingWrite = null;
|
|
511
|
+
this._ownWriteAt = null;
|
|
507
512
|
this.scrollElement = null;
|
|
508
513
|
this.targetWindow = null;
|
|
509
514
|
};
|
|
@@ -540,6 +545,7 @@ class Virtualizer {
|
|
|
540
545
|
this.options.observeElementOffset(this, (offset, isScrolling) => {
|
|
541
546
|
var _a2, _b, _c, _d;
|
|
542
547
|
const elementMax = isScrolling ? this._elementMaxScrollOffset() : null;
|
|
548
|
+
this._readTrailing(elementMax);
|
|
543
549
|
const wasOverscrolled = this._reportedOverscroll;
|
|
544
550
|
this._reportedOverscroll = offset < 0 || elementMax !== null && offset > elementMax + 1;
|
|
545
551
|
const elementOffset = offset;
|
|
@@ -565,6 +571,11 @@ class Virtualizer {
|
|
|
565
571
|
this.scrollState = null;
|
|
566
572
|
}
|
|
567
573
|
this.pendingWrite = null;
|
|
574
|
+
if (kind === "readBack" || kind === "clampedReadBack" || kind === "clampedEcho") {
|
|
575
|
+
this._ownWriteAt = offset;
|
|
576
|
+
} else if (kind !== "restEcho") {
|
|
577
|
+
this._ownWriteAt = null;
|
|
578
|
+
}
|
|
568
579
|
if (this._clampedAdjustment !== null && Math.abs(offset - this._clampedAdjustment.maxAtWrite) >= 1.5) {
|
|
569
580
|
this._clampedAdjustment = null;
|
|
570
581
|
}
|
|
@@ -615,6 +626,8 @@ class Virtualizer {
|
|
|
615
626
|
);
|
|
616
627
|
}
|
|
617
628
|
this._scrollToOffset(this.getScrollOffset());
|
|
629
|
+
this._readTrailing(this._elementMaxScrollOffset());
|
|
630
|
+
this.maybeNotify();
|
|
618
631
|
}
|
|
619
632
|
this._noteClampMax();
|
|
620
633
|
const anchor = this.pendingScrollAnchor;
|
|
@@ -623,14 +636,11 @@ class Virtualizer {
|
|
|
623
636
|
if (anchor.kind === "anchor") {
|
|
624
637
|
if (!this._canWriteScroll()) {
|
|
625
638
|
this._holdOffset += anchor.delta;
|
|
626
|
-
this.
|
|
639
|
+
this._followAnchor(anchor.delta);
|
|
627
640
|
this.notify(false);
|
|
628
|
-
} else if (isSmoothScroll(this.scrollState) && !
|
|
629
|
-
this.getScrollOffset() - anchor.delta,
|
|
630
|
-
this.scrollState.lastTargetOffset
|
|
631
|
-
)) ;
|
|
641
|
+
} else if (isSmoothScroll(this.scrollState) && !this._landedBeforeAnchor(this.scrollState, anchor.delta)) ;
|
|
632
642
|
else {
|
|
633
|
-
this.
|
|
643
|
+
this._followAnchor(anchor.delta);
|
|
634
644
|
this._scrollToOffset(this.getScrollOffset());
|
|
635
645
|
}
|
|
636
646
|
} else {
|
|
@@ -649,7 +659,8 @@ class Virtualizer {
|
|
|
649
659
|
holdOffset: this._holdOffset,
|
|
650
660
|
scrollOffset: this.scrollOffset,
|
|
651
661
|
pendingWrite: this.pendingWrite,
|
|
652
|
-
clampedMaxAtWrite: ((_a = this._clampedAdjustment) == null ? void 0 : _a.maxAtWrite) ?? null
|
|
662
|
+
clampedMaxAtWrite: ((_a = this._clampedAdjustment) == null ? void 0 : _a.maxAtWrite) ?? null,
|
|
663
|
+
ownWriteAt: this._ownWriteAt
|
|
653
664
|
});
|
|
654
665
|
};
|
|
655
666
|
this._retryClampedAdjustment = () => {
|
|
@@ -915,14 +926,15 @@ class Virtualizer {
|
|
|
915
926
|
this.options.lanes,
|
|
916
927
|
// scrollOffset is measured in the scroll element and the layout total
|
|
917
928
|
// from the list start, so the list ends scrollMargin further down.
|
|
918
|
-
this._getLayoutTotalSize() + this.options.scrollMargin
|
|
929
|
+
this._getLayoutTotalSize() + this.options.scrollMargin,
|
|
930
|
+
this._trailing
|
|
919
931
|
],
|
|
920
|
-
(measurements, outerSize, scrollOffset, lanes, listEnd) => {
|
|
932
|
+
(measurements, outerSize, scrollOffset, lanes, listEnd, trailing) => {
|
|
921
933
|
if (measurements.length === 0 || outerSize === 0) {
|
|
922
934
|
this.range = null;
|
|
923
935
|
return null;
|
|
924
936
|
}
|
|
925
|
-
const maxScrollOffset = Math.max(listEnd - outerSize, 0);
|
|
937
|
+
const maxScrollOffset = Math.max(listEnd + trailing - outerSize, 0);
|
|
926
938
|
this.range = calculateRangeImpl(
|
|
927
939
|
measurements,
|
|
928
940
|
outerSize,
|
|
@@ -1107,6 +1119,9 @@ class Virtualizer {
|
|
|
1107
1119
|
this._noteClampMax();
|
|
1108
1120
|
this._flushHoldIfReady(true);
|
|
1109
1121
|
this._retryClampedAdjustment();
|
|
1122
|
+
} else if (this.options.lanes > 1 && !this.options.useCachedMeasurements && !this.laneAssignments.has(index)) {
|
|
1123
|
+
const item = this.getMeasurements()[index];
|
|
1124
|
+
if (item) this.laneAssignments.set(index, item.lane);
|
|
1110
1125
|
}
|
|
1111
1126
|
};
|
|
1112
1127
|
this.getVirtualItems = utils.memo(
|
|
@@ -1166,6 +1181,11 @@ class Virtualizer {
|
|
|
1166
1181
|
}
|
|
1167
1182
|
return offset;
|
|
1168
1183
|
};
|
|
1184
|
+
this._readTrailing = (elementMax) => {
|
|
1185
|
+
if (elementMax === null) return;
|
|
1186
|
+
const trailing = elementMax + this.getSize() - this._drawnListEnd;
|
|
1187
|
+
this._trailing = trailing > 0 ? trailing : 0;
|
|
1188
|
+
};
|
|
1169
1189
|
this._elementMaxScrollOffset = () => {
|
|
1170
1190
|
const el = this.scrollElement;
|
|
1171
1191
|
if (el === null) return null;
|
|
@@ -1331,13 +1351,17 @@ class Virtualizer {
|
|
|
1331
1351
|
}
|
|
1332
1352
|
this.scrollState = null;
|
|
1333
1353
|
};
|
|
1334
|
-
this.getTotalSize = () =>
|
|
1354
|
+
this.getTotalSize = () => {
|
|
1355
|
+
const total = Math.max(this._getLayoutTotalSize() - this._holdOffset, 0);
|
|
1356
|
+
this._drawnListEnd = total + this.options.scrollMargin;
|
|
1357
|
+
return total;
|
|
1358
|
+
};
|
|
1335
1359
|
this._getLayoutTotalSize = () => {
|
|
1336
1360
|
var _a, _b;
|
|
1337
1361
|
const measurements = this.getMeasurements();
|
|
1338
1362
|
let end;
|
|
1339
1363
|
if (measurements.length === 0) {
|
|
1340
|
-
end = this.options.paddingStart;
|
|
1364
|
+
end = this.options.scrollMargin + this.options.paddingStart;
|
|
1341
1365
|
} else if (this.options.lanes === 1) {
|
|
1342
1366
|
const lastIdx = measurements.length - 1;
|
|
1343
1367
|
const flat = (_a = this._singleLaneMeasurements) == null ? void 0 : _a.flat;
|
|
@@ -1407,6 +1431,14 @@ class Virtualizer {
|
|
|
1407
1431
|
this.scrollState.lastTargetOffset += delta;
|
|
1408
1432
|
}
|
|
1409
1433
|
};
|
|
1434
|
+
this._landedBeforeAnchor = (state, delta) => state.phase !== "queued" && (state.stableFrames > 0 || utils.approxEqual(this.getScrollOffset() - delta, state.lastTargetOffset));
|
|
1435
|
+
this._followAnchor = (delta) => {
|
|
1436
|
+
this._followOffsetTarget(delta);
|
|
1437
|
+
const state = this.scrollState;
|
|
1438
|
+
if ((state == null ? void 0 : state.index) != null && !state.toEnd && this._landedBeforeAnchor(state, delta)) {
|
|
1439
|
+
this.scrollState = null;
|
|
1440
|
+
}
|
|
1441
|
+
};
|
|
1410
1442
|
this.measure = () => {
|
|
1411
1443
|
this.pendingMin = null;
|
|
1412
1444
|
this.itemSizeCache.clear();
|