Editors
Editor.js
A block editor built on Editor.js, as a form field: label, help text and validation error around it, and its content saved as Editor.js JSON in a hidden field. Use it when the content is stored as structured blocks (paragraphs, headings, lists, images...) rather than HTML.
Nothing to show
A bordered box under the "Body" label. Once the library loads, clicking inside starts a paragraph; the + button at the start of an empty line adds a heading, a list, an image, a table, a quote or code. Every change is saved as JSON in a hidden field named body, sent with the form.
Bound to Livewire #
The editor opens with a "Hello" paragraph. Each change sets $body to the editor's JSON, e.g. '{"time":...,"blocks":[{"type":"paragraph","data":{"text":"Hello world"}}],"version":"2.31.7"}', and an editor with no blocks sets it to ''. Setting $body on the server replaces the content shown. toolbar limits the tools to inline formatting, headings and lists.
{"blocks":[{"type":"paragraph","data":{"text":"Hello"}}]}
Nothing to show
Your own tools #
scripts loads more plugins from a URL before the editor starts, and data-options is a JavaScript object merged over the Editor.js configuration, where the plugin is registered. options does the same from PHP, for settings that are not functions. Its tools are added to the toolbar's, and an onChange of your own runs alongside the component's.
Nothing to show
Read-only #
readonly or disabled open the editor in read-only mode: the blocks are shown but cannot be changed.
Nothing to show
Placeholder and help #
Editor.js settings go in options, such as its placeholder. The field props (description, help) work as on any field.
Nothing to show
Events #
rendered fires on the tag when the editor is ready, with the instance in $event.detail.editor. editor:x-on:failed listens to load errors on the editor box.
Nothing to show
Customization #
Classes on the tag go to the field control; editor: attributes reach the editor box, with its border and padding.
Nothing to show
Reference
tk:editorjs
| Prop | Type | Default | Description |
|---|---|---|---|
toolbar |
string | all groups | The tool groups, separated by spaces: text (bold, italic, underline, inline code), heading, color (marker), link, list, media (image by URL and embeds), table, quote (quote, warning, delimiter) and code (code and raw HTML). full turns on all of them and none none. |
options |
array | [] |
Editor.js configuration, merged over the one the component builds (holder, tools, inline toolbar, translations, data and read-only mode). Settings such as placeholder, autofocus or minHeight go here. |
scripts |
array | [] |
URLs of scripts loaded before the editor starts, for plugins of your own. |
styles |
array | [] |
URLs of stylesheets loaded with them. |
Also accepts the field props and the field control props. wire:model and x-model bind the editor's content as a JSON string, '' when it has no blocks.
data-options is an attribute, not a prop: a JavaScript expression that returns an object merged over the configuration, after options.
Slots
| Slot | Description |
|---|---|
| default | The initial content, as Editor.js JSON, in place of value. |
Events
| Event | Detail | When |
|---|---|---|
rendered |
{ editor }, the Editor.js instance |
The editor is ready. |
started |
Editor.js and its plugins started loading. | |
completed |
The editor and its plugins are loaded and ready. | |
failed |
A script could not be loaded, or Editor.js threw while starting. |
Prefixes
| Prefix | Goes to |
|---|---|
editor: |
The editor box: border, padding and focus ring. |
Events
rendered is dispatched on the hidden field, the element the tag's attributes go to, and does not bubble: listen on the tag itself. started, completed and failed are dispatched on the editor box and are listened to with the editor: prefix.
With Alpine:
Nothing to show
Calling a Livewire action:
Nothing to show
Customization
Classes on the tag go to the field control around the editor; other attributes go to the hidden field. To reach the other parts, prefix the attribute (listed in the Reference above).
The parts around the field take the prefixes of the field props.
Nothing to show
Accessibility
The label is linked to the editing area with aria-labelledby on its role="group" element, and that element follows the hidden field's aria-describedby and aria-invalid, so a validation error from Livewire reaches screen readers. Keyboard interaction inside the editor (Tab to the block menu, / for blocks, the inline toolbar on selection) is Editor.js's own.
Behavior notes
- Editor.js, the plugins of the chosen groups and DOMPurify are loaded from jsDelivr when the first editor needs them. When the app already puts both
window.EditorJSandwindow.DOMPurifyon the page, Editor.js and the plugins of the chosen groups are not loaded, so the app provides those plugins too (window.Header,window.EditorjsList...). Thescriptsandstylesof the tag still load. - The value must be Editor.js data: JSON with a
blockslist. Anything else, such as HTML, starts the editor empty and logs a warning in the console. - Data set from outside (the initial value, a Livewire update, a form reset) is sanitized before it is shown: the HTML in each block goes through DOMPurify,
embedandsourcekeep onlyhttp(s)links, fields ending inurlkeep onlyhttp(s)anddata:image/links, and an embed without a link, or whose link is not on its service's host (from the Embed tool's services), is dropped.codeandrawblocks are kept as text. - This only protects the editor. The JSON the field sends comes from the browser: escape or sanitize each block when rendering it, and treat
rawblocks as untrusted HTML. disabledandreadonlyopen the editor in read-only mode, and toggling either attribute later switches the mode.wire:model.blursends the value when the focus leaves the whole editor, not when it moves between blocks.- Outside Livewire, resetting the form puts back the content the field had when the page loaded.
- Inside a Livewire component,
valueand the slot are ignored: the bound property is the value. - The texts of the editor's own interface (block menu, tool names, placeholders) are translated with the app's language files.
- The field's
placeholderprop does not reach Editor.js: pass it inoptions(:options="['placeholder' => 'Write something...']").