@react-aria/virtualizer 4.1.9 → 4.1.11

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.
@@ -56,16 +56,6 @@ function $00ca8c0b29e3e07c$export$2ea0c4974da4731b(props, ref) {
56
56
  }).current;
57
57
  let { direction: direction } = (0, $kvIfm$reactariai18n.useLocale)();
58
58
  let [isScrolling, setScrolling] = (0, $kvIfm$react.useState)(false);
59
- let onScrollTimeout = (0, $kvIfm$react.useCallback)(()=>{
60
- state.isScrolling = false;
61
- setScrolling(false);
62
- state.scrollTimeout = null;
63
- window.dispatchEvent(new Event('tk.connect-observer'));
64
- onScrollEnd === null || onScrollEnd === void 0 ? void 0 : onScrollEnd();
65
- }, [
66
- state,
67
- onScrollEnd
68
- ]);
69
59
  let onScroll = (0, $kvIfm$react.useCallback)((e)=>{
70
60
  if (e.target !== e.currentTarget) return;
71
61
  if (props.onScroll) props.onScroll(e);
@@ -87,10 +77,16 @@ function $00ca8c0b29e3e07c$export$2ea0c4974da4731b(props, ref) {
87
77
  // keep track of the current timeout time and only reschedule
88
78
  // the timer when it is getting close.
89
79
  let now = Date.now();
90
- if (!('onscrollend' in window) && state.scrollEndTime <= now + 50) {
80
+ if (state.scrollEndTime <= now + 50) {
91
81
  state.scrollEndTime = now + 300;
92
82
  if (state.scrollTimeout != null) clearTimeout(state.scrollTimeout);
93
- state.scrollTimeout = setTimeout(onScrollTimeout, 300);
83
+ state.scrollTimeout = setTimeout(()=>{
84
+ state.isScrolling = false;
85
+ setScrolling(false);
86
+ state.scrollTimeout = null;
87
+ window.dispatchEvent(new Event('tk.connect-observer'));
88
+ if (onScrollEnd) onScrollEnd();
89
+ }, 300);
94
90
  }
95
91
  });
96
92
  }, [
@@ -100,11 +96,10 @@ function $00ca8c0b29e3e07c$export$2ea0c4974da4731b(props, ref) {
100
96
  contentSize,
101
97
  onVisibleRectChange,
102
98
  onScrollStart,
103
- onScrollTimeout
99
+ onScrollEnd
104
100
  ]);
105
101
  // Attach event directly to ref so RAC Virtualizer doesn't need to send props upward.
106
102
  (0, $kvIfm$reactariautils.useEvent)(ref, 'scroll', onScroll);
107
- (0, $kvIfm$reactariautils.useEvent)(ref, 'scrollend', onScrollTimeout);
108
103
  (0, $kvIfm$react.useEffect)(()=>{
109
104
  return ()=>{
110
105
  if (state.scrollTimeout != null) clearTimeout(state.scrollTimeout);
@@ -113,7 +108,7 @@ function $00ca8c0b29e3e07c$export$2ea0c4974da4731b(props, ref) {
113
108
  // eslint-disable-next-line react-hooks/exhaustive-deps
114
109
  }, []);
115
110
  let isUpdatingSize = (0, $kvIfm$react.useRef)(false);
116
- let updateSize = (0, $kvIfm$reactariautils.useEffectEvent)((flush)=>{
111
+ let updateSize = (0, $kvIfm$react.useCallback)((flush)=>{
117
112
  let dom = ref.current;
118
113
  if (!dom || isUpdatingSize.current) return;
119
114
  // Prevent reentrancy when resize observer fires, triggers re-layout that results in
@@ -146,10 +141,17 @@ function $00ca8c0b29e3e07c$export$2ea0c4974da4731b(props, ref) {
146
141
  }
147
142
  }
148
143
  isUpdatingSize.current = false;
149
- });
144
+ }, [
145
+ ref,
146
+ state,
147
+ onVisibleRectChange
148
+ ]);
149
+ let updateSizeEvent = (0, $kvIfm$reactariautils.useEffectEvent)(updateSize);
150
150
  // Update visible rect when the content size changes, in case scrollbars need to appear or disappear.
151
151
  let lastContentSize = (0, $kvIfm$react.useRef)(null);
152
152
  let [update, setUpdate] = (0, $kvIfm$react.useState)({});
153
+ // We only contain a call to setState in here for testing environments.
154
+ // eslint-disable-next-line react-hooks/exhaustive-deps
153
155
  (0, $kvIfm$reactariautils.useLayoutEffect)(()=>{
154
156
  if (!isUpdatingSize.current && (lastContentSize.current == null || !contentSize.equals(lastContentSize.current))) {
155
157
  // React doesn't allow flushSync inside effects, so queue a microtask.
@@ -165,13 +167,13 @@ function $00ca8c0b29e3e07c$export$2ea0c4974da4731b(props, ref) {
165
167
  setUpdate({});
166
168
  lastContentSize.current = contentSize;
167
169
  return;
168
- } else queueMicrotask(()=>updateSize((0, $kvIfm$reactdom.flushSync)));
170
+ } else queueMicrotask(()=>updateSizeEvent((0, $kvIfm$reactdom.flushSync)));
169
171
  }
170
172
  lastContentSize.current = contentSize;
171
173
  });
172
174
  // Will only run in tests, needs to be in separate effect so it is properly run in the next render in strict mode.
173
175
  (0, $kvIfm$reactariautils.useLayoutEffect)(()=>{
174
- updateSize((fn)=>fn());
176
+ updateSizeEvent((fn)=>fn());
175
177
  }, [
176
178
  update
177
179
  ]);
@@ -1 +1 @@
1
- {"mappings":";;;;;;;;;;;;;;;;;;AAAA;;;;;;;;;;CAUC,GAED,aAAa;;;;;;;AA4Bb,SAAS,iCAAW,KAAsB,EAAE,GAAwC;IAClF,MAAM,CAAA,GAAA,kCAAW,EAAE;IACnB,IAAI,mBAAC,eAAe,gBAAE,YAAY,EAAC,GAAG,0CAAc,OAAO;IAE3D,qBACE,0DAAC;QAAI,MAAK;QAAgB,GAAG,eAAe;QAAE,KAAK;qBACjD,0DAAC,OAAQ,cACN,MAAM,QAAQ;AAIvB;AAEA,MAAM,yDAEN,CAAA,GAAA,sCAAI,EAAE,UAAU,CAAC;AASV,SAAS,0CAAc,KAAsB,EAAE,GAAkC;IACtF,IAAI,eACF,WAAW,uBACX,mBAAmB,cACnB,UAAU,iBACV,aAAa,eACb,WAAW,mBACX,kBAAkB,QAClB,GAAG,YACJ,GAAG;IAEJ,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;IAE3C,IAAI,kBAAkB,CAAA,GAAA,wBAAU,EAAE;QAChC,MAAM,WAAW,GAAG;QACpB,aAAa;QACb,MAA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C/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;qBACL;QACA,iBAAiB;YACf,GAAG,UAAU;mBACb;QACF;QACA,cAAc;YACZ,MAAM;YACN,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 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 {...contentProps}>\n {props.children}\n </div>\n </div>\n );\n}\n\nconst ScrollViewForwardRef:\n React.ForwardRefExoticComponent<ScrollViewProps & React.RefAttributes<HTMLDivElement | null>> =\nReact.forwardRef(ScrollView);\nexport {ScrollViewForwardRef as ScrollView};\n\ninterface ScrollViewAria {\n isScrolling: boolean,\n scrollViewProps: HTMLAttributes<HTMLElement>,\n contentProps: HTMLAttributes<HTMLElement>\n}\n\nexport function useScrollView(props: ScrollViewProps, ref: RefObject<HTMLElement | null>): ScrollViewAria {\n let {\n contentSize,\n onVisibleRectChange,\n innerStyle,\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 as ReturnType<typeof setTimeout> | null,\n width: 0,\n height: 0,\n isScrolling: false\n }).current;\n let {direction} = useLocale();\n\n let [isScrolling, setScrolling] = useState(false);\n\n let onScrollTimeout = useCallback(() => {\n state.isScrolling = false;\n setScrolling(false);\n state.scrollTimeout = null;\n\n window.dispatchEvent(new Event('tk.connect-observer'));\n onScrollEnd?.();\n }, [state, onScrollEnd]);\n\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 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 // Pause typekit MutationObserver during scrolling.\n window.dispatchEvent(new Event('tk.disconnect-observer'));\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 (!('onscrollend' in window) && state.scrollEndTime <= now + 50) {\n state.scrollEndTime = now + 300;\n\n if (state.scrollTimeout != null) {\n clearTimeout(state.scrollTimeout);\n }\n\n state.scrollTimeout = setTimeout(onScrollTimeout, 300);\n }\n });\n }, [props, direction, state, contentSize, onVisibleRectChange, onScrollStart, onScrollTimeout]);\n\n // Attach event directly to ref so RAC Virtualizer doesn't need to send props upward.\n useEvent(ref, 'scroll', onScroll);\n useEvent(ref, 'scrollend', onScrollTimeout);\n\n useEffect(() => {\n return () => {\n if (state.scrollTimeout != null) {\n clearTimeout(state.scrollTimeout);\n }\n\n if (state.isScrolling) {\n window.dispatchEvent(new Event('tk.connect-observer'));\n }\n };\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, []);\n\n let isUpdatingSize = useRef(false);\n let updateSize = useEffectEvent((flush: typeof flushSync) => {\n let dom = ref.current;\n if (!dom || isUpdatingSize.current) {\n return;\n }\n\n // Prevent reentrancy when resize observer fires, triggers re-layout that results in\n // content size update, causing below layout effect to fire. This avoids infinite loops.\n isUpdatingSize.current = true;\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 (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 isUpdatingSize.current = false;\n });\n\n // Update visible rect when the content size changes, in case scrollbars need to appear or disappear.\n let lastContentSize = useRef<Size | null>(null);\n let [update, setUpdate] = useState({});\n useLayoutEffect(() => {\n if (!isUpdatingSize.current && (lastContentSize.current == null || !contentSize.equals(lastContentSize.current))) {\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 // If we are in an `act` environment, update immediately without a microtask so you don't need\n // to mock timers in tests. In this case, the update is synchronous already.\n // IS_REACT_ACT_ENVIRONMENT is used by React 18. Previous versions checked for the `jest` global.\n // https://github.com/reactwg/react-18/discussions/102\n // @ts-ignore\n if (typeof IS_REACT_ACT_ENVIRONMENT === 'boolean' ? IS_REACT_ACT_ENVIRONMENT : typeof jest !== 'undefined') {\n // This is so we update size in a separate render but within the same act. Needs to be setState instead of refs\n // due to strict mode.\n setUpdate({});\n lastContentSize.current = contentSize;\n return;\n } else {\n queueMicrotask(() => updateSize(flushSync));\n }\n }\n\n lastContentSize.current = contentSize;\n });\n\n // Will only run in tests, needs to be in separate effect so it is properly run in the next render in strict mode.\n useLayoutEffect(() => {\n updateSize(fn => fn());\n }, [update]);\n\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 isScrolling,\n scrollViewProps: {\n ...otherProps,\n style\n },\n contentProps: {\n role: 'presentation',\n style: innerStyle\n }\n };\n}\n"],"names":[],"version":3,"file":"ScrollView.main.js.map"}
1
+ {"mappings":";;;;;;;;;;;;;;;;;;AAAA;;;;;;;;;;CAUC,GAED,aAAa;;;;;;;AA4Bb,SAAS,iCAAW,KAAsB,EAAE,GAAwC;IAClF,MAAM,CAAA,GAAA,kCAAW,EAAE;IACnB,IAAI,mBAAC,eAAe,gBAAE,YAAY,EAAC,GAAG,0CAAc,OAAO;IAE3D,qBACE,0DAAC;QAAI,MAAK;QAAgB,GAAG,eAAe;QAAE,KAAK;qBACjD,0DAAC,OAAQ,cACN,MAAM,QAAQ;AAIvB;AAEA,MAAM,yDAEN,CAAA,GAAA,sCAAI,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AC1G,+GAA+G;gBAC/G,sBAAsB;gBACtB,UAAU,CAAC;gBACX,gBAAgB,OAAO,GAAG;gBAC1B;YACF,OACE,eAAe,IAAM,gBAAgB,CAAA,GAAA,yBAAQ;;QAIjD,gBAAgB,OAAO,GAAG;IAC5B;IAEA,kHAAkH;IAClH,CAAA,GAAA,qCAAc,EAAE;QACd,gBAAgB,CAAA,KAAM;IACxB,GAAG;QAAC;KAAO;IAEX,IAAI,WAAW,CAAA,GAAA,wBAAU,EAAE;QACzB,WAAW,CAAA,GAAA,yBAAQ;IACrB,GAAG;QAAC;KAAW;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;qBACL;QACA,iBAAiB;YACf,GAAG,UAAU;mBACb;QACF;QACA,cAAc;YACZ,MAAM;YACN,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 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 {...contentProps}>\n {props.children}\n </div>\n </div>\n );\n}\n\nconst ScrollViewForwardRef:\n React.ForwardRefExoticComponent<ScrollViewProps & React.RefAttributes<HTMLDivElement | null>> =\nReact.forwardRef(ScrollView);\nexport {ScrollViewForwardRef as ScrollView};\n\ninterface ScrollViewAria {\n isScrolling: boolean,\n scrollViewProps: HTMLAttributes<HTMLElement>,\n contentProps: HTMLAttributes<HTMLElement>\n}\n\nexport function useScrollView(props: ScrollViewProps, ref: RefObject<HTMLElement | null>): ScrollViewAria {\n let {\n contentSize,\n onVisibleRectChange,\n innerStyle,\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 as ReturnType<typeof setTimeout> | null,\n width: 0,\n height: 0,\n isScrolling: false\n }).current;\n let {direction} = useLocale();\n\n let [isScrolling, setScrolling] = useState(false);\n\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 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 // Pause typekit MutationObserver during scrolling.\n window.dispatchEvent(new Event('tk.disconnect-observer'));\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 if (state.scrollTimeout != null) {\n clearTimeout(state.scrollTimeout);\n }\n\n state.scrollTimeout = setTimeout(() => {\n state.isScrolling = false;\n setScrolling(false);\n state.scrollTimeout = null;\n\n window.dispatchEvent(new Event('tk.connect-observer'));\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 useEffect(() => {\n return () => {\n if (state.scrollTimeout != null) {\n clearTimeout(state.scrollTimeout);\n }\n\n if (state.isScrolling) {\n window.dispatchEvent(new Event('tk.connect-observer'));\n }\n };\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, []);\n\n let isUpdatingSize = useRef(false);\n let updateSize = useCallback((flush: typeof flushSync) => {\n let dom = ref.current;\n if (!dom || isUpdatingSize.current) {\n return;\n }\n\n // Prevent reentrancy when resize observer fires, triggers re-layout that results in\n // content size update, causing below layout effect to fire. This avoids infinite loops.\n isUpdatingSize.current = true;\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 (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 isUpdatingSize.current = false;\n }, [ref, state, onVisibleRectChange]);\n let updateSizeEvent = useEffectEvent(updateSize);\n\n // Update visible rect when the content size changes, in case scrollbars need to appear or disappear.\n let lastContentSize = useRef<Size | null>(null);\n let [update, setUpdate] = useState({});\n // We only contain a call to setState in here for testing environments.\n // eslint-disable-next-line react-hooks/exhaustive-deps\n useLayoutEffect(() => {\n if (!isUpdatingSize.current && (lastContentSize.current == null || !contentSize.equals(lastContentSize.current))) {\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 // If we are in an `act` environment, update immediately without a microtask so you don't need\n // to mock timers in tests. In this case, the update is synchronous already.\n // IS_REACT_ACT_ENVIRONMENT is used by React 18. Previous versions checked for the `jest` global.\n // https://github.com/reactwg/react-18/discussions/102\n // @ts-ignore\n if (typeof IS_REACT_ACT_ENVIRONMENT === 'boolean' ? IS_REACT_ACT_ENVIRONMENT : typeof jest !== 'undefined') {\n // This is so we update size in a separate render but within the same act. Needs to be setState instead of refs\n // due to strict mode.\n setUpdate({});\n lastContentSize.current = contentSize;\n return;\n } else {\n queueMicrotask(() => updateSizeEvent(flushSync));\n }\n }\n\n lastContentSize.current = contentSize;\n });\n\n // Will only run in tests, needs to be in separate effect so it is properly run in the next render in strict mode.\n useLayoutEffect(() => {\n updateSizeEvent(fn => fn());\n }, [update]);\n\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 isScrolling,\n scrollViewProps: {\n ...otherProps,\n style\n },\n contentProps: {\n role: 'presentation',\n style: innerStyle\n }\n };\n}\n"],"names":[],"version":3,"file":"ScrollView.main.js.map"}
@@ -45,16 +45,6 @@ function $44a6ee657928b002$export$2ea0c4974da4731b(props, ref) {
45
45
  }).current;
