@yamada-ui/autocomplete 0.4.13 → 0.5.2

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.
Files changed (37) hide show
  1. package/dist/autocomplete-create.d.mts +1 -1
  2. package/dist/autocomplete-create.d.ts +1 -1
  3. package/dist/autocomplete-create.mjs +1 -1
  4. package/dist/autocomplete-empty.d.mts +1 -1
  5. package/dist/autocomplete-empty.d.ts +1 -1
  6. package/dist/autocomplete-empty.mjs +1 -1
  7. package/dist/autocomplete-icon.d.mts +2 -2
  8. package/dist/autocomplete-icon.d.ts +2 -2
  9. package/dist/autocomplete-icon.mjs +1 -1
  10. package/dist/autocomplete-list.d.mts +1 -1
  11. package/dist/autocomplete-list.d.ts +1 -1
  12. package/dist/autocomplete-list.mjs +1 -1
  13. package/dist/autocomplete-option-group.d.mts +2 -3
  14. package/dist/autocomplete-option-group.d.ts +2 -3
  15. package/dist/autocomplete-option-group.mjs +1 -1
  16. package/dist/autocomplete-option.d.mts +1 -2
  17. package/dist/autocomplete-option.d.ts +1 -2
  18. package/dist/autocomplete-option.mjs +1 -1
  19. package/dist/autocomplete.d.mts +5 -6
  20. package/dist/autocomplete.d.ts +5 -6
  21. package/dist/autocomplete.js +57 -60
  22. package/dist/autocomplete.mjs +1 -1
  23. package/dist/{chunk-EFOFI4S7.mjs → chunk-JKY5MMNC.mjs} +61 -64
  24. package/dist/index.d.mts +1 -2
  25. package/dist/index.d.ts +1 -2
  26. package/dist/index.js +61 -64
  27. package/dist/index.mjs +1 -1
  28. package/dist/multi-autocomplete.d.mts +5 -6
  29. package/dist/multi-autocomplete.d.ts +5 -6
  30. package/dist/multi-autocomplete.js +57 -60
  31. package/dist/multi-autocomplete.mjs +1 -1
  32. package/dist/{use-autocomplete-2422c1c8.d.ts → use-autocomplete-3e77a4da.d.ts} +31 -42
  33. package/dist/use-autocomplete.d.mts +1 -2
  34. package/dist/use-autocomplete.d.ts +1 -2
  35. package/dist/use-autocomplete.js +53 -56
  36. package/dist/use-autocomplete.mjs +1 -1
  37. package/package.json +6 -6
@@ -171,7 +171,7 @@ var Autocomplete = forwardRef2(
171
171
  getPopoverProps,
172
172
  getContainerProps,
173
173
  getFieldProps,
174
- createOption,
174
+ allowCreate,
175
175
  isEmpty,
176
176
  inputValue,
177
177
  computedChildren,
@@ -193,7 +193,7 @@ var Autocomplete = forwardRef2(
193
193
  ...rest,
194
194
  formControlProps,
195
195
  inputValue,
196
- createOption,
196
+ allowCreate,
197
197
  isEmpty,
198
198
  styles
199
199
  },
@@ -215,9 +215,9 @@ var Autocomplete = forwardRef2(
215
215
  ),
216
216
  /* @__PURE__ */ jsx2(AutocompleteIcon, { ...iconProps, ...formControlProps }),
217
217
  !isEmpty ? /* @__PURE__ */ jsxs(AutocompleteList, { ...listProps, children: [
218
- createOption ? /* @__PURE__ */ jsx2(AutocompleteCreate, {}) : /* @__PURE__ */ jsx2(AutocompleteEmpty, {}),
218
+ allowCreate ? /* @__PURE__ */ jsx2(AutocompleteCreate, {}) : /* @__PURE__ */ jsx2(AutocompleteEmpty, {}),
219
219
  children != null ? children : computedChildren
220
- ] }) : /* @__PURE__ */ jsx2(AutocompleteList, { ...listProps, children: createOption && inputValue ? /* @__PURE__ */ jsx2(AutocompleteCreate, {}) : /* @__PURE__ */ jsx2(AutocompleteEmpty, {}) })
220
+ ] }) : /* @__PURE__ */ jsx2(AutocompleteList, { ...listProps, children: allowCreate && inputValue ? /* @__PURE__ */ jsx2(AutocompleteCreate, {}) : /* @__PURE__ */ jsx2(AutocompleteEmpty, {}) })
221
221
  ]
