Customize Lexical editor features and configuration
developYou can deeply customize the editor using the editorConfigModifier option within lexicalRichTextField. This allows you to:
- Modify Toggles: Enable or disable specific toolbar elements like
textColor,fontSize, ortablesviadefaultEditorConfig.toggles. - Manage Features: Replace or augment the default feature set by defining the
defaultEditorConfig.featuresarray. Each feature is a function that returns aFeatureobject. - Add Custom Features: Push your own custom feature implementations into the
featuresarray.
Note: A feature can consist of nodes, plugins, modals, and toolbar elements.
import { CollectionConfig } from 'payload/types';
import {
lexicalRichTextField,
EquationsFeature,
EmojisFeature,
EmojiPickerFeature,
HorizontalRuleFeature,
FigmaFeature,
YouTubeFeature,
TwitterFeature,
SpeechToTextFeature,
ImportFeature,
ExportFeature,
ClearEditorFeature,
ReadOnlyModeFeature,
ConvertFromMarkdownFeature,
MentionsFeature,
TreeViewFeature,
KeywordsFeature,
AutoCompleteFeature,
CollapsibleFeature,
TypingPerfFeature,
PasteLogFeature,
TestRecorderFeature,
LinkFeature,
TableOfContentsFeature,
AISuggestFeature,
} from 'payload-plugin-lexical';
const Lexical: CollectionConfig = {
slug: 'lexicalRichText',
admin: {
useAsTitle: 'title',
},
fields: [
{
name: 'title',
type: 'text',
required: true,
},
lexicalRichTextField({
name: 'lexicalRichTextEditor',
label: 'cool richtext editor',
localized: true,
editorConfigModifier: (defaultEditorConfig) => {
defaultEditorConfig.debug = false;
defaultEditorConfig.toggles.textColor.enabled = false;
defaultEditorConfig.toggles.textBackground.enabled = false;
defaultEditorConfig.toggles.fontSize.enabled = false;
defaultEditorConfig.toggles.font.enabled = false;
defaultEditorConfig.toggles.align.enabled = false;
defaultEditorConfig.toggles.tables.enabled = true;
defaultEditorConfig.toggles.tables.display = false;
defaultEditorConfig.features = [
EquationsFeature({}),
EmojisFeature({}),
EmojiPickerFeature({}),
HorizontalRuleFeature({}),
FigmaFeature({}),
YouTubeFeature({}),
TwitterFeature({}),
SpeechToTextFeature({}),
ImportFeature({}),
ExportFeature({}),
ClearEditorFeature({}),
ReadOnlyModeFeature({}),
ConvertFromMarkdownFeature({}),
MentionsFeature({}),
TreeViewFeature({ enabled: defaultEditorConfig.debug }),
KeywordsFeature({}),
AutoCompleteFeature({}),
CollapsibleFeature({}),
TypingPerfFeature({ enabled: defaultEditorConfig.debug }),
PasteLogFeature({ enabled: defaultEditorConfig.debug }),
TestRecorderFeature({ enabled: defaultEditorConfig.debug }),
LinkFeature({}),
TableOfContentsFeature({ enabled: false }),
AISuggestFeature({}),
];
// Add your own custom feature
defaultEditorConfig.features.push(YourOwnCustomFeature({}));
return defaultEditorConfig;
},
}),
],
};
export default Lexical;