@etsoo/react 1.7.94 → 1.7.96

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (93) hide show
  1. package/README.md +2 -1
  2. package/__tests__/EventWatcher.tsx +21 -21
  3. package/__tests__/ReactUtils.ts +4 -4
  4. package/__tests__/tsconfig.json +17 -17
  5. package/babel.config.json +8 -8
  6. package/lib/app/CoreConstants.js +2 -2
  7. package/lib/app/EventWatcher.d.ts +1 -1
  8. package/lib/app/EventWatcher.js +3 -5
  9. package/lib/app/InputDialogProps.d.ts +2 -2
  10. package/lib/app/ReactUtils.d.ts +2 -2
  11. package/lib/app/ReactUtils.js +20 -19
  12. package/lib/components/DnDList.d.ts +3 -3
  13. package/lib/components/DnDList.js +4 -4
  14. package/lib/components/DynamicRouter.d.ts +2 -2
  15. package/lib/components/DynamicRouter.js +2 -2
  16. package/lib/components/GridColumn.d.ts +6 -6
  17. package/lib/components/GridColumn.js +7 -7
  18. package/lib/components/GridLoader.d.ts +4 -4
  19. package/lib/components/GridLoader.js +2 -2
  20. package/lib/components/GridMethodRef.d.ts +2 -2
  21. package/lib/components/ListItemReact.d.ts +2 -2
  22. package/lib/components/ScrollRestoration.js +3 -3
  23. package/lib/components/ScrollerGrid.d.ts +7 -12
  24. package/lib/components/ScrollerGrid.js +13 -17
  25. package/lib/components/ScrollerList.d.ts +6 -10
  26. package/lib/components/ScrollerList.js +15 -14
  27. package/lib/custom/CustomFieldReact.d.ts +1 -1
  28. package/lib/index.d.ts +32 -32
  29. package/lib/index.js +31 -31
  30. package/lib/notifier/Notifier.d.ts +5 -5
  31. package/lib/notifier/Notifier.js +7 -7
  32. package/lib/states/CultureState.d.ts +3 -3
  33. package/lib/states/CultureState.js +3 -3
  34. package/lib/states/IState.d.ts +2 -2
  35. package/lib/states/PageState.d.ts +2 -2
  36. package/lib/states/PageState.js +2 -3
  37. package/lib/states/State.d.ts +3 -3
  38. package/lib/states/State.js +2 -2
  39. package/lib/states/UserState.d.ts +2 -2
  40. package/lib/states/UserState.js +5 -5
  41. package/lib/uses/useAsyncState.d.ts +1 -1
  42. package/lib/uses/useAsyncState.js +1 -1
  43. package/lib/uses/useCombinedRefs.js +2 -2
  44. package/lib/uses/useDelayedExecutor.d.ts +1 -1
  45. package/lib/uses/useDelayedExecutor.js +2 -2
  46. package/lib/uses/useDimensions.d.ts +1 -1
  47. package/lib/uses/useDimensions.js +3 -3
  48. package/lib/uses/useParamsEx.d.ts +1 -1
  49. package/lib/uses/useParamsEx.js +2 -2
  50. package/lib/uses/useRefs.d.ts +2 -2
  51. package/lib/uses/useRefs.js +1 -1
  52. package/lib/uses/useSearchParamsEx.d.ts +1 -1
  53. package/lib/uses/useSearchParamsEx.js +3 -3
  54. package/lib/uses/useTimeout.js +2 -2
  55. package/lib/uses/useWindowScroll.js +3 -3
  56. package/lib/uses/useWindowSize.js +4 -5
  57. package/package.json +72 -74
  58. package/src/app/CoreConstants.ts +8 -8
  59. package/src/app/EventWatcher.ts +50 -52
  60. package/src/app/InputDialogProps.ts +16 -16
  61. package/src/app/ReactUtils.ts +206 -208
  62. package/src/components/DnDList.tsx +268 -283
  63. package/src/components/DynamicRouter.tsx +35 -35
  64. package/src/components/GridColumn.ts +201 -201
  65. package/src/components/GridLoader.ts +121 -121
  66. package/src/components/GridMethodRef.ts +26 -26
  67. package/src/components/ListItemReact.ts +2 -2
  68. package/src/components/ScrollRestoration.tsx +24 -24
  69. package/src/components/ScrollerGrid.tsx +428 -448
  70. package/src/components/ScrollerList.tsx +320 -332
  71. package/src/custom/CustomFieldReact.ts +12 -12
  72. package/src/index.ts +35 -35
  73. package/src/notifier/Notifier.ts +229 -240
  74. package/src/states/CultureState.ts +51 -52
  75. package/src/states/IState.ts +19 -19
  76. package/src/states/PageState.ts +63 -66
  77. package/src/states/State.tsx +47 -51
  78. package/src/states/UserState.ts +98 -98
  79. package/src/uses/useAsyncState.ts +37 -39
  80. package/src/uses/useCombinedRefs.ts +16 -16
  81. package/src/uses/useDelayedExecutor.ts +8 -8
  82. package/src/uses/useDimensions.ts +102 -103
  83. package/src/uses/useParamsEx.ts +6 -6
  84. package/src/uses/useRefs.ts +6 -6
  85. package/src/uses/useSearchParamsEx.ts +13 -13
  86. package/src/uses/useTimeout.ts +17 -17
  87. package/src/uses/useWindowScroll.ts +43 -43
  88. package/src/uses/useWindowSize.ts +46 -49
  89. package/tsconfig.json +17 -17
  90. package/.eslintignore +0 -3
  91. package/.eslintrc.json +0 -38
  92. package/.prettierignore +0 -5
  93. package/.prettierrc +0 -6