222
222
  }
223
223
  ) })
@@ -488,7 +488,7 @@ var MultiAutocomplete = forwardRef7(
488
488
  getPopoverProps,
489
489
  getContainerProps,
490
490
  getFieldProps,
491
- createOption,
491
+ allowCreate,
492
492
  isEmpty,
493
493
  inputValue,
494
494
  computedChildren,
@@ -517,7 +517,7 @@ var MultiAutocomplete = forwardRef7(
517
517
  value,
518
518
  formControlProps,
519
519
  inputValue,
520
- createOption,
520
+ allowCreate,
521
521
  isEmpty,
522
522
  styles
523
523
  },
@@ -549,9 +549,9 @@ var MultiAutocomplete = forwardRef7(
549
549
  }
550
550
  ) : /* @__PURE__ */ jsx7(AutocompleteIcon, { ...iconProps, ...formControlProps }),
551
551
  !isEmpty ? /* @__PURE__ */ jsxs6(AutocompleteList, { ...listProps, children: [
552
- createOption ? /* @__PURE__ */ jsx7(AutocompleteCreate, {}) : /* @__PURE__ */ jsx7(AutocompleteEmpty, {}),
552
+ allowCreate ? /* @__PURE__ */ jsx7(AutocompleteCreate, {}) : /* @__PURE__ */ jsx7(AutocompleteEmpty, {}),
553
553
  children != null ? children : computedChildren
554
- ] }) : /* @__PURE__ */ jsx7(AutocompleteList, { ...listProps, children: createOption && inputValue ? /* @__PURE__ */ jsx7(AutocompleteCreate, {}) : /* @__PURE__ */ jsx7(AutocompleteEmpty, {}) })
554
+ ] }) : /* @__PURE__ */ jsx7(AutocompleteList, { ...listProps, children: allowCreate && inputValue ? /* @__PURE__ */ jsx7(AutocompleteCreate, {}) : /* @__PURE__ */ jsx7(AutocompleteEmpty, {}) })
555
555
  ]
556
556
  }
557
557
  ) })
@@ -757,20 +757,20 @@ var defaultFormat = (value) => {
757
757
  value = value.toUpperCase();
758
758
  return value;
759
759
  };
