Skip to content

Commit

Permalink
fix: correct theme for the nested lexial editors
Browse files Browse the repository at this point in the history
  • Loading branch information
petyosi committed Nov 9, 2024
1 parent d3ca9e7 commit fa62100
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions src/plugins/core/NestedLexicalEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import {
importVisitors$,
jsxComponentDescriptors$,
jsxIsAvailable$,
lexicalTheme$,
nestedEditorChildren$,
rootEditor$,
usedLexicalNodes$
Expand All @@ -37,15 +38,14 @@ import LexicalErrorBoundary from '@lexical/react/LexicalErrorBoundary.js'
import { LexicalNestedComposer } from '@lexical/react/LexicalNestedComposer.js'
import { RichTextPlugin } from '@lexical/react/LexicalRichTextPlugin.js'
import classNames from 'classnames'
import { lexicalTheme } from '../../styles/lexicalTheme'
import { exportLexicalTreeToMdast } from '../../exportMarkdownFromLexical'
import { importMdastTreeToLexical } from '../../importMarkdownToLexical'
import styles from '../../styles/ui.module.css'
import { SharedHistoryPlugin } from './SharedHistoryPlugin'
import { mergeRegister } from '@lexical/utils'
import { VoidEmitter } from '../../utils/voidEmitter'
import { isPartOftheEditorUI } from '../../utils/isPartOftheEditorUI'
import { useCellValues, usePublisher } from '@mdxeditor/gurx'
import { useCellValues, usePublisher, useRealm } from '@mdxeditor/gurx'
import { DirectiveNode } from '../directives'
import { LexicalJsxNode } from '../jsx/LexicalJsxNode'

Expand Down Expand Up @@ -181,6 +181,7 @@ export const NestedLexicalEditor = function <T extends Mdast.RootContent>(props:
const updateMdastNode = useMdastNodeUpdater<T>()
const removeNode = useLexicalNodeRemove()
const content = getContent(mdastNode)
const realm = useRealm()

const [
rootEditor,
Expand All @@ -191,7 +192,8 @@ export const NestedLexicalEditor = function <T extends Mdast.RootContent>(props:
directiveDescriptors,
codeBlockEditorDescriptors,
jsxIsAvailable,
nestedEditorChildren
nestedEditorChildren,
lexicalTheme
] = useCellValues(
rootEditor$,
importVisitors$,
Expand All @@ -201,15 +203,16 @@ export const NestedLexicalEditor = function <T extends Mdast.RootContent>(props:
directiveDescriptors$,
codeBlockEditorDescriptors$,
jsxIsAvailable$,
nestedEditorChildren$
nestedEditorChildren$,
lexicalTheme$
)

const setEditorInFocus = usePublisher(editorInFocus$)

const [editor] = React.useState(() => {
const editor = createEditor({
nodes: usedLexicalNodes,
theme: lexicalTheme
theme: realm.getValue(lexicalTheme$)
})
return editor
})
Expand Down Expand Up @@ -261,6 +264,7 @@ export const NestedLexicalEditor = function <T extends Mdast.RootContent>(props:
updateMdastNode(getUpdatedMdastNode(structuredClone(mdastNode) as any, content as any))
})
}

return mergeRegister(
editor.registerCommand(
FOCUS_COMMAND,
Expand Down Expand Up @@ -330,7 +334,7 @@ export const NestedLexicalEditor = function <T extends Mdast.RootContent>(props:
])

return (
<LexicalNestedComposer initialEditor={editor}>
<LexicalNestedComposer initialEditor={editor} initialTheme={lexicalTheme}>
<RichTextPlugin
contentEditable={
<ContentEditable {...contentEditableProps} className={classNames(styles.nestedEditor, contentEditableProps?.className)} />
Expand Down

0 comments on commit fa62100

Please sign in to comment.