@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.
- package/dist/autocomplete-context.d.mts +210 -0
- package/dist/autocomplete-context.d.ts +210 -0
- package/dist/autocomplete-context.js +53 -0
- package/dist/autocomplete-context.js.map +1 -0
- package/dist/autocomplete-context.mjs +18 -0
- package/dist/autocomplete-context.mjs.map +1 -0
- package/dist/autocomplete-create.d.mts +4 -3
- package/dist/autocomplete-create.d.ts +4 -3
- package/dist/autocomplete-create.js +56 -61
- package/dist/autocomplete-create.js.map +1 -1
- package/dist/autocomplete-create.mjs +4 -1
- package/dist/autocomplete-empty.d.mts +4 -3
- package/dist/autocomplete-empty.d.ts +4 -3
- package/dist/autocomplete-empty.js +54 -59
- package/dist/autocomplete-empty.js.map +1 -1
- package/dist/autocomplete-empty.mjs +4 -1
- package/dist/autocomplete-icon.d.mts +6 -4
- package/dist/autocomplete-icon.d.ts +6 -4
- package/dist/autocomplete-icon.js +15 -22
- package/dist/autocomplete-icon.js.map +1 -1
- package/dist/autocomplete-icon.mjs +2 -1
- package/dist/autocomplete-list.d.mts +2 -2
- package/dist/autocomplete-list.d.ts +2 -2
- package/dist/autocomplete-list.js +20 -23
- package/dist/autocomplete-list.js.map +1 -1
- package/dist/autocomplete-list.mjs +3 -1
- package/dist/autocomplete-option-group.d.mts +5 -9
- package/dist/autocomplete-option-group.d.ts +5 -9
- package/dist/autocomplete-option-group.js +14 -16
- package/dist/autocomplete-option-group.js.map +1 -1
- package/dist/autocomplete-option-group.mjs +3 -1
- package/dist/autocomplete-option.d.mts +15 -8
- package/dist/autocomplete-option.d.ts +15 -8
- package/dist/autocomplete-option.js +97 -102
- package/dist/autocomplete-option.js.map +1 -1
- package/dist/autocomplete-option.mjs +4 -1
- package/dist/autocomplete.d.mts +13 -7
- package/dist/autocomplete.d.ts +13 -7
- package/dist/autocomplete.js +673 -661
- package/dist/autocomplete.js.map +1 -1
- package/dist/autocomplete.mjs +12 -1
- package/dist/chunk-7GCVSXCV.mjs +190 -0
- package/dist/chunk-7GCVSXCV.mjs.map +1 -0
- package/dist/chunk-BD7VZQOL.mjs +267 -0
- package/dist/chunk-BD7VZQOL.mjs.map +1 -0
- package/dist/chunk-FZM3BH3D.mjs +57 -0
- package/dist/chunk-FZM3BH3D.mjs.map +1 -0
- package/dist/chunk-GM7RV2YY.mjs +959 -0
- package/dist/chunk-GM7RV2YY.mjs.map +1 -0
- package/dist/chunk-GOMUH7TZ.mjs +60 -0
- package/dist/chunk-GOMUH7TZ.mjs.map +1 -0
- package/dist/chunk-HL2KEBRX.mjs +87 -0
- package/dist/chunk-HL2KEBRX.mjs.map +1 -0
- package/dist/chunk-JMX72TSD.mjs +78 -0
- package/dist/chunk-JMX72TSD.mjs.map +1 -0
- package/dist/chunk-JPUKYLBW.mjs +25 -0
- package/dist/chunk-JPUKYLBW.mjs.map +1 -0
- package/dist/chunk-JXFXCGZK.mjs +102 -0
- package/dist/chunk-JXFXCGZK.mjs.map +1 -0
- package/dist/chunk-KCALQJLK.mjs +59 -0
- package/dist/chunk-KCALQJLK.mjs.map +1 -0
- package/dist/chunk-PRDD3JJO.mjs +202 -0
- package/dist/chunk-PRDD3JJO.mjs.map +1 -0
- package/dist/chunk-QGOCVO2C.mjs +68 -0
- package/dist/chunk-QGOCVO2C.mjs.map +1 -0
- package/dist/chunk-QQFSHTTC.mjs +59 -0
- package/dist/chunk-QQFSHTTC.mjs.map +1 -0
- package/dist/index.d.mts +4 -1
- package/dist/index.d.ts +4 -1
- package/dist/index.js +1550 -1536
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +23 -6
- package/dist/multi-autocomplete.d.mts +13 -7
- package/dist/multi-autocomplete.d.ts +13 -7
- package/dist/multi-autocomplete.js +1516 -1504
- package/dist/multi-autocomplete.js.map +1 -1
- package/dist/multi-autocomplete.mjs +12 -1
- package/dist/use-autocomplete-list.d.mts +8 -0
- package/dist/use-autocomplete-list.d.ts +8 -0
- package/dist/use-autocomplete-list.js +103 -0
- package/dist/use-autocomplete-list.js.map +1 -0
- package/dist/use-autocomplete-list.mjs +9 -0
- package/dist/use-autocomplete-list.mjs.map +1 -0
- package/dist/use-autocomplete-option-group.d.mts +16 -0
- package/dist/use-autocomplete-option-group.d.ts +16 -0
- package/dist/use-autocomplete-option-group.js +113 -0
- package/dist/use-autocomplete-option-group.js.map +1 -0
- package/dist/use-autocomplete-option-group.mjs +9 -0
- package/dist/use-autocomplete-option-group.mjs.map +1 -0
- package/dist/use-autocomplete-option.d.mts +49 -0
- package/dist/use-autocomplete-option.d.ts +49 -0
- package/dist/use-autocomplete-option.js +231 -0
- package/dist/use-autocomplete-option.js.map +1 -0
- package/dist/use-autocomplete-option.mjs +13 -0
- package/dist/use-autocomplete-option.mjs.map +1 -0
- package/dist/use-autocomplete.d.mts +188 -8
- package/dist/use-autocomplete.d.ts +188 -8
- package/dist/use-autocomplete.js +359 -481
- package/dist/use-autocomplete.js.map +1 -1
- package/dist/use-autocomplete.mjs +9 -25
- package/package.json +13 -13
- package/dist/chunk-ZD25NCFE.mjs +0 -2038
- package/dist/chunk-ZD25NCFE.mjs.map +0 -1
- package/dist/use-autocomplete-BJNWa6hL.d.mts +0 -389
- package/dist/use-autocomplete-BJNWa6hL.d.ts +0 -389
package/dist/use-autocomplete.js
CHANGED
|
@@ -21,35 +21,41 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
21
21
|
// src/use-autocomplete.tsx
|
|
22
22
|
var use_autocomplete_exports = {};
|
|
23
23
|
__export(use_autocomplete_exports, {
|
|
24
|
-
AutocompleteDescendantsContextProvider: () => AutocompleteDescendantsContextProvider,
|
|
25
|
-
AutocompleteProvider: () => AutocompleteProvider,
|
|
26
24
|
useAutocomplete: () => useAutocomplete,
|
|
27
|
-
|
|
28
|
-
useAutocompleteCreate: () => useAutocompleteCreate,
|
|
29
|
-
useAutocompleteDescendant: () => useAutocompleteDescendant,
|
|
30
|
-
useAutocompleteDescendants: () => useAutocompleteDescendants,
|
|
31
|
-
useAutocompleteDescendantsContext: () => useAutocompleteDescendantsContext,
|
|
32
|
-
useAutocompleteEmpty: () => useAutocompleteEmpty,
|
|
33
|
-
useAutocompleteInput: () => useAutocompleteInput,
|
|
34
|
-
useAutocompleteList: () => useAutocompleteList,
|
|
35
|
-
useAutocompleteOption: () => useAutocompleteOption,
|
|
36
|
-
useAutocompleteOptionGroup: () => useAutocompleteOptionGroup
|
|
25
|
+
useAutocompleteInput: () => useAutocompleteInput
|
|
37
26
|
});
|
|
38
27
|
module.exports = __toCommonJS(use_autocomplete_exports);
|
|
39
|
-
var
|
|
28
|
+
var import_core5 = require("@yamada-ui/core");
|
|
40
29
|
var import_form_control = require("@yamada-ui/form-control");
|
|
41
30
|
var import_use_controllable_state = require("@yamada-ui/use-controllable-state");
|
|
42
|
-
var import_use_descendant = require("@yamada-ui/use-descendant");
|
|
43
31
|
var import_use_disclosure = require("@yamada-ui/use-disclosure");
|
|
44
32
|
var import_use_outside_click = require("@yamada-ui/use-outside-click");
|
|
33
|
+
var import_utils7 = require("@yamada-ui/utils");
|
|
34
|
+
var import_react4 = require("react");
|
|
35
|
+
|
|
36
|
+
// src/autocomplete-context.ts
|
|
37
|
+
var import_use_descendant = require("@yamada-ui/use-descendant");
|
|
38
|
+
var import_utils = require("@yamada-ui/utils");
|
|
39
|
+
var {
|
|
40
|
+
DescendantsContextProvider: AutocompleteDescendantsContextProvider,
|
|
41
|
+
useDescendantsContext: useAutocompleteDescendantsContext,
|
|
42
|
+
useDescendants: useAutocompleteDescendants,
|
|
43
|
+
useDescendant: useAutocompleteDescendant
|
|
44
|
+
} = (0, import_use_descendant.createDescendant)();
|
|
45
|
+
var [AutocompleteProvider, useAutocompleteContext] = (0, import_utils.createContext)({
|
|
46
|
+
name: "AutocompleteContext",
|
|
47
|
+
errorMessage: `useAutocompleteContext returned is 'undefined'. Seems you forgot to wrap the components in "<Autocomplete />" or "<MultiAutocomplete />"`
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
// src/autocomplete-option.tsx
|
|
51
|
+
var import_core2 = require("@yamada-ui/core");
|
|
45
52
|
var import_utils4 = require("@yamada-ui/utils");
|
|
46
|
-
var import_react2 = require("react");
|
|
47
53
|
|
|
48
54
|
// src/autocomplete-icon.tsx
|
|
49
55
|
var import_core = require("@yamada-ui/core");
|
|
50
56
|
var import_icon = require("@yamada-ui/icon");
|
|
51
57
|
var import_use_clickable = require("@yamada-ui/use-clickable");
|
|
52
|
-
var
|
|
58
|
+
var import_utils2 = require("@yamada-ui/utils");
|
|
53
59
|
var import_react = require("react");
|
|
54
60
|
var import_jsx_runtime = require("react/jsx-runtime");
|
|
55
61
|
var AutocompleteIcon = (0, import_core.forwardRef)(
|
|
@@ -67,7 +73,7 @@ var AutocompleteIcon = (0, import_core.forwardRef)(
|
|
|
67
73
|
...styles.icon,
|
|
68
74
|
...__css
|
|
69
75
|
};
|
|
70
|
-
const validChildren = (0,
|
|
76
|
+
const validChildren = (0, import_utils2.getValidChildren)(children);
|
|
71
77
|
const cloneChildren = validChildren.map(
|
|
72
78
|
(child) => (0, import_react.cloneElement)(child, {
|
|
73
79
|
focusable: false,
|
|
@@ -83,10 +89,10 @@ var AutocompleteIcon = (0, import_core.forwardRef)(
|
|
|
83
89
|
import_core.ui.div,
|
|
84
90
|
{
|
|
85
91
|
ref,
|
|
86
|
-
className: (0,
|
|
92
|
+
className: (0, import_utils2.cx)("ui-autocomplete__icon", className),
|
|
87
93
|
__css: css,
|
|
88
94
|
...rest,
|
|
89
|
-
children: (0,
|
|
95
|
+
children: (0, import_utils2.isValidElement)(children) ? cloneChildren : /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_icon.ChevronIcon, {})
|
|
90
96
|
}
|
|
91
97
|
);
|
|
92
98
|
}
|
|
@@ -105,63 +111,144 @@ var AutocompleteItemIcon = (0, import_core.forwardRef)(({ className, ...rest },
|
|
|
105
111
|
import_core.ui.span,
|
|
106
112
|
{
|
|
107
113
|
ref,
|
|
108
|
-
className: (0,
|
|
114
|
+
className: (0, import_utils2.cx)("ui-autocomplete__item__icon", className),
|
|
109
115
|
__css: css,
|
|
110
116
|
...rest
|
|
111
117
|
}
|
|
112
118
|
);
|
|
113
119
|
});
|
|
114
120
|
|
|
115
|
-
// src/autocomplete-option
|
|
116
|
-
var
|
|
117
|
-
var
|
|
118
|
-
var
|
|
119
|
-
var
|
|
120
|
-
(
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
121
|
+
// src/use-autocomplete-option.ts
|
|
122
|
+
var import_utils3 = require("@yamada-ui/utils");
|
|
123
|
+
var import_react2 = require("react");
|
|
124
|
+
var isTargetOption = (target) => {
|
|
125
|
+
var _a;
|
|
126
|
+
return (0, import_utils3.isHTMLElement)(target) && !!((_a = target == null ? void 0 : target.getAttribute("role")) == null ? void 0 : _a.startsWith("option"));
|
|
127
|
+
};
|
|
128
|
+
var useAutocompleteOption = (props) => {
|
|
129
|
+
var _a, _b;
|
|
130
|
+
const {
|
|
131
|
+
value,
|
|
132
|
+
omitSelectedValues,
|
|
133
|
+
onChange,
|
|
134
|
+
onChangeLabel,
|
|
135
|
+
focusedIndex,
|
|
136
|
+
setFocusedIndex,
|
|
137
|
+
onClose,
|
|
138
|
+
closeOnSelect: generalCloseOnSelect,
|
|
139
|
+
optionProps,
|
|
140
|
+
inputRef,
|
|
141
|
+
onFocusNext
|
|
142
|
+
} = useAutocompleteContext();
|
|
143
|
+
let {
|
|
144
|
+
icon: customIcon,
|
|
145
|
+
isDisabled,
|
|
146
|
+
isFocusable,
|
|
147
|
+
closeOnSelect: customCloseOnSelect,
|
|
148
|
+
children,
|
|
149
|
+
value: optionValue,
|
|
150
|
+
...computedProps
|
|
151
|
+
} = { ...optionProps, ...props };
|
|
152
|
+
const trulyDisabled = !!isDisabled && !isFocusable;
|
|
153
|
+
const itemRef = (0, import_react2.useRef)(null);
|
|
154
|
+
const { index, register, descendants } = useAutocompleteDescendant({
|
|
155
|
+
disabled: trulyDisabled
|
|
156
|
+
});
|
|
157
|
+
const values = descendants.values();
|
|
158
|
+
const frontValues = values.slice(0, index);
|
|
159
|
+
const isMulti = (0, import_utils3.isArray)(value);
|
|
160
|
+
const isDuplicated = !isMulti ? frontValues.some(({ node }) => node.dataset.value === (optionValue != null ? optionValue : "")) : false;
|
|
161
|
+
const isSelected = !isDuplicated && (!isMulti ? (optionValue != null ? optionValue : "") === value : value.includes(optionValue != null ? optionValue : ""));
|
|
162
|
+
const isTarget = "target" in ((_b = (_a = itemRef.current) == null ? void 0 : _a.dataset) != null ? _b : {});
|
|
163
|
+
const isFocused = index === focusedIndex;
|
|
164
|
+
const onClick = (0, import_react2.useCallback)(
|
|
165
|
+
(ev) => {
|
|
166
|
+
ev.stopPropagation();
|
|
167
|
+
if (isDisabled) {
|
|
168
|
+
if (inputRef.current) inputRef.current.focus();
|
|
169
|
+
return;
|
|
155
170
|
}
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
171
|
+
if (!isTargetOption(ev.currentTarget)) {
|
|
172
|
+
if (inputRef.current) inputRef.current.focus();
|
|
173
|
+
return;
|
|
174
|
+
}
|
|
175
|
+
setFocusedIndex(index);
|
|
176
|
+
onChange(optionValue != null ? optionValue : "");
|
|
177
|
+
if (inputRef.current) inputRef.current.focus();
|
|
178
|
+
if (customCloseOnSelect != null ? customCloseOnSelect : generalCloseOnSelect) onClose();
|
|
179
|
+
if (omitSelectedValues) onFocusNext(index);
|
|
180
|
+
},
|
|
181
|
+
[
|
|
182
|
+
onFocusNext,
|
|
183
|
+
omitSelectedValues,
|
|
184
|
+
isDisabled,
|
|
185
|
+
optionValue,
|
|
186
|
+
setFocusedIndex,
|
|
187
|
+
index,
|
|
188
|
+
onChange,
|
|
189
|
+
customCloseOnSelect,
|
|
190
|
+
generalCloseOnSelect,
|
|
191
|
+
onClose,
|
|
192
|
+
inputRef
|
|
193
|
+
]
|
|
194
|
+
);
|
|
195
|
+
(0, import_utils3.useUpdateEffect)(() => {
|
|
196
|
+
if (isSelected) onChangeLabel(optionValue != null ? optionValue : "", { runOmit: false });
|
|
197
|
+
}, [optionValue]);
|
|
198
|
+
const getOptionProps = (0, import_react2.useCallback)(
|
|
199
|
+
(props2 = {}, ref = null) => {
|
|
200
|
+
const style = {
|
|
201
|
+
border: "0px",
|
|
202
|
+
clip: "rect(0px, 0px, 0px, 0px)",
|
|
203
|
+
height: "1px",
|
|
204
|
+
width: "1px",
|
|
205
|
+
margin: "-1px",
|
|
206
|
+
padding: "0px",
|
|
207
|
+
overflow: "hidden",
|
|
208
|
+
whiteSpace: "nowrap",
|
|
209
|
+
position: "absolute"
|
|
210
|
+
};
|
|
211
|
+
return {
|
|
212
|
+
ref: (0, import_utils3.mergeRefs)(itemRef, ref, register),
|
|
213
|
+
id: (0, import_react2.useId)(),
|
|
214
|
+
role: "option",
|
|
215
|
+
...computedProps,
|
|
216
|
+
...props2,
|
|
217
|
+
tabIndex: -1,
|
|
218
|
+
style: !isTarget || omitSelectedValues && isSelected ? style : void 0,
|
|
219
|
+
"data-target": (0, import_utils3.dataAttr)(true),
|
|
220
|
+
"data-value": optionValue != null ? optionValue : "",
|
|
221
|
+
"data-focus": (0, import_utils3.dataAttr)(isFocused),
|
|
222
|
+
"data-disabled": (0, import_utils3.dataAttr)(isDisabled),
|
|
223
|
+
"aria-checked": isSelected,
|
|
224
|
+
"aria-disabled": (0, import_utils3.ariaAttr)(isDisabled),
|
|
225
|
+
onClick: (0, import_utils3.handlerAll)(computedProps.onClick, props2.onClick, onClick)
|
|
226
|
+
};
|
|
227
|
+
},
|
|
228
|
+
[
|
|
229
|
+
optionValue,
|
|
230
|
+
computedProps,
|
|
231
|
+
isDisabled,
|
|
232
|
+
isFocused,
|
|
233
|
+
isSelected,
|
|
234
|
+
isTarget,
|
|
235
|
+
omitSelectedValues,
|
|
236
|
+
onClick,
|
|
237
|
+
register
|
|
238
|
+
]
|
|
239
|
+
);
|
|
240
|
+
return {
|
|
241
|
+
isSelected,
|
|
242
|
+
isFocused,
|
|
243
|
+
customIcon,
|
|
244
|
+
children,
|
|
245
|
+
getOptionProps
|
|
246
|
+
};
|
|
247
|
+
};
|
|
159
248
|
|
|
160
249
|
// src/autocomplete-option.tsx
|
|
161
|
-
var
|
|
162
|
-
var
|
|
163
|
-
var import_jsx_runtime3 = require("react/jsx-runtime");
|
|
164
|
-
var AutocompleteOption = (0, import_core3.forwardRef)(
|
|
250
|
+
var import_jsx_runtime2 = require("react/jsx-runtime");
|
|
251
|
+
var AutocompleteOption = (0, import_core2.forwardRef)(
|
|
165
252
|
({ className, icon, ...rest }, ref) => {
|
|
166
253
|
const { styles } = useAutocompleteContext();
|
|
167
254
|
const { isSelected, customIcon, children, getOptionProps } = useAutocompleteOption(rest);
|
|
@@ -179,27 +266,142 @@ var AutocompleteOption = (0, import_core3.forwardRef)(
|
|
|
179
266
|
gap: "0.75rem",
|
|
180
267
|
...styles.item
|
|
181
268
|
};
|
|
182
|
-
return /* @__PURE__ */ (0,
|
|
183
|
-
|
|
269
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(
|
|
270
|
+
import_core2.ui.li,
|
|
184
271
|
{
|
|
185
|
-
className: (0,
|
|
272
|
+
className: (0, import_utils4.cx)("ui-autocomplete__item", className),
|
|
186
273
|
__css: css,
|
|
187
274
|
...getOptionProps({}, ref),
|
|
188
275
|
children: [
|
|
189
|
-
icon !== null ? /* @__PURE__ */ (0,
|
|
190
|
-
/* @__PURE__ */ (0,
|
|
276
|
+
icon !== null ? /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(AutocompleteItemIcon, { opacity: isSelected ? 1 : 0, children: icon || /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(CheckIcon, {}) }) : null,
|
|
277
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_core2.ui.span, { style: { flex: 1 }, "data-label": true, children })
|
|
278
|
+
]
|
|
279
|
+
}
|
|
280
|
+
);
|
|
281
|
+
}
|
|
282
|
+
);
|
|
283
|
+
var CheckIcon = () => /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("svg", { viewBox: "0 0 14 14", width: "1em", height: "1em", children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
284
|
+
"polygon",
|
|
285
|
+
{
|
|
286
|
+
fill: "currentColor",
|
|
287
|
+
points: "5.5 11.9993304 14 3.49933039 12.5 2 5.5 8.99933039 1.5 4.9968652 0 6.49933039"
|
|
288
|
+
}
|
|
289
|
+
) });
|
|
290
|
+
|
|
291
|
+
// src/autocomplete-option-group.tsx
|
|
292
|
+
var import_core4 = require("@yamada-ui/core");
|
|
293
|
+
var import_utils6 = require("@yamada-ui/utils");
|
|
294
|
+
|
|
295
|
+
// src/use-autocomplete-option-group.ts
|
|
296
|
+
var import_core3 = require("@yamada-ui/core");
|
|
297
|
+
var import_utils5 = require("@yamada-ui/utils");
|
|
298
|
+
var import_react3 = require("react");
|
|
299
|
+
var useAutocompleteOptionGroup = ({
|
|
300
|
+
label,
|
|
301
|
+
...rest
|
|
302
|
+
}) => {
|
|
303
|
+
const { value, omitSelectedValues } = useAutocompleteContext();
|
|
304
|
+
const isMulti = (0, import_utils5.isArray)(value);
|
|
305
|
+
const descendants = useAutocompleteDescendantsContext();
|
|
306
|
+
const values = descendants.values();
|
|
307
|
+
const selectedValues = isMulti && omitSelectedValues ? descendants.values(
|
|
308
|
+
({ node }) => {
|
|
309
|
+
var _a;
|
|
310
|
+
return value.includes((_a = node.dataset.value) != null ? _a : "");
|
|
311
|
+
}
|
|
312
|
+
) : [];
|
|
313
|
+
const selectedIndexes = selectedValues.map(({ index }) => index);
|
|
314
|
+
const childValues = values.filter(
|
|
315
|
+
({ node, index }) => {
|
|
316
|
+
var _a;
|
|
317
|
+
return ((_a = node.parentElement) == null ? void 0 : _a.dataset.label) === label && !selectedIndexes.includes(index) && "target" in node.dataset;
|
|
318
|
+
}
|
|
319
|
+
);
|
|
320
|
+
const isEmpty = !childValues.length;
|
|
321
|
+
const [containerProps, groupProps] = (0, import_utils5.splitObject)(rest, import_core3.layoutStyleProperties);
|
|
322
|
+
const getContainerProps = (0, import_react3.useCallback)(
|
|
323
|
+
(props = {}, ref = null) => {
|
|
324
|
+
const style = {
|
|
325
|
+
border: "0px",
|
|
326
|
+
clip: "rect(0px, 0px, 0px, 0px)",
|
|
327
|
+
height: "1px",
|
|
328
|
+
width: "1px",
|
|
329
|
+
margin: "-1px",
|
|
330
|
+
padding: "0px",
|
|
331
|
+
overflow: "hidden",
|
|
332
|
+
whiteSpace: "nowrap",
|
|
333
|
+
position: "absolute"
|
|
334
|
+
};
|
|
335
|
+
return {
|
|
336
|
+
ref,
|
|
337
|
+
...props,
|
|
338
|
+
...containerProps,
|
|
339
|
+
style: isEmpty ? style : void 0,
|
|
340
|
+
"data-label": label,
|
|
341
|
+
role: "autocomplete-group-container"
|
|
342
|
+
};
|
|
343
|
+
},
|
|
344
|
+
[containerProps, isEmpty, label]
|
|
345
|
+
);
|
|
346
|
+
const getGroupProps = (0, import_react3.useCallback)(
|
|
347
|
+
(props = {}, ref = null) => ({
|
|
348
|
+
ref,
|
|
349
|
+
...props,
|
|
350
|
+
...groupProps,
|
|
351
|
+
"data-label": label,
|
|
352
|
+
role: "autocomplete-group"
|
|
353
|
+
}),
|
|
354
|
+
[groupProps, label]
|
|
355
|
+
);
|
|
356
|
+
return {
|
|
357
|
+
label,
|
|
358
|
+
getContainerProps,
|
|
359
|
+
getGroupProps
|
|
360
|
+
};
|
|
361
|
+
};
|
|
362
|
+
|
|
363
|
+
// src/autocomplete-option-group.tsx
|
|
364
|
+
var import_jsx_runtime3 = require("react/jsx-runtime");
|
|
365
|
+
var AutocompleteOptionGroup = (0, import_core4.forwardRef)(
|
|
366
|
+
({ className, color, h, height, minH, minHeight, children, ...rest }, ref) => {
|
|
367
|
+
const { styles } = useAutocompleteContext();
|
|
368
|
+
const { label, getContainerProps, getGroupProps } = useAutocompleteOptionGroup(rest);
|
|
369
|
+
h != null ? h : h = height;
|
|
370
|
+
minH != null ? minH : minH = minHeight;
|
|
371
|
+
return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(
|
|
372
|
+
import_core4.ui.li,
|
|
373
|
+
{
|
|
374
|
+
className: (0, import_utils6.cx)(
|
|
375
|
+
"ui-autocomplete__item",
|
|
376
|
+
"ui-autocomplete__item--group",
|
|
377
|
+
className
|
|
378
|
+
),
|
|
379
|
+
__css: { w: "100%", h: "fit-content", color },
|
|
380
|
+
...getContainerProps(),
|
|
381
|
+
children: [
|
|
382
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
|
383
|
+
import_core4.ui.span,
|
|
384
|
+
{
|
|
385
|
+
className: "ui-autocomplete__item__group-label",
|
|
386
|
+
__css: styles.groupLabel,
|
|
387
|
+
lineClamp: 1,
|
|
388
|
+
children: label
|
|
389
|
+
}
|
|
390
|
+
),
|
|
391
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
|
392
|
+
import_core4.ui.ul,
|
|
393
|
+
{
|
|
394
|
+
...getGroupProps({}, ref),
|
|
395
|
+
className: "ui-autocomplete__item__group",
|
|
396
|
+
__css: { h, minH, ...styles.group },
|
|
397
|
+
children
|
|
398
|
+
}
|
|
399
|
+
)
|
|
191
400
|
]
|
|
192
401
|
}
|
|
193
402
|
);
|
|
194
403
|
}
|
|
195
404
|
);
|
|
196
|
-
var CheckIcon = () => /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("svg", { viewBox: "0 0 14 14", width: "1em", height: "1em", children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
|
197
|
-
"polygon",
|
|
198
|
-
{
|
|
199
|
-
fill: "currentColor",
|
|
200
|
-
points: "5.5 11.9993304 14 3.49933039 12.5 2 5.5 8.99933039 1.5 4.9968652 0 6.49933039"
|
|
201
|
-
}
|
|
202
|
-
) });
|
|
203
405
|
|
|
204
406
|
// src/use-autocomplete.tsx
|
|
205
407
|
var import_jsx_runtime4 = require("react/jsx-runtime");
|
|
@@ -318,20 +520,6 @@ var flattenItems = (items) => {
|
|
|
318
520
|
}).filter(Boolean);
|
|
319
521
|
return filterItems(items).flat(Infinity);
|
|
320
522
|
};
|
|
321
|
-
var isTargetOption = (target) => {
|
|
322
|
-
var _a;
|
|
323
|
-
return (0, import_utils4.isHTMLElement)(target) && !!((_a = target == null ? void 0 : target.getAttribute("role")) == null ? void 0 : _a.startsWith("option"));
|
|
324
|
-
};
|
|
325
|
-
var {
|
|
326
|
-
DescendantsContextProvider: AutocompleteDescendantsContextProvider,
|
|
327
|
-
useDescendantsContext: useAutocompleteDescendantsContext,
|
|
328
|
-
useDescendants: useAutocompleteDescendants,
|
|
329
|
-
useDescendant: useAutocompleteDescendant
|
|
330
|
-
} = (0, import_use_descendant.createDescendant)();
|
|
331
|
-
var [AutocompleteProvider, useAutocompleteContext] = (0, import_utils4.createContext)({
|
|
332
|
-
name: "AutocompleteContext",
|
|
333
|
-
errorMessage: `useAutocompleteContext returned is 'undefined'. Seems you forgot to wrap the components in "<Autocomplete />" or "<MultiAutocomplete />"`
|
|
334
|
-
});
|
|
335
523
|
var useAutocomplete = (props) => {
|
|
336
524
|
const {
|
|
337
525
|
value: valueProp,
|
|
@@ -380,27 +568,27 @@ var useAutocomplete = (props) => {
|
|
|
380
568
|
"aria-readonly": _ariaReadonly,
|
|
381
569
|
onFocus: onFocusProp,
|
|
382
570
|
...formControlProps
|
|
383
|
-
} = (0,
|
|
384
|
-
const [containerProps, inputProps] = (0,
|
|
571
|
+
} = (0, import_utils7.pickObject)(rest, import_form_control.formControlProperties);
|
|
572
|
+
const [containerProps, inputProps] = (0, import_utils7.splitObject)(rest, import_core5.layoutStyleProperties);
|
|
385
573
|
const { id } = rest;
|
|
386
574
|
const descendants = useAutocompleteDescendants();
|
|
387
|
-
const containerRef = (0,
|
|
388
|
-
const listRef = (0,
|
|
389
|
-
const inputRef = (0,
|
|
390
|
-
const timeoutIds = (0,
|
|
391
|
-
const isComposition = (0,
|
|
392
|
-
const prevValue = (0,
|
|
393
|
-
const [resolvedItems, setResolvedItems] = (0,
|
|
575
|
+
const containerRef = (0, import_react4.useRef)(null);
|
|
576
|
+
const listRef = (0, import_react4.useRef)(null);
|
|
577
|
+
const inputRef = (0, import_react4.useRef)(null);
|
|
578
|
+
const timeoutIds = (0, import_react4.useRef)(/* @__PURE__ */ new Set([]));
|
|
579
|
+
const isComposition = (0, import_react4.useRef)(false);
|
|
580
|
+
const prevValue = (0, import_react4.useRef)(void 0);
|
|
581
|
+
const [resolvedItems, setResolvedItems] = (0, import_react4.useState)(items ? JSON.parse(JSON.stringify(items)) : void 0);
|
|
394
582
|
const [value, setValue] = (0, import_use_controllable_state.useControllableState)({
|
|
395
583
|
value: valueProp,
|
|
396
584
|
defaultValue,
|
|
397
585
|
onChange: onChangeProp
|
|
398
586
|
});
|
|
399
|
-
const [label, setLabel] = (0,
|
|
400
|
-
const [inputValue, setInputValue] = (0,
|
|
401
|
-
const [focusedIndex, setFocusedIndex] = (0,
|
|
402
|
-
const [isAllSelected, setIsAllSelected] = (0,
|
|
403
|
-
const [isHit, setIsHit] = (0,
|
|
587
|
+
const [label, setLabel] = (0, import_react4.useState)(void 0);
|
|
588
|
+
const [inputValue, setInputValue] = (0, import_react4.useState)("");
|
|
589
|
+
const [focusedIndex, setFocusedIndex] = (0, import_react4.useState)(-1);
|
|
590
|
+
const [isAllSelected, setIsAllSelected] = (0, import_react4.useState)(false);
|
|
591
|
+
const [isHit, setIsHit] = (0, import_react4.useState)(true);
|
|
404
592
|
const {
|
|
405
593
|
isOpen,
|
|
406
594
|
onOpen: onInternalOpen,
|
|
@@ -413,16 +601,16 @@ var useAutocomplete = (props) => {
|
|
|
413
601
|
});
|
|
414
602
|
const isFocused = focusedIndex > -1;
|
|
415
603
|
const isCreate = focusedIndex === -2 && allowCreate;
|
|
416
|
-
const isMulti = (0,
|
|
604
|
+
const isMulti = (0, import_utils7.isArray)(value);
|
|
417
605
|
const isEmptyValue = !isMulti ? !value : !value.length;
|
|
418
|
-
const [firstInsertPositionItem, secondInsertPositionItem] = (0,
|
|
419
|
-
if ((0,
|
|
606
|
+
const [firstInsertPositionItem, secondInsertPositionItem] = (0, import_react4.useMemo)(() => {
|
|
607
|
+
if ((0, import_utils7.isArray)(insertPositionItem)) {
|
|
420
608
|
return insertPositionItem;
|
|
421
609
|
} else {
|
|
422
610
|
return [insertPositionItem, "first"];
|
|
423
611
|
}
|
|
424
612
|
}, [insertPositionItem]);
|
|
425
|
-
if (allowCreate && !(0,
|
|
613
|
+
if (allowCreate && !(0, import_utils7.isUndefined)(children)) {
|
|
426
614
|
console.warn(
|
|
427
615
|
`${!isMulti ? "Autocomplete" : "MultiAutocomplete"}: ${!isMulti ? "Autocomplete" : "MultiAutocomplete"} internally prefers 'children'. If 'allowCreate' is true, it will not be reflected correctly. If want to reflect, please set 'items' in props.`
|
|
428
616
|
);
|
|
@@ -437,35 +625,27 @@ var useAutocomplete = (props) => {
|
|
|
437
625
|
const enabledValues = descendants.enabledValues(
|
|
438
626
|
({ node, index }) => "target" in node.dataset && !selectedIndexes.includes(index)
|
|
439
627
|
);
|
|
440
|
-
const validChildren = (0,
|
|
441
|
-
const computedChildren = (0,
|
|
628
|
+
const validChildren = (0, import_utils7.getValidChildren)(children);
|
|
629
|
+
const computedChildren = (0, import_react4.useMemo)(
|
|
442
630
|
() => resolvedItems == null ? void 0 : resolvedItems.map((item, i) => {
|
|
443
631
|
if ("value" in item) {
|
|
444
632
|
const { label: label2, value: value2, ...props2 } = item;
|
|
445
633
|
return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(AutocompleteOption, { value: value2, ...props2, children: label2 }, i);
|
|
446
634
|
} else if ("items" in item) {
|
|
447
635
|
const { label: label2, items: items2 = [], ...props2 } = item;
|
|
448
|
-
return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
|
|
449
|
-
AutocompleteOptionGroup,
|
|
450
|
-
{
|
|
451
|
-
label: label2,
|
|
452
|
-
...props2,
|
|
453
|
-
children: items2.map(({ label: label3, value: value2, ...props3 }, i2) => /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(AutocompleteOption, { value: value2, ...props3, children: label3 }, i2))
|
|
454
|
-
},
|
|
455
|
-
i
|
|
456
|
-
);
|
|
636
|
+
return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(AutocompleteOptionGroup, { label: label2, ...props2, children: items2.map(({ label: label3, value: value2, ...props3 }, i2) => /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(AutocompleteOption, { value: value2, ...props3, children: label3 }, i2)) }, i);
|
|
457
637
|
}
|
|
458
638
|
}),
|
|
459
639
|
[resolvedItems]
|
|
460
640
|
);
|
|
461
641
|
const isEmpty = !validChildren.length && !(computedChildren == null ? void 0 : computedChildren.length);
|
|
462
|
-
const onOpen = (0,
|
|
642
|
+
const onOpen = (0, import_react4.useCallback)(() => {
|
|
463
643
|
if (formControlProps.disabled || formControlProps.readOnly) return;
|
|
464
644
|
if (!allowCreate && (isEmpty || isAllSelected)) return;
|
|
465
645
|
onInternalOpen();
|
|
466
646
|
if (inputRef.current) inputRef.current.focus();
|
|
467
647
|
}, [allowCreate, formControlProps, isAllSelected, isEmpty, onInternalOpen]);
|
|
468
|
-
const onFocusFirst = (0,
|
|
648
|
+
const onFocusFirst = (0, import_react4.useCallback)(() => {
|
|
469
649
|
const id2 = setTimeout(() => {
|
|
470
650
|
if (isEmpty || isAllSelected) return;
|
|
471
651
|
const first = descendants.enabledFirstValue(
|
|
@@ -493,7 +673,7 @@ var useAutocomplete = (props) => {
|
|
|
493
673
|
omitSelectedValues,
|
|
494
674
|
selectedIndexes
|
|
495
675
|
]);
|
|
496
|
-
const onFocusLast = (0,
|
|
676
|
+
const onFocusLast = (0, import_react4.useCallback)(() => {
|
|
497
677
|
const id2 = setTimeout(() => {
|
|
498
678
|
if (isEmpty || isAllSelected) return;
|
|
499
679
|
const last = descendants.enabledLastValue(
|
|
@@ -521,7 +701,7 @@ var useAutocomplete = (props) => {
|
|
|
521
701
|
omitSelectedValues,
|
|
522
702
|
selectedIndexes
|
|
523
703
|
]);
|
|
524
|
-
const onFocusSelected = (0,
|
|
704
|
+
const onFocusSelected = (0, import_react4.useCallback)(() => {
|
|
525
705
|
const id2 = setTimeout(() => {
|
|
526
706
|
const values = descendants.enabledValues();
|
|
527
707
|
const selected = values.find(
|
|
@@ -534,7 +714,7 @@ var useAutocomplete = (props) => {
|
|
|
534
714
|
});
|
|
535
715
|
timeoutIds.current.add(id2);
|
|
536
716
|
}, [descendants, isMulti, value]);
|
|
537
|
-
const onFocusNext = (0,
|
|
717
|
+
const onFocusNext = (0, import_react4.useCallback)(
|
|
538
718
|
(index = focusedIndex) => {
|
|
539
719
|
const id2 = setTimeout(() => {
|
|
540
720
|
var _a;
|
|
@@ -565,7 +745,7 @@ var useAutocomplete = (props) => {
|
|
|
565
745
|
selectedIndexes
|
|
566
746
|
]
|
|
567
747
|
);
|
|
568
|
-
const onFocusPrev = (0,
|
|
748
|
+
const onFocusPrev = (0, import_react4.useCallback)(
|
|
569
749
|
(index = focusedIndex) => {
|
|
570
750
|
const id2 = setTimeout(() => {
|
|
571
751
|
var _a;
|
|
@@ -598,7 +778,7 @@ var useAutocomplete = (props) => {
|
|
|
598
778
|
);
|
|
599
779
|
const onFocusFirstOrSelected = isEmptyValue || omitSelectedValues ? onFocusFirst : onFocusSelected;
|
|
600
780
|
const onFocusLastOrSelected = isEmptyValue || omitSelectedValues ? onFocusLast : onFocusSelected;
|
|
601
|
-
const pickOptions = (0,
|
|
781
|
+
const pickOptions = (0, import_react4.useCallback)(
|
|
602
782
|
(value2) => {
|
|
603
783
|
const values = descendants.values();
|
|
604
784
|
let isHit2 = false;
|
|
@@ -621,7 +801,7 @@ var useAutocomplete = (props) => {
|
|
|
621
801
|
},
|
|
622
802
|
[descendants, format]
|
|
623
803
|
);
|
|
624
|
-
const rebirthOptions = (0,
|
|
804
|
+
const rebirthOptions = (0, import_react4.useCallback)(
|
|
625
805
|
(runFocus = true) => {
|
|
626
806
|
const values = descendants.values();
|
|
627
807
|
values.forEach(({ node }) => {
|
|
@@ -632,10 +812,10 @@ var useAutocomplete = (props) => {
|
|
|
632
812
|
},
|
|
633
813
|
[descendants, onFocusFirst]
|
|
634
814
|
);
|
|
635
|
-
const getSelectedValues = (0,
|
|
815
|
+
const getSelectedValues = (0, import_react4.useCallback)(
|
|
636
816
|
(newValues) => {
|
|
637
817
|
const enabledValues2 = descendants.enabledValues();
|
|
638
|
-
const resolvedValues = (0,
|
|
818
|
+
const resolvedValues = (0, import_utils7.isArray)(newValues) ? newValues : [newValues];
|
|
639
819
|
const selectedValues2 = resolvedValues.map((value2) => {
|
|
640
820
|
var _a, _b;
|
|
641
821
|
const { node } = (_a = enabledValues2.find(({ node: node2 }) => node2.dataset.value === value2)) != null ? _a : {};
|
|
@@ -652,7 +832,7 @@ var useAutocomplete = (props) => {
|
|
|
652
832
|
},
|
|
653
833
|
[allowFree, descendants]
|
|
654
834
|
);
|
|
655
|
-
const onChangeLabel = (0,
|
|
835
|
+
const onChangeLabel = (0, import_react4.useCallback)(
|
|
656
836
|
(newValue, { forceUpdate, runOmit = true } = {}) => {
|
|
657
837
|
const selectedValues2 = getSelectedValues(newValue);
|
|
658
838
|
if (!forceUpdate && !selectedValues2.length) return;
|
|
@@ -661,11 +841,11 @@ var useAutocomplete = (props) => {
|
|
|
661
841
|
return selectedValues2[0];
|
|
662
842
|
} else {
|
|
663
843
|
selectedValues2.forEach((selectedValue) => {
|
|
664
|
-
const isSelected = (0,
|
|
844
|
+
const isSelected = (0, import_utils7.isArray)(prev) && prev.includes(selectedValue != null ? selectedValue : "");
|
|
665
845
|
if (!isSelected) {
|
|
666
|
-
prev = [...(0,
|
|
846
|
+
prev = [...(0, import_utils7.isArray)(prev) ? prev : [], selectedValue];
|
|
667
847
|
} else if (runOmit) {
|
|
668
|
-
prev = (0,
|
|
848
|
+
prev = (0, import_utils7.isArray)(prev) ? prev.filter((value2) => value2 !== selectedValue) : void 0;
|
|
669
849
|
}
|
|
670
850
|
});
|
|
671
851
|
return prev;
|
|
@@ -674,11 +854,11 @@ var useAutocomplete = (props) => {
|
|
|
674
854
|
},
|
|
675
855
|
[getSelectedValues, isMulti]
|
|
676
856
|
);
|
|
677
|
-
const onChange = (0,
|
|
857
|
+
const onChange = (0, import_react4.useCallback)(
|
|
678
858
|
(newValue, { forceUpdate, runRebirth = true } = {}) => {
|
|
679
859
|
setValue((prev) => {
|
|
680
860
|
let next;
|
|
681
|
-
if (!(0,
|
|
861
|
+
if (!(0, import_utils7.isArray)(prev)) {
|
|
682
862
|
next = newValue;
|
|
683
863
|
} else {
|
|
684
864
|
const isSelected = prev.includes(newValue);
|
|
@@ -711,7 +891,7 @@ var useAutocomplete = (props) => {
|
|
|
711
891
|
format
|
|
712
892
|
]
|
|
713
893
|
);
|
|
714
|
-
const onSelect = (0,
|
|
894
|
+
const onSelect = (0, import_react4.useCallback)(() => {
|
|
715
895
|
var _a, _b;
|
|
716
896
|
let enabledValue = descendants.value(focusedIndex);
|
|
717
897
|
if ("disabled" in ((_a = enabledValue == null ? void 0 : enabledValue.node.dataset) != null ? _a : {}))
|
|
@@ -730,7 +910,7 @@ var useAutocomplete = (props) => {
|
|
|
730
910
|
onClose,
|
|
731
911
|
onFocusNext
|
|
732
912
|
]);
|
|
733
|
-
const onSearch = (0,
|
|
913
|
+
const onSearch = (0, import_react4.useCallback)(
|
|
734
914
|
(ev) => {
|
|
735
915
|
if (!isOpen) onOpen();
|
|
736
916
|
onSearchProp == null ? void 0 : onSearchProp(ev);
|
|
@@ -745,13 +925,13 @@ var useAutocomplete = (props) => {
|
|
|
745
925
|
},
|
|
746
926
|
[isOpen, onOpen, format, onSearchProp, pickOptions, rebirthOptions]
|
|
747
927
|
);
|
|
748
|
-
const onCompositionStart = (0,
|
|
928
|
+
const onCompositionStart = (0, import_react4.useCallback)(() => {
|
|
749
929
|
isComposition.current = true;
|
|
750
930
|
}, []);
|
|
751
|
-
const onCompositionEnd = (0,
|
|
931
|
+
const onCompositionEnd = (0, import_react4.useCallback)(() => {
|
|
752
932
|
isComposition.current = false;
|
|
753
933
|
}, []);
|
|
754
|
-
const onCreate = (0,
|
|
934
|
+
const onCreate = (0, import_react4.useCallback)(() => {
|
|
755
935
|
var _a, _b;
|
|
756
936
|
if (!listRef.current) return;
|
|
757
937
|
const newItem = { label: inputValue, value: inputValue };
|
|
@@ -797,7 +977,7 @@ var useAutocomplete = (props) => {
|
|
|
797
977
|
secondInsertPositionItem,
|
|
798
978
|
isMulti
|
|
799
979
|
]);
|
|
800
|
-
const onClick = (0,
|
|
980
|
+
const onClick = (0, import_react4.useCallback)(() => {
|
|
801
981
|
if (isOpen) {
|
|
802
982
|
if (inputRef.current) inputRef.current.focus();
|
|
803
983
|
} else {
|
|
@@ -805,15 +985,15 @@ var useAutocomplete = (props) => {
|
|
|
805
985
|
onFocusFirstOrSelected();
|
|
806
986
|
}
|
|
807
987
|
}, [isOpen, onFocusFirstOrSelected, onOpen]);
|
|
808
|
-
const onFocus = (0,
|
|
988
|
+
const onFocus = (0, import_react4.useCallback)(() => {
|
|
809
989
|
if (isOpen) return;
|
|
810
990
|
onOpen();
|
|
811
991
|
onFocusFirstOrSelected();
|
|
812
992
|
}, [isOpen, onFocusFirstOrSelected, onOpen]);
|
|
813
|
-
const onBlur = (0,
|
|
993
|
+
const onBlur = (0, import_react4.useCallback)(
|
|
814
994
|
(ev) => {
|
|
815
|
-
const relatedTarget = (0,
|
|
816
|
-
if ((0,
|
|
995
|
+
const relatedTarget = (0, import_utils7.getEventRelatedTarget)(ev);
|
|
996
|
+
if ((0, import_utils7.isContains)(containerRef.current, relatedTarget)) return;
|
|
817
997
|
if (!closeOnBlur && isHit) return;
|
|
818
998
|
if (allowFree && !!inputValue) onChange(inputValue, { runRebirth: false });
|
|
819
999
|
setInputValue("");
|
|
@@ -821,7 +1001,7 @@ var useAutocomplete = (props) => {
|
|
|
821
1001
|
},
|
|
822
1002
|
[closeOnBlur, isHit, isOpen, inputValue, allowFree, onClose, onChange]
|
|
823
1003
|
);
|
|
824
|
-
const onDelete = (0,
|
|
1004
|
+
const onDelete = (0, import_react4.useCallback)(() => {
|
|
825
1005
|
if (!isMulti) {
|
|
826
1006
|
onChange("", { forceUpdate: true });
|
|
827
1007
|
} else {
|
|
@@ -829,7 +1009,7 @@ var useAutocomplete = (props) => {
|
|
|
829
1009
|
}
|
|
830
1010
|
if (!isOpen) onFocus();
|
|
831
1011
|
}, [isMulti, isOpen, onChange, onFocus, value]);
|
|
832
|
-
const onClear = (0,
|
|
1012
|
+
const onClear = (0, import_react4.useCallback)(
|
|
833
1013
|
(ev) => {
|
|
834
1014
|
ev.stopPropagation();
|
|
835
1015
|
prevValue.current = [];
|
|
@@ -841,17 +1021,17 @@ var useAutocomplete = (props) => {
|
|
|
841
1021
|
},
|
|
842
1022
|
[isOpen, setLabel, setInputValue, setValue, rebirthOptions]
|
|
843
1023
|
);
|
|
844
|
-
const onKeyDown = (0,
|
|
1024
|
+
const onKeyDown = (0, import_react4.useCallback)(
|
|
845
1025
|
(ev) => {
|
|
846
1026
|
if (ev.key === " ") ev.key = ev.code;
|
|
847
1027
|
if (formControlProps.disabled || formControlProps.readOnly) return;
|
|
848
1028
|
if (isComposition.current) return;
|
|
849
1029
|
const enabledDelete = label === inputValue || !inputValue.length;
|
|
850
1030
|
const actions = {
|
|
851
|
-
ArrowDown: isFocused ? () => onFocusNext() : !isOpen ? (0,
|
|
852
|
-
ArrowUp: isFocused ? () => onFocusPrev() : !isOpen ? (0,
|
|
853
|
-
Space: isCreate ? onCreate : isFocused ? onSelect : !isOpen ? (0,
|
|
854
|
-
Enter: isCreate ? onCreate : isFocused ? onSelect : !isOpen ? (0,
|
|
1031
|
+
ArrowDown: isFocused ? () => onFocusNext() : !isOpen ? (0, import_utils7.funcAll)(onOpen, onFocusFirstOrSelected) : void 0,
|
|
1032
|
+
ArrowUp: isFocused ? () => onFocusPrev() : !isOpen ? (0, import_utils7.funcAll)(onOpen, onFocusLastOrSelected) : void 0,
|
|
1033
|
+
Space: isCreate ? onCreate : isFocused ? onSelect : !isOpen ? (0, import_utils7.funcAll)(onOpen, onFocusFirstOrSelected) : void 0,
|
|
1034
|
+
Enter: isCreate ? onCreate : isFocused ? onSelect : !isOpen ? (0, import_utils7.funcAll)(onOpen, onFocusFirstOrSelected) : allowFree && isMulti ? () => {
|
|
855
1035
|
if (inputValue) onChange(inputValue);
|
|
856
1036
|
setFocusedIndex(0);
|
|
857
1037
|
} : void 0,
|
|
@@ -891,9 +1071,9 @@ var useAutocomplete = (props) => {
|
|
|
891
1071
|
onChange
|
|
892
1072
|
]
|
|
893
1073
|
);
|
|
894
|
-
(0,
|
|
1074
|
+
(0, import_react4.useEffect)(() => {
|
|
895
1075
|
if (!isMulti) return;
|
|
896
|
-
if (!omitSelectedValues && (0,
|
|
1076
|
+
if (!omitSelectedValues && (0, import_utils7.isUndefined)(maxSelectValues)) return;
|
|
897
1077
|
const isAll = value.length > 0 && value.length === descendants.count();
|
|
898
1078
|
const isMax = value.length === maxSelectValues;
|
|
899
1079
|
if (isAll || isMax) {
|
|
@@ -910,7 +1090,7 @@ var useAutocomplete = (props) => {
|
|
|
910
1090
|
onClose,
|
|
911
1091
|
maxSelectValues
|
|
912
1092
|
]);
|
|
913
|
-
(0,
|
|
1093
|
+
(0, import_react4.useEffect)(() => {
|
|
914
1094
|
var _a;
|
|
915
1095
|
if (isMulti) {
|
|
916
1096
|
if (JSON.stringify((_a = prevValue.current) != null ? _a : []) === JSON.stringify(value != null ? value : []))
|
|
@@ -922,18 +1102,18 @@ var useAutocomplete = (props) => {
|
|
|
922
1102
|
onChangeLabel(value, { runOmit: false });
|
|
923
1103
|
}
|
|
924
1104
|
}, [isMulti, value, onChangeLabel, getSelectedValues]);
|
|
925
|
-
(0,
|
|
1105
|
+
(0, import_utils7.useUpdateEffect)(() => {
|
|
926
1106
|
if (isOpen || allowFree) return;
|
|
927
1107
|
setFocusedIndex(-1);
|
|
928
1108
|
setInputValue("");
|
|
929
1109
|
}, [isOpen]);
|
|
930
|
-
(0,
|
|
1110
|
+
(0, import_utils7.useUpdateEffect)(() => {
|
|
931
1111
|
if (!isHit) setFocusedIndex(-2);
|
|
932
1112
|
}, [isHit]);
|
|
933
|
-
(0,
|
|
1113
|
+
(0, import_utils7.useUpdateEffect)(() => {
|
|
934
1114
|
setResolvedItems(items ? JSON.parse(JSON.stringify(items)) : void 0);
|
|
935
1115
|
}, [items]);
|
|
936
|
-
(0,
|
|
1116
|
+
(0, import_utils7.useUnmountEffect)(() => {
|
|
937
1117
|
timeoutIds.current.forEach((id2) => clearTimeout(id2));
|
|
938
1118
|
timeoutIds.current.clear();
|
|
939
1119
|
});
|
|
@@ -942,7 +1122,7 @@ var useAutocomplete = (props) => {
|
|
|
942
1122
|
handler: onClose,
|
|
943
1123
|
enabled: isOpen && (closeOnBlur || !isHit)
|
|
944
1124
|
});
|
|
945
|
-
const getPopoverProps = (0,
|
|
1125
|
+
const getPopoverProps = (0, import_react4.useCallback)(
|
|
946
1126
|
(props2) => ({
|
|
947
1127
|
closeOnBlur,
|
|
948
1128
|
openDelay,
|
|
@@ -991,28 +1171,28 @@ var useAutocomplete = (props) => {
|
|
|
991
1171
|
onClose
|
|
992
1172
|
]
|
|
993
1173
|
);
|
|
994
|
-
const getContainerProps = (0,
|
|
1174
|
+
const getContainerProps = (0, import_react4.useCallback)(
|
|
995
1175
|
(props2 = {}, ref = null) => ({
|
|
996
|
-
ref: (0,
|
|
1176
|
+
ref: (0, import_utils7.mergeRefs)(containerRef, ref),
|
|
997
1177
|
...containerProps,
|
|
998
1178
|
...props2,
|
|
999
1179
|
...formControlProps,
|
|
1000
|
-
onClick: (0,
|
|
1001
|
-
onBlur: (0,
|
|
1180
|
+
onClick: (0, import_utils7.handlerAll)(props2.onClick, rest.onClick, onClick),
|
|
1181
|
+
onBlur: (0, import_utils7.handlerAll)(props2.onBlur, rest.onBlur, onBlur)
|
|
1002
1182
|
}),
|
|
1003
1183
|
[containerProps, formControlProps, onBlur, onClick, rest]
|
|
1004
1184
|
);
|
|
1005
|
-
const getFieldProps = (0,
|
|
1185
|
+
const getFieldProps = (0, import_react4.useCallback)(
|
|
1006
1186
|
(props2 = {}, ref = null) => ({
|
|
1007
1187
|
ref,
|
|
1008
1188
|
tabIndex: -1,
|
|
1009
1189
|
...props2,
|
|
1010
1190
|
...formControlProps,
|
|
1011
1191
|
placeholder,
|
|
1012
|
-
"data-active": (0,
|
|
1013
|
-
"aria-expanded": (0,
|
|
1014
|
-
onFocus: (0,
|
|
1015
|
-
onKeyDown: (0,
|
|
1192
|
+
"data-active": (0, import_utils7.dataAttr)(isOpen),
|
|
1193
|
+
"aria-expanded": (0, import_utils7.dataAttr)(isOpen),
|
|
1194
|
+
onFocus: (0, import_utils7.handlerAll)(props2.onFocus, onFocusProp, onFocus),
|
|
1195
|
+
onKeyDown: (0, import_utils7.handlerAll)(props2.onKeyDown, onKeyDownProp, onKeyDown)
|
|
1016
1196
|
}),
|
|
1017
1197
|
[
|
|
1018
1198
|
formControlProps,
|
|
@@ -1083,14 +1263,14 @@ var useAutocompleteInput = () => {
|
|
|
1083
1263
|
listRef
|
|
1084
1264
|
} = useAutocompleteContext();
|
|
1085
1265
|
const { value } = useAutocompleteDescendantsContext();
|
|
1086
|
-
(0,
|
|
1266
|
+
(0, import_utils7.useUpdateEffect)(() => {
|
|
1087
1267
|
if (isAllSelected && inputRef.current) inputRef.current.blur();
|
|
1088
1268
|
}, [isAllSelected]);
|
|
1089
|
-
const getInputProps = (0,
|
|
1269
|
+
const getInputProps = (0, import_react4.useCallback)(
|
|
1090
1270
|
(props = {}, ref = null) => {
|
|
1091
1271
|
var _a, _b;
|
|
1092
1272
|
return {
|
|
1093
|
-
ref: (0,
|
|
1273
|
+
ref: (0, import_utils7.mergeRefs)(inputRef, ref),
|
|
1094
1274
|
...formControlProps,
|
|
1095
1275
|
role: "combobox",
|
|
1096
1276
|
"aria-haspopup": "listbox",
|
|
@@ -1107,13 +1287,13 @@ var useAutocompleteInput = () => {
|
|
|
1107
1287
|
cursor: formControlProps.readOnly ? "default" : "text",
|
|
1108
1288
|
pointerEvents: formControlProps.disabled || isAllSelected ? "none" : "auto",
|
|
1109
1289
|
tabIndex: isAllSelected ? -1 : 0,
|
|
1110
|
-
onChange: (0,
|
|
1111
|
-
onCompositionStart: (0,
|
|
1290
|
+
onChange: (0, import_utils7.handlerAll)(props.onChange, onSearch),
|
|
1291
|
+
onCompositionStart: (0, import_utils7.handlerAll)(
|
|
1112
1292
|
props.onCompositionStart,
|
|
1113
1293
|
inputProps.onCompositionStart,
|
|
1114
1294
|
onCompositionStart
|
|
1115
1295
|
),
|
|
1116
|
-
onCompositionEnd: (0,
|
|
1296
|
+
onCompositionEnd: (0, import_utils7.handlerAll)(
|
|
1117
1297
|
props.onCompositionEnd,
|
|
1118
1298
|
inputProps.onCompositionEnd,
|
|
1119
1299
|
onCompositionEnd
|
|
@@ -1139,311 +1319,9 @@ var useAutocompleteInput = () => {
|
|
|
1139
1319
|
getInputProps
|
|
1140
1320
|
};
|
|
1141
1321
|
};
|
|
1142
|
-
var useAutocompleteList = () => {
|
|
1143
|
-
const { focusedIndex, isOpen, listRef, rebirthOptions } = useAutocompleteContext();
|
|
1144
|
-
const descendants = useAutocompleteDescendantsContext();
|
|
1145
|
-
const beforeFocusedIndex = (0, import_react2.useRef)(-1);
|
|
1146
|
-
const selectedValue = descendants.value(focusedIndex);
|
|
1147
|
-
const onAnimationComplete = (0, import_react2.useCallback)(() => {
|
|
1148
|
-
if (!isOpen) rebirthOptions(false);
|
|
1149
|
-
}, [isOpen, rebirthOptions]);
|
|
1150
|
-
(0, import_react2.useEffect)(() => {
|
|
1151
|
-
if (!listRef.current || !selectedValue) return;
|
|
1152
|
-
if (beforeFocusedIndex.current === selectedValue.index) return;
|
|
1153
|
-
const parent = listRef.current;
|
|
1154
|
-
const child = selectedValue.node;
|
|
1155
|
-
const parentHeight = parent.clientHeight;
|
|
1156
|
-
const viewTop = parent.scrollTop;
|
|
1157
|
-
const viewBottom = viewTop + parentHeight;
|
|
1158
|
-
const childHeight = child.clientHeight;
|
|
1159
|
-
const childTop = child.offsetTop;
|
|
1160
|
-
const childBottom = childTop + childHeight;
|
|
1161
|
-
const isInView = viewTop <= childTop && childBottom <= viewBottom;
|
|
1162
|
-
const isScrollBottom = beforeFocusedIndex.current < selectedValue.index;
|
|
1163
|
-
if (!isInView) {
|
|
1164
|
-
if (childBottom <= parentHeight) {
|
|
1165
|
-
listRef.current.scrollTo({ top: 0 });
|
|
1166
|
-
} else {
|
|
1167
|
-
if (!isScrollBottom) {
|
|
1168
|
-
listRef.current.scrollTo({ top: childTop + 1 });
|
|
1169
|
-
} else {
|
|
1170
|
-
listRef.current.scrollTo({ top: childBottom - parentHeight });
|
|
1171
|
-
}
|
|
1172
|
-
}
|
|
1173
|
-
}
|
|
1174
|
-
beforeFocusedIndex.current = selectedValue.index;
|
|
1175
|
-
}, [listRef, selectedValue]);
|
|
1176
|
-
(0, import_utils4.useUpdateEffect)(() => {
|
|
1177
|
-
if (!isOpen) beforeFocusedIndex.current = -1;
|
|
1178
|
-
}, [isOpen]);
|
|
1179
|
-
const getListProps = (0, import_react2.useCallback)(
|
|
1180
|
-
(props = {}, ref = null) => ({
|
|
1181
|
-
as: "ul",
|
|
1182
|
-
ref: (0, import_utils4.mergeRefs)(listRef, ref),
|
|
1183
|
-
role: "listbox",
|
|
1184
|
-
tabIndex: -1,
|
|
1185
|
-
position: "relative",
|
|
1186
|
-
id: props.id || (0, import_react2.useId)(),
|
|
1187
|
-
...props
|
|
1188
|
-
}),
|
|
1189
|
-
[listRef]
|
|
1190
|
-
);
|
|
1191
|
-
return {
|
|
1192
|
-
onAnimationComplete,
|
|
1193
|
-
getListProps
|
|
1194
|
-
};
|
|
1195
|
-
};
|
|
1196
|
-
var useAutocompleteOptionGroup = ({
|
|
1197
|
-
label,
|
|
1198
|
-
...rest
|
|
1199
|
-
}) => {
|
|
1200
|
-
const { value, omitSelectedValues } = useAutocompleteContext();
|
|
1201
|
-
const isMulti = (0, import_utils4.isArray)(value);
|
|
1202
|
-
const descendants = useAutocompleteDescendantsContext();
|
|
1203
|
-
const values = descendants.values();
|
|
1204
|
-
const selectedValues = isMulti && omitSelectedValues ? descendants.values(
|
|
1205
|
-
({ node }) => {
|
|
1206
|
-
var _a;
|
|
1207
|
-
return value.includes((_a = node.dataset.value) != null ? _a : "");
|
|
1208
|
-
}
|
|
1209
|
-
) : [];
|
|
1210
|
-
const selectedIndexes = selectedValues.map(({ index }) => index);
|
|
1211
|
-
const childValues = values.filter(
|
|
1212
|
-
({ node, index }) => {
|
|
1213
|
-
var _a;
|
|
1214
|
-
return ((_a = node.parentElement) == null ? void 0 : _a.dataset.label) === label && !selectedIndexes.includes(index) && "target" in node.dataset;
|
|
1215
|
-
}
|
|
1216
|
-
);
|
|
1217
|
-
const isEmpty = !childValues.length;
|
|
1218
|
-
const [containerProps, groupProps] = (0, import_utils4.splitObject)(rest, import_core4.layoutStyleProperties);
|
|
1219
|
-
const getContainerProps = (0, import_react2.useCallback)(
|
|
1220
|
-
(props = {}, ref = null) => {
|
|
1221
|
-
const style = {
|
|
1222
|
-
border: "0px",
|
|
1223
|
-
clip: "rect(0px, 0px, 0px, 0px)",
|
|
1224
|
-
height: "1px",
|
|
1225
|
-
width: "1px",
|
|
1226
|
-
margin: "-1px",
|
|
1227
|
-
padding: "0px",
|
|
1228
|
-
overflow: "hidden",
|
|
1229
|
-
whiteSpace: "nowrap",
|
|
1230
|
-
position: "absolute"
|
|
1231
|
-
};
|
|
1232
|
-
return {
|
|
1233
|
-
ref,
|
|
1234
|
-
...props,
|
|
1235
|
-
...containerProps,
|
|
1236
|
-
style: isEmpty ? style : void 0,
|
|
1237
|
-
"data-label": label,
|
|
1238
|
-
role: "autocomplete-group-container"
|
|
1239
|
-
};
|
|
1240
|
-
},
|
|
1241
|
-
[containerProps, isEmpty, label]
|
|
1242
|
-
);
|
|
1243
|
-
const getGroupProps = (0, import_react2.useCallback)(
|
|
1244
|
-
(props = {}, ref = null) => ({
|
|
1245
|
-
ref,
|
|
1246
|
-
...props,
|
|
1247
|
-
...groupProps,
|
|
1248
|
-
"data-label": label,
|
|
1249
|
-
role: "autocomplete-group"
|
|
1250
|
-
}),
|
|
1251
|
-
[groupProps, label]
|
|
1252
|
-
);
|
|
1253
|
-
return {
|
|
1254
|
-
label,
|
|
1255
|
-
getContainerProps,
|
|
1256
|
-
getGroupProps
|
|
1257
|
-
};
|
|
1258
|
-
};
|
|
1259
|
-
var useAutocompleteOption = (props) => {
|
|
1260
|
-
var _a, _b;
|
|
1261
|
-
const {
|
|
1262
|
-
value,
|
|
1263
|
-
omitSelectedValues,
|
|
1264
|
-
onChange,
|
|
1265
|
-
onChangeLabel,
|
|
1266
|
-
focusedIndex,
|
|
1267
|
-
setFocusedIndex,
|
|
1268
|
-
onClose,
|
|
1269
|
-
closeOnSelect: generalCloseOnSelect,
|
|
1270
|
-
optionProps,
|
|
1271
|
-
inputRef,
|
|
1272
|
-
onFocusNext
|
|
1273
|
-
} = useAutocompleteContext();
|
|
1274
|
-
let {
|
|
1275
|
-
icon: customIcon,
|
|
1276
|
-
isDisabled,
|
|
1277
|
-
isFocusable,
|
|
1278
|
-
closeOnSelect: customCloseOnSelect,
|
|
1279
|
-
children,
|
|
1280
|
-
value: optionValue,
|
|
1281
|
-
...computedProps
|
|
1282
|
-
} = { ...optionProps, ...props };
|
|
1283
|
-
const trulyDisabled = !!isDisabled && !isFocusable;
|
|
1284
|
-
const itemRef = (0, import_react2.useRef)(null);
|
|
1285
|
-
const { index, register, descendants } = useAutocompleteDescendant({
|
|
1286
|
-
disabled: trulyDisabled
|
|
1287
|
-
});
|
|
1288
|
-
const values = descendants.values();
|
|
1289
|
-
const frontValues = values.slice(0, index);
|
|
1290
|
-
const isMulti = (0, import_utils4.isArray)(value);
|
|
1291
|
-
const isDuplicated = !isMulti ? frontValues.some(({ node }) => node.dataset.value === (optionValue != null ? optionValue : "")) : false;
|
|
1292
|
-
const isSelected = !isDuplicated && (!isMulti ? (optionValue != null ? optionValue : "") === value : value.includes(optionValue != null ? optionValue : ""));
|
|
1293
|
-
const isTarget = "target" in ((_b = (_a = itemRef.current) == null ? void 0 : _a.dataset) != null ? _b : {});
|
|
1294
|
-
const isFocused = index === focusedIndex;
|
|
1295
|
-
const onClick = (0, import_react2.useCallback)(
|
|
1296
|
-
(ev) => {
|
|
1297
|
-
ev.stopPropagation();
|
|
1298
|
-
if (isDisabled) {
|
|
1299
|
-
if (inputRef.current) inputRef.current.focus();
|
|
1300
|
-
return;
|
|
1301
|
-
}
|
|
1302
|
-
if (!isTargetOption(ev.currentTarget)) {
|
|
1303
|
-
if (inputRef.current) inputRef.current.focus();
|
|
1304
|
-
return;
|
|
1305
|
-
}
|
|
1306
|
-
setFocusedIndex(index);
|
|
1307
|
-
onChange(optionValue != null ? optionValue : "");
|
|
1308
|
-
if (inputRef.current) inputRef.current.focus();
|
|
1309
|
-
if (customCloseOnSelect != null ? customCloseOnSelect : generalCloseOnSelect) onClose();
|
|
1310
|
-
if (omitSelectedValues) onFocusNext(index);
|
|
1311
|
-
},
|
|
1312
|
-
[
|
|
1313
|
-
onFocusNext,
|
|
1314
|
-
omitSelectedValues,
|
|
1315
|
-
isDisabled,
|
|
1316
|
-
optionValue,
|
|
1317
|
-
setFocusedIndex,
|
|
1318
|
-
index,
|
|
1319
|
-
onChange,
|
|
1320
|
-
customCloseOnSelect,
|
|
1321
|
-
generalCloseOnSelect,
|
|
1322
|
-
onClose,
|
|
1323
|
-
inputRef
|
|
1324
|
-
]
|
|
1325
|
-
);
|
|
1326
|
-
(0, import_utils4.useUpdateEffect)(() => {
|
|
1327
|
-
if (isSelected) onChangeLabel(optionValue != null ? optionValue : "", { runOmit: false });
|
|
1328
|
-
}, [optionValue]);
|
|
1329
|
-
const getOptionProps = (0, import_react2.useCallback)(
|
|
1330
|
-
(props2 = {}, ref = null) => {
|
|
1331
|
-
const style = {
|
|
1332
|
-
border: "0px",
|
|
1333
|
-
clip: "rect(0px, 0px, 0px, 0px)",
|
|
1334
|
-
height: "1px",
|
|
1335
|
-
width: "1px",
|
|
1336
|
-
margin: "-1px",
|
|
1337
|
-
padding: "0px",
|
|
1338
|
-
overflow: "hidden",
|
|
1339
|
-
whiteSpace: "nowrap",
|
|
1340
|
-
position: "absolute"
|
|
1341
|
-
};
|
|
1342
|
-
return {
|
|
1343
|
-
ref: (0, import_utils4.mergeRefs)(itemRef, ref, register),
|
|
1344
|
-
id: (0, import_react2.useId)(),
|
|
1345
|
-
role: "option",
|
|
1346
|
-
...computedProps,
|
|
1347
|
-
...props2,
|
|
1348
|
-
tabIndex: -1,
|
|
1349
|
-
style: !isTarget || omitSelectedValues && isSelected ? style : void 0,
|
|
1350
|
-
"data-target": (0, import_utils4.dataAttr)(true),
|
|
1351
|
-
"data-value": optionValue != null ? optionValue : "",
|
|
1352
|
-
"data-focus": (0, import_utils4.dataAttr)(isFocused),
|
|
1353
|
-
"data-disabled": (0, import_utils4.dataAttr)(isDisabled),
|
|
1354
|
-
"aria-checked": isSelected,
|
|
1355
|
-
"aria-disabled": (0, import_utils4.ariaAttr)(isDisabled),
|
|
1356
|
-
onClick: (0, import_utils4.handlerAll)(computedProps.onClick, props2.onClick, onClick)
|
|
1357
|
-
};
|
|
1358
|
-
},
|
|
1359
|
-
[
|
|
1360
|
-
optionValue,
|
|
1361
|
-
computedProps,
|
|
1362
|
-
isDisabled,
|
|
1363
|
-
isFocused,
|
|
1364
|
-
isSelected,
|
|
1365
|
-
isTarget,
|
|
1366
|
-
omitSelectedValues,
|
|
1367
|
-
onClick,
|
|
1368
|
-
register
|
|
1369
|
-
]
|
|
1370
|
-
);
|
|
1371
|
-
return {
|
|
1372
|
-
isSelected,
|
|
1373
|
-
isFocused,
|
|
1374
|
-
customIcon,
|
|
1375
|
-
children,
|
|
1376
|
-
getOptionProps
|
|
1377
|
-
};
|
|
1378
|
-
};
|
|
1379
|
-
var useAutocompleteCreate = () => {
|
|
1380
|
-
const { isHit, onCreate } = useAutocompleteContext();
|
|
1381
|
-
const getCreateProps = (0, import_react2.useCallback)(
|
|
1382
|
-
(props = {}, ref = null) => {
|
|
1383
|
-
const style = {
|
|
1384
|
-
border: "0px",
|
|
1385
|
-
clip: "rect(0px, 0px, 0px, 0px)",
|
|
1386
|
-
height: "1px",
|
|
1387
|
-
width: "1px",
|
|
1388
|
-
margin: "-1px",
|
|
1389
|
-
padding: "0px",
|
|
1390
|
-
overflow: "hidden",
|
|
1391
|
-
whiteSpace: "nowrap",
|
|
1392
|
-
position: "absolute"
|
|
1393
|
-
};
|
|
1394
|
-
return {
|
|
1395
|
-
ref,
|
|
1396
|
-
...props,
|
|
1397
|
-
tabIndex: -1,
|
|
1398
|
-
style: isHit ? style : void 0,
|
|
1399
|
-
"data-focus": (0, import_utils4.dataAttr)(!isHit),
|
|
1400
|
-
onClick: (0, import_utils4.handlerAll)(props.onClick, onCreate)
|
|
1401
|
-
};
|
|
1402
|
-
},
|
|
1403
|
-
[isHit, onCreate]
|
|
1404
|
-
);
|
|
1405
|
-
return { getCreateProps };
|
|
1406
|
-
};
|
|
1407
|
-
var useAutocompleteEmpty = () => {
|
|
1408
|
-
const { isHit, isEmpty } = useAutocompleteContext();
|
|
1409
|
-
const getEmptyProps = (0, import_react2.useCallback)(
|
|
1410
|
-
(props = {}, ref = null) => {
|
|
1411
|
-
const style = {
|
|
1412
|
-
border: "0px",
|
|
1413
|
-
clip: "rect(0px, 0px, 0px, 0px)",
|
|
1414
|
-
height: "1px",
|
|
1415
|
-
width: "1px",
|
|
1416
|
-
margin: "-1px",
|
|
1417
|
-
padding: "0px",
|
|
1418
|
-
overflow: "hidden",
|
|
1419
|
-
whiteSpace: "nowrap",
|
|
1420
|
-
position: "absolute"
|
|
1421
|
-
};
|
|
1422
|
-
return {
|
|
1423
|
-
ref,
|
|
1424
|
-
...props,
|
|
1425
|
-
tabIndex: -1,
|
|
1426
|
-
style: isHit && !isEmpty ? style : void 0
|
|
1427
|
-
};
|
|
1428
|
-
},
|
|
1429
|
-
[isHit, isEmpty]
|
|
1430
|
-
);
|
|
1431
|
-
return { getEmptyProps };
|
|
1432
|
-
};
|
|
1433
1322
|
// Annotate the CommonJS export names for ESM import in node:
|
|
1434
1323
|
0 && (module.exports = {
|
|
1435
|
-
AutocompleteDescendantsContextProvider,
|
|
1436
|
-
AutocompleteProvider,
|
|
1437
1324
|
useAutocomplete,
|
|
1438
|
-
|
|
1439
|
-
useAutocompleteCreate,
|
|
1440
|
-
useAutocompleteDescendant,
|
|
1441
|
-
useAutocompleteDescendants,
|
|
1442
|
-
useAutocompleteDescendantsContext,
|
|
1443
|
-
useAutocompleteEmpty,
|
|
1444
|
-
useAutocompleteInput,
|
|
1445
|
-
useAutocompleteList,
|
|
1446
|
-
useAutocompleteOption,
|
|
1447
|
-
useAutocompleteOptionGroup
|
|
1325
|
+
useAutocompleteInput
|
|
1448
1326
|
});
|
|
1449
1327
|
//# sourceMappingURL=use-autocomplete.js.map
|