@yamada-ui/autocomplete 0.0.0-dev-20231125122836 → 0.0.0-dev-20231125140816

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.
@@ -1,7 +1,7 @@
1
1
  "use client"
2
2
  import {
3
3
  AutocompleteCreate
4
- } from "./chunk-IXZ5VUE3.mjs";
4
+ } from "./chunk-TZHEVPHW.mjs";
5
5
  export {
6
6
  AutocompleteCreate
7
7
  };
@@ -1,7 +1,7 @@
1
1
  "use client"
2
2
  import {
3
3
  AutocompleteEmpty
4
- } from "./chunk-IXZ5VUE3.mjs";
4
+ } from "./chunk-TZHEVPHW.mjs";
5
5
  export {
6
6
  AutocompleteEmpty
7
7
  };
@@ -3,7 +3,7 @@ import {
3
3
  AutocompleteClearIcon,
4
4
  AutocompleteIcon,
5
5
  AutocompleteItemIcon
6
- } from "./chunk-IXZ5VUE3.mjs";
6
+ } from "./chunk-TZHEVPHW.mjs";
7
7
  export {
8
8
  AutocompleteClearIcon,
9
9
  AutocompleteIcon,
@@ -1,7 +1,7 @@
1
1
  "use client"
2
2
  import {
3
3
  AutocompleteList
4
- } from "./chunk-IXZ5VUE3.mjs";
4
+ } from "./chunk-TZHEVPHW.mjs";
5
5
  export {
6
6
  AutocompleteList
7
7
  };
@@ -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-67b1aea6.js';
3
+ import { U as UseAutocompleteOptionGroupProps } from './use-autocomplete-72ef1a50.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 * as _yamada_ui_core from '@yamada-ui/core';
2
2
  import { HTMLUIProps } from '@yamada-ui/core';
3
- import { U as UseAutocompleteOptionGroupProps } from './use-autocomplete-67b1aea6.js';
3
+ import { U as UseAutocompleteOptionGroupProps } from './use-autocomplete-72ef1a50.js';
4
4
  import 'react/jsx-runtime';
5
5
  import 'react';
6
6
  import '@yamada-ui/form-control';
@@ -1,7 +1,7 @@
1
1
  "use client"
2
2
  import {
3
3
  AutocompleteOptionGroup
4
- } from "./chunk-IXZ5VUE3.mjs";
4
+ } from "./chunk-TZHEVPHW.mjs";
5
5
  export {
6
6
  AutocompleteOptionGroup
7
7
  };
@@ -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-67b1aea6.js';
3
+ export { A as AutocompleteOption, a as AutocompleteOptionProps } from './use-autocomplete-72ef1a50.js';
4
4
  import 'react/jsx-runtime';
5
5
  import '@yamada-ui/form-control';
6
6
  import '@yamada-ui/popover';
@@ -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-67b1aea6.js';
3
+ export { A as AutocompleteOption, a as AutocompleteOptionProps } from './use-autocomplete-72ef1a50.js';
4
4
  import 'react/jsx-runtime';
5
5
  import '@yamada-ui/form-control';
6
6
  import '@yamada-ui/popover';
@@ -1,7 +1,7 @@
1
1
  "use client"
2
2
  import {
3
3
  AutocompleteOption
4
- } from "./chunk-IXZ5VUE3.mjs";
4
+ } from "./chunk-TZHEVPHW.mjs";
5
5
  export {
6
6
  AutocompleteOption
7
7
  };
@@ -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.mjs';
4
4
  import { AutocompleteListProps } from './autocomplete-list.mjs';
5
- import { c as UseAutocompleteProps } from './use-autocomplete-67b1aea6.js';
5
+ import { c as UseAutocompleteProps } from './use-autocomplete-72ef1a50.js';
6
6
  import 'react';
7
7
  import 'react/jsx-runtime';
8
8
  import '@yamada-ui/form-control';
@@ -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 { c as UseAutocompleteProps } from './use-autocomplete-67b1aea6.js';
5
+ import { c as UseAutocompleteProps } from './use-autocomplete-72ef1a50.js';
6
6
  import 'react';
7
7
  import 'react/jsx-runtime';
8
8
  import '@yamada-ui/form-control';
@@ -389,6 +389,7 @@ var useAutocomplete = ({
389
389
  closeOnBlur = true,
390
390
  closeOnEsc = true,
391
391
  allowCreate = false,
392
+ allowFree = false,
392
393
  insertPositionItem = "first",
393
394
  emptyMessage = "No results found",
394
395
  format = defaultFormat,
@@ -676,6 +677,10 @@ var useAutocomplete = ({
676
677
  var _a;
677
678
  return (_a = node.textContent) != null ? _a : "";
678
679
  });
680
+ if (allowFree && selectedValues2.length === 0) {
681
+ selectedValues2.push(newValue);
682
+ setInputValue("");
683
+ }
679
684
  setDisplayValue((prev) => {
680
685
  if (!isMulti) {
681
686
  return selectedValues2[0];
@@ -692,7 +697,7 @@ var useAutocomplete = ({
692
697
  }
693
698
  });
694
699
  },
695
- [descendants, isMulti]
700
+ [descendants, isMulti, allowFree]
696
701
  );
697
702
  const onChange = (0, import_react.useCallback)(
698
703
  (newValue) => {
@@ -708,11 +713,26 @@ var useAutocomplete = ({
708
713
  }
709
714
  }
710
715
  });
716
+ const isHit2 = descendants.values().filter(
717
+ ({ node }) => {
718
+ var _a;
719
+ return format((_a = node.textContent) != null ? _a : "").includes(newValue);
720
+ }
721
+ ).length > 0;
711
722
  onChangeDisplayValue(newValue);
712
- setInputValue("");
723
+ if (!allowFree || isHit2) {
724
+ setInputValue("");
725
+ }
713
726
  rebirthOptions(false);
714
727
  },
715
- [onChangeDisplayValue, rebirthOptions, setValue]
728
+ [
729
+ allowFree,
730
+ onChangeDisplayValue,
731
+ rebirthOptions,
732
+ setValue,
733
+ descendants,
734
+ format
735
+ ]
716
736
  );
