virtual-scroller 1.11.2 → 1.12.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/CHANGELOG.md +5 -0
- package/README.md +13 -11
- 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/DOM/ItemsContainer.js +10 -3
- package/commonjs/DOM/ItemsContainer.js.map +1 -1
- package/commonjs/DOM/VirtualScroller.js +13 -1
- package/commonjs/DOM/VirtualScroller.js.map +1 -1
- package/commonjs/ItemHeights.js +5 -5
- package/commonjs/ItemHeights.js.map +1 -1
- package/commonjs/ItemNotRenderedError.js +64 -0
- package/commonjs/ItemNotRenderedError.js.map +1 -0
- package/commonjs/Layout.test.js +10 -0
- package/commonjs/Layout.test.js.map +1 -1
- package/commonjs/VirtualScroller.js +23 -5
- package/commonjs/VirtualScroller.js.map +1 -1
- package/commonjs/VirtualScroller.layout.js +81 -39
- package/commonjs/VirtualScroller.layout.js.map +1 -1
- package/commonjs/VirtualScroller.onRender.js +97 -45
- package/commonjs/VirtualScroller.onRender.js.map +1 -1
- package/commonjs/VirtualScroller.state.js +50 -18
- package/commonjs/VirtualScroller.state.js.map +1 -1
- package/commonjs/react/VirtualScroller.js +31 -46
- package/commonjs/react/VirtualScroller.js.map +1 -1
- package/commonjs/react/useItemKeys.js +11 -3
- package/commonjs/react/useItemKeys.js.map +1 -1
- package/commonjs/react/useOnChange.js +19 -0
- package/commonjs/react/useOnChange.js.map +1 -0
- package/commonjs/react/{useOnItemHeightChange.js → useOnItemHeightDidChange.js} +7 -7
- package/commonjs/react/useOnItemHeightDidChange.js.map +1 -0
- package/commonjs/react/{useHandleItemsPropertyChange.js → useSetNewItemsOnItemsPropertyChange.js} +15 -14
- package/commonjs/react/useSetNewItemsOnItemsPropertyChange.js.map +1 -0
- package/commonjs/react/useState.js +162 -69
- package/commonjs/react/useState.js.map +1 -1
- package/commonjs/react/useStyle.js +3 -5
- package/commonjs/react/useStyle.js.map +1 -1
- package/commonjs/react/useUpdateItemKeysOnItemsChange.js +61 -0
- package/commonjs/react/useUpdateItemKeysOnItemsChange.js.map +1 -0
- package/commonjs/test/ItemsContainer.js +22 -1
- package/commonjs/test/ItemsContainer.js.map +1 -1
- package/commonjs/utility/debug.js +30 -6
- package/commonjs/utility/debug.js.map +1 -1
- package/dom/index.d.ts +1 -1
- package/index.cjs +2 -0
- package/index.d.ts +7 -1
- package/index.js +1 -0
- package/modules/DOM/ItemsContainer.js +8 -3
- package/modules/DOM/ItemsContainer.js.map +1 -1
- package/modules/DOM/VirtualScroller.js +13 -1
- package/modules/DOM/VirtualScroller.js.map +1 -1
- package/modules/ItemHeights.js +5 -5
- package/modules/ItemHeights.js.map +1 -1
- package/modules/ItemNotRenderedError.js +57 -0
- package/modules/ItemNotRenderedError.js.map +1 -0
- package/modules/Layout.test.js +10 -0
- package/modules/Layout.test.js.map +1 -1
- package/modules/VirtualScroller.js +17 -5
- package/modules/VirtualScroller.js.map +1 -1
- package/modules/VirtualScroller.layout.js +78 -39
- package/modules/VirtualScroller.layout.js.map +1 -1
- package/modules/VirtualScroller.onRender.js +98 -46
- package/modules/VirtualScroller.onRender.js.map +1 -1
- package/modules/VirtualScroller.state.js +50 -18
- package/modules/VirtualScroller.state.js.map +1 -1
- package/modules/react/VirtualScroller.js +31 -46
- package/modules/react/VirtualScroller.js.map +1 -1
- package/modules/react/useItemKeys.js +8 -3
- package/modules/react/useItemKeys.js.map +1 -1
- package/modules/react/useOnChange.js +11 -0
- package/modules/react/useOnChange.js.map +1 -0
- package/modules/react/{useOnItemHeightChange.js → useOnItemHeightDidChange.js} +6 -6
- package/modules/react/useOnItemHeightDidChange.js.map +1 -0
- package/modules/react/{useHandleItemsPropertyChange.js → useSetNewItemsOnItemsPropertyChange.js} +11 -13
- package/modules/react/useSetNewItemsOnItemsPropertyChange.js.map +1 -0
- package/modules/react/useState.js +156 -73
- package/modules/react/useState.js.map +1 -1
- package/modules/react/useStyle.js +3 -5
- package/modules/react/useStyle.js.map +1 -1
- package/{commonjs/react/useHandleItemIndexesChange.js → modules/react/useUpdateItemKeysOnItemsChange.js} +18 -21
- package/modules/react/useUpdateItemKeysOnItemsChange.js.map +1 -0
- package/modules/test/ItemsContainer.js +20 -1
- package/modules/test/ItemsContainer.js.map +1 -1
- package/modules/utility/debug.js +31 -6
- package/modules/utility/debug.js.map +1 -1
- package/package.json +1 -1
- package/source/DOM/ItemsContainer.js +8 -3
- package/source/DOM/VirtualScroller.js +11 -1
- package/source/ItemHeights.js +5 -5
- package/source/ItemNotRenderedError.js +16 -0
- package/source/Layout.test.js +9 -0
- package/source/VirtualScroller.js +14 -3
- package/source/VirtualScroller.layout.js +77 -38
- package/source/VirtualScroller.onRender.js +95 -42
- package/source/VirtualScroller.state.js +57 -20
- package/source/react/VirtualScroller.js +28 -39
- package/source/react/useItemKeys.js +9 -2
- package/source/react/useOnChange.js +11 -0
- package/source/react/{useOnItemHeightChange.js → useOnItemHeightDidChange.js} +5 -5
- package/source/react/{useHandleItemsPropertyChange.js → useSetNewItemsOnItemsPropertyChange.js} +11 -11
- package/source/react/useState.js +159 -71
- package/source/react/useStyle.js +2 -2
- package/source/react/{useHandleItemIndexesChange.js → useUpdateItemKeysOnItemsChange.js} +17 -9
- package/source/test/ItemsContainer.js +22 -1
- package/source/utility/debug.js +18 -4
- package/commonjs/react/useHandleItemIndexesChange.js.map +0 -1
- package/commonjs/react/useHandleItemsPropertyChange.js.map +0 -1
- package/commonjs/react/useOnItemHeightChange.js.map +0 -1
- package/modules/react/useHandleItemIndexesChange.js +0 -45
- package/modules/react/useHandleItemIndexesChange.js.map +0 -1
- package/modules/react/useHandleItemsPropertyChange.js.map +0 -1
- package/modules/react/useOnItemHeightChange.js.map +0 -1
|
@@ -38,6 +38,7 @@ function _default() {
|
|
|
38
38
|
* @param {object} [prevState]
|
|
39
39
|
*/
|
|
40
40
|
this._onRender = function (newState, prevState) {
|
|
41
|
+
_this.waitingForRender = false;
|
|
41
42
|
(0, _debug["default"])('~ Rendered ~');
|
|
42
43
|
|
|
43
44
|
if ((0, _debug.isDebug)()) {
|
|
@@ -55,23 +56,63 @@ function _default() {
|
|
|
55
56
|
|
|
56
57
|
if (_this.tbody) {
|
|
57
58
|
(0, _tbody.setTbodyPadding)(_this.getItemsContainerElement(), newState.beforeItemsHeight, newState.afterItemsHeight);
|
|
58
|
-
}
|
|
59
|
+
} // `this.mostRecentlySetState` checks that state management behavior is correct:
|
|
60
|
+
// that in situations when there're multiple new states waiting to be set,
|
|
61
|
+
// only the latest one gets applied.
|
|
62
|
+
// It keeps the code simpler and prevents possible race condition bugs.
|
|
63
|
+
// For example, `VirtualScroller` keeps track of its latest requested
|
|
64
|
+
// state update in different instance variable flags which assume that
|
|
65
|
+
// only that latest requested state update gets actually applied.
|
|
66
|
+
//
|
|
67
|
+
// This check should also be performed for the initial render in order to
|
|
68
|
+
// guarantee that no potentially incorrect state update goes unnoticed.
|
|
69
|
+
// Incorrect state updates could happen when `VirtualScroller` state
|
|
70
|
+
// is managed externally by passing `getState()`/`updateState()` options.
|
|
71
|
+
//
|
|
72
|
+
// Perform the check only when `this.mostRecentSetStateValue` is defined.
|
|
73
|
+
// `this.mostRecentSetStateValue` is normally gonna be `undefined` at the initial render
|
|
74
|
+
// because the initial state is not set by calling `this.updateState()`.
|
|
75
|
+
// At the same time, it is possible that the initial render is delayed
|
|
76
|
+
// for whatever reason, and `this.updateState()` gets called before the initial render,
|
|
77
|
+
// so `this.mostRecentSetStateValue` could also be defined at the initial render,
|
|
78
|
+
// in which case the check should be performed.
|
|
79
|
+
//
|
|
59
80
|
|
|
60
|
-
|
|
61
|
-
|
|
81
|
+
|
|
82
|
+
if (_this.mostRecentSetStateValue) {
|
|
83
|
+
// "Shallow equality" is used here instead of "strict equality"
|
|
84
|
+
// because a developer might choose to supply an `updateState()` function
|
|
85
|
+
// rather than a `setState()` function, in which case the `updateState()` function
|
|
86
|
+
// would construct its own state object.
|
|
87
|
+
if (!(0, _shallowEqual["default"])(newState, _this.mostRecentSetStateValue)) {
|
|
88
|
+
(0, _debug.warn)('The most recent state that was set', (0, _getStateSnapshot["default"])(_this.mostRecentSetStateValue));
|
|
89
|
+
(0, _debug.reportError)('The state that has been rendered is not the most recent one that was set');
|
|
90
|
+
}
|
|
62
91
|
} // `this.resetStateUpdateFlags()` must be called before calling
|
|
63
92
|
// `this.measureItemHeightsAndSpacing()`.
|
|
64
93
|
|
|
65
94
|
|
|
66
95
|
var _resetStateUpdateFlag = resetStateUpdateFlags.call(_this),
|
|
67
96
|
nonMeasuredItemsHaveBeenRendered = _resetStateUpdateFlag.nonMeasuredItemsHaveBeenRendered,
|
|
97
|
+
itemHeightHasChanged = _resetStateUpdateFlag.itemHeightHasChanged,
|
|
68
98
|
widthHasChanged = _resetStateUpdateFlag.widthHasChanged;
|
|
69
99
|
|
|
70
|
-
var layoutUpdateReason;
|
|
100
|
+
var layoutUpdateReason;
|
|
101
|
+
|
|
102
|
+
if (_this.updateLayoutAfterRenderBecauseItemHeightChanged) {
|
|
103
|
+
layoutUpdateReason = _Layout.LAYOUT_REASON.ITEM_HEIGHT_CHANGED;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
if (!prevState) {
|
|
107
|
+
if (!layoutUpdateReason) {
|
|
108
|
+
return;
|
|
109
|
+
}
|
|
110
|
+
} // If the `VirtualScroller`, while calculating layout parameters, encounters
|
|
71
111
|
// a not-shown item with a non-measured height, it calls `updateState()` just to
|
|
72
112
|
// render that item first, and then, after the list has been re-rendered, it measures
|
|
73
113
|
// the item's height and then proceeds with calculating the correct layout parameters.
|
|
74
114
|
|
|
115
|
+
|
|
75
116
|
if (nonMeasuredItemsHaveBeenRendered) {
|
|
76
117
|
layoutUpdateReason = _Layout.LAYOUT_REASON.NON_MEASURED_ITEMS_HAVE_BEEN_MEASURED;
|
|
77
118
|
} // If scrollable container width has changed, and it has been re-rendered,
|
|
@@ -95,43 +136,45 @@ function _default() {
|
|
|
95
136
|
_this.verticalSpacing = undefined;
|
|
96
137
|
}
|
|
97
138
|
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
139
|
+
if (prevState) {
|
|
140
|
+
var previousItems = prevState.items;
|
|
141
|
+
var newItems = newState.items; // Even if `this.newItemsWillBeRendered` flag is `true`,
|
|
142
|
+
// `newItems` could still be equal to `previousItems`.
|
|
143
|
+
// For example, when `updateState()` calls don't update `state` immediately
|
|
144
|
+
// and a developer first calls `setItems(newItems)` and then calls `setItems(oldItems)`:
|
|
145
|
+
// in that case, `this.newItemsWillBeRendered` flag will be `true` but the actual `items`
|
|
146
|
+
// in state wouldn't have changed due to the first `updateState()` call being overwritten
|
|
147
|
+
// by the second `updateState()` call (that's called "batching state updates" in React).
|
|
148
|
+
|
|
149
|
+
if (newItems !== previousItems) {
|
|
150
|
+
var itemsDiff = _this.getItemsDiff(previousItems, newItems);
|
|
151
|
+
|
|
152
|
+
if (itemsDiff) {
|
|
153
|
+
// The call to `.onPrepend()` must precede the call to `.measureItemHeights()`
|
|
154
|
+
// which is called in `.onRender()`.
|
|
155
|
+
// `this.itemHeights.onPrepend()` updates `firstMeasuredItemIndex`
|
|
156
|
+
// and `lastMeasuredItemIndex` of `this.itemHeights`.
|
|
157
|
+
var prependedItemsCount = itemsDiff.prependedItemsCount;
|
|
158
|
+
|
|
159
|
+
_this.itemHeights.onPrepend(prependedItemsCount);
|
|
160
|
+
} else {
|
|
161
|
+
_this.itemHeights.reset();
|
|
162
|
+
}
|
|
121
163
|
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
164
|
+
if (!widthHasChanged) {
|
|
165
|
+
// The call to `this.onNewItemsRendered()` must precede the call to
|
|
166
|
+
// `.measureItemHeights()` which is called in `.onRender()` because
|
|
167
|
+
// `this.onNewItemsRendered()` updates `firstMeasuredItemIndex` and
|
|
168
|
+
// `lastMeasuredItemIndex` of `this.itemHeights` in case of a prepend.
|
|
169
|
+
//
|
|
170
|
+
// If after prepending items the scroll position
|
|
171
|
+
// should be "restored" so that there's no "jump" of content
|
|
172
|
+
// then it means that all previous items have just been rendered
|
|
173
|
+
// in a single pass, and there's no need to update layout again.
|
|
174
|
+
//
|
|
175
|
+
if (onNewItemsRendered.call(_this, itemsDiff, newState) !== 'SEAMLESS_PREPEND') {
|
|
176
|
+
layoutUpdateReason = _Layout.LAYOUT_REASON.ITEMS_CHANGED;
|
|
177
|
+
}
|
|
135
178
|
}
|
|
136
179
|
}
|
|
137
180
|
}
|
|
@@ -145,7 +188,7 @@ function _default() {
|
|
|
145
188
|
// item height measurements is required.
|
|
146
189
|
//
|
|
147
190
|
|
|
148
|
-
if (newState.firstShownItemIndex !== prevState.firstShownItemIndex || newState.lastShownItemIndex !== prevState.lastShownItemIndex || newState.items !== prevState.items || widthHasChanged) {
|
|
191
|
+
if (prevState && (newState.firstShownItemIndex !== prevState.firstShownItemIndex || newState.lastShownItemIndex !== prevState.lastShownItemIndex || newState.items !== prevState.items) || widthHasChanged) {
|
|
149
192
|
var verticalSpacingStateUpdate = _this.measureItemHeightsAndSpacing();
|
|
150
193
|
|
|
151
194
|
if (verticalSpacingStateUpdate) {
|
|
@@ -218,7 +261,7 @@ function _default() {
|
|
|
218
261
|
if (this.itemHeightsThatChangedWhileNewItemsWereBeingRendered) {
|
|
219
262
|
for (var _i = 0, _Object$keys = Object.keys(this.itemHeightsThatChangedWhileNewItemsWereBeingRendered); _i < _Object$keys.length; _i++) {
|
|
220
263
|
var i = _Object$keys[_i];
|
|
221
|
-
itemHeights[prependedItemsCount +
|
|
264
|
+
itemHeights[prependedItemsCount + Number(i)] = this.itemHeightsThatChangedWhileNewItemsWereBeingRendered[i];
|
|
222
265
|
}
|
|
223
266
|
} // See if any items' states changed while new items were being rendered.
|
|
224
267
|
|
|
@@ -226,7 +269,7 @@ function _default() {
|
|
|
226
269
|
if (this.itemStatesThatChangedWhileNewItemsWereBeingRendered) {
|
|
227
270
|
for (var _i2 = 0, _Object$keys2 = Object.keys(this.itemStatesThatChangedWhileNewItemsWereBeingRendered); _i2 < _Object$keys2.length; _i2++) {
|
|
228
271
|
var _i3 = _Object$keys2[_i2];
|
|
229
|
-
itemStates[prependedItemsCount +
|
|
272
|
+
itemStates[prependedItemsCount + Number(_i3)] = this.itemStatesThatChangedWhileNewItemsWereBeingRendered[_i3];
|
|
230
273
|
}
|
|
231
274
|
}
|
|
232
275
|
|
|
@@ -339,7 +382,12 @@ function _default() {
|
|
|
339
382
|
|
|
340
383
|
this.widthHasChanged = undefined; // Read `this.firstNonMeasuredItemIndex` flag.
|
|
341
384
|
|
|
342
|
-
var nonMeasuredItemsHaveBeenRendered = this.firstNonMeasuredItemIndex !== undefined;
|
|
385
|
+
var nonMeasuredItemsHaveBeenRendered = this.firstNonMeasuredItemIndex !== undefined;
|
|
386
|
+
|
|
387
|
+
if (nonMeasuredItemsHaveBeenRendered) {
|
|
388
|
+
(0, _debug["default"])('Non-measured item index', this.firstNonMeasuredItemIndex);
|
|
389
|
+
} // Reset `this.firstNonMeasuredItemIndex` flag.
|
|
390
|
+
|
|
343
391
|
|
|
344
392
|
this.firstNonMeasuredItemIndex = undefined; // Reset `this.newItemsWillBeRendered` flag.
|
|
345
393
|
|
|
@@ -347,9 +395,13 @@ function _default() {
|
|
|
347
395
|
|
|
348
396
|
this.itemHeightsThatChangedWhileNewItemsWereBeingRendered = undefined; // Reset `this.itemStatesThatChangedWhileNewItemsWereBeingRendered`.
|
|
349
397
|
|
|
350
|
-
this.itemStatesThatChangedWhileNewItemsWereBeingRendered = undefined;
|
|
398
|
+
this.itemStatesThatChangedWhileNewItemsWereBeingRendered = undefined; // Reset `this.updateLayoutAfterRenderBecauseItemHeightChanged`.
|
|
399
|
+
|
|
400
|
+
var itemHeightHasChanged = this.updateLayoutAfterRenderBecauseItemHeightChanged;
|
|
401
|
+
this.updateLayoutAfterRenderBecauseItemHeightChanged = undefined;
|
|
351
402
|
return {
|
|
352
403
|
nonMeasuredItemsHaveBeenRendered: nonMeasuredItemsHaveBeenRendered,
|
|
404
|
+
itemHeightHasChanged: itemHeightHasChanged,
|
|
353
405
|
widthHasChanged: widthHasChanged
|
|
354
406
|
};
|
|
355
407
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"VirtualScroller.onRender.js","names":["_onRender","newState","prevState","log","isDebug","getStateSnapshot","onStateChange","shallowEqual","tbody","setTbodyPadding","getItemsContainerElement","beforeItemsHeight","afterItemsHeight","resetStateUpdateFlags","call","nonMeasuredItemsHaveBeenRendered","widthHasChanged","layoutUpdateReason","LAYOUT_REASON","NON_MEASURED_ITEMS_HAVE_BEEN_MEASURED","VIEWPORT_WIDTH_CHANGED","itemHeights","reset","verticalSpacing","undefined","previousItems","items","newItems","itemsDiff","getItemsDiff","prependedItemsCount","onPrepend","onNewItemsRendered","ITEMS_CHANGED","stateUpdate","firstShownItemIndex","lastShownItemIndex","verticalSpacingStateUpdate","measureItemHeightsAndSpacing","cleanedUpBeforeResize","beforeResize","cleanUpBeforeResizeItemHeights","scrollBy","scroll","scrollByY","_isActive","_stoppedStateUpdate","updateStateRightAfterRender","reason","updateState","newLayout","appendedItemsCount","getState","itemStates","itemHeightsThatChangedWhileNewItemsWereBeingRendered","Object","keys","i","parseInt","itemStatesThatChangedWhileNewItemsWereBeingRendered","previouslyCalculatedLayout","warn","listHeightMeasurement","hasSnapshot","listBottomOffsetChange","getListBottomOffsetChange","shownItemsHeight","_useTimeoutInRenderLoop","cancelLayoutTimer","scheduleLayoutTimer","onUpdateShownItemIndexes","Boolean","firstNonMeasuredItemIndex","newItemsWillBeRendered"],"sources":["../source/VirtualScroller.onRender.js"],"sourcesContent":["import log, { warn, isDebug } from './utility/debug.js'\r\nimport getStateSnapshot from './utility/getStateSnapshot.js'\r\nimport shallowEqual from './utility/shallowEqual.js'\r\nimport { LAYOUT_REASON } from './Layout.js'\r\nimport { setTbodyPadding } from './DOM/tbody.js'\r\n\r\nexport default function() {\r\n\t/**\r\n\t * Should be called right after updates to `state` have been rendered.\r\n\t * @param {object} newState\r\n\t * @param {object} [prevState]\r\n\t */\r\n\tthis._onRender = (newState, prevState) => {\r\n\t\tlog('~ Rendered ~')\r\n\t\tif (isDebug()) {\r\n\t\t\tlog('State', getStateSnapshot(newState))\r\n\t\t}\r\n\r\n\t\tif (this.onStateChange) {\r\n\t\t\tif (!shallowEqual(newState, prevState)) {\r\n\t\t\t\tthis.onStateChange(newState)\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\t// Update `<tbody/>` `padding`.\r\n\t\t// (`<tbody/>` is different in a way that it can't have `margin`, only `padding`).\r\n\t\t// https://gitlab.com/catamphetamine/virtual-scroller/-/issues/1\r\n\t\tif (this.tbody) {\r\n\t\t\tsetTbodyPadding(\r\n\t\t\t\tthis.getItemsContainerElement(),\r\n\t\t\t\tnewState.beforeItemsHeight,\r\n\t\t\t\tnewState.afterItemsHeight\r\n\t\t\t)\r\n\t\t}\r\n\r\n\t\tif (!prevState) {\r\n\t\t\treturn\r\n\t\t}\r\n\r\n\t\t// `this.resetStateUpdateFlags()` must be called before calling\r\n\t\t// `this.measureItemHeightsAndSpacing()`.\r\n\t\tconst {\r\n\t\t\tnonMeasuredItemsHaveBeenRendered,\r\n\t\t\twidthHasChanged\r\n\t\t} = resetStateUpdateFlags.call(this)\r\n\r\n\t\tlet layoutUpdateReason\r\n\r\n\t\t// If the `VirtualScroller`, while calculating layout parameters, encounters\r\n\t\t// a not-shown item with a non-measured height, it calls `updateState()` just to\r\n\t\t// render that item first, and then, after the list has been re-rendered, it measures\r\n\t\t// the item's height and then proceeds with calculating the correct layout parameters.\r\n\t\tif (nonMeasuredItemsHaveBeenRendered) {\r\n\t\t\tlayoutUpdateReason = LAYOUT_REASON.NON_MEASURED_ITEMS_HAVE_BEEN_MEASURED\r\n\t\t}\r\n\r\n\t\t// If scrollable container width has changed, and it has been re-rendered,\r\n\t\t// then it's time to measure the new item heights and then perform a re-layout\r\n\t\t// with the correctly calculated layout parameters.\r\n\t\t//\r\n\t\t// A re-layout is required because the layout parameters calculated on resize\r\n\t\t// are approximate ones, and the exact item heights aren't known at that point.\r\n\t\t// So on resize, it calls `updateState()` just to re-render the `VirtualScroller`.\r\n\t\t// After it has been re-rendered, it will measure item heights and then calculate\r\n\t\t// correct layout parameters.\r\n\t\t//\r\n\t\tif (widthHasChanged) {\r\n\t\t\tlayoutUpdateReason = LAYOUT_REASON.VIEWPORT_WIDTH_CHANGED\r\n\r\n\t\t\t// Reset measured item heights on viewport width change.\r\n\t\t\tthis.itemHeights.reset()\r\n\r\n\t\t\t// Reset `verticalSpacing` (will be re-measured).\r\n\t\t\tthis.verticalSpacing = undefined\r\n\t\t}\r\n\r\n\t\tconst { items: previousItems } = prevState\r\n\t\tconst { items: newItems } = newState\r\n\t\t// Even if `this.newItemsWillBeRendered` flag is `true`,\r\n\t\t// `newItems` could still be equal to `previousItems`.\r\n\t\t// For example, when `updateState()` calls don't update `state` immediately\r\n\t\t// and a developer first calls `setItems(newItems)` and then calls `setItems(oldItems)`:\r\n\t\t// in that case, `this.newItemsWillBeRendered` flag will be `true` but the actual `items`\r\n\t\t// in state wouldn't have changed due to the first `updateState()` call being overwritten\r\n\t\t// by the second `updateState()` call (that's called \"batching state updates\" in React).\r\n\t\tif (newItems !== previousItems) {\r\n\t\t\tconst itemsDiff = this.getItemsDiff(previousItems, newItems)\r\n\t\t\tif (itemsDiff) {\r\n\t\t\t\t// The call to `.onPrepend()` must precede the call to `.measureItemHeights()`\r\n\t\t\t\t// which is called in `.onRender()`.\r\n\t\t\t\t// `this.itemHeights.onPrepend()` updates `firstMeasuredItemIndex`\r\n\t\t\t\t// and `lastMeasuredItemIndex` of `this.itemHeights`.\r\n\t\t\t\tconst { prependedItemsCount } = itemsDiff\r\n\t\t\t\tthis.itemHeights.onPrepend(prependedItemsCount)\r\n\t\t\t} else {\r\n\t\t\t\tthis.itemHeights.reset()\r\n\t\t\t}\r\n\r\n\t\t\tif (!widthHasChanged) {\r\n\t\t\t\t// The call to `this.onNewItemsRendered()` must precede the call to\r\n\t\t\t\t// `.measureItemHeights()` which is called in `.onRender()` because\r\n\t\t\t\t// `this.onNewItemsRendered()` updates `firstMeasuredItemIndex` and\r\n\t\t\t\t// `lastMeasuredItemIndex` of `this.itemHeights` in case of a prepend.\r\n\t\t\t\t//\r\n\t\t\t\t// If after prepending items the scroll position\r\n\t\t\t\t// should be \"restored\" so that there's no \"jump\" of content\r\n\t\t\t\t// then it means that all previous items have just been rendered\r\n\t\t\t\t// in a single pass, and there's no need to update layout again.\r\n\t\t\t\t//\r\n\t\t\t\tif (onNewItemsRendered.call(this, itemsDiff, newState) !== 'SEAMLESS_PREPEND') {\r\n\t\t\t\t\tlayoutUpdateReason = LAYOUT_REASON.ITEMS_CHANGED\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tlet stateUpdate\r\n\r\n\t\t// Re-measure item heights.\r\n\t\t// Also, measure vertical spacing (if not measured) and fix `<table/>` padding.\r\n\t\t//\r\n\t\t// This block should go after `if (newItems !== previousItems) {}`\r\n\t\t// because `this.itemHeights` can get `.reset()` there, which would\r\n\t\t// discard all the measurements done here, and having currently shown\r\n\t\t// item height measurements is required.\r\n\t\t//\r\n\t\tif (\r\n\t\t\tnewState.firstShownItemIndex !== prevState.firstShownItemIndex ||\r\n\t\t\tnewState.lastShownItemIndex !== prevState.lastShownItemIndex ||\r\n\t\t\tnewState.items !== prevState.items ||\r\n\t\t\twidthHasChanged\r\n\t\t) {\r\n\t\t\tconst verticalSpacingStateUpdate = this.measureItemHeightsAndSpacing()\r\n\t\t\tif (verticalSpacingStateUpdate) {\r\n\t\t\t\tstateUpdate = {\r\n\t\t\t\t\t...stateUpdate,\r\n\t\t\t\t\t...verticalSpacingStateUpdate\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\t// Clean up \"before resize\" item heights and adjust the scroll position accordingly.\r\n\t\t// Calling `this.beforeResize.cleanUpBeforeResizeItemHeights()` might trigger\r\n\t\t// a `this.updateState()` call but that wouldn't matter because `beforeResize`\r\n\t\t// properties have already been modified directly in `state` (a hacky technique)\r\n\t\tconst cleanedUpBeforeResize = this.beforeResize.cleanUpBeforeResizeItemHeights()\r\n\t\tif (cleanedUpBeforeResize !== undefined) {\r\n\t\t\tconst { scrollBy, beforeResize } = cleanedUpBeforeResize\r\n\t\t\tlog('Correct scroll position by', scrollBy)\r\n\t\t\tthis.scroll.scrollByY(scrollBy)\r\n\t\t\tstateUpdate = {\r\n\t\t\t\t...stateUpdate,\r\n\t\t\t\tbeforeResize\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tif (!this._isActive) {\r\n\t\t\tthis._stoppedStateUpdate = stateUpdate\r\n\t\t\treturn\r\n\t\t}\r\n\r\n\t\tif (layoutUpdateReason) {\r\n\t\t\tupdateStateRightAfterRender.call(this, {\r\n\t\t\t\tstateUpdate,\r\n\t\t\t\treason: layoutUpdateReason\r\n\t\t\t})\r\n\t\t} else if (stateUpdate) {\r\n\t\t\tthis.updateState(stateUpdate)\r\n\t\t} else {\r\n\t\t\tlog('~ Finished Layout ~')\r\n\t\t}\r\n\t}\r\n\r\n\t// After a new set of items has been rendered:\r\n\t//\r\n\t// * Restores scroll position when using `preserveScrollPositionOnPrependItems`\r\n\t// and items have been prepended.\r\n\t//\r\n\t// * Applies any \"pending\" `itemHeights` updates — those ones that happened\r\n\t// while an asynchronous `updateState()` call in `setItems()` was pending.\r\n\t//\r\n\t// * Either creates or resets the snapshot of the current layout.\r\n\t//\r\n\t// The current layout snapshot could be stored as a \"previously calculated layout\" variable\r\n\t// so that it could theoretically be used when calculating new layout incrementally\r\n\t// rather than from scratch, which would be an optimization.\r\n\t//\r\n\t// The \"previously calculated layout\" feature is not currently used.\r\n\t//\r\n\tfunction onNewItemsRendered(itemsDiff, newLayout) {\r\n\t\t// If it's an \"incremental\" update.\r\n\t\tif (itemsDiff) {\r\n\t\t\tconst {\r\n\t\t\t\tprependedItemsCount,\r\n\t\t\t\tappendedItemsCount\r\n\t\t\t} = itemsDiff\r\n\r\n\t\t\tconst {\r\n\t\t\t\titemHeights,\r\n\t\t\t\titemStates\r\n\t\t\t} = this.getState()\r\n\r\n\t\t\t// See if any items' heights changed while new items were being rendered.\r\n\t\t\tif (this.itemHeightsThatChangedWhileNewItemsWereBeingRendered) {\r\n\t\t\t\tfor (const i of Object.keys(this.itemHeightsThatChangedWhileNewItemsWereBeingRendered)) {\r\n\t\t\t\t\titemHeights[prependedItemsCount + parseInt(i)] = this.itemHeightsThatChangedWhileNewItemsWereBeingRendered[i]\r\n\t\t\t\t}\r\n\t\t\t}\r\n\r\n\t\t\t// See if any items' states changed while new items were being rendered.\r\n\t\t\tif (this.itemStatesThatChangedWhileNewItemsWereBeingRendered) {\r\n\t\t\t\tfor (const i of Object.keys(this.itemStatesThatChangedWhileNewItemsWereBeingRendered)) {\r\n\t\t\t\t\titemStates[prependedItemsCount + parseInt(i)] = this.itemStatesThatChangedWhileNewItemsWereBeingRendered[i]\r\n\t\t\t\t}\r\n\t\t\t}\r\n\r\n\t\t\tif (prependedItemsCount === 0) {\r\n\t\t\t\t// Adjust `this.previouslyCalculatedLayout`.\r\n\t\t\t\tif (this.previouslyCalculatedLayout) {\r\n\t\t\t\t\tif (\r\n\t\t\t\t\t\tthis.previouslyCalculatedLayout.firstShownItemIndex === newLayout.firstShownItemIndex &&\r\n\t\t\t\t\t\tthis.previouslyCalculatedLayout.lastShownItemIndex === newLayout.lastShownItemIndex\r\n\t\t\t\t\t) {\r\n\t\t\t\t\t\t// `this.previouslyCalculatedLayout` stays the same.\r\n\t\t\t\t\t\t// `firstShownItemIndex` / `lastShownItemIndex` didn't get changed in `setItems()`,\r\n\t\t\t\t\t\t// so `beforeItemsHeight` and `shownItemsHeight` also stayed the same.\r\n\t\t\t\t\t} else {\r\n\t\t\t\t\t\twarn('Unexpected (non-matching) \"firstShownItemIndex\" or \"lastShownItemIndex\" encountered in \"onRender()\" after appending items')\r\n\t\t\t\t\t\twarn('Previously calculated layout', this.previouslyCalculatedLayout)\r\n\t\t\t\t\t\twarn('New layout', newLayout)\r\n\t\t\t\t\t\tthis.previouslyCalculatedLayout = undefined\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t\treturn 'SEAMLESS_APPEND'\r\n\t\t\t} else {\r\n\t\t\t\tif (this.listHeightMeasurement.hasSnapshot()) {\r\n\t\t\t\t\tif (newLayout.firstShownItemIndex === 0) {\r\n\t\t\t\t\t\t// Restore (adjust) scroll position.\r\n\t\t\t\t\t\tlog('~ Restore Scroll Position ~')\r\n\t\t\t\t\t\tconst listBottomOffsetChange = this.listHeightMeasurement.getListBottomOffsetChange({\r\n\t\t\t\t\t\t\tbeforeItemsHeight: newLayout.beforeItemsHeight\r\n\t\t\t\t\t\t})\r\n\t\t\t\t\t\tthis.listHeightMeasurement.reset()\r\n\t\t\t\t\t\tif (listBottomOffsetChange) {\r\n\t\t\t\t\t\t\tlog('Scroll down by', listBottomOffsetChange)\r\n\t\t\t\t\t\t\tthis.scroll.scrollByY(listBottomOffsetChange)\r\n\t\t\t\t\t\t} else {\r\n\t\t\t\t\t\t\tlog('Scroll position hasn\\'t changed')\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t\t// Create new `this.previouslyCalculatedLayout`.\r\n\t\t\t\t\t\tif (this.previouslyCalculatedLayout) {\r\n\t\t\t\t\t\t\tif (\r\n\t\t\t\t\t\t\t\tthis.previouslyCalculatedLayout.firstShownItemIndex === 0 &&\r\n\t\t\t\t\t\t\t\tthis.previouslyCalculatedLayout.lastShownItemIndex === newLayout.lastShownItemIndex - prependedItemsCount\r\n\t\t\t\t\t\t\t) {\r\n\t\t\t\t\t\t\t\tthis.previouslyCalculatedLayout = {\r\n\t\t\t\t\t\t\t\t\tbeforeItemsHeight: 0,\r\n\t\t\t\t\t\t\t\t\tshownItemsHeight: this.previouslyCalculatedLayout.shownItemsHeight + listBottomOffsetChange,\r\n\t\t\t\t\t\t\t\t\tfirstShownItemIndex: 0,\r\n\t\t\t\t\t\t\t\t\tlastShownItemIndex: newLayout.lastShownItemIndex\r\n\t\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t\t} else {\r\n\t\t\t\t\t\t\t\twarn('Unexpected (non-matching) \"firstShownItemIndex\" or \"lastShownItemIndex\" encountered in \"onRender()\" after prepending items')\r\n\t\t\t\t\t\t\t\twarn('Previously calculated layout', this.previouslyCalculatedLayout)\r\n\t\t\t\t\t\t\t\twarn('New layout', newLayout)\r\n\t\t\t\t\t\t\t\tthis.previouslyCalculatedLayout = undefined\r\n\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t\treturn 'SEAMLESS_PREPEND'\r\n\t\t\t\t\t} else {\r\n\t\t\t\t\t\twarn(`Unexpected \"firstShownItemIndex\" ${newLayout.firstShownItemIndex} encountered in \"onRender()\" after prepending items. Expected 0.`)\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\t// Reset `this.previouslyCalculatedLayout` in any case other than\r\n\t\t// SEAMLESS_PREPEND or SEAMLESS_APPEND.\r\n\t\tthis.previouslyCalculatedLayout = undefined\r\n\t}\r\n\r\n\tfunction updateStateRightAfterRender({\r\n\t\treason,\r\n\t\tstateUpdate\r\n\t}) {\r\n\t\t// In React, `setTimeout()` is used to prevent a React error:\r\n\t\t// \"Maximum update depth exceeded.\r\n\t\t// This can happen when a component repeatedly calls\r\n\t\t// `.updateState()` inside `componentWillUpdate()` or `componentDidUpdate()`.\r\n\t\t// React limits the number of nested updates to prevent infinite loops.\"\r\n\t\tif (this._useTimeoutInRenderLoop) {\r\n\t\t\t// Cancel a previously scheduled re-layout.\r\n\t\t\tstateUpdate = this.cancelLayoutTimer({ stateUpdate })\r\n\t\t\t// Schedule a new re-layout.\r\n\t\t\tthis.scheduleLayoutTimer({\r\n\t\t\t\treason,\r\n\t\t\t\tstateUpdate\r\n\t\t\t})\r\n\t\t} else {\r\n\t\t\tthis.onUpdateShownItemIndexes({\r\n\t\t\t\treason,\r\n\t\t\t\tstateUpdate\r\n\t\t\t})\r\n\t\t}\r\n\t}\r\n\r\n\tfunction resetStateUpdateFlags() {\r\n\t\t// Read and reset `this.widthHasChanged` flag.\r\n\t\t//\r\n\t\t// If `this.widthHasChanged` flag was reset after calling\r\n\t\t// `this.measureWidthHeightsAndSpacingAndUpdateTablePadding()`\r\n\t\t// then there would be a bug because\r\n\t\t// `this.measureWidthHeightsAndSpacingAndUpdateTablePadding()`\r\n\t\t// calls `this.updateState({ verticalSpacing })` which calls\r\n\t\t// `this.onRender()` immediately, so `this.widthHasChanged`\r\n\t\t// flag wouldn't be reset by that time and would trigger things\r\n\t\t// like `this.itemHeights.reset()` a second time.\r\n\t\t//\r\n\t\t// So, instead read the value of `this.widthHasChanged` flag\r\n\t\t// and reset it right away to prevent any such potential bugs.\r\n\t\t//\r\n\t\tconst widthHasChanged = Boolean(this.widthHasChanged)\r\n\t\t//\r\n\t\t// Reset `this.widthHasChanged` flag.\r\n\t\tthis.widthHasChanged = undefined\r\n\r\n\t\t// Read `this.firstNonMeasuredItemIndex` flag.\r\n\t\tconst nonMeasuredItemsHaveBeenRendered = this.firstNonMeasuredItemIndex !== undefined\r\n\t\t// Reset `this.firstNonMeasuredItemIndex` flag.\r\n\t\tthis.firstNonMeasuredItemIndex = undefined\r\n\r\n\t\t// Reset `this.newItemsWillBeRendered` flag.\r\n\t\tthis.newItemsWillBeRendered = undefined\r\n\r\n\t\t// Reset `this.itemHeightsThatChangedWhileNewItemsWereBeingRendered`.\r\n\t\tthis.itemHeightsThatChangedWhileNewItemsWereBeingRendered = undefined\r\n\r\n\t\t// Reset `this.itemStatesThatChangedWhileNewItemsWereBeingRendered`.\r\n\t\tthis.itemStatesThatChangedWhileNewItemsWereBeingRendered = undefined\r\n\r\n\t\treturn {\r\n\t\t\tnonMeasuredItemsHaveBeenRendered,\r\n\t\t\twidthHasChanged\r\n\t\t}\r\n\t}\r\n}"],"mappings":";;;;;;;;;AAAA;;AACA;;AACA;;AACA;;AACA;;;;;;;;;;;;;;AAEe,oBAAW;EAAA;;EACzB;AACD;AACA;AACA;AACA;EACC,KAAKA,SAAL,GAAiB,UAACC,QAAD,EAAWC,SAAX,EAAyB;IACzC,IAAAC,iBAAA,EAAI,cAAJ;;IACA,IAAI,IAAAC,cAAA,GAAJ,EAAe;MACd,IAAAD,iBAAA,EAAI,OAAJ,EAAa,IAAAE,4BAAA,EAAiBJ,QAAjB,CAAb;IACA;;IAED,IAAI,KAAI,CAACK,aAAT,EAAwB;MACvB,IAAI,CAAC,IAAAC,wBAAA,EAAaN,QAAb,EAAuBC,SAAvB,CAAL,EAAwC;QACvC,KAAI,CAACI,aAAL,CAAmBL,QAAnB;MACA;IACD,CAVwC,CAYzC;IACA;IACA;;;IACA,IAAI,KAAI,CAACO,KAAT,EAAgB;MACf,IAAAC,sBAAA,EACC,KAAI,CAACC,wBAAL,EADD,EAECT,QAAQ,CAACU,iBAFV,EAGCV,QAAQ,CAACW,gBAHV;IAKA;;IAED,IAAI,CAACV,SAAL,EAAgB;MACf;IACA,CAzBwC,CA2BzC;IACA;;;IACA,4BAGIW,qBAAqB,CAACC,IAAtB,CAA2B,KAA3B,CAHJ;IA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irtualScroller.onRender.js","names":["_onRender","newState","prevState","waitingForRender","log","isDebug","getStateSnapshot","onStateChange","shallowEqual","tbody","setTbodyPadding","getItemsContainerElement","beforeItemsHeight","afterItemsHeight","mostRecentSetStateValue","warn","reportError","resetStateUpdateFlags","call","nonMeasuredItemsHaveBeenRendered","itemHeightHasChanged","widthHasChanged","layoutUpdateReason","updateLayoutAfterRenderBecauseItemHeightChanged","LAYOUT_REASON","ITEM_HEIGHT_CHANGED","NON_MEASURED_ITEMS_HAVE_BEEN_MEASURED","VIEWPORT_WIDTH_CHANGED","itemHeights","reset","verticalSpacing","undefined","previousItems","items","newItems","itemsDiff","getItemsDiff","prependedItemsCount","onPrepend","onNewItemsRendered","ITEMS_CHANGED","stateUpdate","firstShownItemIndex","lastShownItemIndex","verticalSpacingStateUpdate","measureItemHeightsAndSpacing","cleanedUpBeforeResize","beforeResize","cleanUpBeforeResizeItemHeights","scrollBy","scroll","scrollByY","_isActive","_stoppedStateUpdate","updateStateRightAfterRender","reason","updateState","newLayout","appendedItemsCount","getState","itemStates","itemHeightsThatChangedWhileNewItemsWereBeingRendered","Object","keys","i","Number","itemStatesThatChangedWhileNewItemsWereBeingRendered","previouslyCalculatedLayout","listHeightMeasurement","hasSnapshot","listBottomOffsetChange","getListBottomOffsetChange","shownItemsHeight","_useTimeoutInRenderLoop","cancelLayoutTimer","scheduleLayoutTimer","onUpdateShownItemIndexes","Boolean","firstNonMeasuredItemIndex","newItemsWillBeRendered"],"sources":["../source/VirtualScroller.onRender.js"],"sourcesContent":["import log, { warn, reportError, isDebug } from './utility/debug.js'\r\nimport getStateSnapshot from './utility/getStateSnapshot.js'\r\nimport shallowEqual from './utility/shallowEqual.js'\r\nimport { LAYOUT_REASON } from './Layout.js'\r\nimport { setTbodyPadding } from './DOM/tbody.js'\r\n\r\nexport default function() {\r\n\t/**\r\n\t * Should be called right after updates to `state` have been rendered.\r\n\t * @param {object} newState\r\n\t * @param {object} [prevState]\r\n\t */\r\n\tthis._onRender = (newState, prevState) => {\r\n\t\tthis.waitingForRender = false\r\n\r\n\t\tlog('~ Rendered ~')\r\n\t\tif (isDebug()) {\r\n\t\t\tlog('State', getStateSnapshot(newState))\r\n\t\t}\r\n\r\n\t\tif (this.onStateChange) {\r\n\t\t\tif (!shallowEqual(newState, prevState)) {\r\n\t\t\t\tthis.onStateChange(newState)\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\t// Update `<tbody/>` `padding`.\r\n\t\t// (`<tbody/>` is different in a way that it can't have `margin`, only `padding`).\r\n\t\t// https://gitlab.com/catamphetamine/virtual-scroller/-/issues/1\r\n\t\tif (this.tbody) {\r\n\t\t\tsetTbodyPadding(\r\n\t\t\t\tthis.getItemsContainerElement(),\r\n\t\t\t\tnewState.beforeItemsHeight,\r\n\t\t\t\tnewState.afterItemsHeight\r\n\t\t\t)\r\n\t\t}\r\n\r\n\t\t// `this.mostRecentlySetState` checks that state management behavior is correct:\r\n\t\t// that in situations when there're multiple new states waiting to be set,\r\n\t\t// only the latest one gets applied.\r\n\t\t// It keeps the code simpler and prevents possible race condition bugs.\r\n\t\t// For example, `VirtualScroller` keeps track of its latest requested\r\n\t\t// state update in different instance variable flags which assume that\r\n\t\t// only that latest requested state update gets actually applied.\r\n\t\t//\r\n\t\t// This check should also be performed for the initial render in order to\r\n\t\t// guarantee that no potentially incorrect state update goes unnoticed.\r\n\t\t// Incorrect state updates could happen when `VirtualScroller` state\r\n\t\t// is managed externally by passing `getState()`/`updateState()` options.\r\n\t\t//\r\n\t\t// Perform the check only when `this.mostRecentSetStateValue` is defined.\r\n\t\t// `this.mostRecentSetStateValue` is normally gonna be `undefined` at the initial render\r\n\t\t// because the initial state is not set by calling `this.updateState()`.\r\n\t\t// At the same time, it is possible that the initial render is delayed\r\n\t\t// for whatever reason, and `this.updateState()` gets called before the initial render,\r\n\t\t// so `this.mostRecentSetStateValue` could also be defined at the initial render,\r\n\t\t// in which case the check should be performed.\r\n\t\t//\r\n\t\tif (this.mostRecentSetStateValue) {\r\n\t\t\t// \"Shallow equality\" is used here instead of \"strict equality\"\r\n\t\t\t// because a developer might choose to supply an `updateState()` function\r\n\t\t\t// rather than a `setState()` function, in which case the `updateState()` function\r\n\t\t\t// would construct its own state object.\r\n\t\t\tif (!shallowEqual(newState, this.mostRecentSetStateValue)) {\r\n\t\t\t\twarn('The most recent state that was set', getStateSnapshot(this.mostRecentSetStateValue))\r\n\t\t\t\treportError('The state that has been rendered is not the most recent one that was set')\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\t// `this.resetStateUpdateFlags()` must be called before calling\r\n\t\t// `this.measureItemHeightsAndSpacing()`.\r\n\t\tconst {\r\n\t\t\tnonMeasuredItemsHaveBeenRendered,\r\n\t\t\titemHeightHasChanged,\r\n\t\t\twidthHasChanged\r\n\t\t} = resetStateUpdateFlags.call(this)\r\n\r\n\t\tlet layoutUpdateReason\r\n\r\n\t\tif (this.updateLayoutAfterRenderBecauseItemHeightChanged) {\r\n\t\t\tlayoutUpdateReason = LAYOUT_REASON.ITEM_HEIGHT_CHANGED\r\n\t\t}\r\n\r\n\t\tif (!prevState) {\r\n\t\t\tif (!layoutUpdateReason) {\r\n\t\t\t\treturn\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\t// If the `VirtualScroller`, while calculating layout parameters, encounters\r\n\t\t// a not-shown item with a non-measured height, it calls `updateState()` just to\r\n\t\t// render that item first, and then, after the list has been re-rendered, it measures\r\n\t\t// the item's height and then proceeds with calculating the correct layout parameters.\r\n\t\tif (nonMeasuredItemsHaveBeenRendered) {\r\n\t\t\tlayoutUpdateReason = LAYOUT_REASON.NON_MEASURED_ITEMS_HAVE_BEEN_MEASURED\r\n\t\t}\r\n\r\n\t\t// If scrollable container width has changed, and it has been re-rendered,\r\n\t\t// then it's time to measure the new item heights and then perform a re-layout\r\n\t\t// with the correctly calculated layout parameters.\r\n\t\t//\r\n\t\t// A re-layout is required because the layout parameters calculated on resize\r\n\t\t// are approximate ones, and the exact item heights aren't known at that point.\r\n\t\t// So on resize, it calls `updateState()` just to re-render the `VirtualScroller`.\r\n\t\t// After it has been re-rendered, it will measure item heights and then calculate\r\n\t\t// correct layout parameters.\r\n\t\t//\r\n\t\tif (widthHasChanged) {\r\n\t\t\tlayoutUpdateReason = LAYOUT_REASON.VIEWPORT_WIDTH_CHANGED\r\n\r\n\t\t\t// Reset measured item heights on viewport width change.\r\n\t\t\tthis.itemHeights.reset()\r\n\r\n\t\t\t// Reset `verticalSpacing` (will be re-measured).\r\n\t\t\tthis.verticalSpacing = undefined\r\n\t\t}\r\n\r\n\t\tif (prevState) {\r\n\t\t\tconst { items: previousItems } = prevState\r\n\t\t\tconst { items: newItems } = newState\r\n\t\t\t// Even if `this.newItemsWillBeRendered` flag is `true`,\r\n\t\t\t// `newItems` could still be equal to `previousItems`.\r\n\t\t\t// For example, when `updateState()` calls don't update `state` immediately\r\n\t\t\t// and a developer first calls `setItems(newItems)` and then calls `setItems(oldItems)`:\r\n\t\t\t// in that case, `this.newItemsWillBeRendered` flag will be `true` but the actual `items`\r\n\t\t\t// in state wouldn't have changed due to the first `updateState()` call being overwritten\r\n\t\t\t// by the second `updateState()` call (that's called \"batching state updates\" in React).\r\n\t\t\tif (newItems !== previousItems) {\r\n\t\t\t\tconst itemsDiff = this.getItemsDiff(previousItems, newItems)\r\n\t\t\t\tif (itemsDiff) {\r\n\t\t\t\t\t// The call to `.onPrepend()` must precede the call to `.measureItemHeights()`\r\n\t\t\t\t\t// which is called in `.onRender()`.\r\n\t\t\t\t\t// `this.itemHeights.onPrepend()` updates `firstMeasuredItemIndex`\r\n\t\t\t\t\t// and `lastMeasuredItemIndex` of `this.itemHeights`.\r\n\t\t\t\t\tconst { prependedItemsCount } = itemsDiff\r\n\t\t\t\t\tthis.itemHeights.onPrepend(prependedItemsCount)\r\n\t\t\t\t} else {\r\n\t\t\t\t\tthis.itemHeights.reset()\r\n\t\t\t\t}\r\n\r\n\t\t\t\tif (!widthHasChanged) {\r\n\t\t\t\t\t// The call to `this.onNewItemsRendered()` must precede the call to\r\n\t\t\t\t\t// `.measureItemHeights()` which is called in `.onRender()` because\r\n\t\t\t\t\t// `this.onNewItemsRendered()` updates `firstMeasuredItemIndex` and\r\n\t\t\t\t\t// `lastMeasuredItemIndex` of `this.itemHeights` in case of a prepend.\r\n\t\t\t\t\t//\r\n\t\t\t\t\t// If after prepending items the scroll position\r\n\t\t\t\t\t// should be \"restored\" so that there's no \"jump\" of content\r\n\t\t\t\t\t// then it means that all previous items have just been rendered\r\n\t\t\t\t\t// in a single pass, and there's no need to update layout again.\r\n\t\t\t\t\t//\r\n\t\t\t\t\tif (onNewItemsRendered.call(this, itemsDiff, newState) !== 'SEAMLESS_PREPEND') {\r\n\t\t\t\t\t\tlayoutUpdateReason = LAYOUT_REASON.ITEMS_CHANGED\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tlet stateUpdate\r\n\r\n\t\t// Re-measure item heights.\r\n\t\t// Also, measure vertical spacing (if not measured) and fix `<table/>` padding.\r\n\t\t//\r\n\t\t// This block should go after `if (newItems !== previousItems) {}`\r\n\t\t// because `this.itemHeights` can get `.reset()` there, which would\r\n\t\t// discard all the measurements done here, and having currently shown\r\n\t\t// item height measurements is required.\r\n\t\t//\r\n\t\tif (\r\n\t\t\t(prevState && (\r\n\t\t\t\tnewState.firstShownItemIndex !== prevState.firstShownItemIndex ||\r\n\t\t\t\tnewState.lastShownItemIndex !== prevState.lastShownItemIndex ||\r\n\t\t\t\tnewState.items !== prevState.items\r\n\t\t\t)) ||\r\n\t\t\twidthHasChanged\r\n\t\t) {\r\n\t\t\tconst verticalSpacingStateUpdate = this.measureItemHeightsAndSpacing()\r\n\t\t\tif (verticalSpacingStateUpdate) {\r\n\t\t\t\tstateUpdate = {\r\n\t\t\t\t\t...stateUpdate,\r\n\t\t\t\t\t...verticalSpacingStateUpdate\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\t// Clean up \"before resize\" item heights and adjust the scroll position accordingly.\r\n\t\t// Calling `this.beforeResize.cleanUpBeforeResizeItemHeights()` might trigger\r\n\t\t// a `this.updateState()` call but that wouldn't matter because `beforeResize`\r\n\t\t// properties have already been modified directly in `state` (a hacky technique)\r\n\t\tconst cleanedUpBeforeResize = this.beforeResize.cleanUpBeforeResizeItemHeights()\r\n\t\tif (cleanedUpBeforeResize !== undefined) {\r\n\t\t\tconst { scrollBy, beforeResize } = cleanedUpBeforeResize\r\n\t\t\tlog('Correct scroll position by', scrollBy)\r\n\t\t\tthis.scroll.scrollByY(scrollBy)\r\n\t\t\tstateUpdate = {\r\n\t\t\t\t...stateUpdate,\r\n\t\t\t\tbeforeResize\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tif (!this._isActive) {\r\n\t\t\tthis._stoppedStateUpdate = stateUpdate\r\n\t\t\treturn\r\n\t\t}\r\n\r\n\t\tif (layoutUpdateReason) {\r\n\t\t\tupdateStateRightAfterRender.call(this, {\r\n\t\t\t\tstateUpdate,\r\n\t\t\t\treason: layoutUpdateReason\r\n\t\t\t})\r\n\t\t} else if (stateUpdate) {\r\n\t\t\tthis.updateState(stateUpdate)\r\n\t\t} else {\r\n\t\t\tlog('~ Finished Layout ~')\r\n\t\t}\r\n\t}\r\n\r\n\t// After a new set of items has been rendered:\r\n\t//\r\n\t// * Restores scroll position when using `preserveScrollPositionOnPrependItems`\r\n\t// and items have been prepended.\r\n\t//\r\n\t// * Applies any \"pending\" `itemHeights` updates — those ones that happened\r\n\t// while an asynchronous `updateState()` call in `setItems()` was pending.\r\n\t//\r\n\t// * Either creates or resets the snapshot of the current layout.\r\n\t//\r\n\t// The current layout snapshot could be stored as a \"previously calculated layout\" variable\r\n\t// so that it could theoretically be used when calculating new layout incrementally\r\n\t// rather than from scratch, which would be an optimization.\r\n\t//\r\n\t// The \"previously calculated layout\" feature is not currently used.\r\n\t//\r\n\tfunction onNewItemsRendered(itemsDiff, newLayout) {\r\n\t\t// If it's an \"incremental\" update.\r\n\t\tif (itemsDiff) {\r\n\t\t\tconst {\r\n\t\t\t\tprependedItemsCount,\r\n\t\t\t\tappendedItemsCount\r\n\t\t\t} = itemsDiff\r\n\r\n\t\t\tconst {\r\n\t\t\t\titemHeights,\r\n\t\t\t\titemStates\r\n\t\t\t} = this.getState()\r\n\r\n\t\t\t// See if any items' heights changed while new items were being rendered.\r\n\t\t\tif (this.itemHeightsThatChangedWhileNewItemsWereBeingRendered) {\r\n\t\t\t\tfor (const i of Object.keys(this.itemHeightsThatChangedWhileNewItemsWereBeingRendered)) {\r\n\t\t\t\t\titemHeights[prependedItemsCount + Number(i)] = this.itemHeightsThatChangedWhileNewItemsWereBeingRendered[i]\r\n\t\t\t\t}\r\n\t\t\t}\r\n\r\n\t\t\t// See if any items' states changed while new items were being rendered.\r\n\t\t\tif (this.itemStatesThatChangedWhileNewItemsWereBeingRendered) {\r\n\t\t\t\tfor (const i of Object.keys(this.itemStatesThatChangedWhileNewItemsWereBeingRendered)) {\r\n\t\t\t\t\titemStates[prependedItemsCount + Number(i)] = this.itemStatesThatChangedWhileNewItemsWereBeingRendered[i]\r\n\t\t\t\t}\r\n\t\t\t}\r\n\r\n\t\t\tif (prependedItemsCount === 0) {\r\n\t\t\t\t// Adjust `this.previouslyCalculatedLayout`.\r\n\t\t\t\tif (this.previouslyCalculatedLayout) {\r\n\t\t\t\t\tif (\r\n\t\t\t\t\t\tthis.previouslyCalculatedLayout.firstShownItemIndex === newLayout.firstShownItemIndex &&\r\n\t\t\t\t\t\tthis.previouslyCalculatedLayout.lastShownItemIndex === newLayout.lastShownItemIndex\r\n\t\t\t\t\t) {\r\n\t\t\t\t\t\t// `this.previouslyCalculatedLayout` stays the same.\r\n\t\t\t\t\t\t// `firstShownItemIndex` / `lastShownItemIndex` didn't get changed in `setItems()`,\r\n\t\t\t\t\t\t// so `beforeItemsHeight` and `shownItemsHeight` also stayed the same.\r\n\t\t\t\t\t} else {\r\n\t\t\t\t\t\twarn('Unexpected (non-matching) \"firstShownItemIndex\" or \"lastShownItemIndex\" encountered in \"onRender()\" after appending items')\r\n\t\t\t\t\t\twarn('Previously calculated layout', this.previouslyCalculatedLayout)\r\n\t\t\t\t\t\twarn('New layout', newLayout)\r\n\t\t\t\t\t\tthis.previouslyCalculatedLayout = undefined\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t\treturn 'SEAMLESS_APPEND'\r\n\t\t\t} else {\r\n\t\t\t\tif (this.listHeightMeasurement.hasSnapshot()) {\r\n\t\t\t\t\tif (newLayout.firstShownItemIndex === 0) {\r\n\t\t\t\t\t\t// Restore (adjust) scroll position.\r\n\t\t\t\t\t\tlog('~ Restore Scroll Position ~')\r\n\t\t\t\t\t\tconst listBottomOffsetChange = this.listHeightMeasurement.getListBottomOffsetChange({\r\n\t\t\t\t\t\t\tbeforeItemsHeight: newLayout.beforeItemsHeight\r\n\t\t\t\t\t\t})\r\n\t\t\t\t\t\tthis.listHeightMeasurement.reset()\r\n\t\t\t\t\t\tif (listBottomOffsetChange) {\r\n\t\t\t\t\t\t\tlog('Scroll down by', listBottomOffsetChange)\r\n\t\t\t\t\t\t\tthis.scroll.scrollByY(listBottomOffsetChange)\r\n\t\t\t\t\t\t} else {\r\n\t\t\t\t\t\t\tlog('Scroll position hasn\\'t changed')\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t\t// Create new `this.previouslyCalculatedLayout`.\r\n\t\t\t\t\t\tif (this.previouslyCalculatedLayout) {\r\n\t\t\t\t\t\t\tif (\r\n\t\t\t\t\t\t\t\tthis.previouslyCalculatedLayout.firstShownItemIndex === 0 &&\r\n\t\t\t\t\t\t\t\tthis.previouslyCalculatedLayout.lastShownItemIndex === newLayout.lastShownItemIndex - prependedItemsCount\r\n\t\t\t\t\t\t\t) {\r\n\t\t\t\t\t\t\t\tthis.previouslyCalculatedLayout = {\r\n\t\t\t\t\t\t\t\t\tbeforeItemsHeight: 0,\r\n\t\t\t\t\t\t\t\t\tshownItemsHeight: this.previouslyCalculatedLayout.shownItemsHeight + listBottomOffsetChange,\r\n\t\t\t\t\t\t\t\t\tfirstShownItemIndex: 0,\r\n\t\t\t\t\t\t\t\t\tlastShownItemIndex: newLayout.lastShownItemIndex\r\n\t\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t\t} else {\r\n\t\t\t\t\t\t\t\twarn('Unexpected (non-matching) \"firstShownItemIndex\" or \"lastShownItemIndex\" encountered in \"onRender()\" after prepending items')\r\n\t\t\t\t\t\t\t\twarn('Previously calculated layout', this.previouslyCalculatedLayout)\r\n\t\t\t\t\t\t\t\twarn('New layout', newLayout)\r\n\t\t\t\t\t\t\t\tthis.previouslyCalculatedLayout = undefined\r\n\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t\treturn 'SEAMLESS_PREPEND'\r\n\t\t\t\t\t} else {\r\n\t\t\t\t\t\twarn(`Unexpected \"firstShownItemIndex\" ${newLayout.firstShownItemIndex} encountered in \"onRender()\" after prepending items. Expected 0.`)\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\t// Reset `this.previouslyCalculatedLayout` in any case other than\r\n\t\t// SEAMLESS_PREPEND or SEAMLESS_APPEND.\r\n\t\tthis.previouslyCalculatedLayout = undefined\r\n\t}\r\n\r\n\tfunction updateStateRightAfterRender({\r\n\t\treason,\r\n\t\tstateUpdate\r\n\t}) {\r\n\t\t// In React, `setTimeout()` is used to prevent a React error:\r\n\t\t// \"Maximum update depth exceeded.\r\n\t\t// This can happen when a component repeatedly calls\r\n\t\t// `.updateState()` inside `componentWillUpdate()` or `componentDidUpdate()`.\r\n\t\t// React limits the number of nested updates to prevent infinite loops.\"\r\n\t\tif (this._useTimeoutInRenderLoop) {\r\n\t\t\t// Cancel a previously scheduled re-layout.\r\n\t\t\tstateUpdate = this.cancelLayoutTimer({ stateUpdate })\r\n\t\t\t// Schedule a new re-layout.\r\n\t\t\tthis.scheduleLayoutTimer({\r\n\t\t\t\treason,\r\n\t\t\t\tstateUpdate\r\n\t\t\t})\r\n\t\t} else {\r\n\t\t\tthis.onUpdateShownItemIndexes({\r\n\t\t\t\treason,\r\n\t\t\t\tstateUpdate\r\n\t\t\t})\r\n\t\t}\r\n\t}\r\n\r\n\tfunction resetStateUpdateFlags() {\r\n\t\t// Read and reset `this.widthHasChanged` flag.\r\n\t\t//\r\n\t\t// If `this.widthHasChanged` flag was reset after calling\r\n\t\t// `this.measureWidthHeightsAndSpacingAndUpdateTablePadding()`\r\n\t\t// then there would be a bug because\r\n\t\t// `this.measureWidthHeightsAndSpacingAndUpdateTablePadding()`\r\n\t\t// calls `this.updateState({ verticalSpacing })` which calls\r\n\t\t// `this.onRender()` immediately, so `this.widthHasChanged`\r\n\t\t// flag wouldn't be reset by that time and would trigger things\r\n\t\t// like `this.itemHeights.reset()` a second time.\r\n\t\t//\r\n\t\t// So, instead read the value of `this.widthHasChanged` flag\r\n\t\t// and reset it right away to prevent any such potential bugs.\r\n\t\t//\r\n\t\tconst widthHasChanged = Boolean(this.widthHasChanged)\r\n\t\t//\r\n\t\t// Reset `this.widthHasChanged` flag.\r\n\t\tthis.widthHasChanged = undefined\r\n\r\n\t\t// Read `this.firstNonMeasuredItemIndex` flag.\r\n\t\tconst nonMeasuredItemsHaveBeenRendered = this.firstNonMeasuredItemIndex !== undefined\r\n\t\tif (nonMeasuredItemsHaveBeenRendered) {\r\n\t\t\tlog('Non-measured item index', this.firstNonMeasuredItemIndex)\r\n\t\t}\r\n\t\t// Reset `this.firstNonMeasuredItemIndex` flag.\r\n\t\tthis.firstNonMeasuredItemIndex = undefined\r\n\r\n\t\t// Reset `this.newItemsWillBeRendered` flag.\r\n\t\tthis.newItemsWillBeRendered = undefined\r\n\r\n\t\t// Reset `this.itemHeightsThatChangedWhileNewItemsWereBeingRendered`.\r\n\t\tthis.itemHeightsThatChangedWhileNewItemsWereBeingRendered = undefined\r\n\r\n\t\t// Reset `this.itemStatesThatChangedWhileNewItemsWereBeingRendered`.\r\n\t\tthis.itemStatesThatChangedWhileNewItemsWereBeingRendered = undefined\r\n\r\n\t\t// Reset `this.updateLayoutAfterRenderBecauseItemHeightChanged`.\r\n\t\tconst itemHeightHasChanged = this.updateLayoutAfterRenderBecauseItemHeightChanged\r\n\t\tthis.updateLayoutAfterRenderBecauseItemHeightChanged = undefined\r\n\r\n\t\treturn {\r\n\t\t\tnonMeasuredItemsHaveBeenRendered,\r\n\t\t\titemHeightHasChanged,\r\n\t\t\twidthHasChanged\r\n\t\t}\r\n\t}\r\n}"],"mappings":";;;;;;;;;AAAA;;AACA;;AACA;;AACA;;AACA;;;;;;;;;;;;;;AAEe,oBAAW;EAAA;;EACzB;AACD;AACA;AACA;AACA;EACC,KAAKA,SAAL,GAAiB,UAACC,QAAD,EAAWC,SAAX,EAAyB;IACzC,KAAI,CAACC,gBAAL,GAAwB,KAAxB;IAEA,IAAAC,iBAAA,EAAI,cAAJ;;IACA,IAAI,IAAAC,cAAA,GAAJ,EAAe;MACd,IAAAD,iBAAA,EAAI,OAAJ,EAAa,IAAAE,4BAAA,EAAiBL,QAAjB,CAAb;IACA;;IAED,IAAI,KAAI,CAACM,aAAT,EAAwB;MACvB,IAAI,CAAC,IAAAC,wBAAA,EAAaP,QAAb,EAAuBC,SAAvB,CAAL,EAAwC;QACvC,KAAI,CAACK,aAAL,CAAmBN,QAAnB;MACA;IACD,CAZwC,CAczC;IACA;IACA;;;IACA,IAAI,KAAI,CAACQ,KAAT,EAAgB;MACf,IAAAC,sBAAA,EACC,KAAI,CAACC,wBAAL,EADD,EAECV,QAAQ,CAACW,iBAFV,EAGCX,QAAQ,CAACY,gBAHV;IAKA,CAvBwC,CAyBzC;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;;;IACA,IAAI,KAAI,CAACC,uBAAT,EAAkC;MACjC;MACA;MACA;MACA;MACA,IAAI,CAAC,IAAAN,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;IACA;IACA;IACA;IACA;IACA,IAAMI,eAAe,GAAGwD,OAAO,CAAC,KAAKxD,eAAN,CAA/B,CAfgC,CAgBhC;IACA;;IACA,KAAKA,eAAL,GAAuBU,SAAvB,CAlBgC,CAoBhC;;IACA,IAAMZ,gCAAgC,GAAG,KAAK2D,yBAAL,KAAmC/C,SAA5E;;IACA,IAAIZ,gCAAJ,EAAsC;MACrC,IAAAf,iBAAA,EAAI,yBAAJ,EAA+B,KAAK0E,yBAApC;IACA,CAxB+B,CAyBhC;;;IACA,KAAKA,yBAAL,GAAiC/C,SAAjC,CA1BgC,CA4BhC;;IACA,KAAKgD,sBAAL,GAA8BhD,SAA9B,CA7BgC,CA+BhC;;IACA,KAAK8B,oDAAL,GAA4D9B,SAA5D,CAhCgC,CAkChC;;IACA,KAAKmC,mDAAL,GAA2DnC,SAA3D,CAnCgC,CAqChC;;IACA,IAAMX,oBAAoB,GAAG,KAAKG,+CAAlC;IACA,KAAKA,+CAAL,GAAuDQ,SAAvD;IAEA,OAAO;MACNZ,gCAAgC,EAAhCA,gCADM;MAENC,oBAAoB,EAApBA,oBAFM;MAGNC,eAAe,EAAfA;IAHM,CAAP;EAKA;AACD"}
|
|
@@ -73,7 +73,13 @@ function createStateHelpers(_ref) {
|
|
|
73
73
|
(0, _debug["default"])('New state' + '\n' + JSON.stringify(newItemState, null, 2));
|
|
74
74
|
}
|
|
75
75
|
|
|
76
|
-
_this.getState().itemStates[i] = newItemState; //
|
|
76
|
+
_this.getState().itemStates[i] = newItemState; // If there was a request for `setState()` with new `items`, then the changes
|
|
77
|
+
// to `currentState.itemStates[]` made above would be overwritten when that
|
|
78
|
+
// pending `setState()` call gets applied.
|
|
79
|
+
// To fix that, the updates to current `itemStates[]` are noted in
|
|
80
|
+
// `this.itemStatesThatChangedWhileNewItemsWereBeingRendered` variable.
|
|
81
|
+
// That variable is then checked when the `setState()` call with the new `items`
|
|
82
|
+
// has been updated.
|
|
77
83
|
|
|
78
84
|
if (_this.newItemsWillBeRendered) {
|
|
79
85
|
if (!_this.itemStatesThatChangedWhileNewItemsWereBeingRendered) {
|
|
@@ -102,11 +108,20 @@ function createStateHelpers(_ref) {
|
|
|
102
108
|
}
|
|
103
109
|
}
|
|
104
110
|
|
|
105
|
-
_this._isSettingNewItems = undefined;
|
|
111
|
+
_this._isSettingNewItems = undefined;
|
|
112
|
+
_this.waitingForRender = true; // Store previous `state`.
|
|
106
113
|
|
|
107
|
-
_this.previousState = _this.getState();
|
|
114
|
+
_this.previousState = _this.getState(); // If it's the first call to `this.updateState()` then initialize
|
|
115
|
+
// the most recent `setState()` value to be the current state.
|
|
108
116
|
|
|
109
|
-
_this.
|
|
117
|
+
if (!_this.mostRecentSetStateValue) {
|
|
118
|
+
_this.mostRecentSetStateValue = _this.getState();
|
|
119
|
+
} // Accumulates all "pending" state updates until they have been applied.
|
|
120
|
+
|
|
121
|
+
|
|
122
|
+
_this.mostRecentSetStateValue = _objectSpread(_objectSpread({}, _this.mostRecentSetStateValue), stateUpdate); // Update `state`.
|
|
123
|
+
|
|
124
|
+
_this._setState(_this.mostRecentSetStateValue, stateUpdate);
|
|
110
125
|
};
|
|
111
126
|
|
|
112
127
|
this.getInitialState = function () {
|
|
@@ -121,6 +136,7 @@ function createStateHelpers(_ref) {
|
|
|
121
136
|
|
|
122
137
|
this.useState = function (_ref2) {
|
|
123
138
|
var getState = _ref2.getState,
|
|
139
|
+
setState = _ref2.setState,
|
|
124
140
|
updateState = _ref2.updateState;
|
|
125
141
|
|
|
126
142
|
if (_this._isActive) {
|
|
@@ -132,26 +148,37 @@ function createStateHelpers(_ref) {
|
|
|
132
148
|
}
|
|
133
149
|
|
|
134
150
|
if (render) {
|
|
135
|
-
throw new Error('[virtual-scroller] Creating a `VirtualScroller` class instance with a `render()` parameter
|
|
151
|
+
throw new Error('[virtual-scroller] Creating a `VirtualScroller` class instance with a `render()` parameter implies using the default (internal) state storage');
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
if (setState && updateState) {
|
|
155
|
+
throw new Error('[virtual-scroller] When using a custom state storage, one must supply either `setState()` or `updateState()` function but not both');
|
|
136
156
|
}
|
|
137
157
|
|
|
138
|
-
if (!getState || !updateState) {
|
|
139
|
-
throw new Error('[virtual-scroller] When using a custom state storage, one must supply both `getState()` and `updateState()` functions');
|
|
158
|
+
if (!getState || !(setState || updateState)) {
|
|
159
|
+
throw new Error('[virtual-scroller] When using a custom state storage, one must supply both `getState()` and `setState()`/`updateState()` functions');
|
|
140
160
|
}
|
|
141
161
|
|
|
142
162
|
_this._usesCustomStateStorage = true;
|
|
143
163
|
_this._getState = getState;
|
|
144
|
-
|
|
164
|
+
|
|
165
|
+
_this._setState = function (newState, stateUpdate) {
|
|
166
|
+
if (setState) {
|
|
167
|
+
setState(newState);
|
|
168
|
+
} else {
|
|
169
|
+
updateState(stateUpdate);
|
|
170
|
+
}
|
|
171
|
+
};
|
|
145
172
|
};
|
|
146
173
|
|
|
147
174
|
this.useDefaultStateStorage = function () {
|
|
148
175
|
if (!render) {
|
|
149
176
|
throw new Error('[virtual-scroller] When using the default (internal) state management, one must supply a `render(state, prevState)` function parameter');
|
|
150
|
-
} // Create default `getState()`/`
|
|
177
|
+
} // Create default `getState()`/`setState()` functions.
|
|
151
178
|
|
|
152
179
|
|
|
153
180
|
_this._getState = defaultGetState.bind(_this);
|
|
154
|
-
_this.
|
|
181
|
+
_this._setState = defaultSetState.bind(_this); // When `state` is stored externally, a developer is responsible for
|
|
155
182
|
// initializing it with the initial value.
|
|
156
183
|
// Otherwise, if default state management is used, set the initial state now.
|
|
157
184
|
|
|
@@ -167,14 +194,19 @@ function createStateHelpers(_ref) {
|
|
|
167
194
|
this.state = newState;
|
|
168
195
|
}
|
|
169
196
|
|
|
170
|
-
function
|
|
171
|
-
// Because
|
|
172
|
-
//
|
|
173
|
-
//
|
|
174
|
-
//
|
|
175
|
-
//
|
|
176
|
-
//
|
|
177
|
-
|
|
197
|
+
function defaultSetState(newState, stateUpdate) {
|
|
198
|
+
// // Because the default state updates are "synchronous" (immediate),
|
|
199
|
+
// // the `...stateUpdate` could be applied over `...this.state`,
|
|
200
|
+
// // and no state updates would be lost.
|
|
201
|
+
// // But if it was "asynchronous" (not immediate), then `...this.state`
|
|
202
|
+
// // wouldn't work in all cases, because it could be stale in cases
|
|
203
|
+
// // when more than a single `setState()` call is made before
|
|
204
|
+
// // the state actually updates, making some properties of `this.state` stale.
|
|
205
|
+
// this.state = {
|
|
206
|
+
// ...this.state,
|
|
207
|
+
// ...stateUpdate
|
|
208
|
+
// }
|
|
209
|
+
this.state = newState;
|
|
178
210
|
render(this.state, this.previousState);
|
|
179
211
|
this.onRender();
|
|
180
212
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"VirtualScroller.state.js","names":["createStateHelpers","initialState","state","getInitialItemState","onStateChange","render","initialItems","items","_render","_setItemState","i","newItemState","isDebug","log","JSON","stringify","getState","itemStates","newItemsWillBeRendered","itemStatesThatChangedWhileNewItemsWereBeingRendered","String","_getState","updateState","stateUpdate","getStateSnapshot","_isSettingNewItems","reportError","undefined","previousState","_updateState","getInitialState","getRestoredState","call","getInitialStateFromScratch","useState","_isActive","Error","_usesCustomStateStorage","useDefaultStateStorage","defaultGetState","bind","defaultUpdateState","setInitialState","defaultSetInitialState","newState","onRender","getInitialLayoutState","beforeStart","fillArray","Array","length","firstShownItemIndex","lastShownItemIndex","cleanUpBeforeResizeState","verticalSpacing","isStateColumnsCountMismatch","columnsCount","getActualColumnsCount","warn","itemsCount","getColumnsCount","layout","getInitialLayoutValueWithFallback","getInitialLayoutValues","beforeItemsHeight","afterItemsHeight","itemHeights","onBeforeShowItems","getActualColumnsCountForState","stateColumnsCount","Math","floor"],"sources":["../source/VirtualScroller.state.js"],"sourcesContent":["import fillArray from './utility/fillArray.js'\r\nimport log, { warn, isDebug, reportError } from './utility/debug.js'\r\nimport { cleanUpBeforeResizeState } from './BeforeResize.js'\r\nimport getStateSnapshot from './utility/getStateSnapshot.js'\r\n\r\n// There're three main places where state is updated:\r\n//\r\n// * On scroll.\r\n// * On window resize.\r\n// * On set new items.\r\n//\r\n// State updates may be \"asynchronous\" (like in React), in which case the\r\n// corresponding operation is \"pending\" until the state update is applied.\r\n//\r\n// If there's a \"pending\" window resize or a \"pending\" update of the set of items,\r\n// then \"on scroll\" updates aren't dispatched.\r\n//\r\n// If there's a \"pending\" on scroll update and the window is resize or a new set\r\n// of items is set, then that \"pending\" on scroll update gets overwritten.\r\n//\r\n// If there's a \"pending\" update of the set of items, then window resize handler\r\n// sees that \"pending\" update and dispatches its own state update so that the\r\n// \"pending\" state update originating from `setItems()` is not lost.\r\n//\r\n// If there's a \"pending\" window resize, and a new set of items is set,\r\n// then the state update of the window resize handler gets overwritten.\r\n\r\nexport default function createStateHelpers({\r\n\tstate: initialState,\r\n\tgetInitialItemState,\r\n\tonStateChange,\r\n\trender,\r\n\titems: initialItems\r\n}) {\r\n\tthis.onStateChange = onStateChange\r\n\tthis._render = render\r\n\r\n\tthis.getInitialItemState = getInitialItemState\r\n\r\n\tthis._setItemState = (i, newItemState) => {\r\n\t\tif (isDebug()) {\r\n\t\t\tlog('~ Item state changed ~')\r\n\t\t\tlog('Item index', i)\r\n\t\t\t// Uses `JSON.stringify()` here instead of just outputting the JSON objects as is\r\n\t\t\t// because outputting JSON objects as is would show different results later when\r\n\t\t\t// the developer inspects those in the web browser console if those state objects\r\n\t\t\t// get modified in between they've been output to the console and the developer\r\n\t\t\t// decided to inspect them.\r\n\t\t\tlog('Previous state' + '\\n' + JSON.stringify(this.getState().itemStates[i], null, 2))\r\n\t\t\tlog('New state' + '\\n' + JSON.stringify(newItemState, null, 2))\r\n\t\t}\r\n\r\n\t\tthis.getState().itemStates[i] = newItemState\r\n\r\n\t\t// Schedule the item state update for after the new items have been rendered.\r\n\t\tif (this.newItemsWillBeRendered) {\r\n\t\t\tif (!this.itemStatesThatChangedWhileNewItemsWereBeingRendered) {\r\n\t\t\t\tthis.itemStatesThatChangedWhileNewItemsWereBeingRendered = {}\r\n\t\t\t}\r\n\t\t\tthis.itemStatesThatChangedWhileNewItemsWereBeingRendered[String(i)] = newItemState\r\n\t\t}\r\n\t}\r\n\r\n\tthis.getState = () => this._getState()\r\n\r\n\tthis.updateState = (stateUpdate) => {\r\n\t\tif (isDebug()) {\r\n\t\t\tlog('~ Set state ~')\r\n\t\t\tlog(getStateSnapshot(stateUpdate))\r\n\t\t}\r\n\r\n\t\t// Ensure that a non-initial `stateUpdate` can only contain an `items`\r\n\t\t// property when it comes from a `setItems()` call.\r\n\t\tif (stateUpdate.items) {\r\n\t\t\tif (!this._isSettingNewItems) {\r\n\t\t\t\treportError('A `stateUpdate` can only contain `items` property as a result of calling `.setItems()`')\r\n\t\t\t}\r\n\t\t}\r\n\t\tthis._isSettingNewItems = undefined\r\n\r\n\t\t// Update `state`.\r\n\t\tthis.previousState = this.getState()\r\n\t\tthis._updateState(stateUpdate)\r\n\t}\r\n\r\n\tthis.getInitialState = () => {\r\n\t\tif (initialState) {\r\n\t\t\treturn getRestoredState.call(this, initialState)\r\n\t\t}\r\n\t\treturn getInitialStateFromScratch.call(this, { getInitialItemState })\r\n\t}\r\n\r\n\tthis.useState = ({\r\n\t\tgetState,\r\n\t\tupdateState\r\n\t}) => {\r\n\t\tif (this._isActive) {\r\n\t\t\tthrow new Error('[virtual-scroller] `VirtualScroller` has already been started')\r\n\t\t}\r\n\r\n\t\tif (this._getState) {\r\n\t\t\tthrow new Error('[virtual-scroller] Custom state storage has already been configured')\r\n\t\t}\r\n\r\n\t\tif (render) {\r\n\t\t\tthrow new Error('[virtual-scroller] Creating a `VirtualScroller` class instance with a `render()` parameter means using the default (internal) state storage')\r\n\t\t}\r\n\r\n\t\tif (!getState || !updateState) {\r\n\t\t\tthrow new Error('[virtual-scroller] When using a custom state storage, one must supply both `getState()` and `updateState()` functions')\r\n\t\t}\r\n\r\n\t\tthis._usesCustomStateStorage = true\r\n\r\n\t\tthis._getState = getState\r\n\t\tthis._updateState = updateState\r\n\t}\r\n\r\n\tthis.useDefaultStateStorage = () => {\r\n\t\tif (!render) {\r\n\t\t\tthrow new Error('[virtual-scroller] When using the default (internal) state management, one must supply a `render(state, prevState)` function parameter')\r\n\t\t}\r\n\r\n\t\t// Create default `getState()`/`updateState()` functions.\r\n\t\tthis._getState = defaultGetState.bind(this)\r\n\t\tthis._updateState = defaultUpdateState.bind(this)\r\n\r\n\t\t// When `state` is stored externally, a developer is responsible for\r\n\t\t// initializing it with the initial value.\r\n\t\t// Otherwise, if default state management is used, set the initial state now.\r\n\t\tconst setInitialState = defaultSetInitialState.bind(this)\r\n\t\tsetInitialState(this.getInitialState())\r\n\t}\r\n\r\n\tfunction defaultGetState() {\r\n\t\treturn this.state\r\n\t}\r\n\r\n\tfunction defaultSetInitialState(newState) {\r\n\t\tthis.state = newState\r\n\t}\r\n\r\n\tfunction defaultUpdateState(stateUpdate) {\r\n\t\t// Because this variant of `.updateState()` is \"synchronous\" (immediate),\r\n\t\t// it can be written like `...prevState`, and no state updates would be lost.\r\n\t\t// But if it was \"asynchronous\" (not immediate), then `...prevState`\r\n\t\t// wouldn't work in all cases, because it could be stale in cases\r\n\t\t// when more than a single `updateState()` call is made before\r\n\t\t// the state actually updates, making `prevState` stale.\r\n\t\tthis.state = {\r\n\t\t\t...this.state,\r\n\t\t\t...stateUpdate\r\n\t\t}\r\n\r\n\t\trender(this.state, this.previousState)\r\n\r\n\t\tthis.onRender()\r\n\t}\r\n\r\n\t/**\r\n\t * Returns the initial state of the `VirtualScroller` \"from scratch\".\r\n\t * (i.e. not from a previously saved one).\r\n\t * @param {function} [options.getInitialItemState] — Gets initial item state.\r\n\t * @return {object}\r\n\t */\r\n\tfunction getInitialStateFromScratch({ getInitialItemState }) {\r\n\t\tconst items = initialItems\r\n\r\n\t\tconst state = {\r\n\t\t\t...getInitialLayoutState.call(this, items, { beforeStart: true }),\r\n\t\t\titems,\r\n\t\t\titemStates: fillArray(new Array(items.length), (i) => getInitialItemState(items[i]))\r\n\t\t}\r\n\r\n\t\tif (isDebug()) {\r\n\t\t\tlog('Initial state (autogenerated)', getStateSnapshot(state))\r\n\t\t}\r\n\t\tlog('First shown item index', state.firstShownItemIndex)\r\n\t\tlog('Last shown item index', state.lastShownItemIndex)\r\n\r\n\t\treturn state\r\n\t}\r\n\r\n\tfunction getRestoredState(state) {\r\n\t\tif (isDebug()) {\r\n\t\t\tlog('Restore state', getStateSnapshot(state))\r\n\t\t}\r\n\r\n\t\t// Possibly clean up \"before resize\" property in state.\r\n\t\t// \"Before resize\" state property is cleaned up when all \"before resize\" item heights\r\n\t\t// have been re-measured in an asynchronous `this.updateState({ beforeResize: undefined })` call.\r\n\t\t// If `VirtualScroller` state was snapshotted externally before that `this.updateState()` call\r\n\t\t// has been applied, then \"before resize\" property might have not been cleaned up properly.\r\n\t\tstate = cleanUpBeforeResizeState(state)\r\n\r\n\t\t// Reset `verticalSpacing` so that it re-measures it after the list\r\n\t\t// has been rendered initially. The rationale is that a previously captured\r\n\t\t// inter-item vertical spacing can't be \"trusted\" in a sense that the user\r\n\t\t// might have resized the window after the previous `state` has been snapshotted.\r\n\t\t// If the user has resized the window, then changing window width might have\r\n\t\t// activated different CSS `@media()` \"queries\" resulting in a potentially different\r\n\t\t// vertical spacing when the `VirtualScroller` is re-created with such previously\r\n\t\t// snapshotted state.\r\n\t\tstate = {\r\n\t\t\t...state,\r\n\t\t\tverticalSpacing: undefined\r\n\t\t}\r\n\r\n\t\t// `this.verticalSpacing` acts as a \"true\" source for vertical spacing value.\r\n\t\t// Vertical spacing is also stored in `state` but `state` updates could be\r\n\t\t// \"asynchronous\" (not applied immediately) and `this.onUpdateShownItemIndexes()`\r\n\t\t// requires vertical spacing to be correct at any time, without any delays.\r\n\t\t// So, vertical spacing is also duplicated in `state`, but the \"true\" source\r\n\t\t// is still `this.verticalSpacing`.\r\n\t\t//\r\n\t\t// `this.verticalSpacing` must be initialized before calling `this.getInitialStateFromScratch()`\r\n\t\t// because `this.getInitialStateFromScratch()` uses `this.verticalSpacing` in its calculations.\r\n\t\t//\r\n\t\t// With the code above, `state.verticalSpacing` is always gonna be `undefined`,\r\n\t\t// so commented out this code. It's safer to just re-measure vertical spacing\r\n\t\t// from scratch when `VirtualScroller` is mounted.\r\n\t\t//\r\n\t\t// this.verticalSpacing = state ? state.verticalSpacing : undefined\r\n\r\n\t\t// Check if the actual `columnsCount` on the screen matches the one from state.\r\n\t\tif (isStateColumnsCountMismatch(state, {\r\n\t\t\tcolumnsCount: this.getActualColumnsCount()\r\n\t\t})) {\r\n\t\t\twarn('Reset Layout')\r\n\t\t\tstate = {\r\n\t\t\t\t...state,\r\n\t\t\t\t...getInitialLayoutState.call(this, state.items, { beforeStart: false })\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\treturn state\r\n\t}\r\n\r\n\tfunction getInitialLayoutState(items, { beforeStart }) {\r\n\t\tconst itemsCount = items.length\r\n\r\n\t\tconst getColumnsCount = () => this.getActualColumnsCount()\r\n\r\n\t\tconst columnsCount = beforeStart\r\n\t\t\t? this.layout.getInitialLayoutValueWithFallback(\r\n\t\t\t\t'columnsCount',\r\n\t\t\t\tgetColumnsCount,\r\n\t\t\t\t1\r\n\t\t\t)\r\n\t\t\t: getColumnsCount()\r\n\r\n\t\tconst {\r\n\t\t\tfirstShownItemIndex,\r\n\t\t\tlastShownItemIndex,\r\n\t\t\tbeforeItemsHeight,\r\n\t\t\tafterItemsHeight\r\n\t\t} = this.layout.getInitialLayoutValues({\r\n\t\t\titemsCount,\r\n\t\t\tcolumnsCount: this.getActualColumnsCount(),\r\n\t\t\tbeforeStart\r\n\t\t})\r\n\r\n\t\tconst itemHeights = new Array(itemsCount)\r\n\r\n\t\t// Optionally preload items to be rendered.\r\n\t\tthis.onBeforeShowItems(\r\n\t\t\titems,\r\n\t\t\titemHeights,\r\n\t\t\tfirstShownItemIndex,\r\n\t\t\tlastShownItemIndex\r\n\t\t)\r\n\r\n\t\treturn {\r\n\t\t\titemHeights,\r\n\t\t\tcolumnsCount: this.getActualColumnsCountForState(),\r\n\t\t\tverticalSpacing: this.verticalSpacing,\r\n\t\t\tfirstShownItemIndex,\r\n\t\t\tlastShownItemIndex,\r\n\t\t\tbeforeItemsHeight,\r\n\t\t\tafterItemsHeight\r\n\t\t}\r\n\t}\r\n\r\n\t// Checks if the actual `columnsCount` on the screen matches the one from state.\r\n\t//\r\n\t// For example, a developer might snapshot `VirtualScroller` state\r\n\t// when the user navigates from the page containing the list\r\n\t// in order to later restore the list's state when the user goes \"Back\".\r\n\t// But, the user might have also resized the window while being on that\r\n\t// \"other\" page, and when they come \"Back\", their snapshotted state\r\n\t// no longer qualifies. Well, it does qualify, but only partially.\r\n\t// For example, `itemStates` are still valid, but first and last shown\r\n\t// item indexes aren't.\r\n\t//\r\n\tfunction isStateColumnsCountMismatch(state, { columnsCount }) {\r\n\t\tconst stateColumnsCount = state.columnsCount || 1\r\n\t\tif (stateColumnsCount !== columnsCount) {\r\n\t\t\twarn('~ Columns Count changed from', stateColumnsCount, 'to', columnsCount, '~')\r\n\t\t\treturn true\r\n\t\t}\r\n\t\tconst firstShownItemIndex = Math.floor(state.firstShownItemIndex / columnsCount) * columnsCount\r\n\t\tif (firstShownItemIndex !== state.firstShownItemIndex) {\r\n\t\t\twarn('~ First Shown Item Index', state.firstShownItemIndex, 'is not divisible by Columns Count', columnsCount, '~')\r\n\t\t\treturn true\r\n\t\t}\r\n\t}\r\n}"],"mappings":";;;;;;;;;AAAA;;AACA;;AACA;;AACA;;;;;;;;;;;;;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAEe,SAASA,kBAAT,OAMZ;EAAA;;EAAA,IALKC,YAKL,QALFC,KAKE;EAAA,IAJFC,mBAIE,QAJFA,mBAIE;EAAA,IAHFC,aAGE,QAHFA,aAGE;EAAA,IAFFC,MAEE,QAFFA,MAEE;EAAA,IADKC,YACL,QADFC,KACE;EACF,K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F;;IACA,IAAIL,mBAAmB,KAAKjD,KAAK,CAACiD,mBAAlC,EAAuD;MACtD,IAAAO,WAAA,EAAK,0BAAL,EAAiCxD,KAAK,CAACiD,mBAAvC,EAA4D,mCAA5D,EAAiGK,YAAjG,EAA+G,GAA/G;MACA,OAAO,IAAP;IACA;EACD;AACD"}
|
|
1
|
+
{"version":3,"file":"VirtualScroller.state.js","names":["createStateHelpers","initialState","state","getInitialItemState","onStateChange","render","initialItems","items","_render","_setItemState","i","newItemState","isDebug","log","JSON","stringify","getState","itemStates","newItemsWillBeRendered","itemStatesThatChangedWhileNewItemsWereBeingRendered","String","_getState","updateState","stateUpdate","getStateSnapshot","_isSettingNewItems","reportError","undefined","waitingForRender","previousState","mostRecentSetStateValue","_setState","getInitialState","getRestoredState","call","getInitialStateFromScratch","useState","setState","_isActive","Error","_usesCustomStateStorage","newState","useDefaultStateStorage","defaultGetState","bind","defaultSetState","setInitialState","defaultSetInitialState","onRender","getInitialLayoutState","beforeStart","fillArray","Array","length","firstShownItemIndex","lastShownItemIndex","cleanUpBeforeResizeState","verticalSpacing","isStateColumnsCountMismatch","columnsCount","getActualColumnsCount","warn","itemsCount","getColumnsCount","layout","getInitialLayoutValueWithFallback","getInitialLayoutValues","beforeItemsHeight","afterItemsHeight","itemHeights","onBeforeShowItems","getActualColumnsCountForState","stateColumnsCount","Math","floor"],"sources":["../source/VirtualScroller.state.js"],"sourcesContent":["import fillArray from './utility/fillArray.js'\r\nimport log, { warn, isDebug, reportError } from './utility/debug.js'\r\nimport { cleanUpBeforeResizeState } from './BeforeResize.js'\r\nimport getStateSnapshot from './utility/getStateSnapshot.js'\r\n\r\n// There're three main places where state is updated:\r\n//\r\n// * On scroll.\r\n// * On window resize.\r\n// * On set new items.\r\n//\r\n// State updates may be \"asynchronous\" (like in React), in which case the\r\n// corresponding operation is \"pending\" until the state update is applied.\r\n//\r\n// If there's a \"pending\" window resize or a \"pending\" update of the set of items,\r\n// then \"on scroll\" updates aren't dispatched.\r\n//\r\n// If there's a \"pending\" on scroll update and the window is resize or a new set\r\n// of items is set, then that \"pending\" on scroll update gets overwritten.\r\n//\r\n// If there's a \"pending\" update of the set of items, then window resize handler\r\n// sees that \"pending\" update and dispatches its own state update so that the\r\n// \"pending\" state update originating from `setItems()` is not lost.\r\n//\r\n// If there's a \"pending\" window resize, and a new set of items is set,\r\n// then the state update of the window resize handler gets overwritten.\r\n\r\nexport default function createStateHelpers({\r\n\tstate: initialState,\r\n\tgetInitialItemState,\r\n\tonStateChange,\r\n\trender,\r\n\titems: initialItems\r\n}) {\r\n\tthis.onStateChange = onStateChange\r\n\tthis._render = render\r\n\r\n\tthis.getInitialItemState = getInitialItemState\r\n\r\n\tthis._setItemState = (i, newItemState) => {\r\n\t\tif (isDebug()) {\r\n\t\t\tlog('~ Item state changed ~')\r\n\t\t\tlog('Item index', i)\r\n\t\t\t// Uses `JSON.stringify()` here instead of just outputting the JSON objects as is\r\n\t\t\t// because outputting JSON objects as is would show different results later when\r\n\t\t\t// the developer inspects those in the web browser console if those state objects\r\n\t\t\t// get modified in between they've been output to the console and the developer\r\n\t\t\t// decided to inspect them.\r\n\t\t\tlog('Previous state' + '\\n' + JSON.stringify(this.getState().itemStates[i], null, 2))\r\n\t\t\tlog('New state' + '\\n' + JSON.stringify(newItemState, null, 2))\r\n\t\t}\r\n\r\n\t\tthis.getState().itemStates[i] = newItemState\r\n\r\n\t\t// If there was a request for `setState()` with new `items`, then the changes\r\n\t\t// to `currentState.itemStates[]` made above would be overwritten when that\r\n\t\t// pending `setState()` call gets applied.\r\n\t\t// To fix that, the updates to current `itemStates[]` are noted in\r\n\t\t// `this.itemStatesThatChangedWhileNewItemsWereBeingRendered` variable.\r\n\t\t// That variable is then checked when the `setState()` call with the new `items`\r\n\t\t// has been updated.\r\n\t\tif (this.newItemsWillBeRendered) {\r\n\t\t\tif (!this.itemStatesThatChangedWhileNewItemsWereBeingRendered) {\r\n\t\t\t\tthis.itemStatesThatChangedWhileNewItemsWereBeingRendered = {}\r\n\t\t\t}\r\n\t\t\tthis.itemStatesThatChangedWhileNewItemsWereBeingRendered[String(i)] = newItemState\r\n\t\t}\r\n\t}\r\n\r\n\tthis.getState = () => this._getState()\r\n\r\n\tthis.updateState = (stateUpdate) => {\r\n\t\tif (isDebug()) {\r\n\t\t\tlog('~ Set state ~')\r\n\t\t\tlog(getStateSnapshot(stateUpdate))\r\n\t\t}\r\n\r\n\t\t// Ensure that a non-initial `stateUpdate` can only contain an `items`\r\n\t\t// property when it comes from a `setItems()` call.\r\n\t\tif (stateUpdate.items) {\r\n\t\t\tif (!this._isSettingNewItems) {\r\n\t\t\t\treportError('A `stateUpdate` can only contain `items` property as a result of calling `.setItems()`')\r\n\t\t\t}\r\n\t\t}\r\n\t\tthis._isSettingNewItems = undefined\r\n\r\n\t\tthis.waitingForRender = true\r\n\r\n\t\t// Store previous `state`.\r\n\t\tthis.previousState = this.getState()\r\n\r\n\t\t// If it's the first call to `this.updateState()` then initialize\r\n\t\t// the most recent `setState()` value to be the current state.\r\n\t\tif (!this.mostRecentSetStateValue) {\r\n\t\t\tthis.mostRecentSetStateValue = this.getState()\r\n\t\t}\r\n\r\n\t\t// Accumulates all \"pending\" state updates until they have been applied.\r\n\t\tthis.mostRecentSetStateValue = {\r\n\t\t\t...this.mostRecentSetStateValue,\r\n\t\t\t...stateUpdate\r\n\t\t}\r\n\r\n\t\t// Update `state`.\r\n\t\tthis._setState(this.mostRecentSetStateValue, stateUpdate)\r\n\t}\r\n\r\n\tthis.getInitialState = () => {\r\n\t\tif (initialState) {\r\n\t\t\treturn getRestoredState.call(this, initialState)\r\n\t\t}\r\n\t\treturn getInitialStateFromScratch.call(this, { getInitialItemState })\r\n\t}\r\n\r\n\tthis.useState = ({\r\n\t\tgetState,\r\n\t\tsetState,\r\n\t\tupdateState\r\n\t}) => {\r\n\t\tif (this._isActive) {\r\n\t\t\tthrow new Error('[virtual-scroller] `VirtualScroller` has already been started')\r\n\t\t}\r\n\r\n\t\tif (this._getState) {\r\n\t\t\tthrow new Error('[virtual-scroller] Custom state storage has already been configured')\r\n\t\t}\r\n\r\n\t\tif (render) {\r\n\t\t\tthrow new Error('[virtual-scroller] Creating a `VirtualScroller` class instance with a `render()` parameter implies using the default (internal) state storage')\r\n\t\t}\r\n\r\n\t\tif (setState && updateState) {\r\n\t\t\tthrow new Error('[virtual-scroller] When using a custom state storage, one must supply either `setState()` or `updateState()` function but not both')\r\n\t\t}\r\n\r\n\t\tif (!getState || !(setState || updateState)) {\r\n\t\t\tthrow new Error('[virtual-scroller] When using a custom state storage, one must supply both `getState()` and `setState()`/`updateState()` functions')\r\n\t\t}\r\n\r\n\t\tthis._usesCustomStateStorage = true\r\n\r\n\t\tthis._getState = getState\r\n\r\n\t\tthis._setState = (newState, stateUpdate) => {\r\n\t\t\tif (setState) {\r\n\t\t\t\tsetState(newState)\r\n\t\t\t} else {\r\n\t\t\t\tupdateState(stateUpdate)\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\r\n\tthis.useDefaultStateStorage = () => {\r\n\t\tif (!render) {\r\n\t\t\tthrow new Error('[virtual-scroller] When using the default (internal) state management, one must supply a `render(state, prevState)` function parameter')\r\n\t\t}\r\n\r\n\t\t// Create default `getState()`/`setState()` functions.\r\n\t\tthis._getState = defaultGetState.bind(this)\r\n\t\tthis._setState = defaultSetState.bind(this)\r\n\r\n\t\t// When `state` is stored externally, a developer is responsible for\r\n\t\t// initializing it with the initial value.\r\n\t\t// Otherwise, if default state management is used, set the initial state now.\r\n\t\tconst setInitialState = defaultSetInitialState.bind(this)\r\n\t\tsetInitialState(this.getInitialState())\r\n\t}\r\n\r\n\tfunction defaultGetState() {\r\n\t\treturn this.state\r\n\t}\r\n\r\n\tfunction defaultSetInitialState(newState) {\r\n\t\tthis.state = newState\r\n\t}\r\n\r\n\tfunction defaultSetState(newState, stateUpdate) {\r\n\t\t// // Because the default state updates are \"synchronous\" (immediate),\r\n\t\t// // the `...stateUpdate` could be applied over `...this.state`,\r\n\t\t// // and no state updates would be lost.\r\n\t\t// // But if it was \"asynchronous\" (not immediate), then `...this.state`\r\n\t\t// // wouldn't work in all cases, because it could be stale in cases\r\n\t\t// // when more than a single `setState()` call is made before\r\n\t\t// // the state actually updates, making some properties of `this.state` stale.\r\n\t\t// this.state = {\r\n\t\t// \t...this.state,\r\n\t\t// \t...stateUpdate\r\n\t\t// }\r\n\r\n\t\tthis.state = newState\r\n\r\n\t\trender(this.state, this.previousState)\r\n\r\n\t\tthis.onRender()\r\n\t}\r\n\r\n\t/**\r\n\t * Returns the initial state of the `VirtualScroller` \"from scratch\".\r\n\t * (i.e. not from a previously saved one).\r\n\t * @param {function} [options.getInitialItemState] — Gets initial item state.\r\n\t * @return {object}\r\n\t */\r\n\tfunction getInitialStateFromScratch({ getInitialItemState }) {\r\n\t\tconst items = initialItems\r\n\r\n\t\tconst state = {\r\n\t\t\t...getInitialLayoutState.call(this, items, { beforeStart: true }),\r\n\t\t\titems,\r\n\t\t\titemStates: fillArray(new Array(items.length), (i) => getInitialItemState(items[i]))\r\n\t\t}\r\n\r\n\t\tif (isDebug()) {\r\n\t\t\tlog('Initial state (autogenerated)', getStateSnapshot(state))\r\n\t\t}\r\n\t\tlog('First shown item index', state.firstShownItemIndex)\r\n\t\tlog('Last shown item index', state.lastShownItemIndex)\r\n\r\n\t\treturn state\r\n\t}\r\n\r\n\tfunction getRestoredState(state) {\r\n\t\tif (isDebug()) {\r\n\t\t\tlog('Restore state', getStateSnapshot(state))\r\n\t\t}\r\n\r\n\t\t// Possibly clean up \"before resize\" property in state.\r\n\t\t// \"Before resize\" state property is cleaned up when all \"before resize\" item heights\r\n\t\t// have been re-measured in an asynchronous `this.updateState({ beforeResize: undefined })` call.\r\n\t\t// If `VirtualScroller` state was snapshotted externally before that `this.updateState()` call\r\n\t\t// has been applied, then \"before resize\" property might have not been cleaned up properly.\r\n\t\tstate = cleanUpBeforeResizeState(state)\r\n\r\n\t\t// Reset `verticalSpacing` so that it re-measures it after the list\r\n\t\t// has been rendered initially. The rationale is that a previously captured\r\n\t\t// inter-item vertical spacing can't be \"trusted\" in a sense that the user\r\n\t\t// might have resized the window after the previous `state` has been snapshotted.\r\n\t\t// If the user has resized the window, then changing window width might have\r\n\t\t// activated different CSS `@media()` \"queries\" resulting in a potentially different\r\n\t\t// vertical spacing when the `VirtualScroller` is re-created with such previously\r\n\t\t// snapshotted state.\r\n\t\tstate = {\r\n\t\t\t...state,\r\n\t\t\tverticalSpacing: undefined\r\n\t\t}\r\n\r\n\t\t// `this.verticalSpacing` acts as a \"true\" source for vertical spacing value.\r\n\t\t// Vertical spacing is also stored in `state` but `state` updates could be\r\n\t\t// \"asynchronous\" (not applied immediately) and `this.onUpdateShownItemIndexes()`\r\n\t\t// requires vertical spacing to be correct at any time, without any delays.\r\n\t\t// So, vertical spacing is also duplicated in `state`, but the \"true\" source\r\n\t\t// is still `this.verticalSpacing`.\r\n\t\t//\r\n\t\t// `this.verticalSpacing` must be initialized before calling `this.getInitialStateFromScratch()`\r\n\t\t// because `this.getInitialStateFromScratch()` uses `this.verticalSpacing` in its calculations.\r\n\t\t//\r\n\t\t// With the code above, `state.verticalSpacing` is always gonna be `undefined`,\r\n\t\t// so commented out this code. It's safer to just re-measure vertical spacing\r\n\t\t// from scratch when `VirtualScroller` is mounted.\r\n\t\t//\r\n\t\t// this.verticalSpacing = state ? state.verticalSpacing : undefined\r\n\r\n\t\t// Check if the actual `columnsCount` on the screen matches the one from state.\r\n\t\tif (isStateColumnsCountMismatch(state, {\r\n\t\t\tcolumnsCount: this.getActualColumnsCount()\r\n\t\t})) {\r\n\t\t\twarn('Reset Layout')\r\n\t\t\tstate = {\r\n\t\t\t\t...state,\r\n\t\t\t\t...getInitialLayoutState.call(this, state.items, { beforeStart: false })\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\treturn state\r\n\t}\r\n\r\n\tfunction getInitialLayoutState(items, { beforeStart }) {\r\n\t\tconst itemsCount = items.length\r\n\r\n\t\tconst getColumnsCount = () => this.getActualColumnsCount()\r\n\r\n\t\tconst columnsCount = beforeStart\r\n\t\t\t? this.layout.getInitialLayoutValueWithFallback(\r\n\t\t\t\t'columnsCount',\r\n\t\t\t\tgetColumnsCount,\r\n\t\t\t\t1\r\n\t\t\t)\r\n\t\t\t: getColumnsCount()\r\n\r\n\t\tconst {\r\n\t\t\tfirstShownItemIndex,\r\n\t\t\tlastShownItemIndex,\r\n\t\t\tbeforeItemsHeight,\r\n\t\t\tafterItemsHeight\r\n\t\t} = this.layout.getInitialLayoutValues({\r\n\t\t\titemsCount,\r\n\t\t\tcolumnsCount: this.getActualColumnsCount(),\r\n\t\t\tbeforeStart\r\n\t\t})\r\n\r\n\t\tconst itemHeights = new Array(itemsCount)\r\n\r\n\t\t// Optionally preload items to be rendered.\r\n\t\tthis.onBeforeShowItems(\r\n\t\t\titems,\r\n\t\t\titemHeights,\r\n\t\t\tfirstShownItemIndex,\r\n\t\t\tlastShownItemIndex\r\n\t\t)\r\n\r\n\t\treturn {\r\n\t\t\titemHeights,\r\n\t\t\tcolumnsCount: this.getActualColumnsCountForState(),\r\n\t\t\tverticalSpacing: this.verticalSpacing,\r\n\t\t\tfirstShownItemIndex,\r\n\t\t\tlastShownItemIndex,\r\n\t\t\tbeforeItemsHeight,\r\n\t\t\tafterItemsHeight\r\n\t\t}\r\n\t}\r\n\r\n\t// Checks if the actual `columnsCount` on the screen matches the one from state.\r\n\t//\r\n\t// For example, a developer might snapshot `VirtualScroller` state\r\n\t// when the user navigates from the page containing the list\r\n\t// in order to later restore the list's state when the user goes \"Back\".\r\n\t// But, the user might have also resized the window while being on that\r\n\t// \"other\" page, and when they come \"Back\", their snapshotted state\r\n\t// no longer qualifies. Well, it does qualify, but only partially.\r\n\t// For example, `itemStates` are still valid, but first and last shown\r\n\t// item indexes aren't.\r\n\t//\r\n\tfunction isStateColumnsCountMismatch(state, { columnsCount }) {\r\n\t\tconst stateColumnsCount = state.columnsCount || 1\r\n\t\tif (stateColumnsCount !== columnsCount) {\r\n\t\t\twarn('~ Columns Count changed from', stateColumnsCount, 'to', columnsCount, '~')\r\n\t\t\treturn true\r\n\t\t}\r\n\t\tconst firstShownItemIndex = Math.floor(state.firstShownItemIndex / columnsCount) * columnsCount\r\n\t\tif (firstShownItemIndex !== state.firstShownItemIndex) {\r\n\t\t\twarn('~ First Shown Item Index', state.firstShownItemIndex, 'is not divisible by Columns Count', columnsCount, '~')\r\n\t\t\treturn true\r\n\t\t}\r\n\t}\r\n}"],"mappings":";;;;;;;;;AAAA;;AACA;;AACA;;AACA;;;;;;;;;;;;;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAEe,SAASA,kBAAT,OAMZ;EAAA;;EAAA,IALKC,YAKL,QALFC,KAKE;EAAA,IAJFC,mBAIE,QAJFA,mBAIE;EAAA,IAHFC,aAGE,QAHFA,aAGE;EAAA,IAFFC,MAEE,QAFFA,MAEE;EAAA,IADKC,YACL,QADFC,KACE;EACF,KAAKH,aAAL,GAAqBA,aAArB;EACA,KAAKI,OAAL,GAAeH,MAAf;EAEA,KAAKF,mBAAL,GAA2BA,mBAA3B;;EAEA,KAAKM,aAAL,GAAqB,UAACC,CAAD,EAAIC,YAAJ,EAAqB;IACzC,IAAI,IAAAC,cAAA,GAAJ,EAAe;MACd,IAAAC,iBAAA,EAAI,wBAAJ;MACA,IAAAA,iBAAA,EAAI,YAAJ,EAAkBH,CAAlB,EAFc,CAGd;MACA;MACA;MACA;MACA;;MACA,IAAAG,iBAAA,EAAI,mBAAmB,IAAnB,GAA0BC,IAAI,CAACC,SAAL,CAAe,KAAI,CAACC,QAAL,GAAgBC,UAAhB,CAA2BP,CAA3B,CAAf,EAA8C,IAA9C,EAAoD,CAApD,CAA9B;MACA,IAAAG,iBAAA,EAAI,cAAc,IAAd,GAAqBC,IAAI,CAACC,SAAL,CAAeJ,YAAf,EAA6B,IAA7B,EAAmC,CAAnC,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