@react-stately/virtualizer 4.4.6 → 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.
Files changed (71) hide show
  1. package/dist/import.mjs +2 -14
  2. package/dist/main.js +8 -20
  3. package/dist/main.js.map +1 -1
  4. package/dist/module.js +2 -14
  5. package/dist/module.js.map +1 -1
  6. package/dist/types/src/index.d.ts +2 -0
  7. package/package.json +15 -12
  8. package/src/index.ts +2 -11
  9. package/dist/Layout.main.js +0 -54
  10. package/dist/Layout.main.js.map +0 -1
  11. package/dist/Layout.mjs +0 -49
  12. package/dist/Layout.module.js +0 -49
  13. package/dist/Layout.module.js.map +0 -1
  14. package/dist/LayoutInfo.main.js +0 -52
  15. package/dist/LayoutInfo.main.js.map +0 -1
  16. package/dist/LayoutInfo.mjs +0 -47
  17. package/dist/LayoutInfo.module.js +0 -47
  18. package/dist/LayoutInfo.module.js.map +0 -1
  19. package/dist/OverscanManager.main.js +0 -52
  20. package/dist/OverscanManager.main.js.map +0 -1
  21. package/dist/OverscanManager.mjs +0 -47
  22. package/dist/OverscanManager.module.js +0 -47
  23. package/dist/OverscanManager.module.js.map +0 -1
  24. package/dist/Point.main.js +0 -40
  25. package/dist/Point.main.js.map +0 -1
  26. package/dist/Point.mjs +0 -35
  27. package/dist/Point.module.js +0 -35
  28. package/dist/Point.module.js.map +0 -1
  29. package/dist/Rect.main.js +0 -131
  30. package/dist/Rect.main.js.map +0 -1
  31. package/dist/Rect.mjs +0 -126
  32. package/dist/Rect.module.js +0 -126
  33. package/dist/Rect.module.js.map +0 -1
  34. package/dist/ReusableView.main.js +0 -69
  35. package/dist/ReusableView.main.js.map +0 -1
  36. package/dist/ReusableView.mjs +0 -63
  37. package/dist/ReusableView.module.js +0 -63
  38. package/dist/ReusableView.module.js.map +0 -1
  39. package/dist/Size.main.js +0 -40
  40. package/dist/Size.main.js.map +0 -1
  41. package/dist/Size.mjs +0 -35
  42. package/dist/Size.module.js +0 -35
  43. package/dist/Size.module.js.map +0 -1
  44. package/dist/Virtualizer.main.js +0 -239
  45. package/dist/Virtualizer.main.js.map +0 -1
  46. package/dist/Virtualizer.mjs +0 -234
  47. package/dist/Virtualizer.module.js +0 -234
  48. package/dist/Virtualizer.module.js.map +0 -1
  49. package/dist/types.d.ts +0 -368
  50. package/dist/types.d.ts.map +0 -1
  51. package/dist/useVirtualizerState.main.js +0 -101
  52. package/dist/useVirtualizerState.main.js.map +0 -1
  53. package/dist/useVirtualizerState.mjs +0 -92
  54. package/dist/useVirtualizerState.module.js +0 -92
  55. package/dist/useVirtualizerState.module.js.map +0 -1
  56. package/dist/utils.main.js +0 -27
  57. package/dist/utils.main.js.map +0 -1
  58. package/dist/utils.mjs +0 -22
  59. package/dist/utils.module.js +0 -22
  60. package/dist/utils.module.js.map +0 -1
  61. package/src/Layout.ts +0 -101
  62. package/src/LayoutInfo.ts +0 -118
  63. package/src/OverscanManager.ts +0 -56
  64. package/src/Point.ts +0 -45
  65. package/src/Rect.ts +0 -193
  66. package/src/ReusableView.ts +0 -98
  67. package/src/Size.ts +0 -43
  68. package/src/Virtualizer.ts +0 -363
  69. package/src/types.ts +0 -44
  70. package/src/useVirtualizerState.ts +0 -120
  71. 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
- }