Docs
Plate Core

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

Collapse all

    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

Collapse all

    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

Collapse all

    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.

createPluginFactory

Generates a factory for creating plugins with a default plugin, which can be overridden.

Parameters

Collapse all

    The default plugin. The only required property is key.

    Overrides for the default plugin.

    Overrides for nested plugins (in plugin.plugins) by key.

Returns

    A plugin factory based on the default one, with the specified overrides applied.

getPlugin

Retrieves a plugin by plugin key.

Parameters

Collapse all

    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

Collapse all

    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

Collapse all

    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

Collapse all

    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

Expand all

toggleNodeType

Toggle the type of the selected node. No operation is performed if activeType equals inactiveType.

Parameters

Collapse all

    The editor.

    Options for getting the nodes of the editor.

useElement

Hook to get the element from a node component.

Parameters

Collapse all

    The plugin key.

    • Default: the closest element 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.
  • Should be used inside Plate.
  • Note the reference does not change when the editor changes.

Parameters

Collapse all

    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.
  • Should be used inside Plate.

Parameters

Collapse all

    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.
  • Should be used inside Plate.
  • Note the reference does not change when the editor changes.
  • If performance is a concern, useEditorSelector should be used instead.

Parameters

Collapse all

    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

Collapse all

    The ID of the plate editor.

Returns

    The readOnly state of the editor.

useEditorSelection

Get the editor's selection. Memoized so it does not re-render if the range is the same.

Parameters

Collapse all

    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

Collapse all

    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

Collapse all

    The ID of the plate editor.

Returns

    The current version of the editor selection.

Core plugins

createDeserializeAstPlugin

Enables support for deserializing inserted content from Slate Ast format to Slate format while applying a small bug fix.

createDeserializeHtmlPlugin

Enables support for deserializing inserted content from HTML format to Slate format.

createEditorProtocolPlugin

Reset marks when the selection is at the start of a block and after delete operations.

createEventEditorPlugin

Creates a plugin that dispatches focus and blur events.

createHistoryPlugin

Creates a plugin that enables history support for the editor.

createInlineVoidPlugin

Creates a plugin that merges and registers all the inline types and void types from the plugins and options, using editor.isInline and editor.isVoid.

createInsertDataPlugin

Creates a plugin that overrides the default insertData function in the editor, which is called when data is being pasted or dragged into the editor.

createLengthPlugin

Creates a plugin that enforces a maximum length for the editor.

createNodeFactoryPlugin

Creates a 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.

createPrevSelectionPlugin

Creates a plugin that keeps track of the previous selection in the editor and the current keyboard event being processed.

createReactPlugin

Creates a 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.