@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/pages/ListPage.tsx
CHANGED
|
@@ -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
|
|
@@ -62,8 +59,6 @@ export function ListPage<T extends object, F>(props: ListPageProps<T, F>) {
|
|
|
62
59
|
if (first) reset();
|
|
63
60
|
});
|
|
64
61
|
|
|
65
|
-
const initLoadedRef = React.useRef<boolean>(null);
|
|
66
|
-
|
|
67
62
|
const reset = () => {
|
|
68
63
|
if (states.data == null || states.ref == null) return;
|
|
69
64
|
states.ref.reset({ data: states.data });
|
|
@@ -89,41 +84,6 @@ export function ListPage<T extends object, F>(props: ListPageProps<T, F>) {
|
|
|
89
84
|
// Search data
|
|
90
85
|
const searchData = useSearchParamsWithCache(cacheKey);
|
|
91
86
|
|
|
92
|
-
const onInitLoad = (
|
|
93
|
-
ref: ScrollerListRef
|
|
94
|
-
): [T[], Partial<GridLoaderStates<T>>?] | null | undefined => {
|
|
95
|
-
// Avoid repeatedly load from cache
|
|
96
|
-
if (initLoadedRef.current || !cacheKey) return undefined;
|
|
97
|
-
|
|
98
|
-
// Cache data
|
|
99
|
-
const cacheData = GridUtils.getCacheData<T>(cacheKey, cacheMinutes);
|
|
100
|
-
if (cacheData) {
|
|
101
|
-
const { rows, state } = cacheData;
|
|
102
|
-
|
|
103
|
-
GridUtils.mergeSearchData(state, searchData);
|
|
104
|
-
|
|
105
|
-
// Scroll position
|
|
106
|
-
const scrollData = sessionStorage.getItem(`${cacheKey}-scroll`);
|
|
107
|
-
if (scrollData) {
|
|
108
|
-
const { scrollOffset } = JSON.parse(scrollData) as ListOnScrollProps;
|
|
109
|
-
globalThis.setTimeout(() => ref.scrollTo(scrollOffset), 0);
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
// Update flag value
|
|
113
|
-
initLoadedRef.current = true;
|
|
114
|
-
|
|
115
|
-
// Return cached rows and state
|
|
116
|
-
return [rows, state];
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
return undefined;
|
|
120
|
-
};
|
|
121
|
-
|
|
122
|
-
const onListScroll = (props: ListOnScrollProps) => {
|
|
123
|
-
if (!cacheKey || !initLoadedRef.current) return;
|
|
124
|
-
sessionStorage.setItem(`${cacheKey}-scroll`, JSON.stringify(props));
|
|
125
|
-
};
|
|
126
|
-
|
|
127
87
|
const f = typeof fields == "function" ? fields(searchData ?? {}) : fields;
|
|
128
88
|
|
|
129
89
|
// Layout
|
|
@@ -148,9 +108,6 @@ export function ListPage<T extends object, F>(props: ListPageProps<T, F>) {
|
|
|
148
108
|
<ScrollerListEx<T>
|
|
149
109
|
autoLoad={false}
|
|
150
110
|
loadData={localLoadData}
|
|
151
|
-
onUpdateRows={GridUtils.getUpdateRowsHandler<T>(cacheKey)}
|
|
152
|
-
onInitLoad={onInitLoad}
|
|
153
|
-
onScroll={onListScroll}
|
|
154
111
|
mRef={refs}
|
|
155
112
|
{...rest}
|
|
156
113
|
/>
|
|
@@ -1,21 +1,23 @@
|
|
|
1
1
|
import React from "react";
|
|
2
2
|
import { MUGlobal } from "../MUGlobal";
|
|
3
|
-
import {
|
|
3
|
+
import {
|
|
4
|
+
ResponsibleContainer,
|
|
5
|
+
ResponsibleContainerProps
|
|
6
|
+
} from "../ResponsibleContainer";
|
|
4
7
|
import { CommonPage } from "./CommonPage";
|
|
5
8
|
import { OperationMessageContainer } from "../messages/OperationMessageContainer";
|
|
6
9
|
import type { DataGridPageProps } from "./DataGridPageProps";
|
|
7
|
-
import type {
|
|
8
|
-
ScrollerListExInnerItemRendererProps,
|
|
9
|
-
ScrollerListExItemSize
|
|
10
|
-
} from "../ScrollerListEx";
|
|
11
|
-
import { ListChildComponentProps } from "react-window";
|
|
10
|
+
import type { ScrollerListExProps } from "../ScrollerListEx";
|
|
12
11
|
import { GridMethodRef } from "@etsoo/react";
|
|
13
12
|
import type { OperationMessageHandlerAll } from "../messages/OperationMessageHandler";
|
|
14
13
|
|
|
15
14
|
/**
|
|
16
15
|
* Response page props
|
|
17
16
|
*/
|
|
18
|
-
export type ResponsePageProps<T extends object, F> =
|
|
17
|
+
export type ResponsePageProps<T extends object, F> = Omit<
|
|
18
|
+
DataGridPageProps<T, F>,
|
|
19
|
+
"mRef" | "rowHeight"
|
|
20
|
+
> & {
|
|
19
21
|
/**
|
|
20
22
|
*
|
|
21
23
|
* @param height Current height
|
|
@@ -29,27 +31,15 @@ export type ResponsePageProps<T extends object, F> = DataGridPageProps<T, F> & {
|
|
|
29
31
|
*/
|
|
30
32
|
dataGridMinWidth?: number;
|
|
31
33
|
|
|
32
|
-
/**
|
|
33
|
-
* Inner item renderer
|
|
34
|
-
*/
|
|
35
|
-
innerItemRenderer: (
|
|
36
|
-
props: ScrollerListExInnerItemRendererProps<T>
|
|
37
|
-
) => React.ReactNode;
|
|
38
|
-
|
|
39
34
|
/**
|
|
40
35
|
* Item renderer
|
|
41
36
|
*/
|
|
42
|
-
itemRenderer?:
|
|
43
|
-
|
|
44
|
-
/**
|
|
45
|
-
* Item size, a function indicates its a variable size list
|
|
46
|
-
*/
|
|
47
|
-
itemSize: ScrollerListExItemSize;
|
|
37
|
+
itemRenderer?: ScrollerListExProps<T>["itemRenderer"];
|
|
48
38
|
|
|
49
39
|
/**
|
|
50
40
|
* Methods
|
|
51
41
|
*/
|
|
52
|
-
mRef?: React.
|
|
42
|
+
mRef?: React.RefObject<GridMethodRef<T> | undefined>;
|
|
53
43
|
|
|
54
44
|
/**
|
|
55
45
|
* Pull to refresh data
|
|
@@ -65,6 +55,11 @@ export type ResponsePageProps<T extends object, F> = DataGridPageProps<T, F> & {
|
|
|
65
55
|
* Operation message handler
|
|
66
56
|
*/
|
|
67
57
|
operationMessageHandler?: OperationMessageHandlerAll;
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Row height
|
|
61
|
+
*/
|
|
62
|
+
rowHeight?: ResponsibleContainerProps<T, F>["rowHeight"];
|
|
68
63
|
};
|
|
69
64
|
|
|
70
65
|
/**
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import {
|
|
2
|
+
GridImperativeAPI,
|
|
3
|
+
OnCellsRenderedData,
|
|
4
|
+
ScrollerGridProps,
|
|
5
|
+
useSearchParamsWithCache
|
|
6
|
+
} from "@etsoo/react";
|
|
7
|
+
import React from "react";
|
|
8
|
+
import { GridUtils } from "../GridUtils";
|
|
9
|
+
import { ExtendUtils } from "@etsoo/shared";
|
|
10
|
+
|
|
11
|
+
export function useGridCacheInitLoad<T extends object>(
|
|
12
|
+
cacheKey: string | undefined,
|
|
13
|
+
cacheMinutes: number
|
|
14
|
+
): ScrollerGridProps<T>["onInitLoad"] {
|
|
15
|
+
// Reference
|
|
16
|
+
const ref = React.useRef<boolean>(null);
|
|
17
|
+
|
|
18
|
+
// Search data
|
|
19
|
+
const searchData = useSearchParamsWithCache(cacheKey);
|
|
20
|
+
|
|
21
|
+
// Avoid repeatedly load from cache
|
|
22
|
+
if (ref.current || !cacheKey) return undefined;
|
|
23
|
+
|
|
24
|
+
// Cache data
|
|
25
|
+
const cacheData = GridUtils.getCacheData<T>(cacheKey, cacheMinutes);
|
|
26
|
+
if (cacheData) {
|
|
27
|
+
const { rows, state } = cacheData;
|
|
28
|
+
|
|
29
|
+
GridUtils.mergeSearchData(state, searchData);
|
|
30
|
+
|
|
31
|
+
// Update flag value
|
|
32
|
+
ref.current = true;
|
|
33
|
+
|
|
34
|
+
return (ref: GridImperativeAPI) => {
|
|
35
|
+
// Scroll position
|
|
36
|
+
const scrollData = sessionStorage.getItem(`${cacheKey}-scroll`);
|
|
37
|
+
if (scrollData) {
|
|
38
|
+
const data = JSON.parse(scrollData) as OnCellsRenderedData;
|
|
39
|
+
ExtendUtils.waitFor(
|
|
40
|
+
() =>
|
|
41
|
+
ref.scrollToCell({
|
|
42
|
+
rowIndex: data.rowStartIndex,
|
|
43
|
+
columnIndex: data.columnStartIndex
|
|
44
|
+
}),
|
|
45
|
+
100
|
|
46
|
+
);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
// Return cached rows and state
|
|
50
|
+
return [rows, state];
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
return undefined;
|
|
55
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import {
|
|
2
|
+
ListImperativeAPI,
|
|
3
|
+
OnRowsRenderedData,
|
|
4
|
+
ScrollerListProps,
|
|
5
|
+
useSearchParamsWithCache
|
|
6
|
+
} from "@etsoo/react";
|
|
7
|
+
import React from "react";
|
|
8
|
+
import { GridUtils } from "../GridUtils";
|
|
9
|
+
import { ExtendUtils } from "@etsoo/shared";
|
|
10
|
+
|
|
11
|
+
export function useListCacheInitLoad<T extends object>(
|
|
12
|
+
cacheKey: string | undefined,
|
|
13
|
+
cacheMinutes: number
|
|
14
|
+
): ScrollerListProps<T>["onInitLoad"] {
|
|
15
|
+
// Reference
|
|
16
|
+
const ref = React.useRef<boolean>(null);
|
|
17
|
+
|
|
18
|
+
// Search data
|
|
19
|
+
const searchData = useSearchParamsWithCache(cacheKey);
|
|
20
|
+
|
|
21
|
+
// Avoid repeatedly load from cache
|
|
22
|
+
if (ref.current || !cacheKey) return undefined;
|
|
23
|
+
|
|
24
|
+
// Cache data
|
|
25
|
+
const cacheData = GridUtils.getCacheData<T>(cacheKey, cacheMinutes);
|
|
26
|
+
if (cacheData) {
|
|
27
|
+
const { rows, state } = cacheData;
|
|
28
|
+
|
|
29
|
+
GridUtils.mergeSearchData(state, searchData);
|
|
30
|
+
|
|
31
|
+
// Update flag value
|
|
32
|
+
ref.current = true;
|
|
33
|
+
|
|
34
|
+
return (ref: ListImperativeAPI) => {
|
|
35
|
+
// Scroll position
|
|
36
|
+
const scrollData = sessionStorage.getItem(`${cacheKey}-scroll`);
|
|
37
|
+
if (scrollData) {
|
|
38
|
+
const data = JSON.parse(scrollData) as OnRowsRenderedData;
|
|
39
|
+
ExtendUtils.waitFor(
|
|
40
|
+
() => ref.scrollToRow({ index: data.startIndex }),
|
|
41
|
+
100
|
|
42
|
+
);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
// Return cached rows and state
|
|
46
|
+
return [rows, state];
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
return undefined;
|
|
51
|
+
}
|