@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,207 @@
|
|
|
1
|
+
import { ComboboxItemValue as oe } from "@ariakit/react";
|
|
2
|
+
import { Combobox as m, LoadingIndicator as te, InlineNotice as re, Text as ne } from "@box/blueprint-web";
|
|
3
|
+
import { Search as ie, Loader as se } from "@box/blueprint-web-assets/icons/Fill";
|
|
4
|
+
import { IconIconOnLightSecondary as ae, Size6 as M, Size1 as le } from "@box/blueprint-web-assets/tokens/tokens";
|
|
5
|
+
import { useForkRef as ce } from "@box/blueprint-web/lib-esm/utils/useForkRef";
|
|
6
|
+
import T from "clsx";
|
|
7
|
+
import { forwardRef as F, useRef as C, useCallback as ue, useMemo as L, useEffect as de } from "react";
|
|
8
|
+
import { useIntl as P, FormattedMessage as V } from "react-intl";
|
|
9
|
+
import i from "./messages.js";
|
|
10
|
+
import { useAsyncList as me } from "./use-async-list.js";
|
|
11
|
+
import { useControllableState as pe } from "./utils/use-controllable-state.js";
|
|
12
|
+
import { useTrackVisibility as he } from "./utils/use-intersection-observer.js";
|
|
13
|
+
import { jsx as r, jsxs as N, Fragment as fe } from "react/jsx-runtime";
|
|
14
|
+
import '../../../../styles/combobox-with-api-pagination.css';const be = "_container_1m7se_1", ge = "_disabled_1m7se_7", xe = "_highlightOptionText_1m7se_11", _e = "_selected_1m7se_23", Oe = "_option_1m7se_34", Re = "_errorComboboxOption_1m7se_38", Ce = "_errorComboboxOptionText_1m7se_43", a = {
|
|
15
|
+
container: be,
|
|
16
|
+
disabled: ge,
|
|
17
|
+
highlightOptionText: xe,
|
|
18
|
+
selected: _e,
|
|
19
|
+
option: Oe,
|
|
20
|
+
errorComboboxOption: Re,
|
|
21
|
+
errorComboboxOptionText: Ce
|
|
22
|
+
}, S = /* @__PURE__ */ F(({
|
|
23
|
+
onTryAgain: y
|
|
24
|
+
}, p) => {
|
|
25
|
+
const {
|
|
26
|
+
formatMessage: h
|
|
27
|
+
} = P();
|
|
28
|
+
return /* @__PURE__ */ N(fe, {
|
|
29
|
+
children: [/* @__PURE__ */ r(re, {
|
|
30
|
+
variant: "error",
|
|
31
|
+
variantIconAriaLabel: h(i.loadingResultsErrorIconLabel),
|
|
32
|
+
children: /* @__PURE__ */ r(V, {
|
|
33
|
+
...i.loadingResultsErrorMessage
|
|
34
|
+
})
|
|
35
|
+
}), /* @__PURE__ */ r(m.Option, {
|
|
36
|
+
ref: p,
|
|
37
|
+
className: a.errorComboboxOption,
|
|
38
|
+
onClick: y,
|
|
39
|
+
children: /* @__PURE__ */ N(ne, {
|
|
40
|
+
as: "span",
|
|
41
|
+
className: a.errorComboboxOptionText,
|
|
42
|
+
color: "textOnLightLink",
|
|
43
|
+
variant: "bodyDefaultBold",
|
|
44
|
+
children: [/* @__PURE__ */ r(V, {
|
|
45
|
+
...i.loadingResultsErrorAction
|
|
46
|
+
}), /* @__PURE__ */ r(se, {
|
|
47
|
+
color: "currentColor",
|
|
48
|
+
height: "12px",
|
|
49
|
+
width: "12px"
|
|
50
|
+
})]
|
|
51
|
+
})
|
|
52
|
+
})]
|
|
53
|
+
});
|
|
54
|
+
}), A = "__LOADING__", E = "__LOADING_ERROR__", Le = "0px 0px 20px 0px", Ae = /* @__PURE__ */ r(ie, {
|
|
55
|
+
color: ae,
|
|
56
|
+
height: M,
|
|
57
|
+
role: "presentation",
|
|
58
|
+
style: {
|
|
59
|
+
padding: le,
|
|
60
|
+
boxSizing: "border-box"
|
|
61
|
+
},
|
|
62
|
+
width: M
|
|
63
|
+
}), we = /* @__PURE__ */ F(function(p, h) {
|
|
64
|
+
const {
|
|
65
|
+
defaultFetcher: k,
|
|
66
|
+
onInputValueChange: f,
|
|
67
|
+
value: D,
|
|
68
|
+
onValueChange: w,
|
|
69
|
+
noResultMessage: B,
|
|
70
|
+
defaultValue: W = [],
|
|
71
|
+
loadingAriaLabel: z,
|
|
72
|
+
multiselect: l = !1,
|
|
73
|
+
disabled: G,
|
|
74
|
+
className: j,
|
|
75
|
+
...U
|
|
76
|
+
} = p, {
|
|
77
|
+
formatMessage: u
|
|
78
|
+
} = P(), b = C(null), g = C(!0), e = me({
|
|
79
|
+
async load({
|
|
80
|
+
marker: o,
|
|
81
|
+
searchInput: t,
|
|
82
|
+
signal: R
|
|
83
|
+
}) {
|
|
84
|
+
const c = await k({
|
|
85
|
+
signal: R,
|
|
86
|
+
marker: o,
|
|
87
|
+
searchInput: t
|
|
88
|
+
});
|
|
89
|
+
return {
|
|
90
|
+
items: c.options,
|
|
91
|
+
marker: c.marker
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
}), v = C(!1), q = ue(() => {
|
|
95
|
+
v.current || (e.reload(), v.current = !0);
|
|
96
|
+
}, []), [n, x] = pe({
|
|
97
|
+
prop: D,
|
|
98
|
+
defaultProp: W,
|
|
99
|
+
onChange: w
|
|
100
|
+
}), _ = !l && n.length === 1, H = (o) => {
|
|
101
|
+
o === void 0 ? (x([]), g.current || (e.search(""), g.current = !0)) : Array.isArray(o) ? x(o) : x([o]);
|
|
102
|
+
}, J = L(() => n.length === 0 ? l ? [] : void 0 : l ? n : n[0], [l, n]), O = L(() => n.filter((o) => !e.items.some((t) => t.value === o.value)), [n, e.items]), K = (o) => {
|
|
103
|
+
const {
|
|
104
|
+
value: t,
|
|
105
|
+
displayValue: R,
|
|
106
|
+
...c
|
|
107
|
+
} = o;
|
|
108
|
+
if (t === A)
|
|
109
|
+
return e.hasNextPage ? /* @__PURE__ */ r(m.Option, {
|
|
110
|
+
...c,
|
|
111
|
+
ref: Y,
|
|
112
|
+
disabled: !0,
|
|
113
|
+
value: t,
|
|
114
|
+
children: /* @__PURE__ */ r(te, {
|
|
115
|
+
"aria-label": u(i.loadingMoreAriaLabel),
|
|
116
|
+
style: {
|
|
117
|
+
position: "unset"
|
|
118
|
+
}
|
|
119
|
+
})
|
|
120
|
+
}) : null;
|
|
121
|
+
if (t === E && e.hasError && !e.isEmpty)
|
|
122
|
+
return /* @__PURE__ */ r(S, {
|
|
123
|
+
onTryAgain: () => {
|
|
124
|
+
var s;
|
|
125
|
+
e.loadMore(), (s = b.current) == null || s.focus();
|
|
126
|
+
}
|
|
127
|
+
});
|
|
128
|
+
if (O.some((s) => s.value === t))
|
|
129
|
+
return null;
|
|
130
|
+
const ee = n.some((s) => s.value === t);
|
|
131
|
+
return /* @__PURE__ */ r(m.Option, {
|
|
132
|
+
...c,
|
|
133
|
+
className: a.option,
|
|
134
|
+
value: t,
|
|
135
|
+
children: /* @__PURE__ */ r(oe, {
|
|
136
|
+
className: T(a.highlightOptionText, ee && a.selected),
|
|
137
|
+
value: R || t
|
|
138
|
+
})
|
|
139
|
+
});
|
|
140
|
+
}, Q = (o) => {
|
|
141
|
+
if (f == null || f(o), _ && o === "") {
|
|
142
|
+
g.current = !1;
|
|
143
|
+
return;
|
|
144
|
+
}
|
|
145
|
+
e.search(o);
|
|
146
|
+
}, X = () => {
|
|
147
|
+
var o;
|
|
148
|
+
e.reload(), (o = b.current) == null || o.focus();
|
|
149
|
+
};
|
|
150
|
+
let d;
|
|
151
|
+
e.hasError && !e.isLoading ? d = /* @__PURE__ */ r(S, {
|
|
152
|
+
onTryAgain: X
|
|
153
|
+
}) : e.isEmpty && !e.isLoading ? d = B || u(i.noResults) : d = void 0;
|
|
154
|
+
const [Y, {
|
|
155
|
+
rootRef: Z,
|
|
156
|
+
isVisible: I
|
|
157
|
+
}] = he({
|
|
158
|
+
rootMargin: Le
|
|
159
|
+
});
|
|
160
|
+
de(() => {
|
|
161
|
+
if (!(I && e.hasNextPage))
|
|
162
|
+
return;
|
|
163
|
+
const t = setTimeout(() => {
|
|
164
|
+
e.loadMore();
|
|
165
|
+
}, 100);
|
|
166
|
+
return () => {
|
|
167
|
+
clearTimeout(t);
|
|
168
|
+
};
|
|
169
|
+
}, [I]);
|
|
170
|
+
const $ = L(() => {
|
|
171
|
+
const o = e.hasNextPage ? {
|
|
172
|
+
displayValue: A,
|
|
173
|
+
value: A
|
|
174
|
+
} : null, t = !o && e.hasError && !e.isEmpty ? {
|
|
175
|
+
displayValue: E,
|
|
176
|
+
value: E
|
|
177
|
+
} : null;
|
|
178
|
+
return [...e.items, ...O, o, t].filter(Boolean);
|
|
179
|
+
}, [e.hasNextPage, e.hasError, e.isEmpty, e.items, O]);
|
|
180
|
+
return /* @__PURE__ */ r(m, {
|
|
181
|
+
as: "input",
|
|
182
|
+
...U,
|
|
183
|
+
ref: ce(b, h),
|
|
184
|
+
className: T({
|
|
185
|
+
[a.disabled]: _
|
|
186
|
+
}, j),
|
|
187
|
+
clearButtonAriaLabel: u(i.clearButtonAriaLabel),
|
|
188
|
+
disabled: G || _,
|
|
189
|
+
displayValue: (o) => o.displayValue || o.value,
|
|
190
|
+
endComboboxIcon: Ae,
|
|
191
|
+
focusLoop: !1,
|
|
192
|
+
getPopoverRef: Z,
|
|
193
|
+
loading: e.isReloading,
|
|
194
|
+
loadingAriaLabel: z || u(i.loadingAriaLabel),
|
|
195
|
+
multiselect: l,
|
|
196
|
+
noResultMessage: d,
|
|
197
|
+
onFocus: q,
|
|
198
|
+
onInputValueChange: Q,
|
|
199
|
+
onValueChange: H,
|
|
200
|
+
options: $,
|
|
201
|
+
renderOption: K,
|
|
202
|
+
value: J
|
|
203
|
+
});
|
|
204
|
+
});
|
|
205
|
+
export {
|
|
206
|
+
we as ComboboxWithApiPagination
|
|
207
|
+
};
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { defineMessages as o } from "react-intl";
|
|
2
|
+
const e = o({
|
|
3
|
+
loadingResultsErrorAction: {
|
|
4
|
+
id: "comboboxWithApiPagination.errorAction",
|
|
5
|
+
defaultMessage: "Reload"
|
|
6
|
+
},
|
|
7
|
+
loadingResultsErrorMessage: {
|
|
8
|
+
id: "comboboxWithApiPagination.errorMessage",
|
|
9
|
+
defaultMessage: "Failed to load options"
|
|
10
|
+
},
|
|
11
|
+
loadingResultsErrorIconLabel: {
|
|
12
|
+
id: "comboboxWithApiPagination.errorIconLabel",
|
|
13
|
+
defaultMessage: "Error"
|
|
14
|
+
},
|
|
15
|
+
loadingAriaLabel: {
|
|
16
|
+
id: "comboboxWithApiPagination.loadingAriaLabel",
|
|
17
|
+
defaultMessage: "Loading..."
|
|
18
|
+
},
|
|
19
|
+
loadingMoreAriaLabel: {
|
|
20
|
+
id: "comboboxWithApiPagination.loadingMoreAriaLabel",
|
|
21
|
+
defaultMessage: "Loading more..."
|
|
22
|
+
},
|
|
23
|
+
noResults: {
|
|
24
|
+
id: "comboboxWithApiPagination.noResults",
|
|
25
|
+
defaultMessage: "No results found"
|
|
26
|
+
},
|
|
27
|
+
clearButtonAriaLabel: {
|
|
28
|
+
id: "comboboxWithApiPagination.clearButtonAriaLabel",
|
|
29
|
+
defaultMessage: "Clear input and selection"
|
|
30
|
+
}
|
|
31
|
+
});
|
|
32
|
+
export {
|
|
33
|
+
e as default
|
|
34
|
+
};
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
import { useReducer as O } from "react";
|
|
2
|
+
import { RequestStates as u } from "./request.js";
|
|
3
|
+
import { isAbortError as I } from "./utils/is-abort-error.js";
|
|
4
|
+
var s = /* @__PURE__ */ function(r) {
|
|
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 || {});
|
|
7
|
+
function a(r, e) {
|
|
8
|
+
switch (e.type) {
|
|
9
|
+
case s.LOAD_MORE:
|
|
10
|
+
return {
|
|
11
|
+
...r,
|
|
12
|
+
abortController: e.abortController,
|
|
13
|
+
error: null,
|
|
14
|
+
items: [...r.items, ...e.items],
|
|
15
|
+
marker: e.marker,
|
|
16
|
+
requestState: u.SUCCESS
|
|
17
|
+
};
|
|
18
|
+
case s.RELOAD:
|
|
19
|
+
return e.abortController !== r.abortController ? r : {
|
|
20
|
+
...r,
|
|
21
|
+
abortController: null,
|
|
22
|
+
error: null,
|
|
23
|
+
items: [...e.items],
|
|
24
|
+
marker: e.marker,
|
|
25
|
+
requestState: u.SUCCESS,
|
|
26
|
+
searchInput: ""
|
|
27
|
+
};
|
|
28
|
+
case s.SEARCH:
|
|
29
|
+
return {
|
|
30
|
+
...r,
|
|
31
|
+
abortController: e.abortController,
|
|
32
|
+
error: null,
|
|
33
|
+
items: [...e.items],
|
|
34
|
+
marker: e.marker,
|
|
35
|
+
requestState: u.SUCCESS,
|
|
36
|
+
searchInput: e.searchInput ?? r.searchInput
|
|
37
|
+
};
|
|
38
|
+
case s.SET_ERROR:
|
|
39
|
+
return {
|
|
40
|
+
...r,
|
|
41
|
+
items: s.LOAD_MORE ? r.items : [],
|
|
42
|
+
error: e.error,
|
|
43
|
+
requestState: u.ERROR
|
|
44
|
+
};
|
|
45
|
+
case s.SET_LOADING:
|
|
46
|
+
return {
|
|
47
|
+
...r,
|
|
48
|
+
requestInitiator: e.requestInitiator,
|
|
49
|
+
requestState: u.IN_PROGRESS,
|
|
50
|
+
abortController: e.abortController
|
|
51
|
+
};
|
|
52
|
+
default:
|
|
53
|
+
throw new Error(`Invalid action type "${e.type}"`);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
function E(r, e) {
|
|
57
|
+
return r.type === s.SEARCH && e.requestState === u.IN_PROGRESS;
|
|
58
|
+
}
|
|
59
|
+
function S(r, e) {
|
|
60
|
+
return e.requestInitiator === s.LOAD_MORE && e.requestState === u.IN_PROGRESS && r.type === s.LOAD_MORE;
|
|
61
|
+
}
|
|
62
|
+
function m(r, e) {
|
|
63
|
+
return E(r, e) || S(r, e);
|
|
64
|
+
}
|
|
65
|
+
function p(r, e) {
|
|
66
|
+
var t;
|
|
67
|
+
E(r, e) && e.abortController.abort(), S(r, e) && ((t = r.abortController) == null || t.abort());
|
|
68
|
+
}
|
|
69
|
+
function h(r, e) {
|
|
70
|
+
return S(r, e);
|
|
71
|
+
}
|
|
72
|
+
async function R(r, e, t, n) {
|
|
73
|
+
const o = new AbortController();
|
|
74
|
+
if (m(r, t) && p(r, t), !h(r, t)) {
|
|
75
|
+
n({
|
|
76
|
+
type: s.SET_LOADING,
|
|
77
|
+
requestInitiator: r.type,
|
|
78
|
+
abortController: o
|
|
79
|
+
});
|
|
80
|
+
try {
|
|
81
|
+
const l = await e({
|
|
82
|
+
items: t.items.slice(),
|
|
83
|
+
signal: o.signal,
|
|
84
|
+
marker: r.type === s.LOAD_MORE ? t.marker : null,
|
|
85
|
+
searchInput: r.searchInput ?? t.searchInput
|
|
86
|
+
}), i = l.searchInput ?? r.searchInput ?? t.searchInput;
|
|
87
|
+
n({
|
|
88
|
+
type: r.type,
|
|
89
|
+
...l,
|
|
90
|
+
searchInput: i,
|
|
91
|
+
abortController: o
|
|
92
|
+
});
|
|
93
|
+
} catch (l) {
|
|
94
|
+
if (I(l))
|
|
95
|
+
return;
|
|
96
|
+
n({
|
|
97
|
+
type: s.SET_ERROR,
|
|
98
|
+
error: l,
|
|
99
|
+
abortController: o
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
function _(r) {
|
|
105
|
+
const {
|
|
106
|
+
load: e
|
|
107
|
+
} = r, [t, n] = O(a, {
|
|
108
|
+
error: null,
|
|
109
|
+
items: [],
|
|
110
|
+
requestInitiator: null,
|
|
111
|
+
requestState: u.NOT_STARTED,
|
|
112
|
+
searchInput: ""
|
|
113
|
+
});
|
|
114
|
+
return {
|
|
115
|
+
hasError: t.requestState === u.ERROR,
|
|
116
|
+
hasNextPage: t.requestState === u.ERROR ? !1 : t.marker != null,
|
|
117
|
+
isEmpty: t.items.length === 0,
|
|
118
|
+
isLoading: t.requestState === u.IN_PROGRESS,
|
|
119
|
+
isReloading: t.requestState === u.IN_PROGRESS && (t.requestInitiator === s.RELOAD || t.requestInitiator === s.SEARCH),
|
|
120
|
+
items: t.items,
|
|
121
|
+
loadMore: () => R({
|
|
122
|
+
type: s.LOAD_MORE
|
|
123
|
+
}, e, t, n),
|
|
124
|
+
reload: () => R({
|
|
125
|
+
type: s.RELOAD
|
|
126
|
+
}, e, t, n),
|
|
127
|
+
requestInitiator: t.requestInitiator,
|
|
128
|
+
searchInput: t.searchInput,
|
|
129
|
+
search: (o) => R({
|
|
130
|
+
type: s.SEARCH,
|
|
131
|
+
searchInput: o
|
|
132
|
+
}, e, t, n)
|
|
133
|
+
};
|
|
134
|
+
}
|
|
135
|
+
export {
|
|
136
|
+
_ as useAsyncList
|
|
137
|
+
};
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import * as s from "react";
|
|
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
|
+
}, []);
|
|
10
|
+
}
|
|
11
|
+
function R({
|
|
12
|
+
prop: e,
|
|
13
|
+
defaultProp: n,
|
|
14
|
+
onChange: o = () => {
|
|
15
|
+
}
|
|
16
|
+
}) {
|
|
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) => {
|
|
21
|
+
if (r) {
|
|
22
|
+
const f = typeof u == "function" ? u(e) : u;
|
|
23
|
+
f !== e && l(f);
|
|
24
|
+
} else
|
|
25
|
+
c(u);
|
|
26
|
+
}, [r, e, c, l]);
|
|
27
|
+
return [i, d];
|
|
28
|
+
}
|
|
29
|
+
function C({
|
|
30
|
+
defaultProp: e,
|
|
31
|
+
onChange: n
|
|
32
|
+
}) {
|
|
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;
|
|
37
|
+
}
|
|
38
|
+
export {
|
|
39
|
+
R as useControllableState
|
|
40
|
+
};
|
|
@@ -0,0 +1,87 @@
|
|
|
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
|
|
9
|
+
}) {
|
|
10
|
+
let r = o.get(c);
|
|
11
|
+
r || (r = /* @__PURE__ */ new Map(), o.set(c, r));
|
|
12
|
+
const i = JSON.stringify({
|
|
13
|
+
rootMargin: s,
|
|
14
|
+
threshold: u
|
|
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);
|
|
24
|
+
});
|
|
25
|
+
}, {
|
|
26
|
+
root: c,
|
|
27
|
+
rootMargin: s,
|
|
28
|
+
threshold: u
|
|
29
|
+
}),
|
|
30
|
+
entryCallbacks: n
|
|
31
|
+
}, r.set(i, e);
|
|
32
|
+
}
|
|
33
|
+
return {
|
|
34
|
+
observe: (n, l) => {
|
|
35
|
+
e == null || e.entryCallbacks.set(n, l), e == null || e.observer.observe(n);
|
|
36
|
+
},
|
|
37
|
+
unobserve: (n) => {
|
|
38
|
+
e == null || e.entryCallbacks.delete(n), e == null || e.observer.unobserve(n);
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
return {
|
|
43
|
+
getObserver: b
|
|
44
|
+
};
|
|
45
|
+
}
|
|
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);
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
const f = M.getObserver({
|
|
55
|
+
root: u.current,
|
|
56
|
+
rootMargin: b,
|
|
57
|
+
threshold: c
|
|
58
|
+
});
|
|
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, {
|
|
71
|
+
entry: i,
|
|
72
|
+
rootRef: v
|
|
73
|
+
}];
|
|
74
|
+
}
|
|
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
|
|
82
|
+
}];
|
|
83
|
+
}
|
|
84
|
+
export {
|
|
85
|
+
w as createObserverCache,
|
|
86
|
+
V as useTrackVisibility
|
|
87
|
+
};
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
import { useComboboxStore as j, ComboboxProvider as F, PopoverAnchor as G, Combobox as z, ComboboxCancel as E, ComboboxPopover as X } from "@ariakit/react";
|
|
2
|
+
import { useLabelable as q, InputChip as H, IconButton as J } from "@box/blueprint-web";
|
|
3
|
+
import { XMark as K } from "@box/blueprint-web-assets/icons/Fill";
|
|
4
|
+
import { ChipsGroup as Q } from "@box/blueprint-web/lib-esm/combobox/chips-group";
|
|
5
|
+
import c from "clsx";
|
|
6
|
+
import { forwardRef as U, useId as Y, useState as g, useRef as Z, useCallback as _ } from "react";
|
|
7
|
+
import { useIntl as $ } from "react-intl";
|
|
8
|
+
import V from "../combobox-with-api-pagination/messages.js";
|
|
9
|
+
import { useControllableState as ee } from "../combobox-with-api-pagination/utils/use-controllable-state.js";
|
|
10
|
+
import { s as l, D as oe } from "../../../../chunks/dynamic-loading-tree.js";
|
|
11
|
+
import { jsxs as u, jsx as o } from "react/jsx-runtime";
|
|
12
|
+
const fe = /* @__PURE__ */ U(function(I, te) {
|
|
13
|
+
const {
|
|
14
|
+
defaultFetcher: L,
|
|
15
|
+
value: N,
|
|
16
|
+
onValueChange: w,
|
|
17
|
+
noResultMessage: S,
|
|
18
|
+
defaultValue: A = [],
|
|
19
|
+
loadingAriaLabel: R,
|
|
20
|
+
multiselect: m = !1,
|
|
21
|
+
className: y,
|
|
22
|
+
levels: B,
|
|
23
|
+
selectableLevels: M,
|
|
24
|
+
label: P,
|
|
25
|
+
hideLabel: p,
|
|
26
|
+
treeAriaLabel: k
|
|
27
|
+
} = I, {
|
|
28
|
+
formatMessage: b
|
|
29
|
+
} = $(), d = Y(), [f, D] = g(!1), [t, n] = ee({
|
|
30
|
+
prop: N,
|
|
31
|
+
defaultProp: A,
|
|
32
|
+
onChange: w
|
|
33
|
+
}), [h, C] = g(""), O = Z(null), T = _((e) => {
|
|
34
|
+
C(e);
|
|
35
|
+
}, [C]), i = j({
|
|
36
|
+
includesBaseElement: !0,
|
|
37
|
+
virtualFocus: !1,
|
|
38
|
+
value: h,
|
|
39
|
+
setValue: T,
|
|
40
|
+
open: f,
|
|
41
|
+
setOpen: D
|
|
42
|
+
}), v = t.length > 0, x = t.length > 0, W = q(P, d);
|
|
43
|
+
return /* @__PURE__ */ u(F, {
|
|
44
|
+
store: i,
|
|
45
|
+
children: [/* @__PURE__ */ o(W, {
|
|
46
|
+
className: c(l.label, {
|
|
47
|
+
[l.hiddenLabel]: p
|
|
48
|
+
}),
|
|
49
|
+
hideLabel: p
|
|
50
|
+
}), /* @__PURE__ */ o(G, {
|
|
51
|
+
children: /* @__PURE__ */ o("div", {
|
|
52
|
+
className: c(l.container, y),
|
|
53
|
+
children: /* @__PURE__ */ u("div", {
|
|
54
|
+
className: c(l.comboboxContainer, {
|
|
55
|
+
[l.withChips]: x,
|
|
56
|
+
[l.withComboboxButtons]: v
|
|
57
|
+
}),
|
|
58
|
+
children: [x && /* @__PURE__ */ o(Q, {
|
|
59
|
+
children: t.map((e) => /* @__PURE__ */ o(H, {
|
|
60
|
+
label: e.displayValue,
|
|
61
|
+
onDelete: () => {
|
|
62
|
+
const a = t.filter((r) => r.value !== e.value);
|
|
63
|
+
n(a);
|
|
64
|
+
},
|
|
65
|
+
tooltip: e.displayValue
|
|
66
|
+
}, e.value))
|
|
67
|
+
}), /* @__PURE__ */ u("div", {
|
|
68
|
+
className: l.textInputWrapper,
|
|
69
|
+
children: [/* @__PURE__ */ o(z, {
|
|
70
|
+
ref: O,
|
|
71
|
+
className: l.textInput,
|
|
72
|
+
id: d,
|
|
73
|
+
store: i
|
|
74
|
+
}), /* @__PURE__ */ o("div", {
|
|
75
|
+
className: l.comboboxButtons,
|
|
76
|
+
children: v ? /* @__PURE__ */ o(E, {
|
|
77
|
+
onClick: () => {
|
|
78
|
+
n([]);
|
|
79
|
+
},
|
|
80
|
+
render: (e) => /* @__PURE__ */ o(J, {
|
|
81
|
+
...e,
|
|
82
|
+
"aria-label": "Clear selection",
|
|
83
|
+
icon: K,
|
|
84
|
+
size: "x-small"
|
|
85
|
+
}),
|
|
86
|
+
store: i
|
|
87
|
+
}) : null
|
|
88
|
+
})]
|
|
89
|
+
})]
|
|
90
|
+
})
|
|
91
|
+
})
|
|
92
|
+
}), /* @__PURE__ */ o(X, {
|
|
93
|
+
className: l.popover,
|
|
94
|
+
gutter: 8,
|
|
95
|
+
children: /* @__PURE__ */ o(oe, {
|
|
96
|
+
ariaLabel: k,
|
|
97
|
+
defaultFetcher: L,
|
|
98
|
+
levels: B,
|
|
99
|
+
loadingAriaLabel: R || b(V.loadingAriaLabel),
|
|
100
|
+
multiselect: m,
|
|
101
|
+
noResultMessage: S || b(V.noResults),
|
|
102
|
+
onSelect: (e) => {
|
|
103
|
+
const {
|
|
104
|
+
metadata: s
|
|
105
|
+
} = e.element;
|
|
106
|
+
let a = [];
|
|
107
|
+
e.isSelected ? (m && (a = t.filter((r) => r.value !== e.element.id)), a.push({
|
|
108
|
+
value: e.element.id,
|
|
109
|
+
displayValue: s.displayValue,
|
|
110
|
+
level: s.level,
|
|
111
|
+
selectable: s.selectable,
|
|
112
|
+
ancestors: s.ancestors
|
|
113
|
+
})) : a = t.filter((r) => r.value !== e.element.id), n(a);
|
|
114
|
+
},
|
|
115
|
+
open: f,
|
|
116
|
+
searchInput: h.trimStart(),
|
|
117
|
+
selectableLevels: M,
|
|
118
|
+
selectedNodes: t.map((e) => e.value)
|
|
119
|
+
})
|
|
120
|
+
})]
|
|
121
|
+
});
|
|
122
|
+
});
|
|
123
|
+
export {
|
|
124
|
+
fe as ComboboxWithApiTreeView
|
|
125
|
+
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import "@box/blueprint-web";
|
|
2
|
+
import "@box/tree";
|
|
3
|
+
import "react";
|
|
4
|
+
import "./tree-utils.js";
|
|
5
|
+
import { D as p, S as s } from "../../../../chunks/dynamic-loading-tree.js";
|
|
6
|
+
import "react/jsx-runtime";
|
|
7
|
+
export {
|
|
8
|
+
p as DynamicLoadingTree,
|
|
9
|
+
s as SearchResultsName
|
|
10
|
+
};
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
const r = (t, n, e) => {
|
|
2
|
+
const o = {
|
|
3
|
+
name: n,
|
|
4
|
+
id: `${t}_${e}`,
|
|
5
|
+
parent: t,
|
|
6
|
+
children: [],
|
|
7
|
+
metadata: {
|
|
8
|
+
variant: e
|
|
9
|
+
}
|
|
10
|
+
};
|
|
11
|
+
return o;
|
|
12
|
+
}, d = {
|
|
13
|
+
name: "Root",
|
|
14
|
+
id: "root",
|
|
15
|
+
parent: null,
|
|
16
|
+
children: [],
|
|
17
|
+
metadata: {
|
|
18
|
+
variant: "content",
|
|
19
|
+
level: 0,
|
|
20
|
+
displayValue: "Root"
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
export {
|
|
24
|
+
d as RootTreeNode,
|
|
25
|
+
r as getServiceNode
|
|
26
|
+
};
|