@react-aria/virtualizer 4.1.12 → 4.2.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 (40) hide show
  1. package/dist/import.mjs +6 -6
  2. package/dist/main.js +14 -14
  3. package/dist/main.js.map +1 -1
  4. package/dist/module.js +6 -6
  5. package/dist/module.js.map +1 -1
  6. package/dist/types/src/index.d.ts +7 -0
  7. package/package.json +15 -16
  8. package/src/index.ts +8 -7
  9. package/dist/ScrollView.main.js +0 -228
  10. package/dist/ScrollView.main.js.map +0 -1
  11. package/dist/ScrollView.mjs +0 -218
  12. package/dist/ScrollView.module.js +0 -218
  13. package/dist/ScrollView.module.js.map +0 -1
  14. package/dist/Virtualizer.main.js +0 -84
  15. package/dist/Virtualizer.main.js.map +0 -1
  16. package/dist/Virtualizer.mjs +0 -75
  17. package/dist/Virtualizer.module.js +0 -75
  18. package/dist/Virtualizer.module.js.map +0 -1
  19. package/dist/VirtualizerItem.main.js +0 -90
  20. package/dist/VirtualizerItem.main.js.map +0 -1
  21. package/dist/VirtualizerItem.mjs +0 -80
  22. package/dist/VirtualizerItem.module.js +0 -80
  23. package/dist/VirtualizerItem.module.js.map +0 -1
  24. package/dist/types.d.ts +0 -60
  25. package/dist/types.d.ts.map +0 -1
  26. package/dist/useVirtualizerItem.main.js +0 -54
  27. package/dist/useVirtualizerItem.main.js.map +0 -1
  28. package/dist/useVirtualizerItem.mjs +0 -49
  29. package/dist/useVirtualizerItem.module.js +0 -49
  30. package/dist/useVirtualizerItem.module.js.map +0 -1
  31. package/dist/utils.main.js +0 -80
  32. package/dist/utils.main.js.map +0 -1
  33. package/dist/utils.mjs +0 -73
  34. package/dist/utils.module.js +0 -73
  35. package/dist/utils.module.js.map +0 -1
  36. package/src/ScrollView.tsx +0 -282
  37. package/src/Virtualizer.tsx +0 -113
  38. package/src/VirtualizerItem.tsx +0 -93
  39. package/src/useVirtualizerItem.ts +0 -55
  40. package/src/utils.ts +0 -107
