@box/combobox-with-api 1.42.32 → 1.42.34

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.
Files changed (28) hide show
  1. package/dist/chunks/combobox-with-api-error.js +18 -0
  2. package/dist/chunks/combobox-with-api-pagination.js +168 -0
  3. package/dist/chunks/combobox-with-api-pagination2.js +229 -0
  4. package/dist/chunks/combobox-with-api-tree-view.js +423 -0
  5. package/dist/chunks/dynamic-loading-tree.js +299 -326
  6. package/dist/chunks/treeReducer.js +60 -78
  7. package/dist/esm/index.js +6 -16
  8. package/dist/esm/lib/components/combobox-with-api/combobox-with-api-container.js +47 -52
  9. package/dist/esm/lib/components/combobox-with-api/combobox-with-api-error.js +2 -26
  10. package/dist/esm/lib/components/combobox-with-api/combobox-with-api.js +16 -36
  11. package/dist/esm/lib/components/combobox-with-api/messages.js +6 -10
  12. package/dist/esm/lib/components/combobox-with-api-pagination/combobox-with-api-pagination.js +2 -214
  13. package/dist/esm/lib/components/combobox-with-api-pagination/index.js +3 -205
  14. package/dist/esm/lib/components/combobox-with-api-pagination/messages.js +31 -33
  15. package/dist/esm/lib/components/combobox-with-api-pagination/request.js +4 -6
  16. package/dist/esm/lib/components/combobox-with-api-pagination/use-async-list.js +113 -128
  17. package/dist/esm/lib/components/combobox-with-api-pagination/utils/is-abort-error.js +8 -10
  18. package/dist/esm/lib/components/combobox-with-api-pagination/utils/use-controllable-state.js +32 -34
  19. package/dist/esm/lib/components/combobox-with-api-pagination/utils/use-intersection-observer.js +72 -82
  20. package/dist/esm/lib/components/combobox-with-api-tree-view/combobox-with-api-tree-view.js +133 -174
  21. package/dist/esm/lib/components/combobox-with-api-tree-view/dynamic-loading-tree.js +2 -10
  22. package/dist/esm/lib/components/combobox-with-api-tree-view/index.js +3 -464
  23. package/dist/esm/lib/components/combobox-with-api-tree-view/tree-utils.js +17 -26
  24. package/dist/esm/lib/components/combobox-with-api-tree-view/treeReducer.js +2 -6
  25. package/dist/styles/combobox-with-api-error.css +1 -1
  26. package/dist/styles/combobox-with-api-pagination.css +1 -1
  27. package/dist/styles/dynamic-loading-tree.css +1 -1
  28. package/package.json +7 -7
