Vitral 0.2.18
Form

Editor

Rich text with its own engine and no dependency: headings, lists, tables, images, links and Markdown shortcuts, bound as sanitised HTML.

Import

main.ts
import { Editor } from '@vitral/vue';

Default

Release notes

This editor writes semantic HTML, keeps undo history and understands Markdown as you type. Try ## , - or **bold**.

  • Paste from Word or Google Docs

  • Select text and press Ctrl+K for a link

Nothing pasted can run a script: only what the schema knows survives.

Rich text. Alt+F10 moves to the toolbar, Escape comes back. Ctrl+K edits a link, Alt+Enter opens the one under the caret, Ctrl+F finds and Ctrl+H replaces. Markdown shortcuts such as # and - work at the start of a line.
<script setup lang="ts">import { Editor, Label, StackPanel } from '@vitral/vue';import { ref } from 'vue'; const article = ref(    '<h2>Release notes</h2><p>This editor writes <strong>semantic HTML</strong>, keeps <em>undo</em> history and understands <code>Markdown</code> as you type. Try <code>## </code>, <code>- </code> or <code>**bold**</code>.</p>' +        '<ul data-type="taskList"><li data-type="taskItem" data-checked="true"><p>Paste from Word or Google Docs</p></li><li data-type="taskItem" data-checked="false"><p>Select text and press Ctrl+K for a link</p></li></ul>' +        '<blockquote><p>Nothing pasted can run a script: only what the schema knows survives.</p></blockquote>');</script> <template>    <StackPanel spacing="0.375rem" style="width: 100%">        <Label for="ed-article">Article</Label>        <Editor id="ed-article" v-model="article" placeholder="Write something…" />    </StackPanel></template>

Custom toolbar

`toolbar` takes groups of item names; the `toolbar` slot replaces the bar with parts of your own.

Only the basics here.

Rich text. Alt+F10 moves to the toolbar, Escape comes back. Ctrl+K edits a link, Alt+Enter opens the one under the caret, Ctrl+F finds and Ctrl+H replaces. Markdown shortcuts such as # and - work at the start of a line.


Rich text. Alt+F10 moves to the toolbar, Escape comes back. Ctrl+K edits a link, Alt+Enter opens the one under the caret, Ctrl+F finds and Ctrl+H replaces. Markdown shortcuts such as # and - work at the start of a line.
<script setup lang="ts">import { Editor, EditorButton, EditorToolbar, EditorToolbarGroup, StackPanel } from '@vitral/vue';import { ref } from 'vue'; const note = ref('<p>Only the basics here.</p>');</script> <template>    <StackPanel spacing="1rem" style="width: 100%">        <Editor v-model="note" :toolbar="[['bold', 'italic', 'strike'], ['bulletList', 'orderedList'], ['link', 'undo', 'redo']]" aria-label="Note" />        <Editor aria-label="Minimal" placeholder="The toolbar slot">            <template #toolbar>                <EditorToolbar>                    <EditorToolbarGroup>                        <EditorButton command="heading2" />                        <EditorButton command="bold" />                        <EditorButton command="italic" />                    </EditorToolbarGroup>                    <EditorToolbarGroup>                        <EditorButton command="clear" show-label />                    </EditorToolbarGroup>                </EditorToolbar>            </template>        </Editor>    </StackPanel></template>

Slash menu and block actions

Type `/` where a word starts and the blocks are offered, filtered as you type; Enter or a press puts one in. Beside the block the caret is in there is a handle, and it opens duplicate, move, turn into text and delete. `slash-menu` and `block-menu` take your own entries, or `false` for none.

Type a slash on the empty line under this one.


Rich text. Alt+F10 moves to the toolbar, Escape comes back. Ctrl+K edits a link, Alt+Enter opens the one under the caret, Ctrl+F finds and Ctrl+H replaces. Markdown shortcuts such as # and - work at the start of a line.

This one offers three commands of its own.


Rich text. Alt+F10 moves to the toolbar, Escape comes back. Ctrl+K edits a link, Alt+Enter opens the one under the caret, Ctrl+F finds and Ctrl+H replaces. Markdown shortcuts such as # and - work at the start of a line.
<script setup lang="ts">import { Editor, StackPanel } from '@vitral/vue';import { ref } from 'vue'; const blocks = ref('<p>Type a slash on the empty line under this one.</p><p></p>');const custom = ref('<p>This one offers three commands of its own.</p><p></p>'); // A slash command is data: a name, a line about it, and either a command the// editor knows or a `run` of your own.const slashCommands = [    { id: 'heading2', label: 'Section', description: 'A heading for a section', icon: 'heading2', command: ['toggleHeading', 2] as const },    { id: 'taskList', label: 'Checklist', description: 'Things to tick off', icon: 'listChecks', command: ['toggleTaskList'] as const },    {        id: 'today',        label: "Today's date",        description: 'Puts the date in, as text',        icon: 'calendar',        keywords: ['date', 'now'],        run: (editor: { run: (name: string, ...args: unknown[]) => boolean }) => editor.run('insertText', new Date().toLocaleDateString())    }];</script> <template>    <StackPanel spacing="1rem" style="width: 100%">        <Editor v-model="blocks" aria-label="Slash menu example" :toolbar="[['blockType'], ['bold', 'italic']]" />        <Editor            v-model="custom"            aria-label="Own slash commands"            :toolbar="false"            :slash-menu="slashCommands"            :block-menu="[{ id: 'delete', label: 'Delete', icon: 'trash', run: (editor) => editor.run('deleteBlock') }]"        />    </StackPanel></template>

