@yamada-ui/autocomplete 0.2.10 → 0.2.12

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 (35) hide show
  1. package/dist/autocomplete-create.js +24 -17
  2. package/dist/autocomplete-create.mjs +1 -1
  3. package/dist/autocomplete-empty.js +24 -17
  4. package/dist/autocomplete-empty.mjs +1 -1
  5. package/dist/autocomplete-icon.js +30 -23
  6. package/dist/autocomplete-icon.mjs +1 -1
  7. package/dist/autocomplete-list.js +4 -1
  8. package/dist/autocomplete-list.mjs +1 -1
  9. package/dist/autocomplete-option-group.d.mts +1 -1
  10. package/dist/autocomplete-option-group.d.ts +1 -1
  11. package/dist/autocomplete-option-group.js +10 -5
  12. package/dist/autocomplete-option-group.mjs +1 -1
  13. package/dist/autocomplete-option.d.mts +1 -1
  14. package/dist/autocomplete-option.d.ts +1 -1
  15. package/dist/autocomplete-option.js +33 -22
  16. package/dist/autocomplete-option.mjs +1 -1
  17. package/dist/autocomplete.d.mts +1 -1
  18. package/dist/autocomplete.d.ts +1 -1
  19. package/dist/autocomplete.js +226 -120
  20. package/dist/autocomplete.mjs +1 -1
  21. package/dist/{chunk-5O3XEEJE.mjs → chunk-ZVZP7IWT.mjs} +352 -229
  22. package/dist/index.d.mts +1 -1
  23. package/dist/index.d.ts +1 -1
  24. package/dist/index.js +345 -229
  25. package/dist/index.mjs +1 -1
  26. package/dist/multi-autocomplete.d.mts +1 -1
  27. package/dist/multi-autocomplete.d.ts +1 -1
  28. package/dist/multi-autocomplete.js +245 -149
  29. package/dist/multi-autocomplete.mjs +1 -1
  30. package/dist/{use-autocomplete-cbe9b443.d.ts → use-autocomplete-2422c1c8.d.ts} +25 -5
  31. package/dist/use-autocomplete.d.mts +1 -1
  32. package/dist/use-autocomplete.d.ts +1 -1
  33. package/dist/use-autocomplete.js +131 -45
  34. package/dist/use-autocomplete.mjs +1 -1
  35. package/package.json +11 -11
@@ -77,31 +77,38 @@ var AutocompleteIcon = (0, import_core.forwardRef)(
77
77
  }
78
78
  })
79
79
  );
80
- return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_core.ui.div, { ref, className: (0, import_utils.cx)("ui-autocomplete-icon", className), __css: css, ...rest, children: (0, import_utils.isValidElement)(children) ? cloneChildren : /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_icon.ChevronIcon, {}) });
81
- }
82
- );
83
- var AutocompleteItemIcon = (0, import_core.forwardRef)(
84
- ({ className, ...rest }, ref) => {
85
- const { styles } = useAutocompleteContext();
86
- const css = {
87
- flexShrink: 0,
88
- display: "inline-flex",
89
- justifyContent: "center",
90
- alignItems: "center",
91
- fontSize: "0.85em",
92
- ...styles.itemIcon
93
- };
94
80
  return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
95
- import_core.ui.span,
81
+ import_core.ui.div,
96
82
  {
97
83
  ref,
98
- className: (0, import_utils.cx)("ui-autocomplete-item-icon", className),
84
+ className: (0, import_utils.cx)("ui-autocomplete-icon", className),
99
85
  __css: css,
100
- ...rest
86
+ ...rest,
87
+ children: (0, import_utils.isValidElement)(children) ? cloneChildren : /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_icon.ChevronIcon, {})
101
88
  }
102
89
  );
103
90
  }
104
91
  );
92
+ var AutocompleteItemIcon = (0, import_core.forwardRef)(({ className, ...rest }, ref) => {
93
+ const { styles } = useAutocompleteContext();
94
+ const css = {
95
+ flexShrink: 0,
96
+ display: "inline-flex",
97
+ justifyContent: "center",
98
+ alignItems: "center",
99
+ fontSize: "0.85em",
100
+ ...styles.itemIcon
101
+ };
102
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
103
+ import_core.ui.span,
104
+ {
105
+ ref,
106
+ className: (0, import_utils.cx)("ui-autocomplete-item-icon", className),
107
+ __css: css,
108
+ ...rest
109
+ }
110
+ );
111
+ });
105
112
 
106
113
  // src/autocomplete-option-group.tsx
107
114
  var import_core2 = require("@yamada-ui/core");
@@ -282,7 +289,10 @@ var kanaMap = {
282
289
  "\uFF65": "\u30FB"
283
290
  };
