Skip to content

API reference

This page describes the public surface of @erag/text-editor-vue. The examples use Vue 3, <script setup lang="ts">, and the package's published types.

Runtime exports

ts
import {
    Editor,
    defaultEditorConfig,
    sanitizeHtml,
} from '@erag/text-editor-vue';
ExportPurpose
EditorThe Vue component used to render the editor.
defaultEditorConfigThe resolved default configuration. Treat it as read-only; pass your overrides through init.
sanitizeHtml(html, options)Sanitizes an HTML string using explicit allowedTags, allowedAttributes, and allowRelativeUrls options. It returns an empty string when browser DOM APIs are unavailable; sanitize untrusted HTML on the server as well.

Most consumers should configure init.sanitize and let Editor call the sanitizer. The direct utility is useful when preparing a browser-side preview with the same allowlist.

ts
const safeHtml = sanitizeHtml('<p>Hello</p><script>alert(1)</script>', {
    allowedTags: ['p'],
    allowedAttributes: {},
    allowRelativeUrls: true,
});

Props (EditorProps)

PropTypeDefaultDescription
modelValuestring''HTML controlled by v-model.
initEditorInitpackage defaultsPartial editor configuration. It is normalized reactively and is not mutated.
disabledbooleanfalseDisables editing and editor actions.
readonlybooleanfalsePrevents content changes while keeping safe viewing actions available.
idstringApplied to the editable content element.
namestringAdds a hidden form input containing the current HTML.
ariaLabelstring'Rich text editor'Accessible label for the editing surface. In templates, use aria-label or :aria-label.
vue
<Editor
    id="message-body"
    v-model="content"
    name="body"
    aria-label="Message body"
    :init="editorConfig"
    :disabled="isDisabled"
/>

Events (EditorEmits)

EventPayloadWhen it is emitted
update:modelValuestringHTML actually changed. Duplicate model updates are not emitted.
clickMouseEventThe editable area is clicked.
focusFocusEventThe editable area receives focus.
blurFocusEventThe editable area loses focus.
inputInputEventA native editor input is handled.
changestringOn blur, when HTML changed since the previous committed value.
keydownKeyboardEventA key is pressed in the editor.
pasteClipboardEventA paste action is handled.
readyHTMLElementThe editable root is connected on the client.
selection-changeSelectionThe browser selection changes while the editor is active.
resize{ height: number }The bottom resize handle changes editor height.
mention-searchMentionSearchEventA debounced mention search starts.
mention-selectMentionSelectEventA mention is inserted.
mention-removeMentionRemoveEventA complete mention token is removed.
merge-tag-selectMergeTagSelectEventA merge tag is inserted.
merge-tag-removeMergeTagRemoveEventA complete merge-tag token is removed.
template-insertTemplateInsertEventA configured template is inserted.
image-removeImageDeleteInfoAn image is removed after any configured delete handler succeeds.
vue
<Editor
    v-model="content"
    @ready="handleReady"
    @change="saveDraft"
    @resize="({ height }) => console.log(height)"
    @image-remove="handleImageRemove"
/>

Exposed methods (EditorInstance)

Use a typed template ref when another control needs to call the editor directly.

vue
<script setup lang="ts">
import { useTemplateRef } from 'vue';
import { Editor, type EditorInstance } from '@erag/text-editor-vue';

const editor = useTemplateRef<EditorInstance>('editor');

function insertGreeting(): void {
    editor.value?.focus();
    editor.value?.insertText('Hello ');
}
</script>

<template>
    <button type="button" @click="insertGreeting">Insert greeting</button>
    <Editor ref="editor" />
</template>
MethodResultDescription
focus()voidFocuses the editable area.
blur()voidRemoves focus from it.
getHtml()stringReturns current normalized HTML.
setHtml(value)voidReplaces content and publishes the change.
getText()stringReturns plain text.
clear()voidReplaces content with an empty string.
insertHtml(value)voidSanitizes and inserts HTML at the saved selection.
insertText(value)voidEscapes and inserts plain text.
selectAll()voidSelects the editor content.
undo() / redo()voidMoves through editor history when possible.
openSourceCode()voidOpens the source-code dialog.
openPreview()voidOpens the preview dialog.
getRootElement()HTMLElement | nullReturns the editable root, not the outer editor shell.

Slots

SlotPropsPurpose
toolbar-startContent before toolbar groups.
toolbar-endContent after toolbar groups.
menubar-endContent at the end of the menubar.
statusbar-startContent before the status information.
statusbar-endContent after the status information.
emptyCustom empty-state content inside the editable canvas.
mention-item{ item, active }Custom mention result rendering.
mention-loading{ query }Custom mention loading state.
mention-empty{ query }Custom mention empty state.
mention-error{ query, retry }Custom mention error state.

Slots add presentation only; editor keyboard handling and selection management remain internal.

Released under the MIT License. Copyright © Er Amit Gupta