@box/metadata-editor 0.54.0 → 0.55.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,46 +1,46 @@
1
1
  import "../../../../styles/combobox-with-api-pagination.css";
2
- import { ComboboxItemValue as U } from "@ariakit/react";
3
- import { Combobox as p, LoadingIndicator as q, InlineNotice as H, Text as J } from "@box/blueprint-web";
4
- import { Search as K, Loader as Q } from "@box/blueprint-web-assets/icons/Fill";
5
- import { IconIconOnLightSecondary as X, Size6 as C, Size1 as Y } from "@box/blueprint-web-assets/tokens/tokens";
6
- import { useRef as E, useCallback as Z, useMemo as v, useEffect as $, forwardRef as oo } from "react";
7
- import { useIntl as T, FormattedMessage as y } from "react-intl";
2
+ import { ComboboxItemValue as J } from "@ariakit/react";
3
+ import { Combobox as p, LoadingIndicator as K, InlineNotice as Q, Text as X } from "@box/blueprint-web";
4
+ import { Search as Y, Loader as Z } from "@box/blueprint-web-assets/icons/Fill";
5
+ import { IconIconOnLightSecondary as $, Size6 as E, Size1 as oo } from "@box/blueprint-web-assets/tokens/tokens";
6
+ import { useRef as y, useCallback as eo, useMemo as _, useEffect as to, forwardRef as ro } from "react";
7
+ import { useIntl as T, FormattedMessage as v } from "react-intl";
8
8
  import i from "./messages.js";
