@box/metadata-editor 1.60.0 → 1.61.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,141 +1,142 @@
1
- import v from "clsx";
2
- import { useFormikContext as R } from "formik";
3
- import M from "lodash/isEqual";
4
- import ee from "lodash/isUndefined";
5
- import { memo as oe, forwardRef as ie, useCallback as a, useEffect as K, useMemo as te } from "react";
1
+ import C from "clsx";
2
+ import { useFormikContext as M } from "formik";
3
+ import oo from "lodash/isEqual";
4
+ import eo from "lodash/isUndefined";
5
+ import { memo as io, forwardRef as to, useCallback as a, useEffect as K, useMemo as no } from "react";
6
6
  import { A as p } from "../../../../chunks/types.js";
7
- import { checkIfHasBoundingBoxes as ne } from "../../utils/check-if-has-bounding-boxes.js";
8
- import { isInteractiveFormElement as T } from "../../utils/is-interactive-form-element.js";
7
+ import { checkIfHasBoundingBoxes as so } from "../../utils/check-if-has-bounding-boxes.js";
8
+ import { isInteractiveFormElement as q } from "../../utils/is-interactive-form-element.js";
9
9
  import { s as d } from "../../../../chunks/shared-field-styles.module.js";
10
- import { UpdateModeFieldWrapper as se } from "./components/update-mode-field-wrapper/update-mode-field-wrapper.js";
11
- import { editorFieldTypes as re } from "./editor-field-types.js";
10
+ import { UpdateModeFieldWrapper as ro } from "./components/update-mode-field-wrapper/update-mode-field-wrapper.js";
11
+ import { editorFieldTypes as co } from "./editor-field-types.js";
12
12
  import { s as f } from "../../../../chunks/utils2.js";
