@tanstack/react-virtual 3.13.13 → 3.13.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 +5 -2
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs/index.d.cts +5 -2
- package/dist/esm/index.d.ts +5 -2
- package/dist/esm/index.js +5 -2
- package/dist/esm/index.js.map +1 -1
- package/package.json +3 -3
- package/src/index.tsx +17 -6
package/dist/cjs/index.cjs
CHANGED
|
@@ -21,13 +21,16 @@ function _interopNamespaceDefault(e) {
|
|
|
21
21
|
}
|
|
22
22
|
const React__namespace = /* @__PURE__ */ _interopNamespaceDefault(React);
|
|
23
23
|
const useIsomorphicLayoutEffect = typeof document !== "undefined" ? React__namespace.useLayoutEffect : React__namespace.useEffect;
|
|
24
|
-
function useVirtualizerBase(
|
|
24
|
+
function useVirtualizerBase({
|
|
25
|
+
useFlushSync = true,
|
|
26
|
+
...options
|
|
27
|
+
}) {
|
|
25
28
|
const rerender = React__namespace.useReducer(() => ({}), {})[1];
|
|
26
29
|
const resolvedOptions = {
|
|
27
30
|
...options,
|
|
28
31
|
onChange: (instance2, sync) => {
|
|
29
32
|
var _a;
|
|
30
|
-
if (sync) {
|
|
33
|
+
if (useFlushSync && sync) {
|
|
31
34
|
reactDom.flushSync(rerender);
|
|
32
35
|
} else {
|
|
33
36
|
rerender();
|
package/dist/cjs/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","sources":["../../src/index.tsx"],"sourcesContent":["import * as React from 'react'\nimport { flushSync } from 'react-dom'\nimport {\n Virtualizer,\n elementScroll,\n observeElementOffset,\n observeElementRect,\n observeWindowOffset,\n observeWindowRect,\n windowScroll,\n} from '@tanstack/virtual-core'\nimport type { PartialKeys, VirtualizerOptions } from '@tanstack/virtual-core'\n\nexport * from '@tanstack/virtual-core'\n\nconst useIsomorphicLayoutEffect =\n typeof document !== 'undefined' ? React.useLayoutEffect : React.useEffect\n\nfunction useVirtualizerBase<\n TScrollElement extends Element | Window,\n TItemElement extends Element,\n>(\n options:
|
|
1
|
+
{"version":3,"file":"index.cjs","sources":["../../src/index.tsx"],"sourcesContent":["import * as React from 'react'\nimport { flushSync } from 'react-dom'\nimport {\n Virtualizer,\n elementScroll,\n observeElementOffset,\n observeElementRect,\n observeWindowOffset,\n observeWindowRect,\n windowScroll,\n} from '@tanstack/virtual-core'\nimport type { PartialKeys, VirtualizerOptions } from '@tanstack/virtual-core'\n\nexport * from '@tanstack/virtual-core'\n\nconst useIsomorphicLayoutEffect =\n typeof document !== 'undefined' ? React.useLayoutEffect : React.useEffect\n\nexport type ReactVirtualizerOptions<\n TScrollElement extends Element | Window,\n TItemElement extends Element,\n> = VirtualizerOptions<TScrollElement, TItemElement> & {\n useFlushSync?: boolean\n}\n\nfunction useVirtualizerBase<\n TScrollElement extends Element | Window,\n TItemElement extends Element,\n>({\n useFlushSync = true,\n ...options\n}: ReactVirtualizerOptions<TScrollElement, TItemElement>): Virtualizer<\n TScrollElement,\n TItemElement\n> {\n const rerender = React.useReducer(() => ({}), {})[1]\n\n const resolvedOptions: VirtualizerOptions<TScrollElement, TItemElement> = {\n ...options,\n onChange: (instance, sync) => {\n if (useFlushSync && sync) {\n flushSync(rerender)\n } else {\n rerender()\n }\n options.onChange?.(instance, sync)\n },\n }\n\n const [instance] = React.useState(\n () => new Virtualizer<TScrollElement, TItemElement>(resolvedOptions),\n )\n\n instance.setOptions(resolvedOptions)\n\n useIsomorphicLayoutEffect(() => {\n return instance._didMount()\n }, [])\n\n useIsomorphicLayoutEffect(() => {\n return instance._willUpdate()\n })\n\n return instance\n}\n\nexport function useVirtualizer<\n TScrollElement extends Element,\n TItemElement extends Element,\n>(\n options: PartialKeys<\n ReactVirtualizerOptions<TScrollElement, TItemElement>,\n 'observeElementRect' | 'observeElementOffset' | 'scrollToFn'\n >,\n): Virtualizer<TScrollElement, TItemElement> {\n return useVirtualizerBase<TScrollElement, TItemElement>({\n observeElementRect: observeElementRect,\n observeElementOffset: observeElementOffset,\n scrollToFn: elementScroll,\n ...options,\n })\n}\n\nexport function useWindowVirtualizer<TItemElement extends Element>(\n options: PartialKeys<\n ReactVirtualizerOptions<Window, TItemElement>,\n | 'getScrollElement'\n | 'observeElementRect'\n | 'observeElementOffset'\n | 'scrollToFn'\n >,\n): Virtualizer<Window, TItemElement> {\n return useVirtualizerBase<Window, TItemElement>({\n getScrollElement: () => (typeof document !== 'undefined' ? window : null),\n observeElementRect: observeWindowRect,\n observeElementOffset: observeWindowOffset,\n scrollToFn: windowScroll,\n initialOffset: () => (typeof document !== 'undefined' ? window.scrollY : 0),\n ...options,\n })\n}\n"],"names":["React","instance","flushSync","Virtualizer","observeElementRect","observeElementOffset","elementScroll","observeWindowRect","observeWindowOffset","windowScroll"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAeA,MAAM,4BACJ,OAAO,aAAa,cAAcA,iBAAM,kBAAkBA,iBAAM;AASlE,SAAS,mBAGP;AAAA,EACA,eAAe;AAAA,EACf,GAAG;AACL,GAGE;AACA,QAAM,WAAWA,iBAAM,WAAW,OAAO,CAAA,IAAK,CAAA,CAAE,EAAE,CAAC;AAEnD,QAAM,kBAAoE;AAAA,IACxE,GAAG;AAAA,IACH,UAAU,CAACC,WAAU,SAAS;;AAC5B,UAAI,gBAAgB,MAAM;AACxBC,iBAAAA,UAAU,QAAQ;AAAA,MACpB,OAAO;AACL,iBAAA;AAAA,MACF;AACA,oBAAQ,aAAR,iCAAmBD,WAAU;AAAA,IAC/B;AAAA,EAAA;AAGF,QAAM,CAAC,QAAQ,IAAID,iBAAM;AAAA,IACvB,MAAM,IAAIG,YAAAA,YAA0C,eAAe;AAAA,EAAA;AAGrE,WAAS,WAAW,eAAe;AAEnC,4BAA0B,MAAM;AAC9B,WAAO,SAAS,UAAA;AAAA,EAClB,GAAG,CAAA,CAAE;AAEL,4BAA0B,MAAM;AAC9B,WAAO,SAAS,YAAA;AAAA,EAClB,CAAC;AAED,SAAO;AACT;AAEO,SAAS,eAId,SAI2C;AAC3C,SAAO,mBAAiD;AAAA,IAAA,oBACtDC,YAAAA;AAAAA,IAAA,sBACAC,YAAAA;AAAAA,IACA,YAAYC,YAAAA;AAAAA,IACZ,GAAG;AAAA,EAAA,CACJ;AACH;AAEO,SAAS,qBACd,SAOmC;AACnC,SAAO,mBAAyC;AAAA,IAC9C,kBAAkB,MAAO,OAAO,aAAa,cAAc,SAAS;AAAA,IACpE,oBAAoBC,YAAAA;AAAAA,IACpB,sBAAsBC,YAAAA;AAAAA,IACtB,YAAYC,YAAAA;AAAAA,IACZ,eAAe,MAAO,OAAO,aAAa,cAAc,OAAO,UAAU;AAAA,IACzE,GAAG;AAAA,EAAA,CACJ;AACH;;;;;;;;;"}
|
package/dist/cjs/index.d.cts
CHANGED
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
import { Virtualizer, PartialKeys, VirtualizerOptions } from '@tanstack/virtual-core';
|
|
2
2
|
export * from '@tanstack/virtual-core';
|
|
3
|
-
export
|
|
4
|
-
|
|
3
|
+
export type ReactVirtualizerOptions<TScrollElement extends Element | Window, TItemElement extends Element> = VirtualizerOptions<TScrollElement, TItemElement> & {
|
|
4
|
+
useFlushSync?: boolean;
|
|
5
|
+
};
|
|
6
|
+
export declare function useVirtualizer<TScrollElement extends Element, TItemElement extends Element>(options: PartialKeys<ReactVirtualizerOptions<TScrollElement, TItemElement>, 'observeElementRect' | 'observeElementOffset' | 'scrollToFn'>): Virtualizer<TScrollElement, TItemElement>;
|
|
7
|
+
export declare function useWindowVirtualizer<TItemElement extends Element>(options: PartialKeys<ReactVirtualizerOptions<Window, TItemElement>, 'getScrollElement' | 'observeElementRect' | 'observeElementOffset' | 'scrollToFn'>): Virtualizer<Window, TItemElement>;
|
package/dist/esm/index.d.ts
CHANGED
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
import { Virtualizer, PartialKeys, VirtualizerOptions } from '@tanstack/virtual-core';
|
|
2
2
|
export * from '@tanstack/virtual-core';
|
|
3
|
-
export
|
|
4
|
-
|
|
3
|
+
export type ReactVirtualizerOptions<TScrollElement extends Element | Window, TItemElement extends Element> = VirtualizerOptions<TScrollElement, TItemElement> & {
|
|
4
|
+
useFlushSync?: boolean;
|
|
5
|
+
};
|
|
6
|
+
export declare function useVirtualizer<TScrollElement extends Element, TItemElement extends Element>(options: PartialKeys<ReactVirtualizerOptions<TScrollElement, TItemElement>, 'observeElementRect' | 'observeElementOffset' | 'scrollToFn'>): Virtualizer<TScrollElement, TItemElement>;
|
|
7
|
+
export declare function useWindowVirtualizer<TItemElement extends Element>(options: PartialKeys<ReactVirtualizerOptions<Window, TItemElement>, 'getScrollElement' | 'observeElementRect' | 'observeElementOffset' | 'scrollToFn'>): Virtualizer<Window, TItemElement>;
|
package/dist/esm/index.js
CHANGED
|
@@ -3,13 +3,16 @@ import { flushSync } from "react-dom";
|
|
|
3
3
|
import { Virtualizer, elementScroll, observeElementOffset, observeElementRect, windowScroll, observeWindowOffset, observeWindowRect } from "@tanstack/virtual-core";
|
|
4
4
|
export * from "@tanstack/virtual-core";
|
|
5
5
|
const useIsomorphicLayoutEffect = typeof document !== "undefined" ? React.useLayoutEffect : React.useEffect;
|
|
6
|
-
function useVirtualizerBase(
|
|
6
|
+
function useVirtualizerBase({
|
|
7
|
+
useFlushSync = true,
|
|
8
|
+
...options
|
|
9
|
+
}) {
|
|
7
10
|
const rerender = React.useReducer(() => ({}), {})[1];
|
|
8
11
|
const resolvedOptions = {
|
|
9
12
|
...options,
|
|
10
13
|
onChange: (instance2, sync) => {
|
|
11
14
|
var _a;
|
|
12
|
-
if (sync) {
|
|
15
|
+
if (useFlushSync && sync) {
|
|
13
16
|
flushSync(rerender);
|
|
14
17
|
} else {
|
|
15
18
|
rerender();
|
package/dist/esm/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../../src/index.tsx"],"sourcesContent":["import * as React from 'react'\nimport { flushSync } from 'react-dom'\nimport {\n Virtualizer,\n elementScroll,\n observeElementOffset,\n observeElementRect,\n observeWindowOffset,\n observeWindowRect,\n windowScroll,\n} from '@tanstack/virtual-core'\nimport type { PartialKeys, VirtualizerOptions } from '@tanstack/virtual-core'\n\nexport * from '@tanstack/virtual-core'\n\nconst useIsomorphicLayoutEffect =\n typeof document !== 'undefined' ? React.useLayoutEffect : React.useEffect\n\nfunction useVirtualizerBase<\n TScrollElement extends Element | Window,\n TItemElement extends Element,\n>(\n options:
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../src/index.tsx"],"sourcesContent":["import * as React from 'react'\nimport { flushSync } from 'react-dom'\nimport {\n Virtualizer,\n elementScroll,\n observeElementOffset,\n observeElementRect,\n observeWindowOffset,\n observeWindowRect,\n windowScroll,\n} from '@tanstack/virtual-core'\nimport type { PartialKeys, VirtualizerOptions } from '@tanstack/virtual-core'\n\nexport * from '@tanstack/virtual-core'\n\nconst useIsomorphicLayoutEffect =\n typeof document !== 'undefined' ? React.useLayoutEffect : React.useEffect\n\nexport type ReactVirtualizerOptions<\n TScrollElement extends Element | Window,\n TItemElement extends Element,\n> = VirtualizerOptions<TScrollElement, TItemElement> & {\n useFlushSync?: boolean\n}\n\nfunction useVirtualizerBase<\n TScrollElement extends Element | Window,\n TItemElement extends Element,\n>({\n useFlushSync = true,\n ...options\n}: ReactVirtualizerOptions<TScrollElement, TItemElement>): Virtualizer<\n TScrollElement,\n TItemElement\n> {\n const rerender = React.useReducer(() => ({}), {})[1]\n\n const resolvedOptions: VirtualizerOptions<TScrollElement, TItemElement> = {\n ...options,\n onChange: (instance, sync) => {\n if (useFlushSync && sync) {\n flushSync(rerender)\n } else {\n rerender()\n }\n options.onChange?.(instance, sync)\n },\n }\n\n const [instance] = React.useState(\n () => new Virtualizer<TScrollElement, TItemElement>(resolvedOptions),\n )\n\n instance.setOptions(resolvedOptions)\n\n useIsomorphicLayoutEffect(() => {\n return instance._didMount()\n }, [])\n\n useIsomorphicLayoutEffect(() => {\n return instance._willUpdate()\n })\n\n return instance\n}\n\nexport function useVirtualizer<\n TScrollElement extends Element,\n TItemElement extends Element,\n>(\n options: PartialKeys<\n ReactVirtualizerOptions<TScrollElement, TItemElement>,\n 'observeElementRect' | 'observeElementOffset' | 'scrollToFn'\n >,\n): Virtualizer<TScrollElement, TItemElement> {\n return useVirtualizerBase<TScrollElement, TItemElement>({\n observeElementRect: observeElementRect,\n observeElementOffset: observeElementOffset,\n scrollToFn: elementScroll,\n ...options,\n })\n}\n\nexport function useWindowVirtualizer<TItemElement extends Element>(\n options: PartialKeys<\n ReactVirtualizerOptions<Window, TItemElement>,\n | 'getScrollElement'\n | 'observeElementRect'\n | 'observeElementOffset'\n | 'scrollToFn'\n >,\n): Virtualizer<Window, TItemElement> {\n return useVirtualizerBase<Window, TItemElement>({\n getScrollElement: () => (typeof document !== 'undefined' ? window : null),\n observeElementRect: observeWindowRect,\n observeElementOffset: observeWindowOffset,\n scrollToFn: windowScroll,\n initialOffset: () => (typeof document !== 'undefined' ? window.scrollY : 0),\n ...options,\n })\n}\n"],"names":["instance"],"mappings":";;;;AAeA,MAAM,4BACJ,OAAO,aAAa,cAAc,MAAM,kBAAkB,MAAM;AASlE,SAAS,mBAGP;AAAA,EACA,eAAe;AAAA,EACf,GAAG;AACL,GAGE;AACA,QAAM,WAAW,MAAM,WAAW,OAAO,CAAA,IAAK,CAAA,CAAE,EAAE,CAAC;AAEnD,QAAM,kBAAoE;AAAA,IACxE,GAAG;AAAA,IACH,UAAU,CAACA,WAAU,SAAS;;AAC5B,UAAI,gBAAgB,MAAM;AACxB,kBAAU,QAAQ;AAAA,MACpB,OAAO;AACL,iBAAA;AAAA,MACF;AACA,oBAAQ,aAAR,iCAAmBA,WAAU;AAAA,IAC/B;AAAA,EAAA;AAGF,QAAM,CAAC,QAAQ,IAAI,MAAM;AAAA,IACvB,MAAM,IAAI,YAA0C,eAAe;AAAA,EAAA;AAGrE,WAAS,WAAW,eAAe;AAEnC,4BAA0B,MAAM;AAC9B,WAAO,SAAS,UAAA;AAAA,EAClB,GAAG,CAAA,CAAE;AAEL,4BAA0B,MAAM;AAC9B,WAAO,SAAS,YAAA;AAAA,EAClB,CAAC;AAED,SAAO;AACT;AAEO,SAAS,eAId,SAI2C;AAC3C,SAAO,mBAAiD;AAAA,IACtD;AAAA,IACA;AAAA,IACA,YAAY;AAAA,IACZ,GAAG;AAAA,EAAA,CACJ;AACH;AAEO,SAAS,qBACd,SAOmC;AACnC,SAAO,mBAAyC;AAAA,IAC9C,kBAAkB,MAAO,OAAO,aAAa,cAAc,SAAS;AAAA,IACpE,oBAAoB;AAAA,IACpB,sBAAsB;AAAA,IACtB,YAAY;AAAA,IACZ,eAAe,MAAO,OAAO,aAAa,cAAc,OAAO,UAAU;AAAA,IACzE,GAAG;AAAA,EAAA,CACJ;AACH;"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tanstack/react-virtual",
|
|
3
|
-
"version": "3.13.
|
|
3
|
+
"version": "3.13.15",
|
|
4
4
|
"description": "Headless UI for virtualizing scrollable elements in React",
|
|
5
5
|
"author": "Tanner Linsley",
|
|
6
6
|
"license": "MIT",
|
|
@@ -45,7 +45,7 @@
|
|
|
45
45
|
"src"
|
|
46
46
|
],
|
|
47
47
|
"dependencies": {
|
|
48
|
-
"@tanstack/virtual-core": "3.13.
|
|
48
|
+
"@tanstack/virtual-core": "3.13.15"
|
|
49
49
|
},
|
|
50
50
|
"devDependencies": {
|
|
51
51
|
"@testing-library/react": "^16.3.0",
|
|
@@ -68,6 +68,6 @@
|
|
|
68
68
|
"test:lib:dev": "pnpm run test:lib --watch",
|
|
69
69
|
"test:build": "publint --strict",
|
|
70
70
|
"build": "vite build",
|
|
71
|
-
"test:e2e": "playwright test"
|
|
71
|
+
"test:e2e": "../../node_modules/.bin/playwright test"
|
|
72
72
|
}
|
|
73
73
|
}
|
package/src/index.tsx
CHANGED
|
@@ -16,18 +16,29 @@ export * from '@tanstack/virtual-core'
|
|
|
16
16
|
const useIsomorphicLayoutEffect =
|
|
17
17
|
typeof document !== 'undefined' ? React.useLayoutEffect : React.useEffect
|
|
18
18
|
|
|
19
|
+
export type ReactVirtualizerOptions<
|
|
20
|
+
TScrollElement extends Element | Window,
|
|
21
|
+
TItemElement extends Element,
|
|
22
|
+
> = VirtualizerOptions<TScrollElement, TItemElement> & {
|
|
23
|
+
useFlushSync?: boolean
|
|
24
|
+
}
|
|
25
|
+
|
|
19
26
|
function useVirtualizerBase<
|
|
20
27
|
TScrollElement extends Element | Window,
|
|
21
28
|
TItemElement extends Element,
|
|
22
|
-
>(
|
|
23
|
-
|
|
24
|
-
|
|
29
|
+
>({
|
|
30
|
+
useFlushSync = true,
|
|
31
|
+
...options
|
|
32
|
+
}: ReactVirtualizerOptions<TScrollElement, TItemElement>): Virtualizer<
|
|
33
|
+
TScrollElement,
|
|
34
|
+
TItemElement
|
|
35
|
+
> {
|
|
25
36
|
const rerender = React.useReducer(() => ({}), {})[1]
|
|
26
37
|
|
|
27
38
|
const resolvedOptions: VirtualizerOptions<TScrollElement, TItemElement> = {
|
|
28
39
|
...options,
|
|
29
40
|
onChange: (instance, sync) => {
|
|
30
|
-
if (sync) {
|
|
41
|
+
if (useFlushSync && sync) {
|
|
31
42
|
flushSync(rerender)
|
|
32
43
|
} else {
|
|
33
44
|
rerender()
|
|
@@ -58,7 +69,7 @@ export function useVirtualizer<
|
|
|
58
69
|
TItemElement extends Element,
|
|
59
70
|
>(
|
|
60
71
|
options: PartialKeys<
|
|
61
|
-
|
|
72
|
+
ReactVirtualizerOptions<TScrollElement, TItemElement>,
|
|
62
73
|
'observeElementRect' | 'observeElementOffset' | 'scrollToFn'
|
|
63
74
|
>,
|
|
64
75
|
): Virtualizer<TScrollElement, TItemElement> {
|
|
@@ -72,7 +83,7 @@ export function useVirtualizer<
|
|
|
72
83
|
|
|
73
84
|
export function useWindowVirtualizer<TItemElement extends Element>(
|
|
74
85
|
options: PartialKeys<
|
|
75
|
-
|
|
86
|
+
ReactVirtualizerOptions<Window, TItemElement>,
|
|
76
87
|
| 'getScrollElement'
|
|
77
88
|
| 'observeElementRect'
|
|
78
89
|
| 'observeElementOffset'
|