@etsoo/materialui 1.6.16 → 1.6.17

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.
@@ -0,0 +1,27 @@
1
+ import { CustomFieldData } from "@etsoo/appscript";
2
+ /**
3
+ * CustomFieldUI component props
4
+ */
5
+ export type CustomFieldUIProps<D extends CustomFieldData = CustomFieldData> = {
6
+ /**
7
+ * Custom fields
8
+ */
9
+ fields: D[];
10
+ /**
11
+ * Change event
12
+ * @param data Current data collection
13
+ * @param name Changed field name
14
+ * @param value Changed field value
15
+ */
16
+ onChange?: (data: Record<string, unknown>, name: string, value: unknown) => void;
17
+ /**
18
+ * Initial value
19
+ */
20
+ value?: Record<string, unknown>;
21
+ };
22
+ /**
23
+ * CustomFieldUI component
24
+ * @param props Props
25
+ * @returns component
26
+ */
27
+ export declare function CustomFieldUI<D extends CustomFieldData = CustomFieldData>(props: CustomFieldUIProps<D>): import("react/jsx-runtime").JSX.Element[];
@@ -0,0 +1,29 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.CustomFieldUI = CustomFieldUI;
7
+ const react_1 = __importDefault(require("react"));
8
+ const CustomFieldUtils_1 = require("./CustomFieldUtils");
9
+ /**
10
+ * CustomFieldUI component
11
+ * @param props Props
12
+ * @returns component
13
+ */
14
+ function CustomFieldUI(props) {
15
+ // Destruct
16
+ const { fields, onChange, value } = props;
17
+ const data = react_1.default.useRef({});
18
+ const getValue = react_1.default.useCallback((field) => {
19
+ if (!field.name)
20
+ return undefined;
21
+ return value?.[field.name];
22
+ }, [value]);
23
+ const doChange = react_1.default.useCallback((name, value) => {
24
+ data.current[name] = value;
25
+ onChange?.(data.current, name, value);
26
+ }, []);
27
+ // Layout
28
+ return CustomFieldUtils_1.CustomFieldUtils.create(fields, {}, getValue, doChange);
29
+ }
@@ -70,7 +70,7 @@ var CustomFieldUtils;
70
70
  fieldCalback(field);
71
71
  const creator = CustomFieldUtils.customFieldCreators[field.type];
72
72
  if (creator == null) {
73
- return ((0, jsx_runtime_1.jsx)(Grid_1.default, { size: transformSpace(field.space), ...field.gridItemProps, children: `Type ${field.type} is not supported currently` }, index));
73
+ return ((0, jsx_runtime_1.jsx)(Grid_1.default, { size: transformSpace(field.space), ...field.gridItemProps, children: `Type ${field.type} is not supported currently` }, field.name ?? index));
74
74
  }
75
75
  const Creator = creator;
76
76
  const mref = react_1.default.createRef();
@@ -7,6 +7,7 @@ export * from "./app/Labels";
7
7
  export * from "./app/ReactApp";
8
8
  export * from "./app/ServiceApp";
9
9
  export * from "./custom/CustomAttributeArea";
10
+ export * from "./custom/CustomFieldUI";
10
11
  export * from "./custom/CustomFieldUtils";
11
12
  export * from "./custom/CustomFieldViewer";
12
13
  export * from "./custom/CustomFieldWindow";
package/lib/cjs/index.js CHANGED
@@ -23,6 +23,7 @@ __exportStar(require("./app/Labels"), exports);
23
23
  __exportStar(require("./app/ReactApp"), exports);
24
24
  __exportStar(require("./app/ServiceApp"), exports);
25
25
  __exportStar(require("./custom/CustomAttributeArea"), exports);
26
+ __exportStar(require("./custom/CustomFieldUI"), exports);
26
27
  __exportStar(require("./custom/CustomFieldUtils"), exports);
27
28
  __exportStar(require("./custom/CustomFieldViewer"), exports);
28
29
  __exportStar(require("./custom/CustomFieldWindow"), exports);
@@ -0,0 +1,27 @@
1
+ import { CustomFieldData } from "@etsoo/appscript";
2
+ /**
3
+ * CustomFieldUI component props
4
+ */
5
+ export type CustomFieldUIProps<D extends CustomFieldData = CustomFieldData> = {
6
+ /**
7
+ * Custom fields
8
+ */
9
+ fields: D[];
10
+ /**
11
+ * Change event
12
+ * @param data Current data collection
13
+ * @param name Changed field name
14
+ * @param value Changed field value
15
+ */
16
+ onChange?: (data: Record<string, unknown>, name: string, value: unknown) => void;
17
+ /**
18
+ * Initial value
19
+ */
20
+ value?: Record<string, unknown>;
21
+ };
22
+ /**
23
+ * CustomFieldUI component
24
+ * @param props Props
25
+ * @returns component
26
+ */
27
+ export declare function CustomFieldUI<D extends CustomFieldData = CustomFieldData>(props: CustomFieldUIProps<D>): import("react/jsx-runtime").JSX.Element[];
@@ -0,0 +1,23 @@
1
+ import React from "react";
2
+ import { CustomFieldUtils } from "./CustomFieldUtils";
3
+ /**
4
+ * CustomFieldUI component
5
+ * @param props Props
6
+ * @returns component
7
+ */
8
+ export function CustomFieldUI(props) {
9
+ // Destruct
10
+ const { fields, onChange, value } = props;
11
+ const data = React.useRef({});
12
+ const getValue = React.useCallback((field) => {
13
+ if (!field.name)
14
+ return undefined;
15
+ return value?.[field.name];
16
+ }, [value]);
17
+ const doChange = React.useCallback((name, value) => {
18
+ data.current[name] = value;
19
+ onChange?.(data.current, name, value);
20
+ }, []);
21
+ // Layout
22
+ return CustomFieldUtils.create(fields, {}, getValue, doChange);
23
+ }
@@ -64,7 +64,7 @@ export var CustomFieldUtils;
64
64
  fieldCalback(field);
