Olddevs UI4.14.0
Recipes

Spoiler: hidden text in RichTextView

A Block that is plain framed text in the Editor and hides behind a button in RichTextView thanks to an Island.

RichTextView shows the Document as sanitized HTML and loads no engine. To make a custom Block do something in RichTextView (expand, play a video, count votes), give it an Island: a client component in the island field of its Schema rules.

The butler did not do it.

It was the gardener all along.

Try it

On the left is the Editor; on the right, RichTextView shows the same Document. Turn a paragraph into a spoiler via “¶” or “/” and a button appears on the right. The basic Preset has no Slash menu, so the example adds "insertMenu" to basic: see “Note”.

How it works

One tools array for everything

The Editor, server sanitization (sanitizeRichText(html, DOMPurify, tools)) and the View receive the same tools array. The View takes only the Islands from it.

The Island receives data, not HTML

The Island receives the Block name, its declared attributes and text — the Block's text from the server HTML.

Server HTML is always visible

Until the page is hydrated, while JavaScript is off or the Island's code is loading, the reader sees the Block's content as saved.

island is a client component

The component lives in a "use client" module. Only a reference to it crosses the server component boundary; the Island's code loads only when such a Block is in the Document.

turnInto — “can turn into”

turnInto: true is a Block trait: an item from the turnInto section appears in “¶”, “/” and the handle's “Format ›”.

RichTextView does not sanitize HTML. In an app the Document is sanitized on the server on save with the same tools array; in the example the HTML comes straight from the Editor.

On this page