@tanstack/virtual-core 3.17.11 → 3.18.0
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 +43 -12
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs/index.d.cts +2 -0
- package/dist/esm/index.d.ts +2 -0
- package/dist/esm/index.js +43 -12
- package/dist/esm/index.js.map +1 -1
- package/package.json +1 -1
- package/src/index.ts +86 -16
package/dist/esm/index.js
CHANGED
|
@@ -449,11 +449,14 @@ class Virtualizer {
|
|
|
449
449
|
);
|
|
450
450
|
this.unsubs.push(
|
|
451
451
|
this.options.observeElementOffset(this, (offset, isScrolling) => {
|
|
452
|
+
var _a2;
|
|
452
453
|
if (isScrolling && this._intendedScrollOffset === null && offset === this.scrollOffset) {
|
|
453
454
|
return;
|
|
454
455
|
}
|
|
455
456
|
if (this._intendedScrollOffset !== null && Math.abs(offset - this._intendedScrollOffset) < 1.5) {
|
|
456
457
|
offset = this._intendedScrollOffset;
|
|
458
|
+
} else if (((_a2 = this.scrollState) == null ? void 0 : _a2.index) != null && this.scrollState.hasReachedTarget && !approxEqual(offset, this.scrollState.lastTargetOffset) && !approxEqual(offset, this.getScrollStateTarget(this.scrollState)) && (this._clampedAdjustment === null || Math.abs(offset - this._clampedAdjustment.maxAtWrite) >= 1.5)) {
|
|
459
|
+
this.scrollState = null;
|
|
457
460
|
}
|
|
458
461
|
this._intendedScrollOffset = null;
|
|
459
462
|
if (this._clampedAdjustment !== null && Math.abs(offset - this._clampedAdjustment.maxAtWrite) >= 1.5) {
|
|
@@ -888,7 +891,7 @@ class Virtualizer {
|
|
|
888
891
|
this.observer.observe(node);
|
|
889
892
|
this.elementsCache.set(key, node);
|
|
890
893
|
}
|
|
891
|
-
if ((!this.isScrolling || this.scrollState) && this.shouldMeasureDuringScroll(index)) {
|
|
894
|
+
if (node.isConnected && (!this.isScrolling || this.scrollState) && this.shouldMeasureDuringScroll(index)) {
|
|
892
895
|
this.resizeItem(index, this.options.measureElement(node, void 0, this));
|
|
893
896
|
}
|
|
894
897
|
};
|
|
@@ -1047,7 +1050,9 @@ class Virtualizer {
|
|
|
1047
1050
|
}
|
|
1048
1051
|
}
|
|
1049
1052
|
if (align === "end" && index === this.options.count - 1) {
|
|
1050
|
-
|
|
1053
|
+
const maxOffset = this.getMaxScrollOffset();
|
|
1054
|
+
const toOffset2 = maxOffset - this.options.paddingEnd + this.options.scrollPaddingEnd;
|
|
1055
|
+
return [Math.max(Math.min(toOffset2, maxOffset), 0), align];
|
|
1051
1056
|
}
|
|
1052
1057
|
const toOffset = align === "end" ? item.end + this.options.scrollPaddingEnd : item.start - this.options.scrollPaddingStart;
|
|
1053
1058
|
return [
|
|
@@ -1065,7 +1070,8 @@ class Virtualizer {
|
|
|
1065
1070
|
behavior,
|
|
1066
1071
|
startedAt: now,
|
|
1067
1072
|
lastTargetOffset: offset,
|
|
1068
|
-
stableFrames: 0
|
|
1073
|
+
stableFrames: 0,
|
|
1074
|
+
hasReachedTarget: false
|
|
1069
1075
|
};
|
|
1070
1076
|
this._scrollToOffset(offset, { adjustments: void 0, behavior });
|
|
1071
1077
|
this.scheduleScrollReconcile();
|
|
@@ -1088,7 +1094,8 @@ class Virtualizer {
|
|
|
1088
1094
|
behavior,
|
|
1089
1095
|
startedAt: now,
|
|
1090
1096
|
lastTargetOffset: offset,
|
|
1091
|
-
stableFrames: 0
|
|
1097
|
+
stableFrames: 0,
|
|
1098
|
+
hasReachedTarget: approxEqual(offset, this.getScrollOffset())
|
|
1092
1099
|
};
|
|
1093
1100
|
this._scrollToOffset(offset, { adjustments: void 0, behavior });
|
|
1094
1101
|
this.scheduleScrollReconcile();
|
|
@@ -1102,23 +1109,41 @@ class Virtualizer {
|
|
|
1102
1109
|
behavior,
|
|
1103
1110
|
startedAt: now,
|
|
1104
1111
|
lastTargetOffset: offset,
|
|
1105
|
-
stableFrames: 0
|
|
1112
|
+
stableFrames: 0,
|
|
1113
|
+
hasReachedTarget: false
|
|
1106
1114
|
};
|
|
1107
1115
|
this._scrollToOffset(offset, { adjustments: void 0, behavior });
|
|
1108
1116
|
this.scheduleScrollReconcile();
|
|
1109
1117
|
};
|
|
1110
1118
|
this.scrollToEnd = ({ behavior = "auto" } = {}) => {
|
|
1111
1119
|
if (this.options.count > 0) {
|
|
1112
|
-
this.
|
|
1120
|
+
this._iosDeferredAdjustment = 0;
|
|
1121
|
+
const offset = Math.max(this.getMaxScrollOffset(), 0);
|
|
1122
|
+
this.scrollState = {
|
|
1123
|
+
index: this.options.count - 1,
|
|
1113
1124
|
align: "end",
|
|
1114
|
-
behavior
|
|
1115
|
-
|
|
1125
|
+
behavior,
|
|
1126
|
+
toEnd: true,
|
|
1127
|
+
startedAt: this.now(),
|
|
1128
|
+
lastTargetOffset: offset,
|
|
1129
|
+
stableFrames: 0,
|
|
1130
|
+
hasReachedTarget: approxEqual(offset, this.getScrollOffset())
|
|
1131
|
+
};
|
|
1132
|
+
this._scrollToOffset(offset, { adjustments: void 0, behavior });
|
|
1133
|
+
this.scheduleScrollReconcile();
|
|
1116
1134
|
return;
|
|
1117
1135
|
}
|
|
1118
1136
|
this.scrollToOffset(Math.max(this.getTotalSize() - this.getSize(), 0), {
|
|
1119
1137
|
behavior
|
|
1120
1138
|
});
|
|
1121
1139
|
};
|
|
1140
|
+
this.cancelScroll = () => {
|
|
1141
|
+
if (this.rafId != null && this.targetWindow) {
|
|
1142
|
+
this.targetWindow.cancelAnimationFrame(this.rafId);
|
|
1143
|
+
this.rafId = null;
|
|
1144
|
+
}
|
|
1145
|
+
this.scrollState = null;
|
|
1146
|
+
};
|
|
1122
1147
|
this.getTotalSize = () => {
|
|
1123
1148
|
var _a, _b;
|
|
1124
1149
|
const measurements = this.getMeasurements();
|
|
@@ -1224,6 +1249,10 @@ class Virtualizer {
|
|
|
1224
1249
|
this.reconcileScroll();
|
|
1225
1250
|
});
|
|
1226
1251
|
}
|
|
1252
|
+
getScrollStateTarget(state) {
|
|
1253
|
+
const offsetInfo = state.toEnd ? [Math.max(this.getMaxScrollOffset(), 0)] : state.index != null ? this.getOffsetForIndex(state.index, state.align) : void 0;
|
|
1254
|
+
return offsetInfo ? offsetInfo[0] : state.lastTargetOffset;
|
|
1255
|
+
}
|
|
1227
1256
|
reconcileScroll() {
|
|
1228
1257
|
if (!this.scrollState) return;
|
|
1229
1258
|
const el = this.scrollElement;
|
|
@@ -1233,11 +1262,11 @@ class Virtualizer {
|
|
|
1233
1262
|
this.scrollState = null;
|
|
1234
1263
|
return;
|
|
1235
1264
|
}
|
|
1236
|
-
const
|
|
1237
|
-
const
|
|
1238
|
-
const STABLE_FRAMES = 1;
|
|
1265
|
+
const targetOffset = this.getScrollStateTarget(this.scrollState);
|
|
1266
|
+
const STABLE_FRAMES = this.scrollState.index == null ? 1 : this.options.useAnimationFrameWithResizeObserver ? 3 : 2;
|
|
1239
1267
|
const targetChanged = targetOffset !== this.scrollState.lastTargetOffset;
|
|
1240
1268
|
if (!targetChanged && approxEqual(targetOffset, this.getScrollOffset())) {
|
|
1269
|
+
this.scrollState.hasReachedTarget = true;
|
|
1241
1270
|
this.scrollState.stableFrames++;
|
|
1242
1271
|
if (this.scrollState.stableFrames >= STABLE_FRAMES) {
|
|
1243
1272
|
if (this.getScrollOffset() !== targetOffset) {
|
|
@@ -1256,7 +1285,9 @@ class Virtualizer {
|
|
|
1256
1285
|
const distance = Math.abs(targetOffset - this.getScrollOffset());
|
|
1257
1286
|
const keepSmooth = this.scrollState.behavior === "smooth" && distance > viewport;
|
|
1258
1287
|
this.scrollState.lastTargetOffset = targetOffset;
|
|
1259
|
-
if (
|
|
1288
|
+
if (keepSmooth) {
|
|
1289
|
+
this.scrollState.hasReachedTarget = false;
|
|
1290
|
+
} else {
|
|
1260
1291
|
this.scrollState.behavior = "auto";
|
|
1261
1292
|
}
|
|
1262
1293
|
this._scrollToOffset(targetOffset, {
|