diff --git a/src/MDXEditor.tsx b/src/MDXEditor.tsx index 4b4de82..92ea11c 100644 --- a/src/MDXEditor.tsx +++ b/src/MDXEditor.tsx @@ -17,7 +17,8 @@ import { setMarkdown$, topAreaChildren$, useTranslation, - viewMode$ + viewMode$, + contentEditableRef$ } from './plugins/core' import { ContentEditable } from '@lexical/react/LexicalContentEditable.js' @@ -45,6 +46,11 @@ const LexicalProvider: React.FC<{ const RichTextEditor: React.FC = () => { const t = useTranslation() + const setContentEditableRef = usePublisher(contentEditableRef$) + const onRef = (_contentEditableRef: HTMLDivElement) => { + setContentEditableRef({ current: _contentEditableRef }) + } + const [contentEditableClassName, spellCheck, composerChildren, topAreaChildren, editorWrappers, placeholder] = useCellValues( contentEditableClassName$, spellCheck$, @@ -62,11 +68,13 @@ const RichTextEditor: React.FC = () => {
+
+ +
} placeholder={
diff --git a/src/plugins/core/index.ts b/src/plugins/core/index.ts index 882ace2..85ce3be 100644 --- a/src/plugins/core/index.ts +++ b/src/plugins/core/index.ts @@ -293,6 +293,12 @@ export const codeBlockEditorDescriptors$ = Cell([]) */ export const editorRootElementRef$ = Cell | null>(null) +/** + * A reference to the content editable element. + * @group Core + */ +export const contentEditableRef$ = Cell | null>(null) + /** * Registers a lexical node to be used in the editor. * @group Core