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,301 @@
1
+ "use strict";
2
+
3
+ function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
4
+
5
+ Object.defineProperty(exports, "__esModule", {
6
+ value: true
7
+ });
8
+ exports["default"] = createStateHelpers;
9
+
10
+ var _debug = _interopRequireWildcard(require("./utility/debug.js"));
11
+
12
+ var _BeforeResize = require("./BeforeResize.js");
13
+
14
+ var _getStateSnapshot = _interopRequireDefault(require("./utility/getStateSnapshot.js"));
15
+
16
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
17
+
18
+ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
19
+
20
+ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
21
+
22
+ 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; }
23
+
24
+ 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; }
25
+
26
+ 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; }
27
+
28
+ // There're three main places where state is updated:
29
+ //
30
+ // * On scroll.
31
+ // * On window resize.
32
+ // * On set new items.
33
+ //
34
+ // State updates may be "asynchronous" (like in React), in which case the
35
+ // corresponding operation is "pending" until the state update is applied.
36
+ //
37
+ // If there's a "pending" window resize or a "pending" update of the set of items,
38
+ // then "on scroll" updates aren't dispatched.
39
+ //
40
+ // If there's a "pending" on scroll update and the window is resize or a new set
41
+ // of items is set, then that "pending" on scroll update gets overwritten.
42
+ //
43
+ // If there's a "pending" update of the set of items, then window resize handler
44
+ // sees that "pending" update and dispatches its own state update so that the
45
+ // "pending" state update originating from `setItems()` is not lost.
46
+ //
47
+ // If there's a "pending" window resize, and a new set of items is set,
48
+ // then the state update of the window resize handler gets overwritten.
49
+ function createStateHelpers(_ref) {
50
+ var _this = this;
51
+
52
+ var state = _ref.state,
53
+ onStateChange = _ref.onStateChange,
54
+ render = _ref.render,
55
+ initialItems = _ref.items;
56
+ this.onStateChange = onStateChange;
57
+ this._render = render;
58
+
59
+ this._onItemStateChange = function (i, newItemState) {
60
+ if ((0, _debug.isDebug)()) {
61
+ (0, _debug["default"])('~ Item state changed ~');
62
+ (0, _debug["default"])('Item', i); // Uses `JSON.stringify()` here instead of just outputting the JSON objects as is
63
+ // because outputting JSON objects as is would show different results later when
64
+ // the developer inspects those in the web browser console if those state objects
65
+ // get modified in between they've been output to the console and the developer
66
+ // decided to inspect them.
67
+
68
+ (0, _debug["default"])('Previous state' + '\n' + JSON.stringify(_this.getState().itemStates[i], null, 2));
69
+ (0, _debug["default"])('New state' + '\n' + JSON.stringify(newItemState, null, 2));
70
+ }
71
+
72
+ _this.getState().itemStates[i] = newItemState; // Schedule the item state update for after the new items have been rendered.
73
+
74
+ if (_this.newItemsWillBeRendered) {
75
+ if (!_this.itemStatesThatChangedWhileNewItemsWereBeingRendered) {
76
+ _this.itemStatesThatChangedWhileNewItemsWereBeingRendered = {};
77
+ }
78
+
79
+ _this.itemStatesThatChangedWhileNewItemsWereBeingRendered[String(i)] = newItemState;
80
+ }
81
+ };
82
+
83
+ this.getState = function () {
84
+ return _this._getState();
85
+ };
86
+
87
+ this.updateState = function (stateUpdate) {
88
+ if ((0, _debug.isDebug)()) {
89
+ (0, _debug["default"])('~ Set state ~');
90
+ (0, _debug["default"])((0, _getStateSnapshot["default"])(stateUpdate));
91
+ } // Ensure that a non-initial `stateUpdate` can only contain an `items`
92
+ // property when it comes from a `setItems()` call.
93
+
94
+
95
+ if (stateUpdate.items) {
96
+ if (!_this._isSettingNewItems) {
97
+ (0, _debug.reportError)('A `stateUpdate` can only contain `items` property as a result of calling `.setItems()`');
98
+ }
99
+ }
100
+
101
+ _this._isSettingNewItems = undefined; // Update `state`.
102
+
103
+ _this.previousState = _this.getState();
104
+
105
+ _this._updateState(stateUpdate);
106
+ };
107
+
108
+ this.getInitialState = function () {
109
+ if (state) {
110
+ return getRestoredState.call(_this, state);
111
+ }
112
+
113
+ return getInitialStateFromScratch.call(_this);
114
+ };
115
+
116
+ this.useState = function (_ref2) {
117
+ var getState = _ref2.getState,
118
+ updateState = _ref2.updateState;
119
+
120
+ if (_this._isActive) {
121
+ throw new Error('[virtual-scroller] `VirtualScroller` has already been started');
122
+ }
123
+
124
+ if (_this._getState) {
125
+ throw new Error('[virtual-scroller] Custom state storage has already been configured');
126
+ }
127
+
128
+ if (render) {
129
+ throw new Error('[virtual-scroller] Creating a `VirtualScroller` class instance with a `render()` parameter means using the default (internal) state storage');
130
+ }
131
+
132
+ if (!getState || !updateState) {
133
+ throw new Error('[virtual-scroller] When using a custom state storage, one must supply both `getState()` and `updateState()` functions');
134
+ }
135
+
136
+ _this._usesCustomStateStorage = true;
137
+ _this._getState = getState;
138
+ _this._updateState = updateState;
139
+ };
140
+
141
+ this.useDefaultStateStorage = function () {
142
+ if (!render) {
143
+ throw new Error('[virtual-scroller] When using the default (internal) state management, one must supply a `render(state, prevState)` function parameter');
144
+ } // Create default `getState()`/`updateState()` functions.
145
+
146
+
147
+ _this._getState = defaultGetState.bind(_this);
148
+ _this._updateState = defaultUpdateState.bind(_this); // When `state` is stored externally, a developer is responsible for
149
+ // initializing it with the initial value.
150
+ // Otherwise, if default state management is used, set the initial state now.
151
+
152
+ var setInitialState = defaultSetInitialState.bind(_this);
153
+ setInitialState(_this.getInitialState());
154
+ };
155
+
156
+ function defaultGetState() {
157
+ return this.state;
158
+ }
159
+
160
+ function defaultSetInitialState(newState) {
161
+ this.state = newState;
162
+ }
163
+
164
+ function defaultUpdateState(stateUpdate) {
165
+ // Because this variant of `.updateState()` is "synchronous" (immediate),
166
+ // it can be written like `...prevState`, and no state updates would be lost.
167
+ // But if it was "asynchronous" (not immediate), then `...prevState`
168
+ // wouldn't work in all cases, because it could be stale in cases
169
+ // when more than a single `updateState()` call is made before
170
+ // the state actually updates, making `prevState` stale.
171
+ this.state = _objectSpread(_objectSpread({}, this.state), stateUpdate);
172
+ render(this.state, this.previousState);
173
+ this.onRender();
174
+ }
175
+ /**
176
+ * Returns the initial state of the `VirtualScroller` "from scratch".
177
+ * (i.e. not from a previously saved one).
178
+ * @return {object}
179
+ */
180
+
181
+
182
+ function getInitialStateFromScratch() {
183
+ var items = initialItems;
184
+
185
+ var state = _objectSpread(_objectSpread({}, getInitialLayoutState.call(this, items)), {}, {
186
+ items: items,
187
+ itemStates: new Array(items.length)
188
+ });
189
+
190
+ if ((0, _debug.isDebug)()) {
191
+ (0, _debug["default"])('Initial state (autogenerated)', (0, _getStateSnapshot["default"])(state));
192
+ }
193
+
194
+ (0, _debug["default"])('First shown item index', state.firstShownItemIndex);
195
+ (0, _debug["default"])('Last shown item index', state.lastShownItemIndex);
196
+ return state;
197
+ }
198
+
199
+ function getRestoredState(state) {
200
+ if ((0, _debug.isDebug)()) {
201
+ (0, _debug["default"])('Restore state', (0, _getStateSnapshot["default"])(state));
202
+ } // Possibly clean up "before resize" property in state.
203
+ // "Before resize" state property is cleaned up when all "before resize" item heights
204
+ // have been re-measured in an asynchronous `this.updateState({ beforeResize: undefined })` call.
205
+ // If `VirtualScroller` state was snapshotted externally before that `this.updateState()` call
206
+ // has been applied, then "before resize" property might have not been cleaned up properly.
207
+
208
+
209
+ state = (0, _BeforeResize.cleanUpBeforeResizeState)(state); // Reset `verticalSpacing` so that it re-measures it after the list
210
+ // has been rendered initially. The rationale is that a previously captured
211
+ // inter-item vertical spacing can't be "trusted" in a sense that the user
212
+ // might have resized the window after the previous `state` has been snapshotted.
213
+ // If the user has resized the window, then changing window width might have
214
+ // activated different CSS `@media()` "queries" resulting in a potentially different
215
+ // vertical spacing when the `VirtualScroller` is re-created with such previously
216
+ // snapshotted state.
217
+
218
+ state = _objectSpread(_objectSpread({}, state), {}, {
219
+ verticalSpacing: undefined
220
+ }); // `this.verticalSpacing` acts as a "true" source for vertical spacing value.
221
+ // Vertical spacing is also stored in `state` but `state` updates could be
222
+ // "asynchronous" (not applied immediately) and `this.onUpdateShownItemIndexes()`
223
+ // requires vertical spacing to be correct at any time, without any delays.
224
+ // So, vertical spacing is also duplicated in `state`, but the "true" source
225
+ // is still `this.verticalSpacing`.
226
+ //
227
+ // `this.verticalSpacing` must be initialized before calling `this.getInitialStateFromScratch()`
228
+ // because `this.getInitialStateFromScratch()` uses `this.verticalSpacing` in its calculations.
229
+ //
230
+ // With the code above, `state.verticalSpacing` is always gonna be `undefined`,
231
+ // so commented out this code. It's safer to just re-measure vertical spacing
232
+ // from scratch when `VirtualScroller` is mounted.
233
+ //
234
+ // this.verticalSpacing = state ? state.verticalSpacing : undefined
235
+ // Check if the actual `columnsCount` on the screen matches the one from state.
236
+
237
+ if (isStateColumnsCountMismatch(state, {
238
+ columnsCount: this.getActualColumnsCount()
239
+ })) {
240
+ (0, _debug.warn)('Reset Layout');
241
+ state = _objectSpread(_objectSpread({}, state), getInitialLayoutState.call(this, state.items));
242
+ }
243
+
244
+ return state;
245
+ }
246
+
247
+ function getInitialLayoutState(items) {
248
+ var itemsCount = items.length;
249
+
250
+ var _this$layout$getIniti = this.layout.getInitialLayoutValues({
251
+ itemsCount: itemsCount,
252
+ columnsCount: this.getActualColumnsCount()
253
+ }),
254
+ firstShownItemIndex = _this$layout$getIniti.firstShownItemIndex,
255
+ lastShownItemIndex = _this$layout$getIniti.lastShownItemIndex,
256
+ beforeItemsHeight = _this$layout$getIniti.beforeItemsHeight,
257
+ afterItemsHeight = _this$layout$getIniti.afterItemsHeight;
258
+
259
+ var itemHeights = new Array(itemsCount); // Optionally preload items to be rendered.
260
+
261
+ this.onBeforeShowItems(items, itemHeights, firstShownItemIndex, lastShownItemIndex);
262
+ return {
263
+ itemHeights: itemHeights,
264
+ columnsCount: this.getActualColumnsCountForState(),
265
+ verticalSpacing: this.verticalSpacing,
266
+ firstShownItemIndex: firstShownItemIndex,
267
+ lastShownItemIndex: lastShownItemIndex,
268
+ beforeItemsHeight: beforeItemsHeight,
269
+ afterItemsHeight: afterItemsHeight
270
+ };
271
+ } // Checks if the actual `columnsCount` on the screen matches the one from state.
272
+ //
273
+ // For example, a developer might snapshot `VirtualScroller` state
274
+ // when the user navigates from the page containing the list
275
+ // in order to later restore the list's state when the user goes "Back".
276
+ // But, the user might have also resized the window while being on that
277
+ // "other" page, and when they come "Back", their snapshotted state
278
+ // no longer qualifies. Well, it does qualify, but only partially.
279
+ // For example, `itemStates` are still valid, but first and last shown
280
+ // item indexes aren't.
281
+ //
282
+
283
+
284
+ function isStateColumnsCountMismatch(state, _ref3) {
285
+ var columnsCount = _ref3.columnsCount;
286
+ var stateColumnsCount = state.columnsCount || 1;
287
+
288
+ if (stateColumnsCount !== columnsCount) {
289
+ (0, _debug.warn)('~ Columns Count changed from', stateColumnsCount, 'to', columnsCount, '~');
290
+ return true;
291
+ }
292
+
293
+ var firstShownItemIndex = Math.floor(state.firstShownItemIndex / columnsCount) * columnsCount;
294
+
295
+ if (firstShownItemIndex !== state.firstShownItemIndex) {
296
+ (0, _debug.warn)('~ First Shown Item Index', state.firstShownItemIndex, 'is not divisible by Columns Count', columnsCount, '~');
297
+ return true;
298
+ }
299
+ }
300
+ }
301
+ //# sourceMappingURL=VirtualScroller.state.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"VirtualScroller.state.js","names":["createStateHelpers","state","onStateChange","render","initialItems","items","_render","_onItemStateChange","i","newItemState","isDebug","log","JSON","stringify","getState","itemStates","newItemsWillBeRendered","itemStatesThatChangedWhileNewItemsWereBeingRendered","String","_getState","updateState","stateUpdate","getStateSnapshot","_isSettingNewItems","reportError","undefined","previousState","_updateState","getInitialState","getRestoredState","call","getInitialStateFromScratch","useState","_isActive","Error","_usesCustomStateStorage","useDefaultStateStorage","defaultGetState","bind","defaultUpdateState","setInitialState","defaultSetInitialState","newState","onRender","getInitialLayoutState","Array","length","firstShownItemIndex","lastShownItemIndex","cleanUpBeforeResizeState","verticalSpacing","isStateColumnsCountMismatch","columnsCount","getActualColumnsCount","warn","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;;AACA;;AACA;;;;;;;;;;;;;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAEe,SAASA,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,IAAI,IAAAC,cAAA,GAAJ,EAAe;MACd,IAAAC,iBAAA,EAAI,wBAAJ;MACA,IAAAA,iBAAA,EAAI,MAAJ,EAAYH,CAAZ,EAFc,CAGd;MACA;MACA;MACA;MACA;;MACA,IAAAG,iBAAA,EAAI,mBAAmB,IAAnB,G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AsB,CAAhD;;IACA,IAAIW,iBAAiB,KAAKX,YAA1B,EAAwC;MACvC,IAAAE,WAAA,EAAK,8BAAL,EAAqCS,iBAArC,EAAwD,IAAxD,EAA8DX,YAA9D,EAA4E,GAA5E;MACA,OAAO,IAAP;IACA;;IACD,IAAML,mBAAmB,GAAGiB,IAAI,CAACC,KAAL,CAAWhE,KAAK,CAAC8C,mBAAN,GAA4BK,YAAvC,IAAuDA,YAAnF;;IACA,IAAIL,mBAAmB,KAAK9C,KAAK,CAAC8C,mBAAlC,EAAuD;MACtD,IAAAO,WAAA,EAAK,0BAAL,EAAiCrD,KAAK,CAAC8C,mBAAvC,EAA4D,mCAA5D,EAAiGK,YAAjG,EAA+G,GAA/G;MACA,OAAO,IAAP;IACA;EACD;AACD"}
@@ -0,0 +1,65 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports["default"] = createVerticalSpacingHelpers;
7
+
8
+ var _debug = _interopRequireDefault(require("./utility/debug.js"));
9
+
10
+ var _getVerticalSpacing = _interopRequireDefault(require("./getVerticalSpacing.js"));
11
+
12
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
13
+
14
+ function createVerticalSpacingHelpers() {
15
+ var _this = this;
16
+
17
+ // Bind to `this` in order to prevent bugs when this function is passed by reference
18
+ // and then called with its `this` being unintentionally `window` resulting in
19
+ // the `if` condition being "falsy".
20
+ this.getVerticalSpacing = function () {
21
+ return _this.verticalSpacing || 0;
22
+ };
23
+
24
+ this.getVerticalSpacingBeforeResize = function () {
25
+ // `beforeResize.verticalSpacing` can be `undefined`.
26
+ // For example, if `this.updateState({ verticalSpacing })` call hasn't been applied
27
+ // before the resize happened (in case of an "asynchronous" state update).
28
+ var _this$getState = _this.getState(),
29
+ beforeResize = _this$getState.beforeResize;
30
+
31
+ return beforeResize && beforeResize.verticalSpacing || 0;
32
+ };
33
+ /**
34
+ * Measures item vertical spacing, if not measured.
35
+ * @return {object} [stateUpdate]
36
+ */
37
+
38
+
39
+ this.measureVerticalSpacingIfNotMeasured = function () {
40
+ if (_this.verticalSpacing === undefined) {
41
+ _this.verticalSpacing = measureVerticalSpacing.call(_this);
42
+ return _this.verticalSpacing;
43
+ }
44
+ };
45
+
46
+ function measureVerticalSpacing() {
47
+ var _this$getState2 = this.getState(),
48
+ firstShownItemIndex = _this$getState2.firstShownItemIndex,
49
+ lastShownItemIndex = _this$getState2.lastShownItemIndex;
50
+
51
+ (0, _debug["default"])('~ Measure item vertical spacing ~');
52
+ var verticalSpacing = (0, _getVerticalSpacing["default"])({
53
+ itemsContainer: this.itemsContainer,
54
+ renderedItemsCount: lastShownItemIndex - firstShownItemIndex + 1
55
+ });
56
+
57
+ if (verticalSpacing === undefined) {
58
+ (0, _debug["default"])('Not enough items rendered to measure vertical spacing');
59
+ } else {
60
+ (0, _debug["default"])('Item vertical spacing', verticalSpacing);
61
+ return verticalSpacing;
62
+ }
63
+ }
64
+ }
65
+ //# sourceMappingURL=VirtualScroller.verticalSpacing.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"VirtualScroller.verticalSpacing.js","names":["createVerticalSpacingHelpers","getVerticalSpacing","verticalSpacing","getVerticalSpacingBeforeResize","getState","beforeResize","measureVerticalSpacingIfNotMeasured","undefined","measureVerticalSpacing","call","firstShownItemIndex","lastShownItemIndex","log","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;;AACA;;;;AAEe,SAASA,4BAAT,GAAwC;EAAA;;EACtD;EACA;EACA;EACA,KAAKC,kBAAL,GAA0B,YAAM;IAC/B,OAAO,KAAI,CAACC,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;;IAKA,IAAAC,iBAAA,EAAI,mCAAJ;IAEA,IAAMV,eAAe,GAAG,IAAAD,8BAAA,EAAmB;MAC1CY,cAAc,EAAE,KAAKA,cADqB;MAE1CC,kBAAkB,EAAEH,kBAAkB,GAAGD,mBAArB,GAA2C;IAFrB,CAAnB,CAAxB;;IAKA,IAAIR,eAAe,KAAKK,SAAxB,EAAmC;MAClC,IAAAK,iBAAA,EAAI,uDAAJ;IACA,CAFD,MAEO;MACN,IAAAA,iBAAA,EAAI,uBAAJ,EAA6BV,eAA7B;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;;;;;;;;AAQe,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;AACe,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;;;;;;AAMe,SAASA,YAAT,CAAsBC,aAAtB,EAAqCC,QAArC,EAA+CC,OAA/C,EAAwD;AACtE,MAAIC,sBAAsB,GAAG,CAAC,CAA9B;AACA,MAAIC,qBAAqB,GAAG,CAAC,CAA7B;;AACA,MAAIJ,aAAa,CAACK,MAAd,GAAuB,CAA3B,EAA8B;AAC7BF,IAAAA,sBAAsB,GAAGG,WAAW,CAACL,QAAD,EAAWD,aAAa,CAAC,CAAD,CAAxB,EAA6BE,OAA7B,CAApC;;AACA,QAAIC,sBAAsB,IAAI,CAA9B,EAAiC;AAChC,UAAII,yBAAyB,CAACP,aAAD,EAAgBC,QAAhB,EAA0BE,sBAA1B,EAAkDD,OAAlD,CAA7B,EAAyF;AACxFE,QAAAA,qBAAqB,GAAGD,sBAAsB,GAAGH,aAAa,CAACK,MAAvC,GAAgD,CAAxE;AACA;AACD;AACD;;AACD,MAAMG,mBAAmB,GAAGL,sBAAsB,IAAI,CAA1B,IAA+BC,qBAAqB,IAAI,CAApF;;AACA,MAAII,mBAAJ,EAAyB;AACxB,WAAO;AACNC,MAAAA,mBAAmB,EAAEN,sBADf;AAENO,MAAAA,kBAAkB,EAAET,QAAQ,CAACI,MAAT,IAAmBD,qBAAqB,GAAG,CAA3C;AAFd,KAAP;AAIA;AACD;;AAED,SAASG,yBAAT,CAAmCP,aAAnC,EAAkDC,QAAlD,EAA4DU,MAA5D,EAAoET,OAApE,EAA6E;AAC5E;AACA;AACA;AACA,MAAIU,CAAC,GAAG,CAAR;;AACA,SAAOA,CAAC,GAAGZ,aAAa,CAACK,MAAzB,EAAiC;AAChC,QAAIJ,QAAQ,CAACI,MAAT,IAAmBM,MAAM,GAAGC,CAA5B,IACH,CAACV,OAAO,CAACD,QAAQ,CAACU,MAAM,GAAGC,CAAV,CAAT,EAAuBZ,aAAa,CAACY,CAAD,CAApC,CADT,EACmD;AAClD,aAAO,KAAP;AACA;;AACDA,IAAAA,CAAC;AACD;;AACD,SAAO,IAAP;AACA;;AAED,SAASN,WAAT,CAAqBO,KAArB,EAA4BC,OAA5B,EAAqCZ,OAArC,EAA8C;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;AACe,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"}
@@ -6,17 +6,17 @@ Object.defineProperty(exports, "__esModule", {
6
6
  exports["default"] = getVerticalSpacing;
7
7
 
8
8
  function getVerticalSpacing(_ref) {
9
- var container = _ref.container,
10
- screen = _ref.screen;
9
+ var itemsContainer = _ref.itemsContainer,
10
+ renderedItemsCount = _ref.renderedItemsCount;
11
11
 
12
- if (screen.getChildElementsCount(container) > 1) {
13
- var firstShownRowTopOffset = screen.getChildElementTopOffset(container, 0);
14
- var firstShownRowHeight = screen.getChildElementHeight(container, 0);
12
+ if (renderedItemsCount > 1) {
13
+ var firstShownRowTopOffset = itemsContainer.getNthRenderedItemTopOffset(0);
14
+ var firstShownRowHeight = itemsContainer.getNthRenderedItemHeight(0);
15
15
  var i = 1;
16
16
 
17
- while (i < screen.getChildElementsCount(container)) {
18
- var itemTopOffset = screen.getChildElementTopOffset(container, i);
19
- var itemHeight = screen.getChildElementHeight(container, i); // If next row is detected.
17
+ while (i < renderedItemsCount) {
18
+ var itemTopOffset = itemsContainer.getNthRenderedItemTopOffset(i);
19
+ var itemHeight = itemsContainer.getNthRenderedItemHeight(i); // If next row is detected.
20
20
 
21
21
  if (itemTopOffset !== firstShownRowTopOffset) {
22
22
  // 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":";;;;;;;AAAe,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":";;;;;;;AAAe,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"}
@@ -0,0 +1,5 @@
1
+ {
2
+ "name": "virtual-scroller/commonjs",
3
+ "type": "commonjs",
4
+ "private": true
5
+ }