virtual-scroller 1.7.9 → 1.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.gitlab-ci.yml +1 -1
- package/CHANGELOG.md +71 -1
- package/README.md +434 -151
- package/bundle/index-bypass.html +1 -1
- package/bundle/index-dom.html +1 -1
- package/bundle/index-grid.html +1 -2
- package/bundle/index-scrollableContainer.html +1 -1
- package/bundle/index-tbody-scrollableContainer.html +2 -0
- package/bundle/index-tbody.html +2 -0
- package/bundle/virtual-scroller-dom.js +1 -1
- package/bundle/virtual-scroller-dom.js.map +1 -1
- package/bundle/virtual-scroller-react.js +1 -1
- package/bundle/virtual-scroller-react.js.map +1 -1
- package/bundle/virtual-scroller.js +1 -1
- package/bundle/virtual-scroller.js.map +1 -1
- package/commonjs/BeforeResize.js +315 -0
- package/commonjs/BeforeResize.js.map +1 -0
- package/commonjs/DOM/Engine.js +46 -0
- package/commonjs/DOM/Engine.js.map +1 -0
- package/commonjs/DOM/ItemsContainer.js +78 -0
- package/commonjs/DOM/ItemsContainer.js.map +1 -0
- package/commonjs/DOM/{WaitForStylesToLoad.js → ListTopOffsetWatcher.js} +71 -44
- package/commonjs/DOM/ListTopOffsetWatcher.js.map +1 -0
- package/commonjs/DOM/ScrollableContainer.js +69 -101
- package/commonjs/DOM/ScrollableContainer.js.map +1 -1
- package/commonjs/DOM/VirtualScroller.js +37 -29
- package/commonjs/DOM/VirtualScroller.js.map +1 -1
- package/commonjs/DOM/tbody.js +17 -11
- package/commonjs/DOM/tbody.js.map +1 -1
- package/commonjs/ItemHeights.js +33 -34
- package/commonjs/ItemHeights.js.map +1 -1
- package/commonjs/Layout.js +591 -216
- package/commonjs/Layout.js.map +1 -1
- package/commonjs/Layout.test.js +196 -0
- package/commonjs/Layout.test.js.map +1 -0
- package/commonjs/ListHeightMeasurement.js +124 -0
- package/commonjs/ListHeightMeasurement.js.map +1 -0
- package/commonjs/Resize.js +50 -39
- package/commonjs/Resize.js.map +1 -1
- package/commonjs/Scroll.js +139 -95
- package/commonjs/Scroll.js.map +1 -1
- package/commonjs/VirtualScroller.columns.js +43 -0
- package/commonjs/VirtualScroller.columns.js.map +1 -0
- package/commonjs/VirtualScroller.constructor.js +408 -0
- package/commonjs/VirtualScroller.constructor.js.map +1 -0
- package/commonjs/VirtualScroller.items.js +305 -0
- package/commonjs/VirtualScroller.items.js.map +1 -0
- package/commonjs/VirtualScroller.js +160 -1021
- package/commonjs/VirtualScroller.js.map +1 -1
- package/commonjs/VirtualScroller.layout.js +562 -0
- package/commonjs/VirtualScroller.layout.js.map +1 -0
- package/commonjs/VirtualScroller.onRender.js +357 -0
- package/commonjs/VirtualScroller.onRender.js.map +1 -0
- package/commonjs/VirtualScroller.resize.js +186 -0
- package/commonjs/VirtualScroller.resize.js.map +1 -0
- package/commonjs/VirtualScroller.state.js +301 -0
- package/commonjs/VirtualScroller.state.js.map +1 -0
- package/commonjs/VirtualScroller.verticalSpacing.js +65 -0
- package/commonjs/VirtualScroller.verticalSpacing.js.map +1 -0
- package/commonjs/getItemCoordinates.js.map +1 -1
- package/commonjs/getItemsDiff.js.map +1 -1
- package/commonjs/getVerticalSpacing.js +8 -8
- package/commonjs/getVerticalSpacing.js.map +1 -1
- package/commonjs/package.json +5 -0
- package/commonjs/react/VirtualScroller.js +182 -628
- package/commonjs/react/VirtualScroller.js.map +1 -1
- package/commonjs/react/useClassName.js +26 -0
- package/commonjs/react/useClassName.js.map +1 -0
- package/commonjs/react/useHandleItemsChange.js +116 -0
- package/commonjs/react/useHandleItemsChange.js.map +1 -0
- package/commonjs/react/useInstanceMethods.js +37 -0
- package/commonjs/react/useInstanceMethods.js.map +1 -0
- package/commonjs/react/useItemKeys.js +60 -0
- package/commonjs/react/useItemKeys.js.map +1 -0
- package/commonjs/react/useOnItemHeightChange.js +32 -0
- package/commonjs/react/useOnItemHeightChange.js.map +1 -0
- package/commonjs/react/useOnItemStateChange.js +32 -0
- package/commonjs/react/useOnItemStateChange.js.map +1 -0
- package/commonjs/react/useState.js +140 -0
- package/commonjs/react/useState.js.map +1 -0
- package/commonjs/react/useStyle.js +29 -0
- package/commonjs/react/useStyle.js.map +1 -0
- package/commonjs/react/useVirtualScroller.js +62 -0
- package/commonjs/react/useVirtualScroller.js.map +1 -0
- package/commonjs/react/useVirtualScrollerStartStop.js +20 -0
- package/commonjs/react/useVirtualScrollerStartStop.js.map +1 -0
- package/commonjs/test/Engine.js +23 -0
- package/commonjs/test/Engine.js.map +1 -0
- package/commonjs/test/ItemsContainer.js +127 -0
- package/commonjs/test/ItemsContainer.js.map +1 -0
- package/commonjs/test/ScrollableContainer.js +130 -0
- package/commonjs/test/ScrollableContainer.js.map +1 -0
- package/commonjs/test/VirtualScroller.js +281 -0
- package/commonjs/test/VirtualScroller.js.map +1 -0
- package/commonjs/utility/debounce.js +28 -6
- package/commonjs/utility/debounce.js.map +1 -1
- package/commonjs/utility/debug.js +51 -12
- package/commonjs/utility/debug.js.map +1 -1
- package/commonjs/utility/getStateSnapshot.js +50 -0
- package/commonjs/utility/getStateSnapshot.js.map +1 -0
- package/commonjs/utility/px.js +1 -1
- package/commonjs/utility/px.js.map +1 -1
- package/commonjs/utility/px.test.js +14 -0
- package/commonjs/utility/px.test.js.map +1 -0
- package/commonjs/utility/shallowEqual.js +1 -1
- package/commonjs/utility/shallowEqual.js.map +1 -1
- package/commonjs/utility/throttle.js.map +1 -1
- package/dom/index.cjs +4 -0
- package/dom/index.cjs.js +9 -0
- package/dom/index.d.ts +25 -0
- package/dom/index.js +1 -1
- package/dom/package.json +10 -4
- package/index.cjs +4 -0
- package/index.cjs.js +9 -0
- package/index.d.ts +99 -0
- package/index.js +1 -1
- package/modules/BeforeResize.js +305 -0
- package/modules/BeforeResize.js.map +1 -0
- package/modules/DOM/Engine.js +27 -0
- package/modules/DOM/Engine.js.map +1 -0
- package/modules/DOM/ItemsContainer.js +71 -0
- package/modules/DOM/ItemsContainer.js.map +1 -0
- package/modules/DOM/{WaitForStylesToLoad.js → ListTopOffsetWatcher.js} +72 -44
- package/modules/DOM/ListTopOffsetWatcher.js.map +1 -0
- package/modules/DOM/ScrollableContainer.js +68 -100
- package/modules/DOM/ScrollableContainer.js.map +1 -1
- package/modules/DOM/VirtualScroller.js +32 -28
- package/modules/DOM/VirtualScroller.js.map +1 -1
- package/modules/DOM/tbody.js +11 -9
- package/modules/DOM/tbody.js.map +1 -1
- package/modules/ItemHeights.js +28 -33
- package/modules/ItemHeights.js.map +1 -1
- package/modules/Layout.js +585 -214
- package/modules/Layout.js.map +1 -1
- package/modules/Layout.test.js +190 -0
- package/modules/Layout.test.js.map +1 -0
- package/modules/ListHeightMeasurement.js +117 -0
- package/modules/ListHeightMeasurement.js.map +1 -0
- package/modules/Resize.js +50 -39
- package/modules/Resize.js.map +1 -1
- package/modules/Scroll.js +139 -94
- package/modules/Scroll.js.map +1 -1
- package/modules/VirtualScroller.columns.js +36 -0
- package/modules/VirtualScroller.columns.js.map +1 -0
- package/modules/VirtualScroller.constructor.js +371 -0
- package/modules/VirtualScroller.constructor.js.map +1 -0
- package/modules/VirtualScroller.items.js +288 -0
- package/modules/VirtualScroller.items.js.map +1 -0
- package/modules/VirtualScroller.js +159 -1014
- package/modules/VirtualScroller.js.map +1 -1
- package/modules/VirtualScroller.layout.js +549 -0
- package/modules/VirtualScroller.layout.js.map +1 -0
- package/modules/VirtualScroller.onRender.js +337 -0
- package/modules/VirtualScroller.onRender.js.map +1 -0
- package/modules/VirtualScroller.resize.js +176 -0
- package/modules/VirtualScroller.resize.js.map +1 -0
- package/modules/VirtualScroller.state.js +283 -0
- package/modules/VirtualScroller.state.js.map +1 -0
- package/modules/VirtualScroller.verticalSpacing.js +54 -0
- package/modules/VirtualScroller.verticalSpacing.js.map +1 -0
- package/modules/getItemCoordinates.js.map +1 -1
- package/modules/getItemsDiff.js.map +1 -1
- package/modules/getVerticalSpacing.js +8 -8
- package/modules/getVerticalSpacing.js.map +1 -1
- package/modules/react/VirtualScroller.js +179 -634
- package/modules/react/VirtualScroller.js.map +1 -1
- package/modules/react/useClassName.js +18 -0
- package/modules/react/useClassName.js.map +1 -0
- package/modules/react/useHandleItemsChange.js +108 -0
- package/modules/react/useHandleItemsChange.js.map +1 -0
- package/modules/react/useInstanceMethods.js +28 -0
- package/modules/react/useInstanceMethods.js.map +1 -0
- package/modules/react/useItemKeys.js +52 -0
- package/modules/react/useItemKeys.js.map +1 -0
- package/modules/react/useOnItemHeightChange.js +24 -0
- package/modules/react/useOnItemHeightChange.js.map +1 -0
- package/modules/react/useOnItemStateChange.js +24 -0
- package/modules/react/useOnItemStateChange.js.map +1 -0
- package/modules/react/useState.js +132 -0
- package/modules/react/useState.js.map +1 -0
- package/modules/react/useStyle.js +19 -0
- package/modules/react/useStyle.js.map +1 -0
- package/modules/react/useVirtualScroller.js +51 -0
- package/modules/react/useVirtualScroller.js.map +1 -0
- package/modules/react/useVirtualScrollerStartStop.js +12 -0
- package/modules/react/useVirtualScrollerStartStop.js.map +1 -0
- package/modules/test/Engine.js +11 -0
- package/modules/test/Engine.js.map +1 -0
- package/modules/test/ItemsContainer.js +120 -0
- package/modules/test/ItemsContainer.js.map +1 -0
- package/modules/test/ScrollableContainer.js +123 -0
- package/modules/test/ScrollableContainer.js.map +1 -0
- package/modules/test/VirtualScroller.js +270 -0
- package/modules/test/VirtualScroller.js.map +1 -0
- package/modules/utility/debounce.js +28 -6
- package/modules/utility/debounce.js.map +1 -1
- package/modules/utility/debug.js +47 -10
- package/modules/utility/debug.js.map +1 -1
- package/modules/utility/getStateSnapshot.js +43 -0
- package/modules/utility/getStateSnapshot.js.map +1 -0
- package/modules/utility/px.js +1 -1
- package/modules/utility/px.js.map +1 -1
- package/modules/utility/px.test.js +9 -0
- package/modules/utility/px.test.js.map +1 -0
- package/modules/utility/shallowEqual.js +1 -1
- package/modules/utility/shallowEqual.js.map +1 -1
- package/modules/utility/throttle.js.map +1 -1
- package/package.json +54 -29
- package/react/index.cjs +4 -0
- package/react/index.cjs.js +9 -0
- package/react/index.d.ts +28 -0
- package/react/index.js +1 -1
- package/react/package.json +10 -4
- package/rollup.config.mjs +62 -0
- package/runnable/create-commonjs-package-json.js +11 -0
- package/source/BeforeResize.js +312 -0
- package/source/DOM/Engine.js +30 -0
- package/source/DOM/ItemsContainer.js +48 -0
- package/source/DOM/{WaitForStylesToLoad.js → ListTopOffsetWatcher.js} +61 -30
- package/source/DOM/ScrollableContainer.js +51 -73
- package/source/DOM/VirtualScroller.js +33 -18
- package/source/DOM/tbody.js +30 -21
- package/source/ItemHeights.js +27 -27
- package/source/Layout.js +629 -252
- package/source/Layout.test.js +176 -0
- package/source/ListHeightMeasurement.js +95 -0
- package/source/Resize.js +56 -32
- package/source/Scroll.js +135 -82
- package/source/VirtualScroller.columns.js +26 -0
- package/source/VirtualScroller.constructor.js +336 -0
- package/source/VirtualScroller.items.js +302 -0
- package/source/VirtualScroller.js +162 -936
- package/source/VirtualScroller.layout.js +539 -0
- package/source/VirtualScroller.onRender.js +345 -0
- package/source/VirtualScroller.resize.js +189 -0
- package/source/VirtualScroller.state.js +284 -0
- package/source/VirtualScroller.verticalSpacing.js +51 -0
- package/source/getVerticalSpacing.js +7 -7
- package/source/react/VirtualScroller.js +243 -603
- package/source/react/useClassName.js +14 -0
- package/source/react/useHandleItemsChange.js +115 -0
- package/source/react/useInstanceMethods.js +25 -0
- package/source/react/useItemKeys.js +59 -0
- package/source/react/useOnItemHeightChange.js +28 -0
- package/source/react/useOnItemStateChange.js +28 -0
- package/source/react/useState.js +114 -0
- package/source/react/useStyle.js +20 -0
- package/source/react/useVirtualScroller.js +59 -0
- package/source/react/useVirtualScrollerStartStop.js +12 -0
- package/source/test/Engine.js +11 -0
- package/source/test/ItemsContainer.js +87 -0
- package/source/test/ScrollableContainer.js +88 -0
- package/source/test/VirtualScroller.js +232 -0
- package/source/utility/debounce.js +22 -5
- package/source/utility/debug.js +34 -3
- package/source/utility/getStateSnapshot.js +36 -0
- package/source/utility/px.js +1 -1
- package/source/utility/px.test.js +9 -0
- package/website/index-bypass.html +195 -0
- package/website/index-grid.html +0 -1
- package/website/index-scrollableContainer.html +208 -0
- package/website/index-tbody-scrollableContainer.html +68 -0
- package/website/index-tbody.html +55 -0
- package/commonjs/DOM/RenderingEngine.js +0 -33
- package/commonjs/DOM/RenderingEngine.js.map +0 -1
- package/commonjs/DOM/Screen.js +0 -87
- package/commonjs/DOM/Screen.js.map +0 -1
- package/commonjs/DOM/WaitForStylesToLoad.js.map +0 -1
- package/commonjs/RestoreScroll.js +0 -118
- package/commonjs/RestoreScroll.js.map +0 -1
- package/dom/index.commonjs.js +0 -4
- package/index.commonjs.js +0 -4
- package/modules/DOM/RenderingEngine.js +0 -19
- package/modules/DOM/RenderingEngine.js.map +0 -1
- package/modules/DOM/Screen.js +0 -80
- package/modules/DOM/Screen.js.map +0 -1
- package/modules/DOM/WaitForStylesToLoad.js.map +0 -1
- package/modules/RestoreScroll.js +0 -111
- package/modules/RestoreScroll.js.map +0 -1
- package/react/index.commonjs.js +0 -4
- package/source/DOM/RenderingEngine.js +0 -22
- package/source/DOM/Screen.js +0 -51
- package/source/RestoreScroll.js +0 -86
package/modules/Layout.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../source/Layout.js"],"names":["log","Layout","bypass","estimatedItemHeight","measureItemsBatchSize","getVerticalSpacing","getColumnsCount","getItemHeight","getAverageItemHeight","itemsCount","visibleAreaHeightIncludingMargins","estimatedRowsCount","getEstimatedRowsCountForHeight","firstShownItemIndex","lastShownItemIndex","getLastShownItemIndex","beforeItemsHeight","afterItemsHeight","Math","min","height","getEstimatedItemHeight","ceil","layout","prependedItemsCount","appendedItemsCount","columnsCount","prependedRowsCount","appendedRowsCount","averageItemHeight","verticalSpacing","getBeforeItemsHeight","getAfterItemsHeight","visibleAreaTop","visibleAreaBottom","listTopOffset","previousRowsHeight","rowsCount","rowIndex","hasMoreRows","verticalSpaceAfterCurrentRow","currentRowHeight","columnIndex","i","itemHeight","undefined","heightLeft","firstNonMeasuredItemIndex","max","_getVisibleItemIndexes","redoLayoutAfterMeasuringItemHeights","maxAllowedLastShownItemIndex","listHeight","isVisible","indexes","getVisibleItemIndexes","firstShownRowIndex","floor","rowHeight","lastShownRowIndex","visibleAreaIncludingMargins","listTopOffsetInsideScrollableContainer","getItemIndexes","top","bottom","getNonVisibleListShownItemIndexes","LAYOUT_REASON","SCROLL","STOPPED_SCROLLING","MANUAL","MOUNT","ITEM_HEIGHT_NOT_MEASURED","RESIZE","ITEM_HEIGHT_CHANGED","ITEMS_CHANGED","TOP_OFFSET_CHANGED"],"mappings":";;;;;;AAAA,OAAOA,GAAP,MAAgB,iBAAhB;;IAEqBC,M;;;AACpB,wBAQG;AAAA,QAPFC,MAOE,QAPFA,MAOE;AAAA,QANFC,mBAME,QANFA,mBAME;AAAA,QALFC,qBAKE,QALFA,qBAKE;AAAA,QAJFC,kBAIE,QAJFA,kBAIE;AAAA,QAHFC,eAGE,QAHFA,eAGE;AAAA,QAFFC,aAEE,QAFFA,aAEE;AAAA,QADFC,oBACE,QADFA,oBACE;;AAAA;;AACF,SAAKN,MAAL,GAAcA,MAAd;AACA,SAAKC,mBAAL,GAA2BA,mBAA3B;AACA,SAAKC,qBAAL,GAA6BA,qBAA7B;AACA,SAAKC,kBAAL,GAA0BA,kBAA1B;AACA,SAAKC,eAAL,GAAuBA,eAAvB;AACA,SAAKC,aAAL,GAAqBA,aAArB;AACA,SAAKC,oBAAL,GAA4BA,oBAA5B;AACA;;;;kDAME;AAAA,UAHFN,MAGE,SAHFA,MAGE;AAAA,UAFFO,UAEE,SAFFA,UAEE;AAAA,UADFC,iCACE,SADFA,iCACE;AACF;AACA;AACA,UAAMC,kBAAkB,GAAGD,iCAAiC,GACzD,KAAKE,8BAAL,CAAoCF,iCAApC,CADyD,GAEzD,CAFH;AAGA,UAAIG,mBAAJ;AACA,UAAIC,kBAAJ,CAPE,CAQF;;AACA,UAAIL,UAAU,GAAG,CAAjB,EA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G5BC,EAAAA,MAAM,EAAE,QAHoB;AAI5BC,EAAAA,KAAK,EAAE,OAJqB;AAK5BC,EAAAA,wBAAwB,EAAE,mCALE;AAM5BC,EAAAA,MAAM,EAAE,QANoB;AAO5BC,EAAAA,mBAAmB,EAAE,qBAPO;AAQ5BC,EAAAA,aAAa,EAAE,eARa;AAS5BC,EAAAA,kBAAkB,EAAE;AATQ,CAAtB","sourcesContent":["import log 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\tgetVerticalSpacing,\r\n\t\tgetColumnsCount,\r\n\t\tgetItemHeight,\r\n\t\tgetAverageItemHeight\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.getVerticalSpacing = getVerticalSpacing\r\n\t\tthis.getColumnsCount = getColumnsCount\r\n\t\tthis.getItemHeight = getItemHeight\r\n\t\tthis.getAverageItemHeight = getAverageItemHeight\r\n\t}\r\n\r\n\tgetInitialLayoutValues({\r\n\t\tbypass,\r\n\t\titemsCount,\r\n\t\tvisibleAreaHeightIncludingMargins\r\n\t}) {\r\n\t\t// On server side, at initialization time, there's no \"visible area height\",\r\n\t\t// so default to `1` estimated rows count.\r\n\t\tconst estimatedRowsCount = visibleAreaHeightIncludingMargins\r\n\t\t\t? this.getEstimatedRowsCountForHeight(visibleAreaHeightIncludingMargins)\r\n\t\t\t: 1\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.getLastShownItemIndex(\r\n\t\t\t\tfirstShownItemIndex,\r\n\t\t\t\titemsCount,\r\n\t\t\t\testimatedRowsCount,\r\n\t\t\t\tbypass\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\tgetLastShownItemIndex(\r\n\t\tfirstShownItemIndex,\r\n\t\titemsCount,\r\n\t\testimatedRowsCount,\r\n\t\tbypass\r\n\t) {\r\n\t\tif (this.bypass || bypass) {\r\n\t\t\treturn itemsCount - 1\r\n\t\t}\r\n\t\treturn Math.min(\r\n\t\t\tfirstShownItemIndex + (estimatedRowsCount * this.getColumnsCount() - 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\tif (estimatedItemHeight) {\r\n\t\t\treturn Math.ceil((height + this.getVerticalSpacing()) / (estimatedItemHeight + this.getVerticalSpacing()))\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\tupdateLayoutForItemsDiff(layout, {\r\n\t\tprependedItemsCount,\r\n\t\tappendedItemsCount\r\n\t}, {\r\n\t\titemsCount\r\n\t}) {\r\n\t\tlayout.firstShownItemIndex += prependedItemsCount\r\n\t\tlayout.lastShownItemIndex += prependedItemsCount\r\n\t\tconst columnsCount = this.getColumnsCount()\r\n\t\tif (prependedItemsCount % columnsCount === 0) {\r\n\t\t\t// If the layout stays the same, then simply increase\r\n\t\t\t// the top and bottom margins proportionally to the amount\r\n\t\t\t// of the items added.\r\n\t\t\tconst prependedRowsCount = prependedItemsCount / columnsCount\r\n\t\t\tconst appendedRowsCount = Math.ceil(appendedItemsCount / columnsCount)\r\n\t\t\tconst averageItemHeight = this.getAverageItemHeight()\r\n\t\t\tconst verticalSpacing = this.getVerticalSpacing()\r\n\t\t\tlayout.beforeItemsHeight += prependedRowsCount * (averageItemHeight + verticalSpacing)\r\n\t\t\tlayout.afterItemsHeight += appendedRowsCount * (verticalSpacing + averageItemHeight)\r\n\t\t} else {\r\n\t\t\t// Rows will be rebalanced as a result of prepending the items,\r\n\t\t\t// and the row heights can change as a result, so recalculate\r\n\t\t\t// `beforeItemsHeight` and `afterItemsHeight` from scratch.\r\n\t\t\t// `this.itemHeights[]` and `firstShownItemIndex`/`lastShownItemIndex`\r\n\t\t\t// have already been updated at this point.\r\n\t\t\tlayout.beforeItemsHeight = this.getBeforeItemsHeight(\r\n\t\t\t\tlayout.firstShownItemIndex,\r\n\t\t\t\tlayout.lastShownItemIndex\r\n\t\t\t)\r\n\t\t\tlayout.afterItemsHeight = this.getAfterItemsHeight(\r\n\t\t\t\tlayout.firstShownItemIndex,\r\n\t\t\t\tlayout.lastShownItemIndex,\r\n\t\t\t\titemsCount\r\n\t\t\t)\r\n\t\t}\r\n\t}\r\n\r\n\t_getVisibleItemIndexes(\r\n\t\tvisibleAreaTop,\r\n\t\tvisibleAreaBottom,\r\n\t\tlistTopOffset,\r\n\t\titemsCount\r\n\t) {\r\n\t\tconst columnsCount = this.getColumnsCount()\r\n\t\tlet firstShownItemIndex\r\n\t\tlet lastShownItemIndex\r\n\t\tlet previousRowsHeight = 0\r\n\t\tconst rowsCount = Math.ceil(itemsCount / columnsCount)\r\n\t\tlet rowIndex = 0\r\n\t\twhile (rowIndex < rowsCount) {\r\n\t\t\tconst hasMoreRows = itemsCount > (rowIndex + 1) * columnsCount\r\n\t\t\tconst verticalSpaceAfterCurrentRow = hasMoreRows ? this.getVerticalSpacing() : 0\r\n\t\t\tlet currentRowHeight = 0\r\n\t\t\tlet columnIndex = 0\r\n\t\t\tlet i\r\n\t\t\twhile (columnIndex < columnsCount\r\n\t\t\t\t&& (i = rowIndex * columnsCount + columnIndex) < itemsCount) {\r\n\t\t\t\tconst itemHeight = this.getItemHeight(i)\r\n\t\t\t\t// If an item that hasn't been shown (and measured) yet is encountered\r\n\t\t\t\t// then show such item and then retry after it has been measured.\r\n\t\t\t\tif (itemHeight === undefined) {\r\n\t\t\t\t\tlog(`Item index ${i} lies within the visible area or its \"margins\", but its height hasn't been measured yet. Mark the item as \"shown\", render the list, measure the item's height and redo the layout.`)\r\n\t\t\t\t\tif (firstShownItemIndex === undefined) {\r\n\t\t\t\t\t\tfirstShownItemIndex = rowIndex * columnsCount\r\n\t\t\t\t\t}\r\n\t\t\t\t\tconst heightLeft = visibleAreaBottom - (listTopOffset + previousRowsHeight)\r\n\t\t\t\t\tlastShownItemIndex = Math.min(\r\n\t\t\t\t\t\t(rowIndex + this.getEstimatedRowsCountForHeight(heightLeft)) * columnsCount - 1,\r\n\t\t\t\t\t\t// Guard against index overflow.\r\n\t\t\t\t\t\titemsCount - 1\r\n\t\t\t\t\t)\r\n\t\t\t\t\treturn {\r\n\t\t\t\t\t\tfirstNonMeasuredItemIndex: i,\r\n\t\t\t\t\t\tfirstShownItemIndex,\r\n\t\t\t\t\t\tlastShownItemIndex\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t\tcurrentRowHeight = Math.max(currentRowHeight, itemHeight)\r\n\t\t\t\t// If this is the first item visible\r\n\t\t\t\t// then start showing items from this row.\r\n\t\t\t\tif (firstShownItemIndex === undefined) {\r\n\t\t\t\t\tif (listTopOffset + previousRowsHeight + currentRowHeight > visibleAreaTop) {\r\n\t\t\t\t\t\tlog('First shown row index', rowIndex)\r\n\t\t\t\t\t\tfirstShownItemIndex = rowIndex * columnsCount\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t\t// If this item is the last one visible in the viewport then exit.\r\n\t\t\t\tif (listTopOffset + previousRowsHeight + currentRowHeight + verticalSpaceAfterCurrentRow > visibleAreaBottom) {\r\n\t\t\t\t\tlog('Last shown row index', rowIndex)\r\n\t\t\t\t\t// The list height is estimated until all items have been seen,\r\n\t\t\t\t\t// so it's possible that even when the list DOM element happens\r\n\t\t\t\t\t// to be in the viewport in reality the list isn't visible\r\n\t\t\t\t\t// in which case `firstShownItemIndex` will be `undefined`.\r\n\t\t\t\t\tif (firstShownItemIndex !== undefined) {\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\t(rowIndex + 1) * 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\treturn {\r\n\t\t\t\t\t\tfirstShownItemIndex,\r\n\t\t\t\t\t\tlastShownItemIndex\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t\tcolumnIndex++\r\n\t\t\t}\r\n\t\t\tpreviousRowsHeight += currentRowHeight\r\n\t\t\t// If there're more rows below the current row, then add vertical spacing.\r\n\t\t\tpreviousRowsHeight += verticalSpaceAfterCurrentRow\r\n\t\t\trowIndex++\r\n\t\t}\r\n\t\t// If there're no more items then the last item is the last one to show.\r\n\t\tif (firstShownItemIndex !== undefined && lastShownItemIndex === undefined) {\r\n\t\t\tlastShownItemIndex = itemsCount - 1\r\n\t\t\tlog('Last item index (is fully visible)', lastShownItemIndex)\r\n\t\t}\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// Finds the items which are displayed in the viewport.\r\n\tgetVisibleItemIndexes(\r\n\t\tvisibleAreaTop,\r\n\t\tvisibleAreaBottom,\r\n\t\tlistTopOffset,\r\n\t\titemsCount\r\n\t) {\r\n\t\tlet {\r\n\t\t\tfirstNonMeasuredItemIndex,\r\n\t\t\tfirstShownItemIndex,\r\n\t\t\tlastShownItemIndex\r\n\t\t} = this._getVisibleItemIndexes(\r\n\t\t\tvisibleAreaTop,\r\n\t\t\tvisibleAreaBottom,\r\n\t\t\tlistTopOffset,\r\n\t\t\titemsCount\r\n\t\t)\r\n\t\tconst redoLayoutAfterMeasuringItemHeights = firstNonMeasuredItemIndex !== undefined\r\n\t\t// If some items will be rendered in order to measure their height,\r\n\t\t// and it's not a `preserveScrollPositionOnPrependItems` case,\r\n\t\t// then limit the amount of such items being measured in a single pass.\r\n\t\tif (redoLayoutAfterMeasuringItemHeights && this.measureItemsBatchSize) {\r\n\t\t\tconst maxAllowedLastShownItemIndex = firstNonMeasuredItemIndex + this.measureItemsBatchSize - 1\r\n\t\t\tconst columnsCount = this.getColumnsCount()\r\n\t\t\tlastShownItemIndex = Math.min(\r\n\t\t\t\t// Also guards against index overflow.\r\n\t\t\t\tlastShownItemIndex,\r\n\t\t\t\t// The index of the last item in the row.\r\n\t\t\t\tMath.ceil(maxAllowedLastShownItemIndex / columnsCount) * columnsCount - 1\r\n\t\t\t)\r\n\t\t}\r\n\t\treturn {\r\n\t\t\tfirstShownItemIndex,\r\n\t\t\tlastShownItemIndex,\r\n\t\t\tredoLayoutAfterMeasuringItemHeights\r\n\t\t}\r\n\t}\r\n\r\n\tgetNonVisibleListShownItemIndexes() {\r\n\t\treturn {\r\n\t\t\tfirstShownItemIndex: 0,\r\n\t\t\tlastShownItemIndex: 0,\r\n\t\t\tredoLayoutAfterMeasuringItemHeights: this.getItemHeight(0) === undefined\r\n\t\t}\r\n\t}\r\n\r\n\tgetItemIndexes(\r\n\t\tvisibleAreaTop,\r\n\t\tvisibleAreaBottom,\r\n\t\tlistTopOffset,\r\n\t\tlistHeight,\r\n\t\titemsCount\r\n\t) {\r\n\t\tconst isVisible = listTopOffset + listHeight > visibleAreaTop && listTopOffset < visibleAreaBottom\r\n\t\tif (!isVisible) {\r\n\t\t\tlog('The entire list is off-screen. No items are visible.')\r\n\t\t\treturn\r\n\t\t}\r\n\t\t// Find the items which are displayed in the viewport.\r\n\t\tconst indexes = this.getVisibleItemIndexes(\r\n\t\t\tvisibleAreaTop,\r\n\t\t\tvisibleAreaBottom,\r\n\t\t\tlistTopOffset,\r\n\t\t\titemsCount\r\n\t\t)\r\n\t\t// The list height is estimated until all items have been seen,\r\n\t\t// so it's possible that even when the list DOM element happens\r\n\t\t// to be in the viewport, in reality the list isn't visible\r\n\t\t// in which case `firstShownItemIndex` will be `undefined`.\r\n\t\tif (indexes.firstShownItemIndex === undefined) {\r\n\t\t\tlog('The entire list is off-screen. No items are visible.')\r\n\t\t\treturn\r\n\t\t}\r\n\t\treturn indexes\r\n\t}\r\n\r\n\t/**\r\n\t * Measures \"before\" items height.\r\n\t * @param {number} firstShownItemIndex — New first shown item index.\r\n\t * @param {number} lastShownItemIndex — New last shown item index.\r\n\t * @return {number}\r\n\t */\r\n\tgetBeforeItemsHeight(\r\n\t\tfirstShownItemIndex,\r\n\t\tlastShownItemIndex\r\n\t) {\r\n\t\tconst columnsCount = this.getColumnsCount()\r\n\t\tconst firstShownRowIndex = Math.floor(firstShownItemIndex / columnsCount)\r\n\t\tlet beforeItemsHeight = 0\r\n\t\t// Add all \"before\" items height.\r\n\t\tlet rowIndex = 0\r\n\t\twhile (rowIndex < firstShownRowIndex) {\r\n\t\t\tlet rowHeight = 0\r\n\t\t\tlet columnIndex = 0\r\n\t\t\twhile (columnIndex < columnsCount) {\r\n\t\t\t\trowHeight = Math.max(\r\n\t\t\t\t\trowHeight,\r\n\t\t\t\t\tthis.getItemHeight(rowIndex * columnsCount + columnIndex)\r\n\t\t\t\t\t\t|| this.getAverageItemHeight()\r\n\t\t\t\t)\r\n\t\t\t\tcolumnIndex++\r\n\t\t\t}\r\n\t\t\tbeforeItemsHeight += rowHeight\r\n\t\t\tbeforeItemsHeight += this.getVerticalSpacing()\r\n\t\t\trowIndex++\r\n\t\t}\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} firstShownItemIndex — New first shown item index.\r\n\t * @param {number} lastShownItemIndex — New last shown item index.\r\n\t * @param {number} averageItemHeight — Average item height.\r\n\t * @param {number} verticalSpacing — Item vertical spacing.\r\n\t * @param {number} itemsCount — Items count.\r\n\t * @return {number}\r\n\t */\r\n\tgetAfterItemsHeight(\r\n\t\tfirstShownItemIndex,\r\n\t\tlastShownItemIndex,\r\n\t\titemsCount\r\n\t) {\r\n\t\tconst columnsCount = this.getColumnsCount()\r\n\t\tconst rowsCount = Math.ceil(itemsCount / columnsCount)\r\n\t\tconst lastShownRowIndex = Math.floor(lastShownItemIndex / columnsCount)\r\n\t\tlet afterItemsHeight = 0\r\n\t\tlet rowIndex = lastShownRowIndex + 1\r\n\t\twhile (rowIndex < rowsCount) {\r\n\t\t\tlet rowHeight = 0\r\n\t\t\tlet columnIndex = 0\r\n\t\t\tlet i\r\n\t\t\twhile (columnIndex < columnsCount\r\n\t\t\t\t&& (i = rowIndex * columnsCount + columnIndex) < itemsCount) {\r\n\t\t\t\trowHeight = Math.max(\r\n\t\t\t\t\trowHeight,\r\n\t\t\t\t\tthis.getItemHeight(i) || this.getAverageItemHeight()\r\n\t\t\t\t)\r\n\t\t\t\tcolumnIndex++\r\n\t\t\t}\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\trowIndex++\r\n\t\t}\r\n\t\treturn afterItemsHeight\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, redoLayoutAfterMeasuringItemHeights: boolean }`\r\n\t */\r\n\tgetShownItemIndexes({\r\n\t\tlistHeight,\r\n\t\titemsCount,\r\n\t\tvisibleAreaIncludingMargins,\r\n\t\tlistTopOffsetInsideScrollableContainer\r\n\t}) {\r\n\t\tif (this.bypass) {\r\n\t\t\treturn {\r\n\t\t\t\tfirstShownItemIndex: 0,\r\n\t\t\t\tlastShownItemIndex: itemsCount - 1\r\n\t\t\t}\r\n\t\t}\r\n\t\t// Finds the indexes of the items that are currently visible\r\n\t\t// (or close to being visible) in the scrollable container.\r\n\t\t// For scrollable containers other than the main screen, it could also\r\n\t\t// check the visibility of such scrollable container itself, because it\r\n\t\t// might be not visible.\r\n\t\t// If such kind of an optimization would hypothetically be implemented,\r\n\t\t// then it would also require listening for \"scroll\" events on the screen.\r\n\t\t// Overall, I suppose that such \"actual visibility\" feature would be\r\n\t\t// a very minor optimization and not something I'd deal with.\r\n\t\treturn this.getItemIndexes(\r\n\t\t\tvisibleAreaIncludingMargins.top,\r\n\t\t\tvisibleAreaIncludingMargins.bottom,\r\n\t\t\tlistTopOffsetInsideScrollableContainer,\r\n\t\t\tlistHeight,\r\n\t\t\titemsCount\r\n\t\t) || this.getNonVisibleListShownItemIndexes()\r\n\t}\r\n\r\n\tshowItemsFromTheStart(layout) {\r\n\t\tlayout.firstShownItemIndex = 0\r\n\t\tlayout.beforeItemsHeight = 0\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\tMOUNT: 'mount',\r\n\tITEM_HEIGHT_NOT_MEASURED: 'some item height wasn\\'t measured',\r\n\tRESIZE: 'resize',\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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AA1C,CAArB;MAEA,IAAI6E,QAAQ,GAAG,CAAf;;MACA,OAAOA,QAAQ,GAAGD,YAAlB,EAAgC;QAC/B,IAAIN,UAAS,GAAG,CAAhB;QACA,IAAIV,WAAW,GAAG,CAAlB;;QACA,OAAOA,WAAW,GAAG,KAAK5D,eAAL,EAArB,EAA6C;UAC5C,IAAM6D,UAAU,GAAG,KAAK3D,aAAL,CAClBkD,sBAAsB,GAAGyB,QAAQ,GAAG,KAAK7E,eAAL,EAApC,GAA6D4D,WAD3C,CAAnB;;UAGA,IAAIC,UAAU,KAAKtB,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"}
|
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
import Layout from './Layout.js';
|
|
2
|
+
import Engine from './test/Engine.js';
|
|
3
|
+
describe('Layout', function () {
|
|
4
|
+
it('should work', function () {
|
|
5
|
+
var SCREEN_HEIGHT = 400;
|
|
6
|
+
var scrollableContainer = {
|
|
7
|
+
width: 800,
|
|
8
|
+
height: SCREEN_HEIGHT
|
|
9
|
+
};
|
|
10
|
+
var ITEM_WIDTH = scrollableContainer.width;
|
|
11
|
+
var ITEM_HEIGHT = 200;
|
|
12
|
+
var VERTICAL_SPACING = 100;
|
|
13
|
+
var items = new Array(9).fill(ITEM_WIDTH * ITEM_HEIGHT);
|
|
14
|
+
var layout = new Layout({
|
|
15
|
+
getPrerenderMargin: function getPrerenderMargin() {
|
|
16
|
+
return SCREEN_HEIGHT;
|
|
17
|
+
},
|
|
18
|
+
getVerticalSpacing: function getVerticalSpacing() {
|
|
19
|
+
return VERTICAL_SPACING;
|
|
20
|
+
},
|
|
21
|
+
getColumnsCount: function getColumnsCount() {
|
|
22
|
+
return 1;
|
|
23
|
+
},
|
|
24
|
+
getItemHeight: function getItemHeight(i) {
|
|
25
|
+
return items[i] / scrollableContainer.width;
|
|
26
|
+
},
|
|
27
|
+
getBeforeResizeItemsCount: function getBeforeResizeItemsCount() {
|
|
28
|
+
return 0;
|
|
29
|
+
},
|
|
30
|
+
getAverageItemHeight: function getAverageItemHeight() {
|
|
31
|
+
return ITEM_HEIGHT;
|
|
32
|
+
},
|
|
33
|
+
getScrollableContainerHeight: function getScrollableContainerHeight() {
|
|
34
|
+
return scrollableContainer.height;
|
|
35
|
+
}
|
|
36
|
+
}); // Initial render.
|
|
37
|
+
|
|
38
|
+
layout.getShownItemIndexes({
|
|
39
|
+
itemsCount: items.length,
|
|
40
|
+
visibleAreaTop: 0,
|
|
41
|
+
visibleAreaBottom: SCREEN_HEIGHT
|
|
42
|
+
}).should.deep.equal({
|
|
43
|
+
firstShownItemIndex: 0,
|
|
44
|
+
lastShownItemIndex: 2
|
|
45
|
+
}); // The first item is almost hidden.
|
|
46
|
+
|
|
47
|
+
layout.getShownItemIndexes({
|
|
48
|
+
itemsCount: items.length,
|
|
49
|
+
visibleAreaTop: SCREEN_HEIGHT + ITEM_HEIGHT - 1,
|
|
50
|
+
visibleAreaBottom: SCREEN_HEIGHT + ITEM_HEIGHT - 1 + SCREEN_HEIGHT
|
|
51
|
+
}).should.deep.equal({
|
|
52
|
+
firstShownItemIndex: 0,
|
|
53
|
+
lastShownItemIndex: 4
|
|
54
|
+
}); // The first item is hidden.
|
|
55
|
+
|
|
56
|
+
layout.getShownItemIndexes({
|
|
57
|
+
itemsCount: items.length,
|
|
58
|
+
visibleAreaTop: SCREEN_HEIGHT + ITEM_HEIGHT,
|
|
59
|
+
visibleAreaBottom: SCREEN_HEIGHT + ITEM_HEIGHT + SCREEN_HEIGHT
|
|
60
|
+
}).should.deep.equal({
|
|
61
|
+
firstShownItemIndex: 1,
|
|
62
|
+
lastShownItemIndex: 4
|
|
63
|
+
}); // A new item at the bottom is almost visible.
|
|
64
|
+
|
|
65
|
+
layout.getShownItemIndexes({
|
|
66
|
+
itemsCount: items.length,
|
|
67
|
+
visibleAreaTop: (ITEM_HEIGHT + VERTICAL_SPACING) * 5 - SCREEN_HEIGHT * 2,
|
|
68
|
+
visibleAreaBottom: (ITEM_HEIGHT + VERTICAL_SPACING) * 5 - SCREEN_HEIGHT
|
|
69
|
+
}).should.deep.equal({
|
|
70
|
+
firstShownItemIndex: 1,
|
|
71
|
+
lastShownItemIndex: 4
|
|
72
|
+
}); // A new item at the bottom is visible.
|
|
73
|
+
|
|
74
|
+
layout.getShownItemIndexes({
|
|
75
|
+
itemsCount: items.length,
|
|
76
|
+
visibleAreaTop: (ITEM_HEIGHT + VERTICAL_SPACING) * 5 + 1 - SCREEN_HEIGHT * 2,
|
|
77
|
+
visibleAreaBottom: (ITEM_HEIGHT + VERTICAL_SPACING) * 5 + 1 - SCREEN_HEIGHT
|
|
78
|
+
}).should.deep.equal({
|
|
79
|
+
firstShownItemIndex: 1,
|
|
80
|
+
lastShownItemIndex: 5
|
|
81
|
+
});
|
|
82
|
+
});
|
|
83
|
+
it('should update layout for items incremental change', function () {
|
|
84
|
+
var scrollableContainer = {
|
|
85
|
+
width: 800,
|
|
86
|
+
height: 400
|
|
87
|
+
};
|
|
88
|
+
var ITEM_WIDTH = scrollableContainer.width;
|
|
89
|
+
var ITEM_HEIGHT = 200;
|
|
90
|
+
var items = new Array(9).fill(ITEM_WIDTH * ITEM_HEIGHT);
|
|
91
|
+
var VERTICAL_SPACING = 100;
|
|
92
|
+
var layout = new Layout({
|
|
93
|
+
getPrerenderMargin: function getPrerenderMargin() {
|
|
94
|
+
return scrollableContainer.height;
|
|
95
|
+
},
|
|
96
|
+
getVerticalSpacing: function getVerticalSpacing() {
|
|
97
|
+
return VERTICAL_SPACING;
|
|
98
|
+
},
|
|
99
|
+
getColumnsCount: function getColumnsCount() {
|
|
100
|
+
return 1;
|
|
101
|
+
},
|
|
102
|
+
getItemHeight: function getItemHeight(i) {
|
|
103
|
+
return ITEM_HEIGHT;
|
|
104
|
+
},
|
|
105
|
+
getBeforeResizeItemsCount: function getBeforeResizeItemsCount() {
|
|
106
|
+
return 0;
|
|
107
|
+
},
|
|
108
|
+
getAverageItemHeight: function getAverageItemHeight() {
|
|
109
|
+
return ITEM_HEIGHT;
|
|
110
|
+
},
|
|
111
|
+
getScrollableContainerHeight: function getScrollableContainerHeight() {
|
|
112
|
+
return scrollableContainer.height;
|
|
113
|
+
}
|
|
114
|
+
});
|
|
115
|
+
layout.getLayoutUpdateForItemsDiff({
|
|
116
|
+
firstShownItemIndex: 3,
|
|
117
|
+
lastShownItemIndex: 5,
|
|
118
|
+
beforeItemsHeight: 3 * (ITEM_HEIGHT + VERTICAL_SPACING),
|
|
119
|
+
afterItemsHeight: 3 * (ITEM_HEIGHT + VERTICAL_SPACING)
|
|
120
|
+
}, {
|
|
121
|
+
prependedItemsCount: 5,
|
|
122
|
+
appendedItemsCount: 5
|
|
123
|
+
}, {
|
|
124
|
+
itemsCount: 5 + 5 + items.length,
|
|
125
|
+
columnsCount: 1
|
|
126
|
+
}).should.deep.equal({
|
|
127
|
+
firstShownItemIndex: 5 + 3,
|
|
128
|
+
lastShownItemIndex: 5 + 5,
|
|
129
|
+
beforeItemsHeight: (5 + 3) * (ITEM_HEIGHT + VERTICAL_SPACING),
|
|
130
|
+
afterItemsHeight: (3 + 5) * (ITEM_HEIGHT + VERTICAL_SPACING)
|
|
131
|
+
});
|
|
132
|
+
});
|
|
133
|
+
it('should update layout for items incremental change (rows get rebalanced)', function () {
|
|
134
|
+
var scrollableContainer = {
|
|
135
|
+
width: 800,
|
|
136
|
+
height: 400
|
|
137
|
+
};
|
|
138
|
+
var ITEM_WIDTH = scrollableContainer.width;
|
|
139
|
+
var ITEM_HEIGHT = 400;
|
|
140
|
+
var items = new Array(9).fill(ITEM_WIDTH * ITEM_HEIGHT);
|
|
141
|
+
var VERTICAL_SPACING = 100;
|
|
142
|
+
var layout = new Layout({
|
|
143
|
+
getPrerenderMargin: function getPrerenderMargin() {
|
|
144
|
+
return scrollableContainer.height;
|
|
145
|
+
},
|
|
146
|
+
getVerticalSpacing: function getVerticalSpacing() {
|
|
147
|
+
return VERTICAL_SPACING;
|
|
148
|
+
},
|
|
149
|
+
getColumnsCount: function getColumnsCount() {
|
|
150
|
+
return 4;
|
|
151
|
+
},
|
|
152
|
+
getItemHeight: function getItemHeight() {
|
|
153
|
+
return ITEM_HEIGHT;
|
|
154
|
+
},
|
|
155
|
+
getBeforeResizeItemsCount: function getBeforeResizeItemsCount() {
|
|
156
|
+
return 0;
|
|
157
|
+
},
|
|
158
|
+
getAverageItemHeight: function getAverageItemHeight() {
|
|
159
|
+
return ITEM_HEIGHT;
|
|
160
|
+
},
|
|
161
|
+
getScrollableContainerHeight: function getScrollableContainerHeight() {
|
|
162
|
+
return scrollableContainer.height;
|
|
163
|
+
}
|
|
164
|
+
});
|
|
165
|
+
var shouldResetGridLayout;
|
|
166
|
+
layout.getLayoutUpdateForItemsDiff({
|
|
167
|
+
firstShownItemIndex: 3,
|
|
168
|
+
lastShownItemIndex: 5,
|
|
169
|
+
beforeItemsHeight: 3 * (ITEM_HEIGHT + VERTICAL_SPACING),
|
|
170
|
+
afterItemsHeight: 3 * (ITEM_HEIGHT + VERTICAL_SPACING)
|
|
171
|
+
}, {
|
|
172
|
+
prependedItemsCount: 5,
|
|
173
|
+
appendedItemsCount: 5
|
|
174
|
+
}, {
|
|
175
|
+
itemsCount: 5 + 5 + items.length,
|
|
176
|
+
columnsCount: 4,
|
|
177
|
+
shouldRestoreScrollPosition: true,
|
|
178
|
+
onResetGridLayout: function onResetGridLayout() {
|
|
179
|
+
return shouldResetGridLayout = true;
|
|
180
|
+
}
|
|
181
|
+
}).should.deep.equal({
|
|
182
|
+
firstShownItemIndex: 0,
|
|
183
|
+
lastShownItemIndex: 5 + 5,
|
|
184
|
+
beforeItemsHeight: 0,
|
|
185
|
+
afterItemsHeight: 5 * (ITEM_HEIGHT + VERTICAL_SPACING)
|
|
186
|
+
});
|
|
187
|
+
shouldResetGridLayout.should.equal(true);
|
|
188
|
+
});
|
|
189
|
+
});
|
|
190
|
+
//# sourceMappingURL=Layout.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
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,IAAMC,KAAK,GAAG,IAAIC,KAAJ,CAAU,CAAV,EAAaC,IAAb,CAAkB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E,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"}
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
2
|
+
|
|
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
|
+
|
|
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
|
+
|
|
7
|
+
var ListHeightMeasurement = /*#__PURE__*/function () {
|
|
8
|
+
function ListHeightMeasurement(_ref) {
|
|
9
|
+
var itemsContainer = _ref.itemsContainer,
|
|
10
|
+
getListTopOffset = _ref.getListTopOffset;
|
|
11
|
+
|
|
12
|
+
_classCallCheck(this, ListHeightMeasurement);
|
|
13
|
+
|
|
14
|
+
this.itemsContainer = itemsContainer;
|
|
15
|
+
this.getListTopOffset = getListTopOffset;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
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.
|
|
23
|
+
* @param {any[]} previousItems
|
|
24
|
+
* @param {any[]} newItems
|
|
25
|
+
* @param {number} prependedItemsCount
|
|
26
|
+
*/
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
_createClass(ListHeightMeasurement, [{
|
|
30
|
+
key: "snapshotListHeightBeforeAddingNewItems",
|
|
31
|
+
value: function snapshotListHeightBeforeAddingNewItems(_ref2) {
|
|
32
|
+
var previousItems = _ref2.previousItems,
|
|
33
|
+
newItems = _ref2.newItems,
|
|
34
|
+
prependedItemsCount = _ref2.prependedItemsCount;
|
|
35
|
+
|
|
36
|
+
// If there were no items in the list
|
|
37
|
+
// then there's no point in restoring scroll position.
|
|
38
|
+
if (previousItems.length === 0) {
|
|
39
|
+
return;
|
|
40
|
+
} // If no items were prepended then no need to restore scroll position.
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
if (prependedItemsCount === 0) {
|
|
44
|
+
return;
|
|
45
|
+
} // The first item is supposed to be shown when the user clicks
|
|
46
|
+
// "Show previous items" button. If it isn't shown though,
|
|
47
|
+
// could still calculate the first item's top position using
|
|
48
|
+
// the values from `itemHeights` and `verticalSpacing`.
|
|
49
|
+
// But that would be a weird non-realistic scenario.
|
|
50
|
+
// if (firstShownItemIndex > 0) {
|
|
51
|
+
// let i = firstShownItemIndex - 1
|
|
52
|
+
// while (i >= 0) {
|
|
53
|
+
// firstItemTopOffset += itemHeights[i] + verticalSpacing
|
|
54
|
+
// i--
|
|
55
|
+
// }
|
|
56
|
+
// }
|
|
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
|
+
// }
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
this._snapshot = {
|
|
70
|
+
previousItems: previousItems,
|
|
71
|
+
newItems: newItems,
|
|
72
|
+
itemIndex: prependedItemsCount,
|
|
73
|
+
itemTopOffset: this.itemsContainer.getNthRenderedItemTopOffset(0),
|
|
74
|
+
// Snapshot list top offset inside the scrollable container too
|
|
75
|
+
// because it's common to hide the "Show previous items" button
|
|
76
|
+
// when the user has browsed to the top of the list, which causes
|
|
77
|
+
// the list's top position to shift upwards due to the button
|
|
78
|
+
// no longer being rendered. Tracking list top offset doesn't
|
|
79
|
+
// fit here that well, but it makes sense in real-world applications.
|
|
80
|
+
listTopOffset: this.getListTopOffset()
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
}, {
|
|
84
|
+
key: "getAnchorItemIndex",
|
|
85
|
+
value: function getAnchorItemIndex() {
|
|
86
|
+
return this._snapshot.itemIndex;
|
|
87
|
+
}
|
|
88
|
+
}, {
|
|
89
|
+
key: "hasSnapshot",
|
|
90
|
+
value: function hasSnapshot() {
|
|
91
|
+
return this._snapshot !== undefined;
|
|
92
|
+
}
|
|
93
|
+
}, {
|
|
94
|
+
key: "getListBottomOffsetChange",
|
|
95
|
+
value: function getListBottomOffsetChange() {
|
|
96
|
+
var _this$_snapshot = this._snapshot,
|
|
97
|
+
itemIndex = _this$_snapshot.itemIndex,
|
|
98
|
+
itemTopOffset = _this$_snapshot.itemTopOffset,
|
|
99
|
+
listTopOffset = _this$_snapshot.listTopOffset; // `firstShownItemIndex` is supposed to be `0` at this point,
|
|
100
|
+
// so `renderedElementIndex` would be the same as the `itemIndex`.
|
|
101
|
+
|
|
102
|
+
var itemTopOffsetNew = this.itemsContainer.getNthRenderedItemTopOffset(itemIndex);
|
|
103
|
+
var listTopOffsetNew = this.getListTopOffset();
|
|
104
|
+
return itemTopOffsetNew - itemTopOffset + (listTopOffsetNew - listTopOffset);
|
|
105
|
+
}
|
|
106
|
+
}, {
|
|
107
|
+
key: "reset",
|
|
108
|
+
value: function reset() {
|
|
109
|
+
this._snapshot = undefined;
|
|
110
|
+
}
|
|
111
|
+
}]);
|
|
112
|
+
|
|
113
|
+
return ListHeightMeasurement;
|
|
114
|
+
}();
|
|
115
|
+
|
|
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,EAARA,QAFgB;QAGhBI,SAAS,EAAEH,mBAHK;QAIhBI,aAAa,EAAE,KAAKR,cAAL,CAAoBS,2BAApB,CAAgD,CAAhD,CAJC;QAKhB;QACA;QACA;QACA;QACA;QACA;QACAC,aAAa,EAAE,KAAKT,gBAAL;MAXC,CAAjB;IAaA;;;WAED,8BAAqB;MACpB,OAAO,KAAKK,SAAL,CAAeC,SAAtB;IACA;;;WAED,uBAAc;M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