virtual-scroller 1.10.1 → 1.11.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 (74) hide show
  1. package/CHANGELOG.md +16 -0
  2. package/README.md +48 -24
  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/VirtualScroller.js +5 -0
  10. package/commonjs/DOM/VirtualScroller.js.map +1 -1
  11. package/commonjs/ItemHeights.js +1 -1
  12. package/commonjs/ItemHeights.js.map +1 -1
  13. package/commonjs/Layout.js +2 -2
  14. package/commonjs/Layout.js.map +1 -1
  15. package/commonjs/VirtualScroller.constructor.js +6 -4
  16. package/commonjs/VirtualScroller.constructor.js.map +1 -1
  17. package/commonjs/VirtualScroller.items.js +11 -10
  18. package/commonjs/VirtualScroller.items.js.map +1 -1
  19. package/commonjs/VirtualScroller.js +10 -3
  20. package/commonjs/VirtualScroller.js.map +1 -1
  21. package/commonjs/VirtualScroller.layout.js +2 -2
  22. package/commonjs/VirtualScroller.layout.js.map +1 -1
  23. package/commonjs/VirtualScroller.state.js +27 -17
  24. package/commonjs/VirtualScroller.state.js.map +1 -1
  25. package/commonjs/react/VirtualScroller.js +26 -11
  26. package/commonjs/react/VirtualScroller.js.map +1 -1
  27. package/commonjs/react/{useOnItemStateChange.js → useSetItemState.js} +7 -7
  28. package/commonjs/react/useSetItemState.js.map +1 -0
  29. package/commonjs/react/useVirtualScroller.js +2 -1
  30. package/commonjs/react/useVirtualScroller.js.map +1 -1
  31. package/commonjs/utility/fillArray.js +18 -0
  32. package/commonjs/utility/fillArray.js.map +1 -0
  33. package/dom/index.d.ts +7 -6
  34. package/index.d.ts +16 -15
  35. package/modules/DOM/VirtualScroller.js +5 -0
  36. package/modules/DOM/VirtualScroller.js.map +1 -1
  37. package/modules/ItemHeights.js +1 -1
  38. package/modules/ItemHeights.js.map +1 -1
  39. package/modules/Layout.js +2 -2
  40. package/modules/Layout.js.map +1 -1
  41. package/modules/VirtualScroller.constructor.js +6 -4
  42. package/modules/VirtualScroller.constructor.js.map +1 -1
  43. package/modules/VirtualScroller.items.js +10 -10
  44. package/modules/VirtualScroller.items.js.map +1 -1
  45. package/modules/VirtualScroller.js +10 -3
  46. package/modules/VirtualScroller.js.map +1 -1
  47. package/modules/VirtualScroller.layout.js +2 -2
  48. package/modules/VirtualScroller.layout.js.map +1 -1
  49. package/modules/VirtualScroller.state.js +24 -15
  50. package/modules/VirtualScroller.state.js.map +1 -1
  51. package/modules/react/VirtualScroller.js +26 -11
  52. package/modules/react/VirtualScroller.js.map +1 -1
  53. package/modules/react/{useOnItemStateChange.js → useSetItemState.js} +6 -6
  54. package/modules/react/useSetItemState.js.map +1 -0
  55. package/modules/react/useVirtualScroller.js +2 -1
  56. package/modules/react/useVirtualScroller.js.map +1 -1
  57. package/modules/utility/fillArray.js +11 -0
  58. package/modules/utility/fillArray.js.map +1 -0
  59. package/package.json +1 -1
  60. package/react/index.d.ts +14 -8
  61. package/source/DOM/VirtualScroller.js +4 -0
  62. package/source/ItemHeights.js +1 -1
  63. package/source/Layout.js +3 -3
  64. package/source/VirtualScroller.constructor.js +5 -3
  65. package/source/VirtualScroller.items.js +16 -8
  66. package/source/VirtualScroller.js +8 -2
  67. package/source/VirtualScroller.layout.js +2 -2
  68. package/source/VirtualScroller.state.js +20 -12
  69. package/source/react/VirtualScroller.js +25 -10
  70. package/source/react/{useOnItemStateChange.js → useSetItemState.js} +5 -5
  71. package/source/react/useVirtualScroller.js +2 -0
  72. package/source/utility/fillArray.js +8 -0
  73. package/commonjs/react/useOnItemStateChange.js.map +0 -1
  74. package/modules/react/useOnItemStateChange.js.map +0 -1
package/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  export type ItemHeight = number | undefined;
2
- export type ItemState = any | undefined;
2
+ export type NoItemState = undefined;
3
3
 
