@box/metadata-editor 0.53.0 → 0.53.1
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/esm/lib/components/metadata-editor-fields/components/metadata-float-field/metadata-float-field.js +7 -6
- package/esm/lib/components/metadata-instance-editor/subcomponents/metadata-instance-form/utils.js +30 -23
- package/package.json +2 -2
- package/types/lib/components/metadata-instance-editor/subcomponents/metadata-instance-form/types.d.ts +2 -2
- package/types/lib/types.d.ts +1 -1
@@ -3,9 +3,9 @@ import { useFormikContext as T, getIn as g, Field as C } from "formik";
|
|
3
3
|
import { useRef as I } from "react";
|
4
4
|
import V from "../../../interactive-text/interactive-text.js";
|
5
5
|
import { fieldDefaultProps as $ } from "../constants.js";
|
6
|
-
import { useFloatValidation as
|
6
|
+
import { useFloatValidation as b } from "./use-float-validation.js";
|
7
7
|
import { jsx as a } from "react/jsx-runtime";
|
8
|
-
const
|
8
|
+
const M = ({
|
9
9
|
className: i,
|
10
10
|
description: l,
|
11
11
|
label: r,
|
@@ -18,7 +18,7 @@ const N = ({
|
|
18
18
|
setFieldTouched: c
|
19
19
|
} = T(), t = `${d}.value`, f = g(u, t), n = I(f), {
|
20
20
|
validateFloats: p
|
21
|
-
} =
|
21
|
+
} = b(), h = (e) => {
|
22
22
|
n.current = e, m(t, e);
|
23
23
|
}, F = (e) => {
|
24
24
|
c(e, !0);
|
@@ -47,12 +47,13 @@ const N = ({
|
|
47
47
|
}) : r,
|
48
48
|
onBlur: () => F(t),
|
49
49
|
onChange: (o) => h(o.currentTarget.value),
|
50
|
-
placeholder: "0"
|
50
|
+
placeholder: "0",
|
51
|
+
type: "number"
|
51
52
|
})
|
52
53
|
})
|
53
54
|
});
|
54
55
|
};
|
55
56
|
export {
|
56
|
-
|
57
|
-
|
57
|
+
M as MetadataFloatField,
|
58
|
+
M as default
|
58
59
|
};
|
package/esm/lib/components/metadata-instance-editor/subcomponents/metadata-instance-form/utils.js
CHANGED
@@ -1,33 +1,40 @@
|
|
1
|
-
|
1
|
+
import v from "lodash/isEmpty";
|
2
|
+
import O from "lodash/isArray";
|
3
|
+
import { TEMPLATE_CUSTOM_PROPERTIES as f } from "../../../../constants.js";
|
4
|
+
const n = {
|
2
5
|
ADD: "add",
|
3
6
|
REMOVE: "remove",
|
4
7
|
REPLACE: "replace",
|
5
8
|
TEST: "test"
|
6
|
-
},
|
7
|
-
const
|
8
|
-
return
|
9
|
-
const
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
},
|
16
|
-
|
17
|
-
|
9
|
+
}, o = (e) => e.value === null || e.value === "" || O(e.value) && v(e.value), S = (e, s) => {
|
10
|
+
const p = [], c = e.metadata.fields, r = s.templateKey === f, m = new Map(s.fields.map((t) => [t.key, t])), h = new Map(c.map((t) => [t.key, t]));
|
11
|
+
return c.forEach((t) => {
|
12
|
+
const a = m.get(t.key);
|
13
|
+
a ? JSON.stringify(t) === JSON.stringify(a) || (!r && o(a) && !o(t) ? p.push(y(t.key, u(t))) : (
|
14
|
+
// template instance
|
15
|
+
(!r && t.value !== a.value && a.value !== null && !o(t) || // custom instance
|
16
|
+
r && t.value !== a.value) && (p.push(E(a.key, u(a))), p.push(M(t.key, u(t))))
|
17
|
+
)) : p.push(y(t.key, t.value));
|
18
|
+
}), s.fields.forEach((t) => {
|
19
|
+
const a = h.get(t.key);
|
20
|
+
(!a || !r && o(a) && !o(t)) && (p.push(E(t.key, u(t))), p.push(k(t.key)));
|
21
|
+
}), p;
|
22
|
+
}, u = (e) => e.type === "float" ? Number(e.value) : e.value, E = (e, s) => ({
|
23
|
+
op: n.TEST,
|
24
|
+
path: `/${e}`,
|
18
25
|
value: s
|
19
|
-
}),
|
20
|
-
op:
|
21
|
-
path: `/${
|
26
|
+
}), y = (e, s) => ({
|
27
|
+
op: n.ADD,
|
28
|
+
path: `/${e}`,
|
22
29
|
value: s
|
23
|
-
}),
|
24
|
-
op:
|
25
|
-
path: `/${
|
26
|
-
}),
|
27
|
-
op:
|
28
|
-
path: `/${
|
30
|
+
}), k = (e) => ({
|
31
|
+
op: n.REMOVE,
|
32
|
+
path: `/${e}`
|
33
|
+
}), M = (e, s) => ({
|
34
|
+
op: n.REPLACE,
|
35
|
+
path: `/${e}`,
|
29
36
|
value: s
|
30
37
|
});
|
31
38
|
export {
|
32
|
-
|
39
|
+
S as createJSONPatch
|
33
40
|
};
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@box/metadata-editor",
|
3
|
-
"version": "0.53.
|
3
|
+
"version": "0.53.1",
|
4
4
|
"peerDependencies": {
|
5
5
|
"@ariakit/react": "0.4.5",
|
6
6
|
"@box/blueprint-web": "^7.20.0",
|
@@ -52,5 +52,5 @@
|
|
52
52
|
"**/*.css"
|
53
53
|
],
|
54
54
|
"license": "SEE LICENSE IN LICENSE",
|
55
|
-
"gitHead": "
|
55
|
+
"gitHead": "7e6b9d100238888a4c82c0479c6a534df1f7d9b5"
|
56
56
|
}
|
@@ -1,4 +1,4 @@
|
|
1
|
-
import { type MetadataTemplateInstance } from '../../../../types';
|
1
|
+
import { type MetadataFormFieldValue, type MetadataTemplateInstance } from '../../../../types';
|
2
2
|
import { type FormValues } from '../../types';
|
3
3
|
export type MetadataInstanceFormProps = {
|
4
4
|
isAiSuggestionsFeatureEnabled: boolean;
|
@@ -25,6 +25,6 @@ export type JSONPatchOperation = {
|
|
25
25
|
/** The path to the field in the JSON document */
|
26
26
|
path: string;
|
27
27
|
/** The value to add/replace if needed (optional for 'remove') */
|
28
|
-
value?:
|
28
|
+
value?: MetadataFormFieldValue;
|
29
29
|
};
|
30
30
|
export type JSONPatchOperations = JSONPatchOperation[];
|
package/types/lib/types.d.ts
CHANGED
@@ -6,7 +6,7 @@ export type MetadataEmptyStateProps = {
|
|
6
6
|
level: 'manager' | 'file' | 'instance';
|
7
7
|
onShowEmptyValues?: () => void;
|
8
8
|
};
|
9
|
-
export type MetadataFormFieldValue = string | Array<string
|
9
|
+
export type MetadataFormFieldValue = string | Array<string> | number;
|
10
10
|
export type MetadataFields = Record<string, MetadataFieldValue>;
|
11
11
|
export interface MetadataTemplateFieldOption {
|
12
12
|
key: string;
|