46
46
  let { direction: direction } = (0, $f9kpT$useLocale)();
47
47
  let [isScrolling, setScrolling] = (0, $f9kpT$useState)(false);
48
- let onScrollTimeout = (0, $f9kpT$useCallback)(()=>{
49
- state.isScrolling = false;
50
- setScrolling(false);
51
- state.scrollTimeout = null;
52
- window.dispatchEvent(new Event('tk.connect-observer'));
53
- onScrollEnd === null || onScrollEnd === void 0 ? void 0 : onScrollEnd();
54
- }, [
55
- state,
56
- onScrollEnd
57
- ]);
58
48
  let onScroll = (0, $f9kpT$useCallback)((e)=>{
59
49
  if (e.target !== e.currentTarget) return;
60
50
  if (props.onScroll) props.onScroll(e);
@@ -76,10 +66,16 @@ function $44a6ee657928b002$export$2ea0c4974da4731b(props, ref) {
76
66
  // keep track of the current timeout time and only reschedule
77
67
  // the timer when it is getting close.
78
68
  let now = Date.now();
79
- if (!('onscrollend' in window) && state.scrollEndTime <= now + 50) {
69
+ if (state.scrollEndTime <= now + 50) {
80
70
  state.scrollEndTime = now + 300;
81
71
  if (state.scrollTimeout != null) clearTimeout(state.scrollTimeout);
82
- state.scrollTimeout = setTimeout(onScrollTimeout, 300);
72
+ state.scrollTimeout = setTimeout(()=>{
73
+ state.isScrolling = false;
74
+ setScrolling(false);
75
+ state.scrollTimeout = null;
76
+ window.dispatchEvent(new Event('tk.connect-observer'));
77
+ if (onScrollEnd) onScrollEnd();
78
+ }, 300);
83
79
  }
84
80
  });
85
81
  }, [
@@ -89,11 +85,10 @@ function $44a6ee657928b002$export$2ea0c4974da4731b(props, ref) {
89
85
  contentSize,
90
86
  onVisibleRectChange,
91
87
  onScrollStart,
92
- onScrollTimeout
88
+ onScrollEnd
93
89
  ]);
94
90
  // Attach event directly to ref so RAC Virtualizer doesn't need to send props upward.
95
91
  (0, $f9kpT$useEvent)(ref, 'scroll', onScroll);
96
- (0, $f9kpT$useEvent)(ref, 'scrollend', onScrollTimeout);
97
92
  (0, $f9kpT$useEffect)(()=>{
98
93
  return ()=>{
99
94
  if (state.scrollTimeout != null) clearTimeout(state.scrollTimeout);
@@ -102,7 +97,7 @@ function $44a6ee657928b002$export$2ea0c4974da4731b(props, ref) {
102
97
  // eslint-disable-next-line react-hooks/exhaustive-deps
103
98
  }, []);
104
99
  let isUpdatingSize = (0, $f9kpT$useRef)(false);
105
- let updateSize = (0, $f9kpT$useEffectEvent)((flush)=>{
100
+ let updateSize = (0, $f9kpT$useCallback)((flush)=>{
106
101
  let dom = ref.current;
107
102
  if (!dom || isUpdatingSize.current) return;
108
103
  // Prevent reentrancy when resize observer fires, triggers re-layout that results in
@@ -135,10 +130,17 @@ function $44a6ee657928b002$export$2ea0c4974da4731b(props, ref) {
135
130
  }
136
131
  }
137
132
  isUpdatingSize.current = false;
138
- });
133
+ }, [
134
+ ref,
135
+ state,
136
+ onVisibleRectChange
137
+ ]);
138
+ let updateSizeEvent = (0, $f9kpT$useEffectEvent)(updateSize);
139
139
  // Update visible rect when the content size changes, in case scrollbars need to appear or disappear.
140
140
  let lastContentSize = (0, $f9kpT$useRef)(null);
141
141
  let [update, setUpdate] = (0, $f9kpT$useState)({});
142
+ // We only contain a call to setState in here for testing environments.
143
+ // eslint-disable-next-line react-hooks/exhaustive-deps
142
144
  (0, $f9kpT$useLayoutEffect)(()=>{
143
145
  if (!isUpdatingSize.current && (lastContentSize.current == null || !contentSize.equals(lastContentSize.current))) {
144
146
  // React doesn't allow flushSync inside effects, so queue a microtask.
@@ -154,13 +156,13 @@ function $44a6ee657928b002$export$2ea0c4974da4731b(props, ref) {
154
156
  setUpdate({});
155
157
  lastContentSize.current = contentSize;
156
158
  return;
157
- } else queueMicrotask(()=>updateSize((0, $f9kpT$flushSync)));
159
+ } else queueMicrotask(()=>updateSizeEvent((0, $f9kpT$flushSync)));
158
160
  }
159
161
  lastContentSize.current = contentSize;
160
162
  });
161
163
  // Will only run in tests, needs to be in separate effect so it is properly run in the next render in strict mode.
162
164
  (0, $f9kpT$useLayoutEffect)(()=>{
163
- updateSize((fn)=>fn());
165
+ updateSizeEvent((fn)=>fn());
164
166
  }, [
165
167
  update
166
168
  ]);
@@ -45,16 +45,6 @@ function $44a6ee657928b002$export$2ea0c4974da4731b(props, ref) {
45
45
  }).current;