@@ -0,0 +1,18 @@
1
+ import e from "../esm/lib/components/combobox-with-api/messages.js";
2
+ import { Combobox as t, Text as n } from "@box/blueprint-web";
3
+ import { forwardRef as r } from "react";
4
+ import { FormattedMessage as i } from "react-intl";
5
+ import { jsx as a } from "react/jsx-runtime";
6
+ import '../styles/combobox-with-api-error.css';var o = { container: "_container_1ozsi_1" }, s = /* @__PURE__ */ r(({ onTryAgain: r }, s) => /* @__PURE__ */ a(t.Option, {
7
+ onClick: r,
8
+ children: /* @__PURE__ */ a("div", {
9
+ ref: s,
10
+ className: o.container,
11
+ children: /* @__PURE__ */ a(n, {
12
+ as: "span",
13
+ color: "textOnLightLink",
14
+ children: /* @__PURE__ */ a(i, { ...e.loadingResultsError })
15
+ })
16
+ })
17
+ }));
18
+ export { s as t };
@@ -0,0 +1,168 @@
1
+ import e from "../esm/lib/components/combobox-with-api-pagination/messages.js";
2
+ import { useAsyncList as t } from "../esm/lib/components/combobox-with-api-pagination/use-async-list.js";
3
+ import { useControllableState as n } from "../esm/lib/components/combobox-with-api-pagination/utils/use-controllable-state.js";
4
+ import { useTrackVisibility as r } from "../esm/lib/components/combobox-with-api-pagination/utils/use-intersection-observer.js";
5
+ import { ComboboxItemValue as ee } from "@ariakit/react";
6
+ import { Combobox as i, InlineNotice as a, LoadingIndicator as o, Text as s, useForkRef as c } from "@box/blueprint-web";
7
+ import { Loader as l, Search as u } from "@box/blueprint-web-assets/icons/Fill";
8
+ import { IconIconOnLightSecondary as d, Size1 as f, Size6 as p } from "@box/blueprint-web-assets/tokens/tokens";
9
+ import m from "clsx";
10
+ import { forwardRef as h, useCallback as g, useEffect as _, useMemo as v, useRef as y, useState as b } from "react";
11
+ import { FormattedMessage as x, useIntl as S } from "react-intl";
12
+ import { Fragment as C, jsx as w, jsxs as T } from "react/jsx-runtime";
13
+ import '../styles/combobox-with-api-pagination.css';var E = {
14
+ container: "_container_19k3s_2",
15
+ disabled: "_disabled_19k3s_8",
16
+ highlightOptionText: "_highlightOptionText_19k3s_12",
17
+ selected: "_selected_19k3s_24",
18
+ option: "_option_19k3s_35",
19
+ errorComboboxOption: "_errorComboboxOption_19k3s_39",
20
+ errorComboboxOptionText: "_errorComboboxOptionText_19k3s_44"
21
+ }, D = /* @__PURE__ */ h(({ onTryAgain: t }, n) => {
22
+ let { formatMessage: r } = S();
23
+ return /* @__PURE__ */ T(C, { children: [/* @__PURE__ */ w(a, {
24
+ variant: "error",
25
+ variantIconAriaLabel: r(e.loadingResultsErrorIconLabel),
26
+ children: /* @__PURE__ */ w(x, { ...e.loadingResultsErrorMessage })
27
+ }), /* @__PURE__ */ w(i.Option, {
28
+ ref: n,
29
+ className: E.errorComboboxOption,
30
+ onClick: t,
31
+ children: /* @__PURE__ */ T(s, {
32
+ as: "span",
33
+ className: E.errorComboboxOptionText,
34
+ color: "textOnLightLink",
35
+ variant: "bodyDefaultBold",
36
+ children: [/* @__PURE__ */ w(x, { ...e.loadingResultsErrorAction }), /* @__PURE__ */ w(l, {
37
+ color: "currentColor",
38
+ height: "12px",
39
+ width: "12px"
40
+ })]
41
+ })
42
+ })] });
43
+ }), O = "__LOADING__", k = "__LOADING_ERROR__", te = "0px 0px 20px 0px", ne = /* @__PURE__ */ w(u, {
44
+ color: d,
45
+ height: p,
46
+ role: "presentation",
47
+ style: {
48
+ padding: f,
49
+ boxSizing: "border-box"
50
+ },
51
+ width: p
52
+ }), A = /* @__PURE__ */ h(function(a, s) {
53
+ let { dataTargetId: l, defaultFetcher: u, initialOpen: d = !1, onInputValueChange: f, value: p, onValueChange: h, onOpenChange: x, noResultMessage: C, defaultValue: T = [], loadingAriaLabel: A, multiselect: j = !1, disabled: M, className: N, displaySingleSelectionAsChip: P = !0, ...re } = a, { formatMessage: F } = S(), I = y(null), L = y(!0), [R, z] = b(d), B = t({ async load({ marker: e, searchInput: t, signal: n }) {
54
+ let r = await u({
55
+ signal: n,
56
+ marker: e,
57
+ searchInput: t
58
+ });
59
+ return {
60
+ items: r.options,
61
+ marker: r.marker
62
+ };
63
+ } }), V = y(!1), H = g(() => {
64
+ V.current ||= (B.reload(), !0);
65
+ }, []), [U, W] = n({
66
+ prop: p,
67
+ defaultProp: T,
68
+ onChange: h
69
+ }), G = !j && U.length === 1, K = G && !M, q = g((e) => {
70
+ z(e), x?.(e);
71
+ }, [x]), J = (e) => {
72
+ M || (e === void 0 ? (W([]), (!L.current || !P) && (B.search(""), L.current = !0)) : Array.isArray(e) ? W(e) : (W([e]), j || (z(!1), x?.(!1))));
73
+ }, Y = v(() => U.length === 0 ? j ? [] : void 0 : j ? U : U[0], [j, U]), X = v(() => U.filter((e) => !B.items.some((t) => t.value === e.value)), [U, B.items]), ie = (t) => {
74
+ let { value: n, displayValue: r, ...a } = t;
75
+ if (n === O) return B.hasNextPage ? /* @__PURE__ */ w(i.Option, {
76
+ ...a,
77
+ ref: oe,
78
+ disabled: !0,
79
+ value: n,
80
+ children: /* @__PURE__ */ w(o, {
81
+ "aria-label": F(e.loadingMoreAriaLabel),
82
+ style: { position: "unset" }
83
+ })
84
+ }) : null;
85
+ if (n === k && B.hasError && !B.isEmpty) return /* @__PURE__ */ w(D, { onTryAgain: () => {
86
+ B.loadMore(), I.current?.focus();
87
+ } });
88
+ if (X.some((e) => e.value === n)) return null;
89
+ let s = U.some((e) => e.value === n);
90
+ return /* @__PURE__ */ w(i.Option, {
91
+ ...a,
92
+ className: E.option,
93
+ value: n,
94
+ children: /* @__PURE__ */ w(ee, {
95
+ className: m(E.highlightOptionText, s && E.selected),
96
+ value: r || n
97
+ })
98
+ });
99
+ }, Z = (e) => {
100
+ if (f?.(e), G && e === "") {
101
+ L.current = !1;
102
+ return;
103
+ }
104
+ B.search(e);
105
+ }, ae = () => {
106
+ B.reload(), I.current?.focus();
107
+ }, Q;
108
+ Q = B.hasError && !B.isLoading ? /* @__PURE__ */ w(D, { onTryAgain: ae }) : B.isEmpty && !B.isLoading ? C || F(e.noResults) : void 0;
109
+ let [oe, { rootRef: se, isVisible: $ }] = r({ rootMargin: te });
110
+ _(() => {
111
+ if (!($ && B.hasNextPage)) return;
112
+ let e = setTimeout(() => {
113
+ B.loadMore();
114
+ }, 100);
115
+ return () => {
116
+ clearTimeout(e);
117
+ };
118
+ }, [$]);
119
+ let ce = v(() => {
120
+ let e = B.hasNextPage ? {
121
+ displayValue: O,
122
+ value: O
123
+ } : null, t = !e && B.hasError && !B.isEmpty ? {
124
+ displayValue: k,
125
+ value: k
126
+ } : null;
127
+ return [
128
+ ...B.items,
129
+ ...X,
130
+ e,
131
+ t
132
+ ].filter(Boolean);
133
+ }, [
134
+ B.hasNextPage,
135
+ B.hasError,
136
+ B.isEmpty,
137
+ B.items,
138
+ X
139
+ ]);
140
+ return /* @__PURE__ */ w(i, {
141
+ ...re,
142
+ ref: c(I, s),
143
+ as: "input",
144
+ className: m(N, { [E.disabled]: K }),
145
+ clearButtonAriaLabel: F(e.clearButtonAriaLabel),
146
+ clearOnBlur: !1,
147
+ "data-target-id": l,
148
+ disabled: M || G && P,
149
+ displaySingleSelectionAsChip: P,
150
+ displayValue: (e) => e.displayValue || e.value,
151
+ endComboboxIcon: ne,
152
+ focusLoop: !1,
153
+ getPopoverRef: se,
154
+ loading: B.isReloading,
155
+ loadingAriaLabel: A || F(e.loadingAriaLabel),
156
+ multiselect: j,
157
+ noResultMessage: Q,
158
+ onFocus: H,
159
+ onInputValueChange: Z,
160
+ onOpenChange: q,
161
+ onValueChange: J,
162
+ open: R,
163
+ options: ce,
164
+ renderOption: ie,
165
+ value: Y
166
+ });
167
+ });
168
+ export { A as t };
@@ -0,0 +1,229 @@
1
+ function e(e) {
2
+ return {
3
+ marker: e.marker,
4
+ options: e.options.map(({ value: e, displayValue: t }) => t ? {
5
+ displayValue: t,
6
+ value: e
7
+ } : { value: e })
8
+ };
9
+ }
10
+ var t = [
11
+ {
12
+ value: "0",
13
+ displayValue: "Alabama"
14
+ },
15
+ {
16
+ value: "1",
17
+ displayValue: "Alaska"
18
+ },
19
+ {
20
+ value: "2",
21
+ displayValue: "Arizona"
22
+ },
23
+ {
24
+ value: "3",
25
+ displayValue: "Arkansas"
26
+ },
27
+ {
28
+ value: "4",
29
+ displayValue: "California"
30
+ },
31
+ {
32
+ value: "5",
33
+ displayValue: "Colorado"
34
+ },
35
+ {
36
+ value: "6",
37
+ displayValue: "Connecticut"
38
+ },
39
+ {
40
+ value: "7",
41
+ displayValue: "Delaware"
42
+ },
43
+ {
44
+ value: "8",
45
+ displayValue: "Florida"
46
+ },
47
+ {
48
+ value: "9",
49
+ displayValue: "Georgia"
50
+ },
51
+ {
52
+ value: "10",
53
+ displayValue: "Hawaii"
54
+ },
55
+ {
56
+ value: "11",
57
+ displayValue: "Idaho"
58
+ },
59
+ {
60
+ value: "12",
61
+ displayValue: "Illinois"
62
+ },
63
+ {
64
+ value: "13",
65
+ displayValue: "Indiana"
66
+ },
67
+ {
68
+ value: "14",
69
+ displayValue: "Iowa"
70
+ },
71
+ {
72
+ value: "15",
73
+ displayValue: "Kansas"
74
+ },
75
+ {
76
+ value: "16",
77
+ displayValue: "Kentucky"
78
+ },
79
+ {
80
+ value: "17",
81
+ displayValue: "Louisiana"
82
+ },
83
+ {
84
+ value: "18",
85
+ displayValue: "Maine"
86
+ },
87
+ {
88
+ value: "19",
89
+ displayValue: "Maryland"
90
+ },
91
+ {
92
+ value: "20",
93
+ displayValue: "Massachusetts"
94
+ },
95
+ {
96
+ value: "21",
97
+ displayValue: "Michigan"
98
+ },
99
+ {
100
+ value: "22",
101
+ displayValue: "Minnesota"
102
+ },
103
+ {
104
+ value: "23",
105
+ displayValue: "Mississippi"
106
+ },
107
+ {
108
+ value: "24",
109
+ displayValue: "Missouri"
110
+ },
111
+ {
112
+ value: "25",
113
+ displayValue: "Montana"
114
+ },
115
+ {
116
+ value: "26",
117
+ displayValue: "Nebraska"
118
+ },
119
+ {
120
+ value: "27",
121
+ displayValue: "Nevada"
122
+ },
123
+ {
124
+ value: "28",
125
+ displayValue: "New Hampshire"
126
+ },
127
+ {
128
+ value: "29",
129
+ displayValue: "New Jersey"
130
+ },
131
+ {
132
+ value: "30",
133
+ displayValue: "New Mexico"
134
+ },
135
+ {
136
+ value: "31",
137
+ displayValue: "New York"
138
+ },
139
+ {
140
+ value: "32",
141
+ displayValue: "North Carolina"
142
+ },
143
+ {
144
+ value: "33",
145
+ displayValue: "North Dakota"
146
+ },
147
+ {
148
+ value: "34",
149
+ displayValue: "Ohio"
150
+ },
151
+ {
152
+ value: "35",
153
+ displayValue: "Oklahoma"
154
+ },
155
+ {
156
+ value: "36",
157
+ displayValue: "Oregon"
158
+ },
159
+ {
160
+ value: "37",
161
+ displayValue: "Pennsylvania"
162
+ },
163
+ {
164
+ value: "38",
165
+ displayValue: "Rhode Island"
166
+ },
167
+ {
168
+ value: "39",
169
+ displayValue: "South Carolina"
170
+ },
171
+ {
172
+ value: "40",
173
+ displayValue: "South Dakota"
174
+ },
175
+ {
176
+ value: "41",
177
+ displayValue: "Tennessee"
178
+ },
179
+ {
180
+ value: "42",
181
+ displayValue: "Texas"
182
+ },
183
+ {
184
+ value: "43",
185
+ displayValue: "Utah"
186
+ },
187
+ {
188
+ value: "44",
189
+ displayValue: "Vermont"
190
+ },
191
+ {
192
+ value: "45",
193
+ displayValue: "Virginia"
194
+ },
195
+ {
196
+ value: "46",
197
+ displayValue: "Washington"
198
+ },
199
+ {
200
+ value: "47",
201
+ displayValue: "West Virginia"
202
+ },
203
+ {
204
+ value: "48",
205
+ displayValue: "Wisconsin"
206
+ },
207
+ {
208
+ value: "49",
209
+ displayValue: "Wyoming"
210
+ }
211
+ ], n = (e) => t.find((t) => t.displayValue === e), r = 10, i = (e, t) => {
212
+ let n = (parseInt(e, 10) || 0) * r, i = n + r;
213
+ return t.slice(n, i).map(({ displayValue: e, value: t }) => ({
214
+ displayValue: e,
215
+ value: t
216
+ }));
217
+ }, a = (e, t) => (parseInt(e, 10) || 0) * r + r < t.length ? ((parseInt(e, 10) || 0) + 1).toString() : void 0, o = (() => {
218
+ let n = 0;
219
+ return async ({ delay: r, signal: o, searchInput: s, marker: c, failOnLoadMore: l, failOnLoadMoreTimes: u = 2 ** 53 - 1, options: d = t }) => {
220
+ if (r && await new Promise((e) => setTimeout(e, r)), o.aborted) return Promise.reject(new DOMException("Aborted", "AbortError"));
221
+ if (l && c != null && n < u) return n += 1, Promise.reject();
222
+ let f = d.filter(({ displayValue: e, value: t }) => e ? e.toLowerCase().includes(s.toLowerCase()) : t.toLowerCase().includes(s.toLowerCase()));
223
+ return e(await Promise.resolve({
224
+ marker: a(c, f),
225
+ options: i(c, f)
226
+ }));
227
+ };
228
+ })();
229
+ export { o as n, t as r, n as t };