/** * Custom override of @wordpress/components autocomplete types. * * Path mapping is required because ReplaceOption is a type alias (not interface), * which cannot be augmented via `declare module`. This file completely replaces * the original types when importing from "@wordpress/components/build-types/autocomplete/types". * * Modified: ReplaceOption.value allows string in addition to RichTextValue, * which is the actual runtime behavior when using custom autocompleters. */ import type { ReactElement } from "react"; import type { RichTextValue } from "@wordpress/rich-text"; export type InsertOption = { action: "insert-at-caret"; value: React.ReactNode; }; export type ReplaceOption = { action: "replace"; value: RichTextValue | string; }; export type OptionCompletion = React.ReactNode | InsertOption | ReplaceOption; type OptionLabel = string | ReactElement | Array; export type KeyedOption = { key: string; value: any; label: OptionLabel; keywords: Array; isDisabled: boolean; }; export type WPCompleter = { name: string; triggerPrefix: string; options: | (( query: string ) => | PromiseLike | readonly TCompleterOption[]) | readonly TCompleterOption[]; getOptionKeywords?: (option: TCompleterOption) => Array; isOptionDisabled?: (option: TCompleterOption) => boolean; getOptionLabel: (option: TCompleterOption) => OptionLabel; allowContext?: (before: string, after: string) => boolean; getOptionCompletion?: ( option: TCompleterOption, query: string ) => OptionCompletion; useItems?: (filterValue: string) => readonly [Array]; isDebounced?: boolean; className?: string; }; type ContentRef = React.RefObject; export type AutocompleterUIProps = { filterValue: string; instanceId: number; listBoxId: string | undefined; className?: string; selectedIndex: number; onChangeOptions: (items: Array) => void; onSelect: (option: KeyedOption) => void; onReset?: () => void; reset: (event: Event) => void; value?: RichTextValue; contentRef: ContentRef; }; export type CancelablePromise = Promise & { canceled?: boolean; }; export type UseAutocompleteProps = { record: RichTextValue & { start: NonNullable; end: NonNullable; }; onChange: (value: RichTextValue) => void; onReplace: (values: RichTextValue[]) => void; completers: Array; contentRef: ContentRef; }; export type AutocompleteProps = UseAutocompleteProps & { children: ( props: Omit, "popover"> ) => React.ReactNode; isSelected: boolean; };