@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.
@@ -1,51 +1,55 @@
1
- import i from "lodash/isArray";
2
- import m from "lodash/isEmpty";
3
- import { TEMPLATE_CUSTOM_PROPERTIES as O } from "../esm/lib/constants.js";
4
- const E = {
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
- }, l = "AI_ACCEPTED", y = (e, s) => e.value === s.value && e.level === s.level && e.isAccepted === s.isAccepted, a = (e) => e.value === void 0 || e.value === null || e.value === "" || i(e.value) && m(e.value), A = (e, s, o) => {
10
- const r = s.confidenceScore, n = o.confidenceScore;
11
- return n ? r && y(r, n) ? [] : T(e, n, r) : r ? g(e, r) : [];
12
- }, g = (e, s) => {
13
- const o = [];
14
- return s.isAccepted && o.push(u(`${e}/process`)), o.push(u(`${e}/confidenceScore`), u(`${e}/confidenceLevel`)), o;
15
- }, T = (e, s, o) => {
16
- const r = [];
17
- return s.isAccepted ? r.push(p(`${e}/process`, l)) : o?.isAccepted && r.push(u(`${e}/process`)), r.push(p(`${e}/confidenceScore`, s.value), p(`${e}/confidenceLevel`, s.level)), r;
18
- }, M = (e, s) => {
19
- const o = [], r = e.metadata.fields, n = s.templateKey === O, h = new Map(s.fields.map((t) => [t.key, t])), S = new Map(r.map((t) => [t.key, t]));
20
- return r.forEach((t) => {
21
- const c = h.get(t.key);
22
- if (!c) {
23
- o.push(p(t.key, t.value));
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
- JSON.stringify(t) !== JSON.stringify(c) && (!n && a(c) && !a(t) ? o.push(p(t.key, v(t))) : (!n && t.value !== c.value && c.value !== null && !a(t) || n && t.value !== c.value) && (o.push(f(c.key, v(c))), o.push($(t.key, v(t)))), o.push(...A(t.key, c, t)));
27
- }), s.fields.forEach((t) => {
28
- const c = S.get(t.key);
29
- (!c || !n && a(c) && !a(t)) && (o.push(f(t.key, v(t))), o.push(u(t.key)));
30
- }), o;
31
- }, v = (e) => e.type === "float" ? Number(e.value) : e.type === "taxonomy" ? e.value.map((s) => s.value) : e.type === "date" && typeof e.value == "string" ? new Date(e.value).toISOString() : e.value, f = (e, s) => ({
32
- op: E.TEST,
33
- path: `/${e}`,
34
- value: s
35
- }), p = (e, s) => ({
36
- op: E.ADD,
37
- path: `/${e}`,
38
- value: s
39
- }), u = (e) => ({
40
- op: E.REMOVE,
41
- path: `/${e}`
42
- }), $ = (e, s) => ({
43
- op: E.REPLACE,
44
- path: `/${e}`,
45
- value: s
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
- E as J,
49
- M as c,
50
- v as g
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 c, useEffect as H, useMemo as fe } from "react";
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 p } from "../../../../chunks/types.js";
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 ye } from "./editor-field-types.js";
13
+ import { editorFieldTypes as ve } from "./editor-field-types.js";
14
14
  import G from "../../messages.js";
15
- import { useViewReferenceTooltip as ve } from "./hooks/use-view-reference-tooltip.js";
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 a, jsxs as $e } from "react/jsx-runtime";
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: x,
23
+ portalElement: I,
24
24
  field: e,
25
25
  index: M,
