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
@@ -0,0 +1,283 @@
1
+ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
2
+
3
+ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
4
+
5
+ function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
6
+
7
+ import log, { warn, isDebug, reportError } from './utility/debug.js';
8
+ import { cleanUpBeforeResizeState } from './BeforeResize.js';
9
+ import getStateSnapshot from './utility/getStateSnapshot.js'; // There're three main places where state is updated:
10
+ //
11
+ // * On scroll.
12
+ // * On window resize.
13
+ // * On set new items.
14
+ //
15
+ // State updates may be "asynchronous" (like in React), in which case the
16
+ // corresponding operation is "pending" until the state update is applied.
17
+ //
18
+ // If there's a "pending" window resize or a "pending" update of the set of items,
19
+ // then "on scroll" updates aren't dispatched.
20
+ //
21
+ // If there's a "pending" on scroll update and the window is resize or a new set
22
+ // of items is set, then that "pending" on scroll update gets overwritten.
23
+ //
24
+ // If there's a "pending" update of the set of items, then window resize handler
25
+ // sees that "pending" update and dispatches its own state update so that the
26
+ // "pending" state update originating from `setItems()` is not lost.
27
+ //
28
+ // If there's a "pending" window resize, and a new set of items is set,
29
+ // then the state update of the window resize handler gets overwritten.
30
+
31
+ export default function createStateHelpers(_ref) {
32
+ var _this = this;
33
+
34
+ var state = _ref.state,
35
+ onStateChange = _ref.onStateChange,
36
+ render = _ref.render,
37
+ initialItems = _ref.items;
38
+ this.onStateChange = onStateChange;
39
+ this._render = render;
40
+
41
+ this._onItemStateChange = function (i, newItemState) {
42
+ if (isDebug()) {
43
+ log('~ Item state changed ~');
44
+ log('Item', i); // Uses `JSON.stringify()` here instead of just outputting the JSON objects as is
45
+ // because outputting JSON objects as is would show different results later when
46
+ // the developer inspects those in the web browser console if those state objects
47
+ // get modified in between they've been output to the console and the developer
48
+ // decided to inspect them.
49
+
50
+ log('Previous state' + '\n' + JSON.stringify(_this.getState().itemStates[i], null, 2));
51
+ log('New state' + '\n' + JSON.stringify(newItemState, null, 2));
52
+ }
53
+
54
+ _this.getState().itemStates[i] = newItemState; // Schedule the item state update for after the new items have been rendered.
55
+
56
+ if (_this.newItemsWillBeRendered) {
57
+ if (!_this.itemStatesThatChangedWhileNewItemsWereBeingRendered) {
58
+ _this.itemStatesThatChangedWhileNewItemsWereBeingRendered = {};
59
+ }
60
+
61
+ _this.itemStatesThatChangedWhileNewItemsWereBeingRendered[String(i)] = newItemState;
62
+ }
63
+ };
64
+
65
+ this.getState = function () {
66
+ return _this._getState();
67
+ };
68
+
69
+ this.updateState = function (stateUpdate) {
70
+ if (isDebug()) {
71
+ log('~ Set state ~');
72
+ log(getStateSnapshot(stateUpdate));
73
+ } // Ensure that a non-initial `stateUpdate` can only contain an `items`
74
+ // property when it comes from a `setItems()` call.
75
+
76
+
77
+ if (stateUpdate.items) {
78
+ if (!_this._isSettingNewItems) {
79
+ reportError('A `stateUpdate` can only contain `items` property as a result of calling `.setItems()`');
80
+ }
81
+ }
82
+
83
+ _this._isSettingNewItems = undefined; // Update `state`.
84
+
85
+ _this.previousState = _this.getState();
86
+
87
+ _this._updateState(stateUpdate);
88
+ };
89
+
90
+ this.getInitialState = function () {
91
+ if (state) {
92
+ return getRestoredState.call(_this, state);
93
+ }
94
+
95
+ return getInitialStateFromScratch.call(_this);
96
+ };
97
+
98
+ this.useState = function (_ref2) {
99
+ var getState = _ref2.getState,
100
+ updateState = _ref2.updateState;
101
+
102
+ if (_this._isActive) {
103
+ throw new Error('[virtual-scroller] `VirtualScroller` has already been started');
104
+ }
105
+
106
+ if (_this._getState) {
107
+ throw new Error('[virtual-scroller] Custom state storage has already been configured');
108
+ }
109
+
110
+ if (render) {
111
+ throw new Error('[virtual-scroller] Creating a `VirtualScroller` class instance with a `render()` parameter means using the default (internal) state storage');
112
+ }
113
+
114
+ if (!getState || !updateState) {
115
+ throw new Error('[virtual-scroller] When using a custom state storage, one must supply both `getState()` and `updateState()` functions');
116
+ }
117
+
118
+ _this._usesCustomStateStorage = true;
119
+ _this._getState = getState;
120
+ _this._updateState = updateState;
121
+ };
122
+
123
+ this.useDefaultStateStorage = function () {
124
+ if (!render) {
125
+ throw new Error('[virtual-scroller] When using the default (internal) state management, one must supply a `render(state, prevState)` function parameter');
126
+ } // Create default `getState()`/`updateState()` functions.
127
+
128
+
129
+ _this._getState = defaultGetState.bind(_this);
130
+ _this._updateState = defaultUpdateState.bind(_this); // When `state` is stored externally, a developer is responsible for
131
+ // initializing it with the initial value.
132
+ // Otherwise, if default state management is used, set the initial state now.
133
+
134
+ var setInitialState = defaultSetInitialState.bind(_this);
135
+ setInitialState(_this.getInitialState());
136
+ };
137
+
138
+ function defaultGetState() {
139
+ return this.state;
140
+ }
141
+
142
+ function defaultSetInitialState(newState) {
143
+ this.state = newState;
144
+ }
145
+
146
+ function defaultUpdateState(stateUpdate) {
147
+ // Because this variant of `.updateState()` is "synchronous" (immediate),
148
+ // it can be written like `...prevState`, and no state updates would be lost.
149
+ // But if it was "asynchronous" (not immediate), then `...prevState`
150
+ // wouldn't work in all cases, because it could be stale in cases
151
+ // when more than a single `updateState()` call is made before
152
+ // the state actually updates, making `prevState` stale.
153
+ this.state = _objectSpread(_objectSpread({}, this.state), stateUpdate);
154
+ render(this.state, this.previousState);
155
+ this.onRender();
156
+ }
157
+ /**
158
+ * Returns the initial state of the `VirtualScroller` "from scratch".
159
+ * (i.e. not from a previously saved one).
160
+ * @return {object}
161
+ */
162
+
163
+
164
+ function getInitialStateFromScratch() {
165
+ var items = initialItems;
166
+
167
+ var state = _objectSpread(_objectSpread({}, getInitialLayoutState.call(this, items)), {}, {
168
+ items: items,
169
+ itemStates: new Array(items.length)
170
+ });
171
+
172
+ if (isDebug()) {
173
+ log('Initial state (autogenerated)', getStateSnapshot(state));
174
+ }
175
+
176
+ log('First shown item index', state.firstShownItemIndex);
177
+ log('Last shown item index', state.lastShownItemIndex);
178
+ return state;
179
+ }
180
+
181
+ function getRestoredState(state) {
182
+ if (isDebug()) {
183
+ log('Restore state', getStateSnapshot(state));
184
+ } // Possibly clean up "before resize" property in state.
185
+ // "Before resize" state property is cleaned up when all "before resize" item heights
186
+ // have been re-measured in an asynchronous `this.updateState({ beforeResize: undefined })` call.
187
+ // If `VirtualScroller` state was snapshotted externally before that `this.updateState()` call
188
+ // has been applied, then "before resize" property might have not been cleaned up properly.
189
+
190
+
191
+ state = cleanUpBeforeResizeState(state); // Reset `verticalSpacing` so that it re-measures it after the list
192
+ // has been rendered initially. The rationale is that a previously captured
193
+ // inter-item vertical spacing can't be "trusted" in a sense that the user
194
+ // might have resized the window after the previous `state` has been snapshotted.
195
+ // If the user has resized the window, then changing window width might have
196
+ // activated different CSS `@media()` "queries" resulting in a potentially different
197
+ // vertical spacing when the `VirtualScroller` is re-created with such previously
198
+ // snapshotted state.
199
+
200
+ state = _objectSpread(_objectSpread({}, state), {}, {
201
+ verticalSpacing: undefined
202
+ }); // `this.verticalSpacing` acts as a "true" source for vertical spacing value.
203
+ // Vertical spacing is also stored in `state` but `state` updates could be
204
+ // "asynchronous" (not applied immediately) and `this.onUpdateShownItemIndexes()`
205
+ // requires vertical spacing to be correct at any time, without any delays.
206
+ // So, vertical spacing is also duplicated in `state`, but the "true" source
207
+ // is still `this.verticalSpacing`.
208
+ //
209
+ // `this.verticalSpacing` must be initialized before calling `this.getInitialStateFromScratch()`
210
+ // because `this.getInitialStateFromScratch()` uses `this.verticalSpacing` in its calculations.
211
+ //
212
+ // With the code above, `state.verticalSpacing` is always gonna be `undefined`,
213
+ // so commented out this code. It's safer to just re-measure vertical spacing
214
+ // from scratch when `VirtualScroller` is mounted.
215
+ //
216
+ // this.verticalSpacing = state ? state.verticalSpacing : undefined
217
+ // Check if the actual `columnsCount` on the screen matches the one from state.
218
+
219
+ if (isStateColumnsCountMismatch(state, {
220
+ columnsCount: this.getActualColumnsCount()
221
+ })) {
222
+ warn('Reset Layout');
223
+ state = _objectSpread(_objectSpread({}, state), getInitialLayoutState.call(this, state.items));
224
+ }
225
+
226
+ return state;
227
+ }
228
+
229
+ function getInitialLayoutState(items) {
230
+ var itemsCount = items.length;
231
+
232
+ var _this$layout$getIniti = this.layout.getInitialLayoutValues({
233
+ itemsCount: itemsCount,
234
+ columnsCount: this.getActualColumnsCount()
235
+ }),
236
+ firstShownItemIndex = _this$layout$getIniti.firstShownItemIndex,
237
+ lastShownItemIndex = _this$layout$getIniti.lastShownItemIndex,
238
+ beforeItemsHeight = _this$layout$getIniti.beforeItemsHeight,
239
+ afterItemsHeight = _this$layout$getIniti.afterItemsHeight;
240
+
241
+ var itemHeights = new Array(itemsCount); // Optionally preload items to be rendered.
242
+
243
+ this.onBeforeShowItems(items, itemHeights, firstShownItemIndex, lastShownItemIndex);
244
+ return {
245
+ itemHeights: itemHeights,
246
+ columnsCount: this.getActualColumnsCountForState(),
247
+ verticalSpacing: this.verticalSpacing,
248
+ firstShownItemIndex: firstShownItemIndex,
249
+ lastShownItemIndex: lastShownItemIndex,
250
+ beforeItemsHeight: beforeItemsHeight,
251
+ afterItemsHeight: afterItemsHeight
252
+ };
253
+ } // Checks if the actual `columnsCount` on the screen matches the one from state.
254
+ //
255
+ // For example, a developer might snapshot `VirtualScroller` state
256
+ // when the user navigates from the page containing the list
257
+ // in order to later restore the list's state when the user goes "Back".
258
+ // But, the user might have also resized the window while being on that
259
+ // "other" page, and when they come "Back", their snapshotted state
260
+ // no longer qualifies. Well, it does qualify, but only partially.
261
+ // For example, `itemStates` are still valid, but first and last shown
262
+ // item indexes aren't.
263
+ //
264
+
265
+
266
+ function isStateColumnsCountMismatch(state, _ref3) {
267
+ var columnsCount = _ref3.columnsCount;
268
+ var stateColumnsCount = state.columnsCount || 1;
269
+
270
+ if (stateColumnsCount !== columnsCount) {
271
+ warn('~ Columns Count changed from', stateColumnsCount, 'to', columnsCount, '~');
272
+ return true;
273
+ }
274
+
275
+ var firstShownItemIndex = Math.floor(state.firstShownItemIndex / columnsCount) * columnsCount;
276
+
277
+ if (firstShownItemIndex !== state.firstShownItemIndex) {
278
+ warn('~ First Shown Item Index', state.firstShownItemIndex, 'is not divisible by Columns Count', columnsCount, '~');
279
+ return true;
280
+ }
281
+ }
282
+ }
283
+ //# sourceMappingURL=VirtualScroller.state.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"VirtualScroller.state.js","names":["log","warn","isDebug","reportError","cleanUpBeforeResizeState","getStateSnapshot","createStateHelpers","state","onStateChange","render","initialItems","items","_render","_onItemStateChange","i","newItemState","JSON","stringify","getState","itemStates","newItemsWillBeRendered","itemStatesThatChangedWhileNewItemsWereBeingRendered","String","_getState","updateState","stateUpdate","_isSettingNewItems","undefined","previousState","_updateState","getInitialState","getRestoredState","call","getInitialStateFromScratch","useState","_isActive","Error","_usesCustomStateStorage","useDefaultStateStorage","defaultGetState","bind","defaultUpdateState","setInitialState","defaultSetInitialState","newState","onRender","getInitialLayoutState","Array","length","firstShownItemIndex","lastShownItemIndex","verticalSpacing","isStateColumnsCountMismatch","columnsCount","getActualColumnsCount","itemsCount","layout","getInitialLayoutValues","beforeItemsHeight","afterItemsHeight","itemHeights","onBeforeShowItems","getActualColumnsCountForState","stateColumnsCount","Math","floor"],"sources":["../source/VirtualScroller.state.js"],"sourcesContent":["import log, { warn, isDebug, reportError } from './utility/debug.js'\r\nimport { cleanUpBeforeResizeState } from './BeforeResize.js'\r\nimport getStateSnapshot from './utility/getStateSnapshot.js'\r\n\r\n// There're three main places where state is updated:\r\n//\r\n// * On scroll.\r\n// * On window resize.\r\n// * On set new items.\r\n//\r\n// State updates may be \"asynchronous\" (like in React), in which case the\r\n// corresponding operation is \"pending\" until the state update is applied.\r\n//\r\n// If there's a \"pending\" window resize or a \"pending\" update of the set of items,\r\n// then \"on scroll\" updates aren't dispatched.\r\n//\r\n// If there's a \"pending\" on scroll update and the window is resize or a new set\r\n// of items is set, then that \"pending\" on scroll update gets overwritten.\r\n//\r\n// If there's a \"pending\" update of the set of items, then window resize handler\r\n// sees that \"pending\" update and dispatches its own state update so that the\r\n// \"pending\" state update originating from `setItems()` is not lost.\r\n//\r\n// If there's a \"pending\" window resize, and a new set of items is set,\r\n// then the state update of the window resize handler gets overwritten.\r\n\r\nexport default function createStateHelpers({\r\n\tstate,\r\n\tonStateChange,\r\n\trender,\r\n\titems: initialItems\r\n}) {\r\n\tthis.onStateChange = onStateChange\r\n\tthis._render = render\r\n\r\n\tthis._onItemStateChange = (i, newItemState) => {\r\n\t\tif (isDebug()) {\r\n\t\t\tlog('~ Item state changed ~')\r\n\t\t\tlog('Item', i)\r\n\t\t\t// Uses `JSON.stringify()` here instead of just outputting the JSON objects as is\r\n\t\t\t// because outputting JSON objects as is would show different results later when\r\n\t\t\t// the developer inspects those in the web browser console if those state objects\r\n\t\t\t// get modified in between they've been output to the console and the developer\r\n\t\t\t// decided to inspect them.\r\n\t\t\tlog('Previous state' + '\\n' + JSON.stringify(this.getState().itemStates[i], null, 2))\r\n\t\t\tlog('New state' + '\\n' + JSON.stringify(newItemState, null, 2))\r\n\t\t}\r\n\r\n\t\tthis.getState().itemStates[i] = newItemState\r\n\r\n\t\t// Schedule the item state update for after the new items have been rendered.\r\n\t\tif (this.newItemsWillBeRendered) {\r\n\t\t\tif (!this.itemStatesThatChangedWhileNewItemsWereBeingRendered) {\r\n\t\t\t\tthis.itemStatesThatChangedWhileNewItemsWereBeingRendered = {}\r\n\t\t\t}\r\n\t\t\tthis.itemStatesThatChangedWhileNewItemsWereBeingRendered[String(i)] = newItemState\r\n\t\t}\r\n\t}\r\n\r\n\tthis.getState = () => this._getState()\r\n\r\n\tthis.updateState = (stateUpdate) => {\r\n\t\tif (isDebug()) {\r\n\t\t\tlog('~ Set state ~')\r\n\t\t\tlog(getStateSnapshot(stateUpdate))\r\n\t\t}\r\n\r\n\t\t// Ensure that a non-initial `stateUpdate` can only contain an `items`\r\n\t\t// property when it comes from a `setItems()` call.\r\n\t\tif (stateUpdate.items) {\r\n\t\t\tif (!this._isSettingNewItems) {\r\n\t\t\t\treportError('A `stateUpdate` can only contain `items` property as a result of calling `.setItems()`')\r\n\t\t\t}\r\n\t\t}\r\n\t\tthis._isSettingNewItems = undefined\r\n\r\n\t\t// Update `state`.\r\n\t\tthis.previousState = this.getState()\r\n\t\tthis._updateState(stateUpdate)\r\n\t}\r\n\r\n\tthis.getInitialState = () => {\r\n\t\tif (state) {\r\n\t\t\treturn getRestoredState.call(this, state)\r\n\t\t}\r\n\t\treturn getInitialStateFromScratch.call(this)\r\n\t}\r\n\r\n\tthis.useState = ({\r\n\t\tgetState,\r\n\t\tupdateState\r\n\t}) => {\r\n\t\tif (this._isActive) {\r\n\t\t\tthrow new Error('[virtual-scroller] `VirtualScroller` has already been started')\r\n\t\t}\r\n\r\n\t\tif (this._getState) {\r\n\t\t\tthrow new Error('[virtual-scroller] Custom state storage has already been configured')\r\n\t\t}\r\n\r\n\t\tif (render) {\r\n\t\t\tthrow new Error('[virtual-scroller] Creating a `VirtualScroller` class instance with a `render()` parameter means using the default (internal) state storage')\r\n\t\t}\r\n\r\n\t\tif (!getState || !updateState) {\r\n\t\t\tthrow new Error('[virtual-scroller] When using a custom state storage, one must supply both `getState()` and `updateState()` functions')\r\n\t\t}\r\n\r\n\t\tthis._usesCustomStateStorage = true\r\n\r\n\t\tthis._getState = getState\r\n\t\tthis._updateState = updateState\r\n\t}\r\n\r\n\tthis.useDefaultStateStorage = () => {\r\n\t\tif (!render) {\r\n\t\t\tthrow new Error('[virtual-scroller] When using the default (internal) state management, one must supply a `render(state, prevState)` function parameter')\r\n\t\t}\r\n\r\n\t\t// Create default `getState()`/`updateState()` functions.\r\n\t\tthis._getState = defaultGetState.bind(this)\r\n\t\tthis._updateState = defaultUpdateState.bind(this)\r\n\r\n\t\t// When `state` is stored externally, a developer is responsible for\r\n\t\t// initializing it with the initial value.\r\n\t\t// Otherwise, if default state management is used, set the initial state now.\r\n\t\tconst setInitialState = defaultSetInitialState.bind(this)\r\n\t\tsetInitialState(this.getInitialState())\r\n\t}\r\n\r\n\tfunction defaultGetState() {\r\n\t\treturn this.state\r\n\t}\r\n\r\n\tfunction defaultSetInitialState(newState) {\r\n\t\tthis.state = newState\r\n\t}\r\n\r\n\tfunction defaultUpdateState(stateUpdate) {\r\n\t\t// Because this variant of `.updateState()` is \"synchronous\" (immediate),\r\n\t\t// it can be written like `...prevState`, and no state updates would be lost.\r\n\t\t// But if it was \"asynchronous\" (not immediate), then `...prevState`\r\n\t\t// wouldn't work in all cases, because it could be stale in cases\r\n\t\t// when more than a single `updateState()` call is made before\r\n\t\t// the state actually updates, making `prevState` stale.\r\n\t\tthis.state = {\r\n\t\t\t...this.state,\r\n\t\t\t...stateUpdate\r\n\t\t}\r\n\r\n\t\trender(this.state, this.previousState)\r\n\r\n\t\tthis.onRender()\r\n\t}\r\n\r\n\t/**\r\n\t * Returns the initial state of the `VirtualScroller` \"from scratch\".\r\n\t * (i.e. not from a previously saved one).\r\n\t * @return {object}\r\n\t */\r\n\tfunction getInitialStateFromScratch() {\r\n\t\tconst items = initialItems\r\n\t\tconst state = {\r\n\t\t\t...getInitialLayoutState.call(this, items),\r\n\t\t\titems,\r\n\t\t\titemStates: new Array(items.length)\r\n\t\t}\r\n\t\tif (isDebug()) {\r\n\t\t\tlog('Initial state (autogenerated)', getStateSnapshot(state))\r\n\t\t}\r\n\t\tlog('First shown item index', state.firstShownItemIndex)\r\n\t\tlog('Last shown item index', state.lastShownItemIndex)\r\n\t\treturn state\r\n\t}\r\n\r\n\tfunction getRestoredState(state) {\r\n\t\tif (isDebug()) {\r\n\t\t\tlog('Restore state', getStateSnapshot(state))\r\n\t\t}\r\n\r\n\t\t// Possibly clean up \"before resize\" property in state.\r\n\t\t// \"Before resize\" state property is cleaned up when all \"before resize\" item heights\r\n\t\t// have been re-measured in an asynchronous `this.updateState({ beforeResize: undefined })` call.\r\n\t\t// If `VirtualScroller` state was snapshotted externally before that `this.updateState()` call\r\n\t\t// has been applied, then \"before resize\" property might have not been cleaned up properly.\r\n\t\tstate = cleanUpBeforeResizeState(state)\r\n\r\n\t\t// Reset `verticalSpacing` so that it re-measures it after the list\r\n\t\t// has been rendered initially. The rationale is that a previously captured\r\n\t\t// inter-item vertical spacing can't be \"trusted\" in a sense that the user\r\n\t\t// might have resized the window after the previous `state` has been snapshotted.\r\n\t\t// If the user has resized the window, then changing window width might have\r\n\t\t// activated different CSS `@media()` \"queries\" resulting in a potentially different\r\n\t\t// vertical spacing when the `VirtualScroller` is re-created with such previously\r\n\t\t// snapshotted state.\r\n\t\tstate = {\r\n\t\t\t...state,\r\n\t\t\tverticalSpacing: undefined\r\n\t\t}\r\n\r\n\t\t// `this.verticalSpacing` acts as a \"true\" source for vertical spacing value.\r\n\t\t// Vertical spacing is also stored in `state` but `state` updates could be\r\n\t\t// \"asynchronous\" (not applied immediately) and `this.onUpdateShownItemIndexes()`\r\n\t\t// requires vertical spacing to be correct at any time, without any delays.\r\n\t\t// So, vertical spacing is also duplicated in `state`, but the \"true\" source\r\n\t\t// is still `this.verticalSpacing`.\r\n\t\t//\r\n\t\t// `this.verticalSpacing` must be initialized before calling `this.getInitialStateFromScratch()`\r\n\t\t// because `this.getInitialStateFromScratch()` uses `this.verticalSpacing` in its calculations.\r\n\t\t//\r\n\t\t// With the code above, `state.verticalSpacing` is always gonna be `undefined`,\r\n\t\t// so commented out this code. It's safer to just re-measure vertical spacing\r\n\t\t// from scratch when `VirtualScroller` is mounted.\r\n\t\t//\r\n\t\t// this.verticalSpacing = state ? state.verticalSpacing : undefined\r\n\r\n\t\t// Check if the actual `columnsCount` on the screen matches the one from state.\r\n\t\tif (isStateColumnsCountMismatch(state, {\r\n\t\t\tcolumnsCount: this.getActualColumnsCount()\r\n\t\t})) {\r\n\t\t\twarn('Reset Layout')\r\n\t\t\tstate = {\r\n\t\t\t\t...state,\r\n\t\t\t\t...getInitialLayoutState.call(this, state.items)\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\treturn state\r\n\t}\r\n\r\n\tfunction getInitialLayoutState(items) {\r\n\t\tconst itemsCount = items.length\r\n\t\tconst {\r\n\t\t\tfirstShownItemIndex,\r\n\t\t\tlastShownItemIndex,\r\n\t\t\tbeforeItemsHeight,\r\n\t\t\tafterItemsHeight\r\n\t\t} = this.layout.getInitialLayoutValues({\r\n\t\t\titemsCount,\r\n\t\t\tcolumnsCount: this.getActualColumnsCount()\r\n\t\t})\r\n\t\tconst itemHeights = new Array(itemsCount)\r\n\t\t// Optionally preload items to be rendered.\r\n\t\tthis.onBeforeShowItems(\r\n\t\t\titems,\r\n\t\t\titemHeights,\r\n\t\t\tfirstShownItemIndex,\r\n\t\t\tlastShownItemIndex\r\n\t\t)\r\n\t\treturn {\r\n\t\t\titemHeights,\r\n\t\t\tcolumnsCount: this.getActualColumnsCountForState(),\r\n\t\t\tverticalSpacing: this.verticalSpacing,\r\n\t\t\tfirstShownItemIndex,\r\n\t\t\tlastShownItemIndex,\r\n\t\t\tbeforeItemsHeight,\r\n\t\t\tafterItemsHeight\r\n\t\t}\r\n\t}\r\n\r\n\t// Checks if the actual `columnsCount` on the screen matches the one from state.\r\n\t//\r\n\t// For example, a developer might snapshot `VirtualScroller` state\r\n\t// when the user navigates from the page containing the list\r\n\t// in order to later restore the list's state when the user goes \"Back\".\r\n\t// But, the user might have also resized the window while being on that\r\n\t// \"other\" page, and when they come \"Back\", their snapshotted state\r\n\t// no longer qualifies. Well, it does qualify, but only partially.\r\n\t// For example, `itemStates` are still valid, but first and last shown\r\n\t// item indexes aren't.\r\n\t//\r\n\tfunction isStateColumnsCountMismatch(state, { columnsCount }) {\r\n\t\tconst stateColumnsCount = state.columnsCount || 1\r\n\t\tif (stateColumnsCount !== columnsCount) {\r\n\t\t\twarn('~ Columns Count changed from', stateColumnsCount, 'to', columnsCount, '~')\r\n\t\t\treturn true\r\n\t\t}\r\n\t\tconst firstShownItemIndex = Math.floor(state.firstShownItemIndex / columnsCount) * columnsCount\r\n\t\tif (firstShownItemIndex !== state.firstShownItemIndex) {\r\n\t\t\twarn('~ First Shown Item Index', state.firstShownItemIndex, 'is not divisible by Columns Count', columnsCount, '~')\r\n\t\t\treturn true\r\n\t\t}\r\n\t}\r\n}"],"mappings":";;;;;;AAAA,OAAOA,GAAP,IAAcC,IAAd,EAAoBC,OAApB,EAA6BC,WAA7B,QAAgD,oBAAhD;AACA,SAASC,wBAAT,QAAyC,mBAAzC;AACA,OAAOC,gBAAP,MAA6B,+BAA7B,C,CAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA,eAAe,SAASC,kBAAT,OAKZ;EAAA;;EAAA,IAJFC,KAIE,QAJFA,KAIE;EAAA,IAHFC,aAGE,QAHFA,aAGE;EAAA,IAFFC,MAEE,QAFFA,MAEE;EAAA,IADKC,YACL,QADFC,KACE;EACF,KAAKH,aAAL,GAAqBA,aAArB;EACA,KAAKI,OAAL,GAAeH,MAAf;;EAEA,KAAKI,kBAAL,GAA0B,UAACC,CAAD,EAAIC,YAAJ,EAAqB;IAC9C,IAAIb,OAAO,EAAX,EAAe;MACdF,GAAG,CAAC,wBAAD,CAAH;MACAA,GAA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IAAMU,iBAAiB,GAAGxD,KAAK,CAAC8C,YAAN,IAAsB,CAAhD;;IACA,IAAIU,iBAAiB,KAAKV,YAA1B,EAAwC;MACvCpD,IAAI,CAAC,8BAAD,EAAiC8D,iBAAjC,EAAoD,IAApD,EAA0DV,YAA1D,EAAwE,GAAxE,CAAJ;MACA,OAAO,IAAP;IACA;;IACD,IAAMJ,mBAAmB,GAAGe,IAAI,CAACC,KAAL,CAAW1D,KAAK,CAAC0C,mBAAN,GAA4BI,YAAvC,IAAuDA,YAAnF;;IACA,IAAIJ,mBAAmB,KAAK1C,KAAK,CAAC0C,mBAAlC,EAAuD;MACtDhD,IAAI,CAAC,0BAAD,EAA6BM,KAAK,CAAC0C,mBAAnC,EAAwD,mCAAxD,EAA6FI,YAA7F,EAA2G,GAA3G,CAAJ;MACA,OAAO,IAAP;IACA;EACD;AACD"}
@@ -0,0 +1,54 @@
1
+ import log from './utility/debug.js';
2
+ import getVerticalSpacing from './getVerticalSpacing.js';
3
+ export default function createVerticalSpacingHelpers() {
4
+ var _this = this;
5
+
6
+ // Bind to `this` in order to prevent bugs when this function is passed by reference
7
+ // and then called with its `this` being unintentionally `window` resulting in
8
+ // the `if` condition being "falsy".
9
+ this.getVerticalSpacing = function () {
10
+ return _this.verticalSpacing || 0;
11
+ };
12
+
13
+ this.getVerticalSpacingBeforeResize = function () {
14
+ // `beforeResize.verticalSpacing` can be `undefined`.
15
+ // For example, if `this.updateState({ verticalSpacing })` call hasn't been applied
16
+ // before the resize happened (in case of an "asynchronous" state update).
17
+ var _this$getState = _this.getState(),
18
+ beforeResize = _this$getState.beforeResize;
19
+
20
+ return beforeResize && beforeResize.verticalSpacing || 0;
21
+ };
22
+ /**
23
+ * Measures item vertical spacing, if not measured.
24
+ * @return {object} [stateUpdate]
25
+ */
26
+
27
+
28
+ this.measureVerticalSpacingIfNotMeasured = function () {
29
+ if (_this.verticalSpacing === undefined) {
30
+ _this.verticalSpacing = measureVerticalSpacing.call(_this);
31
+ return _this.verticalSpacing;
32
+ }
33
+ };
34
+
35
+ function measureVerticalSpacing() {
36
+ var _this$getState2 = this.getState(),
37
+ firstShownItemIndex = _this$getState2.firstShownItemIndex,
38
+ lastShownItemIndex = _this$getState2.lastShownItemIndex;
39
+
40
+ log('~ Measure item vertical spacing ~');
41
+ var verticalSpacing = getVerticalSpacing({
42
+ itemsContainer: this.itemsContainer,
43
+ renderedItemsCount: lastShownItemIndex - firstShownItemIndex + 1
44
+ });
45
+
46
+ if (verticalSpacing === undefined) {
47
+ log('Not enough items rendered to measure vertical spacing');
48
+ } else {
49
+ log('Item vertical spacing', verticalSpacing);
50
+ return verticalSpacing;
51
+ }
52
+ }
53
+ }
54
+ //# sourceMappingURL=VirtualScroller.verticalSpacing.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"VirtualScroller.verticalSpacing.js","names":["log","getVerticalSpacing","createVerticalSpacingHelpers","verticalSpacing","getVerticalSpacingBeforeResize","getState","beforeResize","measureVerticalSpacingIfNotMeasured","undefined","measureVerticalSpacing","call","firstShownItemIndex","lastShownItemIndex","itemsContainer","renderedItemsCount"],"sources":["../source/VirtualScroller.verticalSpacing.js"],"sourcesContent":["import log from './utility/debug.js'\r\nimport getVerticalSpacing from './getVerticalSpacing.js'\r\n\r\nexport default function createVerticalSpacingHelpers() {\r\n\t// Bind to `this` in order to prevent bugs when this function is passed by reference\r\n\t// and then called with its `this` being unintentionally `window` resulting in\r\n\t// the `if` condition being \"falsy\".\r\n\tthis.getVerticalSpacing = () => {\r\n\t\treturn this.verticalSpacing || 0\r\n\t}\r\n\r\n\tthis.getVerticalSpacingBeforeResize = () => {\r\n\t\t// `beforeResize.verticalSpacing` can be `undefined`.\r\n\t\t// For example, if `this.updateState({ verticalSpacing })` call hasn't been applied\r\n\t\t// before the resize happened (in case of an \"asynchronous\" state update).\r\n\t\tconst { beforeResize } = this.getState()\r\n\t\treturn beforeResize && beforeResize.verticalSpacing || 0\r\n\t}\r\n\r\n\t/**\r\n\t * Measures item vertical spacing, if not measured.\r\n\t * @return {object} [stateUpdate]\r\n\t */\r\n\tthis.measureVerticalSpacingIfNotMeasured = () => {\r\n\t\tif (this.verticalSpacing === undefined) {\r\n\t\t\tthis.verticalSpacing = measureVerticalSpacing.call(this)\r\n\t\t\treturn this.verticalSpacing\r\n\t\t}\r\n\t}\r\n\r\n\tfunction measureVerticalSpacing() {\r\n\t\tconst {\r\n\t\t\tfirstShownItemIndex,\r\n\t\t\tlastShownItemIndex\r\n\t\t} = this.getState()\r\n\r\n\t\tlog('~ Measure item vertical spacing ~')\r\n\r\n\t\tconst verticalSpacing = getVerticalSpacing({\r\n\t\t\titemsContainer: this.itemsContainer,\r\n\t\t\trenderedItemsCount: lastShownItemIndex - firstShownItemIndex + 1\r\n\t\t})\r\n\r\n\t\tif (verticalSpacing === undefined) {\r\n\t\t\tlog('Not enough items rendered to measure vertical spacing')\r\n\t\t} else {\r\n\t\t\tlog('Item vertical spacing', verticalSpacing)\r\n\t\t\treturn verticalSpacing\r\n\t\t}\r\n\t}\r\n}"],"mappings":"AAAA,OAAOA,GAAP,MAAgB,oBAAhB;AACA,OAAOC,kBAAP,MAA+B,yBAA/B;AAEA,eAAe,SAASC,4BAAT,GAAwC;EAAA;;EACtD;EACA;EACA;EACA,KAAKD,kBAAL,GAA0B,YAAM;IAC/B,OAAO,KAAI,CAACE,eAAL,IAAwB,CAA/B;EACA,CAFD;;EAIA,KAAKC,8BAAL,GAAsC,YAAM;IAC3C;IACA;IACA;IACA,qBAAyB,KAAI,CAACC,QAAL,EAAzB;IAAA,IAAQC,YAAR,kBAAQA,YAAR;;IACA,OAAOA,YAAY,IAAIA,YAAY,CAACH,eAA7B,IAAgD,CAAvD;EACA,CAND;EAQA;AACD;AACA;AACA;;;EACC,KAAKI,mCAAL,GAA2C,YAAM;IAChD,IAAI,KAAI,CAACJ,eAAL,KAAyBK,SAA7B,EAAwC;MACvC,KAAI,CAACL,eAAL,GAAuBM,sBAAsB,CAACC,IAAvB,CAA4B,KAA5B,CAAvB;MACA,OAAO,KAAI,CAACP,eAAZ;IACA;EACD,CALD;;EAOA,SAASM,sBAAT,GAAkC;IACjC,sBAGI,KAAKJ,QAAL,EAHJ;IAAA,IACCM,mBADD,mBACCA,mBADD;IAAA,IAECC,kBAFD,mBAECA,kBAFD;;IAKAZ,GAAG,CAAC,mCAAD,CAAH;IAEA,IAAMG,eAAe,GAAGF,kBAAkB,CAAC;MAC1CY,cAAc,EAAE,KAAKA,cADqB;MAE1CC,kBAAkB,EAAEF,kBAAkB,GAAGD,mBAArB,GAA2C;IAFrB,CAAD,CAA1C;;IAKA,IAAIR,eAAe,KAAKK,SAAxB,EAAmC;MAClCR,GAAG,CAAC,uDAAD,CAAH;IACA,CAFD,MAEO;MACNA,GAAG,CAAC,uBAAD,EAA0BG,eAA1B,CAAH;MACA,OAAOA,eAAP;IACA;EACD;AACD"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../source/getItemCoordinates.js"],"names":["getItemCoordinates","i","itemHeights","columnsCount","verticalSpacing","listTopOffsetInsideScrollableContainer","rowTop","itemRowIndex","Math","floor","rowIndex","rowHeight","columnIndex","itemHeight","undefined","max","top","bottom","height"],"mappings":"AAAA;;AAEA;;;;;;;;AAQA,eAAe,SAASA,kBAAT,CAA4BC,CAA5B,QAKZ;AAAA,MAJFC,WAIE,QAJFA,WAIE;AAAA,MAHFC,YAGE,QAHFA,YAGE;AAAA,MAFFC,eAEE,QAFFA,eAEE;AAAA,MADFC,sCACE,QADFA,sCACE;AACF,MAAIC,MAAM,GAAGD,sCAAb;AACA,MAAME,YAAY,GAAGC,IAAI,CAACC,KAAL,CAAWR,CAAC,GAAGE,YAAf,CAArB;AACA,MAAIO,QAAQ,GAAG,CAAf;;AACA,SAAOA,QAAQ,GAAGH,YAAlB,EAAgC;AAC/B,QAAII,SAAS,GAAG,CAAhB;AACA,QAAIC,WAAW,GAAG,CAAlB;;AACA,WAAOA,WAAW,GAAGT,YAArB,EAAmC;AAClC,UAAMU,UAAU,GAAGX,WAAW,CAACQ,QAAQ,GAAGP,YAAX,GAA0BS,WAA3B,CAA9B;;AACA,UAAIC,UAAU,KAAKC,SAAnB,EAA8B;AAC7B;AACA;;AACDH,MAAAA,SAAS,GAAGH,IAAI,CAACO,GAAL,CAASJ,SAAT,EAAoBE,UAApB,CAAZ;AACAD,MAAAA,WAAW;AACX;;AACDN,IAAAA,MAAM,IAAIK,SAAV;AACAL,IAAAA,MAAM,IAAIF,eAAV;AACAM,IAAAA,QAAQ;AACR;;AACD,SAAO;AACNM,IAAAA,GAAG,EAAEV,MADC;AAENW,IAAAA,MAAM,EAAEX,MAAM,GAAGJ,WAAW,CAACD,CAAD,CAFtB;AAGNiB,IAAAA,MAAM,EAAEhB,WAAW,CAACD,CAAD;AAHb,GAAP;AAKA","sourcesContent":["// This function isn't currenly used.\r\n\r\n/**\r\n * Returns coordinates of item with index `i` relative to the document.\r\n * `top` is the top offset of the item relative to the start of the document.\r\n * `bottom` is the top offset of the item's bottom edge relative to the start of the document.\r\n * `height` is the item's height.\r\n * @param {number} i\r\n * @return {object} [coordinates] — An object of shape `{ top, bottom, height }`. Returns `undefined` if some of the items along the way haven't been measured.\r\n */\r\nexport default function getItemCoordinates(i, {\r\n\titemHeights,\r\n\tcolumnsCount,\r\n\tverticalSpacing,\r\n\tlistTopOffsetInsideScrollableContainer\r\n}) {\r\n\tlet rowTop = listTopOffsetInsideScrollableContainer\r\n\tconst itemRowIndex = Math.floor(i / columnsCount)\r\n\tlet rowIndex = 0\r\n\twhile (rowIndex < itemRowIndex) {\r\n\t\tlet rowHeight = 0\r\n\t\tlet columnIndex = 0\r\n\t\twhile (columnIndex < columnsCount) {\r\n\t\t\tconst itemHeight = itemHeights[rowIndex * columnsCount + columnIndex]\r\n\t\t\tif (itemHeight === undefined) {\r\n\t\t\t\treturn\r\n\t\t\t}\r\n\t\t\trowHeight = Math.max(rowHeight, itemHeight)\r\n\t\t\tcolumnIndex++\r\n\t\t}\r\n\t\trowTop += rowHeight\r\n\t\trowTop += verticalSpacing\r\n\t\trowIndex++\r\n\t}\r\n\treturn {\r\n\t\ttop: rowTop,\r\n\t\tbottom: rowTop + itemHeights[i],\r\n\t\theight: itemHeights[i]\r\n\t}\r\n}"],"file":"getItemCoordinates.js"}
1
+ {"version":3,"file":"getItemCoordinates.js","names":["getItemCoordinates","i","itemHeights","columnsCount","verticalSpacing","listTopOffsetInsideScrollableContainer","rowTop","itemRowIndex","Math","floor","rowIndex","rowHeight","columnIndex","itemHeight","undefined","max","top","bottom","height"],"sources":["../source/getItemCoordinates.js"],"sourcesContent":["// This function isn't currenly used.\r\n\r\n/**\r\n * Returns coordinates of item with index `i` relative to the document.\r\n * `top` is the top offset of the item relative to the start of the document.\r\n * `bottom` is the top offset of the item's bottom edge relative to the start of the document.\r\n * `height` is the item's height.\r\n * @param {number} i\r\n * @return {object} [coordinates] — An object of shape `{ top, bottom, height }`. Returns `undefined` if some of the items along the way haven't been measured.\r\n */\r\nexport default function getItemCoordinates(i, {\r\n\titemHeights,\r\n\tcolumnsCount,\r\n\tverticalSpacing,\r\n\tlistTopOffsetInsideScrollableContainer\r\n}) {\r\n\tlet rowTop = listTopOffsetInsideScrollableContainer\r\n\tconst itemRowIndex = Math.floor(i / columnsCount)\r\n\tlet rowIndex = 0\r\n\twhile (rowIndex < itemRowIndex) {\r\n\t\tlet rowHeight = 0\r\n\t\tlet columnIndex = 0\r\n\t\twhile (columnIndex < columnsCount) {\r\n\t\t\tconst itemHeight = itemHeights[rowIndex * columnsCount + columnIndex]\r\n\t\t\tif (itemHeight === undefined) {\r\n\t\t\t\treturn\r\n\t\t\t}\r\n\t\t\trowHeight = Math.max(rowHeight, itemHeight)\r\n\t\t\tcolumnIndex++\r\n\t\t}\r\n\t\trowTop += rowHeight\r\n\t\trowTop += verticalSpacing\r\n\t\trowIndex++\r\n\t}\r\n\treturn {\r\n\t\ttop: rowTop,\r\n\t\tbottom: rowTop + itemHeights[i],\r\n\t\theight: itemHeights[i]\r\n\t}\r\n}"],"mappings":"AAAA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,eAAe,SAASA,kBAAT,CAA4BC,CAA5B,QAKZ;EAAA,IAJFC,WAIE,QAJFA,WAIE;EAAA,IAHFC,YAGE,QAHFA,YAGE;EAAA,IAFFC,eAEE,QAFFA,eAEE;EAAA,IADFC,sCACE,QADFA,sCACE;EACF,IAAIC,MAAM,GAAGD,sCAAb;EACA,IAAME,YAAY,GAAGC,IAAI,CAACC,KAAL,CAAWR,CAAC,GAAGE,YAAf,CAArB;EACA,IAAIO,QAAQ,GAAG,CAAf;;EACA,OAAOA,QAAQ,GAAGH,YAAlB,EAAgC;IAC/B,IAAII,SAAS,GAAG,CAAhB;IACA,IAAIC,WAAW,GAAG,CAAlB;;IACA,OAAOA,WAAW,GAAGT,YAArB,EAAmC;MAClC,IAAMU,UAAU,GAAGX,WAAW,CAACQ,QAAQ,GAAGP,YAAX,GAA0BS,WAA3B,CAA9B;;MACA,IAAIC,UAAU,KAAKC,SAAnB,EAA8B;QAC7B;MACA;;MACDH,SAAS,GAAGH,IAAI,CAACO,GAAL,CAASJ,SAAT,EAAoBE,UAApB,CAAZ;MACAD,WAAW;IACX;;IACDN,MAAM,IAAIK,SAAV;IACAL,MAAM,IAAIF,eAAV;IACAM,QAAQ;EACR;;EACD,OAAO;IACNM,GAAG,EAAEV,MADC;IAENW,MAAM,EAAEX,MAAM,GAAGJ,WAAW,CAACD,CAAD,CAFtB;IAGNiB,MAAM,EAAEhB,WAAW,CAACD,CAAD;EAHb,CAAP;AAKA"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../source/getItemsDiff.js"],"names":["getItemsDiff","previousItems","newItems","isEqual","firstPreviousItemIndex","lastPreviousItemIndex","length","findInArray","arePreviousItemsPreserved","isIncrementalUpdate","prependedItemsCount","appendedItemsCount","offset","i","array","element"],"mappings":"AAAA;;;;;;AAMA,eAAe,SAASA,YAAT,CAAsBC,aAAtB,EAAqCC,QAArC,EAA+C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AA8C;AAC7C,MAAIU,CAAC,GAAG,CAAR;;AACA,SAAOA,CAAC,GAAGC,KAAK,CAACR,MAAjB,EAAyB;AACxB,QAAIH,OAAO,CAACW,KAAK,CAACD,CAAD,CAAN,EAAWE,OAAX,CAAX,EAAgC;AAC/B,aAAOF,CAAP;AACA;;AACDA,IAAAA,CAAC;AACD;;AACD,SAAO,CAAC,CAAR;AACA","sourcesContent":["/**\r\n * Checks whether it's an \"incremental\" items update, and returns the \"diff\".\r\n * @param {any[]} previousItems\r\n * @param {any[]} newItems\r\n * @return {object} [diff]\r\n */\r\nexport default function getItemsDiff(previousItems, newItems, isEqual) {\r\n\tlet firstPreviousItemIndex = -1\r\n\tlet lastPreviousItemIndex = -1\r\n\tif (previousItems.length > 0) {\r\n\t\tfirstPreviousItemIndex = findInArray(newItems, previousItems[0], isEqual)\r\n\t\tif (firstPreviousItemIndex >= 0) {\r\n\t\t\tif (arePreviousItemsPreserved(previousItems, newItems, firstPreviousItemIndex, isEqual)) {\r\n\t\t\t\tlastPreviousItemIndex = firstPreviousItemIndex + previousItems.length - 1\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\tconst isIncrementalUpdate = firstPreviousItemIndex >= 0 && lastPreviousItemIndex >= 0\r\n\tif (isIncrementalUpdate) {\r\n\t\treturn {\r\n\t\t\tprependedItemsCount: firstPreviousItemIndex,\r\n\t\t\tappendedItemsCount: newItems.length - (lastPreviousItemIndex + 1)\r\n\t\t}\r\n\t}\r\n}\r\n\r\nfunction arePreviousItemsPreserved(previousItems, newItems, offset, isEqual) {\r\n\t// Check each item of the `previousItems` to determine\r\n\t// whether it's an \"incremental\" items update.\r\n\t// (an update when items are prepended or appended)\r\n\tlet i = 0\r\n\twhile (i < previousItems.length) {\r\n\t\tif (newItems.length <= offset + i ||\r\n\t\t\t!isEqual(newItems[offset + i], previousItems[i])) {\r\n\t\t\treturn false\r\n\t\t}\r\n\t\ti++\r\n\t}\r\n\treturn true\r\n}\r\n\r\nfunction findInArray(array, element, isEqual) {\r\n\tlet i = 0\r\n\twhile (i < array.length) {\r\n\t\tif (isEqual(array[i], element)) {\r\n\t\t\treturn i\r\n\t\t}\r\n\t\ti++\r\n\t}\r\n\treturn -1\r\n}"],"file":"getItemsDiff.js"}
1
+ {"version":3,"file":"getItemsDiff.js","names":["getItemsDiff","previousItems","newItems","isEqual","firstPreviousItemIndex","lastPreviousItemIndex","length","findInArray","arePreviousItemsPreserved","isIncrementalUpdate","prependedItemsCount","appendedItemsCount","offset","i","array","element"],"sources":["../source/getItemsDiff.js"],"sourcesContent":["/**\r\n * Checks whether it's an \"incremental\" items update, and returns the \"diff\".\r\n * @param {any[]} previousItems\r\n * @param {any[]} newItems\r\n * @return {object} [diff]\r\n */\r\nexport default function getItemsDiff(previousItems, newItems, isEqual) {\r\n\tlet firstPreviousItemIndex = -1\r\n\tlet lastPreviousItemIndex = -1\r\n\tif (previousItems.length > 0) {\r\n\t\tfirstPreviousItemIndex = findInArray(newItems, previousItems[0], isEqual)\r\n\t\tif (firstPreviousItemIndex >= 0) {\r\n\t\t\tif (arePreviousItemsPreserved(previousItems, newItems, firstPreviousItemIndex, isEqual)) {\r\n\t\t\t\tlastPreviousItemIndex = firstPreviousItemIndex + previousItems.length - 1\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\tconst isIncrementalUpdate = firstPreviousItemIndex >= 0 && lastPreviousItemIndex >= 0\r\n\tif (isIncrementalUpdate) {\r\n\t\treturn {\r\n\t\t\tprependedItemsCount: firstPreviousItemIndex,\r\n\t\t\tappendedItemsCount: newItems.length - (lastPreviousItemIndex + 1)\r\n\t\t}\r\n\t}\r\n}\r\n\r\nfunction arePreviousItemsPreserved(previousItems, newItems, offset, isEqual) {\r\n\t// Check each item of the `previousItems` to determine\r\n\t// whether it's an \"incremental\" items update.\r\n\t// (an update when items are prepended or appended)\r\n\tlet i = 0\r\n\twhile (i < previousItems.length) {\r\n\t\tif (newItems.length <= offset + i ||\r\n\t\t\t!isEqual(newItems[offset + i], previousItems[i])) {\r\n\t\t\treturn false\r\n\t\t}\r\n\t\ti++\r\n\t}\r\n\treturn true\r\n}\r\n\r\nfunction findInArray(array, element, isEqual) {\r\n\tlet i = 0\r\n\twhile (i < array.length) {\r\n\t\tif (isEqual(array[i], element)) {\r\n\t\t\treturn i\r\n\t\t}\r\n\t\ti++\r\n\t}\r\n\treturn -1\r\n}"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA,eAAe,SAASA,YAAT,CAAsBC,aAAtB,EAAqCC,QAArC,EAA+CC,OAA/C,EAAwD;EACtE,IAAIC,sBAAsB,GAAG,CAAC,CAA9B;EACA,IAAIC,qBAAqB,GAAG,CAAC,CAA7B;;EACA,IAAIJ,aAAa,CAACK,MAAd,GAAuB,CAA3B,EAA8B;IAC7BF,sBAAsB,GAAGG,WAAW,CAACL,QAAD,EAAWD,aAAa,CAAC,CAAD,CAAxB,EAA6BE,OAA7B,CAApC;;IACA,IAAIC,sBAAsB,IAAI,CAA9B,EAAiC;MAChC,IAAII,yBAAyB,CAACP,aAAD,EAAgBC,QAAhB,EAA0BE,sBAA1B,EAAkDD,OAAlD,CAA7B,EAAyF;QACxFE,qBAAqB,GAAGD,sBAAsB,GAAGH,aAAa,CAACK,MAAvC,GAAgD,CAAxE;MACA;IACD;EACD;;EACD,IAAMG,mBAAmB,GAAGL,sBAAsB,IAAI,CAA1B,IAA+BC,qBAAqB,IAAI,CAApF;;EACA,IAAII,mBAAJ,EAAyB;IACxB,OAAO;MACNC,mBAAmB,EAAEN,sBADf;MAENO,kBAAkB,EAAET,QAAQ,CAACI,MAAT,IAAmBD,qBAAqB,GAAG,CAA3C;IAFd,CAAP;EAIA;AACD;;AAED,SAASG,yBAAT,CAAmCP,aAAnC,EAAkDC,QAAlD,EAA4DU,MAA5D,EAAoET,OAApE,EAA6E;EAC5E;EACA;EACA;EACA,IAAIU,CAAC,GAAG,CAAR;;EACA,OAAOA,CAAC,GAAGZ,aAAa,CAACK,MAAzB,EAAiC;IAChC,IAAIJ,QAAQ,CAACI,MAAT,IAAmBM,MAAM,GAAGC,CAA5B,IACH,CAACV,OAAO,CAACD,QAAQ,CAACU,MAAM,GAAGC,CAAV,CAAT,EAAuBZ,aAAa,CAACY,CAAD,CAApC,CADT,EACmD;MAClD,OAAO,KAAP;IACA;;IACDA,CAAC;EACD;;EACD,OAAO,IAAP;AACA;;AAED,SAASN,WAAT,CAAqBO,KAArB,EAA4BC,OAA5B,EAAqCZ,OAArC,EAA8C;EAC7C,IAAIU,CAAC,GAAG,CAAR;;EACA,OAAOA,CAAC,GAAGC,KAAK,CAACR,MAAjB,EAAyB;IACxB,IAAIH,OAAO,CAACW,KAAK,CAACD,CAAD,CAAN,EAAWE,OAAX,CAAX,EAAgC;MAC/B,OAAOF,CAAP;IACA;;IACDA,CAAC;EACD;;EACD,OAAO,CAAC,CAAR;AACA"}
@@ -1,15 +1,15 @@
1
1
  export default function getVerticalSpacing(_ref) {
2
- var container = _ref.container,
3
- screen = _ref.screen;
2
+ var itemsContainer = _ref.itemsContainer,
3
+ renderedItemsCount = _ref.renderedItemsCount;
4
4
 
5
- if (screen.getChildElementsCount(container) > 1) {
6
- var firstShownRowTopOffset = screen.getChildElementTopOffset(container, 0);
7
- var firstShownRowHeight = screen.getChildElementHeight(container, 0);
5
+ if (renderedItemsCount > 1) {
6
+ var firstShownRowTopOffset = itemsContainer.getNthRenderedItemTopOffset(0);
7
+ var firstShownRowHeight = itemsContainer.getNthRenderedItemHeight(0);
8
8
  var i = 1;
9
9
 
10
- while (i < screen.getChildElementsCount(container)) {
11
- var itemTopOffset = screen.getChildElementTopOffset(container, i);
12
- var itemHeight = screen.getChildElementHeight(container, i); // If next row is detected.
10
+ while (i < renderedItemsCount) {
11
+ var itemTopOffset = itemsContainer.getNthRenderedItemTopOffset(i);
12
+ var itemHeight = itemsContainer.getNthRenderedItemHeight(i); // If next row is detected.
13
13
 
14
14
  if (itemTopOffset !== firstShownRowTopOffset) {
15
15
  // Measure inter-row spacing.
@@ -1 +1 @@
1
- {"version":3,"sources":["../source/getVerticalSpacing.js"],"names":["getVerticalSpacing","container","screen","getChildElementsCount","firstShownRowTopOffset","getChildElementTopOffset","firstShownRowHeight","getChildElementHeight","i","itemTopOffset","itemHeight","Math","max"],"mappings":"AAAA,eAAe,SAASA,kBAAT,OAAmD;AAAA,MAArBC,SAAqB,QAArBA,SAAqB;AAAA,MAAVC,MAAU,QAAVA,MAAU;;AACjE,MAAIA,MAAM,CAACC,qBAAP,CAA6BF,SAA7B,IAA0C,CAA9C,EAAiD;AAChD,QAAMG,sBAAsB,GAAGF,MAAM,CAACG,wBAAP,CAAgCJ,SAAhC,EAA2C,CAA3C,CAA/B;AACA,QAAIK,mBAAmB,GAAGJ,MAAM,CAACK,qBAAP,CAA6BN,SAA7B,EAAwC,CAAxC,CAA1B;AACA,QAAIO,CAAC,GAAG,CAAR;;AACA,WAAOA,CAAC,GAAGN,MAAM,CAACC,qBAAP,CAA6BF,SAA7B,CAAX,EAAoD;AACnD,UAAMQ,aAAa,GAAGP,MAAM,CAACG,wBAAP,CAAgCJ,SAAhC,EAA2CO,CAA3C,CAAtB;AACA,UAAME,UAAU,GAAGR,MAAM,CAACK,qBAAP,CAA6BN,SAA7B,EAAwCO,CAAxC,CAAnB,CAFmD,CAGnD;;AACA,UAAIC,aAAa,KAAKL,sBAAtB,EAA8C;AAC7C;AACA,eAAOK,aAAa,IAAIL,sBAAsB,GAAGE,mBAA7B,CAApB;AACA,OAPkD,CAQnD;;;AACAA,MAAAA,mBAAmB,GAAGK,IAAI,CAACC,GAAL,CAASN,mBAAT,EAA8BI,UAA9B,CAAtB;AACAF,MAAAA,CAAC;AACD;AACD;AACD","sourcesContent":["export default function getVerticalSpacing({ container, screen }) {\r\n\tif (screen.getChildElementsCount(container) > 1) {\r\n\t\tconst firstShownRowTopOffset = screen.getChildElementTopOffset(container, 0)\r\n\t\tlet firstShownRowHeight = screen.getChildElementHeight(container, 0)\r\n\t\tlet i = 1\r\n\t\twhile (i < screen.getChildElementsCount(container)) {\r\n\t\t\tconst itemTopOffset = screen.getChildElementTopOffset(container, i)\r\n\t\t\tconst itemHeight = screen.getChildElementHeight(container, i)\r\n\t\t\t// If next row is detected.\r\n\t\t\tif (itemTopOffset !== firstShownRowTopOffset) {\r\n\t\t\t\t// Measure inter-row spacing.\r\n\t\t\t\treturn itemTopOffset - (firstShownRowTopOffset + firstShownRowHeight)\r\n\t\t\t}\r\n\t\t\t// A row height is the maximum of its item heights.\r\n\t\t\tfirstShownRowHeight = Math.max(firstShownRowHeight, itemHeight)\r\n\t\t\ti++\r\n\t\t}\r\n\t}\r\n}"],"file":"getVerticalSpacing.js"}
1
+ {"version":3,"file":"getVerticalSpacing.js","names":["getVerticalSpacing","itemsContainer","renderedItemsCount","firstShownRowTopOffset","getNthRenderedItemTopOffset","firstShownRowHeight","getNthRenderedItemHeight","i","itemTopOffset","itemHeight","Math","max"],"sources":["../source/getVerticalSpacing.js"],"sourcesContent":["export default function getVerticalSpacing({ itemsContainer, renderedItemsCount }) {\r\n\tif (renderedItemsCount > 1) {\r\n\t\tconst firstShownRowTopOffset = itemsContainer.getNthRenderedItemTopOffset(0)\r\n\t\tlet firstShownRowHeight = itemsContainer.getNthRenderedItemHeight(0)\r\n\t\tlet i = 1\r\n\t\twhile (i < renderedItemsCount) {\r\n\t\t\tconst itemTopOffset = itemsContainer.getNthRenderedItemTopOffset(i)\r\n\t\t\tconst itemHeight = itemsContainer.getNthRenderedItemHeight(i)\r\n\t\t\t// If next row is detected.\r\n\t\t\tif (itemTopOffset !== firstShownRowTopOffset) {\r\n\t\t\t\t// Measure inter-row spacing.\r\n\t\t\t\treturn itemTopOffset - (firstShownRowTopOffset + firstShownRowHeight)\r\n\t\t\t}\r\n\t\t\t// A row height is the maximum of its item heights.\r\n\t\t\tfirstShownRowHeight = Math.max(firstShownRowHeight, itemHeight)\r\n\t\t\ti++\r\n\t\t}\r\n\t}\r\n}"],"mappings":"AAAA,eAAe,SAASA,kBAAT,OAAoE;EAAA,IAAtCC,cAAsC,QAAtCA,cAAsC;EAAA,IAAtBC,kBAAsB,QAAtBA,kBAAsB;;EAClF,IAAIA,kBAAkB,GAAG,CAAzB,EAA4B;IAC3B,IAAMC,sBAAsB,GAAGF,cAAc,CAACG,2BAAf,CAA2C,CAA3C,CAA/B;IACA,IAAIC,mBAAmB,GAAGJ,cAAc,CAACK,wBAAf,CAAwC,CAAxC,CAA1B;IACA,IAAIC,CAAC,GAAG,CAAR;;IACA,OAAOA,CAAC,GAAGL,kBAAX,EAA+B;MAC9B,IAAMM,aAAa,GAAGP,cAAc,CAACG,2BAAf,CAA2CG,CAA3C,CAAtB;MACA,IAAME,UAAU,GAAGR,cAAc,CAACK,wBAAf,CAAwCC,CAAxC,CAAnB,CAF8B,CAG9B;;MACA,IAAIC,aAAa,KAAKL,sBAAtB,EAA8C;QAC7C;QACA,OAAOK,aAAa,IAAIL,sBAAsB,GAAGE,mBAA7B,CAApB;MACA,CAP6B,CAQ9B;;;MACAA,mBAAmB,GAAGK,IAAI,CAACC,GAAL,CAASN,mBAAT,EAA8BI,UAA9B,CAAtB;MACAF,CAAC;IACD;EACD;AACD"}