virtual-scroller 1.15.0 → 1.15.2
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 +6 -0
- package/README.md +98 -8
- package/bundle/index-dom-bypass.html +3 -4
- package/bundle/index-dom-grid.html +3 -4
- package/bundle/index-dom-scrollableContainer.html +3 -4
- package/bundle/index-dom.html +3 -4
- package/bundle/index-react-bypass.html +56 -62
- package/bundle/index-react-grid.html +55 -61
- package/bundle/index-react-hook.html +209 -0
- package/bundle/index-react-scrollableContainer.html +56 -62
- package/bundle/index-react-strictMode.html +55 -61
- package/bundle/index-react-tbody-scrollableContainer.html +13 -15
- package/bundle/index-react-tbody.html +10 -12
- 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/VirtualScroller.constructor.js +3 -1
- package/commonjs/VirtualScroller.constructor.js.map +1 -1
- package/commonjs/VirtualScroller.items.js +19 -0
- package/commonjs/VirtualScroller.items.js.map +1 -1
- package/commonjs/react/VirtualScroller.js +69 -127
- package/commonjs/react/VirtualScroller.js.map +1 -1
- package/commonjs/react/useCreateVirtualScroller.js +64 -0
- package/commonjs/react/useCreateVirtualScroller.js.map +1 -0
- package/commonjs/react/useInstanceMethods.js +2 -2
- package/commonjs/react/useInstanceMethods.js.map +1 -1
- package/commonjs/react/useMergeRefs.js +52 -0
- package/commonjs/react/useMergeRefs.js.map +1 -0
- package/commonjs/react/{useVirtualScrollerStartStop.js → useStartStopVirtualScroller.js} +1 -1
- package/commonjs/react/{useVirtualScrollerStartStop.js.map → useStartStopVirtualScroller.js.map} +1 -1
- package/commonjs/react/useStyle.js +18 -0
- package/commonjs/react/useStyle.js.map +1 -1
- package/commonjs/react/useVirtualScroller.js +142 -43
- package/commonjs/react/useVirtualScroller.js.map +1 -1
- package/commonjs/test/VirtualScroller.js +17 -1
- package/commonjs/test/VirtualScroller.js.map +1 -1
- package/modules/VirtualScroller.constructor.js +3 -1
- package/modules/VirtualScroller.constructor.js.map +1 -1
- package/modules/VirtualScroller.items.js +19 -0
- package/modules/VirtualScroller.items.js.map +1 -1
- package/modules/react/VirtualScroller.js +68 -119
- package/modules/react/VirtualScroller.js.map +1 -1
- package/modules/react/useCreateVirtualScroller.js +53 -0
- package/modules/react/useCreateVirtualScroller.js.map +1 -0
- package/modules/react/useInstanceMethods.js +2 -2
- package/modules/react/useInstanceMethods.js.map +1 -1
- package/modules/react/useMergeRefs.js +44 -0
- package/modules/react/useMergeRefs.js.map +1 -0
- package/modules/react/{useVirtualScrollerStartStop.js → useStartStopVirtualScroller.js} +1 -1
- package/modules/react/{useVirtualScrollerStartStop.js.map → useStartStopVirtualScroller.js.map} +1 -1
- package/modules/react/useStyle.js +17 -0
- package/modules/react/useStyle.js.map +1 -1
- package/modules/react/useVirtualScroller.js +136 -43
- package/modules/react/useVirtualScroller.js.map +1 -1
- package/modules/test/VirtualScroller.js +17 -1
- package/modules/test/VirtualScroller.js.map +1 -1
- package/package.json +4 -1
- package/react/index.cjs +2 -1
- package/react/index.d.ts +51 -7
- package/react/index.js +1 -0
- package/rollup.config.mjs +15 -1
- package/source/VirtualScroller.constructor.js +3 -0
- package/source/VirtualScroller.items.js +14 -0
- package/source/react/VirtualScroller.js +66 -127
- package/source/react/useCreateVirtualScroller.js +65 -0
- package/source/react/useInstanceMethods.js +2 -2
- package/source/react/useMergeRefs.js +45 -0
- package/source/react/useStyle.js +15 -0
- package/source/react/useVirtualScroller.js +155 -48
- package/source/test/VirtualScroller.js +11 -1
- package/website/index-dom-bypass.html +3 -4
- package/website/index-dom-grid.html +3 -4
- package/website/index-dom-scrollableContainer.html +3 -4
- package/website/index-dom.html +3 -4
- package/website/index-react-bypass.html +56 -62
- package/website/index-react-grid.html +55 -61
- package/website/index-react-hook.html +209 -0
- package/website/index-react-scrollableContainer.html +56 -62
- package/website/index-react-strictMode.html +55 -61
- package/website/index-react-tbody-scrollableContainer.html +13 -15
- package/website/index-react-tbody.html +10 -12
- package/website/index-react.html +55 -61
- package/website/index.html +55 -61
- package/commonjs/react/useForwardedRef.js +0 -50
- package/commonjs/react/useForwardedRef.js.map +0 -1
- package/modules/react/useForwardedRef.js +0 -42
- package/modules/react/useForwardedRef.js.map +0 -1
- package/source/react/useForwardedRef.js +0 -39
- /package/source/react/{useVirtualScrollerStartStop.js → useStartStopVirtualScroller.js} +0 -0
|
@@ -141,7 +141,9 @@ function VirtualScrollerConstructor(getItemsContainerElement, items) {
|
|
|
141
141
|
// `.setState()` inside `componentWillUpdate()` or `componentDidUpdate()`.
|
|
142
142
|
// React limits the number of nested updates to prevent infinite loops."
|
|
143
143
|
|
|
144
|
-
this._useTimeoutInRenderLoop = _useTimeoutInRenderLoop;
|
|
144
|
+
this._useTimeoutInRenderLoop = _useTimeoutInRenderLoop; // `_getItemId()` function is used in `_getItemIndexByItemOrIndex()` function.
|
|
145
|
+
|
|
146
|
+
this._getItemId = getItemId;
|
|
145
147
|
|
|
146
148
|
if (getItemId) {
|
|
147
149
|
this.isItemEqual = function (a, b) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"VirtualScroller.constructor.js","names":["VirtualScrollerConstructor","getItemsContainerElement","items","options","bypass","render","state","getInitialItemState","onStateChange","initialScrollPosition","onScrollPositionChange","scrollableContainer","measureItemsBatchSize","getColumnsCount","getItemId","estimatedItemHeight","getEstimatedVisibleItemRowsCount","getEstimatedInterItemVerticalSpacing","onItemInitialRender","onItemFirstRender","_useTimeoutInRenderLoop","_waitForScrollingToStop","engine","getEstimatedItemHeight","getScrollableContainer","log","DOMEngine","getState","setState","Error","_bypass","isItemEqual","a","b","item","warn","i","indexOf","length","createStateHelpers","call","createVerticalSpacingHelpers","createColumnsHelpers","createLayoutHelpers","createOnRenderHelpers","createScrollableContainerResizeHelpers","createItemsHelpers","createHelpers","waitForScrollingToStop","itemHeights","readItemHeightsFromState","beforeResize","initializeFromState","itemsContainer","createItemsContainer","clear","isItemsContainerElementTableBody","tagName","isInBypassMode","createScrollableContainer","ItemHeights","container","getItemHeight","setItemHeight","height","getAverageItemHeight","averageItemHeight","DEFAULT_ITEM_HEIGHT","layout","Layout","getEstimatedVisibleItemRowsCountForInitialRender","getPrerenderMargin","getPrerenderMarginRatio","getVerticalSpacing","getVerticalSpacingBeforeResize","getColumnsCountBeforeResize","columnsCount","getItemHeightBeforeResize","getBeforeResizeItemsCount","getMaxVisibleAreaHeight","getHeight","getPreviouslyCalculatedLayout","previouslyCalculatedLayout","scrollableContainerResizeHandler","ScrollableContainerResizeHandler","getWidth","listenForResize","listener","onResize","onResizeStart","_isResizing","onResizeStop","undefined","onNoChange","onUpdateShownItemIndexes","reason","LAYOUT_REASON","VIEWPORT_SIZE_UNCHANGED","onHeightChange","VIEWPORT_HEIGHT_CHANGED","onWidthChange","prevWidth","newWidth","onContainerResize","scroll","Scroll","onScroll","delayed","STOPPED_SCROLLING","SCROLL","isImmediateLayoutScheduled","Boolean","layoutTimer","hasNonRenderedItemsAtTheTop","firstShownItemIndex","hasNonRenderedItemsAtTheBottom","lastShownItemIndex","getItemsCount","getLatestLayoutVisibleArea","latestLayoutVisibleArea","getListTopOffset","getListTopOffsetInsideScrollableContainer","listHeightMeasurement","ListHeightMeasurement","watchListTopOffset","listTopOffsetWatcher","onListTopOffsetChange","TOP_OFFSET_CHANGED","BeforeResize"],"sources":["../source/VirtualScroller.constructor.js"],"sourcesContent":["import DOMEngine from './DOM/Engine.js'\r\n\r\nimport Layout, { LAYOUT_REASON } from './Layout.js'\r\nimport { DEFAULT_ITEM_HEIGHT } from './Layout.defaults.js'\r\nimport ScrollableContainerResizeHandler from './ScrollableContainerResizeHandler.js'\r\nimport BeforeResize from './BeforeResize.js'\r\nimport Scroll from './Scroll.js'\r\nimport ListHeightMeasurement from './ListHeightMeasurement.js'\r\nimport ItemHeights from './ItemHeights.js'\r\n\r\nimport log, { warn } from './utility/debug.js'\r\n\r\nimport createStateHelpers from './VirtualScroller.state.js'\r\nimport createVerticalSpacingHelpers from './VirtualScroller.verticalSpacing.js'\r\nimport createColumnsHelpers from './VirtualScroller.columns.js'\r\nimport createLayoutHelpers from './VirtualScroller.layout.js'\r\nimport createOnRenderHelpers from './VirtualScroller.onRender.js'\r\nimport createScrollableContainerResizeHelpers from './VirtualScroller.onContainerResize.js'\r\nimport createItemsHelpers from './VirtualScroller.items.js'\r\n\r\n/**\r\n * @param {function} getItemsContainerElement — Returns the container DOM `Element`.\r\n * @param {any[]} items — The list of items.\r\n * @param {Object} [options] — See README.md.\r\n * @return {VirtualScroller}\r\n */\r\nexport default function VirtualScrollerConstructor(\r\n\tgetItemsContainerElement,\r\n\titems,\r\n\toptions = {}\r\n) {\r\n\tconst {\r\n\t\tbypass,\r\n\t\trender,\r\n\t\tstate,\r\n\t\tgetInitialItemState = () => {},\r\n\t\tonStateChange,\r\n\t\tinitialScrollPosition,\r\n\t\tonScrollPositionChange,\r\n\t\t// `scrollableContainer` option is deprecated.\r\n\t\t// Use `getScrollableContainer()` option instead.\r\n\t\tscrollableContainer,\r\n\t\tmeasureItemsBatchSize = 50,\r\n\t\tgetColumnsCount,\r\n\t\tgetItemId,\r\n\t\t// `estimatedItemHeight` is deprecated, use `getEstimatedItemHeight()` instead.\r\n\t\testimatedItemHeight,\r\n\t\tgetEstimatedVisibleItemRowsCount,\r\n\t\tgetEstimatedInterItemVerticalSpacing,\r\n\t\tonItemInitialRender,\r\n\t\t// `onItemFirstRender(i)` is deprecated, use `onItemInitialRender(item)` instead.\r\n\t\tonItemFirstRender,\r\n\t\t_useTimeoutInRenderLoop,\r\n\t\t_waitForScrollingToStop,\r\n\t\tengine\r\n\t} = options\r\n\r\n\tlet {\r\n\t\tgetEstimatedItemHeight,\r\n\t\tgetScrollableContainer\r\n\t} = options\r\n\r\n\tlog('~ Initialize ~')\r\n\r\n\t// Could support non-DOM rendering engines.\r\n\t// For example, React Native, `<canvas/>`, etc.\r\n\tthis.engine = engine || DOMEngine\r\n\r\n\tif (!getEstimatedItemHeight && typeof estimatedItemHeight === 'number') {\r\n\t\tgetEstimatedItemHeight = () => estimatedItemHeight\r\n\t}\r\n\r\n\t// `scrollableContainer` option is deprecated.\r\n\t// Use `getScrollableContainer()` option instead.\r\n\tif (!getScrollableContainer && scrollableContainer) {\r\n\t\tgetScrollableContainer = () => scrollableContainer\r\n\t}\r\n\r\n\t// Sometimes, when `new VirtualScroller()` instance is created,\r\n\t// `getItemsContainerElement()` might not be ready to return the \"container\" DOM Element yet\r\n\t// (for example, because it's not rendered yet). That's the reason why it's a getter function.\r\n\t// For example, in React `<VirtualScroller/>` component, a `VirtualScroller`\r\n\t// instance is created in the React component's `constructor()`, and at that time\r\n\t// the container Element is not yet available. The container Element is available\r\n\t// in `componentDidMount()`, but `componentDidMount()` is not executed on server,\r\n\t// which would mean that React `<VirtualScroller/>` wouldn't render at all\r\n\t// on server side, while with the `getItemsContainerElement()` approach, on server side,\r\n\t// it still \"renders\" a list with a predefined amount of items in it by default.\r\n\t// (`initiallyRenderedItemsCount`, or `1`).\r\n\tthis.getItemsContainerElement = getItemsContainerElement\r\n\r\n\t// if (prerenderMargin === undefined) {\r\n\t// \t// Renders items which are outside of the screen by this \"prerender margin\".\r\n\t// \t// Is the screen height by default: seems to be the optimal value\r\n\t// \t// for \"Page Up\" / \"Page Down\" navigation and optimized mouse wheel scrolling.\r\n\t// \tprerenderMargin = this.scrollableContainer ? this.scrollableContainer.getHeight() : 0\r\n\t// }\r\n\r\n\tif (options.getState || options.setState) {\r\n\t\tthrow new Error('[virtual-scroller] `getState`/`setState` options usage has changed in the new version. See the readme for more details.')\r\n\t}\r\n\r\n\tif (bypass) {\r\n\t\tlog('~ \"bypass\" mode ~')\r\n\t}\r\n\r\n\t// In `bypass` mode, `VirtualScroller` doesn't wait\r\n\t// for the user to scroll down to render all items:\r\n\t// instead, it renders all items right away, as if\r\n\t// the list is rendered without using `VirtualScroller`.\r\n\t// It was added just to measure how much is the\r\n\t// performance difference between using a `VirtualScroller`\r\n\t// and not using a `VirtualScroller`.\r\n\t// It turned out that unmounting large React component trees\r\n\t// is a very long process, so `VirtualScroller` does seem to\r\n\t// make sense when used in a React application.\r\n\tthis._bypass = bypass\r\n\t// this.bypassBatchSize = bypassBatchSize || 10\r\n\r\n\t// Using `setTimeout()` in render loop is a workaround\r\n\t// for avoiding a React error message:\r\n\t// \"Maximum update depth exceeded.\r\n\t// This can happen when a component repeatedly calls\r\n\t// `.setState()` inside `componentWillUpdate()` or `componentDidUpdate()`.\r\n\t// React limits the number of nested updates to prevent infinite loops.\"\r\n\tthis._useTimeoutInRenderLoop = _useTimeoutInRenderLoop\r\n\r\n\tif (getItemId) {\r\n\t\tthis.isItemEqual = (a, b) => getItemId(a) === getItemId(b)\r\n\t} else {\r\n\t\tthis.isItemEqual = (a, b) => a === b\r\n\t}\r\n\r\n\tif (onItemInitialRender) {\r\n\t\tthis.onItemInitialRender = onItemInitialRender\r\n\t}\r\n\t// `onItemFirstRender(i)` is deprecated, use `onItemInitialRender(item)` instead.\r\n\telse if (onItemFirstRender) {\r\n\t\tthis.onItemInitialRender = (item) => {\r\n\t\t\twarn('`onItemFirstRender(i)` is deprecated, use `onItemInitialRender(item)` instead.')\r\n\t\t\tconst { items } = this.getState()\r\n\t\t\tconst i = items.indexOf(item)\r\n\t\t\t// The `item` could also be non-found due to the inconsistency bug:\r\n\t\t\t// The reason is that `i` can be non-consistent with the `items`\r\n\t\t\t// passed to `<VirtualScroller/>` in React due to `updateState()` not being\r\n\t\t\t// instanteneous: when new `items` are passed to `<VirtualScroller/>`,\r\n\t\t\t// `VirtualScroller.updateState({ items })` is called, and if `onItemFirstRender(i)`\r\n\t\t\t// is called after the aforementioned `updateState()` is called but before it finishes,\r\n\t\t\t// `i` would point to an index in \"previous\" `items` while the application\r\n\t\t\t// would assume that `i` points to an index in the \"new\" `items`,\r\n\t\t\t// resulting in an incorrect item being assumed by the application\r\n\t\t\t// or even in an \"array index out of bounds\" error.\r\n\t\t\tif (i >= 0) {\r\n\t\t\t\tonItemFirstRender(i)\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\r\n\t// If initial `state` is passed then use `items` from `state`\r\n\t// instead of the `items` argument.\r\n\tif (state) {\r\n\t\titems = state.items\r\n\t}\r\n\r\n\tlog('Items count', items.length)\r\n\tif (getEstimatedItemHeight) {\r\n\t\tlog('Estimated item height', getEstimatedItemHeight())\r\n\t}\r\n\r\n\tcreateStateHelpers.call(this, { state, getInitialItemState, onStateChange, render, items })\r\n\r\n\tcreateVerticalSpacingHelpers.call(this, { getEstimatedInterItemVerticalSpacing })\r\n\tcreateColumnsHelpers.call(this, { getColumnsCount })\r\n\r\n\tcreateLayoutHelpers.call(this)\r\n\tcreateOnRenderHelpers.call(this)\r\n\tcreateScrollableContainerResizeHelpers.call(this)\r\n\tcreateItemsHelpers.call(this)\r\n\r\n\tcreateHelpers.call(this, {\r\n\t\tgetScrollableContainer,\r\n\t\tgetEstimatedItemHeight,\r\n\t\tgetEstimatedVisibleItemRowsCount,\r\n\t\tmeasureItemsBatchSize,\r\n\t\tinitialScrollPosition,\r\n\t\tonScrollPositionChange,\r\n\t\twaitForScrollingToStop: _waitForScrollingToStop\r\n\t})\r\n\r\n\tif (state) {\r\n\t\t// Initialize `ItemHeights` from previously measured `state.itemHeights`.\r\n\t\tthis.itemHeights.readItemHeightsFromState(state)\r\n\r\n\t\t// Initialize some `BeforeResize` internal flags from a previously saved state.\r\n\t\tthis.beforeResize.initializeFromState(state)\r\n\t}\r\n}\r\n\r\nfunction createHelpers({\r\n\tgetScrollableContainer,\r\n\tgetEstimatedItemHeight,\r\n\tgetEstimatedVisibleItemRowsCount,\r\n\tmeasureItemsBatchSize,\r\n\tinitialScrollPosition,\r\n\tonScrollPositionChange,\r\n\twaitForScrollingToStop\r\n}) {\r\n\tthis.itemsContainer = this.engine.createItemsContainer(\r\n\t\tthis.getItemsContainerElement\r\n\t)\r\n\r\n\t// If the items \"container\" element is mounted at this stage,\r\n\t// remove any accidental text nodes from it (like whitespace).\r\n\t//\r\n\t// Also, this guards against cases when someone accidentally tries\r\n\t// using `VirtualScroller` on a non-empty element.\r\n\t//\r\n\tif (this.getItemsContainerElement()) {\r\n\t\tthis.itemsContainer.clear()\r\n\t}\r\n\r\n\tthis.isItemsContainerElementTableBody = () => {\r\n\t\treturn this.engine === DOMEngine &&\r\n\t\t\tthis.getItemsContainerElement().tagName === 'TBODY'\r\n\t}\r\n\r\n\tthis.isInBypassMode = () => this._bypass\r\n\r\n\tthis.scrollableContainer = this.engine.createScrollableContainer(\r\n\t\tgetScrollableContainer,\r\n\t\tthis.getItemsContainerElement\r\n\t)\r\n\r\n\t// Create `ItemHeights` instance.\r\n\tthis.itemHeights = new ItemHeights({\r\n\t\tcontainer: this.itemsContainer,\r\n\t\tgetItemHeight: (i) => this.getState().itemHeights[i],\r\n\t\tsetItemHeight: (i, height) => this.getState().itemHeights[i] = height\r\n\t})\r\n\r\n\tthis.getAverageItemHeight = () => {\r\n\t\tconst averageItemHeight = this.itemHeights.getAverageItemHeight()\r\n\t\tif (typeof averageItemHeight === 'number') {\r\n\t\t\treturn averageItemHeight\r\n\t\t}\r\n\t\treturn this.getEstimatedItemHeight()\r\n\t}\r\n\r\n\tthis.getEstimatedItemHeight = () => {\r\n\t\tif (getEstimatedItemHeight) {\r\n\t\t\tconst estimatedItemHeight = getEstimatedItemHeight()\r\n\t\t\tif (typeof estimatedItemHeight === 'number') {\r\n\t\t\t\treturn estimatedItemHeight\r\n\t\t\t}\r\n\t\t\tthrow new Error('[virtual-scroller] `getEstimatedItemHeight()` must return a number')\r\n\t\t}\r\n\t\t// `DEFAULT_ITEM_HEIGHT` will be used in server-side render\r\n\t\t// unless `getEstimatedItemHeight()` parameter is specified.\r\n\t\treturn DEFAULT_ITEM_HEIGHT\r\n\t}\r\n\r\n\tthis.layout = new Layout({\r\n\t\tisInBypassMode: this.isInBypassMode,\r\n\t\tgetEstimatedVisibleItemRowsCountForInitialRender: getEstimatedVisibleItemRowsCount,\r\n\t\tmeasureItemsBatchSize,\r\n\t\tgetPrerenderMargin: () => this.getPrerenderMargin(),\r\n\t\tgetPrerenderMarginRatio: () => this.getPrerenderMarginRatio(),\r\n\t\tgetVerticalSpacing: () => this.getVerticalSpacing(),\r\n\t\tgetVerticalSpacingBeforeResize: () => this.getVerticalSpacingBeforeResize(),\r\n\t\tgetColumnsCount: () => this.getColumnsCount(),\r\n\t\tgetColumnsCountBeforeResize: () => this.getState().beforeResize && this.getState().beforeResize.columnsCount,\r\n\t\tgetItemHeight: (i) => this.getState().itemHeights[i],\r\n\t\tgetItemHeightBeforeResize: (i) => this.getState().beforeResize && this.getState().beforeResize.itemHeights[i],\r\n\t\tgetBeforeResizeItemsCount: () => this.getState().beforeResize ? this.getState().beforeResize.itemHeights.length : 0,\r\n\t\tgetAverageItemHeight: () => this.getAverageItemHeight(),\r\n\t\t// `this.scrollableContainer` is gonna be `undefined` during server-side rendering.\r\n\t\t// https://gitlab.com/catamphetamine/virtual-scroller/-/issues/30\r\n\t\tgetMaxVisibleAreaHeight: () => this.scrollableContainer && this.scrollableContainer.getHeight(),\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\tgetPreviouslyCalculatedLayout: () => this.previouslyCalculatedLayout\r\n\t})\r\n\r\n\tthis.scrollableContainerResizeHandler = new ScrollableContainerResizeHandler({\r\n\t\tisInBypassMode: this.isInBypassMode,\r\n\t\tgetWidth: () => this.scrollableContainer.getWidth(),\r\n\t\tgetHeight: () => this.scrollableContainer.getHeight(),\r\n\t\tlistenForResize: (listener) => this.scrollableContainer.onResize(listener),\r\n\t\tonResizeStart: () => {\r\n\t\t\tlog('~ Scrollable container resize started ~')\r\n\t\t\tthis._isResizing = true\r\n\t\t},\r\n\t\tonResizeStop: () => {\r\n\t\t\tlog('~ Scrollable container resize finished ~')\r\n\t\t\tthis._isResizing = undefined\r\n\t\t},\r\n\t\tonNoChange: () => {\r\n\t\t\t// There might have been some missed `this.onUpdateShownItemIndexes()` calls\r\n\t\t\t// due to setting `this._isResizing` flag to `true` during the resize.\r\n\t\t\t// So, update shown item indexes just in case.\r\n\t\t\tthis.onUpdateShownItemIndexes({\r\n\t\t\t\treason: LAYOUT_REASON.VIEWPORT_SIZE_UNCHANGED\r\n\t\t\t})\r\n\t\t},\r\n\t\tonHeightChange: () => this.onUpdateShownItemIndexes({\r\n\t\t\treason: LAYOUT_REASON.VIEWPORT_HEIGHT_CHANGED\r\n\t\t}),\r\n\t\tonWidthChange: (prevWidth, newWidth) => {\r\n\t\t\tlog('~ Scrollable container width changed from', prevWidth, 'to', newWidth, '~')\r\n\t\t\tthis.onContainerResize()\r\n\t\t}\r\n\t})\r\n\r\n\tthis.scroll = new Scroll({\r\n\t\tisInBypassMode: this.isInBypassMode,\r\n\t\tscrollableContainer: this.scrollableContainer,\r\n\t\titemsContainer: this.itemsContainer,\r\n\t\twaitForScrollingToStop,\r\n\t\tonScroll: ({ delayed } = {}) => {\r\n\t\t\tthis.onUpdateShownItemIndexes({\r\n\t\t\t\treason: delayed ? LAYOUT_REASON.STOPPED_SCROLLING : LAYOUT_REASON.SCROLL\r\n\t\t\t})\r\n\t\t},\r\n\t\tinitialScrollPosition,\r\n\t\tonScrollPositionChange,\r\n\t\tisImmediateLayoutScheduled: () => Boolean(this.layoutTimer),\r\n\t\thasNonRenderedItemsAtTheTop: () => this.getState().firstShownItemIndex > 0,\r\n\t\thasNonRenderedItemsAtTheBottom: () => this.getState().lastShownItemIndex < this.getItemsCount() - 1,\r\n\t\tgetLatestLayoutVisibleArea: () => this.latestLayoutVisibleArea,\r\n\t\tgetListTopOffset: this.getListTopOffsetInsideScrollableContainer,\r\n\t\tgetPrerenderMargin: () => this.getPrerenderMargin()\r\n\t})\r\n\r\n\tthis.listHeightMeasurement = new ListHeightMeasurement({\r\n\t\titemsContainer: this.itemsContainer,\r\n\t\tgetListTopOffset: this.getListTopOffsetInsideScrollableContainer\r\n\t})\r\n\r\n\tif (this.engine.watchListTopOffset) {\r\n\t\tthis.listTopOffsetWatcher = this.engine.watchListTopOffset({\r\n\t\t\tgetListTopOffset: this.getListTopOffsetInsideScrollableContainer,\r\n\t\t\tonListTopOffsetChange: ({ reason }) => this.onUpdateShownItemIndexes({\r\n\t\t\t\treason: LAYOUT_REASON.TOP_OFFSET_CHANGED\r\n\t\t\t})\r\n\t\t})\r\n\t}\r\n\r\n\tthis.beforeResize = new BeforeResize({\r\n\t\tgetState: this.getState,\r\n\t\tgetVerticalSpacing: this.getVerticalSpacing,\r\n\t\tgetColumnsCount: this.getColumnsCount\r\n\t})\r\n}"],"mappings":";;;;;;;;;AAAA;;AAEA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AAEA;;AAEA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;;;;;;;AAEA;AACA;AACA;AACA;AACA;AACA;AACe,SAASA,0BAAT,CACdC,wBADc,EAEdC,KAFc,EAIb;EAAA;;EAAA,IADDC,OACC,uEADS,EACT;EACD,IACCC,MADD,GAwBID,OAxBJ,CACCC,MADD;EAAA,IAECC,MAFD,GAwBIF,OAxBJ,CAECE,MAFD;EAAA,IAGCC,KAHD,GAwBIH,OAxBJ,CAGCG,KAHD;EAAA,4BAwBIH,OAxBJ,CAICI,mBAJD;EAAA,IAICA,mBAJD,sCAIuB,YAAM,CAAE,CAJ/B;EAAA,IAKCC,aALD,GAwBIL,OAxBJ,CAKCK,aALD;EAAA,IAMCC,qBAND,GAwBIN,OAxBJ,CAMCM,qBAND;EAAA,IAOCC,sBAPD,GAwBIP,OAxBJ,CAOCO,sBAPD;EAAA,IAUCC,mBAVD,GAwB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I,CAACC,aAAL,KAAuB,CAAlE;IAAA,CAdR;IAexBC,0BAA0B,EAAE;MAAA,OAAM,MAAI,CAACC,uBAAX;IAAA,CAfJ;IAgBxBC,gBAAgB,EAAE,KAAKC,yCAhBC;IAiBxBlD,kBAAkB,EAAE;MAAA,OAAM,MAAI,CAACA,kBAAL,EAAN;IAAA;EAjBI,CAAX,CAAd;EAoBA,KAAKmD,qBAAL,GAA6B,IAAIC,iCAAJ,CAA0B;IACtDtE,cAAc,EAAE,KAAKA,cADiC;IAEtDmE,gBAAgB,EAAE,KAAKC;EAF+B,CAA1B,CAA7B;;EAKA,IAAI,KAAKnG,MAAL,CAAYsG,kBAAhB,EAAoC;IACnC,KAAKC,oBAAL,GAA4B,KAAKvG,MAAL,CAAYsG,kBAAZ,CAA+B;MAC1DJ,gBAAgB,EAAE,KAAKC,yCADmC;MAE1DK,qBAAqB,EAAE;QAAA,IAAG/B,MAAH,SAAGA,MAAH;QAAA,OAAgB,MAAI,CAACD,wBAAL,CAA8B;UACpEC,MAAM,EAAEC,qBAAA,CAAc+B;QAD8C,CAA9B,CAAhB;MAAA;IAFmC,CAA/B,CAA5B;EAMA;;EAED,KAAK5E,YAAL,GAAoB,IAAI6E,wBAAJ,CAAiB;IACpCrG,QAAQ,EAAE,KAAKA,QADqB;IAEpC8C,kBAAkB,EAAE,KAAKA,kBAFW;IAGpC5D,eAAe,EAAE,KAAKA;EAHc,CAAjB,CAApB;AAKA"}
|
|
1
|
+
{"version":3,"file":"VirtualScroller.constructor.js","names":["VirtualScrollerConstructor","getItemsContainerElement","items","options","bypass","render","state","getInitialItemState","onStateChange","initialScrollPosition","onScrollPositionChange","scrollableContainer","measureItemsBatchSize","getColumnsCount","getItemId","estimatedItemHeight","getEstimatedVisibleItemRowsCount","getEstimatedInterItemVerticalSpacing","onItemInitialRender","onItemFirstRender","_useTimeoutInRenderLoop","_waitForScrollingToStop","engine","getEstimatedItemHeight","getScrollableContainer","log","DOMEngine","getState","setState","Error","_bypass","_getItemId","isItemEqual","a","b","item","warn","i","indexOf","length","createStateHelpers","call","createVerticalSpacingHelpers","createColumnsHelpers","createLayoutHelpers","createOnRenderHelpers","createScrollableContainerResizeHelpers","createItemsHelpers","createHelpers","waitForScrollingToStop","itemHeights","readItemHeightsFromState","beforeResize","initializeFromState","itemsContainer","createItemsContainer","clear","isItemsContainerElementTableBody","tagName","isInBypassMode","createScrollableContainer","ItemHeights","container","getItemHeight","setItemHeight","height","getAverageItemHeight","averageItemHeight","DEFAULT_ITEM_HEIGHT","layout","Layout","getEstimatedVisibleItemRowsCountForInitialRender","getPrerenderMargin","getPrerenderMarginRatio","getVerticalSpacing","getVerticalSpacingBeforeResize","getColumnsCountBeforeResize","columnsCount","getItemHeightBeforeResize","getBeforeResizeItemsCount","getMaxVisibleAreaHeight","getHeight","getPreviouslyCalculatedLayout","previouslyCalculatedLayout","scrollableContainerResizeHandler","ScrollableContainerResizeHandler","getWidth","listenForResize","listener","onResize","onResizeStart","_isResizing","onResizeStop","undefined","onNoChange","onUpdateShownItemIndexes","reason","LAYOUT_REASON","VIEWPORT_SIZE_UNCHANGED","onHeightChange","VIEWPORT_HEIGHT_CHANGED","onWidthChange","prevWidth","newWidth","onContainerResize","scroll","Scroll","onScroll","delayed","STOPPED_SCROLLING","SCROLL","isImmediateLayoutScheduled","Boolean","layoutTimer","hasNonRenderedItemsAtTheTop","firstShownItemIndex","hasNonRenderedItemsAtTheBottom","lastShownItemIndex","getItemsCount","getLatestLayoutVisibleArea","latestLayoutVisibleArea","getListTopOffset","getListTopOffsetInsideScrollableContainer","listHeightMeasurement","ListHeightMeasurement","watchListTopOffset","listTopOffsetWatcher","onListTopOffsetChange","TOP_OFFSET_CHANGED","BeforeResize"],"sources":["../source/VirtualScroller.constructor.js"],"sourcesContent":["import DOMEngine from './DOM/Engine.js'\r\n\r\nimport Layout, { LAYOUT_REASON } from './Layout.js'\r\nimport { DEFAULT_ITEM_HEIGHT } from './Layout.defaults.js'\r\nimport ScrollableContainerResizeHandler from './ScrollableContainerResizeHandler.js'\r\nimport BeforeResize from './BeforeResize.js'\r\nimport Scroll from './Scroll.js'\r\nimport ListHeightMeasurement from './ListHeightMeasurement.js'\r\nimport ItemHeights from './ItemHeights.js'\r\n\r\nimport log, { warn } from './utility/debug.js'\r\n\r\nimport createStateHelpers from './VirtualScroller.state.js'\r\nimport createVerticalSpacingHelpers from './VirtualScroller.verticalSpacing.js'\r\nimport createColumnsHelpers from './VirtualScroller.columns.js'\r\nimport createLayoutHelpers from './VirtualScroller.layout.js'\r\nimport createOnRenderHelpers from './VirtualScroller.onRender.js'\r\nimport createScrollableContainerResizeHelpers from './VirtualScroller.onContainerResize.js'\r\nimport createItemsHelpers from './VirtualScroller.items.js'\r\n\r\n/**\r\n * @param {function} getItemsContainerElement — Returns the container DOM `Element`.\r\n * @param {any[]} items — The list of items.\r\n * @param {Object} [options] — See README.md.\r\n * @return {VirtualScroller}\r\n */\r\nexport default function VirtualScrollerConstructor(\r\n\tgetItemsContainerElement,\r\n\titems,\r\n\toptions = {}\r\n) {\r\n\tconst {\r\n\t\tbypass,\r\n\t\trender,\r\n\t\tstate,\r\n\t\tgetInitialItemState = () => {},\r\n\t\tonStateChange,\r\n\t\tinitialScrollPosition,\r\n\t\tonScrollPositionChange,\r\n\t\t// `scrollableContainer` option is deprecated.\r\n\t\t// Use `getScrollableContainer()` option instead.\r\n\t\tscrollableContainer,\r\n\t\tmeasureItemsBatchSize = 50,\r\n\t\tgetColumnsCount,\r\n\t\tgetItemId,\r\n\t\t// `estimatedItemHeight` is deprecated, use `getEstimatedItemHeight()` instead.\r\n\t\testimatedItemHeight,\r\n\t\tgetEstimatedVisibleItemRowsCount,\r\n\t\tgetEstimatedInterItemVerticalSpacing,\r\n\t\tonItemInitialRender,\r\n\t\t// `onItemFirstRender(i)` is deprecated, use `onItemInitialRender(item)` instead.\r\n\t\tonItemFirstRender,\r\n\t\t_useTimeoutInRenderLoop,\r\n\t\t_waitForScrollingToStop,\r\n\t\tengine\r\n\t} = options\r\n\r\n\tlet {\r\n\t\tgetEstimatedItemHeight,\r\n\t\tgetScrollableContainer\r\n\t} = options\r\n\r\n\tlog('~ Initialize ~')\r\n\r\n\t// Could support non-DOM rendering engines.\r\n\t// For example, React Native, `<canvas/>`, etc.\r\n\tthis.engine = engine || DOMEngine\r\n\r\n\tif (!getEstimatedItemHeight && typeof estimatedItemHeight === 'number') {\r\n\t\tgetEstimatedItemHeight = () => estimatedItemHeight\r\n\t}\r\n\r\n\t// `scrollableContainer` option is deprecated.\r\n\t// Use `getScrollableContainer()` option instead.\r\n\tif (!getScrollableContainer && scrollableContainer) {\r\n\t\tgetScrollableContainer = () => scrollableContainer\r\n\t}\r\n\r\n\t// Sometimes, when `new VirtualScroller()` instance is created,\r\n\t// `getItemsContainerElement()` might not be ready to return the \"container\" DOM Element yet\r\n\t// (for example, because it's not rendered yet). That's the reason why it's a getter function.\r\n\t// For example, in React `<VirtualScroller/>` component, a `VirtualScroller`\r\n\t// instance is created in the React component's `constructor()`, and at that time\r\n\t// the container Element is not yet available. The container Element is available\r\n\t// in `componentDidMount()`, but `componentDidMount()` is not executed on server,\r\n\t// which would mean that React `<VirtualScroller/>` wouldn't render at all\r\n\t// on server side, while with the `getItemsContainerElement()` approach, on server side,\r\n\t// it still \"renders\" a list with a predefined amount of items in it by default.\r\n\t// (`initiallyRenderedItemsCount`, or `1`).\r\n\tthis.getItemsContainerElement = getItemsContainerElement\r\n\r\n\t// if (prerenderMargin === undefined) {\r\n\t// \t// Renders items which are outside of the screen by this \"prerender margin\".\r\n\t// \t// Is the screen height by default: seems to be the optimal value\r\n\t// \t// for \"Page Up\" / \"Page Down\" navigation and optimized mouse wheel scrolling.\r\n\t// \tprerenderMargin = this.scrollableContainer ? this.scrollableContainer.getHeight() : 0\r\n\t// }\r\n\r\n\tif (options.getState || options.setState) {\r\n\t\tthrow new Error('[virtual-scroller] `getState`/`setState` options usage has changed in the new version. See the readme for more details.')\r\n\t}\r\n\r\n\tif (bypass) {\r\n\t\tlog('~ \"bypass\" mode ~')\r\n\t}\r\n\r\n\t// In `bypass` mode, `VirtualScroller` doesn't wait\r\n\t// for the user to scroll down to render all items:\r\n\t// instead, it renders all items right away, as if\r\n\t// the list is rendered without using `VirtualScroller`.\r\n\t// It was added just to measure how much is the\r\n\t// performance difference between using a `VirtualScroller`\r\n\t// and not using a `VirtualScroller`.\r\n\t// It turned out that unmounting large React component trees\r\n\t// is a very long process, so `VirtualScroller` does seem to\r\n\t// make sense when used in a React application.\r\n\tthis._bypass = bypass\r\n\t// this.bypassBatchSize = bypassBatchSize || 10\r\n\r\n\t// Using `setTimeout()` in render loop is a workaround\r\n\t// for avoiding a React error message:\r\n\t// \"Maximum update depth exceeded.\r\n\t// This can happen when a component repeatedly calls\r\n\t// `.setState()` inside `componentWillUpdate()` or `componentDidUpdate()`.\r\n\t// React limits the number of nested updates to prevent infinite loops.\"\r\n\tthis._useTimeoutInRenderLoop = _useTimeoutInRenderLoop\r\n\r\n\t// `_getItemId()` function is used in `_getItemIndexByItemOrIndex()` function.\r\n\tthis._getItemId = getItemId\r\n\r\n\tif (getItemId) {\r\n\t\tthis.isItemEqual = (a, b) => getItemId(a) === getItemId(b)\r\n\t} else {\r\n\t\tthis.isItemEqual = (a, b) => a === b\r\n\t}\r\n\r\n\tif (onItemInitialRender) {\r\n\t\tthis.onItemInitialRender = onItemInitialRender\r\n\t}\r\n\t// `onItemFirstRender(i)` is deprecated, use `onItemInitialRender(item)` instead.\r\n\telse if (onItemFirstRender) {\r\n\t\tthis.onItemInitialRender = (item) => {\r\n\t\t\twarn('`onItemFirstRender(i)` is deprecated, use `onItemInitialRender(item)` instead.')\r\n\t\t\tconst { items } = this.getState()\r\n\t\t\tconst i = items.indexOf(item)\r\n\t\t\t// The `item` could also be non-found due to the inconsistency bug:\r\n\t\t\t// The reason is that `i` can be non-consistent with the `items`\r\n\t\t\t// passed to `<VirtualScroller/>` in React due to `updateState()` not being\r\n\t\t\t// instanteneous: when new `items` are passed to `<VirtualScroller/>`,\r\n\t\t\t// `VirtualScroller.updateState({ items })` is called, and if `onItemFirstRender(i)`\r\n\t\t\t// is called after the aforementioned `updateState()` is called but before it finishes,\r\n\t\t\t// `i` would point to an index in \"previous\" `items` while the application\r\n\t\t\t// would assume that `i` points to an index in the \"new\" `items`,\r\n\t\t\t// resulting in an incorrect item being assumed by the application\r\n\t\t\t// or even in an \"array index out of bounds\" error.\r\n\t\t\tif (i >= 0) {\r\n\t\t\t\tonItemFirstRender(i)\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\r\n\t// If initial `state` is passed then use `items` from `state`\r\n\t// instead of the `items` argument.\r\n\tif (state) {\r\n\t\titems = state.items\r\n\t}\r\n\r\n\tlog('Items count', items.length)\r\n\tif (getEstimatedItemHeight) {\r\n\t\tlog('Estimated item height', getEstimatedItemHeight())\r\n\t}\r\n\r\n\tcreateStateHelpers.call(this, { state, getInitialItemState, onStateChange, render, items })\r\n\r\n\tcreateVerticalSpacingHelpers.call(this, { getEstimatedInterItemVerticalSpacing })\r\n\tcreateColumnsHelpers.call(this, { getColumnsCount })\r\n\r\n\tcreateLayoutHelpers.call(this)\r\n\tcreateOnRenderHelpers.call(this)\r\n\tcreateScrollableContainerResizeHelpers.call(this)\r\n\tcreateItemsHelpers.call(this)\r\n\r\n\tcreateHelpers.call(this, {\r\n\t\tgetScrollableContainer,\r\n\t\tgetEstimatedItemHeight,\r\n\t\tgetEstimatedVisibleItemRowsCount,\r\n\t\tmeasureItemsBatchSize,\r\n\t\tinitialScrollPosition,\r\n\t\tonScrollPositionChange,\r\n\t\twaitForScrollingToStop: _waitForScrollingToStop\r\n\t})\r\n\r\n\tif (state) {\r\n\t\t// Initialize `ItemHeights` from previously measured `state.itemHeights`.\r\n\t\tthis.itemHeights.readItemHeightsFromState(state)\r\n\r\n\t\t// Initialize some `BeforeResize` internal flags from a previously saved state.\r\n\t\tthis.beforeResize.initializeFromState(state)\r\n\t}\r\n}\r\n\r\nfunction createHelpers({\r\n\tgetScrollableContainer,\r\n\tgetEstimatedItemHeight,\r\n\tgetEstimatedVisibleItemRowsCount,\r\n\tmeasureItemsBatchSize,\r\n\tinitialScrollPosition,\r\n\tonScrollPositionChange,\r\n\twaitForScrollingToStop\r\n}) {\r\n\tthis.itemsContainer = this.engine.createItemsContainer(\r\n\t\tthis.getItemsContainerElement\r\n\t)\r\n\r\n\t// If the items \"container\" element is mounted at this stage,\r\n\t// remove any accidental text nodes from it (like whitespace).\r\n\t//\r\n\t// Also, this guards against cases when someone accidentally tries\r\n\t// using `VirtualScroller` on a non-empty element.\r\n\t//\r\n\tif (this.getItemsContainerElement()) {\r\n\t\tthis.itemsContainer.clear()\r\n\t}\r\n\r\n\tthis.isItemsContainerElementTableBody = () => {\r\n\t\treturn this.engine === DOMEngine &&\r\n\t\t\tthis.getItemsContainerElement().tagName === 'TBODY'\r\n\t}\r\n\r\n\tthis.isInBypassMode = () => this._bypass\r\n\r\n\tthis.scrollableContainer = this.engine.createScrollableContainer(\r\n\t\tgetScrollableContainer,\r\n\t\tthis.getItemsContainerElement\r\n\t)\r\n\r\n\t// Create `ItemHeights` instance.\r\n\tthis.itemHeights = new ItemHeights({\r\n\t\tcontainer: this.itemsContainer,\r\n\t\tgetItemHeight: (i) => this.getState().itemHeights[i],\r\n\t\tsetItemHeight: (i, height) => this.getState().itemHeights[i] = height\r\n\t})\r\n\r\n\tthis.getAverageItemHeight = () => {\r\n\t\tconst averageItemHeight = this.itemHeights.getAverageItemHeight()\r\n\t\tif (typeof averageItemHeight === 'number') {\r\n\t\t\treturn averageItemHeight\r\n\t\t}\r\n\t\treturn this.getEstimatedItemHeight()\r\n\t}\r\n\r\n\tthis.getEstimatedItemHeight = () => {\r\n\t\tif (getEstimatedItemHeight) {\r\n\t\t\tconst estimatedItemHeight = getEstimatedItemHeight()\r\n\t\t\tif (typeof estimatedItemHeight === 'number') {\r\n\t\t\t\treturn estimatedItemHeight\r\n\t\t\t}\r\n\t\t\tthrow new Error('[virtual-scroller] `getEstimatedItemHeight()` must return a number')\r\n\t\t}\r\n\t\t// `DEFAULT_ITEM_HEIGHT` will be used in server-side render\r\n\t\t// unless `getEstimatedItemHeight()` parameter is specified.\r\n\t\treturn DEFAULT_ITEM_HEIGHT\r\n\t}\r\n\r\n\tthis.layout = new Layout({\r\n\t\tisInBypassMode: this.isInBypassMode,\r\n\t\tgetEstimatedVisibleItemRowsCountForInitialRender: getEstimatedVisibleItemRowsCount,\r\n\t\tmeasureItemsBatchSize,\r\n\t\tgetPrerenderMargin: () => this.getPrerenderMargin(),\r\n\t\tgetPrerenderMarginRatio: () => this.getPrerenderMarginRatio(),\r\n\t\tgetVerticalSpacing: () => this.getVerticalSpacing(),\r\n\t\tgetVerticalSpacingBeforeResize: () => this.getVerticalSpacingBeforeResize(),\r\n\t\tgetColumnsCount: () => this.getColumnsCount(),\r\n\t\tgetColumnsCountBeforeResize: () => this.getState().beforeResize && this.getState().beforeResize.columnsCount,\r\n\t\tgetItemHeight: (i) => this.getState().itemHeights[i],\r\n\t\tgetItemHeightBeforeResize: (i) => this.getState().beforeResize && this.getState().beforeResize.itemHeights[i],\r\n\t\tgetBeforeResizeItemsCount: () => this.getState().beforeResize ? this.getState().beforeResize.itemHeights.length : 0,\r\n\t\tgetAverageItemHeight: () => this.getAverageItemHeight(),\r\n\t\t// `this.scrollableContainer` is gonna be `undefined` during server-side rendering.\r\n\t\t// https://gitlab.com/catamphetamine/virtual-scroller/-/issues/30\r\n\t\tgetMaxVisibleAreaHeight: () => this.scrollableContainer && this.scrollableContainer.getHeight(),\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\tgetPreviouslyCalculatedLayout: () => this.previouslyCalculatedLayout\r\n\t})\r\n\r\n\tthis.scrollableContainerResizeHandler = new ScrollableContainerResizeHandler({\r\n\t\tisInBypassMode: this.isInBypassMode,\r\n\t\tgetWidth: () => this.scrollableContainer.getWidth(),\r\n\t\tgetHeight: () => this.scrollableContainer.getHeight(),\r\n\t\tlistenForResize: (listener) => this.scrollableContainer.onResize(listener),\r\n\t\tonResizeStart: () => {\r\n\t\t\tlog('~ Scrollable container resize started ~')\r\n\t\t\tthis._isResizing = true\r\n\t\t},\r\n\t\tonResizeStop: () => {\r\n\t\t\tlog('~ Scrollable container resize finished ~')\r\n\t\t\tthis._isResizing = undefined\r\n\t\t},\r\n\t\tonNoChange: () => {\r\n\t\t\t// There might have been some missed `this.onUpdateShownItemIndexes()` calls\r\n\t\t\t// due to setting `this._isResizing` flag to `true` during the resize.\r\n\t\t\t// So, update shown item indexes just in case.\r\n\t\t\tthis.onUpdateShownItemIndexes({\r\n\t\t\t\treason: LAYOUT_REASON.VIEWPORT_SIZE_UNCHANGED\r\n\t\t\t})\r\n\t\t},\r\n\t\tonHeightChange: () => this.onUpdateShownItemIndexes({\r\n\t\t\treason: LAYOUT_REASON.VIEWPORT_HEIGHT_CHANGED\r\n\t\t}),\r\n\t\tonWidthChange: (prevWidth, newWidth) => {\r\n\t\t\tlog('~ Scrollable container width changed from', prevWidth, 'to', newWidth, '~')\r\n\t\t\tthis.onContainerResize()\r\n\t\t}\r\n\t})\r\n\r\n\tthis.scroll = new Scroll({\r\n\t\tisInBypassMode: this.isInBypassMode,\r\n\t\tscrollableContainer: this.scrollableContainer,\r\n\t\titemsContainer: this.itemsContainer,\r\n\t\twaitForScrollingToStop,\r\n\t\tonScroll: ({ delayed } = {}) => {\r\n\t\t\tthis.onUpdateShownItemIndexes({\r\n\t\t\t\treason: delayed ? LAYOUT_REASON.STOPPED_SCROLLING : LAYOUT_REASON.SCROLL\r\n\t\t\t})\r\n\t\t},\r\n\t\tinitialScrollPosition,\r\n\t\tonScrollPositionChange,\r\n\t\tisImmediateLayoutScheduled: () => Boolean(this.layoutTimer),\r\n\t\thasNonRenderedItemsAtTheTop: () => this.getState().firstShownItemIndex > 0,\r\n\t\thasNonRenderedItemsAtTheBottom: () => this.getState().lastShownItemIndex < this.getItemsCount() - 1,\r\n\t\tgetLatestLayoutVisibleArea: () => this.latestLayoutVisibleArea,\r\n\t\tgetListTopOffset: this.getListTopOffsetInsideScrollableContainer,\r\n\t\tgetPrerenderMargin: () => this.getPrerenderMargin()\r\n\t})\r\n\r\n\tthis.listHeightMeasurement = new ListHeightMeasurement({\r\n\t\titemsContainer: this.itemsContainer,\r\n\t\tgetListTopOffset: this.getListTopOffsetInsideScrollableContainer\r\n\t})\r\n\r\n\tif (this.engine.watchListTopOffset) {\r\n\t\tthis.listTopOffsetWatcher = this.engine.watchListTopOffset({\r\n\t\t\tgetListTopOffset: this.getListTopOffsetInsideScrollableContainer,\r\n\t\t\tonListTopOffsetChange: ({ reason }) => this.onUpdateShownItemIndexes({\r\n\t\t\t\treason: LAYOUT_REASON.TOP_OFFSET_CHANGED\r\n\t\t\t})\r\n\t\t})\r\n\t}\r\n\r\n\tthis.beforeResize = new BeforeResize({\r\n\t\tgetState: this.getState,\r\n\t\tgetVerticalSpacing: this.getVerticalSpacing,\r\n\t\tgetColumnsCount: this.getColumnsCount\r\n\t})\r\n}"],"mappings":";;;;;;;;;AAAA;;AAEA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AAEA;;AAEA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;;;;;;;AAEA;AACA;AACA;AACA;AACA;AACA;AACe,SAASA,0BAAT,CACdC,wBADc,EAEdC,KAFc,EAIb;EAAA;;EAAA,IADDC,OACC,uEADS,EACT;EACD,IACCC,MADD,GAwBID,OAxBJ,CACCC,MADD;EAAA,IAECC,MAFD,GAwBIF,OAxBJ,CAECE,MAFD;EAAA,IAGCC,KAHD,GAwBIH,OAxBJ,CAGCG,KAHD;EAAA,4BAwBIH,OAxBJ,CAICI,mBAJD;EAAA,IAICA,mBAJD,sCAIuB,YAAM,CAAE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|
|
76
|
+
} else {
|
|
77
|
+
// It is also possible that the `item` is stale and that items have already been updated
|
|
78
|
+
// via `.setItems()`. In that case, a developer could supply a `getItemId(item)` function
|
|
79
|
+
// in order for this library to be able to detect the items that have stayed even when
|
|
80
|
+
// their "reference" has changed. To support such case, here it has to also attempt a search
|
|
81
|
+
// for the `item` by its `id` rather than just its "reference".
|
|
82
|
+
var getItemId = _this._getItemId;
|
|
83
|
+
|
|
84
|
+
if (getItemId) {
|
|
85
|
+
var itemId = getItemId(item);
|
|
86
|
+
|
|
87
|
+
var _i2 = items.findIndex(function (item) {
|
|
88
|
+
return getItemId(item) === itemId;
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
if (_i2 >= 0) {
|
|
92
|
+
return _i2;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
76
95
|
}
|
|
77
96
|
|
|
78
97
|
(0, _debug.reportError)("Item not found: ".concat(JSON.stringify(item)));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"VirtualScroller.items.js","names":["getItemsCount","getState","items","length","_getItemIndexByItemOrIndex","itemOrIndex","item","i","indexOf","reportError","JSON","stringify","_setItems","newItems","options","previousItems","itemStates","widthHasChanged","stateUpdate","itemHeights","log","layoutUpdate","itemsUpdateInfo","itemsDiff","getItemsDiff","firstShownItemIndex","lastShownItemIndex","beforeItemsHeight","afterItemsHeight","shouldRestoreScrollPosition","preserveScrollPositionOnPrependItems","preserveScrollPosition","prependedItemsCount","appendedItemsCount","shouldResetGridLayout","layout","getLayoutUpdateForItemsDiff","itemsCount","columnsCount","getActualColumnsCount","onResetGridLayout","Array","concat","fillArray","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, { reportError } 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\tthis._getItemIndexByItemOrIndex = (itemOrIndex) => {\r\n\t\tconst item = itemOrIndex\r\n\t\tconst { items } = this.getState()\r\n\t\t// Find the `item`'s index in the `items` array.\r\n\t\t//\r\n\t\t// Performance notes:\r\n\t\t// Doing an `.indexOf()` operation on a very large array could be inefficient\r\n\t\t// because it would have to check every element of the array.\r\n\t\t// In case of any hypothetical performance-related issues,\r\n\t\t// the code could use a `new Map()` as an \"index\" for finding individual items.\r\n\t\tconst i = items.indexOf(item)\r\n\t\t// validate that the `item` exists in the `items` array.\r\n\t\tif (i >= 0) {\r\n\t\t\treturn i\r\n\t\t}\r\n\r\n\t\t// Legacy behavior: some functions used to accept an `i: number` item index as an argument.\r\n\t\t// Later the argument was changed to `item: Item`.\r\n\t\t//\r\n\t\t// The old way of passing an `i: number` argument would only result in weird application behavior\r\n\t\t// when all of the below circumstances are true, which is assumed extremely unlikely:\r\n\t\t//\r\n\t\t// BOTH use a previous version of `virtual-scroller` (ones before December 2025, with downloads count that is not very high)\r\n\t\t// AND to be used with an `items` array of type `number[]`\r\n\t\t// AND to use any of the \"advanced\" functions:\r\n // * `setItemState(i, newState)`\r\n // * `onItemHeightDidChange(i)`\r\n // * `getItemScrollPosition(i)`\r\n\t\t//\r\n\t\t// The code below handles the legacy compatibility aspect of the old type of argument\r\n\t\t// except maybe for those \"extremely unlikely\" cases in which the app is still unlikely to crash.\r\n\t\t//\r\n\t\tif (typeof itemOrIndex === 'number') {\r\n\t\t\tconst i = itemOrIndex\r\n\t\t\t// Validate the item index argument.\r\n\t\t\tif (i >= 0 && i < items.length) {\r\n\t\t\t\treturn i\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\treportError(`Item not found: ${JSON.stringify(item)}`)\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)\r\n\t\t\t\t\t.concat(itemHeights)\r\n\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 `.onContainerResize()` 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;;AACA;;AACA;;;;;;;;;;;;;;AAEe,oBAAW;EAAA;;EAC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IAAI,KAAI,CAACuC,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,CAACzC,eAAL,GACrB,KAAI,CAACA,eAAL,CAAqBC,WAArB,CAAiCwC,YADZ,GAErB,KAAI,CAACzD,QAAL,GAAgByD,YAFnB;MAGA;IACD,CAlR2C,CAoR5C;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,CApSD;;EAsSA,KAAKjC,YAAL,GAAoB,UAACT,aAAD,EAAgBF,QAAhB,EAA6B;IAChD,OAAO,IAAAW,wBAAA,EAAaT,aAAb,EAA4BF,QAA5B,EAAsC,KAAI,CAACkD,WAA3C,CAAP;EACA,CAFD;AAGA"}
|
|
1
|
+
{"version":3,"file":"VirtualScroller.items.js","names":["getItemsCount","getState","items","length","_getItemIndexByItemOrIndex","itemOrIndex","item","i","indexOf","getItemId","_getItemId","itemId","findIndex","reportError","JSON","stringify","_setItems","newItems","options","previousItems","itemStates","widthHasChanged","stateUpdate","itemHeights","log","layoutUpdate","itemsUpdateInfo","itemsDiff","getItemsDiff","firstShownItemIndex","lastShownItemIndex","beforeItemsHeight","afterItemsHeight","shouldRestoreScrollPosition","preserveScrollPositionOnPrependItems","preserveScrollPosition","prependedItemsCount","appendedItemsCount","shouldResetGridLayout","layout","getLayoutUpdateForItemsDiff","itemsCount","columnsCount","getActualColumnsCount","onResetGridLayout","Array","concat","fillArray","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, { reportError } 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\tthis._getItemIndexByItemOrIndex = (itemOrIndex) => {\r\n\t\tconst item = itemOrIndex\r\n\t\tconst { items } = this.getState()\r\n\t\t// Find the `item`'s index in the `items` array.\r\n\t\t//\r\n\t\t// Performance notes:\r\n\t\t// Doing an `.indexOf()` operation on a very large array could be inefficient\r\n\t\t// because it would have to check every element of the array.\r\n\t\t// In case of any hypothetical performance-related issues,\r\n\t\t// the code could use a `new Map()` as an \"index\" for finding individual items.\r\n\t\tconst i = items.indexOf(item)\r\n\t\t// validate that the `item` exists in the `items` array.\r\n\t\tif (i >= 0) {\r\n\t\t\treturn i\r\n\t\t}\r\n\r\n\t\t// Legacy behavior: some functions used to accept an `i: number` item index as an argument.\r\n\t\t// Later the argument was changed to `item: Item`.\r\n\t\t//\r\n\t\t// The old way of passing an `i: number` argument would only result in weird application behavior\r\n\t\t// when all of the below circumstances are true, which is assumed extremely unlikely:\r\n\t\t//\r\n\t\t// BOTH use a previous version of `virtual-scroller` (ones before December 2025, with downloads count that is not very high)\r\n\t\t// AND to be used with an `items` array of type `number[]`\r\n\t\t// AND to use any of the \"advanced\" functions:\r\n // * `setItemState(i, newState)`\r\n // * `onItemHeightDidChange(i)`\r\n // * `getItemScrollPosition(i)`\r\n\t\t//\r\n\t\t// The code below handles the legacy compatibility aspect of the old type of argument\r\n\t\t// except maybe for those \"extremely unlikely\" cases in which the app is still unlikely to crash.\r\n\t\t//\r\n\t\tif (typeof itemOrIndex === 'number') {\r\n\t\t\tconst i = itemOrIndex\r\n\t\t\t// Validate the item index argument.\r\n\t\t\tif (i >= 0 && i < items.length) {\r\n\t\t\t\treturn i\r\n\t\t\t}\r\n\t\t} else {\r\n\t\t\t// It is also possible that the `item` is stale and that items have already been updated\r\n\t\t\t// via `.setItems()`. In that case, a developer could supply a `getItemId(item)` function\r\n\t\t\t// in order for this library to be able to detect the items that have stayed even when\r\n\t\t\t// their \"reference\" has changed. To support such case, here it has to also attempt a search\r\n\t\t\t// for the `item` by its `id` rather than just its \"reference\".\r\n\t\t\tconst getItemId = this._getItemId\r\n\t\t\tif (getItemId) {\r\n\t\t\t\tconst itemId = getItemId(item)\r\n\t\t\t\tconst i = items.findIndex((item) => getItemId(item) === itemId)\r\n\t\t\t\tif (i >= 0) {\r\n\t\t\t\t\treturn i\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\treportError(`Item not found: ${JSON.stringify(item)}`)\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)\r\n\t\t\t\t\t.concat(itemHeights)\r\n\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 `.onContainerResize()` 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;;AACA;;AACA;;;;;;;;;;;;;;AAEe,oBAAW;EAAA;;EACzB,KAAKA,aAAL,GAAqB,YAAM;IAC1B,OAAO,KAAI,CAACC,QAAL,GAAgBC,KAAhB,CAAsBC,MAA7B;EACA,CAFD;;EAIA,KAAKC,0BAAL,GAAkC,UAACC,WAAD,EAAiB;IAClD,IAAMC,IAAI,GAAGD,WAAb;;IACA,qBAAkB,KAAI,CAACJ,QAAL,EAAlB;IAAA,IAAQC,KAAR,kBAAQA,KAAR,CAFkD,CAGlD;IACA;IACA;IACA;IACA;IACA;IACA;;;IACA,IAAMK,CAAC,GAAGL,KAAK,CAACM,OAAN,CAAcF,IAAd,CAAV,CAVkD,CAWlD;;IACA,IAAIC,CAAC,IAAI,CAAT,EAAY;MACX,OAAOA,CAAP;IACA,CAdiD,CAgBlD;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACE;IACA;IACA;IACF;IACA;IACA;IACA;;;IACA,IAAI,OAAOF,WAAP,KAAuB,QAA3B,EAAqC;MACpC,IAAME,EAAC,GAAGF,WAAV,CADoC,CAEpC;;MACA,IAAIE,EAAC,IAAI,CAAL,IAAUA,EAAC,GAAGL,KA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C,YADZ,GAErB,KAAI,CAAC7D,QAAL,GAAgB6D,YAFnB;MAGA;IACD,CAlR2C,CAoR5C;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,CApSD;;EAsSA,KAAKjC,YAAL,GAAoB,UAACT,aAAD,EAAgBF,QAAhB,EAA6B;IAChD,OAAO,IAAAW,wBAAA,EAAaT,aAAb,EAA4BF,QAA5B,EAAsC,KAAI,CAACkD,WAA3C,CAAP;EACA,CAFD;AAGA"}
|
|
@@ -11,13 +11,7 @@ var _react = _interopRequireWildcard(require("react"));
|
|
|
11
11
|
|
|
12
12
|
var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
13
13
|
|
|
14
|
-
var
|
|
15
|
-
|
|
16
|
-
var _useVirtualScroller = _interopRequireDefault(require("./useVirtualScroller.js"));
|
|
17
|
-
|
|
18
|
-
var _useVirtualScrollerStartStop = _interopRequireDefault(require("./useVirtualScrollerStartStop.js"));
|
|
19
|
-
|
|
20
|
-
var _useInstanceMethods = _interopRequireDefault(require("./useInstanceMethods.js"));
|
|
14
|
+
var _useVirtualScroller2 = _interopRequireDefault(require("./useVirtualScroller.js"));
|
|
21
15
|
|
|
22
16
|
var _useItemKeys2 = _interopRequireDefault(require("./useItemKeys.js"));
|
|
23
17
|
|
|
@@ -25,21 +19,15 @@ var _useSetItemState = _interopRequireDefault(require("./useSetItemState.js"));
|
|
|
25
19
|
|
|
26
20
|
var _useOnItemHeightDidChange = _interopRequireDefault(require("./useOnItemHeightDidChange.js"));
|
|
27
21
|
|
|
28
|
-
var
|
|
29
|
-
|
|
30
|
-
var _useUpdateItemKeysOnItemsChange = _interopRequireDefault(require("./useUpdateItemKeysOnItemsChange.js"));
|
|
31
|
-
|
|
32
|
-
var _useValidateTableBodyItemsContainer = _interopRequireDefault(require("./useValidateTableBodyItemsContainer.js"));
|
|
33
|
-
|
|
34
|
-
var _useForwardedRef2 = _interopRequireDefault(require("./useForwardedRef.js"));
|
|
22
|
+
var _useMergeRefs = _interopRequireDefault(require("./useMergeRefs.js"));
|
|
35
23
|
|
|
36
|
-
var
|
|
24
|
+
var _useInstanceMethods = _interopRequireDefault(require("./useInstanceMethods.js"));
|
|
37
25
|
|
|
38
|
-
var
|
|
26
|
+
var _useUpdateItemKeysOnItemsChange = _interopRequireDefault(require("./useUpdateItemKeysOnItemsChange.js"));
|
|
39
27
|
|
|
40
28
|
var _debug = require("../utility/debug.js");
|
|
41
29
|
|
|
42
|
-
var _excluded = ["as", "items", "itemComponent", "itemComponentProps", "itemsContainerComponent", "itemsContainerComponentProps", "itemsContainerRef", "
|
|
30
|
+
var _excluded = ["as", "items", "itemComponent", "itemComponentProps", "itemsContainerComponent", "itemsContainerComponentProps", "itemsContainerRef", "onMount", "tbody", "readyToStart", "className", "bypass", "preserveScrollPosition", "preserveScrollPositionOnPrependItems", "measureItemsBatchSize", "scrollableContainer", "getScrollableContainer", "getColumnsCount", "getItemId", "onItemFirstRender", "onItemInitialRender", "initialScrollPosition", "onScrollPositionChange", "initialState", "getInitialItemState", "onStateChange", "estimatedItemHeight", "getEstimatedItemHeight", "getEstimatedVisibleItemRowsCount", "getEstimatedInterItemVerticalSpacing"];
|
|
43
31
|
|
|
44
32
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
|
45
33
|
|
|
@@ -53,16 +41,6 @@ function _objectWithoutProperties(source, excluded) { if (source == null) return
|
|
|
53
41
|
|
|
54
42
|
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
|
|
55
43
|
|
|
56
|
-
// When `items` property changes:
|
|
57
|
-
// * A new `items` property is supplied to the React component.
|
|
58
|
-
// * The React component re-renders itself.
|
|
59
|
-
// * `useSetNewItemsOnItemsPropertyChange()` hook is run.
|
|
60
|
-
// * `useSetNewItemsOnItemsPropertyChange()` hook detects that the `items` property
|
|
61
|
-
// has changed and calls `VirtualScroller.setItems(items)`.
|
|
62
|
-
// * `VirtualScroller.setItems(items)` calls `VirtualScroller.setState()`.
|
|
63
|
-
// * `VirtualScroller.setState()` calls the `setState()` function.
|
|
64
|
-
// * The `setState()` function calls a setter from a `useState()` hook.
|
|
65
|
-
// * The React component re-renders itself the second time.
|
|
66
44
|
function VirtualScroller(_ref, ref) {
|
|
67
45
|
var as = _ref.as,
|
|
68
46
|
itemsProperty = _ref.items,
|
|
@@ -70,11 +48,7 @@ function VirtualScroller(_ref, ref) {
|
|
|
70
48
|
itemComponentProps = _ref.itemComponentProps,
|
|
71
49
|
ItemsContainerComponent = _ref.itemsContainerComponent,
|
|
72
50
|
itemsContainerComponentProps = _ref.itemsContainerComponentProps,
|
|
73
|
-
|
|
74
|
-
estimatedItemHeight = _ref.estimatedItemHeight,
|
|
75
|
-
getEstimatedItemHeight = _ref.getEstimatedItemHeight,
|
|
76
|
-
getEstimatedVisibleItemRowsCount = _ref.getEstimatedVisibleItemRowsCount,
|
|
77
|
-
getEstimatedInterItemVerticalSpacing = _ref.getEstimatedInterItemVerticalSpacing,
|
|
51
|
+
itemsContainerRefProperty = _ref.itemsContainerRef,
|
|
78
52
|
onMount = _ref.onMount,
|
|
79
53
|
tbody = _ref.tbody,
|
|
80
54
|
readyToStart = _ref.readyToStart,
|
|
@@ -94,6 +68,10 @@ function VirtualScroller(_ref, ref) {
|
|
|
94
68
|
initialState = _ref.initialState,
|
|
95
69
|
getInitialItemState = _ref.getInitialItemState,
|
|
96
70
|
onStateChange = _ref.onStateChange,
|
|
71
|
+
estimatedItemHeight = _ref.estimatedItemHeight,
|
|
72
|
+
getEstimatedItemHeight = _ref.getEstimatedItemHeight,
|
|
73
|
+
getEstimatedVisibleItemRowsCount = _ref.getEstimatedVisibleItemRowsCount,
|
|
74
|
+
getEstimatedInterItemVerticalSpacing = _ref.getEstimatedInterItemVerticalSpacing,
|
|
97
75
|
rest = _objectWithoutProperties(_ref, _excluded);
|
|
98
76
|
|
|
99
77
|
// Previously, `as` property was being used instead of `itemsContainerComponent`,
|
|
@@ -102,47 +80,34 @@ function VirtualScroller(_ref, ref) {
|
|
|
102
80
|
// The default `"div"` fallback value is just a legacy compatibility relic, and so is the `as` property.
|
|
103
81
|
if (!ItemsContainerComponent) {
|
|
104
82
|
ItemsContainerComponent = as || 'div';
|
|
105
|
-
} //
|
|
106
|
-
// Instead, it always derived `tbody` property value from `as` property value by comparing it to `"tbody"` string.
|
|
107
|
-
// As a result, it seemed like the explicit passing of `tbody` property didn't really work as intended.
|
|
108
|
-
// In the end, it was decided that perhaps `tbody` property value should always be derived from `as` property
|
|
109
|
-
// without a developer having to manually specify it. So the `tbody` property was deprecated.
|
|
110
|
-
// It still exists though for backwards compatibility with the older versions of the package.
|
|
83
|
+
} // In simple cases, the use of a `<tbody/>` tag as an items container component could be auto-detected.
|
|
111
84
|
|
|
112
85
|
|
|
113
86
|
if (tbody === undefined) {
|
|
114
|
-
// `tbody` should
|
|
87
|
+
// `tbody` auto-detection should happen before any DOM Elements have been mounted,
|
|
88
|
+
// i.e. it can't rely on the trivial `getItemsContainerElement().tagName === 'TBODY'` check.
|
|
115
89
|
// This is because during Server-Side Render there's no DOM Elements tree at all.
|
|
116
90
|
// And server-sider render result is required to be exactly the same as client-side render result.
|
|
117
91
|
// This means that `tbody` detection for the purposes of getting the initial
|
|
118
92
|
// `className` or `style` property values must not rely on any DOM Elements at all,
|
|
119
93
|
// and should use some other means such as explicitly passing a `tbody: true` property
|
|
120
|
-
//
|
|
121
|
-
// `itemsContainerCompoent` property value.
|
|
94
|
+
// or detecting `<tbody/>` tag usage from the `itemsContainerCompoent` property value.
|
|
122
95
|
tbody = ItemsContainerComponent === 'tbody';
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
var _useForwardedRef = (0, _useForwardedRef2["default"])(itemsContainerRef),
|
|
127
|
-
setItemsContainerRef = _useForwardedRef.setRef,
|
|
128
|
-
itemsContainer = _useForwardedRef.internalRef; // Create a `VirtualScroller` instance.
|
|
96
|
+
}
|
|
129
97
|
|
|
130
|
-
|
|
131
|
-
var virtualScroller = (0, _useVirtualScroller["default"])({
|
|
98
|
+
var _useVirtualScroller = (0, _useVirtualScroller2["default"])({
|
|
132
99
|
items: itemsProperty,
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
100
|
+
tbody: tbody,
|
|
101
|
+
readyToStart: readyToStart,
|
|
102
|
+
style: itemsContainerComponentProps && itemsContainerComponentProps.style,
|
|
103
|
+
className: classNameProperty || itemsContainerComponentProps && itemsContainerComponentProps.className,
|
|
104
|
+
// The following are the "core" component options.
|
|
105
|
+
//
|
|
139
106
|
bypass: bypass,
|
|
140
|
-
//
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
initialScrollPosition: initialScrollPosition,
|
|
145
|
-
onScrollPositionChange: onScrollPositionChange,
|
|
107
|
+
// `preserveScrollPosition` property name is deprecated,
|
|
108
|
+
// use `preserveScrollPositionOnPrependItems` property instead.
|
|
109
|
+
preserveScrollPosition: preserveScrollPosition,
|
|
110
|
+
preserveScrollPositionOnPrependItems: preserveScrollPositionOnPrependItems,
|
|
146
111
|
measureItemsBatchSize: measureItemsBatchSize,
|
|
147
112
|
// `scrollableContainer` property is deprecated.
|
|
148
113
|
// Use `getScrollableContainer()` property instead.
|
|
@@ -150,39 +115,30 @@ function VirtualScroller(_ref, ref) {
|
|
|
150
115
|
getScrollableContainer: getScrollableContainer,
|
|
151
116
|
getColumnsCount: getColumnsCount,
|
|
152
117
|
getItemId: getItemId,
|
|
118
|
+
// `onItemFirstRender(i)` is deprecated, use `onItemInitialRender(item)` instead.
|
|
119
|
+
onItemFirstRender: onItemFirstRender,
|
|
120
|
+
onItemInitialRender: onItemInitialRender,
|
|
121
|
+
initialScrollPosition: initialScrollPosition,
|
|
122
|
+
onScrollPositionChange: onScrollPositionChange,
|
|
153
123
|
initialState: initialState,
|
|
154
124
|
getInitialItemState: getInitialItemState,
|
|
155
|
-
onStateChange: onStateChange
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
125
|
+
onStateChange: onStateChange,
|
|
126
|
+
getEstimatedItemHeight: getEstimatedItemHeight || ( // `estimatedItemHeight` property name is deprecated,
|
|
127
|
+
// use `getEstimatedItemHeight` property instead.
|
|
128
|
+
typeof estimatedItemHeight === 'number' ? function () {
|
|
129
|
+
return estimatedItemHeight;
|
|
130
|
+
} : undefined),
|
|
131
|
+
getEstimatedVisibleItemRowsCount: getEstimatedVisibleItemRowsCount,
|
|
132
|
+
getEstimatedInterItemVerticalSpacing: getEstimatedInterItemVerticalSpacing
|
|
133
|
+
}),
|
|
134
|
+
stateToRender = _useVirtualScroller.state,
|
|
135
|
+
style = _useVirtualScroller.style,
|
|
136
|
+
className = _useVirtualScroller.className,
|
|
137
|
+
itemsContainerRef = _useVirtualScroller.itemsContainerRef,
|
|
138
|
+
virtualScroller = _useVirtualScroller.virtualScroller; // List items "container" DOM Element reference.
|
|
164
139
|
|
|
165
140
|
|
|
166
|
-
var
|
|
167
|
-
initialState: _initialState,
|
|
168
|
-
onRender: virtualScroller.onRender
|
|
169
|
-
}),
|
|
170
|
-
getState = _useState.getState,
|
|
171
|
-
setState = _useState.setState,
|
|
172
|
-
stateToRender = _useState.stateToRender; // Use custom (external) state storage in the `VirtualScroller`.
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
(0, _react.useMemo)(function () {
|
|
176
|
-
virtualScroller.useState({
|
|
177
|
-
getState: getState,
|
|
178
|
-
setState: setState
|
|
179
|
-
});
|
|
180
|
-
}, []); // Start `VirtualScroller` on mount.
|
|
181
|
-
// Stop `VirtualScroller` on unmount.
|
|
182
|
-
|
|
183
|
-
(0, _useVirtualScrollerStartStop["default"])(virtualScroller, {
|
|
184
|
-
readyToStart: readyToStart
|
|
185
|
-
}); // List items are rendered with `key`s so that React doesn't
|
|
141
|
+
var setItemsContainerRef = (0, _useMergeRefs["default"])(itemsContainerRef, itemsContainerRefProperty); // List items are rendered with `key`s so that React doesn't
|
|
186
142
|
// "reuse" `itemComponent`s in cases when `items` are changed.
|
|
187
143
|
|
|
188
144
|
var _useItemKeys = (0, _useItemKeys2["default"])({
|
|
@@ -191,9 +147,15 @@ function VirtualScroller(_ref, ref) {
|
|
|
191
147
|
getItemKey = _useItemKeys.getItemKey,
|
|
192
148
|
onItemKeysReset = _useItemKeys.onItemKeysReset,
|
|
193
149
|
usesAutogeneratedItemKeys = _useItemKeys.usesAutogeneratedItemKeys,
|
|
194
|
-
updateItemKeysForNewItems = _useItemKeys.updateItemKeysForNewItems; //
|
|
195
|
-
|
|
150
|
+
updateItemKeysForNewItems = _useItemKeys.updateItemKeysForNewItems; // Updates `key`s if item indexes have changed.
|
|
151
|
+
|
|
196
152
|
|
|
153
|
+
(0, _useUpdateItemKeysOnItemsChange["default"])(stateToRender.items, {
|
|
154
|
+
virtualScroller: virtualScroller,
|
|
155
|
+
usesAutogeneratedItemKeys: usesAutogeneratedItemKeys,
|
|
156
|
+
updateItemKeysForNewItems: updateItemKeysForNewItems
|
|
157
|
+
}); // Cache per-item `setItemState` functions' "references"
|
|
158
|
+
// so that item components don't get re-rendered needlessly.
|
|
197
159
|
|
|
198
160
|
var getSetItemState = (0, _useSetItemState["default"])({
|
|
199
161
|
getItemKey: getItemKey,
|
|
@@ -206,20 +168,6 @@ function VirtualScroller(_ref, ref) {
|
|
|
206
168
|
getItemKey: getItemKey,
|
|
207
169
|
onItemKeysReset: onItemKeysReset,
|
|
208
170
|
virtualScroller: virtualScroller
|
|
209
|
-
}); // Calls `.setItems()` if `items` property has changed.
|
|
210
|
-
|
|
211
|
-
(0, _useSetNewItemsOnItemsPropertyChange["default"])(itemsProperty, {
|
|
212
|
-
virtualScroller: virtualScroller,
|
|
213
|
-
// `preserveScrollPosition` property name is deprecated,
|
|
214
|
-
// use `preserveScrollPositionOnPrependItems` property instead.
|
|
215
|
-
preserveScrollPosition: preserveScrollPosition,
|
|
216
|
-
preserveScrollPositionOnPrependItems: preserveScrollPositionOnPrependItems
|
|
217
|
-
}); // Updates `key`s if item indexes have changed.
|
|
218
|
-
|
|
219
|
-
(0, _useUpdateItemKeysOnItemsChange["default"])(stateToRender.items, {
|
|
220
|
-
virtualScroller: virtualScroller,
|
|
221
|
-
usesAutogeneratedItemKeys: usesAutogeneratedItemKeys,
|
|
222
|
-
updateItemKeysForNewItems: updateItemKeysForNewItems
|
|
223
171
|
}); // Add instance methods to the React component.
|
|
224
172
|
|
|
225
173
|
(0, _useInstanceMethods["default"])(ref, {
|
|
@@ -233,14 +181,7 @@ function VirtualScroller(_ref, ref) {
|
|
|
233
181
|
(0, _debug.warn)('`onMount` property is deprecated');
|
|
234
182
|
onMount();
|
|
235
183
|
}
|
|
236
|
-
}, []); //
|
|
237
|
-
// when using a `<tbody/>` as a container for list items.
|
|
238
|
-
// This hook validates that the developer didn't "forget" to do that in such case.
|
|
239
|
-
|
|
240
|
-
(0, _useValidateTableBodyItemsContainer["default"])({
|
|
241
|
-
virtualScroller: virtualScroller,
|
|
242
|
-
tbody: tbody
|
|
243
|
-
}); // `willRender()` function is no longer used.
|
|
184
|
+
}, []); // `willRender()` function is no longer used.
|
|
244
185
|
//
|
|
245
186
|
// // `getSnapshotBeforeUpdate()` is called right before `componentDidUpdate()`.
|
|
246
187
|
// // A hook equivalent/workaround for `getSnapshotBeforeUpdate()`:
|
|
@@ -255,15 +196,6 @@ function VirtualScroller(_ref, ref) {
|
|
|
255
196
|
// return null
|
|
256
197
|
// }
|
|
257
198
|
|
|
258
|
-
var classNamePassThrough = classNameProperty || itemsContainerComponentProps && itemsContainerComponentProps.className;
|
|
259
|
-
var className = (0, _useClassName["default"])(classNamePassThrough, {
|
|
260
|
-
tbody: tbody
|
|
261
|
-
});
|
|
262
|
-
var stylePassThrough = itemsContainerComponentProps && itemsContainerComponentProps.style;
|
|
263
|
-
var style = (0, _useStyle["default"])(stylePassThrough, {
|
|
264
|
-
tbody: tbody,
|
|
265
|
-
state: stateToRender
|
|
266
|
-
});
|
|
267
199
|
var currentItems = stateToRender.items,
|
|
268
200
|
itemStates = stateToRender.itemStates,
|
|
269
201
|
firstShownItemIndex = stateToRender.firstShownItemIndex,
|
|
@@ -343,9 +275,7 @@ VirtualScroller.propTypes = {
|
|
|
343
275
|
getEstimatedInterItemVerticalSpacing: _propTypes["default"].func,
|
|
344
276
|
bypass: _propTypes["default"].bool,
|
|
345
277
|
// bypassBatchSize: PropTypes.number,
|
|
346
|
-
|
|
347
|
-
// Pass `as: "tbody"` property instead.
|
|
348
|
-
// tbody: PropTypes.bool,
|
|
278
|
+
tbody: _propTypes["default"].bool,
|
|
349
279
|
preserveScrollPositionOnPrependItems: _propTypes["default"].bool,
|
|
350
280
|
// `preserveScrollPosition` property name is deprecated,
|
|
351
281
|
// use `preserveScrollPositionOnPrependItems` instead.
|
|
@@ -378,5 +308,17 @@ VirtualScroller.propTypes = {
|
|
|
378
308
|
verticalSpacing: _propTypes["default"].number
|
|
379
309
|
}),
|
|
380
310
|
getInitialItemState: _propTypes["default"].func
|
|
381
|
-
};
|
|
311
|
+
}; // Legacy compatibility:
|
|
312
|
+
//
|
|
313
|
+
// Originally, the default export of the `virtual-scroller/react` subpackage
|
|
314
|
+
// was only the `VirtualScroller` component, and there were no other exports.
|
|
315
|
+
//
|
|
316
|
+
// Later, `useVirtualScroller()` hook export was added.
|
|
317
|
+
// In order to maintain legacy compatibility, the new exports shouldn't "break"
|
|
318
|
+
// the existing environments that were using the old versions of the package.
|
|
319
|
+
// This means that in non-ES6-import environments, any additional exports
|
|
320
|
+
// should be added directly to the default `VirtualScroller` export.
|
|
321
|
+
//
|
|
322
|
+
|
|
323
|
+
VirtualScroller.useVirtualScroller = _useVirtualScroller2["default"];
|
|
382
324
|
//# sourceMappingURL=VirtualScroller.js.map
|