@etsoo/react 1.4.22 → 1.4.26
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/ScrollerList.js +3 -1
- package/lib/mu/DataGridEx.js +2 -2
- package/lib/mu/DataGridRenderers.d.ts +4 -2
- package/lib/mu/DataGridRenderers.js +14 -10
- package/lib/mu/ResponsibleContainer.d.ts +9 -1
- package/lib/mu/ResponsibleContainer.js +41 -13
- package/lib/mu/SearchBar.js +29 -27
- package/lib/mu/pages/CommonPage.d.ts +0 -4
- package/lib/mu/pages/CommonPage.js +2 -11
- package/lib/mu/pages/CommonPageProps.d.ts +0 -4
- package/lib/mu/pages/DataGridPage.js +4 -7
- package/lib/mu/pages/FixedListPage.js +3 -6
- package/lib/mu/pages/ListPage.js +2 -2
- package/lib/mu/pages/ResponsivePage.js +33 -119
- package/lib/mu/pages/ResponsivePageProps.d.ts +4 -0
- package/lib/mu/pages/TablePage.js +4 -3
- package/lib/uses/useWindowSize.d.ts +6 -5
- package/lib/uses/useWindowSize.js +22 -16
- package/package.json +2 -2
- package/src/components/ScrollerList.tsx +4 -1
- package/src/mu/DataGridEx.tsx +2 -2
- package/src/mu/DataGridRenderers.tsx +14 -11
- package/src/mu/ResponsibleContainer.tsx +75 -16
- package/src/mu/SearchBar.tsx +26 -24
- package/src/mu/pages/CommonPage.tsx +0 -21
- package/src/mu/pages/CommonPageProps.ts +0 -5
- package/src/mu/pages/DataGridPage.tsx +3 -11
- package/src/mu/pages/FixedListPage.tsx +2 -7
- package/src/mu/pages/ListPage.tsx +2 -10
- package/src/mu/pages/ResponsivePage.tsx +37 -192
- package/src/mu/pages/ResponsivePageProps.ts +5 -0
- package/src/mu/pages/TablePage.tsx +5 -11
- package/src/uses/useWindowSize.ts +32 -19
|
@@ -15,7 +15,7 @@ const calculateBatchSize = (height, itemSize) => {
|
|
|
15
15
|
*/
|
|
16
16
|
export const ScrollerList = (props) => {
|
|
17
17
|
// Destruct
|
|
18
|
-
const { autoLoad = true, defaultOrderBy, defaultOrderByAsc, height =
|
|
18
|
+
const { autoLoad = true, defaultOrderBy, defaultOrderByAsc, height = document.documentElement.clientHeight, width = '100%', mRef, oRef, style = {}, itemRenderer, itemSize, loadBatchSize = calculateBatchSize(height, itemSize), loadData, threshold = GridSizeGet(loadBatchSize, height) / 2, onItemsRendered, ...rest } = props;
|
|
19
19
|
// Style
|
|
20
20
|
Object.assign(style, {
|
|
21
21
|
width: '100%',
|
|
@@ -120,6 +120,8 @@ export const ScrollerList = (props) => {
|
|
|
120
120
|
...add
|
|
121
121
|
};
|
|
122
122
|
Object.assign(state, resetState);
|
|
123
|
+
// Reset
|
|
124
|
+
setRows([]);
|
|
123
125
|
},
|
|
124
126
|
scrollTo(scrollOffset) {
|
|
125
127
|
refMethods.scrollTo(scrollOffset);
|
package/lib/mu/DataGridEx.js
CHANGED
|
@@ -86,7 +86,7 @@ export function DataGridEx(props) {
|
|
|
86
86
|
sortLabel = headerCellRenderer({
|
|
87
87
|
cellProps,
|
|
88
88
|
column,
|
|
89
|
-
columnIndex: index,
|
|
89
|
+
columnIndex: checkable ? index - 1 : index,
|
|
90
90
|
states
|
|
91
91
|
});
|
|
92
92
|
}
|
|
@@ -115,7 +115,7 @@ export function DataGridEx(props) {
|
|
|
115
115
|
const cell = footerItemRenderer
|
|
116
116
|
? footerItemRenderer(rows, {
|
|
117
117
|
column,
|
|
118
|
-
index,
|
|
118
|
+
index: checkable ? index - 1 : index,
|
|
119
119
|
states,
|
|
120
120
|
cellProps,
|
|
121
121
|
checkable
|
|
@@ -13,8 +13,10 @@ export declare namespace DataGridRenderers {
|
|
|
13
13
|
function defaultCellRenderer<T extends Record<string, any>>({ cellProps, data, field, formattedValue, columnIndex, type, renderProps }: GridCellRendererProps<T>): React.ReactNode;
|
|
14
14
|
/**
|
|
15
15
|
* Default footer item renderer
|
|
16
|
-
* @param
|
|
16
|
+
* @param rows Rows
|
|
17
|
+
* @param props Renderer props
|
|
18
|
+
* @param location Renderer location (column index)
|
|
17
19
|
* @returns Component
|
|
18
20
|
*/
|
|
19
|
-
function defaultFooterItemRenderer<T>(_rows: T[], { index, states, checkable }: DataGridExFooterItemRendererProps<T
|
|
21
|
+
function defaultFooterItemRenderer<T>(_rows: T[], { index, states, checkable }: DataGridExFooterItemRendererProps<T>, location?: number): string | undefined;
|
|
20
22
|
}
|
|
@@ -75,19 +75,23 @@ export var DataGridRenderers;
|
|
|
75
75
|
DataGridRenderers.defaultCellRenderer = defaultCellRenderer;
|
|
76
76
|
/**
|
|
77
77
|
* Default footer item renderer
|
|
78
|
-
* @param
|
|
78
|
+
* @param rows Rows
|
|
79
|
+
* @param props Renderer props
|
|
80
|
+
* @param location Renderer location (column index)
|
|
79
81
|
* @returns Component
|
|
80
82
|
*/
|
|
81
|
-
function defaultFooterItemRenderer(_rows, { index, states, checkable }) {
|
|
83
|
+
function defaultFooterItemRenderer(_rows, { index, states, checkable }, location = 0) {
|
|
82
84
|
const { selectedItems, loadedItems, hasNextPage } = states;
|
|
83
|
-
if (
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
85
|
+
if (index === location) {
|
|
86
|
+
if (checkable) {
|
|
87
|
+
return [
|
|
88
|
+
selectedItems.length,
|
|
89
|
+
loadedItems.toLocaleString() + (hasNextPage ? '+' : '')
|
|
90
|
+
].join(' / ');
|
|
91
|
+
}
|
|
92
|
+
else {
|
|
93
|
+
return loadedItems.toLocaleString() + (hasNextPage ? '+' : '');
|
|
94
|
+
}
|
|
91
95
|
}
|
|
92
96
|
return undefined;
|
|
93
97
|
}
|
|
@@ -20,6 +20,10 @@ export interface ResponsibleContainerProps<T extends {}, F extends DataTypes.Bas
|
|
|
20
20
|
* Columns
|
|
21
21
|
*/
|
|
22
22
|
columns: GridColumn<T>[];
|
|
23
|
+
/**
|
|
24
|
+
* Container box SX (dataGrid determines the case)
|
|
25
|
+
*/
|
|
26
|
+
containerBoxSx?: (dataGrid: boolean) => SxProps<Theme>;
|
|
23
27
|
/**
|
|
24
28
|
* Min width to show Datagrid
|
|
25
29
|
*/
|
|
@@ -51,7 +55,7 @@ export interface ResponsibleContainerProps<T extends {}, F extends DataTypes.Bas
|
|
|
51
55
|
/**
|
|
52
56
|
* Listbox SX (dataGrid determines the case)
|
|
53
57
|
*/
|
|
54
|
-
listBoxSx?: (dataGrid: boolean) => SxProps<Theme>;
|
|
58
|
+
listBoxSx?: (dataGrid: boolean, height: number) => SxProps<Theme>;
|
|
55
59
|
/**
|
|
56
60
|
* Load data callback
|
|
57
61
|
*/
|
|
@@ -60,6 +64,10 @@ export interface ResponsibleContainerProps<T extends {}, F extends DataTypes.Bas
|
|
|
60
64
|
* Methods
|
|
61
65
|
*/
|
|
62
66
|
mRef?: React.MutableRefObject<GridMethodRef | undefined>;
|
|
67
|
+
/**
|
|
68
|
+
* Element ready callback
|
|
69
|
+
*/
|
|
70
|
+
elementReady?: (element: HTMLElement, isDataGrid: boolean) => void;
|
|
63
71
|
/**
|
|
64
72
|
* Paddings
|
|
65
73
|
*/
|
|
@@ -9,6 +9,15 @@ import { MUGlobal } from './MUGlobal';
|
|
|
9
9
|
import { PullToRefreshUI } from './PullToRefreshUI';
|
|
10
10
|
import { ScrollerListEx } from './ScrollerListEx';
|
|
11
11
|
import { SearchBar } from './SearchBar';
|
|
12
|
+
function getDefaultSearchBoxSx(paddings) {
|
|
13
|
+
const half = MUGlobal.half(paddings);
|
|
14
|
+
return {
|
|
15
|
+
paddingLeft: (theme) => theme.spacing(0.5),
|
|
16
|
+
paddingRight: (theme) => theme.spacing(0.5),
|
|
17
|
+
paddingTop: half,
|
|
18
|
+
marginBottom: half
|
|
19
|
+
};
|
|
20
|
+
}
|
|
12
21
|
/**
|
|
13
22
|
* Responsible container
|
|
14
23
|
* @param props Props
|
|
@@ -16,7 +25,7 @@ import { SearchBar } from './SearchBar';
|
|
|
16
25
|
*/
|
|
17
26
|
export function ResponsibleContainer(props) {
|
|
18
27
|
// Destruct
|
|
19
|
-
const { adjustHeight, columns, dataGridMinWidth = DataGridExCalColumns(columns).total, fields, fieldTemplate, height, listBoxSx, loadData, mRef, paddings = MUGlobal.pagePaddings, pullToRefresh = true, searchBoxSx =
|
|
28
|
+
const { adjustHeight, columns, containerBoxSx, dataGridMinWidth = DataGridExCalColumns(columns).total, elementReady, fields, fieldTemplate, height, listBoxSx, loadData, mRef, paddings = MUGlobal.pagePaddings, pullToRefresh = true, searchBoxSx = getDefaultSearchBoxSx(paddings), sizeReadyMiliseconds = 0, ...rest } = props;
|
|
20
29
|
// Labels
|
|
21
30
|
const labels = Labels.CommonPage;
|
|
22
31
|
// Refs
|
|
@@ -70,7 +79,7 @@ export function ResponsibleContainer(props) {
|
|
|
70
79
|
const [list, showDataGrid] = (() => {
|
|
71
80
|
// No layout
|
|
72
81
|
if (rect == null)
|
|
73
|
-
return [null,
|
|
82
|
+
return [null, undefined];
|
|
74
83
|
// Width
|
|
75
84
|
const width = rect.width;
|
|
76
85
|
// Show DataGrid or List dependng on width
|
|
@@ -82,7 +91,9 @@ export function ResponsibleContainer(props) {
|
|
|
82
91
|
}
|
|
83
92
|
else {
|
|
84
93
|
// Auto calculation
|
|
85
|
-
heightLocal =
|
|
94
|
+
heightLocal =
|
|
95
|
+
document.documentElement.clientHeight -
|
|
96
|
+
Math.round(rect.bottom + 1);
|
|
86
97
|
const style = window.getComputedStyle(dimensions[0][1]);
|
|
87
98
|
const boxMargin = parseFloat(style.marginBottom);
|
|
88
99
|
if (!isNaN(boxMargin))
|
|
@@ -95,8 +106,13 @@ export function ResponsibleContainer(props) {
|
|
|
95
106
|
// Delete
|
|
96
107
|
delete rest.itemRenderer;
|
|
97
108
|
return [
|
|
98
|
-
React.createElement(Box, { sx: listBoxSx == null
|
|
99
|
-
|
|
109
|
+
React.createElement(Box, { sx: listBoxSx == null
|
|
110
|
+
? undefined
|
|
111
|
+
: listBoxSx(true, heightLocal) },
|
|
112
|
+
React.createElement(DataGridEx, { autoLoad: !hasFields, height: heightLocal, width: rect.width, loadData: localLoadData, mRef: mRefs, outerRef: (element) => {
|
|
113
|
+
if (element != null && elementReady)
|
|
114
|
+
elementReady(element, true);
|
|
115
|
+
}, columns: columns, ...rest })),
|
|
100
116
|
true
|
|
101
117
|
];
|
|
102
118
|
}
|
|
@@ -110,21 +126,33 @@ export function ResponsibleContainer(props) {
|
|
|
110
126
|
delete rest.hoverColor;
|
|
111
127
|
delete rest.selectable;
|
|
112
128
|
return [
|
|
113
|
-
React.createElement(Box, { sx: listBoxSx == null
|
|
114
|
-
|
|
129
|
+
React.createElement(Box, { sx: listBoxSx == null
|
|
130
|
+
? undefined
|
|
131
|
+
: listBoxSx(false, heightLocal) },
|
|
132
|
+
React.createElement(ScrollerListEx, { autoLoad: !hasFields, height: heightLocal, loadData: localLoadData, mRef: mRefs, oRef: (element) => {
|
|
133
|
+
if (element != null && elementReady)
|
|
134
|
+
elementReady(element, false);
|
|
135
|
+
}, ...rest })),
|
|
115
136
|
false
|
|
116
137
|
];
|
|
117
138
|
})();
|
|
139
|
+
const searchBar = React.useMemo(() => {
|
|
140
|
+
if (!hasFields || showDataGrid == null)
|
|
141
|
+
return;
|
|
142
|
+
return (React.createElement(SearchBar, { fields: fields, onSubmit: onSubmit, className: `searchBar${showDataGrid ? 'Grid' : 'List'}` }));
|
|
143
|
+
}, [showDataGrid, hasFields]);
|
|
118
144
|
// Pull container
|
|
119
|
-
const pullContainer =
|
|
120
|
-
?
|
|
145
|
+
const pullContainer = showDataGrid == null
|
|
146
|
+
? undefined
|
|
147
|
+
: showDataGrid
|
|
121
148
|
? '.DataGridEx-Body'
|
|
122
|
-
: '.ScrollerListEx-Body'
|
|
123
|
-
: undefined;
|
|
149
|
+
: '.ScrollerListEx-Body';
|
|
124
150
|
// Layout
|
|
125
|
-
return (React.createElement(
|
|
151
|
+
return (React.createElement(Box, { sx: containerBoxSx == null || showDataGrid == null
|
|
152
|
+
? undefined
|
|
153
|
+
: containerBoxSx(showDataGrid) },
|
|
126
154
|
React.createElement(Stack, null,
|
|
127
|
-
React.createElement(Box, { ref: dimensions[0][0], sx: searchBoxSx },
|
|
155
|
+
React.createElement(Box, { ref: dimensions[0][0], sx: searchBoxSx }, searchBar),
|
|
128
156
|
list),
|
|
129
157
|
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: () => {
|
|
130
158
|
const container = document.querySelector(pullContainer);
|
package/lib/mu/SearchBar.js
CHANGED
|
@@ -63,12 +63,12 @@ export function SearchBar(props) {
|
|
|
63
63
|
const [index, updateIndex] = React.useState();
|
|
64
64
|
// Drawer open / close
|
|
65
65
|
const [open, updateOpen] = React.useState(false);
|
|
66
|
-
//
|
|
67
|
-
const
|
|
66
|
+
// State
|
|
67
|
+
const state = React.useRef({}).current;
|
|
68
68
|
// Watch container
|
|
69
69
|
const { dimensions } = useDimensions(1, (target, rect) => {
|
|
70
70
|
// Same logic from resetButtonRef
|
|
71
|
-
if (rect.width ===
|
|
71
|
+
if (rect.width === state.lastMaxWidth)
|
|
72
72
|
return false;
|
|
73
73
|
// Len
|
|
74
74
|
const len = target.children.length;
|
|
@@ -96,10 +96,10 @@ export function SearchBar(props) {
|
|
|
96
96
|
return;
|
|
97
97
|
// Container width
|
|
98
98
|
let maxWidth = containerRect.width;
|
|
99
|
-
if (maxWidth ===
|
|
99
|
+
if (maxWidth === state.lastMaxWidth) {
|
|
100
100
|
return;
|
|
101
101
|
}
|
|
102
|
-
|
|
102
|
+
state.lastMaxWidth = maxWidth;
|
|
103
103
|
// More button
|
|
104
104
|
const buttonMore = resetButton.previousElementSibling;
|
|
105
105
|
// Cached button width
|
|
@@ -174,8 +174,8 @@ export function SearchBar(props) {
|
|
|
174
174
|
const handleForm = (event) => {
|
|
175
175
|
if (event.nativeEvent.cancelable && !event.nativeEvent.composed)
|
|
176
176
|
return;
|
|
177
|
-
if (
|
|
178
|
-
|
|
177
|
+
if (state.form == null)
|
|
178
|
+
state.form = event.currentTarget;
|
|
179
179
|
handleSubmit();
|
|
180
180
|
};
|
|
181
181
|
// Handle more button click
|
|
@@ -186,54 +186,56 @@ export function SearchBar(props) {
|
|
|
186
186
|
const moreFormChange = (event) => {
|
|
187
187
|
if (event.nativeEvent.cancelable && !event.nativeEvent.composed)
|
|
188
188
|
return;
|
|
189
|
-
if (
|
|
190
|
-
|
|
189
|
+
if (state.moreForm == null)
|
|
190
|
+
state.moreForm = event.currentTarget;
|
|
191
191
|
handleSubmit();
|
|
192
192
|
};
|
|
193
193
|
// Reset
|
|
194
194
|
const handleReset = () => {
|
|
195
195
|
// Clear form values
|
|
196
|
-
if (
|
|
197
|
-
resetForm(
|
|
198
|
-
if (
|
|
199
|
-
resetForm(
|
|
196
|
+
if (state.form != null)
|
|
197
|
+
resetForm(state.form);
|
|
198
|
+
if (state.moreForm != null)
|
|
199
|
+
resetForm(state.moreForm);
|
|
200
200
|
// Resubmit
|
|
201
201
|
handleSubmitInstant(true);
|
|
202
202
|
};
|
|
203
203
|
// Submit
|
|
204
|
-
const handleSubmit = () => {
|
|
205
|
-
if (
|
|
206
|
-
clearTimeout(
|
|
204
|
+
const handleSubmit = (delay = 480) => {
|
|
205
|
+
if (state.submitSeed != null) {
|
|
206
|
+
clearTimeout(state.submitSeed);
|
|
207
207
|
}
|
|
208
208
|
// Delay the change
|
|
209
|
-
|
|
209
|
+
state.submitSeed = window.setTimeout(handleSubmitInstant, delay);
|
|
210
210
|
};
|
|
211
211
|
// Submit at once
|
|
212
212
|
const handleSubmitInstant = (reset = false) => {
|
|
213
213
|
// Reset timeout
|
|
214
|
-
|
|
214
|
+
state.submitSeed = undefined;
|
|
215
215
|
// Prepare data
|
|
216
|
-
const data = new FormData(
|
|
217
|
-
if (
|
|
218
|
-
DomUtils.mergeFormData(data, new FormData(
|
|
216
|
+
const data = new FormData(state.form);
|
|
217
|
+
if (state.moreForm != null) {
|
|
218
|
+
DomUtils.mergeFormData(data, new FormData(state.moreForm));
|
|
219
219
|
}
|
|
220
220
|
onSubmit(data, reset);
|
|
221
221
|
};
|
|
222
222
|
// First loading
|
|
223
223
|
React.useEffect(() => {
|
|
224
|
-
// Delayed way
|
|
225
|
-
handleSubmit();
|
|
226
224
|
return () => {
|
|
227
225
|
// Clear the seeds
|
|
228
|
-
if (
|
|
229
|
-
clearTimeout(
|
|
226
|
+
if (state.submitSeed != null)
|
|
227
|
+
clearTimeout(state.submitSeed);
|
|
230
228
|
};
|
|
231
229
|
}, []);
|
|
230
|
+
React.useEffect(() => {
|
|
231
|
+
// Delayed way
|
|
232
|
+
handleSubmit(100);
|
|
233
|
+
}, [className]);
|
|
232
234
|
// Layout
|
|
233
235
|
return (React.createElement(React.Fragment, null,
|
|
234
236
|
React.createElement("form", { id: "SearchBarForm", className: className, onChange: handleForm, ref: (form) => {
|
|
235
237
|
if (form)
|
|
236
|
-
|
|
238
|
+
state.form = form;
|
|
237
239
|
} },
|
|
238
240
|
React.createElement(Stack, { ref: dimensions[0][0], justifyContent: "center", alignItems: "center", direction: "row", spacing: 1, height: innerHeight, sx: {
|
|
239
241
|
'& > :not(style)': {
|
|
@@ -260,7 +262,7 @@ export function SearchBar(props) {
|
|
|
260
262
|
}, open: open, onClose: () => updateOpen(false) },
|
|
261
263
|
React.createElement("form", { onChange: moreFormChange, ref: (form) => {
|
|
262
264
|
if (form)
|
|
263
|
-
|
|
265
|
+
state.moreForm = form;
|
|
264
266
|
} },
|
|
265
267
|
React.createElement(Stack, { direction: "column", alignItems: "stretch", spacing: 2, padding: 2 }, moreItems))))));
|
|
266
268
|
}
|
|
@@ -1,17 +1,12 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { FabBox } from '../FabBox';
|
|
3
3
|
import { ScrollTopFab } from '../ScrollTopFab';
|
|
4
|
-
import { PullToRefreshUI } from '../PullToRefreshUI';
|
|
5
4
|
import { Labels } from '../../app/Labels';
|
|
6
5
|
import { MUGlobal } from '../MUGlobal';
|
|
7
6
|
import { MoreFab } from '../MoreFab';
|
|
8
7
|
import { ReactAppStateDetector } from '../../app/ReactApp';
|
|
9
8
|
import { Container, Fab } from '@mui/material';
|
|
10
9
|
import RefreshIcon from '@mui/icons-material/Refresh';
|
|
11
|
-
/**
|
|
12
|
-
* Default pull container
|
|
13
|
-
*/
|
|
14
|
-
export const CommonPagePullContainer = '#page-container';
|
|
15
10
|
/**
|
|
16
11
|
* Default scroll container
|
|
17
12
|
*/
|
|
@@ -22,7 +17,7 @@ export const CommonPageScrollContainer = global;
|
|
|
22
17
|
*/
|
|
23
18
|
export function CommonPage(props) {
|
|
24
19
|
// Destruct
|
|
25
|
-
const { children, disableGutters = true, fabButtons, fabColumnDirection, fabPaddingAdjust = 1.5, fabSize = 'small', maxWidth = false, moreActions, onRefresh, onUpdate, onUpdateAll, paddings = MUGlobal.pagePaddings, scrollContainer, targetFields,
|
|
20
|
+
const { children, disableGutters = true, fabButtons, fabColumnDirection, fabPaddingAdjust = 1.5, fabSize = 'small', maxWidth = false, moreActions, onRefresh, onUpdate, onUpdateAll, paddings = MUGlobal.pagePaddings, scrollContainer, targetFields, sx = {}, ...rest } = props;
|
|
26
21
|
// Merge style
|
|
27
22
|
Object.assign(sx, {
|
|
28
23
|
padding: paddings
|
|
@@ -59,9 +54,5 @@ export function CommonPage(props) {
|
|
|
59
54
|
onRefresh != null && (React.createElement(Fab, { title: labels.refresh, size: fabSize, onClick: onRefresh, sx: { display: { xs: 'none', md: 'inherit' } } },
|
|
60
55
|
React.createElement(RefreshIcon, null))),
|
|
61
56
|
React.createElement(MoreFab, { size: fabSize, title: labels.more, actions: moreActions })),
|
|
62
|
-
children)
|
|
63
|
-
onRefresh != null && pullContainer != null && (React.createElement(PullToRefreshUI, { mainElement: pullContainer, triggerElement: pullContainer, instructionsPullToRefresh: labels.pullToRefresh, instructionsReleaseToRefresh: labels.releaseToRefresh, instructionsRefreshing: labels.refreshing, onRefresh: onRefresh, shouldPullToRefresh: () => {
|
|
64
|
-
const container = document.querySelector(pullContainer);
|
|
65
|
-
return !(container === null || container === void 0 ? void 0 : container.scrollTop);
|
|
66
|
-
} }))));
|
|
57
|
+
children)));
|
|
67
58
|
}
|
|
@@ -13,7 +13,7 @@ import { CommonPage } from './CommonPage';
|
|
|
13
13
|
* @returns Component
|
|
14
14
|
*/
|
|
15
15
|
export function DataGridPage(props) {
|
|
16
|
-
var _a
|
|
16
|
+
var _a;
|
|
17
17
|
// Destruct
|
|
18
18
|
const { adjustHeight, fields, fieldTemplate, height, loadData, mRef, sizeReadyMiliseconds = 100, pageProps = {}, ...rest } = props;
|
|
19
19
|
(_a = pageProps.paddings) !== null && _a !== void 0 ? _a : (pageProps.paddings = MUGlobal.pagePaddings);
|
|
@@ -42,7 +42,8 @@ export function DataGridPage(props) {
|
|
|
42
42
|
const rect = dimensions[0][2];
|
|
43
43
|
React.useEffect(() => {
|
|
44
44
|
if (rect != null && rect.height > 50 && height == null) {
|
|
45
|
-
let gridHeight =
|
|
45
|
+
let gridHeight = document.documentElement.clientHeight -
|
|
46
|
+
Math.round(rect.top + rect.height + 1);
|
|
46
47
|
const style = window.getComputedStyle(dimensions[0][1]);
|
|
47
48
|
const paddingBottom = parseFloat(style.paddingBottom);
|
|
48
49
|
if (!isNaN(paddingBottom))
|
|
@@ -69,12 +70,8 @@ export function DataGridPage(props) {
|
|
|
69
70
|
return;
|
|
70
71
|
ref.reset({ data });
|
|
71
72
|
}, [ref, data]);
|
|
72
|
-
// Pull container id
|
|
73
|
-
const pullContainer = ((_b = states.element) === null || _b === void 0 ? void 0 : _b.parentElement)
|
|
74
|
-
? '.DataGridEx-Body'
|
|
75
|
-
: undefined;
|
|
76
73
|
// Layout
|
|
77
|
-
return (React.createElement(CommonPage, { ...pageProps, scrollContainer: states.element
|
|
74
|
+
return (React.createElement(CommonPage, { ...pageProps, scrollContainer: states.element },
|
|
78
75
|
React.createElement(Stack, null,
|
|
79
76
|
React.createElement(Box, { ref: dimensions[0][0], sx: {
|
|
80
77
|
paddingBottom: pageProps.paddings
|
|
@@ -48,7 +48,8 @@ export function FixedListPage(props) {
|
|
|
48
48
|
const rect = dimensions[0][2];
|
|
49
49
|
const list = React.useMemo(() => {
|
|
50
50
|
if (rect != null && rect.height > 50) {
|
|
51
|
-
let height =
|
|
51
|
+
let height = document.documentElement.clientHeight -
|
|
52
|
+
Math.round(rect.top + rect.height + 1);
|
|
52
53
|
if (adjustHeight != null) {
|
|
53
54
|
height -= adjustHeight(height);
|
|
54
55
|
}
|
|
@@ -61,13 +62,9 @@ export function FixedListPage(props) {
|
|
|
61
62
|
}, ...rest })));
|
|
62
63
|
}
|
|
63
64
|
}, [rect]);
|
|
64
|
-
// Pull container id
|
|
65
|
-
const pullContainer = (scrollContainer === null || scrollContainer === void 0 ? void 0 : scrollContainer.parentElement)
|
|
66
|
-
? '#' + (scrollContainer === null || scrollContainer === void 0 ? void 0 : scrollContainer.parentElement.id)
|
|
67
|
-
: undefined;
|
|
68
65
|
const { paddings, ...pageRest } = pageProps;
|
|
69
66
|
// Layout
|
|
70
|
-
return (React.createElement(CommonPage, { ...pageRest, paddings: {}, scrollContainer: scrollContainer
|
|
67
|
+
return (React.createElement(CommonPage, { ...pageRest, paddings: {}, scrollContainer: scrollContainer },
|
|
71
68
|
React.createElement(Stack, null,
|
|
72
69
|
React.createElement(Box, { ref: dimensions[0][0], sx: { padding: paddings } },
|
|
73
70
|
React.createElement(SearchBar, { fields: fields, onSubmit: onSubmit })),
|
package/lib/mu/pages/ListPage.js
CHANGED
|
@@ -5,7 +5,7 @@ import useCombinedRefs from '../../uses/useCombinedRefs';
|
|
|
5
5
|
import { MUGlobal } from '../MUGlobal';
|
|
6
6
|
import { ScrollerListEx } from '../ScrollerListEx';
|
|
7
7
|
import { SearchBar } from '../SearchBar';
|
|
8
|
-
import { CommonPage,
|
|
8
|
+
import { CommonPage, CommonPageScrollContainer } from './CommonPage';
|
|
9
9
|
/**
|
|
10
10
|
* List page
|
|
11
11
|
* @param props Props
|
|
@@ -41,7 +41,7 @@ export function ListPage(props) {
|
|
|
41
41
|
return loadData(data);
|
|
42
42
|
};
|
|
43
43
|
// Layout
|
|
44
|
-
return (React.createElement(CommonPage, { ...pageProps, scrollContainer: CommonPageScrollContainer
|
|
44
|
+
return (React.createElement(CommonPage, { ...pageProps, scrollContainer: CommonPageScrollContainer },
|
|
45
45
|
React.createElement(Stack, null,
|
|
46
46
|
React.createElement(Box, { sx: {
|
|
47
47
|
paddingBottom: pageProps.paddings
|
|
@@ -1,12 +1,6 @@
|
|
|
1
|
-
import { Box, Stack } from '@mui/material';
|
|
2
1
|
import React from 'react';
|
|
3
|
-
import { GridDataGet } from '../../components/GridLoader';
|
|
4
|
-
import useCombinedRefs from '../../uses/useCombinedRefs';
|
|
5
|
-
import { useDimensions } from '../../uses/useDimensions';
|
|
6
|
-
import { DataGridEx, DataGridExCalColumns } from '../DataGridEx';
|
|
7
2
|
import { MUGlobal } from '../MUGlobal';
|
|
8
|
-
import {
|
|
9
|
-
import { SearchBar } from '../SearchBar';
|
|
3
|
+
import { ResponsibleContainer } from '../ResponsibleContainer';
|
|
10
4
|
import { CommonPage } from './CommonPage';
|
|
11
5
|
/**
|
|
12
6
|
* Fixed height list page
|
|
@@ -14,119 +8,39 @@ import { CommonPage } from './CommonPage';
|
|
|
14
8
|
* @returns Component
|
|
15
9
|
*/
|
|
16
10
|
export function ResponsivePage(props) {
|
|
17
|
-
var _a
|
|
11
|
+
var _a;
|
|
18
12
|
// Destruct
|
|
19
|
-
const {
|
|
13
|
+
const { pageProps = {}, ...rest } = props;
|
|
20
14
|
(_a = pageProps.paddings) !== null && _a !== void 0 ? _a : (pageProps.paddings = MUGlobal.pagePaddings);
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
height
|
|
26
|
-
});
|
|
27
|
-
const localLoadData = (props) => {
|
|
28
|
-
const data = GridDataGet(props, fieldTemplate);
|
|
29
|
-
return loadData(data);
|
|
30
|
-
};
|
|
31
|
-
const refs = useCombinedRefs(mRef, (ref) => {
|
|
32
|
-
if (ref == null)
|
|
33
|
-
return;
|
|
34
|
-
states.ref = ref;
|
|
35
|
-
// setStates({ ref });
|
|
36
|
-
});
|
|
37
|
-
// On submit callback
|
|
38
|
-
const onSubmit = (data, _reset) => {
|
|
39
|
-
setStates({ data });
|
|
40
|
-
};
|
|
41
|
-
// Watch container
|
|
42
|
-
const { dimensions } = useDimensions(1, undefined, sizeReadyMiliseconds);
|
|
43
|
-
const rect = dimensions[0][2];
|
|
44
|
-
const showDataGrid = ((_b = rect === null || rect === void 0 ? void 0 : rect.width) !== null && _b !== void 0 ? _b : 0) >= dataGridMinWidth;
|
|
45
|
-
React.useEffect(() => {
|
|
46
|
-
if (rect != null && rect.height > 50 && height == null) {
|
|
47
|
-
let gridHeight = window.innerHeight - Math.round(rect.top + rect.height + 1);
|
|
48
|
-
const style = window.getComputedStyle(dimensions[0][1]);
|
|
49
|
-
const boxPadding = parseFloat(style.paddingLeft);
|
|
50
|
-
if (!isNaN(boxPadding))
|
|
51
|
-
gridHeight -= 2 * boxPadding;
|
|
52
|
-
if (adjustHeight != null) {
|
|
53
|
-
gridHeight -= adjustHeight(gridHeight);
|
|
54
|
-
}
|
|
55
|
-
if (gridHeight !== states.height)
|
|
56
|
-
setStates({ height: gridHeight });
|
|
57
|
-
}
|
|
58
|
-
}, [rect]);
|
|
59
|
-
const { paddings, ...pageRest } = pageProps;
|
|
60
|
-
const list = React.useMemo(() => {
|
|
61
|
-
const gridHeight = states.height;
|
|
62
|
-
if (gridHeight == null)
|
|
63
|
-
return;
|
|
64
|
-
// Show in a row when under DataGrid
|
|
65
|
-
pageProps.fabColumnDirection = !showDataGrid;
|
|
66
|
-
if (showDataGrid) {
|
|
67
|
-
// Delete
|
|
68
|
-
delete rest.itemRenderer;
|
|
69
|
-
return (React.createElement(Box, { sx: {
|
|
70
|
-
padding: paddings
|
|
71
|
-
} },
|
|
72
|
-
React.createElement(DataGridEx, { autoLoad: false, height: gridHeight, loadData: localLoadData, mRef: refs, columns: columns, outerRef: (element) => {
|
|
73
|
-
if (element != null)
|
|
74
|
-
setStates({ element });
|
|
75
|
-
}, ...rest })));
|
|
76
|
-
}
|
|
77
|
-
// Delete
|
|
78
|
-
delete rest.checkable;
|
|
79
|
-
delete rest.borderRowsCount;
|
|
80
|
-
delete rest.bottomHeight;
|
|
81
|
-
delete rest.footerItemRenderer;
|
|
82
|
-
delete rest.headerHeight;
|
|
83
|
-
delete rest.hideFooter;
|
|
84
|
-
delete rest.hoverColor;
|
|
85
|
-
delete rest.selectable;
|
|
86
|
-
// Half
|
|
87
|
-
const halfPadding = MUGlobal.half(paddings);
|
|
88
|
-
const style = window.getComputedStyle(dimensions[0][1]);
|
|
89
|
-
const boxPadding = parseFloat(style.paddingLeft);
|
|
90
|
-
return (React.createElement(Box, { sx: {
|
|
91
|
-
height: gridHeight + (isNaN(boxPadding) ? 0 : boxPadding),
|
|
92
|
-
paddingTop: halfPadding,
|
|
93
|
-
paddingBottom: halfPadding
|
|
94
|
-
} },
|
|
95
|
-
React.createElement(ScrollerListEx, { autoLoad: false, height: gridHeight, innerItemRenderer: innerItemRenderer, itemSize: itemSize, loadData: localLoadData, mRef: refs, oRef: (element) => {
|
|
96
|
-
if (element != null)
|
|
97
|
-
setStates({ element });
|
|
98
|
-
}, ...rest })));
|
|
99
|
-
}, [states.height, showDataGrid, localLoadData]);
|
|
100
|
-
const sizeRef = React.useRef();
|
|
101
|
-
const { ref, data } = states;
|
|
102
|
-
React.useEffect(() => {
|
|
103
|
-
if (ref == null || data == null || rect == null)
|
|
104
|
-
return;
|
|
105
|
-
// Resize without reset
|
|
106
|
-
if (sizeRef.current == null) {
|
|
107
|
-
sizeRef.current = [rect.width, rect.height];
|
|
108
|
-
}
|
|
109
|
-
else if (sizeRef.current[0] !== rect.width ||
|
|
110
|
-
sizeRef.current[1] !== rect.height) {
|
|
111
|
-
sizeRef.current = [rect.width, rect.height];
|
|
112
|
-
return;
|
|
113
|
-
}
|
|
114
|
-
ref.reset({ data });
|
|
115
|
-
});
|
|
116
|
-
// Pull container id
|
|
117
|
-
const pullContainer = states.element
|
|
118
|
-
? showDataGrid
|
|
119
|
-
? '.DataGridEx-Body'
|
|
120
|
-
: '.ScrollerListEx-Body'
|
|
121
|
-
: undefined;
|
|
15
|
+
const { paddings, fabColumnDirection, ...pageRest } = pageProps;
|
|
16
|
+
// State
|
|
17
|
+
const [scrollContainer, setScrollContainer] = React.useState();
|
|
18
|
+
const [direction, setDirection] = React.useState(fabColumnDirection);
|
|
122
19
|
// Layout
|
|
123
|
-
return (React.createElement(CommonPage, { ...pageRest, paddings: {}, scrollContainer:
|
|
124
|
-
React.createElement(
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
|
|
20
|
+
return (React.createElement(CommonPage, { ...pageRest, paddings: {}, scrollContainer: scrollContainer, fabColumnDirection: direction },
|
|
21
|
+
React.createElement(ResponsibleContainer, { paddings: paddings, containerBoxSx: (dataGrid) => {
|
|
22
|
+
if (dataGrid) {
|
|
23
|
+
return {
|
|
24
|
+
padding: paddings
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
else {
|
|
28
|
+
return {
|
|
29
|
+
paddingTop: paddings,
|
|
30
|
+
paddingBottom: paddings
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
}, elementReady: (element, isDataGrid) => {
|
|
34
|
+
setDirection(!isDataGrid);
|
|
35
|
+
setScrollContainer(element);
|
|
36
|
+
}, listBoxSx: (dataGrid, height) => {
|
|
37
|
+
if (dataGrid) {
|
|
38
|
+
return {};
|
|
39
|
+
}
|
|
40
|
+
else {
|
|
41
|
+
return {
|
|
42
|
+
height: height
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
}, ...rest })));
|
|
132
46
|
}
|