@box/metadata-editor 0.118.0 → 0.119.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.
@@ -4,52 +4,53 @@ import { TEMPLATE_CUSTOM_PROPERTIES as S } from "../esm/lib/constants.js";
4
4
  import { MetadataInstanceFormFooter as w } from "../esm/lib/components/metadata-instance-editor/subcomponents/metadata-instance-form-footer/metadata-instance-form-footer.js";
5
5
  import { MetadataInstanceFormHeader as M } from "../esm/lib/components/metadata-instance-editor/subcomponents/metadata-instance-form-header/metadata-instance-form-header.js";
6
6
  import { jsx as t, jsxs as b } from "react/jsx-runtime";
7
- import '../styles/metadata-instance-form-card-wrapper.css';const v = "_metadataInstanceForm_1e6l2_1", x = "_wrapperGradient_1e6l2_7", D = "_suggestionsFetching_1e6l2_12", I = "_metadataInstanceFormContent_1e6l2_18", L = "_showOverlay_1e6l2_25", s = {
7
+ import '../styles/metadata-instance-form-card-wrapper.css';const v = "_metadataInstanceForm_1e6l2_1", x = "_wrapperGradient_1e6l2_7", D = "_suggestionsFetching_1e6l2_12", I = "_metadataInstanceFormContent_1e6l2_18", L = "_showOverlay_1e6l2_25", n = {
8
8
  metadataInstanceForm: v,
9
9
  wrapperGradient: x,
10
10
  suggestionsFetching: D,
11
11
  metadataInstanceFormContent: I,
12
12
  showOverlay: L
13
- }, B = (n) => {
13
+ }, B = (o) => {
14
14
  const {
15
- areAiSuggestionsAvailable: o,
16
- children: r,
17
- className: i,
18
- formRef: g,
19
- isAdvancedExtractAgentEnabled: m = !1,
20
- isAiSuggestionsFeatureEnabled: l,
21
- isBetaLanguageEnabled: d,
22
- isLargeFile: c = !1,
23
- isDeleteButtonDisabled: F,
24
- suggestions: u,
15
+ areAiSuggestionsAvailable: r,
16
+ children: i,
17
+ className: g,
18
+ formRef: m,
19
+ isAdvancedExtractAgentEnabled: l = !1,
20
+ isAiSuggestionsFeatureEnabled: d,
21
+ isBetaLanguageEnabled: c,
22
+ isLargeFile: F = !1,
23
+ isDeleteButtonDisabled: u,
24
+ suggestions: _,
25
25
  isFetchingSuggestions: e,
26
- isFormDirty: _ = !1,
26
+ isFormDirty: s = !1,
27
27
  selectedTemplateInstance: a,
28
28
  getAiSuggestions: p,
29
29
  handleCancel: h,
30
30
  handleDelete: f
31
- } = n, A = (a == null ? void 0 : a.templateKey) === S, C = !!u[a == null ? void 0 : a.templateKey];
31
+ } = o, A = (a == null ? void 0 : a.templateKey) === S, C = !!_[a == null ? void 0 : a.templateKey];
32
32
  return /* @__PURE__ */ t("div", {
33
- className: e && s.wrapperGradient,
33
+ className: e && n.wrapperGradient,
34
34
  children: /* @__PURE__ */ b(E, {
35
- ref: g,
36
- className: y(i, {
37
- [s.suggestionsFetching]: e
35
+ ref: m,
36
+ className: y(g, {
37
+ [n.suggestionsFetching]: e
38
38
  }),
39
39
  children: [/* @__PURE__ */ t(M, {
40
- areAiSuggestionsAvailable: o,
40
+ areAiSuggestionsAvailable: r,
41
41
  hasSuggestions: C,
42
- isAdvancedExtractAgentEnabled: m,
43
- isAiSuggestionsFeatureEnabled: l && !A,
44
- isBetaLanguageEnabled: d,
45
- isLargeFile: c,
42
+ isAdvancedExtractAgentEnabled: l,
43
+ isAiSuggestionsFeatureEnabled: d && !A,
44
+ isBetaLanguageEnabled: c,
45
+ isLargeFile: F,
46
46
  isLoading: e,
47
47
  onAutofill: p,
48
48
  templateName: a == null ? void 0 : a.displayName
49
- }), a && r, /* @__PURE__ */ t(w, {
50
- isDeleteButtonDisabled: F,
49
+ }), a && i, /* @__PURE__ */ t(w, {
50
+ isDeleteButtonDisabled: u,
51
+ isFormDirty: s,
51
52
  isLoading: e,
52
- onCancel: () => h(_),
53
+ onCancel: () => h(s),
53
54
  onDelete: f
54
55
  })]
55
56
  })
@@ -57,5 +58,5 @@ import '../styles/metadata-instance-form-card-wrapper.css';const v = "_metadataI
57
58
  };
58
59
  export {
59
60
  B as M,
60
- s
61
+ n as s
61
62
  };
@@ -1,42 +1,47 @@
1
1
  import h from "lodash/isEmpty";
2
- import O from "lodash/isArray";
3
- import { TEMPLATE_CUSTOM_PROPERTIES as f } from "../esm/lib/constants.js";
2
+ import l from "lodash/isArray";
3
+ import { TEMPLATE_CUSTOM_PROPERTIES as O } from "../esm/lib/constants.js";
4
+ import { defaultMetadataValueMap as M } from "../esm/lib/defaults.js";
4
5
  const n = {
5
6
  ADD: "add",
6
7
  REMOVE: "remove",
7
8
  REPLACE: "replace",
8
9
  TEST: "test"
9
- }, p = (e) => e.value === void 0 || e.value === null || e.value === "" || O(e.value) && h(e.value), S = (e, a) => {
10
- const o = [], c = e.metadata.fields, r = a.templateKey === f, E = new Map(a.fields.map((t) => [t.key, t])), m = new Map(c.map((t) => [t.key, t]));
10
+ }, o = (a) => a.value === void 0 || a.value === null || a.value === "" || l(a.value) && h(a.value), P = (a, e) => {
11
+ const p = [], c = a.metadata.fields, r = e.templateKey === O, y = new Map(e.fields.map((t) => [t.key, t])), E = new Map(c.map((t) => [t.key, t]));
11
12
  return c.forEach((t) => {
12
- const s = E.get(t.key);
13
- s ? JSON.stringify(t) === JSON.stringify(s) || (!r && p(s) && !p(t) ? o.push(v(t.key, u(t))) : (
13
+ const s = y.get(t.key);
14
+ s ? JSON.stringify(t) === JSON.stringify(s) || (!r && o(s) && !o(t) ? p.push(v(t.key, u(t))) : (
14
15
  // template instance
15
- (!r && t.value !== s.value && s.value !== null && !p(t) || // custom instance
16
- r && t.value !== s.value) && (o.push(y(s.key, u(s))), o.push(M(t.key, u(t))))
17
- )) : o.push(v(t.key, t.value));
18
- }), a.fields.forEach((t) => {
19
- const s = m.get(t.key);
20
- (!s || !r && p(s) && !p(t)) && (o.push(y(t.key, u(t))), o.push(k(t.key)));
21
- }), o;
22
- }, u = (e) => e.type === "float" ? Number(e.value) : e.type === "taxonomy" ? e.value.map((a) => a.value) : e.value, y = (e, a) => ({
16
+ (!r && t.value !== s.value && s.value !== null && !o(t) || // custom instance
17
+ r && t.value !== s.value) && (p.push(m(s.key, u(s))), p.push(k(t.key, u(t))))
18
+ )) : p.push(v(t.key, t.value));
19
+ }), e.fields.forEach((t) => {
20
+ const s = E.get(t.key);
21
+ (!s || !r && o(s) && !o(t)) && (p.push(m(t.key, u(t))), p.push(f(t.key)));
22
+ }), p;
23
+ }, u = (a) => a.type === "float" ? Number(a.value) : a.type === "taxonomy" ? a.value.map((e) => e.value) : a.value, g = (a) => a.map((e) => ({
24
+ ...e,
25
+ value: e.value ?? M[e.type]
26
+ })), m = (a, e) => ({
23
27
  op: n.TEST,
24
- path: `/${e}`,
25
- value: a
26
- }), v = (e, a) => ({
28
+ path: `/${a}`,
29
+ value: e
30
+ }), v = (a, e) => ({
27
31
  op: n.ADD,
28
- path: `/${e}`,
29
- value: a
30
- }), k = (e) => ({
32
+ path: `/${a}`,
33
+ value: e
34
+ }), f = (a) => ({
31
35
  op: n.REMOVE,
32
- path: `/${e}`
33
- }), M = (e, a) => ({
36
+ path: `/${a}`
37
+ }), k = (a, e) => ({
34
38
  op: n.REPLACE,
35
- path: `/${e}`,
36
- value: a
39
+ path: `/${a}`,
40
+ value: e
37
41
  });
38
42
  export {
39
43
  n as J,
40
- S as c,
44
+ P as c,
45
+ g as e,
41
46
  u as g
42
47
  };
@@ -10,20 +10,20 @@ import { TEMPLATE_CUSTOM_PROPERTIES as I } from "../../../../constants.js";
10
10
  import { useAutofill as T } from "../../../../utils/autofill-context.js";
11
11
  import { TemplateInstance as oo } from "../../../metadata-editor-fields/metadata-editor-fields.js";
12
12
  import { MetadataEmptyState as ro } from "../../../metadata-empty-state/metadata-empty-state.js";
13
- import { AutofillOverlay as to } from "../autofill-overlay/autofill-overlay.js";
14
- import { CustomInstance as io } from "../custom-instance/custom-instance.js";
15
- import { c as ao } from "../../../../../../chunks/utils.js";
16
- import { s as u, M as no } from "../../../../../../chunks/metadata-instance-form-card-wrapper.js";
17
- import { jsx as i, jsxs as D } from "react/jsx-runtime";
13
+ import { AutofillOverlay as io } from "../autofill-overlay/autofill-overlay.js";
14
+ import { CustomInstance as to } from "../custom-instance/custom-instance.js";
15
+ import { e as ao, c as no } from "../../../../../../chunks/utils.js";
16
+ import { s as u, M as so } from "../../../../../../chunks/metadata-instance-form-card-wrapper.js";
17
+ import { jsx as t, jsxs as D } from "react/jsx-runtime";
18
18
  import { UnsavedChangesModal as eo } from "../../../unsaved-changes-modal/unsaved-changes-modal.js";
19
- const so = ({
20
- dirty: s,
19
+ const mo = ({
20
+ dirty: e,
21
21
  onChange: m,
22
22
  values: r
23
23
  }) => {
24
24
  const n = O(r);
25
- return s && !Y(n.current.metadata.fields, r.metadata.fields) && (n.current = r, m(r)), null;
26
- }, Ao = (s) => {
25
+ return e && !Y(n.current.metadata.fields, r.metadata.fields) && (n.current = r, m(r)), null;
26
+ }, vo = (e) => {
27
27
  const {
28
28
  areAiSuggestionsAvailable: m,
29
29
  customRef: r,
@@ -44,70 +44,71 @@ const so = ({
44
44
  onDiscardUnsavedChanges: U,
45
45
  onSubmit: B,
46
46
  setIsUnsavedChangesModalOpen: p,
47
- taxonomyOptionsFetcher: c
48
- } = s, w = k ?? no, [K, h] = S(!1), {
47
+ taxonomyOptionsFetcher: h
48
+ } = e, V = k ?? so, [W, C] = S(!1), {
49
49
  isFetchingSuggestions: a,
50
- isLongLoading: C,
51
- getAiSuggestions: V,
52
- clearState: E,
53
- suggestions: W
50
+ isLongLoading: E,
51
+ getAiSuggestions: w,
52
+ clearState: c,
53
+ suggestions: K
54
54
  } = T();
55
55
  y(() => () => {
56
- E();
57
- }, [E, o == null ? void 0 : o.id]);
58
- const F = (o == null ? void 0 : o.templateKey) === I, j = async (t) => {
59
- await B(t, ao(t, o));
60
- }, _ = (t) => {
61
- t ? p(!0) : N();
56
+ c();
57
+ }, [c, o == null ? void 0 : o.id]);
58
+ const F = (o == null ? void 0 : o.templateKey) === I, j = async (i) => {
59
+ await B(i, no(i, o));
60
+ }, _ = (i) => {
61
+ i ? p(!0) : N();
62
62
  }, $ = () => {
63
- h(!0);
63
+ C(!0);
64
64
  }, q = {
65
65
  metadata: {
66
- ...o
66
+ ...o,
67
+ fields: ao((o == null ? void 0 : o.fields) ?? [])
67
68
  }
68
69
  }, M = O(null), [b, J] = S(null);
69
70
  y(() => {
70
71
  J(r ?? M.current);
71
72
  }, [r, o == null ? void 0 : o.templateKey, o == null ? void 0 : o.scope]);
72
73
  const z = Z(() => {
73
- const t = (o == null ? void 0 : o.fields.length) === 0;
74
+ const i = (o == null ? void 0 : o.fields.length) === 0;
74
75
  if (F)
75
- return /* @__PURE__ */ i(io, {
76
+ return /* @__PURE__ */ t(to, {
76
77
  isLoading: a
77
78
  });
78
- if (t)
79
- return /* @__PURE__ */ i(ro, {
79
+ if (i)
80
+ return /* @__PURE__ */ t(ro, {
80
81
  isBoxAiSuggestionsFeatureEnabled: f,
81
82
  level: "instance"
82
83
  });
83
- const e = !!(a || l);
84
+ const s = !!(a || l);
84
85
  return /* @__PURE__ */ D("div", {
85
- className: H(u.metadataInstanceFormContent, e && u.showOverlay),
86
- children: [/* @__PURE__ */ i(to, {
86
+ className: H(u.metadataInstanceFormContent, s && u.showOverlay),
87
+ children: [/* @__PURE__ */ t(io, {
87
88
  errorCode: l,
88
89
  isFetchingSuggestions: a,
89
- isLongLoading: C
90
- }), /* @__PURE__ */ i(oo, {
90
+ isLongLoading: E
91
+ }), /* @__PURE__ */ t(oo, {
91
92
  disableForm: a,
92
93
  isMultilevelTaxonomyFieldEnabled: d,
93
94
  portalElement: r ?? b,
94
- taxonomyOptionsFetcher: c
95
+ taxonomyOptionsFetcher: h
95
96
  })]
96
97
  });
97
- }, [o == null ? void 0 : o.fields.length, F, a, C, r, b, c, f, d, l]);
98
- return /* @__PURE__ */ i(Q, {
98
+ }, [o == null ? void 0 : o.fields.length, F, a, E, r, b, h, f, d, l]);
99
+ return /* @__PURE__ */ t(Q, {
99
100
  initialValues: q,
100
101
  onSubmit: j,
101
102
  children: ({
102
- values: t,
103
- dirty: e
103
+ values: i,
104
+ dirty: s
104
105
  }) => /* @__PURE__ */ D(X, {
105
- children: [/* @__PURE__ */ i(w, {
106
+ children: [/* @__PURE__ */ t(V, {
106
107
  areAiSuggestionsAvailable: m,
107
108
  className: u.metadataInstanceForm,
108
109
  formRef: M,
109
- formValues: t,
110
- getAiSuggestions: V,
110
+ formValues: i,
111
+ getAiSuggestions: w,
111
112
  handleCancel: _,
112
113
  handleDelete: $,
113
114
  isAdvancedExtractAgentEnabled: x,
@@ -115,29 +116,29 @@ const so = ({
115
116
  isBetaLanguageEnabled: A,
116
117
  isDeleteButtonDisabled: v,
117
118
  isFetchingSuggestions: a,
118
- isFormDirty: e,
119
+ isFormDirty: s,
119
120
  isLargeFile: n,
120
121
  selectedTemplateInstance: o,
121
- suggestions: W,
122
+ suggestions: K,
122
123
  children: o && z
123
- }), g && /* @__PURE__ */ i(so, {
124
- dirty: e,
124
+ }), g && /* @__PURE__ */ t(mo, {
125
+ dirty: s,
125
126
  onChange: g,
126
- values: t
127
- }), /* @__PURE__ */ i(eo, {
127
+ values: i
128
+ }), /* @__PURE__ */ t(eo, {
128
129
  onBackToEdit: () => p(!1),
129
130
  onDiscardChanges: U,
130
131
  open: R
131
- }), /* @__PURE__ */ i(G, {
132
+ }), /* @__PURE__ */ t(G, {
132
133
  isCheckboxEnabled: L,
133
134
  onConfirm: () => P(o),
134
- onDismiss: () => h(!1),
135
- open: K,
135
+ onDismiss: () => C(!1),
136
+ open: W,
136
137
  templateName: o == null ? void 0 : o.displayName
137
138
  })]
138
139
  })
139
140
  }, `${o == null ? void 0 : o.scope}.${o == null ? void 0 : o.templateKey}`);
140
141
  };
141
142
  export {
142
- Ao as MetadataInstanceForm
143
+ vo as MetadataInstanceForm
143
144
  };
@@ -1,8 +1,10 @@
1
1
  import "lodash/isEmpty";
2
2
  import "lodash/isArray";
3
- import { c as m, g as i } from "../../../../../../chunks/utils.js";
3
+ import { c as m, e as l, g as p } from "../../../../../../chunks/utils.js";
4
4
  import "../../../../constants.js";
5
+ import "../../../../defaults.js";
5
6
  export {
6
7
  m as createJSONPatch,
7
- i as getFormatedFieldValue
8
+ l as enrichFieldsWithInitialValues,
9
+ p as getFormatedFieldValue
8
10
  };
@@ -1,29 +1,30 @@
1
- import { TextButton as b, Button as r } from "@box/blueprint-web";
2
- import { useFormikContext as g } from "formik";
3
- import { useIntl as B } from "react-intl";
1
+ import { TextButton as g, Button as r } from "@box/blueprint-web";
2
+ import { useFormikContext as B } from "formik";
3
+ import { useIntl as F } from "react-intl";
4
4
  import o from "./messages.js";
5
5
  import { jsx as e, jsxs as i } from "react/jsx-runtime";
6
- import '../../../../../../styles/metadata-instance-form-footer.css';const F = "_metadataInstanceFormFooter_sqpiw_1", f = "_buttonsContainer_sqpiw_7", p = "_buttons_sqpiw_7", n = {
7
- metadataInstanceFormFooter: F,
8
- buttonsContainer: f,
9
- buttons: p
10
- }, I = ({
6
+ import '../../../../../../styles/metadata-instance-form-footer.css';const f = "_metadataInstanceFormFooter_sqpiw_1", p = "_buttonsContainer_sqpiw_7", _ = "_buttons_sqpiw_7", n = {
7
+ metadataInstanceFormFooter: f,
8
+ buttonsContainer: p,
9
+ buttons: _
10
+ }, M = ({
11
11
  isDeleteButtonDisabled: d,
12
+ isFormDirty: l = !1,
12
13
  isLoading: m,
13
14
  onCancel: c,
14
- onDelete: l
15
+ onDelete: u
15
16
  }) => {
16
- const t = B(), {
17
+ const t = F(), {
17
18
  isSubmitting: s,
18
- submitForm: u
19
- } = g(), a = m || s;
19
+ submitForm: b
20
+ } = B(), a = m || s;
20
21
  return /* @__PURE__ */ e("div", {
21
22
  className: n.metadataInstanceFormFooter,
22
23
  children: /* @__PURE__ */ i("div", {
23
24
  className: n.buttonsContainer,
24
- children: [/* @__PURE__ */ e(b, {
25
+ children: [/* @__PURE__ */ e(g, {
25
26
  disabled: a || d,
26
- onClick: l,
27
+ onClick: u,
27
28
  "data-target-id": "TextButton-deleteButton",
28
29
  children: t.formatMessage(o.deleteButton)
29
30
  }), /* @__PURE__ */ i("div", {
@@ -36,10 +37,10 @@ import '../../../../../../styles/metadata-instance-form-footer.css';const F = "_
36
37
  "data-target-id": "Button-cancelButton",
37
38
  children: t.formatMessage(o.cancelButton)
38
39
  }), /* @__PURE__ */ e(r, {
39
- disabled: a,
40
+ disabled: a || !l,
40
41
  loading: s,
41
42
  loadingAriaLabel: t.formatMessage(o.loadingAriaLabel),
42
- onClick: u,
43
+ onClick: b,
43
44
  size: "large",
44
45
  "data-target-id": "Button-saveButton",
45
46
  children: t.formatMessage(o.saveButton)
@@ -49,5 +50,5 @@ import '../../../../../../styles/metadata-instance-form-footer.css';const F = "_
49
50
  });
50
51
  };
51
52
  export {
52
- I as MetadataInstanceFormFooter
53
+ M as MetadataInstanceFormFooter
53
54
  };
@@ -11,3 +11,4 @@ import { JSONPatchOperations } from './types';
11
11
  */
12
12
  export declare const createJSONPatch: (formValues: FormValues, originalData: MetadataTemplateInstance) => JSONPatchOperations;
13
13
  export declare const getFormatedFieldValue: (field: MetadataTemplateField) => MetadataFormFieldValue;
14
+ export declare const enrichFieldsWithInitialValues: (fields: MetadataTemplateField[]) => MetadataTemplateField[];
@@ -1,2 +1,2 @@
1
1
  import { MetadataInstanceFormFooterProps } from './types';
2
- export declare const MetadataInstanceFormFooter: ({ isDeleteButtonDisabled, isLoading, onCancel, onDelete, }: MetadataInstanceFormFooterProps) => import("react/jsx-runtime").JSX.Element;
2
+ export declare const MetadataInstanceFormFooter: ({ isDeleteButtonDisabled, isFormDirty, isLoading, onCancel, onDelete, }: MetadataInstanceFormFooterProps) => import("react/jsx-runtime").JSX.Element;
@@ -1,5 +1,6 @@
1
1
  export type MetadataInstanceFormFooterProps = {
2
2
  isDeleteButtonDisabled: boolean;
3
+ isFormDirty?: boolean;
3
4
  isLoading: boolean;
4
5
  onCancel: () => void;
5
6
  onDelete: () => void;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@box/metadata-editor",
3
- "version": "0.118.0",
3
+ "version": "0.119.1",
4
4
  "peerDependencies": {
5
5
  "@ariakit/react": "0.4.15",
6
6
  "@box/box-ai-agent-selector": "^0.41.7",
@@ -15,11 +15,11 @@
15
15
  },
16
16
  "devDependencies": {
17
17
  "@ariakit/react": "0.4.15",
18
- "@box/box-ai-agent-selector": "^0.46.0",
18
+ "@box/box-ai-agent-selector": "^0.46.1",
19
19
  "@box/babel-plugin-target-attributes": "1.3.0",
20
- "@box/blueprint-web": "^12.24.0",
21
- "@box/blueprint-web-assets": "^4.56.6",
22
- "@box/storybook-utils": "^0.13.10",
20
+ "@box/blueprint-web": "^12.25.0",
21
+ "@box/blueprint-web-assets": "^4.57.0",
22
+ "@box/storybook-utils": "^0.13.11",
23
23
  "@testing-library/react": "^15.0.6",
24
24
  "react": "^18.3.0",
25
25
  "react-dom": "^18.3.0",