@react-aria/virtualizer 4.1.13 → 4.2.0
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 +6 -6
- package/dist/main.js +14 -14
- package/dist/main.js.map +1 -1
- package/dist/module.js +6 -6
- package/dist/module.js.map +1 -1
- package/dist/types/src/index.d.ts +7 -0
- package/package.json +15 -16
- package/src/index.ts +8 -7
- package/dist/ScrollView.main.js +0 -228
- package/dist/ScrollView.main.js.map +0 -1
- package/dist/ScrollView.mjs +0 -218
- package/dist/ScrollView.module.js +0 -218
- package/dist/ScrollView.module.js.map +0 -1
- package/dist/Virtualizer.main.js +0 -84
- package/dist/Virtualizer.main.js.map +0 -1
- package/dist/Virtualizer.mjs +0 -75
- package/dist/Virtualizer.module.js +0 -75
- package/dist/Virtualizer.module.js.map +0 -1
- package/dist/VirtualizerItem.main.js +0 -90
- package/dist/VirtualizerItem.main.js.map +0 -1
- package/dist/VirtualizerItem.mjs +0 -80
- package/dist/VirtualizerItem.module.js +0 -80
- package/dist/VirtualizerItem.module.js.map +0 -1
- package/dist/types.d.ts +0 -60
- package/dist/types.d.ts.map +0 -1
- package/dist/useVirtualizerItem.main.js +0 -54
- package/dist/useVirtualizerItem.main.js.map +0 -1
- package/dist/useVirtualizerItem.mjs +0 -49
- package/dist/useVirtualizerItem.module.js +0 -49
- package/dist/useVirtualizerItem.module.js.map +0 -1
- package/dist/utils.main.js +0 -80
- package/dist/utils.main.js.map +0 -1
- package/dist/utils.mjs +0 -73
- package/dist/utils.module.js +0 -73
- package/dist/utils.module.js.map +0 -1
- package/src/ScrollView.tsx +0 -282
- package/src/Virtualizer.tsx +0 -113
- package/src/VirtualizerItem.tsx +0 -93
- package/src/useVirtualizerItem.ts +0 -55
- package/src/utils.ts +0 -107
package/dist/utils.main.js
DELETED
|
@@ -1,80 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
function $parcel$export(e, n, v, s) {
|
|
3
|
-
Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
|
|
4
|
-
}
|
|
5
|
-
|
|
6
|
-
$parcel$export(module.exports, "getRTLOffsetType", () => $efdd61e59e023a1d$export$faf7630257ad4304);
|
|
7
|
-
$parcel$export(module.exports, "getScrollLeft", () => $efdd61e59e023a1d$export$1389d168952b34b5);
|
|
8
|
-
$parcel$export(module.exports, "setScrollLeft", () => $efdd61e59e023a1d$export$ed5fd5ffe5ab0ac);
|
|
9
|
-
/*
|
|
10
|
-
* Copyright 2020 Adobe. All rights reserved.
|
|
11
|
-
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
12
|
-
* you may not use this file except in compliance with the License. You may obtain a copy
|
|
13
|
-
* of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
14
|
-
*
|
|
15
|
-
* Unless required by applicable law or agreed to in writing, software distributed under
|
|
16
|
-
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
17
|
-
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
18
|
-
* governing permissions and limitations under the License.
|
|
19
|
-
*/ let $efdd61e59e023a1d$var$cachedRTLResult = null;
|
|
20
|
-
function $efdd61e59e023a1d$export$faf7630257ad4304(recalculate = false) {
|
|
21
|
-
if ($efdd61e59e023a1d$var$cachedRTLResult === null || recalculate) {
|
|
22
|
-
const outerDiv = document.createElement('div');
|
|
23
|
-
const outerStyle = outerDiv.style;
|
|
24
|
-
outerStyle.width = '50px';
|
|
25
|
-
outerStyle.height = '50px';
|
|
26
|
-
outerStyle.overflow = 'scroll';
|
|
27
|
-
outerStyle.direction = 'rtl';
|
|
28
|
-
const innerDiv = document.createElement('div');
|
|
29
|
-
const innerStyle = innerDiv.style;
|
|
30
|
-
innerStyle.width = '100px';
|
|
31
|
-
innerStyle.height = '100px';
|
|
32
|
-
outerDiv.appendChild(innerDiv);
|
|
33
|
-
document.body.appendChild(outerDiv);
|
|
34
|
-
if (outerDiv.scrollLeft > 0) $efdd61e59e023a1d$var$cachedRTLResult = 'positive-descending';
|
|
35
|
-
else {
|
|
36
|
-
outerDiv.scrollLeft = 1;
|
|
37
|
-
if (outerDiv.scrollLeft === 0) $efdd61e59e023a1d$var$cachedRTLResult = 'negative';
|
|
38
|
-
else $efdd61e59e023a1d$var$cachedRTLResult = 'positive-ascending';
|
|
39
|
-
}
|
|
40
|
-
document.body.removeChild(outerDiv);
|
|
41
|
-
return $efdd61e59e023a1d$var$cachedRTLResult;
|
|
42
|
-
}
|
|
43
|
-
return $efdd61e59e023a1d$var$cachedRTLResult;
|
|
44
|
-
}
|
|
45
|
-
function $efdd61e59e023a1d$export$1389d168952b34b5(node, direction) {
|
|
46
|
-
let { scrollLeft: scrollLeft } = node;
|
|
47
|
-
// scrollLeft in rtl locales differs across browsers, so normalize.
|
|
48
|
-
// See comment by getRTLOffsetType below for details.
|
|
49
|
-
if (direction === 'rtl') {
|
|
50
|
-
let { scrollWidth: scrollWidth, clientWidth: clientWidth } = node;
|
|
51
|
-
switch($efdd61e59e023a1d$export$faf7630257ad4304()){
|
|
52
|
-
case 'negative':
|
|
53
|
-
scrollLeft = -scrollLeft;
|
|
54
|
-
break;
|
|
55
|
-
case 'positive-descending':
|
|
56
|
-
scrollLeft = scrollWidth - clientWidth - scrollLeft;
|
|
57
|
-
break;
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
return scrollLeft;
|
|
61
|
-
}
|
|
62
|
-
function $efdd61e59e023a1d$export$ed5fd5ffe5ab0ac(node, direction, scrollLeft) {
|
|
63
|
-
if (direction === 'rtl') switch($efdd61e59e023a1d$export$faf7630257ad4304()){
|
|
64
|
-
case 'negative':
|
|
65
|
-
scrollLeft = -scrollLeft;
|
|
66
|
-
break;
|
|
67
|
-
case 'positive-ascending':
|
|
68
|
-
break;
|
|
69
|
-
default:
|
|
70
|
-
{
|
|
71
|
-
const { clientWidth: clientWidth, scrollWidth: scrollWidth } = node;
|
|
72
|
-
scrollLeft = scrollWidth - clientWidth - scrollLeft;
|
|
73
|
-
break;
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
node.scrollLeft = scrollLeft;
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
//# sourceMappingURL=utils.main.js.map
|
package/dist/utils.main.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"mappings":";;;;;;;;AAAA;;;;;;;;;;CAUC,GASD,IAAI,wCAAwC;AAarC,SAAS,0CAAiB,cAAuB,KAAK;IAC3D,IAAI,0CAAoB,QAAQ,aAAa;QAC3C,MAAM,WAAW,SAAS,aAAa,CAAC;QACxC,MAAM,aAAa,SAAS,KAAK;QACjC,WAAW,KAAK,GAAG;QACnB,WAAW,MAAM,GAAG;QACpB,WAAW,QAAQ,GAAG;QACtB,WAAW,SAAS,GAAG;QAEvB,MAAM,WAAW,SAAS,aAAa,CAAC;QACxC,MAAM,aAAa,SAAS,KAAK;QACjC,WAAW,KAAK,GAAG;QACnB,WAAW,MAAM,GAAG;QAEpB,SAAS,WAAW,CAAC;QAErB,SAAS,IAAI,CAAC,WAAW,CAAC;QAE1B,IAAI,SAAS,UAAU,GAAG,GACxB,wCAAkB;aACb;YACL,SAAS,UAAU,GAAG;YACtB,IAAI,SAAS,UAAU,KAAK,GAC1B,wCAAkB;iBAElB,wCAAkB;QAEtB;QAEA,SAAS,IAAI,CAAC,WAAW,CAAC;QAE1B,OAAO;IACT;IAEA,OAAO;AACT;AAEO,SAAS,0CAAc,IAAa,EAAE,SAAoB;IAC/D,IAAI,cAAC,UAAU,EAAC,GAAG;IAEnB,mEAAmE;IACnE,qDAAqD;IACrD,IAAI,cAAc,OAAO;QACvB,IAAI,eAAC,WAAW,eAAE,WAAW,EAAC,GAAG;QACjC,OAAQ;YACN,KAAK;gBACH,aAAa,CAAC;gBACd;YACF,KAAK;gBACH,aAAa,cAAc,cAAc;gBACzC;QACJ;IACF;IAEA,OAAO;AACT;AAEO,SAAS,yCAAc,IAAa,EAAE,SAAoB,EAAE,UAAkB;IACnF,IAAI,cAAc,OAChB,OAAQ;QACN,KAAK;YACH,aAAa,CAAC;YACd;QACF,KAAK;YACH;QACF;YAAS;gBACP,MAAM,eAAC,WAAW,eAAE,WAAW,EAAC,GAAG;gBACnC,aAAa,cAAc,cAAc;gBACzC;YACF;IACF;IAGF,KAAK,UAAU,GAAG;AACpB","sources":["packages/@react-aria/virtualizer/src/utils.ts"],"sourcesContent":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {Direction} from '@react-types/shared';\n\nexport type RTLOffsetType =\n | 'negative'\n | 'positive-descending'\n | 'positive-ascending';\n\nlet cachedRTLResult: RTLOffsetType | null = null;\n\n\n// Original licensing for the following methods can be found in the\n// NOTICE file in the root directory of this source tree.\n// See https://github.com/bvaughn/react-window/blob/master/src/createGridComponent.js\n\n// According to the spec, scrollLeft should be negative for RTL aligned elements.\n// Chrome does not seem to adhere; its scrollLeft values are positive (measured relative to the left).\n// Safari's elastic bounce makes detecting this even more complicated wrt potential false positives.\n// The safest way to check this is to intentionally set a negative offset,\n// and then verify that the subsequent \"scroll\" event matches the negative offset.\n// If it does not match, then we can assume a non-standard RTL scroll implementation.\nexport function getRTLOffsetType(recalculate: boolean = false): RTLOffsetType {\n if (cachedRTLResult === null || recalculate) {\n const outerDiv = document.createElement('div');\n const outerStyle = outerDiv.style;\n outerStyle.width = '50px';\n outerStyle.height = '50px';\n outerStyle.overflow = 'scroll';\n outerStyle.direction = 'rtl';\n\n const innerDiv = document.createElement('div');\n const innerStyle = innerDiv.style;\n innerStyle.width = '100px';\n innerStyle.height = '100px';\n\n outerDiv.appendChild(innerDiv);\n\n document.body.appendChild(outerDiv);\n\n if (outerDiv.scrollLeft > 0) {\n cachedRTLResult = 'positive-descending';\n } else {\n outerDiv.scrollLeft = 1;\n if (outerDiv.scrollLeft === 0) {\n cachedRTLResult = 'negative';\n } else {\n cachedRTLResult = 'positive-ascending';\n }\n }\n\n document.body.removeChild(outerDiv);\n\n return cachedRTLResult;\n }\n\n return cachedRTLResult;\n}\n\nexport function getScrollLeft(node: Element, direction: Direction): number {\n let {scrollLeft} = node;\n\n // scrollLeft in rtl locales differs across browsers, so normalize.\n // See comment by getRTLOffsetType below for details.\n if (direction === 'rtl') {\n let {scrollWidth, clientWidth} = node;\n switch (getRTLOffsetType()) {\n case 'negative':\n scrollLeft = -scrollLeft;\n break;\n case 'positive-descending':\n scrollLeft = scrollWidth - clientWidth - scrollLeft;\n break;\n }\n }\n\n return scrollLeft;\n}\n\nexport function setScrollLeft(node: Element, direction: Direction, scrollLeft: number): void {\n if (direction === 'rtl') {\n switch (getRTLOffsetType()) {\n case 'negative':\n scrollLeft = -scrollLeft;\n break;\n case 'positive-ascending':\n break;\n default: {\n const {clientWidth, scrollWidth} = node;\n scrollLeft = scrollWidth - clientWidth - scrollLeft;\n break;\n }\n }\n }\n\n node.scrollLeft = scrollLeft;\n}\n"],"names":[],"version":3,"file":"utils.main.js.map"}
|
package/dist/utils.mjs
DELETED
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Copyright 2020 Adobe. All rights reserved.
|
|
3
|
-
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
4
|
-
* you may not use this file except in compliance with the License. You may obtain a copy
|
|
5
|
-
* of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
6
|
-
*
|
|
7
|
-
* Unless required by applicable law or agreed to in writing, software distributed under
|
|
8
|
-
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
9
|
-
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
10
|
-
* governing permissions and limitations under the License.
|
|
11
|
-
*/ let $ce415dc67314b753$var$cachedRTLResult = null;
|
|
12
|
-
function $ce415dc67314b753$export$faf7630257ad4304(recalculate = false) {
|
|
13
|
-
if ($ce415dc67314b753$var$cachedRTLResult === null || recalculate) {
|
|
14
|
-
const outerDiv = document.createElement('div');
|
|
15
|
-
const outerStyle = outerDiv.style;
|
|
16
|
-
outerStyle.width = '50px';
|
|
17
|
-
outerStyle.height = '50px';
|
|
18
|
-
outerStyle.overflow = 'scroll';
|
|
19
|
-
outerStyle.direction = 'rtl';
|
|
20
|
-
const innerDiv = document.createElement('div');
|
|
21
|
-
const innerStyle = innerDiv.style;
|
|
22
|
-
innerStyle.width = '100px';
|
|
23
|
-
innerStyle.height = '100px';
|
|
24
|
-
outerDiv.appendChild(innerDiv);
|
|
25
|
-
document.body.appendChild(outerDiv);
|
|
26
|
-
if (outerDiv.scrollLeft > 0) $ce415dc67314b753$var$cachedRTLResult = 'positive-descending';
|
|
27
|
-
else {
|
|
28
|
-
outerDiv.scrollLeft = 1;
|
|
29
|
-
if (outerDiv.scrollLeft === 0) $ce415dc67314b753$var$cachedRTLResult = 'negative';
|
|
30
|
-
else $ce415dc67314b753$var$cachedRTLResult = 'positive-ascending';
|
|
31
|
-
}
|
|
32
|
-
document.body.removeChild(outerDiv);
|
|
33
|
-
return $ce415dc67314b753$var$cachedRTLResult;
|
|
34
|
-
}
|
|
35
|
-
return $ce415dc67314b753$var$cachedRTLResult;
|
|
36
|
-
}
|
|
37
|
-
function $ce415dc67314b753$export$1389d168952b34b5(node, direction) {
|
|
38
|
-
let { scrollLeft: scrollLeft } = node;
|
|
39
|
-
// scrollLeft in rtl locales differs across browsers, so normalize.
|
|
40
|
-
// See comment by getRTLOffsetType below for details.
|
|
41
|
-
if (direction === 'rtl') {
|
|
42
|
-
let { scrollWidth: scrollWidth, clientWidth: clientWidth } = node;
|
|
43
|
-
switch($ce415dc67314b753$export$faf7630257ad4304()){
|
|
44
|
-
case 'negative':
|
|
45
|
-
scrollLeft = -scrollLeft;
|
|
46
|
-
break;
|
|
47
|
-
case 'positive-descending':
|
|
48
|
-
scrollLeft = scrollWidth - clientWidth - scrollLeft;
|
|
49
|
-
break;
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
return scrollLeft;
|
|
53
|
-
}
|
|
54
|
-
function $ce415dc67314b753$export$ed5fd5ffe5ab0ac(node, direction, scrollLeft) {
|
|
55
|
-
if (direction === 'rtl') switch($ce415dc67314b753$export$faf7630257ad4304()){
|
|
56
|
-
case 'negative':
|
|
57
|
-
scrollLeft = -scrollLeft;
|
|
58
|
-
break;
|
|
59
|
-
case 'positive-ascending':
|
|
60
|
-
break;
|
|
61
|
-
default:
|
|
62
|
-
{
|
|
63
|
-
const { clientWidth: clientWidth, scrollWidth: scrollWidth } = node;
|
|
64
|
-
scrollLeft = scrollWidth - clientWidth - scrollLeft;
|
|
65
|
-
break;
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
node.scrollLeft = scrollLeft;
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
export {$ce415dc67314b753$export$faf7630257ad4304 as getRTLOffsetType, $ce415dc67314b753$export$1389d168952b34b5 as getScrollLeft, $ce415dc67314b753$export$ed5fd5ffe5ab0ac as setScrollLeft};
|
|
73
|
-
//# sourceMappingURL=utils.module.js.map
|
package/dist/utils.module.js
DELETED
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Copyright 2020 Adobe. All rights reserved.
|
|
3
|
-
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
4
|
-
* you may not use this file except in compliance with the License. You may obtain a copy
|
|
5
|
-
* of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
6
|
-
*
|
|
7
|
-
* Unless required by applicable law or agreed to in writing, software distributed under
|
|
8
|
-
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
9
|
-
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
10
|
-
* governing permissions and limitations under the License.
|
|
11
|
-
*/ let $ce415dc67314b753$var$cachedRTLResult = null;
|
|
12
|
-
function $ce415dc67314b753$export$faf7630257ad4304(recalculate = false) {
|
|
13
|
-
if ($ce415dc67314b753$var$cachedRTLResult === null || recalculate) {
|
|
14
|
-
const outerDiv = document.createElement('div');
|
|
15
|
-
const outerStyle = outerDiv.style;
|
|
16
|
-
outerStyle.width = '50px';
|
|
17
|
-
outerStyle.height = '50px';
|
|
18
|
-
outerStyle.overflow = 'scroll';
|
|
19
|
-
outerStyle.direction = 'rtl';
|
|
20
|
-
const innerDiv = document.createElement('div');
|
|
21
|
-
const innerStyle = innerDiv.style;
|
|
22
|
-
innerStyle.width = '100px';
|
|
23
|
-
innerStyle.height = '100px';
|
|
24
|
-
outerDiv.appendChild(innerDiv);
|
|
25
|
-
document.body.appendChild(outerDiv);
|
|
26
|
-
if (outerDiv.scrollLeft > 0) $ce415dc67314b753$var$cachedRTLResult = 'positive-descending';
|
|
27
|
-
else {
|
|
28
|
-
outerDiv.scrollLeft = 1;
|
|
29
|
-
if (outerDiv.scrollLeft === 0) $ce415dc67314b753$var$cachedRTLResult = 'negative';
|
|
30
|
-
else $ce415dc67314b753$var$cachedRTLResult = 'positive-ascending';
|
|
31
|
-
}
|
|
32
|
-
document.body.removeChild(outerDiv);
|
|
33
|
-
return $ce415dc67314b753$var$cachedRTLResult;
|
|
34
|
-
}
|
|
35
|
-
return $ce415dc67314b753$var$cachedRTLResult;
|
|
36
|
-
}
|
|
37
|
-
function $ce415dc67314b753$export$1389d168952b34b5(node, direction) {
|
|
38
|
-
let { scrollLeft: scrollLeft } = node;
|
|
39
|
-
// scrollLeft in rtl locales differs across browsers, so normalize.
|
|
40
|
-
// See comment by getRTLOffsetType below for details.
|
|
41
|
-
if (direction === 'rtl') {
|
|
42
|
-
let { scrollWidth: scrollWidth, clientWidth: clientWidth } = node;
|
|
43
|
-
switch($ce415dc67314b753$export$faf7630257ad4304()){
|
|
44
|
-
case 'negative':
|
|
45
|
-
scrollLeft = -scrollLeft;
|
|
46
|
-
break;
|
|
47
|
-
case 'positive-descending':
|
|
48
|
-
scrollLeft = scrollWidth - clientWidth - scrollLeft;
|
|
49
|
-
break;
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
return scrollLeft;
|
|
53
|
-
}
|
|
54
|
-
function $ce415dc67314b753$export$ed5fd5ffe5ab0ac(node, direction, scrollLeft) {
|
|
55
|
-
if (direction === 'rtl') switch($ce415dc67314b753$export$faf7630257ad4304()){
|
|
56
|
-
case 'negative':
|
|
57
|
-
scrollLeft = -scrollLeft;
|
|
58
|
-
break;
|
|
59
|
-
case 'positive-ascending':
|
|
60
|
-
break;
|
|
61
|
-
default:
|
|
62
|
-
{
|
|
63
|
-
const { clientWidth: clientWidth, scrollWidth: scrollWidth } = node;
|
|
64
|
-
scrollLeft = scrollWidth - clientWidth - scrollLeft;
|
|
65
|
-
break;
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
node.scrollLeft = scrollLeft;
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
export {$ce415dc67314b753$export$faf7630257ad4304 as getRTLOffsetType, $ce415dc67314b753$export$1389d168952b34b5 as getScrollLeft, $ce415dc67314b753$export$ed5fd5ffe5ab0ac as setScrollLeft};
|
|
73
|
-
//# sourceMappingURL=utils.module.js.map
|
package/dist/utils.module.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"mappings":"AAAA;;;;;;;;;;CAUC,GASD,IAAI,wCAAwC;AAarC,SAAS,0CAAiB,cAAuB,KAAK;IAC3D,IAAI,0CAAoB,QAAQ,aAAa;QAC3C,MAAM,WAAW,SAAS,aAAa,CAAC;QACxC,MAAM,aAAa,SAAS,KAAK;QACjC,WAAW,KAAK,GAAG;QACnB,WAAW,MAAM,GAAG;QACpB,WAAW,QAAQ,GAAG;QACtB,WAAW,SAAS,GAAG;QAEvB,MAAM,WAAW,SAAS,aAAa,CAAC;QACxC,MAAM,aAAa,SAAS,KAAK;QACjC,WAAW,KAAK,GAAG;QACnB,WAAW,MAAM,GAAG;QAEpB,SAAS,WAAW,CAAC;QAErB,SAAS,IAAI,CAAC,WAAW,CAAC;QAE1B,IAAI,SAAS,UAAU,GAAG,GACxB,wCAAkB;aACb;YACL,SAAS,UAAU,GAAG;YACtB,IAAI,SAAS,UAAU,KAAK,GAC1B,wCAAkB;iBAElB,wCAAkB;QAEtB;QAEA,SAAS,IAAI,CAAC,WAAW,CAAC;QAE1B,OAAO;IACT;IAEA,OAAO;AACT;AAEO,SAAS,0CAAc,IAAa,EAAE,SAAoB;IAC/D,IAAI,cAAC,UAAU,EAAC,GAAG;IAEnB,mEAAmE;IACnE,qDAAqD;IACrD,IAAI,cAAc,OAAO;QACvB,IAAI,eAAC,WAAW,eAAE,WAAW,EAAC,GAAG;QACjC,OAAQ;YACN,KAAK;gBACH,aAAa,CAAC;gBACd;YACF,KAAK;gBACH,aAAa,cAAc,cAAc;gBACzC;QACJ;IACF;IAEA,OAAO;AACT;AAEO,SAAS,yCAAc,IAAa,EAAE,SAAoB,EAAE,UAAkB;IACnF,IAAI,cAAc,OAChB,OAAQ;QACN,KAAK;YACH,aAAa,CAAC;YACd;QACF,KAAK;YACH;QACF;YAAS;gBACP,MAAM,eAAC,WAAW,eAAE,WAAW,EAAC,GAAG;gBACnC,aAAa,cAAc,cAAc;gBACzC;YACF;IACF;IAGF,KAAK,UAAU,GAAG;AACpB","sources":["packages/@react-aria/virtualizer/src/utils.ts"],"sourcesContent":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {Direction} from '@react-types/shared';\n\nexport type RTLOffsetType =\n | 'negative'\n | 'positive-descending'\n | 'positive-ascending';\n\nlet cachedRTLResult: RTLOffsetType | null = null;\n\n\n// Original licensing for the following methods can be found in the\n// NOTICE file in the root directory of this source tree.\n// See https://github.com/bvaughn/react-window/blob/master/src/createGridComponent.js\n\n// According to the spec, scrollLeft should be negative for RTL aligned elements.\n// Chrome does not seem to adhere; its scrollLeft values are positive (measured relative to the left).\n// Safari's elastic bounce makes detecting this even more complicated wrt potential false positives.\n// The safest way to check this is to intentionally set a negative offset,\n// and then verify that the subsequent \"scroll\" event matches the negative offset.\n// If it does not match, then we can assume a non-standard RTL scroll implementation.\nexport function getRTLOffsetType(recalculate: boolean = false): RTLOffsetType {\n if (cachedRTLResult === null || recalculate) {\n const outerDiv = document.createElement('div');\n const outerStyle = outerDiv.style;\n outerStyle.width = '50px';\n outerStyle.height = '50px';\n outerStyle.overflow = 'scroll';\n outerStyle.direction = 'rtl';\n\n const innerDiv = document.createElement('div');\n const innerStyle = innerDiv.style;\n innerStyle.width = '100px';\n innerStyle.height = '100px';\n\n outerDiv.appendChild(innerDiv);\n\n document.body.appendChild(outerDiv);\n\n if (outerDiv.scrollLeft > 0) {\n cachedRTLResult = 'positive-descending';\n } else {\n outerDiv.scrollLeft = 1;\n if (outerDiv.scrollLeft === 0) {\n cachedRTLResult = 'negative';\n } else {\n cachedRTLResult = 'positive-ascending';\n }\n }\n\n document.body.removeChild(outerDiv);\n\n return cachedRTLResult;\n }\n\n return cachedRTLResult;\n}\n\nexport function getScrollLeft(node: Element, direction: Direction): number {\n let {scrollLeft} = node;\n\n // scrollLeft in rtl locales differs across browsers, so normalize.\n // See comment by getRTLOffsetType below for details.\n if (direction === 'rtl') {\n let {scrollWidth, clientWidth} = node;\n switch (getRTLOffsetType()) {\n case 'negative':\n scrollLeft = -scrollLeft;\n break;\n case 'positive-descending':\n scrollLeft = scrollWidth - clientWidth - scrollLeft;\n break;\n }\n }\n\n return scrollLeft;\n}\n\nexport function setScrollLeft(node: Element, direction: Direction, scrollLeft: number): void {\n if (direction === 'rtl') {\n switch (getRTLOffsetType()) {\n case 'negative':\n scrollLeft = -scrollLeft;\n break;\n case 'positive-ascending':\n break;\n default: {\n const {clientWidth, scrollWidth} = node;\n scrollLeft = scrollWidth - clientWidth - scrollLeft;\n break;\n }\n }\n }\n\n node.scrollLeft = scrollLeft;\n}\n"],"names":[],"version":3,"file":"utils.module.js.map"}
|
package/src/ScrollView.tsx
DELETED
|
@@ -1,282 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Copyright 2020 Adobe. All rights reserved.
|
|
3
|
-
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
4
|
-
* you may not use this file except in compliance with the License. You may obtain a copy
|
|
5
|
-
* of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
6
|
-
*
|
|
7
|
-
* Unless required by applicable law or agreed to in writing, software distributed under
|
|
8
|
-
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
9
|
-
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
10
|
-
* governing permissions and limitations under the License.
|
|
11
|
-
*/
|
|
12
|
-
|
|
13
|
-
// @ts-ignore
|
|
14
|
-
import {flushSync} from 'react-dom';
|
|
15
|
-
import {getEventTarget, useEffectEvent, useEvent, useLayoutEffect, useObjectRef, useResizeObserver} from '@react-aria/utils';
|
|
16
|
-
import {getScrollLeft} from './utils';
|
|
17
|
-
import React, {
|
|
18
|
-
CSSProperties,
|
|
19
|
-
ForwardedRef,
|
|
20
|
-
HTMLAttributes,
|
|
21
|
-
ReactNode,
|
|
22
|
-
RefObject,
|
|
23
|
-
useCallback,
|
|
24
|
-
useEffect,
|
|
25
|
-
useRef,
|
|
26
|
-
useState
|
|
27
|
-
} from 'react';
|
|
28
|
-
import {Rect, Size} from '@react-stately/virtualizer';
|
|
29
|
-
import {useLocale} from '@react-aria/i18n';
|
|
30
|
-
|
|
31
|
-
interface ScrollViewProps extends HTMLAttributes<HTMLElement> {
|
|
32
|
-
contentSize: Size,
|
|
33
|
-
onVisibleRectChange: (rect: Rect) => void,
|
|
34
|
-
children?: ReactNode,
|
|
35
|
-
innerStyle?: CSSProperties,
|
|
36
|
-
onScrollStart?: () => void,
|
|
37
|
-
onScrollEnd?: () => void,
|
|
38
|
-
scrollDirection?: 'horizontal' | 'vertical' | 'both'
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
function ScrollView(props: ScrollViewProps, ref: ForwardedRef<HTMLDivElement | null>) {
|
|
42
|
-
ref = useObjectRef(ref);
|
|
43
|
-
let {scrollViewProps, contentProps} = useScrollView(props, ref);
|
|
44
|
-
|
|
45
|
-
return (
|
|
46
|
-
<div role="presentation" {...scrollViewProps} ref={ref}>
|
|
47
|
-
<div {...contentProps}>
|
|
48
|
-
{props.children}
|
|
49
|
-
</div>
|
|
50
|
-
</div>
|
|
51
|
-
);
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
const ScrollViewForwardRef:
|
|
55
|
-
React.ForwardRefExoticComponent<ScrollViewProps & React.RefAttributes<HTMLDivElement | null>> =
|
|
56
|
-
React.forwardRef(ScrollView);
|
|
57
|
-
export {ScrollViewForwardRef as ScrollView};
|
|
58
|
-
|
|
59
|
-
interface ScrollViewAria {
|
|
60
|
-
isScrolling: boolean,
|
|
61
|
-
scrollViewProps: HTMLAttributes<HTMLElement>,
|
|
62
|
-
contentProps: HTMLAttributes<HTMLElement>
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
export function useScrollView(props: ScrollViewProps, ref: RefObject<HTMLElement | null>): ScrollViewAria {
|
|
66
|
-
let {
|
|
67
|
-
contentSize,
|
|
68
|
-
onVisibleRectChange,
|
|
69
|
-
innerStyle,
|
|
70
|
-
onScrollStart,
|
|
71
|
-
onScrollEnd,
|
|
72
|
-
scrollDirection = 'both',
|
|
73
|
-
...otherProps
|
|
74
|
-
} = props;
|
|
75
|
-
|
|
76
|
-
let state = useRef({
|
|
77
|
-
scrollTop: 0,
|
|
78
|
-
scrollLeft: 0,
|
|
79
|
-
scrollEndTime: 0,
|
|
80
|
-
scrollTimeout: null as ReturnType<typeof setTimeout> | null,
|
|
81
|
-
width: 0,
|
|
82
|
-
height: 0,
|
|
83
|
-
isScrolling: false
|
|
84
|
-
}).current;
|
|
85
|
-
let {direction} = useLocale();
|
|
86
|
-
|
|
87
|
-
let [isScrolling, setScrolling] = useState(false);
|
|
88
|
-
|
|
89
|
-
let onScroll = useCallback((e) => {
|
|
90
|
-
if (getEventTarget(e) !== e.currentTarget) {
|
|
91
|
-
return;
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
if (props.onScroll) {
|
|
95
|
-
props.onScroll(e);
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
flushSync(() => {
|
|
99
|
-
let scrollTop = e.currentTarget.scrollTop;
|
|
100
|
-
let scrollLeft = getScrollLeft(e.currentTarget, direction);
|
|
101
|
-
|
|
102
|
-
// Prevent rubber band scrolling from shaking when scrolling out of bounds
|
|
103
|
-
state.scrollTop = Math.max(0, Math.min(scrollTop, contentSize.height - state.height));
|
|
104
|
-
state.scrollLeft = Math.max(0, Math.min(scrollLeft, contentSize.width - state.width));
|
|
105
|
-
onVisibleRectChange(new Rect(state.scrollLeft, state.scrollTop, state.width, state.height));
|
|
106
|
-
|
|
107
|
-
if (!state.isScrolling) {
|
|
108
|
-
state.isScrolling = true;
|
|
109
|
-
setScrolling(true);
|
|
110
|
-
|
|
111
|
-
// Pause typekit MutationObserver during scrolling.
|
|
112
|
-
window.dispatchEvent(new Event('tk.disconnect-observer'));
|
|
113
|
-
if (onScrollStart) {
|
|
114
|
-
onScrollStart();
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
// So we don't constantly call clearTimeout and setTimeout,
|
|
119
|
-
// keep track of the current timeout time and only reschedule
|
|
120
|
-
// the timer when it is getting close.
|
|
121
|
-
let now = Date.now();
|
|
122
|
-
if (state.scrollEndTime <= now + 50) {
|
|
123
|
-
state.scrollEndTime = now + 300;
|
|
124
|
-
|
|
125
|
-
if (state.scrollTimeout != null) {
|
|
126
|
-
clearTimeout(state.scrollTimeout);
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
state.scrollTimeout = setTimeout(() => {
|
|
130
|
-
state.isScrolling = false;
|
|
131
|
-
setScrolling(false);
|
|
132
|
-
state.scrollTimeout = null;
|
|
133
|
-
|
|
134
|
-
window.dispatchEvent(new Event('tk.connect-observer'));
|
|
135
|
-
if (onScrollEnd) {
|
|
136
|
-
onScrollEnd();
|
|
137
|
-
}
|
|
138
|
-
}, 300);
|
|
139
|
-
}
|
|
140
|
-
});
|
|
141
|
-
}, [props, direction, state, contentSize, onVisibleRectChange, onScrollStart, onScrollEnd]);
|
|
142
|
-
|
|
143
|
-
// Attach event directly to ref so RAC Virtualizer doesn't need to send props upward.
|
|
144
|
-
useEvent(ref, 'scroll', onScroll);
|
|
145
|
-
|
|
146
|
-
useEffect(() => {
|
|
147
|
-
return () => {
|
|
148
|
-
if (state.scrollTimeout != null) {
|
|
149
|
-
clearTimeout(state.scrollTimeout);
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
if (state.isScrolling) {
|
|
153
|
-
window.dispatchEvent(new Event('tk.connect-observer'));
|
|
154
|
-
}
|
|
155
|
-
};
|
|
156
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
157
|
-
}, []);
|
|
158
|
-
|
|
159
|
-
let isUpdatingSize = useRef(false);
|
|
160
|
-
let updateSize = useCallback((flush: typeof flushSync) => {
|
|
161
|
-
let dom = ref.current;
|
|
162
|
-
if (!dom || isUpdatingSize.current) {
|
|
163
|
-
return;
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
// Prevent reentrancy when resize observer fires, triggers re-layout that results in
|
|
167
|
-
// content size update, causing below layout effect to fire. This avoids infinite loops.
|
|
168
|
-
isUpdatingSize.current = true;
|
|
169
|
-
|
|
170
|
-
let isTestEnv = process.env.NODE_ENV === 'test' && !process.env.VIRT_ON;
|
|
171
|
-
let isClientWidthMocked = Object.getOwnPropertyNames(window.HTMLElement.prototype).includes('clientWidth');
|
|
172
|
-
let isClientHeightMocked = Object.getOwnPropertyNames(window.HTMLElement.prototype).includes('clientHeight');
|
|
173
|
-
let clientWidth = dom.clientWidth;
|
|
174
|
-
let clientHeight = dom.clientHeight;
|
|
175
|
-
let w = isTestEnv && !isClientWidthMocked ? Infinity : clientWidth;
|
|
176
|
-
let h = isTestEnv && !isClientHeightMocked ? Infinity : clientHeight;
|
|
177
|
-
|
|
178
|
-
if (state.width !== w || state.height !== h) {
|
|
179
|
-
state.width = w;
|
|
180
|
-
state.height = h;
|
|
181
|
-
flush(() => {
|
|
182
|
-
onVisibleRectChange(new Rect(state.scrollLeft, state.scrollTop, w, h));
|
|
183
|
-
});
|
|
184
|
-
|
|
185
|
-
// If the clientWidth or clientHeight changed, scrollbars appeared or disappeared as
|
|
186
|
-
// a result of the layout update. In this case, re-layout again to account for the
|
|
187
|
-
// adjusted space. In very specific cases this might result in the scrollbars disappearing
|
|
188
|
-
// again, resulting in extra padding. We stop after a maximum of two layout passes to avoid
|
|
189
|
-
// an infinite loop. This matches how browsers behavior with native CSS grid layout.
|
|
190
|
-
if (!isTestEnv && clientWidth !== dom.clientWidth || clientHeight !== dom.clientHeight) {
|
|
191
|
-
state.width = dom.clientWidth;
|
|
192
|
-
state.height = dom.clientHeight;
|
|
193
|
-
flush(() => {
|
|
194
|
-
onVisibleRectChange(new Rect(state.scrollLeft, state.scrollTop, state.width, state.height));
|
|
195
|
-
});
|
|
196
|
-
}
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
isUpdatingSize.current = false;
|
|
200
|
-
}, [ref, state, onVisibleRectChange]);
|
|
201
|
-
let updateSizeEvent = useEffectEvent(updateSize);
|
|
202
|
-
|
|
203
|
-
// Update visible rect when the content size changes, in case scrollbars need to appear or disappear.
|
|
204
|
-
let lastContentSize = useRef<Size | null>(null);
|
|
205
|
-
let [update, setUpdate] = useState({});
|
|
206
|
-
// We only contain a call to setState in here for testing environments.
|
|
207
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
208
|
-
useLayoutEffect(() => {
|
|
209
|
-
if (!isUpdatingSize.current && (lastContentSize.current == null || !contentSize.equals(lastContentSize.current))) {
|
|
210
|
-
// React doesn't allow flushSync inside effects, so queue a microtask.
|
|
211
|
-
// We also need to wait until all refs are set (e.g. when passing a ref down from a parent).
|
|
212
|
-
// If we are in an `act` environment, update immediately without a microtask so you don't need
|
|
213
|
-
// to mock timers in tests. In this case, the update is synchronous already.
|
|
214
|
-
// IS_REACT_ACT_ENVIRONMENT is used by React 18. Previous versions checked for the `jest` global.
|
|
215
|
-
// https://github.com/reactwg/react-18/discussions/102
|
|
216
|
-
// @ts-ignore
|
|
217
|
-
if (typeof IS_REACT_ACT_ENVIRONMENT === 'boolean' ? IS_REACT_ACT_ENVIRONMENT : typeof jest !== 'undefined') {
|
|
218
|
-
// This is so we update size in a separate render but within the same act. Needs to be setState instead of refs
|
|
219
|
-
// due to strict mode.
|
|
220
|
-
setUpdate({});
|
|
221
|
-
lastContentSize.current = contentSize;
|
|
222
|
-
return;
|
|
223
|
-
} else {
|
|
224
|
-
queueMicrotask(() => updateSizeEvent(flushSync));
|
|
225
|
-
}
|
|
226
|
-
}
|
|
227
|
-
|
|
228
|
-
lastContentSize.current = contentSize;
|
|
229
|
-
});
|
|
230
|
-
|
|
231
|
-
// Will only run in tests, needs to be in separate effect so it is properly run in the next render in strict mode.
|
|
232
|
-
useLayoutEffect(() => {
|
|
233
|
-
updateSizeEvent(fn => fn());
|
|
234
|
-
}, [update]);
|
|
235
|
-
|
|
236
|
-
let onResize = useCallback(() => {
|
|
237
|
-
updateSize(flushSync);
|
|
238
|
-
}, [updateSize]);
|
|
239
|
-
|
|
240
|
-
// Watch border-box instead of of content-box so that we don't go into
|
|
241
|
-
// an infinite loop when scrollbars appear or disappear.
|
|
242
|
-
useResizeObserver({ref, box: 'border-box', onResize});
|
|
243
|
-
|
|
244
|
-
let style: React.CSSProperties = {
|
|
245
|
-
// Reset padding so that relative positioning works correctly. Padding will be done in JS layout.
|
|
246
|
-
padding: 0,
|
|
247
|
-
...otherProps.style
|
|
248
|
-
};
|
|
249
|
-
|
|
250
|
-
if (scrollDirection === 'horizontal') {
|
|
251
|
-
style.overflowX = 'auto';
|
|
252
|
-
style.overflowY = 'hidden';
|
|
253
|
-
} else if (scrollDirection === 'vertical' || contentSize.width === state.width) {
|
|
254
|
-
// Set overflow-x: hidden if content size is equal to the width of the scroll view.
|
|
255
|
-
// This prevents horizontal scrollbars from flickering during resizing due to resize observer
|
|
256
|
-
// firing slower than the frame rate, which may cause an infinite re-render loop.
|
|
257
|
-
style.overflowY = 'auto';
|
|
258
|
-
style.overflowX = 'hidden';
|
|
259
|
-
} else {
|
|
260
|
-
style.overflow = 'auto';
|
|
261
|
-
}
|
|
262
|
-
|
|
263
|
-
innerStyle = {
|
|
264
|
-
width: Number.isFinite(contentSize.width) ? contentSize.width : undefined,
|
|
265
|
-
height: Number.isFinite(contentSize.height) ? contentSize.height : undefined,
|
|
266
|
-
pointerEvents: isScrolling ? 'none' : 'auto',
|
|
267
|
-
position: 'relative',
|
|
268
|
-
...innerStyle
|
|
269
|
-
};
|
|
270
|
-
|
|
271
|
-
return {
|
|
272
|
-
isScrolling,
|
|
273
|
-
scrollViewProps: {
|
|
274
|
-
...otherProps,
|
|
275
|
-
style
|
|
276
|
-
},
|
|
277
|
-
contentProps: {
|
|
278
|
-
role: 'presentation',
|
|
279
|
-
style: innerStyle
|
|
280
|
-
}
|
|
281
|
-
};
|
|
282
|
-
}
|
package/src/Virtualizer.tsx
DELETED
|
@@ -1,113 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Copyright 2020 Adobe. All rights reserved.
|
|
3
|
-
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
4
|
-
* you may not use this file except in compliance with the License. You may obtain a copy
|
|
5
|
-
* of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
6
|
-
*
|
|
7
|
-
* Unless required by applicable law or agreed to in writing, software distributed under
|
|
8
|
-
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
9
|
-
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
10
|
-
* governing permissions and limitations under the License.
|
|
11
|
-
*/
|
|
12
|
-
|
|
13
|
-
import {Collection, Key, RefObject} from '@react-types/shared';
|
|
14
|
-
import {Layout, Rect, ReusableView, useVirtualizerState} from '@react-stately/virtualizer';
|
|
15
|
-
import {mergeProps, useLoadMore, useObjectRef} from '@react-aria/utils';
|
|
16
|
-
import React, {ForwardedRef, HTMLAttributes, ReactElement, ReactNode, useCallback} from 'react';
|
|
17
|
-
import {ScrollView} from './ScrollView';
|
|
18
|
-
import {VirtualizerItem} from './VirtualizerItem';
|
|
19
|
-
|
|
20
|
-
type RenderWrapper<T extends object, V> = (
|
|
21
|
-
parent: ReusableView<T, V> | null,
|
|
22
|
-
reusableView: ReusableView<T, V>,
|
|
23
|
-
children: ReusableView<T, V>[],
|
|
24
|
-
renderChildren: (views: ReusableView<T, V>[]) => ReactElement[]
|
|
25
|
-
) => ReactElement | null;
|
|
26
|
-
|
|
27
|
-
interface VirtualizerProps<T extends object, V, O> extends Omit<HTMLAttributes<HTMLElement>, 'children'> {
|
|
28
|
-
children: (type: string, content: T) => V,
|
|
29
|
-
renderWrapper?: RenderWrapper<T, V>,
|
|
30
|
-
layout: Layout<T, O>,
|
|
31
|
-
collection: Collection<T>,
|
|
32
|
-
persistedKeys?: Set<Key> | null,
|
|
33
|
-
scrollDirection?: 'horizontal' | 'vertical' | 'both',
|
|
34
|
-
isLoading?: boolean,
|
|
35
|
-
onLoadMore?: () => void,
|
|
36
|
-
layoutOptions?: O
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
// forwardRef doesn't support generic parameters, so cast the result to the correct type
|
|
40
|
-
// https://stackoverflow.com/questions/58469229/react-with-typescript-generics-while-using-react-forwardref
|
|
41
|
-
export const Virtualizer = React.forwardRef(function Virtualizer<T extends object, V extends ReactNode, O>(props: VirtualizerProps<T, V, O>, forwardedRef: ForwardedRef<HTMLDivElement | null>) {
|
|
42
|
-
let {
|
|
43
|
-
children: renderView,
|
|
44
|
-
renderWrapper,
|
|
45
|
-
layout,
|
|
46
|
-
collection,
|
|
47
|
-
scrollDirection,
|
|
48
|
-
isLoading,
|
|
49
|
-
onLoadMore,
|
|
50
|
-
persistedKeys,
|
|
51
|
-
layoutOptions,
|
|
52
|
-
...otherProps
|
|
53
|
-
} = props;
|
|
54
|
-
|
|
55
|
-
let ref = useObjectRef(forwardedRef);
|
|
56
|
-
|
|
57
|
-
let state = useVirtualizerState({
|
|
58
|
-
layout,
|
|
59
|
-
collection,
|
|
60
|
-
renderView,
|
|
61
|
-
onVisibleRectChange(rect) {
|
|
62
|
-
if (ref.current) {
|
|
63
|
-
ref.current.scrollLeft = rect.x;
|
|
64
|
-
ref.current.scrollTop = rect.y;
|
|
65
|
-
}
|
|
66
|
-
},
|
|
67
|
-
persistedKeys,
|
|
68
|
-
layoutOptions
|
|
69
|
-
});
|
|
70
|
-
|
|
71
|
-
useLoadMore({isLoading, onLoadMore, scrollOffset: 1}, ref);
|
|
72
|
-
let onVisibleRectChange = useCallback((rect: Rect) => {
|
|
73
|
-
state.setVisibleRect(rect);
|
|
74
|
-
}, [state]);
|
|
75
|
-
|
|
76
|
-
return (
|
|
77
|
-
<ScrollView
|
|
78
|
-
{...mergeProps(otherProps, {onVisibleRectChange})}
|
|
79
|
-
ref={ref}
|
|
80
|
-
contentSize={state.contentSize}
|
|
81
|
-
onScrollStart={state.startScrolling}
|
|
82
|
-
onScrollEnd={state.endScrolling}
|
|
83
|
-
scrollDirection={scrollDirection}>
|
|
84
|
-
{renderChildren(null, state.visibleViews, renderWrapper || defaultRenderWrapper)}
|
|
85
|
-
</ScrollView>
|
|
86
|
-
);
|
|
87
|
-
}) as <T extends object, V, O>(props: VirtualizerProps<T, V, O> & {ref?: RefObject<HTMLDivElement | null>}) => ReactElement;
|
|
88
|
-
|
|
89
|
-
function renderChildren<T extends object, V>(parent: ReusableView<T, V> | null, views: ReusableView<T, V>[], renderWrapper: RenderWrapper<T, V>) {
|
|
90
|
-
return views.map(view => {
|
|
91
|
-
return renderWrapper(
|
|
92
|
-
parent,
|
|
93
|
-
view,
|
|
94
|
-
view.children ? Array.from(view.children) : [],
|
|
95
|
-
childViews => renderChildren(view, childViews, renderWrapper)
|
|
96
|
-
);
|
|
97
|
-
});
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
function defaultRenderWrapper<T extends object, V extends ReactNode>(
|
|
101
|
-
parent: ReusableView<T, V> | null,
|
|
102
|
-
reusableView: ReusableView<T, V>
|
|
103
|
-
) {
|
|
104
|
-
return (
|
|
105
|
-
<VirtualizerItem
|
|
106
|
-
key={reusableView.key}
|
|
107
|
-
layoutInfo={reusableView.layoutInfo!}
|
|
108
|
-
virtualizer={reusableView.virtualizer}
|
|
109
|
-
parent={parent?.layoutInfo}>
|
|
110
|
-
{reusableView.rendered}
|
|
111
|
-
</VirtualizerItem>
|
|
112
|
-
);
|
|
113
|
-
}
|