Skip to main content

Reset Node

Allows you to reset the block type based on certain rules.

In the following example, you can press Enter in an empty block quote or Backspace at the start of a block so it resets to a paragraph.

Installation#

npm install @udecode/plate
# or
npm install @udecode/plate-reset-node

Usage#

import React from 'react';
import {
  createExitBreakPlugin,
  createListPlugin,
  createResetNodePlugin,
  createSoftBreakPlugin,
  createTablePlugin,
  createTrailingBlockPlugin,
  Plate,
} from '@udecode/plate';
import { basicElementsValue } from './basic-elements/basicElementsValue';
import { basicNodesPlugins } from './basic-nodes/basicNodesPlugins';
import { editableProps } from './common/editableProps';
import { plateUI } from './common/plateUI';
import { exitBreakPlugin } from './exit-break/exitBreakPlugin';
import { resetBlockTypePlugin } from './reset-node/resetBlockTypePlugin';
import { softBreakPlugin } from './soft-break/softBreakPlugin';
import { trailingBlockPlugin } from './trailing-block/trailingBlockPlugin';
import { createMyPlugins, MyValue } from './typescript/plateTypes';

const plugins = createMyPlugins(
  [
    ...basicNodesPlugins,
    createListPlugin(),
    createTablePlugin(),
    createTrailingBlockPlugin(trailingBlockPlugin),
    createResetNodePlugin(resetBlockTypePlugin),
    createSoftBreakPlugin(softBreakPlugin),
    createExitBreakPlugin(exitBreakPlugin),
  ],
  {
    components: plateUI,
  }
);

export default () => (
  <Plate<MyValue>
    editableProps={editableProps}
    plugins={plugins}
    initialValue={basicElementsValue}
  />
);

Options#

export interface ResetNodePluginRule<V extends Value = Value, E extends PlateEditor<V> = PlateEditor<V>> extends HotkeyPlugin {
defaultType?: string;
/**
* Node types where the rule applies.
*/
types: string[];
/**
* Additional condition to the rule.
*/
predicate: (editor: E) => boolean;
/**
* Callback called when resetting.
*/
onReset?: (editor: E) => void;
}
export interface ResetNodePlugin<V extends Value = Value, E extends PlateEditor<V> = PlateEditor<V>> {
rules?: ResetNodePluginRule<V, E>[];
}

Source Code#