virtual-scroller 1.10.0 → 1.10.1
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/CHANGELOG.md +9 -0
- package/README.md +65 -13
- package/bundle/virtual-scroller-dom.js +1 -1
- package/bundle/virtual-scroller-dom.js.map +1 -1
- package/bundle/virtual-scroller-react.js +1 -1
- package/bundle/virtual-scroller-react.js.map +1 -1
- package/bundle/virtual-scroller.js +1 -1
- package/bundle/virtual-scroller.js.map +1 -1
- package/commonjs/DOM/ScrollableContainer.js +13 -1
- package/commonjs/DOM/ScrollableContainer.js.map +1 -1
- package/commonjs/Layout.js +65 -10
- package/commonjs/Layout.js.map +1 -1
- package/commonjs/ScrollableContainerNotReadyError.js +51 -0
- package/commonjs/ScrollableContainerNotReadyError.js.map +1 -0
- package/commonjs/VirtualScroller.constructor.js +22 -7
- package/commonjs/VirtualScroller.constructor.js.map +1 -1
- package/commonjs/VirtualScroller.state.js +20 -6
- package/commonjs/VirtualScroller.state.js.map +1 -1
- package/commonjs/react/VirtualScroller.js +13 -2
- package/commonjs/react/VirtualScroller.js.map +1 -1
- package/commonjs/react/useVirtualScroller.js +5 -0
- package/commonjs/react/useVirtualScroller.js.map +1 -1
- package/index.d.ts +2 -1
- package/modules/DOM/ScrollableContainer.js +11 -1
- package/modules/DOM/ScrollableContainer.js.map +1 -1
- package/modules/Layout.js +62 -10
- package/modules/Layout.js.map +1 -1
- package/modules/ScrollableContainerNotReadyError.js +44 -0
- package/modules/ScrollableContainerNotReadyError.js.map +1 -0
- package/modules/VirtualScroller.constructor.js +22 -7
- package/modules/VirtualScroller.constructor.js.map +1 -1
- package/modules/VirtualScroller.state.js +20 -6
- package/modules/VirtualScroller.state.js.map +1 -1
- package/modules/react/VirtualScroller.js +13 -2
- package/modules/react/VirtualScroller.js.map +1 -1
- package/modules/react/useVirtualScroller.js +5 -0
- package/modules/react/useVirtualScroller.js.map +1 -1
- package/package.json +1 -1
- package/source/DOM/ScrollableContainer.js +8 -0
- package/source/Layout.js +57 -9
- package/source/ScrollableContainerNotReadyError.js +5 -0
- package/source/VirtualScroller.constructor.js +17 -6
- package/source/VirtualScroller.state.js +19 -4
- package/source/react/VirtualScroller.js +14 -1
- package/source/react/useVirtualScroller.js +6 -0
|
@@ -46,7 +46,9 @@ export default function VirtualScrollerConstructor(
|
|
|
46
46
|
getColumnsCount,
|
|
47
47
|
getItemId,
|
|
48
48
|
tbody,
|
|
49
|
+
// `estimatedItemHeight` is deprecated, use `getEstimatedItemHeight()` instead.
|
|
49
50
|
estimatedItemHeight,
|
|
51
|
+
getEstimatedVisibleItemRowsCount,
|
|
50
52
|
onItemInitialRender,
|
|
51
53
|
// `onItemFirstRender(i)` is deprecated, use `onItemInitialRender(item)` instead.
|
|
52
54
|
onItemFirstRender,
|
|
@@ -57,6 +59,7 @@ export default function VirtualScrollerConstructor(
|
|
|
57
59
|
|
|
58
60
|
let {
|
|
59
61
|
bypass,
|
|
62
|
+
getEstimatedItemHeight,
|
|
60
63
|
getScrollableContainer
|
|
61
64
|
} = options
|
|
62
65
|
|
|
@@ -66,6 +69,10 @@ export default function VirtualScrollerConstructor(
|
|
|
66
69
|
// For example, React Native, `<canvas/>`, etc.
|
|
67
70
|
this.engine = engine || DOMEngine
|
|
68
71
|
|
|
72
|
+
if (!getEstimatedItemHeight && typeof estimatedItemHeight === 'number') {
|
|
73
|
+
getEstimatedItemHeight = () => estimatedItemHeight
|
|
74
|
+
}
|
|
75
|
+
|
|
69
76
|
// `scrollableContainer` option is deprecated.
|
|
70
77
|
// Use `getScrollableContainer()` option instead.
|
|
71
78
|
if (!getScrollableContainer && scrollableContainer) {
|
|
@@ -174,8 +181,8 @@ export default function VirtualScrollerConstructor(
|
|
|
174
181
|
}
|
|
175
182
|
|
|
176
183
|
log('Items count', items.length)
|
|
177
|
-
if (
|
|
178
|
-
log('Estimated item height',
|
|
184
|
+
if (getEstimatedItemHeight) {
|
|
185
|
+
log('Estimated item height', getEstimatedItemHeight())
|
|
179
186
|
}
|
|
180
187
|
|
|
181
188
|
createStateHelpers.call(this, { state, onStateChange, render, items })
|
|
@@ -190,7 +197,8 @@ export default function VirtualScrollerConstructor(
|
|
|
190
197
|
|
|
191
198
|
createHelpers.call(this, {
|
|
192
199
|
getScrollableContainer,
|
|
193
|
-
|
|
200
|
+
getEstimatedItemHeight,
|
|
201
|
+
getEstimatedVisibleItemRowsCount,
|
|
194
202
|
measureItemsBatchSize,
|
|
195
203
|
initialScrollPosition,
|
|
196
204
|
onScrollPositionChange,
|
|
@@ -208,7 +216,8 @@ export default function VirtualScrollerConstructor(
|
|
|
208
216
|
|
|
209
217
|
function createHelpers({
|
|
210
218
|
getScrollableContainer,
|
|
211
|
-
|
|
219
|
+
getEstimatedItemHeight,
|
|
220
|
+
getEstimatedVisibleItemRowsCount,
|
|
212
221
|
measureItemsBatchSize,
|
|
213
222
|
initialScrollPosition,
|
|
214
223
|
onScrollPositionChange,
|
|
@@ -242,7 +251,8 @@ function createHelpers({
|
|
|
242
251
|
|
|
243
252
|
this.layout = new Layout({
|
|
244
253
|
bypass: this.bypass,
|
|
245
|
-
|
|
254
|
+
getInitialEstimatedItemHeight: getEstimatedItemHeight,
|
|
255
|
+
getInitialEstimatedVisibleItemRowsCount: getEstimatedVisibleItemRowsCount,
|
|
246
256
|
measureItemsBatchSize,
|
|
247
257
|
getPrerenderMargin: () => this.getPrerenderMargin(),
|
|
248
258
|
getVerticalSpacing: () => this.getVerticalSpacing(),
|
|
@@ -253,7 +263,8 @@ function createHelpers({
|
|
|
253
263
|
getItemHeightBeforeResize: (i) => this.getState().beforeResize && this.getState().beforeResize.itemHeights[i],
|
|
254
264
|
getBeforeResizeItemsCount: () => this.getState().beforeResize ? this.getState().beforeResize.itemHeights.length : 0,
|
|
255
265
|
getAverageItemHeight: () => this.itemHeights.getAverage(),
|
|
256
|
-
getMaxVisibleAreaHeight: () => this.scrollableContainer
|
|
266
|
+
getMaxVisibleAreaHeight: () => this.scrollableContainer.getHeight(),
|
|
267
|
+
isScrollableContainerReady: () => this.scrollableContainer.isReady(),
|
|
257
268
|
//
|
|
258
269
|
// The "previously calculated layout" feature is not currently used.
|
|
259
270
|
//
|
|
@@ -161,7 +161,7 @@ export default function createStateHelpers({
|
|
|
161
161
|
function getInitialStateFromScratch() {
|
|
162
162
|
const items = initialItems
|
|
163
163
|
const state = {
|
|
164
|
-
...getInitialLayoutState.call(this, items),
|
|
164
|
+
...getInitialLayoutState.call(this, items, { initialLayout: true }),
|
|
165
165
|
items,
|
|
166
166
|
itemStates: new Array(items.length)
|
|
167
167
|
}
|
|
@@ -221,15 +221,26 @@ export default function createStateHelpers({
|
|
|
221
221
|
warn('Reset Layout')
|
|
222
222
|
state = {
|
|
223
223
|
...state,
|
|
224
|
-
...getInitialLayoutState.call(this, state.items)
|
|
224
|
+
...getInitialLayoutState.call(this, state.items, { initialLayout: false })
|
|
225
225
|
}
|
|
226
226
|
}
|
|
227
227
|
|
|
228
228
|
return state
|
|
229
229
|
}
|
|
230
230
|
|
|
231
|
-
function getInitialLayoutState(items) {
|
|
231
|
+
function getInitialLayoutState(items, { initialLayout }) {
|
|
232
232
|
const itemsCount = items.length
|
|
233
|
+
|
|
234
|
+
const getColumnsCount = () => this.getActualColumnsCount()
|
|
235
|
+
|
|
236
|
+
const columnsCount = initialLayout
|
|
237
|
+
? this.layout.getInitialLayoutValueWithFallback(
|
|
238
|
+
'columnsCount',
|
|
239
|
+
getColumnsCount,
|
|
240
|
+
1
|
|
241
|
+
)
|
|
242
|
+
: getColumnsCount()
|
|
243
|
+
|
|
233
244
|
const {
|
|
234
245
|
firstShownItemIndex,
|
|
235
246
|
lastShownItemIndex,
|
|
@@ -237,9 +248,12 @@ export default function createStateHelpers({
|
|
|
237
248
|
afterItemsHeight
|
|
238
249
|
} = this.layout.getInitialLayoutValues({
|
|
239
250
|
itemsCount,
|
|
240
|
-
columnsCount: this.getActualColumnsCount()
|
|
251
|
+
columnsCount: this.getActualColumnsCount(),
|
|
252
|
+
initialLayout
|
|
241
253
|
})
|
|
254
|
+
|
|
242
255
|
const itemHeights = new Array(itemsCount)
|
|
256
|
+
|
|
243
257
|
// Optionally preload items to be rendered.
|
|
244
258
|
this.onBeforeShowItems(
|
|
245
259
|
items,
|
|
@@ -247,6 +261,7 @@ export default function createStateHelpers({
|
|
|
247
261
|
firstShownItemIndex,
|
|
248
262
|
lastShownItemIndex
|
|
249
263
|
)
|
|
264
|
+
|
|
250
265
|
return {
|
|
251
266
|
itemHeights,
|
|
252
267
|
columnsCount: this.getActualColumnsCountForState(),
|
|
@@ -17,7 +17,11 @@ function VirtualScroller({
|
|
|
17
17
|
items,
|
|
18
18
|
itemComponent: Component,
|
|
19
19
|
itemComponentProps,
|
|
20
|
+
// `estimatedItemHeight` property name is deprecated,
|
|
21
|
+
// use `getEstimatedItemHeight` property instead.
|
|
20
22
|
estimatedItemHeight,
|
|
23
|
+
getEstimatedItemHeight,
|
|
24
|
+
getEstimatedVisibleItemRowsCount,
|
|
21
25
|
bypass,
|
|
22
26
|
tbody,
|
|
23
27
|
// `preserveScrollPosition` property name is deprecated,
|
|
@@ -48,7 +52,11 @@ function VirtualScroller({
|
|
|
48
52
|
// Create a `VirtualScroller` instance.
|
|
49
53
|
const virtualScroller = useVirtualScroller({
|
|
50
54
|
items,
|
|
55
|
+
// `estimatedItemHeight` property name is deprecated,
|
|
56
|
+
// use `getEstimatedItemHeight` property instead.
|
|
51
57
|
estimatedItemHeight,
|
|
58
|
+
getEstimatedItemHeight,
|
|
59
|
+
getEstimatedVisibleItemRowsCount,
|
|
52
60
|
bypass,
|
|
53
61
|
// bypassBatchSize,
|
|
54
62
|
tbody,
|
|
@@ -76,7 +84,8 @@ function VirtualScroller({
|
|
|
76
84
|
return virtualScroller.getInitialState()
|
|
77
85
|
}, [])
|
|
78
86
|
|
|
79
|
-
//
|
|
87
|
+
// Use React's `useState()` hook for managing `VirtualScroller`'s state lifecycle.
|
|
88
|
+
// This way, React will re-render the component on every state update.
|
|
80
89
|
const {
|
|
81
90
|
getState,
|
|
82
91
|
updateState
|
|
@@ -224,7 +233,11 @@ VirtualScroller.propTypes = {
|
|
|
224
233
|
items: PropTypes.arrayOf(PropTypes.any).isRequired,
|
|
225
234
|
itemComponent: elementType.isRequired,
|
|
226
235
|
itemComponentProps: PropTypes.object,
|
|
236
|
+
// `estimatedItemHeight` property name is deprecated,
|
|
237
|
+
// use `getEstimatedItemHeight` property instead.
|
|
227
238
|
estimatedItemHeight: PropTypes.number,
|
|
239
|
+
getEstimatedItemHeight: PropTypes.func,
|
|
240
|
+
getEstimatedVisibleItemRowsCount: PropTypes.func,
|
|
228
241
|
bypass: PropTypes.bool,
|
|
229
242
|
// bypassBatchSize: PropTypes.number,
|
|
230
243
|
tbody: PropTypes.bool,
|
|
@@ -5,7 +5,10 @@ import VirtualScroller from '../VirtualScroller.js'
|
|
|
5
5
|
// Creates a `VirtualScroller` instance.
|
|
6
6
|
export default function useVirtualScroller({
|
|
7
7
|
items,
|
|
8
|
+
// `estimatedItemHeight` is deprecated, use `getEstimatedItemHeight()` instead.
|
|
8
9
|
estimatedItemHeight,
|
|
10
|
+
getEstimatedItemHeight,
|
|
11
|
+
getEstimatedVisibleItemRowsCount,
|
|
9
12
|
bypass,
|
|
10
13
|
// bypassBatchSize,
|
|
11
14
|
tbody,
|
|
@@ -34,7 +37,10 @@ export default function useVirtualScroller({
|
|
|
34
37
|
items,
|
|
35
38
|
{
|
|
36
39
|
_useTimeoutInRenderLoop: true,
|
|
40
|
+
// `estimatedItemHeight` is deprecated, use `getEstimatedItemHeight()` instead.
|
|
37
41
|
estimatedItemHeight,
|
|
42
|
+
getEstimatedItemHeight,
|
|
43
|
+
getEstimatedVisibleItemRowsCount,
|
|
38
44
|
bypass,
|
|
39
45
|
// bypassBatchSize,
|
|
40
46
|
tbody,
|