@box/combobox-with-api 1.42.33 → 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
@@ -1,205 +1,3 @@
1
- import { ComboboxWithApiPagination as x } from "./combobox-with-api-pagination.js";
2
- function V(a) {
3
- return {
4
- marker: a.marker,
5
- options: a.options.map(({
6
- value: e,
7
- displayValue: l
8
- }) => l ? {
9
- displayValue: l,
10
- value: e
11
- } : {
12
- value: e
13
- })
14
- };
15
- }
16
- const r = [{
17
- value: "0",
18
- displayValue: "Alabama"
19
- }, {
20
- value: "1",
21
- displayValue: "Alaska"
22
- }, {
23
- value: "2",
24
- displayValue: "Arizona"
25
- }, {
26
- value: "3",
27
- displayValue: "Arkansas"
28
- }, {
29
- value: "4",
30
- displayValue: "California"
31
- }, {
32
- value: "5",
33
- displayValue: "Colorado"
34
- }, {
35
- value: "6",
36
- displayValue: "Connecticut"
37
- }, {
38
- value: "7",
39
- displayValue: "Delaware"
40
- }, {
41
- value: "8",
42
- displayValue: "Florida"
43
- }, {
44
- value: "9",
45
- displayValue: "Georgia"
46
- }, {
47
- value: "10",
48
- displayValue: "Hawaii"
49
- }, {
50
- value: "11",
51
- displayValue: "Idaho"
52
- }, {
53
- value: "12",
54
- displayValue: "Illinois"
55
- }, {
56
- value: "13",
57
- displayValue: "Indiana"
58
- }, {
59
- value: "14",
60
- displayValue: "Iowa"
61
- }, {
62
- value: "15",
63
- displayValue: "Kansas"
64
- }, {
65
- value: "16",
66
- displayValue: "Kentucky"
67
- }, {
68
- value: "17",
69
- displayValue: "Louisiana"
70
- }, {
71
- value: "18",
72
- displayValue: "Maine"
73
- }, {
74
- value: "19",
75
- displayValue: "Maryland"
76
- }, {
77
- value: "20",
78
- displayValue: "Massachusetts"
79
- }, {
80
- value: "21",
81
- displayValue: "Michigan"
82
- }, {
83
- value: "22",
84
- displayValue: "Minnesota"
85
- }, {
86
- value: "23",
87
- displayValue: "Mississippi"
88
- }, {
89
- value: "24",
90
- displayValue: "Missouri"
91
- }, {
92
- value: "25",
93
- displayValue: "Montana"
94
- }, {
95
- value: "26",
96
- displayValue: "Nebraska"
97
- }, {
98
- value: "27",
99
- displayValue: "Nevada"
100
- }, {
101
- value: "28",
102
- displayValue: "New Hampshire"
103
- }, {
104
- value: "29",
105
- displayValue: "New Jersey"
106
- }, {
107
- value: "30",
108
- displayValue: "New Mexico"
109
- }, {
110
- value: "31",
111
- displayValue: "New York"
112
- }, {
113
- value: "32",
114
- displayValue: "North Carolina"
115
- }, {
116
- value: "33",
117
- displayValue: "North Dakota"
118
- }, {
119
- value: "34",
120
- displayValue: "Ohio"
121
- }, {
122
- value: "35",
123
- displayValue: "Oklahoma"
124
- }, {
125
- value: "36",
126
- displayValue: "Oregon"
127
- }, {
128
- value: "37",
129
- displayValue: "Pennsylvania"
130
- }, {
131
- value: "38",
132
- displayValue: "Rhode Island"
133
- }, {
134
- value: "39",
135
- displayValue: "South Carolina"
136
- }, {
137
- value: "40",
138
- displayValue: "South Dakota"
139
- }, {
140
- value: "41",
141
- displayValue: "Tennessee"
142
- }, {
143
- value: "42",
144
- displayValue: "Texas"
145
- }, {
146
- value: "43",
147
- displayValue: "Utah"
148
- }, {
149
- value: "44",
150
- displayValue: "Vermont"
151
- }, {
152
- value: "45",
153
- displayValue: "Virginia"
154
- }, {
155
- value: "46",
156
- displayValue: "Washington"
157
- }, {
158
- value: "47",
159
- displayValue: "West Virginia"
160
- }, {
161
- value: "48",
162
- displayValue: "Wisconsin"
163
- }, {
164
- value: "49",
165
- displayValue: "Wyoming"
166
- }], h = (a) => r.find((e) => e.displayValue === a), n = 10, c = (a, e) => {
167
- const l = (parseInt(a, 10) || 0) * n, u = l + n;
168
- return e.slice(l, u).map(({
169
- displayValue: i,
170
- value: t
171
- }) => ({
172
- displayValue: i,
173
- value: t
174
- }));
175
- }, m = (a, e) => (parseInt(a, 10) || 0) * n + n < e.length ? ((parseInt(a, 10) || 0) + 1).toString() : void 0, w = /* @__PURE__ */ (() => {
176
- let a = 0;
177
- return async ({
178
- delay: e,
179
- signal: l,
180
- searchInput: u,
181
- marker: i,
182
- failOnLoadMore: t,
183
- failOnLoadMoreTimes: d = Number.MAX_SAFE_INTEGER,
184
- options: p = r
185
- }) => {
186
- if (e && await new Promise((s) => setTimeout(s, e)), l.aborted)
187
- return Promise.reject(new DOMException("Aborted", "AbortError"));
188
- if (t && i != null && a < d)
189
- return a += 1, Promise.reject();
190
- const o = p.filter(({
191
- displayValue: s,
192
- value: v
193
- }) => s ? s.toLowerCase().includes(u.toLowerCase()) : v.toLowerCase().includes(u.toLowerCase())), y = Promise.resolve({
194
- marker: m(i, o),
195
- options: c(i, o)
196
- });
197
- return V(await y);
198
- };
199
- })();
200
- export {
201
- x as ComboboxWithApiPagination,
202
- h as findState,
203
- w as mockFetcher,
204
- r as states
205
- };
1
+ import { t as e } from "../../../../chunks/combobox-with-api-pagination.js";
2
+ import { n as t, r as n, t as r } from "../../../../chunks/combobox-with-api-pagination2.js";
3
+ export { e as ComboboxWithApiPagination, r as findState, t as mockFetcher, n as states };
@@ -1,34 +1,32 @@
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
- }
1
+ import { defineMessages as e } from "react-intl";
2
+ var t = e({
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
31
  });