760
- var flattenOptions = (options) => {
761
- const filterOptions = (options2) => options2.map((options3) => {
762
- const { value, isDisabled, isFocusable } = options3;
760
+ var flattenItems = (items) => {
761
+ const filterItems = (items2) => items2.map((item) => {
762
+ var _a;
763
+ const { isDisabled, isFocusable } = item;
763
764
  const trulyDisabled = !!isDisabled && !isFocusable;
764
- const isMulti = isArray(value);
765
765
  if (trulyDisabled)
766
766
  return;
767
- if (!isMulti) {
768
- return options3;
767
+ if ("items" in item) {
768
+ return filterItems((_a = item.items) != null ? _a : []);
769
769
  } else {
770
- return filterOptions(value);
770
+ return item;
771
771
  }
772
772
  }).filter(Boolean);
773
- return filterOptions(options).flat(Infinity);
773
+ return filterItems(items).flat(Infinity);
774
774
  };
775
775
  var isTargetOption = (target) => {
776
776
  var _a;
@@ -793,14 +793,15 @@ var useAutocomplete = ({
793
793
  maxSelectedValues,
794
794
  closeOnBlur = true,
795
795
  closeOnEsc = true,
796
- createOption = false,
797
- insertPositionOnCreate = "first",
796
+ allowCreate = false,
797
+ insertPositionItem = "first",
798
798
  emptyMessage = "No results found",
799
799
  format = defaultFormat,
800
800
  placement = "bottom-start",
801
801
  duration = 0.2,
802
802
  optionProps,
803
803
  placeholder,
804
+ items,
804
805
  children,
805
806
  ...rest
806
807
  }) => {
@@ -824,7 +825,7 @@ var useAutocomplete = ({
824
825
  const inputRef = useRef2(null);
825
826
  const timeoutIds = useRef2(/* @__PURE__ */ new Set([]));
826
827
  const isComposition = useRef2(false);
827
- const [options, setOptions] = useState(rest.options);
828
+ const [resolvedItems, setResolvedItems] = useState(items);
828
829
  const [value, setValue] = useControllableState({
829
830
  value: rest.value,
830
831
  defaultValue: rest.defaultValue,
@@ -837,19 +838,19 @@ var useAutocomplete = ({
837
838
  const [isHit, setIsHit] = useState(true);
838
839
  const [isOpen, setIsOpen] = useState(defaultIsOpen != null ? defaultIsOpen : false);
839
840
  const isFocused = focusedIndex > -1;
840
- const isCreate = focusedIndex === -2 && createOption;
841
+ const isCreate = focusedIndex === -2 && allowCreate;
841
842
  const isMulti = isArray(value);
842
843
  const isEmptyValue = !isMulti ? !value : !value.length;
843
- const [firstInsertPositionOnCreate, secondInsertPositionOnCreate] = useMemo2(() => {
844
- if (isArray(insertPositionOnCreate)) {
845
- return insertPositionOnCreate;
844
+ const [firstInsertPositionItem, secondInsertPositionItem] = useMemo2(() => {
845
+ if (isArray(insertPositionItem)) {
846
+ return insertPositionItem;
846
847
  } else {
847
- return [insertPositionOnCreate, "first"];
848
+ return [insertPositionItem, "first"];
848
849
  }
849
- }, [insertPositionOnCreate]);
850
- if (createOption && !isUndefined(children)) {
850
+ }, [insertPositionItem]);
851
+ if (allowCreate && !isUndefined(children)) {
851
852
  console.warn(
852
- `${!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.`
853
+ `${!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.`
853
854
  );
854
855
  }
855
856
  const selectedValues = descendants.enabledValues(
@@ -863,18 +864,18 @@ var useAutocomplete = ({
863
864
  ({ node, index }) => "target" in node.dataset && !selectedIndexes.includes(index)
864
865
  );
865
866
  const validChildren = getValidChildren2(children);
866
- const computedChildren = options == null ? void 0 : options.map(({ label, value: value2, ...props }, i) => {
867
- if (!isArray(value2)) {
867
+ const computedChildren = resolvedItems == null ? void 0 : resolvedItems.map((item, i) => {
868
+ if ("value" in item) {
869
+ const { label, value: value2, ...props } = item;
868
870
  return /* @__PURE__ */ jsx8(AutocompleteOption, { value: value2, ...props, children: label }, i);
869
- } else {
871
+ } else if ("items" in item) {
872
+ const { label, items: items2 = [], ...props } = item;
870
873
  return /* @__PURE__ */ jsx8(
871
874
  AutocompleteOptionGroup,
872
875
  {
873
876
  label,
874
877
  ...props,
875
- children: value2.map(
876
- ({ label: label2, value: value3, ...props2 }, i2) => !isArray(value3) ? /* @__PURE__ */ jsx8(AutocompleteOption, { value: value3, ...props2, children: label2 }, i2) : null
877
- )
878
+ children: items2.map(({ label: label2, value: value2, ...props2 }, i2) => /* @__PURE__ */ jsx8(AutocompleteOption, { value: value2, ...props2, children: label2 }, i2))
878
879
  },
879
880
  i
880
881
  );
@@ -885,13 +886,13 @@ var useAutocomplete = ({
885
886
  var _a;
886
887
  if (formControlProps.disabled || formControlProps.readOnly)
887
888
  return;
888
- if (!createOption && (isEmpty || isAllSelected))
889
+ if (!allowCreate && (isEmpty || isAllSelected))
889
890
  return;
890
891
  setIsOpen(true);
891
892
  if (inputRef.current)
892
893
  inputRef.current.focus();
893
894
  (_a = rest.onOpen) == null ? void 0 : _a.call(rest);
894
- }, [createOption, formControlProps, isAllSelected, isEmpty, rest]);
895
+ }, [allowCreate, formControlProps, isAllSelected, isEmpty, rest]);
895
896
  const onClose = useCallback(() => {
896
897
  var _a;
897
898
  setIsOpen(false);
@@ -1163,55 +1164,51 @@ var useAutocomplete = ({
1163
1164
  isComposition.current = false;
1164
1165
  }, []);
1165
1166
  const onCreate = useCallback(() => {
1166
- var _a;
1167
+ var _a, _b, _c;
1167
1168
  if (!listRef.current)
1168
1169
  return;
1169
- const newOption = { label: inputValue, value: inputValue };
1170
- let newOptions = [];
1171
- if (options)
1172
- newOptions = options;
1173
- if (firstInsertPositionOnCreate === "first") {
1174
- newOptions = [newOption, ...newOptions];
1175
- } else if (firstInsertPositionOnCreate === "last") {
1176
- newOptions = [...newOptions, newOption];
1170
+ const newItem = { label: inputValue, value: inputValue };
1171
+ let newItems = [];
1172
+ if (resolvedItems)
1173
+ newItems = resolvedItems;
1174
+ if (firstInsertPositionItem === "first") {
1175
+ newItems = [newItem, ...newItems];
1176
+ } else if (firstInsertPositionItem === "last") {
1177
+ newItems = [...newItems, newItem];
1177
1178
  } else {
1178
- const i = newOptions.findIndex(
1179
- ({ label }) => label === firstInsertPositionOnCreate
1179
+ const i = newItems.findIndex(
1180
+ ({ label }) => label === firstInsertPositionItem
1180
1181
  );
1181
- if (i !== -1 && isArray(newOptions[i].value)) {
1182
- if (secondInsertPositionOnCreate === "first") {
1183
- newOptions[i].value = [
1184
- newOption,
1185
- ...newOptions[i].value
1186
- ];
1182
+ const targetItem = newItems[i];
1183
+ if (i !== -1 && "items" in targetItem) {
1184
+ if (secondInsertPositionItem === "first") {
1185
+ targetItem.items = [newItem, ...(_a = targetItem.items) != null ? _a : []];
1187
1186
  } else {
1188
- newOptions[i].value = [
1189
- ...newOptions[i].value,
1190
- newOption
1191
- ];
1187
+ targetItem.items = [...(_b = targetItem.items) != null ? _b : [], newItem];
1192
1188
  }
1189
+ newItems[i] = targetItem;
1193
1190
  } else {
1194
1191
  console.warn(
1195
- `${!isMulti ? "Autocomplete" : "MultiAutocomplete"}: '${firstInsertPositionOnCreate}' specified in insertPositionOnCreate does not exist in the option group.`
1192
+ `${!isMulti ? "Autocomplete" : "MultiAutocomplete"}: '${firstInsertPositionItem}' specified in insertPositionItem does not exist in the option group.`
1196
1193
  );
1197
1194
  }
1198
1195
  }
1199
- setOptions(newOptions);
1196
+ setResolvedItems(newItems);
1200
1197
  onChange(inputValue);
1201
1198
  rebirthOptions(false);
1202
- const index = flattenOptions(newOptions).findIndex(
1199
+ const index = flattenItems(newItems).findIndex(
1203
1200
  ({ value: value2 }) => value2 === inputValue
1204
1201
  );
1205
1202
  setFocusedIndex(index);
1206
- (_a = rest.onCreate) == null ? void 0 : _a.call(rest, newOption, newOptions);
1203
+ (_c = rest.onCreate) == null ? void 0 : _c.call(rest, newItem, newItems);
1207
1204
  }, [
1208
1205
  inputValue,
1209
- options,
1210
- firstInsertPositionOnCreate,
1206
+ resolvedItems,
1207
+ firstInsertPositionItem,
1211
1208
  onChange,
1212
1209
  rebirthOptions,
1213
1210
  rest,
1214
- secondInsertPositionOnCreate,
1211
+ secondInsertPositionItem,
1215
1212
  isMulti
1216
1213
  ]);
1217
1214
  const onDelete = useCallback(() => {
@@ -1398,7 +1395,7 @@ var useAutocomplete = ({
1398
1395
  focusedIndex,
1399
1396
  omitSelectedValues,
1400
1397
  closeOnSelect,
1401
- createOption,
1398
+ allowCreate,
1402
1399
  emptyMessage,
1403
1400
  isOpen,
1404
1401
  isAllSelected,
package/dist/index.d.mts CHANGED
@@ -1,6 +1,6 @@
1
1
  export { Autocomplete, AutocompleteProps } from './autocomplete.mjs';
2
2
  export { AutocompleteOptionGroup, AutocompleteOptionGroupProps } from './autocomplete-option-group.mjs';
3
- export { A as AutocompleteOption, a as AutocompleteOptionProps } from './use-autocomplete-2422c1c8.js';
3
+ export { b as AutocompleteItem, A as AutocompleteOption, a as AutocompleteOptionProps } from './use-autocomplete-3e77a4da.js';
4
4
  export { AutocompleteCreate, AutocompleteCreateProps } from './autocomplete-create.mjs';
5
5
  export { AutocompleteEmpty, AutocompleteEmptyProps } from './autocomplete-empty.mjs';
6
6
  export { MultiAutocomplete, MultiAutocompleteProps } from './multi-autocomplete.mjs';
@@ -11,5 +11,4 @@ import './autocomplete-list.mjs';
11
11
  import 'react/jsx-runtime';
12
12
  import '@yamada-ui/form-control';
13
13
  import '@yamada-ui/popover';
14
- import '@yamada-ui/select';
15
14
  import '@yamada-ui/utils';
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-2422c1c8.js';
3
+ export { b as AutocompleteItem, A as AutocompleteOption, a as AutocompleteOptionProps } from './use-autocomplete-3e77a4da.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';
@@ -11,5 +11,4 @@ import './autocomplete-list.js';
11
11
  import 'react/jsx-runtime';
12
12
  import '@yamada-ui/form-control';
13
13
  import '@yamada-ui/popover';
14
- import '@yamada-ui/select';
15
14
  import '@yamada-ui/utils';
package/dist/index.js CHANGED
@@ -152,20 +152,20 @@ var defaultFormat = (value) => {
152
152
  value = value.toUpperCase();
153
153
  return value;
154
154
  };
155
- var flattenOptions = (options) => {
156
- const filterOptions = (options2) => options2.map((options3) => {
157
- const { value, isDisabled, isFocusable } = options3;
155
+ var flattenItems = (items) => {
156
+ const filterItems = (items2) => items2.map((item) => {
157
+ var _a;
158
+ const { isDisabled, isFocusable } = item;
158
159
  const trulyDisabled = !!isDisabled && !isFocusable;
159
- const isMulti = (0, import_utils.isArray)(value);
160
160
  if (trulyDisabled)
161
161
  return;
162
- if (!isMulti) {
163
- return options3;
162
+ if ("items" in item) {
163
+ return filterItems((_a = item.items) != null ? _a : []);
164
164
  } else {
165
- return filterOptions(value);
165
+ return item;
166
166
  }
167
167
  }).filter(Boolean);
168
- return filterOptions(options).flat(Infinity);
168
+ return filterItems(items).flat(Infinity);
169
169
  };
170
170
  var isTargetOption = (target) => {
171
171
  var _a;
@@ -188,14 +188,15 @@ var useAutocomplete = ({
188
188
  maxSelectedValues,
189
189
  closeOnBlur = true,
190
190
  closeOnEsc = true,
191
- createOption = false,
192
- insertPositionOnCreate = "first",
191
+ allowCreate = false,
192
+ insertPositionItem = "first",
193
193
  emptyMessage = "No results found",
194
194
  format = defaultFormat,
195
195
  placement = "bottom-start",
196
196
  duration = 0.2,
197
197
  optionProps,
198
198
  placeholder,
199
+ items,
199
200
  children,
200
201
  ...rest
201
202
  }) => {
@@ -219,7 +220,7 @@ var useAutocomplete = ({
219
220
  const inputRef = (0, import_react.useRef)(null);
220
221
  const timeoutIds = (0, import_react.useRef)(/* @__PURE__ */ new Set([]));
221
222
  const isComposition = (0, import_react.useRef)(false);
222
- const [options, setOptions] = (0, import_react.useState)(rest.options);
223
+ const [resolvedItems, setResolvedItems] = (0, import_react.useState)(items);
223
224
  const [value, setValue] = (0, import_use_controllable_state.useControllableState)({
224
225
  value: rest.value,
225
226
  defaultValue: rest.defaultValue,
@@ -232,19 +233,19 @@ var useAutocomplete = ({
232
233
  const [isHit, setIsHit] = (0, import_react.useState)(true);
233
234
  const [isOpen, setIsOpen] = (0, import_react.useState)(defaultIsOpen != null ? defaultIsOpen : false);
234
235
  const isFocused = focusedIndex > -1;
235
- const isCreate = focusedIndex === -2 && createOption;
236
+ const isCreate = focusedIndex === -2 && allowCreate;
236
237
  const isMulti = (0, import_utils.isArray)(value);
237
238
  const isEmptyValue = !isMulti ? !value : !value.length;
238
- const [firstInsertPositionOnCreate, secondInsertPositionOnCreate] = (0, import_react.useMemo)(() => {
239
- if ((0, import_utils.isArray)(insertPositionOnCreate)) {
240
- return insertPositionOnCreate;
239
+ const [firstInsertPositionItem, secondInsertPositionItem] = (0, import_react.useMemo)(() => {
240
+ if ((0, import_utils.isArray)(insertPositionItem)) {
241
+ return insertPositionItem;
241
242
  } else {
242
- return [insertPositionOnCreate, "first"];
243
+ return [insertPositionItem, "first"];
243
244
  }
244
- }, [insertPositionOnCreate]);
245
- if (createOption && !(0, import_utils.isUndefined)(children)) {
245
+ }, [insertPositionItem]);
246
+ if (allowCreate && !(0, import_utils.isUndefined)(children)) {
246
247
  console.warn(
247
- `${!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.`
248
+ `${!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.`
248
249
  );
249
250
  }
250
251
  const selectedValues = descendants.enabledValues(
@@ -258,18 +259,18 @@ var useAutocomplete = ({
258
259
  ({ node, index }) => "target" in node.dataset && !selectedIndexes.includes(index)
259
260
  );
260
261
  const validChildren = (0, import_utils.getValidChildren)(children);
261
- const computedChildren = options == null ? void 0 : options.map(({ label, value: value2, ...props }, i) => {
262
- if (!(0, import_utils.isArray)(value2)) {
262
+ const computedChildren = resolvedItems == null ? void 0 : resolvedItems.map((item, i) => {
263
+ if ("value" in item) {
264
+ const { label, value: value2, ...props } = item;
263
265
  return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(AutocompleteOption, { value: value2, ...props, children: label }, i);
264
- } else {
266
+ } else if ("items" in item) {
267
+ const { label, items: items2 = [], ...props } = item;
265
268
  return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
266
269
  AutocompleteOptionGroup,
267
270
  {
268
271
  label,
269
272
  ...props,
270
- children: value2.map(
271
- ({ label: label2, value: value3, ...props2 }, i2) => !(0, import_utils.isArray)(value3) ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(AutocompleteOption, { value: value3, ...props2, children: label2 }, i2) : null
272
- )
273
+ children: items2.map(({ label: label2, value: value2, ...props2 }, i2) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(AutocompleteOption, { value: value2, ...props2, children: label2 }, i2))
273
274
  },
274
275
  i
275
276
  );
@@ -280,13 +281,13 @@ var useAutocomplete = ({
280
281
  var _a;
281
282
  if (formControlProps.disabled || formControlProps.readOnly)
282
283
  return;
283
- if (!createOption && (isEmpty || isAllSelected))
284
+ if (!allowCreate && (isEmpty || isAllSelected))
284
285
  return;
285
286
  setIsOpen(true);
286
287
  if (inputRef.current)
287
288
  inputRef.current.focus();
288
289
  (_a = rest.onOpen) == null ? void 0 : _a.call(rest);
289
- }, [createOption, formControlProps, isAllSelected, isEmpty, rest]);
290
+ }, [allowCreate, formControlProps, isAllSelected, isEmpty, rest]);
290
291
  const onClose = (0, import_react.useCallback)(() => {
291
292
  var _a;
292
293
  setIsOpen(false);
@@ -558,55 +559,51 @@ var useAutocomplete = ({
558
559
  isComposition.current = false;
559
560
  }, []);
560
561
  const onCreate = (0, import_react.useCallback)(() => {
561
- var _a;
562
+ var _a, _b, _c;
562
563
  if (!listRef.current)
563
564
  return;
564
- const newOption = { label: inputValue, value: inputValue };
565
- let newOptions = [];
566
- if (options)
567
- newOptions = options;
568
- if (firstInsertPositionOnCreate === "first") {
569
- newOptions = [newOption, ...newOptions];
570
- } else if (firstInsertPositionOnCreate === "last") {
571
- newOptions = [...newOptions, newOption];
565
+ const newItem = { label: inputValue, value: inputValue };
566
+ let newItems = [];
567
+ if (resolvedItems)
568
+ newItems = resolvedItems;
569
+ if (firstInsertPositionItem === "first") {
570
+ newItems = [newItem, ...newItems];
571
+ } else if (firstInsertPositionItem === "last") {
572
+ newItems = [...newItems, newItem];
572
573
  } else {
573
- const i = newOptions.findIndex(
574
- ({ label }) => label === firstInsertPositionOnCreate
574
+ const i = newItems.findIndex(
575
+ ({ label }) => label === firstInsertPositionItem
575
576
  );
576
- if (i !== -1 && (0, import_utils.isArray)(newOptions[i].value)) {
577
- if (secondInsertPositionOnCreate === "first") {
578
- newOptions[i].value = [
579
- newOption,
580
- ...newOptions[i].value
581
- ];
577
+ const targetItem = newItems[i];
578
+ if (i !== -1 && "items" in targetItem) {
579
+ if (secondInsertPositionItem === "first") {
580
+ targetItem.items = [newItem, ...(_a = targetItem.items) != null ? _a : []];
582
581
  } else {
583
- newOptions[i].value = [
584
- ...newOptions[i].value,
585
- newOption
586
- ];
582
+ targetItem.items = [...(_b = targetItem.items) != null ? _b : [], newItem];
587
583
  }
584
+ newItems[i] = targetItem;
588
585
  } else {
589
586
  console.warn(
590
- `${!isMulti ? "Autocomplete" : "MultiAutocomplete"}: '${firstInsertPositionOnCreate}' specified in insertPositionOnCreate does not exist in the option group.`
587
+ `${!isMulti ? "Autocomplete" : "MultiAutocomplete"}: '${firstInsertPositionItem}' specified in insertPositionItem does not exist in the option group.`
591
588
  );
592
589
  }
593
590
  }
594
- setOptions(newOptions);
591
+ setResolvedItems(newItems);
595
592
  onChange(inputValue);
596
593
  rebirthOptions(false);
597
- const index = flattenOptions(newOptions).findIndex(
594
+ const index = flattenItems(newItems).findIndex(
598
595
  ({ value: value2 }) => value2 === inputValue
599
596
  );
600
597
  setFocusedIndex(index);
601
- (_a = rest.onCreate) == null ? void 0 : _a.call(rest, newOption, newOptions);
598
+ (_c = rest.onCreate) == null ? void 0 : _c.call(rest, newItem, newItems);
602
599
  }, [
603
600
  inputValue,
604
- options,
605
- firstInsertPositionOnCreate,
601
+ resolvedItems,
602
+ firstInsertPositionItem,
606
603
  onChange,
607
604
  rebirthOptions,
608
605
  rest,
609
- secondInsertPositionOnCreate,
606
+ secondInsertPositionItem,
610
607
  isMulti
611
608
  ]);
612
609
  const onDelete = (0, import_react.useCallback)(() => {
@@ -793,7 +790,7 @@ var useAutocomplete = ({
793
790
  focusedIndex,
794
791
  omitSelectedValues,
795
792
  closeOnSelect,
796
- createOption,
793
+ allowCreate,
797
794
  emptyMessage,
798
795
  isOpen,
799
796
  isAllSelected,
@@ -1321,7 +1318,7 @@ var Autocomplete = (0, import_core4.forwardRef)(
1321
1318
  getPopoverProps,
1322
1319
  getContainerProps,
1323
1320
  getFieldProps,
1324
- createOption,
1321
+ allowCreate,
1325
1322
  isEmpty,
1326
1323
  inputValue,
1327
1324
  computedChildren,
@@ -1343,7 +1340,7 @@ var Autocomplete = (0, import_core4.forwardRef)(
1343
1340
  ...rest,
1344
1341
  formControlProps,
1345
1342
  inputValue,
1346
- createOption,
1343
+ allowCreate,
1347
1344
  isEmpty,
1348
1345
  styles
1349
1346
  },
@@ -1365,9 +1362,9 @@ var Autocomplete = (0, import_core4.forwardRef)(
1365
1362
  ),
1366
1363
  /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(AutocompleteIcon, { ...iconProps, ...formControlProps }),
1367
1364
  !isEmpty ? /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(AutocompleteList, { ...listProps, children: [
1368
- createOption ? /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(AutocompleteCreate, {}) : /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(AutocompleteEmpty, {}),
1365
+ allowCreate ? /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(AutocompleteCreate, {}) : /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(AutocompleteEmpty, {}),
1369
1366
  children != null ? children : computedChildren
1370
- ] }) : /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(AutocompleteList, { ...listProps, children: createOption && inputValue ? /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(AutocompleteCreate, {}) : /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(AutocompleteEmpty, {}) })
1367
+ ] }) : /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(AutocompleteList, { ...listProps, children: allowCreate && inputValue ? /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(AutocompleteCreate, {}) : /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(AutocompleteEmpty, {}) })
1371
1368
  ]
1372
1369
  }
1373
1370
  ) })
@@ -1630,7 +1627,7 @@ var MultiAutocomplete = (0, import_core9.forwardRef)(
1630
1627
  getPopoverProps,
1631
1628
  getContainerProps,
1632
1629
  getFieldProps,
1633
- createOption,
1630
+ allowCreate,
1634
1631
  isEmpty,
1635
1632
  inputValue,
1636
1633
  computedChildren,
@@ -1659,7 +1656,7 @@ var MultiAutocomplete = (0, import_core9.forwardRef)(
1659
1656
  value,
1660
1657
  formControlProps,
1661
1658
  inputValue,
1662
- createOption,
1659
+ allowCreate,
1663
1660
  isEmpty,
1664
1661
  styles
1665
1662
  },
@@ -1691,9 +1688,9 @@ var MultiAutocomplete = (0, import_core9.forwardRef)(
1691
1688
  }
1692
1689
  ) : /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(AutocompleteIcon, { ...iconProps, ...formControlProps }),
1693
1690
  !isEmpty ? /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)(AutocompleteList, { ...listProps, children: [
1694
- createOption ? /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(AutocompleteCreate, {}) : /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(AutocompleteEmpty, {}),
1691
+ allowCreate ? /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(AutocompleteCreate, {}) : /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(AutocompleteEmpty, {}),
1695
1692
  children != null ? children : computedChildren
1696
- ] }) : /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(AutocompleteList, { ...listProps, children: createOption && inputValue ? /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(AutocompleteCreate, {}) : /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(AutocompleteEmpty, {}) })
1693
+ ] }) : /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(AutocompleteList, { ...listProps, children: allowCreate && inputValue ? /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(AutocompleteCreate, {}) : /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(AutocompleteEmpty, {}) })
1697
1694
  ]
1698
1695
  }
1699
1696
  ) })
package/dist/index.mjs CHANGED
@@ -6,7 +6,7 @@ import {
6
6
  AutocompleteOption,
7
7
  AutocompleteOptionGroup,
8
8
  MultiAutocomplete
9
- } from "./chunk-EFOFI4S7.mjs";
9
+ } from "./chunk-JKY5MMNC.mjs";
10
10
  export {
11
11
  Autocomplete,
12
12
  AutocompleteCreate,
@@ -3,11 +3,10 @@ import { ThemeProps, HTMLUIProps } from '@yamada-ui/core';
3
3
  import { FC, MouseEventHandler } from 'react';
4
4
  import { AutocompleteIconProps } from './autocomplete-icon.mjs';
5
5
  import { AutocompleteListProps } from './autocomplete-list.mjs';
6
- import { b as UseAutocompleteProps } from './use-autocomplete-2422c1c8.js';
6
+ import { c as UseAutocompleteProps } from './use-autocomplete-3e77a4da.js';
7
7
  import 'react/jsx-runtime';
8
8
  import '@yamada-ui/form-control';
9
9
  import '@yamada-ui/popover';
10
- import '@yamada-ui/select';
11
10
  import '@yamada-ui/utils';
12
11
 
13
12
  type MultiAutocompleteOptions = {
@@ -49,15 +48,15 @@ type MultiAutocompleteOptions = {
49
48
  /**
50
49
  * Props for multi autocomplete container element.
51
50
  */
52
- containerProps?: Omit<HTMLUIProps<'div'>, 'children'>;
51
+ containerProps?: Omit<HTMLUIProps<"div">, "children">;
53
52
  /**
54
53
  * Props for multi autocomplete list element.
55
54
  */
56
- listProps?: Omit<AutocompleteListProps, 'children'>;
55
+ listProps?: Omit<AutocompleteListProps, "children">;
57
56
  /**
58
57
  * Props for multi autocomplete input element.
59
58
  */
60
- inputProps?: HTMLUIProps<'input'>;
59
+ inputProps?: HTMLUIProps<"input">;
61
60
  /**
62
61
  * Props for multi autocomplete icon element.
63
62
  */
@@ -67,7 +66,7 @@ type MultiAutocompleteOptions = {
67
66
  */
68
67
  clearIconProps?: AutocompleteIconProps;
69
68
  };
70
- type MultiAutocompleteProps = ThemeProps<'Select'> & UseAutocompleteProps<string[]> & MultiAutocompleteOptions;
69
+ type MultiAutocompleteProps = ThemeProps<"Select"> & UseAutocompleteProps<string[]> & MultiAutocompleteOptions;
71
70
  declare const MultiAutocomplete: _yamada_ui_core.Component<"div", MultiAutocompleteProps>;
72
71
 
73
72
  export { MultiAutocomplete, MultiAutocompleteProps };