26
- taxonomyOptionsFetcher: I,
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(), y = e.aiSuggestionState || p.Initial, u = y === p.Pending, F = y === p.Applied, P = y === p.Initial, v = ye[e.type], {
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: g
43
- } = e, X = v && !e.hidden, Y = !de(e.updateMode), o = `metadata.fields[${M}]`, Z = e.type === "taxonomy" && e.optionsRules?.multiSelect, $ = s && !!e.confidenceScore, W = $ && J(e.confidenceScore), _ = $ && !u && !J(e.confidenceScore), w = Q === e.id, b = Ae(e.targetLocation), d = $ && b && !!i, {
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
- } = ve(d), ne = C({
49
+ } = ye(m), ne = C({
50
50
  [A.aiApproved]: F || _,
51
- [A.hasSuggestion]: u,
52
- [A.hasConfidenceReview]: !u && W,
51
+ [A.hasSuggestion]: g,
52
+ [A.hasConfidenceReview]: !g && W,
53
53
  [A.dateField]: S === "date"
54
- }), m = c((t) => {
54
+ }), c = a((t) => {
55
55
  n(`${o}.aiSuggestionState`, t);
56
- }, [o, n]), h = c((t, ae = !1) => {
57
- if (n(`${o}.value`, t), m(p.Applied), s && f) {
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, m, f, D, s]), k = c(() => {
65
- m(p.Initial), n(`${o}.aiSuggestion`, void 0), s && (n(`${o}.aiSuggestionConfidenceScore`, void 0), n(`${o}.aiSuggestionTargetLocation`, void 0));
66
- }, [m, n, o, s]), te = c(() => {
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 = c(() => {
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 = c(() => {
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 = c((t) => {
77
+ }, [k, s, e.confidenceScore, n, o, i]), se = a((t) => {
77
78
  i && (z(t.target) || i(e));
78
- }, [e, i]), re = c((t) => {
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
- u && (!g || Array.isArray(g) && g.length === 0) && h(r);
87
- }, [r, u, h]), H(() => {
88
- P && r && m(p.Pending);
89
- }, [P, r, m]);
90
- const ce = fe(() => r ? ge(g, r) : !1, [r, g]);
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__ */ a(he, {
107
+ const t = /* @__PURE__ */ p(he, {
107
108
  fieldNamePrefix: o,
108
109
  fieldType: e.type,
109
110
  isTaxonomyMultiSelect: Z,
110
- children: /* @__PURE__ */ a(v, {
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: x,
122
- taxonomyOptionsFetcher: I
122
+ portalElement: I,
123
+ taxonomyOptionsFetcher: x
123
124
  })
124
125
  }, e.key);
125
- return d ? /* @__PURE__ */ a(q, {
126
+ return m ? /* @__PURE__ */ p(q, {
126
127
  content: B(G.viewOnDocument),
127
128
  open: O,
128
- children: /* @__PURE__ */ a("div", {
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, d && l.clickableField, d && w && l.selectedField),
137
- ...d && j,
138
- children: [/* @__PURE__ */ a(v, {
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: x,
151
- taxonomyOptionsFetcher: I
152
- }), u && /* @__PURE__ */ a(ke, {
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([g, r].flat().filter(Boolean))];
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
- }), !u && W && /* @__PURE__ */ a(Ce, {
164
+ }), !g && W && /* @__PURE__ */ p(Ce, {
164
165
  onAccept: te,
165
166
  onClear: ie
166
167
  })]
167
168
  }, e.key);
168
- return d ? /* @__PURE__ */ a(q, {
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 m, g as i } from "../../../../../../chunks/utils.js";
5
+ import { c as i, g as p } from "../../../../../../chunks/utils.js";
5
6
  export {
6
- m as createJSONPatch,
7
- i as getFormatedFieldValue
7
+ i as createJSONPatch,
8
+ p as getFormatedFieldValue
8
9
  };
@@ -1,4 +1,4 @@
1
- import { AutofillSuggestions, MetadataFormFieldValue, MetadataTemplateField, MetadataTemplateInstance } from '../../../../types';
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?: MetadataFormFieldValue;
80
+ value?: JSONPatchValue;
76
81
  };
77
82
  export type JSONPatchOperations = JSONPatchOperation[];
@@ -1,6 +1,6 @@
1
- import { MetadataFormFieldValue, MetadataTemplateField, MetadataTemplateInstance } from '../../../../types';
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) => MetadataFormFieldValue;
13
+ export declare const getFormatedFieldValue: (field: MetadataTemplateField) => JSONPatchValue;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@box/metadata-editor",
3
- "version": "1.63.2",
3
+ "version": "1.64.0",
4
4
  "peerDependencies": {
5
5
  "@ariakit/react": "0.4.21",
6
6
  "@box/blueprint-web": "^14.4.0",