Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(richtext-lexical): add DebugJsxConverterFeature #10856

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/richtext-lexical/src/exports/client/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,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'

Expand Down
31 changes: 16 additions & 15 deletions packages/richtext-lexical/src/exports/react/index.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
export { BlockquoteJSXConverter } from './components/RichText/converter/converters/blockquote.js'
export { HeadingJSXConverter } from './components/RichText/converter/converters/heading.js'
export { HorizontalRuleJSXConverter } from './components/RichText/converter/converters/horizontalRule.js'
export { LinebreakJSXConverter } from './components/RichText/converter/converters/linebreak.js'
export { LinkJSXConverter } from './components/RichText/converter/converters/link.js'
export { ListJSXConverter } from './components/RichText/converter/converters/list.js'
export { ParagraphJSXConverter } from './components/RichText/converter/converters/paragraph.js'
export { TabJSXConverter } from './components/RichText/converter/converters/tab.js'
export { TableJSXConverter } from './components/RichText/converter/converters/table.js'
export { TextJSXConverter } from './components/RichText/converter/converters/text.js'
export { BlockquoteJSXConverter } from '../../features/converters/jsx/converter/converters/blockquote.js'

export { UploadJSXConverter } from './components/RichText/converter/converters/upload.js'
export { HeadingJSXConverter } from '../../features/converters/jsx/converter/converters/heading.js'
export { HorizontalRuleJSXConverter } from '../../features/converters/jsx/converter/converters/horizontalRule.js'
export { LinebreakJSXConverter } from '../../features/converters/jsx/converter/converters/linebreak.js'
export { LinkJSXConverter } from '../../features/converters/jsx/converter/converters/link.js'
export { ListJSXConverter } from '../../features/converters/jsx/converter/converters/list.js'
export { ParagraphJSXConverter } from '../../features/converters/jsx/converter/converters/paragraph.js'
export { TabJSXConverter } from '../../features/converters/jsx/converter/converters/tab.js'
export { TableJSXConverter } from '../../features/converters/jsx/converter/converters/table.js'
export { TextJSXConverter } from '../../features/converters/jsx/converter/converters/text.js'
export { UploadJSXConverter } from '../../features/converters/jsx/converter/converters/upload.js'

export { defaultJSXConverters } from './components/RichText/converter/defaultConverters.js'
export { convertLexicalNodesToJSX } from './components/RichText/converter/index.js'
export { defaultJSXConverters } from '../../features/converters/jsx/converter/defaultConverters.js'

export { convertLexicalNodesToJSX } from '../../features/converters/jsx/converter/index.js'
export type {
JSXConverter,
JSXConverters,
SerializedLexicalNodeWithParent,
} from './components/RichText/converter/types.js'
export { type JSXConvertersFunction, RichText } from './components/RichText/index.js'
} from '../../features/converters/jsx/converter/types.js'
export { type JSXConvertersFunction, RichText } from '../../features/converters/jsx/index.js'
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { SerializedQuoteNode } from '../../../../../../nodeTypes.js'
import type { SerializedQuoteNode } from '../../../../../nodeTypes.js'
import type { JSXConverters } from '../types.js'

