Editor
Rich text with its own engine and no dependency: headings, lists, tables, images, links and Markdown shortcuts, bound as sanitised HTML.
Import
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.
Custom toolbar
`toolbar` takes groups of item names; the `toolbar` slot replaces the bar with parts of your own.
Only the basics here.
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;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.
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.
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.
Water is , and it forms by .
The answer sheet: . The text around the formula can be changed; the formula cannot.
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.
<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 KBx^2 - 5x + 6 = 0
\frac{6a^2 b}{3ab}
\overline{x} = \frac{1}{n} \sum_{i=1}^{n} x_iMathematics — 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.
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.
<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>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.
Read only
With count and limit
`max-length` stops typing and pasting at the limit; the count describes the text.
Keep it short.
HTML and JSON output
Type here and watch both formats change.
<p>Type here and watch <strong>both</strong> formats change.</p>
null
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.
API
Read from packages/vue/src/components/Editor/types.ts, so it says what the component actually accepts.
Props
| Name | Type | Description |
|---|---|---|
| placeholder | string | — |
| readonly | boolean | The text can be read, selected and copied, not changed. |
| disabled | boolean | — |
| invalid | boolean | — |
| variant | InputVariant | Defaults to the plugin's `inputVariant`. |
| maxLength | number | The most characters the text may hold; typing and pasting stop there. |
| autofocus | boolean | Focuses 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 | number | Milliseconds 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 | EditorMathOptions | Formulas, 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 | boolean | Find 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 | boolean | Shows the word and character count under the text. On by default when there is a `maxLength`. |
| showWordCount | boolean | Shows the word count beside the character count. Defaults to true. |
| scrollbar | ScrollbarMode | The 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
| Event | Payload | Description |
|---|---|---|
| update:modelValue | value: string | — |
| update:json | value: EditorJSON | — |
| text-change | event: EditorTextChangeEvent | The 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
| Name | Slot props | Description |
|---|---|---|
| toolbar | — | Replaces the toolbar. Build one from `EditorToolbar`, `EditorButton` and the other parts. |
| footer | — | Replaces the footer's content (the count). |