717
737
  const onSelect = (0, import_react.useCallback)(() => {
718
738
  var _a, _b;
@@ -846,11 +866,15 @@ var useAutocomplete = ({
846
866
  return;
847
867
  if (!closeOnBlur && isHit)
848
868
  return;
849
- setInputValue("");
869
+ if (allowFree && !!inputValue) {
870
+ onChange(inputValue);
871
+ } else {
872
+ setInputValue("");
873
+ }
850
874
  if (isOpen)
851
875
  onClose();
852
876
  },
853
- [closeOnBlur, isHit, isOpen, onClose]
877
+ [closeOnBlur, isHit, isOpen, inputValue, allowFree, onClose, onChange]
854
878
  );
855
879
  const onKeyDown = (0, import_react.useCallback)(
856
880
  (ev) => {
@@ -865,7 +889,11 @@ var useAutocomplete = ({
865
889
  ArrowDown: isFocused ? () => onFocusNext() : !isOpen ? (0, import_utils6.funcAll)(onOpen, onFocusFirstOrSelected) : void 0,
866
890
  ArrowUp: isFocused ? () => onFocusPrev() : !isOpen ? (0, import_utils6.funcAll)(onOpen, onFocusLastOrSelected) : void 0,
867
891
  Space: isCreate ? onCreate : isFocused ? onSelect : !isOpen ? (0, import_utils6.funcAll)(onOpen, onFocusFirstOrSelected) : void 0,
868
- Enter: isCreate ? onCreate : isFocused ? onSelect : !isOpen ? (0, import_utils6.funcAll)(onOpen, onFocusFirstOrSelected) : void 0,
892
+ Enter: isCreate ? onCreate : isFocused ? onSelect : !isOpen ? (0, import_utils6.funcAll)(onOpen, onFocusFirstOrSelected) : allowFree && isMulti ? () => {
893
+ if (inputValue)
894
+ onChange(inputValue);
895
+ setFocusedIndex(0);
896
+ } : void 0,
869
897
  Home: isOpen ? onFocusFirst : void 0,
870
898
  End: isOpen ? onFocusLast : void 0,
871
899
  Escape: closeOnEsc ? onClose : void 0,
@@ -879,11 +907,13 @@ var useAutocomplete = ({
879
907
  action(ev);
880
908
  },
881
909
  [
910
+ allowFree,
882
911
  formControlProps,
883
912
  displayValue,
884
913
  inputValue,
885
914
  onOpen,
886
915
  isFocused,
916
+ isMulti,
887
917
  onFocusFirstOrSelected,
888
918
  onFocusNext,
889
919
  onFocusLastOrSelected,
@@ -897,7 +927,8 @@ var useAutocomplete = ({
897
927
  closeOnEsc,
898
928
  onClose,
899
929
  isEmptyValue,
900
- onDelete
930
+ onDelete,
931
+ onChange
901
932
  ]
902
933
  );
903
934
  (0, import_react.useEffect)(() => {
@@ -922,7 +953,7 @@ var useAutocomplete = ({
922
953
  maxSelectedValues
923
954
  ]);
924
955
  (0, import_utils6.useUpdateEffect)(() => {
925
- if (isOpen)
956
+ if (isOpen || allowFree)
926
957
  return;
927
958
  setFocusedIndex(-1);
928
959
  setInputValue("");
@@ -993,6 +1024,7 @@ var useAutocomplete = ({
993
1024
  omitSelectedValues,
994
1025
  closeOnSelect,
995
1026
  allowCreate,
1027
+ allowFree,
996
1028
  emptyMessage,
997
1029
  isOpen,
998
1030
  isAllSelected,
@@ -1,7 +1,7 @@
1
1
  "use client"
2
2
  import {
3
3
  Autocomplete
4
- } from "./chunk-IXZ5VUE3.mjs";
4
+ } from "./chunk-TZHEVPHW.mjs";
5
5
  export {
6
6
  Autocomplete
7
7
  };
@@ -798,6 +798,7 @@ var useAutocomplete = ({
798
798
  closeOnBlur = true,
799
799
  closeOnEsc = true,
800
800
  allowCreate = false,
801
+ allowFree = false,
801
802
  insertPositionItem = "first",
802
803
  emptyMessage = "No results found",
803
804
  format = defaultFormat,
@@ -1085,6 +1086,10 @@ var useAutocomplete = ({
1085
1086
  var _a;
1086
1087
  return (_a = node.textContent) != null ? _a : "";
1087
1088
  });
1089
+ if (allowFree && selectedValues2.length === 0) {
1090
+ selectedValues2.push(newValue);
1091
+ setInputValue("");
1092
+ }
1088
1093
  setDisplayValue((prev) => {
1089
1094
  if (!isMulti) {
1090
1095
  return selectedValues2[0];
@@ -1101,7 +1106,7 @@ var useAutocomplete = ({
1101
1106
  }
1102
1107
  });
1103
1108
  },
1104
- [descendants, isMulti]
1109
+ [descendants, isMulti, allowFree]
1105
1110
  );
1106
1111
  const onChange = useCallback(
1107
1112
  (newValue) => {
@@ -1117,11 +1122,26 @@ var useAutocomplete = ({
1117
1122
  }
1118
1123
  }
1119
1124
  });
1125
+ const isHit2 = descendants.values().filter(
1126
+ ({ node }) => {
1127
+ var _a;
1128
+ return format((_a = node.textContent) != null ? _a : "").includes(newValue);
1129
+ }
1130
+ ).length > 0;
1120
1131
  onChangeDisplayValue(newValue);
1121
- setInputValue("");
1132
+ if (!allowFree || isHit2) {
1133
+ setInputValue("");
1134
+ }
1122
1135
  rebirthOptions(false);
1123
1136
  },
1124
- [onChangeDisplayValue, rebirthOptions, setValue]
1137
+ [
1138
+ allowFree,
1139
+ onChangeDisplayValue,
1140
+ rebirthOptions,
1141
+ setValue,
1142
+ descendants,
1143
+ format
1144
+ ]
1125
1145
  );
1126
1146
  const onSelect = useCallback(() => {
1127
1147
  var _a, _b;
@@ -1255,11 +1275,15 @@ var useAutocomplete = ({
1255
1275
  return;
1256
1276
  if (!closeOnBlur && isHit)
1257
1277
  return;
1258
- setInputValue("");
1278
+ if (allowFree && !!inputValue) {
1279
+ onChange(inputValue);
1280
+ } else {
1281
+ setInputValue("");
1282
+ }
1259
1283
  if (isOpen)
1260
1284
  onClose();
1261
1285
  },
1262
- [closeOnBlur, isHit, isOpen, onClose]
1286
+ [closeOnBlur, isHit, isOpen, inputValue, allowFree, onClose, onChange]
1263
1287
  );
1264
1288
  const onKeyDown = useCallback(
1265
1289
  (ev) => {
@@ -1274,7 +1298,11 @@ var useAutocomplete = ({
1274
1298
  ArrowDown: isFocused ? () => onFocusNext() : !isOpen ? funcAll(onOpen, onFocusFirstOrSelected) : void 0,
1275
1299
  ArrowUp: isFocused ? () => onFocusPrev() : !isOpen ? funcAll(onOpen, onFocusLastOrSelected) : void 0,
1276
1300
  Space: isCreate ? onCreate : isFocused ? onSelect : !isOpen ? funcAll(onOpen, onFocusFirstOrSelected) : void 0,
1277
- Enter: isCreate ? onCreate : isFocused ? onSelect : !isOpen ? funcAll(onOpen, onFocusFirstOrSelected) : void 0,
1301
+ Enter: isCreate ? onCreate : isFocused ? onSelect : !isOpen ? funcAll(onOpen, onFocusFirstOrSelected) : allowFree && isMulti ? () => {
1302
+ if (inputValue)
1303
+ onChange(inputValue);
1304
+ setFocusedIndex(0);
1305
+ } : void 0,
1278
1306
  Home: isOpen ? onFocusFirst : void 0,
1279
1307
  End: isOpen ? onFocusLast : void 0,
1280
1308
  Escape: closeOnEsc ? onClose : void 0,
@@ -1288,11 +1316,13 @@ var useAutocomplete = ({
1288
1316
  action(ev);
1289
1317
  },
1290
1318
  [
1319
+ allowFree,
1291
1320
  formControlProps,
1292
1321
  displayValue,
1293
1322
  inputValue,
1294
1323
  onOpen,
1295
1324
  isFocused,
1325
+ isMulti,
1296
1326
  onFocusFirstOrSelected,
1297
1327
  onFocusNext,
1298
1328
  onFocusLastOrSelected,
@@ -1306,7 +1336,8 @@ var useAutocomplete = ({
1306
1336
  closeOnEsc,
1307
1337
  onClose,
1308
1338
  isEmptyValue,
1309
- onDelete
1339
+ onDelete,
1340
+ onChange
1310
1341
  ]
1311
1342
  );
1312
1343
  useEffect(() => {
@@ -1331,7 +1362,7 @@ var useAutocomplete = ({
1331
1362
  maxSelectedValues
1332
1363
  ]);
1333
1364
  useUpdateEffect(() => {
1334
- if (isOpen)
1365
+ if (isOpen || allowFree)
1335
1366
  return;
1336
1367
  setFocusedIndex(-1);
1337
1368
  setInputValue("");
@@ -1402,6 +1433,7 @@ var useAutocomplete = ({
1402
1433
  omitSelectedValues,
1403
1434
  closeOnSelect,
1404
1435
  allowCreate,
1436
+ allowFree,
1405
1437
  emptyMessage,
1406
1438
  isOpen,
1407
1439
  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 { b as AutocompleteItem, A as AutocompleteOption, a as AutocompleteOptionProps } from './use-autocomplete-67b1aea6.js';
3
+ export { b as AutocompleteItem, A as AutocompleteOption, a as AutocompleteOptionProps } from './use-autocomplete-72ef1a50.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';
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 { b as AutocompleteItem, A as AutocompleteOption, a as AutocompleteOptionProps } from './use-autocomplete-67b1aea6.js';
3
+ export { b as AutocompleteItem, A as AutocompleteOption, a as AutocompleteOptionProps } from './use-autocomplete-72ef1a50.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
@@ -190,6 +190,7 @@ var useAutocomplete = ({
190
190
  closeOnBlur = true,
191
191
  closeOnEsc = true,
192
192
  allowCreate = false,
193
+ allowFree = false,
193
194
  insertPositionItem = "first",
194
195
  emptyMessage = "No results found",
195
196
  format = defaultFormat,
@@ -477,6 +478,10 @@ var useAutocomplete = ({
477
478
  var _a;
478
479
  return (_a = node.textContent) != null ? _a : "";
479
480
  });
481
+ if (allowFree && selectedValues2.length === 0) {
482
+ selectedValues2.push(newValue);
483
+ setInputValue("");
484
+ }
480
485
  setDisplayValue((prev) => {
481
486
  if (!isMulti) {
482
487
  return selectedValues2[0];
@@ -493,7 +498,7 @@ var useAutocomplete = ({
493
498
  }
494
499
  });
495
500
  },
496
- [descendants, isMulti]
501
+ [descendants, isMulti, allowFree]
497
502
  );
498
503
  const onChange = (0, import_react.useCallback)(
499
504
  (newValue) => {
@@ -509,11 +514,26 @@ var useAutocomplete = ({
509
514
  }
510
515
  }
511
516
  });
517
+ const isHit2 = descendants.values().filter(
518
+ ({ node }) => {
519
+ var _a;
520
+ return format((_a = node.textContent) != null ? _a : "").includes(newValue);
521
+ }
522
+ ).length > 0;
512
523
  onChangeDisplayValue(newValue);
513
- setInputValue("");
524
+ if (!allowFree || isHit2) {
525
+ setInputValue("");
526
+ }
514
527
  rebirthOptions(false);
515
528
  },
516
- [onChangeDisplayValue, rebirthOptions, setValue]
529
+ [
530
+ allowFree,
531
+ onChangeDisplayValue,
532
+ rebirthOptions,
533
+ setValue,
534
+ descendants,
535
+ format
536
+ ]
517
537
  );
518
538
  const onSelect = (0, import_react.useCallback)(() => {
519
539
  var _a, _b;
@@ -647,11 +667,15 @@ var useAutocomplete = ({
647
667
  return;
648
668
  if (!closeOnBlur && isHit)
649
669
  return;
650
- setInputValue("");
670
+ if (allowFree && !!inputValue) {
671
+ onChange(inputValue);
672
+ } else {
673
+ setInputValue("");
674
+ }
651
675
  if (isOpen)
652
676
  onClose();
653
677
  },
654
- [closeOnBlur, isHit, isOpen, onClose]
678
+ [closeOnBlur, isHit, isOpen, inputValue, allowFree, onClose, onChange]
655
679
  );
656
680
  const onKeyDown = (0, import_react.useCallback)(
657
681
  (ev) => {
@@ -666,7 +690,11 @@ var useAutocomplete = ({
666
690
  ArrowDown: isFocused ? () => onFocusNext() : !isOpen ? (0, import_utils.funcAll)(onOpen, onFocusFirstOrSelected) : void 0,
667
691
  ArrowUp: isFocused ? () => onFocusPrev() : !isOpen ? (0, import_utils.funcAll)(onOpen, onFocusLastOrSelected) : void 0,
668
692
  Space: isCreate ? onCreate : isFocused ? onSelect : !isOpen ? (0, import_utils.funcAll)(onOpen, onFocusFirstOrSelected) : void 0,
669
- Enter: isCreate ? onCreate : isFocused ? onSelect : !isOpen ? (0, import_utils.funcAll)(onOpen, onFocusFirstOrSelected) : void 0,
693
+ Enter: isCreate ? onCreate : isFocused ? onSelect : !isOpen ? (0, import_utils.funcAll)(onOpen, onFocusFirstOrSelected) : allowFree && isMulti ? () => {
694
+ if (inputValue)
695
+ onChange(inputValue);
696
+ setFocusedIndex(0);
697
+ } : void 0,
670
698
  Home: isOpen ? onFocusFirst : void 0,
671
699
  End: isOpen ? onFocusLast : void 0,
672
700
  Escape: closeOnEsc ? onClose : void 0,
@@ -680,11 +708,13 @@ var useAutocomplete = ({
680
708
  action(ev);
681
709
  },
682
710
  [
711
+ allowFree,
683
712
  formControlProps,
684
713
  displayValue,
685
714
  inputValue,
686
715
  onOpen,
687
716
  isFocused,
717
+ isMulti,
688
718
  onFocusFirstOrSelected,
689
719
  onFocusNext,
690
720
  onFocusLastOrSelected,
@@ -698,7 +728,8 @@ var useAutocomplete = ({
698
728
  closeOnEsc,
699
729
  onClose,
700
730
  isEmptyValue,
701
- onDelete
731
+ onDelete,
732
+ onChange
702
733
  ]
703
734
  );
704
735
  (0, import_react.useEffect)(() => {
@@ -723,7 +754,7 @@ var useAutocomplete = ({
723
754
  maxSelectedValues
724
755
  ]);
725
756
  (0, import_utils.useUpdateEffect)(() => {
726
- if (isOpen)
757
+ if (isOpen || allowFree)
727
758
  return;
728
759
  setFocusedIndex(-1);
729
760
  setInputValue("");
@@ -794,6 +825,7 @@ var useAutocomplete = ({
794
825
  omitSelectedValues,
795
826
  closeOnSelect,
796
827
  allowCreate,
828
+ allowFree,
797
829
  emptyMessage,
798
830
  isOpen,
799
831
  isAllSelected,
package/dist/index.mjs CHANGED
@@ -6,7 +6,7 @@ import {
6
6
  AutocompleteOption,
7
7
  AutocompleteOptionGroup,
8
8
  MultiAutocomplete
9
- } from "./chunk-IXZ5VUE3.mjs";
9
+ } from "./chunk-TZHEVPHW.mjs";
10
10
  export {
11
11
  Autocomplete,
12
12
  AutocompleteCreate,
@@ -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.mjs';
5
5
  import { AutocompleteListProps } from './autocomplete-list.mjs';
6
- import { c as UseAutocompleteProps } from './use-autocomplete-67b1aea6.js';
6
+ import { c as UseAutocompleteProps } from './use-autocomplete-72ef1a50.js';
7
7
  import 'react/jsx-runtime';
8
8
  import '@yamada-ui/form-control';
9
9
  import '@yamada-ui/popover';
@@ -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 { c as UseAutocompleteProps } from './use-autocomplete-67b1aea6.js';
6
+ import { c as UseAutocompleteProps } from './use-autocomplete-72ef1a50.js';
7
7
  import 'react/jsx-runtime';
8
8
  import '@yamada-ui/form-control';
9
9
  import '@yamada-ui/popover';
@@ -390,6 +390,7 @@ var useAutocomplete = ({
390
390
  closeOnBlur = true,
391
391
  closeOnEsc = true,
392
392
  allowCreate = false,
393
+ allowFree = false,
393
394
  insertPositionItem = "first",
394
395
  emptyMessage = "No results found",
395
396
  format = defaultFormat,
@@ -677,6 +678,10 @@ var useAutocomplete = ({
677
678
  var _a;
678
679
  return (_a = node.textContent) != null ? _a : "";
679
680
  });
681
+ if (allowFree && selectedValues2.length === 0) {
682
+ selectedValues2.push(newValue);
683
+ setInputValue("");
684
+ }
680
685
  setDisplayValue((prev) => {
681
686
  if (!isMulti) {
682
687
  return selectedValues2[0];
@@ -693,7 +698,7 @@ var useAutocomplete = ({
693
698
  }
694
699
  });
695
700
  },
696
- [descendants, isMulti]
701
+ [descendants, isMulti, allowFree]
697
702
  );
698
703
  const onChange = (0, import_react.useCallback)(
699
704
  (newValue) => {
@@ -709,11 +714,26 @@ var useAutocomplete = ({
709
714
  }
710
715
  }
711
716
  });
717
+ const isHit2 = descendants.values().filter(
718
+ ({ node }) => {
719
+ var _a;
720
+ return format((_a = node.textContent) != null ? _a : "").includes(newValue);
721
+ }
722
+ ).length > 0;
712
723
  onChangeDisplayValue(newValue);
713
- setInputValue("");
724
+ if (!allowFree || isHit2) {
725
+ setInputValue("");
726
+ }
714
727
  rebirthOptions(false);
715
728
  },
716
- [onChangeDisplayValue, rebirthOptions, setValue]
729
+ [
730
+ allowFree,
731
+ onChangeDisplayValue,
732
+ rebirthOptions,
733
+ setValue,
734
+ descendants,
735
+ format
736
+ ]
717
737
  );
718
738
  const onSelect = (0, import_react.useCallback)(() => {
719
739
  var _a, _b;
@@ -847,11 +867,15 @@ var useAutocomplete = ({
847
867
  return;
848
868
  if (!closeOnBlur && isHit)
849
869
  return;
850
- setInputValue("");
870
+ if (allowFree && !!inputValue) {
871
+ onChange(inputValue);
872
+ } else {
873
+ setInputValue("");
874
+ }
851
875
  if (isOpen)
852
876
  onClose();
853
877
  },
854
- [closeOnBlur, isHit, isOpen, onClose]
878
+ [closeOnBlur, isHit, isOpen, inputValue, allowFree, onClose, onChange]
855
879
  );
856
880
  const onKeyDown = (0, import_react.useCallback)(
857
881
  (ev) => {
@@ -866,7 +890,11 @@ var useAutocomplete = ({
866
890
  ArrowDown: isFocused ? () => onFocusNext() : !isOpen ? (0, import_utils6.funcAll)(onOpen, onFocusFirstOrSelected) : void 0,
867
891
  ArrowUp: isFocused ? () => onFocusPrev() : !isOpen ? (0, import_utils6.funcAll)(onOpen, onFocusLastOrSelected) : void 0,
868
892
  Space: isCreate ? onCreate : isFocused ? onSelect : !isOpen ? (0, import_utils6.funcAll)(onOpen, onFocusFirstOrSelected) : void 0,
869
- Enter: isCreate ? onCreate : isFocused ? onSelect : !isOpen ? (0, import_utils6.funcAll)(onOpen, onFocusFirstOrSelected) : void 0,
893
+ Enter: isCreate ? onCreate : isFocused ? onSelect : !isOpen ? (0, import_utils6.funcAll)(onOpen, onFocusFirstOrSelected) : allowFree && isMulti ? () => {
894
+ if (inputValue)
895
+ onChange(inputValue);
896
+ setFocusedIndex(0);
897
+ } : void 0,
870
898
  Home: isOpen ? onFocusFirst : void 0,
871
899
  End: isOpen ? onFocusLast : void 0,
872
900
  Escape: closeOnEsc ? onClose : void 0,
@@ -880,11 +908,13 @@ var useAutocomplete = ({
880
908
  action(ev);
881
909
  },
882
910
  [
911
+ allowFree,
883
912
  formControlProps,
884
913
  displayValue,
885
914
  inputValue,
886
915
  onOpen,
887
916
  isFocused,
917
+ isMulti,
888
918
  onFocusFirstOrSelected,
889
919
  onFocusNext,
890
920
  onFocusLastOrSelected,
@@ -898,7 +928,8 @@ var useAutocomplete = ({
898
928
  closeOnEsc,
899
929
  onClose,
900
930
  isEmptyValue,
901
- onDelete
931
+ onDelete,
932
+ onChange
902
933
  ]
903
934
  );
904
935
  (0, import_react.useEffect)(() => {
@@ -923,7 +954,7 @@ var useAutocomplete = ({
923
954
  maxSelectedValues
924
955
  ]);
925
956
  (0, import_utils6.useUpdateEffect)(() => {
926
- if (isOpen)
957
+ if (isOpen || allowFree)
927
958
  return;
928
959
  setFocusedIndex(-1);
929
960
  setInputValue("");
@@ -994,6 +1025,7 @@ var useAutocomplete = ({
994
1025
  omitSelectedValues,
995
1026
  closeOnSelect,
996
1027
  allowCreate,
1028
+ allowFree,
997
1029
  emptyMessage,
998
1030
  isOpen,
999
1031
  isAllSelected,
@@ -1,7 +1,7 @@
1
1
  "use client"
2
2
  import {
3
3
  MultiAutocomplete
4
- } from "./chunk-IXZ5VUE3.mjs";
4
+ } from "./chunk-TZHEVPHW.mjs";
5
5
  export {
6
6
  MultiAutocomplete
7
7
  };
@@ -3407,6 +3407,10 @@ type UseAutocompleteBaseProps<T extends string | string[] = string> = Omit<Popov
3407
3407
  * @default false
3408
3408
  */
3409
3409
  allowCreate?: boolean;
3410
+ /**
3411
+ * If `true`, enables the free input.
3412
+ */
3413
+ allowFree?: boolean;
3410
3414
  /**
3411
3415
  * If `true`, the selected item(s) will be excluded from the list.
3412
3416
  *
@@ -3427,7 +3431,7 @@ type UseAutocompleteBaseProps<T extends string | string[] = string> = Omit<Popov
3427
3431
  items?: AutocompleteItem[];
3428
3432
  };
3429
3433
  type UseAutocompleteProps<T extends string | string[] = string> = Omit<HTMLUIProps<"input">, keyof UseAutocompleteBaseProps | "list" | "disabled" | "required" | "readOnly" | "size"> & UseAutocompleteBaseProps<T>;
3430
- declare const useAutocomplete: <T extends string | string[] = string>({ defaultIsOpen, closeOnSelect, omitSelectedValues, maxSelectedValues, closeOnBlur, closeOnEsc, allowCreate, insertPositionItem, emptyMessage, format, placement, duration, optionProps, placeholder, items, children, ...rest }: UseAutocompleteProps<T>) => {
3434
+ declare const useAutocomplete: <T extends string | string[] = string>({ defaultIsOpen, closeOnSelect, omitSelectedValues, maxSelectedValues, closeOnBlur, closeOnEsc, allowCreate, allowFree, insertPositionItem, emptyMessage, format, placement, duration, optionProps, placeholder, items, children, ...rest }: UseAutocompleteProps<T>) => {
3431
3435
  id: string | undefined;
3432
3436
  descendants: {
3433
3437
  register: (nodeOrOptions: HTMLElement | {
@@ -4036,6 +4040,7 @@ declare const useAutocomplete: <T extends string | string[] = string>({ defaultI
4036
4040
  omitSelectedValues: boolean;
4037
4041
  closeOnSelect: boolean;
4038
4042
  allowCreate: boolean;
4043
+ allowFree: boolean;
4039
4044
  emptyMessage: string;
4040
4045
  isOpen: boolean;
4041
4046
  isAllSelected: boolean;
@@ -4,4 +4,4 @@ import '@yamada-ui/core';
4
4
  import '@yamada-ui/form-control';
5
5
  import '@yamada-ui/popover';
6
6
  import '@yamada-ui/utils';
7
- export { d as AutocompleteDescendantsContextProvider, b as AutocompleteItem, g as AutocompleteProvider, t as UseAutocompleteCreateReturn, w as UseAutocompleteEmptyReturn, l as UseAutocompleteInputReturn, U as UseAutocompleteOptionGroupProps, o as UseAutocompleteOptionGroupReturn, p as UseAutocompleteOptionProps, r as UseAutocompleteOptionReturn, c as UseAutocompleteProps, j as UseAutocompleteReturn, i as useAutocomplete, h as useAutocompleteContext, s as useAutocompleteCreate, f as useAutocompleteDescendant, e as useAutocompleteDescendants, u as useAutocompleteDescendantsContext, v as useAutocompleteEmpty, k as useAutocompleteInput, m as useAutocompleteList, q as useAutocompleteOption, n as useAutocompleteOptionGroup } from './use-autocomplete-67b1aea6.js';
7
+ export { d as AutocompleteDescendantsContextProvider, b as AutocompleteItem, g as AutocompleteProvider, t as UseAutocompleteCreateReturn, w as UseAutocompleteEmptyReturn, l as UseAutocompleteInputReturn, U as UseAutocompleteOptionGroupProps, o as UseAutocompleteOptionGroupReturn, p as UseAutocompleteOptionProps, r as UseAutocompleteOptionReturn, c as UseAutocompleteProps, j as UseAutocompleteReturn, i as useAutocomplete, h as useAutocompleteContext, s as useAutocompleteCreate, f as useAutocompleteDescendant, e as useAutocompleteDescendants, u as useAutocompleteDescendantsContext, v as useAutocompleteEmpty, k as useAutocompleteInput, m as useAutocompleteList, q as useAutocompleteOption, n as useAutocompleteOptionGroup } from './use-autocomplete-72ef1a50.js';
@@ -4,4 +4,4 @@ import '@yamada-ui/core';
4
4
  import '@yamada-ui/form-control';
5
5
  import '@yamada-ui/popover';
6
6
  import '@yamada-ui/utils';
7
- export { d as AutocompleteDescendantsContextProvider, b as AutocompleteItem, g as AutocompleteProvider, t as UseAutocompleteCreateReturn, w as UseAutocompleteEmptyReturn, l as UseAutocompleteInputReturn, U as UseAutocompleteOptionGroupProps, o as UseAutocompleteOptionGroupReturn, p as UseAutocompleteOptionProps, r as UseAutocompleteOptionReturn, c as UseAutocompleteProps, j as UseAutocompleteReturn, i as useAutocomplete, h as useAutocompleteContext, s as useAutocompleteCreate, f as useAutocompleteDescendant, e as useAutocompleteDescendants, u as useAutocompleteDescendantsContext, v as useAutocompleteEmpty, k as useAutocompleteInput, m as useAutocompleteList, q as useAutocompleteOption, n as useAutocompleteOptionGroup } from './use-autocomplete-67b1aea6.js';
7
+ export { d as AutocompleteDescendantsContextProvider, b as AutocompleteItem, g as AutocompleteProvider, t as UseAutocompleteCreateReturn, w as UseAutocompleteEmptyReturn, l as UseAutocompleteInputReturn, U as UseAutocompleteOptionGroupProps, o as UseAutocompleteOptionGroupReturn, p as UseAutocompleteOptionProps, r as UseAutocompleteOptionReturn, c as UseAutocompleteProps, j as UseAutocompleteReturn, i as useAutocomplete, h as useAutocompleteContext, s as useAutocompleteCreate, f as useAutocompleteDescendant, e as useAutocompleteDescendants, u as useAutocompleteDescendantsContext, v as useAutocompleteEmpty, k as useAutocompleteInput, m as useAutocompleteList, q as useAutocompleteOption, n as useAutocompleteOptionGroup } from './use-autocomplete-72ef1a50.js';
@@ -341,6 +341,7 @@ var useAutocomplete = ({
341
341
  closeOnBlur = true,
342
342
  closeOnEsc = true,
343
343
  allowCreate = false,
344
+ allowFree = false,
344
345
  insertPositionItem = "first",
345
346
  emptyMessage = "No results found",
346
347
  format = defaultFormat,
@@ -628,6 +629,10 @@ var useAutocomplete = ({
628
629
  var _a;
629
630
  return (_a = node.textContent) != null ? _a : "";
630
631
  });
632
+ if (allowFree && selectedValues2.length === 0) {
633
+ selectedValues2.push(newValue);
634
+ setInputValue("");
635
+ }
631
636
  setDisplayValue((prev) => {
632
637
  if (!isMulti) {
633
638
  return selectedValues2[0];
@@ -644,7 +649,7 @@ var useAutocomplete = ({
644
649
  }
645
650
  });
646
651
  },
647
- [descendants, isMulti]
652
+ [descendants, isMulti, allowFree]
648
653
  );
649
654
  const onChange = (0, import_react2.useCallback)(
650
655
  (newValue) => {
@@ -660,11 +665,26 @@ var useAutocomplete = ({
660
665
  }
661
666
  }
662
667
  });
668
+ const isHit2 = descendants.values().filter(
669
+ ({ node }) => {
670
+ var _a;
671
+ return format((_a = node.textContent) != null ? _a : "").includes(newValue);
672
+ }
673
+ ).length > 0;
663
674
  onChangeDisplayValue(newValue);
664
- setInputValue("");
675
+ if (!allowFree || isHit2) {
676
+ setInputValue("");
677
+ }
665
678
  rebirthOptions(false);
666
679
  },
667
- [onChangeDisplayValue, rebirthOptions, setValue]
680
+ [
681
+ allowFree,
682
+ onChangeDisplayValue,
683
+ rebirthOptions,
684
+ setValue,
685
+ descendants,
686
+ format
687
+ ]
668
688
  );
669
689
  const onSelect = (0, import_react2.useCallback)(() => {
670
690
  var _a, _b;
@@ -798,11 +818,15 @@ var useAutocomplete = ({
798
818
  return;
799
819
  if (!closeOnBlur && isHit)
800
820
  return;
801
- setInputValue("");
821
+ if (allowFree && !!inputValue) {
822
+ onChange(inputValue);
823
+ } else {
824
+ setInputValue("");
825
+ }
802
826
  if (isOpen)
803
827
  onClose();
804
828
  },
805
- [closeOnBlur, isHit, isOpen, onClose]
829
+ [closeOnBlur, isHit, isOpen, inputValue, allowFree, onClose, onChange]
806
830
  );
807
831
  const onKeyDown = (0, import_react2.useCallback)(
808
832
  (ev) => {
@@ -817,7 +841,11 @@ var useAutocomplete = ({
817
841
  ArrowDown: isFocused ? () => onFocusNext() : !isOpen ? (0, import_utils4.funcAll)(onOpen, onFocusFirstOrSelected) : void 0,
818
842
  ArrowUp: isFocused ? () => onFocusPrev() : !isOpen ? (0, import_utils4.funcAll)(onOpen, onFocusLastOrSelected) : void 0,
819
843
  Space: isCreate ? onCreate : isFocused ? onSelect : !isOpen ? (0, import_utils4.funcAll)(onOpen, onFocusFirstOrSelected) : void 0,
820
- Enter: isCreate ? onCreate : isFocused ? onSelect : !isOpen ? (0, import_utils4.funcAll)(onOpen, onFocusFirstOrSelected) : void 0,
844
+ Enter: isCreate ? onCreate : isFocused ? onSelect : !isOpen ? (0, import_utils4.funcAll)(onOpen, onFocusFirstOrSelected) : allowFree && isMulti ? () => {
845
+ if (inputValue)
846
+ onChange(inputValue);
847
+ setFocusedIndex(0);
848
+ } : void 0,
821
849
  Home: isOpen ? onFocusFirst : void 0,
822
850
  End: isOpen ? onFocusLast : void 0,
823
851
  Escape: closeOnEsc ? onClose : void 0,
@@ -831,11 +859,13 @@ var useAutocomplete = ({
831
859
  action(ev);
832
860
  },
833
861
  [
862
+ allowFree,
834
863
  formControlProps,
835
864
  displayValue,
836
865
  inputValue,
837
866
  onOpen,
838
867
  isFocused,
868
+ isMulti,
839
869
  onFocusFirstOrSelected,
840
870
  onFocusNext,
841
871
  onFocusLastOrSelected,
@@ -849,7 +879,8 @@ var useAutocomplete = ({
849
879
  closeOnEsc,
850
880
  onClose,
851
881
  isEmptyValue,
852
- onDelete
882
+ onDelete,
883
+ onChange
853
884
  ]
854
885
  );
855
886
  (0, import_react2.useEffect)(() => {
@@ -874,7 +905,7 @@ var useAutocomplete = ({
874
905
  maxSelectedValues
875
906
  ]);
876
907
  (0, import_utils4.useUpdateEffect)(() => {
877
- if (isOpen)
908
+ if (isOpen || allowFree)
878
909
  return;
879
910
  setFocusedIndex(-1);
880
911
  setInputValue("");
@@ -945,6 +976,7 @@ var useAutocomplete = ({
945
976
  omitSelectedValues,
946
977
  closeOnSelect,
947
978
  allowCreate,
979
+ allowFree,
948
980
  emptyMessage,
949
981
  isOpen,
950
982
  isAllSelected,
@@ -13,7 +13,7 @@ import {
13
13
  useAutocompleteList,
14
14
  useAutocompleteOption,
15
15
  useAutocompleteOptionGroup
16
- } from "./chunk-IXZ5VUE3.mjs";
16
+ } from "./chunk-TZHEVPHW.mjs";
17
17
  export {
18
18
  AutocompleteDescendantsContextProvider,
19
19
  AutocompleteProvider,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yamada-ui/autocomplete",
3
- "version": "0.0.0-dev-20231125122836",
3
+ "version": "0.0.0-dev-20231125140816",
4
4
  "description": "Yamada UI autocomplete component",
5
5
  "keywords": [
6
6
  "yamada",
@@ -36,16 +36,16 @@
36
36
  "url": "https://github.com/hirotomoyamada/yamada-ui/issues"
37
37
  },
38
38
  "dependencies": {
39
- "@yamada-ui/core": "0.0.0-dev-20231125122836",
39
+ "@yamada-ui/core": "0.0.0-dev-20231125140816",
40
40
  "@yamada-ui/utils": "0.3.3",
41
- "@yamada-ui/icon": "0.0.0-dev-20231125122836",
42
- "@yamada-ui/select": "0.0.0-dev-20231125122836",
43
- "@yamada-ui/form-control": "0.0.0-dev-20231125122836",
44
- "@yamada-ui/popover": "0.0.0-dev-20231125122836",
45
- "@yamada-ui/use-descendant": "0.0.0-dev-20231125122836",
46
- "@yamada-ui/use-clickable": "0.0.0-dev-20231125122836",
47
- "@yamada-ui/use-outside-click": "0.0.0-dev-20231125122836",
48
- "@yamada-ui/use-controllable-state": "0.0.0-dev-20231125122836"
41
+ "@yamada-ui/icon": "0.0.0-dev-20231125140816",
42
+ "@yamada-ui/select": "0.0.0-dev-20231125140816",
43
+ "@yamada-ui/form-control": "0.0.0-dev-20231125140816",
44
+ "@yamada-ui/popover": "0.0.0-dev-20231125140816",
45
+ "@yamada-ui/use-descendant": "0.0.0-dev-20231125140816",
46
+ "@yamada-ui/use-clickable": "0.0.0-dev-20231125140816",
47
+ "@yamada-ui/use-outside-click": "0.0.0-dev-20231125140816",
48
+ "@yamada-ui/use-controllable-state": "0.0.0-dev-20231125140816"
49
49
  },
50
50
  "devDependencies": {
51
51
  "react": "^18.0.0",