import { EditorNotFoundError, type Editor, type Extension } from '@prosekit/core' import { createEffect, onCleanup, type Accessor } from 'solid-js' import { useEditorContext } from '../contexts/editor-context.ts' import type { MaybeAccessor } from '../types.ts' import { toValue } from '../utils/to-value.ts' /** * @internal */ export function useEditorExtension( editorAccessor: MaybeAccessor | undefined | null, extensionAccessor: Accessor, ): void { const editorContext = useEditorContext() createEffect(() => { const editor = toValue(editorAccessor) || toValue(editorContext) const extension = extensionAccessor() if (!editor) { throw new EditorNotFoundError() } if (extension) { onCleanup(editor.use(extension)) } }) }