@box/metadata-editor 0.67.0 → 0.67.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,74 +1,85 @@
1
1
  import "../../../../../../styles/metadata-instance-form-header.css";
2
- import { Focusable as k } from "@ariakit/react";
3
- import { Text as v, Tooltip as f, Button as A } from "@box/blueprint-web";
2
+ import { Focusable as v } from "@ariakit/react";
3
+ import { Text as K, Tooltip as h, Button as k } from "@box/blueprint-web";
4
4
  import { BoxAiLogo as S } from "@box/blueprint-web-assets/icons/Logo";
5
- import { useFormikContext as j, getIn as g } from "formik";
6
- import { useState as C, useRef as E, useEffect as K } from "react";
5
+ import { useFormikContext as j, getIn as i } from "formik";
6
+ import { useState as C, useRef as E, useEffect as I } from "react";
7
7
  import { useIntl as L } from "react-intl";
8
- import o from "./messages.js";
9
- import { jsx as t, jsxs as N } from "react/jsx-runtime";
10
- const R = "_metadataInstanceFormHeader_rdx5o_1", W = "_title_rdx5o_9", p = {
11
- metadataInstanceFormHeader: R,
12
- title: W
13
- }, Q = ({
14
- areAiSuggestionsAvailable: h,
15
- isAiSuggestionsFeatureEnabled: I,
16
- isLoading: c,
17
- templateName: x,
18
- onAutofill: B
8
+ import { useAutofill as N } from "../../../../utils/autofill-context.js";
9
+ import r from "./messages.js";
10
+ import { jsx as o, jsxs as R } from "react/jsx-runtime";
11
+ const W = "_metadataInstanceFormHeader_rdx5o_1", D = "_title_rdx5o_9", x = {
12
+ metadataInstanceFormHeader: W,
13
+ title: D
14
+ }, X = ({
15
+ areAiSuggestionsAvailable: B,
16
+ isAiSuggestionsFeatureEnabled: F,
17
+ isLoading: d,
18
+ templateName: T,
19
+ onAutofill: y
19
20
  }) => {
20
21
  const {
21
- isSubmitting: F,
22
- values: m,
23
- setFieldValue: T
24
- } = j(), e = L(), [y, b] = C(!1), n = E(null), M = async () => {
25
- const a = g(m, "metadata.fields"), i = g(m, "metadata.templateKey"), r = await B(i, a);
26
- T("metadata.fields", a.map((l) => {
27
- const u = r == null ? void 0 : r.find((H) => H.key === l.key);
28
- return u ? {
29
- ...l,
30
- aiSuggestion: u.aiSuggestion
31
- } : l;
32
- }));
33
- }, s = x ?? e.formatMessage(o.customInstanceTitle);
34
- K(() => {
35
- if (n.current) {
22
+ isSubmitting: b,
23
+ values: n,
24
+ setFieldValue: u
25
+ } = j(), s = L(), {
26
+ suggestions: t
27
+ } = N(), [M, _] = C(!1), l = E(null);
28
+ I(() => {
29
+ if (t) {
30
+ const e = i(n, "metadata.fields"), a = i(n, "metadata.templateKey");
31
+ u("metadata.fields", e.map((c) => {
32
+ var g;
33
+ const p = (g = t == null ? void 0 : t[a]) == null ? void 0 : g[c.key];
34
+ return p ? {
35
+ ...c,
36
+ aiSuggestion: p
37
+ } : c;
38
+ }));
39
+ }
40
+ }, [t, u]);
41
+ const A = () => {
42
+ const e = i(n, "metadata.fields"), a = i(n, "metadata.templateKey");
43
+ y(a, e);
44
+ }, m = T ?? s.formatMessage(r.customInstanceTitle);
45
+ I(() => {
46
+ if (l.current) {
36
47
  const {
37
- scrollWidth: a,
38
- clientWidth: i
39
- } = n.current;
40
- b(a > i);
48
+ scrollWidth: e,
49
+ clientWidth: a
50
+ } = l.current;
51
+ _(e > a);
41
52
  }
42
- }, [s]);
43
- const d = /* @__PURE__ */ t(v, {
44
- ref: n,
53
+ }, [m]);
54
+ const f = /* @__PURE__ */ o(K, {
55
+ ref: l,
45
56
  as: "h1",
46
- className: p.title,
57
+ className: x.title,
47
58
  variant: "titleMedium",
48
- children: s
49
- }), _ = !h || F || c;
50
- return /* @__PURE__ */ N("div", {
51
- className: p.metadataInstanceFormHeader,
52
- children: [y ? /* @__PURE__ */ t(f, {
53
- content: s,
54
- children: /* @__PURE__ */ t(k, {
55
- render: d
59
+ children: m
60
+ }), H = !B || b || d;
61
+ return /* @__PURE__ */ R("div", {
62
+ className: x.metadataInstanceFormHeader,
63
+ children: [M ? /* @__PURE__ */ o(h, {
64
+ content: m,
65
+ children: /* @__PURE__ */ o(v, {
66
+ render: f
56
67
  })
57
- }) : d, I && /* @__PURE__ */ t(f, {
58
- content: e.formatMessage(o.autofillButtonTooltip),
59
- children: /* @__PURE__ */ t(A, {
60
- disabled: _,
68
+ }) : f, F && /* @__PURE__ */ o(h, {
69
+ content: s.formatMessage(r.autofillButtonTooltip),
70
+ children: /* @__PURE__ */ o(k, {
71
+ disabled: H,
61
72
  icon: S,
62
- loading: c,
63
- loadingAriaLabel: e.formatMessage(o.loadingButtonAriaLabel),
64
- onClick: M,
73
+ loading: d,
74
+ loadingAriaLabel: s.formatMessage(r.loadingButtonAriaLabel),
75
+ onClick: A,
65
76
  variant: "secondary",
66
77
  "data-target-id": "Button-autofillButton",
67
- children: e.formatMessage(o.autofillButton)
78
+ children: s.formatMessage(r.autofillButton)
68
79
  })
69
80
  })]
70
81
  });
71
82
  };
72
83
  export {
73
- Q as MetadataInstanceFormHeader
84
+ X as MetadataInstanceFormHeader
74
85
  };
@@ -1,61 +1,49 @@
1
- import { createContext as p, useState as m, useCallback as v, useMemo as x, useContext as A } from "react";
2
- import { TEMPLATE_CUSTOM_PROPERTIES as P } from "../constants.js";
3
- import { fetchSuggestions as E } from "./utils.js";
4
- import { jsx as M } from "react/jsx-runtime";
5
- const h = /* @__PURE__ */ p(null), O = ({
6
- children: e,
7
- isAiSuggestionsFeatureEnabled: r,
8
- fetchSuggestions: i = E
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 = ({
6
+ children: t,
7
+ isAiSuggestionsFeatureEnabled: o,
8
+ fetchSuggestions: i = x
9
9
  }) => {
10
- const [t, S] = m({}), [u, l] = m(!1), a = v(async (s, c, C = !1) => {
11
- let n = [];
12
- if (!r)
10
+ const [e, g] = l({}), [u, f] = l(!1), c = C(async (s, m) => {
11
+ let r = [];
12
+ if (!o)
13
13
  throw new Error("AI Suggestions feature not available.");
14
- if (s === P)
14
+ if (s === v)
15
15
  throw new Error("Can't fetch suggestions for Custom Metadata instance");
16
- if (!t[s] || C) {
17
- l(!0);
18
- try {
19
- n = await i(s, c), S({
20
- ...t,
21
- [s]: {
22
- ...Object.fromEntries(n.map((o) => [o.key, o.aiSuggestion]))
23
- }
24
- });
25
- } catch {
26
- } finally {
27
- l(!1);
28
- }
29
- } else
30
- n = c.map((o) => {
31
- var g;
32
- const f = (g = t == null ? void 0 : t.templateKey) == null ? void 0 : g[o.key];
33
- return {
34
- ...o,
35
- ...f ? {
36
- aiSuggestion: f
37
- } : null
38
- };
16
+ f(!0);
17
+ try {
18
+ r = await i(s, m), g({
19
+ ...e,
20
+ [s]: {
21
+ ...Object.fromEntries(r.map((n) => [n.key, n.aiSuggestion]))
22
+ }
39
23
  });
40
- return n;
41
- }, [r, t, i]), w = x(() => ({
42
- getAiSuggestions: a,
43
- isAiSuggestionsFeatureEnabled: r,
24
+ } catch {
25
+ } finally {
26
+ f(!1);
27
+ }
28
+ return r;
29
+ }, [o, e, i]), h = S(() => ({
30
+ getAiSuggestions: c,
31
+ isAiSuggestionsFeatureEnabled: o,
44
32
  isFetchingSuggestions: u,
45
- suggestions: t
46
- }), [a, r, u, t]);
47
- return /* @__PURE__ */ M(h.Provider, {
48
- value: w,
49
- children: e
33
+ suggestions: e
34
+ }), [c, o, u, e]);
35
+ return /* @__PURE__ */ A(a.Provider, {
36
+ value: h,
37
+ children: t
50
38
  });
51
- }, d = () => {
52
- const e = A(h);
53
- if (!e)
39
+ }, I = () => {
40
+ const t = p(a);
41
+ if (!t)
54
42
  throw new Error("useAutofill should be wrapped inside AutofillProvider");
55
- return e;
43
+ return t;
56
44
  };
57
45
  export {
58
- h as AutofillContext,
59
- O as AutofillContextProvider,
60
- d as useAutofill
46
+ a as AutofillContext,
47
+ T as AutofillContextProvider,
48
+ I as useAutofill
61
49
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@box/metadata-editor",
3
- "version": "0.67.0",
3
+ "version": "0.67.1",
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": "07a6f2c37ecd9a24ac3e47158a93ebd8cc687ccf"
56
+ "gitHead": "4ba02b87e8c84ad8f951540f77eb1efc83a13918"
57
57
  }