@etsoo/react 1.5.79 → 1.5.82

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.
Files changed (255) hide show
  1. package/README.md +7 -2
  2. package/__tests__/ReactUtils.ts +6 -0
  3. package/lib/{mu → components}/DnDList.d.ts +1 -14
  4. package/lib/{mu → components}/DnDList.js +1 -24
  5. package/lib/components/GridMethodRef.d.ts +11 -0
  6. package/lib/{mu → components}/GridMethodRef.js +0 -0
  7. package/lib/components/ScrollerGrid.d.ts +3 -3
  8. package/lib/components/ScrollerList.d.ts +3 -3
  9. package/lib/index.d.ts +2 -74
  10. package/lib/index.js +2 -75
  11. package/lib/notifier/Notifier.d.ts +2 -3
  12. package/lib/uses/useWindowScroll.d.ts +10 -0
  13. package/lib/uses/useWindowScroll.js +46 -0
  14. package/lib/uses/useWindowSize.js +11 -5
  15. package/package.json +9 -21
  16. package/src/{mu → components}/DnDList.tsx +11 -34
  17. package/src/components/GridMethodRef.ts +12 -0
  18. package/src/components/ScrollerGrid.tsx +3 -3
  19. package/src/components/ScrollerList.tsx +5 -3
  20. package/src/index.ts +2 -78
  21. package/src/notifier/Notifier.ts +2 -3
  22. package/src/uses/useWindowScroll.ts +60 -0
  23. package/src/uses/useWindowSize.ts +14 -5
  24. package/__tests__/mu/MUGlobalTests.tsx +0 -58
  25. package/__tests__/mu/NotifierMUTests.tsx +0 -213
  26. package/lib/app/CommonApp.d.ts +0 -39
  27. package/lib/app/CommonApp.js +0 -149
  28. package/lib/app/IServiceAppSettings.d.ts +0 -11
  29. package/lib/app/IServiceAppSettings.js +0 -1
  30. package/lib/app/IServicePage.d.ts +0 -6
  31. package/lib/app/IServicePage.js +0 -1
  32. package/lib/app/IServiceUser.d.ts +0 -14
  33. package/lib/app/IServiceUser.js +0 -1
  34. package/lib/app/ISmartERPUser.d.ts +0 -14
  35. package/lib/app/ISmartERPUser.js +0 -1
  36. package/lib/app/Labels.d.ts +0 -65
  37. package/lib/app/Labels.js +0 -62
  38. package/lib/app/ReactApp.d.ts +0 -194
  39. package/lib/app/ReactApp.js +0 -298
  40. package/lib/app/ServiceApp.d.ts +0 -78
  41. package/lib/app/ServiceApp.js +0 -244
  42. package/lib/components/ShowDataComparison.d.ts +0 -20
  43. package/lib/components/ShowDataComparison.js +0 -60
  44. package/lib/mu/AuditDisplay.d.ts +0 -33
  45. package/lib/mu/AuditDisplay.js +0 -52
  46. package/lib/mu/AutocompleteExtendedProps.d.ts +0 -64
  47. package/lib/mu/AutocompleteExtendedProps.js +0 -1
  48. package/lib/mu/BackButton.d.ts +0 -13
  49. package/lib/mu/BackButton.js +0 -33
  50. package/lib/mu/BridgeCloseButton.d.ts +0 -23
  51. package/lib/mu/BridgeCloseButton.js +0 -32
  52. package/lib/mu/ButtonLink.d.ts +0 -17
  53. package/lib/mu/ButtonLink.js +0 -19
  54. package/lib/mu/ComboBox.d.ts +0 -38
  55. package/lib/mu/ComboBox.js +0 -108
  56. package/lib/mu/CountdownButton.d.ts +0 -23
  57. package/lib/mu/CountdownButton.js +0 -81
  58. package/lib/mu/CustomFabProps.d.ts +0 -27
  59. package/lib/mu/CustomFabProps.js +0 -1
  60. package/lib/mu/DataGridEx.d.ts +0 -96
  61. package/lib/mu/DataGridEx.js +0 -331
  62. package/lib/mu/DataGridRenderers.d.ts +0 -22
  63. package/lib/mu/DataGridRenderers.js +0 -99
  64. package/lib/mu/DialogButton.d.ts +0 -54
  65. package/lib/mu/DialogButton.js +0 -45
  66. package/lib/mu/DraggablePaperComponent.d.ts +0 -8
  67. package/lib/mu/DraggablePaperComponent.js +0 -12
  68. package/lib/mu/EmailInput.d.ts +0 -11
  69. package/lib/mu/EmailInput.js +0 -15
  70. package/lib/mu/FabBox.d.ts +0 -21
  71. package/lib/mu/FabBox.js +0 -31
  72. package/lib/mu/FlexBox.d.ts +0 -14
  73. package/lib/mu/FlexBox.js +0 -18
  74. package/lib/mu/GridDataFormat.d.ts +0 -10
  75. package/lib/mu/GridDataFormat.js +0 -43
  76. package/lib/mu/GridMethodRef.d.ts +0 -11
  77. package/lib/mu/IconButtonLink.d.ts +0 -17
  78. package/lib/mu/IconButtonLink.js +0 -16
  79. package/lib/mu/InputField.d.ts +0 -21
  80. package/lib/mu/InputField.js +0 -39
  81. package/lib/mu/ItemList.d.ts +0 -56
  82. package/lib/mu/ItemList.js +0 -69
  83. package/lib/mu/ListItemRightIcon.d.ts +0 -4
  84. package/lib/mu/ListItemRightIcon.js +0 -8
  85. package/lib/mu/ListMoreDisplay.d.ts +0 -35
  86. package/lib/mu/ListMoreDisplay.js +0 -99
  87. package/lib/mu/LoadingButton.d.ts +0 -16
  88. package/lib/mu/LoadingButton.js +0 -41
  89. package/lib/mu/MUGlobal.d.ts +0 -102
  90. package/lib/mu/MUGlobal.js +0 -184
  91. package/lib/mu/MaskInput.d.ts +0 -34
  92. package/lib/mu/MaskInput.js +0 -43
  93. package/lib/mu/MobileListItemRenderer.d.ts +0 -17
  94. package/lib/mu/MobileListItemRenderer.js +0 -35
  95. package/lib/mu/MoreFab.d.ts +0 -45
  96. package/lib/mu/MoreFab.js +0 -95
  97. package/lib/mu/NotifierMU.d.ts +0 -47
  98. package/lib/mu/NotifierMU.js +0 -387
  99. package/lib/mu/NotifierPromptProps.d.ts +0 -22
  100. package/lib/mu/NotifierPromptProps.js +0 -1
  101. package/lib/mu/OptionGroup.d.ts +0 -58
  102. package/lib/mu/OptionGroup.js +0 -81
  103. package/lib/mu/PList.d.ts +0 -15
  104. package/lib/mu/PList.js +0 -12
  105. package/lib/mu/ProgressCount.d.ts +0 -44
  106. package/lib/mu/ProgressCount.js +0 -79
  107. package/lib/mu/PullToRefreshUI.d.ts +0 -9
  108. package/lib/mu/PullToRefreshUI.js +0 -18
  109. package/lib/mu/RLink.d.ts +0 -14
  110. package/lib/mu/RLink.js +0 -37
  111. package/lib/mu/ResponsibleContainer.d.ts +0 -89
  112. package/lib/mu/ResponsibleContainer.js +0 -159
  113. package/lib/mu/ScrollTopFab.d.ts +0 -7
  114. package/lib/mu/ScrollTopFab.js +0 -25
  115. package/lib/mu/ScrollerListEx.d.ts +0 -81
  116. package/lib/mu/ScrollerListEx.js +0 -167
  117. package/lib/mu/SearchBar.d.ts +0 -29
  118. package/lib/mu/SearchBar.js +0 -262
  119. package/lib/mu/SearchField.d.ts +0 -21
  120. package/lib/mu/SearchField.js +0 -39
  121. package/lib/mu/SearchOptionGroup.d.ts +0 -9
  122. package/lib/mu/SearchOptionGroup.js +0 -14
  123. package/lib/mu/SelectBool.d.ts +0 -13
  124. package/lib/mu/SelectBool.js +0 -22
  125. package/lib/mu/SelectEx.d.ts +0 -50
  126. package/lib/mu/SelectEx.js +0 -156
  127. package/lib/mu/Switch.d.ts +0 -29
  128. package/lib/mu/Switch.js +0 -34
  129. package/lib/mu/SwitchAnt.d.ts +0 -25
  130. package/lib/mu/SwitchAnt.js +0 -40
  131. package/lib/mu/TabBox.d.ts +0 -54
  132. package/lib/mu/TabBox.js +0 -31
  133. package/lib/mu/TableEx.d.ts +0 -66
  134. package/lib/mu/TableEx.js +0 -271
  135. package/lib/mu/TextFieldEx.d.ts +0 -101
  136. package/lib/mu/TextFieldEx.js +0 -127
  137. package/lib/mu/Tiplist.d.ts +0 -18
  138. package/lib/mu/Tiplist.js +0 -158
  139. package/lib/mu/TooltipClick.d.ts +0 -15
  140. package/lib/mu/TooltipClick.js +0 -40
  141. package/lib/mu/UserAvatar.d.ts +0 -24
  142. package/lib/mu/UserAvatar.js +0 -25
  143. package/lib/mu/UserAvatarEditor.d.ts +0 -53
  144. package/lib/mu/UserAvatarEditor.js +0 -129
  145. package/lib/mu/pages/CommonPage.d.ts +0 -11
  146. package/lib/mu/pages/CommonPage.js +0 -60
  147. package/lib/mu/pages/CommonPageProps.d.ts +0 -60
  148. package/lib/mu/pages/CommonPageProps.js +0 -1
  149. package/lib/mu/pages/DataGridPage.d.ts +0 -9
  150. package/lib/mu/pages/DataGridPage.js +0 -81
  151. package/lib/mu/pages/DataGridPageProps.d.ts +0 -17
  152. package/lib/mu/pages/DataGridPageProps.js +0 -1
  153. package/lib/mu/pages/EditPage.d.ts +0 -33
  154. package/lib/mu/pages/EditPage.js +0 -29
  155. package/lib/mu/pages/FixedListPage.d.ts +0 -15
  156. package/lib/mu/pages/FixedListPage.js +0 -72
  157. package/lib/mu/pages/ListPage.d.ts +0 -9
  158. package/lib/mu/pages/ListPage.js +0 -51
  159. package/lib/mu/pages/ListPageProps.d.ts +0 -7
  160. package/lib/mu/pages/ListPageProps.js +0 -1
  161. package/lib/mu/pages/ResponsivePage.d.ts +0 -9
  162. package/lib/mu/pages/ResponsivePage.js +0 -45
  163. package/lib/mu/pages/ResponsivePageProps.d.ts +0 -39
  164. package/lib/mu/pages/ResponsivePageProps.js +0 -1
  165. package/lib/mu/pages/SearchPageProps.d.ts +0 -30
  166. package/lib/mu/pages/SearchPageProps.js +0 -1
  167. package/lib/mu/pages/TablePage.d.ts +0 -9
  168. package/lib/mu/pages/TablePage.js +0 -71
  169. package/lib/mu/pages/TablePageProps.d.ts +0 -7
  170. package/lib/mu/pages/TablePageProps.js +0 -1
  171. package/lib/mu/pages/ViewPage.d.ts +0 -66
  172. package/lib/mu/pages/ViewPage.js +0 -105
  173. package/lib/mu/texts/DateText.d.ts +0 -34
  174. package/lib/mu/texts/DateText.js +0 -25
  175. package/lib/mu/texts/MoneyText.d.ts +0 -21
  176. package/lib/mu/texts/MoneyText.js +0 -14
  177. package/lib/mu/texts/NumberText.d.ts +0 -25
  178. package/lib/mu/texts/NumberText.js +0 -14
  179. package/src/app/CommonApp.ts +0 -225
  180. package/src/app/IServiceAppSettings.ts +0 -13
  181. package/src/app/IServicePage.ts +0 -6
  182. package/src/app/IServiceUser.ts +0 -17
  183. package/src/app/ISmartERPUser.ts +0 -16
  184. package/src/app/Labels.ts +0 -77
  185. package/src/app/ReactApp.ts +0 -500
  186. package/src/app/ServiceApp.ts +0 -353
  187. package/src/components/ShowDataComparison.tsx +0 -108
  188. package/src/mu/AuditDisplay.tsx +0 -117
  189. package/src/mu/AutocompleteExtendedProps.ts +0 -83
  190. package/src/mu/BackButton.tsx +0 -55
  191. package/src/mu/BridgeCloseButton.tsx +0 -69
  192. package/src/mu/ButtonLink.tsx +0 -32
  193. package/src/mu/ComboBox.tsx +0 -251
  194. package/src/mu/CountdownButton.tsx +0 -119
  195. package/src/mu/CustomFabProps.ts +0 -32
  196. package/src/mu/DataGridEx.tsx +0 -712
  197. package/src/mu/DataGridRenderers.tsx +0 -140
  198. package/src/mu/DialogButton.tsx +0 -163
  199. package/src/mu/DraggablePaperComponent.tsx +0 -19
  200. package/src/mu/EmailInput.tsx +0 -24
  201. package/src/mu/FabBox.tsx +0 -51
  202. package/src/mu/FlexBox.tsx +0 -20
  203. package/src/mu/GridDataFormat.tsx +0 -77
  204. package/src/mu/GridMethodRef.ts +0 -12
  205. package/src/mu/IconButtonLink.tsx +0 -29
  206. package/src/mu/InputField.tsx +0 -82
  207. package/src/mu/ItemList.tsx +0 -204
  208. package/src/mu/ListItemRightIcon.tsx +0 -9
  209. package/src/mu/ListMoreDisplay.tsx +0 -205
  210. package/src/mu/LoadingButton.tsx +0 -75
  211. package/src/mu/MUGlobal.ts +0 -220
  212. package/src/mu/MaskInput.tsx +0 -107
  213. package/src/mu/MobileListItemRenderer.tsx +0 -79
  214. package/src/mu/MoreFab.tsx +0 -211
  215. package/src/mu/NotifierMU.tsx +0 -654
  216. package/src/mu/NotifierPromptProps.ts +0 -26
  217. package/src/mu/OptionGroup.tsx +0 -223
  218. package/src/mu/PList.tsx +0 -27
  219. package/src/mu/ProgressCount.tsx +0 -166
  220. package/src/mu/PullToRefreshUI.tsx +0 -21
  221. package/src/mu/RLink.tsx +0 -64
  222. package/src/mu/ResponsibleContainer.tsx +0 -394
  223. package/src/mu/ScrollTopFab.tsx +0 -34
  224. package/src/mu/ScrollerListEx.tsx +0 -387
  225. package/src/mu/SearchBar.tsx +0 -398
  226. package/src/mu/SearchField.tsx +0 -82
  227. package/src/mu/SearchOptionGroup.tsx +0 -31
  228. package/src/mu/SelectBool.tsx +0 -33
  229. package/src/mu/SelectEx.tsx +0 -290
  230. package/src/mu/Switch.tsx +0 -94
  231. package/src/mu/SwitchAnt.tsx +0 -95
  232. package/src/mu/TabBox.tsx +0 -118
  233. package/src/mu/TableEx.tsx +0 -560
  234. package/src/mu/TextFieldEx.tsx +0 -250
  235. package/src/mu/Tiplist.tsx +0 -304
  236. package/src/mu/TooltipClick.tsx +0 -84
  237. package/src/mu/UserAvatar.tsx +0 -64
  238. package/src/mu/UserAvatarEditor.tsx +0 -287
  239. package/src/mu/pages/CommonPage.tsx +0 -128
  240. package/src/mu/pages/CommonPageProps.ts +0 -71
  241. package/src/mu/pages/DataGridPage.tsx +0 -137
  242. package/src/mu/pages/DataGridPageProps.ts +0 -24
  243. package/src/mu/pages/EditPage.tsx +0 -114
  244. package/src/mu/pages/FixedListPage.tsx +0 -135
  245. package/src/mu/pages/ListPage.tsx +0 -87
  246. package/src/mu/pages/ListPageProps.ts +0 -12
  247. package/src/mu/pages/ResponsivePage.tsx +0 -68
  248. package/src/mu/pages/ResponsivePageProps.ts +0 -57
  249. package/src/mu/pages/SearchPageProps.ts +0 -39
  250. package/src/mu/pages/TablePage.tsx +0 -120
  251. package/src/mu/pages/TablePageProps.ts +0 -12
  252. package/src/mu/pages/ViewPage.tsx +0 -285
  253. package/src/mu/texts/DateText.tsx +0 -74
  254. package/src/mu/texts/MoneyText.tsx +0 -49
  255. package/src/mu/texts/NumberText.tsx +0 -40
