A rich-text control for Formwright, powered by Tiptap 3 and its StarterKit.
npm install @ember-formwright/ember @ember-formwright/tiptap @tiptap/core @tiptap/pm @tiptap/starter-kit
// app/app.ts
import { registerTiptapControl } from '@ember-formwright/tiptap'
import '@ember-formwright/tiptap/theme.css' // optional; after the Formwright theme
registerTiptapControl() // @control="rich-text"
The package types these names for Glint: which paths each fits, and which args it takes. If you register under other names, declare them.
<f.Field @for="body" @control="rich-text" @label="Body" @placeholder="Write something" />
{{! a trimmed toolbar, storing Tiptap JSON }}
<f.Field @for="comment" @control="rich-text" @label="Comment" as |field|>
<field.Control @toolbar={{array "bold" "italic" "bullet-list"}} @output="json" />
</f.Field>
{{! inline forms show the value as text }}
<f.Field @for="body" @control="rich-text" @format={{toPlainText}} />
The field stores HTML, or Tiptap's JSON document with @output="json". An empty editor
stores '' (null for JSON), so required checks work. field.Control also takes @toolbar
(the buttons to show, or false), @extensions (more Tiptap extensions) and @starterKit
(StarterKit's options); the last two are read once, when the editor is created. Button names
go through the app's translator (./messages lists them), or take @toolLabels
({ bold: 'Strong' }) and @toolbarLabel.
Toolbar buttons: bold, italic, strike, heading-2, heading-3, bullet-list,
ordered-list, blockquote, undo, redo. Each has an accessible name, and the toggles
carry aria-pressed.
import { RichTextHarness } from '@ember-formwright/tiptap/test-support'
class PostForm extends FormHarness {
@field(RichTextHarness) declare body: RichTextHarness
}
await post.body.typeText('Hello')
await post.body.selectAll()
await post.body.press('bold')
assert.true(post.body.isActive('bold'))
assert.strictEqual(post.body.html, '<p><strong>Hello</strong></p>')
It also has text, setContent(html), tools, isEditable and editor (the Tiptap
editor). Text goes in through Tiptap's commands: ProseMirror doesn't react to synthetic key
events.
div role="textbox", which <label for> doesn't name; the
control passes @label as aria-label, and a click on the label focuses the editor.<input name>; the wrapper carries data-fw-name with the
field's path.