Find and replace

Ctrl+F (⌘F) opens the bar over the text and Ctrl+H (⌘⌥F) opens it with the replace row; so does the `find` toolbar item. Every match is washed in yellow and the one in hand in orange, painted with highlights rather than written into the document, so undo, the caret and a screen reader see only the text. Match case, whole words and regular expressions — where `$1` works in the replacement — are toggles beside the field. Enter goes to the next match and Shift+Enter to the one before; a replacement keeps the formatting of the words it replaces, and Replace all is one step to undo. `:find="false"` leaves the keys to the browser.

Release notes

The colour tokens are now grouped by colour role, and every colour a chart uses is a token of its own.

Colour contrast was checked against WCAG AA in both colour schemes.

--vt-chart-1: colour-1;
Rich text. Alt+F10 moves to the toolbar, Escape comes back. Ctrl+K edits a link, Alt+Enter opens the one under the caret, Ctrl+F finds and Ctrl+H replaces. Markdown shortcuts such as # and - work at the start of a line.
<script setup lang="ts">import { Editor } from '@vitral/vue';import { ref } from 'vue'; const text = ref(    '<h3>Release notes</h3><p>The <strong>colour</strong> tokens are now grouped by colour role, and every colour a chart uses is a token of its own.</p><p>Colour contrast was checked against WCAG AA in both colour schemes.</p><pre><code>--vt-chart-1: colour-1;</code></pre>');</script> <template>    <Editor v-model="text" :toolbar="[['bold', 'italic', 'link'], ['undo', 'redo'], ['find']]" aria-label="Release notes" style="width: 100%" /></template>

Inline chips

A chip is one piece in the line — a person, a tag, a variable — that the caret goes around and one Backspace removes. `chips` takes a trigger per kind: type @ or # and pick from the list, which `items` may fill later, from a server. `run('insertChip', { id, label, kind })` puts one in from code. The HTML keeps what each chip stands for, in `data-chip`.

Ask Ana Souza about the release, and tag it urgent. Type @ or # on the line below.


Rich text. Alt+F10 moves to the toolbar, Escape comes back. Ctrl+K edits a link, Alt+Enter opens the one under the caret, Ctrl+F finds and Ctrl+H replaces. Markdown shortcuts such as # and - work at the start of a line.
<script setup lang="ts">import { Button, Editor, type ChipTrigger } from '@vitral/vue';import { ref } from 'vue'; const text = ref(    '<p>Ask <span data-chip="u1" data-kind="mention" contenteditable="false">Ana Souza</span> about the release, and tag it <span data-chip="t-urgent" data-kind="tag" contenteditable="false">urgent</span>. Type @ or # on the line below.</p><p></p>');const editor = ref<InstanceType<typeof Editor> | null>(null); const people = [    { id: 'u1', label: 'Ana Souza', description: 'Product designer' },    { id: 'u2', label: 'Bruno Lima', description: 'Engineer' },    { id: 'u3', label: 'Carla Dias', description: 'Support' }]; // One trigger a kind. `items` can answer at once, or later — here the tags// stand in for a search on the server.const chips: ChipTrigger[] = [    { char: '@', kind: 'mention', items: (q) => people.filter((p) => p.label.toLowerCase().includes(q.toLowerCase())) },    {        char: '#',        kind: 'tag',        items: (q) =>            new Promise((resolve) =>                setTimeout(() => resolve(['urgent', 'design', 'backend', q].filter((t, i, all) => t && all.indexOf(t) === i && t.includes(q.toLowerCase())).map((t) => ({ id: `t-${t}`, label: t }))), 150)            )    }]; // A chip can be put in from code too: a variable a template fills in later.function insertVariable(name: string) {    editor.value?.editor?.run('insertChip', { id: name, label: name, kind: 'variable' });    editor.value?.focus();}</script> <template>    <div style="display: flex; flex-direction: column; gap: 0.5rem; width: 100%">        <div style="display: flex; flex-wrap: wrap; gap: 0.5rem">            <Button label="first_name" icon="plus" size="small" variant="outlined" severity="secondary" @click="insertVariable('first_name')" />            <Button label="order_id" icon="plus" size="small" variant="outlined" severity="secondary" @click="insertVariable('order_id')" />        </div>        <Editor ref="editor" v-model="text" :chips="chips" aria-label="Inline chips" style="width: 100%" />    </div></template>

Formulas

A formula is written in LaTeX — `\frac{a}{b}`, `\sqrt{x}`, `x^2` — and drawn. The Σ button in the toolbar and `/formula` open the panel: the source in a box, the formula drawn above it as you type, and the usual ones ready-made on buttons. In the text, press a number or a letter of a formula and it is edited where it stands, the formula redrawn around it with every key; Tab goes to the next value, Enter keeps it, Escape puts it back. A press anywhere else on the formula opens the panel with that piece selected. The drawing is outlines laid out by Vitral, not text the browser sets, so it is the same in every browser and prints as it looks; the HTML keeps the source in `data-math`.

Quadratic equations

The roots of are

