Fine-tune Light, shadows, borders, neumorphic
Light and shadows
315°
1×
1×
1×
Borders
1 px
Neumorphic
1×
0×
Forms Form-associated

BlockEditor <pm-block-editor>

Block editor for long content: articles, blog posts, documentation and notes, written in blocks you can format, align and drag into a new order.

Full screen
Props
<script type="module"> import '@prismora/css'; import '@prismora/elements/block-editor'; </script> <pm-block-editor label="Article" name="body" stats hint="Type / for blocks, select text to format it, drag the handle to move a block." value="<h2>Release notes</h2><p>This week we shipped <strong>faster search</strong> and a <mark>new dashboard</mark>.</p><ul data-checklist><li data-checked='true'>Update the docs</li><li>Tell support</li></ul><aside data-tone='info'>Tip: press / on an empty line for every kind of block.</aside><pre data-lang='ts'><code>const results = await search(query);</code></pre>" style="inline-size: min(100%, 46rem)"></pm-block-editor>

States

Each state is one attribute.

Disabled
Read-only
Required
Error

Overview

Blocks: text, four heading levels, bulleted, numbered and check lists, quotes, callouts, code, images, videos, tables and dividers.

  • Type / for the block menu, or start a line with Markdown: #, -, 1., [] or > then a space; three backticks or --- then Enter.
  • Select text for its formatting bar: bold, italic, underline, strikethrough, inline code, highlight, link.
  • Each block has a handle: drag it to move the block, or press it for the block menu (turn into, align, width, tone, move, duplicate, delete). From the keyboard: Alt+Shift+↑/↓ moves the block.
  • Paste or drop pictures to upload them (upload), and paste a YouTube or Vimeo link on an empty line to embed it.
  • Its own undo and redo (Mod+Z, Mod+Shift+Z) cover typing, formatting and moves.

Form-associated: submits clean HTML (only the blocks and marks above; scripts and unknown markup never get in). Also as JSON blocks (blocks) and Markdown (markdown). Sanitise again on the server before storing or showing. For a comment or a short description, <pm-editor> is lighter.

Attributes

AttributeTypeDefaultDescription
labelstring—Visible label (required for accessibility).
namestring—Form field name.
valuestring—Initial HTML.
placeholderstring—Shown in an empty document (default: "Write, or press / for blocks").
hintstring—Help text under the editor.
errorstring—Error message; marks the editor invalid.
requiredboolean—Must have content.
disabledboolean—Not editable, not submitted.
readonlyboolean—Not editable, still submitted.
statsboolean—Show the number of words and the reading time.
toolbar'full' | 'minimal'—full (default), minimal (formatting bar and slash menu only).

Also accepts the contextual attributes tone, surface, radius, density, motion, elevation. They are inherited from ancestors' data-* attributes.

Events

EventReact / Svelte propDescription
pm-upload-erroronPmUploadErrorA picture could not be uploaded. detail.file, detail.error.
pm-inputonPmInputThe content changed.
pm-changeonPmChangeThe content changed and the editor lost focus.

Methods

checkValidity(), reportValidity(), focus(), undo(), redo()