@tanstack/virtual-core 3.19.0 → 3.19.1
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 -14
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/esm/index.js +45 -14
- package/dist/esm/index.js.map +1 -1
- package/package.json +1 -1
- package/src/index.ts +72 -11
package/dist/cjs/index.cjs
CHANGED
|
@@ -467,10 +467,24 @@ class Virtualizer {
|
|
|
467
467
|
}
|
|
468
468
|
if (this._intendedScrollOffset !== null && Math.abs(offset - this._intendedScrollOffset) < 1.5) {
|
|
469
469
|
offset = this._intendedScrollOffset;
|
|
470
|
-
} else if (((_a2 = this.scrollState) == null ? void 0 : _a2.index) != null &&
|
|
470
|
+
} 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
|
+
// the user's, even before reconcile saw the target reached (the
|
|
472
|
+
// target may keep moving, or iOS ignored the write under a
|
|
473
|
+
// finger). A write the browser clamped because the sizer hasn't
|
|
474
|
+
// grown yet reads back at the max, which is also where the fresh
|
|
475
|
+
// target clamps, so the check below keeps it reconciling (#1294).
|
|
476
|
+
// Not when rows above the target shrink before the read-back and
|
|
477
|
+
// pull the target below the new max: the read-back then looks
|
|
478
|
+
// like the user and the scroll stops at the max. That needs the
|
|
479
|
+
// sizer re-rendered before the scroll event, which browsers have
|
|
480
|
+
// not been seen to do (pinned by a `.fails` test).
|
|
481
|
+
// A smooth scroll's own animation events look like a user's, so
|
|
482
|
+
// it only yields once it has reached the target.
|
|
483
|
+
(this.scrollState.hasReachedTarget || !this.scrollState.startedSmooth) && !utils.approxEqual(offset, this.scrollState.lastTargetOffset) && !utils.approxEqual(offset, this.getScrollStateTarget(this.scrollState)) && (this._clampedAdjustment === null || Math.abs(offset - this._clampedAdjustment.maxAtWrite) >= 1.5)) {
|
|
471
484
|
this.scrollState = null;
|
|
472
485
|
}
|
|
473
486
|
this._intendedScrollOffset = null;
|
|
487
|
+
if (this.scrollState) this.scrollState.writtenOffset = null;
|
|
474
488
|
if (this._clampedAdjustment !== null && Math.abs(offset - this._clampedAdjustment.maxAtWrite) >= 1.5) {
|
|
475
489
|
this._clampedAdjustment = null;
|
|
476
490
|
}
|
|
@@ -910,7 +924,7 @@ class Virtualizer {
|
|
|
910
924
|
}
|
|
911
925
|
};
|
|
912
926
|
this.resizeItem = (index, size) => {
|
|
913
|
-
var _a, _b, _c, _d, _e;
|
|
927
|
+
var _a, _b, _c, _d, _e, _f;
|
|
914
928
|
if (!this.isIndexInRange(index)) return;
|
|
915
929
|
if ((_a = this._resizeBatch) == null ? void 0 : _a.sync) this.getMeasurements();
|
|
916
930
|
let cachedSize;
|
|
@@ -969,17 +983,23 @@ class Virtualizer {
|
|
|
969
983
|
}
|
|
970
984
|
this.itemSizeCache.set(key, size);
|
|
971
985
|
this.itemSizeCacheVersion++;
|
|
986
|
+
const awaitingCommandReadBack = ((_e = this.scrollState) == null ? void 0 : _e.writtenOffset) != null && !utils.approxEqual(
|
|
987
|
+
this.scrollState.writtenOffset,
|
|
988
|
+
this.getScrollOffset() + this.scrollAdjustments
|
|
989
|
+
);
|
|
972
990
|
let adjustedSync = false;
|
|
973
|
-
if (
|
|
974
|
-
|
|
975
|
-
this.
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
991
|
+
if (!awaitingCommandReadBack) {
|
|
992
|
+
if (wasAtEnd) {
|
|
993
|
+
adjustedSync = this.applyScrollAdjustment(
|
|
994
|
+
this.getTotalSize() - prevTotalSize
|
|
995
|
+
);
|
|
996
|
+
} else if (shouldAdjustScroll) {
|
|
997
|
+
adjustedSync = this.applyScrollAdjustment(delta);
|
|
998
|
+
}
|
|
979
999
|
}
|
|
980
1000
|
if (this._resizeBatch) {
|
|
981
1001
|
this._resizeBatch.notify = true;
|
|
982
|
-
(
|
|
1002
|
+
(_f = this._resizeBatch).sync || (_f.sync = adjustedSync);
|
|
983
1003
|
return;
|
|
984
1004
|
}
|
|
985
1005
|
this.notify(adjustedSync);
|
|
@@ -1091,7 +1111,8 @@ class Virtualizer {
|
|
|
1091
1111
|
startedAt: now,
|
|
1092
1112
|
lastTargetOffset: offset,
|
|
1093
1113
|
stableFrames: 0,
|
|
1094
|
-
hasReachedTarget: false
|
|
1114
|
+
hasReachedTarget: false,
|
|
1115
|
+
startedSmooth: behavior === "smooth"
|
|
1095
1116
|
};
|
|
1096
1117
|
this._scrollToOffset(offset, { adjustments: void 0, behavior });
|
|
1097
1118
|
this.scheduleScrollReconcile();
|
|
@@ -1115,13 +1136,18 @@ class Virtualizer {
|
|
|
1115
1136
|
startedAt: now,
|
|
1116
1137
|
lastTargetOffset: offset,
|
|
1117
1138
|
stableFrames: 0,
|
|
1118
|
-
hasReachedTarget: utils.approxEqual(offset, this.getScrollOffset())
|
|
1139
|
+
hasReachedTarget: utils.approxEqual(offset, this.getScrollOffset()),
|
|
1140
|
+
startedSmooth: behavior === "smooth"
|
|
1119
1141
|
};
|
|
1120
1142
|
this._scrollToOffset(offset, { adjustments: void 0, behavior });
|
|
1121
1143
|
this.scheduleScrollReconcile();
|
|
1122
1144
|
};
|
|
1123
1145
|
this.scrollBy = (delta, { behavior = "auto" } = {}) => {
|
|
1124
|
-
|
|
1146
|
+
var _a;
|
|
1147
|
+
const offset = this.getOffsetForAlignment(
|
|
1148
|
+
(((_a = this.scrollState) == null ? void 0 : _a.writtenOffset) ?? this.getScrollOffset()) + delta,
|
|
1149
|
+
"start"
|
|
1150
|
+
);
|
|
1125
1151
|
const now = this.now();
|
|
1126
1152
|
this.scrollState = {
|
|
1127
1153
|
index: null,
|
|
@@ -1130,7 +1156,8 @@ class Virtualizer {
|
|
|
1130
1156
|
startedAt: now,
|
|
1131
1157
|
lastTargetOffset: offset,
|
|
1132
1158
|
stableFrames: 0,
|
|
1133
|
-
hasReachedTarget: false
|
|
1159
|
+
hasReachedTarget: false,
|
|
1160
|
+
startedSmooth: behavior === "smooth"
|
|
1134
1161
|
};
|
|
1135
1162
|
this._scrollToOffset(offset, { adjustments: void 0, behavior });
|
|
1136
1163
|
this.scheduleScrollReconcile();
|
|
@@ -1147,7 +1174,8 @@ class Virtualizer {
|
|
|
1147
1174
|
startedAt: this.now(),
|
|
1148
1175
|
lastTargetOffset: offset,
|
|
1149
1176
|
stableFrames: 0,
|
|
1150
|
-
hasReachedTarget: utils.approxEqual(offset, this.getScrollOffset())
|
|
1177
|
+
hasReachedTarget: utils.approxEqual(offset, this.getScrollOffset()),
|
|
1178
|
+
startedSmooth: behavior === "smooth"
|
|
1151
1179
|
};
|
|
1152
1180
|
this._scrollToOffset(offset, { adjustments: void 0, behavior });
|
|
1153
1181
|
this.scheduleScrollReconcile();
|
|
@@ -1218,6 +1246,9 @@ class Virtualizer {
|
|
|
1218
1246
|
behavior
|
|
1219
1247
|
}) => {
|
|
1220
1248
|
this._intendedScrollOffset = offset + (adjustments ?? 0);
|
|
1249
|
+
if (this.scrollState) {
|
|
1250
|
+
this.scrollState.writtenOffset = behavior === "smooth" ? null : this._intendedScrollOffset;
|
|
1251
|
+
}
|
|
1221
1252
|
this.options.scrollToFn(offset, { behavior, adjustments }, this);
|
|
1222
1253
|
};
|
|
1223
1254
|
this.measure = () => {
|