@tarojs/components-advanced 3.6.0-beta.2 → 3.6.0-beta.4

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