Skip to main content

Plugin Customization

Motivation#

As it turns out, various RichContentEditor consumers have different customization needs. On other hand, it is important to keep the public API clean, while providing the desired customability. In order to meet these requirements, the RichContentEditor exposes config object prop.

This document focuses on plugin customization capabilities.

Plugin Types as config Keys#

Every plugin exports a constant value that defines its type. The convention is to name the type according to the pluginName_TYPE pattern. The type is actually a plugin identifier, so it has to be unique.

The type serves multiple purposes. It is used to map the entities to proper plugin components both in RichContentEditor and RichContentViewer. Another plugin type application is config keys.

Every plugin expects to find its custom settings within the config[pluginName_TYPE] field. The expected value is an object containing specific settings that vary for every plugin. The following sections provide a list of plugin settings. As usual, the list is a subject to change.

Plugin Settings#

Common Settings#

These settings are common to all the plugins and handled at the base plugin level.

width and height#

The width and height are expected to be integers. They serve as initial plugin component dimensions in pixels, if there are no width and height fields defined in componentData.config for that specific plugin entity.

toolbar#

The toolbar setting refers to the plugin functionality toolbar, it is an object which may consist of the following keys:

setting keydescriptiondefault valueis required?editor/viewer config
hiddenan array of toolbar button keynames to be removed from toolbarnoneNoeditor
iconsan object of toolbar button keynames to custom icons map: { delete: MyCustomTrashIcon }noneNoeditor

Currently, it exposes a field hidden which is expected to be an array of toolbar button keynames to be removed from toolbar and a field icons which is expected to be an object of button icons to replace the existing icons.

defaultData#

The defaultData setting enables consumers to set the default data for a plugin when it is inserted into the editor. It is an object with the same fields as the plugins entity data.

Button Plugin Settings#

setting keydescriptiondefault valueis required?editor/viewer config
activeButtonThe index of the chosen preset button design0Noboth
borderRadiusThe border radius in pixels0Noboth
borderWidthThe border width in pixels0Noboth
buttonTextThe button labelClick MeNoboth
urlThe URL that should be redirected when clicking on the buttonnoneYesboth
relThe relationship between the current URL and the linked URLnofollowYesboth
targetSpecifies where to open URL in new tab or in current tab_blankYesboth
textColorThe color of button text in Hex.#FEFDFDNoboth
borderColorThe color of button border in Hex.#0161FFNoboth
backgroundColorThe color of button background in Hex.#0161FFNoboth

HTML Plugin Settings#

setting keydescriptiondefault valueis required?editor/viewer config
htmlIframeSrcsrc attribute of the HTML iframe when the plugin is used in source modenoneYesboth
maxWidththe maximum component width in pixels. note: this value is dynamically limited by the editor boundaries940Noboth
minWidththe minimum component width in pixels35Noboth
maxHeightthe maximum component height in pixels1200Noboth
minHeightthe minimum component height in pixels35Noboth
widththe initial component width in pixels740Noboth
heightthe initial component height in pixels242Noboth
siteDomainthe site domain in order for adsense to worknoneNoboth
exposeButtonscontrols what buttons will be exposed to open HTML modal['html']Noeditor

Hashtag Plugin Settings#

setting keydescriptiondefault valueis required?editor/viewer config
createHrefconverter function that converts the Hashtag #text to URL. if provided, the hashtags will behave as anchor linksnoneNoboth
onClickoptional Hashtag click handlernoneNoboth

Link Plugin Settings#

setting keydescriptiondefault valueis required?editor/viewer config
onClickoptional Link click handlernoneNoboth
previewLink Preview settingsnoneNoboth
linkTypesSupported Links types{ anchor: true }Noeditor

The Link Preview Plugin is implemented within the Link Plugin, and is activated once the Link Plugin Settings object contains preview field. The preview object structure as follows:

{
getMetadataUrl: (query: string) => string,
token: string,
format: string,
}

The getMetadataUrl should provide a Website metadata service endpoint URL for a given query URL. The token is a security token appended to request headers (Authorization header). The format is the expected response format. Currently the only supported format is 'oembed'.

