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