@tanstack/virtual-core 3.19.3 → 3.19.4
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 +27 -4
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/esm/index.js +27 -4
- package/dist/esm/index.js.map +1 -1
- package/package.json +1 -1
- package/src/index.ts +30 -4
package/dist/cjs/index.cjs
CHANGED
|
@@ -17,6 +17,22 @@ const getRect = (element) => {
|
|
|
17
17
|
const { offsetWidth, offsetHeight } = element;
|
|
18
18
|
return { width: offsetWidth, height: offsetHeight };
|
|
19
19
|
};
|
|
20
|
+
const createFrameQueue = (targetWindow) => {
|
|
21
|
+
const ids = /* @__PURE__ */ new Set();
|
|
22
|
+
return {
|
|
23
|
+
schedule: (fn) => {
|
|
24
|
+
const id = targetWindow.requestAnimationFrame(() => {
|
|
25
|
+
ids.delete(id);
|
|
26
|
+
fn();
|
|
27
|
+
});
|
|
28
|
+
ids.add(id);
|
|
29
|
+
},
|
|
30
|
+
cancel: () => {
|
|
31
|
+
ids.forEach((id) => targetWindow.cancelAnimationFrame(id));
|
|
32
|
+
ids.clear();
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
};
|
|
20
36
|
const defaultKeyExtractor = (index) => index;
|
|
21
37
|
const defaultRangeExtractor = (range) => {
|
|
22
38
|
const overscan = range.overscan * Math.max(range.lanes ?? 1, 1);
|
|
@@ -47,6 +63,7 @@ const observeElementRect = (instance, cb) => {
|
|
|
47
63
|
return () => {
|
|
48
64
|
};
|
|
49
65
|
}
|
|
66
|
+
const frames = createFrameQueue(targetWindow);
|
|
50
67
|
const observer = new targetWindow.ResizeObserver((entries) => {
|
|
51
68
|
const run = () => {
|
|
52
69
|
const entry = entries[0];
|
|
@@ -59,11 +76,12 @@ const observeElementRect = (instance, cb) => {
|
|
|
59
76
|
}
|
|
60
77
|
handler(getRect(element));
|
|
61
78
|
};
|
|
62
|
-
instance.options.useAnimationFrameWithResizeObserver ?
|
|
79
|
+
instance.options.useAnimationFrameWithResizeObserver ? frames.schedule(run) : run();
|
|
63
80
|
});
|
|
64
81
|
observer.observe(element, { box: "border-box" });
|
|
65
82
|
return () => {
|
|
66
83
|
observer.unobserve(element);
|
|
84
|
+
frames.cancel();
|
|
67
85
|
};
|
|
68
86
|
};
|
|
69
87
|
const addEventListenerOptions = {
|
|
@@ -221,14 +239,17 @@ class Virtualizer {
|
|
|
221
239
|
};
|
|
222
240
|
this.observer = /* @__PURE__ */ (() => {
|
|
223
241
|
let _ro = null;
|
|
242
|
+
let _frames = null;
|
|
224
243
|
const get = () => {
|
|
225
244
|
if (_ro) {
|
|
226
245
|
return _ro;
|
|
227
246
|
}
|
|
228
|
-
|
|
247
|
+
const targetWindow = this.targetWindow;
|
|
248
|
+
if (!targetWindow || !targetWindow.ResizeObserver) {
|
|
229
249
|
return null;
|
|
230
250
|
}
|
|
231
|
-
|
|
251
|
+
const frames = _frames = createFrameQueue(targetWindow);
|
|
252
|
+
return _ro = new targetWindow.ResizeObserver((entries) => {
|
|
232
253
|
const run = () => {
|
|
233
254
|
const batch = { sync: false };
|
|
234
255
|
this._resizeBatch = batch;
|
|
@@ -242,7 +263,7 @@ class Virtualizer {
|
|
|
242
263
|
}
|
|
243
264
|
}
|
|
244
265
|
};
|
|
245
|
-
this.options.useAnimationFrameWithResizeObserver ?
|
|
266
|
+
this.options.useAnimationFrameWithResizeObserver ? frames.schedule(run) : run();
|
|
246
267
|
});
|
|
247
268
|
};
|
|
248
269
|
const measureEntry = (entry) => {
|
|
@@ -267,7 +288,9 @@ class Virtualizer {
|
|
|
267
288
|
disconnect: () => {
|
|
268
289
|
var _a;
|
|
269
290
|
(_a = get()) == null ? void 0 : _a.disconnect();
|
|
291
|
+
_frames == null ? void 0 : _frames.cancel();
|
|
270
292
|
_ro = null;
|
|
293
|
+
_frames = null;
|
|
271
294
|
},
|
|
272
295
|
observe: (target) => {
|
|
273
296
|
var _a;
|