@box/combobox-with-api 1.15.9 → 1.16.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,48 +1,47 @@
1
1
  import { ComboboxItemValue as ce } from "@ariakit/react";
2
- import { Combobox as m, useForkRef as ue, LoadingIndicator as de, InlineNotice as pe, Text as me } from "@box/blueprint-web";
3
- import { Search as fe, Loader as he } from "@box/blueprint-web-assets/icons/Fill";
4
- import { IconIconOnLightSecondary as ge, Size6 as V, Size1 as be } from "@box/blueprint-web-assets/tokens/tokens";
5
- import N from "clsx";
6
- import { forwardRef as B, useRef as L, useState as xe, useCallback as k, useMemo as y, useEffect as Oe } from "react";
7
- import { useIntl as W, FormattedMessage as F } from "react-intl";
2
+ import { Combobox as d, useForkRef as ue, LoadingIndicator as de, InlineNotice as pe, Text as me } from "@box/blueprint-web";
3
+ import { Search as he, Loader as fe } from "@box/blueprint-web-assets/icons/Fill";
4
+ import { Size6 as V, Size1 as ge, IconIconOnLightSecondary as be } from "@box/blueprint-web-assets/tokens/tokens";
5
+ import S from "clsx";
6
+ import { forwardRef as D, useRef as A, useState as xe, useCallback as N, useMemo as L, useEffect as Oe } from "react";
7
+ import { useIntl as B, FormattedMessage as k } from "react-intl";
8
8
  import a from "./messages.js";
9
9
  import { useAsyncList as _e } from "./use-async-list.js";