@@ -1,105 +1,100 @@
1
- import { DataTypes, Utils } from '@etsoo/shared';
2
- import React from 'react';
1
+ import { DataTypes, Utils } from "@etsoo/shared";
2
+ import React from "react";
3
3
  import {
4
- Align,
5
- FixedSizeList,
6
- ListChildComponentProps,
7
- ListOnItemsRenderedProps,
8
- ListProps,
9
- VariableSizeList
10
- } from 'react-window';
11
- import { useCombinedRefs } from '../uses/useCombinedRefs';
4
+ Align,
5
+ FixedSizeList,
6
+ ListChildComponentProps,
7
+ ListOnItemsRenderedProps,
8
+ ListProps,
9
+ VariableSizeList
10
+ } from "react-window";
11
+ import { useCombinedRefs } from "../uses/useCombinedRefs";
12
12
  import {
13
- GridLoadDataProps,
14
- GridLoader,
15
- GridLoaderPartialStates,
16
- GridLoaderStates,
17
- GridSizeGet
18
- } from './GridLoader';
19
- import { GridMethodRef } from './GridMethodRef';
13
+ GridLoadDataProps,
14
+ GridLoader,
15
+ GridLoaderPartialStates,
16
+ GridLoaderStates,
17
+ GridSizeGet
18
+ } from "./GridLoader";
19
+ import { GridMethodRef } from "./GridMethodRef";
20
20
 
21
21
  /**
22
22
  * Scroller vertical list props
23
23
  */
24
24
  export interface ScrollerListProps<T extends object>
