Skip to content

Events

The editor emits typed events for real-time notifications of all user actions.

Subscribing to Events

Use the imperative API via template ref:

vue
<script setup>
import { ref, onMounted } from 'vue'
import { EmailEditor } from '@lab2view/vue-email-editor'
import '@lab2view/vue-email-editor/style.css'

const editor = ref()

onMounted(() => {
  editor.value.on('editor:change', ({ document }) => {
    console.log('Document changed')
    autoSave(document)
  })

  editor.value.on('node:selected', ({ nodeId, node }) => {
    console.log(`Selected: ${node.type} (${nodeId})`)
  })
})
</script>

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

All Events

editor:ready

Fired once when the editor is fully initialized.

ts
editor.value.on('editor:ready', ({ document }) => {
  console.log('Editor ready with', countNodes(document.body), 'nodes')
})
FieldTypeDescription
documentEmailDocumentThe initial document

editor:change

Fired on every document change (edits, deletes, moves, attribute changes).

ts
editor.value.on('editor:change', ({ document }) => {
  debouncedSave(document)
})
FieldTypeDescription
documentEmailDocumentThe updated document

node:selected

Fired when a node is selected (by click or API).

FieldTypeDescription
nodeIdNodeIdSelected node ID
nodeEmailNodeThe selected node

node:deselected

Fired when the current selection is cleared.

FieldTypeDescription
nodeIdNodeIdPreviously selected node ID

node:deleted

Fired when a node is removed from the document.

FieldTypeDescription
nodeIdNodeIdDeleted node ID

node:moved

Fired when a node changes position in the tree.

FieldTypeDescription
nodeIdNodeIdMoved node ID
fromParentIdNodeIdOriginal parent
toParentIdNodeIdNew parent

node:duplicated

Fired when a node is cloned.

FieldTypeDescription
originalIdNodeIdSource node ID
newIdNodeIdCloned node ID

block:dropped

Fired when a block from the panel is dropped onto the canvas.

FieldTypeDescription
blockIdstringBlock definition ID
parentIdNodeIdTarget parent node

history:undo

Fired after an undo operation.

FieldTypeDescription
canUndobooleanWhether more undos are available
canRedobooleanWhether redo is available

history:redo

Fired after a redo operation.

FieldTypeDescription
canUndobooleanWhether undo is available
canRedobooleanWhether more redos are available

property:changed

Fired when a node attribute is updated via the properties panel.

FieldTypeDescription
nodeIdNodeIdAffected node ID
keystringAttribute name
valuestringNew attribute value

Unsubscribing

ts
const handler = ({ document }) => { /* ... */ }

// Subscribe
editor.value.on('editor:change', handler)

// Unsubscribe
editor.value.off('editor:change', handler)

Released under the MIT License.