ZUI

Search documentation

Find a page or a heading.

Email Editor

A block editor for an email's body, with {{name}} variables, whose blocks and links stay inside what the email renderer prints, and a live preview.

tsx

Installation

bash

Usage

tsx
tsx

The editor states an email as the blocks the renderer takes: paragraph, button, code, list, callout, divider, columns and html. It never fills a variable with a real value, and it never refuses an edit because of a problem: it marks the problem and reports it.

API reference

EmailEditor

renderer and previewInput come together: the preview is drawn only with a renderer, and a renderer needs the subject, locale and layout it renders in. previewInput is a render's input without blocks, variables and variableTypes, which the editor fills from the document and the declarations' sampleValue.

label is the editable surface's accessible name. readOnly shows the document and its problems with nothing that changes it: typing is refused and the toolbar, the slash menu and the block menu are not drawn.

messages words every string the editor draws, in the host's language; a key it leaves out stays English. ProfileEditorMessages and its English, DEFAULT_PROFILE_MESSAGES, come from messages.ts. A message that takes a value is a function, such as problem(problem), which names the variable a problem is about. Build messages once per locale, outside the render or in a memo: a new object rebuilds the toolbar's and the menus' items. A problem keeps the words it was marked with until the editor reads the problems again, after the next edit.

tsx

required lists the ids of the blocks the author may not remove. structure="locked" lets the author edit text and variables only: nothing is inserted, removed or restyled. renderBlockAdornment draws what the host wants beside a block, such as a translation's standing; id is null for a block not saved yet, so key identifies it. features adds the host's own blocks, each with an email codec, and is read once: a change needs a remount.

emailProfile takes allow (the block kinds the author may use, all eight by default), variables, extraKinds (the kinds of the host's own features) and bounds, a partial of the limits below:

The defaults of text, label, href, listItems and lanes are what the renderer accepts, so a bound can go lower, never higher: a higher one throws editor.profile.bound_above_renderer. Columns hold one level only.

Variables

Declare each variable once, in the profile, with a name of word characters, a type of string, duration, url or email, and optionally a label, a sampleValue and required. A token is written {{name}}.

Typing {{ at any position opens the variable menu, and the toolbar's variable button opens it too; picking one inserts a pill. A button's link takes one url variable, and a text link points to one url variable too. A required variable that no block prints is a problem.

When the declarations change, hand the editor a new profile: it reads the new declarations and redraws its pills and problems itself. If a host edits the declarations in place instead, call refreshVariables(editor) with the editor onReady gave it, so every pill reads its label and its problem again:

tsx

Validation

onValidate receives the problems on mount and whenever the list changes. Each marks its block in the editor, and the server reads the same list with validate(blocks, profile) from @zeroxsolutions/editor-core/profiles/index, so build the same profile on both sides.

A message about a variable names it, as in This variable is not declared: {{trip_name}}. A host words them through messages.problem.

F8 moves the caret to the next problem and Shift+F8 to the previous one; Escape on a problem's marker goes back to its block.

Markup

A paragraph, a callout and a list item carry text in a small markup, which the editor shows as formatting:

A backslash escapes the next character. A **, _ or [ left open is a markup-malformed problem.

Hosting the value

value is the document the editor shows. Hand back what onChange gave you; do not rebuild it or refetch it into value while the author is editing. After a save, run assignBlockIds on the blocks the server answered with, so a block the editor added keeps its identity. Pass a different value only to load another document, such as another locale; a value that differs from the editor's replaces it and drops the edits made since. Remounting the editor with a key loads one as well.

Travel

Travel keeps one template per message and locale, whose body is these blocks. Its profile declares the variables the message may print, such as first_name and trip_url, and marks trip_url required for a message whose only job is to open the trip. The renderer that prints the preview is the one the sending service renders with, so the preview is the email a traveller receives.