// This file is auto-generated by "@aria-ui/cli". Do not edit this file directly. import { registerMenuItemElement, type MenuItemElement, type MenuItemProps as MenuItemElementProps, type MenuItemEvents } from '@prosekit/web/menu'; import { createElement, forwardRef, useCallback, useRef, type ForwardedRef, type ForwardRefExoticComponent, type HTMLAttributes, type RefAttributes, useLayoutEffect } from 'react'; /** Props for the {@link MenuItem} React component. */ export interface MenuItemProps { /** * The unique value for this menu item. * * @default "" */ value?: MenuItemElementProps['value']; /** * Whether this menu item is disabled. * * @default false */ disabled?: MenuItemElementProps['disabled']; /** * Whether to close the menu when the item is pressed. * * @default true */ closeOnSelect?: MenuItemElementProps['closeOnSelect']; /** Emitted when the the item is selected. */ onSelect?: (event: MenuItemEvents['select']) => void; } function MenuItemComponent(props: MenuItemProps, forwardedRef: ForwardedRef) { registerMenuItemElement(); const elementRef = useRef(null); const handlersRef = useRef void) | undefined>>([]); const { closeOnSelect: p0, disabled: p1, value: p2, onSelect: e0, ...restProps } = props; useLayoutEffect(() => { const element = elementRef.current as Record | null; if (!element) return; Object.assign(element, { closeOnSelect: p0, disabled: p1, value: p2 }); handlersRef.current = [e0] as Array<((event: Event) => void) | undefined>; }); useLayoutEffect(() => { const element = elementRef.current; if (!element) return; const ac = new AbortController(); for (const [index, eventName] of ['select'].entries()) { element.addEventListener( eventName, (event: Event) => { handlersRef.current[index]?.(event); }, { signal: ac.signal }, ); } return () => ac.abort(); }, []); const mergedRef = useCallback( (element: MenuItemElement | null) => { elementRef.current = element; if (typeof forwardedRef === 'function') { forwardedRef(element); } else if (forwardedRef) { forwardedRef.current = element; } }, [forwardedRef], ); return createElement('prosekit-menu-item', { ...restProps, ref: mergedRef, suppressHydrationWarning: true }); } /** A React component that renders an `prosekit-menu-item` custom element. */ export const MenuItem: ForwardRefExoticComponent, 'onSelect'> & RefAttributes> = /* @__PURE__ */ forwardRef(MenuItemComponent);