@yamada-ui/autocomplete 0.4.13 → 0.5.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/autocomplete-create.d.mts +1 -1
- package/dist/autocomplete-create.d.ts +1 -1
- package/dist/autocomplete-create.mjs +1 -1
- package/dist/autocomplete-empty.d.mts +1 -1
- package/dist/autocomplete-empty.d.ts +1 -1
- package/dist/autocomplete-empty.mjs +1 -1
- package/dist/autocomplete-icon.d.mts +2 -2
- package/dist/autocomplete-icon.d.ts +2 -2
- package/dist/autocomplete-icon.mjs +1 -1
- package/dist/autocomplete-list.d.mts +1 -1
- package/dist/autocomplete-list.d.ts +1 -1
- package/dist/autocomplete-list.mjs +1 -1
- package/dist/autocomplete-option-group.d.mts +2 -3
- package/dist/autocomplete-option-group.d.ts +2 -3
- package/dist/autocomplete-option-group.mjs +1 -1
- package/dist/autocomplete-option.d.mts +1 -2
- package/dist/autocomplete-option.d.ts +1 -2
- package/dist/autocomplete-option.mjs +1 -1
- package/dist/autocomplete.d.mts +5 -6
- package/dist/autocomplete.d.ts +5 -6
- package/dist/autocomplete.js +57 -60
- package/dist/autocomplete.mjs +1 -1
- package/dist/{chunk-EFOFI4S7.mjs → chunk-JKY5MMNC.mjs} +61 -64
- package/dist/index.d.mts +1 -2
- package/dist/index.d.ts +1 -2
- package/dist/index.js +61 -64
- package/dist/index.mjs +1 -1
- package/dist/multi-autocomplete.d.mts +5 -6
- package/dist/multi-autocomplete.d.ts +5 -6
- package/dist/multi-autocomplete.js +57 -60
- package/dist/multi-autocomplete.mjs +1 -1
- package/dist/{use-autocomplete-2422c1c8.d.ts → use-autocomplete-3e77a4da.d.ts} +31 -42
- package/dist/use-autocomplete.d.mts +1 -2
- package/dist/use-autocomplete.d.ts +1 -2
- package/dist/use-autocomplete.js +53 -56
- package/dist/use-autocomplete.mjs +1 -1
- package/package.json +3 -3
package/dist/use-autocomplete.js
CHANGED
|
@@ -303,20 +303,20 @@ var defaultFormat = (value) => {
|
|
|
303
303
|
value = value.toUpperCase();
|
|
304
304
|
return value;
|
|
305
305
|
};
|
|
306
|
-
var
|
|
307
|
-
const
|
|
308
|
-
|
|
306
|
+
var flattenItems = (items) => {
|
|
307
|
+
const filterItems = (items2) => items2.map((item) => {
|
|
308
|
+
var _a;
|
|
309
|
+
const { isDisabled, isFocusable } = item;
|
|
309
310
|
const trulyDisabled = !!isDisabled && !isFocusable;
|
|
310
|
-
const isMulti = (0, import_utils4.isArray)(value);
|
|
311
311
|
if (trulyDisabled)
|
|
312
312
|
return;
|
|
313
|
-
if (
|
|
314
|
-
return
|
|
313
|
+
if ("items" in item) {
|
|
314
|
+
return filterItems((_a = item.items) != null ? _a : []);
|
|
315
315
|
} else {
|
|
316
|
-
return
|
|
316
|
+
return item;
|
|
317
317
|
}
|
|
318
318
|
}).filter(Boolean);
|
|
319
|
-
return
|
|
319
|
+
return filterItems(items).flat(Infinity);
|
|
320
320
|
};
|
|
321
321
|
var isTargetOption = (target) => {
|
|
322
322
|
var _a;
|
|
@@ -339,14 +339,15 @@ var useAutocomplete = ({
|
|
|
339
339
|
maxSelectedValues,
|
|
340
340
|
closeOnBlur = true,
|
|
341
341
|
closeOnEsc = true,
|
|
342
|
-
|
|
343
|
-
|
|
342
|
+
allowCreate = false,
|
|
343
|
+
insertPositionItem = "first",
|
|
344
344
|
emptyMessage = "No results found",
|
|
345
345
|
format = defaultFormat,
|
|
346
346
|
placement = "bottom-start",
|
|
347
347
|
duration = 0.2,
|
|
348
348
|
optionProps,
|
|
349
349
|
placeholder,
|
|
350
|
+
items,
|
|
350
351
|
children,
|
|
351
352
|
...rest
|
|
352
353
|
}) => {
|
|
@@ -370,7 +371,7 @@ var useAutocomplete = ({
|
|
|
370
371
|
const inputRef = (0, import_react2.useRef)(null);
|
|
371
372
|
const timeoutIds = (0, import_react2.useRef)(/* @__PURE__ */ new Set([]));
|
|
372
373
|
const isComposition = (0, import_react2.useRef)(false);
|
|
373
|
-
const [
|
|
374
|
+
const [resolvedItems, setResolvedItems] = (0, import_react2.useState)(items);
|
|
374
375
|
const [value, setValue] = (0, import_use_controllable_state.useControllableState)({
|
|
375
376
|
value: rest.value,
|
|
376
377
|
defaultValue: rest.defaultValue,
|
|
@@ -383,19 +384,19 @@ var useAutocomplete = ({
|
|
|
383
384
|
const [isHit, setIsHit] = (0, import_react2.useState)(true);
|
|
384
385
|
const [isOpen, setIsOpen] = (0, import_react2.useState)(defaultIsOpen != null ? defaultIsOpen : false);
|
|
385
386
|
const isFocused = focusedIndex > -1;
|
|
386
|
-
const isCreate = focusedIndex === -2 &&
|
|
387
|
+
const isCreate = focusedIndex === -2 && allowCreate;
|
|
387
388
|
const isMulti = (0, import_utils4.isArray)(value);
|
|
388
389
|
const isEmptyValue = !isMulti ? !value : !value.length;
|
|
389
|
-
const [
|
|
390
|
-
if ((0, import_utils4.isArray)(
|
|
391
|
-
return
|
|
390
|
+
const [firstInsertPositionItem, secondInsertPositionItem] = (0, import_react2.useMemo)(() => {
|
|
391
|
+
if ((0, import_utils4.isArray)(insertPositionItem)) {
|
|
392
|
+
return insertPositionItem;
|
|
392
393
|
} else {
|
|
393
|
-
return [
|
|
394
|
+
return [insertPositionItem, "first"];
|
|
394
395
|
}
|
|
395
|
-
}, [
|
|
396
|
-
if (
|
|
396
|
+
}, [insertPositionItem]);
|
|
397
|
+
if (allowCreate && !(0, import_utils4.isUndefined)(children)) {
|
|
397
398
|
console.warn(
|
|
398
|
-
`${!isMulti ? "Autocomplete" : "MultiAutocomplete"}: ${!isMulti ? "Autocomplete" : "MultiAutocomplete"} internally prefers 'children'. If '
|
|
399
|
+
`${!isMulti ? "Autocomplete" : "MultiAutocomplete"}: ${!isMulti ? "Autocomplete" : "MultiAutocomplete"} internally prefers 'children'. If 'allowCreate' is true, it will not be reflected correctly. If want to reflect, please set 'items' in props.`
|
|
399
400
|
);
|
|
400
401
|
}
|
|
401
402
|
const selectedValues = descendants.enabledValues(
|
|
@@ -409,18 +410,18 @@ var useAutocomplete = ({
|
|
|
409
410
|
({ node, index }) => "target" in node.dataset && !selectedIndexes.includes(index)
|
|
410
411
|
);
|
|
411
412
|
const validChildren = (0, import_utils4.getValidChildren)(children);
|
|
412
|
-
const computedChildren =
|
|
413
|
-
if (
|
|
413
|
+
const computedChildren = resolvedItems == null ? void 0 : resolvedItems.map((item, i) => {
|
|
414
|
+
if ("value" in item) {
|
|
415
|
+
const { label, value: value2, ...props } = item;
|
|
414
416
|
return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(AutocompleteOption, { value: value2, ...props, children: label }, i);
|
|
415
|
-
} else {
|
|
417
|
+
} else if ("items" in item) {
|
|
418
|
+
const { label, items: items2 = [], ...props } = item;
|
|
416
419
|
return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
|
|
417
420
|
AutocompleteOptionGroup,
|
|
418
421
|
{
|
|
419
422
|
label,
|
|
420
423
|
...props,
|
|
421
|
-
children:
|
|
422
|
-
({ label: label2, value: value3, ...props2 }, i2) => !(0, import_utils4.isArray)(value3) ? /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(AutocompleteOption, { value: value3, ...props2, children: label2 }, i2) : null
|
|
423
|
-
)
|
|
424
|
+
children: items2.map(({ label: label2, value: value2, ...props2 }, i2) => /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(AutocompleteOption, { value: value2, ...props2, children: label2 }, i2))
|
|
424
425
|
},
|
|
425
426
|
i
|
|
426
427
|
);
|
|
@@ -431,13 +432,13 @@ var useAutocomplete = ({
|
|
|
431
432
|
var _a;
|
|
432
433
|
if (formControlProps.disabled || formControlProps.readOnly)
|
|
433
434
|
return;
|
|
434
|
-
if (!
|
|
435
|
+
if (!allowCreate && (isEmpty || isAllSelected))
|
|
435
436
|
return;
|
|
436
437
|
setIsOpen(true);
|
|
437
438
|
if (inputRef.current)
|
|
438
439
|
inputRef.current.focus();
|
|
439
440
|
(_a = rest.onOpen) == null ? void 0 : _a.call(rest);
|
|
440
|
-
}, [
|
|
441
|
+
}, [allowCreate, formControlProps, isAllSelected, isEmpty, rest]);
|
|
441
442
|
const onClose = (0, import_react2.useCallback)(() => {
|
|
442
443
|
var _a;
|
|
443
444
|
setIsOpen(false);
|
|
@@ -709,55 +710,51 @@ var useAutocomplete = ({
|
|
|
709
710
|
isComposition.current = false;
|
|
710
711
|
}, []);
|
|
711
712
|
const onCreate = (0, import_react2.useCallback)(() => {
|
|
712
|
-
var _a;
|
|
713
|
+
var _a, _b, _c;
|
|
713
714
|
if (!listRef.current)
|
|
714
715
|
return;
|
|
715
|
-
const
|
|
716
|
-
let
|
|
717
|
-
if (
|
|
718
|
-
|
|
719
|
-
if (
|
|
720
|
-
|
|
721
|
-
} else if (
|
|
722
|
-
|
|
716
|
+
const newItem = { label: inputValue, value: inputValue };
|
|
717
|
+
let newItems = [];
|
|
718
|
+
if (resolvedItems)
|
|
719
|
+
newItems = resolvedItems;
|
|
720
|
+
if (firstInsertPositionItem === "first") {
|
|
721
|
+
newItems = [newItem, ...newItems];
|
|
722
|
+
} else if (firstInsertPositionItem === "last") {
|
|
723
|
+
newItems = [...newItems, newItem];
|
|
723
724
|
} else {
|
|
724
|
-
const i =
|
|
725
|
-
({ label }) => label ===
|
|
725
|
+
const i = newItems.findIndex(
|
|
726
|
+
({ label }) => label === firstInsertPositionItem
|
|
726
727
|
);
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
...newOptions[i].value
|
|
732
|
-
];
|
|
728
|
+
const targetItem = newItems[i];
|
|
729
|
+
if (i !== -1 && "items" in targetItem) {
|
|
730
|
+
if (secondInsertPositionItem === "first") {
|
|
731
|
+
targetItem.items = [newItem, ...(_a = targetItem.items) != null ? _a : []];
|
|
733
732
|
} else {
|
|
734
|
-
|
|
735
|
-
...newOptions[i].value,
|
|
736
|
-
newOption
|
|
737
|
-
];
|
|
733
|
+
targetItem.items = [...(_b = targetItem.items) != null ? _b : [], newItem];
|
|
738
734
|
}
|
|
735
|
+
newItems[i] = targetItem;
|
|
739
736
|
} else {
|
|
740
737
|
console.warn(
|
|
741
|
-
`${!isMulti ? "Autocomplete" : "MultiAutocomplete"}: '${
|
|
738
|
+
`${!isMulti ? "Autocomplete" : "MultiAutocomplete"}: '${firstInsertPositionItem}' specified in insertPositionItem does not exist in the option group.`
|
|
742
739
|
);
|
|
743
740
|
}
|
|
744
741
|
}
|
|
745
|
-
|
|
742
|
+
setResolvedItems(newItems);
|
|
746
743
|
onChange(inputValue);
|
|
747
744
|
rebirthOptions(false);
|
|
748
|
-
const index =
|
|
745
|
+
const index = flattenItems(newItems).findIndex(
|
|
749
746
|
({ value: value2 }) => value2 === inputValue
|
|
750
747
|
);
|
|
751
748
|
setFocusedIndex(index);
|
|
752
|
-
(
|
|
749
|
+
(_c = rest.onCreate) == null ? void 0 : _c.call(rest, newItem, newItems);
|
|
753
750
|
}, [
|
|
754
751
|
inputValue,
|
|
755
|
-
|
|
756
|
-
|
|
752
|
+
resolvedItems,
|
|
753
|
+
firstInsertPositionItem,
|
|
757
754
|
onChange,
|
|
758
755
|
rebirthOptions,
|
|
759
756
|
rest,
|
|
760
|
-
|
|
757
|
+
secondInsertPositionItem,
|
|
761
758
|
isMulti
|
|
762
759
|
]);
|
|
763
760
|
const onDelete = (0, import_react2.useCallback)(() => {
|
|
@@ -944,7 +941,7 @@ var useAutocomplete = ({
|
|
|
944
941
|
focusedIndex,
|
|
945
942
|
omitSelectedValues,
|
|
946
943
|
closeOnSelect,
|
|
947
|
-
|
|
944
|
+
allowCreate,
|
|
948
945
|
emptyMessage,
|
|
949
946
|
isOpen,
|
|
950
947
|
isAllSelected,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@yamada-ui/autocomplete",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.0",
|
|
4
4
|
"description": "Yamada UI autocomplete component",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"yamada",
|
|
@@ -39,9 +39,9 @@
|
|
|
39
39
|
"@yamada-ui/core": "0.12.5",
|
|
40
40
|
"@yamada-ui/utils": "0.3.3",
|
|
41
41
|
"@yamada-ui/icon": "0.3.15",
|
|
42
|
-
"@yamada-ui/select": "0.
|
|
42
|
+
"@yamada-ui/select": "0.5.0",
|
|
43
43
|
"@yamada-ui/form-control": "0.3.18",
|
|
44
|
-
"@yamada-ui/popover": "0.3.
|
|
44
|
+
"@yamada-ui/popover": "0.3.20",
|
|
45
45
|
"@yamada-ui/use-descendant": "0.2.5",
|
|
46
46
|
"@yamada-ui/use-clickable": "0.3.5",
|
|
47
47
|
"@yamada-ui/use-outside-click": "0.2.5",
|