import { Replace } from '@remirror/core'; import type { MentionExtensionAttributes } from '@remirror/extension-mention'; import { ChangeReason, ExitReason, SuggestChangeHandlerProps } from '@remirror/pm/suggest'; import { MenuNavigationOptions, UseMenuNavigationReturn } from './use-menu-navigation'; export interface MentionState extends Pick { /** * This command when the mention is active. */ command: (item: Data) => void; /** * The reason for the change. */ reason: ChangeReason; } export interface UseMentionReturn extends UseMenuNavigationReturn { state: MentionState | null; } /** * A hook that provides the state for social mentions that responds to * keybindings and key-presses from the user. * * This is used by the `SocialMentionDropdown` component and can be used by you * for a customized component. * * The only prop required is the list of data in order to support keybinding and * properly selecting the index for you. The data must have a `label` and `id` * key. The label is the text that should be shown inside the mention and the * `id` is whatever unique identifier that can be used. * * You can also add other supported attributes which will be added to the * mention node, like `href` and whatever you decide. * * @param list - the list of data from which an index can be calculated. Must * include at least an `id` and a `label`. */ export declare function useMention(props: UseMentionProps): UseMentionReturn; export interface UseMentionProps extends MenuNavigationOptions { /** * The list of data from which an index can be calculated. Must include at * least an `id` and a `label`. */ items: Data[]; /** * This method is called when a user induced exit happens before a mention has * been created. It receives the state, and gives the consumer of this hook * the opportunity to manually create their own mention * * Leave this undefined to ignore exits. * * To enable automatic exit handling. The following will automatically set the * id to be the query and the label to be the full matching text. Extra attrs * like `href` can be added by you to the attrs object parameter. * * ```ts * const mentionState = useMention({ items, onExit(_, command) => command(), }); * ``` */ onExit?: UseMentionExitHandler; /** * Whether matches should be permanently ignored when the user presses escape. * * @defaultValue true */ ignoreMatchesOnDismiss?: boolean; } export type UseMentionExitHandler = (props: OnExitProps, command: (attrs?: Partial) => void) => void; type OnExitProps = Replace, 'command'>, { reason: ExitReason; }>; export {};