25
- extends GridLoader<T>,
26
- Omit<
27
- ListProps<T>,
28
- 'outerRef' | 'height' | 'width' | 'children' | 'itemCount' // Exclude these props, shoud be exisited otherwise will be failed
29
- > {
30
- /**
31
- * Default order by asc/desc
32
- */
33
- defaultOrderByAsc?: boolean;
34
-
35
- /**
36
- * Methods ref
37
- */
38
- mRef?: React.Ref<ScrollerListForwardRef<T>>;
39
-
40
- /**
41
- * Outer div ref
42
- */
43
- oRef?: React.Ref<HTMLDivElement>;
44
-
45
- /**
46
- * Height of the list
47
- */
48
- height?: number;
49
-
50
- /**
51
- * Width of the list
52
- */
53
- width?: number | string;
54
-
55
- /**
56
- * Id field
57
- */
58
- idField?: DataTypes.Keys<T>;
59
-
60
- /**
61
- * Item renderer
62
- */
63
- itemRenderer: (props: ListChildComponentProps<T>) => React.ReactElement;
64
-
65
- /**
66
- * Item size, a function indicates its a variable size list
67
- */
68
- itemSize: ((index: number) => number) | number;
25
+ extends GridLoader<T>,
26
+ Omit<
27
+ ListProps<T>,
28
+ "outerRef" | "height" | "width" | "children" | "itemCount" // Exclude these props, shoud be exisited otherwise will be failed
29
+ > {
30
+ /**
31
+ * Methods ref
32
+ */
33
+ mRef?: React.Ref<ScrollerListForwardRef<T>>;
34
+
35
+ /**
36
+ * Outer div ref
37
+ */
38
+ oRef?: React.Ref<HTMLDivElement>;
39
+
40
+ /**
41
+ * Height of the list
42
+ */
43
+ height?: number;
44
+
45
+ /**
46
+ * Width of the list
47
+ */
48
+ width?: number | string;
49
+
50
+ /**
51
+ * Id field
52
+ */
53
+ idField?: DataTypes.Keys<T>;
54
+
55
+ /**
56
+ * Item renderer
57
+ */
58
+ itemRenderer: (props: ListChildComponentProps<T>) => React.ReactElement;
59
+
60
+ /**
61
+ * Item size, a function indicates its a variable size list
62
+ */
63
+ itemSize: ((index: number) => number) | number;
69
64
  }
70
65
 
71
66
  /**
72
67
  * Scroller list ref
73
68
  */
74
69
  export interface ScrollerListRef {
75
- /**
76
- * Scroll to the specified offset (scrollTop or scrollLeft, depending on the direction prop).
77
- */
78
- scrollTo(scrollOffset: number): void;
79
-
80
- /**
81
- * Scroll to the specified item.
82
- */
83
- scrollToItem(index: number, align?: Align): void;
70
+ /**
71
+ * Scroll to the specified offset (scrollTop or scrollLeft, depending on the direction prop).
72
+ */
73
+ scrollTo(scrollOffset: number): void;
74
+
75
+ /**
76
+ * Scroll to the specified item.
77
+ */
78
+ scrollToItem(index: number, align?: Align): void;
84
79
  }
85
80
 
86
81
  /**
87
82
  * Scroller list forward ref
88
83
  */
89
84
  export interface ScrollerListForwardRef<T> extends GridMethodRef<T> {
90
- /**
91
- * Refresh latest page data
92
- */
93
- refresh(): void;
85
+ /**
86
+ * Refresh latest page data
87
+ */
88
+ refresh(): void;
94
89
  }
95
90
 
96
91
  // Calculate loadBatchSize
97
92
  const calculateBatchSize = (
98
- height: number,
99
- itemSize: ((index: number) => number) | number
93
+ height: number,
94
+ itemSize: ((index: number) => number) | number
100
95
  ) => {
101
- const size = Utils.getResult(itemSize, 0);
102
- return 2 + Math.ceil(height / size);
96
+ const size = Utils.getResult(itemSize, 0);
97
+ return 2 + Math.ceil(height / size);
103
98
  };
104
99
 
105
100
  /**
@@ -108,274 +103,267 @@ const calculateBatchSize = (
108
103
  * @returns Component
109
104
  */
110
105
  export const ScrollerList = <T extends object>(props: ScrollerListProps<T>) => {
111
- // Destruct
112
- const {
113
- autoLoad = true,
114
- defaultOrderBy,
115
- defaultOrderByAsc,
116
- height = document.documentElement.clientHeight,
117
- width = '100%',
118
- mRef,
119
- oRef,
120
- style = {},
121
- idField = 'id' as DataTypes.Keys<T>,
122
- itemRenderer,
123
- itemSize,
124
- loadBatchSize = calculateBatchSize(height, itemSize),
125
- loadData,
126
- threshold = GridSizeGet(loadBatchSize, height) / 2,
127
- onItemsRendered,
128
- onInitLoad,
129
- onUpdateRows,
130
- ...rest
131
- } = props;
132
-
133
- // Style
134
- Object.assign(style, {
135
- width: '100%',
136
- height: '100%',
137
- display: 'inline-block'
138
- });
106
+ // Destruct
107
+ const {
108
+ autoLoad = true,
109
+ defaultOrderBy,
110
+ height = document.documentElement.clientHeight,
111
+ width = "100%",
112
+ mRef,
113
+ oRef,
114
+ style = {},
115
+ idField = "id" as DataTypes.Keys<T>,
116
+ itemRenderer,
117
+ itemSize,
118
+ loadBatchSize = calculateBatchSize(height, itemSize),
119
+ loadData,
120
+ threshold = GridSizeGet(loadBatchSize, height) / 2,
121
+ onItemsRendered,
122
+ onInitLoad,
123
+ onUpdateRows,
124
+ ...rest
125
+ } = props;
126
+
127
+ // Style
128
+ Object.assign(style, {
129
+ width: "100%",
130
+ height: "100%",
131
+ display: "inline-block"
132
+ });
133
+
134
+ // Refs
135
+ const listRef = React.useRef<any>();
136
+ const outerRef = React.useRef<HTMLDivElement>();
137
+
138
+ const refs = useCombinedRefs(oRef, outerRef);
139
+
140
+ // Rows
141
+ const [rows, updateRows] = React.useState<T[]>([]);
142
+ const setRows = (rows: T[], reset: boolean = false) => {
143
+ stateRefs.current.loadedItems = rows.length;
144
+ updateRows(rows);
145
+
146
+ if (!reset && onUpdateRows) onUpdateRows(rows, stateRefs.current);
147
+ };
148
+
149
+ // States
150
+ const batchSize = GridSizeGet(loadBatchSize, height);
151
+ const stateRefs = React.useRef<GridLoaderStates<T>>({
152
+ queryPaging: {
153
+ currentPage: 0,
154
+ orderBy: defaultOrderBy,
155
+ batchSize
156
+ },
157
+ autoLoad,
158
+ loadedItems: 0,
159
+ hasNextPage: true,
160
+ isNextPageLoading: false,
161
+ selectedItems: [],
162
+ idCache: {}
163
+ });
164
+
165
+ // Load data
166
+ const loadDataLocal = (pageAdd: number = 1) => {
167
+ // Prevent multiple loadings
168
+ if (!stateRefs.current.hasNextPage || stateRefs.current.isNextPageLoading)
169
+ return;
170
+
171
+ // Update state
172
+ stateRefs.current.isNextPageLoading = true;
173
+
174
+ // Parameters
175
+ const { queryPaging, data } = stateRefs.current;
176
+
177
+ const loadProps: GridLoadDataProps = {
178
+ queryPaging,
179
+ data
180
+ };
139
181
 
140
- // Refs
141
- const listRef = React.useRef<any>();
142
- const outerRef = React.useRef<HTMLDivElement>();
182
+ loadData(loadProps).then((result) => {
183
+ if (result == null || stateRefs.current.isMounted === false) {
184
+ return;
185
+ }
186
+ stateRefs.current.isMounted = true;
187
+
188
+ const newItems = result.length;
189
+ stateRefs.current.lastLoadedItems = newItems;
190
+ stateRefs.current.hasNextPage = newItems >= batchSize;
191
+ stateRefs.current.isNextPageLoading = false;
192
+
193
+ if (pageAdd === 0) {
194
+ // New items
195
+ const newRows = stateRefs.current.lastLoadedItems
196
+ ? [...rows]
197
+ .splice(
198
+ rows.length - stateRefs.current.lastLoadedItems,
199
+ stateRefs.current.lastLoadedItems
200
+ )
201
+ .concat(result)
202
+ : result;
203
+
204
+ stateRefs.current.idCache = {};
205
+ for (const row of newRows) {
206
+ const id = row[idField] as any;
207
+ stateRefs.current.idCache[id] = null;
208
+ }
143
209
 
144
- const refs = useCombinedRefs(oRef, outerRef);
210
+ // Update rows
211
+ setRows(newRows);
212
+ } else {
213
+ if (stateRefs.current.queryPaging.currentPage == null)
214
+ stateRefs.current.queryPaging.currentPage = pageAdd;
215
+ else stateRefs.current.queryPaging.currentPage += pageAdd;
216
+
217
+ // Update rows, avoid duplicate items
218
+ const newRows = [...rows];
219
+
220
+ for (const item of result) {
221
+ const id = item[idField] as any;
222
+ if (stateRefs.current.idCache[id] === undefined) {
223
+ newRows.push(item);
224
+ }
225
+ }
145
226
 
146
- // Rows
147
- const [rows, updateRows] = React.useState<T[]>([]);
148
- const setRows = (rows: T[], reset: boolean = false) => {
149
- stateRefs.current.loadedItems = rows.length;
150
- updateRows(rows);
227
+ setRows(newRows);
228
+ }
229
+ });
230
+ };
151
231
 
152
- if (!reset && onUpdateRows) onUpdateRows(rows, stateRefs.current);
232
+ const itemRendererLocal = (itemProps: ListChildComponentProps<T>) => {
233
+ // Custom render
234
+ return itemRenderer({
235
+ ...itemProps,
236
+ data: rows[itemProps.index]
237
+ });
238
+ };
239
+
240
+ // Reset the state and load again
241
+ const reset = (add?: GridLoaderPartialStates<T>, items: T[] = []) => {
242
+ const { queryPaging, ...rest } = add ?? {};
243
+ const resetState: GridLoaderPartialStates<T> = {
244
+ autoLoad: true,
245
+ lastLoadedItems: undefined,
246
+ loadedItems: 0,
247
+ hasNextPage: true,
248
+ isNextPageLoading: false,
249
+ ...rest
153
250
  };
251
+ Object.assign(stateRefs.current, resetState);
252
+ Object.assign(stateRefs.current.queryPaging, {
253
+ currentPage: 0,
254
+ ...queryPaging
255
+ });
154
256
 
155
- // States
156
- const batchSize = GridSizeGet(loadBatchSize, height);
157
- const stateRefs = React.useRef<GridLoaderStates<T>>({
158
- queryPaging: {
159
- currentPage: 0,
160
- orderBy: defaultOrderBy,
161
- orderByAsc: defaultOrderByAsc,
162
- batchSize
257
+ // Reset
258
+ if (stateRefs.current.isMounted !== false) setRows(items, true);
259
+ };
260
+
261
+ React.useImperativeHandle(
262
+ mRef,
263
+ () => {
264
+ const refMethods = listRef.current as ScrollerListRef;
265
+
266
+ return {
267
+ delete(index) {
268
+ const item = rows.at(index);
269
+ if (item) {
270
+ const newRows = [...rows];
271
+ newRows.splice(index, 1);
272
+ setRows(newRows);
273
+ }
274
+ return item;
275
+ },
276
+ insert(item, start) {
277
+ const newRows = [...rows];
278
+ newRows.splice(start, 0, item);
279
+ setRows(newRows);
280
+ },
281
+ refresh(): void {
282
+ loadDataLocal(0);
163
283
  },
164
- autoLoad,
165
- loadedItems: 0,
166
- hasNextPage: true,
167
- isNextPageLoading: false,
168
- selectedItems: [],
169
- idCache: {}
170
- });
171
284
 
172
- // Load data
173
- const loadDataLocal = (pageAdd: number = 1) => {
174
- // Prevent multiple loadings
175
- if (
176
- !stateRefs.current.hasNextPage ||
177
- stateRefs.current.isNextPageLoading
178
- )
179
- return;
180
-
181
- // Update state
182
- stateRefs.current.isNextPageLoading = true;
183
-
184
- // Parameters
185
- const { queryPaging, data } = stateRefs.current;
186
-
187
- const loadProps: GridLoadDataProps = {
188
- queryPaging,
189
- data
190
- };
191
-
192
- loadData(loadProps).then((result) => {
193
- if (result == null || stateRefs.current.isMounted === false) {
194
- return;
195
- }
196
- stateRefs.current.isMounted = true;
197
-
198
- const newItems = result.length;
199
- stateRefs.current.lastLoadedItems = newItems;
200
- stateRefs.current.hasNextPage = newItems >= batchSize;
201
- stateRefs.current.isNextPageLoading = false;
202
-
203
- if (pageAdd === 0) {
204
- // New items
205
- const newRows = stateRefs.current.lastLoadedItems
206
- ? [...rows]
207
- .splice(
208
- rows.length - stateRefs.current.lastLoadedItems,
209
- stateRefs.current.lastLoadedItems
210
- )
211
- .concat(result)
212
- : result;
213
-
214
- stateRefs.current.idCache = {};
215
- for (const row of newRows) {
216
- const id = row[idField] as any;
217
- stateRefs.current.idCache[id] = null;
218
- }
219
-
220
- // Update rows
221
- setRows(newRows);
222
- } else {
223
- stateRefs.current.queryPaging.currentPage += pageAdd;
224
-
225
- // Update rows, avoid duplicate items
226
- const newRows = [...rows];
227
-
228
- for (const item of result) {
229
- const id = item[idField] as any;
230
- if (stateRefs.current.idCache[id] === undefined) {
231
- newRows.push(item);
232
- }
233
- }
234
-
235
- setRows(newRows);
236
- }
237
- });
238
- };
285
+ reset,
239
286
 
240
- const itemRendererLocal = (itemProps: ListChildComponentProps<T>) => {
241
- // Custom render
242
- return itemRenderer({
243
- ...itemProps,
244
- data: rows[itemProps.index]
245
- });
246
- };
287
+ scrollToRef(scrollOffset: number): void {
288
+ refMethods.scrollTo(scrollOffset);
289
+ },
247
290
 
248
- // Reset the state and load again
249
- const reset = (add?: GridLoaderPartialStates<T>, items: T[] = []) => {
250
- const { queryPaging, ...rest } = add ?? {};
251
- const resetState: GridLoaderPartialStates<T> = {
252
- autoLoad: true,
253
- lastLoadedItems: undefined,
254
- loadedItems: 0,
255
- hasNextPage: true,
256
- isNextPageLoading: false,
257
- ...rest
258
- };
259
- Object.assign(stateRefs.current, resetState);
260
- Object.assign(stateRefs.current.queryPaging, {
261
- currentPage: 0,
262
- ...queryPaging
263
- });
264
-
265
- // Reset
266
- if (stateRefs.current.isMounted !== false) setRows(items, true);
291
+ scrollToItemRef(index: number, align?: Align): void {
292
+ refMethods.scrollToItem(index, align);
293
+ }
294
+ };
295
+ },
296
+ []
297
+ );
298
+
299
+ // When layout ready
300
+ React.useEffect(() => {
301
+ // Return clear function
302
+ return () => {
303
+ stateRefs.current.isMounted = false;
267
304
  };
305
+ }, []);
268
306
 
269
- React.useImperativeHandle(
270
- mRef,
271
- () => {
272
- const refMethods = listRef.current as ScrollerListRef;
273
-
274
- return {
275
- delete(index) {
276
- const item = rows.at(index);
277
- if (item) {
278
- const newRows = [...rows];
279
- newRows.splice(index, 1);
280
- setRows(newRows);
281
- }
282
- return item;
283
- },
284
- insert(item, start) {
285
- const newRows = [...rows];
286
- newRows.splice(start, 0, item);
287
- setRows(newRows);
288
- },
289
- refresh(): void {
290
- loadDataLocal(0);
291
- },
292
-
293
- reset,
294
-
295
- scrollToRef(scrollOffset: number): void {
296
- refMethods.scrollTo(scrollOffset);
297
- },
298
-
299
- scrollToItemRef(index: number, align?: Align): void {
300
- refMethods.scrollToItem(index, align);
301
- }
302
- };
303
- },
304
- []
305
- );
306
-
307
- // When layout ready
308
- React.useEffect(() => {
309
- // Return clear function
310
- return () => {
311
- stateRefs.current.isMounted = false;
312
- };
313
- }, []);
314
-
315
- // Row count
316
- const rowCount = rows.length;
317
-
318
- // Local items renderer callback
319
- const onItemsRenderedLocal = (props: ListOnItemsRenderedProps) => {
320
- // No items, means no necessary to load more data during reset
321
-
322
- if (rowCount > 0 && props.visibleStopIndex + threshold > rowCount) {
323
- // Auto load next page
324
- loadDataLocal();
325
- }
307
+ // Row count
308
+ const rowCount = rows.length;
326
309
 
327
- // Custom
328
- if (onItemsRendered) onItemsRendered(props);
329
- };
310
+ // Local items renderer callback
311
+ const onItemsRenderedLocal = (props: ListOnItemsRenderedProps) => {
312
+ // No items, means no necessary to load more data during reset
330
313
 
331
- // Item count
332
- const itemCount = stateRefs.current.hasNextPage ? rowCount + 1 : rowCount;
333
-
334
- // Auto load data when current page is 0
335
- if (
336
- stateRefs.current.queryPaging?.currentPage === 0 &&
337
- stateRefs.current.autoLoad
338
- ) {
339
- const initItems =
340
- onInitLoad == null ? undefined : onInitLoad(listRef.current);
341
- if (initItems) reset(initItems[1], initItems[0]);
342
- else loadDataLocal();
314
+ if (rowCount > 0 && props.visibleStopIndex + threshold > rowCount) {
315
+ // Auto load next page
316
+ loadDataLocal();
343
317
  }
344
318
 
345
- // Layout
346
- return typeof itemSize === 'function' ? (
347
- <VariableSizeList<T>
348
- height={height}
349
- width={width}
350
- itemCount={itemCount}
351
- itemKey={(index, data) =>
352
- DataTypes.getIdValue1(data, idField) ?? index
353
- }
354
- itemSize={itemSize}
355
- outerRef={refs}
356
- ref={listRef}
357
- style={style}
358
- onItemsRendered={onItemsRenderedLocal}
359
- {...rest}
360
- >
361
- {itemRendererLocal}
362
- </VariableSizeList>
363
- ) : (
364
- <FixedSizeList<T>
365
- height={height}
366
- width={width}
367
- itemCount={itemCount}
368
- itemKey={(index, data) =>
369
- DataTypes.getIdValue1(data, idField) ?? index
370
- }
371
- itemSize={itemSize}
372
- outerRef={refs}
373
- ref={listRef}
374
- style={style}
375
- onItemsRendered={onItemsRenderedLocal}
376
- {...rest}
377
- >
378
- {itemRendererLocal}
379
- </FixedSizeList>
380
- );
319
+ // Custom
320
+ if (onItemsRendered) onItemsRendered(props);
321
+ };
322
+
323
+ // Item count
324
+ const itemCount = stateRefs.current.hasNextPage ? rowCount + 1 : rowCount;
325
+
326
+ // Auto load data when current page is 0
327
+ if (
328
+ stateRefs.current.queryPaging?.currentPage === 0 &&
329
+ stateRefs.current.autoLoad
330
+ ) {
331
+ const initItems =
332
+ onInitLoad == null ? undefined : onInitLoad(listRef.current);
333
+ if (initItems) reset(initItems[1], initItems[0]);
334
+ else loadDataLocal();
335
+ }
336
+
337
+ // Layout
338
+ return typeof itemSize === "function" ? (
339
+ <VariableSizeList<T>
340
+ height={height}
341
+ width={width}
342
+ itemCount={itemCount}
343
+ itemKey={(index, data) => DataTypes.getIdValue1(data, idField) ?? index}
344
+ itemSize={itemSize}
345
+ outerRef={refs}
346
+ ref={listRef}
347
+ style={style}
348
+ onItemsRendered={onItemsRenderedLocal}
349
+ {...rest}
350
+ >
351
+ {itemRendererLocal}
352
+ </VariableSizeList>
353
+ ) : (
354
+ <FixedSizeList<T>
355
+ height={height}
356
+ width={width}
357
+ itemCount={itemCount}
358
+ itemKey={(index, data) => DataTypes.getIdValue1(data, idField) ?? index}
359
+ itemSize={itemSize}
360
+ outerRef={refs}
361
+ ref={listRef}
362
+ style={style}
363
+ onItemsRendered={onItemsRenderedLocal}
364
+ {...rest}
365
+ >
366
+ {itemRendererLocal}
367
+ </FixedSizeList>
368
+ );
381
369
  };