import type {
DefaultNodeTypes,
SerializedBlockNode,
} from '@frogbotai/richtext-lexical'
import type { SerializedEditorState } from '@frogbotai/richtext-lexical/lexical'
import {
convertLexicalToPlaintext,
type PlaintextConverters,
} from '@frogbotai/richtext-lexical/plaintext'
type TextBlock = {
blockName?: string
blockType: 'text'
text?: string
}
const converters: PlaintextConverters = {
blocks: {
text: ({ node }) => ('text' in node.fields ? node.fields.text ?? '' : ''),
},
link: ({ node }) => node.fields.url ?? '',
}
export function toPlainText(data: SerializedEditorState) {
return convertLexicalToPlaintext({ converters, data })
}