@box/combobox-with-api 0.45.10 → 0.46.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,45 +1,51 @@
1
- import { useState as e, useMemo as L, useCallback as S, useEffect as V } from "react";
2
- import T from "lodash/debounce";
3
- import { ComboboxWithApi as w } from "./combobox-with-api.js";
4
- import { jsx as Q } from "react/jsx-runtime";
5
- const W = "AbortError", _ = (b) => {
1
+ import { useState as s, useMemo as d, useCallback as Q, useEffect as T } from "react";
2
+ import w from "lodash/debounce";
3
+ import { ComboboxWithApi as D } from "./combobox-with-api.js";
4
+ import { jsx as W } from "react/jsx-runtime";
5
+ const j = "AbortError", _ = (E) => {
6
6
  const {
7
- debounceTime: l = 250,
8
- fetcher: u,
9
- includeTextInputOption: f = !1,
10
- onInputValueChange: s,
11
- ...h
12
- } = b, [m, p] = e(!1), [d, y] = e(!1), [E, g] = e(!1), [o, x] = e(""), [A, r] = e([]), i = L(() => T(x, l), [l]), C = (n) => {
13
- i(n), s == null || s(n);
14
- }, a = S(async (n) => {
15
- const c = n.trim();
16
- if (c) {
17
- y(!1), p(!0);
7
+ debounceTime: u = 250,
8
+ defaultOptions: n,
9
+ fetcher: f,
10
+ includeTextInputOption: m = !1,
11
+ onInputValueChange: i,
12
+ ...O
13
+ } = E, [p, h] = s(!1), [x, g] = s(!1), [A, y] = s(!1), [e, C] = s(""), [b, a] = s([]), c = d(() => w(C, u), [u]), I = (o) => {
14
+ c(o), i == null || i(o);
15
+ }, l = Q(async (o) => {
16
+ const r = o.trim();
17
+ if (r) {
18
+ g(!1), h(!0);
18
19
  try {
19
- const t = await u(c);
20
- if ((t.length > 0 ? typeof t[0] == "string" : !0) && f) {
21
- const O = c.toLocaleLowerCase();
22
- r([O, ...t]);
20
+ const t = await f(r);
21
+ if ((t.length > 0 ? typeof t[0] == "string" : !0) && m) {
22
+ const V = r.toLocaleLowerCase();
23
+ a([V, ...t]);
23
24
  } else
24
- g((t == null ? void 0 : t.length) === 0), r(t);
25
+ y((t == null ? void 0 : t.length) === 0), a(t);
25
26
  } catch (t) {
26
- (t == null ? void 0 : t.name) !== W && y(!0);
27
+ (t == null ? void 0 : t.name) !== j && g(!0);
27
28
  } finally {
28
- p(!1);
29
+ h(!1);
29
30
  }
30
31
  }
31
- }, [u, f]), I = () => {
32
- a(o);
32
+ }, [f, m]), L = () => {
33
+ l(e);
33
34
  };
34
- return V(() => (o.trim().length ? a(o) : (r([]), g(!1)), () => i.cancel()), [i, a, o]), /* @__PURE__ */ Q(w, {
35
- ...h,
36
- isEmpty: E,
37
- isError: d,
38
- isLoading: m,
39
- loading: m,
40
- onInputValueChange: C,
41
- onTryAgain: I,
42
- options: A
35
+ T(() => (e.trim().length ? l(e) : (a([]), y(!1)), () => c.cancel()), [c, l, e]);
36
+ const S = d(() => {
37
+ const o = e.trim().length > 0;
38
+ return (n == null ? void 0 : n.length) > 0 && !o ? n : b;
39
+ }, [e, n, b]);
40
+ return /* @__PURE__ */ W(D, {
41
+ ...O,
42
+ isEmpty: A,
43
+ isError: x,
44
+ isLoading: p,
45
+ loading: p,
46
+ onInputValueChange: I,
47
+ onTryAgain: L,
48
+ options: S
43
49
  });
44
50
  };
45
51
  export {
@@ -30,6 +30,10 @@ export type ComboboxWithApiContainerProps<Multiple extends boolean, FreeInput ex
30
30
  * Boolean to show a dropdown option for text input
31
31
  */
32
32
  includeTextInputOption?: boolean;
33
+ /**
34
+ * Default options to show when the input is empty
35
+ */
36
+ defaultOptions?: T[];
33
37
  };
34
38
  export type ComboboxWithApiErrorProps = {
35
39
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@box/combobox-with-api",
3
- "version": "0.45.10",
3
+ "version": "0.46.0",
4
4
  "peerDependencies": {
5
5
  "@ariakit/react": "0.4.15",
6
6
  "@box/blueprint-web": "^10.3.1",