@box/metadata-editor 0.68.0 → 0.69.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,6 +1,6 @@
1
- import V from "clsx";
2
- import { useFormikContext as k } from "formik";
3
- import w from "lodash/isUndefined";
1
+ import I from "clsx";
2
+ import { useFormikContext as V } from "formik";
3
+ import k from "lodash/isUndefined";
4
4
  import { forwardRef as E, useState as y } from "react";
5
5
  import { AiSuggestionField as P } from "./components/ai-suggestion-field/ai-suggestion-field.js";
6
6
  import { UpdateModeFieldWrapper as R } from "./components/update-mode-field-wrapper/update-mode-field-wrapper.js";
@@ -8,8 +8,8 @@ import { editorFieldTypes as T } from "./editor-field-types.js";
8
8
  import { s as i } from "../../../../chunks/utils.js";
9
9
  import { jsx as o, jsxs as U } from "react/jsx-runtime";
10
10
  const H = /* @__PURE__ */ E(({
11
- disableForm: l,
12
- portalElement: d,
11
+ disableForm: d,
12
+ portalElement: l,
13
13
  field: e,
14
14
  index: h,
15
15
  taxonomyOptionsFetcher: u
@@ -17,11 +17,11 @@ const H = /* @__PURE__ */ E(({
17
17
  var A;
18
18
  const {
19
19
  setFieldValue: m
20
- } = k(), [x, n] = y(!0), [a, p] = y(!1), r = T[e.type], {
21
- aiSuggestion: t,
20
+ } = V(), [x, n] = y(!0), [a, p] = y(!1), r = T[e.type], {
21
+ aiSuggestion: s,
22
22
  type: c,
23
23
  value: F
24
- } = e, M = r && !e.hidden, N = !w(e.updateMode), s = `metadata.fields[${h}]`, W = e.type === "taxonomy" && ((A = e.optionsRules) == null ? void 0 : A.multiSelect), S = t && x, v = V({
24
+ } = e, M = r && !e.hidden, N = !k(e.updateMode), t = `metadata.fields[${h}]`, W = e.type === "taxonomy" && ((A = e.optionsRules) == null ? void 0 : A.multiSelect), S = s && x, v = I({
25
25
  [i.suggestionApplied]: a,
26
26
  [i.hasSuggestion]: S,
27
27
  [i.dateField]: c === "date"
@@ -32,18 +32,18 @@ const H = /* @__PURE__ */ E(({
32
32
  a && p(!1);
33
33
  };
34
34
  return N ? /* @__PURE__ */ o(R, {
35
- fieldNamePrefix: s,
35
+ fieldNamePrefix: t,
36
36
  fieldType: e.type,
37
37
  isTaxonomyMultiSelect: W,
38
38
  children: /* @__PURE__ */ o(r, {
39
39
  ref: g,
40
40
  description: e.description,
41
- disableForm: l,
42
- fieldNamePrefix: s,
41
+ disableForm: d,
42
+ fieldNamePrefix: t,
43
43
  isAiSuggestionApplied: !1,
44
44
  label: e.displayName,
45
45
  onValueEdited: f,
46
- portalElement: d,
46
+ portalElement: l,
47
47
  taxonomyOptionsFetcher: u
48
48
  })
49
49
  }, e.key) : /* @__PURE__ */ U("div", {
@@ -52,22 +52,22 @@ const H = /* @__PURE__ */ E(({
52
52
  ref: g,
53
53
  className: v,
54
54
  description: e.description,
55
- disableForm: l,
56
- fieldNamePrefix: s,
55
+ disableForm: d,
56
+ fieldNamePrefix: t,
57
57
  isAiSuggestionApplied: a,
58
58
  label: e.displayName,
59
59
  onValueEdited: f,
60
- portalElement: d,
60
+ portalElement: l,
61
61
  taxonomyOptionsFetcher: u
62
62
  }), S && /* @__PURE__ */ o(P, {
63
- aiSuggestion: t,
63
+ aiSuggestion: s,
64
64
  onAiSuggestionAppend: () => {
65
- const I = e.type === "multiSelect" ? [F, t].flat() : t;
66
- m(`${s}.value`, I), n(!1), p(!0);
65
+ const w = [...new Set([F, s].flat())];
66
+ m(`${t}.value`, w), n(!1), p(!0);
67
67
  },
68
68
  onAiSuggestionIgnore: () => n(!1),
69
69
  onAiSuggestionReplace: () => {
70
- m(`${s}.value`, t), n(!1), p(!0);
70
+ m(`${t}.value`, s), n(!1), p(!0);
71
71
  },
72
72
  type: c
73
73
  })]
@@ -6,35 +6,36 @@ const n = {
6
6
  REMOVE: "remove",
7
7
  REPLACE: "replace",
8
8
  TEST: "test"
9
- }, p = (e) => e.value === void 0 || e.value === null || e.value === "" || O(e.value) && h(e.value), S = (e, s) => {
10
- const o = [], c = e.metadata.fields, r = s.templateKey === f, v = new Map(s.fields.map((t) => [t.key, t])), m = new Map(c.map((t) => [t.key, t]));
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]));
11
11
  return c.forEach((t) => {
12
- const a = v.get(t.key);
13
- a ? JSON.stringify(t) === JSON.stringify(a) || (!r && p(a) && !p(t) ? o.push(y(t.key, u(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))) : (
14
14
  // template instance
15
- (!r && t.value !== a.value && a.value !== null && !p(t) || // custom instance
16
- r && t.value !== a.value) && (o.push(E(a.key, u(a))), o.push(M(t.key, u(t))))
17
- )) : o.push(y(t.key, t.value));
18
- }), s.fields.forEach((t) => {
19
- const a = m.get(t.key);
20
- (!a || !r && p(a) && !p(t)) && (o.push(E(t.key, u(t))), o.push(k(t.key)));
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
21
  }), o;
22
- }, u = (e) => e.type === "float" ? Number(e.value) : e.value, E = (e, s) => ({
22
+ }, u = (e) => e.type === "float" ? Number(e.value) : e.type === "taxonomy" ? e.value.map((a) => a.value) : e.value, y = (e, a) => ({
23
23
  op: n.TEST,
24
24
  path: `/${e}`,
25
- value: s
26
- }), y = (e, s) => ({
25
+ value: a
26
+ }), v = (e, a) => ({
27
27
  op: n.ADD,
28
28
  path: `/${e}`,
29
- value: s
29
+ value: a
30
30
  }), k = (e) => ({
31
31
  op: n.REMOVE,
32
32
  path: `/${e}`
33
- }), M = (e, s) => ({
33
+ }), M = (e, a) => ({
34
34
  op: n.REPLACE,
35
35
  path: `/${e}`,
36
- value: s
36
+ value: a
37
37
  });
38
38
  export {
39
- S as createJSONPatch
39
+ S as createJSONPatch,
40
+ u as getFormatedFieldValue
40
41
  };
@@ -1,50 +1,50 @@
1
1
  import "../../../../../../styles/metadata-instance.css";
2
- import { Card as h, Divider as l } from "@box/blueprint-web";
3
- import { useState as D } from "react";
4
- import { useAutofill as V } from "../../../../utils/autofill-context.js";
5
- import { MetadataEmptyState as A } from "../../../metadata-empty-state/metadata-empty-state.js";
6
- import { MetadataInstanceContent as S } from "../metadata-instance-content/metadata-instance-content.js";
7
- import { MetadataInstanceFooter as b } from "../metadata-instance-footer/metadata-instance-footer.js";
2
+ import { Card as V, Divider as n } from "@box/blueprint-web";
3
+ import { useState as A } from "react";
4
+ import { useAutofill as D } from "../../../../utils/autofill-context.js";
5
+ import { MetadataEmptyState as S } from "../../../metadata-empty-state/metadata-empty-state.js";
6
+ import { MetadataInstanceContent as b } from "../metadata-instance-content/metadata-instance-content.js";
7
+ import { MetadataInstanceFooter as g } from "../metadata-instance-footer/metadata-instance-footer.js";
8
8
  import { MetadataInstanceHeader as H } from "../metadata-instance-header/metadata-instance-header.js";
9
- import { jsxs as d, jsx as t, Fragment as u } from "react/jsx-runtime";
10
- const _ = "_topDivider_tzhlb_1", g = "_bottomDivider_tzhlb_5", n = {
9
+ import { jsxs as a, jsx as t, Fragment as u } from "react/jsx-runtime";
10
+ const _ = "_topDivider_tzhlb_1", M = "_bottomDivider_tzhlb_5", y = {
11
11
  topDivider: _,
12
- bottomDivider: g
13
- }, K = ({
12
+ bottomDivider: M
13
+ }, W = ({
14
14
  areAiSuggestionsAvailable: p,
15
- isAiSuggestionsFeatureEnabled: a,
15
+ isAiSuggestionsFeatureEnabled: d,
16
16
  onEdit: m,
17
17
  templateInstance: o
18
18
  }) => {
19
- const i = o.fields, y = i.every((s) => !s.value), f = i.some((s) => !s.value), c = i.length > 0, [e, r] = D(!0), {
20
- getAiSuggestions: v
21
- } = V(), E = () => {
22
- m(o), v(o.templateKey, i);
19
+ const e = o.fields, l = (s) => !s.value || Array.isArray(s.value) && s.value.length === 0, c = e.every(l), h = e.some(l), v = e.length > 0, [i, r] = A(!0), {
20
+ getAiSuggestions: E
21
+ } = D(), f = () => {
22
+ m(o), E(o.templateKey, e);
23
23
  };
24
- return /* @__PURE__ */ d(h, {
24
+ return /* @__PURE__ */ a(V, {
25
25
  children: [/* @__PURE__ */ t(H, {
26
26
  areAiSuggestionsAvailable: p,
27
27
  canEdit: o.canEdit,
28
- isAiSuggestionsFeatureEnabled: a,
29
- onAutofill: E,
28
+ isAiSuggestionsFeatureEnabled: d,
29
+ onAutofill: f,
30
30
  onEdit: () => m(o),
31
31
  templateName: o == null ? void 0 : o.displayName
32
- }), /* @__PURE__ */ t(l, {
33
- className: n.topDivider
34
- }), e && y ? /* @__PURE__ */ t(A, {
35
- isAnyEmptyValueHidden: c,
36
- isBoxAiSuggestionsFeatureEnabled: a,
32
+ }), /* @__PURE__ */ t(n, {
33
+ className: y.topDivider
34
+ }), i && c ? /* @__PURE__ */ t(S, {
35
+ isAnyEmptyValueHidden: v,
36
+ isBoxAiSuggestionsFeatureEnabled: d,
37
37
  level: "instance",
38
38
  onShowEmptyValues: () => r(!1)
39
- }) : /* @__PURE__ */ d(u, {
40
- children: [/* @__PURE__ */ t(S, {
41
- shouldHideEmptyValues: e,
39
+ }) : /* @__PURE__ */ a(u, {
40
+ children: [/* @__PURE__ */ t(b, {
41
+ shouldHideEmptyValues: i,
42
42
  templateInstance: o
43
- }), f && /* @__PURE__ */ d(u, {
44
- children: [/* @__PURE__ */ t(l, {
45
- className: n.bottomDivider
46
- }), /* @__PURE__ */ t(b, {
47
- isAnyEmptyValueHidden: e,
43
+ }), h && /* @__PURE__ */ a(u, {
44
+ children: [/* @__PURE__ */ t(n, {
45
+ className: y.bottomDivider
46
+ }), /* @__PURE__ */ t(g, {
47
+ isAnyEmptyValueHidden: i,
48
48
  onHideEmptyValues: () => r(!0),
49
49
  onShowEmptyValues: () => r(!1)
50
50
  })]
@@ -53,5 +53,5 @@ const _ = "_topDivider_tzhlb_1", g = "_bottomDivider_tzhlb_5", n = {
53
53
  });
54
54
  };
55
55
  export {
56
- K as MetadataInstance
56
+ W as MetadataInstance
57
57
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@box/metadata-editor",
3
- "version": "0.68.0",
3
+ "version": "0.69.0",
4
4
  "peerDependencies": {
5
5
  "@ariakit/react": "0.4.5",
6
6
  "@box/blueprint-web": "^7.30.3",
@@ -53,5 +53,5 @@
53
53
  "**/*.css"
54
54
  ],
55
55
  "license": "SEE LICENSE IN LICENSE",
56
- "gitHead": "cb9d1103ad345206637fdc35e1650751ae752a0a"
56
+ "gitHead": "cb2d8bc467948346206919d6efae781b79e70aaf"
57
57
  }
@@ -1,4 +1,4 @@
1
- import { type MetadataTemplateInstance } from '../../../../types';
1
+ import { type MetadataFormFieldValue, type MetadataTemplateField, type MetadataTemplateInstance } from '../../../../types';
2
2
  import { type FormValues } from '../../types';
3
3
  import { type JSONPatchOperations } from './types';
4
4
  /**
@@ -10,3 +10,4 @@ import { type 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;
@@ -6,6 +6,8 @@ declare const floatField: MetadataTemplateField;
6
6
  declare const multiSelectField: MetadataTemplateField;
7
7
  declare const taxonomySingleSelectSingleLevelField: MetadataTemplateField;
8
8
  declare const taxonomyMultiSelectSingleLevelField: MetadataTemplateField;
9
+ declare const taxonomySingleSelectSingleLevelFieldWithValue: MetadataTemplateField;
10
+ declare const taxonomyMultiSelectSingleLevelFieldWithValue: MetadataTemplateField;
9
11
  declare const hiddenField: MetadataTemplateField;
10
12
  declare const noValueField: MetadataTemplateField;
11
13
  declare const allFieldsTemplate: MetadataTemplate;
@@ -16,6 +18,7 @@ declare const templates: MetadataTemplate[];
16
18
  declare const customTemplate: MetadataTemplate;
17
19
  declare const templateOptions: MetadataTemplateOption[];
18
20
  declare const fields: MetadataTemplateField[];
21
+ declare const floatInstanceField: MetadataTemplateField;
19
22
  declare const allFieldsTemplateInstance: MetadataTemplateInstance;
20
23
  declare const templateInstanceWithoutEmptyValues: MetadataTemplateInstance;
21
24
  declare const emptyTemplateInstance: MetadataTemplateInstance;
@@ -35,4 +38,4 @@ declare const firstTemplateInstanceFieldsWithSuggestions: MetadataTemplateField[
35
38
  declare const secondTemplateInstance: MetadataTemplate;
36
39
  declare const secondTemplateSuggestions: AutofillSuggestions;
37
40
  declare const secondTemplateInstanceFieldsWithSuggestions: MetadataTemplateField[];
38
- export { allFieldsSuggestions, allFieldsTemplate, allFieldsTemplateInstance, allFieldsWithAiSuggestions, customTemplate, customTemplateInstance, customTemplateInstanceWithAllFieldsEmpty, customTemplateInstanceWithoutEditPermissions, customTemplateInstanceWithoutEmptyValues, dateField, emptyCustomTemplateInstance, emptyTemplateInstance, enumField, fields, firstTemplateInstance, firstTemplateInstanceFieldsWithSuggestions, firstTemplateSuggestions, floatField, hiddenField, multiSelectField, noFieldsTemplate, nonHiddenFieldsTemplate, nonHiddenFieldsWithValuesTemplate, noValueField, secondTemplateInstance, secondTemplateInstanceFieldsWithSuggestions, secondTemplateSuggestions, stringField, taxonomyMultiSelectSingleLevelField, taxonomySingleSelectSingleLevelField, templateInstancesList, templateInstanceWithAllFieldsEmpty, templateInstanceWithoutEditPermissions, templateInstanceWithoutEmptyValues, templateOptions, templates, };
41
+ export { allFieldsSuggestions, allFieldsTemplate, allFieldsTemplateInstance, allFieldsWithAiSuggestions, customTemplate, customTemplateInstance, customTemplateInstanceWithAllFieldsEmpty, customTemplateInstanceWithoutEditPermissions, customTemplateInstanceWithoutEmptyValues, dateField, emptyCustomTemplateInstance, emptyTemplateInstance, enumField, fields, firstTemplateInstance, firstTemplateInstanceFieldsWithSuggestions, firstTemplateSuggestions, floatField, floatInstanceField, hiddenField, multiSelectField, noFieldsTemplate, nonHiddenFieldsTemplate, nonHiddenFieldsWithValuesTemplate, noValueField, secondTemplateInstance, secondTemplateInstanceFieldsWithSuggestions, secondTemplateSuggestions, stringField, taxonomyMultiSelectSingleLevelField, taxonomyMultiSelectSingleLevelFieldWithValue, taxonomySingleSelectSingleLevelField, taxonomySingleSelectSingleLevelFieldWithValue, templateInstancesList, templateInstanceWithAllFieldsEmpty, templateInstanceWithoutEditPermissions, templateInstanceWithoutEmptyValues, templateOptions, templates, };