@tarojs/components 3.6.0-canary.6 → 3.6.0-canary.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (69) hide show
  1. package/dist/react/component-lib/index.js +20 -10
  2. package/dist/react/component-lib/input.js +3 -4
  3. package/dist/react/component-lib/reactify-wc.js +9 -46
  4. package/dist/react/components.js +0 -2
  5. package/dist/react/react-component-lib/createComponent.js +10 -30
  6. package/dist/react/react-component-lib/createOverlayComponent.js +8 -37
  7. package/dist/react/react-component-lib/utils/attachProps.js +9 -18
  8. package/dist/react/react-component-lib/utils/index.js +6 -9
  9. package/dist/vue2/component-lib/components.js +22 -11
  10. package/dist/vue2/component-lib/createFormsComponent.js +0 -5
  11. package/dist/vue2/component-lib/index.js +6 -8
  12. package/dist/vue2/component-lib/mixins/refs.js +0 -5
  13. package/dist/vue2/components.js +0 -3
  14. package/dist/vue2/index.js +3 -7
  15. package/dist/vue2/vue-component-lib/utils.js +0 -1
  16. package/dist/vue3/component-lib/createComponent.js +1 -1
  17. package/dist/vue3/component-lib/createFormsComponent.js +3 -8
  18. package/dist/vue3/component-lib/forwardRef.js +0 -2
  19. package/dist/vue3/component-lib/icon.js +2 -2
  20. package/dist/vue3/component-lib/image.js +2 -2
  21. package/dist/vue3/component-lib/index.js +22 -11
  22. package/dist/vue3/component-lib/scroll-view.js +2 -2
  23. package/dist/vue3/component-lib/text.js +2 -2
  24. package/dist/vue3/components.js +0 -2
  25. package/dist/vue3/index.js +2 -4
  26. package/dist/vue3/vue-component-lib/utils.js +7 -29
  27. package/package.json +4 -3
  28. package/types/Button.d.ts +1 -1
  29. package/types/Camera.d.ts +1 -1
  30. package/types/Checkbox.d.ts +1 -1
  31. package/types/CheckboxGroup.d.ts +1 -1
  32. package/types/CoverImage.d.ts +1 -1
  33. package/types/CustomWrapper.d.ts +1 -0
  34. package/types/Form.d.ts +1 -1
  35. package/types/Icon.d.ts +1 -1
  36. package/types/Image.d.ts +1 -1
  37. package/types/Input.d.ts +15 -1
  38. package/types/Label.d.ts +1 -1
  39. package/types/NativeSlot.d.ts +1 -0
  40. package/types/NavigationBar.d.ts +2 -1
  41. package/types/Navigator.d.ts +1 -1
  42. package/types/Picker.d.ts +1 -1
  43. package/types/PickerView.d.ts +1 -1
  44. package/types/PickerViewColumn.d.ts +1 -1
  45. package/types/Progress.d.ts +1 -1
  46. package/types/Radio.d.ts +1 -1
  47. package/types/RadioGroup.d.ts +1 -1
  48. package/types/RichText.d.ts +1 -1
  49. package/types/ScrollView.d.ts +1 -1
  50. package/types/ShareElement.d.ts +3 -3
  51. package/types/Slider.d.ts +1 -1
  52. package/types/Slot.d.ts +2 -1
  53. package/types/Swiper.d.ts +1 -1
  54. package/types/SwiperItem.d.ts +1 -1
  55. package/types/Switch.d.ts +1 -1
  56. package/types/Textarea.d.ts +1 -1
  57. package/types/Video.d.ts +1 -1
  58. package/types/View.d.ts +1 -1
  59. package/types/WebView.d.ts +1 -1
  60. package/virtual-list/index.d.ts +3 -120
  61. package/virtual-list/index.js +3 -7
  62. package/virtual-list/domHelpers.js +0 -40
  63. package/virtual-list/memoize.js +0 -38
  64. package/virtual-list/react/FixedSizeList.js +0 -193
  65. package/virtual-list/react/createListComponent.js +0 -654
  66. package/virtual-list/react/index.d.ts +0 -123
  67. package/virtual-list/react/index.js +0 -67
  68. package/virtual-list/timer.js +0 -24
  69. package/virtual-list/vue/index.js +0 -589
@@ -1,121 +1,4 @@
1
- import { Component, ComponentType, CSSProperties, ReactNode } from 'react'
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
- interface VirtualListProps extends StandardProps {
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
@@ -1,7 +1,3 @@
1
- if (process.env.FRAMEWORK === 'vue') {
2
- module.exports = require('./vue').default
3
- module.exports.default = module.exports
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
- }
@@ -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