46
46
  let { direction: direction } = (0, $f9kpT$useLocale)();
47
47
  let [isScrolling, setScrolling] = (0, $f9kpT$useState)(false);
48
- let onScrollTimeout = (0, $f9kpT$useCallback)(()=>{
49
- state.isScrolling = false;
50
- setScrolling(false);
51
- state.scrollTimeout = null;
52
- window.dispatchEvent(new Event('tk.connect-observer'));
53
- onScrollEnd === null || onScrollEnd === void 0 ? void 0 : onScrollEnd();
54
- }, [
55
- state,
56
- onScrollEnd
57
- ]);
58
48
  let onScroll = (0, $f9kpT$useCallback)((e)=>{
59
49
  if (e.target !== e.currentTarget) return;
60
50
  if (props.onScroll) props.onScroll(e);
@@ -76,10 +66,16 @@ function $44a6ee657928b002$export$2ea0c4974da4731b(props, ref) {
76
66
  // keep track of the current timeout time and only reschedule
77
67
  // the timer when it is getting close.
78
68
  let now = Date.now();
79
- if (!('onscrollend' in window) && state.scrollEndTime <= now + 50) {
69
+ if (state.scrollEndTime <= now + 50) {
80
70
  state.scrollEndTime = now + 300;
81
71
  if (state.scrollTimeout != null) clearTimeout(state.scrollTimeout);
82
- state.scrollTimeout = setTimeout(onScrollTimeout, 300);
72
+ state.scrollTimeout = setTimeout(()=>{
73
+ state.isScrolling = false;
74
+ setScrolling(false);
75
+ state.scrollTimeout = null;
76
+ window.dispatchEvent(new Event('tk.connect-observer'));
77
+ if (onScrollEnd) onScrollEnd();
78
+ }, 300);
83
79
  }
84
80
  });
85
81
  }, [
@@ -89,11 +85,10 @@ function $44a6ee657928b002$export$2ea0c4974da4731b(props, ref) {
89
85
  contentSize,
90
86
  onVisibleRectChange,
91
87
  onScrollStart,
92
- onScrollTimeout
88
+ onScrollEnd
93
89
  ]);
94
90
  // Attach event directly to ref so RAC Virtualizer doesn't need to send props upward.
95
91
  (0, $f9kpT$useEvent)(ref, 'scroll', onScroll);
96
- (0, $f9kpT$useEvent)(ref, 'scrollend', onScrollTimeout);
97
92
  (0, $f9kpT$useEffect)(()=>{
98
93
  return ()=>{
99
94
  if (state.scrollTimeout != null) clearTimeout(state.scrollTimeout);
@@ -102,7 +97,7 @@ function $44a6ee657928b002$export$2ea0c4974da4731b(props, ref) {
102
97
  // eslint-disable-next-line react-hooks/exhaustive-deps
103
98
  }, []);
104
99
  let isUpdatingSize = (0, $f9kpT$useRef)(false);
105
- let updateSize = (0, $f9kpT$useEffectEvent)((flush)=>{
100
+ let updateSize = (0, $f9kpT$useCallback)((flush)=>{
106
101
  let dom = ref.current;
107
102
  if (!dom || isUpdatingSize.current) return;
108
103
  // Prevent reentrancy when resize observer fires, triggers re-layout that results in
@@ -135,10 +130,17 @@ function $44a6ee657928b002$export$2ea0c4974da4731b(props, ref) {
135
130
  }
136
131
  }
137
132
  isUpdatingSize.current = false;
138
- });
133
+ }, [
134
+ ref,
135
+ state,
136
+ onVisibleRectChange
137
+ ]);
138
+ let updateSizeEvent = (0, $f9kpT$useEffectEvent)(updateSize);
139
139
  // Update visible rect when the content size changes, in case scrollbars need to appear or disappear.
140
140
  let lastContentSize = (0, $f9kpT$useRef)(null);
141
141
  let [update, setUpdate] = (0, $f9kpT$useState)({});
142
+ // We only contain a call to setState in here for testing environments.
143
+ // eslint-disable-next-line react-hooks/exhaustive-deps
142
144
  (0, $f9kpT$useLayoutEffect)(()=>{
143
145
  if (!isUpdatingSize.current && (lastContentSize.current == null || !contentSize.equals(lastContentSize.current))) {
144
146
  // React doesn't allow flushSync inside effects, so queue a microtask.
@@ -154,13 +156,13 @@ function $44a6ee657928b002$export$2ea0c4974da4731b(props, ref) {
154
156
  setUpdate({});
155
157
  lastContentSize.current = contentSize;
156
158
  return;
157
- } else queueMicrotask(()=>updateSize((0, $f9kpT$flushSync)));
159
+ } else queueMicrotask(()=>updateSizeEvent((0, $f9kpT$flushSync)));
158
160
  }
159
161
  lastContentSize.current = contentSize;
160
162
  });
161
163
  // Will only run in tests, needs to be in separate effect so it is properly run in the next render in strict mode.
162
164
  (0, $f9kpT$useLayoutEffect)(()=>{
163
- updateSize((fn)=>fn());
165
+ updateSizeEvent((fn)=>fn());
164
166
  }, [
165
167
  update
166
168
  ]);
@@ -1 +1 @@
1
- {"mappings":";;;;;;;AAAA;;;;;;;;;;CAUC,GAED,aAAa;;;;;;;AA4Bb,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,OAAQ,cACN,MAAM,QAAQ;AAIvB;AAEA,MAAM,yDAEN,CAAA,GAAA,YAAI,EAAE,UAAU,CAAC;AASV,SAAS,0CAAc,KAAsB,EAAE,GAAkC;IACtF,IAAI,eACF,WAAW,uBACX,mBAAmB,cACnB,UAAU,iBACV,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;IAE3C,IAAI,kBAAkB,CAAA,GAAA,kBAAU,EAAE;QAChC,MAAM,WAAW,GAAG;QACp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A6B;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;qBACL;QACA,iBAAiB;YACf,GAAG,UAAU;mBACb;QACF;QACA,cAAc;YACZ,MAAM;YACN,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 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 {...contentProps}>\n {props.children}\n </div>\n </div>\n );\n}\n\nconst ScrollViewForwardRef:\n React.ForwardRefExoticComponent<ScrollViewProps & React.RefAttributes<HTMLDivElement | null>> =\nReact.forwardRef(ScrollView);\nexport {ScrollViewForwardRef as ScrollView};\n\ninterface ScrollViewAria {\n isScrolling: boolean,\n scrollViewProps: HTMLAttributes<HTMLElement>,\n contentProps: HTMLAttributes<HTMLElement>\n}\n\nexport function useScrollView(props: ScrollViewProps, ref: RefObject<HTMLElement | null>): ScrollViewAria {\n let {\n contentSize,\n onVisibleRectChange,\n innerStyle,\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 as ReturnType<typeof setTimeout> | null,\n width: 0,\n height: 0,\n isScrolling: false\n }).current;\n let {direction} = useLocale();\n\n let [isScrolling, setScrolling] = useState(false);\n\n let onScrollTimeout = useCallback(() => {\n state.isScrolling = false;\n setScrolling(false);\n state.scrollTimeout = null;\n\n window.dispatchEvent(new Event('tk.connect-observer'));\n onScrollEnd?.();\n }, [state, onScrollEnd]);\n\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 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 // Pause typekit MutationObserver during scrolling.\n window.dispatchEvent(new Event('tk.disconnect-observer'));\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 (!('onscrollend' in window) && state.scrollEndTime <= now + 50) {\n state.scrollEndTime = now + 300;\n\n if (state.scrollTimeout != null) {\n clearTimeout(state.scrollTimeout);\n }\n\n state.scrollTimeout = setTimeout(onScrollTimeout, 300);\n }\n });\n }, [props, direction, state, contentSize, onVisibleRectChange, onScrollStart, onScrollTimeout]);\n\n // Attach event directly to ref so RAC Virtualizer doesn't need to send props upward.\n useEvent(ref, 'scroll', onScroll);\n useEvent(ref, 'scrollend', onScrollTimeout);\n\n useEffect(() => {\n return () => {\n if (state.scrollTimeout != null) {\n clearTimeout(state.scrollTimeout);\n }\n\n if (state.isScrolling) {\n window.dispatchEvent(new Event('tk.connect-observer'));\n }\n };\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, []);\n\n let isUpdatingSize = useRef(false);\n let updateSize = useEffectEvent((flush: typeof flushSync) => {\n let dom = ref.current;\n if (!dom || isUpdatingSize.current) {\n return;\n }\n\n // Prevent reentrancy when resize observer fires, triggers re-layout that results in\n // content size update, causing below layout effect to fire. This avoids infinite loops.\n isUpdatingSize.current = true;\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 (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 isUpdatingSize.current = false;\n });\n\n // Update visible rect when the content size changes, in case scrollbars need to appear or disappear.\n let lastContentSize = useRef<Size | null>(null);\n let [update, setUpdate] = useState({});\n useLayoutEffect(() => {\n if (!isUpdatingSize.current && (lastContentSize.current == null || !contentSize.equals(lastContentSize.current))) {\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 // If we are in an `act` environment, update immediately without a microtask so you don't need\n // to mock timers in tests. In this case, the update is synchronous already.\n // IS_REACT_ACT_ENVIRONMENT is used by React 18. Previous versions checked for the `jest` global.\n // https://github.com/reactwg/react-18/discussions/102\n // @ts-ignore\n if (typeof IS_REACT_ACT_ENVIRONMENT === 'boolean' ? IS_REACT_ACT_ENVIRONMENT : typeof jest !== 'undefined') {\n // This is so we update size in a separate render but within the same act. Needs to be setState instead of refs\n // due to strict mode.\n setUpdate({});\n lastContentSize.current = contentSize;\n return;\n } else {\n queueMicrotask(() => updateSize(flushSync));\n }\n }\n\n lastContentSize.current = contentSize;\n });\n\n // Will only run in tests, needs to be in separate effect so it is properly run in the next render in strict mode.\n useLayoutEffect(() => {\n updateSize(fn => fn());\n }, [update]);\n\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 isScrolling,\n scrollViewProps: {\n ...otherProps,\n style\n },\n contentProps: {\n role: 'presentation',\n style: innerStyle\n }\n };\n}\n"],"names":[],"version":3,"file":"ScrollView.module.js.map"}
1
+ {"mappings":";;;;;;;AAAA;;;;;;;;;;CAUC,GAED,aAAa;;;;;;;AA4Bb,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,OAAQ,cACN,MAAM,QAAQ;AAIvB;AAEA,MAAM,yDAEN,CAAA,GAAA,YAAI,EAAE,U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C/G,sBAAsB;gBACtB,UAAU,CAAC;gBACX,gBAAgB,OAAO,GAAG;gBAC1B;YACF,OACE,eAAe,IAAM,gBAAgB,CAAA,GAAA,gBAAQ;;QAIjD,gBAAgB,OAAO,GAAG;IAC5B;IAEA,kHAAkH;IAClH,CAAA,GAAA,sBAAc,EAAE;QACd,gBAAgB,CAAA,KAAM;IACxB,GAAG;QAAC;KAAO;IAEX,IAAI,WAAW,CAAA,GAAA,kBAAU,EAAE;QACzB,WAAW,CAAA,GAAA,gBAAQ;IACrB,GAAG;QAAC;KAAW;IAEf,sEAAsE;IACtE,wDAAwD;IACxD,CAAA,GAAA,wBAAgB,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;qBACL;QACA,iBAAiB;YACf,GAAG,UAAU;mBACb;QACF;QACA,cAAc;YACZ,MAAM;YACN,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 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 {...contentProps}>\n {props.children}\n </div>\n </div>\n );\n}\n\nconst ScrollViewForwardRef:\n React.ForwardRefExoticComponent<ScrollViewProps & React.RefAttributes<HTMLDivElement | null>> =\nReact.forwardRef(ScrollView);\nexport {ScrollViewForwardRef as ScrollView};\n\ninterface ScrollViewAria {\n isScrolling: boolean,\n scrollViewProps: HTMLAttributes<HTMLElement>,\n contentProps: HTMLAttributes<HTMLElement>\n}\n\nexport function useScrollView(props: ScrollViewProps, ref: RefObject<HTMLElement | null>): ScrollViewAria {\n let {\n contentSize,\n onVisibleRectChange,\n innerStyle,\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 as ReturnType<typeof setTimeout> | null,\n width: 0,\n height: 0,\n isScrolling: false\n }).current;\n let {direction} = useLocale();\n\n let [isScrolling, setScrolling] = useState(false);\n\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 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 // Pause typekit MutationObserver during scrolling.\n window.dispatchEvent(new Event('tk.disconnect-observer'));\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 if (state.scrollTimeout != null) {\n clearTimeout(state.scrollTimeout);\n }\n\n state.scrollTimeout = setTimeout(() => {\n state.isScrolling = false;\n setScrolling(false);\n state.scrollTimeout = null;\n\n window.dispatchEvent(new Event('tk.connect-observer'));\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 useEffect(() => {\n return () => {\n if (state.scrollTimeout != null) {\n clearTimeout(state.scrollTimeout);\n }\n\n if (state.isScrolling) {\n window.dispatchEvent(new Event('tk.connect-observer'));\n }\n };\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, []);\n\n let isUpdatingSize = useRef(false);\n let updateSize = useCallback((flush: typeof flushSync) => {\n let dom = ref.current;\n if (!dom || isUpdatingSize.current) {\n return;\n }\n\n // Prevent reentrancy when resize observer fires, triggers re-layout that results in\n // content size update, causing below layout effect to fire. This avoids infinite loops.\n isUpdatingSize.current = true;\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 (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 isUpdatingSize.current = false;\n }, [ref, state, onVisibleRectChange]);\n let updateSizeEvent = useEffectEvent(updateSize);\n\n // Update visible rect when the content size changes, in case scrollbars need to appear or disappear.\n let lastContentSize = useRef<Size | null>(null);\n let [update, setUpdate] = useState({});\n // We only contain a call to setState in here for testing environments.\n // eslint-disable-next-line react-hooks/exhaustive-deps\n useLayoutEffect(() => {\n if (!isUpdatingSize.current && (lastContentSize.current == null || !contentSize.equals(lastContentSize.current))) {\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 // If we are in an `act` environment, update immediately without a microtask so you don't need\n // to mock timers in tests. In this case, the update is synchronous already.\n // IS_REACT_ACT_ENVIRONMENT is used by React 18. Previous versions checked for the `jest` global.\n // https://github.com/reactwg/react-18/discussions/102\n // @ts-ignore\n if (typeof IS_REACT_ACT_ENVIRONMENT === 'boolean' ? IS_REACT_ACT_ENVIRONMENT : typeof jest !== 'undefined') {\n // This is so we update size in a separate render but within the same act. Needs to be setState instead of refs\n // due to strict mode.\n setUpdate({});\n lastContentSize.current = contentSize;\n return;\n } else {\n queueMicrotask(() => updateSizeEvent(flushSync));\n }\n }\n\n lastContentSize.current = contentSize;\n });\n\n // Will only run in tests, needs to be in separate effect so it is properly run in the next render in strict mode.\n useLayoutEffect(() => {\n updateSizeEvent(fn => fn());\n }, [update]);\n\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 isScrolling,\n scrollViewProps: {\n ...otherProps,\n style\n },\n contentProps: {\n role: 'presentation',\n style: innerStyle\n }\n };\n}\n"],"names":[],"version":3,"file":"ScrollView.module.js.map"}
@@ -1 +1 @@
1
- {"mappings":";;;AAcA,4BACI,UAAU,GACV,qBAAqB,GACrB,oBAAoB,CAAC;AAezB,iCAAiC,WAAW,GAAE,OAAe,GAAG,aAAa,CAmC5E;AAED,8BAA8B,IAAI,EAAE,OAAO,EAAE,SAAS,EAAE,SAAS,GAAG,MAAM,CAkBzE;AAED,8BAA8B,IAAI,EAAE,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,GAAG,IAAI,CAiB3F;ACzFD;IACE,cAAc,CAAC,GAAG,EAAE,GAAG,EAAE,IAAI,EAAE,IAAI,GAAG,IAAI,CAAA;CAC3C;AAED;IACE,UAAU,EAAE,UAAU,GAAG,IAAI,CAAC;IAC9B,WAAW,EAAE,YAAY,CAAC;IAC1B,GAAG,EAAE,UAAU,WAAW,GAAG,IAAI,CAAC,CAAA;CACnC;AAED,mCAAmC,OAAO,EAAE,sBAAsB,GAAG;IAAC,UAAU,EAAE,MAAM,IAAI,CAAA;CAAC,CAkB5F;ACfD,yBAA0B,SAAQ,eAAe,WAAW,CAAC;IAC3D,WAAW,EAAE,IAAI,CAAC;IAClB,mBAAmB,EAAE,CAAC,IAAI,EAAE,IAAI,KAAK,IAAI,CAAC;IAC1C,QAAQ,CAAC,EAAE,SAAS,CAAC;IACrB,UAAU,CAAC,EAAE,aAAa,CAAC;IAC3B,aAAa,CAAC,EAAE,MAAM,IAAI,CAAC;IAC3B,WAAW,CAAC,EAAE,MAAM,IAAI,CAAC;IACzB,eAAe,CAAC,EAAE,YAAY,GAAG,UAAU,GAAG,MAAM,CAAA;CACrD;AAeD,OAAA,MAAM,YACJ,MAAM,yBAAyB,CAAC,eAAe,GAAG,MAAM,aAAa,CAAC,cAAc,GAAG,IAAI,CAAC,CAClE,CA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CAAC,EAAE,CAAC,CAAC,CAAC;IACpC,MAAM,EAAE,OAAO,CAAC,EAAE,CAAC,CAAC,CAAC;IACrB,UAAU,EAAE,WAAW,CAAC,CAAC,CAAC;IAC1B,aAAa,CAAC,EAAE,GAAG,CAAC,GAAG,CAAC,GAAG,IAAI,CAAC;IAChC,eAAe,CAAC,EAAE,YAAY,GAAG,UAAU,GAAG,MAAM,CAAC;IACrD,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,UAAU,CAAC,EAAE,MAAM,IAAI,CAAC;IACxB,aAAa,CAAC,EAAE,CAAC,CAAA;CAClB;AAID,OAAO,MAAM,aA8CP,CAAC,CAAC,SAAS,MAAM,EAAE,CAAC,EAAE,CAAC,EAAE,KAAK,EAAE,iBAAiB,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,GAAG;IAAC,GAAG,CAAC,EAAE,UAAU,cAAc,GAAG,IAAI,CAAC,CAAA;CAAC,KAAK,YAAY,CAAC","sources":["packages/@react-aria/virtualizer/src/packages/@react-aria/virtualizer/src/utils.ts","packages/@react-aria/virtualizer/src/packages/@react-aria/virtualizer/src/useVirtualizerItem.ts","packages/@react-aria/virtualizer/src/packages/@react-aria/virtualizer/src/ScrollView.tsx","packages/@react-aria/virtualizer/src/packages/@react-aria/virtualizer/src/VirtualizerItem.tsx","packages/@react-aria/virtualizer/src/packages/@react-aria/virtualizer/src/Virtualizer.tsx","packages/@react-aria/virtualizer/src/packages/@react-aria/virtualizer/src/index.ts","packages/@react-aria/virtualizer/src/index.ts"],"sourcesContent":[null,null,null,null,null,null,"/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nexport type {RTLOffsetType} from './utils';\nexport type {VirtualizerItemOptions} from './useVirtualizerItem';\nexport {Virtualizer} from './Virtualizer';\nexport {useVirtualizerItem} from './useVirtualizerItem';\nexport {VirtualizerItem, layoutInfoToStyle} from './VirtualizerItem';\nexport {ScrollView, useScrollView} from './ScrollView';\nexport {getRTLOffsetType, getScrollLeft, setScrollLeft} from './utils';\n"],"names":[],"version":3,"file":"types.d.ts.map"}
1
+ {"mappings":";;;AAcA,4BACI,UAAU,GACV,qBAAqB,GACrB,oBAAoB,CAAC;AAezB,iCAAiC,WAAW,GAAE,OAAe,GAAG,aAAa,CAmC5E;AAED,8BAA8B,IAAI,EAAE,OAAO,EAAE,SAAS,EAAE,SAAS,GAAG,MAAM,CAkBzE;AAED,8BAA8B,IAAI,EAAE,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,GAAG,IAAI,CAiB3F;ACzFD;IACE,cAAc,CAAC,GAAG,EAAE,GAAG,EAAE,IAAI,EAAE,IAAI,GAAG,IAAI,CAAA;CAC3C;AAED;IACE,UAAU,EAAE,UAAU,GAAG,IAAI,CAAC;IAC9B,WAAW,EAAE,YAAY,CAAC;IAC1B,GAAG,EAAE,UAAU,WAAW,GAAG,IAAI,CAAC,CAAA;CACnC;AAED,mCAAmC,OAAO,EAAE,sBAAsB,GAAG;IAAC,UAAU,EAAE,MAAM,IAAI,CAAA;CAAC,CAkB5F;ACfD,yBAA0B,SAAQ,eAAe,WAAW,CAAC;IAC3D,WAAW,EAAE,IAAI,CAAC;IAClB,mBAAmB,EAAE,CAAC,IAAI,EAAE,IAAI,KAAK,IAAI,CAAC;IAC1C,QAAQ,CAAC,EAAE,SAAS,CAAC;IACrB,UAAU,CAAC,EAAE,aAAa,CAAC;IAC3B,aAAa,CAAC,EAAE,MAAM,IAAI,CAAC;IAC3B,WAAW,CAAC,EAAE,MAAM,IAAI,CAAC;IACzB,eAAe,CAAC,EAAE,Y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,WAAW,CAAC,EAAE,UAAU,CAAC;IACtG,QAAQ,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,CAAC,KAAK,CAAC,CAAC;IAC1C,aAAa,CAAC,EAAE,cAAc,CAAC,EAAE,CAAC,CAAC,CAAC;IACpC,MAAM,EAAE,OAAO,CAAC,EAAE,CAAC,CAAC,CAAC;IACrB,UAAU,EAAE,WAAW,CAAC,CAAC,CAAC;IAC1B,aAAa,CAAC,EAAE,GAAG,CAAC,GAAG,CAAC,GAAG,IAAI,CAAC;IAChC,eAAe,CAAC,EAAE,YAAY,GAAG,UAAU,GAAG,MAAM,CAAC;IACrD,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,UAAU,CAAC,EAAE,MAAM,IAAI,CAAC;IACxB,aAAa,CAAC,EAAE,CAAC,CAAA;CAClB;AAID,OAAO,MAAM,aA8CP,CAAC,CAAC,SAAS,MAAM,EAAE,CAAC,EAAE,CAAC,EAAE,KAAK,EAAE,iBAAiB,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,GAAG;IAAC,GAAG,CAAC,EAAE,UAAU,cAAc,GAAG,IAAI,CAAC,CAAA;CAAC,KAAK,YAAY,CAAC","sources":["packages/@react-aria/virtualizer/src/packages/@react-aria/virtualizer/src/utils.ts","packages/@react-aria/virtualizer/src/packages/@react-aria/virtualizer/src/useVirtualizerItem.ts","packages/@react-aria/virtualizer/src/packages/@react-aria/virtualizer/src/ScrollView.tsx","packages/@react-aria/virtualizer/src/packages/@react-aria/virtualizer/src/VirtualizerItem.tsx","packages/@react-aria/virtualizer/src/packages/@react-aria/virtualizer/src/Virtualizer.tsx","packages/@react-aria/virtualizer/src/packages/@react-aria/virtualizer/src/index.ts","packages/@react-aria/virtualizer/src/index.ts"],"sourcesContent":[null,null,null,null,null,null,"/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nexport type {RTLOffsetType} from './utils';\nexport type {VirtualizerItemOptions} from './useVirtualizerItem';\nexport {Virtualizer} from './Virtualizer';\nexport {useVirtualizerItem} from './useVirtualizerItem';\nexport {VirtualizerItem, layoutInfoToStyle} from './VirtualizerItem';\nexport {ScrollView, useScrollView} from './ScrollView';\nexport {getRTLOffsetType, getScrollLeft, setScrollLeft} from './utils';\n"],"names":[],"version":3,"file":"types.d.ts.map"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@react-aria/virtualizer",
3
- "version": "4.1.9",
3
+ "version": "4.1.11",
4
4
  "description": "Spectrum UI components in React",
5
5
  "license": "Apache-2.0",
6
6
  "main": "dist/main.js",
@@ -26,11 +26,11 @@
26
26
  "url": "https://github.com/adobe/react-spectrum"
27
27
  },
