@etsoo/react 1.7.94 → 1.7.95
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/README.md +2 -1
- package/__tests__/EventWatcher.tsx +21 -21
- package/__tests__/ReactUtils.ts +4 -4
- package/__tests__/tsconfig.json +17 -17
- package/babel.config.json +8 -8
- package/lib/app/CoreConstants.js +2 -2
- package/lib/app/EventWatcher.d.ts +1 -1
- package/lib/app/EventWatcher.js +3 -5
- package/lib/app/InputDialogProps.d.ts +2 -2
- package/lib/app/ReactUtils.d.ts +2 -2
- package/lib/app/ReactUtils.js +20 -19
- package/lib/components/DnDList.d.ts +3 -3
- package/lib/components/DnDList.js +4 -4
- package/lib/components/DynamicRouter.d.ts +2 -2
- package/lib/components/DynamicRouter.js +2 -2
- package/lib/components/GridColumn.d.ts +6 -6
- package/lib/components/GridColumn.js +7 -7
- package/lib/components/GridLoader.d.ts +4 -4
- package/lib/components/GridLoader.js +2 -2
- package/lib/components/GridMethodRef.d.ts +2 -2
- package/lib/components/ListItemReact.d.ts +2 -2
- package/lib/components/ScrollRestoration.js +3 -3
- package/lib/components/ScrollerGrid.d.ts +7 -12
- package/lib/components/ScrollerGrid.js +13 -17
- package/lib/components/ScrollerList.d.ts +6 -10
- package/lib/components/ScrollerList.js +15 -14
- package/lib/custom/CustomFieldReact.d.ts +1 -1
- package/lib/index.d.ts +32 -32
- package/lib/index.js +31 -31
- package/lib/notifier/Notifier.d.ts +5 -5
- package/lib/notifier/Notifier.js +7 -7
- package/lib/states/CultureState.d.ts +3 -3
- package/lib/states/CultureState.js +3 -3
- package/lib/states/IState.d.ts +2 -2
- package/lib/states/PageState.d.ts +2 -2
- package/lib/states/PageState.js +2 -3
- package/lib/states/State.d.ts +3 -3
- package/lib/states/State.js +2 -2
- package/lib/states/UserState.d.ts +2 -2
- package/lib/states/UserState.js +5 -5
- package/lib/uses/useAsyncState.d.ts +1 -1
- package/lib/uses/useAsyncState.js +1 -1
- package/lib/uses/useCombinedRefs.js +2 -2
- package/lib/uses/useDelayedExecutor.d.ts +1 -1
- package/lib/uses/useDelayedExecutor.js +2 -2
- package/lib/uses/useDimensions.d.ts +1 -1
- package/lib/uses/useDimensions.js +3 -3
- package/lib/uses/useParamsEx.d.ts +1 -1
- package/lib/uses/useParamsEx.js +2 -2
- package/lib/uses/useRefs.d.ts +2 -2
- package/lib/uses/useRefs.js +1 -1
- package/lib/uses/useSearchParamsEx.d.ts +1 -1
- package/lib/uses/useSearchParamsEx.js +3 -3
- package/lib/uses/useTimeout.js +2 -2
- package/lib/uses/useWindowScroll.js +3 -3
- package/lib/uses/useWindowSize.js +4 -5
- package/package.json +72 -74
- package/src/app/CoreConstants.ts +8 -8
- package/src/app/EventWatcher.ts +50 -52
- package/src/app/InputDialogProps.ts +16 -16
- package/src/app/ReactUtils.ts +206 -208
- package/src/components/DnDList.tsx +268 -283
- package/src/components/DynamicRouter.tsx +35 -35
- package/src/components/GridColumn.ts +201 -201
- package/src/components/GridLoader.ts +121 -121
- package/src/components/GridMethodRef.ts +26 -26
- package/src/components/ListItemReact.ts +2 -2
- package/src/components/ScrollRestoration.tsx +24 -24
- package/src/components/ScrollerGrid.tsx +428 -448
- package/src/components/ScrollerList.tsx +320 -332
- package/src/custom/CustomFieldReact.ts +12 -12
- package/src/index.ts +35 -35
- package/src/notifier/Notifier.ts +229 -240
- package/src/states/CultureState.ts +51 -52
- package/src/states/IState.ts +19 -19
- package/src/states/PageState.ts +63 -66
- package/src/states/State.tsx +47 -51
- package/src/states/UserState.ts +98 -98
- package/src/uses/useAsyncState.ts +37 -39
- package/src/uses/useCombinedRefs.ts +16 -16
- package/src/uses/useDelayedExecutor.ts +8 -8
- package/src/uses/useDimensions.ts +102 -103
- package/src/uses/useParamsEx.ts +6 -6
- package/src/uses/useRefs.ts +6 -6
- package/src/uses/useSearchParamsEx.ts +13 -13
- package/src/uses/useTimeout.ts +17 -17
- package/src/uses/useWindowScroll.ts +43 -43
- package/src/uses/useWindowSize.ts +46 -49
- package/tsconfig.json +17 -17
- package/.eslintignore +0 -3
- package/.eslintrc.json +0 -38
- package/.prettierignore +0 -5
- package/.prettierrc +0 -6
|
@@ -1,105 +1,100 @@
|
|
|
1
|
-
import { DataTypes, Utils } from
|
|
2
|
-
import React from
|
|
1
|
+
import { DataTypes, Utils } from "@etsoo/shared";
|
|
2
|
+
import React from "react";
|
|
3
3
|
import {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
} from
|
|
11
|
-
import { useCombinedRefs } from
|
|
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
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
} from
|
|
19
|
-
import { GridMethodRef } from
|
|
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
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
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
|
-
|
|
63
|
-
|
|
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
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
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
|
-
|
|
92
|
-
|
|
93
|
-
|
|
85
|
+
/**
|
|
86
|
+
* Refresh latest page data
|
|
87
|
+
*/
|
|
88
|
+
refresh(): void;
|
|
94
89
|
}
|
|
95
90
|
|
|
96
91
|
// Calculate loadBatchSize
|
|
97
92
|
const calculateBatchSize = (
|
|
98
|
-
|
|
99
|
-
|
|
93
|
+
height: number,
|
|
94
|
+
itemSize: ((index: number) => number) | number
|
|
100
95
|
) => {
|
|
101
|
-
|
|
102
|
-
|
|
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
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
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
|
-
|
|
141
|
-
|
|
142
|
-
|
|
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
|
-
|
|
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
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
updateRows(rows);
|
|
227
|
+
setRows(newRows);
|
|
228
|
+
}
|
|
229
|
+
});
|
|
230
|
+
};
|
|
151
231
|
|
|
152
|
-
|
|
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
|
-
//
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
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
|
-
|
|
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
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
...itemProps,
|
|
244
|
-
data: rows[itemProps.index]
|
|
245
|
-
});
|
|
246
|
-
};
|
|
287
|
+
scrollToRef(scrollOffset: number): void {
|
|
288
|
+
refMethods.scrollTo(scrollOffset);
|
|
289
|
+
},
|
|
247
290
|
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
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
|
-
|
|
270
|
-
|
|
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
|
-
|
|
328
|
-
|
|
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
|
-
|
|
332
|
-
|
|
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
|
-
//
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
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
|
};
|