@etsoo/react 1.4.21 → 1.4.22
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/lib/components/ScrollerGrid.js +2 -0
- package/lib/mu/ResponsibleContainer.d.ts +4 -0
- package/lib/mu/ResponsibleContainer.js +16 -15
- package/lib/mu/pages/CommonPage.d.ts +1 -2
- package/package.json +8 -8
- package/src/components/ScrollerGrid.tsx +3 -0
- package/src/mu/ResponsibleContainer.tsx +21 -14
|
@@ -5,6 +5,7 @@ import { GridDataGet } from '../components/GridLoader';
|
|
|
5
5
|
import useCombinedRefs from '../uses/useCombinedRefs';
|
|
6
6
|
import { useDimensions } from '../uses/useDimensions';
|
|
7
7
|
import { DataGridEx, DataGridExCalColumns } from './DataGridEx';
|
|
8
|
+
import { MUGlobal } from './MUGlobal';
|
|
8
9
|
import { PullToRefreshUI } from './PullToRefreshUI';
|
|
9
10
|
import { ScrollerListEx } from './ScrollerListEx';
|
|
10
11
|
import { SearchBar } from './SearchBar';
|
|
@@ -15,35 +16,36 @@ import { SearchBar } from './SearchBar';
|
|
|
15
16
|
*/
|
|
16
17
|
export function ResponsibleContainer(props) {
|
|
17
18
|
// Destruct
|
|
18
|
-
const { adjustHeight, columns, dataGridMinWidth = DataGridExCalColumns(columns).total, fields, fieldTemplate, height, listBoxSx, loadData, mRef, pullToRefresh = true, searchBoxSx, sizeReadyMiliseconds = 0, ...rest } = props;
|
|
19
|
+
const { adjustHeight, columns, dataGridMinWidth = DataGridExCalColumns(columns).total, fields, fieldTemplate, height, listBoxSx, loadData, mRef, paddings = MUGlobal.pagePaddings, pullToRefresh = true, searchBoxSx = { marginBottom: MUGlobal.half(paddings) }, sizeReadyMiliseconds = 0, ...rest } = props;
|
|
19
20
|
// Labels
|
|
20
21
|
const labels = Labels.CommonPage;
|
|
21
22
|
// Refs
|
|
22
23
|
const refs = React.useRef({});
|
|
24
|
+
const state = refs.current;
|
|
23
25
|
const mRefs = useCombinedRefs(mRef, (ref) => {
|
|
24
26
|
if (ref == null)
|
|
25
27
|
return;
|
|
26
|
-
|
|
28
|
+
state.ref = ref;
|
|
27
29
|
});
|
|
28
30
|
// Update mounted state
|
|
29
31
|
React.useEffect(() => {
|
|
30
32
|
return () => {
|
|
31
|
-
|
|
33
|
+
state.mounted = false;
|
|
32
34
|
};
|
|
33
35
|
}, []);
|
|
34
36
|
// Has fields
|
|
35
37
|
const hasFields = fields != null && fields.length > 0;
|
|
36
38
|
// Load data
|
|
37
39
|
const localLoadData = (props) => {
|
|
38
|
-
|
|
40
|
+
state.mounted = true;
|
|
39
41
|
const data = GridDataGet(props, fieldTemplate);
|
|
40
42
|
return loadData(data);
|
|
41
43
|
};
|
|
42
44
|
// On submit callback
|
|
43
45
|
const onSubmit = (data, _reset) => {
|
|
44
|
-
if (data == null ||
|
|
46
|
+
if (data == null || state.ref == null)
|
|
45
47
|
return;
|
|
46
|
-
|
|
48
|
+
state.ref.reset({ data });
|
|
47
49
|
};
|
|
48
50
|
// Watch container
|
|
49
51
|
const { dimensions } = useDimensions(1, undefined, sizeReadyMiliseconds, (_preRect, rect) => {
|
|
@@ -51,15 +53,15 @@ export function ResponsibleContainer(props) {
|
|
|
51
53
|
if (rect == null)
|
|
52
54
|
return true;
|
|
53
55
|
// Last rect
|
|
54
|
-
const lastRect =
|
|
56
|
+
const lastRect = state.rect;
|
|
55
57
|
// 32 = scroll bar width
|
|
56
58
|
if (lastRect != null &&
|
|
57
|
-
|
|
59
|
+
state.mounted !== true &&
|
|
58
60
|
Math.abs(rect.width - lastRect.width) <= 32 &&
|
|
59
61
|
Math.abs(rect.height - lastRect.height) <= 32)
|
|
60
62
|
return true;
|
|
61
63
|
// Hold the new rect
|
|
62
|
-
|
|
64
|
+
state.rect = rect;
|
|
63
65
|
return false;
|
|
64
66
|
});
|
|
65
67
|
// Rect
|
|
@@ -80,12 +82,11 @@ export function ResponsibleContainer(props) {
|
|
|
80
82
|
}
|
|
81
83
|
else {
|
|
82
84
|
// Auto calculation
|
|
83
|
-
heightLocal =
|
|
84
|
-
window.innerHeight - Math.round(rect.top + rect.height + 1);
|
|
85
|
+
heightLocal = window.innerHeight - Math.round(rect.bottom + 1);
|
|
85
86
|
const style = window.getComputedStyle(dimensions[0][1]);
|
|
86
|
-
const
|
|
87
|
-
if (!isNaN(
|
|
88
|
-
heightLocal -=
|
|
87
|
+
const boxMargin = parseFloat(style.marginBottom);
|
|
88
|
+
if (!isNaN(boxMargin))
|
|
89
|
+
heightLocal -= 3 * boxMargin; // 1 - Box, 2 - Page bottom
|
|
89
90
|
if (adjustHeight != null) {
|
|
90
91
|
heightLocal -= adjustHeight(heightLocal);
|
|
91
92
|
}
|
|
@@ -125,7 +126,7 @@ export function ResponsibleContainer(props) {
|
|
|
125
126
|
React.createElement(Stack, null,
|
|
126
127
|
React.createElement(Box, { ref: dimensions[0][0], sx: searchBoxSx }, hasFields && (React.createElement(SearchBar, { fields: fields, onSubmit: onSubmit }))),
|
|
127
128
|
list),
|
|
128
|
-
pullToRefresh && pullContainer && (React.createElement(PullToRefreshUI, { mainElement: pullContainer, triggerElement: pullContainer, instructionsPullToRefresh: labels.pullToRefresh, instructionsReleaseToRefresh: labels.releaseToRefresh, instructionsRefreshing: labels.refreshing, onRefresh: () => { var _a; return (_a =
|
|
129
|
+
pullToRefresh && pullContainer && (React.createElement(PullToRefreshUI, { mainElement: pullContainer, triggerElement: pullContainer, instructionsPullToRefresh: labels.pullToRefresh, instructionsReleaseToRefresh: labels.releaseToRefresh, instructionsRefreshing: labels.refreshing, onRefresh: () => { var _a; return (_a = state.ref) === null || _a === void 0 ? void 0 : _a.reset(); }, shouldPullToRefresh: () => {
|
|
129
130
|
const container = document.querySelector(pullContainer);
|
|
130
131
|
return !(container === null || container === void 0 ? void 0 : container.scrollTop);
|
|
131
132
|
} }))));
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
/// <reference types="node" />
|
|
2
1
|
/// <reference types="react" />
|
|
3
2
|
import { CommonPageProps } from './CommonPageProps';
|
|
4
3
|
/**
|
|
@@ -8,7 +7,7 @@ export declare const CommonPagePullContainer = "#page-container";
|
|
|
8
7
|
/**
|
|
9
8
|
* Default scroll container
|
|
10
9
|
*/
|
|
11
|
-
export declare const CommonPageScrollContainer:
|
|
10
|
+
export declare const CommonPageScrollContainer: typeof globalThis;
|
|
12
11
|
/**
|
|
13
12
|
* Common page
|
|
14
13
|
* @param props Props
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@etsoo/react",
|
|
3
|
-
"version": "1.4.
|
|
3
|
+
"version": "1.4.22",
|
|
4
4
|
"description": "TypeScript ReactJs framework",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"types": "lib/index.d.ts",
|
|
@@ -54,7 +54,7 @@
|
|
|
54
54
|
"@etsoo/notificationbase": "^1.1.0",
|
|
55
55
|
"@etsoo/shared": "^1.1.3",
|
|
56
56
|
"@mui/icons-material": "^5.2.5",
|
|
57
|
-
"@mui/material": "^5.2.
|
|
57
|
+
"@mui/material": "^5.2.8",
|
|
58
58
|
"@reach/router": "^1.3.4",
|
|
59
59
|
"@types/pica": "^5.1.3",
|
|
60
60
|
"@types/pulltorefreshjs": "^0.1.5",
|
|
@@ -76,15 +76,15 @@
|
|
|
76
76
|
"react-window": "^1.8.6"
|
|
77
77
|
},
|
|
78
78
|
"devDependencies": {
|
|
79
|
-
"@babel/cli": "^7.16.
|
|
79
|
+
"@babel/cli": "^7.16.8",
|
|
80
80
|
"@babel/core": "^7.16.7",
|
|
81
|
-
"@babel/plugin-transform-runtime": "^7.16.
|
|
82
|
-
"@babel/preset-env": "^7.16.
|
|
83
|
-
"@babel/runtime-corejs3": "^7.16.
|
|
81
|
+
"@babel/plugin-transform-runtime": "^7.16.8",
|
|
82
|
+
"@babel/preset-env": "^7.16.8",
|
|
83
|
+
"@babel/runtime-corejs3": "^7.16.8",
|
|
84
84
|
"@types/jest": "^27.4.0",
|
|
85
85
|
"@types/react-test-renderer": "^17.0.1",
|
|
86
|
-
"@typescript-eslint/eslint-plugin": "^5.9.
|
|
87
|
-
"@typescript-eslint/parser": "^5.9.
|
|
86
|
+
"@typescript-eslint/eslint-plugin": "^5.9.1",
|
|
87
|
+
"@typescript-eslint/parser": "^5.9.1",
|
|
88
88
|
"eslint": "^8.6.0",
|
|
89
89
|
"eslint-config-airbnb-base": "^15.0.0",
|
|
90
90
|
"eslint-plugin-import": "^2.25.4",
|
|
@@ -17,6 +17,7 @@ import {
|
|
|
17
17
|
DataGridExProps
|
|
18
18
|
} from './DataGridEx';
|
|
19
19
|
import { GridMethodRef } from './GridMethodRef';
|
|
20
|
+
import { MUGlobal } from './MUGlobal';
|
|
20
21
|
import { PullToRefreshUI } from './PullToRefreshUI';
|
|
21
22
|
import {
|
|
22
23
|
ScrollerListEx,
|
|
@@ -104,6 +105,11 @@ export interface ResponsibleContainerProps<
|
|
|
104
105
|
*/
|
|
105
106
|
mRef?: React.MutableRefObject<GridMethodRef | undefined>;
|
|
106
107
|
|
|
108
|
+
/**
|
|
109
|
+
* Paddings
|
|
110
|
+
*/
|
|
111
|
+
paddings?: {};
|
|
112
|
+
|
|
107
113
|
/**
|
|
108
114
|
* Pull to refresh data
|
|
109
115
|
*/
|
|
@@ -146,8 +152,9 @@ export function ResponsibleContainer<
|
|
|
146
152
|
listBoxSx,
|
|
147
153
|
loadData,
|
|
148
154
|
mRef,
|
|
155
|
+
paddings = MUGlobal.pagePaddings,
|
|
149
156
|
pullToRefresh = true,
|
|
150
|
-
searchBoxSx,
|
|
157
|
+
searchBoxSx = { marginBottom: MUGlobal.half(paddings) },
|
|
151
158
|
sizeReadyMiliseconds = 0,
|
|
152
159
|
...rest
|
|
153
160
|
} = props;
|
|
@@ -157,16 +164,17 @@ export function ResponsibleContainer<
|
|
|
157
164
|
|
|
158
165
|
// Refs
|
|
159
166
|
const refs = React.useRef<LocalRefs>({});
|
|
167
|
+
const state = refs.current;
|
|
160
168
|
|
|
161
169
|
const mRefs = useCombinedRefs(mRef, (ref: GridMethodRef) => {
|
|
162
170
|
if (ref == null) return;
|
|
163
|
-
|
|
171
|
+
state.ref = ref;
|
|
164
172
|
});
|
|
165
173
|
|
|
166
174
|
// Update mounted state
|
|
167
175
|
React.useEffect(() => {
|
|
168
176
|
return () => {
|
|
169
|
-
|
|
177
|
+
state.mounted = false;
|
|
170
178
|
};
|
|
171
179
|
}, []);
|
|
172
180
|
|
|
@@ -175,15 +183,15 @@ export function ResponsibleContainer<
|
|
|
175
183
|
|
|
176
184
|
// Load data
|
|
177
185
|
const localLoadData = (props: GridLoadDataProps) => {
|
|
178
|
-
|
|
186
|
+
state.mounted = true;
|
|
179
187
|
const data = GridDataGet(props, fieldTemplate);
|
|
180
188
|
return loadData(data);
|
|
181
189
|
};
|
|
182
190
|
|
|
183
191
|
// On submit callback
|
|
184
192
|
const onSubmit = (data: FormData, _reset: boolean) => {
|
|
185
|
-
if (data == null ||
|
|
186
|
-
|
|
193
|
+
if (data == null || state.ref == null) return;
|
|
194
|
+
state.ref.reset({ data });
|
|
187
195
|
};
|
|
188
196
|
|
|
189
197
|
// Watch container
|
|
@@ -196,19 +204,19 @@ export function ResponsibleContainer<
|
|
|
196
204
|
if (rect == null) return true;
|
|
197
205
|
|
|
198
206
|
// Last rect
|
|
199
|
-
const lastRect =
|
|
207
|
+
const lastRect = state.rect;
|
|
200
208
|
|
|
201
209
|
// 32 = scroll bar width
|
|
202
210
|
if (
|
|
203
211
|
lastRect != null &&
|
|
204
|
-
|
|
212
|
+
state.mounted !== true &&
|
|
205
213
|
Math.abs(rect.width - lastRect.width) <= 32 &&
|
|
206
214
|
Math.abs(rect.height - lastRect.height) <= 32
|
|
207
215
|
)
|
|
208
216
|
return true;
|
|
209
217
|
|
|
210
218
|
// Hold the new rect
|
|
211
|
-
|
|
219
|
+
state.rect = rect;
|
|
212
220
|
|
|
213
221
|
return false;
|
|
214
222
|
}
|
|
@@ -234,12 +242,11 @@ export function ResponsibleContainer<
|
|
|
234
242
|
heightLocal = height;
|
|
235
243
|
} else {
|
|
236
244
|
// Auto calculation
|
|
237
|
-
heightLocal =
|
|
238
|
-
window.innerHeight - Math.round(rect.top + rect.height + 1);
|
|
245
|
+
heightLocal = window.innerHeight - Math.round(rect.bottom + 1);
|
|
239
246
|
|
|
240
247
|
const style = window.getComputedStyle(dimensions[0][1]!);
|
|
241
|
-
const
|
|
242
|
-
if (!isNaN(
|
|
248
|
+
const boxMargin = parseFloat(style.marginBottom);
|
|
249
|
+
if (!isNaN(boxMargin)) heightLocal -= 3 * boxMargin; // 1 - Box, 2 - Page bottom
|
|
243
250
|
|
|
244
251
|
if (adjustHeight != null) {
|
|
245
252
|
heightLocal -= adjustHeight(heightLocal);
|
|
@@ -316,7 +323,7 @@ export function ResponsibleContainer<
|
|
|
316
323
|
instructionsPullToRefresh={labels.pullToRefresh}
|
|
317
324
|
instructionsReleaseToRefresh={labels.releaseToRefresh}
|
|
318
325
|
instructionsRefreshing={labels.refreshing}
|
|
319
|
-
onRefresh={() =>
|
|
326
|
+
onRefresh={() => state.ref?.reset()}
|
|
320
327
|
shouldPullToRefresh={() => {
|
|
321
328
|
const container = document.querySelector(pullContainer);
|
|
322
329
|
return !container?.scrollTop;
|