chore(richtext-lexical): add DebugJsxConverterFeature (#10856)

Display the editor content below using the JSX converter
Added for debugging reasons, similar to TreeViewFeature

usage:

```ts
    {
      name: 'content',
      type: 'richText',
      editor: lexicalEditor({
        features: ({ defaultFeatures }) => [...defaultFeatures, DebugJsxConverterFeature()],
      }),
    },
```
This commit is contained in:
Germán Jabloñski
2025-04-03 10:06:07 -03:00
committed by GitHub
parent 6c735effff
commit 308cb64b9c
5 changed files with 43 additions and 0 deletions

View File

@@ -30,6 +30,7 @@ export { UnorderedListFeatureClient } from '../../features/lists/unorderedList/c
export { LexicalPluginToLexicalFeatureClient } from '../../features/migrations/lexicalPluginToLexical/feature.client.js'
export { SlateToLexicalFeatureClient } from '../../features/migrations/slateToLexical/feature.client.js'
export { ParagraphFeatureClient } from '../../features/paragraph/client/index.js'
export { DebugJsxConverterFeatureClient } from '../../features/debug/jsxConverter/client/index.js'
export { RelationshipFeatureClient } from '../../features/relationship/client/index.js'

View File

@@ -0,0 +1,13 @@
'use client'
import { createClientFeature } from '../../../../utilities/createClientFeature.js'
import { RichTextPlugin } from './plugin/index.js'
export const DebugJsxConverterFeatureClient = createClientFeature({
plugins: [
{
Component: RichTextPlugin,
position: 'bottom',
},
],
})

View File

@@ -0,0 +1,20 @@
'use client'
import { useLexicalComposerContext } from '@lexical/react/LexicalComposerContext'
import { useEffect, useState } from 'react'
// eslint-disable-next-line payload/no-imports-from-exports-dir
import { defaultJSXConverters, RichText } from '../../../../../exports/react/index.js'
export function RichTextPlugin() {
const [editor] = useLexicalComposerContext()
const [editorState, setEditorState] = useState(editor.getEditorState().toJSON())
useEffect(() => {
return editor.registerUpdateListener(({ editorState }) => {
setEditorState(editorState.toJSON())
})
}, [editor])
return <RichText converters={defaultJSXConverters} data={editorState} />
}

View File

@@ -0,0 +1,8 @@
import { createServerFeature } from '../../../../utilities/createServerFeature.js'
export const DebugJsxConverterFeature = createServerFeature({
feature: {
ClientFeature: '@payloadcms/richtext-lexical/client#DebugJsxConverterFeatureClient',
},
key: 'jsxConverter',
})

View File

@@ -901,6 +901,7 @@ export {
HTMLConverterFeature,
type HTMLConverterFeatureProps,
} from './features/converters/lexicalToHtml_deprecated/index.js'
export { DebugJsxConverterFeature } from './features/debug/jsxConverter/server/index.js'
export { convertLexicalToMarkdown } from './features/converters/lexicalToMarkdown/index.js'
export { convertMarkdownToLexical } from './features/converters/markdownToLexical/index.js'