@box/combobox-with-api 2.1.35 → 2.1.37

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 (25) hide show
  1. package/dist/chunks/combobox-with-api-error.js +1 -18
  2. package/dist/chunks/combobox-with-api-pagination.js +1 -167
  3. package/dist/chunks/combobox-with-api-pagination2.js +1 -229
  4. package/dist/chunks/combobox-with-api-tree-view.js +1 -423
  5. package/dist/chunks/dynamic-loading-tree.js +1 -293
  6. package/dist/chunks/treeReducer.js +1 -60
  7. package/dist/esm/index.js +1 -6
  8. package/dist/esm/lib/components/combobox-with-api/combobox-with-api-container.js +1 -48
  9. package/dist/esm/lib/components/combobox-with-api/combobox-with-api-error.js +1 -2
  10. package/dist/esm/lib/components/combobox-with-api/combobox-with-api.js +1 -17
  11. package/dist/esm/lib/components/combobox-with-api/messages.js +1 -6
  12. package/dist/esm/lib/components/combobox-with-api-pagination/combobox-with-api-pagination.js +1 -2
  13. package/dist/esm/lib/components/combobox-with-api-pagination/index.js +1 -3
  14. package/dist/esm/lib/components/combobox-with-api-pagination/messages.js +1 -32
  15. package/dist/esm/lib/components/combobox-with-api-pagination/request.js +1 -4
  16. package/dist/esm/lib/components/combobox-with-api-pagination/use-async-list.js +1 -118
  17. package/dist/esm/lib/components/combobox-with-api-pagination/utils/is-abort-error.js +1 -11
  18. package/dist/esm/lib/components/combobox-with-api-pagination/utils/use-controllable-state.js +1 -35
  19. package/dist/esm/lib/components/combobox-with-api-pagination/utils/use-intersection-observer.js +1 -75
  20. package/dist/esm/lib/components/combobox-with-api-tree-view/combobox-with-api-tree-view.js +1 -134
  21. package/dist/esm/lib/components/combobox-with-api-tree-view/dynamic-loading-tree.js +1 -2
  22. package/dist/esm/lib/components/combobox-with-api-tree-view/index.js +1 -3
  23. package/dist/esm/lib/components/combobox-with-api-tree-view/tree-utils.js +1 -18
  24. package/dist/esm/lib/components/combobox-with-api-tree-view/treeReducer.js +1 -2
  25. package/package.json +7 -7