@@ -1,287 +0,0 @@
1
- import { Button, ButtonGroup, Slider, Stack } from '@mui/material';
2
- import React from 'react';
3
- import AvatarEditor from 'react-avatar-editor';
4
- import RotateLeftIcon from '@mui/icons-material/RotateLeft';
5
- import RotateRightIcon from '@mui/icons-material/RotateRight';
6
- import ClearAllIcon from '@mui/icons-material/ClearAll';
7
- import ComputerIcon from '@mui/icons-material/Computer';
8
- import DoneIcon from '@mui/icons-material/Done';
9
- import pica from 'pica';
10
- import { Labels } from '../app/Labels';
11
-
12
- /**
13
- * User avatar editor to Blob helper
14
- */
15
- export interface UserAvatarEditorToBlob {
16
- (
17
- canvas: HTMLCanvasElement,
18
- mimeType?: string,
19
- quality?: number
20
- ): Promise<Blob>;
21
- }
22
-
23
- /**
24
- * User avatar editor on done handler
25
- */
26
- export interface UserAvatarEditorOnDoneHandler {
27
- (canvas: HTMLCanvasElement, toBlob: UserAvatarEditorToBlob): void;
28
- }
29
-
30
- /**
31
- * User avatar editor props
32
- */
33
- export interface UserAvatarEditorProps {
34
- /**
35
- * Cropping border size
36
- */
37
- border?: number;
38
-
39
- /**
40
- * Image source
41
- */
42
- image?: string | File;
43
-
44
- /**
45
- * Max width to save
46
- */
47
- maxWidth?: number;
48
-
49
- /**
50
- * On done handler
51
- */
52
- onDone: UserAvatarEditorOnDoneHandler;
53
-
54
- /**
55
- * Return scaled result?
56
- */
57
- scaledResult?: boolean;
58
-
59
- /**
60
- * Width of the editor
61
- */
62
- width?: number;
63
-
64
- /**
65
- * Height of the editor
66
- */
67
- height?: number;
68
- }
69
-
70
- interface EditorState {
71
- scale: number;
72
- rotate: number;
73
- }
74
-
75
- const defaultState: EditorState = {
76
- scale: 1,
77
- rotate: 0
78
- };
79
-
80
- /**
81
- * User avatar editor
82
- * https://github.com/mosch/react-avatar-editor
83
- * @param props Props
84
- * @returns Component
85
- */
86
- export function UserAvatarEditor(props: UserAvatarEditorProps) {
87
- // Destruct
88
- const {
89
- border = 30,
90
- image,
91
- maxWidth,
92
- onDone,
93
- scaledResult = false,
94
- width = 200,
95
- height = 200
96
- } = props;
97
-
98
- // Container width
99
- const containerWidth = width + 2 * border + 44 + 4;
100
-
101
- // Calculated max width
102
- const maxWidthCalculated =
103
- maxWidth == null || maxWidth < 200 ? 3 * width : maxWidth;
104
-
105
- // Labels
106
- const labels = Labels.UserAvatarEditor;
107
-
108
- // Ref
109
- const ref = React.createRef<AvatarEditor>();
110
-
111
- // Button ref
112
- const buttonRef = React.createRef<HTMLButtonElement>();
113
-
114
- // Preview image state
115
- const [previewImage, setPreviewImage] = React.useState(image);
116
-
117
- // Is ready state
118
- const [ready, setReady] = React.useState(false);
119
-
120
- // Editor states
121
- const [editorState, setEditorState] = React.useState(defaultState);
122
-
123
- // Handle zoom
124
- const handleZoom = (
125
- _event: Event,
126
- value: number | number[],
127
- _activeThumb: number
128
- ) => {
129
- const scale = typeof value === 'number' ? value : value[0];
130
- const newState = { ...editorState, scale };
131
- setEditorState(newState);
132
- };
133
-
134
- // Handle image load
135
- const handleLoad = () => {
136
- setReady(true);
137
- };
138
-
139
- // Handle file change
140
- const handleFileChange = (event: React.ChangeEvent<HTMLInputElement>) => {
141
- const files = event.target.files;
142
- if (files == null || files.length == 0) return;
143
-
144
- // Reset all settings
145
- handleReset();
146
-
147
- // Set new preview image
148
- setPreviewImage(files[0]);
149
-
150
- // Set ready state
151
- setReady(false);
152
-
153
- // Make the submit button visible
154
- buttonRef.current?.scrollIntoView(false);
155
- };
156
-
157
- // Handle reset
158
- const handleReset = () => {
159
- setEditorState({ ...defaultState });
160
- };
161
-
162
- // Handle rotate
163
- const handleRotate = (r: number) => {
164
- let rotate = editorState.rotate + r;
165
- if (rotate >= 360 || rotate <= -360) rotate = 0;
166
-
167
- const newState = { ...editorState, rotate };
168
- setEditorState(newState);
169
- };
170
-
171
- // Handle done
172
- const handleDone = () => {
173
- // Data
174
- var data = scaledResult
175
- ? ref.current?.getImageScaledToCanvas()
176
- : ref.current?.getImage();
177
- if (data == null) return;
178
-
179
- // pica
180
- const picaInstance = pica();
181
-
182
- // toBlob helper
183
- // Convenience method, similar to canvas.toBlob(), but with promise interface & polyfill for old browsers.
184
- const toBlob = (
185
- canvas: HTMLCanvasElement,
186
- mimeType: string = 'image/jpeg',
187
- quality: number = 1
188
- ) => {
189
- return picaInstance.toBlob(canvas, mimeType, quality);
190
- };
191
-
192
- if (data.width > maxWidthCalculated) {
193
- // Target height
194
- const heightCalculated = (height * maxWidthCalculated) / width;
195
-
196
- // Target
197
- const to = document.createElement('canvas');
198
- to.width = maxWidthCalculated;
199
- to.height = heightCalculated;
200
-
201
- // Large photo, resize it
202
- // https://github.com/nodeca/pica
203
- picaInstance
204
- .resize(data, to, {
205
- unsharpAmount: 160,
206
- unsharpRadius: 0.6,
207
- unsharpThreshold: 1
208
- })
209
- .then((result) => onDone(result, toBlob));
210
- } else {
211
- onDone(data, toBlob);
212
- }
213
- };
214
-
215
- return (
216
- <Stack direction="column" spacing={0.5} width={containerWidth}>
217
- <Button
218
- variant="outlined"
219
- size="medium"
220
- component="label"
221
- startIcon={<ComputerIcon />}
222
- fullWidth
223
- >
224
- {labels.upload}
225
- <input
226
- id="fileInput"
227
- type="file"
228
- accept="image/png, image/jpeg"
229
- multiple={false}
230
- hidden
231
- onChange={handleFileChange}
232
- />
233
- </Button>
234
- <Stack direction="row" spacing={0.5}>
235
- <AvatarEditor
236
- ref={ref}
237
- border={border}
238
- width={width}
239
- height={height}
240
- onLoadSuccess={handleLoad}
241
- image={previewImage ?? ''}
242
- scale={editorState.scale}
243
- rotate={editorState.rotate}
244
- />
245
- <ButtonGroup
246
- size="small"
247
- orientation="vertical"
248
- disabled={!ready}
249
- >
250
- <Button
251
- onClick={() => handleRotate(90)}
252
- title={labels.rotateRight}
253
- >
254
- <RotateRightIcon />
255
- </Button>
256
- <Button
257
- onClick={() => handleRotate(-90)}
258
- title={labels.rotateLeft}
259
- >
260
- <RotateLeftIcon />
261
- </Button>
262
- <Button onClick={handleReset} title={labels.reset}>
263
- <ClearAllIcon />
264
- </Button>
265
- </ButtonGroup>
266
- </Stack>
267
- <Slider
268
- title={labels.zoom}
269
- disabled={!ready}
270
- min={1}
271
- max={5}
272
- step={0.01}
273
- value={editorState.scale}
274
- onChange={handleZoom}
275
- />
276
- <Button
277
- ref={buttonRef}
278
- variant="contained"
279
- startIcon={<DoneIcon />}
280
- disabled={!ready}
281
- onClick={handleDone}
282
- >
283
- {labels.done}
284
- </Button>
285
- </Stack>
286
- );
287
- }
@@ -1,128 +0,0 @@
1
- import React from 'react';
2
- import { FabBox } from '../FabBox';
3
- import { ScrollTopFab } from '../ScrollTopFab';
4
- import { Labels } from '../../app/Labels';
5
- import { MUGlobal } from '../MUGlobal';
6
- import { CommonPageProps } from './CommonPageProps';
7
- import { MoreFab } from '../MoreFab';
8
- import { ReactAppStateDetector } from '../../app/ReactApp';
9
- import { Container, Fab } from '@mui/material';
10
- import RefreshIcon from '@mui/icons-material/Refresh';
11
- import { BackButton } from '../BackButton';
12
-
13
- /**
14
- * Default scroll container
15
- */
16
- export const CommonPageScrollContainer = global;
17
-
18
- /**
19
- * Common page
20
- * @param props Props
21
- */
22
- export function CommonPage(props: CommonPageProps) {
23
- // Destruct
24
- const {
25
- children,
26
- disableGutters = true,
27
- fabButtons,
28
- fabColumnDirection,
29
- fabPaddingAdjust = 1.5,
30
- fabSize = 'small',
31
- maxWidth = false,
32
- moreActions,
33
- onRefresh,
34
- onUpdate,
35
- onUpdateAll,
36
- paddings = MUGlobal.pagePaddings,
37
- scrollContainer,
38
- supportBack = false,
39
- targetFields,
40
- sx = {},
41
- ...rest
42
- } = props;
43
-
44
- // Fab padding
45
- const fabPadding = MUGlobal.increase(
46
- MUGlobal.pagePaddings,
47
- fabPaddingAdjust
48
- );
49
-
50
- if (typeof sx === 'object' && sx != null && !Reflect.has(sx, 'padding')) {
51
- // Set default padding
52
- Reflect.set(sx, 'padding', paddings);
53
- }
54
-
55
- // Labels
56
- const labels = Labels.CommonPage;
57
-
58
- // Update
59
- const update = onUpdateAll
60
- ? onUpdateAll
61
- : onUpdate
62
- ? (authorized?: boolean) => {
63
- if (authorized == null || authorized) onUpdate();
64
- }
65
- : onRefresh
66
- ? (authorized?: boolean) => {
67
- if (authorized) onRefresh();
68
- }
69
- : undefined;
70
-
71
- // Return the UI
72
- return (
73
- <React.Fragment>
74
- {update && (
75
- <ReactAppStateDetector
76
- targetFields={targetFields}
77
- update={update}
78
- />
79
- )}
80
- <Container
81
- disableGutters={disableGutters}
82
- maxWidth={maxWidth}
83
- sx={sx}
84
- id="page-container"
85
- {...rest}
86
- >
87
- <FabBox
88
- sx={{
89
- zIndex: 1,
90
- bottom: (theme) =>
91
- MUGlobal.updateWithTheme(fabPadding, theme.spacing),
92
- right: (theme) =>
93
- MUGlobal.updateWithTheme(fabPadding, theme.spacing)
94
- }}
95
- columnDirection={fabColumnDirection}
96
- >
97
- {scrollContainer && (
98
- <ScrollTopFab
99
- size={fabSize}
100
- target={scrollContainer}
101
- title={labels.scrollTop}
102
- />
103
- )}
104
- {fabButtons}
105
- {onRefresh != null && (
106
- <Fab
107
- title={labels.refresh}
108
- size={fabSize}
109
- onClick={onRefresh}
110
- sx={{ display: { xs: 'none', md: 'inherit' } }}
111
- >
112
- <RefreshIcon />
113
- </Fab>
114
- )}
115
- <MoreFab
116
- size={fabSize}
117
- title={labels.more}
118
- actions={moreActions}
119
- />
120
- {supportBack && (
121
- <BackButton title={labels.back} size={fabSize} />
122
- )}
123
- </FabBox>
124
- {children}
125
- </Container>
126
- </React.Fragment>
127
- );
128
- }
@@ -1,71 +0,0 @@
1
- import { UserKey } from '@etsoo/appscript';
2
- import { ContainerProps } from '@mui/material';
3
- import { ListItemReact } from '../../components/ListItemReact';
4
- import { IStateUpdate } from '../../states/IState';
5
- import { CustomFabSize } from '../CustomFabProps';
6
-
7
- /**
8
- * Common page props
9
- * Default container id is 'pageContainer'
10
- */
11
- export interface CommonPageProps extends Omit<ContainerProps, 'id'> {
12
- /**
13
- * Fab buttons
14
- */
15
- fabButtons?: React.ReactNode;
16
-
17
- /**
18
- * Fab size
19
- */
20
- fabSize?: CustomFabSize;
21
-
22
- /**
23
- * Fab flex column direction, undefined to hide it
24
- */
25
- fabColumnDirection?: boolean;
26
-
27
- /**
28
- * Fab padding adjust
29
- */
30
- fabPaddingAdjust?: number;
31
-
32
- /**
33
- * More actions
34
- */
35
- moreActions?: ListItemReact[];
36
-
37
- /**
38
- * On refresh callback, only when authorized = true
39
- */
40
- onRefresh?: () => void | PromiseLike<void>;
41
-
42
- /**
43
- * On page update, when authorized = null or true case, may uses onRefresh
44
- */
45
- onUpdate?: () => void | PromiseLike<void>;
46
-
47
- /**
48
- * On page update, all cases with authorized
49
- */
50
- onUpdateAll?: IStateUpdate;
51
-
52
- /**
53
- * Paddings
54
- */
55
- paddings?: Record<string, string | number>;
56
-
57
- /**
58
- * Scroll container
59
- */
60
- scrollContainer?: HTMLElement | object;
61
-
62
- /**
63
- * Support back click
64
- */
65
- supportBack?: boolean;
66
-
67
- /**
68
- * State last changed fields
69
- */
70
- targetFields?: UserKey[];
71
- }
@@ -1,137 +0,0 @@
1
- import { DataTypes, IdDefaultType } from '@etsoo/shared';
2
- import { Box, Stack } from '@mui/material';
3
- import React from 'react';
4
- import { GridDataGet, GridLoadDataProps } from '../../components/GridLoader';
5
- import { ScrollerGridForwardRef } from '../../components/ScrollerGrid';
6
- import useCombinedRefs from '../../uses/useCombinedRefs';
7
- import { useDimensions } from '../../uses/useDimensions';
8
- import { DataGridEx, DataGridExProps } from '../DataGridEx';
9
- import { MUGlobal } from '../MUGlobal';
10
- import { SearchBar } from '../SearchBar';
11
- import { CommonPage } from './CommonPage';
12
- import { DataGridPageProps } from './DataGridPageProps';
13
-
14
- interface LocalStates {
15
- data?: FormData;
16
- element?: HTMLElement;
17
- height?: number;
18
- ref?: ScrollerGridForwardRef;
19
- }
20
-
21
- /**
22
- * DataGrid page
23
- * @param props Props
24
- * @returns Component
25
- */
26
- export function DataGridPage<
27
- T extends object,
28
- F extends DataTypes.BasicTemplate = DataTypes.BasicTemplate,
29
- D extends DataTypes.Keys<T> = IdDefaultType<T>
30
- >(props: DataGridPageProps<T, F, D>) {
31
- // Destruct
32
- const {
33
- adjustHeight,
34
- fields,
35
- fieldTemplate,
36
- height,
37
- loadData,
38
- mRef,
39
- sizeReadyMiliseconds = 100,
40
- pageProps = {},
41
- ...rest
42
- } = props;
43
-
44
- pageProps.paddings ??= MUGlobal.pagePaddings;
45
-
46
- // States
47
- const [states, setStates] = React.useReducer(
48
- (currentState: LocalStates, newState: Partial<LocalStates>) => {
49
- return { ...currentState, ...newState };
50
- },
51
- {
52
- height
53
- }
54
- );
55
-
56
- const refs = useCombinedRefs<ScrollerGridForwardRef>(
57
- mRef,
58
- (ref: ScrollerGridForwardRef | null) => {
59
- if (ref == null) return;
60
- states.ref = ref;
61
- //setStates({ ref });
62
- }
63
- );
64
-
65
- // On submit callback
66
- const onSubmit = (data: FormData, _reset: boolean) => {
67
- setStates({ data });
68
- };
69
-
70
- const localLoadData = (props: GridLoadDataProps) => {
71
- const data = GridDataGet(props, fieldTemplate);
72
- return loadData(data);
73
- };
74
-
75
- // Watch container
76
- const { dimensions } = useDimensions(1, undefined, sizeReadyMiliseconds);
77
- const rect = dimensions[0][2];
78
-
79
- React.useEffect(() => {
80
- if (rect != null && rect.height > 50 && height == null) {
81
- let gridHeight =
82
- document.documentElement.clientHeight -
83
- Math.round(rect.top + rect.height + 1);
84
-
85
- const style = window.getComputedStyle(dimensions[0][1]!);
86
- const paddingBottom = parseFloat(style.paddingBottom);
87
- if (!isNaN(paddingBottom)) gridHeight -= paddingBottom;
88
-
89
- if (adjustHeight != null) {
90
- gridHeight -= adjustHeight(gridHeight);
91
- }
92
-
93
- if (gridHeight !== states.height) setStates({ height: gridHeight });
94
- }
95
- }, [rect]);
96
-
97
- const list = React.useMemo(() => {
98
- const gridHeight = states.height;
99
- if (gridHeight == null) return;
100
-
101
- return (
102
- <DataGridEx<T, D>
103
- autoLoad={false}
104
- height={gridHeight}
105
- loadData={localLoadData}
106
- mRef={refs}
107
- outerRef={(element?: HTMLDivElement) => {
108
- if (element != null) setStates({ element });
109
- }}
110
- {...rest}
111
- />
112
- );
113
- }, [states.height]);
114
-
115
- const { ref, data } = states;
116
- React.useEffect(() => {
117
- if (ref == null || data == null) return;
118
- ref.reset({ data });
119
- }, [ref, data]);
120
-
121
- // Layout
122
- return (
123
- <CommonPage {...pageProps} scrollContainer={states.element}>
124
- <Stack>
125
- <Box
126
- ref={dimensions[0][0]}
127
- sx={{
128
- paddingBottom: pageProps.paddings
129
- }}
130
- >
131
- <SearchBar fields={fields} onSubmit={onSubmit} />
132
- </Box>
133
- {list}
134
- </Stack>
135
- </CommonPage>
136
- );
137
- }
@@ -1,24 +0,0 @@
1
- import { DataTypes, IdDefaultType } from '@etsoo/shared';
2
- import { DataGridExProps } from '../DataGridEx';
3
- import { SearchPageProps } from './SearchPageProps';
4
-
5
- /**
6
- * DataGrid page props
7
- */
8
- export type DataGridPageProps<
9
- T extends object,
10
- F extends DataTypes.BasicTemplate,
11
- D extends DataTypes.Keys<T> = IdDefaultType<T>
12
- > = SearchPageProps<T, F> &
13
- Omit<DataGridExProps<T, D>, 'loadData' | 'height'> & {
14
- /**
15
- * Height will be deducted
16
- * @param height Current calcuated height
17
- */
18
- adjustHeight?: (height: number) => number;
19
-
20
- /**
21
- * Grid height
22
- */
23
- height?: number;
24
- };