@yamada-ui/autocomplete 0.4.13 → 0.5.0
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-create.d.mts +1 -1
- package/dist/autocomplete-create.d.ts +1 -1
- package/dist/autocomplete-create.mjs +1 -1
- package/dist/autocomplete-empty.d.mts +1 -1
- package/dist/autocomplete-empty.d.ts +1 -1
- package/dist/autocomplete-empty.mjs +1 -1
- package/dist/autocomplete-icon.d.mts +2 -2
- package/dist/autocomplete-icon.d.ts +2 -2
- package/dist/autocomplete-icon.mjs +1 -1
- package/dist/autocomplete-list.d.mts +1 -1
- package/dist/autocomplete-list.d.ts +1 -1
- package/dist/autocomplete-list.mjs +1 -1
- package/dist/autocomplete-option-group.d.mts +2 -3
- package/dist/autocomplete-option-group.d.ts +2 -3
- package/dist/autocomplete-option-group.mjs +1 -1
- package/dist/autocomplete-option.d.mts +1 -2
- package/dist/autocomplete-option.d.ts +1 -2
- package/dist/autocomplete-option.mjs +1 -1
- package/dist/autocomplete.d.mts +5 -6
- package/dist/autocomplete.d.ts +5 -6
- package/dist/autocomplete.js +57 -60
- package/dist/autocomplete.mjs +1 -1
- package/dist/{chunk-EFOFI4S7.mjs → chunk-JKY5MMNC.mjs} +61 -64
- package/dist/index.d.mts +1 -2
- package/dist/index.d.ts +1 -2
- package/dist/index.js +61 -64
- package/dist/index.mjs +1 -1
- package/dist/multi-autocomplete.d.mts +5 -6
- package/dist/multi-autocomplete.d.ts +5 -6
- package/dist/multi-autocomplete.js +57 -60
- package/dist/multi-autocomplete.mjs +1 -1
- package/dist/{use-autocomplete-2422c1c8.d.ts → use-autocomplete-3e77a4da.d.ts} +31 -42
- package/dist/use-autocomplete.d.mts +1 -2
- package/dist/use-autocomplete.d.ts +1 -2
- package/dist/use-autocomplete.js +53 -56
- package/dist/use-autocomplete.mjs +1 -1
- package/package.json +3 -3
|
@@ -12,7 +12,7 @@ type AutocompleteCreateOptions = {
|
|
|
12
12
|
*/
|
|
13
13
|
children?: string | ((inputValue: string) => string);
|
|
14
14
|
};
|
|
15
|
-
type AutocompleteCreateProps = Omit<HTMLUIProps<
|
|
15
|
+
type AutocompleteCreateProps = Omit<HTMLUIProps<"li">, "children"> & AutocompleteCreateOptions;
|
|
16
16
|
declare const AutocompleteCreate: _yamada_ui_core.Component<"li", AutocompleteCreateProps>;
|
|
17
17
|
|
|
18
18
|
export { AutocompleteCreate, AutocompleteCreateProps };
|
|
@@ -12,7 +12,7 @@ type AutocompleteCreateOptions = {
|
|
|
12
12
|
*/
|
|
13
13
|
children?: string | ((inputValue: string) => string);
|
|
14
14
|
};
|
|
15
|
-
type AutocompleteCreateProps = Omit<HTMLUIProps<
|
|
15
|
+
type AutocompleteCreateProps = Omit<HTMLUIProps<"li">, "children"> & AutocompleteCreateOptions;
|
|
16
16
|
declare const AutocompleteCreate: _yamada_ui_core.Component<"li", AutocompleteCreateProps>;
|
|
17
17
|
|
|
18
18
|
export { AutocompleteCreate, AutocompleteCreateProps };
|
|
@@ -12,7 +12,7 @@ type AutocompleteEmptyOptions = {
|
|
|
12
12
|
*/
|
|
13
13
|
children?: string;
|
|
14
14
|
};
|
|
15
|
-
type AutocompleteEmptyProps = Omit<HTMLUIProps<
|
|
15
|
+
type AutocompleteEmptyProps = Omit<HTMLUIProps<"li">, "children"> & AutocompleteEmptyOptions;
|
|
16
16
|
declare const AutocompleteEmpty: _yamada_ui_core.Component<"li", AutocompleteEmptyProps>;
|
|
17
17
|
|
|
18
18
|
export { AutocompleteEmpty, AutocompleteEmptyProps };
|
|
@@ -12,7 +12,7 @@ type AutocompleteEmptyOptions = {
|
|
|
12
12
|
*/
|
|
13
13
|
children?: string;
|
|
14
14
|
};
|
|
15
|
-
type AutocompleteEmptyProps = Omit<HTMLUIProps<
|
|
15
|
+
type AutocompleteEmptyProps = Omit<HTMLUIProps<"li">, "children"> & AutocompleteEmptyOptions;
|
|
16
16
|
declare const AutocompleteEmpty: _yamada_ui_core.Component<"li", AutocompleteEmptyProps>;
|
|
17
17
|
|
|
18
18
|
export { AutocompleteEmpty, AutocompleteEmptyProps };
|
|
@@ -2,13 +2,13 @@ import * as _yamada_ui_core from '@yamada-ui/core';
|
|
|
2
2
|
import { HTMLUIProps } from '@yamada-ui/core';
|
|
3
3
|
import { FC } from 'react';
|
|
4
4
|
|
|
5
|
-
type AutocompleteIconProps = HTMLUIProps<
|
|
5
|
+
type AutocompleteIconProps = HTMLUIProps<"div">;
|
|
6
6
|
declare const AutocompleteIcon: _yamada_ui_core.Component<"div", AutocompleteIconProps>;
|
|
7
7
|
type AutocompleteClearIconProps = AutocompleteIconProps & {
|
|
8
8
|
disabled?: boolean;
|
|
9
9
|
};
|
|
10
10
|
declare const AutocompleteClearIcon: FC<AutocompleteClearIconProps>;
|
|
11
|
-
type AutocompleteItemIconProps = HTMLUIProps<
|
|
11
|
+
type AutocompleteItemIconProps = HTMLUIProps<"span">;
|
|
12
12
|
declare const AutocompleteItemIcon: _yamada_ui_core.Component<"span", AutocompleteItemIconProps>;
|
|
13
13
|
|
|
14
14
|
export { AutocompleteClearIcon, AutocompleteClearIconProps, AutocompleteIcon, AutocompleteIconProps, AutocompleteItemIcon, AutocompleteItemIconProps };
|
|
@@ -2,13 +2,13 @@ import * as _yamada_ui_core from '@yamada-ui/core';
|
|
|
2
2
|
import { HTMLUIProps } from '@yamada-ui/core';
|
|
3
3
|
import { FC } from 'react';
|
|
4
4
|
|
|
5
|
-
type AutocompleteIconProps = HTMLUIProps<
|
|
5
|
+
type AutocompleteIconProps = HTMLUIProps<"div">;
|
|
6
6
|
declare const AutocompleteIcon: _yamada_ui_core.Component<"div", AutocompleteIconProps>;
|
|
7
7
|
type AutocompleteClearIconProps = AutocompleteIconProps & {
|
|
8
8
|
disabled?: boolean;
|
|
9
9
|
};
|
|
10
10
|
declare const AutocompleteClearIcon: FC<AutocompleteClearIconProps>;
|
|
11
|
-
type AutocompleteItemIconProps = HTMLUIProps<
|
|
11
|
+
type AutocompleteItemIconProps = HTMLUIProps<"span">;
|
|
12
12
|
declare const AutocompleteItemIcon: _yamada_ui_core.Component<"span", AutocompleteItemIconProps>;
|
|
13
13
|
|
|
14
14
|
export { AutocompleteClearIcon, AutocompleteClearIconProps, AutocompleteIcon, AutocompleteIconProps, AutocompleteItemIcon, AutocompleteItemIconProps };
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import * as _yamada_ui_core from '@yamada-ui/core';
|
|
2
2
|
import { HTMLUIProps } from '@yamada-ui/core';
|
|
3
3
|
|
|
4
|
-
type AutocompleteListProps = HTMLUIProps<
|
|
4
|
+
type AutocompleteListProps = HTMLUIProps<"ul">;
|
|
5
5
|
declare const AutocompleteList: _yamada_ui_core.Component<"ul", AutocompleteListProps>;
|
|
6
6
|
|
|
7
7
|
export { AutocompleteList, AutocompleteListProps };
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import * as _yamada_ui_core from '@yamada-ui/core';
|
|
2
2
|
import { HTMLUIProps } from '@yamada-ui/core';
|
|
3
3
|
|
|
4
|
-
type AutocompleteListProps = HTMLUIProps<
|
|
4
|
+
type AutocompleteListProps = HTMLUIProps<"ul">;
|
|
5
5
|
declare const AutocompleteList: _yamada_ui_core.Component<"ul", AutocompleteListProps>;
|
|
6
6
|
|
|
7
7
|
export { AutocompleteList, AutocompleteListProps };
|
|
@@ -1,15 +1,14 @@
|
|
|
1
1
|
import * as _yamada_ui_core from '@yamada-ui/core';
|
|
2
2
|
import { HTMLUIProps } from '@yamada-ui/core';
|
|
3
|
-
import { U as UseAutocompleteOptionGroupProps } from './use-autocomplete-
|
|
3
|
+
import { U as UseAutocompleteOptionGroupProps } from './use-autocomplete-3e77a4da.js';
|
|
4
4
|
import 'react/jsx-runtime';
|
|
5
5
|
import 'react';
|
|
6
6
|
import '@yamada-ui/form-control';
|
|
7
7
|
import '@yamada-ui/popover';
|
|
8
|
-
import '@yamada-ui/select';
|
|
9
8
|
import '@yamada-ui/utils';
|
|
10
9
|
|
|
11
10
|
type AutocompleteOptionGroupOptions = UseAutocompleteOptionGroupProps;
|
|
12
|
-
type AutocompleteOptionGroupProps = HTMLUIProps<
|
|
11
|
+
type AutocompleteOptionGroupProps = HTMLUIProps<"ul"> & AutocompleteOptionGroupOptions;
|
|
13
12
|
declare const AutocompleteOptionGroup: _yamada_ui_core.Component<"ul", AutocompleteOptionGroupProps>;
|
|
14
13
|
|
|
15
14
|
export { AutocompleteOptionGroup, AutocompleteOptionGroupProps };
|
|
@@ -1,15 +1,14 @@
|
|
|
1
1
|
import * as _yamada_ui_core from '@yamada-ui/core';
|
|
2
2
|
import { HTMLUIProps } from '@yamada-ui/core';
|
|
3
|
-
import { U as UseAutocompleteOptionGroupProps } from './use-autocomplete-
|
|
3
|
+
import { U as UseAutocompleteOptionGroupProps } from './use-autocomplete-3e77a4da.js';
|
|
4
4
|
import 'react/jsx-runtime';
|
|
5
5
|
import 'react';
|
|
6
6
|
import '@yamada-ui/form-control';
|
|
7
7
|
import '@yamada-ui/popover';
|
|
8
|
-
import '@yamada-ui/select';
|
|
9
8
|
import '@yamada-ui/utils';
|
|
10
9
|
|
|
11
10
|
type AutocompleteOptionGroupOptions = UseAutocompleteOptionGroupProps;
|
|
12
|
-
type AutocompleteOptionGroupProps = HTMLUIProps<
|
|
11
|
+
type AutocompleteOptionGroupProps = HTMLUIProps<"ul"> & AutocompleteOptionGroupOptions;
|
|
13
12
|
declare const AutocompleteOptionGroup: _yamada_ui_core.Component<"ul", AutocompleteOptionGroupProps>;
|
|
14
13
|
|
|
15
14
|
export { AutocompleteOptionGroup, AutocompleteOptionGroupProps };
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import '@yamada-ui/core';
|
|
2
2
|
import 'react';
|
|
3
|
-
export { A as AutocompleteOption, a as AutocompleteOptionProps } from './use-autocomplete-
|
|
3
|
+
export { A as AutocompleteOption, a as AutocompleteOptionProps } from './use-autocomplete-3e77a4da.js';
|
|
4
4
|
import 'react/jsx-runtime';
|
|
5
5
|
import '@yamada-ui/form-control';
|
|
6
6
|
import '@yamada-ui/popover';
|
|
7
|
-
import '@yamada-ui/select';
|
|
8
7
|
import '@yamada-ui/utils';
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import '@yamada-ui/core';
|
|
2
2
|
import 'react';
|
|
3
|
-
export { A as AutocompleteOption, a as AutocompleteOptionProps } from './use-autocomplete-
|
|
3
|
+
export { A as AutocompleteOption, a as AutocompleteOptionProps } from './use-autocomplete-3e77a4da.js';
|
|
4
4
|
import 'react/jsx-runtime';
|
|
5
5
|
import '@yamada-ui/form-control';
|
|
6
6
|
import '@yamada-ui/popover';
|
|
7
|
-
import '@yamada-ui/select';
|
|
8
7
|
import '@yamada-ui/utils';
|
package/dist/autocomplete.d.mts
CHANGED
|
@@ -2,12 +2,11 @@ import * as _yamada_ui_core from '@yamada-ui/core';
|
|
|
2
2
|
import { ThemeProps, HTMLUIProps } from '@yamada-ui/core';
|
|
3
3
|
import { AutocompleteIconProps } from './autocomplete-icon.mjs';
|
|
4
4
|
import { AutocompleteListProps } from './autocomplete-list.mjs';
|
|
5
|
-
import {
|
|
5
|
+
import { c as UseAutocompleteProps } from './use-autocomplete-3e77a4da.js';
|
|
6
6
|
import 'react';
|
|
7
7
|
import 'react/jsx-runtime';
|
|
8
8
|
import '@yamada-ui/form-control';
|
|
9
9
|
import '@yamada-ui/popover';
|
|
10
|
-
import '@yamada-ui/select';
|
|
11
10
|
import '@yamada-ui/utils';
|
|
12
11
|
|
|
13
12
|
type AutocompleteOptions = {
|
|
@@ -22,21 +21,21 @@ type AutocompleteOptions = {
|
|
|
22
21
|
/**
|
|
23
22
|
* Props for autocomplete container element.
|
|
24
23
|
*/
|
|
25
|
-
containerProps?: Omit<HTMLUIProps<
|
|
24
|
+
containerProps?: Omit<HTMLUIProps<"div">, "children">;
|
|
26
25
|
/**
|
|
27
26
|
* Props for autocomplete list element.
|
|
28
27
|
*/
|
|
29
|
-
listProps?: Omit<AutocompleteListProps,
|
|
28
|
+
listProps?: Omit<AutocompleteListProps, "children">;
|
|
30
29
|
/**
|
|
31
30
|
* Props for autocomplete input element.
|
|
32
31
|
*/
|
|
33
|
-
inputProps?: HTMLUIProps<
|
|
32
|
+
inputProps?: HTMLUIProps<"input">;
|
|
34
33
|
/**
|
|
35
34
|
* Props for autocomplete icon element.
|
|
36
35
|
*/
|
|
37
36
|
iconProps?: AutocompleteIconProps;
|
|
38
37
|
};
|
|
39
|
-
type AutocompleteProps = ThemeProps<
|
|
38
|
+
type AutocompleteProps = ThemeProps<"Select"> & Omit<UseAutocompleteProps<string>, "maxSelectedValues" | "omitSelectedValues"> & AutocompleteOptions;
|
|
40
39
|
declare const Autocomplete: _yamada_ui_core.Component<"input", AutocompleteProps>;
|
|
41
40
|
|
|
42
41
|
export { Autocomplete, AutocompleteProps };
|
package/dist/autocomplete.d.ts
CHANGED
|
@@ -2,12 +2,11 @@ import * as _yamada_ui_core from '@yamada-ui/core';
|
|
|
2
2
|
import { ThemeProps, HTMLUIProps } from '@yamada-ui/core';
|
|
3
3
|
import { AutocompleteIconProps } from './autocomplete-icon.js';
|
|
4
4
|
import { AutocompleteListProps } from './autocomplete-list.js';
|
|
5
|
-
import {
|
|
5
|
+
import { c as UseAutocompleteProps } from './use-autocomplete-3e77a4da.js';
|
|
6
6
|
import 'react';
|
|
7
7
|
import 'react/jsx-runtime';
|
|
8
8
|
import '@yamada-ui/form-control';
|
|
9
9
|
import '@yamada-ui/popover';
|
|
10
|
-
import '@yamada-ui/select';
|
|
11
10
|
import '@yamada-ui/utils';
|
|
12
11
|
|
|
13
12
|
type AutocompleteOptions = {
|
|
@@ -22,21 +21,21 @@ type AutocompleteOptions = {
|
|
|
22
21
|
/**
|
|
23
22
|
* Props for autocomplete container element.
|
|
24
23
|
*/
|
|
25
|
-
containerProps?: Omit<HTMLUIProps<
|
|
24
|
+
containerProps?: Omit<HTMLUIProps<"div">, "children">;
|
|
26
25
|
/**
|
|
27
26
|
* Props for autocomplete list element.
|
|
28
27
|
*/
|
|
29
|
-
listProps?: Omit<AutocompleteListProps,
|
|
28
|
+
listProps?: Omit<AutocompleteListProps, "children">;
|
|
30
29
|
/**
|
|
31
30
|
* Props for autocomplete input element.
|
|
32
31
|
*/
|
|
33
|
-
inputProps?: HTMLUIProps<
|
|
32
|
+
inputProps?: HTMLUIProps<"input">;
|
|
34
33
|
/**
|
|
35
34
|
* Props for autocomplete icon element.
|
|
36
35
|
*/
|
|
37
36
|
iconProps?: AutocompleteIconProps;
|
|
38
37
|
};
|
|
39
|
-
type AutocompleteProps = ThemeProps<
|
|
38
|
+
type AutocompleteProps = ThemeProps<"Select"> & Omit<UseAutocompleteProps<string>, "maxSelectedValues" | "omitSelectedValues"> & AutocompleteOptions;
|
|
40
39
|
declare const Autocomplete: _yamada_ui_core.Component<"input", AutocompleteProps>;
|
|
41
40
|
|
|
42
41
|
export { Autocomplete, AutocompleteProps };
|
package/dist/autocomplete.js
CHANGED
|
@@ -351,20 +351,20 @@ var defaultFormat = (value) => {
|
|
|
351
351
|
value = value.toUpperCase();
|
|
352
352
|
return value;
|
|
353
353
|
};
|
|
354
|
-
var
|
|
355
|
-
const
|
|
356
|
-
|
|
354
|
+
var flattenItems = (items) => {
|
|
355
|
+
const filterItems = (items2) => items2.map((item) => {
|
|
356
|
+
var _a;
|
|
357
|
+
const { isDisabled, isFocusable } = item;
|
|
357
358
|
const trulyDisabled = !!isDisabled && !isFocusable;
|
|
358
|
-
const isMulti = (0, import_utils6.isArray)(value);
|
|
359
359
|
if (trulyDisabled)
|
|
360
360
|
return;
|
|
361
|
-
if (
|
|
362
|
-
return
|
|
361
|
+
if ("items" in item) {
|
|
362
|
+
return filterItems((_a = item.items) != null ? _a : []);
|
|
363
363
|
} else {
|
|
364
|
-
return
|
|
364
|
+
return item;
|
|
365
365
|
}
|
|
366
366
|
}).filter(Boolean);
|
|
367
|
-
return
|
|
367
|
+
return filterItems(items).flat(Infinity);
|
|
368
368
|
};
|
|
369
369
|
var isTargetOption = (target) => {
|
|
370
370
|
var _a;
|
|
@@ -387,14 +387,15 @@ var useAutocomplete = ({
|
|
|
387
387
|
maxSelectedValues,
|
|
388
388
|
closeOnBlur = true,
|
|
389
389
|
closeOnEsc = true,
|
|
390
|
-
|
|
391
|
-
|
|
390
|
+
allowCreate = false,
|
|
391
|
+
insertPositionItem = "first",
|
|
392
392
|
emptyMessage = "No results found",
|
|
393
393
|
format = defaultFormat,
|
|
394
394
|
placement = "bottom-start",
|
|
395
395
|
duration = 0.2,
|
|
396
396
|
optionProps,
|
|
397
397
|
placeholder,
|
|
398
|
+
items,
|
|
398
399
|
children,
|
|
399
400
|
...rest
|
|
400
401
|
}) => {
|
|
@@ -418,7 +419,7 @@ var useAutocomplete = ({
|
|
|
418
419
|
const inputRef = (0, import_react.useRef)(null);
|
|
419
420
|
const timeoutIds = (0, import_react.useRef)(/* @__PURE__ */ new Set([]));
|
|
420
421
|
const isComposition = (0, import_react.useRef)(false);
|
|
421
|
-
const [
|
|
422
|
+
const [resolvedItems, setResolvedItems] = (0, import_react.useState)(items);
|
|
422
423
|
const [value, setValue] = (0, import_use_controllable_state.useControllableState)({
|
|
423
424
|
value: rest.value,
|
|
424
425
|
defaultValue: rest.defaultValue,
|
|
@@ -431,19 +432,19 @@ var useAutocomplete = ({
|
|
|
431
432
|
const [isHit, setIsHit] = (0, import_react.useState)(true);
|
|
432
433
|
const [isOpen, setIsOpen] = (0, import_react.useState)(defaultIsOpen != null ? defaultIsOpen : false);
|
|
433
434
|
const isFocused = focusedIndex > -1;
|
|
434
|
-
const isCreate = focusedIndex === -2 &&
|
|
435
|
+
const isCreate = focusedIndex === -2 && allowCreate;
|
|
435
436
|
const isMulti = (0, import_utils6.isArray)(value);
|
|
436
437
|
const isEmptyValue = !isMulti ? !value : !value.length;
|
|
437
|
-
const [
|
|
438
|
-
if ((0, import_utils6.isArray)(
|
|
439
|
-
return
|
|
438
|
+
const [firstInsertPositionItem, secondInsertPositionItem] = (0, import_react.useMemo)(() => {
|
|
439
|
+
if ((0, import_utils6.isArray)(insertPositionItem)) {
|
|
440
|
+
return insertPositionItem;
|
|
440
441
|
} else {
|
|
441
|
-
return [
|
|
442
|
+
return [insertPositionItem, "first"];
|
|
442
443
|
}
|
|
443
|
-
}, [
|
|
444
|
-
if (
|
|
444
|
+
}, [insertPositionItem]);
|
|
445
|
+
if (allowCreate && !(0, import_utils6.isUndefined)(children)) {
|
|
445
446
|
console.warn(
|
|
446
|
-
`${!isMulti ? "Autocomplete" : "MultiAutocomplete"}: ${!isMulti ? "Autocomplete" : "MultiAutocomplete"} internally prefers 'children'. If '
|
|
447
|
+
`${!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.`
|
|
447
448
|
);
|
|
448
449
|
}
|
|
449
450
|
const selectedValues = descendants.enabledValues(
|
|
@@ -457,18 +458,18 @@ var useAutocomplete = ({
|
|
|
457
458
|
({ node, index }) => "target" in node.dataset && !selectedIndexes.includes(index)
|
|
458
459
|
);
|
|
459
460
|
const validChildren = (0, import_utils6.getValidChildren)(children);
|
|
460
|
-
const computedChildren =
|
|
461
|
-
if (
|
|
461
|
+
const computedChildren = resolvedItems == null ? void 0 : resolvedItems.map((item, i) => {
|
|
462
|
+
if ("value" in item) {
|
|
463
|
+
const { label, value: value2, ...props } = item;
|
|
462
464
|
return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(AutocompleteOption, { value: value2, ...props, children: label }, i);
|
|
463
|
-
} else {
|
|
465
|
+
} else if ("items" in item) {
|
|
466
|
+
const { label, items: items2 = [], ...props } = item;
|
|
464
467
|
return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
|
|
465
468
|
AutocompleteOptionGroup,
|
|
466
469
|
{
|
|
467
470
|
label,
|
|
468
471
|
...props,
|
|
469
|
-
children:
|
|
470
|
-
({ label: label2, value: value3, ...props2 }, i2) => !(0, import_utils6.isArray)(value3) ? /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(AutocompleteOption, { value: value3, ...props2, children: label2 }, i2) : null
|
|
471
|
-
)
|
|
472
|
+
children: items2.map(({ label: label2, value: value2, ...props2 }, i2) => /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(AutocompleteOption, { value: value2, ...props2, children: label2 }, i2))
|
|
472
473
|
},
|
|
473
474
|
i
|
|
474
475
|
);
|
|
@@ -479,13 +480,13 @@ var useAutocomplete = ({
|
|
|
479
480
|
var _a;
|
|
480
481
|
if (formControlProps.disabled || formControlProps.readOnly)
|
|
481
482
|
return;
|
|
482
|
-
if (!
|
|
483
|
+
if (!allowCreate && (isEmpty || isAllSelected))
|
|
483
484
|
return;
|
|
484
485
|
setIsOpen(true);
|
|
485
486
|
if (inputRef.current)
|
|
486
487
|
inputRef.current.focus();
|
|
487
488
|
(_a = rest.onOpen) == null ? void 0 : _a.call(rest);
|
|
488
|
-
}, [
|
|
489
|
+
}, [allowCreate, formControlProps, isAllSelected, isEmpty, rest]);
|
|
489
490
|
const onClose = (0, import_react.useCallback)(() => {
|
|
490
491
|
var _a;
|
|
491
492
|
setIsOpen(false);
|
|
@@ -757,55 +758,51 @@ var useAutocomplete = ({
|
|
|
757
758
|
isComposition.current = false;
|
|
758
759
|
}, []);
|
|
759
760
|
const onCreate = (0, import_react.useCallback)(() => {
|
|
760
|
-
var _a;
|
|
761
|
+
var _a, _b, _c;
|
|
761
762
|
if (!listRef.current)
|
|
762
763
|
return;
|
|
763
|
-
const
|
|
764
|
-
let
|
|
765
|
-
if (
|
|
766
|
-
|
|
767
|
-
if (
|
|
768
|
-
|
|
769
|
-
} else if (
|
|
770
|
-
|
|
764
|
+
const newItem = { label: inputValue, value: inputValue };
|
|
765
|
+
let newItems = [];
|
|
766
|
+
if (resolvedItems)
|
|
767
|
+
newItems = resolvedItems;
|
|
768
|
+
if (firstInsertPositionItem === "first") {
|
|
769
|
+
newItems = [newItem, ...newItems];
|
|
770
|
+
} else if (firstInsertPositionItem === "last") {
|
|
771
|
+
newItems = [...newItems, newItem];
|
|
771
772
|
} else {
|
|
772
|
-
const i =
|
|
773
|
-
({ label }) => label ===
|
|
773
|
+
const i = newItems.findIndex(
|
|
774
|
+
({ label }) => label === firstInsertPositionItem
|
|
774
775
|
);
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
...newOptions[i].value
|
|
780
|
-
];
|
|
776
|
+
const targetItem = newItems[i];
|
|
777
|
+
if (i !== -1 && "items" in targetItem) {
|
|
778
|
+
if (secondInsertPositionItem === "first") {
|
|
779
|
+
targetItem.items = [newItem, ...(_a = targetItem.items) != null ? _a : []];
|
|
781
780
|
} else {
|
|
782
|
-
|
|
783
|
-
...newOptions[i].value,
|
|
784
|
-
newOption
|
|
785
|
-
];
|
|
781
|
+
targetItem.items = [...(_b = targetItem.items) != null ? _b : [], newItem];
|
|
786
782
|
}
|
|
783
|
+
newItems[i] = targetItem;
|
|
787
784
|
} else {
|
|
788
785
|
console.warn(
|
|
789
|
-
`${!isMulti ? "Autocomplete" : "MultiAutocomplete"}: '${
|
|
786
|
+
`${!isMulti ? "Autocomplete" : "MultiAutocomplete"}: '${firstInsertPositionItem}' specified in insertPositionItem does not exist in the option group.`
|
|
790
787
|
);
|
|
791
788
|
}
|
|
792
789
|
}
|
|
793
|
-
|
|
790
|
+
setResolvedItems(newItems);
|
|
794
791
|
onChange(inputValue);
|
|
795
792
|
rebirthOptions(false);
|
|
796
|
-
const index =
|
|
793
|
+
const index = flattenItems(newItems).findIndex(
|
|
797
794
|
({ value: value2 }) => value2 === inputValue
|
|
798
795
|
);
|
|
799
796
|
setFocusedIndex(index);
|
|
800
|
-
(
|
|
797
|
+
(_c = rest.onCreate) == null ? void 0 : _c.call(rest, newItem, newItems);
|
|
801
798
|
}, [
|
|
802
799
|
inputValue,
|
|
803
|
-
|
|
804
|
-
|
|
800
|
+
resolvedItems,
|
|
801
|
+
firstInsertPositionItem,
|
|
805
802
|
onChange,
|
|
806
803
|
rebirthOptions,
|
|
807
804
|
rest,
|
|
808
|
-
|
|
805
|
+
secondInsertPositionItem,
|
|
809
806
|
isMulti
|
|
810
807
|
]);
|
|
811
808
|
const onDelete = (0, import_react.useCallback)(() => {
|
|
@@ -992,7 +989,7 @@ var useAutocomplete = ({
|
|
|
992
989
|
focusedIndex,
|
|
993
990
|
omitSelectedValues,
|
|
994
991
|
closeOnSelect,
|
|
995
|
-
|
|
992
|
+
allowCreate,
|
|
996
993
|
emptyMessage,
|
|
997
994
|
isOpen,
|
|
998
995
|
isAllSelected,
|
|
@@ -1471,7 +1468,7 @@ var Autocomplete = (0, import_core8.forwardRef)(
|
|
|
1471
1468
|
getPopoverProps,
|
|
1472
1469
|
getContainerProps,
|
|
1473
1470
|
getFieldProps,
|
|
1474
|
-
|
|
1471
|
+
allowCreate,
|
|
1475
1472
|
isEmpty,
|
|
1476
1473
|
inputValue,
|
|
1477
1474
|
computedChildren,
|
|
@@ -1493,7 +1490,7 @@ var Autocomplete = (0, import_core8.forwardRef)(
|
|
|
1493
1490
|
...rest,
|
|
1494
1491
|
formControlProps,
|
|
1495
1492
|
inputValue,
|
|
1496
|
-
|
|
1493
|
+
allowCreate,
|
|
1497
1494
|
isEmpty,
|
|
1498
1495
|
styles
|
|
1499
1496
|
},
|
|
@@ -1515,9 +1512,9 @@ var Autocomplete = (0, import_core8.forwardRef)(
|
|
|
1515
1512
|
),
|
|
1516
1513
|
/* @__PURE__ */ (0, import_jsx_runtime8.jsx)(AutocompleteIcon, { ...iconProps, ...formControlProps }),
|
|
1517
1514
|
!isEmpty ? /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)(AutocompleteList, { ...listProps, children: [
|
|
1518
|
-
|
|
1515
|
+
allowCreate ? /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(AutocompleteCreate, {}) : /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(AutocompleteEmpty, {}),
|
|
1519
1516
|
children != null ? children : computedChildren
|
|
1520
|
-
] }) : /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(AutocompleteList, { ...listProps, children:
|
|
1517
|
+
] }) : /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(AutocompleteList, { ...listProps, children: allowCreate && inputValue ? /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(AutocompleteCreate, {}) : /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(AutocompleteEmpty, {}) })
|
|
1521
1518
|
]
|
|
1522
1519
|
}
|
|
1523
1520
|
) })
|