// This file is auto-generated by "@aria-ui/cli". Do not edit this file directly. import { registerAutocompleteRootElement, type AutocompleteRootElement, type AutocompleteRootEvents, type AutocompleteRootProps as AutocompleteRootElementProps } from "@prosekit/web/autocomplete"; import { createEffect, createSignal, mergeProps, splitProps } from "solid-js"; import type { Component, JSX } from "solid-js"; import h from "solid-js/h"; import { useEditorContext } from "../../contexts/editor-context.ts"; /** Props for the {@link AutocompleteRoot} Solid component. */ export interface AutocompleteRootProps { /** * The ProseKit editor instance. * * @default null * @hidden */ editor?: AutocompleteRootElementProps['editor']; /** * The regular expression to match the query text to autocomplete. * * @default null */ regex?: AutocompleteRootElementProps['regex']; /** * The filter function to determine if an item should be shown in the * listbox. * * @default defaultItemFilter */ filter?: AutocompleteRootElementProps['filter']; /** * Builds the query string from the regex match found before the cursor. The * query is exposed via the `queryChange` event and used by the built-in item * filter. The default builder lowercases the match and strips punctuation. * Provide a custom builder to control the query, for example to preserve the * casing and punctuation the user typed. * * @default defaultQueryBuilder */ queryBuilder?: AutocompleteRootElementProps['queryBuilder']; /** * The reference to position the popup against. This can be a DOM element, a * Floating UI virtual element, or a function that returns either of them. * By default, the popup will be positioned against the text content that * triggers the autocomplete. * * @default null */ anchor?: AutocompleteRootElementProps['anchor']; /** * Whether the autocomplete match should follow the text cursor when it * moves without editing, growing and shrinking the query as the cursor * moves over existing text (for example with arrow keys). * * @default false */ followCursor?: AutocompleteRootElementProps['followCursor']; /** Fired when the open state changes. */ onOpenChange?: (event: AutocompleteRootEvents['openChange']) => void; /** Fired when the query changes. */ onQueryChange?: (event: AutocompleteRootEvents['queryChange']) => void; /** * Emitted when the selected value changes. Only available when multiple is * false. */ onValueChange?: (event: AutocompleteRootEvents['valueChange']) => void; /** * Emitted when the selected values change. Only available when multiple is * true. */ onValuesChange?: (event: AutocompleteRootEvents['valuesChange']) => void; } /** A Solid component that renders an `prosekit-autocomplete-root` custom element. */ export const AutocompleteRoot: Component> = (props): any => { registerAutocompleteRootElement() const [getElement, setElement] = createSignal(null) const handlers: Array<((event: any) => void) | undefined> = [] const [ elementProps, eventHandlers, restProps ] = splitProps(props, ["anchor","editor","filter","followCursor","queryBuilder","regex"], ["onOpenChange","onQueryChange","onValueChange","onValuesChange"]) const p1Fallback = useEditorContext(); createEffect(() => { const element = getElement() if (!element) return Object.assign(element, { anchor: elementProps.anchor, editor: elementProps.editor ?? p1Fallback, filter: elementProps.filter, followCursor: elementProps.followCursor, queryBuilder: elementProps.queryBuilder, regex: elementProps.regex }) handlers.length = 0 handlers.push(eventHandlers.onOpenChange) handlers.push(eventHandlers.onQueryChange) handlers.push(eventHandlers.onValueChange) handlers.push(eventHandlers.onValuesChange) }) createEffect(() => { const element = getElement() if (!element) return const ac = new AbortController() for (const [index, eventName] of ['openChange', 'queryChange', 'valueChange', 'valuesChange'].entries()) { element.addEventListener(eventName, (event) => { handlers[index]?.(event) }, { signal: ac.signal }) } return () => ac.abort() }) return () => h( 'prosekit-autocomplete-root', mergeProps(restProps, { ref: (el: AutocompleteRootElement | null ) => { setElement(el) }, }), ) };