@tarojs/components 3.6.0-canary.6 → 3.6.0-canary.7
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/react/component-lib/input.js +1 -1
- package/dist/react/component-lib/reactify-wc.js +3 -3
- package/dist/react/react-component-lib/createComponent.js +1 -1
- package/dist/react/react-component-lib/createOverlayComponent.js +6 -8
- package/dist/react/react-component-lib/utils/index.js +6 -7
- package/package.json +4 -3
- package/virtual-list/index.d.ts +3 -120
- package/virtual-list/index.js +3 -7
- package/virtual-list/domHelpers.js +0 -40
- package/virtual-list/memoize.js +0 -38
- package/virtual-list/react/FixedSizeList.js +0 -193
- package/virtual-list/react/createListComponent.js +0 -654
- package/virtual-list/react/index.d.ts +0 -123
- package/virtual-list/react/index.js +0 -67
- package/virtual-list/timer.js +0 -24
- package/virtual-list/vue/index.js +0 -589
|
@@ -4,7 +4,7 @@ import reactifyWc from './reactify-wc';
|
|
|
4
4
|
var Input = reactifyWc('taro-input-core');
|
|
5
5
|
var h = React.createElement; // eslint-disable-next-line react/display-name
|
|
6
6
|
|
|
7
|
-
export default React.forwardRef(function (props, ref) {
|
|
7
|
+
export default /*#__PURE__*/React.forwardRef(function (props, ref) {
|
|
8
8
|
var args = _objectSpread({}, props);
|
|
9
9
|
|
|
10
10
|
if (args.hasOwnProperty('focus')) {
|
|
@@ -154,7 +154,7 @@ var reactifyWebComponent = function reactifyWebComponent(WC) {
|
|
|
154
154
|
_defineProperty(_assertThisInitialized(_this), "ref", void 0);
|
|
155
155
|
|
|
156
156
|
_this.eventHandlers = [];
|
|
157
|
-
_this.ref = createRef();
|
|
157
|
+
_this.ref = /*#__PURE__*/createRef();
|
|
158
158
|
return _this;
|
|
159
159
|
}
|
|
160
160
|
|
|
@@ -225,7 +225,7 @@ var reactifyWebComponent = function reactifyWebComponent(WC) {
|
|
|
225
225
|
ref: this.ref
|
|
226
226
|
};
|
|
227
227
|
if (dangerouslySetInnerHTML) props.dangerouslySetInnerHTML = dangerouslySetInnerHTML;
|
|
228
|
-
return createElement(WC, props, children);
|
|
228
|
+
return /*#__PURE__*/createElement(WC, props, children);
|
|
229
229
|
}
|
|
230
230
|
}]);
|
|
231
231
|
|
|
@@ -233,7 +233,7 @@ var reactifyWebComponent = function reactifyWebComponent(WC) {
|
|
|
233
233
|
}(React.Component); // eslint-disable-next-line react/display-name
|
|
234
234
|
|
|
235
235
|
|
|
236
|
-
return React.forwardRef(function (props, ref) {
|
|
236
|
+
return /*#__PURE__*/React.forwardRef(function (props, ref) {
|
|
237
237
|
return h(Index, _objectSpread(_objectSpread({}, props), {}, {
|
|
238
238
|
forwardRef: ref
|
|
239
239
|
}));
|
|
@@ -98,7 +98,7 @@ export var createReactComponent = function createReactComponent(tagName, ReactCo
|
|
|
98
98
|
*/
|
|
99
99
|
|
|
100
100
|
|
|
101
|
-
return createElement(tagName, newProps, children);
|
|
101
|
+
return /*#__PURE__*/createElement(tagName, newProps, children);
|
|
102
102
|
}
|
|
103
103
|
}], [{
|
|
104
104
|
key: "displayName",
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import _mergeJSXProps from "@vue/babel-helper-vue-jsx-merge-props";
|
|
2
1
|
import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
|
|
3
2
|
import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
|
|
4
3
|
import _regeneratorRuntime from "@babel/runtime/helpers/esm/regeneratorRuntime";
|
|
@@ -13,6 +12,7 @@ var _excluded = ["children", "isOpen", "onDidDismiss", "onDidPresent", "onWillDi
|
|
|
13
12
|
import React from 'react';
|
|
14
13
|
import ReactDOM from 'react-dom';
|
|
15
14
|
import { attachProps, dashToPascalCase, defineCustomElement, setRef } from './utils';
|
|
15
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
16
16
|
export var createOverlayComponent = function createOverlayComponent(tagName, controller, customElement) {
|
|
17
17
|
defineCustomElement(tagName, customElement);
|
|
18
18
|
var displayName = dashToPascalCase(tagName);
|
|
@@ -185,7 +185,7 @@ export var createOverlayComponent = function createOverlayComponent(tagName, con
|
|
|
185
185
|
* overlay is dismissing otherwise component
|
|
186
186
|
* will be hidden before animation is done.
|
|
187
187
|
*/
|
|
188
|
-
return ReactDOM.createPortal(this.props.isOpen || isDismissing ? this.props.children : null, this.el);
|
|
188
|
+
return /*#__PURE__*/ReactDOM.createPortal(this.props.isOpen || isDismissing ? this.props.children : null, this.el);
|
|
189
189
|
}
|
|
190
190
|
}], [{
|
|
191
191
|
key: "displayName",
|
|
@@ -197,11 +197,9 @@ export var createOverlayComponent = function createOverlayComponent(tagName, con
|
|
|
197
197
|
return Overlay;
|
|
198
198
|
}(React.Component);
|
|
199
199
|
|
|
200
|
-
return React.forwardRef(function (props, ref) {
|
|
201
|
-
return
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
}
|
|
205
|
-
}]));
|
|
200
|
+
return /*#__PURE__*/React.forwardRef(function (props, ref) {
|
|
201
|
+
return /*#__PURE__*/_jsx(Overlay, _objectSpread(_objectSpread({}, props), {}, {
|
|
202
|
+
forwardedRef: ref
|
|
203
|
+
}));
|
|
206
204
|
});
|
|
207
205
|
};
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import
|
|
1
|
+
import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
|
|
2
2
|
import React from 'react';
|
|
3
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
4
|
export var setRef = function setRef(ref, value) {
|
|
4
5
|
if (typeof ref === 'function') {
|
|
5
6
|
ref(value);
|
|
@@ -21,15 +22,13 @@ export var mergeRefs = function mergeRefs() {
|
|
|
21
22
|
};
|
|
22
23
|
export var createForwardRef = function createForwardRef(ReactComponent, displayName) {
|
|
23
24
|
var forwardRef = function forwardRef(props, ref) {
|
|
24
|
-
return
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
}
|
|
28
|
-
}]));
|
|
25
|
+
return /*#__PURE__*/_jsx(ReactComponent, _objectSpread(_objectSpread({}, props), {}, {
|
|
26
|
+
forwardedRef: ref
|
|
27
|
+
}));
|
|
29
28
|
};
|
|
30
29
|
|
|
31
30
|
forwardRef.displayName = displayName;
|
|
32
|
-
return React.forwardRef(forwardRef);
|
|
31
|
+
return /*#__PURE__*/React.forwardRef(forwardRef);
|
|
33
32
|
};
|
|
34
33
|
export var defineCustomElement = function defineCustomElement(tagName, customElement) {
|
|
35
34
|
if (customElement !== undefined && typeof customElements !== 'undefined' && !customElements.get(tagName)) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tarojs/components",
|
|
3
|
-
"version": "3.6.0-canary.
|
|
3
|
+
"version": "3.6.0-canary.7",
|
|
4
4
|
"description": "Taro 组件库",
|
|
5
5
|
"browser": "dist/index.js",
|
|
6
6
|
"main:h5": "dist/index.js",
|
|
@@ -35,8 +35,9 @@
|
|
|
35
35
|
"resolve-pathname": "^3.0.0",
|
|
36
36
|
"swiper": "6.8.0",
|
|
37
37
|
"weui": "^1.1.2",
|
|
38
|
-
"@tarojs/
|
|
39
|
-
"@tarojs/
|
|
38
|
+
"@tarojs/components-advanced": "3.6.0-canary.7",
|
|
39
|
+
"@tarojs/router": "3.6.0-canary.7",
|
|
40
|
+
"@tarojs/taro": "3.6.0-canary.7"
|
|
40
41
|
},
|
|
41
42
|
"devDependencies": {
|
|
42
43
|
"@babel/generator": "^7.14.5",
|
package/virtual-list/index.d.ts
CHANGED
|
@@ -1,121 +1,4 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { StandardProps, BaseEventOrigFunction } from '../types/common'
|
|
3
|
-
import { ScrollViewProps } from '../types/ScrollView'
|
|
1
|
+
import VirtualList from '@tarojs/components-advanced/dist/components/virtual-list/index'
|
|
4
2
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
height: string | number
|
|
8
|
-
/** 列表的宽度。 */
|
|
9
|
-
width: string | number
|
|
10
|
-
/** 列表的长度 */
|
|
11
|
-
itemCount: number
|
|
12
|
-
/** 渲染数据 */
|
|
13
|
-
itemData: any[]
|
|
14
|
-
/** 列表单项的大小,垂直滚动时为高度,水平滚动时为宽度。 */
|
|
15
|
-
itemSize: number
|
|
16
|
-
/** 解开高度列表单项大小限制,默认值使用: itemSize (请注意,初始高度与实际高度差异过大会导致隐患)。 */
|
|
17
|
-
unlimitedSize?: boolean
|
|
18
|
-
/** 布局方式,默认采用 "absolute" */
|
|
19
|
-
position?: 'absolute' | 'relative'
|
|
20
|
-
/** 初始滚动偏移值,水平滚动影响 scrollLeft,垂直滚动影响 scrollTop。 */
|
|
21
|
-
initialScrollOffset?: number
|
|
22
|
-
/** 列表内部容器组件类型,默认值为 View。 */
|
|
23
|
-
innerElementType?: ComponentType
|
|
24
|
-
/** 底部区域 */
|
|
25
|
-
renderBottom?: ReactNode
|
|
26
|
-
/** 滚动方向。vertical 为垂直滚动,horizontal 为平行滚动。默认为 vertical。 */
|
|
27
|
-
layout?: 'vertical' | 'horizontal'
|
|
28
|
-
/** 列表滚动时调用函数 */
|
|
29
|
-
onScroll?: (event: VirtualListEvent<VirtualListProps.onScrollDetail>) => void
|
|
30
|
-
/** 调用平台原生的滚动监听函数。 */
|
|
31
|
-
onScrollNative?: BaseEventOrigFunction<ScrollViewProps.onScrollDetail>
|
|
32
|
-
/** 在可视区域之外渲染的列表单项数量,值设置得越高,快速滚动时出现白屏的概率就越小,相应地,每次滚动的性能会变得越差。 */
|
|
33
|
-
overscanCount?: number
|
|
34
|
-
/** 是否注入 isScrolling 属性到 children 组件。这个参数一般用于实现滚动骨架屏(或其它 placeholder) 时比较有用。 */
|
|
35
|
-
useIsScrolling?: boolean
|
|
36
|
-
children?: ComponentType<{
|
|
37
|
-
/** 组件 ID */
|
|
38
|
-
id: string
|
|
39
|
-
/** 单项的样式,样式必须传入组件的 style 中 */
|
|
40
|
-
style?: CSSProperties
|
|
41
|
-
/** 组件渲染的数据 */
|
|
42
|
-
data: any
|
|
43
|
-
/** 组件渲染数据的索引 */
|
|
44
|
-
index: number
|
|
45
|
-
/** 组件是否正在滚动,当 useIsScrolling 值为 true 时返回布尔值,否则返回 undefined */
|
|
46
|
-
isScrolling?: boolean
|
|
47
|
-
}>
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
declare namespace VirtualListProps {
|
|
51
|
-
// eslint-disable-next-line @typescript-eslint/class-name-casing
|
|
52
|
-
interface onScrollDetail {
|
|
53
|
-
clientWidth: number
|
|
54
|
-
clientHeight: number
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
interface VirtualListEvent<T> {
|
|
59
|
-
/** 滚动方向,可能值为 forward 往前, backward 往后。 */
|
|
60
|
-
scrollDirection: 'forward' | 'backward'
|
|
61
|
-
/** 滚动距离 */
|
|
62
|
-
scrollOffset: number
|
|
63
|
-
/** 当滚动是由 scrollTo() 或 scrollToItem() 调用时返回 true,否则返回 false */
|
|
64
|
-
scrollUpdateWasRequested: boolean
|
|
65
|
-
/** 当前只有 React 支持 */
|
|
66
|
-
detail?: {
|
|
67
|
-
scrollLeft: number
|
|
68
|
-
scrollTop: number
|
|
69
|
-
scrollHeight: number
|
|
70
|
-
scrollWidth: number
|
|
71
|
-
clientWidth: number
|
|
72
|
-
clientHeight: number
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
/**
|
|
77
|
-
* @classification viewContainer
|
|
78
|
-
* @supported weapp, swan, alipay, tt, qq, jd, h5
|
|
79
|
-
* @example
|
|
80
|
-
* ```tsx
|
|
81
|
-
* import VirtualList from `@tarojs/components/virtual-list`
|
|
82
|
-
*
|
|
83
|
-
* function buildData (offset = 0) {
|
|
84
|
-
* return Array(100).fill(0).map((_, i) => i + offset);
|
|
85
|
-
* }
|
|
86
|
-
*
|
|
87
|
-
* const Row = React.memo(({ id, index, style, data }) => {
|
|
88
|
-
* return (
|
|
89
|
-
* <View id={id} className={index % 2 ? 'ListItemOdd' : 'ListItemEven'} style={style}>
|
|
90
|
-
* Row {index}
|
|
91
|
-
* </View>
|
|
92
|
-
* );
|
|
93
|
-
* })
|
|
94
|
-
*
|
|
95
|
-
* export default class Index extends Component {
|
|
96
|
-
* state = {
|
|
97
|
-
* data: buildData(0),
|
|
98
|
-
* }
|
|
99
|
-
*
|
|
100
|
-
* render() {
|
|
101
|
-
* const { data } = this.state
|
|
102
|
-
* const dataLen = data.length
|
|
103
|
-
* return (
|
|
104
|
-
* <VirtualList
|
|
105
|
-
* height={500} // 列表的高度
|
|
106
|
-
* width='100%' // 列表的宽度
|
|
107
|
-
* itemData={data} // 渲染列表的数据
|
|
108
|
-
* itemCount={dataLen} // 渲染列表的长度
|
|
109
|
-
* itemSize={100} // 列表单项的高度
|
|
110
|
-
* >
|
|
111
|
-
* {Row} // 列表单项组件,这里只能传入一个组件
|
|
112
|
-
* </VirtualList>
|
|
113
|
-
* );
|
|
114
|
-
* }
|
|
115
|
-
* }
|
|
116
|
-
* ```
|
|
117
|
-
* @see https://taro-docs.jd.com/taro/docs/virtual-list/
|
|
118
|
-
*/
|
|
119
|
-
declare class VirtualList extends Component<VirtualListProps> {}
|
|
120
|
-
|
|
121
|
-
export = VirtualList
|
|
3
|
+
export * from '@tarojs/components-advanced/dist/components/virtual-list/index'
|
|
4
|
+
export default VirtualList
|
package/virtual-list/index.js
CHANGED
|
@@ -1,7 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
} else {
|
|
5
|
-
module.exports = require('./react').default
|
|
6
|
-
module.exports.default = module.exports
|
|
7
|
-
}
|
|
1
|
+
module.exports = require('@tarojs/components-advanced/dist/components/virtual-list/index.js').default
|
|
2
|
+
|
|
3
|
+
module.exports.default = module.exports
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
let cachedRTLResult = null // TRICKY According to the spec, scrollLeft should be negative for RTL aligned elements.
|
|
2
|
-
// Chrome does not seem to adhere; its scrollLeft values are positive (measured relative to the left).
|
|
3
|
-
// Safari's elastic bounce makes detecting this even more complicated wrt potential false positives.
|
|
4
|
-
// The safest way to check this is to intentionally set a negative offset,
|
|
5
|
-
// and then verify that the subsequent "scroll" event matches the negative offset.
|
|
6
|
-
// If it does not match, then we can assume a non-standard RTL scroll implementation.
|
|
7
|
-
|
|
8
|
-
export function getRTLOffsetType (recalculate = false) {
|
|
9
|
-
if (cachedRTLResult === null || recalculate) {
|
|
10
|
-
const outerDiv = document.createElement('div')
|
|
11
|
-
const outerStyle = outerDiv.style
|
|
12
|
-
outerStyle.width = '50px'
|
|
13
|
-
outerStyle.height = '50px'
|
|
14
|
-
outerStyle.overflow = 'scroll'
|
|
15
|
-
outerStyle.direction = 'rtl'
|
|
16
|
-
const innerDiv = document.createElement('div')
|
|
17
|
-
const innerStyle = innerDiv.style
|
|
18
|
-
innerStyle.width = '100px'
|
|
19
|
-
innerStyle.height = '100px'
|
|
20
|
-
outerDiv.appendChild(innerDiv)
|
|
21
|
-
document.body.appendChild(outerDiv)
|
|
22
|
-
|
|
23
|
-
if (outerDiv.scrollLeft > 0) {
|
|
24
|
-
cachedRTLResult = 'positive-descending'
|
|
25
|
-
} else {
|
|
26
|
-
outerDiv.scrollLeft = 1
|
|
27
|
-
|
|
28
|
-
if (outerDiv.scrollLeft === 0) {
|
|
29
|
-
cachedRTLResult = 'negative'
|
|
30
|
-
} else {
|
|
31
|
-
cachedRTLResult = 'positive-ascending'
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
document.body.removeChild(outerDiv)
|
|
36
|
-
return cachedRTLResult
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
return cachedRTLResult
|
|
40
|
-
}
|
package/virtual-list/memoize.js
DELETED
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
// https://github.com/alexreardon/memoize-one#readme
|
|
2
|
-
|
|
3
|
-
function areInputsEqual (newInputs, lastInputs) {
|
|
4
|
-
if (newInputs.length !== lastInputs.length) {
|
|
5
|
-
return false
|
|
6
|
-
}
|
|
7
|
-
for (let i = 0; i < newInputs.length; i++) {
|
|
8
|
-
if (newInputs[i] !== lastInputs[i]) {
|
|
9
|
-
return false
|
|
10
|
-
}
|
|
11
|
-
}
|
|
12
|
-
return true
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
export function memoizeOne (resultFn, isEqual) {
|
|
16
|
-
// eslint-disable-next-line no-void
|
|
17
|
-
if (isEqual === void 0) { isEqual = areInputsEqual }
|
|
18
|
-
let lastThis
|
|
19
|
-
let lastArgs = []
|
|
20
|
-
let lastResult
|
|
21
|
-
let calledOnce = false
|
|
22
|
-
function memoized () {
|
|
23
|
-
const newArgs = []
|
|
24
|
-
for (let _i = 0; _i < arguments.length; _i++) {
|
|
25
|
-
newArgs[_i] = arguments[_i]
|
|
26
|
-
}
|
|
27
|
-
if (calledOnce && lastThis === this && isEqual(newArgs, lastArgs)) {
|
|
28
|
-
return lastResult
|
|
29
|
-
}
|
|
30
|
-
lastResult = resultFn.apply(this, newArgs)
|
|
31
|
-
calledOnce = true
|
|
32
|
-
// eslint-disable-next-line @typescript-eslint/no-this-alias
|
|
33
|
-
lastThis = this
|
|
34
|
-
lastArgs = newArgs
|
|
35
|
-
return lastResult
|
|
36
|
-
}
|
|
37
|
-
return memoized
|
|
38
|
-
}
|
|
@@ -1,193 +0,0 @@
|
|
|
1
|
-
import createListComponent, { isHorizontalFunc } from './createListComponent'
|
|
2
|
-
|
|
3
|
-
let devWarningsDirection = null
|
|
4
|
-
let devWarningsTagName = null
|
|
5
|
-
|
|
6
|
-
if (process.env.NODE_ENV !== 'production') {
|
|
7
|
-
if (typeof window !== 'undefined' && typeof window.WeakSet !== 'undefined') {
|
|
8
|
-
devWarningsDirection =
|
|
9
|
-
/* #__PURE__ */
|
|
10
|
-
new WeakSet()
|
|
11
|
-
devWarningsTagName =
|
|
12
|
-
/* #__PURE__ */
|
|
13
|
-
new WeakSet()
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
const validateSharedProps = ({
|
|
18
|
-
children,
|
|
19
|
-
direction,
|
|
20
|
-
height,
|
|
21
|
-
layout,
|
|
22
|
-
itemTagName,
|
|
23
|
-
innerTagName,
|
|
24
|
-
outerTagName,
|
|
25
|
-
width
|
|
26
|
-
}, {
|
|
27
|
-
instance
|
|
28
|
-
}) => {
|
|
29
|
-
if (process.env.NODE_ENV !== 'production') {
|
|
30
|
-
if (innerTagName != null || outerTagName != null || itemTagName != null) {
|
|
31
|
-
if (devWarningsTagName && !devWarningsTagName.has(instance)) {
|
|
32
|
-
devWarningsTagName.add(instance)
|
|
33
|
-
console.warn('The itemTagName、innerTagName and outerTagName props have been deprecated. ' + 'Please use the itemElementType、innerElementType and outerElementType props instead.')
|
|
34
|
-
}
|
|
35
|
-
} // TODO Deprecate direction "horizontal"
|
|
36
|
-
|
|
37
|
-
const isHorizontal = direction === 'horizontal' || layout === 'horizontal'
|
|
38
|
-
|
|
39
|
-
switch (direction) {
|
|
40
|
-
case 'horizontal':
|
|
41
|
-
case 'vertical':
|
|
42
|
-
if (devWarningsDirection && !devWarningsDirection.has(instance)) {
|
|
43
|
-
devWarningsDirection.add(instance)
|
|
44
|
-
console.warn('The direction prop should be either "ltr" (default) or "rtl". ' + 'Please use the layout prop to specify "vertical" (default) or "horizontal" orientation.')
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
break
|
|
48
|
-
|
|
49
|
-
case 'ltr':
|
|
50
|
-
case 'rtl':
|
|
51
|
-
// Valid values
|
|
52
|
-
break
|
|
53
|
-
|
|
54
|
-
default:
|
|
55
|
-
throw Error('An invalid "direction" prop has been specified. ' + 'Value should be either "ltr" or "rtl". ' + `"${direction}" was specified.`)
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
switch (layout) {
|
|
59
|
-
case 'horizontal':
|
|
60
|
-
case 'vertical':
|
|
61
|
-
// Valid values
|
|
62
|
-
break
|
|
63
|
-
|
|
64
|
-
default:
|
|
65
|
-
throw Error('An invalid "layout" prop has been specified. ' + 'Value should be either "horizontal" or "vertical". ' + `"${layout}" was specified.`)
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
if (children == null) {
|
|
69
|
-
throw Error('An invalid "children" prop has been specified. ' + 'Value should be a React component. ' + `"${children === null ? 'null' : typeof children}" was specified.`)
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
if (isHorizontal && typeof width !== 'number') {
|
|
73
|
-
throw Error('An invalid "width" prop has been specified. ' + 'Horizontal lists must specify a number for width. ' + `"${width === null ? 'null' : typeof width}" was specified.`)
|
|
74
|
-
} else if (!isHorizontal && typeof height !== 'number') {
|
|
75
|
-
throw Error('An invalid "height" prop has been specified. ' + 'Vertical lists must specify a number for height. ' + `"${height === null ? 'null' : typeof height}" was specified.`)
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
const FixedSizeList =
|
|
81
|
-
/* #__PURE__ */
|
|
82
|
-
createListComponent({
|
|
83
|
-
getItemOffset (props, index, ref) {
|
|
84
|
-
if (!props.unlimitedSize) {
|
|
85
|
-
return index * props.itemSize
|
|
86
|
-
}
|
|
87
|
-
return ref._getCountSize(props, index)
|
|
88
|
-
},
|
|
89
|
-
getItemSize (props, index, ref) {
|
|
90
|
-
if (!props.unlimitedSize) {
|
|
91
|
-
return props.itemSize
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
return ref._getSizeUpload(index, isHorizontalFunc(props))
|
|
95
|
-
},
|
|
96
|
-
getEstimatedTotalSize (props, ref) {
|
|
97
|
-
return ref._getCountSize(props, props.itemCount)
|
|
98
|
-
},
|
|
99
|
-
getOffsetForIndexAndAlignment: (props, id, index, align, scrollOffset, ref) => {
|
|
100
|
-
const { height, width } = props
|
|
101
|
-
const { sizeList } = ref.state
|
|
102
|
-
// TODO Deprecate direction "horizontal"
|
|
103
|
-
const size = isHorizontalFunc(props) ? width : height
|
|
104
|
-
const itemSize = ref._getSize(sizeList[index])
|
|
105
|
-
const lastItemOffset = Math.max(0, ref._getCountSize(props, props.itemCount) - size)
|
|
106
|
-
const maxOffset = Math.min(lastItemOffset, ref._getCountSize(props, index))
|
|
107
|
-
const minOffset = Math.max(0, ref._getCountSize(props, index) - size + itemSize)
|
|
108
|
-
|
|
109
|
-
if (align === 'smart') {
|
|
110
|
-
if (scrollOffset >= minOffset - size && scrollOffset <= maxOffset + size) {
|
|
111
|
-
align = 'auto'
|
|
112
|
-
} else {
|
|
113
|
-
align = 'center'
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
switch (align) {
|
|
118
|
-
case 'start':
|
|
119
|
-
return maxOffset
|
|
120
|
-
|
|
121
|
-
case 'end':
|
|
122
|
-
return minOffset
|
|
123
|
-
|
|
124
|
-
case 'center':
|
|
125
|
-
{
|
|
126
|
-
// "Centered" offset is usually the average of the min and max.
|
|
127
|
-
// But near the edges of the list, this doesn't hold true.
|
|
128
|
-
const middleOffset = Math.round(minOffset + (maxOffset - minOffset) / 2)
|
|
129
|
-
|
|
130
|
-
if (middleOffset < Math.ceil(size / 2)) {
|
|
131
|
-
return 0 // near the beginning
|
|
132
|
-
} else if (middleOffset > lastItemOffset + Math.floor(size / 2)) {
|
|
133
|
-
return lastItemOffset // near the end
|
|
134
|
-
} else {
|
|
135
|
-
return middleOffset
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
case 'auto':
|
|
140
|
-
default:
|
|
141
|
-
if (scrollOffset >= minOffset && scrollOffset <= maxOffset) {
|
|
142
|
-
return scrollOffset
|
|
143
|
-
} else if (scrollOffset < minOffset) {
|
|
144
|
-
return minOffset
|
|
145
|
-
} else {
|
|
146
|
-
return maxOffset
|
|
147
|
-
}
|
|
148
|
-
}
|
|
149
|
-
},
|
|
150
|
-
getStartIndexForOffset (props, scrollOffset, ref) {
|
|
151
|
-
return Math.max(0, ref._getSizeCount(props, scrollOffset) - 1)
|
|
152
|
-
},
|
|
153
|
-
getStopIndexForStartIndex (props, scrollOffset, startIndex, ref) {
|
|
154
|
-
const {
|
|
155
|
-
height,
|
|
156
|
-
itemCount,
|
|
157
|
-
itemSize,
|
|
158
|
-
width
|
|
159
|
-
} = props
|
|
160
|
-
const size = isHorizontalFunc(props) ? width : height
|
|
161
|
-
const offset = ref._getCountSize(props, startIndex)
|
|
162
|
-
if (!props.unlimitedSize) {
|
|
163
|
-
// TODO Deprecate direction "horizontal"
|
|
164
|
-
const numVisibleItems = Math.ceil((size + scrollOffset - offset) / itemSize)
|
|
165
|
-
/** -1 is because stop index is inclusive */
|
|
166
|
-
return Math.max(startIndex, Math.min(itemCount - 1, startIndex + numVisibleItems - 1))
|
|
167
|
-
}
|
|
168
|
-
return Math.max(startIndex, Math.min(itemCount - 1, ref._getSizeCount(props, size + scrollOffset)))
|
|
169
|
-
},
|
|
170
|
-
|
|
171
|
-
initInstanceProps () { // Noop
|
|
172
|
-
},
|
|
173
|
-
|
|
174
|
-
shouldResetStyleCacheOnItemSizeChange: true,
|
|
175
|
-
validateProps: (nextProps, prevState) => {
|
|
176
|
-
const { itemCount, itemSize } = nextProps
|
|
177
|
-
const { sizeList } = prevState
|
|
178
|
-
if (itemCount > sizeList.length) {
|
|
179
|
-
const arr = new Array(itemCount - sizeList.length).fill(-1)
|
|
180
|
-
sizeList.push(...arr)
|
|
181
|
-
} else if (itemCount < sizeList.length) {
|
|
182
|
-
sizeList.length = itemCount
|
|
183
|
-
}
|
|
184
|
-
if (process.env.NODE_ENV !== 'production') {
|
|
185
|
-
if (typeof itemSize !== 'number') {
|
|
186
|
-
throw Error('An invalid "itemSize" prop has been specified. ' + 'Value should be a number. ' + `"${itemSize === null ? 'null' : typeof itemSize}" was specified.`)
|
|
187
|
-
}
|
|
188
|
-
}
|
|
189
|
-
validateSharedProps(nextProps, prevState)
|
|
190
|
-
}
|
|
191
|
-
})
|
|
192
|
-
|
|
193
|
-
export default FixedSizeList
|