Skip to content

API Methods ​

All methods are accessed via a template ref on the <EmailEditor> component.

vue
<script setup>
const editor = ref()
// editor.value.getMjml()
</script>

<template>
  <EmailEditor ref="editor" />
</template>

Export ​

MethodReturnsDescription
getDocument()EmailDocumentGet the current document tree
setDocument(doc)voidReplace the entire document
getMjml()stringSerialize as MJML string
getHtml()stringGet compiled HTML output
getDesignJson()EmailDesignJsonGet the persisted design format
loadTemplate(doc)voidLoad an EmailDocument, resetting history

History ​

MethodReturnsDescription
undo()voidUndo the last change
redo()voidRedo the last undone change
canUndo()booleanWhether undo is available
canRedo()booleanWhether redo is available

Selection ​

MethodReturnsDescription
selectNode(nodeId)voidSelect a node by its ID
getSelectedNode()EmailNode | nullGet the currently selected node
clearSelection()voidDeselect the current node

Manipulation ​

MethodReturnsDescription
deleteNode(nodeId)voidRemove a node from the document
duplicateNode(nodeId)NodeId | nullClone a node, returns new ID
insertBlock(block, parentId, index?)NodeId | nullInsert a block definition
updateNodeAttribute(nodeId, key, value)voidUpdate a single MJML attribute

Events ​

MethodReturnsDescription
on(event, handler)voidSubscribe to an editor event
off(event, handler)voidUnsubscribe from an event

TypeScript Interface ​

ts
interface EmailEditorAPI {
  getDocument: () => EmailDocument
  setDocument: (doc: EmailDocument) => void
  getMjml: () => string
  getHtml: () => string
  getDesignJson: () => EmailDesignJson
  undo: () => void
  redo: () => void
  canUndo: () => boolean
  canRedo: () => boolean
  selectNode: (nodeId: NodeId) => void
  getSelectedNode: () => EmailNode | null
  clearSelection: () => void
  deleteNode: (nodeId: NodeId) => void
  duplicateNode: (nodeId: NodeId) => NodeId | null
  insertBlock: (block: BlockDefinition, parentId: NodeId, index?: number) => NodeId | null
  updateNodeAttribute: (nodeId: NodeId, key: string, value: string) => void
  loadTemplate: (template: EmailDocument) => void
  on: <K extends keyof EditorEventMap>(event: K, handler: (payload: EditorEventMap[K]) => void) => void
  off: <K extends keyof EditorEventMap>(event: K, handler: (payload: EditorEventMap[K]) => void) => void
}

Released under the MIT License.