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.
Files changed (115) hide show
  1. package/CHANGELOG.md +5 -0
  2. package/README.md +13 -11
  3. package/bundle/virtual-scroller-dom.js +1 -1
  4. package/bundle/virtual-scroller-dom.js.map +1 -1
  5. package/bundle/virtual-scroller-react.js +1 -1
  6. package/bundle/virtual-scroller-react.js.map +1 -1
  7. package/bundle/virtual-scroller.js +1 -1
  8. package/bundle/virtual-scroller.js.map +1 -1
  9. package/commonjs/DOM/ItemsContainer.js +10 -3
  10. package/commonjs/DOM/ItemsContainer.js.map +1 -1
  11. package/commonjs/DOM/VirtualScroller.js +13 -1
  12. package/commonjs/DOM/VirtualScroller.js.map +1 -1
  13. package/commonjs/ItemHeights.js +5 -5
  14. package/commonjs/ItemHeights.js.map +1 -1
  15. package/commonjs/ItemNotRenderedError.js +64 -0
  16. package/commonjs/ItemNotRenderedError.js.map +1 -0
  17. package/commonjs/Layout.test.js +10 -0
  18. package/commonjs/Layout.test.js.map +1 -1
  19. package/commonjs/VirtualScroller.js +23 -5
  20. package/commonjs/VirtualScroller.js.map +1 -1
  21. package/commonjs/VirtualScroller.layout.js +81 -39
  22. package/commonjs/VirtualScroller.layout.js.map +1 -1
  23. package/commonjs/VirtualScroller.onRender.js +97 -45
  24. package/commonjs/VirtualScroller.onRender.js.map +1 -1
  25. package/commonjs/VirtualScroller.state.js +50 -18
  26. package/commonjs/VirtualScroller.state.js.map +1 -1
  27. package/commonjs/react/VirtualScroller.js +31 -46
  28. package/commonjs/react/VirtualScroller.js.map +1 -1
  29. package/commonjs/react/useItemKeys.js +11 -3
  30. package/commonjs/react/useItemKeys.js.map +1 -1
  31. package/commonjs/react/useOnChange.js +19 -0
  32. package/commonjs/react/useOnChange.js.map +1 -0
  33. package/commonjs/react/{useOnItemHeightChange.js → useOnItemHeightDidChange.js} +7 -7
  34. package/commonjs/react/useOnItemHeightDidChange.js.map +1 -0
  35. package/commonjs/react/{useHandleItemsPropertyChange.js → useSetNewItemsOnItemsPropertyChange.js} +15 -14
  36. package/commonjs/react/useSetNewItemsOnItemsPropertyChange.js.map +1 -0
  37. package/commonjs/react/useState.js +162 -69
  38. package/commonjs/react/useState.js.map +1 -1
  39. package/commonjs/react/useStyle.js +3 -5
  40. package/commonjs/react/useStyle.js.map +1 -1
  41. package/commonjs/react/useUpdateItemKeysOnItemsChange.js +61 -0
  42. package/commonjs/react/useUpdateItemKeysOnItemsChange.js.map +1 -0
  43. package/commonjs/test/ItemsContainer.js +22 -1
  44. package/commonjs/test/ItemsContainer.js.map +1 -1
  45. package/commonjs/utility/debug.js +30 -6
  46. package/commonjs/utility/debug.js.map +1 -1
  47. package/dom/index.d.ts +1 -1
  48. package/index.cjs +2 -0
  49. package/index.d.ts +7 -1
  50. package/index.js +1 -0
  51. package/modules/DOM/ItemsContainer.js +8 -3
  52. package/modules/DOM/ItemsContainer.js.map +1 -1
  53. package/modules/DOM/VirtualScroller.js +13 -1
  54. package/modules/DOM/VirtualScroller.js.map +1 -1
  55. package/modules/ItemHeights.js +5 -5
  56. package/modules/ItemHeights.js.map +1 -1
  57. package/modules/ItemNotRenderedError.js +57 -0
  58. package/modules/ItemNotRenderedError.js.map +1 -0
  59. package/modules/Layout.test.js +10 -0
  60. package/modules/Layout.test.js.map +1 -1
  61. package/modules/VirtualScroller.js +17 -5
  62. package/modules/VirtualScroller.js.map +1 -1
  63. package/modules/VirtualScroller.layout.js +78 -39
  64. package/modules/VirtualScroller.layout.js.map +1 -1
  65. package/modules/VirtualScroller.onRender.js +98 -46
  66. package/modules/VirtualScroller.onRender.js.map +1 -1
  67. package/modules/VirtualScroller.state.js +50 -18
  68. package/modules/VirtualScroller.state.js.map +1 -1
  69. package/modules/react/VirtualScroller.js +31 -46
  70. package/modules/react/VirtualScroller.js.map +1 -1
  71. package/modules/react/useItemKeys.js +8 -3
  72. package/modules/react/useItemKeys.js.map +1 -1
  73. package/modules/react/useOnChange.js +11 -0
  74. package/modules/react/useOnChange.js.map +1 -0
  75. package/modules/react/{useOnItemHeightChange.js → useOnItemHeightDidChange.js} +6 -6
  76. package/modules/react/useOnItemHeightDidChange.js.map +1 -0
  77. package/modules/react/{useHandleItemsPropertyChange.js → useSetNewItemsOnItemsPropertyChange.js} +11 -13
  78. package/modules/react/useSetNewItemsOnItemsPropertyChange.js.map +1 -0
  79. package/modules/react/useState.js +156 -73
  80. package/modules/react/useState.js.map +1 -1
  81. package/modules/react/useStyle.js +3 -5
  82. package/modules/react/useStyle.js.map +1 -1
  83. package/{commonjs/react/useHandleItemIndexesChange.js → modules/react/useUpdateItemKeysOnItemsChange.js} +18 -21
  84. package/modules/react/useUpdateItemKeysOnItemsChange.js.map +1 -0
  85. package/modules/test/ItemsContainer.js +20 -1
  86. package/modules/test/ItemsContainer.js.map +1 -1
  87. package/modules/utility/debug.js +31 -6
  88. package/modules/utility/debug.js.map +1 -1
  89. package/package.json +1 -1
  90. package/source/DOM/ItemsContainer.js +8 -3
  91. package/source/DOM/VirtualScroller.js +11 -1
  92. package/source/ItemHeights.js +5 -5
  93. package/source/ItemNotRenderedError.js +16 -0
  94. package/source/Layout.test.js +9 -0
  95. package/source/VirtualScroller.js +14 -3
  96. package/source/VirtualScroller.layout.js +77 -38
  97. package/source/VirtualScroller.onRender.js +95 -42
  98. package/source/VirtualScroller.state.js +57 -20
  99. package/source/react/VirtualScroller.js +28 -39
  100. package/source/react/useItemKeys.js +9 -2
  101. package/source/react/useOnChange.js +11 -0
  102. package/source/react/{useOnItemHeightChange.js → useOnItemHeightDidChange.js} +5 -5
  103. package/source/react/{useHandleItemsPropertyChange.js → useSetNewItemsOnItemsPropertyChange.js} +11 -11
  104. package/source/react/useState.js +159 -71
  105. package/source/react/useStyle.js +2 -2
  106. package/source/react/{useHandleItemIndexesChange.js → useUpdateItemKeysOnItemsChange.js} +17 -9
  107. package/source/test/ItemsContainer.js +22 -1
  108. package/source/utility/debug.js +18 -4
  109. package/commonjs/react/useHandleItemIndexesChange.js.map +0 -1
  110. package/commonjs/react/useHandleItemsPropertyChange.js.map +0 -1
  111. package/commonjs/react/useOnItemHeightChange.js.map +0 -1
  112. package/modules/react/useHandleItemIndexesChange.js +0 -45
  113. package/modules/react/useHandleItemIndexesChange.js.map +0 -1
  114. package/modules/react/useHandleItemsPropertyChange.js.map +0 -1
  115. package/modules/react/useOnItemHeightChange.js.map +0 -1
