@yamada-ui/autocomplete 1.5.1 → 1.5.2-dev-20240917033401

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 (105) hide show
  1. package/dist/autocomplete-context.d.mts +210 -0
  2. package/dist/autocomplete-context.d.ts +210 -0
  3. package/dist/autocomplete-context.js +53 -0
  4. package/dist/autocomplete-context.js.map +1 -0
  5. package/dist/autocomplete-context.mjs +18 -0
  6. package/dist/autocomplete-context.mjs.map +1 -0
  7. package/dist/autocomplete-create.d.mts +4 -3
  8. package/dist/autocomplete-create.d.ts +4 -3
  9. package/dist/autocomplete-create.js +56 -61
  10. package/dist/autocomplete-create.js.map +1 -1
  11. package/dist/autocomplete-create.mjs +4 -1
  12. package/dist/autocomplete-empty.d.mts +4 -3
  13. package/dist/autocomplete-empty.d.ts +4 -3
  14. package/dist/autocomplete-empty.js +54 -59
  15. package/dist/autocomplete-empty.js.map +1 -1
  16. package/dist/autocomplete-empty.mjs +4 -1
  17. package/dist/autocomplete-icon.d.mts +6 -4
  18. package/dist/autocomplete-icon.d.ts +6 -4
  19. package/dist/autocomplete-icon.js +15 -22
  20. package/dist/autocomplete-icon.js.map +1 -1
  21. package/dist/autocomplete-icon.mjs +2 -1
  22. package/dist/autocomplete-list.d.mts +2 -2
  23. package/dist/autocomplete-list.d.ts +2 -2
  24. package/dist/autocomplete-list.js +20 -23
  25. package/dist/autocomplete-list.js.map +1 -1
  26. package/dist/autocomplete-list.mjs +3 -1
  27. package/dist/autocomplete-option-group.d.mts +5 -9
  28. package/dist/autocomplete-option-group.d.ts +5 -9
  29. package/dist/autocomplete-option-group.js +14 -16
  30. package/dist/autocomplete-option-group.js.map +1 -1
  31. package/dist/autocomplete-option-group.mjs +3 -1
  32. package/dist/autocomplete-option.d.mts +15 -8
  33. package/dist/autocomplete-option.d.ts +15 -8
  34. package/dist/autocomplete-option.js +97 -102
  35. package/dist/autocomplete-option.js.map +1 -1
  36. package/dist/autocomplete-option.mjs +4 -1
  37. package/dist/autocomplete.d.mts +13 -7
  38. package/dist/autocomplete.d.ts +13 -7
  39. package/dist/autocomplete.js +673 -661
  40. package/dist/autocomplete.js.map +1 -1
  41. package/dist/autocomplete.mjs +12 -1
  42. package/dist/chunk-7GCVSXCV.mjs +190 -0
  43. package/dist/chunk-7GCVSXCV.mjs.map +1 -0
  44. package/dist/chunk-BD7VZQOL.mjs +267 -0
  45. package/dist/chunk-BD7VZQOL.mjs.map +1 -0
  46. package/dist/chunk-FZM3BH3D.mjs +57 -0
  47. package/dist/chunk-FZM3BH3D.mjs.map +1 -0
  48. package/dist/chunk-GM7RV2YY.mjs +959 -0
  49. package/dist/chunk-GM7RV2YY.mjs.map +1 -0
  50. package/dist/chunk-GOMUH7TZ.mjs +60 -0
  51. package/dist/chunk-GOMUH7TZ.mjs.map +1 -0
  52. package/dist/chunk-HL2KEBRX.mjs +87 -0
  53. package/dist/chunk-HL2KEBRX.mjs.map +1 -0
  54. package/dist/chunk-JMX72TSD.mjs +78 -0
  55. package/dist/chunk-JMX72TSD.mjs.map +1 -0
  56. package/dist/chunk-JPUKYLBW.mjs +25 -0
  57. package/dist/chunk-JPUKYLBW.mjs.map +1 -0
  58. package/dist/chunk-JXFXCGZK.mjs +102 -0
  59. package/dist/chunk-JXFXCGZK.mjs.map +1 -0
  60. package/dist/chunk-KCALQJLK.mjs +59 -0
  61. package/dist/chunk-KCALQJLK.mjs.map +1 -0
  62. package/dist/chunk-PRDD3JJO.mjs +202 -0
  63. package/dist/chunk-PRDD3JJO.mjs.map +1 -0
  64. package/dist/chunk-QGOCVO2C.mjs +68 -0
  65. package/dist/chunk-QGOCVO2C.mjs.map +1 -0
  66. package/dist/chunk-QQFSHTTC.mjs +59 -0
  67. package/dist/chunk-QQFSHTTC.mjs.map +1 -0
  68. package/dist/index.d.mts +4 -1
  69. package/dist/index.d.ts +4 -1
  70. package/dist/index.js +1550 -1536
  71. package/dist/index.js.map +1 -1
  72. package/dist/index.mjs +23 -6
  73. package/dist/multi-autocomplete.d.mts +13 -7
  74. package/dist/multi-autocomplete.d.ts +13 -7
  75. package/dist/multi-autocomplete.js +1516 -1504
  76. package/dist/multi-autocomplete.js.map +1 -1
  77. package/dist/multi-autocomplete.mjs +12 -1
  78. package/dist/use-autocomplete-list.d.mts +8 -0
  79. package/dist/use-autocomplete-list.d.ts +8 -0
  80. package/dist/use-autocomplete-list.js +103 -0
  81. package/dist/use-autocomplete-list.js.map +1 -0
  82. package/dist/use-autocomplete-list.mjs +9 -0
  83. package/dist/use-autocomplete-list.mjs.map +1 -0
  84. package/dist/use-autocomplete-option-group.d.mts +16 -0
  85. package/dist/use-autocomplete-option-group.d.ts +16 -0
  86. package/dist/use-autocomplete-option-group.js +113 -0
  87. package/dist/use-autocomplete-option-group.js.map +1 -0
  88. package/dist/use-autocomplete-option-group.mjs +9 -0
  89. package/dist/use-autocomplete-option-group.mjs.map +1 -0
  90. package/dist/use-autocomplete-option.d.mts +49 -0
  91. package/dist/use-autocomplete-option.d.ts +49 -0
  92. package/dist/use-autocomplete-option.js +231 -0
  93. package/dist/use-autocomplete-option.js.map +1 -0
  94. package/dist/use-autocomplete-option.mjs +13 -0
  95. package/dist/use-autocomplete-option.mjs.map +1 -0
  96. package/dist/use-autocomplete.d.mts +188 -8
  97. package/dist/use-autocomplete.d.ts +188 -8
  98. package/dist/use-autocomplete.js +359 -481
  99. package/dist/use-autocomplete.js.map +1 -1
  100. package/dist/use-autocomplete.mjs +9 -25
  101. package/package.json +13 -13
  102. package/dist/chunk-ZD25NCFE.mjs +0 -2038
  103. package/dist/chunk-ZD25NCFE.mjs.map +0 -1
  104. package/dist/use-autocomplete-BJNWa6hL.d.mts +0 -389
  105. package/dist/use-autocomplete-BJNWa6hL.d.ts +0 -389
