@etsoo/materialui 1.3.42 → 1.3.44

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 (86) hide show
  1. package/__tests__/NotifierMUTests.tsx +140 -140
  2. package/__tests__/ResponsePage.tsx +48 -0
  3. package/__tests__/SelectEx.tsx +2 -2
  4. package/__tests__/SwitchAnt.tsx +17 -17
  5. package/__tests__/tsconfig.json +17 -17
  6. package/lib/AddresSelector.js +1 -2
  7. package/lib/AuditDisplay.js +2 -3
  8. package/lib/BridgeCloseButton.js +1 -2
  9. package/lib/ComboBox.js +5 -5
  10. package/lib/ComboBoxMultiple.js +7 -8
  11. package/lib/ComboBoxPro.js +1 -2
  12. package/lib/CultureDataTable.js +2 -2
  13. package/lib/DataGridEx.d.ts +2 -3
  14. package/lib/DataGridEx.js +12 -14
  15. package/lib/DataGridRenderers.js +6 -6
  16. package/lib/DataSteps.js +1 -2
  17. package/lib/DataTable.js +1 -2
  18. package/lib/DialogButton.js +2 -3
  19. package/lib/DnDList.js +1 -1
  20. package/lib/EmailInput.js +1 -2
  21. package/lib/FileUploadButton.js +1 -1
  22. package/lib/GridDataFormat.js +5 -5
  23. package/lib/GridUtils.js +1 -2
  24. package/lib/HiSelector.js +1 -1
  25. package/lib/HiSelectorTL.js +1 -1
  26. package/lib/InputField.js +4 -5
  27. package/lib/InputTipField.js +1 -1
  28. package/lib/ItemList.js +2 -3
  29. package/lib/ListChooser.js +4 -5
  30. package/lib/LoadingButton.js +1 -2
  31. package/lib/MaskInput.js +2 -3
  32. package/lib/NotifierMU.js +14 -19
  33. package/lib/OptionBool.js +1 -2
  34. package/lib/OptionGroup.js +3 -4
  35. package/lib/OptionGroupFlag.js +1 -1
  36. package/lib/QuickList.js +2 -2
  37. package/lib/ResponsibleContainer.d.ts +3 -3
  38. package/lib/ResponsibleContainer.js +3 -3
  39. package/lib/ScrollerListEx.d.ts +6 -7
  40. package/lib/ScrollerListEx.js +30 -36
  41. package/lib/SearchField.js +3 -4
  42. package/lib/SelectBool.js +1 -2
  43. package/lib/SelectEx.js +6 -8
  44. package/lib/ShowDataComparison.js +3 -4
  45. package/lib/Switch.js +1 -2
  46. package/lib/SwitchAnt.js +6 -7
  47. package/lib/TableEx.js +5 -7
  48. package/lib/TagList.js +3 -5
  49. package/lib/TagListPro.js +3 -5
  50. package/lib/TextFieldEx.js +2 -2
  51. package/lib/Tiplist.js +6 -8
  52. package/lib/TiplistPro.js +9 -10
  53. package/lib/TooltipClick.js +2 -2
  54. package/lib/TwoFieldInput.js +1 -1
  55. package/lib/UserAvatar.js +1 -2
  56. package/lib/UserAvatarEditor.js +4 -6
  57. package/lib/app/CommonApp.js +1 -1
  58. package/lib/app/ReactApp.js +4 -6
  59. package/lib/app/ServiceApp.js +5 -7
  60. package/lib/pages/DataGridPage.d.ts +2 -2
  61. package/lib/pages/DataGridPage.js +2 -3
  62. package/lib/pages/DataGridPageProps.d.ts +2 -2
  63. package/lib/pages/FixedListPage.d.ts +2 -2
  64. package/lib/pages/FixedListPage.js +2 -3
  65. package/lib/pages/LeftDrawer.js +2 -3
  66. package/lib/pages/ListPage.d.ts +2 -2
  67. package/lib/pages/ListPage.js +2 -3
  68. package/lib/pages/ListPageProps.d.ts +1 -1
  69. package/lib/pages/ResponsivePage.d.ts +2 -2
  70. package/lib/pages/ResponsivePage.js +1 -2
  71. package/lib/pages/ResponsivePageProps.d.ts +2 -2
  72. package/lib/pages/TablePage.js +3 -5
  73. package/lib/pages/UserMenu.js +1 -2
  74. package/lib/pages/ViewPage.js +6 -7
  75. package/package.json +14 -12
  76. package/src/DataGridEx.tsx +6 -12
  77. package/src/ResponsibleContainer.tsx +7 -9
  78. package/src/ScrollerListEx.tsx +301 -311
  79. package/src/pages/DataGridPage.tsx +4 -5
  80. package/src/pages/DataGridPageProps.ts +3 -4
  81. package/src/pages/FixedListPage.tsx +4 -5
  82. package/src/pages/ListPage.tsx +4 -5
  83. package/src/pages/ListPageProps.ts +2 -3
  84. package/src/pages/ResponsivePage.tsx +4 -5
  85. package/src/pages/ResponsivePageProps.ts +3 -4
  86. package/tsconfig.json +3 -3