4
4
  interface BeforeResizeState {
5
5
  itemHeights: number[];
@@ -7,7 +7,7 @@ interface BeforeResizeState {
7
7
  verticalSpacing: number;
8
8
  }
9
9
 
10
- export interface State<Item> {
10
+ export interface State<Item, ItemState> {
11
11
  items: Item[];
12
12
  firstShownItemIndex: number;
13
13
  lastShownItemIndex: number;
@@ -49,9 +49,10 @@ interface ScrollableContainerArgument {
49
49
  getWidth(): number;
50
50
  }
51
51
 
52
- export interface VirtualScrollerCommonOptions<Item> {
52
+ export interface VirtualScrollerCommonOptions<Item, ItemState> {
53
53
  bypass?: boolean;
54
- onStateChange?(newState: State<Item>);
54
+ onStateChange?(newState: State<Item, ItemState>);
55
+ getInitialItemState?: (item: Item) => ItemState;
55
56
  measureItemsBatchSize?: number;
56
57
  getEstimatedItemHeight?: () => number;
57
58
  getEstimatedVisibleItemRowsCount?: () => number;
@@ -62,29 +63,29 @@ export interface VirtualScrollerCommonOptions<Item> {
62
63
  getColumnsCount?(scrollableContainer: ScrollableContainerArgument): number;
63
64
  }
64
65
 
65
- interface Options<Element, Item> extends VirtualScrollerCommonOptions<Item> {
66
- state?: State<Item>;
67
- render?(state: State<Item>, previousState?: State<Item>): void;
66
+ interface Options<Element, Item, ItemState> extends VirtualScrollerCommonOptions<Item, ItemState> {
67
+ state?: State<Item, ItemState>;
68
+ render?(state: State<Item, ItemState>, previousState?: State<Item, ItemState>): void;
68
69
  engine?: Engine<Element>;
69
70
  tbody?: boolean;
70
71
  scrollableContainer?: Element;
71
72
  getScrollableContainer?(): Element;
72
73
  }
73
74
 
74
- interface UseStateOptions<Item> {
75
- getState?(): State<Item>;
76
- updateState?(stateUpdate: Partial<State<Item>>): void;
75
+ interface UseStateOptions<Item, ItemState> {
76
+ getState?(): State<Item, ItemState>;
77
+ updateState?(stateUpdate: Partial<State<Item, ItemState>>): void;
77
78
  }
78
79
 
79
80
  export interface SetItemsOptions {
80
81
  preserveScrollPositionOnPrependItems?: boolean;
81
82
  }
82
83
 
83
- export default class VirtualScroller<Element, Item> {
84
+ export default class VirtualScroller<Element, Item, ItemState> {
84
85
  constructor(
85
86
  getItemsContainerElement: () => Element,
86
87
  items: Item[],
87
- options?: Options<Element, Item>
88
+ options?: Options<Element, Item, ItemState>
88
89
  );
89
90
 
90
91
  start(): void;
@@ -93,8 +94,8 @@ export default class VirtualScroller<Element, Item> {
93
94
  onRender(): void;
94
95
  setItems(newItems: Item[], options?: SetItemsOptions): void;
95
96
  onItemHeightChange(i: number): void;
96
- onItemStateChange(i: number, itemState?: object): void;
97
+ setItemState(i: number, itemState?: object): void;
97
98
  getItemScrollPosition(i: number): number | undefined;
98
- getInitialState(): State<Item>;
99
- useState(options: UseStateOptions<Item>): void;
99
+ getInitialState(): State<Item, ItemState>;
100
+ useState(options: UseStateOptions<Item, ItemState>): void;
100
101
  }
@@ -160,6 +160,11 @@ var VirtualScroller = /*#__PURE__*/function () {
160
160
  value: function onItemHeightChange(i) {
161
161
  this.virtualScroller.onItemHeightChange(i);
162
162
  }
163
+ }, {
164
+ key: "setItemState",
165
+ value: function setItemState(i, newState) {
166
+ this.virtualScroller.setItemState(i, newState);
167
+ }
163
168
  /**
164
169
  * @deprecated
165
170
  * `.updateItems()` has been renamed to `.setItems()`.
@@ -1 +1 @@
1
- {"version":3,"file":"VirtualScroller.js","names":["VirtualScrollerCore","log","warn","px","VirtualScroller","itemsContainerElement","items","renderItem","options","state","prevState","firstShownItemIndex","lastShownItemIndex","beforeItemsHeight","afterItemsHeight","tbody","container","style","paddingTop","paddingBottom","diffRender","length","i","unmountItem","childNodes","firstChild","shouldPrependItems","prependBeforeItemElement","item","insertBefore","appendChild","stop","virtualScroller","start","onMount","onItemUnmount","restOptions","tagName","render","itemElement","removeChild","onItemHeightChange","newItems","setItems"],"sources":["../../source/DOM/VirtualScroller.js"],"sourcesContent":["import VirtualScrollerCore from '../VirtualScroller.js'\r\n\r\nimport log, { warn } from '../utility/debug.js'\r\nimport px from '../utility/px.js'\r\n\r\nexport default class VirtualScroller {\r\n constructor(itemsContainerElement, items, renderItem, options = {}) {\r\n this.container = itemsContainerElement\r\n this.renderItem = renderItem\r\n\r\n const {\r\n onMount,\r\n onItemUnmount,\r\n ...restOptions\r\n } = options\r\n\r\n this.onItemUnmount = onItemUnmount\r\n this.tbody = this.container.tagName === 'TBODY'\r\n\r\n this.virtualScroller = new VirtualScrollerCore(\r\n () => this.container,\r\n items,\r\n {\r\n ...restOptions,\r\n render: this.render,\r\n tbody: this.tbody\r\n }\r\n )\r\n\r\n this.start()\r\n\r\n // `onMount()` option is deprecated due to no longer being used.\r\n // If someone thinks there's a valid use case for it, create an issue.\r\n if (onMount) {\r\n onMount()\r\n }\r\n }\r\n\r\n render = (state, prevState) => {\r\n const {\r\n items,\r\n firstShownItemIndex,\r\n lastShownItemIndex,\r\n beforeItemsHeight,\r\n afterItemsHeight\r\n } = state\r\n\r\n // log('~ On state change ~')\r\n // log('Previous state', prevState)\r\n // log('New state', state)\r\n\r\n // Set container padding top and bottom.\r\n // Work around `<tbody/>` not being able to have `padding`.\r\n // https://gitlab.com/catamphetamine/virtual-scroller/-/issues/1\r\n // `this.virtualScroller` hasn't been initialized yet at this stage,\r\n // so using `this.tbody` instead of `this.virtualScroller.tbody`.\r\n if (!this.tbody) {\r\n this.container.style.paddingTop = px(beforeItemsHeight)\r\n this.container.style.paddingBottom = px(afterItemsHeight)\r\n }\r\n\r\n // Perform an intelligent \"diff\" re-render if the `items` are the same.\r\n const diffRender = prevState && items === prevState.items && items.length > 0\r\n // Remove no longer visible items from the DOM.\r\n if (diffRender) {\r\n // Decrement instead of increment here because\r\n // `this.container.removeChild()` changes indexes.\r\n let i = prevState.lastShownItemIndex\r\n while (i >= prevState.firstShownItemIndex) {\r\n if (i >= firstShownItemIndex && i <= lastShownItemIndex) {\r\n // The item is still visible.\r\n } else {\r\n log('DOM: Remove element for item index', i)\r\n // The item is no longer visible. Remove it.\r\n this.unmountItem(this.container.childNodes[i - prevState.firstShownItemIndex])\r\n }\r\n i--\r\n }\r\n } else {\r\n log('DOM: Rerender the list from scratch')\r\n while (this.container.firstChild) {\r\n this.unmountItem(this.container.firstChild)\r\n }\r\n }\r\n\r\n // Add newly visible items to the DOM.\r\n let shouldPrependItems = diffRender\r\n const prependBeforeItemElement = shouldPrependItems && this.container.firstChild\r\n let i = firstShownItemIndex\r\n while (i <= lastShownItemIndex) {\r\n if (diffRender && i >= prevState.firstShownItemIndex && i <= prevState.lastShownItemIndex) {\r\n // The item is already being rendered.\r\n // Next items will be appended rather than prepended.\r\n if (shouldPrependItems) {\r\n shouldPrependItems = false\r\n }\r\n } else {\r\n const item = this.renderItem(items[i])\r\n if (shouldPrependItems) {\r\n log('DOM: Prepend element for item index', i)\r\n // Append `item` to `this.container` before the retained items.\r\n this.container.insertBefore(item, prependBeforeItemElement)\r\n } else {\r\n log('DOM: Append element for item index', i)\r\n // Append `item` to `this.container`.\r\n this.container.appendChild(item)\r\n }\r\n }\r\n i++\r\n }\r\n }\r\n\r\n // Public API. Should be \"bound\" to `this`.\r\n onUnmount = () => {\r\n warn('`.onUnmount()` instance method name is deprecated, use `.stop()` instance method name instead.')\r\n this.stop()\r\n }\r\n\r\n // Public API. Should be \"bound\" to `this`.\r\n destroy = () => {\r\n warn('`.destroy()` instance method name is deprecated, use `.stop()` instance method name instead.')\r\n this.stop()\r\n }\r\n\r\n // Public API.\r\n // Should be \"bound\" to `this`.\r\n stop = () => {\r\n this.virtualScroller.stop()\r\n }\r\n\r\n // Potentially public API in some hypothetical scenario.\r\n // Should be \"bound\" to `this`.\r\n start = () => {\r\n this.virtualScroller.start()\r\n }\r\n\r\n unmountItem(itemElement) {\r\n this.container.removeChild(itemElement)\r\n if (this.onItemUnmount) {\r\n this.onItemUnmount(itemElement)\r\n }\r\n }\r\n\r\n onItemHeightChange(i) {\r\n this.virtualScroller.onItemHeightChange(i)\r\n }\r\n\r\n /**\r\n * @deprecated\r\n * `.updateItems()` has been renamed to `.setItems()`.\r\n */\r\n updateItems(newItems, options) {\r\n this.setItems(newItems, options)\r\n }\r\n\r\n setItems(newItems, options) {\r\n this.virtualScroller.setItems(newItems, options)\r\n }\r\n\r\n /*\r\n getItemCoordinates(i) {\r\n return this.virtualScroller.getItemCoordinates(i)\r\n }\r\n */\r\n}"],"mappings":";;;;;;;;;;;;;;;;;;AAAA,OAAOA,mBAAP,MAAgC,uBAAhC;AAEA,OAAOC,GAAP,IAAcC,IAAd,QAA0B,qBAA1B;AACA,OAAOC,EAAP,MAAe,kBAAf;;IAEqBC,e;EACnB,yBAAYC,qBAAZ,EAAmCC,MAAnC,EAA0CC,UAA1C,EAAoE;IAAA;;IAAA,IAAdC,OAAc,uEAAJ,EAAI;;IAAA;;IAAA,gCAgC3D,UAACC,KAAD,EAAQC,SAAR,EAAsB;MAC7B,IACEJ,KADF,GAMIG,KANJ,CACEH,KADF;MAAA,IAEEK,mBAFF,GAMIF,KANJ,CAEEE,mBAFF;MAAA,IAGEC,kBAHF,GAMIH,KANJ,CAGEG,kBAHF;MAAA,IAIEC,iBAJF,GAMIJ,KANJ,CAIEI,iBAJF;MAAA,IAKEC,gBALF,GAMIL,KANJ,CAKEK,gBALF,CAD6B,CAS7B;MACA;MACA;MAEA;MACA;MACA;MACA;MACA;;MACA,IAAI,CAAC,KAAI,CAACC,KAAV,EAAiB;QACf,KAAI,CAACC,SAAL,CAAeC,KAAf,CAAqBC,UAArB,GAAkCf,EAAE,CAACU,iBAAD,CAApC;QACA,KAAI,CAACG,SAAL,CAAeC,KAAf,CAAqBE,aAArB,GAAqChB,EAAE,CAACW,gBAAD,CAAvC;MACD,CArB4B,CAuB7B;;;MACA,IAAMM,UAAU,GAAGV,SAAS,IAAIJ,KAAK,KAAKI,SAAS,CAACJ,KAAjC,IAA0CA,KAAK,CAACe,MAAN,GAAe,CAA5E,CAxB6B,CAyB7B;;MACA,IAAID,UAAJ,EAAgB;QACd;QACA;QACA,IAAIE,E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WAED,4BAAmBjB,CAAnB,EAAsB;MACpB,KAAKU,eAAL,CAAqBS,kBAArB,CAAwCnB,CAAxC;IACD;IAED;AACF;AACA;AACA;;;;WACE,qBAAYoB,QAAZ,EAAsBlC,OAAtB,EAA+B;MAC7B,KAAKmC,QAAL,CAAcD,QAAd,EAAwBlC,OAAxB;IACD;;;WAED,kBAASkC,QAAT,EAAmBlC,OAAnB,EAA4B;MAC1B,KAAKwB,eAAL,CAAqBW,QAArB,CAA8BD,QAA9B,EAAwClC,OAAxC;IACD;IAED;AACF;AACA;AACA;AACA;;;;;;;SA9JqBJ,e"}
1
+ {"version":3,"file":"VirtualScroller.js","names":["VirtualScrollerCore","log","warn","px","VirtualScroller","itemsContainerElement","items","renderItem","options","state","prevState","firstShownItemIndex","lastShownItemIndex","beforeItemsHeight","afterItemsHeight","tbody","container","style","paddingTop","paddingBottom","diffRender","length","i","unmountItem","childNodes","firstChild","shouldPrependItems","prependBeforeItemElement","item","insertBefore","appendChild","stop","virtualScroller","start","onMount","onItemUnmount","restOptions","tagName","render","itemElement","removeChild","onItemHeightChange","newState","setItemState","newItems","setItems"],"sources":["../../source/DOM/VirtualScroller.js"],"sourcesContent":["import VirtualScrollerCore from '../VirtualScroller.js'\r\n\r\nimport log, { warn } from '../utility/debug.js'\r\nimport px from '../utility/px.js'\r\n\r\nexport default class VirtualScroller {\r\n constructor(itemsContainerElement, items, renderItem, options = {}) {\r\n this.container = itemsContainerElement\r\n this.renderItem = renderItem\r\n\r\n const {\r\n onMount,\r\n onItemUnmount,\r\n ...restOptions\r\n } = options\r\n\r\n this.onItemUnmount = onItemUnmount\r\n this.tbody = this.container.tagName === 'TBODY'\r\n\r\n this.virtualScroller = new VirtualScrollerCore(\r\n () => this.container,\r\n items,\r\n {\r\n ...restOptions,\r\n render: this.render,\r\n tbody: this.tbody\r\n }\r\n )\r\n\r\n this.start()\r\n\r\n // `onMount()` option is deprecated due to no longer being used.\r\n // If someone thinks there's a valid use case for it, create an issue.\r\n if (onMount) {\r\n onMount()\r\n }\r\n }\r\n\r\n render = (state, prevState) => {\r\n const {\r\n items,\r\n firstShownItemIndex,\r\n lastShownItemIndex,\r\n beforeItemsHeight,\r\n afterItemsHeight\r\n } = state\r\n\r\n // log('~ On state change ~')\r\n // log('Previous state', prevState)\r\n // log('New state', state)\r\n\r\n // Set container padding top and bottom.\r\n // Work around `<tbody/>` not being able to have `padding`.\r\n // https://gitlab.com/catamphetamine/virtual-scroller/-/issues/1\r\n // `this.virtualScroller` hasn't been initialized yet at this stage,\r\n // so using `this.tbody` instead of `this.virtualScroller.tbody`.\r\n if (!this.tbody) {\r\n this.container.style.paddingTop = px(beforeItemsHeight)\r\n this.container.style.paddingBottom = px(afterItemsHeight)\r\n }\r\n\r\n // Perform an intelligent \"diff\" re-render if the `items` are the same.\r\n const diffRender = prevState && items === prevState.items && items.length > 0\r\n // Remove no longer visible items from the DOM.\r\n if (diffRender) {\r\n // Decrement instead of increment here because\r\n // `this.container.removeChild()` changes indexes.\r\n let i = prevState.lastShownItemIndex\r\n while (i >= prevState.firstShownItemIndex) {\r\n if (i >= firstShownItemIndex && i <= lastShownItemIndex) {\r\n // The item is still visible.\r\n } else {\r\n log('DOM: Remove element for item index', i)\r\n // The item is no longer visible. Remove it.\r\n this.unmountItem(this.container.childNodes[i - prevState.firstShownItemIndex])\r\n }\r\n i--\r\n }\r\n } else {\r\n log('DOM: Rerender the list from scratch')\r\n while (this.container.firstChild) {\r\n this.unmountItem(this.container.firstChild)\r\n }\r\n }\r\n\r\n // Add newly visible items to the DOM.\r\n let shouldPrependItems = diffRender\r\n const prependBeforeItemElement = shouldPrependItems && this.container.firstChild\r\n let i = firstShownItemIndex\r\n while (i <= lastShownItemIndex) {\r\n if (diffRender && i >= prevState.firstShownItemIndex && i <= prevState.lastShownItemIndex) {\r\n // The item is already being rendered.\r\n // Next items will be appended rather than prepended.\r\n if (shouldPrependItems) {\r\n shouldPrependItems = false\r\n }\r\n } else {\r\n const item = this.renderItem(items[i])\r\n if (shouldPrependItems) {\r\n log('DOM: Prepend element for item index', i)\r\n // Append `item` to `this.container` before the retained items.\r\n this.container.insertBefore(item, prependBeforeItemElement)\r\n } else {\r\n log('DOM: Append element for item index', i)\r\n // Append `item` to `this.container`.\r\n this.container.appendChild(item)\r\n }\r\n }\r\n i++\r\n }\r\n }\r\n\r\n // Public API. Should be \"bound\" to `this`.\r\n onUnmount = () => {\r\n warn('`.onUnmount()` instance method name is deprecated, use `.stop()` instance method name instead.')\r\n this.stop()\r\n }\r\n\r\n // Public API. Should be \"bound\" to `this`.\r\n destroy = () => {\r\n warn('`.destroy()` instance method name is deprecated, use `.stop()` instance method name instead.')\r\n this.stop()\r\n }\r\n\r\n // Public API.\r\n // Should be \"bound\" to `this`.\r\n stop = () => {\r\n this.virtualScroller.stop()\r\n }\r\n\r\n // Potentially public API in some hypothetical scenario.\r\n // Should be \"bound\" to `this`.\r\n start = () => {\r\n this.virtualScroller.start()\r\n }\r\n\r\n unmountItem(itemElement) {\r\n this.container.removeChild(itemElement)\r\n if (this.onItemUnmount) {\r\n this.onItemUnmount(itemElement)\r\n }\r\n }\r\n\r\n onItemHeightChange(i) {\r\n this.virtualScroller.onItemHeightChange(i)\r\n }\r\n\r\n setItemState(i, newState) {\r\n this.virtualScroller.setItemState(i, newState)\r\n }\r\n\r\n /**\r\n * @deprecated\r\n * `.updateItems()` has been renamed to `.setItems()`.\r\n */\r\n updateItems(newItems, options) {\r\n this.setItems(newItems, options)\r\n }\r\n\r\n setItems(newItems, options) {\r\n this.virtualScroller.setItems(newItems, options)\r\n }\r\n\r\n /*\r\n getItemCoordinates(i) {\r\n return this.virtualScroller.getItemCoordinates(i)\r\n }\r\n */\r\n}"],"mappings":";;;;;;;;;;;;;;;;;;AAAA,OAAOA,mBAAP,MAAgC,uBAAhC;AAEA,OAAOC,GAAP,IAAcC,IAAd,QAA0B,qBAA1B;AACA,OAAOC,EAAP,MAAe,kBAAf;;IAEqBC,e;EACnB,yBAAYC,qBAAZ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CAAqBa,QAArB,CAA8BD,QAA9B,EAAwCpC,OAAxC;IACD;IAED;AACF;AACA;AACA;AACA;;;;;;;SAlKqBJ,e"}
@@ -195,7 +195,7 @@ var ItemHeights = /*#__PURE__*/function () {
195
195
  var _height = this._measureItemHeight(i, firstShownItemIndex);
196
196
 
197
197
  if (previousHeight !== _height) {
198
- warn('Item index', i, 'height changed unexpectedly: it was', previousHeight, 'before, but now it is', _height, '. An item\'s height is allowed to change only in two cases: when the item\'s "state" changes and the developer calls `onItemStateChange(i, newState)`, or when the item\'s height changes for some other reason and the developer calls `onItemHeightChange(i)`. Perhaps you forgot to persist the item\'s "state" by calling `onItemStateChange(i, newState)` when it changed, and that "state" got lost when the item element was unmounted, which resulted in a different height when the item was shown again having its "state" reset.'); // Update the item's height as an attempt to fix things.
198
+ warn('Item index', i, 'height changed unexpectedly: it was', previousHeight, 'before, but now it is', _height, '. An item\'s height is allowed to change only in two cases: when the item\'s "state" changes and the developer calls `setItemState(i, newState)`, or when the item\'s height changes for some other reason and the developer calls `onItemHeightChange(i)`. Perhaps you forgot to persist the item\'s "state" by calling `setItemState(i, newState)` when it changed, and that "state" got lost when the item element was unmounted, which resulted in a different height when the item was shown again having its "state" reset.'); // Update the item's height as an attempt to fix things.
199
199
 
200
200
  this._set(i, _height);
201
201
  }
@@ -1 +1 @@
1
- {"version":3,"file":"ItemHeights.js","names":["log","warn","isDebug","reportError","ItemHeights","container","itemHeights","getItemHeight","setItemHeight","_get","_set","reset","measuredItemsHeight","firstMeasuredItemIndex","undefined","lastMeasuredItemIndex","i","length","firstShownItemIndex","getNthRenderedItemHeight","lastShownItemIndex","nonPreviouslyMeasuredItemIndexes","previousFirstMeasuredItemIndex","previousLastMeasuredItemIndex","firstMeasuredItemIndexHasBeenUpdated","push","height","_measureItemHeight","previousHeight","count"],"sources":["../source/ItemHeights.js"],"sourcesContent":["import log, { warn, isDebug, reportError } from './utility/debug.js'\r\n\r\nexport default class ItemHeights {\r\n\tconstructor({\r\n\t\tcontainer,\r\n\t\titemHeights,\r\n\t\tgetItemHeight,\r\n\t\tsetItemHeight\r\n\t}) {\r\n\t\tthis.container = container\r\n\t\tthis._get = getItemHeight\r\n\t\tthis._set = setItemHeight\r\n\t\tthis.reset()\r\n\t}\r\n\r\n\treset() {\r\n\t\tthis.measuredItemsHeight = 0\r\n\t\t// \"First measured item index\" variable was introduced\r\n\t\t// because it's not always `0`: when `virtualScroller.setItems()`\r\n\t\t// is called, some items might get prepended, in which case\r\n\t\t// `this.lastMeasuredItemIndex` is updated. If there was no\r\n\t\t// `this.firstMeasuredItemIndex`, then the average item height\r\n\t\t// calculated in `.getAverage()` would be incorrect in the timeframe\r\n\t\t// between `.setItems()` is called and those changes have been rendered.\r\n\t\t// And in that timeframe, `.getAverage()` is used to calculate the \"layout\":\r\n\t\t// stuff like \"before/after items height\" and \"estimated items count on screen\".\r\n\t\tthis.firstMeasuredItemIndex = undefined\r\n\t\tthis.lastMeasuredItemIndex = undefined\r\n\t}\r\n\r\n\t/**\r\n\t * Can only be called after a `.reset()` (including new instance creation).\r\n\t * Initializes `this.measuredItemsHeight`, `this.firstMeasuredItemIndex`\r\n\t * and `this.lastMeasuredItemIndex` instance variables from `VirtualScroller` `state`.\r\n\t * These instance variables are used when calculating \"average\" item height:\r\n\t * the \"average\" item height is simply `this.measuredItemsHeight` divided by\r\n\t * `this.lastMeasuredItemIndex` minus `this.firstMeasuredItemIndex` plus 1.\r\n\t */\r\n\treadItemHeightsFromState({ itemHeights }) {\r\n\t\tlet i = 0\r\n\t\twhile (i < itemHeights.length) {\r\n\t\t\tif (itemHeights[i] === undefined) {\r\n\t\t\t\tif (this.firstMeasuredItemIndex !== undefined) {\r\n\t\t\t\t\tthis.lastMeasuredItemIndex = i - 1\r\n\t\t\t\t\tbreak\r\n\t\t\t\t}\r\n\t\t\t} else {\r\n\t\t\t\tif (this.firstMeasuredItemIndex === undefined) {\r\n\t\t\t\t\tthis.firstMeasuredItemIndex = i\r\n\t\t\t\t}\r\n\t\t\t\tthis.measuredItemsHeight += itemHeights[i]\r\n\t\t\t}\r\n\t\t\ti++\r\n\t\t}\r\n\t}\r\n\r\n\t// Seems to be no longer used.\r\n\t// getItemHeight(i, firstShownItemIndex) {\r\n\t// \tif (this._get(i)) {\r\n\t// \t\treturn this._get(i)\r\n\t// \t}\r\n\t// \tconst itemHeight = this._measureItemHeight(i, firstShownItemIndex)\r\n\t// \tif (itemHeight) {\r\n\t// \t\tthis._set(i, itemHeight)\r\n\t// \t\treturn itemHeight\r\n\t// \t}\r\n\t// \treturn this.getAverage()\r\n\t// }\r\n\r\n\t_measureItemHeight(i, firstShownItemIndex) {\r\n\t\treturn this.container.getNthRenderedItemHeight(i - firstShownItemIndex)\r\n\t}\r\n\r\n\t/**\r\n\t * Measures item heights:\r\n\t *\r\n\t * * For the items that haven't been previously measured,\r\n\t * measures them for the first time.\r\n\t *\r\n\t * * For the items that have been previoulsy measured,\r\n\t * validate that their previously measured height\r\n\t * is still equal to their current height.\r\n\t * The unequalness may not necessarily be caused by\r\n\t * incorrect use of `virtual-scroller`: there are\r\n\t * also some valid use cases when such unequalness\r\n\t * could happen (see the comments in the code).\r\n\t *\r\n\t * @param {number} firstShownItemIndex\r\n\t * @param {number} lastShownItemIndex\r\n\t * @return {number[]} The indexes of the items that have not previously been measured and have been measured now.\r\n\t */\r\n\tmeasureItemHeights(firstShownItemIndex, lastShownItemIndex) {\r\n\t\tlog('~ Measure item heights ~')\r\n\t\t// If no items are rendered, don't measure anything.\r\n\t\tif (firstShownItemIndex === undefined) {\r\n\t\t\treturn\r\n\t\t}\r\n\t\t// Reset `this.measuredItemsHeight` if it's not a \"continuous\" measured items list:\r\n\t\t// if a group of items has been measured previously, and now it has rendered a completely\r\n\t\t// different group of items, and there's a non-measured \"gap\" between those two groups,\r\n\t\t// then reset `this.measuredItemsHeight` and \"first measured\"/\"last measured\" item indexes.\r\n\t\t// For example, this could happen when `.setItems()` prepends a lot of new items.\r\n\t\tif (this.firstMeasuredItemIndex !== undefined) {\r\n\t\t\tif (\r\n\t\t\t\tfirstShownItemIndex > this.lastMeasuredItemIndex + 1 ||\r\n\t\t\t\tlastShownItemIndex < this.firstMeasuredItemIndex - 1\r\n\t\t\t) {\r\n\t\t\t\t// Reset.\r\n\t\t\t\tlog('Non-measured items gap detected. Reset first and last measured item indexes.')\r\n\t\t\t\tthis.reset()\r\n\t\t\t}\r\n\t\t}\r\n\t\tconst nonPreviouslyMeasuredItemIndexes = []\r\n\t\tconst previousFirstMeasuredItemIndex = this.firstMeasuredItemIndex\r\n\t\tconst previousLastMeasuredItemIndex = this.lastMeasuredItemIndex\r\n\t\tlet firstMeasuredItemIndexHasBeenUpdated = false\r\n\t\tlet i = firstShownItemIndex\r\n\t\twhile (i <= lastShownItemIndex) {\r\n\t\t\t// Measure item heights that haven't been measured previously.\r\n\t\t\t// Don't re-measure item heights that have been measured previously.\r\n\t\t\t// The rationale is that developers are supposed to manually call\r\n\t\t\t// `.onItemHeightChange()` every time an item's height changes.\r\n\t\t\t// If developers don't neglect that rule, item heights won't\r\n\t\t\t// change unexpectedly.\r\n\t\t\tif (this._get(i) === undefined) {\r\n\t\t\t\tnonPreviouslyMeasuredItemIndexes.push(i)\r\n\t\t\t\tconst height = this._measureItemHeight(i, firstShownItemIndex)\r\n\t\t\t\tlog('Item index', i, 'height', height)\r\n\t\t\t\tthis._set(i, height)\r\n\t\t\t\t// Update average item height calculation variables\r\n\t\t\t\t// related to the previously measured items\r\n\t\t\t\t// that're above the items currently being shown.\r\n\t\t\t\t// It is known to be a \"continuous\" measured items list,\r\n\t\t\t\t// because the code at the start of this function checks that.\r\n\t\t\t\tif (previousFirstMeasuredItemIndex === undefined || i < previousFirstMeasuredItemIndex) {\r\n\t\t\t\t\tthis.measuredItemsHeight += height\r\n\t\t\t\t\t// Update first measured item index.\r\n\t\t\t\t\tif (!firstMeasuredItemIndexHasBeenUpdated) {\r\n\t\t\t\t\t\t// log('Set first measured item index', i)\r\n\t\t\t\t\t\tthis.firstMeasuredItemIndex = i\r\n\t\t\t\t\t\tfirstMeasuredItemIndexHasBeenUpdated = true\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t\t// Update average item height calculation variables\r\n\t\t\t\t// related to the previously measured items\r\n\t\t\t\t// that're below the items currently being shown.\r\n\t\t\t\t// It is known to be a \"continuous\" measured items list,\r\n\t\t\t\t// because the code at the start of this function checks that.\r\n\t\t\t\tif (previousLastMeasuredItemIndex === undefined || i > previousLastMeasuredItemIndex) {\r\n\t\t\t\t\t// If `previousLastMeasuredItemIndex` is `undefined`\r\n\t\t\t\t\t// then `previousFirstMeasuredItemIndex` is also `undefined`\r\n\t\t\t\t\t// which means that the item's `height` has already been added\r\n\t\t\t\t\t// to `this.measuredItemsHeight` in the code above,\r\n\t\t\t\t\t// so this condition guards against counting the item's `height`\r\n\t\t\t\t\t// twice in `this.measuredItemsHeight`.\r\n\t\t\t\t\tif (previousLastMeasuredItemIndex !== undefined) {\r\n\t\t\t\t\t\t// Add newly shown item height.\r\n\t\t\t\t\t\tthis.measuredItemsHeight += height\r\n\t\t\t\t\t}\r\n\t\t\t\t\t// Update last measured item index.\r\n\t\t\t\t\tthis.lastMeasuredItemIndex = i\r\n\t\t\t\t}\r\n\t\t\t} else {\r\n\t\t\t\t// Validate that the item's height didn't change since it was last measured.\r\n\t\t\t\t// If it did, then display a warning and update the item's height\r\n\t\t\t\t// as an attempt to fix things.\r\n\t\t\t\t// If an item's height changes unexpectedly then it means that there'll\r\n\t\t\t\t// likely be \"content jumping\".\r\n\t\t\t\tconst previousHeight = this._get(i)\r\n\t\t\t\tconst height = this._measureItemHeight(i, firstShownItemIndex)\r\n\t\t\t\tif (previousHeight !== height) {\r\n\t\t\t\t\twarn('Item index', i, 'height changed unexpectedly: it was', previousHeight, 'before, but now it is', height, '. An item\\'s height is allowed to change only in two cases: when the item\\'s \"state\" changes and the developer calls `onItemStateChange(i, newState)`, or when the item\\'s height changes for some other reason and the developer calls `onItemHeightChange(i)`. Perhaps you forgot to persist the item\\'s \"state\" by calling `onItemStateChange(i, newState)` when it changed, and that \"state\" got lost when the item element was unmounted, which resulted in a different height when the item was shown again having its \"state\" reset.')\r\n\t\t\t\t\t// Update the item's height as an attempt to fix things.\r\n\t\t\t\t\tthis._set(i, height)\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\ti++\r\n\t\t}\r\n\t\t// // Update average item height.\r\n\t\t// this.updateAverageItemHeight()\r\n\t\treturn nonPreviouslyMeasuredItemIndexes\r\n\t}\r\n\r\n\t/**\r\n\t * Re-measures item height.\r\n\t * @param {number} i — Item index.\r\n\t * @param {number} firstShownItemIndex\r\n\t */\r\n\tremeasureItemHeight(i, firstShownItemIndex) {\r\n\t\tconst previousHeight = this._get(i)\r\n\t\tconst height = this._measureItemHeight(i, firstShownItemIndex)\r\n\t\t// // Because this function is called from `.onItemHeightChange()`,\r\n\t\t// // there're no guarantees in which circumstances a developer calls it,\r\n\t\t// // and for which item indexes.\r\n\t\t// // Therefore, to guard against cases of incorrect usage,\r\n\t\t// // this function won't crash anything if the item isn't rendered\r\n\t\t// // or hasn't been previously rendered.\r\n\t\t// if (height !== undefined) {\r\n\t\t// \treportError(`\"onItemHeightChange()\" has been called for item ${i}, but that item isn't rendered.`)\r\n\t\t// \treturn\r\n\t\t// }\r\n\t\t// if (previousHeight === undefined) {\r\n\t\t// \treportError(`\"onItemHeightChange()\" has been called for item ${i}, but that item hasn't been rendered before.`)\r\n\t\t// \treturn\r\n\t\t// }\r\n\t\tthis._set(i, height)\r\n\t\tthis.measuredItemsHeight += height - previousHeight\r\n\t\treturn height\r\n\t}\r\n\r\n\t// /**\r\n\t// * \"Average\" item height is stored as an instance variable.\r\n\t// * For example, for caching, so that it isn't calculated every time it's requested.\r\n\t// * But that would be negligible performance gain, not really worth the extra code.\r\n\t// * Another thing it's stored for as an instance variable is\r\n\t// * keeping \"previous\" \"average\" item height, because it can be more precise\r\n\t// * than the newly calculated \"average\" item height, provided it had\r\n\t// * more \"samples\" (measured items). The newly calculated average item height\r\n\t// * could get less samples in a scenario when the scroll somehow jumps\r\n\t// * from one position to some other distant position: in that case previous\r\n\t// * \"total measured items height\" is discarded and the new one is initialized.\r\n\t// * Could such situation happen in real life? I guess, it's unlikely.\r\n\t// * So I'm commenting out this code, but still keeping it just in case.\r\n\t// */\r\n\t// updateAverageItemHeight() {\r\n\t// \tthis.averageItemHeightSamplesCount = this.lastMeasuredItemIndex - this.firstMeasuredItemIndex + 1\r\n\t// \tthis.averageItemHeight = this.measuredItemsHeight / this.averageItemHeightSamplesCount\r\n\t// }\r\n\t//\r\n\t// /**\r\n\t// * Public API: is called by `VirtualScroller`.\r\n\t// * @return {number}\r\n\t// */\r\n\t// getAverage() {\r\n\t// \t// Previously measured average item height might still be\r\n\t// \t// more precise if it contains more measured items (\"samples\").\r\n\t// \tif (this.previousAverageItemHeight) {\r\n\t// \t\tif (this.previousAverageItemHeightSamplesCount > this.averageItemHeightSamplesCount) {\r\n\t// \t\t\treturn this.previousAverageItemHeight\r\n\t// \t\t}\r\n\t// \t}\r\n\t// \treturn this.averageItemHeight || 0\r\n\t// }\r\n\r\n\t/**\r\n\t * Public API: is called by `VirtualScroller`.\r\n\t * @return {number}\r\n\t */\r\n\tgetAverage() {\r\n\t\tif (this.lastMeasuredItemIndex === undefined) {\r\n\t\t\treturn 0\r\n\t\t}\r\n\t\treturn this.measuredItemsHeight / (this.lastMeasuredItemIndex - this.firstMeasuredItemIndex + 1)\r\n\t}\r\n\r\n\tonPrepend(count) {\r\n\t\tif (this.firstMeasuredItemIndex !== undefined) {\r\n\t\t\tthis.firstMeasuredItemIndex += count\r\n\t\t\tthis.lastMeasuredItemIndex += count\r\n\t\t}\r\n\t}\r\n}"],"mappings":";;;;;;AAAA,OAAOA,GAAP,IAAcC,IAAd,EAAoBC,OAApB,EAA6BC,WAA7B,QAAgD,oBAAhD;;IAEqBC,W;EACpB,2BAKG;IAAA,IAJFC,SAIE,QAJFA,SAIE;IAAA,IAHFC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;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;;IAEA;AACD;AACA;AACA;;;;WACC,sBAAa;MACZ,IAAI,KAAKX,qBAAL,KAA+BD,SAAnC,EAA8C;QAC7C,OAAO,CAAP;MACA;;MACD,OAAO,KAAKF,mBAAL,IAA4B,KAAKG,qBAAL,GAA6B,KAAKF,sBAAlC,GAA2D,CAAvF,CAAP;IACA;;;WAED,mBAAUgB,KAAV,EAAiB;MAChB,IAAI,KAAKhB,sBAAL,KAAgCC,SAApC,EAA+C;QAC9C,KAAKD,sBAAL,IAA+BgB,KAA/B;QACA,KAAKd,qBAAL,IAA8Bc,KAA9B;MACA;IACD;;;;;;SAlQmBzB,W"}
1
+ {"version":3,"file":"ItemHeights.js","names":["log","warn","isDebug","reportError","ItemHeights","container","itemHeights","getItemHeight","setItemHeight","_get","_set","reset","measuredItemsHeight","firstMeasuredItemIndex","undefined","lastMeasuredItemIndex","i","length","firstShownItemIndex","getNthRenderedItemHeight","lastShownItemIndex","nonPreviouslyMeasuredItemIndexes","previousFirstMeasuredItemIndex","previousLastMeasuredItemIndex","firstMeasuredItemIndexHasBeenUpdated","push","height","_measureItemHeight","previousHeight","count"],"sources":["../source/ItemHeights.js"],"sourcesContent":["import log, { warn, isDebug, reportError } from './utility/debug.js'\r\n\r\nexport default class ItemHeights {\r\n\tconstructor({\r\n\t\tcontainer,\r\n\t\titemHeights,\r\n\t\tgetItemHeight,\r\n\t\tsetItemHeight\r\n\t}) {\r\n\t\tthis.container = container\r\n\t\tthis._get = getItemHeight\r\n\t\tthis._set = setItemHeight\r\n\t\tthis.reset()\r\n\t}\r\n\r\n\treset() {\r\n\t\tthis.measuredItemsHeight = 0\r\n\t\t// \"First measured item index\" variable was introduced\r\n\t\t// because it's not always `0`: when `virtualScroller.setItems()`\r\n\t\t// is called, some items might get prepended, in which case\r\n\t\t// `this.lastMeasuredItemIndex` is updated. If there was no\r\n\t\t// `this.firstMeasuredItemIndex`, then the average item height\r\n\t\t// calculated in `.getAverage()` would be incorrect in the timeframe\r\n\t\t// between `.setItems()` is called and those changes have been rendered.\r\n\t\t// And in that timeframe, `.getAverage()` is used to calculate the \"layout\":\r\n\t\t// stuff like \"before/after items height\" and \"estimated items count on screen\".\r\n\t\tthis.firstMeasuredItemIndex = undefined\r\n\t\tthis.lastMeasuredItemIndex = undefined\r\n\t}\r\n\r\n\t/**\r\n\t * Can only be called after a `.reset()` (including new instance creation).\r\n\t * Initializes `this.measuredItemsHeight`, `this.firstMeasuredItemIndex`\r\n\t * and `this.lastMeasuredItemIndex` instance variables from `VirtualScroller` `state`.\r\n\t * These instance variables are used when calculating \"average\" item height:\r\n\t * the \"average\" item height is simply `this.measuredItemsHeight` divided by\r\n\t * `this.lastMeasuredItemIndex` minus `this.firstMeasuredItemIndex` plus 1.\r\n\t */\r\n\treadItemHeightsFromState({ itemHeights }) {\r\n\t\tlet i = 0\r\n\t\twhile (i < itemHeights.length) {\r\n\t\t\tif (itemHeights[i] === undefined) {\r\n\t\t\t\tif (this.firstMeasuredItemIndex !== undefined) {\r\n\t\t\t\t\tthis.lastMeasuredItemIndex = i - 1\r\n\t\t\t\t\tbreak\r\n\t\t\t\t}\r\n\t\t\t} else {\r\n\t\t\t\tif (this.firstMeasuredItemIndex === undefined) {\r\n\t\t\t\t\tthis.firstMeasuredItemIndex = i\r\n\t\t\t\t}\r\n\t\t\t\tthis.measuredItemsHeight += itemHeights[i]\r\n\t\t\t}\r\n\t\t\ti++\r\n\t\t}\r\n\t}\r\n\r\n\t// Seems to be no longer used.\r\n\t// getItemHeight(i, firstShownItemIndex) {\r\n\t// \tif (this._get(i)) {\r\n\t// \t\treturn this._get(i)\r\n\t// \t}\r\n\t// \tconst itemHeight = this._measureItemHeight(i, firstShownItemIndex)\r\n\t// \tif (itemHeight) {\r\n\t// \t\tthis._set(i, itemHeight)\r\n\t// \t\treturn itemHeight\r\n\t// \t}\r\n\t// \treturn this.getAverage()\r\n\t// }\r\n\r\n\t_measureItemHeight(i, firstShownItemIndex) {\r\n\t\treturn this.container.getNthRenderedItemHeight(i - firstShownItemIndex)\r\n\t}\r\n\r\n\t/**\r\n\t * Measures item heights:\r\n\t *\r\n\t * * For the items that haven't been previously measured,\r\n\t * measures them for the first time.\r\n\t *\r\n\t * * For the items that have been previoulsy measured,\r\n\t * validate that their previously measured height\r\n\t * is still equal to their current height.\r\n\t * The unequalness may not necessarily be caused by\r\n\t * incorrect use of `virtual-scroller`: there are\r\n\t * also some valid use cases when such unequalness\r\n\t * could happen (see the comments in the code).\r\n\t *\r\n\t * @param {number} firstShownItemIndex\r\n\t * @param {number} lastShownItemIndex\r\n\t * @return {number[]} The indexes of the items that have not previously been measured and have been measured now.\r\n\t */\r\n\tmeasureItemHeights(firstShownItemIndex, lastShownItemIndex) {\r\n\t\tlog('~ Measure item heights ~')\r\n\t\t// If no items are rendered, don't measure anything.\r\n\t\tif (firstShownItemIndex === undefined) {\r\n\t\t\treturn\r\n\t\t}\r\n\t\t// Reset `this.measuredItemsHeight` if it's not a \"continuous\" measured items list:\r\n\t\t// if a group of items has been measured previously, and now it has rendered a completely\r\n\t\t// different group of items, and there's a non-measured \"gap\" between those two groups,\r\n\t\t// then reset `this.measuredItemsHeight` and \"first measured\"/\"last measured\" item indexes.\r\n\t\t// For example, this could happen when `.setItems()` prepends a lot of new items.\r\n\t\tif (this.firstMeasuredItemIndex !== undefined) {\r\n\t\t\tif (\r\n\t\t\t\tfirstShownItemIndex > this.lastMeasuredItemIndex + 1 ||\r\n\t\t\t\tlastShownItemIndex < this.firstMeasuredItemIndex - 1\r\n\t\t\t) {\r\n\t\t\t\t// Reset.\r\n\t\t\t\tlog('Non-measured items gap detected. Reset first and last measured item indexes.')\r\n\t\t\t\tthis.reset()\r\n\t\t\t}\r\n\t\t}\r\n\t\tconst nonPreviouslyMeasuredItemIndexes = []\r\n\t\tconst previousFirstMeasuredItemIndex = this.firstMeasuredItemIndex\r\n\t\tconst previousLastMeasuredItemIndex = this.lastMeasuredItemIndex\r\n\t\tlet firstMeasuredItemIndexHasBeenUpdated = false\r\n\t\tlet i = firstShownItemIndex\r\n\t\twhile (i <= lastShownItemIndex) {\r\n\t\t\t// Measure item heights that haven't been measured previously.\r\n\t\t\t// Don't re-measure item heights that have been measured previously.\r\n\t\t\t// The rationale is that developers are supposed to manually call\r\n\t\t\t// `.onItemHeightChange()` every time an item's height changes.\r\n\t\t\t// If developers don't neglect that rule, item heights won't\r\n\t\t\t// change unexpectedly.\r\n\t\t\tif (this._get(i) === undefined) {\r\n\t\t\t\tnonPreviouslyMeasuredItemIndexes.push(i)\r\n\t\t\t\tconst height = this._measureItemHeight(i, firstShownItemIndex)\r\n\t\t\t\tlog('Item index', i, 'height', height)\r\n\t\t\t\tthis._set(i, height)\r\n\t\t\t\t// Update average item height calculation variables\r\n\t\t\t\t// related to the previously measured items\r\n\t\t\t\t// that're above the items currently being shown.\r\n\t\t\t\t// It is known to be a \"continuous\" measured items list,\r\n\t\t\t\t// because the code at the start of this function checks that.\r\n\t\t\t\tif (previousFirstMeasuredItemIndex === undefined || i < previousFirstMeasuredItemIndex) {\r\n\t\t\t\t\tthis.measuredItemsHeight += height\r\n\t\t\t\t\t// Update first measured item index.\r\n\t\t\t\t\tif (!firstMeasuredItemIndexHasBeenUpdated) {\r\n\t\t\t\t\t\t// log('Set first measured item index', i)\r\n\t\t\t\t\t\tthis.firstMeasuredItemIndex = i\r\n\t\t\t\t\t\tfirstMeasuredItemIndexHasBeenUpdated = true\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t\t// Update average item height calculation variables\r\n\t\t\t\t// related to the previously measured items\r\n\t\t\t\t// that're below the items currently being shown.\r\n\t\t\t\t// It is known to be a \"continuous\" measured items list,\r\n\t\t\t\t// because the code at the start of this function checks that.\r\n\t\t\t\tif (previousLastMeasuredItemIndex === undefined || i > previousLastMeasuredItemIndex) {\r\n\t\t\t\t\t// If `previousLastMeasuredItemIndex` is `undefined`\r\n\t\t\t\t\t// then `previousFirstMeasuredItemIndex` is also `undefined`\r\n\t\t\t\t\t// which means that the item's `height` has already been added\r\n\t\t\t\t\t// to `this.measuredItemsHeight` in the code above,\r\n\t\t\t\t\t// so this condition guards against counting the item's `height`\r\n\t\t\t\t\t// twice in `this.measuredItemsHeight`.\r\n\t\t\t\t\tif (previousLastMeasuredItemIndex !== undefined) {\r\n\t\t\t\t\t\t// Add newly shown item height.\r\n\t\t\t\t\t\tthis.measuredItemsHeight += height\r\n\t\t\t\t\t}\r\n\t\t\t\t\t// Update last measured item index.\r\n\t\t\t\t\tthis.lastMeasuredItemIndex = i\r\n\t\t\t\t}\r\n\t\t\t} else {\r\n\t\t\t\t// Validate that the item's height didn't change since it was last measured.\r\n\t\t\t\t// If it did, then display a warning and update the item's height\r\n\t\t\t\t// as an attempt to fix things.\r\n\t\t\t\t// If an item's height changes unexpectedly then it means that there'll\r\n\t\t\t\t// likely be \"content jumping\".\r\n\t\t\t\tconst previousHeight = this._get(i)\r\n\t\t\t\tconst height = this._measureItemHeight(i, firstShownItemIndex)\r\n\t\t\t\tif (previousHeight !== height) {\r\n\t\t\t\t\twarn('Item index', i, 'height changed unexpectedly: it was', previousHeight, 'before, but now it is', height, '. An item\\'s height is allowed to change only in two cases: when the item\\'s \"state\" changes and the developer calls `setItemState(i, newState)`, or when the item\\'s height changes for some other reason and the developer calls `onItemHeightChange(i)`. Perhaps you forgot to persist the item\\'s \"state\" by calling `setItemState(i, newState)` when it changed, and that \"state\" got lost when the item element was unmounted, which resulted in a different height when the item was shown again having its \"state\" reset.')\r\n\t\t\t\t\t// Update the item's height as an attempt to fix things.\r\n\t\t\t\t\tthis._set(i, height)\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\ti++\r\n\t\t}\r\n\t\t// // Update average item height.\r\n\t\t// this.updateAverageItemHeight()\r\n\t\treturn nonPreviouslyMeasuredItemIndexes\r\n\t}\r\n\r\n\t/**\r\n\t * Re-measures item height.\r\n\t * @param {number} i — Item index.\r\n\t * @param {number} firstShownItemIndex\r\n\t */\r\n\tremeasureItemHeight(i, firstShownItemIndex) {\r\n\t\tconst previousHeight = this._get(i)\r\n\t\tconst height = this._measureItemHeight(i, firstShownItemIndex)\r\n\t\t// // Because this function is called from `.onItemHeightChange()`,\r\n\t\t// // there're no guarantees in which circumstances a developer calls it,\r\n\t\t// // and for which item indexes.\r\n\t\t// // Therefore, to guard against cases of incorrect usage,\r\n\t\t// // this function won't crash anything if the item isn't rendered\r\n\t\t// // or hasn't been previously rendered.\r\n\t\t// if (height !== undefined) {\r\n\t\t// \treportError(`\"onItemHeightChange()\" has been called for item ${i}, but that item isn't rendered.`)\r\n\t\t// \treturn\r\n\t\t// }\r\n\t\t// if (previousHeight === undefined) {\r\n\t\t// \treportError(`\"onItemHeightChange()\" has been called for item ${i}, but that item hasn't been rendered before.`)\r\n\t\t// \treturn\r\n\t\t// }\r\n\t\tthis._set(i, height)\r\n\t\tthis.measuredItemsHeight += height - previousHeight\r\n\t\treturn height\r\n\t}\r\n\r\n\t// /**\r\n\t// * \"Average\" item height is stored as an instance variable.\r\n\t// * For example, for caching, so that it isn't calculated every time it's requested.\r\n\t// * But that would be negligible performance gain, not really worth the extra code.\r\n\t// * Another thing it's stored for as an instance variable is\r\n\t// * keeping \"previous\" \"average\" item height, because it can be more precise\r\n\t// * than the newly calculated \"average\" item height, provided it had\r\n\t// * more \"samples\" (measured items). The newly calculated average item height\r\n\t// * could get less samples in a scenario when the scroll somehow jumps\r\n\t// * from one position to some other distant position: in that case previous\r\n\t// * \"total measured items height\" is discarded and the new one is initialized.\r\n\t// * Could such situation happen in real life? I guess, it's unlikely.\r\n\t// * So I'm commenting out this code, but still keeping it just in case.\r\n\t// */\r\n\t// updateAverageItemHeight() {\r\n\t// \tthis.averageItemHeightSamplesCount = this.lastMeasuredItemIndex - this.firstMeasuredItemIndex + 1\r\n\t// \tthis.averageItemHeight = this.measuredItemsHeight / this.averageItemHeightSamplesCount\r\n\t// }\r\n\t//\r\n\t// /**\r\n\t// * Public API: is called by `VirtualScroller`.\r\n\t// * @return {number}\r\n\t// */\r\n\t// getAverage() {\r\n\t// \t// Previously measured average item height might still be\r\n\t// \t// more precise if it contains more measured items (\"samples\").\r\n\t// \tif (this.previousAverageItemHeight) {\r\n\t// \t\tif (this.previousAverageItemHeightSamplesCount > this.averageItemHeightSamplesCount) {\r\n\t// \t\t\treturn this.previousAverageItemHeight\r\n\t// \t\t}\r\n\t// \t}\r\n\t// \treturn this.averageItemHeight || 0\r\n\t// }\r\n\r\n\t/**\r\n\t * Public API: is called by `VirtualScroller`.\r\n\t * @return {number}\r\n\t */\r\n\tgetAverage() {\r\n\t\tif (this.lastMeasuredItemIndex === undefined) {\r\n\t\t\treturn 0\r\n\t\t}\r\n\t\treturn this.measuredItemsHeight / (this.lastMeasuredItemIndex - this.firstMeasuredItemIndex + 1)\r\n\t}\r\n\r\n\tonPrepend(count) {\r\n\t\tif (this.firstMeasuredItemIndex !== undefined) {\r\n\t\t\tthis.firstMeasuredItemIndex += count\r\n\t\t\tthis.lastMeasuredItemIndex += count\r\n\t\t}\r\n\t}\r\n}"],"mappings":";;;;;;AAAA,OAAOA,GAAP,IAAcC,IAAd,EAAoBC,OAApB,EAA6BC,WAA7B,QAAgD,oBAAhD;;IAEqBC,W;EACpB,2BAKG;IAAA,IAJFC,SAIE,QAJFA,SAIE;IAAA,IAHFC,WAGE,QAHFA,WAGE;IAAA,IAFFC,aAEE,QAFFA,aAEE;IAAA,IADFC,aACE,QADFA,aACE;;IAAA;;IACF,KAAKH,SAAL,GAAiBA,SAAjB;IACA,KAAKI,IAAL,GAAYF,aAAZ;IACA,KAAKG,IAAL,GAAYF,aAAZ;IACA,KAAKG,KAAL;EACA;;;;WAED,iBAAQ;MACP,KAAKC,mBAAL,GAA2B,CAA3B,CADO,CAEP;MACA;MACA;MACA;MACA;MACA;MACA;MACA;MACA;;MACA,KAAKC,sBAAL,GAA8BC,SAA9B;MACA,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,KAAgCC,SAApC,EAA+C;QAC9C,KAAKD,sBAAL,IAA+BgB,KAA/B;QACA,KAAKd,qBAAL,IAA8Bc,KAA9B;MACA;IACD;;;;;;SAlQmBzB,W"}
package/modules/Layout.js CHANGED
@@ -84,7 +84,7 @@ var Layout = /*#__PURE__*/function () {
84
84
 
85
85
  var itemsCount = _ref2.itemsCount,
86
86
  columnsCount = _ref2.columnsCount,
87
- initialLayout = _ref2.initialLayout;
87
+ beforeStart = _ref2.beforeStart;
88
88
  var firstShownItemIndex;
89
89
  var lastShownItemIndex; // If there're no items then `firstShownItemIndex` stays `undefined`.
90
90
 
@@ -98,7 +98,7 @@ var Layout = /*#__PURE__*/function () {
98
98
  };
99
99
 
100
100
  firstShownItemIndex = 0;
101
- lastShownItemIndex = initialLayout ? this.getInitialLayoutValueWithFallback('lastShownItemIndex', getLastShownItemIndex, 0) : getLastShownItemIndex();
101
+ lastShownItemIndex = beforeStart ? this.getInitialLayoutValueWithFallback('lastShownItemIndex', getLastShownItemIndex, 0) : getLastShownItemIndex();
102
102
  }
103
103
 
104
104
  return {
@@ -1 +1 @@
1
- {"version":3,"file":"Layout.js","names":["log","warn","ScrollableContainerNotReadyError","Layout","bypass","getInitialEstimatedItemHeight","getInitialEstimatedVisibleItemRowsCount","measureItemsBatchSize","getPrerenderMargin","getVerticalSpacing","getVerticalSpacingBeforeResize","getColumnsCount","getColumnsCountBeforeResize","getItemHeight","getItemHeightBeforeResize","getBeforeResizeItemsCount","getAverageItemHeight","getMaxVisibleAreaHeight","getPreviouslyCalculatedLayout","name","getValue","defaultValue","error","itemsCount","columnsCount","initialLayout","firstShownItemIndex","lastShownItemIndex","getLastShownItemIndex","getInitialLastShownItemIndex","getInitialLayoutValueWithFallback","beforeItemsHeight","afterItemsHeight","estimatedRowsCount","getEstimatedRowsCountForHeight","isNaN","Error","Math","min","height","estimatedItemHeight","getEstimatedItemHeight","verticalSpacing","ceil","averageItemHeight","prependedItemsCount","appendedItemsCount","shouldRestoreScrollPosition","onResetGridLayout","appendedRowsCount","addedHeightAfter","prependedRowsCount","addedHeightBefore","shownItemsCountBeforeItemsUpdate","afterItemsCount","i","nonMeasuredAreaHeight","indexOfTheFirstItemInTheRow","itemsCountToRenderForMeasurement","Infinity","undefined","firstNonMeasuredItemIndex","visibleAreaTop","visibleAreaBottom","indexes","_getShownItemIndex","fromIndex","findFirstShownItemIndex","getNonVisibleListShownItemIndexes","findLastShownItemIndex","parameters","beforeResize","beforeResizeItemsCount","notFound","beforeResizeItemsHeight","floor","currentRowFirstItemIndex","hasMoreRows","verticalSpacingAfterCurrentRow","currentRowHeight","columnIndex","itemHeight","getItemNotMeasuredIndexes","max","itemsHeightFromFirstRowToThisRow","rowStepsIntoVisibleAreaTop","rowStepsOutOfVisibleAreaBottomOrIsAtTheBorder","layout","beforeItemsCount","getBeforeItemsHeight","rowHeight","lastShownRowIndex","topOffsetInsideScrollableContainer","beforeResizeRowsCount","maxBeforeResizeRowsCount","beforeResizeRowIndex","itemRowIndex","rowIndex","LAYOUT_REASON","SCROLL","STOPPED_SCROLLING","MANUAL","STARTED","NON_MEASURED_ITEMS_HAVE_BEEN_MEASURED","VIEWPORT_WIDTH_CHANGED","VIEWPORT_HEIGHT_CHANGED","VIEWPORT_SIZE_UNCHANGED","ITEM_HEIGHT_CHANGED","ITEMS_CHANGED","TOP_OFFSET_CHANGED"],"sources":["../source/Layout.js"],"sourcesContent":["import log, { warn } from './utility/debug.js'\r\nimport ScrollableContainerNotReadyError from './ScrollableContainerNotReadyError.js'\r\n\r\nexport default class Layout {\r\n\tconstructor({\r\n\t\tbypass,\r\n\t\tgetInitialEstimatedItemHeight,\r\n\t\tgetInitialEstimatedVisibleItemRowsCount,\r\n\t\tmeasureItemsBatchSize,\r\n\t\tgetPrerenderMargin,\r\n\t\tgetVerticalSpacing,\r\n\t\tgetVerticalSpacingBeforeResize,\r\n\t\tgetColumnsCount,\r\n\t\tgetColumnsCountBeforeResize,\r\n\t\tgetItemHeight,\r\n\t\tgetItemHeightBeforeResize,\r\n\t\tgetBeforeResizeItemsCount,\r\n\t\tgetAverageItemHeight,\r\n\t\tgetMaxVisibleAreaHeight,\r\n\t\tgetPreviouslyCalculatedLayout\r\n\t}) {\r\n\t\tthis.bypass = bypass\r\n\t\tthis.getInitialEstimatedItemHeight = getInitialEstimatedItemHeight\r\n\t\tthis.getInitialEstimatedVisibleItemRowsCount = getInitialEstimatedVisibleItemRowsCount\r\n\t\tthis.measureItemsBatchSize = measureItemsBatchSize\r\n\t\tthis.getPrerenderMargin = getPrerenderMargin\r\n\t\tthis.getVerticalSpacing = getVerticalSpacing\r\n\t\tthis.getVerticalSpacingBeforeResize = getVerticalSpacingBeforeResize\r\n\t\tthis.getColumnsCount = getColumnsCount\r\n\t\tthis.getColumnsCountBeforeResize = getColumnsCountBeforeResize\r\n\t\tthis.getItemHeight = getItemHeight\r\n\t\tthis.getItemHeightBeforeResize = getItemHeightBeforeResize\r\n\t\tthis.getBeforeResizeItemsCount = getBeforeResizeItemsCount\r\n\t\tthis.getAverageItemHeight = getAverageItemHeight\r\n\t\tthis.getMaxVisibleAreaHeight = getMaxVisibleAreaHeight\r\n\t\t//\r\n\t\t// The \"previously calculated layout\" feature is not currently used.\r\n\t\t//\r\n\t\t// The current layout snapshot could be stored as a \"previously calculated layout\" variable\r\n\t\t// so that it could theoretically be used when calculating new layout incrementally\r\n\t\t// rather than from scratch, which would be an optimization.\r\n\t\t//\r\n\t\tthis.getPreviouslyCalculatedLayout = getPreviouslyCalculatedLayout\r\n\t}\r\n\r\n\t// React `<VirtualScroller/>` component attempts to create the initial state\r\n\t// before the component tree has mounted. This could result in an inability to\r\n\t// calculate some initial layout values like `columnsCount` or `lastShownItemIndex`.\r\n\t// Such errors aren't considered critical because layout will be re-calculated\r\n\t// after the component mounts. The workaround is to use some sane default values\r\n\t// until the scrollable container has mounted.\r\n\tgetInitialLayoutValueWithFallback(name, getValue, defaultValue) {\r\n\t\ttry {\r\n\t\t\treturn getValue()\r\n\t\t} catch (error) {\r\n\t\t\tif (error instanceof ScrollableContainerNotReadyError) {\r\n\t\t\t\tlog('Couldn\\'t calculate', name, 'before scrollable container is ready. Default to', defaultValue);\r\n\t\t\t\treturn defaultValue\r\n\t\t\t} else {\r\n\t\t\t\tthrow error\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\r\n\tgetInitialLayoutValues({\r\n\t\titemsCount,\r\n\t\tcolumnsCount,\r\n\t\tinitialLayout\r\n\t}) {\r\n\t\tlet firstShownItemIndex\r\n\t\tlet lastShownItemIndex\r\n\t\t// If there're no items then `firstShownItemIndex` stays `undefined`.\r\n\t\tif (itemsCount > 0) {\r\n\t\t\tconst getLastShownItemIndex = () => {\r\n\t\t\t\treturn this.getInitialLastShownItemIndex({\r\n\t\t\t\t\titemsCount,\r\n\t\t\t\t\tcolumnsCount,\r\n\t\t\t\t\tfirstShownItemIndex\r\n\t\t\t\t})\r\n\t\t\t}\r\n\t\t\tfirstShownItemIndex = 0\r\n\t\t\tlastShownItemIndex = initialLayout\r\n\t\t\t\t? this.getInitialLayoutValueWithFallback(\r\n\t\t\t\t\t'lastShownItemIndex',\r\n\t\t\t\t\tgetLastShownItemIndex,\r\n\t\t\t\t\t0\r\n\t\t\t\t)\r\n\t\t\t: getLastShownItemIndex()\r\n\t\t}\r\n\t\treturn {\r\n\t\t\tbeforeItemsHeight: 0,\r\n\t\t\tafterItemsHeight: 0,\r\n\t\t\tfirstShownItemIndex,\r\n\t\t\tlastShownItemIndex\r\n\t\t}\r\n\t}\r\n\r\n\tgetInitialLastShownItemIndex({\r\n\t\titemsCount,\r\n\t\tcolumnsCount,\r\n\t\tfirstShownItemIndex\r\n\t}) {\r\n\t\tif (this.bypass) {\r\n\t\t\treturn itemsCount - 1\r\n\t\t}\r\n\t\t// On server side, at initialization time,\r\n\t\t// `scrollableContainer` is `undefined`,\r\n\t\t// so default to `1` estimated rows count.\r\n\t\tlet estimatedRowsCount = 1\r\n\t\tif (this.getMaxVisibleAreaHeight()) {\r\n\t\t\testimatedRowsCount = this.getEstimatedRowsCountForHeight(this.getMaxVisibleAreaHeight() + this.getPrerenderMargin())\r\n\t\t} else if (this.getInitialEstimatedVisibleItemRowsCount) {\r\n\t\t\testimatedRowsCount = this.getInitialEstimatedVisibleItemRowsCount()\r\n\t\t\tif (isNaN(estimatedRowsCount)) {\r\n\t\t\t\tthrow new Error('[virtual-scroller] `getEstimatedVisibleItemRowsCount()` must return a number')\r\n\t\t\t}\r\n\t\t}\r\n\t\treturn Math.min(\r\n\t\t\tfirstShownItemIndex + (estimatedRowsCount * columnsCount - 1),\r\n\t\t\titemsCount - 1\r\n\t\t)\r\n\t}\r\n\r\n\tgetEstimatedRowsCountForHeight(height) {\r\n\t\tconst estimatedItemHeight = this.getEstimatedItemHeight()\r\n\t\tconst verticalSpacing = this.getVerticalSpacing()\r\n\t\tif (estimatedItemHeight) {\r\n\t\t\treturn Math.ceil((height + verticalSpacing) / (estimatedItemHeight + verticalSpacing))\r\n\t\t} else {\r\n\t\t\t// If no items have been rendered yet, and no `estimatedItemHeight` option\r\n\t\t\t// has been passed, then default to `1` estimated rows count in any `height`.\r\n\t\t\treturn 1\r\n\t\t}\r\n\t}\r\n\r\n\t/**\r\n\t * Returns estimated list item height.\r\n\t * (depends on which items have been previously rendered and measured).\r\n\t * @return {number}\r\n\t */\r\n\tgetEstimatedItemHeight() {\r\n\t\tconst averageItemHeight = this.getAverageItemHeight()\r\n\t\tif (averageItemHeight) {\r\n\t\t\treturn averageItemHeight\r\n\t\t}\r\n\t\tif (this.getInitialEstimatedItemHeight) {\r\n\t\t\tconst estimatedItemHeight = this.getInitialEstimatedItemHeight()\r\n\t\t\tif (isNaN(estimatedItemHeight)) {\r\n\t\t\t\tthrow new Error('[virtual-scroller] `getInitialEstimatedItemHeight()` must return a number')\r\n\t\t\t}\r\n\t\t\treturn estimatedItemHeight\r\n\t\t}\r\n\t\treturn 0\r\n\t}\r\n\r\n\tgetLayoutUpdateForItemsDiff({\r\n\t\tfirstShownItemIndex,\r\n\t\tlastShownItemIndex,\r\n\t\tbeforeItemsHeight,\r\n\t\tafterItemsHeight\r\n\t}, {\r\n\t\tprependedItemsCount,\r\n\t\tappendedItemsCount\r\n\t}, {\r\n\t\titemsCount,\r\n\t\tcolumnsCount,\r\n\t\tshouldRestoreScrollPosition,\r\n\t\tonResetGridLayout\r\n\t}) {\r\n\t\t// const layoutUpdate = {}\r\n\r\n\t\t// If the layout stays the same, then simply increase\r\n\t\t// the top and bottom margins proportionally to the amount\r\n\t\t// of the items added.\r\n\t\tconst averageItemHeight = this.getAverageItemHeight()\r\n\t\tconst verticalSpacing = this.getVerticalSpacing()\r\n\r\n\t\tif (appendedItemsCount > 0) {\r\n\t\t\tconst appendedRowsCount = Math.ceil(appendedItemsCount / columnsCount)\r\n\t\t\tconst addedHeightAfter = appendedRowsCount * (verticalSpacing + averageItemHeight)\r\n\r\n\t\t\tafterItemsHeight += addedHeightAfter\r\n\r\n\t\t\t// layoutUpdate = {\r\n\t\t\t// \t...layoutUpdate,\r\n\t\t\t// \tafterItemsHeight\r\n\t\t\t// }\r\n\t\t}\r\n\r\n\t\tif (prependedItemsCount > 0) {\r\n\t\t\tconst prependedRowsCount = Math.ceil(prependedItemsCount / columnsCount)\r\n\t\t\tconst addedHeightBefore = prependedRowsCount * (averageItemHeight + verticalSpacing)\r\n\r\n\t\t\tfirstShownItemIndex += prependedItemsCount\r\n\t\t\tlastShownItemIndex += prependedItemsCount\r\n\t\t\tbeforeItemsHeight += addedHeightBefore\r\n\r\n\t\t\t// If the currently shown items position on screen should be preserved\r\n\t\t\t// when prepending new items, then it means that:\r\n\t\t\t// * The current scroll position should be snapshotted.\r\n\t\t\t// * The current list height should be snapshotted.\r\n\t\t\t// * All prepended items should be shown so that their height could be\r\n\t\t\t// measured after they're rendered. Based on the prepended items' height,\r\n\t\t\t// the scroll position will be restored so that there's no \"jump of content\".\r\n\t\t\tif (shouldRestoreScrollPosition) {\r\n\t\t\t\tfirstShownItemIndex = 0\r\n\t\t\t\tbeforeItemsHeight = 0\r\n\t\t\t}\r\n\r\n\t\t\tif (prependedItemsCount % columnsCount > 0) {\r\n\t\t\t\t// Rows will be rebalanced as a result of prepending new items,\r\n\t\t\t\t// and row heights can change as a result, so re-layout items\r\n\t\t\t\t// after they've been measured (after the upcoming re-render).\r\n\t\t\t\t//\r\n\t\t\t\t// For example, consider a web page where item rows are `display: flex`.\r\n\t\t\t\t// Suppose there're 3 columns and it shows items from 4 to 6.\r\n\t\t\t\t//\r\n\t\t\t\t// ------------------------------------------\r\n\t\t\t\t// | Apples are | Bananas | Cranberries |\r\n\t\t\t\t// | green | | |\r\n\t\t\t\t// ------------------------------------------\r\n\t\t\t\t// | Dates | Elderberry | Figs are |\r\n\t\t\t\t// | | | tasty |\r\n\t\t\t\t// ------------------------------------------\r\n\t\t\t\t//\r\n\t\t\t\t// Now, 1 item gets prepended. As a result, all existing rows will have\r\n\t\t\t\t// a different set of items, which means that the row heights will change.\r\n\t\t\t\t//\r\n\t\t\t\t// ------------------------------------------\r\n\t\t\t\t// | Zucchini | Apples are | Bananas |\r\n\t\t\t\t// | | green | |\r\n\t\t\t\t// ------------------------------------------\r\n\t\t\t\t// | Cranberries | Dates | Elderberry |\r\n\t\t\t\t// ------------------------------------------\r\n\t\t\t\t// | Figs |\r\n\t\t\t\t// | are tasty |\r\n\t\t\t\t// ---------------\r\n\t\t\t\t//\r\n\t\t\t\t// As it can be seen above, the second row's height has changed from 2 to 1.\r\n\t\t\t\t// Not only that, but `itemHeights` have changed as well, so if you thought\r\n\t\t\t\t// that the library could easily recalculate row heights using `Math.max()` — \r\n\t\t\t\t// turns out it's not always the case.\r\n\t\t\t\t//\r\n\t\t\t\t// There could be an explicit opt-in option for automatically recalculating\r\n\t\t\t\t// row heights, but I don't want to write code for such an extremely rare\r\n\t\t\t\t// use case. Instead, use the `getColumnsCount()` parameter function when\r\n\t\t\t\t// fetching previous items.\r\n\r\n\t\t\t\tonResetGridLayout()\r\n\r\n\t\t\t\twarn('~ Prepended items count', prependedItemsCount, 'is not divisible by Columns Count', columnsCount, '~')\r\n\t\t\t\twarn('Layout reset required')\r\n\r\n\t\t\t\tconst shownItemsCountBeforeItemsUpdate = lastShownItemIndex - firstShownItemIndex + 1\r\n\r\n\t\t\t\tfirstShownItemIndex = 0\r\n\t\t\t\tbeforeItemsHeight = 0\r\n\r\n\t\t\t\tif (!shouldRestoreScrollPosition) {\r\n\t\t\t\t\t// Limit shown items count if too many items have been prepended.\r\n\t\t\t\t\tif (prependedItemsCount > shownItemsCountBeforeItemsUpdate) {\r\n\t\t\t\t\t\tlastShownItemIndex = this.getInitialLastShownItemIndex({\r\n\t\t\t\t\t\t\titemsCount,\r\n\t\t\t\t\t\t\tcolumnsCount,\r\n\t\t\t\t\t\t\tfirstShownItemIndex\r\n\t\t\t\t\t\t})\r\n\r\n\t\t\t\t\t\t// Approximate `afterItemsHeight` calculation.\r\n\t\t\t\t\t\tconst afterItemsCount = itemsCount - (lastShownItemIndex + 1)\r\n\t\t\t\t\t\tafterItemsHeight = Math.ceil(afterItemsCount / columnsCount) * (verticalSpacing + averageItemHeight)\r\n\r\n\t\t\t\t\t\t// layoutUpdate = {\r\n\t\t\t\t\t\t// \t...layoutUpdate,\r\n\t\t\t\t\t\t// \tafterItemsHeight\r\n\t\t\t\t\t\t// }\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t}\r\n\r\n\t\t\t// layoutUpdate = {\r\n\t\t\t// \t...layoutUpdate,\r\n\t\t\t// \tbeforeItemsHeight,\r\n\t\t\t// \tfirstShownItemIndex,\r\n\t\t\t// \tlastShownItemIndex\r\n\t\t\t// }\r\n\t\t}\r\n\r\n\t\t// return layoutUpdate\r\n\r\n\t\t// Overwrite all four props in all scenarios.\r\n\t\t// The reason is that only this way subsequent `setItems()` calls\r\n\t\t// will be truly \"stateless\" when a chain of `setItems()` calls\r\n\t\t// could be replaced with just the last one in a scenario when\r\n\t\t// `updateState()` calls are \"asynchronous\" (delayed execution).\r\n\t\t//\r\n\t\t// So, for example, the user calls `setItems()` with one set of items.\r\n\t\t// A `updateState()` call has been dispatched but the `state` hasn't been updated yet.\r\n\t\t// Then the user calls `setItems()` with another set of items.\r\n\t\t// If this function only returned a minimal set of properties that actually change,\r\n\t\t// the other layout properties of the second `setItems()` call wouldn't overwrite the ones\r\n\t\t// scheduled for update during the first `setItems()` call, resulting in an inconsistent `state`.\r\n\t\t//\r\n\t\t// For example, the first `setItems()` call does a `updateState()` call where it updates\r\n\t\t// `afterItemsHeight`, and then the second `setItems()` call only updates `beforeItemsHeight`\r\n\t\t// and `firstShownItemIndex` and `lastShownItemIndex`. If the second `setItems()` call was to\r\n\t\t// overwrite any effects of the pending-but-not-yet-applied first `setItems()` call, it would\r\n\t\t// have to call `updateState()` with an `afterItemsHeight` property too, even though it hasn't change.\r\n\t\t// That would be just to revert the change to `afterItemsHeight` state property already scheduled\r\n\t\t// by the first `setItems()` call.\r\n\t\t//\r\n\t\treturn {\r\n\t\t\tbeforeItemsHeight,\r\n\t\t\tafterItemsHeight,\r\n\t\t\tfirstShownItemIndex,\r\n\t\t\tlastShownItemIndex\r\n\t\t}\r\n\t}\r\n\r\n\t// If an item that hasn't been shown (and measured) yet is encountered\r\n\t// then show such item and then retry after it has been measured.\r\n\tgetItemNotMeasuredIndexes(i, {\r\n\t\titemsCount,\r\n\t\tfirstShownItemIndex,\r\n\t\tnonMeasuredAreaHeight,\r\n\t\tindexOfTheFirstItemInTheRow\r\n\t}) {\r\n\t\tlog('Item index', i, 'height is required for calculations but hasn\\'t been measured yet. Mark the item as \"shown\", rerender the list, measure the item\\'s height and redo the layout.')\r\n\r\n\t\tconst columnsCount = this.getColumnsCount()\r\n\r\n\t\tconst itemsCountToRenderForMeasurement = Math.min(\r\n\t\t\tthis.getEstimatedRowsCountForHeight(nonMeasuredAreaHeight) * columnsCount,\r\n\t\t\tthis.measureItemsBatchSize || Infinity,\r\n\t\t)\r\n\r\n\t\tif (firstShownItemIndex === undefined) {\r\n\t\t\tfirstShownItemIndex = indexOfTheFirstItemInTheRow\r\n\t\t}\r\n\r\n\t\tconst lastShownItemIndex = Math.min(\r\n\t\t\tindexOfTheFirstItemInTheRow + itemsCountToRenderForMeasurement - 1,\r\n\t\t\t// Guard against index overflow.\r\n\t\t\titemsCount - 1\r\n\t\t)\r\n\r\n\t\treturn {\r\n\t\t\tfirstNonMeasuredItemIndex: i,\r\n\t\t\tfirstShownItemIndex,\r\n\t\t\tlastShownItemIndex\r\n\t\t}\r\n\t}\r\n\r\n\t/**\r\n\t * Finds the indexes of the currently visible items.\r\n\t * @return {object} `{ firstShownItemIndex: number, lastShownItemIndex: number, firstNonMeasuredItemIndex: number? }`\r\n\t */\r\n\tgetShownItemIndexes({\r\n\t\titemsCount,\r\n\t\tvisibleAreaTop,\r\n\t\tvisibleAreaBottom\r\n\t}) {\r\n\t\tlet indexes = this._getShownItemIndex({\r\n\t\t\titemsCount,\r\n\t\t\tfromIndex: 0,\r\n\t\t\tvisibleAreaTop,\r\n\t\t\tvisibleAreaBottom,\r\n\t\t\tfindFirstShownItemIndex: true\r\n\t\t})\r\n\r\n\t\tif (indexes === null) {\r\n\t\t\treturn this.getNonVisibleListShownItemIndexes()\r\n\t\t}\r\n\r\n\t\tif (indexes.firstNonMeasuredItemIndex !== undefined) {\r\n\t\t\treturn indexes\r\n\t\t}\r\n\r\n\t\tconst { firstShownItemIndex, beforeItemsHeight } = indexes\r\n\r\n\t\tindexes = this._getShownItemIndex({\r\n\t\t\titemsCount,\r\n\t\t\tfromIndex: firstShownItemIndex,\r\n\t\t\tbeforeItemsHeight,\r\n\t\t\tvisibleAreaTop,\r\n\t\t\tvisibleAreaBottom,\r\n\t\t\tfindLastShownItemIndex: true\r\n\t\t})\r\n\r\n\t\tif (indexes === null) {\r\n\t\t\treturn this.getNonVisibleListShownItemIndexes()\r\n\t\t}\r\n\r\n\t\tif (indexes.firstNonMeasuredItemIndex !== undefined) {\r\n\t\t\treturn indexes\r\n\t\t}\r\n\r\n\t\tconst { lastShownItemIndex } = indexes\r\n\r\n\t\treturn {\r\n\t\t\tfirstShownItemIndex,\r\n\t\t\tlastShownItemIndex\r\n\t\t}\r\n\t}\r\n\r\n\t_getShownItemIndex(parameters) {\r\n\t\tconst {\r\n\t\t\tbeforeResize,\r\n\t\t\titemsCount,\r\n\t\t\tvisibleAreaTop,\r\n\t\t\tvisibleAreaBottom,\r\n\t\t\tfindFirstShownItemIndex,\r\n\t\t\tfindLastShownItemIndex,\r\n\t\t\t// backwards\r\n\t\t} = parameters\r\n\r\n\t\tlet {\r\n\t\t\tfromIndex,\r\n\t\t\tbeforeItemsHeight\r\n\t\t} = parameters\r\n\r\n\t\t// This function could potentially also use `this.getPreviouslyCalculatedLayout()`\r\n\t\t// in order to skip calculating visible item indexes from scratch\r\n\t\t// and instead just calculate the difference from a \"previously calculated layout\".\r\n\t\t//\r\n\t\t// I did a simple test in a web browser and found out that running the following\r\n\t\t// piece of code is less than 10 milliseconds:\r\n\t\t//\r\n\t\t// var startedAt = Date.now()\r\n\t\t// var i = 0\r\n\t\t// while (i < 1000000) {\r\n\t\t// i++\r\n\t\t// }\r\n\t\t// console.log(Date.now() - startedAt)\r\n\t\t//\r\n\t\t// Which becomes negligible in my project's use case (a couple thousands items max).\r\n\t\t//\r\n\t\t// If someone would attempt to use a \"previously calculated layout\" here\r\n\t\t// then `shownItemsHeight` would also have to be returned from this function:\r\n\t\t// the total height of all shown items including vertical spacing between them.\r\n\t\t//\r\n\t\t// If \"previously calculated layout\" would be used then it would first find\r\n\t\t// `firstShownItemIndex` and then find `lastShownItemIndex` as part of two\r\n\t\t// separate calls of this function, each with or without `backwards` flag,\r\n\t\t// depending on whether `visibleAreaTop` and `visibleAreBottom` have shifted up or down.\r\n\r\n\t\tlet firstShownItemIndex\r\n\t\tlet lastShownItemIndex\r\n\r\n\t\t// It's not always required to pass `beforeItemsHeight` parameter:\r\n\t\t// when `fromIndex` is `0`, it's also assumed to be `0`.\r\n\t\tif (fromIndex === 0) {\r\n\t\t\tbeforeItemsHeight = 0\r\n\t\t}\r\n\r\n\t\tif (beforeItemsHeight === undefined) {\r\n\t\t\tthrow new Error('[virtual-scroller] `beforeItemsHeight` not passed to `Layout.getShownItemIndexes()` when starting from index ' + fromIndex);\r\n\t\t}\r\n\r\n\t\t// const backwards = false\r\n\t\t// while (backwards ? i >= 0 : i < itemsCount) {}\r\n\r\n\t\tif (!beforeResize) {\r\n\t\t\tconst beforeResizeItemsCount = this.getBeforeResizeItemsCount()\r\n\t\t\tif (beforeResizeItemsCount > fromIndex) {\r\n\t\t\t\t// First search for the item in \"before resize\" items.\r\n\t\t\t\tconst {\r\n\t\t\t\t\tnotFound,\r\n\t\t\t\t\tbeforeItemsHeight: beforeResizeItemsHeight,\r\n\t\t\t\t\tfirstShownItemIndex,\r\n\t\t\t\t\tlastShownItemIndex\r\n\t\t\t\t} = this._getShownItemIndex({\r\n\t\t\t\t\t...parameters,\r\n\t\t\t\t\tbeforeResize: true,\r\n\t\t\t\t\titemsCount: beforeResizeItemsCount\r\n\t\t\t\t})\r\n\r\n\t\t\t\t// If the item was not found in \"before resize\" items\r\n\t\t\t\t// then search in regular items skipping \"before resize\" ones.\r\n\t\t\t\tif (notFound) {\r\n\t\t\t\t\tbeforeItemsHeight = beforeResizeItemsHeight\r\n\t\t\t\t\tfromIndex += beforeResizeItemsCount\r\n\t\t\t\t} else {\r\n\t\t\t\t\t// If the item was found in \"before resize\" items\r\n\t\t\t\t\t// then return the result.\r\n\t\t\t\t\t// Rebalance first / last shown item indexes based on\r\n\t\t\t\t\t// the current columns count, if required.\r\n\t\t\t\t\tconst columnsCount = this.getColumnsCount()\r\n\t\t\t\t\treturn {\r\n\t\t\t\t\t\tfirstShownItemIndex: firstShownItemIndex === undefined\r\n\t\t\t\t\t\t\t? undefined\r\n\t\t\t\t\t\t\t: Math.floor(firstShownItemIndex / columnsCount) * columnsCount,\r\n\t\t\t\t\t\tlastShownItemIndex: lastShownItemIndex === undefined\r\n\t\t\t\t\t\t\t? undefined\r\n\t\t\t\t\t\t\t: Math.floor(lastShownItemIndex / columnsCount) * columnsCount,\r\n\t\t\t\t\t\tbeforeItemsHeight: beforeResizeItemsHeight\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\tconst columnsCount = beforeResize ? this.getColumnsCountBeforeResize() : this.getColumnsCount()\r\n\t\tconst verticalSpacing = beforeResize ? this.getVerticalSpacingBeforeResize() : this.getVerticalSpacing()\r\n\r\n\t\tlet i = fromIndex\r\n\t\twhile (i < itemsCount) {\r\n\t\t\tconst currentRowFirstItemIndex = i\r\n\r\n\t\t\tconst hasMoreRows = itemsCount > currentRowFirstItemIndex + columnsCount\r\n\t\t\tconst verticalSpacingAfterCurrentRow = hasMoreRows ? verticalSpacing : 0\r\n\r\n\t\t\tlet currentRowHeight = 0\r\n\r\n\t\t\t// Calculate current row height.\r\n\t\t\tlet columnIndex = 0\r\n\t\t\twhile (columnIndex < columnsCount && i < itemsCount) {\r\n\t\t\t\tconst itemHeight = beforeResize ? this.getItemHeightBeforeResize(i) : this.getItemHeight(i)\r\n\r\n\t\t\t\t// If this item hasn't been measured yet (or re-measured after a resize)\r\n\t\t\t\t// then mark it as the first non-measured one.\r\n\t\t\t\t//\r\n\t\t\t\t// Can't happen by definition when `beforeResize` parameter is `true`.\r\n\t\t\t\t//\r\n\t\t\t\tif (itemHeight === undefined) {\r\n\t\t\t\t\treturn this.getItemNotMeasuredIndexes(i, {\r\n\t\t\t\t\t\titemsCount,\r\n\t\t\t\t\t\tfirstShownItemIndex: findLastShownItemIndex ? fromIndex : undefined,\r\n\t\t\t\t\t\tindexOfTheFirstItemInTheRow: currentRowFirstItemIndex,\r\n\t\t\t\t\t\tnonMeasuredAreaHeight: (visibleAreaBottom + this.getPrerenderMargin()) - beforeItemsHeight\r\n\t\t\t\t\t})\r\n\t\t\t\t}\r\n\r\n\t\t\t\tcurrentRowHeight = Math.max(currentRowHeight, itemHeight)\r\n\r\n\t\t\t\tcolumnIndex++\r\n\t\t\t\ti++\r\n\t\t\t}\r\n\r\n\t\t\tconst itemsHeightFromFirstRowToThisRow = beforeItemsHeight + currentRowHeight\r\n\r\n\t\t\tconst rowStepsIntoVisibleAreaTop = itemsHeightFromFirstRowToThisRow > visibleAreaTop - this.getPrerenderMargin()\r\n\t\t\tconst rowStepsOutOfVisibleAreaBottomOrIsAtTheBorder = itemsHeightFromFirstRowToThisRow + verticalSpacingAfterCurrentRow >= visibleAreaBottom + this.getPrerenderMargin()\r\n\r\n\t\t\t// if (backwards) {\r\n\t\t\t// \tif (findFirstShownItemIndex) {\r\n\t\t\t// \t\tif (rowStepsOutOfVisibleAreaTop) {\r\n\t\t\t// \t\t\treturn {\r\n\t\t\t// \t\t\t\tfirstShownItemIndex: currentRowFirstItemIndex + columnsCount\r\n\t\t\t// \t\t\t}\r\n\t\t\t// \t\t}\r\n\t\t\t// \t} else if (findLastShownItemIndex) {\r\n\t\t\t// \t\tif (rowStepsIntoVisibleAreaBottom) {\r\n\t\t\t// \t\t\treturn {\r\n\t\t\t// \t\t\t\tlastShownItemIndex: currentRowFirstItemIndex + columnsCount - 1\r\n\t\t\t// \t\t\t}\r\n\t\t\t// \t\t}\r\n\t\t\t// \t}\r\n\t\t\t// }\r\n\r\n\t\t\tif (findFirstShownItemIndex) {\r\n\t\t\t\tif (rowStepsIntoVisibleAreaTop) {\r\n\t\t\t\t\t// If item is the first one visible in the viewport\r\n\t\t\t\t\t// then start showing items from this row.\r\n\t\t\t\t\treturn {\r\n\t\t\t\t\t\tfirstShownItemIndex: currentRowFirstItemIndex,\r\n\t\t\t\t\t\tbeforeItemsHeight\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t} else if (findLastShownItemIndex) {\r\n\t\t\t\tif (rowStepsOutOfVisibleAreaBottomOrIsAtTheBorder) {\r\n\t\t\t\t\treturn {\r\n\t\t\t\t\t\tlastShownItemIndex: Math.min(\r\n\t\t\t\t\t\t\t// The index of the last item in the current row.\r\n\t\t\t\t\t\t\tcurrentRowFirstItemIndex + columnsCount - 1,\r\n\t\t\t\t\t\t\t// Guards against index overflow.\r\n\t\t\t\t\t\t\titemsCount - 1\r\n\t\t\t\t\t\t)\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t}\r\n\r\n\t\t\tbeforeItemsHeight += currentRowHeight + verticalSpacingAfterCurrentRow\r\n\r\n\t\t\t// if (backwards) {\r\n\t\t\t// \t// Set `i` to be the first item of the current row.\r\n\t\t\t// \ti -= columnsCount\r\n\t\t\t// \tconst prevoiusRowIsBeforeResize = i - 1 < this.getBeforeResizeItemsCount()\r\n\t\t\t// \tconst previousRowColumnsCount = prevoiusRowIsBeforeResize ? this.getColumnsCountBeforeResize() : this.getColumnsCount()\r\n\t\t\t// \t// Set `i` to be the first item of the previous row.\r\n\t\t\t// \ti -= previousRowColumnsCount\r\n\t\t\t// }\r\n\t\t}\r\n\r\n\t\t// if (backwards) {\r\n\t\t// \tif (findFirstShownItemIndex) {\r\n\t\t// \t\twarn('The list is supposed to be visible but no visible item has been found (while traversing backwards)')\r\n\t\t// \t\treturn null\r\n\t\t// \t} else if (findLastShownItemIndex) {\r\n\t\t// \t\treturn {\r\n\t\t// \t\t\tfirstShownItemIndex: 0\r\n\t\t// \t\t}\r\n\t\t// \t}\r\n\t\t// }\r\n\r\n\t\tif (beforeResize) {\r\n\t\t\treturn {\r\n\t\t\t\tnotFound: true,\r\n\t\t\t\tbeforeItemsHeight\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\t// This case isn't supposed to happen but it could hypothetically happen\r\n\t\t// because the list height is measured from the user's screen and\r\n\t\t// not necessarily can be trusted.\r\n\t\tif (findFirstShownItemIndex) {\r\n\t\t\twarn('The list is supposed to be visible but no visible item has been found')\r\n\t\t\treturn null\r\n\t\t} else if (findLastShownItemIndex) {\r\n\t\t\treturn {\r\n\t\t\t\tlastShownItemIndex: itemsCount - 1\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\r\n\tgetNonVisibleListShownItemIndexes() {\r\n\t\tconst layout = {\r\n\t\t\tfirstShownItemIndex: 0,\r\n\t\t\tlastShownItemIndex: 0\r\n\t\t}\r\n\t\tif (this.getItemHeight(0) === undefined) {\r\n\t\t\tlayout.firstNonMeasuredItemIndex = 0\r\n\t\t}\r\n\t\treturn layout\r\n\t}\r\n\r\n\t/**\r\n\t * Measures \"before\" items height.\r\n\t * @param {number} beforeItemsCount — Basically, first shown item index.\r\n\t * @return {number}\r\n\t */\r\n\tgetBeforeItemsHeight(\r\n\t\tbeforeItemsCount,\r\n\t\t{ beforeResize } = {}\r\n\t) {\r\n\t\t// This function could potentially also use `this.getPreviouslyCalculatedLayout()`\r\n\t\t// in order to skip calculating visible item indexes from scratch\r\n\t\t// and instead just calculate the difference from a \"previously calculated layout\".\r\n\t\t//\r\n\t\t// I did a simple test in a web browser and found out that running the following\r\n\t\t// piece of code is less than 10 milliseconds:\r\n\t\t//\r\n\t\t// var startedAt = Date.now()\r\n\t\t// var i = 0\r\n\t\t// while (i < 1000000) {\r\n\t\t// i++\r\n\t\t// }\r\n\t\t// console.log(Date.now() - startedAt)\r\n\t\t//\r\n\t\t// Which becomes negligible in my project's use case (a couple thousands items max).\r\n\r\n\t\tlet beforeItemsHeight = 0\r\n\t\tlet i = 0\r\n\r\n\t\tif (!beforeResize) {\r\n\t\t\tconst beforeResizeItemsCount = this.getBeforeResizeItemsCount()\r\n\r\n\t\t\tif (beforeResizeItemsCount > 0) {\r\n\t\t\t\t// First add all \"before resize\" item heights.\r\n\t\t\t\tbeforeItemsHeight = this.getBeforeItemsHeight(\r\n\t\t\t\t\t// `firstShownItemIndex` (called `beforeItemsCount`) could be greater than\r\n\t\t\t\t\t// `beforeResizeItemsCount` when the user scrolls down.\r\n\t\t\t\t\t// `firstShownItemIndex` (called `beforeItemsCount`) could be less than\r\n\t\t\t\t\t// `beforeResizeItemsCount` when the user scrolls up.\r\n\t\t\t\t\tMath.min(beforeItemsCount, beforeResizeItemsCount),\r\n\t\t\t\t\t{ beforeResize: true }\r\n\t\t\t\t)\r\n\t\t\t\ti = beforeResizeItemsCount\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tconst columnsCount = beforeResize ? this.getColumnsCountBeforeResize() : this.getColumnsCount()\r\n\t\tconst verticalSpacing = beforeResize ? this.getVerticalSpacingBeforeResize() : this.getVerticalSpacing()\r\n\r\n\t\twhile (i < beforeItemsCount) {\r\n\t\t\tconst currentRowFirstItemIndex = i\r\n\r\n\t\t\tlet rowHeight = 0\r\n\t\t\tlet columnIndex = 0\r\n\t\t\t// Not checking for `itemsCount` overflow here because `i = beforeItemsCount`\r\n\t\t\t// can only start at the start of a row, meaning that when calculating\r\n\t\t\t// \"before items height\" it's not supposed to add item heights from the\r\n\t\t\t// last row of items because in that case it would have to iterate from\r\n\t\t\t// `i === beforeItemsCount` and that condition is already checked above.\r\n\t\t\t// while (i < itemsCount) {\r\n\t\t\twhile (columnIndex < columnsCount) {\r\n\t\t\t\tlet itemHeight = beforeResize ? this.getItemHeightBeforeResize(i) : this.getItemHeight(i)\r\n\t\t\t\tif (itemHeight === undefined) {\r\n\t\t\t\t\t// `itemHeight` can only be `undefined` when not `beforeResize`.\r\n\t\t\t\t\t// Use the current \"average item height\" as a substitute.\r\n\t\t\t\t\titemHeight = this.getAverageItemHeight()\r\n\t\t\t\t}\r\n\t\t\t\trowHeight = Math.max(rowHeight, itemHeight)\r\n\t\t\t\ti++\r\n\t\t\t\tcolumnIndex++\r\n\t\t\t}\r\n\r\n\t\t\tbeforeItemsHeight += rowHeight\r\n\t\t\tbeforeItemsHeight += verticalSpacing\r\n\t\t}\r\n\r\n\t\treturn beforeItemsHeight\r\n\t}\r\n\r\n\t/**\r\n\t * Measures \"after\" items height.\r\n\t * @param {number} lastShownItemIndex — Last shown item index.\r\n\t * @param {number} itemsCount — Items count.\r\n\t * @return {number}\r\n\t */\r\n\tgetAfterItemsHeight(\r\n\t\tlastShownItemIndex,\r\n\t\titemsCount\r\n\t) {\r\n\t\t// This function could potentially also use `this.getPreviouslyCalculatedLayout()`\r\n\t\t// in order to skip calculating visible item indexes from scratch\r\n\t\t// and instead just calculate the difference from a \"previously calculated layout\".\r\n\t\t//\r\n\t\t// I did a simple test in a web browser and found out that running the following\r\n\t\t// piece of code is less than 10 milliseconds:\r\n\t\t//\r\n\t\t// var startedAt = Date.now()\r\n\t\t// var i = 0\r\n\t\t// while (i < 1000000) {\r\n\t\t// i++\r\n\t\t// }\r\n\t\t// console.log(Date.now() - startedAt)\r\n\t\t//\r\n\t\t// Which becomes negligible in my project's use case (a couple thousands items max).\r\n\r\n\t\tconst columnsCount = this.getColumnsCount()\r\n\t\tconst lastShownRowIndex = Math.floor(lastShownItemIndex / columnsCount)\r\n\r\n\t\tlet afterItemsHeight = 0\r\n\r\n\t\tlet i = lastShownItemIndex + 1\r\n\t\twhile (i < itemsCount) {\r\n\t\t\tlet rowHeight = 0\r\n\t\t\tlet columnIndex = 0\r\n\t\t\twhile (columnIndex < columnsCount && i < itemsCount) {\r\n\t\t\t\tlet itemHeight = this.getItemHeight(i)\r\n\t\t\t\tif (itemHeight === undefined) {\r\n\t\t\t\t\titemHeight = this.getAverageItemHeight()\r\n\t\t\t\t}\r\n\t\t\t\trowHeight = Math.max(rowHeight, itemHeight)\r\n\t\t\t\ti++\r\n\t\t\t\tcolumnIndex++\r\n\t\t\t}\r\n\r\n\t\t\t// Add all \"after\" items height.\r\n\t\t\tafterItemsHeight += this.getVerticalSpacing()\r\n\t\t\tafterItemsHeight += rowHeight\r\n\t\t}\r\n\r\n\t\treturn afterItemsHeight\r\n\t}\r\n\r\n\t/**\r\n\t * Returns the items's top offset relative to the top edge of the first item.\r\n\t * @param {number} i — Item index\r\n\t * @return {[number]} Returns `undefined` if any of the previous items haven't been rendered yet.\r\n\t */\r\n\tgetItemTopOffset(i) {\r\n\t\tlet topOffsetInsideScrollableContainer = 0\r\n\r\n\t\tconst beforeResizeItemsCount = this.getBeforeResizeItemsCount()\r\n\t\tconst beforeResizeRowsCount = beforeResizeItemsCount === 0\r\n\t\t\t? 0\r\n\t\t\t: Math.ceil(beforeResizeItemsCount / this.getColumnsCountBeforeResize())\r\n\r\n\t\tconst maxBeforeResizeRowsCount = i < beforeResizeItemsCount\r\n\t\t\t? Math.floor(i / this.getColumnsCountBeforeResize())\r\n\t\t\t: beforeResizeRowsCount\r\n\r\n\t\tlet beforeResizeRowIndex = 0\r\n\t\twhile (beforeResizeRowIndex < maxBeforeResizeRowsCount) {\r\n\t\t\tconst rowHeight = this.getItemHeightBeforeResize(\r\n\t\t\t\tbeforeResizeRowIndex * this.getColumnsCountBeforeResize()\r\n\t\t\t)\r\n\r\n\t\t\ttopOffsetInsideScrollableContainer += rowHeight\r\n\t\t\ttopOffsetInsideScrollableContainer += this.getVerticalSpacingBeforeResize()\r\n\r\n\t\t\tbeforeResizeRowIndex++\r\n\t\t}\r\n\r\n\t\tconst itemRowIndex = Math.floor((i - beforeResizeItemsCount) / this.getColumnsCount())\r\n\r\n\t\tlet rowIndex = 0\r\n\t\twhile (rowIndex < itemRowIndex) {\r\n\t\t\tlet rowHeight = 0\r\n\t\t\tlet columnIndex = 0\r\n\t\t\twhile (columnIndex < this.getColumnsCount()) {\r\n\t\t\t\tconst itemHeight = this.getItemHeight(\r\n\t\t\t\t\tbeforeResizeItemsCount + rowIndex * this.getColumnsCount() + columnIndex\r\n\t\t\t\t)\r\n\t\t\t\tif (itemHeight === undefined) {\r\n\t\t\t\t\treturn\r\n\t\t\t\t}\r\n\t\t\t\trowHeight = Math.max(rowHeight, itemHeight)\r\n\t\t\t\tcolumnIndex++\r\n\t\t\t}\r\n\r\n\t\t\ttopOffsetInsideScrollableContainer += rowHeight\r\n\t\t\ttopOffsetInsideScrollableContainer += this.getVerticalSpacing()\r\n\r\n\t\t\trowIndex++\r\n\t\t}\r\n\r\n\t\treturn topOffsetInsideScrollableContainer\r\n\t}\r\n}\r\n\r\nexport const LAYOUT_REASON = {\r\n\tSCROLL: 'scroll',\r\n\tSTOPPED_SCROLLING: 'stopped scrolling',\r\n\tMANUAL: 'manual',\r\n\tSTARTED: 'started',\r\n\tNON_MEASURED_ITEMS_HAVE_BEEN_MEASURED: 'non-measured item heights have been measured',\r\n\tVIEWPORT_WIDTH_CHANGED: 'viewport width changed',\r\n\tVIEWPORT_HEIGHT_CHANGED: 'viewport height changed',\r\n\tVIEWPORT_SIZE_UNCHANGED: 'viewport size unchanged',\r\n\tITEM_HEIGHT_CHANGED: 'item height changed',\r\n\tITEMS_CHANGED: 'items changed',\r\n\tTOP_OFFSET_CHANGED: 'list top offset changed'\r\n}"],"mappings":";;;;;;;;;;;;AAAA,OAAOA,GAAP,IAAcC,IAAd,QAA0B,oBAA1B;AACA,OAAOC,gCAAP,MAA6C,uCAA7C;;IAEqBC,M;EACpB,sBAgBG;IAAA,IAfFC,MAeE,QAfFA,MAeE;IAAA,IAdFC,6BAcE,QAdFA,6BAcE;IAAA,IAbFC,uCAaE,QAbFA,uCAaE;IAAA,IAZFC,qBAYE,QAZFA,qBAYE;IAAA,IAXFC,kBAWE,QAXFA,kBAWE;IAAA,IAVFC,kBAUE,QAVFA,kBAUE;IAAA,IATFC,8BASE,QATFA,8BASE;IAAA,IARFC,eAQE,QARFA,eAQE;IAAA,IAPFC,2BAOE,QAPFA,2BAOE;IAAA,IANFC,aAME,QANFA,aAME;IAAA,IALFC,yBAKE,QALFA,yBAKE;IAAA,IAJFC,yBAIE,QAJFA,yBAIE;IAAA,IAHFC,oBAGE,QAHFA,oBAGE;IAAA,IAFFC,uBAEE,QAFFA,uBAEE;IAAA,IADFC,6BACE,QADFA,6BACE;;IAAA;;IACF,KAAKd,MAAL,GAAcA,MAAd;IACA,KAAKC,6BAAL,GAAqCA,6BAArC;IACA,KAAKC,uCAAL,GAA+CA,uCAA/C;IACA,KAAKC,qBAAL,GAA6BA,qBAA7B;IACA,KAAKC,kBAAL,GAA0BA,kBAA1B;IACA,KAAKC,kBAAL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G,CAAlB;;QACA,OAAOA,WAAW,GAAG,KAAKrE,eAAL,EAArB,EAA6C;UAC5C,IAAMsE,UAAU,GAAG,KAAKpE,aAAL,CAClB2D,sBAAsB,GAAGyB,QAAQ,GAAG,KAAKtF,eAAL,EAApC,GAA6DqE,WAD3C,CAAnB;;UAGA,IAAIC,UAAU,KAAKrB,SAAnB,EAA8B;YAC7B;UACA;;UACD8B,UAAS,GAAGrD,IAAI,CAAC8C,GAAL,CAASO,UAAT,EAAoBT,UAApB,CAAZ;UACAD,WAAW;QACX;;QAEDY,kCAAkC,IAAIF,UAAtC;QACAE,kCAAkC,IAAI,KAAKnF,kBAAL,EAAtC;QAEAwF,QAAQ;MACR;;MAED,OAAOL,kCAAP;IACA;;;;;;SA/yBmBzF,M;AAkzBrB,OAAO,IAAM+F,aAAa,GAAG;EAC5BC,MAAM,EAAE,QADoB;EAE5BC,iBAAiB,EAAE,mBAFS;EAG5BC,MAAM,EAAE,QAHoB;EAI5BC,OAAO,EAAE,SAJmB;EAK5BC,qCAAqC,EAAE,8CALX;EAM5BC,sBAAsB,EAAE,wBANI;EAO5BC,uBAAuB,EAAE,yBAPG;EAQ5BC,uBAAuB,EAAE,yBARG;EAS5BC,mBAAmB,EAAE,qBATO;EAU5BC,aAAa,EAAE,eAVa;EAW5BC,kBAAkB,EAAE;AAXQ,CAAtB"}
1
+ {"version":3,"file":"Layout.js","names":["log","warn","ScrollableContainerNotReadyError","Layout","bypass","getInitialEstimatedItemHeight","getInitialEstimatedVisibleItemRowsCount","measureItemsBatchSize","getPrerenderMargin","getVerticalSpacing","getVerticalSpacingBeforeResize","getColumnsCount","getColumnsCountBeforeResize","getItemHeight","getItemHeightBeforeResize","getBeforeResizeItemsCount","getAverageItemHeight","getMaxVisibleAreaHeight","getPreviouslyCalculatedLayout","name","getValue","defaultValue","error","itemsCount","columnsCount","beforeStart","firstShownItemIndex","lastShownItemIndex","getLastShownItemIndex","getInitialLastShownItemIndex","getInitialLayoutValueWithFallback","beforeItemsHeight","afterItemsHeight","estimatedRowsCount","getEstimatedRowsCountForHeight","isNaN","Error","Math","min","height","estimatedItemHeight","getEstimatedItemHeight","verticalSpacing","ceil","averageItemHeight","prependedItemsCount","appendedItemsCount","shouldRestoreScrollPosition","onResetGridLayout","appendedRowsCount","addedHeightAfter","prependedRowsCount","addedHeightBefore","shownItemsCountBeforeItemsUpdate","afterItemsCount","i","nonMeasuredAreaHeight","indexOfTheFirstItemInTheRow","itemsCountToRenderForMeasurement","Infinity","undefined","firstNonMeasuredItemIndex","visibleAreaTop","visibleAreaBottom","indexes","_getShownItemIndex","fromIndex","findFirstShownItemIndex","getNonVisibleListShownItemIndexes","findLastShownItemIndex","parameters","beforeResize","beforeResizeItemsCount","notFound","beforeResizeItemsHeight","floor","currentRowFirstItemIndex","hasMoreRows","verticalSpacingAfterCurrentRow","currentRowHeight","columnIndex","itemHeight","getItemNotMeasuredIndexes","max","itemsHeightFromFirstRowToThisRow","rowStepsIntoVisibleAreaTop","rowStepsOutOfVisibleAreaBottomOrIsAtTheBorder","layout","beforeItemsCount","getBeforeItemsHeight","rowHeight","lastShownRowIndex","topOffsetInsideScrollableContainer","beforeResizeRowsCount","maxBeforeResizeRowsCount","beforeResizeRowIndex","itemRowIndex","rowIndex","LAYOUT_REASON","SCROLL","STOPPED_SCROLLING","MANUAL","STARTED","NON_MEASURED_ITEMS_HAVE_BEEN_MEASURED","VIEWPORT_WIDTH_CHANGED","VIEWPORT_HEIGHT_CHANGED","VIEWPORT_SIZE_UNCHANGED","ITEM_HEIGHT_CHANGED","ITEMS_CHANGED","TOP_OFFSET_CHANGED"],"sources":["../source/Layout.js"],"sourcesContent":["import log, { warn } from './utility/debug.js'\r\nimport ScrollableContainerNotReadyError from './ScrollableContainerNotReadyError.js'\r\n\r\nexport default class Layout {\r\n\tconstructor({\r\n\t\tbypass,\r\n\t\tgetInitialEstimatedItemHeight,\r\n\t\tgetInitialEstimatedVisibleItemRowsCount,\r\n\t\tmeasureItemsBatchSize,\r\n\t\tgetPrerenderMargin,\r\n\t\tgetVerticalSpacing,\r\n\t\tgetVerticalSpacingBeforeResize,\r\n\t\tgetColumnsCount,\r\n\t\tgetColumnsCountBeforeResize,\r\n\t\tgetItemHeight,\r\n\t\tgetItemHeightBeforeResize,\r\n\t\tgetBeforeResizeItemsCount,\r\n\t\tgetAverageItemHeight,\r\n\t\tgetMaxVisibleAreaHeight,\r\n\t\tgetPreviouslyCalculatedLayout\r\n\t}) {\r\n\t\tthis.bypass = bypass\r\n\t\tthis.getInitialEstimatedItemHeight = getInitialEstimatedItemHeight\r\n\t\tthis.getInitialEstimatedVisibleItemRowsCount = getInitialEstimatedVisibleItemRowsCount\r\n\t\tthis.measureItemsBatchSize = measureItemsBatchSize\r\n\t\tthis.getPrerenderMargin = getPrerenderMargin\r\n\t\tthis.getVerticalSpacing = getVerticalSpacing\r\n\t\tthis.getVerticalSpacingBeforeResize = getVerticalSpacingBeforeResize\r\n\t\tthis.getColumnsCount = getColumnsCount\r\n\t\tthis.getColumnsCountBeforeResize = getColumnsCountBeforeResize\r\n\t\tthis.getItemHeight = getItemHeight\r\n\t\tthis.getItemHeightBeforeResize = getItemHeightBeforeResize\r\n\t\tthis.getBeforeResizeItemsCount = getBeforeResizeItemsCount\r\n\t\tthis.getAverageItemHeight = getAverageItemHeight\r\n\t\tthis.getMaxVisibleAreaHeight = getMaxVisibleAreaHeight\r\n\t\t//\r\n\t\t// The \"previously calculated layout\" feature is not currently used.\r\n\t\t//\r\n\t\t// The current layout snapshot could be stored as a \"previously calculated layout\" variable\r\n\t\t// so that it could theoretically be used when calculating new layout incrementally\r\n\t\t// rather than from scratch, which would be an optimization.\r\n\t\t//\r\n\t\tthis.getPreviouslyCalculatedLayout = getPreviouslyCalculatedLayout\r\n\t}\r\n\r\n\t// React `<VirtualScroller/>` component attempts to create the initial state\r\n\t// before the component tree has mounted. This could result in an inability to\r\n\t// calculate some initial layout values like `columnsCount` or `lastShownItemIndex`.\r\n\t// Such errors aren't considered critical because layout will be re-calculated\r\n\t// after the component mounts. The workaround is to use some sane default values\r\n\t// until the scrollable container has mounted.\r\n\tgetInitialLayoutValueWithFallback(name, getValue, defaultValue) {\r\n\t\ttry {\r\n\t\t\treturn getValue()\r\n\t\t} catch (error) {\r\n\t\t\tif (error instanceof ScrollableContainerNotReadyError) {\r\n\t\t\t\tlog('Couldn\\'t calculate', name, 'before scrollable container is ready. Default to', defaultValue);\r\n\t\t\t\treturn defaultValue\r\n\t\t\t} else {\r\n\t\t\t\tthrow error\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\r\n\tgetInitialLayoutValues({\r\n\t\titemsCount,\r\n\t\tcolumnsCount,\r\n\t\tbeforeStart\r\n\t}) {\r\n\t\tlet firstShownItemIndex\r\n\t\tlet lastShownItemIndex\r\n\t\t// If there're no items then `firstShownItemIndex` stays `undefined`.\r\n\t\tif (itemsCount > 0) {\r\n\t\t\tconst getLastShownItemIndex = () => {\r\n\t\t\t\treturn this.getInitialLastShownItemIndex({\r\n\t\t\t\t\titemsCount,\r\n\t\t\t\t\tcolumnsCount,\r\n\t\t\t\t\tfirstShownItemIndex\r\n\t\t\t\t})\r\n\t\t\t}\r\n\t\t\tfirstShownItemIndex = 0\r\n\t\t\tlastShownItemIndex = beforeStart\r\n\t\t\t\t? this.getInitialLayoutValueWithFallback(\r\n\t\t\t\t\t'lastShownItemIndex',\r\n\t\t\t\t\tgetLastShownItemIndex,\r\n\t\t\t\t\t0\r\n\t\t\t\t)\r\n\t\t\t\t: getLastShownItemIndex()\r\n\t\t}\r\n\t\treturn {\r\n\t\t\tbeforeItemsHeight: 0,\r\n\t\t\tafterItemsHeight: 0,\r\n\t\t\tfirstShownItemIndex,\r\n\t\t\tlastShownItemIndex\r\n\t\t}\r\n\t}\r\n\r\n\tgetInitialLastShownItemIndex({\r\n\t\titemsCount,\r\n\t\tcolumnsCount,\r\n\t\tfirstShownItemIndex\r\n\t}) {\r\n\t\tif (this.bypass) {\r\n\t\t\treturn itemsCount - 1\r\n\t\t}\r\n\t\t// On server side, at initialization time,\r\n\t\t// `scrollableContainer` is `undefined`,\r\n\t\t// so default to `1` estimated rows count.\r\n\t\tlet estimatedRowsCount = 1\r\n\t\tif (this.getMaxVisibleAreaHeight()) {\r\n\t\t\testimatedRowsCount = this.getEstimatedRowsCountForHeight(this.getMaxVisibleAreaHeight() + this.getPrerenderMargin())\r\n\t\t} else if (this.getInitialEstimatedVisibleItemRowsCount) {\r\n\t\t\testimatedRowsCount = this.getInitialEstimatedVisibleItemRowsCount()\r\n\t\t\tif (isNaN(estimatedRowsCount)) {\r\n\t\t\t\tthrow new Error('[virtual-scroller] `getEstimatedVisibleItemRowsCount()` must return a number')\r\n\t\t\t}\r\n\t\t}\r\n\t\treturn Math.min(\r\n\t\t\tfirstShownItemIndex + (estimatedRowsCount * columnsCount - 1),\r\n\t\t\titemsCount - 1\r\n\t\t)\r\n\t}\r\n\r\n\tgetEstimatedRowsCountForHeight(height) {\r\n\t\tconst estimatedItemHeight = this.getEstimatedItemHeight()\r\n\t\tconst verticalSpacing = this.getVerticalSpacing()\r\n\t\tif (estimatedItemHeight) {\r\n\t\t\treturn Math.ceil((height + verticalSpacing) / (estimatedItemHeight + verticalSpacing))\r\n\t\t} else {\r\n\t\t\t// If no items have been rendered yet, and no `estimatedItemHeight` option\r\n\t\t\t// has been passed, then default to `1` estimated rows count in any `height`.\r\n\t\t\treturn 1\r\n\t\t}\r\n\t}\r\n\r\n\t/**\r\n\t * Returns estimated list item height.\r\n\t * (depends on which items have been previously rendered and measured).\r\n\t * @return {number}\r\n\t */\r\n\tgetEstimatedItemHeight() {\r\n\t\tconst averageItemHeight = this.getAverageItemHeight()\r\n\t\tif (averageItemHeight) {\r\n\t\t\treturn averageItemHeight\r\n\t\t}\r\n\t\tif (this.getInitialEstimatedItemHeight) {\r\n\t\t\tconst estimatedItemHeight = this.getInitialEstimatedItemHeight()\r\n\t\t\tif (isNaN(estimatedItemHeight)) {\r\n\t\t\t\tthrow new Error('[virtual-scroller] `getInitialEstimatedItemHeight()` must return a number')\r\n\t\t\t}\r\n\t\t\treturn estimatedItemHeight\r\n\t\t}\r\n\t\treturn 0\r\n\t}\r\n\r\n\tgetLayoutUpdateForItemsDiff({\r\n\t\tfirstShownItemIndex,\r\n\t\tlastShownItemIndex,\r\n\t\tbeforeItemsHeight,\r\n\t\tafterItemsHeight\r\n\t}, {\r\n\t\tprependedItemsCount,\r\n\t\tappendedItemsCount\r\n\t}, {\r\n\t\titemsCount,\r\n\t\tcolumnsCount,\r\n\t\tshouldRestoreScrollPosition,\r\n\t\tonResetGridLayout\r\n\t}) {\r\n\t\t// const layoutUpdate = {}\r\n\r\n\t\t// If the layout stays the same, then simply increase\r\n\t\t// the top and bottom margins proportionally to the amount\r\n\t\t// of the items added.\r\n\t\tconst averageItemHeight = this.getAverageItemHeight()\r\n\t\tconst verticalSpacing = this.getVerticalSpacing()\r\n\r\n\t\tif (appendedItemsCount > 0) {\r\n\t\t\tconst appendedRowsCount = Math.ceil(appendedItemsCount / columnsCount)\r\n\t\t\tconst addedHeightAfter = appendedRowsCount * (verticalSpacing + averageItemHeight)\r\n\r\n\t\t\tafterItemsHeight += addedHeightAfter\r\n\r\n\t\t\t// layoutUpdate = {\r\n\t\t\t// \t...layoutUpdate,\r\n\t\t\t// \tafterItemsHeight\r\n\t\t\t// }\r\n\t\t}\r\n\r\n\t\tif (prependedItemsCount > 0) {\r\n\t\t\tconst prependedRowsCount = Math.ceil(prependedItemsCount / columnsCount)\r\n\t\t\tconst addedHeightBefore = prependedRowsCount * (averageItemHeight + verticalSpacing)\r\n\r\n\t\t\tfirstShownItemIndex += prependedItemsCount\r\n\t\t\tlastShownItemIndex += prependedItemsCount\r\n\t\t\tbeforeItemsHeight += addedHeightBefore\r\n\r\n\t\t\t// If the currently shown items position on screen should be preserved\r\n\t\t\t// when prepending new items, then it means that:\r\n\t\t\t// * The current scroll position should be snapshotted.\r\n\t\t\t// * The current list height should be snapshotted.\r\n\t\t\t// * All prepended items should be shown so that their height could be\r\n\t\t\t// measured after they're rendered. Based on the prepended items' height,\r\n\t\t\t// the scroll position will be restored so that there's no \"jump of content\".\r\n\t\t\tif (shouldRestoreScrollPosition) {\r\n\t\t\t\tfirstShownItemIndex = 0\r\n\t\t\t\tbeforeItemsHeight = 0\r\n\t\t\t}\r\n\r\n\t\t\tif (prependedItemsCount % columnsCount > 0) {\r\n\t\t\t\t// Rows will be rebalanced as a result of prepending new items,\r\n\t\t\t\t// and row heights can change as a result, so re-layout items\r\n\t\t\t\t// after they've been measured (after the upcoming re-render).\r\n\t\t\t\t//\r\n\t\t\t\t// For example, consider a web page where item rows are `display: flex`.\r\n\t\t\t\t// Suppose there're 3 columns and it shows items from 4 to 6.\r\n\t\t\t\t//\r\n\t\t\t\t// ------------------------------------------\r\n\t\t\t\t// | Apples are | Bananas | Cranberries |\r\n\t\t\t\t// | green | | |\r\n\t\t\t\t// ------------------------------------------\r\n\t\t\t\t// | Dates | Elderberry | Figs are |\r\n\t\t\t\t// | | | tasty |\r\n\t\t\t\t// ------------------------------------------\r\n\t\t\t\t//\r\n\t\t\t\t// Now, 1 item gets prepended. As a result, all existing rows will have\r\n\t\t\t\t// a different set of items, which means that the row heights will change.\r\n\t\t\t\t//\r\n\t\t\t\t// ------------------------------------------\r\n\t\t\t\t// | Zucchini | Apples are | Bananas |\r\n\t\t\t\t// | | green | |\r\n\t\t\t\t// ------------------------------------------\r\n\t\t\t\t// | Cranberries | Dates | Elderberry |\r\n\t\t\t\t// ------------------------------------------\r\n\t\t\t\t// | Figs |\r\n\t\t\t\t// | are tasty |\r\n\t\t\t\t// ---------------\r\n\t\t\t\t//\r\n\t\t\t\t// As it can be seen above, the second row's height has changed from 2 to 1.\r\n\t\t\t\t// Not only that, but `itemHeights` have changed as well, so if you thought\r\n\t\t\t\t// that the library could easily recalculate row heights using `Math.max()` — \r\n\t\t\t\t// turns out it's not always the case.\r\n\t\t\t\t//\r\n\t\t\t\t// There could be an explicit opt-in option for automatically recalculating\r\n\t\t\t\t// row heights, but I don't want to write code for such an extremely rare\r\n\t\t\t\t// use case. Instead, use the `getColumnsCount()` parameter function when\r\n\t\t\t\t// fetching previous items.\r\n\r\n\t\t\t\tonResetGridLayout()\r\n\r\n\t\t\t\twarn('~ Prepended items count', prependedItemsCount, 'is not divisible by Columns Count', columnsCount, '~')\r\n\t\t\t\twarn('Layout reset required')\r\n\r\n\t\t\t\tconst shownItemsCountBeforeItemsUpdate = lastShownItemIndex - firstShownItemIndex + 1\r\n\r\n\t\t\t\tfirstShownItemIndex = 0\r\n\t\t\t\tbeforeItemsHeight = 0\r\n\r\n\t\t\t\tif (!shouldRestoreScrollPosition) {\r\n\t\t\t\t\t// Limit shown items count if too many items have been prepended.\r\n\t\t\t\t\tif (prependedItemsCount > shownItemsCountBeforeItemsUpdate) {\r\n\t\t\t\t\t\tlastShownItemIndex = this.getInitialLastShownItemIndex({\r\n\t\t\t\t\t\t\titemsCount,\r\n\t\t\t\t\t\t\tcolumnsCount,\r\n\t\t\t\t\t\t\tfirstShownItemIndex\r\n\t\t\t\t\t\t})\r\n\r\n\t\t\t\t\t\t// Approximate `afterItemsHeight` calculation.\r\n\t\t\t\t\t\tconst afterItemsCount = itemsCount - (lastShownItemIndex + 1)\r\n\t\t\t\t\t\tafterItemsHeight = Math.ceil(afterItemsCount / columnsCount) * (verticalSpacing + averageItemHeight)\r\n\r\n\t\t\t\t\t\t// layoutUpdate = {\r\n\t\t\t\t\t\t// \t...layoutUpdate,\r\n\t\t\t\t\t\t// \tafterItemsHeight\r\n\t\t\t\t\t\t// }\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t}\r\n\r\n\t\t\t// layoutUpdate = {\r\n\t\t\t// \t...layoutUpdate,\r\n\t\t\t// \tbeforeItemsHeight,\r\n\t\t\t// \tfirstShownItemIndex,\r\n\t\t\t// \tlastShownItemIndex\r\n\t\t\t// }\r\n\t\t}\r\n\r\n\t\t// return layoutUpdate\r\n\r\n\t\t// Overwrite all four props in all scenarios.\r\n\t\t// The reason is that only this way subsequent `setItems()` calls\r\n\t\t// will be truly \"stateless\" when a chain of `setItems()` calls\r\n\t\t// could be replaced with just the last one in a scenario when\r\n\t\t// `updateState()` calls are \"asynchronous\" (delayed execution).\r\n\t\t//\r\n\t\t// So, for example, the user calls `setItems()` with one set of items.\r\n\t\t// A `updateState()` call has been dispatched but the `state` hasn't been updated yet.\r\n\t\t// Then the user calls `setItems()` with another set of items.\r\n\t\t// If this function only returned a minimal set of properties that actually change,\r\n\t\t// the other layout properties of the second `setItems()` call wouldn't overwrite the ones\r\n\t\t// scheduled for update during the first `setItems()` call, resulting in an inconsistent `state`.\r\n\t\t//\r\n\t\t// For example, the first `setItems()` call does a `updateState()` call where it updates\r\n\t\t// `afterItemsHeight`, and then the second `setItems()` call only updates `beforeItemsHeight`\r\n\t\t// and `firstShownItemIndex` and `lastShownItemIndex`. If the second `setItems()` call was to\r\n\t\t// overwrite any effects of the pending-but-not-yet-applied first `setItems()` call, it would\r\n\t\t// have to call `updateState()` with an `afterItemsHeight` property too, even though it hasn't change.\r\n\t\t// That would be just to revert the change to `afterItemsHeight` state property already scheduled\r\n\t\t// by the first `setItems()` call.\r\n\t\t//\r\n\t\treturn {\r\n\t\t\tbeforeItemsHeight,\r\n\t\t\tafterItemsHeight,\r\n\t\t\tfirstShownItemIndex,\r\n\t\t\tlastShownItemIndex\r\n\t\t}\r\n\t}\r\n\r\n\t// If an item that hasn't been shown (and measured) yet is encountered\r\n\t// then show such item and then retry after it has been measured.\r\n\tgetItemNotMeasuredIndexes(i, {\r\n\t\titemsCount,\r\n\t\tfirstShownItemIndex,\r\n\t\tnonMeasuredAreaHeight,\r\n\t\tindexOfTheFirstItemInTheRow\r\n\t}) {\r\n\t\tlog('Item index', i, 'height is required for calculations but hasn\\'t been measured yet. Mark the item as \"shown\", rerender the list, measure the item\\'s height and redo the layout.')\r\n\r\n\t\tconst columnsCount = this.getColumnsCount()\r\n\r\n\t\tconst itemsCountToRenderForMeasurement = Math.min(\r\n\t\t\tthis.getEstimatedRowsCountForHeight(nonMeasuredAreaHeight) * columnsCount,\r\n\t\t\tthis.measureItemsBatchSize || Infinity,\r\n\t\t)\r\n\r\n\t\tif (firstShownItemIndex === undefined) {\r\n\t\t\tfirstShownItemIndex = indexOfTheFirstItemInTheRow\r\n\t\t}\r\n\r\n\t\tconst lastShownItemIndex = Math.min(\r\n\t\t\tindexOfTheFirstItemInTheRow + itemsCountToRenderForMeasurement - 1,\r\n\t\t\t// Guard against index overflow.\r\n\t\t\titemsCount - 1\r\n\t\t)\r\n\r\n\t\treturn {\r\n\t\t\tfirstNonMeasuredItemIndex: i,\r\n\t\t\tfirstShownItemIndex,\r\n\t\t\tlastShownItemIndex\r\n\t\t}\r\n\t}\r\n\r\n\t/**\r\n\t * Finds the indexes of the currently visible items.\r\n\t * @return {object} `{ firstShownItemIndex: number, lastShownItemIndex: number, firstNonMeasuredItemIndex: number? }`\r\n\t */\r\n\tgetShownItemIndexes({\r\n\t\titemsCount,\r\n\t\tvisibleAreaTop,\r\n\t\tvisibleAreaBottom\r\n\t}) {\r\n\t\tlet indexes = this._getShownItemIndex({\r\n\t\t\titemsCount,\r\n\t\t\tfromIndex: 0,\r\n\t\t\tvisibleAreaTop,\r\n\t\t\tvisibleAreaBottom,\r\n\t\t\tfindFirstShownItemIndex: true\r\n\t\t})\r\n\r\n\t\tif (indexes === null) {\r\n\t\t\treturn this.getNonVisibleListShownItemIndexes()\r\n\t\t}\r\n\r\n\t\tif (indexes.firstNonMeasuredItemIndex !== undefined) {\r\n\t\t\treturn indexes\r\n\t\t}\r\n\r\n\t\tconst { firstShownItemIndex, beforeItemsHeight } = indexes\r\n\r\n\t\tindexes = this._getShownItemIndex({\r\n\t\t\titemsCount,\r\n\t\t\tfromIndex: firstShownItemIndex,\r\n\t\t\tbeforeItemsHeight,\r\n\t\t\tvisibleAreaTop,\r\n\t\t\tvisibleAreaBottom,\r\n\t\t\tfindLastShownItemIndex: true\r\n\t\t})\r\n\r\n\t\tif (indexes === null) {\r\n\t\t\treturn this.getNonVisibleListShownItemIndexes()\r\n\t\t}\r\n\r\n\t\tif (indexes.firstNonMeasuredItemIndex !== undefined) {\r\n\t\t\treturn indexes\r\n\t\t}\r\n\r\n\t\tconst { lastShownItemIndex } = indexes\r\n\r\n\t\treturn {\r\n\t\t\tfirstShownItemIndex,\r\n\t\t\tlastShownItemIndex\r\n\t\t}\r\n\t}\r\n\r\n\t_getShownItemIndex(parameters) {\r\n\t\tconst {\r\n\t\t\tbeforeResize,\r\n\t\t\titemsCount,\r\n\t\t\tvisibleAreaTop,\r\n\t\t\tvisibleAreaBottom,\r\n\t\t\tfindFirstShownItemIndex,\r\n\t\t\tfindLastShownItemIndex,\r\n\t\t\t// backwards\r\n\t\t} = parameters\r\n\r\n\t\tlet {\r\n\t\t\tfromIndex,\r\n\t\t\tbeforeItemsHeight\r\n\t\t} = parameters\r\n\r\n\t\t// This function could potentially also use `this.getPreviouslyCalculatedLayout()`\r\n\t\t// in order to skip calculating visible item indexes from scratch\r\n\t\t// and instead just calculate the difference from a \"previously calculated layout\".\r\n\t\t//\r\n\t\t// I did a simple test in a web browser and found out that running the following\r\n\t\t// piece of code is less than 10 milliseconds:\r\n\t\t//\r\n\t\t// var startedAt = Date.now()\r\n\t\t// var i = 0\r\n\t\t// while (i < 1000000) {\r\n\t\t// i++\r\n\t\t// }\r\n\t\t// console.log(Date.now() - startedAt)\r\n\t\t//\r\n\t\t// Which becomes negligible in my project's use case (a couple thousands items max).\r\n\t\t//\r\n\t\t// If someone would attempt to use a \"previously calculated layout\" here\r\n\t\t// then `shownItemsHeight` would also have to be returned from this function:\r\n\t\t// the total height of all shown items including vertical spacing between them.\r\n\t\t//\r\n\t\t// If \"previously calculated layout\" would be used then it would first find\r\n\t\t// `firstShownItemIndex` and then find `lastShownItemIndex` as part of two\r\n\t\t// separate calls of this function, each with or without `backwards` flag,\r\n\t\t// depending on whether `visibleAreaTop` and `visibleAreBottom` have shifted up or down.\r\n\r\n\t\tlet firstShownItemIndex\r\n\t\tlet lastShownItemIndex\r\n\r\n\t\t// It's not always required to pass `beforeItemsHeight` parameter:\r\n\t\t// when `fromIndex` is `0`, it's also assumed to be `0`.\r\n\t\tif (fromIndex === 0) {\r\n\t\t\tbeforeItemsHeight = 0\r\n\t\t}\r\n\r\n\t\tif (beforeItemsHeight === undefined) {\r\n\t\t\tthrow new Error('[virtual-scroller] `beforeItemsHeight` not passed to `Layout.getShownItemIndexes()` when starting from index ' + fromIndex);\r\n\t\t}\r\n\r\n\t\t// const backwards = false\r\n\t\t// while (backwards ? i >= 0 : i < itemsCount) {}\r\n\r\n\t\tif (!beforeResize) {\r\n\t\t\tconst beforeResizeItemsCount = this.getBeforeResizeItemsCount()\r\n\t\t\tif (beforeResizeItemsCount > fromIndex) {\r\n\t\t\t\t// First search for the item in \"before resize\" items.\r\n\t\t\t\tconst {\r\n\t\t\t\t\tnotFound,\r\n\t\t\t\t\tbeforeItemsHeight: beforeResizeItemsHeight,\r\n\t\t\t\t\tfirstShownItemIndex,\r\n\t\t\t\t\tlastShownItemIndex\r\n\t\t\t\t} = this._getShownItemIndex({\r\n\t\t\t\t\t...parameters,\r\n\t\t\t\t\tbeforeResize: true,\r\n\t\t\t\t\titemsCount: beforeResizeItemsCount\r\n\t\t\t\t})\r\n\r\n\t\t\t\t// If the item was not found in \"before resize\" items\r\n\t\t\t\t// then search in regular items skipping \"before resize\" ones.\r\n\t\t\t\tif (notFound) {\r\n\t\t\t\t\tbeforeItemsHeight = beforeResizeItemsHeight\r\n\t\t\t\t\tfromIndex += beforeResizeItemsCount\r\n\t\t\t\t} else {\r\n\t\t\t\t\t// If the item was found in \"before resize\" items\r\n\t\t\t\t\t// then return the result.\r\n\t\t\t\t\t// Rebalance first / last shown item indexes based on\r\n\t\t\t\t\t// the current columns count, if required.\r\n\t\t\t\t\tconst columnsCount = this.getColumnsCount()\r\n\t\t\t\t\treturn {\r\n\t\t\t\t\t\tfirstShownItemIndex: firstShownItemIndex === undefined\r\n\t\t\t\t\t\t\t? undefined\r\n\t\t\t\t\t\t\t: Math.floor(firstShownItemIndex / columnsCount) * columnsCount,\r\n\t\t\t\t\t\tlastShownItemIndex: lastShownItemIndex === undefined\r\n\t\t\t\t\t\t\t? undefined\r\n\t\t\t\t\t\t\t: Math.floor(lastShownItemIndex / columnsCount) * columnsCount,\r\n\t\t\t\t\t\tbeforeItemsHeight: beforeResizeItemsHeight\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\tconst columnsCount = beforeResize ? this.getColumnsCountBeforeResize() : this.getColumnsCount()\r\n\t\tconst verticalSpacing = beforeResize ? this.getVerticalSpacingBeforeResize() : this.getVerticalSpacing()\r\n\r\n\t\tlet i = fromIndex\r\n\t\twhile (i < itemsCount) {\r\n\t\t\tconst currentRowFirstItemIndex = i\r\n\r\n\t\t\tconst hasMoreRows = itemsCount > currentRowFirstItemIndex + columnsCount\r\n\t\t\tconst verticalSpacingAfterCurrentRow = hasMoreRows ? verticalSpacing : 0\r\n\r\n\t\t\tlet currentRowHeight = 0\r\n\r\n\t\t\t// Calculate current row height.\r\n\t\t\tlet columnIndex = 0\r\n\t\t\twhile (columnIndex < columnsCount && i < itemsCount) {\r\n\t\t\t\tconst itemHeight = beforeResize ? this.getItemHeightBeforeResize(i) : this.getItemHeight(i)\r\n\r\n\t\t\t\t// If this item hasn't been measured yet (or re-measured after a resize)\r\n\t\t\t\t// then mark it as the first non-measured one.\r\n\t\t\t\t//\r\n\t\t\t\t// Can't happen by definition when `beforeResize` parameter is `true`.\r\n\t\t\t\t//\r\n\t\t\t\tif (itemHeight === undefined) {\r\n\t\t\t\t\treturn this.getItemNotMeasuredIndexes(i, {\r\n\t\t\t\t\t\titemsCount,\r\n\t\t\t\t\t\tfirstShownItemIndex: findLastShownItemIndex ? fromIndex : undefined,\r\n\t\t\t\t\t\tindexOfTheFirstItemInTheRow: currentRowFirstItemIndex,\r\n\t\t\t\t\t\tnonMeasuredAreaHeight: (visibleAreaBottom + this.getPrerenderMargin()) - beforeItemsHeight\r\n\t\t\t\t\t})\r\n\t\t\t\t}\r\n\r\n\t\t\t\tcurrentRowHeight = Math.max(currentRowHeight, itemHeight)\r\n\r\n\t\t\t\tcolumnIndex++\r\n\t\t\t\ti++\r\n\t\t\t}\r\n\r\n\t\t\tconst itemsHeightFromFirstRowToThisRow = beforeItemsHeight + currentRowHeight\r\n\r\n\t\t\tconst rowStepsIntoVisibleAreaTop = itemsHeightFromFirstRowToThisRow > visibleAreaTop - this.getPrerenderMargin()\r\n\t\t\tconst rowStepsOutOfVisibleAreaBottomOrIsAtTheBorder = itemsHeightFromFirstRowToThisRow + verticalSpacingAfterCurrentRow >= visibleAreaBottom + this.getPrerenderMargin()\r\n\r\n\t\t\t// if (backwards) {\r\n\t\t\t// \tif (findFirstShownItemIndex) {\r\n\t\t\t// \t\tif (rowStepsOutOfVisibleAreaTop) {\r\n\t\t\t// \t\t\treturn {\r\n\t\t\t// \t\t\t\tfirstShownItemIndex: currentRowFirstItemIndex + columnsCount\r\n\t\t\t// \t\t\t}\r\n\t\t\t// \t\t}\r\n\t\t\t// \t} else if (findLastShownItemIndex) {\r\n\t\t\t// \t\tif (rowStepsIntoVisibleAreaBottom) {\r\n\t\t\t// \t\t\treturn {\r\n\t\t\t// \t\t\t\tlastShownItemIndex: currentRowFirstItemIndex + columnsCount - 1\r\n\t\t\t// \t\t\t}\r\n\t\t\t// \t\t}\r\n\t\t\t// \t}\r\n\t\t\t// }\r\n\r\n\t\t\tif (findFirstShownItemIndex) {\r\n\t\t\t\tif (rowStepsIntoVisibleAreaTop) {\r\n\t\t\t\t\t// If item is the first one visible in the viewport\r\n\t\t\t\t\t// then start showing items from this row.\r\n\t\t\t\t\treturn {\r\n\t\t\t\t\t\tfirstShownItemIndex: currentRowFirstItemIndex,\r\n\t\t\t\t\t\tbeforeItemsHeight\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t} else if (findLastShownItemIndex) {\r\n\t\t\t\tif (rowStepsOutOfVisibleAreaBottomOrIsAtTheBorder) {\r\n\t\t\t\t\treturn {\r\n\t\t\t\t\t\tlastShownItemIndex: Math.min(\r\n\t\t\t\t\t\t\t// The index of the last item in the current row.\r\n\t\t\t\t\t\t\tcurrentRowFirstItemIndex + columnsCount - 1,\r\n\t\t\t\t\t\t\t// Guards against index overflow.\r\n\t\t\t\t\t\t\titemsCount - 1\r\n\t\t\t\t\t\t)\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t}\r\n\r\n\t\t\tbeforeItemsHeight += currentRowHeight + verticalSpacingAfterCurrentRow\r\n\r\n\t\t\t// if (backwards) {\r\n\t\t\t// \t// Set `i` to be the first item of the current row.\r\n\t\t\t// \ti -= columnsCount\r\n\t\t\t// \tconst prevoiusRowIsBeforeResize = i - 1 < this.getBeforeResizeItemsCount()\r\n\t\t\t// \tconst previousRowColumnsCount = prevoiusRowIsBeforeResize ? this.getColumnsCountBeforeResize() : this.getColumnsCount()\r\n\t\t\t// \t// Set `i` to be the first item of the previous row.\r\n\t\t\t// \ti -= previousRowColumnsCount\r\n\t\t\t// }\r\n\t\t}\r\n\r\n\t\t// if (backwards) {\r\n\t\t// \tif (findFirstShownItemIndex) {\r\n\t\t// \t\twarn('The list is supposed to be visible but no visible item has been found (while traversing backwards)')\r\n\t\t// \t\treturn null\r\n\t\t// \t} else if (findLastShownItemIndex) {\r\n\t\t// \t\treturn {\r\n\t\t// \t\t\tfirstShownItemIndex: 0\r\n\t\t// \t\t}\r\n\t\t// \t}\r\n\t\t// }\r\n\r\n\t\tif (beforeResize) {\r\n\t\t\treturn {\r\n\t\t\t\tnotFound: true,\r\n\t\t\t\tbeforeItemsHeight\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\t// This case isn't supposed to happen but it could hypothetically happen\r\n\t\t// because the list height is measured from the user's screen and\r\n\t\t// not necessarily can be trusted.\r\n\t\tif (findFirstShownItemIndex) {\r\n\t\t\twarn('The list is supposed to be visible but no visible item has been found')\r\n\t\t\treturn null\r\n\t\t} else if (findLastShownItemIndex) {\r\n\t\t\treturn {\r\n\t\t\t\tlastShownItemIndex: itemsCount - 1\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\r\n\tgetNonVisibleListShownItemIndexes() {\r\n\t\tconst layout = {\r\n\t\t\tfirstShownItemIndex: 0,\r\n\t\t\tlastShownItemIndex: 0\r\n\t\t}\r\n\t\tif (this.getItemHeight(0) === undefined) {\r\n\t\t\tlayout.firstNonMeasuredItemIndex = 0\r\n\t\t}\r\n\t\treturn layout\r\n\t}\r\n\r\n\t/**\r\n\t * Measures \"before\" items height.\r\n\t * @param {number} beforeItemsCount — Basically, first shown item index.\r\n\t * @return {number}\r\n\t */\r\n\tgetBeforeItemsHeight(\r\n\t\tbeforeItemsCount,\r\n\t\t{ beforeResize } = {}\r\n\t) {\r\n\t\t// This function could potentially also use `this.getPreviouslyCalculatedLayout()`\r\n\t\t// in order to skip calculating visible item indexes from scratch\r\n\t\t// and instead just calculate the difference from a \"previously calculated layout\".\r\n\t\t//\r\n\t\t// I did a simple test in a web browser and found out that running the following\r\n\t\t// piece of code is less than 10 milliseconds:\r\n\t\t//\r\n\t\t// var startedAt = Date.now()\r\n\t\t// var i = 0\r\n\t\t// while (i < 1000000) {\r\n\t\t// i++\r\n\t\t// }\r\n\t\t// console.log(Date.now() - startedAt)\r\n\t\t//\r\n\t\t// Which becomes negligible in my project's use case (a couple thousands items max).\r\n\r\n\t\tlet beforeItemsHeight = 0\r\n\t\tlet i = 0\r\n\r\n\t\tif (!beforeResize) {\r\n\t\t\tconst beforeResizeItemsCount = this.getBeforeResizeItemsCount()\r\n\r\n\t\t\tif (beforeResizeItemsCount > 0) {\r\n\t\t\t\t// First add all \"before resize\" item heights.\r\n\t\t\t\tbeforeItemsHeight = this.getBeforeItemsHeight(\r\n\t\t\t\t\t// `firstShownItemIndex` (called `beforeItemsCount`) could be greater than\r\n\t\t\t\t\t// `beforeResizeItemsCount` when the user scrolls down.\r\n\t\t\t\t\t// `firstShownItemIndex` (called `beforeItemsCount`) could be less than\r\n\t\t\t\t\t// `beforeResizeItemsCount` when the user scrolls up.\r\n\t\t\t\t\tMath.min(beforeItemsCount, beforeResizeItemsCount),\r\n\t\t\t\t\t{ beforeResize: true }\r\n\t\t\t\t)\r\n\t\t\t\ti = beforeResizeItemsCount\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tconst columnsCount = beforeResize ? this.getColumnsCountBeforeResize() : this.getColumnsCount()\r\n\t\tconst verticalSpacing = beforeResize ? this.getVerticalSpacingBeforeResize() : this.getVerticalSpacing()\r\n\r\n\t\twhile (i < beforeItemsCount) {\r\n\t\t\tconst currentRowFirstItemIndex = i\r\n\r\n\t\t\tlet rowHeight = 0\r\n\t\t\tlet columnIndex = 0\r\n\t\t\t// Not checking for `itemsCount` overflow here because `i = beforeItemsCount`\r\n\t\t\t// can only start at the start of a row, meaning that when calculating\r\n\t\t\t// \"before items height\" it's not supposed to add item heights from the\r\n\t\t\t// last row of items because in that case it would have to iterate from\r\n\t\t\t// `i === beforeItemsCount` and that condition is already checked above.\r\n\t\t\t// while (i < itemsCount) {\r\n\t\t\twhile (columnIndex < columnsCount) {\r\n\t\t\t\tlet itemHeight = beforeResize ? this.getItemHeightBeforeResize(i) : this.getItemHeight(i)\r\n\t\t\t\tif (itemHeight === undefined) {\r\n\t\t\t\t\t// `itemHeight` can only be `undefined` when not `beforeResize`.\r\n\t\t\t\t\t// Use the current \"average item height\" as a substitute.\r\n\t\t\t\t\titemHeight = this.getAverageItemHeight()\r\n\t\t\t\t}\r\n\t\t\t\trowHeight = Math.max(rowHeight, itemHeight)\r\n\t\t\t\ti++\r\n\t\t\t\tcolumnIndex++\r\n\t\t\t}\r\n\r\n\t\t\tbeforeItemsHeight += rowHeight\r\n\t\t\tbeforeItemsHeight += verticalSpacing\r\n\t\t}\r\n\r\n\t\treturn beforeItemsHeight\r\n\t}\r\n\r\n\t/**\r\n\t * Measures \"after\" items height.\r\n\t * @param {number} lastShownItemIndex — Last shown item index.\r\n\t * @param {number} itemsCount — Items count.\r\n\t * @return {number}\r\n\t */\r\n\tgetAfterItemsHeight(\r\n\t\tlastShownItemIndex,\r\n\t\titemsCount\r\n\t) {\r\n\t\t// This function could potentially also use `this.getPreviouslyCalculatedLayout()`\r\n\t\t// in order to skip calculating visible item indexes from scratch\r\n\t\t// and instead just calculate the difference from a \"previously calculated layout\".\r\n\t\t//\r\n\t\t// I did a simple test in a web browser and found out that running the following\r\n\t\t// piece of code is less than 10 milliseconds:\r\n\t\t//\r\n\t\t// var startedAt = Date.now()\r\n\t\t// var i = 0\r\n\t\t// while (i < 1000000) {\r\n\t\t// i++\r\n\t\t// }\r\n\t\t// console.log(Date.now() - startedAt)\r\n\t\t//\r\n\t\t// Which becomes negligible in my project's use case (a couple thousands items max).\r\n\r\n\t\tconst columnsCount = this.getColumnsCount()\r\n\t\tconst lastShownRowIndex = Math.floor(lastShownItemIndex / columnsCount)\r\n\r\n\t\tlet afterItemsHeight = 0\r\n\r\n\t\tlet i = lastShownItemIndex + 1\r\n\t\twhile (i < itemsCount) {\r\n\t\t\tlet rowHeight = 0\r\n\t\t\tlet columnIndex = 0\r\n\t\t\twhile (columnIndex < columnsCount && i < itemsCount) {\r\n\t\t\t\tlet itemHeight = this.getItemHeight(i)\r\n\t\t\t\tif (itemHeight === undefined) {\r\n\t\t\t\t\titemHeight = this.getAverageItemHeight()\r\n\t\t\t\t}\r\n\t\t\t\trowHeight = Math.max(rowHeight, itemHeight)\r\n\t\t\t\ti++\r\n\t\t\t\tcolumnIndex++\r\n\t\t\t}\r\n\r\n\t\t\t// Add all \"after\" items height.\r\n\t\t\tafterItemsHeight += this.getVerticalSpacing()\r\n\t\t\tafterItemsHeight += rowHeight\r\n\t\t}\r\n\r\n\t\treturn afterItemsHeight\r\n\t}\r\n\r\n\t/**\r\n\t * Returns the items's top offset relative to the top edge of the first item.\r\n\t * @param {number} i — Item index\r\n\t * @return {[number]} Returns `undefined` if any of the previous items haven't been rendered yet.\r\n\t */\r\n\tgetItemTopOffset(i) {\r\n\t\tlet topOffsetInsideScrollableContainer = 0\r\n\r\n\t\tconst beforeResizeItemsCount = this.getBeforeResizeItemsCount()\r\n\t\tconst beforeResizeRowsCount = beforeResizeItemsCount === 0\r\n\t\t\t? 0\r\n\t\t\t: Math.ceil(beforeResizeItemsCount / this.getColumnsCountBeforeResize())\r\n\r\n\t\tconst maxBeforeResizeRowsCount = i < beforeResizeItemsCount\r\n\t\t\t? Math.floor(i / this.getColumnsCountBeforeResize())\r\n\t\t\t: beforeResizeRowsCount\r\n\r\n\t\tlet beforeResizeRowIndex = 0\r\n\t\twhile (beforeResizeRowIndex < maxBeforeResizeRowsCount) {\r\n\t\t\tconst rowHeight = this.getItemHeightBeforeResize(\r\n\t\t\t\tbeforeResizeRowIndex * this.getColumnsCountBeforeResize()\r\n\t\t\t)\r\n\r\n\t\t\ttopOffsetInsideScrollableContainer += rowHeight\r\n\t\t\ttopOffsetInsideScrollableContainer += this.getVerticalSpacingBeforeResize()\r\n\r\n\t\t\tbeforeResizeRowIndex++\r\n\t\t}\r\n\r\n\t\tconst itemRowIndex = Math.floor((i - beforeResizeItemsCount) / this.getColumnsCount())\r\n\r\n\t\tlet rowIndex = 0\r\n\t\twhile (rowIndex < itemRowIndex) {\r\n\t\t\tlet rowHeight = 0\r\n\t\t\tlet columnIndex = 0\r\n\t\t\twhile (columnIndex < this.getColumnsCount()) {\r\n\t\t\t\tconst itemHeight = this.getItemHeight(\r\n\t\t\t\t\tbeforeResizeItemsCount + rowIndex * this.getColumnsCount() + columnIndex\r\n\t\t\t\t)\r\n\t\t\t\tif (itemHeight === undefined) {\r\n\t\t\t\t\treturn\r\n\t\t\t\t}\r\n\t\t\t\trowHeight = Math.max(rowHeight, itemHeight)\r\n\t\t\t\tcolumnIndex++\r\n\t\t\t}\r\n\r\n\t\t\ttopOffsetInsideScrollableContainer += rowHeight\r\n\t\t\ttopOffsetInsideScrollableContainer += this.getVerticalSpacing()\r\n\r\n\t\t\trowIndex++\r\n\t\t}\r\n\r\n\t\treturn topOffsetInsideScrollableContainer\r\n\t}\r\n}\r\n\r\nexport const LAYOUT_REASON = {\r\n\tSCROLL: 'scroll',\r\n\tSTOPPED_SCROLLING: 'stopped scrolling',\r\n\tMANUAL: 'manual',\r\n\tSTARTED: 'started',\r\n\tNON_MEASURED_ITEMS_HAVE_BEEN_MEASURED: 'non-measured item heights have been measured',\r\n\tVIEWPORT_WIDTH_CHANGED: 'viewport width changed',\r\n\tVIEWPORT_HEIGHT_CHANGED: 'viewport height changed',\r\n\tVIEWPORT_SIZE_UNCHANGED: 'viewport size unchanged',\r\n\tITEM_HEIGHT_CHANGED: 'item height changed',\r\n\tITEMS_CHANGED: 'items changed',\r\n\tTOP_OFFSET_CHANGED: 'list top offset changed'\r\n}"],"mappings":";;;;;;;;;;;;AAAA,OAAOA,GAAP,IAAcC,IAAd,QAA0B,oBAA1B;AACA,OAAOC,gCAAP,MAA6C,uCAA7C;;IAEqBC,M;EACpB,sBAgBG;IAAA,IAfFC,MAeE,QAfFA,MAeE;IAAA,IAdFC,6BAcE,QAdFA,6BAcE;IAAA,IAbFC,uCAaE,QAbFA,uCAaE;IAAA,IAZFC,qBAYE,QAZFA,qBAYE;IAAA,IAXFC,kBAWE,QAXFA,kBAWE;IAAA,IAVFC,kBAUE,QAVFA,kBAUE;IAAA,IATFC,8BASE,QATFA,8BASE;IAAA,IARFC,eAQE,QARFA,eAQE;IAAA,IAPFC,2BAOE,QAPFA,2BAOE;IAAA,IANFC,aAME,QANFA,aAME;IAAA,IALFC,yBAKE,QALFA,yBAKE;IAAA,IAJFC,yBAIE,QAJFA,yBAIE;IAAA,IAHFC,oBAGE,QAHFA,oBAGE;IAAA,IAFFC,uBAEE,QAFFA,uBAEE;IAAA,IADFC,6BACE,QADFA,6BACE;;IAAA;;IACF,KAAKd,MAAL,GAAcA,MAAd;IACA,K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K7D,eAAL,EAA1C,CAArB;MAEA,IAAIsF,QAAQ,GAAG,CAAf;;MACA,OAAOA,QAAQ,GAAGD,YAAlB,EAAgC;QAC/B,IAAIN,UAAS,GAAG,CAAhB;QACA,IAAIV,WAAW,GAAG,CAAlB;;QACA,OAAOA,WAAW,GAAG,KAAKrE,eAAL,EAArB,EAA6C;UAC5C,IAAMsE,UAAU,GAAG,KAAKpE,aAAL,CAClB2D,sBAAsB,GAAGyB,QAAQ,GAAG,KAAKtF,eAAL,EAApC,GAA6DqE,WAD3C,CAAnB;;UAGA,IAAIC,UAAU,KAAKrB,SAAnB,EAA8B;YAC7B;UACA;;UACD8B,UAAS,GAAGrD,IAAI,CAAC8C,GAAL,CAASO,UAAT,EAAoBT,UAApB,CAAZ;UACAD,WAAW;QACX;;QAEDY,kCAAkC,IAAIF,UAAtC;QACAE,kCAAkC,IAAI,KAAKnF,kBAAL,EAAtC;QAEAwF,QAAQ;MACR;;MAED,OAAOL,kCAAP;IACA;;;;;;SA/yBmBzF,M;AAkzBrB,OAAO,IAAM+F,aAAa,GAAG;EAC5BC,MAAM,EAAE,QADoB;EAE5BC,iBAAiB,EAAE,mBAFS;EAG5BC,MAAM,EAAE,QAHoB;EAI5BC,OAAO,EAAE,SAJmB;EAK5BC,qCAAqC,EAAE,8CALX;EAM5BC,sBAAsB,EAAE,wBANI;EAO5BC,uBAAuB,EAAE,yBAPG;EAQ5BC,uBAAuB,EAAE,yBARG;EAS5BC,mBAAmB,EAAE,qBATO;EAU5BC,aAAa,EAAE,eAVa;EAW5BC,kBAAkB,EAAE;AAXQ,CAAtB"}
@@ -27,6 +27,8 @@ export default function VirtualScrollerConstructor(getItemsContainerElement, ite
27
27
  var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
28
28
  var render = options.render,
29
29
  state = options.state,
30
+ _options$getInitialIt = options.getInitialItemState,
31
+ getInitialItemState = _options$getInitialIt === void 0 ? function () {} : _options$getInitialIt,
30
32
  onStateChange = options.onStateChange,
31
33
  initialScrollPosition = options.initialScrollPosition,
32
34
  onScrollPositionChange = options.onScrollPositionChange,
@@ -179,6 +181,7 @@ export default function VirtualScrollerConstructor(getItemsContainerElement, ite
179
181
 
180
182
  createStateHelpers.call(this, {
181
183
  state: state,
184
+ getInitialItemState: getInitialItemState,
182
185
  onStateChange: onStateChange,
183
186
  render: render,
184
187
  items: items
@@ -273,11 +276,10 @@ function createHelpers(_ref) {
273
276
  getAverageItemHeight: function getAverageItemHeight() {
274
277
  return _this2.itemHeights.getAverage();
275
278
  },
279
+ // `this.scrollableContainer` is gonna be `undefined` during server-side rendering.
280
+ // https://gitlab.com/catamphetamine/virtual-scroller/-/issues/30
276
281
  getMaxVisibleAreaHeight: function getMaxVisibleAreaHeight() {
277
- return _this2.scrollableContainer.getHeight();
278
- },
279
- isScrollableContainerReady: function isScrollableContainerReady() {
280
- return _this2.scrollableContainer.isReady();
282
+ return _this2.scrollableContainer && _this2.scrollableContainer.getHeight();
281
283
  },
282
284
  //
283
285
  // The "previously calculated layout" feature is not currently used.