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
package/commonjs/Resize.js
CHANGED
|
@@ -5,9 +5,9 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports["default"] = void 0;
|
|
7
7
|
|
|
8
|
-
var
|
|
8
|
+
var _debounce = _interopRequireDefault(require("./utility/debounce.js"));
|
|
9
9
|
|
|
10
|
-
var
|
|
10
|
+
var _debug = _interopRequireDefault(require("./utility/debug.js"));
|
|
11
11
|
|
|
12
12
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
|
13
13
|
|
|
@@ -15,86 +15,97 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons
|
|
|
15
15
|
|
|
16
16
|
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); } }
|
|
17
17
|
|
|
18
|
-
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
|
|
18
|
+
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
|
19
19
|
|
|
20
20
|
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; }
|
|
21
21
|
|
|
22
|
-
var Resize =
|
|
23
|
-
/*#__PURE__*/
|
|
24
|
-
function () {
|
|
22
|
+
var Resize = /*#__PURE__*/function () {
|
|
25
23
|
function Resize(_ref) {
|
|
26
24
|
var _this = this;
|
|
27
25
|
|
|
28
26
|
var bypass = _ref.bypass,
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
27
|
+
getWidth = _ref.getWidth,
|
|
28
|
+
getHeight = _ref.getHeight,
|
|
29
|
+
listenForResize = _ref.listenForResize,
|
|
30
|
+
onResizeStart = _ref.onResizeStart,
|
|
31
|
+
onResizeStop = _ref.onResizeStop,
|
|
32
|
+
onHeightChange = _ref.onHeightChange,
|
|
33
|
+
onWidthChange = _ref.onWidthChange,
|
|
34
|
+
onNoChange = _ref.onNoChange;
|
|
33
35
|
|
|
34
36
|
_classCallCheck(this, Resize);
|
|
35
37
|
|
|
36
|
-
_defineProperty(this, "
|
|
38
|
+
_defineProperty(this, "_onResize", function () {
|
|
37
39
|
// If `VirtualScroller` has been unmounted
|
|
38
40
|
// while `debounce()`'s `setTimeout()` was waiting, then exit.
|
|
39
|
-
|
|
41
|
+
// If the `VirtualScroller` gets restarted later, it will detect
|
|
42
|
+
// that `state.scrollableContainerWidth` doesn't match the actual
|
|
43
|
+
// scrollable container width, and will call `this.onResize()`.
|
|
44
|
+
if (!_this.isActive) {
|
|
40
45
|
return;
|
|
41
46
|
}
|
|
42
47
|
|
|
43
|
-
var prevScrollableContainerWidth = _this.
|
|
44
|
-
var prevScrollableContainerHeight = _this.
|
|
45
|
-
_this.
|
|
46
|
-
_this.
|
|
48
|
+
var prevScrollableContainerWidth = _this.width;
|
|
49
|
+
var prevScrollableContainerHeight = _this.height;
|
|
50
|
+
_this.width = _this.getWidth();
|
|
51
|
+
_this.height = _this.getHeight();
|
|
47
52
|
|
|
48
|
-
if (_this.
|
|
49
|
-
if (_this.
|
|
53
|
+
if (_this.width === prevScrollableContainerWidth) {
|
|
54
|
+
if (_this.height === prevScrollableContainerHeight) {
|
|
50
55
|
// The dimensions of the container didn't change,
|
|
51
56
|
// so there's no need to re-layout anything.
|
|
52
|
-
|
|
57
|
+
_this.onNoChange();
|
|
53
58
|
} else {
|
|
54
59
|
// Scrollable container height has changed,
|
|
55
60
|
// so just recalculate shown item indexes.
|
|
56
61
|
// No need to perform a re-layout from scratch.
|
|
57
|
-
_this.
|
|
58
|
-
reason: _Layout.LAYOUT_REASON.RESIZE
|
|
59
|
-
});
|
|
62
|
+
_this.onHeightChange(prevScrollableContainerHeight, _this.height);
|
|
60
63
|
}
|
|
61
64
|
} else {
|
|
62
65
|
// Reset item heights, because if scrollable container's width (or height)
|
|
63
66
|
// has changed, then the list width (or height) most likely also has changed,
|
|
64
67
|
// and also some CSS `@media()` rules might have been added or removed.
|
|
65
68
|
// So re-render the list entirely.
|
|
66
|
-
_this.
|
|
69
|
+
_this.onWidthChange(prevScrollableContainerWidth, _this.width);
|
|
67
70
|
}
|
|
68
|
-
}
|
|
71
|
+
});
|
|
69
72
|
|
|
70
73
|
this.bypass = bypass;
|
|
71
|
-
this.
|
|
72
|
-
this.
|
|
73
|
-
this.
|
|
74
|
-
this.
|
|
74
|
+
this.onHeightChange = onHeightChange;
|
|
75
|
+
this.onWidthChange = onWidthChange;
|
|
76
|
+
this.onNoChange = onNoChange;
|
|
77
|
+
this.getWidth = getWidth;
|
|
78
|
+
this.getHeight = getHeight;
|
|
79
|
+
this.listenForResize = listenForResize;
|
|
80
|
+
this.onResize = (0, _debounce["default"])(this._onResize, SCROLLABLE_CONTAINER_RESIZE_DEBOUNCE_INTERVAL, {
|
|
81
|
+
onStart: onResizeStart,
|
|
82
|
+
onStop: onResizeStop
|
|
83
|
+
});
|
|
75
84
|
}
|
|
76
85
|
|
|
77
86
|
_createClass(Resize, [{
|
|
78
|
-
key: "
|
|
79
|
-
value: function
|
|
87
|
+
key: "start",
|
|
88
|
+
value: function start() {
|
|
89
|
+
this.isActive = true;
|
|
90
|
+
|
|
80
91
|
if (this.bypass) {
|
|
81
92
|
return;
|
|
82
93
|
}
|
|
83
94
|
|
|
84
|
-
this.
|
|
85
|
-
this.
|
|
86
|
-
this.
|
|
87
|
-
this.scrollableContainerUnlistenResize = this.scrollableContainer.onResize(this.onResize, {
|
|
88
|
-
container: this.getContainerElement()
|
|
89
|
-
});
|
|
95
|
+
this.width = this.getWidth();
|
|
96
|
+
this.height = this.getHeight();
|
|
97
|
+
this.unlistenResize = this.listenForResize(this.onResize);
|
|
90
98
|
}
|
|
91
99
|
}, {
|
|
92
100
|
key: "stop",
|
|
93
101
|
value: function stop() {
|
|
94
|
-
this.
|
|
102
|
+
this.isActive = false;
|
|
103
|
+
this.width = undefined;
|
|
104
|
+
this.height = undefined;
|
|
95
105
|
|
|
96
|
-
if (this.
|
|
97
|
-
this.
|
|
106
|
+
if (this.unlistenResize) {
|
|
107
|
+
this.unlistenResize();
|
|
108
|
+
this.unlistenResize = undefined;
|
|
98
109
|
}
|
|
99
110
|
}
|
|
100
111
|
/**
|
package/commonjs/Resize.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"Resize.js","names":["Resize","bypass","getWidth","getHeight","listenForResize","onResizeStart","onResizeStop","onHeightChange","onWidthChange","onNoChange","isActive","prevScrollableContainerWidth","width","prevScrollableContainerHeight","height","onResize","debounce","_onResize","SCROLLABLE_CONTAINER_RESIZE_DEBOUNCE_INTERVAL","onStart","onStop","unlistenResize","undefined"],"sources":["../source/Resize.js"],"sourcesContent":["import debounce from './utility/debounce.js'\r\nimport log from './utility/debug.js'\r\n\r\nexport default class Resize {\r\n\tconstructor({\r\n\t\tbypass,\r\n\t\tgetWidth,\r\n\t\tgetHeight,\r\n\t\tlistenForResize,\r\n\t\tonResizeStart,\r\n\t\tonResizeStop,\r\n\t\tonHeightChange,\r\n\t\tonWidthChange,\r\n\t\tonNoChange\r\n\t}) {\r\n\t\tthis.bypass = bypass\r\n\r\n\t\tthis.onHeightChange = onHeightChange\r\n\t\tthis.onWidthChange = onWidthChange\r\n\t\tthis.onNoChange = onNoChange\r\n\r\n\t\tthis.getWidth = getWidth\r\n\t\tthis.getHeight = getHeight\r\n\t\tthis.listenForResize = listenForResize\r\n\r\n\t\tthis.onResize = debounce(\r\n\t\t\tthis._onResize,\r\n\t\t\tSCROLLABLE_CONTAINER_RESIZE_DEBOUNCE_INTERVAL,\r\n\t\t\t{\r\n\t\t\t\tonStart: onResizeStart,\r\n\t\t\t\tonStop: onResizeStop\r\n\t\t\t}\r\n\t\t)\r\n\t}\r\n\r\n\tstart() {\r\n\t\tthis.isActive = true\r\n\t\tif (this.bypass) {\r\n\t\t\treturn\r\n\t\t}\r\n\t\tthis.width = this.getWidth()\r\n\t\tthis.height = this.getHeight()\r\n\t\tthis.unlistenResize = this.listenForResize(this.onResize)\r\n\t}\r\n\r\n\tstop() {\r\n\t\tthis.isActive = false\r\n\t\tthis.width = undefined\r\n\t\tthis.height = undefined\r\n\t\tif (this.unlistenResize) {\r\n\t\t\tthis.unlistenResize()\r\n\t\t\tthis.unlistenResize = undefined\r\n\t\t}\r\n\t}\r\n\r\n\t/**\r\n\t * On scrollable container resize.\r\n\t */\r\n\t_onResize = () => {\r\n\t\t// If `VirtualScroller` has been unmounted\r\n\t\t// while `debounce()`'s `setTimeout()` was waiting, then exit.\r\n\t\t// If the `VirtualScroller` gets restarted later, it will detect\r\n\t\t// that `state.scrollableContainerWidth` doesn't match the actual\r\n\t\t// scrollable container width, and will call `this.onResize()`.\r\n\t\tif (!this.isActive) {\r\n\t\t\treturn\r\n\t\t}\r\n\r\n\t\tconst prevScrollableContainerWidth = this.width\r\n\t\tconst prevScrollableContainerHeight = this.height\r\n\r\n\t\tthis.width = this.getWidth()\r\n\t\tthis.height = this.getHeight()\r\n\r\n\t\tif (this.width === prevScrollableContainerWidth) {\r\n\t\t\tif (this.height === prevScrollableContainerHeight) {\r\n\t\t\t\t// The dimensions of the container didn't change,\r\n\t\t\t\t// so there's no need to re-layout anything.\r\n\t\t\t\tthis.onNoChange()\r\n\t\t\t} else {\r\n\t\t\t\t// Scrollable container height has changed,\r\n\t\t\t\t// so just recalculate shown item indexes.\r\n\t\t\t\t// No need to perform a re-layout from scratch.\r\n\t\t\t\tthis.onHeightChange(prevScrollableContainerHeight, this.height)\r\n\t\t\t}\r\n\t\t} else {\r\n\t\t\t// Reset item heights, because if scrollable container's width (or height)\r\n\t\t\t// has changed, then the list width (or height) most likely also has changed,\r\n\t\t\t// and also some CSS `@media()` rules might have been added or removed.\r\n\t\t\t// So re-render the list entirely.\r\n\t\t\tthis.onWidthChange(prevScrollableContainerWidth, this.width)\r\n\t\t}\r\n\t}\r\n}\r\n\r\nconst SCROLLABLE_CONTAINER_RESIZE_DEBOUNCE_INTERVAL = 250"],"mappings":";;;;;;;AAAA;;AACA;;;;;;;;;;;;IAEqBA,M;EACpB,sBAUG;IAAA;;IAAA,IATFC,MASE,QATFA,MASE;IAAA,IARFC,QAQE,QARFA,QAQE;IAAA,IAPFC,SAOE,QAPFA,SAOE;IAAA,IANFC,eAME,QANFA,eAME;IAAA,IALFC,aAKE,QALFA,aAKE;IAAA,IAJFC,YAIE,QAJFA,YAIE;IAAA,IAHFC,cAGE,QAHFA,cAGE;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AKV,QAAL,EAAb;MACA,KAAKY,MAAL,GAAc,KAAKX,SAAL,EAAd;MACA,KAAKkB,cAAL,GAAsB,KAAKjB,eAAL,CAAqB,KAAKW,QAA1B,CAAtB;IACA;;;WAED,gBAAO;MACN,KAAKL,QAAL,GAAgB,KAAhB;MACA,KAAKE,KAAL,GAAaU,SAAb;MACA,KAAKR,MAAL,GAAcQ,SAAd;;MACA,IAAI,KAAKD,cAAT,EAAyB;QACxB,KAAKA,cAAL;QACA,KAAKA,cAAL,GAAsBC,SAAtB;MACA;IACD;IAED;AACD;AACA;;;;;;;;AAsCA,IAAMJ,6CAA6C,GAAG,GAAtD"}
|
package/commonjs/Scroll.js
CHANGED
|
@@ -7,9 +7,7 @@ exports["default"] = void 0;
|
|
|
7
7
|
|
|
8
8
|
var _requestAnimationFrameTimeout = require("request-animation-frame-timeout");
|
|
9
9
|
|
|
10
|
-
var
|
|
11
|
-
|
|
12
|
-
var _debug = _interopRequireDefault(require("./utility/debug"));
|
|
10
|
+
var _debug = _interopRequireDefault(require("./utility/debug.js"));
|
|
13
11
|
|
|
14
12
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
|
15
13
|
|
|
@@ -17,179 +15,225 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons
|
|
|
17
15
|
|
|
18
16
|
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); } }
|
|
19
17
|
|
|
20
|
-
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
|
|
18
|
+
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
|
21
19
|
|
|
22
20
|
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; }
|
|
23
21
|
|
|
24
|
-
var Scroll =
|
|
25
|
-
/*#__PURE__*/
|
|
26
|
-
function () {
|
|
22
|
+
var Scroll = /*#__PURE__*/function () {
|
|
27
23
|
function Scroll(_ref) {
|
|
28
24
|
var _this = this;
|
|
29
25
|
|
|
30
26
|
var bypass = _ref.bypass,
|
|
31
27
|
scrollableContainer = _ref.scrollableContainer,
|
|
32
|
-
|
|
28
|
+
itemsContainer = _ref.itemsContainer,
|
|
29
|
+
onScroll = _ref.onScroll,
|
|
33
30
|
initialScrollPosition = _ref.initialScrollPosition,
|
|
34
31
|
onScrollPositionChange = _ref.onScrollPositionChange,
|
|
35
32
|
isImmediateLayoutScheduled = _ref.isImmediateLayoutScheduled,
|
|
36
33
|
hasNonRenderedItemsAtTheTop = _ref.hasNonRenderedItemsAtTheTop,
|
|
37
34
|
hasNonRenderedItemsAtTheBottom = _ref.hasNonRenderedItemsAtTheBottom,
|
|
38
|
-
|
|
39
|
-
|
|
35
|
+
getLatestLayoutVisibleArea = _ref.getLatestLayoutVisibleArea,
|
|
36
|
+
getListTopOffset = _ref.getListTopOffset,
|
|
37
|
+
getPrerenderMargin = _ref.getPrerenderMargin,
|
|
38
|
+
onScrolledToTop = _ref.onScrolledToTop,
|
|
39
|
+
waitForScrollingToStop = _ref.waitForScrollingToStop;
|
|
40
40
|
|
|
41
41
|
_classCallCheck(this, Scroll);
|
|
42
42
|
|
|
43
|
-
_defineProperty(this, "
|
|
44
|
-
_this.
|
|
43
|
+
_defineProperty(this, "scrollByY", function (scrollByY) {
|
|
44
|
+
_this.scrollToY(_this.getScrollY() + scrollByY);
|
|
45
45
|
});
|
|
46
46
|
|
|
47
|
-
_defineProperty(this, "
|
|
48
|
-
|
|
47
|
+
_defineProperty(this, "onScrollListener", function () {
|
|
48
|
+
if (_this.onScrollPositionChange) {
|
|
49
|
+
_this.onScrollPositionChange(_this.getScrollY());
|
|
50
|
+
} // If the user has scrolled up to the top of the items container.
|
|
51
|
+
// (this option isn't currently used)
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
if (_this.onScrolledToTop) {
|
|
55
|
+
if (_this.getScrollY() < _this.getListTopOffset()) {
|
|
56
|
+
_this.onScrolledToTop();
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
if (_this.bypass) {
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
if (_this.ignoreScrollEvents) {
|
|
65
|
+
return;
|
|
66
|
+
} // Prefer not performing a re-layout while the user is scrolling (if possible).
|
|
49
67
|
// If the user doesn't scroll too far and then stops for a moment,
|
|
50
68
|
// then a mid-scroll re-layout could be delayed until such a brief stop:
|
|
51
69
|
// presumably, this results in better (smoother) scrolling performance,
|
|
52
70
|
// delaying the work to when it doesn't introduce any stutter or "jank".
|
|
53
|
-
// Reset `this.
|
|
54
|
-
|
|
55
|
-
|
|
71
|
+
// Reset `this.onStopScrollingTimer` (will be re-created below).
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
_this.cancelOnStopScrollingTimer(); // See if the latest "layout" (the currently rendered set of items)
|
|
75
|
+
// is still sufficient in order to show all the items that're
|
|
76
|
+
// currently inside the viewport. If there're some non-rendered items
|
|
77
|
+
// that're visible in the current viewport, then those items
|
|
78
|
+
// should be rendered "immediately" rather than waiting until
|
|
79
|
+
// the user stops scrolling.
|
|
56
80
|
|
|
57
81
|
|
|
58
82
|
var forceUpdate = // If the items have been rendered at least once
|
|
59
|
-
_this.
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
83
|
+
_this.getLatestLayoutVisibleArea() && ( // If the user has scrolled up past the "prerender margin"
|
|
84
|
+
// and there're some non-rendered items at the top,
|
|
85
|
+
// then force a re-layout.
|
|
86
|
+
//
|
|
87
|
+
// (during these calculations we assume that the list's top coordinate
|
|
88
|
+
// hasn't changed since previous layout; even if that's not exactly true,
|
|
89
|
+
// the items will be re-layout when the user stops scrolling anyway)
|
|
90
|
+
//
|
|
91
|
+
_this.getScrollY() < _this.getLatestLayoutVisibleArea().top - _this.getPrerenderMargin() && _this.hasNonRenderedItemsAtTheTop() || // If the user has scrolled down past the "prerender margin"
|
|
92
|
+
// and there're any non-rendered items left at the end,
|
|
93
|
+
// then force a re-layout.
|
|
94
|
+
//
|
|
95
|
+
// (during these calculations we assume that the list's top coordinate
|
|
96
|
+
// hasn't changed since previous layout; even if that's not exactly true,
|
|
97
|
+
// the items will be re-layout when the user stops scrolling anyway)
|
|
98
|
+
//
|
|
99
|
+
_this.getScrollY() + _this.scrollableContainer.getHeight() > _this.getLatestLayoutVisibleArea().bottom + _this.getPrerenderMargin() && _this.hasNonRenderedItemsAtTheBottom());
|
|
64
100
|
|
|
65
101
|
if (forceUpdate) {
|
|
66
|
-
(0, _debug["default"])('The user has scrolled far enough:
|
|
102
|
+
(0, _debug["default"])('The user has scrolled far enough: perform a re-layout');
|
|
67
103
|
} else {
|
|
68
|
-
(0, _debug["default"])('The user
|
|
104
|
+
(0, _debug["default"])('The user is scrolling: perform a re-layout when they stop scrolling');
|
|
69
105
|
}
|
|
70
106
|
|
|
71
|
-
if (
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
return;
|
|
76
|
-
}
|
|
107
|
+
if (forceUpdate || _this.waitForScrollingToStop === false) {
|
|
108
|
+
return _this.onScroll();
|
|
109
|
+
} // If a re-layout is already scheduled at the next "frame",
|
|
110
|
+
// don't schedule a "re-layout when user stops scrolling" timer.
|
|
77
111
|
|
|
78
|
-
_this.onUserStopsScrollingTimer = (0, _requestAnimationFrameTimeout.setTimeout)(function () {
|
|
79
|
-
_this.onUserStopsScrollingTimer = undefined;
|
|
80
112
|
|
|
81
|
-
|
|
82
|
-
reason: _Layout.LAYOUT_REASON.STOPPED_SCROLLING
|
|
83
|
-
});
|
|
84
|
-
}, // "scroll" events are usually dispatched every 16 milliseconds
|
|
85
|
-
// for 60fps refresh rate, so waiting for 100 milliseconds feels
|
|
86
|
-
// reasonable: that would be about 6 frames of inactivity period,
|
|
87
|
-
// which could mean that either the user has stopped scrolling
|
|
88
|
-
// (for a moment) or the browser is lagging and stuttering
|
|
89
|
-
// (skipping frames due to high load).
|
|
90
|
-
// If the user continues scrolling then this timeout is constantly
|
|
91
|
-
// refreshed (cancelled and then re-created).
|
|
92
|
-
WAIT_FOR_USER_TO_STOP_SCROLLING_TIMEOUT);
|
|
113
|
+
if (_this.isImmediateLayoutScheduled()) {
|
|
93
114
|
return;
|
|
94
115
|
}
|
|
95
116
|
|
|
96
|
-
_this.
|
|
97
|
-
|
|
98
|
-
|
|
117
|
+
_this.shouldCallOnScrollListenerWhenStopsScrolling = true;
|
|
118
|
+
|
|
119
|
+
_this.watchOnStopScrolling();
|
|
99
120
|
});
|
|
100
121
|
|
|
101
122
|
this.bypass = bypass;
|
|
102
123
|
this.scrollableContainer = scrollableContainer;
|
|
103
|
-
this.
|
|
124
|
+
this.itemsContainer = itemsContainer;
|
|
125
|
+
this.onScroll = onScroll;
|
|
104
126
|
this.initialScrollPosition = initialScrollPosition;
|
|
105
127
|
this.onScrollPositionChange = onScrollPositionChange;
|
|
106
128
|
this.isImmediateLayoutScheduled = isImmediateLayoutScheduled;
|
|
107
129
|
this.hasNonRenderedItemsAtTheTop = hasNonRenderedItemsAtTheTop;
|
|
108
130
|
this.hasNonRenderedItemsAtTheBottom = hasNonRenderedItemsAtTheBottom;
|
|
109
|
-
this.
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
scrollableContainerContentHeight: scrollableContainer.getContentHeight()
|
|
115
|
-
};
|
|
116
|
-
}
|
|
117
|
-
}
|
|
131
|
+
this.getLatestLayoutVisibleArea = getLatestLayoutVisibleArea;
|
|
132
|
+
this.getListTopOffset = getListTopOffset;
|
|
133
|
+
this.getPrerenderMargin = getPrerenderMargin;
|
|
134
|
+
this.onScrolledToTop = onScrolledToTop;
|
|
135
|
+
this.waitForScrollingToStop = waitForScrollingToStop;
|
|
118
136
|
}
|
|
119
137
|
|
|
120
138
|
_createClass(Scroll, [{
|
|
121
|
-
key: "
|
|
122
|
-
value: function
|
|
139
|
+
key: "start",
|
|
140
|
+
value: function start() {
|
|
123
141
|
if (this.initialScrollPosition !== undefined) {
|
|
124
142
|
this.scrollToY(this.initialScrollPosition);
|
|
143
|
+
this.initialScrollPosition = undefined;
|
|
125
144
|
}
|
|
126
145
|
|
|
127
146
|
if (this.onScrollPositionChange) {
|
|
128
|
-
this.
|
|
129
|
-
this.removeScrollPositionListener = this.scrollableContainer.addScrollListener(this.updateScrollPosition);
|
|
147
|
+
this.onScrollPositionChange(this.getScrollY());
|
|
130
148
|
}
|
|
131
149
|
|
|
132
|
-
|
|
133
|
-
this.removeScrollListener = this.scrollableContainer.addScrollListener(this.onScroll);
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
if (this.preserveScrollPositionOfTheBottomOfTheListOnMount) {
|
|
137
|
-
this.scrollToY(this.getScrollY() + (this.scrollableContainer.getContentHeight() - this.preserveScrollPositionOfTheBottomOfTheListOnMount.scrollableContainerContentHeight));
|
|
138
|
-
}
|
|
150
|
+
this.stopListeningToScroll = this.scrollableContainer.onScroll(this.onScrollListener);
|
|
139
151
|
}
|
|
140
152
|
}, {
|
|
141
153
|
key: "stop",
|
|
142
154
|
value: function stop() {
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
if (this.removeScrollListener) {
|
|
148
|
-
this.removeScrollListener();
|
|
149
|
-
}
|
|
155
|
+
this.stopListeningToScroll();
|
|
156
|
+
this.stopListeningToScroll = undefined; // this.onStopScrollingListener = undefined
|
|
150
157
|
|
|
151
|
-
this.
|
|
158
|
+
this.shouldCallOnScrollListenerWhenStopsScrolling = undefined;
|
|
159
|
+
this.cancelOnStopScrollingTimer();
|
|
152
160
|
}
|
|
153
161
|
}, {
|
|
154
162
|
key: "scrollToY",
|
|
155
163
|
value: function scrollToY(scrollY) {
|
|
164
|
+
this.ignoreScrollEvents = true;
|
|
156
165
|
this.scrollableContainer.scrollToY(scrollY);
|
|
157
|
-
|
|
158
|
-
}, {
|
|
159
|
-
key: "scrollByY",
|
|
160
|
-
value: function scrollByY(_scrollByY) {
|
|
161
|
-
this.scrollToY(this.getScrollY() + _scrollByY);
|
|
166
|
+
this.ignoreScrollEvents = undefined;
|
|
162
167
|
}
|
|
163
168
|
}, {
|
|
164
169
|
key: "getScrollY",
|
|
165
170
|
value: function getScrollY() {
|
|
166
171
|
return this.scrollableContainer.getScrollY();
|
|
167
172
|
}
|
|
168
|
-
/**
|
|
169
|
-
* Updates the current scroll Y position in state.
|
|
170
|
-
*/
|
|
171
|
-
|
|
172
173
|
}, {
|
|
173
|
-
key: "
|
|
174
|
-
value: function
|
|
175
|
-
if (this.
|
|
176
|
-
(0, _requestAnimationFrameTimeout.clearTimeout)(this.
|
|
177
|
-
this.
|
|
174
|
+
key: "cancelOnStopScrollingTimer",
|
|
175
|
+
value: function cancelOnStopScrollingTimer() {
|
|
176
|
+
if (this.onStopScrollingTimer) {
|
|
177
|
+
(0, _requestAnimationFrameTimeout.clearTimeout)(this.onStopScrollingTimer);
|
|
178
|
+
this.onStopScrollingTimer = undefined;
|
|
178
179
|
}
|
|
179
180
|
}
|
|
180
181
|
}, {
|
|
181
|
-
key: "
|
|
182
|
-
value: function
|
|
182
|
+
key: "cancelScheduledLayout",
|
|
183
|
+
value: function cancelScheduledLayout() {
|
|
183
184
|
// Cancel a "re-layout when user stops scrolling" timer.
|
|
184
|
-
this.
|
|
185
|
+
this.cancelOnStopScrollingTimer();
|
|
185
186
|
}
|
|
186
187
|
}, {
|
|
187
|
-
key: "
|
|
188
|
+
key: "watchOnStopScrolling",
|
|
189
|
+
value: function watchOnStopScrolling() {
|
|
190
|
+
var _this2 = this;
|
|
191
|
+
|
|
192
|
+
this.onStopScrollingTimer = (0, _requestAnimationFrameTimeout.setTimeout)(function () {
|
|
193
|
+
_this2.onStopScrollingTimer = undefined;
|
|
194
|
+
|
|
195
|
+
if (_this2.shouldCallOnScrollListenerWhenStopsScrolling) {
|
|
196
|
+
_this2.shouldCallOnScrollListenerWhenStopsScrolling = undefined;
|
|
197
|
+
|
|
198
|
+
_this2.onScroll({
|
|
199
|
+
delayed: true
|
|
200
|
+
});
|
|
201
|
+
} // `onStopScrolling()` feature is not currently used.
|
|
202
|
+
// if (this.onStopScrollingListener) {
|
|
203
|
+
// const onStopScrollingListener = this.onStopScrollingListener
|
|
204
|
+
// this.onStopScrollingListener = undefined
|
|
205
|
+
// // `onStopScrollingListener()` may hypothetically schedule
|
|
206
|
+
// // another `onStopScrolling()` listener, so set
|
|
207
|
+
// // `this.onStopScrollingListener` to `undefined` before
|
|
208
|
+
// // calling it rather than after.
|
|
209
|
+
// log('~ The user has stopped scrolling ~')
|
|
210
|
+
// onStopScrollingListener()
|
|
211
|
+
// }
|
|
212
|
+
|
|
213
|
+
}, // "scroll" events are usually dispatched every 16 milliseconds
|
|
214
|
+
// for 60fps refresh rate, so waiting for 100 milliseconds feels
|
|
215
|
+
// reasonable: that would be about 6 frames of inactivity period,
|
|
216
|
+
// which could mean that either the user has stopped scrolling
|
|
217
|
+
// (for a moment) or the browser is lagging and stuttering
|
|
218
|
+
// (skipping frames due to high load).
|
|
219
|
+
// If the user continues scrolling then this timeout is constantly
|
|
220
|
+
// refreshed (cancelled and then re-created).
|
|
221
|
+
ON_STOP_SCROLLING_INACTIVE_PERIOD);
|
|
222
|
+
} // (this function isn't currently used)
|
|
223
|
+
// onStopScrolling(onStopScrollingListener) {
|
|
224
|
+
// this.onStopScrollingListener = onStopScrollingListener
|
|
225
|
+
// if (!this.onStopScrollingTimer) {
|
|
226
|
+
// this.watchOnStopScrolling()
|
|
227
|
+
// }
|
|
228
|
+
// }
|
|
188
229
|
|
|
189
230
|
/**
|
|
190
231
|
* Returns visible area coordinates relative to the scrollable container.
|
|
191
232
|
* @return {object} `{ top: number, bottom: number }`
|
|
192
233
|
*/
|
|
234
|
+
|
|
235
|
+
}, {
|
|
236
|
+
key: "getVisibleAreaBounds",
|
|
193
237
|
value: function getVisibleAreaBounds() {
|
|
194
238
|
var scrollY = this.getScrollY();
|
|
195
239
|
return {
|
|
@@ -205,5 +249,5 @@ function () {
|
|
|
205
249
|
}();
|
|
206
250
|
|
|
207
251
|
exports["default"] = Scroll;
|
|
208
|
-
var
|
|
252
|
+
var ON_STOP_SCROLLING_INACTIVE_PERIOD = 100;
|
|
209
253
|
//# sourceMappingURL=Scroll.js.map
|
package/commonjs/Scroll.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../source/Scroll.js"],"names":["Scroll","bypass","scrollableContainer","updateLayout","initialScrollPosition","onScrollPositionChange","isImmediateLayoutScheduled","hasNonRenderedItemsAtTheTop","hasNonRenderedItemsAtTheBottom","getLatestLayoutVisibleAreaIncludingMargins","preserveScrollPositionOfTheBottomOfTheListOnMount","getScrollY","cancelOnUserStopsScrollingTimer","forceUpdate","top","getHeight","bottom","onUserStopsScrollingTimer","undefined","reason","LAYOUT_REASON","STOPPED_SCROLLING","WAIT_FOR_USER_TO_STOP_SCROLLING_TIMEOUT","SCROLL","scrollableContainerContentHeight","getContentHeight","scrollToY","updateScrollPosition","removeScrollPositionListener","addScrollListener","removeScrollListener","onScroll","scrollY","scrollByY"],"mappings":";;;;;;;AAIA;;AAEA;;AACA;;;;;;;;;;;;IAEqBA,M;;;AACpB,wBAWG;AAAA;;AAAA,QAVFC,MAUE,QAVFA,MAUE;AAAA,QATFC,mBASE,QATFA,mBASE;AAAA,QARFC,YAQE,QARFA,YAQE;AAAA,QAPFC,qBAOE,QAPFA,qBAOE;AAAA,QANFC,sBAME,QANFA,sBAME;AAAA,QALFC,0BAKE,QALFA,0BAKE;AAAA,QAJFC,2BAIE,QAJFA,2BAI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;AAClB,WAAK9B,mBAAL,CAAyBwB,SAAzB,CAAmCM,OAAnC;AACA;;;8BAESC,U,EAAW;AACpB,WAAKP,SAAL,CAAe,KAAKf,UAAL,KAAoBsB,UAAnC;AACA;;;iCAEY;AACZ,aAAO,KAAK/B,mBAAL,CAAyBS,UAAzB,EAAP;AACA;AAED;;;;;;sDAOkC;AACjC,UAAI,KAAKM,yBAAT,EAAoC;AACnC,wDAAa,KAAKA,yBAAlB;AACA,aAAKA,yBAAL,GAAiCC,SAAjC;AACA;AACD;;;+BAEU;AACV;AACA,WAAKN,+BAAL;AACA;;;;AAiED;;;;2CAIuB;AACtB,UAAMoB,OAAO,GAAG,KAAKrB,UAAL,EAAhB;AACA,aAAO;AACN;AACAG,QAAAA,GAAG,EAAEkB,OAFC;AAGN;AACAhB,QAAAA,MAAM,EAAEgB,OAAO,GAAG,KAAK9B,mBAAL,CAAyBa,SAAzB;AAJZ,OAAP;AAMA;;;;;;;AAGF,IAAMO,uCAAuC,GAAG,GAAhD","sourcesContent":["// For some weird reason, in Chrome, `setTimeout()` would lag up to a second (or more) behind.\r\n// Turns out, Chrome developers have deprecated `setTimeout()` API entirely without asking anyone.\r\n// Replacing `setTimeout()` with `requestAnimationFrame()` can work around that Chrome bug.\r\n// https://github.com/bvaughn/react-virtualized/issues/722\r\nimport { setTimeout, clearTimeout } from 'request-animation-frame-timeout'\r\n\r\nimport { LAYOUT_REASON } from './Layout'\r\nimport log from './utility/debug'\r\n\r\nexport default class Scroll {\r\n\tconstructor({\r\n\t\tbypass,\r\n\t\tscrollableContainer,\r\n\t\tupdateLayout,\r\n\t\tinitialScrollPosition,\r\n\t\tonScrollPositionChange,\r\n\t\tisImmediateLayoutScheduled,\r\n\t\thasNonRenderedItemsAtTheTop,\r\n\t\thasNonRenderedItemsAtTheBottom,\r\n\t\tgetLatestLayoutVisibleAreaIncludingMargins,\r\n\t\tpreserveScrollPositionOfTheBottomOfTheListOnMount\r\n\t}) {\r\n\t\tthis.bypass = bypass\r\n\t\tthis.scrollableContainer = scrollableContainer\r\n\t\tthis.updateLayout = updateLayout\r\n\t\tthis.initialScrollPosition = initialScrollPosition\r\n\t\tthis.onScrollPositionChange = onScrollPositionChange\r\n\t\tthis.isImmediateLayoutScheduled = isImmediateLayoutScheduled\r\n\t\tthis.hasNonRenderedItemsAtTheTop = hasNonRenderedItemsAtTheTop\r\n\t\tthis.hasNonRenderedItemsAtTheBottom = hasNonRenderedItemsAtTheBottom\r\n\t\tthis.getLatestLayoutVisibleAreaIncludingMargins = getLatestLayoutVisibleAreaIncludingMargins\r\n\r\n\t\tif (preserveScrollPositionOfTheBottomOfTheListOnMount) {\r\n\t\t\tif (scrollableContainer) {\r\n\t\t\t\tthis.preserveScrollPositionOfTheBottomOfTheListOnMount = {\r\n\t\t\t\t\tscrollableContainerContentHeight: scrollableContainer.getContentHeight()\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\r\n\tlisten() {\r\n\t\tif (this.initialScrollPosition !== undefined) {\r\n\t\t\tthis.scrollToY(this.initialScrollPosition)\r\n\t\t}\r\n\t\tif (this.onScrollPositionChange) {\r\n\t\t\tthis.updateScrollPosition()\r\n\t\t\tthis.removeScrollPositionListener = this.scrollableContainer.addScrollListener(this.updateScrollPosition)\r\n\t\t}\r\n\t\tif (!this.bypass) {\r\n\t\t\tthis.removeScrollListener = this.scrollableContainer.addScrollListener(this.onScroll)\r\n\t\t}\r\n\t\tif (this.preserveScrollPositionOfTheBottomOfTheListOnMount) {\r\n\t\t\tthis.scrollToY(this.getScrollY() + (this.scrollableContainer.getContentHeight() - this.preserveScrollPositionOfTheBottomOfTheListOnMount.scrollableContainerContentHeight))\r\n\t\t}\r\n\t}\r\n\r\n\tstop() {\r\n\t\tif (this.removeScrollPositionListener) {\r\n\t\t\tthis.removeScrollPositionListener()\r\n\t\t}\r\n\t\tif (this.removeScrollListener) {\r\n\t\t\tthis.removeScrollListener()\r\n\t\t}\r\n\t\tthis.cancelOnUserStopsScrollingTimer()\r\n\t}\r\n\r\n\tscrollToY(scrollY) {\r\n\t\tthis.scrollableContainer.scrollToY(scrollY)\r\n\t}\r\n\r\n\tscrollByY(scrollByY) {\r\n\t\tthis.scrollToY(this.getScrollY() + scrollByY)\r\n\t}\r\n\r\n\tgetScrollY() {\r\n\t\treturn this.scrollableContainer.getScrollY()\r\n\t}\r\n\r\n\t/**\r\n\t * Updates the current scroll Y position in state.\r\n\t */\r\n\tupdateScrollPosition = () => {\r\n\t\tthis.onScrollPositionChange(this.getScrollY())\r\n\t}\r\n\r\n\tcancelOnUserStopsScrollingTimer() {\r\n\t\tif (this.onUserStopsScrollingTimer) {\r\n\t\t\tclearTimeout(this.onUserStopsScrollingTimer)\r\n\t\t\tthis.onUserStopsScrollingTimer = undefined\r\n\t\t}\r\n\t}\r\n\r\n\tonLayout() {\r\n\t\t// Cancel a \"re-layout when user stops scrolling\" timer.\r\n\t\tthis.cancelOnUserStopsScrollingTimer()\r\n\t}\r\n\r\n\tonScroll = () => {\r\n\t\t// Prefer not performing a re-layout while the user is scrolling (if possible).\r\n\t\t// If the user doesn't scroll too far and then stops for a moment,\r\n\t\t// then a mid-scroll re-layout could be delayed until such a brief stop:\r\n\t\t// presumably, this results in better (smoother) scrolling performance,\r\n\t\t// delaying the work to when it doesn't introduce any stutter or \"jank\".\r\n\r\n\t\t// Reset `this.onUserStopsScrollingTimer` (will be re-created below).\r\n\t\tthis.cancelOnUserStopsScrollingTimer()\r\n\r\n\t\t// See whether rendering \"new\" previous/next items is required\r\n\t\t// right now, or it can wait until the user stops scrolling.\r\n\t\tconst forceUpdate =\r\n\t\t\t// If the items have been rendered at least once\r\n\t\t\tthis.getLatestLayoutVisibleAreaIncludingMargins() && (\r\n\t\t\t\t(\r\n\t\t\t\t\t// If the user has scrolled up past the extra \"margin\"\r\n\t\t\t\t\t(this.getScrollY() < this.getLatestLayoutVisibleAreaIncludingMargins().top) &&\r\n\t\t\t\t\t// and if there're any previous non-rendered items to render.\r\n\t\t\t\t\tthis.hasNonRenderedItemsAtTheTop()\r\n\t\t\t\t)\r\n\t\t\t\t||\r\n\t\t\t\t(\r\n\t\t\t\t\t// If the user has scrolled down past the extra \"margin\"\r\n\t\t\t\t\t(this.getScrollY() + this.scrollableContainer.getHeight() > this.getLatestLayoutVisibleAreaIncludingMargins().bottom) &&\r\n\t\t\t\t\t// and if there're any next non-rendered items to render.\r\n\t\t\t\t\tthis.hasNonRenderedItemsAtTheBottom()\r\n\t\t\t\t)\r\n\t\t\t)\r\n\r\n\t\tif (forceUpdate) {\r\n\t\t\tlog('The user has scrolled far enough: force re-layout')\r\n\t\t} else {\r\n\t\t\tlog('The user hasn\\'t scrolled too much: delay re-layout')\r\n\t\t}\r\n\r\n\t\tif (!forceUpdate) {\r\n\t\t\t// If a re-layout is already scheduled at the next \"frame\",\r\n\t\t\t// don't schedule a \"re-layout when user stops scrolling\" timer.\r\n\t\t\tif (this.isImmediateLayoutScheduled()) {\r\n\t\t\t\treturn\r\n\t\t\t}\r\n\t\t\tthis.onUserStopsScrollingTimer = setTimeout(\r\n\t\t\t\t() => {\r\n\t\t\t\t\tthis.onUserStopsScrollingTimer = undefined\r\n\t\t\t\t\tthis.updateLayout({ reason: LAYOUT_REASON.STOPPED_SCROLLING })\r\n\t\t\t\t},\r\n\t\t\t\t// \"scroll\" events are usually dispatched every 16 milliseconds\r\n\t\t\t\t// for 60fps refresh rate, so waiting for 100 milliseconds feels\r\n\t\t\t\t// reasonable: that would be about 6 frames of inactivity period,\r\n\t\t\t\t// which could mean that either the user has stopped scrolling\r\n\t\t\t\t// (for a moment) or the browser is lagging and stuttering\r\n\t\t\t\t// (skipping frames due to high load).\r\n\t\t\t\t// If the user continues scrolling then this timeout is constantly\r\n\t\t\t\t// refreshed (cancelled and then re-created).\r\n\t\t\t\tWAIT_FOR_USER_TO_STOP_SCROLLING_TIMEOUT\r\n\t\t\t)\r\n\t\t\treturn\r\n\t\t}\r\n\r\n\t\tthis.updateLayout({ reason: LAYOUT_REASON.SCROLL })\r\n\t}\r\n\r\n\t/**\r\n\t * Returns visible area coordinates relative to the scrollable container.\r\n\t * @return {object} `{ top: number, bottom: number }`\r\n\t */\r\n\tgetVisibleAreaBounds() {\r\n\t\tconst scrollY = this.getScrollY()\r\n\t\treturn {\r\n\t\t\t// The first pixel of the screen.\r\n\t\t\ttop: scrollY,\r\n\t\t\t// The pixel after the last pixel of the screen.\r\n\t\t\tbottom: scrollY + this.scrollableContainer.getHeight()\r\n\t\t}\r\n\t}\r\n}\r\n\r\nconst WAIT_FOR_USER_TO_STOP_SCROLLING_TIMEOUT = 100"],"file":"Scroll.js"}
|
|
1
|
+
{"version":3,"file":"Scroll.js","names":["Scroll","bypass","scrollableContainer","itemsContainer","onScroll","initialScrollPosition","onScrollPositionChange","isImmediateLayoutScheduled","hasNonRenderedItemsAtTheTop","hasNonRenderedItemsAtTheBottom","getLatestLayoutVisibleArea","getListTopOffset","getPrerenderMargin","onScrolledToTop","waitForScrollingToStop","scrollByY","scrollToY","getScrollY","ignoreScrollEvents","cancelOnStopScrollingTimer","forceUpdate","top","getHeight","bottom","log","shouldCallOnScrollListenerWhenStopsScrolling","watchOnStopScrolling","undefined","stopListeningToScroll","onScrollListener","scrollY","onStopScrollingTimer","clearTimeout","setTimeout","delayed","ON_STOP_SCROLLING_INACTIVE_PERIOD"],"sources":["../source/Scroll.js"],"sourcesContent":["// For some weird reason, in Chrome, `setTimeout()` would lag up to a second (or more) behind.\r\n// Turns out, Chrome developers have deprecated `setTimeout()` API entirely without asking anyone.\r\n// Replacing `setTimeout()` with `requestAnimationFrame()` can work around that Chrome bug.\r\n// https://github.com/bvaughn/react-virtualized/issues/722\r\nimport { setTimeout, clearTimeout } from 'request-animation-frame-timeout'\r\n\r\nimport log from './utility/debug.js'\r\n\r\nexport default class Scroll {\r\n\tconstructor({\r\n\t\tbypass,\r\n\t\tscrollableContainer,\r\n\t\titemsContainer,\r\n\t\tonScroll,\r\n\t\tinitialScrollPosition,\r\n\t\tonScrollPositionChange,\r\n\t\tisImmediateLayoutScheduled,\r\n\t\thasNonRenderedItemsAtTheTop,\r\n\t\thasNonRenderedItemsAtTheBottom,\r\n\t\tgetLatestLayoutVisibleArea,\r\n\t\tgetListTopOffset,\r\n\t\tgetPrerenderMargin,\r\n\t\tonScrolledToTop,\r\n\t\twaitForScrollingToStop\r\n\t}) {\r\n\t\tthis.bypass = bypass\r\n\t\tthis.scrollableContainer = scrollableContainer\r\n\t\tthis.itemsContainer = itemsContainer\r\n\t\tthis.onScroll = onScroll\r\n\t\tthis.initialScrollPosition = initialScrollPosition\r\n\t\tthis.onScrollPositionChange = onScrollPositionChange\r\n\t\tthis.isImmediateLayoutScheduled = isImmediateLayoutScheduled\r\n\t\tthis.hasNonRenderedItemsAtTheTop = hasNonRenderedItemsAtTheTop\r\n\t\tthis.hasNonRenderedItemsAtTheBottom = hasNonRenderedItemsAtTheBottom\r\n\t\tthis.getLatestLayoutVisibleArea = getLatestLayoutVisibleArea\r\n\t\tthis.getListTopOffset = getListTopOffset\r\n\t\tthis.getPrerenderMargin = getPrerenderMargin\r\n\t\tthis.onScrolledToTop = onScrolledToTop\r\n\t\tthis.waitForScrollingToStop = waitForScrollingToStop\r\n\t}\r\n\r\n\tstart() {\r\n\t\tif (this.initialScrollPosition !== undefined) {\r\n\t\t\tthis.scrollToY(this.initialScrollPosition)\r\n\t\t\tthis.initialScrollPosition = undefined\r\n\t\t}\r\n\t\tif (this.onScrollPositionChange) {\r\n\t\t\tthis.onScrollPositionChange(this.getScrollY())\r\n\t\t}\r\n\t\tthis.stopListeningToScroll = this.scrollableContainer.onScroll(this.onScrollListener)\r\n\t}\r\n\r\n\tstop() {\r\n\t\tthis.stopListeningToScroll()\r\n\t\tthis.stopListeningToScroll = undefined\r\n\t\t// this.onStopScrollingListener = undefined\r\n\t\tthis.shouldCallOnScrollListenerWhenStopsScrolling = undefined\r\n\t\tthis.cancelOnStopScrollingTimer()\r\n\t}\r\n\r\n\tscrollToY(scrollY) {\r\n\t\tthis.ignoreScrollEvents = true\r\n\t\tthis.scrollableContainer.scrollToY(scrollY)\r\n\t\tthis.ignoreScrollEvents = undefined\r\n\t}\r\n\r\n\tscrollByY = (scrollByY) => {\r\n\t\tthis.scrollToY(this.getScrollY() + scrollByY)\r\n\t}\r\n\r\n\tgetScrollY() {\r\n\t\treturn this.scrollableContainer.getScrollY()\r\n\t}\r\n\r\n\tcancelOnStopScrollingTimer() {\r\n\t\tif (this.onStopScrollingTimer) {\r\n\t\t\tclearTimeout(this.onStopScrollingTimer)\r\n\t\t\tthis.onStopScrollingTimer = undefined\r\n\t\t}\r\n\t}\r\n\r\n\tcancelScheduledLayout() {\r\n\t\t// Cancel a \"re-layout when user stops scrolling\" timer.\r\n\t\tthis.cancelOnStopScrollingTimer()\r\n\t}\r\n\r\n\tonScrollListener = () => {\r\n\t\tif (this.onScrollPositionChange) {\r\n\t\t\tthis.onScrollPositionChange(this.getScrollY())\r\n\t\t}\r\n\r\n\t\t// If the user has scrolled up to the top of the items container.\r\n\t\t// (this option isn't currently used)\r\n\t\tif (this.onScrolledToTop) {\r\n\t\t\tif (this.getScrollY() < this.getListTopOffset()) {\r\n\t\t\t\tthis.onScrolledToTop()\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tif (this.bypass) {\r\n\t\t\treturn\r\n\t\t}\r\n\r\n\t\tif (this.ignoreScrollEvents) {\r\n\t\t\treturn\r\n\t\t}\r\n\r\n\t\t// Prefer not performing a re-layout while the user is scrolling (if possible).\r\n\t\t// If the user doesn't scroll too far and then stops for a moment,\r\n\t\t// then a mid-scroll re-layout could be delayed until such a brief stop:\r\n\t\t// presumably, this results in better (smoother) scrolling performance,\r\n\t\t// delaying the work to when it doesn't introduce any stutter or \"jank\".\r\n\r\n\t\t// Reset `this.onStopScrollingTimer` (will be re-created below).\r\n\t\tthis.cancelOnStopScrollingTimer()\r\n\r\n\t\t// See if the latest \"layout\" (the currently rendered set of items)\r\n\t\t// is still sufficient in order to show all the items that're\r\n\t\t// currently inside the viewport. If there're some non-rendered items\r\n\t\t// that're visible in the current viewport, then those items\r\n\t\t// should be rendered \"immediately\" rather than waiting until\r\n\t\t// the user stops scrolling.\r\n\t\tconst forceUpdate =\r\n\t\t\t// If the items have been rendered at least once\r\n\t\t\tthis.getLatestLayoutVisibleArea() && (\r\n\t\t\t\t(\r\n\t\t\t\t\t// If the user has scrolled up past the \"prerender margin\"\r\n\t\t\t\t\t// and there're some non-rendered items at the top,\r\n\t\t\t\t\t// then force a re-layout.\r\n\t\t\t\t\t//\r\n\t\t\t\t\t// (during these calculations we assume that the list's top coordinate\r\n\t\t\t\t\t// hasn't changed since previous layout; even if that's not exactly true,\r\n\t\t\t\t\t// the items will be re-layout when the user stops scrolling anyway)\r\n\t\t\t\t\t//\r\n\t\t\t\t\t(this.getScrollY() < this.getLatestLayoutVisibleArea().top - this.getPrerenderMargin()) &&\r\n\t\t\t\t\tthis.hasNonRenderedItemsAtTheTop()\r\n\t\t\t\t)\r\n\t\t\t\t||\r\n\t\t\t\t(\r\n\t\t\t\t\t// If the user has scrolled down past the \"prerender margin\"\r\n\t\t\t\t\t// and there're any non-rendered items left at the end,\r\n\t\t\t\t\t// then force a re-layout.\r\n\t\t\t\t\t//\r\n\t\t\t\t\t// (during these calculations we assume that the list's top coordinate\r\n\t\t\t\t\t// hasn't changed since previous layout; even if that's not exactly true,\r\n\t\t\t\t\t// the items will be re-layout when the user stops scrolling anyway)\r\n\t\t\t\t\t//\r\n\t\t\t\t\t(this.getScrollY() + this.scrollableContainer.getHeight() > this.getLatestLayoutVisibleArea().bottom + this.getPrerenderMargin()) &&\r\n\t\t\t\t\tthis.hasNonRenderedItemsAtTheBottom()\r\n\t\t\t\t)\r\n\t\t\t)\r\n\r\n\t\tif (forceUpdate) {\r\n\t\t\tlog('The user has scrolled far enough: perform a re-layout')\r\n\t\t} else {\r\n\t\t\tlog('The user is scrolling: perform a re-layout when they stop scrolling')\r\n\t\t}\r\n\r\n\t\tif (forceUpdate || this.waitForScrollingToStop === false) {\r\n\t\t\treturn this.onScroll()\r\n\t\t}\r\n\r\n\t\t// If a re-layout is already scheduled at the next \"frame\",\r\n\t\t// don't schedule a \"re-layout when user stops scrolling\" timer.\r\n\t\tif (this.isImmediateLayoutScheduled()) {\r\n\t\t\treturn\r\n\t\t}\r\n\r\n\t\tthis.shouldCallOnScrollListenerWhenStopsScrolling = true\r\n\t\tthis.watchOnStopScrolling()\r\n\t}\r\n\r\n\twatchOnStopScrolling() {\r\n\t\tthis.onStopScrollingTimer = setTimeout(\r\n\t\t\t() => {\r\n\t\t\t\tthis.onStopScrollingTimer = undefined\r\n\r\n\t\t\t\tif (this.shouldCallOnScrollListenerWhenStopsScrolling) {\r\n\t\t\t\t\tthis.shouldCallOnScrollListenerWhenStopsScrolling = undefined\r\n\t\t\t\t\tthis.onScroll({ delayed: true })\r\n\t\t\t\t}\r\n\r\n\t\t\t\t// `onStopScrolling()` feature is not currently used.\r\n\t\t\t\t// if (this.onStopScrollingListener) {\r\n\t\t\t\t// \tconst onStopScrollingListener = this.onStopScrollingListener\r\n\t\t\t\t// \tthis.onStopScrollingListener = undefined\r\n\t\t\t\t// \t// `onStopScrollingListener()` may hypothetically schedule\r\n\t\t\t\t// \t// another `onStopScrolling()` listener, so set\r\n\t\t\t\t// \t// `this.onStopScrollingListener` to `undefined` before\r\n\t\t\t\t// \t// calling it rather than after.\r\n\t\t\t\t// \tlog('~ The user has stopped scrolling ~')\r\n\t\t\t\t// \tonStopScrollingListener()\r\n\t\t\t\t// }\r\n\t\t\t},\r\n\t\t\t// \"scroll\" events are usually dispatched every 16 milliseconds\r\n\t\t\t// for 60fps refresh rate, so waiting for 100 milliseconds feels\r\n\t\t\t// reasonable: that would be about 6 frames of inactivity period,\r\n\t\t\t// which could mean that either the user has stopped scrolling\r\n\t\t\t// (for a moment) or the browser is lagging and stuttering\r\n\t\t\t// (skipping frames due to high load).\r\n\t\t\t// If the user continues scrolling then this timeout is constantly\r\n\t\t\t// refreshed (cancelled and then re-created).\r\n\t\t\tON_STOP_SCROLLING_INACTIVE_PERIOD\r\n\t\t)\r\n\t}\r\n\r\n\t// (this function isn't currently used)\r\n\t// onStopScrolling(onStopScrollingListener) {\r\n\t// \tthis.onStopScrollingListener = onStopScrollingListener\r\n\t// \tif (!this.onStopScrollingTimer) {\r\n\t// \t\tthis.watchOnStopScrolling()\r\n\t// \t}\r\n\t// }\r\n\r\n\t/**\r\n\t * Returns visible area coordinates relative to the scrollable container.\r\n\t * @return {object} `{ top: number, bottom: number }`\r\n\t */\r\n\tgetVisibleAreaBounds() {\r\n\t\tconst scrollY = this.getScrollY()\r\n\t\treturn {\r\n\t\t\t// The first pixel of the screen.\r\n\t\t\ttop: scrollY,\r\n\t\t\t// The pixel after the last pixel of the screen.\r\n\t\t\tbottom: scrollY + this.scrollableContainer.getHeight()\r\n\t\t}\r\n\t}\r\n}\r\n\r\nconst ON_STOP_SCROLLING_INACTIVE_PERIOD = 100"],"mappings":";;;;;;;AAIA;;AAEA;;;;;;;;;;;;IAEqBA,M;EACpB,sBAeG;IAAA;;IAAA,IAdFC,MAcE,QAdFA,MAcE;IAAA,IAbFC,mBAaE,QAbFA,mBAaE;IAAA,IAZFC,cAYE,QAZFA,cAYE;IAAA,IAXFC,QAWE,QAXFA,QAWE;IAAA,IAVFC,qBAUE,QAVFA,qBAUE;IAAA,IATFC,sBASE,QATFA,sBASE;IAAA,IARFC,0BAQE,QARFA,0BAQE;IAAA,IAPFC,2BAOE,QAPFA,2BAOE;IAAA,IANFC,8BAME,QANFA,8BAME;IAAA,IALFC,0BAKE,QALFA,0BAKE;IAAA,IAJFC,gBAIE,QAJFA,gBAIE;IAAA,IAHFC,kBAGE,QAHFA,kBAGE;IAAA,IAFFC,eAEE,QAFFA,eAEE;IAAA,IADFC,sBACE,QADFA,sBACE;;IAAA;;IAAA,mCA0CS,UAACC,SAAD,EAAe;MAC1B,KAAI,CAACC,SAAL,CAAe,KAAI,CAACC,UAAL,KAAoBF,SAA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,SAA1B;IACA;;;WAMD,sBAAa;MACZ,OAAO,KAAKzB,mBAAL,CAAyBe,UAAzB,EAAP;IACA;;;WAED,sCAA6B;MAC5B,IAAI,KAAKc,oBAAT,EAA+B;QAC9B,IAAAC,0CAAA,EAAa,KAAKD,oBAAlB;QACA,KAAKA,oBAAL,GAA4BJ,SAA5B;MACA;IACD;;;WAED,iCAAwB;MACvB;MACA,KAAKR,0BAAL;IACA;;;WAwFD,gCAAuB;MAAA;;MACtB,KAAKY,oBAAL,GAA4B,IAAAE,wCAAA,EAC3B,YAAM;QACL,MAAI,CAACF,oBAAL,GAA4BJ,SAA5B;;QAEA,IAAI,MAAI,CAACF,4CAAT,EAAuD;UACtD,MAAI,CAACA,4CAAL,GAAoDE,SAApD;;UACA,MAAI,CAACvB,QAAL,CAAc;YAAE8B,OAAO,EAAE;UAAX,CAAd;QACA,CANI,CAQL;QACA;QACA;QACA;QACA;QACA;QACA;QACA;QACA;QACA;QACA;;MACA,CApB0B,EAqB3B;MACA;MACA;MACA;MACA;MACA;MACA;MACA;MACAC,iCA7B2B,CAA5B;IA+BA,C,CAED;IACA;IACA;IACA;IACA;IACA;IACA;;IAEA;AACD;AACA;AACA;;;;WACC,gCAAuB;MACtB,IAAML,OAAO,GAAG,KAAKb,UAAL,EAAhB;MACA,OAAO;QACN;QACAI,GAAG,EAAES,OAFC;QAGN;QACAP,MAAM,EAAEO,OAAO,GAAG,KAAK5B,mBAAL,CAAyBoB,SAAzB;MAJZ,CAAP;IAMA;;;;;;;AAGF,IAAMa,iCAAiC,GAAG,GAA1C"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports["default"] = createColumnsHelpers;
|
|
7
|
+
|
|
8
|
+
function createColumnsHelpers(_ref) {
|
|
9
|
+
var _this = this;
|
|
10
|
+
|
|
11
|
+
var getColumnsCount = _ref.getColumnsCount;
|
|
12
|
+
|
|
13
|
+
if (getColumnsCount) {
|
|
14
|
+
var scrollableContainerArgument = {
|
|
15
|
+
getWidth: function getWidth() {
|
|
16
|
+
return _this.scrollableContainer.getWidth();
|
|
17
|
+
}
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
this.getActualColumnsCountForState = function () {
|
|
21
|
+
var columnsCount = getColumnsCount(scrollableContainerArgument); // `columnsCount: 1` is effectively same as `columnsCount: undefined`
|
|
22
|
+
// from the code's point of view. This makes one less property in `state`
|
|
23
|
+
// which makes `state` a bit less cluttered (easier for inspection).
|
|
24
|
+
|
|
25
|
+
if (columnsCount !== 1) {
|
|
26
|
+
return columnsCount;
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
} else {
|
|
30
|
+
this.getActualColumnsCountForState = function () {
|
|
31
|
+
return undefined;
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
this.getActualColumnsCount = function () {
|
|
36
|
+
return _this.getActualColumnsCountForState() || 1;
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
this.getColumnsCount = function () {
|
|
40
|
+
return _this.getState() && _this.getState().columnsCount || 1;
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
//# sourceMappingURL=VirtualScroller.columns.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"VirtualScroller.columns.js","names":["createColumnsHelpers","getColumnsCount","scrollableContainerArgument","getWidth","scrollableContainer","getActualColumnsCountForState","columnsCount","undefined","getActualColumnsCount","getState"],"sources":["../source/VirtualScroller.columns.js"],"sourcesContent":["export default function createColumnsHelpers({ getColumnsCount }) {\r\n\tif (getColumnsCount) {\r\n\t\tconst scrollableContainerArgument = {\r\n\t\t\tgetWidth: () => this.scrollableContainer.getWidth()\r\n\t\t}\r\n\t\tthis.getActualColumnsCountForState = () => {\r\n\t\t\tconst columnsCount = getColumnsCount(scrollableContainerArgument)\r\n\t\t\t// `columnsCount: 1` is effectively same as `columnsCount: undefined`\r\n\t\t\t// from the code's point of view. This makes one less property in `state`\r\n\t\t\t// which makes `state` a bit less cluttered (easier for inspection).\r\n\t\t\tif (columnsCount !== 1) {\r\n\t\t\t\treturn columnsCount\r\n\t\t\t}\r\n\t\t}\r\n\t} else {\r\n\t\tthis.getActualColumnsCountForState = () => undefined\r\n\t}\r\n\r\n\tthis.getActualColumnsCount = () => {\r\n\t\treturn this.getActualColumnsCountForState() || 1\r\n\t}\r\n\r\n\tthis.getColumnsCount = () => {\r\n\t\treturn this.getState() && this.getState().columnsCount || 1\r\n\t}\r\n}"],"mappings":";;;;;;;AAAe,SAASA,oBAAT,OAAmD;EAAA;;EAAA,IAAnBC,eAAmB,QAAnBA,eAAmB;;EACjE,IAAIA,eAAJ,EAAqB;IACpB,IAAMC,2BAA2B,GAAG;MACnCC,QAAQ,EAAE;QAAA,OAAM,KAAI,CAACC,mBAAL,CAAyBD,QAAzB,EAAN;MAAA;IADyB,CAApC;;IAGA,KAAKE,6BAAL,GAAqC,YAAM;MAC1C,IAAMC,YAAY,GAAGL,eAAe,CAACC,2BAAD,CAApC,CAD0C,CAE1C;MACA;MACA;;MACA,IAAII,YAAY,KAAK,CAArB,EAAwB;QACvB,OAAOA,YAAP;MACA;IACD,CARD;EASA,CAbD,MAaO;IACN,KAAKD,6BAAL,GAAqC;MAAA,OAAME,SAAN;IAAA,CAArC;EACA;;EAED,KAAKC,qBAAL,GAA6B,YAAM;IAClC,OAAO,KAAI,CAACH,6BAAL,MAAwC,CAA/C;EACA,CAFD;;EAIA,KAAKJ,eAAL,GAAuB,YAAM;IAC5B,OAAO,KAAI,CAACQ,QAAL,MAAmB,KAAI,CAACA,QAAL,GAAgBH,YAAnC,IAAmD,CAA1D;EACA,CAFD;AAGA"}
|