@react-aria/virtualizer 3.10.2-nightly.4674 → 3.10.2-nightly.4683
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/ScrollView.main.js +45 -19
- package/dist/ScrollView.main.js.map +1 -1
- package/dist/ScrollView.mjs +46 -21
- package/dist/ScrollView.module.js +46 -21
- package/dist/ScrollView.module.js.map +1 -1
- package/dist/Virtualizer.main.js +2 -2
- package/dist/Virtualizer.main.js.map +1 -1
- package/dist/Virtualizer.mjs +2 -2
- package/dist/Virtualizer.module.js +2 -2
- package/dist/Virtualizer.module.js.map +1 -1
- package/dist/VirtualizerItem.main.js +4 -2
- package/dist/VirtualizerItem.main.js.map +1 -1
- package/dist/VirtualizerItem.mjs +4 -2
- package/dist/VirtualizerItem.module.js +4 -2
- package/dist/VirtualizerItem.module.js.map +1 -1
- package/dist/import.mjs +2 -2
- package/dist/main.js +1 -0
- 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 +289 -5
- package/dist/types.d.ts.map +1 -1
- package/dist/useVirtualizerItem.main.js.map +1 -1
- package/dist/useVirtualizerItem.module.js.map +1 -1
- package/package.json +9 -9
- package/src/ScrollView.tsx +50 -21
- package/src/Virtualizer.tsx +5 -5
- package/src/VirtualizerItem.tsx +5 -3
- package/src/index.ts +1 -1
- package/src/useVirtualizerItem.ts +1 -1
package/dist/ScrollView.main.js
CHANGED
|
@@ -14,6 +14,7 @@ function $parcel$export(e, n, v, s) {
|
|
|
14
14
|
Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
|
|
15
15
|
}
|
|
16
16
|
|
|
17
|
+
$parcel$export(module.exports, "useScrollView", () => $00ca8c0b29e3e07c$export$2ea0c4974da4731b);
|
|
17
18
|
$parcel$export(module.exports, "ScrollView", () => $00ca8c0b29e3e07c$export$5665e3d6be6adea);
|
|
18
19
|
/*
|
|
19
20
|
* Copyright 2020 Adobe. All rights reserved.
|
|
@@ -33,9 +34,20 @@ $parcel$export(module.exports, "ScrollView", () => $00ca8c0b29e3e07c$export$5665
|
|
|
33
34
|
|
|
34
35
|
|
|
35
36
|
function $00ca8c0b29e3e07c$var$ScrollView(props, ref) {
|
|
36
|
-
|
|
37
|
-
let
|
|
38
|
-
|
|
37
|
+
ref = (0, $kvIfm$reactariautils.useObjectRef)(ref);
|
|
38
|
+
let { scrollViewProps: scrollViewProps, contentProps: contentProps } = $00ca8c0b29e3e07c$export$2ea0c4974da4731b(props, ref);
|
|
39
|
+
return /*#__PURE__*/ (0, ($parcel$interopDefault($kvIfm$react))).createElement("div", {
|
|
40
|
+
role: "presentation",
|
|
41
|
+
...scrollViewProps,
|
|
42
|
+
ref: ref
|
|
43
|
+
}, /*#__PURE__*/ (0, ($parcel$interopDefault($kvIfm$react))).createElement("div", {
|
|
44
|
+
role: "presentation",
|
|
45
|
+
...contentProps
|
|
46
|
+
}, props.children));
|
|
47
|
+
}
|
|
48
|
+
const $00ca8c0b29e3e07c$export$5665e3d6be6adea = /*#__PURE__*/ (0, ($parcel$interopDefault($kvIfm$react))).forwardRef($00ca8c0b29e3e07c$var$ScrollView);
|
|
49
|
+
function $00ca8c0b29e3e07c$export$2ea0c4974da4731b(props, ref) {
|
|
50
|
+
let { contentSize: contentSize, onVisibleRectChange: onVisibleRectChange, innerStyle: innerStyle, sizeToFit: sizeToFit, onScrollStart: onScrollStart, onScrollEnd: onScrollEnd, scrollDirection: scrollDirection = 'both', ...otherProps } = props;
|
|
39
51
|
let state = (0, $kvIfm$react.useRef)({
|
|
40
52
|
scrollTop: 0,
|
|
41
53
|
scrollLeft: 0,
|
|
@@ -86,6 +98,8 @@ function $00ca8c0b29e3e07c$var$ScrollView(props, ref) {
|
|
|
86
98
|
onScrollStart,
|
|
87
99
|
onScrollEnd
|
|
88
100
|
]);
|
|
101
|
+
// Attach event directly to ref so RAC Virtualizer doesn't need to send props upward.
|
|
102
|
+
(0, $kvIfm$reactariautils.useEvent)(ref, 'scroll', onScroll);
|
|
89
103
|
// eslint-disable-next-line arrow-body-style
|
|
90
104
|
(0, $kvIfm$react.useEffect)(()=>{
|
|
91
105
|
return ()=>{
|
|
@@ -127,12 +141,26 @@ function $00ca8c0b29e3e07c$var$ScrollView(props, ref) {
|
|
|
127
141
|
}
|
|
128
142
|
}
|
|
129
143
|
});
|
|
144
|
+
let didUpdateSize = (0, $kvIfm$react.useRef)(false);
|
|
130
145
|
(0, $kvIfm$reactariautils.useLayoutEffect)(()=>{
|
|
131
|
-
// React doesn't allow flushSync inside effects so
|
|
132
|
-
//
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
146
|
+
// React doesn't allow flushSync inside effects, so queue a microtask.
|
|
147
|
+
// We also need to wait until all refs are set (e.g. when passing a ref down from a parent).
|
|
148
|
+
queueMicrotask(()=>{
|
|
149
|
+
if (!didUpdateSize.current) {
|
|
150
|
+
didUpdateSize.current = true;
|
|
151
|
+
updateSize((0, $kvIfm$reactdom.flushSync));
|
|
152
|
+
}
|
|
153
|
+
});
|
|
154
|
+
}, [
|
|
155
|
+
updateSize
|
|
156
|
+
]);
|
|
157
|
+
(0, $kvIfm$react.useEffect)(()=>{
|
|
158
|
+
if (!didUpdateSize.current) {
|
|
159
|
+
// If useEffect ran before the above microtask, we are in a synchronous render (e.g. act).
|
|
160
|
+
// Update the size here so that you don't need to mock timers in tests.
|
|
161
|
+
didUpdateSize.current = true;
|
|
162
|
+
updateSize((fn)=>fn());
|
|
163
|
+
}
|
|
136
164
|
}, [
|
|
137
165
|
updateSize
|
|
138
166
|
]);
|
|
@@ -170,18 +198,16 @@ function $00ca8c0b29e3e07c$var$ScrollView(props, ref) {
|
|
|
170
198
|
position: 'relative',
|
|
171
199
|
...innerStyle
|
|
172
200
|
};
|
|
173
|
-
return
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
}, children));
|
|
201
|
+
return {
|
|
202
|
+
scrollViewProps: {
|
|
203
|
+
...otherProps,
|
|
204
|
+
style: style
|
|
205
|
+
},
|
|
206
|
+
contentProps: {
|
|
207
|
+
style: innerStyle
|
|
208
|
+
}
|
|
209
|
+
};
|
|
183
210
|
}
|
|
184
|
-
const $00ca8c0b29e3e07c$export$5665e3d6be6adea = /*#__PURE__*/ (0, ($parcel$interopDefault($kvIfm$react))).forwardRef($00ca8c0b29e3e07c$var$ScrollView);
|
|
185
211
|
|
|
186
212
|
|
|
187
213
|
//# sourceMappingURL=ScrollView.main.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":";;;;;;;;;;;;;;;;;AAAA;;;;;;;;;;CAUC,GAED,aAAa;;;;;;;AA4Bb,SAAS,iCAAW,KAAsB,EAAE,GAA8B;IACxE,IAAI,eACF,WAAW,uBACX,mBAAmB,YACnB,QAAQ,cACR,UAAU,aACV,SAAS,iBACT,aAAa,eACb,WAAW,mBACX,kBAAkB,QAClB,GAAG,YACJ,GAAG;IAEJ,IAAI,aAAa,CAAA,GAAA,mBAAK;IACtB,MAAM,OAAO;IACb,IAAI,QAAQ,CAAA,GAAA,mBAAK,EAAE;QACjB,WAAW;QACX,YAAY;QACZ,eAAe;QACf,eAAe;QACf,OAAO;QACP,QAAQ;QACR,aAAa;IACf,GAAG,OAAO;IACV,IAAI,aAAC,SAAS,EAAC,GAAG,CAAA,GAAA,8BAAQ;IAE1B,IAAI,CAAC,aAAa,aAAa,GAAG,CAAA,GAAA,qBAAO,EAAE;IAC3C,IAAI,WAAW,CAAA,GAAA,wBAAU,EAAE,CAAC;QAC1B,IAAI,EAAE,MAAM,KAAK,EAAE,aAAa,EAC9B;QAGF,IAAI,MAAM,QAAQ,EAChB,MAAM,QAAQ,CAAC;QAGjB,CAAA,GAAA,yBAAQ,EAAE;YACR,IAAI,YAAY,EAAE,aAAa,CAAC,SAAS;YACzC,IAAI,aAAa,CAAA,GAAA,uCAAY,EA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AAA,GAAA,uCAAgB,EAAE;aAAC;QAAK,KAAK;kBAAc;IAAQ;IAEnD,IAAI,QAA6B;QAC/B,iGAAiG;QACjG,SAAS;QACT,GAAG,WAAW,KAAK;IACrB;IAEA,IAAI,oBAAoB,cAAc;QACpC,MAAM,SAAS,GAAG;QAClB,MAAM,SAAS,GAAG;IACpB,OAAO,IAAI,oBAAoB,cAAc,YAAY,KAAK,KAAK,MAAM,KAAK,EAAE;QAC9E,mFAAmF;QACnF,6FAA6F;QAC7F,iFAAiF;QACjF,MAAM,SAAS,GAAG;QAClB,MAAM,SAAS,GAAG;IACpB,OACE,MAAM,QAAQ,GAAG;IAGnB,aAAa;QACX,OAAO,OAAO,QAAQ,CAAC,YAAY,KAAK,IAAI,YAAY,KAAK,GAAG;QAChE,QAAQ,OAAO,QAAQ,CAAC,YAAY,MAAM,IAAI,YAAY,MAAM,GAAG;QACnE,eAAe,cAAc,SAAS;QACtC,UAAU;QACV,GAAG,UAAU;IACf;IAEA,qBACE,0DAAC;QAAI,MAAK;QAAgB,GAAG,UAAU;QAAE,OAAO;QAAO,KAAK;QAAK,UAAU;qBACzE,0DAAC;QAAI,MAAK;QAAe,OAAO;OAC7B;AAIT;AAEA,MAAM,yDAAuB,CAAA,GAAA,sCAAI,EAAE,UAAU,CAAC","sources":["packages/@react-aria/virtualizer/src/ScrollView.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\n// @ts-ignore\nimport {flushSync} from 'react-dom';\nimport {getScrollLeft} from './utils';\nimport React, {\n CSSProperties,\n HTMLAttributes,\n ReactNode,\n RefObject,\n useCallback,\n useEffect,\n useRef,\n useState\n} from 'react';\nimport {Rect, Size} from '@react-stately/virtualizer';\nimport {useEffectEvent, useLayoutEffect, useResizeObserver} from '@react-aria/utils';\nimport {useLocale} from '@react-aria/i18n';\n\ninterface ScrollViewProps extends HTMLAttributes<HTMLElement> {\n contentSize: Size,\n onVisibleRectChange: (rect: Rect) => void,\n children: ReactNode,\n innerStyle?: CSSProperties,\n sizeToFit?: 'width' | 'height',\n onScrollStart?: () => void,\n onScrollEnd?: () => void,\n scrollDirection?: 'horizontal' | 'vertical' | 'both'\n}\n\nfunction ScrollView(props: ScrollViewProps, ref: RefObject<HTMLDivElement>) {\n let {\n contentSize,\n onVisibleRectChange,\n children,\n innerStyle,\n sizeToFit,\n onScrollStart,\n onScrollEnd,\n scrollDirection = 'both',\n ...otherProps\n } = props;\n\n let defaultRef = useRef();\n ref = ref || defaultRef;\n let state = useRef({\n scrollTop: 0,\n scrollLeft: 0,\n scrollEndTime: 0,\n scrollTimeout: null,\n width: 0,\n height: 0,\n isScrolling: false\n }).current;\n let {direction} = useLocale();\n\n let [isScrolling, setScrolling] = useState(false);\n let onScroll = useCallback((e) => {\n if (e.target !== e.currentTarget) {\n return;\n }\n\n if (props.onScroll) {\n props.onScroll(e);\n }\n\n flushSync(() => {\n let scrollTop = e.currentTarget.scrollTop;\n let scrollLeft = getScrollLeft(e.currentTarget, direction);\n\n // Prevent rubber band scrolling from shaking when scrolling out of bounds\n state.scrollTop = Math.max(0, Math.min(scrollTop, contentSize.height - state.height));\n state.scrollLeft = Math.max(0, Math.min(scrollLeft, contentSize.width - state.width));\n\n onVisibleRectChange(new Rect(state.scrollLeft, state.scrollTop, state.width, state.height));\n\n if (!state.isScrolling) {\n state.isScrolling = true;\n setScrolling(true);\n\n if (onScrollStart) {\n onScrollStart();\n }\n }\n\n // So we don't constantly call clearTimeout and setTimeout,\n // keep track of the current timeout time and only reschedule\n // the timer when it is getting close.\n let now = Date.now();\n if (state.scrollEndTime <= now + 50) {\n state.scrollEndTime = now + 300;\n\n clearTimeout(state.scrollTimeout);\n state.scrollTimeout = setTimeout(() => {\n state.isScrolling = false;\n setScrolling(false);\n state.scrollTimeout = null;\n\n if (onScrollEnd) {\n onScrollEnd();\n }\n }, 300);\n }\n });\n }, [props, direction, state, contentSize, onVisibleRectChange, onScrollStart, onScrollEnd]);\n\n // eslint-disable-next-line arrow-body-style\n useEffect(() => {\n return () => {\n clearTimeout(state.scrollTimeout);\n };\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, []);\n\n let updateSize = useEffectEvent((flush: typeof flushSync) => {\n let dom = ref.current;\n if (!dom) {\n return;\n }\n\n let isTestEnv = process.env.NODE_ENV === 'test' && !process.env.VIRT_ON;\n let isClientWidthMocked = Object.getOwnPropertyNames(window.HTMLElement.prototype).includes('clientWidth');\n let isClientHeightMocked = Object.getOwnPropertyNames(window.HTMLElement.prototype).includes('clientHeight');\n let clientWidth = dom.clientWidth;\n let clientHeight = dom.clientHeight;\n let w = isTestEnv && !isClientWidthMocked ? Infinity : clientWidth;\n let h = isTestEnv && !isClientHeightMocked ? Infinity : clientHeight;\n\n if (sizeToFit && contentSize.width > 0 && contentSize.height > 0) {\n if (sizeToFit === 'width') {\n w = Math.min(w, contentSize.width);\n } else if (sizeToFit === 'height') {\n h = Math.min(h, contentSize.height);\n }\n }\n\n if (state.width !== w || state.height !== h) {\n state.width = w;\n state.height = h;\n flush(() => {\n onVisibleRectChange(new Rect(state.scrollLeft, state.scrollTop, w, h));\n });\n\n // If the clientWidth or clientHeight changed, scrollbars appeared or disappeared as\n // a result of the layout update. In this case, re-layout again to account for the\n // adjusted space. In very specific cases this might result in the scrollbars disappearing\n // again, resulting in extra padding. We stop after a maximum of two layout passes to avoid\n // an infinite loop. This matches how browsers behavior with native CSS grid layout.\n if (!isTestEnv && clientWidth !== dom.clientWidth || clientHeight !== dom.clientHeight) {\n state.width = dom.clientWidth;\n state.height = dom.clientHeight;\n flush(() => {\n onVisibleRectChange(new Rect(state.scrollLeft, state.scrollTop, state.width, state.height));\n });\n }\n }\n });\n\n useLayoutEffect(() => {\n // React doesn't allow flushSync inside effects so pass an identity function instead.\n // This only happens on initial render. The resize observer will also call updateSize\n // once it initializes, but we need earlier initialization in a layout effect to avoid\n // a flash of missing content.\n updateSize(fn => fn());\n }, [updateSize]);\n let onResize = useCallback(() => {\n updateSize(flushSync);\n }, [updateSize]);\n // Watch border-box instead of of content-box so that we don't go into\n // an infinite loop when scrollbars appear or disappear.\n useResizeObserver({ref, box: 'border-box', onResize});\n\n let style: React.CSSProperties = {\n // Reset padding so that relative positioning works correctly. Padding will be done in JS layout.\n padding: 0,\n ...otherProps.style\n };\n\n if (scrollDirection === 'horizontal') {\n style.overflowX = 'auto';\n style.overflowY = 'hidden';\n } else if (scrollDirection === 'vertical' || contentSize.width === state.width) {\n // Set overflow-x: hidden if content size is equal to the width of the scroll view.\n // This prevents horizontal scrollbars from flickering during resizing due to resize observer\n // firing slower than the frame rate, which may cause an infinite re-render loop.\n style.overflowY = 'auto';\n style.overflowX = 'hidden';\n } else {\n style.overflow = 'auto';\n }\n\n innerStyle = {\n width: Number.isFinite(contentSize.width) ? contentSize.width : undefined,\n height: Number.isFinite(contentSize.height) ? contentSize.height : undefined,\n pointerEvents: isScrolling ? 'none' : 'auto',\n position: 'relative',\n ...innerStyle\n };\n\n return (\n <div role=\"presentation\" {...otherProps} style={style} ref={ref} onScroll={onScroll}>\n <div role=\"presentation\" style={innerStyle}>\n {children}\n </div>\n </div>\n );\n}\n\nconst ScrollViewForwardRef = React.forwardRef(ScrollView);\nexport {ScrollViewForwardRef as ScrollView};\n"],"names":[],"version":3,"file":"ScrollView.main.js.map"}
|
|
1
|
+
{"mappings":";;;;;;;;;;;;;;;;;;AAAA;;;;;;;;;;CAUC,GAED,aAAa;;;;;;;AA6Bb,SAAS,iCAAW,KAAsB,EAAE,GAAwC;IAClF,MAAM,CAAA,GAAA,kCAAW,EAAE;IACnB,IAAI,mBAAC,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W;IAEf,sEAAsE;IACtE,wDAAwD;IACxD,CAAA,GAAA,uCAAgB,EAAE;aAAC;QAAK,KAAK;kBAAc;IAAQ;IAEnD,IAAI,QAA6B;QAC/B,iGAAiG;QACjG,SAAS;QACT,GAAG,WAAW,KAAK;IACrB;IAEA,IAAI,oBAAoB,cAAc;QACpC,MAAM,SAAS,GAAG;QAClB,MAAM,SAAS,GAAG;IACpB,OAAO,IAAI,oBAAoB,cAAc,YAAY,KAAK,KAAK,MAAM,KAAK,EAAE;QAC9E,mFAAmF;QACnF,6FAA6F;QAC7F,iFAAiF;QACjF,MAAM,SAAS,GAAG;QAClB,MAAM,SAAS,GAAG;IACpB,OACE,MAAM,QAAQ,GAAG;IAGnB,aAAa;QACX,OAAO,OAAO,QAAQ,CAAC,YAAY,KAAK,IAAI,YAAY,KAAK,GAAG;QAChE,QAAQ,OAAO,QAAQ,CAAC,YAAY,MAAM,IAAI,YAAY,MAAM,GAAG;QACnE,eAAe,cAAc,SAAS;QACtC,UAAU;QACV,GAAG,UAAU;IACf;IAEA,OAAO;QACL,iBAAiB;YACf,GAAG,UAAU;mBACb;QACF;QACA,cAAc;YACZ,OAAO;QACT;IACF;AACF","sources":["packages/@react-aria/virtualizer/src/ScrollView.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\n// @ts-ignore\nimport {flushSync} from 'react-dom';\nimport {getScrollLeft} from './utils';\nimport React, {\n CSSProperties,\n ForwardedRef,\n HTMLAttributes,\n ReactNode,\n RefObject,\n useCallback,\n useEffect,\n useRef,\n useState\n} from 'react';\nimport {Rect, Size} from '@react-stately/virtualizer';\nimport {useEffectEvent, useEvent, useLayoutEffect, useObjectRef, useResizeObserver} from '@react-aria/utils';\nimport {useLocale} from '@react-aria/i18n';\n\ninterface ScrollViewProps extends HTMLAttributes<HTMLElement> {\n contentSize: Size,\n onVisibleRectChange: (rect: Rect) => void,\n children?: ReactNode,\n innerStyle?: CSSProperties,\n sizeToFit?: 'width' | 'height',\n onScrollStart?: () => void,\n onScrollEnd?: () => void,\n scrollDirection?: 'horizontal' | 'vertical' | 'both'\n}\n\nfunction ScrollView(props: ScrollViewProps, ref: ForwardedRef<HTMLDivElement | null>) {\n ref = useObjectRef(ref);\n let {scrollViewProps, contentProps} = useScrollView(props, ref);\n\n return (\n <div role=\"presentation\" {...scrollViewProps} ref={ref}>\n <div role=\"presentation\" {...contentProps}>\n {props.children}\n </div>\n </div>\n );\n}\n\nconst ScrollViewForwardRef = React.forwardRef(ScrollView);\nexport {ScrollViewForwardRef as ScrollView};\n\nexport function useScrollView(props: ScrollViewProps, ref: RefObject<HTMLElement | null>) {\n let {\n contentSize,\n onVisibleRectChange,\n innerStyle,\n sizeToFit,\n onScrollStart,\n onScrollEnd,\n scrollDirection = 'both',\n ...otherProps\n } = props;\n\n let state = useRef({\n scrollTop: 0,\n scrollLeft: 0,\n scrollEndTime: 0,\n scrollTimeout: null,\n width: 0,\n height: 0,\n isScrolling: false\n }).current;\n let {direction} = useLocale();\n\n let [isScrolling, setScrolling] = useState(false);\n let onScroll = useCallback((e) => {\n if (e.target !== e.currentTarget) {\n return;\n }\n\n if (props.onScroll) {\n props.onScroll(e);\n }\n\n flushSync(() => {\n let scrollTop = e.currentTarget.scrollTop;\n let scrollLeft = getScrollLeft(e.currentTarget, direction);\n\n // Prevent rubber band scrolling from shaking when scrolling out of bounds\n state.scrollTop = Math.max(0, Math.min(scrollTop, contentSize.height - state.height));\n state.scrollLeft = Math.max(0, Math.min(scrollLeft, contentSize.width - state.width));\n\n onVisibleRectChange(new Rect(state.scrollLeft, state.scrollTop, state.width, state.height));\n\n if (!state.isScrolling) {\n state.isScrolling = true;\n setScrolling(true);\n\n if (onScrollStart) {\n onScrollStart();\n }\n }\n\n // So we don't constantly call clearTimeout and setTimeout,\n // keep track of the current timeout time and only reschedule\n // the timer when it is getting close.\n let now = Date.now();\n if (state.scrollEndTime <= now + 50) {\n state.scrollEndTime = now + 300;\n\n clearTimeout(state.scrollTimeout);\n state.scrollTimeout = setTimeout(() => {\n state.isScrolling = false;\n setScrolling(false);\n state.scrollTimeout = null;\n\n if (onScrollEnd) {\n onScrollEnd();\n }\n }, 300);\n }\n });\n }, [props, direction, state, contentSize, onVisibleRectChange, onScrollStart, onScrollEnd]);\n\n // Attach event directly to ref so RAC Virtualizer doesn't need to send props upward.\n useEvent(ref, 'scroll', onScroll);\n\n // eslint-disable-next-line arrow-body-style\n useEffect(() => {\n return () => {\n clearTimeout(state.scrollTimeout);\n };\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, []);\n\n let updateSize = useEffectEvent((flush: typeof flushSync) => {\n let dom = ref.current;\n if (!dom) {\n return;\n }\n\n let isTestEnv = process.env.NODE_ENV === 'test' && !process.env.VIRT_ON;\n let isClientWidthMocked = Object.getOwnPropertyNames(window.HTMLElement.prototype).includes('clientWidth');\n let isClientHeightMocked = Object.getOwnPropertyNames(window.HTMLElement.prototype).includes('clientHeight');\n let clientWidth = dom.clientWidth;\n let clientHeight = dom.clientHeight;\n let w = isTestEnv && !isClientWidthMocked ? Infinity : clientWidth;\n let h = isTestEnv && !isClientHeightMocked ? Infinity : clientHeight;\n\n if (sizeToFit && contentSize.width > 0 && contentSize.height > 0) {\n if (sizeToFit === 'width') {\n w = Math.min(w, contentSize.width);\n } else if (sizeToFit === 'height') {\n h = Math.min(h, contentSize.height);\n }\n }\n\n if (state.width !== w || state.height !== h) {\n state.width = w;\n state.height = h;\n flush(() => {\n onVisibleRectChange(new Rect(state.scrollLeft, state.scrollTop, w, h));\n });\n\n // If the clientWidth or clientHeight changed, scrollbars appeared or disappeared as\n // a result of the layout update. In this case, re-layout again to account for the\n // adjusted space. In very specific cases this might result in the scrollbars disappearing\n // again, resulting in extra padding. We stop after a maximum of two layout passes to avoid\n // an infinite loop. This matches how browsers behavior with native CSS grid layout.\n if (!isTestEnv && clientWidth !== dom.clientWidth || clientHeight !== dom.clientHeight) {\n state.width = dom.clientWidth;\n state.height = dom.clientHeight;\n flush(() => {\n onVisibleRectChange(new Rect(state.scrollLeft, state.scrollTop, state.width, state.height));\n });\n }\n }\n });\n\n let didUpdateSize = useRef(false);\n useLayoutEffect(() => {\n // React doesn't allow flushSync inside effects, so queue a microtask.\n // We also need to wait until all refs are set (e.g. when passing a ref down from a parent).\n queueMicrotask(() => {\n if (!didUpdateSize.current) {\n didUpdateSize.current = true;\n updateSize(flushSync);\n }\n });\n }, [updateSize]);\n useEffect(() => {\n if (!didUpdateSize.current) {\n // If useEffect ran before the above microtask, we are in a synchronous render (e.g. act).\n // Update the size here so that you don't need to mock timers in tests.\n didUpdateSize.current = true;\n updateSize(fn => fn());\n }\n }, [updateSize]);\n let onResize = useCallback(() => {\n updateSize(flushSync);\n }, [updateSize]);\n\n // Watch border-box instead of of content-box so that we don't go into\n // an infinite loop when scrollbars appear or disappear.\n useResizeObserver({ref, box: 'border-box', onResize});\n\n let style: React.CSSProperties = {\n // Reset padding so that relative positioning works correctly. Padding will be done in JS layout.\n padding: 0,\n ...otherProps.style\n };\n\n if (scrollDirection === 'horizontal') {\n style.overflowX = 'auto';\n style.overflowY = 'hidden';\n } else if (scrollDirection === 'vertical' || contentSize.width === state.width) {\n // Set overflow-x: hidden if content size is equal to the width of the scroll view.\n // This prevents horizontal scrollbars from flickering during resizing due to resize observer\n // firing slower than the frame rate, which may cause an infinite re-render loop.\n style.overflowY = 'auto';\n style.overflowX = 'hidden';\n } else {\n style.overflow = 'auto';\n }\n\n innerStyle = {\n width: Number.isFinite(contentSize.width) ? contentSize.width : undefined,\n height: Number.isFinite(contentSize.height) ? contentSize.height : undefined,\n pointerEvents: isScrolling ? 'none' : 'auto',\n position: 'relative',\n ...innerStyle\n };\n\n return {\n scrollViewProps: {\n ...otherProps,\n style\n },\n contentProps: {\n style: innerStyle\n }\n };\n}\n"],"names":[],"version":3,"file":"ScrollView.main.js.map"}
|
package/dist/ScrollView.mjs
CHANGED
|
@@ -2,7 +2,7 @@ import {getScrollLeft as $ce415dc67314b753$export$1389d168952b34b5} from "./util
|
|
|
2
2
|
import {flushSync as $f9kpT$flushSync} from "react-dom";
|
|
3
3
|
import $f9kpT$react, {useRef as $f9kpT$useRef, useState as $f9kpT$useState, useCallback as $f9kpT$useCallback, useEffect as $f9kpT$useEffect} from "react";
|
|
4
4
|
import {Rect as $f9kpT$Rect} from "@react-stately/virtualizer";
|
|
5
|
-
import {useEffectEvent as $f9kpT$useEffectEvent, useLayoutEffect as $f9kpT$useLayoutEffect, useResizeObserver as $f9kpT$useResizeObserver} from "@react-aria/utils";
|
|
5
|
+
import {useObjectRef as $f9kpT$useObjectRef, useEvent as $f9kpT$useEvent, useEffectEvent as $f9kpT$useEffectEvent, useLayoutEffect as $f9kpT$useLayoutEffect, useResizeObserver as $f9kpT$useResizeObserver} from "@react-aria/utils";
|
|
6
6
|
import {useLocale as $f9kpT$useLocale} from "@react-aria/i18n";
|
|
7
7
|
|
|
8
8
|
/*
|
|
@@ -23,9 +23,20 @@ import {useLocale as $f9kpT$useLocale} from "@react-aria/i18n";
|
|
|
23
23
|
|
|
24
24
|
|
|
25
25
|
function $44a6ee657928b002$var$ScrollView(props, ref) {
|
|
26
|
-
|
|
27
|
-
let
|
|
28
|
-
|
|
26
|
+
ref = (0, $f9kpT$useObjectRef)(ref);
|
|
27
|
+
let { scrollViewProps: scrollViewProps, contentProps: contentProps } = $44a6ee657928b002$export$2ea0c4974da4731b(props, ref);
|
|
28
|
+
return /*#__PURE__*/ (0, $f9kpT$react).createElement("div", {
|
|
29
|
+
role: "presentation",
|
|
30
|
+
...scrollViewProps,
|
|
31
|
+
ref: ref
|
|
32
|
+
}, /*#__PURE__*/ (0, $f9kpT$react).createElement("div", {
|
|
33
|
+
role: "presentation",
|
|
34
|
+
...contentProps
|
|
35
|
+
}, props.children));
|
|
36
|
+
}
|
|
37
|
+
const $44a6ee657928b002$export$5665e3d6be6adea = /*#__PURE__*/ (0, $f9kpT$react).forwardRef($44a6ee657928b002$var$ScrollView);
|
|
38
|
+
function $44a6ee657928b002$export$2ea0c4974da4731b(props, ref) {
|
|
39
|
+
let { contentSize: contentSize, onVisibleRectChange: onVisibleRectChange, innerStyle: innerStyle, sizeToFit: sizeToFit, onScrollStart: onScrollStart, onScrollEnd: onScrollEnd, scrollDirection: scrollDirection = 'both', ...otherProps } = props;
|
|
29
40
|
let state = (0, $f9kpT$useRef)({
|
|
30
41
|
scrollTop: 0,
|
|
31
42
|
scrollLeft: 0,
|
|
@@ -76,6 +87,8 @@ function $44a6ee657928b002$var$ScrollView(props, ref) {
|
|
|
76
87
|
onScrollStart,
|
|
77
88
|
onScrollEnd
|
|
78
89
|
]);
|
|
90
|
+
// Attach event directly to ref so RAC Virtualizer doesn't need to send props upward.
|
|
91
|
+
(0, $f9kpT$useEvent)(ref, 'scroll', onScroll);
|
|
79
92
|
// eslint-disable-next-line arrow-body-style
|
|
80
93
|
(0, $f9kpT$useEffect)(()=>{
|
|
81
94
|
return ()=>{
|
|
@@ -117,12 +130,26 @@ function $44a6ee657928b002$var$ScrollView(props, ref) {
|
|
|
117
130
|
}
|
|
118
131
|
}
|
|
119
132
|
});
|
|
133
|
+
let didUpdateSize = (0, $f9kpT$useRef)(false);
|
|
120
134
|
(0, $f9kpT$useLayoutEffect)(()=>{
|
|
121
|
-
// React doesn't allow flushSync inside effects so
|
|
122
|
-
//
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
135
|
+
// React doesn't allow flushSync inside effects, so queue a microtask.
|
|
136
|
+
// We also need to wait until all refs are set (e.g. when passing a ref down from a parent).
|
|
137
|
+
queueMicrotask(()=>{
|
|
138
|
+
if (!didUpdateSize.current) {
|
|
139
|
+
didUpdateSize.current = true;
|
|
140
|
+
updateSize((0, $f9kpT$flushSync));
|
|
141
|
+
}
|
|
142
|
+
});
|
|
143
|
+
}, [
|
|
144
|
+
updateSize
|
|
145
|
+
]);
|
|
146
|
+
(0, $f9kpT$useEffect)(()=>{
|
|
147
|
+
if (!didUpdateSize.current) {
|
|
148
|
+
// If useEffect ran before the above microtask, we are in a synchronous render (e.g. act).
|
|
149
|
+
// Update the size here so that you don't need to mock timers in tests.
|
|
150
|
+
didUpdateSize.current = true;
|
|
151
|
+
updateSize((fn)=>fn());
|
|
152
|
+
}
|
|
126
153
|
}, [
|
|
127
154
|
updateSize
|
|
128
155
|
]);
|
|
@@ -160,19 +187,17 @@ function $44a6ee657928b002$var$ScrollView(props, ref) {
|
|
|
160
187
|
position: 'relative',
|
|
161
188
|
...innerStyle
|
|
162
189
|
};
|
|
163
|
-
return
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
}, children));
|
|
190
|
+
return {
|
|
191
|
+
scrollViewProps: {
|
|
192
|
+
...otherProps,
|
|
193
|
+
style: style
|
|
194
|
+
},
|
|
195
|
+
contentProps: {
|
|
196
|
+
style: innerStyle
|
|
197
|
+
}
|
|
198
|
+
};
|
|
173
199
|
}
|
|
174
|
-
const $44a6ee657928b002$export$5665e3d6be6adea = /*#__PURE__*/ (0, $f9kpT$react).forwardRef($44a6ee657928b002$var$ScrollView);
|
|
175
200
|
|
|
176
201
|
|
|
177
|
-
export {$44a6ee657928b002$export$5665e3d6be6adea as ScrollView};
|
|
202
|
+
export {$44a6ee657928b002$export$2ea0c4974da4731b as useScrollView, $44a6ee657928b002$export$5665e3d6be6adea as ScrollView};
|
|
178
203
|
//# sourceMappingURL=ScrollView.module.js.map
|
|
@@ -2,7 +2,7 @@ import {getScrollLeft as $ce415dc67314b753$export$1389d168952b34b5} from "./util
|
|
|
2
2
|
import {flushSync as $f9kpT$flushSync} from "react-dom";
|
|
3
3
|
import $f9kpT$react, {useRef as $f9kpT$useRef, useState as $f9kpT$useState, useCallback as $f9kpT$useCallback, useEffect as $f9kpT$useEffect} from "react";
|
|
4
4
|
import {Rect as $f9kpT$Rect} from "@react-stately/virtualizer";
|
|
5
|
-
import {useEffectEvent as $f9kpT$useEffectEvent, useLayoutEffect as $f9kpT$useLayoutEffect, useResizeObserver as $f9kpT$useResizeObserver} from "@react-aria/utils";
|
|
5
|
+
import {useObjectRef as $f9kpT$useObjectRef, useEvent as $f9kpT$useEvent, useEffectEvent as $f9kpT$useEffectEvent, useLayoutEffect as $f9kpT$useLayoutEffect, useResizeObserver as $f9kpT$useResizeObserver} from "@react-aria/utils";
|
|
6
6
|
import {useLocale as $f9kpT$useLocale} from "@react-aria/i18n";
|
|
7
7
|
|
|
8
8
|
/*
|
|
@@ -23,9 +23,20 @@ import {useLocale as $f9kpT$useLocale} from "@react-aria/i18n";
|
|
|
23
23
|
|
|
24
24
|
|
|
25
25
|
function $44a6ee657928b002$var$ScrollView(props, ref) {
|
|
26
|
-
|
|
27
|
-
let
|
|
28
|
-
|
|
26
|
+
ref = (0, $f9kpT$useObjectRef)(ref);
|
|
27
|
+
let { scrollViewProps: scrollViewProps, contentProps: contentProps } = $44a6ee657928b002$export$2ea0c4974da4731b(props, ref);
|
|
28
|
+
return /*#__PURE__*/ (0, $f9kpT$react).createElement("div", {
|
|
29
|
+
role: "presentation",
|
|
30
|
+
...scrollViewProps,
|
|
31
|
+
ref: ref
|
|
32
|
+
}, /*#__PURE__*/ (0, $f9kpT$react).createElement("div", {
|
|
33
|
+
role: "presentation",
|
|
34
|
+
...contentProps
|
|
35
|
+
}, props.children));
|
|
36
|
+
}
|
|
37
|
+
const $44a6ee657928b002$export$5665e3d6be6adea = /*#__PURE__*/ (0, $f9kpT$react).forwardRef($44a6ee657928b002$var$ScrollView);
|
|
38
|
+
function $44a6ee657928b002$export$2ea0c4974da4731b(props, ref) {
|
|
39
|
+
let { contentSize: contentSize, onVisibleRectChange: onVisibleRectChange, innerStyle: innerStyle, sizeToFit: sizeToFit, onScrollStart: onScrollStart, onScrollEnd: onScrollEnd, scrollDirection: scrollDirection = 'both', ...otherProps } = props;
|
|
29
40
|
let state = (0, $f9kpT$useRef)({
|
|
30
41
|
scrollTop: 0,
|
|
31
42
|
scrollLeft: 0,
|
|
@@ -76,6 +87,8 @@ function $44a6ee657928b002$var$ScrollView(props, ref) {
|
|
|
76
87
|
onScrollStart,
|
|
77
88
|
onScrollEnd
|
|
78
89
|
]);
|
|
90
|
+
// Attach event directly to ref so RAC Virtualizer doesn't need to send props upward.
|
|
91
|
+
(0, $f9kpT$useEvent)(ref, 'scroll', onScroll);
|
|
79
92
|
// eslint-disable-next-line arrow-body-style
|
|
80
93
|
(0, $f9kpT$useEffect)(()=>{
|
|
81
94
|
return ()=>{
|
|
@@ -117,12 +130,26 @@ function $44a6ee657928b002$var$ScrollView(props, ref) {
|
|
|
117
130
|
}
|
|
118
131
|
}
|
|
119
132
|
});
|
|
133
|
+
let didUpdateSize = (0, $f9kpT$useRef)(false);
|
|
120
134
|
(0, $f9kpT$useLayoutEffect)(()=>{
|
|
121
|
-
// React doesn't allow flushSync inside effects so
|
|
122
|
-
//
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
135
|
+
// React doesn't allow flushSync inside effects, so queue a microtask.
|
|
136
|
+
// We also need to wait until all refs are set (e.g. when passing a ref down from a parent).
|
|
137
|
+
queueMicrotask(()=>{
|
|
138
|
+
if (!didUpdateSize.current) {
|
|
139
|
+
didUpdateSize.current = true;
|
|
140
|
+
updateSize((0, $f9kpT$flushSync));
|
|
141
|
+
}
|
|
142
|
+
});
|
|
143
|
+
}, [
|
|
144
|
+
updateSize
|
|
145
|
+
]);
|
|
146
|
+
(0, $f9kpT$useEffect)(()=>{
|
|
147
|
+
if (!didUpdateSize.current) {
|
|
148
|
+
// If useEffect ran before the above microtask, we are in a synchronous render (e.g. act).
|
|
149
|
+
// Update the size here so that you don't need to mock timers in tests.
|
|
150
|
+
didUpdateSize.current = true;
|
|
151
|
+
updateSize((fn)=>fn());
|
|
152
|
+
}
|
|
126
153
|
}, [
|
|
127
154
|
updateSize
|
|
128
155
|
]);
|
|
@@ -160,19 +187,17 @@ function $44a6ee657928b002$var$ScrollView(props, ref) {
|
|
|
160
187
|
position: 'relative',
|
|
161
188
|
...innerStyle
|
|
162
189
|
};
|
|
163
|
-
return
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
}, children));
|
|
190
|
+
return {
|
|
191
|
+
scrollViewProps: {
|
|
192
|
+
...otherProps,
|
|
193
|
+
style: style
|
|
194
|
+
},
|
|
195
|
+
contentProps: {
|
|
196
|
+
style: innerStyle
|
|
197
|
+
}
|
|
198
|
+
};
|
|
173
199
|
}
|
|
174
|
-
const $44a6ee657928b002$export$5665e3d6be6adea = /*#__PURE__*/ (0, $f9kpT$react).forwardRef($44a6ee657928b002$var$ScrollView);
|
|
175
200
|
|
|
176
201
|
|
|
177
|
-
export {$44a6ee657928b002$export$5665e3d6be6adea as ScrollView};
|
|
202
|
+
export {$44a6ee657928b002$export$2ea0c4974da4731b as useScrollView, $44a6ee657928b002$export$5665e3d6be6adea as ScrollView};
|
|
178
203
|
//# sourceMappingURL=ScrollView.module.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":";;;;;;;AAAA;;;;;;;;;;CAUC,GAED,aAAa;;;;;;;AA4Bb,SAAS,iCAAW,KAAsB,EAAE,GAA8B;IACxE,IAAI,eACF,WAAW,uBACX,mBAAmB,YACnB,QAAQ,cACR,UAAU,aACV,SAAS,iBACT,aAAa,eACb,WAAW,mBACX,kBAAkB,QAClB,GAAG,YACJ,GAAG;IAEJ,IAAI,aAAa,CAAA,GAAA,aAAK;IACtB,MAAM,OAAO;IACb,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;QAAe,OAAO;OAC7B;AAIT;AAEA,MAAM,yDAAuB,CAAA,GAAA,YAAI,EAAE,UAAU,CAAC","sources":["packages/@react-aria/virtualizer/src/ScrollView.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\n// @ts-ignore\nimport {flushSync} from 'react-dom';\nimport {getScrollLeft} from './utils';\nimport React, {\n CSSProperties,\n HTMLAttributes,\n ReactNode,\n RefObject,\n useCallback,\n useEffect,\n useRef,\n useState\n} from 'react';\nimport {Rect, Size} from '@react-stately/virtualizer';\nimport {useEffectEvent, useLayoutEffect, useResizeObserver} from '@react-aria/utils';\nimport {useLocale} from '@react-aria/i18n';\n\ninterface ScrollViewProps extends HTMLAttributes<HTMLElement> {\n contentSize: Size,\n onVisibleRectChange: (rect: Rect) => void,\n children: ReactNode,\n innerStyle?: CSSProperties,\n sizeToFit?: 'width' | 'height',\n onScrollStart?: () => void,\n onScrollEnd?: () => void,\n scrollDirection?: 'horizontal' | 'vertical' | 'both'\n}\n\nfunction ScrollView(props: ScrollViewProps, ref: RefObject<HTMLDivElement>) {\n let {\n contentSize,\n onVisibleRectChange,\n children,\n innerStyle,\n sizeToFit,\n onScrollStart,\n onScrollEnd,\n scrollDirection = 'both',\n ...otherProps\n } = props;\n\n let defaultRef = useRef();\n ref = ref || defaultRef;\n let state = useRef({\n scrollTop: 0,\n scrollLeft: 0,\n scrollEndTime: 0,\n scrollTimeout: null,\n width: 0,\n height: 0,\n isScrolling: false\n }).current;\n let {direction} = useLocale();\n\n let [isScrolling, setScrolling] = useState(false);\n let onScroll = useCallback((e) => {\n if (e.target !== e.currentTarget) {\n return;\n }\n\n if (props.onScroll) {\n props.onScroll(e);\n }\n\n flushSync(() => {\n let scrollTop = e.currentTarget.scrollTop;\n let scrollLeft = getScrollLeft(e.currentTarget, direction);\n\n // Prevent rubber band scrolling from shaking when scrolling out of bounds\n state.scrollTop = Math.max(0, Math.min(scrollTop, contentSize.height - state.height));\n state.scrollLeft = Math.max(0, Math.min(scrollLeft, contentSize.width - state.width));\n\n onVisibleRectChange(new Rect(state.scrollLeft, state.scrollTop, state.width, state.height));\n\n if (!state.isScrolling) {\n state.isScrolling = true;\n setScrolling(true);\n\n if (onScrollStart) {\n onScrollStart();\n }\n }\n\n // So we don't constantly call clearTimeout and setTimeout,\n // keep track of the current timeout time and only reschedule\n // the timer when it is getting close.\n let now = Date.now();\n if (state.scrollEndTime <= now + 50) {\n state.scrollEndTime = now + 300;\n\n clearTimeout(state.scrollTimeout);\n state.scrollTimeout = setTimeout(() => {\n state.isScrolling = false;\n setScrolling(false);\n state.scrollTimeout = null;\n\n if (onScrollEnd) {\n onScrollEnd();\n }\n }, 300);\n }\n });\n }, [props, direction, state, contentSize, onVisibleRectChange, onScrollStart, onScrollEnd]);\n\n // eslint-disable-next-line arrow-body-style\n useEffect(() => {\n return () => {\n clearTimeout(state.scrollTimeout);\n };\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, []);\n\n let updateSize = useEffectEvent((flush: typeof flushSync) => {\n let dom = ref.current;\n if (!dom) {\n return;\n }\n\n let isTestEnv = process.env.NODE_ENV === 'test' && !process.env.VIRT_ON;\n let isClientWidthMocked = Object.getOwnPropertyNames(window.HTMLElement.prototype).includes('clientWidth');\n let isClientHeightMocked = Object.getOwnPropertyNames(window.HTMLElement.prototype).includes('clientHeight');\n let clientWidth = dom.clientWidth;\n let clientHeight = dom.clientHeight;\n let w = isTestEnv && !isClientWidthMocked ? Infinity : clientWidth;\n let h = isTestEnv && !isClientHeightMocked ? Infinity : clientHeight;\n\n if (sizeToFit && contentSize.width > 0 && contentSize.height > 0) {\n if (sizeToFit === 'width') {\n w = Math.min(w, contentSize.width);\n } else if (sizeToFit === 'height') {\n h = Math.min(h, contentSize.height);\n }\n }\n\n if (state.width !== w || state.height !== h) {\n state.width = w;\n state.height = h;\n flush(() => {\n onVisibleRectChange(new Rect(state.scrollLeft, state.scrollTop, w, h));\n });\n\n // If the clientWidth or clientHeight changed, scrollbars appeared or disappeared as\n // a result of the layout update. In this case, re-layout again to account for the\n // adjusted space. In very specific cases this might result in the scrollbars disappearing\n // again, resulting in extra padding. We stop after a maximum of two layout passes to avoid\n // an infinite loop. This matches how browsers behavior with native CSS grid layout.\n if (!isTestEnv && clientWidth !== dom.clientWidth || clientHeight !== dom.clientHeight) {\n state.width = dom.clientWidth;\n state.height = dom.clientHeight;\n flush(() => {\n onVisibleRectChange(new Rect(state.scrollLeft, state.scrollTop, state.width, state.height));\n });\n }\n }\n });\n\n useLayoutEffect(() => {\n // React doesn't allow flushSync inside effects so pass an identity function instead.\n // This only happens on initial render. The resize observer will also call updateSize\n // once it initializes, but we need earlier initialization in a layout effect to avoid\n // a flash of missing content.\n updateSize(fn => fn());\n }, [updateSize]);\n let onResize = useCallback(() => {\n updateSize(flushSync);\n }, [updateSize]);\n // Watch border-box instead of of content-box so that we don't go into\n // an infinite loop when scrollbars appear or disappear.\n useResizeObserver({ref, box: 'border-box', onResize});\n\n let style: React.CSSProperties = {\n // Reset padding so that relative positioning works correctly. Padding will be done in JS layout.\n padding: 0,\n ...otherProps.style\n };\n\n if (scrollDirection === 'horizontal') {\n style.overflowX = 'auto';\n style.overflowY = 'hidden';\n } else if (scrollDirection === 'vertical' || contentSize.width === state.width) {\n // Set overflow-x: hidden if content size is equal to the width of the scroll view.\n // This prevents horizontal scrollbars from flickering during resizing due to resize observer\n // firing slower than the frame rate, which may cause an infinite re-render loop.\n style.overflowY = 'auto';\n style.overflowX = 'hidden';\n } else {\n style.overflow = 'auto';\n }\n\n innerStyle = {\n width: Number.isFinite(contentSize.width) ? contentSize.width : undefined,\n height: Number.isFinite(contentSize.height) ? contentSize.height : undefined,\n pointerEvents: isScrolling ? 'none' : 'auto',\n position: 'relative',\n ...innerStyle\n };\n\n return (\n <div role=\"presentation\" {...otherProps} style={style} ref={ref} onScroll={onScroll}>\n <div role=\"presentation\" style={innerStyle}>\n {children}\n </div>\n </div>\n );\n}\n\nconst ScrollViewForwardRef = React.forwardRef(ScrollView);\nexport {ScrollViewForwardRef as ScrollView};\n"],"names":[],"version":3,"file":"ScrollView.module.js.map"}
|
|
1
|
+
{"mappings":";;;;;;;AAAA;;;;;;;;;;CAUC,GAED,aAAa;;;;;;;AA6Bb,SAAS,iCAAW,KAAsB,EAAE,GAAwC;IAClF,MAAM,CAAA,GAAA,mBAAW,EAAE;IACnB,IAAI,mBAAC,eAAe,gBAAE,YAAY,EAAC,GAAG,0CAAc,OAAO;IAE3D,qBACE,gCAAC;QAAI,MAAK;QAAgB,GAAG,eAAe;QAAE,KAAK;qBACjD,gCAAC;QAAI,MAAK;QAAgB,GAAG,YAAY;OACtC,MAAM,QAAQ;AAIvB;AAEA,MAAM,yDAAuB,CAAA,GAAA,YAAI,EAAE,UAAU,CAAC;AAGvC,SAAS,0CAAc,KAAsB,EAAE,GAAkC;IACtF,IAAI,eACF,WAAW,uBACX,mBAAmB,cACnB,UAAU,aACV,SAAS,iBACT,aAAa,eACb,WAAW,mBACX,kBAAkB,QAClB,GAAG,YACJ,GAAG;IAEJ,IAAI,QAAQ,CAAA,GAAA,aAAK,EAAE;QACjB,WAAW;QACX,YAAY;QACZ,eAAe;QACf,eAAe;QACf,OAAO;QACP,QAAQ;QACR,aAAa;IACf,GAAG,OAAO;IACV,IAAI,aAAC,SAAS,EAAC,GAAG,CAAA,GAAA,gBAAQ;IAE1B,IAAI,CAAC,aAAa,aAAa,GAAG,CAAA,GAAA,eAAO,EAAE;IAC3C,IAAI,WAAW,CAAA,GAAA,kBAAU,EAAE,CAAC;QAC1B,IAAI,EAAE,MAAM,K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/@react-aria/virtualizer/src/ScrollView.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\n// @ts-ignore\nimport {flushSync} from 'react-dom';\nimport {getScrollLeft} from './utils';\nimport React, {\n CSSProperties,\n ForwardedRef,\n HTMLAttributes,\n ReactNode,\n RefObject,\n useCallback,\n useEffect,\n useRef,\n useState\n} from 'react';\nimport {Rect, Size} from '@react-stately/virtualizer';\nimport {useEffectEvent, useEvent, useLayoutEffect, useObjectRef, useResizeObserver} from '@react-aria/utils';\nimport {useLocale} from '@react-aria/i18n';\n\ninterface ScrollViewProps extends HTMLAttributes<HTMLElement> {\n contentSize: Size,\n onVisibleRectChange: (rect: Rect) => void,\n children?: ReactNode,\n innerStyle?: CSSProperties,\n sizeToFit?: 'width' | 'height',\n onScrollStart?: () => void,\n onScrollEnd?: () => void,\n scrollDirection?: 'horizontal' | 'vertical' | 'both'\n}\n\nfunction ScrollView(props: ScrollViewProps, ref: ForwardedRef<HTMLDivElement | null>) {\n ref = useObjectRef(ref);\n let {scrollViewProps, contentProps} = useScrollView(props, ref);\n\n return (\n <div role=\"presentation\" {...scrollViewProps} ref={ref}>\n <div role=\"presentation\" {...contentProps}>\n {props.children}\n </div>\n </div>\n );\n}\n\nconst ScrollViewForwardRef = React.forwardRef(ScrollView);\nexport {ScrollViewForwardRef as ScrollView};\n\nexport function useScrollView(props: ScrollViewProps, ref: RefObject<HTMLElement | null>) {\n let {\n contentSize,\n onVisibleRectChange,\n innerStyle,\n sizeToFit,\n onScrollStart,\n onScrollEnd,\n scrollDirection = 'both',\n ...otherProps\n } = props;\n\n let state = useRef({\n scrollTop: 0,\n scrollLeft: 0,\n scrollEndTime: 0,\n scrollTimeout: null,\n width: 0,\n height: 0,\n isScrolling: false\n }).current;\n let {direction} = useLocale();\n\n let [isScrolling, setScrolling] = useState(false);\n let onScroll = useCallback((e) => {\n if (e.target !== e.currentTarget) {\n return;\n }\n\n if (props.onScroll) {\n props.onScroll(e);\n }\n\n flushSync(() => {\n let scrollTop = e.currentTarget.scrollTop;\n let scrollLeft = getScrollLeft(e.currentTarget, direction);\n\n // Prevent rubber band scrolling from shaking when scrolling out of bounds\n state.scrollTop = Math.max(0, Math.min(scrollTop, contentSize.height - state.height));\n state.scrollLeft = Math.max(0, Math.min(scrollLeft, contentSize.width - state.width));\n\n onVisibleRectChange(new Rect(state.scrollLeft, state.scrollTop, state.width, state.height));\n\n if (!state.isScrolling) {\n state.isScrolling = true;\n setScrolling(true);\n\n if (onScrollStart) {\n onScrollStart();\n }\n }\n\n // So we don't constantly call clearTimeout and setTimeout,\n // keep track of the current timeout time and only reschedule\n // the timer when it is getting close.\n let now = Date.now();\n if (state.scrollEndTime <= now + 50) {\n state.scrollEndTime = now + 300;\n\n clearTimeout(state.scrollTimeout);\n state.scrollTimeout = setTimeout(() => {\n state.isScrolling = false;\n setScrolling(false);\n state.scrollTimeout = null;\n\n if (onScrollEnd) {\n onScrollEnd();\n }\n }, 300);\n }\n });\n }, [props, direction, state, contentSize, onVisibleRectChange, onScrollStart, onScrollEnd]);\n\n // Attach event directly to ref so RAC Virtualizer doesn't need to send props upward.\n useEvent(ref, 'scroll', onScroll);\n\n // eslint-disable-next-line arrow-body-style\n useEffect(() => {\n return () => {\n clearTimeout(state.scrollTimeout);\n };\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, []);\n\n let updateSize = useEffectEvent((flush: typeof flushSync) => {\n let dom = ref.current;\n if (!dom) {\n return;\n }\n\n let isTestEnv = process.env.NODE_ENV === 'test' && !process.env.VIRT_ON;\n let isClientWidthMocked = Object.getOwnPropertyNames(window.HTMLElement.prototype).includes('clientWidth');\n let isClientHeightMocked = Object.getOwnPropertyNames(window.HTMLElement.prototype).includes('clientHeight');\n let clientWidth = dom.clientWidth;\n let clientHeight = dom.clientHeight;\n let w = isTestEnv && !isClientWidthMocked ? Infinity : clientWidth;\n let h = isTestEnv && !isClientHeightMocked ? Infinity : clientHeight;\n\n if (sizeToFit && contentSize.width > 0 && contentSize.height > 0) {\n if (sizeToFit === 'width') {\n w = Math.min(w, contentSize.width);\n } else if (sizeToFit === 'height') {\n h = Math.min(h, contentSize.height);\n }\n }\n\n if (state.width !== w || state.height !== h) {\n state.width = w;\n state.height = h;\n flush(() => {\n onVisibleRectChange(new Rect(state.scrollLeft, state.scrollTop, w, h));\n });\n\n // If the clientWidth or clientHeight changed, scrollbars appeared or disappeared as\n // a result of the layout update. In this case, re-layout again to account for the\n // adjusted space. In very specific cases this might result in the scrollbars disappearing\n // again, resulting in extra padding. We stop after a maximum of two layout passes to avoid\n // an infinite loop. This matches how browsers behavior with native CSS grid layout.\n if (!isTestEnv && clientWidth !== dom.clientWidth || clientHeight !== dom.clientHeight) {\n state.width = dom.clientWidth;\n state.height = dom.clientHeight;\n flush(() => {\n onVisibleRectChange(new Rect(state.scrollLeft, state.scrollTop, state.width, state.height));\n });\n }\n }\n });\n\n let didUpdateSize = useRef(false);\n useLayoutEffect(() => {\n // React doesn't allow flushSync inside effects, so queue a microtask.\n // We also need to wait until all refs are set (e.g. when passing a ref down from a parent).\n queueMicrotask(() => {\n if (!didUpdateSize.current) {\n didUpdateSize.current = true;\n updateSize(flushSync);\n }\n });\n }, [updateSize]);\n useEffect(() => {\n if (!didUpdateSize.current) {\n // If useEffect ran before the above microtask, we are in a synchronous render (e.g. act).\n // Update the size here so that you don't need to mock timers in tests.\n didUpdateSize.current = true;\n updateSize(fn => fn());\n }\n }, [updateSize]);\n let onResize = useCallback(() => {\n updateSize(flushSync);\n }, [updateSize]);\n\n // Watch border-box instead of of content-box so that we don't go into\n // an infinite loop when scrollbars appear or disappear.\n useResizeObserver({ref, box: 'border-box', onResize});\n\n let style: React.CSSProperties = {\n // Reset padding so that relative positioning works correctly. Padding will be done in JS layout.\n padding: 0,\n ...otherProps.style\n };\n\n if (scrollDirection === 'horizontal') {\n style.overflowX = 'auto';\n style.overflowY = 'hidden';\n } else if (scrollDirection === 'vertical' || contentSize.width === state.width) {\n // Set overflow-x: hidden if content size is equal to the width of the scroll view.\n // This prevents horizontal scrollbars from flickering during resizing due to resize observer\n // firing slower than the frame rate, which may cause an infinite re-render loop.\n style.overflowY = 'auto';\n style.overflowX = 'hidden';\n } else {\n style.overflow = 'auto';\n }\n\n innerStyle = {\n width: Number.isFinite(contentSize.width) ? contentSize.width : undefined,\n height: Number.isFinite(contentSize.height) ? contentSize.height : undefined,\n pointerEvents: isScrolling ? 'none' : 'auto',\n position: 'relative',\n ...innerStyle\n };\n\n return {\n scrollViewProps: {\n ...otherProps,\n style\n },\n contentProps: {\n style: innerStyle\n }\n };\n}\n"],"names":[],"version":3,"file":"ScrollView.module.js.map"}
|
package/dist/Virtualizer.main.js
CHANGED
|
@@ -36,7 +36,7 @@ function $e1fb6f3669e1c329$var$Virtualizer(props, ref) {
|
|
|
36
36
|
let { children: renderView, renderWrapper: renderWrapper, layout: layout, collection: collection, sizeToFit: sizeToFit, scrollDirection: scrollDirection, isLoading: // eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
37
37
|
isLoading, onLoadMore: // eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
38
38
|
onLoadMore, focusedKey: focusedKey, layoutOptions: layoutOptions, ...otherProps } = props;
|
|
39
|
-
let fallbackRef = (0, $knrtk$react.useRef)();
|
|
39
|
+
let fallbackRef = (0, $knrtk$react.useRef)(undefined);
|
|
40
40
|
ref = ref || fallbackRef;
|
|
41
41
|
let state = (0, $knrtk$reactstatelyvirtualizer.useVirtualizerState)({
|
|
42
42
|
layout: layout,
|
|
@@ -47,7 +47,7 @@ function $e1fb6f3669e1c329$var$Virtualizer(props, ref) {
|
|
|
47
47
|
ref.current.scrollLeft = rect.x;
|
|
48
48
|
ref.current.scrollTop = rect.y;
|
|
49
49
|
},
|
|
50
|
-
persistedKeys: (0, $knrtk$react.useMemo)(()=>focusedKey ? new Set([
|
|
50
|
+
persistedKeys: (0, $knrtk$react.useMemo)(()=>focusedKey != null ? new Set([
|
|
51
51
|
focusedKey
|
|
52
52
|
]) : new Set(), [
|
|
53
53
|
focusedKey
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":";;;;;;;;;;;;;;;;;;AAAA;;;;;;;;;;CAUC;;;;;AA2BM,MAAM,yDAAqB,CAAA,GAAA,0BAAY,EAA0C;AAExF,SAAS,kCAAsD,KAAgC,EAAE,
|
|
1
|
+
{"mappings":";;;;;;;;;;;;;;;;;;AAAA;;;;;;;;;;CAUC;;;;;AA2BM,MAAM,yDAAqB,CAAA,GAAA,0BAAY,EAA0C;AAExF,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,cACV,UAAU,iBACV,aAAa,EACb,GAAG,YACJ,GAAG;IAEJ,IAAI,cAAc,CAAA,GAAA,mBAAK,EAAkB;IACzC,MAAM,OAAO;IAEb,IAAI,QAAQ,CAAA,GAAA,kDAAkB,EAAE;gBAC9B;oBACA;oBACA;QACA,eAAe,iBAAiB;QAChC,qBAAoB,IAAI;YACtB,IAAI,OAAO,CAAC,UAAU,GAAG,KAAK,CAAC;YAC/B,IAAI,OAAO,CAAC,SAAS,GAAG,KAAK,CAAC;QAChC;QACA,eAAe,CAAA,GAAA,oBAAM,EAAE,IAAM,cAAc,OAAO,IAAI,IAAI;gBAAC;aAAW,IAAI,IAAI,OAAO;YAAC;SAAW;uBACjG;IACF;IAEA,IAAI,oBAAC,gBAAgB,mBAAE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AC,MAAM,IAG/D,CAAA,cAAc,MAAM,WAAW,CAAC,MAAM,KAAK,gBAAgB,OAAO,AAAD;QAEvE,IAAI,gBAAgB;YAClB,aAAa,OAAO,GAAG;YACvB;QACF;QACA,gBAAgB,OAAO,GAAG,MAAM,WAAW,CAAC,MAAM;IACpD,GAAG;QAAC,MAAM,WAAW;QAAE,MAAM,WAAW;QAAE;QAAW;QAAY;KAAM;IAEvE,OAAO;QACL,kBAAkB,CAAC;QACnB,iBAAiB;iCACf;QACF;IACF;AACF;AAEA,wFAAwF;AACxF,2GAA2G;AAC3G,MAAM,0DAAe,CAAA,GAAA,sCAAI,EAAE,UAAU,CAAC;AAGtC,SAAS,2CACP,MAAiC,EACjC,YAAgC;IAEhC,qBACE,0DAAC,CAAA,GAAA,yCAAc;QACb,KAAK,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} from '@react-types/shared';\nimport {Layout, Rect, ReusableView, useVirtualizerState, VirtualizerState} from '@react-stately/virtualizer';\nimport {mergeProps, useLayoutEffect} from '@react-aria/utils';\nimport React, {createContext, HTMLAttributes, ReactElement, ReactNode, RefObject, useCallback, useMemo, useRef} from 'react';\nimport {ScrollView} from './ScrollView';\nimport {VirtualizerItem} from './VirtualizerItem';\n\ninterface VirtualizerProps<T extends object, V, O> extends Omit<HTMLAttributes<HTMLElement>, 'children'> {\n children: (type: string, content: T) => V,\n renderWrapper?: (\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 layout: Layout<T, O>,\n collection: Collection<T>,\n focusedKey?: Key,\n sizeToFit?: 'width' | 'height',\n scrollDirection?: 'horizontal' | 'vertical' | 'both',\n isLoading?: boolean,\n onLoadMore?: () => void,\n layoutOptions?: O\n}\n\nexport const VirtualizerContext = createContext<VirtualizerState<any, any, any> | null>(null);\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 focusedKey,\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 renderWrapper: renderWrapper || defaultRenderWrapper,\n onVisibleRectChange(rect) {\n ref.current.scrollLeft = rect.x;\n ref.current.scrollTop = rect.y;\n },\n persistedKeys: useMemo(() => focusedKey != null ? new Set([focusedKey]) : new Set(), [focusedKey]),\n layoutOptions\n });\n\n let {virtualizerProps, scrollViewProps} = useVirtualizer(props, state, ref);\n\n return (\n <ScrollView\n {...mergeProps(otherProps, virtualizerProps, scrollViewProps)}\n ref={ref}\n contentSize={state.contentSize}\n onScrollStart={state.startScrolling}\n onScrollEnd={state.endScrolling}\n sizeToFit={sizeToFit}\n scrollDirection={scrollDirection}>\n <VirtualizerContext.Provider value={state}>\n {state.visibleViews}\n </VirtualizerContext.Provider>\n </ScrollView>\n );\n}\n\ninterface VirtualizerOptions {\n tabIndex?: number,\n focusedKey?: Key,\n isLoading?: boolean,\n onLoadMore?: () => void\n}\n\n// eslint-disable-next-line @typescript-eslint/no-unused-vars\nexport function useVirtualizer<T extends object, V extends ReactNode, W>(props: VirtualizerOptions, state: VirtualizerState<T, V, W>, ref: RefObject<HTMLElement | null>) {\n let {isLoading, onLoadMore} = props;\n let {setVisibleRect, virtualizer} = state;\n\n // Handle scrolling, and call onLoadMore when nearing the bottom.\n let isLoadingRef = useRef(isLoading);\n let prevProps = useRef(props);\n let onVisibleRectChange = useCallback((rect: Rect) => {\n setVisibleRect(rect);\n\n if (!isLoadingRef.current && onLoadMore) {\n let scrollOffset = virtualizer.contentSize.height - rect.height * 2;\n if (rect.y > scrollOffset) {\n isLoadingRef.current = true;\n onLoadMore();\n }\n }\n }, [onLoadMore, setVisibleRect, virtualizer]);\n\n let lastContentSize = useRef(0);\n useLayoutEffect(() => {\n // Only update isLoadingRef if props object actually changed,\n // not if a local state change occurred.\n let wasLoading = isLoadingRef.current;\n if (props !== prevProps.current) {\n isLoadingRef.current = isLoading;\n prevProps.current = props;\n }\n\n let shouldLoadMore = !isLoadingRef.current\n && onLoadMore\n && state.contentSize.height > 0\n && state.contentSize.height <= state.virtualizer.visibleRect.height\n // Only try loading more if the content size changed, or if we just finished\n // loading and still have room for more items.\n && (wasLoading || state.contentSize.height !== lastContentSize.current);\n\n if (shouldLoadMore) {\n isLoadingRef.current = true;\n onLoadMore();\n }\n lastContentSize.current = state.contentSize.height;\n }, [state.contentSize, state.virtualizer, isLoading, onLoadMore, props]);\n\n return {\n virtualizerProps: {},\n scrollViewProps: {\n onVisibleRectChange\n }\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 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
|
@@ -24,7 +24,7 @@ function $6d0a5c394373ae64$var$Virtualizer(props, ref) {
|
|
|
24
24
|
let { children: renderView, renderWrapper: renderWrapper, layout: layout, collection: collection, sizeToFit: sizeToFit, scrollDirection: scrollDirection, isLoading: // eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
25
25
|
isLoading, onLoadMore: // eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
26
26
|
onLoadMore, focusedKey: focusedKey, layoutOptions: layoutOptions, ...otherProps } = props;
|
|
27
|
-
let fallbackRef = (0, $9WwqA$useRef)();
|
|
27
|
+
let fallbackRef = (0, $9WwqA$useRef)(undefined);
|
|
28
28
|
ref = ref || fallbackRef;
|
|
29
29
|
let state = (0, $9WwqA$useVirtualizerState)({
|
|
30
30
|
layout: layout,
|
|
@@ -35,7 +35,7 @@ function $6d0a5c394373ae64$var$Virtualizer(props, ref) {
|
|
|
35
35
|
ref.current.scrollLeft = rect.x;
|
|
36
36
|
ref.current.scrollTop = rect.y;
|
|
37
37
|
},
|
|
38
|
-
persistedKeys: (0, $9WwqA$useMemo)(()=>focusedKey ? new Set([
|
|
38
|
+
persistedKeys: (0, $9WwqA$useMemo)(()=>focusedKey != null ? new Set([
|
|
39
39
|
focusedKey
|
|
40
40
|
]) : new Set(), [
|
|
41
41
|
focusedKey
|
|
@@ -24,7 +24,7 @@ function $6d0a5c394373ae64$var$Virtualizer(props, ref) {
|
|
|
24
24
|
let { children: renderView, renderWrapper: renderWrapper, layout: layout, collection: collection, sizeToFit: sizeToFit, scrollDirection: scrollDirection, isLoading: // eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
25
25
|
isLoading, onLoadMore: // eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
26
26
|
onLoadMore, focusedKey: focusedKey, layoutOptions: layoutOptions, ...otherProps } = props;
|
|
27
|
-
let fallbackRef = (0, $9WwqA$useRef)();
|
|
27
|
+
let fallbackRef = (0, $9WwqA$useRef)(undefined);
|
|
28
28
|
ref = ref || fallbackRef;
|
|
29
29
|
let state = (0, $9WwqA$useVirtualizerState)({
|
|
30
30
|
layout: layout,
|
|
@@ -35,7 +35,7 @@ function $6d0a5c394373ae64$var$Virtualizer(props, ref) {
|
|
|
35
35
|
ref.current.scrollLeft = rect.x;
|
|
36
36
|
ref.current.scrollTop = rect.y;
|
|
37
37
|
},
|
|
38
|
-
persistedKeys: (0, $9WwqA$useMemo)(()=>focusedKey ? new Set([
|
|
38
|
+
persistedKeys: (0, $9WwqA$useMemo)(()=>focusedKey != null ? new Set([
|
|
39
39
|
focusedKey
|
|
40
40
|
]) : new Set(), [
|
|
41
41
|
focusedKey
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":";;;;;;AAAA;;;;;;;;;;CAUC;;;;;AA2BM,MAAM,yDAAqB,CAAA,GAAA,oBAAY,EAA0C;AAExF,SAAS,kCAAsD,KAAgC,EAAE,
|
|
1
|
+
{"mappings":";;;;;;AAAA;;;;;;;;;;CAUC;;;;;AA2BM,MAAM,yDAAqB,CAAA,GAAA,oBAAY,EAA0C;AAExF,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,cACV,UAAU,iBACV,aAAa,EACb,GAAG,YACJ,GAAG;IAEJ,IAAI,cAAc,CAAA,GAAA,aAAK,EAAkB;IACzC,M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AE5C,IAAI,kBAAkB,CAAA,GAAA,aAAK,EAAE;IAC7B,CAAA,GAAA,sBAAc,EAAE;QACd,6DAA6D;QAC7D,wCAAwC;QACxC,IAAI,aAAa,aAAa,OAAO;QACrC,IAAI,UAAU,UAAU,OAAO,EAAE;YAC/B,aAAa,OAAO,GAAG;YACvB,UAAU,OAAO,GAAG;QACtB;QAEA,IAAI,iBAAiB,CAAC,aAAa,OAAO,IACrC,cACA,MAAM,WAAW,CAAC,MAAM,GAAG,KAC3B,MAAM,WAAW,CAAC,MAAM,IAAI,MAAM,WAAW,CAAC,WAAW,CAAC,MAAM,IAG/D,CAAA,cAAc,MAAM,WAAW,CAAC,MAAM,KAAK,gBAAgB,OAAO,AAAD;QAEvE,IAAI,gBAAgB;YAClB,aAAa,OAAO,GAAG;YACvB;QACF;QACA,gBAAgB,OAAO,GAAG,MAAM,WAAW,CAAC,MAAM;IACpD,GAAG;QAAC,MAAM,WAAW;QAAE,MAAM,WAAW;QAAE;QAAW;QAAY;KAAM;IAEvE,OAAO;QACL,kBAAkB,CAAC;QACnB,iBAAiB;iCACf;QACF;IACF;AACF;AAEA,wFAAwF;AACxF,2GAA2G;AAC3G,MAAM,0DAAe,CAAA,GAAA,YAAI,EAAE,UAAU,CAAC;AAGtC,SAAS,2CACP,MAAiC,EACjC,YAAgC;IAEhC,qBACE,gCAAC,CAAA,GAAA,yCAAc;QACb,KAAK,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} from '@react-types/shared';\nimport {Layout, Rect, ReusableView, useVirtualizerState, VirtualizerState} from '@react-stately/virtualizer';\nimport {mergeProps, useLayoutEffect} from '@react-aria/utils';\nimport React, {createContext, HTMLAttributes, ReactElement, ReactNode, RefObject, useCallback, useMemo, useRef} from 'react';\nimport {ScrollView} from './ScrollView';\nimport {VirtualizerItem} from './VirtualizerItem';\n\ninterface VirtualizerProps<T extends object, V, O> extends Omit<HTMLAttributes<HTMLElement>, 'children'> {\n children: (type: string, content: T) => V,\n renderWrapper?: (\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 layout: Layout<T, O>,\n collection: Collection<T>,\n focusedKey?: Key,\n sizeToFit?: 'width' | 'height',\n scrollDirection?: 'horizontal' | 'vertical' | 'both',\n isLoading?: boolean,\n onLoadMore?: () => void,\n layoutOptions?: O\n}\n\nexport const VirtualizerContext = createContext<VirtualizerState<any, any, any> | null>(null);\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 focusedKey,\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 renderWrapper: renderWrapper || defaultRenderWrapper,\n onVisibleRectChange(rect) {\n ref.current.scrollLeft = rect.x;\n ref.current.scrollTop = rect.y;\n },\n persistedKeys: useMemo(() => focusedKey != null ? new Set([focusedKey]) : new Set(), [focusedKey]),\n layoutOptions\n });\n\n let {virtualizerProps, scrollViewProps} = useVirtualizer(props, state, ref);\n\n return (\n <ScrollView\n {...mergeProps(otherProps, virtualizerProps, scrollViewProps)}\n ref={ref}\n contentSize={state.contentSize}\n onScrollStart={state.startScrolling}\n onScrollEnd={state.endScrolling}\n sizeToFit={sizeToFit}\n scrollDirection={scrollDirection}>\n <VirtualizerContext.Provider value={state}>\n {state.visibleViews}\n </VirtualizerContext.Provider>\n </ScrollView>\n );\n}\n\ninterface VirtualizerOptions {\n tabIndex?: number,\n focusedKey?: Key,\n isLoading?: boolean,\n onLoadMore?: () => void\n}\n\n// eslint-disable-next-line @typescript-eslint/no-unused-vars\nexport function useVirtualizer<T extends object, V extends ReactNode, W>(props: VirtualizerOptions, state: VirtualizerState<T, V, W>, ref: RefObject<HTMLElement | null>) {\n let {isLoading, onLoadMore} = props;\n let {setVisibleRect, virtualizer} = state;\n\n // Handle scrolling, and call onLoadMore when nearing the bottom.\n let isLoadingRef = useRef(isLoading);\n let prevProps = useRef(props);\n let onVisibleRectChange = useCallback((rect: Rect) => {\n setVisibleRect(rect);\n\n if (!isLoadingRef.current && onLoadMore) {\n let scrollOffset = virtualizer.contentSize.height - rect.height * 2;\n if (rect.y > scrollOffset) {\n isLoadingRef.current = true;\n onLoadMore();\n }\n }\n }, [onLoadMore, setVisibleRect, virtualizer]);\n\n let lastContentSize = useRef(0);\n useLayoutEffect(() => {\n // Only update isLoadingRef if props object actually changed,\n // not if a local state change occurred.\n let wasLoading = isLoadingRef.current;\n if (props !== prevProps.current) {\n isLoadingRef.current = isLoading;\n prevProps.current = props;\n }\n\n let shouldLoadMore = !isLoadingRef.current\n && onLoadMore\n && state.contentSize.height > 0\n && state.contentSize.height <= state.virtualizer.visibleRect.height\n // Only try loading more if the content size changed, or if we just finished\n // loading and still have room for more items.\n && (wasLoading || state.contentSize.height !== lastContentSize.current);\n\n if (shouldLoadMore) {\n isLoadingRef.current = true;\n onLoadMore();\n }\n lastContentSize.current = state.contentSize.height;\n }, [state.contentSize, state.virtualizer, isLoading, onLoadMore, props]);\n\n return {\n virtualizerProps: {},\n scrollViewProps: {\n onVisibleRectChange\n }\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 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"}
|
|
@@ -29,7 +29,7 @@ $parcel$export(module.exports, "layoutInfoToStyle", () => $d6a26279cc31826b$expo
|
|
|
29
29
|
function $d6a26279cc31826b$export$6796df8ba7398521(props) {
|
|
30
30
|
let { className: className, layoutInfo: layoutInfo, virtualizer: virtualizer, parent: parent, children: children } = props;
|
|
31
31
|
let { direction: direction } = (0, $eXWCF$reactariai18n.useLocale)();
|
|
32
|
-
let ref = (0, $eXWCF$react.useRef)();
|
|
32
|
+
let ref = (0, $eXWCF$react.useRef)(undefined);
|
|
33
33
|
(0, $7d70e069fceb2deb$exports.useVirtualizerItem)({
|
|
34
34
|
layoutInfo: layoutInfo,
|
|
35
35
|
virtualizer: virtualizer,
|
|
@@ -67,7 +67,9 @@ function $d6a26279cc31826b$export$1481e64fbe01b8b3(layoutInfo, dir, parent) {
|
|
|
67
67
|
position: layoutInfo.isSticky ? 'sticky' : 'absolute',
|
|
68
68
|
// Sticky elements are positioned in normal document flow. Display inline-block so that they don't push other sticky columns onto the following rows.
|
|
69
69
|
display: layoutInfo.isSticky ? 'inline-block' : undefined,
|
|
70
|
-
|
|
70
|
+
// Use clip instead of hidden to avoid creating an implicit generic container in the accessibility tree in Firefox.
|
|
71
|
+
// Hidden still allows programmatic scrolling whereas clip does not.
|
|
72
|
+
overflow: layoutInfo.allowOverflow ? 'visible' : 'clip',
|
|
71
73
|
opacity: layoutInfo.opacity,
|
|
72
74
|
zIndex: layoutInfo.zIndex,
|
|
73
75
|
transform: layoutInfo.transform,
|