@tanstack/virtual-core 3.19.15 → 3.19.17
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 +36 -2
- 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 +36 -2
- package/dist/esm/index.js.map +1 -1
- package/package.json +1 -1
- package/src/index.ts +63 -6
package/dist/cjs/index.d.cts
CHANGED
|
@@ -103,6 +103,7 @@ export declare class Virtualizer<TScrollElement extends Element | Window, TItemE
|
|
|
103
103
|
measurementsCache: Array<VirtualItem>;
|
|
104
104
|
private _singleLaneMeasurements;
|
|
105
105
|
itemSizeCache: Map<Key, number>;
|
|
106
|
+
private elementKeys;
|
|
106
107
|
private itemSizeCacheVersion;
|
|
107
108
|
private builtMeasurementOptions;
|
|
108
109
|
private builtItemSizeCacheVersion;
|
|
@@ -196,6 +197,7 @@ export declare class Virtualizer<TScrollElement extends Element | Window, TItemE
|
|
|
196
197
|
private shouldMeasureDuringScroll;
|
|
197
198
|
private dropDisconnected;
|
|
198
199
|
measureElement: (node: TItemElement | null) => void;
|
|
200
|
+
private onlyPendingResizesSinceBuild;
|
|
199
201
|
private canShiftFromPendingResizes;
|
|
200
202
|
resizeItem: (index: number, size: number) => void;
|
|
201
203
|
getVirtualItems: {
|
package/dist/esm/index.d.ts
CHANGED
|
@@ -103,6 +103,7 @@ export declare class Virtualizer<TScrollElement extends Element | Window, TItemE
|
|
|
103
103
|
measurementsCache: Array<VirtualItem>;
|
|
104
104
|
private _singleLaneMeasurements;
|
|
105
105
|
itemSizeCache: Map<Key, number>;
|
|
106
|
+
private elementKeys;
|
|
106
107
|
private itemSizeCacheVersion;
|
|
107
108
|
private builtMeasurementOptions;
|
|
108
109
|
private builtItemSizeCacheVersion;
|
|
@@ -196,6 +197,7 @@ export declare class Virtualizer<TScrollElement extends Element | Window, TItemE
|
|
|
196
197
|
private shouldMeasureDuringScroll;
|
|
197
198
|
private dropDisconnected;
|
|
198
199
|
measureElement: (node: TItemElement | null) => void;
|
|
200
|
+
private onlyPendingResizesSinceBuild;
|
|
199
201
|
private canShiftFromPendingResizes;
|
|
200
202
|
resizeItem: (index: number, size: number) => void;
|
|
201
203
|
getVirtualItems: {
|
package/dist/esm/index.js
CHANGED
|
@@ -201,6 +201,7 @@ class Virtualizer {
|
|
|
201
201
|
this.measurementsCache = [];
|
|
202
202
|
this._singleLaneMeasurements = null;
|
|
203
203
|
this.itemSizeCache = /* @__PURE__ */ new Map();
|
|
204
|
+
this.elementKeys = /* @__PURE__ */ new WeakMap();
|
|
204
205
|
this.itemSizeCacheVersion = 0;
|
|
205
206
|
this.builtMeasurementOptions = null;
|
|
206
207
|
this.builtItemSizeCacheVersion = -1;
|
|
@@ -359,6 +360,16 @@ class Virtualizer {
|
|
|
359
360
|
var _a;
|
|
360
361
|
pendingObservations.delete(target);
|
|
361
362
|
(_a = get()) == null ? void 0 : _a.unobserve(target);
|
|
363
|
+
},
|
|
364
|
+
isDelivering: () => delivering,
|
|
365
|
+
asDelivery: (fn) => {
|
|
366
|
+
const prev = delivering;
|
|
367
|
+
delivering = true;
|
|
368
|
+
try {
|
|
369
|
+
fn();
|
|
370
|
+
} finally {
|
|
371
|
+
delivering = prev;
|
|
372
|
+
}
|
|
362
373
|
}
|
|
363
374
|
};
|
|
364
375
|
})();
|
|
@@ -551,12 +562,15 @@ class Virtualizer {
|
|
|
551
562
|
this.elementsCache.forEach((cached) => {
|
|
552
563
|
this.observer.observe(cached);
|
|
553
564
|
});
|
|
565
|
+
let observing = false;
|
|
554
566
|
this.unsubs.push(
|
|
555
567
|
this.options.observeElementRect(this, (rect) => {
|
|
556
568
|
this.scrollRect = rect;
|
|
557
569
|
this.maybeNotify();
|
|
570
|
+
if (observing) this.measureElement(null);
|
|
558
571
|
})
|
|
559
572
|
);
|
|
573
|
+
observing = true;
|
|
560
574
|
this.unsubs.push(
|
|
561
575
|
this.options.observeElementOffset(this, (offset, isScrolling) => {
|
|
562
576
|
var _a2, _b, _c, _d;
|
|
@@ -1093,6 +1107,19 @@ class Virtualizer {
|
|
|
1093
1107
|
}
|
|
1094
1108
|
return;
|
|
1095
1109
|
}
|
|
1110
|
+
if (!node.isConnected && !node.getAttribute(this.options.indexAttribute)) {
|
|
1111
|
+
const delivering = this.observer.isDelivering();
|
|
1112
|
+
queueMicrotask(() => {
|
|
1113
|
+
if (!node.getAttribute(this.options.indexAttribute)) {
|
|
1114
|
+
this.indexFromElement(node);
|
|
1115
|
+
} else if (delivering) {
|
|
1116
|
+
this.observer.asDelivery(() => this.measureElement(node));
|
|
1117
|
+
} else {
|
|
1118
|
+
this.measureElement(node);
|
|
1119
|
+
}
|
|
1120
|
+
});
|
|
1121
|
+
return;
|
|
1122
|
+
}
|
|
1096
1123
|
const index = this.indexFromElement(node);
|
|
1097
1124
|
if (!this.isIndexInRange(index)) return;
|
|
1098
1125
|
const key = this.options.getItemKey(index);
|
|
@@ -1101,18 +1128,25 @@ class Virtualizer {
|
|
|
1101
1128
|
if (prevNode) {
|
|
1102
1129
|
this.observer.unobserve(prevNode);
|
|
1103
1130
|
}
|
|
1131
|
+
const prevKey = this.elementKeys.get(node);
|
|
1132
|
+
if (prevKey !== void 0 && this.elementsCache.get(prevKey) === node) {
|
|
1133
|
+
this.elementsCache.delete(prevKey);
|
|
1134
|
+
this.observer.unobserve(node);
|
|
1135
|
+
}
|
|
1104
1136
|
this.observer.observe(node);
|
|
1105
1137
|
this.elementsCache.set(key, node);
|
|
1138
|
+
this.elementKeys.set(node, key);
|
|
1106
1139
|
}
|
|
1107
1140
|
if (node.isConnected && (!this.isScrolling || this.scrollState) && this.shouldMeasureDuringScroll(index)) {
|
|
1108
1141
|
this.resizeItem(index, this.options.measureElement(node, void 0, this));
|
|
1109
1142
|
}
|
|
1110
1143
|
};
|
|
1111
|
-
this.
|
|
1144
|
+
this.onlyPendingResizesSinceBuild = () => this.itemSizeCacheVersion === this.builtItemSizeCacheVersion + this.pendingResizes.length;
|
|
1145
|
+
this.canShiftFromPendingResizes = () => this.options.lanes === 1 && this._singleLaneMeasurements !== null && this.shouldAdjustScrollPositionOnItemSizeChange === void 0 && !this.lanesChangedFlag && !this.lanesSettling && this.getMeasurementOptions() === this.builtMeasurementOptions && this.onlyPendingResizesSinceBuild();
|
|
1112
1146
|
this.resizeItem = (index, size) => {
|
|
1113
1147
|
var _a, _b, _c;
|
|
1114
1148
|
if (!this.isIndexInRange(index)) return;
|
|
1115
|
-
if (this.getMeasurementOptions() !== this.builtMeasurementOptions) {
|
|
1149
|
+
if (this.getMeasurementOptions() !== this.builtMeasurementOptions || !this.onlyPendingResizesSinceBuild()) {
|
|
1116
1150
|
this.getMeasurements();
|
|
1117
1151
|
}
|
|
1118
1152
|
let startShift = 0;
|