Type Editor / @type-editor/commands / toggle-block-type / toggleBlockType
Function: toggleBlockType()
ts
function toggleBlockType(
nodeType,
unwrapNodeType,
attrs?,
allowUnwrap?,
): Command;Defined in: toggle-block-type.ts:23
Creates a command that toggles between two block types.
If the selection is currently inside a node of the specified nodeType and unwrapping is allowed, it will convert the block to unwrapNodeType. Otherwise, it will convert the block to nodeType.
This is useful for implementing toggle buttons (e.g., toggling between a heading and a paragraph).
Parameters
| Parameter | Type | Default value | Description |
|---|---|---|---|
nodeType | NodeType | undefined | The node type to toggle to when not already in this type. |
unwrapNodeType | NodeType | undefined | The node type to revert to when already inside nodeType. |
attrs | Readonly<Record<string, any>> | null | Optional attributes to apply to the new block node. |
allowUnwrap | boolean | true | Whether to allow toggling back to unwrapNodeType. Defaults to true. |
Returns
Command
A command function that toggles the block type when executed.