Source code, preview, and fullscreen for Vue 3
Three plugins in the Vue 3 editor help users check what they wrote: code for the raw HTML, preview for a sanitized read-only view, and fullscreen for distraction-free editing. Besides the toolbar and menus, a template ref lets your component open the dialogs itself:
<script setup lang="ts">
import { shallowRef, useTemplateRef } from 'vue';
import { Editor, type EditorInstance } from '@erag/text-editor-vue';
const content = shallowRef('<p>Draft</p>');
const editor = useTemplateRef<EditorInstance>('editor');
function showPreview(): void {
editor.value?.openPreview();
}
</script>
<template>
<button type="button" @click="showPreview">Preview</button>
<Editor ref="editor" v-model="content" />
</template>The full list of exposed methods is in the API reference.
Configuration
Enable code, preview, and fullscreen plugins:
const editorConfig: EditorInit = {
plugins: ['code', 'preview', 'fullscreen'],
toolbar: 'undo redo | blocks | bold italic | code preview fullscreen',
sourceCodeEditable: true,
};1. Source Code View (code)
Clicking the Source Code (code) button or opening Tools → Source code launches an interactive HTML code modal.
- Displays raw sanitized HTML structure.
- Allows developers or power users to inspect and directly edit HTML tags.
- Applying changes re-sanitizes and updates the active editor canvas.
Source editing is enabled by default. To keep the dialog available for HTML inspection while preventing changes, set:
const editorConfig: EditorInit = {
sourceCodeEditable: false,
};When disabled, the source textarea is read-only and the Apply button is hidden. The editor's readonly or disabled state also keeps this dialog read-only.
Programmatic invocation:
editor.value?.openSourceCode();2. Live Preview (preview)
Clicking Preview (preview) or opening File → Preview launches a modal dialog rendering the sanitized document inside a clean view-only frame.
- Prevents accidental edits while reviewing.
- Shows exact layout rendering without editor toolbars or chrome.
- Includes a Print button that prints only the preview content.
Programmatic invocation:
editor.value?.openPreview();You can also choose File → Print without opening Preview. The editor creates a temporary print-only portal, calls the browser print dialog, and cleans the portal afterward so the surrounding application page is not part of the printed document. The editor workflow page describes printing alongside undo, paste, and resizing.
3. Fullscreen Editing Mode (fullscreen)
Clicking Fullscreen (fullscreen) expands the editor canvas across the full browser viewport.
- Hides surrounding page elements and navigation sidebars.
- Uses native browser Fullscreen API with automatic fallback for restricted environments.
- The browser's Escape behavior or clicking the Fullscreen button again exits native fullscreen. The CSS fallback can be toggled with the same editor button.