RichText#
RichText holds formatted content (headings, lists, links, tables,
images), richtext in the descriptor. It gives authors a
word-processor-like editor (Tiptap, on ProseMirror) and stores what they
write as the editor’s JSON document (a tree, not markup) in a string
property on a TEXT or JSON column. The server validates every write
against a fixed schema, so sanitizing becomes schema validation:
RichText::make('description')
->features(['bold', 'italic', 'heading', 'list', 'link', 'table']) // default: all but image and mention
->imageField('imageKey') // images upload through this file/image field and store its key
->mentions('assignee') // @ offers the records of this relation
->textField('descriptionText'), // search reads the plain text the writer fills here
Features are what the editor offers and the server accepts:
bold,italic,underline,strike,code,heading,list,blockquote,codeBlock,horizontalRule,link,table,image,mention: all but images and mentions by default.Validation. The value must be valid JSON with a
{"type": "doc", "content": [...]}root; every node and mark type must be one of the field’s features, and every attribute one that type defines; a link goes only tohttp(s):,mailto:or a relative place; the document is at mostmaxBytes()(256 KiB by default), 32 levels deep and 20 000 nodes. A refusal is a422on the field, with the path into the document (description/content/2/marks/0/attrs/href). An empty document is no value, sorequired()works.Images store a storage key, never a URL: one the image field’s upload endpoint issued, or one already in the stored document. The admin fetches it with its credentials through
GET /vector/r/{resource}/{id}/files/{imageField}?key=…, which serves only keys a document of that record shows.Search needs
textField('bodyText'): a second string property the writer fills withDocument::toPlainText()on every write. The build refusessearchable()without one. A rich-text field is never sorted or summarized, and filtered only bynullandnnull.
The descriptor publishes
richtext: {features, imageField, mentions, storesHtml, maxBytes}.
On your own pages#
Kinetis\Vector\RichText\Document renders a stored value without
knowing the editor:
public function __construct(private Document $document) {}
$html = $this->document->toHtml($product['description'], Document::DEFAULT_FEATURES,
static fn (string $key): ?string => "/media/{$key}"); // or null to leave an image out
toHtml() renders through
ueberdosis/tiptap-php,
configured with exactly the given features, never its highlighting code
blocks, which reach the filesystem or a process. What they do not cover
is dropped, and text and attributes are escaped. toPlainText() is the
projection CSV exports and search use. The demo’s shop page,
GET /shop/products/{id}, renders the product description this way.
An application node type, such as a callout or an embed, is registered on both sides; see Customizing the UI.
HTML storage#
RichText::make('body')->storesHtml() is an opt-in for an existing HTML
column: the admin still sends the document, and the server stores
toHtml() of it. The admin reads the stored HTML back through the same
schema, so anything outside it is dropped on the next save. Fidelity is
only what HTML carries: prefer the document for new columns. The demo’s
ticket body is one.
In the browser#
The admin renders HTML only from a document it generated itself through
the field’s schema (or from markdown-it with HTML off, for a
Markdown field), then passes it through DOMPurify with an
allow-list matching that schema: no style, no event handlers, no
src. That happens in the layer’s only v-html, in
Vx/Cell/RichText.vue and Vx/Cell/Markdown.vue. A sanitizer that
fails its canary check is not trusted, and values are then shown as
text. DOMPurify is dual-licensed MPL-2.0 OR Apache-2.0; the layer uses
it under Apache-2.0. Under the hosted shell’s strict CSP the editor’s
own style element carries the response nonce, table resizing (which
writes style attributes) is off, and images display as data: URLs:
the editor and the record page run without a single violation.
It takes the common modifiers too.