@@ -1,11 +1,11 @@
1
1
  import {
2
- INotification,
3
- NotificationMessageType
4
- } from '@etsoo/notificationbase';
5
- import React from 'react';
6
- import { createRoot } from 'react-dom/client';
7
- import { act } from 'react-dom/test-utils';
8
- import { NotifierMU } from '../src';
2
+ INotification,
3
+ NotificationMessageType
4
+ } from "@etsoo/notificationbase";
5
+ import React from "react";
6
+ import { createRoot } from "react-dom/client";
7
+ import { act } from "react-dom/test-utils";
8
+ import { NotifierMU } from "../src";
9
9
 
10
10
  // Without it will popup error:
11
11
  // The current testing environment is not configured to support act
@@ -13,7 +13,7 @@ import { NotifierMU } from '../src';
13
13
 
14
14
  // Root
15
15
  const root = document.body;
16
- const container: HTMLElement = document.createElement('div');
16
+ const container: HTMLElement = document.createElement("div");
17
17
  root.append(container);
18
18
 
19
19
  // The state provider
@@ -21,8 +21,8 @@ const Provider = NotifierMU.setup();
21
21
  const reactRoot = createRoot(container);
22
22
 
23
23
  act(() => {
24
- // Concorrent renderer needs act block
25
- reactRoot.render(<Provider />);
24
+ // Concorrent renderer needs act block
25
+ reactRoot.render(<Provider />);
26
26
  });
27
27
 
28
28
  // Notifier
@@ -32,186 +32,186 @@ const notifier = NotifierMU.instance;
32
32
  // https://jestjs.io/docs/en/timer-mocks
33
33
  jest.useFakeTimers();
34
34
 
