@react-aria/virtualizer 3.0.0-nightly-641446f65-240905

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (40) hide show
  1. package/README.md +3 -0
  2. package/dist/ScrollView.main.js +214 -0
  3. package/dist/ScrollView.main.js.map +1 -0
  4. package/dist/ScrollView.mjs +204 -0
  5. package/dist/ScrollView.module.js +204 -0
  6. package/dist/ScrollView.module.js.map +1 -0
  7. package/dist/Virtualizer.main.js +88 -0
  8. package/dist/Virtualizer.main.js.map +1 -0
  9. package/dist/Virtualizer.mjs +79 -0
  10. package/dist/Virtualizer.module.js +79 -0
  11. package/dist/Virtualizer.module.js.map +1 -0
  12. package/dist/VirtualizerItem.main.js +82 -0
  13. package/dist/VirtualizerItem.main.js.map +1 -0
  14. package/dist/VirtualizerItem.mjs +72 -0
  15. package/dist/VirtualizerItem.module.js +72 -0
  16. package/dist/VirtualizerItem.module.js.map +1 -0
  17. package/dist/import.mjs +25 -0
  18. package/dist/main.js +38 -0
  19. package/dist/main.js.map +1 -0
  20. package/dist/module.js +25 -0
  21. package/dist/module.js.map +1 -0
  22. package/dist/types.d.ts +337 -0
  23. package/dist/types.d.ts.map +1 -0
  24. package/dist/useVirtualizerItem.main.js +53 -0
  25. package/dist/useVirtualizerItem.main.js.map +1 -0
  26. package/dist/useVirtualizerItem.mjs +48 -0
  27. package/dist/useVirtualizerItem.module.js +48 -0
  28. package/dist/useVirtualizerItem.module.js.map +1 -0
  29. package/dist/utils.main.js +80 -0
  30. package/dist/utils.main.js.map +1 -0
  31. package/dist/utils.mjs +73 -0
  32. package/dist/utils.module.js +73 -0
  33. package/dist/utils.module.js.map +1 -0
  34. package/package.json +40 -0
  35. package/src/ScrollView.tsx +246 -0
  36. package/src/Virtualizer.tsx +117 -0
  37. package/src/VirtualizerItem.tsx +87 -0
  38. package/src/index.ts +19 -0
  39. package/src/useVirtualizerItem.ts +54 -0
  40. package/src/utils.ts +107 -0
