Control via ref: a template and Markdown
Inserting at the caret from screen code, the onReady callback and Markdown export of the Document via the Handle.
The Handle (ref) is how a screen drives the field: insert a template
at the caret, read the text, export Markdown. Its methods are safe before
Readiness: calling them on the server or before the engine loads breaks
nothing.
How it works
insertHTML and insertText
Both methods insert at the caret and return true if the Document changed. false means there is
no engine yet, the field is read-only, the Schema dropped the insert, or it would exceed
maxLength. A template that doesn't fit the limit is not inserted at all: it is never cut in the
middle.
The caret before inserting
focus("restore") before inserting from a button puts the caret back where the selection was.
An insert is a User edit
A User edit: its own history step, onChange after the delay.
clear() and setMarkdown() are a Programmatic replacement: onChange
right away, the limit doesn't apply.
onReady
Called once per mount, when the engine has been created. ref already works inside it.
getMarkdown() loses formatting
getMarkdown() exports what Markdown can express: color, alignment and image width are lost. For
lossless storage use HTML.