@etsoo/materialui 1.4.74 → 1.4.76

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 (115) hide show
  1. package/__tests__/ResponsePage.tsx +34 -31
  2. package/lib/cjs/AddresSelector.js +4 -2
  3. package/lib/cjs/AuditDisplay.js +11 -11
  4. package/lib/cjs/BridgeCloseButton.js +3 -1
  5. package/lib/cjs/ButtonPopover.d.ts +5 -0
  6. package/lib/cjs/ButtonPopover.js +5 -4
  7. package/lib/cjs/ComboBox.js +3 -1
  8. package/lib/cjs/ComboBoxMultiple.js +3 -1
  9. package/lib/cjs/ComboBoxPro.js +4 -2
  10. package/lib/cjs/CultureDataTable.js +3 -1
  11. package/lib/cjs/DataSteps.js +3 -6
  12. package/lib/cjs/DataTable.js +3 -1
  13. package/lib/cjs/InputField.d.ts +3 -3
  14. package/lib/cjs/InputTipField.js +15 -8
  15. package/lib/cjs/ListMoreDisplay.js +3 -1
  16. package/lib/cjs/OptionBool.js +3 -1
  17. package/lib/cjs/QuickList.js +4 -2
  18. package/lib/cjs/SelectBool.js +4 -2
  19. package/lib/cjs/ShowDataComparison.js +2 -5
  20. package/lib/cjs/SwitchAnt.js +3 -1
  21. package/lib/cjs/TagList.js +3 -1
  22. package/lib/cjs/TagListPro.js +4 -2
  23. package/lib/cjs/TextFieldEx.d.ts +3 -3
  24. package/lib/cjs/TextFieldEx.js +3 -1
  25. package/lib/cjs/Tiplist.js +5 -3
  26. package/lib/cjs/TiplistPro.js +3 -1
  27. package/lib/cjs/UserAvatar.js +3 -1
  28. package/lib/cjs/app/CommonApp.d.ts +1 -2
  29. package/lib/cjs/app/IServiceApp.d.ts +1 -6
  30. package/lib/cjs/app/IServiceApp.js +0 -9
  31. package/lib/cjs/app/ReactApp.d.ts +18 -74
  32. package/lib/cjs/app/ReactApp.js +40 -82
  33. package/lib/cjs/app/ServiceApp.d.ts +1 -2
  34. package/lib/cjs/custom/CustomFieldWindow.js +3 -6
  35. package/lib/cjs/index.d.ts +0 -1
  36. package/lib/cjs/index.js +0 -1
  37. package/lib/cjs/pages/CommonPage.js +3 -1
  38. package/lib/cjs/pages/LeftDrawer.js +4 -2
  39. package/lib/cjs/pages/ViewPage.js +13 -14
  40. package/lib/mjs/AddresSelector.js +4 -2
  41. package/lib/mjs/AuditDisplay.js +11 -11
  42. package/lib/mjs/BridgeCloseButton.js +4 -2
  43. package/lib/mjs/ButtonPopover.d.ts +5 -0
  44. package/lib/mjs/ButtonPopover.js +5 -4
  45. package/lib/mjs/ComboBox.js +4 -2
  46. package/lib/mjs/ComboBoxMultiple.js +4 -2
  47. package/lib/mjs/ComboBoxPro.js +4 -2
  48. package/lib/mjs/CultureDataTable.js +4 -2
  49. package/lib/mjs/DataSteps.js +3 -6
  50. package/lib/mjs/DataTable.js +4 -2
  51. package/lib/mjs/InputField.d.ts +3 -3
  52. package/lib/mjs/InputTipField.js +15 -8
  53. package/lib/mjs/ListMoreDisplay.js +4 -2
  54. package/lib/mjs/OptionBool.js +4 -2
  55. package/lib/mjs/QuickList.js +4 -2
  56. package/lib/mjs/SelectBool.js +4 -2
  57. package/lib/mjs/ShowDataComparison.js +3 -6
  58. package/lib/mjs/SwitchAnt.js +4 -2
  59. package/lib/mjs/TagList.js +4 -2
  60. package/lib/mjs/TagListPro.js +4 -2
  61. package/lib/mjs/TextFieldEx.d.ts +3 -3
  62. package/lib/mjs/TextFieldEx.js +4 -2
  63. package/lib/mjs/Tiplist.js +5 -3
  64. package/lib/mjs/TiplistPro.js +4 -2
  65. package/lib/mjs/UserAvatar.js +4 -2
  66. package/lib/mjs/app/CommonApp.d.ts +1 -2
  67. package/lib/mjs/app/IServiceApp.d.ts +1 -6
  68. package/lib/mjs/app/IServiceApp.js +1 -5
  69. package/lib/mjs/app/ReactApp.d.ts +18 -74
  70. package/lib/mjs/app/ReactApp.js +36 -83
  71. package/lib/mjs/app/ServiceApp.d.ts +1 -2
  72. package/lib/mjs/custom/CustomFieldWindow.js +3 -6
  73. package/lib/mjs/index.d.ts +0 -1
  74. package/lib/mjs/index.js +0 -1
  75. package/lib/mjs/pages/CommonPage.js +4 -2
  76. package/lib/mjs/pages/LeftDrawer.js +5 -3
  77. package/lib/mjs/pages/ViewPage.js +14 -15
  78. package/package.json +11 -11
  79. package/src/AddresSelector.tsx +5 -2
  80. package/src/AuditDisplay.tsx +14 -12
  81. package/src/BridgeCloseButton.tsx +5 -2
  82. package/src/ButtonPopover.tsx +13 -6
  83. package/src/ComboBox.tsx +5 -2
  84. package/src/ComboBoxMultiple.tsx +5 -2
  85. package/src/ComboBoxPro.tsx +5 -2
  86. package/src/CultureDataTable.tsx +6 -3
  87. package/src/DataSteps.tsx +3 -6
  88. package/src/DataTable.tsx +5 -2
  89. package/src/InputTipField.tsx +26 -17
  90. package/src/ListMoreDisplay.tsx +5 -3
  91. package/src/OptionBool.tsx +5 -3
  92. package/src/QuickList.tsx +5 -2
  93. package/src/SelectBool.tsx +5 -3
  94. package/src/ShowDataComparison.tsx +3 -6
  95. package/src/SwitchAnt.tsx +5 -2
  96. package/src/TagList.tsx +5 -2
  97. package/src/TagListPro.tsx +5 -2
  98. package/src/TextFieldEx.tsx +5 -3
  99. package/src/Tiplist.tsx +7 -4
  100. package/src/TiplistPro.tsx +5 -2
  101. package/src/UserAvatar.tsx +5 -3
  102. package/src/app/CommonApp.ts +2 -3
  103. package/src/app/IServiceApp.ts +1 -8
  104. package/src/app/ReactApp.ts +52 -151
  105. package/src/app/ServiceApp.ts +1 -3
  106. package/src/custom/CustomFieldWindow.tsx +3 -6
  107. package/src/index.ts +0 -1
  108. package/src/pages/CommonPage.tsx +5 -4
  109. package/src/pages/LeftDrawer.tsx +6 -3
  110. package/src/pages/ViewPage.tsx +18 -13
  111. package/lib/cjs/app/IServicePage.d.ts +0 -6
  112. package/lib/cjs/app/IServicePage.js +0 -2
  113. package/lib/mjs/app/IServicePage.d.ts +0 -6
  114. package/lib/mjs/app/IServicePage.js +0 -1
  115. package/src/app/IServicePage.ts +0 -6
