virtual-scroller 1.7.9 → 1.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.gitlab-ci.yml +1 -1
- package/CHANGELOG.md +71 -1
- package/README.md +434 -151
- package/bundle/index-bypass.html +1 -1
- package/bundle/index-dom.html +1 -1
- package/bundle/index-grid.html +1 -2
- package/bundle/index-scrollableContainer.html +1 -1
- package/bundle/index-tbody-scrollableContainer.html +2 -0
- package/bundle/index-tbody.html +2 -0
- package/bundle/virtual-scroller-dom.js +1 -1
- package/bundle/virtual-scroller-dom.js.map +1 -1
- package/bundle/virtual-scroller-react.js +1 -1
- package/bundle/virtual-scroller-react.js.map +1 -1
- package/bundle/virtual-scroller.js +1 -1
- package/bundle/virtual-scroller.js.map +1 -1
- package/commonjs/BeforeResize.js +315 -0
- package/commonjs/BeforeResize.js.map +1 -0
- package/commonjs/DOM/Engine.js +46 -0
- package/commonjs/DOM/Engine.js.map +1 -0
- package/commonjs/DOM/ItemsContainer.js +78 -0
- package/commonjs/DOM/ItemsContainer.js.map +1 -0
- package/commonjs/DOM/{WaitForStylesToLoad.js → ListTopOffsetWatcher.js} +71 -44
- package/commonjs/DOM/ListTopOffsetWatcher.js.map +1 -0
- package/commonjs/DOM/ScrollableContainer.js +69 -101
- package/commonjs/DOM/ScrollableContainer.js.map +1 -1
- package/commonjs/DOM/VirtualScroller.js +37 -29
- package/commonjs/DOM/VirtualScroller.js.map +1 -1
- package/commonjs/DOM/tbody.js +17 -11
- package/commonjs/DOM/tbody.js.map +1 -1
- package/commonjs/ItemHeights.js +33 -34
- package/commonjs/ItemHeights.js.map +1 -1
- package/commonjs/Layout.js +591 -216
- package/commonjs/Layout.js.map +1 -1
- package/commonjs/Layout.test.js +196 -0
- package/commonjs/Layout.test.js.map +1 -0
- package/commonjs/ListHeightMeasurement.js +124 -0
- package/commonjs/ListHeightMeasurement.js.map +1 -0
- package/commonjs/Resize.js +50 -39
- package/commonjs/Resize.js.map +1 -1
- package/commonjs/Scroll.js +139 -95
- package/commonjs/Scroll.js.map +1 -1
- package/commonjs/VirtualScroller.columns.js +43 -0
- package/commonjs/VirtualScroller.columns.js.map +1 -0
- package/commonjs/VirtualScroller.constructor.js +408 -0
- package/commonjs/VirtualScroller.constructor.js.map +1 -0
- package/commonjs/VirtualScroller.items.js +305 -0
- package/commonjs/VirtualScroller.items.js.map +1 -0
- package/commonjs/VirtualScroller.js +160 -1021
- package/commonjs/VirtualScroller.js.map +1 -1
- package/commonjs/VirtualScroller.layout.js +562 -0
- package/commonjs/VirtualScroller.layout.js.map +1 -0
- package/commonjs/VirtualScroller.onRender.js +357 -0
- package/commonjs/VirtualScroller.onRender.js.map +1 -0
- package/commonjs/VirtualScroller.resize.js +186 -0
- package/commonjs/VirtualScroller.resize.js.map +1 -0
- package/commonjs/VirtualScroller.state.js +301 -0
- package/commonjs/VirtualScroller.state.js.map +1 -0
- package/commonjs/VirtualScroller.verticalSpacing.js +65 -0
- package/commonjs/VirtualScroller.verticalSpacing.js.map +1 -0
- package/commonjs/getItemCoordinates.js.map +1 -1
- package/commonjs/getItemsDiff.js.map +1 -1
- package/commonjs/getVerticalSpacing.js +8 -8
- package/commonjs/getVerticalSpacing.js.map +1 -1
- package/commonjs/package.json +5 -0
- package/commonjs/react/VirtualScroller.js +182 -628
- package/commonjs/react/VirtualScroller.js.map +1 -1
- package/commonjs/react/useClassName.js +26 -0
- package/commonjs/react/useClassName.js.map +1 -0
- package/commonjs/react/useHandleItemsChange.js +116 -0
- package/commonjs/react/useHandleItemsChange.js.map +1 -0
- package/commonjs/react/useInstanceMethods.js +37 -0
- package/commonjs/react/useInstanceMethods.js.map +1 -0
- package/commonjs/react/useItemKeys.js +60 -0
- package/commonjs/react/useItemKeys.js.map +1 -0
- package/commonjs/react/useOnItemHeightChange.js +32 -0
- package/commonjs/react/useOnItemHeightChange.js.map +1 -0
- package/commonjs/react/useOnItemStateChange.js +32 -0
- package/commonjs/react/useOnItemStateChange.js.map +1 -0
- package/commonjs/react/useState.js +140 -0
- package/commonjs/react/useState.js.map +1 -0
- package/commonjs/react/useStyle.js +29 -0
- package/commonjs/react/useStyle.js.map +1 -0
- package/commonjs/react/useVirtualScroller.js +62 -0
- package/commonjs/react/useVirtualScroller.js.map +1 -0
- package/commonjs/react/useVirtualScrollerStartStop.js +20 -0
- package/commonjs/react/useVirtualScrollerStartStop.js.map +1 -0
- package/commonjs/test/Engine.js +23 -0
- package/commonjs/test/Engine.js.map +1 -0
- package/commonjs/test/ItemsContainer.js +127 -0
- package/commonjs/test/ItemsContainer.js.map +1 -0
- package/commonjs/test/ScrollableContainer.js +130 -0
- package/commonjs/test/ScrollableContainer.js.map +1 -0
- package/commonjs/test/VirtualScroller.js +281 -0
- package/commonjs/test/VirtualScroller.js.map +1 -0
- package/commonjs/utility/debounce.js +28 -6
- package/commonjs/utility/debounce.js.map +1 -1
- package/commonjs/utility/debug.js +51 -12
- package/commonjs/utility/debug.js.map +1 -1
- package/commonjs/utility/getStateSnapshot.js +50 -0
- package/commonjs/utility/getStateSnapshot.js.map +1 -0
- package/commonjs/utility/px.js +1 -1
- package/commonjs/utility/px.js.map +1 -1
- package/commonjs/utility/px.test.js +14 -0
- package/commonjs/utility/px.test.js.map +1 -0
- package/commonjs/utility/shallowEqual.js +1 -1
- package/commonjs/utility/shallowEqual.js.map +1 -1
- package/commonjs/utility/throttle.js.map +1 -1
- package/dom/index.cjs +4 -0
- package/dom/index.cjs.js +9 -0
- package/dom/index.d.ts +25 -0
- package/dom/index.js +1 -1
- package/dom/package.json +10 -4
- package/index.cjs +4 -0
- package/index.cjs.js +9 -0
- package/index.d.ts +99 -0
- package/index.js +1 -1
- package/modules/BeforeResize.js +305 -0
- package/modules/BeforeResize.js.map +1 -0
- package/modules/DOM/Engine.js +27 -0
- package/modules/DOM/Engine.js.map +1 -0
- package/modules/DOM/ItemsContainer.js +71 -0
- package/modules/DOM/ItemsContainer.js.map +1 -0
- package/modules/DOM/{WaitForStylesToLoad.js → ListTopOffsetWatcher.js} +72 -44
- package/modules/DOM/ListTopOffsetWatcher.js.map +1 -0
- package/modules/DOM/ScrollableContainer.js +68 -100
- package/modules/DOM/ScrollableContainer.js.map +1 -1
- package/modules/DOM/VirtualScroller.js +32 -28
- package/modules/DOM/VirtualScroller.js.map +1 -1
- package/modules/DOM/tbody.js +11 -9
- package/modules/DOM/tbody.js.map +1 -1
- package/modules/ItemHeights.js +28 -33
- package/modules/ItemHeights.js.map +1 -1
- package/modules/Layout.js +585 -214
- package/modules/Layout.js.map +1 -1
- package/modules/Layout.test.js +190 -0
- package/modules/Layout.test.js.map +1 -0
- package/modules/ListHeightMeasurement.js +117 -0
- package/modules/ListHeightMeasurement.js.map +1 -0
- package/modules/Resize.js +50 -39
- package/modules/Resize.js.map +1 -1
- package/modules/Scroll.js +139 -94
- package/modules/Scroll.js.map +1 -1
- package/modules/VirtualScroller.columns.js +36 -0
- package/modules/VirtualScroller.columns.js.map +1 -0
- package/modules/VirtualScroller.constructor.js +371 -0
- package/modules/VirtualScroller.constructor.js.map +1 -0
- package/modules/VirtualScroller.items.js +288 -0
- package/modules/VirtualScroller.items.js.map +1 -0
- package/modules/VirtualScroller.js +159 -1014
- package/modules/VirtualScroller.js.map +1 -1
- package/modules/VirtualScroller.layout.js +549 -0
- package/modules/VirtualScroller.layout.js.map +1 -0
- package/modules/VirtualScroller.onRender.js +337 -0
- package/modules/VirtualScroller.onRender.js.map +1 -0
- package/modules/VirtualScroller.resize.js +176 -0
- package/modules/VirtualScroller.resize.js.map +1 -0
- package/modules/VirtualScroller.state.js +283 -0
- package/modules/VirtualScroller.state.js.map +1 -0
- package/modules/VirtualScroller.verticalSpacing.js +54 -0
- package/modules/VirtualScroller.verticalSpacing.js.map +1 -0
- package/modules/getItemCoordinates.js.map +1 -1
- package/modules/getItemsDiff.js.map +1 -1
- package/modules/getVerticalSpacing.js +8 -8
- package/modules/getVerticalSpacing.js.map +1 -1
- package/modules/react/VirtualScroller.js +179 -634
- package/modules/react/VirtualScroller.js.map +1 -1
- package/modules/react/useClassName.js +18 -0
- package/modules/react/useClassName.js.map +1 -0
- package/modules/react/useHandleItemsChange.js +108 -0
- package/modules/react/useHandleItemsChange.js.map +1 -0
- package/modules/react/useInstanceMethods.js +28 -0
- package/modules/react/useInstanceMethods.js.map +1 -0
- package/modules/react/useItemKeys.js +52 -0
- package/modules/react/useItemKeys.js.map +1 -0
- package/modules/react/useOnItemHeightChange.js +24 -0
- package/modules/react/useOnItemHeightChange.js.map +1 -0
- package/modules/react/useOnItemStateChange.js +24 -0
- package/modules/react/useOnItemStateChange.js.map +1 -0
- package/modules/react/useState.js +132 -0
- package/modules/react/useState.js.map +1 -0
- package/modules/react/useStyle.js +19 -0
- package/modules/react/useStyle.js.map +1 -0
- package/modules/react/useVirtualScroller.js +51 -0
- package/modules/react/useVirtualScroller.js.map +1 -0
- package/modules/react/useVirtualScrollerStartStop.js +12 -0
- package/modules/react/useVirtualScrollerStartStop.js.map +1 -0
- package/modules/test/Engine.js +11 -0
- package/modules/test/Engine.js.map +1 -0
- package/modules/test/ItemsContainer.js +120 -0
- package/modules/test/ItemsContainer.js.map +1 -0
- package/modules/test/ScrollableContainer.js +123 -0
- package/modules/test/ScrollableContainer.js.map +1 -0
- package/modules/test/VirtualScroller.js +270 -0
- package/modules/test/VirtualScroller.js.map +1 -0
- package/modules/utility/debounce.js +28 -6
- package/modules/utility/debounce.js.map +1 -1
- package/modules/utility/debug.js +47 -10
- package/modules/utility/debug.js.map +1 -1
- package/modules/utility/getStateSnapshot.js +43 -0
- package/modules/utility/getStateSnapshot.js.map +1 -0
- package/modules/utility/px.js +1 -1
- package/modules/utility/px.js.map +1 -1
- package/modules/utility/px.test.js +9 -0
- package/modules/utility/px.test.js.map +1 -0
- package/modules/utility/shallowEqual.js +1 -1
- package/modules/utility/shallowEqual.js.map +1 -1
- package/modules/utility/throttle.js.map +1 -1
- package/package.json +54 -29
- package/react/index.cjs +4 -0
- package/react/index.cjs.js +9 -0
- package/react/index.d.ts +28 -0
- package/react/index.js +1 -1
- package/react/package.json +10 -4
- package/rollup.config.mjs +62 -0
- package/runnable/create-commonjs-package-json.js +11 -0
- package/source/BeforeResize.js +312 -0
- package/source/DOM/Engine.js +30 -0
- package/source/DOM/ItemsContainer.js +48 -0
- package/source/DOM/{WaitForStylesToLoad.js → ListTopOffsetWatcher.js} +61 -30
- package/source/DOM/ScrollableContainer.js +51 -73
- package/source/DOM/VirtualScroller.js +33 -18
- package/source/DOM/tbody.js +30 -21
- package/source/ItemHeights.js +27 -27
- package/source/Layout.js +629 -252
- package/source/Layout.test.js +176 -0
- package/source/ListHeightMeasurement.js +95 -0
- package/source/Resize.js +56 -32
- package/source/Scroll.js +135 -82
- package/source/VirtualScroller.columns.js +26 -0
- package/source/VirtualScroller.constructor.js +336 -0
- package/source/VirtualScroller.items.js +302 -0
- package/source/VirtualScroller.js +162 -936
- package/source/VirtualScroller.layout.js +539 -0
- package/source/VirtualScroller.onRender.js +345 -0
- package/source/VirtualScroller.resize.js +189 -0
- package/source/VirtualScroller.state.js +284 -0
- package/source/VirtualScroller.verticalSpacing.js +51 -0
- package/source/getVerticalSpacing.js +7 -7
- package/source/react/VirtualScroller.js +243 -603
- package/source/react/useClassName.js +14 -0
- package/source/react/useHandleItemsChange.js +115 -0
- package/source/react/useInstanceMethods.js +25 -0
- package/source/react/useItemKeys.js +59 -0
- package/source/react/useOnItemHeightChange.js +28 -0
- package/source/react/useOnItemStateChange.js +28 -0
- package/source/react/useState.js +114 -0
- package/source/react/useStyle.js +20 -0
- package/source/react/useVirtualScroller.js +59 -0
- package/source/react/useVirtualScrollerStartStop.js +12 -0
- package/source/test/Engine.js +11 -0
- package/source/test/ItemsContainer.js +87 -0
- package/source/test/ScrollableContainer.js +88 -0
- package/source/test/VirtualScroller.js +232 -0
- package/source/utility/debounce.js +22 -5
- package/source/utility/debug.js +34 -3
- package/source/utility/getStateSnapshot.js +36 -0
- package/source/utility/px.js +1 -1
- package/source/utility/px.test.js +9 -0
- package/website/index-bypass.html +195 -0
- package/website/index-grid.html +0 -1
- package/website/index-scrollableContainer.html +208 -0
- package/website/index-tbody-scrollableContainer.html +68 -0
- package/website/index-tbody.html +55 -0
- package/commonjs/DOM/RenderingEngine.js +0 -33
- package/commonjs/DOM/RenderingEngine.js.map +0 -1
- package/commonjs/DOM/Screen.js +0 -87
- package/commonjs/DOM/Screen.js.map +0 -1
- package/commonjs/DOM/WaitForStylesToLoad.js.map +0 -1
- package/commonjs/RestoreScroll.js +0 -118
- package/commonjs/RestoreScroll.js.map +0 -1
- package/dom/index.commonjs.js +0 -4
- package/index.commonjs.js +0 -4
- package/modules/DOM/RenderingEngine.js +0 -19
- package/modules/DOM/RenderingEngine.js.map +0 -1
- package/modules/DOM/Screen.js +0 -80
- package/modules/DOM/Screen.js.map +0 -1
- package/modules/DOM/WaitForStylesToLoad.js.map +0 -1
- package/modules/RestoreScroll.js +0 -111
- package/modules/RestoreScroll.js.map +0 -1
- package/react/index.commonjs.js +0 -4
- package/source/DOM/RenderingEngine.js +0 -22
- package/source/DOM/Screen.js +0 -51
- package/source/RestoreScroll.js +0 -86
|
@@ -0,0 +1,315 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.cleanUpBeforeResizeState = cleanUpBeforeResizeState;
|
|
7
|
+
exports["default"] = void 0;
|
|
8
|
+
|
|
9
|
+
var _debug = _interopRequireDefault(require("./utility/debug.js"));
|
|
10
|
+
|
|
11
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
|
12
|
+
|
|
13
|
+
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; }
|
|
14
|
+
|
|
15
|
+
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; }
|
|
16
|
+
|
|
17
|
+
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; }
|
|
18
|
+
|
|
19
|
+
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
20
|
+
|
|
21
|
+
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
|
|
22
|
+
|
|
23
|
+
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
|
24
|
+
|
|
25
|
+
var BeforeResize = /*#__PURE__*/function () {
|
|
26
|
+
function BeforeResize(_ref) {
|
|
27
|
+
var getState = _ref.getState,
|
|
28
|
+
getVerticalSpacing = _ref.getVerticalSpacing,
|
|
29
|
+
getColumnsCount = _ref.getColumnsCount;
|
|
30
|
+
|
|
31
|
+
_classCallCheck(this, BeforeResize);
|
|
32
|
+
|
|
33
|
+
this.getState = getState;
|
|
34
|
+
this.getVerticalSpacing = getVerticalSpacing;
|
|
35
|
+
this.getColumnsCount = getColumnsCount;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
_createClass(BeforeResize, [{
|
|
39
|
+
key: "initializeFromState",
|
|
40
|
+
value: function initializeFromState(state) {
|
|
41
|
+
this._includesBeforeResizeInState = Boolean(state.beforeResize);
|
|
42
|
+
} // Cleans up "before resize" item heights and adjusts the scroll position accordingly.
|
|
43
|
+
//
|
|
44
|
+
// Hypothetically, it could also wait for the user to stop scrolling and only then
|
|
45
|
+
// adjust the scroll position. The rationale is that if `window.scrollTo()` is called
|
|
46
|
+
// while the user is scrolling, the user would occasionally experience "lost" mouse wheel
|
|
47
|
+
// events when scrolling with a mouse wheel.
|
|
48
|
+
//
|
|
49
|
+
// Seems like Twitter's website waits for the user to stop scrolling before applying
|
|
50
|
+
// the scroll position correction after a window resize. This library could do that too,
|
|
51
|
+
// but that would require rewriting "before items height" top padding calculation
|
|
52
|
+
// so that it doesn't re-calculate it on every re-render and instead does so incrementally,
|
|
53
|
+
// and then, when the user stops, it re-calculates it from scratch removing the error
|
|
54
|
+
// and adjusting the scroll position accordingly so that there's no "jump of content".
|
|
55
|
+
//
|
|
56
|
+
// But, seems like it works fine as it is and there's no need to rewrite anything.
|
|
57
|
+
//
|
|
58
|
+
|
|
59
|
+
}, {
|
|
60
|
+
key: "cleanUpBeforeResizeItemHeights",
|
|
61
|
+
value: function cleanUpBeforeResizeItemHeights() {
|
|
62
|
+
var _this$getState = this.getState(),
|
|
63
|
+
firstShownItemIndex = _this$getState.firstShownItemIndex,
|
|
64
|
+
lastShownItemIndex = _this$getState.lastShownItemIndex,
|
|
65
|
+
itemHeights = _this$getState.itemHeights,
|
|
66
|
+
beforeResize = _this$getState.beforeResize; // If there're "before resize" properties in `state`
|
|
67
|
+
// then it means that the corresponding items are waiting to be
|
|
68
|
+
// re-measured after container resize. Since the resize,
|
|
69
|
+
// some of those non-re-measured items might have just been measured,
|
|
70
|
+
// so see if that's true, and if it is, remove those now-obsolete
|
|
71
|
+
// "before resize" item heights and ajust the scroll position
|
|
72
|
+
// so that there's no "content jumping".
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
if (beforeResize) {
|
|
76
|
+
// If the user has scrolled up to reveal a previously hidden item
|
|
77
|
+
// that has not yet been re-measured after a previous resize.
|
|
78
|
+
if (firstShownItemIndex < beforeResize.itemHeights.length) {
|
|
79
|
+
(0, _debug["default"])('~ Clean up "before resize" item heights and correct scroll position ~'); // Some of the "before" items have been un-hidden and re-measured.
|
|
80
|
+
// Un-hiding those items would result in a "jump of content"
|
|
81
|
+
// because "before resize" heights of those un-hidden items
|
|
82
|
+
// could (and most likely will) be different from the current ones,
|
|
83
|
+
// or because "before resize" columns count is different from
|
|
84
|
+
// the current one.
|
|
85
|
+
// To prevent a "jump of content", calculate the scroll position
|
|
86
|
+
// difference and adjust the scroll position.
|
|
87
|
+
// The height of the item rows that have transitioned
|
|
88
|
+
// from hidden to shown.
|
|
89
|
+
|
|
90
|
+
var newlyShownItemRowsHeight = 0; // Some of the `itemHeights` between the current `firstShownItemIndex` and
|
|
91
|
+
// the previous `firstShownItemIndex` could stay `undefined` if the user
|
|
92
|
+
// scrolled "abruptly": for example, by using a `window.scrollTo()` call.
|
|
93
|
+
// In that case, the items below the visible ones won't be rendered and measured.
|
|
94
|
+
// In such case, limit the items being iterated over to the current `lastShownItemIndex`
|
|
95
|
+
// rather than the previous `firstShownItemIndex`.
|
|
96
|
+
|
|
97
|
+
var prevFirstReMeasuredItemsRowIndex = Math.floor(beforeResize.itemHeights.length / this.getColumnsCount());
|
|
98
|
+
var newlyShownItemsToIndex = Math.min(prevFirstReMeasuredItemsRowIndex * this.getColumnsCount() - 1, lastShownItemIndex);
|
|
99
|
+
var i = firstShownItemIndex;
|
|
100
|
+
|
|
101
|
+
while (i <= newlyShownItemsToIndex) {
|
|
102
|
+
// Calculate newly shown row height.
|
|
103
|
+
var rowHeight = 0;
|
|
104
|
+
var columnIndex = 0;
|
|
105
|
+
|
|
106
|
+
while (columnIndex < this.getColumnsCount() && i <= newlyShownItemsToIndex) {
|
|
107
|
+
var itemHeight = itemHeights[i];
|
|
108
|
+
|
|
109
|
+
if (itemHeight === undefined) {
|
|
110
|
+
// `itemHeight` can only be `undefined` when not `beforeResize`.
|
|
111
|
+
// Use the current "average item height" as a substitute.
|
|
112
|
+
itemHeight = this.getAverageItemHeight();
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
rowHeight = Math.max(rowHeight, itemHeight);
|
|
116
|
+
i++;
|
|
117
|
+
columnIndex++;
|
|
118
|
+
} // Append to the total "newly shown item rows height".
|
|
119
|
+
|
|
120
|
+
|
|
121
|
+
newlyShownItemRowsHeight += rowHeight;
|
|
122
|
+
newlyShownItemRowsHeight += this.getVerticalSpacing();
|
|
123
|
+
} // The height of the "before resize" item rows
|
|
124
|
+
// that will be "cleaned up" in this function call.
|
|
125
|
+
|
|
126
|
+
|
|
127
|
+
var cleanedUpBeforeResizeItemRowsHeight = 0; // Some of the `beforeResize` item rows might have been skipped if the user
|
|
128
|
+
// scrolled up "abruptly": for example, by using a `window.scrollTo()` call.
|
|
129
|
+
// In that case, the "before resize" items below the bottom border of the screen
|
|
130
|
+
// shouldn't be accounted for when calculating the scrollbar adjustment shift
|
|
131
|
+
// because items after `lastShownItemIndex` aren't participating in the calculation
|
|
132
|
+
// of `newlyShownItemRowsHeight`.
|
|
133
|
+
|
|
134
|
+
var maxParticipatingBeforeResizeItemsCount = Math.min(beforeResize.itemHeights.length, lastShownItemIndex + 1);
|
|
135
|
+
var participatingBeforeResizeItemRowsCount = Math.ceil(maxParticipatingBeforeResizeItemsCount / beforeResize.columnsCount);
|
|
136
|
+
var firstCleanedUpBeforeResizeItemsRowIndex = firstShownItemIndex === 0 ? 0 : Math.floor((firstShownItemIndex - 1) / beforeResize.columnsCount) + 1;
|
|
137
|
+
var k = firstCleanedUpBeforeResizeItemsRowIndex;
|
|
138
|
+
|
|
139
|
+
while (k < participatingBeforeResizeItemRowsCount) {
|
|
140
|
+
var _rowHeight = beforeResize.itemHeights[k * beforeResize.columnsCount];
|
|
141
|
+
cleanedUpBeforeResizeItemRowsHeight += _rowHeight;
|
|
142
|
+
cleanedUpBeforeResizeItemRowsHeight += beforeResize.verticalSpacing;
|
|
143
|
+
k++;
|
|
144
|
+
} // Schedule an asynchronous `this.updateState()` call that will update
|
|
145
|
+
// `beforeResize` property of `state`. Ideally, it should be updated
|
|
146
|
+
// immediately, but since `this.updateState()` calls are asynchronous,
|
|
147
|
+
// the code updates just the underlying `beforeResize.itemHeights`
|
|
148
|
+
// array immediately instead, which is still a hack but still a lesser one.
|
|
149
|
+
|
|
150
|
+
|
|
151
|
+
if (firstShownItemIndex === 0) {
|
|
152
|
+
(0, _debug["default"])('Drop all "before resize" item heights');
|
|
153
|
+
} else {
|
|
154
|
+
var firstDroppedBeforeResizeItemIndex = firstShownItemIndex;
|
|
155
|
+
var lastDroppedBeforeResizeItemIndex = beforeResize.itemHeights.length - 1;
|
|
156
|
+
|
|
157
|
+
if (firstDroppedBeforeResizeItemIndex === lastDroppedBeforeResizeItemIndex) {
|
|
158
|
+
(0, _debug["default"])('For item index', firstDroppedBeforeResizeItemIndex, '— drop "before resize" height', beforeResize.itemHeights[firstDroppedBeforeResizeItemIndex]);
|
|
159
|
+
} else {
|
|
160
|
+
(0, _debug["default"])('For item indexes from', firstDroppedBeforeResizeItemIndex, 'to', lastDroppedBeforeResizeItemIndex, '— drop "before resize" heights', beforeResize.itemHeights.slice(firstDroppedBeforeResizeItemIndex));
|
|
161
|
+
}
|
|
162
|
+
} // Immediately update `beforeResize.itemHeights`
|
|
163
|
+
// so that the component isn't left in an inconsistent state
|
|
164
|
+
// before a `this.updateState()` call below is applied.
|
|
165
|
+
|
|
166
|
+
|
|
167
|
+
beforeResize.itemHeights.splice(firstShownItemIndex, beforeResize.itemHeights.length - firstShownItemIndex); // Return the "scroll by" amount that would correct the scroll position.
|
|
168
|
+
// Also return a state update.
|
|
169
|
+
|
|
170
|
+
return {
|
|
171
|
+
scrollBy: newlyShownItemRowsHeight - cleanedUpBeforeResizeItemRowsHeight,
|
|
172
|
+
beforeResize: firstShownItemIndex === 0 ? undefined : _objectSpread({}, beforeResize)
|
|
173
|
+
};
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
} // Snapshots "before resize" values in order to preserve the currently
|
|
177
|
+
// shown items' vertical position on screen so that there's no "content jumping".
|
|
178
|
+
//
|
|
179
|
+
// `newFirstShownItemIndex` is `> 0`.
|
|
180
|
+
//
|
|
181
|
+
|
|
182
|
+
}, {
|
|
183
|
+
key: "snapshotBeforeResizeItemHeights",
|
|
184
|
+
value: function snapshotBeforeResizeItemHeights(_ref2) {
|
|
185
|
+
var firstShownItemIndex = _ref2.firstShownItemIndex,
|
|
186
|
+
newFirstShownItemIndex = _ref2.newFirstShownItemIndex,
|
|
187
|
+
newColumnsCount = _ref2.newColumnsCount;
|
|
188
|
+
var columnsCount = this.getColumnsCount();
|
|
189
|
+
var verticalSpacing = this.getVerticalSpacing();
|
|
190
|
+
this._includesBeforeResizeInState = true;
|
|
191
|
+
|
|
192
|
+
var _this$getState2 = this.getState(),
|
|
193
|
+
prevBeforeResize = _this$getState2.beforeResize,
|
|
194
|
+
itemHeights = _this$getState2.itemHeights;
|
|
195
|
+
|
|
196
|
+
var prevBeforeResizeItemsCount = prevBeforeResize ? prevBeforeResize.itemHeights.length : 0; // If there already are "before resize" values in `state`
|
|
197
|
+
// then it means that those should be merged with the new ones.
|
|
198
|
+
//
|
|
199
|
+
// `beforeResize.itemHeights` could be empty in an edge case
|
|
200
|
+
// when there's a pending state update that sets `beforeResize`
|
|
201
|
+
// to `undefined`, and in that case empty `beforeResize.itemHeights`
|
|
202
|
+
// signals about that type of a situation.
|
|
203
|
+
//
|
|
204
|
+
|
|
205
|
+
if (prevBeforeResizeItemsCount > 0) {
|
|
206
|
+
// Because the "previous" before resize values might have been captured
|
|
207
|
+
// for a window width corresponding to a layout with a different columns count
|
|
208
|
+
// and different vertical spacing, re-calculate those item heights as if
|
|
209
|
+
// they corresponded to the current columns count and current vertical spacing,
|
|
210
|
+
// since "previous" and "new" before resize item heights are gonna be merged.
|
|
211
|
+
if (prevBeforeResize.columnsCount !== columnsCount || prevBeforeResize.verticalSpacing !== verticalSpacing) {
|
|
212
|
+
var prevBeforeResizeBeforeItemsHeight = 0;
|
|
213
|
+
var prevBeforeResizeItemRowsCount = Math.ceil(prevBeforeResizeItemsCount / prevBeforeResize.columnsCount);
|
|
214
|
+
var rowIndex = 0;
|
|
215
|
+
|
|
216
|
+
while (rowIndex < prevBeforeResizeItemRowsCount) {
|
|
217
|
+
// Since all "before resize" item heights are equal within a row,
|
|
218
|
+
// the height of the first "before resize" item in a row is that row's height.
|
|
219
|
+
var rowHeight = prevBeforeResize.itemHeights[rowIndex * prevBeforeResize.columnsCount];
|
|
220
|
+
prevBeforeResizeBeforeItemsHeight += rowHeight;
|
|
221
|
+
prevBeforeResizeBeforeItemsHeight += prevBeforeResize.verticalSpacing;
|
|
222
|
+
rowIndex++;
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
var newBeforeResizeAdditionalBeforeItemsHeight = 0;
|
|
226
|
+
var i = firstShownItemIndex;
|
|
227
|
+
|
|
228
|
+
while (i < newFirstShownItemIndex) {
|
|
229
|
+
var _rowHeight2 = 0;
|
|
230
|
+
var k = 0;
|
|
231
|
+
|
|
232
|
+
while (k < columnsCount && i < newFirstShownItemIndex) {
|
|
233
|
+
_rowHeight2 = Math.max(_rowHeight2, itemHeights[i]);
|
|
234
|
+
k++;
|
|
235
|
+
i++;
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
newBeforeResizeAdditionalBeforeItemsHeight += _rowHeight2;
|
|
239
|
+
newBeforeResizeAdditionalBeforeItemsHeight += verticalSpacing;
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
var newBeforeResizeBeforeItemsHeight = prevBeforeResizeBeforeItemsHeight + newBeforeResizeAdditionalBeforeItemsHeight;
|
|
243
|
+
var newBeforeResizeBeforeItemRowsCount = Math.ceil(newFirstShownItemIndex / columnsCount);
|
|
244
|
+
return new Array(newFirstShownItemIndex).fill( // Re-calculate "before resize" item heights so that "previous" and "new" ones
|
|
245
|
+
// correspond to the same (new) columns count.
|
|
246
|
+
// Also don't occasionally set item heights to `< 0`.
|
|
247
|
+
Math.max(0, newBeforeResizeBeforeItemsHeight / newBeforeResizeBeforeItemRowsCount - verticalSpacing));
|
|
248
|
+
} else {
|
|
249
|
+
// Add new item heights to the previously snapshotted ones.
|
|
250
|
+
return prevBeforeResize.itemHeights.concat(equalizeItemHeights(itemHeights, newFirstShownItemIndex, columnsCount).slice(prevBeforeResize.itemHeights.length));
|
|
251
|
+
}
|
|
252
|
+
} else {
|
|
253
|
+
return equalizeItemHeights(itemHeights, newFirstShownItemIndex, columnsCount);
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
}, {
|
|
257
|
+
key: "shouldIncludeBeforeResizeValuesInState",
|
|
258
|
+
value: function shouldIncludeBeforeResizeValuesInState() {
|
|
259
|
+
return this._includesBeforeResizeInState;
|
|
260
|
+
}
|
|
261
|
+
}]);
|
|
262
|
+
|
|
263
|
+
return BeforeResize;
|
|
264
|
+
}(); // Equalizes all item heights within a given row, for each row.
|
|
265
|
+
//
|
|
266
|
+
// The reason is that `beforeResize.itemHeights` is not necessarily divisible by
|
|
267
|
+
// `beforeResize.columnsCount`, which would result in varying last row height
|
|
268
|
+
// as items get removed from `beforeResize.itemHeights` as the user scrolls up.
|
|
269
|
+
//
|
|
270
|
+
// By equalizing all item heights within a given row, for each row, such "jumping"
|
|
271
|
+
// last "before resize" row height is prevented when the user scrolls up.
|
|
272
|
+
//
|
|
273
|
+
|
|
274
|
+
|
|
275
|
+
exports["default"] = BeforeResize;
|
|
276
|
+
|
|
277
|
+
function equalizeItemHeights(itemHeights, maxItemsCount, columnsCount) {
|
|
278
|
+
itemHeights = itemHeights.slice(0, Math.ceil(maxItemsCount / columnsCount) * columnsCount);
|
|
279
|
+
var rowIndex = 0;
|
|
280
|
+
|
|
281
|
+
while (rowIndex * columnsCount < maxItemsCount) {
|
|
282
|
+
// Calculate row height.
|
|
283
|
+
var rowHeight = 0;
|
|
284
|
+
var k = 0;
|
|
285
|
+
|
|
286
|
+
while (k < columnsCount) {
|
|
287
|
+
rowHeight = Math.max(rowHeight, itemHeights[rowIndex * columnsCount + k]);
|
|
288
|
+
k++;
|
|
289
|
+
} // Equalize all item heights within the row.
|
|
290
|
+
|
|
291
|
+
|
|
292
|
+
k = 0;
|
|
293
|
+
|
|
294
|
+
while (k < columnsCount) {
|
|
295
|
+
itemHeights[rowIndex * columnsCount + k] = rowHeight;
|
|
296
|
+
k++;
|
|
297
|
+
} // Proceed with the next row.
|
|
298
|
+
|
|
299
|
+
|
|
300
|
+
rowIndex++;
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
return itemHeights.slice(0, maxItemsCount);
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
function cleanUpBeforeResizeState(state) {
|
|
307
|
+
if (state.beforeResize) {
|
|
308
|
+
if (state.beforeResize.itemHeights.length === 0) {
|
|
309
|
+
state.beforeResize = undefined;
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
return state;
|
|
314
|
+
}
|
|
315
|
+
//# sourceMappingURL=BeforeResize.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"BeforeResize.js","names":["BeforeResize","getState","getVerticalSpacing","getColumnsCount","state","_includesBeforeResizeInState","Boolean","beforeResize","firstShownItemIndex","lastShownItemIndex","itemHeights","length","log","newlyShownItemRowsHeight","prevFirstReMeasuredItemsRowIndex","Math","floor","newlyShownItemsToIndex","min","i","rowHeight","columnIndex","itemHeight","undefined","getAverageItemHeight","max","cleanedUpBeforeResizeItemRowsHeight","maxParticipatingBeforeResizeItemsCount","participatingBeforeResizeItemRowsCount","ceil","columnsCount","firstCleanedUpBeforeResizeItemsRowIndex","k","verticalSpacing","firstDroppedBeforeResizeItemIndex","lastDroppedBeforeResizeItemIndex","slice","splice","scrollBy","newFirstShownItemIndex","newColumnsCount","prevBeforeResize","prevBeforeResizeItemsCount","prevBeforeResizeBeforeItemsHeight","prevBeforeResizeItemRowsCount","rowIndex","newBeforeResizeAdditionalBeforeItemsHeight","newBeforeResizeBeforeItemsHeight","newBeforeResizeBeforeItemRowsCount","Array","fill","concat","equalizeItemHeights","maxItemsCount","cleanUpBeforeResizeState"],"sources":["../source/BeforeResize.js"],"sourcesContent":["import log from './utility/debug.js'\r\n\r\nexport default class BeforeResize {\r\n\tconstructor({\r\n\t\tgetState,\r\n\t\tgetVerticalSpacing,\r\n\t\tgetColumnsCount\r\n\t}) {\r\n\t\tthis.getState = getState\r\n\t\tthis.getVerticalSpacing = getVerticalSpacing\r\n\t\tthis.getColumnsCount = getColumnsCount\r\n\t}\r\n\r\n\tinitializeFromState(state) {\r\n\t\tthis._includesBeforeResizeInState = Boolean(state.beforeResize)\r\n\t}\r\n\r\n\t// Cleans up \"before resize\" item heights and adjusts the scroll position accordingly.\r\n\t//\r\n\t// Hypothetically, it could also wait for the user to stop scrolling and only then\r\n\t// adjust the scroll position. The rationale is that if `window.scrollTo()` is called\r\n\t// while the user is scrolling, the user would occasionally experience \"lost\" mouse wheel\r\n\t// events when scrolling with a mouse wheel.\r\n\t//\r\n\t// Seems like Twitter's website waits for the user to stop scrolling before applying\r\n\t// the scroll position correction after a window resize. This library could do that too,\r\n\t// but that would require rewriting \"before items height\" top padding calculation\r\n\t// so that it doesn't re-calculate it on every re-render and instead does so incrementally,\r\n\t// and then, when the user stops, it re-calculates it from scratch removing the error\r\n\t// and adjusting the scroll position accordingly so that there's no \"jump of content\".\r\n\t//\r\n\t// But, seems like it works fine as it is and there's no need to rewrite anything.\r\n\t//\r\n\tcleanUpBeforeResizeItemHeights() {\r\n\t\tconst {\r\n\t\t\tfirstShownItemIndex,\r\n\t\t\tlastShownItemIndex,\r\n\t\t\titemHeights,\r\n\t\t\tbeforeResize\r\n\t\t} = this.getState()\r\n\r\n\t\t// If there're \"before resize\" properties in `state`\r\n\t\t// then it means that the corresponding items are waiting to be\r\n\t\t// re-measured after container resize. Since the resize,\r\n\t\t// some of those non-re-measured items might have just been measured,\r\n\t\t// so see if that's true, and if it is, remove those now-obsolete\r\n\t\t// \"before resize\" item heights and ajust the scroll position\r\n\t\t// so that there's no \"content jumping\".\r\n\r\n\t\tif (beforeResize) {\r\n\t\t\t// If the user has scrolled up to reveal a previously hidden item\r\n\t\t\t// that has not yet been re-measured after a previous resize.\r\n\t\t\tif (firstShownItemIndex < beforeResize.itemHeights.length) {\r\n\t\t\t\tlog('~ Clean up \"before resize\" item heights and correct scroll position ~')\r\n\r\n\t\t\t\t// Some of the \"before\" items have been un-hidden and re-measured.\r\n\t\t\t\t// Un-hiding those items would result in a \"jump of content\"\r\n\t\t\t\t// because \"before resize\" heights of those un-hidden items\r\n\t\t\t\t// could (and most likely will) be different from the current ones,\r\n\t\t\t\t// or because \"before resize\" columns count is different from\r\n\t\t\t\t// the current one.\r\n\t\t\t\t// To prevent a \"jump of content\", calculate the scroll position\r\n\t\t\t\t// difference and adjust the scroll position.\r\n\r\n\t\t\t\t// The height of the item rows that have transitioned\r\n\t\t\t\t// from hidden to shown.\r\n\t\t\t\tlet newlyShownItemRowsHeight = 0\r\n\r\n\t\t\t\t// Some of the `itemHeights` between the current `firstShownItemIndex` and\r\n\t\t\t\t// the previous `firstShownItemIndex` could stay `undefined` if the user\r\n\t\t\t\t// scrolled \"abruptly\": for example, by using a `window.scrollTo()` call.\r\n\t\t\t\t// In that case, the items below the visible ones won't be rendered and measured.\r\n\t\t\t\t// In such case, limit the items being iterated over to the current `lastShownItemIndex`\r\n\t\t\t\t// rather than the previous `firstShownItemIndex`.\r\n\t\t\t\tconst prevFirstReMeasuredItemsRowIndex = Math.floor(beforeResize.itemHeights.length / this.getColumnsCount())\r\n\t\t\t\tconst newlyShownItemsToIndex = Math.min(\r\n\t\t\t\t\tprevFirstReMeasuredItemsRowIndex * this.getColumnsCount() - 1,\r\n\t\t\t\t\tlastShownItemIndex\r\n\t\t\t\t)\r\n\r\n\t\t\t\tlet i = firstShownItemIndex\r\n\t\t\t\twhile (i <= newlyShownItemsToIndex) {\r\n\t\t\t\t\t// Calculate newly shown row height.\r\n\t\t\t\t\tlet rowHeight = 0\r\n\t\t\t\t\tlet columnIndex = 0\r\n\t\t\t\t\twhile (columnIndex < this.getColumnsCount() && i <= newlyShownItemsToIndex) {\r\n\t\t\t\t\t\tlet itemHeight = itemHeights[i]\r\n\t\t\t\t\t\tif (itemHeight === undefined) {\r\n\t\t\t\t\t\t\t// `itemHeight` can only be `undefined` when not `beforeResize`.\r\n\t\t\t\t\t\t\t// Use the current \"average item height\" as a substitute.\r\n\t\t\t\t\t\t\titemHeight = this.getAverageItemHeight()\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t\trowHeight = Math.max(rowHeight, itemHeight)\r\n\t\t\t\t\t\ti++\r\n\t\t\t\t\t\tcolumnIndex++\r\n\t\t\t\t\t}\r\n\t\t\t\t\t// Append to the total \"newly shown item rows height\".\r\n\t\t\t\t\tnewlyShownItemRowsHeight += rowHeight\r\n\t\t\t\t\tnewlyShownItemRowsHeight += this.getVerticalSpacing()\r\n\t\t\t\t}\r\n\r\n\t\t\t\t// The height of the \"before resize\" item rows\r\n\t\t\t\t// that will be \"cleaned up\" in this function call.\r\n\t\t\t\tlet cleanedUpBeforeResizeItemRowsHeight = 0\r\n\r\n\t\t\t\t// Some of the `beforeResize` item rows might have been skipped if the user\r\n\t\t\t\t// scrolled up \"abruptly\": for example, by using a `window.scrollTo()` call.\r\n\t\t\t\t// In that case, the \"before resize\" items below the bottom border of the screen\r\n\t\t\t\t// shouldn't be accounted for when calculating the scrollbar adjustment shift\r\n\t\t\t\t// because items after `lastShownItemIndex` aren't participating in the calculation\r\n\t\t\t\t// of `newlyShownItemRowsHeight`.\r\n\t\t\t\tconst maxParticipatingBeforeResizeItemsCount = Math.min(beforeResize.itemHeights.length, lastShownItemIndex + 1)\r\n\t\t\t\tconst participatingBeforeResizeItemRowsCount = Math.ceil(maxParticipatingBeforeResizeItemsCount / beforeResize.columnsCount)\r\n\r\n\t\t\t\tconst firstCleanedUpBeforeResizeItemsRowIndex = firstShownItemIndex === 0\r\n\t\t\t\t\t? 0\r\n\t\t\t\t\t: Math.floor((firstShownItemIndex - 1) / beforeResize.columnsCount) + 1\r\n\r\n\t\t\t\tlet k = firstCleanedUpBeforeResizeItemsRowIndex\r\n\t\t\t\twhile (k < participatingBeforeResizeItemRowsCount) {\r\n\t\t\t\t\tconst rowHeight = beforeResize.itemHeights[k * beforeResize.columnsCount]\r\n\t\t\t\t\tcleanedUpBeforeResizeItemRowsHeight += rowHeight\r\n\t\t\t\t\tcleanedUpBeforeResizeItemRowsHeight += beforeResize.verticalSpacing\r\n\t\t\t\t\tk++\r\n\t\t\t\t}\r\n\r\n\t\t\t\t// Schedule an asynchronous `this.updateState()` call that will update\r\n\t\t\t\t// `beforeResize` property of `state`. Ideally, it should be updated\r\n\t\t\t\t// immediately, but since `this.updateState()` calls are asynchronous,\r\n\t\t\t\t// the code updates just the underlying `beforeResize.itemHeights`\r\n\t\t\t\t// array immediately instead, which is still a hack but still a lesser one.\r\n\t\t\t\tif (firstShownItemIndex === 0) {\r\n\t\t\t\t\tlog('Drop all \"before resize\" item heights')\r\n\t\t\t\t} else {\r\n\t\t\t\t\tconst firstDroppedBeforeResizeItemIndex = firstShownItemIndex\r\n\t\t\t\t\tconst lastDroppedBeforeResizeItemIndex = beforeResize.itemHeights.length - 1\r\n\t\t\t\t\tif (firstDroppedBeforeResizeItemIndex === lastDroppedBeforeResizeItemIndex) {\r\n\t\t\t\t\t\tlog('For item index', firstDroppedBeforeResizeItemIndex, '— drop \"before resize\" height', beforeResize.itemHeights[firstDroppedBeforeResizeItemIndex], )\r\n\t\t\t\t\t} else {\r\n\t\t\t\t\t\tlog('For item indexes from', firstDroppedBeforeResizeItemIndex, 'to', lastDroppedBeforeResizeItemIndex, '— drop \"before resize\" heights', beforeResize.itemHeights.slice(firstDroppedBeforeResizeItemIndex))\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\r\n\t\t\t\t// Immediately update `beforeResize.itemHeights`\r\n\t\t\t\t// so that the component isn't left in an inconsistent state\r\n\t\t\t\t// before a `this.updateState()` call below is applied.\r\n\t\t\t\tbeforeResize.itemHeights.splice(\r\n\t\t\t\t\tfirstShownItemIndex,\r\n\t\t\t\t\tbeforeResize.itemHeights.length - firstShownItemIndex\r\n\t\t\t\t)\r\n\r\n\t\t\t\t// Return the \"scroll by\" amount that would correct the scroll position.\r\n\t\t\t\t// Also return a state update.\r\n\t\t\t\treturn {\r\n\t\t\t\t\tscrollBy: newlyShownItemRowsHeight - cleanedUpBeforeResizeItemRowsHeight,\r\n\t\t\t\t\tbeforeResize: firstShownItemIndex === 0 ? undefined : {\r\n\t\t\t\t\t\t// Simply change the \"reference\" to `beforeResize` while leaving\r\n\t\t\t\t\t\t// its contents unchanged. That simply indicates that it has been updated:\r\n\t\t\t\t\t\t// `beforeResize.itemHeights` array length has been changed \"directly\".\r\n\t\t\t\t\t\t...beforeResize\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\r\n\t// Snapshots \"before resize\" values in order to preserve the currently\r\n\t// shown items' vertical position on screen so that there's no \"content jumping\".\r\n\t//\r\n\t// `newFirstShownItemIndex` is `> 0`.\r\n\t//\r\n\tsnapshotBeforeResizeItemHeights({\r\n\t\tfirstShownItemIndex,\r\n\t\tnewFirstShownItemIndex,\r\n\t\tnewColumnsCount\r\n\t}) {\r\n\t\tconst columnsCount = this.getColumnsCount()\r\n\t\tconst verticalSpacing = this.getVerticalSpacing()\r\n\r\n\t\tthis._includesBeforeResizeInState = true\r\n\r\n\t\tconst {\r\n\t\t\tbeforeResize: prevBeforeResize,\r\n\t\t\titemHeights\r\n\t\t} = this.getState()\r\n\r\n\t\tconst prevBeforeResizeItemsCount = prevBeforeResize\r\n\t\t\t? prevBeforeResize.itemHeights.length\r\n\t\t\t: 0\r\n\r\n\t\t// If there already are \"before resize\" values in `state`\r\n\t\t// then it means that those should be merged with the new ones.\r\n\t\t//\r\n\t\t// `beforeResize.itemHeights` could be empty in an edge case\r\n\t\t// when there's a pending state update that sets `beforeResize`\r\n\t\t// to `undefined`, and in that case empty `beforeResize.itemHeights`\r\n\t\t// signals about that type of a situation.\r\n\t\t//\r\n\t\tif (prevBeforeResizeItemsCount > 0) {\r\n\t\t\t// Because the \"previous\" before resize values might have been captured\r\n\t\t\t// for a window width corresponding to a layout with a different columns count\r\n\t\t\t// and different vertical spacing, re-calculate those item heights as if\r\n\t\t\t// they corresponded to the current columns count and current vertical spacing,\r\n\t\t\t// since \"previous\" and \"new\" before resize item heights are gonna be merged.\r\n\t\t\tif (\r\n\t\t\t\tprevBeforeResize.columnsCount !== columnsCount ||\r\n\t\t\t\tprevBeforeResize.verticalSpacing !== verticalSpacing\r\n\t\t\t) {\r\n\t\t\t\tlet prevBeforeResizeBeforeItemsHeight = 0\r\n\r\n\t\t\t\tconst prevBeforeResizeItemRowsCount = Math.ceil(prevBeforeResizeItemsCount / prevBeforeResize.columnsCount)\r\n\t\t\t\tlet rowIndex = 0\r\n\t\t\t\twhile (rowIndex < prevBeforeResizeItemRowsCount) {\r\n\t\t\t\t\t// Since all \"before resize\" item heights are equal within a row,\r\n\t\t\t\t\t// the height of the first \"before resize\" item in a row is that row's height.\r\n\t\t\t\t\tconst rowHeight = prevBeforeResize.itemHeights[rowIndex * prevBeforeResize.columnsCount]\r\n\t\t\t\t\tprevBeforeResizeBeforeItemsHeight += rowHeight\r\n\t\t\t\t\tprevBeforeResizeBeforeItemsHeight += prevBeforeResize.verticalSpacing\r\n\t\t\t\t\trowIndex++\r\n\t\t\t\t}\r\n\r\n\t\t\t\tlet newBeforeResizeAdditionalBeforeItemsHeight = 0\r\n\t\t\t\tlet i = firstShownItemIndex\r\n\t\t\t\twhile (i < newFirstShownItemIndex) {\r\n\t\t\t\t\tlet rowHeight = 0\r\n\t\t\t\t\tlet k = 0\r\n\t\t\t\t\twhile (k < columnsCount && i < newFirstShownItemIndex) {\r\n\t\t\t\t\t\trowHeight = Math.max(rowHeight, itemHeights[i])\r\n\t\t\t\t\t\tk++\r\n\t\t\t\t\t\ti++\r\n\t\t\t\t\t}\r\n\t\t\t\t\tnewBeforeResizeAdditionalBeforeItemsHeight += rowHeight\r\n\t\t\t\t\tnewBeforeResizeAdditionalBeforeItemsHeight += verticalSpacing\r\n\t\t\t\t}\r\n\r\n\t\t\t\tconst newBeforeResizeBeforeItemsHeight = prevBeforeResizeBeforeItemsHeight + newBeforeResizeAdditionalBeforeItemsHeight\r\n\t\t\t\tconst newBeforeResizeBeforeItemRowsCount = Math.ceil(newFirstShownItemIndex / columnsCount)\r\n\r\n\t\t\t\treturn new Array(newFirstShownItemIndex).fill(\r\n\t\t\t\t\t// Re-calculate \"before resize\" item heights so that \"previous\" and \"new\" ones\r\n\t\t\t\t\t// correspond to the same (new) columns count.\r\n\t\t\t\t\t// Also don't occasionally set item heights to `< 0`.\r\n\t\t\t\t\tMath.max(0, newBeforeResizeBeforeItemsHeight / newBeforeResizeBeforeItemRowsCount - verticalSpacing)\r\n\t\t\t\t)\r\n\t\t\t} else {\r\n\t\t\t\t// Add new item heights to the previously snapshotted ones.\r\n\t\t\t\treturn prevBeforeResize.itemHeights.concat(\r\n\t\t\t\t\tequalizeItemHeights(\r\n\t\t\t\t\t\titemHeights,\r\n\t\t\t\t\t\tnewFirstShownItemIndex,\r\n\t\t\t\t\t\tcolumnsCount\r\n\t\t\t\t\t).slice(prevBeforeResize.itemHeights.length)\r\n\t\t\t\t)\r\n\t\t\t}\r\n\t\t} else {\r\n\t\t\treturn equalizeItemHeights(\r\n\t\t\t\titemHeights,\r\n\t\t\t\tnewFirstShownItemIndex,\r\n\t\t\t\tcolumnsCount\r\n\t\t\t)\r\n\t\t}\r\n\t}\r\n\r\n\tshouldIncludeBeforeResizeValuesInState() {\r\n\t\treturn this._includesBeforeResizeInState\r\n\t}\r\n}\r\n\r\n// Equalizes all item heights within a given row, for each row.\r\n//\r\n// The reason is that `beforeResize.itemHeights` is not necessarily divisible by\r\n// `beforeResize.columnsCount`, which would result in varying last row height\r\n// as items get removed from `beforeResize.itemHeights` as the user scrolls up.\r\n//\r\n// By equalizing all item heights within a given row, for each row, such \"jumping\"\r\n// last \"before resize\" row height is prevented when the user scrolls up.\r\n//\r\nfunction equalizeItemHeights(itemHeights, maxItemsCount, columnsCount) {\r\n\titemHeights = itemHeights.slice(0, Math.ceil(maxItemsCount / columnsCount) * columnsCount)\r\n\r\n\tlet rowIndex = 0\r\n\twhile (rowIndex * columnsCount < maxItemsCount) {\r\n\t\t// Calculate row height.\r\n\t\tlet rowHeight = 0\r\n\t\tlet k = 0\r\n\t\twhile (k < columnsCount) {\r\n\t\t\trowHeight = Math.max(rowHeight, itemHeights[rowIndex * columnsCount + k])\r\n\t\t\tk++\r\n\t\t}\r\n\r\n\t\t// Equalize all item heights within the row.\r\n\t\tk = 0\r\n\t\twhile (k < columnsCount) {\r\n\t\t\titemHeights[rowIndex * columnsCount + k] = rowHeight\r\n\t\t\tk++\r\n\t\t}\r\n\r\n\t\t// Proceed with the next row.\r\n\t\trowIndex++\r\n\t}\r\n\r\n\treturn itemHeights.slice(0, maxItemsCount)\r\n}\r\n\r\nexport function cleanUpBeforeResizeState(state) {\r\n\tif (state.beforeResize) {\r\n\t\tif (state.beforeResize.itemHeights.length === 0) {\r\n\t\t\tstate.beforeResize = undefined\r\n\t\t}\r\n\t}\r\n\treturn state\r\n}"],"mappings":";;;;;;;;AAAA;;;;;;;;;;;;;;;;IAEqBA,Y;EACpB,4BAIG;IAAA,IAHFC,QAGE,QAHFA,QAGE;IAAA,IAFFC,kBAEE,QAFFA,kBAEE;IAAA,IADFC,eACE,QADFA,eACE;;IAAA;;IACF,KAAKF,QAAL,GAAgBA,QAAhB;IACA,KAAKC,kBAAL,GAA0BA,kBAA1B;IACA,KAAKC,eAAL,GAAuBA,eAAvB;EACA;;;;WAED,6BAAoB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A3C;MACAY,CAAC;IACD,CAd8C,CAgB/C;;;IACAa,QAAQ;EACR;;EAED,OAAOnC,WAAW,CAAC0B,KAAZ,CAAkB,CAAlB,EAAqBiB,aAArB,CAAP;AACA;;AAEM,SAASC,wBAAT,CAAkClD,KAAlC,EAAyC;EAC/C,IAAIA,KAAK,CAACG,YAAV,EAAwB;IACvB,IAAIH,KAAK,CAACG,YAAN,CAAmBG,WAAnB,CAA+BC,MAA/B,KAA0C,CAA9C,EAAiD;MAChDP,KAAK,CAACG,YAAN,GAAqBgB,SAArB;IACA;EACD;;EACD,OAAOnB,KAAP;AACA"}
|
|
@@ -0,0 +1,46 @@
|
|
|
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"] = void 0;
|
|
9
|
+
|
|
10
|
+
var _ItemsContainer = _interopRequireDefault(require("./ItemsContainer.js"));
|
|
11
|
+
|
|
12
|
+
var _ScrollableContainer = _interopRequireWildcard(require("./ScrollableContainer.js"));
|
|
13
|
+
|
|
14
|
+
var _ListTopOffsetWatcher = _interopRequireDefault(require("./ListTopOffsetWatcher.js"));
|
|
15
|
+
|
|
16
|
+
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); }
|
|
17
|
+
|
|
18
|
+
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; }
|
|
19
|
+
|
|
20
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
|
21
|
+
|
|
22
|
+
var _default = {
|
|
23
|
+
createItemsContainer: function createItemsContainer(getItemsContainerElement) {
|
|
24
|
+
return new _ItemsContainer["default"](getItemsContainerElement);
|
|
25
|
+
},
|
|
26
|
+
// Creates a `scrollableContainer`.
|
|
27
|
+
// On client side, `scrollableContainer` is always created.
|
|
28
|
+
// On server side, `scrollableContainer` is not created (and not used).
|
|
29
|
+
createScrollableContainer: function createScrollableContainer(getScrollableContainerElement, getItemsContainerElement) {
|
|
30
|
+
if (getScrollableContainerElement) {
|
|
31
|
+
return new _ScrollableContainer["default"](getScrollableContainerElement, getItemsContainerElement);
|
|
32
|
+
} else if (typeof window !== 'undefined') {
|
|
33
|
+
return new _ScrollableContainer.ScrollableWindowContainer(getItemsContainerElement);
|
|
34
|
+
}
|
|
35
|
+
},
|
|
36
|
+
watchListTopOffset: function watchListTopOffset(_ref) {
|
|
37
|
+
var getListTopOffset = _ref.getListTopOffset,
|
|
38
|
+
onListTopOffsetChange = _ref.onListTopOffsetChange;
|
|
39
|
+
return new _ListTopOffsetWatcher["default"]({
|
|
40
|
+
getListTopOffset: getListTopOffset,
|
|
41
|
+
onListTopOffsetChange: onListTopOffsetChange
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
exports["default"] = _default;
|
|
46
|
+
//# sourceMappingURL=Engine.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Engine.js","names":["createItemsContainer","getItemsContainerElement","ItemsContainer","createScrollableContainer","getScrollableContainerElement","ScrollableContainer","window","ScrollableWindowContainer","watchListTopOffset","getListTopOffset","onListTopOffsetChange","ListTopOffsetWatcher"],"sources":["../../source/DOM/Engine.js"],"sourcesContent":["import ItemsContainer from './ItemsContainer.js'\r\nimport ScrollableContainer, { ScrollableWindowContainer } from './ScrollableContainer.js'\r\nimport ListTopOffsetWatcher from './ListTopOffsetWatcher.js'\r\n\r\nexport default {\r\n\tcreateItemsContainer(getItemsContainerElement) {\r\n\t\treturn new ItemsContainer(getItemsContainerElement)\r\n\t},\r\n\r\n\t// Creates a `scrollableContainer`.\r\n\t// On client side, `scrollableContainer` is always created.\r\n\t// On server side, `scrollableContainer` is not created (and not used).\r\n\tcreateScrollableContainer(getScrollableContainerElement, getItemsContainerElement) {\r\n\t\tif (getScrollableContainerElement) {\r\n\t\t\treturn new ScrollableContainer(getScrollableContainerElement, getItemsContainerElement)\r\n\t\t} else if (typeof window !== 'undefined') {\r\n\t\t\treturn new ScrollableWindowContainer(getItemsContainerElement)\r\n\t\t}\r\n\t},\r\n\r\n\twatchListTopOffset({\r\n\t\tgetListTopOffset,\r\n\t\tonListTopOffsetChange\r\n\t}) {\r\n\t\treturn new ListTopOffsetWatcher({\r\n\t\t\tgetListTopOffset,\r\n\t\t\tonListTopOffsetChange\r\n\t\t})\r\n\t}\r\n}"],"mappings":";;;;;;;;;AAAA;;AACA;;AACA;;;;;;;;eAEe;EACdA,oBADc,gCACOC,wBADP,EACiC;IAC9C,OAAO,IAAIC,0BAAJ,CAAmBD,wBAAnB,CAAP;EACA,CAHa;EAKd;EACA;EACA;EACAE,yBARc,qCAQYC,6BARZ,EAQ2CH,wBAR3C,EAQqE;IAClF,IAAIG,6BAAJ,EAAmC;MAClC,OAAO,IAAIC,+BAAJ,CAAwBD,6BAAxB,EAAuDH,wBAAvD,CAAP;IACA,CAFD,MAEO,IAAI,OAAOK,MAAP,KAAkB,WAAtB,EAAmC;MACzC,OAAO,IAAIC,8CAAJ,CAA8BN,wBAA9B,CAAP;IACA;EACD,CAda;EAgBdO,kBAhBc,oCAmBX;IAAA,IAFFC,gBAEE,QAFFA,gBAEE;IAAA,IADFC,qBACE,QADFA,qBACE;IACF,OAAO,IAAIC,gCAAJ,CAAyB;MAC/BF,gBAAgB,EAAhBA,gBAD+B;MAE/BC,qBAAqB,EAArBA;IAF+B,CAAzB,CAAP;EAIA;AAxBa,C"}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports["default"] = void 0;
|
|
7
|
+
|
|
8
|
+
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
9
|
+
|
|
10
|
+
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
|
|
11
|
+
|
|
12
|
+
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
|
13
|
+
|
|
14
|
+
var ItemsContainer = /*#__PURE__*/function () {
|
|
15
|
+
/**
|
|
16
|
+
* Constructs a new "container" from an element.
|
|
17
|
+
* @param {function} getElement
|
|
18
|
+
*/
|
|
19
|
+
function ItemsContainer(getElement) {
|
|
20
|
+
_classCallCheck(this, ItemsContainer);
|
|
21
|
+
|
|
22
|
+
this.getElement = getElement;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Returns an item element's "top offset", relative to the items `container`'s top edge.
|
|
26
|
+
* @param {number} renderedElementIndex — An index of an item relative to the "first shown item index". For example, if the list is showing items from index 8 to index 12 then `renderedElementIndex = 0` would mean the item at index `8`.
|
|
27
|
+
* @return {number}
|
|
28
|
+
*/
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
_createClass(ItemsContainer, [{
|
|
32
|
+
key: "getNthRenderedItemTopOffset",
|
|
33
|
+
value: function getNthRenderedItemTopOffset(renderedElementIndex) {
|
|
34
|
+
return this.getElement().childNodes[renderedElementIndex].getBoundingClientRect().top - this.getElement().getBoundingClientRect().top;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Returns an item element's height.
|
|
38
|
+
* @param {number} renderedElementIndex — An index of an item relative to the "first shown item index". For example, if the list is showing items from index 8 to index 12 then `renderedElementIndex = 0` would mean the item at index `8`.
|
|
39
|
+
* @return {number}
|
|
40
|
+
*/
|
|
41
|
+
|
|
42
|
+
}, {
|
|
43
|
+
key: "getNthRenderedItemHeight",
|
|
44
|
+
value: function getNthRenderedItemHeight(renderedElementIndex) {
|
|
45
|
+
// `offsetHeight` is not precise enough (doesn't return fractional pixels).
|
|
46
|
+
// return this.getElement().childNodes[renderedElementIndex].offsetHeight
|
|
47
|
+
return this.getElement().childNodes[renderedElementIndex].getBoundingClientRect().height;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Returns items container height.
|
|
51
|
+
* @return {number}
|
|
52
|
+
*/
|
|
53
|
+
|
|
54
|
+
}, {
|
|
55
|
+
key: "getHeight",
|
|
56
|
+
value: function getHeight() {
|
|
57
|
+
// `offsetHeight` is not precise enough (doesn't return fractional pixels).
|
|
58
|
+
// return this.getElement().offsetHeight
|
|
59
|
+
return this.getElement().getBoundingClientRect().height;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Removes all item elements of an items container.
|
|
63
|
+
*/
|
|
64
|
+
|
|
65
|
+
}, {
|
|
66
|
+
key: "clear",
|
|
67
|
+
value: function clear() {
|
|
68
|
+
while (this.getElement().firstChild) {
|
|
69
|
+
this.getElement().removeChild(this.getElement().firstChild);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
}]);
|
|
73
|
+
|
|
74
|
+
return ItemsContainer;
|
|
75
|
+
}();
|
|
76
|
+
|
|
77
|
+
exports["default"] = ItemsContainer;
|
|
78
|
+
//# sourceMappingURL=ItemsContainer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ItemsContainer.js","names":["ItemsContainer","getElement","renderedElementIndex","childNodes","getBoundingClientRect","top","height","firstChild","removeChild"],"sources":["../../source/DOM/ItemsContainer.js"],"sourcesContent":["export default class ItemsContainer {\r\n\t/**\r\n\t * Constructs a new \"container\" from an element.\r\n\t * @param {function} getElement\r\n\t */\r\n\tconstructor(getElement) {\r\n\t\tthis.getElement = getElement\r\n\t}\r\n\r\n\t/**\r\n\t * Returns an item element's \"top offset\", relative to the items `container`'s top edge.\r\n\t * @param {number} renderedElementIndex — An index of an item relative to the \"first shown item index\". For example, if the list is showing items from index 8 to index 12 then `renderedElementIndex = 0` would mean the item at index `8`.\r\n\t * @return {number}\r\n\t */\r\n\tgetNthRenderedItemTopOffset(renderedElementIndex) {\r\n\t\treturn this.getElement().childNodes[renderedElementIndex].getBoundingClientRect().top - this.getElement().getBoundingClientRect().top\r\n\t}\r\n\r\n\t/**\r\n\t * Returns an item element's height.\r\n\t * @param {number} renderedElementIndex — An index of an item relative to the \"first shown item index\". For example, if the list is showing items from index 8 to index 12 then `renderedElementIndex = 0` would mean the item at index `8`.\r\n\t * @return {number}\r\n\t */\r\n\tgetNthRenderedItemHeight(renderedElementIndex) {\r\n\t\t// `offsetHeight` is not precise enough (doesn't return fractional pixels).\r\n\t\t// return this.getElement().childNodes[renderedElementIndex].offsetHeight\r\n\t\treturn this.getElement().childNodes[renderedElementIndex].getBoundingClientRect().height\r\n\t}\r\n\r\n\t/**\r\n\t * Returns items container height.\r\n\t * @return {number}\r\n\t */\r\n\tgetHeight() {\r\n\t\t// `offsetHeight` is not precise enough (doesn't return fractional pixels).\r\n\t\t// return this.getElement().offsetHeight\r\n\t\treturn this.getElement().getBoundingClientRect().height\r\n\t}\r\n\r\n\t/**\r\n\t * Removes all item elements of an items container.\r\n\t */\r\n\tclear() {\r\n\t\twhile (this.getElement().firstChild) {\r\n\t\t\tthis.getElement().removeChild(this.getElement().firstChild)\r\n\t\t}\r\n\t}\r\n}"],"mappings":";;;;;;;;;;;;;IAAqBA,c;EACpB;AACD;AACA;AACA;EACC,wBAAYC,UAAZ,EAAwB;IAAA;;IACvB,KAAKA,UAAL,GAAkBA,UAAlB;EACA;EAED;AACD;AACA;AACA;AACA;;;;;WACC,qCAA4BC,oBAA5B,EAAkD;MACjD,OAAO,KAAKD,UAAL,GAAkBE,UAAlB,CAA6BD,oBAA7B,EAAmDE,qBAAnD,GAA2EC,GAA3E,GAAiF,KAAKJ,UAAL,GAAkBG,qBAAlB,GAA0CC,GAAlI;IACA;IAED;AACD;AACA;AACA;AACA;;;;WACC,kCAAyBH,oBAAzB,EAA+C;MAC9C;MACA;MACA,OAAO,KAAKD,UAAL,GAAkBE,UAAlB,CAA6BD,oBAA7B,EAAmDE,qBAAnD,GAA2EE,MAAlF;IACA;IAED;AACD;AACA;AACA;;;;WACC,qBAAY;MACX;MACA;MACA,OAAO,KAAKL,UAAL,GAAkBG,qBAAlB,GAA0CE,MAAjD;IACA;IAED;AACD;AACA;;;;WACC,iBAAQ;MACP,OAAO,KAAKL,UAAL,GAAkBM,UAAzB,EAAqC;QACpC,KAAKN,UAAL,GAAkBO,WAAlB,CAA8B,KAAKP,UAAL,GAAkBM,UAAhD;MACA;IACD"}
|