10
- import { useControllableState as Re } from "./utils/use-controllable-state.js";
11
- import { useTrackVisibility as Ae } from "./utils/use-intersection-observer.js";
12
- import { jsx as r, jsxs as P, Fragment as Ce } from "react/jsx-runtime";
13
- import '../../../../styles/combobox-with-api-pagination.css';const Le = "_container_19k3s_2", ye = "_disabled_19k3s_8", Ee = "_highlightOptionText_19k3s_12", ve = "_selected_19k3s_24", Ie = "_option_19k3s_35", Me = "_errorComboboxOption_19k3s_39", Te = "_errorComboboxOptionText_19k3s_44", c = {
14
- container: Le,
15
- disabled: ye,
16
- highlightOptionText: Ee,
17
- selected: ve,
10
+ import { useControllableState as Ce } from "./utils/use-controllable-state.js";
11
+ import { useTrackVisibility as Re } from "./utils/use-intersection-observer.js";
12
+ import { jsx as r, jsxs as F, Fragment as Ae } from "react/jsx-runtime";
13
+ import '../../../../styles/combobox-with-api-pagination.css';const Le = "_disabled_19k3s_8", ye = "_highlightOptionText_19k3s_12", Ee = "_selected_19k3s_24", Ie = "_option_19k3s_35", ve = "_errorComboboxOption_19k3s_39", Me = "_errorComboboxOptionText_19k3s_44", i = {
14
+ disabled: Le,
15
+ highlightOptionText: ye,
16
+ selected: Ee,
18
17
  option: Ie,
19
- errorComboboxOption: Me,
20
- errorComboboxOptionText: Te
21
- }, D = /* @__PURE__ */ B(({
18
+ errorComboboxOption: ve,
19
+ errorComboboxOptionText: Me
20
+ }, P = /* @__PURE__ */ D(({
22
21
  onTryAgain: I
23
- }, f) => {
22
+ }, p) => {
24
23
  const {
25
- formatMessage: h
26
- } = W();
27
- return /* @__PURE__ */ P(Ce, {
24
+ formatMessage: m
25
+ } = B();
26
+ return /* @__PURE__ */ F(Ae, {
28
27
  children: [/* @__PURE__ */ r(pe, {
29
28
  variant: "error",
30
- variantIconAriaLabel: h(a.loadingResultsErrorIconLabel),
31
- children: /* @__PURE__ */ r(F, {
29
+ variantIconAriaLabel: m(a.loadingResultsErrorIconLabel),
30
+ children: /* @__PURE__ */ r(k, {
32
31
  ...a.loadingResultsErrorMessage
33
32
  })
34
- }), /* @__PURE__ */ r(m.Option, {
35
- ref: f,
36
- className: c.errorComboboxOption,
33
+ }), /* @__PURE__ */ r(d.Option, {
34
+ ref: p,
35
+ className: i.errorComboboxOption,
37
36
  onClick: I,
38
- children: /* @__PURE__ */ P(me, {
37
+ children: /* @__PURE__ */ F(me, {
39
38
  as: "span",
40
- className: c.errorComboboxOptionText,
39
+ className: i.errorComboboxOptionText,
41
40
  color: "textOnLightLink",
42
41
  variant: "bodyDefaultBold",
43
- children: [/* @__PURE__ */ r(F, {
42
+ children: [/* @__PURE__ */ r(k, {
44
43
  ...a.loadingResultsErrorAction
45
- }), /* @__PURE__ */ r(he, {
44
+ }), /* @__PURE__ */ r(fe, {
46
45
  color: "currentColor",
47
46
  height: "12px",
48
47
  width: "12px"
@@ -50,158 +49,156 @@ import '../../../../styles/combobox-with-api-pagination.css';const Le = "_contai
50
49
  })
51
50
  })]
52
51
  });
53
- }), E = "__LOADING__", v = "__LOADING_ERROR__", Se = "0px 0px 20px 0px", Ve = /* @__PURE__ */ r(fe, {
54
- color: ge,
52
+ }), y = "__LOADING__", E = "__LOADING_ERROR__", Te = "0px 0px 20px 0px", Ve = /* @__PURE__ */ r(he, {
53
+ color: be,
55
54
  height: V,
56
55
  role: "presentation",
57
56
  style: {
58
- padding: be,
57
+ padding: ge,
59
58
  boxSizing: "border-box"
60
59
  },
61
60
  width: V
62
- }), qe = /* @__PURE__ */ B(function(f, h) {
61
+ }), Ue = /* @__PURE__ */ D(function(p, m) {
63
62
  const {
64
- dataTargetId: w,
65
- defaultFetcher: z,
66
- initialOpen: G = !1,
67
- onInputValueChange: g,
63
+ dataTargetId: W,
64
+ defaultFetcher: w,
65
+ initialOpen: z = !1,
66
+ onInputValueChange: G,
68
67
  value: j,
69
68
  onValueChange: U,
70
- onOpenChange: s,
69
+ onOpenChange: h,
71
70
  noResultMessage: q,
72
71
  defaultValue: H = [],
73
72
  loadingAriaLabel: J,
74
- multiselect: i = !1,
73
+ multiselect: s = !1,
75
74
  disabled: K,
76
75
  className: Q,
77
- displaySingleSelectionAsChip: b = !0,
76
+ displaySingleSelectionAsChip: f = !0,
78
77
  ...X
79
- } = f, {
80
- formatMessage: d
81
- } = W(), x = L(null), O = L(!0), [Y, M] = xe(G), o = _e({
78
+ } = p, {
79
+ formatMessage: c
80
+ } = B(), g = A(null), b = A(!0), [Y, v] = xe(z), e = _e({
82
81
  async load({
83
- marker: e,
82
+ marker: o,
84
83
  searchInput: t,
85
84
  signal: C
86
85
  }) {
87
- const u = await z({
86
+ const l = await w({
88
87
  signal: C,
89
- marker: e,
88
+ marker: o,
90
89
  searchInput: t
91
90
  });
92
91
  return {
93
- items: u.options,
94
- marker: u.marker
92
+ items: l.options,
93
+ marker: l.marker
95
94
  };
96
95
  }
97
- }), T = L(!1), Z = k(() => {
98
- T.current || (o.reload(), T.current = !0);
99
- }, []), [n, _] = Re({
96
+ }), M = A(!1), Z = N(() => {
97
+ M.current || (e.reload(), M.current = !0);
98
+ }, []), [n, x] = Ce({
100
99
  prop: j,
101
100
  defaultProp: H,
102
101
  onChange: U
103
- }), R = !i && n.length === 1, $ = k((e) => {
104
- M(e), s == null || s(e);
105
- }, [s]), ee = (e) => {
106
- e === void 0 ? (_([]), (!O.current || !b) && (o.search(""), O.current = !0)) : Array.isArray(e) ? _(e) : (_([e]), i || (M(!1), s == null || s(!1)));
107
- }, oe = y(() => n.length === 0 ? i ? [] : void 0 : i ? n : n[0], [i, n]), A = y(() => n.filter((e) => !o.items.some((t) => t.value === e.value)), [n, o.items]), te = (e) => {
102
+ }), O = !s && n.length === 1, $ = N((o) => {
103
+ v(o), h?.(o);
104
+ }, [h]), ee = (o) => {
105
+ o === void 0 ? (x([]), (!b.current || !f) && (e.search(""), b.current = !0)) : Array.isArray(o) ? x(o) : (x([o]), s || (v(!1), h?.(!1)));
106
+ }, oe = L(() => n.length === 0 ? s ? [] : void 0 : s ? n : n[0], [s, n]), _ = L(() => n.filter((o) => !e.items.some((t) => t.value === o.value)), [n, e.items]), te = (o) => {
108
107
  const {
109
108
  value: t,
110
109
  displayValue: C,
111
- ...u
112
- } = e;
113
- if (t === E)
114
- return o.hasNextPage ? /* @__PURE__ */ r(m.Option, {
115
- ...u,
116
- ref: se,
110
+ ...l
111
+ } = o;
112
+ if (t === y)
113
+ return e.hasNextPage ? /* @__PURE__ */ r(d.Option, {
114
+ ...l,
115
+ ref: ae,
117
116
  disabled: !0,
118
117
  value: t,
119
118
  children: /* @__PURE__ */ r(de, {
120
- "aria-label": d(a.loadingMoreAriaLabel),
119
+ "aria-label": c(a.loadingMoreAriaLabel),
121
120
  style: {
122
121
  position: "unset"
123
122
  }
124
123
  })
125
124
  }) : null;
126
- if (t === v && o.hasError && !o.isEmpty)
127
- return /* @__PURE__ */ r(D, {
125
+ if (t === E && e.hasError && !e.isEmpty)
126
+ return /* @__PURE__ */ r(P, {
128
127
  onTryAgain: () => {
129
- var l;
130
- o.loadMore(), (l = x.current) == null || l.focus();
128
+ e.loadMore(), g.current?.focus();
131
129
  }
132
130
  });
133
- if (A.some((l) => l.value === t))
131
+ if (_.some((R) => R.value === t))
134
132
  return null;
135
- const le = n.some((l) => l.value === t);
136
- return /* @__PURE__ */ r(m.Option, {
137
- ...u,
138
- className: c.option,
133
+ const le = n.some((R) => R.value === t);
134
+ return /* @__PURE__ */ r(d.Option, {
135
+ ...l,
136
+ className: i.option,
139
137
  value: t,
140
138
  children: /* @__PURE__ */ r(ce, {
141
- className: N(c.highlightOptionText, le && c.selected),
139
+ className: S(i.highlightOptionText, le && i.selected),
142
140
  value: C || t
143
141
  })
144
142
  });
145
- }, re = (e) => {
146
- if (g == null || g(e), R && e === "") {
147
- O.current = !1;
143
+ }, re = (o) => {
144
+ if (G?.(o), O && o === "") {
145
+ b.current = !1;
148
146
  return;
149
147
  }
150
- o.search(e);
148
+ e.search(o);
151
149
  }, ne = () => {
152
- var e;
153
- o.reload(), (e = x.current) == null || e.focus();
150
+ e.reload(), g.current?.focus();
154
151
  };
155
- let p;
156
- o.hasError && !o.isLoading ? p = /* @__PURE__ */ r(D, {
152
+ let u;
153
+ e.hasError && !e.isLoading ? u = /* @__PURE__ */ r(P, {
157
154
  onTryAgain: ne
158
- }) : o.isEmpty && !o.isLoading ? p = q || d(a.noResults) : p = void 0;
159
- const [se, {
160
- rootRef: ae,
161
- isVisible: S
162
- }] = Ae({
163
- rootMargin: Se
155
+ }) : e.isEmpty && !e.isLoading ? u = q || c(a.noResults) : u = void 0;
156
+ const [ae, {
157
+ rootRef: se,
158
+ isVisible: T
159
+ }] = Re({
160
+ rootMargin: Te
164
161
  });
165
162
  Oe(() => {
166
- if (!(S && o.hasNextPage))
163
+ if (!(T && e.hasNextPage))
167
164
  return;
168
165
  const t = setTimeout(() => {
169
- o.loadMore();
166
+ e.loadMore();
170
167
  }, 100);
171
168
  return () => {
172
169
  clearTimeout(t);
173
170
  };
174
- }, [S]);
175
- const ie = y(() => {
176
- const e = o.hasNextPage ? {
171
+ }, [T]);
172
+ const ie = L(() => {
173
+ const o = e.hasNextPage ? {
174
+ displayValue: y,
175
+ value: y
176
+ } : null, t = !o && e.hasError && !e.isEmpty ? {
177
177
  displayValue: E,
178
178
  value: E
179
- } : null, t = !e && o.hasError && !o.isEmpty ? {
180
- displayValue: v,
181
- value: v
182
179
  } : null;
183
- return [...o.items, ...A, e, t].filter(Boolean);
184
- }, [o.hasNextPage, o.hasError, o.isEmpty, o.items, A]);
185
- return /* @__PURE__ */ r(m, {
180
+ return [...e.items, ..._, o, t].filter(Boolean);
181
+ }, [e.hasNextPage, e.hasError, e.isEmpty, e.items, _]);
182
+ return /* @__PURE__ */ r(d, {
186
183
  ...X,
187
- ref: ue(x, h),
184
+ ref: ue(g, m),
188
185
  as: "input",
189
- className: N({
190
- [c.disabled]: R
186
+ className: S({
187
+ [i.disabled]: O
191
188
  }, Q),
192
- clearButtonAriaLabel: d(a.clearButtonAriaLabel),
189
+ clearButtonAriaLabel: c(a.clearButtonAriaLabel),
193
190
  clearOnBlur: !1,
194
- "data-target-id": w,
195
- disabled: K || R && b,
196
- displaySingleSelectionAsChip: b,
197
- displayValue: (e) => e.displayValue || e.value,
191
+ "data-target-id": W,
192
+ disabled: K || O && f,
193
+ displaySingleSelectionAsChip: f,
194
+ displayValue: (o) => o.displayValue || o.value,
198
195
  endComboboxIcon: Ve,
199
196
  focusLoop: !1,
200
- getPopoverRef: ae,
201
- loading: o.isReloading,
202
- loadingAriaLabel: J || d(a.loadingAriaLabel),
203
- multiselect: i,
204
- noResultMessage: p,
197
+ getPopoverRef: se,
198
+ loading: e.isReloading,
199
+ loadingAriaLabel: J || c(a.loadingAriaLabel),
200
+ multiselect: s,
201
+ noResultMessage: u,
205
202
  onFocus: Z,
206
203
  onInputValueChange: re,
207
204
  onOpenChange: $,
@@ -213,5 +210,5 @@ import '../../../../styles/combobox-with-api-pagination.css';const Le = "_contai
213
210
  });
214
211
  });
215
212
  export {
216
- qe as ComboboxWithApiPagination
213
+ Ue as ComboboxWithApiPagination
217
214
  };
@@ -1,6 +1,6 @@
1
- let C = /* @__PURE__ */ function(E) {
1
+ let C = /* @__PURE__ */ (function(E) {
2
2
  return E.NOT_STARTED = "NOT_STARTED", E.IN_PROGRESS = "IN_PROGRESS", E.ERROR = "ERROR", E.SUCCESS = "SUCCESS", E.CANCELLED = "CANCELLED", E;
3
- }({});
3
+ })({});
4
4
  export {
5
5
  C as RequestStates
6
6
  };
@@ -1,9 +1,9 @@
1
1
  import { useReducer as O } from "react";
2
2
  import { RequestStates as u } from "./request.js";
3
3
  import { isAbortError as I } from "./utils/is-abort-error.js";
4
- var s = /* @__PURE__ */ function(r) {
4
+ var s = /* @__PURE__ */ (function(r) {
5
5
  return r.LOAD_MORE = "LOAD_MORE", r.RELOAD = "RELOAD", r.SEARCH = "SEARCH", r.SET_ERROR = "SET_ERROR", r.SET_LOADING = "SET_LOADING", r;
6
- }(s || {});
6
+ })(s || {});
7
7
  function a(r, e) {
8
8
  switch (e.type) {
9
9
  case s.LOAD_MORE:
@@ -63,8 +63,7 @@ function m(r, e) {
63
63
  return E(r, e) || S(r, e);
64
64
  }
65
65
  function p(r, e) {
66
- var t;
67
- E(r, e) && e.abortController.abort(), S(r, e) && ((t = r.abortController) == null || t.abort());
66
+ E(r, e) && e.abortController.abort(), S(r, e) && r.abortController?.abort();
68
67
  }
69
68
  function h(r, e) {
70
69
  return S(r, e);
@@ -1,40 +1,37 @@
1
- import * as s from "react";
1
+ import * as o from "react";
2
2
  function a(e) {
3
- const n = s.useRef(e);
4
- return s.useEffect(() => {
5
- n.current = e;
6
- }), s.useMemo(() => (...o) => {
7
- var t;
8
- return (t = n.current) == null ? void 0 : t.call(n, ...o);
9
- }, []);
3
+ const c = o.useRef(e);
4
+ return o.useEffect(() => {
5
+ c.current = e;
6
+ }), o.useMemo(() => (...t) => c.current?.(...t), []);
10
7
  }
11
- function R({
8
+ function v({
12
9
  prop: e,
13
- defaultProp: n,
14
- onChange: o = () => {
10
+ defaultProp: c,
11
+ onChange: t = () => {
15
12
  }
16
13
  }) {
17
- const [t, c] = C({
18
- defaultProp: n,
19
- onChange: o
20
- }), r = e !== void 0, i = r ? e : t, l = a(o), d = s.useCallback((u) => {
14
+ const [n, s] = R({
15
+ defaultProp: c,
16
+ onChange: t
17
+ }), r = e !== void 0, i = r ? e : n, l = a(t), d = o.useCallback((u) => {
21
18
  if (r) {
22
19
  const f = typeof u == "function" ? u(e) : u;
23
20
  f !== e && l(f);
24
21
  } else
25
- c(u);
26
- }, [r, e, c, l]);
22
+ s(u);
23
+ }, [r, e, s, l]);
27
24
  return [i, d];
28
25
  }
29
- function C({
26
+ function R({
30
27
  defaultProp: e,
31
- onChange: n
28
+ onChange: c
32
29
  }) {
33
- const o = s.useState(e), [t] = o, c = s.useRef(t), r = a(n);
34
- return s.useEffect(() => {
35
- c.current !== t && (r(t), c.current = t);
36
- }, [t, c, r]), o;
30
+ const t = o.useState(e), [n] = t, s = o.useRef(n), r = a(c);
31
+ return o.useEffect(() => {
32
+ s.current !== n && (r(n), s.current = n);
33
+ }, [n, s, r]), t;
37
34
  }
38
35
  export {
39
- R as useControllableState
36
+ v as useControllableState
40
37
  };
@@ -1,87 +1,85 @@
1
- import { useState as C, useRef as y, useCallback as a } from "react";
2
- const k = "0px", p = [0];
3
- function w() {
4
- const o = /* @__PURE__ */ new Map();
5
- function b({
6
- root: c,
7
- rootMargin: s,
8
- threshold: u
1
+ import { useState as y, useRef as R, useCallback as f } from "react";
2
+ const k = "0px", g = [0];
3
+ function C() {
4
+ const b = /* @__PURE__ */ new Map();
5
+ function a({
6
+ root: s,
7
+ rootMargin: t,
8
+ threshold: c
9
9
  }) {
10
- let r = o.get(c);
11
- r || (r = /* @__PURE__ */ new Map(), o.set(c, r));
10
+ let r = b.get(s);
11
+ r || (r = /* @__PURE__ */ new Map(), b.set(s, r));
12
12
  const i = JSON.stringify({
13
- rootMargin: s,
14
- threshold: u
13
+ rootMargin: t,
14
+ threshold: c
15
15
  });
16
- let e = r.get(i);
17
- if (!e) {
18
- const n = /* @__PURE__ */ new Map();
19
- e = {
20
- observer: new IntersectionObserver((R) => {
21
- R.forEach((v) => {
22
- const t = n.get(v.target);
23
- t == null || t(v);
16
+ let n = r.get(i);
17
+ if (!n) {
18
+ const e = /* @__PURE__ */ new Map();
19
+ n = {
20
+ observer: new IntersectionObserver((O) => {
21
+ O.forEach((v) => {
22
+ e.get(v.target)?.(v);
24
23
  });
25
24
  }, {
26
- root: c,
27
- rootMargin: s,
28
- threshold: u
25
+ root: s,
26
+ rootMargin: t,
27
+ threshold: c
29
28
  }),
30
- entryCallbacks: n
31
- }, r.set(i, e);
29
+ entryCallbacks: e
30
+ }, r.set(i, n);
32
31
  }
33
32
  return {
34
- observe: (n, l) => {
35
- e == null || e.entryCallbacks.set(n, l), e == null || e.observer.observe(n);
33
+ observe: (e, l) => {
34
+ n?.entryCallbacks.set(e, l), n?.observer.observe(e);
36
35
  },
37
- unobserve: (n) => {
38
- e == null || e.entryCallbacks.delete(n), e == null || e.observer.unobserve(n);
36
+ unobserve: (e) => {
37
+ n?.entryCallbacks.delete(e), n?.observer.unobserve(e);
39
38
  }
40
39
  };
41
40
  }
42
41
  return {
43
- getObserver: b
42
+ getObserver: a
44
43
  };
45
44
  }
46
- const M = w();
47
- function T(o) {
48
- const b = (o == null ? void 0 : o.rootMargin) ?? k, c = (o == null ? void 0 : o.threshold) ?? p, s = y(null), u = y(null), r = y(null), [i, e] = C(), n = a(() => {
49
- const t = s.current;
50
- if (!t) {
51
- e(void 0);
45
+ const E = C();
46
+ function p(b) {
47
+ const a = b?.rootMargin ?? k, s = b?.threshold ?? g, t = R(null), c = R(null), r = R(null), [i, n] = y(), e = f(() => {
48
+ const o = t.current;
49
+ if (!o) {
50
+ n(void 0);
52
51
  return;
53
52
  }
54
- const f = M.getObserver({
55
- root: u.current,
56
- rootMargin: b,
57
- threshold: c
53
+ const u = E.getObserver({
54
+ root: c.current,
55
+ rootMargin: a,
56
+ threshold: s
58
57
  });
59
- f.observe(t, (E) => {
60
- e(E);
61
- }), r.current = f;
62
- }, [b, c]), l = a(() => {
63
- const t = r.current, f = s.current;
64
- f && (t == null || t.unobserve(f)), r.current = null;
65
- }, []), R = a((t) => {
66
- l(), s.current = t, n();
67
- }, [n, l]), v = a((t) => {
68
- l(), u.current = t, n();
69
- }, [n, l]);
70
- return [R, {
58
+ u.observe(o, (h) => {
59
+ n(h);
60
+ }), r.current = u;
61
+ }, [a, s]), l = f(() => {
62
+ const o = r.current, u = t.current;
63
+ u && o?.unobserve(u), r.current = null;
64
+ }, []), O = f((o) => {
65
+ l(), t.current = o, e();
66
+ }, [e, l]), v = f((o) => {
67
+ l(), c.current = o, e();
68
+ }, [e, l]);
69
+ return [O, {
71
70
  entry: i,
72
71
  rootRef: v
73
72
  }];
74
73
  }
75
- function V(o) {
76
- var i;
77
- const [b, c] = T(o), s = !!((i = c.entry) != null && i.isIntersecting), [u, r] = C(s);
78
- return s && !u && r(!0), [b, {
79
- ...c,
80
- isVisible: s,
81
- wasEverVisible: u
74
+ function w(b) {
75
+ const [a, s] = p(b), t = !!s.entry?.isIntersecting, [c, r] = y(t);
76
+ return t && !c && r(!0), [a, {
77
+ ...s,
78
+ isVisible: t,
79
+ wasEverVisible: c
82
80
  }];
83
81
  }
84
82
  export {
85
- w as createObserverCache,
86
- V as useTrackVisibility
83
+ C as createObserverCache,
84
+ w as useTrackVisibility
87
85
  };