virtual-scroller 1.11.2 → 1.12.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/CHANGELOG.md +5 -0
- package/README.md +13 -11
- 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/ItemsContainer.js +10 -3
- package/commonjs/DOM/ItemsContainer.js.map +1 -1
- package/commonjs/DOM/VirtualScroller.js +13 -1
- package/commonjs/DOM/VirtualScroller.js.map +1 -1
- package/commonjs/ItemHeights.js +5 -5
- package/commonjs/ItemHeights.js.map +1 -1
- package/commonjs/ItemNotRenderedError.js +64 -0
- package/commonjs/ItemNotRenderedError.js.map +1 -0
- package/commonjs/Layout.test.js +10 -0
- package/commonjs/Layout.test.js.map +1 -1
- package/commonjs/VirtualScroller.js +23 -5
- package/commonjs/VirtualScroller.js.map +1 -1
- package/commonjs/VirtualScroller.layout.js +81 -39
- package/commonjs/VirtualScroller.layout.js.map +1 -1
- package/commonjs/VirtualScroller.onRender.js +97 -45
- package/commonjs/VirtualScroller.onRender.js.map +1 -1
- package/commonjs/VirtualScroller.state.js +50 -18
- package/commonjs/VirtualScroller.state.js.map +1 -1
- package/commonjs/react/VirtualScroller.js +31 -46
- package/commonjs/react/VirtualScroller.js.map +1 -1
- package/commonjs/react/useItemKeys.js +11 -3
- package/commonjs/react/useItemKeys.js.map +1 -1
- package/commonjs/react/useOnChange.js +19 -0
- package/commonjs/react/useOnChange.js.map +1 -0
- package/commonjs/react/{useOnItemHeightChange.js → useOnItemHeightDidChange.js} +7 -7
- package/commonjs/react/useOnItemHeightDidChange.js.map +1 -0
- package/commonjs/react/{useHandleItemsPropertyChange.js → useSetNewItemsOnItemsPropertyChange.js} +15 -14
- package/commonjs/react/useSetNewItemsOnItemsPropertyChange.js.map +1 -0
- package/commonjs/react/useState.js +162 -69
- package/commonjs/react/useState.js.map +1 -1
- package/commonjs/react/useStyle.js +3 -5
- package/commonjs/react/useStyle.js.map +1 -1
- package/commonjs/react/useUpdateItemKeysOnItemsChange.js +61 -0
- package/commonjs/react/useUpdateItemKeysOnItemsChange.js.map +1 -0
- package/commonjs/test/ItemsContainer.js +22 -1
- package/commonjs/test/ItemsContainer.js.map +1 -1
- package/commonjs/utility/debug.js +30 -6
- package/commonjs/utility/debug.js.map +1 -1
- package/dom/index.d.ts +1 -1
- package/index.cjs +2 -0
- package/index.d.ts +7 -1
- package/index.js +1 -0
- package/modules/DOM/ItemsContainer.js +8 -3
- package/modules/DOM/ItemsContainer.js.map +1 -1
- package/modules/DOM/VirtualScroller.js +13 -1
- package/modules/DOM/VirtualScroller.js.map +1 -1
- package/modules/ItemHeights.js +5 -5
- package/modules/ItemHeights.js.map +1 -1
- package/modules/ItemNotRenderedError.js +57 -0
- package/modules/ItemNotRenderedError.js.map +1 -0
- package/modules/Layout.test.js +10 -0
- package/modules/Layout.test.js.map +1 -1
- package/modules/VirtualScroller.js +17 -5
- package/modules/VirtualScroller.js.map +1 -1
- package/modules/VirtualScroller.layout.js +78 -39
- package/modules/VirtualScroller.layout.js.map +1 -1
- package/modules/VirtualScroller.onRender.js +98 -46
- package/modules/VirtualScroller.onRender.js.map +1 -1
- package/modules/VirtualScroller.state.js +50 -18
- package/modules/VirtualScroller.state.js.map +1 -1
- package/modules/react/VirtualScroller.js +31 -46
- package/modules/react/VirtualScroller.js.map +1 -1
- package/modules/react/useItemKeys.js +8 -3
- package/modules/react/useItemKeys.js.map +1 -1
- package/modules/react/useOnChange.js +11 -0
- package/modules/react/useOnChange.js.map +1 -0
- package/modules/react/{useOnItemHeightChange.js → useOnItemHeightDidChange.js} +6 -6
- package/modules/react/useOnItemHeightDidChange.js.map +1 -0
- package/modules/react/{useHandleItemsPropertyChange.js → useSetNewItemsOnItemsPropertyChange.js} +11 -13
- package/modules/react/useSetNewItemsOnItemsPropertyChange.js.map +1 -0
- package/modules/react/useState.js +156 -73
- package/modules/react/useState.js.map +1 -1
- package/modules/react/useStyle.js +3 -5
- package/modules/react/useStyle.js.map +1 -1
- package/{commonjs/react/useHandleItemIndexesChange.js → modules/react/useUpdateItemKeysOnItemsChange.js} +18 -21
- package/modules/react/useUpdateItemKeysOnItemsChange.js.map +1 -0
- package/modules/test/ItemsContainer.js +20 -1
- package/modules/test/ItemsContainer.js.map +1 -1
- package/modules/utility/debug.js +31 -6
- package/modules/utility/debug.js.map +1 -1
- package/package.json +1 -1
- package/source/DOM/ItemsContainer.js +8 -3
- package/source/DOM/VirtualScroller.js +11 -1
- package/source/ItemHeights.js +5 -5
- package/source/ItemNotRenderedError.js +16 -0
- package/source/Layout.test.js +9 -0
- package/source/VirtualScroller.js +14 -3
- package/source/VirtualScroller.layout.js +77 -38
- package/source/VirtualScroller.onRender.js +95 -42
- package/source/VirtualScroller.state.js +57 -20
- package/source/react/VirtualScroller.js +28 -39
- package/source/react/useItemKeys.js +9 -2
- package/source/react/useOnChange.js +11 -0
- package/source/react/{useOnItemHeightChange.js → useOnItemHeightDidChange.js} +5 -5
- package/source/react/{useHandleItemsPropertyChange.js → useSetNewItemsOnItemsPropertyChange.js} +11 -11
- package/source/react/useState.js +159 -71
- package/source/react/useStyle.js +2 -2
- package/source/react/{useHandleItemIndexesChange.js → useUpdateItemKeysOnItemsChange.js} +17 -9
- package/source/test/ItemsContainer.js +22 -1
- package/source/utility/debug.js +18 -4
- package/commonjs/react/useHandleItemIndexesChange.js.map +0 -1
- package/commonjs/react/useHandleItemsPropertyChange.js.map +0 -1
- package/commonjs/react/useOnItemHeightChange.js.map +0 -1
- package/modules/react/useHandleItemIndexesChange.js +0 -45
- package/modules/react/useHandleItemIndexesChange.js.map +0 -1
- package/modules/react/useHandleItemsPropertyChange.js.map +0 -1
- package/modules/react/useOnItemHeightChange.js.map +0 -1
|
@@ -11,6 +11,7 @@ function _defineProperty(obj, key, value) { if (key in obj) { Object.definePrope
|
|
|
11
11
|
import { setTimeout, clearTimeout } from 'request-animation-frame-timeout';
|
|
12
12
|
import log, { warn, isDebug, reportError } from './utility/debug.js';
|
|
13
13
|
import { LAYOUT_REASON } from './Layout.js';
|
|
14
|
+
import ItemNotRenderedError from './ItemNotRenderedError.js';
|
|
14
15
|
export default function () {
|
|
15
16
|
var _this = this;
|
|
16
17
|
|
|
@@ -110,7 +111,7 @@ export default function () {
|
|
|
110
111
|
// or an "Expand YouTube video" button, which would result
|
|
111
112
|
// in the actual height of the list item being different
|
|
112
113
|
// from what has been initially measured in `this.itemHeights[i]`,
|
|
113
|
-
// if the developer didn't call `.setItemState(i, newState)` and `.
|
|
114
|
+
// if the developer didn't call `.setItemState(i, newState)` and `.onItemHeightDidChange(i)`.
|
|
114
115
|
|
|
115
116
|
|
|
116
117
|
if (!validateWillBeHiddenItemHeightsAreAccurate.call(this, firstShownItemIndex, lastShownItemIndex)) {
|
|
@@ -152,7 +153,10 @@ export default function () {
|
|
|
152
153
|
|
|
153
154
|
this.onBeforeShowItems(this.getState().items, this.getState().itemHeights, firstShownItemIndex, lastShownItemIndex); // Set `this.firstNonMeasuredItemIndex`.
|
|
154
155
|
|
|
155
|
-
this.firstNonMeasuredItemIndex = firstNonMeasuredItemIndex; //
|
|
156
|
+
this.firstNonMeasuredItemIndex = firstNonMeasuredItemIndex; // if (firstNonMeasuredItemIndex !== undefined) {
|
|
157
|
+
// log('Non-measured item index that will be measured at next layout', firstNonMeasuredItemIndex)
|
|
158
|
+
// }
|
|
159
|
+
// Set "previously calculated layout".
|
|
156
160
|
//
|
|
157
161
|
// The "previously calculated layout" feature is not currently used.
|
|
158
162
|
//
|
|
@@ -175,9 +179,9 @@ export default function () {
|
|
|
175
179
|
// Instead of using a `this.previouslyCalculatedLayout` instance variable,
|
|
176
180
|
// this code could use `this.getState()` because it reflects what's currently on screen,
|
|
177
181
|
// but there's a single edge case when it could go out of sync —
|
|
178
|
-
// updating item heights externally via `.
|
|
182
|
+
// updating item heights externally via `.onItemHeightDidChange(i)`.
|
|
179
183
|
//
|
|
180
|
-
// If, for example, an item height was updated externally via `.
|
|
184
|
+
// If, for example, an item height was updated externally via `.onItemHeightDidChange(i)`
|
|
181
185
|
// then `this.getState().itemHeights` would get updated immediately but
|
|
182
186
|
// `this.getState().beforeItemsHeight` or `this.getState().afterItemsHeight`
|
|
183
187
|
// would still correspond to the previous item height, so those would be "stale".
|
|
@@ -269,7 +273,7 @@ export default function () {
|
|
|
269
273
|
* or an "Expand YouTube video" button, which would result
|
|
270
274
|
* in the actual height of the list item being different
|
|
271
275
|
* from what has been initially measured in `this.itemHeights[i]`,
|
|
272
|
-
* if the developer didn't call `.setItemState(i, newState)` and `.
|
|
276
|
+
* if the developer didn't call `.setItemState(i, newState)` and `.onItemHeightDidChange(i)`.
|
|
273
277
|
*/
|
|
274
278
|
|
|
275
279
|
|
|
@@ -283,26 +287,26 @@ export default function () {
|
|
|
283
287
|
// The item will be hidden. Re-measure its height.
|
|
284
288
|
// The rationale is that there could be a situation when an item's
|
|
285
289
|
// height has changed, and the developer has properly added an
|
|
286
|
-
// `.
|
|
290
|
+
// `.onItemHeightDidChange(i)` call to notify `VirtualScroller`
|
|
287
291
|
// about that change, but at the same time that wouldn't work.
|
|
288
292
|
// For example, suppose there's a list of several items on a page,
|
|
289
293
|
// and those items are in "minimized" state (having height 100px).
|
|
290
294
|
// Then, a user clicks an "Expand all items" button, and all items
|
|
291
295
|
// in the list are expanded (expanded item height is gonna be 700px).
|
|
292
|
-
// `VirtualScroller` demands that `.
|
|
296
|
+
// `VirtualScroller` demands that `.onItemHeightDidChange(i)` is called
|
|
293
297
|
// in such cases, and the developer has properly added the code to do that.
|
|
294
298
|
// So, if there were 10 "minimized" items visible on a page, then there
|
|
295
|
-
// will be 10 individual `.
|
|
296
|
-
// But, as the first `.
|
|
299
|
+
// will be 10 individual `.onItemHeightDidChange(i)` calls. No issues so far.
|
|
300
|
+
// But, as the first `.onItemHeightDidChange(i)` call executes, it immediately
|
|
297
301
|
// ("synchronously") triggers a re-layout, and that re-layout finds out
|
|
298
302
|
// that now, because the first item is big, it occupies most of the screen
|
|
299
303
|
// space, and only the first 3 items are visible on screen instead of 10,
|
|
300
304
|
// and so it leaves the first 3 items mounted and unmounts the rest 7.
|
|
301
305
|
// Then, after `VirtualScroller` has rerendered, the code returns to
|
|
302
|
-
// where it was executing, and calls `.
|
|
306
|
+
// where it was executing, and calls `.onItemHeightDidChange(i)` for the
|
|
303
307
|
// second item. It also triggers an immediate re-layout that finds out
|
|
304
308
|
// that only the first 2 items are visible on screen, and it unmounts
|
|
305
|
-
// the third one too. After that, it calls `.
|
|
309
|
+
// the third one too. After that, it calls `.onItemHeightDidChange(i)`
|
|
306
310
|
// for the third item, but that item is no longer rendered, so its height
|
|
307
311
|
// can't be measured, and the same's for all the rest of the original 10 items.
|
|
308
312
|
// So, even though the developer has written their code properly, the
|
|
@@ -322,7 +326,7 @@ export default function () {
|
|
|
322
326
|
}
|
|
323
327
|
|
|
324
328
|
isValid = false;
|
|
325
|
-
warn('Item index', i, 'is no longer visible and will be unmounted. Its height has changed from', previouslyMeasuredItemHeight, 'to', actualItemHeight, 'since it was last measured. This is not necessarily a bug, and could happen, for example, on screen width change, or when there\'re several `
|
|
329
|
+
warn('Item index', i, 'is no longer visible and will be unmounted. Its height has changed from', previouslyMeasuredItemHeight, 'to', actualItemHeight, 'since it was last measured. This is not necessarily a bug, and could happen, for example, on screen width change, or when there\'re several `onItemHeightDidChange(i)` calls issued at the same time, and the first one triggers a re-layout before the rest of them have had a chance to be executed.');
|
|
326
330
|
}
|
|
327
331
|
}
|
|
328
332
|
|
|
@@ -348,21 +352,23 @@ export default function () {
|
|
|
348
352
|
|
|
349
353
|
|
|
350
354
|
function updatePreviouslyCalculatedLayoutOnItemHeightChange(i, previousHeight, newHeight) {
|
|
351
|
-
|
|
355
|
+
var prevLayout = this.previouslyCalculatedLayout;
|
|
356
|
+
|
|
357
|
+
if (prevLayout) {
|
|
352
358
|
var heightDifference = newHeight - previousHeight;
|
|
353
359
|
|
|
354
|
-
if (i <
|
|
355
|
-
// Patch `
|
|
356
|
-
|
|
357
|
-
} else if (i >
|
|
358
|
-
// Could patch `.afterItemsHeight` of `
|
|
359
|
-
// if `.afterItemsHeight` property existed in `
|
|
360
|
-
if (
|
|
361
|
-
|
|
360
|
+
if (i < prevLayout.firstShownItemIndex) {
|
|
361
|
+
// Patch `prevLayout`'s `.beforeItemsHeight`.
|
|
362
|
+
prevLayout.beforeItemsHeight += heightDifference;
|
|
363
|
+
} else if (i > prevLayout.lastShownItemIndex) {
|
|
364
|
+
// Could patch `.afterItemsHeight` of `prevLayout` here,
|
|
365
|
+
// if `.afterItemsHeight` property existed in `prevLayout`.
|
|
366
|
+
if (prevLayout.afterItemsHeight !== undefined) {
|
|
367
|
+
prevLayout.afterItemsHeight += heightDifference;
|
|
362
368
|
}
|
|
363
369
|
} else {
|
|
364
|
-
// Patch `
|
|
365
|
-
|
|
370
|
+
// Patch `prevLayout`'s shown items height.
|
|
371
|
+
prevLayout.shownItemsHeight += newHeight - previousHeight;
|
|
366
372
|
}
|
|
367
373
|
}
|
|
368
374
|
}
|
|
@@ -382,8 +388,8 @@ export default function () {
|
|
|
382
388
|
return listTopOffset;
|
|
383
389
|
};
|
|
384
390
|
|
|
385
|
-
this.
|
|
386
|
-
log('~
|
|
391
|
+
this._onItemHeightDidChange = function (i) {
|
|
392
|
+
log('~ On Item Height Did Change was called ~');
|
|
387
393
|
log('Item index', i);
|
|
388
394
|
|
|
389
395
|
var _this$getState2 = _this.getState(),
|
|
@@ -394,51 +400,84 @@ export default function () {
|
|
|
394
400
|
|
|
395
401
|
if (!(i >= firstShownItemIndex && i <= lastShownItemIndex)) {
|
|
396
402
|
// There could be valid cases when an item is no longer rendered
|
|
397
|
-
// by the time `.
|
|
403
|
+
// by the time `.onItemHeightDidChange(i)` gets called.
|
|
398
404
|
// For example, suppose there's a list of several items on a page,
|
|
399
405
|
// and those items are in "minimized" state (having height 100px).
|
|
400
406
|
// Then, a user clicks an "Expand all items" button, and all items
|
|
401
407
|
// in the list are expanded (expanded item height is gonna be 700px).
|
|
402
|
-
// `VirtualScroller` demands that `.
|
|
408
|
+
// `VirtualScroller` demands that `.onItemHeightDidChange(i)` is called
|
|
403
409
|
// in such cases, and the developer has properly added the code to do that.
|
|
404
410
|
// So, if there were 10 "minimized" items visible on a page, then there
|
|
405
|
-
// will be 10 individual `.
|
|
406
|
-
// But, as the first `.
|
|
411
|
+
// will be 10 individual `.onItemHeightDidChange(i)` calls. No issues so far.
|
|
412
|
+
// But, as the first `.onItemHeightDidChange(i)` call executes, it immediately
|
|
407
413
|
// ("synchronously") triggers a re-layout, and that re-layout finds out
|
|
408
414
|
// that now, because the first item is big, it occupies most of the screen
|
|
409
415
|
// space, and only the first 3 items are visible on screen instead of 10,
|
|
410
416
|
// and so it leaves the first 3 items mounted and unmounts the rest 7.
|
|
411
417
|
// Then, after `VirtualScroller` has rerendered, the code returns to
|
|
412
|
-
// where it was executing, and calls `.
|
|
418
|
+
// where it was executing, and calls `.onItemHeightDidChange(i)` for the
|
|
413
419
|
// second item. It also triggers an immediate re-layout that finds out
|
|
414
420
|
// that only the first 2 items are visible on screen, and it unmounts
|
|
415
|
-
// the third one too. After that, it calls `.
|
|
421
|
+
// the third one too. After that, it calls `.onItemHeightDidChange(i)`
|
|
416
422
|
// for the third item, but that item is no longer rendered, so its height
|
|
417
423
|
// can't be measured, and the same's for all the rest of the original 10 items.
|
|
418
424
|
// So, even though the developer has written their code properly, there're
|
|
419
425
|
// still situations when the item could be no longer rendered by the time
|
|
420
|
-
// `.
|
|
421
|
-
return warn('The item is no longer rendered. This is not necessarily a bug, and could happen, for example, when when a developer calls `
|
|
426
|
+
// `.onItemHeightDidChange(i)` gets called.
|
|
427
|
+
return warn('The item is no longer rendered. This is not necessarily a bug, and could happen, for example, when when a developer calls `onItemHeightDidChange(i)` while looping through a batch of items.');
|
|
422
428
|
}
|
|
423
429
|
|
|
424
430
|
var previousHeight = itemHeights[i];
|
|
425
431
|
|
|
426
432
|
if (previousHeight === undefined) {
|
|
427
|
-
return reportError("\"
|
|
433
|
+
return reportError("\"onItemHeightDidChange()\" has been called for item index ".concat(i, " but the item hasn't been rendered before."));
|
|
434
|
+
}
|
|
435
|
+
|
|
436
|
+
log('~ Re-measure item height ~');
|
|
437
|
+
var newHeight;
|
|
438
|
+
|
|
439
|
+
try {
|
|
440
|
+
newHeight = remeasureItemHeight.call(_this, i);
|
|
441
|
+
} catch (error) {
|
|
442
|
+
// Successfully finishing an `onItemHeightDidChange(i)` call is not considered
|
|
443
|
+
// critical for `VirtualScroller`'s operation, so such errors could be ignored.
|
|
444
|
+
if (error instanceof ItemNotRenderedError) {
|
|
445
|
+
return reportError("\"onItemHeightDidChange()\" has been called for item index ".concat(i, " but the item is not currently rendered and can't be measured. The exact error was: ").concat(error.message));
|
|
446
|
+
}
|
|
428
447
|
}
|
|
429
448
|
|
|
430
|
-
var newHeight = remeasureItemHeight.call(_this, i);
|
|
431
449
|
log('Previous height', previousHeight);
|
|
432
450
|
log('New height', newHeight);
|
|
433
451
|
|
|
434
452
|
if (previousHeight !== newHeight) {
|
|
435
|
-
log('~ Item height has changed ~'); // Update or reset previously calculated layout
|
|
453
|
+
log('~ Item height has changed. Should update layout. ~'); // Update or reset a previously calculated layout
|
|
454
|
+
// so that the "diff"s based on that layout in the future
|
|
455
|
+
// produce correct results.
|
|
436
456
|
|
|
437
457
|
updatePreviouslyCalculatedLayoutOnItemHeightChange.call(_this, i, previousHeight, newHeight); // Recalculate layout.
|
|
458
|
+
//
|
|
459
|
+
// If the `VirtualScroller` is already waiting for a state update to be rendered,
|
|
460
|
+
// delay `onItemHeightDidChange(i)`'s re-layout until that state update is rendered.
|
|
461
|
+
// The reason is that React `<VirtualScroller/>`'s `onHeightDidChange()` is meant to
|
|
462
|
+
// be called inside `useLayoutEffect()` hook. Due to how React is implemented internally,
|
|
463
|
+
// that might happen in the middle of the currently pending `setState()` operation
|
|
464
|
+
// being applied, resulting in weird "race condition" bugs.
|
|
465
|
+
//
|
|
438
466
|
|
|
439
|
-
_this.
|
|
440
|
-
|
|
441
|
-
|
|
467
|
+
if (_this.waitingForRender) {
|
|
468
|
+
log('~ Another state update is already waiting to be rendered. Delay the layout update until then. ~');
|
|
469
|
+
_this.updateLayoutAfterRenderBecauseItemHeightChanged = true;
|
|
470
|
+
} else {
|
|
471
|
+
_this.onUpdateShownItemIndexes({
|
|
472
|
+
reason: LAYOUT_REASON.ITEM_HEIGHT_CHANGED
|
|
473
|
+
});
|
|
474
|
+
} // If there was a request for `setState()` with new `items`, then the changes
|
|
475
|
+
// to `currentState.itemHeights[]` made above in a `remeasureItemHeight()` call
|
|
476
|
+
// would be overwritten when that pending `setState()` call gets applied.
|
|
477
|
+
// To fix that, the updates to current `itemHeights[]` are noted in
|
|
478
|
+
// `this.itemHeightsThatChangedWhileNewItemsWereBeingRendered` variable.
|
|
479
|
+
// That variable is then checked when the `setState()` call with the new `items`
|
|
480
|
+
// has been updated.
|
|
442
481
|
|
|
443
482
|
|
|
444
483
|
if (_this.newItemsWillBeRendered) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"VirtualScroller.layout.js","names":["setTimeout","clearTimeout","log","warn","isDebug","reportError","LAYOUT_REASON","onUpdateShownItemIndexes","reason","stateUpdate","skip","updateState","newItemsWillBeRendered","widthHasChanged","_isResizing","getItemsCount","scroll","cancelScheduledLayout","cancelLayoutTimer","updateShownItemIndexes","call","startedAt","Date","now","getShownItemIndexes","firstShownItemIndex","lastShownItemIndex","shownItemsHeight","firstNonMeasuredItemIndex","listHeightMeasurement","hasSnapshot","getAnchorItemIndex","undefined","validateWillBeHiddenItemHeightsAreAccurate","beforeItemsHeight","layout","getBeforeItemsHeight","afterItemsHeight","getAfterItemsHeight","layoutDuration","bypass","SLOW_LAYOUT_DURATION","getColumnsCount","itemHeights","getAverage","getState","slice","itemStates","onBeforeShowItems","items","previouslyCalculatedLayout","getVisibleArea","visibleArea","getVisibleAreaBounds","latestLayoutVisibleArea","listTopOffsetInsideScrollableContainer","getListTopOffsetInsideScrollableContainer","top","bottom","itemsCount","visibleAreaTop","visibleAreaBottom","isVisible","itemsContainer","getHeight","getNonVisibleListShownItemIndexes","isValid","i","previouslyMeasuredItemHeight","actualItemHeight","remeasureItemHeight","updatePreviouslyCalculatedLayoutOnItemHeightChange","previousHeight","newHeight","heightDifference","listTopOffset","scrollableContainer","getItemsContainerTopOffset","listTopOffsetWatcher","onListTopOffset","_onItemHeightChange","ITEM_HEIGHT_CHANGED","itemHeightsThatChangedWhileNewItemsWereBeingRendered","String","getPrerenderMargin","renderAheadMarginRatio","onItemInitialRender","measureItemHeightsAndSpacing","measureItemHeights","verticalSpacing","measureVerticalSpacingIfNotMeasured","layoutTimer","layoutTimerStateUpdate","scheduleLayoutTimer"],"sources":["../source/VirtualScroller.layout.js"],"sourcesContent":["// For some weird reason, in Chrome, `setTimeout()` would lag up to a second (or more) behind.\r\n// Turns out, Chrome developers have deprecated `setTimeout()` API entirely without asking anyone.\r\n// Replacing `setTimeout()` with `requestAnimationFrame()` can work around that Chrome bug.\r\n// https://github.com/bvaughn/react-virtualized/issues/722\r\nimport { setTimeout, clearTimeout } from 'request-animation-frame-timeout'\r\n\r\nimport log, { warn, isDebug, reportError } from './utility/debug.js'\r\nimport { LAYOUT_REASON } from './Layout.js'\r\n\r\nexport default function() {\r\n\tthis.onUpdateShownItemIndexes = ({ reason, stateUpdate }) => {\r\n\t\t// In case of \"don't do anything\".\r\n\t\tconst skip = () => {\r\n\t\t\tif (stateUpdate) {\r\n\t\t\t\tthis.updateState(stateUpdate)\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\t// If new `items` have been set and are waiting to be applied,\r\n\t\t// or if the viewport width has changed requiring a re-layout,\r\n\t\t// then temporarily stop all other updates like \"on scroll\" updates.\r\n\t\t// This prevents `state` being inconsistent, because, for example,\r\n\t\t// both `setItems()` and this function could update `VirtualScroller` state\r\n\t\t// and having them operate in parallel could result in incorrectly calculated\r\n\t\t// `beforeItemsHeight` / `afterItemsHeight` / `firstShownItemIndex` /\r\n\t\t// `lastShownItemIndex`, because, when operating in parallel, this function\r\n\t\t// would have different `items` than the `setItems()` function, so their\r\n\t\t// results could diverge.\r\n\t\tif (this.newItemsWillBeRendered || this.widthHasChanged || this._isResizing) {\r\n\t\t\treturn skip()\r\n\t\t}\r\n\r\n\t\t// If there're no items then there's no need to re-layout anything.\r\n\t\tif (this.getItemsCount() === 0) {\r\n\t\t\treturn skip()\r\n\t\t}\r\n\r\n\t\t// Cancel a \"re-layout when user stops scrolling\" timer.\r\n\t\tthis.scroll.cancelScheduledLayout()\r\n\r\n\t\t// Cancel a re-layout that is scheduled to run at the next \"frame\",\r\n\t\t// because a re-layout will be performed right now.\r\n\t\tstateUpdate = this.cancelLayoutTimer({ stateUpdate })\r\n\r\n\t\t// Perform a re-layout.\r\n\t\tlog(`~ Update Layout (on ${reason}) ~`)\r\n\t\tupdateShownItemIndexes.call(this, { stateUpdate })\r\n\t}\r\n\r\n\t/**\r\n\t * Updates the \"from\" and \"to\" shown item indexes.\r\n\t * If the list is visible and some of the items being shown are new\r\n\t * and are required to be measured first, then\r\n\t * `firstNonMeasuredItemIndex` is defined.\r\n\t * If the list is visible and all items being shown have been encountered\r\n\t * (and measured) before, then `firstNonMeasuredItemIndex` is `undefined`.\r\n\t *\r\n\t * The `stateUpdate` parameter is just an optional \"additional\" state update.\r\n\t */\r\n\tfunction updateShownItemIndexes({ stateUpdate }) {\r\n\t\tconst startedAt = Date.now()\r\n\r\n\t\t// Get shown item indexes.\r\n\t\tlet {\r\n\t\t\tfirstShownItemIndex,\r\n\t\t\tlastShownItemIndex,\r\n\t\t\tshownItemsHeight,\r\n\t\t\tfirstNonMeasuredItemIndex\r\n\t\t} = getShownItemIndexes.call(this)\r\n\r\n\t\t// If scroll position is scheduled to be restored after render,\r\n\t\t// then the \"anchor\" item must be rendered, and all of the prepended\r\n\t\t// items before it, all in a single pass. This way, all of the\r\n\t\t// prepended items' heights could be measured right after the render\r\n\t\t// has finished, and the scroll position can then be immediately restored.\r\n\t\tif (this.listHeightMeasurement.hasSnapshot()) {\r\n\t\t\tif (lastShownItemIndex < this.listHeightMeasurement.getAnchorItemIndex()) {\r\n\t\t\t\tlastShownItemIndex = this.listHeightMeasurement.getAnchorItemIndex()\r\n\t\t\t}\r\n\t\t\t// `firstShownItemIndex` is always `0` when prepending items.\r\n\t\t\t// And `lastShownItemIndex` always covers all prepended items in this case.\r\n\t\t\t// None of the prepended items have been rendered before,\r\n\t\t\t// so their heights are unknown. The code at the start of this function\r\n\t\t\t// did therefore set `firstNonMeasuredItemIndex` to non-`undefined`\r\n\t\t\t// in order to render just the first prepended item in order to\r\n\t\t\t// measure it, and only then make a decision on how many other\r\n\t\t\t// prepended items to render. But since we've instructed the code\r\n\t\t\t// to show all of the prepended items at once, there's no need to\r\n\t\t\t// \"redo layout after render\". Additionally, if layout was re-done\r\n\t\t\t// after render, then there would be a short interval of visual\r\n\t\t\t// \"jitter\" due to the scroll position not being restored because it'd\r\n\t\t\t// wait for the second layout to finish instead of being restored\r\n\t\t\t// right after the first one.\r\n\t\t\tfirstNonMeasuredItemIndex = undefined\r\n\t\t}\r\n\r\n\t\t// Validate the heights of items to be hidden on next render.\r\n\t\t// For example, a user could click a \"Show more\" button,\r\n\t\t// or an \"Expand YouTube video\" button, which would result\r\n\t\t// in the actual height of the list item being different\r\n\t\t// from what has been initially measured in `this.itemHeights[i]`,\r\n\t\t// if the developer didn't call `.setItemState(i, newState)` and `.onItemHeightChange(i)`.\r\n\t\tif (!validateWillBeHiddenItemHeightsAreAccurate.call(this, firstShownItemIndex, lastShownItemIndex)) {\r\n\t\t\tlog('~ Because some of the will-be-hidden item heights (listed above) have changed since they\\'ve last been measured, redo layout. ~')\r\n\t\t\t// Redo layout, now with the correct item heights.\r\n\t\t\treturn updateShownItemIndexes.call(this, { stateUpdate });\r\n\t\t}\r\n\r\n\t\t// Measure \"before\" items height.\r\n\t\tconst beforeItemsHeight = this.layout.getBeforeItemsHeight(\r\n\t\t\tfirstShownItemIndex\r\n\t\t)\r\n\r\n\t\t// Measure \"after\" items height.\r\n\t\tconst afterItemsHeight = this.layout.getAfterItemsHeight(\r\n\t\t\tlastShownItemIndex,\r\n\t\t\tthis.getItemsCount()\r\n\t\t)\r\n\r\n\t\tconst layoutDuration = Date.now() - startedAt\r\n\r\n\t\t// Debugging.\r\n\t\tlog('~ Calculated Layout' + (this.bypass ? ' (bypass)' : '') + ' ~')\r\n\t\tif (layoutDuration < SLOW_LAYOUT_DURATION) {\r\n\t\t\t// log('Calculated in', layoutDuration, 'ms')\r\n\t\t} else {\r\n\t\t\twarn('Layout calculated in', layoutDuration, 'ms')\r\n\t\t}\r\n\t\tif (this.getColumnsCount()) {\r\n\t\t\tlog('Columns count', this.getColumnsCount())\r\n\t\t}\r\n\t\tlog('First shown item index', firstShownItemIndex)\r\n\t\tlog('Last shown item index', lastShownItemIndex)\r\n\t\tlog('Before items height', beforeItemsHeight)\r\n\t\tlog('After items height (actual or estimated)', afterItemsHeight)\r\n\t\tlog('Average item height (used for estimated after items height calculation)', this.itemHeights.getAverage())\r\n\t\tif (isDebug()) {\r\n\t\t\tlog('Item heights', this.getState().itemHeights.slice())\r\n\t\t\tlog('Item states', this.getState().itemStates.slice())\r\n\t\t}\r\n\r\n\t\t// Optionally preload items to be rendered.\r\n\t\tthis.onBeforeShowItems(\r\n\t\t\tthis.getState().items,\r\n\t\t\tthis.getState().itemHeights,\r\n\t\t\tfirstShownItemIndex,\r\n\t\t\tlastShownItemIndex\r\n\t\t)\r\n\r\n\t\t// Set `this.firstNonMeasuredItemIndex`.\r\n\t\tthis.firstNonMeasuredItemIndex = firstNonMeasuredItemIndex\r\n\r\n\t\t// Set \"previously calculated layout\".\r\n\t\t//\r\n\t\t// The \"previously calculated layout\" feature is not currently used.\r\n\t\t//\r\n\t\t// The current layout snapshot could be stored as a \"previously calculated layout\" variable\r\n\t\t// so that it could theoretically be used when calculating new layout incrementally\r\n\t\t// rather than from scratch, which would be an optimization.\r\n\t\t//\r\n\t\t// Currently, this feature is not used, and `shownItemsHeight` property\r\n\t\t// is not returned at all, so don't set any \"previously calculated layout\".\r\n\t\t//\r\n\t\tif (shownItemsHeight === undefined) {\r\n\t\t\tthis.previouslyCalculatedLayout = undefined\r\n\t\t} else {\r\n\t\t\t// If \"previously calculated layout\" feature would be implmeneted,\r\n\t\t\t// then this code would set \"previously calculate layout\" instance variable.\r\n\t\t\t//\r\n\t\t\t// What for would this instance variable be used?\r\n\t\t\t//\r\n\t\t\t// Instead of using a `this.previouslyCalculatedLayout` instance variable,\r\n\t\t\t// this code could use `this.getState()` because it reflects what's currently on screen,\r\n\t\t\t// but there's a single edge case when it could go out of sync —\r\n\t\t\t// updating item heights externally via `.onItemHeightChange(i)`.\r\n\t\t\t//\r\n\t\t\t// If, for example, an item height was updated externally via `.onItemHeightChange(i)`\r\n\t\t\t// then `this.getState().itemHeights` would get updated immediately but\r\n\t\t\t// `this.getState().beforeItemsHeight` or `this.getState().afterItemsHeight`\r\n\t\t\t// would still correspond to the previous item height, so those would be \"stale\".\r\n\t\t\t// On the other hand, same values in `this.previouslyCalculatedLayout` instance variable\r\n\t\t\t// can also be updated immediately, so they won't go out of sync with the updated item height.\r\n\t\t\t// That seems the only edge case when using a separate `this.previouslyCalculatedLayout`\r\n\t\t\t// instance variable instead of using `this.getState()` would theoretically be justified.\r\n\t\t\t//\r\n\t\t\tthis.previouslyCalculatedLayout = {\r\n\t\t\t\tfirstShownItemIndex,\r\n\t\t\t\tlastShownItemIndex,\r\n\t\t\t\tbeforeItemsHeight,\r\n\t\t\t\tshownItemsHeight\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\t// Update `VirtualScroller` state.\r\n\t\t// `VirtualScroller` automatically re-renders on state updates.\r\n\t\t//\r\n\t\t// All `state` properties updated here should be overwritten in\r\n\t\t// the implementation of `setItems()` and `onResize()` methods\r\n\t\t// so that the `state` is not left in an inconsistent state\r\n\t\t// whenever there're concurrent `updateState()` updates that could\r\n\t\t// possibly conflict with one another — instead, those state updates\r\n\t\t// should overwrite each other in terms of priority.\r\n\t\t// These \"on scroll\" updates have the lowest priority compared to\r\n\t\t// the state updates originating from `setItems()` and `onResize()` methods.\r\n\t\t//\r\n\t\tthis.updateState({\r\n\t\t\tfirstShownItemIndex,\r\n\t\t\tlastShownItemIndex,\r\n\t\t\tbeforeItemsHeight,\r\n\t\t\tafterItemsHeight,\r\n\t\t\t...stateUpdate\r\n\t\t})\r\n\t}\r\n\r\n\tfunction getVisibleArea() {\r\n\t\tconst visibleArea = this.scroll.getVisibleAreaBounds()\r\n\t\tthis.latestLayoutVisibleArea = visibleArea\r\n\r\n\t\t// Subtract the top offset of the list inside the scrollable container.\r\n\t\tconst listTopOffsetInsideScrollableContainer = this.getListTopOffsetInsideScrollableContainer()\r\n\t\treturn {\r\n\t\t\ttop: visibleArea.top - listTopOffsetInsideScrollableContainer,\r\n\t\t\tbottom: visibleArea.bottom - listTopOffsetInsideScrollableContainer\r\n\t\t}\r\n\t}\r\n\r\n\tfunction getShownItemIndexes() {\r\n\t\tconst itemsCount = this.getItemsCount()\r\n\r\n\t\tconst {\r\n\t\t\ttop: visibleAreaTop,\r\n\t\t\tbottom: visibleAreaBottom\r\n\t\t} = getVisibleArea.call(this)\r\n\r\n\t\tif (this.bypass) {\r\n\t\t\treturn {\r\n\t\t\t\tfirstShownItemIndex: 0,\r\n\t\t\t\tlastShownItemIndex: itemsCount - 1,\r\n\t\t\t\t// shownItemsHeight: this.getState().itemHeights.reduce((sum, itemHeight) => sum + itemHeight, 0)\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\t// Find the indexes of the items that are currently visible\r\n\t\t// (or close to being visible) in the scrollable container.\r\n\t\t// For scrollable containers other than the main screen, it could also\r\n\t\t// check the visibility of such scrollable container itself, because it\r\n\t\t// might be not visible.\r\n\t\t// If such kind of an optimization would hypothetically be implemented,\r\n\t\t// then it would also require listening for \"scroll\" events on the screen.\r\n\t\t// Overall, I suppose that such \"actual visibility\" feature would be\r\n\t\t// a very minor optimization and not something I'd deal with.\r\n\t\tconst isVisible = visibleAreaTop < this.itemsContainer.getHeight() && visibleAreaBottom > 0\r\n\t\tif (!isVisible) {\r\n\t\t\tlog('The entire list is off-screen. No items are visible.')\r\n\t\t\treturn this.layout.getNonVisibleListShownItemIndexes()\r\n\t\t}\r\n\r\n\t\t// Get shown item indexes.\r\n\t\treturn this.layout.getShownItemIndexes({\r\n\t\t\titemsCount: this.getItemsCount(),\r\n\t\t\tvisibleAreaTop,\r\n\t\t\tvisibleAreaBottom\r\n\t\t})\r\n\t}\r\n\r\n\t/**\r\n\t * Validates the heights of items to be hidden on next render.\r\n\t * For example, a user could click a \"Show more\" button,\r\n\t * or an \"Expand YouTube video\" button, which would result\r\n\t * in the actual height of the list item being different\r\n\t * from what has been initially measured in `this.itemHeights[i]`,\r\n\t * if the developer didn't call `.setItemState(i, newState)` and `.onItemHeightChange(i)`.\r\n\t */\r\n\tfunction validateWillBeHiddenItemHeightsAreAccurate(firstShownItemIndex, lastShownItemIndex) {\r\n\t\tlet isValid = true\r\n\t\tlet i = this.getState().firstShownItemIndex\r\n\t\twhile (i <= this.getState().lastShownItemIndex) {\r\n\t\t\tif (i >= firstShownItemIndex && i <= lastShownItemIndex) {\r\n\t\t\t\t// The item's still visible.\r\n\t\t\t} else {\r\n\t\t\t\t// The item will be hidden. Re-measure its height.\r\n\t\t\t\t// The rationale is that there could be a situation when an item's\r\n\t\t\t\t// height has changed, and the developer has properly added an\r\n\t\t\t\t// `.onItemHeightChange(i)` call to notify `VirtualScroller`\r\n\t\t\t\t// about that change, but at the same time that wouldn't work.\r\n\t\t\t\t// For example, suppose there's a list of several items on a page,\r\n\t\t\t\t// and those items are in \"minimized\" state (having height 100px).\r\n\t\t\t\t// Then, a user clicks an \"Expand all items\" button, and all items\r\n\t\t\t\t// in the list are expanded (expanded item height is gonna be 700px).\r\n\t\t\t\t// `VirtualScroller` demands that `.onItemHeightChange(i)` is called\r\n\t\t\t\t// in such cases, and the developer has properly added the code to do that.\r\n\t\t\t\t// So, if there were 10 \"minimized\" items visible on a page, then there\r\n\t\t\t\t// will be 10 individual `.onItemHeightChange(i)` calls. No issues so far.\r\n\t\t\t\t// But, as the first `.onItemHeightChange(i)` call executes, it immediately\r\n\t\t\t\t// (\"synchronously\") triggers a re-layout, and that re-layout finds out\r\n\t\t\t\t// that now, because the first item is big, it occupies most of the screen\r\n\t\t\t\t// space, and only the first 3 items are visible on screen instead of 10,\r\n\t\t\t\t// and so it leaves the first 3 items mounted and unmounts the rest 7.\r\n\t\t\t\t// Then, after `VirtualScroller` has rerendered, the code returns to\r\n\t\t\t\t// where it was executing, and calls `.onItemHeightChange(i)` for the\r\n\t\t\t\t// second item. It also triggers an immediate re-layout that finds out\r\n\t\t\t\t// that only the first 2 items are visible on screen, and it unmounts\r\n\t\t\t\t// the third one too. After that, it calls `.onItemHeightChange(i)`\r\n\t\t\t\t// for the third item, but that item is no longer rendered, so its height\r\n\t\t\t\t// can't be measured, and the same's for all the rest of the original 10 items.\r\n\t\t\t\t// So, even though the developer has written their code properly, the\r\n\t\t\t\t// `VirtualScroller` still ends up having incorrect `itemHeights[]`:\r\n\t\t\t\t// `[700px, 700px, 100px, 100px, 100px, 100px, 100px, 100px, 100px, 100px]`\r\n\t\t\t\t// while it should have been `700px` for all of them.\r\n\t\t\t\t// To work around such issues, every item's height is re-measured before it\r\n\t\t\t\t// gets hidden.\r\n\t\t\t\tconst previouslyMeasuredItemHeight = this.getState().itemHeights[i]\r\n\t\t\t\tconst actualItemHeight = remeasureItemHeight.call(this, i)\r\n\t\t\t\tif (actualItemHeight !== previouslyMeasuredItemHeight) {\r\n\t\t\t\t\tif (isValid) {\r\n\t\t\t\t\t\tlog('~ Validate will-be-hidden item heights. ~')\r\n\t\t\t\t\t\t// Update or reset previously calculated layout.\r\n\t\t\t\t\t\tupdatePreviouslyCalculatedLayoutOnItemHeightChange.call(this, i, previouslyMeasuredItemHeight, actualItemHeight)\r\n\t\t\t\t\t}\r\n\t\t\t\t\tisValid = false\r\n\t\t\t\t\twarn('Item index', i, 'is no longer visible and will be unmounted. Its height has changed from', previouslyMeasuredItemHeight, 'to', actualItemHeight, 'since it was last measured. This is not necessarily a bug, and could happen, for example, on screen width change, or when there\\'re several `onItemHeightChange(i)` calls issued at the same time, and the first one triggers a re-layout before the rest of them have had a chance to be executed.')\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\ti++\r\n\t\t}\r\n\t\treturn isValid\r\n\t}\r\n\r\n\tfunction remeasureItemHeight(i) {\r\n\t\tconst { firstShownItemIndex } = this.getState()\r\n\t\treturn this.itemHeights.remeasureItemHeight(i, firstShownItemIndex)\r\n\t}\r\n\r\n\t// Updates the snapshot of the current layout when an item's height changes.\r\n\t//\r\n\t// The \"previously calculated layout\" feature is not currently used.\r\n\t//\r\n\t// The current layout snapshot could be stored as a \"previously calculated layout\" variable\r\n\t// so that it could theoretically be used when calculating new layout incrementally\r\n\t// rather than from scratch, which would be an optimization.\r\n\t//\r\n\tfunction updatePreviouslyCalculatedLayoutOnItemHeightChange(i, previousHeight, newHeight) {\r\n\t\tif (this.previouslyCalculatedLayout) {\r\n\t\t\tconst heightDifference = newHeight - previousHeight\r\n\t\t\tif (i < this.previouslyCalculatedLayout.firstShownItemIndex) {\r\n\t\t\t\t// Patch `this.previouslyCalculatedLayout`'s `.beforeItemsHeight`.\r\n\t\t\t\tthis.previouslyCalculatedLayout.beforeItemsHeight += heightDifference\r\n\t\t\t} else if (i > this.previouslyCalculatedLayout.lastShownItemIndex) {\r\n\t\t\t\t// Could patch `.afterItemsHeight` of `this.previouslyCalculatedLayout` here,\r\n\t\t\t\t// if `.afterItemsHeight` property existed in `this.previouslyCalculatedLayout`.\r\n\t\t\t\tif (this.previouslyCalculatedLayout.afterItemsHeight !== undefined) {\r\n\t\t\t\t\tthis.previouslyCalculatedLayout.afterItemsHeight += heightDifference\r\n\t\t\t\t}\r\n\t\t\t} else {\r\n\t\t\t\t// Patch `this.previouslyCalculatedLayout`'s shown items height.\r\n\t\t\t\tthis.previouslyCalculatedLayout.shownItemsHeight += newHeight - previousHeight\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\r\n\t/**\r\n\t * Returns the list's top offset relative to the scrollable container's top edge.\r\n\t * @return {number}\r\n\t */\r\n\tthis.getListTopOffsetInsideScrollableContainer = () => {\r\n\t\tconst listTopOffset = this.scrollableContainer.getItemsContainerTopOffset()\r\n\t\tif (this.listTopOffsetWatcher) {\r\n\t\t\tthis.listTopOffsetWatcher.onListTopOffset(listTopOffset)\r\n\t\t}\r\n\t\treturn listTopOffset\r\n\t}\r\n\r\n\tthis._onItemHeightChange = (i) => {\r\n\t\tlog('~ Re-measure item height ~')\r\n\t\tlog('Item index', i)\r\n\r\n\t\tconst {\r\n\t\t\titemHeights,\r\n\t\t\tfirstShownItemIndex,\r\n\t\t\tlastShownItemIndex\r\n\t\t} = this.getState()\r\n\r\n\t\t// Check if the item is still rendered.\r\n\t\tif (!(i >= firstShownItemIndex && i <= lastShownItemIndex)) {\r\n\t\t\t// There could be valid cases when an item is no longer rendered\r\n\t\t\t// by the time `.onItemHeightChange(i)` gets called.\r\n\t\t\t// For example, suppose there's a list of several items on a page,\r\n\t\t\t// and those items are in \"minimized\" state (having height 100px).\r\n\t\t\t// Then, a user clicks an \"Expand all items\" button, and all items\r\n\t\t\t// in the list are expanded (expanded item height is gonna be 700px).\r\n\t\t\t// `VirtualScroller` demands that `.onItemHeightChange(i)` is called\r\n\t\t\t// in such cases, and the developer has properly added the code to do that.\r\n\t\t\t// So, if there were 10 \"minimized\" items visible on a page, then there\r\n\t\t\t// will be 10 individual `.onItemHeightChange(i)` calls. No issues so far.\r\n\t\t\t// But, as the first `.onItemHeightChange(i)` call executes, it immediately\r\n\t\t\t// (\"synchronously\") triggers a re-layout, and that re-layout finds out\r\n\t\t\t// that now, because the first item is big, it occupies most of the screen\r\n\t\t\t// space, and only the first 3 items are visible on screen instead of 10,\r\n\t\t\t// and so it leaves the first 3 items mounted and unmounts the rest 7.\r\n\t\t\t// Then, after `VirtualScroller` has rerendered, the code returns to\r\n\t\t\t// where it was executing, and calls `.onItemHeightChange(i)` for the\r\n\t\t\t// second item. It also triggers an immediate re-layout that finds out\r\n\t\t\t// that only the first 2 items are visible on screen, and it unmounts\r\n\t\t\t// the third one too. After that, it calls `.onItemHeightChange(i)`\r\n\t\t\t// for the third item, but that item is no longer rendered, so its height\r\n\t\t\t// can't be measured, and the same's for all the rest of the original 10 items.\r\n\t\t\t// So, even though the developer has written their code properly, there're\r\n\t\t\t// still situations when the item could be no longer rendered by the time\r\n\t\t\t// `.onItemHeightChange(i)` gets called.\r\n\t\t\treturn warn('The item is no longer rendered. This is not necessarily a bug, and could happen, for example, when when a developer calls `onItemHeightChange(i)` while looping through a batch of items.')\r\n\t\t}\r\n\r\n\t\tconst previousHeight = itemHeights[i]\r\n\t\tif (previousHeight === undefined) {\r\n\t\t\treturn reportError(`\"onItemHeightChange()\" has been called for item ${i}, but that item hasn't been rendered before.`)\r\n\t\t}\r\n\r\n\t\tconst newHeight = remeasureItemHeight.call(this, i)\r\n\r\n\t\tlog('Previous height', previousHeight)\r\n\t\tlog('New height', newHeight)\r\n\r\n\t\tif (previousHeight !== newHeight) {\r\n\t\t\tlog('~ Item height has changed ~')\r\n\r\n\t\t\t// Update or reset previously calculated layout.\r\n\t\t\tupdatePreviouslyCalculatedLayoutOnItemHeightChange.call(this, i, previousHeight, newHeight)\r\n\r\n\t\t\t// Recalculate layout.\r\n\t\t\tthis.onUpdateShownItemIndexes({ reason: LAYOUT_REASON.ITEM_HEIGHT_CHANGED })\r\n\r\n\t\t\t// Schedule the item height update for after the new items have been rendered.\r\n\t\t\tif (this.newItemsWillBeRendered) {\r\n\t\t\t\tif (!this.itemHeightsThatChangedWhileNewItemsWereBeingRendered) {\r\n\t\t\t\t\tthis.itemHeightsThatChangedWhileNewItemsWereBeingRendered = {}\r\n\t\t\t\t}\r\n\t\t\t\tthis.itemHeightsThatChangedWhileNewItemsWereBeingRendered[String(i)] = newHeight\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\r\n\tthis.getPrerenderMargin = () => {\r\n\t\t// The list component renders not only the items that're currently visible\r\n\t\t// but also the items that lie within some extra vertical margin (called\r\n\t\t// \"prerender margin\") on top and bottom for future scrolling: this way,\r\n\t\t// there'll be significantly less layout recalculations as the user scrolls,\r\n\t\t// because now it doesn't have to recalculate layout on each scroll event.\r\n\t\t// By default, the \"prerender margin\" is equal to the screen height:\r\n\t\t// this seems to be the optimal value for \"Page Up\" / \"Page Down\" navigation\r\n\t\t// and optimized mouse wheel scrolling (a user is unlikely to continuously\r\n\t\t// scroll past the screen height, because they'd stop to read through\r\n\t\t// the newly visible items first, and when they do stop scrolling, that's\r\n\t\t// when layout gets recalculated).\r\n\t\tconst renderAheadMarginRatio = 1 // in scrollable container heights.\r\n\t\treturn this.scrollableContainer.getHeight() * renderAheadMarginRatio\r\n\t}\r\n\r\n\t/**\r\n\t * Calls `onItemFirstRender()` for items that haven't been\r\n\t * \"seen\" previously.\r\n\t * @param {any[]} items\r\n\t * @param {number[]} itemHeights\r\n\t * @param {number} firstShownItemIndex\r\n\t * @param {number} lastShownItemIndex\r\n\t */\r\n\tthis.onBeforeShowItems = (\r\n\t\titems,\r\n\t\titemHeights,\r\n\t\tfirstShownItemIndex,\r\n\t\tlastShownItemIndex\r\n\t) => {\r\n\t\tif (this.onItemInitialRender) {\r\n\t\t\tlet i = firstShownItemIndex\r\n\t\t\twhile (i <= lastShownItemIndex) {\r\n\t\t\t\tif (itemHeights[i] === undefined) {\r\n\t\t\t\t\tthis.onItemInitialRender(items[i])\r\n\t\t\t\t}\r\n\t\t\t\ti++\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\r\n\tthis.measureItemHeightsAndSpacing = () => {\r\n\t\t// Measure \"newly shown\" item heights.\r\n\t\t// Also re-validate already measured items' heights.\r\n\t\tthis.itemHeights.measureItemHeights(\r\n\t\t\tthis.getState().firstShownItemIndex,\r\n\t\t\tthis.getState().lastShownItemIndex\r\n\t\t)\r\n\r\n\t\t// Measure item vertical spacing, if required.\r\n\t\tconst verticalSpacing = this.measureVerticalSpacingIfNotMeasured()\r\n\r\n\t\t// Return a state update if vertical spacing has been measured.\r\n\t\t// Doesn't set `verticalSpacing: 0` in `state` because it is effectively\r\n\t\t// same as `verticalSpacing: undefined` in terms code behavior and calculations.\r\n\t\t// Not having `verticalSpacing: 0` in `state` just makes the `state` object\r\n\t\t// a bit more cleaner and a bit less cluttered (easier for inspection).\r\n\t\tif (verticalSpacing && verticalSpacing !== 0) {\r\n\t\t\t// Return a state update.\r\n\t\t\t// Sets `verticalSpacing` property in `state`.\r\n\t\t\treturn {\r\n\t\t\t\tverticalSpacing\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\r\n\tthis.cancelLayoutTimer = ({ stateUpdate }) => {\r\n\t\tif (this.layoutTimer) {\r\n\t\t\tclearTimeout(this.layoutTimer)\r\n\t\t\tthis.layoutTimer = undefined\r\n\t\t\t// Merge state updates.\r\n\t\t\tif (stateUpdate || this.layoutTimerStateUpdate) {\r\n\t\t\t\tstateUpdate = {\r\n\t\t\t\t\t...this.layoutTimerStateUpdate,\r\n\t\t\t\t\t...stateUpdate\r\n\t\t\t\t}\r\n\t\t\t\tthis.layoutTimerStateUpdate = undefined\r\n\t\t\t\treturn stateUpdate\r\n\t\t\t}\r\n\t\t} else {\r\n\t\t\treturn stateUpdate\r\n\t\t}\r\n\t}\r\n\r\n\tthis.scheduleLayoutTimer = ({ reason, stateUpdate }) => {\r\n\t\tthis.layoutTimerStateUpdate = stateUpdate\r\n\t\tthis.layoutTimer = setTimeout(() => {\r\n\t\t\tthis.layoutTimerStateUpdate = undefined\r\n\t\t\tthis.layoutTimer = undefined\r\n\t\t\tthis.onU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K,CAA3C,EAA8C;MAC7C;MACA;MACA,OAAO;QACNA,eAAe,EAAfA;MADM,CAAP;IAGA;EACD,CAvBD;;EAyBA,KAAKvE,iBAAL,GAAyB,iBAAqB;IAAA,IAAlBT,WAAkB,SAAlBA,WAAkB;;IAC7C,IAAI,KAAI,CAACkF,WAAT,EAAsB;MACrB1F,YAAY,CAAC,KAAI,CAAC0F,WAAN,CAAZ;MACA,KAAI,CAACA,WAAL,GAAmB3D,SAAnB,CAFqB,CAGrB;;MACA,IAAIvB,WAAW,IAAI,KAAI,CAACmF,sBAAxB,EAAgD;QAC/CnF,WAAW,mCACP,KAAI,CAACmF,sBADE,GAEPnF,WAFO,CAAX;QAIA,KAAI,CAACmF,sBAAL,GAA8B5D,SAA9B;QACA,OAAOvB,WAAP;MACA;IACD,CAZD,MAYO;MACN,OAAOA,WAAP;IACA;EACD,CAhBD;;EAkBA,KAAKoF,mBAAL,GAA2B,iBAA6B;IAAA,IAA1BrF,MAA0B,SAA1BA,MAA0B;IAAA,IAAlBC,WAAkB,SAAlBA,WAAkB;IACvD,KAAI,CAACmF,sBAAL,GAA8BnF,WAA9B;IACA,KAAI,CAACkF,WAAL,GAAmB3F,UAAU,CAAC,YAAM;MACnC,KAAI,CAAC4F,sBAAL,GAA8B5D,SAA9B;MACA,KAAI,CAAC2D,WAAL,GAAmB3D,SAAnB;;MACA,KAAI,CAACzB,wBAAL,CAA8B;QAC7BC,MAAM,EAANA,MAD6B;QAE7BC,WAAW,EAAXA;MAF6B,CAA9B;IAIA,CAP4B,EAO1B,CAP0B,CAA7B;EAQA,CAVD;AAWA;AAED,IAAMgC,oBAAoB,GAAG,EAA7B,C,CAAgC"}
|
|
1
|
+
{"version":3,"file":"VirtualScroller.layout.js","names":["setTimeout","clearTimeout","log","warn","isDebug","reportError","LAYOUT_REASON","ItemNotRenderedError","onUpdateShownItemIndexes","reason","stateUpdate","skip","updateState","newItemsWillBeRendered","widthHasChanged","_isResizing","getItemsCount","scroll","cancelScheduledLayout","cancelLayoutTimer","updateShownItemIndexes","call","startedAt","Date","now","getShownItemIndexes","firstShownItemIndex","lastShownItemIndex","shownItemsHeight","firstNonMeasuredItemIndex","listHeightMeasurement","hasSnapshot","getAnchorItemIndex","undefined","validateWillBeHiddenItemHeightsAreAccurate","beforeItemsHeight","layout","getBeforeItemsHeight","afterItemsHeight","getAfterItemsHeight","layoutDuration","bypass","SLOW_LAYOUT_DURATION","getColumnsCount","itemHeights","getAverage","getState","slice","itemStates","onBeforeShowItems","items","previouslyCalculatedLayout","getVisibleArea","visibleArea","getVisibleAreaBounds","latestLayoutVisibleArea","listTopOffsetInsideScrollableContainer","getListTopOffsetInsideScrollableContainer","top","bottom","itemsCount","visibleAreaTop","visibleAreaBottom","isVisible","itemsContainer","getHeight","getNonVisibleListShownItemIndexes","isValid","i","previouslyMeasuredItemHeight","actualItemHeight","remeasureItemHeight","updatePreviouslyCalculatedLayoutOnItemHeightChange","previousHeight","newHeight","prevLayout","heightDifference","listTopOffset","scrollableContainer","getItemsContainerTopOffset","listTopOffsetWatcher","onListTopOffset","_onItemHeightDidChange","error","message","waitingForRender","updateLayoutAfterRenderBecauseItemHeightChanged","ITEM_HEIGHT_CHANGED","itemHeightsThatChangedWhileNewItemsWereBeingRendered","String","getPrerenderMargin","renderAheadMarginRatio","onItemInitialRender","measureItemHeightsAndSpacing","measureItemHeights","verticalSpacing","measureVerticalSpacingIfNotMeasured","layoutTimer","layoutTimerStateUpdate","scheduleLayoutTimer"],"sources":["../source/VirtualScroller.layout.js"],"sourcesContent":["// For some weird reason, in Chrome, `setTimeout()` would lag up to a second (or more) behind.\r\n// Turns out, Chrome developers have deprecated `setTimeout()` API entirely without asking anyone.\r\n// Replacing `setTimeout()` with `requestAnimationFrame()` can work around that Chrome bug.\r\n// https://github.com/bvaughn/react-virtualized/issues/722\r\nimport { setTimeout, clearTimeout } from 'request-animation-frame-timeout'\r\n\r\nimport log, { warn, isDebug, reportError } from './utility/debug.js'\r\nimport { LAYOUT_REASON } from './Layout.js'\r\n\r\nimport ItemNotRenderedError from './ItemNotRenderedError.js'\r\n\r\nexport default function() {\r\n\tthis.onUpdateShownItemIndexes = ({ reason, stateUpdate }) => {\r\n\t\t// In case of \"don't do anything\".\r\n\t\tconst skip = () => {\r\n\t\t\tif (stateUpdate) {\r\n\t\t\t\tthis.updateState(stateUpdate)\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\t// If new `items` have been set and are waiting to be applied,\r\n\t\t// or if the viewport width has changed requiring a re-layout,\r\n\t\t// then temporarily stop all other updates like \"on scroll\" updates.\r\n\t\t// This prevents `state` being inconsistent, because, for example,\r\n\t\t// both `setItems()` and this function could update `VirtualScroller` state\r\n\t\t// and having them operate in parallel could result in incorrectly calculated\r\n\t\t// `beforeItemsHeight` / `afterItemsHeight` / `firstShownItemIndex` /\r\n\t\t// `lastShownItemIndex`, because, when operating in parallel, this function\r\n\t\t// would have different `items` than the `setItems()` function, so their\r\n\t\t// results could diverge.\r\n\t\tif (this.newItemsWillBeRendered || this.widthHasChanged || this._isResizing) {\r\n\t\t\treturn skip()\r\n\t\t}\r\n\r\n\t\t// If there're no items then there's no need to re-layout anything.\r\n\t\tif (this.getItemsCount() === 0) {\r\n\t\t\treturn skip()\r\n\t\t}\r\n\r\n\t\t// Cancel a \"re-layout when user stops scrolling\" timer.\r\n\t\tthis.scroll.cancelScheduledLayout()\r\n\r\n\t\t// Cancel a re-layout that is scheduled to run at the next \"frame\",\r\n\t\t// because a re-layout will be performed right now.\r\n\t\tstateUpdate = this.cancelLayoutTimer({ stateUpdate })\r\n\r\n\t\t// Perform a re-layout.\r\n\t\tlog(`~ Update Layout (on ${reason}) ~`)\r\n\t\tupdateShownItemIndexes.call(this, { stateUpdate })\r\n\t}\r\n\r\n\t/**\r\n\t * Updates the \"from\" and \"to\" shown item indexes.\r\n\t * If the list is visible and some of the items being shown are new\r\n\t * and are required to be measured first, then\r\n\t * `firstNonMeasuredItemIndex` is defined.\r\n\t * If the list is visible and all items being shown have been encountered\r\n\t * (and measured) before, then `firstNonMeasuredItemIndex` is `undefined`.\r\n\t *\r\n\t * The `stateUpdate` parameter is just an optional \"additional\" state update.\r\n\t */\r\n\tfunction updateShownItemIndexes({ stateUpdate }) {\r\n\t\tconst startedAt = Date.now()\r\n\r\n\t\t// Get shown item indexes.\r\n\t\tlet {\r\n\t\t\tfirstShownItemIndex,\r\n\t\t\tlastShownItemIndex,\r\n\t\t\tshownItemsHeight,\r\n\t\t\tfirstNonMeasuredItemIndex\r\n\t\t} = getShownItemIndexes.call(this)\r\n\r\n\t\t// If scroll position is scheduled to be restored after render,\r\n\t\t// then the \"anchor\" item must be rendered, and all of the prepended\r\n\t\t// items before it, all in a single pass. This way, all of the\r\n\t\t// prepended items' heights could be measured right after the render\r\n\t\t// has finished, and the scroll position can then be immediately restored.\r\n\t\tif (this.listHeightMeasurement.hasSnapshot()) {\r\n\t\t\tif (lastShownItemIndex < this.listHeightMeasurement.getAnchorItemIndex()) {\r\n\t\t\t\tlastShownItemIndex = this.listHeightMeasurement.getAnchorItemIndex()\r\n\t\t\t}\r\n\t\t\t// `firstShownItemIndex` is always `0` when prepending items.\r\n\t\t\t// And `lastShownItemIndex` always covers all prepended items in this case.\r\n\t\t\t// None of the prepended items have been rendered before,\r\n\t\t\t// so their heights are unknown. The code at the start of this function\r\n\t\t\t// did therefore set `firstNonMeasuredItemIndex` to non-`undefined`\r\n\t\t\t// in order to render just the first prepended item in order to\r\n\t\t\t// measure it, and only then make a decision on how many other\r\n\t\t\t// prepended items to render. But since we've instructed the code\r\n\t\t\t// to show all of the prepended items at once, there's no need to\r\n\t\t\t// \"redo layout after render\". Additionally, if layout was re-done\r\n\t\t\t// after render, then there would be a short interval of visual\r\n\t\t\t// \"jitter\" due to the scroll position not being restored because it'd\r\n\t\t\t// wait for the second layout to finish instead of being restored\r\n\t\t\t// right after the first one.\r\n\t\t\tfirstNonMeasuredItemIndex = undefined\r\n\t\t}\r\n\r\n\t\t// Validate the heights of items to be hidden on next render.\r\n\t\t// For example, a user could click a \"Show more\" button,\r\n\t\t// or an \"Expand YouTube video\" button, which would result\r\n\t\t// in the actual height of the list item being different\r\n\t\t// from what has been initially measured in `this.itemHeights[i]`,\r\n\t\t// if the developer didn't call `.setItemState(i, newState)` and `.onItemHeightDidChange(i)`.\r\n\t\tif (!validateWillBeHiddenItemHeightsAreAccurate.call(this, firstShownItemIndex, lastShownItemIndex)) {\r\n\t\t\tlog('~ Because some of the will-be-hidden item heights (listed above) have changed since they\\'ve last been measured, redo layout. ~')\r\n\t\t\t// Redo layout, now with the correct item heights.\r\n\t\t\treturn updateShownItemIndexes.call(this, { stateUpdate });\r\n\t\t}\r\n\r\n\t\t// Measure \"before\" items height.\r\n\t\tconst beforeItemsHeight = this.layout.getBeforeItemsHeight(\r\n\t\t\tfirstShownItemIndex\r\n\t\t)\r\n\r\n\t\t// Measure \"after\" items height.\r\n\t\tconst afterItemsHeight = this.layout.getAfterItemsHeight(\r\n\t\t\tlastShownItemIndex,\r\n\t\t\tthis.getItemsCount()\r\n\t\t)\r\n\r\n\t\tconst layoutDuration = Date.now() - startedAt\r\n\r\n\t\t// Debugging.\r\n\t\tlog('~ Calculated Layout' + (this.bypass ? ' (bypass)' : '') + ' ~')\r\n\t\tif (layoutDuration < SLOW_LAYOUT_DURATION) {\r\n\t\t\t// log('Calculated in', layoutDuration, 'ms')\r\n\t\t} else {\r\n\t\t\twarn('Layout calculated in', layoutDuration, 'ms')\r\n\t\t}\r\n\t\tif (this.getColumnsCount()) {\r\n\t\t\tlog('Columns count', this.getColumnsCount())\r\n\t\t}\r\n\t\tlog('First shown item index', firstShownItemIndex)\r\n\t\tlog('Last shown item index', lastShownItemIndex)\r\n\t\tlog('Before items height', beforeItemsHeight)\r\n\t\tlog('After items height (actual or estimated)', afterItemsHeight)\r\n\t\tlog('Average item height (used for estimated after items height calculation)', this.itemHeights.getAverage())\r\n\t\tif (isDebug()) {\r\n\t\t\tlog('Item heights', this.getState().itemHeights.slice())\r\n\t\t\tlog('Item states', this.getState().itemStates.slice())\r\n\t\t}\r\n\r\n\t\t// Optionally preload items to be rendered.\r\n\t\tthis.onBeforeShowItems(\r\n\t\t\tthis.getState().items,\r\n\t\t\tthis.getState().itemHeights,\r\n\t\t\tfirstShownItemIndex,\r\n\t\t\tlastShownItemIndex\r\n\t\t)\r\n\r\n\t\t// Set `this.firstNonMeasuredItemIndex`.\r\n\t\tthis.firstNonMeasuredItemIndex = firstNonMeasuredItemIndex\r\n\t\t// if (firstNonMeasuredItemIndex !== undefined) {\r\n\t\t// \tlog('Non-measured item index that will be measured at next layout', firstNonMeasuredItemIndex)\r\n\t\t// }\r\n\r\n\t\t// Set \"previously calculated layout\".\r\n\t\t//\r\n\t\t// The \"previously calculated layout\" feature is not currently used.\r\n\t\t//\r\n\t\t// The current layout snapshot could be stored as a \"previously calculated layout\" variable\r\n\t\t// so that it could theoretically be used when calculating new layout incrementally\r\n\t\t// rather than from scratch, which would be an optimization.\r\n\t\t//\r\n\t\t// Currently, this feature is not used, and `shownItemsHeight` property\r\n\t\t// is not returned at all, so don't set any \"previously calculated layout\".\r\n\t\t//\r\n\t\tif (shownItemsHeight === undefined) {\r\n\t\t\tthis.previouslyCalculatedLayout = undefined\r\n\t\t} else {\r\n\t\t\t// If \"previously calculated layout\" feature would be implmeneted,\r\n\t\t\t// then this code would set \"previously calculate layout\" instance variable.\r\n\t\t\t//\r\n\t\t\t// What for would this instance variable be used?\r\n\t\t\t//\r\n\t\t\t// Instead of using a `this.previouslyCalculatedLayout` instance variable,\r\n\t\t\t// this code could use `this.getState()` because it reflects what's currently on screen,\r\n\t\t\t// but there's a single edge case when it could go out of sync —\r\n\t\t\t// updating item heights externally via `.onItemHeightDidChange(i)`.\r\n\t\t\t//\r\n\t\t\t// If, for example, an item height was updated externally via `.onItemHeightDidChange(i)`\r\n\t\t\t// then `this.getState().itemHeights` would get updated immediately but\r\n\t\t\t// `this.getState().beforeItemsHeight` or `this.getState().afterItemsHeight`\r\n\t\t\t// would still correspond to the previous item height, so those would be \"stale\".\r\n\t\t\t// On the other hand, same values in `this.previouslyCalculatedLayout` instance variable\r\n\t\t\t// can also be updated immediately, so they won't go out of sync with the updated item height.\r\n\t\t\t// That seems the only edge case when using a separate `this.previouslyCalculatedLayout`\r\n\t\t\t// instance variable instead of using `this.getState()` would theoretically be justified.\r\n\t\t\t//\r\n\t\t\tthis.previouslyCalculatedLayout = {\r\n\t\t\t\tfirstShownItemIndex,\r\n\t\t\t\tlastShownItemIndex,\r\n\t\t\t\tbeforeItemsHeight,\r\n\t\t\t\tshownItemsHeight\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\t// Update `VirtualScroller` state.\r\n\t\t// `VirtualScroller` automatically re-renders on state updates.\r\n\t\t//\r\n\t\t// All `state` properties updated here should be overwritten in\r\n\t\t// the implementation of `setItems()` and `onResize()` methods\r\n\t\t// so that the `state` is not left in an inconsistent state\r\n\t\t// whenever there're concurrent `updateState()` updates that could\r\n\t\t// possibly conflict with one another — instead, those state updates\r\n\t\t// should overwrite each other in terms of priority.\r\n\t\t// These \"on scroll\" updates have the lowest priority compared to\r\n\t\t// the state updates originating from `setItems()` and `onResize()` methods.\r\n\t\t//\r\n\t\tthis.updateState({\r\n\t\t\tfirstShownItemIndex,\r\n\t\t\tlastShownItemIndex,\r\n\t\t\tbeforeItemsHeight,\r\n\t\t\tafterItemsHeight,\r\n\t\t\t...stateUpdate\r\n\t\t})\r\n\t}\r\n\r\n\tfunction getVisibleArea() {\r\n\t\tconst visibleArea = this.scroll.getVisibleAreaBounds()\r\n\t\tthis.latestLayoutVisibleArea = visibleArea\r\n\r\n\t\t// Subtract the top offset of the list inside the scrollable container.\r\n\t\tconst listTopOffsetInsideScrollableContainer = this.getListTopOffsetInsideScrollableContainer()\r\n\t\treturn {\r\n\t\t\ttop: visibleArea.top - listTopOffsetInsideScrollableContainer,\r\n\t\t\tbottom: visibleArea.bottom - listTopOffsetInsideScrollableContainer\r\n\t\t}\r\n\t}\r\n\r\n\tfunction getShownItemIndexes() {\r\n\t\tconst itemsCount = this.getItemsCount()\r\n\r\n\t\tconst {\r\n\t\t\ttop: visibleAreaTop,\r\n\t\t\tbottom: visibleAreaBottom\r\n\t\t} = getVisibleArea.call(this)\r\n\r\n\t\tif (this.bypass) {\r\n\t\t\treturn {\r\n\t\t\t\tfirstShownItemIndex: 0,\r\n\t\t\t\tlastShownItemIndex: itemsCount - 1,\r\n\t\t\t\t// shownItemsHeight: this.getState().itemHeights.reduce((sum, itemHeight) => sum + itemHeight, 0)\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\t// Find the indexes of the items that are currently visible\r\n\t\t// (or close to being visible) in the scrollable container.\r\n\t\t// For scrollable containers other than the main screen, it could also\r\n\t\t// check the visibility of such scrollable container itself, because it\r\n\t\t// might be not visible.\r\n\t\t// If such kind of an optimization would hypothetically be implemented,\r\n\t\t// then it would also require listening for \"scroll\" events on the screen.\r\n\t\t// Overall, I suppose that such \"actual visibility\" feature would be\r\n\t\t// a very minor optimization and not something I'd deal with.\r\n\t\tconst isVisible = visibleAreaTop < this.itemsContainer.getHeight() && visibleAreaBottom > 0\r\n\t\tif (!isVisible) {\r\n\t\t\tlog('The entire list is off-screen. No items are visible.')\r\n\t\t\treturn this.layout.getNonVisibleListShownItemIndexes()\r\n\t\t}\r\n\r\n\t\t// Get shown item indexes.\r\n\t\treturn this.layout.getShownItemIndexes({\r\n\t\t\titemsCount: this.getItemsCount(),\r\n\t\t\tvisibleAreaTop,\r\n\t\t\tvisibleAreaBottom\r\n\t\t})\r\n\t}\r\n\r\n\t/**\r\n\t * Validates the heights of items to be hidden on next render.\r\n\t * For example, a user could click a \"Show more\" button,\r\n\t * or an \"Expand YouTube video\" button, which would result\r\n\t * in the actual height of the list item being different\r\n\t * from what has been initially measured in `this.itemHeights[i]`,\r\n\t * if the developer didn't call `.setItemState(i, newState)` and `.onItemHeightDidChange(i)`.\r\n\t */\r\n\tfunction validateWillBeHiddenItemHeightsAreAccurate(firstShownItemIndex, lastShownItemIndex) {\r\n\t\tlet isValid = true\r\n\t\tlet i = this.getState().firstShownItemIndex\r\n\t\twhile (i <= this.getState().lastShownItemIndex) {\r\n\t\t\tif (i >= firstShownItemIndex && i <= lastShownItemIndex) {\r\n\t\t\t\t// The item's still visible.\r\n\t\t\t} else {\r\n\t\t\t\t// The item will be hidden. Re-measure its height.\r\n\t\t\t\t// The rationale is that there could be a situation when an item's\r\n\t\t\t\t// height has changed, and the developer has properly added an\r\n\t\t\t\t// `.onItemHeightDidChange(i)` call to notify `VirtualScroller`\r\n\t\t\t\t// about that change, but at the same time that wouldn't work.\r\n\t\t\t\t// For example, suppose there's a list of several items on a page,\r\n\t\t\t\t// and those items are in \"minimized\" state (having height 100px).\r\n\t\t\t\t// Then, a user clicks an \"Expand all items\" button, and all items\r\n\t\t\t\t// in the list are expanded (expanded item height is gonna be 700px).\r\n\t\t\t\t// `VirtualScroller` demands that `.onItemHeightDidChange(i)` is called\r\n\t\t\t\t// in such cases, and the developer has properly added the code to do that.\r\n\t\t\t\t// So, if there were 10 \"minimized\" items visible on a page, then there\r\n\t\t\t\t// will be 10 individual `.onItemHeightDidChange(i)` calls. No issues so far.\r\n\t\t\t\t// But, as the first `.onItemHeightDidChange(i)` call executes, it immediately\r\n\t\t\t\t// (\"synchronously\") triggers a re-layout, and that re-layout finds out\r\n\t\t\t\t// that now, because the first item is big, it occupies most of the screen\r\n\t\t\t\t// space, and only the first 3 items are visible on screen instead of 10,\r\n\t\t\t\t// and so it leaves the first 3 items mounted and unmounts the rest 7.\r\n\t\t\t\t// Then, after `VirtualScroller` has rerendered, the code returns to\r\n\t\t\t\t// where it was executing, and calls `.onItemHeightDidChange(i)` for the\r\n\t\t\t\t// second item. It also triggers an immediate re-layout that finds out\r\n\t\t\t\t// that only the first 2 items are visible on screen, and it unmounts\r\n\t\t\t\t// the third one too. After that, it calls `.onItemHeightDidChange(i)`\r\n\t\t\t\t// for the third item, but that item is no longer rendered, so its height\r\n\t\t\t\t// can't be measured, and the same's for all the rest of the original 10 items.\r\n\t\t\t\t// So, even though the developer has written their code properly, the\r\n\t\t\t\t// `VirtualScroller` still ends up having incorrect `itemHeights[]`:\r\n\t\t\t\t// `[700px, 700px, 100px, 100px, 100px, 100px, 100px, 100px, 100px, 100px]`\r\n\t\t\t\t// while it should have been `700px` for all of them.\r\n\t\t\t\t// To work around such issues, every item's height is re-measured before it\r\n\t\t\t\t// gets hidden.\r\n\t\t\t\tconst previouslyMeasuredItemHeight = this.getState().itemHeights[i]\r\n\t\t\t\tconst actualItemHeight = remeasureItemHeight.call(this, i)\r\n\t\t\t\tif (actualItemHeight !== previouslyMeasuredItemHeight) {\r\n\t\t\t\t\tif (isValid) {\r\n\t\t\t\t\t\tlog('~ Validate will-be-hidden item heights. ~')\r\n\t\t\t\t\t\t// Update or reset previously calculated layout.\r\n\t\t\t\t\t\tupdatePreviouslyCalculatedLayoutOnItemHeightChange.call(this, i, previouslyMeasuredItemHeight, actualItemHeight)\r\n\t\t\t\t\t}\r\n\t\t\t\t\tisValid = false\r\n\t\t\t\t\twarn('Item index', i, 'is no longer visible and will be unmounted. Its height has changed from', previouslyMeasuredItemHeight, 'to', actualItemHeight, 'since it was last measured. This is not necessarily a bug, and could happen, for example, on screen width change, or when there\\'re several `onItemHeightDidChange(i)` calls issued at the same time, and the first one triggers a re-layout before the rest of them have had a chance to be executed.')\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\ti++\r\n\t\t}\r\n\t\treturn isValid\r\n\t}\r\n\r\n\tfunction remeasureItemHeight(i) {\r\n\t\tconst { firstShownItemIndex } = this.getState()\r\n\t\treturn this.itemHeights.remeasureItemHeight(i, firstShownItemIndex)\r\n\t}\r\n\r\n\t// Updates the snapshot of the current layout when an item's height changes.\r\n\t//\r\n\t// The \"previously calculated layout\" feature is not currently used.\r\n\t//\r\n\t// The current layout snapshot could be stored as a \"previously calculated layout\" variable\r\n\t// so that it could theoretically be used when calculating new layout incrementally\r\n\t// rather than from scratch, which would be an optimization.\r\n\t//\r\n\tfunction updatePreviouslyCalculatedLayoutOnItemHeightChange(i, previousHeight, newHeight) {\r\n\t\tconst prevLayout = this.previouslyCalculatedLayout\r\n\t\tif (prevLayout) {\r\n\t\t\tconst heightDifference = newHeight - previousHeight\r\n\t\t\tif (i < prevLayout.firstShownItemIndex) {\r\n\t\t\t\t// Patch `prevLayout`'s `.beforeItemsHeight`.\r\n\t\t\t\tprevLayout.beforeItemsHeight += heightDifference\r\n\t\t\t} else if (i > prevLayout.lastShownItemIndex) {\r\n\t\t\t\t// Could patch `.afterItemsHeight` of `prevLayout` here,\r\n\t\t\t\t// if `.afterItemsHeight` property existed in `prevLayout`.\r\n\t\t\t\tif (prevLayout.afterItemsHeight !== undefined) {\r\n\t\t\t\t\tprevLayout.afterItemsHeight += heightDifference\r\n\t\t\t\t}\r\n\t\t\t} else {\r\n\t\t\t\t// Patch `prevLayout`'s shown items height.\r\n\t\t\t\tprevLayout.shownItemsHeight += newHeight - previousHeight\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\r\n\t/**\r\n\t * Returns the list's top offset relative to the scrollable container's top edge.\r\n\t * @return {number}\r\n\t */\r\n\tthis.getListTopOffsetInsideScrollableContainer = () => {\r\n\t\tconst listTopOffset = this.scrollableContainer.getItemsContainerTopOffset()\r\n\t\tif (this.listTopOffsetWatcher) {\r\n\t\t\tthis.listTopOffsetWatcher.onListTopOffset(listTopOffset)\r\n\t\t}\r\n\t\treturn listTopOffset\r\n\t}\r\n\r\n\tthis._onItemHeightDidChange = (i) => {\r\n\t\tlog('~ On Item Height Did Change was called ~')\r\n\t\tlog('Item index', i)\r\n\r\n\t\tconst {\r\n\t\t\titemHeights,\r\n\t\t\tfirstShownItemIndex,\r\n\t\t\tlastShownItemIndex\r\n\t\t} = this.getState()\r\n\r\n\t\t// Check if the item is still rendered.\r\n\t\tif (!(i >= firstShownItemIndex && i <= lastShownItemIndex)) {\r\n\t\t\t// There could be valid cases when an item is no longer rendered\r\n\t\t\t// by the time `.onItemHeightDidChange(i)` gets called.\r\n\t\t\t// For example, suppose there's a list of several items on a page,\r\n\t\t\t// and those items are in \"minimized\" state (having height 100px).\r\n\t\t\t// Then, a user clicks an \"Expand all items\" button, and all items\r\n\t\t\t// in the list are expanded (expanded item height is gonna be 700px).\r\n\t\t\t// `VirtualScroller` demands that `.onItemHeightDidChange(i)` is called\r\n\t\t\t// in such cases, and the developer has properly added the code to do that.\r\n\t\t\t// So, if there were 10 \"minimized\" items visible on a page, then there\r\n\t\t\t// will be 10 individual `.onItemHeightDidChange(i)` calls. No issues so far.\r\n\t\t\t// But, as the first `.onItemHeightDidChange(i)` call executes, it immediately\r\n\t\t\t// (\"synchronously\") triggers a re-layout, and that re-layout finds out\r\n\t\t\t// that now, because the first item is big, it occupies most of the screen\r\n\t\t\t// space, and only the first 3 items are visible on screen instead of 10,\r\n\t\t\t// and so it leaves the first 3 items mounted and unmounts the rest 7.\r\n\t\t\t// Then, after `VirtualScroller` has rerendered, the code returns to\r\n\t\t\t// where it was executing, and calls `.onItemHeightDidChange(i)` for the\r\n\t\t\t// second item. It also triggers an immediate re-layout that finds out\r\n\t\t\t// that only the first 2 items are visible on screen, and it unmounts\r\n\t\t\t// the third one too. After that, it calls `.onItemHeightDidChange(i)`\r\n\t\t\t// for the third item, but that item is no longer rendered, so its height\r\n\t\t\t// can't be measured, and the same's for all the rest of the original 10 items.\r\n\t\t\t// So, even though the developer has written their code properly, there're\r\n\t\t\t// still situations when the item could be no longer rendered by the time\r\n\t\t\t// `.onItemHeightDidChange(i)` gets called.\r\n\t\t\treturn warn('The item is no longer rendered. This is not necessarily a bug, and could happen, for example, when when a developer calls `onItemHeightDidChange(i)` while looping through a batch of items.')\r\n\t\t}\r\n\r\n\t\tconst previousHeight = itemHeights[i]\r\n\t\tif (previousHeight === undefined) {\r\n\t\t\treturn reportError(`\"onItemHeightDidChange()\" has been called for item index ${i} but the item hasn't been rendered before.`)\r\n\t\t}\r\n\r\n\t\tlog('~ Re-measure item height ~')\r\n\r\n\t\tlet newHeight\r\n\r\n\t\ttry {\r\n\t\t\tnewHeight = remeasureItemHeight.call(this, i)\r\n\t\t} catch (error) {\r\n\t\t\t// Successfully finishing an `onItemHeightDidChange(i)` call is not considered\r\n\t\t\t// critical for `VirtualScroller`'s operation, so such errors could be ignored.\r\n\t\t\tif (error instanceof ItemNotRenderedError) {\r\n\t\t\t\treturn reportError(`\"onItemHeightDidChange()\" has been called for item index ${i} but the item is not currently rendered and can\\'t be measured. The exact error was: ${error.message}`)\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tlog('Previous height', previousHeight)\r\n\t\tlog('New height', newHeight)\r\n\r\n\t\tif (previousHeight !== newHeight) {\r\n\t\t\tlog('~ Item height has changed. Should update layout. ~')\r\n\r\n\t\t\t// Update or reset a previously calculated layout\r\n\t\t\t// so that the \"diff\"s based on that layout in the future\r\n\t\t\t// produce correct results.\r\n\t\t\tupdatePreviouslyCalculatedLayoutOnItemHeightChange.call(this, i, previousHeight, newHeight)\r\n\r\n\t\t\t// Recalculate layout.\r\n\t\t\t//\r\n\t\t\t// If the `VirtualScroller` is already waiting for a state update to be rendered,\r\n\t\t\t// delay `onItemHeightDidChange(i)`'s re-layout until that state update is rendered.\r\n\t\t\t// The reason is that React `<VirtualScroller/>`'s `onHeightDidChange()` is meant to\r\n\t\t\t// be called inside `useLayoutEffect()` hook. Due to how React is implemented internally,\r\n\t\t\t// that might happen in the middle of the currently pending `setState()` operation\r\n\t\t\t// being applied, resulting in weird \"race condition\" bugs.\r\n\t\t\t//\r\n\t\t\tif (this.waitingForRender) {\r\n\t\t\t\tlog('~ Another state update is already waiting to be rendered. Delay the layout update until then. ~')\r\n\t\t\t\tthis.updateLayoutAfterRenderBecauseItemHeightChanged = true\r\n\t\t\t} else {\r\n\t\t\t\tthis.onUpdateShownItemIndexes({ reason: LAYOUT_REASON.ITEM_HEIGHT_CHANGED })\r\n\t\t\t}\r\n\r\n\t\t\t// If there was a request for `setState()` with new `items`, then the changes\r\n\t\t\t// to `currentState.itemHeights[]` made above in a `remeasureItemHeight()` call\r\n\t\t\t// would be overwritten when that pending `setState()` call gets applied.\r\n\t\t\t// To fix that, the updates to current `itemHeights[]` are noted in\r\n\t\t\t// `this.itemHeightsThatChangedWhileNewItemsWereBeingRendered` variable.\r\n\t\t\t// That variable is then checked when the `setState()` call with the new `items`\r\n\t\t\t// has been updated.\r\n\t\t\tif (this.newItemsWillBeRendered) {\r\n\t\t\t\tif (!this.itemHeightsThatChangedWhileNewItemsWereBeingRendered) {\r\n\t\t\t\t\tthis.itemHeightsThatChangedWhileNewItemsWereBeingRendered = {}\r\n\t\t\t\t}\r\n\t\t\t\tthis.itemHeightsThatChangedWhileNewItemsWereBeingRendered[String(i)] = newHeight\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\r\n\tthis.getPrerenderMargin = () => {\r\n\t\t// The list component renders not only the items that're currently visible\r\n\t\t// but also the items that lie within some extra vertical margin (called\r\n\t\t// \"prerender margin\") on top and bottom for future scrolling: this way,\r\n\t\t// there'll be significantly less layout recalculations as the user scrolls,\r\n\t\t// because now it doesn't have to recalculate layout on each scroll event.\r\n\t\t// By default, the \"prerender margin\" is equal to the screen height:\r\n\t\t// this seems to be the optimal value for \"Page Up\" / \"Page Down\" navigation\r\n\t\t// and optimized mouse wheel scrolling (a user is unlikely to continuously\r\n\t\t// scroll past the screen height, because they'd stop to read through\r\n\t\t// the newly visible items first, and when they do stop scrolling, that's\r\n\t\t// when layout gets recalculated).\r\n\t\tconst renderAheadMarginRatio = 1 // in scrollable container heights.\r\n\t\treturn this.scrollableContainer.getHeight() * renderAheadMarginRatio\r\n\t}\r\n\r\n\t/**\r\n\t * Calls `onItemFirstRender()` for items that haven't been\r\n\t * \"seen\" previously.\r\n\t * @param {any[]} items\r\n\t * @param {number[]} itemHeights\r\n\t * @param {number} firstShownItemIndex\r\n\t * @param {number} lastShownItemIndex\r\n\t */\r\n\tthis.onBeforeShowItems = (\r\n\t\titems,\r\n\t\titemHeights,\r\n\t\tfirstShownItemIndex,\r\n\t\tlastShownItemIndex\r\n\t) => {\r\n\t\tif (this.onItemInitialRender) {\r\n\t\t\tlet i = firstShownItemIndex\r\n\t\t\twhile (i <= lastShownItemIndex) {\r\n\t\t\t\tif (itemHeights[i] === undefined) {\r\n\t\t\t\t\tthis.onItemInitialRender(items[i])\r\n\t\t\t\t}\r\n\t\t\t\ti++\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\r\n\tthis.measureItemHeightsAndSpacing = () => {\r\n\t\t// Measure \"newly shown\" item heights.\r\n\t\t// Also re-validate already measured items' heights.\r\n\t\tthis.itemHeights.measureItemHeights(\r\n\t\t\tthis.getState().firstShownItemIndex,\r\n\t\t\tthis.getState().lastShownItemIndex\r\n\t\t)\r\n\r\n\t\t// Measure item vertical spacing, if required.\r\n\t\tconst verticalSpacing = this.measureVerticalSpacingIfNotMeasured()\r\n\r\n\t\t// Return a state update if vertical spacing has been measured.\r\n\t\t// Doesn't set `verticalSpacing: 0` in `state` because it is effectively\r\n\t\t// same as `verticalSpacing: undefined` in terms code behavior and calculations.\r\n\t\t// Not having `verticalSpacing: 0` in `state` just makes the `state` object\r\n\t\t// a bit more cleaner and a bit less cluttered (easier for inspection).\r\n\t\tif (verticalSpacing && verticalSpacing !== 0) {\r\n\t\t\t// Return a state update.\r\n\t\t\t// Sets `verticalSpacing` property in `state`.\r\n\t\t\treturn {\r\n\t\t\t\tverticalSpacing\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\r\n\tthis.cancelLayoutTimer = ({ stateUpdate }) => {\r\n\t\tif (this.layoutTimer) {\r\n\t\t\tclearTimeout(this.layoutTimer)\r\n\t\t\tthis.layoutTimer = undefined\r\n\t\t\t// Merge state updates.\r\n\t\t\tif (stateUpdate || this.layoutTimerStateUpdate) {\r\n\t\t\t\tstateUpdate = {\r\n\t\t\t\t\t...this.layoutTimerStateUpdate,\r\n\t\t\t\t\t...stateUpdate\r\n\t\t\t\t}\r\n\t\t\t\tthis.layoutTimerStateUpdate = undefined\r\n\t\t\t\treturn stateUpdate\r\n\t\t\t}\r\n\t\t} else {\r\n\t\t\treturn stateUpdate\r\n\t\t}\r\n\t}\r\n\r\n\tthis.scheduleLayoutTimer = ({ reason, stateUpdate }) => {\r\n\t\tthis.layoutTimerStateUpdate = stateUpdate\r\n\t\tthis.layoutTimer = setTimeout(() => {\r\n\t\t\tthis.layoutTimerStateUpdate = undefined\r\n\t\t\tthis.layoutTimer = undefined\r\n\t\t\tthis.onUpdateShownItemIndexes({\r\n\t\t\t\treason,\r\n\t\t\t\tstateUpdate\r\n\t\t\t})\r\n\t\t}, 0)\r\n\t}\r\n}\r\n\r\nconst SLOW_LAYOUT_DURATION = 15 // in milliseconds."],"mappings":";;;;;;AAAA;AACA;AACA;AACA;AACA,SAASA,UAAT,EAAqBC,YAArB,QAAyC,iCAAzC;AAEA,OAAOC,GAAP,IAAcC,IAAd,EAAoBC,OAApB,EAA6BC,WAA7B,QAAgD,oBAAhD;AACA,SAASC,aAAT,QAA8B,aAA9B;AAEA,OAAOC,oBAAP,MAAiC,2BAAjC;AAEA,eAAe,YAAW;EAAA;;EACzB,KAAKC,wBAAL,GAAgC,gBAA6B;IAAA,IAA1BC,MAA0B,QAA1BA,MAA0B;IAAA,IAAlBC,WAAkB,QAAlBA,WAAkB;;IAC5D;IACA,IAAMC,IAAI,GAAG,SAAPA,IAAO,GAAM;MAClB,IAAID,WAAJ,EAAiB;QAChB,KAAI,CAACE,WAAL,CAAiBF,WAAjB;MACA;IACD,CAJD,CAF4D,CAQ5D;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;;;IACA,IAAI,KAAI,CAACG,sBAAL,IAA+B,KAAI,CAACC,eAApC,IAAuD,KAAI,CAACC,WAAhE,EAA6E;MAC5E,OAAOJ,IAAI,EAAX;IACA,CApB2D,CAsB5D;;;IACA,IAAI,KAAI,CAACK,aAAL,OAAyB,CAA7B,EAAgC;MAC/B,OAAOL,IA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