@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
@@ -7,8 +7,8 @@ import {
7
7
  VariableSizeGrid,
8
8
  VariableSizeGridProps
9
9
  } from 'react-window';
10
- import { GridMethodRef } from '../mu/GridMethodRef';
11
10
  import { GridLoadDataProps, GridLoader, GridLoaderStates } from './GridLoader';
11
+ import { GridMethodRef } from './GridMethodRef';
12
12
 
13
13
  export type ScrollerGridItemRendererProps<T> = Omit<
14
14
  GridChildComponentProps<T>,
@@ -70,7 +70,7 @@ export type ScrollerGridProps<
70
70
  /**
71
71
  * Methods
72
72
  */
73
- mRef?: React.Ref<ScrollerGridForwardRef>;
73
+ mRef?: React.Ref<ScrollerGridForwardRef<T>>;
74
74
 
75
75
  /**
76
76
  * On items select change
@@ -86,7 +86,7 @@ export type ScrollerGridProps<
86
86
  /**
87
87
  * Scroller grid forward ref
88
88
  */
89
- export interface ScrollerGridForwardRef extends GridMethodRef {
89
+ export interface ScrollerGridForwardRef<T> extends GridMethodRef<T> {
90
90
  /**
91
91
  * Scroll to the specified offsets
92
92
  */
@@ -8,7 +8,6 @@ import {
8
8
  ListProps,
9
9
  VariableSizeList
10
10
  } from 'react-window';
11
- import { GridMethodRef } from '../mu/GridMethodRef';
12
11
  import useCombinedRefs from '../uses/useCombinedRefs';
13
12
  import {
14
13
  GridLoadDataProps,
@@ -16,6 +15,7 @@ import {
16
15
  GridLoaderStates,
17
16
  GridSizeGet
18
17
  } from './GridLoader';
18
+ import { GridMethodRef } from './GridMethodRef';
19
19
 
20
20
  /**
21
21
  * Scroller vertical list props
@@ -34,7 +34,7 @@ export interface ScrollerListProps<T extends object>
34
34
  /**
35
35
  * Methods ref
36
36
  */
37
- mRef?: React.Ref<ScrollerListForwardRef>;
37
+ mRef?: React.Ref<ScrollerListForwardRef<T>>;
38
38
 
39
39
  /**
40
40
  * Outer div ref
@@ -77,7 +77,9 @@ interface ScrollerListRef {
77
77
  /**
78
78
  * Scroller list forward ref
79
79
  */
80
- export interface ScrollerListForwardRef extends GridMethodRef, ScrollerListRef {
80
+ export interface ScrollerListForwardRef<T>
81
+ extends GridMethodRef<T>,
82
+ ScrollerListRef {
81
83
  /**
82
84
  * Refresh latest page data
83
85
  */
package/src/index.ts CHANGED
@@ -1,94 +1,17 @@
1
1
  // app
2
- export * from './app/CommonApp';
3
2
  export * from './app/CoreConstants';
4
3
  export * from './app/InputDialogProps';
5
- export * from './app/IServiceAppSettings';
6
- export * from './app/IServicePage';
7
- export * from './app/IServiceUser';
8
- export * from './app/ISmartERPUser';
9
- export * from './app/Labels';
10
- export * from './app/ReactApp';
11
4
  export * from './app/ReactUtils';
12
5
  export * from './app/RefreshTokenRQ';
13
- export * from './app/ServiceApp';
14
6
 
15
7
  // components
8
+ export * from './components/DnDList';
16
9
  export * from './components/GridColumn';
17
10
  export * from './components/GridLoader';
18
11
  export * from './components/HRouter';
19
12
  export * from './components/ListItemReact';
20
13
  export * from './components/ScrollerGrid';
21
14
  export * from './components/ScrollerList';
22
- export * from './components/ShowDataComparison';
23
-
24
- // mu
25
- export * from './mu/pages/CommonPage';
26
- export * from './mu/pages/CommonPageProps';
27
- export * from './mu/pages/DataGridPage';
28
- export * from './mu/pages/DataGridPageProps';
29
- export * from './mu/pages/EditPage';
30
- export * from './mu/pages/FixedListPage';
31
- export * from './mu/pages/ListPage';
32
- export * from './mu/pages/ListPageProps';
33
- export * from './mu/pages/ResponsivePage';
34
- export * from './mu/pages/ResponsivePageProps';
35
- export * from './mu/pages/SearchPageProps';
36
- export * from './mu/pages/TablePage';
37
- export * from './mu/pages/ViewPage';
38
-
39
- export * from './mu/texts/DateText';
40
- export * from './mu/texts/MoneyText';
41
- export * from './mu/texts/NumberText';
42
-
43
- export * from './mu/AuditDisplay';
44
- export * from './mu/BackButton';
45
- export * from './mu/BridgeCloseButton';
46
- export * from './mu/ButtonLink';
47
- export * from './mu/ComboBox';
48
- export * from './mu/CountdownButton';
49
- export * from './mu/CustomFabProps';
50
- export * from './mu/DataGridEx';
51
- export * from './mu/DataGridRenderers';
52
- export * from './mu/DialogButton';
53
- export * from './mu/DnDList';
54
- export * from './mu/DraggablePaperComponent';
55
- export * from './mu/EmailInput';
56
- export * from './mu/FabBox';
57
- export * from './mu/FlexBox';
58
- export * from './mu/GridDataFormat';
59
- export * from './mu/IconButtonLink';
60
- export * from './mu/InputField';
61
- export * from './mu/ItemList';
62
- export * from './mu/ListItemRightIcon';
63
- export * from './mu/ListMoreDisplay';
64
- export * from './mu/LoadingButton';
65
- export * from './mu/MaskInput';
66
- export * from './mu/MobileListItemRenderer';
67
- export * from './mu/MoreFab';
68
- export * from './mu/MUGlobal';
69
- export * from './mu/NotifierMU';
70
- export * from './mu/OptionGroup';
71
- export * from './mu/PList';
72
- export * from './mu/ProgressCount';
73
- export * from './mu/PullToRefreshUI';
74
- export * from './mu/ResponsibleContainer';
75
- export * from './mu/RLink';
76
- export * from './mu/ScrollerListEx';
77
- export * from './mu/ScrollTopFab';
78
- export * from './mu/SearchBar';
79
- export * from './mu/SearchField';
80
- export * from './mu/SearchOptionGroup';
81
- export * from './mu/SelectBool';
82
- export * from './mu/SelectEx';
83
- export * from './mu/Switch';
84
- export * from './mu/SwitchAnt';
85
- export * from './mu/TabBox';
86
- export * from './mu/TableEx';
87
- export * from './mu/TextFieldEx';
88
- export * from './mu/Tiplist';
89
- export * from './mu/TooltipClick';
90
- export * from './mu/UserAvatar';
91
- export * from './mu/UserAvatarEditor';
92
15
 
93
16
  // notifier
94
17
  export * from './notifier/Notifier';
@@ -107,4 +30,5 @@ export * from './uses/useDelayedExecutor';
107
30
  export * from './uses/useDimensions';
108
31
  export * from './uses/useParamsEx';
109
32
  export * from './uses/useTimeout';
33
+ export * from './uses/useWindowScroll';
110
34
  export * from './uses/useWindowSize';
@@ -13,7 +13,6 @@ import {
13
13
  import { IAction } from '@etsoo/appscript';
14
14
  import { State } from '../states/State';
15
15
  import { IProviderProps, IUpdate } from '../states/IState';
16
- import { Breakpoint, ButtonProps } from '@mui/material';
17
16
 
18
17
  /**
19
18
  * React notification call props
@@ -37,7 +36,7 @@ export interface NotificationReactCallProps extends NotificationCallProps {
37
36
  /**
38
37
  * Max width
39
38
  */
40
- maxWidth?: Breakpoint | false;
39
+ maxWidth?: 'xs' | 'sm' | 'md' | 'lg' | 'xl' | false;
41
40
 
42
41
  /**
43
42
  * OK label
@@ -62,7 +61,7 @@ export interface NotificationReactCallProps extends NotificationCallProps {
62
61
  /**
63
62
  * Primary button props
64
63
  */
65
- primaryButton?: ButtonProps;
64
+ primaryButton?: {};
66
65
  }
67
66
 
68
67
  /**
@@ -0,0 +1,60 @@
1
+ import React from 'react';
2
+
3
+ interface IScrollPos {
4
+ x: number;
5
+ y: number;
6
+ }
7
+
8
+ /**
9
+ * Detect window scroll
10
+ * @returns Scroll location
11
+ */
12
+ export const useWindowScroll = () => {
13
+ // State
14
+ const [pos, setPos] = React.useState<IScrollPos>({
15
+ x: window.pageXOffset,
16
+ y: window.pageYOffset
17
+ });
18
+
19
+ React.useEffect(() => {
20
+ let ticking = false;
21
+ let lastPos: IScrollPos;
22
+ let requestAnimationFrameSeed = 0;
23
+
24
+ const scrollHandler = () => {
25
+ lastPos = {
26
+ x: window.pageXOffset,
27
+ y: window.pageYOffset
28
+ };
29
+
30
+ if (!ticking) {
31
+ requestAnimationFrameSeed = window.requestAnimationFrame(() => {
32
+ ticking = false;
33
+ requestAnimationFrameSeed = 0;
34
+
35
+ if (lastPos.x != lastPos.x || lastPos.y != lastPos.y) {
36
+ setPos(lastPos);
37
+ }
38
+ });
39
+ ticking = true;
40
+ }
41
+ };
42
+
43
+ window.addEventListener('scroll', scrollHandler, {
44
+ passive: true,
45
+ capture: false
46
+ });
47
+
48
+ return () => {
49
+ // Cancel animation frame
50
+ if (requestAnimationFrameSeed > 0)
51
+ window.cancelAnimationFrame(requestAnimationFrameSeed);
52
+
53
+ // Remove scroll event
54
+ window.removeEventListener('scroll', scrollHandler);
55
+ };
56
+ }, []);
57
+
58
+ // Return
59
+ return pos;
60
+ };
@@ -18,33 +18,42 @@ export const useWindowSize = () => {
18
18
 
19
19
  React.useEffect(() => {
20
20
  let ticking = false;
21
- let lastKnownSize: ISize;
21
+ let lastSize: ISize;
22
22
  let requestAnimationFrameSeed = 0;
23
23
 
24
24
  const resizeHandler = () => {
25
- lastKnownSize = {
25
+ lastSize = {
26
26
  width: document.documentElement.clientWidth,
27
27
  height: document.documentElement.clientHeight
28
28
  };
29
29
 
30
30
  if (!ticking) {
31
31
  requestAnimationFrameSeed = window.requestAnimationFrame(() => {
32
- setSize(lastKnownSize);
33
32
  ticking = false;
34
33
  requestAnimationFrameSeed = 0;
34
+
35
+ if (
36
+ lastSize.width != size.width ||
37
+ lastSize.height != size.height
38
+ ) {
39
+ setSize(lastSize);
40
+ }
35
41
  });
36
42
  ticking = true;
37
43
  }
38
44
  };
39
45
 
40
- window.addEventListener('resize', resizeHandler);
46
+ window.addEventListener('resize', resizeHandler, {
47
+ passive: true,
48
+ capture: false
49
+ });
41
50
 
42
51
  return () => {
43
52
  // Cancel animation frame
44
53
  if (requestAnimationFrameSeed > 0)
45
54
  window.cancelAnimationFrame(requestAnimationFrameSeed);
46
55
 
47
- // Remove scroll event
56
+ // Remove resize event
48
57
  window.removeEventListener('resize', resizeHandler);
49
58
  };
50
59
  }, []);
@@ -1,58 +0,0 @@
1
- import { MUGlobal } from '../../src/mu/MUGlobal';
2
-
3
- // Theme update function
4
- const updateFunc = (value: number) => `${value * 8}px`;
5
-
6
- // Arrange
7
- const paddings = { sx: 2, sm: 3, key: 'a' };
8
-
9
- test('getMenuItem tests', () => {
10
- // Assert
11
- expect(
12
- MUGlobal.getMenuItem('/user/add', '/user/all').selected
13
- ).toBeTruthy();
14
- expect(MUGlobal.getMenuItem('/user/add', '/user/*').selected).toBeTruthy();
15
- expect(
16
- MUGlobal.getMenuItem('/user/add', '/user/edit').selected
17
- ).toBeFalsy();
18
- });
19
-
20
- test('half tests', () => {
21
- // Act
22
- const result = MUGlobal.half(paddings);
23
-
24
- // Assert
25
- expect(paddings).toHaveProperty('sx', 2);
26
- expect(result).toHaveProperty('sx', 1);
27
- expect(result).toHaveProperty('sm', 1.5);
28
- });
29
-
30
- test('increase tests', () => {
31
- // Act
32
- const result = MUGlobal.increase(paddings, 2);
33
-
34
- // Assert
35
- expect(paddings).toHaveProperty('sx', 2);
36
- expect(result).toHaveProperty('sx', 4);
37
- expect(result).toHaveProperty('sm', 5);
38
- });
39
-
40
- test('adjustWithTheme tests', () => {
41
- // Act
42
- const result = MUGlobal.adjustWithTheme(160, paddings, updateFunc);
43
-
44
- // Assert
45
- expect(paddings).toHaveProperty('sx', 2);
46
- expect(result).toHaveProperty('sx', '144px');
47
- expect(result).toHaveProperty('sm', '136px');
48
- });
49
-
50
- test('updateWithTheme tests', () => {
51
- // Act
52
- const result = MUGlobal.updateWithTheme(paddings, updateFunc);
53
-
54
- // Assert
55
- expect(paddings).toHaveProperty('sx', 2);
56
- expect(result).toHaveProperty('sx', '16px');
57
- expect(result).toHaveProperty('sm', '24px');
58
- });
@@ -1,213 +0,0 @@
1
- import React from 'react';
2
- import { createRoot } from 'react-dom/client';
3
- import { act } from 'react-dom/test-utils';
4
- import { INotification, NotificationMessageType, NotifierMU } from '../../src';
5
-
6
- // Without it will popup error:
7
- // The current testing environment is not configured to support act
8
- (globalThis as any).IS_REACT_ACT_ENVIRONMENT = true;
9
-
10
- // Root
11
- const root = document.body;
12
- const container: HTMLElement = document.createElement('div');
13
- root.append(container);
14
-
15
- // The state provider
16
- const Provider = NotifierMU.setup();
17
- const reactRoot = createRoot(container); // createRoot(container!) if you use TypeScript
18
-
19
- act(() => {
20
- // Concorrent renderer needs act block
21
- reactRoot.render(<Provider />);
22
- });
23
-
24
- // Notifier
25
- const notifier = NotifierMU.instance;
26
-
27
- // Timer mock
28
- // https://jestjs.io/docs/en/timer-mocks
29
- jest.useFakeTimers();
30
-
31
- test('Alert tests', async () => {
32
- // Click
33
- const handleClick = jest.fn();
34
-
35
- act(() => {
36
- // Add the notification
37
- notifier.alert('Alert message', handleClick);
38
- });
39
-
40
- // Button
41
- const button = root.getElementsByTagName('button');
42
-
43
- expect(button.length).toBe(1);
44
- expect(button[0].innerHTML).toContain('OK');
45
-
46
- await act(async () => {
47
- button[0].click();
48
- });
49
-
50
- expect(handleClick).toBeCalled();
51
-
52
- // Fast forward
53
- jest.runOnlyPendingTimers();
54
- });
55
-
56
- test('Confirm tests', async () => {
57
- // Click
58
- const handleClick = jest.fn();
59
-
60
- act(() => {
61
- // Add the notification
62
- notifier.confirm('Confirm message', undefined, handleClick);
63
- });
64
-
65
- // Button
66
- const button = root.getElementsByTagName('button');
67
-
68
- expect(button.length).toBe(2);
69
- expect(button[0].innerHTML).toContain('Cancel');
70
-
71
- await act(async () => {
72
- button[0].click();
73
- });
74
-
75
- expect(handleClick).toBeCalled();
76
-
77
- // Fast forward
78
- jest.runOnlyPendingTimers();
79
- });
80
-
81
- test('Confirm tests without cancel button', async () => {
82
- // Click
83
- const handleClick = jest.fn();
84
-
85
- act(() => {
86
- // Add the notification
87
- notifier.confirm('Confirm message', undefined, handleClick, {
88
- cancelButton: false
89
- });
90
- });
91
-
92
- // Button
93
- const button = root.getElementsByTagName('button');
94
-
95
- expect(button.length).toBe(1);
96
- expect(button[0].innerHTML).toContain('OK');
97
-
98
- await act(async () => {
99
- button[0].click();
100
- });
101
-
102
- expect(handleClick).toBeCalled();
103
-
104
- // Fast forward
105
- jest.runOnlyPendingTimers();
106
- });
107
-
108
- test('Prompt tests', async () => {
109
- // Click
110
- const handleClick = jest.fn((result: boolean) => {
111
- expect(result).toBeTruthy();
112
- });
113
-
114
- act(() => {
115
- // Add the notification
116
- notifier.prompt<boolean>('Prompt message', handleClick, undefined, {
117
- type: 'switch',
118
- required: false
119
- });
120
- });
121
-
122
- // Button
123
- const button = root.getElementsByTagName('button');
124
-
125
- expect(button.length).toBe(2); // Switch will generate a button
126
- expect(button[1].innerHTML).toContain('OK');
127
-
128
- await act(async () => {
129
- button[1].click();
130
- });
131
-
132
- expect(handleClick).toBeCalled();
133
-
134
- jest.runOnlyPendingTimers();
135
- });
136
-
137
- test('Prompt tests with form submit', async () => {
138
- // Click
139
- const handleClick = jest.fn((result: boolean) => {
140
- expect(result).toBeTruthy();
141
- });
142
-
143
- act(() => {
144
- // Add the notification
145
- notifier.prompt<boolean>('Prompt message', handleClick, undefined, {
146
- type: 'switch',
147
- required: false
148
- });
149
- });
150
-
151
- await act(async () => {
152
- (
153
- root
154
- .getElementsByTagName('form')[0]
155
- .elements.namedItem('okButton') as HTMLButtonElement
156
- )?.click();
157
- });
158
-
159
- expect(handleClick).toBeCalled();
160
-
161
- jest.runOnlyPendingTimers();
162
- });
163
-
164
- test('Message tests', (done) => {
165
- // Callback
166
- const callback = jest.fn(() => done());
167
-
168
- let n: INotification<React.ReactNode, any> | undefined;
169
- act(() => {
170
- // Add the notification
171
- n = notifier.message(
172
- NotificationMessageType.Danger,
173
- 'Error Message',
174
- undefined,
175
- {
176
- callback
177
- }
178
- );
179
- });
180
-
181
- expect(n?.timespan).toBe(5);
182
-
183
- expect(root.innerHTML).toContain('Error Message');
184
-
185
- act(() => {
186
- // Here is the bug need further study...
187
- n?.dismiss();
188
-
189
- // Fast forward
190
- jest.runOnlyPendingTimers();
191
- });
192
-
193
- expect(root.innerHTML).not.toContain('Error Message');
194
- expect(callback).toBeCalled();
195
- });
196
-
197
- test('Loading tests', () => {
198
- act(() => {
199
- // Add the notification
200
- notifier.showLoading('Loading');
201
- });
202
-
203
- expect(root.innerHTML).toContain('Loading');
204
-
205
- act(() => {
206
- notifier.hideLoading();
207
-
208
- // Fast forward
209
- jest.runOnlyPendingTimers();
210
- });
211
-
212
- expect(root.innerHTML).not.toContain('Loading');
213
- });
@@ -1,39 +0,0 @@
1
- import { IAppSettings, IUser, RefreshTokenProps } from '@etsoo/appscript';
2
- import { IPageData } from '../states/PageState';
3
- import { ReactApp } from './ReactApp';
4
- import { RefreshTokenRQ } from './RefreshTokenRQ';
5
- /**
6
- * Common independent application
7
- * 通用独立程序
8
- */
9
- export declare abstract class CommonApp<U extends IUser = IUser, P extends IPageData = IPageData, S extends IAppSettings = IAppSettings> extends ReactApp<S, U, P> {
10
- /**
11
- * Override persistedFields
12
- */
13
- protected get persistedFields(): string[];
14
- /**
15
- * Init call update fields in local storage
16
- * @returns Fields
17
- */
18
- protected initCallEncryptedUpdateFields(): string[];
19
- /**
20
- * Do user login
21
- * @param data User data
22
- * @param refreshToken Refresh token
23
- * @param keep Keep login
24
- * @returns Success data
25
- */
26
- protected doUserLogin(data: U, refreshToken: string, keep: boolean): string | undefined;
27
- /**
28
- * Refresh token
29
- * @param props Props
30
- */
31
- refreshToken<D extends object = RefreshTokenRQ>(props?: RefreshTokenProps<D>): Promise<boolean>;
32
- /**
33
- * Try login
34
- * @param data Additional data
35
- * @param showLoading Show loading bar or not
36
- * @returns Result
37
- */
38
- tryLogin<D extends object = RefreshTokenRQ>(data?: D, showLoading?: boolean): Promise<boolean>;
39
- }