@tanstack/virtual-core 3.17.10 → 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 +50 -15
- 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 +51 -16
- package/dist/esm/index.js.map +1 -1
- package/package.json +1 -1
- package/src/index.ts +102 -17
package/dist/esm/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { createLazyMeasurementsView, getMeasurementKey } from "./lazy-measurements.js";
|
|
2
|
-
import { memo,
|
|
2
|
+
import { memo, approxEqual, notUndefined, debounce } from "./utils.js";
|
|
3
3
|
let _isIOSResult;
|
|
4
4
|
const isIOSWebKit = () => {
|
|
5
5
|
if (_isIOSResult !== void 0) return _isIOSResult;
|
|
@@ -94,7 +94,7 @@ const observeOffset = (instance, cb, readOffset) => {
|
|
|
94
94
|
let offset = 0;
|
|
95
95
|
const fallback = registerScrollendEvent ? null : debounce(
|
|
96
96
|
targetWindow,
|
|
97
|
-
() => cb(
|
|
97
|
+
() => cb(readOffset(element), false),
|
|
98
98
|
instance.options.isScrollingResetDelay
|
|
99
99
|
);
|
|
100
100
|
const createHandler = (isScrolling) => () => {
|
|
@@ -424,7 +424,7 @@ class Virtualizer {
|
|
|
424
424
|
};
|
|
425
425
|
};
|
|
426
426
|
this._willUpdate = () => {
|
|
427
|
-
var _a;
|
|
427
|
+
var _a, _b;
|
|
428
428
|
const scrollElement = this.options.enabled ? this.options.getScrollElement() : null;
|
|
429
429
|
if (this.scrollElement !== scrollElement) {
|
|
430
430
|
this.cleanup();
|
|
@@ -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) {
|
|
@@ -526,7 +529,11 @@ class Virtualizer {
|
|
|
526
529
|
if (anchorDelta !== 0) {
|
|
527
530
|
this._iosDeferredAdjustment += anchorDelta;
|
|
528
531
|
}
|
|
529
|
-
} else
|
|
532
|
+
} else if (((_b = this.scrollState) == null ? void 0 : _b.behavior) === "smooth" && !approxEqual(
|
|
533
|
+
this.getScrollOffset() - anchorDelta,
|
|
534
|
+
this.scrollState.lastTargetOffset
|
|
535
|
+
)) ;
|
|
536
|
+
else {
|
|
530
537
|
this._scrollToOffset(this.getScrollOffset(), {
|
|
531
538
|
adjustments: void 0,
|
|
532
539
|
behavior: void 0
|
|
@@ -884,7 +891,7 @@ class Virtualizer {
|
|
|
884
891
|
this.observer.observe(node);
|
|
885
892
|
this.elementsCache.set(key, node);
|
|
886
893
|
}
|
|
887
|
-
if ((!this.isScrolling || this.scrollState) && this.shouldMeasureDuringScroll(index)) {
|
|
894
|
+
if (node.isConnected && (!this.isScrolling || this.scrollState) && this.shouldMeasureDuringScroll(index)) {
|
|
888
895
|
this.resizeItem(index, this.options.measureElement(node, void 0, this));
|
|
889
896
|
}
|
|
890
897
|
};
|
|
@@ -1043,7 +1050,9 @@ class Virtualizer {
|
|
|
1043
1050
|
}
|
|
1044
1051
|
}
|
|
1045
1052
|
if (align === "end" && index === this.options.count - 1) {
|
|
1046
|
-
|
|
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];
|
|
1047
1056
|
}
|
|
1048
1057
|
const toOffset = align === "end" ? item.end + this.options.scrollPaddingEnd : item.start - this.options.scrollPaddingStart;
|
|
1049
1058
|
return [
|
|
@@ -1061,7 +1070,8 @@ class Virtualizer {
|
|
|
1061
1070
|
behavior,
|
|
1062
1071
|
startedAt: now,
|
|
1063
1072
|
lastTargetOffset: offset,
|
|
1064
|
-
stableFrames: 0
|
|
1073
|
+
stableFrames: 0,
|
|
1074
|
+
hasReachedTarget: false
|
|
1065
1075
|
};
|
|
1066
1076
|
this._scrollToOffset(offset, { adjustments: void 0, behavior });
|
|
1067
1077
|
this.scheduleScrollReconcile();
|
|
@@ -1084,7 +1094,8 @@ class Virtualizer {
|
|
|
1084
1094
|
behavior,
|
|
1085
1095
|
startedAt: now,
|
|
1086
1096
|
lastTargetOffset: offset,
|
|
1087
|
-
stableFrames: 0
|
|
1097
|
+
stableFrames: 0,
|
|
1098
|
+
hasReachedTarget: approxEqual(offset, this.getScrollOffset())
|
|
1088
1099
|
};
|
|
1089
1100
|
this._scrollToOffset(offset, { adjustments: void 0, behavior });
|
|
1090
1101
|
this.scheduleScrollReconcile();
|
|
@@ -1098,23 +1109,41 @@ class Virtualizer {
|
|
|
1098
1109
|
behavior,
|
|
1099
1110
|
startedAt: now,
|
|
1100
1111
|
lastTargetOffset: offset,
|
|
1101
|
-
stableFrames: 0
|
|
1112
|
+
stableFrames: 0,
|
|
1113
|
+
hasReachedTarget: false
|
|
1102
1114
|
};
|
|
1103
1115
|
this._scrollToOffset(offset, { adjustments: void 0, behavior });
|
|
1104
1116
|
this.scheduleScrollReconcile();
|
|
1105
1117
|
};
|
|
1106
1118
|
this.scrollToEnd = ({ behavior = "auto" } = {}) => {
|
|
1107
1119
|
if (this.options.count > 0) {
|
|
1108
|
-
this.
|
|
1120
|
+
this._iosDeferredAdjustment = 0;
|
|
1121
|
+
const offset = Math.max(this.getMaxScrollOffset(), 0);
|
|
1122
|
+
this.scrollState = {
|
|
1123
|
+
index: this.options.count - 1,
|
|
1109
1124
|
align: "end",
|
|
1110
|
-
behavior
|
|
1111
|
-
|
|
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();
|
|
1112
1134
|
return;
|
|
1113
1135
|
}
|
|
1114
1136
|
this.scrollToOffset(Math.max(this.getTotalSize() - this.getSize(), 0), {
|
|
1115
1137
|
behavior
|
|
1116
1138
|
});
|
|
1117
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
|
+
};
|
|
1118
1147
|
this.getTotalSize = () => {
|
|
1119
1148
|
var _a, _b;
|
|
1120
1149
|
const measurements = this.getMeasurements();
|
|
@@ -1220,6 +1249,10 @@ class Virtualizer {
|
|
|
1220
1249
|
this.reconcileScroll();
|
|
1221
1250
|
});
|
|
1222
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
|
+
}
|
|
1223
1256
|
reconcileScroll() {
|
|
1224
1257
|
if (!this.scrollState) return;
|
|
1225
1258
|
const el = this.scrollElement;
|
|
@@ -1229,11 +1262,11 @@ class Virtualizer {
|
|
|
1229
1262
|
this.scrollState = null;
|
|
1230
1263
|
return;
|
|
1231
1264
|
}
|
|
1232
|
-
const
|
|
1233
|
-
const
|
|
1234
|
-
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;
|
|
1235
1267
|
const targetChanged = targetOffset !== this.scrollState.lastTargetOffset;
|
|
1236
1268
|
if (!targetChanged && approxEqual(targetOffset, this.getScrollOffset())) {
|
|
1269
|
+
this.scrollState.hasReachedTarget = true;
|
|
1237
1270
|
this.scrollState.stableFrames++;
|
|
1238
1271
|
if (this.scrollState.stableFrames >= STABLE_FRAMES) {
|
|
1239
1272
|
if (this.getScrollOffset() !== targetOffset) {
|
|
@@ -1252,7 +1285,9 @@ class Virtualizer {
|
|
|
1252
1285
|
const distance = Math.abs(targetOffset - this.getScrollOffset());
|
|
1253
1286
|
const keepSmooth = this.scrollState.behavior === "smooth" && distance > viewport;
|
|
1254
1287
|
this.scrollState.lastTargetOffset = targetOffset;
|
|
1255
|
-
if (
|
|
1288
|
+
if (keepSmooth) {
|
|
1289
|
+
this.scrollState.hasReachedTarget = false;
|
|
1290
|
+
} else {
|
|
1256
1291
|
this.scrollState.behavior = "auto";
|
|
1257
1292
|
}
|
|
1258
1293
|
this._scrollToOffset(targetOffset, {
|