@@ -1,93 +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 {Direction} from '@react-types/shared';
14
- import {LayoutInfo} from '@react-stately/virtualizer';
15
- import React, {CSSProperties, JSX, ReactNode, useRef} from 'react';
16
- import {useLocale} from '@react-aria/i18n';
17
- import {useVirtualizerItem, VirtualizerItemOptions} from './useVirtualizerItem';
18
-
19
- interface VirtualizerItemProps extends Omit<VirtualizerItemOptions, 'ref'> {
20
- layoutInfo: LayoutInfo,
21
- parent?: LayoutInfo | null,
22
- style?: CSSProperties,
23
- className?: string,
24
- children: ReactNode
25
- }
26
-
27
- export function VirtualizerItem(props: VirtualizerItemProps): JSX.Element {
28
- let {style, className, layoutInfo, virtualizer, parent, children} = props;
29
- let {direction} = useLocale();
30
- let ref = useRef<HTMLDivElement | null>(null);
31
- useVirtualizerItem({
32
- layoutInfo,
33
- virtualizer,
34
- ref
35
- });
36
-
37
- return (
38
- <div role="presentation" ref={ref} className={className} style={{...layoutInfoToStyle(layoutInfo, direction, parent), ...style}}>
39
- {children}
40
- </div>
41
- );
42
- }
43
-
44
- let cache = new WeakMap();
45
- export function layoutInfoToStyle(layoutInfo: LayoutInfo, dir: Direction, parent?: LayoutInfo | null): CSSProperties {
46
- let xProperty = dir === 'rtl' ? 'right' : 'left';
47
- let cached = cache.get(layoutInfo);
48
- if (cached && cached[xProperty] != null) {
49
- if (!parent) {
50
- return cached;
51
- }
52
-
53
- // Invalidate if the parent position changed.
54
- let top = layoutInfo.rect.y - parent.rect.y;
55
- let x = layoutInfo.rect.x - parent.rect.x;
56
- if (cached.top === top && cached[xProperty] === x) {
57
- return cached;
58
- }
59
- }
60
-
61
- let rectStyles: Record<string, number | undefined> = {
62
- // TODO: For layoutInfos that are sticky that have parents with overflow visible, their "top" will be relative to the to the nearest scrolling container
63
- // which WON'T be the parent since the parent has overflow visible. This means we shouldn't offset the height by the parent's position
64
- // Not 100% about this change here since it is quite ambigious what the scrolling container maybe and how its top is positioned with respect to the
65
- // calculated layoutInfo.y here
66
- top: layoutInfo.rect.y - (parent && !(parent.allowOverflow && layoutInfo.isSticky) ? parent.rect.y : 0),
67
- [xProperty]: layoutInfo.rect.x - (parent && !(parent.allowOverflow && layoutInfo.isSticky) ? parent.rect.x : 0),
68
- width: layoutInfo.rect.width,
69
- height: layoutInfo.rect.height
70
- };
71
-
72
- // Get rid of any non finite values since they aren't valid css values
73
- Object.entries(rectStyles).forEach(([key, value]) => {
74
- if (!Number.isFinite(value)) {
75
- rectStyles[key] = undefined;
76
- }
77
- });
78
-
79
- let style: CSSProperties = {
80
- position: layoutInfo.isSticky ? 'sticky' : 'absolute',
81
- // Sticky elements are positioned in normal document flow. Display inline-block so that they don't push other sticky columns onto the following rows.
82
- display: layoutInfo.isSticky ? 'inline-block' : undefined,
83
- overflow: layoutInfo.allowOverflow ? 'visible' : 'hidden',
84
- opacity: layoutInfo.opacity,
85
- zIndex: layoutInfo.zIndex,
86
- transform: layoutInfo.transform ?? undefined,
87
- contain: 'size layout style',
88
- ...rectStyles
89
- };
90
-
91
- cache.set(layoutInfo, style);
92
- return style;
93
- }
@@ -1,55 +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 {Key, RefObject} from '@react-types/shared';
14
- import {LayoutInfo, Size} from '@react-stately/virtualizer';
15
- import {useCallback} from 'react';
16
- import {useLayoutEffect} from '@react-aria/utils';
17
-
18
- interface IVirtualizer {
19
- updateItemSize(key: Key, size: Size): void
20
- }
21
-
22
- export interface VirtualizerItemOptions {
23
- layoutInfo: LayoutInfo | null,
24
- virtualizer: IVirtualizer,
25
- ref: RefObject<HTMLElement | null>
26
- }
27
-
28
- export function useVirtualizerItem(options: VirtualizerItemOptions): {updateSize: () => void} {
29
- let {layoutInfo, virtualizer, ref} = options;
30
- let key = layoutInfo?.key;
31
-
32
- let updateSize = useCallback(() => {
33
- if (key != null && ref.current) {
34
- let size = getSize(ref.current);
35
- virtualizer.updateItemSize(key, size);
36
- }
37
- }, [virtualizer, key, ref]);
38
-
39
- useLayoutEffect(() => {
40
- if (layoutInfo?.estimatedSize) {
41
- updateSize();
42
- }
43
- });
44
-
45
- return {updateSize};
46
- }
47
-
48
- function getSize(node: HTMLElement): Size {
49
- // Reset height before measuring so we get the intrinsic size
50
- let height = node.style.height;
51
- node.style.height = '';
52
- let size = new Size(node.scrollWidth, node.scrollHeight);
53
- node.style.height = height;
54
- return size;
55
- }
package/src/utils.ts DELETED
@@ -1,107 +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 {Direction} from '@react-types/shared';
14
-
15
- export type RTLOffsetType =
16
- | 'negative'
17
- | 'positive-descending'
18
- | 'positive-ascending';
19
-
20
- let cachedRTLResult: RTLOffsetType | null = null;
21
-
22
-
23
- // Original licensing for the following methods can be found in the
24
- // NOTICE file in the root directory of this source tree.
25
- // See https://github.com/bvaughn/react-window/blob/master/src/createGridComponent.js
26
-
27
- // According to the spec, scrollLeft should be negative for RTL aligned elements.
28
- // Chrome does not seem to adhere; its scrollLeft values are positive (measured relative to the left).
29
- // Safari's elastic bounce makes detecting this even more complicated wrt potential false positives.
30
- // The safest way to check this is to intentionally set a negative offset,
31
- // and then verify that the subsequent "scroll" event matches the negative offset.
32
- // If it does not match, then we can assume a non-standard RTL scroll implementation.
33
- export function getRTLOffsetType(recalculate: boolean = false): RTLOffsetType {
34
- if (cachedRTLResult === null || recalculate) {
35
- const outerDiv = document.createElement('div');
36
- const outerStyle = outerDiv.style;
37
- outerStyle.width = '50px';
38
- outerStyle.height = '50px';
39
- outerStyle.overflow = 'scroll';
40
- outerStyle.direction = 'rtl';
41
-
42
- const innerDiv = document.createElement('div');
43
- const innerStyle = innerDiv.style;
44
- innerStyle.width = '100px';
45
- innerStyle.height = '100px';
46
-
47
- outerDiv.appendChild(innerDiv);
48
-
49
- document.body.appendChild(outerDiv);
50
-
51
- if (outerDiv.scrollLeft > 0) {
52
- cachedRTLResult = 'positive-descending';
53
- } else {
54
- outerDiv.scrollLeft = 1;
55
- if (outerDiv.scrollLeft === 0) {
56
- cachedRTLResult = 'negative';
57
- } else {
58
- cachedRTLResult = 'positive-ascending';
59
- }
60
- }
61
-
62
- document.body.removeChild(outerDiv);
63
-
64
- return cachedRTLResult;
65
- }
66
-
67
- return cachedRTLResult;
68
- }
69
-
70
- export function getScrollLeft(node: Element, direction: Direction): number {
71
- let {scrollLeft} = node;
72
-
73
- // scrollLeft in rtl locales differs across browsers, so normalize.
74
- // See comment by getRTLOffsetType below for details.
75
- if (direction === 'rtl') {
76
- let {scrollWidth, clientWidth} = node;
77
- switch (getRTLOffsetType()) {
78
- case 'negative':
79
- scrollLeft = -scrollLeft;
80
- break;
81
- case 'positive-descending':
82
- scrollLeft = scrollWidth - clientWidth - scrollLeft;
83
- break;
84
- }
85
- }
86
-
87
- return scrollLeft;
88
- }
89
-
90
- export function setScrollLeft(node: Element, direction: Direction, scrollLeft: number): void {
91
- if (direction === 'rtl') {
92
- switch (getRTLOffsetType()) {
93
- case 'negative':
94
- scrollLeft = -scrollLeft;
95
- break;
96
- case 'positive-ascending':
97
- break;
98
- default: {
99
- const {clientWidth, scrollWidth} = node;
100
- scrollLeft = scrollWidth - clientWidth - scrollLeft;
101
- break;
102
- }
103
- }
104
- }
105
-
106
- node.scrollLeft = scrollLeft;
107
- }