@yamada-ui/autocomplete 1.6.5-dev-20241118224412 → 1.6.5-dev-20241119150031
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/autocomplete-context.d.mts +0 -1
- package/dist/autocomplete-context.d.ts +0 -1
- package/dist/autocomplete-context.js.map +1 -1
- package/dist/autocomplete-context.mjs +1 -1
- package/dist/autocomplete-create.js.map +1 -1
- package/dist/autocomplete-create.mjs +4 -4
- package/dist/autocomplete-empty.js.map +1 -1
- package/dist/autocomplete-empty.mjs +4 -4
- package/dist/autocomplete-icon.js.map +1 -1
- package/dist/autocomplete-icon.mjs +2 -2
- package/dist/autocomplete-list.js +22 -15
- package/dist/autocomplete-list.js.map +1 -1
- package/dist/autocomplete-list.mjs +3 -3
- package/dist/autocomplete-option-group.js.map +1 -1
- package/dist/autocomplete-option-group.mjs +3 -3
- package/dist/autocomplete-option.js.map +1 -1
- package/dist/autocomplete-option.mjs +4 -4
- package/dist/autocomplete.js +66 -76
- package/dist/autocomplete.js.map +1 -1
- package/dist/autocomplete.mjs +12 -12
- package/dist/{chunk-7YDPBPBY.mjs → chunk-2CVB4NO5.mjs} +7 -7
- package/dist/{chunk-LCC3VNZV.mjs → chunk-2LP57WVB.mjs} +2 -2
- package/dist/{chunk-PTPJFYGI.mjs → chunk-4GVV3HBE.mjs} +29 -13
- package/dist/chunk-4GVV3HBE.mjs.map +1 -0
- package/dist/{chunk-6OTUOEYS.mjs → chunk-7QCZ5NGS.mjs} +2 -2
- package/dist/{chunk-PU6HFINM.mjs → chunk-ABCTEZN5.mjs} +3 -3
- package/dist/{chunk-J3GHHVSC.mjs → chunk-IFH3PPSD.mjs} +7 -7
- package/dist/{chunk-REPBXBG3.mjs → chunk-LIBFONYN.mjs} +7 -10
- package/dist/chunk-LIBFONYN.mjs.map +1 -0
- package/dist/{chunk-7GVG5MVF.mjs → chunk-PWV7X7G6.mjs} +4 -4
- package/dist/{chunk-ZFWB5LCD.mjs → chunk-RK5E5J5E.mjs} +4 -4
- package/dist/{chunk-ZNO5RUVT.mjs → chunk-TP5VZFO3.mjs} +1 -1
- package/dist/chunk-TP5VZFO3.mjs.map +1 -0
- package/dist/{chunk-CMFJUJJW.mjs → chunk-UX5QECNB.mjs} +2 -2
- package/dist/{chunk-6QAH2ARG.mjs → chunk-YPKDYYEV.mjs} +4 -4
- package/dist/{chunk-YWUT56L3.mjs → chunk-ZR77IT3O.mjs} +49 -67
- package/dist/chunk-ZR77IT3O.mjs.map +1 -0
- package/dist/index.js +66 -76
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +13 -13
- package/dist/multi-autocomplete.js +66 -76
- package/dist/multi-autocomplete.js.map +1 -1
- package/dist/multi-autocomplete.mjs +12 -12
- package/dist/use-autocomplete-list.d.mts +2 -1
- package/dist/use-autocomplete-list.d.ts +2 -1
- package/dist/use-autocomplete-list.js +19 -9
- package/dist/use-autocomplete-list.js.map +1 -1
- package/dist/use-autocomplete-list.mjs +2 -2
- package/dist/use-autocomplete-option-group.js.map +1 -1
- package/dist/use-autocomplete-option-group.mjs +2 -2
- package/dist/use-autocomplete-option.js.map +1 -1
- package/dist/use-autocomplete-option.mjs +2 -2
- package/dist/use-autocomplete.d.mts +0 -2
- package/dist/use-autocomplete.d.ts +0 -2
- package/dist/use-autocomplete.js +44 -61
- package/dist/use-autocomplete.js.map +1 -1
- package/dist/use-autocomplete.mjs +7 -7
- package/package.json +4 -4
- package/dist/chunk-PTPJFYGI.mjs.map +0 -1
- package/dist/chunk-REPBXBG3.mjs.map +0 -1
- package/dist/chunk-YWUT56L3.mjs.map +0 -1
- package/dist/chunk-ZNO5RUVT.mjs.map +0 -1
- /package/dist/{chunk-7YDPBPBY.mjs.map → chunk-2CVB4NO5.mjs.map} +0 -0
- /package/dist/{chunk-LCC3VNZV.mjs.map → chunk-2LP57WVB.mjs.map} +0 -0
- /package/dist/{chunk-6OTUOEYS.mjs.map → chunk-7QCZ5NGS.mjs.map} +0 -0
- /package/dist/{chunk-PU6HFINM.mjs.map → chunk-ABCTEZN5.mjs.map} +0 -0
- /package/dist/{chunk-J3GHHVSC.mjs.map → chunk-IFH3PPSD.mjs.map} +0 -0
- /package/dist/{chunk-7GVG5MVF.mjs.map → chunk-PWV7X7G6.mjs.map} +0 -0
- /package/dist/{chunk-ZFWB5LCD.mjs.map → chunk-RK5E5J5E.mjs.map} +0 -0
- /package/dist/{chunk-CMFJUJJW.mjs.map → chunk-UX5QECNB.mjs.map} +0 -0
- /package/dist/{chunk-6QAH2ARG.mjs.map → chunk-YPKDYYEV.mjs.map} +0 -0
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../src/autocomplete-option.tsx","../src/autocomplete-context.ts","../src/autocomplete-icon.tsx","../src/use-autocomplete-option.ts"],"sourcesContent":["import type { CSSUIObject, FC } from \"@yamada-ui/core\"\nimport type { ReactElement } from \"react\"\nimport type { UseAutocompleteOptionProps } from \"./use-autocomplete-option\"\nimport { forwardRef, ui } from \"@yamada-ui/core\"\nimport { cx } from \"@yamada-ui/utils\"\nimport { useAutocompleteContext } from \"./autocomplete-context\"\nimport { AutocompleteItemIcon } from \"./autocomplete-icon\"\nimport { useAutocompleteOption } from \"./use-autocomplete-option\"\n\ninterface AutocompleteOptionOptions {\n /**\n * The autocomplete option icon to use.\n */\n icon?: null | ReactElement\n}\n\nexport interface AutocompleteOptionProps\n extends UseAutocompleteOptionProps,\n AutocompleteOptionOptions {}\n\nexport const AutocompleteOption = forwardRef<AutocompleteOptionProps, \"div\">(\n ({ className, icon, ...rest }, ref) => {\n const { styles } = useAutocompleteContext()\n const { children, customIcon, isSelected, getOptionProps } =\n useAutocompleteOption(rest)\n\n icon ??= customIcon\n\n const css: CSSUIObject = {\n alignItems: \"center\",\n color: \"inherit\",\n display: \"flex\",\n flex: \"0 0 auto\",\n gap: \"0.75rem\",\n outline: 0,\n textAlign: \"start\",\n textDecoration: \"none\",\n userSelect: \"none\",\n width: \"100%\",\n ...styles.item,\n }\n\n return (\n <ui.div\n className={cx(\"ui-autocomplete__item\", className)}\n __css={css}\n {...getOptionProps({}, ref)}\n >\n {icon !== null ? (\n <AutocompleteItemIcon opacity={isSelected ? 1 : 0}>\n {icon || <AutocompleteCheckIcon />}\n </AutocompleteItemIcon>\n ) : null}\n\n <ui.span style={{ flex: 1 }} data-label>\n {children}\n </ui.span>\n </ui.div>\n )\n },\n)\n\nAutocompleteOption.displayName = \"AutocompleteOption\"\nAutocompleteOption.__ui__ = \"AutocompleteOption\"\n\nconst AutocompleteCheckIcon: FC = () => (\n <svg height=\"1em\" viewBox=\"0 0 14 14\" width=\"1em\">\n <polygon\n fill=\"currentColor\"\n points=\"5.5 11.9993304 14 3.49933039 12.5 2 5.5 8.99933039 1.5 4.9968652 0 6.49933039\"\n />\n </svg>\n)\n\nAutocompleteCheckIcon.displayName = \"AutocompleteCheckIcon\"\nAutocompleteCheckIcon.__ui__ = \"AutocompleteCheckIcon\"\n","import type { CSSUIObject } from \"@yamada-ui/core\"\nimport type { Dispatch, DOMAttributes, RefObject, SetStateAction } from \"react\"\nimport type { UseAutocompleteProps } from \"./use-autocomplete\"\nimport { createDescendant } from \"@yamada-ui/use-descendant\"\nimport { createContext } from \"@yamada-ui/utils\"\n\nexport const {\n DescendantsContextProvider: AutocompleteDescendantsContextProvider,\n useDescendant: useAutocompleteDescendant,\n useDescendants: useAutocompleteDescendants,\n useDescendantsContext: useAutocompleteDescendantsContext,\n} = createDescendant()\n\ninterface AutocompleteContext\n extends Omit<\n UseAutocompleteProps,\n \"defaultValue\" | \"onChange\" | \"onCreate\" | \"value\"\n > {\n focusedIndex: number\n inputRef: RefObject<HTMLInputElement>\n inputValue: string\n isAllSelected: boolean\n isEmpty: boolean\n isHit: boolean\n isOpen: boolean\n label: string | string[] | undefined\n listRef: RefObject<HTMLUListElement>\n pickOptions: (value: string) => void\n rebirthOptions: (runFocus?: boolean) => void\n setFocusedIndex: Dispatch<SetStateAction<number>>\n styles: { [key: string]: CSSUIObject | undefined }\n value: string | string[]\n formControlProps: { [key: string]: any }\n inputProps: DOMAttributes<HTMLInputElement>\n onChange: (newValue: string, runRebirth?: boolean) => void\n onClose: () => void\n onCreate: () => void\n onFocusFirst: () => void\n onFocusLast: () => void\n onFocusNext: (index?: number) => void\n onFocusPrev: (index?: number) => void\n onOpen: () => void\n}\n\nexport const [AutocompleteProvider, useAutocompleteContext] =\n createContext<AutocompleteContext>({\n name: \"AutocompleteContext\",\n errorMessage: `useAutocompleteContext returned is 'undefined'. Seems you forgot to wrap the components in \"<Autocomplete />\" or \"<MultiAutocomplete />\"`,\n })\n","import type { CSSUIObject, FC, HTMLUIProps } from \"@yamada-ui/core\"\nimport type { HTMLAttributes } from \"react\"\nimport { forwardRef, ui } from \"@yamada-ui/core\"\nimport { ChevronIcon, CloseIcon } from \"@yamada-ui/icon\"\nimport { useClickable } from \"@yamada-ui/use-clickable\"\nimport { cx, getValidChildren, isValidElement } from \"@yamada-ui/utils\"\nimport { cloneElement, useRef } from \"react\"\nimport { useAutocompleteContext } from \"./autocomplete-context\"\n\nexport interface AutocompleteIconProps extends HTMLUIProps {}\n\nexport const AutocompleteIcon = forwardRef<AutocompleteIconProps, \"div\">(\n ({ className, children, __css, ...rest }, ref) => {\n const { styles } = useAutocompleteContext()\n\n const css: CSSUIObject = {\n alignItems: \"center\",\n cursor: \"pointer\",\n display: \"inline-flex\",\n justifyContent: \"center\",\n pointerEvents: \"none\",\n position: \"absolute\",\n top: \"50%\",\n transform: \"translateY(-50%)\",\n ...styles.icon,\n ...__css,\n }\n\n const validChildren = getValidChildren(children)\n\n const cloneChildren = validChildren.map((child) =>\n cloneElement(child, {\n style: {\n color: \"currentColor\",\n maxHeight: \"1em\",\n maxWidth: \"1em\",\n },\n \"aria-hidden\": true,\n focusable: false,\n }),\n )\n\n return (\n <ui.div\n ref={ref}\n className={cx(\"ui-autocomplete__icon\", className)}\n __css={css}\n {...rest}\n >\n {isValidElement(children) ? cloneChildren : <ChevronIcon />}\n </ui.div>\n )\n },\n)\n\nAutocompleteIcon.displayName = \"AutocompleteIcon\"\nAutocompleteIcon.__ui__ = \"AutocompleteIcon\"\n\nexport interface AutocompleteClearIconProps extends AutocompleteIconProps {\n disabled?: boolean\n}\n\nexport const AutocompleteClearIcon: FC<AutocompleteClearIconProps> = ({\n className,\n children,\n ...props\n}) => {\n const ref = useRef<HTMLDivElement>(null)\n const { styles } = useAutocompleteContext()\n\n const isDisabled = props.disabled\n\n const rest = useClickable({\n ref,\n isDisabled,\n ...(props as HTMLAttributes<HTMLElement>),\n })\n\n return (\n <AutocompleteIcon\n className={cx(\"ui-autocomplete__icon--clear\", className)}\n aria-label=\"Clear value\"\n __css={styles.clearIcon}\n {...rest}\n >\n {children ?? <CloseIcon h=\"0.5em\" w=\"0.5em\" />}\n </AutocompleteIcon>\n )\n}\n\nAutocompleteClearIcon.displayName = \"AutocompleteClearIcon\"\nAutocompleteClearIcon.__ui__ = \"AutocompleteClearIcon\"\n\nexport interface AutocompleteItemIconProps extends HTMLUIProps<\"span\"> {}\n\nexport const AutocompleteItemIcon = forwardRef<\n AutocompleteItemIconProps,\n \"span\"\n>(({ className, ...rest }, ref) => {\n const { styles } = useAutocompleteContext()\n\n const css: CSSUIObject = {\n alignItems: \"center\",\n display: \"inline-flex\",\n flexShrink: 0,\n fontSize: \"0.85em\",\n justifyContent: \"center\",\n ...styles.itemIcon,\n }\n\n return (\n <ui.span\n ref={ref}\n className={cx(\"ui-autocomplete__item__icon\", className)}\n __css={css}\n {...rest}\n />\n )\n})\n\nAutocompleteItemIcon.displayName = \"AutocompleteItemIcon\"\nAutocompleteItemIcon.__ui__ = \"AutocompleteItemIcon\"\n","import type { HTMLUIProps, PropGetter } from \"@yamada-ui/core\"\nimport type { CSSProperties, MouseEvent } from \"react\"\nimport {\n ariaAttr,\n dataAttr,\n handlerAll,\n isArray,\n isHTMLElement,\n isNumber,\n isString,\n isUndefined,\n mergeRefs,\n} from \"@yamada-ui/utils\"\nimport { useCallback, useId, useRef } from \"react\"\nimport {\n useAutocompleteContext,\n useAutocompleteDescendant,\n} from \"./autocomplete-context\"\n\nconst isTargetOption = (target: EventTarget | null): boolean =>\n isHTMLElement(target) && !!target.getAttribute(\"role\")?.startsWith(\"option\")\n\nexport interface UseAutocompleteOptionProps\n extends Omit<HTMLUIProps, \"children\" | \"value\"> {\n /**\n * The label of the autocomplete option.\n */\n children?: string\n /**\n * If `true`, the list element will be closed when selected.\n *\n * @default false\n */\n closeOnSelect?: boolean\n /**\n * If `true`, the autocomplete option will be disabled.\n *\n * @default false\n */\n disabled?: boolean\n /**\n * If `true`, the autocomplete option will be focusable.\n *\n * @default false\n */\n focusable?: boolean\n /**\n * If `true`, the autocomplete option will be disabled.\n *\n * @default false\n *\n * @deprecated Use `disabled` instead.\n */\n isDisabled?: boolean\n /**\n * If `true`, the autocomplete option will be focusable.\n *\n * @default false\n *\n * @deprecated Use `focusable` instead.\n */\n isFocusable?: boolean\n /**\n * The value of the autocomplete option.\n */\n value?: string\n}\n\nexport const useAutocompleteOption = (props: UseAutocompleteOptionProps) => {\n const {\n closeOnSelect,\n focusedIndex,\n inputRef,\n omitSelectedValues,\n setFocusedIndex,\n value,\n optionProps,\n onChange,\n onClose,\n onFocusNext,\n } = useAutocompleteContext()\n const uuid = useId()\n const itemRef = useRef<HTMLLIElement>(null)\n let {\n id,\n children,\n closeOnSelect: customCloseOnSelect,\n disabled,\n focusable,\n icon: customIcon,\n isDisabled,\n isFocusable,\n value: optionValue,\n ...computedProps\n } = { ...optionProps, ...props }\n disabled ??= isDisabled\n focusable ??= isFocusable\n const trulyDisabled = !!disabled && !focusable\n const { descendants, index, register } = useAutocompleteDescendant({\n disabled: trulyDisabled,\n })\n const values = descendants.values()\n const frontValues = values.slice(0, index)\n const isMulti = isArray(value)\n const isDuplicated = frontValues.some(\n ({ node }) => node.dataset.value === (optionValue ?? \"\"),\n )\n const isSelected =\n !isDuplicated &&\n (!isMulti\n ? (optionValue ?? \"\") === value\n : value.includes(optionValue ?? \"\"))\n const isTarget = \"target\" in (itemRef.current?.dataset ?? {})\n const isFocused = index === focusedIndex\n\n id ??= uuid\n\n if (isUndefined(optionValue)) {\n if (isString(children) || isNumber(children)) {\n optionValue = children.toString()\n } else {\n console.warn(\n `${\n !isMulti ? \"Autocomplete\" : \"MultiAutocomplete\"\n }: Cannot infer the option value of complex children. Pass a \\`value\\` prop or use a plain string as children to <Option>.`,\n )\n }\n }\n\n const onClick = useCallback(\n (ev: MouseEvent<HTMLDivElement>) => {\n ev.stopPropagation()\n\n if (disabled || !isTargetOption(ev.currentTarget)) {\n if (inputRef.current) inputRef.current.focus()\n\n return\n }\n\n if (!isDuplicated) setFocusedIndex(index)\n\n onChange(optionValue ?? \"\")\n\n if (inputRef.current) inputRef.current.focus()\n\n if (customCloseOnSelect ?? closeOnSelect) onClose()\n\n if (omitSelectedValues) onFocusNext(index)\n },\n [\n isDuplicated,\n onFocusNext,\n omitSelectedValues,\n disabled,\n optionValue,\n setFocusedIndex,\n index,\n onChange,\n customCloseOnSelect,\n closeOnSelect,\n onClose,\n inputRef,\n ],\n )\n\n const getOptionProps: PropGetter = useCallback(\n (props = {}, ref = null) => {\n const isHidden = !isTarget || (omitSelectedValues && isSelected)\n\n const style: CSSProperties = {\n border: \"0px\",\n clip: \"rect(0px, 0px, 0px, 0px)\",\n height: \"1px\",\n margin: \"-1px\",\n overflow: \"hidden\",\n padding: \"0px\",\n position: \"absolute\",\n whiteSpace: \"nowrap\",\n width: \"1px\",\n }\n\n return {\n ref: mergeRefs(itemRef, ref, register),\n role: \"option\",\n ...computedProps,\n ...props,\n id,\n style: isHidden ? style : undefined,\n \"aria-disabled\": ariaAttr(disabled),\n \"aria-hidden\": ariaAttr(isHidden),\n \"aria-selected\": isSelected,\n \"data-disabled\": dataAttr(disabled),\n \"data-duplicated\": dataAttr(isDuplicated),\n \"data-focus\": dataAttr(isFocused),\n \"data-target\": dataAttr(true),\n \"data-value\": optionValue ?? \"\",\n tabIndex: -1,\n onClick: handlerAll(computedProps.onClick, props.onClick, onClick),\n }\n },\n [\n id,\n isDuplicated,\n optionValue,\n computedProps,\n disabled,\n isFocused,\n isSelected,\n isTarget,\n omitSelectedValues,\n onClick,\n register,\n ],\n )\n\n return {\n children,\n customIcon,\n isFocused,\n isSelected,\n isTarget,\n omitSelectedValues,\n getOptionProps,\n }\n}\n\nexport type UseAutocompleteOptionReturn = ReturnType<\n typeof useAutocompleteOption\n>\n\nexport const useAutocompleteCreate = () => {\n const { isHit, onCreate } = useAutocompleteContext()\n\n const getCreateProps: PropGetter = useCallback(\n (props = {}, ref = null) => {\n const style: CSSProperties = {\n border: \"0px\",\n clip: \"rect(0px, 0px, 0px, 0px)\",\n height: \"1px\",\n margin: \"-1px\",\n overflow: \"hidden\",\n padding: \"0px\",\n position: \"absolute\",\n whiteSpace: \"nowrap\",\n width: \"1px\",\n }\n\n return {\n ref,\n role: \"option\",\n ...props,\n style: isHit ? style : undefined,\n \"aria-hidden\": ariaAttr(isHit),\n \"data-focus\": dataAttr(!isHit),\n tabIndex: -1,\n onClick: handlerAll(props.onClick, onCreate),\n }\n },\n [isHit, onCreate],\n )\n\n return { getCreateProps }\n}\n\nexport type UseAutocompleteCreateReturn = ReturnType<\n typeof useAutocompleteCreate\n>\n\nexport const useAutocompleteEmpty = () => {\n const { isEmpty, isHit } = useAutocompleteContext()\n\n const getEmptyProps: PropGetter = useCallback(\n (props = {}, ref = null) => {\n const isHidden = isHit && !isEmpty\n\n const style: CSSProperties = {\n border: \"0px\",\n clip: \"rect(0px, 0px, 0px, 0px)\",\n height: \"1px\",\n margin: \"-1px\",\n overflow: \"hidden\",\n padding: \"0px\",\n position: \"absolute\",\n whiteSpace: \"nowrap\",\n width: \"1px\",\n }\n\n return {\n ref,\n role: \"presentation\",\n ...props,\n style: isHidden ? style : undefined,\n \"aria-hidden\": ariaAttr(isHidden),\n tabIndex: -1,\n }\n },\n [isHit, isEmpty],\n )\n\n return { getEmptyProps }\n}\n\nexport type UseAutocompleteEmptyReturn = ReturnType<typeof useAutocompleteEmpty>\n"],"mappings":";;;;;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AAA;AAAA,IACC,MAAK;AAAA,IACL,QAAO;AAAA;AACT,GACF;AAGF,sBAAsB,cAAc;AACpC,sBAAsB,SAAS;","names":["import_core","import_utils","import_utils","import_utils","import_react","props","import_jsx_runtime"]}
|
1
|
+
{"version":3,"sources":["../src/autocomplete-option.tsx","../src/autocomplete-context.ts","../src/autocomplete-icon.tsx","../src/use-autocomplete-option.ts"],"sourcesContent":["import type { CSSUIObject, FC } from \"@yamada-ui/core\"\nimport type { ReactElement } from \"react\"\nimport type { UseAutocompleteOptionProps } from \"./use-autocomplete-option\"\nimport { forwardRef, ui } from \"@yamada-ui/core\"\nimport { cx } from \"@yamada-ui/utils\"\nimport { useAutocompleteContext } from \"./autocomplete-context\"\nimport { AutocompleteItemIcon } from \"./autocomplete-icon\"\nimport { useAutocompleteOption } from \"./use-autocomplete-option\"\n\ninterface AutocompleteOptionOptions {\n /**\n * The autocomplete option icon to use.\n */\n icon?: null | ReactElement\n}\n\nexport interface AutocompleteOptionProps\n extends UseAutocompleteOptionProps,\n AutocompleteOptionOptions {}\n\nexport const AutocompleteOption = forwardRef<AutocompleteOptionProps, \"div\">(\n ({ className, icon, ...rest }, ref) => {\n const { styles } = useAutocompleteContext()\n const { children, customIcon, isSelected, getOptionProps } =\n useAutocompleteOption(rest)\n\n icon ??= customIcon\n\n const css: CSSUIObject = {\n alignItems: \"center\",\n color: \"inherit\",\n display: \"flex\",\n flex: \"0 0 auto\",\n gap: \"0.75rem\",\n outline: 0,\n textAlign: \"start\",\n textDecoration: \"none\",\n userSelect: \"none\",\n width: \"100%\",\n ...styles.item,\n }\n\n return (\n <ui.div\n className={cx(\"ui-autocomplete__item\", className)}\n __css={css}\n {...getOptionProps({}, ref)}\n >\n {icon !== null ? (\n <AutocompleteItemIcon opacity={isSelected ? 1 : 0}>\n {icon || <AutocompleteCheckIcon />}\n </AutocompleteItemIcon>\n ) : null}\n\n <ui.span style={{ flex: 1 }} data-label>\n {children}\n </ui.span>\n </ui.div>\n )\n },\n)\n\nAutocompleteOption.displayName = \"AutocompleteOption\"\nAutocompleteOption.__ui__ = \"AutocompleteOption\"\n\nconst AutocompleteCheckIcon: FC = () => (\n <svg height=\"1em\" viewBox=\"0 0 14 14\" width=\"1em\">\n <polygon\n fill=\"currentColor\"\n points=\"5.5 11.9993304 14 3.49933039 12.5 2 5.5 8.99933039 1.5 4.9968652 0 6.49933039\"\n />\n </svg>\n)\n\nAutocompleteCheckIcon.displayName = \"AutocompleteCheckIcon\"\nAutocompleteCheckIcon.__ui__ = \"AutocompleteCheckIcon\"\n","import type { CSSUIObject } from \"@yamada-ui/core\"\nimport type { Dispatch, DOMAttributes, RefObject, SetStateAction } from \"react\"\nimport type { UseAutocompleteProps } from \"./use-autocomplete\"\nimport { createDescendant } from \"@yamada-ui/use-descendant\"\nimport { createContext } from \"@yamada-ui/utils\"\n\nexport const {\n DescendantsContextProvider: AutocompleteDescendantsContextProvider,\n useDescendant: useAutocompleteDescendant,\n useDescendants: useAutocompleteDescendants,\n useDescendantsContext: useAutocompleteDescendantsContext,\n} = createDescendant()\n\ninterface AutocompleteContext\n extends Omit<\n UseAutocompleteProps,\n \"defaultValue\" | \"onChange\" | \"onCreate\" | \"value\"\n > {\n focusedIndex: number\n inputRef: RefObject<HTMLInputElement>\n inputValue: string\n isAllSelected: boolean\n isEmpty: boolean\n isHit: boolean\n isOpen: boolean\n label: string | string[] | undefined\n pickOptions: (value: string) => void\n rebirthOptions: (runFocus?: boolean) => void\n setFocusedIndex: Dispatch<SetStateAction<number>>\n styles: { [key: string]: CSSUIObject | undefined }\n value: string | string[]\n formControlProps: { [key: string]: any }\n inputProps: DOMAttributes<HTMLInputElement>\n onChange: (newValue: string, runRebirth?: boolean) => void\n onClose: () => void\n onCreate: () => void\n onFocusFirst: () => void\n onFocusLast: () => void\n onFocusNext: (index?: number) => void\n onFocusPrev: (index?: number) => void\n onOpen: () => void\n}\n\nexport const [AutocompleteProvider, useAutocompleteContext] =\n createContext<AutocompleteContext>({\n name: \"AutocompleteContext\",\n errorMessage: `useAutocompleteContext returned is 'undefined'. Seems you forgot to wrap the components in \"<Autocomplete />\" or \"<MultiAutocomplete />\"`,\n })\n","import type { CSSUIObject, FC, HTMLUIProps } from \"@yamada-ui/core\"\nimport type { HTMLAttributes } from \"react\"\nimport { forwardRef, ui } from \"@yamada-ui/core\"\nimport { ChevronIcon, CloseIcon } from \"@yamada-ui/icon\"\nimport { useClickable } from \"@yamada-ui/use-clickable\"\nimport { cx, getValidChildren, isValidElement } from \"@yamada-ui/utils\"\nimport { cloneElement, useRef } from \"react\"\nimport { useAutocompleteContext } from \"./autocomplete-context\"\n\nexport interface AutocompleteIconProps extends HTMLUIProps {}\n\nexport const AutocompleteIcon = forwardRef<AutocompleteIconProps, \"div\">(\n ({ className, children, __css, ...rest }, ref) => {\n const { styles } = useAutocompleteContext()\n\n const css: CSSUIObject = {\n alignItems: \"center\",\n cursor: \"pointer\",\n display: \"inline-flex\",\n justifyContent: \"center\",\n pointerEvents: \"none\",\n position: \"absolute\",\n top: \"50%\",\n transform: \"translateY(-50%)\",\n ...styles.icon,\n ...__css,\n }\n\n const validChildren = getValidChildren(children)\n\n const cloneChildren = validChildren.map((child) =>\n cloneElement(child, {\n style: {\n color: \"currentColor\",\n maxHeight: \"1em\",\n maxWidth: \"1em\",\n },\n \"aria-hidden\": true,\n focusable: false,\n }),\n )\n\n return (\n <ui.div\n ref={ref}\n className={cx(\"ui-autocomplete__icon\", className)}\n __css={css}\n {...rest}\n >\n {isValidElement(children) ? cloneChildren : <ChevronIcon />}\n </ui.div>\n )\n },\n)\n\nAutocompleteIcon.displayName = \"AutocompleteIcon\"\nAutocompleteIcon.__ui__ = \"AutocompleteIcon\"\n\nexport interface AutocompleteClearIconProps extends AutocompleteIconProps {\n disabled?: boolean\n}\n\nexport const AutocompleteClearIcon: FC<AutocompleteClearIconProps> = ({\n className,\n children,\n ...props\n}) => {\n const ref = useRef<HTMLDivElement>(null)\n const { styles } = useAutocompleteContext()\n\n const isDisabled = props.disabled\n\n const rest = useClickable({\n ref,\n isDisabled,\n ...(props as HTMLAttributes<HTMLElement>),\n })\n\n return (\n <AutocompleteIcon\n className={cx(\"ui-autocomplete__icon--clear\", className)}\n aria-label=\"Clear value\"\n __css={styles.clearIcon}\n {...rest}\n >\n {children ?? <CloseIcon h=\"0.5em\" w=\"0.5em\" />}\n </AutocompleteIcon>\n )\n}\n\nAutocompleteClearIcon.displayName = \"AutocompleteClearIcon\"\nAutocompleteClearIcon.__ui__ = \"AutocompleteClearIcon\"\n\nexport interface AutocompleteItemIconProps extends HTMLUIProps<\"span\"> {}\n\nexport const AutocompleteItemIcon = forwardRef<\n AutocompleteItemIconProps,\n \"span\"\n>(({ className, ...rest }, ref) => {\n const { styles } = useAutocompleteContext()\n\n const css: CSSUIObject = {\n alignItems: \"center\",\n display: \"inline-flex\",\n flexShrink: 0,\n fontSize: \"0.85em\",\n justifyContent: \"center\",\n ...styles.itemIcon,\n }\n\n return (\n <ui.span\n ref={ref}\n className={cx(\"ui-autocomplete__item__icon\", className)}\n __css={css}\n {...rest}\n />\n )\n})\n\nAutocompleteItemIcon.displayName = \"AutocompleteItemIcon\"\nAutocompleteItemIcon.__ui__ = \"AutocompleteItemIcon\"\n","import type { HTMLUIProps, PropGetter } from \"@yamada-ui/core\"\nimport type { CSSProperties, MouseEvent } from \"react\"\nimport {\n ariaAttr,\n dataAttr,\n handlerAll,\n isArray,\n isHTMLElement,\n isNumber,\n isString,\n isUndefined,\n mergeRefs,\n} from \"@yamada-ui/utils\"\nimport { useCallback, useId, useRef } from \"react\"\nimport {\n useAutocompleteContext,\n useAutocompleteDescendant,\n} from \"./autocomplete-context\"\n\nconst isTargetOption = (target: EventTarget | null): boolean =>\n isHTMLElement(target) && !!target.getAttribute(\"role\")?.startsWith(\"option\")\n\nexport interface UseAutocompleteOptionProps\n extends Omit<HTMLUIProps, \"children\" | \"value\"> {\n /**\n * The label of the autocomplete option.\n */\n children?: string\n /**\n * If `true`, the list element will be closed when selected.\n *\n * @default false\n */\n closeOnSelect?: boolean\n /**\n * If `true`, the autocomplete option will be disabled.\n *\n * @default false\n */\n disabled?: boolean\n /**\n * If `true`, the autocomplete option will be focusable.\n *\n * @default false\n */\n focusable?: boolean\n /**\n * If `true`, the autocomplete option will be disabled.\n *\n * @default false\n *\n * @deprecated Use `disabled` instead.\n */\n isDisabled?: boolean\n /**\n * If `true`, the autocomplete option will be focusable.\n *\n * @default false\n *\n * @deprecated Use `focusable` instead.\n */\n isFocusable?: boolean\n /**\n * The value of the autocomplete option.\n */\n value?: string\n}\n\nexport const useAutocompleteOption = (props: UseAutocompleteOptionProps) => {\n const {\n closeOnSelect,\n focusedIndex,\n inputRef,\n omitSelectedValues,\n setFocusedIndex,\n value,\n optionProps,\n onChange,\n onClose,\n onFocusNext,\n } = useAutocompleteContext()\n const uuid = useId()\n const itemRef = useRef<HTMLLIElement>(null)\n let {\n id,\n children,\n closeOnSelect: customCloseOnSelect,\n disabled,\n focusable,\n icon: customIcon,\n isDisabled,\n isFocusable,\n value: optionValue,\n ...computedProps\n } = { ...optionProps, ...props }\n disabled ??= isDisabled\n focusable ??= isFocusable\n const trulyDisabled = !!disabled && !focusable\n const { descendants, index, register } = useAutocompleteDescendant({\n disabled: trulyDisabled,\n })\n const values = descendants.values()\n const frontValues = values.slice(0, index)\n const isMulti = isArray(value)\n const isDuplicated = frontValues.some(\n ({ node }) => node.dataset.value === (optionValue ?? \"\"),\n )\n const isSelected =\n !isDuplicated &&\n (!isMulti\n ? (optionValue ?? \"\") === value\n : value.includes(optionValue ?? \"\"))\n const isTarget = \"target\" in (itemRef.current?.dataset ?? {})\n const isFocused = index === focusedIndex\n\n id ??= uuid\n\n if (isUndefined(optionValue)) {\n if (isString(children) || isNumber(children)) {\n optionValue = children.toString()\n } else {\n console.warn(\n `${\n !isMulti ? \"Autocomplete\" : \"MultiAutocomplete\"\n }: Cannot infer the option value of complex children. Pass a \\`value\\` prop or use a plain string as children to <Option>.`,\n )\n }\n }\n\n const onClick = useCallback(\n (ev: MouseEvent<HTMLDivElement>) => {\n ev.stopPropagation()\n\n if (disabled || !isTargetOption(ev.currentTarget)) {\n if (inputRef.current) inputRef.current.focus()\n\n return\n }\n\n if (!isDuplicated) setFocusedIndex(index)\n\n onChange(optionValue ?? \"\")\n\n if (inputRef.current) inputRef.current.focus()\n\n if (customCloseOnSelect ?? closeOnSelect) onClose()\n\n if (omitSelectedValues) onFocusNext(index)\n },\n [\n isDuplicated,\n onFocusNext,\n omitSelectedValues,\n disabled,\n optionValue,\n setFocusedIndex,\n index,\n onChange,\n customCloseOnSelect,\n closeOnSelect,\n onClose,\n inputRef,\n ],\n )\n\n const getOptionProps: PropGetter = useCallback(\n (props = {}, ref = null) => {\n const isHidden = !isTarget || (omitSelectedValues && isSelected)\n\n const style: CSSProperties = {\n border: \"0px\",\n clip: \"rect(0px, 0px, 0px, 0px)\",\n height: \"1px\",\n margin: \"-1px\",\n overflow: \"hidden\",\n padding: \"0px\",\n position: \"absolute\",\n whiteSpace: \"nowrap\",\n width: \"1px\",\n }\n\n return {\n ref: mergeRefs(itemRef, ref, register),\n role: \"option\",\n ...computedProps,\n ...props,\n id,\n style: isHidden ? style : undefined,\n \"aria-disabled\": ariaAttr(disabled),\n \"aria-hidden\": ariaAttr(isHidden),\n \"aria-selected\": isSelected,\n \"data-disabled\": dataAttr(disabled),\n \"data-duplicated\": dataAttr(isDuplicated),\n \"data-focus\": dataAttr(isFocused),\n \"data-target\": dataAttr(true),\n \"data-value\": optionValue ?? \"\",\n tabIndex: -1,\n onClick: handlerAll(computedProps.onClick, props.onClick, onClick),\n }\n },\n [\n id,\n isDuplicated,\n optionValue,\n computedProps,\n disabled,\n isFocused,\n isSelected,\n isTarget,\n omitSelectedValues,\n onClick,\n register,\n ],\n )\n\n return {\n children,\n customIcon,\n isFocused,\n isSelected,\n isTarget,\n omitSelectedValues,\n getOptionProps,\n }\n}\n\nexport type UseAutocompleteOptionReturn = ReturnType<\n typeof useAutocompleteOption\n>\n\nexport const useAutocompleteCreate = () => {\n const { isHit, onCreate } = useAutocompleteContext()\n\n const getCreateProps: PropGetter = useCallback(\n (props = {}, ref = null) => {\n const style: CSSProperties = {\n border: \"0px\",\n clip: \"rect(0px, 0px, 0px, 0px)\",\n height: \"1px\",\n margin: \"-1px\",\n overflow: \"hidden\",\n padding: \"0px\",\n position: \"absolute\",\n whiteSpace: \"nowrap\",\n width: \"1px\",\n }\n\n return {\n ref,\n role: \"option\",\n ...props,\n style: isHit ? style : undefined,\n \"aria-hidden\": ariaAttr(isHit),\n \"data-focus\": dataAttr(!isHit),\n tabIndex: -1,\n onClick: handlerAll(props.onClick, onCreate),\n }\n },\n [isHit, onCreate],\n )\n\n return { getCreateProps }\n}\n\nexport type UseAutocompleteCreateReturn = ReturnType<\n typeof useAutocompleteCreate\n>\n\nexport const useAutocompleteEmpty = () => {\n const { isEmpty, isHit } = useAutocompleteContext()\n\n const getEmptyProps: PropGetter = useCallback(\n (props = {}, ref = null) => {\n const isHidden = isHit && !isEmpty\n\n const style: CSSProperties = {\n border: \"0px\",\n clip: \"rect(0px, 0px, 0px, 0px)\",\n height: \"1px\",\n margin: \"-1px\",\n overflow: \"hidden\",\n padding: \"0px\",\n position: \"absolute\",\n whiteSpace: \"nowrap\",\n width: \"1px\",\n }\n\n return {\n ref,\n role: \"presentation\",\n ...props,\n style: isHidden ? style : undefined,\n \"aria-hidden\": ariaAttr(isHidden),\n tabIndex: -1,\n }\n },\n [isHit, isEmpty],\n )\n\n return { getEmptyProps }\n}\n\nexport type UseAutocompleteEmptyReturn = ReturnType<typeof useAutocompleteEmpty>\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,IAAAA,eAA+B;AAC/B,IAAAC,gBAAmB;;;ACDnB,4BAAiC;AACjC,mBAA8B;AAEvB,IAAM;AAAA,EACX,4BAA4B;AAAA,EAC5B,eAAe;AAAA,EACf,gBAAgB;AAAA,EAChB,uBAAuB;AAC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ACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF;AACF;;;AHrLM,IAAAC,sBAAA;AAvBC,IAAM,yBAAqB;AAAA,EAChC,CAAC,EAAE,WAAW,MAAM,GAAG,KAAK,GAAG,QAAQ;AACrC,UAAM,EAAE,OAAO,IAAI,uBAAuB;AAC1C,UAAM,EAAE,UAAU,YAAY,YAAY,eAAe,IACvD,sBAAsB,IAAI;AAE5B,iCAAS;AAET,UAAM,MAAmB;AAAA,MACvB,YAAY;AAAA,MACZ,OAAO;AAAA,MACP,SAAS;AAAA,MACT,MAAM;AAAA,MACN,KAAK;AAAA,MACL,SAAS;AAAA,MACT,WAAW;AAAA,MACX,gBAAgB;AAAA,MAChB,YAAY;AAAA,MACZ,OAAO;AAAA,MACP,GAAG,OAAO;AAAA,IACZ;AAEA,WACE;AAAA,MAAC,gBAAG;AAAA,MAAH;AAAA,QACC,eAAW,kBAAG,yBAAyB,SAAS;AAAA,QAChD,OAAO;AAAA,QACN,GAAG,eAAe,CAAC,GAAG,GAAG;AAAA,QAEzB;AAAA,mBAAS,OACR,6CAAC,wBAAqB,SAAS,aAAa,IAAI,GAC7C,kBAAQ,6CAAC,yBAAsB,GAClC,IACE;AAAA,UAEJ,6CAAC,gBAAG,MAAH,EAAQ,OAAO,EAAE,MAAM,EAAE,GAAG,cAAU,MACpC,UACH;AAAA;AAAA;AAAA,IACF;AAAA,EAEJ;AACF;AAEA,mBAAmB,cAAc;AACjC,mBAAmB,SAAS;AAE5B,IAAM,wBAA4B,MAChC,6CAAC,SAAI,QAAO,OAAM,SAAQ,aAAY,OAAM,OAC1C;AAAA,EAAC;AAAA;AAAA,IACC,MAAK;AAAA,IACL,QAAO;AAAA;AACT,GACF;AAGF,sBAAsB,cAAc;AACpC,sBAAsB,SAAS;","names":["import_core","import_utils","import_utils","import_utils","import_react","props","import_jsx_runtime"]}
|
@@ -1,10 +1,10 @@
|
|
1
1
|
"use client"
|
2
2
|
import {
|
3
3
|
AutocompleteOption
|
4
|
-
} from "./chunk-
|
5
|
-
import "./chunk-
|
6
|
-
import "./chunk-
|
7
|
-
import "./chunk-
|
4
|
+
} from "./chunk-PWV7X7G6.mjs";
|
5
|
+
import "./chunk-2LP57WVB.mjs";
|
6
|
+
import "./chunk-7QCZ5NGS.mjs";
|
7
|
+
import "./chunk-TP5VZFO3.mjs";
|
8
8
|
export {
|
9
9
|
AutocompleteOption
|
10
10
|
};
|
package/dist/autocomplete.js
CHANGED
@@ -453,9 +453,9 @@ var import_utils7 = require("@yamada-ui/utils");
|
|
453
453
|
var import_utils6 = require("@yamada-ui/utils");
|
454
454
|
var import_react3 = require("react");
|
455
455
|
var useAutocompleteList = () => {
|
456
|
-
const { focusedIndex, isOpen,
|
456
|
+
const { focusedIndex, isOpen, rebirthOptions, value } = useAutocompleteContext();
|
457
457
|
const descendants = useAutocompleteDescendantsContext();
|
458
|
-
const
|
458
|
+
const listRef = (0, import_react3.useRef)(null);
|
459
459
|
const beforeFocusedIndex = (0, import_react3.useRef)(-1);
|
460
460
|
const selectedValue = descendants.value(focusedIndex);
|
461
461
|
const isMulti = (0, import_utils6.isArray)(value);
|
@@ -491,21 +491,31 @@ var useAutocompleteList = () => {
|
|
491
491
|
(0, import_utils6.useUpdateEffect)(() => {
|
492
492
|
if (!isOpen) beforeFocusedIndex.current = -1;
|
493
493
|
}, [isOpen]);
|
494
|
+
const getContainerProps = (0, import_react3.useCallback)(
|
495
|
+
(props = {}, ref = null) => ({
|
496
|
+
ref,
|
497
|
+
"aria-multiselectable": (0, import_utils6.ariaAttr)(isMulti),
|
498
|
+
role: "listbox",
|
499
|
+
...props,
|
500
|
+
onAnimationComplete: (0, import_utils6.handlerAll)(
|
501
|
+
props.onAnimationComplete,
|
502
|
+
onAnimationComplete
|
503
|
+
)
|
504
|
+
}),
|
505
|
+
[isMulti, onAnimationComplete]
|
506
|
+
);
|
494
507
|
const getListProps = (0, import_react3.useCallback)(
|
495
|
-
(
|
496
|
-
id: id != null ? id : uuid,
|
508
|
+
(props = {}, ref = null) => ({
|
497
509
|
ref: (0, import_utils6.mergeRefs)(listRef, ref),
|
498
|
-
"aria-multiselectable": (0, import_utils6.ariaAttr)(isMulti),
|
499
510
|
position: "relative",
|
500
|
-
role: "listbox",
|
501
511
|
tabIndex: -1,
|
502
512
|
...props
|
503
513
|
}),
|
504
|
-
[listRef
|
514
|
+
[listRef]
|
505
515
|
);
|
506
516
|
return {
|
507
|
-
|
508
|
-
|
517
|
+
getContainerProps,
|
518
|
+
getListProps
|
509
519
|
};
|
510
520
|
};
|
511
521
|
|
@@ -528,7 +538,7 @@ var AutocompleteList = (0, import_core4.forwardRef)(
|
|
528
538
|
}, ref) => {
|
529
539
|
var _a, _b, _c, _d, _e, _f, _g, _h, _i;
|
530
540
|
const { styles } = useAutocompleteContext();
|
531
|
-
const {
|
541
|
+
const { getContainerProps, getListProps } = useAutocompleteList();
|
532
542
|
width != null ? width : width = w;
|
533
543
|
width != null ? width : width = (_c = (_a = styles.list) == null ? void 0 : _a.width) != null ? _c : (_b = styles.list) == null ? void 0 : _b.w;
|
534
544
|
minWidth != null ? minWidth : minWidth = minW;
|
@@ -538,16 +548,13 @@ var AutocompleteList = (0, import_core4.forwardRef)(
|
|
538
548
|
return /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(
|
539
549
|
import_popover.PopoverContent,
|
540
550
|
{
|
551
|
+
as: "div",
|
541
552
|
className: "ui-autocomplete__popover",
|
542
553
|
maxWidth,
|
543
554
|
minWidth,
|
544
555
|
width,
|
545
556
|
__css: { ...styles.content, maxWidth, minWidth, width },
|
546
|
-
...contentProps,
|
547
|
-
onAnimationComplete: (0, import_utils7.handlerAll)(
|
548
|
-
contentProps == null ? void 0 : contentProps.onAnimationComplete,
|
549
|
-
onAnimationComplete
|
550
|
-
),
|
557
|
+
...getContainerProps(contentProps),
|
551
558
|
children: [
|
552
559
|
header ? /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
|
553
560
|
import_core4.ui.header,
|
@@ -899,6 +906,7 @@ var flattenItems = (items) => {
|
|
899
906
|
return filterItems(items).flat(Infinity);
|
900
907
|
};
|
901
908
|
var useAutocomplete = (props) => {
|
909
|
+
var _a;
|
902
910
|
const {
|
903
911
|
allowCreate = false,
|
904
912
|
allowFree = false,
|
@@ -942,16 +950,8 @@ var useAutocomplete = (props) => {
|
|
942
950
|
onSearch: onSearchProp,
|
943
951
|
...rest
|
944
952
|
} = (0, import_form_control.useFormControlProps)(props);
|
945
|
-
const {
|
946
|
-
"aria-readonly": _ariaReadonly,
|
947
|
-
onFocus: onFocusProp,
|
948
|
-
...formControlProps
|
949
|
-
} = (0, import_utils11.pickObject)(rest, import_form_control.formControlProperties);
|
950
|
-
const [containerProps, inputProps] = (0, import_utils11.splitObject)(rest, import_core8.layoutStyleProperties);
|
951
|
-
const { id } = rest;
|
952
953
|
const descendants = useAutocompleteDescendants();
|
953
954
|
const containerRef = (0, import_react5.useRef)(null);
|
954
|
-
const listRef = (0, import_react5.useRef)(null);
|
955
955
|
const inputRef = (0, import_react5.useRef)(null);
|
956
956
|
const timeoutIds = (0, import_react5.useRef)(/* @__PURE__ */ new Set([]));
|
957
957
|
const isComposition = (0, import_react5.useRef)(false);
|
@@ -977,6 +977,12 @@ var useAutocomplete = (props) => {
|
|
977
977
|
onClose: onCloseProp,
|
978
978
|
onOpen: onOpenProp
|
979
979
|
});
|
980
|
+
const {
|
981
|
+
"aria-readonly": _ariaReadonly,
|
982
|
+
onFocus: onFocusProp,
|
983
|
+
...formControlProps
|
984
|
+
} = (0, import_utils11.pickObject)(rest, import_form_control.formControlProperties);
|
985
|
+
const [containerProps, inputProps] = (0, import_utils11.splitObject)(rest, import_core8.layoutStyleProperties);
|
980
986
|
const isFocused = focusedIndex > -1;
|
981
987
|
const isCreate = focusedIndex === -2 && allowCreate;
|
982
988
|
const isMulti = (0, import_utils11.isArray)(value);
|
@@ -995,14 +1001,15 @@ var useAutocomplete = (props) => {
|
|
995
1001
|
}
|
996
1002
|
const selectedValues = descendants.enabledValues(
|
997
1003
|
({ node }) => {
|
998
|
-
var
|
999
|
-
return isMulti && value.includes((
|
1004
|
+
var _a2;
|
1005
|
+
return isMulti && value.includes((_a2 = node.dataset.value) != null ? _a2 : "");
|
1000
1006
|
}
|
1001
1007
|
);
|
1002
1008
|
const selectedIndexes = selectedValues.map(({ index }) => index);
|
1003
1009
|
const enabledValues = descendants.enabledValues(
|
1004
1010
|
({ index, node }) => "target" in node.dataset && !selectedIndexes.includes(index)
|
1005
1011
|
);
|
1012
|
+
const activedescendantId = (_a = descendants.value(focusedIndex)) == null ? void 0 : _a.node.id;
|
1006
1013
|
const validChildren = (0, import_utils11.getValidChildren)(children);
|
1007
1014
|
const computedChildren = (0, import_react5.useMemo)(
|
1008
1015
|
() => resolvedItems == null ? void 0 : resolvedItems.map((item, index) => {
|
@@ -1032,8 +1039,8 @@ var useAutocomplete = (props) => {
|
|
1032
1039
|
if (inputRef.current) inputRef.current.focus();
|
1033
1040
|
}, [allowCreate, formControlProps, isAllSelected, isEmpty, onInternalOpen]);
|
1034
1041
|
const onFocusFirst = (0, import_react5.useCallback)(() => {
|
1035
|
-
const
|
1036
|
-
var
|
1042
|
+
const id = setTimeout(() => {
|
1043
|
+
var _a2;
|
1037
1044
|
if (isEmpty || isAllSelected) return;
|
1038
1045
|
const first = descendants.enabledFirstValue(
|
1039
1046
|
({ node }) => "target" in node.dataset
|
@@ -1044,13 +1051,13 @@ var useAutocomplete = (props) => {
|
|
1044
1051
|
} else {
|
1045
1052
|
if (selectedIndexes.includes(first.index)) {
|
1046
1053
|
const enabledFirst = enabledValues[0];
|
1047
|
-
setFocusedIndex((
|
1054
|
+
setFocusedIndex((_a2 = enabledFirst == null ? void 0 : enabledFirst.index) != null ? _a2 : -1);
|
1048
1055
|
} else {
|
1049
1056
|
setFocusedIndex(first.index);
|
1050
1057
|
}
|
1051
1058
|
}
|
1052
1059
|
});
|
1053
|
-
timeoutIds.current.add(
|
1060
|
+
timeoutIds.current.add(id);
|
1054
1061
|
}, [
|
1055
1062
|
descendants,
|
1056
1063
|
enabledValues,
|
@@ -1061,8 +1068,8 @@ var useAutocomplete = (props) => {
|
|
1061
1068
|
selectedIndexes
|
1062
1069
|
]);
|
1063
1070
|
const onFocusLast = (0, import_react5.useCallback)(() => {
|
1064
|
-
const
|
1065
|
-
var
|
1071
|
+
const id = setTimeout(() => {
|
1072
|
+
var _a2;
|
1066
1073
|
if (isEmpty || isAllSelected) return;
|
1067
1074
|
const last = descendants.enabledLastValue(
|
1068
1075
|
({ node }) => "target" in node.dataset
|
@@ -1073,13 +1080,13 @@ var useAutocomplete = (props) => {
|
|
1073
1080
|
} else {
|
1074
1081
|
if (selectedIndexes.includes(last.index)) {
|
1075
1082
|
const enabledLast = enabledValues.reverse()[0];
|
1076
|
-
setFocusedIndex((
|
1083
|
+
setFocusedIndex((_a2 = enabledLast == null ? void 0 : enabledLast.index) != null ? _a2 : -1);
|
1077
1084
|
} else {
|
1078
1085
|
setFocusedIndex(last.index);
|
1079
1086
|
}
|
1080
1087
|
}
|
1081
1088
|
});
|
1082
|
-
timeoutIds.current.add(
|
1089
|
+
timeoutIds.current.add(id);
|
1083
1090
|
}, [
|
1084
1091
|
descendants,
|
1085
1092
|
enabledValues,
|
@@ -1090,22 +1097,22 @@ var useAutocomplete = (props) => {
|
|
1090
1097
|
selectedIndexes
|
1091
1098
|
]);
|
1092
1099
|
const onFocusSelected = (0, import_react5.useCallback)(() => {
|
1093
|
-
const
|
1100
|
+
const id = setTimeout(() => {
|
1094
1101
|
const values = descendants.enabledValues();
|
1095
1102
|
const selected = values.find(
|
1096
1103
|
({ node }) => {
|
1097
|
-
var
|
1098
|
-
return !isMulti ? node.dataset.value === value : value.includes((
|
1104
|
+
var _a2;
|
1105
|
+
return !isMulti ? node.dataset.value === value : value.includes((_a2 = node.dataset.value) != null ? _a2 : "");
|
1099
1106
|
}
|
1100
1107
|
);
|
1101
1108
|
if (selected) setFocusedIndex(selected.index);
|
1102
1109
|
});
|
1103
|
-
timeoutIds.current.add(
|
1110
|
+
timeoutIds.current.add(id);
|
1104
1111
|
}, [descendants, isMulti, value]);
|
1105
1112
|
const onFocusNext = (0, import_react5.useCallback)(
|
1106
1113
|
(index = focusedIndex) => {
|
1107
|
-
const
|
1108
|
-
var
|
1114
|
+
const id = setTimeout(() => {
|
1115
|
+
var _a2, _b;
|
1109
1116
|
const next = descendants.enabledNextValue(
|
1110
1117
|
index,
|
1111
1118
|
({ node }) => "target" in node.dataset
|
@@ -1115,14 +1122,14 @@ var useAutocomplete = (props) => {
|
|
1115
1122
|
setFocusedIndex(next.index);
|
1116
1123
|
} else {
|
1117
1124
|
if (selectedIndexes.includes(next.index)) {
|
1118
|
-
const enabledNext = (
|
1125
|
+
const enabledNext = (_a2 = enabledValues.find(({ index: index2 }) => next.index < index2)) != null ? _a2 : enabledValues[0];
|
1119
1126
|
setFocusedIndex((_b = enabledNext == null ? void 0 : enabledNext.index) != null ? _b : -1);
|
1120
1127
|
} else {
|
1121
1128
|
setFocusedIndex(next.index);
|
1122
1129
|
}
|
1123
1130
|
}
|
1124
1131
|
});
|
1125
|
-
timeoutIds.current.add(
|
1132
|
+
timeoutIds.current.add(id);
|
1126
1133
|
},
|
1127
1134
|
[
|
1128
1135
|
descendants,
|
@@ -1135,8 +1142,8 @@ var useAutocomplete = (props) => {
|
|
1135
1142
|
);
|
1136
1143
|
const onFocusPrev = (0, import_react5.useCallback)(
|
1137
1144
|
(index = focusedIndex) => {
|
1138
|
-
const
|
1139
|
-
var
|
1145
|
+
const id = setTimeout(() => {
|
1146
|
+
var _a2, _b;
|
1140
1147
|
const prev = descendants.enabledPrevValue(
|
1141
1148
|
index,
|
1142
1149
|
({ node }) => "target" in node.dataset
|
@@ -1146,14 +1153,14 @@ var useAutocomplete = (props) => {
|
|
1146
1153
|
setFocusedIndex(prev.index);
|
1147
1154
|
} else {
|
1148
1155
|
if (selectedIndexes.includes(prev.index)) {
|
1149
|
-
const enabledPrev = (
|
1156
|
+
const enabledPrev = (_a2 = enabledValues.reverse().find(({ index: index2 }) => index2 < prev.index)) != null ? _a2 : enabledValues[0];
|
1150
1157
|
setFocusedIndex((_b = enabledPrev == null ? void 0 : enabledPrev.index) != null ? _b : -1);
|
1151
1158
|
} else {
|
1152
1159
|
setFocusedIndex(prev.index);
|
1153
1160
|
}
|
1154
1161
|
}
|
1155
1162
|
});
|
1156
|
-
timeoutIds.current.add(
|
1163
|
+
timeoutIds.current.add(id);
|
1157
1164
|
},
|
1158
1165
|
[
|
1159
1166
|
descendants,
|
@@ -1172,8 +1179,8 @@ var useAutocomplete = (props) => {
|
|
1172
1179
|
let isHit2 = false;
|
1173
1180
|
let isFocused2 = false;
|
1174
1181
|
values.forEach(({ index, node }) => {
|
1175
|
-
var
|
1176
|
-
if (format((
|
1182
|
+
var _a2;
|
1183
|
+
if (format((_a2 = node.textContent) != null ? _a2 : "").includes(value2)) {
|
1177
1184
|
isHit2 = true;
|
1178
1185
|
const isDisabled = "disabled" in node.dataset;
|
1179
1186
|
node.dataset.target = "";
|
@@ -1206,8 +1213,8 @@ var useAutocomplete = (props) => {
|
|
1206
1213
|
if (!values.length) return;
|
1207
1214
|
const resolvedValues = (0, import_utils11.isArray)(newValue) ? newValue : [newValue];
|
1208
1215
|
const selectedLabel = resolvedValues.map((value2) => {
|
1209
|
-
var
|
1210
|
-
const { node } = (
|
1216
|
+
var _a2, _b;
|
1217
|
+
const { node } = (_a2 = values.find(({ node: node2 }) => node2.dataset.value === value2)) != null ? _a2 : {};
|
1211
1218
|
if (node) {
|
1212
1219
|
const { textContent } = (_b = Array.from(node.children).find(
|
1213
1220
|
(child) => child.getAttribute("data-label") !== null
|
@@ -1244,9 +1251,9 @@ var useAutocomplete = (props) => {
|
|
1244
1251
|
[isMulti, rebirthOptions, setValue]
|
1245
1252
|
);
|
1246
1253
|
const onSelect = (0, import_react5.useCallback)(() => {
|
1247
|
-
var
|
1254
|
+
var _a2, _b;
|
1248
1255
|
let enabledValue = descendants.value(focusedIndex);
|
1249
|
-
if ("disabled" in ((
|
1256
|
+
if ("disabled" in ((_a2 = enabledValue == null ? void 0 : enabledValue.node.dataset) != null ? _a2 : {}))
|
1250
1257
|
enabledValue = void 0;
|
1251
1258
|
if (!enabledValue) return;
|
1252
1259
|
const value2 = (_b = enabledValue.node.dataset.value) != null ? _b : "";
|
@@ -1284,8 +1291,7 @@ var useAutocomplete = (props) => {
|
|
1284
1291
|
isComposition.current = false;
|
1285
1292
|
}, []);
|
1286
1293
|
const onCreate = (0, import_react5.useCallback)(() => {
|
1287
|
-
var
|
1288
|
-
if (!listRef.current) return;
|
1294
|
+
var _a2, _b;
|
1289
1295
|
const newItem = { label: inputValue, value: inputValue };
|
1290
1296
|
let newItems = [];
|
1291
1297
|
if (resolvedItems) newItems = [...resolvedItems];
|
@@ -1300,7 +1306,7 @@ var useAutocomplete = (props) => {
|
|
1300
1306
|
const targetItem = newItems[i];
|
1301
1307
|
if (i !== -1 && targetItem && "items" in targetItem) {
|
1302
1308
|
if (secondInsertPositionItem === "first") {
|
1303
|
-
targetItem.items = [newItem, ...(
|
1309
|
+
targetItem.items = [newItem, ...(_a2 = targetItem.items) != null ? _a2 : []];
|
1304
1310
|
} else {
|
1305
1311
|
targetItem.items = [...(_b = targetItem.items) != null ? _b : [], newItem];
|
1306
1312
|
}
|
@@ -1457,7 +1463,7 @@ var useAutocomplete = (props) => {
|
|
1457
1463
|
setResolvedItems(items ? JSON.parse(JSON.stringify(items)) : void 0);
|
1458
1464
|
}, [items]);
|
1459
1465
|
(0, import_utils11.useUnmountEffect)(() => {
|
1460
|
-
timeoutIds.current.forEach((
|
1466
|
+
timeoutIds.current.forEach((id) => clearTimeout(id));
|
1461
1467
|
timeoutIds.current.clear();
|
1462
1468
|
});
|
1463
1469
|
(0, import_use_outside_click.useOutsideClick)({
|
@@ -1528,6 +1534,10 @@ var useAutocomplete = (props) => {
|
|
1528
1534
|
const getFieldProps = (0, import_react5.useCallback)(
|
1529
1535
|
(props2 = {}, ref = null) => ({
|
1530
1536
|
ref,
|
1537
|
+
"aria-activedescendant": activedescendantId,
|
1538
|
+
"aria-autocomplete": "list",
|
1539
|
+
"aria-haspopup": "listbox",
|
1540
|
+
role: "combobox",
|
1531
1541
|
tabIndex: -1,
|
1532
1542
|
...props2,
|
1533
1543
|
...formControlProps,
|
@@ -1537,6 +1547,7 @@ var useAutocomplete = (props) => {
|
|
1537
1547
|
onKeyDown: (0, import_utils11.handlerAll)(props2.onKeyDown, onKeyDownProp, onKeyDown)
|
1538
1548
|
}),
|
1539
1549
|
[
|
1550
|
+
activedescendantId,
|
1540
1551
|
formControlProps,
|
1541
1552
|
placeholder,
|
1542
1553
|
isOpen,
|
@@ -1547,7 +1558,6 @@ var useAutocomplete = (props) => {
|
|
1547
1558
|
]
|
1548
1559
|
);
|
1549
1560
|
return {
|
1550
|
-
id,
|
1551
1561
|
allowCreate,
|
1552
1562
|
allowFree,
|
1553
1563
|
children: children != null ? children : computedChildren,
|
@@ -1562,7 +1572,6 @@ var useAutocomplete = (props) => {
|
|
1562
1572
|
isHit,
|
1563
1573
|
isOpen,
|
1564
1574
|
label,
|
1565
|
-
listRef,
|
1566
1575
|
omitSelectedValues,
|
1567
1576
|
pickOptions,
|
1568
1577
|
rebirthOptions,
|
@@ -1590,23 +1599,15 @@ var useAutocomplete = (props) => {
|
|
1590
1599
|
};
|
1591
1600
|
};
|
1592
1601
|
var useAutocompleteInput = () => {
|
1593
|
-
var _a, _b;
|
1594
1602
|
const {
|
1595
|
-
id,
|
1596
|
-
focusedIndex,
|
1597
1603
|
inputRef,
|
1598
1604
|
isAllSelected,
|
1599
|
-
isOpen,
|
1600
|
-
listRef,
|
1601
1605
|
formControlProps,
|
1602
1606
|
inputProps,
|
1603
1607
|
onCompositionEnd,
|
1604
1608
|
onCompositionStart,
|
1605
1609
|
onSearch
|
1606
1610
|
} = useAutocompleteContext();
|
1607
|
-
const descendants = useAutocompleteDescendantsContext();
|
1608
|
-
const activedescendantId = (_a = descendants.value(focusedIndex)) == null ? void 0 : _a.node.id;
|
1609
|
-
const listId = (_b = listRef.current) == null ? void 0 : _b.id;
|
1610
1611
|
(0, import_utils11.useUpdateEffect)(() => {
|
1611
1612
|
if (isAllSelected && inputRef.current) inputRef.current.blur();
|
1612
1613
|
}, [isAllSelected]);
|
@@ -1615,19 +1616,12 @@ var useAutocompleteInput = () => {
|
|
1615
1616
|
return {
|
1616
1617
|
ref: (0, import_utils11.mergeRefs)(inputRef, ref),
|
1617
1618
|
...formControlProps,
|
1618
|
-
"aria-activedescendant": activedescendantId,
|
1619
|
-
"aria-autocomplete": "list",
|
1620
|
-
"aria-controls": listId,
|
1621
|
-
"aria-expanded": isOpen,
|
1622
|
-
"aria-haspopup": "listbox",
|
1623
1619
|
autoCapitalize: "none",
|
1624
1620
|
autoComplete: "off",
|
1625
|
-
role: "combobox",
|
1626
1621
|
spellCheck: "false",
|
1627
1622
|
tabIndex: isAllSelected ? -1 : 0,
|
1628
1623
|
...inputProps,
|
1629
1624
|
...props,
|
1630
|
-
id,
|
1631
1625
|
cursor: formControlProps.readOnly ? "default" : "text",
|
1632
1626
|
pointerEvents: formControlProps.disabled || isAllSelected ? "none" : "auto",
|
1633
1627
|
onChange: (0, import_utils11.handlerAll)(props.onChange, onSearch),
|
@@ -1644,13 +1638,9 @@ var useAutocompleteInput = () => {
|
|
1644
1638
|
};
|
1645
1639
|
},
|
1646
1640
|
[
|
1647
|
-
listId,
|
1648
|
-
activedescendantId,
|
1649
|
-
isOpen,
|
1650
1641
|
inputProps,
|
1651
1642
|
inputRef,
|
1652
1643
|
formControlProps,
|
1653
|
-
id,
|
1654
1644
|
isAllSelected,
|
1655
1645
|
onSearch,
|
1656
1646
|
onCompositionStart,
|