9
- import { useAsyncList as eo } from "./use-async-list.js";
10
- import { useControllableState as ro } from "./utils/use-controllable-state.js";
11
- import { useTrackVisibility as to } from "./utils/use-intersection-observer.js";
12
- import { jsx as t, jsxs as I, Fragment as no } from "react/jsx-runtime";
13
- const io = "_container_16dlc_1", ao = "_highlightOptionText_16dlc_7", so = "_option_16dlc_20", lo = "_errorComboboxOption_16dlc_24", co = "_errorComboboxOptionText_16dlc_29", d = {
14
- container: io,
15
- highlightOptionText: ao,
16
- option: so,
17
- errorComboboxOption: lo,
18
- errorComboboxOptionText: co
19
- }, M = /* @__PURE__ */ oo(({
20
- onTryAgain: f
21
- }, h) => {
9
+ import { useAsyncList as no } from "./use-async-list.js";
10
+ import { useControllableState as io } from "./utils/use-controllable-state.js";
11
+ import { useTrackVisibility as ao } from "./utils/use-intersection-observer.js";
12
+ import { jsx as r, jsxs as I, Fragment as so } from "react/jsx-runtime";
13
+ const lo = "_container_16dlc_1", co = "_highlightOptionText_16dlc_7", uo = "_option_16dlc_20", po = "_errorComboboxOption_16dlc_24", mo = "_errorComboboxOptionText_16dlc_29", m = {
14
+ container: lo,
15
+ highlightOptionText: co,
16
+ option: uo,
17
+ errorComboboxOption: po,
18
+ errorComboboxOptionText: mo
19
+ }, M = /* @__PURE__ */ ro(({
20
+ onTryAgain: h
21
+ }, f) => {
22
22
  const {
23
23
  formatMessage: s
24
24
  } = T();
25
- return /* @__PURE__ */ I(no, {
26
- children: [/* @__PURE__ */ t(H, {
25
+ return /* @__PURE__ */ I(so, {
26
+ children: [/* @__PURE__ */ r(Q, {
27
27
  variant: "error",
28
28
  variantIconAriaLabel: s(i.loadingResultsErrorIconLabel),
29
- children: /* @__PURE__ */ t(y, {
29
+ children: /* @__PURE__ */ r(v, {
30
30
  ...i.loadingResultsErrorMessage
31
31
  })
32
- }), /* @__PURE__ */ t(p.Option, {
33
- ref: h,
34
- className: d.errorComboboxOption,
35
- onClick: f,
36
- children: /* @__PURE__ */ I(J, {
32
+ }), /* @__PURE__ */ r(p.Option, {
33
+ ref: f,
34
+ className: m.errorComboboxOption,
35
+ onClick: h,
36
+ children: /* @__PURE__ */ I(X, {
37
37
  as: "span",
38
- className: d.errorComboboxOptionText,
38
+ className: m.errorComboboxOptionText,
39
39
  color: "textOnLightLink",
40
40
  variant: "bodyDefaultBold",
41
- children: [/* @__PURE__ */ t(y, {
41
+ children: [/* @__PURE__ */ r(v, {
42
42
  ...i.loadingResultsErrorAction
43
- }), /* @__PURE__ */ t(Q, {
43
+ }), /* @__PURE__ */ r(Z, {
44
44
  color: "currentColor",
45
45
  height: "12px",
46
46
  width: "12px"
@@ -48,144 +48,148 @@ const io = "_container_16dlc_1", ao = "_highlightOptionText_16dlc_7", so = "_opt
48
48
  })
49
49
  })]
50
50
  });
51
- }), x = "__LOADING__", O = "__LOADING_ERROR__", uo = "0px 0px 20px 0px", mo = /* @__PURE__ */ t(K, {
52
- color: X,
53
- height: C,
51
+ }), R = "__LOADING__", L = "__LOADING_ERROR__", ho = "0px 0px 20px 0px", fo = /* @__PURE__ */ r(Y, {
52
+ color: $,
53
+ height: E,
54
54
  role: "presentation",
55
55
  style: {
56
- padding: Y,
56
+ padding: oo,
57
57
  boxSizing: "border-box"
58
58
  },
59
- width: C
60
- }), Eo = (f) => {
59
+ width: E
60
+ }), Io = (h) => {
61
61
  const {
62
- defaultFetcher: h,
62
+ defaultFetcher: f,
63
63
  onInputValueChange: s,
64
- value: N,
65
- onValueChange: S,
66
- noResultMessage: V,
67
- defaultValue: D,
64
+ value: V,
65
+ onValueChange: N,
66
+ noResultMessage: S,
67
+ defaultValue: D = [],
68
68
  loadingAriaLabel: P,
69
- multiselect: _ = !1,
69
+ multiselect: c = !1,
70
70
  ...k
71
- } = f, {
72
- formatMessage: l
73
- } = T(), g = E(null), o = eo({
71
+ } = h, {
72
+ formatMessage: u
73
+ } = T(), g = y(null), o = no({
74
74
  async load({
75
75
  marker: e,
76
- searchInput: r,
77
- signal: u
76
+ searchInput: t,
77
+ signal: O
78
78
  }) {
79
- const m = await h({
80
- signal: u,
79
+ const l = await f({
80
+ signal: O,
81
81
  marker: e,
82
- searchInput: r
82
+ searchInput: t
83
83
  });
84
84
  return {
85
- items: m.options,
86
- marker: m.marker
85
+ items: l.options,
86
+ marker: l.marker
87
87
  };
88
88
  }
89
- }), R = E(!1), F = Z(() => {
90
- R.current || (o.reload(), R.current = !0);
91
- }, []), [n, A] = ro({
92
- prop: N,
89
+ }), C = y(!1), F = eo(() => {
90
+ C.current || (o.reload(), C.current = !0);
91
+ }, []), [n, b] = io({
92
+ prop: V,
93
93
  defaultProp: D,
94
- onChange: S
95
- }), b = v(() => Array.isArray(n) ? n.filter((e) => !o.items.some((r) => r.value === e.value)) : [], [n, o.items]), w = (e) => {
94
+ onChange: N
95
+ }), w = (e) => {
96
+ e === void 0 ? b([]) : Array.isArray(e) ? b(e) : b([e]);
97
+ }, B = _(() => n.length === 0 ? c ? [] : void 0 : c ? n : n[0], [c, n]), x = _(() => n.filter((e) => !o.items.some((t) => t.value === e.value)), [n, o.items]), z = (e) => {
96
98
  const {
97
- value: r,
98
- ...u
99
+ value: t,
100
+ displayValue: O,
101
+ ...l
99
102
  } = e;
100
- if (r === x)
101
- return o.hasNextPage ? /* @__PURE__ */ t(p.Option, {
102
- ...u,
103
- ref: G,
103
+ if (t === R)
104
+ return o.hasNextPage ? /* @__PURE__ */ r(p.Option, {
105
+ ...l,
106
+ ref: j,
104
107
  disabled: !0,
105
- value: r,
106
- children: /* @__PURE__ */ t(q, {
107
- "aria-label": l(i.loadingMoreAriaLabel),
108
+ value: t,
109
+ children: /* @__PURE__ */ r(K, {
110
+ "aria-label": u(i.loadingMoreAriaLabel),
108
111
  style: {
109
112
  position: "unset"
110
113
  }
111
114
  })
112
115
  }) : null;
113
- if (r === O && o.hasError && !o.isEmpty)
114
- return /* @__PURE__ */ t(M, {
116
+ if (t === L && o.hasError && !o.isEmpty)
117
+ return /* @__PURE__ */ r(M, {
115
118
  onTryAgain: () => {
116
119
  var a;
117
120
  o.loadMore(), (a = g.current) == null || a.focus();
118
121
  }
119
122
  });
120
- if (b.some((a) => a.value === r))
123
+ if (x.some((a) => a.value === t))
121
124
  return null;
122
- const m = () => n ? Array.isArray(n) ? n.some((a) => a.value === r) : n.value === r : !1;
123
- return /* @__PURE__ */ t(p.Option, {
124
- ...u,
125
- className: d.option,
126
- disabled: m(),
127
- value: r,
128
- children: /* @__PURE__ */ t(U, {
129
- className: d.highlightOptionText,
130
- value: r
125
+ const H = () => n.some((a) => a.value === t);
126
+ return /* @__PURE__ */ r(p.Option, {
127
+ ...l,
128
+ className: m.option,
129
+ disabled: H(),
130
+ value: t,
131
+ children: /* @__PURE__ */ r(J, {
132
+ className: m.highlightOptionText,
133
+ value: O || t
131
134
  })
132
135
  });
133
- }, B = (e) => {
134
- s == null || s(e), o.search(e), e.trim() === "" && !_ && A(null);
135
- }, z = () => {
136
+ }, G = (e) => {
137
+ s == null || s(e), o.search(e);
138
+ }, W = () => {
136
139
  var e;
137
140
  o.reload(), (e = g.current) == null || e.focus();
138
141
  };
139
- let c;
140
- o.hasError && !o.isLoading ? c = /* @__PURE__ */ t(M, {
141
- onTryAgain: z
142
- }) : o.isEmpty && !o.isLoading ? c = V || l(i.noResults) : c = void 0;
143
- const [G, {
144
- rootRef: W,
145
- isVisible: L
146
- }] = to({
147
- rootMargin: uo
142
+ let d;
143
+ o.hasError && !o.isLoading ? d = /* @__PURE__ */ r(M, {
144
+ onTryAgain: W
145
+ }) : o.isEmpty && !o.isLoading ? d = S || u(i.noResults) : d = void 0;
146
+ const [j, {
147
+ rootRef: U,
148
+ isVisible: A
149
+ }] = ao({
150
+ rootMargin: ho
148
151
  });
149
- $(() => {
150
- if (!(L && o.hasNextPage))
152
+ to(() => {
153
+ if (!(A && o.hasNextPage))
151
154
  return;
152
- const r = setTimeout(() => {
155
+ const t = setTimeout(() => {
153
156
  o.loadMore();
154
157
  }, 100);
155
158
  return () => {
156
- clearTimeout(r);
159
+ clearTimeout(t);
157
160
  };
158
- }, [L]);
159
- const j = v(() => {
161
+ }, [A]);
162
+ const q = _(() => {
160
163
  const e = o.hasNextPage ? {
161
- id: x,
162
- value: x
163
- } : null, r = !e && o.hasError && !o.isEmpty ? {
164
- id: O,
165
- value: O
164
+ displayValue: R,
165
+ value: R
166
+ } : null, t = !e && o.hasError && !o.isEmpty ? {
167
+ displayValue: L,
168
+ value: L
166
169
  } : null;
167
- return [...o.items, ...b, e, r].filter(Boolean);
168
- }, [o.hasNextPage, o.hasError, o.isEmpty, o.items, b]);
169
- return /* @__PURE__ */ t(p, {
170
+ return [...o.items, ...x, e, t].filter(Boolean);
171
+ }, [o.hasNextPage, o.hasError, o.isEmpty, o.items, x]);
172
+ return /* @__PURE__ */ r(p, {
170
173
  as: "input",
171
174
  ...k,
172
175
  ref: g,
173
- clearButtonAriaLabel: l(i.clearButtonAriaLabel),
174
- endComboboxIcon: mo,
176
+ clearButtonAriaLabel: u(i.clearButtonAriaLabel),
177
+ displayValue: (e) => e.displayValue || e.value,
178
+ endComboboxIcon: fo,
175
179
  focusLoop: !1,
176
- getPopoverRef: W,
180
+ getPopoverRef: U,
177
181
  loading: o.isReloading,
178
- loadingAriaLabel: P || l(i.loadingAriaLabel),
179
- multiselect: _,
180
- noResultMessage: c,
182
+ loadingAriaLabel: P || u(i.loadingAriaLabel),
183
+ multiselect: c,
184
+ noResultMessage: d,
181
185
  onFocus: F,
182
- onInputValueChange: B,
183
- onValueChange: A,
184
- options: j,
185
- renderOption: w,
186
- value: n
186
+ onInputValueChange: G,
187
+ onValueChange: w,
188
+ options: q,
189
+ renderOption: z,
190
+ value: B
187
191
  });
188
192
  };
189
193
  export {
190
- Eo as ComboboxWithApiPagination
194
+ Io as ComboboxWithApiPagination
191
195
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@box/metadata-editor",
3
- "version": "0.54.0",
3
+ "version": "0.55.0",
4
4
  "peerDependencies": {
5
5
  "@ariakit/react": "0.4.5",
6
6
  "@box/blueprint-web": "^7.20.0",
@@ -52,5 +52,5 @@
52
52
  "**/*.css"
53
53
  ],
54
54
  "license": "SEE LICENSE IN LICENSE",
55
- "gitHead": "c4e8483378415e000dd6bb2a9ca046d5176f98f0"
55
+ "gitHead": "c8b17c1172f3189aeab0378c577c87b79f3a837f"
56
56
  }
@@ -12,7 +12,7 @@ export interface FetcherResponse<T> {
12
12
  options: T[];
13
13
  }
14
14
  export interface BaseOptionType {
15
- id?: string;
15
+ displayValue?: string;
16
16
  value: string;
17
17
  }
18
18
  interface BaseComboboxProps<T extends BaseOptionType, M extends boolean> {
@@ -21,9 +21,9 @@ interface BaseComboboxProps<T extends BaseOptionType, M extends boolean> {
21
21
  noResultMessage?: ReactElement | string;
22
22
  onInputValueChange?: (inputValue: string) => void;
23
23
  multiselect: M;
24
- onValueChange?: (selectedOptions: M extends true ? T[] : T) => void;
25
- value?: M extends true ? T[] : T;
26
- defaultValue?: M extends true ? T[] : T;
24
+ onValueChange?: (selectedOptions: T[]) => void;
25
+ value?: T[];
26
+ defaultValue?: T[];
27
27
  label: string;
28
28
  loadingAriaLabel?: string;
29
29
  portalElement?: HTMLElement | (() => HTMLElement);