@heroui/autocomplete 2.3.12 → 2.3.14

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.
@@ -0,0 +1,401 @@
1
+ "use client";
2
+ "use strict";
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __export = (target, all) => {
8
+ for (var name in all)
9
+ __defProp(target, name, { get: all[name], enumerable: true });
10
+ };
11
+ var __copyProps = (to, from, except, desc) => {
12
+ if (from && typeof from === "object" || typeof from === "function") {
13
+ for (let key of __getOwnPropNames(from))
14
+ if (!__hasOwnProp.call(to, key) && key !== except)
15
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
+ }
17
+ return to;
18
+ };
19
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
20
+
21
+ // src/use-autocomplete.ts
22
+ var use_autocomplete_exports = {};
23
+ __export(use_autocomplete_exports, {
24
+ useAutocomplete: () => useAutocomplete
25
+ });
26
+ module.exports = __toCommonJS(use_autocomplete_exports);
27
+ var import_system = require("@heroui/system");
28
+ var import_use_safe_layout_effect = require("@heroui/use-safe-layout-effect");
29
+ var import_theme = require("@heroui/theme");
30
+ var import_i18n = require("@react-aria/i18n");
31
+ var import_combobox = require("@react-stately/combobox");
32
+ var import_react_utils = require("@heroui/react-utils");
33
+ var import_react = require("react");
34
+ var import_shared_utils = require("@heroui/shared-utils");
35
+ var import_utils = require("@react-aria/utils");
36
+ var import_combobox2 = require("@react-aria/combobox");
37
+ var import_form = require("@heroui/form");
38
+ var import_aria_utils = require("@heroui/aria-utils");
39
+ function useAutocomplete(originalProps) {
40
+ var _a, _b, _c, _d, _e;
41
+ const globalContext = (0, import_system.useProviderContext)();
42
+ const { validationBehavior: formValidationBehavior } = (0, import_form.useSlottedContext)(import_form.FormContext) || {};
43
+ const [props, variantProps] = (0, import_system.mapPropsVariants)(originalProps, import_theme.autocomplete.variantKeys);
44
+ const disableAnimation = (_b = (_a = originalProps.disableAnimation) != null ? _a : globalContext == null ? void 0 : globalContext.disableAnimation) != null ? _b : false;
45
+ const isClearable = originalProps.disableClearable !== void 0 ? !originalProps.disableClearable : originalProps.isReadOnly ? false : originalProps.isClearable;
46
+ const {
47
+ ref,
48
+ as,
49
+ label,
50
+ isLoading,
51
+ menuTrigger = "focus",
52
+ filterOptions = {
53
+ sensitivity: "base"
54
+ },
55
+ children,
56
+ selectorIcon,
57
+ clearIcon,
58
+ scrollRef: scrollRefProp,
59
+ defaultFilter,
60
+ endContent,
61
+ allowsEmptyCollection = true,
62
+ shouldCloseOnBlur = true,
63
+ popoverProps = {},
64
+ inputProps: userInputProps = {},
65
+ scrollShadowProps = {},
66
+ listboxProps = {},
67
+ selectorButtonProps = {},
68
+ clearButtonProps = {},
69
+ showScrollIndicators = true,
70
+ allowsCustomValue = false,
71
+ isVirtualized,
72
+ maxListboxHeight = 256,
73
+ itemHeight = 32,
74
+ validationBehavior = (_c = formValidationBehavior != null ? formValidationBehavior : globalContext == null ? void 0 : globalContext.validationBehavior) != null ? _c : "native",
75
+ className,
76
+ classNames,
77
+ errorMessage,
78
+ onOpenChange,
79
+ onClose,
80
+ isReadOnly = false,
81
+ ...otherProps
82
+ } = props;
83
+ const { contains } = (0, import_i18n.useFilter)(filterOptions);
84
+ let state = (0, import_combobox.useComboBoxState)({
85
+ ...originalProps,
86
+ children,
87
+ menuTrigger,
88
+ validationBehavior,
89
+ shouldCloseOnBlur,
90
+ allowsEmptyCollection,
91
+ defaultFilter: defaultFilter && typeof defaultFilter === "function" ? defaultFilter : contains,
92
+ onOpenChange: (open, menuTrigger2) => {
93
+ onOpenChange == null ? void 0 : onOpenChange(open, menuTrigger2);
94
+ if (!open) {
95
+ onClose == null ? void 0 : onClose();
96
+ }
97
+ }
98
+ });
99
+ state = {
100
+ ...state,
101
+ ...isReadOnly && {
102
+ disabledKeys: /* @__PURE__ */ new Set([...state.collection.getKeys()])
103
+ }
104
+ };
105
+ const buttonRef = (0, import_react.useRef)(null);
106
+ const inputWrapperRef = (0, import_react.useRef)(null);
107
+ const listBoxRef = (0, import_react.useRef)(null);
108
+ const popoverRef = (0, import_react.useRef)(null);
109
+ const inputRef = (0, import_react_utils.useDOMRef)(ref);
110
+ const scrollShadowRef = (0, import_react_utils.useDOMRef)(scrollRefProp);
111
+ const {
112
+ buttonProps,
113
+ inputProps,
114
+ listBoxProps,
115
+ isInvalid: isAriaInvalid,
116
+ validationDetails,
117
+ validationErrors
118
+ } = (0, import_combobox2.useComboBox)(
119
+ {
120
+ validationBehavior,
121
+ ...originalProps,
122
+ inputRef,
123
+ buttonRef,
124
+ listBoxRef,
125
+ popoverRef
126
+ },
127
+ state
128
+ );
129
+ const isInvalid = originalProps.isInvalid || isAriaInvalid;
130
+ const slotsProps = {
131
+ inputProps: (0, import_utils.mergeProps)(
132
+ {
133
+ label,
134
+ ref: inputRef,
135
+ wrapperRef: inputWrapperRef,
136
+ onClick: () => {
137
+ if (!state.isOpen && !!state.selectedItem) {
138
+ state.open();
139
+ }
140
+ },
141
+ isClearable: false,
142
+ disableAnimation
143
+ },
144
+ userInputProps
145
+ ),
146
+ popoverProps: (0, import_utils.mergeProps)(
147
+ {
148
+ offset: 5,
149
+ placement: "bottom",
150
+ triggerScaleOnOpen: false,
151
+ disableAnimation
152
+ },
153
+ popoverProps
154
+ ),
155
+ scrollShadowProps: (0, import_utils.mergeProps)(
156
+ {
157
+ ref: scrollShadowRef,
158
+ isEnabled: (_d = showScrollIndicators && state.collection.size > 5) != null ? _d : true,
159
+ hideScrollBar: true,
160
+ offset: 15
161
+ },
162
+ scrollShadowProps
163
+ ),
164
+ listboxProps: (0, import_utils.mergeProps)(
165
+ {
166
+ hideEmptyContent: allowsCustomValue,
167
+ emptyContent: "No results found.",
168
+ disableAnimation
169
+ },
170
+ listboxProps
171
+ ),
172
+ selectorButtonProps: (0, import_utils.mergeProps)(
173
+ {
174
+ isLoading,
175
+ size: "sm",
176
+ variant: "light",
177
+ radius: "full",
178
+ color: isInvalid ? "danger" : originalProps == null ? void 0 : originalProps.color,
179
+ isIconOnly: true,
180
+ disableAnimation
181
+ },
182
+ selectorButtonProps
183
+ ),
184
+ clearButtonProps: (0, import_utils.mergeProps)(
185
+ {
186
+ size: "sm",
187
+ variant: "light",
188
+ radius: "full",
189
+ color: isInvalid ? "danger" : originalProps == null ? void 0 : originalProps.color,
190
+ isIconOnly: true,
191
+ disableAnimation
192
+ },
193
+ clearButtonProps
194
+ )
195
+ };
196
+ const baseStyles = (0, import_shared_utils.clsx)(classNames == null ? void 0 : classNames.base, className);
197
+ const isOpen = ((_e = slotsProps.listboxProps) == null ? void 0 : _e.hideEmptyContent) ? state.isOpen && !!state.collection.size : state.isOpen;
198
+ (0, import_use_safe_layout_effect.useSafeLayoutEffect)(() => {
199
+ if (!inputRef.current) return;
200
+ const key = inputRef.current.value;
201
+ const item = state.collection.getItem(key);
202
+ if (item && state.inputValue !== item.textValue) {
203
+ state.setSelectedKey(key);
204
+ state.setInputValue(item.textValue);
205
+ }
206
+ }, [inputRef.current]);
207
+ (0, import_react.useEffect)(() => {
208
+ let key = state.collection.getFirstKey();
209
+ while (key && state.disabledKeys.has(key)) {
210
+ key = state.collection.getKeyAfter(key);
211
+ }
212
+ state.selectionManager.setFocusedKey(key);
213
+ }, [state.collection, state.disabledKeys]);
214
+ (0, import_react.useEffect)(() => {
215
+ if (isOpen) {
216
+ if (popoverRef.current && inputWrapperRef.current) {
217
+ let rect = inputWrapperRef.current.getBoundingClientRect();
218
+ let popover = popoverRef.current;
219
+ popover.style.width = rect.width + "px";
220
+ }
221
+ }
222
+ }, [isOpen]);
223
+ if (inputProps.onKeyDown) {
224
+ const originalOnKeyDown = inputProps.onKeyDown;
225
+ inputProps.onKeyDown = (e) => {
226
+ if ("continuePropagation" in e) {
227
+ e.stopPropagation = () => {
228
+ };
229
+ }
230
+ return originalOnKeyDown(e);
231
+ };
232
+ }
233
+ const Component = as || "div";
234
+ const slots = (0, import_react.useMemo)(
235
+ () => (0, import_theme.autocomplete)({
236
+ ...variantProps,
237
+ isClearable,
238
+ disableAnimation
239
+ }),
240
+ [(0, import_shared_utils.objectToDeps)(variantProps), isClearable, disableAnimation]
241
+ );
242
+ const getBaseProps = () => ({
243
+ "data-invalid": (0, import_shared_utils.dataAttr)(isInvalid),
244
+ "data-open": (0, import_shared_utils.dataAttr)(state.isOpen),
245
+ className: slots.base({ class: baseStyles })
246
+ });
247
+ const getSelectorButtonProps = () => {
248
+ var _a2;
249
+ return {
250
+ ref: buttonRef,
251
+ ...(0, import_utils.mergeProps)(buttonProps, slotsProps.selectorButtonProps),
252
+ "data-open": (0, import_shared_utils.dataAttr)(state.isOpen),
253
+ className: slots.selectorButton({
254
+ class: (0, import_shared_utils.clsx)(classNames == null ? void 0 : classNames.selectorButton, (_a2 = slotsProps.selectorButtonProps) == null ? void 0 : _a2.className)
255
+ })
256
+ };
257
+ };
258
+ const getClearButtonProps = () => {
259
+ var _a2, _b2;
260
+ return {
261
+ ...(0, import_utils.mergeProps)(buttonProps, slotsProps.clearButtonProps),
262
+ // disable original focus and state toggle from react aria
263
+ onPressStart: () => {
264
+ var _a3;
265
+ (_a3 = inputRef.current) == null ? void 0 : _a3.focus();
266
+ },
267
+ onPress: (e) => {
268
+ var _a3, _b3;
269
+ (_b3 = (_a3 = slotsProps.clearButtonProps) == null ? void 0 : _a3.onPress) == null ? void 0 : _b3.call(_a3, e);
270
+ if (state.selectedItem) {
271
+ state.setSelectedKey(null);
272
+ }
273
+ state.setInputValue("");
274
+ state.open();
275
+ },
276
+ "data-visible": !!state.selectedItem || ((_a2 = state.inputValue) == null ? void 0 : _a2.length) > 0,
277
+ className: slots.clearButton({
278
+ class: (0, import_shared_utils.clsx)(classNames == null ? void 0 : classNames.clearButton, (_b2 = slotsProps.clearButtonProps) == null ? void 0 : _b2.className)
279
+ })
280
+ };
281
+ };
282
+ const hasUncommittedValidation = validationBehavior === "native" && state.displayValidation.isInvalid === false && state.realtimeValidation.isInvalid === true;
283
+ const getInputProps = () => ({
284
+ ...otherProps,
285
+ ...inputProps,
286
+ ...slotsProps.inputProps,
287
+ isInvalid: hasUncommittedValidation ? void 0 : isInvalid,
288
+ validationBehavior,
289
+ errorMessage: typeof errorMessage === "function" ? errorMessage({ isInvalid, validationErrors, validationDetails }) : errorMessage || (validationErrors == null ? void 0 : validationErrors.join(" ")),
290
+ onClick: (0, import_utils.chain)(slotsProps.inputProps.onClick, otherProps.onClick)
291
+ });
292
+ const getListBoxProps = () => {
293
+ const shouldVirtualize = isVirtualized != null ? isVirtualized : state.collection.size > 50;
294
+ return {
295
+ state,
296
+ ref: listBoxRef,
297
+ isVirtualized: shouldVirtualize,
298
+ virtualization: shouldVirtualize ? {
299
+ maxListboxHeight,
300
+ itemHeight
301
+ } : void 0,
302
+ scrollShadowProps: slotsProps.scrollShadowProps,
303
+ ...(0, import_utils.mergeProps)(slotsProps.listboxProps, listBoxProps, {
304
+ shouldHighlightOnFocus: true
305
+ })
306
+ };
307
+ };
308
+ const getPopoverProps = (props2 = {}) => {
309
+ var _a2, _b2, _c2;
310
+ const popoverProps2 = (0, import_utils.mergeProps)(slotsProps.popoverProps, props2);
311
+ return {
312
+ state,
313
+ ref: popoverRef,
314
+ triggerRef: inputWrapperRef,
315
+ scrollRef: listBoxRef,
316
+ triggerType: "listbox",
317
+ ...popoverProps2,
318
+ classNames: {
319
+ ...(_a2 = slotsProps.popoverProps) == null ? void 0 : _a2.classNames,
320
+ content: slots.popoverContent({
321
+ class: (0, import_shared_utils.clsx)(
322
+ classNames == null ? void 0 : classNames.popoverContent,
323
+ (_c2 = (_b2 = slotsProps.popoverProps) == null ? void 0 : _b2.classNames) == null ? void 0 : _c2["content"],
324
+ props2.className
325
+ )
326
+ })
327
+ },
328
+ shouldCloseOnInteractOutside: (popoverProps2 == null ? void 0 : popoverProps2.shouldCloseOnInteractOutside) ? popoverProps2.shouldCloseOnInteractOutside : (element) => (0, import_aria_utils.ariaShouldCloseOnInteractOutside)(element, inputWrapperRef, state),
329
+ // when the popover is open, the focus should be on input instead of dialog
330
+ // therefore, we skip dialog focus here
331
+ disableDialogFocus: true
332
+ };
333
+ };
334
+ const getEmptyPopoverProps = () => {
335
+ return {
336
+ ref: popoverRef,
337
+ className: "hidden"
338
+ };
339
+ };
340
+ const getListBoxWrapperProps = (props2 = {}) => {
341
+ var _a2, _b2;
342
+ return {
343
+ ...(0, import_utils.mergeProps)(slotsProps.scrollShadowProps, props2),
344
+ className: slots.listboxWrapper({
345
+ class: (0, import_shared_utils.clsx)(
346
+ classNames == null ? void 0 : classNames.listboxWrapper,
347
+ (_a2 = slotsProps.scrollShadowProps) == null ? void 0 : _a2.className,
348
+ props2 == null ? void 0 : props2.className
349
+ )
350
+ }),
351
+ style: {
352
+ maxHeight: (_b2 = originalProps.maxListboxHeight) != null ? _b2 : 256
353
+ }
354
+ };
355
+ };
356
+ const getEndContentWrapperProps = (props2 = {}) => ({
357
+ className: slots.endContentWrapper({
358
+ class: (0, import_shared_utils.clsx)(classNames == null ? void 0 : classNames.endContentWrapper, props2 == null ? void 0 : props2.className)
359
+ }),
360
+ onPointerDown: (0, import_utils.chain)(props2.onPointerDown, (e) => {
361
+ var _a2;
362
+ if (e.button === 0 && e.currentTarget === e.target) {
363
+ (_a2 = inputRef.current) == null ? void 0 : _a2.focus();
364
+ }
365
+ }),
366
+ onMouseDown: (0, import_utils.chain)(props2.onMouseDown, (e) => {
367
+ if (e.button === 0 && e.currentTarget === e.target) {
368
+ e.preventDefault();
369
+ }
370
+ })
371
+ });
372
+ return {
373
+ Component,
374
+ inputRef,
375
+ label,
376
+ state,
377
+ slots,
378
+ classNames,
379
+ isLoading,
380
+ clearIcon,
381
+ isOpen,
382
+ endContent,
383
+ isClearable,
384
+ disableAnimation,
385
+ allowsCustomValue,
386
+ selectorIcon,
387
+ getBaseProps,
388
+ getInputProps,
389
+ getListBoxProps,
390
+ getPopoverProps,
391
+ getEmptyPopoverProps,
392
+ getClearButtonProps,
393
+ getSelectorButtonProps,
394
+ getListBoxWrapperProps,
395
+ getEndContentWrapperProps
396
+ };
397
+ }
398
+ // Annotate the CommonJS export names for ESM import in node:
399
+ 0 && (module.exports = {
400
+ useAutocomplete
401
+ });
@@ -0,0 +1,7 @@
1
+ "use client";
2
+ import {
3
+ useAutocomplete
4
+ } from "./chunk-OHYOYGT2.mjs";
5
+ export {
6
+ useAutocomplete
7
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@heroui/autocomplete",
3
- "version": "2.3.12",
3
+ "version": "2.3.14",
4
4
  "description": "An autocomplete combines a text input with a listbox, allowing users to filter a list of options to items matching a query.",
5
5
  "keywords": [
6
6
  "autocomplete"
@@ -41,19 +41,19 @@
41
41
  "@react-stately/combobox": "3.10.2",
42
42
  "@react-types/combobox": "3.13.2",
43
43
  "@react-types/shared": "3.27.0",
44
- "@heroui/form": "2.1.10",
45
- "@heroui/aria-utils": "2.2.9",
46
- "@heroui/button": "2.2.11",
47
- "@heroui/input": "2.4.11",
48
- "@heroui/listbox": "2.3.11",
49
- "@heroui/popover": "2.3.11",
50
- "@heroui/react-utils": "2.1.5",
51
- "@heroui/scroll-shadow": "2.3.7",
52
- "@heroui/shared-icons": "2.1.3",
53
- "@heroui/shared-utils": "2.1.4",
54
- "@heroui/spinner": "2.2.8",
55
- "@heroui/use-aria-button": "2.2.6",
56
- "@heroui/use-safe-layout-effect": "2.1.3"
44
+ "@heroui/form": "2.1.12",
45
+ "@heroui/aria-utils": "2.2.11",
46
+ "@heroui/button": "2.2.13",
47
+ "@heroui/input": "2.4.13",
48
+ "@heroui/listbox": "2.3.13",
49
+ "@heroui/popover": "2.3.13",
50
+ "@heroui/react-utils": "2.1.7",
51
+ "@heroui/scroll-shadow": "2.3.9",
52
+ "@heroui/shared-icons": "2.1.5",
53
+ "@heroui/shared-utils": "2.1.6",
54
+ "@heroui/spinner": "2.2.10",
55
+ "@heroui/use-aria-button": "2.2.8",
56
+ "@heroui/use-safe-layout-effect": "2.1.5"
57
57
  },
58
58
  "clean-package": "../../../clean-package.config.json",
59
59
  "module": "dist/index.mjs",