65
65
  const creator = CustomFieldUtils.customFieldCreators[field.type];
66
66
  if (creator == null) {
67
- return (_jsx(Grid, { size: transformSpace(field.space), ...field.gridItemProps, children: `Type ${field.type} is not supported currently` }, index));
67
+ return (_jsx(Grid, { size: transformSpace(field.space), ...field.gridItemProps, children: `Type ${field.type} is not supported currently` }, field.name ?? index));
68
68
  }
69
69
  const Creator = creator;
70
70
  const mref = React.createRef();
@@ -7,6 +7,7 @@ export * from "./app/Labels";
7
7
  export * from "./app/ReactApp";
8
8
  export * from "./app/ServiceApp";
9
9
  export * from "./custom/CustomAttributeArea";
10
+ export * from "./custom/CustomFieldUI";
10
11
  export * from "./custom/CustomFieldUtils";
11
12
  export * from "./custom/CustomFieldViewer";
12
13
  export * from "./custom/CustomFieldWindow";
package/lib/mjs/index.js CHANGED
@@ -7,6 +7,7 @@ export * from "./app/Labels";
7
7
  export * from "./app/ReactApp";
8
8
  export * from "./app/ServiceApp";
9
9
  export * from "./custom/CustomAttributeArea";
10
+ export * from "./custom/CustomFieldUI";
10
11
  export * from "./custom/CustomFieldUtils";
11
12
  export * from "./custom/CustomFieldViewer";
12
13
  export * from "./custom/CustomFieldWindow";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@etsoo/materialui",
3
- "version": "1.6.16",
3
+ "version": "1.6.17",
4
4
  "description": "TypeScript Material-UI Implementation",
5
5
  "main": "lib/cjs/index.js",
6
6
  "module": "lib/mjs/index.js",
@@ -0,0 +1,60 @@
1
+ import { CustomFieldData } from "@etsoo/appscript";
2
+ import React from "react";
3
+ import { CustomFieldUtils } from "./CustomFieldUtils";
4
+
5
+ /**
6
+ * CustomFieldUI component props
7
+ */
8
+ export type CustomFieldUIProps<D extends CustomFieldData = CustomFieldData> = {
9
+ /**
10
+ * Custom fields
11
+ */
12
+ fields: D[];
13
+
14
+ /**
15
+ * Change event
16
+ * @param data Current data collection
17
+ * @param name Changed field name
18
+ * @param value Changed field value
19
+ */
20
+ onChange?: (
21
+ data: Record<string, unknown>,
22
+ name: string,
23
+ value: unknown
24
+ ) => void;
25
+
26
+ /**
27
+ * Initial value
28
+ */
29
+ value?: Record<string, unknown>;
30
+ };
31
+
32
+ /**
33
+ * CustomFieldUI component
34
+ * @param props Props
35
+ * @returns component
36
+ */
37
+ export function CustomFieldUI<D extends CustomFieldData = CustomFieldData>(
38
+ props: CustomFieldUIProps<D>
39
+ ) {
40
+ // Destruct
41
+ const { fields, onChange, value } = props;
42
+
43
+ const data = React.useRef<Record<string, unknown>>({});
44
+
45
+ const getValue = React.useCallback(
46
+ (field: CustomFieldData) => {
47
+ if (!field.name) return undefined;
48
+ return value?.[field.name];
49
+ },
50
+ [value]
51
+ );
52
+
53
+ const doChange = React.useCallback((name: string, value: unknown) => {
54
+ data.current[name] = value;
55
+ onChange?.(data.current, name, value);
56
+ }, []);
57
+
58
+ // Layout
59
+ return CustomFieldUtils.create(fields, {}, getValue, doChange);
60
+ }
@@ -84,7 +84,7 @@ export namespace CustomFieldUtils {
84
84
  if (creator == null) {
85
85
  return (
86
86
  <Grid
87
- key={index}
87
+ key={field.name ?? index}
88
88
  size={transformSpace(field.space)}
89
89
  {...field.gridItemProps}
90
90
  >
@@ -153,14 +153,14 @@ export namespace CustomFieldUtils {
153
153
  space === "full"
154
154
  ? { xs: 12 }
155
155
  : space === "quater"
156
- ? { sm: 12, md: 6, lg: 3 }
157
- : space === "five"
158
- ? { sm: 12, md: 5 }
159
- : space === "seven"
160
- ? { sm: 12, md: 7 }
161
- : space === "half1"
162
- ? { xs: 12, sm: 6 }
163
- : { sm: 12, md: 6 };
156
+ ? { sm: 12, md: 6, lg: 3 }
157
+ : space === "five"
158
+ ? { sm: 12, md: 5 }
159
+ : space === "seven"
160
+ ? { sm: 12, md: 7 }
161
+ : space === "half1"
162
+ ? { xs: 12, sm: 6 }
163
+ : { sm: 12, md: 6 };
164
164
  return size;
165
165
  }
166
166
 
package/src/index.ts CHANGED
@@ -8,6 +8,7 @@ export * from "./app/ReactApp";
8
8
  export * from "./app/ServiceApp";
9
9
 
10
10
  export * from "./custom/CustomAttributeArea";
11
+ export * from "./custom/CustomFieldUI";
11
12
  export * from "./custom/CustomFieldUtils";
12
13
  export * from "./custom/CustomFieldViewer";
13
14
  export * from "./custom/CustomFieldWindow";