@etsoo/react 1.5.80 → 1.5.83

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 (259) 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/states/UserState.d.ts +1 -1
  13. package/lib/uses/useWindowScroll.d.ts +10 -0
  14. package/lib/uses/useWindowScroll.js +46 -0
  15. package/lib/uses/useWindowSize.js +11 -5
  16. package/package.json +4 -16
  17. package/src/{mu → components}/DnDList.tsx +11 -34
  18. package/src/components/GridMethodRef.ts +12 -0
  19. package/src/components/ScrollerGrid.tsx +3 -3
  20. package/src/components/ScrollerList.tsx +5 -3
  21. package/src/index.ts +2 -78
  22. package/src/notifier/Notifier.ts +2 -3
  23. package/src/states/UserState.ts +7 -2
  24. package/src/uses/useWindowScroll.ts +60 -0
  25. package/src/uses/useWindowSize.ts +14 -5
  26. package/__tests__/mu/ComboBox.tsx +0 -30
  27. package/__tests__/mu/MUGlobalTests.tsx +0 -58
  28. package/__tests__/mu/NotifierMUTests.tsx +0 -213
  29. package/__tests__/mu/SelectEx.tsx +0 -26
  30. package/lib/app/CommonApp.d.ts +0 -39
  31. package/lib/app/CommonApp.js +0 -149
  32. package/lib/app/IServiceAppSettings.d.ts +0 -11
  33. package/lib/app/IServiceAppSettings.js +0 -1
  34. package/lib/app/IServicePage.d.ts +0 -6
  35. package/lib/app/IServicePage.js +0 -1
  36. package/lib/app/IServiceUser.d.ts +0 -14
  37. package/lib/app/IServiceUser.js +0 -1
  38. package/lib/app/ISmartERPUser.d.ts +0 -14
  39. package/lib/app/ISmartERPUser.js +0 -1
  40. package/lib/app/Labels.d.ts +0 -65
  41. package/lib/app/Labels.js +0 -62
  42. package/lib/app/ReactApp.d.ts +0 -194
  43. package/lib/app/ReactApp.js +0 -298
  44. package/lib/app/ServiceApp.d.ts +0 -78
  45. package/lib/app/ServiceApp.js +0 -244
  46. package/lib/components/ShowDataComparison.d.ts +0 -20
  47. package/lib/components/ShowDataComparison.js +0 -60
  48. package/lib/mu/AuditDisplay.d.ts +0 -33
  49. package/lib/mu/AuditDisplay.js +0 -52
  50. package/lib/mu/AutocompleteExtendedProps.d.ts +0 -64
  51. package/lib/mu/AutocompleteExtendedProps.js +0 -1
  52. package/lib/mu/BackButton.d.ts +0 -13
  53. package/lib/mu/BackButton.js +0 -33
  54. package/lib/mu/BridgeCloseButton.d.ts +0 -23
  55. package/lib/mu/BridgeCloseButton.js +0 -32
  56. package/lib/mu/ButtonLink.d.ts +0 -17
  57. package/lib/mu/ButtonLink.js +0 -19
  58. package/lib/mu/ComboBox.d.ts +0 -38
  59. package/lib/mu/ComboBox.js +0 -108
  60. package/lib/mu/CountdownButton.d.ts +0 -23
  61. package/lib/mu/CountdownButton.js +0 -81
  62. package/lib/mu/CustomFabProps.d.ts +0 -27
  63. package/lib/mu/CustomFabProps.js +0 -1
  64. package/lib/mu/DataGridEx.d.ts +0 -96
  65. package/lib/mu/DataGridEx.js +0 -331
  66. package/lib/mu/DataGridRenderers.d.ts +0 -22
  67. package/lib/mu/DataGridRenderers.js +0 -99
  68. package/lib/mu/DialogButton.d.ts +0 -54
  69. package/lib/mu/DialogButton.js +0 -45
  70. package/lib/mu/DraggablePaperComponent.d.ts +0 -8
  71. package/lib/mu/DraggablePaperComponent.js +0 -12
  72. package/lib/mu/EmailInput.d.ts +0 -11
  73. package/lib/mu/EmailInput.js +0 -15
  74. package/lib/mu/FabBox.d.ts +0 -21
  75. package/lib/mu/FabBox.js +0 -31
  76. package/lib/mu/FlexBox.d.ts +0 -14
  77. package/lib/mu/FlexBox.js +0 -18
  78. package/lib/mu/GridDataFormat.d.ts +0 -10
  79. package/lib/mu/GridDataFormat.js +0 -43
  80. package/lib/mu/GridMethodRef.d.ts +0 -11
  81. package/lib/mu/IconButtonLink.d.ts +0 -17
  82. package/lib/mu/IconButtonLink.js +0 -16
  83. package/lib/mu/InputField.d.ts +0 -21
  84. package/lib/mu/InputField.js +0 -39
  85. package/lib/mu/ItemList.d.ts +0 -56
  86. package/lib/mu/ItemList.js +0 -69
  87. package/lib/mu/ListItemRightIcon.d.ts +0 -4
  88. package/lib/mu/ListItemRightIcon.js +0 -8
  89. package/lib/mu/ListMoreDisplay.d.ts +0 -35
  90. package/lib/mu/ListMoreDisplay.js +0 -99
  91. package/lib/mu/LoadingButton.d.ts +0 -16
  92. package/lib/mu/LoadingButton.js +0 -41
  93. package/lib/mu/MUGlobal.d.ts +0 -102
  94. package/lib/mu/MUGlobal.js +0 -184
  95. package/lib/mu/MaskInput.d.ts +0 -34
  96. package/lib/mu/MaskInput.js +0 -43
  97. package/lib/mu/MobileListItemRenderer.d.ts +0 -17
  98. package/lib/mu/MobileListItemRenderer.js +0 -35
  99. package/lib/mu/MoreFab.d.ts +0 -45
  100. package/lib/mu/MoreFab.js +0 -95
  101. package/lib/mu/NotifierMU.d.ts +0 -47
  102. package/lib/mu/NotifierMU.js +0 -387
  103. package/lib/mu/NotifierPromptProps.d.ts +0 -22
  104. package/lib/mu/NotifierPromptProps.js +0 -1
  105. package/lib/mu/OptionGroup.d.ts +0 -58
  106. package/lib/mu/OptionGroup.js +0 -81
  107. package/lib/mu/PList.d.ts +0 -15
  108. package/lib/mu/PList.js +0 -12
  109. package/lib/mu/ProgressCount.d.ts +0 -44
  110. package/lib/mu/ProgressCount.js +0 -79
  111. package/lib/mu/PullToRefreshUI.d.ts +0 -9
  112. package/lib/mu/PullToRefreshUI.js +0 -18
  113. package/lib/mu/RLink.d.ts +0 -14
  114. package/lib/mu/RLink.js +0 -37
  115. package/lib/mu/ResponsibleContainer.d.ts +0 -89
  116. package/lib/mu/ResponsibleContainer.js +0 -159
  117. package/lib/mu/ScrollTopFab.d.ts +0 -7
  118. package/lib/mu/ScrollTopFab.js +0 -25
  119. package/lib/mu/ScrollerListEx.d.ts +0 -81
  120. package/lib/mu/ScrollerListEx.js +0 -167
  121. package/lib/mu/SearchBar.d.ts +0 -29
  122. package/lib/mu/SearchBar.js +0 -262
  123. package/lib/mu/SearchField.d.ts +0 -21
  124. package/lib/mu/SearchField.js +0 -39
  125. package/lib/mu/SearchOptionGroup.d.ts +0 -9
  126. package/lib/mu/SearchOptionGroup.js +0 -14
  127. package/lib/mu/SelectBool.d.ts +0 -13
  128. package/lib/mu/SelectBool.js +0 -22
  129. package/lib/mu/SelectEx.d.ts +0 -50
  130. package/lib/mu/SelectEx.js +0 -156
  131. package/lib/mu/Switch.d.ts +0 -29
  132. package/lib/mu/Switch.js +0 -34
  133. package/lib/mu/SwitchAnt.d.ts +0 -25
  134. package/lib/mu/SwitchAnt.js +0 -40
  135. package/lib/mu/TabBox.d.ts +0 -54
  136. package/lib/mu/TabBox.js +0 -31
  137. package/lib/mu/TableEx.d.ts +0 -66
  138. package/lib/mu/TableEx.js +0 -271
  139. package/lib/mu/TextFieldEx.d.ts +0 -101
  140. package/lib/mu/TextFieldEx.js +0 -127
  141. package/lib/mu/Tiplist.d.ts +0 -18
  142. package/lib/mu/Tiplist.js +0 -158
  143. package/lib/mu/TooltipClick.d.ts +0 -15
  144. package/lib/mu/TooltipClick.js +0 -40
  145. package/lib/mu/UserAvatar.d.ts +0 -24
  146. package/lib/mu/UserAvatar.js +0 -25
  147. package/lib/mu/UserAvatarEditor.d.ts +0 -53
  148. package/lib/mu/UserAvatarEditor.js +0 -129
  149. package/lib/mu/pages/CommonPage.d.ts +0 -11
  150. package/lib/mu/pages/CommonPage.js +0 -60
  151. package/lib/mu/pages/CommonPageProps.d.ts +0 -60
  152. package/lib/mu/pages/CommonPageProps.js +0 -1
  153. package/lib/mu/pages/DataGridPage.d.ts +0 -9
  154. package/lib/mu/pages/DataGridPage.js +0 -81
  155. package/lib/mu/pages/DataGridPageProps.d.ts +0 -17
  156. package/lib/mu/pages/DataGridPageProps.js +0 -1
  157. package/lib/mu/pages/EditPage.d.ts +0 -33
  158. package/lib/mu/pages/EditPage.js +0 -29
  159. package/lib/mu/pages/FixedListPage.d.ts +0 -15
  160. package/lib/mu/pages/FixedListPage.js +0 -72
  161. package/lib/mu/pages/ListPage.d.ts +0 -9
  162. package/lib/mu/pages/ListPage.js +0 -51
  163. package/lib/mu/pages/ListPageProps.d.ts +0 -7
  164. package/lib/mu/pages/ListPageProps.js +0 -1
  165. package/lib/mu/pages/ResponsivePage.d.ts +0 -9
  166. package/lib/mu/pages/ResponsivePage.js +0 -45
  167. package/lib/mu/pages/ResponsivePageProps.d.ts +0 -39
  168. package/lib/mu/pages/ResponsivePageProps.js +0 -1
  169. package/lib/mu/pages/SearchPageProps.d.ts +0 -30
  170. package/lib/mu/pages/SearchPageProps.js +0 -1
  171. package/lib/mu/pages/TablePage.d.ts +0 -9
  172. package/lib/mu/pages/TablePage.js +0 -71
  173. package/lib/mu/pages/TablePageProps.d.ts +0 -7
  174. package/lib/mu/pages/TablePageProps.js +0 -1
  175. package/lib/mu/pages/ViewPage.d.ts +0 -66
  176. package/lib/mu/pages/ViewPage.js +0 -105
  177. package/lib/mu/texts/DateText.d.ts +0 -34
  178. package/lib/mu/texts/DateText.js +0 -25
  179. package/lib/mu/texts/MoneyText.d.ts +0 -21
  180. package/lib/mu/texts/MoneyText.js +0 -14
  181. package/lib/mu/texts/NumberText.d.ts +0 -25
  182. package/lib/mu/texts/NumberText.js +0 -14
  183. package/src/app/CommonApp.ts +0 -225
  184. package/src/app/IServiceAppSettings.ts +0 -13
  185. package/src/app/IServicePage.ts +0 -6
  186. package/src/app/IServiceUser.ts +0 -17
  187. package/src/app/ISmartERPUser.ts +0 -16
  188. package/src/app/Labels.ts +0 -77
  189. package/src/app/ReactApp.ts +0 -500
  190. package/src/app/ServiceApp.ts +0 -353
  191. package/src/components/ShowDataComparison.tsx +0 -108
  192. package/src/mu/AuditDisplay.tsx +0 -117
  193. package/src/mu/AutocompleteExtendedProps.ts +0 -83
  194. package/src/mu/BackButton.tsx +0 -55
  195. package/src/mu/BridgeCloseButton.tsx +0 -69
  196. package/src/mu/ButtonLink.tsx +0 -32
  197. package/src/mu/ComboBox.tsx +0 -251
  198. package/src/mu/CountdownButton.tsx +0 -119
  199. package/src/mu/CustomFabProps.ts +0 -32
  200. package/src/mu/DataGridEx.tsx +0 -712
  201. package/src/mu/DataGridRenderers.tsx +0 -140
  202. package/src/mu/DialogButton.tsx +0 -163
  203. package/src/mu/DraggablePaperComponent.tsx +0 -19
  204. package/src/mu/EmailInput.tsx +0 -24
  205. package/src/mu/FabBox.tsx +0 -51
  206. package/src/mu/FlexBox.tsx +0 -20
  207. package/src/mu/GridDataFormat.tsx +0 -77
  208. package/src/mu/GridMethodRef.ts +0 -12
  209. package/src/mu/IconButtonLink.tsx +0 -29
  210. package/src/mu/InputField.tsx +0 -82
  211. package/src/mu/ItemList.tsx +0 -204
  212. package/src/mu/ListItemRightIcon.tsx +0 -9
  213. package/src/mu/ListMoreDisplay.tsx +0 -205
  214. package/src/mu/LoadingButton.tsx +0 -75
  215. package/src/mu/MUGlobal.ts +0 -220
  216. package/src/mu/MaskInput.tsx +0 -107
  217. package/src/mu/MobileListItemRenderer.tsx +0 -79
  218. package/src/mu/MoreFab.tsx +0 -211
  219. package/src/mu/NotifierMU.tsx +0 -654
  220. package/src/mu/NotifierPromptProps.ts +0 -26
  221. package/src/mu/OptionGroup.tsx +0 -223
  222. package/src/mu/PList.tsx +0 -27
  223. package/src/mu/ProgressCount.tsx +0 -166
  224. package/src/mu/PullToRefreshUI.tsx +0 -21
  225. package/src/mu/RLink.tsx +0 -64
  226. package/src/mu/ResponsibleContainer.tsx +0 -394
  227. package/src/mu/ScrollTopFab.tsx +0 -34
  228. package/src/mu/ScrollerListEx.tsx +0 -387
  229. package/src/mu/SearchBar.tsx +0 -398
  230. package/src/mu/SearchField.tsx +0 -82
  231. package/src/mu/SearchOptionGroup.tsx +0 -31
  232. package/src/mu/SelectBool.tsx +0 -33
  233. package/src/mu/SelectEx.tsx +0 -290
  234. package/src/mu/Switch.tsx +0 -94
  235. package/src/mu/SwitchAnt.tsx +0 -95
  236. package/src/mu/TabBox.tsx +0 -118
  237. package/src/mu/TableEx.tsx +0 -560
  238. package/src/mu/TextFieldEx.tsx +0 -250
  239. package/src/mu/Tiplist.tsx +0 -304
  240. package/src/mu/TooltipClick.tsx +0 -84
  241. package/src/mu/UserAvatar.tsx +0 -64
  242. package/src/mu/UserAvatarEditor.tsx +0 -287
  243. package/src/mu/pages/CommonPage.tsx +0 -128
  244. package/src/mu/pages/CommonPageProps.ts +0 -71
  245. package/src/mu/pages/DataGridPage.tsx +0 -137
  246. package/src/mu/pages/DataGridPageProps.ts +0 -24
  247. package/src/mu/pages/EditPage.tsx +0 -114
  248. package/src/mu/pages/FixedListPage.tsx +0 -135
  249. package/src/mu/pages/ListPage.tsx +0 -87
  250. package/src/mu/pages/ListPageProps.ts +0 -12
  251. package/src/mu/pages/ResponsivePage.tsx +0 -68
  252. package/src/mu/pages/ResponsivePageProps.ts +0 -57
  253. package/src/mu/pages/SearchPageProps.ts +0 -39
  254. package/src/mu/pages/TablePage.tsx +0 -120
  255. package/src/mu/pages/TablePageProps.ts +0 -12
  256. package/src/mu/pages/ViewPage.tsx +0 -285
  257. package/src/mu/texts/DateText.tsx +0 -74
  258. package/src/mu/texts/MoneyText.tsx +0 -49
  259. package/src/mu/texts/NumberText.tsx +0 -40