13
- import { jsx as m, jsxs as ce } from "react/jsx-runtime";
14
- import { isConfidenceScoreNeedingReview as q } from "../../utils/confidence-score/is-confidence-score-needing-review.js";
15
- import { AiSuggestionField as ae } from "./components/ai-suggestion-field/ai-suggestion-field.js";
16
- import { LowConfidenceSuggestionField as pe } from "./components/low-confidence-suggestion-field/low-confidence-suggestion-field.js";
17
- const Ie = /* @__PURE__ */ oe(/* @__PURE__ */ ie(({
13
+ import { jsx as m, jsxs as ao } from "react/jsx-runtime";
14
+ import { isConfidenceScoreNeedingReview as w } from "../../utils/confidence-score/is-confidence-score-needing-review.js";
15
+ import { AiSuggestionField as po } from "./components/ai-suggestion-field/ai-suggestion-field.js";
16
+ import { LowConfidenceSuggestionField as uo } from "./components/low-confidence-suggestion-field/low-confidence-suggestion-field.js";
17
+ const Vo = /* @__PURE__ */ io(/* @__PURE__ */ to(({
18
18
  disableForm: x,
19
19
  portalElement: N,
20
- field: e,
21
- index: w,
20
+ field: o,
21
+ index: H,
22
22
  taxonomyOptionsFetcher: I,
23
- isExternallyOwned: V,
24
- isMultilevelTaxonomyFieldEnabled: P,
23
+ isExternallyOwned: L,
24
+ isMultilevelTaxonomyFieldEnabled: V,
25
25
  isConfidenceScoreReviewEnabled: s = !1,
26
26
  onSelectMetadataField: n,
27
- selectedMetadataFieldId: H
28
- }, B) => {
27
+ selectedMetadataFieldId: z
28
+ }, P) => {
29
29
  const {
30
- setFieldValue: t
31
- } = R(), h = e.aiSuggestionState || p.Initial, c = h === p.Pending, W = h === p.Applied, F = h === p.Initial, y = re[e.type], {
30
+ setFieldValue: i
31
+ } = M(), h = o.aiSuggestionState || p.Initial, c = h === p.Pending, B = h === p.Applied, T = h === p.Initial, y = co[o.type], {
32
32
  aiSuggestion: r,
33
- aiSuggestionConfidenceScore: k,
33
+ aiSuggestionConfidenceScore: $,
34
+ aiSuggestionTargetLocation: W,
34
35
  type: l,
35
36
  value: u
36
- } = e, z = y && !e.hidden, G = !ee(e.updateMode), o = `metadata.fields[${w}]`, J = e.type === "taxonomy" && e.optionsRules?.multiSelect, C = s && !!e.confidenceScore, L = C && q(e.confidenceScore), Q = C && !c && !q(e.confidenceScore), D = H === e.id, X = ne(e.targetLocation), S = C && X && !!n, Y = v({
37
- [f.aiApproved]: W || Q,
37
+ } = o, G = y && !o.hidden, J = !eo(o.updateMode), e = `metadata.fields[${H}]`, Q = o.type === "taxonomy" && o.optionsRules?.multiSelect, k = s && !!o.confidenceScore, F = k && w(o.confidenceScore), X = k && !c && !w(o.confidenceScore), D = z === o.id, Y = so(o.targetLocation), S = k && Y && !!n, Z = C({
38
+ [f.aiApproved]: B || X,
38
39
  [f.hasSuggestion]: c,
39
- [f.hasConfidenceReview]: !c && L,
40
+ [f.hasConfidenceReview]: !c && F,
40
41
  [f.dateField]: l === "date"
41
- }), g = a((i) => {
42
- t(`${o}.aiSuggestionState`, i);
43
- }, [o, t]), A = a((i) => {
44
- t(`${o}.value`, i), g(p.Applied), s && (t(`${o}.confidenceScore`, k), t(`${o}.aiSuggestionConfidenceScore`, void 0));
45
- }, [o, t, g, k, s]), $ = a(() => {
46
- g(p.Initial), t(`${o}.aiSuggestion`, void 0), s && t(`${o}.aiSuggestionConfidenceScore`, void 0);
47
- }, [g, t, o, s]), Z = a(() => {
48
- t(`${o}.confidenceScore.isAccepted`, !0), n?.(null);
49
- }, [o, t, n]), _ = a(() => {
50
- const i = l === "multiSelect" || l === "taxonomy" ? [] : "";
51
- t(`${o}.value`, i), t(`${o}.confidenceScore`, void 0), n?.(null);
52
- }, [o, t, l, n]), U = a(() => {
53
- $(), s && e.confidenceScore && (t(`${o}.confidenceScore`, void 0), n?.(null));
54
- }, [$, s, e.confidenceScore, t, o, n]), b = a((i) => {
55
- n && (T(i.target) || n(e));
56
- }, [e, n]), O = a((i) => {
57
- if (i.key === "Enter") {
58
- if (!n || T(i.target))
42
+ }), g = a((t) => {
43
+ i(`${e}.aiSuggestionState`, t);
44
+ }, [e, i]), A = a((t) => {
45
+ i(`${e}.value`, t), g(p.Applied), s && (i(`${e}.confidenceScore`, $), i(`${e}.aiSuggestionConfidenceScore`, void 0), i(`${e}.targetLocation`, W), i(`${e}.aiSuggestionTargetLocation`, void 0));
46
+ }, [e, i, g, $, W, s]), v = a(() => {
47
+ g(p.Initial), i(`${e}.aiSuggestion`, void 0), s && (i(`${e}.aiSuggestionConfidenceScore`, void 0), i(`${e}.aiSuggestionTargetLocation`, void 0));
48
+ }, [g, i, e, s]), _ = a(() => {
49
+ i(`${e}.confidenceScore.isAccepted`, !0), n?.(null);
50
+ }, [e, i, n]), b = a(() => {
51
+ const t = l === "multiSelect" || l === "taxonomy" ? [] : "";
52
+ i(`${e}.value`, t), i(`${e}.confidenceScore`, void 0), n?.(null);
53
+ }, [e, i, l, n]), U = a(() => {
54
+ v(), s && o.confidenceScore && (i(`${e}.confidenceScore`, void 0), n?.(null));
55
+ }, [v, s, o.confidenceScore, i, e, n]), O = a((t) => {
56
+ n && (q(t.target) || n(o));
57
+ }, [o, n]), E = a((t) => {
58
+ if (t.key === "Enter") {
59
+ if (!n || q(t.target))
59
60
  return;
60
- i.preventDefault(), i.stopPropagation(), n(e);
61
+ t.preventDefault(), t.stopPropagation(), n(o);
61
62
  }
62
- }, [e, n]);
63
+ }, [o, n]);
63
64
  K(() => {
64
65
  c && (!u || Array.isArray(u) && u.length === 0) && A(r);
65
66
  }, [r, c, A]), K(() => {
66
- F && r && g(p.Pending);
67
- }, [F, r, g]);
68
- const E = te(() => r ? M(u, r) : !1, [r, u]);
69
- if (!z)
67
+ T && r && g(p.Pending);
68
+ }, [T, r, g]);
69
+ const R = no(() => r ? oo(u, r) : !1, [r, u]);
70
+ if (!G)
70
71
  return null;
71
72
  const j = {
72
73
  "data-metadata-field": !0,
73
74
  "data-testid": "metadata-field",
74
- onClick: b,
75
- onKeyDown: O,
75
+ onClick: O,
76
+ onKeyDown: E,
76
77
  role: "button",
77
78
  tabIndex: 0
78
79
  };
79
- if (G) {
80
- const i = /* @__PURE__ */ m(se, {
81
- fieldNamePrefix: o,
82
- fieldType: e.type,
83
- isTaxonomyMultiSelect: J,
80
+ if (J) {
81
+ const t = /* @__PURE__ */ m(ro, {
82
+ fieldNamePrefix: e,
83
+ fieldType: o.type,
84
+ isTaxonomyMultiSelect: Q,
84
85
  children: /* @__PURE__ */ m(y, {
85
- ref: B,
86
- description: e.description,
86
+ ref: P,
87
+ description: o.description,
87
88
  disableForm: x,
88
- fieldNamePrefix: o,
89
+ fieldNamePrefix: e,
89
90
  isAiSuggestionApplied: !1,
90
- isExternallyOwned: V,
91
- isMultilevelTaxonomyFieldEnabled: P,
92
- label: e.displayName,
93
- levels: e.levels,
91
+ isExternallyOwned: L,
92
+ isMultilevelTaxonomyFieldEnabled: V,
93
+ label: o.displayName,
94
+ levels: o.levels,
94
95
  onValueEdited: U,
95
96
  portalElement: N,
96
97
  taxonomyOptionsFetcher: I
97
98
  })
98
- }, e.key);
99
+ }, o.key);
99
100
  return S ? /* @__PURE__ */ m("div", {
100
- className: v(d.spacious, d.clickableField, D && d.selectedField),
101
+ className: C(d.spacious, d.clickableField, D && d.selectedField),
101
102
  ...j,
102
- children: i
103
- }) : i;
103
+ children: t
104
+ }) : t;
104
105
  }
105
- return /* @__PURE__ */ ce("div", {
106
- className: v(f.fieldWrapper, s && d.spacious, S && d.clickableField, S && D && d.selectedField),
106
+ return /* @__PURE__ */ ao("div", {
107
+ className: C(f.fieldWrapper, s && d.spacious, S && d.clickableField, S && D && d.selectedField),
107
108
  ...S && j,
108
109
  children: [/* @__PURE__ */ m(y, {
109
- ref: B,
110
- className: Y,
111
- description: e.description,
110
+ ref: P,
111
+ className: Z,
112
+ description: o.description,
112
113
  disableForm: x,
113
- fieldNamePrefix: o,
114
- isAiSuggestionApplied: W,
115
- isExternallyOwned: V,
116
- confidenceScore: s && !c ? e.confidenceScore : void 0,
117
- isMultilevelTaxonomyFieldEnabled: P,
118
- label: e.displayName,
114
+ fieldNamePrefix: e,
115
+ isAiSuggestionApplied: B,
116
+ isExternallyOwned: L,
117
+ confidenceScore: s && !c ? o.confidenceScore : void 0,
118
+ isMultilevelTaxonomyFieldEnabled: V,
119
+ label: o.displayName,
119
120
  onValueEdited: U,
120
121
  portalElement: N,
121
122
  taxonomyOptionsFetcher: I
122
- }), c && /* @__PURE__ */ m(ae, {
123
+ }), c && /* @__PURE__ */ m(po, {
123
124
  aiSuggestion: r,
124
- confidenceLevel: s ? k?.level : void 0,
125
- isSameValue: E,
125
+ confidenceLevel: s ? $?.level : void 0,
126
+ isSameValue: R,
126
127
  onAiSuggestionAppend: () => {
127
- const i = [...new Set([u, r].flat().filter(Boolean))];
128
- A(i);
128
+ const t = [...new Set([u, r].flat().filter(Boolean))];
129
+ A(t);
129
130
  },
130
- onAiSuggestionIgnore: $,
131
+ onAiSuggestionIgnore: v,
131
132
  onAiSuggestionReplace: () => A(r),
132
133
  type: l
133
- }), !c && L && /* @__PURE__ */ m(pe, {
134
- onAccept: Z,
135
- onClear: _
134
+ }), !c && F && /* @__PURE__ */ m(uo, {
135
+ onAccept: _,
136
+ onClear: b
136
137
  })]
137
- }, e.key);
138
+ }, o.key);
138
139
  }));
