@box/combobox-with-api 0.25.0 → 0.26.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,9 +1,9 @@
1
1
  import { Text as g, LoadingIndicator as G } from "@box/blueprint-web";
2
2
  import { Tree as H } from "@box/tree";
3
- import { useReducer as J, useState as V, useMemo as K, useCallback as R, useEffect as P } from "react";
4
- import { RootTreeNode as d, getServiceNode as x } from "../esm/lib/components/combobox-with-api-tree-view/tree-utils.js";
3
+ import { useReducer as J, useState as V, useMemo as K, useCallback as E, useEffect as W } from "react";
4
+ import { RootTreeNode as i, getServiceNode as C } from "../esm/lib/components/combobox-with-api-tree-view/tree-utils.js";
5
5
  import { jsxs as N, jsx as u } from "react/jsx-runtime";
6
- import '../styles/dynamic-loading-tree.css';const Q = "_container_sdpm3_1", X = "_disabled_sdpm3_12", Y = "_label_sdpm3_15", Z = "_hiddenLabel_sdpm3_27", F = "_comboboxContainer_sdpm3_30", ee = "_withComboboxButtons_sdpm3_46", te = "_error_sdpm3_54", ae = "_textInputWrapper_sdpm3_62", se = "_textInput_sdpm3_62", ne = "_errorIcon_sdpm3_84", le = "_comboboxButtons_sdpm3_87", oe = "_withChips_sdpm3_94", re = "_inlineError_sdpm3_104", ie = "_popover_sdpm3_108", de = "_option_sdpm3_134", ce = "_indicator_sdpm3_157", me = "_indicatorIcon_sdpm3_166", pe = "_optionWithIndicator_sdpm3_169", _e = "_loadingIndicator_sdpm3_172", ue = "_noResultOption_sdpm3_175", he = "_treeContainer_sdpm3_181", f = {
6
+ import '../styles/dynamic-loading-tree.css';const Q = "_container_bezt1_1", X = "_disabled_bezt1_12", Y = "_label_bezt1_15", Z = "_hiddenLabel_bezt1_27", F = "_comboboxContainer_bezt1_30", ee = "_withComboboxButtons_bezt1_46", te = "_error_bezt1_54", ae = "_textInputWrapper_bezt1_62", ne = "_textInput_bezt1_62", le = "_errorIcon_bezt1_84", se = "_comboboxButtons_bezt1_87", oe = "_withChips_bezt1_94", re = "_inlineError_bezt1_104", ie = "_popover_bezt1_108", de = "_option_bezt1_134", ce = "_indicator_bezt1_157", pe = "_indicatorIcon_bezt1_166", me = "_optionWithIndicator_bezt1_169", _e = "_loadingIndicator_bezt1_172", ue = "_noResultOption_bezt1_175", x = {
7
7
  container: Q,
8
8
  disabled: X,
9
9
  label: Y,
@@ -12,27 +12,26 @@ import '../styles/dynamic-loading-tree.css';const Q = "_container_sdpm3_1", X =
12
12
  withComboboxButtons: ee,
13
13
  error: te,
14
14
  textInputWrapper: ae,
15
- textInput: se,
16
- errorIcon: ne,
17
- comboboxButtons: le,
15
+ textInput: ne,
16
+ errorIcon: le,
17
+ comboboxButtons: se,
18
18
  withChips: oe,
19
19
  inlineError: re,
20
20
  popover: ie,
21
21
  option: de,
22
22
  indicator: ce,
23
- indicatorIcon: me,
24
- optionWithIndicator: pe,
23
+ indicatorIcon: pe,
24
+ optionWithIndicator: me,
25
25
  loadingIndicator: _e,
26
- noResultOption: ue,
27
- treeContainer: he
26
+ noResultOption: ue
28
27
  };
29
28
  let n = /* @__PURE__ */ function(a) {
30
29
  return a.LOAD_DATA = "LOAD_DATA", a.LOAD_ERROR = "LOAD_DATA_ERROR", a.LOAD_SUCCESS = "LOAD_DATA_SUCCESS", a.LOAD_MORE = "LOAD_DATA_SUCCESS", a.RESET = "RESET", a;
31
30
  }({});
32
- const ye = ({
31
+ const be = ({
33
32
  levelName: a,
34
- parentDisplayValue: b,
35
- displayValue: l
33
+ parentDisplayValue: y,
34
+ displayValue: o
36
35
  }) => /* @__PURE__ */ N("div", {
37
36
  style: {
38
37
  display: "flex",
@@ -51,119 +50,101 @@ const ye = ({
51
50
  }), /* @__PURE__ */ u(g, {
52
51
  as: "span",
53
52
  variant: "label",
54
- children: `/${b}`
53
+ children: `/${y}`
55
54
  })]
56
55
  }), /* @__PURE__ */ u(g, {
57
56
  as: "span",
58
57
  variant: "bodyDefault",
59
- children: l
58
+ children: o
60
59
  })]
61
- }), Se = (a, b) => {
60
+ }), ye = (a, y) => {
62
61
  const {
63
- id: l,
62
+ id: o,
64
63
  items: m,
65
- marker: y
66
- } = b.payload;
67
- switch (b.type) {
64
+ marker: b
65
+ } = y.payload;
66
+ switch (y.type) {
68
67
  case n.LOAD_DATA:
69
68
  return {
70
69
  ...a,
71
- [l]: {
72
- ...a[l],
70
+ [o]: {
71
+ ...a[o],
73
72
  status: "loading"
74
73
  }
75
74
  };
76
75
  case n.LOAD_ERROR:
77
76
  return {
78
77
  ...a,
79
- [l]: {
80
- ...a[l],
81
- marker: y,
78
+ [o]: {
79
+ ...a[o],
80
+ marker: b,
82
81
  status: "error"
83
82
  }
84
83
  };
85
84
  case n.LOAD_SUCCESS: {
86
85
  const {
87
- itemsWithParent: S,
88
- itemsIds: v
89
- } = m.reduce((h, o) => ({
86
+ itemsWithParent: D,
87
+ itemsIds: f
88
+ } = m.reduce((O, d) => ({
90
89
  itemsWithParent: {
91
- ...h.itemsWithParent,
92
- [o.id]: {
93
- ...o,
94
- parent: l,
90
+ ...O.itemsWithParent,
91
+ [d.id]: {
92
+ ...d,
93
+ parent: o,
95
94
  children: []
96
95
  }
97
96
  },
98
- itemsIds: [...h.itemsIds, o.id]
97
+ itemsIds: [...O.itemsIds, d.id]
99
98
  }), {
100
99
  itemsWithParent: {},
101
100
  itemsIds: []
102
101
  });
103
102
  return {
104
103
  ...a,
105
- [l]: {
106
- ...a[l],
104
+ [o]: {
105
+ ...a[o],
107
106
  status: "success",
108
- marker: y,
109
- children: [...a[l].children || [], ...v]
107
+ marker: b,
108
+ children: [...a[o].children || [], ...f]
110
109
  },
111
- ...S
110
+ ...D
112
111
  };
113
112
  }
114
- case n.RESET: {
115
- const {
116
- itemsWithParent: S,
117
- itemsIds: v
118
- } = m.reduce((h, o) => ({
119
- itemsWithParent: {
120
- ...h.itemsWithParent,
121
- [o.id]: {
122
- ...o,
123
- parent: l,
124
- children: []
125
- }
126
- },
127
- itemsIds: [...h.itemsIds, o.id]
128
- }), {
129
- itemsWithParent: {},
130
- itemsIds: []
131
- });
113
+ case n.RESET:
132
114
  return {
133
- [l]: {
134
- ...a[l],
115
+ ...a,
116
+ [o]: {
117
+ ...a[o],
135
118
  status: "success",
136
- marker: y,
137
- children: [...v]
138
- },
139
- ...S
119
+ marker: b,
120
+ children: []
121
+ }
140
122
  };
141
- }
142
123
  default:
143
124
  return a;
144
125
  }
145
- }, Re = ({
126
+ }, Ee = ({
146
127
  ariaLabel: a,
147
- onSelect: b,
148
- selectedNodes: l,
128
+ onSelect: y,
129
+ selectedNodes: o,
149
130
  defaultFetcher: m,
150
- levels: y,
151
- selectableLevels: S,
152
- multiselect: v,
153
- open: h,
154
- searchInput: o,
131
+ levels: b,
132
+ selectableLevels: D,
133
+ multiselect: f,
134
+ open: O,
135
+ searchInput: d,
155
136
  noResultMessage: B,
156
137
  loadingAriaLabel: U
157
138
  }) => {
158
- const [D, r] = J(Se, {
159
- [d.id]: d
160
- }), [E, M] = V({
139
+ const [h, s] = J(ye, {
140
+ [i.id]: i
141
+ }), [R, P] = V({
161
142
  nodes: [],
162
143
  selectedIds: []
163
- }), [T, A] = V(!1), I = K(() => Math.max(...S), [S]), k = R((e = D) => {
164
- const i = [];
144
+ }), [T, A] = V(!1), v = K(() => Math.max(...D), [D]), z = E((e = h) => {
145
+ const r = [];
165
146
  return [...Object.values(e).map((t) => {
166
- const _ = [...t.children], s = {
147
+ const _ = [...t.children], l = {
167
148
  ...t,
168
149
  children: _,
169
150
  metadata: {
@@ -173,21 +154,21 @@ const ye = ({
173
154
  }
174
155
  };
175
156
  let c;
176
- return t.children.length && t.status === "loading" && (c = x(s.id, s.metadata.displayValue, "loading")), t.status === "error" && (c = x(s.id, s.metadata.displayValue, "reload")), t.status === "success" && t.marker && (c = x(s.id, s.metadata.displayValue, "loadMore")), c && (i.push(c), s.children.push(c.id)), s;
177
- }), ...i];
178
- }, [D]), C = R((e) => {
157
+ return t.children.length && t.status === "loading" && (c = C(l.id, l.metadata.displayValue, "loading")), t.status === "error" && (c = C(l.id, l.metadata.displayValue, "reload")), t.status === "success" && t.marker && (c = C(l.id, l.metadata.displayValue, "loadMore")), c && (r.push(c), l.children.push(c.id)), l;
158
+ }), ...r];
159
+ }, [h]), I = E((e) => {
179
160
  var _;
180
- const i = (_ = e.ancestors) == null ? void 0 : _.find((s) => s.level === e.level - 1), p = y.find((s) => s.level === e.level);
181
- return e.level === 1 || o === "" ? e.displayValue : /* @__PURE__ */ u(ye, {
161
+ const r = (_ = e.ancestors) == null ? void 0 : _.find((l) => l.level === e.level - 1), p = b.find((l) => l.level === e.level);
162
+ return e.level === 1 || d === "" ? e.displayValue : /* @__PURE__ */ u(be, {
182
163
  displayValue: e.displayValue,
183
164
  levelName: p.displayName,
184
- parentDisplayValue: i.displayName
165
+ parentDisplayValue: r.displayName
185
166
  });
186
- }, [y, o]), O = R((e) => ({
167
+ }, [b, d]), S = E((e) => ({
187
168
  id: e.value,
188
- name: C(e),
189
- parent: d.id,
190
- isBranch: e.level !== I,
169
+ name: I(e),
170
+ parent: i.id,
171
+ isBranch: e.level !== v,
191
172
  children: [],
192
173
  metadata: {
193
174
  variant: "content",
@@ -197,37 +178,37 @@ const ye = ({
197
178
  marker: e.marker,
198
179
  ancestors: e.ancestors
199
180
  }
200
- }), [C, I]);
201
- P(() => {
202
- M({
203
- nodes: k(D),
204
- selectedIds: l
181
+ }), [I, v]);
182
+ W(() => {
183
+ P({
184
+ nodes: z(h),
185
+ selectedIds: o
205
186
  });
206
- }, [k, l, D]), P(() => {
207
- if (!h)
187
+ }, [z, o, h]), W(() => {
188
+ if (!O)
208
189
  return;
209
190
  const {
210
191
  signal: e
211
192
  } = new AbortController();
212
- A(!0), o ? (r({
193
+ A(!0), d ? (s({
213
194
  type: n.RESET,
214
195
  payload: {
215
- id: d.id,
196
+ id: i.id,
216
197
  items: []
217
198
  }
218
199
  }), m({
219
200
  signal: e,
220
201
  marker: null,
221
- searchInput: o,
202
+ searchInput: d,
222
203
  level: null,
223
204
  onlySelectableOptions: !1,
224
205
  ancestorId: null
225
- }).then((i) => {
226
- const p = i.options.map((t) => ({
206
+ }).then((r) => {
207
+ const p = r.options.map((t) => ({
227
208
  id: t.value,
228
- name: C(t),
229
- parent: d.id,
230
- isBranch: t.level < I,
209
+ name: I(t),
210
+ parent: i.id,
211
+ isBranch: t.level < v,
231
212
  children: [],
232
213
  metadata: {
233
214
  variant: "content",
@@ -237,37 +218,37 @@ const ye = ({
237
218
  ancestors: t.ancestors
238
219
  }
239
220
  }));
240
- r({
221
+ s({
241
222
  type: n.RESET,
242
223
  payload: {
243
- id: d.id,
224
+ id: i.id,
244
225
  items: []
245
226
  }
246
- }), r({
227
+ }), s({
247
228
  type: n.LOAD_SUCCESS,
248
229
  payload: {
249
- id: d.id,
230
+ id: i.id,
250
231
  items: p,
251
- marker: i.marker
232
+ marker: r.marker
252
233
  }
253
234
  }), A(!1);
254
235
  }).catch(() => {
255
- r({
236
+ s({
256
237
  type: n.LOAD_ERROR,
257
238
  payload: {
258
- id: d.id
239
+ id: i.id
259
240
  }
260
241
  }), A(!1);
261
- })) : (r({
242
+ })) : (s({
262
243
  type: n.RESET,
263
244
  payload: {
264
- id: d.id,
245
+ id: i.id,
265
246
  items: []
266
247
  }
267
- }), r({
248
+ }), s({
268
249
  type: n.LOAD_DATA,
269
250
  payload: {
270
- id: d.id
251
+ id: i.id
271
252
  }
272
253
  }), m({
273
254
  signal: e,
@@ -276,101 +257,109 @@ const ye = ({
276
257
  level: 1,
277
258
  onlySelectableOptions: !1,
278
259
  ancestorId: null
279
- }).then((i) => {
280
- const p = i.options.map(O);
281
- r({
260
+ }).then((r) => {
261
+ const p = r.options.map(S);
262
+ s({
282
263
  type: n.RESET,
283
264
  payload: {
284
- id: d.id,
265
+ id: i.id,
285
266
  items: []
286
267
  }
287
- }), r({
268
+ }), s({
288
269
  type: n.LOAD_SUCCESS,
289
270
  payload: {
290
- id: d.id,
271
+ id: i.id,
291
272
  items: p,
292
- marker: i.marker
273
+ marker: r.marker
293
274
  }
294
275
  }), A(!1);
295
276
  }).catch(() => {
296
- r({
277
+ s({
297
278
  type: n.LOAD_ERROR,
298
279
  payload: {
299
- id: d.id
280
+ id: i.id
300
281
  }
301
282
  }), A(!1);
302
283
  }));
303
- }, [m, O, h, o, y, I, C]);
304
- const j = R((e) => {
284
+ }, [m, S, O, d, b, v, I]);
285
+ const M = E((e) => {
305
286
  const {
306
- isExpanded: i,
287
+ isExpanded: r,
307
288
  isDisabled: p,
308
289
  element: t
309
290
  } = e;
310
- if (!i || p)
291
+ if (!r || p) {
292
+ s({
293
+ type: n.RESET,
294
+ payload: {
295
+ id: t.id,
296
+ items: []
297
+ }
298
+ });
311
299
  return;
300
+ }
312
301
  const {
313
302
  level: _
314
303
  } = t.metadata, {
315
- id: s,
304
+ id: l,
316
305
  marker: c
317
306
  } = t, {
318
307
  signal: L
319
308
  } = new AbortController();
320
- r({
309
+ s({
321
310
  type: n.LOAD_DATA,
322
311
  payload: {
323
- id: s
312
+ id: l
324
313
  }
325
314
  }), m({
326
315
  signal: L,
327
316
  marker: c,
328
317
  searchInput: "",
329
318
  level: _ + 1,
330
- ancestorId: s,
319
+ ancestorId: l,
331
320
  onlySelectableOptions: !1
332
- }).then((W) => {
333
- const q = W.options.map((w) => (t.children.push(w.value), O(w)));
334
- r({
321
+ }).then((k) => {
322
+ const q = k.options.map((w) => (t.children.push(w.value), S(w)));
323
+ s({
335
324
  type: n.LOAD_SUCCESS,
336
325
  payload: {
337
- id: s,
326
+ id: l,
338
327
  items: q,
339
- marker: W.marker
328
+ marker: k.marker
340
329
  }
341
330
  });
342
331
  }).catch(() => {
343
- r({
332
+ s({
344
333
  type: n.LOAD_ERROR,
345
334
  payload: {
346
- id: s
335
+ id: l
347
336
  }
348
337
  });
349
338
  });
350
- }, [m, O]), $ = R((e) => {
351
- const i = D[e], {
339
+ }, [m, S]), j = E((e) => {
340
+ const r = h[e], {
352
341
  level: p
353
- } = i.metadata, {
342
+ } = r.metadata, {
354
343
  id: t,
355
344
  marker: _
356
- } = i, {
357
- signal: s
345
+ } = r, {
346
+ signal: l
358
347
  } = new AbortController();
359
- r({
348
+ s({
360
349
  type: n.LOAD_DATA,
361
350
  payload: {
362
351
  id: t
363
352
  }
364
353
  }), m({
365
- signal: s,
354
+ signal: l,
366
355
  marker: _,
367
- searchInput: o,
368
- level: o === "" ? p + 1 : null,
369
- ancestorId: t !== d.id ? t.toString() : null,
356
+ searchInput: d,
357
+ level: d === "" ? p + 1 : null,
358
+ ancestorId: t !== i.id ? t.toString() : null,
370
359
  onlySelectableOptions: !1
371
360
  }).then((c) => {
372
- const L = c.options.map(O);
373
- r({
361
+ const L = c.options.map(S);
362
+ s({
374
363
  type: n.LOAD_SUCCESS,
375
364
  payload: {
376
365
  id: t,
@@ -379,7 +368,7 @@ const ye = ({
379
368
  }
380
369
  });
381
370
  }).catch(() => {
382
- r({
371
+ s({
383
372
  type: n.LOAD_ERROR,
384
373
  payload: {
385
374
  id: t,
@@ -387,37 +376,34 @@ const ye = ({
387
376
  }
388
377
  });
389
378
  });
390
- }, [m, O, o, D]), z = E.nodes.length === 0 || E.nodes[0].children.length === 0 && E.nodes[0].id === d.id;
379
+ }, [m, S, d, h]), $ = R.nodes.length === 0 || R.nodes[0].children.length === 0 && R.nodes[0].id === i.id;
391
380
  return /* @__PURE__ */ N("div", {
392
381
  children: [T && /* @__PURE__ */ u("div", {
393
- className: f.noResultOption,
382
+ className: x.noResultOption,
394
383
  children: /* @__PURE__ */ u(G, {
395
384
  "aria-label": U,
396
- className: f.loadingIndicator
385
+ className: x.loadingIndicator
397
386
  })
398
- }), z && !T ? /* @__PURE__ */ u("div", {
399
- className: f.noResultOption,
387
+ }), $ && !T ? /* @__PURE__ */ u("div", {
388
+ className: x.noResultOption,
400
389
  children: B
401
- }) : /* @__PURE__ */ u("div", {
402
- className: f.treeContainer,
403
- children: /* @__PURE__ */ u(H, {
404
- "aria-label": a,
405
- data: E.nodes,
406
- multiSelect: v,
407
- onExpand: j,
408
- onLoadData: $,
409
- onNodeSelect: (e) => {
410
- S.includes(e.element.metadata.level) ? b(e) : (e.isSelected = !1, e.treeState.selectedIds.delete(e.element.id));
411
- },
412
- size: "large",
413
- togglableSelect: !0,
414
- withIcons: !1
415
- })
390
+ }) : /* @__PURE__ */ u(H, {
391
+ "aria-label": a,
392
+ data: R.nodes,
393
+ multiSelect: f,
394
+ onExpand: M,
395
+ onLoadData: j,
396
+ onNodeSelect: (e) => {
397
+ D.includes(e.element.metadata.level) ? y(e) : (e.isSelected = !1, e.treeState.selectedIds.delete(e.element.id));
398
+ },
399
+ size: "large",
400
+ togglableSelect: !0,
401
+ withIcons: !1
416
402
  })]
417
403
  });
418
404
  };
419
405
  export {
420
- Re as D,
421
- ye as S,
422
- f as s
406
+ Ee as D,
407
+ be as S,
408
+ x as s
423
409
  };