@box/metadata-editor 0.77.0 → 0.77.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.
@@ -1,98 +1,101 @@
1
1
  import "../../../../../../styles/metadata-instance-form.css";
2
- import { Card as N } from "@box/blueprint-web";
3
- import { Formik as x, Form as P } from "formik";
4
- import { useState as c, useRef as U, useEffect as _, useMemo as L } from "react";
5
- import { TEMPLATE_CUSTOM_PROPERTIES as R } from "../../../../constants.js";
6
- import { useAutofill as B } from "../../../../utils/autofill-context.js";
7
- import { TemplateInstance as K } from "../../../metadata-editor-fields/metadata-editor-fields.js";
8
- import { MetadataEmptyState as j } from "../../../metadata-empty-state/metadata-empty-state.js";
9
- import { UnsavedChangesModal as k } from "../../../unsaved-changes-modal/unsaved-changes-modal.js";
10
- import { CustomInstance as $ } from "../custom-instance/custom-instance.js";
11
- import { DeleteConfirmationModal as w } from "../delete-confirmation-modal/delete-confirmation-modal.js";
12
- import { MetadataInstanceFormFooter as H } from "../metadata-instance-form-footer/metadata-instance-form-footer.js";
13
- import { MetadataInstanceFormHeader as J } from "../metadata-instance-form-header/metadata-instance-form-header.js";
14
- import { createJSONPatch as V } from "./utils.js";
15
- import { jsx as t, jsxs as d } from "react/jsx-runtime";
16
- const q = "_metadataInstanceForm_1hu4u_1", z = {
17
- metadataInstanceForm: q
18
- }, le = (p) => {
2
+ import { Card as P } from "@box/blueprint-web";
3
+ import { Formik as U, Form as _ } from "formik";
4
+ import { useState as d, useEffect as p, useRef as L, useMemo as R } from "react";
5
+ import { TEMPLATE_CUSTOM_PROPERTIES as B } from "../../../../constants.js";
6
+ import { useAutofill as K } from "../../../../utils/autofill-context.js";
7
+ import { TemplateInstance as j } from "../../../metadata-editor-fields/metadata-editor-fields.js";
8
+ import { MetadataEmptyState as k } from "../../../metadata-empty-state/metadata-empty-state.js";
9
+ import { UnsavedChangesModal as $ } from "../../../unsaved-changes-modal/unsaved-changes-modal.js";
10
+ import { CustomInstance as w } from "../custom-instance/custom-instance.js";
11
+ import { DeleteConfirmationModal as H } from "../delete-confirmation-modal/delete-confirmation-modal.js";
12
+ import { MetadataInstanceFormFooter as J } from "../metadata-instance-form-footer/metadata-instance-form-footer.js";
13
+ import { MetadataInstanceFormHeader as V } from "../metadata-instance-form-header/metadata-instance-form-header.js";
14
+ import { createJSONPatch as q } from "./utils.js";
15
+ import { jsx as t, jsxs as u } from "react/jsx-runtime";
16
+ const z = "_metadataInstanceForm_1hu4u_1", G = {
17
+ metadataInstanceForm: z
18
+ }, ce = (f) => {
19
19
  const {
20
- areAiSuggestionsAvailable: f,
20
+ areAiSuggestionsAvailable: g,
21
21
  isAiSuggestionsFeatureEnabled: o,
22
- isDeleteButtonDisabled: u,
23
- isUnsavedChangesModalOpen: g = !1,
24
- onCancel: h,
25
- onDelete: C,
26
- onDiscardUnsavedChanges: F,
27
- onSubmit: M,
22
+ isDeleteButtonDisabled: h,
23
+ isUnsavedChangesModalOpen: C = !1,
24
+ onCancel: F,
25
+ onDelete: S,
26
+ onDiscardUnsavedChanges: M,
27
+ onSubmit: E,
28
28
  selectedTemplateInstance: e,
29
29
  setIsUnsavedChangesModalOpen: i,
30
- taxonomyOptionsFetcher: S
31
- } = p, [E, r] = c(!1), {
30
+ taxonomyOptionsFetcher: I
31
+ } = f, [D, r] = d(!1), {
32
32
  isFetchingSuggestions: n,
33
- getAiSuggestions: I
34
- } = B(), s = e.templateKey === R, D = async (a) => {
35
- await M(a, V(a, e));
36
- }, y = (a) => {
37
- a ? i(!0) : h();
38
- }, b = () => {
33
+ getAiSuggestions: y,
34
+ clearSuggestions: m
35
+ } = K();
36
+ p(() => m(), [m]);
37
+ const s = e.templateKey === B, b = async (a) => {
38
+ await E(a, q(a, e));
39
+ }, A = (a) => {
40
+ a ? i(!0) : F();
41
+ }, O = () => {
39
42
  r(!0);
40
- }, A = {
43
+ }, T = {
41
44
  metadata: {
42
45
  ...e
43
46
  }
44
- }, m = U(null), [l, O] = c(null);
45
- _(() => {
46
- O(m.current);
47
+ }, l = L(null), [c, v] = d(null);
48
+ p(() => {
49
+ v(l.current);
47
50
  }, [e.templateKey, e.scope]);
48
- const T = L(() => {
51
+ const N = R(() => {
49
52
  const a = e.fields.length === 0;
50
- return s ? /* @__PURE__ */ t($, {
53
+ return s ? /* @__PURE__ */ t(w, {
51
54
  isLoading: n
52
- }) : a ? /* @__PURE__ */ t(j, {
55
+ }) : a ? /* @__PURE__ */ t(k, {
53
56
  isBoxAiSuggestionsFeatureEnabled: o,
54
57
  level: "instance"
55
- }) : /* @__PURE__ */ t(K, {
58
+ }) : /* @__PURE__ */ t(j, {
56
59
  disableForm: n,
57
- portalElement: l,
58
- taxonomyOptionsFetcher: S
60
+ portalElement: c,
61
+ taxonomyOptionsFetcher: I
59
62
  });
60
- }, [s, e.fields.length, n, o, l]);
61
- return /* @__PURE__ */ t(x, {
62
- initialValues: A,
63
- onSubmit: D,
63
+ }, [s, e.fields.length, n, o, c]);
64
+ return /* @__PURE__ */ t(U, {
65
+ initialValues: T,
66
+ onSubmit: b,
64
67
  children: ({
65
68
  values: a,
66
- dirty: v
67
- }) => /* @__PURE__ */ d(P, {
68
- children: [/* @__PURE__ */ d(N, {
69
- ref: m,
70
- className: z.metadataInstanceForm,
71
- children: [/* @__PURE__ */ t(J, {
72
- areAiSuggestionsAvailable: f,
69
+ dirty: x
70
+ }) => /* @__PURE__ */ u(_, {
71
+ children: [/* @__PURE__ */ u(P, {
72
+ ref: l,
73
+ className: G.metadataInstanceForm,
74
+ children: [/* @__PURE__ */ t(V, {
75
+ areAiSuggestionsAvailable: g,
73
76
  isAiSuggestionsFeatureEnabled: o && !s,
74
77
  isLoading: n,
75
- onAutofill: I,
78
+ onAutofill: y,
76
79
  templateName: e.displayName
77
- }), T, /* @__PURE__ */ t(H, {
78
- isDeleteButtonDisabled: u,
80
+ }), N, /* @__PURE__ */ t(J, {
81
+ isDeleteButtonDisabled: h,
79
82
  isLoading: n,
80
- onCancel: () => y(v),
81
- onDelete: b
83
+ onCancel: () => A(x),
84
+ onDelete: O
82
85
  })]
83
- }), /* @__PURE__ */ t(k, {
86
+ }), /* @__PURE__ */ t($, {
84
87
  onBackToEdit: () => i(!1),
85
- onDiscardChanges: F,
86
- open: g
87
- }), /* @__PURE__ */ t(w, {
88
- onConfirm: () => C(e),
88
+ onDiscardChanges: M,
89
+ open: C
90
+ }), /* @__PURE__ */ t(H, {
91
+ onConfirm: () => S(e),
89
92
  onDismiss: () => r(!1),
90
- open: E,
93
+ open: D,
91
94
  templateName: e.displayName
92
95
  })]
93
96
  })
94
97
  }, `${e.scope}.${e.templateKey}`);
95
98
  };
96
99
  export {
97
- le as MetadataInstanceForm
100
+ ce as MetadataInstanceForm
98
101
  };
@@ -1,21 +1,21 @@
1
- import { createContext as w, useState as l, useCallback as C, useMemo as S, useContext as p } from "react";
2
- import { TEMPLATE_CUSTOM_PROPERTIES as v } from "../constants.js";
3
- import { fetchSuggestions as x } from "./utils.js";
4
- import { jsx as A } from "react/jsx-runtime";
5
- const a = /* @__PURE__ */ w(null), T = ({
1
+ import { createContext as C, useState as a, useCallback as h, useMemo as p, useContext as v } from "react";
2
+ import { TEMPLATE_CUSTOM_PROPERTIES as x } from "../constants.js";
3
+ import { fetchSuggestions as A } from "./utils.js";
4
+ import { jsx as P } from "react/jsx-runtime";
5
+ const m = /* @__PURE__ */ C(null), I = ({
6
6
  children: t,
7
7
  isAiSuggestionsFeatureEnabled: o,
8
- fetchSuggestions: i = x
8
+ fetchSuggestions: i = A
9
9
  }) => {
10
- const [e, g] = l({}), [u, f] = l(!1), c = C(async (s, m) => {
10
+ const [e, u] = a({}), [c, f] = a(!1), l = h(async (s, w) => {
11
11
  let r = [];
12
12
  if (!o)
13
13
  throw new Error("AI Suggestions feature not available.");
14
- if (s === v)
14
+ if (s === x)
15
15
  throw new Error("Can't fetch suggestions for Custom Metadata instance");
16
16
  f(!0);
17
17
  try {
18
- r = await i(s, m), g({
18
+ r = await i(s, w), u({
19
19
  ...e,
20
20
  [s]: {
21
21
  ...Object.fromEntries(r.map((n) => [n.key, n.aiSuggestion]))
@@ -26,24 +26,27 @@ const a = /* @__PURE__ */ w(null), T = ({
26
26
  f(!1);
27
27
  }
28
28
  return r;
29
- }, [o, e, i]), h = S(() => ({
30
- getAiSuggestions: c,
29
+ }, [o, e, i]), g = h(() => {
30
+ u({});
31
+ }, []), S = p(() => ({
32
+ clearSuggestions: g,
33
+ getAiSuggestions: l,
31
34
  isAiSuggestionsFeatureEnabled: o,
32
- isFetchingSuggestions: u,
35
+ isFetchingSuggestions: c,
33
36
  suggestions: e
34
- }), [c, o, u, e]);
35
- return /* @__PURE__ */ A(a.Provider, {
36
- value: h,
37
+ }), [g, l, o, c, e]);
38
+ return /* @__PURE__ */ P(m.Provider, {
39
+ value: S,
37
40
  children: t
38
41
  });
39
- }, I = () => {
40
- const t = p(a);
42
+ }, O = () => {
43
+ const t = v(m);
41
44
  if (!t)
42
45
  throw new Error("useAutofill should be wrapped inside AutofillProvider");
43
46
  return t;
44
47
  };
45
48
  export {
46
- a as AutofillContext,
47
- T as AutofillContextProvider,
48
- I as useAutofill
49
+ m as AutofillContext,
50
+ I as AutofillContextProvider,
51
+ O as useAutofill
49
52
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@box/metadata-editor",
3
- "version": "0.77.0",
3
+ "version": "0.77.1",
4
4
  "peerDependencies": {
5
5
  "@ariakit/react": "0.4.14",
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": "8371b326ea09e2a07955fb57e63e15e9b14abc4c"
56
+ "gitHead": "df7ec535045306e0106c19cfd013611ba6c618f8"
57
57
  }
@@ -1,6 +1,7 @@
1
1
  import React from 'react';
2
2
  import { type AutofillSuggestions, type MetadataTemplateField, type MetadataTemplateInstance } from '../types';
3
3
  export interface AutofillContextType {
4
+ clearSuggestions: () => void;
4
5
  getAiSuggestions: (templateKey: MetadataTemplateInstance['templateKey'], fields: MetadataTemplateField[]) => Promise<MetadataTemplateField[]>;
5
6
  isFetchingSuggestions: boolean;
6
7
  isAiSuggestionsFeatureEnabled: boolean;