139
140
  export {
140
- Ie as MetadataEditorFieldWrapper
141
+ Vo as MetadataEditorFieldWrapper
141
142
  };
@@ -1,33 +1,33 @@
1
- import { Tooltip as L, Button as k, LoadingIndicator as E, IconButton as R, SplitButton as v, DropdownMenu as N, Text as x } from "@box/blueprint-web";
2
- import { BoxAiAdvancedLogo24 as D, BoxAiLogo24 as K } from "@box/blueprint-web-assets/icons/Logo";
3
- import { useLocalStorageAIAgents as O } from "@box/box-ai-agent-selector";
4
- import { useFormikContext as j, getIn as g } from "formik";
5
- import { useEffect as w, useMemo as F, forwardRef as P, useState as Y } from "react";
6
- import { useIntl as G } from "react-intl";
7
- import { EXTRACT_AI_AGENT_LOCAL_STORAGE_KEY as V, EXTRACT_AGENTS_MAP as M } from "../../../../constants.js";
8
- import { autofillMessages as X } from "../../../../messages.js";
9
- import { useAutofill as q } from "../../../../utils/autofill-context.js";
10
- import { getTooltipContent as z } from "../../../../utils/utils.js";
1
+ import { Tooltip as N, Button as E, LoadingIndicator as R, IconButton as v, SplitButton as x, DropdownMenu as G, Text as D } from "@box/blueprint-web";
2
+ import { BoxAiAdvancedLogo24 as K, BoxAiLogo24 as O } from "@box/blueprint-web-assets/icons/Logo";
3
+ import { useLocalStorageAIAgents as j } from "@box/box-ai-agent-selector";
4
+ import { useFormikContext as w, getIn as f } from "formik";
5
+ import { useEffect as F, useMemo as P, forwardRef as Y, useState as V } from "react";
6
+ import { useIntl as k } from "react-intl";
7
+ import { EXTRACT_AI_AGENT_LOCAL_STORAGE_KEY as X, EXTRACT_AGENTS_MAP as M } from "../../../../constants.js";
8
+ import { autofillMessages as q } from "../../../../messages.js";
9
+ import { useAutofill as z } from "../../../../utils/autofill-context.js";
10
+ import { getTooltipContent as H } from "../../../../utils/utils.js";
11
11
  import p from "./messages.js";
