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