@etsoo/materialui 1.0.43 → 1.0.45

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/SelectEx.js CHANGED
@@ -4,6 +4,7 @@ import { MUGlobal } from './MUGlobal';
4
4
  import { ListItemRightIcon } from './ListItemRightIcon';
5
5
  import RefreshIcon from '@mui/icons-material/Refresh';
6
6
  import { Utils } from '@etsoo/shared';
7
+ import { ReactUtils } from '@etsoo/react';
7
8
  /**
8
9
  * Extended select component
9
10
  * @param props Props
@@ -52,7 +53,12 @@ export function SelectEx(props) {
52
53
  localValue = valueSource;
53
54
  }
54
55
  // Value state
55
- const [valueState, setValueState] = React.useState();
56
+ const [valueState, setValueStateBase] = React.useState();
57
+ const valueRef = React.useRef();
58
+ const setValueState = (newValue) => {
59
+ valueRef.current = newValue;
60
+ setValueStateBase(newValue);
61
+ };
56
62
  React.useEffect(() => {
57
63
  if (localValue != null)
58
64
  setValueState(localValue);
@@ -69,22 +75,23 @@ export function SelectEx(props) {
69
75
  const handleChange = (event) => {
70
76
  const value = event.target.value;
71
77
  if (multiple && !Array.isArray(value))
72
- setItemValue([value]);
78
+ return setItemValue([value]);
73
79
  else
74
- setItemValue(value);
80
+ return setItemValue(value);
75
81
  };
76
82
  // Set item
77
83
  const setItemValue = (id) => {
78
- if (id != valueState) {
84
+ var _a;
85
+ if (id != valueRef.current) {
79
86
  setValueState(id);
80
- /*
81
- const input = divRef.current?.querySelector('input');
87
+ const input = (_a = divRef.current) === null || _a === void 0 ? void 0 : _a.querySelector('input');
82
88
  if (input) {
83
89
  // Different value, trigger change event
84
- ReactUtils.triggerChange(input, id as string, false);
90
+ ReactUtils.triggerChange(input, id, false);
85
91
  }
86
- */
92
+ return true;
87
93
  }
94
+ return false;
88
95
  };
89
96
  // Get option id
