virtual-scroller 1.7.9 → 1.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (283) hide show
  1. package/.gitlab-ci.yml +1 -1
  2. package/CHANGELOG.md +71 -1
  3. package/README.md +434 -151
  4. package/bundle/index-bypass.html +1 -1
  5. package/bundle/index-dom.html +1 -1
  6. package/bundle/index-grid.html +1 -2
  7. package/bundle/index-scrollableContainer.html +1 -1
  8. package/bundle/index-tbody-scrollableContainer.html +2 -0
  9. package/bundle/index-tbody.html +2 -0
  10. package/bundle/virtual-scroller-dom.js +1 -1
  11. package/bundle/virtual-scroller-dom.js.map +1 -1
  12. package/bundle/virtual-scroller-react.js +1 -1
  13. package/bundle/virtual-scroller-react.js.map +1 -1
  14. package/bundle/virtual-scroller.js +1 -1
  15. package/bundle/virtual-scroller.js.map +1 -1
  16. package/commonjs/BeforeResize.js +315 -0
  17. package/commonjs/BeforeResize.js.map +1 -0
  18. package/commonjs/DOM/Engine.js +46 -0
  19. package/commonjs/DOM/Engine.js.map +1 -0
  20. package/commonjs/DOM/ItemsContainer.js +78 -0
  21. package/commonjs/DOM/ItemsContainer.js.map +1 -0
  22. package/commonjs/DOM/{WaitForStylesToLoad.js → ListTopOffsetWatcher.js} +71 -44
  23. package/commonjs/DOM/ListTopOffsetWatcher.js.map +1 -0
  24. package/commonjs/DOM/ScrollableContainer.js +69 -101
  25. package/commonjs/DOM/ScrollableContainer.js.map +1 -1
  26. package/commonjs/DOM/VirtualScroller.js +37 -29
  27. package/commonjs/DOM/VirtualScroller.js.map +1 -1
  28. package/commonjs/DOM/tbody.js +17 -11
  29. package/commonjs/DOM/tbody.js.map +1 -1
  30. package/commonjs/ItemHeights.js +33 -34
  31. package/commonjs/ItemHeights.js.map +1 -1
  32. package/commonjs/Layout.js +591 -216
  33. package/commonjs/Layout.js.map +1 -1
  34. package/commonjs/Layout.test.js +196 -0
  35. package/commonjs/Layout.test.js.map +1 -0
  36. package/commonjs/ListHeightMeasurement.js +124 -0
  37. package/commonjs/ListHeightMeasurement.js.map +1 -0
  38. package/commonjs/Resize.js +50 -39
  39. package/commonjs/Resize.js.map +1 -1
  40. package/commonjs/Scroll.js +139 -95
  41. package/commonjs/Scroll.js.map +1 -1
  42. package/commonjs/VirtualScroller.columns.js +43 -0
  43. package/commonjs/VirtualScroller.columns.js.map +1 -0
  44. package/commonjs/VirtualScroller.constructor.js +408 -0
  45. package/commonjs/VirtualScroller.constructor.js.map +1 -0
  46. package/commonjs/VirtualScroller.items.js +305 -0
  47. package/commonjs/VirtualScroller.items.js.map +1 -0
  48. package/commonjs/VirtualScroller.js +160 -1021
  49. package/commonjs/VirtualScroller.js.map +1 -1
  50. package/commonjs/VirtualScroller.layout.js +562 -0
  51. package/commonjs/VirtualScroller.layout.js.map +1 -0
  52. package/commonjs/VirtualScroller.onRender.js +357 -0
  53. package/commonjs/VirtualScroller.onRender.js.map +1 -0
  54. package/commonjs/VirtualScroller.resize.js +186 -0
  55. package/commonjs/VirtualScroller.resize.js.map +1 -0
  56. package/commonjs/VirtualScroller.state.js +301 -0
  57. package/commonjs/VirtualScroller.state.js.map +1 -0
  58. package/commonjs/VirtualScroller.verticalSpacing.js +65 -0
  59. package/commonjs/VirtualScroller.verticalSpacing.js.map +1 -0
  60. package/commonjs/getItemCoordinates.js.map +1 -1
  61. package/commonjs/getItemsDiff.js.map +1 -1
  62. package/commonjs/getVerticalSpacing.js +8 -8
  63. package/commonjs/getVerticalSpacing.js.map +1 -1
  64. package/commonjs/package.json +5 -0
  65. package/commonjs/react/VirtualScroller.js +182 -628
  66. package/commonjs/react/VirtualScroller.js.map +1 -1
  67. package/commonjs/react/useClassName.js +26 -0
  68. package/commonjs/react/useClassName.js.map +1 -0
  69. package/commonjs/react/useHandleItemsChange.js +116 -0
  70. package/commonjs/react/useHandleItemsChange.js.map +1 -0
  71. package/commonjs/react/useInstanceMethods.js +37 -0
  72. package/commonjs/react/useInstanceMethods.js.map +1 -0
  73. package/commonjs/react/useItemKeys.js +60 -0
  74. package/commonjs/react/useItemKeys.js.map +1 -0
  75. package/commonjs/react/useOnItemHeightChange.js +32 -0
  76. package/commonjs/react/useOnItemHeightChange.js.map +1 -0
  77. package/commonjs/react/useOnItemStateChange.js +32 -0
  78. package/commonjs/react/useOnItemStateChange.js.map +1 -0
  79. package/commonjs/react/useState.js +140 -0
  80. package/commonjs/react/useState.js.map +1 -0
  81. package/commonjs/react/useStyle.js +29 -0
  82. package/commonjs/react/useStyle.js.map +1 -0
  83. package/commonjs/react/useVirtualScroller.js +62 -0
  84. package/commonjs/react/useVirtualScroller.js.map +1 -0
  85. package/commonjs/react/useVirtualScrollerStartStop.js +20 -0
  86. package/commonjs/react/useVirtualScrollerStartStop.js.map +1 -0
  87. package/commonjs/test/Engine.js +23 -0
  88. package/commonjs/test/Engine.js.map +1 -0
  89. package/commonjs/test/ItemsContainer.js +127 -0
  90. package/commonjs/test/ItemsContainer.js.map +1 -0
  91. package/commonjs/test/ScrollableContainer.js +130 -0
  92. package/commonjs/test/ScrollableContainer.js.map +1 -0
  93. package/commonjs/test/VirtualScroller.js +281 -0
  94. package/commonjs/test/VirtualScroller.js.map +1 -0
  95. package/commonjs/utility/debounce.js +28 -6
  96. package/commonjs/utility/debounce.js.map +1 -1
  97. package/commonjs/utility/debug.js +51 -12
  98. package/commonjs/utility/debug.js.map +1 -1
  99. package/commonjs/utility/getStateSnapshot.js +50 -0
  100. package/commonjs/utility/getStateSnapshot.js.map +1 -0
  101. package/commonjs/utility/px.js +1 -1
  102. package/commonjs/utility/px.js.map +1 -1
  103. package/commonjs/utility/px.test.js +14 -0
  104. package/commonjs/utility/px.test.js.map +1 -0
  105. package/commonjs/utility/shallowEqual.js +1 -1
  106. package/commonjs/utility/shallowEqual.js.map +1 -1
  107. package/commonjs/utility/throttle.js.map +1 -1
  108. package/dom/index.cjs +4 -0
  109. package/dom/index.cjs.js +9 -0
  110. package/dom/index.d.ts +25 -0
  111. package/dom/index.js +1 -1
  112. package/dom/package.json +10 -4
  113. package/index.cjs +4 -0
  114. package/index.cjs.js +9 -0
  115. package/index.d.ts +99 -0
  116. package/index.js +1 -1
  117. package/modules/BeforeResize.js +305 -0
  118. package/modules/BeforeResize.js.map +1 -0
  119. package/modules/DOM/Engine.js +27 -0
  120. package/modules/DOM/Engine.js.map +1 -0
  121. package/modules/DOM/ItemsContainer.js +71 -0
  122. package/modules/DOM/ItemsContainer.js.map +1 -0
  123. package/modules/DOM/{WaitForStylesToLoad.js → ListTopOffsetWatcher.js} +72 -44
  124. package/modules/DOM/ListTopOffsetWatcher.js.map +1 -0
  125. package/modules/DOM/ScrollableContainer.js +68 -100
  126. package/modules/DOM/ScrollableContainer.js.map +1 -1
  127. package/modules/DOM/VirtualScroller.js +32 -28
  128. package/modules/DOM/VirtualScroller.js.map +1 -1
  129. package/modules/DOM/tbody.js +11 -9
  130. package/modules/DOM/tbody.js.map +1 -1
  131. package/modules/ItemHeights.js +28 -33
  132. package/modules/ItemHeights.js.map +1 -1
  133. package/modules/Layout.js +585 -214
  134. package/modules/Layout.js.map +1 -1
  135. package/modules/Layout.test.js +190 -0
  136. package/modules/Layout.test.js.map +1 -0
  137. package/modules/ListHeightMeasurement.js +117 -0
  138. package/modules/ListHeightMeasurement.js.map +1 -0
  139. package/modules/Resize.js +50 -39
  140. package/modules/Resize.js.map +1 -1
  141. package/modules/Scroll.js +139 -94
  142. package/modules/Scroll.js.map +1 -1
  143. package/modules/VirtualScroller.columns.js +36 -0
  144. package/modules/VirtualScroller.columns.js.map +1 -0
  145. package/modules/VirtualScroller.constructor.js +371 -0
  146. package/modules/VirtualScroller.constructor.js.map +1 -0
  147. package/modules/VirtualScroller.items.js +288 -0
  148. package/modules/VirtualScroller.items.js.map +1 -0
  149. package/modules/VirtualScroller.js +159 -1014
  150. package/modules/VirtualScroller.js.map +1 -1
  151. package/modules/VirtualScroller.layout.js +549 -0
  152. package/modules/VirtualScroller.layout.js.map +1 -0
  153. package/modules/VirtualScroller.onRender.js +337 -0
  154. package/modules/VirtualScroller.onRender.js.map +1 -0
  155. package/modules/VirtualScroller.resize.js +176 -0
  156. package/modules/VirtualScroller.resize.js.map +1 -0
  157. package/modules/VirtualScroller.state.js +283 -0
  158. package/modules/VirtualScroller.state.js.map +1 -0
  159. package/modules/VirtualScroller.verticalSpacing.js +54 -0
  160. package/modules/VirtualScroller.verticalSpacing.js.map +1 -0
  161. package/modules/getItemCoordinates.js.map +1 -1
  162. package/modules/getItemsDiff.js.map +1 -1
  163. package/modules/getVerticalSpacing.js +8 -8
  164. package/modules/getVerticalSpacing.js.map +1 -1
  165. package/modules/react/VirtualScroller.js +179 -634
  166. package/modules/react/VirtualScroller.js.map +1 -1
  167. package/modules/react/useClassName.js +18 -0
  168. package/modules/react/useClassName.js.map +1 -0
  169. package/modules/react/useHandleItemsChange.js +108 -0
  170. package/modules/react/useHandleItemsChange.js.map +1 -0
  171. package/modules/react/useInstanceMethods.js +28 -0
  172. package/modules/react/useInstanceMethods.js.map +1 -0
  173. package/modules/react/useItemKeys.js +52 -0
  174. package/modules/react/useItemKeys.js.map +1 -0
  175. package/modules/react/useOnItemHeightChange.js +24 -0
  176. package/modules/react/useOnItemHeightChange.js.map +1 -0
  177. package/modules/react/useOnItemStateChange.js +24 -0
  178. package/modules/react/useOnItemStateChange.js.map +1 -0
  179. package/modules/react/useState.js +132 -0
  180. package/modules/react/useState.js.map +1 -0
  181. package/modules/react/useStyle.js +19 -0
  182. package/modules/react/useStyle.js.map +1 -0
  183. package/modules/react/useVirtualScroller.js +51 -0
  184. package/modules/react/useVirtualScroller.js.map +1 -0
  185. package/modules/react/useVirtualScrollerStartStop.js +12 -0
  186. package/modules/react/useVirtualScrollerStartStop.js.map +1 -0
  187. package/modules/test/Engine.js +11 -0
  188. package/modules/test/Engine.js.map +1 -0
  189. package/modules/test/ItemsContainer.js +120 -0
  190. package/modules/test/ItemsContainer.js.map +1 -0
  191. package/modules/test/ScrollableContainer.js +123 -0
  192. package/modules/test/ScrollableContainer.js.map +1 -0
  193. package/modules/test/VirtualScroller.js +270 -0
  194. package/modules/test/VirtualScroller.js.map +1 -0
  195. package/modules/utility/debounce.js +28 -6
  196. package/modules/utility/debounce.js.map +1 -1
  197. package/modules/utility/debug.js +47 -10
  198. package/modules/utility/debug.js.map +1 -1
  199. package/modules/utility/getStateSnapshot.js +43 -0
  200. package/modules/utility/getStateSnapshot.js.map +1 -0
  201. package/modules/utility/px.js +1 -1
  202. package/modules/utility/px.js.map +1 -1
  203. package/modules/utility/px.test.js +9 -0
  204. package/modules/utility/px.test.js.map +1 -0
  205. package/modules/utility/shallowEqual.js +1 -1
  206. package/modules/utility/shallowEqual.js.map +1 -1
  207. package/modules/utility/throttle.js.map +1 -1
  208. package/package.json +54 -29
  209. package/react/index.cjs +4 -0
  210. package/react/index.cjs.js +9 -0
  211. package/react/index.d.ts +28 -0
  212. package/react/index.js +1 -1
  213. package/react/package.json +10 -4
  214. package/rollup.config.mjs +62 -0
  215. package/runnable/create-commonjs-package-json.js +11 -0
  216. package/source/BeforeResize.js +312 -0
  217. package/source/DOM/Engine.js +30 -0
  218. package/source/DOM/ItemsContainer.js +48 -0
  219. package/source/DOM/{WaitForStylesToLoad.js → ListTopOffsetWatcher.js} +61 -30
  220. package/source/DOM/ScrollableContainer.js +51 -73
  221. package/source/DOM/VirtualScroller.js +33 -18
  222. package/source/DOM/tbody.js +30 -21
  223. package/source/ItemHeights.js +27 -27
  224. package/source/Layout.js +629 -252
  225. package/source/Layout.test.js +176 -0
  226. package/source/ListHeightMeasurement.js +95 -0
  227. package/source/Resize.js +56 -32
  228. package/source/Scroll.js +135 -82
  229. package/source/VirtualScroller.columns.js +26 -0
  230. package/source/VirtualScroller.constructor.js +336 -0
  231. package/source/VirtualScroller.items.js +302 -0
  232. package/source/VirtualScroller.js +162 -936
  233. package/source/VirtualScroller.layout.js +539 -0
  234. package/source/VirtualScroller.onRender.js +345 -0
  235. package/source/VirtualScroller.resize.js +189 -0
  236. package/source/VirtualScroller.state.js +284 -0
  237. package/source/VirtualScroller.verticalSpacing.js +51 -0
  238. package/source/getVerticalSpacing.js +7 -7
  239. package/source/react/VirtualScroller.js +243 -603
  240. package/source/react/useClassName.js +14 -0
  241. package/source/react/useHandleItemsChange.js +115 -0
  242. package/source/react/useInstanceMethods.js +25 -0
  243. package/source/react/useItemKeys.js +59 -0
  244. package/source/react/useOnItemHeightChange.js +28 -0
  245. package/source/react/useOnItemStateChange.js +28 -0
  246. package/source/react/useState.js +114 -0
  247. package/source/react/useStyle.js +20 -0
  248. package/source/react/useVirtualScroller.js +59 -0
  249. package/source/react/useVirtualScrollerStartStop.js +12 -0
  250. package/source/test/Engine.js +11 -0
  251. package/source/test/ItemsContainer.js +87 -0
  252. package/source/test/ScrollableContainer.js +88 -0
  253. package/source/test/VirtualScroller.js +232 -0
  254. package/source/utility/debounce.js +22 -5
  255. package/source/utility/debug.js +34 -3
  256. package/source/utility/getStateSnapshot.js +36 -0
  257. package/source/utility/px.js +1 -1
  258. package/source/utility/px.test.js +9 -0
  259. package/website/index-bypass.html +195 -0
  260. package/website/index-grid.html +0 -1
  261. package/website/index-scrollableContainer.html +208 -0
  262. package/website/index-tbody-scrollableContainer.html +68 -0
  263. package/website/index-tbody.html +55 -0
  264. package/commonjs/DOM/RenderingEngine.js +0 -33
  265. package/commonjs/DOM/RenderingEngine.js.map +0 -1
  266. package/commonjs/DOM/Screen.js +0 -87
  267. package/commonjs/DOM/Screen.js.map +0 -1
  268. package/commonjs/DOM/WaitForStylesToLoad.js.map +0 -1
  269. package/commonjs/RestoreScroll.js +0 -118
  270. package/commonjs/RestoreScroll.js.map +0 -1
  271. package/dom/index.commonjs.js +0 -4
  272. package/index.commonjs.js +0 -4
  273. package/modules/DOM/RenderingEngine.js +0 -19
  274. package/modules/DOM/RenderingEngine.js.map +0 -1
  275. package/modules/DOM/Screen.js +0 -80
  276. package/modules/DOM/Screen.js.map +0 -1
  277. package/modules/DOM/WaitForStylesToLoad.js.map +0 -1
  278. package/modules/RestoreScroll.js +0 -111
  279. package/modules/RestoreScroll.js.map +0 -1
  280. package/react/index.commonjs.js +0 -4
  281. package/source/DOM/RenderingEngine.js +0 -22
  282. package/source/DOM/Screen.js +0 -51
  283. package/source/RestoreScroll.js +0 -86