@@ -1,12 +1,7 @@
1
1
  import { ApiRefreshTokenDto, IApi, IApiPayload } from "@etsoo/appscript";
2
- import { ReactAppData, ReactAppType } from "./ReactApp";
2
+ import { ReactAppType } from "./ReactApp";
3
3
  import { IServiceUser, ServiceUserToken } from "./IServiceUser";
4
4
  import { IActionResult } from "@etsoo/shared";
5
- import React from "react";
6
- /**
7
- * Service application context
8
- */
9
- export declare const ServiceAppContext: React.Context<ReactAppData<IServiceApp> | null>;
10
5
  /**
11
6
  * Service application interface
12
7
  */
@@ -1,11 +1,2 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
2
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.ServiceAppContext = void 0;
7
- const react_1 = __importDefault(require("react"));
8
- /**
9
- * Service application context
10
- */
11
- exports.ServiceAppContext = react_1.default.createContext(null);
@@ -2,41 +2,26 @@ import { AppTryLoginParams, CoreApp, FormatResultCustomCallback, IApp, IAppSetti
2
2
  import { INotifier, NotificationReturn } from "@etsoo/notificationbase";
3
3
  import { DataTypes, IActionResult } from "@etsoo/shared";
4
4
  import React from "react";
5
- import { CultureAction, CultureState, INotificationReact, InputDialogProps, IPageData, IStateProps, NotificationReactCallProps, PageAction, PageState, UserAction, UserState } from "@etsoo/react";
5
+ import { CultureAction, CultureState, INotificationReact, InputDialogProps, IStateProps, NotificationReactCallProps, UserAction, UserState } from "@etsoo/react";
6
6
  import { NavigateFunction, NavigateOptions } from "react-router";
7
7
  /**
8
8
  * React Application Type
9
9
  */
10
10
  export type ReactAppType = IApp & IReactAppBase;
11
- /**
12
- * React application data
13
- */
14
- export type ReactAppData<A extends ReactAppType> = {
15
- /**
16
- * Current application
17
- */
18
- app: A;
19
- };
20
11
  /**
21
12
  * React application context
22
13
  */
23
- export declare const ReactAppContext: React.Context<ReactAppData<ReactAppType> | null>;
14
+ export declare const ReactAppContext: React.Context<ReactAppType | null>;
24
15
  /**
25
- * Global application
16
+ * Get React application context hook
17
+ * @returns React application
26
18
  */
27
- export declare let globalApp: ReactAppType | null;
19
+ export declare function useAppContext(): ReactAppType | null;
28
20
  /**
29
- * React app state detector
30
- * Case 1: undefined, when refresh the whole page
31
- * Case 2: false, unauthorized
32
- * Case 3: true, authorized or considered as authorized (maynot, like token expiry)
33
- * Case 4: property or properties changed
34
- * @param props Props
35
- * @returns Component
21
+ * Get React application context hook
22
+ * @returns React application
36
23
  */
37
- export declare function ReactAppStateDetector(props: IStateProps): React.FunctionComponentElement<{
38
- children?: React.ReactNode | undefined;
39
- }>;
24
+ export declare function useRequiredAppContext(): IApp & IReactAppBase;
40
25
  /**
41
26
  * React implemented base
42
27
  */
@@ -45,10 +30,6 @@ export interface IReactAppBase {
45
30
  * Override Notifier as React specific
46
31
  */
47
32
  readonly notifier: INotifier<React.ReactNode, NotificationReactCallProps>;
48
- /**
49
- * User state
50
- */
51
- readonly userState: UserState<any>;
52
33
  /**
53
34
  * Is screen size down 'sm'
54
35
  */
@@ -68,46 +49,30 @@ export interface IReactAppBase {
68
49
  * @returns Props
69
50
  */
70
51
  getMoneyFormatProps(currency?: string): object;
71
- /**
72
- * Set page data
73
- * @param data Page data
74
- */
75
- setPageData(data: IPageData): void;
76
- /**
77
- * Set page title and subtitle
78
- * @param title Page title
79
- * @param subtitle Page subtitle
80
- */
81
- setPageTitle(title: string, subtitle?: string): void;
82
- /**
83
- * Set page title and data
84
- * @param title Page title
85
- */
86
- setPageTitle(title: string): void;
87
52
  /**
88
53
  * Show input dialog
89
54
  * @param props Props
90
55
  */
91
56
  showInputDialog({ title, message, callback, ...rest }: InputDialogProps): INotificationReact;
57
+ /**
58
+ * State detector component
59
+ * @param props Props
60
+ */
61
+ stateDetector(props: IStateProps): React.ReactNode;
92
62
  }
93
63
  /**
94
64
  * Core application interface
95
65
  */
96
- export interface IReactApp<S extends IAppSettings, D extends IUser, P extends IPageData> extends ICoreApp<D, S, React.ReactNode, NotificationReactCallProps>, IReactAppBase {
66
+ export interface IReactApp<S extends IAppSettings, D extends IUser> extends ICoreApp<D, S, React.ReactNode, NotificationReactCallProps>, Omit<IReactAppBase, "userState"> {
97
67
  /**
98
68
  * User state
99
69
  */
100
70
  readonly userState: UserState<D>;
101
- /**
102
- * Set page data
103
- * @param data Page data
104
- */
105
- setPageData(data: P): void;
106
71
  }
107
72
  /**
108
73
  * React application
109
74
  */
110
- export declare class ReactApp<S extends IAppSettings, D extends IUser, P extends IPageData> extends CoreApp<D, S, React.ReactNode, NotificationReactCallProps> implements IReactApp<S, D, P> {
75
+ export declare class ReactApp<S extends IAppSettings, D extends IUser> extends CoreApp<D, S, React.ReactNode, NotificationReactCallProps> implements IReactApp<S, D> {
111
76
  private static _notifierProvider;
112
77
  /**
113
78
  * Get notifier provider
@@ -118,10 +83,6 @@ export declare class ReactApp<S extends IAppSettings, D extends IUser, P extends
118
83
  * Culture state
119
84
  */
120
85
  readonly cultureState: CultureState;
121
- /**
122
- * Page state
123
- */
124
- readonly pageState: PageState<P>;
125
86
  /**
126
87
  * User state
127
88
  */
@@ -138,10 +99,6 @@ export declare class ReactApp<S extends IAppSettings, D extends IUser, P extends
138
99
  * Navigate function
139
100
  */
140
101
  navigateFunction?: NavigateFunction;
141
- /**
142
- * Page state dispatch
143
- */
144
- pageStateDispatch?: React.Dispatch<PageAction<P>>;
145
102
  /**
146
103
  * User state dispatch
147
104
  */
@@ -205,33 +162,20 @@ export declare class ReactApp<S extends IAppSettings, D extends IUser, P extends
205
162
  * @returns Result
206
163
  */
207
164
  protected tryLoginIgnoreResult(result: IActionResult): boolean;
208
- /**
209
- * Set page data
210
- * @param data Page data
211
- */
212
- setPageData(data: P): void;
213
- /**
214
- * Set page title and subtitle
215
- * @param title Page title
216
- * @param subtitle Page subtitle
217
- */
218
- setPageTitle(title: string, subtitle?: string): void;
219
165
  /**
220
166
  * Navigate to Url or delta
221
167
  * @param url Url or delta
222
168
  * @param options Options
223
169
  */
224
170
  navigate<T extends number | string | URL>(to: T, options?: T extends number ? never : NavigateOptions): void;
225
- /**
226
- * Set page title and data
227
- * @param key Page title resource key
228
- */
229
- setPageKey(key: string): void;
230
171
  /**
231
172
  * Show input dialog
232
173
  * @param props Props
233
174
  */
234
175
  showInputDialog({ title, message, callback, ...rest }: InputDialogProps): INotificationReact;
176
+ stateDetector(props: IStateProps): React.FunctionComponentElement<{
177
+ children?: React.ReactNode | undefined;
178
+ }>;
235
179
  /**
236
180
  * User login extended
237
181
  * @param user New user
@@ -3,8 +3,9 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.ReactApp = exports.globalApp = exports.ReactAppContext = void 0;
7
- exports.ReactAppStateDetector = ReactAppStateDetector;
6
+ exports.ReactApp = exports.ReactAppContext = void 0;
7
+ exports.useAppContext = useAppContext;
8
+ exports.useRequiredAppContext = useRequiredAppContext;
8
9
  const appscript_1 = require("@etsoo/appscript");
9
10
  const notificationbase_1 = require("@etsoo/notificationbase");
10
11
  const shared_1 = require("@etsoo/shared");
@@ -18,41 +19,18 @@ const react_2 = require("@etsoo/react");
18
19
  */
19
20
  exports.ReactAppContext = react_1.default.createContext(null);
20
21
  /**
21
- * React app state detector
22
- * Case 1: undefined, when refresh the whole page
23
- * Case 2: false, unauthorized
24
- * Case 3: true, authorized or considered as authorized (maynot, like token expiry)
25
- * Case 4: property or properties changed
26
- * @param props Props
27
- * @returns Component
22
+ * Get React application context hook
23
+ * @returns React application
28
24
  */
29
- function ReactAppStateDetector(props) {
30
- // Destruct
31
- const { targetFields, update } = props;
32
- // Context
33
- const { state } = exports.globalApp == null
34
- ? {}
35
- : react_1.default.useContext(exports.globalApp.userState.context);
36
- // Ready
37
- react_1.default.useEffect(() => {
38
- // Match fields
39
- const changedFields = state.lastChangedFields;
40
- let matchedFields;
41
- if (targetFields == null || changedFields == null) {
42
- matchedFields = changedFields;
43
- }
44
- else {
45
- matchedFields = [];
46
- targetFields.forEach((targetField) => {
47
- if (changedFields.includes(targetField))
48
- matchedFields?.push(targetField);
49
- });
50
- }
51
- // Callback
52
- update(state.authorized, matchedFields);
53
- }, [state]);
54
- // return
55
- return react_1.default.createElement(react_1.default.Fragment);
25
+ function useAppContext() {
26
+ return react_1.default.useContext(exports.ReactAppContext);
27
+ }
28
+ /**
29
+ * Get React application context hook
30
+ * @returns React application
31
+ */
32
+ function useRequiredAppContext() {
33
+ return (0, react_2.useRequiredContext)(exports.ReactAppContext);
56
34
  }
57
35
  /**
58
36
  * React application
@@ -74,10 +52,6 @@ class ReactApp extends appscript_1.CoreApp {
74
52
  * Culture state
75
53
  */
76
54
  cultureState;
77
- /**
78
- * Page state
79
- */
80
- pageState;
81
55
  /**
82
56
  * User state
83
57
  */
@@ -94,10 +68,6 @@ class ReactApp extends appscript_1.CoreApp {
94
68
  * Navigate function
95
69
  */
96
70
  navigateFunction;
97
- /**
98
- * Page state dispatch
99
- */
100
- pageStateDispatch;
101
71
  /**
102
72
  * User state dispatch
103
73
  */
@@ -116,8 +86,6 @@ class ReactApp extends appscript_1.CoreApp {
116
86
  });
117
87
  }
118
88
  this.cultureState = new react_2.CultureState(settings.currentCulture);
119
- this.pageState = new react_2.PageState();
120
- exports.globalApp = this;
121
89
  }
122
90
  /**
123
91
  * Override alert action result
@@ -283,35 +251,6 @@ class ReactApp extends appscript_1.CoreApp {
283
251
  else
284
252
  return false;
285
253
  }
286
- /**
287
- * Set page data
288
- * @param data Page data
289
- */
290
- setPageData(data) {
291
- // Dispatch the change
292
- if (this.pageStateDispatch != null) {
293
- this.pageStateDispatch({
294
- type: react_2.PageActionType.Data,
295
- data
296
- });
297
- }
298
- }
299
- /**
300
- * Set page title and subtitle
301
- * @param title Page title
302
- * @param subtitle Page subtitle
303
- */
304
- setPageTitle(title, subtitle) {
305
- // Data
306
- const data = { title, subtitle };
307
- // Dispatch the change
308
- if (this.pageStateDispatch != null) {
309
- this.pageStateDispatch({
310
- type: react_2.PageActionType.Title,
311
- data
312
- });
313
- }
314
- }
315
254
  /**
316
255
  * Navigate to Url or delta
317
256
  * @param url Url or delta
@@ -325,13 +264,6 @@ class ReactApp extends appscript_1.CoreApp {
325
264
  else
326
265
  this.navigateFunction(to, options);
327
266
  }
328
- /**
329
- * Set page title and data
330
- * @param key Page title resource key
331
- */
332
- setPageKey(key) {
333
- this.setPageTitle(this.get(key) ?? "");
334
- }
335
267
  /**
336
268
  * Show input dialog
337
269
  * @param props Props
@@ -339,6 +271,32 @@ class ReactApp extends appscript_1.CoreApp {
339
271
  showInputDialog({ title, message, callback, ...rest }) {
340
272
  return this.notifier.prompt(message, callback, title, rest);
341
273
  }
274
+ stateDetector(props) {
275
+ // Destruct
276
+ const { targetFields, update } = props;
277
+ // Context
278
+ const { state } = react_1.default.useContext(this.userState.context);
279
+ // Ready
280
+ react_1.default.useEffect(() => {
281
+ // Match fields
282
+ const changedFields = state.lastChangedFields;
283
+ let matchedFields;
284
+ if (targetFields == null || changedFields == null) {
285
+ matchedFields = changedFields;
286
+ }
287
+ else {
288
+ matchedFields = [];
289
+ targetFields.forEach((targetField) => {
290
+ if (changedFields.includes(targetField))
291
+ matchedFields?.push(targetField);
292
+ });
293
+ }
294
+ // Callback
295
+ update(state.authorized, matchedFields);
296
+ }, [state]);
297
+ // return
298
+ return react_1.default.createElement(react_1.default.Fragment);
299
+ }
342
300
  /**
343
301
  * User login extended
344
302
  * @param user New user
@@ -1,7 +1,6 @@
1
1
  import { ApiRefreshTokenDto, AppLoginParams, AppTryLoginParams, ExternalEndpoint, IApi, IApiPayload } from "@etsoo/appscript";
2
2
  import { IServiceApp } from "./IServiceApp";
3
3
  import { IServiceAppSettings } from "./IServiceAppSettings";
4
- import { IServicePageData } from "./IServicePage";
5
4
  import { IServiceUser, ServiceUserToken } from "./IServiceUser";
6
5
  import { ReactApp } from "./ReactApp";
7
6
  import { IActionResult } from "@etsoo/shared";
@@ -11,7 +10,7 @@ import { IActionResult } from "@etsoo/shared";
11
10
  * Use the acess token to the service api, get a service access token
12
11
  * Use the new acess token and refresh token to login
13
12
  */
14
- export declare class ServiceApp<U extends IServiceUser = IServiceUser, P extends IServicePageData = IServicePageData, S extends IServiceAppSettings = IServiceAppSettings> extends ReactApp<S, U, P> implements IServiceApp {
13
+ export declare class ServiceApp<U extends IServiceUser = IServiceUser, S extends IServiceAppSettings = IServiceAppSettings> extends ReactApp<S, U> implements IServiceApp {
15
14
  /**
16
15
  * Core endpoint
17
16
  */
@@ -8,9 +8,9 @@ const jsx_runtime_1 = require("react/jsx-runtime");
8
8
  const shared_1 = require("@etsoo/shared");
9
9
  const material_1 = require("@mui/material");
10
10
  const react_1 = __importDefault(require("react"));
11
- const ReactApp_1 = require("../app/ReactApp");
12
11
  const MUGlobal_1 = require("../MUGlobal");
13
12
  const CustomFieldUtils_1 = require("./CustomFieldUtils");
13
+ const ReactApp_1 = require("../app/ReactApp");
14
14
  function calculateKeys(data) {
15
15
  let count = 0;
16
16
  for (const key in data) {
@@ -46,11 +46,8 @@ function parseJsonData(jsonData) {
46
46
  * @returns Component
47
47
  */
48
48
  function CustomFieldWindow(props) {
49
- // Validate app
50
- const app = ReactApp_1.globalApp;
51
- if (app == null) {
52
- throw new Error("No globalApp");
53
- }
49
+ // Global app
50
+ const app = (0, ReactApp_1.useRequiredAppContext)();
54
51
  const { children, label = app.get("jsonData"), gridProps, jsonData, inputName = "jsonData", inputRef, onUpdate } = props;
55
52
  const spacing = MUGlobal_1.MUGlobal.half(MUGlobal_1.MUGlobal.pagePaddings);
56
53
  const [count, setCount] = react_1.default.useState(0);
@@ -1,7 +1,6 @@
1
1
  export * from "./app/CommonApp";
2
2
  export * from "./app/IServiceApp";
3
3
  export * from "./app/IServiceAppSettings";
4
- export * from "./app/IServicePage";
5
4
  export * from "./app/IServiceUser";
6
5
  export * from "./app/ISmartERPUser";
7
6
  export * from "./app/Labels";
package/lib/cjs/index.js CHANGED
@@ -17,7 +17,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
17
17
  __exportStar(require("./app/CommonApp"), exports);
18
18
  __exportStar(require("./app/IServiceApp"), exports);
19
19
  __exportStar(require("./app/IServiceAppSettings"), exports);
20
- __exportStar(require("./app/IServicePage"), exports);
21
20
  __exportStar(require("./app/IServiceUser"), exports);
22
21
  __exportStar(require("./app/ISmartERPUser"), exports);
23
22
  __exportStar(require("./app/Labels"), exports);
@@ -20,6 +20,8 @@ const ReactApp_1 = require("../app/ReactApp");
20
20
  * @param props Props
21
21
  */
22
22
  function CommonPage(props) {
23
+ // Global app
24
+ const app = (0, ReactApp_1.useAppContext)();
23
25
  // Destruct
24
26
  const { children, disableGutters = true, fabTop, fabButtons, fabColumnDirection, fabPanel, fabPaddingAdjust = 1.5, fabSize = "small", maxWidth = false, moreActions, onRefresh, onUpdate, onUpdateAll, paddings = MUGlobal_1.MUGlobal.pagePaddings, scrollContainer, supportBack = false, targetFields, sx = {}, ...rest } = props;
25
27
  // Fab padding
@@ -57,7 +59,7 @@ function CommonPage(props) {
57
59
  }
58
60
  }, [update]);
59
61
  // Return the UI
60
- return ((0, jsx_runtime_1.jsxs)(react_1.default.Fragment, { children: [update && ((0, jsx_runtime_1.jsx)(ReactApp_1.ReactAppStateDetector, { targetFields: targetFields, update: update })), (0, jsx_runtime_1.jsxs)(material_1.Container, { disableGutters: disableGutters, maxWidth: maxWidth, sx: sx, id: "page-container", ...rest, children: [(0, jsx_runtime_1.jsxs)(FabBox_1.FabBox, { sx: {
62
+ return ((0, jsx_runtime_1.jsxs)(react_1.default.Fragment, { children: [update && app?.stateDetector({ targetFields, update }), (0, jsx_runtime_1.jsxs)(material_1.Container, { disableGutters: disableGutters, maxWidth: maxWidth, sx: sx, id: "page-container", ...rest, children: [(0, jsx_runtime_1.jsxs)(FabBox_1.FabBox, { sx: {
61
63
  zIndex: 1,
62
64
  ...(typeof fabTop === "function"
63
65
  ? fabTop(theme, fabPadding)
@@ -11,8 +11,10 @@ const ChevronLeft_1 = __importDefault(require("@mui/icons-material/ChevronLeft")
11
11
  const DrawerHeader_1 = require("./DrawerHeader");
12
12
  const ReactApp_1 = require("../app/ReactApp");
13
13
  function LeftDrawer(props) {
14
+ // Global app
15
+ const app = (0, ReactApp_1.useAppContext)();
14
16
  // Destruct
15
- const { mdUp, width, appName = ReactApp_1.globalApp?.get("appName"), logoUrl = "/logo192.png", onMinimize, open = mdUp, children } = props;
17
+ const { mdUp, width, appName = app?.get("appName"), logoUrl = "/logo192.png", onMinimize, open = mdUp, children } = props;
16
18
  // Menu open/close state
17
19
  const [openLocal, setOpen] = react_1.default.useState();
18
20
  const handleDrawerClose = () => {
@@ -33,5 +35,5 @@ function LeftDrawer(props) {
33
35
  }
34
36
  }, anchor: "left", variant: mdUp ? "persistent" : "temporary", open: open, transitionDuration: 0, onClose: mdUp ? undefined : handleDrawerClose, ModalProps: {
35
37
  keepMounted: true // Better open performance on mobile.
36
- }, children: [(0, jsx_runtime_1.jsxs)(DrawerHeader_1.DrawerHeader, { children: [(0, jsx_runtime_1.jsx)("a", { href: "https://www.etsoo.com", title: ReactApp_1.globalApp?.get("etsoo") ?? "ETSOO", target: "_blank", rel: "noreferrer", children: (0, jsx_runtime_1.jsx)(material_1.Avatar, { src: logoUrl, variant: "square", sx: { marginLeft: -0.5, marginRight: 1.5, marginBottom: 1 } }) }), (0, jsx_runtime_1.jsx)(material_1.Typography, { noWrap: true, component: "div", title: appName, sx: { flexGrow: 2 }, children: appName }), (0, jsx_runtime_1.jsx)(material_1.IconButton, { size: "small", onClick: handleDrawerClose, children: (0, jsx_runtime_1.jsx)(ChevronLeft_1.default, {}) })] }), (0, jsx_runtime_1.jsx)(material_1.Divider, {}), (0, jsx_runtime_1.jsx)(material_1.List, { onClick: mdUp ? undefined : handleDrawerClose, children: children })] }));
38
+ }, children: [(0, jsx_runtime_1.jsxs)(DrawerHeader_1.DrawerHeader, { children: [(0, jsx_runtime_1.jsx)("a", { href: "https://www.etsoo.com", title: app?.get("etsoo") ?? "ETSOO", target: "_blank", rel: "noreferrer", children: (0, jsx_runtime_1.jsx)(material_1.Avatar, { src: logoUrl, variant: "square", sx: { marginLeft: -0.5, marginRight: 1.5, marginBottom: 1 } }) }), (0, jsx_runtime_1.jsx)(material_1.Typography, { noWrap: true, component: "div", title: appName, sx: { flexGrow: 2 }, children: appName }), (0, jsx_runtime_1.jsx)(material_1.IconButton, { size: "small", onClick: handleDrawerClose, children: (0, jsx_runtime_1.jsx)(ChevronLeft_1.default, {}) })] }), (0, jsx_runtime_1.jsx)(material_1.Divider, {}), (0, jsx_runtime_1.jsx)(material_1.List, { onClick: mdUp ? undefined : handleDrawerClose, children: children })] }));
37
39
  }
@@ -12,13 +12,13 @@ const shared_1 = require("@etsoo/shared");
12
12
  const material_1 = require("@mui/material");
13
13
  const react_3 = __importDefault(require("react"));
14
14
  const Labels_1 = require("../app/Labels");
15
- const ReactApp_1 = require("../app/ReactApp");
16
15
  const GridDataFormat_1 = require("../GridDataFormat");
17
16
  const MUGlobal_1 = require("../MUGlobal");
18
17
  const PullToRefreshUI_1 = require("../PullToRefreshUI");
19
18
  const CommonPage_1 = require("./CommonPage");
20
19
  const MessageUtils_1 = require("../messages/MessageUtils");
21
20
  const OperationMessageContainer_1 = require("../messages/OperationMessageContainer");
21
+ const ReactApp_1 = require("../app/ReactApp");
22
22
  /**
23
23
  * View page grid item
24
24
  * @param props Props
@@ -38,15 +38,13 @@ function ViewPageGridItem(props) {
38
38
  // Layout
39
39
  return ((0, jsx_runtime_1.jsxs)(material_1.Grid2, { ...gridProps, ...options, children: [label != null && ((0, jsx_runtime_1.jsxs)(material_1.Typography, { variant: "caption", component: "div", children: [label, ":"] })), typeof data === "object" ? (data) : ((0, jsx_runtime_1.jsx)(material_1.Typography, { variant: "subtitle2", children: data }))] }));
40
40
  }
41
- function formatItemData(fieldData) {
41
+ function formatItemData(app, fieldData) {
42
42
  if (fieldData == null)
43
43
  return undefined;
44
44
  if (typeof fieldData === "string")
45
45
  return fieldData;
46
46
  if (fieldData instanceof Date)
47
- return ReactApp_1.globalApp
48
- ? ReactApp_1.globalApp.formatDate(fieldData, "d")
49
- : shared_1.DateUtils.format(fieldData, "d");
47
+ return app.formatDate(fieldData, "d");
50
48
  return `${fieldData}`;
51
49
  }
52
50
  function getResp(singleRow) {
@@ -65,13 +63,13 @@ function getResp(singleRow) {
65
63
  };
66
64
  return { size };
67
65
  }
68
- function getItemField(field, data) {
66
+ function getItemField(app, field, data) {
69
67
  // Item data and label
70
68
  let itemData, itemLabel, gridProps = {};
71
69
  if (Array.isArray(field)) {
72
70
  const [fieldData, fieldType, renderProps, singleRow = "small"] = field;
73
71
  itemData = (0, GridDataFormat_1.GridDataFormat)(data[fieldData], fieldType, renderProps);
74
- itemLabel = ReactApp_1.globalApp?.get(fieldData) ?? fieldData;
72
+ itemLabel = app.get(fieldData) ?? fieldData;
75
73
  gridProps = { ...getResp(singleRow) };
76
74
  }
77
75
  else if (typeof field === "object") {
@@ -85,7 +83,7 @@ function getItemField(field, data) {
85
83
  if (typeof fieldData === "function")
86
84
  itemData = fieldData(data);
87
85
  else if (dataType == null)
88
- itemData = formatItemData(data[fieldData]);
86
+ itemData = formatItemData(app, data[fieldData]);
89
87
  else
90
88
  itemData = (0, GridDataFormat_1.GridDataFormat)(data[fieldData], dataType, renderProps);
91
89
  // Field label
@@ -93,12 +91,12 @@ function getItemField(field, data) {
93
91
  typeof fieldLabel === "function"
94
92
  ? fieldLabel(data)
95
93
  : fieldLabel != null
96
- ? ReactApp_1.globalApp?.get(fieldLabel) ?? fieldLabel
94
+ ? app.get(fieldLabel) ?? fieldLabel
97
95
  : fieldLabel;
98
96
  }
99
97
  else {
100
- itemData = formatItemData(data[field]);
101
- itemLabel = ReactApp_1.globalApp?.get(field) ?? field;
98
+ itemData = formatItemData(app, data[field]);
99
+ itemLabel = app.get(field) ?? field;
102
100
  }
103
101
  return [itemData, itemLabel, gridProps];
104
102
  }
@@ -107,6 +105,8 @@ function getItemField(field, data) {
107
105
  * @param props Props
108
106
  */
109
107
  function ViewPage(props) {
108
+ // Global app
109
+ const app = (0, ReactApp_1.useRequiredAppContext)();
110
110
  // Destruct
111
111
  const { actions, children, fields, loadData, paddings = MUGlobal_1.MUGlobal.pagePaddings, spacing = MUGlobal_1.MUGlobal.half(MUGlobal_1.MUGlobal.pagePaddings), supportRefresh = true, fabColumnDirection = true, fabTop = true, supportBack = true, pullToRefresh = true, gridRef, operationMessageHandler, ...rest } = props;
112
112
  // Data
@@ -118,8 +118,7 @@ function ViewPage(props) {
118
118
  // Load data
119
119
  const refresh = react_3.default.useCallback(async () => {
120
120
  const result = await loadData();
121
- if (result == null)
122
- return;
121
+ // When failed or no data returned, show the loading bar
123
122
  setData(result);
124
123
  }, [loadData]);
125
124
  react_3.default.useEffect(() => {
@@ -147,7 +146,7 @@ function ViewPage(props) {
147
146
  // Most flexible way, do whatever you want
148
147
  return field(data, refresh);
149
148
  }
150
- const [itemData, itemLabel, gridProps] = getItemField(field, data);
149
+ const [itemData, itemLabel, gridProps] = getItemField(app, field, data);
151
150
  // Some callback function may return '' instead of undefined
152
151
  if (itemData == null || itemData === "")
153
152
  return undefined;
@@ -1,9 +1,9 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  import { FormLabel, Grid2 } from "@mui/material";
3
3
  import React from "react";
4
- import { globalApp } from "./app/ReactApp";
5
4
  import { ComboBox } from "./ComboBox";
6
5
  import { Tiplist } from "./Tiplist";
6
+ import { useAppContext } from "./app/ReactApp";
7
7
  /**
8
8
  * Address field
9
9
  */
@@ -19,8 +19,10 @@ export var AddressField;
19
19
  * @param props Props
20
20
  */
21
21
  export function AddressSelector(props) {
22
+ // Global app
23
+ const app = useAppContext();
22
24
  // Labels
23
- const { city: cityDefault = "City", district: districtDefault = "District", region: regionDefault = "Region", state: stateDefault = "State" } = globalApp?.getLabels("region", "state", "city", "district") ?? {};
25
+ const { city: cityDefault = "City", district: districtDefault = "District", region: regionDefault = "Region", state: stateDefault = "State" } = app?.getLabels("region", "state", "city", "district") ?? {};
24
26
  // Destruct
25
27
  const { api, city, cityLabel = cityDefault, district, districtLabel = districtDefault, error, favoredIds, helperText, hideRegion, label, onChange, region, regionLabel = regionDefault, required, search, state, stateLabel = stateDefault, breakPoints = { xs: 12, md: 6, lg: hideRegion ? 4 : 3 } } = props;
26
28
  const isMounted = React.useRef(true);
@@ -2,19 +2,9 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  import { Utils } from "@etsoo/shared";
3
3
  import { Button, Divider, Typography, useTheme } from "@mui/material";
4
4
  import React from "react";
5
- import { globalApp } from "./app/ReactApp";
6
5
  import { ListMoreDisplay } from "./ListMoreDisplay";
7
6
  import { ShowDataComparison } from "./ShowDataComparison";
8
- // Get label
9
- const getLabel = (key) => {
10
- return globalApp?.get(Utils.formatInitial(key)) ?? key;
11
- };
12
- // Format date
13
- const formatDate = (date) => {
14
- if (globalApp)
15
- return globalApp.formatDate(date, "ds");
16
- return date.toUTCString();
17
- };
7
+ import { useAppContext } from "./app/ReactApp";
18
8
  /**
19
9
  * Audit display
20
10
  * @param props Props
@@ -23,6 +13,16 @@ const formatDate = (date) => {
23
13
  export function AuditDisplay(props) {
24
14
  // Theme
25
15
  const theme = useTheme();
16
+ // Global app
17
+ const app = useAppContext();
18
+ // Get label
19
+ const getLabel = (key) => {
20
+ return app?.get(Utils.formatInitial(key)) ?? key;
21
+ };
22
+ // Format date
23
+ const formatDate = (date) => {
24
+ return app?.formatDate(date, "ds") ?? date.toUTCString();
25
+ };
26
26
  // Title
27
27
  var title = getLabel("dataComparison");
28
28
  // Destruct
@@ -3,15 +3,17 @@ import { BridgeUtils } from "@etsoo/appscript";
3
3
  import CloseIcon from "@mui/icons-material/Close";
4
4
  import { Box, IconButton } from "@mui/material";
5
5
  import React from "react";
6
- import { globalApp } from "./app/ReactApp";
6
+ import { useAppContext } from "./app/ReactApp";
7
7
  /**
8
8
  * Bridge close button
9
9
  * @param props Props
10
10
  * @returns Component
11
11
  */
12
12
  export function BridgeCloseButton(props) {
13
+ // Global app
14
+ const app = useAppContext();
13
15
  // Destruct
14
- const { boxProps, onClick, title = globalApp?.get("close") ?? "Close", validate, ...rest } = props;
16
+ const { boxProps, onClick, title = app?.get("close") ?? "Close", validate, ...rest } = props;
15
17
  // Host
16
18
  const host = BridgeUtils.host;
17
19
  if (host == null ||