@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/chunk-ZD25NCFE.mjs
DELETED
|
@@ -1,2038 +0,0 @@
|
|
|
1
|
-
"use client"
|
|
2
|
-
|
|
3
|
-
// src/autocomplete-list.tsx
|
|
4
|
-
import { ui as ui8, forwardRef as forwardRef8 } from "@yamada-ui/core";
|
|
5
|
-
import { PopoverContent } from "@yamada-ui/popover";
|
|
6
|
-
import { cx as cx8, handlerAll as handlerAll3 } from "@yamada-ui/utils";
|
|
7
|
-
|
|
8
|
-
// src/use-autocomplete.tsx
|
|
9
|
-
import { layoutStyleProperties } from "@yamada-ui/core";
|
|
10
|
-
import {
|
|
11
|
-
formControlProperties,
|
|
12
|
-
useFormControlProps
|
|
13
|
-
} from "@yamada-ui/form-control";
|
|
14
|
-
import { useControllableState } from "@yamada-ui/use-controllable-state";
|
|
15
|
-
import { createDescendant } from "@yamada-ui/use-descendant";
|
|
16
|
-
import { useDisclosure } from "@yamada-ui/use-disclosure";
|
|
17
|
-
import { useOutsideClick } from "@yamada-ui/use-outside-click";
|
|
18
|
-
import {
|
|
19
|
-
ariaAttr,
|
|
20
|
-
createContext,
|
|
21
|
-
dataAttr,
|
|
22
|
-
funcAll,
|
|
23
|
-
getEventRelatedTarget,
|
|
24
|
-
handlerAll as handlerAll2,
|
|
25
|
-
isArray,
|
|
26
|
-
isContains,
|
|
27
|
-
isHTMLElement,
|
|
28
|
-
mergeRefs,
|
|
29
|
-
pickObject,
|
|
30
|
-
splitObject,
|
|
31
|
-
useUnmountEffect,
|
|
32
|
-
useUpdateEffect,
|
|
33
|
-
getValidChildren as getValidChildren2,
|
|
34
|
-
isUndefined
|
|
35
|
-
} from "@yamada-ui/utils";
|
|
36
|
-
import { useCallback, useEffect, useId, useMemo as useMemo2, useRef as useRef2, useState } from "react";
|
|
37
|
-
|
|
38
|
-
// src/autocomplete.tsx
|
|
39
|
-
import {
|
|
40
|
-
ui as ui2,
|
|
41
|
-
forwardRef as forwardRef2,
|
|
42
|
-
useMultiComponentStyle,
|
|
43
|
-
omitThemeProps
|
|
44
|
-
} from "@yamada-ui/core";
|
|
45
|
-
import { Popover, PopoverTrigger } from "@yamada-ui/popover";
|
|
46
|
-
import { Portal } from "@yamada-ui/portal";
|
|
47
|
-
import { cx as cx2, runIfFunc } from "@yamada-ui/utils";
|
|
48
|
-
|
|
49
|
-
// src/autocomplete-icon.tsx
|
|
50
|
-
import { ui, forwardRef } from "@yamada-ui/core";
|
|
51
|
-
import { ChevronIcon, CloseIcon } from "@yamada-ui/icon";
|
|
52
|
-
import { useClickable } from "@yamada-ui/use-clickable";
|
|
53
|
-
import { cx, getValidChildren, isValidElement } from "@yamada-ui/utils";
|
|
54
|
-
import { cloneElement, useRef } from "react";
|
|
55
|
-
import { jsx } from "react/jsx-runtime";
|
|
56
|
-
var AutocompleteIcon = forwardRef(
|
|
57
|
-
({ className, children, __css, ...rest }, ref) => {
|
|
58
|
-
const { styles } = useAutocompleteContext();
|
|
59
|
-
const css = {
|
|
60
|
-
position: "absolute",
|
|
61
|
-
top: "50%",
|
|
62
|
-
transform: "translateY(-50%)",
|
|
63
|
-
display: "inline-flex",
|
|
64
|
-
alignItems: "center",
|
|
65
|
-
justifyContent: "center",
|
|
66
|
-
pointerEvents: "none",
|
|
67
|
-
cursor: "pointer",
|
|
68
|
-
...styles.icon,
|
|
69
|
-
...__css
|
|
70
|
-
};
|
|
71
|
-
const validChildren = getValidChildren(children);
|
|
72
|
-
const cloneChildren = validChildren.map(
|
|
73
|
-
(child) => cloneElement(child, {
|
|
74
|
-
focusable: false,
|
|
75
|
-
"aria-hidden": true,
|
|
76
|
-
style: {
|
|
77
|
-
maxWidth: "1em",
|
|
78
|
-
maxHeight: "1em",
|
|
79
|
-
color: "currentColor"
|
|
80
|
-
}
|
|
81
|
-
})
|
|
82
|
-
);
|
|
83
|
-
return /* @__PURE__ */ jsx(
|
|
84
|
-
ui.div,
|
|
85
|
-
{
|
|
86
|
-
ref,
|
|
87
|
-
className: cx("ui-autocomplete__icon", className),
|
|
88
|
-
__css: css,
|
|
89
|
-
...rest,
|
|
90
|
-
children: isValidElement(children) ? cloneChildren : /* @__PURE__ */ jsx(ChevronIcon, {})
|
|
91
|
-
}
|
|
92
|
-
);
|
|
93
|
-
}
|
|
94
|
-
);
|
|
95
|
-
var AutocompleteClearIcon = ({
|
|
96
|
-
className,
|
|
97
|
-
children,
|
|
98
|
-
...props
|
|
99
|
-
}) => {
|
|
100
|
-
const ref = useRef(null);
|
|
101
|
-
const { styles } = useAutocompleteContext();
|
|
102
|
-
const isDisabled = props.disabled;
|
|
103
|
-
const rest = useClickable({
|
|
104
|
-
ref,
|
|
105
|
-
isDisabled,
|
|
106
|
-
...props
|
|
107
|
-
});
|
|
108
|
-
return /* @__PURE__ */ jsx(
|
|
109
|
-
AutocompleteIcon,
|
|
110
|
-
{
|
|
111
|
-
"aria-label": "Clear value",
|
|
112
|
-
className: cx("ui-autocomplete__icon--clear", className),
|
|
113
|
-
__css: styles.clearIcon,
|
|
114
|
-
...rest,
|
|
115
|
-
children: children != null ? children : /* @__PURE__ */ jsx(CloseIcon, { w: "0.5em", h: "0.5em" })
|
|
116
|
-
}
|
|
117
|
-
);
|
|
118
|
-
};
|
|
119
|
-
var AutocompleteItemIcon = forwardRef(({ className, ...rest }, ref) => {
|
|
120
|
-
const { styles } = useAutocompleteContext();
|
|
121
|
-
const css = {
|
|
122
|
-
flexShrink: 0,
|
|
123
|
-
display: "inline-flex",
|
|
124
|
-
justifyContent: "center",
|
|
125
|
-
alignItems: "center",
|
|
126
|
-
fontSize: "0.85em",
|
|
127
|
-
...styles.itemIcon
|
|
128
|
-
};
|
|
129
|
-
return /* @__PURE__ */ jsx(
|
|
130
|
-
ui.span,
|
|
131
|
-
{
|
|
132
|
-
ref,
|
|
133
|
-
className: cx("ui-autocomplete__item__icon", className),
|
|
134
|
-
__css: css,
|
|
135
|
-
...rest
|
|
136
|
-
}
|
|
137
|
-
);
|
|
138
|
-
});
|
|
139
|
-
|
|
140
|
-
// src/autocomplete.tsx
|
|
141
|
-
import { jsx as jsx2, jsxs } from "react/jsx-runtime";
|
|
142
|
-
var Autocomplete = forwardRef2(
|
|
143
|
-
(props, ref) => {
|
|
144
|
-
const [styles, mergedProps] = useMultiComponentStyle("Autocomplete", props);
|
|
145
|
-
let {
|
|
146
|
-
className,
|
|
147
|
-
defaultValue = "",
|
|
148
|
-
color,
|
|
149
|
-
h,
|
|
150
|
-
height,
|
|
151
|
-
minH,
|
|
152
|
-
minHeight,
|
|
153
|
-
containerProps,
|
|
154
|
-
contentProps,
|
|
155
|
-
listProps,
|
|
156
|
-
fieldProps,
|
|
157
|
-
inputProps,
|
|
158
|
-
iconProps,
|
|
159
|
-
portalProps = { isDisabled: true },
|
|
160
|
-
createProps,
|
|
161
|
-
emptyProps,
|
|
162
|
-
header,
|
|
163
|
-
footer,
|
|
164
|
-
children,
|
|
165
|
-
...computedProps
|
|
166
|
-
} = omitThemeProps(mergedProps);
|
|
167
|
-
const {
|
|
168
|
-
value,
|
|
169
|
-
onClose,
|
|
170
|
-
descendants,
|
|
171
|
-
formControlProps,
|
|
172
|
-
getPopoverProps,
|
|
173
|
-
getContainerProps,
|
|
174
|
-
getFieldProps,
|
|
175
|
-
allowCreate,
|
|
176
|
-
isEmpty,
|
|
177
|
-
inputValue,
|
|
178
|
-
computedChildren,
|
|
179
|
-
...rest
|
|
180
|
-
} = useAutocomplete({ ...computedProps, defaultValue, children });
|
|
181
|
-
h != null ? h : h = height;
|
|
182
|
-
minH != null ? minH : minH = minHeight;
|
|
183
|
-
const css = {
|
|
184
|
-
w: "100%",
|
|
185
|
-
h: "fit-content",
|
|
186
|
-
color,
|
|
187
|
-
...styles.container
|
|
188
|
-
};
|
|
189
|
-
return /* @__PURE__ */ jsx2(AutocompleteDescendantsContextProvider, { value: descendants, children: /* @__PURE__ */ jsx2(
|
|
190
|
-
AutocompleteProvider,
|
|
191
|
-
{
|
|
192
|
-
value: {
|
|
193
|
-
...rest,
|
|
194
|
-
value,
|
|
195
|
-
onClose,
|
|
196
|
-
formControlProps,
|
|
197
|
-
inputValue,
|
|
198
|
-
allowCreate,
|
|
199
|
-
isEmpty,
|
|
200
|
-
styles
|
|
201
|
-
},
|
|
202
|
-
children: /* @__PURE__ */ jsx2(Popover, { ...getPopoverProps(), children: /* @__PURE__ */ jsxs(
|
|
203
|
-
ui2.div,
|
|
204
|
-
{
|
|
205
|
-
className: cx2("ui-autocomplete", className),
|
|
206
|
-
__css: css,
|
|
207
|
-
...getContainerProps(containerProps),
|
|
208
|
-
children: [
|
|
209
|
-
/* @__PURE__ */ jsxs(
|
|
210
|
-
ui2.div,
|
|
211
|
-
{
|
|
212
|
-
className: "ui-autocomplete__inner",
|
|
213
|
-
__css: { position: "relative", ...styles.inner },
|
|
214
|
-
children: [
|
|
215
|
-
/* @__PURE__ */ jsx2(
|
|
216
|
-
AutocompleteField,
|
|
217
|
-
{
|
|
218
|
-
h,
|
|
219
|
-
minH,
|
|
220
|
-
inputProps,
|
|
221
|
-
...getFieldProps(fieldProps, ref)
|
|
222
|
-
}
|
|
223
|
-
),
|
|
224
|
-
/* @__PURE__ */ jsx2(AutocompleteIcon, { ...iconProps, ...formControlProps })
|
|
225
|
-
]
|
|
226
|
-
}
|
|
227
|
-
),
|
|
228
|
-
!isEmpty ? /* @__PURE__ */ jsx2(Portal, { ...portalProps, children: /* @__PURE__ */ jsxs(
|
|
229
|
-
AutocompleteList,
|
|
230
|
-
{
|
|
231
|
-
header: runIfFunc(header, { value, onClose }),
|
|
232
|
-
footer: runIfFunc(footer, { value, onClose }),
|
|
233
|
-
contentProps,
|
|
234
|
-
...listProps,
|
|
235
|
-
children: [
|
|
236
|
-
allowCreate ? /* @__PURE__ */ jsx2(AutocompleteCreate, { ...createProps }) : /* @__PURE__ */ jsx2(AutocompleteEmpty, { ...emptyProps }),
|
|
237
|
-
children != null ? children : computedChildren
|
|
238
|
-
]
|
|
239
|
-
}
|
|
240
|
-
) }) : /* @__PURE__ */ jsx2(Portal, { ...portalProps, children: /* @__PURE__ */ jsx2(
|
|
241
|
-
AutocompleteList,
|
|
242
|
-
{
|
|
243
|
-
header: runIfFunc(header, { value, onClose }),
|
|
244
|
-
footer: runIfFunc(footer, { value, onClose }),
|
|
245
|
-
contentProps,
|
|
246
|
-
...listProps,
|
|
247
|
-
children: allowCreate && inputValue ? /* @__PURE__ */ jsx2(AutocompleteCreate, { ...createProps }) : /* @__PURE__ */ jsx2(AutocompleteEmpty, { ...emptyProps })
|
|
248
|
-
}
|
|
249
|
-
) })
|
|
250
|
-
]
|
|
251
|
-
}
|
|
252
|
-
) })
|
|
253
|
-
}
|
|
254
|
-
) });
|
|
255
|
-
}
|
|
256
|
-
);
|
|
257
|
-
var AutocompleteField = forwardRef2(
|
|
258
|
-
({ className, h, minH, placeholder, inputProps, ...rest }, ref) => {
|
|
259
|
-
const { label, inputValue, styles } = useAutocompleteContext();
|
|
260
|
-
const { getInputProps } = useAutocompleteInput();
|
|
261
|
-
const css = {
|
|
262
|
-
pe: "2rem",
|
|
263
|
-
h,
|
|
264
|
-
minH,
|
|
265
|
-
display: "flex",
|
|
266
|
-
alignItems: "center",
|
|
267
|
-
...styles.field,
|
|
268
|
-
cursor: "text"
|
|
269
|
-
};
|
|
270
|
-
return /* @__PURE__ */ jsx2(PopoverTrigger, { children: /* @__PURE__ */ jsx2(
|
|
271
|
-
ui2.div,
|
|
272
|
-
{
|
|
273
|
-
className: cx2("ui-autocomplete__field", className),
|
|
274
|
-
__css: css,
|
|
275
|
-
...rest,
|
|
276
|
-
children: /* @__PURE__ */ jsx2(
|
|
277
|
-
ui2.input,
|
|
278
|
-
{
|
|
279
|
-
className: "ui-autocomplete__field__input",
|
|
280
|
-
display: "inline-block",
|
|
281
|
-
w: "100%",
|
|
282
|
-
placeholder,
|
|
283
|
-
...getInputProps(
|
|
284
|
-
{ ...inputProps, value: inputValue || label || "" },
|
|
285
|
-
ref
|
|
286
|
-
)
|
|
287
|
-
}
|
|
288
|
-
)
|
|
289
|
-
}
|
|
290
|
-
) });
|
|
291
|
-
}
|
|
292
|
-
);
|
|
293
|
-
|
|
294
|
-
// src/autocomplete-option-group.tsx
|
|
295
|
-
import { ui as ui3, forwardRef as forwardRef3 } from "@yamada-ui/core";
|
|
296
|
-
import { cx as cx3 } from "@yamada-ui/utils";
|
|
297
|
-
import { jsx as jsx3, jsxs as jsxs2 } from "react/jsx-runtime";
|
|
298
|
-
var AutocompleteOptionGroup = forwardRef3(
|
|
299
|
-
({ className, color, h, height, minH, minHeight, children, ...rest }, ref) => {
|
|
300
|
-
const { styles } = useAutocompleteContext();
|
|
301
|
-
const { label, getContainerProps, getGroupProps } = useAutocompleteOptionGroup(rest);
|
|
302
|
-
h != null ? h : h = height;
|
|
303
|
-
minH != null ? minH : minH = minHeight;
|
|
304
|
-
return /* @__PURE__ */ jsxs2(
|
|
305
|
-
ui3.li,
|
|
306
|
-
{
|
|
307
|
-
className: cx3(
|
|
308
|
-
"ui-autocomplete__item",
|
|
309
|
-
"ui-autocomplete__item--group",
|
|
310
|
-
className
|
|
311
|
-
),
|
|
312
|
-
__css: { w: "100%", h: "fit-content", color },
|
|
313
|
-
...getContainerProps(),
|
|
314
|
-
children: [
|
|
315
|
-
/* @__PURE__ */ jsx3(
|
|
316
|
-
ui3.span,
|
|
317
|
-
{
|
|
318
|
-
className: "ui-autocomplete__item__group-label",
|
|
319
|
-
__css: styles.groupLabel,
|
|
320
|
-
lineClamp: 1,
|
|
321
|
-
children: label
|
|
322
|
-
}
|
|
323
|
-
),
|
|
324
|
-
/* @__PURE__ */ jsx3(
|
|
325
|
-
ui3.ul,
|
|
326
|
-
{
|
|
327
|
-
...getGroupProps({}, ref),
|
|
328
|
-
className: "ui-autocomplete__item__group",
|
|
329
|
-
__css: { h, minH, ...styles.group },
|
|
330
|
-
children
|
|
331
|
-
}
|
|
332
|
-
)
|
|
333
|
-
]
|
|
334
|
-
}
|
|
335
|
-
);
|
|
336
|
-
}
|
|
337
|
-
);
|
|
338
|
-
|
|
339
|
-
// src/autocomplete-option.tsx
|
|
340
|
-
import { ui as ui4, forwardRef as forwardRef4 } from "@yamada-ui/core";
|
|
341
|
-
import { cx as cx4 } from "@yamada-ui/utils";
|
|
342
|
-
import { jsx as jsx4, jsxs as jsxs3 } from "react/jsx-runtime";
|
|
343
|
-
var AutocompleteOption = forwardRef4(
|
|
344
|
-
({ className, icon, ...rest }, ref) => {
|
|
345
|
-
const { styles } = useAutocompleteContext();
|
|
346
|
-
const { isSelected, customIcon, children, getOptionProps } = useAutocompleteOption(rest);
|
|
347
|
-
icon != null ? icon : icon = customIcon;
|
|
348
|
-
const css = {
|
|
349
|
-
textDecoration: "none",
|
|
350
|
-
color: "inherit",
|
|
351
|
-
userSelect: "none",
|
|
352
|
-
display: "flex",
|
|
353
|
-
width: "100%",
|
|
354
|
-
alignItems: "center",
|
|
355
|
-
textAlign: "start",
|
|
356
|
-
flex: "0 0 auto",
|
|
357
|
-
outline: 0,
|
|
358
|
-
gap: "0.75rem",
|
|
359
|
-
...styles.item
|
|
360
|
-
};
|
|
361
|
-
return /* @__PURE__ */ jsxs3(
|
|
362
|
-
ui4.li,
|
|
363
|
-
{
|
|
364
|
-
className: cx4("ui-autocomplete__item", className),
|
|
365
|
-
__css: css,
|
|
366
|
-
...getOptionProps({}, ref),
|
|
367
|
-
children: [
|
|
368
|
-
icon !== null ? /* @__PURE__ */ jsx4(AutocompleteItemIcon, { opacity: isSelected ? 1 : 0, children: icon || /* @__PURE__ */ jsx4(CheckIcon, {}) }) : null,
|
|
369
|
-
/* @__PURE__ */ jsx4(ui4.span, { style: { flex: 1 }, "data-label": true, children })
|
|
370
|
-
]
|
|
371
|
-
}
|
|
372
|
-
);
|
|
373
|
-
}
|
|
374
|
-
);
|
|
375
|
-
var CheckIcon = () => /* @__PURE__ */ jsx4("svg", { viewBox: "0 0 14 14", width: "1em", height: "1em", children: /* @__PURE__ */ jsx4(
|
|
376
|
-
"polygon",
|
|
377
|
-
{
|
|
378
|
-
fill: "currentColor",
|
|
379
|
-
points: "5.5 11.9993304 14 3.49933039 12.5 2 5.5 8.99933039 1.5 4.9968652 0 6.49933039"
|
|
380
|
-
}
|
|
381
|
-
) });
|
|
382
|
-
|
|
383
|
-
// src/autocomplete-create.tsx
|
|
384
|
-
import { ui as ui5, forwardRef as forwardRef5 } from "@yamada-ui/core";
|
|
385
|
-
import { cx as cx5, runIfFunc as runIfFunc2 } from "@yamada-ui/utils";
|
|
386
|
-
import { jsx as jsx5, jsxs as jsxs4 } from "react/jsx-runtime";
|
|
387
|
-
var AutocompleteCreate = forwardRef5(
|
|
388
|
-
({ className, icon, children, ...rest }, ref) => {
|
|
389
|
-
const { inputValue, styles } = useAutocompleteContext();
|
|
390
|
-
const { getCreateProps } = useAutocompleteCreate();
|
|
391
|
-
children != null ? children : children = inputValue;
|
|
392
|
-
const css = {
|
|
393
|
-
textDecoration: "none",
|
|
394
|
-
color: "inherit",
|
|
395
|
-
userSelect: "none",
|
|
396
|
-
display: "flex",
|
|
397
|
-
width: "100%",
|
|
398
|
-
alignItems: "center",
|
|
399
|
-
textAlign: "start",
|
|
400
|
-
flex: "0 0 auto",
|
|
401
|
-
outline: 0,
|
|
402
|
-
gap: "0.75rem",
|
|
403
|
-
...styles.item
|
|
404
|
-
};
|
|
405
|
-
return /* @__PURE__ */ jsxs4(
|
|
406
|
-
ui5.li,
|
|
407
|
-
{
|
|
408
|
-
className: cx5("ui-autocomplete__item--create", className),
|
|
409
|
-
__css: css,
|
|
410
|
-
...getCreateProps(rest, ref),
|
|
411
|
-
children: [
|
|
412
|
-
icon !== null ? /* @__PURE__ */ jsx5(AutocompleteItemIcon, { children: icon || /* @__PURE__ */ jsx5(PlusIcon, {}) }) : null,
|
|
413
|
-
icon ? /* @__PURE__ */ jsx5(ui5.span, { style: { pointerEvents: "none", flex: 1 }, lineClamp: 1, children: runIfFunc2(children, inputValue) }) : runIfFunc2(children, inputValue)
|
|
414
|
-
]
|
|
415
|
-
}
|
|
416
|
-
);
|
|
417
|
-
}
|
|
418
|
-
);
|
|
419
|
-
var PlusIcon = () => /* @__PURE__ */ jsx5("svg", { viewBox: "0 0 45.402 45.402", width: "1em", height: "1em", children: /* @__PURE__ */ jsx5(
|
|
420
|
-
"path",
|
|
421
|
-
{
|
|
422
|
-
fill: "currentColor",
|
|
423
|
-
d: "M41.267,18.557H26.832V4.134C26.832,1.851,24.99,0,22.707,0c-2.283,0-4.124,1.851-4.124,4.135v14.432H4.141 c-2.283,0-4.139,1.851-4.138,4.135c-0.001,1.141,0.46,2.187,1.207,2.934c0.748,0.749,1.78,1.222,2.92,1.222h14.453V41.27 c0,1.142,0.453,2.176,1.201,2.922c0.748,0.748,1.777,1.211,2.919,1.211c2.282,0,4.129-1.851,4.129-4.133V26.857h14.435 c2.283,0,4.134-1.867,4.133-4.15C45.399,20.425,43.548,18.557,41.267,18.557z"
|
|
424
|
-
}
|
|
425
|
-
) });
|
|
426
|
-
|
|
427
|
-
// src/autocomplete-empty.tsx
|
|
428
|
-
import { ui as ui6, forwardRef as forwardRef6 } from "@yamada-ui/core";
|
|
429
|
-
import { cx as cx6 } from "@yamada-ui/utils";
|
|
430
|
-
import { jsx as jsx6, jsxs as jsxs5 } from "react/jsx-runtime";
|
|
431
|
-
var AutocompleteEmpty = forwardRef6(
|
|
432
|
-
({ className, icon, children, ...rest }, ref) => {
|
|
433
|
-
const { emptyMessage, styles } = useAutocompleteContext();
|
|
434
|
-
const { getEmptyProps } = useAutocompleteEmpty();
|
|
435
|
-
children != null ? children : children = emptyMessage;
|
|
436
|
-
const css = {
|
|
437
|
-
textDecoration: "none",
|
|
438
|
-
color: "inherit",
|
|
439
|
-
userSelect: "none",
|
|
440
|
-
display: "flex",
|
|
441
|
-
width: "100%",
|
|
442
|
-
alignItems: "center",
|
|
443
|
-
textAlign: "start",
|
|
444
|
-
flex: "0 0 auto",
|
|
445
|
-
outline: 0,
|
|
446
|
-
gap: "0.75rem",
|
|
447
|
-
pointerEvents: "none",
|
|
448
|
-
...styles.item
|
|
449
|
-
};
|
|
450
|
-
return /* @__PURE__ */ jsxs5(
|
|
451
|
-
ui6.li,
|
|
452
|
-
{
|
|
453
|
-
className: cx6("ui-autocomplete__item--empty", className),
|
|
454
|
-
__css: css,
|
|
455
|
-
...getEmptyProps(rest, ref),
|
|
456
|
-
children: [
|
|
457
|
-
icon !== null ? /* @__PURE__ */ jsx6(AutocompleteItemIcon, { children: icon || /* @__PURE__ */ jsx6(MinusIcon, {}) }) : null,
|
|
458
|
-
icon ? /* @__PURE__ */ jsx6(ui6.span, { style: { pointerEvents: "none", flex: 1 }, lineClamp: 1, children }) : children
|
|
459
|
-
]
|
|
460
|
-
}
|
|
461
|
-
);
|
|
462
|
-
}
|
|
463
|
-
);
|
|
464
|
-
var MinusIcon = () => /* @__PURE__ */ jsx6("svg", { viewBox: "0 0 448 512", width: "1em", height: "1em", children: /* @__PURE__ */ jsx6(
|
|
465
|
-
"path",
|
|
466
|
-
{
|
|
467
|
-
fill: "currentColor",
|
|
468
|
-
d: "M432 256c0 17.7-14.3 32-32 32L48 288c-17.7 0-32-14.3-32-32s14.3-32 32-32l352 0c17.7 0 32 14.3 32 32z"
|
|
469
|
-
}
|
|
470
|
-
) });
|
|
471
|
-
|
|
472
|
-
// src/multi-autocomplete.tsx
|
|
473
|
-
import {
|
|
474
|
-
ui as ui7,
|
|
475
|
-
forwardRef as forwardRef7,
|
|
476
|
-
useMultiComponentStyle as useMultiComponentStyle2,
|
|
477
|
-
omitThemeProps as omitThemeProps2
|
|
478
|
-
} from "@yamada-ui/core";
|
|
479
|
-
import { Popover as Popover2, PopoverTrigger as PopoverTrigger2 } from "@yamada-ui/popover";
|
|
480
|
-
import { Portal as Portal2 } from "@yamada-ui/portal";
|
|
481
|
-
import { cx as cx7, handlerAll, runIfFunc as runIfFunc3 } from "@yamada-ui/utils";
|
|
482
|
-
import { cloneElement as cloneElement2, useMemo } from "react";
|
|
483
|
-
import { jsx as jsx7, jsxs as jsxs6 } from "react/jsx-runtime";
|
|
484
|
-
var MultiAutocomplete = forwardRef7(
|
|
485
|
-
(props, ref) => {
|
|
486
|
-
const [styles, mergedProps] = useMultiComponentStyle2(
|
|
487
|
-
"MultiAutocomplete",
|
|
488
|
-
props
|
|
489
|
-
);
|
|
490
|
-
let {
|
|
491
|
-
className,
|
|
492
|
-
defaultValue = [],
|
|
493
|
-
component,
|
|
494
|
-
separator,
|
|
495
|
-
isClearable = true,
|
|
496
|
-
color,
|
|
497
|
-
h,
|
|
498
|
-
height,
|
|
499
|
-
minH,
|
|
500
|
-
minHeight,
|
|
501
|
-
closeOnSelect = false,
|
|
502
|
-
keepPlaceholder = false,
|
|
503
|
-
containerProps,
|
|
504
|
-
contentProps,
|
|
505
|
-
listProps,
|
|
506
|
-
fieldProps,
|
|
507
|
-
inputProps,
|
|
508
|
-
iconProps,
|
|
509
|
-
clearIconProps,
|
|
510
|
-
portalProps = { isDisabled: true },
|
|
511
|
-
createProps,
|
|
512
|
-
emptyProps,
|
|
513
|
-
header,
|
|
514
|
-
footer,
|
|
515
|
-
children,
|
|
516
|
-
...computedProps
|
|
517
|
-
} = omitThemeProps2(mergedProps);
|
|
518
|
-
const {
|
|
519
|
-
value,
|
|
520
|
-
onClose,
|
|
521
|
-
descendants,
|
|
522
|
-
formControlProps,
|
|
523
|
-
getPopoverProps,
|
|
524
|
-
getContainerProps,
|
|
525
|
-
getFieldProps,
|
|
526
|
-
allowCreate,
|
|
527
|
-
isEmpty,
|
|
528
|
-
inputValue,
|
|
529
|
-
computedChildren,
|
|
530
|
-
onClear,
|
|
531
|
-
...rest
|
|
532
|
-
} = useAutocomplete({
|
|
533
|
-
...computedProps,
|
|
534
|
-
defaultValue,
|
|
535
|
-
closeOnSelect,
|
|
536
|
-
children
|
|
537
|
-
});
|
|
538
|
-
h != null ? h : h = height;
|
|
539
|
-
minH != null ? minH : minH = minHeight;
|
|
540
|
-
const css = {
|
|
541
|
-
w: "100%",
|
|
542
|
-
h: "fit-content",
|
|
543
|
-
color,
|
|
544
|
-
...styles.container
|
|
545
|
-
};
|
|
546
|
-
return /* @__PURE__ */ jsx7(AutocompleteDescendantsContextProvider, { value: descendants, children: /* @__PURE__ */ jsx7(
|
|
547
|
-
AutocompleteProvider,
|
|
548
|
-
{
|
|
549
|
-
value: {
|
|
550
|
-
...rest,
|
|
551
|
-
value,
|
|
552
|
-
onClose,
|
|
553
|
-
formControlProps,
|
|
554
|
-
inputValue,
|
|
555
|
-
allowCreate,
|
|
556
|
-
isEmpty,
|
|
557
|
-
styles
|
|
558
|
-
},
|
|
559
|
-
children: /* @__PURE__ */ jsx7(Popover2, { ...getPopoverProps(), children: /* @__PURE__ */ jsxs6(
|
|
560
|
-
ui7.div,
|
|
561
|
-
{
|
|
562
|
-
className: cx7("ui-multi-autocomplete", className),
|
|
563
|
-
__css: css,
|
|
564
|
-
...getContainerProps(containerProps),
|
|
565
|
-
children: [
|
|
566
|
-
/* @__PURE__ */ jsxs6(
|
|
567
|
-
ui7.div,
|
|
568
|
-
{
|
|
569
|
-
className: "ui-multi-autocomplete__inner",
|
|
570
|
-
__css: { position: "relative", ...styles.inner },
|
|
571
|
-
children: [
|
|
572
|
-
/* @__PURE__ */ jsx7(
|
|
573
|
-
MultiAutocompleteField,
|
|
574
|
-
{
|
|
575
|
-
component,
|
|
576
|
-
separator,
|
|
577
|
-
keepPlaceholder,
|
|
578
|
-
h,
|
|
579
|
-
minH,
|
|
580
|
-
inputProps,
|
|
581
|
-
...getFieldProps(fieldProps, ref)
|
|
582
|
-
}
|
|
583
|
-
),
|
|
584
|
-
isClearable && value.length ? /* @__PURE__ */ jsx7(
|
|
585
|
-
AutocompleteClearIcon,
|
|
586
|
-
{
|
|
587
|
-
...clearIconProps,
|
|
588
|
-
onClick: handlerAll(clearIconProps == null ? void 0 : clearIconProps.onClick, onClear),
|
|
589
|
-
...formControlProps
|
|
590
|
-
}
|
|
591
|
-
) : /* @__PURE__ */ jsx7(AutocompleteIcon, { ...iconProps, ...formControlProps })
|
|
592
|
-
]
|
|
593
|
-
}
|
|
594
|
-
),
|
|
595
|
-
!isEmpty ? /* @__PURE__ */ jsx7(Portal2, { ...portalProps, children: /* @__PURE__ */ jsxs6(
|
|
596
|
-
AutocompleteList,
|
|
597
|
-
{
|
|
598
|
-
header: runIfFunc3(header, { value, onClose }),
|
|
599
|
-
footer: runIfFunc3(footer, { value, onClose }),
|
|
600
|
-
contentProps,
|
|
601
|
-
...listProps,
|
|
602
|
-
children: [
|
|
603
|
-
allowCreate ? /* @__PURE__ */ jsx7(AutocompleteCreate, { ...createProps }) : /* @__PURE__ */ jsx7(AutocompleteEmpty, { ...emptyProps }),
|
|
604
|
-
children != null ? children : computedChildren
|
|
605
|
-
]
|
|
606
|
-
}
|
|
607
|
-
) }) : /* @__PURE__ */ jsx7(Portal2, { ...portalProps, children: /* @__PURE__ */ jsx7(
|
|
608
|
-
AutocompleteList,
|
|
609
|
-
{
|
|
610
|
-
header: runIfFunc3(header, { value, onClose }),
|
|
611
|
-
footer: runIfFunc3(footer, { value, onClose }),
|
|
612
|
-
contentProps,
|
|
613
|
-
...listProps,
|
|
614
|
-
children: allowCreate && inputValue ? /* @__PURE__ */ jsx7(AutocompleteCreate, { ...createProps }) : /* @__PURE__ */ jsx7(AutocompleteEmpty, { ...emptyProps })
|
|
615
|
-
}
|
|
616
|
-
) })
|
|
617
|
-
]
|
|
618
|
-
}
|
|
619
|
-
) })
|
|
620
|
-
}
|
|
621
|
-
) });
|
|
622
|
-
}
|
|
623
|
-
);
|
|
624
|
-
var MultiAutocompleteField = forwardRef7(
|
|
625
|
-
({
|
|
626
|
-
className,
|
|
627
|
-
component,
|
|
628
|
-
separator = ",",
|
|
629
|
-
keepPlaceholder,
|
|
630
|
-
h,
|
|
631
|
-
minH,
|
|
632
|
-
placeholder,
|
|
633
|
-
inputProps,
|
|
634
|
-
...rest
|
|
635
|
-
}, ref) => {
|
|
636
|
-
const { value, label, inputValue, onChange, isOpen, inputRef, styles } = useAutocompleteContext();
|
|
637
|
-
const { getInputProps } = useAutocompleteInput();
|
|
638
|
-
const cloneChildren = useMemo(() => {
|
|
639
|
-
if (!(label == null ? void 0 : label.length)) return null;
|
|
640
|
-
if (component) {
|
|
641
|
-
return label.map((label2, index) => {
|
|
642
|
-
const onRemove = (ev) => {
|
|
643
|
-
ev.stopPropagation();
|
|
644
|
-
onChange(value[index]);
|
|
645
|
-
if (inputRef.current) inputRef.current.focus();
|
|
646
|
-
};
|
|
647
|
-
const el = component({
|
|
648
|
-
value: value[index],
|
|
649
|
-
label: label2,
|
|
650
|
-
index,
|
|
651
|
-
onRemove
|
|
652
|
-
});
|
|
653
|
-
const style = {
|
|
654
|
-
marginBlockStart: "0.125rem",
|
|
655
|
-
marginBlockEnd: "0.125rem",
|
|
656
|
-
marginInlineEnd: "0.25rem"
|
|
657
|
-
};
|
|
658
|
-
return el ? cloneElement2(el, { key: index, style }) : null;
|
|
659
|
-
});
|
|
660
|
-
} else {
|
|
661
|
-
return label.map((value2, index) => {
|
|
662
|
-
const isLast = label.length === index + 1;
|
|
663
|
-
return /* @__PURE__ */ jsxs6(ui7.span, { display: "inline-block", me: "0.25rem", children: [
|
|
664
|
-
value2,
|
|
665
|
-
!isLast || isOpen ? separator : null
|
|
666
|
-
] }, index);
|
|
667
|
-
});
|
|
668
|
-
}
|
|
669
|
-
}, [label, component, value, onChange, isOpen, inputRef, separator]);
|
|
670
|
-
const css = {
|
|
671
|
-
pe: "2rem",
|
|
672
|
-
h,
|
|
673
|
-
minH,
|
|
674
|
-
display: "flex",
|
|
675
|
-
flexWrap: "wrap",
|
|
676
|
-
alignItems: "center",
|
|
677
|
-
...styles.field,
|
|
678
|
-
cursor: "text"
|
|
679
|
-
};
|
|
680
|
-
return /* @__PURE__ */ jsx7(PopoverTrigger2, { children: /* @__PURE__ */ jsxs6(
|
|
681
|
-
ui7.div,
|
|
682
|
-
{
|
|
683
|
-
className: cx7("ui-multi-autocomplete__field", className),
|
|
684
|
-
__css: css,
|
|
685
|
-
py: (label == null ? void 0 : label.length) && component ? "0.125rem" : void 0,
|
|
686
|
-
...rest,
|
|
687
|
-
children: [
|
|
688
|
-
cloneChildren,
|
|
689
|
-
/* @__PURE__ */ jsx7(
|
|
690
|
-
ui7.input,
|
|
691
|
-
{
|
|
692
|
-
"aria-label": "Input value",
|
|
693
|
-
className: "ui-multi-autocomplete__field__input",
|
|
694
|
-
display: "inline-block",
|
|
695
|
-
flex: "1",
|
|
696
|
-
minW: "0px",
|
|
697
|
-
overflow: "hidden",
|
|
698
|
-
marginBlockStart: "0.125rem",
|
|
699
|
-
marginBlockEnd: "0.125rem",
|
|
700
|
-
"aria-multiselectable": "true",
|
|
701
|
-
placeholder: !label || !(label == null ? void 0 : label.length) || keepPlaceholder && isOpen ? placeholder : void 0,
|
|
702
|
-
...getInputProps({ ...inputProps, value: inputValue != null ? inputValue : "" }, ref)
|
|
703
|
-
}
|
|
704
|
-
)
|
|
705
|
-
]
|
|
706
|
-
}
|
|
707
|
-
) });
|
|
708
|
-
}
|
|
709
|
-
);
|
|
710
|
-
|
|
711
|
-
// src/use-autocomplete.tsx
|
|
712
|
-
import { jsx as jsx8 } from "react/jsx-runtime";
|
|
713
|
-
var kanaMap = {
|
|
714
|
-
\uFF76\uFF9E: "\u30AC",
|
|
715
|
-
\uFF77\uFF9E: "\u30AE",
|
|
716
|
-
\uFF78\uFF9E: "\u30B0",
|
|
717
|
-
\uFF79\uFF9E: "\u30B2",
|
|
718
|
-
\uFF7A\uFF9E: "\u30B4",
|
|
719
|
-
\uFF7B\uFF9E: "\u30B6",
|
|
720
|
-
\uFF7C\uFF9E: "\u30B8",
|
|
721
|
-
\uFF7D\uFF9E: "\u30BA",
|
|
722
|
-
\uFF7E\uFF9E: "\u30BC",
|
|
723
|
-
\uFF7F\uFF9E: "\u30BE",
|
|
724
|
-
\uFF80\uFF9E: "\u30C0",
|
|
725
|
-
\uFF81\uFF9E: "\u30C2",
|
|
726
|
-
\uFF82\uFF9E: "\u30C5",
|
|
727
|
-
\uFF83\uFF9E: "\u30C7",
|
|
728
|
-
\uFF84\uFF9E: "\u30C9",
|
|
729
|
-
\uFF8A\uFF9E: "\u30D0",
|
|
730
|
-
\uFF8B\uFF9E: "\u30D3",
|
|
731
|
-
\uFF8C\uFF9E: "\u30D6",
|
|
732
|
-
\uFF8D\uFF9E: "\u30D9",
|
|
733
|
-
\uFF8E\uFF9E: "\u30DC",
|
|
734
|
-
\uFF8A\uFF9F: "\u30D1",
|
|
735
|
-
\uFF8B\uFF9F: "\u30D4",
|
|
736
|
-
\uFF8C\uFF9F: "\u30D7",
|
|
737
|
-
\uFF8D\uFF9F: "\u30DA",
|
|
738
|
-
\uFF8E\uFF9F: "\u30DD",
|
|
739
|
-
\uFF73\uFF9E: "\u30F4",
|
|
740
|
-
\uFF9C\uFF9E: "\u30F7",
|
|
741
|
-
\uFF66\uFF9E: "\u30FA",
|
|
742
|
-
\uFF71: "\u30A2",
|
|
743
|
-
\uFF72: "\u30A4",
|
|
744
|
-
\uFF73: "\u30A6",
|
|
745
|
-
\uFF74: "\u30A8",
|
|
746
|
-
\uFF75: "\u30AA",
|
|
747
|
-
\uFF76: "\u30AB",
|
|
748
|
-
\uFF77: "\u30AD",
|
|
749
|
-
\uFF78: "\u30AF",
|
|
750
|
-
\uFF79: "\u30B1",
|
|
751
|
-
\uFF7A: "\u30B3",
|
|
752
|
-
\uFF7B: "\u30B5",
|
|
753
|
-
\uFF7C: "\u30B7",
|
|
754
|
-
\uFF7D: "\u30B9",
|
|
755
|
-
\uFF7E: "\u30BB",
|
|
756
|
-
\uFF7F: "\u30BD",
|
|
757
|
-
\uFF80: "\u30BF",
|
|
758
|
-
\uFF81: "\u30C1",
|
|
759
|
-
\uFF82: "\u30C4",
|
|
760
|
-
\uFF83: "\u30C6",
|
|
761
|
-
\uFF84: "\u30C8",
|
|
762
|
-
\uFF85: "\u30CA",
|
|
763
|
-
\uFF86: "\u30CB",
|
|
764
|
-
\uFF87: "\u30CC",
|
|
765
|
-
\uFF88: "\u30CD",
|
|
766
|
-
\uFF89: "\u30CE",
|
|
767
|
-
\uFF8A: "\u30CF",
|
|
768
|
-
\uFF8B: "\u30D2",
|
|
769
|
-
\uFF8C: "\u30D5",
|
|
770
|
-
\uFF8D: "\u30D8",
|
|
771
|
-
\uFF8E: "\u30DB",
|
|
772
|
-
\uFF8F: "\u30DE",
|
|
773
|
-
\uFF90: "\u30DF",
|
|
774
|
-
\uFF91: "\u30E0",
|
|
775
|
-
\uFF92: "\u30E1",
|
|
776
|
-
\uFF93: "\u30E2",
|
|
777
|
-
\uFF94: "\u30E4",
|
|
778
|
-
\uFF95: "\u30E6",
|
|
779
|
-
\uFF96: "\u30E8",
|
|
780
|
-
\uFF97: "\u30E9",
|
|
781
|
-
\uFF98: "\u30EA",
|
|
782
|
-
\uFF99: "\u30EB",
|
|
783
|
-
\uFF9A: "\u30EC",
|
|
784
|
-
\uFF9B: "\u30ED",
|
|
785
|
-
\uFF9C: "\u30EF",
|
|
786
|
-
\uFF66: "\u30F2",
|
|
787
|
-
\uFF9D: "\u30F3",
|
|
788
|
-
\uFF67: "\u30A1",
|
|
789
|
-
\uFF68: "\u30A3",
|
|
790
|
-
\uFF69: "\u30A5",
|
|
791
|
-
\uFF6A: "\u30A7",
|
|
792
|
-
\uFF6B: "\u30A9",
|
|
793
|
-
\uFF6F: "\u30C3",
|
|
794
|
-
\uFF6C: "\u30E3",
|
|
795
|
-
\uFF6D: "\u30E5",
|
|
796
|
-
\uFF6E: "\u30E7",
|
|
797
|
-
"\uFF61": "\u3002",
|
|
798
|
-
"\uFF64": "\u3001",
|
|
799
|
-
\uFF70: "\u30FC",
|
|
800
|
-
"\uFF62": "\u300C",
|
|
801
|
-
"\uFF63": "\u300D",
|
|
802
|
-
"\uFF65": "\u30FB"
|
|
803
|
-
};
|
|
804
|
-
var defaultFormat = (value) => {
|
|
805
|
-
value = value.replace(
|
|
806
|
-
/[!-~]/g,
|
|
807
|
-
(v) => String.fromCharCode(v.charCodeAt(0) - 65248)
|
|
808
|
-
);
|
|
809
|
-
const reg = new RegExp("(" + Object.keys(kanaMap).join("|") + ")", "g");
|
|
810
|
-
value = value.replace(reg, (v) => kanaMap[v]).replace(/゙/g, "\u309B").replace(/゚/g, "\u309C");
|
|
811
|
-
value = value.toUpperCase();
|
|
812
|
-
return value;
|
|
813
|
-
};
|
|
814
|
-
var flattenItems = (items) => {
|
|
815
|
-
const filterItems = (items2) => items2.map((item) => {
|
|
816
|
-
var _a;
|
|
817
|
-
const { isDisabled, isFocusable } = item;
|
|
818
|
-
const trulyDisabled = !!isDisabled && !isFocusable;
|
|
819
|
-
if (trulyDisabled) return;
|
|
820
|
-
if ("items" in item) {
|
|
821
|
-
return filterItems((_a = item.items) != null ? _a : []);
|
|
822
|
-
} else {
|
|
823
|
-
return item;
|
|
824
|
-
}
|
|
825
|
-
}).filter(Boolean);
|
|
826
|
-
return filterItems(items).flat(Infinity);
|
|
827
|
-
};
|
|
828
|
-
var isTargetOption = (target) => {
|
|
829
|
-
var _a;
|
|
830
|
-
return isHTMLElement(target) && !!((_a = target == null ? void 0 : target.getAttribute("role")) == null ? void 0 : _a.startsWith("option"));
|
|
831
|
-
};
|
|
832
|
-
var {
|
|
833
|
-
DescendantsContextProvider: AutocompleteDescendantsContextProvider,
|
|
834
|
-
useDescendantsContext: useAutocompleteDescendantsContext,
|
|
835
|
-
useDescendants: useAutocompleteDescendants,
|
|
836
|
-
useDescendant: useAutocompleteDescendant
|
|
837
|
-
} = createDescendant();
|
|
838
|
-
var [AutocompleteProvider, useAutocompleteContext] = createContext({
|
|
839
|
-
name: "AutocompleteContext",
|
|
840
|
-
errorMessage: `useAutocompleteContext returned is 'undefined'. Seems you forgot to wrap the components in "<Autocomplete />" or "<MultiAutocomplete />"`
|
|
841
|
-
});
|
|
842
|
-
var useAutocomplete = (props) => {
|
|
843
|
-
const {
|
|
844
|
-
value: valueProp,
|
|
845
|
-
defaultValue,
|
|
846
|
-
onChange: onChangeProp,
|
|
847
|
-
onCreate: onCreateProp,
|
|
848
|
-
onSearch: onSearchProp,
|
|
849
|
-
closeOnSelect = true,
|
|
850
|
-
omitSelectedValues = false,
|
|
851
|
-
maxSelectValues,
|
|
852
|
-
allowCreate = false,
|
|
853
|
-
allowFree = false,
|
|
854
|
-
insertPositionItem = "first",
|
|
855
|
-
emptyMessage = "No results found",
|
|
856
|
-
format = defaultFormat,
|
|
857
|
-
optionProps,
|
|
858
|
-
placeholder,
|
|
859
|
-
onKeyDown: onKeyDownProp,
|
|
860
|
-
isOpen: isOpenProp,
|
|
861
|
-
defaultIsOpen,
|
|
862
|
-
onOpen: onOpenProp,
|
|
863
|
-
onClose: onCloseProp,
|
|
864
|
-
closeOnBlur = true,
|
|
865
|
-
closeOnEsc = true,
|
|
866
|
-
openDelay,
|
|
867
|
-
closeDelay,
|
|
868
|
-
isLazy,
|
|
869
|
-
lazyBehavior,
|
|
870
|
-
animation,
|
|
871
|
-
duration = 0.2,
|
|
872
|
-
offset,
|
|
873
|
-
gutter,
|
|
874
|
-
preventOverflow,
|
|
875
|
-
flip,
|
|
876
|
-
matchWidth = true,
|
|
877
|
-
boundary,
|
|
878
|
-
eventListeners,
|
|
879
|
-
strategy,
|
|
880
|
-
placement = "bottom-start",
|
|
881
|
-
modifiers,
|
|
882
|
-
items,
|
|
883
|
-
children,
|
|
884
|
-
...rest
|
|
885
|
-
} = useFormControlProps(props);
|
|
886
|
-
const {
|
|
887
|
-
"aria-readonly": _ariaReadonly,
|
|
888
|
-
onFocus: onFocusProp,
|
|
889
|
-
...formControlProps
|
|
890
|
-
} = pickObject(rest, formControlProperties);
|
|
891
|
-
const [containerProps, inputProps] = splitObject(rest, layoutStyleProperties);
|
|
892
|
-
const { id } = rest;
|
|
893
|
-
const descendants = useAutocompleteDescendants();
|
|
894
|
-
const containerRef = useRef2(null);
|
|
895
|
-
const listRef = useRef2(null);
|
|
896
|
-
const inputRef = useRef2(null);
|
|
897
|
-
const timeoutIds = useRef2(/* @__PURE__ */ new Set([]));
|
|
898
|
-
const isComposition = useRef2(false);
|
|
899
|
-
const prevValue = useRef2(void 0);
|
|
900
|
-
const [resolvedItems, setResolvedItems] = useState(items ? JSON.parse(JSON.stringify(items)) : void 0);
|
|
901
|
-
const [value, setValue] = useControllableState({
|
|
902
|
-
value: valueProp,
|
|
903
|
-
defaultValue,
|
|
904
|
-
onChange: onChangeProp
|
|
905
|
-
});
|
|
906
|
-
const [label, setLabel] = useState(void 0);
|
|
907
|
-
const [inputValue, setInputValue] = useState("");
|
|
908
|
-
const [focusedIndex, setFocusedIndex] = useState(-1);
|
|
909
|
-
const [isAllSelected, setIsAllSelected] = useState(false);
|
|
910
|
-
const [isHit, setIsHit] = useState(true);
|
|
911
|
-
const {
|
|
912
|
-
isOpen,
|
|
913
|
-
onOpen: onInternalOpen,
|
|
914
|
-
onClose
|
|
915
|
-
} = useDisclosure({
|
|
916
|
-
isOpen: isOpenProp,
|
|
917
|
-
defaultIsOpen,
|
|
918
|
-
onOpen: onOpenProp,
|
|
919
|
-
onClose: onCloseProp
|
|
920
|
-
});
|
|
921
|
-
const isFocused = focusedIndex > -1;
|
|
922
|
-
const isCreate = focusedIndex === -2 && allowCreate;
|
|
923
|
-
const isMulti = isArray(value);
|
|
924
|
-
const isEmptyValue = !isMulti ? !value : !value.length;
|
|
925
|
-
const [firstInsertPositionItem, secondInsertPositionItem] = useMemo2(() => {
|
|
926
|
-
if (isArray(insertPositionItem)) {
|
|
927
|
-
return insertPositionItem;
|
|
928
|
-
} else {
|
|
929
|
-
return [insertPositionItem, "first"];
|
|
930
|
-
}
|
|
931
|
-
}, [insertPositionItem]);
|
|
932
|
-
if (allowCreate && !isUndefined(children)) {
|
|
933
|
-
console.warn(
|
|
934
|
-
`${!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.`
|
|
935
|
-
);
|
|
936
|
-
}
|
|
937
|
-
const selectedValues = descendants.enabledValues(
|
|
938
|
-
({ node }) => {
|
|
939
|
-
var _a;
|
|
940
|
-
return isMulti && value.includes((_a = node.dataset.value) != null ? _a : "");
|
|
941
|
-
}
|
|
942
|
-
);
|
|
943
|
-
const selectedIndexes = selectedValues.map(({ index }) => index);
|
|
944
|
-
const enabledValues = descendants.enabledValues(
|
|
945
|
-
({ node, index }) => "target" in node.dataset && !selectedIndexes.includes(index)
|
|
946
|
-
);
|
|
947
|
-
const validChildren = getValidChildren2(children);
|
|
948
|
-
const computedChildren = useMemo2(
|
|
949
|
-
() => resolvedItems == null ? void 0 : resolvedItems.map((item, i) => {
|
|
950
|
-
if ("value" in item) {
|
|
951
|
-
const { label: label2, value: value2, ...props2 } = item;
|
|
952
|
-
return /* @__PURE__ */ jsx8(AutocompleteOption, { value: value2, ...props2, children: label2 }, i);
|
|
953
|
-
} else if ("items" in item) {
|
|
954
|
-
const { label: label2, items: items2 = [], ...props2 } = item;
|
|
955
|
-
return /* @__PURE__ */ jsx8(
|
|
956
|
-
AutocompleteOptionGroup,
|
|
957
|
-
{
|
|
958
|
-
label: label2,
|
|
959
|
-
...props2,
|
|
960
|
-
children: items2.map(({ label: label3, value: value2, ...props3 }, i2) => /* @__PURE__ */ jsx8(AutocompleteOption, { value: value2, ...props3, children: label3 }, i2))
|
|
961
|
-
},
|
|
962
|
-
i
|
|
963
|
-
);
|
|
964
|
-
}
|
|
965
|
-
}),
|
|
966
|
-
[resolvedItems]
|
|
967
|
-
);
|
|
968
|
-
const isEmpty = !validChildren.length && !(computedChildren == null ? void 0 : computedChildren.length);
|
|
969
|
-
const onOpen = useCallback(() => {
|
|
970
|
-
if (formControlProps.disabled || formControlProps.readOnly) return;
|
|
971
|
-
if (!allowCreate && (isEmpty || isAllSelected)) return;
|
|
972
|
-
onInternalOpen();
|
|
973
|
-
if (inputRef.current) inputRef.current.focus();
|
|
974
|
-
}, [allowCreate, formControlProps, isAllSelected, isEmpty, onInternalOpen]);
|
|
975
|
-
const onFocusFirst = useCallback(() => {
|
|
976
|
-
const id2 = setTimeout(() => {
|
|
977
|
-
if (isEmpty || isAllSelected) return;
|
|
978
|
-
const first = descendants.enabledFirstValue(
|
|
979
|
-
({ node }) => "target" in node.dataset
|
|
980
|
-
);
|
|
981
|
-
if (!first) return;
|
|
982
|
-
if (!isMulti || !omitSelectedValues) {
|
|
983
|
-
setFocusedIndex(first.index);
|
|
984
|
-
} else {
|
|
985
|
-
if (selectedIndexes.includes(first.index)) {
|
|
986
|
-
const enabledFirst = enabledValues[0];
|
|
987
|
-
setFocusedIndex(enabledFirst.index);
|
|
988
|
-
} else {
|
|
989
|
-
setFocusedIndex(first.index);
|
|
990
|
-
}
|
|
991
|
-
}
|
|
992
|
-
});
|
|
993
|
-
timeoutIds.current.add(id2);
|
|
994
|
-
}, [
|
|
995
|
-
descendants,
|
|
996
|
-
enabledValues,
|
|
997
|
-
isAllSelected,
|
|
998
|
-
isEmpty,
|
|
999
|
-
isMulti,
|
|
1000
|
-
omitSelectedValues,
|
|
1001
|
-
selectedIndexes
|
|
1002
|
-
]);
|
|
1003
|
-
const onFocusLast = useCallback(() => {
|
|
1004
|
-
const id2 = setTimeout(() => {
|
|
1005
|
-
if (isEmpty || isAllSelected) return;
|
|
1006
|
-
const last = descendants.enabledLastValue(
|
|
1007
|
-
({ node }) => "target" in node.dataset
|
|
1008
|
-
);
|
|
1009
|
-
if (!last) return;
|
|
1010
|
-
if (!isMulti || !omitSelectedValues) {
|
|
1011
|
-
setFocusedIndex(last.index);
|
|
1012
|
-
} else {
|
|
1013
|
-
if (selectedIndexes.includes(last.index)) {
|
|
1014
|
-
const enabledLast = enabledValues.reverse()[0];
|
|
1015
|
-
setFocusedIndex(enabledLast.index);
|
|
1016
|
-
} else {
|
|
1017
|
-
setFocusedIndex(last.index);
|
|
1018
|
-
}
|
|
1019
|
-
}
|
|
1020
|
-
});
|
|
1021
|
-
timeoutIds.current.add(id2);
|
|
1022
|
-
}, [
|
|
1023
|
-
descendants,
|
|
1024
|
-
enabledValues,
|
|
1025
|
-
isAllSelected,
|
|
1026
|
-
isEmpty,
|
|
1027
|
-
isMulti,
|
|
1028
|
-
omitSelectedValues,
|
|
1029
|
-
selectedIndexes
|
|
1030
|
-
]);
|
|
1031
|
-
const onFocusSelected = useCallback(() => {
|
|
1032
|
-
const id2 = setTimeout(() => {
|
|
1033
|
-
const values = descendants.enabledValues();
|
|
1034
|
-
const selected = values.find(
|
|
1035
|
-
({ node }) => {
|
|
1036
|
-
var _a;
|
|
1037
|
-
return !isMulti ? node.dataset.value === value : value.includes((_a = node.dataset.value) != null ? _a : "");
|
|
1038
|
-
}
|
|
1039
|
-
);
|
|
1040
|
-
if (selected) setFocusedIndex(selected.index);
|
|
1041
|
-
});
|
|
1042
|
-
timeoutIds.current.add(id2);
|
|
1043
|
-
}, [descendants, isMulti, value]);
|
|
1044
|
-
const onFocusNext = useCallback(
|
|
1045
|
-
(index = focusedIndex) => {
|
|
1046
|
-
const id2 = setTimeout(() => {
|
|
1047
|
-
var _a;
|
|
1048
|
-
const next = descendants.enabledNextValue(
|
|
1049
|
-
index,
|
|
1050
|
-
({ node }) => "target" in node.dataset
|
|
1051
|
-
);
|
|
1052
|
-
if (!next) return;
|
|
1053
|
-
if (!isMulti || !omitSelectedValues) {
|
|
1054
|
-
setFocusedIndex(next.index);
|
|
1055
|
-
} else {
|
|
1056
|
-
if (selectedIndexes.includes(next.index)) {
|
|
1057
|
-
const enabledNext = (_a = enabledValues.find(({ index: index2 }) => next.index < index2)) != null ? _a : enabledValues[0];
|
|
1058
|
-
setFocusedIndex(enabledNext.index);
|
|
1059
|
-
} else {
|
|
1060
|
-
setFocusedIndex(next.index);
|
|
1061
|
-
}
|
|
1062
|
-
}
|
|
1063
|
-
});
|
|
1064
|
-
timeoutIds.current.add(id2);
|
|
1065
|
-
},
|
|
1066
|
-
[
|
|
1067
|
-
descendants,
|
|
1068
|
-
enabledValues,
|
|
1069
|
-
focusedIndex,
|
|
1070
|
-
isMulti,
|
|
1071
|
-
omitSelectedValues,
|
|
1072
|
-
selectedIndexes
|
|
1073
|
-
]
|
|
1074
|
-
);
|
|
1075
|
-
const onFocusPrev = useCallback(
|
|
1076
|
-
(index = focusedIndex) => {
|
|
1077
|
-
const id2 = setTimeout(() => {
|
|
1078
|
-
var _a;
|
|
1079
|
-
const prev = descendants.enabledPrevValue(
|
|
1080
|
-
index,
|
|
1081
|
-
({ node }) => "target" in node.dataset
|
|
1082
|
-
);
|
|
1083
|
-
if (!prev) return;
|
|
1084
|
-
if (!isMulti || !omitSelectedValues) {
|
|
1085
|
-
setFocusedIndex(prev.index);
|
|
1086
|
-
} else {
|
|
1087
|
-
if (selectedIndexes.includes(prev.index)) {
|
|
1088
|
-
const enabledPrev = (_a = enabledValues.reverse().find(({ index: index2 }) => index2 < prev.index)) != null ? _a : enabledValues[0];
|
|
1089
|
-
setFocusedIndex(enabledPrev.index);
|
|
1090
|
-
} else {
|
|
1091
|
-
setFocusedIndex(prev.index);
|
|
1092
|
-
}
|
|
1093
|
-
}
|
|
1094
|
-
});
|
|
1095
|
-
timeoutIds.current.add(id2);
|
|
1096
|
-
},
|
|
1097
|
-
[
|
|
1098
|
-
descendants,
|
|
1099
|
-
enabledValues,
|
|
1100
|
-
focusedIndex,
|
|
1101
|
-
isMulti,
|
|
1102
|
-
omitSelectedValues,
|
|
1103
|
-
selectedIndexes
|
|
1104
|
-
]
|
|
1105
|
-
);
|
|
1106
|
-
const onFocusFirstOrSelected = isEmptyValue || omitSelectedValues ? onFocusFirst : onFocusSelected;
|
|
1107
|
-
const onFocusLastOrSelected = isEmptyValue || omitSelectedValues ? onFocusLast : onFocusSelected;
|
|
1108
|
-
const pickOptions = useCallback(
|
|
1109
|
-
(value2) => {
|
|
1110
|
-
const values = descendants.values();
|
|
1111
|
-
let isHit2 = false;
|
|
1112
|
-
let isFocused2 = false;
|
|
1113
|
-
values.forEach(({ node, index }) => {
|
|
1114
|
-
var _a;
|
|
1115
|
-
if (format((_a = node.textContent) != null ? _a : "").includes(value2)) {
|
|
1116
|
-
isHit2 = true;
|
|
1117
|
-
const isDisabled = "disabled" in node.dataset;
|
|
1118
|
-
node.dataset.target = "";
|
|
1119
|
-
if (!isFocused2 && !isDisabled) {
|
|
1120
|
-
isFocused2 = true;
|
|
1121
|
-
setFocusedIndex(index);
|
|
1122
|
-
}
|
|
1123
|
-
} else {
|
|
1124
|
-
delete node.dataset.target;
|
|
1125
|
-
}
|
|
1126
|
-
});
|
|
1127
|
-
setIsHit(isHit2);
|
|
1128
|
-
},
|
|
1129
|
-
[descendants, format]
|
|
1130
|
-
);
|
|
1131
|
-
const rebirthOptions = useCallback(
|
|
1132
|
-
(runFocus = true) => {
|
|
1133
|
-
const values = descendants.values();
|
|
1134
|
-
values.forEach(({ node }) => {
|
|
1135
|
-
node.dataset.target = "";
|
|
1136
|
-
});
|
|
1137
|
-
if (runFocus) onFocusFirst();
|
|
1138
|
-
setIsHit(true);
|
|
1139
|
-
},
|
|
1140
|
-
[descendants, onFocusFirst]
|
|
1141
|
-
);
|
|
1142
|
-
const getSelectedValues = useCallback(
|
|
1143
|
-
(newValues) => {
|
|
1144
|
-
const enabledValues2 = descendants.enabledValues();
|
|
1145
|
-
const resolvedValues = isArray(newValues) ? newValues : [newValues];
|
|
1146
|
-
const selectedValues2 = resolvedValues.map((value2) => {
|
|
1147
|
-
var _a, _b;
|
|
1148
|
-
const { node } = (_a = enabledValues2.find(({ node: node2 }) => node2.dataset.value === value2)) != null ? _a : {};
|
|
1149
|
-
if (node) {
|
|
1150
|
-
const el = Array.from(node.children).find(
|
|
1151
|
-
(child) => child.getAttribute("data-label") !== null
|
|
1152
|
-
);
|
|
1153
|
-
return (_b = el == null ? void 0 : el.textContent) != null ? _b : void 0;
|
|
1154
|
-
} else {
|
|
1155
|
-
return allowFree ? value2 : void 0;
|
|
1156
|
-
}
|
|
1157
|
-
}).filter(Boolean);
|
|
1158
|
-
return selectedValues2;
|
|
1159
|
-
},
|
|
1160
|
-
[allowFree, descendants]
|
|
1161
|
-
);
|
|
1162
|
-
const onChangeLabel = useCallback(
|
|
1163
|
-
(newValue, { forceUpdate, runOmit = true } = {}) => {
|
|
1164
|
-
const selectedValues2 = getSelectedValues(newValue);
|
|
1165
|
-
if (!forceUpdate && !selectedValues2.length) return;
|
|
1166
|
-
setLabel((prev) => {
|
|
1167
|
-
if (!isMulti) {
|
|
1168
|
-
return selectedValues2[0];
|
|
1169
|
-
} else {
|
|
1170
|
-
selectedValues2.forEach((selectedValue) => {
|
|
1171
|
-
const isSelected = isArray(prev) && prev.includes(selectedValue != null ? selectedValue : "");
|
|
1172
|
-
if (!isSelected) {
|
|
1173
|
-
prev = [...isArray(prev) ? prev : [], selectedValue];
|
|
1174
|
-
} else if (runOmit) {
|
|
1175
|
-
prev = isArray(prev) ? prev.filter((value2) => value2 !== selectedValue) : void 0;
|
|
1176
|
-
}
|
|
1177
|
-
});
|
|
1178
|
-
return prev;
|
|
1179
|
-
}
|
|
1180
|
-
});
|
|
1181
|
-
},
|
|
1182
|
-
[getSelectedValues, isMulti]
|
|
1183
|
-
);
|
|
1184
|
-
const onChange = useCallback(
|
|
1185
|
-
(newValue, { forceUpdate, runRebirth = true } = {}) => {
|
|
1186
|
-
setValue((prev) => {
|
|
1187
|
-
let next;
|
|
1188
|
-
if (!isArray(prev)) {
|
|
1189
|
-
next = newValue;
|
|
1190
|
-
} else {
|
|
1191
|
-
const isSelected = prev.includes(newValue);
|
|
1192
|
-
if (!isSelected) {
|
|
1193
|
-
next = [...prev, newValue];
|
|
1194
|
-
} else {
|
|
1195
|
-
next = prev.filter((value2) => value2 !== newValue);
|
|
1196
|
-
}
|
|
1197
|
-
}
|
|
1198
|
-
prevValue.current = next;
|
|
1199
|
-
return next;
|
|
1200
|
-
});
|
|
1201
|
-
const isHit2 = descendants.values().filter(
|
|
1202
|
-
({ node }) => {
|
|
1203
|
-
var _a;
|
|
1204
|
-
return format((_a = node.textContent) != null ? _a : "").includes(newValue);
|
|
1205
|
-
}
|
|
1206
|
-
).length > 0;
|
|
1207
|
-
onChangeLabel(newValue, { forceUpdate });
|
|
1208
|
-
if (allowFree || isHit2) setInputValue("");
|
|
1209
|
-
if (isMulti && runRebirth) rebirthOptions(false);
|
|
1210
|
-
},
|
|
1211
|
-
[
|
|
1212
|
-
allowFree,
|
|
1213
|
-
isMulti,
|
|
1214
|
-
onChangeLabel,
|
|
1215
|
-
rebirthOptions,
|
|
1216
|
-
setValue,
|
|
1217
|
-
descendants,
|
|
1218
|
-
format
|
|
1219
|
-
]
|
|
1220
|
-
);
|
|
1221
|
-
const onSelect = useCallback(() => {
|
|
1222
|
-
var _a, _b;
|
|
1223
|
-
let enabledValue = descendants.value(focusedIndex);
|
|
1224
|
-
if ("disabled" in ((_a = enabledValue == null ? void 0 : enabledValue.node.dataset) != null ? _a : {}))
|
|
1225
|
-
enabledValue = void 0;
|
|
1226
|
-
if (!enabledValue) return;
|
|
1227
|
-
const value2 = (_b = enabledValue.node.dataset.value) != null ? _b : "";
|
|
1228
|
-
onChange(value2);
|
|
1229
|
-
if (closeOnSelect) onClose();
|
|
1230
|
-
if (omitSelectedValues) onFocusNext();
|
|
1231
|
-
}, [
|
|
1232
|
-
closeOnSelect,
|
|
1233
|
-
descendants,
|
|
1234
|
-
focusedIndex,
|
|
1235
|
-
omitSelectedValues,
|
|
1236
|
-
onChange,
|
|
1237
|
-
onClose,
|
|
1238
|
-
onFocusNext
|
|
1239
|
-
]);
|
|
1240
|
-
const onSearch = useCallback(
|
|
1241
|
-
(ev) => {
|
|
1242
|
-
if (!isOpen) onOpen();
|
|
1243
|
-
onSearchProp == null ? void 0 : onSearchProp(ev);
|
|
1244
|
-
const value2 = ev.target.value;
|
|
1245
|
-
const computedValue = format(value2);
|
|
1246
|
-
if (computedValue) {
|
|
1247
|
-
pickOptions(computedValue);
|
|
1248
|
-
} else {
|
|
1249
|
-
rebirthOptions();
|
|
1250
|
-
}
|
|
1251
|
-
setInputValue(value2);
|
|
1252
|
-
},
|
|
1253
|
-
[isOpen, onOpen, format, onSearchProp, pickOptions, rebirthOptions]
|
|
1254
|
-
);
|
|
1255
|
-
const onCompositionStart = useCallback(() => {
|
|
1256
|
-
isComposition.current = true;
|
|
1257
|
-
}, []);
|
|
1258
|
-
const onCompositionEnd = useCallback(() => {
|
|
1259
|
-
isComposition.current = false;
|
|
1260
|
-
}, []);
|
|
1261
|
-
const onCreate = useCallback(() => {
|
|
1262
|
-
var _a, _b;
|
|
1263
|
-
if (!listRef.current) return;
|
|
1264
|
-
const newItem = { label: inputValue, value: inputValue };
|
|
1265
|
-
let newItems = [];
|
|
1266
|
-
if (resolvedItems) newItems = [...resolvedItems];
|
|
1267
|
-
if (firstInsertPositionItem === "first") {
|
|
1268
|
-
newItems = [newItem, ...newItems];
|
|
1269
|
-
} else if (firstInsertPositionItem === "last") {
|
|
1270
|
-
newItems = [...newItems, newItem];
|
|
1271
|
-
} else {
|
|
1272
|
-
const i = newItems.findIndex(
|
|
1273
|
-
({ label: label2 }) => label2 === firstInsertPositionItem
|
|
1274
|
-
);
|
|
1275
|
-
const targetItem = newItems[i];
|
|
1276
|
-
if (i !== -1 && "items" in targetItem) {
|
|
1277
|
-
if (secondInsertPositionItem === "first") {
|
|
1278
|
-
targetItem.items = [newItem, ...(_a = targetItem.items) != null ? _a : []];
|
|
1279
|
-
} else {
|
|
1280
|
-
targetItem.items = [...(_b = targetItem.items) != null ? _b : [], newItem];
|
|
1281
|
-
}
|
|
1282
|
-
newItems[i] = targetItem;
|
|
1283
|
-
} else {
|
|
1284
|
-
console.warn(
|
|
1285
|
-
`${!isMulti ? "Autocomplete" : "MultiAutocomplete"}: '${firstInsertPositionItem}' specified in insertPositionItem does not exist in the option group.`
|
|
1286
|
-
);
|
|
1287
|
-
}
|
|
1288
|
-
}
|
|
1289
|
-
setResolvedItems(newItems);
|
|
1290
|
-
onChange(inputValue);
|
|
1291
|
-
rebirthOptions(false);
|
|
1292
|
-
const index = flattenItems(newItems).findIndex(
|
|
1293
|
-
({ value: value2 }) => value2 === inputValue
|
|
1294
|
-
);
|
|
1295
|
-
setFocusedIndex(index);
|
|
1296
|
-
onCreateProp == null ? void 0 : onCreateProp(newItem, newItems);
|
|
1297
|
-
}, [
|
|
1298
|
-
inputValue,
|
|
1299
|
-
resolvedItems,
|
|
1300
|
-
firstInsertPositionItem,
|
|
1301
|
-
onChange,
|
|
1302
|
-
rebirthOptions,
|
|
1303
|
-
onCreateProp,
|
|
1304
|
-
secondInsertPositionItem,
|
|
1305
|
-
isMulti
|
|
1306
|
-
]);
|
|
1307
|
-
const onClick = useCallback(() => {
|
|
1308
|
-
if (isOpen) {
|
|
1309
|
-
if (inputRef.current) inputRef.current.focus();
|
|
1310
|
-
} else {
|
|
1311
|
-
onOpen();
|
|
1312
|
-
onFocusFirstOrSelected();
|
|
1313
|
-
}
|
|
1314
|
-
}, [isOpen, onFocusFirstOrSelected, onOpen]);
|
|
1315
|
-
const onFocus = useCallback(() => {
|
|
1316
|
-
if (isOpen) return;
|
|
1317
|
-
onOpen();
|
|
1318
|
-
onFocusFirstOrSelected();
|
|
1319
|
-
}, [isOpen, onFocusFirstOrSelected, onOpen]);
|
|
1320
|
-
const onBlur = useCallback(
|
|
1321
|
-
(ev) => {
|
|
1322
|
-
const relatedTarget = getEventRelatedTarget(ev);
|
|
1323
|
-
if (isContains(containerRef.current, relatedTarget)) return;
|
|
1324
|
-
if (!closeOnBlur && isHit) return;
|
|
1325
|
-
if (allowFree && !!inputValue) onChange(inputValue, { runRebirth: false });
|
|
1326
|
-
setInputValue("");
|
|
1327
|
-
if (isOpen) onClose();
|
|
1328
|
-
},
|
|
1329
|
-
[closeOnBlur, isHit, isOpen, inputValue, allowFree, onClose, onChange]
|
|
1330
|
-
);
|
|
1331
|
-
const onDelete = useCallback(() => {
|
|
1332
|
-
if (!isMulti) {
|
|
1333
|
-
onChange("", { forceUpdate: true });
|
|
1334
|
-
} else {
|
|
1335
|
-
onChange(value[value.length - 1]);
|
|
1336
|
-
}
|
|
1337
|
-
if (!isOpen) onFocus();
|
|
1338
|
-
}, [isMulti, isOpen, onChange, onFocus, value]);
|
|
1339
|
-
const onClear = useCallback(
|
|
1340
|
-
(ev) => {
|
|
1341
|
-
ev.stopPropagation();
|
|
1342
|
-
prevValue.current = [];
|
|
1343
|
-
setValue([]);
|
|
1344
|
-
setLabel(void 0);
|
|
1345
|
-
setInputValue("");
|
|
1346
|
-
rebirthOptions();
|
|
1347
|
-
if (isOpen && inputRef.current) inputRef.current.focus();
|
|
1348
|
-
},
|
|
1349
|
-
[isOpen, setLabel, setInputValue, setValue, rebirthOptions]
|
|
1350
|
-
);
|
|
1351
|
-
const onKeyDown = useCallback(
|
|
1352
|
-
(ev) => {
|
|
1353
|
-
if (ev.key === " ") ev.key = ev.code;
|
|
1354
|
-
if (formControlProps.disabled || formControlProps.readOnly) return;
|
|
1355
|
-
if (isComposition.current) return;
|
|
1356
|
-
const enabledDelete = label === inputValue || !inputValue.length;
|
|
1357
|
-
const actions = {
|
|
1358
|
-
ArrowDown: isFocused ? () => onFocusNext() : !isOpen ? funcAll(onOpen, onFocusFirstOrSelected) : void 0,
|
|
1359
|
-
ArrowUp: isFocused ? () => onFocusPrev() : !isOpen ? funcAll(onOpen, onFocusLastOrSelected) : void 0,
|
|
1360
|
-
Space: isCreate ? onCreate : isFocused ? onSelect : !isOpen ? funcAll(onOpen, onFocusFirstOrSelected) : void 0,
|
|
1361
|
-
Enter: isCreate ? onCreate : isFocused ? onSelect : !isOpen ? funcAll(onOpen, onFocusFirstOrSelected) : allowFree && isMulti ? () => {
|
|
1362
|
-
if (inputValue) onChange(inputValue);
|
|
1363
|
-
setFocusedIndex(0);
|
|
1364
|
-
} : void 0,
|
|
1365
|
-
Home: isOpen ? onFocusFirst : void 0,
|
|
1366
|
-
End: isOpen ? onFocusLast : void 0,
|
|
1367
|
-
Escape: closeOnEsc ? onClose : void 0,
|
|
1368
|
-
Backspace: !isEmptyValue && enabledDelete ? onDelete : void 0
|
|
1369
|
-
};
|
|
1370
|
-
const action = actions[ev.key];
|
|
1371
|
-
if (!action) return;
|
|
1372
|
-
ev.preventDefault();
|
|
1373
|
-
ev.stopPropagation();
|
|
1374
|
-
action(ev);
|
|
1375
|
-
},
|
|
1376
|
-
[
|
|
1377
|
-
allowFree,
|
|
1378
|
-
formControlProps,
|
|
1379
|
-
label,
|
|
1380
|
-
inputValue,
|
|
1381
|
-
onOpen,
|
|
1382
|
-
isFocused,
|
|
1383
|
-
isMulti,
|
|
1384
|
-
onFocusFirstOrSelected,
|
|
1385
|
-
onFocusNext,
|
|
1386
|
-
onFocusLastOrSelected,
|
|
1387
|
-
onFocusPrev,
|
|
1388
|
-
isCreate,
|
|
1389
|
-
onCreate,
|
|
1390
|
-
onSelect,
|
|
1391
|
-
isOpen,
|
|
1392
|
-
onFocusFirst,
|
|
1393
|
-
onFocusLast,
|
|
1394
|
-
closeOnEsc,
|
|
1395
|
-
onClose,
|
|
1396
|
-
isEmptyValue,
|
|
1397
|
-
onDelete,
|
|
1398
|
-
onChange
|
|
1399
|
-
]
|
|
1400
|
-
);
|
|
1401
|
-
useEffect(() => {
|
|
1402
|
-
if (!isMulti) return;
|
|
1403
|
-
if (!omitSelectedValues && isUndefined(maxSelectValues)) return;
|
|
1404
|
-
const isAll = value.length > 0 && value.length === descendants.count();
|
|
1405
|
-
const isMax = value.length === maxSelectValues;
|
|
1406
|
-
if (isAll || isMax) {
|
|
1407
|
-
onClose();
|
|
1408
|
-
setIsAllSelected(true);
|
|
1409
|
-
} else {
|
|
1410
|
-
setIsAllSelected(false);
|
|
1411
|
-
}
|
|
1412
|
-
}, [
|
|
1413
|
-
omitSelectedValues,
|
|
1414
|
-
value,
|
|
1415
|
-
descendants,
|
|
1416
|
-
isMulti,
|
|
1417
|
-
onClose,
|
|
1418
|
-
maxSelectValues
|
|
1419
|
-
]);
|
|
1420
|
-
useEffect(() => {
|
|
1421
|
-
var _a;
|
|
1422
|
-
if (isMulti) {
|
|
1423
|
-
if (JSON.stringify((_a = prevValue.current) != null ? _a : []) === JSON.stringify(value != null ? value : []))
|
|
1424
|
-
return;
|
|
1425
|
-
const label2 = getSelectedValues(value);
|
|
1426
|
-
setLabel(label2);
|
|
1427
|
-
} else {
|
|
1428
|
-
if (prevValue.current === value) return;
|
|
1429
|
-
onChangeLabel(value, { runOmit: false });
|
|
1430
|
-
}
|
|
1431
|
-
}, [isMulti, value, onChangeLabel, getSelectedValues]);
|
|
1432
|
-
useUpdateEffect(() => {
|
|
1433
|
-
if (isOpen || allowFree) return;
|
|
1434
|
-
setFocusedIndex(-1);
|
|
1435
|
-
setInputValue("");
|
|
1436
|
-
}, [isOpen]);
|
|
1437
|
-
useUpdateEffect(() => {
|
|
1438
|
-
if (!isHit) setFocusedIndex(-2);
|
|
1439
|
-
}, [isHit]);
|
|
1440
|
-
useUpdateEffect(() => {
|
|
1441
|
-
setResolvedItems(items ? JSON.parse(JSON.stringify(items)) : void 0);
|
|
1442
|
-
}, [items]);
|
|
1443
|
-
useUnmountEffect(() => {
|
|
1444
|
-
timeoutIds.current.forEach((id2) => clearTimeout(id2));
|
|
1445
|
-
timeoutIds.current.clear();
|
|
1446
|
-
});
|
|
1447
|
-
useOutsideClick({
|
|
1448
|
-
ref: containerRef,
|
|
1449
|
-
handler: onClose,
|
|
1450
|
-
enabled: isOpen && (closeOnBlur || !isHit)
|
|
1451
|
-
});
|
|
1452
|
-
const getPopoverProps = useCallback(
|
|
1453
|
-
(props2) => ({
|
|
1454
|
-
closeOnBlur,
|
|
1455
|
-
openDelay,
|
|
1456
|
-
closeDelay,
|
|
1457
|
-
isLazy,
|
|
1458
|
-
lazyBehavior,
|
|
1459
|
-
animation,
|
|
1460
|
-
duration,
|
|
1461
|
-
offset,
|
|
1462
|
-
gutter,
|
|
1463
|
-
preventOverflow,
|
|
1464
|
-
flip,
|
|
1465
|
-
matchWidth,
|
|
1466
|
-
boundary,
|
|
1467
|
-
eventListeners,
|
|
1468
|
-
strategy,
|
|
1469
|
-
placement,
|
|
1470
|
-
modifiers,
|
|
1471
|
-
...props2,
|
|
1472
|
-
trigger: "never",
|
|
1473
|
-
closeOnButton: false,
|
|
1474
|
-
isOpen,
|
|
1475
|
-
onOpen,
|
|
1476
|
-
onClose
|
|
1477
|
-
}),
|
|
1478
|
-
[
|
|
1479
|
-
closeOnBlur,
|
|
1480
|
-
openDelay,
|
|
1481
|
-
closeDelay,
|
|
1482
|
-
isLazy,
|
|
1483
|
-
lazyBehavior,
|
|
1484
|
-
animation,
|
|
1485
|
-
duration,
|
|
1486
|
-
offset,
|
|
1487
|
-
gutter,
|
|
1488
|
-
preventOverflow,
|
|
1489
|
-
flip,
|
|
1490
|
-
matchWidth,
|
|
1491
|
-
boundary,
|
|
1492
|
-
eventListeners,
|
|
1493
|
-
strategy,
|
|
1494
|
-
placement,
|
|
1495
|
-
modifiers,
|
|
1496
|
-
isOpen,
|
|
1497
|
-
onOpen,
|
|
1498
|
-
onClose
|
|
1499
|
-
]
|
|
1500
|
-
);
|
|
1501
|
-
const getContainerProps = useCallback(
|
|
1502
|
-
(props2 = {}, ref = null) => ({
|
|
1503
|
-
ref: mergeRefs(containerRef, ref),
|
|
1504
|
-
...containerProps,
|
|
1505
|
-
...props2,
|
|
1506
|
-
...formControlProps,
|
|
1507
|
-
onClick: handlerAll2(props2.onClick, rest.onClick, onClick),
|
|
1508
|
-
onBlur: handlerAll2(props2.onBlur, rest.onBlur, onBlur)
|
|
1509
|
-
}),
|
|
1510
|
-
[containerProps, formControlProps, onBlur, onClick, rest]
|
|
1511
|
-
);
|
|
1512
|
-
const getFieldProps = useCallback(
|
|
1513
|
-
(props2 = {}, ref = null) => ({
|
|
1514
|
-
ref,
|
|
1515
|
-
tabIndex: -1,
|
|
1516
|
-
...props2,
|
|
1517
|
-
...formControlProps,
|
|
1518
|
-
placeholder,
|
|
1519
|
-
"data-active": dataAttr(isOpen),
|
|
1520
|
-
"aria-expanded": dataAttr(isOpen),
|
|
1521
|
-
onFocus: handlerAll2(props2.onFocus, onFocusProp, onFocus),
|
|
1522
|
-
onKeyDown: handlerAll2(props2.onKeyDown, onKeyDownProp, onKeyDown)
|
|
1523
|
-
}),
|
|
1524
|
-
[
|
|
1525
|
-
formControlProps,
|
|
1526
|
-
placeholder,
|
|
1527
|
-
isOpen,
|
|
1528
|
-
onFocusProp,
|
|
1529
|
-
onFocus,
|
|
1530
|
-
onKeyDownProp,
|
|
1531
|
-
onKeyDown
|
|
1532
|
-
]
|
|
1533
|
-
);
|
|
1534
|
-
return {
|
|
1535
|
-
id,
|
|
1536
|
-
descendants,
|
|
1537
|
-
value,
|
|
1538
|
-
label,
|
|
1539
|
-
inputValue,
|
|
1540
|
-
isHit,
|
|
1541
|
-
isEmpty,
|
|
1542
|
-
computedChildren,
|
|
1543
|
-
focusedIndex,
|
|
1544
|
-
omitSelectedValues,
|
|
1545
|
-
closeOnSelect,
|
|
1546
|
-
allowCreate,
|
|
1547
|
-
allowFree,
|
|
1548
|
-
emptyMessage,
|
|
1549
|
-
isOpen,
|
|
1550
|
-
isAllSelected,
|
|
1551
|
-
listRef,
|
|
1552
|
-
inputRef,
|
|
1553
|
-
optionProps,
|
|
1554
|
-
formControlProps,
|
|
1555
|
-
setFocusedIndex,
|
|
1556
|
-
onChangeLabel,
|
|
1557
|
-
onChange,
|
|
1558
|
-
onSearch,
|
|
1559
|
-
onCreate,
|
|
1560
|
-
onClear,
|
|
1561
|
-
onCompositionStart,
|
|
1562
|
-
onCompositionEnd,
|
|
1563
|
-
pickOptions,
|
|
1564
|
-
rebirthOptions,
|
|
1565
|
-
onOpen,
|
|
1566
|
-
onClose,
|
|
1567
|
-
onFocusFirst,
|
|
1568
|
-
onFocusLast,
|
|
1569
|
-
onFocusSelected,
|
|
1570
|
-
onFocusNext,
|
|
1571
|
-
onFocusPrev,
|
|
1572
|
-
getPopoverProps,
|
|
1573
|
-
getContainerProps,
|
|
1574
|
-
getFieldProps,
|
|
1575
|
-
inputProps
|
|
1576
|
-
};
|
|
1577
|
-
};
|
|
1578
|
-
var useAutocompleteInput = () => {
|
|
1579
|
-
const {
|
|
1580
|
-
id,
|
|
1581
|
-
inputRef,
|
|
1582
|
-
onSearch,
|
|
1583
|
-
onCompositionStart,
|
|
1584
|
-
onCompositionEnd,
|
|
1585
|
-
isAllSelected,
|
|
1586
|
-
formControlProps,
|
|
1587
|
-
inputProps,
|
|
1588
|
-
isOpen,
|
|
1589
|
-
focusedIndex,
|
|
1590
|
-
listRef
|
|
1591
|
-
} = useAutocompleteContext();
|
|
1592
|
-
const { value } = useAutocompleteDescendantsContext();
|
|
1593
|
-
useUpdateEffect(() => {
|
|
1594
|
-
if (isAllSelected && inputRef.current) inputRef.current.blur();
|
|
1595
|
-
}, [isAllSelected]);
|
|
1596
|
-
const getInputProps = useCallback(
|
|
1597
|
-
(props = {}, ref = null) => {
|
|
1598
|
-
var _a, _b;
|
|
1599
|
-
return {
|
|
1600
|
-
ref: mergeRefs(inputRef, ref),
|
|
1601
|
-
...formControlProps,
|
|
1602
|
-
role: "combobox",
|
|
1603
|
-
"aria-haspopup": "listbox",
|
|
1604
|
-
"aria-autocomplete": "list",
|
|
1605
|
-
"aria-expanded": isOpen,
|
|
1606
|
-
"aria-activedescendant": (_a = value(focusedIndex)) == null ? void 0 : _a.node.id,
|
|
1607
|
-
"aria-controls": (_b = listRef.current) == null ? void 0 : _b.id,
|
|
1608
|
-
autoCapitalize: "none",
|
|
1609
|
-
autoComplete: "off",
|
|
1610
|
-
spellCheck: "false",
|
|
1611
|
-
...inputProps,
|
|
1612
|
-
...props,
|
|
1613
|
-
id,
|
|
1614
|
-
cursor: formControlProps.readOnly ? "default" : "text",
|
|
1615
|
-
pointerEvents: formControlProps.disabled || isAllSelected ? "none" : "auto",
|
|
1616
|
-
tabIndex: isAllSelected ? -1 : 0,
|
|
1617
|
-
onChange: handlerAll2(props.onChange, onSearch),
|
|
1618
|
-
onCompositionStart: handlerAll2(
|
|
1619
|
-
props.onCompositionStart,
|
|
1620
|
-
inputProps.onCompositionStart,
|
|
1621
|
-
onCompositionStart
|
|
1622
|
-
),
|
|
1623
|
-
onCompositionEnd: handlerAll2(
|
|
1624
|
-
props.onCompositionEnd,
|
|
1625
|
-
inputProps.onCompositionEnd,
|
|
1626
|
-
onCompositionEnd
|
|
1627
|
-
)
|
|
1628
|
-
};
|
|
1629
|
-
},
|
|
1630
|
-
[
|
|
1631
|
-
listRef,
|
|
1632
|
-
focusedIndex,
|
|
1633
|
-
isOpen,
|
|
1634
|
-
inputProps,
|
|
1635
|
-
inputRef,
|
|
1636
|
-
formControlProps,
|
|
1637
|
-
id,
|
|
1638
|
-
isAllSelected,
|
|
1639
|
-
value,
|
|
1640
|
-
onSearch,
|
|
1641
|
-
onCompositionStart,
|
|
1642
|
-
onCompositionEnd
|
|
1643
|
-
]
|
|
1644
|
-
);
|
|
1645
|
-
return {
|
|
1646
|
-
getInputProps
|
|
1647
|
-
};
|
|
1648
|
-
};
|
|
1649
|
-
var useAutocompleteList = () => {
|
|
1650
|
-
const { focusedIndex, isOpen, listRef, rebirthOptions } = useAutocompleteContext();
|
|
1651
|
-
const descendants = useAutocompleteDescendantsContext();
|
|
1652
|
-
const beforeFocusedIndex = useRef2(-1);
|
|
1653
|
-
const selectedValue = descendants.value(focusedIndex);
|
|
1654
|
-
const onAnimationComplete = useCallback(() => {
|
|
1655
|
-
if (!isOpen) rebirthOptions(false);
|
|
1656
|
-
}, [isOpen, rebirthOptions]);
|
|
1657
|
-
useEffect(() => {
|
|
1658
|
-
if (!listRef.current || !selectedValue) return;
|
|
1659
|
-
if (beforeFocusedIndex.current === selectedValue.index) return;
|
|
1660
|
-
const parent = listRef.current;
|
|
1661
|
-
const child = selectedValue.node;
|
|
1662
|
-
const parentHeight = parent.clientHeight;
|
|
1663
|
-
const viewTop = parent.scrollTop;
|
|
1664
|
-
const viewBottom = viewTop + parentHeight;
|
|
1665
|
-
const childHeight = child.clientHeight;
|
|
1666
|
-
const childTop = child.offsetTop;
|
|
1667
|
-
const childBottom = childTop + childHeight;
|
|
1668
|
-
const isInView = viewTop <= childTop && childBottom <= viewBottom;
|
|
1669
|
-
const isScrollBottom = beforeFocusedIndex.current < selectedValue.index;
|
|
1670
|
-
if (!isInView) {
|
|
1671
|
-
if (childBottom <= parentHeight) {
|
|
1672
|
-
listRef.current.scrollTo({ top: 0 });
|
|
1673
|
-
} else {
|
|
1674
|
-
if (!isScrollBottom) {
|
|
1675
|
-
listRef.current.scrollTo({ top: childTop + 1 });
|
|
1676
|
-
} else {
|
|
1677
|
-
listRef.current.scrollTo({ top: childBottom - parentHeight });
|
|
1678
|
-
}
|
|
1679
|
-
}
|
|
1680
|
-
}
|
|
1681
|
-
beforeFocusedIndex.current = selectedValue.index;
|
|
1682
|
-
}, [listRef, selectedValue]);
|
|
1683
|
-
useUpdateEffect(() => {
|
|
1684
|
-
if (!isOpen) beforeFocusedIndex.current = -1;
|
|
1685
|
-
}, [isOpen]);
|
|
1686
|
-
const getListProps = useCallback(
|
|
1687
|
-
(props = {}, ref = null) => ({
|
|
1688
|
-
as: "ul",
|
|
1689
|
-
ref: mergeRefs(listRef, ref),
|
|
1690
|
-
role: "listbox",
|
|
1691
|
-
tabIndex: -1,
|
|
1692
|
-
position: "relative",
|
|
1693
|
-
id: props.id || useId(),
|
|
1694
|
-
...props
|
|
1695
|
-
}),
|
|
1696
|
-
[listRef]
|
|
1697
|
-
);
|
|
1698
|
-
return {
|
|
1699
|
-
onAnimationComplete,
|
|
1700
|
-
getListProps
|
|
1701
|
-
};
|
|
1702
|
-
};
|
|
1703
|
-
var useAutocompleteOptionGroup = ({
|
|
1704
|
-
label,
|
|
1705
|
-
...rest
|
|
1706
|
-
}) => {
|
|
1707
|
-
const { value, omitSelectedValues } = useAutocompleteContext();
|
|
1708
|
-
const isMulti = isArray(value);
|
|
1709
|
-
const descendants = useAutocompleteDescendantsContext();
|
|
1710
|
-
const values = descendants.values();
|
|
1711
|
-
const selectedValues = isMulti && omitSelectedValues ? descendants.values(
|
|
1712
|
-
({ node }) => {
|
|
1713
|
-
var _a;
|
|
1714
|
-
return value.includes((_a = node.dataset.value) != null ? _a : "");
|
|
1715
|
-
}
|
|
1716
|
-
) : [];
|
|
1717
|
-
const selectedIndexes = selectedValues.map(({ index }) => index);
|
|
1718
|
-
const childValues = values.filter(
|
|
1719
|
-
({ node, index }) => {
|
|
1720
|
-
var _a;
|
|
1721
|
-
return ((_a = node.parentElement) == null ? void 0 : _a.dataset.label) === label && !selectedIndexes.includes(index) && "target" in node.dataset;
|
|
1722
|
-
}
|
|
1723
|
-
);
|
|
1724
|
-
const isEmpty = !childValues.length;
|
|
1725
|
-
const [containerProps, groupProps] = splitObject(rest, layoutStyleProperties);
|
|
1726
|
-
const getContainerProps = useCallback(
|
|
1727
|
-
(props = {}, ref = null) => {
|
|
1728
|
-
const style = {
|
|
1729
|
-
border: "0px",
|
|
1730
|
-
clip: "rect(0px, 0px, 0px, 0px)",
|
|
1731
|
-
height: "1px",
|
|
1732
|
-
width: "1px",
|
|
1733
|
-
margin: "-1px",
|
|
1734
|
-
padding: "0px",
|
|
1735
|
-
overflow: "hidden",
|
|
1736
|
-
whiteSpace: "nowrap",
|
|
1737
|
-
position: "absolute"
|
|
1738
|
-
};
|
|
1739
|
-
return {
|
|
1740
|
-
ref,
|
|
1741
|
-
...props,
|
|
1742
|
-
...containerProps,
|
|
1743
|
-
style: isEmpty ? style : void 0,
|
|
1744
|
-
"data-label": label,
|
|
1745
|
-
role: "autocomplete-group-container"
|
|
1746
|
-
};
|
|
1747
|
-
},
|
|
1748
|
-
[containerProps, isEmpty, label]
|
|
1749
|
-
);
|
|
1750
|
-
const getGroupProps = useCallback(
|
|
1751
|
-
(props = {}, ref = null) => ({
|
|
1752
|
-
ref,
|
|
1753
|
-
...props,
|
|
1754
|
-
...groupProps,
|
|
1755
|
-
"data-label": label,
|
|
1756
|
-
role: "autocomplete-group"
|
|
1757
|
-
}),
|
|
1758
|
-
[groupProps, label]
|
|
1759
|
-
);
|
|
1760
|
-
return {
|
|
1761
|
-
label,
|
|
1762
|
-
getContainerProps,
|
|
1763
|
-
getGroupProps
|
|
1764
|
-
};
|
|
1765
|
-
};
|
|
1766
|
-
var useAutocompleteOption = (props) => {
|
|
1767
|
-
var _a, _b;
|
|
1768
|
-
const {
|
|
1769
|
-
value,
|
|
1770
|
-
omitSelectedValues,
|
|
1771
|
-
onChange,
|
|
1772
|
-
onChangeLabel,
|
|
1773
|
-
focusedIndex,
|
|
1774
|
-
setFocusedIndex,
|
|
1775
|
-
onClose,
|
|
1776
|
-
closeOnSelect: generalCloseOnSelect,
|
|
1777
|
-
optionProps,
|
|
1778
|
-
inputRef,
|
|
1779
|
-
onFocusNext
|
|
1780
|
-
} = useAutocompleteContext();
|
|
1781
|
-
let {
|
|
1782
|
-
icon: customIcon,
|
|
1783
|
-
isDisabled,
|
|
1784
|
-
isFocusable,
|
|
1785
|
-
closeOnSelect: customCloseOnSelect,
|
|
1786
|
-
children,
|
|
1787
|
-
value: optionValue,
|
|
1788
|
-
...computedProps
|
|
1789
|
-
} = { ...optionProps, ...props };
|
|
1790
|
-
const trulyDisabled = !!isDisabled && !isFocusable;
|
|
1791
|
-
const itemRef = useRef2(null);
|
|
1792
|
-
const { index, register, descendants } = useAutocompleteDescendant({
|
|
1793
|
-
disabled: trulyDisabled
|
|
1794
|
-
});
|
|
1795
|
-
const values = descendants.values();
|
|
1796
|
-
const frontValues = values.slice(0, index);
|
|
1797
|
-
const isMulti = isArray(value);
|
|
1798
|
-
const isDuplicated = !isMulti ? frontValues.some(({ node }) => node.dataset.value === (optionValue != null ? optionValue : "")) : false;
|
|
1799
|
-
const isSelected = !isDuplicated && (!isMulti ? (optionValue != null ? optionValue : "") === value : value.includes(optionValue != null ? optionValue : ""));
|
|
1800
|
-
const isTarget = "target" in ((_b = (_a = itemRef.current) == null ? void 0 : _a.dataset) != null ? _b : {});
|
|
1801
|
-
const isFocused = index === focusedIndex;
|
|
1802
|
-
const onClick = useCallback(
|
|
1803
|
-
(ev) => {
|
|
1804
|
-
ev.stopPropagation();
|
|
1805
|
-
if (isDisabled) {
|
|
1806
|
-
if (inputRef.current) inputRef.current.focus();
|
|
1807
|
-
return;
|
|
1808
|
-
}
|
|
1809
|
-
if (!isTargetOption(ev.currentTarget)) {
|
|
1810
|
-
if (inputRef.current) inputRef.current.focus();
|
|
1811
|
-
return;
|
|
1812
|
-
}
|
|
1813
|
-
setFocusedIndex(index);
|
|
1814
|
-
onChange(optionValue != null ? optionValue : "");
|
|
1815
|
-
if (inputRef.current) inputRef.current.focus();
|
|
1816
|
-
if (customCloseOnSelect != null ? customCloseOnSelect : generalCloseOnSelect) onClose();
|
|
1817
|
-
if (omitSelectedValues) onFocusNext(index);
|
|
1818
|
-
},
|
|
1819
|
-
[
|
|
1820
|
-
onFocusNext,
|
|
1821
|
-
omitSelectedValues,
|
|
1822
|
-
isDisabled,
|
|
1823
|
-
optionValue,
|
|
1824
|
-
setFocusedIndex,
|
|
1825
|
-
index,
|
|
1826
|
-
onChange,
|
|
1827
|
-
customCloseOnSelect,
|
|
1828
|
-
generalCloseOnSelect,
|
|
1829
|
-
onClose,
|
|
1830
|
-
inputRef
|
|
1831
|
-
]
|
|
1832
|
-
);
|
|
1833
|
-
useUpdateEffect(() => {
|
|
1834
|
-
if (isSelected) onChangeLabel(optionValue != null ? optionValue : "", { runOmit: false });
|
|
1835
|
-
}, [optionValue]);
|
|
1836
|
-
const getOptionProps = useCallback(
|
|
1837
|
-
(props2 = {}, ref = null) => {
|
|
1838
|
-
const style = {
|
|
1839
|
-
border: "0px",
|
|
1840
|
-
clip: "rect(0px, 0px, 0px, 0px)",
|
|
1841
|
-
height: "1px",
|
|
1842
|
-
width: "1px",
|
|
1843
|
-
margin: "-1px",
|
|
1844
|
-
padding: "0px",
|
|
1845
|
-
overflow: "hidden",
|
|
1846
|
-
whiteSpace: "nowrap",
|
|
1847
|
-
position: "absolute"
|
|
1848
|
-
};
|
|
1849
|
-
return {
|
|
1850
|
-
ref: mergeRefs(itemRef, ref, register),
|
|
1851
|
-
id: useId(),
|
|
1852
|
-
role: "option",
|
|
1853
|
-
...computedProps,
|
|
1854
|
-
...props2,
|
|
1855
|
-
tabIndex: -1,
|
|
1856
|
-
style: !isTarget || omitSelectedValues && isSelected ? style : void 0,
|
|
1857
|
-
"data-target": dataAttr(true),
|
|
1858
|
-
"data-value": optionValue != null ? optionValue : "",
|
|
1859
|
-
"data-focus": dataAttr(isFocused),
|
|
1860
|
-
"data-disabled": dataAttr(isDisabled),
|
|
1861
|
-
"aria-checked": isSelected,
|
|
1862
|
-
"aria-disabled": ariaAttr(isDisabled),
|
|
1863
|
-
onClick: handlerAll2(computedProps.onClick, props2.onClick, onClick)
|
|
1864
|
-
};
|
|
1865
|
-
},
|
|
1866
|
-
[
|
|
1867
|
-
optionValue,
|
|
1868
|
-
computedProps,
|
|
1869
|
-
isDisabled,
|
|
1870
|
-
isFocused,
|
|
1871
|
-
isSelected,
|
|
1872
|
-
isTarget,
|
|
1873
|
-
omitSelectedValues,
|
|
1874
|
-
onClick,
|
|
1875
|
-
register
|
|
1876
|
-
]
|
|
1877
|
-
);
|
|
1878
|
-
return {
|
|
1879
|
-
isSelected,
|
|
1880
|
-
isFocused,
|
|
1881
|
-
customIcon,
|
|
1882
|
-
children,
|
|
1883
|
-
getOptionProps
|
|
1884
|
-
};
|
|
1885
|
-
};
|
|
1886
|
-
var useAutocompleteCreate = () => {
|
|
1887
|
-
const { isHit, onCreate } = useAutocompleteContext();
|
|
1888
|
-
const getCreateProps = useCallback(
|
|
1889
|
-
(props = {}, ref = null) => {
|
|
1890
|
-
const style = {
|
|
1891
|
-
border: "0px",
|
|
1892
|
-
clip: "rect(0px, 0px, 0px, 0px)",
|
|
1893
|
-
height: "1px",
|
|
1894
|
-
width: "1px",
|
|
1895
|
-
margin: "-1px",
|
|
1896
|
-
padding: "0px",
|
|
1897
|
-
overflow: "hidden",
|
|
1898
|
-
whiteSpace: "nowrap",
|
|
1899
|
-
position: "absolute"
|
|
1900
|
-
};
|
|
1901
|
-
return {
|
|
1902
|
-
ref,
|
|
1903
|
-
...props,
|
|
1904
|
-
tabIndex: -1,
|
|
1905
|
-
style: isHit ? style : void 0,
|
|
1906
|
-
"data-focus": dataAttr(!isHit),
|
|
1907
|
-
onClick: handlerAll2(props.onClick, onCreate)
|
|
1908
|
-
};
|
|
1909
|
-
},
|
|
1910
|
-
[isHit, onCreate]
|
|
1911
|
-
);
|
|
1912
|
-
return { getCreateProps };
|
|
1913
|
-
};
|
|
1914
|
-
var useAutocompleteEmpty = () => {
|
|
1915
|
-
const { isHit, isEmpty } = useAutocompleteContext();
|
|
1916
|
-
const getEmptyProps = useCallback(
|
|
1917
|
-
(props = {}, ref = null) => {
|
|
1918
|
-
const style = {
|
|
1919
|
-
border: "0px",
|
|
1920
|
-
clip: "rect(0px, 0px, 0px, 0px)",
|
|
1921
|
-
height: "1px",
|
|
1922
|
-
width: "1px",
|
|
1923
|
-
margin: "-1px",
|
|
1924
|
-
padding: "0px",
|
|
1925
|
-
overflow: "hidden",
|
|
1926
|
-
whiteSpace: "nowrap",
|
|
1927
|
-
position: "absolute"
|
|
1928
|
-
};
|
|
1929
|
-
return {
|
|
1930
|
-
ref,
|
|
1931
|
-
...props,
|
|
1932
|
-
tabIndex: -1,
|
|
1933
|
-
style: isHit && !isEmpty ? style : void 0
|
|
1934
|
-
};
|
|
1935
|
-
},
|
|
1936
|
-
[isHit, isEmpty]
|
|
1937
|
-
);
|
|
1938
|
-
return { getEmptyProps };
|
|
1939
|
-
};
|
|
1940
|
-
|
|
1941
|
-
// src/autocomplete-list.tsx
|
|
1942
|
-
import { jsx as jsx9, jsxs as jsxs7 } from "react/jsx-runtime";
|
|
1943
|
-
var AutocompleteList = forwardRef8(
|
|
1944
|
-
({
|
|
1945
|
-
className,
|
|
1946
|
-
w,
|
|
1947
|
-
width,
|
|
1948
|
-
minW,
|
|
1949
|
-
minWidth,
|
|
1950
|
-
maxW,
|
|
1951
|
-
maxWidth,
|
|
1952
|
-
contentProps,
|
|
1953
|
-
header,
|
|
1954
|
-
footer,
|
|
1955
|
-
children,
|
|
1956
|
-
...rest
|
|
1957
|
-
}, ref) => {
|
|
1958
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i;
|
|
1959
|
-
const { styles } = useAutocompleteContext();
|
|
1960
|
-
const { onAnimationComplete, getListProps } = useAutocompleteList();
|
|
1961
|
-
width != null ? width : width = w;
|
|
1962
|
-
width != null ? width : width = (_c = (_a = styles.list) == null ? void 0 : _a.width) != null ? _c : (_b = styles.list) == null ? void 0 : _b.w;
|
|
1963
|
-
minWidth != null ? minWidth : minWidth = minW;
|
|
1964
|
-
minWidth != null ? minWidth : minWidth = (_f = (_d = styles.list) == null ? void 0 : _d.minWidth) != null ? _f : (_e = styles.list) == null ? void 0 : _e.minW;
|
|
1965
|
-
maxWidth != null ? maxWidth : maxWidth = maxW;
|
|
1966
|
-
maxWidth != null ? maxWidth : maxWidth = (_i = (_g = styles.list) == null ? void 0 : _g.maxWidth) != null ? _i : (_h = styles.list) == null ? void 0 : _h.maxW;
|
|
1967
|
-
return /* @__PURE__ */ jsxs7(
|
|
1968
|
-
PopoverContent,
|
|
1969
|
-
{
|
|
1970
|
-
as: "div",
|
|
1971
|
-
className: "ui-autocomplete__popover",
|
|
1972
|
-
width,
|
|
1973
|
-
minWidth,
|
|
1974
|
-
maxWidth,
|
|
1975
|
-
__css: { ...styles.content, width, minWidth, maxWidth },
|
|
1976
|
-
...contentProps,
|
|
1977
|
-
onAnimationComplete: handlerAll3(
|
|
1978
|
-
contentProps == null ? void 0 : contentProps.onAnimationComplete,
|
|
1979
|
-
onAnimationComplete
|
|
1980
|
-
),
|
|
1981
|
-
children: [
|
|
1982
|
-
header ? /* @__PURE__ */ jsx9(
|
|
1983
|
-
ui8.div,
|
|
1984
|
-
{
|
|
1985
|
-
className: "ui-autocomplete__header",
|
|
1986
|
-
__css: { ...styles.header },
|
|
1987
|
-
children: header
|
|
1988
|
-
}
|
|
1989
|
-
) : null,
|
|
1990
|
-
/* @__PURE__ */ jsx9(
|
|
1991
|
-
ui8.ul,
|
|
1992
|
-
{
|
|
1993
|
-
className: cx8("ui-autocomplete__list", className),
|
|
1994
|
-
__css: { ...styles.list },
|
|
1995
|
-
...getListProps(rest, ref),
|
|
1996
|
-
children
|
|
1997
|
-
}
|
|
1998
|
-
),
|
|
1999
|
-
footer ? /* @__PURE__ */ jsx9(
|
|
2000
|
-
ui8.div,
|
|
2001
|
-
{
|
|
2002
|
-
className: "ui-autocomplete__footer",
|
|
2003
|
-
__css: { ...styles.footer },
|
|
2004
|
-
children: footer
|
|
2005
|
-
}
|
|
2006
|
-
) : null
|
|
2007
|
-
]
|
|
2008
|
-
}
|
|
2009
|
-
);
|
|
2010
|
-
}
|
|
2011
|
-
);
|
|
2012
|
-
|
|
2013
|
-
export {
|
|
2014
|
-
AutocompleteList,
|
|
2015
|
-
Autocomplete,
|
|
2016
|
-
AutocompleteOptionGroup,
|
|
2017
|
-
AutocompleteOption,
|
|
2018
|
-
AutocompleteEmpty,
|
|
2019
|
-
MultiAutocomplete,
|
|
2020
|
-
AutocompleteDescendantsContextProvider,
|
|
2021
|
-
useAutocompleteDescendantsContext,
|
|
2022
|
-
useAutocompleteDescendants,
|
|
2023
|
-
useAutocompleteDescendant,
|
|
2024
|
-
AutocompleteProvider,
|
|
2025
|
-
useAutocompleteContext,
|
|
2026
|
-
useAutocomplete,
|
|
2027
|
-
useAutocompleteInput,
|
|
2028
|
-
useAutocompleteList,
|
|
2029
|
-
useAutocompleteOptionGroup,
|
|
2030
|
-
useAutocompleteOption,
|
|
2031
|
-
useAutocompleteCreate,
|
|
2032
|
-
useAutocompleteEmpty,
|
|
2033
|
-
AutocompleteIcon,
|
|
2034
|
-
AutocompleteClearIcon,
|
|
2035
|
-
AutocompleteItemIcon,
|
|
2036
|
-
AutocompleteCreate
|
|
2037
|
-
};
|
|
2038
|
-
//# sourceMappingURL=chunk-ZD25NCFE.mjs.map
|