@tanstack/virtual-core 3.19.12 → 3.19.13
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 +34 -13
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs/index.d.cts +5 -0
- package/dist/esm/index.d.ts +5 -0
- package/dist/esm/index.js +34 -13
- package/dist/esm/index.js.map +1 -1
- package/package.json +1 -1
- package/src/index.ts +43 -8
package/dist/cjs/index.d.cts
CHANGED
|
@@ -104,11 +104,15 @@ export declare class Virtualizer<TScrollElement extends Element | Window, TItemE
|
|
|
104
104
|
private _singleLaneMeasurements;
|
|
105
105
|
itemSizeCache: Map<Key, number>;
|
|
106
106
|
private itemSizeCacheVersion;
|
|
107
|
+
private builtMeasurementOptions;
|
|
108
|
+
private builtItemSizeCacheVersion;
|
|
109
|
+
private pendingResizes;
|
|
107
110
|
private laneAssignments;
|
|
108
111
|
private pendingMin;
|
|
109
112
|
private prevLanes;
|
|
110
113
|
private lanesChangedFlag;
|
|
111
114
|
private lanesSettling;
|
|
115
|
+
private initialMeasurementsCacheApplied;
|
|
112
116
|
private pendingScrollAnchor;
|
|
113
117
|
scrollRect: Rect | null;
|
|
114
118
|
/**
|
|
@@ -186,6 +190,7 @@ export declare class Virtualizer<TScrollElement extends Element | Window, TItemE
|
|
|
186
190
|
*/
|
|
187
191
|
private shouldMeasureDuringScroll;
|
|
188
192
|
measureElement: (node: TItemElement | null) => void;
|
|
193
|
+
private canShiftFromPendingResizes;
|
|
189
194
|
resizeItem: (index: number, size: number) => void;
|
|
190
195
|
getVirtualItems: {
|
|
191
196
|
(): VirtualItem[];
|
package/dist/esm/index.d.ts
CHANGED
|
@@ -104,11 +104,15 @@ export declare class Virtualizer<TScrollElement extends Element | Window, TItemE
|
|
|
104
104
|
private _singleLaneMeasurements;
|
|
105
105
|
itemSizeCache: Map<Key, number>;
|
|
106
106
|
private itemSizeCacheVersion;
|
|
107
|
+
private builtMeasurementOptions;
|
|
108
|
+
private builtItemSizeCacheVersion;
|
|
109
|
+
private pendingResizes;
|
|
107
110
|
private laneAssignments;
|
|
108
111
|
private pendingMin;
|
|
109
112
|
private prevLanes;
|
|
110
113
|
private lanesChangedFlag;
|
|
111
114
|
private lanesSettling;
|
|
115
|
+
private initialMeasurementsCacheApplied;
|
|
112
116
|
private pendingScrollAnchor;
|
|
113
117
|
scrollRect: Rect | null;
|
|
114
118
|
/**
|
|
@@ -186,6 +190,7 @@ export declare class Virtualizer<TScrollElement extends Element | Window, TItemE
|
|
|
186
190
|
*/
|
|
187
191
|
private shouldMeasureDuringScroll;
|
|
188
192
|
measureElement: (node: TItemElement | null) => void;
|
|
193
|
+
private canShiftFromPendingResizes;
|
|
189
194
|
resizeItem: (index: number, size: number) => void;
|
|
190
195
|
getVirtualItems: {
|
|
191
196
|
(): VirtualItem[];
|
package/dist/esm/index.js
CHANGED
|
@@ -202,11 +202,15 @@ class Virtualizer {
|
|
|
202
202
|
this._singleLaneMeasurements = null;
|
|
203
203
|
this.itemSizeCache = /* @__PURE__ */ new Map();
|
|
204
204
|
this.itemSizeCacheVersion = 0;
|
|
205
|
+
this.builtMeasurementOptions = null;
|
|
206
|
+
this.builtItemSizeCacheVersion = -1;
|
|
207
|
+
this.pendingResizes = [];
|
|
205
208
|
this.laneAssignments = /* @__PURE__ */ new Map();
|
|
206
209
|
this.pendingMin = null;
|
|
207
210
|
this.prevLanes = void 0;
|
|
208
211
|
this.lanesChangedFlag = false;
|
|
209
212
|
this.lanesSettling = false;
|
|
213
|
+
this.initialMeasurementsCacheApplied = false;
|
|
210
214
|
this.pendingScrollAnchor = null;
|
|
211
215
|
this.scrollRect = null;
|
|
212
216
|
this.scrollOffset = null;
|
|
@@ -769,23 +773,28 @@ class Virtualizer {
|
|
|
769
773
|
this.isIndexInRange = (index) => index >= 0 && index < this.options.count;
|
|
770
774
|
this.getMeasurements = memo(
|
|
771
775
|
() => [this.getMeasurementOptions(), this.itemSizeCacheVersion],
|
|
772
|
-
({
|
|
773
|
-
count,
|
|
774
|
-
paddingStart,
|
|
775
|
-
scrollMargin,
|
|
776
|
-
getItemKey,
|
|
777
|
-
enabled,
|
|
778
|
-
lanes,
|
|
779
|
-
laneAssignmentMode,
|
|
780
|
-
gap
|
|
781
|
-
}, _itemSizeCacheVersion) => {
|
|
776
|
+
(measurementOptions, itemSizeCacheVersion) => {
|
|
782
777
|
var _a;
|
|
778
|
+
const {
|
|
779
|
+
count,
|
|
780
|
+
paddingStart,
|
|
781
|
+
scrollMargin,
|
|
782
|
+
getItemKey,
|
|
783
|
+
enabled,
|
|
784
|
+
lanes,
|
|
785
|
+
laneAssignmentMode,
|
|
786
|
+
gap
|
|
787
|
+
} = measurementOptions;
|
|
788
|
+
this.builtMeasurementOptions = measurementOptions;
|
|
789
|
+
this.builtItemSizeCacheVersion = itemSizeCacheVersion;
|
|
790
|
+
this.pendingResizes = [];
|
|
783
791
|
const itemSizeCache = this.itemSizeCache;
|
|
784
792
|
if (!enabled) {
|
|
785
793
|
this.measurementsCache = [];
|
|
786
794
|
this._singleLaneMeasurements = null;
|
|
787
795
|
this.itemSizeCache.clear();
|
|
788
796
|
this.laneAssignments.clear();
|
|
797
|
+
this.initialMeasurementsCacheApplied = false;
|
|
789
798
|
return [];
|
|
790
799
|
}
|
|
791
800
|
if (this.laneAssignments.size > count) {
|
|
@@ -804,7 +813,8 @@ class Virtualizer {
|
|
|
804
813
|
this.laneAssignments.clear();
|
|
805
814
|
this.pendingMin = null;
|
|
806
815
|
}
|
|
807
|
-
if (this.measurementsCache.length === 0 && !this.lanesSettling) {
|
|
816
|
+
if (!this.initialMeasurementsCacheApplied && this.measurementsCache.length === 0 && !this.lanesSettling) {
|
|
817
|
+
this.initialMeasurementsCacheApplied = true;
|
|
808
818
|
this.measurementsCache = this.options.initialMeasurementsCache;
|
|
809
819
|
this.measurementsCache.forEach((item) => {
|
|
810
820
|
this.itemSizeCache.set(item.key, item.size);
|
|
@@ -1039,17 +1049,27 @@ class Virtualizer {
|
|
|
1039
1049
|
this.resizeItem(index, this.options.measureElement(node, void 0, this));
|
|
1040
1050
|
}
|
|
1041
1051
|
};
|
|
1052
|
+
this.canShiftFromPendingResizes = () => this.options.lanes === 1 && this._singleLaneMeasurements !== null && this.shouldAdjustScrollPositionOnItemSizeChange === void 0 && !this.lanesChangedFlag && !this.lanesSettling && this.getMeasurementOptions() === this.builtMeasurementOptions && this.itemSizeCacheVersion === this.builtItemSizeCacheVersion + this.pendingResizes.length;
|
|
1042
1053
|
this.resizeItem = (index, size) => {
|
|
1043
1054
|
var _a, _b, _c;
|
|
1044
1055
|
if (!this.isIndexInRange(index)) return;
|
|
1045
|
-
|
|
1056
|
+
let startShift = 0;
|
|
1057
|
+
if ((_a = this._resizeBatch) == null ? void 0 : _a.sync) {
|
|
1058
|
+
if (this.canShiftFromPendingResizes()) {
|
|
1059
|
+
for (const resize of this.pendingResizes) {
|
|
1060
|
+
if (resize.index < index) startShift += resize.delta;
|
|
1061
|
+
}
|
|
1062
|
+
} else {
|
|
1063
|
+
this.getMeasurements();
|
|
1064
|
+
}
|
|
1065
|
+
}
|
|
1046
1066
|
let cachedSize;
|
|
1047
1067
|
let itemStart;
|
|
1048
1068
|
let key;
|
|
1049
1069
|
const flat = (_b = this._singleLaneMeasurements) == null ? void 0 : _b.flat;
|
|
1050
1070
|
if (this.options.lanes === 1 && flat != null) {
|
|
1051
1071
|
key = this.options.getItemKey(index);
|
|
1052
|
-
itemStart = flat[index * 2];
|
|
1072
|
+
itemStart = flat[index * 2] + startShift;
|
|
1053
1073
|
cachedSize = flat[index * 2 + 1];
|
|
1054
1074
|
} else {
|
|
1055
1075
|
const item = this.measurementsCache[index];
|
|
@@ -1099,6 +1119,7 @@ class Virtualizer {
|
|
|
1099
1119
|
}
|
|
1100
1120
|
this.itemSizeCache.set(key, size);
|
|
1101
1121
|
this.itemSizeCacheVersion++;
|
|
1122
|
+
this.pendingResizes.push({ index, delta });
|
|
1102
1123
|
let adjustedSync = false;
|
|
1103
1124
|
if (!this._awaitingCommandReadBack()) {
|
|
1104
1125
|
if (wasAtEnd) {
|