@box/combobox-with-api 0.25.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.
- package/LICENSE +379 -0
- package/chunks/dynamic-loading-tree.js +423 -0
- package/esm/index.js +8 -0
- package/esm/lib/components/combobox-with-api/combobox-with-api-container.js +47 -0
- package/esm/lib/components/combobox-with-api/combobox-with-api-error.js +26 -0
- package/esm/lib/components/combobox-with-api/combobox-with-api.js +37 -0
- package/esm/lib/components/combobox-with-api/messages.js +10 -0
- package/esm/lib/components/combobox-with-api-pagination/combobox-with-api-pagination.js +207 -0
- package/esm/lib/components/combobox-with-api-pagination/index.js +4 -0
- package/esm/lib/components/combobox-with-api-pagination/messages.js +34 -0
- package/esm/lib/components/combobox-with-api-pagination/request.js +6 -0
- package/esm/lib/components/combobox-with-api-pagination/use-async-list.js +137 -0
- package/esm/lib/components/combobox-with-api-pagination/utils/is-abort-error.js +13 -0
- package/esm/lib/components/combobox-with-api-pagination/utils/use-controllable-state.js +40 -0
- package/esm/lib/components/combobox-with-api-pagination/utils/use-intersection-observer.js +87 -0
- package/esm/lib/components/combobox-with-api-tree-view/combobox-with-api-tree-view.js +125 -0
- package/esm/lib/components/combobox-with-api-tree-view/dynamic-loading-tree.js +10 -0
- package/esm/lib/components/combobox-with-api-tree-view/index.js +4 -0
- package/esm/lib/components/combobox-with-api-tree-view/tree-utils.js +26 -0
- package/i18n/bn-IN.js +10 -0
- package/i18n/bn-IN.properties +16 -0
- package/i18n/da-DK.js +10 -0
- package/i18n/da-DK.properties +16 -0
- package/i18n/de-DE.js +10 -0
- package/i18n/de-DE.properties +16 -0
- package/i18n/en-AU.js +10 -0
- package/i18n/en-AU.properties +16 -0
- package/i18n/en-CA.js +10 -0
- package/i18n/en-CA.properties +16 -0
- package/i18n/en-GB.js +10 -0
- package/i18n/en-GB.properties +16 -0
- package/i18n/en-US.js +10 -0
- package/i18n/en-US.properties +16 -0
- package/i18n/en-x-pseudo.js +10 -0
- package/i18n/en-x-pseudo.properties +16 -0
- package/i18n/es-419.js +10 -0
- package/i18n/es-419.properties +16 -0
- package/i18n/es-ES.js +10 -0
- package/i18n/es-ES.properties +16 -0
- package/i18n/fi-FI.js +10 -0
- package/i18n/fi-FI.properties +16 -0
- package/i18n/fr-CA.js +10 -0
- package/i18n/fr-CA.properties +16 -0
- package/i18n/fr-FR.js +10 -0
- package/i18n/fr-FR.properties +16 -0
- package/i18n/hi-IN.js +10 -0
- package/i18n/hi-IN.properties +16 -0
- package/i18n/it-IT.js +10 -0
- package/i18n/it-IT.properties +16 -0
- package/i18n/ja-JP.js +10 -0
- package/i18n/ja-JP.properties +16 -0
- package/i18n/json/src/lib/components/combobox-with-api/messages.json +1 -0
- package/i18n/json/src/lib/components/combobox-with-api-pagination/messages.json +1 -0
- package/i18n/ko-KR.js +10 -0
- package/i18n/ko-KR.properties +16 -0
- package/i18n/nb-NO.js +10 -0
- package/i18n/nb-NO.properties +16 -0
- package/i18n/nl-NL.js +10 -0
- package/i18n/nl-NL.properties +16 -0
- package/i18n/pl-PL.js +10 -0
- package/i18n/pl-PL.properties +16 -0
- package/i18n/pt-BR.js +10 -0
- package/i18n/pt-BR.properties +16 -0
- package/i18n/ru-RU.js +10 -0
- package/i18n/ru-RU.properties +16 -0
- package/i18n/sv-SE.js +10 -0
- package/i18n/sv-SE.properties +16 -0
- package/i18n/tr-TR.js +10 -0
- package/i18n/tr-TR.properties +16 -0
- package/i18n/zh-CN.js +10 -0
- package/i18n/zh-CN.properties +16 -0
- package/i18n/zh-TW.js +10 -0
- package/i18n/zh-TW.properties +16 -0
- package/package.json +55 -0
- package/styles/combobox-with-api-error.css +1 -0
- package/styles/combobox-with-api-pagination.css +1 -0
- package/styles/dynamic-loading-tree.css +1 -0
- package/types/index.d.ts +4 -0
- package/types/lib/components/combobox-with-api/combobox-with-api-container.d.ts +3 -0
- package/types/lib/components/combobox-with-api/combobox-with-api-error.d.ts +3 -0
- package/types/lib/components/combobox-with-api/combobox-with-api.d.ts +3 -0
- package/types/lib/components/combobox-with-api/messages.d.ts +8 -0
- package/types/lib/components/combobox-with-api/stories/shared.d.ts +8 -0
- package/types/lib/components/combobox-with-api/types.d.ts +39 -0
- package/types/lib/components/combobox-with-api-pagination/combobox-with-api-pagination.d.ts +17 -0
- package/types/lib/components/combobox-with-api-pagination/index.d.ts +2 -0
- package/types/lib/components/combobox-with-api-pagination/messages.d.ts +38 -0
- package/types/lib/components/combobox-with-api-pagination/request.d.ts +7 -0
- package/types/lib/components/combobox-with-api-pagination/stories/shared.d.ts +38 -0
- package/types/lib/components/combobox-with-api-pagination/types.d.ts +49 -0
- package/types/lib/components/combobox-with-api-pagination/use-async-list.d.ts +63 -0
- package/types/lib/components/combobox-with-api-pagination/utils/is-abort-error.d.ts +1 -0
- package/types/lib/components/combobox-with-api-pagination/utils/use-controllable-state.d.ts +8 -0
- package/types/lib/components/combobox-with-api-pagination/utils/use-intersection-observer.d.ts +28 -0
- package/types/lib/components/combobox-with-api-tree-view/combobox-with-api-tree-view.d.ts +21 -0
- package/types/lib/components/combobox-with-api-tree-view/dynamic-loading-tree.d.ts +23 -0
- package/types/lib/components/combobox-with-api-tree-view/index.d.ts +3 -0
- package/types/lib/components/combobox-with-api-tree-view/stories/mock-api-response.d.ts +11 -0
- package/types/lib/components/combobox-with-api-tree-view/stories/shared.d.ts +26 -0
- package/types/lib/components/combobox-with-api-tree-view/tree-utils.d.ts +22 -0
- package/types/lib/components/combobox-with-api-tree-view/types.d.ts +60 -0
|
@@ -0,0 +1,423 @@
|
|
|
1
|
+
import { Text as g, LoadingIndicator as G } from "@box/blueprint-web";
|
|
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";
|
|
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 = {
|
|
7
|
+
container: Q,
|
|
8
|
+
disabled: X,
|
|
9
|
+
label: Y,
|
|
10
|
+
hiddenLabel: Z,
|
|
11
|
+
comboboxContainer: F,
|
|
12
|
+
withComboboxButtons: ee,
|
|
13
|
+
error: te,
|
|
14
|
+
textInputWrapper: ae,
|
|
15
|
+
textInput: se,
|
|
16
|
+
errorIcon: ne,
|
|
17
|
+
comboboxButtons: le,
|
|
18
|
+
withChips: oe,
|
|
19
|
+
inlineError: re,
|
|
20
|
+
popover: ie,
|
|
21
|
+
option: de,
|
|
22
|
+
indicator: ce,
|
|
23
|
+
indicatorIcon: me,
|
|
24
|
+
optionWithIndicator: pe,
|
|
25
|
+
loadingIndicator: _e,
|
|
26
|
+
noResultOption: ue,
|
|
27
|
+
treeContainer: he
|
|
28
|
+
};
|
|
29
|
+
let n = /* @__PURE__ */ function(a) {
|
|
30
|
+
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
|
+
}({});
|
|
32
|
+
const ye = ({
|
|
33
|
+
levelName: a,
|
|
34
|
+
parentDisplayValue: b,
|
|
35
|
+
displayValue: l
|
|
36
|
+
}) => /* @__PURE__ */ N("div", {
|
|
37
|
+
style: {
|
|
38
|
+
display: "flex",
|
|
39
|
+
alignItems: "flex-start",
|
|
40
|
+
flexDirection: "column"
|
|
41
|
+
},
|
|
42
|
+
children: [/* @__PURE__ */ N("div", {
|
|
43
|
+
style: {
|
|
44
|
+
display: "flex",
|
|
45
|
+
alignItems: "flex-start"
|
|
46
|
+
},
|
|
47
|
+
children: [/* @__PURE__ */ u(g, {
|
|
48
|
+
as: "span",
|
|
49
|
+
variant: "labelBold",
|
|
50
|
+
children: `${a}`
|
|
51
|
+
}), /* @__PURE__ */ u(g, {
|
|
52
|
+
as: "span",
|
|
53
|
+
variant: "label",
|
|
54
|
+
children: `/${b}`
|
|
55
|
+
})]
|
|
56
|
+
}), /* @__PURE__ */ u(g, {
|
|
57
|
+
as: "span",
|
|
58
|
+
variant: "bodyDefault",
|
|
59
|
+
children: l
|
|
60
|
+
})]
|
|
61
|
+
}), Se = (a, b) => {
|
|
62
|
+
const {
|
|
63
|
+
id: l,
|
|
64
|
+
items: m,
|
|
65
|
+
marker: y
|
|
66
|
+
} = b.payload;
|
|
67
|
+
switch (b.type) {
|
|
68
|
+
case n.LOAD_DATA:
|
|
69
|
+
return {
|
|
70
|
+
...a,
|
|
71
|
+
[l]: {
|
|
72
|
+
...a[l],
|
|
73
|
+
status: "loading"
|
|
74
|
+
}
|
|
75
|
+
};
|
|
76
|
+
case n.LOAD_ERROR:
|
|
77
|
+
return {
|
|
78
|
+
...a,
|
|
79
|
+
[l]: {
|
|
80
|
+
...a[l],
|
|
81
|
+
marker: y,
|
|
82
|
+
status: "error"
|
|
83
|
+
}
|
|
84
|
+
};
|
|
85
|
+
case n.LOAD_SUCCESS: {
|
|
86
|
+
const {
|
|
87
|
+
itemsWithParent: S,
|
|
88
|
+
itemsIds: v
|
|
89
|
+
} = m.reduce((h, o) => ({
|
|
90
|
+
itemsWithParent: {
|
|
91
|
+
...h.itemsWithParent,
|
|
92
|
+
[o.id]: {
|
|
93
|
+
...o,
|
|
94
|
+
parent: l,
|
|
95
|
+
children: []
|
|
96
|
+
}
|
|
97
|
+
},
|
|
98
|
+
itemsIds: [...h.itemsIds, o.id]
|
|
99
|
+
}), {
|
|
100
|
+
itemsWithParent: {},
|
|
101
|
+
itemsIds: []
|
|
102
|
+
});
|
|
103
|
+
return {
|
|
104
|
+
...a,
|
|
105
|
+
[l]: {
|
|
106
|
+
...a[l],
|
|
107
|
+
status: "success",
|
|
108
|
+
marker: y,
|
|
109
|
+
children: [...a[l].children || [], ...v]
|
|
110
|
+
},
|
|
111
|
+
...S
|
|
112
|
+
};
|
|
113
|
+
}
|
|
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
|
+
});
|
|
132
|
+
return {
|
|
133
|
+
[l]: {
|
|
134
|
+
...a[l],
|
|
135
|
+
status: "success",
|
|
136
|
+
marker: y,
|
|
137
|
+
children: [...v]
|
|
138
|
+
},
|
|
139
|
+
...S
|
|
140
|
+
};
|
|
141
|
+
}
|
|
142
|
+
default:
|
|
143
|
+
return a;
|
|
144
|
+
}
|
|
145
|
+
}, Re = ({
|
|
146
|
+
ariaLabel: a,
|
|
147
|
+
onSelect: b,
|
|
148
|
+
selectedNodes: l,
|
|
149
|
+
defaultFetcher: m,
|
|
150
|
+
levels: y,
|
|
151
|
+
selectableLevels: S,
|
|
152
|
+
multiselect: v,
|
|
153
|
+
open: h,
|
|
154
|
+
searchInput: o,
|
|
155
|
+
noResultMessage: B,
|
|
156
|
+
loadingAriaLabel: U
|
|
157
|
+
}) => {
|
|
158
|
+
const [D, r] = J(Se, {
|
|
159
|
+
[d.id]: d
|
|
160
|
+
}), [E, M] = V({
|
|
161
|
+
nodes: [],
|
|
162
|
+
selectedIds: []
|
|
163
|
+
}), [T, A] = V(!1), I = K(() => Math.max(...S), [S]), k = R((e = D) => {
|
|
164
|
+
const i = [];
|
|
165
|
+
return [...Object.values(e).map((t) => {
|
|
166
|
+
const _ = [...t.children], s = {
|
|
167
|
+
...t,
|
|
168
|
+
children: _,
|
|
169
|
+
metadata: {
|
|
170
|
+
...t.metadata,
|
|
171
|
+
variant: "content",
|
|
172
|
+
isLoading: t.status === "loading" && !t.children.length
|
|
173
|
+
}
|
|
174
|
+
};
|
|
175
|
+
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) => {
|
|
179
|
+
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, {
|
|
182
|
+
displayValue: e.displayValue,
|
|
183
|
+
levelName: p.displayName,
|
|
184
|
+
parentDisplayValue: i.displayName
|
|
185
|
+
});
|
|
186
|
+
}, [y, o]), O = R((e) => ({
|
|
187
|
+
id: e.value,
|
|
188
|
+
name: C(e),
|
|
189
|
+
parent: d.id,
|
|
190
|
+
isBranch: e.level !== I,
|
|
191
|
+
children: [],
|
|
192
|
+
metadata: {
|
|
193
|
+
variant: "content",
|
|
194
|
+
level: e.level,
|
|
195
|
+
selectable: e.selectable,
|
|
196
|
+
displayValue: e.displayValue,
|
|
197
|
+
marker: e.marker,
|
|
198
|
+
ancestors: e.ancestors
|
|
199
|
+
}
|
|
200
|
+
}), [C, I]);
|
|
201
|
+
P(() => {
|
|
202
|
+
M({
|
|
203
|
+
nodes: k(D),
|
|
204
|
+
selectedIds: l
|
|
205
|
+
});
|
|
206
|
+
}, [k, l, D]), P(() => {
|
|
207
|
+
if (!h)
|
|
208
|
+
return;
|
|
209
|
+
const {
|
|
210
|
+
signal: e
|
|
211
|
+
} = new AbortController();
|
|
212
|
+
A(!0), o ? (r({
|
|
213
|
+
type: n.RESET,
|
|
214
|
+
payload: {
|
|
215
|
+
id: d.id,
|
|
216
|
+
items: []
|
|
217
|
+
}
|
|
218
|
+
}), m({
|
|
219
|
+
signal: e,
|
|
220
|
+
marker: null,
|
|
221
|
+
searchInput: o,
|
|
222
|
+
level: null,
|
|
223
|
+
onlySelectableOptions: !1,
|
|
224
|
+
ancestorId: null
|
|
225
|
+
}).then((i) => {
|
|
226
|
+
const p = i.options.map((t) => ({
|
|
227
|
+
id: t.value,
|
|
228
|
+
name: C(t),
|
|
229
|
+
parent: d.id,
|
|
230
|
+
isBranch: t.level < I,
|
|
231
|
+
children: [],
|
|
232
|
+
metadata: {
|
|
233
|
+
variant: "content",
|
|
234
|
+
level: t.level,
|
|
235
|
+
selectable: t.selectable,
|
|
236
|
+
displayValue: t.displayValue,
|
|
237
|
+
ancestors: t.ancestors
|
|
238
|
+
}
|
|
239
|
+
}));
|
|
240
|
+
r({
|
|
241
|
+
type: n.RESET,
|
|
242
|
+
payload: {
|
|
243
|
+
id: d.id,
|
|
244
|
+
items: []
|
|
245
|
+
}
|
|
246
|
+
}), r({
|
|
247
|
+
type: n.LOAD_SUCCESS,
|
|
248
|
+
payload: {
|
|
249
|
+
id: d.id,
|
|
250
|
+
items: p,
|
|
251
|
+
marker: i.marker
|
|
252
|
+
}
|
|
253
|
+
}), A(!1);
|
|
254
|
+
}).catch(() => {
|
|
255
|
+
r({
|
|
256
|
+
type: n.LOAD_ERROR,
|
|
257
|
+
payload: {
|
|
258
|
+
id: d.id
|
|
259
|
+
}
|
|
260
|
+
}), A(!1);
|
|
261
|
+
})) : (r({
|
|
262
|
+
type: n.RESET,
|
|
263
|
+
payload: {
|
|
264
|
+
id: d.id,
|
|
265
|
+
items: []
|
|
266
|
+
}
|
|
267
|
+
}), r({
|
|
268
|
+
type: n.LOAD_DATA,
|
|
269
|
+
payload: {
|
|
270
|
+
id: d.id
|
|
271
|
+
}
|
|
272
|
+
}), m({
|
|
273
|
+
signal: e,
|
|
274
|
+
marker: null,
|
|
275
|
+
searchInput: "",
|
|
276
|
+
level: 1,
|
|
277
|
+
onlySelectableOptions: !1,
|
|
278
|
+
ancestorId: null
|
|
279
|
+
}).then((i) => {
|
|
280
|
+
const p = i.options.map(O);
|
|
281
|
+
r({
|
|
282
|
+
type: n.RESET,
|
|
283
|
+
payload: {
|
|
284
|
+
id: d.id,
|
|
285
|
+
items: []
|
|
286
|
+
}
|
|
287
|
+
}), r({
|
|
288
|
+
type: n.LOAD_SUCCESS,
|
|
289
|
+
payload: {
|
|
290
|
+
id: d.id,
|
|
291
|
+
items: p,
|
|
292
|
+
marker: i.marker
|
|
293
|
+
}
|
|
294
|
+
}), A(!1);
|
|
295
|
+
}).catch(() => {
|
|
296
|
+
r({
|
|
297
|
+
type: n.LOAD_ERROR,
|
|
298
|
+
payload: {
|
|
299
|
+
id: d.id
|
|
300
|
+
}
|
|
301
|
+
}), A(!1);
|
|
302
|
+
}));
|
|
303
|
+
}, [m, O, h, o, y, I, C]);
|
|
304
|
+
const j = R((e) => {
|
|
305
|
+
const {
|
|
306
|
+
isExpanded: i,
|
|
307
|
+
isDisabled: p,
|
|
308
|
+
element: t
|
|
309
|
+
} = e;
|
|
310
|
+
if (!i || p)
|
|
311
|
+
return;
|
|
312
|
+
const {
|
|
313
|
+
level: _
|
|
314
|
+
} = t.metadata, {
|
|
315
|
+
id: s,
|
|
316
|
+
marker: c
|
|
317
|
+
} = t, {
|
|
318
|
+
signal: L
|
|
319
|
+
} = new AbortController();
|
|
320
|
+
r({
|
|
321
|
+
type: n.LOAD_DATA,
|
|
322
|
+
payload: {
|
|
323
|
+
id: s
|
|
324
|
+
}
|
|
325
|
+
}), m({
|
|
326
|
+
signal: L,
|
|
327
|
+
marker: c,
|
|
328
|
+
searchInput: "",
|
|
329
|
+
level: _ + 1,
|
|
330
|
+
ancestorId: s,
|
|
331
|
+
onlySelectableOptions: !1
|
|
332
|
+
}).then((W) => {
|
|
333
|
+
const q = W.options.map((w) => (t.children.push(w.value), O(w)));
|
|
334
|
+
r({
|
|
335
|
+
type: n.LOAD_SUCCESS,
|
|
336
|
+
payload: {
|
|
337
|
+
id: s,
|
|
338
|
+
items: q,
|
|
339
|
+
marker: W.marker
|
|
340
|
+
}
|
|
341
|
+
});
|
|
342
|
+
}).catch(() => {
|
|
343
|
+
r({
|
|
344
|
+
type: n.LOAD_ERROR,
|
|
345
|
+
payload: {
|
|
346
|
+
id: s
|
|
347
|
+
}
|
|
348
|
+
});
|
|
349
|
+
});
|
|
350
|
+
}, [m, O]), $ = R((e) => {
|
|
351
|
+
const i = D[e], {
|
|
352
|
+
level: p
|
|
353
|
+
} = i.metadata, {
|
|
354
|
+
id: t,
|
|
355
|
+
marker: _
|
|
356
|
+
} = i, {
|
|
357
|
+
signal: s
|
|
358
|
+
} = new AbortController();
|
|
359
|
+
r({
|
|
360
|
+
type: n.LOAD_DATA,
|
|
361
|
+
payload: {
|
|
362
|
+
id: t
|
|
363
|
+
}
|
|
364
|
+
}), m({
|
|
365
|
+
signal: s,
|
|
366
|
+
marker: _,
|
|
367
|
+
searchInput: o,
|
|
368
|
+
level: o === "" ? p + 1 : null,
|
|
369
|
+
ancestorId: t !== d.id ? t.toString() : null,
|
|
370
|
+
onlySelectableOptions: !1
|
|
371
|
+
}).then((c) => {
|
|
372
|
+
const L = c.options.map(O);
|
|
373
|
+
r({
|
|
374
|
+
type: n.LOAD_SUCCESS,
|
|
375
|
+
payload: {
|
|
376
|
+
id: t,
|
|
377
|
+
items: L,
|
|
378
|
+
marker: c.marker
|
|
379
|
+
}
|
|
380
|
+
});
|
|
381
|
+
}).catch(() => {
|
|
382
|
+
r({
|
|
383
|
+
type: n.LOAD_ERROR,
|
|
384
|
+
payload: {
|
|
385
|
+
id: t,
|
|
386
|
+
marker: _
|
|
387
|
+
}
|
|
388
|
+
});
|
|
389
|
+
});
|
|
390
|
+
}, [m, O, o, D]), z = E.nodes.length === 0 || E.nodes[0].children.length === 0 && E.nodes[0].id === d.id;
|
|
391
|
+
return /* @__PURE__ */ N("div", {
|
|
392
|
+
children: [T && /* @__PURE__ */ u("div", {
|
|
393
|
+
className: f.noResultOption,
|
|
394
|
+
children: /* @__PURE__ */ u(G, {
|
|
395
|
+
"aria-label": U,
|
|
396
|
+
className: f.loadingIndicator
|
|
397
|
+
})
|
|
398
|
+
}), z && !T ? /* @__PURE__ */ u("div", {
|
|
399
|
+
className: f.noResultOption,
|
|
400
|
+
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
|
+
})
|
|
416
|
+
})]
|
|
417
|
+
});
|
|
418
|
+
};
|
|
419
|
+
export {
|
|
420
|
+
Re as D,
|
|
421
|
+
ye as S,
|
|
422
|
+
f as s
|
|
423
|
+
};
|
package/esm/index.js
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { ComboboxWithApiPagination as t } from "./lib/components/combobox-with-api-pagination/combobox-with-api-pagination.js";
|
|
2
|
+
import { ComboboxWithApiTreeView as r } from "./lib/components/combobox-with-api-tree-view/combobox-with-api-tree-view.js";
|
|
3
|
+
import { ComboboxWithApiContainer as m } from "./lib/components/combobox-with-api/combobox-with-api-container.js";
|
|
4
|
+
export {
|
|
5
|
+
m as ComboboxWithApi,
|
|
6
|
+
t as ComboboxWithApiPagination,
|
|
7
|
+
r as ComboboxWithApiTreeView
|
|
8
|
+
};
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import L from "lodash/debounce";
|
|
2
|
+
import { useState as e, useMemo as S, useCallback as V, useEffect as T } from "react";
|
|
3
|
+
import { ComboboxWithApi as w } from "./combobox-with-api.js";
|
|
4
|
+
import { jsx as Q } from "react/jsx-runtime";
|
|
5
|
+
const W = "AbortError", _ = (b) => {
|
|
6
|
+
const {
|
|
7
|
+
debounceTime: l = 250,
|
|
8
|
+
fetcher: u,
|
|
9
|
+
onInputValueChange: s,
|
|
10
|
+
includeTextInputOption: f = !1,
|
|
11
|
+
...h
|
|
12
|
+
} = b, [m, p] = e(!1), [d, y] = e(!1), [E, g] = e(!1), [o, x] = e(""), [A, r] = e([]), i = S(() => L(x, l), [l]), C = (n) => {
|
|
13
|
+
i(n), s == null || s(n);
|
|
14
|
+
}, a = V(async (n) => {
|
|
15
|
+
const c = n.trim();
|
|
16
|
+
if (c) {
|
|
17
|
+
y(!1), p(!0);
|
|
18
|
+
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]);
|
|
23
|
+
} else
|
|
24
|
+
g((t == null ? void 0 : t.length) === 0), r(t);
|
|
25
|
+
} catch (t) {
|
|
26
|
+
(t == null ? void 0 : t.name) !== W && y(!0);
|
|
27
|
+
} finally {
|
|
28
|
+
p(!1);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
}, [u, f]), I = () => {
|
|
32
|
+
a(o);
|
|
33
|
+
};
|
|
34
|
+
return T(() => (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
|
|
43
|
+
});
|
|
44
|
+
};
|
|
45
|
+
export {
|
|
46
|
+
_ as ComboboxWithApiContainer
|
|
47
|
+
};
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { Combobox as e, Text as i } from "@box/blueprint-web";
|
|
2
|
+
import { forwardRef as n } from "react";
|
|
3
|
+
import { FormattedMessage as s } from "react-intl";
|
|
4
|
+
import a from "./messages.js";
|
|
5
|
+
import { jsx as o } from "react/jsx-runtime";
|
|
6
|
+
import '../../../../styles/combobox-with-api-error.css';const m = "_container_1ozsi_1", c = {
|
|
7
|
+
container: m
|
|
8
|
+
}, h = /* @__PURE__ */ n(({
|
|
9
|
+
onTryAgain: r
|
|
10
|
+
}, t) => /* @__PURE__ */ o(e.Option, {
|
|
11
|
+
onClick: r,
|
|
12
|
+
children: /* @__PURE__ */ o("div", {
|
|
13
|
+
ref: t,
|
|
14
|
+
className: c.container,
|
|
15
|
+
children: /* @__PURE__ */ o(i, {
|
|
16
|
+
as: "span",
|
|
17
|
+
color: "textOnLightLink",
|
|
18
|
+
children: /* @__PURE__ */ o(s, {
|
|
19
|
+
...a.loadingResultsError
|
|
20
|
+
})
|
|
21
|
+
})
|
|
22
|
+
})
|
|
23
|
+
}));
|
|
24
|
+
export {
|
|
25
|
+
h as default
|
|
26
|
+
};
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { Combobox as f } from "@box/blueprint-web";
|
|
2
|
+
import v from "lodash/uniqBy";
|
|
3
|
+
import { useMemo as b } from "react";
|
|
4
|
+
import g from "./combobox-with-api-error.js";
|
|
5
|
+
import { jsx as n } from "react/jsx-runtime";
|
|
6
|
+
const h = (m) => {
|
|
7
|
+
const {
|
|
8
|
+
isError: u,
|
|
9
|
+
isEmpty: p,
|
|
10
|
+
isLoading: r,
|
|
11
|
+
noResultMessage: i,
|
|
12
|
+
options: t,
|
|
13
|
+
onTryAgain: a,
|
|
14
|
+
value: e,
|
|
15
|
+
...l
|
|
16
|
+
} = m, c = b(() => {
|
|
17
|
+
if (Array.isArray(e)) {
|
|
18
|
+
const d = [...t, ...e].reverse();
|
|
19
|
+
return v(d, (s) => (typeof s == "string" ? s : s.value).toLocaleLowerCase().trim()).reverse();
|
|
20
|
+
}
|
|
21
|
+
return t;
|
|
22
|
+
}, [t, e]);
|
|
23
|
+
let o;
|
|
24
|
+
return u && !r ? o = /* @__PURE__ */ n(g, {
|
|
25
|
+
onTryAgain: a
|
|
26
|
+
}) : p && i && !r ? o = i : o = void 0, /* @__PURE__ */ n(f, {
|
|
27
|
+
...l,
|
|
28
|
+
hideSelectedOptions: !0,
|
|
29
|
+
loading: r,
|
|
30
|
+
noResultMessage: o,
|
|
31
|
+
options: c,
|
|
32
|
+
value: e
|
|
33
|
+
});
|
|
34
|
+
};
|
|
35
|
+
export {
|
|
36
|
+
h as ComboboxWithApi
|
|
37
|
+
};
|