@availity/mui-autocomplete 2.2.7 → 3.0.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/dist/index.mjs DELETED
@@ -1,363 +0,0 @@
1
- var __defProp = Object.defineProperty;
2
- var __defProps = Object.defineProperties;
3
- var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
4
- var __getOwnPropSymbols = Object.getOwnPropertySymbols;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __propIsEnum = Object.prototype.propertyIsEnumerable;
7
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
8
- var __spreadValues = (a, b) => {
9
- for (var prop in b || (b = {}))
10
- if (__hasOwnProp.call(b, prop))
11
- __defNormalProp(a, prop, b[prop]);
12
- if (__getOwnPropSymbols)
13
- for (var prop of __getOwnPropSymbols(b)) {
14
- if (__propIsEnum.call(b, prop))
15
- __defNormalProp(a, prop, b[prop]);
16
- }
17
- return a;
18
- };
19
- var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
20
- var __objRest = (source, exclude) => {
21
- var target = {};
22
- for (var prop in source)
23
- if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
24
- target[prop] = source[prop];
25
- if (source != null && __getOwnPropSymbols)
26
- for (var prop of __getOwnPropSymbols(source)) {
27
- if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
28
- target[prop] = source[prop];
29
- }
30
- return target;
31
- };
32
- var __async = (__this, __arguments, generator) => {
33
- return new Promise((resolve, reject) => {
34
- var fulfilled = (value) => {
35
- try {
36
- step(generator.next(value));
37
- } catch (e) {
38
- reject(e);
39
- }
40
- };
41
- var rejected = (value) => {
42
- try {
43
- step(generator.throw(value));
44
- } catch (e) {
45
- reject(e);
46
- }
47
- };
48
- var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
49
- step((generator = generator.apply(__this, __arguments)).next());
50
- });
51
- };
52
-
53
- // src/lib/Autocomplete.tsx
54
- import { forwardRef } from "react";
55
- import {
56
- default as MuiAutocomplete
57
- } from "@mui/material/Autocomplete";
58
- import CircularProgress from "@mui/material/CircularProgress";
59
- import { default as MuiIconButton } from "@mui/material/IconButton";
60
- import { TextField } from "@availity/mui-textfield";
61
- import { SelectDivider, SelectExpandIcon } from "@availity/mui-form-utils";
62
- import { createFilterOptions } from "@mui/material/Autocomplete";
63
- import { Fragment, jsx, jsxs } from "react/jsx-runtime";
64
- var PopupIndicatorWrapper = forwardRef((props, ref) => /* @__PURE__ */ jsxs(Fragment, { children: [
65
- /* @__PURE__ */ jsx(SelectDivider, { orientation: "vertical", className: "MuiSelect-avEndAdornmentDivider" }),
66
- /* @__PURE__ */ jsx(MuiIconButton, __spreadProps(__spreadValues({}, props), { ref }))
67
- ] }));
68
- var progressSx = { marginRight: ".5rem" };
69
- var LoadingIndicator = () => /* @__PURE__ */ jsx(CircularProgress, { "aria-label": "Loading", size: 20, sx: progressSx });
70
- var Autocomplete = (_a) => {
71
- var _b = _a, {
72
- FieldProps
73
- } = _b, props = __objRest(_b, [
74
- "FieldProps"
75
- ]);
76
- const defaultProps = {
77
- fullWidth: true,
78
- size: "small"
79
- };
80
- const resolvedProps = (params) => ({
81
- InputProps: __spreadProps(__spreadValues(__spreadValues({}, params == null ? void 0 : params.InputProps), FieldProps == null ? void 0 : FieldProps.InputProps), {
82
- endAdornment: props.loading ? /* @__PURE__ */ jsxs(Fragment, { children: [
83
- (params == null ? void 0 : params.InputProps.endAdornment) || null,
84
- /* @__PURE__ */ jsx(LoadingIndicator, {})
85
- ] }) : (params == null ? void 0 : params.InputProps.endAdornment) || null
86
- }),
87
- inputProps: __spreadProps(__spreadValues({}, params == null ? void 0 : params.inputProps), {
88
- // appease the Level Access scanning tools
89
- "aria-controls": (params == null ? void 0 : params.inputProps["aria-controls"]) || ""
90
- })
91
- });
92
- return /* @__PURE__ */ jsx(
93
- MuiAutocomplete,
94
- __spreadValues(__spreadValues({
95
- renderInput: (params) => {
96
- return /* @__PURE__ */ jsx(TextField, __spreadValues(__spreadValues(__spreadValues({}, params), FieldProps), resolvedProps(params)));
97
- },
98
- popupIcon: /* @__PURE__ */ jsx(SelectExpandIcon, { className: "MuiSelect-avExpandIcon" }),
99
- slotProps: { popupIndicator: { component: PopupIndicatorWrapper } }
100
- }, props), defaultProps)
101
- );
102
- };
103
-
104
- // src/lib/AsyncAutocomplete.tsx
105
- import { useState as useState2, useRef, useEffect as useEffect2, useCallback } from "react";
106
- import { useInfiniteQuery } from "@tanstack/react-query";
107
-
108
- // src/lib/util.tsx
109
- import { useEffect, useState } from "react";
110
- var useDebounce = (value, delay) => {
111
- const [debouncedValue, setDebouncedValue] = useState("");
112
- useEffect(() => {
113
- const timer = setTimeout(() => {
114
- setDebouncedValue(value);
115
- }, delay);
116
- return () => {
117
- clearTimeout(timer);
118
- };
119
- }, [value]);
120
- return debouncedValue;
121
- };
122
-
123
- // src/lib/AsyncAutocomplete.tsx
124
- import { jsx as jsx2 } from "react/jsx-runtime";
125
- var AsyncAutocomplete = (_a) => {
126
- var _b = _a, {
127
- loadOptions,
128
- limit = 50,
129
- queryKey,
130
- ListboxProps,
131
- queryOptions,
132
- watchParams,
133
- debounceTimeout = 350,
134
- FieldProps,
135
- onInputChange,
136
- prependOptions = []
137
- } = _b, rest = __objRest(_b, [
138
- "loadOptions",
139
- "limit",
140
- "queryKey",
141
- "ListboxProps",
142
- "queryOptions",
143
- "watchParams",
144
- "debounceTimeout",
145
- "FieldProps",
146
- "onInputChange",
147
- "prependOptions"
148
- ]);
149
- const [inputValue, setInputValue] = useState2("");
150
- const listboxRef = useRef(null);
151
- const setListboxRef = useCallback((node) => {
152
- listboxRef.current = node;
153
- }, []);
154
- const handleInputPropsOnChange = (event) => {
155
- var _a2;
156
- setInputValue(event.target.value);
157
- if ((_a2 = FieldProps == null ? void 0 : FieldProps.InputProps) == null ? void 0 : _a2.onChange) FieldProps.InputProps.onChange(event);
158
- };
159
- const debouncedInput = useDebounce(inputValue, debounceTimeout);
160
- const { isLoading, isFetching, data, hasNextPage, fetchNextPage } = useInfiniteQuery(__spreadValues({
161
- queryKey: [queryKey, limit, debouncedInput, watchParams],
162
- queryFn: (_0) => __async(null, [_0], function* ({ pageParam = 0 }) {
163
- return loadOptions(pageParam, limit, debouncedInput);
164
- }),
165
- staleTime: 1e4,
166
- getNextPageParam: (lastPage) => lastPage.hasMore ? lastPage.offset + limit : void 0
167
- }, queryOptions));
168
- const options = (data == null ? void 0 : data.pages) ? data.pages.map((page) => page.options).flat() : [];
169
- const finalOptions = prependOptions.length > 0 ? [
170
- ...prependOptions,
171
- ...options.filter(
172
- (option) => !prependOptions.some(
173
- (prepended) => rest.isOptionEqualToValue ? rest.isOptionEqualToValue(option, prepended) : option === prepended
174
- )
175
- )
176
- ] : options;
177
- const handleOnInputChange = (event, value, reason) => {
178
- if (reason === "clear") {
179
- setInputValue(event.target.value);
180
- } else if (reason === "blur") {
181
- setInputValue(value);
182
- }
183
- if (onInputChange) onInputChange(event, value, reason);
184
- };
185
- const handleAddingOptions = (event) => __async(null, null, function* () {
186
- const listboxNode = event.currentTarget;
187
- const difference = listboxNode.scrollHeight - (listboxNode.scrollTop + listboxNode.clientHeight);
188
- if (difference <= 10 && !isLoading && !isFetching && hasNextPage) {
189
- fetchNextPage();
190
- }
191
- });
192
- useEffect2(() => {
193
- var _a2;
194
- if (hasNextPage) {
195
- (_a2 = listboxRef.current) == null ? void 0 : _a2.dispatchEvent(new UIEvent("scroll"));
196
- }
197
- }, [data == null ? void 0 : data.pages.length, hasNextPage]);
198
- return /* @__PURE__ */ jsx2(
199
- Autocomplete,
200
- __spreadProps(__spreadValues({}, rest), {
201
- onInputChange: handleOnInputChange,
202
- FieldProps: __spreadProps(__spreadValues({}, FieldProps), {
203
- InputProps: __spreadProps(__spreadValues({}, FieldProps == null ? void 0 : FieldProps.InputProps), {
204
- onChange: handleInputPropsOnChange
205
- })
206
- }),
207
- loading: isFetching,
208
- options: finalOptions,
209
- ListboxProps: __spreadProps(__spreadValues({}, ListboxProps), {
210
- ref: setListboxRef,
211
- onScroll: handleAddingOptions,
212
- onPointerEnter: handleAddingOptions
213
- })
214
- })
215
- );
216
- };
217
-
218
- // src/lib/CodesAutocomplete.tsx
219
- import { avCodesApi } from "@availity/api-axios";
220
- import { jsx as jsx3 } from "react/jsx-runtime";
221
- var fetchCodes = (config) => __async(null, null, function* () {
222
- const resp = yield avCodesApi.query(config);
223
- return {
224
- options: resp.data.codes,
225
- hasMore: config.params.offset + config.params.limit < resp.data.totalCount,
226
- offset: config.params.offset
227
- };
228
- });
229
- var handleGetCodesOptionLabel = (option) => [option.code, option.value].filter(Boolean).join(" - ");
230
- var CodesAutocomplete = (_a) => {
231
- var _b = _a, {
232
- apiConfig = {},
233
- queryOptions,
234
- queryKey = "codes-autocomplete",
235
- list,
236
- watchParams
237
- } = _b, rest = __objRest(_b, [
238
- "apiConfig",
239
- "queryOptions",
240
- "queryKey",
241
- "list",
242
- "watchParams"
243
- ]);
244
- const handleLoadOptions = (offset, limit, inputValue) => __async(null, null, function* () {
245
- const resp = yield fetchCodes(__spreadProps(__spreadValues({}, apiConfig), {
246
- params: __spreadProps(__spreadValues({}, apiConfig.params), { list, offset, limit, q: inputValue })
247
- }));
248
- return __spreadProps(__spreadValues({}, resp), {
249
- options: resp.options
250
- });
251
- });
252
- return /* @__PURE__ */ jsx3(
253
- AsyncAutocomplete,
254
- __spreadProps(__spreadValues({
255
- getOptionLabel: handleGetCodesOptionLabel,
256
- queryKey,
257
- queryOptions: __spreadValues({ enabled: !!list }, queryOptions),
258
- watchParams: __spreadValues({ list }, watchParams)
259
- }, rest), {
260
- loadOptions: handleLoadOptions
261
- })
262
- );
263
- };
264
-
265
- // src/lib/OrganizationAutocomplete.tsx
266
- import { avOrganizationsApi } from "@availity/api-axios";
267
- import qs from "qs";
268
- import { jsx as jsx4 } from "react/jsx-runtime";
269
- var fetchOrgs = (config) => __async(null, null, function* () {
270
- const configWithParamsSerializer = __spreadProps(__spreadValues({}, config), {
271
- paramsSerializer: {
272
- serialize: (params) => qs.stringify(params, { arrayFormat: "repeat" })
273
- }
274
- });
275
- const resp = yield avOrganizationsApi.getOrganizations(configWithParamsSerializer);
276
- return {
277
- options: resp.data.organizations,
278
- hasMore: config.params.offset + config.params.limit < resp.data.totalCount,
279
- offset: config.params.offset
280
- };
281
- });
282
- var handleGetOrgOptionLabel = (org) => org.name;
283
- var OrganizationAutocomplete = (_a) => {
284
- var _b = _a, {
285
- apiConfig = {},
286
- queryKey = "org-autocomplete"
287
- } = _b, rest = __objRest(_b, [
288
- "apiConfig",
289
- "queryKey"
290
- ]);
291
- const handleLoadOptions = (offset, limit) => __async(null, null, function* () {
292
- const resp = yield fetchOrgs(__spreadProps(__spreadValues({}, apiConfig), { params: __spreadProps(__spreadValues({ dropdown: true }, apiConfig.params), { offset, limit }) }));
293
- return __spreadProps(__spreadValues({}, resp), {
294
- options: resp.options
295
- });
296
- });
297
- return /* @__PURE__ */ jsx4(
298
- AsyncAutocomplete,
299
- __spreadProps(__spreadValues({
300
- getOptionLabel: handleGetOrgOptionLabel,
301
- queryKey
302
- }, rest), {
303
- loadOptions: handleLoadOptions
304
- })
305
- );
306
- };
307
-
308
- // src/lib/ProviderAutocomplete.tsx
309
- import { avProvidersApi } from "@availity/api-axios";
310
- import { jsx as jsx5 } from "react/jsx-runtime";
311
- var fetchProviders = (customerId, config) => __async(null, null, function* () {
312
- const resp = yield avProvidersApi.getProviders(customerId, config);
313
- return {
314
- options: resp.data.providers,
315
- hasMore: config.params.offset + config.params.limit < resp.data.totalCount,
316
- offset: config.params.offset
317
- };
318
- });
319
- var handleGetProviderOptionLabel = (option) => option.uiDisplayName;
320
- var ProviderAutocomplete = (_a) => {
321
- var _b = _a, {
322
- apiConfig = {},
323
- customerId,
324
- queryKey = "prov-autocomplete"
325
- } = _b, rest = __objRest(_b, [
326
- "apiConfig",
327
- "customerId",
328
- "queryKey"
329
- ]);
330
- const handleLoadOptions = (offset, limit, inputValue) => __async(null, null, function* () {
331
- const resp = yield fetchProviders(customerId, __spreadProps(__spreadValues({}, apiConfig), {
332
- params: __spreadProps(__spreadValues({}, apiConfig.params), { offset, limit, q: inputValue })
333
- }));
334
- return __spreadProps(__spreadValues({}, resp), {
335
- options: resp.options
336
- });
337
- });
338
- return /* @__PURE__ */ jsx5(
339
- AsyncAutocomplete,
340
- __spreadProps(__spreadValues({
341
- getOptionLabel: handleGetProviderOptionLabel,
342
- queryOptions: { enabled: !!customerId },
343
- queryKey,
344
- watchParams: { customerId }
345
- }, rest), {
346
- loadOptions: handleLoadOptions
347
- })
348
- );
349
- };
350
- export {
351
- AsyncAutocomplete,
352
- Autocomplete,
353
- CodesAutocomplete,
354
- OrganizationAutocomplete,
355
- ProviderAutocomplete,
356
- createFilterOptions,
357
- fetchCodes,
358
- fetchOrgs,
359
- fetchProviders,
360
- handleGetCodesOptionLabel,
361
- handleGetOrgOptionLabel,
362
- handleGetProviderOptionLabel
363
- };
package/jest.config.js DELETED
@@ -1,17 +0,0 @@
1
- const global = require('../../jest.config.global');
2
-
3
- module.exports = {
4
- ...global,
5
- displayName: 'autocomplete',
6
- coverageDirectory: '../../coverage/autocomplete',
7
- /* TODO: Update to latest Jest snapshotFormat
8
- * By default Nx has kept the older style of Jest Snapshot formats
9
- * to prevent breaking of any existing tests with snapshots.
10
- * It's recommend you update to the latest format.
11
- * You can do this by removing snapshotFormat property
12
- * and running tests with --update-snapshot flag.
13
- * Example: From within the project directory, run "nx test --update-snapshot"
14
- * More info: https://jestjs.io/docs/upgrading-to-jest29#snapshot-format
15
- */
16
- snapshotFormat: { escapeString: true, printBasicPrototype: true },
17
- };
@@ -1,10 +0,0 @@
1
- {
2
- "extends": "./tsconfig.json",
3
- "compilerOptions": {
4
- "outDir": "../../dist/out-tsc",
5
- "module": "commonjs",
6
- "types": ["jest", "node", "@testing-library/jest-dom"],
7
- "allowJs": true
8
- },
9
- "include": ["jest.config.ts", "**/*.test.js", "**/*.test.ts", "**/*.test.tsx", "**/*.d.ts"]
10
- }