90
97
  const getId = (option) => {
@@ -147,8 +154,9 @@ export function SelectEx(props) {
147
154
  if (event.defaultPrevented)
148
155
  return;
149
156
  }
150
- doItemChange(localOptions, event.target.value, true);
151
- handleChange(event);
157
+ if (handleChange(event)) {
158
+ doItemChange(localOptions, event.target.value, true);
159
+ }
152
160
  }, renderValue: (selected) => {
153
161
  // The text shows up
154
162
  return localOptions
@@ -4,10 +4,14 @@ import { DataTypes } from '@etsoo/shared';
4
4
  import React from 'react';
5
5
  import { CultureAction, CultureState, INotificationReact, InputDialogProps, IPageData, IStateProps, NotificationReactCallProps, PageAction, PageState, UserAction, UserState } from '@etsoo/react';
6
6
  import { NavigateFunction, NavigateOptions } from 'react-router-dom';
7
+ /**
8
+ * React Application Type
9
+ */
10
+ export declare type ReactAppType = IApp & IReactAppBase;
7
11
  /**
8
12
  * Global application
9
13
  */
10
- export declare let globalApp: IApp & IReactAppBase;
14
+ export declare let globalApp: ReactAppType;
11
15
  /**
12
16
  * React app state detector
13
17
  * Case 1: undefined, when refresh the whole page
@@ -95,7 +99,6 @@ export declare class ReactApp<S extends IAppSettings, D extends IUser, P extends
95
99
  * Get notifier provider
96
100
  */
97
101
  static get notifierProvider(): React.FunctionComponent<object>;
98
- private static createApi;
99
102
  private static createNotifier;
100
103
  /**
101
104
  * Culture state
@@ -57,7 +57,7 @@ export class ReactApp extends CoreApp {
57
57
  * @param name Application name
58
58
  */
59
59
  constructor(settings, name) {
60
- super(settings, ReactApp.createApi(settings), ReactApp.createNotifier(), new WindowStorage(), name);
60
+ super(settings, createClient(), ReactApp.createNotifier(), new WindowStorage(), name);
61
61
  /**
62
62
  * User state
63
63
  */
@@ -77,13 +77,6 @@ export class ReactApp extends CoreApp {
77
77
  static get notifierProvider() {
78
78
  return this._notifierProvider;
79
79
  }
80
- static createApi(settings) {
81
- // API
82
- // Support to replace {hostname} with current hostname
83
- const api = createClient();
84
- api.baseUrl = settings.endpoint;
85
- return api;
86
- }
87
80
  static createNotifier() {
88
81
  // Notifier
89
82
  ReactApp._notifierProvider = NotifierMU.setup();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@etsoo/materialui",
3
- "version": "1.0.43",
3
+ "version": "1.0.45",
4
4
  "description": "TypeScript Material-UI Implementation",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",
@@ -51,12 +51,12 @@
51
51
  "@emotion/css": "^11.10.0",
52
52
  "@emotion/react": "^11.10.4",
53
53
  "@emotion/styled": "^11.10.4",
54
- "@etsoo/appscript": "^1.3.1",
54
+ "@etsoo/appscript": "^1.3.4",
55
55
  "@etsoo/notificationbase": "^1.1.12",
56
- "@etsoo/react": "^1.6.12",
57
- "@etsoo/shared": "^1.1.59",
58
- "@mui/icons-material": "^5.10.6",
59
- "@mui/material": "^5.10.8",
56
+ "@etsoo/react": "^1.6.14",
57
+ "@etsoo/shared": "^1.1.60",
58
+ "@mui/icons-material": "^5.10.9",
59
+ "@mui/material": "^5.10.9",
60
60
  "@types/pica": "^9.0.1",
61
61
  "@types/pulltorefreshjs": "^0.1.5",
62
62
  "@types/react": "^18.0.21",
@@ -71,24 +71,24 @@
71
71
  "react-dom": "^18.2.0",
72
72
  "react-draggable": "^4.4.5",
73
73
  "react-imask": "^6.4.3",
74
- "react-router-dom": "^6.4.1",
74
+ "react-router-dom": "^6.4.2",
75
75
  "react-window": "^1.8.7"
76
76
  },
77
77
  "devDependencies": {
78
78
  "@babel/cli": "^7.19.3",
79
79
  "@babel/core": "^7.19.3",
80
80
  "@babel/plugin-transform-runtime": "^7.19.1",
81
- "@babel/preset-env": "^7.19.3",
82
- "@babel/runtime-corejs3": "^7.19.1",
81
+ "@babel/preset-env": "^7.19.4",
82
+ "@babel/runtime-corejs3": "^7.19.4",
83
83
  "@testing-library/jest-dom": "^5.16.5",
84
84
  "@testing-library/react": "^13.4.0",
85
- "@types/jest": "^29.1.1",
86
- "@typescript-eslint/eslint-plugin": "^5.39.0",
87
- "@typescript-eslint/parser": "^5.39.0",
88
- "eslint": "^8.24.0",
85
+ "@types/jest": "^29.1.2",
86
+ "@typescript-eslint/eslint-plugin": "^5.40.0",
87
+ "@typescript-eslint/parser": "^5.40.0",
88
+ "eslint": "^8.25.0",
89
89
  "eslint-config-airbnb-base": "^15.0.0",
90
90
  "eslint-plugin-import": "^2.26.0",
91
- "eslint-plugin-react": "^7.31.8",
91
+ "eslint-plugin-react": "^7.31.10",
92
92
  "jest": "^29.1.2",
93
93
  "jest-environment-jsdom": "^29.1.2",
94
94
  "ts-jest": "^29.0.3",
package/src/SelectEx.tsx CHANGED
@@ -23,6 +23,7 @@ import {
23
23
  ListType,
24
24
  Utils
25
25
  } from '@etsoo/shared';
26
+ import { ReactUtils } from '@etsoo/react';
26
27
 
27
28
  /**
28
29
  * Extended select component props
@@ -183,7 +184,12 @@ export function SelectEx<
183
184
  }
184
185
 
185
186
  // Value state
186
- const [valueState, setValueState] = React.useState<unknown>();
187
+ const [valueState, setValueStateBase] = React.useState<unknown>();
188
+ const valueRef = React.useRef<unknown>();
189
+ const setValueState = (newValue: unknown) => {
190
+ valueRef.current = newValue;
191
+ setValueStateBase(newValue);
192
+ };
187
193
 
188
194
  React.useEffect(() => {
189
195
  if (localValue != null) setValueState(localValue);
@@ -201,23 +207,23 @@ export function SelectEx<
201
207
  // Change handler
202
208
  const handleChange = (event: SelectChangeEvent<unknown>) => {
203
209
  const value = event.target.value;
204
- if (multiple && !Array.isArray(value)) setItemValue([value]);
205
- else setItemValue(value);
210
+ if (multiple && !Array.isArray(value)) return setItemValue([value]);
211
+ else return setItemValue(value);
206
212
  };
207
213
 
208
214
  // Set item
209
215
  const setItemValue = (id: unknown) => {
210
- if (id != valueState) {
216
+ if (id != valueRef.current) {
211
217
  setValueState(id);
212
218
 
213
- /*
214
219
  const input = divRef.current?.querySelector('input');
215
220
  if (input) {
216
221
  // Different value, trigger change event
217
222
  ReactUtils.triggerChange(input, id as string, false);
218
223
  }
219
- */
224
+ return true;
220
225
  }
226
+ return false;
221
227
  };
222
228
 
223
229
  // Get option id
@@ -314,8 +320,14 @@ export function SelectEx<
314
320
  // event.preventDefault() will block executing
315
321
  if (event.defaultPrevented) return;
316
322
  }
317
- doItemChange(localOptions, event.target.value, true);
318
- handleChange(event);
323
+
324
+ if (handleChange(event)) {
325
+ doItemChange(
326
+ localOptions,
327
+ event.target.value,
328
+ true
329
+ );
330
+ }
319
331
  }}
