@react-aria/virtualizer 3.9.11-nightly.4552 → 3.9.11-nightly.4558
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/ScrollView.main.js +180 -0
- package/dist/ScrollView.main.js.map +1 -0
- package/dist/ScrollView.mjs +171 -0
- package/dist/ScrollView.module.js +171 -0
- package/dist/ScrollView.module.js.map +1 -0
- package/dist/Virtualizer.main.js +210 -0
- package/dist/Virtualizer.main.js.map +1 -0
- package/dist/Virtualizer.mjs +200 -0
- package/dist/Virtualizer.module.js +200 -0
- package/dist/Virtualizer.module.js.map +1 -0
- package/dist/VirtualizerItem.main.js +86 -0
- package/dist/VirtualizerItem.main.js.map +1 -0
- package/dist/VirtualizerItem.mjs +76 -0
- package/dist/VirtualizerItem.module.js +76 -0
- package/dist/VirtualizerItem.module.js.map +1 -0
- package/dist/import.mjs +5 -535
- package/dist/main.js +14 -548
- package/dist/main.js.map +1 -1
- package/dist/module.js +5 -535
- package/dist/module.js.map +1 -1
- package/dist/useVirtualizerItem.main.js +51 -0
- package/dist/useVirtualizerItem.main.js.map +1 -0
- package/dist/useVirtualizerItem.mjs +46 -0
- package/dist/useVirtualizerItem.module.js +46 -0
- package/dist/useVirtualizerItem.module.js.map +1 -0
- package/dist/utils.main.js +80 -0
- package/dist/utils.main.js.map +1 -0
- package/dist/utils.mjs +73 -0
- package/dist/utils.module.js +73 -0
- package/dist/utils.module.js.map +1 -0
- package/package.json +7 -7
package/dist/import.mjs
CHANGED
|
@@ -1,277 +1,8 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import
|
|
5
|
-
import {
|
|
6
|
-
import {useLocale as $kSaV5$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
|
-
*/ /*
|
|
19
|
-
* Copyright 2020 Adobe. All rights reserved.
|
|
20
|
-
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
21
|
-
* you may not use this file except in compliance with the License. You may obtain a copy
|
|
22
|
-
* of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
23
|
-
*
|
|
24
|
-
* Unless required by applicable law or agreed to in writing, software distributed under
|
|
25
|
-
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
26
|
-
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
27
|
-
* governing permissions and limitations under the License.
|
|
28
|
-
*/
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
/*
|
|
33
|
-
* Copyright 2020 Adobe. All rights reserved.
|
|
34
|
-
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
35
|
-
* you may not use this file except in compliance with the License. You may obtain a copy
|
|
36
|
-
* of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
37
|
-
*
|
|
38
|
-
* Unless required by applicable law or agreed to in writing, software distributed under
|
|
39
|
-
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
40
|
-
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
41
|
-
* governing permissions and limitations under the License.
|
|
42
|
-
*/ // @ts-ignore
|
|
43
|
-
|
|
44
|
-
/*
|
|
45
|
-
* Copyright 2020 Adobe. All rights reserved.
|
|
46
|
-
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
47
|
-
* you may not use this file except in compliance with the License. You may obtain a copy
|
|
48
|
-
* of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
49
|
-
*
|
|
50
|
-
* Unless required by applicable law or agreed to in writing, software distributed under
|
|
51
|
-
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
52
|
-
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
53
|
-
* governing permissions and limitations under the License.
|
|
54
|
-
*/ let $ce415dc67314b753$var$cachedRTLResult = null;
|
|
55
|
-
function $ce415dc67314b753$export$faf7630257ad4304(recalculate = false) {
|
|
56
|
-
if ($ce415dc67314b753$var$cachedRTLResult === null || recalculate) {
|
|
57
|
-
const outerDiv = document.createElement("div");
|
|
58
|
-
const outerStyle = outerDiv.style;
|
|
59
|
-
outerStyle.width = "50px";
|
|
60
|
-
outerStyle.height = "50px";
|
|
61
|
-
outerStyle.overflow = "scroll";
|
|
62
|
-
outerStyle.direction = "rtl";
|
|
63
|
-
const innerDiv = document.createElement("div");
|
|
64
|
-
const innerStyle = innerDiv.style;
|
|
65
|
-
innerStyle.width = "100px";
|
|
66
|
-
innerStyle.height = "100px";
|
|
67
|
-
outerDiv.appendChild(innerDiv);
|
|
68
|
-
document.body.appendChild(outerDiv);
|
|
69
|
-
if (outerDiv.scrollLeft > 0) $ce415dc67314b753$var$cachedRTLResult = "positive-descending";
|
|
70
|
-
else {
|
|
71
|
-
outerDiv.scrollLeft = 1;
|
|
72
|
-
if (outerDiv.scrollLeft === 0) $ce415dc67314b753$var$cachedRTLResult = "negative";
|
|
73
|
-
else $ce415dc67314b753$var$cachedRTLResult = "positive-ascending";
|
|
74
|
-
}
|
|
75
|
-
document.body.removeChild(outerDiv);
|
|
76
|
-
return $ce415dc67314b753$var$cachedRTLResult;
|
|
77
|
-
}
|
|
78
|
-
return $ce415dc67314b753$var$cachedRTLResult;
|
|
79
|
-
}
|
|
80
|
-
function $ce415dc67314b753$export$1389d168952b34b5(node, direction) {
|
|
81
|
-
let { scrollLeft: scrollLeft } = node;
|
|
82
|
-
// scrollLeft in rtl locales differs across browsers, so normalize.
|
|
83
|
-
// See comment by getRTLOffsetType below for details.
|
|
84
|
-
if (direction === "rtl") {
|
|
85
|
-
let { scrollWidth: scrollWidth, clientWidth: clientWidth } = node;
|
|
86
|
-
switch($ce415dc67314b753$export$faf7630257ad4304()){
|
|
87
|
-
case "negative":
|
|
88
|
-
scrollLeft = -scrollLeft;
|
|
89
|
-
break;
|
|
90
|
-
case "positive-descending":
|
|
91
|
-
scrollLeft = scrollWidth - clientWidth - scrollLeft;
|
|
92
|
-
break;
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
return scrollLeft;
|
|
96
|
-
}
|
|
97
|
-
function $ce415dc67314b753$export$ed5fd5ffe5ab0ac(node, direction, scrollLeft) {
|
|
98
|
-
if (direction === "rtl") switch($ce415dc67314b753$export$faf7630257ad4304()){
|
|
99
|
-
case "negative":
|
|
100
|
-
scrollLeft = -scrollLeft;
|
|
101
|
-
break;
|
|
102
|
-
case "positive-ascending":
|
|
103
|
-
break;
|
|
104
|
-
default:
|
|
105
|
-
{
|
|
106
|
-
const { clientWidth: clientWidth, scrollWidth: scrollWidth } = node;
|
|
107
|
-
scrollLeft = scrollWidth - clientWidth - scrollLeft;
|
|
108
|
-
break;
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
node.scrollLeft = scrollLeft;
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
let $44a6ee657928b002$var$isOldReact = (0, $kSaV5$react).version.startsWith("16.") || (0, $kSaV5$react).version.startsWith("17.");
|
|
120
|
-
function $44a6ee657928b002$var$ScrollView(props, ref) {
|
|
121
|
-
let { contentSize: contentSize, onVisibleRectChange: onVisibleRectChange, children: children, innerStyle: innerStyle, sizeToFit: sizeToFit, onScrollStart: onScrollStart, onScrollEnd: onScrollEnd, scrollDirection: scrollDirection = "both", ...otherProps } = props;
|
|
122
|
-
let defaultRef = (0, $kSaV5$useRef)();
|
|
123
|
-
ref = ref || defaultRef;
|
|
124
|
-
let state = (0, $kSaV5$useRef)({
|
|
125
|
-
scrollTop: 0,
|
|
126
|
-
scrollLeft: 0,
|
|
127
|
-
scrollEndTime: 0,
|
|
128
|
-
scrollTimeout: null,
|
|
129
|
-
width: 0,
|
|
130
|
-
height: 0,
|
|
131
|
-
isScrolling: false
|
|
132
|
-
}).current;
|
|
133
|
-
let { direction: direction } = (0, $kSaV5$useLocale)();
|
|
134
|
-
let [isScrolling, setScrolling] = (0, $kSaV5$useState)(false);
|
|
135
|
-
let onScroll = (0, $kSaV5$useCallback)((e)=>{
|
|
136
|
-
if (e.target !== e.currentTarget) return;
|
|
137
|
-
if (props.onScroll) props.onScroll(e);
|
|
138
|
-
(0, $kSaV5$flushSync)(()=>{
|
|
139
|
-
let scrollTop = e.currentTarget.scrollTop;
|
|
140
|
-
let scrollLeft = (0, $ce415dc67314b753$export$1389d168952b34b5)(e.currentTarget, direction);
|
|
141
|
-
// Prevent rubber band scrolling from shaking when scrolling out of bounds
|
|
142
|
-
state.scrollTop = Math.max(0, Math.min(scrollTop, contentSize.height - state.height));
|
|
143
|
-
state.scrollLeft = Math.max(0, Math.min(scrollLeft, contentSize.width - state.width));
|
|
144
|
-
onVisibleRectChange(new (0, $kSaV5$Rect)(state.scrollLeft, state.scrollTop, state.width, state.height));
|
|
145
|
-
if (!state.isScrolling) {
|
|
146
|
-
state.isScrolling = true;
|
|
147
|
-
setScrolling(true);
|
|
148
|
-
if (onScrollStart) onScrollStart();
|
|
149
|
-
}
|
|
150
|
-
// So we don't constantly call clearTimeout and setTimeout,
|
|
151
|
-
// keep track of the current timeout time and only reschedule
|
|
152
|
-
// the timer when it is getting close.
|
|
153
|
-
let now = Date.now();
|
|
154
|
-
if (state.scrollEndTime <= now + 50) {
|
|
155
|
-
state.scrollEndTime = now + 300;
|
|
156
|
-
clearTimeout(state.scrollTimeout);
|
|
157
|
-
state.scrollTimeout = setTimeout(()=>{
|
|
158
|
-
state.isScrolling = false;
|
|
159
|
-
setScrolling(false);
|
|
160
|
-
state.scrollTimeout = null;
|
|
161
|
-
if (onScrollEnd) onScrollEnd();
|
|
162
|
-
}, 300);
|
|
163
|
-
}
|
|
164
|
-
});
|
|
165
|
-
}, [
|
|
166
|
-
props,
|
|
167
|
-
direction,
|
|
168
|
-
state,
|
|
169
|
-
contentSize,
|
|
170
|
-
onVisibleRectChange,
|
|
171
|
-
onScrollStart,
|
|
172
|
-
onScrollEnd
|
|
173
|
-
]);
|
|
174
|
-
// eslint-disable-next-line arrow-body-style
|
|
175
|
-
(0, $kSaV5$useEffect)(()=>{
|
|
176
|
-
return ()=>{
|
|
177
|
-
clearTimeout(state.scrollTimeout);
|
|
178
|
-
};
|
|
179
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
180
|
-
}, []);
|
|
181
|
-
let updateSize = (0, $kSaV5$useCallback)(()=>{
|
|
182
|
-
let dom = ref.current;
|
|
183
|
-
if (!dom) return;
|
|
184
|
-
let isTestEnv = false;
|
|
185
|
-
let isClientWidthMocked = Object.getOwnPropertyNames(window.HTMLElement.prototype).includes("clientWidth");
|
|
186
|
-
let isClientHeightMocked = Object.getOwnPropertyNames(window.HTMLElement.prototype).includes("clientHeight");
|
|
187
|
-
let w = isTestEnv && !isClientWidthMocked ? Infinity : dom.clientWidth;
|
|
188
|
-
let h = isTestEnv && !isClientHeightMocked ? Infinity : dom.clientHeight;
|
|
189
|
-
if (sizeToFit && contentSize.width > 0 && contentSize.height > 0) {
|
|
190
|
-
if (sizeToFit === "width") w = Math.min(w, contentSize.width);
|
|
191
|
-
else if (sizeToFit === "height") h = Math.min(h, contentSize.height);
|
|
192
|
-
}
|
|
193
|
-
if (state.width !== w || state.height !== h) {
|
|
194
|
-
state.width = w;
|
|
195
|
-
state.height = h;
|
|
196
|
-
onVisibleRectChange(new (0, $kSaV5$Rect)(state.scrollLeft, state.scrollTop, w, h));
|
|
197
|
-
}
|
|
198
|
-
}, [
|
|
199
|
-
onVisibleRectChange,
|
|
200
|
-
ref,
|
|
201
|
-
state,
|
|
202
|
-
sizeToFit,
|
|
203
|
-
contentSize
|
|
204
|
-
]);
|
|
205
|
-
(0, $kSaV5$useLayoutEffect)(()=>{
|
|
206
|
-
updateSize();
|
|
207
|
-
}, [
|
|
208
|
-
updateSize
|
|
209
|
-
]);
|
|
210
|
-
let raf = (0, $kSaV5$useRef)();
|
|
211
|
-
let onResize = ()=>{
|
|
212
|
-
var _raf;
|
|
213
|
-
var _current;
|
|
214
|
-
if ($44a6ee657928b002$var$isOldReact) (_current = (_raf = raf).current) !== null && _current !== void 0 ? _current : _raf.current = requestAnimationFrame(()=>{
|
|
215
|
-
updateSize();
|
|
216
|
-
raf.current = null;
|
|
217
|
-
});
|
|
218
|
-
else updateSize();
|
|
219
|
-
};
|
|
220
|
-
(0, $kSaV5$useResizeObserver)({
|
|
221
|
-
ref: ref,
|
|
222
|
-
onResize: onResize
|
|
223
|
-
});
|
|
224
|
-
(0, $kSaV5$useEffect)(()=>{
|
|
225
|
-
return ()=>{
|
|
226
|
-
if (raf.current) cancelAnimationFrame(raf.current);
|
|
227
|
-
};
|
|
228
|
-
}, []);
|
|
229
|
-
let style = {
|
|
230
|
-
// Reset padding so that relative positioning works correctly. Padding will be done in JS layout.
|
|
231
|
-
padding: 0,
|
|
232
|
-
...otherProps.style
|
|
233
|
-
};
|
|
234
|
-
if (scrollDirection === "horizontal") {
|
|
235
|
-
style.overflowX = "auto";
|
|
236
|
-
style.overflowY = "hidden";
|
|
237
|
-
} else if (scrollDirection === "vertical" || contentSize.width === state.width) {
|
|
238
|
-
// Set overflow-x: hidden if content size is equal to the width of the scroll view.
|
|
239
|
-
// This prevents horizontal scrollbars from flickering during resizing due to resize observer
|
|
240
|
-
// firing slower than the frame rate, which may cause an infinite re-render loop.
|
|
241
|
-
style.overflowY = "auto";
|
|
242
|
-
style.overflowX = "hidden";
|
|
243
|
-
} else style.overflow = "auto";
|
|
244
|
-
innerStyle = {
|
|
245
|
-
width: Number.isFinite(contentSize.width) ? contentSize.width : undefined,
|
|
246
|
-
height: Number.isFinite(contentSize.height) ? contentSize.height : undefined,
|
|
247
|
-
pointerEvents: isScrolling ? "none" : "auto",
|
|
248
|
-
position: "relative",
|
|
249
|
-
...innerStyle
|
|
250
|
-
};
|
|
251
|
-
return /*#__PURE__*/ (0, $kSaV5$react).createElement("div", {
|
|
252
|
-
...otherProps,
|
|
253
|
-
style: style,
|
|
254
|
-
ref: ref,
|
|
255
|
-
onScroll: onScroll
|
|
256
|
-
}, /*#__PURE__*/ (0, $kSaV5$react).createElement("div", {
|
|
257
|
-
role: "presentation",
|
|
258
|
-
style: innerStyle
|
|
259
|
-
}, children));
|
|
260
|
-
}
|
|
261
|
-
const $44a6ee657928b002$export$5665e3d6be6adea = /*#__PURE__*/ (0, $kSaV5$react).forwardRef($44a6ee657928b002$var$ScrollView);
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
/*
|
|
265
|
-
* Copyright 2020 Adobe. All rights reserved.
|
|
266
|
-
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
267
|
-
* you may not use this file except in compliance with the License. You may obtain a copy
|
|
268
|
-
* of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
269
|
-
*
|
|
270
|
-
* Unless required by applicable law or agreed to in writing, software distributed under
|
|
271
|
-
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
272
|
-
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
273
|
-
* governing permissions and limitations under the License.
|
|
274
|
-
*/
|
|
1
|
+
import {useVirtualizer as $6d0a5c394373ae64$export$dd6d526d88b5a137, Virtualizer as $6d0a5c394373ae64$export$89be5a243e59c4b2} from "./Virtualizer.mjs";
|
|
2
|
+
import {useVirtualizerItem as $47736c1e63ba1c6d$export$1da781778207e0a2} from "./useVirtualizerItem.mjs";
|
|
3
|
+
import {layoutInfoToStyle as $ccf8a0a04e4175ae$export$1481e64fbe01b8b3, VirtualizerItem as $ccf8a0a04e4175ae$export$6796df8ba7398521} from "./VirtualizerItem.mjs";
|
|
4
|
+
import {ScrollView as $44a6ee657928b002$export$5665e3d6be6adea} from "./ScrollView.mjs";
|
|
5
|
+
import {getRTLOffsetType as $ce415dc67314b753$export$faf7630257ad4304, getScrollLeft as $ce415dc67314b753$export$1389d168952b34b5, setScrollLeft as $ce415dc67314b753$export$ed5fd5ffe5ab0ac} from "./utils.mjs";
|
|
275
6
|
|
|
276
7
|
/*
|
|
277
8
|
* Copyright 2020 Adobe. All rights reserved.
|
|
@@ -286,267 +17,6 @@ const $44a6ee657928b002$export$5665e3d6be6adea = /*#__PURE__*/ (0, $kSaV5$react)
|
|
|
286
17
|
*/
|
|
287
18
|
|
|
288
19
|
|
|
289
|
-
function $47736c1e63ba1c6d$export$1da781778207e0a2(options) {
|
|
290
|
-
let { layoutInfo: layoutInfo, virtualizer: virtualizer, ref: ref } = options;
|
|
291
|
-
let updateSize = (0, $kSaV5$useCallback)(()=>{
|
|
292
|
-
let size = $47736c1e63ba1c6d$var$getSize(ref.current);
|
|
293
|
-
virtualizer.updateItemSize(layoutInfo.key, size);
|
|
294
|
-
}, [
|
|
295
|
-
virtualizer,
|
|
296
|
-
layoutInfo.key,
|
|
297
|
-
ref
|
|
298
|
-
]);
|
|
299
|
-
(0, $kSaV5$useLayoutEffect)(()=>{
|
|
300
|
-
if (layoutInfo.estimatedSize) updateSize();
|
|
301
|
-
});
|
|
302
|
-
return {
|
|
303
|
-
updateSize: updateSize
|
|
304
|
-
};
|
|
305
|
-
}
|
|
306
|
-
function $47736c1e63ba1c6d$var$getSize(node) {
|
|
307
|
-
// Reset height before measuring so we get the intrinsic size
|
|
308
|
-
let height = node.style.height;
|
|
309
|
-
node.style.height = "";
|
|
310
|
-
let size = new (0, $kSaV5$Size)(node.scrollWidth, node.scrollHeight);
|
|
311
|
-
node.style.height = height;
|
|
312
|
-
return size;
|
|
313
|
-
}
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
function $ccf8a0a04e4175ae$export$6796df8ba7398521(props) {
|
|
317
|
-
let { className: className, layoutInfo: layoutInfo, virtualizer: virtualizer, parent: parent, children: children } = props;
|
|
318
|
-
let { direction: direction } = (0, $kSaV5$useLocale)();
|
|
319
|
-
let ref = (0, $kSaV5$useRef)();
|
|
320
|
-
(0, $47736c1e63ba1c6d$export$1da781778207e0a2)({
|
|
321
|
-
layoutInfo: layoutInfo,
|
|
322
|
-
virtualizer: virtualizer,
|
|
323
|
-
ref: ref
|
|
324
|
-
});
|
|
325
|
-
return /*#__PURE__*/ (0, $kSaV5$react).createElement("div", {
|
|
326
|
-
role: "presentation",
|
|
327
|
-
ref: ref,
|
|
328
|
-
className: className,
|
|
329
|
-
style: $ccf8a0a04e4175ae$export$1481e64fbe01b8b3(layoutInfo, direction, parent)
|
|
330
|
-
}, children);
|
|
331
|
-
}
|
|
332
|
-
let $ccf8a0a04e4175ae$var$cache = new WeakMap();
|
|
333
|
-
function $ccf8a0a04e4175ae$export$1481e64fbe01b8b3(layoutInfo, dir, parent) {
|
|
334
|
-
let xProperty = dir === "rtl" ? "right" : "left";
|
|
335
|
-
let cached = $ccf8a0a04e4175ae$var$cache.get(layoutInfo);
|
|
336
|
-
if (cached && cached[xProperty] != null) {
|
|
337
|
-
if (!parent) return cached;
|
|
338
|
-
// Invalidate if the parent position changed.
|
|
339
|
-
let top = layoutInfo.rect.y - parent.rect.y;
|
|
340
|
-
let x = layoutInfo.rect.x - parent.rect.x;
|
|
341
|
-
if (cached.top === top && cached[xProperty] === x) return cached;
|
|
342
|
-
}
|
|
343
|
-
let rectStyles = {
|
|
344
|
-
top: layoutInfo.rect.y - (parent ? parent.rect.y : 0),
|
|
345
|
-
[xProperty]: layoutInfo.rect.x - (parent ? parent.rect.x : 0),
|
|
346
|
-
width: layoutInfo.rect.width,
|
|
347
|
-
height: layoutInfo.rect.height
|
|
348
|
-
};
|
|
349
|
-
// Get rid of any non finite values since they aren't valid css values
|
|
350
|
-
Object.entries(rectStyles).forEach(([key, value])=>{
|
|
351
|
-
if (!Number.isFinite(value)) rectStyles[key] = undefined;
|
|
352
|
-
});
|
|
353
|
-
let style = {
|
|
354
|
-
position: layoutInfo.isSticky ? "sticky" : "absolute",
|
|
355
|
-
// Sticky elements are positioned in normal document flow. Display inline-block so that they don't push other sticky columns onto the following rows.
|
|
356
|
-
display: layoutInfo.isSticky ? "inline-block" : undefined,
|
|
357
|
-
overflow: layoutInfo.allowOverflow ? "visible" : "hidden",
|
|
358
|
-
transition: "all",
|
|
359
|
-
WebkitTransition: "all",
|
|
360
|
-
WebkitTransitionDuration: "inherit",
|
|
361
|
-
transitionDuration: "inherit",
|
|
362
|
-
opacity: layoutInfo.opacity,
|
|
363
|
-
zIndex: layoutInfo.zIndex,
|
|
364
|
-
transform: layoutInfo.transform,
|
|
365
|
-
contain: "size layout style",
|
|
366
|
-
...rectStyles
|
|
367
|
-
};
|
|
368
|
-
$ccf8a0a04e4175ae$var$cache.set(layoutInfo, style);
|
|
369
|
-
return style;
|
|
370
|
-
}
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
function $6d0a5c394373ae64$var$Virtualizer(props, ref) {
|
|
374
|
-
let { children: renderView, renderWrapper: renderWrapper, layout: layout, collection: collection, sizeToFit: sizeToFit, scrollDirection: scrollDirection, transitionDuration: transitionDuration, isLoading: // eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
375
|
-
isLoading, onLoadMore: // eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
376
|
-
onLoadMore, focusedKey: // eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
377
|
-
focusedKey, shouldUseVirtualFocus: // eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
378
|
-
shouldUseVirtualFocus, scrollToItem: // eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
379
|
-
scrollToItem, autoFocus: // eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
380
|
-
autoFocus, ...otherProps } = props;
|
|
381
|
-
let fallbackRef = (0, $kSaV5$useRef)();
|
|
382
|
-
ref = ref || fallbackRef;
|
|
383
|
-
let state = (0, $kSaV5$useVirtualizerState)({
|
|
384
|
-
transitionDuration: transitionDuration,
|
|
385
|
-
layout: layout,
|
|
386
|
-
collection: collection,
|
|
387
|
-
renderView: renderView,
|
|
388
|
-
renderWrapper: renderWrapper || $6d0a5c394373ae64$var$defaultRenderWrapper,
|
|
389
|
-
onVisibleRectChange (rect) {
|
|
390
|
-
ref.current.scrollLeft = rect.x;
|
|
391
|
-
ref.current.scrollTop = rect.y;
|
|
392
|
-
}
|
|
393
|
-
});
|
|
394
|
-
let { virtualizerProps: virtualizerProps, scrollViewProps: scrollViewProps } = $6d0a5c394373ae64$export$dd6d526d88b5a137(props, state, ref);
|
|
395
|
-
return /*#__PURE__*/ (0, $kSaV5$react).createElement((0, $44a6ee657928b002$export$5665e3d6be6adea), {
|
|
396
|
-
...(0, $kSaV5$mergeProps)(otherProps, virtualizerProps, scrollViewProps),
|
|
397
|
-
ref: ref,
|
|
398
|
-
innerStyle: state.isAnimating ? {
|
|
399
|
-
transition: `none ${state.virtualizer.transitionDuration}ms`
|
|
400
|
-
} : undefined,
|
|
401
|
-
contentSize: state.contentSize,
|
|
402
|
-
onScrollStart: state.startScrolling,
|
|
403
|
-
onScrollEnd: state.endScrolling,
|
|
404
|
-
sizeToFit: sizeToFit,
|
|
405
|
-
scrollDirection: scrollDirection
|
|
406
|
-
}, state.visibleViews);
|
|
407
|
-
}
|
|
408
|
-
function $6d0a5c394373ae64$export$dd6d526d88b5a137(props, state, ref) {
|
|
409
|
-
let { focusedKey: focusedKey, scrollToItem: scrollToItem, shouldUseVirtualFocus: shouldUseVirtualFocus, isLoading: isLoading, onLoadMore: onLoadMore } = props;
|
|
410
|
-
let { virtualizer: virtualizer } = state;
|
|
411
|
-
// Scroll to the focusedKey when it changes. Actually focusing the focusedKey
|
|
412
|
-
// is up to the implementation using Virtualizer since we don't have refs
|
|
413
|
-
// to all of the item DOM nodes.
|
|
414
|
-
let lastFocusedKey = (0, $kSaV5$useRef)(null);
|
|
415
|
-
let isFocusWithin = (0, $kSaV5$useRef)(false);
|
|
416
|
-
let autoFocus = (0, $kSaV5$useRef)(props.autoFocus);
|
|
417
|
-
(0, $kSaV5$useEffect)(()=>{
|
|
418
|
-
if (virtualizer.visibleRect.height === 0) return;
|
|
419
|
-
// Only scroll the focusedKey into view if the modality is not pointer to avoid jumps in position when clicking/pressing tall items.
|
|
420
|
-
let modality = (0, $kSaV5$getInteractionModality)();
|
|
421
|
-
if (focusedKey !== lastFocusedKey.current && (modality !== "pointer" || autoFocus.current)) {
|
|
422
|
-
autoFocus.current = false;
|
|
423
|
-
if (scrollToItem) // If user provides scrolltoitem, then it is their responsibility to call scrollIntoViewport if desired
|
|
424
|
-
// since we don't know if their scrollToItem may take some time to actually bring the active element into the virtualizer's visible rect.
|
|
425
|
-
scrollToItem(focusedKey);
|
|
426
|
-
else virtualizer.scrollToItem(focusedKey, {
|
|
427
|
-
duration: 0
|
|
428
|
-
});
|
|
429
|
-
}
|
|
430
|
-
lastFocusedKey.current = focusedKey;
|
|
431
|
-
}, [
|
|
432
|
-
focusedKey,
|
|
433
|
-
virtualizer.visibleRect.height,
|
|
434
|
-
virtualizer,
|
|
435
|
-
lastFocusedKey,
|
|
436
|
-
scrollToItem,
|
|
437
|
-
ref
|
|
438
|
-
]);
|
|
439
|
-
// Persist the focusedKey and prevent it from being removed from the DOM when scrolled out of view.
|
|
440
|
-
virtualizer.persistedKeys = (0, $kSaV5$useMemo)(()=>focusedKey ? new Set([
|
|
441
|
-
focusedKey
|
|
442
|
-
]) : new Set(), [
|
|
443
|
-
focusedKey
|
|
444
|
-
]);
|
|
445
|
-
let onFocus = (0, $kSaV5$useCallback)((e)=>{
|
|
446
|
-
// If the focused item is scrolled out of view and is not in the DOM, the collection
|
|
447
|
-
// will have tabIndex={0}. When tabbing in from outside, scroll the focused item into view.
|
|
448
|
-
// Ignore focus events that bubble through portals (e.g. focus that happens on a menu popover child of the virtualizer)
|
|
449
|
-
// Don't scroll focused key into view if modality is pointer to prevent sudden jump in position (e.g. CardView).
|
|
450
|
-
let modality = (0, $kSaV5$getInteractionModality)();
|
|
451
|
-
if (!isFocusWithin.current && ref.current.contains(e.target) && modality !== "pointer") {
|
|
452
|
-
if (scrollToItem) scrollToItem(focusedKey);
|
|
453
|
-
else virtualizer.scrollToItem(focusedKey, {
|
|
454
|
-
duration: 0
|
|
455
|
-
});
|
|
456
|
-
}
|
|
457
|
-
isFocusWithin.current = e.target !== ref.current;
|
|
458
|
-
}, [
|
|
459
|
-
ref,
|
|
460
|
-
virtualizer,
|
|
461
|
-
focusedKey,
|
|
462
|
-
scrollToItem
|
|
463
|
-
]);
|
|
464
|
-
let onBlur = (0, $kSaV5$useCallback)((e)=>{
|
|
465
|
-
isFocusWithin.current = ref.current.contains(e.relatedTarget);
|
|
466
|
-
}, [
|
|
467
|
-
ref
|
|
468
|
-
]);
|
|
469
|
-
// Set tabIndex to -1 if there is a focused key, otherwise 0 so that the collection
|
|
470
|
-
// itself is tabbable. When the collection receives focus, we scroll the focused item back into
|
|
471
|
-
// view, which will allow it to be properly focused. If using virtual focus, don't set a
|
|
472
|
-
// tabIndex at all so that VoiceOver on iOS 14 doesn't try to move real DOM focus to the element anyway.
|
|
473
|
-
let tabIndex;
|
|
474
|
-
if (!shouldUseVirtualFocus) {
|
|
475
|
-
// When there is no focusedKey the default tabIndex is 0. We include logic for empty collections too.
|
|
476
|
-
// For collections that are empty, but have a link in the empty children we want to skip focusing this
|
|
477
|
-
// and let focus move to the link similar to link moving to children.
|
|
478
|
-
tabIndex = focusedKey != null ? -1 : 0;
|
|
479
|
-
// If the collection is empty, we want the tabIndex provided from props (if any)
|
|
480
|
-
// so that we handle when tabbable items are added to the empty state.
|
|
481
|
-
if (virtualizer.collection.size === 0 && props.tabIndex != null) tabIndex = props.tabIndex;
|
|
482
|
-
}
|
|
483
|
-
// Handle scrolling, and call onLoadMore when nearing the bottom.
|
|
484
|
-
let isLoadingRef = (0, $kSaV5$useRef)(isLoading);
|
|
485
|
-
let prevProps = (0, $kSaV5$useRef)(props);
|
|
486
|
-
let onVisibleRectChange = (0, $kSaV5$useCallback)((rect)=>{
|
|
487
|
-
state.setVisibleRect(rect);
|
|
488
|
-
if (!isLoadingRef.current && onLoadMore) {
|
|
489
|
-
let scrollOffset = state.virtualizer.contentSize.height - rect.height * 2;
|
|
490
|
-
if (rect.y > scrollOffset) {
|
|
491
|
-
isLoadingRef.current = true;
|
|
492
|
-
onLoadMore();
|
|
493
|
-
}
|
|
494
|
-
}
|
|
495
|
-
}, [
|
|
496
|
-
onLoadMore,
|
|
497
|
-
state
|
|
498
|
-
]);
|
|
499
|
-
let lastContentSize = (0, $kSaV5$useRef)(0);
|
|
500
|
-
(0, $kSaV5$useLayoutEffect)(()=>{
|
|
501
|
-
// If animating, wait until we're done.
|
|
502
|
-
if (state.isAnimating) return;
|
|
503
|
-
// Only update isLoadingRef if props object actually changed,
|
|
504
|
-
// not if a local state change occurred.
|
|
505
|
-
let wasLoading = isLoadingRef.current;
|
|
506
|
-
if (props !== prevProps.current) {
|
|
507
|
-
isLoadingRef.current = isLoading;
|
|
508
|
-
prevProps.current = props;
|
|
509
|
-
}
|
|
510
|
-
let shouldLoadMore = !isLoadingRef.current && onLoadMore && state.contentSize.height > 0 && state.contentSize.height <= state.virtualizer.visibleRect.height && (wasLoading || state.contentSize.height !== lastContentSize.current);
|
|
511
|
-
if (shouldLoadMore) {
|
|
512
|
-
isLoadingRef.current = true;
|
|
513
|
-
onLoadMore();
|
|
514
|
-
}
|
|
515
|
-
lastContentSize.current = state.contentSize.height;
|
|
516
|
-
}, [
|
|
517
|
-
state.contentSize,
|
|
518
|
-
state.isAnimating,
|
|
519
|
-
state.virtualizer,
|
|
520
|
-
isLoading,
|
|
521
|
-
onLoadMore,
|
|
522
|
-
props
|
|
523
|
-
]);
|
|
524
|
-
return {
|
|
525
|
-
virtualizerProps: {
|
|
526
|
-
tabIndex: tabIndex,
|
|
527
|
-
onFocus: onFocus,
|
|
528
|
-
onBlur: onBlur
|
|
529
|
-
},
|
|
530
|
-
scrollViewProps: {
|
|
531
|
-
onVisibleRectChange: onVisibleRectChange
|
|
532
|
-
}
|
|
533
|
-
};
|
|
534
|
-
}
|
|
535
|
-
// forwardRef doesn't support generic parameters, so cast the result to the correct type
|
|
536
|
-
// https://stackoverflow.com/questions/58469229/react-with-typescript-generics-while-using-react-forwardref
|
|
537
|
-
const $6d0a5c394373ae64$export$89be5a243e59c4b2 = /*#__PURE__*/ (0, $kSaV5$react).forwardRef($6d0a5c394373ae64$var$Virtualizer);
|
|
538
|
-
function $6d0a5c394373ae64$var$defaultRenderWrapper(parent, reusableView) {
|
|
539
|
-
return /*#__PURE__*/ (0, $kSaV5$react).createElement((0, $ccf8a0a04e4175ae$export$6796df8ba7398521), {
|
|
540
|
-
key: reusableView.key,
|
|
541
|
-
layoutInfo: reusableView.layoutInfo,
|
|
542
|
-
virtualizer: reusableView.virtualizer,
|
|
543
|
-
parent: parent === null || parent === void 0 ? void 0 : parent.layoutInfo
|
|
544
|
-
}, reusableView.rendered);
|
|
545
|
-
}
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
20
|
|
|
551
21
|
|
|
552
22
|
|