@tanstack/react-virtual 3.0.0-beta.8 → 3.0.0
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/LICENSE +21 -0
- package/build/lib/_virtual/_rollupPluginBabelHelpers.esm.js +27 -0
- package/build/lib/_virtual/_rollupPluginBabelHelpers.esm.js.map +1 -0
- package/build/lib/_virtual/_rollupPluginBabelHelpers.js +31 -0
- package/build/lib/_virtual/_rollupPluginBabelHelpers.js.map +1 -0
- package/build/lib/_virtual/_rollupPluginBabelHelpers.mjs +27 -0
- package/build/lib/_virtual/_rollupPluginBabelHelpers.mjs.map +1 -0
- package/build/lib/index.d.ts +4 -0
- package/build/lib/index.esm.js +67 -0
- package/build/lib/index.esm.js.map +1 -0
- package/build/lib/index.js +97 -0
- package/build/lib/index.js.map +1 -0
- package/build/lib/index.mjs +67 -0
- package/build/lib/index.mjs.map +1 -0
- package/build/umd/index.development.js +661 -477
- package/build/umd/index.development.js.map +1 -1
- package/build/umd/index.production.js +22 -2
- package/build/umd/index.production.js.map +1 -1
- package/package.json +26 -12
- package/src/index.tsx +20 -8
- package/build/cjs/react-virtual/src/index.js +0 -90
- package/build/cjs/react-virtual/src/index.js.map +0 -1
- package/build/cjs/virtual-core/build/esm/index.js +0 -584
- package/build/cjs/virtual-core/build/esm/index.js.map +0 -1
- package/build/esm/index.js +0 -611
- package/build/esm/index.js.map +0 -1
- package/build/stats-html.html +0 -2689
- package/build/stats.json +0 -90
- package/build/types/react-virtual/src/index.d.ts +0 -4
- package/build/types/virtual-core/src/utils.d.ts +0 -7
package/src/index.tsx
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import * as React from 'react'
|
|
2
|
+
import { flushSync } from 'react-dom'
|
|
2
3
|
import {
|
|
3
4
|
elementScroll,
|
|
4
5
|
observeElementOffset,
|
|
@@ -15,18 +16,25 @@ export * from '@tanstack/virtual-core'
|
|
|
15
16
|
//
|
|
16
17
|
|
|
17
18
|
const useIsomorphicLayoutEffect =
|
|
18
|
-
typeof
|
|
19
|
+
typeof document !== 'undefined' ? React.useLayoutEffect : React.useEffect
|
|
19
20
|
|
|
20
|
-
function useVirtualizerBase<
|
|
21
|
+
function useVirtualizerBase<
|
|
22
|
+
TScrollElement extends Element | Window,
|
|
23
|
+
TItemElement extends Element,
|
|
24
|
+
>(
|
|
21
25
|
options: VirtualizerOptions<TScrollElement, TItemElement>,
|
|
22
26
|
): Virtualizer<TScrollElement, TItemElement> {
|
|
23
27
|
const rerender = React.useReducer(() => ({}), {})[1]
|
|
24
28
|
|
|
25
29
|
const resolvedOptions: VirtualizerOptions<TScrollElement, TItemElement> = {
|
|
26
30
|
...options,
|
|
27
|
-
onChange: (instance) => {
|
|
28
|
-
|
|
29
|
-
|
|
31
|
+
onChange: (instance, sync) => {
|
|
32
|
+
if (sync) {
|
|
33
|
+
flushSync(rerender)
|
|
34
|
+
} else {
|
|
35
|
+
rerender()
|
|
36
|
+
}
|
|
37
|
+
options.onChange?.(instance, sync)
|
|
30
38
|
},
|
|
31
39
|
}
|
|
32
40
|
|
|
@@ -47,7 +55,10 @@ function useVirtualizerBase<TScrollElement, TItemElement = unknown>(
|
|
|
47
55
|
return instance
|
|
48
56
|
}
|
|
49
57
|
|
|
50
|
-
export function useVirtualizer<
|
|
58
|
+
export function useVirtualizer<
|
|
59
|
+
TScrollElement extends Element,
|
|
60
|
+
TItemElement extends Element,
|
|
61
|
+
>(
|
|
51
62
|
options: PartialKeys<
|
|
52
63
|
VirtualizerOptions<TScrollElement, TItemElement>,
|
|
53
64
|
'observeElementRect' | 'observeElementOffset' | 'scrollToFn'
|
|
@@ -61,7 +72,7 @@ export function useVirtualizer<TScrollElement, TItemElement = unknown>(
|
|
|
61
72
|
})
|
|
62
73
|
}
|
|
63
74
|
|
|
64
|
-
export function useWindowVirtualizer<TItemElement
|
|
75
|
+
export function useWindowVirtualizer<TItemElement extends Element>(
|
|
65
76
|
options: PartialKeys<
|
|
66
77
|
VirtualizerOptions<Window, TItemElement>,
|
|
67
78
|
| 'getScrollElement'
|
|
@@ -71,10 +82,11 @@ export function useWindowVirtualizer<TItemElement = unknown>(
|
|
|
71
82
|
>,
|
|
72
83
|
): Virtualizer<Window, TItemElement> {
|
|
73
84
|
return useVirtualizerBase<Window, TItemElement>({
|
|
74
|
-
getScrollElement: () => (typeof
|
|
85
|
+
getScrollElement: () => (typeof document !== 'undefined' ? window : null),
|
|
75
86
|
observeElementRect: observeWindowRect,
|
|
76
87
|
observeElementOffset: observeWindowOffset,
|
|
77
88
|
scrollToFn: windowScroll,
|
|
89
|
+
initialOffset: typeof document !== 'undefined' ? window.scrollY : undefined,
|
|
78
90
|
...options,
|
|
79
91
|
})
|
|
80
92
|
}
|
|
@@ -1,90 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* react-virtual
|
|
3
|
-
*
|
|
4
|
-
* Copyright (c) TanStack
|
|
5
|
-
*
|
|
6
|
-
* This source code is licensed under the MIT license found in the
|
|
7
|
-
* LICENSE.md file in the root directory of this source tree.
|
|
8
|
-
*
|
|
9
|
-
* @license MIT
|
|
10
|
-
*/
|
|
11
|
-
'use strict';
|
|
12
|
-
|
|
13
|
-
Object.defineProperty(exports, '__esModule', { value: true });
|
|
14
|
-
|
|
15
|
-
var React = require('react');
|
|
16
|
-
var index = require('../../virtual-core/build/esm/index.js');
|
|
17
|
-
|
|
18
|
-
function _interopNamespace(e) {
|
|
19
|
-
if (e && e.__esModule) return e;
|
|
20
|
-
var n = Object.create(null);
|
|
21
|
-
if (e) {
|
|
22
|
-
Object.keys(e).forEach(function (k) {
|
|
23
|
-
if (k !== 'default') {
|
|
24
|
-
var d = Object.getOwnPropertyDescriptor(e, k);
|
|
25
|
-
Object.defineProperty(n, k, d.get ? d : {
|
|
26
|
-
enumerable: true,
|
|
27
|
-
get: function () { return e[k]; }
|
|
28
|
-
});
|
|
29
|
-
}
|
|
30
|
-
});
|
|
31
|
-
}
|
|
32
|
-
n["default"] = e;
|
|
33
|
-
return Object.freeze(n);
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
var React__namespace = /*#__PURE__*/_interopNamespace(React);
|
|
37
|
-
|
|
38
|
-
const useIsomorphicLayoutEffect = typeof window !== 'undefined' ? React__namespace.useLayoutEffect : React__namespace.useEffect;
|
|
39
|
-
|
|
40
|
-
function useVirtualizerBase(options) {
|
|
41
|
-
const rerender = React__namespace.useReducer(() => ({}), {})[1];
|
|
42
|
-
const resolvedOptions = { ...options,
|
|
43
|
-
onChange: instance => {
|
|
44
|
-
rerender();
|
|
45
|
-
options.onChange == null ? void 0 : options.onChange(instance);
|
|
46
|
-
}
|
|
47
|
-
};
|
|
48
|
-
const [instance] = React__namespace.useState(() => new index.Virtualizer(resolvedOptions));
|
|
49
|
-
instance.setOptions(resolvedOptions);
|
|
50
|
-
React__namespace.useEffect(() => {
|
|
51
|
-
return instance._didMount();
|
|
52
|
-
}, []);
|
|
53
|
-
useIsomorphicLayoutEffect(() => {
|
|
54
|
-
return instance._willUpdate();
|
|
55
|
-
});
|
|
56
|
-
return instance;
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
function useVirtualizer(options) {
|
|
60
|
-
return useVirtualizerBase({
|
|
61
|
-
observeElementRect: index.observeElementRect,
|
|
62
|
-
observeElementOffset: index.observeElementOffset,
|
|
63
|
-
scrollToFn: index.elementScroll,
|
|
64
|
-
...options
|
|
65
|
-
});
|
|
66
|
-
}
|
|
67
|
-
function useWindowVirtualizer(options) {
|
|
68
|
-
return useVirtualizerBase({
|
|
69
|
-
getScrollElement: () => typeof window !== 'undefined' ? window : null,
|
|
70
|
-
observeElementRect: index.observeWindowRect,
|
|
71
|
-
observeElementOffset: index.observeWindowOffset,
|
|
72
|
-
scrollToFn: index.windowScroll,
|
|
73
|
-
...options
|
|
74
|
-
});
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
exports.Virtualizer = index.Virtualizer;
|
|
78
|
-
exports.defaultKeyExtractor = index.defaultKeyExtractor;
|
|
79
|
-
exports.defaultRangeExtractor = index.defaultRangeExtractor;
|
|
80
|
-
exports.elementScroll = index.elementScroll;
|
|
81
|
-
exports.measureElement = index.measureElement;
|
|
82
|
-
exports.memo = index.memo;
|
|
83
|
-
exports.observeElementOffset = index.observeElementOffset;
|
|
84
|
-
exports.observeElementRect = index.observeElementRect;
|
|
85
|
-
exports.observeWindowOffset = index.observeWindowOffset;
|
|
86
|
-
exports.observeWindowRect = index.observeWindowRect;
|
|
87
|
-
exports.windowScroll = index.windowScroll;
|
|
88
|
-
exports.useVirtualizer = useVirtualizer;
|
|
89
|
-
exports.useWindowVirtualizer = useWindowVirtualizer;
|
|
90
|
-
//# sourceMappingURL=index.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../../../../src/index.tsx"],"sourcesContent":["import * as React from 'react'\nimport {\n elementScroll,\n observeElementOffset,\n observeElementRect,\n observeWindowOffset,\n observeWindowRect,\n PartialKeys,\n Virtualizer,\n VirtualizerOptions,\n windowScroll,\n} from '@tanstack/virtual-core'\nexport * from '@tanstack/virtual-core'\n\n//\n\nconst useIsomorphicLayoutEffect =\n typeof window !== 'undefined' ? React.useLayoutEffect : React.useEffect\n\nfunction useVirtualizerBase<TScrollElement, TItemElement = unknown>(\n options: VirtualizerOptions<TScrollElement, TItemElement>,\n): Virtualizer<TScrollElement, TItemElement> {\n const rerender = React.useReducer(() => ({}), {})[1]\n\n const resolvedOptions: VirtualizerOptions<TScrollElement, TItemElement> = {\n ...options,\n onChange: (instance) => {\n rerender()\n options.onChange?.(instance)\n },\n }\n\n const [instance] = React.useState(\n () => new Virtualizer<TScrollElement, TItemElement>(resolvedOptions),\n )\n\n instance.setOptions(resolvedOptions)\n\n React.useEffect(() => {\n return instance._didMount()\n }, [])\n\n useIsomorphicLayoutEffect(() => {\n return instance._willUpdate()\n })\n\n return instance\n}\n\nexport function useVirtualizer<TScrollElement, TItemElement = unknown>(\n options: PartialKeys<\n VirtualizerOptions<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 = unknown>(\n options: PartialKeys<\n VirtualizerOptions<Window, TItemElement>,\n | 'getScrollElement'\n | 'observeElementRect'\n | 'observeElementOffset'\n | 'scrollToFn'\n >,\n): Virtualizer<Window, TItemElement> {\n return useVirtualizerBase<Window, TItemElement>({\n getScrollElement: () => (typeof window !== 'undefined' ? window : null!),\n observeElementRect: observeWindowRect,\n observeElementOffset: observeWindowOffset,\n scrollToFn: windowScroll,\n ...options,\n })\n}\n"],"names":["useIsomorphicLayoutEffect","window","React","useLayoutEffect","useEffect","useVirtualizerBase","options","rerender","useReducer","resolvedOptions","onChange","instance","useState","Virtualizer","setOptions","_didMount","_willUpdate","useVirtualizer","observeElementRect","observeElementOffset","scrollToFn","elementScroll","useWindowVirtualizer","getScrollElement","observeWindowRect","observeWindowOffset","windowScroll"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAgBA,MAAMA,yBAAyB,GAC7B,OAAOC,MAAP,KAAkB,WAAlB,GAAgCC,gBAAK,CAACC,eAAtC,GAAwDD,gBAAK,CAACE,SADhE,CAAA;;AAGA,SAASC,kBAAT,CACEC,OADF,EAE6C;AAC3C,EAAA,MAAMC,QAAQ,GAAGL,gBAAK,CAACM,UAAN,CAAiB,OAAO,EAAP,CAAjB,EAA6B,EAA7B,CAAA,CAAiC,CAAjC,CAAjB,CAAA;AAEA,EAAA,MAAMC,eAAiE,GAAG,EACxE,GAAGH,OADqE;IAExEI,QAAQ,EAAGC,QAAD,IAAc;MACtBJ,QAAQ,EAAA,CAAA;AACRD,MAAAA,OAAO,CAACI,QAAR,IAAA,IAAA,GAAA,KAAA,CA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