// This file is auto-generated by "@aria-ui/cli". Do not edit this file directly. import { registerAutocompletePopupElement, type AutocompletePopupElement, type AutocompletePopupEvents } 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"; /** Props for the {@link AutocompletePopup} Solid component. */ export interface AutocompletePopupProps { /** * Emitted when the selected value changes. Only available when multiple is * false. */ onValueChange?: (event: AutocompletePopupEvents['valueChange']) => void; /** * Emitted when the selected values change. Only available when multiple is * true. */ onValuesChange?: (event: AutocompletePopupEvents['valuesChange']) => void; } /** A Solid component that renders an `prosekit-autocomplete-popup` custom element. */ export const AutocompletePopup: Component> = (props): any => { registerAutocompletePopupElement() const [getElement, setElement] = createSignal(null) const handlers: Array<((event: any) => void) | undefined> = [] const [ eventHandlers, restProps ] = splitProps(props, ["onValueChange","onValuesChange"]) createEffect(() => { const element = getElement() if (!element) return handlers.length = 0 handlers.push(eventHandlers.onValueChange) handlers.push(eventHandlers.onValuesChange) }) createEffect(() => { const element = getElement() if (!element) return const ac = new AbortController() for (const [index, eventName] of ['valueChange', 'valuesChange'].entries()) { element.addEventListener(eventName, (event) => { handlers[index]?.(event) }, { signal: ac.signal }) } return () => ac.abort() }) return () => h( 'prosekit-autocomplete-popup', mergeProps(restProps, { ref: (el: AutocompletePopupElement | null ) => { setElement(el) }, }), ) };