Editor API
The Editor API is the entry point for Yoopta:createYooptaEditor creates an editor instance (YooEditor) that holds content, block/element methods, events, parsers, and history. Use it together with the Blocks, Elements, and Marks APIs.
createYooptaEditor
Creates a Yoopta editor instance.options.plugins— Array of block plugins (required).options.marks— Optional array of mark definitions (e.g. fromcreateYooptaMark).options.value— Optional initial content (YooptaContentValue). If invalid or omitted, one empty paragraph block is used.options.id— Optional editor ID; a unique ID is generated if omitted.options.readOnly— Optional; default:false.
YooEditor instance.
Type Definitions
YooEditor instance
The object returned bycreateYooptaEditor exposes the following. Block and element methods are documented in Blocks API and Elements API.
Content
editor.children— Current content:YooptaContentValue(record of block id → block data).editor.isEmpty()— Returns whether the editor has no meaningful content.editor.getEditorValue()— Returnseditor.children(current content).editor.setEditorValue(value)— Replaces editor content withvalue; ifvalueisnullor invalid, resets to one empty paragraph block.
value—YooptaContentValue | null; usenullor invalid value to reset.
Block methods (on editor)
Available on the instance; see Blocks API for full signatures and options.insertBlock,deleteBlock,updateBlock,getBlockmoveBlock,focusBlock,duplicateBlocktoggleBlock,splitBlock,mergeBlockincreaseBlockDepth,decreaseBlockDepthsetPath(path)— Setseditor.path(e.g. current block index).path: YooptaPath.
Element methods (on editor)
Available on the instance; see Elements API for full signatures and options.insertElement,updateElement,deleteElementgetElement,getElements,getElementEntrygetElementPath,getParentElementPath,getElementRectgetElementChildren,isElementEmpty
Element builder: editor.y
Build Slate elements for use in block/element APIs.editor.y(type, options)— Block element:type(e.g.'paragraph','heading-one'), optionaloptions.props,options.children.editor.y.text(text, marks)— Text node with optional marks (e.g.{ bold: true }).editor.y.inline(type, options)— Inline element (e.g.'link'withprops.url).
Path
editor.path— Current path state:{ current, selected?, selection?, source? }.editor.setPath(path)— Updates path; e.g.editor.setPath({ current: 2 }).
Focus
editor.focus()— Focuses the editor.editor.blur(options?)— Removes focus.editor.isFocused()— Returns whether the editor is focused.
Events
editor.on(event, callback)— Subscribe to event.editor.off(event, callback)— Unsubscribe.editor.once(event, callback)— Subscribe once.editor.emit(event, payload)— Emit event.
'change' (payload: { operations, value }), 'focus', 'blur', 'block:copy', 'path-change'.
Parsers (serialization)
Convert content to different formats. Each parser takes the content to serialize (usuallyeditor.children or the value from onChange).
content—YooptaContentValueto serialize (required).getEmailonly:options— Optional email template options.
History (undo/redo)
editor.undo(options?)— Undo last batch.options.scroll— scroll to block; default:true.editor.redo(options?)— Redo last undone batch. Sameoptions.editor.historyStack—{ undos: HistoryStack[], redos: HistoryStack[] }(internal).editor.isSavingHistory()— Whether history is currently being saved.editor.isMergingHistory()— Whether history is being merged.editor.withoutSavingHistory(fn)— Runfnwithout pushing to history.editor.withSavingHistory(fn)— Runfnwith history saving enabled.editor.withoutMergingHistory(fn)— Runfnwithout merging with previous batch.editor.withMergingHistory(fn)— Runfnwith history merging enabled.
Batch operations and transforms
editor.batchOperations(callback)— Runcallback; all operations performed inside are collected and applied in a single transform. Use for multiple block/element changes that should be one undo step.
callback— Function with no args; call block/element/transform methods inside it.
editor.applyTransforms(operations, options?)— Low-level: apply an array of Yoopta operations. Prefer block/element APIs andbatchOperationsin app code.
Instance properties (read-only / internal)
editor.id— Editor ID.editor.readOnly— Whether the editor is read-only.editor.formats— Built mark format helpers (frommarks).editor.marks— Array of mark definitions passed tocreateYooptaEditor.editor.plugins— Resolved plugin map.editor.blockEditorsMap— Map of block ID to Slate editor (internal).editor.refElement— DOM element ref when used with the editor component.