@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.
- package/LICENSE +21 -0
- package/dist/components/index.d.ts +1 -0
- package/dist/components/index.js +1 -0
- package/dist/components/virtual-list/constants.d.ts +1 -0
- package/dist/components/virtual-list/constants.js +1 -0
- package/dist/components/virtual-list/dom-helpers.d.ts +1 -0
- package/dist/components/virtual-list/dom-helpers.js +38 -0
- package/dist/components/virtual-list/index.d.ts +189 -0
- package/dist/components/virtual-list/index.js +103 -0
- package/dist/components/virtual-list/list-set.d.ts +27 -0
- package/dist/components/virtual-list/list-set.js +227 -0
- package/dist/components/virtual-list/preset.d.ts +49 -0
- package/dist/components/virtual-list/preset.js +166 -0
- package/dist/components/virtual-list/react/index.d.ts +4 -0
- package/dist/components/virtual-list/react/index.js +67 -0
- package/dist/components/virtual-list/react/list.d.ts +39 -0
- package/dist/components/virtual-list/react/list.js +481 -0
- package/dist/components/virtual-list/react/validate.d.ts +3 -0
- package/dist/components/virtual-list/react/validate.js +69 -0
- package/dist/components/virtual-list/utils.d.ts +12 -0
- package/dist/components/virtual-list/utils.js +33 -0
- package/dist/components/virtual-list/vue/index.d.ts +17 -0
- package/dist/components/virtual-list/vue/index.js +8 -0
- package/dist/components/virtual-list/vue/list.d.ts +120 -0
- package/dist/components/virtual-list/vue/list.js +489 -0
- package/dist/components/virtual-list/vue/render.d.ts +3 -0
- package/dist/components/virtual-list/vue/render.js +24 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +2 -0
- package/dist/utils/convert.d.ts +5 -0
- package/dist/utils/convert.js +16 -0
- package/dist/utils/index.d.ts +4 -0
- package/dist/utils/index.js +4 -0
- package/dist/utils/lodash.d.ts +1 -0
- package/dist/utils/lodash.js +10 -0
- package/dist/utils/math.d.ts +2 -0
- package/dist/utils/math.js +18 -0
- package/dist/utils/timer.d.ts +6 -0
- package/dist/utils/timer.js +20 -0
- package/package.json +49 -0
- package/typings/global.d.ts +1 -0
- package/typings/vue.d.ts +7 -0
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
import Preset from '../preset';
|
|
2
|
+
declare const _default: {
|
|
3
|
+
props: {
|
|
4
|
+
height: {
|
|
5
|
+
type: (NumberConstructor | StringConstructor)[];
|
|
6
|
+
required: boolean;
|
|
7
|
+
};
|
|
8
|
+
width: {
|
|
9
|
+
type: (NumberConstructor | StringConstructor)[];
|
|
10
|
+
required: boolean;
|
|
11
|
+
};
|
|
12
|
+
itemCount: {
|
|
13
|
+
type: NumberConstructor;
|
|
14
|
+
required: boolean;
|
|
15
|
+
};
|
|
16
|
+
itemData: {
|
|
17
|
+
type: ArrayConstructor;
|
|
18
|
+
required: boolean;
|
|
19
|
+
};
|
|
20
|
+
itemSize: {
|
|
21
|
+
type: (NumberConstructor | FunctionConstructor)[];
|
|
22
|
+
required: boolean;
|
|
23
|
+
};
|
|
24
|
+
unlimitedSize: {
|
|
25
|
+
type: BooleanConstructor;
|
|
26
|
+
default: boolean;
|
|
27
|
+
};
|
|
28
|
+
position: {
|
|
29
|
+
type: StringConstructor;
|
|
30
|
+
default: string;
|
|
31
|
+
};
|
|
32
|
+
initialScrollOffset: {
|
|
33
|
+
type: NumberConstructor;
|
|
34
|
+
default: number;
|
|
35
|
+
};
|
|
36
|
+
innerElementType: {
|
|
37
|
+
type: StringConstructor;
|
|
38
|
+
default: string;
|
|
39
|
+
};
|
|
40
|
+
direction: {
|
|
41
|
+
type: StringConstructor;
|
|
42
|
+
default: string;
|
|
43
|
+
};
|
|
44
|
+
layout: {
|
|
45
|
+
type: StringConstructor;
|
|
46
|
+
default: string;
|
|
47
|
+
};
|
|
48
|
+
overscanCount: {
|
|
49
|
+
type: NumberConstructor;
|
|
50
|
+
default: number;
|
|
51
|
+
};
|
|
52
|
+
placeholderCount: {
|
|
53
|
+
type: NumberConstructor;
|
|
54
|
+
};
|
|
55
|
+
useIsScrolling: {
|
|
56
|
+
type: BooleanConstructor;
|
|
57
|
+
default: boolean;
|
|
58
|
+
};
|
|
59
|
+
item: {
|
|
60
|
+
required: boolean;
|
|
61
|
+
};
|
|
62
|
+
itemKey: StringConstructor;
|
|
63
|
+
itemTagName: {
|
|
64
|
+
type: StringConstructor;
|
|
65
|
+
default: string;
|
|
66
|
+
};
|
|
67
|
+
innerTagName: {
|
|
68
|
+
type: StringConstructor;
|
|
69
|
+
default: string;
|
|
70
|
+
};
|
|
71
|
+
outerTagName: {
|
|
72
|
+
type: StringConstructor;
|
|
73
|
+
default: string;
|
|
74
|
+
};
|
|
75
|
+
itemElementType: StringConstructor;
|
|
76
|
+
outerElementType: StringConstructor;
|
|
77
|
+
innerRef: StringConstructor;
|
|
78
|
+
outerRef: StringConstructor;
|
|
79
|
+
onItemsRendered: FunctionConstructor;
|
|
80
|
+
onScrollNative: FunctionConstructor;
|
|
81
|
+
shouldResetStyleCacheOnItemSizeChange: {
|
|
82
|
+
type: BooleanConstructor;
|
|
83
|
+
default: boolean;
|
|
84
|
+
};
|
|
85
|
+
};
|
|
86
|
+
data(): {
|
|
87
|
+
itemList: import("../list-set").default;
|
|
88
|
+
preset: Preset;
|
|
89
|
+
id: any;
|
|
90
|
+
instance: any;
|
|
91
|
+
isScrolling: boolean;
|
|
92
|
+
scrollDirection: string;
|
|
93
|
+
scrollOffset: any;
|
|
94
|
+
scrollUpdateWasRequested: boolean;
|
|
95
|
+
resetIsScrollingTimeoutId: any;
|
|
96
|
+
refreshCount: number;
|
|
97
|
+
};
|
|
98
|
+
methods: {
|
|
99
|
+
refresh(): void;
|
|
100
|
+
scrollTo(scrollOffset: any): void;
|
|
101
|
+
scrollToItem(index: any, align?: string): void;
|
|
102
|
+
_callOnItemsRendered: import("memoize-one").MemoizedFn<(this: any, overscanStartIndex: any, overscanStopIndex: any, visibleStartIndex: any, visibleStopIndex: any) => any>;
|
|
103
|
+
_callOnScroll: import("memoize-one").MemoizedFn<(this: any, scrollDirection: any, scrollOffset: any, scrollUpdateWasRequested: any, detail: any) => void>;
|
|
104
|
+
_callPropsCallbacks(): void;
|
|
105
|
+
_getSizeUploadSync(index: number, isHorizontal: boolean): Promise<unknown>;
|
|
106
|
+
_getRangeToRender(): any;
|
|
107
|
+
_onScrollHorizontal(event: any): void;
|
|
108
|
+
_onScrollVertical(event: any): void;
|
|
109
|
+
_outerRefSetter(ref: any): void;
|
|
110
|
+
_resetIsScrollingDebounced(): void;
|
|
111
|
+
_resetIsScrolling(): void;
|
|
112
|
+
};
|
|
113
|
+
mounted(): void;
|
|
114
|
+
updated(): void;
|
|
115
|
+
beforeDestroy(): void;
|
|
116
|
+
render(): import("vue").VNode<import("vue").RendererNode, import("vue").RendererElement, {
|
|
117
|
+
[key: string]: any;
|
|
118
|
+
}>;
|
|
119
|
+
};
|
|
120
|
+
export default _default;
|
|
@@ -0,0 +1,489 @@
|
|
|
1
|
+
import _typeof from "@babel/runtime/helpers/esm/typeof";
|
|
2
|
+
import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
|
|
3
|
+
import memoizeOne from 'memoize-one';
|
|
4
|
+
import { convertNumber2PX } from '../../../utils/convert';
|
|
5
|
+
import { omit } from '../../../utils/lodash';
|
|
6
|
+
import { cancelTimeout, requestTimeout } from '../../../utils/timer';
|
|
7
|
+
import { IS_SCROLLING_DEBOUNCE_INTERVAL } from '../constants';
|
|
8
|
+
import { getRTLOffsetType } from '../dom-helpers';
|
|
9
|
+
import Preset from '../preset';
|
|
10
|
+
import { defaultItemKey, getRectSize } from '../utils';
|
|
11
|
+
import _render from './render';
|
|
12
|
+
export default {
|
|
13
|
+
props: {
|
|
14
|
+
height: {
|
|
15
|
+
type: [String, Number],
|
|
16
|
+
required: true
|
|
17
|
+
},
|
|
18
|
+
width: {
|
|
19
|
+
type: [String, Number],
|
|
20
|
+
required: true
|
|
21
|
+
},
|
|
22
|
+
itemCount: {
|
|
23
|
+
type: Number,
|
|
24
|
+
required: true
|
|
25
|
+
},
|
|
26
|
+
itemData: {
|
|
27
|
+
type: Array,
|
|
28
|
+
required: true
|
|
29
|
+
},
|
|
30
|
+
itemSize: {
|
|
31
|
+
type: [Number, Function],
|
|
32
|
+
required: true
|
|
33
|
+
},
|
|
34
|
+
unlimitedSize: {
|
|
35
|
+
type: Boolean,
|
|
36
|
+
default: false
|
|
37
|
+
},
|
|
38
|
+
position: {
|
|
39
|
+
type: String,
|
|
40
|
+
default: 'absolute'
|
|
41
|
+
},
|
|
42
|
+
initialScrollOffset: {
|
|
43
|
+
type: Number,
|
|
44
|
+
default: 0
|
|
45
|
+
},
|
|
46
|
+
innerElementType: {
|
|
47
|
+
type: String,
|
|
48
|
+
default: process.env.TARO_ENV === 'h5' ? 'taro-view-core' : 'view'
|
|
49
|
+
},
|
|
50
|
+
direction: {
|
|
51
|
+
type: String,
|
|
52
|
+
default: 'ltr'
|
|
53
|
+
},
|
|
54
|
+
layout: {
|
|
55
|
+
type: String,
|
|
56
|
+
default: 'vertical'
|
|
57
|
+
},
|
|
58
|
+
overscanCount: {
|
|
59
|
+
type: Number,
|
|
60
|
+
default: 1
|
|
61
|
+
},
|
|
62
|
+
placeholderCount: {
|
|
63
|
+
type: Number
|
|
64
|
+
},
|
|
65
|
+
useIsScrolling: {
|
|
66
|
+
type: Boolean,
|
|
67
|
+
default: false
|
|
68
|
+
},
|
|
69
|
+
item: {
|
|
70
|
+
required: true
|
|
71
|
+
},
|
|
72
|
+
itemKey: String,
|
|
73
|
+
itemTagName: {
|
|
74
|
+
type: String,
|
|
75
|
+
default: process.env.TARO_ENV === 'h5' ? 'taro-view-core' : 'view'
|
|
76
|
+
},
|
|
77
|
+
innerTagName: {
|
|
78
|
+
type: String,
|
|
79
|
+
default: process.env.TARO_ENV === 'h5' ? 'taro-view-core' : 'view'
|
|
80
|
+
},
|
|
81
|
+
outerTagName: {
|
|
82
|
+
type: String,
|
|
83
|
+
default: process.env.TARO_ENV === 'h5' ? 'taro-scroll-view-core' : 'scroll-view'
|
|
84
|
+
},
|
|
85
|
+
itemElementType: String,
|
|
86
|
+
outerElementType: String,
|
|
87
|
+
innerRef: String,
|
|
88
|
+
outerRef: String,
|
|
89
|
+
onItemsRendered: Function,
|
|
90
|
+
onScrollNative: Function,
|
|
91
|
+
shouldResetStyleCacheOnItemSizeChange: {
|
|
92
|
+
type: Boolean,
|
|
93
|
+
default: true
|
|
94
|
+
}
|
|
95
|
+
},
|
|
96
|
+
data: function data() {
|
|
97
|
+
var preset = new Preset(this.$props, this.refresh);
|
|
98
|
+
return {
|
|
99
|
+
itemList: preset.itemList,
|
|
100
|
+
preset: preset,
|
|
101
|
+
id: this.$props.id || preset.id,
|
|
102
|
+
instance: this,
|
|
103
|
+
isScrolling: false,
|
|
104
|
+
scrollDirection: 'forward',
|
|
105
|
+
scrollOffset: typeof this.$props.initialScrollOffset === 'number' ? this.$props.initialScrollOffset : 0,
|
|
106
|
+
scrollUpdateWasRequested: false,
|
|
107
|
+
resetIsScrollingTimeoutId: null,
|
|
108
|
+
refreshCount: 0
|
|
109
|
+
};
|
|
110
|
+
},
|
|
111
|
+
methods: {
|
|
112
|
+
refresh: function refresh() {
|
|
113
|
+
this.refreshCount = this.refreshCount + 1;
|
|
114
|
+
},
|
|
115
|
+
scrollTo: function scrollTo(scrollOffset) {
|
|
116
|
+
scrollOffset = Math.max(0, scrollOffset);
|
|
117
|
+
if (this.scrollOffset === scrollOffset) {
|
|
118
|
+
return;
|
|
119
|
+
}
|
|
120
|
+
this.scrollDirection = this.scrollOffset < scrollOffset ? 'forward' : 'backward';
|
|
121
|
+
this.scrollOffset = scrollOffset;
|
|
122
|
+
this.scrollUpdateWasRequested = true;
|
|
123
|
+
this.$nextTick(this._resetIsScrollingDebounced);
|
|
124
|
+
},
|
|
125
|
+
scrollToItem: function scrollToItem(index) {
|
|
126
|
+
var align = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'auto';
|
|
127
|
+
var itemCount = this.$props.itemCount;
|
|
128
|
+
var scrollOffset = this.$data.scrollOffset;
|
|
129
|
+
index = Math.max(0, Math.min(index, itemCount - 1));
|
|
130
|
+
this.scrollTo(this.itemList.getOffsetForIndexAndAlignment(this.$props, index, align, scrollOffset));
|
|
131
|
+
},
|
|
132
|
+
_callOnItemsRendered: memoizeOne(function (overscanStartIndex, overscanStopIndex, visibleStartIndex, visibleStopIndex) {
|
|
133
|
+
return this.$props.onItemsRendered({
|
|
134
|
+
overscanStartIndex: overscanStartIndex,
|
|
135
|
+
overscanStopIndex: overscanStopIndex,
|
|
136
|
+
visibleStartIndex: visibleStartIndex,
|
|
137
|
+
visibleStopIndex: visibleStopIndex
|
|
138
|
+
});
|
|
139
|
+
}),
|
|
140
|
+
_callOnScroll: memoizeOne(function (scrollDirection, scrollOffset, scrollUpdateWasRequested, detail) {
|
|
141
|
+
this.$emit('scroll', {
|
|
142
|
+
scrollDirection: scrollDirection,
|
|
143
|
+
scrollOffset: scrollOffset,
|
|
144
|
+
scrollUpdateWasRequested: scrollUpdateWasRequested,
|
|
145
|
+
detail: detail
|
|
146
|
+
});
|
|
147
|
+
}),
|
|
148
|
+
_callPropsCallbacks: function _callPropsCallbacks() {
|
|
149
|
+
var _this = this;
|
|
150
|
+
if (typeof this.$props.onItemsRendered === 'function') {
|
|
151
|
+
var itemCount = this.$props.itemCount;
|
|
152
|
+
if (itemCount > 0) {
|
|
153
|
+
var _this$_getRangeToRend = this._getRangeToRender(),
|
|
154
|
+
_this$_getRangeToRend2 = _slicedToArray(_this$_getRangeToRend, 4),
|
|
155
|
+
overscanStartIndex = _this$_getRangeToRend2[0],
|
|
156
|
+
overscanStopIndex = _this$_getRangeToRend2[1],
|
|
157
|
+
visibleStartIndex = _this$_getRangeToRend2[2],
|
|
158
|
+
visibleStopIndex = _this$_getRangeToRend2[3];
|
|
159
|
+
this._callOnItemsRendered(overscanStartIndex, overscanStopIndex, visibleStartIndex, visibleStopIndex);
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
this._callOnScroll(this.scrollDirection, this.scrollOffset, this.scrollUpdateWasRequested, this.preset.field);
|
|
163
|
+
setTimeout(function () {
|
|
164
|
+
var _this$_getRangeToRend3 = _this._getRangeToRender(),
|
|
165
|
+
_this$_getRangeToRend4 = _slicedToArray(_this$_getRangeToRend3, 2),
|
|
166
|
+
startIndex = _this$_getRangeToRend4[0],
|
|
167
|
+
stopIndex = _this$_getRangeToRend4[1];
|
|
168
|
+
var isHorizontal = _this.preset.isHorizontal;
|
|
169
|
+
for (var index = startIndex; index <= stopIndex; index++) {
|
|
170
|
+
_this._getSizeUploadSync(index, isHorizontal);
|
|
171
|
+
}
|
|
172
|
+
}, 0);
|
|
173
|
+
},
|
|
174
|
+
_getSizeUploadSync: function _getSizeUploadSync(index, isHorizontal) {
|
|
175
|
+
var _this2 = this;
|
|
176
|
+
var ID = "#".concat(this.$data.id, "-").concat(index);
|
|
177
|
+
return new Promise(function (resolve) {
|
|
178
|
+
var success = function success(_ref) {
|
|
179
|
+
var width = _ref.width,
|
|
180
|
+
height = _ref.height;
|
|
181
|
+
var size = isHorizontal ? width : height;
|
|
182
|
+
if (!_this2.itemList.compareSize(index, size)) {
|
|
183
|
+
_this2.itemList.setSize(index, size);
|
|
184
|
+
resolve(_this2.itemList.getSize(index));
|
|
185
|
+
}
|
|
186
|
+
};
|
|
187
|
+
var fail = function fail() {
|
|
188
|
+
var _this2$_getRangeToRen = _this2._getRangeToRender(),
|
|
189
|
+
_this2$_getRangeToRen2 = _slicedToArray(_this2$_getRangeToRen, 2),
|
|
190
|
+
startIndex = _this2$_getRangeToRen2[0],
|
|
191
|
+
stopIndex = _this2$_getRangeToRen2[1];
|
|
192
|
+
if (index >= startIndex && index <= stopIndex) {
|
|
193
|
+
setTimeout(function () {
|
|
194
|
+
getRectSize(ID, success, fail);
|
|
195
|
+
}, 100);
|
|
196
|
+
}
|
|
197
|
+
};
|
|
198
|
+
getRectSize(ID, success, fail);
|
|
199
|
+
});
|
|
200
|
+
},
|
|
201
|
+
_getRangeToRender: function _getRangeToRender() {
|
|
202
|
+
return this.itemList.getRangeToRender(this.$data.scrollDirection, this.$data.scrollOffset, this.$data.isScrolling);
|
|
203
|
+
},
|
|
204
|
+
_onScrollHorizontal: function _onScrollHorizontal(event) {
|
|
205
|
+
var _event$currentTarget = event.currentTarget,
|
|
206
|
+
clientWidth = _event$currentTarget.clientWidth,
|
|
207
|
+
scrollTop = _event$currentTarget.scrollTop,
|
|
208
|
+
scrollLeft = _event$currentTarget.scrollLeft,
|
|
209
|
+
scrollHeight = _event$currentTarget.scrollHeight,
|
|
210
|
+
scrollWidth = _event$currentTarget.scrollWidth;
|
|
211
|
+
this.preset.field = {
|
|
212
|
+
scrollHeight: scrollHeight,
|
|
213
|
+
scrollWidth: this.itemList.getOffsetSize(),
|
|
214
|
+
scrollTop: scrollTop,
|
|
215
|
+
scrollLeft: scrollLeft,
|
|
216
|
+
clientHeight: scrollHeight,
|
|
217
|
+
clientWidth: scrollWidth
|
|
218
|
+
};
|
|
219
|
+
if (this.$props.onScrollNative) {
|
|
220
|
+
this.$props.onScrollNative(event);
|
|
221
|
+
}
|
|
222
|
+
var diffOffset = this.preset.field.scrollLeft - scrollLeft;
|
|
223
|
+
if (this.scrollOffset === scrollLeft || this.preset.isShaking(diffOffset)) {
|
|
224
|
+
return;
|
|
225
|
+
}
|
|
226
|
+
var scrollOffset = scrollLeft;
|
|
227
|
+
if (this.preset.isRtl) {
|
|
228
|
+
// TRICKY According to the spec, scrollLeft should be negative for RTL aligned elements.
|
|
229
|
+
// This is not the case for all browsers though (e.g. Chrome reports values as positive, measured relative to the left).
|
|
230
|
+
// It's also easier for this component if we convert offsets to the same format as they would be in for ltr.
|
|
231
|
+
// So the simplest solution is to determine which browser behavior we're dealing with, and convert based on it.
|
|
232
|
+
switch (getRTLOffsetType()) {
|
|
233
|
+
case 'negative':
|
|
234
|
+
scrollOffset = -scrollLeft;
|
|
235
|
+
break;
|
|
236
|
+
case 'positive-descending':
|
|
237
|
+
scrollOffset = scrollWidth - clientWidth - scrollLeft;
|
|
238
|
+
break;
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
// Prevent Safari's elastic scrolling from causing visual shaking when scrolling past bounds.
|
|
243
|
+
scrollOffset = Math.max(0, Math.min(scrollOffset, scrollWidth - clientWidth));
|
|
244
|
+
this.preset.field = {
|
|
245
|
+
scrollWidth: scrollOffset
|
|
246
|
+
};
|
|
247
|
+
this.isScrolling = true;
|
|
248
|
+
this.scrollDirection = this.scrollOffset < scrollLeft ? 'forward' : 'backward';
|
|
249
|
+
this.scrollOffset = scrollOffset;
|
|
250
|
+
this.scrollUpdateWasRequested = false;
|
|
251
|
+
this.$nextTick(this._resetIsScrollingDebounced);
|
|
252
|
+
},
|
|
253
|
+
_onScrollVertical: function _onScrollVertical(event) {
|
|
254
|
+
var _event$currentTarget2 = event.currentTarget,
|
|
255
|
+
clientHeight = _event$currentTarget2.clientHeight,
|
|
256
|
+
scrollHeight = _event$currentTarget2.scrollHeight,
|
|
257
|
+
scrollWidth = _event$currentTarget2.scrollWidth,
|
|
258
|
+
scrollTop = _event$currentTarget2.scrollTop,
|
|
259
|
+
scrollLeft = _event$currentTarget2.scrollLeft;
|
|
260
|
+
if (this.$props.onScrollNative) {
|
|
261
|
+
this.$props.onScrollNative(event);
|
|
262
|
+
}
|
|
263
|
+
var diffOffset = this.preset.field.scrollTop - scrollTop;
|
|
264
|
+
if (this.scrollOffset === scrollTop || this.preset.isShaking(diffOffset)) {
|
|
265
|
+
return;
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
// Prevent Safari's elastic scrolling from causing visual shaking when scrolling past bounds.
|
|
269
|
+
var scrollOffset = Math.max(0, Math.min(scrollTop, scrollHeight - clientHeight));
|
|
270
|
+
this.preset.field = {
|
|
271
|
+
scrollHeight: this.itemList.getOffsetSize(),
|
|
272
|
+
scrollWidth: scrollWidth,
|
|
273
|
+
scrollTop: scrollOffset,
|
|
274
|
+
scrollLeft: scrollLeft,
|
|
275
|
+
clientHeight: clientHeight,
|
|
276
|
+
clientWidth: scrollWidth,
|
|
277
|
+
diffOffset: this.preset.field.scrollTop - scrollOffset
|
|
278
|
+
};
|
|
279
|
+
this.isScrolling = true;
|
|
280
|
+
this.scrollDirection = this.scrollOffset < scrollOffset ? 'forward' : 'backward';
|
|
281
|
+
this.scrollOffset = scrollOffset;
|
|
282
|
+
this.scrollUpdateWasRequested = false;
|
|
283
|
+
this.$nextTick(this._resetIsScrollingDebounced);
|
|
284
|
+
},
|
|
285
|
+
_outerRefSetter: function _outerRefSetter(ref) {
|
|
286
|
+
var outerRef = this.$props.outerRef;
|
|
287
|
+
this._outerRef = ref;
|
|
288
|
+
if (typeof outerRef === 'function') {
|
|
289
|
+
outerRef(ref);
|
|
290
|
+
} else if (outerRef != null && _typeof(outerRef) === 'object' && outerRef.hasOwnProperty('value')) {
|
|
291
|
+
outerRef.value = ref;
|
|
292
|
+
}
|
|
293
|
+
},
|
|
294
|
+
_resetIsScrollingDebounced: function _resetIsScrollingDebounced() {
|
|
295
|
+
if (this.resetIsScrollingTimeoutId !== null) {
|
|
296
|
+
cancelTimeout(this.resetIsScrollingTimeoutId);
|
|
297
|
+
}
|
|
298
|
+
this.resetIsScrollingTimeoutId = requestTimeout(this._resetIsScrolling, IS_SCROLLING_DEBOUNCE_INTERVAL);
|
|
299
|
+
},
|
|
300
|
+
_resetIsScrolling: function _resetIsScrolling() {
|
|
301
|
+
var _this3 = this;
|
|
302
|
+
this.resetIsScrollingTimeoutId = null;
|
|
303
|
+
this.isScrolling = false;
|
|
304
|
+
this.$nextTick(function () {
|
|
305
|
+
_this3.preset.getItemStyleCache(-1, null);
|
|
306
|
+
});
|
|
307
|
+
}
|
|
308
|
+
},
|
|
309
|
+
mounted: function mounted() {
|
|
310
|
+
var initialScrollOffset = this.$props.initialScrollOffset;
|
|
311
|
+
if (typeof initialScrollOffset === 'number' && this._outerRef != null) {
|
|
312
|
+
var outerRef = this._outerRef;
|
|
313
|
+
if (this.preset.isHorizontal) {
|
|
314
|
+
outerRef.scrollLeft = initialScrollOffset;
|
|
315
|
+
} else {
|
|
316
|
+
outerRef.scrollTop = initialScrollOffset;
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
this._callPropsCallbacks();
|
|
320
|
+
},
|
|
321
|
+
updated: function updated() {
|
|
322
|
+
this.preset.update(this.$props);
|
|
323
|
+
var _this$$data = this.$data,
|
|
324
|
+
scrollOffset = _this$$data.scrollOffset,
|
|
325
|
+
scrollUpdateWasRequested = _this$$data.scrollUpdateWasRequested;
|
|
326
|
+
if (scrollUpdateWasRequested && this._outerRef != null) {
|
|
327
|
+
var outerRef = this._outerRef;
|
|
328
|
+
if (this.preset.isHorizontal) {
|
|
329
|
+
if (this.preset.isRtl) {
|
|
330
|
+
// TRICKY According to the spec, scrollLeft should be negative for RTL aligned elements.
|
|
331
|
+
// This is not the case for all browsers though (e.g. Chrome reports values as positive, measured relative to the left).
|
|
332
|
+
// So we need to determine which browser behavior we're dealing with, and mimic it.
|
|
333
|
+
switch (getRTLOffsetType()) {
|
|
334
|
+
case 'negative':
|
|
335
|
+
outerRef.scrollLeft = -scrollOffset;
|
|
336
|
+
break;
|
|
337
|
+
case 'positive-ascending':
|
|
338
|
+
outerRef.scrollLeft = scrollOffset;
|
|
339
|
+
break;
|
|
340
|
+
default:
|
|
341
|
+
{
|
|
342
|
+
var clientWidth = outerRef.clientWidth,
|
|
343
|
+
scrollWidth = outerRef.scrollWidth;
|
|
344
|
+
outerRef.scrollLeft = scrollWidth - clientWidth - scrollOffset;
|
|
345
|
+
break;
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
} else {
|
|
349
|
+
outerRef.scrollLeft = scrollOffset;
|
|
350
|
+
}
|
|
351
|
+
} else {
|
|
352
|
+
outerRef.scrollTop = scrollOffset;
|
|
353
|
+
}
|
|
354
|
+
}
|
|
355
|
+
this._callPropsCallbacks();
|
|
356
|
+
},
|
|
357
|
+
beforeDestroy: function beforeDestroy() {
|
|
358
|
+
if (this.resetIsScrollingTimeoutId !== null) {
|
|
359
|
+
cancelTimeout(this.resetIsScrollingTimeoutId);
|
|
360
|
+
}
|
|
361
|
+
},
|
|
362
|
+
render: function render() {
|
|
363
|
+
var _this4 = this;
|
|
364
|
+
var _omit = omit(this.$props, ['innerElementType', 'innerTagName', 'itemElementType', 'itemTagName', 'outerElementType', 'outerTagName', 'position']),
|
|
365
|
+
item = _omit.item,
|
|
366
|
+
direction = _omit.direction,
|
|
367
|
+
height = _omit.height,
|
|
368
|
+
innerRef = _omit.innerRef,
|
|
369
|
+
itemCount = _omit.itemCount,
|
|
370
|
+
itemData = _omit.itemData,
|
|
371
|
+
_omit$itemKey = _omit.itemKey,
|
|
372
|
+
itemKey = _omit$itemKey === void 0 ? defaultItemKey : _omit$itemKey,
|
|
373
|
+
layout = _omit.layout,
|
|
374
|
+
useIsScrolling = _omit.useIsScrolling,
|
|
375
|
+
width = _omit.width;
|
|
376
|
+
var _this$$data2 = this.$data,
|
|
377
|
+
id = _this$$data2.id,
|
|
378
|
+
isScrolling = _this$$data2.isScrolling,
|
|
379
|
+
scrollOffset = _this$$data2.scrollOffset,
|
|
380
|
+
scrollUpdateWasRequested = _this$$data2.scrollUpdateWasRequested;
|
|
381
|
+
var isHorizontal = this.preset.isHorizontal;
|
|
382
|
+
var placeholderCount = this.preset.placeholderCount;
|
|
383
|
+
var onScroll = isHorizontal ? this._onScrollHorizontal : this._onScrollVertical;
|
|
384
|
+
var _this$_getRangeToRend5 = this._getRangeToRender(),
|
|
385
|
+
_this$_getRangeToRend6 = _slicedToArray(_this$_getRangeToRend5, 2),
|
|
386
|
+
startIndex = _this$_getRangeToRend6[0],
|
|
387
|
+
stopIndex = _this$_getRangeToRend6[1];
|
|
388
|
+
var items = [];
|
|
389
|
+
if (itemCount > 0) {
|
|
390
|
+
var prevPlaceholder = startIndex < placeholderCount ? startIndex : placeholderCount;
|
|
391
|
+
items.push(new Array(prevPlaceholder).fill(-1).map(function (_, index) {
|
|
392
|
+
return _render(_this4.preset.itemTagName, {
|
|
393
|
+
key: itemKey(index + startIndex - prevPlaceholder, itemData),
|
|
394
|
+
style: {
|
|
395
|
+
display: 'none'
|
|
396
|
+
}
|
|
397
|
+
});
|
|
398
|
+
}));
|
|
399
|
+
for (var index = startIndex; index <= stopIndex; index++) {
|
|
400
|
+
var style = this.preset.getItemStyle(index);
|
|
401
|
+
items.push(_render(this.preset.itemTagName, {
|
|
402
|
+
key: itemKey(index, itemData),
|
|
403
|
+
style: style
|
|
404
|
+
}, [_render(item, {
|
|
405
|
+
id: "".concat(id, "-").concat(index),
|
|
406
|
+
props: {
|
|
407
|
+
id: "".concat(id, "-").concat(index),
|
|
408
|
+
data: itemData,
|
|
409
|
+
index: index,
|
|
410
|
+
isScrolling: useIsScrolling ? isScrolling : undefined
|
|
411
|
+
}
|
|
412
|
+
})]));
|
|
413
|
+
}
|
|
414
|
+
var restCount = itemCount - stopIndex;
|
|
415
|
+
var postPlaceholder = restCount < placeholderCount ? restCount : placeholderCount;
|
|
416
|
+
items.push(new Array(postPlaceholder).fill(-1).map(function (_, index) {
|
|
417
|
+
return _render(_this4.preset.itemTagName, {
|
|
418
|
+
key: itemKey(1 + index + stopIndex, itemData),
|
|
419
|
+
style: {
|
|
420
|
+
display: 'none'
|
|
421
|
+
}
|
|
422
|
+
});
|
|
423
|
+
}));
|
|
424
|
+
}
|
|
425
|
+
|
|
426
|
+
// Read this value AFTER items have been created,
|
|
427
|
+
// So their actual sizes (if variable) are taken into consideration.
|
|
428
|
+
var estimatedTotalSize = convertNumber2PX(this.itemList.getOffsetSize());
|
|
429
|
+
var outerElementProps = {
|
|
430
|
+
id: id,
|
|
431
|
+
ref: this._outerRefSetter,
|
|
432
|
+
layout: layout,
|
|
433
|
+
style: {
|
|
434
|
+
position: 'relative',
|
|
435
|
+
height: convertNumber2PX(height),
|
|
436
|
+
width: convertNumber2PX(width),
|
|
437
|
+
overflow: 'auto',
|
|
438
|
+
WebkitOverflowScrolling: 'touch',
|
|
439
|
+
willChange: 'transform',
|
|
440
|
+
direction: direction
|
|
441
|
+
},
|
|
442
|
+
attrs: {
|
|
443
|
+
scrollY: layout === 'vertical',
|
|
444
|
+
scrollX: layout === 'horizontal'
|
|
445
|
+
},
|
|
446
|
+
on: {
|
|
447
|
+
scroll: onScroll
|
|
448
|
+
}
|
|
449
|
+
};
|
|
450
|
+
if (isHorizontal) {
|
|
451
|
+
outerElementProps.scrollLeft = scrollUpdateWasRequested ? scrollOffset : this.preset.field.scrollLeft;
|
|
452
|
+
} else {
|
|
453
|
+
outerElementProps.scrollTop = scrollUpdateWasRequested ? scrollOffset : this.preset.field.scrollTop;
|
|
454
|
+
}
|
|
455
|
+
if (this.preset.isRelative) {
|
|
456
|
+
var _this$$slots$top, _this$$slots, _this$$slots$bottom, _this$$slots2;
|
|
457
|
+
var pre = convertNumber2PX(this.itemList.getOffsetSize(startIndex));
|
|
458
|
+
return _render(this.preset.outerTagName, outerElementProps, [process.env.FRAMEWORK === 'vue3' ? (_this$$slots$top = (_this$$slots = this.$slots).top) === null || _this$$slots$top === void 0 ? void 0 : _this$$slots$top.call(_this$$slots) : this.$slots.top, _render(this.preset.itemTagName, {
|
|
459
|
+
key: "".concat(id, "-pre"),
|
|
460
|
+
id: "".concat(id, "-pre"),
|
|
461
|
+
style: {
|
|
462
|
+
height: isHorizontal ? '100%' : pre,
|
|
463
|
+
width: !isHorizontal ? '100%' : pre
|
|
464
|
+
}
|
|
465
|
+
}), _render(this.preset.innerTagName, {
|
|
466
|
+
ref: innerRef,
|
|
467
|
+
key: "".concat(id, "-inner"),
|
|
468
|
+
id: "".concat(id, "-inner"),
|
|
469
|
+
style: {
|
|
470
|
+
pointerEvents: isScrolling ? 'none' : 'auto',
|
|
471
|
+
position: 'relative'
|
|
472
|
+
}
|
|
473
|
+
}, items), process.env.FRAMEWORK === 'vue3' ? (_this$$slots$bottom = (_this$$slots2 = this.$slots).bottom) === null || _this$$slots$bottom === void 0 ? void 0 : _this$$slots$bottom.call(_this$$slots2) : this.$slots.bottom]);
|
|
474
|
+
} else {
|
|
475
|
+
var _this$$slots$top2, _this$$slots3, _this$$slots$bottom2, _this$$slots4;
|
|
476
|
+
return _render(this.preset.outerTagName, outerElementProps, [process.env.FRAMEWORK === 'vue3' ? (_this$$slots$top2 = (_this$$slots3 = this.$slots).top) === null || _this$$slots$top2 === void 0 ? void 0 : _this$$slots$top2.call(_this$$slots3) : this.$slots.top, _render(this.preset.innerTagName, {
|
|
477
|
+
ref: innerRef,
|
|
478
|
+
key: "".concat(id, "-inner"),
|
|
479
|
+
id: "".concat(id, "-inner"),
|
|
480
|
+
style: {
|
|
481
|
+
height: isHorizontal ? '100%' : estimatedTotalSize,
|
|
482
|
+
pointerEvents: isScrolling ? 'none' : 'auto',
|
|
483
|
+
position: 'relative',
|
|
484
|
+
width: !isHorizontal ? '100%' : estimatedTotalSize
|
|
485
|
+
}
|
|
486
|
+
}, items), process.env.FRAMEWORK === 'vue3' ? (_this$$slots$bottom2 = (_this$$slots4 = this.$slots).bottom) === null || _this$$slots$bottom2 === void 0 ? void 0 : _this$$slots$bottom2.call(_this$$slots4) : this.$slots.bottom]);
|
|
487
|
+
}
|
|
488
|
+
}
|
|
489
|
+
};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
|
|
2
|
+
import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
|
|
3
|
+
var _excluded = ["attrs", "on", "props", "slots"];
|
|
4
|
+
import { h } from 'vue';
|
|
5
|
+
export default function (componentName, options, children) {
|
|
6
|
+
var _options$attrs = options.attrs,
|
|
7
|
+
attrs = _options$attrs === void 0 ? {} : _options$attrs,
|
|
8
|
+
_options$on = options.on,
|
|
9
|
+
on = _options$on === void 0 ? {} : _options$on,
|
|
10
|
+
_options$props = options.props,
|
|
11
|
+
props = _options$props === void 0 ? {} : _options$props,
|
|
12
|
+
_options$slots = options.slots,
|
|
13
|
+
slots = _options$slots === void 0 ? {} : _options$slots,
|
|
14
|
+
el = _objectWithoutProperties(options, _excluded);
|
|
15
|
+
if (process.env.FRAMEWORK === 'vue3') {
|
|
16
|
+
// Events
|
|
17
|
+
Object.keys(on).forEach(function (key) {
|
|
18
|
+
var name = "on".concat(key.charAt(0).toUpperCase()).concat(key.slice(1));
|
|
19
|
+
el[name] = on[key];
|
|
20
|
+
});
|
|
21
|
+
return h(componentName, _objectSpread(_objectSpread(_objectSpread(_objectSpread({}, attrs), props), slots), el), children);
|
|
22
|
+
}
|
|
23
|
+
return h(componentName, options, children);
|
|
24
|
+
}
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/** 将距离值根据单位转换为 Number 类型
|
|
2
|
+
* TODO: 未来可以考虑支持更多单位
|
|
3
|
+
*/
|
|
4
|
+
export function convertPX2Int(distance) {
|
|
5
|
+
if (typeof distance === 'string') {
|
|
6
|
+
var str = distance.toLowerCase();
|
|
7
|
+
if (/px$/.test(str)) {
|
|
8
|
+
return Number(str.replace(/px$/, ''));
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
return distance;
|
|
12
|
+
}
|
|
13
|
+
export function convertNumber2PX(styleValue) {
|
|
14
|
+
if (!styleValue && styleValue !== 0) return '';
|
|
15
|
+
return typeof styleValue === 'number' ? styleValue + 'px' : styleValue;
|
|
16
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function omit<T extends Record<string, unknown> = Record<string, any>, P extends string = ''>(obj?: T, fields?: P[]): Omit<T, P>;
|