@@ -1,167 +0,0 @@
1
- import { css } from '@emotion/css';
2
- import { DataTypes, Utils } from '@etsoo/shared';
3
- import { useTheme } from '@mui/material';
4
- import React from 'react';
5
- import { ScrollerList } from '../components/ScrollerList';
6
- import { MUGlobal } from './MUGlobal';
7
- // Scroll bar size
8
- const scrollbarSize = 16;
9
- // Selected class name
10
- const selectedClassName = 'ScrollerListEx-Selected';
11
- const createGridStyle = (alternatingColors, selectedColor) => {
12
- return css({
13
- '& .ScrollerListEx-Selected': {
14
- backgroundColor: selectedColor
15
- },
16
- '& .ScrollerListEx-Row0:not(.ScrollerListEx-Selected)': {
17
- backgroundColor: alternatingColors[0]
18
- },
19
- '& .ScrollerListEx-Row1:not(.ScrollerListEx-Selected)': {
20
- backgroundColor: alternatingColors[1]
21
- },
22
- '@media (min-width: 800px)': {
23
- '::-webkit-scrollbar': {
24
- width: scrollbarSize,
25
- height: scrollbarSize,
26
- backgroundColor: '#f6f6f6'
27
- },
28
- '::-webkit-scrollbar-thumb': {
29
- backgroundColor: 'rgba(0,0,0,0.4)',
30
- borderRadius: '2px'
31
- },
32
- '::-webkit-scrollbar-track-piece:start': {
33
- background: 'transparent'
34
- },
35
- '::-webkit-scrollbar-track-piece:end': {
36
- background: 'transparent'
37
- }
38
- }
39
- });
40
- };
41
- // Default margin
42
- const defaultMargin = (margin, isNarrow) => {
43
- const half = MUGlobal.half(margin);
44
- if (isNarrow == null) {
45
- const half = MUGlobal.half(margin);
46
- return {
47
- marginLeft: margin,
48
- marginRight: margin,
49
- marginTop: half,
50
- marginBottom: half
51
- };
52
- }
53
- if (isNarrow) {
54
- return {
55
- marginLeft: 0,
56
- marginRight: 0,
57
- marginTop: half,
58
- marginBottom: half
59
- };
60
- }
61
- return {
62
- marginLeft: half,
63
- marginRight: half,
64
- marginTop: half,
65
- marginBottom: half
66
- };
67
- };
68
- // Default itemRenderer
69
- function defaultItemRenderer({ index, innerItemRenderer, data, onMouseDown, selected, style, itemHeight, onClick, onDoubleClick, space, margins }) {
70
- // Child
71
- const child = innerItemRenderer({
72
- index,
73
- data,
74
- style,
75
- selected,
76
- itemHeight,
77
- space,
78
- margins
79
- });
80
- let rowClass = `ScrollerListEx-Row${index % 2}`;
81
- if (selected)
82
- rowClass += ` ${selectedClassName}`;
83
- // Layout
84
- return (React.createElement("div", { className: rowClass, style: style, onMouseDown: (event) => onMouseDown(event.currentTarget, data), onClick: (event) => onClick && onClick(event, data), onDoubleClick: (event) => onDoubleClick && onDoubleClick(event, data) }, child));
85
- }
86
- /**
87
- * Extended ScrollerList
88
- * @param props Props
89
- * @returns Component
90
- */
91
- export function ScrollerListEx(props) {
92
- // Selected item ref
93
- const selectedItem = React.useRef();
94
- const onMouseDown = (div, data) => {
95
- var _a;
96
- // Destruct
97
- const [selectedDiv, selectedData] = (_a = selectedItem.current) !== null && _a !== void 0 ? _a : [];
98
- if (selectedData != null && selectedData[idField] === data[idField])
99
- return;
100
- selectedDiv === null || selectedDiv === void 0 ? void 0 : selectedDiv.classList.remove(selectedClassName);
101
- div.classList.add(selectedClassName);
102
- selectedItem.current = [div, data];
103
- if (onSelectChange)
104
- onSelectChange([data]);
105
- };
106
- const isSelected = (data) => {
107
- var _a;
108
- const [_, selectedData] = (_a = selectedItem.current) !== null && _a !== void 0 ? _a : [];
109
- const selected = selectedData && data && selectedData[idField] === data[idField]
110
- ? true
111
- : false;
112
- return selected;
113
- };
114
- // Destruct
115
- const { alternatingColors = [undefined, undefined], className, idField = 'id', innerItemRenderer, itemSize, itemKey = (index, data) => { var _a; return (_a = DataTypes.getIdValue1(data, idField)) !== null && _a !== void 0 ? _a : index; }, itemRenderer = (itemProps) => {
116
- const [itemHeight, space, margins] = calculateItemSize(itemProps.index);
117
- return defaultItemRenderer({
118
- itemHeight,
119
- innerItemRenderer,
120
- onMouseDown,
121
- onClick,
122
- onDoubleClick,
123
- space,
124
- margins,
125
- selected: isSelected(itemProps.data),
126
- ...itemProps
127
- });
128
- }, onClick, onDoubleClick, onSelectChange, selectedColor = '#edf4fb', ...rest } = props;
129
- // Theme
130
- const theme = useTheme();
131
- // Cache calculation
132
- const itemSizeResult = React.useMemo(() => {
133
- if (typeof itemSize === 'function')
134
- return undefined;
135
- const [size, spaces, isNarrow] = itemSize;
136
- if (typeof spaces === 'number')
137
- return [
138
- size,
139
- spaces,
140
- defaultMargin(MUGlobal.pagePaddings, undefined)
141
- ];
142
- return [
143
- size,
144
- MUGlobal.getSpace(spaces, theme),
145
- defaultMargin(spaces, isNarrow)
146
- ];
147
- }, [itemSize]);
148
- // Calculate size
149
- const calculateItemSize = (index) => {
150
- // Callback function
151
- if (typeof itemSize === 'function') {
152
- const result = itemSize(index);
153
- if (result.length == 2)
154
- return [...result, defaultMargin(MUGlobal.pagePaddings)];
155
- return result;
156
- }
157
- // Calculation
158
- return itemSizeResult;
159
- };
160
- // Local item size
161
- const itemSizeLocal = (index) => {
162
- const [size, space] = calculateItemSize(index);
163
- return size + space;
164
- };
165
- // Layout
166
- return (React.createElement(ScrollerList, { className: Utils.mergeClasses('ScrollerListEx-Body', className, createGridStyle(alternatingColors, selectedColor)), itemKey: itemKey, itemRenderer: itemRenderer, itemSize: itemSizeLocal, ...rest }));
167
- }
@@ -1,29 +0,0 @@
1
- import React from 'react';
2
- /**
3
- * Search bar props
4
- */
5
- export interface SearchBarProps {
6
- /**
7
- * Style class name
8
- */
9
- className?: string;
10
- /**
11
- * Fields
12
- */
13
- fields: React.ReactElement[];
14
- /**
15
- * Inner height
16
- * @default 40
17
- */
18
- innerHeight?: number;
19
- /**
20
- * On submit callback
21
- */
22
- onSubmit: (data: FormData, reset: boolean) => void | PromiseLike<void>;
23
- }
24
- /**
25
- * Search bar
26
- * @param props Props
27
- * @returns Component
28
- */
29
- export declare function SearchBar(props: SearchBarProps): JSX.Element;
@@ -1,262 +0,0 @@
1
- import { Button, Drawer, IconButton, Stack, useTheme } from '@mui/material';
2
- import React from 'react';
3
- import MoreHorizIcon from '@mui/icons-material/MoreHoriz';
4
- import { useDimensions } from '../uses/useDimensions';
5
- import { DomUtils } from '@etsoo/shared';
6
- import { Labels } from '../app/Labels';
7
- import { ReactUtils } from '../app/ReactUtils';
8
- import { useDelayedExecutor } from '..';
9
- // Cached width attribute name
10
- const cachedWidthName = 'data-cached-width';
11
- // Reset form
12
- const resetForm = (form) => {
13
- for (const input of form.elements) {
14
- // Ignore disabled inputs
15
- if ('disabled' in input && input.disabled)
16
- continue;
17
- // All non hidden inputs
18
- if (input instanceof HTMLInputElement) {
19
- // Ignore hidden input
20
- if (input.type === 'hidden')
21
- continue;
22
- // Ignore readOnly without data-reset=true inputs
23
- if (!input.readOnly || input.dataset.reset === 'true') {
24
- ReactUtils.triggerChange(input, '', true);
25
- }
26
- continue;
27
- }
28
- // All selects
29
- if (input instanceof HTMLSelectElement) {
30
- if (input.options.length > 0 && input.options[0].value === '') {
31
- input.selectedIndex = 0;
32
- }
33
- else {
34
- input.selectedIndex = -1;
35
- }
36
- continue;
37
- }
38
- }
39
- // Trigger reset event
40
- const resetEvent = new Event('reset');
41
- form.dispatchEvent(resetEvent);
42
- };
43
- // Disable inputs avoid auto trigger change events for them
44
- const setChildState = (child, enabled) => {
45
- const inputs = child.getElementsByTagName('input');
46
- for (const input of inputs) {
47
- input.disabled = !enabled;
48
- }
49
- };
50
- /**
51
- * Search bar
52
- * @param props Props
53
- * @returns Component
54
- */
55
- export function SearchBar(props) {
56
- // Destruct
57
- const { className, fields, innerHeight = 40, onSubmit } = props;
58
- // Labels
59
- const labels = Labels.CommonPage;
60
- // Spacing
61
- const theme = useTheme();
62
- const gap = parseFloat(theme.spacing(1));
63
- // Menu index
64
- const [index, updateIndex] = React.useState();
65
- // Drawer open / close
66
- const [open, updateOpen] = React.useState(false);
67
- // State
68
- const state = React.useRef({ hasMore: true, lastMaxWidth: 9999 }).current;
69
- // Watch container
70
- const { dimensions } = useDimensions(1, (target, rect) => {
71
- // Same logic from resetButtonRef
72
- if (rect.width === state.lastMaxWidth ||
73
- (!state.hasMore && rect.width > state.lastMaxWidth))
74
- return false;
75
- // Len
76
- const len = target.children.length;
77
- for (let i = 0; i < len; i++) {
78
- var classList = target.children[i].classList;
79
- classList.remove('showChild');
80
- }
81
- }, 0);
82
- // Show or hide element
83
- const setElementVisible = (element, visible) => {
84
- element.classList.remove(visible ? 'hiddenChild' : 'showChild');
85
- element.classList.add(visible ? 'showChild' : 'hiddenChild');
86
- };
87
- // Reset button ref
88
- const resetButtonRef = (instance) => {
89
- // Reset button
90
- const resetButton = instance;
91
- if (resetButton == null)
92
- return;
93
- // First
94
- const [_, container, containerRect] = dimensions[0];
95
- if (container == null ||
96
- containerRect == null ||
97
- containerRect.width < 10)
98
- return;
99
- // Container width
100
- let maxWidth = containerRect.width;
101
- if (maxWidth === state.lastMaxWidth ||
102
- (!state.hasMore && maxWidth > state.lastMaxWidth)) {
103
- return;
104
- }
105
- state.lastMaxWidth = maxWidth;
106
- // More button
107
- const buttonMore = resetButton.previousElementSibling;
108
- // Cached button width
109
- const cachedButtonWidth = container.getAttribute(cachedWidthName);
110
- if (cachedButtonWidth) {
111
- maxWidth -= Number.parseFloat(cachedButtonWidth);
112
- }
113
- else {
114
- // Reset button rect
115
- const resetButtonRect = resetButton.getBoundingClientRect();
116
- // More button rect
117
- const buttonMoreRect = buttonMore.getBoundingClientRect();
118
- // Total
119
- const totalButtonWidth = resetButtonRect.width + buttonMoreRect.width + 3 * gap;
120
- // Cache
121
- container.setAttribute(cachedWidthName, totalButtonWidth.toString());
122
- maxWidth -= totalButtonWidth;
123
- }
124
- // Children
125
- const children = container.children;
126
- // Len
127
- const len = children.length;
128
- // Other elements
129
- const others = len - 2;
130
- let hasMore = false;
131
- let newIndex = others;
132
- for (let c = 0; c < others; c++) {
133
- const child = children[c];
134
- const cachedWidth = child.getAttribute(cachedWidthName);
135
- let childWidth;
136
- if (cachedWidth) {
137
- childWidth = Number.parseFloat(cachedWidth);
138
- }
139
- else {
140
- const childD = child.getBoundingClientRect();
141
- childWidth = childD.width + gap;
142
- child.setAttribute(cachedWidthName, childWidth.toString());
143
- }
144
- // No gap here, child width includes the gap
145
- if (childWidth <= maxWidth) {
146
- maxWidth -= childWidth;
147
- setChildState(child, true);
148
- setElementVisible(child, true);
149
- }
150
- else {
151
- setChildState(child, false);
152
- setElementVisible(child, false);
153
- if (!hasMore) {
154
- // Make sure coming logic to the block
155
- maxWidth = 0;
156
- // Keep the current index
157
- newIndex = c;
158
- // Indicates more
159
- hasMore = true;
160
- }
161
- }
162
- }
163
- // Show or hide more button
164
- state.hasMore = hasMore;
165
- setElementVisible(buttonMore, hasMore);
166
- setElementVisible(resetButton, true);
167
- // Update menu start index
168
- updateIndex(newIndex);
169
- };
170
- // More items creator
171
- const moreItems = [];
172
- if (index != null) {
173
- for (let i = index; i < fields.length; i++) {
174
- moreItems.push(React.createElement(React.Fragment, { key: i }, fields[i]));
175
- }
176
- }
177
- // Handle main form
178
- const handleForm = (event) => {
179
- if (event.nativeEvent.cancelable && !event.nativeEvent.composed)
180
- return;
181
- if (state.form == null)
182
- state.form = event.currentTarget;
183
- delayed.call();
184
- };
185
- // Handle more button click
186
- const handleMore = () => {
187
- updateOpen(!open);
188
- };
189
- // More form change
190
- const moreFormChange = (event) => {
191
- if (event.nativeEvent.cancelable && !event.nativeEvent.composed)
192
- return;
193
- if (state.moreForm == null)
194
- state.moreForm = event.currentTarget;
195
- delayed.call();
196
- };
197
- // Submit at once
198
- const handleSubmitInstant = (reset = false) => {
199
- // Prepare data
200
- const data = new FormData(state.form);
201
- if (state.moreForm != null) {
202
- DomUtils.mergeFormData(data, new FormData(state.moreForm));
203
- }
204
- onSubmit(data, reset);
205
- };
206
- const delayed = useDelayedExecutor(handleSubmitInstant, 480);
207
- // Reset
208
- const handleReset = () => {
209
- // Clear form values
210
- if (state.form != null)
211
- resetForm(state.form);
212
- if (state.moreForm != null)
213
- resetForm(state.moreForm);
214
- // Resubmit
215
- handleSubmitInstant(true);
216
- };
217
- React.useEffect(() => {
218
- // Delayed way
219
- delayed.call(100);
220
- return () => {
221
- delayed.clear();
222
- };
223
- }, [className]);
224
- // Layout
225
- return (React.createElement(React.Fragment, null,
226
- React.createElement("form", { id: "SearchBarForm", className: className, onChange: handleForm, ref: (form) => {
227
- if (form)
228
- state.form = form;
229
- } },
230
- React.createElement(Stack, { ref: dimensions[0][0], justifyContent: "center", alignItems: "center", direction: "row", spacing: 1, height: innerHeight, sx: {
231
- '& > :not(style)': {
232
- flexBasis: 'auto',
233
- flexGrow: 0,
234
- flexShrink: 0,
235
- maxWidth: '180px',
236
- visibility: 'hidden'
237
- },
238
- '& > .hiddenChild': {
239
- display: 'none'
240
- },
241
- '& > .showChild': {
242
- display: 'block',
243
- visibility: 'visible'
244
- }
245
- } },
246
- fields.map((item, index) => (React.createElement(React.Fragment, { key: index }, item))),
247
- React.createElement(IconButton, { "aria-label": "delete", size: "medium", onClick: handleMore },
248
- React.createElement(MoreHorizIcon, null)),
249
- React.createElement(Button, { variant: "contained", size: "medium", ref: resetButtonRef, onClick: handleReset }, labels.reset))),
250
- index != null && index < fields.length && (React.createElement(Drawer, { anchor: "right", sx: { minWidth: '250px' }, ModalProps: {
251
- keepMounted: true // Better open performance on mobile.
252
- }, open: open, onClose: () => updateOpen(false) },
253
- React.createElement("form", { onChange: moreFormChange, ref: (form) => {
254
- if (form)
255
- state.moreForm = form;
256
- } },
257
- React.createElement(Stack, { direction: "column", alignItems: "stretch", spacing: 2, padding: 2, sx: {
258
- '& > :not(style)': {
259
- minWidth: '100px'
260
- }
261
- } }, moreItems))))));
262
- }
@@ -1,21 +0,0 @@
1
- /// <reference types="react" />
2
- import { TextFieldProps } from '@mui/material';
3
- /**
4
- * Search field props
5
- */
6
- export declare type SearchFieldProps = TextFieldProps & {
7
- /**
8
- * Change delay (ms) to avoid repeatly dispatch onChange
9
- */
10
- changeDelay?: number;
11
- /**
12
- * Is the field read only?
13
- */
14
- readOnly?: boolean;
15
- };
16
- /**
17
- * Search field
18
- * @param props Props
19
- * @returns Component
20
- */
21
- export declare function SearchField(props: SearchFieldProps): JSX.Element;
@@ -1,39 +0,0 @@
1
- import { TextField } from '@mui/material';
2
- import React from 'react';
3
- import { useDelayedExecutor } from '../uses/useDelayedExecutor';
4
- import { MUGlobal } from './MUGlobal';
5
- /**
6
- * Search field
7
- * @param props Props
8
- * @returns Component
9
- */
10
- export function SearchField(props) {
11
- // Destruct
12
- const { changeDelay, InputLabelProps = {}, InputProps = {}, onChange, readOnly, size = MUGlobal.searchFieldSize, variant = MUGlobal.searchFieldVariant, ...rest } = props;
13
- // Shrink
14
- InputLabelProps.shrink = MUGlobal.searchFieldShrink;
15
- // Read only
16
- if (readOnly != null)
17
- InputProps.readOnly = readOnly;
18
- const isMounted = React.useRef(true);
19
- const delayed = onChange != null && changeDelay != null && changeDelay >= 1
20
- ? useDelayedExecutor(onChange, changeDelay)
21
- : undefined;
22
- const onChangeEx = (event) => {
23
- if (onChange == null)
24
- return;
25
- if (changeDelay == null || changeDelay < 1) {
26
- onChange(event);
27
- return;
28
- }
29
- delayed === null || delayed === void 0 ? void 0 : delayed.call(undefined, event);
30
- };
31
- React.useEffect(() => {
32
- return () => {
33
- isMounted.current = false;
34
- delayed === null || delayed === void 0 ? void 0 : delayed.clear();
35
- };
36
- }, []);
37
- // Layout
38
- return (React.createElement(TextField, { InputLabelProps: InputLabelProps, InputProps: InputProps, onChange: onChangeEx, size: size, variant: variant, ...rest }));
39
- }
@@ -1,9 +0,0 @@
1
- /// <reference types="react" />
2
- import { DataTypes, IdDefaultType, LabelDefaultType, ListType } from '@etsoo/shared';
3
- import { OptionGroupProps } from './OptionGroup';
4
- /**
5
- * Search OptionGroup
6
- * @param props Props
7
- * @returns Component
8
- */
9
- export declare function SearchOptionGroup<T extends object = ListType, D extends DataTypes.Keys<T> = IdDefaultType<T>, L extends DataTypes.Keys<T, string> = LabelDefaultType<T>>(props: OptionGroupProps<T, D, L>): JSX.Element;
@@ -1,14 +0,0 @@
1
- import React from 'react';
2
- import { MUGlobal } from './MUGlobal';
3
- import { OptionGroup } from './OptionGroup';
4
- /**
5
- * Search OptionGroup
6
- * @param props Props
7
- * @returns Component
8
- */
9
- export function SearchOptionGroup(props) {
10
- // Destruct
11
- const { row = true, size = MUGlobal.searchFieldSize, sx = { '& .MuiFormLabel-root': { fontSize: '0.75em' } }, ...rest } = props;
12
- // Layout
13
- return React.createElement(OptionGroup, { row: row, size: size, sx: sx, ...rest });
14
- }
@@ -1,13 +0,0 @@
1
- /// <reference types="react" />
2
- import { ListType1 } from '@etsoo/shared';
3
- import { SelectExProps } from './SelectEx';
4
- /**
5
- * SelectBool props
6
- */
7
- export declare type SelectBoolProps = Omit<SelectExProps<ListType1>, 'options' | 'loadData'>;
8
- /**
9
- * SelectBool (yes/no)
10
- * @param props Props
11
- * @returns Component
12
- */
13
- export declare function SelectBool(props: SelectBoolProps): JSX.Element;
@@ -1,22 +0,0 @@
1
- import { Utils } from '@etsoo/shared';
2
- import React from 'react';
3
- import { globalApp } from '..';
4
- import { SelectEx } from './SelectEx';
5
- /**
6
- * SelectBool (yes/no)
7
- * @param props Props
8
- * @returns Component
9
- */
10
- export function SelectBool(props) {
11
- // Destruct
12
- const { search = true, autoAddBlankItem = search, ...rest } = props;
13
- // Options
14
- const options = [
15
- { id: 'false', label: globalApp.get('no') },
16
- { id: 'true', label: globalApp.get('yes') }
17
- ];
18
- if (autoAddBlankItem)
19
- Utils.addBlankItem(options);
20
- // Layout
21
- return React.createElement(SelectEx, { options: options, search: search, ...rest });
22
- }
@@ -1,50 +0,0 @@
1
- import { SelectProps } from '@mui/material';
2
- import React from 'react';
3
- import { DataTypes, IdDefaultType, LabelDefaultType, ListType } from '@etsoo/shared';
4
- /**
5
- * Extended select component props
6
- */
7
- export declare type SelectExProps<T extends object, D extends DataTypes.Keys<T> = IdDefaultType<T>, L extends DataTypes.Keys<T, string> = LabelDefaultType<T>> = Omit<SelectProps, 'labelId' | 'input' | 'native'> & {
8
- /**
9
- * Auto add blank item
10
- */
11
- autoAddBlankItem?: boolean;
12
- /**
13
- * Id field
14
- */
15
- idField?: D;
16
- /**
17
- * Item icon renderer
18
- */
19
- itemIconRenderer?: (id: T[D]) => React.ReactNode;
20
- /**
21
- * Label field
22
- */
23
- labelField?: L | ((option: T) => string);
24
- /**
25
- * Load data callback
26
- */
27
- loadData?: () => PromiseLike<T[] | null | undefined>;
28
- /**
29
- * Item click handler
30
- */
31
- onItemClick?: (event: React.MouseEvent, option: T) => void;
32
- /**
33
- * On load data handler
34
- */
35
- onLoadData?: (options: T[]) => void;
36
- /**
37
- * Array of options.
38
- */
39
- options?: ReadonlyArray<T>;
40
- /**
41
- * Is search case?
42
- */
43
- search?: boolean;
44
- };
45
- /**
46
- * Extended select component
47
- * @param props Props
48
- * @returns Component
49
- */
50
- export declare function SelectEx<T extends object = ListType, D extends DataTypes.Keys<T> = IdDefaultType<T>, L extends DataTypes.Keys<T, string> = LabelDefaultType<T>>(props: SelectExProps<T, D, L>): JSX.Element;