@etsoo/materialui 1.6.20 → 1.6.22

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.
@@ -44,7 +44,10 @@ function InputItemUIs({ data }) {
44
44
  return ((0, jsx_runtime_1.jsxs)(Grid_1.default, { container: true, spacing: 2, marginTop: 1, children: [(0, jsx_runtime_1.jsx)(Grid_1.default, { size: { xs: 12, sm: 6 }, children: (0, jsx_runtime_1.jsx)(ComboBox_1.ComboBox, { name: "type", label: labels.type, inputRequired: true, size: "small", loadData: () => Promise.resolve(types.map((t) => ({ id: t, label: t }))), onValueChange: (item) => {
45
45
  const type = item?.id;
46
46
  optionsRef.current.disabled =
47
- type !== "combobox" && type !== "select";
47
+ type !== "combobox" &&
48
+ type !== "select" &&
49
+ type !== "checkbox" &&
50
+ type !== "radio";
48
51
  const nameInput = nameRef.current;
49
52
  if (nameInput.value === "" &&
50
53
  (type === "amountlabel" || type === "divider" || type === "label")) {
@@ -1,4 +1,5 @@
1
- import { CustomFieldData } from "@etsoo/appscript";
1
+ import { CustomFieldData, CustomFieldRef } from "@etsoo/appscript";
2
+ import React from "react";
2
3
  /**
3
4
  * CustomFieldUI component props
4
5
  */
@@ -7,6 +8,10 @@ export type CustomFieldUIProps<D extends CustomFieldData = CustomFieldData> = {
7
8
  * Custom fields
8
9
  */
9
10
  fields: D[];
11
+ /**
12
+ * Initial value
13
+ */
14
+ initialValue?: Record<string, unknown>;
10
15
  /**
11
16
  * Change event
12
17
  * @param data Current data collection
@@ -15,9 +20,9 @@ export type CustomFieldUIProps<D extends CustomFieldData = CustomFieldData> = {
15
20
  */
16
21
  onChange?: (data: Record<string, unknown>, name: string, value: unknown) => void;
17
22
  /**
18
- * Initial value
23
+ * Methods reference
19
24
  */
20
- value?: Record<string, unknown>;
25
+ mref: React.Ref<CustomFieldRef<Record<string, unknown>>>;
21
26
  };
22
27
  /**
23
28
  * CustomFieldUI component
@@ -1,7 +1,12 @@
1
1
  "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
2
5
  Object.defineProperty(exports, "__esModule", { value: true });
3
6
  exports.CustomFieldUI = CustomFieldUI;
7
+ const react_1 = __importDefault(require("react"));
4
8
  const CustomFieldUtils_1 = require("./CustomFieldUtils");
9
+ const ReactApp_1 = require("../app/ReactApp");
5
10
  /**
6
11
  * CustomFieldUI component
7
12
  * @param props Props
@@ -9,14 +14,30 @@ const CustomFieldUtils_1 = require("./CustomFieldUtils");
9
14
  */
10
15
  function CustomFieldUI(props) {
11
16
  // Destruct
12
- const { fields, onChange, value = {} } = props;
17
+ const { fields, initialValue, mref, onChange } = props;
18
+ // App
19
+ const app = (0, ReactApp_1.useAppContext)();
20
+ // Field component collections
21
+ const collections = {};
22
+ // Value reference
23
+ const valueRef = react_1.default.useRef({ ...initialValue });
24
+ // Methods
25
+ react_1.default.useImperativeHandle(mref, () => ({
26
+ getValue: () => valueRef.current,
27
+ setValue: (value) => {
28
+ if (!!value && typeof value === "object") {
29
+ valueRef.current = { ...value };
30
+ CustomFieldUtils_1.CustomFieldUtils.updateValues(collections, valueRef.current);
31
+ }
32
+ }
33
+ }), []);
13
34
  // Layout
14
- return CustomFieldUtils_1.CustomFieldUtils.create(fields, {}, (field) => {
35
+ return CustomFieldUtils_1.CustomFieldUtils.create(fields, collections, (field) => {
15
36
  if (!field.name)
16
37
  return undefined;
17
- return value[field.name];
38
+ return valueRef.current[field.name];
18
39
  }, (name, fieldValue) => {
19
- value[name] = fieldValue;
20
- onChange?.(value, name, fieldValue);
21
- });
40
+ valueRef.current[name] = fieldValue;
41
+ onChange?.(valueRef.current, name, fieldValue);
42
+ }, (input) => app?.get(input) ?? input);
22
43
  }
@@ -53,4 +53,10 @@ export declare namespace CustomFieldUtils {
53
53
  * @param globalCallback Global callback
54
54
  */
55
55
  function updateProperties(input: object, globalCallback: (input: string) => string): void;
56
+ /**
57
+ * Update values for all fields
58
+ * @param collections Field component collections
59
+ * @param value New value
60
+ */
61
+ function updateValues<D extends CustomFieldData = CustomFieldData>(collections: CustomFieldReactCollection<D>, value: Record<string, unknown>): void;
56
62
  }
@@ -150,4 +150,21 @@ var CustomFieldUtils;
150
150
  }
151
151
  }
152
152
  CustomFieldUtils.updateProperties = updateProperties;
153
+ /**
154
+ * Update values for all fields
155
+ * @param collections Field component collections
156
+ * @param value New value
157
+ */
158
+ function updateValues(collections, value) {
159
+ for (const key in collections) {
160
+ const c = collections[key];
161
+ if (c == null)
162
+ continue;
163
+ const [ref, data] = c;
164
+ if (ref.current == null || !data.name)
165
+ continue;
166
+ ref.current.setValue(value[data.name]);
167
+ }
168
+ }
169
+ CustomFieldUtils.updateValues = updateValues;
153
170
  })(CustomFieldUtils || (exports.CustomFieldUtils = CustomFieldUtils = {}));
@@ -38,7 +38,10 @@ function InputItemUIs({ data }) {
38
38
  return (_jsxs(Grid, { container: true, spacing: 2, marginTop: 1, children: [_jsx(Grid, { size: { xs: 12, sm: 6 }, children: _jsx(ComboBox, { name: "type", label: labels.type, inputRequired: true, size: "small", loadData: () => Promise.resolve(types.map((t) => ({ id: t, label: t }))), onValueChange: (item) => {
39
39
  const type = item?.id;
40
40
  optionsRef.current.disabled =
41
- type !== "combobox" && type !== "select";
41
+ type !== "combobox" &&
42
+ type !== "select" &&
43
+ type !== "checkbox" &&
44
+ type !== "radio";
42
45
  const nameInput = nameRef.current;
43
46
  if (nameInput.value === "" &&
44
47
  (type === "amountlabel" || type === "divider" || type === "label")) {
@@ -1,4 +1,5 @@
1
- import { CustomFieldData } from "@etsoo/appscript";
1
+ import { CustomFieldData, CustomFieldRef } from "@etsoo/appscript";
2
+ import React from "react";
2
3
  /**
3
4
  * CustomFieldUI component props
4
5
  */
@@ -7,6 +8,10 @@ export type CustomFieldUIProps<D extends CustomFieldData = CustomFieldData> = {
7
8
  * Custom fields
8
9
  */
9
10
  fields: D[];
11
+ /**
12
+ * Initial value
13
+ */
14
+ initialValue?: Record<string, unknown>;
10
15
  /**
11
16
  * Change event
12
17
  * @param data Current data collection
@@ -15,9 +20,9 @@ export type CustomFieldUIProps<D extends CustomFieldData = CustomFieldData> = {
15
20
  */
16
21
  onChange?: (data: Record<string, unknown>, name: string, value: unknown) => void;
17
22
  /**
18
- * Initial value
23
+ * Methods reference
19
24
  */
20
- value?: Record<string, unknown>;
25
+ mref: React.Ref<CustomFieldRef<Record<string, unknown>>>;
21
26
  };
22
27
  /**
23
28
  * CustomFieldUI component
@@ -1,4 +1,6 @@
1
+ import React from "react";
1
2
  import { CustomFieldUtils } from "./CustomFieldUtils";
3
+ import { useAppContext } from "../app/ReactApp";
2
4
  /**
3
5
  * CustomFieldUI component
4
6
  * @param props Props
@@ -6,14 +8,30 @@ import { CustomFieldUtils } from "./CustomFieldUtils";
6
8
  */
7
9
  export function CustomFieldUI(props) {
8
10
  // Destruct
9
- const { fields, onChange, value = {} } = props;
11
+ const { fields, initialValue, mref, onChange } = props;
12
+ // App
13
+ const app = useAppContext();
14
+ // Field component collections
15
+ const collections = {};
16
+ // Value reference
17
+ const valueRef = React.useRef({ ...initialValue });
18
+ // Methods
19
+ React.useImperativeHandle(mref, () => ({
20
+ getValue: () => valueRef.current,
21
+ setValue: (value) => {
22
+ if (!!value && typeof value === "object") {
23
+ valueRef.current = { ...value };
24
+ CustomFieldUtils.updateValues(collections, valueRef.current);
25
+ }
26
+ }
27
+ }), []);
10
28
  // Layout
11
- return CustomFieldUtils.create(fields, {}, (field) => {
29
+ return CustomFieldUtils.create(fields, collections, (field) => {
12
30
  if (!field.name)
13
31
  return undefined;
14
- return value[field.name];
32
+ return valueRef.current[field.name];
15
33
  }, (name, fieldValue) => {
16
- value[name] = fieldValue;
17
- onChange?.(value, name, fieldValue);
18
- });
34
+ valueRef.current[name] = fieldValue;
35
+ onChange?.(valueRef.current, name, fieldValue);
36
+ }, (input) => app?.get(input) ?? input);
19
37
  }
@@ -53,4 +53,10 @@ export declare namespace CustomFieldUtils {
53
53
  * @param globalCallback Global callback
54
54
  */
55
55
  function updateProperties(input: object, globalCallback: (input: string) => string): void;
56
+ /**
57
+ * Update values for all fields
58
+ * @param collections Field component collections
59
+ * @param value New value
60
+ */
61
+ function updateValues<D extends CustomFieldData = CustomFieldData>(collections: CustomFieldReactCollection<D>, value: Record<string, unknown>): void;
56
62
  }
@@ -144,4 +144,21 @@ export var CustomFieldUtils;
144
144
  }
145
145
  }
146
146
  CustomFieldUtils.updateProperties = updateProperties;
147
+ /**
148
+ * Update values for all fields
149
+ * @param collections Field component collections
150
+ * @param value New value
151
+ */
152
+ function updateValues(collections, value) {
153
+ for (const key in collections) {
154
+ const c = collections[key];
155
+ if (c == null)
156
+ continue;
157
+ const [ref, data] = c;
158
+ if (ref.current == null || !data.name)
159
+ continue;
160
+ ref.current.setValue(value[data.name]);
161
+ }
162
+ }
163
+ CustomFieldUtils.updateValues = updateValues;
147
164
  })(CustomFieldUtils || (CustomFieldUtils = {}));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@etsoo/materialui",
3
- "version": "1.6.20",
3
+ "version": "1.6.22",
4
4
  "description": "TypeScript Material-UI Implementation",
5
5
  "main": "lib/cjs/index.js",
6
6
  "module": "lib/mjs/index.js",
@@ -43,12 +43,12 @@
43
43
  "@etsoo/notificationbase": "^1.1.66",
44
44
  "@etsoo/react": "^1.8.78",
45
45
  "@etsoo/shared": "^1.2.80",
46
- "@mui/icons-material": "^7.3.8",
47
- "@mui/material": "^7.3.8",
48
- "@mui/x-data-grid": "^8.27.3",
46
+ "@mui/icons-material": "^7.3.9",
47
+ "@mui/material": "^7.3.9",
48
+ "@mui/x-data-grid": "^8.27.4",
49
49
  "chart.js": "^4.5.1",
50
50
  "chartjs-plugin-datalabels": "^2.2.0",
51
- "dompurify": "^3.3.1",
51
+ "dompurify": "^3.3.2",
52
52
  "eventemitter3": "^5.0.4",
53
53
  "pica": "^9.0.1",
54
54
  "pulltorefreshjs": "^0.1.22",
@@ -68,7 +68,10 @@ function InputItemUIs({ data }: { data?: CustomFieldData }) {
68
68
  onValueChange={(item) => {
69
69
  const type = item?.id;
70
70
  optionsRef.current!.disabled =
71
- type !== "combobox" && type !== "select";
71
+ type !== "combobox" &&
72
+ type !== "select" &&
73
+ type !== "checkbox" &&
74
+ type !== "radio";
72
75
 
73
76
  const nameInput = nameRef.current!;
74
77
  if (
@@ -1,5 +1,8 @@
1
- import { CustomFieldData } from "@etsoo/appscript";
1
+ import { CustomFieldData, CustomFieldRef } from "@etsoo/appscript";
2
+ import { CustomFieldReactCollection } from "@etsoo/react";
3
+ import React from "react";
2
4
  import { CustomFieldUtils } from "./CustomFieldUtils";
5
+ import { useAppContext } from "../app/ReactApp";
3
6
 
4
7
  /**
5
8
  * CustomFieldUI component props
@@ -10,6 +13,11 @@ export type CustomFieldUIProps<D extends CustomFieldData = CustomFieldData> = {
10
13
  */
11
14
  fields: D[];
12
15
 
16
+ /**
17
+ * Initial value
18
+ */
19
+ initialValue?: Record<string, unknown>;
20
+
13
21
  /**
14
22
  * Change event
15
23
  * @param data Current data collection
@@ -23,9 +31,9 @@ export type CustomFieldUIProps<D extends CustomFieldData = CustomFieldData> = {
23
31
  ) => void;
24
32
 
25
33
  /**
26
- * Initial value
34
+ * Methods reference
27
35
  */
28
- value?: Record<string, unknown>;
36
+ mref: React.Ref<CustomFieldRef<Record<string, unknown>>>;
29
37
  };
30
38
 
31
39
  /**
@@ -37,19 +45,44 @@ export function CustomFieldUI<D extends CustomFieldData = CustomFieldData>(
37
45
  props: CustomFieldUIProps<D>
38
46
  ) {
39
47
  // Destruct
40
- const { fields, onChange, value = {} } = props;
48
+ const { fields, initialValue, mref, onChange } = props;
49
+
50
+ // App
51
+ const app = useAppContext();
52
+
53
+ // Field component collections
54
+ const collections: CustomFieldReactCollection<D> = {};
55
+
56
+ // Value reference
57
+ const valueRef = React.useRef<Record<string, unknown>>({ ...initialValue });
58
+
59
+ // Methods
60
+ React.useImperativeHandle(
61
+ mref,
62
+ () => ({
63
+ getValue: () => valueRef.current,
64
+ setValue: (value) => {
65
+ if (!!value && typeof value === "object") {
66
+ valueRef.current = { ...value };
67
+ CustomFieldUtils.updateValues(collections, valueRef.current);
68
+ }
69
+ }
70
+ }),
71
+ []
72
+ );
41
73
 
42
74
  // Layout
43
75
  return CustomFieldUtils.create(
44
76
  fields,
45
- {},
77
+ collections,
46
78
  (field) => {
47
79
  if (!field.name) return undefined;
48
- return value[field.name];
80
+ return valueRef.current[field.name];
49
81
  },
50
82
  (name, fieldValue) => {
51
- value[name] = fieldValue;
52
- onChange?.(value, name, fieldValue);
53
- }
83
+ valueRef.current[name] = fieldValue;
84
+ onChange?.(valueRef.current, name, fieldValue);
85
+ },
86
+ (input) => app?.get(input) ?? input
54
87
  );
55
88
  }
@@ -199,4 +199,24 @@ export namespace CustomFieldUtils {
199
199
  }
200
200
  }
201
201
  }
202
+
203
+ /**
204
+ * Update values for all fields
205
+ * @param collections Field component collections
206
+ * @param value New value
207
+ */
208
+ export function updateValues<D extends CustomFieldData = CustomFieldData>(
209
+ collections: CustomFieldReactCollection<D>,
210
+ value: Record<string, unknown>
211
+ ) {
212
+ for (const key in collections) {
213
+ const c = collections[key];
214
+ if (c == null) continue;
215
+
216
+ const [ref, data] = c;
217
+ if (ref.current == null || !data.name) continue;
218
+
219
+ ref.current.setValue(value[data.name]);
220
+ }
221
+ }
202
222
  }