320
332
  renderValue={(selected) => {
321
333
  // The text shows up
@@ -37,10 +37,15 @@ import {
37
37
  } from '@etsoo/react';
38
38
  import { NavigateFunction, NavigateOptions } from 'react-router-dom';
39
39
 
40
+ /**
41
+ * React Application Type
42
+ */
43
+ export type ReactAppType = IApp & IReactAppBase;
44
+
40
45
  /**
41
46
  * Global application
42
47
  */
43
- export let globalApp: IApp & IReactAppBase;
48
+ export let globalApp: ReactAppType;
44
49
 
45
50
  /**
46
51
  * React app state detector
@@ -192,14 +197,6 @@ export class ReactApp<
192
197
  return this._notifierProvider;
193
198
  }
194
199
 
195
- private static createApi(settings: IAppSettings) {
196
- // API
197
- // Support to replace {hostname} with current hostname
198
- const api = createClient();
199
- api.baseUrl = settings.endpoint;
200
- return api;
201
- }
202
-
203
200
  private static createNotifier() {
204
201
  // Notifier
205
202
  ReactApp._notifierProvider = NotifierMU.setup();
@@ -255,7 +252,7 @@ export class ReactApp<
255
252
  constructor(settings: S, name: string) {
256
253
  super(
257
254
  settings,
258
- ReactApp.createApi(settings),
255
+ createClient(),
259
256
  ReactApp.createNotifier(),
260
257
  new WindowStorage(),
261
258
  name