virtual-scroller 1.11.0 → 1.11.2
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/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 +22 -9
- package/commonjs/DOM/ItemsContainer.js.map +1 -1
- package/commonjs/ItemHeights.js +1 -1
- package/commonjs/ItemHeights.js.map +1 -1
- package/commonjs/VirtualScroller.layout.js +2 -2
- package/commonjs/VirtualScroller.layout.js.map +1 -1
- package/commonjs/VirtualScroller.state.js +1 -1
- package/commonjs/VirtualScroller.state.js.map +1 -1
- package/commonjs/react/VirtualScroller.js +48 -16
- package/commonjs/react/VirtualScroller.js.map +1 -1
- package/commonjs/react/useHandleItemIndexesChange.js +53 -0
- package/commonjs/react/useHandleItemIndexesChange.js.map +1 -0
- package/commonjs/react/{useHandleItemsChange.js → useHandleItemsPropertyChange.js} +21 -40
- package/commonjs/react/useHandleItemsPropertyChange.js.map +1 -0
- package/commonjs/react/useOnItemHeightChange.js +2 -2
- package/commonjs/react/useOnItemHeightChange.js.map +1 -1
- package/commonjs/react/useSetItemState.js +2 -2
- package/commonjs/react/useSetItemState.js.map +1 -1
- package/commonjs/react/useState.js +47 -69
- package/commonjs/react/useState.js.map +1 -1
- package/commonjs/react/useStyle.js +4 -4
- package/commonjs/react/useStyle.js.map +1 -1
- package/index.d.ts +1 -1
- package/modules/DOM/ItemsContainer.js +22 -9
- package/modules/DOM/ItemsContainer.js.map +1 -1
- package/modules/ItemHeights.js +1 -1
- package/modules/ItemHeights.js.map +1 -1
- package/modules/VirtualScroller.layout.js +2 -2
- package/modules/VirtualScroller.layout.js.map +1 -1
- package/modules/VirtualScroller.state.js +1 -1
- package/modules/VirtualScroller.state.js.map +1 -1
- package/modules/react/VirtualScroller.js +47 -17
- package/modules/react/VirtualScroller.js.map +1 -1
- package/modules/react/useHandleItemIndexesChange.js +45 -0
- package/modules/react/useHandleItemIndexesChange.js.map +1 -0
- package/modules/react/{useHandleItemsChange.js → useHandleItemsPropertyChange.js} +20 -39
- package/modules/react/useHandleItemsPropertyChange.js.map +1 -0
- package/modules/react/useOnItemHeightChange.js +2 -2
- package/modules/react/useOnItemHeightChange.js.map +1 -1
- package/modules/react/useSetItemState.js +2 -2
- package/modules/react/useSetItemState.js.map +1 -1
- package/modules/react/useState.js +48 -70
- package/modules/react/useState.js.map +1 -1
- package/modules/react/useStyle.js +4 -4
- package/modules/react/useStyle.js.map +1 -1
- package/package.json +1 -1
- package/source/DOM/ItemsContainer.js +13 -3
- package/source/ItemHeights.js +1 -1
- package/source/VirtualScroller.layout.js +2 -2
- package/source/VirtualScroller.state.js +1 -1
- package/source/react/VirtualScroller.js +45 -13
- package/source/react/useHandleItemIndexesChange.js +49 -0
- package/source/react/{useHandleItemsChange.js → useHandleItemsPropertyChange.js} +20 -38
- package/source/react/useOnItemHeightChange.js +2 -2
- package/source/react/useSetItemState.js +2 -2
- package/source/react/useState.js +57 -72
- package/source/react/useStyle.js +2 -2
- package/commonjs/react/useHandleItemsChange.js.map +0 -1
- package/modules/react/useHandleItemsChange.js.map +0 -1
|
@@ -21,17 +21,30 @@ var ItemsContainer = /*#__PURE__*/function () {
|
|
|
21
21
|
|
|
22
22
|
this.getElement = getElement;
|
|
23
23
|
}
|
|
24
|
-
/**
|
|
25
|
-
* Returns an item element's "top offset", relative to the items `container`'s top edge.
|
|
26
|
-
* @param {number} renderedElementIndex — An index of an item relative to the "first shown item index". For example, if the list is showing items from index 8 to index 12 then `renderedElementIndex = 0` would mean the item at index `8`.
|
|
27
|
-
* @return {number}
|
|
28
|
-
*/
|
|
29
|
-
|
|
30
24
|
|
|
31
25
|
_createClass(ItemsContainer, [{
|
|
26
|
+
key: "_getNthRenderedItemElement",
|
|
27
|
+
value: function _getNthRenderedItemElement(renderedElementIndex) {
|
|
28
|
+
var childNodes = this.getElement().childNodes;
|
|
29
|
+
|
|
30
|
+
if (renderedElementIndex > childNodes.length - 1) {
|
|
31
|
+
console.log('~ Items Container Contents ~');
|
|
32
|
+
console.log(this.getElement().innerHTML);
|
|
33
|
+
throw new Error("Element with index ".concat(renderedElementIndex, " was not found in the list of Rendered Item Elements in the Items Container of Virtual Scroller. There're only ").concat(childNodes.length, " Elements there."));
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
return childNodes[renderedElementIndex];
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Returns an item element's "top offset", relative to the items `container`'s top edge.
|
|
40
|
+
* @param {number} renderedElementIndex — An index of an item relative to the "first shown item index". For example, if the list is showing items from index 8 to index 12 then `renderedElementIndex = 0` would mean the item at index `8`.
|
|
41
|
+
* @return {number}
|
|
42
|
+
*/
|
|
43
|
+
|
|
44
|
+
}, {
|
|
32
45
|
key: "getNthRenderedItemTopOffset",
|
|
33
46
|
value: function getNthRenderedItemTopOffset(renderedElementIndex) {
|
|
34
|
-
return this.
|
|
47
|
+
return this._getNthRenderedItemElement(renderedElementIndex).getBoundingClientRect().top - this.getElement().getBoundingClientRect().top;
|
|
35
48
|
}
|
|
36
49
|
/**
|
|
37
50
|
* Returns an item element's height.
|
|
@@ -43,8 +56,8 @@ var ItemsContainer = /*#__PURE__*/function () {
|
|
|
43
56
|
key: "getNthRenderedItemHeight",
|
|
44
57
|
value: function getNthRenderedItemHeight(renderedElementIndex) {
|
|
45
58
|
// `offsetHeight` is not precise enough (doesn't return fractional pixels).
|
|
46
|
-
// return this.
|
|
47
|
-
return this.
|
|
59
|
+
// return this._getNthRenderedItemElement(renderedElementIndex).offsetHeight
|
|
60
|
+
return this._getNthRenderedItemElement(renderedElementIndex).getBoundingClientRect().height;
|
|
48
61
|
}
|
|
49
62
|
/**
|
|
50
63
|
* Returns items container height.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ItemsContainer.js","names":["ItemsContainer","getElement","renderedElementIndex","childNodes","getBoundingClientRect","top","height","firstChild","removeChild"],"sources":["../../source/DOM/ItemsContainer.js"],"sourcesContent":["export default class ItemsContainer {\r\n\t/**\r\n\t * Constructs a new \"container\" from an element.\r\n\t * @param {function} getElement\r\n\t */\r\n\tconstructor(getElement) {\r\n\t\tthis.getElement = getElement\r\n\t}\r\n\r\n\t/**\r\n\t * Returns an item element's \"top offset\", relative to the items `container`'s top edge.\r\n\t * @param {number} renderedElementIndex — An index of an item relative to the \"first shown item index\". For example, if the list is showing items from index 8 to index 12 then `renderedElementIndex = 0` would mean the item at index `8`.\r\n\t * @return {number}\r\n\t */\r\n\tgetNthRenderedItemTopOffset(renderedElementIndex) {\r\n\t\treturn this.
|
|
1
|
+
{"version":3,"file":"ItemsContainer.js","names":["ItemsContainer","getElement","renderedElementIndex","childNodes","length","console","log","innerHTML","Error","_getNthRenderedItemElement","getBoundingClientRect","top","height","firstChild","removeChild"],"sources":["../../source/DOM/ItemsContainer.js"],"sourcesContent":["export default class ItemsContainer {\r\n\t/**\r\n\t * Constructs a new \"container\" from an element.\r\n\t * @param {function} getElement\r\n\t */\r\n\tconstructor(getElement) {\r\n\t\tthis.getElement = getElement\r\n\t}\r\n\r\n\t_getNthRenderedItemElement(renderedElementIndex) {\r\n\t\tconst childNodes = this.getElement().childNodes\r\n\t\tif (renderedElementIndex > childNodes.length - 1) {\r\n\t\t\tconsole.log('~ Items Container Contents ~')\r\n\t\t\tconsole.log(this.getElement().innerHTML)\r\n\t\t\tthrow new Error(`Element with index ${renderedElementIndex} was not found in the list of Rendered Item Elements in the Items Container of Virtual Scroller. There're only ${childNodes.length} Elements there.`)\r\n\t\t}\r\n\t\treturn childNodes[renderedElementIndex]\r\n\t}\r\n\r\n\t/**\r\n\t * Returns an item element's \"top offset\", relative to the items `container`'s top edge.\r\n\t * @param {number} renderedElementIndex — An index of an item relative to the \"first shown item index\". For example, if the list is showing items from index 8 to index 12 then `renderedElementIndex = 0` would mean the item at index `8`.\r\n\t * @return {number}\r\n\t */\r\n\tgetNthRenderedItemTopOffset(renderedElementIndex) {\r\n\t\treturn this._getNthRenderedItemElement(renderedElementIndex).getBoundingClientRect().top - this.getElement().getBoundingClientRect().top\r\n\t}\r\n\r\n\t/**\r\n\t * Returns an item element's height.\r\n\t * @param {number} renderedElementIndex — An index of an item relative to the \"first shown item index\". For example, if the list is showing items from index 8 to index 12 then `renderedElementIndex = 0` would mean the item at index `8`.\r\n\t * @return {number}\r\n\t */\r\n\tgetNthRenderedItemHeight(renderedElementIndex) {\r\n\t\t// `offsetHeight` is not precise enough (doesn't return fractional pixels).\r\n\t\t// return this._getNthRenderedItemElement(renderedElementIndex).offsetHeight\r\n\t\treturn this._getNthRenderedItemElement(renderedElementIndex).getBoundingClientRect().height\r\n\t}\r\n\r\n\t/**\r\n\t * Returns items container height.\r\n\t * @return {number}\r\n\t */\r\n\tgetHeight() {\r\n\t\t// `offsetHeight` is not precise enough (doesn't return fractional pixels).\r\n\t\t// return this.getElement().offsetHeight\r\n\t\treturn this.getElement().getBoundingClientRect().height\r\n\t}\r\n\r\n\t/**\r\n\t * Removes all item elements of an items container.\r\n\t */\r\n\tclear() {\r\n\t\twhile (this.getElement().firstChild) {\r\n\t\t\tthis.getElement().removeChild(this.getElement().firstChild)\r\n\t\t}\r\n\t}\r\n}"],"mappings":";;;;;;;;;;;;;IAAqBA,c;EACpB;AACD;AACA;AACA;EACC,wBAAYC,UAAZ,EAAwB;IAAA;;IACvB,KAAKA,UAAL,GAAkBA,UAAlB;EACA;;;;WAED,oCAA2BC,oBAA3B,EAAiD;MAChD,IAAMC,UAAU,GAAG,KAAKF,UAAL,GAAkBE,UAArC;;MACA,IAAID,oBAAoB,GAAGC,UAAU,CAACC,MAAX,GAAoB,CAA/C,EAAkD;QACjDC,OAAO,CAACC,GAAR,CAAY,8BAAZ;QACAD,OAAO,CAACC,GAAR,CAAY,KAAKL,UAAL,GAAkBM,SAA9B;QACA,MAAM,IAAIC,KAAJ,8BAAgCN,oBAAhC,4HAAsKC,UAAU,CAACC,MAAjL,sBAAN;MACA;;MACD,OAAOD,UAAU,CAACD,oBAAD,CAAjB;IACA;IAED;AACD;AACA;AACA;AACA;;;;WACC,qCAA4BA,oBAA5B,EAAkD;MACjD,OAAO,KAAKO,0BAAL,CAAgCP,oBAAhC,EAAsDQ,qBAAtD,GAA8EC,GAA9E,GAAoF,KAAKV,UAAL,GAAkBS,qBAAlB,GAA0CC,GAArI;IACA;IAED;AACD;AACA;AACA;AACA;;;;WACC,kCAAyBT,oBAAzB,EAA+C;MAC9C;MACA;MACA,OAAO,KAAKO,0BAAL,CAAgCP,oBAAhC,EAAsDQ,qBAAtD,GAA8EE,MAArF;IACA;IAED;AACD;AACA;AACA;;;;WACC,qBAAY;MACX;MACA;MACA,OAAO,KAAKX,UAAL,GAAkBS,qBAAlB,GAA0CE,MAAjD;IACA;IAED;AACD;AACA;;;;WACC,iBAAQ;MACP,OAAO,KAAKX,UAAL,GAAkBY,UAAzB,EAAqC;QACpC,KAAKZ,UAAL,GAAkBa,WAAlB,CAA8B,KAAKb,UAAL,GAAkBY,UAAhD;MACA;IACD"}
|
package/commonjs/ItemHeights.js
CHANGED
|
@@ -208,7 +208,7 @@ var ItemHeights = /*#__PURE__*/function () {
|
|
|
208
208
|
var _height = this._measureItemHeight(i, firstShownItemIndex);
|
|
209
209
|
|
|
210
210
|
if (previousHeight !== _height) {
|
|
211
|
-
(0, _debug.warn)('Item index', i, 'height changed unexpectedly: it was', previousHeight, 'before, but now it is', _height, '. An item\'s height is allowed to change only in two cases: when the item\'s "state" changes and the developer calls `setItemState(i, newState)`, or when the item\'s height changes for
|
|
211
|
+
(0, _debug.warn)('Item index', i, 'height changed unexpectedly: it was', previousHeight, 'before, but now it is', _height, '. An item\'s height is allowed to change only in two cases: when the item\'s "state" changes and the developer calls `setItemState(i, newState)`, or when the item\'s height changes for any reason and the developer calls `onItemHeightChange(i)`. Perhaps you forgot to persist the item\'s "state" by calling `setItemState(i, newState)` when it changed, and that "state" got lost when the item element was unmounted, which resulted in a different height when the item was shown again having its "state" reset.'); // Update the item's height as an attempt to fix things.
|
|
212
212
|
|
|
213
213
|
this._set(i, _height);
|
|
214
214
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ItemHeights.js","names":["ItemHeights","container","itemHeights","getItemHeight","setItemHeight","_get","_set","reset","measuredItemsHeight","firstMeasuredItemIndex","undefined","lastMeasuredItemIndex","i","length","firstShownItemIndex","getNthRenderedItemHeight","lastShownItemIndex","log","nonPreviouslyMeasuredItemIndexes","previousFirstMeasuredItemIndex","previousLastMeasuredItemIndex","firstMeasuredItemIndexHasBeenUpdated","push","height","_measureItemHeight","previousHeight","warn","count"],"sources":["../source/ItemHeights.js"],"sourcesContent":["import log, { warn, isDebug, reportError } from './utility/debug.js'\r\n\r\nexport default class ItemHeights {\r\n\tconstructor({\r\n\t\tcontainer,\r\n\t\titemHeights,\r\n\t\tgetItemHeight,\r\n\t\tsetItemHeight\r\n\t}) {\r\n\t\tthis.container = container\r\n\t\tthis._get = getItemHeight\r\n\t\tthis._set = setItemHeight\r\n\t\tthis.reset()\r\n\t}\r\n\r\n\treset() {\r\n\t\tthis.measuredItemsHeight = 0\r\n\t\t// \"First measured item index\" variable was introduced\r\n\t\t// because it's not always `0`: when `virtualScroller.setItems()`\r\n\t\t// is called, some items might get prepended, in which case\r\n\t\t// `this.lastMeasuredItemIndex` is updated. If there was no\r\n\t\t// `this.firstMeasuredItemIndex`, then the average item height\r\n\t\t// calculated in `.getAverage()` would be incorrect in the timeframe\r\n\t\t// between `.setItems()` is called and those changes have been rendered.\r\n\t\t// And in that timeframe, `.getAverage()` is used to calculate the \"layout\":\r\n\t\t// stuff like \"before/after items height\" and \"estimated items count on screen\".\r\n\t\tthis.firstMeasuredItemIndex = undefined\r\n\t\tthis.lastMeasuredItemIndex = undefined\r\n\t}\r\n\r\n\t/**\r\n\t * Can only be called after a `.reset()` (including new instance creation).\r\n\t * Initializes `this.measuredItemsHeight`, `this.firstMeasuredItemIndex`\r\n\t * and `this.lastMeasuredItemIndex` instance variables from `VirtualScroller` `state`.\r\n\t * These instance variables are used when calculating \"average\" item height:\r\n\t * the \"average\" item height is simply `this.measuredItemsHeight` divided by\r\n\t * `this.lastMeasuredItemIndex` minus `this.firstMeasuredItemIndex` plus 1.\r\n\t */\r\n\treadItemHeightsFromState({ itemHeights }) {\r\n\t\tlet i = 0\r\n\t\twhile (i < itemHeights.length) {\r\n\t\t\tif (itemHeights[i] === undefined) {\r\n\t\t\t\tif (this.firstMeasuredItemIndex !== undefined) {\r\n\t\t\t\t\tthis.lastMeasuredItemIndex = i - 1\r\n\t\t\t\t\tbreak\r\n\t\t\t\t}\r\n\t\t\t} else {\r\n\t\t\t\tif (this.firstMeasuredItemIndex === undefined) {\r\n\t\t\t\t\tthis.firstMeasuredItemIndex = i\r\n\t\t\t\t}\r\n\t\t\t\tthis.measuredItemsHeight += itemHeights[i]\r\n\t\t\t}\r\n\t\t\ti++\r\n\t\t}\r\n\t}\r\n\r\n\t// Seems to be no longer used.\r\n\t// getItemHeight(i, firstShownItemIndex) {\r\n\t// \tif (this._get(i)) {\r\n\t// \t\treturn this._get(i)\r\n\t// \t}\r\n\t// \tconst itemHeight = this._measureItemHeight(i, firstShownItemIndex)\r\n\t// \tif (itemHeight) {\r\n\t// \t\tthis._set(i, itemHeight)\r\n\t// \t\treturn itemHeight\r\n\t// \t}\r\n\t// \treturn this.getAverage()\r\n\t// }\r\n\r\n\t_measureItemHeight(i, firstShownItemIndex) {\r\n\t\treturn this.container.getNthRenderedItemHeight(i - firstShownItemIndex)\r\n\t}\r\n\r\n\t/**\r\n\t * Measures item heights:\r\n\t *\r\n\t * * For the items that haven't been previously measured,\r\n\t * measures them for the first time.\r\n\t *\r\n\t * * For the items that have been previoulsy measured,\r\n\t * validate that their previously measured height\r\n\t * is still equal to their current height.\r\n\t * The unequalness may not necessarily be caused by\r\n\t * incorrect use of `virtual-scroller`: there are\r\n\t * also some valid use cases when such unequalness\r\n\t * could happen (see the comments in the code).\r\n\t *\r\n\t * @param {number} firstShownItemIndex\r\n\t * @param {number} lastShownItemIndex\r\n\t * @return {number[]} The indexes of the items that have not previously been measured and have been measured now.\r\n\t */\r\n\tmeasureItemHeights(firstShownItemIndex, lastShownItemIndex) {\r\n\t\tlog('~ Measure item heights ~')\r\n\t\t// If no items are rendered, don't measure anything.\r\n\t\tif (firstShownItemIndex === undefined) {\r\n\t\t\treturn\r\n\t\t}\r\n\t\t// Reset `this.measuredItemsHeight` if it's not a \"continuous\" measured items list:\r\n\t\t// if a group of items has been measured previously, and now it has rendered a completely\r\n\t\t// different group of items, and there's a non-measured \"gap\" between those two groups,\r\n\t\t// then reset `this.measuredItemsHeight` and \"first measured\"/\"last measured\" item indexes.\r\n\t\t// For example, this could happen when `.setItems()` prepends a lot of new items.\r\n\t\tif (this.firstMeasuredItemIndex !== undefined) {\r\n\t\t\tif (\r\n\t\t\t\tfirstShownItemIndex > this.lastMeasuredItemIndex + 1 ||\r\n\t\t\t\tlastShownItemIndex < this.firstMeasuredItemIndex - 1\r\n\t\t\t) {\r\n\t\t\t\t// Reset.\r\n\t\t\t\tlog('Non-measured items gap detected. Reset first and last measured item indexes.')\r\n\t\t\t\tthis.reset()\r\n\t\t\t}\r\n\t\t}\r\n\t\tconst nonPreviouslyMeasuredItemIndexes = []\r\n\t\tconst previousFirstMeasuredItemIndex = this.firstMeasuredItemIndex\r\n\t\tconst previousLastMeasuredItemIndex = this.lastMeasuredItemIndex\r\n\t\tlet firstMeasuredItemIndexHasBeenUpdated = false\r\n\t\tlet i = firstShownItemIndex\r\n\t\twhile (i <= lastShownItemIndex) {\r\n\t\t\t// Measure item heights that haven't been measured previously.\r\n\t\t\t// Don't re-measure item heights that have been measured previously.\r\n\t\t\t// The rationale is that developers are supposed to manually call\r\n\t\t\t// `.onItemHeightChange()` every time an item's height changes.\r\n\t\t\t// If developers don't neglect that rule, item heights won't\r\n\t\t\t// change unexpectedly.\r\n\t\t\tif (this._get(i) === undefined) {\r\n\t\t\t\tnonPreviouslyMeasuredItemIndexes.push(i)\r\n\t\t\t\tconst height = this._measureItemHeight(i, firstShownItemIndex)\r\n\t\t\t\tlog('Item index', i, 'height', height)\r\n\t\t\t\tthis._set(i, height)\r\n\t\t\t\t// Update average item height calculation variables\r\n\t\t\t\t// related to the previously measured items\r\n\t\t\t\t// that're above the items currently being shown.\r\n\t\t\t\t// It is known to be a \"continuous\" measured items list,\r\n\t\t\t\t// because the code at the start of this function checks that.\r\n\t\t\t\tif (previousFirstMeasuredItemIndex === undefined || i < previousFirstMeasuredItemIndex) {\r\n\t\t\t\t\tthis.measuredItemsHeight += height\r\n\t\t\t\t\t// Update first measured item index.\r\n\t\t\t\t\tif (!firstMeasuredItemIndexHasBeenUpdated) {\r\n\t\t\t\t\t\t// log('Set first measured item index', i)\r\n\t\t\t\t\t\tthis.firstMeasuredItemIndex = i\r\n\t\t\t\t\t\tfirstMeasuredItemIndexHasBeenUpdated = true\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t\t// Update average item height calculation variables\r\n\t\t\t\t// related to the previously measured items\r\n\t\t\t\t// that're below the items currently being shown.\r\n\t\t\t\t// It is known to be a \"continuous\" measured items list,\r\n\t\t\t\t// because the code at the start of this function checks that.\r\n\t\t\t\tif (previousLastMeasuredItemIndex === undefined || i > previousLastMeasuredItemIndex) {\r\n\t\t\t\t\t// If `previousLastMeasuredItemIndex` is `undefined`\r\n\t\t\t\t\t// then `previousFirstMeasuredItemIndex` is also `undefined`\r\n\t\t\t\t\t// which means that the item's `height` has already been added\r\n\t\t\t\t\t// to `this.measuredItemsHeight` in the code above,\r\n\t\t\t\t\t// so this condition guards against counting the item's `height`\r\n\t\t\t\t\t// twice in `this.measuredItemsHeight`.\r\n\t\t\t\t\tif (previousLastMeasuredItemIndex !== undefined) {\r\n\t\t\t\t\t\t// Add newly shown item height.\r\n\t\t\t\t\t\tthis.measuredItemsHeight += height\r\n\t\t\t\t\t}\r\n\t\t\t\t\t// Update last measured item index.\r\n\t\t\t\t\tthis.lastMeasuredItemIndex = i\r\n\t\t\t\t}\r\n\t\t\t} else {\r\n\t\t\t\t// Validate that the item's height didn't change since it was last measured.\r\n\t\t\t\t// If it did, then display a warning and update the item's height\r\n\t\t\t\t// as an attempt to fix things.\r\n\t\t\t\t// If an item's height changes unexpectedly then it means that there'll\r\n\t\t\t\t// likely be \"content jumping\".\r\n\t\t\t\tconst previousHeight = this._get(i)\r\n\t\t\t\tconst height = this._measureItemHeight(i, firstShownItemIndex)\r\n\t\t\t\tif (previousHeight !== height) {\r\n\t\t\t\t\twarn('Item index', i, 'height changed unexpectedly: it was', previousHeight, 'before, but now it is', height, '. An item\\'s height is allowed to change only in two cases: when the item\\'s \"state\" changes and the developer calls `setItemState(i, newState)`, or when the item\\'s height changes for some other reason and the developer calls `onItemHeightChange(i)`. Perhaps you forgot to persist the item\\'s \"state\" by calling `setItemState(i, newState)` when it changed, and that \"state\" got lost when the item element was unmounted, which resulted in a different height when the item was shown again having its \"state\" reset.')\r\n\t\t\t\t\t// Update the item's height as an attempt to fix things.\r\n\t\t\t\t\tthis._set(i, height)\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\ti++\r\n\t\t}\r\n\t\t// // Update average item height.\r\n\t\t// this.updateAverageItemHeight()\r\n\t\treturn nonPreviouslyMeasuredItemIndexes\r\n\t}\r\n\r\n\t/**\r\n\t * Re-measures item height.\r\n\t * @param {number} i — Item index.\r\n\t * @param {number} firstShownItemIndex\r\n\t */\r\n\tremeasureItemHeight(i, firstShownItemIndex) {\r\n\t\tconst previousHeight = this._get(i)\r\n\t\tconst height = this._measureItemHeight(i, firstShownItemIndex)\r\n\t\t// // Because this function is called from `.onItemHeightChange()`,\r\n\t\t// // there're no guarantees in which circumstances a developer calls it,\r\n\t\t// // and for which item indexes.\r\n\t\t// // Therefore, to guard against cases of incorrect usage,\r\n\t\t// // this function won't crash anything if the item isn't rendered\r\n\t\t// // or hasn't been previously rendered.\r\n\t\t// if (height !== undefined) {\r\n\t\t// \treportError(`\"onItemHeightChange()\" has been called for item ${i}, but that item isn't rendered.`)\r\n\t\t// \treturn\r\n\t\t// }\r\n\t\t// if (previousHeight === undefined) {\r\n\t\t// \treportError(`\"onItemHeightChange()\" has been called for item ${i}, but that item hasn't been rendered before.`)\r\n\t\t// \treturn\r\n\t\t// }\r\n\t\tthis._set(i, height)\r\n\t\tthis.measuredItemsHeight += height - previousHeight\r\n\t\treturn height\r\n\t}\r\n\r\n\t// /**\r\n\t// * \"Average\" item height is stored as an instance variable.\r\n\t// * For example, for caching, so that it isn't calculated every time it's requested.\r\n\t// * But that would be negligible performance gain, not really worth the extra code.\r\n\t// * Another thing it's stored for as an instance variable is\r\n\t// * keeping \"previous\" \"average\" item height, because it can be more precise\r\n\t// * than the newly calculated \"average\" item height, provided it had\r\n\t// * more \"samples\" (measured items). The newly calculated average item height\r\n\t// * could get less samples in a scenario when the scroll somehow jumps\r\n\t// * from one position to some other distant position: in that case previous\r\n\t// * \"total measured items height\" is discarded and the new one is initialized.\r\n\t// * Could such situation happen in real life? I guess, it's unlikely.\r\n\t// * So I'm commenting out this code, but still keeping it just in case.\r\n\t// */\r\n\t// updateAverageItemHeight() {\r\n\t// \tthis.averageItemHeightSamplesCount = this.lastMeasuredItemIndex - this.firstMeasuredItemIndex + 1\r\n\t// \tthis.averageItemHeight = this.measuredItemsHeight / this.averageItemHeightSamplesCount\r\n\t// }\r\n\t//\r\n\t// /**\r\n\t// * Public API: is called by `VirtualScroller`.\r\n\t// * @return {number}\r\n\t// */\r\n\t// getAverage() {\r\n\t// \t// Previously measured average item height might still be\r\n\t// \t// more precise if it contains more measured items (\"samples\").\r\n\t// \tif (this.previousAverageItemHeight) {\r\n\t// \t\tif (this.previousAverageItemHeightSamplesCount > this.averageItemHeightSamplesCount) {\r\n\t// \t\t\treturn this.previousAverageItemHeight\r\n\t// \t\t}\r\n\t// \t}\r\n\t// \treturn this.averageItemHeight || 0\r\n\t// }\r\n\r\n\t/**\r\n\t * Public API: is called by `VirtualScroller`.\r\n\t * @return {number}\r\n\t */\r\n\tgetAverage() {\r\n\t\tif (this.lastMeasuredItemIndex === undefined) {\r\n\t\t\treturn 0\r\n\t\t}\r\n\t\treturn this.measuredItemsHeight / (this.lastMeasuredItemIndex - this.firstMeasuredItemIndex + 1)\r\n\t}\r\n\r\n\tonPrepend(count) {\r\n\t\tif (this.firstMeasuredItemIndex !== undefined) {\r\n\t\t\tthis.firstMeasuredItemIndex += count\r\n\t\t\tthis.lastMeasuredItemIndex += count\r\n\t\t}\r\n\t}\r\n}"],"mappings":";;;;;;;;;AAAA;;;;;;;;;;;;IAEqBA,W;EACpB,2BAKG;IAAA,IAJFC,SAIE,QAJFA,SAIE;IAAA,IAHFC,WAGE,QAHFA,WAGE;IAAA,IAFFC,aAEE,QAFFA,aAEE;IAAA,IADFC,aACE,QADFA,aACE;;IAAA;;IACF,KAAKH,SAAL,GAAiBA,SAAjB;IACA,KAAKI,IAAL,GAAYF,aAAZ;IACA,KAAKG,IAAL,GAAYF,aAAZ;IACA,KAAKG,KAAL;EACA;;;;WAED,iBAAQ;MACP,KAAKC,mBAAL,GAA2B,CAA3B,CADO,CAEP;MACA;MACA;MACA;MACA;MACA;MACA;MACA;MACA;;MACA,KAAKC,sBAAL,GAA8BC,SAA9B;MACA,KAAKC,qBAAL,GAA6BD,SAA7B;IACA;IAED;AACD;AACA;AACA;AACA;AACA;AACA;AACA;;;;WACC,yCAA0C;MAAA,IAAfR,WAAe,SAAfA,WAAe;MACzC,IAAIU,CAAC,GAAG,CAAR;;MACA,OAAOA,CAAC,GAAGV,WAAW,CAACW,MAAvB,EAA+B;QAC9B,IAAIX,WAAW,CAACU,CAAD,CAAX,KAAmBF,SAAvB,EAAkC;UACjC,IAAI,KAAKD,sBAAL,KAAgCC,SAApC,EAA+C;YAC9C,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AaW,OAAb;UACA;QACD;;QACDX,CAAC;MACD,CAtF0D,CAuF3D;MACA;;;MACA,OAAOM,gCAAP;IACA;IAED;AACD;AACA;AACA;AACA;;;;WACC,6BAAoBN,CAApB,EAAuBE,mBAAvB,EAA4C;MAC3C,IAAMW,cAAc,GAAG,KAAKpB,IAAL,CAAUO,CAAV,CAAvB;;MACA,IAAMW,MAAM,GAAG,KAAKC,kBAAL,CAAwBZ,CAAxB,EAA2BE,mBAA3B,CAAf,CAF2C,CAG3C;MACA;MACA;MACA;MACA;MACA;MACA;MACA;MACA;MACA;MACA;MACA;MACA;MACA;;;MACA,KAAKR,IAAL,CAAUM,CAAV,EAAaW,MAAb;;MACA,KAAKf,mBAAL,IAA4Be,MAAM,GAAGE,cAArC;MACA,OAAOF,MAAP;IACA,C,CAED;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;;IAEA;AACD;AACA;AACA;;;;WACC,sBAAa;MACZ,IAAI,KAAKZ,qBAAL,KAA+BD,SAAnC,EAA8C;QAC7C,OAAO,CAAP;MACA;;MACD,OAAO,KAAKF,mBAAL,IAA4B,KAAKG,qBAAL,GAA6B,KAAKF,sBAAlC,GAA2D,CAAvF,CAAP;IACA;;;WAED,mBAAUkB,KAAV,EAAiB;MAChB,IAAI,KAAKlB,sBAAL,KAAgCC,SAApC,EAA+C;QAC9C,KAAKD,sBAAL,IAA+BkB,KAA/B;QACA,KAAKhB,qBAAL,IAA8BgB,KAA9B;MACA;IACD"}
|
|
1
|
+
{"version":3,"file":"ItemHeights.js","names":["ItemHeights","container","itemHeights","getItemHeight","setItemHeight","_get","_set","reset","measuredItemsHeight","firstMeasuredItemIndex","undefined","lastMeasuredItemIndex","i","length","firstShownItemIndex","getNthRenderedItemHeight","lastShownItemIndex","log","nonPreviouslyMeasuredItemIndexes","previousFirstMeasuredItemIndex","previousLastMeasuredItemIndex","firstMeasuredItemIndexHasBeenUpdated","push","height","_measureItemHeight","previousHeight","warn","count"],"sources":["../source/ItemHeights.js"],"sourcesContent":["import log, { warn, isDebug, reportError } from './utility/debug.js'\r\n\r\nexport default class ItemHeights {\r\n\tconstructor({\r\n\t\tcontainer,\r\n\t\titemHeights,\r\n\t\tgetItemHeight,\r\n\t\tsetItemHeight\r\n\t}) {\r\n\t\tthis.container = container\r\n\t\tthis._get = getItemHeight\r\n\t\tthis._set = setItemHeight\r\n\t\tthis.reset()\r\n\t}\r\n\r\n\treset() {\r\n\t\tthis.measuredItemsHeight = 0\r\n\t\t// \"First measured item index\" variable was introduced\r\n\t\t// because it's not always `0`: when `virtualScroller.setItems()`\r\n\t\t// is called, some items might get prepended, in which case\r\n\t\t// `this.lastMeasuredItemIndex` is updated. If there was no\r\n\t\t// `this.firstMeasuredItemIndex`, then the average item height\r\n\t\t// calculated in `.getAverage()` would be incorrect in the timeframe\r\n\t\t// between `.setItems()` is called and those changes have been rendered.\r\n\t\t// And in that timeframe, `.getAverage()` is used to calculate the \"layout\":\r\n\t\t// stuff like \"before/after items height\" and \"estimated items count on screen\".\r\n\t\tthis.firstMeasuredItemIndex = undefined\r\n\t\tthis.lastMeasuredItemIndex = undefined\r\n\t}\r\n\r\n\t/**\r\n\t * Can only be called after a `.reset()` (including new instance creation).\r\n\t * Initializes `this.measuredItemsHeight`, `this.firstMeasuredItemIndex`\r\n\t * and `this.lastMeasuredItemIndex` instance variables from `VirtualScroller` `state`.\r\n\t * These instance variables are used when calculating \"average\" item height:\r\n\t * the \"average\" item height is simply `this.measuredItemsHeight` divided by\r\n\t * `this.lastMeasuredItemIndex` minus `this.firstMeasuredItemIndex` plus 1.\r\n\t */\r\n\treadItemHeightsFromState({ itemHeights }) {\r\n\t\tlet i = 0\r\n\t\twhile (i < itemHeights.length) {\r\n\t\t\tif (itemHeights[i] === undefined) {\r\n\t\t\t\tif (this.firstMeasuredItemIndex !== undefined) {\r\n\t\t\t\t\tthis.lastMeasuredItemIndex = i - 1\r\n\t\t\t\t\tbreak\r\n\t\t\t\t}\r\n\t\t\t} else {\r\n\t\t\t\tif (this.firstMeasuredItemIndex === undefined) {\r\n\t\t\t\t\tthis.firstMeasuredItemIndex = i\r\n\t\t\t\t}\r\n\t\t\t\tthis.measuredItemsHeight += itemHeights[i]\r\n\t\t\t}\r\n\t\t\ti++\r\n\t\t}\r\n\t}\r\n\r\n\t// Seems to be no longer used.\r\n\t// getItemHeight(i, firstShownItemIndex) {\r\n\t// \tif (this._get(i)) {\r\n\t// \t\treturn this._get(i)\r\n\t// \t}\r\n\t// \tconst itemHeight = this._measureItemHeight(i, firstShownItemIndex)\r\n\t// \tif (itemHeight) {\r\n\t// \t\tthis._set(i, itemHeight)\r\n\t// \t\treturn itemHeight\r\n\t// \t}\r\n\t// \treturn this.getAverage()\r\n\t// }\r\n\r\n\t_measureItemHeight(i, firstShownItemIndex) {\r\n\t\treturn this.container.getNthRenderedItemHeight(i - firstShownItemIndex)\r\n\t}\r\n\r\n\t/**\r\n\t * Measures item heights:\r\n\t *\r\n\t * * For the items that haven't been previously measured,\r\n\t * measures them for the first time.\r\n\t *\r\n\t * * For the items that have been previoulsy measured,\r\n\t * validate that their previously measured height\r\n\t * is still equal to their current height.\r\n\t * The unequalness may not necessarily be caused by\r\n\t * incorrect use of `virtual-scroller`: there are\r\n\t * also some valid use cases when such unequalness\r\n\t * could happen (see the comments in the code).\r\n\t *\r\n\t * @param {number} firstShownItemIndex\r\n\t * @param {number} lastShownItemIndex\r\n\t * @return {number[]} The indexes of the items that have not previously been measured and have been measured now.\r\n\t */\r\n\tmeasureItemHeights(firstShownItemIndex, lastShownItemIndex) {\r\n\t\tlog('~ Measure item heights ~')\r\n\t\t// If no items are rendered, don't measure anything.\r\n\t\tif (firstShownItemIndex === undefined) {\r\n\t\t\treturn\r\n\t\t}\r\n\t\t// Reset `this.measuredItemsHeight` if it's not a \"continuous\" measured items list:\r\n\t\t// if a group of items has been measured previously, and now it has rendered a completely\r\n\t\t// different group of items, and there's a non-measured \"gap\" between those two groups,\r\n\t\t// then reset `this.measuredItemsHeight` and \"first measured\"/\"last measured\" item indexes.\r\n\t\t// For example, this could happen when `.setItems()` prepends a lot of new items.\r\n\t\tif (this.firstMeasuredItemIndex !== undefined) {\r\n\t\t\tif (\r\n\t\t\t\tfirstShownItemIndex > this.lastMeasuredItemIndex + 1 ||\r\n\t\t\t\tlastShownItemIndex < this.firstMeasuredItemIndex - 1\r\n\t\t\t) {\r\n\t\t\t\t// Reset.\r\n\t\t\t\tlog('Non-measured items gap detected. Reset first and last measured item indexes.')\r\n\t\t\t\tthis.reset()\r\n\t\t\t}\r\n\t\t}\r\n\t\tconst nonPreviouslyMeasuredItemIndexes = []\r\n\t\tconst previousFirstMeasuredItemIndex = this.firstMeasuredItemIndex\r\n\t\tconst previousLastMeasuredItemIndex = this.lastMeasuredItemIndex\r\n\t\tlet firstMeasuredItemIndexHasBeenUpdated = false\r\n\t\tlet i = firstShownItemIndex\r\n\t\twhile (i <= lastShownItemIndex) {\r\n\t\t\t// Measure item heights that haven't been measured previously.\r\n\t\t\t// Don't re-measure item heights that have been measured previously.\r\n\t\t\t// The rationale is that developers are supposed to manually call\r\n\t\t\t// `.onItemHeightChange()` every time an item's height changes.\r\n\t\t\t// If developers don't neglect that rule, item heights won't\r\n\t\t\t// change unexpectedly.\r\n\t\t\tif (this._get(i) === undefined) {\r\n\t\t\t\tnonPreviouslyMeasuredItemIndexes.push(i)\r\n\t\t\t\tconst height = this._measureItemHeight(i, firstShownItemIndex)\r\n\t\t\t\tlog('Item index', i, 'height', height)\r\n\t\t\t\tthis._set(i, height)\r\n\t\t\t\t// Update average item height calculation variables\r\n\t\t\t\t// related to the previously measured items\r\n\t\t\t\t// that're above the items currently being shown.\r\n\t\t\t\t// It is known to be a \"continuous\" measured items list,\r\n\t\t\t\t// because the code at the start of this function checks that.\r\n\t\t\t\tif (previousFirstMeasuredItemIndex === undefined || i < previousFirstMeasuredItemIndex) {\r\n\t\t\t\t\tthis.measuredItemsHeight += height\r\n\t\t\t\t\t// Update first measured item index.\r\n\t\t\t\t\tif (!firstMeasuredItemIndexHasBeenUpdated) {\r\n\t\t\t\t\t\t// log('Set first measured item index', i)\r\n\t\t\t\t\t\tthis.firstMeasuredItemIndex = i\r\n\t\t\t\t\t\tfirstMeasuredItemIndexHasBeenUpdated = true\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t\t// Update average item height calculation variables\r\n\t\t\t\t// related to the previously measured items\r\n\t\t\t\t// that're below the items currently being shown.\r\n\t\t\t\t// It is known to be a \"continuous\" measured items list,\r\n\t\t\t\t// because the code at the start of this function checks that.\r\n\t\t\t\tif (previousLastMeasuredItemIndex === undefined || i > previousLastMeasuredItemIndex) {\r\n\t\t\t\t\t// If `previousLastMeasuredItemIndex` is `undefined`\r\n\t\t\t\t\t// then `previousFirstMeasuredItemIndex` is also `undefined`\r\n\t\t\t\t\t// which means that the item's `height` has already been added\r\n\t\t\t\t\t// to `this.measuredItemsHeight` in the code above,\r\n\t\t\t\t\t// so this condition guards against counting the item's `height`\r\n\t\t\t\t\t// twice in `this.measuredItemsHeight`.\r\n\t\t\t\t\tif (previousLastMeasuredItemIndex !== undefined) {\r\n\t\t\t\t\t\t// Add newly shown item height.\r\n\t\t\t\t\t\tthis.measuredItemsHeight += height\r\n\t\t\t\t\t}\r\n\t\t\t\t\t// Update last measured item index.\r\n\t\t\t\t\tthis.lastMeasuredItemIndex = i\r\n\t\t\t\t}\r\n\t\t\t} else {\r\n\t\t\t\t// Validate that the item's height didn't change since it was last measured.\r\n\t\t\t\t// If it did, then display a warning and update the item's height\r\n\t\t\t\t// as an attempt to fix things.\r\n\t\t\t\t// If an item's height changes unexpectedly then it means that there'll\r\n\t\t\t\t// likely be \"content jumping\".\r\n\t\t\t\tconst previousHeight = this._get(i)\r\n\t\t\t\tconst height = this._measureItemHeight(i, firstShownItemIndex)\r\n\t\t\t\tif (previousHeight !== height) {\r\n\t\t\t\t\twarn('Item index', i, 'height changed unexpectedly: it was', previousHeight, 'before, but now it is', height, '. An item\\'s height is allowed to change only in two cases: when the item\\'s \"state\" changes and the developer calls `setItemState(i, newState)`, or when the item\\'s height changes for any reason and the developer calls `onItemHeightChange(i)`. Perhaps you forgot to persist the item\\'s \"state\" by calling `setItemState(i, newState)` when it changed, and that \"state\" got lost when the item element was unmounted, which resulted in a different height when the item was shown again having its \"state\" reset.')\r\n\t\t\t\t\t// Update the item's height as an attempt to fix things.\r\n\t\t\t\t\tthis._set(i, height)\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\ti++\r\n\t\t}\r\n\t\t// // Update average item height.\r\n\t\t// this.updateAverageItemHeight()\r\n\t\treturn nonPreviouslyMeasuredItemIndexes\r\n\t}\r\n\r\n\t/**\r\n\t * Re-measures item height.\r\n\t * @param {number} i — Item index.\r\n\t * @param {number} firstShownItemIndex\r\n\t */\r\n\tremeasureItemHeight(i, firstShownItemIndex) {\r\n\t\tconst previousHeight = this._get(i)\r\n\t\tconst height = this._measureItemHeight(i, firstShownItemIndex)\r\n\t\t// // Because this function is called from `.onItemHeightChange()`,\r\n\t\t// // there're no guarantees in which circumstances a developer calls it,\r\n\t\t// // and for which item indexes.\r\n\t\t// // Therefore, to guard against cases of incorrect usage,\r\n\t\t// // this function won't crash anything if the item isn't rendered\r\n\t\t// // or hasn't been previously rendered.\r\n\t\t// if (height !== undefined) {\r\n\t\t// \treportError(`\"onItemHeightChange()\" has been called for item ${i}, but that item isn't rendered.`)\r\n\t\t// \treturn\r\n\t\t// }\r\n\t\t// if (previousHeight === undefined) {\r\n\t\t// \treportError(`\"onItemHeightChange()\" has been called for item ${i}, but that item hasn't been rendered before.`)\r\n\t\t// \treturn\r\n\t\t// }\r\n\t\tthis._set(i, height)\r\n\t\tthis.measuredItemsHeight += height - previousHeight\r\n\t\treturn height\r\n\t}\r\n\r\n\t// /**\r\n\t// * \"Average\" item height is stored as an instance variable.\r\n\t// * For example, for caching, so that it isn't calculated every time it's requested.\r\n\t// * But that would be negligible performance gain, not really worth the extra code.\r\n\t// * Another thing it's stored for as an instance variable is\r\n\t// * keeping \"previous\" \"average\" item height, because it can be more precise\r\n\t// * than the newly calculated \"average\" item height, provided it had\r\n\t// * more \"samples\" (measured items). The newly calculated average item height\r\n\t// * could get less samples in a scenario when the scroll somehow jumps\r\n\t// * from one position to some other distant position: in that case previous\r\n\t// * \"total measured items height\" is discarded and the new one is initialized.\r\n\t// * Could such situation happen in real life? I guess, it's unlikely.\r\n\t// * So I'm commenting out this code, but still keeping it just in case.\r\n\t// */\r\n\t// updateAverageItemHeight() {\r\n\t// \tthis.averageItemHeightSamplesCount = this.lastMeasuredItemIndex - this.firstMeasuredItemIndex + 1\r\n\t// \tthis.averageItemHeight = this.measuredItemsHeight / this.averageItemHeightSamplesCount\r\n\t// }\r\n\t//\r\n\t// /**\r\n\t// * Public API: is called by `VirtualScroller`.\r\n\t// * @return {number}\r\n\t// */\r\n\t// getAverage() {\r\n\t// \t// Previously measured average item height might still be\r\n\t// \t// more precise if it contains more measured items (\"samples\").\r\n\t// \tif (this.previousAverageItemHeight) {\r\n\t// \t\tif (this.previousAverageItemHeightSamplesCount > this.averageItemHeightSamplesCount) {\r\n\t// \t\t\treturn this.previousAverageItemHeight\r\n\t// \t\t}\r\n\t// \t}\r\n\t// \treturn this.averageItemHeight || 0\r\n\t// }\r\n\r\n\t/**\r\n\t * Public API: is called by `VirtualScroller`.\r\n\t * @return {number}\r\n\t */\r\n\tgetAverage() {\r\n\t\tif (this.lastMeasuredItemIndex === undefined) {\r\n\t\t\treturn 0\r\n\t\t}\r\n\t\treturn this.measuredItemsHeight / (this.lastMeasuredItemIndex - this.firstMeasuredItemIndex + 1)\r\n\t}\r\n\r\n\tonPrepend(count) {\r\n\t\tif (this.firstMeasuredItemIndex !== undefined) {\r\n\t\t\tthis.firstMeasuredItemIndex += count\r\n\t\t\tthis.lastMeasuredItem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Ab;;MACA,KAAKf,mBAAL,IAA4Be,MAAM,GAAGE,cAArC;MACA,OAAOF,MAAP;IACA,C,CAED;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;;IAEA;AACD;AACA;AACA;;;;WACC,sBAAa;MACZ,IAAI,KAAKZ,qBAAL,KAA+BD,SAAnC,EAA8C;QAC7C,OAAO,CAAP;MACA;;MACD,OAAO,KAAKF,mBAAL,IAA4B,KAAKG,qBAAL,GAA6B,KAAKF,sBAAlC,GAA2D,CAAvF,CAAP;IACA;;;WAED,mBAAUkB,KAAV,EAAiB;MAChB,IAAI,KAAKlB,sBAAL,KAAgCC,SAApC,EAA+C;QAC9C,KAAKD,sBAAL,IAA+BkB,KAA/B;QACA,KAAKhB,qBAAL,IAA8BgB,KAA9B;MACA;IACD"}
|
|
@@ -396,7 +396,7 @@ function _default() {
|
|
|
396
396
|
|
|
397
397
|
this._onItemHeightChange = function (i) {
|
|
398
398
|
(0, _debug["default"])('~ Re-measure item height ~');
|
|
399
|
-
(0, _debug["default"])('Item', i);
|
|
399
|
+
(0, _debug["default"])('Item index', i);
|
|
400
400
|
|
|
401
401
|
var _this$getState2 = _this.getState(),
|
|
402
402
|
itemHeights = _this$getState2.itemHeights,
|
|
@@ -430,7 +430,7 @@ function _default() {
|
|
|
430
430
|
// So, even though the developer has written their code properly, there're
|
|
431
431
|
// still situations when the item could be no longer rendered by the time
|
|
432
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
|
|
433
|
+
return (0, _debug.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.');
|
|
434
434
|
}
|
|
435
435
|
|
|
436
436
|
var previousHeight = itemHeights[i];
|
|
@@ -1 +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 `.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', 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;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,IAAI,EAAX;IACA,CAzB2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B/D,SAAnB;;MACA,KAAI,CAAC1B,wBAAL,CAA8B;QAC7BC,MAAM,EAANA,MAD6B;QAE7BC,WAAW,EAAXA;MAF6B,CAA9B;IAIA,CAPkB,EAOhB,CAPgB,CAAnB;EAQA,CAVD;AAWA;;AAED,IAAMiC,oBAAoB,GAAG,EAA7B,C,CAAgC"}
|
|
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 `.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.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;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;;;IACA,IAAI,KAAI,CAACG,sBAAL,IAA+B,KA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SAAlBA,WAAkB;IACvD,KAAI,CAACyF,sBAAL,GAA8BzF,WAA9B;IACA,KAAI,CAACuF,WAAL,GAAmB,IAAAI,wCAAA,EAAW,YAAM;MACnC,KAAI,CAACF,sBAAL,GAA8BjE,SAA9B;MACA,KAAI,CAAC+D,WAAL,GAAmB/D,SAAnB;;MACA,KAAI,CAAC1B,wBAAL,CAA8B;QAC7BC,MAAM,EAANA,MAD6B;QAE7BC,WAAW,EAAXA;MAF6B,CAA9B;IAIA,CAPkB,EAOhB,CAPgB,CAAnB;EAQA,CAVD;AAWA;;AAED,IAAMiC,oBAAoB,GAAG,EAA7B,C,CAAgC"}
|
|
@@ -63,7 +63,7 @@ function createStateHelpers(_ref) {
|
|
|
63
63
|
this._setItemState = function (i, newItemState) {
|
|
64
64
|
if ((0, _debug.isDebug)()) {
|
|
65
65
|
(0, _debug["default"])('~ Item state changed ~');
|
|
66
|
-
(0, _debug["default"])('Item', i); // Uses `JSON.stringify()` here instead of just outputting the JSON objects as is
|
|
66
|
+
(0, _debug["default"])('Item index', i); // Uses `JSON.stringify()` here instead of just outputting the JSON objects as is
|
|
67
67
|
// because outputting JSON objects as is would show different results later when
|
|
68
68
|
// the developer inspects those in the web browser console if those state objects
|
|
69
69
|
// get modified in between they've been output to the console and the developer
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"VirtualScroller.state.js","names":["createStateHelpers","initialState","state","getInitialItemState","onStateChange","render","initialItems","items","_render","_setItemState","i","newItemState","isDebug","log","JSON","stringify","getState","itemStates","newItemsWillBeRendered","itemStatesThatChangedWhileNewItemsWereBeingRendered","String","_getState","updateState","stateUpdate","getStateSnapshot","_isSettingNewItems","reportError","undefined","previousState","_updateState","getInitialState","getRestoredState","call","getInitialStateFromScratch","useState","_isActive","Error","_usesCustomStateStorage","useDefaultStateStorage","defaultGetState","bind","defaultUpdateState","setInitialState","defaultSetInitialState","newState","onRender","getInitialLayoutState","beforeStart","fillArray","Array","length","firstShownItemIndex","lastShownItemIndex","cleanUpBeforeResizeState","verticalSpacing","isStateColumnsCountMismatch","columnsCount","getActualColumnsCount","warn","itemsCount","getColumnsCount","layout","getInitialLayoutValueWithFallback","getInitialLayoutValues","beforeItemsHeight","afterItemsHeight","itemHeights","onBeforeShowItems","getActualColumnsCountForState","stateColumnsCount","Math","floor"],"sources":["../source/VirtualScroller.state.js"],"sourcesContent":["import fillArray from './utility/fillArray.js'\r\nimport log, { warn, isDebug, reportError } from './utility/debug.js'\r\nimport { cleanUpBeforeResizeState } from './BeforeResize.js'\r\nimport getStateSnapshot from './utility/getStateSnapshot.js'\r\n\r\n// There're three main places where state is updated:\r\n//\r\n// * On scroll.\r\n// * On window resize.\r\n// * On set new items.\r\n//\r\n// State updates may be \"asynchronous\" (like in React), in which case the\r\n// corresponding operation is \"pending\" until the state update is applied.\r\n//\r\n// If there's a \"pending\" window resize or a \"pending\" update of the set of items,\r\n// then \"on scroll\" updates aren't dispatched.\r\n//\r\n// If there's a \"pending\" on scroll update and the window is resize or a new set\r\n// of items is set, then that \"pending\" on scroll update gets overwritten.\r\n//\r\n// If there's a \"pending\" update of the set of items, then window resize handler\r\n// sees that \"pending\" update and dispatches its own state update so that the\r\n// \"pending\" state update originating from `setItems()` is not lost.\r\n//\r\n// If there's a \"pending\" window resize, and a new set of items is set,\r\n// then the state update of the window resize handler gets overwritten.\r\n\r\nexport default function createStateHelpers({\r\n\tstate: initialState,\r\n\tgetInitialItemState,\r\n\tonStateChange,\r\n\trender,\r\n\titems: initialItems\r\n}) {\r\n\tthis.onStateChange = onStateChange\r\n\tthis._render = render\r\n\r\n\tthis.getInitialItemState = getInitialItemState\r\n\r\n\tthis._setItemState = (i, newItemState) => {\r\n\t\tif (isDebug()) {\r\n\t\t\tlog('~ Item state changed ~')\r\n\t\t\tlog('Item', i)\r\n\t\t\t// Uses `JSON.stringify()` here instead of just outputting the JSON objects as is\r\n\t\t\t// because outputting JSON objects as is would show different results later when\r\n\t\t\t// the developer inspects those in the web browser console if those state objects\r\n\t\t\t// get modified in between they've been output to the console and the developer\r\n\t\t\t// decided to inspect them.\r\n\t\t\tlog('Previous state' + '\\n' + JSON.stringify(this.getState().itemStates[i], null, 2))\r\n\t\t\tlog('New state' + '\\n' + JSON.stringify(newItemState, null, 2))\r\n\t\t}\r\n\r\n\t\tthis.getState().itemStates[i] = newItemState\r\n\r\n\t\t// Schedule the item state update for after the new items have been rendered.\r\n\t\tif (this.newItemsWillBeRendered) {\r\n\t\t\tif (!this.itemStatesThatChangedWhileNewItemsWereBeingRendered) {\r\n\t\t\t\tthis.itemStatesThatChangedWhileNewItemsWereBeingRendered = {}\r\n\t\t\t}\r\n\t\t\tthis.itemStatesThatChangedWhileNewItemsWereBeingRendered[String(i)] = newItemState\r\n\t\t}\r\n\t}\r\n\r\n\tthis.getState = () => this._getState()\r\n\r\n\tthis.updateState = (stateUpdate) => {\r\n\t\tif (isDebug()) {\r\n\t\t\tlog('~ Set state ~')\r\n\t\t\tlog(getStateSnapshot(stateUpdate))\r\n\t\t}\r\n\r\n\t\t// Ensure that a non-initial `stateUpdate` can only contain an `items`\r\n\t\t// property when it comes from a `setItems()` call.\r\n\t\tif (stateUpdate.items) {\r\n\t\t\tif (!this._isSettingNewItems) {\r\n\t\t\t\treportError('A `stateUpdate` can only contain `items` property as a result of calling `.setItems()`')\r\n\t\t\t}\r\n\t\t}\r\n\t\tthis._isSettingNewItems = undefined\r\n\r\n\t\t// Update `state`.\r\n\t\tthis.previousState = this.getState()\r\n\t\tthis._updateState(stateUpdate)\r\n\t}\r\n\r\n\tthis.getInitialState = () => {\r\n\t\tif (initialState) {\r\n\t\t\treturn getRestoredState.call(this, initialState)\r\n\t\t}\r\n\t\treturn getInitialStateFromScratch.call(this, { getInitialItemState })\r\n\t}\r\n\r\n\tthis.useState = ({\r\n\t\tgetState,\r\n\t\tupdateState\r\n\t}) => {\r\n\t\tif (this._isActive) {\r\n\t\t\tthrow new Error('[virtual-scroller] `VirtualScroller` has already been started')\r\n\t\t}\r\n\r\n\t\tif (this._getState) {\r\n\t\t\tthrow new Error('[virtual-scroller] Custom state storage has already been configured')\r\n\t\t}\r\n\r\n\t\tif (render) {\r\n\t\t\tthrow new Error('[virtual-scroller] Creating a `VirtualScroller` class instance with a `render()` parameter means using the default (internal) state storage')\r\n\t\t}\r\n\r\n\t\tif (!getState || !updateState) {\r\n\t\t\tthrow new Error('[virtual-scroller] When using a custom state storage, one must supply both `getState()` and `updateState()` functions')\r\n\t\t}\r\n\r\n\t\tthis._usesCustomStateStorage = true\r\n\r\n\t\tthis._getState = getState\r\n\t\tthis._updateState = updateState\r\n\t}\r\n\r\n\tthis.useDefaultStateStorage = () => {\r\n\t\tif (!render) {\r\n\t\t\tthrow new Error('[virtual-scroller] When using the default (internal) state management, one must supply a `render(state, prevState)` function parameter')\r\n\t\t}\r\n\r\n\t\t// Create default `getState()`/`updateState()` functions.\r\n\t\tthis._getState = defaultGetState.bind(this)\r\n\t\tthis._updateState = defaultUpdateState.bind(this)\r\n\r\n\t\t// When `state` is stored externally, a developer is responsible for\r\n\t\t// initializing it with the initial value.\r\n\t\t// Otherwise, if default state management is used, set the initial state now.\r\n\t\tconst setInitialState = defaultSetInitialState.bind(this)\r\n\t\tsetInitialState(this.getInitialState())\r\n\t}\r\n\r\n\tfunction defaultGetState() {\r\n\t\treturn this.state\r\n\t}\r\n\r\n\tfunction defaultSetInitialState(newState) {\r\n\t\tthis.state = newState\r\n\t}\r\n\r\n\tfunction defaultUpdateState(stateUpdate) {\r\n\t\t// Because this variant of `.updateState()` is \"synchronous\" (immediate),\r\n\t\t// it can be written like `...prevState`, and no state updates would be lost.\r\n\t\t// But if it was \"asynchronous\" (not immediate), then `...prevState`\r\n\t\t// wouldn't work in all cases, because it could be stale in cases\r\n\t\t// when more than a single `updateState()` call is made before\r\n\t\t// the state actually updates, making `prevState` stale.\r\n\t\tthis.state = {\r\n\t\t\t...this.state,\r\n\t\t\t...stateUpdate\r\n\t\t}\r\n\r\n\t\trender(this.state, this.previousState)\r\n\r\n\t\tthis.onRender()\r\n\t}\r\n\r\n\t/**\r\n\t * Returns the initial state of the `VirtualScroller` \"from scratch\".\r\n\t * (i.e. not from a previously saved one).\r\n\t * @param {function} [options.getInitialItemState] — Gets initial item state.\r\n\t * @return {object}\r\n\t */\r\n\tfunction getInitialStateFromScratch({ getInitialItemState }) {\r\n\t\tconst items = initialItems\r\n\r\n\t\tconst state = {\r\n\t\t\t...getInitialLayoutState.call(this, items, { beforeStart: true }),\r\n\t\t\titems,\r\n\t\t\titemStates: fillArray(new Array(items.length), (i) => getInitialItemState(items[i]))\r\n\t\t}\r\n\r\n\t\tif (isDebug()) {\r\n\t\t\tlog('Initial state (autogenerated)', getStateSnapshot(state))\r\n\t\t}\r\n\t\tlog('First shown item index', state.firstShownItemIndex)\r\n\t\tlog('Last shown item index', state.lastShownItemIndex)\r\n\r\n\t\treturn state\r\n\t}\r\n\r\n\tfunction getRestoredState(state) {\r\n\t\tif (isDebug()) {\r\n\t\t\tlog('Restore state', getStateSnapshot(state))\r\n\t\t}\r\n\r\n\t\t// Possibly clean up \"before resize\" property in state.\r\n\t\t// \"Before resize\" state property is cleaned up when all \"before resize\" item heights\r\n\t\t// have been re-measured in an asynchronous `this.updateState({ beforeResize: undefined })` call.\r\n\t\t// If `VirtualScroller` state was snapshotted externally before that `this.updateState()` call\r\n\t\t// has been applied, then \"before resize\" property might have not been cleaned up properly.\r\n\t\tstate = cleanUpBeforeResizeState(state)\r\n\r\n\t\t// Reset `verticalSpacing` so that it re-measures it after the list\r\n\t\t// has been rendered initially. The rationale is that a previously captured\r\n\t\t// inter-item vertical spacing can't be \"trusted\" in a sense that the user\r\n\t\t// might have resized the window after the previous `state` has been snapshotted.\r\n\t\t// If the user has resized the window, then changing window width might have\r\n\t\t// activated different CSS `@media()` \"queries\" resulting in a potentially different\r\n\t\t// vertical spacing when the `VirtualScroller` is re-created with such previously\r\n\t\t// snapshotted state.\r\n\t\tstate = {\r\n\t\t\t...state,\r\n\t\t\tverticalSpacing: undefined\r\n\t\t}\r\n\r\n\t\t// `this.verticalSpacing` acts as a \"true\" source for vertical spacing value.\r\n\t\t// Vertical spacing is also stored in `state` but `state` updates could be\r\n\t\t// \"asynchronous\" (not applied immediately) and `this.onUpdateShownItemIndexes()`\r\n\t\t// requires vertical spacing to be correct at any time, without any delays.\r\n\t\t// So, vertical spacing is also duplicated in `state`, but the \"true\" source\r\n\t\t// is still `this.verticalSpacing`.\r\n\t\t//\r\n\t\t// `this.verticalSpacing` must be initialized before calling `this.getInitialStateFromScratch()`\r\n\t\t// because `this.getInitialStateFromScratch()` uses `this.verticalSpacing` in its calculations.\r\n\t\t//\r\n\t\t// With the code above, `state.verticalSpacing` is always gonna be `undefined`,\r\n\t\t// so commented out this code. It's safer to just re-measure vertical spacing\r\n\t\t// from scratch when `VirtualScroller` is mounted.\r\n\t\t//\r\n\t\t// this.verticalSpacing = state ? state.verticalSpacing : undefined\r\n\r\n\t\t// Check if the actual `columnsCount` on the screen matches the one from state.\r\n\t\tif (isStateColumnsCountMismatch(state, {\r\n\t\t\tcolumnsCount: this.getActualColumnsCount()\r\n\t\t})) {\r\n\t\t\twarn('Reset Layout')\r\n\t\t\tstate = {\r\n\t\t\t\t...state,\r\n\t\t\t\t...getInitialLayoutState.call(this, state.items, { beforeStart: false })\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\treturn state\r\n\t}\r\n\r\n\tfunction getInitialLayoutState(items, { beforeStart }) {\r\n\t\tconst itemsCount = items.length\r\n\r\n\t\tconst getColumnsCount = () => this.getActualColumnsCount()\r\n\r\n\t\tconst columnsCount = beforeStart\r\n\t\t\t? this.layout.getInitialLayoutValueWithFallback(\r\n\t\t\t\t'columnsCount',\r\n\t\t\t\tgetColumnsCount,\r\n\t\t\t\t1\r\n\t\t\t)\r\n\t\t\t: getColumnsCount()\r\n\r\n\t\tconst {\r\n\t\t\tfirstShownItemIndex,\r\n\t\t\tlastShownItemIndex,\r\n\t\t\tbeforeItemsHeight,\r\n\t\t\tafterItemsHeight\r\n\t\t} = this.layout.getInitialLayoutValues({\r\n\t\t\titemsCount,\r\n\t\t\tcolumnsCount: this.getActualColumnsCount(),\r\n\t\t\tbeforeStart\r\n\t\t})\r\n\r\n\t\tconst itemHeights = new Array(itemsCount)\r\n\r\n\t\t// Optionally preload items to be rendered.\r\n\t\tthis.onBeforeShowItems(\r\n\t\t\titems,\r\n\t\t\titemHeights,\r\n\t\t\tfirstShownItemIndex,\r\n\t\t\tlastShownItemIndex\r\n\t\t)\r\n\r\n\t\treturn {\r\n\t\t\titemHeights,\r\n\t\t\tcolumnsCount: this.getActualColumnsCountForState(),\r\n\t\t\tverticalSpacing: this.verticalSpacing,\r\n\t\t\tfirstShownItemIndex,\r\n\t\t\tlastShownItemIndex,\r\n\t\t\tbeforeItemsHeight,\r\n\t\t\tafterItemsHeight\r\n\t\t}\r\n\t}\r\n\r\n\t// Checks if the actual `columnsCount` on the screen matches the one from state.\r\n\t//\r\n\t// For example, a developer might snapshot `VirtualScroller` state\r\n\t// when the user navigates from the page containing the list\r\n\t// in order to later restore the list's state when the user goes \"Back\".\r\n\t// But, the user might have also resized the window while being on that\r\n\t// \"other\" page, and when they come \"Back\", their snapshotted state\r\n\t// no longer qualifies. Well, it does qualify, but only partially.\r\n\t// For example, `itemStates` are still valid, but first and last shown\r\n\t// item indexes aren't.\r\n\t//\r\n\tfunction isStateColumnsCountMismatch(state, { columnsCount }) {\r\n\t\tconst stateColumnsCount = state.columnsCount || 1\r\n\t\tif (stateColumnsCount !== columnsCount) {\r\n\t\t\twarn('~ Columns Count changed from', stateColumnsCount, 'to', columnsCount, '~')\r\n\t\t\treturn true\r\n\t\t}\r\n\t\tconst firstShownItemIndex = Math.floor(state.firstShownItemIndex / columnsCount) * columnsCount\r\n\t\tif (firstShownItemIndex !== state.firstShownItemIndex) {\r\n\t\t\twarn('~ First Shown Item Index', state.firstShownItemIndex, 'is not divisible by Columns Count', columnsCount, '~')\r\n\t\t\treturn true\r\n\t\t}\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A8D;IAAA,IAAhBsD,YAAgB,SAAhBA,YAAgB;IAC7D,IAAMa,iBAAiB,GAAGnE,KAAK,CAACsD,YAAN,IAAsB,CAAhD;;IACA,IAAIa,iBAAiB,KAAKb,YAA1B,EAAwC;MACvC,IAAAE,WAAA,EAAK,8BAAL,EAAqCW,iBAArC,EAAwD,IAAxD,EAA8Db,YAA9D,EAA4E,GAA5E;MACA,OAAO,IAAP;IACA;;IACD,IAAML,mBAAmB,GAAGmB,IAAI,CAACC,KAAL,CAAWrE,KAAK,CAACiD,mBAAN,GAA4BK,YAAvC,IAAuDA,YAAnF;;IACA,IAAIL,mBAAmB,KAAKjD,KAAK,CAACiD,mBAAlC,EAAuD;MACtD,IAAAO,WAAA,EAAK,0BAAL,EAAiCxD,KAAK,CAACiD,mBAAvC,EAA4D,mCAA5D,EAAiGK,YAAjG,EAA+G,GAA/G;MACA,OAAO,IAAP;IACA;EACD;AACD"}
|
|
1
|
+
{"version":3,"file":"VirtualScroller.state.js","names":["createStateHelpers","initialState","state","getInitialItemState","onStateChange","render","initialItems","items","_render","_setItemState","i","newItemState","isDebug","log","JSON","stringify","getState","itemStates","newItemsWillBeRendered","itemStatesThatChangedWhileNewItemsWereBeingRendered","String","_getState","updateState","stateUpdate","getStateSnapshot","_isSettingNewItems","reportError","undefined","previousState","_updateState","getInitialState","getRestoredState","call","getInitialStateFromScratch","useState","_isActive","Error","_usesCustomStateStorage","useDefaultStateStorage","defaultGetState","bind","defaultUpdateState","setInitialState","defaultSetInitialState","newState","onRender","getInitialLayoutState","beforeStart","fillArray","Array","length","firstShownItemIndex","lastShownItemIndex","cleanUpBeforeResizeState","verticalSpacing","isStateColumnsCountMismatch","columnsCount","getActualColumnsCount","warn","itemsCount","getColumnsCount","layout","getInitialLayoutValueWithFallback","getInitialLayoutValues","beforeItemsHeight","afterItemsHeight","itemHeights","onBeforeShowItems","getActualColumnsCountForState","stateColumnsCount","Math","floor"],"sources":["../source/VirtualScroller.state.js"],"sourcesContent":["import fillArray from './utility/fillArray.js'\r\nimport log, { warn, isDebug, reportError } from './utility/debug.js'\r\nimport { cleanUpBeforeResizeState } from './BeforeResize.js'\r\nimport getStateSnapshot from './utility/getStateSnapshot.js'\r\n\r\n// There're three main places where state is updated:\r\n//\r\n// * On scroll.\r\n// * On window resize.\r\n// * On set new items.\r\n//\r\n// State updates may be \"asynchronous\" (like in React), in which case the\r\n// corresponding operation is \"pending\" until the state update is applied.\r\n//\r\n// If there's a \"pending\" window resize or a \"pending\" update of the set of items,\r\n// then \"on scroll\" updates aren't dispatched.\r\n//\r\n// If there's a \"pending\" on scroll update and the window is resize or a new set\r\n// of items is set, then that \"pending\" on scroll update gets overwritten.\r\n//\r\n// If there's a \"pending\" update of the set of items, then window resize handler\r\n// sees that \"pending\" update and dispatches its own state update so that the\r\n// \"pending\" state update originating from `setItems()` is not lost.\r\n//\r\n// If there's a \"pending\" window resize, and a new set of items is set,\r\n// then the state update of the window resize handler gets overwritten.\r\n\r\nexport default function createStateHelpers({\r\n\tstate: initialState,\r\n\tgetInitialItemState,\r\n\tonStateChange,\r\n\trender,\r\n\titems: initialItems\r\n}) {\r\n\tthis.onStateChange = onStateChange\r\n\tthis._render = render\r\n\r\n\tthis.getInitialItemState = getInitialItemState\r\n\r\n\tthis._setItemState = (i, newItemState) => {\r\n\t\tif (isDebug()) {\r\n\t\t\tlog('~ Item state changed ~')\r\n\t\t\tlog('Item index', i)\r\n\t\t\t// Uses `JSON.stringify()` here instead of just outputting the JSON objects as is\r\n\t\t\t// because outputting JSON objects as is would show different results later when\r\n\t\t\t// the developer inspects those in the web browser console if those state objects\r\n\t\t\t// get modified in between they've been output to the console and the developer\r\n\t\t\t// decided to inspect them.\r\n\t\t\tlog('Previous state' + '\\n' + JSON.stringify(this.getState().itemStates[i], null, 2))\r\n\t\t\tlog('New state' + '\\n' + JSON.stringify(newItemState, null, 2))\r\n\t\t}\r\n\r\n\t\tthis.getState().itemStates[i] = newItemState\r\n\r\n\t\t// Schedule the item state update for after the new items have been rendered.\r\n\t\tif (this.newItemsWillBeRendered) {\r\n\t\t\tif (!this.itemStatesThatChangedWhileNewItemsWereBeingRendered) {\r\n\t\t\t\tthis.itemStatesThatChangedWhileNewItemsWereBeingRendered = {}\r\n\t\t\t}\r\n\t\t\tthis.itemStatesThatChangedWhileNewItemsWereBeingRendered[String(i)] = newItemState\r\n\t\t}\r\n\t}\r\n\r\n\tthis.getState = () => this._getState()\r\n\r\n\tthis.updateState = (stateUpdate) => {\r\n\t\tif (isDebug()) {\r\n\t\t\tlog('~ Set state ~')\r\n\t\t\tlog(getStateSnapshot(stateUpdate))\r\n\t\t}\r\n\r\n\t\t// Ensure that a non-initial `stateUpdate` can only contain an `items`\r\n\t\t// property when it comes from a `setItems()` call.\r\n\t\tif (stateUpdate.items) {\r\n\t\t\tif (!this._isSettingNewItems) {\r\n\t\t\t\treportError('A `stateUpdate` can only contain `items` property as a result of calling `.setItems()`')\r\n\t\t\t}\r\n\t\t}\r\n\t\tthis._isSettingNewItems = undefined\r\n\r\n\t\t// Update `state`.\r\n\t\tthis.previousState = this.getState()\r\n\t\tthis._updateState(stateUpdate)\r\n\t}\r\n\r\n\tthis.getInitialState = () => {\r\n\t\tif (initialState) {\r\n\t\t\treturn getRestoredState.call(this, initialState)\r\n\t\t}\r\n\t\treturn getInitialStateFromScratch.call(this, { getInitialItemState })\r\n\t}\r\n\r\n\tthis.useState = ({\r\n\t\tgetState,\r\n\t\tupdateState\r\n\t}) => {\r\n\t\tif (this._isActive) {\r\n\t\t\tthrow new Error('[virtual-scroller] `VirtualScroller` has already been started')\r\n\t\t}\r\n\r\n\t\tif (this._getState) {\r\n\t\t\tthrow new Error('[virtual-scroller] Custom state storage has already been configured')\r\n\t\t}\r\n\r\n\t\tif (render) {\r\n\t\t\tthrow new Error('[virtual-scroller] Creating a `VirtualScroller` class instance with a `render()` parameter means using the default (internal) state storage')\r\n\t\t}\r\n\r\n\t\tif (!getState || !updateState) {\r\n\t\t\tthrow new Error('[virtual-scroller] When using a custom state storage, one must supply both `getState()` and `updateState()` functions')\r\n\t\t}\r\n\r\n\t\tthis._usesCustomStateStorage = true\r\n\r\n\t\tthis._getState = getState\r\n\t\tthis._updateState = updateState\r\n\t}\r\n\r\n\tthis.useDefaultStateStorage = () => {\r\n\t\tif (!render) {\r\n\t\t\tthrow new Error('[virtual-scroller] When using the default (internal) state management, one must supply a `render(state, prevState)` function parameter')\r\n\t\t}\r\n\r\n\t\t// Create default `getState()`/`updateState()` functions.\r\n\t\tthis._getState = defaultGetState.bind(this)\r\n\t\tthis._updateState = defaultUpdateState.bind(this)\r\n\r\n\t\t// When `state` is stored externally, a developer is responsible for\r\n\t\t// initializing it with the initial value.\r\n\t\t// Otherwise, if default state management is used, set the initial state now.\r\n\t\tconst setInitialState = defaultSetInitialState.bind(this)\r\n\t\tsetInitialState(this.getInitialState())\r\n\t}\r\n\r\n\tfunction defaultGetState() {\r\n\t\treturn this.state\r\n\t}\r\n\r\n\tfunction defaultSetInitialState(newState) {\r\n\t\tthis.state = newState\r\n\t}\r\n\r\n\tfunction defaultUpdateState(stateUpdate) {\r\n\t\t// Because this variant of `.updateState()` is \"synchronous\" (immediate),\r\n\t\t// it can be written like `...prevState`, and no state updates would be lost.\r\n\t\t// But if it was \"asynchronous\" (not immediate), then `...prevState`\r\n\t\t// wouldn't work in all cases, because it could be stale in cases\r\n\t\t// when more than a single `updateState()` call is made before\r\n\t\t// the state actually updates, making `prevState` stale.\r\n\t\tthis.state = {\r\n\t\t\t...this.state,\r\n\t\t\t...stateUpdate\r\n\t\t}\r\n\r\n\t\trender(this.state, this.previousState)\r\n\r\n\t\tthis.onRender()\r\n\t}\r\n\r\n\t/**\r\n\t * Returns the initial state of the `VirtualScroller` \"from scratch\".\r\n\t * (i.e. not from a previously saved one).\r\n\t * @param {function} [options.getInitialItemState] — Gets initial item state.\r\n\t * @return {object}\r\n\t */\r\n\tfunction getInitialStateFromScratch({ getInitialItemState }) {\r\n\t\tconst items = initialItems\r\n\r\n\t\tconst state = {\r\n\t\t\t...getInitialLayoutState.call(this, items, { beforeStart: true }),\r\n\t\t\titems,\r\n\t\t\titemStates: fillArray(new Array(items.length), (i) => getInitialItemState(items[i]))\r\n\t\t}\r\n\r\n\t\tif (isDebug()) {\r\n\t\t\tlog('Initial state (autogenerated)', getStateSnapshot(state))\r\n\t\t}\r\n\t\tlog('First shown item index', state.firstShownItemIndex)\r\n\t\tlog('Last shown item index', state.lastShownItemIndex)\r\n\r\n\t\treturn state\r\n\t}\r\n\r\n\tfunction getRestoredState(state) {\r\n\t\tif (isDebug()) {\r\n\t\t\tlog('Restore state', getStateSnapshot(state))\r\n\t\t}\r\n\r\n\t\t// Possibly clean up \"before resize\" property in state.\r\n\t\t// \"Before resize\" state property is cleaned up when all \"before resize\" item heights\r\n\t\t// have been re-measured in an asynchronous `this.updateState({ beforeResize: undefined })` call.\r\n\t\t// If `VirtualScroller` state was snapshotted externally before that `this.updateState()` call\r\n\t\t// has been applied, then \"before resize\" property might have not been cleaned up properly.\r\n\t\tstate = cleanUpBeforeResizeState(state)\r\n\r\n\t\t// Reset `verticalSpacing` so that it re-measures it after the list\r\n\t\t// has been rendered initially. The rationale is that a previously captured\r\n\t\t// inter-item vertical spacing can't be \"trusted\" in a sense that the user\r\n\t\t// might have resized the window after the previous `state` has been snapshotted.\r\n\t\t// If the user has resized the window, then changing window width might have\r\n\t\t// activated different CSS `@media()` \"queries\" resulting in a potentially different\r\n\t\t// vertical spacing when the `VirtualScroller` is re-created with such previously\r\n\t\t// snapshotted state.\r\n\t\tstate = {\r\n\t\t\t...state,\r\n\t\t\tverticalSpacing: undefined\r\n\t\t}\r\n\r\n\t\t// `this.verticalSpacing` acts as a \"true\" source for vertical spacing value.\r\n\t\t// Vertical spacing is also stored in `state` but `state` updates could be\r\n\t\t// \"asynchronous\" (not applied immediately) and `this.onUpdateShownItemIndexes()`\r\n\t\t// requires vertical spacing to be correct at any time, without any delays.\r\n\t\t// So, vertical spacing is also duplicated in `state`, but the \"true\" source\r\n\t\t// is still `this.verticalSpacing`.\r\n\t\t//\r\n\t\t// `this.verticalSpacing` must be initialized before calling `this.getInitialStateFromScratch()`\r\n\t\t// because `this.getInitialStateFromScratch()` uses `this.verticalSpacing` in its calculations.\r\n\t\t//\r\n\t\t// With the code above, `state.verticalSpacing` is always gonna be `undefined`,\r\n\t\t// so commented out this code. It's safer to just re-measure vertical spacing\r\n\t\t// from scratch when `VirtualScroller` is mounted.\r\n\t\t//\r\n\t\t// this.verticalSpacing = state ? state.verticalSpacing : undefined\r\n\r\n\t\t// Check if the actual `columnsCount` on the screen matches the one from state.\r\n\t\tif (isStateColumnsCountMismatch(state, {\r\n\t\t\tcolumnsCount: this.getActualColumnsCount()\r\n\t\t})) {\r\n\t\t\twarn('Reset Layout')\r\n\t\t\tstate = {\r\n\t\t\t\t...state,\r\n\t\t\t\t...getInitialLayoutState.call(this, state.items, { beforeStart: false })\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\treturn state\r\n\t}\r\n\r\n\tfunction getInitialLayoutState(items, { beforeStart }) {\r\n\t\tconst itemsCount = items.length\r\n\r\n\t\tconst getColumnsCount = () => this.getActualColumnsCount()\r\n\r\n\t\tconst columnsCount = beforeStart\r\n\t\t\t? this.layout.getInitialLayoutValueWithFallback(\r\n\t\t\t\t'columnsCount',\r\n\t\t\t\tgetColumnsCount,\r\n\t\t\t\t1\r\n\t\t\t)\r\n\t\t\t: getColumnsCount()\r\n\r\n\t\tconst {\r\n\t\t\tfirstShownItemIndex,\r\n\t\t\tlastShownItemIndex,\r\n\t\t\tbeforeItemsHeight,\r\n\t\t\tafterItemsHeight\r\n\t\t} = this.layout.getInitialLayoutValues({\r\n\t\t\titemsCount,\r\n\t\t\tcolumnsCount: this.getActualColumnsCount(),\r\n\t\t\tbeforeStart\r\n\t\t})\r\n\r\n\t\tconst itemHeights = new Array(itemsCount)\r\n\r\n\t\t// Optionally preload items to be rendered.\r\n\t\tthis.onBeforeShowItems(\r\n\t\t\titems,\r\n\t\t\titemHeights,\r\n\t\t\tfirstShownItemIndex,\r\n\t\t\tlastShownItemIndex\r\n\t\t)\r\n\r\n\t\treturn {\r\n\t\t\titemHeights,\r\n\t\t\tcolumnsCount: this.getActualColumnsCountForState(),\r\n\t\t\tverticalSpacing: this.verticalSpacing,\r\n\t\t\tfirstShownItemIndex,\r\n\t\t\tlastShownItemIndex,\r\n\t\t\tbeforeItemsHeight,\r\n\t\t\tafterItemsHeight\r\n\t\t}\r\n\t}\r\n\r\n\t// Checks if the actual `columnsCount` on the screen matches the one from state.\r\n\t//\r\n\t// For example, a developer might snapshot `VirtualScroller` state\r\n\t// when the user navigates from the page containing the list\r\n\t// in order to later restore the list's state when the user goes \"Back\".\r\n\t// But, the user might have also resized the window while being on that\r\n\t// \"other\" page, and when they come \"Back\", their snapshotted state\r\n\t// no longer qualifies. Well, it does qualify, but only partially.\r\n\t// For example, `itemStates` are still valid, but first and last shown\r\n\t// item indexes aren't.\r\n\t//\r\n\tfunction isStateColumnsCountMismatch(state, { columnsCount }) {\r\n\t\tconst stateColumnsCount = state.columnsCount || 1\r\n\t\tif (stateColumnsCount !== columnsCount) {\r\n\t\t\twarn('~ Columns Count changed from', stateColumnsCount, 'to', columnsCount, '~')\r\n\t\t\treturn true\r\n\t\t}\r\n\t\tconst firstShownItemIndex = Math.floor(state.firstShownItemIndex / columnsCount) * columnsCount\r\n\t\tif (firstShownItemIndex !== state.firstShownItemIndex) {\r\n\t\t\twarn('~ First Shown Item Index', state.firstShownItemIndex, 'is not divisible by Columns Count', columnsCount, '~')\r\n\t\t\treturn true\r\n\t\t}\r\n\t}\r\n}"],"mappings":";;;;;;;;;AAAA;;AACA;;AACA;;AACA;;;;;;;;;;;;;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAEe,SAASA,kBAAT,OAMZ;EAAA;;EAAA,IALKC,YAKL,QALFC,KAKE;E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