35
- test('Alert tests', async () => {
36
- // Click
37
- const handleClick = jest.fn();
35
+ test("Alert tests", async () => {
36
+ // Click
37
+ const handleClick = jest.fn();
38
38
 
39
- act(() => {
40
- // Add the notification
41
- notifier.alert('Alert message', handleClick);
42
- });
39
+ act(() => {
40
+ // Add the notification
41
+ notifier.alert("Alert message", handleClick);
42
+ });
43
43
 
44
- // Button
45
- const button = root.getElementsByTagName('button');
44
+ // Button
45
+ const button = root.getElementsByTagName("button");
46
46
 
47
- expect(button.length).toBe(1);
48
- expect(button[0].innerHTML).toContain('OK');
47
+ expect(button.length).toBe(1);
48
+ expect(button[0].innerHTML).toContain("OK");
49
49
 
50
- await act(async () => {
51
- button[0].click();
52
- });
50
+ await act(async () => {
51
+ button[0].click();
52
+ });
53
53
 
54
- expect(handleClick).toBeCalled();
54
+ expect(handleClick).toHaveBeenCalled();
55
55
 
56
- // Fast forward
57
- jest.runOnlyPendingTimers();
56
+ // Fast forward
57
+ jest.runOnlyPendingTimers();
58
58
  });
59
59
 
60
- test('Confirm tests', async () => {
61
- // Click
62
- const handleClick = jest.fn();
60
+ test("Confirm tests", async () => {
61
+ // Click
62
+ const handleClick = jest.fn();
63
63
 
64
- act(() => {
65
- // Add the notification
66
- notifier.confirm('Confirm message', undefined, handleClick);
67
- });
64
+ act(() => {
65
+ // Add the notification
66
+ notifier.confirm("Confirm message", undefined, handleClick);
67
+ });
68
68
 
69
- // Button
70
- const button = root.getElementsByTagName('button');
69
+ // Button
70
+ const button = root.getElementsByTagName("button");
71
71
 
72
- expect(button.length).toBe(2);
73
- expect(button[0].innerHTML).toContain('Cancel');
72
+ expect(button.length).toBe(2);
73
+ expect(button[0].innerHTML).toContain("Cancel");
74
74
 
75
- await act(async () => {
76
- button[0].click();
77
- });
75
+ await act(async () => {
76
+ button[0].click();
77
+ });
78
78
 
79
- expect(handleClick).toBeCalled();
79
+ expect(handleClick).toHaveBeenCalled();
80
80
 
81
- // Fast forward
82
- jest.runOnlyPendingTimers();
81
+ // Fast forward
82
+ jest.runOnlyPendingTimers();
83
83
  });
84
84
 
85
- test('Confirm tests without cancel button', async () => {
86
- // Click
87
- const handleClick = jest.fn();
85
+ test("Confirm tests without cancel button", async () => {
86
+ // Click
87
+ const handleClick = jest.fn();
88
88
 
89
- act(() => {
90
- // Add the notification
91
- notifier.confirm('Confirm message', undefined, handleClick, {
92
- cancelButton: false
93
- });
89
+ act(() => {
90
+ // Add the notification
91
+ notifier.confirm("Confirm message", undefined, handleClick, {
92
+ cancelButton: false
94
93
  });
94
+ });
95
95
 
96
- // Button
97
- const button = root.getElementsByTagName('button');
96
+ // Button
97
+ const button = root.getElementsByTagName("button");
98
98
 
99
- expect(button.length).toBe(1);
100
- expect(button[0].innerHTML).toContain('OK');
99
+ expect(button.length).toBe(1);
100
+ expect(button[0].innerHTML).toContain("OK");
101
101
 
102
- await act(async () => {
103
- button[0].click();
104
- });
102
+ await act(async () => {
103
+ button[0].click();
104
+ });
105
105
 
106
- expect(handleClick).toBeCalled();
106
+ expect(handleClick).toHaveBeenCalled();
107
107
 
108
- // Fast forward
109
- jest.runOnlyPendingTimers();
108
+ // Fast forward
109
+ jest.runOnlyPendingTimers();
110
110
  });
111
111
 
112
- test('Prompt tests', async () => {
113
- // Click
114
- const handleClick = jest.fn((result: boolean) => {
115
- expect(result).toBeTruthy();
116
- });
112
+ test("Prompt tests", async () => {
113
+ // Click
114
+ const handleClick = jest.fn((result: boolean) => {
115
+ expect(result).toBeTruthy();
116
+ });
117
117
 
118
- act(() => {
119
- // Add the notification
120
- notifier.prompt<boolean>('Prompt message', handleClick, undefined, {
121
- type: 'switch',
122
- inputProps: { required: false }
123
- });
118
+ act(() => {
119
+ // Add the notification
120
+ notifier.prompt<boolean>("Prompt message", handleClick, undefined, {
121
+ type: "switch",
122
+ inputProps: { required: false }
124
123
  });
124
+ });
125
125
 
126
- // Button
127
- const button = root.getElementsByTagName('button');
126
+ // Button
127
+ const button = root.getElementsByTagName("button");
128
128
 
129
- expect(button.length).toBe(2); // Switch will generate a button
130
- expect(button[1].innerHTML).toContain('OK');
129
+ expect(button.length).toBe(2); // Switch will generate a button
130
+ expect(button[1].innerHTML).toContain("OK");
131
131
 
132
- await act(async () => {
133
- button[1].click();
134
- });
132
+ await act(async () => {
133
+ button[1].click();
134
+ });
135
135
 
136
- expect(handleClick).toBeCalled();
136
+ expect(handleClick).toHaveBeenCalled();
137
137
 
138
- jest.runOnlyPendingTimers();
138
+ jest.runOnlyPendingTimers();
139
139
  });
140
140
 
141
- test('Prompt tests with form submit', async () => {
142
- // Click
143
- const handleClick = jest.fn((result: boolean) => {
144
- expect(result).toBeTruthy();
145
- });
141
+ test("Prompt tests with form submit", async () => {
142
+ // Click
143
+ const handleClick = jest.fn((result: boolean) => {
144
+ expect(result).toBeTruthy();
145
+ });
146
146
 
147
- act(() => {
148
- // Add the notification
149
- notifier.prompt<boolean>('Prompt message', handleClick, undefined, {
150
- type: 'switch',
151
- inputProps: { required: false }
152
- });
147
+ act(() => {
148
+ // Add the notification
149
+ notifier.prompt<boolean>("Prompt message", handleClick, undefined, {
150
+ type: "switch",
151
+ inputProps: { required: false }
153
152
  });
153
+ });
154
154
 
155
- await act(async () => {
156
- (
157
- root
158
- .getElementsByTagName('form')[0]
159
- .elements.namedItem('okButton') as HTMLButtonElement
160
- )?.click();
161
- });
155
+ await act(async () => {
156
+ (
157
+ root
158
+ .getElementsByTagName("form")[0]
159
+ .elements.namedItem("okButton") as HTMLButtonElement
160
+ )?.click();
161
+ });
162
162
 
163
- expect(handleClick).toBeCalled();
163
+ expect(handleClick).toHaveBeenCalled();
164
164
 
165
- jest.runOnlyPendingTimers();
165
+ jest.runOnlyPendingTimers();
166
166
  });
167
167
 
168
- test('Message tests', (done) => {
169
- // Callback
170
- const callback = jest.fn(() => done());
171
-
172
- let n: INotification<React.ReactNode, any> | undefined;
173
- act(() => {
174
- // Add the notification
175
- n = notifier.message(
176
- NotificationMessageType.Danger,
177
- 'Error Message',
178
- undefined,
179
- {
180
- callback
181
- }
182
- );
183
- });
168
+ test("Message tests", (done) => {
169
+ // Callback
170
+ const callback = jest.fn(() => done());
184
171
 
185
- expect(n?.timespan).toBe(5);
172
+ let n: INotification<React.ReactNode, any> | undefined;
173
+ act(() => {
174
+ // Add the notification
175
+ n = notifier.message(
176
+ NotificationMessageType.Danger,
177
+ "Error Message",
178
+ undefined,
179
+ {
180
+ callback
181
+ }
182
+ );
183
+ });
186
184
 
187
- expect(root.innerHTML).toContain('Error Message');
185
+ expect(n?.timespan).toBe(5);
188
186
 
189
- act(() => {
190
- // Here is the bug need further study...
191
- n?.dismiss();
187
+ expect(root.innerHTML).toContain("Error Message");
192
188
 
193
- // Fast forward
194
- jest.runOnlyPendingTimers();
195
- });
189
+ act(() => {
190
+ // Here is the bug need further study...
191
+ n?.dismiss();
196
192
 
197
- expect(root.innerHTML).not.toContain('Error Message');
198
- expect(callback).toBeCalled();
193
+ // Fast forward
194
+ jest.runOnlyPendingTimers();
195
+ });
196
+
197
+ expect(root.innerHTML).not.toContain("Error Message");
198
+ expect(callback).toHaveBeenCalled();
199
199
  });
200
200
 
201
- test('Loading tests', () => {
202
- act(() => {
203
- // Add the notification
204
- notifier.showLoading('Loading');
205
- });
201
+ test("Loading tests", () => {
202
+ act(() => {
203
+ // Add the notification
204
+ notifier.showLoading("Loading");
205
+ });
206
206
 
207
- expect(root.innerHTML).toContain('Loading');
207
+ expect(root.innerHTML).toContain("Loading");
208
208
 
209
- act(() => {
210
- notifier.hideLoading();
209
+ act(() => {
210
+ notifier.hideLoading();
211
211
 
212
- // Fast forward
213
- jest.runOnlyPendingTimers();
214
- });
212
+ // Fast forward
213
+ jest.runOnlyPendingTimers();
214
+ });
215
215
 
216
- expect(root.innerHTML).not.toContain('Loading');
216
+ expect(root.innerHTML).not.toContain("Loading");
217
217
  });
@@ -0,0 +1,48 @@
1
+ import { act, render } from "@testing-library/react";
2
+ import { MUGlobal, MobileListItemRenderer, ResponsivePage } from "../src";
3
+ import React from "react";
4
+
5
+ global.ResizeObserver = jest.fn().mockImplementation(() => ({
6
+ observe: jest.fn(),
7
+ unobserve: jest.fn(),
8
+ disconnect: jest.fn()
9
+ }));
10
+
11
+ type Data = { id: number; name: string };
12
+
13
+ // Timer mock
14
+ // https://jestjs.io/docs/en/timer-mocks
15
+ jest.useFakeTimers();
16
+
17
+ it("Render ResponsePage", async () => {
18
+ // Act
19
+ render(
20
+ <ResponsivePage<Data>
21
+ fields={[]}
22
+ columns={[
23
+ { field: "id", header: "ID" },
24
+ { field: "name", header: "Name" }
25
+ ]}
26
+ itemSize={[118, MUGlobal.pagePaddings]}
27
+ loadData={(_data) =>
28
+ Promise.resolve([
29
+ { id: 1, name: "Name 1" },
30
+ { id: 2, name: "Name 2" }
31
+ ])
32
+ }
33
+ innerItemRenderer={(props) =>
34
+ MobileListItemRenderer(props, (data) => {
35
+ return [data.name, undefined, [], <React.Fragment></React.Fragment>];
36
+ })
37
+ }
38
+ />
39
+ );
40
+
41
+ act(() => {
42
+ // Fast forward
43
+ jest.runOnlyPendingTimers();
44
+ });
45
+
46
+ // Assert
47
+ expect(document.getElementById("page-container")).not.toBeNull();
48
+ });
@@ -31,7 +31,7 @@ it("Render SelectEx", async () => {
31
31
  />
32
32
  );
33
33
 
34
- expect(itemChangeCallback).toBeCalled();
34
+ expect(itemChangeCallback).toHaveBeenCalled();
35
35
 
36
36
  // Act, click to show the list
37
37
  const button = screen.getByRole("combobox");
@@ -110,5 +110,5 @@ it("Render multiple SelectEx", async () => {
110
110
 
111
111
  expect(checkbox3?.checked).toBeTruthy();
112
112
 
113
- expect(itemChangeCallback).toBeCalledTimes(2);
113
+ expect(itemChangeCallback).toHaveBeenCalledTimes(2);
114
114
  });
@@ -1,23 +1,23 @@
1
- import { getByText, render } from '@testing-library/react';
2
- import React from 'react';
3
- import { act } from 'react-dom/test-utils';
4
- import { SwitchAnt } from '../src/SwitchAnt';
1
+ import { getByText, render } from "@testing-library/react";
2
+ import React from "react";
3
+ import { act } from "react-dom/test-utils";
4
+ import { SwitchAnt } from "../src/SwitchAnt";
5
5
 
6
- it('SwitchAnt Tests', () => {
7
- const onChange = jest.fn((event: React.ChangeEvent<HTMLInputElement>) =>
8
- expect(event.target.checked).toBeTruthy()
9
- );
6
+ it("SwitchAnt Tests", () => {
7
+ const onChange = jest.fn((event: React.ChangeEvent<HTMLInputElement>) =>
8
+ expect(event.target.checked).toBeTruthy()
9
+ );
10
10
 
11
- // Render component
12
- const { baseElement } = render(
13
- <SwitchAnt startLabel="No" endLabel="Yes" onChange={onChange} />
14
- );
11
+ // Render component
12
+ const { baseElement } = render(
13
+ <SwitchAnt startLabel="No" endLabel="Yes" onChange={onChange} />
14
+ );
15
15
 
16
- const yes = getByText(baseElement, 'Yes');
16
+ const yes = getByText(baseElement, "Yes");
17
17
 
18
- act(() => {
19
- yes.click();
20
- });
18
+ act(() => {
19
+ yes.click();
20
+ });
21
21
 
22
- expect(onChange).toBeCalled();
22
+ expect(onChange).toHaveBeenCalled();
23
23
  });
@@ -1,19 +1,19 @@
1
1
  {
2
- "compilerOptions": {
3
- "target": "ES2019",
4
- "module": "ESNext",
5
- "allowJs": true,
6
- "skipLibCheck": true,
7
- "esModuleInterop": true,
8
- "allowSyntheticDefaultImports": true,
9
- "strict": true,
10
- "forceConsistentCasingInFileNames": true,
11
- "moduleResolution": "node",
12
- "resolveJsonModule": true,
13
- "isolatedModules": true,
14
- "noEmit": true,
15
- "jsx": "react",
16
- "declaration": true
17
- },
18
- "include": [".."]
2
+ "compilerOptions": {
3
+ "target": "ES2020",
4
+ "module": "ESNext",
5
+ "moduleResolution": "Node10",
6
+ "allowJs": false,
7
+ "skipLibCheck": true,
8
+ "esModuleInterop": true,
9
+ "allowSyntheticDefaultImports": true,
10
+ "strict": true,
11
+ "forceConsistentCasingInFileNames": true,
12
+ "resolveJsonModule": true,
13
+ "isolatedModules": true,
14
+ "noEmit": true,
15
+ "jsx": "react",
16
+ "declaration": true
17
+ },
18
+ "include": [".."]
19
19
  }
@@ -18,9 +18,8 @@ export var AddressField;
18
18
  * @param props Props
19
19
  */
20
20
  export function AddressSelector(props) {
21
- var _a;
22
21
  // Labels
23
- const { city: cityDefault = "City", district: districtDefault = "District", region: regionDefault = "Region", state: stateDefault = "State" } = (_a = globalApp === null || globalApp === void 0 ? void 0 : globalApp.getLabels("region", "state", "city", "district")) !== null && _a !== void 0 ? _a : {};
22
+ const { city: cityDefault = "City", district: districtDefault = "District", region: regionDefault = "Region", state: stateDefault = "State" } = globalApp?.getLabels("region", "state", "city", "district") ?? {};
24
23
  // Destruct
25
24
  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
25
  const isMounted = React.useRef(true);
@@ -6,8 +6,7 @@ import { ListMoreDisplay } from "./ListMoreDisplay";
6
6
  import { ShowDataComparison } from "./ShowDataComparison";
7
7
  // Get label
8
8
  const getLabel = (key) => {
9
- var _a;
10
- return (_a = globalApp === null || globalApp === void 0 ? void 0 : globalApp.get(Utils.formatInitial(key))) !== null && _a !== void 0 ? _a : key;
9
+ return globalApp?.get(Utils.formatInitial(key)) ?? key;
11
10
  };
12
11
  // Format date
13
12
  const formatDate = (date) => {
@@ -30,7 +29,7 @@ export function AuditDisplay(props) {
30
29
  padding: [theme.spacing(1.5), theme.spacing(1)].join(" "),
31
30
  background: index % 2 === 0 ? theme.palette.grey[100] : theme.palette.grey[50]
32
31
  }), getColumnLabel, equalCheck, itemRenderer = (data) => {
33
- const { newData, oldData, changes = { newData: newData !== null && newData !== void 0 ? newData : {}, oldData: oldData !== null && oldData !== void 0 ? oldData : {} } } = data;
32
+ const { newData, oldData, changes = { newData: newData ?? {}, oldData: oldData ?? {} } } = data;
34
33
  return (React.createElement(React.Fragment, null,
35
34
  changes != null && (React.createElement(Button, { variant: "outlined", size: "small", onClick: () => ShowDataComparison(changes, title, getColumnLabel, equalCheck), sx: {
36
35
  marginLeft: theme.spacing(1),
@@ -9,9 +9,8 @@ import { globalApp } from "./app/ReactApp";
9
9
  * @returns Component
10
10
  */
11
11
  export function BridgeCloseButton(props) {
12
- var _a;
13
12
  // Destruct
14
- const { boxProps, onClick, title = (_a = globalApp === null || globalApp === void 0 ? void 0 : globalApp.get("close")) !== null && _a !== void 0 ? _a : "Close", validate, ...rest } = props;
13
+ const { boxProps, onClick, title = globalApp?.get("close") ?? "Close", validate, ...rest } = props;
15
14
  // Host
16
15
  const host = BridgeUtils.host;
17
16
  if (host == null ||
package/lib/ComboBox.js CHANGED
@@ -14,13 +14,13 @@ import { globalApp } from "./app/ReactApp";
14
14
  */
15
15
  export function ComboBox(props) {
16
16
  // Labels
17
- const labels = globalApp === null || globalApp === void 0 ? void 0 : globalApp.getLabels("noOptions", "loading", "open", "add");
17
+ const labels = globalApp?.getLabels("noOptions", "loading", "open", "add");
18
18
  // Destruct
19
- const { search = false, autoAddBlankItem = search, idField = "id", idValue, inputError, inputHelperText, inputMargin, inputOnChange, inputRequired, inputReset, inputVariant, defaultValue, label, labelField = "label", loadData, onLoadData, name, inputAutoComplete = "off", options, dataReadonly = true, readOnly, onChange, onValueChange, openOnFocus = true, value, disableCloseOnSelect = false, getOptionLabel = (option) => `${option[labelField]}`, sx = { minWidth: "150px", flexGrow: 2 }, noOptionsText = labels === null || labels === void 0 ? void 0 : labels.noOptions, loadingText = labels === null || labels === void 0 ? void 0 : labels.loading, openText = labels === null || labels === void 0 ? void 0 : labels.open, addLabel = labels === null || labels === void 0 ? void 0 : labels.add, onAdd, ...rest } = props;
19
+ const { search = false, autoAddBlankItem = search, idField = "id", idValue, inputError, inputHelperText, inputMargin, inputOnChange, inputRequired, inputReset, inputVariant, defaultValue, label, labelField = "label", loadData, onLoadData, name, inputAutoComplete = "off", options, dataReadonly = true, readOnly, onChange, onValueChange, openOnFocus = true, value, disableCloseOnSelect = false, getOptionLabel = (option) => `${option[labelField]}`, sx = { minWidth: "150px", flexGrow: 2 }, noOptionsText = labels?.noOptions, loadingText = labels?.loading, openText = labels?.open, addLabel = labels?.add, onAdd, ...rest } = props;
20
20
  // Value input ref
21
21
  const inputRef = React.createRef();
22
22
  // Options state
23
- const [localOptions, setOptions] = React.useState(options !== null && options !== void 0 ? options : []);
23
+ const [localOptions, setOptions] = React.useState(options ?? []);
24
24
  const isMounted = React.useRef(true);
25
25
  // When options change
26
26
  // [options] will cause infinite loop
@@ -37,7 +37,7 @@ export function ComboBox(props) {
37
37
  // Local default value
38
38
  const localValue = idValue != null
39
39
  ? localOptions.find((o) => o[idField] === idValue)
40
- : defaultValue !== null && defaultValue !== void 0 ? defaultValue : value;
40
+ : defaultValue ?? value;
41
41
  // State
42
42
  // null for controlled
43
43
  const [stateValue, setStateValue] = React.useState(null);
@@ -113,7 +113,7 @@ export function ComboBox(props) {
113
113
  }, []);
114
114
  // Layout
115
115
  return (React.createElement("div", null,
116
- React.createElement("input", { ref: inputRef, "data-reset": inputReset !== null && inputReset !== void 0 ? inputReset : true, type: "text", style: { display: "none" }, name: name, value: getValue(stateValue), readOnly: true, onChange: inputOnChange }),
116
+ React.createElement("input", { ref: inputRef, "data-reset": inputReset ?? true, type: "text", style: { display: "none" }, name: name, value: getValue(stateValue), readOnly: true, onChange: inputOnChange }),
117
117
  React.createElement(Stack, { gap: 0.5, direction: "row", width: "100%" },
118
118
  React.createElement(Autocomplete, { value: stateValue, disableCloseOnSelect: disableCloseOnSelect, getOptionLabel: getOptionLabel, isOptionEqualToValue: (option, value) => option[idField] === value[idField], onChange: (event, value, reason, details) => {
119
119
  // Set value
@@ -16,30 +16,29 @@ const checkedIcon = React.createElement(CheckBoxIcon, { fontSize: "small" });
16
16
  * @returns Component
17
17
  */
18
18
  export function ComboBoxMultiple(props) {
19
- var _a;
20
19
  // Labels
21
- const labels = globalApp === null || globalApp === void 0 ? void 0 : globalApp.getLabels("noOptions", "loading");
20
+ const labels = globalApp?.getLabels("noOptions", "loading");
22
21
  // Destruct
23
22
  const { search = false, autoAddBlankItem = search, idField = "id", idValue, idValues, inputError, inputHelperText, inputMargin, inputOnChange, inputRequired, inputReset, inputVariant, defaultValue, label, labelField = "label", loadData, onLoadData, name, inputAutoComplete = "off", options, dataReadonly = true, readOnly, onChange, openOnFocus = true, value, disableCloseOnSelect = true, renderOption = (props, option, { selected }) => (React.createElement("li", { ...props },
24
23
  React.createElement(React.Fragment, null,
25
24
  React.createElement(Checkbox, { icon: icon, checkedIcon: checkedIcon, style: { marginRight: 8 }, checked: selected }),
26
- option[labelField]))), getOptionLabel = (option) => `${option[labelField]}`, sx = { minWidth: "150px" }, noOptionsText = labels === null || labels === void 0 ? void 0 : labels.noOptions, loadingText = labels === null || labels === void 0 ? void 0 : labels.loading, ...rest } = props;
25
+ option[labelField]))), getOptionLabel = (option) => `${option[labelField]}`, sx = { minWidth: "150px" }, noOptionsText = labels?.noOptions, loadingText = labels?.loading, ...rest } = props;
27
26
  // Value input ref
28
27
  const inputRef = React.createRef();
29
28
  // Options state
30
- const [localOptions, setOptions] = React.useState(options !== null && options !== void 0 ? options : []);
29
+ const [localOptions, setOptions] = React.useState(options ?? []);
31
30
  const isMounted = React.useRef(true);
32
31
  // Local default value
33
32
  const localValue = idValue != null
34
33
  ? localOptions.filter((o) => o[idField] === idValue)
35
34
  : idValues != null
36
- ? localOptions.filter((o) => idValues === null || idValues === void 0 ? void 0 : idValues.includes(o[idField]))
37
- : (_a = defaultValue === null || defaultValue === void 0 ? void 0 : defaultValue.concat()) !== null && _a !== void 0 ? _a : value === null || value === void 0 ? void 0 : value.concat();
35
+ ? localOptions.filter((o) => idValues?.includes(o[idField]))
36
+ : defaultValue?.concat() ?? value?.concat();
38
37
  // State
39
38
  // null for controlled
40
39
  const [stateValue, setStateValue] = React.useState(null);
41
40
  React.useEffect(() => {
42
- setStateValue(localValue !== null && localValue !== void 0 ? localValue : []);
41
+ setStateValue(localValue ?? []);
43
42
  }, [localValue]);
44
43
  // When options change
45
44
  // [options] will cause infinite loop
@@ -116,7 +115,7 @@ export function ComboBoxMultiple(props) {
116
115
  }, []);
117
116
  // Layout
118
117
  return (React.createElement("div", null,
119
- React.createElement("input", { ref: inputRef, "data-reset": inputReset !== null && inputReset !== void 0 ? inputReset : true, type: "text", style: { display: "none" }, name: name, value: getValue(stateValue), readOnly: true, onChange: inputOnChange }),
118
+ React.createElement("input", { ref: inputRef, "data-reset": inputReset ?? true, type: "text", style: { display: "none" }, name: name, value: getValue(stateValue), readOnly: true, onChange: inputOnChange }),
120
119
  React.createElement(Autocomplete, { value: stateValue == null
121
120
  ? []
122
121
  : Array.isArray(stateValue)
@@ -4,9 +4,8 @@ import { globalApp } from "./app/ReactApp";
4
4
  import { InputField } from "./InputField";
5
5
  import { DataTypes } from "@etsoo/shared";
6
6
  export function ComboBoxPro(props) {
7
- var _a;
8
7
  // Labels
9
- const { noOptions, loading: loadingLabel, open: openDefault } = (_a = globalApp === null || globalApp === void 0 ? void 0 : globalApp.getLabels("noOptions", "loading", "open")) !== null && _a !== void 0 ? _a : {};
8
+ const { noOptions, loading: loadingLabel, open: openDefault } = globalApp?.getLabels("noOptions", "loading", "open") ?? {};
10
9
  // Destruct
11
10
  const { noOptionsText = noOptions, loadingText = loadingLabel, openText = openDefault, options, openOnFocus = true, label, inputProps, name, value, idValue, onChange, onValueChange, ...rest } = props;
12
11
  const [open, setOpen] = React.useState(false);