virtual-scroller 1.10.2 → 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.
- package/CHANGELOG.md +16 -0
- package/README.md +48 -24
- package/bundle/virtual-scroller-dom.js +1 -1
- package/bundle/virtual-scroller-dom.js.map +1 -1
- package/bundle/virtual-scroller-react.js +1 -1
- package/bundle/virtual-scroller-react.js.map +1 -1
- package/bundle/virtual-scroller.js +1 -1
- package/bundle/virtual-scroller.js.map +1 -1
- package/commonjs/DOM/VirtualScroller.js +5 -0
- package/commonjs/DOM/VirtualScroller.js.map +1 -1
- package/commonjs/ItemHeights.js +1 -1
- package/commonjs/ItemHeights.js.map +1 -1
- package/commonjs/VirtualScroller.constructor.js +3 -0
- package/commonjs/VirtualScroller.constructor.js.map +1 -1
- package/commonjs/VirtualScroller.items.js +11 -10
- package/commonjs/VirtualScroller.items.js.map +1 -1
- package/commonjs/VirtualScroller.js +10 -3
- package/commonjs/VirtualScroller.js.map +1 -1
- package/commonjs/VirtualScroller.layout.js +2 -2
- package/commonjs/VirtualScroller.layout.js.map +1 -1
- package/commonjs/VirtualScroller.state.js +23 -13
- package/commonjs/VirtualScroller.state.js.map +1 -1
- package/commonjs/react/VirtualScroller.js +26 -11
- package/commonjs/react/VirtualScroller.js.map +1 -1
- package/commonjs/react/{useOnItemStateChange.js → useSetItemState.js} +7 -7
- package/commonjs/react/useSetItemState.js.map +1 -0
- package/commonjs/react/useVirtualScroller.js +2 -1
- package/commonjs/react/useVirtualScroller.js.map +1 -1
- package/commonjs/utility/fillArray.js +18 -0
- package/commonjs/utility/fillArray.js.map +1 -0
- package/dom/index.d.ts +7 -6
- package/index.d.ts +16 -15
- package/modules/DOM/VirtualScroller.js +5 -0
- package/modules/DOM/VirtualScroller.js.map +1 -1
- package/modules/ItemHeights.js +1 -1
- package/modules/ItemHeights.js.map +1 -1
- package/modules/VirtualScroller.constructor.js +3 -0
- package/modules/VirtualScroller.constructor.js.map +1 -1
- package/modules/VirtualScroller.items.js +10 -10
- package/modules/VirtualScroller.items.js.map +1 -1
- package/modules/VirtualScroller.js +10 -3
- package/modules/VirtualScroller.js.map +1 -1
- package/modules/VirtualScroller.layout.js +2 -2
- package/modules/VirtualScroller.layout.js.map +1 -1
- package/modules/VirtualScroller.state.js +20 -11
- package/modules/VirtualScroller.state.js.map +1 -1
- package/modules/react/VirtualScroller.js +26 -11
- package/modules/react/VirtualScroller.js.map +1 -1
- package/modules/react/{useOnItemStateChange.js → useSetItemState.js} +6 -6
- package/modules/react/useSetItemState.js.map +1 -0
- package/modules/react/useVirtualScroller.js +2 -1
- package/modules/react/useVirtualScroller.js.map +1 -1
- package/modules/utility/fillArray.js +11 -0
- package/modules/utility/fillArray.js.map +1 -0
- package/package.json +1 -1
- package/react/index.d.ts +14 -8
- package/source/DOM/VirtualScroller.js +4 -0
- package/source/ItemHeights.js +1 -1
- package/source/VirtualScroller.constructor.js +2 -1
- package/source/VirtualScroller.items.js +16 -8
- package/source/VirtualScroller.js +8 -2
- package/source/VirtualScroller.layout.js +2 -2
- package/source/VirtualScroller.state.js +15 -7
- package/source/react/VirtualScroller.js +25 -10
- package/source/react/{useOnItemStateChange.js → useSetItemState.js} +5 -5
- package/source/react/useVirtualScroller.js +2 -0
- package/source/utility/fillArray.js +8 -0
- package/commonjs/react/useOnItemStateChange.js.map +0 -1
- package/modules/react/useOnItemStateChange.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"VirtualScroller.items.js","names":["log","isDebug","getItemsDiff","getItemsCount","getState","items","length","_setItems","newItems","options","previousItems","itemStates","widthHasChanged","stateUpdate","itemHeights","layoutUpdate","itemsUpdateInfo","itemsDiff","firstShownItemIndex","lastShownItemIndex","beforeItemsHeight","afterItemsHeight","shouldRestoreScrollPosition","preserveScrollPositionOnPrependItems","preserveScrollPosition","prependedItemsCount","appendedItemsCount","shouldResetGridLayout","layout","getLayoutUpdateForItemsDiff","itemsCount","columnsCount","getActualColumnsCount","onResetGridLayout","Array","concat","listHeightMeasurement","snapshotListHeightBeforeAddingNewItems","firstNonMeasuredItemIndex","undefined","getInitialLayoutValues","prepend","append","reset","replace","onBeforeShowItems","newItemsWillBeRendered","count","newState","beforeResize","shouldIncludeBeforeResizeValuesInState","shouldDiscardBeforeResizeItemHeights","_isSettingNewItems","updateState","isItemEqual"],"sources":["../source/VirtualScroller.items.js"],"sourcesContent":["import log, { isDebug } from './utility/debug.js'\r\nimport getItemsDiff from './getItemsDiff.js'\r\n\r\nexport default function() {\r\n\tthis.getItemsCount = () => {\r\n\t\treturn this.getState().items.length\r\n\t}\r\n\r\n\t/**\r\n\t * Updates `items`. For example, can prepend or append new items to the list.\r\n\t * @param {any[]} newItems\r\n\t * @param {boolean} [options.preserveScrollPositionOnPrependItems] — Set to `true` to enable \"restore scroll position after prepending items\" feature (could be useful when implementing \"Show previous items\" button).\r\n\t */\r\n\tthis._setItems = (newItems, options = {}) => {\r\n\t\tconst {\r\n\t\t\titems: previousItems\r\n\t\t} = this.getState()\r\n\r\n\t\t// Even if `newItems` are equal to `this.state.items`,\r\n\t\t// still perform a `updateState()` call, because, if `updateState()` calls\r\n\t\t// were \"asynchronous\", there could be a situation when a developer\r\n\t\t// first calls `setItems(newItems)` and then `setItems(oldItems)`:\r\n\t\t// if this function did `return` `if (newItems === this.state.items)`\r\n\t\t// then `updateState({ items: newItems })` would be scheduled as part of\r\n\t\t// `setItems(newItems)` call, but the subsequent `setItems(oldItems)` call\r\n\t\t// wouldn't do anything resulting in `newItems` being set as a result,\r\n\t\t// and that wouldn't be what the developer intended.\r\n\r\n\t\tlet { itemStates } = this.getState()\r\n\t\tlet { itemHeights } = this.widthHasChanged\r\n\t\t\t? this.widthHasChanged.stateUpdate\r\n\t\t\t: this.getState()\r\n\r\n\t\tlog('~ Update items ~')\r\n\r\n\t\tlet layoutUpdate\r\n\t\tlet itemsUpdateInfo\r\n\r\n\t\t// Compare the new items to the current items.\r\n\t\tconst itemsDiff = this.getItemsDiff(previousItems, newItems)\r\n\r\n\t\t// See if it's an \"incremental\" items update.\r\n\t\tif (itemsDiff) {\r\n\t\t\tconst {\r\n\t\t\t\tfirstShownItemIndex,\r\n\t\t\t\tlastShownItemIndex,\r\n\t\t\t\tbeforeItemsHeight,\r\n\t\t\t\tafterItemsHeight\r\n\t\t\t} = this.widthHasChanged\r\n\t\t\t\t? this.widthHasChanged.stateUpdate\r\n\t\t\t\t: this.getState()\r\n\r\n\t\t\tconst shouldRestoreScrollPosition = firstShownItemIndex === 0 &&\r\n\t\t\t\t// `preserveScrollPosition` option name is deprecated,\r\n\t\t\t\t// use `preserveScrollPositionOnPrependItems` instead.\r\n\t\t\t\t(options.preserveScrollPositionOnPrependItems || options.preserveScrollPosition)\r\n\r\n\t\t\tconst {\r\n\t\t\t\tprependedItemsCount,\r\n\t\t\t\tappendedItemsCount\r\n\t\t\t} = itemsDiff\r\n\r\n\t\t\tlet shouldResetGridLayout\r\n\r\n\t\t\tlayoutUpdate = this.layout.getLayoutUpdateForItemsDiff({\r\n\t\t\t\tfirstShownItemIndex,\r\n\t\t\t\tlastShownItemIndex,\r\n\t\t\t\tbeforeItemsHeight,\r\n\t\t\t\tafterItemsHeight\r\n\t\t\t}, {\r\n\t\t\t\tprependedItemsCount,\r\n\t\t\t\tappendedItemsCount\r\n\t\t\t}, {\r\n\t\t\t\titemsCount: newItems.length,\r\n\t\t\t\tcolumnsCount: this.getActualColumnsCount(),\r\n\t\t\t\tshouldRestoreScrollPosition,\r\n\t\t\t\tonResetGridLayout: () => shouldResetGridLayout = true\r\n\t\t\t})\r\n\r\n\t\t\tif (prependedItemsCount > 0) {\r\n\t\t\t\tlog('Prepend', prependedItemsCount, 'items')\r\n\r\n\t\t\t\titemHeights = new Array(prependedItemsCount).concat(itemHeights)\r\n\r\n\t\t\t\tif (itemStates) {\r\n\t\t\t\t\titemStates = new Array(prependedItemsCount).concat(itemStates)\r\n\t\t\t\t}\r\n\r\n\t\t\t\t// Restore scroll position after prepending items (if requested).\r\n\t\t\t\tif (shouldRestoreScrollPosition) {\r\n\t\t\t\t\tlog('Will restore scroll position')\r\n\t\t\t\t\tthis.listHeightMeasurement.snapshotListHeightBeforeAddingNewItems({\r\n\t\t\t\t\t\tpreviousItems,\r\n\t\t\t\t\t\tnewItems,\r\n\t\t\t\t\t\tprependedItemsCount\r\n\t\t\t\t\t})\r\n\t\t\t\t\t// \"Seamless prepend\" scenario doesn't result in a re-layout,\r\n\t\t\t\t\t// so if any \"non measured item\" is currently pending,\r\n\t\t\t\t\t// it doesn't get reset and will be handled after `state` is updated.\r\n\t\t\t\t\tif (this.firstNonMeasuredItemIndex !== undefined) {\r\n\t\t\t\t\t\tthis.firstNonMeasuredItemIndex += prependedItemsCount\r\n\t\t\t\t\t}\r\n\t\t\t\t} else {\r\n\t\t\t\t\tlog('Reset layout')\r\n\t\t\t\t\tif (shouldResetGridLayout) {\r\n\t\t\t\t\t\tlog('Reason: Prepended items count', prependedItemsCount, 'is not divisible by Columns Count', this.getActualColumnsCount())\r\n\t\t\t\t\t\t// Reset item heights because the whole grid is going to be rebalanced\r\n\t\t\t\t\t\t// and re-rendered in a different configuration.\r\n\t\t\t\t\t\titemHeights = new Array(newItems.length)\r\n\t\t\t\t\t} else {\r\n\t\t\t\t\t\t// Reset layout because none of the prepended items have been measured.\r\n\t\t\t\t\t\tlog('Reason: Prepended items\\' heights are unknown')\r\n\t\t\t\t\t}\r\n\t\t\t\t\tlayoutUpdate = this.layout.getInitialLayoutValues({\r\n\t\t\t\t\t\titemsCount: newItems.length,\r\n\t\t\t\t\t\tcolumnsCount: this.getActualColumnsCount()\r\n\t\t\t\t\t})\r\n\t\t\t\t\t// Unschedule a potentially scheduled layout update\r\n\t\t\t\t\t// after measuring a previously non-measured item\r\n\t\t\t\t\t// because the list will be re-layout anyway\r\n\t\t\t\t\t// due to the new items being set.\r\n\t\t\t\t\tthis.firstNonMeasuredItemIndex = undefined\r\n\t\t\t\t}\r\n\t\t\t}\r\n\r\n\t\t\tif (appendedItemsCount > 0) {\r\n\t\t\t\tlog('Append', appendedItemsCount, 'items')\r\n\t\t\t\titemHeights = itemHeights.concat(new Array(appendedItemsCount))\r\n\t\t\t\tif (itemStates) {\r\n\t\t\t\t\titemStates = itemStates.concat(new Array(appendedItemsCount))\r\n\t\t\t\t}\r\n\t\t\t}\r\n\r\n\t\t\titemsUpdateInfo = {\r\n\t\t\t\tprepend: prependedItemsCount > 0,\r\n\t\t\t\tappend: appendedItemsCount > 0\r\n\t\t\t}\r\n\t\t} else {\r\n\t\t\tlog('Items have changed, and', (itemsDiff ? 'a re-layout from scratch has been requested.' : 'it\\'s not a simple append and/or prepend.'), 'Rerender the entire list from scratch.')\r\n\t\t\tlog('Previous items', previousItems)\r\n\t\t\tlog('New items', newItems)\r\n\r\n\t\t\t// Reset item heights and item states.\r\n\t\t\titemHeights = new Array(newItems.length)\r\n\t\t\titemStates = new Array(newItems.length)\r\n\r\n\t\t\tlayoutUpdate = this.layout.getInitialLayoutValues({\r\n\t\t\t\titemsCount: newItems.length,\r\n\t\t\t\tcolumnsCount: this.getActualColumnsCount()\r\n\t\t\t})\r\n\r\n\t\t\t// Unschedule a potentially scheduled layout update\r\n\t\t\t// after measuring a previously non-measured item\r\n\t\t\t// because the list will be re-layout from scratch\r\n\t\t\t// due to the new items being set.\r\n\t\t\tthis.firstNonMeasuredItemIndex = undefined\r\n\r\n\t\t\t// Also reset any potential pending scroll position restoration.\r\n\t\t\t// For example, imagine a developer first called `.setItems(incrementalItemsUpdate)`\r\n\t\t\t// and then called `.setItems(differentItems)` and there was no state update\r\n\t\t\t// in between those two calls. This could happen because state updates aren't\r\n\t\t\t// required to be \"synchronous\". On other words, calling `this.updateState()`\r\n\t\t\t// doesn't necessarily mean that the state is applied immediately.\r\n\t\t\t// Imagine also that such \"delayed\" state updates could be batched,\r\n\t\t\t// like they do in React inside event handlers (though that doesn't apply to this case):\r\n\t\t\t// https://github.com/facebook/react/issues/10231#issuecomment-316644950\r\n\t\t\t// If `this.listHeightMeasurement` wasn't reset on `.setItems(differentItems)`\r\n\t\t\t// and if the second `this.updateState()` call overwrites the first one\r\n\t\t\t// then it would attempt to restore scroll position in a situation when\r\n\t\t\t// it should no longer do that. Hence the reset here.\r\n\t\t\tthis.listHeightMeasurement.reset()\r\n\r\n\t\t\titemsUpdateInfo = {\r\n\t\t\t\treplace: true\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tlog('~ Update state ~')\r\n\r\n\t\t// const layoutValuesAfterUpdate = {\r\n\t\t// \t...this.getState(),\r\n\t\t// \t...layoutUpdate\r\n\t\t// }\r\n\r\n\t\t// `layoutUpdate` is equivalent to `layoutValuesAfterUpdate` because\r\n\t\t// `layoutUpdate` contains all the relevant properties.\r\n\t\tlog('First shown item index', layoutUpdate.firstShownItemIndex)\r\n\t\tlog('Last shown item index', layoutUpdate.lastShownItemIndex)\r\n\t\tlog('Before items height', layoutUpdate.beforeItemsHeight)\r\n\t\tlog('After items height (actual or estimated)', layoutUpdate.afterItemsHeight)\r\n\r\n\t\t// Optionally preload items to be rendered.\r\n\t\t//\r\n\t\t// `layoutUpdate` is equivalent to `layoutValuesAfterUpdate` because\r\n\t\t// `layoutUpdate` contains all the relevant properties.\r\n\t\t//\r\n\t\tthis.onBeforeShowItems(\r\n\t\t\tnewItems,\r\n\t\t\titemHeights,\r\n\t\t\tlayoutUpdate.firstShownItemIndex,\r\n\t\t\tlayoutUpdate.lastShownItemIndex\r\n\t\t)\r\n\r\n\t\t// `this.newItemsWillBeRendered` signals that new `items` are being rendered,\r\n\t\t// and that `VirtualScroller` should temporarily stop all other updates.\r\n\t\t//\r\n\t\t// `this.newItemsWillBeRendered` is cleared in `onRender()`.\r\n\t\t//\r\n\t\t// The values in `this.newItemsWillBeRendered` are used, for example,\r\n\t\t// in `.onResize()` handler in order to not break state consistency when\r\n\t\t// state updates are \"asynchronous\" (delayed) and there's a window resize event\r\n\t\t// in between calling `updateState()` below and that call actually being applied.\r\n\t\t//\r\n\t\tthis.newItemsWillBeRendered = {\r\n\t\t\t...itemsUpdateInfo,\r\n\t\t\tcount: newItems.length,\r\n\t\t\t// `layoutUpdate` now contains all layout-related properties, even if those that\r\n\t\t\t// didn't change. So `firstShownItemIndex` is always in `this.newItemsWillBeRendered`.\r\n\t\t\tlayout: layoutUpdate\r\n\t\t}\r\n\r\n\t\t// `layoutUpdate` now contains all layout-related properties, even if those that\r\n\t\t// didn't change. So this part is no longer relevant.\r\n\t\t//\r\n\t\t// // If `firstShownItemIndex` is gonna be modified as a result of setting new items\r\n\t\t// // then keep that \"new\" `firstShownItemIndex` in order for it to be used by\r\n\t\t// // `onResize()` handler when it calculates \"new\" `firstShownItemIndex`\r\n\t\t// // based on the new columns count (corresponding to the new window width).\r\n\t\t// if (layoutUpdate.firstShownItemIndex !== undefined) {\r\n\t\t// \tthis.newItemsWillBeRendered = {\r\n\t\t// \t\t...this.newItemsWillBeRendered,\r\n\t\t// \t\tfirstShownItemIndex: layoutUpdate.firstShownItemIndex\r\n\t\t// \t}\r\n\t\t// }\r\n\r\n\t\t// Update `VirtualScroller` state.\r\n\t\t//\r\n\t\t// This state update should overwrite all the `state` properties\r\n\t\t// that are also updated in the \"on scroll\" handler (`getShownItemIndexes()`):\r\n\t\t//\r\n\t\t// * `firstShownItemIndex`\r\n\t\t// * `lastShownItemIndex`\r\n\t\t// * `beforeItemsHeight`\r\n\t\t// * `afterItemsHeight`\r\n\t\t//\r\n\t\t// That's because this `updateState()` update has a higher priority\r\n\t\t// than that of the \"on scroll\" handler, so it should overwrite\r\n\t\t// any potential state changes dispatched by the \"on scroll\" handler.\r\n\t\t//\r\n\t\tconst newState = {\r\n\t\t\t...layoutUpdate,\r\n\t\t\titems: newItems,\r\n\t\t\titemStates,\r\n\t\t\titemHeights\r\n\t\t}\r\n\r\n\t\t// Introduced `shouldIncludeBeforeResizeValuesInState()` getter just to prevent\r\n\t\t// cluttering `state` with `beforeResize: undefined` property if `beforeResize`\r\n\t\t// hasn't ever been set in `state` previously.\r\n\t\tif (this.beforeResize.shouldIncludeBeforeResizeValuesInState()) {\r\n\t\t\tif (this.shouldDiscardBeforeResizeItemHeights()) {\r\n\t\t\t\t// Reset \"before resize\" item heights because now there're new items prepended\r\n\t\t\t\t// with unknown heights, or completely new items with unknown heights, so\r\n\t\t\t\t// `beforeItemsHeight` value won't be preserved anyway.\r\n\t\t\t\tnewState.beforeResize = undefined\r\n\t\t\t}\r\n\t\t\telse {\r\n\t\t\t\t// Overwrite `beforeResize` property in `state` even if it wasn't modified\r\n\t\t\t\t// because state updates could be \"asynchronous\" and in that case there could be\r\n\t\t\t\t// some previous `updateState()` call from some previous `setItems()` call that\r\n\t\t\t\t// hasn't yet been applied, and that previous call might have scheduled setting\r\n\t\t\t\t// `state.beforeResize` property to `undefined` in order to reset it, but this\r\n\t\t\t\t// next `updateState()` call might not require resetting `state.beforeResize` property\r\n\t\t\t\t// so it should undo resetting it by simply overwriting it with its normal value.\r\n\t\t\t\tnewState.beforeResize = this.widthHasChanged\r\n\t\t\t\t\t? this.widthHasChanged.stateUpdate.beforeResize\r\n\t\t\t\t\t: this.getState().beforeResize\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\t// `newState` should also overwrite all `state` properties that're updated in `onResize()`\r\n\t\t// because `setItems()`'s state updates always overwrite `onResize()`'s state updates.\r\n\t\t// (The least-priority ones are `onScroll()` state updates, but those're simply skipped\r\n\t\t// if there's a pending `setItems()` or `onResize()` update).\r\n\t\t//\r\n\t\t// `state` property exceptions:\r\n\t\t//\r\n\t\t// `verticalSpacing` property is not updated here because it's fine setting it to\r\n\t\t// `undefined` in `onResize()` — it will simply be re-measured after the component re-renders.\r\n\t\t//\r\n\t\t// `columnsCount` property is also not updated here because by definition it's only\r\n\t\t// updated in `onResize()`.\r\n\r\n\t\t// Render.\r\n\t\tthis._isSettingNewItems = true\r\n\t\tthis.updateState(newState)\r\n\t}\r\n\r\n\tthis.getItemsDiff = (previousItems, newItems) => {\r\n\t\treturn get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b;IALT,GAxM4C,CAgN5C;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IAEA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;;IACA,IAAMiC,QAAQ,mCACVjC,YADU;MAEbV,KAAK,EAAEG,QAFM;MAGbG,UAAU,EAAVA,UAHa;MAIbG,WAAW,EAAXA;IAJa,EAAd,CA5O4C,CAmP5C;IACA;IACA;;;IACA,IAAI,KAAI,CAACmC,YAAL,CAAkBC,sCAAlB,EAAJ,EAAgE;MAC/D,IAAI,KAAI,CAACC,oCAAL,EAAJ,EAAiD;QAChD;QACA;QACA;QACAH,QAAQ,CAACC,YAAT,GAAwBV,SAAxB;MACA,CALD,MAMK;QACJ;QACA;QACA;QACA;QACA;QACA;QACA;QACAS,QAAQ,CAACC,YAAT,GAAwB,KAAI,CAACrC,eAAL,GACrB,KAAI,CAACA,eAAL,CAAqBC,WAArB,CAAiCoC,YADZ,GAErB,KAAI,CAAC7C,QAAL,GAAgB6C,YAFnB;MAGA;IACD,CAzQ2C,CA2Q5C;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IAEA;;;IACA,KAAI,CAACG,kBAAL,GAA0B,IAA1B;;IACA,KAAI,CAACC,WAAL,CAAiBL,QAAjB;EACA,CA3RD;;EA6RA,KAAK9C,YAAL,GAAoB,UAACQ,aAAD,EAAgBF,QAAhB,EAA6B;IAChD,OAAON,YAAY,CAACQ,aAAD,EAAgBF,QAAhB,EAA0B,KAAI,CAAC8C,WAA/B,CAAnB;EACA,CAFD;AAGA"}
|
|
1
|
+
{"version":3,"file":"VirtualScroller.items.js","names":["log","isDebug","getItemsDiff","fillArray","getItemsCount","getState","items","length","_setItems","newItems","options","previousItems","itemStates","widthHasChanged","stateUpdate","itemHeights","layoutUpdate","itemsUpdateInfo","itemsDiff","firstShownItemIndex","lastShownItemIndex","beforeItemsHeight","afterItemsHeight","shouldRestoreScrollPosition","preserveScrollPositionOnPrependItems","preserveScrollPosition","prependedItemsCount","appendedItemsCount","shouldResetGridLayout","layout","getLayoutUpdateForItemsDiff","itemsCount","columnsCount","getActualColumnsCount","onResetGridLayout","Array","concat","i","getInitialItemState","listHeightMeasurement","snapshotListHeightBeforeAddingNewItems","firstNonMeasuredItemIndex","undefined","getInitialLayoutValues","prepend","append","reset","replace","onBeforeShowItems","newItemsWillBeRendered","count","newState","beforeResize","shouldIncludeBeforeResizeValuesInState","shouldDiscardBeforeResizeItemHeights","_isSettingNewItems","updateState","isItemEqual"],"sources":["../source/VirtualScroller.items.js"],"sourcesContent":["import log, { isDebug } from './utility/debug.js'\r\nimport getItemsDiff from './getItemsDiff.js'\r\nimport fillArray from './utility/fillArray.js'\r\n\r\nexport default function() {\r\n\tthis.getItemsCount = () => {\r\n\t\treturn this.getState().items.length\r\n\t}\r\n\r\n\t/**\r\n\t * Updates `items`. For example, can prepend or append new items to the list.\r\n\t * @param {any[]} newItems\r\n\t * @param {boolean} [options.preserveScrollPositionOnPrependItems] — Set to `true` to enable \"restore scroll position after prepending items\" feature (could be useful when implementing \"Show previous items\" button).\r\n\t */\r\n\tthis._setItems = (newItems, options = {}) => {\r\n\t\tconst {\r\n\t\t\titems: previousItems\r\n\t\t} = this.getState()\r\n\r\n\t\t// Even if `newItems` are equal to `this.state.items`,\r\n\t\t// still perform a `updateState()` call, because, if `updateState()` calls\r\n\t\t// were \"asynchronous\", there could be a situation when a developer\r\n\t\t// first calls `setItems(newItems)` and then `setItems(oldItems)`:\r\n\t\t// if this function did `return` `if (newItems === this.state.items)`\r\n\t\t// then `updateState({ items: newItems })` would be scheduled as part of\r\n\t\t// `setItems(newItems)` call, but the subsequent `setItems(oldItems)` call\r\n\t\t// wouldn't do anything resulting in `newItems` being set as a result,\r\n\t\t// and that wouldn't be what the developer intended.\r\n\r\n\t\tlet { itemStates } = this.getState()\r\n\t\tlet { itemHeights } = this.widthHasChanged\r\n\t\t\t? this.widthHasChanged.stateUpdate\r\n\t\t\t: this.getState()\r\n\r\n\t\tlog('~ Update items ~')\r\n\r\n\t\tlet layoutUpdate\r\n\t\tlet itemsUpdateInfo\r\n\r\n\t\t// Compare the new items to the current items.\r\n\t\tconst itemsDiff = this.getItemsDiff(previousItems, newItems)\r\n\r\n\t\t// See if it's an \"incremental\" items update.\r\n\t\tif (itemsDiff) {\r\n\t\t\tconst {\r\n\t\t\t\tfirstShownItemIndex,\r\n\t\t\t\tlastShownItemIndex,\r\n\t\t\t\tbeforeItemsHeight,\r\n\t\t\t\tafterItemsHeight\r\n\t\t\t} = this.widthHasChanged\r\n\t\t\t\t? this.widthHasChanged.stateUpdate\r\n\t\t\t\t: this.getState()\r\n\r\n\t\t\tconst shouldRestoreScrollPosition = firstShownItemIndex === 0 &&\r\n\t\t\t\t// `preserveScrollPosition` option name is deprecated,\r\n\t\t\t\t// use `preserveScrollPositionOnPrependItems` instead.\r\n\t\t\t\t(options.preserveScrollPositionOnPrependItems || options.preserveScrollPosition)\r\n\r\n\t\t\tconst {\r\n\t\t\t\tprependedItemsCount,\r\n\t\t\t\tappendedItemsCount\r\n\t\t\t} = itemsDiff\r\n\r\n\t\t\tlet shouldResetGridLayout\r\n\r\n\t\t\tlayoutUpdate = this.layout.getLayoutUpdateForItemsDiff({\r\n\t\t\t\tfirstShownItemIndex,\r\n\t\t\t\tlastShownItemIndex,\r\n\t\t\t\tbeforeItemsHeight,\r\n\t\t\t\tafterItemsHeight\r\n\t\t\t}, {\r\n\t\t\t\tprependedItemsCount,\r\n\t\t\t\tappendedItemsCount\r\n\t\t\t}, {\r\n\t\t\t\titemsCount: newItems.length,\r\n\t\t\t\tcolumnsCount: this.getActualColumnsCount(),\r\n\t\t\t\tshouldRestoreScrollPosition,\r\n\t\t\t\tonResetGridLayout: () => shouldResetGridLayout = true\r\n\t\t\t})\r\n\r\n\t\t\tif (prependedItemsCount > 0) {\r\n\t\t\t\tlog('Prepend', prependedItemsCount, 'items')\r\n\r\n\t\t\t\titemHeights = new Array(prependedItemsCount).concat(itemHeights)\r\n\t\t\t\titemStates = fillArray(\r\n\t\t\t\t\tnew Array(prependedItemsCount),\r\n\t\t\t\t\t(i) => this.getInitialItemState(newItems[i])\r\n\t\t\t\t)\r\n\t\t\t\t\t.concat(itemStates)\r\n\r\n\t\t\t\t// Restore scroll position after prepending items (if requested).\r\n\t\t\t\tif (shouldRestoreScrollPosition) {\r\n\t\t\t\t\tlog('Will restore scroll position')\r\n\t\t\t\t\tthis.listHeightMeasurement.snapshotListHeightBeforeAddingNewItems({\r\n\t\t\t\t\t\tpreviousItems,\r\n\t\t\t\t\t\tnewItems,\r\n\t\t\t\t\t\tprependedItemsCount\r\n\t\t\t\t\t})\r\n\t\t\t\t\t// \"Seamless prepend\" scenario doesn't result in a re-layout,\r\n\t\t\t\t\t// so if any \"non measured item\" is currently pending,\r\n\t\t\t\t\t// it doesn't get reset and will be handled after `state` is updated.\r\n\t\t\t\t\tif (this.firstNonMeasuredItemIndex !== undefined) {\r\n\t\t\t\t\t\tthis.firstNonMeasuredItemIndex += prependedItemsCount\r\n\t\t\t\t\t}\r\n\t\t\t\t} else {\r\n\t\t\t\t\tlog('Reset layout')\r\n\t\t\t\t\tif (shouldResetGridLayout) {\r\n\t\t\t\t\t\tlog('Reason: Prepended items count', prependedItemsCount, 'is not divisible by Columns Count', this.getActualColumnsCount())\r\n\t\t\t\t\t\t// Reset item heights because the whole grid is going to be rebalanced\r\n\t\t\t\t\t\t// and re-rendered in a different configuration.\r\n\t\t\t\t\t\titemHeights = new Array(newItems.length)\r\n\t\t\t\t\t} else {\r\n\t\t\t\t\t\t// Reset layout because none of the prepended items have been measured.\r\n\t\t\t\t\t\tlog('Reason: Prepended items\\' heights are unknown')\r\n\t\t\t\t\t}\r\n\t\t\t\t\tlayoutUpdate = this.layout.getInitialLayoutValues({\r\n\t\t\t\t\t\titemsCount: newItems.length,\r\n\t\t\t\t\t\tcolumnsCount: this.getActualColumnsCount()\r\n\t\t\t\t\t})\r\n\t\t\t\t\t// Unschedule a potentially scheduled layout update\r\n\t\t\t\t\t// after measuring a previously non-measured item\r\n\t\t\t\t\t// because the list will be re-layout anyway\r\n\t\t\t\t\t// due to the new items being set.\r\n\t\t\t\t\tthis.firstNonMeasuredItemIndex = undefined\r\n\t\t\t\t}\r\n\t\t\t}\r\n\r\n\t\t\tif (appendedItemsCount > 0) {\r\n\t\t\t\tlog('Append', appendedItemsCount, 'items')\r\n\t\t\t\titemHeights = itemHeights.concat(new Array(appendedItemsCount))\r\n\t\t\t\titemStates = itemStates.concat(\r\n\t\t\t\t\tfillArray(\r\n\t\t\t\t\t\tnew Array(appendedItemsCount),\r\n\t\t\t\t\t\t(i) => this.getInitialItemState(newItems[prependedItemsCount + previousItems.length + i])\r\n\t\t\t\t\t)\r\n\t\t\t\t)\r\n\t\t\t}\r\n\r\n\t\t\titemsUpdateInfo = {\r\n\t\t\t\tprepend: prependedItemsCount > 0,\r\n\t\t\t\tappend: appendedItemsCount > 0\r\n\t\t\t}\r\n\t\t} else {\r\n\t\t\tlog('Items have changed, and', (itemsDiff ? 'a re-layout from scratch has been requested.' : 'it\\'s not a simple append and/or prepend.'), 'Rerender the entire list from scratch.')\r\n\t\t\tlog('Previous items', previousItems)\r\n\t\t\tlog('New items', newItems)\r\n\r\n\t\t\t// Reset item heights and item states.\r\n\t\t\titemHeights = new Array(newItems.length)\r\n\t\t\titemStates = fillArray(\r\n\t\t\t\tnew Array(newItems.length),\r\n\t\t\t\t(i) => this.getInitialItemState(newItems[i])\r\n\t\t\t)\r\n\r\n\t\t\tlayoutUpdate = this.layout.getInitialLayoutValues({\r\n\t\t\t\titemsCount: newItems.length,\r\n\t\t\t\tcolumnsCount: this.getActualColumnsCount()\r\n\t\t\t})\r\n\r\n\t\t\t// Unschedule a potentially scheduled layout update\r\n\t\t\t// after measuring a previously non-measured item\r\n\t\t\t// because the list will be re-layout from scratch\r\n\t\t\t// due to the new items being set.\r\n\t\t\tthis.firstNonMeasuredItemIndex = undefined\r\n\r\n\t\t\t// Also reset any potential pending scroll position restoration.\r\n\t\t\t// For example, imagine a developer first called `.setItems(incrementalItemsUpdate)`\r\n\t\t\t// and then called `.setItems(differentItems)` and there was no state update\r\n\t\t\t// in between those two calls. This could happen because state updates aren't\r\n\t\t\t// required to be \"synchronous\". On other words, calling `this.updateState()`\r\n\t\t\t// doesn't necessarily mean that the state is applied immediately.\r\n\t\t\t// Imagine also that such \"delayed\" state updates could be batched,\r\n\t\t\t// like they do in React inside event handlers (though that doesn't apply to this case):\r\n\t\t\t// https://github.com/facebook/react/issues/10231#issuecomment-316644950\r\n\t\t\t// If `this.listHeightMeasurement` wasn't reset on `.setItems(differentItems)`\r\n\t\t\t// and if the second `this.updateState()` call overwrites the first one\r\n\t\t\t// then it would attempt to restore scroll position in a situation when\r\n\t\t\t// it should no longer do that. Hence the reset here.\r\n\t\t\tthis.listHeightMeasurement.reset()\r\n\r\n\t\t\titemsUpdateInfo = {\r\n\t\t\t\treplace: true\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tlog('~ Update state ~')\r\n\r\n\t\t// const layoutValuesAfterUpdate = {\r\n\t\t// \t...this.getState(),\r\n\t\t// \t...layoutUpdate\r\n\t\t// }\r\n\r\n\t\t// `layoutUpdate` is equivalent to `layoutValuesAfterUpdate` because\r\n\t\t// `layoutUpdate` contains all the relevant properties.\r\n\t\tlog('First shown item index', layoutUpdate.firstShownItemIndex)\r\n\t\tlog('Last shown item index', layoutUpdate.lastShownItemIndex)\r\n\t\tlog('Before items height', layoutUpdate.beforeItemsHeight)\r\n\t\tlog('After items height (actual or estimated)', layoutUpdate.afterItemsHeight)\r\n\r\n\t\t// Optionally preload items to be rendered.\r\n\t\t//\r\n\t\t// `layoutUpdate` is equivalent to `layoutValuesAfterUpdate` because\r\n\t\t// `layoutUpdate` contains all the relevant properties.\r\n\t\t//\r\n\t\tthis.onBeforeShowItems(\r\n\t\t\tnewItems,\r\n\t\t\titemHeights,\r\n\t\t\tlayoutUpdate.firstShownItemIndex,\r\n\t\t\tlayoutUpdate.lastShownItemIndex\r\n\t\t)\r\n\r\n\t\t// `this.newItemsWillBeRendered` signals that new `items` are being rendered,\r\n\t\t// and that `VirtualScroller` should temporarily stop all other updates.\r\n\t\t//\r\n\t\t// `this.newItemsWillBeRendered` is cleared in `onRender()`.\r\n\t\t//\r\n\t\t// The values in `this.newItemsWillBeRendered` are used, for example,\r\n\t\t// in `.onResize()` handler in order to not break state consistency when\r\n\t\t// state updates are \"asynchronous\" (delayed) and there's a window resize event\r\n\t\t// in between calling `updateState()` below and that call actually being applied.\r\n\t\t//\r\n\t\tthis.newItemsWillBeRendered = {\r\n\t\t\t...itemsUpdateInfo,\r\n\t\t\tcount: newItems.length,\r\n\t\t\t// `layoutUpdate` now contains all layout-related properties, even if those that\r\n\t\t\t// didn't change. So `firstShownItemIndex` is always in `this.newItemsWillBeRendered`.\r\n\t\t\tlayout: layoutUpdate\r\n\t\t}\r\n\r\n\t\t// `layoutUpdate` now contains all layout-related properties, even if those that\r\n\t\t// didn't change. So this part is no longer relevant.\r\n\t\t//\r\n\t\t// // If `firstShownItemIndex` is gonna be modified as a result of setting new items\r\n\t\t// // then keep that \"new\" `firstShownItemIndex` in order for it to be used by\r\n\t\t// // `onResize()` handler when it calculates \"new\" `firstShownItemIndex`\r\n\t\t// // based on the new columns count (corresponding to the new window width).\r\n\t\t// if (layoutUpdate.firstShownItemIndex !== undefined) {\r\n\t\t// \tthis.newItemsWillBeRendered = {\r\n\t\t// \t\t...this.newItemsWillBeRendered,\r\n\t\t// \t\tfirstShownItemIndex: layoutUpdate.firstShownItemIndex\r\n\t\t// \t}\r\n\t\t// }\r\n\r\n\t\t// Update `VirtualScroller` state.\r\n\t\t//\r\n\t\t// This state update should overwrite all the `state` properties\r\n\t\t// that are also updated in the \"on scroll\" handler (`getShownItemIndexes()`):\r\n\t\t//\r\n\t\t// * `firstShownItemIndex`\r\n\t\t// * `lastShownItemIndex`\r\n\t\t// * `beforeItemsHeight`\r\n\t\t// * `afterItemsHeight`\r\n\t\t//\r\n\t\t// That's because this `updateState()` update has a higher priority\r\n\t\t// than that of the \"on scroll\" handler, so it should overwrite\r\n\t\t// any potential state changes dispatched by the \"on scroll\" handler.\r\n\t\t//\r\n\t\tconst newState = {\r\n\t\t\t...layoutUpdate,\r\n\t\t\titems: newItems,\r\n\t\t\titemStates,\r\n\t\t\titemHeights\r\n\t\t}\r\n\r\n\t\t// Introduced `shouldIncludeBeforeResizeValuesInState()` getter just to prevent\r\n\t\t// cluttering `state` with `beforeResize: undefined` property if `beforeResize`\r\n\t\t// hasn't ever been set in `state` previously.\r\n\t\tif (this.beforeResize.shouldIncludeBeforeResizeValuesInState()) {\r\n\t\t\tif (this.shouldDiscardBeforeResizeItemHeights()) {\r\n\t\t\t\t// Reset \"before resize\" item heights because now there're new items prepended\r\n\t\t\t\t// with unknown heights, or completely new items with unknown heights, so\r\n\t\t\t\t// `beforeItemsHeight` value won't be preserved anyway.\r\n\t\t\t\tnewState.beforeResize = undefined\r\n\t\t\t}\r\n\t\t\telse {\r\n\t\t\t\t// Overwrite `beforeResize` property in `state` even if it wasn't modified\r\n\t\t\t\t// because state updates could be \"asynchronous\" and in that case there could be\r\n\t\t\t\t// some previous `updateState()` call from some previous `setItems()` call that\r\n\t\t\t\t// hasn't yet been applied, and that previous call might have scheduled setting\r\n\t\t\t\t// `state.beforeResize` property to `undefined` in order to reset it, but this\r\n\t\t\t\t// next `updateState()` call might not require resetting `state.beforeResize` property\r\n\t\t\t\t// so it should undo resetting it by simply overwriting it with its normal value.\r\n\t\t\t\tnewState.beforeResize = this.widthHasChanged\r\n\t\t\t\t\t? this.widthHasChanged.stateUpdate.beforeResize\r\n\t\t\t\t\t: this.getState().beforeResize\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\t// `newState` should also overwrite all `state` properties that're updated in `onResize()`\r\n\t\t// because `setItems()`'s state updates always overwrite `onResize()`'s state updates.\r\n\t\t// (The least-priority ones are `onScroll()` state updates, but those're simply skipped\r\n\t\t// if there's a pending `setItems()` or `onResize()` update).\r\n\t\t//\r\n\t\t// `state` property exceptions:\r\n\t\t//\r\n\t\t// `verticalSpacing` property is not updated here because it's fine setting it to\r\n\t\t// `undefined` in `onResize()` — it will simply be re-measured after the component re-renders.\r\n\t\t//\r\n\t\t// `columnsCount` property is also not updated here because by definition it's only\r\n\t\t// updated in `onResize()`.\r\n\r\n\t\t// Render.\r\n\t\tthis._isSettingNewItems = true\r\n\t\tthis.updateState(newState)\r\n\t}\r\n\r\n\tthis.getItemsDiff = (previousItems, newItems) => {\r\n\t\treturn getItemsDiff(previousItems, newItems, this.isItemEqual)\r\n\t}\r\n}"],"mappings":";;;;;;AAAA,OAAOA,GAAP,IAAcC,OAAd,QAA6B,oBAA7B;AACA,OAAOC,YAAP,MAAyB,mBAAzB;AACA,OAAOC,SAAP,MAAsB,wBAAtB;AAEA,eAAe,YAAW;EAAA;;EACzB,KAAKC,aAAL,GAAqB,YAAM;IAC1B,OAAO,KAAI,CAACC,QAAL,GAAgBC,KAAhB,CAAsBC,MAA7B;EACA,CAFD;EAIA;AACD;AACA;AACA;AACA;;;EACC,KAAKC,SAAL,GAAiB,UAACC,QAAD,EAA4B;IAAA,IAAjBC,OAAiB,uEAAP,EAAO;;IAC5C,qBAEI,KAAI,CAACL,QAAL,EAFJ;IAAA,IACQM,aADR,kBACCL,KADD,CAD4C,CAK5C;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;;;IAEA,sBAAqB,KAAI,CAACD,QAAL,EAArB;IAAA,IAAMO,UAAN,mBAAMA,UAAN;;IACA,WAAsB,KAAI,CAACC,eAAL,GACnB,KAAI,CAACA,eAAL,CAAqBC,WADF,GAEnB,KAAI,CAACT,QAAL,EAFH;IAAA,IAAMU,WAAN,QAAMA,WAAN;;IAIAf,GAAG,CAAC,kBAAD,CAAH;IAEA,IAAIgB,YAAJ;IACA,IAAIC,eAAJ,CAvB4C,CAyB5C;;IACA,IAAMC,SAAS,GA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wBV,SAAxB;MACA,CALD,MAMK;QACJ;QACA;QACA;QACA;QACA;QACA;QACA;QACAS,QAAQ,CAACC,YAAT,GAAwB,KAAI,CAACvC,eAAL,GACrB,KAAI,CAACA,eAAL,CAAqBC,WAArB,CAAiCsC,YADZ,GAErB,KAAI,CAAC/C,QAAL,GAAgB+C,YAFnB;MAGA;IACD,CAhR2C,CAkR5C;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IAEA;;;IACA,KAAI,CAACG,kBAAL,GAA0B,IAA1B;;IACA,KAAI,CAACC,WAAL,CAAiBL,QAAjB;EACA,CAlSD;;EAoSA,KAAKjD,YAAL,GAAoB,UAACS,aAAD,EAAgBF,QAAhB,EAA6B;IAChD,OAAOP,YAAY,CAACS,aAAD,EAAgBF,QAAhB,EAA0B,KAAI,CAACgD,WAA/B,CAAnB;EACA,CAFD;AAGA"}
|
|
@@ -236,11 +236,18 @@ var VirtualScroller = /*#__PURE__*/function () {
|
|
|
236
236
|
*/
|
|
237
237
|
|
|
238
238
|
}, {
|
|
239
|
-
key: "
|
|
240
|
-
value: function
|
|
239
|
+
key: "setItemState",
|
|
240
|
+
value: function setItemState(i, newItemState) {
|
|
241
241
|
this.hasToBeStarted();
|
|
242
242
|
|
|
243
|
-
this.
|
|
243
|
+
this._setItemState(i, newItemState);
|
|
244
|
+
} // (deprecated)
|
|
245
|
+
// Use `.setItemState()` method name instead.
|
|
246
|
+
|
|
247
|
+
}, {
|
|
248
|
+
key: "onItemStateChange",
|
|
249
|
+
value: function onItemStateChange(i, newItemState) {
|
|
250
|
+
this.setItemState(i, newItemState);
|
|
244
251
|
}
|
|
245
252
|
/**
|
|
246
253
|
* Updates `items`. For example, can prepend or append new items to the list.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"VirtualScroller.js","names":["VirtualScrollerConstructor","hasTbodyStyles","addTbodyStyles","LAYOUT_REASON","log","VirtualScroller","getItemsContainerElement","items","options","_isActive","Error","resize","stop","scroll","listTopOffsetWatcher","isStarted","cancelLayoutTimer","hasToBeStarted","onUpdateShownItemIndexes","reason","MANUAL","_onRender","getState","previousState","call","isRestart","_usesCustomStateStorage","useDefaultStateStorage","_render","listHeightMeasurement","reset","_isResizing","undefined","_isSettingNewItems","tbody","stateUpdate","_stoppedStateUpdate","verticalSpacing","verticalSpacingStateUpdate","measureItemHeightsAndSpacing","start","scrollableContainerWidth","scrollableContainer","getWidth","newWidth","prevWidth","onResize","columnsCount","getActualColumnsCount","columnsCountFromState","STARTED","i","itemTopOffsetInList","layout","getItemTopOffset","getListTopOffsetInsideScrollableContainer","_onItemHeightChange","newItemState","_onItemStateChange","newItems","_setItems"],"sources":["../source/VirtualScroller.js"],"sourcesContent":["import VirtualScrollerConstructor from './VirtualScroller.constructor.js'\r\nimport { hasTbodyStyles, addTbodyStyles } from './DOM/tbody.js'\r\nimport { LAYOUT_REASON } from './Layout.js'\r\nimport log from './utility/debug.js'\r\n\r\nexport default class VirtualScroller {\r\n\t/**\r\n\t * @param {function} getItemsContainerElement — Returns the container DOM `Element`.\r\n\t * @param {any[]} items — The list of items.\r\n\t * @param {Object} [options] — See README.md.\r\n\t * @return {VirtualScroller}\r\n\t */\r\n\tconstructor(\r\n\t\tgetItemsContainerElement,\r\n\t\titems,\r\n\t\toptions = {}\r\n\t) {\r\n\t\tVirtualScrollerConstructor.call(\r\n\t\t\tthis,\r\n\t\t\tgetItemsContainerElement,\r\n\t\t\titems,\r\n\t\t\toptions\r\n\t\t)\r\n\t}\r\n\r\n\t/**\r\n\t * Should be invoked after a \"container\" DOM Element is mounted (inserted into the DOM tree).\r\n\t */\r\n\tstart() {\r\n\t\tif (this._isActive) {\r\n\t\t\tthrow new Error('[virtual-scroller] `VirtualScroller` has already been started')\r\n\t\t}\r\n\r\n\t\t// If has been stopped previously.\r\n\t\tconst isRestart = this._isActive === false\r\n\r\n\t\tif (!isRestart) {\r\n\t\t\t// If no custom state storage has been configured, use the default one.\r\n\t\t\t// Also sets the initial state.\r\n\t\t\tif (!this._usesCustomStateStorage) {\r\n\t\t\t\tthis.useDefaultStateStorage()\r\n\t\t\t}\r\n\t\t\t// If `render()` function parameter was passed,\r\n\t\t\t// perform an initial render.\r\n\t\t\tif (this._render) {\r\n\t\t\t\tthis._render(this.getState())\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tlog('~ Start ~')\r\n\r\n\t\t// `this._isActive = true` should be placed somewhere at the start of this function.\r\n\t\tthis._isActive = true\r\n\r\n\t\t// Reset `ListHeightMeasurement` just in case it has some \"leftover\" state.\r\n\t\tthis.listHeightMeasurement.reset()\r\n\r\n\t\t// Reset `_isResizing` flag just in case it has some \"leftover\" value.\r\n\t\tthis._isResizing = undefined\r\n\r\n\t\t// Reset `_isSettingNewItems` flag just in case it has some \"leftover\" value.\r\n\t\tthis._isSettingNewItems = undefined\r\n\r\n\t\t// Work around `<tbody/>` not being able to have `padding`.\r\n\t\t// https://gitlab.com/catamphetamine/virtual-scroller/-/issues/1\r\n\t\tif (this.tbody) {\r\n\t\t\tif (!hasTbodyStyles(this.getItemsContainerElement())) {\r\n\t\t\t\taddTbodyStyles(this.getItemsContainerElement())\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\t// If there was a pending state update that didn't get applied\r\n\t\t// because of stopping the `VirtualScroller`, apply that state update now.\r\n\t\t//\r\n\t\t// The pending state update won't get applied if the scrollable container width\r\n\t\t// has changed but that's ok because that state update currently could only contain:\r\n\t\t// * `scrollableContainerWidth`\r\n\t\t// * `verticalSpacing`\r\n\t\t// * `beforeResize`\r\n\t\t// All of those get rewritten in `onResize()` anyway.\r\n\t\t//\r\n\t\tlet stateUpdate = this._stoppedStateUpdate\r\n\t\tthis._stoppedStateUpdate = undefined\r\n\r\n\t\t// Reset `this.verticalSpacing` so that it re-measures it in cases when\r\n\t\t// the `VirtualScroller` was previously stopped and is now being restarted.\r\n\t\t// The rationale is that a previously captured inter-item vertical spacing\r\n\t\t// can't be \"trusted\" in a sense that the user might have resized the window\r\n\t\t// after the previous `state` has been snapshotted.\r\n\t\t// If the user has resized the window, then changing window width might have\r\n\t\t// activated different CSS `@media()` \"queries\" resulting in a potentially different\r\n\t\t// vertical spacing after the restart.\r\n\t\t// If it's not a restart then `this.verticalSpacing` is `undefined` anyway.\r\n\t\tthis.verticalSpacing = undefined\r\n\r\n\t\tconst verticalSpacingStateUpdate = this.measureItemHeightsAndSpacing()\r\n\t\tif (verticalSpacingStateUpdate) {\r\n\t\t\tstateUpdate = {\r\n\t\t\t\t...stateUpdate,\r\n\t\t\t\t...verticalSpacingStateUpdate\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tthis.resize.start()\r\n\t\tthis.scroll.start()\r\n\r\n\t\t// If `scrollableContainerWidth` hasn't been measured yet,\r\n\t\t// measure it and write it to state.\r\n\t\tif (this.getState().scrollableContainerWidth === undefined) {\r\n\t\t\tconst scrollableContainerWidth = this.scrollableContainer.getWidth()\r\n\t\t\tstateUpdate = {\r\n\t\t\t\t...stateUpdate,\r\n\t\t\t\tscrollableContainerWidth\r\n\t\t\t}\r\n\t\t} else {\r\n\t\t\t// Reset layout:\r\n\t\t\t// * If the scrollable container width has changed while stopped.\r\n\t\t\t// * If the restored state was calculated for another scrollable container width.\r\n\t\t\tconst newWidth = this.scrollableContainer.getWidth()\r\n\t\t\tconst prevWidth = this.getState().scrollableContainerWidth\r\n\t\t\tif (newWidth !== prevWidth) {\r\n\t\t\t\tlog('~ Scrollable container width changed from', prevWidth, 'to', newWidth, '~')\r\n\t\t\t\t// `stateUpdate` doesn't get passed to `this.onResize()`, and, therefore,\r\n\t\t\t\t// won't be applied. But that's ok because currently it could only contain:\r\n\t\t\t\t// * `scrollableContainerWidth`\r\n\t\t\t\t// * `verticalSpacing`\r\n\t\t\t\t// * `beforeResize`\r\n\t\t\t\t// All of those get rewritten in `onResize()` anyway.\r\n\t\t\t\treturn this.onResize()\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\t// If the `VirtualScroller` uses custom (external) state storage, then\r\n\t\t// check if the columns count has changed between calling `.getInitialState()`\r\n\t\t// and `.start()`. If it has, perform a re-layout \"from scratch\".\r\n\t\tif (this._usesCustomStateStorage) {\r\n\t\t\tconst columnsCount = this.getActualColumnsCount()\r\n\t\t\tconst columnsCountFromState = this.getState().columnsCount || 1\r\n\t\t\tif (columnsCount !== columnsCountFromState) {\r\n\t\t\t\treturn this.onResize()\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\t// Re-calculate layout and re-render the list.\r\n\t\t// Do that even if when an initial `state` parameter, containing layout values,\r\n\t\t// has been passed. The reason is that the `state` parameter can't be \"trusted\"\r\n\t\t// in a way that it could have been snapshotted for another window width and\r\n\t\t// the user might have resized their window since then.\r\n\t\tthis.onUpdateShownItemIndexes({ reason: LAYOUT_REASON.STARTED, stateUpdate })\r\n\t}\r\n\r\n\t// Could be passed as a \"callback\" parameter, so bind it to `this`.\r\n\tstop = () => {\r\n\t\tif (!this._isActive) {\r\n\t\t\tthrow new Error('[virtual-scroller] Can\\'t stop a `VirtualScroller` that hasn\\'t been started')\r\n\t\t}\r\n\r\n\t\tthis._isActive = false\r\n\r\n\t\tlog('~ Stop ~')\r\n\r\n\t\tthis.resize.stop()\r\n\t\tthis.scroll.stop()\r\n\r\n\t\t// Stop `ListTopOffsetWatcher` if it has been started.\r\n\t\t// There seems to be no need to restart `ListTopOffsetWatcher`.\r\n\t\t// It's mainly a hacky workaround for development mode anyway.\r\n\t\tif (this.listTopOffsetWatcher && this.listTopOffsetWatcher.isStarted()) {\r\n\t\t\tthis.listTopOffsetWatcher.stop()\r\n\t\t}\r\n\r\n\t\t// Cancel any scheduled layout.\r\n\t\tthis.cancelLayoutTimer({})\r\n\t}\r\n\r\n\thasToBeStarted() {\r\n\t\tif (!this._isActive) {\r\n\t\t\tthrow new Error('[virtual-scroller] `VirtualScroller` hasn\\'t been started')\r\n\t\t}\r\n\t}\r\n\r\n\t// Bind it to `this` because this function could hypothetically be passed\r\n\t// as a \"callback\" parameter.\r\n\tupdateLayout = () => {\r\n\t\tthis.hasToBeStarted()\r\n\t\tthis.onUpdateShownItemIndexes({ reason: LAYOUT_REASON.MANUAL })\r\n\t}\r\n\r\n\t// Bind the function to `this` so that it could be passed as a callback\r\n\t// in a random application's code.\r\n\tonRender = () => {\r\n\t\tthis._onRender(this.getState(), this.previousState)\r\n\t}\r\n\r\n\t/**\r\n\t * Returns the items's top offset relative to the scrollable container's top edge.\r\n\t * @param {number} i — Item index\r\n\t * @return {[number]} Returns the item's scroll Y position. Returns `undefined` if any of the previous items haven't been rendered yet.\r\n\t */\r\n\tgetItemScrollPosition(i) {\r\n\t\tconst itemTopOffsetInList = this.layout.getItemTopOffset(i)\r\n\t\tif (itemTopOffsetInList === undefined) {\r\n\t\t\treturn\r\n\t\t}\r\n\t\treturn this.getListTopOffsetInsideScrollableContainer() + itemTopOffsetInList\r\n\t}\r\n\r\n\t/**\r\n\t * Forces a re-measure of an item's height.\r\n\t * @param {number} i — Item index\r\n\t */\r\n\tonItemHeightChange(i) {\r\n\t\tthis.hasToBeStarted()\r\n\t\tthis._onItemHeightChange(i)\r\n\t}\r\n\r\n\t/**\r\n\t * Updates an item's state in `state.itemStates[]`.\r\n\t * @param {number} i — Item index\r\n\t * @param {any} i — Item's new state\r\n\t */\r\n\tonItemStateChange(i, newItemState) {\r\n\t\tthis.hasToBeStarted()\r\n\t\tthis._onItemStateChange(i, newItemState)\r\n\t}\r\n\r\n\t/**\r\n\t * Updates `items`. For example, can prepend or append new items to the list.\r\n\t * @param {any[]} newItems\r\n\t * @param {boolean} [options.preserveScrollPositionOnPrependItems] — Set to `true` to enable \"restore scroll position after prepending items\" feature (could be useful when implementing \"Show previous items\" button).\r\n\t */\r\n\tsetItems(newItems, options = {}) {\r\n\t\tthis.hasToBeStarted()\r\n\t\treturn this._setItems(newItems, options)\r\n\t}\r\n}"],"mappings":";;;;;;;;;;;;AAAA,OAAOA,0BAAP,MAAuC,kCAAvC;AACA,SAASC,cAAT,EAAyBC,c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;MACA,KAAKuC,mBAAL,CAAyBL,CAAzB;IACA;IAED;AACD;AACA;AACA;AACA;;;;WACC,2BAAkBA,CAAlB,EAAqBM,YAArB,EAAmC;MAClC,KAAKxC,cAAL;;MACA,KAAKyC,kBAAL,CAAwBP,CAAxB,EAA2BM,YAA3B;IACA;IAED;AACD;AACA;AACA;AACA;;;;WACC,kBAASE,QAAT,EAAiC;MAAA,IAAdnD,OAAc,uEAAJ,EAAI;MAChC,KAAKS,cAAL;MACA,OAAO,KAAK2C,SAAL,CAAeD,QAAf,EAAyBnD,OAAzB,CAAP;IACA;;;;;;SArOmBH,e"}
|
|
1
|
+
{"version":3,"file":"VirtualScroller.js","names":["VirtualScrollerConstructor","hasTbodyStyles","addTbodyStyles","LAYOUT_REASON","log","VirtualScroller","getItemsContainerElement","items","options","_isActive","Error","resize","stop","scroll","listTopOffsetWatcher","isStarted","cancelLayoutTimer","hasToBeStarted","onUpdateShownItemIndexes","reason","MANUAL","_onRender","getState","previousState","call","isRestart","_usesCustomStateStorage","useDefaultStateStorage","_render","listHeightMeasurement","reset","_isResizing","undefined","_isSettingNewItems","tbody","stateUpdate","_stoppedStateUpdate","verticalSpacing","verticalSpacingStateUpdate","measureItemHeightsAndSpacing","start","scrollableContainerWidth","scrollableContainer","getWidth","newWidth","prevWidth","onResize","columnsCount","getActualColumnsCount","columnsCountFromState","STARTED","i","itemTopOffsetInList","layout","getItemTopOffset","getListTopOffsetInsideScrollableContainer","_onItemHeightChange","newItemState","_setItemState","setItemState","newItems","_setItems"],"sources":["../source/VirtualScroller.js"],"sourcesContent":["import VirtualScrollerConstructor from './VirtualScroller.constructor.js'\r\nimport { hasTbodyStyles, addTbodyStyles } from './DOM/tbody.js'\r\nimport { LAYOUT_REASON } from './Layout.js'\r\nimport log from './utility/debug.js'\r\n\r\nexport default class VirtualScroller {\r\n\t/**\r\n\t * @param {function} getItemsContainerElement — Returns the container DOM `Element`.\r\n\t * @param {any[]} items — The list of items.\r\n\t * @param {Object} [options] — See README.md.\r\n\t * @return {VirtualScroller}\r\n\t */\r\n\tconstructor(\r\n\t\tgetItemsContainerElement,\r\n\t\titems,\r\n\t\toptions = {}\r\n\t) {\r\n\t\tVirtualScrollerConstructor.call(\r\n\t\t\tthis,\r\n\t\t\tgetItemsContainerElement,\r\n\t\t\titems,\r\n\t\t\toptions\r\n\t\t)\r\n\t}\r\n\r\n\t/**\r\n\t * Should be invoked after a \"container\" DOM Element is mounted (inserted into the DOM tree).\r\n\t */\r\n\tstart() {\r\n\t\tif (this._isActive) {\r\n\t\t\tthrow new Error('[virtual-scroller] `VirtualScroller` has already been started')\r\n\t\t}\r\n\r\n\t\t// If has been stopped previously.\r\n\t\tconst isRestart = this._isActive === false\r\n\r\n\t\tif (!isRestart) {\r\n\t\t\t// If no custom state storage has been configured, use the default one.\r\n\t\t\t// Also sets the initial state.\r\n\t\t\tif (!this._usesCustomStateStorage) {\r\n\t\t\t\tthis.useDefaultStateStorage()\r\n\t\t\t}\r\n\t\t\t// If `render()` function parameter was passed,\r\n\t\t\t// perform an initial render.\r\n\t\t\tif (this._render) {\r\n\t\t\t\tthis._render(this.getState())\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tlog('~ Start ~')\r\n\r\n\t\t// `this._isActive = true` should be placed somewhere at the start of this function.\r\n\t\tthis._isActive = true\r\n\r\n\t\t// Reset `ListHeightMeasurement` just in case it has some \"leftover\" state.\r\n\t\tthis.listHeightMeasurement.reset()\r\n\r\n\t\t// Reset `_isResizing` flag just in case it has some \"leftover\" value.\r\n\t\tthis._isResizing = undefined\r\n\r\n\t\t// Reset `_isSettingNewItems` flag just in case it has some \"leftover\" value.\r\n\t\tthis._isSettingNewItems = undefined\r\n\r\n\t\t// Work around `<tbody/>` not being able to have `padding`.\r\n\t\t// https://gitlab.com/catamphetamine/virtual-scroller/-/issues/1\r\n\t\tif (this.tbody) {\r\n\t\t\tif (!hasTbodyStyles(this.getItemsContainerElement())) {\r\n\t\t\t\taddTbodyStyles(this.getItemsContainerElement())\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\t// If there was a pending state update that didn't get applied\r\n\t\t// because of stopping the `VirtualScroller`, apply that state update now.\r\n\t\t//\r\n\t\t// The pending state update won't get applied if the scrollable container width\r\n\t\t// has changed but that's ok because that state update currently could only contain:\r\n\t\t// * `scrollableContainerWidth`\r\n\t\t// * `verticalSpacing`\r\n\t\t// * `beforeResize`\r\n\t\t// All of those get rewritten in `onResize()` anyway.\r\n\t\t//\r\n\t\tlet stateUpdate = this._stoppedStateUpdate\r\n\t\tthis._stoppedStateUpdate = undefined\r\n\r\n\t\t// Reset `this.verticalSpacing` so that it re-measures it in cases when\r\n\t\t// the `VirtualScroller` was previously stopped and is now being restarted.\r\n\t\t// The rationale is that a previously captured inter-item vertical spacing\r\n\t\t// can't be \"trusted\" in a sense that the user might have resized the window\r\n\t\t// after the previous `state` has been snapshotted.\r\n\t\t// If the user has resized the window, then changing window width might have\r\n\t\t// activated different CSS `@media()` \"queries\" resulting in a potentially different\r\n\t\t// vertical spacing after the restart.\r\n\t\t// If it's not a restart then `this.verticalSpacing` is `undefined` anyway.\r\n\t\tthis.verticalSpacing = undefined\r\n\r\n\t\tconst verticalSpacingStateUpdate = this.measureItemHeightsAndSpacing()\r\n\t\tif (verticalSpacingStateUpdate) {\r\n\t\t\tstateUpdate = {\r\n\t\t\t\t...stateUpdate,\r\n\t\t\t\t...verticalSpacingStateUpdate\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tthis.resize.start()\r\n\t\tthis.scroll.start()\r\n\r\n\t\t// If `scrollableContainerWidth` hasn't been measured yet,\r\n\t\t// measure it and write it to state.\r\n\t\tif (this.getState().scrollableContainerWidth === undefined) {\r\n\t\t\tconst scrollableContainerWidth = this.scrollableContainer.getWidth()\r\n\t\t\tstateUpdate = {\r\n\t\t\t\t...stateUpdate,\r\n\t\t\t\tscrollableContainerWidth\r\n\t\t\t}\r\n\t\t} else {\r\n\t\t\t// Reset layout:\r\n\t\t\t// * If the scrollable container width has changed while stopped.\r\n\t\t\t// * If the restored state was calculated for another scrollable container width.\r\n\t\t\tconst newWidth = this.scrollableContainer.getWidth()\r\n\t\t\tconst prevWidth = this.getState().scrollableContainerWidth\r\n\t\t\tif (newWidth !== prevWidth) {\r\n\t\t\t\tlog('~ Scrollable container width changed from', prevWidth, 'to', newWidth, '~')\r\n\t\t\t\t// `stateUpdate` doesn't get passed to `this.onResize()`, and, therefore,\r\n\t\t\t\t// won't be applied. But that's ok because currently it could only contain:\r\n\t\t\t\t// * `scrollableContainerWidth`\r\n\t\t\t\t// * `verticalSpacing`\r\n\t\t\t\t// * `beforeResize`\r\n\t\t\t\t// All of those get rewritten in `onResize()` anyway.\r\n\t\t\t\treturn this.onResize()\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\t// If the `VirtualScroller` uses custom (external) state storage, then\r\n\t\t// check if the columns count has changed between calling `.getInitialState()`\r\n\t\t// and `.start()`. If it has, perform a re-layout \"from scratch\".\r\n\t\tif (this._usesCustomStateStorage) {\r\n\t\t\tconst columnsCount = this.getActualColumnsCount()\r\n\t\t\tconst columnsCountFromState = this.getState().columnsCount || 1\r\n\t\t\tif (columnsCount !== columnsCountFromState) {\r\n\t\t\t\treturn this.onResize()\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\t// Re-calculate layout and re-render the list.\r\n\t\t// Do that even if when an initial `state` parameter, containing layout values,\r\n\t\t// has been passed. The reason is that the `state` parameter can't be \"trusted\"\r\n\t\t// in a way that it could have been snapshotted for another window width and\r\n\t\t// the user might have resized their window since then.\r\n\t\tthis.onUpdateShownItemIndexes({ reason: LAYOUT_REASON.STARTED, stateUpdate })\r\n\t}\r\n\r\n\t// Could be passed as a \"callback\" parameter, so bind it to `this`.\r\n\tstop = () => {\r\n\t\tif (!this._isActive) {\r\n\t\t\tthrow new Error('[virtual-scroller] Can\\'t stop a `VirtualScroller` that hasn\\'t been started')\r\n\t\t}\r\n\r\n\t\tthis._isActive = false\r\n\r\n\t\tlog('~ Stop ~')\r\n\r\n\t\tthis.resize.stop()\r\n\t\tthis.scroll.stop()\r\n\r\n\t\t// Stop `ListTopOffsetWatcher` if it has been started.\r\n\t\t// There seems to be no need to restart `ListTopOffsetWatcher`.\r\n\t\t// It's mainly a hacky workaround for development mode anyway.\r\n\t\tif (this.listTopOffsetWatcher && this.listTopOffsetWatcher.isStarted()) {\r\n\t\t\tthis.listTopOffsetWatcher.stop()\r\n\t\t}\r\n\r\n\t\t// Cancel any scheduled layout.\r\n\t\tthis.cancelLayoutTimer({})\r\n\t}\r\n\r\n\thasToBeStarted() {\r\n\t\tif (!this._isActive) {\r\n\t\t\tthrow new Error('[virtual-scroller] `VirtualScroller` hasn\\'t been started')\r\n\t\t}\r\n\t}\r\n\r\n\t// Bind it to `this` because this function could hypothetically be passed\r\n\t// as a \"callback\" parameter.\r\n\tupdateLayout = () => {\r\n\t\tthis.hasToBeStarted()\r\n\t\tthis.onUpdateShownItemIndexes({ reason: LAYOUT_REASON.MANUAL })\r\n\t}\r\n\r\n\t// Bind the function to `this` so that it could be passed as a callback\r\n\t// in a random application's code.\r\n\tonRender = () => {\r\n\t\tthis._onRender(this.getState(), this.previousState)\r\n\t}\r\n\r\n\t/**\r\n\t * Returns the items's top offset relative to the scrollable container's top edge.\r\n\t * @param {number} i — Item index\r\n\t * @return {[number]} Returns the item's scroll Y position. Returns `undefined` if any of the previous items haven't been rendered yet.\r\n\t */\r\n\tgetItemScrollPosition(i) {\r\n\t\tconst itemTopOffsetInList = this.layout.getItemTopOffset(i)\r\n\t\tif (itemTopOffsetInList === undefined) {\r\n\t\t\treturn\r\n\t\t}\r\n\t\treturn this.getListTopOffsetInsideScrollableContainer() + itemTopOffsetInList\r\n\t}\r\n\r\n\t/**\r\n\t * Forces a re-measure of an item's height.\r\n\t * @param {number} i — Item index\r\n\t */\r\n\tonItemHeightChange(i) {\r\n\t\tthis.hasToBeStarted()\r\n\t\tthis._onItemHeightChange(i)\r\n\t}\r\n\r\n\t/**\r\n\t * Updates an item's state in `state.itemStates[]`.\r\n\t * @param {number} i — Item index\r\n\t * @param {any} i — Item's new state\r\n\t */\r\n\tsetItemState(i, newItemState) {\r\n\t\tthis.hasToBeStarted()\r\n\t\tthis._setItemState(i, newItemState)\r\n\t}\r\n\r\n\t// (deprecated)\r\n\t// Use `.setItemState()` method name instead.\r\n\tonItemStateChange(i, newItemState) {\r\n\t\tthis.setItemState(i, newItemState)\r\n\t}\r\n\r\n\t/**\r\n\t * Updates `items`. For example, can prepend or append new items to the list.\r\n\t * @param {any[]} newItems\r\n\t * @param {boolean} [options.preserveScrollPositionOnPrependItems] — Set to `true` to enable \"restore scroll position after prepending items\" feature (could be useful when implementing \"Show previous items\" button).\r\n\t */\r\n\tsetItems(newItems, options = {}) {\r\n\t\tthis.hasToBeStarted()\r\n\t\treturn this._setItems(newItems, options)\r\n\t}\r\n}"],"mappings":";;;;;;;;;;;;AAAA,OAAOA,0BAAP,MAAuC,kCAAvC;AACA,SAASC,cAAT,EAAyBC,cAAzB,QAA+C,gBAA/C;AACA,SAASC,aAAT,QAA8B,aAA9B;AACA,OAAOC,GAAP,MAAgB,oBAAhB;;IAEqBC,e;EACpB;AACD;AACA;AACA;AACA;AACA;EACC,yBACCC,wBADD,EAECC,KAFD,EAIE;IAAA;;IAAA,IADDC,OACC,uEADS,EACT;;IAAA;;IAAA,8BAwIK,YAAM;MACZ,IAAI,CAAC,KAAI,CAACC,SAAV,EAAqB;QACpB,MAAM,IAAIC,KAAJ,CAAU,8EAAV,CAAN;MACA;;MAED,KAAI,CAACD,SAAL,GAAiB,KAAjB;MAEAL,GAAG,CAAC,UAAD,CAAH;;MAEA,KAAI,CAACO,MAAL,CAAYC,IAAZ;;MACA,KAAI,CAACC,MAAL,CAAYD,IAAZ,GAVY,CAYZ;MACA;MACA;;;MACA,IAAI,KAAI,CAACE,oBAAL,IAA6B,KAAI,CAACA,oBAAL,CAA0BC,SAA1B,EAAjC,EAAwE;QACvE,KAAI,CAACD,oBAAL,C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AKH,QAAL,EAAP;QACA;MACD,CAjHM,CAmHP;MACA;MACA;MACA;MACA;;;MACA,KAAK5B,wBAAL,CAA8B;QAAEC,MAAM,EAAEhB,aAAa,CAAC+C,OAAxB;QAAiCf,WAAW,EAAXA;MAAjC,CAA9B;IACA,C,CAED;;;;WAwBA,0BAAiB;MAChB,IAAI,CAAC,KAAK1B,SAAV,EAAqB;QACpB,MAAM,IAAIC,KAAJ,CAAU,2DAAV,CAAN;MACA;IACD,C,CAED;IACA;;;;;IAYA;AACD;AACA;AACA;AACA;IACC,+BAAsByC,CAAtB,EAAyB;MACxB,IAAMC,mBAAmB,GAAG,KAAKC,MAAL,CAAYC,gBAAZ,CAA6BH,CAA7B,CAA5B;;MACA,IAAIC,mBAAmB,KAAKpB,SAA5B,EAAuC;QACtC;MACA;;MACD,OAAO,KAAKuB,yCAAL,KAAmDH,mBAA1D;IACA;IAED;AACD;AACA;AACA;;;;WACC,4BAAmBD,CAAnB,EAAsB;MACrB,KAAKlC,cAAL;;MACA,KAAKuC,mBAAL,CAAyBL,CAAzB;IACA;IAED;AACD;AACA;AACA;AACA;;;;WACC,sBAAaA,CAAb,EAAgBM,YAAhB,EAA8B;MAC7B,KAAKxC,cAAL;;MACA,KAAKyC,aAAL,CAAmBP,CAAnB,EAAsBM,YAAtB;IACA,C,CAED;IACA;;;;WACA,2BAAkBN,CAAlB,EAAqBM,YAArB,EAAmC;MAClC,KAAKE,YAAL,CAAkBR,CAAlB,EAAqBM,YAArB;IACA;IAED;AACD;AACA;AACA;AACA;;;;WACC,kBAASG,QAAT,EAAiC;MAAA,IAAdpD,OAAc,uEAAJ,EAAI;MAChC,KAAKS,cAAL;MACA,OAAO,KAAK4C,SAAL,CAAeD,QAAf,EAAyBpD,OAAzB,CAAP;IACA;;;;;;SA3OmBH,e"}
|
|
@@ -110,7 +110,7 @@ export default function () {
|
|
|
110
110
|
// or an "Expand YouTube video" button, which would result
|
|
111
111
|
// in the actual height of the list item being different
|
|
112
112
|
// from what has been initially measured in `this.itemHeights[i]`,
|
|
113
|
-
// if the developer didn't call `.
|
|
113
|
+
// if the developer didn't call `.setItemState(i, newState)` and `.onItemHeightChange(i)`.
|
|
114
114
|
|
|
115
115
|
|
|
116
116
|
if (!validateWillBeHiddenItemHeightsAreAccurate.call(this, firstShownItemIndex, lastShownItemIndex)) {
|
|
@@ -269,7 +269,7 @@ export default function () {
|
|
|
269
269
|
* or an "Expand YouTube video" button, which would result
|
|
270
270
|
* in the actual height of the list item being different
|
|
271
271
|
* from what has been initially measured in `this.itemHeights[i]`,
|
|
272
|
-
* if the developer didn't call `.
|
|
272
|
+
* if the developer didn't call `.setItemState(i, newState)` and `.onItemHeightChange(i)`.
|
|
273
273
|
*/
|
|
274
274
|
|
|
275
275
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"VirtualScroller.layout.js","names":["setTimeout","clearTimeout","log","warn","isDebug","reportError","LAYOUT_REASON","onUpdateShownItemIndexes","reason","stateUpdate","skip","updateState","newItemsWillBeRendered","widthHasChanged","_isResizing","getItemsCount","scroll","cancelScheduledLayout","cancelLayoutTimer","updateShownItemIndexes","call","startedAt","Date","now","getShownItemIndexes","firstShownItemIndex","lastShownItemIndex","shownItemsHeight","firstNonMeasuredItemIndex","listHeightMeasurement","hasSnapshot","getAnchorItemIndex","undefined","validateWillBeHiddenItemHeightsAreAccurate","beforeItemsHeight","layout","getBeforeItemsHeight","afterItemsHeight","getAfterItemsHeight","layoutDuration","bypass","SLOW_LAYOUT_DURATION","getColumnsCount","itemHeights","getAverage","getState","slice","itemStates","onBeforeShowItems","items","previouslyCalculatedLayout","getVisibleArea","visibleArea","getVisibleAreaBounds","latestLayoutVisibleArea","listTopOffsetInsideScrollableContainer","getListTopOffsetInsideScrollableContainer","top","bottom","itemsCount","visibleAreaTop","visibleAreaBottom","isVisible","itemsContainer","getHeight","getNonVisibleListShownItemIndexes","isValid","i","previouslyMeasuredItemHeight","actualItemHeight","remeasureItemHeight","updatePreviouslyCalculatedLayoutOnItemHeightChange","previousHeight","newHeight","heightDifference","listTopOffset","scrollableContainer","getItemsContainerTopOffset","listTopOffsetWatcher","onListTopOffset","_onItemHeightChange","ITEM_HEIGHT_CHANGED","itemHeightsThatChangedWhileNewItemsWereBeingRendered","String","getPrerenderMargin","renderAheadMarginRatio","onItemInitialRender","measureItemHeightsAndSpacing","measureItemHeights","verticalSpacing","measureVerticalSpacingIfNotMeasured","layoutTimer","layoutTimerStateUpdate","scheduleLayoutTimer"],"sources":["../source/VirtualScroller.layout.js"],"sourcesContent":["// For some weird reason, in Chrome, `setTimeout()` would lag up to a second (or more) behind.\r\n// Turns out, Chrome developers have deprecated `setTimeout()` API entirely without asking anyone.\r\n// Replacing `setTimeout()` with `requestAnimationFrame()` can work around that Chrome bug.\r\n// https://github.com/bvaughn/react-virtualized/issues/722\r\nimport { setTimeout, clearTimeout } from 'request-animation-frame-timeout'\r\n\r\nimport log, { warn, isDebug, reportError } from './utility/debug.js'\r\nimport { LAYOUT_REASON } from './Layout.js'\r\n\r\nexport default function() {\r\n\tthis.onUpdateShownItemIndexes = ({ reason, stateUpdate }) => {\r\n\t\t// In case of \"don't do anything\".\r\n\t\tconst skip = () => {\r\n\t\t\tif (stateUpdate) {\r\n\t\t\t\tthis.updateState(stateUpdate)\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\t// If new `items` have been set and are waiting to be applied,\r\n\t\t// or if the viewport width has changed requiring a re-layout,\r\n\t\t// then temporarily stop all other updates like \"on scroll\" updates.\r\n\t\t// This prevents `state` being inconsistent, because, for example,\r\n\t\t// both `setItems()` and this function could update `VirtualScroller` state\r\n\t\t// and having them operate in parallel could result in incorrectly calculated\r\n\t\t// `beforeItemsHeight` / `afterItemsHeight` / `firstShownItemIndex` /\r\n\t\t// `lastShownItemIndex`, because, when operating in parallel, this function\r\n\t\t// would have different `items` than the `setItems()` function, so their\r\n\t\t// results could diverge.\r\n\t\tif (this.newItemsWillBeRendered || this.widthHasChanged || this._isResizing) {\r\n\t\t\treturn skip()\r\n\t\t}\r\n\r\n\t\t// If there're no items then there's no need to re-layout anything.\r\n\t\tif (this.getItemsCount() === 0) {\r\n\t\t\treturn skip()\r\n\t\t}\r\n\r\n\t\t// Cancel a \"re-layout when user stops scrolling\" timer.\r\n\t\tthis.scroll.cancelScheduledLayout()\r\n\r\n\t\t// Cancel a re-layout that is scheduled to run at the next \"frame\",\r\n\t\t// because a re-layout will be performed right now.\r\n\t\tstateUpdate = this.cancelLayoutTimer({ stateUpdate })\r\n\r\n\t\t// Perform a re-layout.\r\n\t\tlog(`~ Update Layout (on ${reason}) ~`)\r\n\t\tupdateShownItemIndexes.call(this, { stateUpdate })\r\n\t}\r\n\r\n\t/**\r\n\t * Updates the \"from\" and \"to\" shown item indexes.\r\n\t * If the list is visible and some of the items being shown are new\r\n\t * and are required to be measured first, then\r\n\t * `firstNonMeasuredItemIndex` is defined.\r\n\t * If the list is visible and all items being shown have been encountered\r\n\t * (and measured) before, then `firstNonMeasuredItemIndex` is `undefined`.\r\n\t *\r\n\t * The `stateUpdate` parameter is just an optional \"additional\" state update.\r\n\t */\r\n\tfunction updateShownItemIndexes({ stateUpdate }) {\r\n\t\tconst startedAt = Date.now()\r\n\r\n\t\t// Get shown item indexes.\r\n\t\tlet {\r\n\t\t\tfirstShownItemIndex,\r\n\t\t\tlastShownItemIndex,\r\n\t\t\tshownItemsHeight,\r\n\t\t\tfirstNonMeasuredItemIndex\r\n\t\t} = getShownItemIndexes.call(this)\r\n\r\n\t\t// If scroll position is scheduled to be restored after render,\r\n\t\t// then the \"anchor\" item must be rendered, and all of the prepended\r\n\t\t// items before it, all in a single pass. This way, all of the\r\n\t\t// prepended items' heights could be measured right after the render\r\n\t\t// has finished, and the scroll position can then be immediately restored.\r\n\t\tif (this.listHeightMeasurement.hasSnapshot()) {\r\n\t\t\tif (lastShownItemIndex < this.listHeightMeasurement.getAnchorItemIndex()) {\r\n\t\t\t\tlastShownItemIndex = this.listHeightMeasurement.getAnchorItemIndex()\r\n\t\t\t}\r\n\t\t\t// `firstShownItemIndex` is always `0` when prepending items.\r\n\t\t\t// And `lastShownItemIndex` always covers all prepended items in this case.\r\n\t\t\t// None of the prepended items have been rendered before,\r\n\t\t\t// so their heights are unknown. The code at the start of this function\r\n\t\t\t// did therefore set `firstNonMeasuredItemIndex` to non-`undefined`\r\n\t\t\t// in order to render just the first prepended item in order to\r\n\t\t\t// measure it, and only then make a decision on how many other\r\n\t\t\t// prepended items to render. But since we've instructed the code\r\n\t\t\t// to show all of the prepended items at once, there's no need to\r\n\t\t\t// \"redo layout after render\". Additionally, if layout was re-done\r\n\t\t\t// after render, then there would be a short interval of visual\r\n\t\t\t// \"jitter\" due to the scroll position not being restored because it'd\r\n\t\t\t// wait for the second layout to finish instead of being restored\r\n\t\t\t// right after the first one.\r\n\t\t\tfirstNonMeasuredItemIndex = undefined\r\n\t\t}\r\n\r\n\t\t// Validate the heights of items to be hidden on next render.\r\n\t\t// For example, a user could click a \"Show more\" button,\r\n\t\t// or an \"Expand YouTube video\" button, which would result\r\n\t\t// in the actual height of the list item being different\r\n\t\t// from what has been initially measured in `this.itemHeights[i]`,\r\n\t\t// if the developer didn't call `.onItemStateChange()` and `.onItemHeightChange(i)`.\r\n\t\tif (!validateWillBeHiddenItemHeightsAreAccurate.call(this, firstShownItemIndex, lastShownItemIndex)) {\r\n\t\t\tlog('~ Because some of the will-be-hidden item heights (listed above) have changed since they\\'ve last been measured, redo layout. ~')\r\n\t\t\t// Redo layout, now with the correct item heights.\r\n\t\t\treturn updateShownItemIndexes.call(this, { stateUpdate });\r\n\t\t}\r\n\r\n\t\t// Measure \"before\" items height.\r\n\t\tconst beforeItemsHeight = this.layout.getBeforeItemsHeight(\r\n\t\t\tfirstShownItemIndex\r\n\t\t)\r\n\r\n\t\t// Measure \"after\" items height.\r\n\t\tconst afterItemsHeight = this.layout.getAfterItemsHeight(\r\n\t\t\tlastShownItemIndex,\r\n\t\t\tthis.getItemsCount()\r\n\t\t)\r\n\r\n\t\tconst layoutDuration = Date.now() - startedAt\r\n\r\n\t\t// Debugging.\r\n\t\tlog('~ Calculated Layout' + (this.bypass ? ' (bypass)' : '') + ' ~')\r\n\t\tif (layoutDuration < SLOW_LAYOUT_DURATION) {\r\n\t\t\t// log('Calculated in', layoutDuration, 'ms')\r\n\t\t} else {\r\n\t\t\twarn('Layout calculated in', layoutDuration, 'ms')\r\n\t\t}\r\n\t\tif (this.getColumnsCount()) {\r\n\t\t\tlog('Columns count', this.getColumnsCount())\r\n\t\t}\r\n\t\tlog('First shown item index', firstShownItemIndex)\r\n\t\tlog('Last shown item index', lastShownItemIndex)\r\n\t\tlog('Before items height', beforeItemsHeight)\r\n\t\tlog('After items height (actual or estimated)', afterItemsHeight)\r\n\t\tlog('Average item height (used for estimated after items height calculation)', this.itemHeights.getAverage())\r\n\t\tif (isDebug()) {\r\n\t\t\tlog('Item heights', this.getState().itemHeights.slice())\r\n\t\t\tlog('Item states', this.getState().itemStates.slice())\r\n\t\t}\r\n\r\n\t\t// Optionally preload items to be rendered.\r\n\t\tthis.onBeforeShowItems(\r\n\t\t\tthis.getState().items,\r\n\t\t\tthis.getState().itemHeights,\r\n\t\t\tfirstShownItemIndex,\r\n\t\t\tlastShownItemIndex\r\n\t\t)\r\n\r\n\t\t// Set `this.firstNonMeasuredItemIndex`.\r\n\t\tthis.firstNonMeasuredItemIndex = firstNonMeasuredItemIndex\r\n\r\n\t\t// Set \"previously calculated layout\".\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\t// Currently, this feature is not used, and `shownItemsHeight` property\r\n\t\t// is not returned at all, so don't set any \"previously calculated layout\".\r\n\t\t//\r\n\t\tif (shownItemsHeight === undefined) {\r\n\t\t\tthis.previouslyCalculatedLayout = undefined\r\n\t\t} else {\r\n\t\t\t// If \"previously calculated layout\" feature would be implmeneted,\r\n\t\t\t// then this code would set \"previously calculate layout\" instance variable.\r\n\t\t\t//\r\n\t\t\t// What for would this instance variable be used?\r\n\t\t\t//\r\n\t\t\t// Instead of using a `this.previouslyCalculatedLayout` instance variable,\r\n\t\t\t// this code could use `this.getState()` because it reflects what's currently on screen,\r\n\t\t\t// but there's a single edge case when it could go out of sync —\r\n\t\t\t// updating item heights externally via `.onItemHeightChange(i)`.\r\n\t\t\t//\r\n\t\t\t// If, for example, an item height was updated externally via `.onItemHeightChange(i)`\r\n\t\t\t// then `this.getState().itemHeights` would get updated immediately but\r\n\t\t\t// `this.getState().beforeItemsHeight` or `this.getState().afterItemsHeight`\r\n\t\t\t// would still correspond to the previous item height, so those would be \"stale\".\r\n\t\t\t// On the other hand, same values in `this.previouslyCalculatedLayout` instance variable\r\n\t\t\t// can also be updated immediately, so they won't go out of sync with the updated item height.\r\n\t\t\t// That seems the only edge case when using a separate `this.previouslyCalculatedLayout`\r\n\t\t\t// instance variable instead of using `this.getState()` would theoretically be justified.\r\n\t\t\t//\r\n\t\t\tthis.previouslyCalculatedLayout = {\r\n\t\t\t\tfirstShownItemIndex,\r\n\t\t\t\tlastShownItemIndex,\r\n\t\t\t\tbeforeItemsHeight,\r\n\t\t\t\tshownItemsHeight\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\t// Update `VirtualScroller` state.\r\n\t\t// `VirtualScroller` automatically re-renders on state updates.\r\n\t\t//\r\n\t\t// All `state` properties updated here should be overwritten in\r\n\t\t// the implementation of `setItems()` and `onResize()` methods\r\n\t\t// so that the `state` is not left in an inconsistent state\r\n\t\t// whenever there're concurrent `updateState()` updates that could\r\n\t\t// possibly conflict with one another — instead, those state updates\r\n\t\t// should overwrite each other in terms of priority.\r\n\t\t// These \"on scroll\" updates have the lowest priority compared to\r\n\t\t// the state updates originating from `setItems()` and `onResize()` methods.\r\n\t\t//\r\n\t\tthis.updateState({\r\n\t\t\tfirstShownItemIndex,\r\n\t\t\tlastShownItemIndex,\r\n\t\t\tbeforeItemsHeight,\r\n\t\t\tafterItemsHeight,\r\n\t\t\t...stateUpdate\r\n\t\t})\r\n\t}\r\n\r\n\tfunction getVisibleArea() {\r\n\t\tconst visibleArea = this.scroll.getVisibleAreaBounds()\r\n\t\tthis.latestLayoutVisibleArea = visibleArea\r\n\r\n\t\t// Subtract the top offset of the list inside the scrollable container.\r\n\t\tconst listTopOffsetInsideScrollableContainer = this.getListTopOffsetInsideScrollableContainer()\r\n\t\treturn {\r\n\t\t\ttop: visibleArea.top - listTopOffsetInsideScrollableContainer,\r\n\t\t\tbottom: visibleArea.bottom - listTopOffsetInsideScrollableContainer\r\n\t\t}\r\n\t}\r\n\r\n\tfunction getShownItemIndexes() {\r\n\t\tconst itemsCount = this.getItemsCount()\r\n\r\n\t\tconst {\r\n\t\t\ttop: visibleAreaTop,\r\n\t\t\tbottom: visibleAreaBottom\r\n\t\t} = getVisibleArea.call(this)\r\n\r\n\t\tif (this.bypass) {\r\n\t\t\treturn {\r\n\t\t\t\tfirstShownItemIndex: 0,\r\n\t\t\t\tlastShownItemIndex: itemsCount - 1,\r\n\t\t\t\t// shownItemsHeight: this.getState().itemHeights.reduce((sum, itemHeight) => sum + itemHeight, 0)\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\t// Find the indexes of the items that are currently visible\r\n\t\t// (or close to being visible) in the scrollable container.\r\n\t\t// For scrollable containers other than the main screen, it could also\r\n\t\t// check the visibility of such scrollable container itself, because it\r\n\t\t// might be not visible.\r\n\t\t// If such kind of an optimization would hypothetically be implemented,\r\n\t\t// then it would also require listening for \"scroll\" events on the screen.\r\n\t\t// Overall, I suppose that such \"actual visibility\" feature would be\r\n\t\t// a very minor optimization and not something I'd deal with.\r\n\t\tconst isVisible = visibleAreaTop < this.itemsContainer.getHeight() && visibleAreaBottom > 0\r\n\t\tif (!isVisible) {\r\n\t\t\tlog('The entire list is off-screen. No items are visible.')\r\n\t\t\treturn this.layout.getNonVisibleListShownItemIndexes()\r\n\t\t}\r\n\r\n\t\t// Get shown item indexes.\r\n\t\treturn this.layout.getShownItemIndexes({\r\n\t\t\titemsCount: this.getItemsCount(),\r\n\t\t\tvisibleAreaTop,\r\n\t\t\tvisibleAreaBottom\r\n\t\t})\r\n\t}\r\n\r\n\t/**\r\n\t * Validates the heights of items to be hidden on next render.\r\n\t * For example, a user could click a \"Show more\" button,\r\n\t * or an \"Expand YouTube video\" button, which would result\r\n\t * in the actual height of the list item being different\r\n\t * from what has been initially measured in `this.itemHeights[i]`,\r\n\t * if the developer didn't call `.onItemStateChange()` and `.onItemHeightChange(i)`.\r\n\t */\r\n\tfunction validateWillBeHiddenItemHeightsAreAccurate(firstShownItemIndex, lastShownItemIndex) {\r\n\t\tlet isValid = true\r\n\t\tlet i = this.getState().firstShownItemIndex\r\n\t\twhile (i <= this.getState().lastShownItemIndex) {\r\n\t\t\tif (i >= firstShownItemIndex && i <= lastShownItemIndex) {\r\n\t\t\t\t// The item's still visible.\r\n\t\t\t} else {\r\n\t\t\t\t// The item will be hidden. Re-measure its height.\r\n\t\t\t\t// The rationale is that there could be a situation when an item's\r\n\t\t\t\t// height has changed, and the developer has properly added an\r\n\t\t\t\t// `.onItemHeightChange(i)` call to notify `VirtualScroller`\r\n\t\t\t\t// about that change, but at the same time that wouldn't work.\r\n\t\t\t\t// For example, suppose there's a list of several items on a page,\r\n\t\t\t\t// and those items are in \"minimized\" state (having height 100px).\r\n\t\t\t\t// Then, a user clicks an \"Expand all items\" button, and all items\r\n\t\t\t\t// in the list are expanded (expanded item height is gonna be 700px).\r\n\t\t\t\t// `VirtualScroller` demands that `.onItemHeightChange(i)` is called\r\n\t\t\t\t// in such cases, and the developer has properly added the code to do that.\r\n\t\t\t\t// So, if there were 10 \"minimized\" items visible on a page, then there\r\n\t\t\t\t// will be 10 individual `.onItemHeightChange(i)` calls. No issues so far.\r\n\t\t\t\t// But, as the first `.onItemHeightChange(i)` call executes, it immediately\r\n\t\t\t\t// (\"synchronously\") triggers a re-layout, and that re-layout finds out\r\n\t\t\t\t// that now, because the first item is big, it occupies most of the screen\r\n\t\t\t\t// space, and only the first 3 items are visible on screen instead of 10,\r\n\t\t\t\t// and so it leaves the first 3 items mounted and unmounts the rest 7.\r\n\t\t\t\t// Then, after `VirtualScroller` has rerendered, the code returns to\r\n\t\t\t\t// where it was executing, and calls `.onItemHeightChange(i)` for the\r\n\t\t\t\t// second item. It also triggers an immediate re-layout that finds out\r\n\t\t\t\t// that only the first 2 items are visible on screen, and it unmounts\r\n\t\t\t\t// the third one too. After that, it calls `.onItemHeightChange(i)`\r\n\t\t\t\t// for the third item, but that item is no longer rendered, so its height\r\n\t\t\t\t// can't be measured, and the same's for all the rest of the original 10 items.\r\n\t\t\t\t// So, even though the developer has written their code properly, the\r\n\t\t\t\t// `VirtualScroller` still ends up having incorrect `itemHeights[]`:\r\n\t\t\t\t// `[700px, 700px, 100px, 100px, 100px, 100px, 100px, 100px, 100px, 100px]`\r\n\t\t\t\t// while it should have been `700px` for all of them.\r\n\t\t\t\t// To work around such issues, every item's height is re-measured before it\r\n\t\t\t\t// gets hidden.\r\n\t\t\t\tconst previouslyMeasuredItemHeight = this.getState().itemHeights[i]\r\n\t\t\t\tconst actualItemHeight = remeasureItemHeight.call(this, i)\r\n\t\t\t\tif (actualItemHeight !== previouslyMeasuredItemHeight) {\r\n\t\t\t\t\tif (isValid) {\r\n\t\t\t\t\t\tlog('~ Validate will-be-hidden item heights. ~')\r\n\t\t\t\t\t\t// Update or reset previously calculated layout.\r\n\t\t\t\t\t\tupdatePreviouslyCalculatedLayoutOnItemHeightChange.call(this, i, previouslyMeasuredItemHeight, actualItemHeight)\r\n\t\t\t\t\t}\r\n\t\t\t\t\tisValid = false\r\n\t\t\t\t\twarn('Item index', i, 'is no longer visible and will be unmounted. Its height has changed from', previouslyMeasuredItemHeight, 'to', actualItemHeight, 'since it was last measured. This is not necessarily a bug, and could happen, for example, on screen width change, or when there\\'re several `onItemHeightChange(i)` calls issued at the same time, and the first one triggers a re-layout before the rest of them have had a chance to be executed.')\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\ti++\r\n\t\t}\r\n\t\treturn isValid\r\n\t}\r\n\r\n\tfunction remeasureItemHeight(i) {\r\n\t\tconst { firstShownItemIndex } = this.getState()\r\n\t\treturn this.itemHeights.remeasureItemHeight(i, firstShownItemIndex)\r\n\t}\r\n\r\n\t// Updates the snapshot of the current layout when an item's height changes.\r\n\t//\r\n\t// The \"previously calculated layout\" feature is not currently used.\r\n\t//\r\n\t// The current layout snapshot could be stored as a \"previously calculated layout\" variable\r\n\t// so that it could theoretically be used when calculating new layout incrementally\r\n\t// rather than from scratch, which would be an optimization.\r\n\t//\r\n\tfunction updatePreviouslyCalculatedLayoutOnItemHeightChange(i, previousHeight, newHeight) {\r\n\t\tif (this.previouslyCalculatedLayout) {\r\n\t\t\tconst heightDifference = newHeight - previousHeight\r\n\t\t\tif (i < this.previouslyCalculatedLayout.firstShownItemIndex) {\r\n\t\t\t\t// Patch `this.previouslyCalculatedLayout`'s `.beforeItemsHeight`.\r\n\t\t\t\tthis.previouslyCalculatedLayout.beforeItemsHeight += heightDifference\r\n\t\t\t} else if (i > this.previouslyCalculatedLayout.lastShownItemIndex) {\r\n\t\t\t\t// Could patch `.afterItemsHeight` of `this.previouslyCalculatedLayout` here,\r\n\t\t\t\t// if `.afterItemsHeight` property existed in `this.previouslyCalculatedLayout`.\r\n\t\t\t\tif (this.previouslyCalculatedLayout.afterItemsHeight !== undefined) {\r\n\t\t\t\t\tthis.previouslyCalculatedLayout.afterItemsHeight += heightDifference\r\n\t\t\t\t}\r\n\t\t\t} else {\r\n\t\t\t\t// Patch `this.previouslyCalculatedLayout`'s shown items height.\r\n\t\t\t\tthis.previouslyCalculatedLayout.shownItemsHeight += newHeight - previousHeight\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\r\n\t/**\r\n\t * Returns the list's top offset relative to the scrollable container's top edge.\r\n\t * @return {number}\r\n\t */\r\n\tthis.getListTopOffsetInsideScrollableContainer = () => {\r\n\t\tconst listTopOffset = this.scrollableContainer.getItemsContainerTopOffset()\r\n\t\tif (this.listTopOffsetWatcher) {\r\n\t\t\tthis.listTopOffsetWatcher.onListTopOffset(listTopOffset)\r\n\t\t}\r\n\t\treturn listTopOffset\r\n\t}\r\n\r\n\tthis._onItemHeightChange = (i) => {\r\n\t\tlog('~ Re-measure item height ~')\r\n\t\tlog('Item', i)\r\n\r\n\t\tconst {\r\n\t\t\titemHeights,\r\n\t\t\tfirstShownItemIndex,\r\n\t\t\tlastShownItemIndex\r\n\t\t} = this.getState()\r\n\r\n\t\t// Check if the item is still rendered.\r\n\t\tif (!(i >= firstShownItemIndex && i <= lastShownItemIndex)) {\r\n\t\t\t// There could be valid cases when an item is no longer rendered\r\n\t\t\t// by the time `.onItemHeightChange(i)` gets called.\r\n\t\t\t// For example, suppose there's a list of several items on a page,\r\n\t\t\t// and those items are in \"minimized\" state (having height 100px).\r\n\t\t\t// Then, a user clicks an \"Expand all items\" button, and all items\r\n\t\t\t// in the list are expanded (expanded item height is gonna be 700px).\r\n\t\t\t// `VirtualScroller` demands that `.onItemHeightChange(i)` is called\r\n\t\t\t// in such cases, and the developer has properly added the code to do that.\r\n\t\t\t// So, if there were 10 \"minimized\" items visible on a page, then there\r\n\t\t\t// will be 10 individual `.onItemHeightChange(i)` calls. No issues so far.\r\n\t\t\t// But, as the first `.onItemHeightChange(i)` call executes, it immediately\r\n\t\t\t// (\"synchronously\") triggers a re-layout, and that re-layout finds out\r\n\t\t\t// that now, because the first item is big, it occupies most of the screen\r\n\t\t\t// space, and only the first 3 items are visible on screen instead of 10,\r\n\t\t\t// and so it leaves the first 3 items mounted and unmounts the rest 7.\r\n\t\t\t// Then, after `VirtualScroller` has rerendered, the code returns to\r\n\t\t\t// where it was executing, and calls `.onItemHeightChange(i)` for the\r\n\t\t\t// second item. It also triggers an immediate re-layout that finds out\r\n\t\t\t// that only the first 2 items are visible on screen, and it unmounts\r\n\t\t\t// the third one too. After that, it calls `.onItemHeightChange(i)`\r\n\t\t\t// for the third item, but that item is no longer rendered, so its height\r\n\t\t\t// can't be measured, and the same's for all the rest of the original 10 items.\r\n\t\t\t// So, even though the developer has written their code properly, there're\r\n\t\t\t// still situations when the item could be no longer rendered by the time\r\n\t\t\t// `.onItemHeightChange(i)` gets called.\r\n\t\t\treturn warn('The item is no longer rendered. This is not necessarily a bug, and could happen, for example, when there\\'re several `onItemHeightChange(i)` calls issued at the same time.')\r\n\t\t}\r\n\r\n\t\tconst previousHeight = itemHeights[i]\r\n\t\tif (previousHeight === undefined) {\r\n\t\t\treturn reportError(`\"onItemHeightChange()\" has been called for item ${i}, but that item hasn't been rendered before.`)\r\n\t\t}\r\n\r\n\t\tconst newHeight = remeasureItemHeight.call(this, i)\r\n\r\n\t\tlog('Previous height', previousHeight)\r\n\t\tlog('New height', newHeight)\r\n\r\n\t\tif (previousHeight !== newHeight) {\r\n\t\t\tlog('~ Item height has changed ~')\r\n\r\n\t\t\t// Update or reset previously calculated layout.\r\n\t\t\tupdatePreviouslyCalculatedLayoutOnItemHeightChange.call(this, i, previousHeight, newHeight)\r\n\r\n\t\t\t// Recalculate layout.\r\n\t\t\tthis.onUpdateShownItemIndexes({ reason: LAYOUT_REASON.ITEM_HEIGHT_CHANGED })\r\n\r\n\t\t\t// Schedule the item height update for after the new items have been rendered.\r\n\t\t\tif (this.newItemsWillBeRendered) {\r\n\t\t\t\tif (!this.itemHeightsThatChangedWhileNewItemsWereBeingRendered) {\r\n\t\t\t\t\tthis.itemHeightsThatChangedWhileNewItemsWereBeingRendered = {}\r\n\t\t\t\t}\r\n\t\t\t\tthis.itemHeightsThatChangedWhileNewItemsWereBeingRendered[String(i)] = newHeight\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\r\n\tthis.getPrerenderMargin = () => {\r\n\t\t// The list component renders not only the items that're currently visible\r\n\t\t// but also the items that lie within some extra vertical margin (called\r\n\t\t// \"prerender margin\") on top and bottom for future scrolling: this way,\r\n\t\t// there'll be significantly less layout recalculations as the user scrolls,\r\n\t\t// because now it doesn't have to recalculate layout on each scroll event.\r\n\t\t// By default, the \"prerender margin\" is equal to the screen height:\r\n\t\t// this seems to be the optimal value for \"Page Up\" / \"Page Down\" navigation\r\n\t\t// and optimized mouse wheel scrolling (a user is unlikely to continuously\r\n\t\t// scroll past the screen height, because they'd stop to read through\r\n\t\t// the newly visible items first, and when they do stop scrolling, that's\r\n\t\t// when layout gets recalculated).\r\n\t\tconst renderAheadMarginRatio = 1 // in scrollable container heights.\r\n\t\treturn this.scrollableContainer.getHeight() * renderAheadMarginRatio\r\n\t}\r\n\r\n\t/**\r\n\t * Calls `onItemFirstRender()` for items that haven't been\r\n\t * \"seen\" previously.\r\n\t * @param {any[]} items\r\n\t * @param {number[]} itemHeights\r\n\t * @param {number} firstShownItemIndex\r\n\t * @param {number} lastShownItemIndex\r\n\t */\r\n\tthis.onBeforeShowItems = (\r\n\t\titems,\r\n\t\titemHeights,\r\n\t\tfirstShownItemIndex,\r\n\t\tlastShownItemIndex\r\n\t) => {\r\n\t\tif (this.onItemInitialRender) {\r\n\t\t\tlet i = firstShownItemIndex\r\n\t\t\twhile (i <= lastShownItemIndex) {\r\n\t\t\t\tif (itemHeights[i] === undefined) {\r\n\t\t\t\t\tthis.onItemInitialRender(items[i])\r\n\t\t\t\t}\r\n\t\t\t\ti++\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\r\n\tthis.measureItemHeightsAndSpacing = () => {\r\n\t\t// Measure \"newly shown\" item heights.\r\n\t\t// Also re-validate already measured items' heights.\r\n\t\tthis.itemHeights.measureItemHeights(\r\n\t\t\tthis.getState().firstShownItemIndex,\r\n\t\t\tthis.getState().lastShownItemIndex\r\n\t\t)\r\n\r\n\t\t// Measure item vertical spacing, if required.\r\n\t\tconst verticalSpacing = this.measureVerticalSpacingIfNotMeasured()\r\n\r\n\t\t// Return a state update if vertical spacing has been measured.\r\n\t\t// Doesn't set `verticalSpacing: 0` in `state` because it is effectively\r\n\t\t// same as `verticalSpacing: undefined` in terms code behavior and calculations.\r\n\t\t// Not having `verticalSpacing: 0` in `state` just makes the `state` object\r\n\t\t// a bit more cleaner and a bit less cluttered (easier for inspection).\r\n\t\tif (verticalSpacing && verticalSpacing !== 0) {\r\n\t\t\t// Return a state update.\r\n\t\t\t// Sets `verticalSpacing` property in `state`.\r\n\t\t\treturn {\r\n\t\t\t\tverticalSpacing\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\r\n\tthis.cancelLayoutTimer = ({ stateUpdate }) => {\r\n\t\tif (this.layoutTimer) {\r\n\t\t\tclearTimeout(this.layoutTimer)\r\n\t\t\tthis.layoutTimer = undefined\r\n\t\t\t// Merge state updates.\r\n\t\t\tif (stateUpdate || this.layoutTimerStateUpdate) {\r\n\t\t\t\tstateUpdate = {\r\n\t\t\t\t\t...this.layoutTimerStateUpdate,\r\n\t\t\t\t\t...stateUpdate\r\n\t\t\t\t}\r\n\t\t\t\tthis.layoutTimerStateUpdate = undefined\r\n\t\t\t\treturn stateUpdate\r\n\t\t\t}\r\n\t\t} else {\r\n\t\t\treturn stateUpdate\r\n\t\t}\r\n\t}\r\n\r\n\tthis.scheduleLayoutTimer = ({ reason, stateUpdate }) => {\r\n\t\tthis.layoutTimerStateUpdate = stateUpdate\r\n\t\tthis.layoutTimer = setTimeout(() => {\r\n\t\t\tthis.layoutTimerStateUpdate = undefined\r\n\t\t\tthis.layoutTimer = undefined\r\n\t\t\tthis.onUpdateShownItemIndexes({\r\n\t\t\t\treason,\r\n\t\t\t\tstateUpdate\r\n\t\t\t})\r\n\t\t}, 0)\r\n\t}\r\n}\r\n\r\nconst SLOW_LAYOUT_DURATION = 15 // in milliseconds."],"mappings":";;;;;;AAAA;AACA;AACA;AACA;AACA,SAASA,UAAT,EAAqBC,YAArB,QAAyC,iCAAzC;AAEA,OAAOC,GAAP,IAAcC,IAAd,EAAoBC,OAApB,EAA6BC,WAA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D,SAAnB,CAFqB,CAGrB;;MACA,IAAIvB,WAAW,IAAI,KAAI,CAACmF,sBAAxB,EAAgD;QAC/CnF,WAAW,mCACP,KAAI,CAACmF,sBADE,GAEPnF,WAFO,CAAX;QAIA,KAAI,CAACmF,sBAAL,GAA8B5D,SAA9B;QACA,OAAOvB,WAAP;MACA;IACD,CAZD,MAYO;MACN,OAAOA,WAAP;IACA;EACD,CAhBD;;EAkBA,KAAKoF,mBAAL,GAA2B,iBAA6B;IAAA,IAA1BrF,MAA0B,SAA1BA,MAA0B;IAAA,IAAlBC,WAAkB,SAAlBA,WAAkB;IACvD,KAAI,CAACmF,sBAAL,GAA8BnF,WAA9B;IACA,KAAI,CAACkF,WAAL,GAAmB3F,UAAU,CAAC,YAAM;MACnC,KAAI,CAAC4F,sBAAL,GAA8B5D,SAA9B;MACA,KAAI,CAAC2D,WAAL,GAAmB3D,SAAnB;;MACA,KAAI,CAACzB,wBAAL,CAA8B;QAC7BC,MAAM,EAANA,MAD6B;QAE7BC,WAAW,EAAXA;MAF6B,CAA9B;IAIA,CAP4B,EAO1B,CAP0B,CAA7B;EAQA,CAVD;AAWA;AAED,IAAMgC,oBAAoB,GAAG,EAA7B,C,CAAgC"}
|
|
1
|
+
{"version":3,"file":"VirtualScroller.layout.js","names":["setTimeout","clearTimeout","log","warn","isDebug","reportError","LAYOUT_REASON","onUpdateShownItemIndexes","reason","stateUpdate","skip","updateState","newItemsWillBeRendered","widthHasChanged","_isResizing","getItemsCount","scroll","cancelScheduledLayout","cancelLayoutTimer","updateShownItemIndexes","call","startedAt","Date","now","getShownItemIndexes","firstShownItemIndex","lastShownItemIndex","shownItemsHeight","firstNonMeasuredItemIndex","listHeightMeasurement","hasSnapshot","getAnchorItemIndex","undefined","validateWillBeHiddenItemHeightsAreAccurate","beforeItemsHeight","layout","getBeforeItemsHeight","afterItemsHeight","getAfterItemsHeight","layoutDuration","bypass","SLOW_LAYOUT_DURATION","getColumnsCount","itemHeights","getAverage","getState","slice","itemStates","onBeforeShowItems","items","previouslyCalculatedLayout","getVisibleArea","visibleArea","getVisibleAreaBounds","latestLayoutVisibleArea","listTopOffsetInsideScrollableContainer","getListTopOffsetInsideScrollableContainer","top","bottom","itemsCount","visibleAreaTop","visibleAreaBottom","isVisible","itemsContainer","getHeight","getNonVisibleListShownItemIndexes","isValid","i","previouslyMeasuredItemHeight","actualItemHeight","remeasureItemHeight","updatePreviouslyCalculatedLayoutOnItemHeightChange","previousHeight","newHeight","heightDifference","listTopOffset","scrollableContainer","getItemsContainerTopOffset","listTopOffsetWatcher","onListTopOffset","_onItemHeightChange","ITEM_HEIGHT_CHANGED","itemHeightsThatChangedWhileNewItemsWereBeingRendered","String","getPrerenderMargin","renderAheadMarginRatio","onItemInitialRender","measureItemHeightsAndSpacing","measureItemHeights","verticalSpacing","measureVerticalSpacingIfNotMeasured","layoutTimer","layoutTimerStateUpdate","scheduleLayoutTimer"],"sources":["../source/VirtualScroller.layout.js"],"sourcesContent":["// For some weird reason, in Chrome, `setTimeout()` would lag up to a second (or more) behind.\r\n// Turns out, Chrome developers have deprecated `setTimeout()` API entirely without asking anyone.\r\n// Replacing `setTimeout()` with `requestAnimationFrame()` can work around that Chrome bug.\r\n// https://github.com/bvaughn/react-virtualized/issues/722\r\nimport { setTimeout, clearTimeout } from 'request-animation-frame-timeout'\r\n\r\nimport log, { warn, isDebug, reportError } from './utility/debug.js'\r\nimport { LAYOUT_REASON } from './Layout.js'\r\n\r\nexport default function() {\r\n\tthis.onUpdateShownItemIndexes = ({ reason, stateUpdate }) => {\r\n\t\t// In case of \"don't do anything\".\r\n\t\tconst skip = () => {\r\n\t\t\tif (stateUpdate) {\r\n\t\t\t\tthis.updateState(stateUpdate)\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\t// If new `items` have been set and are waiting to be applied,\r\n\t\t// or if the viewport width has changed requiring a re-layout,\r\n\t\t// then temporarily stop all other updates like \"on scroll\" updates.\r\n\t\t// This prevents `state` being inconsistent, because, for example,\r\n\t\t// both `setItems()` and this function could update `VirtualScroller` state\r\n\t\t// and having them operate in parallel could result in incorrectly calculated\r\n\t\t// `beforeItemsHeight` / `afterItemsHeight` / `firstShownItemIndex` /\r\n\t\t// `lastShownItemIndex`, because, when operating in parallel, this function\r\n\t\t// would have different `items` than the `setItems()` function, so their\r\n\t\t// results could diverge.\r\n\t\tif (this.newItemsWillBeRendered || this.widthHasChanged || this._isResizing) {\r\n\t\t\treturn skip()\r\n\t\t}\r\n\r\n\t\t// If there're no items then there's no need to re-layout anything.\r\n\t\tif (this.getItemsCount() === 0) {\r\n\t\t\treturn skip()\r\n\t\t}\r\n\r\n\t\t// Cancel a \"re-layout when user stops scrolling\" timer.\r\n\t\tthis.scroll.cancelScheduledLayout()\r\n\r\n\t\t// Cancel a re-layout that is scheduled to run at the next \"frame\",\r\n\t\t// because a re-layout will be performed right now.\r\n\t\tstateUpdate = this.cancelLayoutTimer({ stateUpdate })\r\n\r\n\t\t// Perform a re-layout.\r\n\t\tlog(`~ Update Layout (on ${reason}) ~`)\r\n\t\tupdateShownItemIndexes.call(this, { stateUpdate })\r\n\t}\r\n\r\n\t/**\r\n\t * Updates the \"from\" and \"to\" shown item indexes.\r\n\t * If the list is visible and some of the items being shown are new\r\n\t * and are required to be measured first, then\r\n\t * `firstNonMeasuredItemIndex` is defined.\r\n\t * If the list is visible and all items being shown have been encountered\r\n\t * (and measured) before, then `firstNonMeasuredItemIndex` is `undefined`.\r\n\t *\r\n\t * The `stateUpdate` parameter is just an optional \"additional\" state update.\r\n\t */\r\n\tfunction updateShownItemIndexes({ stateUpdate }) {\r\n\t\tconst startedAt = Date.now()\r\n\r\n\t\t// Get shown item indexes.\r\n\t\tlet {\r\n\t\t\tfirstShownItemIndex,\r\n\t\t\tlastShownItemIndex,\r\n\t\t\tshownItemsHeight,\r\n\t\t\tfirstNonMeasuredItemIndex\r\n\t\t} = getShownItemIndexes.call(this)\r\n\r\n\t\t// If scroll position is scheduled to be restored after render,\r\n\t\t// then the \"anchor\" item must be rendered, and all of the prepended\r\n\t\t// items before it, all in a single pass. This way, all of the\r\n\t\t// prepended items' heights could be measured right after the render\r\n\t\t// has finished, and the scroll position can then be immediately restored.\r\n\t\tif (this.listHeightMeasurement.hasSnapshot()) {\r\n\t\t\tif (lastShownItemIndex < this.listHeightMeasurement.getAnchorItemIndex()) {\r\n\t\t\t\tlastShownItemIndex = this.listHeightMeasurement.getAnchorItemIndex()\r\n\t\t\t}\r\n\t\t\t// `firstShownItemIndex` is always `0` when prepending items.\r\n\t\t\t// And `lastShownItemIndex` always covers all prepended items in this case.\r\n\t\t\t// None of the prepended items have been rendered before,\r\n\t\t\t// so their heights are unknown. The code at the start of this function\r\n\t\t\t// did therefore set `firstNonMeasuredItemIndex` to non-`undefined`\r\n\t\t\t// in order to render just the first prepended item in order to\r\n\t\t\t// measure it, and only then make a decision on how many other\r\n\t\t\t// prepended items to render. But since we've instructed the code\r\n\t\t\t// to show all of the prepended items at once, there's no need to\r\n\t\t\t// \"redo layout after render\". Additionally, if layout was re-done\r\n\t\t\t// after render, then there would be a short interval of visual\r\n\t\t\t// \"jitter\" due to the scroll position not being restored because it'd\r\n\t\t\t// wait for the second layout to finish instead of being restored\r\n\t\t\t// right after the first one.\r\n\t\t\tfirstNonMeasuredItemIndex = undefined\r\n\t\t}\r\n\r\n\t\t// Validate the heights of items to be hidden on next render.\r\n\t\t// For example, a user could click a \"Show more\" button,\r\n\t\t// or an \"Expand YouTube video\" button, which would result\r\n\t\t// in the actual height of the list item being different\r\n\t\t// from what has been initially measured in `this.itemHeights[i]`,\r\n\t\t// if the developer didn't call `.setItemState(i, newState)` and `.onItemHeightChange(i)`.\r\n\t\tif (!validateWillBeHiddenItemHeightsAreAccurate.call(this, firstShownItemIndex, lastShownItemIndex)) {\r\n\t\t\tlog('~ Because some of the will-be-hidden item heights (listed above) have changed since they\\'ve last been measured, redo layout. ~')\r\n\t\t\t// Redo layout, now with the correct item heights.\r\n\t\t\treturn updateShownItemIndexes.call(this, { stateUpdate });\r\n\t\t}\r\n\r\n\t\t// Measure \"before\" items height.\r\n\t\tconst beforeItemsHeight = this.layout.getBeforeItemsHeight(\r\n\t\t\tfirstShownItemIndex\r\n\t\t)\r\n\r\n\t\t// Measure \"after\" items height.\r\n\t\tconst afterItemsHeight = this.layout.getAfterItemsHeight(\r\n\t\t\tlastShownItemIndex,\r\n\t\t\tthis.getItemsCount()\r\n\t\t)\r\n\r\n\t\tconst layoutDuration = Date.now() - startedAt\r\n\r\n\t\t// Debugging.\r\n\t\tlog('~ Calculated Layout' + (this.bypass ? ' (bypass)' : '') + ' ~')\r\n\t\tif (layoutDuration < SLOW_LAYOUT_DURATION) {\r\n\t\t\t// log('Calculated in', layoutDuration, 'ms')\r\n\t\t} else {\r\n\t\t\twarn('Layout calculated in', layoutDuration, 'ms')\r\n\t\t}\r\n\t\tif (this.getColumnsCount()) {\r\n\t\t\tlog('Columns count', this.getColumnsCount())\r\n\t\t}\r\n\t\tlog('First shown item index', firstShownItemIndex)\r\n\t\tlog('Last shown item index', lastShownItemIndex)\r\n\t\tlog('Before items height', beforeItemsHeight)\r\n\t\tlog('After items height (actual or estimated)', afterItemsHeight)\r\n\t\tlog('Average item height (used for estimated after items height calculation)', this.itemHeights.getAverage())\r\n\t\tif (isDebug()) {\r\n\t\t\tlog('Item heights', this.getState().itemHeights.slice())\r\n\t\t\tlog('Item states', this.getState().itemStates.slice())\r\n\t\t}\r\n\r\n\t\t// Optionally preload items to be rendered.\r\n\t\tthis.onBeforeShowItems(\r\n\t\t\tthis.getState().items,\r\n\t\t\tthis.getState().itemHeights,\r\n\t\t\tfirstShownItemIndex,\r\n\t\t\tlastShownItemIndex\r\n\t\t)\r\n\r\n\t\t// Set `this.firstNonMeasuredItemIndex`.\r\n\t\tthis.firstNonMeasuredItemIndex = firstNonMeasuredItemIndex\r\n\r\n\t\t// Set \"previously calculated layout\".\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\t// Currently, this feature is not used, and `shownItemsHeight` property\r\n\t\t// is not returned at all, so don't set any \"previously calculated layout\".\r\n\t\t//\r\n\t\tif (shownItemsHeight === undefined) {\r\n\t\t\tthis.previouslyCalculatedLayout = undefined\r\n\t\t} else {\r\n\t\t\t// If \"previously calculated layout\" feature would be implmeneted,\r\n\t\t\t// then this code would set \"previously calculate layout\" instance variable.\r\n\t\t\t//\r\n\t\t\t// What for would this instance variable be used?\r\n\t\t\t//\r\n\t\t\t// Instead of using a `this.previouslyCalculatedLayout` instance variable,\r\n\t\t\t// this code could use `this.getState()` because it reflects what's currently on screen,\r\n\t\t\t// but there's a single edge case when it could go out of sync —\r\n\t\t\t// updating item heights externally via `.onItemHeightChange(i)`.\r\n\t\t\t//\r\n\t\t\t// If, for example, an item height was updated externally via `.onItemHeightChange(i)`\r\n\t\t\t// then `this.getState().itemHeights` would get updated immediately but\r\n\t\t\t// `this.getState().beforeItemsHeight` or `this.getState().afterItemsHeight`\r\n\t\t\t// would still correspond to the previous item height, so those would be \"stale\".\r\n\t\t\t// On the other hand, same values in `this.previouslyCalculatedLayout` instance variable\r\n\t\t\t// can also be updated immediately, so they won't go out of sync with the updated item height.\r\n\t\t\t// That seems the only edge case when using a separate `this.previouslyCalculatedLayout`\r\n\t\t\t// instance variable instead of using `this.getState()` would theoretically be justified.\r\n\t\t\t//\r\n\t\t\tthis.previouslyCalculatedLayout = {\r\n\t\t\t\tfirstShownItemIndex,\r\n\t\t\t\tlastShownItemIndex,\r\n\t\t\t\tbeforeItemsHeight,\r\n\t\t\t\tshownItemsHeight\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\t// Update `VirtualScroller` state.\r\n\t\t// `VirtualScroller` automatically re-renders on state updates.\r\n\t\t//\r\n\t\t// All `state` properties updated here should be overwritten in\r\n\t\t// the implementation of `setItems()` and `onResize()` methods\r\n\t\t// so that the `state` is not left in an inconsistent state\r\n\t\t// whenever there're concurrent `updateState()` updates that could\r\n\t\t// possibly conflict with one another — instead, those state updates\r\n\t\t// should overwrite each other in terms of priority.\r\n\t\t// These \"on scroll\" updates have the lowest priority compared to\r\n\t\t// the state updates originating from `setItems()` and `onResize()` methods.\r\n\t\t//\r\n\t\tthis.updateState({\r\n\t\t\tfirstShownItemIndex,\r\n\t\t\tlastShownItemIndex,\r\n\t\t\tbeforeItemsHeight,\r\n\t\t\tafterItemsHeight,\r\n\t\t\t...stateUpdate\r\n\t\t})\r\n\t}\r\n\r\n\tfunction getVisibleArea() {\r\n\t\tconst visibleArea = this.scroll.getVisibleAreaBounds()\r\n\t\tthis.latestLayoutVisibleArea = visibleArea\r\n\r\n\t\t// Subtract the top offset of the list inside the scrollable container.\r\n\t\tconst listTopOffsetInsideScrollableContainer = this.getListTopOffsetInsideScrollableContainer()\r\n\t\treturn {\r\n\t\t\ttop: visibleArea.top - listTopOffsetInsideScrollableContainer,\r\n\t\t\tbottom: visibleArea.bottom - listTopOffsetInsideScrollableContainer\r\n\t\t}\r\n\t}\r\n\r\n\tfunction getShownItemIndexes() {\r\n\t\tconst itemsCount = this.getItemsCount()\r\n\r\n\t\tconst {\r\n\t\t\ttop: visibleAreaTop,\r\n\t\t\tbottom: visibleAreaBottom\r\n\t\t} = getVisibleArea.call(this)\r\n\r\n\t\tif (this.bypass) {\r\n\t\t\treturn {\r\n\t\t\t\tfirstShownItemIndex: 0,\r\n\t\t\t\tlastShownItemIndex: itemsCount - 1,\r\n\t\t\t\t// shownItemsHeight: this.getState().itemHeights.reduce((sum, itemHeight) => sum + itemHeight, 0)\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\t// Find the indexes of the items that are currently visible\r\n\t\t// (or close to being visible) in the scrollable container.\r\n\t\t// For scrollable containers other than the main screen, it could also\r\n\t\t// check the visibility of such scrollable container itself, because it\r\n\t\t// might be not visible.\r\n\t\t// If such kind of an optimization would hypothetically be implemented,\r\n\t\t// then it would also require listening for \"scroll\" events on the screen.\r\n\t\t// Overall, I suppose that such \"actual visibility\" feature would be\r\n\t\t// a very minor optimization and not something I'd deal with.\r\n\t\tconst isVisible = visibleAreaTop < this.itemsContainer.getHeight() && visibleAreaBottom > 0\r\n\t\tif (!isVisible) {\r\n\t\t\tlog('The entire list is off-screen. No items are visible.')\r\n\t\t\treturn this.layout.getNonVisibleListShownItemIndexes()\r\n\t\t}\r\n\r\n\t\t// Get shown item indexes.\r\n\t\treturn this.layout.getShownItemIndexes({\r\n\t\t\titemsCount: this.getItemsCount(),\r\n\t\t\tvisibleAreaTop,\r\n\t\t\tvisibleAreaBottom\r\n\t\t})\r\n\t}\r\n\r\n\t/**\r\n\t * Validates the heights of items to be hidden on next render.\r\n\t * For example, a user could click a \"Show more\" button,\r\n\t * or an \"Expand YouTube video\" button, which would result\r\n\t * in the actual height of the list item being different\r\n\t * from what has been initially measured in `this.itemHeights[i]`,\r\n\t * if the developer didn't call `.setItemState(i, newState)` and `.onItemHeightChange(i)`.\r\n\t */\r\n\tfunction validateWillBeHiddenItemHeightsAreAccurate(firstShownItemIndex, lastShownItemIndex) {\r\n\t\tlet isValid = true\r\n\t\tlet i = this.getState().firstShownItemIndex\r\n\t\twhile (i <= this.getState().lastShownItemIndex) {\r\n\t\t\tif (i >= firstShownItemIndex && i <= lastShownItemIndex) {\r\n\t\t\t\t// The item's still visible.\r\n\t\t\t} else {\r\n\t\t\t\t// The item will be hidden. Re-measure its height.\r\n\t\t\t\t// The rationale is that there could be a situation when an item's\r\n\t\t\t\t// height has changed, and the developer has properly added an\r\n\t\t\t\t// `.onItemHeightChange(i)` call to notify `VirtualScroller`\r\n\t\t\t\t// about that change, but at the same time that wouldn't work.\r\n\t\t\t\t// For example, suppose there's a list of several items on a page,\r\n\t\t\t\t// and those items are in \"minimized\" state (having height 100px).\r\n\t\t\t\t// Then, a user clicks an \"Expand all items\" button, and all items\r\n\t\t\t\t// in the list are expanded (expanded item height is gonna be 700px).\r\n\t\t\t\t// `VirtualScroller` demands that `.onItemHeightChange(i)` is called\r\n\t\t\t\t// in such cases, and the developer has properly added the code to do that.\r\n\t\t\t\t// So, if there were 10 \"minimized\" items visible on a page, then there\r\n\t\t\t\t// will be 10 individual `.onItemHeightChange(i)` calls. No issues so far.\r\n\t\t\t\t// But, as the first `.onItemHeightChange(i)` call executes, it immediately\r\n\t\t\t\t// (\"synchronously\") triggers a re-layout, and that re-layout finds out\r\n\t\t\t\t// that now, because the first item is big, it occupies most of the screen\r\n\t\t\t\t// space, and only the first 3 items are visible on screen instead of 10,\r\n\t\t\t\t// and so it leaves the first 3 items mounted and unmounts the rest 7.\r\n\t\t\t\t// Then, after `VirtualScroller` has rerendered, the code returns to\r\n\t\t\t\t// where it was executing, and calls `.onItemHeightChange(i)` for the\r\n\t\t\t\t// second item. It also triggers an immediate re-layout that finds out\r\n\t\t\t\t// that only the first 2 items are visible on screen, and it unmounts\r\n\t\t\t\t// the third one too. After that, it calls `.onItemHeightChange(i)`\r\n\t\t\t\t// for the third item, but that item is no longer rendered, so its height\r\n\t\t\t\t// can't be measured, and the same's for all the rest of the original 10 items.\r\n\t\t\t\t// So, even though the developer has written their code properly, the\r\n\t\t\t\t// `VirtualScroller` still ends up having incorrect `itemHeights[]`:\r\n\t\t\t\t// `[700px, 700px, 100px, 100px, 100px, 100px, 100px, 100px, 100px, 100px]`\r\n\t\t\t\t// while it should have been `700px` for all of them.\r\n\t\t\t\t// To work around such issues, every item's height is re-measured before it\r\n\t\t\t\t// gets hidden.\r\n\t\t\t\tconst previouslyMeasuredItemHeight = this.getState().itemHeights[i]\r\n\t\t\t\tconst actualItemHeight = remeasureItemHeight.call(this, i)\r\n\t\t\t\tif (actualItemHeight !== previouslyMeasuredItemHeight) {\r\n\t\t\t\t\tif (isValid) {\r\n\t\t\t\t\t\tlog('~ Validate will-be-hidden item heights. ~')\r\n\t\t\t\t\t\t// Update or reset previously calculated layout.\r\n\t\t\t\t\t\tupdatePreviouslyCalculatedLayoutOnItemHeightChange.call(this, i, previouslyMeasuredItemHeight, actualItemHeight)\r\n\t\t\t\t\t}\r\n\t\t\t\t\tisValid = false\r\n\t\t\t\t\twarn('Item index', i, 'is no longer visible and will be unmounted. Its height has changed from', previouslyMeasuredItemHeight, 'to', actualItemHeight, 'since it was last measured. This is not necessarily a bug, and could happen, for example, on screen width change, or when there\\'re several `onItemHeightChange(i)` calls issued at the same time, and the first one triggers a re-layout before the rest of them have had a chance to be executed.')\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\ti++\r\n\t\t}\r\n\t\treturn isValid\r\n\t}\r\n\r\n\tfunction remeasureItemHeight(i) {\r\n\t\tconst { firstShownItemIndex } = this.getState()\r\n\t\treturn this.itemHeights.remeasureItemHeight(i, firstShownItemIndex)\r\n\t}\r\n\r\n\t// Updates the snapshot of the current layout when an item's height changes.\r\n\t//\r\n\t// The \"previously calculated layout\" feature is not currently used.\r\n\t//\r\n\t// The current layout snapshot could be stored as a \"previously calculated layout\" variable\r\n\t// so that it could theoretically be used when calculating new layout incrementally\r\n\t// rather than from scratch, which would be an optimization.\r\n\t//\r\n\tfunction updatePreviouslyCalculatedLayoutOnItemHeightChange(i, previousHeight, newHeight) {\r\n\t\tif (this.previouslyCalculatedLayout) {\r\n\t\t\tconst heightDifference = newHeight - previousHeight\r\n\t\t\tif (i < this.previouslyCalculatedLayout.firstShownItemIndex) {\r\n\t\t\t\t// Patch `this.previouslyCalculatedLayout`'s `.beforeItemsHeight`.\r\n\t\t\t\tthis.previouslyCalculatedLayout.beforeItemsHeight += heightDifference\r\n\t\t\t} else if (i > this.previouslyCalculatedLayout.lastShownItemIndex) {\r\n\t\t\t\t// Could patch `.afterItemsHeight` of `this.previouslyCalculatedLayout` here,\r\n\t\t\t\t// if `.afterItemsHeight` property existed in `this.previouslyCalculatedLayout`.\r\n\t\t\t\tif (this.previouslyCalculatedLayout.afterItemsHeight !== undefined) {\r\n\t\t\t\t\tthis.previouslyCalculatedLayout.afterItemsHeight += heightDifference\r\n\t\t\t\t}\r\n\t\t\t} else {\r\n\t\t\t\t// Patch `this.previouslyCalculatedLayout`'s shown items height.\r\n\t\t\t\tthis.previouslyCalculatedLayout.shownItemsHeight += newHeight - previousHeight\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\r\n\t/**\r\n\t * Returns the list's top offset relative to the scrollable container's top edge.\r\n\t * @return {number}\r\n\t */\r\n\tthis.getListTopOffsetInsideScrollableContainer = () => {\r\n\t\tconst listTopOffset = this.scrollableContainer.getItemsContainerTopOffset()\r\n\t\tif (this.listTopOffsetWatcher) {\r\n\t\t\tthis.listTopOffsetWatcher.onListTopOffset(listTopOffset)\r\n\t\t}\r\n\t\treturn listTopOffset\r\n\t}\r\n\r\n\tthis._onItemHeightChange = (i) => {\r\n\t\tlog('~ Re-measure item height ~')\r\n\t\tlog('Item', i)\r\n\r\n\t\tconst {\r\n\t\t\titemHeights,\r\n\t\t\tfirstShownItemIndex,\r\n\t\t\tlastShownItemIndex\r\n\t\t} = this.getState()\r\n\r\n\t\t// Check if the item is still rendered.\r\n\t\tif (!(i >= firstShownItemIndex && i <= lastShownItemIndex)) {\r\n\t\t\t// There could be valid cases when an item is no longer rendered\r\n\t\t\t// by the time `.onItemHeightChange(i)` gets called.\r\n\t\t\t// For example, suppose there's a list of several items on a page,\r\n\t\t\t// and those items are in \"minimized\" state (having height 100px).\r\n\t\t\t// Then, a user clicks an \"Expand all items\" button, and all items\r\n\t\t\t// in the list are expanded (expanded item height is gonna be 700px).\r\n\t\t\t// `VirtualScroller` demands that `.onItemHeightChange(i)` is called\r\n\t\t\t// in such cases, and the developer has properly added the code to do that.\r\n\t\t\t// So, if there were 10 \"minimized\" items visible on a page, then there\r\n\t\t\t// will be 10 individual `.onItemHeightChange(i)` calls. No issues so far.\r\n\t\t\t// But, as the first `.onItemHeightChange(i)` call executes, it immediately\r\n\t\t\t// (\"synchronously\") triggers a re-layout, and that re-layout finds out\r\n\t\t\t// that now, because the first item is big, it occupies most of the screen\r\n\t\t\t// space, and only the first 3 items are visible on screen instead of 10,\r\n\t\t\t// and so it leaves the first 3 items mounted and unmounts the rest 7.\r\n\t\t\t// Then, after `VirtualScroller` has rerendered, the code returns to\r\n\t\t\t// where it was executing, and calls `.onItemHeightChange(i)` for the\r\n\t\t\t// second item. It also triggers an immediate re-layout that finds out\r\n\t\t\t// that only the first 2 items are visible on screen, and it unmounts\r\n\t\t\t// the third one too. After that, it calls `.onItemHeightChange(i)`\r\n\t\t\t// for the third item, but that item is no longer rendered, so its height\r\n\t\t\t// can't be measured, and the same's for all the rest of the original 10 items.\r\n\t\t\t// So, even though the developer has written their code properly, there're\r\n\t\t\t// still situations when the item could be no longer rendered by the time\r\n\t\t\t// `.onItemHeightChange(i)` gets called.\r\n\t\t\treturn warn('The item is no longer rendered. This is not necessarily a bug, and could happen, for example, when there\\'re several `onItemHeightChange(i)` calls issued at the same time.')\r\n\t\t}\r\n\r\n\t\tconst previousHeight = itemHeights[i]\r\n\t\tif (previousHeight === undefined) {\r\n\t\t\treturn reportError(`\"onItemHeightChange()\" has been called for item ${i}, but that item hasn't been rendered before.`)\r\n\t\t}\r\n\r\n\t\tconst newHeight = remeasureItemHeight.call(this, i)\r\n\r\n\t\tlog('Previous height', previousHeight)\r\n\t\tlog('New height', newHeight)\r\n\r\n\t\tif (previousHeight !== newHeight) {\r\n\t\t\tlog('~ Item height has changed ~')\r\n\r\n\t\t\t// Update or reset previously calculated layout.\r\n\t\t\tupdatePreviouslyCalculatedLayoutOnItemHeightChange.call(this, i, previousHeight, newHeight)\r\n\r\n\t\t\t// Recalculate layout.\r\n\t\t\tthis.onUpdateShownItemIndexes({ reason: LAYOUT_REASON.ITEM_HEIGHT_CHANGED })\r\n\r\n\t\t\t// Schedule the item height update for after the new items have been rendered.\r\n\t\t\tif (this.newItemsWillBeRendered) {\r\n\t\t\t\tif (!this.itemHeightsThatChangedWhileNewItemsWereBeingRendered) {\r\n\t\t\t\t\tthis.itemHeightsThatChangedWhileNewItemsWereBeingRendered = {}\r\n\t\t\t\t}\r\n\t\t\t\tthis.itemHeightsThatChangedWhileNewItemsWereBeingRendered[String(i)] = newHeight\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\r\n\tthis.getPrerenderMargin = () => {\r\n\t\t// The list component renders not only the items that're currently visible\r\n\t\t// but also the items that lie within some extra vertical margin (called\r\n\t\t// \"prerender margin\") on top and bottom for future scrolling: this way,\r\n\t\t// there'll be significantly less layout recalculations as the user scrolls,\r\n\t\t// because now it doesn't have to recalculate layout on each scroll event.\r\n\t\t// By default, the \"prerender margin\" is equal to the screen height:\r\n\t\t// this seems to be the optimal value for \"Page Up\" / \"Page Down\" navigation\r\n\t\t// and optimized mouse wheel scrolling (a user is unlikely to continuously\r\n\t\t// scroll past the screen height, because they'd stop to read through\r\n\t\t// the newly visible items first, and when they do stop scrolling, that's\r\n\t\t// when layout gets recalculated).\r\n\t\tconst renderAheadMarginRatio = 1 // in scrollable container heights.\r\n\t\treturn this.scrollableContainer.getHeight() * renderAheadMarginRatio\r\n\t}\r\n\r\n\t/**\r\n\t * Calls `onItemFirstRender()` for items that haven't been\r\n\t * \"seen\" previously.\r\n\t * @param {any[]} items\r\n\t * @param {number[]} itemHeights\r\n\t * @param {number} firstShownItemIndex\r\n\t * @param {number} lastShownItemIndex\r\n\t */\r\n\tthis.onBeforeShowItems = (\r\n\t\titems,\r\n\t\titemHeights,\r\n\t\tfirstShownItemIndex,\r\n\t\tlastShownItemIndex\r\n\t) => {\r\n\t\tif (this.onItemInitialRender) {\r\n\t\t\tlet i = firstShownItemIndex\r\n\t\t\twhile (i <= lastShownItemIndex) {\r\n\t\t\t\tif (itemHeights[i] === undefined) {\r\n\t\t\t\t\tthis.onItemInitialRender(items[i])\r\n\t\t\t\t}\r\n\t\t\t\ti++\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\r\n\tthis.measureItemHeightsAndSpacing = () => {\r\n\t\t// Measure \"newly shown\" item heights.\r\n\t\t// Also re-validate already measured items' heights.\r\n\t\tthis.itemHeights.measureItemHeights(\r\n\t\t\tthis.getState().firstShownItemIndex,\r\n\t\t\tthis.getState().lastShownItemIndex\r\n\t\t)\r\n\r\n\t\t// Measure item vertical spacing, if required.\r\n\t\tconst verticalSpacing = this.measureVerticalSpacingIfNotMeasured()\r\n\r\n\t\t// Return a state update if vertical spacing has been measured.\r\n\t\t// Doesn't set `verticalSpacing: 0` in `state` because it is effectively\r\n\t\t// same as `verticalSpacing: undefined` in terms code behavior and calculations.\r\n\t\t// Not having `verticalSpacing: 0` in `state` just makes the `state` object\r\n\t\t// a bit more cleaner and a bit less cluttered (easier for inspection).\r\n\t\tif (verticalSpacing && verticalSpacing !== 0) {\r\n\t\t\t// Return a state update.\r\n\t\t\t// Sets `verticalSpacing` property in `state`.\r\n\t\t\treturn {\r\n\t\t\t\tverticalSpacing\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\r\n\tthis.cancelLayoutTimer = ({ stateUpdate }) => {\r\n\t\tif (this.layoutTimer) {\r\n\t\t\tclearTimeout(this.layoutTimer)\r\n\t\t\tthis.layoutTimer = undefined\r\n\t\t\t// Merge state updates.\r\n\t\t\tif (stateUpdate || this.layoutTimerStateUpdate) {\r\n\t\t\t\tstateUpdate = {\r\n\t\t\t\t\t...this.layoutTimerStateUpdate,\r\n\t\t\t\t\t...stateUpdate\r\n\t\t\t\t}\r\n\t\t\t\tthis.layoutTimerStateUpdate = undefined\r\n\t\t\t\treturn stateUpdate\r\n\t\t\t}\r\n\t\t} else {\r\n\t\t\treturn stateUpdate\r\n\t\t}\r\n\t}\r\n\r\n\tthis.scheduleLayoutTimer = ({ reason, stateUpdate }) => {\r\n\t\tthis.layoutTimerStateUpdate = stateUpdate\r\n\t\tthis.layoutTimer = setTimeout(() => {\r\n\t\t\tthis.layoutTimerStateUpdate = undefined\r\n\t\t\tthis.layoutTimer = undefined\r\n\t\t\tthis.onUpdateShownItemIndexes({\r\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C7C;MACA;MACA,OAAO;QACNA,eAAe,EAAfA;MADM,CAAP;IAGA;EACD,CAvBD;;EAyBA,KAAKvE,iBAAL,GAAyB,iBAAqB;IAAA,IAAlBT,WAAkB,SAAlBA,WAAkB;;IAC7C,IAAI,KAAI,CAACkF,WAAT,EAAsB;MACrB1F,YAAY,CAAC,KAAI,CAAC0F,WAAN,CAAZ;MACA,KAAI,CAACA,WAAL,GAAmB3D,SAAnB,CAFqB,CAGrB;;MACA,IAAIvB,WAAW,IAAI,KAAI,CAACmF,sBAAxB,EAAgD;QAC/CnF,WAAW,mCACP,KAAI,CAACmF,sBADE,GAEPnF,WAFO,CAAX;QAIA,KAAI,CAACmF,sBAAL,GAA8B5D,SAA9B;QACA,OAAOvB,WAAP;MACA;IACD,CAZD,MAYO;MACN,OAAOA,WAAP;IACA;EACD,CAhBD;;EAkBA,KAAKoF,mBAAL,GAA2B,iBAA6B;IAAA,IAA1BrF,MAA0B,SAA1BA,MAA0B;IAAA,IAAlBC,WAAkB,SAAlBA,WAAkB;IACvD,KAAI,CAACmF,sBAAL,GAA8BnF,WAA9B;IACA,KAAI,CAACkF,WAAL,GAAmB3F,UAAU,CAAC,YAAM;MACnC,KAAI,CAAC4F,sBAAL,GAA8B5D,SAA9B;MACA,KAAI,CAAC2D,WAAL,GAAmB3D,SAAnB;;MACA,KAAI,CAACzB,wBAAL,CAA8B;QAC7BC,MAAM,EAANA,MAD6B;QAE7BC,WAAW,EAAXA;MAF6B,CAA9B;IAIA,CAP4B,EAO1B,CAP0B,CAA7B;EAQA,CAVD;AAWA;AAED,IAAMgC,oBAAoB,GAAG,EAA7B,C,CAAgC"}
|
|
@@ -4,6 +4,7 @@ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { va
|
|
|
4
4
|
|
|
5
5
|
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
6
6
|
|
|
7
|
+
import fillArray from './utility/fillArray.js';
|
|
7
8
|
import log, { warn, isDebug, reportError } from './utility/debug.js';
|
|
8
9
|
import { cleanUpBeforeResizeState } from './BeforeResize.js';
|
|
9
10
|
import getStateSnapshot from './utility/getStateSnapshot.js'; // There're three main places where state is updated:
|
|
@@ -31,14 +32,16 @@ import getStateSnapshot from './utility/getStateSnapshot.js'; // There're three
|
|
|
31
32
|
export default function createStateHelpers(_ref) {
|
|
32
33
|
var _this = this;
|
|
33
34
|
|
|
34
|
-
var
|
|
35
|
+
var initialState = _ref.state,
|
|
36
|
+
getInitialItemState = _ref.getInitialItemState,
|
|
35
37
|
onStateChange = _ref.onStateChange,
|
|
36
38
|
render = _ref.render,
|
|
37
39
|
initialItems = _ref.items;
|
|
38
40
|
this.onStateChange = onStateChange;
|
|
39
41
|
this._render = render;
|
|
42
|
+
this.getInitialItemState = getInitialItemState;
|
|
40
43
|
|
|
41
|
-
this.
|
|
44
|
+
this._setItemState = function (i, newItemState) {
|
|
42
45
|
if (isDebug()) {
|
|
43
46
|
log('~ Item state changed ~');
|
|
44
47
|
log('Item', i); // Uses `JSON.stringify()` here instead of just outputting the JSON objects as is
|
|
@@ -88,11 +91,13 @@ export default function createStateHelpers(_ref) {
|
|
|
88
91
|
};
|
|
89
92
|
|
|
90
93
|
this.getInitialState = function () {
|
|
91
|
-
if (
|
|
92
|
-
return getRestoredState.call(_this,
|
|
94
|
+
if (initialState) {
|
|
95
|
+
return getRestoredState.call(_this, initialState);
|
|
93
96
|
}
|
|
94
97
|
|
|
95
|
-
return getInitialStateFromScratch.call(_this
|
|
98
|
+
return getInitialStateFromScratch.call(_this, {
|
|
99
|
+
getInitialItemState: getInitialItemState
|
|
100
|
+
});
|
|
96
101
|
};
|
|
97
102
|
|
|
98
103
|
this.useState = function (_ref2) {
|
|
@@ -157,18 +162,22 @@ export default function createStateHelpers(_ref) {
|
|
|
157
162
|
/**
|
|
158
163
|
* Returns the initial state of the `VirtualScroller` "from scratch".
|
|
159
164
|
* (i.e. not from a previously saved one).
|
|
165
|
+
* @param {function} [options.getInitialItemState] — Gets initial item state.
|
|
160
166
|
* @return {object}
|
|
161
167
|
*/
|
|
162
168
|
|
|
163
169
|
|
|
164
|
-
function getInitialStateFromScratch() {
|
|
170
|
+
function getInitialStateFromScratch(_ref3) {
|
|
171
|
+
var getInitialItemState = _ref3.getInitialItemState;
|
|
165
172
|
var items = initialItems;
|
|
166
173
|
|
|
167
174
|
var state = _objectSpread(_objectSpread({}, getInitialLayoutState.call(this, items, {
|
|
168
175
|
beforeStart: true
|
|
169
176
|
})), {}, {
|
|
170
177
|
items: items,
|
|
171
|
-
itemStates: new Array(items.length)
|
|
178
|
+
itemStates: fillArray(new Array(items.length), function (i) {
|
|
179
|
+
return getInitialItemState(items[i]);
|
|
180
|
+
})
|
|
172
181
|
});
|
|
173
182
|
|
|
174
183
|
if (isDebug()) {
|
|
@@ -230,10 +239,10 @@ export default function createStateHelpers(_ref) {
|
|
|
230
239
|
return state;
|
|
231
240
|
}
|
|
232
241
|
|
|
233
|
-
function getInitialLayoutState(items,
|
|
242
|
+
function getInitialLayoutState(items, _ref4) {
|
|
234
243
|
var _this2 = this;
|
|
235
244
|
|
|
236
|
-
var beforeStart =
|
|
245
|
+
var beforeStart = _ref4.beforeStart;
|
|
237
246
|
var itemsCount = items.length;
|
|
238
247
|
|
|
239
248
|
var getColumnsCount = function getColumnsCount() {
|
|
@@ -277,8 +286,8 @@ export default function createStateHelpers(_ref) {
|
|
|
277
286
|
//
|
|
278
287
|
|
|
279
288
|
|
|
280
|
-
function isStateColumnsCountMismatch(state,
|
|
281
|
-
var columnsCount =
|
|
289
|
+
function isStateColumnsCountMismatch(state, _ref5) {
|
|
290
|
+
var columnsCount = _ref5.columnsCount;
|
|
282
291
|
var stateColumnsCount = state.columnsCount || 1;
|
|
283
292
|
|
|
284
293
|
if (stateColumnsCount !== columnsCount) {
|