The mean of a sample is , and the area of a circle is . Press the 4, the 2 or a letter above to change it where it stands; press the fraction bar to open the whole formula.

Rich text. Alt+F10 moves to the toolbar, Escape comes back. Ctrl+K edits a link, Alt+Enter opens the one under the caret, Ctrl+F finds and Ctrl+H replaces. Markdown shortcuts such as # and - work at the start of a line.
<script setup lang="ts">import { Button, Editor } from '@vitral/vue';import { ref } from 'vue'; // A formula is its LaTeX, in `data-math`. The drawing around it is made from// that, here and in the HTML the editor hands back.const text = ref(    '<h2>Quadratic equations</h2>' +        '<p>The roots of <span data-math="ax^2 + bx + c = 0"></span> are <span data-math="x = \\frac{-b \\pm \\sqrt{b^2 - 4ac}}{2a}" data-display="true"></span></p>' +        '<p>The mean of a sample is <span data-math="\\overline{x} = \\frac{1}{n} \\sum_{i=1}^{n} x_i"></span>, and the area of a circle is <span data-math="\\pi r^2"></span>. Press the 4, the 2 or a letter above to change it where it stands; press the fraction bar to open the whole formula.</p>');const editor = ref<InstanceType<typeof Editor> | null>(null); // From code: a formula is put in where the caret is.function insert(latex: string) {    editor.value?.editor?.run('insertMath', { latex });    editor.value?.focus();} // The HTML carries the formulas as drawings, so it prints as it looks: into a// frame of its own, and the browser's print dialog saves it as a PDF.function print() {    const frame = document.createElement('iframe');    frame.style.cssText = 'position:fixed;width:0;height:0;border:0';    frame.srcdoc = `<!doctype html><meta charset="utf-8"><title>Document</title><style>body{font:16px/1.6 system-ui,sans-serif;margin:2rem;color:#111}</style>${editor.value?.getHTML() ?? ''}`;    frame.onload = () => {        frame.contentWindow?.print();        setTimeout(() => frame.remove(), 1000);    };    document.body.appendChild(frame);}</script> <template>    <div style="display: flex; flex-direction: column; gap: 0.5rem; width: 100%">        <div style="display: flex; flex-wrap: wrap; gap: 0.5rem">            <Button label="Pythagoras" icon="plus" size="small" variant="outlined" severity="secondary" @click="insert('a^2 + b^2 = c^2')" />            <Button label="Fraction" icon="plus" size="small" variant="outlined" severity="secondary" @click="insert('\\frac{1}{2}')" />            <Button label="Print or save as PDF" icon="download" size="small" variant="text" @click="print" />        </div>        <Editor ref="editor" v-model="text" aria-label="Formulas" style="width: 100%" />    </div></template>

Formulas: your own, or none

`math` takes `{ templates, inlineEdit }`: the ready-made formulas the panel offers, and whether a value is edited where it stands (`false` opens the panel instead). `:math="false"` still draws the formulas a document has and takes away every way of making or changing one: no button, no slash entry, no press.

Formulas of your own, edited in the panel

Water is , and it forms by .

Rich text. Alt+F10 moves to the toolbar, Escape comes back. Ctrl+K edits a link, Alt+Enter opens the one under the caret, Ctrl+F finds and Ctrl+H replaces. Markdown shortcuts such as # and - work at the start of a line.
Formulas switched off

The answer sheet: . The text around the formula can be changed; the formula cannot.

Rich text. Alt+F10 moves to the toolbar, Escape comes back. Ctrl+K edits a link, Alt+Enter opens the one under the caret, Ctrl+F finds and Ctrl+H replaces. Markdown shortcuts such as # and - work at the start of a line.
<script setup lang="ts">import { Editor, type EditorMathOptions } from '@vitral/vue';import { ref } from 'vue'; // The formulas a chemistry class writes, in place of the usual ones; and a// press on a value opens the panel rather than a box over it.const chemistry: EditorMathOptions = {    templates: [        { id: 'water', label: 'Water', latex: 'H_2O' },        { id: 'reaction', label: 'Reaction', latex: '2H_2 + O_2 \\to 2H_2O' },        { id: 'concentration', label: 'Concentration', latex: 'C = \\frac{n}{V}' },        { id: 'ph', label: 'pH', latex: '\\text{pH} = -\\log \\left[ H^+ \\right]' }    ],    inlineEdit: false}; const lesson = ref('<p>Water is <span data-math="H_2O"></span>, and it forms by <span data-math="2H_2 + O_2 \\to 2H_2O"></span>.</p>');const fixed = ref('<p>The answer sheet: <span data-math="x = \\frac{-b \\pm \\sqrt{b^2 - 4ac}}{2a}"></span>. The text around the formula can be changed; the formula cannot.</p>');</script> <template>    <div style="display: grid; grid-template-columns: repeat(auto-fit, minmax(18rem, 1fr)); gap: 1rem; width: 100%">        <div style="display: flex; flex-direction: column; gap: 0.375rem">            <span id="ed-math-own">Formulas of your own, edited in the panel</span>            <Editor v-model="lesson" :math="chemistry" aria-labelledby="ed-math-own" />        </div>        <div style="display: flex; flex-direction: column; gap: 0.375rem">            <span id="ed-math-off">Formulas switched off</span>            <Editor v-model="fixed" :math="false" aria-labelledby="ed-math-off" />        </div>    </div></template>

