// This file is auto-generated by "@aria-ui/cli". Do not edit this file directly. import { registerBlockHandleRootElement, type BlockHandleRootElement, type BlockHandleRootProps as BlockHandleRootElementProps, type BlockHandleRootEvents } from '@prosekit/web/block-handle'; import { createElement, forwardRef, useCallback, useRef, type ForwardedRef, type ForwardRefExoticComponent, type HTMLAttributes, type RefAttributes, useLayoutEffect } from 'react'; import { useEditorContext } from '../../contexts/editor-context.ts'; /** Props for the {@link BlockHandleRoot} React component. */ export interface BlockHandleRootProps { /** * The ProseKit editor instance. * * @default null * @hidden */ editor?: BlockHandleRootElementProps['editor']; /** Fired when the hovered block changes. */ onStateChange?: (event: BlockHandleRootEvents['stateChange']) => void; } function BlockHandleRootComponent(props: BlockHandleRootProps, forwardedRef: ForwardedRef) { registerBlockHandleRootElement(); const elementRef = useRef(null); const handlersRef = useRef void) | undefined>>([]); const p0Fallback = useEditorContext(); const { editor: p0, onStateChange: e0, ...restProps } = props; useLayoutEffect(() => { const element = elementRef.current as Record | null; if (!element) return; Object.assign(element, { editor: p0 ?? p0Fallback }); 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 ['stateChange'].entries()) { element.addEventListener( eventName, (event: Event) => { handlersRef.current[index]?.(event); }, { signal: ac.signal }, ); } return () => ac.abort(); }, []); const mergedRef = useCallback( (element: BlockHandleRootElement | null) => { elementRef.current = element; if (typeof forwardedRef === 'function') { forwardedRef(element); } else if (forwardedRef) { forwardedRef.current = element; } }, [forwardedRef], ); return createElement('prosekit-block-handle-root', { ...restProps, ref: mergedRef, suppressHydrationWarning: true }); } /** A React component that renders an `prosekit-block-handle-root` custom element. */ export const BlockHandleRoot: ForwardRefExoticComponent & RefAttributes> = /* @__PURE__ */ forwardRef(BlockHandleRootComponent);