@@ -0,0 +1,103 @@
1
+ "use client"
2
+ "use strict";
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __export = (target, all) => {
8
+ for (var name in all)
9
+ __defProp(target, name, { get: all[name], enumerable: true });
10
+ };
11
+ var __copyProps = (to, from, except, desc) => {
12
+ if (from && typeof from === "object" || typeof from === "function") {
13
+ for (let key of __getOwnPropNames(from))
14
+ if (!__hasOwnProp.call(to, key) && key !== except)
15
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
+ }
17
+ return to;
18
+ };
19
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
20
+
21
+ // src/use-autocomplete-list.ts
22
+ var use_autocomplete_list_exports = {};
23
+ __export(use_autocomplete_list_exports, {
24
+ useAutocompleteList: () => useAutocompleteList
25
+ });
26
+ module.exports = __toCommonJS(use_autocomplete_list_exports);
27
+ var import_utils2 = require("@yamada-ui/utils");
28
+ var import_react = require("react");
29
+
30
+ // src/autocomplete-context.ts
31
+ var import_use_descendant = require("@yamada-ui/use-descendant");
32
+ var import_utils = require("@yamada-ui/utils");
33
+ var {
34
+ DescendantsContextProvider: AutocompleteDescendantsContextProvider,
35
+ useDescendantsContext: useAutocompleteDescendantsContext,
36
+ useDescendants: useAutocompleteDescendants,
37
+ useDescendant: useAutocompleteDescendant
38
+ } = (0, import_use_descendant.createDescendant)();
39
+ var [AutocompleteProvider, useAutocompleteContext] = (0, import_utils.createContext)({
40
+ name: "AutocompleteContext",
41
+ errorMessage: `useAutocompleteContext returned is 'undefined'. Seems you forgot to wrap the components in "<Autocomplete />" or "<MultiAutocomplete />"`
42
+ });
43
+
44
+ // src/use-autocomplete-list.ts
45
+ var useAutocompleteList = () => {
46
+ const { focusedIndex, isOpen, listRef, rebirthOptions } = useAutocompleteContext();
47
+ const descendants = useAutocompleteDescendantsContext();
48
+ const beforeFocusedIndex = (0, import_react.useRef)(-1);
49
+ const selectedValue = descendants.value(focusedIndex);
50
+ const onAnimationComplete = (0, import_react.useCallback)(() => {
51
+ if (!isOpen) rebirthOptions(false);
52
+ }, [isOpen, rebirthOptions]);
53
+ (0, import_react.useEffect)(() => {
54
+ if (!listRef.current || !selectedValue) return;
55
+ if (beforeFocusedIndex.current === selectedValue.index) return;
56
+ const parent = listRef.current;
57
+ const child = selectedValue.node;
58
+ const parentHeight = parent.clientHeight;
59
+ const viewTop = parent.scrollTop;
60
+ const viewBottom = viewTop + parentHeight;
61
+ const childHeight = child.clientHeight;
62
+ const childTop = child.offsetTop;
63
+ const childBottom = childTop + childHeight;
64
+ const isInView = viewTop <= childTop && childBottom <= viewBottom;
65
+ const isScrollBottom = beforeFocusedIndex.current < selectedValue.index;
66
+ if (!isInView) {
67
+ if (childBottom <= parentHeight) {
68
+ listRef.current.scrollTo({ top: 0 });
69
+ } else {
70
+ if (!isScrollBottom) {
71
+ listRef.current.scrollTo({ top: childTop + 1 });
72
+ } else {
73
+ listRef.current.scrollTo({ top: childBottom - parentHeight });
74
+ }
75
+ }
76
+ }
77
+ beforeFocusedIndex.current = selectedValue.index;
78
+ }, [listRef, selectedValue]);
79
+ (0, import_utils2.useUpdateEffect)(() => {
80
+ if (!isOpen) beforeFocusedIndex.current = -1;
81
+ }, [isOpen]);
82
+ const getListProps = (0, import_react.useCallback)(
83
+ (props = {}, ref = null) => ({
84
+ as: "ul",
85
+ ref: (0, import_utils2.mergeRefs)(listRef, ref),
86
+ role: "listbox",
87
+ tabIndex: -1,
88
+ position: "relative",
89
+ id: props.id || (0, import_react.useId)(),
90
+ ...props
91
+ }),
92
+ [listRef]
93
+ );
94
+ return {
95
+ onAnimationComplete,
96
+ getListProps
97
+ };
98
+ };
99
+ // Annotate the CommonJS export names for ESM import in node:
100
+ 0 && (module.exports = {
101
+ useAutocompleteList
102
+ });
103
+ //# sourceMappingURL=use-autocomplete-list.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/use-autocomplete-list.ts","../src/autocomplete-context.ts"],"sourcesContent":["import type { PropGetter } from \"@yamada-ui/core\"\nimport { mergeRefs, useUpdateEffect } from \"@yamada-ui/utils\"\nimport { useCallback, useEffect, useId, useRef } from \"react\"\nimport {\n useAutocompleteContext,\n useAutocompleteDescendantsContext,\n} from \"./autocomplete-context\"\n\nexport const useAutocompleteList = () => {\n const { focusedIndex, isOpen, listRef, rebirthOptions } =\n useAutocompleteContext()\n\n const descendants = useAutocompleteDescendantsContext()\n\n const beforeFocusedIndex = useRef<number>(-1)\n const selectedValue = descendants.value(focusedIndex)\n\n const onAnimationComplete = useCallback(() => {\n if (!isOpen) rebirthOptions(false)\n }, [isOpen, rebirthOptions])\n\n useEffect(() => {\n if (!listRef.current || !selectedValue) return\n\n if (beforeFocusedIndex.current === selectedValue.index) return\n\n const parent = listRef.current\n const child = selectedValue.node\n\n const parentHeight = parent.clientHeight\n const viewTop = parent.scrollTop\n const viewBottom = viewTop + parentHeight\n\n const childHeight = child.clientHeight\n const childTop = child.offsetTop\n const childBottom = childTop + childHeight\n\n const isInView = viewTop <= childTop && childBottom <= viewBottom\n\n const isScrollBottom = beforeFocusedIndex.current < selectedValue.index\n\n if (!isInView) {\n if (childBottom <= parentHeight) {\n listRef.current.scrollTo({ top: 0 })\n } else {\n if (!isScrollBottom) {\n listRef.current.scrollTo({ top: childTop + 1 })\n } else {\n listRef.current.scrollTo({ top: childBottom - parentHeight })\n }\n }\n }\n\n beforeFocusedIndex.current = selectedValue.index\n }, [listRef, selectedValue])\n\n useUpdateEffect(() => {\n if (!isOpen) beforeFocusedIndex.current = -1\n }, [isOpen])\n\n const getListProps: PropGetter<\"ul\"> = useCallback(\n (props = {}, ref = null) => ({\n as: \"ul\",\n ref: mergeRefs(listRef, ref),\n role: \"listbox\",\n tabIndex: -1,\n position: \"relative\",\n id: props.id || useId(),\n ...props,\n }),\n [listRef],\n )\n\n return {\n onAnimationComplete,\n getListProps,\n }\n}\n","import type { CSSUIObject } from \"@yamada-ui/core\"\nimport { createDescendant } from \"@yamada-ui/use-descendant\"\nimport { createContext } from \"@yamada-ui/utils\"\nimport type { Dispatch, DOMAttributes, RefObject, SetStateAction } from \"react\"\nimport type { ChangeOptions, UseAutocompleteProps } from \"./use-autocomplete\"\n\nexport const {\n DescendantsContextProvider: AutocompleteDescendantsContextProvider,\n useDescendantsContext: useAutocompleteDescendantsContext,\n useDescendants: useAutocompleteDescendants,\n useDescendant: useAutocompleteDescendant,\n} = createDescendant()\n\ninterface AutocompleteContext\n extends Omit<\n UseAutocompleteProps,\n \"value\" | \"defaultValue\" | \"onChange\" | \"onCreate\"\n > {\n value: string | string[]\n label: string | string[] | undefined\n inputValue: string\n isHit: boolean\n isEmpty: boolean\n isAllSelected: boolean\n onChange: (newValue: string, options?: ChangeOptions) => void\n onChangeLabel: (newValue: string, options?: ChangeOptions) => void\n pickOptions: (value: string) => void\n rebirthOptions: (runFocus?: boolean) => void\n inputProps: DOMAttributes<HTMLInputElement>\n isOpen: boolean\n onOpen: () => void\n onClose: () => void\n onCreate: () => void\n onFocusFirst: () => void\n onFocusLast: () => void\n onFocusNext: (index?: number) => void\n onFocusPrev: (index?: number) => void\n focusedIndex: number\n setFocusedIndex: Dispatch<SetStateAction<number>>\n listRef: RefObject<HTMLUListElement>\n inputRef: RefObject<HTMLInputElement>\n formControlProps: { [key: string]: any }\n styles: { [key: string]: CSSUIObject }\n}\n\nexport const [AutocompleteProvider, useAutocompleteContext] =\n createContext<AutocompleteContext>({\n name: \"AutocompleteContext\",\n errorMessage: `useAutocompleteContext returned is 'undefined'. Seems you forgot to wrap the components in \"<Autocomplete />\" or \"<MultiAutocomplete />\"`,\n })\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,IAAAA,gBAA2C;AAC3C,mBAAsD;;;ACDtD,4BAAiC;AACjC,mBAA8B;AAIvB,IAAM;AAAA,EACX,4BAA4B;AAAA,EAC5B,uBAAuB;AAAA,EACvB,gBAAgB;AAAA,EAChB,eAAe;AACjB,QAAI,wCAAiB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A,EAC5C,GAAG,CAAC,MAAM,CAAC;AAEX,QAAM,mBAAiC;AAAA,IACrC,CAAC,QAAQ,CAAC,GAAG,MAAM,UAAU;AAAA,MAC3B,IAAI;AAAA,MACJ,SAAK,yBAAU,SAAS,GAAG;AAAA,MAC3B,MAAM;AAAA,MACN,UAAU;AAAA,MACV,UAAU;AAAA,MACV,IAAI,MAAM,UAAM,oBAAM;AAAA,MACtB,GAAG;AAAA,IACL;AAAA,IACA,CAAC,OAAO;AAAA,EACV;AAEA,SAAO;AAAA,IACL;AAAA,IACA;AAAA,EACF;AACF;","names":["import_utils"]}
@@ -0,0 +1,9 @@
1
+ "use client"
2
+ import {
3
+ useAutocompleteList
4
+ } from "./chunk-QGOCVO2C.mjs";
5
+ import "./chunk-JPUKYLBW.mjs";
6
+ export {
7
+ useAutocompleteList
8
+ };
9
+ //# sourceMappingURL=use-autocomplete-list.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
@@ -0,0 +1,16 @@
1
+ import { HTMLUIProps, PropGetter } from '@yamada-ui/core';
2
+
3
+ interface UseAutocompleteOptionGroupProps extends HTMLUIProps<"ul"> {
4
+ /**
5
+ * The label of the autocomplete option group.
6
+ */
7
+ label: string;
8
+ }
9
+ declare const useAutocompleteOptionGroup: ({ label, ...rest }: UseAutocompleteOptionGroupProps) => {
10
+ label: string;
11
+ getContainerProps: PropGetter<"li", undefined>;
12
+ getGroupProps: PropGetter<"ul", undefined>;
13
+ };
14
+ type UseAutocompleteOptionGroupReturn = ReturnType<typeof useAutocompleteOptionGroup>;
15
+
16
+ export { type UseAutocompleteOptionGroupProps, type UseAutocompleteOptionGroupReturn, useAutocompleteOptionGroup };
@@ -0,0 +1,16 @@
1
+ import { HTMLUIProps, PropGetter } from '@yamada-ui/core';
2
+
3
+ interface UseAutocompleteOptionGroupProps extends HTMLUIProps<"ul"> {
4
+ /**
5
+ * The label of the autocomplete option group.
6
+ */
7
+ label: string;
8
+ }
9
+ declare const useAutocompleteOptionGroup: ({ label, ...rest }: UseAutocompleteOptionGroupProps) => {
10
+ label: string;
11
+ getContainerProps: PropGetter<"li", undefined>;
12
+ getGroupProps: PropGetter<"ul", undefined>;
13
+ };
14
+ type UseAutocompleteOptionGroupReturn = ReturnType<typeof useAutocompleteOptionGroup>;
15
+
16
+ export { type UseAutocompleteOptionGroupProps, type UseAutocompleteOptionGroupReturn, useAutocompleteOptionGroup };
@@ -0,0 +1,113 @@
1
+ "use client"
2
+ "use strict";
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __export = (target, all) => {
8
+ for (var name in all)
9
+ __defProp(target, name, { get: all[name], enumerable: true });
10
+ };
11
+ var __copyProps = (to, from, except, desc) => {
12
+ if (from && typeof from === "object" || typeof from === "function") {
13
+ for (let key of __getOwnPropNames(from))
14
+ if (!__hasOwnProp.call(to, key) && key !== except)
15
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
+ }
17
+ return to;
18
+ };
19
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
20
+
21
+ // src/use-autocomplete-option-group.ts
22
+ var use_autocomplete_option_group_exports = {};
23
+ __export(use_autocomplete_option_group_exports, {
24
+ useAutocompleteOptionGroup: () => useAutocompleteOptionGroup
25
+ });
26
+ module.exports = __toCommonJS(use_autocomplete_option_group_exports);
27
+ var import_core = require("@yamada-ui/core");
28
+ var import_utils2 = require("@yamada-ui/utils");
29
+ var import_react = require("react");
30
+
31
+ // src/autocomplete-context.ts
32
+ var import_use_descendant = require("@yamada-ui/use-descendant");
33
+ var import_utils = require("@yamada-ui/utils");
34
+ var {
35
+ DescendantsContextProvider: AutocompleteDescendantsContextProvider,
36
+ useDescendantsContext: useAutocompleteDescendantsContext,
37
+ useDescendants: useAutocompleteDescendants,
38
+ useDescendant: useAutocompleteDescendant
39
+ } = (0, import_use_descendant.createDescendant)();
40
+ var [AutocompleteProvider, useAutocompleteContext] = (0, import_utils.createContext)({
41
+ name: "AutocompleteContext",
42
+ errorMessage: `useAutocompleteContext returned is 'undefined'. Seems you forgot to wrap the components in "<Autocomplete />" or "<MultiAutocomplete />"`
43
+ });
44
+
45
+ // src/use-autocomplete-option-group.ts
46
+ var useAutocompleteOptionGroup = ({
47
+ label,
48
+ ...rest
49
+ }) => {
50
+ const { value, omitSelectedValues } = useAutocompleteContext();
51
+ const isMulti = (0, import_utils2.isArray)(value);
52
+ const descendants = useAutocompleteDescendantsContext();
53
+ const values = descendants.values();
54
+ const selectedValues = isMulti && omitSelectedValues ? descendants.values(
55
+ ({ node }) => {
56
+ var _a;
57
+ return value.includes((_a = node.dataset.value) != null ? _a : "");
58
+ }
59
+ ) : [];
60
+ const selectedIndexes = selectedValues.map(({ index }) => index);
61
+ const childValues = values.filter(
62
+ ({ node, index }) => {
63
+ var _a;
64
+ return ((_a = node.parentElement) == null ? void 0 : _a.dataset.label) === label && !selectedIndexes.includes(index) && "target" in node.dataset;
65
+ }
66
+ );
67
+ const isEmpty = !childValues.length;
68
+ const [containerProps, groupProps] = (0, import_utils2.splitObject)(rest, import_core.layoutStyleProperties);
69
+ const getContainerProps = (0, import_react.useCallback)(
70
+ (props = {}, ref = null) => {
71
+ const style = {
72
+ border: "0px",
73
+ clip: "rect(0px, 0px, 0px, 0px)",
74
+ height: "1px",
75
+ width: "1px",
76
+ margin: "-1px",
77
+ padding: "0px",
78
+ overflow: "hidden",
79
+ whiteSpace: "nowrap",
80
+ position: "absolute"
81
+ };
82
+ return {
83
+ ref,
84
+ ...props,
85
+ ...containerProps,
86
+ style: isEmpty ? style : void 0,
87
+ "data-label": label,
88
+ role: "autocomplete-group-container"
89
+ };
90
+ },
91
+ [containerProps, isEmpty, label]
92
+ );
93
+ const getGroupProps = (0, import_react.useCallback)(
94
+ (props = {}, ref = null) => ({
95
+ ref,
96
+ ...props,
97
+ ...groupProps,
98
+ "data-label": label,
99
+ role: "autocomplete-group"
100
+ }),
101
+ [groupProps, label]
102
+ );
103
+ return {
104
+ label,
105
+ getContainerProps,
106
+ getGroupProps
107
+ };
108
+ };
109
+ // Annotate the CommonJS export names for ESM import in node:
110
+ 0 && (module.exports = {
111
+ useAutocompleteOptionGroup
112
+ });
113
+ //# sourceMappingURL=use-autocomplete-option-group.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/use-autocomplete-option-group.ts","../src/autocomplete-context.ts"],"sourcesContent":["import type { HTMLUIProps, PropGetter } from \"@yamada-ui/core\"\nimport { layoutStyleProperties } from \"@yamada-ui/core\"\nimport { isArray, splitObject } from \"@yamada-ui/utils\"\nimport type { CSSProperties } from \"react\"\nimport { useCallback } from \"react\"\nimport {\n useAutocompleteContext,\n useAutocompleteDescendantsContext,\n} from \"./autocomplete-context\"\n\nexport interface UseAutocompleteOptionGroupProps extends HTMLUIProps<\"ul\"> {\n /**\n * The label of the autocomplete option group.\n */\n label: string\n}\n\nexport const useAutocompleteOptionGroup = ({\n label,\n ...rest\n}: UseAutocompleteOptionGroupProps) => {\n const { value, omitSelectedValues } = useAutocompleteContext()\n\n const isMulti = isArray(value)\n\n const descendants = useAutocompleteDescendantsContext()\n\n const values = descendants.values()\n const selectedValues =\n isMulti && omitSelectedValues\n ? descendants.values(({ node }) =>\n value.includes(node.dataset.value ?? \"\"),\n )\n : []\n const selectedIndexes = selectedValues.map(({ index }) => index)\n const childValues = values.filter(\n ({ node, index }) =>\n node.parentElement?.dataset.label === label &&\n !selectedIndexes.includes(index) &&\n \"target\" in node.dataset,\n )\n\n const isEmpty = !childValues.length\n\n const [containerProps, groupProps] = splitObject(rest, layoutStyleProperties)\n\n const getContainerProps: PropGetter<\"li\"> = useCallback(\n (props = {}, ref = null) => {\n const style: CSSProperties = {\n border: \"0px\",\n clip: \"rect(0px, 0px, 0px, 0px)\",\n height: \"1px\",\n width: \"1px\",\n margin: \"-1px\",\n padding: \"0px\",\n overflow: \"hidden\",\n whiteSpace: \"nowrap\",\n position: \"absolute\",\n }\n\n return {\n ref,\n ...props,\n ...containerProps,\n style: isEmpty ? style : undefined,\n \"data-label\": label,\n role: \"autocomplete-group-container\",\n }\n },\n [containerProps, isEmpty, label],\n )\n\n const getGroupProps: PropGetter<\"ul\"> = useCallback(\n (props = {}, ref = null) => ({\n ref,\n ...props,\n ...groupProps,\n \"data-label\": label,\n role: \"autocomplete-group\",\n }),\n [groupProps, label],\n )\n\n return {\n label,\n getContainerProps,\n getGroupProps,\n }\n}\n\nexport type UseAutocompleteOptionGroupReturn = ReturnType<\n typeof useAutocompleteOptionGroup\n>\n","import type { CSSUIObject } from \"@yamada-ui/core\"\nimport { createDescendant } from \"@yamada-ui/use-descendant\"\nimport { createContext } from \"@yamada-ui/utils\"\nimport type { Dispatch, DOMAttributes, RefObject, SetStateAction } from \"react\"\nimport type { ChangeOptions, UseAutocompleteProps } from \"./use-autocomplete\"\n\nexport const {\n DescendantsContextProvider: AutocompleteDescendantsContextProvider,\n useDescendantsContext: useAutocompleteDescendantsContext,\n useDescendants: useAutocompleteDescendants,\n useDescendant: useAutocompleteDescendant,\n} = createDescendant()\n\ninterface AutocompleteContext\n extends Omit<\n UseAutocompleteProps,\n \"value\" | \"defaultValue\" | \"onChange\" | \"onCreate\"\n > {\n value: string | string[]\n label: string | string[] | undefined\n inputValue: string\n isHit: boolean\n isEmpty: boolean\n isAllSelected: boolean\n onChange: (newValue: string, options?: ChangeOptions) => void\n onChangeLabel: (newValue: string, options?: ChangeOptions) => void\n pickOptions: (value: string) => void\n rebirthOptions: (runFocus?: boolean) => void\n inputProps: DOMAttributes<HTMLInputElement>\n isOpen: boolean\n onOpen: () => void\n onClose: () => void\n onCreate: () => void\n onFocusFirst: () => void\n onFocusLast: () => void\n onFocusNext: (index?: number) => void\n onFocusPrev: (index?: number) => void\n focusedIndex: number\n setFocusedIndex: Dispatch<SetStateAction<number>>\n listRef: RefObject<HTMLUListElement>\n inputRef: RefObject<HTMLInputElement>\n formControlProps: { [key: string]: any }\n styles: { [key: string]: CSSUIObject }\n}\n\nexport const [AutocompleteProvider, useAutocompleteContext] =\n createContext<AutocompleteContext>({\n name: \"AutocompleteContext\",\n errorMessage: `useAutocompleteContext returned is 'undefined'. Seems you forgot to wrap the components in \"<Autocomplete />\" or \"<MultiAutocomplete />\"`,\n })\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,kBAAsC;AACtC,IAAAA,gBAAqC;AAErC,mBAA4B;;;ACH5B,4BAAiC;AACjC,mBAA8B;AAIvB,IAAM;AAAA,EACX,4BAA4B;AAAA,EAC5B,uBAAuB;AAAA,EACvB,gBAAgB;AAAA,EAChB,eAAe;AACjB,QAAI,wCAAiB;AAkCd,IAAM,CAAC,sBAAsB,sBAAsB,QACxD,4BAAmC;AAAA,EACjC,MAAM;AAAA,EACN,cAAc;AAChB,CAAC;;;ADhCI,IAAM,6BAA6B,CAAC;AAAA,EACzC;AAAA,EACA,GAAG;AACL,MAAuC;AACrC,QAAM,EAAE,OAAO,mBAAmB,IAAI,uBAAuB;AAE7D,QAAM,cAAU,uBAAQ,KAAK;AAE7B,QAAM,cAAc,kCAAkC;AAEtD,QAAM,SAAS,YAAY,OAAO;AAClC,QAAM,iBACJ,WAAW,qBACP,YAAY;AAAA,IAAO,CAAC,EAAE,KAAK,MAAG;AA9BtC;AA+BU,mBAAM,UAAS,UAAK,QAAQ,UAAb,YAAsB,EAAE;AAAA;AAAA,EACzC,IACA,CAAC;AACP,QAAM,kBAAkB,eAAe,IAAI,CAAC,EAAE,MAAM,MAAM,KAAK;AAC/D,QAAM,cAAc,OAAO;AAAA,IACzB,CAAC,EAAE,MAAM,MAAM,MAAG;AApCtB;AAqCM,yBAAK,kBAAL,mBAAoB,QAAQ,WAAU,SACtC,CAAC,gBAAgB,SAAS,KAAK,KAC/B,YAAY,KAAK;AAAA;AAAA,EACrB;AAEA,QAAM,UAAU,CAAC,YAAY;AAE7B,QAAM,CAAC,gBAAgB,UAAU,QAAI,2BAAY,MAAM,iCAAqB;AAE5E,QAAM,wBAAsC;AAAA,IAC1C,CAAC,QAAQ,CAAC,GAAG,MAAM,SAAS;AAC1B,YAAM,QAAuB;AAAA,QAC3B,QAAQ;AAAA,QACR,MAAM;AAAA,QACN,QAAQ;AAAA,QACR,OAAO;AAAA,QACP,QAAQ;AAAA,QACR,SAAS;AAAA,QACT,UAAU;AAAA,QACV,YAAY;AAAA,QACZ,UAAU;AAAA,MACZ;AAEA,aAAO;AAAA,QACL;AAAA,QACA,GAAG;AAAA,QACH,GAAG;AAAA,QACH,OAAO,UAAU,QAAQ;AAAA,QACzB,cAAc;AAAA,QACd,MAAM;AAAA,MACR;AAAA,IACF;AAAA,IACA,CAAC,gBAAgB,SAAS,KAAK;AAAA,EACjC;AAEA,QAAM,oBAAkC;AAAA,IACtC,CAAC,QAAQ,CAAC,GAAG,MAAM,UAAU;AAAA,MAC3B;AAAA,MACA,GAAG;AAAA,MACH,GAAG;AAAA,MACH,cAAc;AAAA,MACd,MAAM;AAAA,IACR;AAAA,IACA,CAAC,YAAY,KAAK;AAAA,EACpB;AAEA,SAAO;AAAA,IACL;AAAA,IACA;AAAA,IACA;AAAA,EACF;AACF;","names":["import_utils"]}
@@ -0,0 +1,9 @@
1
+ "use client"
2
+ import {
3
+ useAutocompleteOptionGroup
4
+ } from "./chunk-JMX72TSD.mjs";
5
+ import "./chunk-JPUKYLBW.mjs";
6
+ export {
7
+ useAutocompleteOptionGroup
8
+ };
9
+ //# sourceMappingURL=use-autocomplete-option-group.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
@@ -0,0 +1,49 @@
1
+ import * as react from 'react';
2
+ import { HTMLUIProps, PropGetter } from '@yamada-ui/core';
3
+
4
+ interface UseAutocompleteOptionProps extends Omit<HTMLUIProps<"li">, "value" | "children"> {
5
+ /**
6
+ * The value of the select option.
7
+ */
8
+ value?: string;
9
+ /**
10
+ * The label of the select option.
11
+ */
12
+ children?: string;
13
+ /**
14
+ * If `true`, the select option will be disabled.
15
+ *
16
+ * @default false
17
+ */
18
+ isDisabled?: boolean;
19
+ /**
20
+ * If `true`, the select option will be focusable.
21
+ *
22
+ * @default false
23
+ */
24
+ isFocusable?: boolean;
25
+ /**
26
+ * If `true`, the list element will be closed when selected.
27
+ *
28
+ * @default false
29
+ */
30
+ closeOnSelect?: boolean;
31
+ }
32
+ declare const useAutocompleteOption: (props: UseAutocompleteOptionProps) => {
33
+ isSelected: boolean;
34
+ isFocused: boolean;
35
+ customIcon: react.ReactElement<any, string | react.JSXElementConstructor<any>> | undefined;
36
+ children: string | undefined;
37
+ getOptionProps: PropGetter<"li", undefined>;
38
+ };
39
+ type UseAutocompleteOptionReturn = ReturnType<typeof useAutocompleteOption>;
40
+ declare const useAutocompleteCreate: () => {
41
+ getCreateProps: PropGetter<"li", undefined>;
42
+ };
43
+ type UseAutocompleteCreateReturn = ReturnType<typeof useAutocompleteCreate>;
44
+ declare const useAutocompleteEmpty: () => {
45
+ getEmptyProps: PropGetter<"li", undefined>;
46
+ };
47
+ type UseAutocompleteEmptyReturn = ReturnType<typeof useAutocompleteEmpty>;
48
+
49
+ export { type UseAutocompleteCreateReturn, type UseAutocompleteEmptyReturn, type UseAutocompleteOptionProps, type UseAutocompleteOptionReturn, useAutocompleteCreate, useAutocompleteEmpty, useAutocompleteOption };
@@ -0,0 +1,49 @@
1
+ import * as react from 'react';
2
+ import { HTMLUIProps, PropGetter } from '@yamada-ui/core';
3
+
4
+ interface UseAutocompleteOptionProps extends Omit<HTMLUIProps<"li">, "value" | "children"> {
5
+ /**
6
+ * The value of the select option.
7
+ */
8
+ value?: string;
9
+ /**
10
+ * The label of the select option.
11
+ */
12
+ children?: string;
13
+ /**
14
+ * If `true`, the select option will be disabled.
15
+ *
16
+ * @default false
17
+ */
18
+ isDisabled?: boolean;
19
+ /**
20
+ * If `true`, the select option will be focusable.
21
+ *
22
+ * @default false
23
+ */
24
+ isFocusable?: boolean;
25
+ /**
26
+ * If `true`, the list element will be closed when selected.
27
+ *
28
+ * @default false
29
+ */
30
+ closeOnSelect?: boolean;
31
+ }
32
+ declare const useAutocompleteOption: (props: UseAutocompleteOptionProps) => {
33
+ isSelected: boolean;
34
+ isFocused: boolean;
35
+ customIcon: react.ReactElement<any, string | react.JSXElementConstructor<any>> | undefined;
36
+ children: string | undefined;
37
+ getOptionProps: PropGetter<"li", undefined>;
38
+ };
39
+ type UseAutocompleteOptionReturn = ReturnType<typeof useAutocompleteOption>;
40
+ declare const useAutocompleteCreate: () => {
41
+ getCreateProps: PropGetter<"li", undefined>;
42
+ };
43
+ type UseAutocompleteCreateReturn = ReturnType<typeof useAutocompleteCreate>;
44
+ declare const useAutocompleteEmpty: () => {
45
+ getEmptyProps: PropGetter<"li", undefined>;
46
+ };
47
+ type UseAutocompleteEmptyReturn = ReturnType<typeof useAutocompleteEmpty>;
48
+
49
+ export { type UseAutocompleteCreateReturn, type UseAutocompleteEmptyReturn, type UseAutocompleteOptionProps, type UseAutocompleteOptionReturn, useAutocompleteCreate, useAutocompleteEmpty, useAutocompleteOption };
@@ -0,0 +1,231 @@
1
+ "use client"
2
+ "use strict";
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __export = (target, all) => {
8
+ for (var name in all)
9
+ __defProp(target, name, { get: all[name], enumerable: true });
10
+ };
11
+ var __copyProps = (to, from, except, desc) => {
12
+ if (from && typeof from === "object" || typeof from === "function") {
13
+ for (let key of __getOwnPropNames(from))
14
+ if (!__hasOwnProp.call(to, key) && key !== except)
15
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
+ }
17
+ return to;
18
+ };
19
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
20
+
21
+ // src/use-autocomplete-option.ts
22
+ var use_autocomplete_option_exports = {};
23
+ __export(use_autocomplete_option_exports, {
24
+ useAutocompleteCreate: () => useAutocompleteCreate,
25
+ useAutocompleteEmpty: () => useAutocompleteEmpty,
26
+ useAutocompleteOption: () => useAutocompleteOption
27
+ });
28
+ module.exports = __toCommonJS(use_autocomplete_option_exports);
29
+ var import_utils2 = require("@yamada-ui/utils");
30
+ var import_react = require("react");
31
+
32
+ // src/autocomplete-context.ts
33
+ var import_use_descendant = require("@yamada-ui/use-descendant");
34
+ var import_utils = require("@yamada-ui/utils");
35
+ var {
36
+ DescendantsContextProvider: AutocompleteDescendantsContextProvider,
37
+ useDescendantsContext: useAutocompleteDescendantsContext,
38
+ useDescendants: useAutocompleteDescendants,
39
+ useDescendant: useAutocompleteDescendant
40
+ } = (0, import_use_descendant.createDescendant)();
41
+ var [AutocompleteProvider, useAutocompleteContext] = (0, import_utils.createContext)({
42
+ name: "AutocompleteContext",
43
+ errorMessage: `useAutocompleteContext returned is 'undefined'. Seems you forgot to wrap the components in "<Autocomplete />" or "<MultiAutocomplete />"`
44
+ });
45
+
46
+ // src/use-autocomplete-option.ts
47
+ var isTargetOption = (target) => {
48
+ var _a;
49
+ return (0, import_utils2.isHTMLElement)(target) && !!((_a = target == null ? void 0 : target.getAttribute("role")) == null ? void 0 : _a.startsWith("option"));
50
+ };
51
+ var useAutocompleteOption = (props) => {
52
+ var _a, _b;
53
+ const {
54
+ value,
55
+ omitSelectedValues,
56
+ onChange,
57
+ onChangeLabel,
58
+ focusedIndex,
59
+ setFocusedIndex,
60
+ onClose,
61
+ closeOnSelect: generalCloseOnSelect,
62
+ optionProps,
63
+ inputRef,
64
+ onFocusNext
65
+ } = useAutocompleteContext();
66
+ let {
67
+ icon: customIcon,
68
+ isDisabled,
69
+ isFocusable,
70
+ closeOnSelect: customCloseOnSelect,
71
+ children,
72
+ value: optionValue,
73
+ ...computedProps
74
+ } = { ...optionProps, ...props };
75
+ const trulyDisabled = !!isDisabled && !isFocusable;
76
+ const itemRef = (0, import_react.useRef)(null);
77
+ const { index, register, descendants } = useAutocompleteDescendant({
78
+ disabled: trulyDisabled
79
+ });
80
+ const values = descendants.values();
81
+ const frontValues = values.slice(0, index);
82
+ const isMulti = (0, import_utils2.isArray)(value);
83
+ const isDuplicated = !isMulti ? frontValues.some(({ node }) => node.dataset.value === (optionValue != null ? optionValue : "")) : false;
84
+ const isSelected = !isDuplicated && (!isMulti ? (optionValue != null ? optionValue : "") === value : value.includes(optionValue != null ? optionValue : ""));
85
+ const isTarget = "target" in ((_b = (_a = itemRef.current) == null ? void 0 : _a.dataset) != null ? _b : {});
86
+ const isFocused = index === focusedIndex;
87
+ const onClick = (0, import_react.useCallback)(
88
+ (ev) => {
89
+ ev.stopPropagation();
90
+ if (isDisabled) {
91
+ if (inputRef.current) inputRef.current.focus();
92
+ return;
93
+ }
94
+ if (!isTargetOption(ev.currentTarget)) {
95
+ if (inputRef.current) inputRef.current.focus();
96
+ return;
97
+ }
98
+ setFocusedIndex(index);
99
+ onChange(optionValue != null ? optionValue : "");
100
+ if (inputRef.current) inputRef.current.focus();
101
+ if (customCloseOnSelect != null ? customCloseOnSelect : generalCloseOnSelect) onClose();
102
+ if (omitSelectedValues) onFocusNext(index);
103
+ },
104
+ [
105
+ onFocusNext,
106
+ omitSelectedValues,
107
+ isDisabled,
108
+ optionValue,
109
+ setFocusedIndex,
110
+ index,
111
+ onChange,
112
+ customCloseOnSelect,
113
+ generalCloseOnSelect,
114
+ onClose,
115
+ inputRef
116
+ ]
117
+ );
118
+ (0, import_utils2.useUpdateEffect)(() => {
119
+ if (isSelected) onChangeLabel(optionValue != null ? optionValue : "", { runOmit: false });
120
+ }, [optionValue]);
121
+ const getOptionProps = (0, import_react.useCallback)(
122
+ (props2 = {}, ref = null) => {
123
+ const style = {
124
+ border: "0px",
125
+ clip: "rect(0px, 0px, 0px, 0px)",
126
+ height: "1px",
127
+ width: "1px",
128
+ margin: "-1px",
129
+ padding: "0px",
130
+ overflow: "hidden",
131
+ whiteSpace: "nowrap",
132
+ position: "absolute"
133
+ };
134
+ return {
135
+ ref: (0, import_utils2.mergeRefs)(itemRef, ref, register),
136
+ id: (0, import_react.useId)(),
137
+ role: "option",
138
+ ...computedProps,
139
+ ...props2,
140
+ tabIndex: -1,
141
+ style: !isTarget || omitSelectedValues && isSelected ? style : void 0,
142
+ "data-target": (0, import_utils2.dataAttr)(true),
143
+ "data-value": optionValue != null ? optionValue : "",
144
+ "data-focus": (0, import_utils2.dataAttr)(isFocused),
145
+ "data-disabled": (0, import_utils2.dataAttr)(isDisabled),
146
+ "aria-checked": isSelected,
147
+ "aria-disabled": (0, import_utils2.ariaAttr)(isDisabled),
148
+ onClick: (0, import_utils2.handlerAll)(computedProps.onClick, props2.onClick, onClick)
149
+ };
150
+ },
151
+ [
152
+ optionValue,
153
+ computedProps,
154
+ isDisabled,
155
+ isFocused,
156
+ isSelected,
157
+ isTarget,
158
+ omitSelectedValues,
159
+ onClick,
160
+ register
161
+ ]
162
+ );
163
+ return {
164
+ isSelected,
165
+ isFocused,
166
+ customIcon,
167
+ children,
168
+ getOptionProps
169
+ };
170
+ };
171
+ var useAutocompleteCreate = () => {
172
+ const { isHit, onCreate } = useAutocompleteContext();
173
+ const getCreateProps = (0, import_react.useCallback)(
174
+ (props = {}, ref = null) => {
175
+ const style = {
176
+ border: "0px",
177
+ clip: "rect(0px, 0px, 0px, 0px)",
178
+ height: "1px",
179
+ width: "1px",
180
+ margin: "-1px",
181
+ padding: "0px",
182
+ overflow: "hidden",
183
+ whiteSpace: "nowrap",
184
+ position: "absolute"
185
+ };
186
+ return {
187
+ ref,
188
+ ...props,
189
+ tabIndex: -1,
190
+ style: isHit ? style : void 0,
191
+ "data-focus": (0, import_utils2.dataAttr)(!isHit),
192
+ onClick: (0, import_utils2.handlerAll)(props.onClick, onCreate)
193
+ };
194
+ },
195
+ [isHit, onCreate]
196
+ );
197
+ return { getCreateProps };
198
+ };
199
+ var useAutocompleteEmpty = () => {
200
+ const { isHit, isEmpty } = useAutocompleteContext();
201
+ const getEmptyProps = (0, import_react.useCallback)(
202
+ (props = {}, ref = null) => {
203
+ const style = {
204
+ border: "0px",
205
+ clip: "rect(0px, 0px, 0px, 0px)",
206
+ height: "1px",
207
+ width: "1px",
208
+ margin: "-1px",
209
+ padding: "0px",
210
+ overflow: "hidden",
211
+ whiteSpace: "nowrap",
212
+ position: "absolute"
213
+ };
214
+ return {
215
+ ref,
216
+ ...props,
217
+ tabIndex: -1,
218
+ style: isHit && !isEmpty ? style : void 0
219
+ };
220
+ },
221
+ [isHit, isEmpty]
222
+ );
223
+ return { getEmptyProps };
224
+ };
225
+ // Annotate the CommonJS export names for ESM import in node:
226
+ 0 && (module.exports = {
227
+ useAutocompleteCreate,
228
+ useAutocompleteEmpty,
229
+ useAutocompleteOption
230
+ });
231
+ //# sourceMappingURL=use-autocomplete-option.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/use-autocomplete-option.ts","../src/autocomplete-context.ts"],"sourcesContent":["import type { HTMLUIProps, PropGetter } from \"@yamada-ui/core\"\nimport {\n ariaAttr,\n dataAttr,\n handlerAll,\n isArray,\n isHTMLElement,\n mergeRefs,\n useUpdateEffect,\n} from \"@yamada-ui/utils\"\nimport type { CSSProperties, MouseEvent } from \"react\"\nimport { useCallback, useId, useRef } from \"react\"\nimport {\n useAutocompleteContext,\n useAutocompleteDescendant,\n} from \"./autocomplete-context\"\n\nconst isTargetOption = (target: EventTarget | null): boolean =>\n isHTMLElement(target) && !!target?.getAttribute(\"role\")?.startsWith(\"option\")\n\nexport interface UseAutocompleteOptionProps\n extends Omit<HTMLUIProps<\"li\">, \"value\" | \"children\"> {\n /**\n * The value of the select option.\n */\n value?: string\n /**\n * The label of the select option.\n */\n children?: string\n /**\n * If `true`, the select option will be disabled.\n *\n * @default false\n */\n isDisabled?: boolean\n /**\n * If `true`, the select option will be focusable.\n *\n * @default false\n */\n isFocusable?: boolean\n /**\n * If `true`, the list element will be closed when selected.\n *\n * @default false\n */\n closeOnSelect?: boolean\n}\n\nexport const useAutocompleteOption = (props: UseAutocompleteOptionProps) => {\n const {\n value,\n omitSelectedValues,\n onChange,\n onChangeLabel,\n focusedIndex,\n setFocusedIndex,\n onClose,\n closeOnSelect: generalCloseOnSelect,\n optionProps,\n inputRef,\n onFocusNext,\n } = useAutocompleteContext()\n\n let {\n icon: customIcon,\n isDisabled,\n isFocusable,\n closeOnSelect: customCloseOnSelect,\n children,\n value: optionValue,\n ...computedProps\n } = { ...optionProps, ...props }\n\n const trulyDisabled = !!isDisabled && !isFocusable\n\n const itemRef = useRef<HTMLLIElement>(null)\n\n const { index, register, descendants } = useAutocompleteDescendant({\n disabled: trulyDisabled,\n })\n\n const values = descendants.values()\n const frontValues = values.slice(0, index)\n\n const isMulti = isArray(value)\n const isDuplicated = !isMulti\n ? frontValues.some(({ node }) => node.dataset.value === (optionValue ?? \"\"))\n : false\n\n const isSelected =\n !isDuplicated &&\n (!isMulti\n ? (optionValue ?? \"\") === value\n : value.includes(optionValue ?? \"\"))\n const isTarget = \"target\" in (itemRef.current?.dataset ?? {})\n const isFocused = index === focusedIndex\n\n const onClick = useCallback(\n (ev: MouseEvent<HTMLLIElement>) => {\n ev.stopPropagation()\n\n if (isDisabled) {\n if (inputRef.current) inputRef.current.focus()\n\n return\n }\n\n if (!isTargetOption(ev.currentTarget)) {\n if (inputRef.current) inputRef.current.focus()\n\n return\n }\n\n setFocusedIndex(index)\n\n onChange(optionValue ?? \"\")\n\n if (inputRef.current) inputRef.current.focus()\n\n if (customCloseOnSelect ?? generalCloseOnSelect) onClose()\n\n if (omitSelectedValues) onFocusNext(index)\n },\n [\n onFocusNext,\n omitSelectedValues,\n isDisabled,\n optionValue,\n setFocusedIndex,\n index,\n onChange,\n customCloseOnSelect,\n generalCloseOnSelect,\n onClose,\n inputRef,\n ],\n )\n\n useUpdateEffect(() => {\n if (isSelected) onChangeLabel(optionValue ?? \"\", { runOmit: false })\n }, [optionValue])\n\n const getOptionProps: PropGetter<\"li\"> = useCallback(\n (props = {}, ref = null) => {\n const style: CSSProperties = {\n border: \"0px\",\n clip: \"rect(0px, 0px, 0px, 0px)\",\n height: \"1px\",\n width: \"1px\",\n margin: \"-1px\",\n padding: \"0px\",\n overflow: \"hidden\",\n whiteSpace: \"nowrap\",\n position: \"absolute\",\n }\n\n return {\n ref: mergeRefs(itemRef, ref, register),\n id: useId(),\n role: \"option\",\n ...computedProps,\n ...props,\n tabIndex: -1,\n style:\n !isTarget || (omitSelectedValues && isSelected) ? style : undefined,\n \"data-target\": dataAttr(true),\n \"data-value\": optionValue ?? \"\",\n \"data-focus\": dataAttr(isFocused),\n \"data-disabled\": dataAttr(isDisabled),\n \"aria-checked\": isSelected,\n \"aria-disabled\": ariaAttr(isDisabled),\n onClick: handlerAll(computedProps.onClick, props.onClick, onClick),\n }\n },\n [\n optionValue,\n computedProps,\n isDisabled,\n isFocused,\n isSelected,\n isTarget,\n omitSelectedValues,\n onClick,\n register,\n ],\n )\n\n return {\n isSelected,\n isFocused,\n customIcon,\n children,\n getOptionProps,\n }\n}\n\nexport type UseAutocompleteOptionReturn = ReturnType<\n typeof useAutocompleteOption\n>\n\nexport const useAutocompleteCreate = () => {\n const { isHit, onCreate } = useAutocompleteContext()\n\n const getCreateProps: PropGetter<\"li\"> = useCallback(\n (props = {}, ref = null) => {\n const style: CSSProperties = {\n border: \"0px\",\n clip: \"rect(0px, 0px, 0px, 0px)\",\n height: \"1px\",\n width: \"1px\",\n margin: \"-1px\",\n padding: \"0px\",\n overflow: \"hidden\",\n whiteSpace: \"nowrap\",\n position: \"absolute\",\n }\n\n return {\n ref,\n ...props,\n tabIndex: -1,\n style: isHit ? style : undefined,\n \"data-focus\": dataAttr(!isHit),\n onClick: handlerAll(props.onClick, onCreate),\n }\n },\n [isHit, onCreate],\n )\n\n return { getCreateProps }\n}\n\nexport type UseAutocompleteCreateReturn = ReturnType<\n typeof useAutocompleteCreate\n>\n\nexport const useAutocompleteEmpty = () => {\n const { isHit, isEmpty } = useAutocompleteContext()\n\n const getEmptyProps: PropGetter<\"li\"> = useCallback(\n (props = {}, ref = null) => {\n const style: CSSProperties = {\n border: \"0px\",\n clip: \"rect(0px, 0px, 0px, 0px)\",\n height: \"1px\",\n width: \"1px\",\n margin: \"-1px\",\n padding: \"0px\",\n overflow: \"hidden\",\n whiteSpace: \"nowrap\",\n position: \"absolute\",\n }\n\n return {\n ref,\n ...props,\n tabIndex: -1,\n style: isHit && !isEmpty ? style : undefined,\n }\n },\n [isHit, isEmpty],\n )\n\n return { getEmptyProps }\n}\n\nexport type UseAutocompleteEmptyReturn = ReturnType<typeof useAutocompleteEmpty>\n","import type { CSSUIObject } from \"@yamada-ui/core\"\nimport { createDescendant } from \"@yamada-ui/use-descendant\"\nimport { createContext } from \"@yamada-ui/utils\"\nimport type { Dispatch, DOMAttributes, RefObject, SetStateAction } from \"react\"\nimport type { ChangeOptions, UseAutocompleteProps } from \"./use-autocomplete\"\n\nexport const {\n DescendantsContextProvider: AutocompleteDescendantsContextProvider,\n useDescendantsContext: useAutocompleteDescendantsContext,\n useDescendants: useAutocompleteDescendants,\n useDescendant: useAutocompleteDescendant,\n} = createDescendant()\n\ninterface AutocompleteContext\n extends Omit<\n UseAutocompleteProps,\n \"value\" | \"defaultValue\" | \"onChange\" | \"onCreate\"\n > {\n value: string | string[]\n label: string | string[] | undefined\n inputValue: string\n isHit: boolean\n isEmpty: boolean\n isAllSelected: boolean\n onChange: (newValue: string, options?: ChangeOptions) => void\n onChangeLabel: (newValue: string, options?: ChangeOptions) => void\n pickOptions: (value: string) => void\n rebirthOptions: (runFocus?: boolean) => void\n inputProps: DOMAttributes<HTMLInputElement>\n isOpen: boolean\n onOpen: () => void\n onClose: () => void\n onCreate: () => void\n onFocusFirst: () => void\n onFocusLast: () => void\n onFocusNext: (index?: number) => void\n onFocusPrev: (index?: number) => void\n focusedIndex: number\n setFocusedIndex: Dispatch<SetStateAction<number>>\n listRef: RefObject<HTMLUListElement>\n inputRef: RefObject<HTMLInputElement>\n formControlProps: { [key: string]: any }\n styles: { [key: string]: CSSUIObject }\n}\n\nexport const [AutocompleteProvider, useAutocompleteContext] =\n createContext<AutocompleteContext>({\n name: \"AutocompleteContext\",\n errorMessage: `useAutocompleteContext returned is 'undefined'. Seems you forgot to wrap the components in \"<Autocomplete />\" or \"<MultiAutocomplete />\"`,\n })\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,IAAAA,gBAQO;AAEP,mBAA2C;;;ACV3C,4BAAiC;AACjC,mBAA8B;AAIvB,IAAM;AAAA,EACX,4BAA4B;AAAA,EAC5B,uBAAuB;AAAA,EACvB,gBAAgB;AAAA,EAChB,eAAe;AACjB,QAAI,wCAAiB;AAkCd,IAAM,CAAC,sBAAsB,sBAAsB,QACxD,4BAAmC;AAAA,EACjC,MAAM;AAAA,EACN,cAAc;AAChB,CAAC;;;ADhCH,IAAM,iBAAiB,CAAC,WAAqC;AAjB7D;AAkBE,0CAAc,MAAM,KAAK,CAAC,GAAC,sCAAQ,aAAa,YAArB,mBAA8B,WAAW;AAAA;AAgC/D,IAAM,wBAAwB,CAAC,UAAsC;AAlD5E;AAmDE,QAAM;AAAA,IACJ;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA,eAAe;AAAA,IACf;AAAA,IACA;AAAA,IACA;AAAA,EACF,IAAI,uBAAuB;AAE3B,MAAI;AAAA,IACF,MAAM;AAAA,IACN;AAAA,IACA;AAAA,IACA,eAAe;AAAA,IACf;AAAA,IACA,OAAO;AAAA,IACP,GAAG;AAAA,EACL,IAAI,EAAE,GAAG,aAAa,GAAG,MAAM;AAE/B,QAAM,gBAAgB,CAAC,CAAC,cAAc,CA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