@react-stately/virtualizer 4.4.5 → 4.5.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/dist/import.mjs +2 -14
- package/dist/main.js +8 -20
- package/dist/main.js.map +1 -1
- package/dist/module.js +2 -14
- package/dist/module.js.map +1 -1
- package/dist/types/src/index.d.ts +2 -0
- package/package.json +15 -12
- package/src/index.ts +2 -11
- package/dist/Layout.main.js +0 -54
- package/dist/Layout.main.js.map +0 -1
- package/dist/Layout.mjs +0 -49
- package/dist/Layout.module.js +0 -49
- package/dist/Layout.module.js.map +0 -1
- package/dist/LayoutInfo.main.js +0 -52
- package/dist/LayoutInfo.main.js.map +0 -1
- package/dist/LayoutInfo.mjs +0 -47
- package/dist/LayoutInfo.module.js +0 -47
- package/dist/LayoutInfo.module.js.map +0 -1
- package/dist/OverscanManager.main.js +0 -52
- package/dist/OverscanManager.main.js.map +0 -1
- package/dist/OverscanManager.mjs +0 -47
- package/dist/OverscanManager.module.js +0 -47
- package/dist/OverscanManager.module.js.map +0 -1
- package/dist/Point.main.js +0 -40
- package/dist/Point.main.js.map +0 -1
- package/dist/Point.mjs +0 -35
- package/dist/Point.module.js +0 -35
- package/dist/Point.module.js.map +0 -1
- package/dist/Rect.main.js +0 -131
- package/dist/Rect.main.js.map +0 -1
- package/dist/Rect.mjs +0 -126
- package/dist/Rect.module.js +0 -126
- package/dist/Rect.module.js.map +0 -1
- package/dist/ReusableView.main.js +0 -69
- package/dist/ReusableView.main.js.map +0 -1
- package/dist/ReusableView.mjs +0 -63
- package/dist/ReusableView.module.js +0 -63
- package/dist/ReusableView.module.js.map +0 -1
- package/dist/Size.main.js +0 -40
- package/dist/Size.main.js.map +0 -1
- package/dist/Size.mjs +0 -35
- package/dist/Size.module.js +0 -35
- package/dist/Size.module.js.map +0 -1
- package/dist/Virtualizer.main.js +0 -239
- package/dist/Virtualizer.main.js.map +0 -1
- package/dist/Virtualizer.mjs +0 -234
- package/dist/Virtualizer.module.js +0 -234
- package/dist/Virtualizer.module.js.map +0 -1
- package/dist/types.d.ts +0 -368
- package/dist/types.d.ts.map +0 -1
- package/dist/useVirtualizerState.main.js +0 -101
- package/dist/useVirtualizerState.main.js.map +0 -1
- package/dist/useVirtualizerState.mjs +0 -92
- package/dist/useVirtualizerState.module.js +0 -92
- package/dist/useVirtualizerState.module.js.map +0 -1
- package/dist/utils.main.js +0 -27
- package/dist/utils.main.js.map +0 -1
- package/dist/utils.mjs +0 -22
- package/dist/utils.module.js +0 -22
- package/dist/utils.module.js.map +0 -1
- package/src/Layout.ts +0 -101
- package/src/LayoutInfo.ts +0 -118
- package/src/OverscanManager.ts +0 -56
- package/src/Point.ts +0 -45
- package/src/Rect.ts +0 -193
- package/src/ReusableView.ts +0 -98
- package/src/Size.ts +0 -43
- package/src/Virtualizer.ts +0 -363
- package/src/types.ts +0 -44
- package/src/useVirtualizerState.ts +0 -120
- package/src/utils.ts +0 -30
package/src/types.ts
DELETED
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Copyright 2020 Adobe. All rights reserved.
|
|
3
|
-
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
4
|
-
* you may not use this file except in compliance with the License. You may obtain a copy
|
|
5
|
-
* of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
6
|
-
*
|
|
7
|
-
* Unless required by applicable law or agreed to in writing, software distributed under
|
|
8
|
-
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
9
|
-
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
10
|
-
* governing permissions and limitations under the License.
|
|
11
|
-
*/
|
|
12
|
-
|
|
13
|
-
import {Collection, Key} from '@react-types/shared';
|
|
14
|
-
import {Layout} from './Layout';
|
|
15
|
-
import {Rect} from './Rect';
|
|
16
|
-
|
|
17
|
-
export interface InvalidationContext<O = any> {
|
|
18
|
-
contentChanged?: boolean,
|
|
19
|
-
offsetChanged?: boolean,
|
|
20
|
-
sizeChanged?: boolean,
|
|
21
|
-
itemSizeChanged?: boolean,
|
|
22
|
-
layoutOptionsChanged?: boolean,
|
|
23
|
-
layoutOptions?: O
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
export interface VirtualizerDelegate<T extends object, V> {
|
|
27
|
-
setVisibleRect(rect: Rect): void,
|
|
28
|
-
renderView(type: string, content: T | null): V,
|
|
29
|
-
invalidate(ctx: InvalidationContext): void
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
export interface VirtualizerRenderOptions<T extends object, O = any> {
|
|
33
|
-
layout: Layout<T>,
|
|
34
|
-
collection: Collection<T>,
|
|
35
|
-
persistedKeys?: Set<Key> | null,
|
|
36
|
-
visibleRect: Rect,
|
|
37
|
-
invalidationContext: InvalidationContext,
|
|
38
|
-
isScrolling: boolean,
|
|
39
|
-
layoutOptions?: O
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
export type Mutable<T> = {
|
|
43
|
-
-readonly[P in keyof T]: T[P]
|
|
44
|
-
};
|
|
@@ -1,120 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Copyright 2020 Adobe. All rights reserved.
|
|
3
|
-
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
4
|
-
* you may not use this file except in compliance with the License. You may obtain a copy
|
|
5
|
-
* of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
6
|
-
*
|
|
7
|
-
* Unless required by applicable law or agreed to in writing, software distributed under
|
|
8
|
-
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
9
|
-
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
10
|
-
* governing permissions and limitations under the License.
|
|
11
|
-
*/
|
|
12
|
-
|
|
13
|
-
import {Collection, Key} from '@react-types/shared';
|
|
14
|
-
import {InvalidationContext} from './types';
|
|
15
|
-
import {Layout} from './Layout';
|
|
16
|
-
import React, {useCallback, useMemo, useRef, useState} from 'react';
|
|
17
|
-
import {Rect} from './Rect';
|
|
18
|
-
import {ReusableView} from './ReusableView';
|
|
19
|
-
import {Size} from './Size';
|
|
20
|
-
import {Virtualizer} from './Virtualizer';
|
|
21
|
-
|
|
22
|
-
// During SSR, React emits a warning when calling useLayoutEffect.
|
|
23
|
-
// Since neither useLayoutEffect nor useEffect run on the server,
|
|
24
|
-
// we can suppress this by replace it with a noop on the server.
|
|
25
|
-
export const useLayoutEffect: typeof React.useLayoutEffect = typeof document !== 'undefined'
|
|
26
|
-
? React.useLayoutEffect
|
|
27
|
-
: () => {};
|
|
28
|
-
|
|
29
|
-
interface VirtualizerProps<T extends object, V, O> {
|
|
30
|
-
renderView(type: string, content: T | null): V,
|
|
31
|
-
layout: Layout<T>,
|
|
32
|
-
collection: Collection<T>,
|
|
33
|
-
onVisibleRectChange(rect: Rect): void,
|
|
34
|
-
persistedKeys?: Set<Key> | null,
|
|
35
|
-
layoutOptions?: O
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
export interface VirtualizerState<T extends object, V> {
|
|
39
|
-
visibleViews: ReusableView<T, V>[],
|
|
40
|
-
setVisibleRect: (rect: Rect) => void,
|
|
41
|
-
contentSize: Size,
|
|
42
|
-
virtualizer: Virtualizer<T, V>,
|
|
43
|
-
isScrolling: boolean,
|
|
44
|
-
startScrolling: () => void,
|
|
45
|
-
endScrolling: () => void
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
export function useVirtualizerState<T extends object, V, O = any>(opts: VirtualizerProps<T, V, O>): VirtualizerState<T, V> {
|
|
49
|
-
let [visibleRect, setVisibleRect] = useState(new Rect(0, 0, 0, 0));
|
|
50
|
-
let [isScrolling, setScrolling] = useState(false);
|
|
51
|
-
let [invalidationContext, setInvalidationContext] = useState<InvalidationContext>({});
|
|
52
|
-
let visibleRectChanged = useRef(false);
|
|
53
|
-
let [virtualizer] = useState(() => new Virtualizer<T, V>({
|
|
54
|
-
collection: opts.collection,
|
|
55
|
-
layout: opts.layout,
|
|
56
|
-
delegate: {
|
|
57
|
-
setVisibleRect(rect) {
|
|
58
|
-
setVisibleRect(rect);
|
|
59
|
-
visibleRectChanged.current = true;
|
|
60
|
-
},
|
|
61
|
-
// TODO: should changing these invalidate the entire cache?
|
|
62
|
-
renderView: opts.renderView,
|
|
63
|
-
invalidate: setInvalidationContext
|
|
64
|
-
}
|
|
65
|
-
}));
|
|
66
|
-
|
|
67
|
-
// onVisibleRectChange must be called from an effect, not during render.
|
|
68
|
-
useLayoutEffect(() => {
|
|
69
|
-
if (visibleRectChanged.current) {
|
|
70
|
-
visibleRectChanged.current = false;
|
|
71
|
-
opts.onVisibleRectChange(visibleRect);
|
|
72
|
-
}
|
|
73
|
-
});
|
|
74
|
-
|
|
75
|
-
let mergedInvalidationContext = useMemo(() => {
|
|
76
|
-
if (opts.layoutOptions != null) {
|
|
77
|
-
return {...invalidationContext, layoutOptions: opts.layoutOptions};
|
|
78
|
-
}
|
|
79
|
-
return invalidationContext;
|
|
80
|
-
}, [invalidationContext, opts.layoutOptions]);
|
|
81
|
-
|
|
82
|
-
let visibleViews = virtualizer.render({
|
|
83
|
-
layout: opts.layout,
|
|
84
|
-
collection: opts.collection,
|
|
85
|
-
persistedKeys: opts.persistedKeys,
|
|
86
|
-
layoutOptions: opts.layoutOptions,
|
|
87
|
-
visibleRect,
|
|
88
|
-
invalidationContext: mergedInvalidationContext,
|
|
89
|
-
isScrolling
|
|
90
|
-
});
|
|
91
|
-
|
|
92
|
-
let contentSize = virtualizer.contentSize;
|
|
93
|
-
|
|
94
|
-
let startScrolling = useCallback(() => {
|
|
95
|
-
setScrolling(true);
|
|
96
|
-
}, []);
|
|
97
|
-
let endScrolling = useCallback(() => {
|
|
98
|
-
setScrolling(false);
|
|
99
|
-
}, []);
|
|
100
|
-
|
|
101
|
-
let state = useMemo(() => ({
|
|
102
|
-
virtualizer,
|
|
103
|
-
visibleViews,
|
|
104
|
-
setVisibleRect,
|
|
105
|
-
contentSize,
|
|
106
|
-
isScrolling,
|
|
107
|
-
startScrolling,
|
|
108
|
-
endScrolling
|
|
109
|
-
}), [
|
|
110
|
-
virtualizer,
|
|
111
|
-
visibleViews,
|
|
112
|
-
setVisibleRect,
|
|
113
|
-
contentSize,
|
|
114
|
-
isScrolling,
|
|
115
|
-
startScrolling,
|
|
116
|
-
endScrolling
|
|
117
|
-
]);
|
|
118
|
-
|
|
119
|
-
return state;
|
|
120
|
-
}
|
package/src/utils.ts
DELETED
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Copyright 2020 Adobe. All rights reserved.
|
|
3
|
-
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
4
|
-
* you may not use this file except in compliance with the License. You may obtain a copy
|
|
5
|
-
* of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
6
|
-
*
|
|
7
|
-
* Unless required by applicable law or agreed to in writing, software distributed under
|
|
8
|
-
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
9
|
-
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
10
|
-
* governing permissions and limitations under the License.
|
|
11
|
-
*/
|
|
12
|
-
|
|
13
|
-
/** Returns whether two sets are equal. */
|
|
14
|
-
export function isSetEqual<T>(a: Set<T>, b: Set<T>): boolean {
|
|
15
|
-
if (a === b) {
|
|
16
|
-
return true;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
if (a.size !== b.size) {
|
|
20
|
-
return false;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
for (let key of a) {
|
|
24
|
-
if (!b.has(key)) {
|
|
25
|
-
return false;
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
return true;
|
|
30
|
-
}
|