Mentions Plugin Settings#

setting keydescriptiondefault valueis required?editor/viewer config
getMentionsfunction that retrieves a list of suggestions according to provided search query parameternoneYesboth
onMentionClickoptional Mention click handlernoneNoboth
onMentionHoveroptional Mention hover handlernoneNoboth
getMentionLinkgiven the mention return link for itnoneYesboth
visibleItemsBeforeOverflowboolean how many items should be visible before overflowingnoneNoeditor

Giphy Plugin Settings#

setting keydescriptiondefault valueis required?editor/viewer config
giphySdkApiKeyGiphy Developer API keynoneYesboth
componentDataDefaultsDefault component data{ config: { size: 'content', alignment: 'center' } }Noeditor
insertToolbarsWhich toolbars to add insert button to[TOOLBARS.FOOTER]Noeditor

Image Plugin Settings#

setting keydescriptiondefault valueis required?editor/viewer config
onExpandcalled when the user expands an imagenoneNoviewer
disableExpand (deprecated!)disables expanding images & fullscreenfalseNoviewer
disableExpanddisables expanding images & fullscreenfalseNoeditor

Gallery Plugin Settings#

setting keydescriptiondefault valueis required?editor/viewer config
onExpandcalled when the user expands an itemnoneNoviewer
disableExpand (deprecated)disables expanding items & fullscreenfalseNoviewer
disableExpanddisables expanding items & fullscreenfalseNoeditor

Text Color Plugin#

setting keydescriptiondefault valueis required?editor/viewer config
colorSchemecustom-style to hex-color map: { color1: { color: '#fff', index: 0 }, ... }none (DEFAULT_PALETTE is used by default)Noeditor
styleSelectionPredicatea function that tells the plugin which inline styles are relevant: string => booleanstyle => isHexColor(style)Noboth
customStyleFn (1)a function that converts an inline-style to CSS style: DraftInlineStyle => objectDEFAULT_STYLE_FN_DRAFTNoeditor
customStyleFn (2)a function that converts an inline-style to CSS style: string => objectDEFAULT_STYLE_FNNoviewer
selectionColorselected color indicator (string)#000Noeditor
onColorAddeda handler called when a custom color is addednoneYeseditor
getUserColorsa function that returns user-defined custom colorsnoneYeseditor
onCustomPickerTogglea handler called when the Add Color button is clicked [see Note below for details]modal CustomColorPickerDialog is displayedNoeditor
onCustomColorPickeda handler called when a custom color is picked by hue/saturation controlsnoopNoeditor

Note: onCustomPickerToggle API is intended to be used when there is a need to display the CustomColorPicker outside the modal dialog, e.g. as a Settings panel element. The API is called with the following parameters:

  • onCustomColorPicked(color) -- should be called when a custom color is picked by hue/saturation controls of the CustomColorPicker. Usually it should be wired to the CustomColorPicker's onChange prop
  • onCustomColorUpdate(color) -- should be called when user decides to apply the selected color (e.g. CustomColorPickerDialog Update button)
  • onCustomColorCancel(color) -- should be called when user decides to cancel the custom color selection (e.g. CustomColorPickerDialog Cancel button)
  • all the ColorPicker props (t, isMobile, theme, ...etc)

Note: selectionColor prop is deprecated, please override the .colorPicker_button_selected::after class border-color rule (theme).

Text Color Inline Style Mapper#

The RichContentViewer exposes the inlineStyleMappers prop. The mapper purpose is to provide a mapping inlineStyle => Component, that is used by the RichContentViewer. The prop value is expected to be an array of functions of the following signature:

() => {
style1: {children, { key }} => <Component1 .../>,
style2: {children, { key }} => <Component2 .../>,
...
}

Specifically, the textColorInlineStyleMapper API accepts two parameters -- config and raw (aka ContentState), and returns the mapper array. The custom inline styles are picked from the raw according to the styleSelectionPredicate, and the style conversion is performed by the customStyleFn (2). Both APIs should be provided by the consumer within config object.

References and Examples#

Both editor-example and viewer-example apps demonstrate the plugin customization capabilities.