virtual-scroller 1.14.0 → 1.15.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.
Files changed (235) hide show
  1. package/CHANGELOG.md +29 -0
  2. package/README.md +403 -254
  3. package/bundle/index-dom-bypass.html +197 -0
  4. package/bundle/index-dom-grid.html +203 -0
  5. package/bundle/index-dom-scrollableContainer.html +214 -0
  6. package/bundle/index-dom-tbody-scrollableContainer.html +81 -0
  7. package/bundle/index-dom-tbody.html +65 -0
  8. package/bundle/index-dom.html +114 -84
  9. package/bundle/index-react-bypass.html +194 -0
  10. package/bundle/{index-bypass.html → index-react-grid.html} +122 -120
  11. package/bundle/index-react-hook.html +209 -0
  12. package/bundle/index-react-scrollableContainer.html +207 -0
  13. package/bundle/index-react-strictMode.html +193 -0
  14. package/bundle/index-react-tbody-scrollableContainer.html +94 -0
  15. package/bundle/index-react-tbody.html +78 -0
  16. package/bundle/{messages.js → items.js} +1 -1
  17. package/bundle/lib/babel.min.js +25 -0
  18. package/bundle/lib/prop-types.min.js +1 -0
  19. package/bundle/lib/react-dom.development.js +29924 -0
  20. package/bundle/lib/react-dom.production.min.js +267 -0
  21. package/bundle/lib/react.development.js +3343 -0
  22. package/bundle/lib/react.production.min.js +31 -0
  23. package/bundle/style.base.css +33 -0
  24. package/{website/style.css → bundle/style.list.css} +10 -43
  25. package/bundle/style.list.grid.css +23 -0
  26. package/bundle/virtual-scroller-dom.js +1 -1
  27. package/bundle/virtual-scroller-dom.js.map +1 -1
  28. package/bundle/virtual-scroller-react.js +1 -1
  29. package/bundle/virtual-scroller-react.js.map +1 -1
  30. package/bundle/virtual-scroller.js +1 -1
  31. package/bundle/virtual-scroller.js.map +1 -1
  32. package/commonjs/BeforeResize.js +1 -2
  33. package/commonjs/BeforeResize.js.map +1 -1
  34. package/commonjs/DOM/VirtualScroller.js +7 -13
  35. package/commonjs/DOM/VirtualScroller.js.map +1 -1
  36. package/commonjs/DOM/tbody.js +6 -6
  37. package/commonjs/DOM/tbody.js.map +1 -1
  38. package/commonjs/ItemHeights.js +10 -13
  39. package/commonjs/ItemHeights.js.map +1 -1
  40. package/commonjs/Layout.defaults.js +21 -0
  41. package/commonjs/Layout.defaults.js.map +1 -0
  42. package/commonjs/Layout.js +75 -64
  43. package/commonjs/Layout.js.map +1 -1
  44. package/commonjs/Layout.test.js +8 -4
  45. package/commonjs/Layout.test.js.map +1 -1
  46. package/commonjs/VirtualScroller.constructor.js +38 -4
  47. package/commonjs/VirtualScroller.constructor.js.map +1 -1
  48. package/commonjs/VirtualScroller.items.js +50 -4
  49. package/commonjs/VirtualScroller.items.js.map +1 -1
  50. package/commonjs/VirtualScroller.js +23 -14
  51. package/commonjs/VirtualScroller.js.map +1 -1
  52. package/commonjs/VirtualScroller.layout.js +40 -29
  53. package/commonjs/VirtualScroller.layout.js.map +1 -1
  54. package/commonjs/VirtualScroller.onContainerResize.js +1 -2
  55. package/commonjs/VirtualScroller.onContainerResize.js.map +1 -1
  56. package/commonjs/VirtualScroller.state.js +10 -9
  57. package/commonjs/VirtualScroller.state.js.map +1 -1
  58. package/commonjs/VirtualScroller.verticalSpacing.js +39 -6
  59. package/commonjs/VirtualScroller.verticalSpacing.js.map +1 -1
  60. package/commonjs/react/VirtualScroller.js +124 -131
  61. package/commonjs/react/VirtualScroller.js.map +1 -1
  62. package/commonjs/react/useClassName.js +2 -2
  63. package/commonjs/react/useClassName.js.map +1 -1
  64. package/commonjs/react/useCreateVirtualScroller.js +64 -0
  65. package/commonjs/react/useCreateVirtualScroller.js.map +1 -0
  66. package/commonjs/react/useInstanceMethods.js +4 -4
  67. package/commonjs/react/useInstanceMethods.js.map +1 -1
  68. package/commonjs/react/useItemKeys.js +28 -5
  69. package/commonjs/react/useItemKeys.js.map +1 -1
  70. package/commonjs/react/useMergeRefs.js +52 -0
  71. package/commonjs/react/useMergeRefs.js.map +1 -0
  72. package/commonjs/react/useOnItemHeightDidChange.js +28 -12
  73. package/commonjs/react/useOnItemHeightDidChange.js.map +1 -1
  74. package/commonjs/react/useSetItemState.js +31 -12
  75. package/commonjs/react/useSetItemState.js.map +1 -1
  76. package/commonjs/react/{useVirtualScrollerStartStop.js → useStartStopVirtualScroller.js} +1 -1
  77. package/commonjs/react/{useVirtualScrollerStartStop.js.map → useStartStopVirtualScroller.js.map} +1 -1
  78. package/commonjs/react/useState.js +9 -9
  79. package/commonjs/react/useState.js.map +1 -1
  80. package/commonjs/react/{useStateNoStaleBug.js → useStateWithRepeatableRead.js} +3 -3
  81. package/commonjs/react/useStateWithRepeatableRead.js.map +1 -0
  82. package/commonjs/react/useStyle.js +28 -4
  83. package/commonjs/react/useStyle.js.map +1 -1
  84. package/commonjs/react/useValidateTableBodyItemsContainer.js +24 -0
  85. package/commonjs/react/useValidateTableBodyItemsContainer.js.map +1 -0
  86. package/commonjs/react/useVirtualScroller.js +142 -42
  87. package/commonjs/react/useVirtualScroller.js.map +1 -1
  88. package/commonjs/test/ItemsContainer.js +10 -10
  89. package/commonjs/test/ItemsContainer.js.map +1 -1
  90. package/commonjs/test/VirtualScroller.js +25 -10
  91. package/commonjs/test/VirtualScroller.js.map +1 -1
  92. package/dom/index.d.ts +6 -5
  93. package/index.d.ts +19 -8
  94. package/modules/BeforeResize.js +1 -2
  95. package/modules/BeforeResize.js.map +1 -1
  96. package/modules/DOM/VirtualScroller.js +7 -13
  97. package/modules/DOM/VirtualScroller.js.map +1 -1
  98. package/modules/DOM/tbody.js +4 -4
  99. package/modules/DOM/tbody.js.map +1 -1
  100. package/modules/ItemHeights.js +11 -14
  101. package/modules/ItemHeights.js.map +1 -1
  102. package/modules/Layout.defaults.js +11 -0
  103. package/modules/Layout.defaults.js.map +1 -0
  104. package/modules/Layout.js +74 -64
  105. package/modules/Layout.js.map +1 -1
  106. package/modules/Layout.test.js +8 -4
  107. package/modules/Layout.test.js.map +1 -1
  108. package/modules/VirtualScroller.constructor.js +37 -4
  109. package/modules/VirtualScroller.constructor.js.map +1 -1
  110. package/modules/VirtualScroller.items.js +51 -5
  111. package/modules/VirtualScroller.items.js.map +1 -1
  112. package/modules/VirtualScroller.js +23 -14
  113. package/modules/VirtualScroller.js.map +1 -1
  114. package/modules/VirtualScroller.layout.js +40 -29
  115. package/modules/VirtualScroller.layout.js.map +1 -1
  116. package/modules/VirtualScroller.onContainerResize.js +1 -2
  117. package/modules/VirtualScroller.onContainerResize.js.map +1 -1
  118. package/modules/VirtualScroller.state.js +10 -9
  119. package/modules/VirtualScroller.state.js.map +1 -1
  120. package/modules/VirtualScroller.verticalSpacing.js +38 -6
  121. package/modules/VirtualScroller.verticalSpacing.js.map +1 -1
  122. package/modules/react/VirtualScroller.js +122 -124
  123. package/modules/react/VirtualScroller.js.map +1 -1
  124. package/modules/react/useClassName.js +3 -3
  125. package/modules/react/useClassName.js.map +1 -1
  126. package/modules/react/useCreateVirtualScroller.js +53 -0
  127. package/modules/react/useCreateVirtualScroller.js.map +1 -0
  128. package/modules/react/useInstanceMethods.js +4 -4
  129. package/modules/react/useInstanceMethods.js.map +1 -1
  130. package/modules/react/useItemKeys.js +28 -5
  131. package/modules/react/useItemKeys.js.map +1 -1
  132. package/modules/react/useMergeRefs.js +44 -0
  133. package/modules/react/useMergeRefs.js.map +1 -0
  134. package/modules/react/useOnItemHeightDidChange.js +28 -12
  135. package/modules/react/useOnItemHeightDidChange.js.map +1 -1
  136. package/modules/react/useSetItemState.js +31 -12
  137. package/modules/react/useSetItemState.js.map +1 -1
  138. package/modules/react/{useVirtualScrollerStartStop.js → useStartStopVirtualScroller.js} +1 -1
  139. package/modules/react/{useVirtualScrollerStartStop.js.map → useStartStopVirtualScroller.js.map} +1 -1
  140. package/modules/react/useState.js +9 -9
  141. package/modules/react/useState.js.map +1 -1
  142. package/modules/react/{useStateNoStaleBug.js → useStateWithRepeatableRead.js} +2 -2
  143. package/modules/react/useStateWithRepeatableRead.js.map +1 -0
  144. package/modules/react/useStyle.js +27 -4
  145. package/modules/react/useStyle.js.map +1 -1
  146. package/modules/react/useValidateTableBodyItemsContainer.js +16 -0
  147. package/modules/react/useValidateTableBodyItemsContainer.js.map +1 -0
  148. package/modules/react/useVirtualScroller.js +136 -42
  149. package/modules/react/useVirtualScroller.js.map +1 -1
  150. package/modules/test/ItemsContainer.js +10 -10
  151. package/modules/test/ItemsContainer.js.map +1 -1
  152. package/modules/test/VirtualScroller.js +25 -10
  153. package/modules/test/VirtualScroller.js.map +1 -1
  154. package/package.json +4 -1
  155. package/react/as.d.ts +42 -0
  156. package/react/index.cjs +2 -1
  157. package/react/index.d.ts +248 -63
  158. package/react/index.js +1 -0
  159. package/rollup.config.mjs +15 -1
  160. package/source/BeforeResize.js +1 -2
  161. package/source/DOM/VirtualScroller.js +7 -13
  162. package/source/DOM/tbody.js +5 -5
  163. package/source/ItemHeights.js +11 -12
  164. package/source/Layout.defaults.js +8 -0
  165. package/source/Layout.js +66 -53
  166. package/source/Layout.test.js +7 -2
  167. package/source/VirtualScroller.constructor.js +27 -4
  168. package/source/VirtualScroller.items.js +47 -2
  169. package/source/VirtualScroller.js +23 -14
  170. package/source/VirtualScroller.layout.js +41 -28
  171. package/source/VirtualScroller.onContainerResize.js +1 -2
  172. package/source/VirtualScroller.state.js +10 -11
  173. package/source/VirtualScroller.verticalSpacing.js +32 -6
  174. package/source/react/VirtualScroller.js +135 -133
  175. package/source/react/useClassName.js +3 -3
  176. package/source/react/useCreateVirtualScroller.js +65 -0
  177. package/source/react/useInstanceMethods.js +12 -4
  178. package/source/react/useItemKeys.js +22 -4
  179. package/source/react/useMergeRefs.js +45 -0
  180. package/source/react/useOnItemHeightDidChange.js +29 -10
  181. package/source/react/useSetItemState.js +32 -10
  182. package/source/react/useState.js +6 -6
  183. package/source/react/{useStateNoStaleBug.js → useStateWithRepeatableRead.js} +1 -1
  184. package/source/react/useStyle.js +18 -2
  185. package/source/react/useValidateTableBodyItemsContainer.js +16 -0
  186. package/source/react/useVirtualScroller.js +155 -47
  187. package/source/test/ItemsContainer.js +10 -10
  188. package/source/test/VirtualScroller.js +16 -10
  189. package/website/index-dom-bypass.html +197 -0
  190. package/website/index-dom-grid.html +203 -0
  191. package/website/index-dom-scrollableContainer.html +214 -0
  192. package/website/index-dom-tbody-scrollableContainer.html +81 -0
  193. package/website/index-dom-tbody.html +65 -0
  194. package/website/index-dom.html +116 -84
  195. package/website/index-react-bypass.html +194 -0
  196. package/website/index-react-grid.html +197 -0
  197. package/website/index-react-hook.html +209 -0
  198. package/website/index-react-scrollableContainer.html +207 -0
  199. package/website/index-react-strictMode.html +193 -0
  200. package/website/index-react-tbody-scrollableContainer.html +94 -0
  201. package/website/index-react-tbody.html +78 -0
  202. package/website/index-react.html +193 -0
  203. package/website/index.html +120 -111
  204. package/website/{messages.js → items.js} +1 -1
  205. package/website/lib/babel.min.js +25 -0
  206. package/website/lib/prop-types.min.js +1 -0
  207. package/website/lib/react-dom.development.js +29924 -0
  208. package/website/lib/react-dom.production.min.js +267 -0
  209. package/website/lib/react.development.js +3343 -0
  210. package/website/lib/react.production.min.js +31 -0
  211. package/website/style.base.css +33 -0
  212. package/website/style.list.css +92 -0
  213. package/website/style.list.grid.css +23 -0
  214. package/bundle/index-grid.html +0 -216
  215. package/bundle/index-scrollableContainer.html +0 -208
  216. package/bundle/index-tbody-scrollableContainer.html +0 -70
  217. package/bundle/index-tbody.html +0 -57
  218. package/bundle/on-scroll-to-dom.js +0 -2
  219. package/bundle/on-scroll-to-dom.js.map +0 -1
  220. package/bundle/on-scroll-to-react.js +0 -2
  221. package/bundle/on-scroll-to-react.js.map +0 -1
  222. package/bundle/on-scroll-to.js +0 -2
  223. package/bundle/on-scroll-to.js.map +0 -1
  224. package/commonjs/react/useStateNoStaleBug.js.map +0 -1
  225. package/modules/react/useStateNoStaleBug.js.map +0 -1
  226. package/website/index-bypass.html +0 -185
  227. package/website/index-grid.html +0 -216
  228. package/website/index-scrollableContainer.html +0 -208
  229. package/website/index-tbody-scrollableContainer.html +0 -70
  230. package/website/index-tbody.html +0 -57
  231. package/website/lib/on-scroll-to-dom.js +0 -2
  232. package/website/lib/on-scroll-to-dom.js.map +0 -1
  233. package/website/lib/on-scroll-to-react.js +0 -2
  234. package/website/lib/on-scroll-to-react.js.map +0 -1
  235. /package/source/react/{useVirtualScrollerStartStop.js → useStartStopVirtualScroller.js} +0 -0
