@etsoo/materialui 1.6.20 → 1.6.21
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/cjs/custom/CustomFieldUI.d.ts +8 -3
- package/lib/cjs/custom/CustomFieldUI.js +23 -5
- package/lib/cjs/custom/CustomFieldUtils.d.ts +6 -0
- package/lib/cjs/custom/CustomFieldUtils.js +17 -0
- package/lib/mjs/custom/CustomFieldUI.d.ts +8 -3
- package/lib/mjs/custom/CustomFieldUI.js +20 -5
- package/lib/mjs/custom/CustomFieldUtils.d.ts +6 -0
- package/lib/mjs/custom/CustomFieldUtils.js +17 -0
- package/package.json +1 -1
- package/src/custom/CustomFieldUI.tsx +36 -8
- package/src/custom/CustomFieldUtils.tsx +20 -0
|
@@ -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
|
-
*
|
|
23
|
+
* Methods reference
|
|
19
24
|
*/
|
|
20
|
-
|
|
25
|
+
mref: React.Ref<CustomFieldRef<Record<string, unknown>>>;
|
|
21
26
|
};
|
|
22
27
|
/**
|
|
23
28
|
* CustomFieldUI component
|
|
@@ -1,6 +1,10 @@
|
|
|
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");
|
|
5
9
|
/**
|
|
6
10
|
* CustomFieldUI component
|
|
@@ -9,14 +13,28 @@ const CustomFieldUtils_1 = require("./CustomFieldUtils");
|
|
|
9
13
|
*/
|
|
10
14
|
function CustomFieldUI(props) {
|
|
11
15
|
// Destruct
|
|
12
|
-
const { fields,
|
|
16
|
+
const { fields, initialValue, mref, onChange } = props;
|
|
17
|
+
// Field component collections
|
|
18
|
+
const collections = {};
|
|
19
|
+
// Value reference
|
|
20
|
+
const valueRef = react_1.default.useRef({ ...initialValue });
|
|
21
|
+
// Methods
|
|
22
|
+
react_1.default.useImperativeHandle(mref, () => ({
|
|
23
|
+
getValue: () => valueRef.current,
|
|
24
|
+
setValue: (value) => {
|
|
25
|
+
if (!!value && typeof value === "object") {
|
|
26
|
+
valueRef.current = { ...value };
|
|
27
|
+
CustomFieldUtils_1.CustomFieldUtils.updateValues(collections, valueRef.current);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
}), []);
|
|
13
31
|
// Layout
|
|
14
|
-
return CustomFieldUtils_1.CustomFieldUtils.create(fields,
|
|
32
|
+
return CustomFieldUtils_1.CustomFieldUtils.create(fields, collections, (field) => {
|
|
15
33
|
if (!field.name)
|
|
16
34
|
return undefined;
|
|
17
|
-
return
|
|
35
|
+
return valueRef.current[field.name];
|
|
18
36
|
}, (name, fieldValue) => {
|
|
19
|
-
|
|
20
|
-
onChange?.(
|
|
37
|
+
valueRef.current[name] = fieldValue;
|
|
38
|
+
onChange?.(valueRef.current, name, fieldValue);
|
|
21
39
|
});
|
|
22
40
|
}
|
|
@@ -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 = {}));
|
|
@@ -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
|
-
*
|
|
23
|
+
* Methods reference
|
|
19
24
|
*/
|
|
20
|
-
|
|
25
|
+
mref: React.Ref<CustomFieldRef<Record<string, unknown>>>;
|
|
21
26
|
};
|
|
22
27
|
/**
|
|
23
28
|
* CustomFieldUI component
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import React from "react";
|
|
1
2
|
import { CustomFieldUtils } from "./CustomFieldUtils";
|
|
2
3
|
/**
|
|
3
4
|
* CustomFieldUI component
|
|
@@ -6,14 +7,28 @@ import { CustomFieldUtils } from "./CustomFieldUtils";
|
|
|
6
7
|
*/
|
|
7
8
|
export function CustomFieldUI(props) {
|
|
8
9
|
// Destruct
|
|
9
|
-
const { fields,
|
|
10
|
+
const { fields, initialValue, mref, onChange } = props;
|
|
11
|
+
// Field component collections
|
|
12
|
+
const collections = {};
|
|
13
|
+
// Value reference
|
|
14
|
+
const valueRef = React.useRef({ ...initialValue });
|
|
15
|
+
// Methods
|
|
16
|
+
React.useImperativeHandle(mref, () => ({
|
|
17
|
+
getValue: () => valueRef.current,
|
|
18
|
+
setValue: (value) => {
|
|
19
|
+
if (!!value && typeof value === "object") {
|
|
20
|
+
valueRef.current = { ...value };
|
|
21
|
+
CustomFieldUtils.updateValues(collections, valueRef.current);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
}), []);
|
|
10
25
|
// Layout
|
|
11
|
-
return CustomFieldUtils.create(fields,
|
|
26
|
+
return CustomFieldUtils.create(fields, collections, (field) => {
|
|
12
27
|
if (!field.name)
|
|
13
28
|
return undefined;
|
|
14
|
-
return
|
|
29
|
+
return valueRef.current[field.name];
|
|
15
30
|
}, (name, fieldValue) => {
|
|
16
|
-
|
|
17
|
-
onChange?.(
|
|
31
|
+
valueRef.current[name] = fieldValue;
|
|
32
|
+
onChange?.(valueRef.current, name, fieldValue);
|
|
18
33
|
});
|
|
19
34
|
}
|
|
@@ -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,4 +1,6 @@
|
|
|
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";
|
|
3
5
|
|
|
4
6
|
/**
|
|
@@ -10,6 +12,11 @@ export type CustomFieldUIProps<D extends CustomFieldData = CustomFieldData> = {
|
|
|
10
12
|
*/
|
|
11
13
|
fields: D[];
|
|
12
14
|
|
|
15
|
+
/**
|
|
16
|
+
* Initial value
|
|
17
|
+
*/
|
|
18
|
+
initialValue?: Record<string, unknown>;
|
|
19
|
+
|
|
13
20
|
/**
|
|
14
21
|
* Change event
|
|
15
22
|
* @param data Current data collection
|
|
@@ -23,9 +30,9 @@ export type CustomFieldUIProps<D extends CustomFieldData = CustomFieldData> = {
|
|
|
23
30
|
) => void;
|
|
24
31
|
|
|
25
32
|
/**
|
|
26
|
-
*
|
|
33
|
+
* Methods reference
|
|
27
34
|
*/
|
|
28
|
-
|
|
35
|
+
mref: React.Ref<CustomFieldRef<Record<string, unknown>>>;
|
|
29
36
|
};
|
|
30
37
|
|
|
31
38
|
/**
|
|
@@ -37,19 +44,40 @@ export function CustomFieldUI<D extends CustomFieldData = CustomFieldData>(
|
|
|
37
44
|
props: CustomFieldUIProps<D>
|
|
38
45
|
) {
|
|
39
46
|
// Destruct
|
|
40
|
-
const { fields,
|
|
47
|
+
const { fields, initialValue, mref, onChange } = props;
|
|
48
|
+
|
|
49
|
+
// Field component collections
|
|
50
|
+
const collections: CustomFieldReactCollection<D> = {};
|
|
51
|
+
|
|
52
|
+
// Value reference
|
|
53
|
+
const valueRef = React.useRef<Record<string, unknown>>({ ...initialValue });
|
|
54
|
+
|
|
55
|
+
// Methods
|
|
56
|
+
React.useImperativeHandle(
|
|
57
|
+
mref,
|
|
58
|
+
() => ({
|
|
59
|
+
getValue: () => valueRef.current,
|
|
60
|
+
setValue: (value) => {
|
|
61
|
+
if (!!value && typeof value === "object") {
|
|
62
|
+
valueRef.current = { ...value };
|
|
63
|
+
CustomFieldUtils.updateValues(collections, valueRef.current);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
}),
|
|
67
|
+
[]
|
|
68
|
+
);
|
|
41
69
|
|
|
42
70
|
// Layout
|
|
43
71
|
return CustomFieldUtils.create(
|
|
44
72
|
fields,
|
|
45
|
-
|
|
73
|
+
collections,
|
|
46
74
|
(field) => {
|
|
47
75
|
if (!field.name) return undefined;
|
|
48
|
-
return
|
|
76
|
+
return valueRef.current[field.name];
|
|
49
77
|
},
|
|
50
78
|
(name, fieldValue) => {
|
|
51
|
-
|
|
52
|
-
onChange?.(
|
|
79
|
+
valueRef.current[name] = fieldValue;
|
|
80
|
+
onChange?.(valueRef.current, name, fieldValue);
|
|
53
81
|
}
|
|
54
82
|
);
|
|
55
83
|
}
|
|
@@ -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
|
}
|