virtual-scroller 1.7.9 → 1.9.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/.gitlab-ci.yml +1 -1
- package/CHANGELOG.md +71 -1
- package/README.md +434 -151
- package/bundle/index-bypass.html +1 -1
- package/bundle/index-dom.html +1 -1
- package/bundle/index-grid.html +1 -2
- package/bundle/index-scrollableContainer.html +1 -1
- package/bundle/index-tbody-scrollableContainer.html +2 -0
- package/bundle/index-tbody.html +2 -0
- 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/BeforeResize.js +315 -0
- package/commonjs/BeforeResize.js.map +1 -0
- package/commonjs/DOM/Engine.js +46 -0
- package/commonjs/DOM/Engine.js.map +1 -0
- package/commonjs/DOM/ItemsContainer.js +78 -0
- package/commonjs/DOM/ItemsContainer.js.map +1 -0
- package/commonjs/DOM/{WaitForStylesToLoad.js → ListTopOffsetWatcher.js} +71 -44
- package/commonjs/DOM/ListTopOffsetWatcher.js.map +1 -0
- package/commonjs/DOM/ScrollableContainer.js +69 -101
- package/commonjs/DOM/ScrollableContainer.js.map +1 -1
- package/commonjs/DOM/VirtualScroller.js +37 -29
- package/commonjs/DOM/VirtualScroller.js.map +1 -1
- package/commonjs/DOM/tbody.js +17 -11
- package/commonjs/DOM/tbody.js.map +1 -1
- package/commonjs/ItemHeights.js +33 -34
- package/commonjs/ItemHeights.js.map +1 -1
- package/commonjs/Layout.js +591 -216
- package/commonjs/Layout.js.map +1 -1
- package/commonjs/Layout.test.js +196 -0
- package/commonjs/Layout.test.js.map +1 -0
- package/commonjs/ListHeightMeasurement.js +124 -0
- package/commonjs/ListHeightMeasurement.js.map +1 -0
- package/commonjs/Resize.js +50 -39
- package/commonjs/Resize.js.map +1 -1
- package/commonjs/Scroll.js +139 -95
- package/commonjs/Scroll.js.map +1 -1
- package/commonjs/VirtualScroller.columns.js +43 -0
- package/commonjs/VirtualScroller.columns.js.map +1 -0
- package/commonjs/VirtualScroller.constructor.js +408 -0
- package/commonjs/VirtualScroller.constructor.js.map +1 -0
- package/commonjs/VirtualScroller.items.js +305 -0
- package/commonjs/VirtualScroller.items.js.map +1 -0
- package/commonjs/VirtualScroller.js +160 -1021
- package/commonjs/VirtualScroller.js.map +1 -1
- package/commonjs/VirtualScroller.layout.js +562 -0
- package/commonjs/VirtualScroller.layout.js.map +1 -0
- package/commonjs/VirtualScroller.onRender.js +357 -0
- package/commonjs/VirtualScroller.onRender.js.map +1 -0
- package/commonjs/VirtualScroller.resize.js +186 -0
- package/commonjs/VirtualScroller.resize.js.map +1 -0
- package/commonjs/VirtualScroller.state.js +301 -0
- package/commonjs/VirtualScroller.state.js.map +1 -0
- package/commonjs/VirtualScroller.verticalSpacing.js +65 -0
- package/commonjs/VirtualScroller.verticalSpacing.js.map +1 -0
- package/commonjs/getItemCoordinates.js.map +1 -1
- package/commonjs/getItemsDiff.js.map +1 -1
- package/commonjs/getVerticalSpacing.js +8 -8
- package/commonjs/getVerticalSpacing.js.map +1 -1
- package/commonjs/package.json +5 -0
- package/commonjs/react/VirtualScroller.js +182 -628
- package/commonjs/react/VirtualScroller.js.map +1 -1
- package/commonjs/react/useClassName.js +26 -0
- package/commonjs/react/useClassName.js.map +1 -0
- package/commonjs/react/useHandleItemsChange.js +116 -0
- package/commonjs/react/useHandleItemsChange.js.map +1 -0
- package/commonjs/react/useInstanceMethods.js +37 -0
- package/commonjs/react/useInstanceMethods.js.map +1 -0
- package/commonjs/react/useItemKeys.js +60 -0
- package/commonjs/react/useItemKeys.js.map +1 -0
- package/commonjs/react/useOnItemHeightChange.js +32 -0
- package/commonjs/react/useOnItemHeightChange.js.map +1 -0
- package/commonjs/react/useOnItemStateChange.js +32 -0
- package/commonjs/react/useOnItemStateChange.js.map +1 -0
- package/commonjs/react/useState.js +140 -0
- package/commonjs/react/useState.js.map +1 -0
- package/commonjs/react/useStyle.js +29 -0
- package/commonjs/react/useStyle.js.map +1 -0
- package/commonjs/react/useVirtualScroller.js +62 -0
- package/commonjs/react/useVirtualScroller.js.map +1 -0
- package/commonjs/react/useVirtualScrollerStartStop.js +20 -0
- package/commonjs/react/useVirtualScrollerStartStop.js.map +1 -0
- package/commonjs/test/Engine.js +23 -0
- package/commonjs/test/Engine.js.map +1 -0
- package/commonjs/test/ItemsContainer.js +127 -0
- package/commonjs/test/ItemsContainer.js.map +1 -0
- package/commonjs/test/ScrollableContainer.js +130 -0
- package/commonjs/test/ScrollableContainer.js.map +1 -0
- package/commonjs/test/VirtualScroller.js +281 -0
- package/commonjs/test/VirtualScroller.js.map +1 -0
- package/commonjs/utility/debounce.js +28 -6
- package/commonjs/utility/debounce.js.map +1 -1
- package/commonjs/utility/debug.js +51 -12
- package/commonjs/utility/debug.js.map +1 -1
- package/commonjs/utility/getStateSnapshot.js +50 -0
- package/commonjs/utility/getStateSnapshot.js.map +1 -0
- package/commonjs/utility/px.js +1 -1
- package/commonjs/utility/px.js.map +1 -1
- package/commonjs/utility/px.test.js +14 -0
- package/commonjs/utility/px.test.js.map +1 -0
- package/commonjs/utility/shallowEqual.js +1 -1
- package/commonjs/utility/shallowEqual.js.map +1 -1
- package/commonjs/utility/throttle.js.map +1 -1
- package/dom/index.cjs +4 -0
- package/dom/index.cjs.js +9 -0
- package/dom/index.d.ts +25 -0
- package/dom/index.js +1 -1
- package/dom/package.json +10 -4
- package/index.cjs +4 -0
- package/index.cjs.js +9 -0
- package/index.d.ts +99 -0
- package/index.js +1 -1
- package/modules/BeforeResize.js +305 -0
- package/modules/BeforeResize.js.map +1 -0
- package/modules/DOM/Engine.js +27 -0
- package/modules/DOM/Engine.js.map +1 -0
- package/modules/DOM/ItemsContainer.js +71 -0
- package/modules/DOM/ItemsContainer.js.map +1 -0
- package/modules/DOM/{WaitForStylesToLoad.js → ListTopOffsetWatcher.js} +72 -44
- package/modules/DOM/ListTopOffsetWatcher.js.map +1 -0
- package/modules/DOM/ScrollableContainer.js +68 -100
- package/modules/DOM/ScrollableContainer.js.map +1 -1
- package/modules/DOM/VirtualScroller.js +32 -28
- package/modules/DOM/VirtualScroller.js.map +1 -1
- package/modules/DOM/tbody.js +11 -9
- package/modules/DOM/tbody.js.map +1 -1
- package/modules/ItemHeights.js +28 -33
- package/modules/ItemHeights.js.map +1 -1
- package/modules/Layout.js +585 -214
- package/modules/Layout.js.map +1 -1
- package/modules/Layout.test.js +190 -0
- package/modules/Layout.test.js.map +1 -0
- package/modules/ListHeightMeasurement.js +117 -0
- package/modules/ListHeightMeasurement.js.map +1 -0
- package/modules/Resize.js +50 -39
- package/modules/Resize.js.map +1 -1
- package/modules/Scroll.js +139 -94
- package/modules/Scroll.js.map +1 -1
- package/modules/VirtualScroller.columns.js +36 -0
- package/modules/VirtualScroller.columns.js.map +1 -0
- package/modules/VirtualScroller.constructor.js +371 -0
- package/modules/VirtualScroller.constructor.js.map +1 -0
- package/modules/VirtualScroller.items.js +288 -0
- package/modules/VirtualScroller.items.js.map +1 -0
- package/modules/VirtualScroller.js +159 -1014
- package/modules/VirtualScroller.js.map +1 -1
- package/modules/VirtualScroller.layout.js +549 -0
- package/modules/VirtualScroller.layout.js.map +1 -0
- package/modules/VirtualScroller.onRender.js +337 -0
- package/modules/VirtualScroller.onRender.js.map +1 -0
- package/modules/VirtualScroller.resize.js +176 -0
- package/modules/VirtualScroller.resize.js.map +1 -0
- package/modules/VirtualScroller.state.js +283 -0
- package/modules/VirtualScroller.state.js.map +1 -0
- package/modules/VirtualScroller.verticalSpacing.js +54 -0
- package/modules/VirtualScroller.verticalSpacing.js.map +1 -0
- package/modules/getItemCoordinates.js.map +1 -1
- package/modules/getItemsDiff.js.map +1 -1
- package/modules/getVerticalSpacing.js +8 -8
- package/modules/getVerticalSpacing.js.map +1 -1
- package/modules/react/VirtualScroller.js +179 -634
- package/modules/react/VirtualScroller.js.map +1 -1
- package/modules/react/useClassName.js +18 -0
- package/modules/react/useClassName.js.map +1 -0
- package/modules/react/useHandleItemsChange.js +108 -0
- package/modules/react/useHandleItemsChange.js.map +1 -0
- package/modules/react/useInstanceMethods.js +28 -0
- package/modules/react/useInstanceMethods.js.map +1 -0
- package/modules/react/useItemKeys.js +52 -0
- package/modules/react/useItemKeys.js.map +1 -0
- package/modules/react/useOnItemHeightChange.js +24 -0
- package/modules/react/useOnItemHeightChange.js.map +1 -0
- package/modules/react/useOnItemStateChange.js +24 -0
- package/modules/react/useOnItemStateChange.js.map +1 -0
- package/modules/react/useState.js +132 -0
- package/modules/react/useState.js.map +1 -0
- package/modules/react/useStyle.js +19 -0
- package/modules/react/useStyle.js.map +1 -0
- package/modules/react/useVirtualScroller.js +51 -0
- package/modules/react/useVirtualScroller.js.map +1 -0
- package/modules/react/useVirtualScrollerStartStop.js +12 -0
- package/modules/react/useVirtualScrollerStartStop.js.map +1 -0
- package/modules/test/Engine.js +11 -0
- package/modules/test/Engine.js.map +1 -0
- package/modules/test/ItemsContainer.js +120 -0
- package/modules/test/ItemsContainer.js.map +1 -0
- package/modules/test/ScrollableContainer.js +123 -0
- package/modules/test/ScrollableContainer.js.map +1 -0
- package/modules/test/VirtualScroller.js +270 -0
- package/modules/test/VirtualScroller.js.map +1 -0
- package/modules/utility/debounce.js +28 -6
- package/modules/utility/debounce.js.map +1 -1
- package/modules/utility/debug.js +47 -10
- package/modules/utility/debug.js.map +1 -1
- package/modules/utility/getStateSnapshot.js +43 -0
- package/modules/utility/getStateSnapshot.js.map +1 -0
- package/modules/utility/px.js +1 -1
- package/modules/utility/px.js.map +1 -1
- package/modules/utility/px.test.js +9 -0
- package/modules/utility/px.test.js.map +1 -0
- package/modules/utility/shallowEqual.js +1 -1
- package/modules/utility/shallowEqual.js.map +1 -1
- package/modules/utility/throttle.js.map +1 -1
- package/package.json +54 -29
- package/react/index.cjs +4 -0
- package/react/index.cjs.js +9 -0
- package/react/index.d.ts +28 -0
- package/react/index.js +1 -1
- package/react/package.json +10 -4
- package/rollup.config.mjs +62 -0
- package/runnable/create-commonjs-package-json.js +11 -0
- package/source/BeforeResize.js +312 -0
- package/source/DOM/Engine.js +30 -0
- package/source/DOM/ItemsContainer.js +48 -0
- package/source/DOM/{WaitForStylesToLoad.js → ListTopOffsetWatcher.js} +61 -30
- package/source/DOM/ScrollableContainer.js +51 -73
- package/source/DOM/VirtualScroller.js +33 -18
- package/source/DOM/tbody.js +30 -21
- package/source/ItemHeights.js +27 -27
- package/source/Layout.js +629 -252
- package/source/Layout.test.js +176 -0
- package/source/ListHeightMeasurement.js +95 -0
- package/source/Resize.js +56 -32
- package/source/Scroll.js +135 -82
- package/source/VirtualScroller.columns.js +26 -0
- package/source/VirtualScroller.constructor.js +336 -0
- package/source/VirtualScroller.items.js +302 -0
- package/source/VirtualScroller.js +162 -936
- package/source/VirtualScroller.layout.js +539 -0
- package/source/VirtualScroller.onRender.js +345 -0
- package/source/VirtualScroller.resize.js +189 -0
- package/source/VirtualScroller.state.js +284 -0
- package/source/VirtualScroller.verticalSpacing.js +51 -0
- package/source/getVerticalSpacing.js +7 -7
- package/source/react/VirtualScroller.js +243 -603
- package/source/react/useClassName.js +14 -0
- package/source/react/useHandleItemsChange.js +115 -0
- package/source/react/useInstanceMethods.js +25 -0
- package/source/react/useItemKeys.js +59 -0
- package/source/react/useOnItemHeightChange.js +28 -0
- package/source/react/useOnItemStateChange.js +28 -0
- package/source/react/useState.js +114 -0
- package/source/react/useStyle.js +20 -0
- package/source/react/useVirtualScroller.js +59 -0
- package/source/react/useVirtualScrollerStartStop.js +12 -0
- package/source/test/Engine.js +11 -0
- package/source/test/ItemsContainer.js +87 -0
- package/source/test/ScrollableContainer.js +88 -0
- package/source/test/VirtualScroller.js +232 -0
- package/source/utility/debounce.js +22 -5
- package/source/utility/debug.js +34 -3
- package/source/utility/getStateSnapshot.js +36 -0
- package/source/utility/px.js +1 -1
- package/source/utility/px.test.js +9 -0
- package/website/index-bypass.html +195 -0
- package/website/index-grid.html +0 -1
- package/website/index-scrollableContainer.html +208 -0
- package/website/index-tbody-scrollableContainer.html +68 -0
- package/website/index-tbody.html +55 -0
- package/commonjs/DOM/RenderingEngine.js +0 -33
- package/commonjs/DOM/RenderingEngine.js.map +0 -1
- package/commonjs/DOM/Screen.js +0 -87
- package/commonjs/DOM/Screen.js.map +0 -1
- package/commonjs/DOM/WaitForStylesToLoad.js.map +0 -1
- package/commonjs/RestoreScroll.js +0 -118
- package/commonjs/RestoreScroll.js.map +0 -1
- package/dom/index.commonjs.js +0 -4
- package/index.commonjs.js +0 -4
- package/modules/DOM/RenderingEngine.js +0 -19
- package/modules/DOM/RenderingEngine.js.map +0 -1
- package/modules/DOM/Screen.js +0 -80
- package/modules/DOM/Screen.js.map +0 -1
- package/modules/DOM/WaitForStylesToLoad.js.map +0 -1
- package/modules/RestoreScroll.js +0 -111
- package/modules/RestoreScroll.js.map +0 -1
- package/react/index.commonjs.js +0 -4
- package/source/DOM/RenderingEngine.js +0 -22
- package/source/DOM/Screen.js +0 -51
- package/source/RestoreScroll.js +0 -86
|
@@ -0,0 +1,562 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
|
|
4
|
+
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
exports["default"] = _default;
|
|
9
|
+
|
|
10
|
+
var _requestAnimationFrameTimeout = require("request-animation-frame-timeout");
|
|
11
|
+
|
|
12
|
+
var _debug = _interopRequireWildcard(require("./utility/debug.js"));
|
|
13
|
+
|
|
14
|
+
var _Layout = require("./Layout.js");
|
|
15
|
+
|
|
16
|
+
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
17
|
+
|
|
18
|
+
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
19
|
+
|
|
20
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
21
|
+
|
|
22
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
23
|
+
|
|
24
|
+
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
25
|
+
|
|
26
|
+
function _default() {
|
|
27
|
+
var _this = this;
|
|
28
|
+
|
|
29
|
+
this.onUpdateShownItemIndexes = function (_ref) {
|
|
30
|
+
var reason = _ref.reason,
|
|
31
|
+
stateUpdate = _ref.stateUpdate;
|
|
32
|
+
|
|
33
|
+
// In case of "don't do anything".
|
|
34
|
+
var skip = function skip() {
|
|
35
|
+
if (stateUpdate) {
|
|
36
|
+
_this.updateState(stateUpdate);
|
|
37
|
+
}
|
|
38
|
+
}; // If new `items` have been set and are waiting to be applied,
|
|
39
|
+
// or if the viewport width has changed requiring a re-layout,
|
|
40
|
+
// then temporarily stop all other updates like "on scroll" updates.
|
|
41
|
+
// This prevents `state` being inconsistent, because, for example,
|
|
42
|
+
// both `setItems()` and this function could update `VirtualScroller` state
|
|
43
|
+
// and having them operate in parallel could result in incorrectly calculated
|
|
44
|
+
// `beforeItemsHeight` / `afterItemsHeight` / `firstShownItemIndex` /
|
|
45
|
+
// `lastShownItemIndex`, because, when operating in parallel, this function
|
|
46
|
+
// would have different `items` than the `setItems()` function, so their
|
|
47
|
+
// results could diverge.
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
if (_this.newItemsWillBeRendered || _this.widthHasChanged || _this._isResizing) {
|
|
51
|
+
return skip();
|
|
52
|
+
} // If there're no items then there's no need to re-layout anything.
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
if (_this.getItemsCount() === 0) {
|
|
56
|
+
return skip();
|
|
57
|
+
} // Cancel a "re-layout when user stops scrolling" timer.
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
_this.scroll.cancelScheduledLayout(); // Cancel a re-layout that is scheduled to run at the next "frame",
|
|
61
|
+
// because a re-layout will be performed right now.
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
stateUpdate = _this.cancelLayoutTimer({
|
|
65
|
+
stateUpdate: stateUpdate
|
|
66
|
+
}); // Perform a re-layout.
|
|
67
|
+
|
|
68
|
+
(0, _debug["default"])("~ Update Layout (on ".concat(reason, ") ~"));
|
|
69
|
+
updateShownItemIndexes.call(_this, {
|
|
70
|
+
stateUpdate: stateUpdate
|
|
71
|
+
});
|
|
72
|
+
};
|
|
73
|
+
/**
|
|
74
|
+
* Updates the "from" and "to" shown item indexes.
|
|
75
|
+
* If the list is visible and some of the items being shown are new
|
|
76
|
+
* and are required to be measured first, then
|
|
77
|
+
* `firstNonMeasuredItemIndex` is defined.
|
|
78
|
+
* If the list is visible and all items being shown have been encountered
|
|
79
|
+
* (and measured) before, then `firstNonMeasuredItemIndex` is `undefined`.
|
|
80
|
+
*
|
|
81
|
+
* The `stateUpdate` parameter is just an optional "additional" state update.
|
|
82
|
+
*/
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
function updateShownItemIndexes(_ref2) {
|
|
86
|
+
var stateUpdate = _ref2.stateUpdate;
|
|
87
|
+
var startedAt = Date.now(); // Get shown item indexes.
|
|
88
|
+
|
|
89
|
+
var _getShownItemIndexes$ = getShownItemIndexes.call(this),
|
|
90
|
+
firstShownItemIndex = _getShownItemIndexes$.firstShownItemIndex,
|
|
91
|
+
lastShownItemIndex = _getShownItemIndexes$.lastShownItemIndex,
|
|
92
|
+
shownItemsHeight = _getShownItemIndexes$.shownItemsHeight,
|
|
93
|
+
firstNonMeasuredItemIndex = _getShownItemIndexes$.firstNonMeasuredItemIndex; // If scroll position is scheduled to be restored after render,
|
|
94
|
+
// then the "anchor" item must be rendered, and all of the prepended
|
|
95
|
+
// items before it, all in a single pass. This way, all of the
|
|
96
|
+
// prepended items' heights could be measured right after the render
|
|
97
|
+
// has finished, and the scroll position can then be immediately restored.
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
if (this.listHeightMeasurement.hasSnapshot()) {
|
|
101
|
+
if (lastShownItemIndex < this.listHeightMeasurement.getAnchorItemIndex()) {
|
|
102
|
+
lastShownItemIndex = this.listHeightMeasurement.getAnchorItemIndex();
|
|
103
|
+
} // `firstShownItemIndex` is always `0` when prepending items.
|
|
104
|
+
// And `lastShownItemIndex` always covers all prepended items in this case.
|
|
105
|
+
// None of the prepended items have been rendered before,
|
|
106
|
+
// so their heights are unknown. The code at the start of this function
|
|
107
|
+
// did therefore set `firstNonMeasuredItemIndex` to non-`undefined`
|
|
108
|
+
// in order to render just the first prepended item in order to
|
|
109
|
+
// measure it, and only then make a decision on how many other
|
|
110
|
+
// prepended items to render. But since we've instructed the code
|
|
111
|
+
// to show all of the prepended items at once, there's no need to
|
|
112
|
+
// "redo layout after render". Additionally, if layout was re-done
|
|
113
|
+
// after render, then there would be a short interval of visual
|
|
114
|
+
// "jitter" due to the scroll position not being restored because it'd
|
|
115
|
+
// wait for the second layout to finish instead of being restored
|
|
116
|
+
// right after the first one.
|
|
117
|
+
|
|
118
|
+
|
|
119
|
+
firstNonMeasuredItemIndex = undefined;
|
|
120
|
+
} // Validate the heights of items to be hidden on next render.
|
|
121
|
+
// For example, a user could click a "Show more" button,
|
|
122
|
+
// or an "Expand YouTube video" button, which would result
|
|
123
|
+
// in the actual height of the list item being different
|
|
124
|
+
// from what has been initially measured in `this.itemHeights[i]`,
|
|
125
|
+
// if the developer didn't call `.onItemStateChange()` and `.onItemHeightChange(i)`.
|
|
126
|
+
|
|
127
|
+
|
|
128
|
+
if (!validateWillBeHiddenItemHeightsAreAccurate.call(this, firstShownItemIndex, lastShownItemIndex)) {
|
|
129
|
+
(0, _debug["default"])('~ Because some of the will-be-hidden item heights (listed above) have changed since they\'ve last been measured, redo layout. ~'); // Redo layout, now with the correct item heights.
|
|
130
|
+
|
|
131
|
+
return updateShownItemIndexes.call(this, {
|
|
132
|
+
stateUpdate: stateUpdate
|
|
133
|
+
});
|
|
134
|
+
} // Measure "before" items height.
|
|
135
|
+
|
|
136
|
+
|
|
137
|
+
var beforeItemsHeight = this.layout.getBeforeItemsHeight(firstShownItemIndex); // Measure "after" items height.
|
|
138
|
+
|
|
139
|
+
var afterItemsHeight = this.layout.getAfterItemsHeight(lastShownItemIndex, this.getItemsCount());
|
|
140
|
+
var layoutDuration = Date.now() - startedAt; // Debugging.
|
|
141
|
+
|
|
142
|
+
(0, _debug["default"])('~ Calculated Layout' + (this.bypass ? ' (bypass)' : '') + ' ~');
|
|
143
|
+
|
|
144
|
+
if (layoutDuration < SLOW_LAYOUT_DURATION) {// log('Calculated in', layoutDuration, 'ms')
|
|
145
|
+
} else {
|
|
146
|
+
(0, _debug.warn)('Layout calculated in', layoutDuration, 'ms');
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
if (this.getColumnsCount()) {
|
|
150
|
+
(0, _debug["default"])('Columns count', this.getColumnsCount());
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
(0, _debug["default"])('First shown item index', firstShownItemIndex);
|
|
154
|
+
(0, _debug["default"])('Last shown item index', lastShownItemIndex);
|
|
155
|
+
(0, _debug["default"])('Before items height', beforeItemsHeight);
|
|
156
|
+
(0, _debug["default"])('After items height (actual or estimated)', afterItemsHeight);
|
|
157
|
+
(0, _debug["default"])('Average item height (used for estimated after items height calculation)', this.itemHeights.getAverage());
|
|
158
|
+
|
|
159
|
+
if ((0, _debug.isDebug)()) {
|
|
160
|
+
(0, _debug["default"])('Item heights', this.getState().itemHeights.slice());
|
|
161
|
+
(0, _debug["default"])('Item states', this.getState().itemStates.slice());
|
|
162
|
+
} // Optionally preload items to be rendered.
|
|
163
|
+
|
|
164
|
+
|
|
165
|
+
this.onBeforeShowItems(this.getState().items, this.getState().itemHeights, firstShownItemIndex, lastShownItemIndex); // Set `this.firstNonMeasuredItemIndex`.
|
|
166
|
+
|
|
167
|
+
this.firstNonMeasuredItemIndex = firstNonMeasuredItemIndex; // Set "previously calculated layout".
|
|
168
|
+
//
|
|
169
|
+
// The "previously calculated layout" feature is not currently used.
|
|
170
|
+
//
|
|
171
|
+
// The current layout snapshot could be stored as a "previously calculated layout" variable
|
|
172
|
+
// so that it could theoretically be used when calculating new layout incrementally
|
|
173
|
+
// rather than from scratch, which would be an optimization.
|
|
174
|
+
//
|
|
175
|
+
// Currently, this feature is not used, and `shownItemsHeight` property
|
|
176
|
+
// is not returned at all, so don't set any "previously calculated layout".
|
|
177
|
+
//
|
|
178
|
+
|
|
179
|
+
if (shownItemsHeight === undefined) {
|
|
180
|
+
this.previouslyCalculatedLayout = undefined;
|
|
181
|
+
} else {
|
|
182
|
+
// If "previously calculated layout" feature would be implmeneted,
|
|
183
|
+
// then this code would set "previously calculate layout" instance variable.
|
|
184
|
+
//
|
|
185
|
+
// What for would this instance variable be used?
|
|
186
|
+
//
|
|
187
|
+
// Instead of using a `this.previouslyCalculatedLayout` instance variable,
|
|
188
|
+
// this code could use `this.getState()` because it reflects what's currently on screen,
|
|
189
|
+
// but there's a single edge case when it could go out of sync —
|
|
190
|
+
// updating item heights externally via `.onItemHeightChange(i)`.
|
|
191
|
+
//
|
|
192
|
+
// If, for example, an item height was updated externally via `.onItemHeightChange(i)`
|
|
193
|
+
// then `this.getState().itemHeights` would get updated immediately but
|
|
194
|
+
// `this.getState().beforeItemsHeight` or `this.getState().afterItemsHeight`
|
|
195
|
+
// would still correspond to the previous item height, so those would be "stale".
|
|
196
|
+
// On the other hand, same values in `this.previouslyCalculatedLayout` instance variable
|
|
197
|
+
// can also be updated immediately, so they won't go out of sync with the updated item height.
|
|
198
|
+
// That seems the only edge case when using a separate `this.previouslyCalculatedLayout`
|
|
199
|
+
// instance variable instead of using `this.getState()` would theoretically be justified.
|
|
200
|
+
//
|
|
201
|
+
this.previouslyCalculatedLayout = {
|
|
202
|
+
firstShownItemIndex: firstShownItemIndex,
|
|
203
|
+
lastShownItemIndex: lastShownItemIndex,
|
|
204
|
+
beforeItemsHeight: beforeItemsHeight,
|
|
205
|
+
shownItemsHeight: shownItemsHeight
|
|
206
|
+
};
|
|
207
|
+
} // Update `VirtualScroller` state.
|
|
208
|
+
// `VirtualScroller` automatically re-renders on state updates.
|
|
209
|
+
//
|
|
210
|
+
// All `state` properties updated here should be overwritten in
|
|
211
|
+
// the implementation of `setItems()` and `onResize()` methods
|
|
212
|
+
// so that the `state` is not left in an inconsistent state
|
|
213
|
+
// whenever there're concurrent `updateState()` updates that could
|
|
214
|
+
// possibly conflict with one another — instead, those state updates
|
|
215
|
+
// should overwrite each other in terms of priority.
|
|
216
|
+
// These "on scroll" updates have the lowest priority compared to
|
|
217
|
+
// the state updates originating from `setItems()` and `onResize()` methods.
|
|
218
|
+
//
|
|
219
|
+
|
|
220
|
+
|
|
221
|
+
this.updateState(_objectSpread({
|
|
222
|
+
firstShownItemIndex: firstShownItemIndex,
|
|
223
|
+
lastShownItemIndex: lastShownItemIndex,
|
|
224
|
+
beforeItemsHeight: beforeItemsHeight,
|
|
225
|
+
afterItemsHeight: afterItemsHeight
|
|
226
|
+
}, stateUpdate));
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
function getVisibleArea() {
|
|
230
|
+
var visibleArea = this.scroll.getVisibleAreaBounds();
|
|
231
|
+
this.latestLayoutVisibleArea = visibleArea; // Subtract the top offset of the list inside the scrollable container.
|
|
232
|
+
|
|
233
|
+
var listTopOffsetInsideScrollableContainer = this.getListTopOffsetInsideScrollableContainer();
|
|
234
|
+
return {
|
|
235
|
+
top: visibleArea.top - listTopOffsetInsideScrollableContainer,
|
|
236
|
+
bottom: visibleArea.bottom - listTopOffsetInsideScrollableContainer
|
|
237
|
+
};
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
function getShownItemIndexes() {
|
|
241
|
+
var itemsCount = this.getItemsCount();
|
|
242
|
+
|
|
243
|
+
var _getVisibleArea$call = getVisibleArea.call(this),
|
|
244
|
+
visibleAreaTop = _getVisibleArea$call.top,
|
|
245
|
+
visibleAreaBottom = _getVisibleArea$call.bottom;
|
|
246
|
+
|
|
247
|
+
if (this.bypass) {
|
|
248
|
+
return {
|
|
249
|
+
firstShownItemIndex: 0,
|
|
250
|
+
lastShownItemIndex: itemsCount - 1 // shownItemsHeight: this.getState().itemHeights.reduce((sum, itemHeight) => sum + itemHeight, 0)
|
|
251
|
+
|
|
252
|
+
};
|
|
253
|
+
} // Find the indexes of the items that are currently visible
|
|
254
|
+
// (or close to being visible) in the scrollable container.
|
|
255
|
+
// For scrollable containers other than the main screen, it could also
|
|
256
|
+
// check the visibility of such scrollable container itself, because it
|
|
257
|
+
// might be not visible.
|
|
258
|
+
// If such kind of an optimization would hypothetically be implemented,
|
|
259
|
+
// then it would also require listening for "scroll" events on the screen.
|
|
260
|
+
// Overall, I suppose that such "actual visibility" feature would be
|
|
261
|
+
// a very minor optimization and not something I'd deal with.
|
|
262
|
+
|
|
263
|
+
|
|
264
|
+
var isVisible = visibleAreaTop < this.itemsContainer.getHeight() && visibleAreaBottom > 0;
|
|
265
|
+
|
|
266
|
+
if (!isVisible) {
|
|
267
|
+
(0, _debug["default"])('The entire list is off-screen. No items are visible.');
|
|
268
|
+
return this.layout.getNonVisibleListShownItemIndexes();
|
|
269
|
+
} // Get shown item indexes.
|
|
270
|
+
|
|
271
|
+
|
|
272
|
+
return this.layout.getShownItemIndexes({
|
|
273
|
+
itemsCount: this.getItemsCount(),
|
|
274
|
+
visibleAreaTop: visibleAreaTop,
|
|
275
|
+
visibleAreaBottom: visibleAreaBottom
|
|
276
|
+
});
|
|
277
|
+
}
|
|
278
|
+
/**
|
|
279
|
+
* Validates the heights of items to be hidden on next render.
|
|
280
|
+
* For example, a user could click a "Show more" button,
|
|
281
|
+
* or an "Expand YouTube video" button, which would result
|
|
282
|
+
* in the actual height of the list item being different
|
|
283
|
+
* from what has been initially measured in `this.itemHeights[i]`,
|
|
284
|
+
* if the developer didn't call `.onItemStateChange()` and `.onItemHeightChange(i)`.
|
|
285
|
+
*/
|
|
286
|
+
|
|
287
|
+
|
|
288
|
+
function validateWillBeHiddenItemHeightsAreAccurate(firstShownItemIndex, lastShownItemIndex) {
|
|
289
|
+
var isValid = true;
|
|
290
|
+
var i = this.getState().firstShownItemIndex;
|
|
291
|
+
|
|
292
|
+
while (i <= this.getState().lastShownItemIndex) {
|
|
293
|
+
if (i >= firstShownItemIndex && i <= lastShownItemIndex) {// The item's still visible.
|
|
294
|
+
} else {
|
|
295
|
+
// The item will be hidden. Re-measure its height.
|
|
296
|
+
// The rationale is that there could be a situation when an item's
|
|
297
|
+
// height has changed, and the developer has properly added an
|
|
298
|
+
// `.onItemHeightChange(i)` call to notify `VirtualScroller`
|
|
299
|
+
// about that change, but at the same time that wouldn't work.
|
|
300
|
+
// For example, suppose there's a list of several items on a page,
|
|
301
|
+
// and those items are in "minimized" state (having height 100px).
|
|
302
|
+
// Then, a user clicks an "Expand all items" button, and all items
|
|
303
|
+
// in the list are expanded (expanded item height is gonna be 700px).
|
|
304
|
+
// `VirtualScroller` demands that `.onItemHeightChange(i)` is called
|
|
305
|
+
// in such cases, and the developer has properly added the code to do that.
|
|
306
|
+
// So, if there were 10 "minimized" items visible on a page, then there
|
|
307
|
+
// will be 10 individual `.onItemHeightChange(i)` calls. No issues so far.
|
|
308
|
+
// But, as the first `.onItemHeightChange(i)` call executes, it immediately
|
|
309
|
+
// ("synchronously") triggers a re-layout, and that re-layout finds out
|
|
310
|
+
// that now, because the first item is big, it occupies most of the screen
|
|
311
|
+
// space, and only the first 3 items are visible on screen instead of 10,
|
|
312
|
+
// and so it leaves the first 3 items mounted and unmounts the rest 7.
|
|
313
|
+
// Then, after `VirtualScroller` has rerendered, the code returns to
|
|
314
|
+
// where it was executing, and calls `.onItemHeightChange(i)` for the
|
|
315
|
+
// second item. It also triggers an immediate re-layout that finds out
|
|
316
|
+
// that only the first 2 items are visible on screen, and it unmounts
|
|
317
|
+
// the third one too. After that, it calls `.onItemHeightChange(i)`
|
|
318
|
+
// for the third item, but that item is no longer rendered, so its height
|
|
319
|
+
// can't be measured, and the same's for all the rest of the original 10 items.
|
|
320
|
+
// So, even though the developer has written their code properly, the
|
|
321
|
+
// `VirtualScroller` still ends up having incorrect `itemHeights[]`:
|
|
322
|
+
// `[700px, 700px, 100px, 100px, 100px, 100px, 100px, 100px, 100px, 100px]`
|
|
323
|
+
// while it should have been `700px` for all of them.
|
|
324
|
+
// To work around such issues, every item's height is re-measured before it
|
|
325
|
+
// gets hidden.
|
|
326
|
+
var previouslyMeasuredItemHeight = this.getState().itemHeights[i];
|
|
327
|
+
var actualItemHeight = remeasureItemHeight.call(this, i);
|
|
328
|
+
|
|
329
|
+
if (actualItemHeight !== previouslyMeasuredItemHeight) {
|
|
330
|
+
if (isValid) {
|
|
331
|
+
(0, _debug["default"])('~ Validate will-be-hidden item heights. ~'); // Update or reset previously calculated layout.
|
|
332
|
+
|
|
333
|
+
updatePreviouslyCalculatedLayoutOnItemHeightChange.call(this, i, previouslyMeasuredItemHeight, actualItemHeight);
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
isValid = false;
|
|
337
|
+
(0, _debug.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 `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.');
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
i++;
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
return isValid;
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
function remeasureItemHeight(i) {
|
|
348
|
+
var _this$getState = this.getState(),
|
|
349
|
+
firstShownItemIndex = _this$getState.firstShownItemIndex;
|
|
350
|
+
|
|
351
|
+
return this.itemHeights.remeasureItemHeight(i, firstShownItemIndex);
|
|
352
|
+
} // Updates the snapshot of the current layout when an item's height changes.
|
|
353
|
+
//
|
|
354
|
+
// The "previously calculated layout" feature is not currently used.
|
|
355
|
+
//
|
|
356
|
+
// The current layout snapshot could be stored as a "previously calculated layout" variable
|
|
357
|
+
// so that it could theoretically be used when calculating new layout incrementally
|
|
358
|
+
// rather than from scratch, which would be an optimization.
|
|
359
|
+
//
|
|
360
|
+
|
|
361
|
+
|
|
362
|
+
function updatePreviouslyCalculatedLayoutOnItemHeightChange(i, previousHeight, newHeight) {
|
|
363
|
+
if (this.previouslyCalculatedLayout) {
|
|
364
|
+
var heightDifference = newHeight - previousHeight;
|
|
365
|
+
|
|
366
|
+
if (i < this.previouslyCalculatedLayout.firstShownItemIndex) {
|
|
367
|
+
// Patch `this.previouslyCalculatedLayout`'s `.beforeItemsHeight`.
|
|
368
|
+
this.previouslyCalculatedLayout.beforeItemsHeight += heightDifference;
|
|
369
|
+
} else if (i > this.previouslyCalculatedLayout.lastShownItemIndex) {
|
|
370
|
+
// Could patch `.afterItemsHeight` of `this.previouslyCalculatedLayout` here,
|
|
371
|
+
// if `.afterItemsHeight` property existed in `this.previouslyCalculatedLayout`.
|
|
372
|
+
if (this.previouslyCalculatedLayout.afterItemsHeight !== undefined) {
|
|
373
|
+
this.previouslyCalculatedLayout.afterItemsHeight += heightDifference;
|
|
374
|
+
}
|
|
375
|
+
} else {
|
|
376
|
+
// Patch `this.previouslyCalculatedLayout`'s shown items height.
|
|
377
|
+
this.previouslyCalculatedLayout.shownItemsHeight += newHeight - previousHeight;
|
|
378
|
+
}
|
|
379
|
+
}
|
|
380
|
+
}
|
|
381
|
+
/**
|
|
382
|
+
* Returns the list's top offset relative to the scrollable container's top edge.
|
|
383
|
+
* @return {number}
|
|
384
|
+
*/
|
|
385
|
+
|
|
386
|
+
|
|
387
|
+
this.getListTopOffsetInsideScrollableContainer = function () {
|
|
388
|
+
var listTopOffset = _this.scrollableContainer.getItemsContainerTopOffset();
|
|
389
|
+
|
|
390
|
+
if (_this.listTopOffsetWatcher) {
|
|
391
|
+
_this.listTopOffsetWatcher.onListTopOffset(listTopOffset);
|
|
392
|
+
}
|
|
393
|
+
|
|
394
|
+
return listTopOffset;
|
|
395
|
+
};
|
|
396
|
+
|
|
397
|
+
this._onItemHeightChange = function (i) {
|
|
398
|
+
(0, _debug["default"])('~ Re-measure item height ~');
|
|
399
|
+
(0, _debug["default"])('Item', i);
|
|
400
|
+
|
|
401
|
+
var _this$getState2 = _this.getState(),
|
|
402
|
+
itemHeights = _this$getState2.itemHeights,
|
|
403
|
+
firstShownItemIndex = _this$getState2.firstShownItemIndex,
|
|
404
|
+
lastShownItemIndex = _this$getState2.lastShownItemIndex; // Check if the item is still rendered.
|
|
405
|
+
|
|
406
|
+
|
|
407
|
+
if (!(i >= firstShownItemIndex && i <= lastShownItemIndex)) {
|
|
408
|
+
// There could be valid cases when an item is no longer rendered
|
|
409
|
+
// by the time `.onItemHeightChange(i)` gets called.
|
|
410
|
+
// For example, suppose there's a list of several items on a page,
|
|
411
|
+
// and those items are in "minimized" state (having height 100px).
|
|
412
|
+
// Then, a user clicks an "Expand all items" button, and all items
|
|
413
|
+
// in the list are expanded (expanded item height is gonna be 700px).
|
|
414
|
+
// `VirtualScroller` demands that `.onItemHeightChange(i)` is called
|
|
415
|
+
// in such cases, and the developer has properly added the code to do that.
|
|
416
|
+
// So, if there were 10 "minimized" items visible on a page, then there
|
|
417
|
+
// will be 10 individual `.onItemHeightChange(i)` calls. No issues so far.
|
|
418
|
+
// But, as the first `.onItemHeightChange(i)` call executes, it immediately
|
|
419
|
+
// ("synchronously") triggers a re-layout, and that re-layout finds out
|
|
420
|
+
// that now, because the first item is big, it occupies most of the screen
|
|
421
|
+
// space, and only the first 3 items are visible on screen instead of 10,
|
|
422
|
+
// and so it leaves the first 3 items mounted and unmounts the rest 7.
|
|
423
|
+
// Then, after `VirtualScroller` has rerendered, the code returns to
|
|
424
|
+
// where it was executing, and calls `.onItemHeightChange(i)` for the
|
|
425
|
+
// second item. It also triggers an immediate re-layout that finds out
|
|
426
|
+
// that only the first 2 items are visible on screen, and it unmounts
|
|
427
|
+
// the third one too. After that, it calls `.onItemHeightChange(i)`
|
|
428
|
+
// for the third item, but that item is no longer rendered, so its height
|
|
429
|
+
// can't be measured, and the same's for all the rest of the original 10 items.
|
|
430
|
+
// So, even though the developer has written their code properly, there're
|
|
431
|
+
// still situations when the item could be no longer rendered by the time
|
|
432
|
+
// `.onItemHeightChange(i)` gets called.
|
|
433
|
+
return (0, _debug.warn)('The item is no longer rendered. This is not necessarily a bug, and could happen, for example, when there\'re several `onItemHeightChange(i)` calls issued at the same time.');
|
|
434
|
+
}
|
|
435
|
+
|
|
436
|
+
var previousHeight = itemHeights[i];
|
|
437
|
+
|
|
438
|
+
if (previousHeight === undefined) {
|
|
439
|
+
return (0, _debug.reportError)("\"onItemHeightChange()\" has been called for item ".concat(i, ", but that item hasn't been rendered before."));
|
|
440
|
+
}
|
|
441
|
+
|
|
442
|
+
var newHeight = remeasureItemHeight.call(_this, i);
|
|
443
|
+
(0, _debug["default"])('Previous height', previousHeight);
|
|
444
|
+
(0, _debug["default"])('New height', newHeight);
|
|
445
|
+
|
|
446
|
+
if (previousHeight !== newHeight) {
|
|
447
|
+
(0, _debug["default"])('~ Item height has changed ~'); // Update or reset previously calculated layout.
|
|
448
|
+
|
|
449
|
+
updatePreviouslyCalculatedLayoutOnItemHeightChange.call(_this, i, previousHeight, newHeight); // Recalculate layout.
|
|
450
|
+
|
|
451
|
+
_this.onUpdateShownItemIndexes({
|
|
452
|
+
reason: _Layout.LAYOUT_REASON.ITEM_HEIGHT_CHANGED
|
|
453
|
+
}); // Schedule the item height update for after the new items have been rendered.
|
|
454
|
+
|
|
455
|
+
|
|
456
|
+
if (_this.newItemsWillBeRendered) {
|
|
457
|
+
if (!_this.itemHeightsThatChangedWhileNewItemsWereBeingRendered) {
|
|
458
|
+
_this.itemHeightsThatChangedWhileNewItemsWereBeingRendered = {};
|
|
459
|
+
}
|
|
460
|
+
|
|
461
|
+
_this.itemHeightsThatChangedWhileNewItemsWereBeingRendered[String(i)] = newHeight;
|
|
462
|
+
}
|
|
463
|
+
}
|
|
464
|
+
};
|
|
465
|
+
|
|
466
|
+
this.getPrerenderMargin = function () {
|
|
467
|
+
// The list component renders not only the items that're currently visible
|
|
468
|
+
// but also the items that lie within some extra vertical margin (called
|
|
469
|
+
// "prerender margin") on top and bottom for future scrolling: this way,
|
|
470
|
+
// there'll be significantly less layout recalculations as the user scrolls,
|
|
471
|
+
// because now it doesn't have to recalculate layout on each scroll event.
|
|
472
|
+
// By default, the "prerender margin" is equal to the screen height:
|
|
473
|
+
// this seems to be the optimal value for "Page Up" / "Page Down" navigation
|
|
474
|
+
// and optimized mouse wheel scrolling (a user is unlikely to continuously
|
|
475
|
+
// scroll past the screen height, because they'd stop to read through
|
|
476
|
+
// the newly visible items first, and when they do stop scrolling, that's
|
|
477
|
+
// when layout gets recalculated).
|
|
478
|
+
var renderAheadMarginRatio = 1; // in scrollable container heights.
|
|
479
|
+
|
|
480
|
+
return _this.scrollableContainer.getHeight() * renderAheadMarginRatio;
|
|
481
|
+
};
|
|
482
|
+
/**
|
|
483
|
+
* Calls `onItemFirstRender()` for items that haven't been
|
|
484
|
+
* "seen" previously.
|
|
485
|
+
* @param {any[]} items
|
|
486
|
+
* @param {number[]} itemHeights
|
|
487
|
+
* @param {number} firstShownItemIndex
|
|
488
|
+
* @param {number} lastShownItemIndex
|
|
489
|
+
*/
|
|
490
|
+
|
|
491
|
+
|
|
492
|
+
this.onBeforeShowItems = function (items, itemHeights, firstShownItemIndex, lastShownItemIndex) {
|
|
493
|
+
if (_this.onItemInitialRender) {
|
|
494
|
+
var i = firstShownItemIndex;
|
|
495
|
+
|
|
496
|
+
while (i <= lastShownItemIndex) {
|
|
497
|
+
if (itemHeights[i] === undefined) {
|
|
498
|
+
_this.onItemInitialRender(items[i]);
|
|
499
|
+
}
|
|
500
|
+
|
|
501
|
+
i++;
|
|
502
|
+
}
|
|
503
|
+
}
|
|
504
|
+
};
|
|
505
|
+
|
|
506
|
+
this.measureItemHeightsAndSpacing = function () {
|
|
507
|
+
// Measure "newly shown" item heights.
|
|
508
|
+
// Also re-validate already measured items' heights.
|
|
509
|
+
_this.itemHeights.measureItemHeights(_this.getState().firstShownItemIndex, _this.getState().lastShownItemIndex); // Measure item vertical spacing, if required.
|
|
510
|
+
|
|
511
|
+
|
|
512
|
+
var verticalSpacing = _this.measureVerticalSpacingIfNotMeasured(); // Return a state update if vertical spacing has been measured.
|
|
513
|
+
// Doesn't set `verticalSpacing: 0` in `state` because it is effectively
|
|
514
|
+
// same as `verticalSpacing: undefined` in terms code behavior and calculations.
|
|
515
|
+
// Not having `verticalSpacing: 0` in `state` just makes the `state` object
|
|
516
|
+
// a bit more cleaner and a bit less cluttered (easier for inspection).
|
|
517
|
+
|
|
518
|
+
|
|
519
|
+
if (verticalSpacing && verticalSpacing !== 0) {
|
|
520
|
+
// Return a state update.
|
|
521
|
+
// Sets `verticalSpacing` property in `state`.
|
|
522
|
+
return {
|
|
523
|
+
verticalSpacing: verticalSpacing
|
|
524
|
+
};
|
|
525
|
+
}
|
|
526
|
+
};
|
|
527
|
+
|
|
528
|
+
this.cancelLayoutTimer = function (_ref3) {
|
|
529
|
+
var stateUpdate = _ref3.stateUpdate;
|
|
530
|
+
|
|
531
|
+
if (_this.layoutTimer) {
|
|
532
|
+
(0, _requestAnimationFrameTimeout.clearTimeout)(_this.layoutTimer);
|
|
533
|
+
_this.layoutTimer = undefined; // Merge state updates.
|
|
534
|
+
|
|
535
|
+
if (stateUpdate || _this.layoutTimerStateUpdate) {
|
|
536
|
+
stateUpdate = _objectSpread(_objectSpread({}, _this.layoutTimerStateUpdate), stateUpdate);
|
|
537
|
+
_this.layoutTimerStateUpdate = undefined;
|
|
538
|
+
return stateUpdate;
|
|
539
|
+
}
|
|
540
|
+
} else {
|
|
541
|
+
return stateUpdate;
|
|
542
|
+
}
|
|
543
|
+
};
|
|
544
|
+
|
|
545
|
+
this.scheduleLayoutTimer = function (_ref4) {
|
|
546
|
+
var reason = _ref4.reason,
|
|
547
|
+
stateUpdate = _ref4.stateUpdate;
|
|
548
|
+
_this.layoutTimerStateUpdate = stateUpdate;
|
|
549
|
+
_this.layoutTimer = (0, _requestAnimationFrameTimeout.setTimeout)(function () {
|
|
550
|
+
_this.layoutTimerStateUpdate = undefined;
|
|
551
|
+
_this.layoutTimer = undefined;
|
|
552
|
+
|
|
553
|
+
_this.onUpdateShownItemIndexes({
|
|
554
|
+
reason: reason,
|
|
555
|
+
stateUpdate: stateUpdate
|
|
556
|
+
});
|
|
557
|
+
}, 0);
|
|
558
|
+
};
|
|
559
|
+
}
|
|
560
|
+
|
|
561
|
+
var SLOW_LAYOUT_DURATION = 15; // in milliseconds.
|
|
562
|
+
//# sourceMappingURL=VirtualScroller.layout.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"VirtualScroller.layout.js","names":["onUpdateShownItemIndexes","reason","stateUpdate","skip","updateState","newItemsWillBeRendered","widthHasChanged","_isResizing","getItemsCount","scroll","cancelScheduledLayout","cancelLayoutTimer","log","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","warn","getColumnsCount","itemHeights","getAverage","isDebug","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","reportError","LAYOUT_REASON","ITEM_HEIGHT_CHANGED","itemHeightsThatChangedWhileNewItemsWereBeingRendered","String","getPrerenderMargin","renderAheadMarginRatio","onItemInitialRender","measureItemHeightsAndSpacing","measureItemHeights","verticalSpacing","measureVerticalSpacingIfNotMeasured","layoutTimer","clearTimeout","layoutTimerStateUpdate","scheduleLayoutTimer","setTimeout"],"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 `.onItemStateChange()` 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 `.onItemStateChange()` 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', 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 there\\'re several `onItemHeightChange(i)` calls issued at the same time.')\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.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":";;;;;;;;;AAIA;;AAEA;;AACA;;;;;;;;;;;;AAEe,oBAAW;EAAA;;EACzB,KAAKA,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;IAC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