export const BlockquoteJSXConverter: JSXConverters<SerializedQuoteNode> = {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { SerializedHeadingNode } from '../../../../../../nodeTypes.js'
import type { SerializedHeadingNode } from '../../../../../nodeTypes.js'
import type { JSXConverters } from '../types.js'

export const HeadingJSXConverter: JSXConverters<SerializedHeadingNode> = {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { SerializedHorizontalRuleNode } from '../../../../../../nodeTypes.js'
import type { SerializedHorizontalRuleNode } from '../../../../../nodeTypes.js'
import type { JSXConverters } from '../types.js'
export const HorizontalRuleJSXConverter: JSXConverters<SerializedHorizontalRuleNode> = {
horizontalrule: () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { SerializedLineBreakNode } from '../../../../../../nodeTypes.js'
import type { SerializedLineBreakNode } from '../../../../../nodeTypes.js'
import type { JSXConverters } from '../types.js'

export const LinebreakJSXConverter: JSXConverters<SerializedLineBreakNode> = {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { SerializedAutoLinkNode, SerializedLinkNode } from '../../../../../../nodeTypes.js'
import type { SerializedAutoLinkNode, SerializedLinkNode } from '../../../../../nodeTypes.js'
import type { JSXConverters } from '../types.js'

export const LinkJSXConverter: (args: {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { v4 as uuidv4 } from 'uuid'

import type { SerializedListItemNode, SerializedListNode } from '../../../../../../nodeTypes.js'
import type { SerializedListItemNode, SerializedListNode } from '../../../../../nodeTypes.js'
import type { JSXConverters } from '../types.js'

export const ListJSXConverter: JSXConverters<SerializedListItemNode | SerializedListNode> = {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { SerializedParagraphNode } from '../../../../../../nodeTypes.js'
import type { SerializedParagraphNode } from '../../../../../nodeTypes.js'
import type { JSXConverters } from '../types.js'

export const ParagraphJSXConverter: JSXConverters<SerializedParagraphNode> = {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { SerializedTabNode } from '../../../../../../nodeTypes.js'
import type { SerializedTabNode } from '../../../../../nodeTypes.js'
import type { JSXConverters } from '../types.js'

export const TabJSXConverter: JSXConverters<SerializedTabNode> = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import type {
SerializedTableCellNode,
SerializedTableNode,
SerializedTableRowNode,
} from '../../../../../../nodeTypes.js'
} from '../../../../../nodeTypes.js'
import type { JSXConverters } from '../types.js'

export const TableJSXConverter: JSXConverters<
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import React from 'react'

import type { SerializedTextNode } from '../../../../../../nodeTypes.js'
import type { SerializedTextNode } from '../../../../../nodeTypes.js'
import type { JSXConverters } from '../types.js'

import { NodeFormat } from '../../../../../../lexical/utils/nodeFormat.js'
import { NodeFormat } from '../../../../../lexical/utils/nodeFormat.js'

export const TextJSXConverter: JSXConverters<SerializedTextNode> = {
text: ({ node }) => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { FileData, FileSize, TypeWithID } from 'payload'

import type { SerializedUploadNode } from '../../../../../../nodeTypes.js'
import type { SerializedUploadNode } from '../../../../../nodeTypes.js'
import type { JSXConverters } from '../types.js'

export const UploadJSXConverter: JSXConverters<SerializedUploadNode> = {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { DefaultNodeTypes } from '../../../../../nodeTypes.js'
import type { DefaultNodeTypes } from '../../../../nodeTypes.js'
import type { JSXConverters } from './types.js'

import { BlockquoteJSXConverter } from './converters/blockquote.js'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ import type { SerializedEditorState, SerializedLexicalNode } from 'lexical'

import React from 'react'

import type { SerializedBlockNode, SerializedInlineBlockNode } from '../../../../../nodeTypes.js'
import type { SerializedBlockNode, SerializedInlineBlockNode } from '../../../../nodeTypes.js'
import type { JSXConverter, JSXConverters, SerializedLexicalNodeWithParent } from './types.js'

import { hasText } from '../../../../../validate/hasText.js'
import { hasText } from '../../../../validate/hasText.js'

export type ConvertLexicalToHTMLArgs = {
converters: JSXConverters
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import type {
DefaultNodeTypes,
SerializedBlockNode,
SerializedInlineBlockNode,
} from '../../../../../nodeTypes.js'
} from '../../../../nodeTypes.js'
export type JSXConverter<T extends { [key: string]: any; type?: string } = SerializedLexicalNode> =
(args: {
childIndex: number
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import type {
DefaultNodeTypes,
SerializedBlockNode,
SerializedInlineBlockNode,
} from '../../../../nodeTypes.js'
} from '../../../nodeTypes.js'
import type { JSXConverters } from './converter/types.js'

import { defaultJSXConverters } from './converter/defaultConverters.js'
Expand Down
Original file line number Diff line number Diff line change
@@ -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',
},
],
})
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
'use client'

import { useLexicalComposerContext } from '@lexical/react/LexicalComposerContext'
import { useEffect, useState } from 'react'

import { defaultJSXConverters } from '../../../../converters/jsx/converter/defaultConverters.js'
import { RichText } from '../../../../converters/jsx/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} />
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { createServerFeature } from '../../../../utilities/createServerFeature.js'

export const DebugJsxConverterFeature = createServerFeature({
feature: {
ClientFeature: '@payloadcms/richtext-lexical/client#DebugJsxConverterFeatureClient',
},
key: 'jsxConverter',
})
1 change: 1 addition & 0 deletions packages/richtext-lexical/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -896,6 +896,7 @@ export {
HTMLConverterFeature,
type HTMLConverterFeatureProps,
} from './features/converters/html/index.js'
export { DebugJsxConverterFeature } from './features/debug/jsxConverter/server/index.js'
export { TestRecorderFeature } from './features/debug/testRecorder/server/index.js'
export { TreeViewFeature } from './features/debug/treeView/server/index.js'
export { EXPERIMENTAL_TableFeature } from './features/experimental_table/server/index.js'
Expand Down
Loading