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:
Option 1: Default Editor Config
If you require the default editor config:
Option 2: Extract from a Lexical Field
When a lexical field config is available, you can extract the editor config directly:
Option 3: Create a Custom Editor Config
You can create a custom editor configuration by specifying additional features:
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:
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: