@tarojs/components-advanced 3.6.0-alpha.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.
Files changed (42) hide show
  1. package/LICENSE +21 -0
  2. package/dist/components/index.d.ts +1 -0
  3. package/dist/components/index.js +1 -0
  4. package/dist/components/virtual-list/constants.d.ts +1 -0
  5. package/dist/components/virtual-list/constants.js +1 -0
  6. package/dist/components/virtual-list/dom-helpers.d.ts +1 -0
  7. package/dist/components/virtual-list/dom-helpers.js +38 -0
  8. package/dist/components/virtual-list/index.d.ts +189 -0
  9. package/dist/components/virtual-list/index.js +103 -0
  10. package/dist/components/virtual-list/list-set.d.ts +27 -0
  11. package/dist/components/virtual-list/list-set.js +227 -0
  12. package/dist/components/virtual-list/preset.d.ts +49 -0
  13. package/dist/components/virtual-list/preset.js +166 -0
  14. package/dist/components/virtual-list/react/index.d.ts +4 -0
  15. package/dist/components/virtual-list/react/index.js +67 -0
  16. package/dist/components/virtual-list/react/list.d.ts +39 -0
  17. package/dist/components/virtual-list/react/list.js +481 -0
  18. package/dist/components/virtual-list/react/validate.d.ts +3 -0
  19. package/dist/components/virtual-list/react/validate.js +69 -0
  20. package/dist/components/virtual-list/utils.d.ts +12 -0
  21. package/dist/components/virtual-list/utils.js +33 -0
  22. package/dist/components/virtual-list/vue/index.d.ts +17 -0
  23. package/dist/components/virtual-list/vue/index.js +8 -0
  24. package/dist/components/virtual-list/vue/list.d.ts +120 -0
  25. package/dist/components/virtual-list/vue/list.js +489 -0
  26. package/dist/components/virtual-list/vue/render.d.ts +3 -0
  27. package/dist/components/virtual-list/vue/render.js +24 -0
  28. package/dist/index.d.ts +2 -0
  29. package/dist/index.js +2 -0
  30. package/dist/utils/convert.d.ts +5 -0
  31. package/dist/utils/convert.js +16 -0
  32. package/dist/utils/index.d.ts +4 -0
  33. package/dist/utils/index.js +4 -0
  34. package/dist/utils/lodash.d.ts +1 -0
  35. package/dist/utils/lodash.js +10 -0
  36. package/dist/utils/math.d.ts +2 -0
  37. package/dist/utils/math.js +18 -0
  38. package/dist/utils/timer.d.ts +6 -0
  39. package/dist/utils/timer.js +20 -0
  40. package/package.json +49 -0
  41. package/typings/global.d.ts +1 -0
  42. package/typings/vue.d.ts +7 -0
@@ -0,0 +1,166 @@
1
+ import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
2
+ import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
3
+ import _createClass from "@babel/runtime/helpers/esm/createClass";
4
+ import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
5
+ import memoizeOne from 'memoize-one';
6
+ import { convertNumber2PX, isCosDistributing } from '../../utils';
7
+ import ListSet from './list-set';
8
+ import { isHorizontalFunc, isRtlFunc } from './utils';
9
+ var INSTANCE_ID = 0;
10
+ var Preset = /*#__PURE__*/function () {
11
+ function Preset(props, refresh) {
12
+ _classCallCheck(this, Preset);
13
+ this.props = props;
14
+ this.refresh = refresh;
15
+ _defineProperty(this, "itemList", void 0);
16
+ _defineProperty(this, "wrapperField", {
17
+ scrollLeft: 0,
18
+ scrollTop: 0,
19
+ scrollHeight: 0,
20
+ scrollWidth: 0,
21
+ clientHeight: 0,
22
+ clientWidth: 0,
23
+ diffOffset: 0
24
+ });
25
+ _defineProperty(this, "diffList", [0, 0, 0]);
26
+ _defineProperty(this, "getItemStyleCache", memoizeOne(function (_itemSize, _layout, _direction) {
27
+ // TODO: Cache of item styles, keyed by item index.
28
+ return {};
29
+ }));
30
+ this.init(this.props);
31
+ this.itemList = new ListSet(props, refresh);
32
+ }
33
+ _createClass(Preset, [{
34
+ key: "init",
35
+ value: function init(props) {
36
+ this.props = props;
37
+ }
38
+ }, {
39
+ key: "update",
40
+ value: function update(props) {
41
+ this.props = props;
42
+ this.itemList.update(props);
43
+ }
44
+ }, {
45
+ key: "id",
46
+ get: function get() {
47
+ return "virtual-list-".concat(INSTANCE_ID++);
48
+ }
49
+ }, {
50
+ key: "isHorizontal",
51
+ get: function get() {
52
+ return isHorizontalFunc(this.props);
53
+ }
54
+ }, {
55
+ key: "isRtl",
56
+ get: function get() {
57
+ return isRtlFunc(this.props);
58
+ }
59
+ }, {
60
+ key: "isRelative",
61
+ get: function get() {
62
+ return this.props.position === 'relative';
63
+ }
64
+ }, {
65
+ key: "placeholderCount",
66
+ get: function get() {
67
+ return this.props.placeholderCount >= 0 ? this.props.placeholderCount : this.props.overscanCount;
68
+ }
69
+ }, {
70
+ key: "outerTagName",
71
+ get: function get() {
72
+ return this.props.outerElementType || this.props.outerTagName || 'div';
73
+ }
74
+ }, {
75
+ key: "innerTagName",
76
+ get: function get() {
77
+ return this.props.innerElementType || this.props.innerTagName || 'div';
78
+ }
79
+ }, {
80
+ key: "itemTagName",
81
+ get: function get() {
82
+ return this.props.itemElementType || this.props.itemTagName || 'div';
83
+ }
84
+ }, {
85
+ key: "field",
86
+ get: function get() {
87
+ return this.wrapperField;
88
+ },
89
+ set: function set(o) {
90
+ Object.assign(this.wrapperField, o);
91
+ // Object.keys(o).forEach(key => {
92
+ // if (typeof o[key] === 'number' && typeof this.wrapperField[key] === 'number') {
93
+ // this.wrapperField[key] = o[key]
94
+ // }
95
+ // })
96
+ }
97
+ }, {
98
+ key: "isShaking",
99
+ value: function isShaking(diff) {
100
+ var list = this.diffList.slice(-3);
101
+ this.diffList.push(diff);
102
+ return list.findIndex(function (e) {
103
+ return Math.abs(e) === Math.abs(diff);
104
+ }) !== -1 || isCosDistributing(this.diffList.slice(-4));
105
+ }
106
+ }, {
107
+ key: "getItemStyle",
108
+ value: function getItemStyle(index) {
109
+ var _this$props = this.props,
110
+ direction = _this$props.direction,
111
+ itemSize = _this$props.itemSize,
112
+ layout = _this$props.layout,
113
+ shouldResetStyleCacheOnItemSizeChange = _this$props.shouldResetStyleCacheOnItemSizeChange;
114
+ var itemStyleCache = this.getItemStyleCache(shouldResetStyleCacheOnItemSizeChange ? itemSize : false, shouldResetStyleCacheOnItemSizeChange ? layout : false, shouldResetStyleCacheOnItemSizeChange ? direction : false);
115
+ var style;
116
+ var offset = convertNumber2PX(this.itemList.getOffsetSize(index));
117
+ var size = convertNumber2PX(this.itemList.getSize(index));
118
+ var isHorizontal = this.isHorizontal;
119
+ var isRtl = this.isRtl;
120
+ if (itemStyleCache.hasOwnProperty(index)) {
121
+ // Note: style is frozen.
122
+ style = _objectSpread({}, itemStyleCache[index]);
123
+ if (isHorizontal) {
124
+ style.width = size;
125
+ if (!this.isRelative) {
126
+ if (isRtl) {
127
+ style.right = offset;
128
+ } else {
129
+ style.left = offset;
130
+ }
131
+ }
132
+ } else {
133
+ style.height = size;
134
+ if (!this.isRelative) {
135
+ style.top = offset;
136
+ }
137
+ }
138
+ } else {
139
+ if (this.isRelative) {
140
+ itemStyleCache[index] = style = {
141
+ height: !isHorizontal ? size : '100%',
142
+ width: isHorizontal ? size : '100%'
143
+ };
144
+ } else {
145
+ var offsetHorizontal = isHorizontal ? offset : 0;
146
+ itemStyleCache[index] = style = {
147
+ position: 'absolute',
148
+ left: !isRtl ? offsetHorizontal : undefined,
149
+ right: isRtl ? offsetHorizontal : undefined,
150
+ top: !isHorizontal ? offset : 0,
151
+ height: !isHorizontal ? size : '100%',
152
+ width: isHorizontal ? size : '100%'
153
+ };
154
+ }
155
+ }
156
+ for (var k in style) {
157
+ if (style.hasOwnProperty(k)) {
158
+ style[k] = convertNumber2PX(style[k]);
159
+ }
160
+ }
161
+ return style;
162
+ }
163
+ }]);
164
+ return Preset;
165
+ }();
166
+ export { Preset as default };
@@ -0,0 +1,4 @@
1
+ import React from 'react';
2
+ import type { VirtualListProps } from '../';
3
+ declare const VirtualList: React.ForwardRefExoticComponent<Pick<VirtualListProps, "id" | "className" | "style" | "key" | "hidden" | "animation" | "dangerouslySetInnerHTML" | "onTouchStart" | "onTouchMove" | "onTouchCancel" | "onTouchEnd" | "onClick" | "onLongPress" | "onLongClick" | "onTransitionEnd" | "onAnimationStart" | "onAnimationIteration" | "onAnimationEnd" | "onTouchForceChange" | "height" | "width" | "item" | "itemCount" | "itemData" | "itemSize" | "unlimitedSize" | "position" | "initialScrollOffset" | "innerElementType" | "renderTop" | "renderBottom" | "layout" | "onScroll" | "onScrollNative" | "overscanCount" | "placeholderCount" | "useIsScrolling"> & React.RefAttributes<unknown>>;
4
+ export default VirtualList;
@@ -0,0 +1,67 @@
1
+ import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
2
+ import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
3
+ var _excluded = ["style", "onScroll", "onScrollNative", "layout"],
4
+ _excluded2 = ["direction", "innerElementType", "itemElementType", "initialScrollOffset", "overscanCount"];
5
+ import { ScrollView, View } from '@tarojs/components';
6
+ import React from 'react';
7
+ import { convertPX2Int } from '../../../utils/convert';
8
+ import List from './list';
9
+ var OuterScrollView = React.forwardRef(function OuterScrollView(props, ref) {
10
+ var _ref = props,
11
+ style = _ref.style,
12
+ onScroll = _ref.onScroll,
13
+ onScrollNative = _ref.onScrollNative,
14
+ layout = _ref.layout,
15
+ rest = _objectWithoutProperties(_ref, _excluded);
16
+ var handleScroll = function handleScroll(event) {
17
+ onScroll(_objectSpread(_objectSpread({}, event), {}, {
18
+ currentTarget: _objectSpread(_objectSpread({}, event.detail), {}, {
19
+ clientWidth: convertPX2Int(style.width),
20
+ clientHeight: convertPX2Int(style.height)
21
+ })
22
+ }));
23
+ if (typeof onScrollNative === 'function') {
24
+ onScrollNative(event);
25
+ }
26
+ };
27
+ return React.createElement(ScrollView, _objectSpread({
28
+ ref: ref,
29
+ style: style,
30
+ scrollY: layout === 'vertical',
31
+ scrollX: layout === 'horizontal',
32
+ onScroll: handleScroll
33
+ }, rest));
34
+ });
35
+ var VirtualList = React.forwardRef(function VirtualList(props, ref) {
36
+ var _ref2 = props,
37
+ _ref2$direction = _ref2.direction,
38
+ direction = _ref2$direction === void 0 ? 'ltr' : _ref2$direction,
39
+ _ref2$innerElementTyp = _ref2.innerElementType,
40
+ innerElementType = _ref2$innerElementTyp === void 0 ? View : _ref2$innerElementTyp,
41
+ _ref2$itemElementType = _ref2.itemElementType,
42
+ itemElementType = _ref2$itemElementType === void 0 ? View : _ref2$itemElementType,
43
+ _ref2$initialScrollOf = _ref2.initialScrollOffset,
44
+ initialScrollOffset = _ref2$initialScrollOf === void 0 ? 0 : _ref2$initialScrollOf,
45
+ _ref2$overscanCount = _ref2.overscanCount,
46
+ overscanCount = _ref2$overscanCount === void 0 ? 1 : _ref2$overscanCount,
47
+ rest = _objectWithoutProperties(_ref2, _excluded2);
48
+ if ('children' in rest) {
49
+ console.warn('Taro(VirtualList): children props have been deprecated. ' + 'Please use the item props instead.');
50
+ rest.item = rest.children;
51
+ }
52
+ if (rest.item instanceof Array) {
53
+ console.warn('Taro(VirtualList): item should not be an array');
54
+ rest.item = rest.item[0];
55
+ }
56
+ return React.createElement(List, _objectSpread(_objectSpread({
57
+ ref: ref
58
+ }, rest), {}, {
59
+ itemElementType: itemElementType,
60
+ innerElementType: innerElementType,
61
+ outerElementType: OuterScrollView,
62
+ direction: direction,
63
+ initialScrollOffset: initialScrollOffset,
64
+ overscanCount: overscanCount
65
+ }));
66
+ });
67
+ export default VirtualList;
@@ -0,0 +1,39 @@
1
+ import React from 'react';
2
+ import ListSet from '../list-set';
3
+ import Preset from '../preset';
4
+ import type { IProps } from '../preset';
5
+ export interface IState {
6
+ id: string;
7
+ instance: List;
8
+ isScrolling: boolean;
9
+ scrollDirection: 'forward' | 'backward';
10
+ scrollOffset: number;
11
+ scrollUpdateWasRequested: boolean;
12
+ refreshCount: number;
13
+ }
14
+ export default class List extends React.PureComponent<IProps, IState> {
15
+ static defaultProps: IProps;
16
+ static getDerivedStateFromProps(nextProps: IProps, prevState: IState): any;
17
+ itemList: ListSet;
18
+ preset: Preset;
19
+ constructor(props: IProps);
20
+ refresh: () => void;
21
+ _outerRef: any;
22
+ _resetIsScrollingTimeoutId: any;
23
+ _callOnItemsRendered: import("memoize-one").MemoizedFn<(this: any, overscanStartIndex: any, overscanStopIndex: any, visibleStartIndex: any, visibleStopIndex: any) => any>;
24
+ _callOnScroll: import("memoize-one").MemoizedFn<(this: any, scrollDirection: any, scrollOffset: any, scrollUpdateWasRequested: any, detail: any) => void>;
25
+ _callPropsCallbacks(prevProps?: any, prevState?: any): void;
26
+ _getSizeUploadSync: (index: number, isHorizontal: boolean) => Promise<unknown>;
27
+ _getRangeToRender(): number[];
28
+ _onScrollHorizontal: (event: any) => void;
29
+ _onScrollVertical: (event: any) => void;
30
+ _outerRefSetter: (ref: any) => void;
31
+ _resetIsScrollingDebounced: () => void;
32
+ _resetIsScrolling: () => void;
33
+ scrollTo(scrollOffset: number): void;
34
+ scrollToItem(index: number, align?: string): void;
35
+ componentDidMount(): void;
36
+ componentDidUpdate(prevProps: IProps, prevState: IState): void;
37
+ componentWillUnmount(): void;
38
+ render(): React.ReactElement<{}, string | React.JSXElementConstructor<any>>;
39
+ }