Simplify your stack and build anything. Or everything.
Build tomorrow’s web with a modern solution you truly own.
Code-based nature means you can build on top of it to power anything.
It’s time to take back your content infrastructure.

Lexical Converters

Richtext fields save data in JSON - this is great for storage and flexibility and allows you to easily to convert it to other formats:

Retrieving the Editor Config

Some converters require access to the Lexical editor config, which defines available features and behaviors. Payload provides multiple ways to obtain the editor config through the editorConfigFactory from @payloadcms/richtext-lexical.

Importing the Factory

First, import the necessary utilities:

1
import type { SanitizedConfig } from 'payload'
2
import { editorConfigFactory } from '@payloadcms/richtext-lexical'
3
4
// Your Payload Config needs to be available in order to retrieve the default editor config
5
const config: SanitizedConfig = {} as SanitizedConfig

Option 1: Default Editor Config

If you require the default editor config:

1
const defaultEditorConfig = await editorConfigFactory.default({ config })

Option 2: Extract from a Lexical Field

When a lexical field config is available, you can extract the editor config directly:

1
const fieldEditorConfig = editorConfigFactory.fromField({
2
field: config.collections[0].fields[1],
3
})

Option 3: Create a Custom Editor Config

You can create a custom editor configuration by specifying additional features:

1
import { FixedToolbarFeature } from '@payloadcms/richtext-lexical'
2
3
const customEditorConfig = await editorConfigFactory.fromFeatures({
4
config,
5
features: ({ defaultFeatures }) => [
6
...defaultFeatures,
7
FixedToolbarFeature(),
8
],
9
})

Option 4: Extract from an Instantiated Editor

If you've created a global or reusable Lexical editor instance, you can access its configuration. This method is typically less efficient and not recommended:

1
const editor = lexicalEditor({
2
features: ({ defaultFeatures }) => [
3
...defaultFeatures,
4
FixedToolbarFeature(),
5
],
6
})
7
8
const instantiatedEditorConfig = await editorConfigFactory.fromEditor({
9
config,
10
editor,
11
})

For better efficiency, consider extracting the features into a separate variable and using fromFeatures instead of this method.

Example - Retrieving the editor config from an existing field

If you have access to the sanitized collection config, you can access the lexical sanitized editor config, as every lexical richText field returns it. Here is an example how you can retrieve it from another field's afterRead hook:

1
import type { CollectionConfig, RichTextField } from 'payload'
2
3
import {
4
editorConfigFactory,
5
getEnabledNodes,
6
lexicalEditor,
7
} from '@payloadcms/richtext-lexical'
8
9
export const MyCollection: CollectionConfig = {
10
slug: 'slug',
11
fields: [
12
{
13
name: 'text',
14
type: 'text',
15
hooks: {
16
afterRead: [
17
({ siblingFields, value }) => {
18
const field: RichTextField = siblingFields.find(
19
(field) => 'name' in field && field.name === 'richText',
20
) as RichTextField
21
22
const editorConfig = editorConfigFactory.fromField({
23
field,
24
})
25
26
// Now you can use the editor config
27
28
return value
29
},
30
],
31
},
32
},
33
{
34
name: 'richText',
35
type: 'richText',
36
editor: lexicalEditor(),
37
},
38
],
39
}
Next

Converting JSX