virtual-scroller 1.8.0 → 1.9.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.gitlab-ci.yml +1 -1
- package/CHANGELOG.md +57 -0
- package/README.md +337 -160
- package/bundle/virtual-scroller-dom.js +1 -1
- package/bundle/virtual-scroller-dom.js.map +1 -1
- package/bundle/virtual-scroller-react.js +1 -1
- package/bundle/virtual-scroller-react.js.map +1 -1
- package/bundle/virtual-scroller.js +1 -1
- package/bundle/virtual-scroller.js.map +1 -1
- package/commonjs/BeforeResize.js +23 -27
- package/commonjs/BeforeResize.js.map +1 -1
- package/commonjs/DOM/Engine.js +7 -7
- package/commonjs/DOM/Engine.js.map +1 -1
- package/commonjs/DOM/ItemsContainer.js +1 -1
- package/commonjs/DOM/ItemsContainer.js.map +1 -1
- package/commonjs/DOM/ListTopOffsetWatcher.js +15 -9
- package/commonjs/DOM/ListTopOffsetWatcher.js.map +1 -1
- package/commonjs/DOM/ScrollableContainer.js +28 -28
- package/commonjs/DOM/ScrollableContainer.js.map +1 -1
- package/commonjs/DOM/VirtualScroller.js +20 -17
- package/commonjs/DOM/VirtualScroller.js.map +1 -1
- package/commonjs/DOM/tbody.js +16 -10
- package/commonjs/DOM/tbody.js.map +1 -1
- package/commonjs/ItemHeights.js +23 -17
- package/commonjs/ItemHeights.js.map +1 -1
- package/commonjs/Layout.js +15 -13
- package/commonjs/Layout.js.map +1 -1
- package/commonjs/Layout.test.js +8 -3
- package/commonjs/Layout.test.js.map +1 -1
- package/commonjs/{ListHeightChangeWatcher.js → ListHeightMeasurement.js} +26 -28
- package/commonjs/ListHeightMeasurement.js.map +1 -0
- package/commonjs/Resize.js +38 -28
- package/commonjs/Resize.js.map +1 -1
- package/commonjs/Scroll.js +28 -44
- package/commonjs/Scroll.js.map +1 -1
- package/commonjs/VirtualScroller.columns.js +43 -0
- package/commonjs/VirtualScroller.columns.js.map +1 -0
- package/commonjs/VirtualScroller.constructor.js +408 -0
- package/commonjs/VirtualScroller.constructor.js.map +1 -0
- package/commonjs/VirtualScroller.items.js +305 -0
- package/commonjs/VirtualScroller.items.js.map +1 -0
- package/commonjs/VirtualScroller.js +132 -1872
- package/commonjs/VirtualScroller.js.map +1 -1
- package/commonjs/VirtualScroller.layout.js +562 -0
- package/commonjs/VirtualScroller.layout.js.map +1 -0
- package/commonjs/VirtualScroller.onRender.js +357 -0
- package/commonjs/VirtualScroller.onRender.js.map +1 -0
- package/commonjs/VirtualScroller.resize.js +186 -0
- package/commonjs/VirtualScroller.resize.js.map +1 -0
- package/commonjs/VirtualScroller.state.js +301 -0
- package/commonjs/VirtualScroller.state.js.map +1 -0
- package/commonjs/VirtualScroller.verticalSpacing.js +65 -0
- package/commonjs/VirtualScroller.verticalSpacing.js.map +1 -0
- package/commonjs/getItemCoordinates.js.map +1 -1
- package/commonjs/getItemsDiff.js.map +1 -1
- package/commonjs/getVerticalSpacing.js.map +1 -1
- package/commonjs/package.json +5 -0
- package/commonjs/react/VirtualScroller.js +184 -618
- package/commonjs/react/VirtualScroller.js.map +1 -1
- package/commonjs/react/useClassName.js +26 -0
- package/commonjs/react/useClassName.js.map +1 -0
- package/commonjs/react/useHandleItemsChange.js +116 -0
- package/commonjs/react/useHandleItemsChange.js.map +1 -0
- package/commonjs/react/useInstanceMethods.js +37 -0
- package/commonjs/react/useInstanceMethods.js.map +1 -0
- package/commonjs/react/useItemKeys.js +60 -0
- package/commonjs/react/useItemKeys.js.map +1 -0
- package/commonjs/react/useOnItemHeightChange.js +32 -0
- package/commonjs/react/useOnItemHeightChange.js.map +1 -0
- package/commonjs/react/useOnItemStateChange.js +32 -0
- package/commonjs/react/useOnItemStateChange.js.map +1 -0
- package/commonjs/react/useState.js +140 -0
- package/commonjs/react/useState.js.map +1 -0
- package/commonjs/react/useStyle.js +29 -0
- package/commonjs/react/useStyle.js.map +1 -0
- package/commonjs/react/useVirtualScroller.js +62 -0
- package/commonjs/react/useVirtualScroller.js.map +1 -0
- package/commonjs/react/useVirtualScrollerStartStop.js +20 -0
- package/commonjs/react/useVirtualScrollerStartStop.js.map +1 -0
- package/commonjs/test/Engine.js +23 -0
- package/commonjs/test/Engine.js.map +1 -0
- package/commonjs/test/ItemsContainer.js +127 -0
- package/commonjs/test/ItemsContainer.js.map +1 -0
- package/commonjs/test/ScrollableContainer.js +130 -0
- package/commonjs/test/ScrollableContainer.js.map +1 -0
- package/commonjs/test/VirtualScroller.js +281 -0
- package/commonjs/test/VirtualScroller.js.map +1 -0
- package/commonjs/utility/debounce.js +2 -2
- package/commonjs/utility/debounce.js.map +1 -1
- package/commonjs/utility/debug.js.map +1 -1
- package/commonjs/utility/getStateSnapshot.js +2 -2
- package/commonjs/utility/getStateSnapshot.js.map +1 -1
- package/commonjs/utility/px.js.map +1 -1
- package/commonjs/utility/px.test.js +1 -1
- package/commonjs/utility/px.test.js.map +1 -1
- package/commonjs/utility/shallowEqual.js +1 -1
- package/commonjs/utility/shallowEqual.js.map +1 -1
- package/commonjs/utility/throttle.js.map +1 -1
- package/dom/index.cjs +4 -0
- package/dom/index.cjs.js +9 -0
- package/dom/index.d.ts +6 -4
- package/dom/index.js +1 -1
- package/dom/package.json +10 -4
- package/index.cjs +4 -0
- package/index.cjs.js +9 -0
- package/index.d.ts +30 -15
- package/index.js +1 -1
- package/modules/BeforeResize.js +22 -27
- package/modules/BeforeResize.js.map +1 -1
- package/modules/DOM/Engine.js +6 -6
- package/modules/DOM/Engine.js.map +1 -1
- package/modules/DOM/ItemsContainer.js +1 -1
- package/modules/DOM/ItemsContainer.js.map +1 -1
- package/modules/DOM/ListTopOffsetWatcher.js +15 -9
- package/modules/DOM/ListTopOffsetWatcher.js.map +1 -1
- package/modules/DOM/ScrollableContainer.js +28 -28
- package/modules/DOM/ScrollableContainer.js.map +1 -1
- package/modules/DOM/VirtualScroller.js +19 -16
- package/modules/DOM/VirtualScroller.js.map +1 -1
- package/modules/DOM/tbody.js +11 -9
- package/modules/DOM/tbody.js.map +1 -1
- package/modules/ItemHeights.js +22 -16
- package/modules/ItemHeights.js.map +1 -1
- package/modules/Layout.js +14 -12
- package/modules/Layout.js.map +1 -1
- package/modules/Layout.test.js +8 -3
- package/modules/Layout.test.js.map +1 -1
- package/modules/{ListHeightChangeWatcher.js → ListHeightMeasurement.js} +25 -27
- package/modules/ListHeightMeasurement.js.map +1 -0
- package/modules/Resize.js +38 -28
- package/modules/Resize.js.map +1 -1
- package/modules/Scroll.js +28 -44
- package/modules/Scroll.js.map +1 -1
- package/modules/VirtualScroller.columns.js +36 -0
- package/modules/VirtualScroller.columns.js.map +1 -0
- package/modules/VirtualScroller.constructor.js +371 -0
- package/modules/VirtualScroller.constructor.js.map +1 -0
- package/modules/VirtualScroller.items.js +288 -0
- package/modules/VirtualScroller.items.js.map +1 -0
- package/modules/VirtualScroller.js +132 -1860
- package/modules/VirtualScroller.js.map +1 -1
- package/modules/VirtualScroller.layout.js +549 -0
- package/modules/VirtualScroller.layout.js.map +1 -0
- package/modules/VirtualScroller.onRender.js +337 -0
- package/modules/VirtualScroller.onRender.js.map +1 -0
- package/modules/VirtualScroller.resize.js +176 -0
- package/modules/VirtualScroller.resize.js.map +1 -0
- package/modules/VirtualScroller.state.js +283 -0
- package/modules/VirtualScroller.state.js.map +1 -0
- package/modules/VirtualScroller.verticalSpacing.js +54 -0
- package/modules/VirtualScroller.verticalSpacing.js.map +1 -0
- package/modules/getItemCoordinates.js.map +1 -1
- package/modules/getItemsDiff.js.map +1 -1
- package/modules/getVerticalSpacing.js.map +1 -1
- package/modules/react/VirtualScroller.js +176 -625
- package/modules/react/VirtualScroller.js.map +1 -1
- package/modules/react/useClassName.js +18 -0
- package/modules/react/useClassName.js.map +1 -0
- package/modules/react/useHandleItemsChange.js +108 -0
- package/modules/react/useHandleItemsChange.js.map +1 -0
- package/modules/react/useInstanceMethods.js +28 -0
- package/modules/react/useInstanceMethods.js.map +1 -0
- package/modules/react/useItemKeys.js +52 -0
- package/modules/react/useItemKeys.js.map +1 -0
- package/modules/react/useOnItemHeightChange.js +24 -0
- package/modules/react/useOnItemHeightChange.js.map +1 -0
- package/modules/react/useOnItemStateChange.js +24 -0
- package/modules/react/useOnItemStateChange.js.map +1 -0
- package/modules/react/useState.js +132 -0
- package/modules/react/useState.js.map +1 -0
- package/modules/react/useStyle.js +19 -0
- package/modules/react/useStyle.js.map +1 -0
- package/modules/react/useVirtualScroller.js +51 -0
- package/modules/react/useVirtualScroller.js.map +1 -0
- package/modules/react/useVirtualScrollerStartStop.js +12 -0
- package/modules/react/useVirtualScrollerStartStop.js.map +1 -0
- package/modules/test/Engine.js +11 -0
- package/modules/test/Engine.js.map +1 -0
- package/modules/test/ItemsContainer.js +120 -0
- package/modules/test/ItemsContainer.js.map +1 -0
- package/modules/test/ScrollableContainer.js +123 -0
- package/modules/test/ScrollableContainer.js.map +1 -0
- package/modules/test/VirtualScroller.js +270 -0
- package/modules/test/VirtualScroller.js.map +1 -0
- package/modules/utility/debounce.js +2 -2
- package/modules/utility/debounce.js.map +1 -1
- package/modules/utility/debug.js.map +1 -1
- package/modules/utility/getStateSnapshot.js +2 -2
- package/modules/utility/getStateSnapshot.js.map +1 -1
- package/modules/utility/px.js.map +1 -1
- package/modules/utility/px.test.js +1 -1
- package/modules/utility/px.test.js.map +1 -1
- package/modules/utility/shallowEqual.js +1 -1
- package/modules/utility/shallowEqual.js.map +1 -1
- package/modules/utility/throttle.js.map +1 -1
- package/package.json +46 -23
- package/react/index.cjs +4 -0
- package/react/index.cjs.js +9 -0
- package/react/index.d.ts +10 -9
- package/react/index.js +1 -1
- package/react/package.json +10 -4
- package/rollup.config.mjs +62 -0
- package/runnable/create-commonjs-package-json.js +11 -0
- package/source/BeforeResize.js +16 -21
- package/source/DOM/Engine.js +8 -10
- package/source/DOM/ListTopOffsetWatcher.js +13 -8
- package/source/DOM/ScrollableContainer.js +23 -21
- package/source/DOM/VirtualScroller.js +27 -11
- package/source/DOM/tbody.js +30 -21
- package/source/ItemHeights.js +19 -14
- package/source/Layout.js +12 -9
- package/source/Layout.test.js +8 -3
- package/source/{ListHeightChangeWatcher.js → ListHeightMeasurement.js} +21 -20
- package/source/Resize.js +41 -25
- package/source/Scroll.js +27 -35
- package/source/VirtualScroller.columns.js +26 -0
- package/source/VirtualScroller.constructor.js +336 -0
- package/source/VirtualScroller.items.js +302 -0
- package/source/VirtualScroller.js +144 -1872
- package/source/VirtualScroller.layout.js +539 -0
- package/source/VirtualScroller.onRender.js +345 -0
- package/source/VirtualScroller.resize.js +189 -0
- package/source/VirtualScroller.state.js +284 -0
- package/source/VirtualScroller.verticalSpacing.js +51 -0
- package/source/react/VirtualScroller.js +243 -587
- package/source/react/useClassName.js +14 -0
- package/source/react/useHandleItemsChange.js +115 -0
- package/source/react/useInstanceMethods.js +25 -0
- package/source/react/useItemKeys.js +59 -0
- package/source/react/useOnItemHeightChange.js +28 -0
- package/source/react/useOnItemStateChange.js +28 -0
- package/source/react/useState.js +114 -0
- package/source/react/useStyle.js +20 -0
- package/source/react/useVirtualScroller.js +59 -0
- package/source/react/useVirtualScrollerStartStop.js +12 -0
- package/source/test/Engine.js +11 -0
- package/source/test/ItemsContainer.js +87 -0
- package/source/test/ScrollableContainer.js +88 -0
- package/source/test/VirtualScroller.js +232 -0
- package/source/utility/debounce.js +2 -2
- package/source/utility/px.test.js +1 -1
- package/babel.config.js +0 -25
- package/babel.js +0 -5
- package/commonjs/ListHeightChangeWatcher.js.map +0 -1
- package/dom/index.commonjs.js +0 -4
- package/index.commonjs.js +0 -4
- package/modules/ListHeightChangeWatcher.js.map +0 -1
- package/react/index.commonjs.js +0 -4
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../source/ItemHeights.js"],"names":["log","warn","isDebug","reportError","ItemHeights","container","getItemHeight","setItemHeight","_get","_set","reset","measuredItemsHeight","firstMeasuredItemIndex","undefined","lastMeasuredItemIndex","itemHeights","i","length","firstShownItemIndex","getNthRenderedItemHeight","lastShownItemIndex","nonPreviouslyMeasuredItemIndexes","previousFirstMeasuredItemIndex","previousLastMeasuredItemIndex","firstMeasuredItemIndexHasBeenUpdated","push","height","_measureItemHeight","previousHeight","count"],"mappings":";;;;;;AAAA,OAAOA,GAAP,IAAcC,IAAd,EAAoBC,OAApB,EAA6BC,WAA7B,QAAgD,iBAAhD;;IAEqBC,W;AACpB,uBAAYC,SAAZ,EAAuBC,aAAvB,EAAsCC,aAAtC,EAAqD;AAAA;;AACpD,SAAKF,SAAL,GAAiBA,SAAjB;AACA,SAAKG,IAAL,GAAYF,aAAZ;AACA,SAAKG,IAAL,GAAYF,aAAZ;AACA,SAAKG,KAAL;AACA;;;;WAED,iBAAQ;AACP,WAAKC,mBAAL,GAA2B,CAA3B,CADO,CAEP;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,WAAKC,sBAAL,GAA8BC,SAA9B;AACA,WAAKC,qBAAL,GAA6BD,SAA7B;AACA;AAED;AACD;AACA;AACA;AACA;AACA;AACA;AACA;;;;WACC,oBAAWE,WAAX,EAAwB;AACvB,UAAIC,CAAC,GAAG,CAAR;;AACA,aAAOA,CAAC,GAAGD,WAAW,CAACE,MAAvB,EAA+B;AAC9B,YAAIF,WAAW,CAACC,CAAD,CAAX,KAAmBH,SAAvB,EAAkC;AACjC,cAAI,KAAKD,sBAAL,KAAgCC,SAApC,EAA+C;AAC9C,iBAAKC,qBAAL,GAA6BE,CAAC,GAAG,CAAjC;AACA;AACA;AACD,SALD,MAKO;AACN,cAAI,KAAKJ,sBAAL,KAAgCC,SAApC,EAA+C;AAC9C,iBAAKD,sBAAL,GAA8BI,CAA9B;AACA;;AACD,eAAKL,mBAAL,IAA4BI,WAAW,CAACC,CAAD,CAAvC;AACA;;AACDA,QAAAA,CAAC;AACD;AACD,K,CAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;;WAEA,4BAAmBA,CAAnB,EAAsBE,mBAAtB,EAA2C;AAC1C,aAAO,KAAKb,SAAL,CAAec,wBAA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,IAAL,CAAUO,CAAV,EAAaU,MAAb;;AACA,WAAKf,mBAAL,IAA4Be,MAAM,GAAGE,cAArC;AACA,aAAOF,MAAP;AACA,K,CAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACD;AACA;AACA;;;;WACC,sBAAa;AACZ,UAAI,KAAKZ,qBAAL,KAA+BD,SAAnC,EAA8C;AAC7C,eAAO,CAAP;AACA;;AACD,aAAO,KAAKF,mBAAL,IAA4B,KAAKG,qBAAL,GAA6B,KAAKF,sBAAlC,GAA2D,CAAvF,CAAP;AACA;;;WAED,mBAAUiB,KAAV,EAAiB;AAChB,UAAI,KAAKjB,sBAAL,KAAgCC,SAApC,EAA+C;AAC9C,aAAKD,sBAAL,IAA+BiB,KAA/B;AACA,aAAKf,qBAAL,IAA8Be,KAA9B;AACA;AACD;;;;;;SA7PmBzB,W","sourcesContent":["import log, { warn, isDebug, reportError } from './utility/debug'\r\n\r\nexport default class ItemHeights {\r\n\tconstructor(container, getItemHeight, setItemHeight) {\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 * Is called after `.reset()`.\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\tinitialize(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// 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 aren't neglecting that rule, item heights won't\r\n\t\t\t// change unexpectedly.\r\n\t\t\t// // Re-measure all shown items' heights, because an item's height\r\n\t\t\t// // might have changed since it has been measured initially.\r\n\t\t\t// // For example, if an item is a long comment with a \"Show more\" button,\r\n\t\t\t// // then the user might have clicked that \"Show more\" button.\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 the item's height right after showing it after being hidden,\r\n\t\t\t\t// because, if the stored item's state isn't applied properly, the item's\r\n\t\t\t\t// height might be incorrect when it's rendered with that state not applied,\r\n\t\t\t\t// and so a developer could know that there's a bug in their code.\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 was', previousHeight, 'before it was hidden, but, after showing it again, its height is', height, '. Perhaps you forgot to persist the item\\'s state by calling `onItemStateChange(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, but with the missing state.')\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}"],"file":"ItemHeights.js"}
|
|
1
|
+
{"version":3,"file":"ItemHeights.js","names":["log","warn","isDebug","reportError","ItemHeights","container","itemHeights","getItemHeight","setItemHeight","_get","_set","reset","measuredItemsHeight","firstMeasuredItemIndex","undefined","lastMeasuredItemIndex","i","length","firstShownItemIndex","getNthRenderedItemHeight","lastShownItemIndex","nonPreviouslyMeasuredItemIndexes","previousFirstMeasuredItemIndex","previousLastMeasuredItemIndex","firstMeasuredItemIndexHasBeenUpdated","push","height","_measureItemHeight","previousHeight","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 `onItemStateChange(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 `onItemStateChange(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,OAAOA,GAAP,IAAcC,IAAd,EAAoBC,OAApB,EAA6BC,WAA7B,QAAgD,oBAAhD;;IAEqBC,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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BAAL,IAA+BgB,KAA/B;QACA,KAAKd,qBAAL,IAA8Bc,KAA9B;MACA;IACD;;;;;;SAlQmBzB,W"}
|
package/modules/Layout.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object);
|
|
1
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
2
2
|
|
|
3
|
-
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]
|
|
3
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
4
4
|
|
|
5
5
|
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
6
6
|
|
|
@@ -8,9 +8,9 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons
|
|
|
8
8
|
|
|
9
9
|
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
|
|
10
10
|
|
|
11
|
-
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
|
|
11
|
+
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
|
12
12
|
|
|
13
|
-
import log, { warn } from './utility/debug';
|
|
13
|
+
import log, { warn } from './utility/debug.js';
|
|
14
14
|
|
|
15
15
|
var Layout = /*#__PURE__*/function () {
|
|
16
16
|
function Layout(_ref) {
|
|
@@ -136,7 +136,8 @@ var Layout = /*#__PURE__*/function () {
|
|
|
136
136
|
appendedItemsCount = _ref5.appendedItemsCount;
|
|
137
137
|
var itemsCount = _ref6.itemsCount,
|
|
138
138
|
columnsCount = _ref6.columnsCount,
|
|
139
|
-
shouldRestoreScrollPosition = _ref6.shouldRestoreScrollPosition
|
|
139
|
+
shouldRestoreScrollPosition = _ref6.shouldRestoreScrollPosition,
|
|
140
|
+
onResetGridLayout = _ref6.onResetGridLayout;
|
|
140
141
|
// const layoutUpdate = {}
|
|
141
142
|
// If the layout stays the same, then simply increase
|
|
142
143
|
// the top and bottom margins proportionally to the amount
|
|
@@ -209,8 +210,9 @@ var Layout = /*#__PURE__*/function () {
|
|
|
209
210
|
// row heights, but I don't want to write code for such an extremely rare
|
|
210
211
|
// use case. Instead, use the `getColumnsCount()` parameter function when
|
|
211
212
|
// fetching previous items.
|
|
213
|
+
onResetGridLayout();
|
|
212
214
|
warn('~ Prepended items count', prependedItemsCount, 'is not divisible by Columns Count', columnsCount, '~');
|
|
213
|
-
warn('
|
|
215
|
+
warn('Layout reset required');
|
|
214
216
|
var shownItemsCountBeforeItemsUpdate = lastShownItemIndex - firstShownItemIndex + 1;
|
|
215
217
|
firstShownItemIndex = 0;
|
|
216
218
|
beforeItemsHeight = 0;
|
|
@@ -243,20 +245,20 @@ var Layout = /*#__PURE__*/function () {
|
|
|
243
245
|
// The reason is that only this way subsequent `setItems()` calls
|
|
244
246
|
// will be truly "stateless" when a chain of `setItems()` calls
|
|
245
247
|
// could be replaced with just the last one in a scenario when
|
|
246
|
-
// `
|
|
248
|
+
// `updateState()` calls are "asynchronous" (delayed execution).
|
|
247
249
|
//
|
|
248
250
|
// So, for example, the user calls `setItems()` with one set of items.
|
|
249
|
-
// A `
|
|
251
|
+
// A `updateState()` call has been dispatched but the `state` hasn't been updated yet.
|
|
250
252
|
// Then the user calls `setItems()` with another set of items.
|
|
251
253
|
// If this function only returned a minimal set of properties that actually change,
|
|
252
254
|
// the other layout properties of the second `setItems()` call wouldn't overwrite the ones
|
|
253
255
|
// scheduled for update during the first `setItems()` call, resulting in an inconsistent `state`.
|
|
254
256
|
//
|
|
255
|
-
// For example, the first `setItems()` call does a `
|
|
257
|
+
// For example, the first `setItems()` call does a `updateState()` call where it updates
|
|
256
258
|
// `afterItemsHeight`, and then the second `setItems()` call only updates `beforeItemsHeight`
|
|
257
259
|
// and `firstShownItemIndex` and `lastShownItemIndex`. If the second `setItems()` call was to
|
|
258
260
|
// overwrite any effects of the pending-but-not-yet-applied first `setItems()` call, it would
|
|
259
|
-
// have to call `
|
|
261
|
+
// have to call `updateState()` with an `afterItemsHeight` property too, even though it hasn't change.
|
|
260
262
|
// That would be just to revert the change to `afterItemsHeight` state property already scheduled
|
|
261
263
|
// by the first `setItems()` call.
|
|
262
264
|
//
|
|
@@ -745,8 +747,8 @@ export var LAYOUT_REASON = {
|
|
|
745
747
|
SCROLL: 'scroll',
|
|
746
748
|
STOPPED_SCROLLING: 'stopped scrolling',
|
|
747
749
|
MANUAL: 'manual',
|
|
748
|
-
|
|
749
|
-
|
|
750
|
+
STARTED: 'started',
|
|
751
|
+
NON_MEASURED_ITEMS_HAVE_BEEN_MEASURED: 'non-measured item heights have been measured',
|
|
750
752
|
VIEWPORT_WIDTH_CHANGED: 'viewport width changed',
|
|
751
753
|
VIEWPORT_HEIGHT_CHANGED: 'viewport height changed',
|
|
752
754
|
VIEWPORT_SIZE_UNCHANGED: 'viewport size unchanged',
|
package/modules/Layout.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../source/Layout.js"],"names":["log","warn","Layout","bypass","estimatedItemHeight","measureItemsBatchSize","getPrerenderMargin","getVerticalSpacing","getVerticalSpacingBeforeResize","getColumnsCount","getColumnsCountBeforeResize","getItemHeight","getItemHeightBeforeResize","getBeforeResizeItemsCount","getAverageItemHeight","getMaxVisibleAreaHeight","getPreviouslyCalculatedLayout","itemsCount","columnsCount","firstShownItemIndex","lastShownItemIndex","getInitialLastShownItemIndex","beforeItemsHeight","afterItemsHeight","estimatedRowsCount","getEstimatedRowsCountForHeight","Math","min","height","getEstimatedItemHeight","verticalSpacing","ceil","prependedItemsCount","appendedItemsCount","shouldRestoreScrollPosition","averageItemHeight","appendedRowsCount","addedHeightAfter","prependedRowsCount","addedHeightBefore","shownItemsCountBeforeItemsUpdate","afterItemsCount","i","nonMeasuredAreaHeight","indexOfTheFirstItemInTheRow","itemsCountToRenderForMeasurement","Infinity","undefined","firstNonMeasuredItemIndex","visibleAreaTop","visibleAreaBottom","indexes","_getShownItemIndex","fromIndex","findFirstShownItemIndex","getNonVisibleListShownItemIndexes","findLastShownItemIndex","parameters","beforeResize","Error","beforeResizeItemsCount","notFound","beforeResizeItemsHeight","floor","currentRowFirstItemIndex","hasMoreRows","verticalSpacingAfterCurrentRow","currentRowHeight","columnIndex","itemHeight","getItemNotMeasuredIndexes","max","itemsHeightFromFirstRowToThisRow","rowStepsIntoVisibleAreaTop","rowStepsOutOfVisibleAreaBottomOrIsAtTheBorder","layout","beforeItemsCount","getBeforeItemsHeight","rowHeight","lastShownRowIndex","topOffsetInsideScrollableContainer","beforeResizeRowsCount","maxBeforeResizeRowsCount","beforeResizeRowIndex","itemRowIndex","rowIndex","LAYOUT_REASON","SCROLL","STOPPED_SCROLLING","MANUAL","MOUNTED","ACTUAL_ITEM_HEIGHTS_HAVE_BEEN_MEASURED","VIEWPORT_WIDTH_CHANGED","VIEWPORT_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EAAE,yBARG;AAS5BC,EAAAA,mBAAmB,EAAE,qBATO;AAU5BC,EAAAA,aAAa,EAAE,eAVa;AAW5BC,EAAAA,kBAAkB,EAAE;AAXQ,CAAtB","sourcesContent":["import log, { warn } from './utility/debug'\r\n\r\nexport default class Layout {\r\n\tconstructor({\r\n\t\tbypass,\r\n\t\testimatedItemHeight,\r\n\t\tmeasureItemsBatchSize,\r\n\t\tgetPrerenderMargin,\r\n\t\tgetVerticalSpacing,\r\n\t\tgetVerticalSpacingBeforeResize,\r\n\t\tgetColumnsCount,\r\n\t\tgetColumnsCountBeforeResize,\r\n\t\tgetItemHeight,\r\n\t\tgetItemHeightBeforeResize,\r\n\t\tgetBeforeResizeItemsCount,\r\n\t\tgetAverageItemHeight,\r\n\t\tgetMaxVisibleAreaHeight,\r\n\t\tgetPreviouslyCalculatedLayout\r\n\t}) {\r\n\t\tthis.bypass = bypass\r\n\t\tthis.estimatedItemHeight = estimatedItemHeight\r\n\t\tthis.measureItemsBatchSize = measureItemsBatchSize\r\n\t\tthis.getPrerenderMargin = getPrerenderMargin\r\n\t\tthis.getVerticalSpacing = getVerticalSpacing\r\n\t\tthis.getVerticalSpacingBeforeResize = getVerticalSpacingBeforeResize\r\n\t\tthis.getColumnsCount = getColumnsCount\r\n\t\tthis.getColumnsCountBeforeResize = getColumnsCountBeforeResize\r\n\t\tthis.getItemHeight = getItemHeight\r\n\t\tthis.getItemHeightBeforeResize = getItemHeightBeforeResize\r\n\t\tthis.getBeforeResizeItemsCount = getBeforeResizeItemsCount\r\n\t\tthis.getAverageItemHeight = getAverageItemHeight\r\n\t\tthis.getMaxVisibleAreaHeight = getMaxVisibleAreaHeight\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\tthis.getPreviouslyCalculatedLayout = getPreviouslyCalculatedLayout\r\n\t}\r\n\r\n\tgetInitialLayoutValues({\r\n\t\titemsCount,\r\n\t\tcolumnsCount\r\n\t}) {\r\n\t\tlet firstShownItemIndex\r\n\t\tlet lastShownItemIndex\r\n\t\t// If there're no items then `firstShownItemIndex` stays `undefined`.\r\n\t\tif (itemsCount > 0) {\r\n\t\t\tfirstShownItemIndex = 0\r\n\t\t\tlastShownItemIndex = this.getInitialLastShownItemIndex({\r\n\t\t\t\titemsCount,\r\n\t\t\t\tcolumnsCount,\r\n\t\t\t\tfirstShownItemIndex\r\n\t\t\t})\r\n\t\t}\r\n\t\treturn {\r\n\t\t\tbeforeItemsHeight: 0,\r\n\t\t\tafterItemsHeight: 0,\r\n\t\t\tfirstShownItemIndex,\r\n\t\t\tlastShownItemIndex\r\n\t\t}\r\n\t}\r\n\r\n\tgetInitialLastShownItemIndex({\r\n\t\titemsCount,\r\n\t\tcolumnsCount,\r\n\t\tfirstShownItemIndex\r\n\t}) {\r\n\t\tif (this.bypass) {\r\n\t\t\treturn itemsCount - 1\r\n\t\t}\r\n\t\t// On server side, at initialization time,\r\n\t\t// `scrollableContainer` is `undefined`,\r\n\t\t// so default to `1` estimated rows count.\r\n\t\tlet estimatedRowsCount = 1\r\n\t\tif (this.getMaxVisibleAreaHeight()) {\r\n\t\t\testimatedRowsCount = this.getEstimatedRowsCountForHeight(this.getMaxVisibleAreaHeight() + this.getPrerenderMargin())\r\n\t\t}\r\n\t\treturn Math.min(\r\n\t\t\tfirstShownItemIndex + (estimatedRowsCount * columnsCount - 1),\r\n\t\t\titemsCount - 1\r\n\t\t)\r\n\t}\r\n\r\n\tgetEstimatedRowsCountForHeight(height) {\r\n\t\tconst estimatedItemHeight = this.getEstimatedItemHeight()\r\n\t\tconst verticalSpacing = this.getVerticalSpacing()\r\n\t\tif (estimatedItemHeight) {\r\n\t\t\treturn Math.ceil((height + verticalSpacing) / (estimatedItemHeight + verticalSpacing))\r\n\t\t} else {\r\n\t\t\t// If no items have been rendered yet, and no `estimatedItemHeight` option\r\n\t\t\t// has been passed, then default to `1` estimated rows count in any `height`.\r\n\t\t\treturn 1\r\n\t\t}\r\n\t}\r\n\r\n\t/**\r\n\t * Returns estimated list item height.\r\n\t * (depends on which items have been previously rendered and measured).\r\n\t * @return {number}\r\n\t */\r\n\tgetEstimatedItemHeight() {\r\n\t\treturn this.getAverageItemHeight() || this.estimatedItemHeight || 0\r\n\t}\r\n\r\n\tgetLayoutUpdateForItemsDiff({\r\n\t\tfirstShownItemIndex,\r\n\t\tlastShownItemIndex,\r\n\t\tbeforeItemsHeight,\r\n\t\tafterItemsHeight\r\n\t}, {\r\n\t\tprependedItemsCount,\r\n\t\tappendedItemsCount\r\n\t}, {\r\n\t\titemsCount,\r\n\t\tcolumnsCount,\r\n\t\tshouldRestoreScrollPosition\r\n\t}) {\r\n\t\t// const layoutUpdate = {}\r\n\r\n\t\t// If the layout stays the same, then simply increase\r\n\t\t// the top and bottom margins proportionally to the amount\r\n\t\t// of the items added.\r\n\t\tconst averageItemHeight = this.getAverageItemHeight()\r\n\t\tconst verticalSpacing = this.getVerticalSpacing()\r\n\r\n\t\tif (appendedItemsCount > 0) {\r\n\t\t\tconst appendedRowsCount = Math.ceil(appendedItemsCount / columnsCount)\r\n\t\t\tconst addedHeightAfter = appendedRowsCount * (verticalSpacing + averageItemHeight)\r\n\r\n\t\t\tafterItemsHeight += addedHeightAfter\r\n\r\n\t\t\t// layoutUpdate = {\r\n\t\t\t// \t...layoutUpdate,\r\n\t\t\t// \tafterItemsHeight\r\n\t\t\t// }\r\n\t\t}\r\n\r\n\t\tif (prependedItemsCount > 0) {\r\n\t\t\tconst prependedRowsCount = Math.ceil(prependedItemsCount / columnsCount)\r\n\t\t\tconst addedHeightBefore = prependedRowsCount * (averageItemHeight + verticalSpacing)\r\n\r\n\t\t\tfirstShownItemIndex += prependedItemsCount\r\n\t\t\tlastShownItemIndex += prependedItemsCount\r\n\t\t\tbeforeItemsHeight += addedHeightBefore\r\n\r\n\t\t\t// If the currently shown items position on screen should be preserved\r\n\t\t\t// when prepending new items, then it means that:\r\n\t\t\t// * The current scroll position should be snapshotted.\r\n\t\t\t// * The current list height should be snapshotted.\r\n\t\t\t// * All prepended items should be shown so that their height could be\r\n\t\t\t// measured after they're rendered. Based on the prepended items' height,\r\n\t\t\t// the scroll position will be restored so that there's no \"jump of content\".\r\n\t\t\tif (shouldRestoreScrollPosition) {\r\n\t\t\t\tfirstShownItemIndex = 0\r\n\t\t\t\tbeforeItemsHeight = 0\r\n\t\t\t}\r\n\r\n\t\t\tif (prependedItemsCount % columnsCount > 0) {\r\n\t\t\t\t// Rows will be rebalanced as a result of prepending new items,\r\n\t\t\t\t// and row heights can change as a result, so re-layout items\r\n\t\t\t\t// after they've been measured (after the upcoming re-render).\r\n\t\t\t\t//\r\n\t\t\t\t// For example, consider a web page where item rows are `display: flex`.\r\n\t\t\t\t// Suppose there're 3 columns and it shows items from 4 to 6.\r\n\t\t\t\t//\r\n\t\t\t\t// ------------------------------------------\r\n\t\t\t\t// | Apples are | Bananas | Cranberries |\r\n\t\t\t\t// | green | | |\r\n\t\t\t\t// ------------------------------------------\r\n\t\t\t\t// | Dates | Elderberry | Figs are |\r\n\t\t\t\t// | | | tasty |\r\n\t\t\t\t// ------------------------------------------\r\n\t\t\t\t//\r\n\t\t\t\t// Now, 1 item gets prepended. As a result, all existing rows will have\r\n\t\t\t\t// a different set of items, which means that the row heights will change.\r\n\t\t\t\t//\r\n\t\t\t\t// ------------------------------------------\r\n\t\t\t\t// | Zucchini | Apples are | Bananas |\r\n\t\t\t\t// | | green | |\r\n\t\t\t\t// ------------------------------------------\r\n\t\t\t\t// | Cranberries | Dates | Elderberry |\r\n\t\t\t\t// ------------------------------------------\r\n\t\t\t\t// | Figs |\r\n\t\t\t\t// | are tasty |\r\n\t\t\t\t// ---------------\r\n\t\t\t\t//\r\n\t\t\t\t// As it can be seen above, the second row's height has changed from 2 to 1.\r\n\t\t\t\t// Not only that, but `itemHeights` have changed as well, so if you thought\r\n\t\t\t\t// that the library could easily recalculate row heights using `Math.max()` — \r\n\t\t\t\t// turns out it's not always the case.\r\n\t\t\t\t//\r\n\t\t\t\t// There could be an explicit opt-in option for automatically recalculating\r\n\t\t\t\t// row heights, but I don't want to write code for such an extremely rare\r\n\t\t\t\t// use case. Instead, use the `getColumnsCount()` parameter function when\r\n\t\t\t\t// fetching previous items.\r\n\r\n\t\t\t\twarn('~ Prepended items count', prependedItemsCount, 'is not divisible by Columns Count', columnsCount, '~')\r\n\t\t\t\twarn('Reset Layout')\r\n\r\n\t\t\t\tconst shownItemsCountBeforeItemsUpdate = lastShownItemIndex - firstShownItemIndex + 1\r\n\r\n\t\t\t\tfirstShownItemIndex = 0\r\n\t\t\t\tbeforeItemsHeight = 0\r\n\r\n\t\t\t\tif (!shouldRestoreScrollPosition) {\r\n\t\t\t\t\t// Limit shown items count if too many items have been prepended.\r\n\t\t\t\t\tif (prependedItemsCount > shownItemsCountBeforeItemsUpdate) {\r\n\t\t\t\t\t\tlastShownItemIndex = this.getInitialLastShownItemIndex({\r\n\t\t\t\t\t\t\titemsCount,\r\n\t\t\t\t\t\t\tcolumnsCount,\r\n\t\t\t\t\t\t\tfirstShownItemIndex\r\n\t\t\t\t\t\t})\r\n\r\n\t\t\t\t\t\t// Approximate `afterItemsHeight` calculation.\r\n\t\t\t\t\t\tconst afterItemsCount = itemsCount - (lastShownItemIndex + 1)\r\n\t\t\t\t\t\tafterItemsHeight = Math.ceil(afterItemsCount / columnsCount) * (verticalSpacing + averageItemHeight)\r\n\r\n\t\t\t\t\t\t// layoutUpdate = {\r\n\t\t\t\t\t\t// \t...layoutUpdate,\r\n\t\t\t\t\t\t// \tafterItemsHeight\r\n\t\t\t\t\t\t// }\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t}\r\n\r\n\t\t\t// layoutUpdate = {\r\n\t\t\t// \t...layoutUpdate,\r\n\t\t\t// \tbeforeItemsHeight,\r\n\t\t\t// \tfirstShownItemIndex,\r\n\t\t\t// \tlastShownItemIndex\r\n\t\t\t// }\r\n\t\t}\r\n\r\n\t\t// return layoutUpdate\r\n\r\n\t\t// Overwrite all four props in all scenarios.\r\n\t\t// The reason is that only this way subsequent `setItems()` calls\r\n\t\t// will be truly \"stateless\" when a chain of `setItems()` calls\r\n\t\t// could be replaced with just the last one in a scenario when\r\n\t\t// `setState()` calls are \"asynchronous\" (delayed execution).\r\n\t\t//\r\n\t\t// So, for example, the user calls `setItems()` with one set of items.\r\n\t\t// A `setState()` call has been dispatched but the `state` hasn't been updated yet.\r\n\t\t// Then the user calls `setItems()` with another set of items.\r\n\t\t// If this function only returned a minimal set of properties that actually change,\r\n\t\t// the other layout properties of the second `setItems()` call wouldn't overwrite the ones\r\n\t\t// scheduled for update during the first `setItems()` call, resulting in an inconsistent `state`.\r\n\t\t//\r\n\t\t// For example, the first `setItems()` call does a `setState()` call where it updates\r\n\t\t// `afterItemsHeight`, and then the second `setItems()` call only updates `beforeItemsHeight`\r\n\t\t// and `firstShownItemIndex` and `lastShownItemIndex`. If the second `setItems()` call was to\r\n\t\t// overwrite any effects of the pending-but-not-yet-applied first `setItems()` call, it would\r\n\t\t// have to call `setState()` with an `afterItemsHeight` property too, even though it hasn't change.\r\n\t\t// That would be just to revert the change to `afterItemsHeight` state property already scheduled\r\n\t\t// by the first `setItems()` call.\r\n\t\t//\r\n\t\treturn {\r\n\t\t\tbeforeItemsHeight,\r\n\t\t\tafterItemsHeight,\r\n\t\t\tfirstShownItemIndex,\r\n\t\t\tlastShownItemIndex\r\n\t\t}\r\n\t}\r\n\r\n\t// If an item that hasn't been shown (and measured) yet is encountered\r\n\t// then show such item and then retry after it has been measured.\r\n\tgetItemNotMeasuredIndexes(i, {\r\n\t\titemsCount,\r\n\t\tfirstShownItemIndex,\r\n\t\tnonMeasuredAreaHeight,\r\n\t\tindexOfTheFirstItemInTheRow\r\n\t}) {\r\n\t\tlog('Item index', i, 'height is required for calculations but hasn\\'t been measured yet. Mark the item as \"shown\", rerender the list, measure the item\\'s height and redo the layout.')\r\n\r\n\t\tconst columnsCount = this.getColumnsCount()\r\n\r\n\t\tconst itemsCountToRenderForMeasurement = Math.min(\r\n\t\t\tthis.getEstimatedRowsCountForHeight(nonMeasuredAreaHeight) * columnsCount,\r\n\t\t\tthis.measureItemsBatchSize || Infinity,\r\n\t\t)\r\n\r\n\t\tif (firstShownItemIndex === undefined) {\r\n\t\t\tfirstShownItemIndex = indexOfTheFirstItemInTheRow\r\n\t\t}\r\n\r\n\t\tconst lastShownItemIndex = Math.min(\r\n\t\t\tindexOfTheFirstItemInTheRow + itemsCountToRenderForMeasurement - 1,\r\n\t\t\t// Guard against index overflow.\r\n\t\t\titemsCount - 1\r\n\t\t)\r\n\r\n\t\treturn {\r\n\t\t\tfirstNonMeasuredItemIndex: i,\r\n\t\t\tfirstShownItemIndex,\r\n\t\t\tlastShownItemIndex\r\n\t\t}\r\n\t}\r\n\r\n\t/**\r\n\t * Finds the indexes of the currently visible items.\r\n\t * @return {object} `{ firstShownItemIndex: number, lastShownItemIndex: number, firstNonMeasuredItemIndex: number? }`\r\n\t */\r\n\tgetShownItemIndexes({\r\n\t\titemsCount,\r\n\t\tvisibleAreaTop,\r\n\t\tvisibleAreaBottom\r\n\t}) {\r\n\t\tlet indexes = this._getShownItemIndex({\r\n\t\t\titemsCount,\r\n\t\t\tfromIndex: 0,\r\n\t\t\tvisibleAreaTop,\r\n\t\t\tvisibleAreaBottom,\r\n\t\t\tfindFirstShownItemIndex: true\r\n\t\t})\r\n\r\n\t\tif (indexes === null) {\r\n\t\t\treturn this.getNonVisibleListShownItemIndexes()\r\n\t\t}\r\n\r\n\t\tif (indexes.firstNonMeasuredItemIndex !== undefined) {\r\n\t\t\treturn indexes\r\n\t\t}\r\n\r\n\t\tconst { firstShownItemIndex, beforeItemsHeight } = indexes\r\n\r\n\t\tindexes = this._getShownItemIndex({\r\n\t\t\titemsCount,\r\n\t\t\tfromIndex: firstShownItemIndex,\r\n\t\t\tbeforeItemsHeight,\r\n\t\t\tvisibleAreaTop,\r\n\t\t\tvisibleAreaBottom,\r\n\t\t\tfindLastShownItemIndex: true\r\n\t\t})\r\n\r\n\t\tif (indexes === null) {\r\n\t\t\treturn this.getNonVisibleListShownItemIndexes()\r\n\t\t}\r\n\r\n\t\tif (indexes.firstNonMeasuredItemIndex !== undefined) {\r\n\t\t\treturn indexes\r\n\t\t}\r\n\r\n\t\tconst { lastShownItemIndex } = indexes\r\n\r\n\t\treturn {\r\n\t\t\tfirstShownItemIndex,\r\n\t\t\tlastShownItemIndex\r\n\t\t}\r\n\t}\r\n\r\n\t_getShownItemIndex(parameters) {\r\n\t\tconst {\r\n\t\t\tbeforeResize,\r\n\t\t\titemsCount,\r\n\t\t\tvisibleAreaTop,\r\n\t\t\tvisibleAreaBottom,\r\n\t\t\tfindFirstShownItemIndex,\r\n\t\t\tfindLastShownItemIndex,\r\n\t\t\t// backwards\r\n\t\t} = parameters\r\n\r\n\t\tlet {\r\n\t\t\tfromIndex,\r\n\t\t\tbeforeItemsHeight\r\n\t\t} = parameters\r\n\r\n\t\t// This function could potentially also use `this.getPreviouslyCalculatedLayout()`\r\n\t\t// in order to skip calculating visible item indexes from scratch\r\n\t\t// and instead just calculate the difference from a \"previously calculated layout\".\r\n\t\t//\r\n\t\t// I did a simple test in a web browser and found out that running the following\r\n\t\t// piece of code is less than 10 milliseconds:\r\n\t\t//\r\n\t\t// var startedAt = Date.now()\r\n\t\t// var i = 0\r\n\t\t// while (i < 1000000) {\r\n\t\t// i++\r\n\t\t// }\r\n\t\t// console.log(Date.now() - startedAt)\r\n\t\t//\r\n\t\t// Which becomes negligible in my project's use case (a couple thousands items max).\r\n\t\t//\r\n\t\t// If someone would attempt to use a \"previously calculated layout\" here\r\n\t\t// then `shownItemsHeight` would also have to be returned from this function:\r\n\t\t// the total height of all shown items including vertical spacing between them.\r\n\t\t//\r\n\t\t// If \"previously calculated layout\" would be used then it would first find\r\n\t\t// `firstShownItemIndex` and then find `lastShownItemIndex` as part of two\r\n\t\t// separate calls of this function, each with or without `backwards` flag,\r\n\t\t// depending on whether `visibleAreaTop` and `visibleAreBottom` have shifted up or down.\r\n\r\n\t\tlet firstShownItemIndex\r\n\t\tlet lastShownItemIndex\r\n\r\n\t\t// It's not always required to pass `beforeItemsHeight` parameter:\r\n\t\t// when `fromIndex` is `0`, it's also assumed to be `0`.\r\n\t\tif (fromIndex === 0) {\r\n\t\t\tbeforeItemsHeight = 0\r\n\t\t}\r\n\r\n\t\tif (beforeItemsHeight === undefined) {\r\n\t\t\tthrow new Error('[virtual-scroller] `beforeItemsHeight` not passed to `Layout.getShownItemIndexes()` when starting from index ' + fromIndex);\r\n\t\t}\r\n\r\n\t\t// const backwards = false\r\n\t\t// while (backwards ? i >= 0 : i < itemsCount) {}\r\n\r\n\t\tif (!beforeResize) {\r\n\t\t\tconst beforeResizeItemsCount = this.getBeforeResizeItemsCount()\r\n\t\t\tif (beforeResizeItemsCount > fromIndex) {\r\n\t\t\t\t// First search for the item in \"before resize\" items.\r\n\t\t\t\tconst {\r\n\t\t\t\t\tnotFound,\r\n\t\t\t\t\tbeforeItemsHeight: beforeResizeItemsHeight,\r\n\t\t\t\t\tfirstShownItemIndex,\r\n\t\t\t\t\tlastShownItemIndex\r\n\t\t\t\t} = this._getShownItemIndex({\r\n\t\t\t\t\t...parameters,\r\n\t\t\t\t\tbeforeResize: true,\r\n\t\t\t\t\titemsCount: beforeResizeItemsCount\r\n\t\t\t\t})\r\n\r\n\t\t\t\t// If the item was not found in \"before resize\" items\r\n\t\t\t\t// then search in regular items skipping \"before resize\" ones.\r\n\t\t\t\tif (notFound) {\r\n\t\t\t\t\tbeforeItemsHeight = beforeResizeItemsHeight\r\n\t\t\t\t\tfromIndex += beforeResizeItemsCount\r\n\t\t\t\t} else {\r\n\t\t\t\t\t// If the item was found in \"before resize\" items\r\n\t\t\t\t\t// then return the result.\r\n\t\t\t\t\t// Rebalance first / last shown item indexes based on\r\n\t\t\t\t\t// the current columns count, if required.\r\n\t\t\t\t\tconst columnsCount = this.getColumnsCount()\r\n\t\t\t\t\treturn {\r\n\t\t\t\t\t\tfirstShownItemIndex: firstShownItemIndex === undefined\r\n\t\t\t\t\t\t\t? undefined\r\n\t\t\t\t\t\t\t: Math.floor(firstShownItemIndex / columnsCount) * columnsCount,\r\n\t\t\t\t\t\tlastShownItemIndex: lastShownItemIndex === undefined\r\n\t\t\t\t\t\t\t? undefined\r\n\t\t\t\t\t\t\t: Math.floor(lastShownItemIndex / columnsCount) * columnsCount,\r\n\t\t\t\t\t\tbeforeItemsHeight: beforeResizeItemsHeight\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tconst columnsCount = beforeResize ? this.getColumnsCountBeforeResize() : this.getColumnsCount()\r\n\t\tconst verticalSpacing = beforeResize ? this.getVerticalSpacingBeforeResize() : this.getVerticalSpacing()\r\n\r\n\t\tlet i = fromIndex\r\n\t\twhile (i < itemsCount) {\r\n\t\t\tconst currentRowFirstItemIndex = i\r\n\r\n\t\t\tconst hasMoreRows = itemsCount > currentRowFirstItemIndex + columnsCount\r\n\t\t\tconst verticalSpacingAfterCurrentRow = hasMoreRows ? verticalSpacing : 0\r\n\r\n\t\t\tlet currentRowHeight = 0\r\n\r\n\t\t\t// Calculate current row height.\r\n\t\t\tlet columnIndex = 0\r\n\t\t\twhile (columnIndex < columnsCount && i < itemsCount) {\r\n\t\t\t\tconst itemHeight = beforeResize ? this.getItemHeightBeforeResize(i) : this.getItemHeight(i)\r\n\r\n\t\t\t\t// If this item hasn't been measured yet (or re-measured after a resize)\r\n\t\t\t\t// then mark it as the first non-measured one.\r\n\t\t\t\t//\r\n\t\t\t\t// Can't happen by definition when `beforeResize` parameter is `true`.\r\n\t\t\t\t//\r\n\t\t\t\tif (itemHeight === undefined) {\r\n\t\t\t\t\treturn this.getItemNotMeasuredIndexes(i, {\r\n\t\t\t\t\t\titemsCount,\r\n\t\t\t\t\t\tfirstShownItemIndex: findLastShownItemIndex ? fromIndex : undefined,\r\n\t\t\t\t\t\tindexOfTheFirstItemInTheRow: currentRowFirstItemIndex,\r\n\t\t\t\t\t\tnonMeasuredAreaHeight: (visibleAreaBottom + this.getPrerenderMargin()) - beforeItemsHeight\r\n\t\t\t\t\t})\r\n\t\t\t\t}\r\n\r\n\t\t\t\tcurrentRowHeight = Math.max(currentRowHeight, itemHeight)\r\n\r\n\t\t\t\tcolumnIndex++\r\n\t\t\t\ti++\r\n\t\t\t}\r\n\r\n\t\t\tconst itemsHeightFromFirstRowToThisRow = beforeItemsHeight + currentRowHeight\r\n\r\n\t\t\tconst rowStepsIntoVisibleAreaTop = itemsHeightFromFirstRowToThisRow > visibleAreaTop - this.getPrerenderMargin()\r\n\t\t\tconst rowStepsOutOfVisibleAreaBottomOrIsAtTheBorder = itemsHeightFromFirstRowToThisRow + verticalSpacingAfterCurrentRow >= visibleAreaBottom + this.getPrerenderMargin()\r\n\r\n\t\t\t// if (backwards) {\r\n\t\t\t// \tif (findFirstShownItemIndex) {\r\n\t\t\t// \t\tif (rowStepsOutOfVisibleAreaTop) {\r\n\t\t\t// \t\t\treturn {\r\n\t\t\t// \t\t\t\tfirstShownItemIndex: currentRowFirstItemIndex + columnsCount\r\n\t\t\t// \t\t\t}\r\n\t\t\t// \t\t}\r\n\t\t\t// \t} else if (findLastShownItemIndex) {\r\n\t\t\t// \t\tif (rowStepsIntoVisibleAreaBottom) {\r\n\t\t\t// \t\t\treturn {\r\n\t\t\t// \t\t\t\tlastShownItemIndex: currentRowFirstItemIndex + columnsCount - 1\r\n\t\t\t// \t\t\t}\r\n\t\t\t// \t\t}\r\n\t\t\t// \t}\r\n\t\t\t// }\r\n\r\n\t\t\tif (findFirstShownItemIndex) {\r\n\t\t\t\tif (rowStepsIntoVisibleAreaTop) {\r\n\t\t\t\t\t// If item is the first one visible in the viewport\r\n\t\t\t\t\t// then start showing items from this row.\r\n\t\t\t\t\treturn {\r\n\t\t\t\t\t\tfirstShownItemIndex: currentRowFirstItemIndex,\r\n\t\t\t\t\t\tbeforeItemsHeight\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t} else if (findLastShownItemIndex) {\r\n\t\t\t\tif (rowStepsOutOfVisibleAreaBottomOrIsAtTheBorder) {\r\n\t\t\t\t\treturn {\r\n\t\t\t\t\t\tlastShownItemIndex: Math.min(\r\n\t\t\t\t\t\t\t// The index of the last item in the current row.\r\n\t\t\t\t\t\t\tcurrentRowFirstItemIndex + columnsCount - 1,\r\n\t\t\t\t\t\t\t// Guards against index overflow.\r\n\t\t\t\t\t\t\titemsCount - 1\r\n\t\t\t\t\t\t)\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t}\r\n\r\n\t\t\tbeforeItemsHeight += currentRowHeight + verticalSpacingAfterCurrentRow\r\n\r\n\t\t\t// if (backwards) {\r\n\t\t\t// \t// Set `i` to be the first item of the current row.\r\n\t\t\t// \ti -= columnsCount\r\n\t\t\t// \tconst prevoiusRowIsBeforeResize = i - 1 < this.getBeforeResizeItemsCount()\r\n\t\t\t// \tconst previousRowColumnsCount = prevoiusRowIsBeforeResize ? this.getColumnsCountBeforeResize() : this.getColumnsCount()\r\n\t\t\t// \t// Set `i` to be the first item of the previous row.\r\n\t\t\t// \ti -= previousRowColumnsCount\r\n\t\t\t// }\r\n\t\t}\r\n\r\n\t\t// if (backwards) {\r\n\t\t// \tif (findFirstShownItemIndex) {\r\n\t\t// \t\twarn('The list is supposed to be visible but no visible item has been found (while traversing backwards)')\r\n\t\t// \t\treturn null\r\n\t\t// \t} else if (findLastShownItemIndex) {\r\n\t\t// \t\treturn {\r\n\t\t// \t\t\tfirstShownItemIndex: 0\r\n\t\t// \t\t}\r\n\t\t// \t}\r\n\t\t// }\r\n\r\n\t\tif (beforeResize) {\r\n\t\t\treturn {\r\n\t\t\t\tnotFound: true,\r\n\t\t\t\tbeforeItemsHeight\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\t// This case isn't supposed to happen but it could hypothetically happen\r\n\t\t// because the list height is measured from the user's screen and\r\n\t\t// not necessarily can be trusted.\r\n\t\tif (findFirstShownItemIndex) {\r\n\t\t\twarn('The list is supposed to be visible but no visible item has been found')\r\n\t\t\treturn null\r\n\t\t} else if (findLastShownItemIndex) {\r\n\t\t\treturn {\r\n\t\t\t\tlastShownItemIndex: itemsCount - 1\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\r\n\tgetNonVisibleListShownItemIndexes() {\r\n\t\tconst layout = {\r\n\t\t\tfirstShownItemIndex: 0,\r\n\t\t\tlastShownItemIndex: 0\r\n\t\t}\r\n\t\tif (this.getItemHeight(0) === undefined) {\r\n\t\t\tlayout.firstNonMeasuredItemIndex = 0\r\n\t\t}\r\n\t\treturn layout\r\n\t}\r\n\r\n\t/**\r\n\t * Measures \"before\" items height.\r\n\t * @param {number} beforeItemsCount — Basically, first shown item index.\r\n\t * @return {number}\r\n\t */\r\n\tgetBeforeItemsHeight(\r\n\t\tbeforeItemsCount,\r\n\t\t{ beforeResize } = {}\r\n\t) {\r\n\t\t// This function could potentially also use `this.getPreviouslyCalculatedLayout()`\r\n\t\t// in order to skip calculating visible item indexes from scratch\r\n\t\t// and instead just calculate the difference from a \"previously calculated layout\".\r\n\t\t//\r\n\t\t// I did a simple test in a web browser and found out that running the following\r\n\t\t// piece of code is less than 10 milliseconds:\r\n\t\t//\r\n\t\t// var startedAt = Date.now()\r\n\t\t// var i = 0\r\n\t\t// while (i < 1000000) {\r\n\t\t// i++\r\n\t\t// }\r\n\t\t// console.log(Date.now() - startedAt)\r\n\t\t//\r\n\t\t// Which becomes negligible in my project's use case (a couple thousands items max).\r\n\r\n\t\tlet beforeItemsHeight = 0\r\n\t\tlet i = 0\r\n\r\n\t\tif (!beforeResize) {\r\n\t\t\tconst beforeResizeItemsCount = this.getBeforeResizeItemsCount()\r\n\r\n\t\t\tif (beforeResizeItemsCount > 0) {\r\n\t\t\t\t// First add all \"before resize\" item heights.\r\n\t\t\t\tbeforeItemsHeight = this.getBeforeItemsHeight(\r\n\t\t\t\t\t// `firstShownItemIndex` (called `beforeItemsCount`) could be greater than\r\n\t\t\t\t\t// `beforeResizeItemsCount` when the user scrolls down.\r\n\t\t\t\t\t// `firstShownItemIndex` (called `beforeItemsCount`) could be less than\r\n\t\t\t\t\t// `beforeResizeItemsCount` when the user scrolls up.\r\n\t\t\t\t\tMath.min(beforeItemsCount, beforeResizeItemsCount),\r\n\t\t\t\t\t{ beforeResize: true }\r\n\t\t\t\t)\r\n\t\t\t\ti = beforeResizeItemsCount\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tconst columnsCount = beforeResize ? this.getColumnsCountBeforeResize() : this.getColumnsCount()\r\n\t\tconst verticalSpacing = beforeResize ? this.getVerticalSpacingBeforeResize() : this.getVerticalSpacing()\r\n\r\n\t\twhile (i < beforeItemsCount) {\r\n\t\t\tconst currentRowFirstItemIndex = i\r\n\r\n\t\t\tlet rowHeight = 0\r\n\t\t\tlet columnIndex = 0\r\n\t\t\t// Not checking for `itemsCount` overflow here because `i = beforeItemsCount`\r\n\t\t\t// can only start at the start of a row, meaning that when calculating\r\n\t\t\t// \"before items height\" it's not supposed to add item heights from the\r\n\t\t\t// last row of items because in that case it would have to iterate from\r\n\t\t\t// `i === beforeItemsCount` and that condition is already checked above.\r\n\t\t\t// while (i < itemsCount) {\r\n\t\t\twhile (columnIndex < columnsCount) {\r\n\t\t\t\tlet itemHeight = beforeResize ? this.getItemHeightBeforeResize(i) : this.getItemHeight(i)\r\n\t\t\t\tif (itemHeight === undefined) {\r\n\t\t\t\t\t// `itemHeight` can only be `undefined` when not `beforeResize`.\r\n\t\t\t\t\t// Use the current \"average item height\" as a substitute.\r\n\t\t\t\t\titemHeight = this.getAverageItemHeight()\r\n\t\t\t\t}\r\n\t\t\t\trowHeight = Math.max(rowHeight, itemHeight)\r\n\t\t\t\ti++\r\n\t\t\t\tcolumnIndex++\r\n\t\t\t}\r\n\r\n\t\t\tbeforeItemsHeight += rowHeight\r\n\t\t\tbeforeItemsHeight += verticalSpacing\r\n\t\t}\r\n\r\n\t\treturn beforeItemsHeight\r\n\t}\r\n\r\n\t/**\r\n\t * Measures \"after\" items height.\r\n\t * @param {number} lastShownItemIndex — Last shown item index.\r\n\t * @param {number} itemsCount — Items count.\r\n\t * @return {number}\r\n\t */\r\n\tgetAfterItemsHeight(\r\n\t\tlastShownItemIndex,\r\n\t\titemsCount\r\n\t) {\r\n\t\t// This function could potentially also use `this.getPreviouslyCalculatedLayout()`\r\n\t\t// in order to skip calculating visible item indexes from scratch\r\n\t\t// and instead just calculate the difference from a \"previously calculated layout\".\r\n\t\t//\r\n\t\t// I did a simple test in a web browser and found out that running the following\r\n\t\t// piece of code is less than 10 milliseconds:\r\n\t\t//\r\n\t\t// var startedAt = Date.now()\r\n\t\t// var i = 0\r\n\t\t// while (i < 1000000) {\r\n\t\t// i++\r\n\t\t// }\r\n\t\t// console.log(Date.now() - startedAt)\r\n\t\t//\r\n\t\t// Which becomes negligible in my project's use case (a couple thousands items max).\r\n\r\n\t\tconst columnsCount = this.getColumnsCount()\r\n\t\tconst lastShownRowIndex = Math.floor(lastShownItemIndex / columnsCount)\r\n\r\n\t\tlet afterItemsHeight = 0\r\n\r\n\t\tlet i = lastShownItemIndex + 1\r\n\t\twhile (i < itemsCount) {\r\n\t\t\tlet rowHeight = 0\r\n\t\t\tlet columnIndex = 0\r\n\t\t\twhile (columnIndex < columnsCount && i < itemsCount) {\r\n\t\t\t\tlet itemHeight = this.getItemHeight(i)\r\n\t\t\t\tif (itemHeight === undefined) {\r\n\t\t\t\t\titemHeight = this.getAverageItemHeight()\r\n\t\t\t\t}\r\n\t\t\t\trowHeight = Math.max(rowHeight, itemHeight)\r\n\t\t\t\ti++\r\n\t\t\t\tcolumnIndex++\r\n\t\t\t}\r\n\r\n\t\t\t// Add all \"after\" items height.\r\n\t\t\tafterItemsHeight += this.getVerticalSpacing()\r\n\t\t\tafterItemsHeight += rowHeight\r\n\t\t}\r\n\r\n\t\treturn afterItemsHeight\r\n\t}\r\n\r\n\t/**\r\n\t * Returns the items's top offset relative to the top edge of the first item.\r\n\t * @param {number} i — Item index\r\n\t * @return {[number]} Returns `undefined` if any of the previous items haven't been rendered yet.\r\n\t */\r\n\tgetItemTopOffset(i) {\r\n\t\tlet topOffsetInsideScrollableContainer = 0\r\n\r\n\t\tconst beforeResizeItemsCount = this.getBeforeResizeItemsCount()\r\n\t\tconst beforeResizeRowsCount = beforeResizeItemsCount === 0\r\n\t\t\t? 0\r\n\t\t\t: Math.ceil(beforeResizeItemsCount / this.getColumnsCountBeforeResize())\r\n\r\n\t\tconst maxBeforeResizeRowsCount = i < beforeResizeItemsCount\r\n\t\t\t? Math.floor(i / this.getColumnsCountBeforeResize())\r\n\t\t\t: beforeResizeRowsCount\r\n\r\n\t\tlet beforeResizeRowIndex = 0\r\n\t\twhile (beforeResizeRowIndex < maxBeforeResizeRowsCount) {\r\n\t\t\tconst rowHeight = this.getItemHeightBeforeResize(\r\n\t\t\t\tbeforeResizeRowIndex * this.getColumnsCountBeforeResize()\r\n\t\t\t)\r\n\r\n\t\t\ttopOffsetInsideScrollableContainer += rowHeight\r\n\t\t\ttopOffsetInsideScrollableContainer += this.getVerticalSpacingBeforeResize()\r\n\r\n\t\t\tbeforeResizeRowIndex++\r\n\t\t}\r\n\r\n\t\tconst itemRowIndex = Math.floor((i - beforeResizeItemsCount) / this.getColumnsCount())\r\n\r\n\t\tlet rowIndex = 0\r\n\t\twhile (rowIndex < itemRowIndex) {\r\n\t\t\tlet rowHeight = 0\r\n\t\t\tlet columnIndex = 0\r\n\t\t\twhile (columnIndex < this.getColumnsCount()) {\r\n\t\t\t\tconst itemHeight = this.getItemHeight(\r\n\t\t\t\t\tbeforeResizeItemsCount + rowIndex * this.getColumnsCount() + columnIndex\r\n\t\t\t\t)\r\n\t\t\t\tif (itemHeight === undefined) {\r\n\t\t\t\t\treturn\r\n\t\t\t\t}\r\n\t\t\t\trowHeight = Math.max(rowHeight, itemHeight)\r\n\t\t\t\tcolumnIndex++\r\n\t\t\t}\r\n\r\n\t\t\ttopOffsetInsideScrollableContainer += rowHeight\r\n\t\t\ttopOffsetInsideScrollableContainer += this.getVerticalSpacing()\r\n\r\n\t\t\trowIndex++\r\n\t\t}\r\n\r\n\t\treturn topOffsetInsideScrollableContainer\r\n\t}\r\n}\r\n\r\nexport const LAYOUT_REASON = {\r\n\tSCROLL: 'scroll',\r\n\tSTOPPED_SCROLLING: 'stopped scrolling',\r\n\tMANUAL: 'manual',\r\n\tMOUNTED: 'mounted',\r\n\tACTUAL_ITEM_HEIGHTS_HAVE_BEEN_MEASURED: 'actual item heights have been measured',\r\n\tVIEWPORT_WIDTH_CHANGED: 'viewport width changed',\r\n\tVIEWPORT_HEIGHT_CHANGED: 'viewport height changed',\r\n\tVIEWPORT_SIZE_UNCHANGED: 'viewport size unchanged',\r\n\tITEM_HEIGHT_CHANGED: 'item height changed',\r\n\tITEMS_CHANGED: 'items changed',\r\n\tTOP_OFFSET_CHANGED: 'list top offset changed'\r\n}"],"file":"Layout.js"}
|
|
1
|
+
{"version":3,"file":"Layout.js","names":["log","warn","Layout","bypass","estimatedItemHeight","measureItemsBatchSize","getPrerenderMargin","getVerticalSpacing","getVerticalSpacingBeforeResize","getColumnsCount","getColumnsCountBeforeResize","getItemHeight","getItemHeightBeforeResize","getBeforeResizeItemsCount","getAverageItemHeight","getMaxVisibleAreaHeight","getPreviouslyCalculatedLayout","itemsCount","columnsCount","firstShownItemIndex","lastShownItemIndex","getInitialLastShownItemIndex","beforeItemsHeight","afterItemsHeight","estimatedRowsCount","getEstimatedRowsCountForHeight","Math","min","height","getEstimatedItemHeight","verticalSpacing","ceil","prependedItemsCount","appendedItemsCount","shouldRestoreScrollPosition","onResetGridLayout","averageItemHeight","appendedRowsCount","addedHeightAfter","prependedRowsCount","addedHeightBefore","shownItemsCountBeforeItemsUpdate","afterItemsCount","i","nonMeasuredAreaHeight","indexOfTheFirstItemInTheRow","itemsCountToRenderForMeasurement","Infinity","undefined","firstNonMeasuredItemIndex","visibleAreaTop","visibleAreaBottom","indexes","_getShownItemIndex","fromIndex","findFirstShownItemIndex","getNonVisibleListShownItemIndexes","findLastShownItemIndex","parameters","beforeResize","Error","beforeResizeItemsCount","notFound","beforeResizeItemsHeight","floor","currentRowFirstItemIndex","hasMoreRows","verticalSpacingAfterCurrentRow","currentRowHeight","columnIndex","itemHeight","getItemNotMeasuredIndexes","max","itemsHeightFromFirstRowToThisRow","rowStepsIntoVisibleAreaTop","rowStepsOutOfVisibleAreaBottomOrIsAtTheBorder","layout","beforeItemsCount","getBeforeItemsHeight","rowHeight","lastShownRowIndex","topOffsetInsideScrollableContainer","beforeResizeRowsCount","maxBeforeResizeRowsCount","beforeResizeRowIndex","itemRowIndex","rowIndex","LAYOUT_REASON","SCROLL","STOPPED_SCROLLING","MANUAL","STARTED","NON_MEASURED_ITEMS_HAVE_BEEN_MEASURED","VIEWPORT_WIDTH_CHANGED","VIEWPORT_HEIGHT_CHANGED","VIEWPORT_SIZE_UNCHANGED","ITEM_HEIGHT_CHANGED","ITEMS_CHANGED","TOP_OFFSET_CHANGED"],"sources":["../source/Layout.js"],"sourcesContent":["import log, { warn } from './utility/debug.js'\r\n\r\nexport default class Layout {\r\n\tconstructor({\r\n\t\tbypass,\r\n\t\testimatedItemHeight,\r\n\t\tmeasureItemsBatchSize,\r\n\t\tgetPrerenderMargin,\r\n\t\tgetVerticalSpacing,\r\n\t\tgetVerticalSpacingBeforeResize,\r\n\t\tgetColumnsCount,\r\n\t\tgetColumnsCountBeforeResize,\r\n\t\tgetItemHeight,\r\n\t\tgetItemHeightBeforeResize,\r\n\t\tgetBeforeResizeItemsCount,\r\n\t\tgetAverageItemHeight,\r\n\t\tgetMaxVisibleAreaHeight,\r\n\t\tgetPreviouslyCalculatedLayout\r\n\t}) {\r\n\t\tthis.bypass = bypass\r\n\t\tthis.estimatedItemHeight = estimatedItemHeight\r\n\t\tthis.measureItemsBatchSize = measureItemsBatchSize\r\n\t\tthis.getPrerenderMargin = getPrerenderMargin\r\n\t\tthis.getVerticalSpacing = getVerticalSpacing\r\n\t\tthis.getVerticalSpacingBeforeResize = getVerticalSpacingBeforeResize\r\n\t\tthis.getColumnsCount = getColumnsCount\r\n\t\tthis.getColumnsCountBeforeResize = getColumnsCountBeforeResize\r\n\t\tthis.getItemHeight = getItemHeight\r\n\t\tthis.getItemHeightBeforeResize = getItemHeightBeforeResize\r\n\t\tthis.getBeforeResizeItemsCount = getBeforeResizeItemsCount\r\n\t\tthis.getAverageItemHeight = getAverageItemHeight\r\n\t\tthis.getMaxVisibleAreaHeight = getMaxVisibleAreaHeight\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\tthis.getPreviouslyCalculatedLayout = getPreviouslyCalculatedLayout\r\n\t}\r\n\r\n\tgetInitialLayoutValues({\r\n\t\titemsCount,\r\n\t\tcolumnsCount\r\n\t}) {\r\n\t\tlet firstShownItemIndex\r\n\t\tlet lastShownItemIndex\r\n\t\t// If there're no items then `firstShownItemIndex` stays `undefined`.\r\n\t\tif (itemsCount > 0) {\r\n\t\t\tfirstShownItemIndex = 0\r\n\t\t\tlastShownItemIndex = this.getInitialLastShownItemIndex({\r\n\t\t\t\titemsCount,\r\n\t\t\t\tcolumnsCount,\r\n\t\t\t\tfirstShownItemIndex\r\n\t\t\t})\r\n\t\t}\r\n\t\treturn {\r\n\t\t\tbeforeItemsHeight: 0,\r\n\t\t\tafterItemsHeight: 0,\r\n\t\t\tfirstShownItemIndex,\r\n\t\t\tlastShownItemIndex\r\n\t\t}\r\n\t}\r\n\r\n\tgetInitialLastShownItemIndex({\r\n\t\titemsCount,\r\n\t\tcolumnsCount,\r\n\t\tfirstShownItemIndex\r\n\t}) {\r\n\t\tif (this.bypass) {\r\n\t\t\treturn itemsCount - 1\r\n\t\t}\r\n\t\t// On server side, at initialization time,\r\n\t\t// `scrollableContainer` is `undefined`,\r\n\t\t// so default to `1` estimated rows count.\r\n\t\tlet estimatedRowsCount = 1\r\n\t\tif (this.getMaxVisibleAreaHeight()) {\r\n\t\t\testimatedRowsCount = this.getEstimatedRowsCountForHeight(this.getMaxVisibleAreaHeight() + this.getPrerenderMargin())\r\n\t\t}\r\n\t\treturn Math.min(\r\n\t\t\tfirstShownItemIndex + (estimatedRowsCount * columnsCount - 1),\r\n\t\t\titemsCount - 1\r\n\t\t)\r\n\t}\r\n\r\n\tgetEstimatedRowsCountForHeight(height) {\r\n\t\tconst estimatedItemHeight = this.getEstimatedItemHeight()\r\n\t\tconst verticalSpacing = this.getVerticalSpacing()\r\n\t\tif (estimatedItemHeight) {\r\n\t\t\treturn Math.ceil((height + verticalSpacing) / (estimatedItemHeight + verticalSpacing))\r\n\t\t} else {\r\n\t\t\t// If no items have been rendered yet, and no `estimatedItemHeight` option\r\n\t\t\t// has been passed, then default to `1` estimated rows count in any `height`.\r\n\t\t\treturn 1\r\n\t\t}\r\n\t}\r\n\r\n\t/**\r\n\t * Returns estimated list item height.\r\n\t * (depends on which items have been previously rendered and measured).\r\n\t * @return {number}\r\n\t */\r\n\tgetEstimatedItemHeight() {\r\n\t\treturn this.getAverageItemHeight() || this.estimatedItemHeight || 0\r\n\t}\r\n\r\n\tgetLayoutUpdateForItemsDiff({\r\n\t\tfirstShownItemIndex,\r\n\t\tlastShownItemIndex,\r\n\t\tbeforeItemsHeight,\r\n\t\tafterItemsHeight\r\n\t}, {\r\n\t\tprependedItemsCount,\r\n\t\tappendedItemsCount\r\n\t}, {\r\n\t\titemsCount,\r\n\t\tcolumnsCount,\r\n\t\tshouldRestoreScrollPosition,\r\n\t\tonResetGridLayout\r\n\t}) {\r\n\t\t// const layoutUpdate = {}\r\n\r\n\t\t// If the layout stays the same, then simply increase\r\n\t\t// the top and bottom margins proportionally to the amount\r\n\t\t// of the items added.\r\n\t\tconst averageItemHeight = this.getAverageItemHeight()\r\n\t\tconst verticalSpacing = this.getVerticalSpacing()\r\n\r\n\t\tif (appendedItemsCount > 0) {\r\n\t\t\tconst appendedRowsCount = Math.ceil(appendedItemsCount / columnsCount)\r\n\t\t\tconst addedHeightAfter = appendedRowsCount * (verticalSpacing + averageItemHeight)\r\n\r\n\t\t\tafterItemsHeight += addedHeightAfter\r\n\r\n\t\t\t// layoutUpdate = {\r\n\t\t\t// \t...layoutUpdate,\r\n\t\t\t// \tafterItemsHeight\r\n\t\t\t// }\r\n\t\t}\r\n\r\n\t\tif (prependedItemsCount > 0) {\r\n\t\t\tconst prependedRowsCount = Math.ceil(prependedItemsCount / columnsCount)\r\n\t\t\tconst addedHeightBefore = prependedRowsCount * (averageItemHeight + verticalSpacing)\r\n\r\n\t\t\tfirstShownItemIndex += prependedItemsCount\r\n\t\t\tlastShownItemIndex += prependedItemsCount\r\n\t\t\tbeforeItemsHeight += addedHeightBefore\r\n\r\n\t\t\t// If the currently shown items position on screen should be preserved\r\n\t\t\t// when prepending new items, then it means that:\r\n\t\t\t// * The current scroll position should be snapshotted.\r\n\t\t\t// * The current list height should be snapshotted.\r\n\t\t\t// * All prepended items should be shown so that their height could be\r\n\t\t\t// measured after they're rendered. Based on the prepended items' height,\r\n\t\t\t// the scroll position will be restored so that there's no \"jump of content\".\r\n\t\t\tif (shouldRestoreScrollPosition) {\r\n\t\t\t\tfirstShownItemIndex = 0\r\n\t\t\t\tbeforeItemsHeight = 0\r\n\t\t\t}\r\n\r\n\t\t\tif (prependedItemsCount % columnsCount > 0) {\r\n\t\t\t\t// Rows will be rebalanced as a result of prepending new items,\r\n\t\t\t\t// and row heights can change as a result, so re-layout items\r\n\t\t\t\t// after they've been measured (after the upcoming re-render).\r\n\t\t\t\t//\r\n\t\t\t\t// For example, consider a web page where item rows are `display: flex`.\r\n\t\t\t\t// Suppose there're 3 columns and it shows items from 4 to 6.\r\n\t\t\t\t//\r\n\t\t\t\t// ------------------------------------------\r\n\t\t\t\t// | Apples are | Bananas | Cranberries |\r\n\t\t\t\t// | green | | |\r\n\t\t\t\t// ------------------------------------------\r\n\t\t\t\t// | Dates | Elderberry | Figs are |\r\n\t\t\t\t// | | | tasty |\r\n\t\t\t\t// ------------------------------------------\r\n\t\t\t\t//\r\n\t\t\t\t// Now, 1 item gets prepended. As a result, all existing rows will have\r\n\t\t\t\t// a different set of items, which means that the row heights will change.\r\n\t\t\t\t//\r\n\t\t\t\t// ------------------------------------------\r\n\t\t\t\t// | Zucchini | Apples are | Bananas |\r\n\t\t\t\t// | | green | |\r\n\t\t\t\t// ------------------------------------------\r\n\t\t\t\t// | Cranberries | Dates | Elderberry |\r\n\t\t\t\t// ------------------------------------------\r\n\t\t\t\t// | Figs |\r\n\t\t\t\t// | are tasty |\r\n\t\t\t\t// ---------------\r\n\t\t\t\t//\r\n\t\t\t\t// As it can be seen above, the second row's height has changed from 2 to 1.\r\n\t\t\t\t// Not only that, but `itemHeights` have changed as well, so if you thought\r\n\t\t\t\t// that the library could easily recalculate row heights using `Math.max()` — \r\n\t\t\t\t// turns out it's not always the case.\r\n\t\t\t\t//\r\n\t\t\t\t// There could be an explicit opt-in option for automatically recalculating\r\n\t\t\t\t// row heights, but I don't want to write code for such an extremely rare\r\n\t\t\t\t// use case. Instead, use the `getColumnsCount()` parameter function when\r\n\t\t\t\t// fetching previous items.\r\n\r\n\t\t\t\tonResetGridLayout()\r\n\r\n\t\t\t\twarn('~ Prepended items count', prependedItemsCount, 'is not divisible by Columns Count', columnsCount, '~')\r\n\t\t\t\twarn('Layout reset required')\r\n\r\n\t\t\t\tconst shownItemsCountBeforeItemsUpdate = lastShownItemIndex - firstShownItemIndex + 1\r\n\r\n\t\t\t\tfirstShownItemIndex = 0\r\n\t\t\t\tbeforeItemsHeight = 0\r\n\r\n\t\t\t\tif (!shouldRestoreScrollPosition) {\r\n\t\t\t\t\t// Limit shown items count if too many items have been prepended.\r\n\t\t\t\t\tif (prependedItemsCount > shownItemsCountBeforeItemsUpdate) {\r\n\t\t\t\t\t\tlastShownItemIndex = this.getInitialLastShownItemIndex({\r\n\t\t\t\t\t\t\titemsCount,\r\n\t\t\t\t\t\t\tcolumnsCount,\r\n\t\t\t\t\t\t\tfirstShownItemIndex\r\n\t\t\t\t\t\t})\r\n\r\n\t\t\t\t\t\t// Approximate `afterItemsHeight` calculation.\r\n\t\t\t\t\t\tconst afterItemsCount = itemsCount - (lastShownItemIndex + 1)\r\n\t\t\t\t\t\tafterItemsHeight = Math.ceil(afterItemsCount / columnsCount) * (verticalSpacing + averageItemHeight)\r\n\r\n\t\t\t\t\t\t// layoutUpdate = {\r\n\t\t\t\t\t\t// \t...layoutUpdate,\r\n\t\t\t\t\t\t// \tafterItemsHeight\r\n\t\t\t\t\t\t// }\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t}\r\n\r\n\t\t\t// layoutUpdate = {\r\n\t\t\t// \t...layoutUpdate,\r\n\t\t\t// \tbeforeItemsHeight,\r\n\t\t\t// \tfirstShownItemIndex,\r\n\t\t\t// \tlastShownItemIndex\r\n\t\t\t// }\r\n\t\t}\r\n\r\n\t\t// return layoutUpdate\r\n\r\n\t\t// Overwrite all four props in all scenarios.\r\n\t\t// The reason is that only this way subsequent `setItems()` calls\r\n\t\t// will be truly \"stateless\" when a chain of `setItems()` calls\r\n\t\t// could be replaced with just the last one in a scenario when\r\n\t\t// `updateState()` calls are \"asynchronous\" (delayed execution).\r\n\t\t//\r\n\t\t// So, for example, the user calls `setItems()` with one set of items.\r\n\t\t// A `updateState()` call has been dispatched but the `state` hasn't been updated yet.\r\n\t\t// Then the user calls `setItems()` with another set of items.\r\n\t\t// If this function only returned a minimal set of properties that actually change,\r\n\t\t// the other layout properties of the second `setItems()` call wouldn't overwrite the ones\r\n\t\t// scheduled for update during the first `setItems()` call, resulting in an inconsistent `state`.\r\n\t\t//\r\n\t\t// For example, the first `setItems()` call does a `updateState()` call where it updates\r\n\t\t// `afterItemsHeight`, and then the second `setItems()` call only updates `beforeItemsHeight`\r\n\t\t// and `firstShownItemIndex` and `lastShownItemIndex`. If the second `setItems()` call was to\r\n\t\t// overwrite any effects of the pending-but-not-yet-applied first `setItems()` call, it would\r\n\t\t// have to call `updateState()` with an `afterItemsHeight` property too, even though it hasn't change.\r\n\t\t// That would be just to revert the change to `afterItemsHeight` state property already scheduled\r\n\t\t// by the first `setItems()` call.\r\n\t\t//\r\n\t\treturn {\r\n\t\t\tbeforeItemsHeight,\r\n\t\t\tafterItemsHeight,\r\n\t\t\tfirstShownItemIndex,\r\n\t\t\tlastShownItemIndex\r\n\t\t}\r\n\t}\r\n\r\n\t// If an item that hasn't been shown (and measured) yet is encountered\r\n\t// then show such item and then retry after it has been measured.\r\n\tgetItemNotMeasuredIndexes(i, {\r\n\t\titemsCount,\r\n\t\tfirstShownItemIndex,\r\n\t\tnonMeasuredAreaHeight,\r\n\t\tindexOfTheFirstItemInTheRow\r\n\t}) {\r\n\t\tlog('Item index', i, 'height is required for calculations but hasn\\'t been measured yet. Mark the item as \"shown\", rerender the list, measure the item\\'s height and redo the layout.')\r\n\r\n\t\tconst columnsCount = this.getColumnsCount()\r\n\r\n\t\tconst itemsCountToRenderForMeasurement = Math.min(\r\n\t\t\tthis.getEstimatedRowsCountForHeight(nonMeasuredAreaHeight) * columnsCount,\r\n\t\t\tthis.measureItemsBatchSize || Infinity,\r\n\t\t)\r\n\r\n\t\tif (firstShownItemIndex === undefined) {\r\n\t\t\tfirstShownItemIndex = indexOfTheFirstItemInTheRow\r\n\t\t}\r\n\r\n\t\tconst lastShownItemIndex = Math.min(\r\n\t\t\tindexOfTheFirstItemInTheRow + itemsCountToRenderForMeasurement - 1,\r\n\t\t\t// Guard against index overflow.\r\n\t\t\titemsCount - 1\r\n\t\t)\r\n\r\n\t\treturn {\r\n\t\t\tfirstNonMeasuredItemIndex: i,\r\n\t\t\tfirstShownItemIndex,\r\n\t\t\tlastShownItemIndex\r\n\t\t}\r\n\t}\r\n\r\n\t/**\r\n\t * Finds the indexes of the currently visible items.\r\n\t * @return {object} `{ firstShownItemIndex: number, lastShownItemIndex: number, firstNonMeasuredItemIndex: number? }`\r\n\t */\r\n\tgetShownItemIndexes({\r\n\t\titemsCount,\r\n\t\tvisibleAreaTop,\r\n\t\tvisibleAreaBottom\r\n\t}) {\r\n\t\tlet indexes = this._getShownItemIndex({\r\n\t\t\titemsCount,\r\n\t\t\tfromIndex: 0,\r\n\t\t\tvisibleAreaTop,\r\n\t\t\tvisibleAreaBottom,\r\n\t\t\tfindFirstShownItemIndex: true\r\n\t\t})\r\n\r\n\t\tif (indexes === null) {\r\n\t\t\treturn this.getNonVisibleListShownItemIndexes()\r\n\t\t}\r\n\r\n\t\tif (indexes.firstNonMeasuredItemIndex !== undefined) {\r\n\t\t\treturn indexes\r\n\t\t}\r\n\r\n\t\tconst { firstShownItemIndex, beforeItemsHeight } = indexes\r\n\r\n\t\tindexes = this._getShownItemIndex({\r\n\t\t\titemsCount,\r\n\t\t\tfromIndex: firstShownItemIndex,\r\n\t\t\tbeforeItemsHeight,\r\n\t\t\tvisibleAreaTop,\r\n\t\t\tvisibleAreaBottom,\r\n\t\t\tfindLastShownItemIndex: true\r\n\t\t})\r\n\r\n\t\tif (indexes === null) {\r\n\t\t\treturn this.getNonVisibleListShownItemIndexes()\r\n\t\t}\r\n\r\n\t\tif (indexes.firstNonMeasuredItemIndex !== undefined) {\r\n\t\t\treturn indexes\r\n\t\t}\r\n\r\n\t\tconst { lastShownItemIndex } = indexes\r\n\r\n\t\treturn {\r\n\t\t\tfirstShownItemIndex,\r\n\t\t\tlastShownItemIndex\r\n\t\t}\r\n\t}\r\n\r\n\t_getShownItemIndex(parameters) {\r\n\t\tconst {\r\n\t\t\tbeforeResize,\r\n\t\t\titemsCount,\r\n\t\t\tvisibleAreaTop,\r\n\t\t\tvisibleAreaBottom,\r\n\t\t\tfindFirstShownItemIndex,\r\n\t\t\tfindLastShownItemIndex,\r\n\t\t\t// backwards\r\n\t\t} = parameters\r\n\r\n\t\tlet {\r\n\t\t\tfromIndex,\r\n\t\t\tbeforeItemsHeight\r\n\t\t} = parameters\r\n\r\n\t\t// This function could potentially also use `this.getPreviouslyCalculatedLayout()`\r\n\t\t// in order to skip calculating visible item indexes from scratch\r\n\t\t// and instead just calculate the difference from a \"previously calculated layout\".\r\n\t\t//\r\n\t\t// I did a simple test in a web browser and found out that running the following\r\n\t\t// piece of code is less than 10 milliseconds:\r\n\t\t//\r\n\t\t// var startedAt = Date.now()\r\n\t\t// var i = 0\r\n\t\t// while (i < 1000000) {\r\n\t\t// i++\r\n\t\t// }\r\n\t\t// console.log(Date.now() - startedAt)\r\n\t\t//\r\n\t\t// Which becomes negligible in my project's use case (a couple thousands items max).\r\n\t\t//\r\n\t\t// If someone would attempt to use a \"previously calculated layout\" here\r\n\t\t// then `shownItemsHeight` would also have to be returned from this function:\r\n\t\t// the total height of all shown items including vertical spacing between them.\r\n\t\t//\r\n\t\t// If \"previously calculated layout\" would be used then it would first find\r\n\t\t// `firstShownItemIndex` and then find `lastShownItemIndex` as part of two\r\n\t\t// separate calls of this function, each with or without `backwards` flag,\r\n\t\t// depending on whether `visibleAreaTop` and `visibleAreBottom` have shifted up or down.\r\n\r\n\t\tlet firstShownItemIndex\r\n\t\tlet lastShownItemIndex\r\n\r\n\t\t// It's not always required to pass `beforeItemsHeight` parameter:\r\n\t\t// when `fromIndex` is `0`, it's also assumed to be `0`.\r\n\t\tif (fromIndex === 0) {\r\n\t\t\tbeforeItemsHeight = 0\r\n\t\t}\r\n\r\n\t\tif (beforeItemsHeight === undefined) {\r\n\t\t\tthrow new Error('[virtual-scroller] `beforeItemsHeight` not passed to `Layout.getShownItemIndexes()` when starting from index ' + fromIndex);\r\n\t\t}\r\n\r\n\t\t// const backwards = false\r\n\t\t// while (backwards ? i >= 0 : i < itemsCount) {}\r\n\r\n\t\tif (!beforeResize) {\r\n\t\t\tconst beforeResizeItemsCount = this.getBeforeResizeItemsCount()\r\n\t\t\tif (beforeResizeItemsCount > fromIndex) {\r\n\t\t\t\t// First search for the item in \"before resize\" items.\r\n\t\t\t\tconst {\r\n\t\t\t\t\tnotFound,\r\n\t\t\t\t\tbeforeItemsHeight: beforeResizeItemsHeight,\r\n\t\t\t\t\tfirstShownItemIndex,\r\n\t\t\t\t\tlastShownItemIndex\r\n\t\t\t\t} = this._getShownItemIndex({\r\n\t\t\t\t\t...parameters,\r\n\t\t\t\t\tbeforeResize: true,\r\n\t\t\t\t\titemsCount: beforeResizeItemsCount\r\n\t\t\t\t})\r\n\r\n\t\t\t\t// If the item was not found in \"before resize\" items\r\n\t\t\t\t// then search in regular items skipping \"before resize\" ones.\r\n\t\t\t\tif (notFound) {\r\n\t\t\t\t\tbeforeItemsHeight = beforeResizeItemsHeight\r\n\t\t\t\t\tfromIndex += beforeResizeItemsCount\r\n\t\t\t\t} else {\r\n\t\t\t\t\t// If the item was found in \"before resize\" items\r\n\t\t\t\t\t// then return the result.\r\n\t\t\t\t\t// Rebalance first / last shown item indexes based on\r\n\t\t\t\t\t// the current columns count, if required.\r\n\t\t\t\t\tconst columnsCount = this.getColumnsCount()\r\n\t\t\t\t\treturn {\r\n\t\t\t\t\t\tfirstShownItemIndex: firstShownItemIndex === undefined\r\n\t\t\t\t\t\t\t? undefined\r\n\t\t\t\t\t\t\t: Math.floor(firstShownItemIndex / columnsCount) * columnsCount,\r\n\t\t\t\t\t\tlastShownItemIndex: lastShownItemIndex === undefined\r\n\t\t\t\t\t\t\t? undefined\r\n\t\t\t\t\t\t\t: Math.floor(lastShownItemIndex / columnsCount) * columnsCount,\r\n\t\t\t\t\t\tbeforeItemsHeight: beforeResizeItemsHeight\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tconst columnsCount = beforeResize ? this.getColumnsCountBeforeResize() : this.getColumnsCount()\r\n\t\tconst verticalSpacing = beforeResize ? this.getVerticalSpacingBeforeResize() : this.getVerticalSpacing()\r\n\r\n\t\tlet i = fromIndex\r\n\t\twhile (i < itemsCount) {\r\n\t\t\tconst currentRowFirstItemIndex = i\r\n\r\n\t\t\tconst hasMoreRows = itemsCount > currentRowFirstItemIndex + columnsCount\r\n\t\t\tconst verticalSpacingAfterCurrentRow = hasMoreRows ? verticalSpacing : 0\r\n\r\n\t\t\tlet currentRowHeight = 0\r\n\r\n\t\t\t// Calculate current row height.\r\n\t\t\tlet columnIndex = 0\r\n\t\t\twhile (columnIndex < columnsCount && i < itemsCount) {\r\n\t\t\t\tconst itemHeight = beforeResize ? this.getItemHeightBeforeResize(i) : this.getItemHeight(i)\r\n\r\n\t\t\t\t// If this item hasn't been measured yet (or re-measured after a resize)\r\n\t\t\t\t// then mark it as the first non-measured one.\r\n\t\t\t\t//\r\n\t\t\t\t// Can't happen by definition when `beforeResize` parameter is `true`.\r\n\t\t\t\t//\r\n\t\t\t\tif (itemHeight === undefined) {\r\n\t\t\t\t\treturn this.getItemNotMeasuredIndexes(i, {\r\n\t\t\t\t\t\titemsCount,\r\n\t\t\t\t\t\tfirstShownItemIndex: findLastShownItemIndex ? fromIndex : undefined,\r\n\t\t\t\t\t\tindexOfTheFirstItemInTheRow: currentRowFirstItemIndex,\r\n\t\t\t\t\t\tnonMeasuredAreaHeight: (visibleAreaBottom + this.getPrerenderMargin()) - beforeItemsHeight\r\n\t\t\t\t\t})\r\n\t\t\t\t}\r\n\r\n\t\t\t\tcurrentRowHeight = Math.max(currentRowHeight, itemHeight)\r\n\r\n\t\t\t\tcolumnIndex++\r\n\t\t\t\ti++\r\n\t\t\t}\r\n\r\n\t\t\tconst itemsHeightFromFirstRowToThisRow = beforeItemsHeight + currentRowHeight\r\n\r\n\t\t\tconst rowStepsIntoVisibleAreaTop = itemsHeightFromFirstRowToThisRow > visibleAreaTop - this.getPrerenderMargin()\r\n\t\t\tconst rowStepsOutOfVisibleAreaBottomOrIsAtTheBorder = itemsHeightFromFirstRowToThisRow + verticalSpacingAfterCurrentRow >= visibleAreaBottom + this.getPrerenderMargin()\r\n\r\n\t\t\t// if (backwards) {\r\n\t\t\t// \tif (findFirstShownItemIndex) {\r\n\t\t\t// \t\tif (rowStepsOutOfVisibleAreaTop) {\r\n\t\t\t// \t\t\treturn {\r\n\t\t\t// \t\t\t\tfirstShownItemIndex: currentRowFirstItemIndex + columnsCount\r\n\t\t\t// \t\t\t}\r\n\t\t\t// \t\t}\r\n\t\t\t// \t} else if (findLastShownItemIndex) {\r\n\t\t\t// \t\tif (rowStepsIntoVisibleAreaBottom) {\r\n\t\t\t// \t\t\treturn {\r\n\t\t\t// \t\t\t\tlastShownItemIndex: currentRowFirstItemIndex + columnsCount - 1\r\n\t\t\t// \t\t\t}\r\n\t\t\t// \t\t}\r\n\t\t\t// \t}\r\n\t\t\t// }\r\n\r\n\t\t\tif (findFirstShownItemIndex) {\r\n\t\t\t\tif (rowStepsIntoVisibleAreaTop) {\r\n\t\t\t\t\t// If item is the first one visible in the viewport\r\n\t\t\t\t\t// then start showing items from this row.\r\n\t\t\t\t\treturn {\r\n\t\t\t\t\t\tfirstShownItemIndex: currentRowFirstItemIndex,\r\n\t\t\t\t\t\tbeforeItemsHeight\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t} else if (findLastShownItemIndex) {\r\n\t\t\t\tif (rowStepsOutOfVisibleAreaBottomOrIsAtTheBorder) {\r\n\t\t\t\t\treturn {\r\n\t\t\t\t\t\tlastShownItemIndex: Math.min(\r\n\t\t\t\t\t\t\t// The index of the last item in the current row.\r\n\t\t\t\t\t\t\tcurrentRowFirstItemIndex + columnsCount - 1,\r\n\t\t\t\t\t\t\t// Guards against index overflow.\r\n\t\t\t\t\t\t\titemsCount - 1\r\n\t\t\t\t\t\t)\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t}\r\n\r\n\t\t\tbeforeItemsHeight += currentRowHeight + verticalSpacingAfterCurrentRow\r\n\r\n\t\t\t// if (backwards) {\r\n\t\t\t// \t// Set `i` to be the first item of the current row.\r\n\t\t\t// \ti -= columnsCount\r\n\t\t\t// \tconst prevoiusRowIsBeforeResize = i - 1 < this.getBeforeResizeItemsCount()\r\n\t\t\t// \tconst previousRowColumnsCount = prevoiusRowIsBeforeResize ? this.getColumnsCountBeforeResize() : this.getColumnsCount()\r\n\t\t\t// \t// Set `i` to be the first item of the previous row.\r\n\t\t\t// \ti -= previousRowColumnsCount\r\n\t\t\t// }\r\n\t\t}\r\n\r\n\t\t// if (backwards) {\r\n\t\t// \tif (findFirstShownItemIndex) {\r\n\t\t// \t\twarn('The list is supposed to be visible but no visible item has been found (while traversing backwards)')\r\n\t\t// \t\treturn null\r\n\t\t// \t} else if (findLastShownItemIndex) {\r\n\t\t// \t\treturn {\r\n\t\t// \t\t\tfirstShownItemIndex: 0\r\n\t\t// \t\t}\r\n\t\t// \t}\r\n\t\t// }\r\n\r\n\t\tif (beforeResize) {\r\n\t\t\treturn {\r\n\t\t\t\tnotFound: true,\r\n\t\t\t\tbeforeItemsHeight\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\t// This case isn't supposed to happen but it could hypothetically happen\r\n\t\t// because the list height is measured from the user's screen and\r\n\t\t// not necessarily can be trusted.\r\n\t\tif (findFirstShownItemIndex) {\r\n\t\t\twarn('The list is supposed to be visible but no visible item has been found')\r\n\t\t\treturn null\r\n\t\t} else if (findLastShownItemIndex) {\r\n\t\t\treturn {\r\n\t\t\t\tlastShownItemIndex: itemsCount - 1\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\r\n\tgetNonVisibleListShownItemIndexes() {\r\n\t\tconst layout = {\r\n\t\t\tfirstShownItemIndex: 0,\r\n\t\t\tlastShownItemIndex: 0\r\n\t\t}\r\n\t\tif (this.getItemHeight(0) === undefined) {\r\n\t\t\tlayout.firstNonMeasuredItemIndex = 0\r\n\t\t}\r\n\t\treturn layout\r\n\t}\r\n\r\n\t/**\r\n\t * Measures \"before\" items height.\r\n\t * @param {number} beforeItemsCount — Basically, first shown item index.\r\n\t * @return {number}\r\n\t */\r\n\tgetBeforeItemsHeight(\r\n\t\tbeforeItemsCount,\r\n\t\t{ beforeResize } = {}\r\n\t) {\r\n\t\t// This function could potentially also use `this.getPreviouslyCalculatedLayout()`\r\n\t\t// in order to skip calculating visible item indexes from scratch\r\n\t\t// and instead just calculate the difference from a \"previously calculated layout\".\r\n\t\t//\r\n\t\t// I did a simple test in a web browser and found out that running the following\r\n\t\t// piece of code is less than 10 milliseconds:\r\n\t\t//\r\n\t\t// var startedAt = Date.now()\r\n\t\t// var i = 0\r\n\t\t// while (i < 1000000) {\r\n\t\t// i++\r\n\t\t// }\r\n\t\t// console.log(Date.now() - startedAt)\r\n\t\t//\r\n\t\t// Which becomes negligible in my project's use case (a couple thousands items max).\r\n\r\n\t\tlet beforeItemsHeight = 0\r\n\t\tlet i = 0\r\n\r\n\t\tif (!beforeResize) {\r\n\t\t\tconst beforeResizeItemsCount = this.getBeforeResizeItemsCount()\r\n\r\n\t\t\tif (beforeResizeItemsCount > 0) {\r\n\t\t\t\t// First add all \"before resize\" item heights.\r\n\t\t\t\tbeforeItemsHeight = this.getBeforeItemsHeight(\r\n\t\t\t\t\t// `firstShownItemIndex` (called `beforeItemsCount`) could be greater than\r\n\t\t\t\t\t// `beforeResizeItemsCount` when the user scrolls down.\r\n\t\t\t\t\t// `firstShownItemIndex` (called `beforeItemsCount`) could be less than\r\n\t\t\t\t\t// `beforeResizeItemsCount` when the user scrolls up.\r\n\t\t\t\t\tMath.min(beforeItemsCount, beforeResizeItemsCount),\r\n\t\t\t\t\t{ beforeResize: true }\r\n\t\t\t\t)\r\n\t\t\t\ti = beforeResizeItemsCount\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tconst columnsCount = beforeResize ? this.getColumnsCountBeforeResize() : this.getColumnsCount()\r\n\t\tconst verticalSpacing = beforeResize ? this.getVerticalSpacingBeforeResize() : this.getVerticalSpacing()\r\n\r\n\t\twhile (i < beforeItemsCount) {\r\n\t\t\tconst currentRowFirstItemIndex = i\r\n\r\n\t\t\tlet rowHeight = 0\r\n\t\t\tlet columnIndex = 0\r\n\t\t\t// Not checking for `itemsCount` overflow here because `i = beforeItemsCount`\r\n\t\t\t// can only start at the start of a row, meaning that when calculating\r\n\t\t\t// \"before items height\" it's not supposed to add item heights from the\r\n\t\t\t// last row of items because in that case it would have to iterate from\r\n\t\t\t// `i === beforeItemsCount` and that condition is already checked above.\r\n\t\t\t// while (i < itemsCount) {\r\n\t\t\twhile (columnIndex < columnsCount) {\r\n\t\t\t\tlet itemHeight = beforeResize ? this.getItemHeightBeforeResize(i) : this.getItemHeight(i)\r\n\t\t\t\tif (itemHeight === undefined) {\r\n\t\t\t\t\t// `itemHeight` can only be `undefined` when not `beforeResize`.\r\n\t\t\t\t\t// Use the current \"average item height\" as a substitute.\r\n\t\t\t\t\titemHeight = this.getAverageItemHeight()\r\n\t\t\t\t}\r\n\t\t\t\trowHeight = Math.max(rowHeight, itemHeight)\r\n\t\t\t\ti++\r\n\t\t\t\tcolumnIndex++\r\n\t\t\t}\r\n\r\n\t\t\tbeforeItemsHeight += rowHeight\r\n\t\t\tbeforeItemsHeight += verticalSpacing\r\n\t\t}\r\n\r\n\t\treturn beforeItemsHeight\r\n\t}\r\n\r\n\t/**\r\n\t * Measures \"after\" items height.\r\n\t * @param {number} lastShownItemIndex — Last shown item index.\r\n\t * @param {number} itemsCount — Items count.\r\n\t * @return {number}\r\n\t */\r\n\tgetAfterItemsHeight(\r\n\t\tlastShownItemIndex,\r\n\t\titemsCount\r\n\t) {\r\n\t\t// This function could potentially also use `this.getPreviouslyCalculatedLayout()`\r\n\t\t// in order to skip calculating visible item indexes from scratch\r\n\t\t// and instead just calculate the difference from a \"previously calculated layout\".\r\n\t\t//\r\n\t\t// I did a simple test in a web browser and found out that running the following\r\n\t\t// piece of code is less than 10 milliseconds:\r\n\t\t//\r\n\t\t// var startedAt = Date.now()\r\n\t\t// var i = 0\r\n\t\t// while (i < 1000000) {\r\n\t\t// i++\r\n\t\t// }\r\n\t\t// console.log(Date.now() - startedAt)\r\n\t\t//\r\n\t\t// Which becomes negligible in my project's use case (a couple thousands items max).\r\n\r\n\t\tconst columnsCount = this.getColumnsCount()\r\n\t\tconst lastShownRowIndex = Math.floor(lastShownItemIndex / columnsCount)\r\n\r\n\t\tlet afterItemsHeight = 0\r\n\r\n\t\tlet i = lastShownItemIndex + 1\r\n\t\twhile (i < itemsCount) {\r\n\t\t\tlet rowHeight = 0\r\n\t\t\tlet columnIndex = 0\r\n\t\t\twhile (columnIndex < columnsCount && i < itemsCount) {\r\n\t\t\t\tlet itemHeight = this.getItemHeight(i)\r\n\t\t\t\tif (itemHeight === undefined) {\r\n\t\t\t\t\titemHeight = this.getAverageItemHeight()\r\n\t\t\t\t}\r\n\t\t\t\trowHeight = Math.max(rowHeight, itemHeight)\r\n\t\t\t\ti++\r\n\t\t\t\tcolumnIndex++\r\n\t\t\t}\r\n\r\n\t\t\t// Add all \"after\" items height.\r\n\t\t\tafterItemsHeight += this.getVerticalSpacing()\r\n\t\t\tafterItemsHeight += rowHeight\r\n\t\t}\r\n\r\n\t\treturn afterItemsHeight\r\n\t}\r\n\r\n\t/**\r\n\t * Returns the items's top offset relative to the top edge of the first item.\r\n\t * @param {number} i — Item index\r\n\t * @return {[number]} Returns `undefined` if any of the previous items haven't been rendered yet.\r\n\t */\r\n\tgetItemTopOffset(i) {\r\n\t\tlet topOffsetInsideScrollableContainer = 0\r\n\r\n\t\tconst beforeResizeItemsCount = this.getBeforeResizeItemsCount()\r\n\t\tconst beforeResizeRowsCount = beforeResizeItemsCount === 0\r\n\t\t\t? 0\r\n\t\t\t: Math.ceil(beforeResizeItemsCount / this.getColumnsCountBeforeResize())\r\n\r\n\t\tconst maxBeforeResizeRowsCount = i < beforeResizeItemsCount\r\n\t\t\t? Math.floor(i / this.getColumnsCountBeforeResize())\r\n\t\t\t: beforeResizeRowsCount\r\n\r\n\t\tlet beforeResizeRowIndex = 0\r\n\t\twhile (beforeResizeRowIndex < maxBeforeResizeRowsCount) {\r\n\t\t\tconst rowHeight = this.getItemHeightBeforeResize(\r\n\t\t\t\tbeforeResizeRowIndex * this.getColumnsCountBeforeResize()\r\n\t\t\t)\r\n\r\n\t\t\ttopOffsetInsideScrollableContainer += rowHeight\r\n\t\t\ttopOffsetInsideScrollableContainer += this.getVerticalSpacingBeforeResize()\r\n\r\n\t\t\tbeforeResizeRowIndex++\r\n\t\t}\r\n\r\n\t\tconst itemRowIndex = Math.floor((i - beforeResizeItemsCount) / this.getColumnsCount())\r\n\r\n\t\tlet rowIndex = 0\r\n\t\twhile (rowIndex < itemRowIndex) {\r\n\t\t\tlet rowHeight = 0\r\n\t\t\tlet columnIndex = 0\r\n\t\t\twhile (columnIndex < this.getColumnsCount()) {\r\n\t\t\t\tconst itemHeight = this.getItemHeight(\r\n\t\t\t\t\tbeforeResizeItemsCount + rowIndex * this.getColumnsCount() + columnIndex\r\n\t\t\t\t)\r\n\t\t\t\tif (itemHeight === undefined) {\r\n\t\t\t\t\treturn\r\n\t\t\t\t}\r\n\t\t\t\trowHeight = Math.max(rowHeight, itemHeight)\r\n\t\t\t\tcolumnIndex++\r\n\t\t\t}\r\n\r\n\t\t\ttopOffsetInsideScrollableContainer += rowHeight\r\n\t\t\ttopOffsetInsideScrollableContainer += this.getVerticalSpacing()\r\n\r\n\t\t\trowIndex++\r\n\t\t}\r\n\r\n\t\treturn topOffsetInsideScrollableContainer\r\n\t}\r\n}\r\n\r\nexport const LAYOUT_REASON = {\r\n\tSCROLL: 'scroll',\r\n\tSTOPPED_SCROLLING: 'stopped scrolling',\r\n\tMANUAL: 'manual',\r\n\tSTARTED: 'started',\r\n\tNON_MEASURED_ITEMS_HAVE_BEEN_MEASURED: 'non-measured item heights have been measured',\r\n\tVIEWPORT_WIDTH_CHANGED: 'viewport width changed',\r\n\tVIEWPORT_HEIGHT_CHANGED: 'viewport height changed',\r\n\tVIEWPORT_SIZE_UNCHANGED: 'viewport size unchanged',\r\n\tITEM_HEIGHT_CHANGED: 'item height changed',\r\n\tITEMS_CHANGED: 'items changed',\r\n\tTOP_OFFSET_CHANGED: 'list top offset changed'\r\n}"],"mappings":";;;;;;;;;;;;AAAA,OAAOA,GAAP,IAAcC,IAAd,QAA0B,oBAA1B;;IAEqBC,M;EACpB,sBAeG;IAAA,IAdFC,MAcE,QAdFA,MAcE;IAAA,IAbFC,mBAaE,QAbFA,mBAaE;IAAA,IAZFC,qBAYE,QAZFA,qBAYE;IAAA,IAXFC,kBAWE,QAXFA,kBAWE;IAAA,IAVFC,kBAUE,QAVFA,kBAUE;IAAA,IATFC,8BASE,QATFA,8BASE;IAAA,IARFC,eAQE,QARFA,eAQE;IAAA,IAPFC,2BAOE,QAPFA,2BAOE;IAAA,IANFC,aAME,QANFA,aAME;IAAA,IALFC,yBAKE,QALFA,yBAKE;IAAA,IAJFC,yBAIE,QAJFA,yBAIE;IAAA,IAHFC,oBAGE,QAHFA,oBAGE;IAAA,IAFFC,uBAEE,QAFFA,uBAEE;IAAA,IADFC,6BACE,QADFA,6BACE;;IAAA;;IACF,KAAKb,MAAL,GAAcA,MAAd;IACA,KAAKC,mBAAL,GAA2BA,mBAA3B;IACA,KAAKC,qBAAL,GAA6BA,qBAA7B;IACA,KAAKC,kBAAL,GAA0BA,kBAA1B;IACA,KAAKC,kBAAL,GAA0BA,kBAA1B;IACA,KAAKC,8BAAL,GAAsCA,8BAAtC;IACA,KAAKC,eAAL,GAAuBA,eAAvB;IACA,KAAKC,2BAAL,GAAmCA,2BAAnC;IACA,KAAKC,aAAL,GAAqBA,aAArB;IACA,KAAKC,yBAAL,GAAiCA,yBAAjC;IACA,KAAKC,yBAAL,GAAiCA,yBAAjC;IACA,KAAKC,oBAAL,GAA4BA,oBAA5B;IACA,KAAKC,uBAAL,GAA+BA,uBAA/B,CAbE,CAcF;IACA;IACA;IACA;IACA;IACA;IACA;;IACA,KAAKC,6BAAL,GAAqCA,6BAArC;EACA;;;;W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,SAAnB,EAA8B;YAC7B;UACA;;UACD+B,UAAS,GAAGrD,IAAI,CAAC8C,GAAL,CAASO,UAAT,EAAoBT,UAApB,CAAZ;UACAD,WAAW;QACX;;QAEDY,kCAAkC,IAAIF,UAAtC;QACAE,kCAAkC,IAAI,KAAK1E,kBAAL,EAAtC;QAEA+E,QAAQ;MACR;;MAED,OAAOL,kCAAP;IACA;;;;;;SAhwBmB/E,M;AAmwBrB,OAAO,IAAMqF,aAAa,GAAG;EAC5BC,MAAM,EAAE,QADoB;EAE5BC,iBAAiB,EAAE,mBAFS;EAG5BC,MAAM,EAAE,QAHoB;EAI5BC,OAAO,EAAE,SAJmB;EAK5BC,qCAAqC,EAAE,8CALX;EAM5BC,sBAAsB,EAAE,wBANI;EAO5BC,uBAAuB,EAAE,yBAPG;EAQ5BC,uBAAuB,EAAE,yBARG;EAS5BC,mBAAmB,EAAE,qBATO;EAU5BC,aAAa,EAAE,eAVa;EAW5BC,kBAAkB,EAAE;AAXQ,CAAtB"}
|
package/modules/Layout.test.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import Layout from './Layout';
|
|
2
|
-
import Engine from '
|
|
1
|
+
import Layout from './Layout.js';
|
|
2
|
+
import Engine from './test/Engine.js';
|
|
3
3
|
describe('Layout', function () {
|
|
4
4
|
it('should work', function () {
|
|
5
5
|
var SCREEN_HEIGHT = 400;
|
|
@@ -162,6 +162,7 @@ describe('Layout', function () {
|
|
|
162
162
|
return scrollableContainer.height;
|
|
163
163
|
}
|
|
164
164
|
});
|
|
165
|
+
var shouldResetGridLayout;
|
|
165
166
|
layout.getLayoutUpdateForItemsDiff({
|
|
166
167
|
firstShownItemIndex: 3,
|
|
167
168
|
lastShownItemIndex: 5,
|
|
@@ -173,13 +174,17 @@ describe('Layout', function () {
|
|
|
173
174
|
}, {
|
|
174
175
|
itemsCount: 5 + 5 + items.length,
|
|
175
176
|
columnsCount: 4,
|
|
176
|
-
shouldRestoreScrollPosition: true
|
|
177
|
+
shouldRestoreScrollPosition: true,
|
|
178
|
+
onResetGridLayout: function onResetGridLayout() {
|
|
179
|
+
return shouldResetGridLayout = true;
|
|
180
|
+
}
|
|
177
181
|
}).should.deep.equal({
|
|
178
182
|
firstShownItemIndex: 0,
|
|
179
183
|
lastShownItemIndex: 5 + 5,
|
|
180
184
|
beforeItemsHeight: 0,
|
|
181
185
|
afterItemsHeight: 5 * (ITEM_HEIGHT + VERTICAL_SPACING)
|
|
182
186
|
});
|
|
187
|
+
shouldResetGridLayout.should.equal(true);
|
|
183
188
|
});
|
|
184
189
|
});
|
|
185
190
|
//# sourceMappingURL=Layout.test.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../source/Layout.test.js"],"names":["Layout","Engine","describe","it","SCREEN_HEIGHT","scrollableContainer","width","height","ITEM_WIDTH","ITEM_HEIGHT","VERTICAL_SPACING","items","Array","fill","layout","getPrerenderMargin","getVerticalSpacing","getColumnsCount","getItemHeight","i","getBeforeResizeItemsCount","getAverageItemHeight","getScrollableContainerHeight","getShownItemIndexes","itemsCount","length","visibleAreaTop","visibleAreaBottom","should","deep","equal","firstShownItemIndex","lastShownItemIndex","getLayoutUpdateForItemsDiff","beforeItemsHeight","afterItemsHeight","prependedItemsCount","appendedItemsCount","columnsCount","shouldRestoreScrollPosition"],"mappings":"AAAA,OAAOA,MAAP,MAAmB,UAAnB;AAEA,OAAOC,MAAP,MAAmB,gBAAnB;AAEAC,QAAQ,CAAC,QAAD,EAAW,YAAW;AAC7BC,EAAAA,EAAE,CAAC,aAAD,EAAgB,YAAW;AAC5B,QAAMC,aAAa,GAAG,GAAtB;AAEA,QAAMC,mBAAmB,GAAG;AAC3BC,MAAAA,KAAK,EAAE,GADoB;AAE3BC,MAAAA,MAAM,EAAEH;AAFmB,KAA5B;AAKA,QAAMI,UAAU,GAAGH,mBAAmB,CAACC,KAAvC;AACA,QAAMG,WAAW,GAAG,GAApB;AAEA,QAAMC,gBAAgB,GAAG,GAAzB;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,yBAAyB,EAAE;AAAA,eAAM,CAAN;AAAA,OALF;AAMzBC,MAAAA,oBAAoB,EAAE;AAAA,eAAMZ,WAAN;AAAA,OANG;AAOzBa,MAAAA,4BAA4B,EAAE;AAAA,eAAMjB,mBAAmB,CAACE,MAA1B;AAAA;AAPL,KAAX,CAAf;AAUAO,IAAAA,MAAM,CAACmB,2BAAP,CACC;AACCF,MAAAA,mBAAmB,EAAE,CADtB;AAECC,MAAAA,kBAAkB,EAAE,CAFrB;AAGCE,MAAAA,iBAAiB,EAAE,KAAKzB,WAAW,GAAGC,gBAAnB,CAHpB;AAICyB,MAAAA,gBAAgB,EAAE,KAAK1B,WAAW,GAAGC,gBAAnB;AAJnB,KADD,EAOC;AACC0B,MAAAA,mBAAmB,EAAE,CADtB;AAECC,MAAAA,kBAAkB,EAAE;AAFrB,KAPD,EAUI;AACFb,MAAAA,UAAU,EAAE,IAAI,CAAJ,GAAQb,KAAK,CAACc,MADxB;AAEFa,MAAAA,YAAY,EAAE,CAFZ;AAGFC,MAAAA,2BAA2B,EAAE;AAH3B,KAVJ,EAeEX,MAfF,CAeSC,IAfT,CAecC,KAfd,CAeoB;AACnBC,MAAAA,mBAAmB,EAAE,CADF;AAEnBC,MAAAA,kBAAkB,EAAE,IAAI,CAFL;AAGnBE,MAAAA,iBAAiB,EAAE,CAHA;AAInBC,MAAAA,gBAAgB,EAAE,KAAK1B,WAAW,GAAGC,gBAAnB;AAJC,KAfpB;AAqBA,GA3CC,CAAF;AA4CA,CAtKO,CAAR","sourcesContent":["import Layout from './Layout'\r\n\r\nimport Engine from '../test/Engine'\r\n\r\ndescribe('Layout', function() {\r\n\tit('should work', function() {\r\n\t\tconst SCREEN_HEIGHT = 400\r\n\r\n\t\tconst scrollableContainer = {\r\n\t\t\twidth: 800,\r\n\t\t\theight: SCREEN_HEIGHT\r\n\t\t}\r\n\r\n\t\tconst ITEM_WIDTH = scrollableContainer.width\r\n\t\tconst ITEM_HEIGHT = 200\r\n\r\n\t\tconst VERTICAL_SPACING = 100\r\n\r\n\t\tconst items = new Array(9).fill(ITEM_WIDTH * ITEM_HEIGHT)\r\n\r\n\t\tconst layout = new Layout({\r\n\t\t\tgetPrerenderMargin: () => SCREEN_HEIGHT,\r\n\t\t\tgetVerticalSpacing: () => VERTICAL_SPACING,\r\n\t\t\tgetColumnsCount: () => 1,\r\n\t\t\tgetItemHeight: (i) => items[i] / scrollableContainer.width,\r\n\t\t\tgetBeforeResizeItemsCount: () => 0,\r\n\t\t\tgetAverageItemHeight: () => ITEM_HEIGHT,\r\n\t\t\tgetScrollableContainerHeight: () => scrollableContainer.height\r\n\t\t})\r\n\r\n\t\t// Initial render.\r\n\t\tlayout.getShownItemIndexes({\r\n\t\t\titemsCount: items.length,\r\n\t\t\tvisibleAreaTop: 0,\r\n\t\t\tvisibleAreaBottom: SCREEN_HEIGHT\r\n\t\t}).should.deep.equal({\r\n\t\t\tfirstShownItemIndex: 0,\r\n\t\t\tlastShownItemIndex: 2\r\n\t\t})\r\n\r\n\t\t// The first item is almost hidden.\r\n\t\tlayout.getShownItemIndexes({\r\n\t\t\titemsCount: items.length,\r\n\t\t\tvisibleAreaTop: SCREEN_HEIGHT + ITEM_HEIGHT - 1,\r\n\t\t\tvisibleAreaBottom: (SCREEN_HEIGHT + ITEM_HEIGHT - 1) + SCREEN_HEIGHT\r\n\t\t}).should.deep.equal({\r\n\t\t\tfirstShownItemIndex: 0,\r\n\t\t\tlastShownItemIndex: 4\r\n\t\t})\r\n\r\n\t\t// The first item is hidden.\r\n\t\tlayout.getShownItemIndexes({\r\n\t\t\titemsCount: items.length,\r\n\t\t\tvisibleAreaTop: SCREEN_HEIGHT + ITEM_HEIGHT,\r\n\t\t\tvisibleAreaBottom: (SCREEN_HEIGHT + ITEM_HEIGHT) + SCREEN_HEIGHT\r\n\t\t}).should.deep.equal({\r\n\t\t\tfirstShownItemIndex: 1,\r\n\t\t\tlastShownItemIndex: 4\r\n\t\t})\r\n\r\n\t\t// A new item at the bottom is almost visible.\r\n\t\tlayout.getShownItemIndexes({\r\n\t\t\titemsCount: items.length,\r\n\t\t\tvisibleAreaTop: (ITEM_HEIGHT + VERTICAL_SPACING) * 5 - SCREEN_HEIGHT * 2,\r\n\t\t\tvisibleAreaBottom: (ITEM_HEIGHT + VERTICAL_SPACING) * 5 - SCREEN_HEIGHT\r\n\t\t}).should.deep.equal({\r\n\t\t\tfirstShownItemIndex: 1,\r\n\t\t\tlastShownItemIndex: 4\r\n\t\t})\r\n\r\n\t\t// A new item at the bottom is visible.\r\n\t\tlayout.getShownItemIndexes({\r\n\t\t\titemsCount: items.length,\r\n\t\t\tvisibleAreaTop: (ITEM_HEIGHT + VERTICAL_SPACING) * 5 + 1 - SCREEN_HEIGHT * 2,\r\n\t\t\tvisibleAreaBottom: (ITEM_HEIGHT + VERTICAL_SPACING) * 5 + 1 - SCREEN_HEIGHT\r\n\t\t}).should.deep.equal({\r\n\t\t\tfirstShownItemIndex: 1,\r\n\t\t\tlastShownItemIndex: 5\r\n\t\t})\r\n\t})\r\n\r\n\tit('should update layout for items incremental change', function() {\r\n\t\tconst scrollableContainer = {\r\n\t\t\twidth: 800,\r\n\t\t\theight: 400\r\n\t\t}\r\n\r\n\t\tconst ITEM_WIDTH = scrollableContainer.width\r\n\t\tconst ITEM_HEIGHT = 200\r\n\r\n\t\tconst items = new Array(9).fill(ITEM_WIDTH * ITEM_HEIGHT)\r\n\r\n\t\tconst VERTICAL_SPACING = 100\r\n\r\n\t\tconst layout = new Layout({\r\n\t\t\tgetPrerenderMargin: () => scrollableContainer.height,\r\n\t\t\tgetVerticalSpacing: () => VERTICAL_SPACING,\r\n\t\t\tgetColumnsCount: () => 1,\r\n\t\t\tgetItemHeight: (i) => ITEM_HEIGHT,\r\n\t\t\tgetBeforeResizeItemsCount: () => 0,\r\n\t\t\tgetAverageItemHeight: () => ITEM_HEIGHT,\r\n\t\t\tgetScrollableContainerHeight: () => scrollableContainer.height\r\n\t\t})\r\n\r\n\t\tlayout.getLayoutUpdateForItemsDiff(\r\n\t\t\t{\r\n\t\t\t\tfirstShownItemIndex: 3,\r\n\t\t\t\tlastShownItemIndex: 5,\r\n\t\t\t\tbeforeItemsHeight: 3 * (ITEM_HEIGHT + VERTICAL_SPACING),\r\n\t\t\t\tafterItemsHeight: 3 * (ITEM_HEIGHT + VERTICAL_SPACING)\r\n\t\t\t},\r\n\t\t\t{\r\n\t\t\t\tprependedItemsCount: 5,\r\n\t\t\t\tappendedItemsCount: 5\r\n\t\t\t}, {\r\n\t\t\t\titemsCount: 5 + 5 + items.length,\r\n\t\t\t\tcolumnsCount: 1\r\n\t\t\t}\r\n\t\t).should.deep.equal({\r\n\t\t\tfirstShownItemIndex: 5 + 3,\r\n\t\t\tlastShownItemIndex: 5 + 5,\r\n\t\t\tbeforeItemsHeight: (5 + 3) * (ITEM_HEIGHT + VERTICAL_SPACING),\r\n\t\t\tafterItemsHeight: (3 + 5) * (ITEM_HEIGHT + VERTICAL_SPACING)\r\n\t\t})\r\n\t})\r\n\r\n\tit('should update layout for items incremental change (rows get rebalanced)', function() {\r\n\t\tconst scrollableContainer = {\r\n\t\t\twidth: 800,\r\n\t\t\theight: 400\r\n\t\t}\r\n\t\tconst ITEM_WIDTH = scrollableContainer.width\r\n\t\tconst ITEM_HEIGHT = 400\r\n\r\n\t\tconst items = new Array(9).fill(ITEM_WIDTH * ITEM_HEIGHT)\r\n\r\n\t\tconst VERTICAL_SPACING = 100\r\n\r\n\t\tconst layout = new Layout({\r\n\t\t\tgetPrerenderMargin: () => scrollableContainer.height,\r\n\t\t\tgetVerticalSpacing: () => VERTICAL_SPACING,\r\n\t\t\tgetColumnsCount: () => 4,\r\n\t\t\tgetItemHeight: () => ITEM_HEIGHT,\r\n\t\t\tgetBeforeResizeItemsCount: () => 0,\r\n\t\t\tgetAverageItemHeight: () => ITEM_HEIGHT,\r\n\t\t\tgetScrollableContainerHeight: () => scrollableContainer.height\r\n\t\t})\r\n\r\n\t\tlayout.getLayoutUpdateForItemsDiff(\r\n\t\t\t{\r\n\t\t\t\tfirstShownItemIndex: 3,\r\n\t\t\t\tlastShownItemIndex: 5,\r\n\t\t\t\tbeforeItemsHeight: 3 * (ITEM_HEIGHT + VERTICAL_SPACING),\r\n\t\t\t\tafterItemsHeight: 3 * (ITEM_HEIGHT + VERTICAL_SPACING)\r\n\t\t\t},\r\n\t\t\t{\r\n\t\t\t\tprependedItemsCount: 5,\r\n\t\t\t\tappendedItemsCount: 5\r\n\t\t\t}, {\r\n\t\t\t\titemsCount: 5 + 5 + items.length,\r\n\t\t\t\tcolumnsCount: 4,\r\n\t\t\t\tshouldRestoreScrollPosition: true\r\n\t\t\t}\r\n\t\t).should.deep.equal({\r\n\t\t\tfirstShownItemIndex: 0,\r\n\t\t\tlastShownItemIndex: 5 + 5,\r\n\t\t\tbeforeItemsHeight: 0,\r\n\t\t\tafterItemsHeight: 5 * (ITEM_HEIGHT + VERTICAL_SPACING)\r\n\t\t})\r\n\t})\r\n})"],"file":"Layout.test.js"}
|
|
1
|
+
{"version":3,"file":"Layout.test.js","names":["Layout","Engine","describe","it","SCREEN_HEIGHT","scrollableContainer","width","height","ITEM_WIDTH","ITEM_HEIGHT","VERTICAL_SPACING","items","Array","fill","layout","getPrerenderMargin","getVerticalSpacing","getColumnsCount","getItemHeight","i","getBeforeResizeItemsCount","getAverageItemHeight","getScrollableContainerHeight","getShownItemIndexes","itemsCount","length","visibleAreaTop","visibleAreaBottom","should","deep","equal","firstShownItemIndex","lastShownItemIndex","getLayoutUpdateForItemsDiff","beforeItemsHeight","afterItemsHeight","prependedItemsCount","appendedItemsCount","columnsCount","shouldResetGridLayout","shouldRestoreScrollPosition","onResetGridLayout"],"sources":["../source/Layout.test.js"],"sourcesContent":["import Layout from './Layout.js'\r\n\r\nimport Engine from './test/Engine.js'\r\n\r\ndescribe('Layout', function() {\r\n\tit('should work', function() {\r\n\t\tconst SCREEN_HEIGHT = 400\r\n\r\n\t\tconst scrollableContainer = {\r\n\t\t\twidth: 800,\r\n\t\t\theight: SCREEN_HEIGHT\r\n\t\t}\r\n\r\n\t\tconst ITEM_WIDTH = scrollableContainer.width\r\n\t\tconst ITEM_HEIGHT = 200\r\n\r\n\t\tconst VERTICAL_SPACING = 100\r\n\r\n\t\tconst items = new Array(9).fill(ITEM_WIDTH * ITEM_HEIGHT)\r\n\r\n\t\tconst layout = new Layout({\r\n\t\t\tgetPrerenderMargin: () => SCREEN_HEIGHT,\r\n\t\t\tgetVerticalSpacing: () => VERTICAL_SPACING,\r\n\t\t\tgetColumnsCount: () => 1,\r\n\t\t\tgetItemHeight: (i) => items[i] / scrollableContainer.width,\r\n\t\t\tgetBeforeResizeItemsCount: () => 0,\r\n\t\t\tgetAverageItemHeight: () => ITEM_HEIGHT,\r\n\t\t\tgetScrollableContainerHeight: () => scrollableContainer.height\r\n\t\t})\r\n\r\n\t\t// Initial render.\r\n\t\tlayout.getShownItemIndexes({\r\n\t\t\titemsCount: items.length,\r\n\t\t\tvisibleAreaTop: 0,\r\n\t\t\tvisibleAreaBottom: SCREEN_HEIGHT\r\n\t\t}).should.deep.equal({\r\n\t\t\tfirstShownItemIndex: 0,\r\n\t\t\tlastShownItemIndex: 2\r\n\t\t})\r\n\r\n\t\t// The first item is almost hidden.\r\n\t\tlayout.getShownItemIndexes({\r\n\t\t\titemsCount: items.length,\r\n\t\t\tvisibleAreaTop: SCREEN_HEIGHT + ITEM_HEIGHT - 1,\r\n\t\t\tvisibleAreaBottom: (SCREEN_HEIGHT + ITEM_HEIGHT - 1) + SCREEN_HEIGHT\r\n\t\t}).should.deep.equal({\r\n\t\t\tfirstShownItemIndex: 0,\r\n\t\t\tlastShownItemIndex: 4\r\n\t\t})\r\n\r\n\t\t// The first item is hidden.\r\n\t\tlayout.getShownItemIndexes({\r\n\t\t\titemsCount: items.length,\r\n\t\t\tvisibleAreaTop: SCREEN_HEIGHT + ITEM_HEIGHT,\r\n\t\t\tvisibleAreaBottom: (SCREEN_HEIGHT + ITEM_HEIGHT) + SCREEN_HEIGHT\r\n\t\t}).should.deep.equal({\r\n\t\t\tfirstShownItemIndex: 1,\r\n\t\t\tlastShownItemIndex: 4\r\n\t\t})\r\n\r\n\t\t// A new item at the bottom is almost visible.\r\n\t\tlayout.getShownItemIndexes({\r\n\t\t\titemsCount: items.length,\r\n\t\t\tvisibleAreaTop: (ITEM_HEIGHT + VERTICAL_SPACING) * 5 - SCREEN_HEIGHT * 2,\r\n\t\t\tvisibleAreaBottom: (ITEM_HEIGHT + VERTICAL_SPACING) * 5 - SCREEN_HEIGHT\r\n\t\t}).should.deep.equal({\r\n\t\t\tfirstShownItemIndex: 1,\r\n\t\t\tlastShownItemIndex: 4\r\n\t\t})\r\n\r\n\t\t// A new item at the bottom is visible.\r\n\t\tlayout.getShownItemIndexes({\r\n\t\t\titemsCount: items.length,\r\n\t\t\tvisibleAreaTop: (ITEM_HEIGHT + VERTICAL_SPACING) * 5 + 1 - SCREEN_HEIGHT * 2,\r\n\t\t\tvisibleAreaBottom: (ITEM_HEIGHT + VERTICAL_SPACING) * 5 + 1 - SCREEN_HEIGHT\r\n\t\t}).should.deep.equal({\r\n\t\t\tfirstShownItemIndex: 1,\r\n\t\t\tlastShownItemIndex: 5\r\n\t\t})\r\n\t})\r\n\r\n\tit('should update layout for items incremental change', function() {\r\n\t\tconst scrollableContainer = {\r\n\t\t\twidth: 800,\r\n\t\t\theight: 400\r\n\t\t}\r\n\r\n\t\tconst ITEM_WIDTH = scrollableContainer.width\r\n\t\tconst ITEM_HEIGHT = 200\r\n\r\n\t\tconst items = new Array(9).fill(ITEM_WIDTH * ITEM_HEIGHT)\r\n\r\n\t\tconst VERTICAL_SPACING = 100\r\n\r\n\t\tconst layout = new Layout({\r\n\t\t\tgetPrerenderMargin: () => scrollableContainer.height,\r\n\t\t\tgetVerticalSpacing: () => VERTICAL_SPACING,\r\n\t\t\tgetColumnsCount: () => 1,\r\n\t\t\tgetItemHeight: (i) => ITEM_HEIGHT,\r\n\t\t\tgetBeforeResizeItemsCount: () => 0,\r\n\t\t\tgetAverageItemHeight: () => ITEM_HEIGHT,\r\n\t\t\tgetScrollableContainerHeight: () => scrollableContainer.height\r\n\t\t})\r\n\r\n\t\tlayout.getLayoutUpdateForItemsDiff(\r\n\t\t\t{\r\n\t\t\t\tfirstShownItemIndex: 3,\r\n\t\t\t\tlastShownItemIndex: 5,\r\n\t\t\t\tbeforeItemsHeight: 3 * (ITEM_HEIGHT + VERTICAL_SPACING),\r\n\t\t\t\tafterItemsHeight: 3 * (ITEM_HEIGHT + VERTICAL_SPACING)\r\n\t\t\t},\r\n\t\t\t{\r\n\t\t\t\tprependedItemsCount: 5,\r\n\t\t\t\tappendedItemsCount: 5\r\n\t\t\t}, {\r\n\t\t\t\titemsCount: 5 + 5 + items.length,\r\n\t\t\t\tcolumnsCount: 1\r\n\t\t\t}\r\n\t\t).should.deep.equal({\r\n\t\t\tfirstShownItemIndex: 5 + 3,\r\n\t\t\tlastShownItemIndex: 5 + 5,\r\n\t\t\tbeforeItemsHeight: (5 + 3) * (ITEM_HEIGHT + VERTICAL_SPACING),\r\n\t\t\tafterItemsHeight: (3 + 5) * (ITEM_HEIGHT + VERTICAL_SPACING)\r\n\t\t})\r\n\t})\r\n\r\n\tit('should update layout for items incremental change (rows get rebalanced)', function() {\r\n\t\tconst scrollableContainer = {\r\n\t\t\twidth: 800,\r\n\t\t\theight: 400\r\n\t\t}\r\n\t\tconst ITEM_WIDTH = scrollableContainer.width\r\n\t\tconst ITEM_HEIGHT = 400\r\n\r\n\t\tconst items = new Array(9).fill(ITEM_WIDTH * ITEM_HEIGHT)\r\n\r\n\t\tconst VERTICAL_SPACING = 100\r\n\r\n\t\tconst layout = new Layout({\r\n\t\t\tgetPrerenderMargin: () => scrollableContainer.height,\r\n\t\t\tgetVerticalSpacing: () => VERTICAL_SPACING,\r\n\t\t\tgetColumnsCount: () => 4,\r\n\t\t\tgetItemHeight: () => ITEM_HEIGHT,\r\n\t\t\tgetBeforeResizeItemsCount: () => 0,\r\n\t\t\tgetAverageItemHeight: () => ITEM_HEIGHT,\r\n\t\t\tgetScrollableContainerHeight: () => scrollableContainer.height\r\n\t\t})\r\n\r\n\t\tlet shouldResetGridLayout\r\n\r\n\t\tlayout.getLayoutUpdateForItemsDiff(\r\n\t\t\t{\r\n\t\t\t\tfirstShownItemIndex: 3,\r\n\t\t\t\tlastShownItemIndex: 5,\r\n\t\t\t\tbeforeItemsHeight: 3 * (ITEM_HEIGHT + VERTICAL_SPACING),\r\n\t\t\t\tafterItemsHeight: 3 * (ITEM_HEIGHT + VERTICAL_SPACING)\r\n\t\t\t},\r\n\t\t\t{\r\n\t\t\t\tprependedItemsCount: 5,\r\n\t\t\t\tappendedItemsCount: 5\r\n\t\t\t}, {\r\n\t\t\t\titemsCount: 5 + 5 + items.length,\r\n\t\t\t\tcolumnsCount: 4,\r\n\t\t\t\tshouldRestoreScrollPosition: true,\r\n\t\t\t\tonResetGridLayout: () => shouldResetGridLayout = true\r\n\t\t\t}\r\n\t\t).should.deep.equal({\r\n\t\t\tfirstShownItemIndex: 0,\r\n\t\t\tlastShownItemIndex: 5 + 5,\r\n\t\t\tbeforeItemsHeight: 0,\r\n\t\t\tafterItemsHeight: 5 * (ITEM_HEIGHT + VERTICAL_SPACING)\r\n\t\t})\r\n\r\n\t\tshouldResetGridLayout.should.equal(true)\r\n\t})\r\n})"],"mappings":"AAAA,OAAOA,MAAP,MAAmB,aAAnB;AAEA,OAAOC,MAAP,MAAmB,kBAAnB;AAEAC,QAAQ,CAAC,QAAD,EAAW,YAAW;EAC7BC,EAAE,CAAC,aAAD,EAAgB,YAAW;IAC5B,IAAMC,aAAa,GAAG,GAAtB;IAEA,IAAMC,mBAAmB,GAAG;MAC3BC,KAAK,EAAE,GADoB;MAE3BC,MAAM,EAAEH;IAFmB,CAA5B;IAKA,IAAMI,UAAU,GAAGH,mBAAmB,CAACC,KAAvC;IACA,IAAMG,WAAW,GAAG,GAApB;IAEA,IAAMC,gBAAgB,GAAG,GAAzB;IAEA,I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U,EAAE,IAAI,CAAJ,GAAQb,KAAK,CAACc,MADxB;MAEFa,YAAY,EAAE,CAFZ;MAGFE,2BAA2B,EAAE,IAH3B;MAIFC,iBAAiB,EAAE;QAAA,OAAMF,qBAAqB,GAAG,IAA9B;MAAA;IAJjB,CAVJ,EAgBEX,MAhBF,CAgBSC,IAhBT,CAgBcC,KAhBd,CAgBoB;MACnBC,mBAAmB,EAAE,CADF;MAEnBC,kBAAkB,EAAE,IAAI,CAFL;MAGnBE,iBAAiB,EAAE,CAHA;MAInBC,gBAAgB,EAAE,KAAK1B,WAAW,GAAGC,gBAAnB;IAJC,CAhBpB;IAuBA6B,qBAAqB,CAACX,MAAtB,CAA6BE,KAA7B,CAAmC,IAAnC;EACA,CAhDC,CAAF;AAiDA,CA3KO,CAAR"}
|
|
@@ -2,29 +2,33 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons
|
|
|
2
2
|
|
|
3
3
|
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
|
|
4
4
|
|
|
5
|
-
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
|
|
5
|
+
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
|
6
6
|
|
|
7
|
-
var
|
|
8
|
-
function
|
|
7
|
+
var ListHeightMeasurement = /*#__PURE__*/function () {
|
|
8
|
+
function ListHeightMeasurement(_ref) {
|
|
9
9
|
var itemsContainer = _ref.itemsContainer,
|
|
10
10
|
getListTopOffset = _ref.getListTopOffset;
|
|
11
11
|
|
|
12
|
-
_classCallCheck(this,
|
|
12
|
+
_classCallCheck(this, ListHeightMeasurement);
|
|
13
13
|
|
|
14
14
|
this.itemsContainer = itemsContainer;
|
|
15
15
|
this.getListTopOffset = getListTopOffset;
|
|
16
16
|
}
|
|
17
17
|
/**
|
|
18
|
-
*
|
|
18
|
+
* Snapshots the list height while `previousItems` are still rendered,
|
|
19
|
+
* before rendering `newItems`. The list height will be re-measured
|
|
20
|
+
* after the new items have been rendered, yielding the list height difference
|
|
21
|
+
* which is gonna be the amount to scroll vertically in order to restore
|
|
22
|
+
* the previous scroll position. Is only used when prepending items.
|
|
19
23
|
* @param {any[]} previousItems
|
|
20
24
|
* @param {any[]} newItems
|
|
21
25
|
* @param {number} prependedItemsCount
|
|
22
26
|
*/
|
|
23
27
|
|
|
24
28
|
|
|
25
|
-
_createClass(
|
|
26
|
-
key: "
|
|
27
|
-
value: function
|
|
29
|
+
_createClass(ListHeightMeasurement, [{
|
|
30
|
+
key: "snapshotListHeightBeforeAddingNewItems",
|
|
31
|
+
value: function snapshotListHeightBeforeAddingNewItems(_ref2) {
|
|
28
32
|
var previousItems = _ref2.previousItems,
|
|
29
33
|
newItems = _ref2.newItems,
|
|
30
34
|
prependedItemsCount = _ref2.prependedItemsCount;
|
|
@@ -50,23 +54,17 @@ var ListHeightChangeWatcher = /*#__PURE__*/function () {
|
|
|
50
54
|
// i--
|
|
51
55
|
// }
|
|
52
56
|
// }
|
|
53
|
-
//
|
|
54
|
-
//
|
|
55
|
-
//
|
|
56
|
-
//
|
|
57
|
-
//
|
|
58
|
-
//
|
|
59
|
-
//
|
|
60
|
-
//
|
|
61
|
-
//
|
|
62
|
-
//
|
|
63
|
-
// See the long section of comments in `ReactVirtualScroller.render()`
|
|
64
|
-
// method for more info on why is `ListHeightChangeWatcher.snapshot()` called there.
|
|
65
|
-
|
|
57
|
+
// This part is longer relevant: <ReactVirtualScroller/> no longer calls
|
|
58
|
+
// this function two times consequtively.
|
|
59
|
+
//
|
|
60
|
+
// // If the scroll position has already been captured for restoration,
|
|
61
|
+
// // then don't capture it the second time.
|
|
62
|
+
// if (this._snapshot &&
|
|
63
|
+
// this._snapshot.previousItems === previousItems &&
|
|
64
|
+
// this._snapshot.newItems === newItems) {
|
|
65
|
+
// return
|
|
66
|
+
// }
|
|
66
67
|
|
|
67
|
-
if (this._snapshot && this._snapshot.previousItems === previousItems && this._snapshot.newItems === newItems) {
|
|
68
|
-
return;
|
|
69
|
-
}
|
|
70
68
|
|
|
71
69
|
this._snapshot = {
|
|
72
70
|
previousItems: previousItems,
|
|
@@ -112,8 +110,8 @@ var ListHeightChangeWatcher = /*#__PURE__*/function () {
|
|
|
112
110
|
}
|
|
113
111
|
}]);
|
|
114
112
|
|
|
115
|
-
return
|
|
113
|
+
return ListHeightMeasurement;
|
|
116
114
|
}();
|
|
117
115
|
|
|
118
|
-
export {
|
|
119
|
-
//# sourceMappingURL=
|
|
116
|
+
export { ListHeightMeasurement as default };
|
|
117
|
+
//# sourceMappingURL=ListHeightMeasurement.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ListHeightMeasurement.js","names":["ListHeightMeasurement","itemsContainer","getListTopOffset","previousItems","newItems","prependedItemsCount","length","_snapshot","itemIndex","itemTopOffset","getNthRenderedItemTopOffset","listTopOffset","undefined","itemTopOffsetNew","listTopOffsetNew"],"sources":["../source/ListHeightMeasurement.js"],"sourcesContent":["export default class ListHeightMeasurement {\r\n\tconstructor({\r\n\t\titemsContainer,\r\n\t\tgetListTopOffset\r\n\t}) {\r\n\t\tthis.itemsContainer = itemsContainer\r\n\t\tthis.getListTopOffset = getListTopOffset\r\n\t}\r\n\r\n\t/**\r\n\t * Snapshots the list height while `previousItems` are still rendered,\r\n\t * before rendering `newItems`. The list height will be re-measured\r\n\t * after the new items have been rendered, yielding the list height difference\r\n\t * which is gonna be the amount to scroll vertically in order to restore\r\n\t * the previous scroll position. Is only used when prepending items.\r\n\t * @param {any[]} previousItems\r\n\t * @param {any[]} newItems\r\n\t * @param {number} prependedItemsCount\r\n\t */\r\n\tsnapshotListHeightBeforeAddingNewItems({\r\n\t\tpreviousItems,\r\n\t\tnewItems,\r\n\t\tprependedItemsCount\r\n\t}) {\r\n\t\t// If there were no items in the list\r\n\t\t// then there's no point in restoring scroll position.\r\n\t\tif (previousItems.length === 0) {\r\n\t\t\treturn\r\n\t\t}\r\n\r\n\t\t// If no items were prepended then no need to restore scroll position.\r\n\t\tif (prependedItemsCount === 0) {\r\n\t\t\treturn\r\n\t\t}\r\n\r\n\t\t// The first item is supposed to be shown when the user clicks\r\n\t\t// \"Show previous items\" button. If it isn't shown though,\r\n\t\t// could still calculate the first item's top position using\r\n\t\t// the values from `itemHeights` and `verticalSpacing`.\r\n\t\t// But that would be a weird non-realistic scenario.\r\n\t\t// if (firstShownItemIndex > 0) {\r\n\t\t// \tlet i = firstShownItemIndex - 1\r\n\t\t// \twhile (i >= 0) {\r\n\t\t// \t\tfirstItemTopOffset += itemHeights[i] + verticalSpacing\r\n\t\t// \t\ti--\r\n\t\t// \t}\r\n\t\t// }\r\n\r\n\t\t// This part is longer relevant: <ReactVirtualScroller/> no longer calls\r\n\t\t// this function two times consequtively.\r\n\t\t//\r\n\t\t// // If the scroll position has already been captured for restoration,\r\n\t\t// // then don't capture it the second time.\r\n\t\t// if (this._snapshot &&\r\n\t\t// \tthis._snapshot.previousItems === previousItems &&\r\n\t\t// \tthis._snapshot.newItems === newItems) {\r\n\t\t// \treturn\r\n\t\t// }\r\n\r\n\t\tthis._snapshot = {\r\n\t\t\tpreviousItems,\r\n\t\t\tnewItems,\r\n\t\t\titemIndex: prependedItemsCount,\r\n\t\t\titemTopOffset: this.itemsContainer.getNthRenderedItemTopOffset(0),\r\n\t\t\t// Snapshot list top offset inside the scrollable container too\r\n\t\t\t// because it's common to hide the \"Show previous items\" button\r\n\t\t\t// when the user has browsed to the top of the list, which causes\r\n\t\t\t// the list's top position to shift upwards due to the button\r\n\t\t\t// no longer being rendered. Tracking list top offset doesn't\r\n\t\t\t// fit here that well, but it makes sense in real-world applications.\r\n\t\t\tlistTopOffset: this.getListTopOffset()\r\n\t\t}\r\n\t}\r\n\r\n\tgetAnchorItemIndex() {\r\n\t\treturn this._snapshot.itemIndex\r\n\t}\r\n\r\n\thasSnapshot() {\r\n\t\treturn this._snapshot !== undefined\r\n\t}\r\n\r\n\tgetListBottomOffsetChange() {\r\n\t\tconst { itemIndex, itemTopOffset, listTopOffset } = this._snapshot\r\n\t\t// `firstShownItemIndex` is supposed to be `0` at this point,\r\n\t\t// so `renderedElementIndex` would be the same as the `itemIndex`.\r\n\t\tconst itemTopOffsetNew = this.itemsContainer.getNthRenderedItemTopOffset(itemIndex)\r\n\t\tconst listTopOffsetNew = this.getListTopOffset()\r\n\t\treturn (itemTopOffsetNew - itemTopOffset) + (listTopOffsetNew - listTopOffset)\r\n\t}\r\n\r\n\treset() {\r\n\t\tthis._snapshot = undefined\r\n\t}\r\n}"],"mappings":";;;;;;IAAqBA,qB;EACpB,qCAGG;IAAA,IAFFC,cAEE,QAFFA,cAEE;IAAA,IADFC,gBACE,QADFA,gBACE;;IAAA;;IACF,KAAKD,cAAL,GAAsBA,cAAtB;IACA,KAAKC,gBAAL,GAAwBA,gBAAxB;EACA;EAED;AACD;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;;;WACC,uDAIG;MAAA,IAHFC,aAGE,SAHFA,aAGE;MAAA,IAFFC,QAEE,SAFFA,QAEE;MAAA,IADFC,mBACE,SADFA,mBACE;;MACF;MACA;MACA,IAAIF,aAAa,CAACG,MAAd,KAAyB,CAA7B,EAAgC;QAC/B;MACA,CALC,CAOF;;;MACA,IAAID,mBAAmB,KAAK,CAA5B,EAA+B;QAC9B;MACA,CAVC,CAYF;MACA;MACA;MACA;MACA;MACA;MACA;MACA;MACA;MACA;MACA;MACA;MAEA;MACA;MACA;MACA;MACA;MACA;MACA;MACA;MACA;MACA;;;MAEA,KAAKE,SAAL,GAAiB;QAChBJ,aAAa,EAAbA,aADgB;QAEhBC,QAAQ,EAAR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