Plate Core
API reference for @udecode/plate-core.
API
createPlugins
Creates a new array of plugins by overriding the plugins in the original array.
Parameters
The original array of plugins.
The options to override plugins.
Returns
An array of plugins with overridden components or attributes.
createAtomStore
Creates an atom store from an initial value. Each property of the initial value will have a getter and setter.
Parameters
The initial state of the atom store.
An optional object which can contain a scope, an initial store, and a name.
Returns
An AtomStoreApi
object.
createPlateEditor
Generates a new instance of a PlateEditor
, initialized with a set of plugins and their configurations.
Parameters
Initial editor without withPlate
.
An array of editor plugins.
Components to inject into plugins.
Plugins to override by key.
A flag indicating whether to normalize the initial editor value.
Options for the withPlate
function, excluding plugins
.
Returns
An instance of PlateEditor
with the specified plugins, components, and
settings applied.
createPlugin
Creates a new Plate plugin with the given configuration, supporting extension, nested plugin manipulation, and runtime configuration.
Parameters
The configuration object for the plugin, or a function that returns the configuration. If a function is provided, it will be stored in __extensions
and executed when the plugin is resolved with the editor. All properties are optional except key
.
Returns
- All properties from the input config, merged with default values.
configure(options: Partial<O>): PlatePlugin<K, O, A, T, S>
extend(extendConfig: Partial<PlatePlugin> | ((editor: PlateEditor, plugin: PlatePlugin) => Partial<PlatePlugin>)): PlatePlugin<K, O, A, T, S>
extendPlugin(key: string, extendConfig: Partial<PlatePlugin> | ((editor: PlateEditor, plugin: PlatePlugin) => Partial<PlatePlugin>)): PlatePlugin<K, O, A, T, S>
A new PlatePlugin<K, O, A, T, S>
instance with the following properties and methods:
The createPlugin
function provides a flexible and powerful way to create and manipulate plugins in Plate:
- Generic Support: Uses generics
K
,O
,A
,T
, andS
for strict typing of key, options, API, transforms, and storage respectively. - Default Values: Automatically sets default values for essential plugin properties.
- Nested Plugin Support: Allows for creating and extending plugins at any nesting level.
- Configuration: The
configure
method enables updating plugin options. - Flexible Extension: The
extend
andextendPlugin
methods support both object and function-based extensions. See PlatePlugin API.
Basic Usage
const myPlugin = createPlugin<'myPlugin', MyOptions, MyApi, MyTransforms>({
key: 'myPlugin',
options: { someOption: true },
transforms: { someTransform: () => {} },
});
// or with a function / types inferred
const myPlugin2 = createPlugin((editor) => ({
key: 'myPlugin',
options: { someOption: true },
transforms: { someTransform: () => {} },
}));
getPlugin
Retrieves a plugin by plugin key.
Parameters
The editor to extract the plugin from.
The key of the plugin to retrieve.
Returns
Returns the requested plugin. If the plugin does not exist, returns an object with only the key.
getPluginInjectProps
Retrieves the props to be injected by a plugin, identified by its key.
Parameters
The editor to extract the plugin from.
The key of the plugin whose inject props to retrieve.
Returns
Returns the props to be injected by the specified plugin. If the plugin does not exist or does not have inject props, returns an empty object.
getPluginOptions
Retrieves the options of a plugin, identified by its key.
Parameters
The editor to extract the plugin from.
The key of the plugin whose options to retrieve.
Returns
Returns the options of the specified plugin. If the plugin does not exist or does not have options, returns an empty object.
getPluginType
Retrieves the type of a plugin, identified by its key.
Parameters
The editor to extract the plugin from.
The key of the plugin whose type to retrieve.
Returns
Returns the type of the specified plugin. If the plugin does not exist or does not have a type, returns the key.
Hotkeys
An object containing functions to check for various hotkeys. Each function takes a KeyboardEvent
and returns a boolean indicating whether the hotkey was pressed.
Parameters
toggleNodeType
Toggle the type of the selected node. No operation is performed if activeType
equals inactiveType
.
Parameters
The editor.
Options for getting the nodes of the editor.
useElement
Hook to get the element from a node component.
Parameters
- Default: the closest element key.
The plugin key.
Returns
The value of the element as a TElement.
useEditorRef
Get the Slate editor reference without re-rendering.
- Does not re-render on editor change.
- Must be used inside
Plate
orPlateController
(see Accessing the Editor). - Note the reference does not change when the editor changes.
Parameters
The ID of the plate editor. Useful only when nesting editors. Default is using the closest editor id.
Returns
A PlateEditor
object, which is the Slate editor.
useEditorSelector
Subscribe to a specific property of the editor.
- Calls the selector function on editor change.
- Re-renders when the result of the selector changes.
- Must be used inside
Plate
orPlateController
(see Accessing the Editor).
Parameters
The selector function.
The dependency list for the selector function.
Returns
The return value of the selector function.
useEditorState
Get the Slate editor reference with re-rendering.
- Re-renders on editor change.
- Supports nested editors.
- Must be used inside
Plate
orPlateController
(see Accessing the Editor). - Note the reference does not change when the editor changes.
- If performance is a concern,
useEditorSelector
should be used instead.
Parameters
The ID of the plate editor. Default is using the closest editor id.
Returns
A PlateEditor
object, which is the Slate editor.
useEditorReadOnly
Get the editor's readOnly
state.
Parameters
The ID of the plate editor.
Returns
The readOnly
state of the editor.
useEditorMounted
Get the editor's isMounted
state.
Parameters
The ID of the plate editor.
Returns
The isMounted
state of the editor.
useEditorSelection
Get the editor's selection. Memoized so it does not re-render if the range is the same.
Parameters
The ID of the plate editor.
Returns
- The current selection in the editor.
useEditorVersion
Get the version of the editor value. That version is incremented on each editor change.
Parameters
The ID of the plate editor.
Returns
- The current version of the editor value.
useSelectionVersion
Get the version of the editor selection. That version is incremented on each selection change (the range being different).
Parameters
The ID of the plate editor.
Returns
- The current version of the editor selection.
Core plugins
DeserializeAstPlugin
Enables support for deserializing inserted content from Slate Ast format to Slate format while applying a small bug fix.
DeserializeHtmlPlugin
Enables support for deserializing inserted content from HTML format to Slate format.
EditorProtocolPlugin
Reset marks when the selection is at the start of a block and after delete operations.
EventEditorPlugin
Plugin that dispatches focus and blur events.
HistoryPlugin
Plugin that enables history support for the editor.
InlineVoidPlugin
Plugin that merges and registers all the inline types and void types from the plugins and options, using editor.isInline
and editor.isVoid
.
InsertDataPlugin
Plugin that overrides the default insertData
function in the editor, which is called when data is being pasted or dragged into the editor.
LengthPlugin
Plugin that enforces a maximum length for the editor.
NodeFactoryPlugin
Plugin that overrides the default blockFactory
and childrenFactory
functions in the editor. These functions are used to generate the default blocks and children for the editor.
PrevSelectionPlugin
Plugin that keeps track of the previous selection in the editor and the current keyboard event being processed.
ReactPlugin
Plugin that adds withTReact
to the editor, which is a generic typed version of withReact
from 'slate-react' library.
withPlate
An overrider that applies the withInlineVoid
and all plate plugins' withOverrides
.
withTReact
Generic typed version of withReact
from 'slate-react' library.