28
28
  "dependencies": {
29
- "@react-aria/i18n": "^3.12.12",
30
- "@react-aria/interactions": "^3.25.5",
31
- "@react-aria/utils": "^3.30.1",
32
- "@react-stately/virtualizer": "^4.4.3",
33
- "@react-types/shared": "^3.32.0",
29
+ "@react-aria/i18n": "^3.12.14",
30
+ "@react-aria/interactions": "^3.26.0",
31
+ "@react-aria/utils": "^3.32.0",
32
+ "@react-stately/virtualizer": "^4.4.4",
33
+ "@react-types/shared": "^3.32.1",
34
34
  "@swc/helpers": "^0.5.0"
35
35
  },
36
36
  "peerDependencies": {
@@ -40,5 +40,5 @@
40
40
  "publishConfig": {
41
41
  "access": "public"
42
42
  },
43
- "gitHead": "2c58ed3ddd9be9100af9b1d0cfd137fcdc95ba2d"
43
+ "gitHead": "4d838da5bfe36abb35aed166995a9ef63825370f"
44
44
  }
@@ -86,15 +86,6 @@ export function useScrollView(props: ScrollViewProps, ref: RefObject<HTMLElement
86
86
 
87
87
  let [isScrolling, setScrolling] = useState(false);
88
88
 
89
- let onScrollTimeout = useCallback(() => {
90
- state.isScrolling = false;
91
- setScrolling(false);
92
- state.scrollTimeout = null;
93
-
94
- window.dispatchEvent(new Event('tk.connect-observer'));
95
- onScrollEnd?.();
96
- }, [state, onScrollEnd]);
97
-
98
89
  let onScroll = useCallback((e) => {
99
90
  if (e.target !== e.currentTarget) {
100
91
  return;
@@ -128,21 +119,29 @@ export function useScrollView(props: ScrollViewProps, ref: RefObject<HTMLElement
128
119
  // keep track of the current timeout time and only reschedule
129
120
  // the timer when it is getting close.
130
121
  let now = Date.now();
131
- if (!('onscrollend' in window) && state.scrollEndTime <= now + 50) {
122
+ if (state.scrollEndTime <= now + 50) {
132
123
  state.scrollEndTime = now + 300;
133
124
 
134
125
  if (state.scrollTimeout != null) {
135
126
  clearTimeout(state.scrollTimeout);
136
127
  }
137
128
 
138
- state.scrollTimeout = setTimeout(onScrollTimeout, 300);
129
+ state.scrollTimeout = setTimeout(() => {
130
+ state.isScrolling = false;
131
+ setScrolling(false);
132
+ state.scrollTimeout = null;
133
+
134
+ window.dispatchEvent(new Event('tk.connect-observer'));
135
+ if (onScrollEnd) {
136
+ onScrollEnd();
137
+ }
138
+ }, 300);
139
139
  }
140
140
  });
141
- }, [props, direction, state, contentSize, onVisibleRectChange, onScrollStart, onScrollTimeout]);
141
+ }, [props, direction, state, contentSize, onVisibleRectChange, onScrollStart, onScrollEnd]);
142
142
 