package/README.md ADDED
@@ -0,0 +1,3 @@
1
+ # @react-aria/virtualizer
2
+
3
+ This package is part of [react-spectrum](https://github.com/adobe/react-spectrum). See the repo for more details.
@@ -0,0 +1,214 @@
1
+ var $efdd61e59e023a1d$exports = require("./utils.main.js");
2
+ var $kvIfm$reactdom = require("react-dom");
3
+ var $kvIfm$react = require("react");
4
+ var $kvIfm$reactstatelyvirtualizer = require("@react-stately/virtualizer");
5
+ var $kvIfm$reactariautils = require("@react-aria/utils");
6
+ var $kvIfm$reactariai18n = require("@react-aria/i18n");
7
+
8
+
9
+ function $parcel$interopDefault(a) {
10
+ return a && a.__esModule ? a.default : a;
11
+ }
12
+
13
+ function $parcel$export(e, n, v, s) {
14
+ Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
15
+ }
16
+
17
+ $parcel$export(module.exports, "useScrollView", () => $00ca8c0b29e3e07c$export$2ea0c4974da4731b);
18
+ $parcel$export(module.exports, "ScrollView", () => $00ca8c0b29e3e07c$export$5665e3d6be6adea);
19
+ /*
20
+ * Copyright 2020 Adobe. All rights reserved.
21
+ * This file is licensed to you under the Apache License, Version 2.0 (the "License");
22
+ * you may not use this file except in compliance with the License. You may obtain a copy
23
+ * of the License at http://www.apache.org/licenses/LICENSE-2.0
24
+ *
25
+ * Unless required by applicable law or agreed to in writing, software distributed under
26
+ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
27
+ * OF ANY KIND, either express or implied. See the License for the specific language
28
+ * governing permissions and limitations under the License.
29
+ */ // @ts-ignore
30
+
31
+
32
+
33
+
34
+
35
+
36
+ function $00ca8c0b29e3e07c$var$ScrollView(props, ref) {
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, onScrollStart: onScrollStart, onScrollEnd: onScrollEnd, scrollDirection: scrollDirection = 'both', ...otherProps } = props;
51
+ let state = (0, $kvIfm$react.useRef)({
52
+ scrollTop: 0,
53
+ scrollLeft: 0,
54
+ scrollEndTime: 0,
55
+ scrollTimeout: null,
56
+ width: 0,
57
+ height: 0,
58
+ isScrolling: false
59
+ }).current;
60
+ let { direction: direction } = (0, $kvIfm$reactariai18n.useLocale)();
61
+ let [isScrolling, setScrolling] = (0, $kvIfm$react.useState)(false);
62
+ let onScroll = (0, $kvIfm$react.useCallback)((e)=>{
63
+ if (e.target !== e.currentTarget) return;
64
+ if (props.onScroll) props.onScroll(e);
65
+ (0, $kvIfm$reactdom.flushSync)(()=>{
66
+ let scrollTop = e.currentTarget.scrollTop;
67
+ let scrollLeft = (0, $efdd61e59e023a1d$exports.getScrollLeft)(e.currentTarget, direction);
68
+ // Prevent rubber band scrolling from shaking when scrolling out of bounds
69
+ state.scrollTop = Math.max(0, Math.min(scrollTop, contentSize.height - state.height));
70
+ state.scrollLeft = Math.max(0, Math.min(scrollLeft, contentSize.width - state.width));
71
+ onVisibleRectChange(new (0, $kvIfm$reactstatelyvirtualizer.Rect)(state.scrollLeft, state.scrollTop, state.width, state.height));
72
+ if (!state.isScrolling) {
73
+ state.isScrolling = true;
74
+ setScrolling(true);
75
+ // Pause typekit MutationObserver during scrolling.
76
+ window.dispatchEvent(new Event('tk.disconnect-observer'));
77
+ if (onScrollStart) onScrollStart();
78
+ }
79
+ // So we don't constantly call clearTimeout and setTimeout,
80
+ // keep track of the current timeout time and only reschedule
81
+ // the timer when it is getting close.
82
+ let now = Date.now();
83
+ if (state.scrollEndTime <= now + 50) {
84
+ state.scrollEndTime = now + 300;
85
+ clearTimeout(state.scrollTimeout);
86
+ state.scrollTimeout = setTimeout(()=>{
87
+ state.isScrolling = false;
88
+ setScrolling(false);
89
+ state.scrollTimeout = null;
90
+ window.dispatchEvent(new Event('tk.connect-observer'));
91
+ if (onScrollEnd) onScrollEnd();
92
+ }, 300);
93
+ }
94
+ });
95
+ }, [
96
+ props,
97
+ direction,
98
+ state,
99
+ contentSize,
100
+ onVisibleRectChange,
101
+ onScrollStart,
102
+ onScrollEnd
103
+ ]);
104
+ // Attach event directly to ref so RAC Virtualizer doesn't need to send props upward.
105
+ (0, $kvIfm$reactariautils.useEvent)(ref, 'scroll', onScroll);
106
+ // eslint-disable-next-line arrow-body-style
107
+ (0, $kvIfm$react.useEffect)(()=>{
108
+ return ()=>{
109
+ clearTimeout(state.scrollTimeout);
110
+ if (state.isScrolling) window.dispatchEvent(new Event('tk.connect-observer'));
111
+ };
112
+ // eslint-disable-next-line react-hooks/exhaustive-deps
113
+ }, []);
114
+ let updateSize = (0, $kvIfm$reactariautils.useEffectEvent)((flush)=>{
115
+ let dom = ref.current;
116
+ if (!dom) return;
117
+ let isTestEnv = false;
118
+ let isClientWidthMocked = Object.getOwnPropertyNames(window.HTMLElement.prototype).includes('clientWidth');
119
+ let isClientHeightMocked = Object.getOwnPropertyNames(window.HTMLElement.prototype).includes('clientHeight');
120
+ let clientWidth = dom.clientWidth;
121
+ let clientHeight = dom.clientHeight;
122
+ let w = isTestEnv && !isClientWidthMocked ? Infinity : clientWidth;
123
+ let h = isTestEnv && !isClientHeightMocked ? Infinity : clientHeight;
124
+ if (state.width !== w || state.height !== h) {
125
+ state.width = w;
126
+ state.height = h;
127
+ flush(()=>{
128
+ onVisibleRectChange(new (0, $kvIfm$reactstatelyvirtualizer.Rect)(state.scrollLeft, state.scrollTop, w, h));
129
+ });
130
+ // If the clientWidth or clientHeight changed, scrollbars appeared or disappeared as
131
+ // a result of the layout update. In this case, re-layout again to account for the
132
+ // adjusted space. In very specific cases this might result in the scrollbars disappearing
133
+ // again, resulting in extra padding. We stop after a maximum of two layout passes to avoid
134
+ // an infinite loop. This matches how browsers behavior with native CSS grid layout.
135
+ if (!isTestEnv && clientWidth !== dom.clientWidth || clientHeight !== dom.clientHeight) {
136
+ state.width = dom.clientWidth;
137
+ state.height = dom.clientHeight;
138
+ flush(()=>{
139
+ onVisibleRectChange(new (0, $kvIfm$reactstatelyvirtualizer.Rect)(state.scrollLeft, state.scrollTop, state.width, state.height));
140
+ });
141
+ }
142
+ }
143
+ });
144
+ let didUpdateSize = (0, $kvIfm$react.useRef)(false);
145
+ (0, $kvIfm$reactariautils.useLayoutEffect)(()=>{
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
+ }
164
+ }, [
165
+ updateSize
166
+ ]);
167
+ let onResize = (0, $kvIfm$react.useCallback)(()=>{
168
+ updateSize((0, $kvIfm$reactdom.flushSync));
169
+ }, [
170
+ updateSize
171
+ ]);
172
+ // Watch border-box instead of of content-box so that we don't go into
173
+ // an infinite loop when scrollbars appear or disappear.
174
+ (0, $kvIfm$reactariautils.useResizeObserver)({
175
+ ref: ref,
176
+ box: 'border-box',
177
+ onResize: onResize
178
+ });
179
+ let style = {
180
+ // Reset padding so that relative positioning works correctly. Padding will be done in JS layout.
181
+ padding: 0,
182
+ ...otherProps.style
183
+ };
184
+ if (scrollDirection === 'horizontal') {
185
+ style.overflowX = 'auto';
186
+ style.overflowY = 'hidden';
187
+ } else if (scrollDirection === 'vertical' || contentSize.width === state.width) {
188
+ // Set overflow-x: hidden if content size is equal to the width of the scroll view.
189
+ // This prevents horizontal scrollbars from flickering during resizing due to resize observer
190
+ // firing slower than the frame rate, which may cause an infinite re-render loop.
191
+ style.overflowY = 'auto';
192
+ style.overflowX = 'hidden';
193
+ } else style.overflow = 'auto';
194
+ innerStyle = {
195
+ width: Number.isFinite(contentSize.width) ? contentSize.width : undefined,
196
+ height: Number.isFinite(contentSize.height) ? contentSize.height : undefined,
197
+ pointerEvents: isScrolling ? 'none' : 'auto',
198
+ position: 'relative',
199
+ ...innerStyle
200
+ };
201
+ return {
202
+ scrollViewProps: {
203
+ ...otherProps,
204
+ style: style
205
+ },
206
+ contentProps: {
207
+ role: 'presentation',
208
+ style: innerStyle
209
+ }
210
+ };
211
+ }
212
+
213
+
214
+ //# sourceMappingURL=ScrollView.main.js.map
@@ -0,0 +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;QAAI,MAAK;QAAgB,GAAG,YAAY;OACtC,MAAM,QAAQ;AAIvB;AAEA,MAAM,yDAAuB,CAAA,GAAA,sCAAI,EAAE,UAAU,CAAC;AAGvC,SAAS,0CAAc,KAAsB,EAAE,GAAkC;IACtF,IAAI,eACF,WAAW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F,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,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 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 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 // 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 clearTimeout(state.scrollTimeout);\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 // eslint-disable-next-line arrow-body-style\n useEffect(() => {\n return () => {\n clearTimeout(state.scrollTimeout);\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 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 (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 role: 'presentation',\n style: innerStyle\n }\n };\n}\n"],"names":[],"version":3,"file":"ScrollView.main.js.map"}
@@ -0,0 +1,204 @@
1
+ import {getScrollLeft as $ce415dc67314b753$export$1389d168952b34b5} from "./utils.mjs";
2
+ import {flushSync as $f9kpT$flushSync} from "react-dom";
3
+ import $f9kpT$react, {useRef as $f9kpT$useRef, useState as $f9kpT$useState, useCallback as $f9kpT$useCallback, useEffect as $f9kpT$useEffect} from "react";
4
+ import {Rect as $f9kpT$Rect} from "@react-stately/virtualizer";
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
+ import {useLocale as $f9kpT$useLocale} from "@react-aria/i18n";
7
+
8
+ /*
9
+ * Copyright 2020 Adobe. All rights reserved.
10
+ * This file is licensed to you under the Apache License, Version 2.0 (the "License");
11
+ * you may not use this file except in compliance with the License. You may obtain a copy
12
+ * of the License at http://www.apache.org/licenses/LICENSE-2.0
13
+ *
14
+ * Unless required by applicable law or agreed to in writing, software distributed under
15
+ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
16
+ * OF ANY KIND, either express or implied. See the License for the specific language
17
+ * governing permissions and limitations under the License.
18
+ */ // @ts-ignore
19
+
20
+
21
+
22
+
23
+
24
+
25
+ function $44a6ee657928b002$var$ScrollView(props, ref) {
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, onScrollStart: onScrollStart, onScrollEnd: onScrollEnd, scrollDirection: scrollDirection = 'both', ...otherProps } = props;
40
+ let state = (0, $f9kpT$useRef)({
41
+ scrollTop: 0,
42
+ scrollLeft: 0,
43
+ scrollEndTime: 0,
44
+ scrollTimeout: null,
45
+ width: 0,
46
+ height: 0,
47
+ isScrolling: false
48
+ }).current;
49
+ let { direction: direction } = (0, $f9kpT$useLocale)();
50
+ let [isScrolling, setScrolling] = (0, $f9kpT$useState)(false);
51
+ let onScroll = (0, $f9kpT$useCallback)((e)=>{
52
+ if (e.target !== e.currentTarget) return;
53
+ if (props.onScroll) props.onScroll(e);
54
+ (0, $f9kpT$flushSync)(()=>{
55
+ let scrollTop = e.currentTarget.scrollTop;
56
+ let scrollLeft = (0, $ce415dc67314b753$export$1389d168952b34b5)(e.currentTarget, direction);
57
+ // Prevent rubber band scrolling from shaking when scrolling out of bounds
58
+ state.scrollTop = Math.max(0, Math.min(scrollTop, contentSize.height - state.height));
59
+ state.scrollLeft = Math.max(0, Math.min(scrollLeft, contentSize.width - state.width));
60
+ onVisibleRectChange(new (0, $f9kpT$Rect)(state.scrollLeft, state.scrollTop, state.width, state.height));
61
+ if (!state.isScrolling) {
62
+ state.isScrolling = true;
63
+ setScrolling(true);
64
+ // Pause typekit MutationObserver during scrolling.
65
+ window.dispatchEvent(new Event('tk.disconnect-observer'));
66
+ if (onScrollStart) onScrollStart();
67
+ }
68
+ // So we don't constantly call clearTimeout and setTimeout,
69
+ // keep track of the current timeout time and only reschedule
70
+ // the timer when it is getting close.
71
+ let now = Date.now();
72
+ if (state.scrollEndTime <= now + 50) {
73
+ state.scrollEndTime = now + 300;
74
+ clearTimeout(state.scrollTimeout);
75
+ state.scrollTimeout = setTimeout(()=>{
76
+ state.isScrolling = false;
77
+ setScrolling(false);
78
+ state.scrollTimeout = null;
79
+ window.dispatchEvent(new Event('tk.connect-observer'));
80
+ if (onScrollEnd) onScrollEnd();
81
+ }, 300);
82
+ }
83
+ });
84
+ }, [
85
+ props,
86
+ direction,
87
+ state,
88
+ contentSize,
89
+ onVisibleRectChange,
90
+ onScrollStart,
91
+ onScrollEnd
92
+ ]);
93
+ // Attach event directly to ref so RAC Virtualizer doesn't need to send props upward.
94
+ (0, $f9kpT$useEvent)(ref, 'scroll', onScroll);
95
+ // eslint-disable-next-line arrow-body-style
96
+ (0, $f9kpT$useEffect)(()=>{
97
+ return ()=>{
98
+ clearTimeout(state.scrollTimeout);
99
+ if (state.isScrolling) window.dispatchEvent(new Event('tk.connect-observer'));
100
+ };
101
+ // eslint-disable-next-line react-hooks/exhaustive-deps
102
+ }, []);
103
+ let updateSize = (0, $f9kpT$useEffectEvent)((flush)=>{
104
+ let dom = ref.current;
105
+ if (!dom) return;
106
+ let isTestEnv = false;
107
+ let isClientWidthMocked = Object.getOwnPropertyNames(window.HTMLElement.prototype).includes('clientWidth');
108
+ let isClientHeightMocked = Object.getOwnPropertyNames(window.HTMLElement.prototype).includes('clientHeight');
109
+ let clientWidth = dom.clientWidth;
110
+ let clientHeight = dom.clientHeight;
111
+ let w = isTestEnv && !isClientWidthMocked ? Infinity : clientWidth;
112
+ let h = isTestEnv && !isClientHeightMocked ? Infinity : clientHeight;
113
+ if (state.width !== w || state.height !== h) {
114
+ state.width = w;
115
+ state.height = h;
116
+ flush(()=>{
117
+ onVisibleRectChange(new (0, $f9kpT$Rect)(state.scrollLeft, state.scrollTop, w, h));
118
+ });
119
+ // If the clientWidth or clientHeight changed, scrollbars appeared or disappeared as
120
+ // a result of the layout update. In this case, re-layout again to account for the
121
+ // adjusted space. In very specific cases this might result in the scrollbars disappearing
122
+ // again, resulting in extra padding. We stop after a maximum of two layout passes to avoid
123
+ // an infinite loop. This matches how browsers behavior with native CSS grid layout.
124
+ if (!isTestEnv && clientWidth !== dom.clientWidth || clientHeight !== dom.clientHeight) {
125
+ state.width = dom.clientWidth;
126
+ state.height = dom.clientHeight;
127
+ flush(()=>{
128
+ onVisibleRectChange(new (0, $f9kpT$Rect)(state.scrollLeft, state.scrollTop, state.width, state.height));
129
+ });
130
+ }
131
+ }
132
+ });
133
+ let didUpdateSize = (0, $f9kpT$useRef)(false);
134
+ (0, $f9kpT$useLayoutEffect)(()=>{
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
+ }
153
+ }, [
154
+ updateSize
155
+ ]);
156
+ let onResize = (0, $f9kpT$useCallback)(()=>{
157
+ updateSize((0, $f9kpT$flushSync));
158
+ }, [
159
+ updateSize
160
+ ]);
161
+ // Watch border-box instead of of content-box so that we don't go into
162
+ // an infinite loop when scrollbars appear or disappear.
163
+ (0, $f9kpT$useResizeObserver)({
164
+ ref: ref,
165
+ box: 'border-box',
166
+ onResize: onResize
167
+ });
168
+ let style = {
169
+ // Reset padding so that relative positioning works correctly. Padding will be done in JS layout.
170
+ padding: 0,
171
+ ...otherProps.style
172
+ };
173
+ if (scrollDirection === 'horizontal') {
174
+ style.overflowX = 'auto';
175
+ style.overflowY = 'hidden';
176
+ } else if (scrollDirection === 'vertical' || contentSize.width === state.width) {
177
+ // Set overflow-x: hidden if content size is equal to the width of the scroll view.
178
+ // This prevents horizontal scrollbars from flickering during resizing due to resize observer
179
+ // firing slower than the frame rate, which may cause an infinite re-render loop.
180
+ style.overflowY = 'auto';
181
+ style.overflowX = 'hidden';
182
+ } else style.overflow = 'auto';
183
+ innerStyle = {
184
+ width: Number.isFinite(contentSize.width) ? contentSize.width : undefined,
185
+ height: Number.isFinite(contentSize.height) ? contentSize.height : undefined,
186
+ pointerEvents: isScrolling ? 'none' : 'auto',
187
+ position: 'relative',
188
+ ...innerStyle
189
+ };
190
+ return {
191
+ scrollViewProps: {
192
+ ...otherProps,
193
+ style: style
194
+ },
195
+ contentProps: {
196
+ role: 'presentation',
197
+ style: innerStyle
198
+ }
199
+ };
200
+ }
201
+
202
+
203
+ export {$44a6ee657928b002$export$2ea0c4974da4731b as useScrollView, $44a6ee657928b002$export$5665e3d6be6adea as ScrollView};
204
+ //# sourceMappingURL=ScrollView.module.js.map
@@ -0,0 +1,204 @@
1
+ import {getScrollLeft as $ce415dc67314b753$export$1389d168952b34b5} from "./utils.module.js";
2
+ import {flushSync as $f9kpT$flushSync} from "react-dom";
3
+ import $f9kpT$react, {useRef as $f9kpT$useRef, useState as $f9kpT$useState, useCallback as $f9kpT$useCallback, useEffect as $f9kpT$useEffect} from "react";
4
+ import {Rect as $f9kpT$Rect} from "@react-stately/virtualizer";
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
+ import {useLocale as $f9kpT$useLocale} from "@react-aria/i18n";
7
+
8
+ /*
9
+ * Copyright 2020 Adobe. All rights reserved.
10
+ * This file is licensed to you under the Apache License, Version 2.0 (the "License");
11
+ * you may not use this file except in compliance with the License. You may obtain a copy
12
+ * of the License at http://www.apache.org/licenses/LICENSE-2.0
13
+ *
14
+ * Unless required by applicable law or agreed to in writing, software distributed under
15
+ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
16
+ * OF ANY KIND, either express or implied. See the License for the specific language
17
+ * governing permissions and limitations under the License.
18
+ */ // @ts-ignore
19
+
20
+
21
+
22
+
23
+
24
+
25
+ function $44a6ee657928b002$var$ScrollView(props, ref) {
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, onScrollStart: onScrollStart, onScrollEnd: onScrollEnd, scrollDirection: scrollDirection = 'both', ...otherProps } = props;
40
+ let state = (0, $f9kpT$useRef)({
41
+ scrollTop: 0,
42
+ scrollLeft: 0,
43
+ scrollEndTime: 0,
44
+ scrollTimeout: null,
45
+ width: 0,
46
+ height: 0,
47
+ isScrolling: false
48
+ }).current;
49
+ let { direction: direction } = (0, $f9kpT$useLocale)();
50
+ let [isScrolling, setScrolling] = (0, $f9kpT$useState)(false);
51
+ let onScroll = (0, $f9kpT$useCallback)((e)=>{
52
+ if (e.target !== e.currentTarget) return;
53
+ if (props.onScroll) props.onScroll(e);
54
+ (0, $f9kpT$flushSync)(()=>{
55
+ let scrollTop = e.currentTarget.scrollTop;
56
+ let scrollLeft = (0, $ce415dc67314b753$export$1389d168952b34b5)(e.currentTarget, direction);
57
+ // Prevent rubber band scrolling from shaking when scrolling out of bounds
58
+ state.scrollTop = Math.max(0, Math.min(scrollTop, contentSize.height - state.height));
59
+ state.scrollLeft = Math.max(0, Math.min(scrollLeft, contentSize.width - state.width));
60
+ onVisibleRectChange(new (0, $f9kpT$Rect)(state.scrollLeft, state.scrollTop, state.width, state.height));
61
+ if (!state.isScrolling) {
62
+ state.isScrolling = true;
63
+ setScrolling(true);
64
+ // Pause typekit MutationObserver during scrolling.
65
+ window.dispatchEvent(new Event('tk.disconnect-observer'));
66
+ if (onScrollStart) onScrollStart();
67
+ }
68
+ // So we don't constantly call clearTimeout and setTimeout,
69
+ // keep track of the current timeout time and only reschedule
70
+ // the timer when it is getting close.
71
+ let now = Date.now();
72
+ if (state.scrollEndTime <= now + 50) {
73
+ state.scrollEndTime = now + 300;
74
+ clearTimeout(state.scrollTimeout);
75
+ state.scrollTimeout = setTimeout(()=>{
76
+ state.isScrolling = false;
77
+ setScrolling(false);
78
+ state.scrollTimeout = null;
79
+ window.dispatchEvent(new Event('tk.connect-observer'));
80
+ if (onScrollEnd) onScrollEnd();
81
+ }, 300);
82
+ }
83
+ });
84
+ }, [
85
+ props,
86
+ direction,
87
+ state,
88
+ contentSize,
89
+ onVisibleRectChange,
90
+ onScrollStart,
91
+ onScrollEnd
92
+ ]);
93
+ // Attach event directly to ref so RAC Virtualizer doesn't need to send props upward.
94
+ (0, $f9kpT$useEvent)(ref, 'scroll', onScroll);
95
+ // eslint-disable-next-line arrow-body-style
96
+ (0, $f9kpT$useEffect)(()=>{
97
+ return ()=>{
98
+ clearTimeout(state.scrollTimeout);
99
+ if (state.isScrolling) window.dispatchEvent(new Event('tk.connect-observer'));
100
+ };
101
+ // eslint-disable-next-line react-hooks/exhaustive-deps
102
+ }, []);
103
+ let updateSize = (0, $f9kpT$useEffectEvent)((flush)=>{
104
+ let dom = ref.current;
105
+ if (!dom) return;
106
+ let isTestEnv = false;
107
+ let isClientWidthMocked = Object.getOwnPropertyNames(window.HTMLElement.prototype).includes('clientWidth');
108
+ let isClientHeightMocked = Object.getOwnPropertyNames(window.HTMLElement.prototype).includes('clientHeight');
109
+ let clientWidth = dom.clientWidth;
110
+ let clientHeight = dom.clientHeight;
111
+ let w = isTestEnv && !isClientWidthMocked ? Infinity : clientWidth;
112
+ let h = isTestEnv && !isClientHeightMocked ? Infinity : clientHeight;
113
+ if (state.width !== w || state.height !== h) {
114
+ state.width = w;
115
+ state.height = h;
116
+ flush(()=>{
117
+ onVisibleRectChange(new (0, $f9kpT$Rect)(state.scrollLeft, state.scrollTop, w, h));
118
+ });
119
+ // If the clientWidth or clientHeight changed, scrollbars appeared or disappeared as
120
+ // a result of the layout update. In this case, re-layout again to account for the
121
+ // adjusted space. In very specific cases this might result in the scrollbars disappearing
122
+ // again, resulting in extra padding. We stop after a maximum of two layout passes to avoid
123
+ // an infinite loop. This matches how browsers behavior with native CSS grid layout.
124
+ if (!isTestEnv && clientWidth !== dom.clientWidth || clientHeight !== dom.clientHeight) {
125
+ state.width = dom.clientWidth;
126
+ state.height = dom.clientHeight;
127
+ flush(()=>{
128
+ onVisibleRectChange(new (0, $f9kpT$Rect)(state.scrollLeft, state.scrollTop, state.width, state.height));
129
+ });
130
+ }
131
+ }
132
+ });
133
+ let didUpdateSize = (0, $f9kpT$useRef)(false);
134
+ (0, $f9kpT$useLayoutEffect)(()=>{
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
+ }
153
+ }, [
154
+ updateSize
155
+ ]);
156
+ let onResize = (0, $f9kpT$useCallback)(()=>{
157
+ updateSize((0, $f9kpT$flushSync));
158
+ }, [
159
+ updateSize
160
+ ]);
161
+ // Watch border-box instead of of content-box so that we don't go into
162
+ // an infinite loop when scrollbars appear or disappear.
163
+ (0, $f9kpT$useResizeObserver)({
164
+ ref: ref,
165
+ box: 'border-box',
166
+ onResize: onResize
167
+ });
168
+ let style = {
169
+ // Reset padding so that relative positioning works correctly. Padding will be done in JS layout.
170
+ padding: 0,
171
+ ...otherProps.style
172
+ };
173
+ if (scrollDirection === 'horizontal') {
174
+ style.overflowX = 'auto';
175
+ style.overflowY = 'hidden';
176
+ } else if (scrollDirection === 'vertical' || contentSize.width === state.width) {
177
+ // Set overflow-x: hidden if content size is equal to the width of the scroll view.
178
+ // This prevents horizontal scrollbars from flickering during resizing due to resize observer
179
+ // firing slower than the frame rate, which may cause an infinite re-render loop.
180
+ style.overflowY = 'auto';
181
+ style.overflowX = 'hidden';
182
+ } else style.overflow = 'auto';
183
+ innerStyle = {
184
+ width: Number.isFinite(contentSize.width) ? contentSize.width : undefined,
185
+ height: Number.isFinite(contentSize.height) ? contentSize.height : undefined,
186
+ pointerEvents: isScrolling ? 'none' : 'auto',
187
+ position: 'relative',
188
+ ...innerStyle
189
+ };
190
+ return {
191
+ scrollViewProps: {
192
+ ...otherProps,
193
+ style: style
194
+ },
195
+ contentProps: {
196
+ role: 'presentation',
197
+ style: innerStyle
198
+ }
199
+ };
200
+ }
201
+
202
+
203
+ export {$44a6ee657928b002$export$2ea0c4974da4731b as useScrollView, $44a6ee657928b002$export$5665e3d6be6adea as ScrollView};
204
+ //# sourceMappingURL=ScrollView.module.js.map