Formulas: what comes out

The HTML is where a document's formulas leave with it. By default each goes with its drawing inside, so the HTML shows them on any page and prints as it looks — the button opens the browser's print dialog, which saves a PDF. `:math="{ output: 'source' }"` writes the LaTeX alone: a fraction of the size to store, and `renderMathIn(element)` from `@vitral/core` draws it where the document is shown. `getHTML({ math })` asks for either one at any time, `renderMathHTML(html, 'drawing' | 'source')` turns stored HTML from one into the other without a page, and `editorFormulas(doc)` lists the formulas as strings. JSON, plain text and Markdown carry the LaTeX.

Mathematics — test 3

1. Solve and say which root is the larger.

2. Simplify

3. The mean of the marks is . Find it for 6, 8 and 10.

Rich text. Alt+F10 moves to the toolbar, Escape comes back. Ctrl+K edits a link, Alt+Enter opens the one under the caret, Ctrl+F finds and Ctrl+H replaces. Markdown shortcuts such as # and - work at the start of a line.
The model (v-model), 0.3 KB
<h2>Mathematics — test 3</h2><p>1. Solve <span data-math="x^2 - 5x + 6 = 0"></span> and say which root is the larger.</p><p>2. Simplify <span data-math="\frac{6a^2 b}{3ab}" data-display="true"></span></p><p>3. The mean of the marks is <span data-math="\overline{x} = \frac{1}{n} \sum_{i=1}^{n} x_i"></span>. Find it for 6, 8 and 10.</p>
With drawings: 9.9 KB · source alone: 0.5 KB
The formulas, as strings
x^2 - 5x + 6 = 0
\frac{6a^2 b}{3ab}
\overline{x} = \frac{1}{n} \sum_{i=1}^{n} x_i
A page without the editor

Mathematics — test 3

1. Solve and say which root is the larger.

2. Simplify

3. The mean of the marks is . Find it for 6, 8 and 10.

The source-only HTML, drawn with renderMathIn
<script setup lang="ts">import { editorFormulas, loadMath, renderMathIn } from '@vitral/core';import { Button, Editor, SelectButton, type EditorMathOptions } from '@vitral/vue';import { computed, nextTick, onMounted, ref, watch } from 'vue'; // An exam, with its formulas given as their source alone: that is all the// editor needs to be handed.const text = ref(    '<h2>Mathematics — test 3</h2>' +        '<p>1. Solve <span data-math="x^2 - 5x + 6 = 0"></span> and say which root is the larger.</p>' +        '<p>2. Simplify <span data-math="\\frac{6a^2 b}{3ab}" data-display="true"></span></p>' +        '<p>3. The mean of the marks is <span data-math="\\overline{x} = \\frac{1}{n} \\sum_{i=1}^{n} x_i"></span>. Find it for 6, 8 and 10.</p>'); // How the model's HTML carries a formula: with its drawing, or as its source.const output = ref<'drawing' | 'source'>('drawing');const math = computed<EditorMathOptions>(() => ({ output: output.value })); const editor = ref<InstanceType<typeof Editor> | null>(null);const page = ref<HTMLElement | null>(null);const formulas = ref<string[]>([]);const sizes = ref({ drawing: 0, source: 0 }); async function read() {    const instance = editor.value;    if (!instance?.editor) return;    // The formulas as strings: what a search index, a marking script or another system wants.    formulas.value = editorFormulas(instance.editor.state.doc).map((formula) => formula.latex);    // Either HTML can be asked for, whatever the model holds. The drawings need the renderer, which    // the first formula shown sends for: waiting on it here covers a document read before it has come.    await loadMath();    sizes.value = { drawing: instance.getHTML({ math: 'drawing' }).length, source: instance.getHTML({ math: 'source' }).length };    // A page that shows the document without the editor: the small HTML goes in, and its formulas are drawn from their source.    if (page.value) {        page.value.innerHTML = instance.getHTML({ math: 'source' });        await renderMathIn(page.value);    }} onMounted(() => nextTick(read));watch([text, output], () => nextTick(read)); const kb = (characters: number) => `${(characters / 1024).toFixed(1)} KB`; // The HTML with the drawings prints as it looks: into a frame of its own, and// the browser's print dialog saves it as a PDF.function print() {    const frame = document.createElement('iframe');    frame.style.cssText = 'position:fixed;width:0;height:0;border:0';    frame.srcdoc = `<!doctype html><meta charset="utf-8"><title>Test</title><style>body{font:16px/1.7 system-ui,sans-serif;margin:2.5rem;color:#111}</style>${editor.value?.getHTML({ math: 'drawing' }) ?? ''}`;    frame.onload = () => {        frame.contentWindow?.print();        setTimeout(() => frame.remove(), 1000);    };    document.body.appendChild(frame);}</script> <template>    <div style="display: flex; flex-direction: column; gap: 0.75rem; width: 100%">        <div style="display: flex; flex-wrap: wrap; align-items: center; gap: 0.75rem">            <SelectButton v-model="output" :options="['drawing', 'source']" label="How the model's HTML carries a formula" :allow-empty="false" />            <Button label="Print or save as PDF" icon="download" size="small" variant="outlined" severity="secondary" @click="print" />        </div>        <Editor ref="editor" v-model="text" :math="math" aria-label="Exam" style="width: 100%" />        <div style="display: grid; grid-template-columns: repeat(auto-fit, minmax(17rem, 1fr)); gap: 1rem; width: 100%">            <div style="display: flex; flex-direction: column; gap: 0.375rem; min-width: 0">                <strong style="font-size: 0.8125rem">The model (v-model), {{ kb(text.length) }}</strong>                <pre class="demo-output" aria-label="The model's HTML" tabindex="0" style="margin: 0; max-height: 14rem; overflow: auto; white-space: pre-wrap; word-break: break-all; font-size: 0.6875rem">{{ text }}</pre>                <small style="color: var(--vt-text-muted-color)">With drawings: {{ kb(sizes.drawing) }} · source alone: {{ kb(sizes.source) }}</small>            </div>            <div style="display: flex; flex-direction: column; gap: 0.375rem; min-width: 0">                <strong style="font-size: 0.8125rem">The formulas, as strings</strong>                <pre class="demo-output" aria-label="The formulas as LaTeX" tabindex="0" style="margin: 0; max-height: 14rem; overflow: auto; white-space: pre-wrap; font-size: 0.75rem">{{ formulas.join('\n') }}</pre>            </div>            <div style="display: flex; flex-direction: column; gap: 0.375rem; min-width: 0">                <strong style="font-size: 0.8125rem">A page without the editor</strong>                <div ref="page" aria-label="The document, shown without the editor" style="padding: 0.75rem 1rem; border: 1px solid var(--vt-content-border-color); border-radius: 0.5rem; max-height: 14rem; overflow: auto; line-height: 1.7" />                <small style="color: var(--vt-text-muted-color)">The source-only HTML, drawn with renderMathIn</small>            </div>        </div>    </div></template>

