@react-aria/virtualizer 3.10.2-nightly.4704 → 3.10.2-nightly.4709
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/Virtualizer.main.js +13 -52
- package/dist/Virtualizer.main.js.map +1 -1
- package/dist/Virtualizer.mjs +15 -53
- package/dist/Virtualizer.module.js +15 -53
- package/dist/Virtualizer.module.js.map +1 -1
- package/dist/import.mjs +2 -2
- package/dist/main.js +0 -1
- package/dist/main.js.map +1 -1
- package/dist/module.js +2 -2
- package/dist/module.js.map +1 -1
- package/dist/types.d.ts +1 -13
- package/dist/types.d.ts.map +1 -1
- package/package.json +7 -7
- package/src/Virtualizer.tsx +7 -64
- package/src/index.ts +1 -1
package/dist/Virtualizer.main.js
CHANGED
|
@@ -13,7 +13,6 @@ function $parcel$export(e, n, v, s) {
|
|
|
13
13
|
Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
|
|
14
14
|
}
|
|
15
15
|
|
|
16
|
-
$parcel$export(module.exports, "useVirtualizer", () => $e1fb6f3669e1c329$export$dd6d526d88b5a137);
|
|
17
16
|
$parcel$export(module.exports, "Virtualizer", () => $e1fb6f3669e1c329$export$89be5a243e59c4b2);
|
|
18
17
|
/*
|
|
19
18
|
* Copyright 2020 Adobe. All rights reserved.
|
|
@@ -47,9 +46,20 @@ function $e1fb6f3669e1c329$var$Virtualizer(props, ref) {
|
|
|
47
46
|
persistedKeys: persistedKeys,
|
|
48
47
|
layoutOptions: layoutOptions
|
|
49
48
|
});
|
|
50
|
-
|
|
49
|
+
(0, $knrtk$reactariautils.useLoadMore)({
|
|
50
|
+
isLoading: isLoading,
|
|
51
|
+
onLoadMore: onLoadMore,
|
|
52
|
+
scrollOffset: 1
|
|
53
|
+
}, ref);
|
|
54
|
+
let onVisibleRectChange = (0, $knrtk$react.useCallback)((rect)=>{
|
|
55
|
+
state.setVisibleRect(rect);
|
|
56
|
+
}, [
|
|
57
|
+
state
|
|
58
|
+
]);
|
|
51
59
|
return /*#__PURE__*/ (0, ($parcel$interopDefault($knrtk$react))).createElement((0, $00ca8c0b29e3e07c$exports.ScrollView), {
|
|
52
|
-
...(0, $knrtk$reactariautils.mergeProps)(otherProps,
|
|
60
|
+
...(0, $knrtk$reactariautils.mergeProps)(otherProps, {
|
|
61
|
+
onVisibleRectChange: onVisibleRectChange
|
|
62
|
+
}),
|
|
53
63
|
ref: ref,
|
|
54
64
|
contentSize: state.contentSize,
|
|
55
65
|
onScrollStart: state.startScrolling,
|
|
@@ -58,55 +68,6 @@ function $e1fb6f3669e1c329$var$Virtualizer(props, ref) {
|
|
|
58
68
|
scrollDirection: scrollDirection
|
|
59
69
|
}, $e1fb6f3669e1c329$var$renderChildren(null, state.visibleViews, renderWrapper || $e1fb6f3669e1c329$var$defaultRenderWrapper));
|
|
60
70
|
}
|
|
61
|
-
function $e1fb6f3669e1c329$export$dd6d526d88b5a137(props, state, ref) {
|
|
62
|
-
let { isLoading: isLoading, onLoadMore: onLoadMore } = props;
|
|
63
|
-
let { setVisibleRect: setVisibleRect, virtualizer: virtualizer } = state;
|
|
64
|
-
// Handle scrolling, and call onLoadMore when nearing the bottom.
|
|
65
|
-
let isLoadingRef = (0, $knrtk$react.useRef)(isLoading);
|
|
66
|
-
let prevProps = (0, $knrtk$react.useRef)(props);
|
|
67
|
-
let onVisibleRectChange = (0, $knrtk$react.useCallback)((rect)=>{
|
|
68
|
-
setVisibleRect(rect);
|
|
69
|
-
if (!isLoadingRef.current && onLoadMore) {
|
|
70
|
-
let scrollOffset = virtualizer.contentSize.height - rect.height * 2;
|
|
71
|
-
if (rect.y > scrollOffset) {
|
|
72
|
-
isLoadingRef.current = true;
|
|
73
|
-
onLoadMore();
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
}, [
|
|
77
|
-
onLoadMore,
|
|
78
|
-
setVisibleRect,
|
|
79
|
-
virtualizer
|
|
80
|
-
]);
|
|
81
|
-
let lastContentSize = (0, $knrtk$react.useRef)(0);
|
|
82
|
-
(0, $knrtk$reactariautils.useLayoutEffect)(()=>{
|
|
83
|
-
// Only update isLoadingRef if props object actually changed,
|
|
84
|
-
// not if a local state change occurred.
|
|
85
|
-
let wasLoading = isLoadingRef.current;
|
|
86
|
-
if (props !== prevProps.current) {
|
|
87
|
-
isLoadingRef.current = isLoading;
|
|
88
|
-
prevProps.current = props;
|
|
89
|
-
}
|
|
90
|
-
let shouldLoadMore = !isLoadingRef.current && onLoadMore && state.contentSize.height > 0 && state.contentSize.height <= state.virtualizer.visibleRect.height && (wasLoading || state.contentSize.height !== lastContentSize.current);
|
|
91
|
-
if (shouldLoadMore) {
|
|
92
|
-
isLoadingRef.current = true;
|
|
93
|
-
onLoadMore();
|
|
94
|
-
}
|
|
95
|
-
lastContentSize.current = state.contentSize.height;
|
|
96
|
-
}, [
|
|
97
|
-
state.contentSize,
|
|
98
|
-
state.virtualizer,
|
|
99
|
-
isLoading,
|
|
100
|
-
onLoadMore,
|
|
101
|
-
props
|
|
102
|
-
]);
|
|
103
|
-
return {
|
|
104
|
-
virtualizerProps: {},
|
|
105
|
-
scrollViewProps: {
|
|
106
|
-
onVisibleRectChange: onVisibleRectChange
|
|
107
|
-
}
|
|
108
|
-
};
|
|
109
|
-
}
|
|
110
71
|
// forwardRef doesn't support generic parameters, so cast the result to the correct type
|
|
111
72
|
// https://stackoverflow.com/questions/58469229/react-with-typescript-generics-while-using-react-forwardref
|
|
112
73
|
const $e1fb6f3669e1c329$export$89be5a243e59c4b2 = /*#__PURE__*/ (0, ($parcel$interopDefault($knrtk$react))).forwardRef($e1fb6f3669e1c329$var$Virtualizer);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":"
|
|
1
|
+
{"mappings":";;;;;;;;;;;;;;;;AAAA;;;;;;;;;;CAUC;;;;;AA6BD,SAAS,kCAAsD,KAAgC,EAAE,GAAqC;IACpI,IAAI,EACF,UAAU,UAAU,iBACpB,aAAa,UACb,MAAM,cACN,UAAU,a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aAAa,GAAG;QACrB,YAAY,aAAa,UAAU;QACnC,aAAa,aAAa,WAAW;QACrC,MAAM,EAAE,mBAAA,6BAAA,OAAQ,UAAU;OACzB,aAAa,QAAQ;AAG5B","sources":["packages/@react-aria/virtualizer/src/Virtualizer.tsx"],"sourcesContent":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {Collection, Key, RefObject} from '@react-types/shared';\nimport {Layout, Rect, ReusableView, useVirtualizerState} from '@react-stately/virtualizer';\nimport {mergeProps, useLoadMore} from '@react-aria/utils';\nimport React, {HTMLAttributes, ReactElement, ReactNode, useCallback, useRef} from 'react';\nimport {ScrollView} from './ScrollView';\nimport {VirtualizerItem} from './VirtualizerItem';\n\ntype RenderWrapper<T extends object, V> = (\n parent: ReusableView<T, V> | null,\n reusableView: ReusableView<T, V>,\n children: ReusableView<T, V>[],\n renderChildren: (views: ReusableView<T, V>[]) => ReactElement[]\n) => ReactElement;\n\ninterface VirtualizerProps<T extends object, V, O> extends Omit<HTMLAttributes<HTMLElement>, 'children'> {\n children: (type: string, content: T) => V,\n renderWrapper?: RenderWrapper<T, V>,\n layout: Layout<T, O>,\n collection: Collection<T>,\n persistedKeys?: Set<Key> | null,\n sizeToFit?: 'width' | 'height',\n scrollDirection?: 'horizontal' | 'vertical' | 'both',\n isLoading?: boolean,\n onLoadMore?: () => void,\n layoutOptions?: O\n}\n\nfunction Virtualizer<T extends object, V extends ReactNode, O>(props: VirtualizerProps<T, V, O>, ref: RefObject<HTMLDivElement | null>) {\n let {\n children: renderView,\n renderWrapper,\n layout,\n collection,\n sizeToFit,\n scrollDirection,\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n isLoading,\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n onLoadMore,\n persistedKeys,\n layoutOptions,\n ...otherProps\n } = props;\n\n let fallbackRef = useRef<HTMLDivElement>(undefined);\n ref = ref || fallbackRef;\n\n let state = useVirtualizerState({\n layout,\n collection,\n renderView,\n onVisibleRectChange(rect) {\n ref.current.scrollLeft = rect.x;\n ref.current.scrollTop = rect.y;\n },\n persistedKeys,\n layoutOptions\n });\n\n useLoadMore({isLoading, onLoadMore, scrollOffset: 1}, ref);\n let onVisibleRectChange = useCallback((rect: Rect) => {\n state.setVisibleRect(rect);\n }, [state]);\n\n return (\n <ScrollView\n {...mergeProps(otherProps, {onVisibleRectChange})}\n ref={ref}\n contentSize={state.contentSize}\n onScrollStart={state.startScrolling}\n onScrollEnd={state.endScrolling}\n sizeToFit={sizeToFit}\n scrollDirection={scrollDirection}>\n {renderChildren(null, state.visibleViews, renderWrapper || defaultRenderWrapper)}\n </ScrollView>\n );\n}\n\n// forwardRef doesn't support generic parameters, so cast the result to the correct type\n// https://stackoverflow.com/questions/58469229/react-with-typescript-generics-while-using-react-forwardref\nconst _Virtualizer = React.forwardRef(Virtualizer) as <T extends object, V, O>(props: VirtualizerProps<T, V, O> & {ref?: RefObject<HTMLDivElement | null>}) => ReactElement;\nexport {_Virtualizer as Virtualizer};\n\nfunction renderChildren<T extends object, V>(parent: ReusableView<T, V> | null, views: ReusableView<T, V>[], renderWrapper: RenderWrapper<T, V>) {\n return views.map(view => {\n return renderWrapper(\n parent,\n view,\n view.children ? Array.from(view.children) : [],\n childViews => renderChildren(view, childViews, renderWrapper)\n );\n });\n}\n\nfunction defaultRenderWrapper<T extends object, V extends ReactNode>(\n parent: ReusableView<T, V> | null,\n reusableView: ReusableView<T, V>\n) {\n return (\n <VirtualizerItem\n key={reusableView.key}\n layoutInfo={reusableView.layoutInfo}\n virtualizer={reusableView.virtualizer}\n parent={parent?.layoutInfo}>\n {reusableView.rendered}\n </VirtualizerItem>\n );\n}\n"],"names":[],"version":3,"file":"Virtualizer.main.js.map"}
|
package/dist/Virtualizer.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import {ScrollView as $44a6ee657928b002$export$5665e3d6be6adea} from "./ScrollView.mjs";
|
|
2
2
|
import {VirtualizerItem as $ccf8a0a04e4175ae$export$6796df8ba7398521} from "./VirtualizerItem.mjs";
|
|
3
3
|
import {useVirtualizerState as $9WwqA$useVirtualizerState} from "@react-stately/virtualizer";
|
|
4
|
-
import {
|
|
4
|
+
import {useLoadMore as $9WwqA$useLoadMore, mergeProps as $9WwqA$mergeProps} from "@react-aria/utils";
|
|
5
5
|
import $9WwqA$react, {useRef as $9WwqA$useRef, useCallback as $9WwqA$useCallback} from "react";
|
|
6
6
|
|
|
7
7
|
/*
|
|
@@ -36,9 +36,20 @@ function $6d0a5c394373ae64$var$Virtualizer(props, ref) {
|
|
|
36
36
|
persistedKeys: persistedKeys,
|
|
37
37
|
layoutOptions: layoutOptions
|
|
38
38
|
});
|
|
39
|
-
|
|
39
|
+
(0, $9WwqA$useLoadMore)({
|
|
40
|
+
isLoading: isLoading,
|
|
41
|
+
onLoadMore: onLoadMore,
|
|
42
|
+
scrollOffset: 1
|
|
43
|
+
}, ref);
|
|
44
|
+
let onVisibleRectChange = (0, $9WwqA$useCallback)((rect)=>{
|
|
45
|
+
state.setVisibleRect(rect);
|
|
46
|
+
}, [
|
|
47
|
+
state
|
|
48
|
+
]);
|
|
40
49
|
return /*#__PURE__*/ (0, $9WwqA$react).createElement((0, $44a6ee657928b002$export$5665e3d6be6adea), {
|
|
41
|
-
...(0, $9WwqA$mergeProps)(otherProps,
|
|
50
|
+
...(0, $9WwqA$mergeProps)(otherProps, {
|
|
51
|
+
onVisibleRectChange: onVisibleRectChange
|
|
52
|
+
}),
|
|
42
53
|
ref: ref,
|
|
43
54
|
contentSize: state.contentSize,
|
|
44
55
|
onScrollStart: state.startScrolling,
|
|
@@ -47,55 +58,6 @@ function $6d0a5c394373ae64$var$Virtualizer(props, ref) {
|
|
|
47
58
|
scrollDirection: scrollDirection
|
|
48
59
|
}, $6d0a5c394373ae64$var$renderChildren(null, state.visibleViews, renderWrapper || $6d0a5c394373ae64$var$defaultRenderWrapper));
|
|
49
60
|
}
|
|
50
|
-
function $6d0a5c394373ae64$export$dd6d526d88b5a137(props, state, ref) {
|
|
51
|
-
let { isLoading: isLoading, onLoadMore: onLoadMore } = props;
|
|
52
|
-
let { setVisibleRect: setVisibleRect, virtualizer: virtualizer } = state;
|
|
53
|
-
// Handle scrolling, and call onLoadMore when nearing the bottom.
|
|
54
|
-
let isLoadingRef = (0, $9WwqA$useRef)(isLoading);
|
|
55
|
-
let prevProps = (0, $9WwqA$useRef)(props);
|
|
56
|
-
let onVisibleRectChange = (0, $9WwqA$useCallback)((rect)=>{
|
|
57
|
-
setVisibleRect(rect);
|
|
58
|
-
if (!isLoadingRef.current && onLoadMore) {
|
|
59
|
-
let scrollOffset = virtualizer.contentSize.height - rect.height * 2;
|
|
60
|
-
if (rect.y > scrollOffset) {
|
|
61
|
-
isLoadingRef.current = true;
|
|
62
|
-
onLoadMore();
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
}, [
|
|
66
|
-
onLoadMore,
|
|
67
|
-
setVisibleRect,
|
|
68
|
-
virtualizer
|
|
69
|
-
]);
|
|
70
|
-
let lastContentSize = (0, $9WwqA$useRef)(0);
|
|
71
|
-
(0, $9WwqA$useLayoutEffect)(()=>{
|
|
72
|
-
// Only update isLoadingRef if props object actually changed,
|
|
73
|
-
// not if a local state change occurred.
|
|
74
|
-
let wasLoading = isLoadingRef.current;
|
|
75
|
-
if (props !== prevProps.current) {
|
|
76
|
-
isLoadingRef.current = isLoading;
|
|
77
|
-
prevProps.current = props;
|
|
78
|
-
}
|
|
79
|
-
let shouldLoadMore = !isLoadingRef.current && onLoadMore && state.contentSize.height > 0 && state.contentSize.height <= state.virtualizer.visibleRect.height && (wasLoading || state.contentSize.height !== lastContentSize.current);
|
|
80
|
-
if (shouldLoadMore) {
|
|
81
|
-
isLoadingRef.current = true;
|
|
82
|
-
onLoadMore();
|
|
83
|
-
}
|
|
84
|
-
lastContentSize.current = state.contentSize.height;
|
|
85
|
-
}, [
|
|
86
|
-
state.contentSize,
|
|
87
|
-
state.virtualizer,
|
|
88
|
-
isLoading,
|
|
89
|
-
onLoadMore,
|
|
90
|
-
props
|
|
91
|
-
]);
|
|
92
|
-
return {
|
|
93
|
-
virtualizerProps: {},
|
|
94
|
-
scrollViewProps: {
|
|
95
|
-
onVisibleRectChange: onVisibleRectChange
|
|
96
|
-
}
|
|
97
|
-
};
|
|
98
|
-
}
|
|
99
61
|
// forwardRef doesn't support generic parameters, so cast the result to the correct type
|
|
100
62
|
// https://stackoverflow.com/questions/58469229/react-with-typescript-generics-while-using-react-forwardref
|
|
101
63
|
const $6d0a5c394373ae64$export$89be5a243e59c4b2 = /*#__PURE__*/ (0, $9WwqA$react).forwardRef($6d0a5c394373ae64$var$Virtualizer);
|
|
@@ -114,5 +76,5 @@ function $6d0a5c394373ae64$var$defaultRenderWrapper(parent, reusableView) {
|
|
|
114
76
|
}
|
|
115
77
|
|
|
116
78
|
|
|
117
|
-
export {$6d0a5c394373ae64$export$
|
|
79
|
+
export {$6d0a5c394373ae64$export$89be5a243e59c4b2 as Virtualizer};
|
|
118
80
|
//# sourceMappingURL=Virtualizer.module.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import {ScrollView as $44a6ee657928b002$export$5665e3d6be6adea} from "./ScrollView.module.js";
|
|
2
2
|
import {VirtualizerItem as $ccf8a0a04e4175ae$export$6796df8ba7398521} from "./VirtualizerItem.module.js";
|
|
3
3
|
import {useVirtualizerState as $9WwqA$useVirtualizerState} from "@react-stately/virtualizer";
|
|
4
|
-
import {
|
|
4
|
+
import {useLoadMore as $9WwqA$useLoadMore, mergeProps as $9WwqA$mergeProps} from "@react-aria/utils";
|
|
5
5
|
import $9WwqA$react, {useRef as $9WwqA$useRef, useCallback as $9WwqA$useCallback} from "react";
|
|
6
6
|
|
|
7
7
|
/*
|
|
@@ -36,9 +36,20 @@ function $6d0a5c394373ae64$var$Virtualizer(props, ref) {
|
|
|
36
36
|
persistedKeys: persistedKeys,
|
|
37
37
|
layoutOptions: layoutOptions
|
|
38
38
|
});
|
|
39
|
-
|
|
39
|
+
(0, $9WwqA$useLoadMore)({
|
|
40
|
+
isLoading: isLoading,
|
|
41
|
+
onLoadMore: onLoadMore,
|
|
42
|
+
scrollOffset: 1
|
|
43
|
+
}, ref);
|
|
44
|
+
let onVisibleRectChange = (0, $9WwqA$useCallback)((rect)=>{
|
|
45
|
+
state.setVisibleRect(rect);
|
|
46
|
+
}, [
|
|
47
|
+
state
|
|
48
|
+
]);
|
|
40
49
|
return /*#__PURE__*/ (0, $9WwqA$react).createElement((0, $44a6ee657928b002$export$5665e3d6be6adea), {
|
|
41
|
-
...(0, $9WwqA$mergeProps)(otherProps,
|
|
50
|
+
...(0, $9WwqA$mergeProps)(otherProps, {
|
|
51
|
+
onVisibleRectChange: onVisibleRectChange
|
|
52
|
+
}),
|
|
42
53
|
ref: ref,
|
|
43
54
|
contentSize: state.contentSize,
|
|
44
55
|
onScrollStart: state.startScrolling,
|
|
@@ -47,55 +58,6 @@ function $6d0a5c394373ae64$var$Virtualizer(props, ref) {
|
|
|
47
58
|
scrollDirection: scrollDirection
|
|
48
59
|
}, $6d0a5c394373ae64$var$renderChildren(null, state.visibleViews, renderWrapper || $6d0a5c394373ae64$var$defaultRenderWrapper));
|
|
49
60
|
}
|
|
50
|
-
function $6d0a5c394373ae64$export$dd6d526d88b5a137(props, state, ref) {
|
|
51
|
-
let { isLoading: isLoading, onLoadMore: onLoadMore } = props;
|
|
52
|
-
let { setVisibleRect: setVisibleRect, virtualizer: virtualizer } = state;
|
|
53
|
-
// Handle scrolling, and call onLoadMore when nearing the bottom.
|
|
54
|
-
let isLoadingRef = (0, $9WwqA$useRef)(isLoading);
|
|
55
|
-
let prevProps = (0, $9WwqA$useRef)(props);
|
|
56
|
-
let onVisibleRectChange = (0, $9WwqA$useCallback)((rect)=>{
|
|
57
|
-
setVisibleRect(rect);
|
|
58
|
-
if (!isLoadingRef.current && onLoadMore) {
|
|
59
|
-
let scrollOffset = virtualizer.contentSize.height - rect.height * 2;
|
|
60
|
-
if (rect.y > scrollOffset) {
|
|
61
|
-
isLoadingRef.current = true;
|
|
62
|
-
onLoadMore();
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
}, [
|
|
66
|
-
onLoadMore,
|
|
67
|
-
setVisibleRect,
|
|
68
|
-
virtualizer
|
|
69
|
-
]);
|
|
70
|
-
let lastContentSize = (0, $9WwqA$useRef)(0);
|
|
71
|
-
(0, $9WwqA$useLayoutEffect)(()=>{
|
|
72
|
-
// Only update isLoadingRef if props object actually changed,
|
|
73
|
-
// not if a local state change occurred.
|
|
74
|
-
let wasLoading = isLoadingRef.current;
|
|
75
|
-
if (props !== prevProps.current) {
|
|
76
|
-
isLoadingRef.current = isLoading;
|
|
77
|
-
prevProps.current = props;
|
|
78
|
-
}
|
|
79
|
-
let shouldLoadMore = !isLoadingRef.current && onLoadMore && state.contentSize.height > 0 && state.contentSize.height <= state.virtualizer.visibleRect.height && (wasLoading || state.contentSize.height !== lastContentSize.current);
|
|
80
|
-
if (shouldLoadMore) {
|
|
81
|
-
isLoadingRef.current = true;
|
|
82
|
-
onLoadMore();
|
|
83
|
-
}
|
|
84
|
-
lastContentSize.current = state.contentSize.height;
|
|
85
|
-
}, [
|
|
86
|
-
state.contentSize,
|
|
87
|
-
state.virtualizer,
|
|
88
|
-
isLoading,
|
|
89
|
-
onLoadMore,
|
|
90
|
-
props
|
|
91
|
-
]);
|
|
92
|
-
return {
|
|
93
|
-
virtualizerProps: {},
|
|
94
|
-
scrollViewProps: {
|
|
95
|
-
onVisibleRectChange: onVisibleRectChange
|
|
96
|
-
}
|
|
97
|
-
};
|
|
98
|
-
}
|
|
99
61
|
// forwardRef doesn't support generic parameters, so cast the result to the correct type
|
|
100
62
|
// https://stackoverflow.com/questions/58469229/react-with-typescript-generics-while-using-react-forwardref
|
|
101
63
|
const $6d0a5c394373ae64$export$89be5a243e59c4b2 = /*#__PURE__*/ (0, $9WwqA$react).forwardRef($6d0a5c394373ae64$var$Virtualizer);
|
|
@@ -114,5 +76,5 @@ function $6d0a5c394373ae64$var$defaultRenderWrapper(parent, reusableView) {
|
|
|
114
76
|
}
|
|
115
77
|
|
|
116
78
|
|
|
117
|
-
export {$6d0a5c394373ae64$export$
|
|
79
|
+
export {$6d0a5c394373ae64$export$89be5a243e59c4b2 as Virtualizer};
|
|
118
80
|
//# sourceMappingURL=Virtualizer.module.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":";;;;;;AAAA;;;;;;;;;;CAUC;;;;;AA6BD,SAAS,kCAAsD,KAAgC,EAAE,GAAqC;IACpI,IAAI,EACF,UAAU,UAAU,iBACpB,aAAa,UACb,MAAM,cACN,UAAU,aACV,SAAS,mBACT,eAAe,aACf,6DAA6D;IAC7D,SAAS,cACT,6DAA6D;IAC7D,UAAU,iBACV,aAAa,iBACb,aAAa,EACb,GAAG,YACJ,GAAG;IAEJ,IAAI,cAAc,CAAA,GAAA,aAAK,EAAkB;IACzC,MAAM,OAAO;IAEb,IAAI,QAAQ,CAAA,GAAA,0BAAkB,EAAE;gBAC9B;oBACA;oBACA;QACA,qBAAoB,IAAI;YACtB,IAAI,OAAO,CAAC,UAAU,GAAG,KAAK,CAAC;YAC/B,IAAI,OAAO,CAAC,SAAS,GAAG,KAAK,CAAC;QAChC;uBACA;uBACA;IACF;IAEA,
|
|
1
|
+
{"mappings":";;;;;;AAAA;;;;;;;;;;CAUC;;;;;AA6BD,SAAS,kCAAsD,KAAgC,EAAE,GAAqC;IACpI,IAAI,EACF,UAAU,UAAU,iBACpB,aAAa,UACb,MAAM,cACN,UAAU,aACV,SAAS,mBACT,eAAe,aACf,6DA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AU;QACnC,aAAa,aAAa,WAAW;QACrC,MAAM,EAAE,mBAAA,6BAAA,OAAQ,UAAU;OACzB,aAAa,QAAQ;AAG5B","sources":["packages/@react-aria/virtualizer/src/Virtualizer.tsx"],"sourcesContent":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {Collection, Key, RefObject} from '@react-types/shared';\nimport {Layout, Rect, ReusableView, useVirtualizerState} from '@react-stately/virtualizer';\nimport {mergeProps, useLoadMore} from '@react-aria/utils';\nimport React, {HTMLAttributes, ReactElement, ReactNode, useCallback, useRef} from 'react';\nimport {ScrollView} from './ScrollView';\nimport {VirtualizerItem} from './VirtualizerItem';\n\ntype RenderWrapper<T extends object, V> = (\n parent: ReusableView<T, V> | null,\n reusableView: ReusableView<T, V>,\n children: ReusableView<T, V>[],\n renderChildren: (views: ReusableView<T, V>[]) => ReactElement[]\n) => ReactElement;\n\ninterface VirtualizerProps<T extends object, V, O> extends Omit<HTMLAttributes<HTMLElement>, 'children'> {\n children: (type: string, content: T) => V,\n renderWrapper?: RenderWrapper<T, V>,\n layout: Layout<T, O>,\n collection: Collection<T>,\n persistedKeys?: Set<Key> | null,\n sizeToFit?: 'width' | 'height',\n scrollDirection?: 'horizontal' | 'vertical' | 'both',\n isLoading?: boolean,\n onLoadMore?: () => void,\n layoutOptions?: O\n}\n\nfunction Virtualizer<T extends object, V extends ReactNode, O>(props: VirtualizerProps<T, V, O>, ref: RefObject<HTMLDivElement | null>) {\n let {\n children: renderView,\n renderWrapper,\n layout,\n collection,\n sizeToFit,\n scrollDirection,\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n isLoading,\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n onLoadMore,\n persistedKeys,\n layoutOptions,\n ...otherProps\n } = props;\n\n let fallbackRef = useRef<HTMLDivElement>(undefined);\n ref = ref || fallbackRef;\n\n let state = useVirtualizerState({\n layout,\n collection,\n renderView,\n onVisibleRectChange(rect) {\n ref.current.scrollLeft = rect.x;\n ref.current.scrollTop = rect.y;\n },\n persistedKeys,\n layoutOptions\n });\n\n useLoadMore({isLoading, onLoadMore, scrollOffset: 1}, ref);\n let onVisibleRectChange = useCallback((rect: Rect) => {\n state.setVisibleRect(rect);\n }, [state]);\n\n return (\n <ScrollView\n {...mergeProps(otherProps, {onVisibleRectChange})}\n ref={ref}\n contentSize={state.contentSize}\n onScrollStart={state.startScrolling}\n onScrollEnd={state.endScrolling}\n sizeToFit={sizeToFit}\n scrollDirection={scrollDirection}>\n {renderChildren(null, state.visibleViews, renderWrapper || defaultRenderWrapper)}\n </ScrollView>\n );\n}\n\n// forwardRef doesn't support generic parameters, so cast the result to the correct type\n// https://stackoverflow.com/questions/58469229/react-with-typescript-generics-while-using-react-forwardref\nconst _Virtualizer = React.forwardRef(Virtualizer) as <T extends object, V, O>(props: VirtualizerProps<T, V, O> & {ref?: RefObject<HTMLDivElement | null>}) => ReactElement;\nexport {_Virtualizer as Virtualizer};\n\nfunction renderChildren<T extends object, V>(parent: ReusableView<T, V> | null, views: ReusableView<T, V>[], renderWrapper: RenderWrapper<T, V>) {\n return views.map(view => {\n return renderWrapper(\n parent,\n view,\n view.children ? Array.from(view.children) : [],\n childViews => renderChildren(view, childViews, renderWrapper)\n );\n });\n}\n\nfunction defaultRenderWrapper<T extends object, V extends ReactNode>(\n parent: ReusableView<T, V> | null,\n reusableView: ReusableView<T, V>\n) {\n return (\n <VirtualizerItem\n key={reusableView.key}\n layoutInfo={reusableView.layoutInfo}\n virtualizer={reusableView.virtualizer}\n parent={parent?.layoutInfo}>\n {reusableView.rendered}\n </VirtualizerItem>\n );\n}\n"],"names":[],"version":3,"file":"Virtualizer.module.js.map"}
|
package/dist/import.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {Virtualizer as $6d0a5c394373ae64$export$89be5a243e59c4b2} from "./Virtualizer.mjs";
|
|
2
2
|
import {useVirtualizerItem as $47736c1e63ba1c6d$export$1da781778207e0a2} from "./useVirtualizerItem.mjs";
|
|
3
3
|
import {layoutInfoToStyle as $ccf8a0a04e4175ae$export$1481e64fbe01b8b3, VirtualizerItem as $ccf8a0a04e4175ae$export$6796df8ba7398521} from "./VirtualizerItem.mjs";
|
|
4
4
|
import {ScrollView as $44a6ee657928b002$export$5665e3d6be6adea, useScrollView as $44a6ee657928b002$export$2ea0c4974da4731b} from "./ScrollView.mjs";
|
|
@@ -21,5 +21,5 @@ import {getRTLOffsetType as $ce415dc67314b753$export$faf7630257ad4304, getScroll
|
|
|
21
21
|
|
|
22
22
|
|
|
23
23
|
|
|
24
|
-
export {$6d0a5c394373ae64$export$
|
|
24
|
+
export {$6d0a5c394373ae64$export$89be5a243e59c4b2 as Virtualizer, $47736c1e63ba1c6d$export$1da781778207e0a2 as useVirtualizerItem, $ccf8a0a04e4175ae$export$6796df8ba7398521 as VirtualizerItem, $ccf8a0a04e4175ae$export$1481e64fbe01b8b3 as layoutInfoToStyle, $44a6ee657928b002$export$5665e3d6be6adea as ScrollView, $44a6ee657928b002$export$2ea0c4974da4731b as useScrollView, $ce415dc67314b753$export$faf7630257ad4304 as getRTLOffsetType, $ce415dc67314b753$export$1389d168952b34b5 as getScrollLeft, $ce415dc67314b753$export$ed5fd5ffe5ab0ac as setScrollLeft};
|
|
25
25
|
//# sourceMappingURL=module.js.map
|
package/dist/main.js
CHANGED
|
@@ -9,7 +9,6 @@ function $parcel$export(e, n, v, s) {
|
|
|
9
9
|
Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
|
|
10
10
|
}
|
|
11
11
|
|
|
12
|
-
$parcel$export(module.exports, "useVirtualizer", () => $e1fb6f3669e1c329$exports.useVirtualizer);
|
|
13
12
|
$parcel$export(module.exports, "Virtualizer", () => $e1fb6f3669e1c329$exports.Virtualizer);
|
|
14
13
|
$parcel$export(module.exports, "useVirtualizerItem", () => $7d70e069fceb2deb$exports.useVirtualizerItem);
|
|
15
14
|
$parcel$export(module.exports, "VirtualizerItem", () => $d6a26279cc31826b$exports.VirtualizerItem);
|
package/dist/main.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":"
|
|
1
|
+
{"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;;;;;;;;;;CAUC","sources":["packages/@react-aria/virtualizer/src/index.ts"],"sourcesContent":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nexport type {RTLOffsetType} from './utils';\nexport type {VirtualizerItemOptions} from './useVirtualizerItem';\nexport {Virtualizer} from './Virtualizer';\nexport {useVirtualizerItem} from './useVirtualizerItem';\nexport {VirtualizerItem, layoutInfoToStyle} from './VirtualizerItem';\nexport {ScrollView, useScrollView} from './ScrollView';\nexport {getRTLOffsetType, getScrollLeft, setScrollLeft} from './utils';\n"],"names":[],"version":3,"file":"main.js.map"}
|
package/dist/module.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {Virtualizer as $6d0a5c394373ae64$export$89be5a243e59c4b2} from "./Virtualizer.module.js";
|
|
2
2
|
import {useVirtualizerItem as $47736c1e63ba1c6d$export$1da781778207e0a2} from "./useVirtualizerItem.module.js";
|
|
3
3
|
import {layoutInfoToStyle as $ccf8a0a04e4175ae$export$1481e64fbe01b8b3, VirtualizerItem as $ccf8a0a04e4175ae$export$6796df8ba7398521} from "./VirtualizerItem.module.js";
|
|
4
4
|
import {ScrollView as $44a6ee657928b002$export$5665e3d6be6adea, useScrollView as $44a6ee657928b002$export$2ea0c4974da4731b} from "./ScrollView.module.js";
|
|
@@ -21,5 +21,5 @@ import {getRTLOffsetType as $ce415dc67314b753$export$faf7630257ad4304, getScroll
|
|
|
21
21
|
|
|
22
22
|
|
|
23
23
|
|
|
24
|
-
export {$6d0a5c394373ae64$export$
|
|
24
|
+
export {$6d0a5c394373ae64$export$89be5a243e59c4b2 as Virtualizer, $47736c1e63ba1c6d$export$1da781778207e0a2 as useVirtualizerItem, $ccf8a0a04e4175ae$export$6796df8ba7398521 as VirtualizerItem, $ccf8a0a04e4175ae$export$1481e64fbe01b8b3 as layoutInfoToStyle, $44a6ee657928b002$export$5665e3d6be6adea as ScrollView, $44a6ee657928b002$export$2ea0c4974da4731b as useScrollView, $ce415dc67314b753$export$faf7630257ad4304 as getRTLOffsetType, $ce415dc67314b753$export$1389d168952b34b5 as getScrollLeft, $ce415dc67314b753$export$ed5fd5ffe5ab0ac as setScrollLeft};
|
|
25
25
|
//# sourceMappingURL=module.js.map
|
package/dist/module.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":";;;;;;AAAA;;;;;;;;;;CAUC","sources":["packages/@react-aria/virtualizer/src/index.ts"],"sourcesContent":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nexport type {RTLOffsetType} from './utils';\nexport type {VirtualizerItemOptions} from './useVirtualizerItem';\nexport {
|
|
1
|
+
{"mappings":";;;;;;AAAA;;;;;;;;;;CAUC","sources":["packages/@react-aria/virtualizer/src/index.ts"],"sourcesContent":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nexport type {RTLOffsetType} from './utils';\nexport type {VirtualizerItemOptions} from './useVirtualizerItem';\nexport {Virtualizer} from './Virtualizer';\nexport {useVirtualizerItem} from './useVirtualizerItem';\nexport {VirtualizerItem, layoutInfoToStyle} from './VirtualizerItem';\nexport {ScrollView, useScrollView} from './ScrollView';\nexport {getRTLOffsetType, getScrollLeft, setScrollLeft} from './utils';\n"],"names":[],"version":3,"file":"module.js.map"}
|
package/dist/types.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Direction, Key, RefObject, Collection } from "@react-types/shared";
|
|
2
|
-
import { LayoutInfo, Size, Rect, Layout, ReusableView
|
|
2
|
+
import { LayoutInfo, Size, Rect, Layout, ReusableView } from "@react-stately/virtualizer";
|
|
3
3
|
import React, { CSSProperties, HTMLAttributes, ReactNode, RefObject as _RefObject1, ReactElement } from "react";
|
|
4
4
|
export type RTLOffsetType = 'negative' | 'positive-descending' | 'positive-ascending';
|
|
5
5
|
export function getRTLOffsetType(recalculate?: boolean): RTLOffsetType;
|
|
@@ -332,18 +332,6 @@ interface VirtualizerProps<T extends object, V, O> extends Omit<HTMLAttributes<H
|
|
|
332
332
|
onLoadMore?: () => void;
|
|
333
333
|
layoutOptions?: O;
|
|
334
334
|
}
|
|
335
|
-
interface VirtualizerOptions {
|
|
336
|
-
tabIndex?: number;
|
|
337
|
-
focusedKey?: Key;
|
|
338
|
-
isLoading?: boolean;
|
|
339
|
-
onLoadMore?: () => void;
|
|
340
|
-
}
|
|
341
|
-
export function useVirtualizer<T extends object, V extends ReactNode, W>(props: VirtualizerOptions, state: VirtualizerState<T, V>, ref: RefObject<HTMLElement | null>): {
|
|
342
|
-
virtualizerProps: {};
|
|
343
|
-
scrollViewProps: {
|
|
344
|
-
onVisibleRectChange: (rect: Rect) => void;
|
|
345
|
-
};
|
|
346
|
-
};
|
|
347
335
|
export const Virtualizer: <T extends object, V, O>(props: VirtualizerProps<T, V, O> & {
|
|
348
336
|
ref?: RefObject<HTMLDivElement | null>;
|
|
349
337
|
}) => ReactElement;
|
package/dist/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":";;;AAcA,4BACI,UAAU,GACV,qBAAqB,GACrB,oBAAoB,CAAC;AAezB,iCAAiC,WAAW,GAAE,OAAe,GAAG,aAAa,CAmC5E;AAED,8BAA8B,IAAI,EAAE,OAAO,EAAE,SAAS,EAAE,SAAS,GAAG,MAAM,CAkBzE;AAED,8BAA8B,IAAI,EAAE,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,QAiBpF;ACzFD;IACE,cAAc,CAAC,GAAG,EAAE,GAAG,EAAE,IAAI,EAAE,IAAI,GAAG,IAAI,CAAA;CAC3C;AAED;IACE,UAAU,EAAE,UAAU,CAAC;IACvB,WAAW,EAAE,YAAY,CAAC;IAC1B,GAAG,EAAE,UAAU,WAAW,GAAG,IAAI,CAAC,CAAA;CACnC;AAED,mCAAmC,OAAO,EAAE,sBAAsB;;EAiBjE;ACdD,yBAA0B,SAAQ,eAAe,WAAW,CAAC;IAC3D,WAAW,EAAE,IAAI,CAAC;IAClB,mBAAmB,EAAE,CAAC,IAAI,EAAE,IAAI,KAAK,IAAI,CAAC;IAC1C,QAAQ,CAAC,EAAE,SAAS,CAAC;IACrB,UAAU,CA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,CAAC,CAAC,GAAG;IAAC,GAAG,CAAC,EAAE,UAAU,cAAc,GAAG,IAAI,CAAC,CAAA;CAAC,KAAK,YAAY,CAAC","sources":["packages/@react-aria/virtualizer/src/packages/@react-aria/virtualizer/src/utils.ts","packages/@react-aria/virtualizer/src/packages/@react-aria/virtualizer/src/useVirtualizerItem.ts","packages/@react-aria/virtualizer/src/packages/@react-aria/virtualizer/src/ScrollView.tsx","packages/@react-aria/virtualizer/src/packages/@react-aria/virtualizer/src/VirtualizerItem.tsx","packages/@react-aria/virtualizer/src/packages/@react-aria/virtualizer/src/Virtualizer.tsx","packages/@react-aria/virtualizer/src/packages/@react-aria/virtualizer/src/index.ts","packages/@react-aria/virtualizer/src/index.ts"],"sourcesContent":[null,null,null,null,null,null,"/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nexport type {RTLOffsetType} from './utils';\nexport type {VirtualizerItemOptions} from './useVirtualizerItem';\nexport {Virtualizer} from './Virtualizer';\nexport {useVirtualizerItem} from './useVirtualizerItem';\nexport {VirtualizerItem, layoutInfoToStyle} from './VirtualizerItem';\nexport {ScrollView, useScrollView} from './ScrollView';\nexport {getRTLOffsetType, getScrollLeft, setScrollLeft} from './utils';\n"],"names":[],"version":3,"file":"types.d.ts.map"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@react-aria/virtualizer",
|
|
3
|
-
"version": "3.10.2-nightly.
|
|
3
|
+
"version": "3.10.2-nightly.4709+4fc70174a",
|
|
4
4
|
"description": "Spectrum UI components in React",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"main": "dist/main.js",
|
|
@@ -22,11 +22,11 @@
|
|
|
22
22
|
"url": "https://github.com/adobe/react-spectrum"
|
|
23
23
|
},
|
|
24
24
|
"dependencies": {
|
|
25
|
-
"@react-aria/i18n": "3.0.0-nightly.
|
|
26
|
-
"@react-aria/interactions": "3.0.0-nightly.
|
|
27
|
-
"@react-aria/utils": "3.0.0-nightly.
|
|
28
|
-
"@react-stately/virtualizer": "3.7.2-nightly.
|
|
29
|
-
"@react-types/shared": "3.0.0-nightly.
|
|
25
|
+
"@react-aria/i18n": "3.0.0-nightly.2997+4fc70174a",
|
|
26
|
+
"@react-aria/interactions": "3.0.0-nightly.2997+4fc70174a",
|
|
27
|
+
"@react-aria/utils": "3.0.0-nightly.2997+4fc70174a",
|
|
28
|
+
"@react-stately/virtualizer": "3.7.2-nightly.4709+4fc70174a",
|
|
29
|
+
"@react-types/shared": "3.0.0-nightly.2997+4fc70174a",
|
|
30
30
|
"@swc/helpers": "^0.5.0"
|
|
31
31
|
},
|
|
32
32
|
"peerDependencies": {
|
|
@@ -36,5 +36,5 @@
|
|
|
36
36
|
"publishConfig": {
|
|
37
37
|
"access": "public"
|
|
38
38
|
},
|
|
39
|
-
"gitHead": "
|
|
39
|
+
"gitHead": "4fc70174ac35a5ebf06379f5cafaf943519a1eac"
|
|
40
40
|
}
|
package/src/Virtualizer.tsx
CHANGED
|
@@ -11,8 +11,8 @@
|
|
|
11
11
|
*/
|
|
12
12
|
|
|
13
13
|
import {Collection, Key, RefObject} from '@react-types/shared';
|
|
14
|
-
import {Layout, Rect, ReusableView, useVirtualizerState
|
|
15
|
-
import {mergeProps,
|
|
14
|
+
import {Layout, Rect, ReusableView, useVirtualizerState} from '@react-stately/virtualizer';
|
|
15
|
+
import {mergeProps, useLoadMore} from '@react-aria/utils';
|
|
16
16
|
import React, {HTMLAttributes, ReactElement, ReactNode, useCallback, useRef} from 'react';
|
|
17
17
|
import {ScrollView} from './ScrollView';
|
|
18
18
|
import {VirtualizerItem} from './VirtualizerItem';
|
|
@@ -69,11 +69,14 @@ function Virtualizer<T extends object, V extends ReactNode, O>(props: Virtualize
|
|
|
69
69
|
layoutOptions
|
|
70
70
|
});
|
|
71
71
|
|
|
72
|
-
|
|
72
|
+
useLoadMore({isLoading, onLoadMore, scrollOffset: 1}, ref);
|
|
73
|
+
let onVisibleRectChange = useCallback((rect: Rect) => {
|
|
74
|
+
state.setVisibleRect(rect);
|
|
75
|
+
}, [state]);
|
|
73
76
|
|
|
74
77
|
return (
|
|
75
78
|
<ScrollView
|
|
76
|
-
{...mergeProps(otherProps,
|
|
79
|
+
{...mergeProps(otherProps, {onVisibleRectChange})}
|
|
77
80
|
ref={ref}
|
|
78
81
|
contentSize={state.contentSize}
|
|
79
82
|
onScrollStart={state.startScrolling}
|
|
@@ -85,66 +88,6 @@ function Virtualizer<T extends object, V extends ReactNode, O>(props: Virtualize
|
|
|
85
88
|
);
|
|
86
89
|
}
|
|
87
90
|
|
|
88
|
-
interface VirtualizerOptions {
|
|
89
|
-
tabIndex?: number,
|
|
90
|
-
focusedKey?: Key,
|
|
91
|
-
isLoading?: boolean,
|
|
92
|
-
onLoadMore?: () => void
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
96
|
-
export function useVirtualizer<T extends object, V extends ReactNode, W>(props: VirtualizerOptions, state: VirtualizerState<T, V>, ref: RefObject<HTMLElement | null>) {
|
|
97
|
-
let {isLoading, onLoadMore} = props;
|
|
98
|
-
let {setVisibleRect, virtualizer} = state;
|
|
99
|
-
|
|
100
|
-
// Handle scrolling, and call onLoadMore when nearing the bottom.
|
|
101
|
-
let isLoadingRef = useRef(isLoading);
|
|
102
|
-
let prevProps = useRef(props);
|
|
103
|
-
let onVisibleRectChange = useCallback((rect: Rect) => {
|
|
104
|
-
setVisibleRect(rect);
|
|
105
|
-
|
|
106
|
-
if (!isLoadingRef.current && onLoadMore) {
|
|
107
|
-
let scrollOffset = virtualizer.contentSize.height - rect.height * 2;
|
|
108
|
-
if (rect.y > scrollOffset) {
|
|
109
|
-
isLoadingRef.current = true;
|
|
110
|
-
onLoadMore();
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
}, [onLoadMore, setVisibleRect, virtualizer]);
|
|
114
|
-
|
|
115
|
-
let lastContentSize = useRef(0);
|
|
116
|
-
useLayoutEffect(() => {
|
|
117
|
-
// Only update isLoadingRef if props object actually changed,
|
|
118
|
-
// not if a local state change occurred.
|
|
119
|
-
let wasLoading = isLoadingRef.current;
|
|
120
|
-
if (props !== prevProps.current) {
|
|
121
|
-
isLoadingRef.current = isLoading;
|
|
122
|
-
prevProps.current = props;
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
let shouldLoadMore = !isLoadingRef.current
|
|
126
|
-
&& onLoadMore
|
|
127
|
-
&& state.contentSize.height > 0
|
|
128
|
-
&& state.contentSize.height <= state.virtualizer.visibleRect.height
|
|
129
|
-
// Only try loading more if the content size changed, or if we just finished
|
|
130
|
-
// loading and still have room for more items.
|
|
131
|
-
&& (wasLoading || state.contentSize.height !== lastContentSize.current);
|
|
132
|
-
|
|
133
|
-
if (shouldLoadMore) {
|
|
134
|
-
isLoadingRef.current = true;
|
|
135
|
-
onLoadMore();
|
|
136
|
-
}
|
|
137
|
-
lastContentSize.current = state.contentSize.height;
|
|
138
|
-
}, [state.contentSize, state.virtualizer, isLoading, onLoadMore, props]);
|
|
139
|
-
|
|
140
|
-
return {
|
|
141
|
-
virtualizerProps: {},
|
|
142
|
-
scrollViewProps: {
|
|
143
|
-
onVisibleRectChange
|
|
144
|
-
}
|
|
145
|
-
};
|
|
146
|
-
}
|
|
147
|
-
|
|
148
91
|
// forwardRef doesn't support generic parameters, so cast the result to the correct type
|
|
149
92
|
// https://stackoverflow.com/questions/58469229/react-with-typescript-generics-while-using-react-forwardref
|
|
150
93
|
const _Virtualizer = React.forwardRef(Virtualizer) as <T extends object, V, O>(props: VirtualizerProps<T, V, O> & {ref?: RefObject<HTMLDivElement | null>}) => ReactElement;
|
package/src/index.ts
CHANGED
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
|
|
13
13
|
export type {RTLOffsetType} from './utils';
|
|
14
14
|
export type {VirtualizerItemOptions} from './useVirtualizerItem';
|
|
15
|
-
export {
|
|
15
|
+
export {Virtualizer} from './Virtualizer';
|
|
16
16
|
export {useVirtualizerItem} from './useVirtualizerItem';
|
|
17
17
|
export {VirtualizerItem, layoutInfoToStyle} from './VirtualizerItem';
|
|
18
18
|
export {ScrollView, useScrollView} from './ScrollView';
|