@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,481 +1,378 @@
1
- import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
2
- import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
3
- import _typeof from "@babel/runtime/helpers/esm/typeof";
4
- import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
5
- import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
6
- import _createClass from "@babel/runtime/helpers/esm/createClass";
7
- import _assertThisInitialized from "@babel/runtime/helpers/esm/assertThisInitialized";
8
- import _inherits from "@babel/runtime/helpers/esm/inherits";
9
- import _createSuper from "@babel/runtime/helpers/esm/createSuper";
10
- import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
11
- var _excluded = ["className", "direction", "height", "innerRef", "item", "itemCount", "itemData", "itemKey", "layout", "style", "useIsScrolling", "width", "renderTop", "renderBottom"];
1
+ import { __rest } from 'tslib';
12
2
  import memoizeOne from 'memoize-one';
13
3
  import React from 'react';
14
- import { convertNumber2PX } from '../../../utils/convert';
15
- import { omit } from '../../../utils/lodash';
16
- import { cancelTimeout, requestTimeout } from '../../../utils/timer';
17
- import { IS_SCROLLING_DEBOUNCE_INTERVAL } from '../constants';
18
- import { getRTLOffsetType } from '../dom-helpers';
19
- import Preset from '../preset';
20
- import { defaultItemKey, getRectSize } from '../utils';
21
- import { validateListProps } from './validate';
22
- var List = /*#__PURE__*/function (_React$PureComponent) {
23
- _inherits(List, _React$PureComponent);
24
- var _super = _createSuper(List);
25
- function List(props) {
26
- var _this;
27
- _classCallCheck(this, List);
28
- _this = _super.call(this, props);
29
- _defineProperty(_assertThisInitialized(_this), "itemList", void 0);
30
- _defineProperty(_assertThisInitialized(_this), "preset", void 0);
31
- _defineProperty(_assertThisInitialized(_this), "refresh", function () {
32
- if (process.env.FRAMEWORK === 'preact') {
33
- _this.forceUpdate();
34
- } else {
35
- _this.setState(function (_ref) {
36
- var refreshCount = _ref.refreshCount;
37
- return {
38
- refreshCount: ++refreshCount
39
- };
40
- });
41
- }
42
- });
43
- _defineProperty(_assertThisInitialized(_this), "_outerRef", undefined);
44
- _defineProperty(_assertThisInitialized(_this), "_resetIsScrollingTimeoutId", null);
45
- _defineProperty(_assertThisInitialized(_this), "_callOnItemsRendered", memoizeOne(function (overscanStartIndex, overscanStopIndex, visibleStartIndex, visibleStopIndex) {
46
- return _this.props.onItemsRendered({
47
- overscanStartIndex: overscanStartIndex,
48
- overscanStopIndex: overscanStopIndex,
49
- visibleStartIndex: visibleStartIndex,
50
- visibleStopIndex: visibleStopIndex
51
- });
52
- }));
53
- _defineProperty(_assertThisInitialized(_this), "_callOnScroll", memoizeOne(function (scrollDirection, scrollOffset, scrollUpdateWasRequested, detail) {
54
- return _this.props.onScroll({
55
- scrollDirection: scrollDirection,
56
- scrollOffset: scrollOffset,
57
- scrollUpdateWasRequested: scrollUpdateWasRequested,
58
- detail: detail
59
- });
60
- }));
61
- _defineProperty(_assertThisInitialized(_this), "_getSizeUploadSync", function (index, isHorizontal) {
62
- var ID = "#".concat(_this.state.id, "-").concat(index);
63
- return new Promise(function (resolve) {
64
- var success = function success(_ref2) {
65
- var width = _ref2.width,
66
- height = _ref2.height;
67
- var size = isHorizontal ? width : height;
68
- if (!_this.itemList.compareSize(index, size)) {
69
- _this.itemList.setSize(index, size);
70
- resolve(_this.itemList.getSize(index));
71
- }
4
+ import { convertNumber2PX } from '../../../utils/convert.js';
5
+ import { omit } from '../../../utils/lodash.js';
6
+ import { cancelTimeout, requestTimeout } from '../../../utils/timer.js';
7
+ import { IS_SCROLLING_DEBOUNCE_INTERVAL } from '../constants.js';
8
+ import { getRTLOffsetType } from '../dom-helpers.js';
9
+ import Preset from '../preset.js';
10
+ import { getRectSize, defaultItemKey } from '../utils.js';
11
+ import { validateListProps } from './validate.js';
12
+
13
+ class List extends React.PureComponent {
14
+ constructor(props) {
15
+ super(props);
16
+ // FIXME Warning: Cannot update during an existing state transition (such as within `render`).
17
+ this.refresh = () => {
18
+ if (process.env.FRAMEWORK === 'preact') {
19
+ this.forceUpdate();
20
+ }
21
+ else {
22
+ this.setState(({ refreshCount }) => ({
23
+ refreshCount: ++refreshCount
24
+ }));
25
+ }
72
26
  };
73
- var fail = function fail() {
74
- var _this$_getRangeToRend = _this._getRangeToRender(),
75
- _this$_getRangeToRend2 = _slicedToArray(_this$_getRangeToRend, 2),
76
- startIndex = _this$_getRangeToRend2[0],
77
- stopIndex = _this$_getRangeToRend2[1];
78
- if (index >= startIndex && index <= stopIndex) {
79
- setTimeout(function () {
80
- getRectSize(ID, success, fail);
81
- }, 100);
82
- }
27
+ this._outerRef = undefined;
28
+ this._resetIsScrollingTimeoutId = null;
29
+ this._callOnItemsRendered = memoizeOne((overscanStartIndex, overscanStopIndex, visibleStartIndex, visibleStopIndex) => this.props.onItemsRendered({
30
+ overscanStartIndex,
31
+ overscanStopIndex,
32
+ visibleStartIndex,
33
+ visibleStopIndex
34
+ }));
35
+ // FIXME 优化事件信息
36
+ this._callOnScroll = memoizeOne((scrollDirection, scrollOffset, scrollUpdateWasRequested, detail) => this.props.onScroll({
37
+ scrollDirection,
38
+ scrollOffset,
39
+ scrollUpdateWasRequested,
40
+ detail
41
+ }));
42
+ this._getSizeUploadSync = (index, isHorizontal) => {
43
+ const ID = `#${this.state.id}-${index}`;
44
+ return new Promise((resolve) => {
45
+ const success = ({ width, height }) => {
46
+ const size = isHorizontal ? width : height;
47
+ if (!this.itemList.compareSize(index, size)) {
48
+ this.itemList.setSize(index, size);
49
+ resolve(this.itemList.getSize(index));
50
+ }
51
+ };
52
+ const fail = () => {
53
+ const [startIndex, stopIndex] = this._getRangeToRender();
54
+ if (index >= startIndex && index <= stopIndex) {
55
+ setTimeout(() => {
56
+ getRectSize(ID, success, fail);
57
+ }, 100);
58
+ }
59
+ };
60
+ getRectSize(ID, success, fail);
61
+ });
83
62
  };
84
- getRectSize(ID, success, fail);
85
- });
86
- });
87
- _defineProperty(_assertThisInitialized(_this), "_onScrollHorizontal", function (event) {
88
- var _event$currentTarget = event.currentTarget,
89
- clientWidth = _event$currentTarget.clientWidth,
90
- scrollTop = _event$currentTarget.scrollTop,
91
- scrollLeft = _event$currentTarget.scrollLeft,
92
- scrollHeight = _event$currentTarget.scrollHeight,
93
- scrollWidth = _event$currentTarget.scrollWidth;
94
- _this.preset.field = {
95
- scrollHeight: scrollHeight,
96
- scrollWidth: _this.itemList.getOffsetSize(),
97
- scrollTop: scrollTop,
98
- scrollLeft: scrollLeft,
99
- clientHeight: scrollHeight,
100
- clientWidth: scrollWidth
101
- };
102
- _this.setState(function (prevState) {
103
- var diffOffset = _this.preset.field.scrollLeft - scrollLeft;
104
- if (prevState.scrollOffset === scrollLeft || _this.preset.isShaking(diffOffset)) {
105
- // Scroll position may have been updated by cDM/cDU,
106
- // In which case we don't need to trigger another render,
107
- // And we don't want to update state.isScrolling.
108
- return null;
109
- }
110
- var scrollOffset = scrollLeft;
111
- if (_this.preset.isRtl) {
112
- // TRICKY According to the spec, scrollLeft should be negative for RTL aligned elements.
113
- // This is not the case for all browsers though (e.g. Chrome reports values as positive, measured relative to the left).
114
- // It's also easier for this component if we convert offsets to the same format as they would be in for ltr.
115
- // So the simplest solution is to determine which browser behavior we're dealing with, and convert based on it.
116
- switch (getRTLOffsetType()) {
117
- case 'negative':
118
- scrollOffset = -scrollLeft;
119
- break;
120
- case 'positive-descending':
121
- scrollOffset = scrollWidth - clientWidth - scrollLeft;
122
- break;
123
- }
124
- } // Prevent Safari's elastic scrolling from causing visual shaking when scrolling past bounds.
125
-
126
- _this.preset.field = {
127
- scrollWidth: scrollOffset
63
+ this._onScrollHorizontal = event => {
64
+ const { clientWidth, scrollTop, scrollLeft, scrollHeight, scrollWidth } = event.currentTarget;
65
+ this.preset.field = {
66
+ scrollHeight: scrollHeight,
67
+ scrollWidth: this.itemList.getOffsetSize(),
68
+ scrollTop: scrollTop,
69
+ scrollLeft: scrollLeft,
70
+ clientHeight: scrollHeight,
71
+ clientWidth: scrollWidth
72
+ };
73
+ this.setState((prevState) => {
74
+ const diffOffset = this.preset.field.scrollLeft - scrollLeft;
75
+ if (prevState.scrollOffset === scrollLeft || this.preset.isShaking(diffOffset)) {
76
+ // Scroll position may have been updated by cDM/cDU,
77
+ // In which case we don't need to trigger another render,
78
+ // And we don't want to update state.isScrolling.
79
+ return null;
80
+ }
81
+ let scrollOffset = scrollLeft;
82
+ if (this.preset.isRtl) {
83
+ // TRICKY According to the spec, scrollLeft should be negative for RTL aligned elements.
84
+ // This is not the case for all browsers though (e.g. Chrome reports values as positive, measured relative to the left).
85
+ // It's also easier for this component if we convert offsets to the same format as they would be in for ltr.
86
+ // So the simplest solution is to determine which browser behavior we're dealing with, and convert based on it.
87
+ switch (getRTLOffsetType()) {
88
+ case 'negative':
89
+ scrollOffset = -scrollLeft;
90
+ break;
91
+ case 'positive-descending':
92
+ scrollOffset = scrollWidth - clientWidth - scrollLeft;
93
+ break;
94
+ }
95
+ } // Prevent Safari's elastic scrolling from causing visual shaking when scrolling past bounds.
96
+ this.preset.field = {
97
+ scrollWidth: scrollOffset,
98
+ };
99
+ return {
100
+ isScrolling: true,
101
+ scrollDirection: prevState.scrollOffset < scrollLeft ? 'forward' : 'backward',
102
+ scrollOffset,
103
+ scrollUpdateWasRequested: false
104
+ };
105
+ }, this._resetIsScrollingDebounced);
128
106
  };
129
- return {
130
- isScrolling: true,
131
- scrollDirection: prevState.scrollOffset < scrollLeft ? 'forward' : 'backward',
132
- scrollOffset: scrollOffset,
133
- scrollUpdateWasRequested: false
107
+ this._onScrollVertical = event => {
108
+ const { clientHeight, scrollHeight, scrollWidth, scrollTop, scrollLeft } = event.currentTarget;
109
+ this.setState((prevState) => {
110
+ const diffOffset = this.preset.field.scrollTop - scrollTop;
111
+ if (prevState.scrollOffset === scrollTop || this.preset.isShaking(diffOffset)) {
112
+ // Scroll position may have been updated by cDM/cDU,
113
+ // In which case we don't need to trigger another render,
114
+ // And we don't want to update state.isScrolling.
115
+ return null;
116
+ }
117
+ // FIXME preact 中使用时,该组件会出现触底滚动事件重复触发导致的抖动问题,后续修复
118
+ // Prevent Safari's elastic scrolling from causing visual shaking when scrolling past bounds.
119
+ const scrollOffset = Math.max(0, Math.min(scrollTop, scrollHeight - clientHeight));
120
+ this.preset.field = {
121
+ scrollHeight: this.itemList.getOffsetSize(),
122
+ scrollWidth: scrollWidth,
123
+ scrollTop: scrollOffset,
124
+ scrollLeft: scrollLeft,
125
+ clientHeight: clientHeight,
126
+ clientWidth: scrollWidth,
127
+ diffOffset: this.preset.field.scrollTop - scrollOffset,
128
+ };
129
+ return {
130
+ isScrolling: true,
131
+ scrollDirection: prevState.scrollOffset < scrollOffset ? 'forward' : 'backward',
132
+ scrollOffset,
133
+ scrollUpdateWasRequested: false
134
+ };
135
+ }, this._resetIsScrollingDebounced);
134
136
  };
135
- }, _this._resetIsScrollingDebounced);
136
- });
137
- _defineProperty(_assertThisInitialized(_this), "_onScrollVertical", function (event) {
138
- var _event$currentTarget2 = event.currentTarget,
139
- clientHeight = _event$currentTarget2.clientHeight,
140
- scrollHeight = _event$currentTarget2.scrollHeight,
141
- scrollWidth = _event$currentTarget2.scrollWidth,
142
- scrollTop = _event$currentTarget2.scrollTop,
143
- scrollLeft = _event$currentTarget2.scrollLeft;
144
- _this.setState(function (prevState) {
145
- var diffOffset = _this.preset.field.scrollTop - scrollTop;
146
- if (prevState.scrollOffset === scrollTop || _this.preset.isShaking(diffOffset)) {
147
- // Scroll position may have been updated by cDM/cDU,
148
- // In which case we don't need to trigger another render,
149
- // And we don't want to update state.isScrolling.
150
- return null;
151
- }
152
- // FIXME preact 中使用时,该组件会出现触底滚动事件重复触发导致的抖动问题,后续修复
153
- // Prevent Safari's elastic scrolling from causing visual shaking when scrolling past bounds.
154
- var scrollOffset = Math.max(0, Math.min(scrollTop, scrollHeight - clientHeight));
155
- _this.preset.field = {
156
- scrollHeight: _this.itemList.getOffsetSize(),
157
- scrollWidth: scrollWidth,
158
- scrollTop: scrollOffset,
159
- scrollLeft: scrollLeft,
160
- clientHeight: clientHeight,
161
- clientWidth: scrollWidth,
162
- diffOffset: _this.preset.field.scrollTop - scrollOffset
137
+ this._outerRefSetter = ref => {
138
+ const { outerRef } = this.props;
139
+ this._outerRef = ref;
140
+ if (typeof outerRef === 'function') {
141
+ outerRef(ref);
142
+ }
143
+ else if (outerRef != null && typeof outerRef === 'object' && outerRef.hasOwnProperty('current')) {
144
+ // @ts-ignore
145
+ outerRef.current = ref;
146
+ }
163
147
  };
164
- return {
165
- isScrolling: true,
166
- scrollDirection: prevState.scrollOffset < scrollOffset ? 'forward' : 'backward',
167
- scrollOffset: scrollOffset,
168
- scrollUpdateWasRequested: false
148
+ this._resetIsScrollingDebounced = () => {
149
+ if (this._resetIsScrollingTimeoutId !== null) {
150
+ cancelTimeout(this._resetIsScrollingTimeoutId);
151
+ }
152
+ this._resetIsScrollingTimeoutId = requestTimeout(this._resetIsScrolling, IS_SCROLLING_DEBOUNCE_INTERVAL);
169
153
  };
170
- }, _this._resetIsScrollingDebounced);
171
- });
172
- _defineProperty(_assertThisInitialized(_this), "_outerRefSetter", function (ref) {
173
- var outerRef = _this.props.outerRef;
174
- _this._outerRef = ref;
175
- if (typeof outerRef === 'function') {
176
- outerRef(ref);
177
- } else if (outerRef != null && _typeof(outerRef) === 'object' && outerRef.hasOwnProperty('current')) {
178
- // @ts-ignore
179
- outerRef.current = ref;
180
- }
181
- });
182
- _defineProperty(_assertThisInitialized(_this), "_resetIsScrollingDebounced", function () {
183
- if (_this._resetIsScrollingTimeoutId !== null) {
184
- cancelTimeout(_this._resetIsScrollingTimeoutId);
185
- }
186
- _this._resetIsScrollingTimeoutId = requestTimeout(_this._resetIsScrolling, IS_SCROLLING_DEBOUNCE_INTERVAL);
187
- });
188
- _defineProperty(_assertThisInitialized(_this), "_resetIsScrolling", function () {
189
- _this._resetIsScrollingTimeoutId = null;
190
- _this.setState({
191
- isScrolling: false
192
- }, function () {
193
- // Clear style cache after state update has been committed.
194
- // This way we don't break pure sCU for items that don't use isScrolling param.
195
- _this.preset.getItemStyleCache(-1, null);
196
- });
197
- });
198
- _this.preset = new Preset(props, _this.refresh);
199
- _this.itemList = _this.preset.itemList;
200
- _this.state = {
201
- id: _this.props.id || _this.preset.id,
202
- instance: _assertThisInitialized(_this),
203
- isScrolling: false,
204
- scrollDirection: 'forward',
205
- scrollOffset: typeof _this.props.initialScrollOffset === 'number' ? _this.props.initialScrollOffset : 0,
206
- scrollUpdateWasRequested: false,
207
- refreshCount: 0
208
- };
209
- return _this;
210
- }
211
-
212
- // FIXME Warning: Cannot update during an existing state transition (such as within `render`).
213
- _createClass(List, [{
214
- key: "_callPropsCallbacks",
215
- value: function _callPropsCallbacks() {
216
- var _this2 = this;
217
- var prevProps = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
218
- var prevState = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
219
- if (typeof this.props.onItemsRendered === 'function') {
220
- if (this.props.itemCount > 0) {
221
- if (prevProps && prevProps.itemCount !== this.props.itemCount) {
222
- var _this$_getRangeToRend3 = this._getRangeToRender(),
223
- _this$_getRangeToRend4 = _slicedToArray(_this$_getRangeToRend3, 4),
224
- overscanStartIndex = _this$_getRangeToRend4[0],
225
- overscanStopIndex = _this$_getRangeToRend4[1],
226
- visibleStartIndex = _this$_getRangeToRend4[2],
227
- visibleStopIndex = _this$_getRangeToRend4[3];
228
- this._callOnItemsRendered(overscanStartIndex, overscanStopIndex, visibleStartIndex, visibleStopIndex);
229
- }
230
- }
231
- }
232
- if (typeof this.props.onScroll === 'function') {
233
- if (!prevState || prevState.scrollDirection !== this.state.scrollDirection || prevState.scrollOffset !== this.state.scrollOffset || prevState.scrollUpdateWasRequested !== this.state.scrollUpdateWasRequested) {
234
- this._callOnScroll(this.state.scrollDirection, this.state.scrollOffset, this.state.scrollUpdateWasRequested, this.preset.field);
154
+ this._resetIsScrolling = () => {
155
+ this._resetIsScrollingTimeoutId = null;
156
+ this.setState({
157
+ isScrolling: false
158
+ }, () => {
159
+ // Clear style cache after state update has been committed.
160
+ // This way we don't break pure sCU for items that don't use isScrolling param.
161
+ this.preset.getItemStyleCache(-1, null);
162
+ });
163
+ };
164
+ this.preset = new Preset(props, this.refresh);
165
+ this.itemList = this.preset.itemList;
166
+ this.state = {
167
+ id: this.props.id || this.preset.id,
168
+ instance: this,
169
+ isScrolling: false,
170
+ scrollDirection: 'forward',
171
+ scrollOffset: typeof this.props.initialScrollOffset === 'number'
172
+ ? this.props.initialScrollOffset
173
+ : 0,
174
+ scrollUpdateWasRequested: false,
175
+ refreshCount: 0
176
+ };
177
+ }
178
+ static getDerivedStateFromProps(nextProps, prevState) {
179
+ return validateListProps(nextProps, prevState);
180
+ }
181
+ _callPropsCallbacks(prevProps = {}, prevState = {}) {
182
+ if (typeof this.props.onItemsRendered === 'function') {
183
+ if (this.props.itemCount > 0) {
184
+ if (prevProps && prevProps.itemCount !== this.props.itemCount) {
185
+ const [overscanStartIndex, overscanStopIndex, visibleStartIndex, visibleStopIndex] = this._getRangeToRender();
186
+ this._callOnItemsRendered(overscanStartIndex, overscanStopIndex, visibleStartIndex, visibleStopIndex);
187
+ }
188
+ }
235
189
  }
236
- }
237
- setTimeout(function () {
238
- var _this2$_getRangeToRen = _this2._getRangeToRender(),
239
- _this2$_getRangeToRen2 = _slicedToArray(_this2$_getRangeToRen, 2),
240
- startIndex = _this2$_getRangeToRen2[0],
241
- stopIndex = _this2$_getRangeToRen2[1];
242
- var isHorizontal = _this2.preset.isHorizontal;
243
- for (var index = startIndex; index <= stopIndex; index++) {
244
- _this2._getSizeUploadSync(index, isHorizontal);
190
+ if (typeof this.props.onScroll === 'function') {
191
+ if (!prevState ||
192
+ prevState.scrollDirection !== this.state.scrollDirection ||
193
+ prevState.scrollOffset !== this.state.scrollOffset ||
194
+ prevState.scrollUpdateWasRequested !== this.state.scrollUpdateWasRequested) {
195
+ this._callOnScroll(this.state.scrollDirection, this.state.scrollOffset, this.state.scrollUpdateWasRequested, this.preset.field);
196
+ }
245
197
  }
246
- }, 0);
198
+ setTimeout(() => {
199
+ const [startIndex, stopIndex] = this._getRangeToRender();
200
+ const isHorizontal = this.preset.isHorizontal;
201
+ for (let index = startIndex; index <= stopIndex; index++) {
202
+ this._getSizeUploadSync(index, isHorizontal);
203
+ }
204
+ }, 0);
247
205
  }
248
- }, {
249
- key: "_getRangeToRender",
250
- value:
251
206
  // Lazily create and cache item styles while scrolling,
252
207
  // So that pure component sCU will prevent re-renders.
253
208
  // We maintain this cache, and pass a style prop rather than index,
254
209
  // So that List can clear cached styles and force item re-render if necessary.
255
- function _getRangeToRender() {
256
- return this.itemList.getRangeToRender(this.state.scrollDirection, this.state.scrollOffset, this.state.isScrolling);
210
+ _getRangeToRender() {
211
+ return this.itemList.getRangeToRender(this.state.scrollDirection, this.state.scrollOffset, this.state.isScrolling);
257
212
  }
258
- }, {
259
- key: "scrollTo",
260
- value: function scrollTo(scrollOffset) {
261
- scrollOffset = Math.max(0, scrollOffset);
262
- this.setState(function (prevState) {
263
- if (prevState.scrollOffset === scrollOffset) {
264
- return null;
265
- }
266
- return {
267
- scrollDirection: prevState.scrollOffset < scrollOffset ? 'forward' : 'backward',
268
- scrollOffset: scrollOffset,
269
- scrollUpdateWasRequested: true
270
- };
271
- }, this._resetIsScrollingDebounced);
213
+ scrollTo(scrollOffset) {
214
+ scrollOffset = Math.max(0, scrollOffset);
215
+ this.setState((prevState) => {
216
+ if (prevState.scrollOffset === scrollOffset) {
217
+ return null;
218
+ }
219
+ return {
220
+ scrollDirection: prevState.scrollOffset < scrollOffset ? 'forward' : 'backward',
221
+ scrollOffset: scrollOffset,
222
+ scrollUpdateWasRequested: true
223
+ };
224
+ }, this._resetIsScrollingDebounced);
272
225
  }
273
- }, {
274
- key: "scrollToItem",
275
- value: function scrollToItem(index) {
276
- var align = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'auto';
277
- var itemCount = this.props.itemCount;
278
- var scrollOffset = this.state.scrollOffset;
279
- index = Math.max(0, Math.min(index, itemCount - 1));
280
- this.scrollTo(this.itemList.getOffsetForIndexAndAlignment(index, align, scrollOffset));
226
+ scrollToItem(index, align = 'auto') {
227
+ const { itemCount } = this.props;
228
+ const { scrollOffset } = this.state;
229
+ index = Math.max(0, Math.min(index, itemCount - 1));
230
+ this.scrollTo(this.itemList.getOffsetForIndexAndAlignment(index, align, scrollOffset));
281
231
  }
282
- }, {
283
- key: "componentDidMount",
284
- value: function componentDidMount() {
285
- var initialScrollOffset = this.props.initialScrollOffset;
286
- if (typeof initialScrollOffset === 'number' && this._outerRef != null) {
287
- var outerRef = this._outerRef;
288
- if (this.preset.isHorizontal) {
289
- outerRef.scrollLeft = initialScrollOffset;
290
- } else {
291
- outerRef.scrollTop = initialScrollOffset;
232
+ componentDidMount() {
233
+ const { initialScrollOffset } = this.props;
234
+ if (typeof initialScrollOffset === 'number' && this._outerRef != null) {
235
+ const outerRef = this._outerRef;
236
+ if (this.preset.isHorizontal) {
237
+ outerRef.scrollLeft = initialScrollOffset;
238
+ }
239
+ else {
240
+ outerRef.scrollTop = initialScrollOffset;
241
+ }
292
242
  }
293
- }
294
- this._callPropsCallbacks();
243
+ this._callPropsCallbacks();
295
244
  }
296
- }, {
297
- key: "componentDidUpdate",
298
- value: function componentDidUpdate(prevProps, prevState) {
299
- var _this$state = this.state,
300
- scrollOffset = _this$state.scrollOffset,
301
- scrollUpdateWasRequested = _this$state.scrollUpdateWasRequested;
302
- this.preset.update(this.props);
303
- if (scrollUpdateWasRequested && this._outerRef != null) {
304
- var outerRef = this._outerRef;
305
- if (this.preset.isHorizontal) {
306
- if (this.preset.isRtl) {
307
- // TRICKY According to the spec, scrollLeft should be negative for RTL aligned elements.
308
- // This is not the case for all browsers though (e.g. Chrome reports values as positive, measured relative to the left).
309
- // So we need to determine which browser behavior we're dealing with, and mimic it.
310
- switch (getRTLOffsetType()) {
311
- case 'negative':
312
- outerRef.scrollLeft = -scrollOffset;
313
- break;
314
- case 'positive-ascending':
315
- outerRef.scrollLeft = scrollOffset;
316
- break;
317
- default:
318
- outerRef.scrollLeft = outerRef.scrollWidth - outerRef.clientWidth - scrollOffset;
319
- break;
245
+ componentDidUpdate(prevProps, prevState) {
246
+ const { scrollOffset, scrollUpdateWasRequested } = this.state;
247
+ this.preset.update(this.props);
248
+ if (scrollUpdateWasRequested && this._outerRef != null) {
249
+ const outerRef = this._outerRef;
250
+ if (this.preset.isHorizontal) {
251
+ if (this.preset.isRtl) {
252
+ // TRICKY According to the spec, scrollLeft should be negative for RTL aligned elements.
253
+ // This is not the case for all browsers though (e.g. Chrome reports values as positive, measured relative to the left).
254
+ // So we need to determine which browser behavior we're dealing with, and mimic it.
255
+ switch (getRTLOffsetType()) {
256
+ case 'negative':
257
+ outerRef.scrollLeft = -scrollOffset;
258
+ break;
259
+ case 'positive-ascending':
260
+ outerRef.scrollLeft = scrollOffset;
261
+ break;
262
+ default:
263
+ outerRef.scrollLeft = outerRef.scrollWidth - outerRef.clientWidth - scrollOffset;
264
+ break;
265
+ }
266
+ }
267
+ else {
268
+ outerRef.scrollLeft = scrollOffset;
269
+ }
270
+ }
271
+ else {
272
+ outerRef.scrollTop = scrollOffset;
320
273
  }
321
- } else {
322
- outerRef.scrollLeft = scrollOffset;
323
- }
324
- } else {
325
- outerRef.scrollTop = scrollOffset;
326
274
  }
327
- }
328
- this._callPropsCallbacks(prevProps, prevState);
275
+ this._callPropsCallbacks(prevProps, prevState);
329
276
  }
330
- }, {
331
- key: "componentWillUnmount",
332
- value: function componentWillUnmount() {
333
- if (this._resetIsScrollingTimeoutId !== null) {
334
- cancelTimeout(this._resetIsScrollingTimeoutId);
335
- }
277
+ componentWillUnmount() {
278
+ if (this._resetIsScrollingTimeoutId !== null) {
279
+ cancelTimeout(this._resetIsScrollingTimeoutId);
280
+ }
336
281
  }
337
- }, {
338
- key: "render",
339
- value: function render() {
340
- var _this3 = this;
341
- var _omit = omit(this.props, ['innerElementType', 'innerTagName', 'itemElementType', 'itemTagName', 'outerElementType', 'outerTagName', 'position']),
342
- className = _omit.className,
343
- direction = _omit.direction,
344
- height = _omit.height,
345
- innerRef = _omit.innerRef,
346
- item = _omit.item,
347
- itemCount = _omit.itemCount,
348
- itemData = _omit.itemData,
349
- _omit$itemKey = _omit.itemKey,
350
- itemKey = _omit$itemKey === void 0 ? defaultItemKey : _omit$itemKey,
351
- layout = _omit.layout,
352
- style = _omit.style,
353
- useIsScrolling = _omit.useIsScrolling,
354
- width = _omit.width,
355
- renderTop = _omit.renderTop,
356
- renderBottom = _omit.renderBottom,
357
- rest = _objectWithoutProperties(_omit, _excluded);
358
- var _this$state2 = this.state,
359
- id = _this$state2.id,
360
- isScrolling = _this$state2.isScrolling,
361
- scrollOffset = _this$state2.scrollOffset,
362
- scrollUpdateWasRequested = _this$state2.scrollUpdateWasRequested;
363
- var isHorizontal = this.preset.isHorizontal;
364
- var placeholderCount = this.preset.placeholderCount;
365
- var onScroll = isHorizontal ? this._onScrollHorizontal : this._onScrollVertical;
366
- var _this$_getRangeToRend5 = this._getRangeToRender(),
367
- _this$_getRangeToRend6 = _slicedToArray(_this$_getRangeToRend5, 2),
368
- startIndex = _this$_getRangeToRend6[0],
369
- stopIndex = _this$_getRangeToRend6[1];
370
- var items = [];
371
- if (itemCount > 0) {
372
- var prevPlaceholder = startIndex < placeholderCount ? startIndex : placeholderCount;
373
- items.push(new Array(prevPlaceholder).fill(-1).map(function (_, index) {
374
- return React.createElement(_this3.preset.itemTagName, {
375
- key: itemKey(index + startIndex - prevPlaceholder, itemData),
376
- style: {
377
- display: 'none'
282
+ render() {
283
+ const _a = omit(this.props, ['innerElementType', 'innerTagName', 'itemElementType', 'itemTagName', 'outerElementType', 'outerTagName', 'position']), { className, direction, height, innerRef, item, itemCount, itemData, itemKey = defaultItemKey, layout, style, useIsScrolling, width, renderTop, renderBottom } = _a, rest = __rest(_a, ["className", "direction", "height", "innerRef", "item", "itemCount", "itemData", "itemKey", "layout", "style", "useIsScrolling", "width", "renderTop", "renderBottom"]);
284
+ const { id, isScrolling, scrollOffset, scrollUpdateWasRequested } = this.state;
285
+ const isHorizontal = this.preset.isHorizontal;
286
+ const placeholderCount = this.preset.placeholderCount;
287
+ const onScroll = isHorizontal
288
+ ? this._onScrollHorizontal
289
+ : this._onScrollVertical;
290
+ const [startIndex, stopIndex] = this._getRangeToRender();
291
+ const items = [];
292
+ if (itemCount > 0) {
293
+ const prevPlaceholder = startIndex < placeholderCount ? startIndex : placeholderCount;
294
+ items.push(new Array(prevPlaceholder).fill(-1).map((_, index) => React.createElement(this.preset.itemTagName, {
295
+ key: itemKey(index + startIndex - prevPlaceholder, itemData),
296
+ style: { display: 'none' }
297
+ })));
298
+ for (let index = startIndex; index <= stopIndex; index++) {
299
+ const style = this.preset.getItemStyle(index);
300
+ items.push(React.createElement(this.preset.itemTagName, {
301
+ key: itemKey(index, itemData),
302
+ style
303
+ }, React.createElement(item, {
304
+ id: `${id}-${index}`,
305
+ data: itemData,
306
+ index,
307
+ isScrolling: useIsScrolling ? isScrolling : undefined
308
+ })));
378
309
  }
379
- });
380
- }));
381
- for (var index = startIndex; index <= stopIndex; index++) {
382
- var _style = this.preset.getItemStyle(index);
383
- items.push(React.createElement(this.preset.itemTagName, {
384
- key: itemKey(index, itemData),
385
- style: _style
386
- }, React.createElement(item, {
387
- id: "".concat(id, "-").concat(index),
388
- data: itemData,
389
- index: index,
390
- isScrolling: useIsScrolling ? isScrolling : undefined
391
- })));
310
+ const restCount = itemCount - stopIndex;
311
+ const postPlaceholder = restCount < placeholderCount ? restCount : placeholderCount;
312
+ items.push(new Array(postPlaceholder).fill(-1).map((_, index) => React.createElement(this.preset.itemTagName, {
313
+ key: itemKey(1 + index + stopIndex, itemData),
314
+ style: { display: 'none' }
315
+ })));
316
+ }
317
+ // Read this value AFTER items have been created,
318
+ // So their actual sizes (if variable) are taken into consideration.
319
+ const estimatedTotalSize = convertNumber2PX(this.itemList.getOffsetSize());
320
+ const outerElementProps = Object.assign(Object.assign({}, rest), { id,
321
+ className,
322
+ onScroll, ref: this._outerRefSetter, layout, style: Object.assign({ position: 'relative', height: convertNumber2PX(height), width: convertNumber2PX(width), overflow: 'auto', WebkitOverflowScrolling: 'touch', willChange: 'transform', direction }, style) });
323
+ if (isHorizontal) {
324
+ outerElementProps.scrollLeft = scrollUpdateWasRequested ? scrollOffset : this.preset.field.scrollLeft;
325
+ }
326
+ else {
327
+ outerElementProps.scrollTop = scrollUpdateWasRequested ? scrollOffset : this.preset.field.scrollTop;
328
+ }
329
+ if (this.preset.isRelative) {
330
+ const pre = convertNumber2PX(this.itemList.getOffsetSize(startIndex));
331
+ return React.createElement(this.preset.outerTagName, outerElementProps, renderTop, React.createElement(this.preset.itemTagName, {
332
+ key: `${id}-pre`,
333
+ id: `${id}-pre`,
334
+ style: {
335
+ height: isHorizontal ? '100%' : pre,
336
+ width: !isHorizontal ? '100%' : pre
337
+ }
338
+ }), React.createElement(this.preset.innerTagName, {
339
+ ref: innerRef,
340
+ key: `${id}-inner`,
341
+ id: `${id}-inner`,
342
+ style: {
343
+ pointerEvents: isScrolling ? 'none' : 'auto',
344
+ position: 'relative',
345
+ }
346
+ }, items), renderBottom);
347
+ }
348
+ else {
349
+ return React.createElement(this.preset.outerTagName, outerElementProps, renderTop, React.createElement(this.preset.innerTagName, {
350
+ ref: innerRef,
351
+ key: `${id}-inner`,
352
+ id: `${id}-inner`,
353
+ style: {
354
+ height: isHorizontal ? '100%' : estimatedTotalSize,
355
+ pointerEvents: isScrolling ? 'none' : 'auto',
356
+ position: 'relative',
357
+ width: !isHorizontal ? '100%' : estimatedTotalSize
358
+ }
359
+ }, items), renderBottom);
392
360
  }
393
- var restCount = itemCount - stopIndex;
394
- var postPlaceholder = restCount < placeholderCount ? restCount : placeholderCount;
395
- items.push(new Array(postPlaceholder).fill(-1).map(function (_, index) {
396
- return React.createElement(_this3.preset.itemTagName, {
397
- key: itemKey(1 + index + stopIndex, itemData),
398
- style: {
399
- display: 'none'
400
- }
401
- });
402
- }));
403
- }
404
-
405
- // Read this value AFTER items have been created,
406
- // So their actual sizes (if variable) are taken into consideration.
407
- var estimatedTotalSize = convertNumber2PX(this.itemList.getOffsetSize());
408
- var outerElementProps = _objectSpread(_objectSpread({}, rest), {}, {
409
- id: id,
410
- className: className,
411
- onScroll: onScroll,
412
- ref: this._outerRefSetter,
413
- layout: layout,
414
- style: _objectSpread({
415
- position: 'relative',
416
- height: convertNumber2PX(height),
417
- width: convertNumber2PX(width),
418
- overflow: 'auto',
419
- WebkitOverflowScrolling: 'touch',
420
- willChange: 'transform',
421
- direction: direction
422
- }, style)
423
- });
424
- if (isHorizontal) {
425
- outerElementProps.scrollLeft = scrollUpdateWasRequested ? scrollOffset : this.preset.field.scrollLeft;
426
- } else {
427
- outerElementProps.scrollTop = scrollUpdateWasRequested ? scrollOffset : this.preset.field.scrollTop;
428
- }
429
- if (this.preset.isRelative) {
430
- var pre = convertNumber2PX(this.itemList.getOffsetSize(startIndex));
431
- return React.createElement(this.preset.outerTagName, outerElementProps, renderTop, React.createElement(this.preset.itemTagName, {
432
- key: "".concat(id, "-pre"),
433
- id: "".concat(id, "-pre"),
434
- style: {
435
- height: isHorizontal ? '100%' : pre,
436
- width: !isHorizontal ? '100%' : pre
437
- }
438
- }), React.createElement(this.preset.innerTagName, {
439
- ref: innerRef,
440
- key: "".concat(id, "-inner"),
441
- id: "".concat(id, "-inner"),
442
- style: {
443
- pointerEvents: isScrolling ? 'none' : 'auto',
444
- position: 'relative'
445
- }
446
- }, items), renderBottom);
447
- } else {
448
- return React.createElement(this.preset.outerTagName, outerElementProps, renderTop, React.createElement(this.preset.innerTagName, {
449
- ref: innerRef,
450
- key: "".concat(id, "-inner"),
451
- id: "".concat(id, "-inner"),
452
- style: {
453
- height: isHorizontal ? '100%' : estimatedTotalSize,
454
- pointerEvents: isScrolling ? 'none' : 'auto',
455
- position: 'relative',
456
- width: !isHorizontal ? '100%' : estimatedTotalSize
457
- }
458
- }, items), renderBottom);
459
- }
460
- }
461
- }], [{
462
- key: "getDerivedStateFromProps",
463
- value: function getDerivedStateFromProps(nextProps, prevState) {
464
- return validateListProps(nextProps, prevState);
465
361
  }
466
- }]);
467
- return List;
468
- }(React.PureComponent); // NOTE: I considered further wrapping individual items with a pure ListItem component.
362
+ }
363
+ List.defaultProps = {
364
+ direction: 'ltr',
365
+ itemData: undefined,
366
+ layout: 'vertical',
367
+ overscanCount: 2,
368
+ useIsScrolling: false,
369
+ shouldResetStyleCacheOnItemSizeChange: true
370
+ };
371
+ // NOTE: I considered further wrapping individual items with a pure ListItem component.
469
372
  // This would avoid ever calling the render function for the same index more than once,
470
373
  // But it would also add the overhead of a lot of components/fibers.
471
374
  // I assume people already do this (render function returning a class component),
472
375
  // So my doing it would just unnecessarily double the wrappers.
473
- _defineProperty(List, "defaultProps", {
474
- direction: 'ltr',
475
- itemData: undefined,
476
- layout: 'vertical',
477
- overscanCount: 2,
478
- useIsScrolling: false,
479
- shouldResetStyleCacheOnItemSizeChange: true
480
- });
481
- export { List as default };
376
+
377
+ export { List as default };
378
+ //# sourceMappingURL=list.js.map