@box/combobox-with-api 1.15.9 → 1.17.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,82 +1,73 @@
1
1
  import { LoadingIndicator as Z } from "@box/blueprint-web";
2
2
  import { InlineError as $, Tree as F } from "@box/tree";
3
- import { forwardRef as P, useReducer as ee, useState as A, useMemo as ae, useCallback as p, useEffect as M } from "react";
3
+ import { forwardRef as P, useReducer as ee, useState as A, useMemo as ae, useCallback as u, useEffect as U } from "react";
4
4
  import { RootTreeNode as m, hasValidLevel as te, getServiceNode as D } from "../esm/lib/components/combobox-with-api-tree-view/tree-utils.js";
5
- import { t as le, i as oe, A as r } from "./treeReducer.js";
5
+ import { t as le, i as se, A as o } from "./treeReducer.js";
6
6
  import { jsx as f, jsxs as ne } from "react/jsx-runtime";
7
- import '../styles/dynamic-loading-tree.css';const se = "_container_1wa8l_2", re = "_disabled_1wa8l_13", ie = "_label_1wa8l_16", de = "_hiddenLabel_1wa8l_28", ce = "_comboboxContainer_1wa8l_31", me = "_withComboboxButtons_1wa8l_47", pe = "_error_1wa8l_55", _e = "_textInputWrapper_1wa8l_63", ue = "_textInput_1wa8l_63", be = "_errorIcon_1wa8l_85", ye = "_comboboxButtons_1wa8l_88", he = "_withChips_1wa8l_95", ve = "_inlineError_1wa8l_105", fe = "_popover_1wa8l_109", Ie = "_option_1wa8l_135", we = "_indicator_1wa8l_158", ge = "_indicatorIcon_1wa8l_167", Se = "_optionWithIndicator_1wa8l_170", Ee = "_loadingIndicator_1wa8l_173", Ne = "_noResultOption_1wa8l_176", C = {
8
- container: se,
9
- disabled: re,
10
- label: ie,
7
+ import '../styles/dynamic-loading-tree.css';const oe = "_container_1wa8l_2", re = "_label_1wa8l_16", de = "_hiddenLabel_1wa8l_28", ie = "_comboboxContainer_1wa8l_31", ce = "_withComboboxButtons_1wa8l_47", me = "_textInputWrapper_1wa8l_63", ue = "_textInput_1wa8l_63", pe = "_comboboxButtons_1wa8l_88", be = "_withChips_1wa8l_95", ye = "_popover_1wa8l_109", _e = "_loadingIndicator_1wa8l_173", he = "_noResultOption_1wa8l_176", C = {
8
+ container: oe,
9
+ label: re,
11
10
  hiddenLabel: de,
12
- comboboxContainer: ce,
13
- withComboboxButtons: me,
14
- error: pe,
15
- textInputWrapper: _e,
11
+ comboboxContainer: ie,
12
+ withComboboxButtons: ce,
13
+ textInputWrapper: me,
16
14
  textInput: ue,
17
- errorIcon: be,
18
- comboboxButtons: ye,
19
- withChips: he,
20
- inlineError: ve,
21
- popover: fe,
22
- option: Ie,
23
- indicator: we,
24
- indicatorIcon: ge,
25
- optionWithIndicator: Se,
26
- loadingIndicator: Ee,
27
- noResultOption: Ne
28
- }, Oe = (n) => {
29
- const d = [...n.children], {
15
+ comboboxButtons: pe,
16
+ withChips: be,
17
+ popover: ye,
18
+ loadingIndicator: _e,
19
+ noResultOption: he
20
+ }, ve = (s) => {
21
+ const i = [...s.children], {
30
22
  metadata: c
31
- } = n;
23
+ } = s;
32
24
  return {
33
- ...n,
34
- children: d,
25
+ ...s,
26
+ children: i,
35
27
  metadata: {
36
- ...n.metadata,
28
+ ...s.metadata,
37
29
  variant: c.variant,
38
- isLoading: n.status === "loading" && !n.children.length,
30
+ isLoading: s.status === "loading" && !s.children.length,
39
31
  labelName: c.labelName || "",
40
32
  labelValue: c.labelValue || ""
41
33
  }
42
34
  };
43
- }, Re = (n, d) => {
35
+ }, fe = (s, i) => {
44
36
  let c;
45
- return n.children.length && n.status === "loading" && (c = D(d.id, d.metadata.displayValue, "loading")), n.status === "error" && (c = D(d.id, d.metadata.displayValue, "reload")), n.status === "success" && n.marker && (c = D(d.id, d.metadata.displayValue, "loadMore")), c;
46
- }, Ve = /* @__PURE__ */ P(({
47
- ariaLabel: n,
48
- onSelect: d,
37
+ return s.children.length && s.status === "loading" && (c = D(i.id, i.metadata.displayValue, "loading")), s.status === "error" && (c = D(i.id, i.metadata.displayValue, "reload")), s.status === "success" && s.marker && (c = D(i.id, i.metadata.displayValue, "loadMore")), c;
38
+ }, Ie = /* @__PURE__ */ P(({
39
+ ariaLabel: s,
40
+ onSelect: i,
49
41
  selectedNodes: c,
50
- defaultFetcher: u,
51
- levels: N,
52
- selectableLevels: I,
53
- multiselect: U,
42
+ defaultFetcher: b,
43
+ levels: w,
44
+ selectableLevels: g,
45
+ multiselect: W,
54
46
  open: L,
55
- searchInput: _,
47
+ searchInput: p,
56
48
  noResultMessage: z,
57
49
  loadingAriaLabel: q
58
50
  }, G) => {
59
- const [y, o] = ee(le, oe), [v, H] = A({
51
+ const [_, l] = ee(le, se), [v, H] = A({
60
52
  nodes: [],
61
53
  selectedIds: []
62
- }), [O, b] = A(!1), [w, g] = A(!1), S = ae(() => Math.max(...I), [I]), V = p((e = y) => {
54
+ }), [I, y] = A(!1), [S, N] = A(!1), O = ae(() => Math.max(...g), [g]), V = u((e = _) => {
63
55
  const t = [];
64
56
  return [...Object.values(e).map((a) => {
65
- const s = Oe(a), l = Re(a, s);
66
- return l && (t.push(l), s.children.push(l.id)), s;
57
+ const n = ve(a), d = fe(a, n);
58
+ return d && (t.push(d), n.children.push(d.id)), n;
67
59
  }), ...t];
68
- }, [y]), k = p((e) => {
69
- var s;
70
- const t = (s = e.ancestors) == null ? void 0 : s.find((l) => l.level === e.level - 1), i = N.find((l) => l.level === e.level);
71
- return e.level === 1 || _ === "" ? e.displayValue : {
72
- labelName: i.displayName,
60
+ }, [_]), k = u((e) => {
61
+ const t = e.ancestors?.find((n) => n.level === e.level - 1), r = w.find((n) => n.level === e.level);
62
+ return e.level === 1 || p === "" ? e.displayValue : {
63
+ labelName: r.displayName,
73
64
  labelValue: t.displayName
74
65
  };
75
- }, [N, _]), h = p((e) => ({
66
+ }, [w, p]), h = u((e) => ({
76
67
  id: e.value,
77
68
  name: e.displayValue,
78
69
  parent: m.id,
79
- isBranch: e.level !== S,
70
+ isBranch: e.level !== O,
80
71
  children: [],
81
72
  metadata: {
82
73
  variant: "content",
@@ -86,68 +77,68 @@ import '../styles/dynamic-loading-tree.css';const se = "_container_1wa8l_2", re
86
77
  marker: e.marker,
87
78
  ancestors: e.ancestors
88
79
  }
89
- }), [S]), R = p((e, t) => {
90
- o({
91
- type: r.RESET,
80
+ }), [O]), x = u((e, t) => {
81
+ l({
82
+ type: o.RESET,
92
83
  payload: {
93
84
  id: m.id,
94
85
  items: []
95
86
  }
96
- }), o({
97
- type: r.LOAD_SUCCESS,
87
+ }), l({
88
+ type: o.LOAD_SUCCESS,
98
89
  payload: {
99
90
  id: m.id,
100
91
  items: e,
101
92
  marker: t
102
93
  }
103
- }), b(!1);
104
- }, [o, b]), x = p(() => {
105
- o({
106
- type: r.LOAD_ERROR,
94
+ }), y(!1);
95
+ }, [l, y]), E = u(() => {
96
+ l({
97
+ type: o.LOAD_ERROR,
107
98
  payload: {
108
99
  id: m.id
109
100
  }
110
- }), b(!1), g(!0);
111
- }, [o, b, g]), J = p((e, t) => {
112
- const i = new Set(e.map((a) => a.id));
113
- return t.filter((a) => i.has(a));
101
+ }), y(!1), N(!0);
102
+ }, [l, y, N]), J = u((e, t) => {
103
+ const r = new Set(e.map((a) => a.id));
104
+ return t.filter((a) => r.has(a));
114
105
  }, []);
115
- M(() => {
116
- const e = V(y);
106
+ U(() => {
107
+ const e = V(_);
117
108
  H({
118
109
  nodes: e,
119
110
  selectedIds: J(e, c)
120
111
  });
121
- }, [V, c, y, w]), M(() => {
112
+ }, [V, c, _, S]), U(() => {
122
113
  if (!L)
123
114
  return;
124
115
  const {
125
116
  signal: e
126
117
  } = new AbortController();
127
- b(!0), g(!1), _ ? (o({
128
- type: r.RESET,
118
+ y(!0), N(!1), p ? (l({
119
+ type: o.RESET,
129
120
  payload: {
130
121
  id: m.id,
131
122
  items: []
132
123
  }
133
- }), u({
124
+ }), b({
134
125
  signal: e,
135
126
  marker: null,
136
- searchInput: _,
127
+ searchInput: p,
137
128
  level: null,
138
129
  onlySelectableOptions: !1,
139
130
  ancestorId: null
140
131
  }).then((t) => {
141
- const i = t.options.filter((a) => a.selectable).map((a) => {
132
+ const r = t.options.filter((a) => a.selectable).map((a) => {
142
133
  const {
143
- labelName: s,
144
- labelValue: l
134
+ labelName: n,
135
+ labelValue: d
145
136
  } = k(a);
146
137
  return {
147
138
  id: a.value,
148
139
  name: a.displayValue,
149
140
  parent: m.id,
150
- isBranch: a.level < S,
141
+ isBranch: a.level < O,
151
142
  children: [],
152
143
  metadata: {
153
144
  variant: a.level === 1 ? "content" : "labeled",
@@ -155,26 +146,26 @@ import '../styles/dynamic-loading-tree.css';const se = "_container_1wa8l_2", re
155
146
  level: a.level,
156
147
  selectable: a.selectable,
157
148
  ancestors: a.ancestors,
158
- labelName: s,
159
- labelValue: l
149
+ labelName: n,
150
+ labelValue: d
160
151
  }
161
152
  };
162
153
  });
163
- R(i, t.marker);
154
+ x(r, t.marker);
164
155
  }).catch(() => {
165
- x();
166
- })) : (o({
167
- type: r.RESET,
156
+ E();
157
+ })) : (l({
158
+ type: o.RESET,
168
159
  payload: {
169
160
  id: m.id,
170
161
  items: []
171
162
  }
172
- }), o({
173
- type: r.LOAD_DATA,
163
+ }), l({
164
+ type: o.LOAD_DATA,
174
165
  payload: {
175
166
  id: m.id
176
167
  }
177
- }), u({
168
+ }), b({
178
169
  signal: e,
179
170
  marker: null,
180
171
  searchInput: "",
@@ -182,21 +173,21 @@ import '../styles/dynamic-loading-tree.css';const se = "_container_1wa8l_2", re
182
173
  onlySelectableOptions: !1,
183
174
  ancestorId: null
184
175
  }).then((t) => {
185
- const i = t.options.map(h);
186
- R(i, t.marker);
176
+ const r = t.options.map(h);
177
+ x(r, t.marker);
187
178
  }).catch(() => {
188
- x();
179
+ E();
189
180
  }));
190
- }, [u, h, L, _, N, S, k, R, x]);
191
- const K = p((e) => {
181
+ }, [b, h, L, p, w, O, k, x, E]);
182
+ const K = u((e) => {
192
183
  const {
193
184
  isExpanded: t,
194
- isDisabled: i,
185
+ isDisabled: r,
195
186
  element: a
196
187
  } = e;
197
- if (!t || i) {
198
- o({
199
- type: r.RESET,
188
+ if (!t || r) {
189
+ l({
190
+ type: o.RESET,
200
191
  payload: {
201
192
  id: a.id,
202
193
  items: []
@@ -205,109 +196,109 @@ import '../styles/dynamic-loading-tree.css';const se = "_container_1wa8l_2", re
205
196
  return;
206
197
  }
207
198
  const {
208
- level: s
199
+ level: n
209
200
  } = a.metadata, {
210
- id: l,
211
- marker: E
201
+ id: d,
202
+ marker: R
212
203
  } = a, {
213
204
  signal: T
214
205
  } = new AbortController();
215
- o({
216
- type: r.LOAD_DATA,
206
+ l({
207
+ type: o.LOAD_DATA,
217
208
  payload: {
218
- id: l
209
+ id: d
219
210
  }
220
- }), u({
211
+ }), b({
221
212
  signal: T,
222
- marker: E,
213
+ marker: R,
223
214
  searchInput: "",
224
- level: s + 1,
225
- ancestorId: l,
215
+ level: n + 1,
216
+ ancestorId: d,
226
217
  onlySelectableOptions: !1
227
- }).then((W) => {
228
- const Y = W.options.map((j) => (a.children.push(j.value), h(j)));
229
- o({
230
- type: r.LOAD_SUCCESS,
218
+ }).then((j) => {
219
+ const Y = j.options.map((M) => (a.children.push(M.value), h(M)));
220
+ l({
221
+ type: o.LOAD_SUCCESS,
231
222
  payload: {
232
- id: l,
223
+ id: d,
233
224
  items: Y,
234
- marker: W.marker
225
+ marker: j.marker
235
226
  }
236
227
  });
237
228
  }).catch(() => {
238
- o({
239
- type: r.LOAD_ERROR,
229
+ l({
230
+ type: o.LOAD_ERROR,
240
231
  payload: {
241
- id: l
232
+ id: d
242
233
  }
243
234
  });
244
235
  });
245
- }, [u, h]), B = p((e) => {
246
- w && (g(!1), b(!0));
247
- const t = y[e], {
248
- level: i
236
+ }, [b, h]), B = u((e) => {
237
+ S && (N(!1), y(!0));
238
+ const t = _[e], {
239
+ level: r
249
240
  } = t.metadata, {
250
241
  id: a,
251
- marker: s
242
+ marker: n
252
243
  } = t, {
253
- signal: l
244
+ signal: d
254
245
  } = new AbortController();
255
- o({
256
- type: r.LOAD_DATA,
246
+ l({
247
+ type: o.LOAD_DATA,
257
248
  payload: {
258
249
  id: a
259
250
  }
260
- }), u({
261
- signal: l,
262
- marker: s,
263
- searchInput: _,
264
- level: _ === "" ? i + 1 : null,
251
+ }), b({
252
+ signal: d,
253
+ marker: n,
254
+ searchInput: p,
255
+ level: p === "" ? r + 1 : null,
265
256
  ancestorId: a !== m.id ? a.toString() : null,
266
257
  onlySelectableOptions: !1
267
- }).then((E) => {
268
- const T = E.options.map(h);
269
- o({
270
- type: r.LOAD_SUCCESS,
258
+ }).then((R) => {
259
+ const T = R.options.map(h);
260
+ l({
261
+ type: o.LOAD_SUCCESS,
271
262
  payload: {
272
263
  id: a,
273
264
  items: T,
274
- marker: E.marker
265
+ marker: R.marker
275
266
  }
276
- }), b(!1);
267
+ }), y(!1);
277
268
  }).catch(() => {
278
- o({
279
- type: r.LOAD_ERROR,
269
+ l({
270
+ type: o.LOAD_ERROR,
280
271
  payload: {
281
272
  id: a,
282
- marker: s
273
+ marker: n
283
274
  }
284
275
  });
285
276
  });
286
- }, [u, w, h, _, y]), Q = v.nodes.length === 0 || v.nodes[0].children.length === 0 && v.nodes[0].id === m.id, X = p((e) => {
277
+ }, [b, S, h, p, _]), Q = v.nodes.length === 0 || v.nodes[0].children.length === 0 && v.nodes[0].id === m.id, X = u((e) => {
287
278
  const {
288
279
  metadata: t
289
280
  } = e.element;
290
- te(t) && I.includes(t.level) ? d(e) : (e.isSelected = !1, e.treeState.selectedIds.delete(e.element.id));
291
- }, [I, d]);
292
- return w ? /* @__PURE__ */ f($, {
281
+ te(t) && g.includes(t.level) ? i(e) : (e.isSelected = !1, e.treeState.selectedIds.delete(e.element.id));
282
+ }, [g, i]);
283
+ return S ? /* @__PURE__ */ f($, {
293
284
  onReload: () => {
294
285
  B("root");
295
286
  }
296
287
  }) : /* @__PURE__ */ ne("div", {
297
- children: [O && /* @__PURE__ */ f("div", {
288
+ children: [I && /* @__PURE__ */ f("div", {
298
289
  className: C.noResultOption,
299
290
  children: /* @__PURE__ */ f(Z, {
300
291
  "aria-label": q,
301
292
  className: C.loadingIndicator
302
293
  })
303
- }), Q && !O ? /* @__PURE__ */ f("div", {
294
+ }), Q && !I ? /* @__PURE__ */ f("div", {
304
295
  className: C.noResultOption,
305
296
  children: z
306
- }) : !O && /* @__PURE__ */ f(F, {
297
+ }) : !I && /* @__PURE__ */ f(F, {
307
298
  ref: G,
308
- "aria-label": n,
299
+ "aria-label": s,
309
300
  data: v.nodes,
310
- multiSelect: U,
301
+ multiSelect: W,
311
302
  onExpand: K,
312
303
  onLoadData: B,
313
304
  onNodeSelect: X,
@@ -318,6 +309,6 @@ import '../styles/dynamic-loading-tree.css';const se = "_container_1wa8l_2", re
318
309
  });
319
310
  });
320
311
  export {
321
- Ve as D,
312
+ Ie as D,
322
313
  C as s
323
314
  };
@@ -1,7 +1,7 @@
1
1
  import { RootTreeNode as n } from "../esm/lib/components/combobox-with-api-tree-view/tree-utils.js";
2
- let s = /* @__PURE__ */ function(r) {
2
+ let s = /* @__PURE__ */ (function(r) {
3
3
  return r.LOAD_DATA = "LOAD_DATA", r.LOAD_ERROR = "LOAD_DATA_ERROR", r.LOAD_SUCCESS = "LOAD_DATA_SUCCESS", r.LOAD_MORE = "LOAD_DATA_SUCCESS", r.RESET = "RESET", r;
4
- }({});
4
+ })({});
5
5
  const R = (r, A) => {
6
6
  const {
7
7
  id: e,
@@ -1,51 +1,51 @@
1
- import { useState as s, useMemo as d, useCallback as Q, useEffect as T } from "react";
1
+ import { useState as o, useMemo as y, useCallback as Q, useEffect as T } from "react";
2
2
  import w from "lodash/debounce";
3
3
  import { ComboboxWithApi as D } from "./combobox-with-api.js";
4
4
  import { jsx as W } from "react/jsx-runtime";
5
- const j = "AbortError", _ = (E) => {
5
+ const j = "AbortError", _ = (b) => {
6
6
  const {
7
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);
8
+ defaultOptions: r,
9
+ fetcher: l,
10
+ includeTextInputOption: f = !1,
11
+ onInputValueChange: O,
12
+ ...C
13
+ } = b, [p, m] = o(!1), [I, h] = o(!1), [E, g] = o(!1), [e, x] = o(""), [d, a] = o([]), i = y(() => w(x, u), [u]), A = (n) => {
14
+ i(n), O?.(n);
15
+ }, c = Q(async (n) => {
16
+ const s = n.trim();
17
+ if (s) {
18
+ h(!1), m(!0);
19
19
  try {
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]);
20
+ const t = await l(s);
21
+ if ((t.length > 0 ? typeof t[0] == "string" : !0) && f) {
22
+ const S = s.toLocaleLowerCase();
23
+ a([S, ...t]);
24
24
  } else
25
- y((t == null ? void 0 : t.length) === 0), a(t);
25
+ g(t?.length === 0), a(t);
26
26
  } catch (t) {
27
- (t == null ? void 0 : t.name) !== j && g(!0);
27
+ t?.name !== j && h(!0);
28
28
  } finally {
29
- h(!1);
29
+ m(!1);
30
30
  }
31
31
  }
32
- }, [f, m]), L = () => {
33
- l(e);
32
+ }, [l, f]), V = () => {
33
+ c(e);
34
34
  };
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]);
35
+ T(() => (e.trim().length ? c(e) : (a([]), g(!1)), () => i.cancel()), [i, c, e]);
36
+ const L = y(() => {
37
+ const n = e.trim().length > 0;
38
+ return r?.length > 0 && !n ? r : d;
39
+ }, [e, r, d]);
40
40
  return /* @__PURE__ */ W(D, {
41
- ...O,
42
- isEmpty: A,
43
- isError: x,
41
+ ...C,
42
+ isEmpty: E,
43
+ isError: I,
44
44
  isLoading: p,
45
45
  loading: p,
46
- onInputValueChange: I,
47
- onTryAgain: L,
48
- options: S
46
+ onInputValueChange: A,
47
+ onTryAgain: V,
48
+ options: L
49
49
  });
50
50
  };
51
51
  export {