@box/metadata-editor 1.63.2 → 1.64.0
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/dist/chunks/utils.js +46 -42
- package/dist/esm/lib/components/metadata-editor-fields/metadata-editor-field-wrapper.js +45 -44
- package/dist/esm/lib/components/metadata-instance-editor/subcomponents/metadata-instance-form/utils.js +4 -3
- package/dist/types/lib/components/metadata-instance-editor/subcomponents/metadata-instance-form/types.d.ts +7 -2
- package/dist/types/lib/components/metadata-instance-editor/subcomponents/metadata-instance-form/utils.d.ts +3 -3
- package/package.json +1 -1
package/dist/chunks/utils.js
CHANGED
|
@@ -1,51 +1,55 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
|
|
1
|
+
import g from "lodash/isArray";
|
|
2
|
+
import h from "lodash/isEmpty";
|
|
3
|
+
import f from "lodash/isEqual";
|
|
4
|
+
import { TEMPLATE_CUSTOM_PROPERTIES as m } from "../esm/lib/constants.js";
|
|
5
|
+
const i = {
|
|
5
6
|
ADD: "add",
|
|
6
7
|
REMOVE: "remove",
|
|
7
8
|
REPLACE: "replace",
|
|
8
9
|
TEST: "test"
|
|
9
|
-
},
|
|
10
|
-
const
|
|
11
|
-
return
|
|
12
|
-
},
|
|
13
|
-
const
|
|
14
|
-
return
|
|
15
|
-
},
|
|
16
|
-
const
|
|
17
|
-
return
|
|
18
|
-
},
|
|
19
|
-
const
|
|
20
|
-
return
|
|
21
|
-
const
|
|
22
|
-
if (!
|
|
23
|
-
|
|
10
|
+
}, A = "AI_ACCEPTED", O = (t, o) => t.value === o.value && t.level === o.level && t.isAccepted === o.isAccepted, p = (t) => t.value === void 0 || t.value === null || t.value === "" || g(t.value) && h(t.value), l = (t, o, c) => {
|
|
11
|
+
const n = o.confidenceScore, a = c.confidenceScore;
|
|
12
|
+
return a ? n && O(n, a) ? [] : T(t, a) : [];
|
|
13
|
+
}, T = (t, o) => {
|
|
14
|
+
const c = [];
|
|
15
|
+
return o.isAccepted && c.push(s(`${t}/process`, A)), c.push(s(`${t}/confidenceScore`, o.value), s(`${t}/confidenceLevel`, o.level)), c;
|
|
16
|
+
}, C = (t, o, c) => {
|
|
17
|
+
const n = o.targetLocation, a = c.targetLocation, v = o.confidenceScore?.isAccepted ?? !1, E = c.confidenceScore?.isAccepted ?? !1, e = !v && E;
|
|
18
|
+
return a ? !f(n, a) || e ? [s(`${t}/targetLocation`, JSON.stringify(a))] : [] : [];
|
|
19
|
+
}, D = (t, o) => {
|
|
20
|
+
const c = [], n = t.metadata.fields, a = o.templateKey === m, v = new Map(o.fields.map((e) => [e.key, e])), E = new Map(n.map((e) => [e.key, e]));
|
|
21
|
+
return n.forEach((e) => {
|
|
22
|
+
const r = v.get(e.key);
|
|
23
|
+
if (!r) {
|
|
24
|
+
c.push(s(e.key, u(e)));
|
|
24
25
|
return;
|
|
25
26
|
}
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
const
|
|
29
|
-
|
|
30
|
-
}), o
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
}),
|
|
43
|
-
op:
|
|
44
|
-
path: `/${
|
|
45
|
-
|
|
27
|
+
if (f(e, r))
|
|
28
|
+
return;
|
|
29
|
+
const y = !f(e.value, r.value);
|
|
30
|
+
!a && p(r) && !p(e) ? c.push(s(e.key, u(e))) : (!a && y && r.value !== null && !p(e) || a && y) && (c.push(S(r.key, u(r))), c.push(L(e.key, u(e)))), c.push(...l(e.key, r, e)), c.push(...C(e.key, r, e));
|
|
31
|
+
}), o.fields.forEach((e) => {
|
|
32
|
+
const r = E.get(e.key);
|
|
33
|
+
(!r || !a && p(r) && !p(e)) && (c.push(S(e.key, u(e))), c.push(k(e.key)));
|
|
34
|
+
}), c;
|
|
35
|
+
}, u = (t) => t.type === "float" ? Number(t.value) : t.type === "taxonomy" ? t.value.map((o) => o.value) : t.type === "date" && typeof t.value == "string" ? new Date(t.value).toISOString() : t.value, S = (t, o) => ({
|
|
36
|
+
op: i.TEST,
|
|
37
|
+
path: `/${t}`,
|
|
38
|
+
value: o
|
|
39
|
+
}), s = (t, o) => ({
|
|
40
|
+
op: i.ADD,
|
|
41
|
+
path: `/${t}`,
|
|
42
|
+
value: o
|
|
43
|
+
}), k = (t) => ({
|
|
44
|
+
op: i.REMOVE,
|
|
45
|
+
path: `/${t}`
|
|
46
|
+
}), L = (t, o) => ({
|
|
47
|
+
op: i.REPLACE,
|
|
48
|
+
path: `/${t}`,
|
|
49
|
+
value: o
|
|
46
50
|
});
|
|
47
51
|
export {
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
52
|
+
i as J,
|
|
53
|
+
D as c,
|
|
54
|
+
u as g
|
|
51
55
|
};
|
|
@@ -3,27 +3,27 @@ import C from "clsx";
|
|
|
3
3
|
import { useFormikContext as pe } from "formik";
|
|
4
4
|
import ge from "lodash/isEqual";
|
|
5
5
|
import de from "lodash/isUndefined";
|
|
6
|
-
import { memo as me, forwardRef as le, useCallback as
|
|
6
|
+
import { memo as me, forwardRef as le, useCallback as a, useEffect as H, useMemo as fe } from "react";
|
|
7
7
|
import { useIntl as Se } from "react-intl";
|
|
8
|
-
import { A as
|
|
8
|
+
import { A as u } from "../../../../chunks/types.js";
|
|
9
9
|
import { checkIfHasBoundingBoxes as Ae } from "../../utils/check-if-has-bounding-boxes.js";
|
|
10
10
|
import { isInteractiveFormElement as z } from "../../utils/is-interactive-form-element.js";
|
|
11
11
|
import { s as l } from "../../../../chunks/shared-field-styles.module.js";
|
|
12
12
|
import { UpdateModeFieldWrapper as he } from "./components/update-mode-field-wrapper/update-mode-field-wrapper.js";
|
|
13
|
-
import { editorFieldTypes as
|
|
13
|
+
import { editorFieldTypes as ve } from "./editor-field-types.js";
|
|
14
14
|
import G from "../../messages.js";
|
|
15
|
-
import { useViewReferenceTooltip as
|
|
15
|
+
import { useViewReferenceTooltip as ye } from "./hooks/use-view-reference-tooltip.js";
|
|
16
16
|
import { s as A } from "../../../../chunks/utils2.js";
|
|
17
|
-
import { jsx as
|
|
17
|
+
import { jsx as p, jsxs as $e } from "react/jsx-runtime";
|
|
18
18
|
import { isConfidenceScoreNeedingReview as J } from "../../utils/confidence-score/is-confidence-score-needing-review.js";
|
|
19
19
|
import { AiSuggestionField as ke } from "./components/ai-suggestion-field/ai-suggestion-field.js";
|
|
20
20
|
import { LowConfidenceSuggestionField as Ce } from "./components/low-confidence-suggestion-field/low-confidence-suggestion-field.js";
|
|
21
21
|
const Je = /* @__PURE__ */ me(/* @__PURE__ */ le(({
|
|
22
22
|
disableForm: L,
|
|
23
|
-
portalElement:
|
|
23
|
+
portalElement: I,
|
|
24
24
|
field: e,
|
|
25
25
|
index: M,
|
|
26
|
-
taxonomyOptionsFetcher:
|
|
26
|
+
taxonomyOptionsFetcher: x,
|
|
27
27
|
isExternallyOwned: N,
|
|
28
28
|
isMultilevelTaxonomyFieldEnabled: V,
|
|
29
29
|
isConfidenceScoreReviewEnabled: s = !1,
|
|
@@ -34,48 +34,49 @@ const Je = /* @__PURE__ */ me(/* @__PURE__ */ le(({
|
|
|
34
34
|
setFieldValue: n
|
|
35
35
|
} = pe(), {
|
|
36
36
|
formatMessage: B
|
|
37
|
-
} = Se(),
|
|
37
|
+
} = Se(), v = e.aiSuggestionState || u.Initial, g = v === u.Pending, F = v === u.Applied, P = v === u.Initial, y = ve[e.type], {
|
|
38
38
|
aiSuggestion: r,
|
|
39
39
|
aiSuggestionConfidenceScore: f,
|
|
40
40
|
aiSuggestionTargetLocation: D,
|
|
41
41
|
type: S,
|
|
42
|
-
value:
|
|
43
|
-
} = e, X =
|
|
42
|
+
value: d
|
|
43
|
+
} = e, X = y && !e.hidden, Y = !de(e.updateMode), o = `metadata.fields[${M}]`, Z = e.type === "taxonomy" && e.optionsRules?.multiSelect, $ = s && !!e.confidenceScore, W = $ && J(e.confidenceScore), _ = $ && !g && !J(e.confidenceScore), w = Q === e.id, b = Ae(e.targetLocation), m = $ && b && !!i, {
|
|
44
44
|
isTooltipOpen: O,
|
|
45
45
|
handleMouseOver: E,
|
|
46
46
|
handleMouseLeave: R,
|
|
47
47
|
handleFocus: ee,
|
|
48
48
|
handleBlur: oe
|
|
49
|
-
} =
|
|
49
|
+
} = ye(m), ne = C({
|
|
50
50
|
[A.aiApproved]: F || _,
|
|
51
|
-
[A.hasSuggestion]:
|
|
52
|
-
[A.hasConfidenceReview]: !
|
|
51
|
+
[A.hasSuggestion]: g,
|
|
52
|
+
[A.hasConfidenceReview]: !g && W,
|
|
53
53
|
[A.dateField]: S === "date"
|
|
54
|
-
}),
|
|
54
|
+
}), c = a((t) => {
|
|
55
55
|
n(`${o}.aiSuggestionState`, t);
|
|
56
|
-
}, [o, n]), h =
|
|
57
|
-
if (n(`${o}.value`, t),
|
|
56
|
+
}, [o, n]), h = a((t, ae = !1) => {
|
|
57
|
+
if (n(`${o}.value`, t), c(u.Applied), s && f) {
|
|
58
58
|
const ue = ae ? {
|
|
59
59
|
...f,
|
|
60
60
|
isAccepted: !0
|
|
61
61
|
} : f;
|
|
62
62
|
n(`${o}.confidenceScore`, ue), n(`${o}.aiSuggestionConfidenceScore`, void 0), n(`${o}.targetLocation`, D), n(`${o}.aiSuggestionTargetLocation`, void 0);
|
|
63
63
|
}
|
|
64
|
-
}, [o, n,
|
|
65
|
-
|
|
66
|
-
}, [
|
|
64
|
+
}, [o, n, c, f, D, s]), k = a(() => {
|
|
65
|
+
c(u.Initial), n(`${o}.aiSuggestion`, void 0), s && (n(`${o}.aiSuggestionConfidenceScore`, void 0), n(`${o}.aiSuggestionTargetLocation`, void 0));
|
|
66
|
+
}, [c, n, o, s]), te = a(() => {
|
|
67
67
|
e.confidenceScore && n(`${o}.confidenceScore`, {
|
|
68
68
|
...e.confidenceScore,
|
|
69
69
|
isAccepted: !0
|
|
70
70
|
}), i?.(null);
|
|
71
|
-
}, [o, n, e.confidenceScore, i]), ie =
|
|
71
|
+
}, [o, n, e.confidenceScore, i]), ie = a(() => {
|
|
72
|
+
c(u.Initial), n(`${o}.aiSuggestion`, void 0);
|
|
72
73
|
const t = S === "multiSelect" || S === "taxonomy" ? [] : "";
|
|
73
|
-
n(`${o}.value`, t), n(`${o}.confidenceScore`, void 0), i?.(null);
|
|
74
|
-
}, [o, n, S, i]), U =
|
|
74
|
+
n(`${o}.value`, t), n(`${o}.confidenceScore`, void 0), n(`${o}.targetLocation`, void 0), i?.(null);
|
|
75
|
+
}, [o, n, S, i, c]), U = a(() => {
|
|
75
76
|
k(), s && e.confidenceScore && (n(`${o}.confidenceScore`, void 0), i?.(null));
|
|
76
|
-
}, [k, s, e.confidenceScore, n, o, i]), se =
|
|
77
|
+
}, [k, s, e.confidenceScore, n, o, i]), se = a((t) => {
|
|
77
78
|
i && (z(t.target) || i(e));
|
|
78
|
-
}, [e, i]), re =
|
|
79
|
+
}, [e, i]), re = a((t) => {
|
|
79
80
|
if (t.key === "Enter") {
|
|
80
81
|
if (!i || z(t.target))
|
|
81
82
|
return;
|
|
@@ -83,11 +84,11 @@ const Je = /* @__PURE__ */ me(/* @__PURE__ */ le(({
|
|
|
83
84
|
}
|
|
84
85
|
}, [e, i]);
|
|
85
86
|
H(() => {
|
|
86
|
-
|
|
87
|
-
}, [r,
|
|
88
|
-
P && r &&
|
|
89
|
-
}, [P, r,
|
|
90
|
-
const ce = fe(() => r ? ge(
|
|
87
|
+
g && (!d || Array.isArray(d) && d.length === 0) && h(r);
|
|
88
|
+
}, [r, g, h]), H(() => {
|
|
89
|
+
P && r && c(u.Pending);
|
|
90
|
+
}, [P, r, c]);
|
|
91
|
+
const ce = fe(() => r ? ge(d, r) : !1, [r, d]);
|
|
91
92
|
if (!X)
|
|
92
93
|
return null;
|
|
93
94
|
const j = {
|
|
@@ -103,11 +104,11 @@ const Je = /* @__PURE__ */ me(/* @__PURE__ */ le(({
|
|
|
103
104
|
tabIndex: 0
|
|
104
105
|
};
|
|
105
106
|
if (Y) {
|
|
106
|
-
const t = /* @__PURE__ */
|
|
107
|
+
const t = /* @__PURE__ */ p(he, {
|
|
107
108
|
fieldNamePrefix: o,
|
|
108
109
|
fieldType: e.type,
|
|
109
110
|
isTaxonomyMultiSelect: Z,
|
|
110
|
-
children: /* @__PURE__ */
|
|
111
|
+
children: /* @__PURE__ */ p(y, {
|
|
111
112
|
ref: T,
|
|
112
113
|
description: e.description,
|
|
113
114
|
disableForm: L,
|
|
@@ -118,14 +119,14 @@ const Je = /* @__PURE__ */ me(/* @__PURE__ */ le(({
|
|
|
118
119
|
label: e.displayName,
|
|
119
120
|
levels: e.levels,
|
|
120
121
|
onValueEdited: U,
|
|
121
|
-
portalElement:
|
|
122
|
-
taxonomyOptionsFetcher:
|
|
122
|
+
portalElement: I,
|
|
123
|
+
taxonomyOptionsFetcher: x
|
|
123
124
|
})
|
|
124
125
|
}, e.key);
|
|
125
|
-
return
|
|
126
|
+
return m ? /* @__PURE__ */ p(q, {
|
|
126
127
|
content: B(G.viewOnDocument),
|
|
127
128
|
open: O,
|
|
128
|
-
children: /* @__PURE__ */
|
|
129
|
+
children: /* @__PURE__ */ p("div", {
|
|
129
130
|
className: C(l.spacious, l.clickableField, w && l.selectedField),
|
|
130
131
|
...j,
|
|
131
132
|
children: t
|
|
@@ -133,9 +134,9 @@ const Je = /* @__PURE__ */ me(/* @__PURE__ */ le(({
|
|
|
133
134
|
}) : t;
|
|
134
135
|
}
|
|
135
136
|
const K = /* @__PURE__ */ $e("div", {
|
|
136
|
-
className: C(A.fieldWrapper, s && l.spacious,
|
|
137
|
-
...
|
|
138
|
-
children: [/* @__PURE__ */
|
|
137
|
+
className: C(A.fieldWrapper, s && l.spacious, m && l.clickableField, m && w && l.selectedField),
|
|
138
|
+
...m && j,
|
|
139
|
+
children: [/* @__PURE__ */ p(y, {
|
|
139
140
|
ref: T,
|
|
140
141
|
className: ne,
|
|
141
142
|
description: e.description,
|
|
@@ -147,25 +148,25 @@ const Je = /* @__PURE__ */ me(/* @__PURE__ */ le(({
|
|
|
147
148
|
isMultilevelTaxonomyFieldEnabled: V,
|
|
148
149
|
label: e.displayName,
|
|
149
150
|
onValueEdited: U,
|
|
150
|
-
portalElement:
|
|
151
|
-
taxonomyOptionsFetcher:
|
|
152
|
-
}),
|
|
151
|
+
portalElement: I,
|
|
152
|
+
taxonomyOptionsFetcher: x
|
|
153
|
+
}), g && /* @__PURE__ */ p(ke, {
|
|
153
154
|
aiSuggestion: r,
|
|
154
155
|
confidenceLevel: s ? f?.level : void 0,
|
|
155
156
|
isSameValue: ce,
|
|
156
157
|
onAiSuggestionAppend: () => {
|
|
157
|
-
const t = [...new Set([
|
|
158
|
+
const t = [...new Set([d, r].flat().filter(Boolean))];
|
|
158
159
|
h(t, !0);
|
|
159
160
|
},
|
|
160
161
|
onAiSuggestionIgnore: k,
|
|
161
162
|
onAiSuggestionReplace: () => h(r, !0),
|
|
162
163
|
type: S
|
|
163
|
-
}), !
|
|
164
|
+
}), !g && W && /* @__PURE__ */ p(Ce, {
|
|
164
165
|
onAccept: te,
|
|
165
166
|
onClear: ie
|
|
166
167
|
})]
|
|
167
168
|
}, e.key);
|
|
168
|
-
return
|
|
169
|
+
return m ? /* @__PURE__ */ p(q, {
|
|
169
170
|
content: B(G.viewOnDocument),
|
|
170
171
|
open: O,
|
|
171
172
|
children: K
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import "lodash/isArray";
|
|
2
2
|
import "lodash/isEmpty";
|
|
3
|
+
import "lodash/isEqual";
|
|
3
4
|
import "../../../../constants.js";
|
|
4
|
-
import { c as
|
|
5
|
+
import { c as i, g as p } from "../../../../../../chunks/utils.js";
|
|
5
6
|
export {
|
|
6
|
-
|
|
7
|
-
|
|
7
|
+
i as createJSONPatch,
|
|
8
|
+
p as getFormatedFieldValue
|
|
8
9
|
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { AutofillSuggestions,
|
|
1
|
+
import { AutofillSuggestions, MetadataTemplateField, MetadataTemplateInstance } from '../../../../types';
|
|
2
2
|
import { TaxonomyOptionsFetcher } from '../../../metadata-editor-fields/components/metadata-taxonomy-field/types';
|
|
3
3
|
import { FormValues } from '../../types';
|
|
4
4
|
import { ERROR_CODE_METADATA_AUTOFILL_TIMEOUT, ERROR_CODE_METADATA_PRECONDITION_FAILED, ERROR_CODE_MISSING_PERMISSIONS, ERROR_CODE_UNKNOWN } from './constants';
|
|
@@ -66,12 +66,17 @@ export declare const JSONPatchOp: {
|
|
|
66
66
|
readonly TEST: "test";
|
|
67
67
|
};
|
|
68
68
|
export type JSONPatchOp = (typeof JSONPatchOp)[keyof typeof JSONPatchOp];
|
|
69
|
+
/**
|
|
70
|
+
* Per Box API spec, metadata patch values are primitives or string arrays — never complex objects.
|
|
71
|
+
* @see https://developer.box.com/reference/put-files-id-metadata-id-id
|
|
72
|
+
* */
|
|
73
|
+
export type JSONPatchValue = string | number | string[];
|
|
69
74
|
export type JSONPatchOperation = {
|
|
70
75
|
/** The operation to perform */
|
|
71
76
|
op: JSONPatchOp;
|
|
72
77
|
/** The path to the field in the JSON document */
|
|
73
78
|
path: string;
|
|
74
79
|
/** The value to add/replace if needed (optional for 'remove') */
|
|
75
|
-
value?:
|
|
80
|
+
value?: JSONPatchValue;
|
|
76
81
|
};
|
|
77
82
|
export type JSONPatchOperations = JSONPatchOperation[];
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { MetadataTemplateField, MetadataTemplateInstance } from '../../../../types';
|
|
2
2
|
import { FormValues } from '../../types';
|
|
3
|
-
import { JSONPatchOperations } from './types';
|
|
3
|
+
import { JSONPatchOperations, JSONPatchValue } from './types';
|
|
4
4
|
/**
|
|
5
5
|
* Creates JSON Patch operations from the passed in
|
|
6
6
|
* data while comparing it to the original data from props.
|
|
@@ -10,4 +10,4 @@ import { JSONPatchOperations } from './types';
|
|
|
10
10
|
* @param originalData
|
|
11
11
|
*/
|
|
12
12
|
export declare const createJSONPatch: (formValues: FormValues, originalData: MetadataTemplateInstance) => JSONPatchOperations;
|
|
13
|
-
export declare const getFormatedFieldValue: (field: MetadataTemplateField) =>
|
|
13
|
+
export declare const getFormatedFieldValue: (field: MetadataTemplateField) => JSONPatchValue;
|