@@ -4,7 +4,7 @@ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { va
4
4
 
5
5
  function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
6
6
 
7
- import log, { warn, isDebug } from './utility/debug.js';
7
+ import log, { warn, reportError, isDebug } from './utility/debug.js';
8
8
  import getStateSnapshot from './utility/getStateSnapshot.js';
9
9
  import shallowEqual from './utility/shallowEqual.js';
10
10
  import { LAYOUT_REASON } from './Layout.js';
@@ -18,6 +18,7 @@ export default function () {
18
18
  * @param {object} [prevState]
19
19
  */
20
20
  this._onRender = function (newState, prevState) {
21
+ _this.waitingForRender = false;
21
22
  log('~ Rendered ~');
22
23
 
23
24
  if (isDebug()) {
@@ -35,23 +36,63 @@ export default function () {
35
36
 
36
37
  if (_this.tbody) {
37
38
  setTbodyPadding(_this.getItemsContainerElement(), newState.beforeItemsHeight, newState.afterItemsHeight);
38
- }
39
+ } // `this.mostRecentlySetState` checks that state management behavior is correct:
40
+ // that in situations when there're multiple new states waiting to be set,
41
+ // only the latest one gets applied.
42
+ // It keeps the code simpler and prevents possible race condition bugs.
43
+ // For example, `VirtualScroller` keeps track of its latest requested
44
+ // state update in different instance variable flags which assume that
45
+ // only that latest requested state update gets actually applied.
46
+ //
47
+ // This check should also be performed for the initial render in order to
48
+ // guarantee that no potentially incorrect state update goes unnoticed.
49
+ // Incorrect state updates could happen when `VirtualScroller` state
50
+ // is managed externally by passing `getState()`/`updateState()` options.
51
+ //
52
+ // Perform the check only when `this.mostRecentSetStateValue` is defined.
53
+ // `this.mostRecentSetStateValue` is normally gonna be `undefined` at the initial render
54
+ // because the initial state is not set by calling `this.updateState()`.
55
+ // At the same time, it is possible that the initial render is delayed
56
+ // for whatever reason, and `this.updateState()` gets called before the initial render,
57
+ // so `this.mostRecentSetStateValue` could also be defined at the initial render,
58
+ // in which case the check should be performed.
59
+ //
39
60
 
40
- if (!prevState) {
41
- return;
61
+
62
+ if (_this.mostRecentSetStateValue) {
63
+ // "Shallow equality" is used here instead of "strict equality"
64
+ // because a developer might choose to supply an `updateState()` function
65
+ // rather than a `setState()` function, in which case the `updateState()` function
66
+ // would construct its own state object.
67
+ if (!shallowEqual(newState, _this.mostRecentSetStateValue)) {
68
+ warn('The most recent state that was set', getStateSnapshot(_this.mostRecentSetStateValue));
69
+ reportError('The state that has been rendered is not the most recent one that was set');
70
+ }
42
71
  } // `this.resetStateUpdateFlags()` must be called before calling
43
72
  // `this.measureItemHeightsAndSpacing()`.
44
73
 
45
74
 
46
75
  var _resetStateUpdateFlag = resetStateUpdateFlags.call(_this),
47
76
  nonMeasuredItemsHaveBeenRendered = _resetStateUpdateFlag.nonMeasuredItemsHaveBeenRendered,
77
+ itemHeightHasChanged = _resetStateUpdateFlag.itemHeightHasChanged,
48
78
  widthHasChanged = _resetStateUpdateFlag.widthHasChanged;
49
79
 
50
- var layoutUpdateReason; // If the `VirtualScroller`, while calculating layout parameters, encounters
80
+ var layoutUpdateReason;
81
+
82
+ if (_this.updateLayoutAfterRenderBecauseItemHeightChanged) {
83
+ layoutUpdateReason = LAYOUT_REASON.ITEM_HEIGHT_CHANGED;
84
+ }
85
+
86
+ if (!prevState) {
87
+ if (!layoutUpdateReason) {
88
+ return;
89
+ }
90
+ } // If the `VirtualScroller`, while calculating layout parameters, encounters
51
91
  // a not-shown item with a non-measured height, it calls `updateState()` just to
52
92
  // render that item first, and then, after the list has been re-rendered, it measures
53
93
  // the item's height and then proceeds with calculating the correct layout parameters.
54
94
 
95
+
55
96
  if (nonMeasuredItemsHaveBeenRendered) {
56
97
  layoutUpdateReason = LAYOUT_REASON.NON_MEASURED_ITEMS_HAVE_BEEN_MEASURED;
57
98
  } // If scrollable container width has changed, and it has been re-rendered,
@@ -75,43 +116,45 @@ export default function () {
75
116
  _this.verticalSpacing = undefined;
76
117
  }
77
118
 
78
- var previousItems = prevState.items;
79
- var newItems = newState.items; // Even if `this.newItemsWillBeRendered` flag is `true`,
80
- // `newItems` could still be equal to `previousItems`.
81
- // For example, when `updateState()` calls don't update `state` immediately
82
- // and a developer first calls `setItems(newItems)` and then calls `setItems(oldItems)`:
83
- // in that case, `this.newItemsWillBeRendered` flag will be `true` but the actual `items`
84
- // in state wouldn't have changed due to the first `updateState()` call being overwritten
85
- // by the second `updateState()` call (that's called "batching state updates" in React).
86
-
87
- if (newItems !== previousItems) {
88
- var itemsDiff = _this.getItemsDiff(previousItems, newItems);
89
-
90
- if (itemsDiff) {
91
- // The call to `.onPrepend()` must precede the call to `.measureItemHeights()`
92
- // which is called in `.onRender()`.
93
- // `this.itemHeights.onPrepend()` updates `firstMeasuredItemIndex`
94
- // and `lastMeasuredItemIndex` of `this.itemHeights`.
95
- var prependedItemsCount = itemsDiff.prependedItemsCount;
96
-
97
- _this.itemHeights.onPrepend(prependedItemsCount);
98
- } else {
99
- _this.itemHeights.reset();
100
- }
119
+ if (prevState) {
120
+ var previousItems = prevState.items;
121
+ var newItems = newState.items; // Even if `this.newItemsWillBeRendered` flag is `true`,
122
+ // `newItems` could still be equal to `previousItems`.
123
+ // For example, when `updateState()` calls don't update `state` immediately
124
+ // and a developer first calls `setItems(newItems)` and then calls `setItems(oldItems)`:
125
+ // in that case, `this.newItemsWillBeRendered` flag will be `true` but the actual `items`
126
+ // in state wouldn't have changed due to the first `updateState()` call being overwritten
127
+ // by the second `updateState()` call (that's called "batching state updates" in React).
128
+
129
+ if (newItems !== previousItems) {
130
+ var itemsDiff = _this.getItemsDiff(previousItems, newItems);
131
+
132
+ if (itemsDiff) {
133
+ // The call to `.onPrepend()` must precede the call to `.measureItemHeights()`
134
+ // which is called in `.onRender()`.
135
+ // `this.itemHeights.onPrepend()` updates `firstMeasuredItemIndex`
136
+ // and `lastMeasuredItemIndex` of `this.itemHeights`.
137
+ var prependedItemsCount = itemsDiff.prependedItemsCount;
138
+
139
+ _this.itemHeights.onPrepend(prependedItemsCount);
140
+ } else {
141
+ _this.itemHeights.reset();
142
+ }
101
143
 
102
- if (!widthHasChanged) {
103
- // The call to `this.onNewItemsRendered()` must precede the call to
104
- // `.measureItemHeights()` which is called in `.onRender()` because
105
- // `this.onNewItemsRendered()` updates `firstMeasuredItemIndex` and
106
- // `lastMeasuredItemIndex` of `this.itemHeights` in case of a prepend.
107
- //
108
- // If after prepending items the scroll position
109
- // should be "restored" so that there's no "jump" of content
110
- // then it means that all previous items have just been rendered
111
- // in a single pass, and there's no need to update layout again.
112
- //
113
- if (onNewItemsRendered.call(_this, itemsDiff, newState) !== 'SEAMLESS_PREPEND') {
114
- layoutUpdateReason = LAYOUT_REASON.ITEMS_CHANGED;
144
+ if (!widthHasChanged) {
145
+ // The call to `this.onNewItemsRendered()` must precede the call to
146
+ // `.measureItemHeights()` which is called in `.onRender()` because
147
+ // `this.onNewItemsRendered()` updates `firstMeasuredItemIndex` and
148
+ // `lastMeasuredItemIndex` of `this.itemHeights` in case of a prepend.
149
+ //
150
+ // If after prepending items the scroll position
151
+ // should be "restored" so that there's no "jump" of content
152
+ // then it means that all previous items have just been rendered
153
+ // in a single pass, and there's no need to update layout again.
154
+ //
155
+ if (onNewItemsRendered.call(_this, itemsDiff, newState) !== 'SEAMLESS_PREPEND') {
156
+ layoutUpdateReason = LAYOUT_REASON.ITEMS_CHANGED;
157
+ }
115
158
  }
116
159
  }
117
160
  }
@@ -125,7 +168,7 @@ export default function () {
125
168
  // item height measurements is required.
126
169
  //
127
170
 
128
- if (newState.firstShownItemIndex !== prevState.firstShownItemIndex || newState.lastShownItemIndex !== prevState.lastShownItemIndex || newState.items !== prevState.items || widthHasChanged) {
171
+ if (prevState && (newState.firstShownItemIndex !== prevState.firstShownItemIndex || newState.lastShownItemIndex !== prevState.lastShownItemIndex || newState.items !== prevState.items) || widthHasChanged) {
129
172
  var verticalSpacingStateUpdate = _this.measureItemHeightsAndSpacing();
130
173
 
131
174
  if (verticalSpacingStateUpdate) {
@@ -198,7 +241,7 @@ export default function () {
198
241
  if (this.itemHeightsThatChangedWhileNewItemsWereBeingRendered) {
199
242
  for (var _i = 0, _Object$keys = Object.keys(this.itemHeightsThatChangedWhileNewItemsWereBeingRendered); _i < _Object$keys.length; _i++) {
200
243
  var i = _Object$keys[_i];
201
- itemHeights[prependedItemsCount + parseInt(i)] = this.itemHeightsThatChangedWhileNewItemsWereBeingRendered[i];
244
+ itemHeights[prependedItemsCount + Number(i)] = this.itemHeightsThatChangedWhileNewItemsWereBeingRendered[i];
202
245
  }
203
246
  } // See if any items' states changed while new items were being rendered.
204
247
 
@@ -206,7 +249,7 @@ export default function () {
206
249
  if (this.itemStatesThatChangedWhileNewItemsWereBeingRendered) {
207
250
  for (var _i2 = 0, _Object$keys2 = Object.keys(this.itemStatesThatChangedWhileNewItemsWereBeingRendered); _i2 < _Object$keys2.length; _i2++) {
208
251
  var _i3 = _Object$keys2[_i2];
209
- itemStates[prependedItemsCount + parseInt(_i3)] = this.itemStatesThatChangedWhileNewItemsWereBeingRendered[_i3];
252
+ itemStates[prependedItemsCount + Number(_i3)] = this.itemStatesThatChangedWhileNewItemsWereBeingRendered[_i3];
210
253
  }
211
254
  }
212
255
 
@@ -319,7 +362,12 @@ export default function () {
319
362
 
320
363
  this.widthHasChanged = undefined; // Read `this.firstNonMeasuredItemIndex` flag.
321
364
 
322
- var nonMeasuredItemsHaveBeenRendered = this.firstNonMeasuredItemIndex !== undefined; // Reset `this.firstNonMeasuredItemIndex` flag.
365
+ var nonMeasuredItemsHaveBeenRendered = this.firstNonMeasuredItemIndex !== undefined;
366
+
367
+ if (nonMeasuredItemsHaveBeenRendered) {
368
+ log('Non-measured item index', this.firstNonMeasuredItemIndex);
369
+ } // Reset `this.firstNonMeasuredItemIndex` flag.
370
+
323
371
 
324
372
  this.firstNonMeasuredItemIndex = undefined; // Reset `this.newItemsWillBeRendered` flag.
325
373
 
@@ -327,9 +375,13 @@ export default function () {
327
375
 
328
376
  this.itemHeightsThatChangedWhileNewItemsWereBeingRendered = undefined; // Reset `this.itemStatesThatChangedWhileNewItemsWereBeingRendered`.
329
377
 
330
- this.itemStatesThatChangedWhileNewItemsWereBeingRendered = undefined;
378
+ this.itemStatesThatChangedWhileNewItemsWereBeingRendered = undefined; // Reset `this.updateLayoutAfterRenderBecauseItemHeightChanged`.
379
+
380
+ var itemHeightHasChanged = this.updateLayoutAfterRenderBecauseItemHeightChanged;
381
+ this.updateLayoutAfterRenderBecauseItemHeightChanged = undefined;
331
382
  return {
332
383
  nonMeasuredItemsHaveBeenRendered: nonMeasuredItemsHaveBeenRendered,
384
+ itemHeightHasChanged: itemHeightHasChanged,
333
385
  widthHasChanged: widthHasChanged
334
386
  };
335
387
  }
@@ -1 +1 @@
1
- {"version":3,"file":"VirtualScroller.onRender.js","names":["log","warn","isDebug","getStateSnapshot","shallowEqual","LAYOUT_REASON","setTbodyPadding","_onRender","newState","prevState","onStateChange","tbody","getItemsContainerElement","beforeItemsHeight","afterItemsHeight","resetStateUpdateFlags","call","nonMeasuredItemsHaveBeenRendered","widthHasChanged","layoutUpdateReason","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","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,OAAOA,GAAP,IAAcC,IAAd,EAAoBC,OAApB,QAAmC,oBAAnC;AACA,OAAOC,gBAAP,MAA6B,+BAA7B;AACA,OAAOC,YAAP,MAAyB,2BAAzB;AACA,SAASC,aAAT,QAA8B,aAA9B;AACA,SAASC,eAAT,QAAgC,gBAAhC;AAEA,eAAe,YAAW;EAAA;;EACzB;AACD;AACA;AACA;AACA;EACC,KAAKC,SAAL,GAAiB,UAACC,QAAD,EAAWC,SAAX,EAAyB;IACzCT,GAAG,CAAC,cAAD,CAAH;;IACA,IAAIE,OAAO,EAAX,EAAe;MACdF,GAAG,CAAC,OAAD,EAAUG,gBAAgB,CAACK,QAAD,CAA1B,CAAH;IACA;;IAED,IAAI,KAAI,CAACE,aAAT,EAAwB;MACvB,IAAI,CAACN,YAAY,CAACI,QAAD,EAAWC,SAAX,CAAjB,EAAwC;QACvC,KAAI,CAACC,aAAL,CAAmBF,QAAnB;MACA;IACD,CAVwC,CAYzC;IACA;IACA;;;IACA,IAAI,KAAI,CAACG,KAAT,EAAgB;MACfL,eAAe,CACd,KAAI,CAACM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C;;IACA,KAAK8B,oDAAL,GAA4D9B,SAA5D,CA7BgC,CA+BhC;;IACA,KAAKmC,mDAAL,GAA2DnC,SAA3D;IAEA,OAAO;MACNR,gCAAgC,EAAhCA,gCADM;MAENC,eAAe,EAAfA;IAFM,CAAP;EAIA;AACD"}
1
+ {"version":3,"file":"VirtualScroller.onRender.js","names":["log","warn","reportError","isDebug","getStateSnapshot","shallowEqual","LAYOUT_REASON","setTbodyPadding","_onRender","newState","prevState","waitingForRender","onStateChange","tbody","getItemsContainerElement","beforeItemsHeight","afterItemsHeight","mostRecentSetStateValue","resetStateUpdateFlags","call","nonMeasuredItemsHaveBeenRendered","itemHeightHasChanged","widthHasChanged","layoutUpdateReason","updateLayoutAfterRenderBecauseItemHeightChanged","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,OAAOA,GAAP,IAAcC,IAAd,EAAoBC,WAApB,EAAiCC,OAAjC,QAAgD,oBAAhD;AACA,OAAOC,gBAAP,MAA6B,+BAA7B;AACA,OAAOC,YAAP,MAAyB,2BAAzB;AACA,SAASC,aAAT,QAA8B,aAA9B;AACA,SAASC,eAAT,QAAgC,gBAAhC;AAEA,eAAe,YAAW;EAAA;;EACzB;AACD;AACA;AACA;AACA;EACC,KAAKC,SAAL,GAAiB,UAACC,QAAD,EAAWC,SAAX,EAAyB;IACzC,KAAI,CAACC,gBAAL,GAAwB,KAAxB;IAEAX,GAAG,CAAC,cAAD,CAAH;;IACA,IAAIG,OAAO,EAAX,EAAe;MACdH,GAAG,CAAC,OAAD,EAAUI,gBAAgB,CAACK,QAAD,CAA1B,CAAH;IACA;;IAED,IAAI,KAAI,CAACG,aAAT,EAAwB;MACvB,IAAI,CAACP,YAAY,CAACI,QAAD,EAAWC,SAAX,CAAjB,EAAwC;QACvC,KAAI,CAACE,aAAL,CAAmBH,QAAnB;MACA;IACD,CAZwC,CAczC;IACA;IACA;;;IACA,IA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CAAd,CAFiC,CAGjC;;MACA,KAAKkC,mBAAL,CAAyB;QACxBpB,MAAM,EAANA,MADwB;QAExBd,WAAW,EAAXA;MAFwB,CAAzB;IAIA,CARD,MAQO;MACN,KAAKmC,wBAAL,CAA8B;QAC7BrB,MAAM,EAANA,MAD6B;QAE7Bd,WAAW,EAAXA;MAF6B,CAA9B;IAIA;EACD;;EAED,SAASvB,qBAAT,GAAiC;IAChC;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA,IAAMI,eAAe,GAAGuD,OAAO,CAAC,KAAKvD,eAAN,CAA/B,CAfgC,CAgBhC;IACA;;IACA,KAAKA,eAAL,GAAuBS,SAAvB,CAlBgC,CAoBhC;;IACA,IAAMX,gCAAgC,GAAG,KAAK0D,yBAAL,KAAmC/C,SAA5E;;IACA,IAAIX,gCAAJ,EAAsC;MACrCpB,GAAG,CAAC,yBAAD,EAA4B,KAAK8E,yBAAjC,CAAH;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,IAAMV,oBAAoB,GAAG,KAAKG,+CAAlC;IACA,KAAKA,+CAAL,GAAuDO,SAAvD;IAEA,OAAO;MACNX,gCAAgC,EAAhCA,gCADM;MAENC,oBAAoB,EAApBA,oBAFM;MAGNC,eAAe,EAAfA;IAHM,CAAP;EAKA;AACD"}
@@ -54,7 +54,13 @@ export default function createStateHelpers(_ref) {
54
54
  log('New state' + '\n' + JSON.stringify(newItemState, null, 2));
55
55
  }
56
56
 
57
- _this.getState().itemStates[i] = newItemState; // Schedule the item state update for after the new items have been rendered.
57
+ _this.getState().itemStates[i] = newItemState; // If there was a request for `setState()` with new `items`, then the changes
58
+ // to `currentState.itemStates[]` made above would be overwritten when that
59
+ // pending `setState()` call gets applied.
60
+ // To fix that, the updates to current `itemStates[]` are noted in
61
+ // `this.itemStatesThatChangedWhileNewItemsWereBeingRendered` variable.
62
+ // That variable is then checked when the `setState()` call with the new `items`
63
+ // has been updated.
58
64
 
59
65
  if (_this.newItemsWillBeRendered) {
60
66
  if (!_this.itemStatesThatChangedWhileNewItemsWereBeingRendered) {
@@ -83,11 +89,20 @@ export default function createStateHelpers(_ref) {
83
89
  }
84
90
  }
85
91
 
86
- _this._isSettingNewItems = undefined; // Update `state`.
92
+ _this._isSettingNewItems = undefined;
93
+ _this.waitingForRender = true; // Store previous `state`.
87
94
 
88
- _this.previousState = _this.getState();
95
+ _this.previousState = _this.getState(); // If it's the first call to `this.updateState()` then initialize
96
+ // the most recent `setState()` value to be the current state.
89
97
 
90
- _this._updateState(stateUpdate);
98
+ if (!_this.mostRecentSetStateValue) {
99
+ _this.mostRecentSetStateValue = _this.getState();
100
+ } // Accumulates all "pending" state updates until they have been applied.
101
+
102
+
103
+ _this.mostRecentSetStateValue = _objectSpread(_objectSpread({}, _this.mostRecentSetStateValue), stateUpdate); // Update `state`.
104
+
105
+ _this._setState(_this.mostRecentSetStateValue, stateUpdate);
91
106
  };
92
107
 
93
108
  this.getInitialState = function () {
@@ -102,6 +117,7 @@ export default function createStateHelpers(_ref) {
102
117
 
103
118
  this.useState = function (_ref2) {
104
119
  var getState = _ref2.getState,
120
+ setState = _ref2.setState,
105
121
  updateState = _ref2.updateState;
106
122
 
107
123
  if (_this._isActive) {
@@ -113,26 +129,37 @@ export default function createStateHelpers(_ref) {
113
129
  }
114
130
 
115
131
  if (render) {
116
- throw new Error('[virtual-scroller] Creating a `VirtualScroller` class instance with a `render()` parameter means using the default (internal) state storage');
132
+ throw new Error('[virtual-scroller] Creating a `VirtualScroller` class instance with a `render()` parameter implies using the default (internal) state storage');
133
+ }
134
+
135
+ if (setState && updateState) {
136
+ throw new Error('[virtual-scroller] When using a custom state storage, one must supply either `setState()` or `updateState()` function but not both');
117
137
  }
118
138
 
119
- if (!getState || !updateState) {
120
- throw new Error('[virtual-scroller] When using a custom state storage, one must supply both `getState()` and `updateState()` functions');
139
+ if (!getState || !(setState || updateState)) {
140
+ throw new Error('[virtual-scroller] When using a custom state storage, one must supply both `getState()` and `setState()`/`updateState()` functions');
121
141
  }
122
142
 
123
143
  _this._usesCustomStateStorage = true;
124
144
  _this._getState = getState;
125
- _this._updateState = updateState;
145
+
146
+ _this._setState = function (newState, stateUpdate) {
147
+ if (setState) {
148
+ setState(newState);
149
+ } else {
150
+ updateState(stateUpdate);
151
+ }
152
+ };
126
153
  };
127
154
 
128
155
  this.useDefaultStateStorage = function () {
129
156
  if (!render) {
130
157
  throw new Error('[virtual-scroller] When using the default (internal) state management, one must supply a `render(state, prevState)` function parameter');
131
- } // Create default `getState()`/`updateState()` functions.
158
+ } // Create default `getState()`/`setState()` functions.
132
159
 
133
160
 
134
161
  _this._getState = defaultGetState.bind(_this);
135
- _this._updateState = defaultUpdateState.bind(_this); // When `state` is stored externally, a developer is responsible for
162
+ _this._setState = defaultSetState.bind(_this); // When `state` is stored externally, a developer is responsible for
136
163
  // initializing it with the initial value.
137
164
  // Otherwise, if default state management is used, set the initial state now.
138
165
 
@@ -148,14 +175,19 @@ export default function createStateHelpers(_ref) {
148
175
  this.state = newState;
149
176
  }
150
177
 
151
- function defaultUpdateState(stateUpdate) {
152
- // Because this variant of `.updateState()` is "synchronous" (immediate),
153
- // it can be written like `...prevState`, and no state updates would be lost.
154
- // But if it was "asynchronous" (not immediate), then `...prevState`
155
- // wouldn't work in all cases, because it could be stale in cases
156
- // when more than a single `updateState()` call is made before
157
- // the state actually updates, making `prevState` stale.
158
- this.state = _objectSpread(_objectSpread({}, this.state), stateUpdate);
178
+ function defaultSetState(newState, stateUpdate) {
179
+ // // Because the default state updates are "synchronous" (immediate),
180
+ // // the `...stateUpdate` could be applied over `...this.state`,
181
+ // // and no state updates would be lost.
182
+ // // But if it was "asynchronous" (not immediate), then `...this.state`
183
+ // // wouldn't work in all cases, because it could be stale in cases
184
+ // // when more than a single `setState()` call is made before
185
+ // // the state actually updates, making some properties of `this.state` stale.
186
+ // this.state = {
187
+ // ...this.state,
188
+ // ...stateUpdate
189
+ // }
190
+ this.state = newState;
159
191
  render(this.state, this.previousState);
160
192
  this.onRender();
161
193
  }
@@ -1 +1 @@
1
- {"version":3,"file":"VirtualScroller.state.js","names":["fillArray","log","warn","isDebug","reportError","cleanUpBeforeResizeState","getStateSnapshot","createStateHelpers","initialState","state","getInitialItemState","onStateChange","render","initialItems","items","_render","_setItemState","i","newItemState","JSON","stringify","getState","itemStates","newItemsWillBeRendered","itemStatesThatChangedWhileNewItemsWereBeingRendered","String","_getState","updateState","stateUpdate","_isSettingNewItems","undefined","previousState","_updateState","getInitialState","getRestoredState","call","getInitialStateFromScratch","useState","_isActive","Error","_usesCustomStateStorage","useDefaultStateStorage","defaultGetState","bind","defaultUpdateState","setInitialState","defaultSetInitialState","newState","onRender","getInitialLayoutState","beforeStart","Array","length","firstShownItemIndex","lastShownItemIndex","verticalSpacing","isStateColumnsCountMismatch","columnsCount","getActualColumnsCount","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,OAAOA,SAAP,MAAsB,wBAAtB;AACA,OAAOC,GAAP,IAAcC,IAAd,EAAoBC,OAApB,EAA6BC,WAA7B,QAAgD,oBAAhD;AACA,SAASC,wBAAT,QAAyC,mBAAzC;AACA,OAAOC,gBAAP,MAA6B,+BAA7B,C,CAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA,eAAe,SAASC,kBAAT,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,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AnC,EAAwD,mCAAxD,EAA6FI,YAA7F,EAA2G,GAA3G,CAAJ;MACA,OAAO,IAAP;IACA;EACD;AACD"}
1
+ {"version":3,"file":"VirtualScroller.state.js","names":["fillArray","log","warn","isDebug","reportError","cleanUpBeforeResizeState","getStateSnapshot","createStateHelpers","initialState","state","getInitialItemState","onStateChange","render","initialItems","items","_render","_setItemState","i","newItemState","JSON","stringify","getState","itemStates","newItemsWillBeRendered","itemStatesThatChangedWhileNewItemsWereBeingRendered","String","_getState","updateState","stateUpdate","_isSettingNewItems","undefined","waitingForRender","previousState","mostRecentSetStateValue","_setState","getInitialState","getRestoredState","call","getInitialStateFromScratch","useState","setState","_isActive","Error","_usesCustomStateStorage","newState","useDefaultStateStorage","defaultGetState","bind","defaultSetState","setInitialState","defaultSetInitialState","onRender","getInitialLayoutState","beforeStart","Array","length","firstShownItemIndex","lastShownItemIndex","verticalSpacing","isStateColumnsCountMismatch","columnsCount","getActualColumnsCount","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,OAAOA,SAAP,MAAsB,wBAAtB;AACA,OAAOC,GAAP,IAAcC,IAAd,EAAoBC,OAApB,EAA6BC,WAA7B,QAAgD,oBAAhD;AACA,SAASC,wBAAT,QAAyC,mBAAzC;AACA,OAAOC,gBAAP,MAA6B,+BAA7B,C,CAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA,eAAe,SAASC,kBAAT,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,IAAIf,OAAO,EAAX,EAAe;MACdF,GAAG,CAAC,wBAAD,CAAH;MACAA,GAAG,CAAC,YAAD,EAAegB,CAAf,CAAH,CAFc,CAGd;MACA;MACA;MACA;MACA;;MACAhB,GAAG,CAAC,mBAAmB,IAAnB,GAA0BkB,IAAI,CAACC,SAAL,CAAe,KAAI,CAACC,QAAL,GAAgBC,UAAhB,CAA2BL,CAA3B,CAAf,EAA8C,IAA9C,EAAoD,CAApD,CAA3B,CAAH;MACAhB,GAAG,CAAC,cAAc,IAAd,GAAqBkB,IAAI,CAACC,SAAL,CAAeF,YAAf,EAA6B,IAA7B,EAAmC,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