284
291
  var defaultFormat = (value) => {
285
- value = value.replace(/[!-~]/g, (v) => String.fromCharCode(v.charCodeAt(0) - 65248));
292
+ value = value.replace(
293
+ /[!-~]/g,
294
+ (v) => String.fromCharCode(v.charCodeAt(0) - 65248)
295
+ );
286
296
  const reg = new RegExp("(" + Object.keys(kanaMap).join("|") + ")", "g");
287
297
  value = value.replace(reg, (v) => kanaMap[v]).replace(/゙/g, "\u309B").replace(/゚/g, "\u309C");
288
298
  value = value.toUpperCase();
@@ -339,7 +349,14 @@ var useAutocomplete = ({
339
349
  const { id } = rest;
340
350
  const formControlProps = (0, import_utils4.pickObject)(rest, import_form_control.formControlProperties);
341
351
  const [containerProps, inputProps] = (0, import_utils4.splitObject)(
342
- (0, import_utils4.omitObject)(rest, ["id", "value", "defaultValue", "onChange", "month", "onChangeMonth"]),
352
+ (0, import_utils4.omitObject)(rest, [
353
+ "id",
354
+ "value",
355
+ "defaultValue",
356
+ "onChange",
357
+ "month",
358
+ "onChangeMonth"
359
+ ]),
343
360
  import_core4.layoutStylesProperties
344
361
  );
345
362
  const descendants = useAutocompleteDescendants();
@@ -391,9 +408,17 @@ var useAutocomplete = ({
391
408
  if (!(0, import_utils4.isArray)(value2)) {
392
409
  return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(AutocompleteOption, { value: value2, ...props, children: label }, i);
393
410
  } else {
394
- return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(AutocompleteOptionGroup, { label, ...props, children: value2.map(
395
- ({ label: label2, value: value3, ...props2 }, i2) => !(0, import_utils4.isArray)(value3) ? /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(AutocompleteOption, { value: value3, ...props2, children: label2 }, i2) : null
396
- ) }, i);
411
+ return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
412
+ AutocompleteOptionGroup,
413
+ {
414
+ label,
415
+ ...props,
416
+ children: value2.map(
417
+ ({ label: label2, value: value3, ...props2 }, i2) => !(0, import_utils4.isArray)(value3) ? /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(AutocompleteOption, { value: value3, ...props2, children: label2 }, i2) : null
418
+ )
419
+ },
420
+ i
421
+ );
397
422
  }
398
423
  });
399
424
  const isEmpty = !validChildren.length && !(computedChildren == null ? void 0 : computedChildren.length);
@@ -417,7 +442,9 @@ var useAutocomplete = ({
417
442
  const id2 = setTimeout(() => {
418
443
  if (isEmpty || isAllSelected)
419
444
  return;
420
- const first = descendants.enabledfirstValue(({ node }) => "target" in node.dataset);
445
+ const first = descendants.enabledfirstValue(
446
+ ({ node }) => "target" in node.dataset
447
+ );
421
448
  if (!first)
422
449
  return;
423
450
  if (!isMulti || !omitSelectedValues) {
@@ -445,7 +472,9 @@ var useAutocomplete = ({
445
472
  const id2 = setTimeout(() => {
446
473
  if (isEmpty || isAllSelected)
447
474
  return;
448
- const last = descendants.enabledlastValue(({ node }) => "target" in node.dataset);
475
+ const last = descendants.enabledlastValue(
476
+ ({ node }) => "target" in node.dataset
477
+ );
449
478
  if (!last)
450
479
  return;
451
480
  if (!isMulti || !omitSelectedValues) {
@@ -487,7 +516,10 @@ var useAutocomplete = ({
487
516
  (index = focusedIndex) => {
488
517
  const id2 = setTimeout(() => {
489
518
  var _a;
490
- const next = descendants.enabledNextValue(index, ({ node }) => "target" in node.dataset);
519
+ const next = descendants.enabledNextValue(
520
+ index,
521
+ ({ node }) => "target" in node.dataset
522
+ );
491
523
  if (!next)
492
524
  return;
493
525
  if (!isMulti || !omitSelectedValues) {
@@ -503,13 +535,23 @@ var useAutocomplete = ({
503
535
  });
504
536
  timeoutIds.current.add(id2);
505
537
  },
506
- [descendants, enabledValues, focusedIndex, isMulti, omitSelectedValues, selectedIndexes]
538
+ [
539
+ descendants,
540
+ enabledValues,
541
+ focusedIndex,
542
+ isMulti,
543
+ omitSelectedValues,
544
+ selectedIndexes
545
+ ]
507
546
  );
508
547
  const onFocusPrev = (0, import_react2.useCallback)(
509
548
  (index = focusedIndex) => {
510
549
  const id2 = setTimeout(() => {
511
550
  var _a;
512
- const prev = descendants.enabledPrevValue(index, ({ node }) => "target" in node.dataset);
551
+ const prev = descendants.enabledPrevValue(
552
+ index,
553
+ ({ node }) => "target" in node.dataset
554
+ );
513
555
  if (!prev)
514
556
  return;
515
557
  if (!isMulti || !omitSelectedValues) {
@@ -525,7 +567,14 @@ var useAutocomplete = ({
525
567
  });
526
568
  timeoutIds.current.add(id2);
527
569
  },
528
- [descendants, enabledValues, focusedIndex, isMulti, omitSelectedValues, selectedIndexes]
570
+ [
571
+ descendants,
572
+ enabledValues,
573
+ focusedIndex,
574
+ isMulti,
575
+ omitSelectedValues,
576
+ selectedIndexes
577
+ ]
529
578
  );
530
579
  const onFocusFirstOrSelected = isEmptyValue || omitSelectedValues ? onFocusFirst : onFocusSelected;
531
580
  const onFocusLastOrSelected = isEmptyValue || omitSelectedValues ? onFocusLast : onFocusSelected;
@@ -622,7 +671,15 @@ var useAutocomplete = ({
622
671
  onClose();
623
672
  if (omitSelectedValues)
624
673
  onFocusNext();
625
- }, [closeOnSelect, descendants, focusedIndex, omitSelectedValues, onChange, onClose, onFocusNext]);
674
+ }, [
675
+ closeOnSelect,
676
+ descendants,
677
+ focusedIndex,
678
+ omitSelectedValues,
679
+ onChange,
680
+ onClose,
681
+ onFocusNext
682
+ ]);
626
683
  const onSearch = (0, import_react2.useCallback)(
627
684
  (ev) => {
628
685
  var _a;
@@ -659,12 +716,20 @@ var useAutocomplete = ({
659
716
  } else if (firstInsertPositionOnCreate === "last") {
660
717
  newOptions = [...newOptions, newOption];
661
718
  } else {
662
- const i = newOptions.findIndex(({ label }) => label === firstInsertPositionOnCreate);
719
+ const i = newOptions.findIndex(
720
+ ({ label }) => label === firstInsertPositionOnCreate
721
+ );
663
722
  if (i !== -1 && (0, import_utils4.isArray)(newOptions[i].value)) {
664
723
  if (secondInsertPositionOnCreate === "first") {
665
- newOptions[i].value = [newOption, ...newOptions[i].value];
724
+ newOptions[i].value = [
725
+ newOption,
726
+ ...newOptions[i].value
727
+ ];
666
728
  } else {
667
- newOptions[i].value = [...newOptions[i].value, newOption];
729
+ newOptions[i].value = [
730
+ ...newOptions[i].value,
731
+ newOption
732
+ ];
668
733
  }
669
734
  } else {
670
735
  console.warn(
@@ -675,7 +740,9 @@ var useAutocomplete = ({
675
740
  setOptions(newOptions);
676
741
  onChange(inputValue);
677
742
  rebirthOptions(false);
678
- const index = flattenOptions(newOptions).findIndex(({ value: value2 }) => value2 === inputValue);
743
+ const index = flattenOptions(newOptions).findIndex(
744
+ ({ value: value2 }) => value2 === inputValue
745
+ );
679
746
  setFocusedIndex(index);
680
747
  (_a = rest.onCreate) == null ? void 0 : _a.call(rest, newOption, newOptions);
681
748
  }, [
@@ -794,7 +861,14 @@ var useAutocomplete = ({
794
861
  } else {
795
862
  setIsAllSelected(false);
796
863
  }
797
- }, [omitSelectedValues, value, descendants, isMulti, onClose, maxSelectedValues]);
864
+ }, [
865
+ omitSelectedValues,
866
+ value,
867
+ descendants,
868
+ isMulti,
869
+ onClose,
870
+ maxSelectedValues
871
+ ]);
798
872
  (0, import_utils4.useUpdateEffect)(() => {
799
873
  if (isOpen)
800
874
  return;
@@ -996,7 +1070,10 @@ var useAutocompleteList = () => {
996
1070
  role: "select",
997
1071
  tabIndex: -1,
998
1072
  ...props,
999
- onAnimationComplete: (0, import_utils4.handlerAll)(props.onAnimationComplete, onAnimationComplete)
1073
+ onAnimationComplete: (0, import_utils4.handlerAll)(
1074
+ props.onAnimationComplete,
1075
+ onAnimationComplete
1076
+ )
1000
1077
  }),
1001
1078
  [listRef, onAnimationComplete]
1002
1079
  );
@@ -1004,15 +1081,20 @@ var useAutocompleteList = () => {
1004
1081
  getListProps
1005
1082
  };
1006
1083
  };
1007
- var useAutocompleteOptionGroup = ({ label, ...rest }) => {
1084
+ var useAutocompleteOptionGroup = ({
1085
+ label,
1086
+ ...rest
1087
+ }) => {
1008
1088
  const { value, omitSelectedValues } = useAutocompleteContext();
1009
1089
  const isMulti = (0, import_utils4.isArray)(value);
1010
1090
  const descendants = useAutocompleteDescendantsContext();
1011
1091
  const values = descendants.values();
1012
- const selectedValues = isMulti && omitSelectedValues ? descendants.values(({ node }) => {
1013
- var _a;
1014
- return value.includes((_a = node.dataset.value) != null ? _a : "");
1015
- }) : [];
1092
+ const selectedValues = isMulti && omitSelectedValues ? descendants.values(
1093
+ ({ node }) => {
1094
+ var _a;
1095
+ return value.includes((_a = node.dataset.value) != null ? _a : "");
1096
+ }
1097
+ ) : [];
1016
1098
  const selectedIndexes = selectedValues.map(({ index }) => index);
1017
1099
  const childValues = values.filter(
1018
1100
  ({ node, index }) => {
@@ -1087,14 +1169,18 @@ var useAutocompleteOption = (props) => {
1087
1169
  } = { ...optionProps, ...props };
1088
1170
  const trulyDisabled = !!isDisabled && !isFocusable;
1089
1171
  const itemRef = (0, import_react2.useRef)(null);
1090
- const { index, register, descendants } = useAutocompleteDescendant({ disabled: trulyDisabled });
1172
+ const { index, register, descendants } = useAutocompleteDescendant({
1173
+ disabled: trulyDisabled
1174
+ });
1091
1175
  const values = descendants.values();
1092
1176
  const frontValues = values.slice(0, index);
1093
1177
  const isMulti = (0, import_utils4.isArray)(value);
1094
- const isDuplicated = !isMulti ? frontValues.some(({ node }) => {
1095
- var _a2;
1096
- return node.dataset.value === ((_a2 = computedProps.value) != null ? _a2 : "");
1097
- }) : false;
1178
+ const isDuplicated = !isMulti ? frontValues.some(
1179
+ ({ node }) => {
1180
+ var _a2;
1181
+ return node.dataset.value === ((_a2 = computedProps.value) != null ? _a2 : "");
1182
+ }
1183
+ ) : false;
1098
1184
  const isSelected = !isDuplicated && (!isMulti ? ((_a = computedProps.value) != null ? _a : "") === value : value.includes((_b = computedProps.value) != null ? _b : ""));
1099
1185
  const isTarget = "target" in ((_d = (_c = itemRef.current) == null ? void 0 : _c.dataset) != null ? _d : {});
1100
1186
  const isFocused = index === focusedIndex;
@@ -12,7 +12,7 @@ import {
12
12
  useAutocompleteList,
13
13
  useAutocompleteOption,
14
14
  useAutocompleteOptionGroup
15
- } from "./chunk-5O3XEEJE.mjs";
15
+ } from "./chunk-ZVZP7IWT.mjs";
16
16
  export {
17
17
  AutocompleteDescendantsContextProvider,
18
18
  AutocompleteProvider,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yamada-ui/autocomplete",
3
- "version": "0.2.10",
3
+ "version": "0.2.12",
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.5.1",
40
- "@yamada-ui/utils": "0.1.3",
41
- "@yamada-ui/icon": "0.2.6",
42
- "@yamada-ui/select": "0.2.10",
43
- "@yamada-ui/form-control": "0.2.6",
44
- "@yamada-ui/popover": "0.2.9",
45
- "@yamada-ui/use-descendant": "0.1.4",
46
- "@yamada-ui/use-clickable": "0.2.2",
47
- "@yamada-ui/use-outside-click": "0.1.3",
48
- "@yamada-ui/use-controllable-state": "0.1.4"
39
+ "@yamada-ui/core": "0.5.3",
40
+ "@yamada-ui/utils": "0.1.4",
41
+ "@yamada-ui/icon": "0.2.8",
42
+ "@yamada-ui/select": "0.2.12",
43
+ "@yamada-ui/form-control": "0.2.8",
44
+ "@yamada-ui/popover": "0.2.11",
45
+ "@yamada-ui/use-descendant": "0.1.5",
46
+ "@yamada-ui/use-clickable": "0.2.3",
47
+ "@yamada-ui/use-outside-click": "0.1.4",
48
+ "@yamada-ui/use-controllable-state": "0.1.5"
49
49
  },
50
50
  "devDependencies": {
51
51
  "react": "^18.0.0",