@yamada-ui/autocomplete 0.1.9 → 0.1.11
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.mjs +1 -1
- package/dist/autocomplete-empty.mjs +1 -1
- package/dist/autocomplete-icon.mjs +1 -1
- package/dist/autocomplete-list.js +2 -0
- package/dist/autocomplete-list.mjs +1 -1
- package/dist/autocomplete-option-group.d.ts +1 -1
- package/dist/autocomplete-option-group.mjs +1 -1
- package/dist/autocomplete-option.d.ts +1 -1
- package/dist/autocomplete-option.mjs +1 -1
- package/dist/autocomplete.d.ts +1 -1
- package/dist/autocomplete.js +24 -22
- package/dist/autocomplete.mjs +1 -1
- package/dist/{chunk-UJYX53L6.mjs → chunk-YQULJUTP.mjs} +24 -22
- package/dist/index.d.ts +1 -1
- package/dist/index.js +24 -22
- package/dist/index.mjs +1 -1
- package/dist/multi-autocomplete.d.ts +1 -1
- package/dist/multi-autocomplete.js +24 -22
- package/dist/multi-autocomplete.mjs +1 -1
- package/dist/{use-autocomplete-2e4e8207.d.ts → use-autocomplete-4995431c.d.ts} +1 -1
- package/dist/use-autocomplete.d.ts +1 -1
- package/dist/use-autocomplete.js +24 -22
- package/dist/use-autocomplete.mjs +1 -1
- package/package.json +6 -6
|
@@ -58,6 +58,8 @@ var useAutocompleteList = () => {
|
|
|
58
58
|
(0, import_react.useEffect)(() => {
|
|
59
59
|
if (!listRef.current || !selectedValue)
|
|
60
60
|
return;
|
|
61
|
+
if (beforeFocusedIndex.current === selectedValue.index)
|
|
62
|
+
return;
|
|
61
63
|
const parent = listRef.current;
|
|
62
64
|
const child = selectedValue.node;
|
|
63
65
|
const parentHeight = parent.clientHeight;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as _yamada_ui_core from '@yamada-ui/core';
|
|
2
2
|
import { HTMLUIProps } from '@yamada-ui/core';
|
|
3
|
-
import { U as UseAutocompleteOptionGroupProps } from './use-autocomplete-
|
|
3
|
+
import { U as UseAutocompleteOptionGroupProps } from './use-autocomplete-4995431c.js';
|
|
4
4
|
import 'react/jsx-runtime';
|
|
5
5
|
import 'react';
|
|
6
6
|
import '@yamada-ui/form-control';
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import '@yamada-ui/core';
|
|
2
2
|
import 'react';
|
|
3
|
-
export { a as AutocompleteOption, A as AutocompleteOptionProps } from './use-autocomplete-
|
|
3
|
+
export { a as AutocompleteOption, A as AutocompleteOptionProps } from './use-autocomplete-4995431c.js';
|
|
4
4
|
import 'react/jsx-runtime';
|
|
5
5
|
import '@yamada-ui/form-control';
|
|
6
6
|
import '@yamada-ui/popover';
|
package/dist/autocomplete.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import * as _yamada_ui_core from '@yamada-ui/core';
|
|
|
2
2
|
import { ThemeProps, HTMLUIProps } from '@yamada-ui/core';
|
|
3
3
|
import { AutocompleteIconProps } from './autocomplete-icon.js';
|
|
4
4
|
import { AutocompleteListProps } from './autocomplete-list.js';
|
|
5
|
-
import { b as UseAutocompleteProps } from './use-autocomplete-
|
|
5
|
+
import { b as UseAutocompleteProps } from './use-autocomplete-4995431c.js';
|
|
6
6
|
import 'react';
|
|
7
7
|
import 'react/jsx-runtime';
|
|
8
8
|
import '@yamada-ui/form-control';
|
package/dist/autocomplete.js
CHANGED
|
@@ -343,20 +343,20 @@ var defaultFormat = (value) => {
|
|
|
343
343
|
value = value.toUpperCase();
|
|
344
344
|
return value;
|
|
345
345
|
};
|
|
346
|
-
var
|
|
347
|
-
const
|
|
348
|
-
const { value, isDisabled, isFocusable } =
|
|
346
|
+
var flattenOptions = (options) => {
|
|
347
|
+
const filterOptions = (options2) => options2.map((options3) => {
|
|
348
|
+
const { value, isDisabled, isFocusable } = options3;
|
|
349
349
|
const trulyDisabled = !!isDisabled && !isFocusable;
|
|
350
350
|
const isMulti = (0, import_utils6.isArray)(value);
|
|
351
351
|
if (trulyDisabled)
|
|
352
352
|
return;
|
|
353
353
|
if (!isMulti) {
|
|
354
|
-
return
|
|
354
|
+
return options3;
|
|
355
355
|
} else {
|
|
356
|
-
return
|
|
356
|
+
return filterOptions(value);
|
|
357
357
|
}
|
|
358
358
|
}).filter(Boolean);
|
|
359
|
-
return
|
|
359
|
+
return filterOptions(options).flat(Infinity);
|
|
360
360
|
};
|
|
361
361
|
var isTargetOption = (target) => {
|
|
362
362
|
var _a;
|
|
@@ -404,7 +404,7 @@ var useAutocomplete = ({
|
|
|
404
404
|
const inputRef = (0, import_react.useRef)(null);
|
|
405
405
|
const timeoutIds = (0, import_react.useRef)(/* @__PURE__ */ new Set([]));
|
|
406
406
|
const isComposition = (0, import_react.useRef)(false);
|
|
407
|
-
const [
|
|
407
|
+
const [options, setOptions] = (0, import_react.useState)(rest.options);
|
|
408
408
|
const [value, setValue] = (0, import_use_controllable_state.useControllableState)({
|
|
409
409
|
value: rest.value,
|
|
410
410
|
defaultValue: rest.defaultValue,
|
|
@@ -422,7 +422,7 @@ var useAutocomplete = ({
|
|
|
422
422
|
const isEmptyValue = !isMulti ? !value : !value.length;
|
|
423
423
|
if (createOption && !(0, import_utils6.isUndefined)(children)) {
|
|
424
424
|
console.warn(
|
|
425
|
-
`${!isMulti ? "Autocomplete" : "MultiAutocomplete"}: ${!isMulti ? "Autocomplete" : "MultiAutocomplete"} internally prefers 'children'. If 'createOption' is true, it will not be reflected correctly. If want to reflect, please set '
|
|
425
|
+
`${!isMulti ? "Autocomplete" : "MultiAutocomplete"}: ${!isMulti ? "Autocomplete" : "MultiAutocomplete"} internally prefers 'children'. If 'createOption' is true, it will not be reflected correctly. If want to reflect, please set 'options' in props.`
|
|
426
426
|
);
|
|
427
427
|
}
|
|
428
428
|
const selectedValues = descendants.enabledValues(
|
|
@@ -436,7 +436,7 @@ var useAutocomplete = ({
|
|
|
436
436
|
({ node, index }) => "target" in node.dataset && !selectedIndexes.includes(index)
|
|
437
437
|
);
|
|
438
438
|
const validChildren = (0, import_utils6.getValidChildren)(children);
|
|
439
|
-
const computedChildren =
|
|
439
|
+
const computedChildren = options == null ? void 0 : options.map(({ label, value: value2, ...props }, i) => {
|
|
440
440
|
if (!(0, import_utils6.isArray)(value2)) {
|
|
441
441
|
return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(AutocompleteOption, { value: value2, ...props, children: label }, i);
|
|
442
442
|
} else {
|
|
@@ -700,20 +700,20 @@ var useAutocomplete = ({
|
|
|
700
700
|
if (!listRef.current)
|
|
701
701
|
return;
|
|
702
702
|
const newOption = { label: inputValue, value: inputValue };
|
|
703
|
-
let
|
|
704
|
-
if (
|
|
705
|
-
|
|
703
|
+
let newOptions = [];
|
|
704
|
+
if (options)
|
|
705
|
+
newOptions = options;
|
|
706
706
|
if (createOrder === "first") {
|
|
707
|
-
|
|
707
|
+
newOptions = [newOption, ...newOptions];
|
|
708
708
|
} else if (createOrder === "last") {
|
|
709
|
-
|
|
709
|
+
newOptions = [...newOptions, newOption];
|
|
710
710
|
} else {
|
|
711
|
-
const i =
|
|
712
|
-
if (i !== -1 && (0, import_utils6.isArray)(
|
|
711
|
+
const i = newOptions.findIndex(({ label }) => label === createOrder);
|
|
712
|
+
if (i !== -1 && (0, import_utils6.isArray)(newOptions[i].value)) {
|
|
713
713
|
if (createSecondOrder === "first") {
|
|
714
|
-
|
|
714
|
+
newOptions[i].value = [newOption, ...newOptions[i].value];
|
|
715
715
|
} else {
|
|
716
|
-
|
|
716
|
+
newOptions[i].value = [...newOptions[i].value, newOption];
|
|
717
717
|
}
|
|
718
718
|
} else {
|
|
719
719
|
console.warn(
|
|
@@ -721,13 +721,13 @@ var useAutocomplete = ({
|
|
|
721
721
|
);
|
|
722
722
|
}
|
|
723
723
|
}
|
|
724
|
-
|
|
724
|
+
setOptions(newOptions);
|
|
725
725
|
onChange(inputValue);
|
|
726
726
|
rebirthOptions(false);
|
|
727
|
-
const index =
|
|
727
|
+
const index = flattenOptions(newOptions).findIndex(({ value: value2 }) => value2 === inputValue);
|
|
728
728
|
setFocusedIndex(index);
|
|
729
|
-
(_a = rest.onCreate) == null ? void 0 : _a.call(rest, newOption,
|
|
730
|
-
}, [inputValue,
|
|
729
|
+
(_a = rest.onCreate) == null ? void 0 : _a.call(rest, newOption, newOptions);
|
|
730
|
+
}, [inputValue, options, createOrder, onChange, rebirthOptions, rest, createSecondOrder, isMulti]);
|
|
731
731
|
const onDelete = (0, import_react.useCallback)(() => {
|
|
732
732
|
if (!isMulti) {
|
|
733
733
|
onChange("");
|
|
@@ -1000,6 +1000,8 @@ var useAutocompleteList = () => {
|
|
|
1000
1000
|
(0, import_react.useEffect)(() => {
|
|
1001
1001
|
if (!listRef.current || !selectedValue)
|
|
1002
1002
|
return;
|
|
1003
|
+
if (beforeFocusedIndex.current === selectedValue.index)
|
|
1004
|
+
return;
|
|
1003
1005
|
const parent = listRef.current;
|
|
1004
1006
|
const child = selectedValue.node;
|
|
1005
1007
|
const parentHeight = parent.clientHeight;
|
package/dist/autocomplete.mjs
CHANGED
|
@@ -692,20 +692,20 @@ var defaultFormat = (value) => {
|
|
|
692
692
|
value = value.toUpperCase();
|
|
693
693
|
return value;
|
|
694
694
|
};
|
|
695
|
-
var
|
|
696
|
-
const
|
|
697
|
-
const { value, isDisabled, isFocusable } =
|
|
695
|
+
var flattenOptions = (options) => {
|
|
696
|
+
const filterOptions = (options2) => options2.map((options3) => {
|
|
697
|
+
const { value, isDisabled, isFocusable } = options3;
|
|
698
698
|
const trulyDisabled = !!isDisabled && !isFocusable;
|
|
699
699
|
const isMulti = isArray(value);
|
|
700
700
|
if (trulyDisabled)
|
|
701
701
|
return;
|
|
702
702
|
if (!isMulti) {
|
|
703
|
-
return
|
|
703
|
+
return options3;
|
|
704
704
|
} else {
|
|
705
|
-
return
|
|
705
|
+
return filterOptions(value);
|
|
706
706
|
}
|
|
707
707
|
}).filter(Boolean);
|
|
708
|
-
return
|
|
708
|
+
return filterOptions(options).flat(Infinity);
|
|
709
709
|
};
|
|
710
710
|
var isTargetOption = (target) => {
|
|
711
711
|
var _a;
|
|
@@ -753,7 +753,7 @@ var useAutocomplete = ({
|
|
|
753
753
|
const inputRef = useRef2(null);
|
|
754
754
|
const timeoutIds = useRef2(/* @__PURE__ */ new Set([]));
|
|
755
755
|
const isComposition = useRef2(false);
|
|
756
|
-
const [
|
|
756
|
+
const [options, setOptions] = useState(rest.options);
|
|
757
757
|
const [value, setValue] = useControllableState({
|
|
758
758
|
value: rest.value,
|
|
759
759
|
defaultValue: rest.defaultValue,
|
|
@@ -771,7 +771,7 @@ var useAutocomplete = ({
|
|
|
771
771
|
const isEmptyValue = !isMulti ? !value : !value.length;
|
|
772
772
|
if (createOption && !isUndefined(children)) {
|
|
773
773
|
console.warn(
|
|
774
|
-
`${!isMulti ? "Autocomplete" : "MultiAutocomplete"}: ${!isMulti ? "Autocomplete" : "MultiAutocomplete"} internally prefers 'children'. If 'createOption' is true, it will not be reflected correctly. If want to reflect, please set '
|
|
774
|
+
`${!isMulti ? "Autocomplete" : "MultiAutocomplete"}: ${!isMulti ? "Autocomplete" : "MultiAutocomplete"} internally prefers 'children'. If 'createOption' is true, it will not be reflected correctly. If want to reflect, please set 'options' in props.`
|
|
775
775
|
);
|
|
776
776
|
}
|
|
777
777
|
const selectedValues = descendants.enabledValues(
|
|
@@ -785,7 +785,7 @@ var useAutocomplete = ({
|
|
|
785
785
|
({ node, index }) => "target" in node.dataset && !selectedIndexes.includes(index)
|
|
786
786
|
);
|
|
787
787
|
const validChildren = getValidChildren2(children);
|
|
788
|
-
const computedChildren =
|
|
788
|
+
const computedChildren = options == null ? void 0 : options.map(({ label, value: value2, ...props }, i) => {
|
|
789
789
|
if (!isArray(value2)) {
|
|
790
790
|
return /* @__PURE__ */ jsx8(AutocompleteOption, { value: value2, ...props, children: label }, i);
|
|
791
791
|
} else {
|
|
@@ -1049,20 +1049,20 @@ var useAutocomplete = ({
|
|
|
1049
1049
|
if (!listRef.current)
|
|
1050
1050
|
return;
|
|
1051
1051
|
const newOption = { label: inputValue, value: inputValue };
|
|
1052
|
-
let
|
|
1053
|
-
if (
|
|
1054
|
-
|
|
1052
|
+
let newOptions = [];
|
|
1053
|
+
if (options)
|
|
1054
|
+
newOptions = options;
|
|
1055
1055
|
if (createOrder === "first") {
|
|
1056
|
-
|
|
1056
|
+
newOptions = [newOption, ...newOptions];
|
|
1057
1057
|
} else if (createOrder === "last") {
|
|
1058
|
-
|
|
1058
|
+
newOptions = [...newOptions, newOption];
|
|
1059
1059
|
} else {
|
|
1060
|
-
const i =
|
|
1061
|
-
if (i !== -1 && isArray(
|
|
1060
|
+
const i = newOptions.findIndex(({ label }) => label === createOrder);
|
|
1061
|
+
if (i !== -1 && isArray(newOptions[i].value)) {
|
|
1062
1062
|
if (createSecondOrder === "first") {
|
|
1063
|
-
|
|
1063
|
+
newOptions[i].value = [newOption, ...newOptions[i].value];
|
|
1064
1064
|
} else {
|
|
1065
|
-
|
|
1065
|
+
newOptions[i].value = [...newOptions[i].value, newOption];
|
|
1066
1066
|
}
|
|
1067
1067
|
} else {
|
|
1068
1068
|
console.warn(
|
|
@@ -1070,13 +1070,13 @@ var useAutocomplete = ({
|
|
|
1070
1070
|
);
|
|
1071
1071
|
}
|
|
1072
1072
|
}
|
|
1073
|
-
|
|
1073
|
+
setOptions(newOptions);
|
|
1074
1074
|
onChange(inputValue);
|
|
1075
1075
|
rebirthOptions(false);
|
|
1076
|
-
const index =
|
|
1076
|
+
const index = flattenOptions(newOptions).findIndex(({ value: value2 }) => value2 === inputValue);
|
|
1077
1077
|
setFocusedIndex(index);
|
|
1078
|
-
(_a = rest.onCreate) == null ? void 0 : _a.call(rest, newOption,
|
|
1079
|
-
}, [inputValue,
|
|
1078
|
+
(_a = rest.onCreate) == null ? void 0 : _a.call(rest, newOption, newOptions);
|
|
1079
|
+
}, [inputValue, options, createOrder, onChange, rebirthOptions, rest, createSecondOrder, isMulti]);
|
|
1080
1080
|
const onDelete = useCallback(() => {
|
|
1081
1081
|
if (!isMulti) {
|
|
1082
1082
|
onChange("");
|
|
@@ -1349,6 +1349,8 @@ var useAutocompleteList = () => {
|
|
|
1349
1349
|
useEffect(() => {
|
|
1350
1350
|
if (!listRef.current || !selectedValue)
|
|
1351
1351
|
return;
|
|
1352
|
+
if (beforeFocusedIndex.current === selectedValue.index)
|
|
1353
|
+
return;
|
|
1352
1354
|
const parent = listRef.current;
|
|
1353
1355
|
const child = selectedValue.node;
|
|
1354
1356
|
const parentHeight = parent.clientHeight;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export { Autocomplete, AutocompleteProps } from './autocomplete.js';
|
|
2
2
|
export { AutocompleteOptionGroup, AutocompleteOptionGroupProps } from './autocomplete-option-group.js';
|
|
3
|
-
export { a as AutocompleteOption, A as AutocompleteOptionProps } from './use-autocomplete-
|
|
3
|
+
export { a as AutocompleteOption, A as AutocompleteOptionProps } from './use-autocomplete-4995431c.js';
|
|
4
4
|
export { AutocompleteCreate, AutocompleteCreateProps } from './autocomplete-create.js';
|
|
5
5
|
export { AutocompleteEmpty, AutocompleteEmptyProps } from './autocomplete-empty.js';
|
|
6
6
|
export { MultiAutocomplete, MultiAutocompleteProps } from './multi-autocomplete.js';
|
package/dist/index.js
CHANGED
|
@@ -148,20 +148,20 @@ var defaultFormat = (value) => {
|
|
|
148
148
|
value = value.toUpperCase();
|
|
149
149
|
return value;
|
|
150
150
|
};
|
|
151
|
-
var
|
|
152
|
-
const
|
|
153
|
-
const { value, isDisabled, isFocusable } =
|
|
151
|
+
var flattenOptions = (options) => {
|
|
152
|
+
const filterOptions = (options2) => options2.map((options3) => {
|
|
153
|
+
const { value, isDisabled, isFocusable } = options3;
|
|
154
154
|
const trulyDisabled = !!isDisabled && !isFocusable;
|
|
155
155
|
const isMulti = (0, import_utils.isArray)(value);
|
|
156
156
|
if (trulyDisabled)
|
|
157
157
|
return;
|
|
158
158
|
if (!isMulti) {
|
|
159
|
-
return
|
|
159
|
+
return options3;
|
|
160
160
|
} else {
|
|
161
|
-
return
|
|
161
|
+
return filterOptions(value);
|
|
162
162
|
}
|
|
163
163
|
}).filter(Boolean);
|
|
164
|
-
return
|
|
164
|
+
return filterOptions(options).flat(Infinity);
|
|
165
165
|
};
|
|
166
166
|
var isTargetOption = (target) => {
|
|
167
167
|
var _a;
|
|
@@ -209,7 +209,7 @@ var useAutocomplete = ({
|
|
|
209
209
|
const inputRef = (0, import_react.useRef)(null);
|
|
210
210
|
const timeoutIds = (0, import_react.useRef)(/* @__PURE__ */ new Set([]));
|
|
211
211
|
const isComposition = (0, import_react.useRef)(false);
|
|
212
|
-
const [
|
|
212
|
+
const [options, setOptions] = (0, import_react.useState)(rest.options);
|
|
213
213
|
const [value, setValue] = (0, import_use_controllable_state.useControllableState)({
|
|
214
214
|
value: rest.value,
|
|
215
215
|
defaultValue: rest.defaultValue,
|
|
@@ -227,7 +227,7 @@ var useAutocomplete = ({
|
|
|
227
227
|
const isEmptyValue = !isMulti ? !value : !value.length;
|
|
228
228
|
if (createOption && !(0, import_utils.isUndefined)(children)) {
|
|
229
229
|
console.warn(
|
|
230
|
-
`${!isMulti ? "Autocomplete" : "MultiAutocomplete"}: ${!isMulti ? "Autocomplete" : "MultiAutocomplete"} internally prefers 'children'. If 'createOption' is true, it will not be reflected correctly. If want to reflect, please set '
|
|
230
|
+
`${!isMulti ? "Autocomplete" : "MultiAutocomplete"}: ${!isMulti ? "Autocomplete" : "MultiAutocomplete"} internally prefers 'children'. If 'createOption' is true, it will not be reflected correctly. If want to reflect, please set 'options' in props.`
|
|
231
231
|
);
|
|
232
232
|
}
|
|
233
233
|
const selectedValues = descendants.enabledValues(
|
|
@@ -241,7 +241,7 @@ var useAutocomplete = ({
|
|
|
241
241
|
({ node, index }) => "target" in node.dataset && !selectedIndexes.includes(index)
|
|
242
242
|
);
|
|
243
243
|
const validChildren = (0, import_utils.getValidChildren)(children);
|
|
244
|
-
const computedChildren =
|
|
244
|
+
const computedChildren = options == null ? void 0 : options.map(({ label, value: value2, ...props }, i) => {
|
|
245
245
|
if (!(0, import_utils.isArray)(value2)) {
|
|
246
246
|
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(AutocompleteOption, { value: value2, ...props, children: label }, i);
|
|
247
247
|
} else {
|
|
@@ -505,20 +505,20 @@ var useAutocomplete = ({
|
|
|
505
505
|
if (!listRef.current)
|
|
506
506
|
return;
|
|
507
507
|
const newOption = { label: inputValue, value: inputValue };
|
|
508
|
-
let
|
|
509
|
-
if (
|
|
510
|
-
|
|
508
|
+
let newOptions = [];
|
|
509
|
+
if (options)
|
|
510
|
+
newOptions = options;
|
|
511
511
|
if (createOrder === "first") {
|
|
512
|
-
|
|
512
|
+
newOptions = [newOption, ...newOptions];
|
|
513
513
|
} else if (createOrder === "last") {
|
|
514
|
-
|
|
514
|
+
newOptions = [...newOptions, newOption];
|
|
515
515
|
} else {
|
|
516
|
-
const i =
|
|
517
|
-
if (i !== -1 && (0, import_utils.isArray)(
|
|
516
|
+
const i = newOptions.findIndex(({ label }) => label === createOrder);
|
|
517
|
+
if (i !== -1 && (0, import_utils.isArray)(newOptions[i].value)) {
|
|
518
518
|
if (createSecondOrder === "first") {
|
|
519
|
-
|
|
519
|
+
newOptions[i].value = [newOption, ...newOptions[i].value];
|
|
520
520
|
} else {
|
|
521
|
-
|
|
521
|
+
newOptions[i].value = [...newOptions[i].value, newOption];
|
|
522
522
|
}
|
|
523
523
|
} else {
|
|
524
524
|
console.warn(
|
|
@@ -526,13 +526,13 @@ var useAutocomplete = ({
|
|
|
526
526
|
);
|
|
527
527
|
}
|
|
528
528
|
}
|
|
529
|
-
|
|
529
|
+
setOptions(newOptions);
|
|
530
530
|
onChange(inputValue);
|
|
531
531
|
rebirthOptions(false);
|
|
532
|
-
const index =
|
|
532
|
+
const index = flattenOptions(newOptions).findIndex(({ value: value2 }) => value2 === inputValue);
|
|
533
533
|
setFocusedIndex(index);
|
|
534
|
-
(_a = rest.onCreate) == null ? void 0 : _a.call(rest, newOption,
|
|
535
|
-
}, [inputValue,
|
|
534
|
+
(_a = rest.onCreate) == null ? void 0 : _a.call(rest, newOption, newOptions);
|
|
535
|
+
}, [inputValue, options, createOrder, onChange, rebirthOptions, rest, createSecondOrder, isMulti]);
|
|
536
536
|
const onDelete = (0, import_react.useCallback)(() => {
|
|
537
537
|
if (!isMulti) {
|
|
538
538
|
onChange("");
|
|
@@ -805,6 +805,8 @@ var useAutocompleteList = () => {
|
|
|
805
805
|
(0, import_react.useEffect)(() => {
|
|
806
806
|
if (!listRef.current || !selectedValue)
|
|
807
807
|
return;
|
|
808
|
+
if (beforeFocusedIndex.current === selectedValue.index)
|
|
809
|
+
return;
|
|
808
810
|
const parent = listRef.current;
|
|
809
811
|
const child = selectedValue.node;
|
|
810
812
|
const parentHeight = parent.clientHeight;
|
package/dist/index.mjs
CHANGED
|
@@ -3,7 +3,7 @@ import { ThemeProps, HTMLUIProps } from '@yamada-ui/core';
|
|
|
3
3
|
import { FC, MouseEventHandler } from 'react';
|
|
4
4
|
import { AutocompleteIconProps } from './autocomplete-icon.js';
|
|
5
5
|
import { AutocompleteListProps } from './autocomplete-list.js';
|
|
6
|
-
import { b as UseAutocompleteProps } from './use-autocomplete-
|
|
6
|
+
import { b as UseAutocompleteProps } from './use-autocomplete-4995431c.js';
|
|
7
7
|
import 'react/jsx-runtime';
|
|
8
8
|
import '@yamada-ui/form-control';
|
|
9
9
|
import '@yamada-ui/popover';
|
|
@@ -344,20 +344,20 @@ var defaultFormat = (value) => {
|
|
|
344
344
|
value = value.toUpperCase();
|
|
345
345
|
return value;
|
|
346
346
|
};
|
|
347
|
-
var
|
|
348
|
-
const
|
|
349
|
-
const { value, isDisabled, isFocusable } =
|
|
347
|
+
var flattenOptions = (options) => {
|
|
348
|
+
const filterOptions = (options2) => options2.map((options3) => {
|
|
349
|
+
const { value, isDisabled, isFocusable } = options3;
|
|
350
350
|
const trulyDisabled = !!isDisabled && !isFocusable;
|
|
351
351
|
const isMulti = (0, import_utils6.isArray)(value);
|
|
352
352
|
if (trulyDisabled)
|
|
353
353
|
return;
|
|
354
354
|
if (!isMulti) {
|
|
355
|
-
return
|
|
355
|
+
return options3;
|
|
356
356
|
} else {
|
|
357
|
-
return
|
|
357
|
+
return filterOptions(value);
|
|
358
358
|
}
|
|
359
359
|
}).filter(Boolean);
|
|
360
|
-
return
|
|
360
|
+
return filterOptions(options).flat(Infinity);
|
|
361
361
|
};
|
|
362
362
|
var isTargetOption = (target) => {
|
|
363
363
|
var _a;
|
|
@@ -405,7 +405,7 @@ var useAutocomplete = ({
|
|
|
405
405
|
const inputRef = (0, import_react.useRef)(null);
|
|
406
406
|
const timeoutIds = (0, import_react.useRef)(/* @__PURE__ */ new Set([]));
|
|
407
407
|
const isComposition = (0, import_react.useRef)(false);
|
|
408
|
-
const [
|
|
408
|
+
const [options, setOptions] = (0, import_react.useState)(rest.options);
|
|
409
409
|
const [value, setValue] = (0, import_use_controllable_state.useControllableState)({
|
|
410
410
|
value: rest.value,
|
|
411
411
|
defaultValue: rest.defaultValue,
|
|
@@ -423,7 +423,7 @@ var useAutocomplete = ({
|
|
|
423
423
|
const isEmptyValue = !isMulti ? !value : !value.length;
|
|
424
424
|
if (createOption && !(0, import_utils6.isUndefined)(children)) {
|
|
425
425
|
console.warn(
|
|
426
|
-
`${!isMulti ? "Autocomplete" : "MultiAutocomplete"}: ${!isMulti ? "Autocomplete" : "MultiAutocomplete"} internally prefers 'children'. If 'createOption' is true, it will not be reflected correctly. If want to reflect, please set '
|
|
426
|
+
`${!isMulti ? "Autocomplete" : "MultiAutocomplete"}: ${!isMulti ? "Autocomplete" : "MultiAutocomplete"} internally prefers 'children'. If 'createOption' is true, it will not be reflected correctly. If want to reflect, please set 'options' in props.`
|
|
427
427
|
);
|
|
428
428
|
}
|
|
429
429
|
const selectedValues = descendants.enabledValues(
|
|
@@ -437,7 +437,7 @@ var useAutocomplete = ({
|
|
|
437
437
|
({ node, index }) => "target" in node.dataset && !selectedIndexes.includes(index)
|
|
438
438
|
);
|
|
439
439
|
const validChildren = (0, import_utils6.getValidChildren)(children);
|
|
440
|
-
const computedChildren =
|
|
440
|
+
const computedChildren = options == null ? void 0 : options.map(({ label, value: value2, ...props }, i) => {
|
|
441
441
|
if (!(0, import_utils6.isArray)(value2)) {
|
|
442
442
|
return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(AutocompleteOption, { value: value2, ...props, children: label }, i);
|
|
443
443
|
} else {
|
|
@@ -701,20 +701,20 @@ var useAutocomplete = ({
|
|
|
701
701
|
if (!listRef.current)
|
|
702
702
|
return;
|
|
703
703
|
const newOption = { label: inputValue, value: inputValue };
|
|
704
|
-
let
|
|
705
|
-
if (
|
|
706
|
-
|
|
704
|
+
let newOptions = [];
|
|
705
|
+
if (options)
|
|
706
|
+
newOptions = options;
|
|
707
707
|
if (createOrder === "first") {
|
|
708
|
-
|
|
708
|
+
newOptions = [newOption, ...newOptions];
|
|
709
709
|
} else if (createOrder === "last") {
|
|
710
|
-
|
|
710
|
+
newOptions = [...newOptions, newOption];
|
|
711
711
|
} else {
|
|
712
|
-
const i =
|
|
713
|
-
if (i !== -1 && (0, import_utils6.isArray)(
|
|
712
|
+
const i = newOptions.findIndex(({ label }) => label === createOrder);
|
|
713
|
+
if (i !== -1 && (0, import_utils6.isArray)(newOptions[i].value)) {
|
|
714
714
|
if (createSecondOrder === "first") {
|
|
715
|
-
|
|
715
|
+
newOptions[i].value = [newOption, ...newOptions[i].value];
|
|
716
716
|
} else {
|
|
717
|
-
|
|
717
|
+
newOptions[i].value = [...newOptions[i].value, newOption];
|
|
718
718
|
}
|
|
719
719
|
} else {
|
|
720
720
|
console.warn(
|
|
@@ -722,13 +722,13 @@ var useAutocomplete = ({
|
|
|
722
722
|
);
|
|
723
723
|
}
|
|
724
724
|
}
|
|
725
|
-
|
|
725
|
+
setOptions(newOptions);
|
|
726
726
|
onChange(inputValue);
|
|
727
727
|
rebirthOptions(false);
|
|
728
|
-
const index =
|
|
728
|
+
const index = flattenOptions(newOptions).findIndex(({ value: value2 }) => value2 === inputValue);
|
|
729
729
|
setFocusedIndex(index);
|
|
730
|
-
(_a = rest.onCreate) == null ? void 0 : _a.call(rest, newOption,
|
|
731
|
-
}, [inputValue,
|
|
730
|
+
(_a = rest.onCreate) == null ? void 0 : _a.call(rest, newOption, newOptions);
|
|
731
|
+
}, [inputValue, options, createOrder, onChange, rebirthOptions, rest, createSecondOrder, isMulti]);
|
|
732
732
|
const onDelete = (0, import_react.useCallback)(() => {
|
|
733
733
|
if (!isMulti) {
|
|
734
734
|
onChange("");
|
|
@@ -1001,6 +1001,8 @@ var useAutocompleteList = () => {
|
|
|
1001
1001
|
(0, import_react.useEffect)(() => {
|
|
1002
1002
|
if (!listRef.current || !selectedValue)
|
|
1003
1003
|
return;
|
|
1004
|
+
if (beforeFocusedIndex.current === selectedValue.index)
|
|
1005
|
+
return;
|
|
1004
1006
|
const parent = listRef.current;
|
|
1005
1007
|
const child = selectedValue.node;
|
|
1006
1008
|
const parentHeight = parent.clientHeight;
|
|
@@ -3363,7 +3363,7 @@ type UseAutocompleteBaseProps<T extends MaybeValue = string> = Omit<PopoverProps
|
|
|
3363
3363
|
omitSelectedValues?: boolean;
|
|
3364
3364
|
maxSelectedValues?: number;
|
|
3365
3365
|
optionProps?: Omit<AutocompleteOptionProps, 'value' | 'children'>;
|
|
3366
|
-
|
|
3366
|
+
options?: UIOption[];
|
|
3367
3367
|
};
|
|
3368
3368
|
type UseAutocompleteProps<T extends MaybeValue = string> = Omit<HTMLUIProps<'input'>, keyof UseAutocompleteBaseProps | 'list' | 'disabled' | 'required' | 'readOnly' | 'size'> & UseAutocompleteBaseProps<T>;
|
|
3369
3369
|
declare const useAutocomplete: <T extends MaybeValue = string>({ defaultIsOpen, closeOnSelect, omitSelectedValues, maxSelectedValues, closeOnBlur, closeOnEsc, createOption, createOrder, createSecondOrder, emptyMessage, format, placement, duration, optionProps, placeholder, children, ...rest }: UseAutocompleteProps<T>) => {
|
|
@@ -5,4 +5,4 @@ import '@yamada-ui/form-control';
|
|
|
5
5
|
import '@yamada-ui/popover';
|
|
6
6
|
import '@yamada-ui/select';
|
|
7
7
|
import '@yamada-ui/utils';
|
|
8
|
-
export { c as AutocompleteDescendantsContextProvider, f as AutocompleteProvider, M as MaybeValue, s as UseAutocompleteCreateReturn, v as UseAutocompleteEmptyReturn, k as UseAutocompleteInputReturn, U as UseAutocompleteOptionGroupProps, n as UseAutocompleteOptionGroupReturn, o as UseAutocompleteOptionProps, q as UseAutocompleteOptionReturn, b as UseAutocompleteProps, i as UseAutocompleteReturn, h as useAutocomplete, g as useAutocompleteContext, r as useAutocompleteCreate, e as useAutocompleteDescendant, d as useAutocompleteDescendants, u as useAutocompleteDescendantsContext, t as useAutocompleteEmpty, j as useAutocompleteInput, l as useAutocompleteList, p as useAutocompleteOption, m as useAutocompleteOptionGroup } from './use-autocomplete-
|
|
8
|
+
export { c as AutocompleteDescendantsContextProvider, f as AutocompleteProvider, M as MaybeValue, s as UseAutocompleteCreateReturn, v as UseAutocompleteEmptyReturn, k as UseAutocompleteInputReturn, U as UseAutocompleteOptionGroupProps, n as UseAutocompleteOptionGroupReturn, o as UseAutocompleteOptionProps, q as UseAutocompleteOptionReturn, b as UseAutocompleteProps, i as UseAutocompleteReturn, h as useAutocomplete, g as useAutocompleteContext, r as useAutocompleteCreate, e as useAutocompleteDescendant, d as useAutocompleteDescendants, u as useAutocompleteDescendantsContext, t as useAutocompleteEmpty, j as useAutocompleteInput, l as useAutocompleteList, p as useAutocompleteOption, m as useAutocompleteOptionGroup } from './use-autocomplete-4995431c.js';
|
package/dist/use-autocomplete.js
CHANGED
|
@@ -288,20 +288,20 @@ var defaultFormat = (value) => {
|
|
|
288
288
|
value = value.toUpperCase();
|
|
289
289
|
return value;
|
|
290
290
|
};
|
|
291
|
-
var
|
|
292
|
-
const
|
|
293
|
-
const { value, isDisabled, isFocusable } =
|
|
291
|
+
var flattenOptions = (options) => {
|
|
292
|
+
const filterOptions = (options2) => options2.map((options3) => {
|
|
293
|
+
const { value, isDisabled, isFocusable } = options3;
|
|
294
294
|
const trulyDisabled = !!isDisabled && !isFocusable;
|
|
295
295
|
const isMulti = (0, import_utils4.isArray)(value);
|
|
296
296
|
if (trulyDisabled)
|
|
297
297
|
return;
|
|
298
298
|
if (!isMulti) {
|
|
299
|
-
return
|
|
299
|
+
return options3;
|
|
300
300
|
} else {
|
|
301
|
-
return
|
|
301
|
+
return filterOptions(value);
|
|
302
302
|
}
|
|
303
303
|
}).filter(Boolean);
|
|
304
|
-
return
|
|
304
|
+
return filterOptions(options).flat(Infinity);
|
|
305
305
|
};
|
|
306
306
|
var isTargetOption = (target) => {
|
|
307
307
|
var _a;
|
|
@@ -349,7 +349,7 @@ var useAutocomplete = ({
|
|
|
349
349
|
const inputRef = (0, import_react2.useRef)(null);
|
|
350
350
|
const timeoutIds = (0, import_react2.useRef)(/* @__PURE__ */ new Set([]));
|
|
351
351
|
const isComposition = (0, import_react2.useRef)(false);
|
|
352
|
-
const [
|
|
352
|
+
const [options, setOptions] = (0, import_react2.useState)(rest.options);
|
|
353
353
|
const [value, setValue] = (0, import_use_controllable_state.useControllableState)({
|
|
354
354
|
value: rest.value,
|
|
355
355
|
defaultValue: rest.defaultValue,
|
|
@@ -367,7 +367,7 @@ var useAutocomplete = ({
|
|
|
367
367
|
const isEmptyValue = !isMulti ? !value : !value.length;
|
|
368
368
|
if (createOption && !(0, import_utils4.isUndefined)(children)) {
|
|
369
369
|
console.warn(
|
|
370
|
-
`${!isMulti ? "Autocomplete" : "MultiAutocomplete"}: ${!isMulti ? "Autocomplete" : "MultiAutocomplete"} internally prefers 'children'. If 'createOption' is true, it will not be reflected correctly. If want to reflect, please set '
|
|
370
|
+
`${!isMulti ? "Autocomplete" : "MultiAutocomplete"}: ${!isMulti ? "Autocomplete" : "MultiAutocomplete"} internally prefers 'children'. If 'createOption' is true, it will not be reflected correctly. If want to reflect, please set 'options' in props.`
|
|
371
371
|
);
|
|
372
372
|
}
|
|
373
373
|
const selectedValues = descendants.enabledValues(
|
|
@@ -381,7 +381,7 @@ var useAutocomplete = ({
|
|
|
381
381
|
({ node, index }) => "target" in node.dataset && !selectedIndexes.includes(index)
|
|
382
382
|
);
|
|
383
383
|
const validChildren = (0, import_utils4.getValidChildren)(children);
|
|
384
|
-
const computedChildren =
|
|
384
|
+
const computedChildren = options == null ? void 0 : options.map(({ label, value: value2, ...props }, i) => {
|
|
385
385
|
if (!(0, import_utils4.isArray)(value2)) {
|
|
386
386
|
return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(AutocompleteOption, { value: value2, ...props, children: label }, i);
|
|
387
387
|
} else {
|
|
@@ -645,20 +645,20 @@ var useAutocomplete = ({
|
|
|
645
645
|
if (!listRef.current)
|
|
646
646
|
return;
|
|
647
647
|
const newOption = { label: inputValue, value: inputValue };
|
|
648
|
-
let
|
|
649
|
-
if (
|
|
650
|
-
|
|
648
|
+
let newOptions = [];
|
|
649
|
+
if (options)
|
|
650
|
+
newOptions = options;
|
|
651
651
|
if (createOrder === "first") {
|
|
652
|
-
|
|
652
|
+
newOptions = [newOption, ...newOptions];
|
|
653
653
|
} else if (createOrder === "last") {
|
|
654
|
-
|
|
654
|
+
newOptions = [...newOptions, newOption];
|
|
655
655
|
} else {
|
|
656
|
-
const i =
|
|
657
|
-
if (i !== -1 && (0, import_utils4.isArray)(
|
|
656
|
+
const i = newOptions.findIndex(({ label }) => label === createOrder);
|
|
657
|
+
if (i !== -1 && (0, import_utils4.isArray)(newOptions[i].value)) {
|
|
658
658
|
if (createSecondOrder === "first") {
|
|
659
|
-
|
|
659
|
+
newOptions[i].value = [newOption, ...newOptions[i].value];
|
|
660
660
|
} else {
|
|
661
|
-
|
|
661
|
+
newOptions[i].value = [...newOptions[i].value, newOption];
|
|
662
662
|
}
|
|
663
663
|
} else {
|
|
664
664
|
console.warn(
|
|
@@ -666,13 +666,13 @@ var useAutocomplete = ({
|
|
|
666
666
|
);
|
|
667
667
|
}
|
|
668
668
|
}
|
|
669
|
-
|
|
669
|
+
setOptions(newOptions);
|
|
670
670
|
onChange(inputValue);
|
|
671
671
|
rebirthOptions(false);
|
|
672
|
-
const index =
|
|
672
|
+
const index = flattenOptions(newOptions).findIndex(({ value: value2 }) => value2 === inputValue);
|
|
673
673
|
setFocusedIndex(index);
|
|
674
|
-
(_a = rest.onCreate) == null ? void 0 : _a.call(rest, newOption,
|
|
675
|
-
}, [inputValue,
|
|
674
|
+
(_a = rest.onCreate) == null ? void 0 : _a.call(rest, newOption, newOptions);
|
|
675
|
+
}, [inputValue, options, createOrder, onChange, rebirthOptions, rest, createSecondOrder, isMulti]);
|
|
676
676
|
const onDelete = (0, import_react2.useCallback)(() => {
|
|
677
677
|
if (!isMulti) {
|
|
678
678
|
onChange("");
|
|
@@ -945,6 +945,8 @@ var useAutocompleteList = () => {
|
|
|
945
945
|
(0, import_react2.useEffect)(() => {
|
|
946
946
|
if (!listRef.current || !selectedValue)
|
|
947
947
|
return;
|
|
948
|
+
if (beforeFocusedIndex.current === selectedValue.index)
|
|
949
|
+
return;
|
|
948
950
|
const parent = listRef.current;
|
|
949
951
|
const child = selectedValue.node;
|
|
950
952
|
const parentHeight = parent.clientHeight;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@yamada-ui/autocomplete",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.11",
|
|
4
4
|
"description": "Yamada UI autocomplete component",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"yamada",
|
|
@@ -36,12 +36,12 @@
|
|
|
36
36
|
"url": "https://github.com/hirotomoyamada/yamada-ui/issues"
|
|
37
37
|
},
|
|
38
38
|
"dependencies": {
|
|
39
|
-
"@yamada-ui/core": "0.2.
|
|
39
|
+
"@yamada-ui/core": "0.2.3",
|
|
40
40
|
"@yamada-ui/utils": "0.1.1",
|
|
41
|
-
"@yamada-ui/icon": "0.1.
|
|
42
|
-
"@yamada-ui/select": "0.1.
|
|
43
|
-
"@yamada-ui/form-control": "0.1.
|
|
44
|
-
"@yamada-ui/popover": "0.1.
|
|
41
|
+
"@yamada-ui/icon": "0.1.10",
|
|
42
|
+
"@yamada-ui/select": "0.1.11",
|
|
43
|
+
"@yamada-ui/form-control": "0.1.10",
|
|
44
|
+
"@yamada-ui/popover": "0.1.10",
|
|
45
45
|
"@yamada-ui/use-descendant": "0.1.1",
|
|
46
46
|
"@yamada-ui/use-clickable": "0.1.1",
|
|
47
47
|
"@yamada-ui/use-outside-click": "0.1.1",
|