@yamada-ui/autocomplete 2.0.0-next-20240703154117 → 2.0.0-next-20240705212157
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/autocomplete-create.js.map +1 -1
- package/dist/autocomplete-create.mjs +1 -1
- package/dist/autocomplete-empty.js.map +1 -1
- package/dist/autocomplete-empty.mjs +1 -1
- package/dist/autocomplete-icon.js.map +1 -1
- package/dist/autocomplete-icon.mjs +1 -1
- package/dist/autocomplete-list.js.map +1 -1
- package/dist/autocomplete-list.mjs +1 -1
- package/dist/autocomplete-option-group.d.mts +1 -1
- package/dist/autocomplete-option-group.d.ts +1 -1
- package/dist/autocomplete-option-group.js.map +1 -1
- package/dist/autocomplete-option-group.mjs +1 -1
- package/dist/autocomplete-option.d.mts +1 -1
- package/dist/autocomplete-option.d.ts +1 -1
- package/dist/autocomplete-option.js +1 -1
- package/dist/autocomplete-option.js.map +1 -1
- package/dist/autocomplete-option.mjs +1 -1
- package/dist/autocomplete.d.mts +1 -1
- package/dist/autocomplete.d.ts +1 -1
- package/dist/autocomplete.js +32 -25
- package/dist/autocomplete.js.map +1 -1
- package/dist/autocomplete.mjs +1 -1
- package/dist/{chunk-DQV3VPJ3.mjs → chunk-H6RHDTAI.mjs} +33 -26
- package/dist/chunk-H6RHDTAI.mjs.map +1 -0
- package/dist/index.d.mts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +32 -25
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1 -1
- package/dist/multi-autocomplete.d.mts +1 -1
- package/dist/multi-autocomplete.d.ts +1 -1
- package/dist/multi-autocomplete.js +32 -25
- package/dist/multi-autocomplete.js.map +1 -1
- package/dist/multi-autocomplete.mjs +1 -1
- package/dist/{use-autocomplete-D30tMc5q.d.mts → use-autocomplete-BdEEP0Ef.d.mts} +9 -4
- package/dist/{use-autocomplete-D30tMc5q.d.ts → use-autocomplete-BdEEP0Ef.d.ts} +9 -4
- package/dist/use-autocomplete.d.mts +1 -1
- package/dist/use-autocomplete.d.ts +1 -1
- package/dist/use-autocomplete.js +32 -25
- package/dist/use-autocomplete.js.map +1 -1
- package/dist/use-autocomplete.mjs +1 -1
- package/package.json +13 -13
- package/dist/chunk-DQV3VPJ3.mjs.map +0 -1
@@ -446,23 +446,26 @@ var useAutocomplete = ({
|
|
446
446
|
({ node, index }) => "target" in node.dataset && !selectedIndexes.includes(index)
|
447
447
|
);
|
448
448
|
const validChildren = (0, import_utils6.getValidChildren)(children);
|
449
|
-
const computedChildren =
|
450
|
-
|
451
|
-
|
452
|
-
|
453
|
-
|
454
|
-
|
455
|
-
|
456
|
-
|
457
|
-
|
458
|
-
|
459
|
-
|
460
|
-
|
461
|
-
|
462
|
-
|
463
|
-
|
464
|
-
|
465
|
-
|
449
|
+
const computedChildren = (0, import_react.useMemo)(
|
450
|
+
() => resolvedItems == null ? void 0 : resolvedItems.map((item, i) => {
|
451
|
+
if ("value" in item) {
|
452
|
+
const { label: label2, value: value2, ...props } = item;
|
453
|
+
return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(AutocompleteOption, { value: value2, ...props, children: label2 }, i);
|
454
|
+
} else if ("items" in item) {
|
455
|
+
const { label: label2, items: items2 = [], ...props } = item;
|
456
|
+
return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
|
457
|
+
AutocompleteOptionGroup,
|
458
|
+
{
|
459
|
+
label: label2,
|
460
|
+
...props,
|
461
|
+
children: items2.map(({ label: label3, value: value2, ...props2 }, i2) => /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(AutocompleteOption, { value: value2, ...props2, children: label3 }, i2))
|
462
|
+
},
|
463
|
+
i
|
464
|
+
);
|
465
|
+
}
|
466
|
+
}),
|
467
|
+
[resolvedItems]
|
468
|
+
);
|
466
469
|
const isEmpty = !validChildren.length && !(computedChildren == null ? void 0 : computedChildren.length);
|
467
470
|
const onOpen = (0, import_react.useCallback)(() => {
|
468
471
|
if (formControlProps.disabled || formControlProps.readOnly) return;
|
@@ -658,8 +661,9 @@ var useAutocomplete = ({
|
|
658
661
|
[allowFree, descendants]
|
659
662
|
);
|
660
663
|
const onChangeLabel = (0, import_react.useCallback)(
|
661
|
-
(newValue, runOmit = true) => {
|
664
|
+
(newValue, { forceUpdate, runOmit = true } = {}) => {
|
662
665
|
const selectedValues2 = getSelectedValues(newValue);
|
666
|
+
if (!forceUpdate && !selectedValues2.length) return;
|
663
667
|
setLabel((prev) => {
|
664
668
|
if (!isMulti) {
|
665
669
|
return selectedValues2[0];
|
@@ -679,7 +683,7 @@ var useAutocomplete = ({
|
|
679
683
|
[getSelectedValues, isMulti]
|
680
684
|
);
|
681
685
|
const onChange = (0, import_react.useCallback)(
|
682
|
-
(newValue, runRebirth = true) => {
|
686
|
+
(newValue, { forceUpdate, runRebirth = true } = {}) => {
|
683
687
|
setValue((prev) => {
|
684
688
|
let next;
|
685
689
|
if (!(0, import_utils6.isArray)(prev)) {
|
@@ -701,7 +705,7 @@ var useAutocomplete = ({
|
|
701
705
|
return format((_a = node.textContent) != null ? _a : "").includes(newValue);
|
702
706
|
}
|
703
707
|
).length > 0;
|
704
|
-
onChangeLabel(newValue);
|
708
|
+
onChangeLabel(newValue, { forceUpdate });
|
705
709
|
if (allowFree || isHit2) setInputValue("");
|
706
710
|
if (isMulti && runRebirth) rebirthOptions(false);
|
707
711
|
},
|
@@ -760,7 +764,7 @@ var useAutocomplete = ({
|
|
760
764
|
if (!listRef.current) return;
|
761
765
|
const newItem = { label: inputValue, value: inputValue };
|
762
766
|
let newItems = [];
|
763
|
-
if (resolvedItems) newItems = resolvedItems;
|
767
|
+
if (resolvedItems) newItems = [...resolvedItems];
|
764
768
|
if (firstInsertPositionItem === "first") {
|
765
769
|
newItems = [newItem, ...newItems];
|
766
770
|
} else if (firstInsertPositionItem === "last") {
|
@@ -819,7 +823,7 @@ var useAutocomplete = ({
|
|
819
823
|
const relatedTarget = (0, import_utils6.getEventRelatedTarget)(ev);
|
820
824
|
if ((0, import_utils6.isContains)(containerRef.current, relatedTarget)) return;
|
821
825
|
if (!closeOnBlur && isHit) return;
|
822
|
-
if (allowFree && !!inputValue) onChange(inputValue, false);
|
826
|
+
if (allowFree && !!inputValue) onChange(inputValue, { runRebirth: false });
|
823
827
|
setInputValue("");
|
824
828
|
if (isOpen) onClose();
|
825
829
|
},
|
@@ -827,7 +831,7 @@ var useAutocomplete = ({
|
|
827
831
|
);
|
828
832
|
const onDelete = (0, import_react.useCallback)(() => {
|
829
833
|
if (!isMulti) {
|
830
|
-
onChange("");
|
834
|
+
onChange("", { forceUpdate: true });
|
831
835
|
} else {
|
832
836
|
onChange(value[value.length - 1]);
|
833
837
|
}
|
@@ -923,7 +927,7 @@ var useAutocomplete = ({
|
|
923
927
|
setLabel(label2);
|
924
928
|
} else {
|
925
929
|
if (prevValue.current === value) return;
|
926
|
-
onChangeLabel(value, false);
|
930
|
+
onChangeLabel(value, { runOmit: false });
|
927
931
|
}
|
928
932
|
}, [isMulti, value, onChangeLabel, getSelectedValues]);
|
929
933
|
(0, import_utils6.useUpdateEffect)(() => {
|
@@ -934,6 +938,9 @@ var useAutocomplete = ({
|
|
934
938
|
(0, import_utils6.useUpdateEffect)(() => {
|
935
939
|
if (!isHit) setFocusedIndex(-2);
|
936
940
|
}, [isHit]);
|
941
|
+
(0, import_utils6.useUpdateEffect)(() => {
|
942
|
+
setResolvedItems(items ? JSON.parse(JSON.stringify(items)) : void 0);
|
943
|
+
}, [items]);
|
937
944
|
(0, import_utils6.useUnmountEffect)(() => {
|
938
945
|
timeoutIds.current.forEach((id2) => clearTimeout(id2));
|
939
946
|
timeoutIds.current.clear();
|
@@ -1274,7 +1281,7 @@ var useAutocompleteOption = (props) => {
|
|
1274
1281
|
]
|
1275
1282
|
);
|
1276
1283
|
(0, import_utils6.useUpdateEffect)(() => {
|
1277
|
-
if (isSelected) onChangeLabel(optionValue != null ? optionValue : "", false);
|
1284
|
+
if (isSelected) onChangeLabel(optionValue != null ? optionValue : "", { runOmit: false });
|
1278
1285
|
}, [optionValue]);
|
1279
1286
|
const getOptionProps = (0, import_react.useCallback)(
|
1280
1287
|
(props2 = {}, ref = null) => {
|