@@ -1,80 +0,0 @@
1
- function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
2
-
3
- function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
4
-
5
- function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
6
-
7
- var Screen =
8
- /*#__PURE__*/
9
- function () {
10
- function Screen() {
11
- _classCallCheck(this, Screen);
12
- }
13
-
14
- _createClass(Screen, [{
15
- key: "getChildElementTopOffset",
16
-
17
- /**
18
- * Returns a child element's "top offset", relative to the `parentElement`'s top edge.
19
- * @param {Element} parentElement
20
- * @param {number} childElementIndex
21
- * @return {number}
22
- */
23
- value: function getChildElementTopOffset(parentElement, childElementIndex) {
24
- return parentElement.childNodes[childElementIndex].getBoundingClientRect().top;
25
- }
26
- /**
27
- * Returns a child element's height.
28
- * @param {Element} parentElement
29
- * @param {number} childElementIndex
30
- * @return {number}
31
- */
32
-
33
- }, {
34
- key: "getChildElementHeight",
35
- value: function getChildElementHeight(parentElement, childElementIndex) {
36
- return this.getElementHeight(parentElement.childNodes[childElementIndex]);
37
- }
38
- /**
39
- * Returns the count of child elements of an element.
40
- * @param {Element} parentElement
41
- * @return {number}
42
- */
43
-
44
- }, {
45
- key: "getChildElementsCount",
46
- value: function getChildElementsCount(parentElement) {
47
- return parentElement.childNodes.length;
48
- }
49
- /**
50
- * Removes all child elements of an element.
51
- * @param {Element} element
52
- */
53
-
54
- }, {
55
- key: "clearElement",
56
- value: function clearElement(element) {
57
- while (element.firstChild) {
58
- element.removeChild(element.firstChild);
59
- }
60
- }
61
- /**
62
- * Returns an element's height.
63
- * @param {Element} element
64
- * @return {number}
65
- */
66
-
67
- }, {
68
- key: "getElementHeight",
69
- value: function getElementHeight(element) {
70
- // `offsetHeight` is not precise enough (doesn't return fractional pixels).
71
- // return element.offsetHeight
72
- return element.getBoundingClientRect().height;
73
- }
74
- }]);
75
-
76
- return Screen;
77
- }();
78
-
79
- export { Screen as default };
80
- //# sourceMappingURL=Screen.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../source/DOM/Screen.js"],"names":["Screen","parentElement","childElementIndex","childNodes","getBoundingClientRect","top","getElementHeight","length","element","firstChild","removeChild","height"],"mappings":";;;;;;IAAqBA,M;;;;;;;;;;AACpB;;;;;;6CAMyBC,a,EAAeC,iB,EAAmB;AAC1D,aAAOD,aAAa,CAACE,UAAd,CAAyBD,iBAAzB,EAA4CE,qBAA5C,GAAoEC,GAA3E;AACA;AAED;;;;;;;;;0CAMsBJ,a,EAAeC,iB,EAAmB;AACvD,aAAO,KAAKI,gBAAL,CAAsBL,aAAa,CAACE,UAAd,CAAyBD,iBAAzB,CAAtB,CAAP;AACA;AAED;;;;;;;;0CAKsBD,a,EAAe;AACpC,aAAOA,aAAa,CAACE,UAAd,CAAyBI,MAAhC;AACA;AAED;;;;;;;iCAIaC,O,EAAS;AACrB,aAAOA,OAAO,CAACC,UAAf,EAA2B;AAC1BD,QAAAA,OAAO,CAACE,WAAR,CAAoBF,OAAO,CAACC,UAA5B;AACA;AACD;AAED;;;;;;;;qCAKiBD,O,EAAS;AACzB;AACA;AACA,aAAOA,OAAO,CAACJ,qBAAR,GAAgCO,MAAvC;AACA;;;;;;SAjDmBX,M","sourcesContent":["export default class Screen {\r\n\t/**\r\n\t * Returns a child element's \"top offset\", relative to the `parentElement`'s top edge.\r\n\t * @param {Element} parentElement\r\n\t * @param {number} childElementIndex\r\n\t * @return {number}\r\n\t */\r\n\tgetChildElementTopOffset(parentElement, childElementIndex) {\r\n\t\treturn parentElement.childNodes[childElementIndex].getBoundingClientRect().top\r\n\t}\r\n\r\n\t/**\r\n\t * Returns a child element's height.\r\n\t * @param {Element} parentElement\r\n\t * @param {number} childElementIndex\r\n\t * @return {number}\r\n\t */\r\n\tgetChildElementHeight(parentElement, childElementIndex) {\r\n\t\treturn this.getElementHeight(parentElement.childNodes[childElementIndex])\r\n\t}\r\n\r\n\t/**\r\n\t * Returns the count of child elements of an element.\r\n\t * @param {Element} parentElement\r\n\t * @return {number}\r\n\t */\r\n\tgetChildElementsCount(parentElement) {\r\n\t\treturn parentElement.childNodes.length\r\n\t}\r\n\r\n\t/**\r\n\t * Removes all child elements of an element.\r\n\t * @param {Element} element\r\n\t */\r\n\tclearElement(element) {\r\n\t\twhile (element.firstChild) {\r\n\t\t\telement.removeChild(element.firstChild)\r\n\t\t}\r\n\t}\r\n\r\n\t/**\r\n\t * Returns an element's height.\r\n\t * @param {Element} element\r\n\t * @return {number}\r\n\t */\r\n\tgetElementHeight(element) {\r\n\t\t// `offsetHeight` is not precise enough (doesn't return fractional pixels).\r\n\t\t// return element.offsetHeight\r\n\t\treturn element.getBoundingClientRect().height\r\n\t}\r\n}"],"file":"Screen.js"}
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../source/DOM/WaitForStylesToLoad.js"],"names":["setTimeout","clearTimeout","LAYOUT_REASON","WaitForStylesToLoad","updateLayout","getListTopOffsetInsideScrollableContainer","listTopOffset","listTopOffsetInsideScrollableContainer","undefined","start","isRendered","watchListTopOffset","watchListTopOffsetTimer","startedAt","Date","now","check","reason","TOP_OFFSET_CHANGED","WATCH_LIST_TOP_OFFSET_MAX_DURATION","WATCH_LIST_TOP_OFFSET_INTERVAL"],"mappings":";;;;;;AAAA;AACA;AACA;AACA;AACA,SAASA,UAAT,EAAqBC,YAArB,QAAyC,iCAAzC;AAEA,SAASC,aAAT,QAA8B,WAA9B,C,CAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;IACqBC,mB;;;AACpB,qCAGG;AAAA,QAFFC,YAEE,QAFFA,YAEE;AAAA,QADFC,yCACE,QADFA,yCACE;;AAAA;;AACF,SAAKD,YAAL,GAAoBA,YAApB;AACA,SAAKC,yCAAL,GAAiDA,yCAAjD;AACA;;;;uCAEkBC,a,EAAe;AACjC,UAAI,KAAKC,sCAAL,KAAgDC,SAApD,EAA+D;AAC9D;AACA;AACA;AACA;AACA,aAAKC,KAAL;AACA;;AACD,WAAKF,sCAAL,GAA8CD,aAA9C;AACA;;;4BAEO;AACP,WAAKI,UAAL,GAAkB,IAAlB;AACA,WAAKC,kBAAL;AACA;;;2BAEM;AACN,WAAKD,UAAL,GAAkB,KAAlB;AACAT,MAAAA,YAAY,CAAC,KAAKW,uBAAN,CAAZ;AACA;;;yCAEoB;AAAA;;AACpB,UAAMC,SAAS,GAAGC,IAAI,CAACC,GAAL,EAAlB;;AACA,UAAMC,KAAK,GAAG,SAARA,KAAQ,GAAM;AACnB;AACA;AACA,YAAI,CAAC,KAAI,CAACN,UAAV,EAAsB;AACrB;AACA,SALkB,CAMnB;AACA;;;AACA,YAAI,KAAI,CAACH,sCAAL,KAAgDC,SAApD,EAA+D;AAC9D;AACA;AACA;AACA,cAAI,KAAI,CAACH,yCAAL,OAAqD,KAAI,CAACE,sCAA9D,EAAsG;AACrG,YAAA,KAAI,CAACH,YAAL,CAAkB;AAAEa,cAAAA,MAAM,EAAEf,aAAa,CAACgB;AAAxB,aAAlB;AACA;AACD,SAfkB,CAgBnB;AACA;AACA;AACA;AACA;AACA;AACA;;;AACA,YAAIJ,IAAI,CAACC,GAAL,KAAaF,SAAb,GAAyBM,kCAA7B,EAAiE;AAChE,UAAA,KAAI,CAACP,uBAAL,GAA+BZ,UAAU,CAACgB,KAAD,EAAQI,8BAAR,CAAzC;AACA;AACD,OA1BD,CAFoB,CA6BpB;;;AACAJ,MAAAA,KAAK;AACL;;;;;;SA7DmBb,mB;AAgErB,IAAMiB,8BAA8B,GAAG,GAAvC;AACA,IAAMD,kCAAkC,GAAG,IAA3C","sourcesContent":["// For some weird reason, in Chrome, `setTimeout()` would lag up to a second (or more) behind.\r\n// Turns out, Chrome developers have deprecated `setTimeout()` API entirely without asking anyone.\r\n// Replacing `setTimeout()` with `requestAnimationFrame()` can work around that Chrome bug.\r\n// https://github.com/bvaughn/react-virtualized/issues/722\r\nimport { setTimeout, clearTimeout } from 'request-animation-frame-timeout'\r\n\r\nimport { LAYOUT_REASON } from '../Layout'\r\n\r\n// `VirtualScroller` calls `this.layout.layOut()` on mount,\r\n// but if the page styles are applied after `VirtualScroller` mounts\r\n// (for example, if styles are applied via javascript, like Webpack does)\r\n// then the list might not render correctly and will only show the first item.\r\n// The reason for that would be that calling `.getListTopOffsetInsideScrollableContainer()`\r\n// on mount returns \"incorrect\" `top` position because the styles haven't been applied yet.\r\n// For example, consider a page:\r\n// <div class=\"page\">\r\n// <nav class=\"sidebar\">...</nav>\r\n// <main>...</main>\r\n// </div>\r\n// The sidebar is styled as `position: fixed`, but until\r\n// the page styles have been applied it's gonna be a regular `<div/>`\r\n// meaning that `<main/>` will be rendered below the sidebar\r\n// and will appear offscreen and so it will only render the first item.\r\n// Then, the page styles are loaded and applied and the sidebar\r\n// is now `position: fixed` so `<main/>` is now rendered at the top of the page\r\n// but `VirtualScroller`'s `.render()` has already been called\r\n// and it won't re-render until the user scrolls or the window is resized.\r\n// This type of a bug doesn't occur in production, but it can appear\r\n// in development mode when using Webpack. The workaround `VirtualScroller`\r\n// implements for such cases is calling `.getListTopOffsetInsideScrollableContainer()`\r\n// on the list container DOM element periodically (every second) to check\r\n// if the `top` coordinate has changed as a result of CSS being applied:\r\n// if it has then it recalculates the shown item indexes.\r\nexport default class WaitForStylesToLoad {\r\n\tconstructor({\r\n\t\tupdateLayout,\r\n\t\tgetListTopOffsetInsideScrollableContainer\r\n\t}) {\r\n\t\tthis.updateLayout = updateLayout\r\n\t\tthis.getListTopOffsetInsideScrollableContainer = getListTopOffsetInsideScrollableContainer\r\n\t}\r\n\r\n\tonGotListTopOffset(listTopOffset) {\r\n\t\tif (this.listTopOffsetInsideScrollableContainer === undefined) {\r\n\t\t\t// Start periodical checks of the list's top offset\r\n\t\t\t// in order to perform a re-layout in case it changes.\r\n\t\t\t// See the comments in `WaitForStylesToLoad.js` file\r\n\t\t\t// on why can the list's top offset change, and in which circumstances.\r\n\t\t\tthis.start()\r\n\t\t}\r\n\t\tthis.listTopOffsetInsideScrollableContainer = listTopOffset\r\n\t}\r\n\r\n\tstart() {\r\n\t\tthis.isRendered = true\r\n\t\tthis.watchListTopOffset()\r\n\t}\r\n\r\n\tstop() {\r\n\t\tthis.isRendered = false\r\n\t\tclearTimeout(this.watchListTopOffsetTimer)\r\n\t}\r\n\r\n\twatchListTopOffset() {\r\n\t\tconst startedAt = Date.now()\r\n\t\tconst check = () => {\r\n\t\t\t// If `VirtualScroller` has been unmounted\r\n\t\t\t// while `setTimeout()` was waiting, then exit.\r\n\t\t\tif (!this.isRendered) {\r\n\t\t\t\treturn\r\n\t\t\t}\r\n\t\t\t// Skip comparing `top` coordinate of the list\r\n\t\t\t// when this function is called for the first time.\r\n\t\t\tif (this.listTopOffsetInsideScrollableContainer !== undefined) {\r\n\t\t\t\t// Calling `this.getListTopOffsetInsideScrollableContainer()`\r\n\t\t\t\t// on an element is about 0.003 milliseconds on a modern desktop CPU,\r\n\t\t\t\t// so I guess it's fine calling it twice a second.\r\n\t\t\t\tif (this.getListTopOffsetInsideScrollableContainer() !== this.listTopOffsetInsideScrollableContainer) {\r\n\t\t\t\t\tthis.updateLayout({ reason: LAYOUT_REASON.TOP_OFFSET_CHANGED })\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\t// Compare `top` coordinate of the list twice a second\r\n\t\t\t// to find out if it has changed as a result of loading CSS styles.\r\n\t\t\t// The total duration of 3 seconds would be enough for any styles to load, I guess.\r\n\t\t\t// There could be other cases changing the `top` coordinate\r\n\t\t\t// of the list (like collapsing an \"accordeon\" panel above the list\r\n\t\t\t// without scrolling the page), but those cases should be handled\r\n\t\t\t// by manually calling `.updateLayout()` instance method on `VirtualScroller` instance.\r\n\t\t\tif (Date.now() - startedAt < WATCH_LIST_TOP_OFFSET_MAX_DURATION) {\r\n\t\t\t\tthis.watchListTopOffsetTimer = setTimeout(check, WATCH_LIST_TOP_OFFSET_INTERVAL)\r\n\t\t\t}\r\n\t\t}\r\n\t\t// Run the cycle.\r\n\t\tcheck()\r\n\t}\r\n}\r\n\r\nconst WATCH_LIST_TOP_OFFSET_INTERVAL = 500\r\nconst WATCH_LIST_TOP_OFFSET_MAX_DURATION = 3000"],"file":"WaitForStylesToLoad.js"}
@@ -1,111 +0,0 @@
1
- function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
2
-
3
- function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
4
-
5
- function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
6
-
7
- var RestoreScroll =
8
- /*#__PURE__*/
9
- function () {
10
- function RestoreScroll(_ref) {
11
- var screen = _ref.screen,
12
- getContainerElement = _ref.getContainerElement,
13
- scrollBy = _ref.scrollBy;
14
-
15
- _classCallCheck(this, RestoreScroll);
16
-
17
- this.screen = screen;
18
- this.getContainerElement = getContainerElement;
19
- this.scrollBy = scrollBy;
20
- }
21
- /**
22
- * `<ReactVirtualScroller/>` calls this method.
23
- * @param {any[]} previousItems
24
- * @param {any[]} newItems
25
- * @param {number} prependedItemsCount
26
- */
27
-
28
-
29
- _createClass(RestoreScroll, [{
30
- key: "captureScroll",
31
- value: function captureScroll(_ref2) {
32
- var previousItems = _ref2.previousItems,
33
- newItems = _ref2.newItems,
34
- prependedItemsCount = _ref2.prependedItemsCount;
35
-
36
- // If there were no items in the list
37
- // then there's no point in restoring scroll position.
38
- if (previousItems.length === 0) {
39
- return;
40
- } // If no items were prepended then no need to restore scroll position.
41
-
42
-
43
- if (prependedItemsCount === 0) {
44
- return;
45
- }
46
-
47
- var container = this.getContainerElement();
48
- var firstItemTopOffset = this.screen.getChildElementTopOffset(container, 0); // The first item is supposed to be shown when the user clicks
49
- // "Show previous items" button. If it isn't shown though,
50
- // could still calculate the first item's top position using
51
- // the values from `itemHeights` and `verticalSpacing`.
52
- // But that would be a weird non-realistic scenario.
53
- // if (firstShownItemIndex > 0) {
54
- // let i = firstShownItemIndex - 1
55
- // while (i >= 0) {
56
- // firstItemTopOffset += itemHeights[i] + verticalSpacing
57
- // i--
58
- // }
59
- // }
60
- // If the scroll position has already been captured for restoration,
61
- // then don't capture it the second time.
62
- // Capturing scroll position could happen when using `<ReactVirtualScroller/>`
63
- // because it calls `.captureScroll()` inside `ReactVirtualScroller.render()`
64
- // which is followed by `<VirtualScroller/>`'s `.componentDidUpdate()`
65
- // that also calls `.captureScroll()` with the same arguments,
66
- // so that second call to `.captureScroll()` is ignored.
67
- // Calling `.captureScroll()` inside `ReactVirtualScroller.render()`
68
- // is done to prevent scroll Y position from jumping
69
- // when showing the first page of the "Previous items".
70
- // See the long section of comments in `ReactVirtualScroller.render()`
71
- // method for more info on why is `.captureScroll()` called there.
72
-
73
- if (this.restoreScrollAfterRenderValues && this.restoreScrollAfterRenderValues.previousItems === previousItems && this.restoreScrollAfterRenderValues.newItems === newItems) {
74
- return;
75
- }
76
-
77
- this.restoreScrollAfterRenderValues = {
78
- previousItems: previousItems,
79
- newItems: newItems,
80
- index: prependedItemsCount,
81
- visibleAreaTop: firstItemTopOffset
82
- };
83
- }
84
- }, {
85
- key: "getAnchorItemIndex",
86
- value: function getAnchorItemIndex() {
87
- return this.restoreScrollAfterRenderValues.index;
88
- }
89
- }, {
90
- key: "shouldRestoreScrollAfterRender",
91
- value: function shouldRestoreScrollAfterRender() {
92
- return this.restoreScrollAfterRenderValues !== undefined;
93
- }
94
- }, {
95
- key: "getScrollDifference",
96
- value: function getScrollDifference() {
97
- var _this$restoreScrollAf = this.restoreScrollAfterRenderValues,
98
- index = _this$restoreScrollAf.index,
99
- visibleAreaTop = _this$restoreScrollAf.visibleAreaTop;
100
- this.restoreScrollAfterRenderValues = undefined; // `firstShownItemIndex` is supposed to be `0` here.
101
-
102
- var newVisibleAreaTop = this.screen.getChildElementTopOffset(this.getContainerElement(), index);
103
- return newVisibleAreaTop - visibleAreaTop;
104
- }
105
- }]);
106
-
107
- return RestoreScroll;
108
- }();
109
-
110
- export { RestoreScroll as default };
111
- //# sourceMappingURL=RestoreScroll.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../source/RestoreScroll.js"],"names":["RestoreScroll","screen","getContainerElement","scrollBy","previousItems","newItems","prependedItemsCount","length","container","firstItemTopOffset","getChildElementTopOffset","restoreScrollAfterRenderValues","index","visibleAreaTop","undefined","newVisibleAreaTop"],"mappings":";;;;;;IAAqBA,a;;;AACpB,+BAIG;AAAA,QAHFC,MAGE,QAHFA,MAGE;AAAA,QAFFC,mBAEE,QAFFA,mBAEE;AAAA,QADFC,QACE,QADFA,QACE;;AAAA;;AACF,SAAKF,MAAL,GAAcA,MAAd;AACA,SAAKC,mBAAL,GAA2BA,mBAA3B;AACA,SAAKC,QAAL,GAAgBA,QAAhB;AACA;AAED;;;;;;;;;;yCAUG;AAAA,UAHFC,aAGE,SAHFA,aAGE;AAAA,UAFFC,QAEE,SAFFA,QAEE;AAAA,UADFC,mBACE,SADFA,mBACE;;AACF;AACA;AACA,UAAIF,aAAa,CAACG,MAAd,KAAyB,CAA7B,EAAgC;AAC/B;AACA,OALC,CAMF;;;AACA,UAAID,mBAAmB,KAAK,CAA5B,EAA+B;AAC9B;AACA;;AACD,UAAME,SAAS,GAAG,KAAKN,mBAAL,EAAlB;AACA,UAAMO,kBAAkB,GAAG,KAAKR,MAAL,CAAYS,wBAAZ,CAAqCF,SAArC,EAAgD,CAAhD,CAA3B,CAXE,CAYF;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,UAAI,KAAKG,8BAAL,IACH,KAAKA,8BAAL,CAAoCP,aAApC,KAAsDA,aADnD,IAEH,KAAKO,8BAAL,CAAoCN,QAApC,KAAiDA,QAFlD,EAE4D;AAC3D;AACA;;AACD,WAAKM,8BAAL,GAAsC;AACrCP,QAAAA,aAAa,EAAbA,aADqC;AAErCC,QAAAA,QAAQ,EAARA,QAFqC;AAGrCO,QAAAA,KAAK,EAAEN,mBAH8B;AAIrCO,QAAAA,cAAc,EAAEJ;AAJqB,OAAtC;AAMA;;;yCAEoB;AACpB,aAAO,KAAKE,8BAAL,CAAoCC,KAA3C;AACA;;;qDAEgC;AAChC,aAAO,KAAKD,8BAAL,KAAwCG,SAA/C;AACA;;;0CAEqB;AAAA,kCACa,KAAKH,8BADlB;AAAA,UACbC,KADa,yBACbA,KADa;AAAA,UACNC,cADM,yBACNA,cADM;AAErB,WAAKF,8BAAL,GAAsCG,SAAtC,CAFqB,CAGrB;;AACA,UAAMC,iBAAiB,GAAG,KAAKd,MAAL,CAAYS,wBAAZ,CAAqC,KAAKR,mBAAL,EAArC,EAAiEU,KAAjE,CAA1B;AACA,aAAOG,iBAAiB,GAAGF,cAA3B;AACA;;;;;;SApFmBb,a","sourcesContent":["export default class RestoreScroll {\r\n\tconstructor({\r\n\t\tscreen,\r\n\t\tgetContainerElement,\r\n\t\tscrollBy\r\n\t}) {\r\n\t\tthis.screen = screen\r\n\t\tthis.getContainerElement = getContainerElement\r\n\t\tthis.scrollBy = scrollBy\r\n\t}\r\n\r\n\t/**\r\n\t * `<ReactVirtualScroller/>` calls this method.\r\n\t * @param {any[]} previousItems\r\n\t * @param {any[]} newItems\r\n\t * @param {number} prependedItemsCount\r\n\t */\r\n\tcaptureScroll({\r\n\t\tpreviousItems,\r\n\t\tnewItems,\r\n\t\tprependedItemsCount\r\n\t}) {\r\n\t\t// If there were no items in the list\r\n\t\t// then there's no point in restoring scroll position.\r\n\t\tif (previousItems.length === 0) {\r\n\t\t\treturn\r\n\t\t}\r\n\t\t// If no items were prepended then no need to restore scroll position.\r\n\t\tif (prependedItemsCount === 0) {\r\n\t\t\treturn\r\n\t\t}\r\n\t\tconst container = this.getContainerElement()\r\n\t\tconst firstItemTopOffset = this.screen.getChildElementTopOffset(container, 0)\r\n\t\t// The first item is supposed to be shown when the user clicks\r\n\t\t// \"Show previous items\" button. If it isn't shown though,\r\n\t\t// could still calculate the first item's top position using\r\n\t\t// the values from `itemHeights` and `verticalSpacing`.\r\n\t\t// But that would be a weird non-realistic scenario.\r\n\t\t// if (firstShownItemIndex > 0) {\r\n\t\t// \tlet i = firstShownItemIndex - 1\r\n\t\t// \twhile (i >= 0) {\r\n\t\t// \t\tfirstItemTopOffset += itemHeights[i] + verticalSpacing\r\n\t\t// \t\ti--\r\n\t\t// \t}\r\n\t\t// }\r\n\t\t// If the scroll position has already been captured for restoration,\r\n\t\t// then don't capture it the second time.\r\n\t\t// Capturing scroll position could happen when using `<ReactVirtualScroller/>`\r\n\t\t// because it calls `.captureScroll()` inside `ReactVirtualScroller.render()`\r\n\t\t// which is followed by `<VirtualScroller/>`'s `.componentDidUpdate()`\r\n\t\t// that also calls `.captureScroll()` with the same arguments,\r\n\t\t// so that second call to `.captureScroll()` is ignored.\r\n\t\t// Calling `.captureScroll()` inside `ReactVirtualScroller.render()`\r\n\t\t// is done to prevent scroll Y position from jumping\r\n\t\t// when showing the first page of the \"Previous items\".\r\n\t\t// See the long section of comments in `ReactVirtualScroller.render()`\r\n\t\t// method for more info on why is `.captureScroll()` called there.\r\n\t\tif (this.restoreScrollAfterRenderValues &&\r\n\t\t\tthis.restoreScrollAfterRenderValues.previousItems === previousItems &&\r\n\t\t\tthis.restoreScrollAfterRenderValues.newItems === newItems) {\r\n\t\t\treturn\r\n\t\t}\r\n\t\tthis.restoreScrollAfterRenderValues = {\r\n\t\t\tpreviousItems,\r\n\t\t\tnewItems,\r\n\t\t\tindex: prependedItemsCount,\r\n\t\t\tvisibleAreaTop: firstItemTopOffset\r\n\t\t}\r\n\t}\r\n\r\n\tgetAnchorItemIndex() {\r\n\t\treturn this.restoreScrollAfterRenderValues.index\r\n\t}\r\n\r\n\tshouldRestoreScrollAfterRender() {\r\n\t\treturn this.restoreScrollAfterRenderValues !== undefined\r\n\t}\r\n\r\n\tgetScrollDifference() {\r\n\t\tconst { index, visibleAreaTop } = this.restoreScrollAfterRenderValues\r\n\t\tthis.restoreScrollAfterRenderValues = undefined\r\n\t\t// `firstShownItemIndex` is supposed to be `0` here.\r\n\t\tconst newVisibleAreaTop = this.screen.getChildElementTopOffset(this.getContainerElement(), index)\r\n\t\treturn newVisibleAreaTop - visibleAreaTop\r\n\t}\r\n}"],"file":"RestoreScroll.js"}
@@ -1,4 +0,0 @@
1
- 'use strict'
2
-
3
- exports = module.exports = require('../commonjs/react/VirtualScroller').default
4
- exports['default'] = require('../commonjs/react/VirtualScroller').default
@@ -1,22 +0,0 @@
1
- import Screen from './Screen'
2
-
3
- import ScrollableContainer, {
4
- ScrollableWindowContainer
5
- } from './ScrollableContainer'
6
-
7
- export default {
8
- name: 'DOM',
9
- createScreen() {
10
- return new Screen()
11
- },
12
- // Create `scrollableContainer`.
13
- // On client side, `scrollableContainer` is always created.
14
- // On server side, `scrollableContainer` is not created (and not used).
15
- createScrollableContainer(scrollableContainer) {
16
- if (scrollableContainer) {
17
- return new ScrollableContainer(scrollableContainer)
18
- } else if (typeof window !== 'undefined') {
19
- return new ScrollableWindowContainer()
20
- }
21
- }
22
- }
@@ -1,51 +0,0 @@
1
- export default class Screen {
2
- /**
3
- * Returns a child element's "top offset", relative to the `parentElement`'s top edge.
4
- * @param {Element} parentElement
5
- * @param {number} childElementIndex
6
- * @return {number}
7
- */
8
- getChildElementTopOffset(parentElement, childElementIndex) {
9
- return parentElement.childNodes[childElementIndex].getBoundingClientRect().top
10
- }
11
-
12
- /**
13
- * Returns a child element's height.
14
- * @param {Element} parentElement
15
- * @param {number} childElementIndex
16
- * @return {number}
17
- */
18
- getChildElementHeight(parentElement, childElementIndex) {
19
- return this.getElementHeight(parentElement.childNodes[childElementIndex])
20
- }
21
-
22
- /**
23
- * Returns the count of child elements of an element.
24
- * @param {Element} parentElement
25
- * @return {number}
26
- */
27
- getChildElementsCount(parentElement) {
28
- return parentElement.childNodes.length
29
- }
30
-
31
- /**
32
- * Removes all child elements of an element.
33
- * @param {Element} element
34
- */
35
- clearElement(element) {
36
- while (element.firstChild) {
37
- element.removeChild(element.firstChild)
38
- }
39
- }
40
-
41
- /**
42
- * Returns an element's height.
43
- * @param {Element} element
44
- * @return {number}
45
- */
46
- getElementHeight(element) {
47
- // `offsetHeight` is not precise enough (doesn't return fractional pixels).
48
- // return element.offsetHeight
49
- return element.getBoundingClientRect().height
50
- }
51
- }
@@ -1,86 +0,0 @@
1
- export default class RestoreScroll {
2
- constructor({
3
- screen,
4
- getContainerElement,
5
- scrollBy
6
- }) {
7
- this.screen = screen
8
- this.getContainerElement = getContainerElement
9
- this.scrollBy = scrollBy
10
- }
11
-
12
- /**
13
- * `<ReactVirtualScroller/>` calls this method.
14
- * @param {any[]} previousItems
15
- * @param {any[]} newItems
16
- * @param {number} prependedItemsCount
17
- */
18
- captureScroll({
19
- previousItems,
20
- newItems,
21
- prependedItemsCount
22
- }) {
23
- // If there were no items in the list
24
- // then there's no point in restoring scroll position.
25
- if (previousItems.length === 0) {
26
- return
27
- }
28
- // If no items were prepended then no need to restore scroll position.
29
- if (prependedItemsCount === 0) {
30
- return
31
- }
32
- const container = this.getContainerElement()
33
- const firstItemTopOffset = this.screen.getChildElementTopOffset(container, 0)
34
- // The first item is supposed to be shown when the user clicks
35
- // "Show previous items" button. If it isn't shown though,
36
- // could still calculate the first item's top position using
37
- // the values from `itemHeights` and `verticalSpacing`.
38
- // But that would be a weird non-realistic scenario.
39
- // if (firstShownItemIndex > 0) {
40
- // let i = firstShownItemIndex - 1
41
- // while (i >= 0) {
42
- // firstItemTopOffset += itemHeights[i] + verticalSpacing
43
- // i--
44
- // }
45
- // }
46
- // If the scroll position has already been captured for restoration,
47
- // then don't capture it the second time.
48
- // Capturing scroll position could happen when using `<ReactVirtualScroller/>`
49
- // because it calls `.captureScroll()` inside `ReactVirtualScroller.render()`
50
- // which is followed by `<VirtualScroller/>`'s `.componentDidUpdate()`
51
- // that also calls `.captureScroll()` with the same arguments,
52
- // so that second call to `.captureScroll()` is ignored.
53
- // Calling `.captureScroll()` inside `ReactVirtualScroller.render()`
54
- // is done to prevent scroll Y position from jumping
55
- // when showing the first page of the "Previous items".
56
- // See the long section of comments in `ReactVirtualScroller.render()`
57
- // method for more info on why is `.captureScroll()` called there.
58
- if (this.restoreScrollAfterRenderValues &&
59
- this.restoreScrollAfterRenderValues.previousItems === previousItems &&
60
- this.restoreScrollAfterRenderValues.newItems === newItems) {
61
- return
62
- }
63
- this.restoreScrollAfterRenderValues = {
64
- previousItems,
65
- newItems,
66
- index: prependedItemsCount,
67
- visibleAreaTop: firstItemTopOffset
68
- }
69
- }
70
-
71
- getAnchorItemIndex() {
72
- return this.restoreScrollAfterRenderValues.index
73
- }
74
-
75
- shouldRestoreScrollAfterRender() {
76
- return this.restoreScrollAfterRenderValues !== undefined
77
- }
78
-
79
- getScrollDifference() {
80
- const { index, visibleAreaTop } = this.restoreScrollAfterRenderValues
81
- this.restoreScrollAfterRenderValues = undefined
82
- // `firstShownItemIndex` is supposed to be `0` here.
83
- const newVisibleAreaTop = this.screen.getChildElementTopOffset(this.getContainerElement(), index)
84
- return newVisibleAreaTop - visibleAreaTop
85
- }
86
- }