12
- import { jsx as t, jsxs as H } from "react/jsx-runtime";
13
- import '../../../../../../styles/metadata-instance-form-autofill-button.css';const J = "_loadingIndicator_i1hyy_1", Q = "_actionMenuItem_i1hyy_11", U = "_splitButtonIcon_i1hyy_17", T = {
14
- loadingIndicator: J,
15
- actionMenuItem: Q,
16
- splitButtonIcon: U
17
- }, W = /* @__PURE__ */ P(({
12
+ import { jsx as t, jsxs as J } from "react/jsx-runtime";
13
+ import '../../../../../../styles/metadata-instance-form-autofill-button.css';const Q = "_loadingIndicator_i1hyy_1", U = "_actionMenuItem_i1hyy_11", W = "_splitButtonIcon_i1hyy_17", T = {
14
+ loadingIndicator: Q,
15
+ actionMenuItem: U,
16
+ splitButtonIcon: W
17
+ }, Z = /* @__PURE__ */ Y(({
18
18
  isButtonDisabled: I,
19
19
  onAutofill: A,
20
- onAgentChange: l,
20
+ onAgentChange: c,
21
21
  storedAgent: B,
22
22
  icon: e,
23
23
  ..._
24
24
  }, h) => {
25
- const n = G(), [c, a] = Y(B || "standard"), i = (o) => {
26
- a(o), l(o), setTimeout(() => {
25
+ const n = k(), [u, a] = V(B || "standard"), i = (o) => {
26
+ a(o), c(o), setTimeout(() => {
27
27
  A(o);
28
28
  }, 0);
29
29
  };
30
- return /* @__PURE__ */ t(v, {
30
+ return /* @__PURE__ */ t(x, {
31
31
  ..._,
32
32
  ref: h,
33
33
  disabled: I,
@@ -36,19 +36,19 @@ import '../../../../../../styles/metadata-instance-form-autofill-button.css';con
36
36
  label: n.formatMessage(p.autofillButton),
37
37
  onClick: () => A(),
38
38
  variant: "secondary",
39
- children: /* @__PURE__ */ t(N.RadioGroup, {
39
+ children: /* @__PURE__ */ t(G.RadioGroup, {
40
40
  onValueChange: (o) => i(o),
41
- value: c,
41
+ value: u,
42
42
  children: Object.entries(M).map(([o, s]) => {
43
- const u = s.ICON;
44
- return /* @__PURE__ */ t(N.RadioSelectItem, {
43
+ const m = s.ICON;
44
+ return /* @__PURE__ */ t(G.RadioSelectItem, {
45
45
  value: s.AGENT_TYPE,
46
- children: /* @__PURE__ */ H("div", {
46
+ children: /* @__PURE__ */ J("div", {
47
47
  className: T.actionMenuItem,
48
- children: [/* @__PURE__ */ t(u, {
48
+ children: [/* @__PURE__ */ t(m, {
49
49
  "aria-hidden": !0,
50
50
  className: T.splitButtonIcon
51
- }), /* @__PURE__ */ t(x, {
51
+ }), /* @__PURE__ */ t(D, {
52
52
  as: "span",
53
53
  children: n.formatMessage(p[s.DISPLAY_MSG])
54
54
  })]
@@ -57,10 +57,10 @@ import '../../../../../../styles/metadata-instance-form-autofill-button.css';con
57
57
  })
58
58
  })
59
59
  });
60
- }), ut = ({
60
+ }), mt = ({
61
61
  areAiSuggestionsAvailable: I,
62
62
  isBetaLanguageEnabled: A,
63
- isLoading: l,
63
+ isLoading: c,
64
64
  variant: B = "secondary-button",
65
65
  isAdvancedExtractAgentEnabled: e = !1,
66
66
  onAutofill: _
@@ -68,37 +68,39 @@ import '../../../../../../styles/metadata-instance-form-autofill-button.css';con
68
68
  const {
69
69
  isSubmitting: h,
70
70
  values: n,
71
- setFieldValue: c
72
- } = j(), a = G(), [i, o] = O(V), {
71
+ setFieldValue: u
72
+ } = w(), a = k(), [i, o] = j(X), {
73
73
  suggestions: s,
74
- confidenceScores: u
75
- } = q();
76
- w(() => {
74
+ confidenceScores: m,
75
+ targetLocations: b
76
+ } = z();
77
+ F(() => {
77
78
  if (s) {
78
- const m = g(n, "metadata.fields"), d = g(n, "metadata.templateKey");
79
- c("metadata.fields", m?.map((r) => {
80
- const f = s?.[d]?.[r.key];
81
- return f ? {
79
+ const d = f(n, "metadata.fields"), l = f(n, "metadata.templateKey");
80
+ u("metadata.fields", d?.map((r) => {
81
+ const g = s?.[l]?.[r.key];
82
+ return g ? {
82
83
  ...r,
83
- aiSuggestion: f,
84
- aiSuggestionConfidenceScore: u?.[d]?.[r.key]
84
+ aiSuggestion: g,
85
+ aiSuggestionConfidenceScore: m?.[l]?.[r.key],
86
+ aiSuggestionTargetLocation: b?.[l]?.[r.key]
85
87
  } : r;
86
88
  }));
87
89
  }
88
- }, [s, u, c]);
89
- const S = (m) => {
90
- const d = g(n, "metadata.templateKey"), r = g(n, "metadata.scope"), f = m ? M[m]?.AGENT_ID : M[i]?.AGENT_ID;
91
- _(d, r, e ? f : void 0);
92
- }, y = !I || h || l, C = i === "enhanced" && e ? D : K, b = F(() => z(e, i, a), [e, i, a]);
93
- return B === "secondary-button" ? /* @__PURE__ */ t(L, {
94
- content: b,
95
- children: e ? /* @__PURE__ */ t(W, {
90
+ }, [s, m, b, u]);
91
+ const S = (d) => {
92
+ const l = f(n, "metadata.templateKey"), r = f(n, "metadata.scope"), g = d ? M[d]?.AGENT_ID : M[i]?.AGENT_ID;
93
+ _(l, r, e ? g : void 0);
94
+ }, y = !I || h || c, C = i === "enhanced" && e ? K : O, L = P(() => H(e, i, a), [e, i, a]);
95
+ return B === "secondary-button" ? /* @__PURE__ */ t(N, {
96
+ content: L,
97
+ children: e ? /* @__PURE__ */ t(Z, {
96
98
  icon: C,
97
99
  isButtonDisabled: y,
98
100
  onAgentChange: o,
99
101
  onAutofill: S,
100
102
  storedAgent: i
101
- }) : /* @__PURE__ */ t(k, {
103
+ }) : /* @__PURE__ */ t(E, {
102
104
  disabled: y,
103
105
  icon: C,
104
106
  onClick: () => S(),
@@ -106,13 +108,13 @@ import '../../../../../../styles/metadata-instance-form-autofill-button.css';con
106
108
  "data-target-id": "Button-autofillButton",
107
109
  children: a.formatMessage(p.autofillButton)
108
110
  })
109
- }) : /* @__PURE__ */ t(L, {
110
- content: b,
111
- children: l ? /* @__PURE__ */ t(E, {
111
+ }) : /* @__PURE__ */ t(N, {
112
+ content: L,
113
+ children: c ? /* @__PURE__ */ t(R, {
112
114
  "aria-label": a.formatMessage(p.loadingButtonAriaLabel),
113
115
  className: T.loadingIndicator
114
- }) : /* @__PURE__ */ t(R, {
115
- "aria-label": a.formatMessage(X.autofillButtonAriaLabel),
116
+ }) : /* @__PURE__ */ t(v, {
117
+ "aria-label": a.formatMessage(q.autofillButtonAriaLabel),
116
118
  disabled: y,
117
119
  icon: C,
118
120
  onClick: () => S(),
@@ -122,5 +124,5 @@ import '../../../../../../styles/metadata-instance-form-autofill-button.css';con
122
124
  });
123
125
  };
124
126
  export {
125
- ut as MetadataInstanceFormAutofillButton
127
+ mt as MetadataInstanceFormAutofillButton
126
128
  };
@@ -1,64 +1,68 @@
1
- import A, { createContext as O, useState as u, useCallback as T, useMemo as P, useContext as _ } from "react";
2
- import { TEMPLATE_CUSTOM_PROPERTIES as p } from "../constants.js";
3
- import { jsx as I } from "react/jsx-runtime";
4
- const L = 1e4, h = /* @__PURE__ */ O(null), R = ({
5
- children: o,
6
- isAiSuggestionsFeatureEnabled: s,
1
+ import A, { createContext as P, useState as n, useCallback as h, useMemo as _, useContext as p } from "react";
2
+ import { TEMPLATE_CUSTOM_PROPERTIES as I } from "../constants.js";
3
+ import { jsx as M } from "react/jsx-runtime";
4
+ const j = 1e4, w = /* @__PURE__ */ P(null), y = ({
5
+ children: r,
6
+ isAiSuggestionsFeatureEnabled: i,
7
7
  fetchSuggestions: l
8
8
  }) => {
9
- const [n, g] = u({}), [S, m] = u({}), [r, a] = u(!1), [C, f] = u(!1);
9
+ const [c, g] = n({}), [S, m] = n({}), [C, d] = n({}), [a, u] = n(!1), [E, f] = n(!1);
10
10
  A.useEffect(() => {
11
- let e;
12
- return r ? e = setTimeout(() => {
11
+ let t;
12
+ return a ? t = setTimeout(() => {
13
13
  f(!0);
14
- }, L) : (f(!1), clearTimeout(e)), () => clearTimeout(e);
15
- }, [r]);
16
- const d = T(async (e, v, x) => {
17
- let i = [];
18
- if (!s)
14
+ }, j) : (f(!1), clearTimeout(t)), () => clearTimeout(t);
15
+ }, [a]);
16
+ const T = h(async (t, O, x) => {
17
+ let s = [];
18
+ if (!i)
19
19
  throw new Error("AI Suggestions feature not available.");
20
- if (e === p)
20
+ if (t === I)
21
21
  throw new Error("Can't fetch suggestions for Custom Metadata instance");
22
- a(!0);
22
+ u(!0);
23
23
  try {
24
- i = await l(e, v, x || void 0), g({
25
- ...n,
26
- [e]: {
27
- ...Object.fromEntries(i.map((t) => [t.key, t.aiSuggestion]))
24
+ s = await l(t, O, x || void 0), g({
25
+ ...c,
26
+ [t]: {
27
+ ...Object.fromEntries(s.map((o) => [o.key, o.aiSuggestion]))
28
28
  }
29
- }), m((t) => ({
30
- ...t,
31
- [e]: Object.fromEntries(i.filter((c) => c.aiSuggestionConfidenceScore).map((c) => [c.key, c.aiSuggestionConfidenceScore]))
29
+ }), m((o) => ({
30
+ ...o,
31
+ [t]: Object.fromEntries(s.filter((e) => e.aiSuggestionConfidenceScore).map((e) => [e.key, e.aiSuggestionConfidenceScore]))
32
+ })), d((o) => ({
33
+ ...o,
34
+ [t]: Object.fromEntries(s.filter((e) => e.targetLocation).map((e) => [e.key, e.targetLocation]))
32
35
  }));
33
36
  } catch {
34
37
  } finally {
35
- a(!1);
38
+ u(!1);
36
39
  }
37
- return i;
38
- }, [s, n, l]), E = T(() => {
39
- g({}), m({}), a(!1), f(!1);
40
- }, []), w = P(() => ({
41
- clearState: E,
40
+ return s;
41
+ }, [i, c, l]), L = h(() => {
42
+ g({}), m({}), d({}), u(!1), f(!1);
43
+ }, []), v = _(() => ({
44
+ clearState: L,
42
45
  confidenceScores: S,
43
- getAiSuggestions: d,
44
- isAiSuggestionsFeatureEnabled: s,
45
- isFetchingSuggestions: r,
46
- isLongLoading: C,
47
- suggestions: n
48
- }), [E, S, d, s, r, C, n]);
49
- return /* @__PURE__ */ I(h.Provider, {
50
- value: w,
51
- children: o
46
+ getAiSuggestions: T,
47
+ isAiSuggestionsFeatureEnabled: i,
48
+ isFetchingSuggestions: a,
49
+ isLongLoading: E,
50
+ suggestions: c,
51
+ targetLocations: C
52
+ }), [L, S, T, i, a, E, c, C]);
53
+ return /* @__PURE__ */ M(w.Provider, {
54
+ value: v,
55
+ children: r
52
56
  });
53
- }, b = () => {
54
- const o = _(h);
55
- if (!o)
57
+ }, U = () => {
58
+ const r = p(w);
59
+ if (!r)
56
60
  throw new Error("useAutofill should be wrapped inside AutofillProvider");
57
- return o;
61
+ return r;
58
62
  };
59
63
  export {
60
- h as AutofillContext,
61
- R as AutofillContextProvider,
62
- L as TIMEOUT_10_SECONDS,
63
- b as useAutofill
64
+ w as AutofillContext,
65
+ y as AutofillContextProvider,
66
+ j as TIMEOUT_10_SECONDS,
67
+ U as useAutofill
64
68
  };