Docs
Reset Node
Reset Node
Reset the block type using rules.
Installation
npm install @udecode/plate-reset-node
Usage
// ...
import {
isBlockAboveEmpty,
isSelectionAtBlockStart,
} from '@udecode/plate-common';
import { createResetNodePlugin } from '@udecode/plate-reset-node';
const resetBlockTypesCommonRule = {
types: [ELEMENT_BLOCKQUOTE, ELEMENT_TODO_LI],
defaultType: ELEMENT_PARAGRAPH,
};
const resetBlockTypesCodeBlockRule = {
types: [ELEMENT_CODE_BLOCK],
defaultType: ELEMENT_PARAGRAPH,
onReset: unwrapCodeBlock,
};
const plugins = [
// ...otherPlugins,
createResetNodePlugin({
options: {
rules: [
{
...resetBlockTypesCommonRule,
hotkey: 'Enter',
predicate: isBlockAboveEmpty,
},
{
...resetBlockTypesCommonRule,
hotkey: 'Backspace',
predicate: isSelectionAtBlockStart,
},
{
...resetBlockTypesCodeBlockRule,
hotkey: 'Enter',
predicate: isCodeBlockEmpty,
},
{
...resetBlockTypesCodeBlockRule,
hotkey: 'Backspace',
predicate: isSelectionAtCodeBlockStart,
},
],
},
}),
];
API
createResetNodePlugin
Options
Collapse all
An array of rules which govern how the node reset will be performed. Each rule includes:
Whether to disable reset for the first block in the editor.
Whether to disable the reset operation for the entire editor.