32
- export {
33
- e as default
34
- };
32
+ export { t as default };
@@ -1,6 +1,4 @@
1
- let C = /* @__PURE__ */ (function(E) {
2
- return E.NOT_STARTED = "NOT_STARTED", E.IN_PROGRESS = "IN_PROGRESS", E.ERROR = "ERROR", E.SUCCESS = "SUCCESS", E.CANCELLED = "CANCELLED", E;
3
- })({});
4
- export {
5
- C as RequestStates
6
- };
1
+ var e = /* @__PURE__ */ function(e) {
2
+ return e.NOT_STARTED = "NOT_STARTED", e.IN_PROGRESS = "IN_PROGRESS", e.ERROR = "ERROR", e.SUCCESS = "SUCCESS", e.CANCELLED = "CANCELLED", e;
3
+ }({});
4
+ export { e as RequestStates };
@@ -1,136 +1,121 @@
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
- }
1
+ import { RequestStates as e } from "./request.js";
2
+ import { isAbortError as t } from "./utils/is-abort-error.js";
3
+ import { useReducer as n } from "react";
4
+ var r = /* @__PURE__ */ function(e) {
5
+ return e.LOAD_MORE = "LOAD_MORE", e.RELOAD = "RELOAD", e.SEARCH = "SEARCH", e.SET_ERROR = "SET_ERROR", e.SET_LOADING = "SET_LOADING", e;
6
+ }(r || {});
7
+ function i(t, n) {
8
+ switch (n.type) {
9
+ case r.LOAD_MORE: return {
10
+ ...t,
11
+ abortController: n.abortController,
12
+ error: null,
13
+ items: [...t.items, ...n.items],
14
+ marker: n.marker,
15
+ requestState: e.SUCCESS
16
+ };
17
+ case r.RELOAD: return n.abortController === t.abortController ? {
18
+ ...t,
19
+ abortController: null,
20
+ error: null,
21
+ items: [...n.items],
22
+ marker: n.marker,
23
+ requestState: e.SUCCESS,
24
+ searchInput: ""
25
+ } : t;
26
+ case r.SEARCH: return {
27
+ ...t,
28
+ abortController: n.abortController,
29
+ error: null,
30
+ items: [...n.items],
31
+ marker: n.marker,
32
+ requestState: e.SUCCESS,
33
+ searchInput: n.searchInput ?? t.searchInput
34
+ };
35
+ case r.SET_ERROR: return {
36
+ ...t,
37
+ items: r.LOAD_MORE ? t.items : [],
38
+ error: n.error,
39
+ requestState: e.ERROR
40
+ };
41
+ case r.SET_LOADING: return {
42
+ ...t,
43
+ requestInitiator: n.requestInitiator,
44
+ requestState: e.IN_PROGRESS,
45
+ abortController: n.abortController
46
+ };
47
+ default: throw Error(`Invalid action type "${n.type}"`);
48
+ }
55
49
  }
