Skip to content

Commit 39e37ce

Browse files
committed
fix: support access to the editor wrapper element
1 parent 87f6894 commit 39e37ce

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

src/MDXEditor.tsx

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ import {
2626
topAreaChildren$,
2727
Translation,
2828
useTranslation,
29-
viewMode$
29+
viewMode$,
30+
editorWrapperElementRef$
3031
} from './plugins/core'
3132
import { RealmPlugin, RealmWithPlugins } from './RealmWithPlugins'
3233

@@ -196,7 +197,9 @@ const EditorRootElement: React.FC<{
196197
overlayContainer?: HTMLElement | null
197198
}> = ({ children, className, overlayContainer }) => {
198199
const editorRootElementRef = React.useRef<HTMLDivElement | null>(null)
200+
const wrapperElementRef = React.useRef<HTMLDivElement | null>(null)
199201
const setEditorRootElementRef = usePublisher(editorRootElementRef$)
202+
const setEditorWrapperElementRef = usePublisher(editorWrapperElementRef$)
200203

201204
React.useEffect(() => {
202205
const popupContainer = document.createElement('div')
@@ -210,11 +213,16 @@ const EditorRootElement: React.FC<{
210213
container.appendChild(popupContainer)
211214
editorRootElementRef.current = popupContainer
212215
setEditorRootElementRef(editorRootElementRef)
216+
setEditorWrapperElementRef(wrapperElementRef)
213217
return () => {
214218
popupContainer.remove()
215219
}
216-
}, [className, editorRootElementRef, overlayContainer, setEditorRootElementRef])
217-
return <div className={classNames('mdxeditor', styles.editorRoot, styles.editorWrapper, className)}>{children}</div>
220+
}, [className, editorRootElementRef, overlayContainer, setEditorRootElementRef, setEditorWrapperElementRef])
221+
return (
222+
<div className={classNames('mdxeditor', styles.editorRoot, styles.editorWrapper, className)} ref={wrapperElementRef}>
223+
{children}
224+
</div>
225+
)
218226
}
219227

220228
const Methods: React.FC<{ mdxRef: React.ForwardedRef<MDXEditorMethods> }> = ({ mdxRef }) => {

src/plugins/core/index.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,11 @@ export const codeBlockEditorDescriptors$ = Cell<CodeBlockEditorDescriptor[]>([])
306306
*/
307307
export const editorRootElementRef$ = Cell<React.RefObject<HTMLDivElement> | null>(null)
308308

309+
/**
310+
* @group Core
311+
*/
312+
export const editorWrapperElementRef$ = Cell<React.RefObject<HTMLDivElement> | null>(null)
313+
309314
/**
310315
* A reference to the content editable element.
311316
* @group Core

0 commit comments

Comments
 (0)