Blocks API
The Blocks API provides block-level operations: creation, deletion, movement, transformation, and navigation. It works above the Elements API, operating on entire blocks rather than elements within blocks.Accessing the API
Import theBlocks namespace from @yoopta/editor:
Blocks API methods are not on the editor instance — use the
Blocks namespace.Type Definitions
Methods
insertBlock
Creates and inserts a new block of the given type.editor— Editor instance (required).type— Block type, e.g.'Paragraph','Heading'(required).options.at— Position to insert; default:editor.path.current.options.focus— Whether to focus the block after insertion.options.blockData— Custom block data (id, meta, value).options.elements— Custom element structure viaeditor.y().
deleteBlock
Removes a block and optionally focuses another.editor— Editor instance (required).options.at— Position of the block to delete.options.blockId— ID of the block to delete (overridesatif both set).options.focus— Whether to focus a block after deletion; default:true.options.focusTarget— Which block to focus:'previous'|'next'|'none'; default:'previous'.
updateBlock
Updates a block’s metadata and/or content.editor— Editor instance (required).blockId— ID of the block to update (required).newData.meta— Metadata to update:order,depth,align.newData.value— New block content (array of Slate elements).
getBlock
Retrieves block data by ID or path.editor— Editor instance (required).options.at— Position index of the block.options.id— ID of the block (overridesatif both set). One ofatoridis required.
null.
moveBlock
Moves a block to a new position.editor— Editor instance (required).draggedBlockId— ID of the block to move (required).newPath— New position (order index) for the block (required).
focusBlock
Focuses a block and optionally sets cursor position.editor— Editor instance (required).blockId— ID of the block to focus (required).options.waitExecution— Delay focus (e.g. until DOM is ready).options.waitExecutionMs— Delay in milliseconds.options.shouldUpdateBlockPath— Updateeditor.path.current; default:true.options.focusAt— Cursor position:PointorPath; default: first node.options.slate— Slate editor instance to use (optional).
duplicateBlock
Creates a copy of a block at a given position.editor— Editor instance (required).options.at— Position of the block to duplicate; default:editor.path.current.options.blockId— ID of the block to duplicate (overridesat).options.insertAt— Position to insert the duplicate; default: after original.options.focus— Focus the new block after creation; default:true.options.elements— Custom element structure for the duplicate.
undefined.
splitBlock
Splits a block at the selection (or given position).editor— Editor instance (required).options.at— Position of the block to split; default:editor.path.current.options.blockId— ID of the block to split.options.splitAt— Location to split at; default: current selection.options.focus— Focus after split; default:true.options.focusTarget— Which block to focus:'new'|'original'|'none'; default:'new'.options.preserveContent— Keep content in both blocks; default:true.
undefined.
mergeBlock
Merges a block into another (default: into previous).editor— Editor instance (required).options.at— Position of the source block (the one merged into target).options.blockId— ID of the source block.options.targetAt— Position of the target block (receives content); default: previous block.options.targetBlockId— ID of the target block.options.focus— Focus the target block after merge; default:true.options.preserveContent— Keep content from source block; default:true.
toggleBlock
Transforms block type (e.g. Paragraph → Heading) or inserts element in leaf.editor— Editor instance (required).type— Target block/element type, e.g.'Heading','Paragraph'(required).options.at— Position of the block; default:editor.path.current.options.scope—'auto'(default) |'block'(transform block) |'element'(insert in leaf).options.preserveContent— Transfer text to new block/element; default:true.options.focus— Focus after toggle; default:false.options.elements— Custom element structure viaeditor.y().
increaseBlockDepth
Increases block depth (indent).editor— Editor instance (required).options.at— Position of the block; default:editor.path.current.options.blockId— ID of the block (overridesat).
decreaseBlockDepth
Decreases block depth (outdent).editor— Editor instance (required).options.at— Position of the block; default:editor.path.current.options.blockId— ID of the block (overridesat).
getBlockSlate
Returns the Slate editor instance for a block.editor— Editor instance (required).options.at— Position of the block.options.id— ID of the block (overridesat). One ofatoridis required.
null.
buildBlockData
Builds aYooptaBlockData structure (does not insert into editor).
block.id— Block ID; if omitted, a unique ID is generated.block.type— Block type (plugin name); default:'Paragraph'.block.value— Block content (array of Slate elements).block.meta— Metadata:order,depth,align.
YooptaBlockData object.