@@ -183,8 +183,7 @@ var BeforeResize = /*#__PURE__*/function () {
183
183
  key: "snapshotBeforeResizeItemHeights",
184
184
  value: function snapshotBeforeResizeItemHeights(_ref2) {
185
185
  var firstShownItemIndex = _ref2.firstShownItemIndex,
186
- newFirstShownItemIndex = _ref2.newFirstShownItemIndex,
187
- newColumnsCount = _ref2.newColumnsCount;
186
+ newFirstShownItemIndex = _ref2.newFirstShownItemIndex;
188
187
  var columnsCount = this.getColumnsCount();
189
188
  var verticalSpacing = this.getVerticalSpacing();
190
189
  this._includesBeforeResizeInState = true;
@@ -1 +1 @@
1
- {"version":3,"file":"BeforeResize.js","names":["BeforeResize","getState","getVerticalSpacing","getColumnsCount","state","_includesBeforeResizeInState","Boolean","beforeResize","firstShownItemIndex","lastShownItemIndex","itemHeights","length","log","newlyShownItemRowsHeight","prevFirstReMeasuredItemsRowIndex","Math","floor","newlyShownItemsToIndex","min","i","rowHeight","columnIndex","itemHeight","undefined","getAverageItemHeight","max","cleanedUpBeforeResizeItemRowsHeight","maxParticipatingBeforeResizeItemsCount","participatingBeforeResizeItemRowsCount","ceil","columnsCount","firstCleanedUpBeforeResizeItemsRowIndex","k","verticalSpacing","firstDroppedBeforeResizeItemIndex","lastDroppedBeforeResizeItemIndex","slice","splice","scrollBy","newFirstShownItemIndex","newColumnsCount","prevBeforeResize","prevBeforeResizeItemsCount","prevBeforeResizeBeforeItemsHeight","prevBeforeResizeItemRowsCount","rowIndex","newBeforeResizeAdditionalBeforeItemsHeight","newBeforeResizeBeforeItemsHeight","newBeforeResizeBeforeItemRowsCount","Array","fill","concat","equalizeItemHeights","maxItemsCount","cleanUpBeforeResizeState"],"sources":["../source/BeforeResize.js"],"sourcesContent":["import log from './utility/debug.js'\r\n\r\nexport default class BeforeResize {\r\n\tconstructor({\r\n\t\tgetState,\r\n\t\tgetVerticalSpacing,\r\n\t\tgetColumnsCount\r\n\t}) {\r\n\t\tthis.getState = getState\r\n\t\tthis.getVerticalSpacing = getVerticalSpacing\r\n\t\tthis.getColumnsCount = getColumnsCount\r\n\t}\r\n\r\n\tinitializeFromState(state) {\r\n\t\tthis._includesBeforeResizeInState = Boolean(state.beforeResize)\r\n\t}\r\n\r\n\t// Cleans up \"before resize\" item heights and adjusts the scroll position accordingly.\r\n\t//\r\n\t// Hypothetically, it could also wait for the user to stop scrolling and only then\r\n\t// adjust the scroll position. The rationale is that if `window.scrollTo()` is called\r\n\t// while the user is scrolling, the user would occasionally experience \"lost\" mouse wheel\r\n\t// events when scrolling with a mouse wheel.\r\n\t//\r\n\t// Seems like Twitter's website waits for the user to stop scrolling before applying\r\n\t// the scroll position correction after a window resize. This library could do that too,\r\n\t// but that would require rewriting \"before items height\" top padding calculation\r\n\t// so that it doesn't re-calculate it on every re-render and instead does so incrementally,\r\n\t// and then, when the user stops, it re-calculates it from scratch removing the error\r\n\t// and adjusting the scroll position accordingly so that there's no \"jump of content\".\r\n\t//\r\n\t// But, seems like it works fine as it is and there's no need to rewrite anything.\r\n\t//\r\n\tcleanUpBeforeResizeItemHeights() {\r\n\t\tconst {\r\n\t\t\tfirstShownItemIndex,\r\n\t\t\tlastShownItemIndex,\r\n\t\t\titemHeights,\r\n\t\t\tbeforeResize\r\n\t\t} = this.getState()\r\n\r\n\t\t// If there're \"before resize\" properties in `state`\r\n\t\t// then it means that the corresponding items are waiting to be\r\n\t\t// re-measured after container resize. Since the resize,\r\n\t\t// some of those non-re-measured items might have just been measured,\r\n\t\t// so see if that's true, and if it is, remove those now-obsolete\r\n\t\t// \"before resize\" item heights and ajust the scroll position\r\n\t\t// so that there's no \"content jumping\".\r\n\r\n\t\tif (beforeResize) {\r\n\t\t\t// If the user has scrolled up to reveal a previously hidden item\r\n\t\t\t// that has not yet been re-measured after a previous resize.\r\n\t\t\tif (firstShownItemIndex < beforeResize.itemHeights.length) {\r\n\t\t\t\tlog('~ Clean up \"before resize\" item heights and correct scroll position ~')\r\n\r\n\t\t\t\t// Some of the \"before\" items have been un-hidden and re-measured.\r\n\t\t\t\t// Un-hiding those items would result in a \"jump of content\"\r\n\t\t\t\t// because \"before resize\" heights of those un-hidden items\r\n\t\t\t\t// could (and most likely will) be different from the current ones,\r\n\t\t\t\t// or because \"before resize\" columns count is different from\r\n\t\t\t\t// the current one.\r\n\t\t\t\t// To prevent a \"jump of content\", calculate the scroll position\r\n\t\t\t\t// difference and adjust the scroll position.\r\n\r\n\t\t\t\t// The height of the item rows that have transitioned\r\n\t\t\t\t// from hidden to shown.\r\n\t\t\t\tlet newlyShownItemRowsHeight = 0\r\n\r\n\t\t\t\t// Some of the `itemHeights` between the current `firstShownItemIndex` and\r\n\t\t\t\t// the previous `firstShownItemIndex` could stay `undefined` if the user\r\n\t\t\t\t// scrolled \"abruptly\": for example, by using a `window.scrollTo()` call.\r\n\t\t\t\t// In that case, the items below the visible ones won't be rendered and measured.\r\n\t\t\t\t// In such case, limit the items being iterated over to the current `lastShownItemIndex`\r\n\t\t\t\t// rather than the previous `firstShownItemIndex`.\r\n\t\t\t\tconst prevFirstReMeasuredItemsRowIndex = Math.floor(beforeResize.itemHeights.length / this.getColumnsCount())\r\n\t\t\t\tconst newlyShownItemsToIndex = Math.min(\r\n\t\t\t\t\tprevFirstReMeasuredItemsRowIndex * this.getColumnsCount() - 1,\r\n\t\t\t\t\tlastShownItemIndex\r\n\t\t\t\t)\r\n\r\n\t\t\t\tlet i = firstShownItemIndex\r\n\t\t\t\twhile (i <= newlyShownItemsToIndex) {\r\n\t\t\t\t\t// Calculate newly shown row height.\r\n\t\t\t\t\tlet rowHeight = 0\r\n\t\t\t\t\tlet columnIndex = 0\r\n\t\t\t\t\twhile (columnIndex < this.getColumnsCount() && i <= newlyShownItemsToIndex) {\r\n\t\t\t\t\t\tlet itemHeight = itemHeights[i]\r\n\t\t\t\t\t\tif (itemHeight === undefined) {\r\n\t\t\t\t\t\t\t// `itemHeight` can only be `undefined` when not `beforeResize`.\r\n\t\t\t\t\t\t\t// Use the current \"average item height\" as a substitute.\r\n\t\t\t\t\t\t\titemHeight = this.getAverageItemHeight()\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t\trowHeight = Math.max(rowHeight, itemHeight)\r\n\t\t\t\t\t\ti++\r\n\t\t\t\t\t\tcolumnIndex++\r\n\t\t\t\t\t}\r\n\t\t\t\t\t// Append to the total \"newly shown item rows height\".\r\n\t\t\t\t\tnewlyShownItemRowsHeight += rowHeight\r\n\t\t\t\t\tnewlyShownItemRowsHeight += this.getVerticalSpacing()\r\n\t\t\t\t}\r\n\r\n\t\t\t\t// The height of the \"before resize\" item rows\r\n\t\t\t\t// that will be \"cleaned up\" in this function call.\r\n\t\t\t\tlet cleanedUpBeforeResizeItemRowsHeight = 0\r\n\r\n\t\t\t\t// Some of the `beforeResize` item rows might have been skipped if the user\r\n\t\t\t\t// scrolled up \"abruptly\": for example, by using a `window.scrollTo()` call.\r\n\t\t\t\t// In that case, the \"before resize\" items below the bottom border of the screen\r\n\t\t\t\t// shouldn't be accounted for when calculating the scrollbar adjustment shift\r\n\t\t\t\t// because items after `lastShownItemIndex` aren't participating in the calculation\r\n\t\t\t\t// of `newlyShownItemRowsHeight`.\r\n\t\t\t\tconst maxParticipatingBeforeResizeItemsCount = Math.min(beforeResize.itemHeights.length, lastShownItemIndex + 1)\r\n\t\t\t\tconst participatingBeforeResizeItemRowsCount = Math.ceil(maxParticipatingBeforeResizeItemsCount / beforeResize.columnsCount)\r\n\r\n\t\t\t\tconst firstCleanedUpBeforeResizeItemsRowIndex = firstShownItemIndex === 0\r\n\t\t\t\t\t? 0\r\n\t\t\t\t\t: Math.floor((firstShownItemIndex - 1) / beforeResize.columnsCount) + 1\r\n\r\n\t\t\t\tlet k = firstCleanedUpBeforeResizeItemsRowIndex\r\n\t\t\t\twhile (k < participatingBeforeResizeItemRowsCount) {\r\n\t\t\t\t\tconst rowHeight = beforeResize.itemHeights[k * beforeResize.columnsCount]\r\n\t\t\t\t\tcleanedUpBeforeResizeItemRowsHeight += rowHeight\r\n\t\t\t\t\tcleanedUpBeforeResizeItemRowsHeight += beforeResize.verticalSpacing\r\n\t\t\t\t\tk++\r\n\t\t\t\t}\r\n\r\n\t\t\t\t// Schedule an asynchronous `this.updateState()` call that will update\r\n\t\t\t\t// `beforeResize` property of `state`. Ideally, it should be updated\r\n\t\t\t\t// immediately, but since `this.updateState()` calls are asynchronous,\r\n\t\t\t\t// the code updates just the underlying `beforeResize.itemHeights`\r\n\t\t\t\t// array immediately instead, which is still a hack but still a lesser one.\r\n\t\t\t\tif (firstShownItemIndex === 0) {\r\n\t\t\t\t\tlog('Drop all \"before resize\" item heights')\r\n\t\t\t\t} else {\r\n\t\t\t\t\tconst firstDroppedBeforeResizeItemIndex = firstShownItemIndex\r\n\t\t\t\t\tconst lastDroppedBeforeResizeItemIndex = beforeResize.itemHeights.length - 1\r\n\t\t\t\t\tif (firstDroppedBeforeResizeItemIndex === lastDroppedBeforeResizeItemIndex) {\r\n\t\t\t\t\t\tlog('For item index', firstDroppedBeforeResizeItemIndex, '— drop \"before resize\" height', beforeResize.itemHeights[firstDroppedBeforeResizeItemIndex], )\r\n\t\t\t\t\t} else {\r\n\t\t\t\t\t\tlog('For item indexes from', firstDroppedBeforeResizeItemIndex, 'to', lastDroppedBeforeResizeItemIndex, '— drop \"before resize\" heights', beforeResize.itemHeights.slice(firstDroppedBeforeResizeItemIndex))\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\r\n\t\t\t\t// Immediately update `beforeResize.itemHeights`\r\n\t\t\t\t// so that the component isn't left in an inconsistent state\r\n\t\t\t\t// before a `this.updateState()` call below is applied.\r\n\t\t\t\tbeforeResize.itemHeights.splice(\r\n\t\t\t\t\tfirstShownItemIndex,\r\n\t\t\t\t\tbeforeResize.itemHeights.length - firstShownItemIndex\r\n\t\t\t\t)\r\n\r\n\t\t\t\t// Return the \"scroll by\" amount that would correct the scroll position.\r\n\t\t\t\t// Also return a state update.\r\n\t\t\t\treturn {\r\n\t\t\t\t\tscrollBy: newlyShownItemRowsHeight - cleanedUpBeforeResizeItemRowsHeight,\r\n\t\t\t\t\tbeforeResize: firstShownItemIndex === 0 ? undefined : {\r\n\t\t\t\t\t\t// Simply change the \"reference\" to `beforeResize` while leaving\r\n\t\t\t\t\t\t// its contents unchanged. That simply indicates that it has been updated:\r\n\t\t\t\t\t\t// `beforeResize.itemHeights` array length has been changed \"directly\".\r\n\t\t\t\t\t\t...beforeResize\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\r\n\t// Snapshots \"before resize\" values in order to preserve the currently\r\n\t// shown items' vertical position on screen so that there's no \"content jumping\".\r\n\t//\r\n\t// `newFirstShownItemIndex` is `> 0`.\r\n\t//\r\n\tsnapshotBeforeResizeItemHeights({\r\n\t\tfirstShownItemIndex,\r\n\t\tnewFirstShownItemIndex,\r\n\t\tnewColumnsCount\r\n\t}) {\r\n\t\tconst columnsCount = this.getColumnsCount()\r\n\t\tconst verticalSpacing = this.getVerticalSpacing()\r\n\r\n\t\tthis._includesBeforeResizeInState = true\r\n\r\n\t\tconst {\r\n\t\t\tbeforeResize: prevBeforeResize,\r\n\t\t\titemHeights\r\n\t\t} = this.getState()\r\n\r\n\t\tconst prevBeforeResizeItemsCount = prevBeforeResize\r\n\t\t\t? prevBeforeResize.itemHeights.length\r\n\t\t\t: 0\r\n\r\n\t\t// If there already are \"before resize\" values in `state`\r\n\t\t// then it means that those should be merged with the new ones.\r\n\t\t//\r\n\t\t// `beforeResize.itemHeights` could be empty in an edge case\r\n\t\t// when there's a pending state update that sets `beforeResize`\r\n\t\t// to `undefined`, and in that case empty `beforeResize.itemHeights`\r\n\t\t// signals about that type of a situation.\r\n\t\t//\r\n\t\tif (prevBeforeResizeItemsCount > 0) {\r\n\t\t\t// Because the \"previous\" before resize values might have been captured\r\n\t\t\t// for a window width corresponding to a layout with a different columns count\r\n\t\t\t// and different vertical spacing, re-calculate those item heights as if\r\n\t\t\t// they corresponded to the current columns count and current vertical spacing,\r\n\t\t\t// since \"previous\" and \"new\" before resize item heights are gonna be merged.\r\n\t\t\tif (\r\n\t\t\t\tprevBeforeResize.columnsCount !== columnsCount ||\r\n\t\t\t\tprevBeforeResize.verticalSpacing !== verticalSpacing\r\n\t\t\t) {\r\n\t\t\t\tlet prevBeforeResizeBeforeItemsHeight = 0\r\n\r\n\t\t\t\tconst prevBeforeResizeItemRowsCount = Math.ceil(prevBeforeResizeItemsCount / prevBeforeResize.columnsCount)\r\n\t\t\t\tlet rowIndex = 0\r\n\t\t\t\twhile (rowIndex < prevBeforeResizeItemRowsCount) {\r\n\t\t\t\t\t// Since all \"before resize\" item heights are equal within a row,\r\n\t\t\t\t\t// the height of the first \"before resize\" item in a row is that row's height.\r\n\t\t\t\t\tconst rowHeight = prevBeforeResize.itemHeights[rowIndex * prevBeforeResize.columnsCount]\r\n\t\t\t\t\tprevBeforeResizeBeforeItemsHeight += rowHeight\r\n\t\t\t\t\tprevBeforeResizeBeforeItemsHeight += prevBeforeResize.verticalSpacing\r\n\t\t\t\t\trowIndex++\r\n\t\t\t\t}\r\n\r\n\t\t\t\tlet newBeforeResizeAdditionalBeforeItemsHeight = 0\r\n\t\t\t\tlet i = firstShownItemIndex\r\n\t\t\t\twhile (i < newFirstShownItemIndex) {\r\n\t\t\t\t\tlet rowHeight = 0\r\n\t\t\t\t\tlet k = 0\r\n\t\t\t\t\twhile (k < columnsCount && i < newFirstShownItemIndex) {\r\n\t\t\t\t\t\trowHeight = Math.max(rowHeight, itemHeights[i])\r\n\t\t\t\t\t\tk++\r\n\t\t\t\t\t\ti++\r\n\t\t\t\t\t}\r\n\t\t\t\t\tnewBeforeResizeAdditionalBeforeItemsHeight += rowHeight\r\n\t\t\t\t\tnewBeforeResizeAdditionalBeforeItemsHeight += verticalSpacing\r\n\t\t\t\t}\r\n\r\n\t\t\t\tconst newBeforeResizeBeforeItemsHeight = prevBeforeResizeBeforeItemsHeight + newBeforeResizeAdditionalBeforeItemsHeight\r\n\t\t\t\tconst newBeforeResizeBeforeItemRowsCount = Math.ceil(newFirstShownItemIndex / columnsCount)\r\n\r\n\t\t\t\treturn new Array(newFirstShownItemIndex).fill(\r\n\t\t\t\t\t// Re-calculate \"before resize\" item heights so that \"previous\" and \"new\" ones\r\n\t\t\t\t\t// correspond to the same (new) columns count.\r\n\t\t\t\t\t// Also don't occasionally set item heights to `< 0`.\r\n\t\t\t\t\tMath.max(0, newBeforeResizeBeforeItemsHeight / newBeforeResizeBeforeItemRowsCount - verticalSpacing)\r\n\t\t\t\t)\r\n\t\t\t} else {\r\n\t\t\t\t// Add new item heights to the previously snapshotted ones.\r\n\t\t\t\treturn prevBeforeResize.itemHeights.concat(\r\n\t\t\t\t\tequalizeItemHeights(\r\n\t\t\t\t\t\titemHeights,\r\n\t\t\t\t\t\tnewFirstShownItemIndex,\r\n\t\t\t\t\t\tcolumnsCount\r\n\t\t\t\t\t).slice(prevBeforeResize.itemHeights.length)\r\n\t\t\t\t)\r\n\t\t\t}\r\n\t\t} else {\r\n\t\t\treturn equalizeItemHeights(\r\n\t\t\t\titemHeights,\r\n\t\t\t\tnewFirstShownItemIndex,\r\n\t\t\t\tcolumnsCount\r\n\t\t\t)\r\n\t\t}\r\n\t}\r\n\r\n\tshouldIncludeBeforeResizeValuesInState() {\r\n\t\treturn this._includesBeforeResizeInState\r\n\t}\r\n}\r\n\r\n// Equalizes all item heights within a given row, for each row.\r\n//\r\n// The reason is that `beforeResize.itemHeights` is not necessarily divisible by\r\n// `beforeResize.columnsCount`, which would result in varying last row height\r\n// as items get removed from `beforeResize.itemHeights` as the user scrolls up.\r\n//\r\n// By equalizing all item heights within a given row, for each row, such \"jumping\"\r\n// last \"before resize\" row height is prevented when the user scrolls up.\r\n//\r\nfunction equalizeItemHeights(itemHeights, maxItemsCount, columnsCount) {\r\n\titemHeights = itemHeights.slice(0, Math.ceil(maxItemsCount / columnsCount) * columnsCount)\r\n\r\n\tlet rowIndex = 0\r\n\twhile (rowIndex * columnsCount < maxItemsCount) {\r\n\t\t// Calculate row height.\r\n\t\tlet rowHeight = 0\r\n\t\tlet k = 0\r\n\t\twhile (k < columnsCount) {\r\n\t\t\trowHeight = Math.max(rowHeight, itemHeights[rowIndex * columnsCount + k])\r\n\t\t\tk++\r\n\t\t}\r\n\r\n\t\t// Equalize all item heights within the row.\r\n\t\tk = 0\r\n\t\twhile (k < columnsCount) {\r\n\t\t\titemHeights[rowIndex * columnsCount + k] = rowHeight\r\n\t\t\tk++\r\n\t\t}\r\n\r\n\t\t// Proceed with the next row.\r\n\t\trowIndex++\r\n\t}\r\n\r\n\treturn itemHeights.slice(0, maxItemsCount)\r\n}\r\n\r\nexport function cleanUpBeforeResizeState(state) {\r\n\tif (state.beforeResize) {\r\n\t\tif (state.beforeResize.itemHeights.length === 0) {\r\n\t\t\tstate.beforeResize = undefined\r\n\t\t}\r\n\t}\r\n\treturn state\r\n}"],"mappings":";;;;;;;;AAAA;;;;;;;;;;;;;;;;IAEqBA,Y;EACpB,4BAIG;IAAA,IAHFC,QAGE,QAHFA,QAGE;IAAA,IAFFC,kBAEE,QAFFA,kBAEE;IAAA,IADFC,eACE,QADFA,eACE;;IAAA;;IACF,KAAKF,QAAL,GAAgBA,QAAhB;IACA,KAAKC,kBAAL,GAA0BA,kBAA1B;IACA,KAAKC,eAAL,GAAuBA,eAAvB;EACA;;;;WAED,6BAAoBC,KAApB,EAA2B;MAC1B,KAAKC,4BAAL,GAAoCC,OAAO,CAACF,KAAK,CAACG,YAAP,CAA3C;IACA,C,CAED;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;;;;WACA,0CAAiC;MAChC,qBAKI,KAAKN,QAAL,EALJ;MAAA,IACCO,mB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KAAK,CAACG,YAAN,CAAmBG,WAAnB,CAA+BC,MAA/B,KAA0C,CAA9C,EAAiD;MAChDP,KAAK,CAACG,YAAN,GAAqBgB,SAArB;IACA;EACD;;EACD,OAAOnB,KAAP;AACA"}
1
+ {"version":3,"file":"BeforeResize.js","names":["BeforeResize","getState","getVerticalSpacing","getColumnsCount","state","_includesBeforeResizeInState","Boolean","beforeResize","firstShownItemIndex","lastShownItemIndex","itemHeights","length","log","newlyShownItemRowsHeight","prevFirstReMeasuredItemsRowIndex","Math","floor","newlyShownItemsToIndex","min","i","rowHeight","columnIndex","itemHeight","undefined","getAverageItemHeight","max","cleanedUpBeforeResizeItemRowsHeight","maxParticipatingBeforeResizeItemsCount","participatingBeforeResizeItemRowsCount","ceil","columnsCount","firstCleanedUpBeforeResizeItemsRowIndex","k","verticalSpacing","firstDroppedBeforeResizeItemIndex","lastDroppedBeforeResizeItemIndex","slice","splice","scrollBy","newFirstShownItemIndex","prevBeforeResize","prevBeforeResizeItemsCount","prevBeforeResizeBeforeItemsHeight","prevBeforeResizeItemRowsCount","rowIndex","newBeforeResizeAdditionalBeforeItemsHeight","newBeforeResizeBeforeItemsHeight","newBeforeResizeBeforeItemRowsCount","Array","fill","concat","equalizeItemHeights","maxItemsCount","cleanUpBeforeResizeState"],"sources":["../source/BeforeResize.js"],"sourcesContent":["import log from './utility/debug.js'\r\n\r\nexport default class BeforeResize {\r\n\tconstructor({\r\n\t\tgetState,\r\n\t\tgetVerticalSpacing,\r\n\t\tgetColumnsCount\r\n\t}) {\r\n\t\tthis.getState = getState\r\n\t\tthis.getVerticalSpacing = getVerticalSpacing\r\n\t\tthis.getColumnsCount = getColumnsCount\r\n\t}\r\n\r\n\tinitializeFromState(state) {\r\n\t\tthis._includesBeforeResizeInState = Boolean(state.beforeResize)\r\n\t}\r\n\r\n\t// Cleans up \"before resize\" item heights and adjusts the scroll position accordingly.\r\n\t//\r\n\t// Hypothetically, it could also wait for the user to stop scrolling and only then\r\n\t// adjust the scroll position. The rationale is that if `window.scrollTo()` is called\r\n\t// while the user is scrolling, the user would occasionally experience \"lost\" mouse wheel\r\n\t// events when scrolling with a mouse wheel.\r\n\t//\r\n\t// Seems like Twitter's website waits for the user to stop scrolling before applying\r\n\t// the scroll position correction after a window resize. This library could do that too,\r\n\t// but that would require rewriting \"before items height\" top padding calculation\r\n\t// so that it doesn't re-calculate it on every re-render and instead does so incrementally,\r\n\t// and then, when the user stops, it re-calculates it from scratch removing the error\r\n\t// and adjusting the scroll position accordingly so that there's no \"jump of content\".\r\n\t//\r\n\t// But, seems like it works fine as it is and there's no need to rewrite anything.\r\n\t//\r\n\tcleanUpBeforeResizeItemHeights() {\r\n\t\tconst {\r\n\t\t\tfirstShownItemIndex,\r\n\t\t\tlastShownItemIndex,\r\n\t\t\titemHeights,\r\n\t\t\tbeforeResize\r\n\t\t} = this.getState()\r\n\r\n\t\t// If there're \"before resize\" properties in `state`\r\n\t\t// then it means that the corresponding items are waiting to be\r\n\t\t// re-measured after container resize. Since the resize,\r\n\t\t// some of those non-re-measured items might have just been measured,\r\n\t\t// so see if that's true, and if it is, remove those now-obsolete\r\n\t\t// \"before resize\" item heights and ajust the scroll position\r\n\t\t// so that there's no \"content jumping\".\r\n\r\n\t\tif (beforeResize) {\r\n\t\t\t// If the user has scrolled up to reveal a previously hidden item\r\n\t\t\t// that has not yet been re-measured after a previous resize.\r\n\t\t\tif (firstShownItemIndex < beforeResize.itemHeights.length) {\r\n\t\t\t\tlog('~ Clean up \"before resize\" item heights and correct scroll position ~')\r\n\r\n\t\t\t\t// Some of the \"before\" items have been un-hidden and re-measured.\r\n\t\t\t\t// Un-hiding those items would result in a \"jump of content\"\r\n\t\t\t\t// because \"before resize\" heights of those un-hidden items\r\n\t\t\t\t// could (and most likely will) be different from the current ones,\r\n\t\t\t\t// or because \"before resize\" columns count is different from\r\n\t\t\t\t// the current one.\r\n\t\t\t\t// To prevent a \"jump of content\", calculate the scroll position\r\n\t\t\t\t// difference and adjust the scroll position.\r\n\r\n\t\t\t\t// The height of the item rows that have transitioned\r\n\t\t\t\t// from hidden to shown.\r\n\t\t\t\tlet newlyShownItemRowsHeight = 0\r\n\r\n\t\t\t\t// Some of the `itemHeights` between the current `firstShownItemIndex` and\r\n\t\t\t\t// the previous `firstShownItemIndex` could stay `undefined` if the user\r\n\t\t\t\t// scrolled \"abruptly\": for example, by using a `window.scrollTo()` call.\r\n\t\t\t\t// In that case, the items below the visible ones won't be rendered and measured.\r\n\t\t\t\t// In such case, limit the items being iterated over to the current `lastShownItemIndex`\r\n\t\t\t\t// rather than the previous `firstShownItemIndex`.\r\n\t\t\t\tconst prevFirstReMeasuredItemsRowIndex = Math.floor(beforeResize.itemHeights.length / this.getColumnsCount())\r\n\t\t\t\tconst newlyShownItemsToIndex = Math.min(\r\n\t\t\t\t\tprevFirstReMeasuredItemsRowIndex * this.getColumnsCount() - 1,\r\n\t\t\t\t\tlastShownItemIndex\r\n\t\t\t\t)\r\n\r\n\t\t\t\tlet i = firstShownItemIndex\r\n\t\t\t\twhile (i <= newlyShownItemsToIndex) {\r\n\t\t\t\t\t// Calculate newly shown row height.\r\n\t\t\t\t\tlet rowHeight = 0\r\n\t\t\t\t\tlet columnIndex = 0\r\n\t\t\t\t\twhile (columnIndex < this.getColumnsCount() && i <= newlyShownItemsToIndex) {\r\n\t\t\t\t\t\tlet itemHeight = itemHeights[i]\r\n\t\t\t\t\t\tif (itemHeight === undefined) {\r\n\t\t\t\t\t\t\t// `itemHeight` can only be `undefined` when not `beforeResize`.\r\n\t\t\t\t\t\t\t// Use the current \"average item height\" as a substitute.\r\n\t\t\t\t\t\t\titemHeight = this.getAverageItemHeight()\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t\trowHeight = Math.max(rowHeight, itemHeight)\r\n\t\t\t\t\t\ti++\r\n\t\t\t\t\t\tcolumnIndex++\r\n\t\t\t\t\t}\r\n\t\t\t\t\t// Append to the total \"newly shown item rows height\".\r\n\t\t\t\t\tnewlyShownItemRowsHeight += rowHeight\r\n\t\t\t\t\tnewlyShownItemRowsHeight += this.getVerticalSpacing()\r\n\t\t\t\t}\r\n\r\n\t\t\t\t// The height of the \"before resize\" item rows\r\n\t\t\t\t// that will be \"cleaned up\" in this function call.\r\n\t\t\t\tlet cleanedUpBeforeResizeItemRowsHeight = 0\r\n\r\n\t\t\t\t// Some of the `beforeResize` item rows might have been skipped if the user\r\n\t\t\t\t// scrolled up \"abruptly\": for example, by using a `window.scrollTo()` call.\r\n\t\t\t\t// In that case, the \"before resize\" items below the bottom border of the screen\r\n\t\t\t\t// shouldn't be accounted for when calculating the scrollbar adjustment shift\r\n\t\t\t\t// because items after `lastShownItemIndex` aren't participating in the calculation\r\n\t\t\t\t// of `newlyShownItemRowsHeight`.\r\n\t\t\t\tconst maxParticipatingBeforeResizeItemsCount = Math.min(beforeResize.itemHeights.length, lastShownItemIndex + 1)\r\n\t\t\t\tconst participatingBeforeResizeItemRowsCount = Math.ceil(maxParticipatingBeforeResizeItemsCount / beforeResize.columnsCount)\r\n\r\n\t\t\t\tconst firstCleanedUpBeforeResizeItemsRowIndex = firstShownItemIndex === 0\r\n\t\t\t\t\t? 0\r\n\t\t\t\t\t: Math.floor((firstShownItemIndex - 1) / beforeResize.columnsCount) + 1\r\n\r\n\t\t\t\tlet k = firstCleanedUpBeforeResizeItemsRowIndex\r\n\t\t\t\twhile (k < participatingBeforeResizeItemRowsCount) {\r\n\t\t\t\t\tconst rowHeight = beforeResize.itemHeights[k * beforeResize.columnsCount]\r\n\t\t\t\t\tcleanedUpBeforeResizeItemRowsHeight += rowHeight\r\n\t\t\t\t\tcleanedUpBeforeResizeItemRowsHeight += beforeResize.verticalSpacing\r\n\t\t\t\t\tk++\r\n\t\t\t\t}\r\n\r\n\t\t\t\t// Schedule an asynchronous `this.updateState()` call that will update\r\n\t\t\t\t// `beforeResize` property of `state`. Ideally, it should be updated\r\n\t\t\t\t// immediately, but since `this.updateState()` calls are asynchronous,\r\n\t\t\t\t// the code updates just the underlying `beforeResize.itemHeights`\r\n\t\t\t\t// array immediately instead, which is still a hack but still a lesser one.\r\n\t\t\t\tif (firstShownItemIndex === 0) {\r\n\t\t\t\t\tlog('Drop all \"before resize\" item heights')\r\n\t\t\t\t} else {\r\n\t\t\t\t\tconst firstDroppedBeforeResizeItemIndex = firstShownItemIndex\r\n\t\t\t\t\tconst lastDroppedBeforeResizeItemIndex = beforeResize.itemHeights.length - 1\r\n\t\t\t\t\tif (firstDroppedBeforeResizeItemIndex === lastDroppedBeforeResizeItemIndex) {\r\n\t\t\t\t\t\tlog('For item index', firstDroppedBeforeResizeItemIndex, '— drop \"before resize\" height', beforeResize.itemHeights[firstDroppedBeforeResizeItemIndex], )\r\n\t\t\t\t\t} else {\r\n\t\t\t\t\t\tlog('For item indexes from', firstDroppedBeforeResizeItemIndex, 'to', lastDroppedBeforeResizeItemIndex, '— drop \"before resize\" heights', beforeResize.itemHeights.slice(firstDroppedBeforeResizeItemIndex))\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\r\n\t\t\t\t// Immediately update `beforeResize.itemHeights`\r\n\t\t\t\t// so that the component isn't left in an inconsistent state\r\n\t\t\t\t// before a `this.updateState()` call below is applied.\r\n\t\t\t\tbeforeResize.itemHeights.splice(\r\n\t\t\t\t\tfirstShownItemIndex,\r\n\t\t\t\t\tbeforeResize.itemHeights.length - firstShownItemIndex\r\n\t\t\t\t)\r\n\r\n\t\t\t\t// Return the \"scroll by\" amount that would correct the scroll position.\r\n\t\t\t\t// Also return a state update.\r\n\t\t\t\treturn {\r\n\t\t\t\t\tscrollBy: newlyShownItemRowsHeight - cleanedUpBeforeResizeItemRowsHeight,\r\n\t\t\t\t\tbeforeResize: firstShownItemIndex === 0 ? undefined : {\r\n\t\t\t\t\t\t// Simply change the \"reference\" to `beforeResize` while leaving\r\n\t\t\t\t\t\t// its contents unchanged. That simply indicates that it has been updated:\r\n\t\t\t\t\t\t// `beforeResize.itemHeights` array length has been changed \"directly\".\r\n\t\t\t\t\t\t...beforeResize\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\r\n\t// Snapshots \"before resize\" values in order to preserve the currently\r\n\t// shown items' vertical position on screen so that there's no \"content jumping\".\r\n\t//\r\n\t// `newFirstShownItemIndex` is `> 0`.\r\n\t//\r\n\tsnapshotBeforeResizeItemHeights({\r\n\t\tfirstShownItemIndex,\r\n\t\tnewFirstShownItemIndex\r\n\t}) {\r\n\t\tconst columnsCount = this.getColumnsCount()\r\n\t\tconst verticalSpacing = this.getVerticalSpacing()\r\n\r\n\t\tthis._includesBeforeResizeInState = true\r\n\r\n\t\tconst {\r\n\t\t\tbeforeResize: prevBeforeResize,\r\n\t\t\titemHeights\r\n\t\t} = this.getState()\r\n\r\n\t\tconst prevBeforeResizeItemsCount = prevBeforeResize\r\n\t\t\t? prevBeforeResize.itemHeights.length\r\n\t\t\t: 0\r\n\r\n\t\t// If there already are \"before resize\" values in `state`\r\n\t\t// then it means that those should be merged with the new ones.\r\n\t\t//\r\n\t\t// `beforeResize.itemHeights` could be empty in an edge case\r\n\t\t// when there's a pending state update that sets `beforeResize`\r\n\t\t// to `undefined`, and in that case empty `beforeResize.itemHeights`\r\n\t\t// signals about that type of a situation.\r\n\t\t//\r\n\t\tif (prevBeforeResizeItemsCount > 0) {\r\n\t\t\t// Because the \"previous\" before resize values might have been captured\r\n\t\t\t// for a window width corresponding to a layout with a different columns count\r\n\t\t\t// and different vertical spacing, re-calculate those item heights as if\r\n\t\t\t// they corresponded to the current columns count and current vertical spacing,\r\n\t\t\t// since \"previous\" and \"new\" before resize item heights are gonna be merged.\r\n\t\t\tif (\r\n\t\t\t\tprevBeforeResize.columnsCount !== columnsCount ||\r\n\t\t\t\tprevBeforeResize.verticalSpacing !== verticalSpacing\r\n\t\t\t) {\r\n\t\t\t\tlet prevBeforeResizeBeforeItemsHeight = 0\r\n\r\n\t\t\t\tconst prevBeforeResizeItemRowsCount = Math.ceil(prevBeforeResizeItemsCount / prevBeforeResize.columnsCount)\r\n\t\t\t\tlet rowIndex = 0\r\n\t\t\t\twhile (rowIndex < prevBeforeResizeItemRowsCount) {\r\n\t\t\t\t\t// Since all \"before resize\" item heights are equal within a row,\r\n\t\t\t\t\t// the height of the first \"before resize\" item in a row is that row's height.\r\n\t\t\t\t\tconst rowHeight = prevBeforeResize.itemHeights[rowIndex * prevBeforeResize.columnsCount]\r\n\t\t\t\t\tprevBeforeResizeBeforeItemsHeight += rowHeight\r\n\t\t\t\t\tprevBeforeResizeBeforeItemsHeight += prevBeforeResize.verticalSpacing\r\n\t\t\t\t\trowIndex++\r\n\t\t\t\t}\r\n\r\n\t\t\t\tlet newBeforeResizeAdditionalBeforeItemsHeight = 0\r\n\t\t\t\tlet i = firstShownItemIndex\r\n\t\t\t\twhile (i < newFirstShownItemIndex) {\r\n\t\t\t\t\tlet rowHeight = 0\r\n\t\t\t\t\tlet k = 0\r\n\t\t\t\t\twhile (k < columnsCount && i < newFirstShownItemIndex) {\r\n\t\t\t\t\t\trowHeight = Math.max(rowHeight, itemHeights[i])\r\n\t\t\t\t\t\tk++\r\n\t\t\t\t\t\ti++\r\n\t\t\t\t\t}\r\n\t\t\t\t\tnewBeforeResizeAdditionalBeforeItemsHeight += rowHeight\r\n\t\t\t\t\tnewBeforeResizeAdditionalBeforeItemsHeight += verticalSpacing\r\n\t\t\t\t}\r\n\r\n\t\t\t\tconst newBeforeResizeBeforeItemsHeight = prevBeforeResizeBeforeItemsHeight + newBeforeResizeAdditionalBeforeItemsHeight\r\n\t\t\t\tconst newBeforeResizeBeforeItemRowsCount = Math.ceil(newFirstShownItemIndex / columnsCount)\r\n\r\n\t\t\t\treturn new Array(newFirstShownItemIndex).fill(\r\n\t\t\t\t\t// Re-calculate \"before resize\" item heights so that \"previous\" and \"new\" ones\r\n\t\t\t\t\t// correspond to the same (new) columns count.\r\n\t\t\t\t\t// Also don't occasionally set item heights to `< 0`.\r\n\t\t\t\t\tMath.max(0, newBeforeResizeBeforeItemsHeight / newBeforeResizeBeforeItemRowsCount - verticalSpacing)\r\n\t\t\t\t)\r\n\t\t\t} else {\r\n\t\t\t\t// Add new item heights to the previously snapshotted ones.\r\n\t\t\t\treturn prevBeforeResize.itemHeights.concat(\r\n\t\t\t\t\tequalizeItemHeights(\r\n\t\t\t\t\t\titemHeights,\r\n\t\t\t\t\t\tnewFirstShownItemIndex,\r\n\t\t\t\t\t\tcolumnsCount\r\n\t\t\t\t\t).slice(prevBeforeResize.itemHeights.length)\r\n\t\t\t\t)\r\n\t\t\t}\r\n\t\t} else {\r\n\t\t\treturn equalizeItemHeights(\r\n\t\t\t\titemHeights,\r\n\t\t\t\tnewFirstShownItemIndex,\r\n\t\t\t\tcolumnsCount\r\n\t\t\t)\r\n\t\t}\r\n\t}\r\n\r\n\tshouldIncludeBeforeResizeValuesInState() {\r\n\t\treturn this._includesBeforeResizeInState\r\n\t}\r\n}\r\n\r\n// Equalizes all item heights within a given row, for each row.\r\n//\r\n// The reason is that `beforeResize.itemHeights` is not necessarily divisible by\r\n// `beforeResize.columnsCount`, which would result in varying last row height\r\n// as items get removed from `beforeResize.itemHeights` as the user scrolls up.\r\n//\r\n// By equalizing all item heights within a given row, for each row, such \"jumping\"\r\n// last \"before resize\" row height is prevented when the user scrolls up.\r\n//\r\nfunction equalizeItemHeights(itemHeights, maxItemsCount, columnsCount) {\r\n\titemHeights = itemHeights.slice(0, Math.ceil(maxItemsCount / columnsCount) * columnsCount)\r\n\r\n\tlet rowIndex = 0\r\n\twhile (rowIndex * columnsCount < maxItemsCount) {\r\n\t\t// Calculate row height.\r\n\t\tlet rowHeight = 0\r\n\t\tlet k = 0\r\n\t\twhile (k < columnsCount) {\r\n\t\t\trowHeight = Math.max(rowHeight, itemHeights[rowIndex * columnsCount + k])\r\n\t\t\tk++\r\n\t\t}\r\n\r\n\t\t// Equalize all item heights within the row.\r\n\t\tk = 0\r\n\t\twhile (k < columnsCount) {\r\n\t\t\titemHeights[rowIndex * columnsCount + k] = rowHeight\r\n\t\t\tk++\r\n\t\t}\r\n\r\n\t\t// Proceed with the next row.\r\n\t\trowIndex++\r\n\t}\r\n\r\n\treturn itemHeights.slice(0, maxItemsCount)\r\n}\r\n\r\nexport function cleanUpBeforeResizeState(state) {\r\n\tif (state.beforeResize) {\r\n\t\tif (state.beforeResize.itemHeights.length === 0) {\r\n\t\t\tstate.beforeResize = undefined\r\n\t\t}\r\n\t}\r\n\treturn state\r\n}"],"mappings":";;;;;;;;AAAA;;;;;;;;;;;;;;;;IAEqBA,Y;EACpB,4BAIG;IAAA,IAHFC,QAGE,QAHFA,QAGE;IAAA,IAFFC,kBAEE,QAFFA,kBAEE;IAAA,IADFC,eACE,QADFA,eACE;;IAAA;;IACF,KAAKF,QAAL,GAAgBA,QAAhB;IACA,KAAKC,kBAAL,GAA0BA,kBAA1B;IACA,KAAKC,eAAL,GAAuBA,eAAvB;EACA;;;;WAED,6BAAoBC,KAApB,EAA2B;MAC1B,KAAKC,4BAAL,GAAoCC,OAAO,CAACF,KAAK,CAACG,YAAP,CAA3C;IACA,C,CAED;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;;;;WACA,0CAAiC;MAChC,qBAKI,KAAKN,QAAL,EALJ;MAAA,IACCO,mBADD,kBACCA,mBADD;MAAA,IAECC,kBAFD,kBAECA,kBAFD;MAAA,IAGCC,WAHD,kBAGCA,WAHD;MAAA,IAICH,YAJD,kBAICA,YAJD,CADgC,CAQhC;MACA;MACA;MACA;MACA;MACA;MACA;;;MAEA,IAAIA,YAAJ,EAAkB;QACjB;QACA;QACA,IAAIC,mBAAmB,GAAGD,YAAY,CAACG,WAAb,CAAyBC,MAAnD,EAA2D;UAC1D,IAAAC,iBAAA,EAAI,uEAAJ,EAD0D,CAG1D;UACA;UACA;UACA;UACA;UACA;UACA;UACA;UAEA;UACA;;UACA,IAAIC,wBAAwB,GAAG,CAA/B,CAd0D,CAgB1D;UACA;UACA;UACA;UAC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,aAAa,GAAGtB,YAA1B,IAA0CA,YAA/D,CAAd;EAEA,IAAIc,QAAQ,GAAG,CAAf;;EACA,OAAOA,QAAQ,GAAGd,YAAX,GAA0BsB,aAAjC,EAAgD;IAC/C;IACA,IAAIhC,SAAS,GAAG,CAAhB;IACA,IAAIY,CAAC,GAAG,CAAR;;IACA,OAAOA,CAAC,GAAGF,YAAX,EAAyB;MACxBV,SAAS,GAAGL,IAAI,CAACU,GAAL,CAASL,SAAT,EAAoBV,WAAW,CAACkC,QAAQ,GAAGd,YAAX,GAA0BE,CAA3B,CAA/B,CAAZ;MACAA,CAAC;IACD,CAP8C,CAS/C;;;IACAA,CAAC,GAAG,CAAJ;;IACA,OAAOA,CAAC,GAAGF,YAAX,EAAyB;MACxBpB,WAAW,CAACkC,QAAQ,GAAGd,YAAX,GAA0BE,CAA3B,CAAX,GAA2CZ,SAA3C;MACAY,CAAC;IACD,CAd8C,CAgB/C;;;IACAY,QAAQ;EACR;;EAED,OAAOlC,WAAW,CAAC0B,KAAZ,CAAkB,CAAlB,EAAqBgB,aAArB,CAAP;AACA;;AAEM,SAASC,wBAAT,CAAkCjD,KAAlC,EAAyC;EAC/C,IAAIA,KAAK,CAACG,YAAV,EAAwB;IACvB,IAAIH,KAAK,CAACG,YAAN,CAAmBG,WAAnB,CAA+BC,MAA/B,KAA0C,CAA9C,EAAiD;MAChDP,KAAK,CAACG,YAAN,GAAqBgB,SAArB;IACA;EACD;;EACD,OAAOnB,KAAP;AACA"}
@@ -208,19 +208,19 @@ var VirtualScroller = /*#__PURE__*/function () {
208
208
 
209
209
  }, {
210
210
  key: "onItemHeightChange",
211
- value: function onItemHeightChange(i) {
212
- (0, _debug.warn)('`.onItemHeightChange(i)` method was renamed to `.onItemHeightDidChange(i)`');
213
- this.onItemHeightDidChange(i);
211
+ value: function onItemHeightChange(itemOrIndex) {
212
+ (0, _debug.warn)('`.onItemHeightChange(item)` method was renamed to `.onItemHeightDidChange(item)`');
213
+ this.onItemHeightDidChange(itemOrIndex);
214
214
  }
215
215
  }, {
216
216
  key: "onItemHeightDidChange",
217
- value: function onItemHeightDidChange(i) {
218
- this.virtualScroller.onItemHeightDidChange(i);
217
+ value: function onItemHeightDidChange(itemOrIndex) {
218
+ this.virtualScroller.onItemHeightDidChange(itemOrIndex);
219
219
  }
220
220
  }, {
221
221
  key: "setItemState",
222
- value: function setItemState(i, newState) {
223
- this.virtualScroller.setItemState(i, newState);
222
+ value: function setItemState(itemOrIndex, newState) {
223
+ this.virtualScroller.setItemState(itemOrIndex, newState);
224
224
  }
225
225
  /**
226
226
  * @deprecated
@@ -238,12 +238,6 @@ var VirtualScroller = /*#__PURE__*/function () {
238
238
  value: function setItems(newItems, options) {
239
239
  this.virtualScroller.setItems(newItems, options);
240
240
  }
241
- /*
242
- getItemCoordinates(i) {
243
- return this.virtualScroller.getItemCoordinates(i)
244
- }
245
- */
246
-
247
241
  }]);
248
242
 
249
243
  return VirtualScroller;
@@ -1 +1 @@
1
- {"version":3,"file":"VirtualScroller.js","names":["VirtualScroller","itemsContainerElement","items","renderItem","options","state","prevState","firstShownItemIndex","lastShownItemIndex","beforeItemsHeight","afterItemsHeight","getItemsContainerElement","virtualScroller","isItemsContainerElementTableBody","style","paddingTop","px","paddingBottom","diffRender","length","i","log","unmountItem","childNodes","firstChild","shouldPrependItems","prependBeforeItemElement","item","insertBefore","appendChild","_isMounted","_onMount","warn","stop","start","onMount","onItemUnmount","readyToStart","readyToRender","restOptions","VirtualScrollerCore","render","getInitialState","itemElement","removeChild","onItemHeightDidChange","newState","setItemState","newItems","setItems"],"sources":["../../source/DOM/VirtualScroller.js"],"sourcesContent":["import VirtualScrollerCore from '../VirtualScroller.js'\r\n\r\nimport log, { warn } from '../utility/debug.js'\r\nimport px from '../utility/px.js'\r\n\r\nexport default class VirtualScroller {\r\n constructor(itemsContainerElement, items, renderItem, options = {}) {\r\n this.getItemsContainerElement = typeof itemsContainerElement === 'function'\r\n ? itemsContainerElement\r\n : () => itemsContainerElement\r\n\r\n this.renderItem = renderItem\r\n\r\n const {\r\n onMount,\r\n onItemUnmount,\r\n readyToStart,\r\n readyToRender,\r\n ...restOptions\r\n } = options\r\n\r\n // `onMount()` option is deprecated due to no longer being used.\r\n // If someone thinks there's a valid use case for it, create an issue.\r\n this._onMount = onMount\r\n\r\n this.onItemUnmount = onItemUnmount\r\n\r\n this.virtualScroller = new VirtualScrollerCore(\r\n this.getItemsContainerElement,\r\n items,\r\n {\r\n ...restOptions,\r\n render: this.render\r\n }\r\n )\r\n\r\n if (readyToRender === false) {\r\n // Don't automatically perform the initial render of the list.\r\n // This means that neither `this.render()` nor `this.start()` methods should be called.\r\n } else if (readyToStart === false) {\r\n // Don't automatically call the `.start()` method of the \"core\" component.\r\n // Still, perform the initial render of the list.\r\n this.render(this.virtualScroller.getInitialState())\r\n } else {\r\n // Calls the `.start()` method of the \"core\" component.\r\n // It performs the initial render of the list and starts listening to scroll events.\r\n this.start()\r\n }\r\n }\r\n\r\n render = (state, prevState) => {\r\n const {\r\n items,\r\n firstShownItemIndex,\r\n lastShownItemIndex,\r\n beforeItemsHeight,\r\n afterItemsHeight\r\n } = state\r\n\r\n const itemsContainerElement = this.getItemsContainerElement()\r\n\r\n // log('~ On state change ~')\r\n // log('Previous state', prevState)\r\n // log('New state', state)\r\n\r\n // Set items container's padding-top and padding-bottom.\r\n // But only do that for a non-`<tbody/>` item container\r\n // because, strangely, CSS `padding` doesn't work on a `<tbody/>` element.\r\n // https://gitlab.com/catamphetamine/virtual-scroller/-/issues/1\r\n //\r\n // `this.virtualScroller` hasn't been initialized yet at this stage,\r\n // so this code can't use `this.virtualScroller.isItemsContainerElementTableBody()` function yet.\r\n // Instead, it uses its own method of detecting the use of a `<tbody/>` container.\r\n //\r\n if (!this.virtualScroller.isItemsContainerElementTableBody()) {\r\n itemsContainerElement.style.paddingTop = px(beforeItemsHeight)\r\n itemsContainerElement.style.paddingBottom = px(afterItemsHeight)\r\n }\r\n\r\n // Perform an intelligent \"diff\" re-render if the `items` are the same.\r\n const diffRender = prevState && items === prevState.items && items.length > 0\r\n // Remove no longer visible items from the DOM.\r\n if (diffRender) {\r\n // Decrement instead of increment here because\r\n // `itemsContainerElement.removeChild()` changes indexes.\r\n let i = prevState.lastShownItemIndex\r\n while (i >= prevState.firstShownItemIndex) {\r\n if (i >= firstShownItemIndex && i <= lastShownItemIndex) {\r\n // The item is still visible.\r\n } else {\r\n log('DOM: Remove element for item index', i)\r\n // The item is no longer visible. Remove it.\r\n this.unmountItem(itemsContainerElement.childNodes[i - prevState.firstShownItemIndex])\r\n }\r\n i--\r\n }\r\n } else {\r\n log('DOM: Rerender the list from scratch')\r\n while (itemsContainerElement.firstChild) {\r\n this.unmountItem(itemsContainerElement.firstChild)\r\n }\r\n }\r\n\r\n // Add newly visible items to the DOM.\r\n let shouldPrependItems = diffRender\r\n const prependBeforeItemElement = shouldPrependItems && itemsContainerElement.firstChild\r\n let i = firstShownItemIndex\r\n while (i <= lastShownItemIndex) {\r\n if (diffRender && i >= prevState.firstShownItemIndex && i <= prevState.lastShownItemIndex) {\r\n // The item is already being rendered.\r\n // Next items will be appended rather than prepended.\r\n if (shouldPrependItems) {\r\n shouldPrependItems = false\r\n }\r\n } else {\r\n const item = this.renderItem(items[i])\r\n if (shouldPrependItems) {\r\n log('DOM: Prepend element for item index', i)\r\n // Append `item` to `itemsContainerElement` before the retained items.\r\n itemsContainerElement.insertBefore(item, prependBeforeItemElement)\r\n } else {\r\n log('DOM: Append element for item index', i)\r\n // Append `item` to `itemsContainerElement`.\r\n itemsContainerElement.appendChild(item)\r\n }\r\n }\r\n i++\r\n }\r\n\r\n // Call `onMount()` function when the list has rendered for the first time.\r\n //\r\n // `onMount()` option is deprecated due to no longer being used.\r\n // If someone thinks there's a valid use case for it, create an issue.\r\n //\r\n if (!this._isMounted) {\r\n this._isMounted = true\r\n if (this._onMount) {\r\n this._onMount()\r\n }\r\n }\r\n }\r\n\r\n // Public API. Should be \"bound\" to `this`.\r\n onUnmount = () => {\r\n warn('`.onUnmount()` instance method name is deprecated, use `.stop()` instance method name instead.')\r\n this.stop()\r\n }\r\n\r\n // Public API. Should be \"bound\" to `this`.\r\n destroy = () => {\r\n warn('`.destroy()` instance method name is deprecated, use `.stop()` instance method name instead.')\r\n this.stop()\r\n }\r\n\r\n // Public API.\r\n // Should be \"bound\" to `this`.\r\n stop = () => {\r\n this.virtualScroller.stop()\r\n }\r\n\r\n // Potentially public API in some hypothetical scenario.\r\n // Should be \"bound\" to `this`.\r\n start = () => {\r\n this.virtualScroller.start()\r\n }\r\n\r\n unmountItem(itemElement) {\r\n this.getItemsContainerElement().removeChild(itemElement)\r\n\r\n if (this.onItemUnmount) {\r\n this.onItemUnmount(itemElement)\r\n }\r\n }\r\n\r\n /**\r\n * @deprecated\r\n * `.onItemHeightChange()` has been renamed to `.onItemHeightDidChange()`.\r\n */\r\n onItemHeightChange(i) {\r\n warn('`.onItemHeightChange(i)` method was renamed to `.onItemHeightDidChange(i)`')\r\n this.onItemHeightDidChange(i)\r\n }\r\n\r\n onItemHeightDidChange(i) {\r\n this.virtualScroller.onItemHeightDidChange(i)\r\n }\r\n\r\n setItemState(i, newState) {\r\n this.virtualScroller.setItemState(i, newState)\r\n }\r\n\r\n /**\r\n * @deprecated\r\n * `.updateItems()` has been renamed to `.setItems()`.\r\n */\r\n updateItems(newItems, options) {\r\n warn('`.updateItems()` method was renamed to `.setItems(i)`')\r\n this.setItems(newItems, options)\r\n }\r\n\r\n setItems(newItems, options) {\r\n this.virtualScroller.setItems(newItems, options)\r\n }\r\n\r\n /*\r\n getItemCoordinates(i) {\r\n return this.virtualScroller.getItemCoordinates(i)\r\n }\r\n */\r\n}"],"mappings":";;;;;;;;;AAAA;;AAEA;;AACA;;;;;;;;;;;;;;;;;;;;;;;;;;IAEqBA,e;EACnB,yBAAYC,sBAAZ,EAAmCC,MAAnC,EAA0CC,UAA1C,EAAoE;IAAA;;IAAA,IAAdC,OAAc,uEAAJ,EAAI;;IAAA;;IAAA,g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IACF;IAED;AACF;AACA;AACA;;;;WACE,4BAAmBvB,CAAnB,EAAsB;MACpB,IAAAY,WAAA,EAAK,4EAAL;MACA,KAAKa,qBAAL,CAA2BzB,CAA3B;IACD;;;WAED,+BAAsBA,CAAtB,EAAyB;MACvB,KAAKR,eAAL,CAAqBiC,qBAArB,CAA2CzB,CAA3C;IACD;;;WAED,sBAAaA,CAAb,EAAgB0B,QAAhB,EAA0B;MACxB,KAAKlC,eAAL,CAAqBmC,YAArB,CAAkC3B,CAAlC,EAAqC0B,QAArC;IACD;IAED;AACF;AACA;AACA;;;;WACE,qBAAYE,QAAZ,EAAsB5C,OAAtB,EAA+B;MAC7B,IAAA4B,WAAA,EAAK,uDAAL;MACA,KAAKiB,QAAL,CAAcD,QAAd,EAAwB5C,OAAxB;IACD;;;WAED,kBAAS4C,QAAT,EAAmB5C,OAAnB,EAA4B;MAC1B,KAAKQ,eAAL,CAAqBqC,QAArB,CAA8BD,QAA9B,EAAwC5C,OAAxC;IACD;IAED;AACF;AACA;AACA;AACA"}
1
+ {"version":3,"file":"VirtualScroller.js","names":["VirtualScroller","itemsContainerElement","items","renderItem","options","state","prevState","firstShownItemIndex","lastShownItemIndex","beforeItemsHeight","afterItemsHeight","getItemsContainerElement","virtualScroller","isItemsContainerElementTableBody","style","paddingTop","px","paddingBottom","diffRender","length","i","log","unmountItem","childNodes","firstChild","shouldPrependItems","prependBeforeItemElement","item","insertBefore","appendChild","_isMounted","_onMount","warn","stop","start","onMount","onItemUnmount","readyToStart","readyToRender","restOptions","VirtualScrollerCore","render","getInitialState","itemElement","removeChild","itemOrIndex","onItemHeightDidChange","newState","setItemState","newItems","setItems"],"sources":["../../source/DOM/VirtualScroller.js"],"sourcesContent":["import VirtualScrollerCore from '../VirtualScroller.js'\r\n\r\nimport log, { warn } from '../utility/debug.js'\r\nimport px from '../utility/px.js'\r\n\r\nexport default class VirtualScroller {\r\n constructor(itemsContainerElement, items, renderItem, options = {}) {\r\n this.getItemsContainerElement = typeof itemsContainerElement === 'function'\r\n ? itemsContainerElement\r\n : () => itemsContainerElement\r\n\r\n this.renderItem = renderItem\r\n\r\n const {\r\n onMount,\r\n onItemUnmount,\r\n readyToStart,\r\n readyToRender,\r\n ...restOptions\r\n } = options\r\n\r\n // `onMount()` option is deprecated due to no longer being used.\r\n // If someone thinks there's a valid use case for it, create an issue.\r\n this._onMount = onMount\r\n\r\n this.onItemUnmount = onItemUnmount\r\n\r\n this.virtualScroller = new VirtualScrollerCore(\r\n this.getItemsContainerElement,\r\n items,\r\n {\r\n ...restOptions,\r\n render: this.render\r\n }\r\n )\r\n\r\n if (readyToRender === false) {\r\n // Don't automatically perform the initial render of the list.\r\n // This means that neither `this.render()` nor `this.start()` methods should be called.\r\n } else if (readyToStart === false) {\r\n // Don't automatically call the `.start()` method of the \"core\" component.\r\n // Still, perform the initial render of the list.\r\n this.render(this.virtualScroller.getInitialState())\r\n } else {\r\n // Calls the `.start()` method of the \"core\" component.\r\n // It performs the initial render of the list and starts listening to scroll events.\r\n this.start()\r\n }\r\n }\r\n\r\n render = (state, prevState) => {\r\n const {\r\n items,\r\n firstShownItemIndex,\r\n lastShownItemIndex,\r\n beforeItemsHeight,\r\n afterItemsHeight\r\n } = state\r\n\r\n const itemsContainerElement = this.getItemsContainerElement()\r\n\r\n // log('~ On state change ~')\r\n // log('Previous state', prevState)\r\n // log('New state', state)\r\n\r\n // Set items container's padding-top and padding-bottom.\r\n // But only do that for a non-`<tbody/>` item container\r\n // because, strangely, CSS `padding` doesn't work on a `<tbody/>` element.\r\n // https://gitlab.com/catamphetamine/virtual-scroller/-/issues/1\r\n //\r\n // `this.virtualScroller` hasn't been initialized yet at this stage,\r\n // so this code can't use `this.virtualScroller.isItemsContainerElementTableBody()` function yet.\r\n // Instead, it uses its own method of detecting the use of a `<tbody/>` container.\r\n //\r\n if (!this.virtualScroller.isItemsContainerElementTableBody()) {\r\n itemsContainerElement.style.paddingTop = px(beforeItemsHeight)\r\n itemsContainerElement.style.paddingBottom = px(afterItemsHeight)\r\n }\r\n\r\n // Perform an intelligent \"diff\" re-render if the `items` are the same.\r\n const diffRender = prevState && items === prevState.items && items.length > 0\r\n // Remove no longer visible items from the DOM.\r\n if (diffRender) {\r\n // Decrement instead of increment here because\r\n // `itemsContainerElement.removeChild()` changes indexes.\r\n let i = prevState.lastShownItemIndex\r\n while (i >= prevState.firstShownItemIndex) {\r\n if (i >= firstShownItemIndex && i <= lastShownItemIndex) {\r\n // The item is still visible.\r\n } else {\r\n log('DOM: Remove element for item index', i)\r\n // The item is no longer visible. Remove it.\r\n this.unmountItem(itemsContainerElement.childNodes[i - prevState.firstShownItemIndex])\r\n }\r\n i--\r\n }\r\n } else {\r\n log('DOM: Rerender the list from scratch')\r\n while (itemsContainerElement.firstChild) {\r\n this.unmountItem(itemsContainerElement.firstChild)\r\n }\r\n }\r\n\r\n // Add newly visible items to the DOM.\r\n let shouldPrependItems = diffRender\r\n const prependBeforeItemElement = shouldPrependItems && itemsContainerElement.firstChild\r\n let i = firstShownItemIndex\r\n while (i <= lastShownItemIndex) {\r\n if (diffRender && i >= prevState.firstShownItemIndex && i <= prevState.lastShownItemIndex) {\r\n // The item is already being rendered.\r\n // Next items will be appended rather than prepended.\r\n if (shouldPrependItems) {\r\n shouldPrependItems = false\r\n }\r\n } else {\r\n const item = this.renderItem(items[i])\r\n if (shouldPrependItems) {\r\n log('DOM: Prepend element for item index', i)\r\n // Append `item` to `itemsContainerElement` before the retained items.\r\n itemsContainerElement.insertBefore(item, prependBeforeItemElement)\r\n } else {\r\n log('DOM: Append element for item index', i)\r\n // Append `item` to `itemsContainerElement`.\r\n itemsContainerElement.appendChild(item)\r\n }\r\n }\r\n i++\r\n }\r\n\r\n // Call `onMount()` function when the list has rendered for the first time.\r\n //\r\n // `onMount()` option is deprecated due to no longer being used.\r\n // If someone thinks there's a valid use case for it, create an issue.\r\n //\r\n if (!this._isMounted) {\r\n this._isMounted = true\r\n if (this._onMount) {\r\n this._onMount()\r\n }\r\n }\r\n }\r\n\r\n // Public API. Should be \"bound\" to `this`.\r\n onUnmount = () => {\r\n warn('`.onUnmount()` instance method name is deprecated, use `.stop()` instance method name instead.')\r\n this.stop()\r\n }\r\n\r\n // Public API. Should be \"bound\" to `this`.\r\n destroy = () => {\r\n warn('`.destroy()` instance method name is deprecated, use `.stop()` instance method name instead.')\r\n this.stop()\r\n }\r\n\r\n // Public API.\r\n // Should be \"bound\" to `this`.\r\n stop = () => {\r\n this.virtualScroller.stop()\r\n }\r\n\r\n // Potentially public API in some hypothetical scenario.\r\n // Should be \"bound\" to `this`.\r\n start = () => {\r\n this.virtualScroller.start()\r\n }\r\n\r\n unmountItem(itemElement) {\r\n this.getItemsContainerElement().removeChild(itemElement)\r\n\r\n if (this.onItemUnmount) {\r\n this.onItemUnmount(itemElement)\r\n }\r\n }\r\n\r\n /**\r\n * @deprecated\r\n * `.onItemHeightChange()` has been renamed to `.onItemHeightDidChange()`.\r\n */\r\n onItemHeightChange(itemOrIndex) {\r\n warn('`.onItemHeightChange(item)` method was renamed to `.onItemHeightDidChange(item)`')\r\n this.onItemHeightDidChange(itemOrIndex)\r\n }\r\n\r\n onItemHeightDidChange(itemOrIndex) {\r\n this.virtualScroller.onItemHeightDidChange(itemOrIndex)\r\n }\r\n\r\n setItemState(itemOrIndex, newState) {\r\n this.virtualScroller.setItemState(itemOrIndex, newState)\r\n }\r\n\r\n /**\r\n * @deprecated\r\n * `.updateItems()` has been renamed to `.setItems()`.\r\n */\r\n updateItems(newItems, options) {\r\n warn('`.updateItems()` method was renamed to `.setItems(i)`')\r\n this.setItems(newItems, options)\r\n }\r\n\r\n setItems(newItems, options) {\r\n this.virtualScroller.setItems(newItems, options)\r\n }\r\n}"],"mappings":";;;;;;;;;AAAA;;AAEA;;AACA;;;;;;;;;;;;;;;;;;;;;;;;;;IAEqBA,e;EACnB,yBAAYC,sBAAZ,EAAmCC,MAAnC,EAA0CC,UAA1C,EAAoE;IAAA;;IAAA,IAAdC,OAAc,uEAAJ,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,CAAmBO,WAAnB;MACD;IACF;IAED;AACF;AACA;AACA;;;;WACE,4BAAmBE,WAAnB,EAAgC;MAC9B,IAAAb,WAAA,EAAK,kFAAL;MACA,KAAKc,qBAAL,CAA2BD,WAA3B;IACD;;;WAED,+BAAsBA,WAAtB,EAAmC;MACjC,KAAKjC,eAAL,CAAqBkC,qBAArB,CAA2CD,WAA3C;IACD;;;WAED,sBAAaA,WAAb,EAA0BE,QAA1B,EAAoC;MAClC,KAAKnC,eAAL,CAAqBoC,YAArB,CAAkCH,WAAlC,EAA+CE,QAA/C;IACD;IAED;AACF;AACA;AACA;;;;WACE,qBAAYE,QAAZ,EAAsB7C,OAAtB,EAA+B;MAC7B,IAAA4B,WAAA,EAAK,uDAAL;MACA,KAAKkB,QAAL,CAAcD,QAAd,EAAwB7C,OAAxB;IACD;;;WAED,kBAAS6C,QAAT,EAAmB7C,OAAnB,EAA4B;MAC1B,KAAKQ,eAAL,CAAqBsC,QAArB,CAA8BD,QAA9B,EAAwC7C,OAAxC;IACD"}
@@ -3,7 +3,7 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.TBODY_CLASS_NAME = exports.BROWSER_NOT_SUPPORTED_ERROR = void 0;
6
+ exports.CLASS_NAME_FOR_TBODY_WORKAROUND = exports.BROWSER_NOT_SUPPORTED_ERROR = void 0;
7
7
  exports.addTbodyStyles = addTbodyStyles;
8
8
  exports.hasTbodyStyles = hasTbodyStyles;
9
9
  exports.setTbodyPadding = setTbodyPadding;
@@ -32,22 +32,22 @@ function supportsTbody() {
32
32
  return !isInternetExplorer();
33
33
  }
34
34
 
35
- var TBODY_CLASS_NAME = 'VirtualScroller';
36
- exports.TBODY_CLASS_NAME = TBODY_CLASS_NAME;
35
+ var CLASS_NAME_FOR_TBODY_WORKAROUND = 'VirtualScroller';
36
+ exports.CLASS_NAME_FOR_TBODY_WORKAROUND = CLASS_NAME_FOR_TBODY_WORKAROUND;
37
37
  var STYLE_ELEMENT_ID = 'VirtualScrollerStyle';
38
38
 
39
39
  function hasTbodyStyles(tbody) {
40
- return tbody.classList.contains(TBODY_CLASS_NAME) && Boolean(document.getElementById(STYLE_ELEMENT_ID));
40
+ return tbody.classList.contains(CLASS_NAME_FOR_TBODY_WORKAROUND) && Boolean(document.getElementById(STYLE_ELEMENT_ID));
41
41
  }
42
42
 
43
43
  function addTbodyStyles(tbody) {
44
44
  // `classList.add` is supported in Internet Explorer 10+.
45
- tbody.classList.add(TBODY_CLASS_NAME); // Create a `<style/>` element.
45
+ tbody.classList.add(CLASS_NAME_FOR_TBODY_WORKAROUND); // Create a `<style/>` element.
46
46
 
47
47
  var style = document.createElement('style');
48
48
  style.id = STYLE_ELEMENT_ID; // CSS variables aren't supported in Internet Explorer.
49
49
 
50
- style.innerText = "\n\t\ttbody.".concat(TBODY_CLASS_NAME, ":before {\n\t\t\tcontent: '';\n\t\t\tdisplay: table-row;\n\t\t\theight: var(--VirtualScroller-paddingTop);\n\t\t}\n\t\ttbody.").concat(TBODY_CLASS_NAME, ":after {\n\t\t\tcontent: '';\n\t\t\tdisplay: table-row;\n\t\t\theight: var(--VirtualScroller-paddingBottom);\n\t\t}\n\t").replace(/[\n\t]/g, '');
50
+ style.innerText = "\n\t\ttbody.".concat(CLASS_NAME_FOR_TBODY_WORKAROUND, ":before {\n\t\t\tcontent: '';\n\t\t\tdisplay: table-row;\n\t\t\theight: var(--VirtualScroller-paddingTop);\n\t\t}\n\t\ttbody.").concat(CLASS_NAME_FOR_TBODY_WORKAROUND, ":after {\n\t\t\tcontent: '';\n\t\t\tdisplay: table-row;\n\t\t\theight: var(--VirtualScroller-paddingBottom);\n\t\t}\n\t").replace(/[\n\t]/g, '');
51
51
  document.head.appendChild(style);
52
52
  }
53
53
 
@@ -1 +1 @@
1
- {"version":3,"file":"tbody.js","names":["BROWSER_NOT_SUPPORTED_ERROR","isInternetExplorer","window","Boolean","document","documentMode","supportsTbody","TBODY_CLASS_NAME","STYLE_ELEMENT_ID","hasTbodyStyles","tbody","classList","contains","getElementById","addTbodyStyles","add","style","createElement","id","innerText","replace","head","appendChild","setTbodyPadding","beforeItemsHeight","afterItemsHeight","setProperty","px"],"sources":["../../source/DOM/tbody.js"],"sourcesContent":["// A workaround for `<tbody/>` not being able to have `padding`.\r\n// https://gitlab.com/catamphetamine/virtual-scroller/-/issues/1\r\n\r\nimport px from '../utility/px.js'\r\n\r\nexport const BROWSER_NOT_SUPPORTED_ERROR = 'It looks like you\\'re using Internet Explorer which doesn\\'t support CSS variables required for a <tbody/> container. VirtualScroller has been switched into \"bypass\" mode (render all items). See: https://gitlab.com/catamphetamine/virtual-scroller/-/issues/1'\r\n\r\nfunction isInternetExplorer() {\r\n\t// This function detects Internet Explorer using `documentMode` IE-only property.\r\n\t// https://stackoverflow.com/questions/19999388/check-if-user-is-using-ie\r\n\t// The `documentMode` property exists in IE 9-11. Maybe even IE 8.\r\n\t// http://msdn.microsoft.com/en-us/library/ie/cc196988(v=vs.85).aspx\r\n\treturn typeof window !== 'undefined' && Boolean(window.document.documentMode)\r\n}\r\n\r\nexport function supportsTbody() {\r\n\t// Internet Explorer doesn't support CSS Variables\r\n\t// and therefore it will not be able to apply the `<tbody/>` workaround.\r\n\treturn !isInternetExplorer()\r\n}\r\n\r\nexport const TBODY_CLASS_NAME = 'VirtualScroller'\r\nconst STYLE_ELEMENT_ID = 'VirtualScrollerStyle'\r\n\r\nexport function hasTbodyStyles(tbody) {\r\n\treturn tbody.classList.contains(TBODY_CLASS_NAME) &&\r\n\t\tBoolean(document.getElementById(STYLE_ELEMENT_ID))\r\n}\r\n\r\nexport function addTbodyStyles(tbody) {\r\n\t// `classList.add` is supported in Internet Explorer 10+.\r\n\ttbody.classList.add(TBODY_CLASS_NAME)\r\n\r\n\t// Create a `<style/>` element.\r\n\tconst style = document.createElement('style')\r\n\tstyle.id = STYLE_ELEMENT_ID\r\n\r\n\t// CSS variables aren't supported in Internet Explorer.\r\n\tstyle.innerText = `\r\n\t\ttbody.${TBODY_CLASS_NAME}:before {\r\n\t\t\tcontent: '';\r\n\t\t\tdisplay: table-row;\r\n\t\t\theight: var(--VirtualScroller-paddingTop);\r\n\t\t}\r\n\t\ttbody.${TBODY_CLASS_NAME}:after {\r\n\t\t\tcontent: '';\r\n\t\t\tdisplay: table-row;\r\n\t\t\theight: var(--VirtualScroller-paddingBottom);\r\n\t\t}\r\n\t`.replace(/[\\n\\t]/g, '')\r\n\r\n\tdocument.head.appendChild(style)\r\n}\r\n\r\nexport function setTbodyPadding(tbody, beforeItemsHeight, afterItemsHeight) {\r\n\t// CSS variables aren't supported in Internet Explorer.\r\n\ttbody.style.setProperty('--VirtualScroller-paddingTop', px(beforeItemsHeight));\r\n\ttbody.style.setProperty('--VirtualScroller-paddingBottom', px(afterItemsHeight));\r\n}"],"mappings":";;;;;;;;;;;AAGA;;;;AAHA;AACA;AAIO,IAAMA,2BAA2B,GAAG,mQAApC;;;AAEP,SAASC,kBAAT,GAA8B;EAC7B;EACA;EACA;EACA;EACA,OAAO,OAAOC,MAAP,KAAkB,WAAlB,IAAiCC,OAAO,CAACD,MAAM,CAACE,QAAP,CAAgBC,YAAjB,CAA/C;AACA;;AAEM,SAASC,aAAT,GAAyB;EAC/B;EACA;EACA,OAAO,CAACL,kBAAkB,EAA1B;AACA;;AAEM,IAAMM,gBAAgB,GAAG,iBAAzB;;AACP,IAAMC,gBAAgB,GAAG,sBAAzB;;AAEO,SAASC,cAAT,CAAwBC,KAAxB,EAA+B;EACrC,OAAOA,KAAK,CAACC,SAAN,CAAgBC,QAAhB,CAAyBL,gBAAzB,KACNJ,OAAO,CAACC,QAAQ,CAACS,cAAT,CAAwBL,gBAAxB,CAAD,CADR;AAEA;;AAEM,SAASM,cAAT,CAAwBJ,KAAxB,EAA+B;EACrC;EACAA,KAAK,CAACC,SAAN,CAAgBI,GAAhB,CAAoBR,gBAApB,EAFqC,CAIrC;;EACA,IAAMS,KAAK,GAAGZ,QAAQ,CAACa,aAAT,CAAuB,OAAvB,CAAd;EACAD,KAAK,CAACE,EAAN,GAAWV,gBAAX,CANqC,CAQrC;;EACAQ,KAAK,CAACG,SAAN,GAAkB,sBACTZ,gBADS,0IAMTA,gBANS,6HAWhBa,OAXgB,CAWR,SAXQ,EAWG,EAXH,CAAlB;EAaAhB,QAAQ,CAACiB,IAAT,CAAcC,WAAd,CAA0BN,KAA1B;AACA;;AAEM,SAASO,eAAT,CAAyBb,KAAzB,EAAgCc,iBAAhC,EAAmDC,gBAAnD,EAAqE;EAC3E;EACAf,KAAK,CAACM,KAAN,CAAYU,WAAZ,CAAwB,8BAAxB,EAAwD,IAAAC,cAAA,EAAGH,iBAAH,CAAxD;EACAd,KAAK,CAACM,KAAN,CAAYU,WAAZ,CAAwB,iCAAxB,EAA2D,IAAAC,cAAA,EAAGF,gBAAH,CAA3D;AACA"}
1
+ {"version":3,"file":"tbody.js","names":["BROWSER_NOT_SUPPORTED_ERROR","isInternetExplorer","window","Boolean","document","documentMode","supportsTbody","CLASS_NAME_FOR_TBODY_WORKAROUND","STYLE_ELEMENT_ID","hasTbodyStyles","tbody","classList","contains","getElementById","addTbodyStyles","add","style","createElement","id","innerText","replace","head","appendChild","setTbodyPadding","beforeItemsHeight","afterItemsHeight","setProperty","px"],"sources":["../../source/DOM/tbody.js"],"sourcesContent":["// A workaround for `<tbody/>` not being able to have `padding`.\r\n// https://gitlab.com/catamphetamine/virtual-scroller/-/issues/1\r\n\r\nimport px from '../utility/px.js'\r\n\r\nexport const BROWSER_NOT_SUPPORTED_ERROR = 'It looks like you\\'re using Internet Explorer which doesn\\'t support CSS variables required for a <tbody/> container. VirtualScroller has been switched into \"bypass\" mode (render all items). See: https://gitlab.com/catamphetamine/virtual-scroller/-/issues/1'\r\n\r\nfunction isInternetExplorer() {\r\n\t// This function detects Internet Explorer using `documentMode` IE-only property.\r\n\t// https://stackoverflow.com/questions/19999388/check-if-user-is-using-ie\r\n\t// The `documentMode` property exists in IE 9-11. Maybe even IE 8.\r\n\t// http://msdn.microsoft.com/en-us/library/ie/cc196988(v=vs.85).aspx\r\n\treturn typeof window !== 'undefined' && Boolean(window.document.documentMode)\r\n}\r\n\r\nexport function supportsTbody() {\r\n\t// Internet Explorer doesn't support CSS Variables\r\n\t// and therefore it will not be able to apply the `<tbody/>` workaround.\r\n\treturn !isInternetExplorer()\r\n}\r\n\r\nexport const CLASS_NAME_FOR_TBODY_WORKAROUND = 'VirtualScroller'\r\nconst STYLE_ELEMENT_ID = 'VirtualScrollerStyle'\r\n\r\nexport function hasTbodyStyles(tbody) {\r\n\treturn tbody.classList.contains(CLASS_NAME_FOR_TBODY_WORKAROUND) &&\r\n\t\tBoolean(document.getElementById(STYLE_ELEMENT_ID))\r\n}\r\n\r\nexport function addTbodyStyles(tbody) {\r\n\t// `classList.add` is supported in Internet Explorer 10+.\r\n\ttbody.classList.add(CLASS_NAME_FOR_TBODY_WORKAROUND)\r\n\r\n\t// Create a `<style/>` element.\r\n\tconst style = document.createElement('style')\r\n\tstyle.id = STYLE_ELEMENT_ID\r\n\r\n\t// CSS variables aren't supported in Internet Explorer.\r\n\tstyle.innerText = `\r\n\t\ttbody.${CLASS_NAME_FOR_TBODY_WORKAROUND}:before {\r\n\t\t\tcontent: '';\r\n\t\t\tdisplay: table-row;\r\n\t\t\theight: var(--VirtualScroller-paddingTop);\r\n\t\t}\r\n\t\ttbody.${CLASS_NAME_FOR_TBODY_WORKAROUND}:after {\r\n\t\t\tcontent: '';\r\n\t\t\tdisplay: table-row;\r\n\t\t\theight: var(--VirtualScroller-paddingBottom);\r\n\t\t}\r\n\t`.replace(/[\\n\\t]/g, '')\r\n\r\n\tdocument.head.appendChild(style)\r\n}\r\n\r\nexport function setTbodyPadding(tbody, beforeItemsHeight, afterItemsHeight) {\r\n\t// CSS variables aren't supported in Internet Explorer.\r\n\ttbody.style.setProperty('--VirtualScroller-paddingTop', px(beforeItemsHeight));\r\n\ttbody.style.setProperty('--VirtualScroller-paddingBottom', px(afterItemsHeight));\r\n}"],"mappings":";;;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3D;AACA"}
@@ -22,7 +22,6 @@ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _d
22
22
  var ItemHeights = /*#__PURE__*/function () {
23
23
  function ItemHeights(_ref) {
24
24
  var container = _ref.container,
25
- itemHeights = _ref.itemHeights,
26
25
  getItemHeight = _ref.getItemHeight,
27
26
  setItemHeight = _ref.setItemHeight;
28
27
 
@@ -42,9 +41,9 @@ var ItemHeights = /*#__PURE__*/function () {
42
41
  // is called, some items might get prepended, in which case
43
42
  // `this.lastMeasuredItemIndex` is updated. If there was no
44
43
  // `this.firstMeasuredItemIndex`, then the average item height
45
- // calculated in `.getAverage()` would be incorrect in the timeframe
44
+ // calculated in `.getAverageItemHeight()` would be incorrect in the timeframe
46
45
  // between `.setItems()` is called and those changes have been rendered.
47
- // And in that timeframe, `.getAverage()` is used to calculate the "layout":
46
+ // And in that timeframe, `.getAverageItemHeight()` is used to calculate the "layout":
48
47
  // stuff like "before/after items height" and "estimated items count on screen".
49
48
 
50
49
  this.firstMeasuredItemIndex = undefined;
@@ -91,7 +90,7 @@ var ItemHeights = /*#__PURE__*/function () {
91
90
  // this._set(i, itemHeight)
92
91
  // return itemHeight
93
92
  // }
94
- // return this.getAverage()
93
+ // return this.getAverageItemHeight()
95
94
  // }
96
95
 
97
96
  }, {
@@ -208,7 +207,7 @@ var ItemHeights = /*#__PURE__*/function () {
208
207
  var _height = this._measureItemHeight(i, firstShownItemIndex);
209
208
 
210
209
  if (previousHeight !== _height) {
211
- (0, _debug.warn)('Item index', i, 'height changed unexpectedly: it was', previousHeight, 'before, but now it is', _height, '. Whenever an item\'s height changes for whatever reason, a developer must call `onItemHeightDidChange(i)` right after that change. If you are calling `onItemHeightDidChange(i)` correctly, then there\'re several other possible causes. For example, perhaps you forgot to persist the item\'s "state" by calling `setItemState(i, newState)` when that "state" did change, and so the item\'s "state" got lost when the item element was unmounted, which resulted in a different item height when the item was shown again with no previous "state". Or perhaps you\'re running your application in "devleopment" mode and `VirtualScroller` has initially rendered the list before your CSS styles or custom fonts have loaded, resulting in different item height measurements "before" and "after" the page has fully loaded.'); // Update the item's height as an attempt to fix things.
210
+ (0, _debug.warn)('Item index', i, 'height changed unexpectedly: it was', previousHeight, 'before, but now it is', _height, '. Whenever an item\'s height changes for whatever reason, a developer must call `onItemHeightDidChange(item)` right after that change. If you are calling `onItemHeightDidChange(item)` correctly, then there\'re several other possible causes. For example, perhaps you forgot to persist the item\'s "state" by calling `setItemState(item, newState)` when that "state" did change, and so the item\'s "state" got lost when the item element was unmounted, which resulted in a different item height when the item was shown again with no previous "state". Or perhaps you\'re running your application in "devleopment" mode and `VirtualScroller` has initially rendered the list before your CSS styles or custom fonts have loaded, resulting in different item height measurements "before" and "after" the page has fully loaded.'); // Update the item's height as an attempt to fix things.
212
211
 
213
212
  this._set(i, _height);
214
213
  }
@@ -275,7 +274,7 @@ var ItemHeights = /*#__PURE__*/function () {
275
274
  // * Public API: is called by `VirtualScroller`.
276
275
  // * @return {number}
277
276
  // */
278
- // getAverage() {
277
+ // getAvergetAverageItemHeightage() {
279
278
  // // Previously measured average item height might still be
280
279
  // // more precise if it contains more measured items ("samples").
281
280
  // if (this.previousAverageItemHeight) {
@@ -288,17 +287,15 @@ var ItemHeights = /*#__PURE__*/function () {
288
287
 
289
288
  /**
290
289
  * Public API: is called by `VirtualScroller`.
291
- * @return {number}
290
+ * @return {number} [averageItemHeight] Returns `undefined` until at least one item has been rendered.
292
291
  */
293
292
 
294
293
  }, {
295
- key: "getAverage",
296
- value: function getAverage() {
297
- if (this.lastMeasuredItemIndex === undefined) {
298
- return 0;
294
+ key: "getAverageItemHeight",
295
+ value: function getAverageItemHeight() {
296
+ if (this.lastMeasuredItemIndex !== undefined) {
297
+ return this.measuredItemsHeight / (this.lastMeasuredItemIndex - this.firstMeasuredItemIndex + 1);
299
298
  }
300
-
301
- return this.measuredItemsHeight / (this.lastMeasuredItemIndex - this.firstMeasuredItemIndex + 1);
302
299
  }
303
300
  }, {
304
301
  key: "onPrepend",
@@ -1 +1 @@
1
- {"version":3,"file":"ItemHeights.js","names":["ItemHeights","container","itemHeights","getItemHeight","setItemHeight","_get","_set","reset","measuredItemsHeight","firstMeasuredItemIndex","undefined","lastMeasuredItemIndex","i","length","firstShownItemIndex","getNthRenderedItemHeight","lastShownItemIndex","log","nonPreviouslyMeasuredItemIndexes","previousFirstMeasuredItemIndex","previousLastMeasuredItemIndex","firstMeasuredItemIndexHasBeenUpdated","push","height","_measureItemHeight","previousHeight","warn","count"],"sources":["../source/ItemHeights.js"],"sourcesContent":["import log, { warn, isDebug, reportError } from './utility/debug.js'\r\n\r\nexport default class ItemHeights {\r\n\tconstructor({\r\n\t\tcontainer,\r\n\t\titemHeights,\r\n\t\tgetItemHeight,\r\n\t\tsetItemHeight\r\n\t}) {\r\n\t\tthis.container = container\r\n\t\tthis._get = getItemHeight\r\n\t\tthis._set = setItemHeight\r\n\t\tthis.reset()\r\n\t}\r\n\r\n\treset() {\r\n\t\tthis.measuredItemsHeight = 0\r\n\t\t// \"First measured item index\" variable was introduced\r\n\t\t// because it's not always `0`: when `virtualScroller.setItems()`\r\n\t\t// is called, some items might get prepended, in which case\r\n\t\t// `this.lastMeasuredItemIndex` is updated. If there was no\r\n\t\t// `this.firstMeasuredItemIndex`, then the average item height\r\n\t\t// calculated in `.getAverage()` would be incorrect in the timeframe\r\n\t\t// between `.setItems()` is called and those changes have been rendered.\r\n\t\t// And in that timeframe, `.getAverage()` is used to calculate the \"layout\":\r\n\t\t// stuff like \"before/after items height\" and \"estimated items count on screen\".\r\n\t\tthis.firstMeasuredItemIndex = undefined\r\n\t\tthis.lastMeasuredItemIndex = undefined\r\n\t}\r\n\r\n\t/**\r\n\t * Can only be called after a `.reset()` (including new instance creation).\r\n\t * Initializes `this.measuredItemsHeight`, `this.firstMeasuredItemIndex`\r\n\t * and `this.lastMeasuredItemIndex` instance variables from `VirtualScroller` `state`.\r\n\t * These instance variables are used when calculating \"average\" item height:\r\n\t * the \"average\" item height is simply `this.measuredItemsHeight` divided by\r\n\t * `this.lastMeasuredItemIndex` minus `this.firstMeasuredItemIndex` plus 1.\r\n\t */\r\n\treadItemHeightsFromState({ itemHeights }) {\r\n\t\tlet i = 0\r\n\t\twhile (i < itemHeights.length) {\r\n\t\t\tif (itemHeights[i] === undefined) {\r\n\t\t\t\tif (this.firstMeasuredItemIndex !== undefined) {\r\n\t\t\t\t\tthis.lastMeasuredItemIndex = i - 1\r\n\t\t\t\t\tbreak\r\n\t\t\t\t}\r\n\t\t\t} else {\r\n\t\t\t\tif (this.firstMeasuredItemIndex === undefined) {\r\n\t\t\t\t\tthis.firstMeasuredItemIndex = i\r\n\t\t\t\t}\r\n\t\t\t\tthis.measuredItemsHeight += itemHeights[i]\r\n\t\t\t}\r\n\t\t\ti++\r\n\t\t}\r\n\t}\r\n\r\n\t// Seems to be no longer used.\r\n\t// getItemHeight(i, firstShownItemIndex) {\r\n\t// \tif (this._get(i)) {\r\n\t// \t\treturn this._get(i)\r\n\t// \t}\r\n\t// \tconst itemHeight = this._measureItemHeight(i, firstShownItemIndex)\r\n\t// \tif (itemHeight) {\r\n\t// \t\tthis._set(i, itemHeight)\r\n\t// \t\treturn itemHeight\r\n\t// \t}\r\n\t// \treturn this.getAverage()\r\n\t// }\r\n\r\n\t_measureItemHeight(i, firstShownItemIndex) {\r\n\t\treturn this.container.getNthRenderedItemHeight(i - firstShownItemIndex)\r\n\t}\r\n\r\n\t/**\r\n\t * Measures item heights:\r\n\t *\r\n\t * * For the items that haven't been previously measured,\r\n\t * measures them for the first time.\r\n\t *\r\n\t * * For the items that have been previoulsy measured,\r\n\t * validate that their previously measured height\r\n\t * is still equal to their current height.\r\n\t * The unequalness may not necessarily be caused by\r\n\t * incorrect use of `virtual-scroller`: there are\r\n\t * also some valid use cases when such unequalness\r\n\t * could happen (see the comments in the code).\r\n\t *\r\n\t * @param {number} firstShownItemIndex\r\n\t * @param {number} lastShownItemIndex\r\n\t * @return {number[]} The indexes of the items that have not previously been measured and have been measured now.\r\n\t */\r\n\tmeasureItemHeights(firstShownItemIndex, lastShownItemIndex) {\r\n\t\tlog('~ Measure item heights ~')\r\n\t\t// If no items are rendered, don't measure anything.\r\n\t\tif (firstShownItemIndex === undefined) {\r\n\t\t\treturn\r\n\t\t}\r\n\t\t// Reset `this.measuredItemsHeight` if it's not a \"continuous\" measured items list:\r\n\t\t// if a group of items has been measured previously, and now it has rendered a completely\r\n\t\t// different group of items, and there's a non-measured \"gap\" between those two groups,\r\n\t\t// then reset `this.measuredItemsHeight` and \"first measured\"/\"last measured\" item indexes.\r\n\t\t// For example, this could happen when `.setItems()` prepends a lot of new items.\r\n\t\tif (this.firstMeasuredItemIndex !== undefined) {\r\n\t\t\tif (\r\n\t\t\t\tfirstShownItemIndex > this.lastMeasuredItemIndex + 1 ||\r\n\t\t\t\tlastShownItemIndex < this.firstMeasuredItemIndex - 1\r\n\t\t\t) {\r\n\t\t\t\t// Reset.\r\n\t\t\t\tlog('Non-measured items gap detected. Reset first and last measured item indexes.')\r\n\t\t\t\tthis.reset()\r\n\t\t\t}\r\n\t\t}\r\n\t\tconst nonPreviouslyMeasuredItemIndexes = []\r\n\t\tconst previousFirstMeasuredItemIndex = this.firstMeasuredItemIndex\r\n\t\tconst previousLastMeasuredItemIndex = this.lastMeasuredItemIndex\r\n\t\tlet firstMeasuredItemIndexHasBeenUpdated = false\r\n\t\tlet i = firstShownItemIndex\r\n\t\twhile (i <= lastShownItemIndex) {\r\n\t\t\t// Measure item heights that haven't been measured previously.\r\n\t\t\t// Don't re-measure item heights that have been measured previously.\r\n\t\t\t// The rationale is that developers are supposed to manually call\r\n\t\t\t// `.onItemHeightDidChange()` immediately every time an item's height has changed.\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, '. Whenever an item\\'s height changes for whatever reason, a developer must call `onItemHeightDidChange(i)` right after that change. If you are calling `onItemHeightDidChange(i)` correctly, then there\\'re several other possible causes. For example, perhaps you forgot to persist the item\\'s \"state\" by calling `setItemState(i, newState)` when that \"state\" did change, and so the item\\'s \"state\" got lost when the item element was unmounted, which resulted in a different item height when the item was shown again with no previous \"state\". Or perhaps you\\'re running your application in \"devleopment\" mode and `VirtualScroller` has initially rendered the list before your CSS styles or custom fonts have loaded, resulting in different item height measurements \"before\" and \"after\" the page has fully loaded.')\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 `.onItemHeightDidChange()`,\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(`\"onItemHeightDidChange()\" has been called for item ${i}, but that item isn't currently rendered.`)\r\n\t\t// \treturn\r\n\t\t// }\r\n\t\t// if (previousHeight === undefined) {\r\n\t\t// \treportError(`\"onItemHeightDidChange()\" has been called for item ${i}, but that item hasn't been rendered before.`)\r\n\t\t// \treturn\r\n\t\t// }\r\n\t\tthis._set(i, height)\r\n\t\tthis.measuredItemsHeight += height - previousHeight\r\n\t\treturn height\r\n\t}\r\n\r\n\t// /**\r\n\t// * \"Average\" item height is stored as an instance variable.\r\n\t// * For example, for caching, so that it isn't calculated every time it's requested.\r\n\t// * But that would be negligible performance gain, not really worth the extra code.\r\n\t// * Another thing it's stored for as an instance variable is\r\n\t// * keeping \"previous\" \"average\" item height, because it can be more precise\r\n\t// * than the newly calculated \"average\" item height, provided it had\r\n\t// * more \"samples\" (measured items). The newly calculated average item height\r\n\t// * could get less samples in a scenario when the scroll somehow jumps\r\n\t// * from one position to some other distant position: in that case previous\r\n\t// * \"total measured items height\" is discarded and the new one is initialized.\r\n\t// * Could such situation happen in real life? I guess, it's unlikely.\r\n\t// * So I'm commenting out this code, but still keeping it just in case.\r\n\t// */\r\n\t// updateAverageItemHeight() {\r\n\t// \tthis.averageItemHeightSamplesCount = this.lastMeasuredItemIndex - this.firstMeasuredItemIndex + 1\r\n\t// \tthis.averageItemHeight = this.measuredItemsHeight / this.averageItemHeightSamplesCount\r\n\t// }\r\n\t//\r\n\t// /**\r\n\t// * Public API: is called by `VirtualScroller`.\r\n\t// * @return {number}\r\n\t// */\r\n\t// getAverage() {\r\n\t// \t// Previously measured average item height might still be\r\n\t// \t// more precise if it contains more measured items (\"samples\").\r\n\t// \tif (this.previousAverageItemHeight) {\r\n\t// \t\tif (this.previousAverageItemHeightSamplesCount > this.averageItemHeightSamplesCount) {\r\n\t// \t\t\treturn this.previousAverageItemHeight\r\n\t// \t\t}\r\n\t// \t}\r\n\t// \treturn this.averageItemHeight || 0\r\n\t// }\r\n\r\n\t/**\r\n\t * Public API: is called by `VirtualScroller`.\r\n\t * @return {number}\r\n\t */\r\n\tgetAverage() {\r\n\t\tif (this.lastMeasuredItemIndex === undefined) {\r\n\t\t\treturn 0\r\n\t\t}\r\n\t\treturn this.measuredItemsHeight / (this.lastMeasuredItemIndex - this.firstMeasuredItemIndex + 1)\r\n\t}\r\n\r\n\tonPrepend(count) {\r\n\t\tif (this.firstMeasuredItemIndex !== undefined) {\r\n\t\t\tthis.firstMeasuredItemIndex += count\r\n\t\t\tthis.lastMeasuredItemIndex += count\r\n\t\t}\r\n\t}\r\n}"],"mappings":";;;;;;;;;AAAA;;;;;;;;;;;;IAEqBA,W;EACpB,2BAKG;IAAA,IAJFC,SAIE,QAJFA,SAIE;IAAA,IAHFC,WAGE,QAHFA,WAGE;IAAA,IAFFC,aAEE,QAFFA,aAEE;IAAA,IADFC,aACE,QADFA,aACE;;IAAA;;IACF,KAAKH,SAAL,GAAiBA,SAAjB;IACA,KAAKI,IAAL,GAAYF,aAAZ;IACA,KAAKG,IAAL,GAAYF,aAAZ;IACA,KAAKG,KAAL;EACA;;;;WAED,iBAAQ;MACP,KAAKC,mBAAL,GAA2B,CAA3B,CADO,CAEP;MACA;MACA;MACA;MACA;MACA;MACA;MACA;MACA;;MACA,KAAKC,sBAAL,GAA8BC,SAA9B;MACA,KAAKC,qBAAL,GAA6BD,SAA7B;IACA;IAED;AACD;AACA;AACA;AACA;AACA;AACA;AACA;;;;WACC,yCAA0C;MAAA,IAAfR,WAAe,SAAfA,WAAe;MACzC,IAAIU,CAAC,GAAG,CAAR;;MACA,OAAOA,CAAC,GAAGV,WAAW,CAACW,MAAvB,EAA+B;QAC9B,IAAIX,WAAW,CAACU,CAAD,CAAX,KAAmBF,SAAvB,EAAkC;UACjC,IAAI,KAAKD,sBAAL,KAAgCC,SAApC,EAA+C;YAC9C,KAAKC,qBAAL,GAA6BC,CAAC,GAAG,CAAjC;YACA;UACA;QACD,CALD,MAKO;UACN,IAA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CAAP;IACA;IAED;AACD;AACA;AACA;AACA;;;;WACC,6BAAoBN,CAApB,EAAuBE,mBAAvB,EAA4C;MAC3C,IAAMW,cAAc,GAAG,KAAKpB,IAAL,CAAUO,CAAV,CAAvB;;MACA,IAAMW,MAAM,GAAG,KAAKC,kBAAL,CAAwBZ,CAAxB,EAA2BE,mBAA3B,CAAf,CAF2C,CAG3C;MACA;MACA;MACA;MACA;MACA;MACA;MACA;MACA;MACA;MACA;MACA;MACA;MACA;;;MACA,KAAKR,IAAL,CAAUM,CAAV,EAAaW,MAAb;;MACA,KAAKf,mBAAL,IAA4Be,MAAM,GAAGE,cAArC;MACA,OAAOF,MAAP;IACA,C,CAED;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;;IAEA;AACD;AACA;AACA;;;;WACC,sBAAa;MACZ,IAAI,KAAKZ,qBAAL,KAA+BD,SAAnC,EAA8C;QAC7C,OAAO,CAAP;MACA;;MACD,OAAO,KAAKF,mBAAL,IAA4B,KAAKG,qBAAL,GAA6B,KAAKF,sBAAlC,GAA2D,CAAvF,CAAP;IACA;;;WAED,mBAAUkB,KAAV,EAAiB;MAChB,IAAI,KAAKlB,sBAAL,KAAgCC,SAApC,EAA+C;QAC9C,KAAKD,sBAAL,IAA+BkB,KAA/B;QACA,KAAKhB,qBAAL,IAA8BgB,KAA9B;MACA;IACD"}
1
+ {"version":3,"file":"ItemHeights.js","names":["ItemHeights","container","getItemHeight","setItemHeight","_get","_set","reset","measuredItemsHeight","firstMeasuredItemIndex","undefined","lastMeasuredItemIndex","itemHeights","i","length","firstShownItemIndex","getNthRenderedItemHeight","lastShownItemIndex","log","nonPreviouslyMeasuredItemIndexes","previousFirstMeasuredItemIndex","previousLastMeasuredItemIndex","firstMeasuredItemIndexHasBeenUpdated","push","height","_measureItemHeight","previousHeight","warn","count"],"sources":["../source/ItemHeights.js"],"sourcesContent":["import log, { warn } from './utility/debug.js'\r\n\r\nexport default class ItemHeights {\r\n\tconstructor({\r\n\t\tcontainer,\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\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 `.getAverageItemHeight()` 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, `.getAverageItemHeight()` 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.getAverageItemHeight()\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// `.onItemHeightDidChange()` immediately every time an item's height has changed.\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, '. Whenever an item\\'s height changes for whatever reason, a developer must call `onItemHeightDidChange(item)` right after that change. If you are calling `onItemHeightDidChange(item)` correctly, then there\\'re several other possible causes. For example, perhaps you forgot to persist the item\\'s \"state\" by calling `setItemState(item, newState)` when that \"state\" did change, and so the item\\'s \"state\" got lost when the item element was unmounted, which resulted in a different item height when the item was shown again with no previous \"state\". Or perhaps you\\'re running your application in \"devleopment\" mode and `VirtualScroller` has initially rendered the list before your CSS styles or custom fonts have loaded, resulting in different item height measurements \"before\" and \"after\" the page has fully loaded.')\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 `.onItemHeightDidChange()`,\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(`\"onItemHeightDidChange()\" has been called for item ${i}, but that item isn't currently rendered.`)\r\n\t\t// \treturn\r\n\t\t// }\r\n\t\t// if (previousHeight === undefined) {\r\n\t\t// \treportError(`\"onItemHeightDidChange()\" 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// getAvergetAverageItemHeightage() {\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} [averageItemHeight] Returns `undefined` until at least one item has been rendered.\r\n\t */\r\n\tgetAverageItemHeight() {\r\n\t\tif (this.lastMeasuredItemIndex !== undefined) {\r\n\t\t\treturn this.measuredItemsHeight / (this.lastMeasuredItemIndex - this.firstMeasuredItemIndex + 1)\r\n\t\t}\r\n\t}\r\n\r\n\tonPrepend(count) {\r\n\t\tif (this.firstMeasuredItemIndex !== undefined) {\r\n\t\t\tthis.firstMeasuredItemIndex += count\r\n\t\t\tthis.lastMeasuredItemIndex += count\r\n\t\t}\r\n\t}\r\n}"],"mappings":";;;;;;;;;AAAA;;;;;;;;;;;;IAEqBA,W;EACpB,2BAIG;IAAA,IAHFC,SAGE,QAHFA,SAGE;IAAA,IAFFC,aAEE,QAFFA,aAEE;IAAA,IADFC,aACE,QADFA,aACE;;IAAA;;IACF,KAAKF,SAAL,GAAiBA,SAAjB;IACA,KAAKG,IAAL,GAAYF,aAAZ;IACA,KAAKG,IAAL,GAAYF,aAAZ;IAEA,KAAKG,KAAL;EACA;;;;WAED,iBAAQ;MACP,KAAKC,mBAAL,GAA2B,CAA3B,CADO,CAEP;MACA;MACA;MACA;MACA;MACA;MACA;MACA;MACA;;MACA,KAAKC,sBAAL,GAA8BC,SAA9B;MACA,KAAKC,qBAAL,GAA6BD,SAA7B;IACA;IAED;AACD;AACA;AACA;AACA;AACA;AACA;AACA;;;;WACC,yCAA0C;MAAA,IAAfE,WAAe,SAAfA,WAAe;MACzC,IAAIC,CAAC,GAAG,CAAR;;MACA,OAAOA,CAAC,GAAGD,WAAW,CAACE,MAAvB,EAA+B;QAC9B,IAAIF,WAAW,CAACC,CAAD,CAAX,KAAmBH,SAAvB,EAAkC;UACjC,IAAI,KAAKD,sBAAL,KAAgCC,SAApC,EAA+C;YAC9C,KAAKC,qBAAL,GAA6BE,CAAC,GAAG,CAAjC;YACA;UACA;QACD,CALD,MAKO;UACN,IAAI,KAAKJ,sBAAL,KAAgCC,SAApC,EAA+C;YAC9C,KAAKD,sBAAL,GAA8BI,CAA9B;UACA;;UACD,KAAKL,mBAAL,IAA4BI,WAAW,CAACC,CAAD,CAAvC;QACA;;QACDA,CAAC;MACD;IACD,C,CAED;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;;;;WAEA,4BAAmBA,CAAnB,EAAsBE,mBAAtB,EAA2C;MAC1C,OAAO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ACA;MACA;MACA;MACA;;;MACA,KAAKT,IAAL,CAAUO,CAAV,EAAaW,MAAb;;MACA,KAAKhB,mBAAL,IAA4BgB,MAAM,GAAGE,cAArC;MACA,OAAOF,MAAP;IACA,C,CAED;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;;IAEA;AACD;AACA;AACA;;;;WACC,gCAAuB;MACtB,IAAI,KAAKb,qBAAL,KAA+BD,SAAnC,EAA8C;QAC7C,OAAO,KAAKF,mBAAL,IAA4B,KAAKG,qBAAL,GAA6B,KAAKF,sBAAlC,GAA2D,CAAvF,CAAP;MACA;IACD;;;WAED,mBAAUmB,KAAV,EAAiB;MAChB,IAAI,KAAKnB,sBAAL,KAAgCC,SAApC,EAA+C;QAC9C,KAAKD,sBAAL,IAA+BmB,KAA/B;QACA,KAAKjB,qBAAL,IAA8BiB,KAA9B;MACA;IACD"}
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.DEFAULT_VISIBLE_ITEM_ROWS_COUNT = exports.DEFAULT_ITEM_HEIGHT = exports.DEFAULT_INTER_ITEM_VERTICAL_SPACING = void 0;
7
+ // These values are used by default in server-side render,
8
+ // unless the developer explicitly specifies:
9
+ // * `getEstimatedItemHeight()`
10
+ // * `getEstimatedVisibleItemRowsCount()`
11
+ // * `getEstimatedInterItemVerticalSpacing()`
12
+ var DEFAULT_VISIBLE_ITEM_ROWS_COUNT = 1; // determines the count of items to render.
13
+
14
+ exports.DEFAULT_VISIBLE_ITEM_ROWS_COUNT = DEFAULT_VISIBLE_ITEM_ROWS_COUNT;
15
+ var DEFAULT_ITEM_HEIGHT = 0; // determines the length of the scrollbar, i.e. how much the user can scroll.
16
+
17
+ exports.DEFAULT_ITEM_HEIGHT = DEFAULT_ITEM_HEIGHT;
18
+ var DEFAULT_INTER_ITEM_VERTICAL_SPACING = 0; // determines the length of the scrollbar, i.e. how much the user can scroll.
19
+
20
+ exports.DEFAULT_INTER_ITEM_VERTICAL_SPACING = DEFAULT_INTER_ITEM_VERTICAL_SPACING;
21
+ //# sourceMappingURL=Layout.defaults.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Layout.defaults.js","names":["DEFAULT_VISIBLE_ITEM_ROWS_COUNT","DEFAULT_ITEM_HEIGHT","DEFAULT_INTER_ITEM_VERTICAL_SPACING"],"sources":["../source/Layout.defaults.js"],"sourcesContent":["// These values are used by default in server-side render,\r\n// unless the developer explicitly specifies:\r\n// * `getEstimatedItemHeight()`\r\n// * `getEstimatedVisibleItemRowsCount()`\r\n// * `getEstimatedInterItemVerticalSpacing()`\r\nexport const DEFAULT_VISIBLE_ITEM_ROWS_COUNT = 1 // determines the count of items to render.\r\nexport const DEFAULT_ITEM_HEIGHT = 0 // determines the length of the scrollbar, i.e. how much the user can scroll.\r\nexport const DEFAULT_INTER_ITEM_VERTICAL_SPACING = 0 // determines the length of the scrollbar, i.e. how much the user can scroll.\r\n"],"mappings":";;;;;;AAAA;AACA;AACA;AACA;AACA;AACO,IAAMA,+BAA+B,GAAG,CAAxC,C,CAA0C;;;AAC1C,IAAMC,mBAAmB,GAAG,CAA5B,C,CAA8B;;;AAC9B,IAAMC,mCAAmC,GAAG,CAA5C,C,CAA8C"}