@tanstack/virtual-core 3.19.14 → 3.19.16
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 +28 -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 +28 -7
- package/dist/esm/index.js.map +1 -1
- package/package.json +1 -1
- package/src/index.ts +49 -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();
|
|
@@ -550,12 +551,15 @@ class Virtualizer {
|
|
|
550
551
|
this.elementsCache.forEach((cached) => {
|
|
551
552
|
this.observer.observe(cached);
|
|
552
553
|
});
|
|
554
|
+
let observing = false;
|
|
553
555
|
this.unsubs.push(
|
|
554
556
|
this.options.observeElementRect(this, (rect) => {
|
|
555
557
|
this.scrollRect = rect;
|
|
556
558
|
this.maybeNotify();
|
|
559
|
+
if (observing) this.measureElement(null);
|
|
557
560
|
})
|
|
558
561
|
);
|
|
562
|
+
observing = true;
|
|
559
563
|
this.unsubs.push(
|
|
560
564
|
this.options.observeElementOffset(this, (offset, isScrolling) => {
|
|
561
565
|
var _a2, _b, _c, _d;
|
|
@@ -1072,14 +1076,24 @@ class Virtualizer {
|
|
|
1072
1076
|
}
|
|
1073
1077
|
return true;
|
|
1074
1078
|
};
|
|
1079
|
+
this.dropDisconnected = () => {
|
|
1080
|
+
this.elementsCache.forEach((cached, key) => {
|
|
1081
|
+
if (!cached.isConnected) {
|
|
1082
|
+
this.observer.unobserve(cached);
|
|
1083
|
+
this.elementsCache.delete(key);
|
|
1084
|
+
}
|
|
1085
|
+
});
|
|
1086
|
+
};
|
|
1075
1087
|
this.measureElement = (node) => {
|
|
1076
1088
|
if (!node) {
|
|
1077
|
-
this.
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
|
|
1089
|
+
this.dropDisconnected();
|
|
1090
|
+
if (!this._dropQueued) {
|
|
1091
|
+
this._dropQueued = true;
|
|
1092
|
+
queueMicrotask(() => {
|
|
1093
|
+
this._dropQueued = false;
|
|
1094
|
+
this.dropDisconnected();
|
|
1095
|
+
});
|
|
1096
|
+
}
|
|
1083
1097
|
return;
|
|
1084
1098
|
}
|
|
1085
1099
|
const index = this.indexFromElement(node);
|
|
@@ -1629,7 +1643,8 @@ class Virtualizer {
|
|
|
1629
1643
|
// before the command (below). One held for a touch or a bounce is not
|
|
1630
1644
|
// dropped by a command: the write lands the element `_holdOffset` short
|
|
1631
1645
|
// of the target, under the rows exposed shifted by the same amount, and
|
|
1632
|
-
// the flush moves both together once a write is possible.
|
|
1646
|
+
// the flush moves both together once a write is possible. Unless the
|
|
1647
|
+
// target is less than the hold (below).
|
|
1633
1648
|
//
|
|
1634
1649
|
// An index or end target that is already at its offset starts a smooth
|
|
1635
1650
|
// scroll as landed; an offset target never does, so its first scroll
|
|
@@ -1674,6 +1689,12 @@ class Virtualizer {
|
|
|
1674
1689
|
}
|
|
1675
1690
|
this._iosGesture.end();
|
|
1676
1691
|
}
|
|
1692
|
+
if (offset < this._holdOffset && this._canWriteScroll()) {
|
|
1693
|
+
this.scrollState = null;
|
|
1694
|
+
this._flushHoldIfReady(true);
|
|
1695
|
+
this._clampedAdjustment = null;
|
|
1696
|
+
offset = Math.min(offset, Math.max(this.getMaxScrollOffset(), 0));
|
|
1697
|
+
}
|
|
1677
1698
|
this.scrollState = {
|
|
1678
1699
|
...target,
|
|
1679
1700
|
startedAt: this.now(),
|