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