143
143
  // Attach event directly to ref so RAC Virtualizer doesn't need to send props upward.
144
144
  useEvent(ref, 'scroll', onScroll);
145
- useEvent(ref, 'scrollend', onScrollTimeout);
146
145
 
147
146
  useEffect(() => {
148
147
  return () => {
@@ -158,7 +157,7 @@ export function useScrollView(props: ScrollViewProps, ref: RefObject<HTMLElement
158
157
  }, []);
159
158
 
160
159
  let isUpdatingSize = useRef(false);
161
- let updateSize = useEffectEvent((flush: typeof flushSync) => {
160
+ let updateSize = useCallback((flush: typeof flushSync) => {
162
161
  let dom = ref.current;
163
162
  if (!dom || isUpdatingSize.current) {
164
163
  return;
@@ -198,11 +197,14 @@ export function useScrollView(props: ScrollViewProps, ref: RefObject<HTMLElement
198
197
  }
199
198
 
200
199
  isUpdatingSize.current = false;
201
- });
200
+ }, [ref, state, onVisibleRectChange]);
201
+ let updateSizeEvent = useEffectEvent(updateSize);
202
202
 
203
203
  // Update visible rect when the content size changes, in case scrollbars need to appear or disappear.
204
204
  let lastContentSize = useRef<Size | null>(null);
205
205
  let [update, setUpdate] = useState({});
206
+ // We only contain a call to setState in here for testing environments.
207
+ // eslint-disable-next-line react-hooks/exhaustive-deps
206
208
  useLayoutEffect(() => {
207
209
  if (!isUpdatingSize.current && (lastContentSize.current == null || !contentSize.equals(lastContentSize.current))) {
208
210
  // React doesn't allow flushSync inside effects, so queue a microtask.
@@ -219,7 +221,7 @@ export function useScrollView(props: ScrollViewProps, ref: RefObject<HTMLElement
219
221
  lastContentSize.current = contentSize;
220
222
  return;
221
223
  } else {
222
- queueMicrotask(() => updateSize(flushSync));
224
+ queueMicrotask(() => updateSizeEvent(flushSync));
223
225
  }
224
226
  }
225
227
 
@@ -228,7 +230,7 @@ export function useScrollView(props: ScrollViewProps, ref: RefObject<HTMLElement
228
230
 
229
231
  // Will only run in tests, needs to be in separate effect so it is properly run in the next render in strict mode.
230
232
  useLayoutEffect(() => {
231
- updateSize(fn => fn());
233
+ updateSizeEvent(fn => fn());
232
234
  }, [update]);
233
235
 
234
236
  let onResize = useCallback(() => {