virtual-scroller 1.15.0 → 1.15.1
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/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/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/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/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/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
|
@@ -7,6 +7,8 @@ exports["default"] = useStyle;
|
|
|
7
7
|
|
|
8
8
|
var _px = _interopRequireDefault(require("../utility/px.js"));
|
|
9
9
|
|
|
10
|
+
var _debug = require("../utility/debug.js");
|
|
11
|
+
|
|
10
12
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
|
11
13
|
|
|
12
14
|
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
@@ -21,6 +23,22 @@ function useStyle(style, _ref) {
|
|
|
21
23
|
|
|
22
24
|
if (tbody) {
|
|
23
25
|
return style;
|
|
26
|
+
} // Validate that the passed `style` property doesn't include
|
|
27
|
+
// `padding-top` or `padding-bottom` or `padding`.
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
if (style) {
|
|
31
|
+
if (typeof style.padding === 'number') {
|
|
32
|
+
(0, _debug.reportError)('`style` property can\'t include any `padding`');
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
if (typeof style.paddingTop === 'number') {
|
|
36
|
+
(0, _debug.reportError)('`style` property can\'t include any `paddingTop`');
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
if (typeof style.paddingBottom === 'number') {
|
|
40
|
+
(0, _debug.reportError)('`style` property can\'t include any `paddingBottom`');
|
|
41
|
+
}
|
|
24
42
|
}
|
|
25
43
|
|
|
26
44
|
var beforeItemsHeight = state.beforeItemsHeight,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useStyle.js","names":["useStyle","style","tbody","state","
|
|
1
|
+
{"version":3,"file":"useStyle.js","names":["useStyle","style","tbody","state","padding","reportError","paddingTop","paddingBottom","beforeItemsHeight","afterItemsHeight","px"],"sources":["../../source/react/useStyle.js"],"sourcesContent":["import px from '../utility/px.js'\r\nimport { reportError } from '../utility/debug.js'\r\n\r\nexport default function useStyle(style, {\r\n\ttbody,\r\n\tstate\r\n}) {\r\n\tif (tbody) {\r\n\t\treturn style\r\n\t}\r\n\r\n\t// Validate that the passed `style` property doesn't include\r\n\t// `padding-top` or `padding-bottom` or `padding`.\r\n\tif (style) {\r\n\t\tif (typeof style.padding === 'number') {\r\n\t\t\treportError('`style` property can\\'t include any `padding`')\r\n\t\t}\r\n\t\tif (typeof style.paddingTop === 'number') {\r\n\t\t\treportError('`style` property can\\'t include any `paddingTop`')\r\n\t\t}\r\n\t\tif (typeof style.paddingBottom === 'number') {\r\n\t\t\treportError('`style` property can\\'t include any `paddingBottom`')\r\n\t\t}\r\n\t}\r\n\r\n\tconst {\r\n\t\tbeforeItemsHeight,\r\n\t\tafterItemsHeight\r\n\t} = state\r\n\r\n\treturn {\r\n\t\t...style,\r\n\t\tpaddingTop: px(beforeItemsHeight),\r\n\t\tpaddingBottom: px(afterItemsHeight)\r\n\t}\r\n}"],"mappings":";;;;;;;AAAA;;AACA;;;;;;;;;;AAEe,SAASA,QAAT,CAAkBC,KAAlB,QAGZ;EAAA,IAFFC,KAEE,QAFFA,KAEE;EAAA,IADFC,KACE,QADFA,KACE;;EACF,IAAID,KAAJ,EAAW;IACV,OAAOD,KAAP;EACA,CAHC,CAKF;EACA;;;EACA,IAAIA,KAAJ,EAAW;IACV,IAAI,OAAOA,KAAK,CAACG,OAAb,KAAyB,QAA7B,EAAuC;MACtC,IAAAC,kBAAA,EAAY,+CAAZ;IACA;;IACD,IAAI,OAAOJ,KAAK,CAACK,UAAb,KAA4B,QAAhC,EAA0C;MACzC,IAAAD,kBAAA,EAAY,kDAAZ;IACA;;IACD,IAAI,OAAOJ,KAAK,CAACM,aAAb,KAA+B,QAAnC,EAA6C;MAC5C,IAAAF,kBAAA,EAAY,qDAAZ;IACA;EACD;;EAED,IACCG,iBADD,GAGIL,KAHJ,CACCK,iBADD;EAAA,IAECC,gBAFD,GAGIN,KAHJ,CAECM,gBAFD;EAKA,uCACIR,KADJ;IAECK,UAAU,EAAE,IAAAI,cAAA,EAAGF,iBAAH,CAFb;IAGCD,aAAa,EAAE,IAAAG,cAAA,EAAGD,gBAAH;EAHhB;AAKA"}
|
|
@@ -7,60 +7,159 @@ exports["default"] = useVirtualScroller;
|
|
|
7
7
|
|
|
8
8
|
var _react = require("react");
|
|
9
9
|
|
|
10
|
-
var
|
|
10
|
+
var _useState2 = _interopRequireDefault(require("./useState.js"));
|
|
11
|
+
|
|
12
|
+
var _useCreateVirtualScroller = _interopRequireDefault(require("./useCreateVirtualScroller.js"));
|
|
13
|
+
|
|
14
|
+
var _useStartStopVirtualScroller = _interopRequireDefault(require("./useStartStopVirtualScroller.js"));
|
|
15
|
+
|
|
16
|
+
var _useSetNewItemsOnItemsPropertyChange = _interopRequireDefault(require("./useSetNewItemsOnItemsPropertyChange.js"));
|
|
17
|
+
|
|
18
|
+
var _useValidateTableBodyItemsContainer = _interopRequireDefault(require("./useValidateTableBodyItemsContainer.js"));
|
|
19
|
+
|
|
20
|
+
var _useClassName = _interopRequireDefault(require("./useClassName.js"));
|
|
21
|
+
|
|
22
|
+
var _useStyle = _interopRequireDefault(require("./useStyle.js"));
|
|
11
23
|
|
|
12
24
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
|
13
25
|
|
|
14
|
-
//
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
26
|
+
// When `items` property changes:
|
|
27
|
+
// * A new `items` property is supplied to the React component.
|
|
28
|
+
// * The React component re-renders itself.
|
|
29
|
+
// * `useSetNewItemsOnItemsPropertyChange()` hook is run.
|
|
30
|
+
// * `useSetNewItemsOnItemsPropertyChange()` hook detects that the `items` property
|
|
31
|
+
// has changed and calls `VirtualScroller.setItems(items)`.
|
|
32
|
+
// * `VirtualScroller.setItems(items)` calls `VirtualScroller.setState()`.
|
|
33
|
+
// * `VirtualScroller.setState()` calls the `setState()` function.
|
|
34
|
+
// * The `setState()` function calls a setter from a `useState()` hook.
|
|
35
|
+
// * The React component re-renders itself the second time.
|
|
36
|
+
function useVirtualScroller(_ref) {
|
|
37
|
+
var itemsProperty = _ref.items,
|
|
38
|
+
tbody = _ref.tbody,
|
|
39
|
+
readyToStart = _ref.readyToStart,
|
|
40
|
+
styleProperty = _ref.style,
|
|
41
|
+
classNameProperty = _ref.className,
|
|
21
42
|
bypass = _ref.bypass,
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
initialScrollPosition = _ref.initialScrollPosition,
|
|
25
|
-
onScrollPositionChange = _ref.onScrollPositionChange,
|
|
43
|
+
preserveScrollPosition = _ref.preserveScrollPosition,
|
|
44
|
+
preserveScrollPositionOnPrependItems = _ref.preserveScrollPositionOnPrependItems,
|
|
26
45
|
measureItemsBatchSize = _ref.measureItemsBatchSize,
|
|
27
46
|
scrollableContainer = _ref.scrollableContainer,
|
|
28
47
|
getScrollableContainer = _ref.getScrollableContainer,
|
|
29
48
|
getColumnsCount = _ref.getColumnsCount,
|
|
30
49
|
getItemId = _ref.getItemId,
|
|
50
|
+
onItemFirstRender = _ref.onItemFirstRender,
|
|
51
|
+
onItemInitialRender = _ref.onItemInitialRender,
|
|
52
|
+
initialScrollPosition = _ref.initialScrollPosition,
|
|
53
|
+
onScrollPositionChange = _ref.onScrollPositionChange,
|
|
31
54
|
initialState = _ref.initialState,
|
|
32
55
|
getInitialItemState = _ref.getInitialItemState,
|
|
33
|
-
onStateChange = _ref.onStateChange
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
56
|
+
onStateChange = _ref.onStateChange,
|
|
57
|
+
getEstimatedItemHeight = _ref.getEstimatedItemHeight,
|
|
58
|
+
getEstimatedVisibleItemRowsCount = _ref.getEstimatedVisibleItemRowsCount,
|
|
59
|
+
getEstimatedInterItemVerticalSpacing = _ref.getEstimatedInterItemVerticalSpacing;
|
|
60
|
+
// A `ref` to the items container element.
|
|
61
|
+
var itemsContainerRef = (0, _react.useRef)(); // Use `hasMounted` flag to decide if `itemsContainerRef` value should be validated.
|
|
62
|
+
|
|
63
|
+
var hasMounted = (0, _react.useRef)(false);
|
|
64
|
+
(0, _react.useLayoutEffect)(function () {
|
|
65
|
+
hasMounted.current = true;
|
|
66
|
+
}, []); // Create a `VirtualScroller` instance.
|
|
67
|
+
|
|
68
|
+
var virtualScroller = (0, _useCreateVirtualScroller["default"])({
|
|
69
|
+
items: itemsProperty,
|
|
70
|
+
getEstimatedItemHeight: getEstimatedItemHeight,
|
|
71
|
+
getEstimatedVisibleItemRowsCount: getEstimatedVisibleItemRowsCount,
|
|
72
|
+
getEstimatedInterItemVerticalSpacing: getEstimatedInterItemVerticalSpacing,
|
|
73
|
+
bypass: bypass,
|
|
74
|
+
// bypassBatchSize,
|
|
75
|
+
onItemInitialRender: onItemInitialRender,
|
|
76
|
+
// `onItemFirstRender(i)` is deprecated, use `onItemInitialRender(item)` instead.
|
|
77
|
+
onItemFirstRender: onItemFirstRender,
|
|
78
|
+
initialScrollPosition: initialScrollPosition,
|
|
79
|
+
onScrollPositionChange: onScrollPositionChange,
|
|
80
|
+
measureItemsBatchSize: measureItemsBatchSize,
|
|
81
|
+
// `scrollableContainer` property is deprecated.
|
|
82
|
+
// Use `getScrollableContainer()` property instead.
|
|
83
|
+
scrollableContainer: scrollableContainer,
|
|
84
|
+
getScrollableContainer: getScrollableContainer,
|
|
85
|
+
getColumnsCount: getColumnsCount,
|
|
86
|
+
getItemId: getItemId,
|
|
87
|
+
initialState: initialState,
|
|
88
|
+
getInitialItemState: getInitialItemState,
|
|
89
|
+
onStateChange: onStateChange
|
|
90
|
+
}, {
|
|
91
|
+
getItemsContainerElement: function getItemsContainerElement() {
|
|
92
|
+
// Validate that the developer has correctly passed the returned `itemsContainerRef` property
|
|
93
|
+
// as the items container component's `ref`.
|
|
94
|
+
//
|
|
95
|
+
// `getItemsContainerElement()` function is called both before it has mounted
|
|
96
|
+
// and after it has mounted. Only validate the ref's value after it has mounted.
|
|
97
|
+
//
|
|
98
|
+
if (hasMounted.current) {
|
|
99
|
+
if (!itemsContainerRef.current) {
|
|
100
|
+
throw new Error('[virtual-scroller] Did you forget to pass the returned `itemsContainerRef` property as the items container component\'s `ref`?');
|
|
101
|
+
}
|
|
102
|
+
} // Return the items container element.
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
return itemsContainerRef.current;
|
|
106
|
+
}
|
|
107
|
+
}); // Only compute the initial state once.
|
|
108
|
+
|
|
109
|
+
var _initialState = (0, _react.useMemo)(function () {
|
|
110
|
+
return virtualScroller.getInitialState();
|
|
111
|
+
}, []); // Use React's `useState()` hook for managing `VirtualScroller`'s state lifecycle.
|
|
112
|
+
// This way, React will re-render the component on every state update.
|
|
113
|
+
|
|
114
|
+
|
|
115
|
+
var _useState = (0, _useState2["default"])({
|
|
116
|
+
initialState: _initialState,
|
|
117
|
+
onRender: virtualScroller.onRender
|
|
118
|
+
}),
|
|
119
|
+
getState = _useState.getState,
|
|
120
|
+
setState = _useState.setState,
|
|
121
|
+
stateToRender = _useState.stateToRender; // Use custom (external) state storage in the `VirtualScroller`.
|
|
122
|
+
|
|
123
|
+
|
|
124
|
+
(0, _react.useMemo)(function () {
|
|
125
|
+
virtualScroller.useState({
|
|
126
|
+
getState: getState,
|
|
127
|
+
setState: setState
|
|
63
128
|
});
|
|
64
|
-
}, []);
|
|
129
|
+
}, []); // Start `VirtualScroller` on mount.
|
|
130
|
+
// Stop `VirtualScroller` on unmount.
|
|
131
|
+
|
|
132
|
+
(0, _useStartStopVirtualScroller["default"])(virtualScroller, {
|
|
133
|
+
readyToStart: readyToStart
|
|
134
|
+
}); // Calls `.setItems()` if `items` property has changed.
|
|
135
|
+
|
|
136
|
+
(0, _useSetNewItemsOnItemsPropertyChange["default"])(itemsProperty, {
|
|
137
|
+
virtualScroller: virtualScroller,
|
|
138
|
+
// `preserveScrollPosition` property name is deprecated,
|
|
139
|
+
// use `preserveScrollPositionOnPrependItems` property instead.
|
|
140
|
+
preserveScrollPosition: preserveScrollPosition,
|
|
141
|
+
preserveScrollPositionOnPrependItems: preserveScrollPositionOnPrependItems
|
|
142
|
+
}); // A developer might "forget" to pass `itemsContainerComponent="tbody"` property
|
|
143
|
+
// when using a `<tbody/>` as a container for list items.
|
|
144
|
+
// This hook validates that the developer didn't "forget" to do that in such case.
|
|
145
|
+
|
|
146
|
+
(0, _useValidateTableBodyItemsContainer["default"])({
|
|
147
|
+
virtualScroller: virtualScroller,
|
|
148
|
+
tbody: tbody
|
|
149
|
+
});
|
|
150
|
+
var className = (0, _useClassName["default"])(classNameProperty, {
|
|
151
|
+
tbody: tbody
|
|
152
|
+
});
|
|
153
|
+
var style = (0, _useStyle["default"])(styleProperty, {
|
|
154
|
+
tbody: tbody,
|
|
155
|
+
state: stateToRender
|
|
156
|
+
});
|
|
157
|
+
return {
|
|
158
|
+
state: stateToRender,
|
|
159
|
+
style: style,
|
|
160
|
+
className: className,
|
|
161
|
+
itemsContainerRef: itemsContainerRef,
|
|
162
|
+
virtualScroller: virtualScroller
|
|
163
|
+
};
|
|
65
164
|
}
|
|
66
165
|
//# sourceMappingURL=useVirtualScroller.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useVirtualScroller.js","names":["useVirtualScroller","items","estimatedItemHeight","getEstimatedItemHeight","getEstimatedVisibleItemRowsCount","getEstimatedInterItemVerticalSpacing","bypass","onItemInitialRender","onItemFirstRender","initialScrollPosition","onScrollPositionChange","measureItemsBatchSize","scrollableContainer","getScrollableContainer","getColumnsCount","getItemId","initialState","getInitialItemState","onStateChange","itemsContainer","useMemo","VirtualScroller","current","_useTimeoutInRenderLoop","state"],"sources":["../../source/react/useVirtualScroller.js"],"sourcesContent":["import { useMemo } from 'react'\r\n\r\nimport VirtualScroller from '../VirtualScroller.js'\r\n\r\n// Creates a `VirtualScroller` instance.\r\nexport default function useVirtualScroller({\r\n\titems,\r\n\t// `estimatedItemHeight` is deprecated, use `getEstimatedItemHeight()` instead.\r\n\testimatedItemHeight,\r\n\tgetEstimatedItemHeight,\r\n\tgetEstimatedVisibleItemRowsCount,\r\n\tgetEstimatedInterItemVerticalSpacing,\r\n\tbypass,\r\n\t// bypassBatchSize,\r\n\tonItemInitialRender,\r\n\t// `onItemFirstRender(i)` is deprecated, use `onItemInitialRender(item)` instead.\r\n\tonItemFirstRender,\r\n\tinitialScrollPosition,\r\n\tonScrollPositionChange,\r\n\tmeasureItemsBatchSize,\r\n\t// `scrollableContainer` property is deprecated.\r\n\t// Use `getScrollableContainer()` property instead.\r\n\tscrollableContainer,\r\n\tgetScrollableContainer,\r\n\tgetColumnsCount,\r\n\tgetItemId,\r\n\tinitialState,\r\n\tgetInitialItemState,\r\n\tonStateChange\r\n}, {\r\n\titemsContainer\r\n}) {\r\n\treturn useMemo(() => {\r\n\t\t// Create `virtual-scroller` instance.\r\n\t\treturn new VirtualScroller(\r\n\t\t\t() => itemsContainer.current,\r\n\t\t\titems,\r\n\t\t\t{\r\n\t\t\t\t_useTimeoutInRenderLoop: true,\r\n\t\t\t\t// `estimatedItemHeight` is deprecated, use `getEstimatedItemHeight()` instead.\r\n\t\t\t\testimatedItemHeight,\r\n\t\t\t\tgetEstimatedItemHeight,\r\n\t\t\t\tgetEstimatedVisibleItemRowsCount,\r\n\t\t\t\tgetEstimatedInterItemVerticalSpacing,\r\n\t\t\t\tbypass,\r\n\t\t\t\t// bypassBatchSize,\r\n\t\t\t\tonItemInitialRender,\r\n\t\t\t\t// `onItemFirstRender(i)` is deprecated, use `onItemInitialRender(item)` instead.\r\n\t\t\t\tonItemFirstRender,\r\n\t\t\t\tinitialScrollPosition,\r\n\t\t\t\tonScrollPositionChange,\r\n\t\t\t\tmeasureItemsBatchSize,\r\n\t\t\t\t// `scrollableContainer` property is deprecated.\r\n\t\t\t\t// Use `getScrollableContainer()` property instead.\r\n\t\t\t\tscrollableContainer,\r\n\t\t\t\tgetScrollableContainer,\r\n\t\t\t\tgetColumnsCount,\r\n\t\t\t\tgetItemId,\r\n\t\t\t\tstate: initialState,\r\n\t\t\t\tgetInitialItemState,\r\n\t\t\t\tonStateChange\r\n\t\t\t}\r\n\t\t)\r\n\t}, [])\r\n}"],"mappings":";;;;;;;AAAA;;AAEA;;;;AAEA;AACe,SAASA,kBAAT,cA0BZ;EAAA,IAzBFC,KAyBE,QAzBFA,KAyBE;EAAA,IAvBFC,mBAuBE,QAvBFA,mBAuBE;EAAA,IAtBFC,sBAsBE,QAtBFA,sBAsBE;EAAA,IArBFC,gCAqBE,QArBFA,gCAqBE;EAAA,IApBFC,oCAoBE,QApBFA,oCAoBE;EAAA,IAnBFC,MAmBE,QAnBFA,MAmBE;EAAA,IAjBFC,mBAiBE,QAjBFA,mBAiBE;EAAA,IAfFC,iBAeE,QAfFA,iBAeE;EAAA,IAdFC,qBAcE,QAdFA,qBAcE;EAAA,IAbFC,sBAaE,QAbFA,sBAaE;EAAA,IAZFC,qBAYE,QAZFA,qBAYE;EAAA,IATFC,mBASE,QATFA,mBASE;EAAA,IARFC,sBAQE,QARFA,sBAQE;EAAA,IAPFC,eAOE,QAPFA,eAOE;EAAA,IANFC,SAME,QANFA,SAME;EAAA,IALFC,YAKE,QALFA,YAKE;EAAA,IAJFC,mBAIE,QAJFA,mBAIE;EAAA,IAHFC,aAGE,QAHFA,aAGE;EAAA,IADFC,cACE,SADFA,cACE;EACF,OAAO,IAAAC,cAAA,EAAQ,YAAM;IACpB;IACA,OAAO,IAAIC,2BAAJ,CACN;MAAA,OAAMF,cAAc,CAACG,OAArB;IAAA,CADM,EAENrB,KAFM,EAGN;MACCsB,uBAAuB,EAAE,IAD1B;MAEC;MACArB,mBAAmB,EAAnBA,mBAHD;MAICC,sBAAsB,EAAtBA,sBAJD;MAKCC,gCAAgC,EAAhCA,gCALD;MAMCC,oCAAoC,EAApCA,oCAND;MAOCC,MAAM,EAANA,MAPD;MAQC;MACAC,mBAAmB,EAAnBA,mBATD;MAUC;MACAC,iBAAiB,EAAjBA,iBAXD;MAYCC,qBAAqB,EAArBA,qBAZD;MAaCC,sBAAsB,EAAtBA,sBAbD;MAcCC,qBAAqB,EAArBA,qBAdD;MAeC;MACA;MACAC,mBAAmB,EAAnBA,mBAjBD;MAkBCC,sBAAsB,EAAtBA,sBAlBD;MAmBCC,eAAe,EAAfA,eAnBD;MAoBCC,SAAS,EAATA,SApBD;MAqBCS,KAAK,EAAER,YArBR;MAsBCC,mBAAmB,EAAnBA,mBAtBD;MAuBCC,aAAa,EAAbA;IAvBD,CAHM,CAAP;EA6BA,CA/BM,EA+BJ,EA/BI,CAAP;AAgCA"}
|
|
1
|
+
{"version":3,"file":"useVirtualScroller.js","names":["useVirtualScroller","itemsProperty","items","tbody","readyToStart","styleProperty","style","classNameProperty","className","bypass","preserveScrollPosition","preserveScrollPositionOnPrependItems","measureItemsBatchSize","scrollableContainer","getScrollableContainer","getColumnsCount","getItemId","onItemFirstRender","onItemInitialRender","initialScrollPosition","onScrollPositionChange","initialState","getInitialItemState","onStateChange","getEstimatedItemHeight","getEstimatedVisibleItemRowsCount","getEstimatedInterItemVerticalSpacing","itemsContainerRef","useRef","hasMounted","useLayoutEffect","current","virtualScroller","useCreateVirtualScroller","getItemsContainerElement","Error","_initialState","useMemo","getInitialState","useState","onRender","getState","setState","stateToRender","useStartStopVirtualScroller","useSetNewItemsOnItemsPropertyChange","useValidateTableBodyItemsContainer","useClassName","useStyle","state"],"sources":["../../source/react/useVirtualScroller.js"],"sourcesContent":["import { useLayoutEffect, useMemo, useRef } from 'react'\r\n\r\nimport useState from './useState.js'\r\nimport useCreateVirtualScroller from './useCreateVirtualScroller.js'\r\nimport useStartStopVirtualScroller from './useStartStopVirtualScroller.js'\r\nimport useSetNewItemsOnItemsPropertyChange from './useSetNewItemsOnItemsPropertyChange.js'\r\nimport useValidateTableBodyItemsContainer from './useValidateTableBodyItemsContainer.js'\r\nimport useClassName from './useClassName.js'\r\nimport useStyle from './useStyle.js'\r\n\r\n// When `items` property changes:\r\n// * A new `items` property is supplied to the React component.\r\n// * The React component re-renders itself.\r\n// * `useSetNewItemsOnItemsPropertyChange()` hook is run.\r\n// * `useSetNewItemsOnItemsPropertyChange()` hook detects that the `items` property\r\n// has changed and calls `VirtualScroller.setItems(items)`.\r\n// * `VirtualScroller.setItems(items)` calls `VirtualScroller.setState()`.\r\n// * `VirtualScroller.setState()` calls the `setState()` function.\r\n// * The `setState()` function calls a setter from a `useState()` hook.\r\n// * The React component re-renders itself the second time.\r\n\r\nexport default function useVirtualScroller({\r\n\t// The following are `<VirtualScroller/>` properties.\r\n\t//\r\n\titems: itemsProperty,\r\n\t// Because the use of a `<tbody/>` tag as an items container component can't always be auto-detected,\r\n\t// a developer could manually pass a `tbody: boolean` property.\r\n\t// Futhermore, when using `useVirtualScroller()` hook instead of `<VirtualScroller/>` component,\r\n\t// `itemsContainerComponent` property is not accessible for tag name detection.\r\n\ttbody,\r\n\treadyToStart,\r\n\tstyle: styleProperty,\r\n\tclassName: classNameProperty,\r\n\r\n\t// The following are the \"core\" component options.\r\n\t//\r\n\tbypass,\r\n\t// `preserveScrollPosition` property name is deprecated,\r\n\t// use `preserveScrollPositionOnPrependItems` property instead.\r\n\tpreserveScrollPosition,\r\n\tpreserveScrollPositionOnPrependItems,\r\n\tmeasureItemsBatchSize,\r\n\t// `scrollableContainer` property is deprecated.\r\n\t// Use `getScrollableContainer()` property instead.\r\n\tscrollableContainer,\r\n\tgetScrollableContainer,\r\n\tgetColumnsCount,\r\n\tgetItemId,\r\n\t// `onItemFirstRender(i)` is deprecated, use `onItemInitialRender(item)` instead.\r\n\tonItemFirstRender,\r\n\tonItemInitialRender,\r\n\tinitialScrollPosition,\r\n\tonScrollPositionChange,\r\n\tinitialState,\r\n\tgetInitialItemState,\r\n\tonStateChange,\r\n\tgetEstimatedItemHeight,\r\n\tgetEstimatedVisibleItemRowsCount,\r\n\tgetEstimatedInterItemVerticalSpacing\r\n}) {\r\n\t// A `ref` to the items container element.\r\n\tconst itemsContainerRef = useRef()\r\n\r\n\t// Use `hasMounted` flag to decide if `itemsContainerRef` value should be validated.\r\n\tconst hasMounted = useRef(false)\r\n\tuseLayoutEffect(() => {\r\n\t\thasMounted.current = true\r\n\t}, [])\r\n\r\n\t// Create a `VirtualScroller` instance.\r\n\tconst virtualScroller = useCreateVirtualScroller({\r\n\t\titems: itemsProperty,\r\n\t\tgetEstimatedItemHeight,\r\n\t\tgetEstimatedVisibleItemRowsCount,\r\n\t\tgetEstimatedInterItemVerticalSpacing,\r\n\t\tbypass,\r\n\t\t// bypassBatchSize,\r\n\t\tonItemInitialRender,\r\n\t\t// `onItemFirstRender(i)` is deprecated, use `onItemInitialRender(item)` instead.\r\n\t\tonItemFirstRender,\r\n\t\tinitialScrollPosition,\r\n\t\tonScrollPositionChange,\r\n\t\tmeasureItemsBatchSize,\r\n\t\t// `scrollableContainer` property is deprecated.\r\n\t\t// Use `getScrollableContainer()` property instead.\r\n\t\tscrollableContainer,\r\n\t\tgetScrollableContainer,\r\n\t\tgetColumnsCount,\r\n\t\tgetItemId,\r\n\t\tinitialState,\r\n\t\tgetInitialItemState,\r\n\t\tonStateChange\r\n\t}, {\r\n\t\tgetItemsContainerElement: () => {\r\n\t\t\t// Validate that the developer has correctly passed the returned `itemsContainerRef` property\r\n\t\t\t// as the items container component's `ref`.\r\n\t\t\t//\r\n\t\t\t// `getItemsContainerElement()` function is called both before it has mounted\r\n\t\t\t// and after it has mounted. Only validate the ref's value after it has mounted.\r\n\t\t\t//\r\n\t\t\tif (hasMounted.current) {\r\n\t\t\t\tif (!itemsContainerRef.current) {\r\n\t\t\t\t\tthrow new Error('[virtual-scroller] Did you forget to pass the returned `itemsContainerRef` property as the items container component\\'s `ref`?')\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\t// Return the items container element.\r\n\t\t\treturn itemsContainerRef.current\r\n\t\t}\r\n\t})\r\n\r\n\t// Only compute the initial state once.\r\n\tconst _initialState = useMemo(() => {\r\n\t\treturn virtualScroller.getInitialState()\r\n\t}, [])\r\n\r\n\t// Use React's `useState()` hook for managing `VirtualScroller`'s state lifecycle.\r\n\t// This way, React will re-render the component on every state update.\r\n\tconst {\r\n\t\tgetState,\r\n\t\tsetState,\r\n\t\tstateToRender\r\n\t} = useState({\r\n\t\tinitialState: _initialState,\r\n\t\tonRender: virtualScroller.onRender\r\n\t})\r\n\r\n\t// Use custom (external) state storage in the `VirtualScroller`.\r\n\tuseMemo(() => {\r\n\t\tvirtualScroller.useState({\r\n\t\t\tgetState,\r\n\t\t\tsetState\r\n\t\t})\r\n\t}, [])\r\n\r\n\t// Start `VirtualScroller` on mount.\r\n\t// Stop `VirtualScroller` on unmount.\r\n\tuseStartStopVirtualScroller(virtualScroller, { readyToStart })\r\n\r\n\t// Calls `.setItems()` if `items` property has changed.\r\n\tuseSetNewItemsOnItemsPropertyChange(itemsProperty, {\r\n\t\tvirtualScroller,\r\n\t\t// `preserveScrollPosition` property name is deprecated,\r\n\t\t// use `preserveScrollPositionOnPrependItems` property instead.\r\n\t\tpreserveScrollPosition,\r\n\t\tpreserveScrollPositionOnPrependItems\r\n\t})\r\n\r\n\t// A developer might \"forget\" to pass `itemsContainerComponent=\"tbody\"` property\r\n\t// when using a `<tbody/>` as a container for list items.\r\n\t// This hook validates that the developer didn't \"forget\" to do that in such case.\r\n\tuseValidateTableBodyItemsContainer({\r\n\t\tvirtualScroller,\r\n\t\ttbody\r\n\t})\r\n\r\n\tconst className = useClassName(classNameProperty, {\r\n\t\ttbody\r\n\t})\r\n\r\n\tconst style = useStyle(styleProperty, {\r\n\t\ttbody,\r\n\t\tstate: stateToRender\r\n\t})\r\n\r\n\treturn {\r\n\t\tstate: stateToRender,\r\n\t\tstyle,\r\n\t\tclassName,\r\n\t\titemsContainerRef,\r\n\t\tvirtualScroller\r\n\t}\r\n}"],"mappings":"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"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
var _excluded = ["as", "items", "itemComponent", "itemComponentProps", "itemsContainerComponent", "itemsContainerComponentProps", "itemsContainerRef", "
|
|
1
|
+
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"];
|
|
2
2
|
|
|
3
3
|
function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
|
|
4
4
|
|
|
@@ -6,31 +6,16 @@ function _objectWithoutProperties(source, excluded) { if (source == null) return
|
|
|
6
6
|
|
|
7
7
|
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; }
|
|
8
8
|
|
|
9
|
-
import React, {
|
|
9
|
+
import React, { useLayoutEffect } from 'react';
|
|
10
10
|
import PropTypes from 'prop-types';
|
|
11
|
-
import useState from './useState.js';
|
|
12
11
|
import useVirtualScroller from './useVirtualScroller.js';
|
|
13
|
-
import useVirtualScrollerStartStop from './useVirtualScrollerStartStop.js';
|
|
14
|
-
import useInstanceMethods from './useInstanceMethods.js';
|
|
15
12
|
import useItemKeys from './useItemKeys.js';
|
|
16
13
|
import useSetItemState from './useSetItemState.js';
|
|
17
14
|
import useOnItemHeightDidChange from './useOnItemHeightDidChange.js';
|
|
18
|
-
import
|
|
15
|
+
import useMergeRefs from './useMergeRefs.js';
|
|
16
|
+
import useInstanceMethods from './useInstanceMethods.js';
|
|
19
17
|
import useUpdateItemKeysOnItemsChange from './useUpdateItemKeysOnItemsChange.js';
|
|
20
|
-
import
|
|
21
|
-
import useForwardedRef from './useForwardedRef.js';
|
|
22
|
-
import useClassName from './useClassName.js';
|
|
23
|
-
import useStyle from './useStyle.js';
|
|
24
|
-
import { warn } from '../utility/debug.js'; // When `items` property changes:
|
|
25
|
-
// * A new `items` property is supplied to the React component.
|
|
26
|
-
// * The React component re-renders itself.
|
|
27
|
-
// * `useSetNewItemsOnItemsPropertyChange()` hook is run.
|
|
28
|
-
// * `useSetNewItemsOnItemsPropertyChange()` hook detects that the `items` property
|
|
29
|
-
// has changed and calls `VirtualScroller.setItems(items)`.
|
|
30
|
-
// * `VirtualScroller.setItems(items)` calls `VirtualScroller.setState()`.
|
|
31
|
-
// * `VirtualScroller.setState()` calls the `setState()` function.
|
|
32
|
-
// * The `setState()` function calls a setter from a `useState()` hook.
|
|
33
|
-
// * The React component re-renders itself the second time.
|
|
18
|
+
import { warn } from '../utility/debug.js';
|
|
34
19
|
|
|
35
20
|
function VirtualScroller(_ref, ref) {
|
|
36
21
|
var as = _ref.as,
|
|
@@ -39,11 +24,7 @@ function VirtualScroller(_ref, ref) {
|
|
|
39
24
|
itemComponentProps = _ref.itemComponentProps,
|
|
40
25
|
ItemsContainerComponent = _ref.itemsContainerComponent,
|
|
41
26
|
itemsContainerComponentProps = _ref.itemsContainerComponentProps,
|
|
42
|
-
|
|
43
|
-
estimatedItemHeight = _ref.estimatedItemHeight,
|
|
44
|
-
getEstimatedItemHeight = _ref.getEstimatedItemHeight,
|
|
45
|
-
getEstimatedVisibleItemRowsCount = _ref.getEstimatedVisibleItemRowsCount,
|
|
46
|
-
getEstimatedInterItemVerticalSpacing = _ref.getEstimatedInterItemVerticalSpacing,
|
|
27
|
+
itemsContainerRefProperty = _ref.itemsContainerRef,
|
|
47
28
|
onMount = _ref.onMount,
|
|
48
29
|
tbody = _ref.tbody,
|
|
49
30
|
readyToStart = _ref.readyToStart,
|
|
@@ -63,6 +44,10 @@ function VirtualScroller(_ref, ref) {
|
|
|
63
44
|
initialState = _ref.initialState,
|
|
64
45
|
getInitialItemState = _ref.getInitialItemState,
|
|
65
46
|
onStateChange = _ref.onStateChange,
|
|
47
|
+
estimatedItemHeight = _ref.estimatedItemHeight,
|
|
48
|
+
getEstimatedItemHeight = _ref.getEstimatedItemHeight,
|
|
49
|
+
getEstimatedVisibleItemRowsCount = _ref.getEstimatedVisibleItemRowsCount,
|
|
50
|
+
getEstimatedInterItemVerticalSpacing = _ref.getEstimatedInterItemVerticalSpacing,
|
|
66
51
|
rest = _objectWithoutProperties(_ref, _excluded);
|
|
67
52
|
|
|
68
53
|
// Previously, `as` property was being used instead of `itemsContainerComponent`,
|
|
@@ -71,47 +56,34 @@ function VirtualScroller(_ref, ref) {
|
|
|
71
56
|
// The default `"div"` fallback value is just a legacy compatibility relic, and so is the `as` property.
|
|
72
57
|
if (!ItemsContainerComponent) {
|
|
73
58
|
ItemsContainerComponent = as || 'div';
|
|
74
|
-
} //
|
|
75
|
-
// Instead, it always derived `tbody` property value from `as` property value by comparing it to `"tbody"` string.
|
|
76
|
-
// As a result, it seemed like the explicit passing of `tbody` property didn't really work as intended.
|
|
77
|
-
// In the end, it was decided that perhaps `tbody` property value should always be derived from `as` property
|
|
78
|
-
// without a developer having to manually specify it. So the `tbody` property was deprecated.
|
|
79
|
-
// It still exists though for backwards compatibility with the older versions of the package.
|
|
59
|
+
} // In simple cases, the use of a `<tbody/>` tag as an items container component could be auto-detected.
|
|
80
60
|
|
|
81
61
|
|
|
82
62
|
if (tbody === undefined) {
|
|
83
|
-
// `tbody` should
|
|
63
|
+
// `tbody` auto-detection should happen before any DOM Elements have been mounted,
|
|
64
|
+
// i.e. it can't rely on the trivial `getItemsContainerElement().tagName === 'TBODY'` check.
|
|
84
65
|
// This is because during Server-Side Render there's no DOM Elements tree at all.
|
|
85
66
|
// And server-sider render result is required to be exactly the same as client-side render result.
|
|
86
67
|
// This means that `tbody` detection for the purposes of getting the initial
|
|
87
68
|
// `className` or `style` property values must not rely on any DOM Elements at all,
|
|
88
69
|
// and should use some other means such as explicitly passing a `tbody: true` property
|
|
89
|
-
//
|
|
90
|
-
// `itemsContainerCompoent` property value.
|
|
70
|
+
// or detecting `<tbody/>` tag usage from the `itemsContainerCompoent` property value.
|
|
91
71
|
tbody = ItemsContainerComponent === 'tbody';
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
var _useForwardedRef = useForwardedRef(itemsContainerRef),
|
|
96
|
-
setItemsContainerRef = _useForwardedRef.setRef,
|
|
97
|
-
itemsContainer = _useForwardedRef.internalRef; // Create a `VirtualScroller` instance.
|
|
72
|
+
}
|
|
98
73
|
|
|
99
|
-
|
|
100
|
-
var virtualScroller = useVirtualScroller({
|
|
74
|
+
var _useVirtualScroller = useVirtualScroller({
|
|
101
75
|
items: itemsProperty,
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
76
|
+
tbody: tbody,
|
|
77
|
+
readyToStart: readyToStart,
|
|
78
|
+
style: itemsContainerComponentProps && itemsContainerComponentProps.style,
|
|
79
|
+
className: classNameProperty || itemsContainerComponentProps && itemsContainerComponentProps.className,
|
|
80
|
+
// The following are the "core" component options.
|
|
81
|
+
//
|
|
108
82
|
bypass: bypass,
|
|
109
|
-
//
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
initialScrollPosition: initialScrollPosition,
|
|
114
|
-
onScrollPositionChange: onScrollPositionChange,
|
|
83
|
+
// `preserveScrollPosition` property name is deprecated,
|
|
84
|
+
// use `preserveScrollPositionOnPrependItems` property instead.
|
|
85
|
+
preserveScrollPosition: preserveScrollPosition,
|
|
86
|
+
preserveScrollPositionOnPrependItems: preserveScrollPositionOnPrependItems,
|
|
115
87
|
measureItemsBatchSize: measureItemsBatchSize,
|
|
116
88
|
// `scrollableContainer` property is deprecated.
|
|
117
89
|
// Use `getScrollableContainer()` property instead.
|
|
@@ -119,39 +91,30 @@ function VirtualScroller(_ref, ref) {
|
|
|
119
91
|
getScrollableContainer: getScrollableContainer,
|
|
120
92
|
getColumnsCount: getColumnsCount,
|
|
121
93
|
getItemId: getItemId,
|
|
94
|
+
// `onItemFirstRender(i)` is deprecated, use `onItemInitialRender(item)` instead.
|
|
95
|
+
onItemFirstRender: onItemFirstRender,
|
|
96
|
+
onItemInitialRender: onItemInitialRender,
|
|
97
|
+
initialScrollPosition: initialScrollPosition,
|
|
98
|
+
onScrollPositionChange: onScrollPositionChange,
|
|
122
99
|
initialState: initialState,
|
|
123
100
|
getInitialItemState: getInitialItemState,
|
|
124
|
-
onStateChange: onStateChange
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
// This way, React will re-render the component on every state update.
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
var _useState = useState({
|
|
136
|
-
initialState: _initialState,
|
|
137
|
-
onRender: virtualScroller.onRender
|
|
101
|
+
onStateChange: onStateChange,
|
|
102
|
+
getEstimatedItemHeight: getEstimatedItemHeight || ( // `estimatedItemHeight` property name is deprecated,
|
|
103
|
+
// use `getEstimatedItemHeight` property instead.
|
|
104
|
+
typeof estimatedItemHeight === 'number' ? function () {
|
|
105
|
+
return estimatedItemHeight;
|
|
106
|
+
} : undefined),
|
|
107
|
+
getEstimatedVisibleItemRowsCount: getEstimatedVisibleItemRowsCount,
|
|
108
|
+
getEstimatedInterItemVerticalSpacing: getEstimatedInterItemVerticalSpacing
|
|
138
109
|
}),
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
110
|
+
stateToRender = _useVirtualScroller.state,
|
|
111
|
+
style = _useVirtualScroller.style,
|
|
112
|
+
className = _useVirtualScroller.className,
|
|
113
|
+
itemsContainerRef = _useVirtualScroller.itemsContainerRef,
|
|
114
|
+
virtualScroller = _useVirtualScroller.virtualScroller; // List items "container" DOM Element reference.
|
|
143
115
|
|
|
144
|
-
useMemo(function () {
|
|
145
|
-
virtualScroller.useState({
|
|
146
|
-
getState: getState,
|
|
147
|
-
setState: setState
|
|
148
|
-
});
|
|
149
|
-
}, []); // Start `VirtualScroller` on mount.
|
|
150
|
-
// Stop `VirtualScroller` on unmount.
|
|
151
116
|
|
|
152
|
-
|
|
153
|
-
readyToStart: readyToStart
|
|
154
|
-
}); // List items are rendered with `key`s so that React doesn't
|
|
117
|
+
var setItemsContainerRef = useMergeRefs(itemsContainerRef, itemsContainerRefProperty); // List items are rendered with `key`s so that React doesn't
|
|
155
118
|
// "reuse" `itemComponent`s in cases when `items` are changed.
|
|
156
119
|
|
|
157
120
|
var _useItemKeys = useItemKeys({
|
|
@@ -160,10 +123,16 @@ function VirtualScroller(_ref, ref) {
|
|
|
160
123
|
getItemKey = _useItemKeys.getItemKey,
|
|
161
124
|
onItemKeysReset = _useItemKeys.onItemKeysReset,
|
|
162
125
|
usesAutogeneratedItemKeys = _useItemKeys.usesAutogeneratedItemKeys,
|
|
163
|
-
updateItemKeysForNewItems = _useItemKeys.updateItemKeysForNewItems; //
|
|
164
|
-
// so that item components don't get re-rendered needlessly.
|
|
126
|
+
updateItemKeysForNewItems = _useItemKeys.updateItemKeysForNewItems; // Updates `key`s if item indexes have changed.
|
|
165
127
|
|
|
166
128
|
|
|
129
|
+
useUpdateItemKeysOnItemsChange(stateToRender.items, {
|
|
130
|
+
virtualScroller: virtualScroller,
|
|
131
|
+
usesAutogeneratedItemKeys: usesAutogeneratedItemKeys,
|
|
132
|
+
updateItemKeysForNewItems: updateItemKeysForNewItems
|
|
133
|
+
}); // Cache per-item `setItemState` functions' "references"
|
|
134
|
+
// so that item components don't get re-rendered needlessly.
|
|
135
|
+
|
|
167
136
|
var getSetItemState = useSetItemState({
|
|
168
137
|
getItemKey: getItemKey,
|
|
169
138
|
onItemKeysReset: onItemKeysReset,
|
|
@@ -175,20 +144,6 @@ function VirtualScroller(_ref, ref) {
|
|
|
175
144
|
getItemKey: getItemKey,
|
|
176
145
|
onItemKeysReset: onItemKeysReset,
|
|
177
146
|
virtualScroller: virtualScroller
|
|
178
|
-
}); // Calls `.setItems()` if `items` property has changed.
|
|
179
|
-
|
|
180
|
-
useSetNewItemsOnItemsPropertyChange(itemsProperty, {
|
|
181
|
-
virtualScroller: virtualScroller,
|
|
182
|
-
// `preserveScrollPosition` property name is deprecated,
|
|
183
|
-
// use `preserveScrollPositionOnPrependItems` property instead.
|
|
184
|
-
preserveScrollPosition: preserveScrollPosition,
|
|
185
|
-
preserveScrollPositionOnPrependItems: preserveScrollPositionOnPrependItems
|
|
186
|
-
}); // Updates `key`s if item indexes have changed.
|
|
187
|
-
|
|
188
|
-
useUpdateItemKeysOnItemsChange(stateToRender.items, {
|
|
189
|
-
virtualScroller: virtualScroller,
|
|
190
|
-
usesAutogeneratedItemKeys: usesAutogeneratedItemKeys,
|
|
191
|
-
updateItemKeysForNewItems: updateItemKeysForNewItems
|
|
192
147
|
}); // Add instance methods to the React component.
|
|
193
148
|
|
|
194
149
|
useInstanceMethods(ref, {
|
|
@@ -202,14 +157,7 @@ function VirtualScroller(_ref, ref) {
|
|
|
202
157
|
warn('`onMount` property is deprecated');
|
|
203
158
|
onMount();
|
|
204
159
|
}
|
|
205
|
-
}, []); //
|
|
206
|
-
// when using a `<tbody/>` as a container for list items.
|
|
207
|
-
// This hook validates that the developer didn't "forget" to do that in such case.
|
|
208
|
-
|
|
209
|
-
useValidateTableBodyItemsContainer({
|
|
210
|
-
virtualScroller: virtualScroller,
|
|
211
|
-
tbody: tbody
|
|
212
|
-
}); // `willRender()` function is no longer used.
|
|
160
|
+
}, []); // `willRender()` function is no longer used.
|
|
213
161
|
//
|
|
214
162
|
// // `getSnapshotBeforeUpdate()` is called right before `componentDidUpdate()`.
|
|
215
163
|
// // A hook equivalent/workaround for `getSnapshotBeforeUpdate()`:
|
|
@@ -224,15 +172,6 @@ function VirtualScroller(_ref, ref) {
|
|
|
224
172
|
// return null
|
|
225
173
|
// }
|
|
226
174
|
|
|
227
|
-
var classNamePassThrough = classNameProperty || itemsContainerComponentProps && itemsContainerComponentProps.className;
|
|
228
|
-
var className = useClassName(classNamePassThrough, {
|
|
229
|
-
tbody: tbody
|
|
230
|
-
});
|
|
231
|
-
var stylePassThrough = itemsContainerComponentProps && itemsContainerComponentProps.style;
|
|
232
|
-
var style = useStyle(stylePassThrough, {
|
|
233
|
-
tbody: tbody,
|
|
234
|
-
state: stateToRender
|
|
235
|
-
});
|
|
236
175
|
var currentItems = stateToRender.items,
|
|
237
176
|
itemStates = stateToRender.itemStates,
|
|
238
177
|
firstShownItemIndex = stateToRender.firstShownItemIndex,
|
|
@@ -309,9 +248,7 @@ VirtualScroller.propTypes = {
|
|
|
309
248
|
getEstimatedInterItemVerticalSpacing: PropTypes.func,
|
|
310
249
|
bypass: PropTypes.bool,
|
|
311
250
|
// bypassBatchSize: PropTypes.number,
|
|
312
|
-
|
|
313
|
-
// Pass `as: "tbody"` property instead.
|
|
314
|
-
// tbody: PropTypes.bool,
|
|
251
|
+
tbody: PropTypes.bool,
|
|
315
252
|
preserveScrollPositionOnPrependItems: PropTypes.bool,
|
|
316
253
|
// `preserveScrollPosition` property name is deprecated,
|
|
317
254
|
// use `preserveScrollPositionOnPrependItems` instead.
|
|
@@ -344,5 +281,17 @@ VirtualScroller.propTypes = {
|
|
|
344
281
|
verticalSpacing: PropTypes.number
|
|
345
282
|
}),
|
|
346
283
|
getInitialItemState: PropTypes.func
|
|
347
|
-
};
|
|
284
|
+
}; // Legacy compatibility:
|
|
285
|
+
//
|
|
286
|
+
// Originally, the default export of the `virtual-scroller/react` subpackage
|
|
287
|
+
// was only the `VirtualScroller` component, and there were no other exports.
|
|
288
|
+
//
|
|
289
|
+
// Later, `useVirtualScroller()` hook export was added.
|
|
290
|
+
// In order to maintain legacy compatibility, the new exports shouldn't "break"
|
|
291
|
+
// the existing environments that were using the old versions of the package.
|
|
292
|
+
// This means that in non-ES6-import environments, any additional exports
|
|
293
|
+
// should be added directly to the default `VirtualScroller` export.
|
|
294
|
+
//
|
|
295
|
+
|
|
296
|
+
VirtualScroller.useVirtualScroller = useVirtualScroller;
|
|
348
297
|
//# sourceMappingURL=VirtualScroller.js.map
|