@@ -1,18 +1 @@
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 };
1
+ import messages from"../esm/lib/components/combobox-with-api/messages.js";import{Combobox,Text}from"@box/blueprint-web";import{forwardRef}from"react";import{FormattedMessage}from"react-intl";import{jsx}from"react/jsx-runtime";import '../styles/combobox-with-api-error.css';var combobox_with_api_error_module_default={container:`_container_1ozsi_1`},ComboboxWithApiError=forwardRef(({onTryAgain},forwardedRef)=>jsx(Combobox.Option,{onClick:onTryAgain,children:jsx(`div`,{ref:forwardedRef,className:combobox_with_api_error_module_default.container,children:jsx(Text,{as:`span`,color:`textOnLightLink`,children:jsx(FormattedMessage,{...messages.loadingResultsError})})})}));export{ComboboxWithApiError as t};
@@ -1,167 +1 @@
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
- disabled: "_disabled_9lkdk_27",
15
- highlightOptionText: "_highlightOptionText_9lkdk_31",
16
- selected: "_selected_9lkdk_53",
17
- option: "_option_9lkdk_73",
18
- errorComboboxOption: "_errorComboboxOption_9lkdk_77",
19
- errorComboboxOptionText: "_errorComboboxOptionText_9lkdk_82"
20
- }, D = /*#__PURE__*/ h(({ onTryAgain: t }, n) => {
21
- let { formatMessage: r } = S();
22
- return /* @__PURE__ */ T(C, { children: [/* @__PURE__ */ w(a, {
23
- variant: "error",
24
- variantIconAriaLabel: r(e.loadingResultsErrorIconLabel),
25
- children: /* @__PURE__ */ w(x, { ...e.loadingResultsErrorMessage })
26
- }), /* @__PURE__ */ w(i.Option, {
27
- ref: n,
28
- className: E.errorComboboxOption,
29
- onClick: t,
30
- children: /* @__PURE__ */ T(s, {
31
- as: "span",
32
- className: E.errorComboboxOptionText,
33
- color: "textOnLightLink",
34
- variant: "bodyDefaultBold",
35
- children: [/* @__PURE__ */ w(x, { ...e.loadingResultsErrorAction }), /* @__PURE__ */ w(l, {
36
- color: "currentColor",
37
- height: "12px",
38
- width: "12px"
39
- })]
40
- })
41
- })] });
42
- }), O = "__LOADING__", k = "__LOADING_ERROR__", te = "0px 0px 20px 0px", ne = /* @__PURE__ */ w(u, {
43
- color: d,
44
- height: p,
45
- role: "presentation",
46
- style: {
47
- padding: f,
48
- boxSizing: "border-box"
49
- },
50
- width: p
51
- }), A = /*#__PURE__*/ h(function(a, s) {
52
- 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 }) {
53
- let r = await u({
54
- signal: n,
55
- marker: e,
56
- searchInput: t
57
- });
58
- return {
59
- items: r.options,
60
- marker: r.marker
61
- };
62
- } }), V = y(!1), H = g(() => {
63
- V.current ||= (B.reload(), !0);
64
- }, []), [U, W] = n({
65
- prop: p,
66
- defaultProp: T,
67
- onChange: h
68
- }), G = !j && U.length === 1, K = G && !M, q = g((e) => {
69
- z(e), x?.(e);
70
- }, [x]), J = (e) => {
71
- 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))));
72
- }, 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) => {
73
- let { value: n, displayValue: r, ...a } = t;
74
- if (n === O) return B.hasNextPage ? /* @__PURE__ */ w(i.Option, {
75
- ...a,
76
- ref: oe,
77
- disabled: !0,
78
- value: n,
79
- children: /* @__PURE__ */ w(o, {
80
- "aria-label": F(e.loadingMoreAriaLabel),
81
- style: { position: "unset" }
82
- })
83
- }) : null;
84
- if (n === k && B.hasError && !B.isEmpty) return /* @__PURE__ */ w(D, { onTryAgain: () => {
85
- B.loadMore(), I.current?.focus();
86
- } });
87
- if (X.some((e) => e.value === n)) return null;
88
- let s = U.some((e) => e.value === n);
89
- return /* @__PURE__ */ w(i.Option, {
90
- ...a,
91
- className: E.option,
92
- value: n,
93
- children: /* @__PURE__ */ w(ee, {
94
- className: m(E.highlightOptionText, s && E.selected),
95
- value: r || n
96
- })
97
- });
98
- }, Z = (e) => {
99
- if (f?.(e), G && e === "") {
100
- L.current = !1;
101
- return;
102
- }
103
- B.search(e);
104
- }, ae = () => {
105
- B.reload(), I.current?.focus();
106
- }, Q;
107
- Q = B.hasError && !B.isLoading ? /* @__PURE__ */ w(D, { onTryAgain: ae }) : B.isEmpty && !B.isLoading ? C || F(e.noResults) : void 0;
108
- let [oe, { rootRef: se, isVisible: $ }] = r({ rootMargin: te });
109
- _(() => {
110
- if (!($ && B.hasNextPage)) return;
111
- let e = setTimeout(() => {
112
- B.loadMore();
113
- }, 100);
114
- return () => {
115
- clearTimeout(e);
116
- };
117
- }, [$]);
118
- let ce = v(() => {
119
- let e = B.hasNextPage ? {
120
- displayValue: O,
121
- value: O
122
- } : null, t = !e && B.hasError && !B.isEmpty ? {
123
- displayValue: k,
124
- value: k
125
- } : null;
126
- return [
127
- ...B.items,
128
- ...X,
129
- e,
130
- t
131
- ].filter(Boolean);
132
- }, [
133
- B.hasNextPage,
134
- B.hasError,
135
- B.isEmpty,
136
- B.items,
137
- X
138
- ]);
139
- return /* @__PURE__ */ w(i, {
140
- ...re,
141
- ref: c(I, s),
142
- as: "input",
143
- className: m(N, { [E.disabled]: K }),
144
- clearButtonAriaLabel: F(e.clearButtonAriaLabel),
145
- clearOnBlur: !1,
146
- "data-target-id": l,
147
- disabled: M || G && P,
148
- displaySingleSelectionAsChip: P,
149
- displayValue: (e) => e.displayValue || e.value,
150
- endComboboxIcon: ne,
151
- focusLoop: !1,
152
- getPopoverRef: se,
153
- loading: B.isReloading,
154
- loadingAriaLabel: A || F(e.loadingAriaLabel),
155
- multiselect: j,
156
- noResultMessage: Q,
157
- onFocus: H,
158
- onInputValueChange: Z,
159
- onOpenChange: q,
160
- onValueChange: J,
161
- open: R,
162
- options: ce,
163
- renderOption: ie,
164
- value: Y
165
- });
166
- });
167
- export { A as t };
1
+ import messages from"../esm/lib/components/combobox-with-api-pagination/messages.js";import{useAsyncList}from"../esm/lib/components/combobox-with-api-pagination/use-async-list.js";import{useControllableState}from"../esm/lib/components/combobox-with-api-pagination/utils/use-controllable-state.js";import{useTrackVisibility}from"../esm/lib/components/combobox-with-api-pagination/utils/use-intersection-observer.js";import{ComboboxItemValue}from"@ariakit/react";import{Combobox as Combobox$1,InlineNotice,LoadingIndicator,Text,useForkRef}from"@box/blueprint-web";import{Loader,Search}from"@box/blueprint-web-assets/icons/Fill";import{IconIconOnLightSecondary,Size1,Size6}from"@box/blueprint-web-assets/tokens/tokens";import clsx from"clsx";import{forwardRef,useCallback,useEffect,useMemo,useRef,useState}from"react";import{FormattedMessage,useIntl}from"react-intl";import{Fragment,jsx,jsxs}from"react/jsx-runtime";import '../styles/combobox-with-api-pagination.css';var combobox_with_api_pagination_module_default={disabled:`_disabled_9lkdk_27`,highlightOptionText:`_highlightOptionText_9lkdk_31`,selected:`_selected_9lkdk_53`,option:`_option_9lkdk_73`,errorComboboxOption:`_errorComboboxOption_9lkdk_77`,errorComboboxOptionText:`_errorComboboxOptionText_9lkdk_82`},ComboboxWithApiError=forwardRef(({onTryAgain},forwardedRef)=>{let{formatMessage}=useIntl();return jsxs(Fragment,{children:[jsx(InlineNotice,{variant:`error`,variantIconAriaLabel:formatMessage(messages.loadingResultsErrorIconLabel),children:jsx(FormattedMessage,{...messages.loadingResultsErrorMessage})}),jsx(Combobox$1.Option,{ref:forwardedRef,className:combobox_with_api_pagination_module_default.errorComboboxOption,onClick:onTryAgain,children:jsxs(Text,{as:`span`,className:combobox_with_api_pagination_module_default.errorComboboxOptionText,color:`textOnLightLink`,variant:`bodyDefaultBold`,children:[jsx(FormattedMessage,{...messages.loadingResultsErrorAction}),jsx(Loader,{color:`currentColor`,height:`12px`,width:`12px`})]})})]})}),LOAD_MORE_VALUE=`__LOADING__`,LOAD_MORE_ERROR_VALUE=`__LOADING_ERROR__`,INTERSECTION_ROOT_MARGIN=`0px 0px 20px 0px`,EndComboboxSearchIcon=jsx(Search,{color:IconIconOnLightSecondary,height:Size6,role:`presentation`,style:{padding:Size1,boxSizing:`border-box`},width:Size6}),ComboboxWithApiPagination=forwardRef(function(props,forwardedRef){let{dataTargetId,defaultFetcher,initialOpen=!1,onInputValueChange,value,onValueChange,onOpenChange,noResultMessage,defaultValue=[],loadingAriaLabel,multiselect=!1,disabled,className,displaySingleSelectionAsChip=!0,...rest}=props,{formatMessage}=useIntl(),inputRef=useRef(null),shouldFetchOnSearch=useRef(!0),[isOpen,setIsOpen]=useState(initialOpen),list=useAsyncList({async load({marker,searchInput,signal}){let res=await defaultFetcher({signal,marker,searchInput});return{items:res.options,marker:res.marker}}}),didDispatchInitialFetch=useRef(!1),fetchOptions=useCallback(()=>{didDispatchInitialFetch.current||=(list.reload(),!0)},[]),[selectedValue,setSelectedOption]=useControllableState({prop:value,defaultProp:defaultValue,onChange:onValueChange}),isSingleSelectValueSelected=!multiselect&&selectedValue.length===1,shouldOverrideInputStyles=isSingleSelectValueSelected&&!disabled,handleOpenChange=useCallback(newIsOpen=>{setIsOpen(newIsOpen),onOpenChange?.(newIsOpen)},[onOpenChange]),handleOnValueChange=selectedOptions=>{disabled||(selectedOptions===void 0?(setSelectedOption([]),(!shouldFetchOnSearch.current||!displaySingleSelectionAsChip)&&(list.search(``),shouldFetchOnSearch.current=!0)):Array.isArray(selectedOptions)?setSelectedOption(selectedOptions):(setSelectedOption([selectedOptions]),multiselect||(setIsOpen(!1),onOpenChange?.(!1))))},comboboxValue=useMemo(()=>selectedValue.length===0?multiselect?[]:void 0:multiselect?selectedValue:selectedValue[0],[multiselect,selectedValue]),selectedOptionsWithoutItems=useMemo(()=>selectedValue.filter(option=>!list.items.some(item=>item.value===option.value)),[selectedValue,list.items]),renderInfiniteOption=option=>{let{value:optionValue,displayValue,...optionRest}=option;if(optionValue===LOAD_MORE_VALUE)return list.hasNextPage?jsx(Combobox$1.Option,{...optionRest,ref:triggerRef,disabled:!0,value:optionValue,children:jsx(LoadingIndicator,{"aria-label":formatMessage(messages.loadingMoreAriaLabel),style:{position:`unset`}})}):null;if(optionValue===LOAD_MORE_ERROR_VALUE&&list.hasError&&!list.isEmpty)return jsx(ComboboxWithApiError,{onTryAgain:()=>{list.loadMore(),inputRef.current?.focus()}});if(selectedOptionsWithoutItems.some(optionWithoutItem=>optionWithoutItem.value===optionValue))return null;let isSelected=selectedValue.some(selectedOption=>selectedOption.value===optionValue);return jsx(Combobox$1.Option,{...optionRest,className:combobox_with_api_pagination_module_default.option,value:optionValue,children:jsx(ComboboxItemValue,{className:clsx(combobox_with_api_pagination_module_default.highlightOptionText,isSelected&&combobox_with_api_pagination_module_default.selected),value:displayValue||optionValue})})},handleOnInputValueChange=inputVal=>{if(onInputValueChange?.(inputVal),isSingleSelectValueSelected&&inputVal===``){shouldFetchOnSearch.current=!1;return}list.search(inputVal)},handleTryAgain=()=>{list.reload(),inputRef.current?.focus()},noResultMessageFromState;noResultMessageFromState=list.hasError&&!list.isLoading?jsx(ComboboxWithApiError,{onTryAgain:handleTryAgain}):list.isEmpty&&!list.isLoading?noResultMessage||formatMessage(messages.noResults):void 0;let[triggerRef,{rootRef:popoverRef,isVisible}]=useTrackVisibility({rootMargin:INTERSECTION_ROOT_MARGIN});useEffect(()=>{if(!(isVisible&&list.hasNextPage))return;let timer=setTimeout(()=>{list.loadMore()},100);return()=>{clearTimeout(timer)}},[isVisible]);let finalOptions=useMemo(()=>{let loadMoreOption=list.hasNextPage?{displayValue:LOAD_MORE_VALUE,value:LOAD_MORE_VALUE}:null,loadMoreErrorOption=!loadMoreOption&&list.hasError&&!list.isEmpty?{displayValue:LOAD_MORE_ERROR_VALUE,value:LOAD_MORE_ERROR_VALUE}:null;return[...list.items,...selectedOptionsWithoutItems,loadMoreOption,loadMoreErrorOption].filter(Boolean)},[list.hasNextPage,list.hasError,list.isEmpty,list.items,selectedOptionsWithoutItems]);return jsx(Combobox$1,{...rest,ref:useForkRef(inputRef,forwardedRef),as:`input`,className:clsx(className,{[combobox_with_api_pagination_module_default.disabled]:shouldOverrideInputStyles}),clearButtonAriaLabel:formatMessage(messages.clearButtonAriaLabel),clearOnBlur:!1,"data-target-id":dataTargetId,disabled:disabled||isSingleSelectValueSelected&&displaySingleSelectionAsChip,displaySingleSelectionAsChip,displayValue:option=>option.displayValue||option.value,endComboboxIcon:EndComboboxSearchIcon,focusLoop:!1,getPopoverRef:popoverRef,loading:list.isReloading,loadingAriaLabel:loadingAriaLabel||formatMessage(messages.loadingAriaLabel),multiselect,noResultMessage:noResultMessageFromState,onFocus:fetchOptions,onInputValueChange:handleOnInputValueChange,onOpenChange:handleOpenChange,onValueChange:handleOnValueChange,open:isOpen,options:finalOptions,renderOption:renderInfiniteOption,value:comboboxValue})});export{ComboboxWithApiPagination as t};
@@ -1,229 +1 @@
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 };
1
+ function mapResponse(response){return{marker:response.marker,options:response.options.map(({value,displayValue})=>displayValue?{displayValue,value}:{value})}}var states=[{value:`0`,displayValue:`Alabama`},{value:`1`,displayValue:`Alaska`},{value:`2`,displayValue:`Arizona`},{value:`3`,displayValue:`Arkansas`},{value:`4`,displayValue:`California`},{value:`5`,displayValue:`Colorado`},{value:`6`,displayValue:`Connecticut`},{value:`7`,displayValue:`Delaware`},{value:`8`,displayValue:`Florida`},{value:`9`,displayValue:`Georgia`},{value:`10`,displayValue:`Hawaii`},{value:`11`,displayValue:`Idaho`},{value:`12`,displayValue:`Illinois`},{value:`13`,displayValue:`Indiana`},{value:`14`,displayValue:`Iowa`},{value:`15`,displayValue:`Kansas`},{value:`16`,displayValue:`Kentucky`},{value:`17`,displayValue:`Louisiana`},{value:`18`,displayValue:`Maine`},{value:`19`,displayValue:`Maryland`},{value:`20`,displayValue:`Massachusetts`},{value:`21`,displayValue:`Michigan`},{value:`22`,displayValue:`Minnesota`},{value:`23`,displayValue:`Mississippi`},{value:`24`,displayValue:`Missouri`},{value:`25`,displayValue:`Montana`},{value:`26`,displayValue:`Nebraska`},{value:`27`,displayValue:`Nevada`},{value:`28`,displayValue:`New Hampshire`},{value:`29`,displayValue:`New Jersey`},{value:`30`,displayValue:`New Mexico`},{value:`31`,displayValue:`New York`},{value:`32`,displayValue:`North Carolina`},{value:`33`,displayValue:`North Dakota`},{value:`34`,displayValue:`Ohio`},{value:`35`,displayValue:`Oklahoma`},{value:`36`,displayValue:`Oregon`},{value:`37`,displayValue:`Pennsylvania`},{value:`38`,displayValue:`Rhode Island`},{value:`39`,displayValue:`South Carolina`},{value:`40`,displayValue:`South Dakota`},{value:`41`,displayValue:`Tennessee`},{value:`42`,displayValue:`Texas`},{value:`43`,displayValue:`Utah`},{value:`44`,displayValue:`Vermont`},{value:`45`,displayValue:`Virginia`},{value:`46`,displayValue:`Washington`},{value:`47`,displayValue:`West Virginia`},{value:`48`,displayValue:`Wisconsin`},{value:`49`,displayValue:`Wyoming`}],findState=name=>states.find(state=>state.displayValue===name),PAGE_SIZE=10,getOptions=(marker,options)=>{let startIndex=(parseInt(marker,10)||0)*PAGE_SIZE,endIndex=startIndex+PAGE_SIZE;return options.slice(startIndex,endIndex).map(({displayValue,value})=>({displayValue,value}))},getNextMarker=(marker,options)=>(parseInt(marker,10)||0)*PAGE_SIZE+PAGE_SIZE<options.length?((parseInt(marker,10)||0)+1).toString():void 0,mockFetcher=(()=>{let failedTimes=0;return async({delay,signal,searchInput,marker,failOnLoadMore,failOnLoadMoreTimes=2**53-1,options=states})=>{if(delay&&await new Promise(resolve=>setTimeout(resolve,delay)),signal.aborted)return Promise.reject(new DOMException(`Aborted`,`AbortError`));if(failOnLoadMore&&marker!=null&&failedTimes<failOnLoadMoreTimes)return failedTimes+=1,Promise.reject();let matchingWords=options.filter(({displayValue,value})=>displayValue?displayValue.toLowerCase().includes(searchInput.toLowerCase()):value.toLowerCase().includes(searchInput.toLowerCase()));return mapResponse(await Promise.resolve({marker:getNextMarker(marker,matchingWords),options:getOptions(marker,matchingWords)}))}})();export{mockFetcher as n,states as r,findState as t};