56
- function E(r, e) {
57
- return r.type === s.SEARCH && e.requestState === u.IN_PROGRESS;
50
+ function a(t, n) {
51
+ return t.type === r.SEARCH && n.requestState === e.IN_PROGRESS;
58
52
  }
59
- function S(r, e) {
60
- return e.requestInitiator === s.LOAD_MORE && e.requestState === u.IN_PROGRESS && r.type === s.LOAD_MORE;
53
+ function o(t, n) {
54
+ return n.requestInitiator === r.LOAD_MORE && n.requestState === e.IN_PROGRESS && t.type === r.LOAD_MORE;
61
55
  }
62
- function m(r, e) {
63
- return E(r, e) || S(r, e);
56
+ function s(e, t) {
57
+ return a(e, t) || o(e, t);
64
58
  }
65
- function p(r, e) {
66
- E(r, e) && e.abortController.abort(), S(r, e) && r.abortController?.abort();
59
+ function c(e, t) {
60
+ a(e, t) && t.abortController.abort(), o(e, t) && e.abortController?.abort();
67
61
  }
68
- function h(r, e) {
69
- return S(r, e);
62
+ function l(e, t) {
63
+ return o(e, t);
70
64
  }
71
- async function R(r, e, t, n) {
72
- const o = new AbortController();
73
- if (m(r, t) && p(r, t), !h(r, t)) {
74
- n({
75
- type: s.SET_LOADING,
76
- requestInitiator: r.type,
77
- abortController: o
78
- });
79
- try {
80
- const l = await e({
81
- items: t.items.slice(),
82
- signal: o.signal,
83
- marker: r.type === s.LOAD_MORE ? t.marker : null,
84
- searchInput: r.searchInput ?? t.searchInput
85
- }), i = l.searchInput ?? r.searchInput ?? t.searchInput;
86
- n({
87
- type: r.type,
88
- ...l,
89
- searchInput: i,
90
- abortController: o
91
- });
92
- } catch (l) {
93
- if (I(l))
94
- return;
95
- n({
96
- type: s.SET_ERROR,
97
- error: l,
98
- abortController: o
99
- });
100
- }
101
- }
65
+ async function u(e, n, i, a) {
66
+ let o = new AbortController();
67
+ if (s(e, i) && c(e, i), !l(e, i)) {
68
+ a({
69
+ type: r.SET_LOADING,
70
+ requestInitiator: e.type,
71
+ abortController: o
72
+ });
73
+ try {
74
+ let t = await n({
75
+ items: i.items.slice(),
76
+ signal: o.signal,
77
+ marker: e.type === r.LOAD_MORE ? i.marker : null,
78
+ searchInput: e.searchInput ?? i.searchInput
79
+ }), s = t.searchInput ?? e.searchInput ?? i.searchInput;
80
+ a({
81
+ type: e.type,
82
+ ...t,
83
+ searchInput: s,
84
+ abortController: o
85
+ });
86
+ } catch (e) {
87
+ if (t(e)) return;
88
+ a({
89
+ type: r.SET_ERROR,
90
+ error: e,
91
+ abortController: o
92
+ });
93
+ }
94
+ }
102
95
  }
103
- function _(r) {
104
- const {
105
- load: e
106
- } = r, [t, n] = O(a, {
107
- error: null,
108
- items: [],
109
- requestInitiator: null,
110
- requestState: u.NOT_STARTED,
111
- searchInput: ""
112
- });
113
- return {
114
- hasError: t.requestState === u.ERROR,
115
- hasNextPage: t.requestState === u.ERROR ? !1 : t.marker != null,
116
- isEmpty: t.items.length === 0,
117
- isLoading: t.requestState === u.IN_PROGRESS,
118
- isReloading: t.requestState === u.IN_PROGRESS && (t.requestInitiator === s.RELOAD || t.requestInitiator === s.SEARCH),
119
- items: t.items,
120
- loadMore: () => R({
121
- type: s.LOAD_MORE
122
- }, e, t, n),
123
- reload: () => R({
124
- type: s.RELOAD
125
- }, e, t, n),
126
- requestInitiator: t.requestInitiator,
127
- searchInput: t.searchInput,
128
- search: (o) => R({
129
- type: s.SEARCH,
130
- searchInput: o
131
- }, e, t, n)
132
- };
96
+ function d(t) {
97
+ let { load: a } = t, [o, s] = n(i, {
98
+ error: null,
99
+ items: [],
100
+ requestInitiator: null,
101
+ requestState: e.NOT_STARTED,
102
+ searchInput: ""
103
+ });
104
+ return {
105
+ hasError: o.requestState === e.ERROR,
106
+ hasNextPage: o.requestState === e.ERROR ? !1 : o.marker != null,
107
+ isEmpty: o.items.length === 0,
108
+ isLoading: o.requestState === e.IN_PROGRESS,
109
+ isReloading: o.requestState === e.IN_PROGRESS && (o.requestInitiator === r.RELOAD || o.requestInitiator === r.SEARCH),
110
+ items: o.items,
111
+ loadMore: () => u({ type: r.LOAD_MORE }, a, o, s),
112
+ reload: () => u({ type: r.RELOAD }, a, o, s),
113
+ requestInitiator: o.requestInitiator,
114
+ searchInput: o.searchInput,
115
+ search: (e) => u({
116
+ type: r.SEARCH,
117
+ searchInput: e
118
+ }, a, o, s)
119
+ };
133
120
  }
134
- export {
135
- _ as useAsyncList
136
- };
121
+ export { d as useAsyncList };
@@ -1,13 +1,11 @@
1
- const o = "AbortError";
2
- function t(r) {
3
- return !!(r && r.__CANCEL__);
1
+ var e = "AbortError";
2
+ function t(e) {
3
+ return !!(e && e.__CANCEL__);
4
4
  }
5
- function n(r) {
6
- return !!(r && typeof r == "object" && r.name === o);
5
+ function n(t) {
6
+ return !!(t && typeof t == "object" && t.name === e);
7
7
  }
8
- function c(r) {
9
- return t(r) || n(r);
8
+ function r(e) {
9
+ return t(e) || n(e);
10
10
  }
11
- export {
12
- c as isAbortError
13
- };
11
+ export { r as isAbortError };
@@ -1,37 +1,35 @@
1
- import * as o from "react";
2
- function a(e) {
3
- const c = o.useRef(e);
4
- return o.useEffect(() => {
5
- c.current = e;
6
- }), o.useMemo(() => (...t) => c.current?.(...t), []);
1
+ import * as e from "react";
2
+ function t(t) {
3
+ let n = e.useRef(t);
4
+ return e.useEffect(() => {
5
+ n.current = t;
6
+ }), e.useMemo(() => ((...e) => n.current?.(...e)), []);
7
7
  }
8
- function v({
9
- prop: e,
10
- defaultProp: c,
11
- onChange: t = () => {
12
- }
13
- }) {
14
- const [n, s] = R({
15
- defaultProp: c,
16
- onChange: t
17
- }), r = e !== void 0, i = r ? e : n, l = a(t), d = o.useCallback((u) => {
18
- if (r) {
19
- const f = typeof u == "function" ? u(e) : u;
20
- f !== e && l(f);
21
- } else
22
- s(u);
23
- }, [r, e, s, l]);
24
- return [i, d];
8
+ function n({ prop: n, defaultProp: i, onChange: a = () => {} }) {
9
+ let [o, s] = r({
10
+ defaultProp: i,
11
+ onChange: a
12
+ }), c = n !== void 0, l = c ? n : o, u = t(a);
13
+ return [l, e.useCallback((e) => {
14
+ if (c) {
15
+ let t = typeof e == "function" ? e(n) : e;
16
+ t !== n && u(t);
17
+ } else s(e);
18
+ }, [
19
+ c,
20
+ n,
21
+ s,
22
+ u
23
+ ])];
25
24
  }
26
- function R({
27
- defaultProp: e,
28
- onChange: c
29
- }) {
30
- const t = o.useState(e), [n] = t, s = o.useRef(n), r = a(c);
31
- return o.useEffect(() => {
32
- s.current !== n && (r(n), s.current = n);
33
- }, [n, s, r]), t;
25
+ function r({ defaultProp: n, onChange: r }) {
26
+ let i = e.useState(n), [a] = i, o = e.useRef(a), s = t(r);
27
+ return e.useEffect(() => {
28
+ o.current !== a && (s(a), o.current = a);
29
+ }, [
30
+ a,
31
+ o,
32
+ s
33
+ ]), i;
34
34
  }
35
- export {
36
- v as useControllableState
37
- };
35
+ export { n as useControllableState };