@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,5 +1,5 @@
|
|
|
1
|
-
import { QueryPagingData } from
|
|
2
|
-
import { DataTypes, DomUtils } from
|
|
1
|
+
import { QueryPagingData } from "@etsoo/appscript";
|
|
2
|
+
import { DataTypes, DomUtils } from "@etsoo/shared";
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* Grid size
|
|
@@ -12,8 +12,8 @@ export type GridSize = number | ((input: number) => number);
|
|
|
12
12
|
* @param input Input
|
|
13
13
|
*/
|
|
14
14
|
export const GridSizeGet = (size: GridSize, input: number) => {
|
|
15
|
-
|
|
16
|
-
|
|
15
|
+
if (typeof size === "function") return size(input);
|
|
16
|
+
return size;
|
|
17
17
|
};
|
|
18
18
|
|
|
19
19
|
/**
|
|
@@ -27,14 +27,14 @@ export type GridData = FormData | DataTypes.StringRecord;
|
|
|
27
27
|
* @returns Json data
|
|
28
28
|
*/
|
|
29
29
|
export function GridDataGet<F extends DataTypes.BasicTemplate>(
|
|
30
|
-
|
|
31
|
-
|
|
30
|
+
props: GridLoadDataProps,
|
|
31
|
+
template?: F
|
|
32
32
|
): GridJsonData & DataTypes.BasicTemplateType<F> {
|
|
33
|
-
|
|
34
|
-
|
|
33
|
+
// Destruct
|
|
34
|
+
const { data, ...rest } = props;
|
|
35
35
|
|
|
36
|
-
|
|
37
|
-
|
|
36
|
+
// DomUtils.dataAs(data, template);
|
|
37
|
+
return { ...GridDataGetData(data, template), ...rest };
|
|
38
38
|
}
|
|
39
39
|
|
|
40
40
|
/**
|
|
@@ -43,144 +43,144 @@ export function GridDataGet<F extends DataTypes.BasicTemplate>(
|
|
|
43
43
|
* @returns Json data
|
|
44
44
|
*/
|
|
45
45
|
export function GridDataGetData<F extends DataTypes.BasicTemplate>(
|
|
46
|
-
|
|
47
|
-
|
|
46
|
+
data?: GridData,
|
|
47
|
+
template?: F
|
|
48
48
|
): DataTypes.BasicTemplateType<F> {
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
49
|
+
// Clear form empty value
|
|
50
|
+
if (data instanceof FormData) {
|
|
51
|
+
DomUtils.clearFormData(data);
|
|
52
|
+
}
|
|
53
53
|
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
54
|
+
// Conditions
|
|
55
|
+
const conditions: DataTypes.BasicTemplateType<F> =
|
|
56
|
+
data == null ? {} : DomUtils.dataAs(data, template ?? {}, true); // Set keepSource to true to hold form data, even they are invisible from the conditions
|
|
57
57
|
|
|
58
|
-
|
|
58
|
+
return conditions;
|
|
59
59
|
}
|
|
60
60
|
|
|
61
61
|
/**
|
|
62
62
|
* Grid Json data
|
|
63
63
|
*/
|
|
64
|
-
export type GridJsonData = Omit<GridLoadDataProps,
|
|
64
|
+
export type GridJsonData = Omit<GridLoadDataProps, "data">;
|
|
65
65
|
|
|
66
66
|
/**
|
|
67
67
|
* Grid data load props
|
|
68
68
|
*/
|
|
69
69
|
export type GridLoadDataProps = {
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
70
|
+
/**
|
|
71
|
+
* Query paging data
|
|
72
|
+
*/
|
|
73
|
+
queryPaging: QueryPagingData;
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* Data related
|
|
77
|
+
*/
|
|
78
|
+
data?: GridData;
|
|
79
79
|
};
|
|
80
80
|
|
|
81
81
|
/**
|
|
82
82
|
* Grid data load partial props
|
|
83
83
|
*/
|
|
84
84
|
export type GridLoadDataPartialProps = {
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
85
|
+
/**
|
|
86
|
+
* Query paging data
|
|
87
|
+
*/
|
|
88
|
+
queryPaging?: Partial<QueryPagingData>;
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* Data related
|
|
92
|
+
*/
|
|
93
|
+
data?: GridData;
|
|
94
94
|
};
|
|
95
95
|
|
|
96
96
|
/**
|
|
97
97
|
* Grid data loader
|
|
98
98
|
*/
|
|
99
99
|
export interface GridLoader<T extends object> {
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
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
|
-
|
|
139
|
-
|
|
140
|
-
|
|
100
|
+
/**
|
|
101
|
+
* Auto load data, otherwise call reset
|
|
102
|
+
* @default true
|
|
103
|
+
*/
|
|
104
|
+
autoLoad?: boolean;
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* Default order by
|
|
108
|
+
*/
|
|
109
|
+
defaultOrderBy?: Record<string, boolean>;
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* Batch size when load data, default will be calcuated with height and itemSize
|
|
113
|
+
*/
|
|
114
|
+
loadBatchSize?: GridSize;
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* Load data
|
|
118
|
+
*/
|
|
119
|
+
loadData: (props: GridLoadDataProps) => PromiseLike<T[] | null | undefined>;
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* Handler for init load
|
|
123
|
+
* @param ref Ref
|
|
124
|
+
* @returns Result
|
|
125
|
+
*/
|
|
126
|
+
onInitLoad?: (
|
|
127
|
+
ref: any
|
|
128
|
+
) => [T[], GridLoaderPartialStates<T>?] | null | undefined;
|
|
129
|
+
|
|
130
|
+
/**
|
|
131
|
+
* Handler for updating rows
|
|
132
|
+
* @param rows Rows
|
|
133
|
+
* @param state State
|
|
134
|
+
*/
|
|
135
|
+
onUpdateRows?: (rows: T[], state: GridLoaderStates<T>) => void;
|
|
136
|
+
|
|
137
|
+
/**
|
|
138
|
+
* Threshold at which to pre-fetch data; default is half of loadBatchSize
|
|
139
|
+
*/
|
|
140
|
+
threshold?: number | undefined;
|
|
141
141
|
}
|
|
142
142
|
|
|
143
143
|
type GridLoaderProps<T> = {
|
|
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
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
144
|
+
/**
|
|
145
|
+
* Auto load data, otherwise call reset
|
|
146
|
+
* @default true
|
|
147
|
+
*/
|
|
148
|
+
autoLoad: boolean;
|
|
149
|
+
|
|
150
|
+
/**
|
|
151
|
+
* Last loaded items
|
|
152
|
+
*/
|
|
153
|
+
lastLoadedItems?: number;
|
|
154
|
+
|
|
155
|
+
/**
|
|
156
|
+
* All loaded items count
|
|
157
|
+
*/
|
|
158
|
+
loadedItems: number;
|
|
159
|
+
|
|
160
|
+
/**
|
|
161
|
+
* Has next page?
|
|
162
|
+
*/
|
|
163
|
+
hasNextPage: boolean;
|
|
164
|
+
|
|
165
|
+
/**
|
|
166
|
+
* Is next page loading?
|
|
167
|
+
*/
|
|
168
|
+
isNextPageLoading: boolean;
|
|
169
|
+
|
|
170
|
+
/**
|
|
171
|
+
* Is mounted
|
|
172
|
+
*/
|
|
173
|
+
isMounted?: boolean;
|
|
174
|
+
|
|
175
|
+
/**
|
|
176
|
+
* Selected items of id
|
|
177
|
+
*/
|
|
178
|
+
selectedItems: T[];
|
|
179
|
+
|
|
180
|
+
/**
|
|
181
|
+
* Id cache
|
|
182
|
+
*/
|
|
183
|
+
idCache: Record<any, null>;
|
|
184
184
|
};
|
|
185
185
|
|
|
186
186
|
/**
|
|
@@ -192,4 +192,4 @@ export type GridLoaderStates<T> = GridLoadDataProps & GridLoaderProps<T>;
|
|
|
192
192
|
* Grid loader states
|
|
193
193
|
*/
|
|
194
194
|
export type GridLoaderPartialStates<T> = GridLoadDataPartialProps &
|
|
195
|
-
|
|
195
|
+
Partial<GridLoaderProps<T>>;
|
|
@@ -1,36 +1,36 @@
|
|
|
1
|
-
import { Align } from
|
|
2
|
-
import { GridLoaderPartialStates } from
|
|
1
|
+
import { Align } from "react-window";
|
|
2
|
+
import { GridLoaderPartialStates } from "./GridLoader";
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* Grid method ref
|
|
6
6
|
*/
|
|
7
7
|
export interface GridMethodRef<T> {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
8
|
+
/**
|
|
9
|
+
* Delete item at the index
|
|
10
|
+
* @param index Index
|
|
11
|
+
*/
|
|
12
|
+
delete(index: number): T | undefined;
|
|
13
13
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
14
|
+
/**
|
|
15
|
+
* Insert the item at start
|
|
16
|
+
* @param item Item
|
|
17
|
+
* @param start Start position
|
|
18
|
+
*/
|
|
19
|
+
insert(item: T, start: number): void;
|
|
20
20
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
21
|
+
/**
|
|
22
|
+
* Reset
|
|
23
|
+
* @param add Additional data
|
|
24
|
+
*/
|
|
25
|
+
reset(add?: GridLoaderPartialStates<T>): void;
|
|
26
26
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
27
|
+
/**
|
|
28
|
+
* Scroll to the specified offset (scrollTop or scrollLeft, depending on the direction prop).
|
|
29
|
+
*/
|
|
30
|
+
scrollToRef(scrollOffset: number): void;
|
|
31
31
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
32
|
+
/**
|
|
33
|
+
* Scroll to the specified item.
|
|
34
|
+
*/
|
|
35
|
+
scrollToItemRef(index: number, align?: Align): void;
|
|
36
36
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import React from
|
|
2
|
-
import { useLocation } from
|
|
3
|
-
import { IScrollPos, useWindowScroll } from
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { useLocation } from "react-router-dom";
|
|
3
|
+
import { IScrollPos, useWindowScroll } from "../uses/useWindowScroll";
|
|
4
4
|
|
|
5
5
|
const urls: Record<string, IScrollPos | undefined> = {};
|
|
6
6
|
|
|
@@ -8,30 +8,30 @@ const urls: Record<string, IScrollPos | undefined> = {};
|
|
|
8
8
|
* Scroll restoration
|
|
9
9
|
*/
|
|
10
10
|
export function ScrollRestoration() {
|
|
11
|
-
|
|
12
|
-
|
|
11
|
+
// Location key
|
|
12
|
+
const { key } = useLocation();
|
|
13
13
|
|
|
14
|
-
|
|
15
|
-
|
|
14
|
+
// Mounted
|
|
15
|
+
const mounted = React.useRef(false);
|
|
16
16
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
17
|
+
// Detect scroll
|
|
18
|
+
const data = useWindowScroll();
|
|
19
|
+
if (mounted.current) {
|
|
20
|
+
urls[key] = data;
|
|
21
|
+
}
|
|
22
22
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
23
|
+
// Setup
|
|
24
|
+
React.useEffect(() => {
|
|
25
|
+
const pos = urls[key];
|
|
26
|
+
if (pos) {
|
|
27
|
+
window.scrollTo(pos.x, pos.y);
|
|
28
|
+
}
|
|
29
29
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
30
|
+
mounted.current = true;
|
|
31
|
+
return () => {
|
|
32
|
+
mounted.current = false;
|
|
33
|
+
};
|
|
34
|
+
}, [key]);
|
|
35
35
|
|
|
36
|
-
|
|
36
|
+
return <React.Fragment />;
|
|
37
37
|
}
|