@etsoo/materialui 1.5.71 → 1.5.73
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/__tests__/ReactAppTests.tsx +12 -7
- package/__tests__/{ResponsePage.tsx → ResponsivePage.tsx} +11 -5
- package/__tests__/SelectEx.tsx +1 -1
- package/lib/cjs/DataGridEx.d.ts +8 -1
- package/lib/cjs/DataGridEx.js +71 -56
- package/lib/cjs/DataGridRenderers.d.ts +1 -1
- package/lib/cjs/DataGridRenderers.js +1 -1
- package/lib/cjs/MUUtils.d.ts +0 -9
- package/lib/cjs/MUUtils.js +0 -26
- package/lib/cjs/MobileListItemRenderer.d.ts +2 -2
- package/lib/cjs/MobileListItemRenderer.js +3 -4
- package/lib/cjs/ResponsibleContainer.d.ts +9 -13
- package/lib/cjs/ResponsibleContainer.js +19 -58
- package/lib/cjs/ScrollerListEx.d.ts +23 -23
- package/lib/cjs/ScrollerListEx.js +32 -84
- package/lib/cjs/TableEx.d.ts +7 -0
- package/lib/cjs/TableEx.js +6 -12
- package/lib/cjs/pages/DataGridPage.js +3 -32
- package/lib/cjs/pages/FixedListPage.js +5 -34
- package/lib/cjs/pages/ListPage.js +1 -29
- package/lib/cjs/pages/ResponsivePage.d.ts +9 -13
- package/lib/cjs/uses/useGridCacheInitLoad.d.ts +2 -0
- package/lib/cjs/uses/useGridCacheInitLoad.js +41 -0
- package/lib/cjs/uses/useListCacheInitLoad.d.ts +2 -0
- package/lib/cjs/uses/useListCacheInitLoad.js +38 -0
- package/lib/mjs/DataGridEx.d.ts +8 -1
- package/lib/mjs/DataGridEx.js +71 -56
- package/lib/mjs/DataGridRenderers.d.ts +1 -1
- package/lib/mjs/DataGridRenderers.js +1 -1
- package/lib/mjs/MUUtils.d.ts +0 -9
- package/lib/mjs/MUUtils.js +0 -26
- package/lib/mjs/MobileListItemRenderer.d.ts +2 -2
- package/lib/mjs/MobileListItemRenderer.js +3 -4
- package/lib/mjs/ResponsibleContainer.d.ts +9 -13
- package/lib/mjs/ResponsibleContainer.js +19 -58
- package/lib/mjs/ScrollerListEx.d.ts +23 -23
- package/lib/mjs/ScrollerListEx.js +32 -84
- package/lib/mjs/TableEx.d.ts +7 -0
- package/lib/mjs/TableEx.js +6 -12
- package/lib/mjs/pages/DataGridPage.js +3 -32
- package/lib/mjs/pages/FixedListPage.js +5 -34
- package/lib/mjs/pages/ListPage.js +1 -29
- package/lib/mjs/pages/ResponsivePage.d.ts +9 -13
- package/lib/mjs/uses/useGridCacheInitLoad.d.ts +2 -0
- package/lib/mjs/uses/useGridCacheInitLoad.js +35 -0
- package/lib/mjs/uses/useListCacheInitLoad.d.ts +2 -0
- package/lib/mjs/uses/useListCacheInitLoad.js +32 -0
- package/package.json +18 -19
- package/src/DataGridEx.tsx +155 -109
- package/src/DataGridRenderers.tsx +2 -1
- package/src/MUUtils.ts +0 -33
- package/src/MobileListItemRenderer.tsx +4 -4
- package/src/ResponsibleContainer.tsx +50 -111
- package/src/ScrollerListEx.tsx +141 -229
- package/src/TableEx.tsx +20 -12
- package/src/pages/DataGridPage.tsx +3 -49
- package/src/pages/FixedListPage.tsx +5 -49
- package/src/pages/ListPage.tsx +0 -43
- package/src/pages/ResponsivePage.tsx +16 -21
- package/src/uses/useGridCacheInitLoad.ts +55 -0
- package/src/uses/useListCacheInitLoad.ts +51 -0
package/src/ScrollerListEx.tsx
CHANGED
|
@@ -1,10 +1,15 @@
|
|
|
1
1
|
import { css } from "@emotion/css";
|
|
2
|
-
import {
|
|
2
|
+
import {
|
|
3
|
+
GridLoaderStates,
|
|
4
|
+
ScrollerList,
|
|
5
|
+
ScrollerListProps
|
|
6
|
+
} from "@etsoo/react";
|
|
3
7
|
import { DataTypes, Utils } from "@etsoo/shared";
|
|
4
8
|
import React from "react";
|
|
5
|
-
import { ListChildComponentProps } from "react-window";
|
|
6
9
|
import { MouseEventWithDataHandler, MUGlobal } from "./MUGlobal";
|
|
7
|
-
import {
|
|
10
|
+
import { GridUtils } from "./GridUtils";
|
|
11
|
+
import { useListCacheInitLoad } from "./uses/useListCacheInitLoad";
|
|
12
|
+
import Box from "@mui/material/Box";
|
|
8
13
|
|
|
9
14
|
// Scroll bar size
|
|
10
15
|
const scrollbarSize = 16;
|
|
@@ -46,32 +51,9 @@ const createGridStyle = (
|
|
|
46
51
|
});
|
|
47
52
|
};
|
|
48
53
|
|
|
49
|
-
// Default
|
|
50
|
-
|
|
51
|
-
const
|
|
52
|
-
const half = MUGlobal.half(margin);
|
|
53
|
-
|
|
54
|
-
if (horizon == null) {
|
|
55
|
-
const half = MUGlobal.half(margin);
|
|
56
|
-
return {
|
|
57
|
-
marginLeft: margin,
|
|
58
|
-
marginRight: margin,
|
|
59
|
-
marginTop: half,
|
|
60
|
-
marginBottom: half
|
|
61
|
-
};
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
if (
|
|
65
|
-
(typeof horizon === "number" && horizon >= 0) ||
|
|
66
|
-
(typeof horizon === "string" && /^-?\d+/.test(horizon))
|
|
67
|
-
) {
|
|
68
|
-
return {
|
|
69
|
-
marginLeft: horizon,
|
|
70
|
-
marginRight: horizon,
|
|
71
|
-
marginTop: half,
|
|
72
|
-
marginBottom: half
|
|
73
|
-
};
|
|
74
|
-
}
|
|
54
|
+
// Default margins
|
|
55
|
+
const defaultMargins = () => {
|
|
56
|
+
const half = MUGlobal.half(MUGlobal.pagePaddings);
|
|
75
57
|
|
|
76
58
|
return {
|
|
77
59
|
marginLeft: half,
|
|
@@ -84,175 +66,88 @@ const defaultMargin = (margin: object, horizon?: number | string) => {
|
|
|
84
66
|
/**
|
|
85
67
|
* Extended ScrollerList inner item renderer props
|
|
86
68
|
*/
|
|
87
|
-
export
|
|
88
|
-
extends ListChildComponentProps<T> {
|
|
69
|
+
export type ScrollerListExItemRendererProps<T> = {
|
|
89
70
|
/**
|
|
90
|
-
*
|
|
71
|
+
* Row index
|
|
91
72
|
*/
|
|
92
|
-
|
|
73
|
+
index: number;
|
|
93
74
|
|
|
94
75
|
/**
|
|
95
|
-
*
|
|
76
|
+
* Row data
|
|
96
77
|
*/
|
|
97
|
-
|
|
78
|
+
data: T;
|
|
98
79
|
|
|
99
80
|
/**
|
|
100
|
-
*
|
|
81
|
+
* Style
|
|
101
82
|
*/
|
|
102
|
-
|
|
83
|
+
style: React.CSSProperties;
|
|
103
84
|
|
|
104
85
|
/**
|
|
105
86
|
* Default margins
|
|
106
87
|
*/
|
|
107
88
|
margins: object;
|
|
108
|
-
}
|
|
109
89
|
|
|
110
|
-
/**
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
*/
|
|
116
|
-
export type ScrollerListExItemSize =
|
|
117
|
-
| ((index: number) => [number, number] | [number, number, object])
|
|
118
|
-
| [number, number]
|
|
119
|
-
| [number, object, (number | string)?];
|
|
90
|
+
/**
|
|
91
|
+
* Item selected
|
|
92
|
+
*/
|
|
93
|
+
selected: boolean;
|
|
94
|
+
};
|
|
120
95
|
|
|
121
96
|
/**
|
|
122
97
|
* Extended ScrollerList Props
|
|
123
98
|
*/
|
|
124
99
|
export type ScrollerListExProps<T extends object> = Omit<
|
|
125
100
|
ScrollerListProps<T>,
|
|
126
|
-
"
|
|
127
|
-
> &
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
/**
|
|
178
|
-
* Inner item renderer
|
|
179
|
-
*/
|
|
180
|
-
innerItemRenderer: (
|
|
181
|
-
props: ScrollerListExInnerItemRendererProps<T>
|
|
182
|
-
) => React.ReactNode;
|
|
183
|
-
|
|
184
|
-
/**
|
|
185
|
-
* Item height
|
|
186
|
-
*/
|
|
187
|
-
itemHeight: number;
|
|
188
|
-
|
|
189
|
-
/**
|
|
190
|
-
* Double click handler
|
|
191
|
-
*/
|
|
192
|
-
onDoubleClick?: MouseEventWithDataHandler<T>;
|
|
193
|
-
|
|
194
|
-
/**
|
|
195
|
-
* Click handler
|
|
196
|
-
*/
|
|
197
|
-
onClick?: MouseEventWithDataHandler<T>;
|
|
198
|
-
|
|
199
|
-
/**
|
|
200
|
-
* Item space
|
|
201
|
-
*/
|
|
202
|
-
space: number;
|
|
203
|
-
|
|
204
|
-
/**
|
|
205
|
-
* Default margins
|
|
206
|
-
*/
|
|
207
|
-
margins: object;
|
|
208
|
-
|
|
209
|
-
/**
|
|
210
|
-
* Item selected
|
|
211
|
-
*/
|
|
212
|
-
selected: boolean;
|
|
213
|
-
}
|
|
214
|
-
|
|
215
|
-
// Default itemRenderer
|
|
216
|
-
function defaultItemRenderer<T>({
|
|
217
|
-
index,
|
|
218
|
-
innerItemRenderer,
|
|
219
|
-
data,
|
|
220
|
-
onMouseDown,
|
|
221
|
-
selected,
|
|
222
|
-
style,
|
|
223
|
-
itemHeight,
|
|
224
|
-
onClick,
|
|
225
|
-
onDoubleClick,
|
|
226
|
-
space,
|
|
227
|
-
margins
|
|
228
|
-
}: defaultItemRendererProps<T>) {
|
|
229
|
-
// Child
|
|
230
|
-
const child = innerItemRenderer({
|
|
231
|
-
index,
|
|
232
|
-
data,
|
|
233
|
-
style,
|
|
234
|
-
selected,
|
|
235
|
-
itemHeight,
|
|
236
|
-
space,
|
|
237
|
-
margins
|
|
238
|
-
});
|
|
239
|
-
|
|
240
|
-
let rowClass = `ScrollerListEx-Row${index % 2}`;
|
|
241
|
-
if (selected) rowClass += ` ${selectedClassName}`;
|
|
242
|
-
|
|
243
|
-
// Layout
|
|
244
|
-
return (
|
|
245
|
-
<div
|
|
246
|
-
className={rowClass}
|
|
247
|
-
style={style}
|
|
248
|
-
onMouseDown={(event) => onMouseDown(event.currentTarget, data)}
|
|
249
|
-
onClick={(event) => onClick && onClick(event, data)}
|
|
250
|
-
onDoubleClick={(event) => onDoubleClick && onDoubleClick(event, data)}
|
|
251
|
-
>
|
|
252
|
-
{child}
|
|
253
|
-
</div>
|
|
254
|
-
);
|
|
255
|
-
}
|
|
101
|
+
"rowComponent" | "rowHeight" | "onClick" | "onDoubleClick" | "onInitLoad"
|
|
102
|
+
> &
|
|
103
|
+
Partial<Pick<ScrollerListProps<T>, "rowHeight">> & {
|
|
104
|
+
/**
|
|
105
|
+
* Alternating colors for odd/even rows
|
|
106
|
+
*/
|
|
107
|
+
alternatingColors?: [string?, string?];
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* Cache key
|
|
111
|
+
*/
|
|
112
|
+
cacheKey?: string;
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* Cache minutes
|
|
116
|
+
*/
|
|
117
|
+
cacheMinutes?: number;
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* Cell margins, default to half of MUGlobal.pagePaddings
|
|
121
|
+
*/
|
|
122
|
+
cellMargins?: object;
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* Item renderer
|
|
126
|
+
*/
|
|
127
|
+
itemRenderer?: (
|
|
128
|
+
props: ScrollerListExItemRendererProps<T>
|
|
129
|
+
) => React.ReactNode;
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
* Double click handler
|
|
133
|
+
*/
|
|
134
|
+
onDoubleClick?: MouseEventWithDataHandler<T>;
|
|
135
|
+
|
|
136
|
+
/**
|
|
137
|
+
* Click handler
|
|
138
|
+
*/
|
|
139
|
+
onClick?: MouseEventWithDataHandler<T>;
|
|
140
|
+
|
|
141
|
+
/**
|
|
142
|
+
* On items select change
|
|
143
|
+
*/
|
|
144
|
+
onSelectChange?: (selectedItems: T[]) => void;
|
|
145
|
+
|
|
146
|
+
/**
|
|
147
|
+
* Selected color
|
|
148
|
+
*/
|
|
149
|
+
selectedColor?: string;
|
|
150
|
+
};
|
|
256
151
|
|
|
257
152
|
/**
|
|
258
153
|
* Extended ScrollerList
|
|
@@ -293,64 +188,40 @@ export function ScrollerListEx<T extends object>(
|
|
|
293
188
|
const {
|
|
294
189
|
alternatingColors = [undefined, undefined],
|
|
295
190
|
className,
|
|
191
|
+
cacheKey,
|
|
192
|
+
cacheMinutes = 15,
|
|
193
|
+
cellMargins = defaultMargins(),
|
|
296
194
|
idField = "id" as DataTypes.Keys<T>,
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
margins,
|
|
309
|
-
selected: isSelected(itemProps.data),
|
|
310
|
-
...itemProps
|
|
311
|
-
});
|
|
312
|
-
},
|
|
195
|
+
itemRenderer = ({ data, margins, style }) => (
|
|
196
|
+
<Box
|
|
197
|
+
component="pre"
|
|
198
|
+
sx={{
|
|
199
|
+
...margins
|
|
200
|
+
}}
|
|
201
|
+
style={style}
|
|
202
|
+
>
|
|
203
|
+
{JSON.stringify(data)}
|
|
204
|
+
</Box>
|
|
205
|
+
),
|
|
313
206
|
onClick,
|
|
314
207
|
onDoubleClick,
|
|
208
|
+
onUpdateRows,
|
|
315
209
|
onSelectChange,
|
|
210
|
+
rowHeight = 116,
|
|
316
211
|
selectedColor = "#edf4fb",
|
|
317
212
|
...rest
|
|
318
213
|
} = props;
|
|
319
214
|
|
|
320
|
-
//
|
|
321
|
-
const
|
|
322
|
-
|
|
323
|
-
// Cache calculation
|
|
324
|
-
const itemSizeResult = React.useMemo(():
|
|
325
|
-
| [number, number, object]
|
|
326
|
-
| undefined => {
|
|
327
|
-
if (typeof itemSize === "function") return undefined;
|
|
328
|
-
const [size, spaces, h] = itemSize;
|
|
329
|
-
if (typeof spaces === "number")
|
|
330
|
-
return [size, spaces, defaultMargin(MUGlobal.pagePaddings, undefined)];
|
|
331
|
-
|
|
332
|
-
return [size, MUGlobal.getSpace(spaces, theme), defaultMargin(spaces, h)];
|
|
333
|
-
}, [itemSize]);
|
|
334
|
-
|
|
335
|
-
// Calculate size
|
|
336
|
-
const calculateItemSize = (index: number): [number, number, object] => {
|
|
337
|
-
// Callback function
|
|
338
|
-
if (typeof itemSize === "function") {
|
|
339
|
-
const result = itemSize(index);
|
|
340
|
-
if (result.length == 2)
|
|
341
|
-
return [...result, defaultMargin(MUGlobal.pagePaddings)];
|
|
342
|
-
return result;
|
|
343
|
-
}
|
|
344
|
-
|
|
345
|
-
// Calculation
|
|
346
|
-
return itemSizeResult!;
|
|
347
|
-
};
|
|
215
|
+
// Init handler
|
|
216
|
+
const initHandler = useListCacheInitLoad<T>(cacheKey, cacheMinutes);
|
|
348
217
|
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
218
|
+
const onUpdateRowsHandler = React.useCallback(
|
|
219
|
+
(rows: T[], state: GridLoaderStates<T>) => {
|
|
220
|
+
GridUtils.getUpdateRowsHandler<T>(cacheKey)?.(rows, state);
|
|
221
|
+
onUpdateRows?.(rows, state);
|
|
222
|
+
},
|
|
223
|
+
[onUpdateRows, cacheKey]
|
|
224
|
+
);
|
|
354
225
|
|
|
355
226
|
// Layout
|
|
356
227
|
return (
|
|
@@ -361,8 +232,49 @@ export function ScrollerListEx<T extends object>(
|
|
|
361
232
|
createGridStyle(alternatingColors, selectedColor)
|
|
362
233
|
)}
|
|
363
234
|
idField={idField}
|
|
364
|
-
|
|
365
|
-
|
|
235
|
+
onRowsRendered={
|
|
236
|
+
cacheKey
|
|
237
|
+
? (visibleRows) =>
|
|
238
|
+
sessionStorage.setItem(
|
|
239
|
+
`${cacheKey}-scroll`,
|
|
240
|
+
JSON.stringify(visibleRows)
|
|
241
|
+
)
|
|
242
|
+
: undefined
|
|
243
|
+
}
|
|
244
|
+
onInitLoad={initHandler}
|
|
245
|
+
onUpdateRows={onUpdateRowsHandler}
|
|
246
|
+
rowComponent={(cellProps) => {
|
|
247
|
+
const { index, style, items } = cellProps;
|
|
248
|
+
const data = items[index];
|
|
249
|
+
const selected = isSelected(data);
|
|
250
|
+
const rowClass = `ScrollerListEx-Row${index % 2}${
|
|
251
|
+
selected ? ` ${selectedClassName}` : ""
|
|
252
|
+
}`;
|
|
253
|
+
|
|
254
|
+
// Child
|
|
255
|
+
const child = itemRenderer({
|
|
256
|
+
index,
|
|
257
|
+
data,
|
|
258
|
+
style,
|
|
259
|
+
selected,
|
|
260
|
+
margins: cellMargins
|
|
261
|
+
});
|
|
262
|
+
|
|
263
|
+
return (
|
|
264
|
+
<div
|
|
265
|
+
className={rowClass}
|
|
266
|
+
style={style}
|
|
267
|
+
onMouseDown={(event) => onMouseDown(event.currentTarget, data)}
|
|
268
|
+
onClick={(event) => onClick && onClick(event, data)}
|
|
269
|
+
onDoubleClick={(event) =>
|
|
270
|
+
onDoubleClick && onDoubleClick(event, data)
|
|
271
|
+
}
|
|
272
|
+
>
|
|
273
|
+
{child}
|
|
274
|
+
</div>
|
|
275
|
+
);
|
|
276
|
+
}}
|
|
277
|
+
rowHeight={rowHeight}
|
|
366
278
|
{...rest}
|
|
367
279
|
/>
|
|
368
280
|
);
|
package/src/TableEx.tsx
CHANGED
|
@@ -7,7 +7,8 @@ import {
|
|
|
7
7
|
GridLoaderPartialStates,
|
|
8
8
|
GridLoaderStates,
|
|
9
9
|
GridMethodRef,
|
|
10
|
-
GridSizeGet
|
|
10
|
+
GridSizeGet,
|
|
11
|
+
ScrollToRowParam
|
|
11
12
|
} from "@etsoo/react";
|
|
12
13
|
import { DataTypes, IdDefaultType } from "@etsoo/shared";
|
|
13
14
|
import React from "react";
|
|
@@ -77,6 +78,14 @@ export type TableExProps<
|
|
|
77
78
|
*/
|
|
78
79
|
mRef?: React.Ref<TableExMethodRef<T>>;
|
|
79
80
|
|
|
81
|
+
/**
|
|
82
|
+
* Data change handler
|
|
83
|
+
* @param rows Rows
|
|
84
|
+
* @param rowIndex Row index
|
|
85
|
+
* @param columnIndex Column index
|
|
86
|
+
*/
|
|
87
|
+
onDataChange?: (rows: T[], rowIndex: number, columnIndex: number) => void;
|
|
88
|
+
|
|
80
89
|
/**
|
|
81
90
|
* On items select change
|
|
82
91
|
*/
|
|
@@ -117,6 +126,7 @@ export function TableEx<
|
|
|
117
126
|
loadData,
|
|
118
127
|
maxHeight,
|
|
119
128
|
mRef,
|
|
129
|
+
onDataChange,
|
|
120
130
|
onSelectChange,
|
|
121
131
|
rowHeight = 53,
|
|
122
132
|
otherHeight = 110,
|
|
@@ -183,6 +193,10 @@ export function TableEx<
|
|
|
183
193
|
React.useImperativeHandle(
|
|
184
194
|
mRef,
|
|
185
195
|
() => ({
|
|
196
|
+
get element() {
|
|
197
|
+
return null;
|
|
198
|
+
},
|
|
199
|
+
|
|
186
200
|
delete(index) {
|
|
187
201
|
const item = rows.at(index);
|
|
188
202
|
if (item) {
|
|
@@ -192,27 +206,20 @@ export function TableEx<
|
|
|
192
206
|
}
|
|
193
207
|
return item;
|
|
194
208
|
},
|
|
209
|
+
|
|
195
210
|
insert(item, start) {
|
|
196
211
|
const newRows = [...rows];
|
|
197
212
|
newRows.splice(start, 0, item);
|
|
198
213
|
setRows(newRows);
|
|
199
214
|
},
|
|
200
|
-
|
|
201
|
-
* Refresh data
|
|
202
|
-
*/
|
|
215
|
+
|
|
203
216
|
refresh(): void {
|
|
204
217
|
loadDataLocal();
|
|
205
218
|
},
|
|
206
219
|
|
|
207
|
-
/**
|
|
208
|
-
* Reset
|
|
209
|
-
*/
|
|
210
220
|
reset,
|
|
211
|
-
scrollToRef(scrollOffset: number): void {
|
|
212
|
-
// Not implemented
|
|
213
|
-
},
|
|
214
221
|
|
|
215
|
-
|
|
222
|
+
scrollToRow(param: ScrollToRowParam): void {
|
|
216
223
|
// Not implemented
|
|
217
224
|
}
|
|
218
225
|
}),
|
|
@@ -513,7 +520,8 @@ export function TableEx<
|
|
|
513
520
|
rowIndex,
|
|
514
521
|
columnIndex,
|
|
515
522
|
cellProps,
|
|
516
|
-
|
|
523
|
+
triggerChange: () =>
|
|
524
|
+
onDataChange?.(rows, rowIndex, columnIndex)
|
|
517
525
|
})
|
|
518
526
|
) : (
|
|
519
527
|
<React.Fragment> </React.Fragment>
|
|
@@ -1,9 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
GridLoadDataProps,
|
|
3
|
-
GridLoaderStates,
|
|
4
|
-
GridOnScrollProps,
|
|
5
3
|
ScrollerGridForwardRef,
|
|
6
|
-
VariableSizeGrid,
|
|
7
4
|
useCombinedRefs,
|
|
8
5
|
useDimensions,
|
|
9
6
|
useSearchParamsWithCache
|
|
@@ -66,12 +63,13 @@ export function DataGridPage<T extends object, F>(
|
|
|
66
63
|
(ref: ScrollerGridForwardRef<T> | null | undefined) => {
|
|
67
64
|
if (ref == null) return;
|
|
68
65
|
states.ref = ref;
|
|
66
|
+
|
|
67
|
+
if (ref.element) setStates({ element: ref.element });
|
|
68
|
+
|
|
69
69
|
//setStates({ ref });
|
|
70
70
|
}
|
|
71
71
|
);
|
|
72
72
|
|
|
73
|
-
const initLoadedRef = React.useRef<boolean>(null);
|
|
74
|
-
|
|
75
73
|
// On submit callback
|
|
76
74
|
const onSubmit = (data: FormData, _reset: boolean) => {
|
|
77
75
|
setStates({ data });
|
|
@@ -87,44 +85,6 @@ export function DataGridPage<T extends object, F>(
|
|
|
87
85
|
// Search data
|
|
88
86
|
const searchData = useSearchParamsWithCache(cacheKey);
|
|
89
87
|
|
|
90
|
-
const onInitLoad = (
|
|
91
|
-
ref: VariableSizeGrid<T>
|
|
92
|
-
): [T[], Partial<GridLoaderStates<T>>?] | null | undefined => {
|
|
93
|
-
// Avoid repeatedly load from cache
|
|
94
|
-
if (initLoadedRef.current || !cacheKey) return undefined;
|
|
95
|
-
|
|
96
|
-
// Cache data
|
|
97
|
-
const cacheData = GridUtils.getCacheData<T>(cacheKey, cacheMinutes);
|
|
98
|
-
if (cacheData) {
|
|
99
|
-
const { rows, state } = cacheData;
|
|
100
|
-
|
|
101
|
-
GridUtils.mergeSearchData(state, searchData);
|
|
102
|
-
|
|
103
|
-
// Scroll position
|
|
104
|
-
const scrollData = sessionStorage.getItem(`${cacheKey}-scroll`);
|
|
105
|
-
if (scrollData) {
|
|
106
|
-
const { scrollLeft, scrollTop } = JSON.parse(
|
|
107
|
-
scrollData
|
|
108
|
-
) as GridOnScrollProps;
|
|
109
|
-
|
|
110
|
-
globalThis.setTimeout(() => ref.scrollTo({ scrollLeft, scrollTop }), 0);
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
// Update flag value
|
|
114
|
-
initLoadedRef.current = true;
|
|
115
|
-
|
|
116
|
-
// Return cached rows and state
|
|
117
|
-
return [rows, state];
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
return undefined;
|
|
121
|
-
};
|
|
122
|
-
|
|
123
|
-
const onGridScroll = (props: GridOnScrollProps) => {
|
|
124
|
-
if (!cacheKey || !initLoadedRef.current) return;
|
|
125
|
-
sessionStorage.setItem(`${cacheKey}-scroll`, JSON.stringify(props));
|
|
126
|
-
};
|
|
127
|
-
|
|
128
88
|
// Watch container
|
|
129
89
|
const { dimensions } = useDimensions(1, undefined, sizeReadyMiliseconds);
|
|
130
90
|
const rect = dimensions[0][2];
|
|
@@ -159,12 +119,6 @@ export function DataGridPage<T extends object, F>(
|
|
|
159
119
|
height={gridHeight}
|
|
160
120
|
loadData={localLoadData}
|
|
161
121
|
mRef={refs}
|
|
162
|
-
onUpdateRows={GridUtils.getUpdateRowsHandler<T>(cacheKey)}
|
|
163
|
-
onInitLoad={onInitLoad}
|
|
164
|
-
onScroll={onGridScroll}
|
|
165
|
-
outerRef={(element?: HTMLDivElement) => {
|
|
166
|
-
if (element != null) setStates({ element });
|
|
167
|
-
}}
|
|
168
122
|
{...rest}
|
|
169
123
|
/>
|
|
170
124
|
);
|
|
@@ -1,9 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
GridLoadDataProps,
|
|
3
|
-
GridLoaderStates,
|
|
4
|
-
ListOnScrollProps,
|
|
5
3
|
ScrollerListForwardRef,
|
|
6
|
-
ScrollerListRef,
|
|
7
4
|
useCombinedRefs,
|
|
8
5
|
useDimensions,
|
|
9
6
|
useSearchParamsWithCache
|
|
@@ -56,8 +53,6 @@ export function FixedListPage<T extends object, F>(
|
|
|
56
53
|
ref?: ScrollerListForwardRef<T>;
|
|
57
54
|
}>({});
|
|
58
55
|
|
|
59
|
-
const initLoadedRef = React.useRef<boolean>(null);
|
|
60
|
-
|
|
61
56
|
// Scroll container
|
|
62
57
|
const [scrollContainer, updateScrollContainer] = React.useState<
|
|
63
58
|
HTMLElement | undefined
|
|
@@ -72,6 +67,8 @@ export function FixedListPage<T extends object, F>(
|
|
|
72
67
|
|
|
73
68
|
states.ref = ref;
|
|
74
69
|
|
|
70
|
+
if (ref.element) updateScrollContainer(ref.element);
|
|
71
|
+
|
|
75
72
|
if (first) reset();
|
|
76
73
|
}
|
|
77
74
|
);
|
|
@@ -94,44 +91,6 @@ export function FixedListPage<T extends object, F>(
|
|
|
94
91
|
);
|
|
95
92
|
};
|
|
96
93
|
|
|
97
|
-
// Search data
|
|
98
|
-
const searchData = useSearchParamsWithCache(cacheKey);
|
|
99
|
-
|
|
100
|
-
const onInitLoad = (
|
|
101
|
-
ref: ScrollerListRef
|
|
102
|
-
): [T[], Partial<GridLoaderStates<T>>?] | null | undefined => {
|
|
103
|
-
// Avoid repeatedly load from cache
|
|
104
|
-
if (initLoadedRef.current || !cacheKey) return undefined;
|
|
105
|
-
|
|
106
|
-
// Cache data
|
|
107
|
-
const cacheData = GridUtils.getCacheData<T>(cacheKey, cacheMinutes);
|
|
108
|
-
if (cacheData) {
|
|
109
|
-
const { rows, state } = cacheData;
|
|
110
|
-
|
|
111
|
-
GridUtils.mergeSearchData(state, searchData);
|
|
112
|
-
|
|
113
|
-
// Scroll position
|
|
114
|
-
const scrollData = sessionStorage.getItem(`${cacheKey}-scroll`);
|
|
115
|
-
if (scrollData) {
|
|
116
|
-
const { scrollOffset } = JSON.parse(scrollData) as ListOnScrollProps;
|
|
117
|
-
globalThis.setTimeout(() => ref.scrollTo(scrollOffset), 0);
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
// Update flag value
|
|
121
|
-
initLoadedRef.current = true;
|
|
122
|
-
|
|
123
|
-
// Return cached rows and state
|
|
124
|
-
return [rows, state];
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
return undefined;
|
|
128
|
-
};
|
|
129
|
-
|
|
130
|
-
const onListScroll = (props: ListOnScrollProps) => {
|
|
131
|
-
if (!cacheKey || !initLoadedRef.current) return;
|
|
132
|
-
sessionStorage.setItem(`${cacheKey}-scroll`, JSON.stringify(props));
|
|
133
|
-
};
|
|
134
|
-
|
|
135
94
|
// Watch container
|
|
136
95
|
const { dimensions } = useDimensions(1, undefined, sizeReadyMiliseconds);
|
|
137
96
|
const rect = dimensions[0][2];
|
|
@@ -159,12 +118,6 @@ export function FixedListPage<T extends object, F>(
|
|
|
159
118
|
height={height}
|
|
160
119
|
loadData={localLoadData}
|
|
161
120
|
mRef={refs}
|
|
162
|
-
onUpdateRows={GridUtils.getUpdateRowsHandler<T>(cacheKey)}
|
|
163
|
-
onInitLoad={onInitLoad}
|
|
164
|
-
onScroll={onListScroll}
|
|
165
|
-
oRef={(element) => {
|
|
166
|
-
if (element != null) updateScrollContainer(element);
|
|
167
|
-
}}
|
|
168
121
|
{...rest}
|
|
169
122
|
/>
|
|
170
123
|
</Box>
|
|
@@ -172,6 +125,9 @@ export function FixedListPage<T extends object, F>(
|
|
|
172
125
|
}
|
|
173
126
|
}, [rect]);
|
|
174
127
|
|
|
128
|
+
// Search data
|
|
129
|
+
const searchData = useSearchParamsWithCache(cacheKey);
|
|
130
|
+
|
|
175
131
|
const f = typeof fields == "function" ? fields(searchData ?? {}) : fields;
|
|
176
132
|
|
|
177
133
|
const { paddings, ...pageRest } = pageProps;
|