Formulas: one on its own

Outside the editor a formula is a function of its source. `renderMath(latex, { fontSize, color, display })` from `@vitral/core` gives the SVG as a file: sized in pixels and in a colour of its own, which is what a PDF library draws (pdfmake's `svg`, pdfkit and jsPDF through their SVG plugins) and what a server can write with no browser. `renderMathDataUri` gives the same as an address for an `<img>`, and `renderMathPng` a picture, in the browser, for what only takes pictures. Without a `fontSize` the drawing is the piece of a line a page wants, sized by the text around it.

x = \frac{-b \pm \sqrt{b^2 - 4ac}}{2a}
<svg xmlns="http://www.w3.org/2000/svg" role="img" aria-label="x = \frac{-b \pm \sqrt{b^2 - 4ac}}{2a}" viewBox="-40 -2047.9 8559.4 2770.9" width="239.66" height="77.59" fill="#111827"><g transform="translate(0 0)"><g transform="translate(0 0)"><path d="M0 0 232-276 116-536H205L288-338L445-536H547L324-272L447 0H358L267-208L102 0Z"/></g></g><g transform="translate(798 0)"><g transform="translate(0 0)"><path d="M51-342V-413H521V-342ZM51-143V-214H521V-143Z"/></g></g><g transform="translate(1648 0)"><g transform="translate(110 -704)"><g transform="translate(0 0)"><g transform="translate(0 0)"><path d="M51-242V-313H521V-242Z"/></g></g><g transform="translate(572 0)"><g transform="translate(0 0)"><path d="M269 10Q215 10 182-18Q148-45 132-82H127L94 0H28L189-760H277L239-580Q232-546 224-514Q215-481 209-460Q203-438 202-436H206Q242-480 284-512Q327-545 383-545Q449-545 490-499Q530-453 530-363Q530-290 512-223Q494-156 460-104Q426-51 378-20Q330 10 269 10ZM262-63Q302-63 335-88Q368-114 392-157Q415-200 428-254Q440-308 440-364Q440-472 355-472Q322-472 288-448Q253-423 224-380Q195-338 178-284Q160-230 160-171Q160-123 185-93Q210-63 262-63Z"/></g></g><g transform="translate(1373 0)"><g transform="translate(0 0)"><path d="M250-36V-242H51V-313H250V-520H322V-313H521V-242H322V-36ZM51-36V-107H521V-36Z"/></g></g><g transform="translate(2167 0)"><g transform="translate(0 186.1)"><path d="M315 0 138-580H50V-650H196L351-121L706-1419H780L389 0Z"/></g><rect x="746" y="-1232.9" width="3698.4" height="71"/><g transform="translate(746 0)"><g transform="translate(0 0)"><g transform="translate(0 0)"><g transform="translate(0 0)"><path d="M269 10Q215 10 182-18Q148-45 132-82H127L94 0H28L189-760H277L239-580Q232-546 224-514Q215-481 209-460Q203-438 202-436H206Q242-480 284-512Q327-545 383-545Q449-545 490-499Q530-453 530-363Q530-290 512-223Q494-156 460-104Q426-51 378-20Q330 10 269 10ZM262-63Q302-63 335-88Q368-114 392-157Q415-200 428-254Q440-308 440-364Q440-472 355-472Q322-472 288-448Q253-423 224-380Q195-338 178-284Q160-230 160-171Q160-123 185-93Q210-63 262-63Z"/></g></g><g transform="translate(609 -390)"><g transform="translate(0 0)"><path d="M48 0V-73L235-262Q289-316 326-358Q363-400 382-440Q401-481 401-529Q401-588 366-618Q331-649 275-649Q223-649 184-631Q144-613 103-581L56-640Q98-675 152-700Q207-724 275-724Q375-724 433-674Q491-623 491-534Q491-478 468-430Q445-381 404-333Q363-285 308-231L159-84V-80H520V0Z" transform="scale(0.7 0.7)"/></g></g></g><g transform="translate(1271.4 0)"><g transform="translate(0 0)"><path d="M51-242V-313H521V-242Z"/></g></g><g transform="translate(2065.4 0)"><g transform="translate(0 0)"><path d="M363 0V-162H21V-237L357-718H448V-241H552V-162H448V0ZM107-241H363V-466Q363-518 364-554Q366-591 368-624H364Q356-605 344-583Q332-561 321-546Z"/></g></g><g transform="translate(2637.4 0)"><g transform="translate(0 0)"><path d="M197 10Q125 10 84-30Q44-71 44-129Q44-196 84-237Q124-278 190-298Q257-318 337-320L429-323L436-355Q438-363 439-373Q440-383 440-400Q440-432 416-453Q392-474 340-474Q315-474 270-468Q226-461 169-433L150-495Q193-521 246-533Q298-545 345-545Q409-545 448-526Q488-506 506-473Q525-440 525-400Q525-378 523-362Q521-345 517-328L446 0H382L381-76H377Q333-32 292-11Q251 10 197 10ZM214-61Q260-61 300-86Q341-110 370-148Q399-187 408-229L415-262L335-259Q279-257 234-245Q188-233 162-207Q135-181 135-136Q135-103 158-82Q180-61 214-61Z"/></g></g><g transform="translate(3205.4 0)"><g transform="translate(0 0)"><path d="M247 10Q158 10 103-40Q48-90 48-190Q48-262 68-326Q87-391 124-440Q160-489 212-518Q264-546 328-546Q363-546 398-539Q433-532 461-520L436-447Q416-456 388-464Q361-472 329-472Q272-472 229-434Q186-395 162-331Q138-267 138-191Q138-130 170-96Q201-63 256-63Q291-63 322-73Q354-83 385-96V-22Q357-8 322 1Q288 10 247 10Z"/></g></g></g></g></g><rect x="0" y="-313.5" width="6831.4" height="71"/><g transform="translate(2845.7 673)"><g transform="translate(0 0)"><g transform="translate(0 0)"><path d="M48 0V-73L235-262Q289-316 326-358Q363-400 382-440Q401-481 401-529Q401-588 366-618Q331-649 275-649Q223-649 184-631Q144-613 103-581L56-640Q98-675 152-700Q207-724 275-724Q375-724 433-674Q491-623 491-534Q491-478 468-430Q445-381 404-333Q363-285 308-231L159-84V-80H520V0Z"/></g></g><g transform="translate(572 0)"><g transform="translate(0 0)"><path d="M197 10Q125 10 84-30Q44-71 44-129Q44-196 84-237Q124-278 190-298Q257-318 337-320L429-323L436-355Q438-363 439-373Q440-383 440-400Q440-432 416-453Q392-474 340-474Q315-474 270-468Q226-461 169-433L150-495Q193-521 246-533Q298-545 345-545Q409-545 448-526Q488-506 506-473Q525-440 525-400Q525-378 523-362Q521-345 517-328L446 0H382L381-76H377Q333-32 292-11Q251 10 197 10ZM214-61Q260-61 300-86Q341-110 370-148Q399-187 408-229L415-262L335-259Q279-257 234-245Q188-233 162-207Q135-181 135-136Q135-103 158-82Q180-61 214-61Z"/></g></g></g></g></svg>
<script setup lang="ts">import { renderMath, renderMathDataUri, renderMathPng } from '@vitral/core';import { Button, InputNumber, InputText, Label } from '@vitral/vue';import { ref, watch } from 'vue'; // A formula with no editor around it: from its source to a drawing that// stands on its own, for whatever builds the PDF of an exam.const latex = ref('x = \\frac{-b \\pm \\sqrt{b^2 - 4ac}}{2a}');const fontSize = ref(28);const color = ref('#111827'); const image = ref('');const svg = ref(''); watch(    [latex, fontSize, color],    async () => {        const options = { display: true, fontSize: fontSize.value || 16, color: color.value };        // The drawing as a file: a size in pixels and a colour of its own.        svg.value = await renderMath(latex.value, options);        // The same, as an address an <img> takes.        image.value = await renderMathDataUri(latex.value, options);    },    { immediate: true }); function save(name: string, blob: Blob) {    const link = document.createElement('a');    link.href = URL.createObjectURL(blob);    link.download = name;    link.click();    setTimeout(() => URL.revokeObjectURL(link.href), 1000);} const saveSvg = () => save('formula.svg', new Blob([svg.value], { type: 'image/svg+xml' }));// A picture, for what does not take drawings: three pixels for each one, so it prints sharp.const savePng = async () => save('formula.png', await renderMathPng(latex.value, { display: true, fontSize: fontSize.value || 16, color: color.value, scale: 3, background: '#ffffff' }));const copy = () => navigator.clipboard?.writeText(latex.value);</script> <template>    <div style="display: flex; flex-direction: column; gap: 0.75rem; width: 100%">        <div style="display: flex; flex-wrap: wrap; align-items: end; gap: 0.75rem">            <div style="display: flex; flex-direction: column; gap: 0.375rem; flex: 1 1 18rem">                <Label for="fx-latex">Formula, in LaTeX</Label>                <InputText id="fx-latex" v-model="latex" fluid spellcheck="false" />            </div>            <div style="display: flex; flex-direction: column; gap: 0.375rem">                <Label for="fx-size">Size, in pixels</Label>                <InputNumber id="fx-size" v-model="fontSize" :min="8" :max="96" style="width: 7rem" />            </div>            <div style="display: flex; flex-direction: column; gap: 0.375rem">                <Label for="fx-color">Colour</Label>                <InputText id="fx-color" v-model="color" style="width: 7rem" spellcheck="false" />            </div>        </div>        <!-- An ordinary image: the formula is a file now, and has nothing of the page in it. -->        <div style="display: flex; align-items: center; justify-content: center; min-height: 6rem; padding: 1rem; overflow: auto; background: #ffffff; border: 1px solid var(--vt-content-border-color); border-radius: 0.5rem">            <img v-if="image" :src="image" :alt="latex" />        </div>        <div style="display: flex; flex-wrap: wrap; gap: 0.5rem">            <Button label="Download SVG" icon="download" size="small" @click="saveSvg" />            <Button label="Download PNG" icon="download" size="small" variant="outlined" @click="savePng" />            <Button label="Copy LaTeX" icon="copy" size="small" variant="text" severity="secondary" @click="copy" />        </div>        <pre class="demo-output" aria-label="The SVG" tabindex="0" style="margin: 0; max-height: 8rem; overflow: auto; white-space: pre-wrap; word-break: break-all; font-size: 0.6875rem">{{ svg }}</pre>    </div></template>

Bubble toolbar

`bubble-menu` shows a toolbar over selected text; with `:toolbar="false"` it is the only one.

Select some of this text: a floating toolbar appears over it, with bold, italic, a link and a colour.

Rich text. Alt+F10 moves to the toolbar, Escape comes back. Ctrl+K edits a link, Alt+Enter opens the one under the caret, Ctrl+F finds and Ctrl+H replaces. Markdown shortcuts such as # and - work at the start of a line.
<script setup lang="ts">import { Editor } from '@vitral/vue';import { ref } from 'vue'; const bubble = ref('<p>Select some of this text: a floating toolbar appears over it, with bold, italic, a link and a colour.</p>');</script> <template>    <Editor v-model="bubble" :toolbar="false" bubble-menu aria-label="Bubble toolbar example" style="width: 100%" /></template>

Read only

Terms

Read-only text can still be selected and copied, and links open.

  1. First

  2. Second

Rich text. Alt+F10 moves to the toolbar, Escape comes back. Ctrl+K edits a link, Alt+Enter opens the one under the caret, Ctrl+F finds and Ctrl+H replaces. Markdown shortcuts such as # and - work at the start of a line.
<script setup lang="ts">import { Editor } from '@vitral/vue';import { ref } from 'vue'; const terms = ref(    '<h3>Terms</h3><p>Read-only text can still be <mark data-color="yellow">selected and copied</mark>, and <a href="https://example.com" target="_blank">links</a> open.</p><ol><li><p>First</p></li><li><p>Second</p></li></ol>');</script> <template>    <Editor v-model="terms" readonly :toolbar="false" aria-label="Terms" style="width: 100%" /></template>

With count and limit

`max-length` stops typing and pasting at the limit; the count describes the text.

Keep it short.

Rich text. Alt+F10 moves to the toolbar, Escape comes back. Ctrl+K edits a link, Alt+Enter opens the one under the caret, Ctrl+F finds and Ctrl+H replaces. Markdown shortcuts such as # and - work at the start of a line.
<script setup lang="ts">import { Editor, Label, StackPanel } from '@vitral/vue';import { ref } from 'vue'; const bio = ref('<p>Keep it short.</p>');</script> <template>    <StackPanel spacing="0.375rem" style="width: 100%">        <Label for="ed-bio">Bio</Label>        <Editor id="ed-bio" v-model="bio" :max-length="140" :toolbar="[['bold', 'italic', 'link']]" />    </StackPanel></template>

HTML and JSON output

Type here and watch both formats change.

Rich text. Alt+F10 moves to the toolbar, Escape comes back. Ctrl+K edits a link, Alt+Enter opens the one under the caret, Ctrl+F finds and Ctrl+H replaces. Markdown shortcuts such as # and - work at the start of a line.
<p>Type here and watch <strong>both</strong> formats change.</p>
null
<script setup lang="ts">import { Editor, type EditorJSON } from '@vitral/vue';import { ref } from 'vue'; const output = ref('<p>Type here and watch <strong>both</strong> formats change.</p>');const outputJson = ref<EditorJSON | null>(null);</script> <template>    <Editor v-model="output" v-model:json="outputJson" aria-label="Output example" :toolbar="[['blockType'], ['bold', 'italic', 'color', 'highlight'], ['bulletList', 'link']]" style="width: 100%" />    <div style="display: grid; grid-template-columns: repeat(auto-fit, minmax(16rem, 1fr)); gap: 1rem; width: 100%">        <pre class="demo-output" aria-label="HTML" tabindex="0" style="margin: 0; max-height: 16rem; overflow: auto; white-space: pre-wrap; font-size: 0.75rem">{{ output }}</pre>        <pre class="demo-output" aria-label="JSON" tabindex="0" style="margin: 0; max-height: 16rem; overflow: auto; font-size: 0.75rem">{{ JSON.stringify(outputJson, null, 2) }}</pre>    </div></template>

Composed from parts

`Editor.Root`, `Editor.Toolbar`, `Editor.Button`, `Editor.Content`, `Editor.BubbleMenu`, `Editor.Footer` and `Editor.Count`, also exported as `EditorRoot`, `EditorToolbar`… share one editor; `useEditor()` reaches it from your own components.

This one is built from parts, with a toolbar of its own and a word count.

Rich text. Alt+F10 moves to the toolbar, Escape comes back. Ctrl+K edits a link, Alt+Enter opens the one under the caret, Ctrl+F finds and Ctrl+H replaces. Markdown shortcuts such as # and - work at the start of a line.
<script setup lang="ts">import { Editor } from '@vitral/vue';import { ref } from 'vue'; const composed = ref('<p>This one is built from parts, with a toolbar of its own and a word count.</p>');const words = ref(0);</script> <template>    <Editor.Root v-model="composed" placeholder="Parts…" aria-label="Composed editor" style="width: 100%" @text-change="words = $event.textValue.split(/\s+/).filter(Boolean).length">        <Editor.Toolbar>            <Editor.ToolbarGroup>                <Editor.BlockSelect :options="['paragraph', 'heading1', 'heading2']" />            </Editor.ToolbarGroup>            <Editor.ToolbarGroup>                <Editor.Button command="bold" />                <Editor.Button command="italic" />                <Editor.ColorPicker kind="highlight" />                <Editor.Button command="link" />            </Editor.ToolbarGroup>            <Editor.ToolbarGroup>                <Editor.Button command="taskList" />                <Editor.ImageButton />                <Editor.TableMenu />            </Editor.ToolbarGroup>        </Editor.Toolbar>        <Editor.Content />        <Editor.BubbleMenu :items="['bold', 'italic', 'link']" />        <Editor.Footer>            <span style="margin-inline-end: auto">Edited words: {{ words }}</span>            <Editor.Count :words="false" />        </Editor.Footer>    </Editor.Root></template>

API

Read from packages/vue/src/components/Editor/types.ts, so it says what the component actually accepts.

Props

NameTypeDescription
placeholder string—
readonly booleanThe text can be read, selected and copied, not changed.
disabled boolean—
invalid boolean—
variant InputVariantDefaults to the plugin's `inputVariant`.
maxLength numberThe most characters the text may hold; typing and pasting stop there.
autofocus booleanFocuses the text, with the caret at the end, once mounted.
colors string[]Palette colour names the colour and highlight pickers offer, in order. Defaults to the whole palette.
historyDelay numberMilliseconds within which consecutive typing is one undo step. Defaults to 500.
slashMenu boolean | SlashCommand[]The menu a `/` opens where a word starts: `true` for the blocks the editor knows, the commands to offer, or `false` for none. Defaults to true.
chips ChipTrigger | ChipTrigger[]Inline chips put in by typing a trigger: `{ char: '@', kind: 'mention', items: (q) => people.filter(…) }`, or several triggers. `items` may return a promise, for a search on the server.
math boolean | EditorMathOptionsFormulas, written in LaTeX and drawn: the toolbar's formula button, the slash menu's entry, the panel a formula is written in, and editing one by pressing it in the text. Defaults to true. `false` still draws the formulas a document has, and takes away every way of making or changing one. An object chooses the ready-made formulas the panel offers (`templates`) and whether a value is edited where it stands (`inlineEdit`).
find booleanFind and replace: Ctrl/⌘+F opens the bar over the text, Ctrl+H (⌘+⌥+F on a Mac) with the replace row. Needs an `<EditorFind>` part, which the ready-made editor has. Defaults to true; `false` leaves the keys to the browser.
blockMenu boolean | BlockAction[]The handle beside the block the caret is in: `true` for the usual actions, the actions to offer, or `false` for none. Defaults to true.
toolbar boolean | EditorToolbarItem[][]The toolbar: `false` for none, or groups of item names, as in `[['bold', 'italic'], ['link']]`. The `toolbar` slot replaces it entirely.
bubbleMenu boolean | EditorToolbarItem[]A floating toolbar over selected text; `true` for the default buttons, or the items to show.
showCount booleanShows the word and character count under the text. On by default when there is a `maxLength`.
showWordCount booleanShows the word count beside the character count. Defaults to true.
scrollbar ScrollbarModeThe bars of the boxes this component scrolls inside — `'hover'`, `'always'` or `'native'`. The application's `scrollbar` option by default, which is `'hover'`.

Plus pt, dt and unstyled from BaseProps, see pass-through and unstyled mode.

Emits

EventPayloadDescription
update:modelValue value: string—
update:json value: EditorJSON—
text-change event: EditorTextChangeEventThe content changed.
selection-change event: EditorSelectionChangeEvent—
focus event: FocusEvent—
blur event: FocusEvent—
load event: { instance: unknown }The editor is ready; `instance` is the framework-free editor behind the component.

Slots

NameSlot propsDescription
toolbar —Replaces the toolbar. Build one from `EditorToolbar`, `EditorButton` and the other parts.
footer —Replaces the footer's content (the count).