// This file is auto-generated by "@aria-ui/cli". Do not edit this file directly. import { registerAutocompleteItemElement, type AutocompleteItemElement, type AutocompleteItemEvents, type AutocompleteItemProps as AutocompleteItemElementProps } 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 AutocompleteItem} Solid component. */ export interface AutocompleteItemProps { /** * The value of the item, which will be matched against the query. * * If not provided, the value is the item's text content. * * @default "" */ value?: AutocompleteItemElementProps['value']; /** * Whether this option is disabled. * * @default false */ disabled?: AutocompleteItemElementProps['disabled']; /** Emitted when the the item is selected. */ onSelect?: (event: AutocompleteItemEvents['select']) => void; } /** A Solid component that renders an `prosekit-autocomplete-item` custom element. */ export const AutocompleteItem: Component> = (props): any => { registerAutocompleteItemElement() const [getElement, setElement] = createSignal(null) const handlers: Array<((event: any) => void) | undefined> = [] const [ elementProps, eventHandlers, restProps ] = splitProps(props, ["disabled","value"], ["onSelect"]) createEffect(() => { const element = getElement() if (!element) return Object.assign(element, { disabled: elementProps.disabled, value: elementProps.value }) handlers.length = 0 handlers.push(eventHandlers.onSelect) }) createEffect(() => { const element = getElement() if (!element) return const ac = new AbortController() for (const [index, eventName] of ['select'].entries()) { element.addEventListener(eventName, (event) => { handlers[index]?.(event) }, { signal: ac.signal }) } return () => ac.abort() }) return () => h( 'prosekit-autocomplete-item', mergeProps(restProps, { ref: (el: AutocompleteItemElement | null ) => { setElement(el) }, }), ) };