@tanstack/virtual-core 3.19.14 → 3.19.15
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 +25 -7
- 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 +25 -7
- package/dist/esm/index.js.map +1 -1
- package/package.json +1 -1
- package/src/index.ts +42 -7
package/dist/cjs/index.d.cts
CHANGED
|
@@ -144,6 +144,7 @@ export declare class Virtualizer<TScrollElement extends Element | Window, TItemE
|
|
|
144
144
|
shouldAdjustScrollPositionOnItemSizeChange: undefined | ((item: VirtualItem, delta: number, instance: Virtualizer<TScrollElement, TItemElement>) => boolean);
|
|
145
145
|
elementsCache: Map<Key, TItemElement>;
|
|
146
146
|
private _resizeBatch;
|
|
147
|
+
private _dropQueued;
|
|
147
148
|
private now;
|
|
148
149
|
private observer;
|
|
149
150
|
range: {
|
|
@@ -193,6 +194,7 @@ export declare class Virtualizer<TScrollElement extends Element | Window, TItemE
|
|
|
193
194
|
* to prevent items far from the target from pushing it away.
|
|
194
195
|
*/
|
|
195
196
|
private shouldMeasureDuringScroll;
|
|
197
|
+
private dropDisconnected;
|
|
196
198
|
measureElement: (node: TItemElement | null) => void;
|
|
197
199
|
private canShiftFromPendingResizes;
|
|
198
200
|
resizeItem: (index: number, size: number) => void;
|
package/dist/esm/index.d.ts
CHANGED
|
@@ -144,6 +144,7 @@ export declare class Virtualizer<TScrollElement extends Element | Window, TItemE
|
|
|
144
144
|
shouldAdjustScrollPositionOnItemSizeChange: undefined | ((item: VirtualItem, delta: number, instance: Virtualizer<TScrollElement, TItemElement>) => boolean);
|
|
145
145
|
elementsCache: Map<Key, TItemElement>;
|
|
146
146
|
private _resizeBatch;
|
|
147
|
+
private _dropQueued;
|
|
147
148
|
private now;
|
|
148
149
|
private observer;
|
|
149
150
|
range: {
|
|
@@ -193,6 +194,7 @@ export declare class Virtualizer<TScrollElement extends Element | Window, TItemE
|
|
|
193
194
|
* to prevent items far from the target from pushing it away.
|
|
194
195
|
*/
|
|
195
196
|
private shouldMeasureDuringScroll;
|
|
197
|
+
private dropDisconnected;
|
|
196
198
|
measureElement: (node: TItemElement | null) => void;
|
|
197
199
|
private canShiftFromPendingResizes;
|
|
198
200
|
resizeItem: (index: number, size: number) => void;
|
package/dist/esm/index.js
CHANGED
|
@@ -259,6 +259,7 @@ class Virtualizer {
|
|
|
259
259
|
this._clampedAdjustment = null;
|
|
260
260
|
this.elementsCache = /* @__PURE__ */ new Map();
|
|
261
261
|
this._resizeBatch = null;
|
|
262
|
+
this._dropQueued = false;
|
|
262
263
|
this.now = () => {
|
|
263
264
|
var _a, _b, _c;
|
|
264
265
|
return ((_c = (_b = (_a = this.targetWindow) == null ? void 0 : _a.performance) == null ? void 0 : _b.now) == null ? void 0 : _c.call(_b)) ?? Date.now();
|
|
@@ -1072,14 +1073,24 @@ class Virtualizer {
|
|
|
1072
1073
|
}
|
|
1073
1074
|
return true;
|
|
1074
1075
|
};
|
|
1076
|
+
this.dropDisconnected = () => {
|
|
1077
|
+
this.elementsCache.forEach((cached, key) => {
|
|
1078
|
+
if (!cached.isConnected) {
|
|
1079
|
+
this.observer.unobserve(cached);
|
|
1080
|
+
this.elementsCache.delete(key);
|
|
1081
|
+
}
|
|
1082
|
+
});
|
|
1083
|
+
};
|
|
1075
1084
|
this.measureElement = (node) => {
|
|
1076
1085
|
if (!node) {
|
|
1077
|
-
this.
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
|
|
1086
|
+
this.dropDisconnected();
|
|
1087
|
+
if (!this._dropQueued) {
|
|
1088
|
+
this._dropQueued = true;
|
|
1089
|
+
queueMicrotask(() => {
|
|
1090
|
+
this._dropQueued = false;
|
|
1091
|
+
this.dropDisconnected();
|
|
1092
|
+
});
|
|
1093
|
+
}
|
|
1083
1094
|
return;
|
|
1084
1095
|
}
|
|
1085
1096
|
const index = this.indexFromElement(node);
|
|
@@ -1629,7 +1640,8 @@ class Virtualizer {
|
|
|
1629
1640
|
// before the command (below). One held for a touch or a bounce is not
|
|
1630
1641
|
// dropped by a command: the write lands the element `_holdOffset` short
|
|
1631
1642
|
// of the target, under the rows exposed shifted by the same amount, and
|
|
1632
|
-
// the flush moves both together once a write is possible.
|
|
1643
|
+
// the flush moves both together once a write is possible. Unless the
|
|
1644
|
+
// target is less than the hold (below).
|
|
1633
1645
|
//
|
|
1634
1646
|
// An index or end target that is already at its offset starts a smooth
|
|
1635
1647
|
// scroll as landed; an offset target never does, so its first scroll
|
|
@@ -1674,6 +1686,12 @@ class Virtualizer {
|
|
|
1674
1686
|
}
|
|
1675
1687
|
this._iosGesture.end();
|
|
1676
1688
|
}
|
|
1689
|
+
if (offset < this._holdOffset && this._canWriteScroll()) {
|
|
1690
|
+
this.scrollState = null;
|
|
1691
|
+
this._flushHoldIfReady(true);
|
|
1692
|
+
this._clampedAdjustment = null;
|
|
1693
|
+
offset = Math.min(offset, Math.max(this.getMaxScrollOffset(), 0));
|
|
1694
|
+
}
|
|
1677
1695
|
this.scrollState = {
|
|
1678
1696
|
...target,
|
|
1679
1697
|
startedAt: this.now(),
|