genesis-editor

Tools & plugins

Pick the blocks and formatting the editor offers, arrange its toolbar, and add your own blocks with plugins.

Choosing tools#

Pass tools to list the tools you want. A tool that's off is gone everywhere: the / and + menus, Markdown shortcuts, keyboard shortcuts, the formatting toolbar, and the mobile toolbar. Pasted content it would have produced becomes plain paragraphs, and existing content falls back the same way when it loads. Paragraphs are always on. Without tools, every built-in tool and every plugin is on.

<BlockEditor tools={["heading", "bulletList", "image", "bold", "link"]} />

The object form takes options. Keys set to an options object or true are on:

<BlockEditor
  tools={{
    heading: { levels: [1, 2] },
    image: true,
    bold: true,
    italic: true,
  }}
/>

To start from everything and remove a few, filter the exported list:

import { BUILT_IN_TOOLS } from "genesis-editor";

<BlockEditor tools={BUILT_IN_TOOLS.filter((tool) => tool !== "table")} />

Built-in tools

ToolKindWhat it adds
headingBlockHeadings 1–6 (menus show 1–3). Options: { levels }. Shortcuts # to ######.
bulletListBlockBullet lists. Shortcut - or *.
numberedListBlockNumbered lists. Shortcut 1.
checkListBlockTo-do lists. Shortcut [] or [x].
toggleListBlockCollapsible toggle lists.
quoteBlockBlock quotes. Shortcut >.
codeBlockBlockCode blocks with a language picker and syntax highlighting. Shortcut ```.
dividerBlockHorizontal dividers. Shortcut ---.
tableBlockTables.
columnsBlockTwo- or three-column layouts. Slash /Columns (2) or /3 columns; drag to resize.
imageBlockImages: by URL, upload, paste, or drop.
videoBlockVideo files.
audioBlockAudio files.
fileBlockAny file. Also catches pasted files no other block accepts.
embedBlock
linkPreviewBlock
boldInlineBold. Mod+B.
italicInlineItalic. Mod+I.
underlineInlineUnderline. Mod+U.
strikeInlineStrikethrough. Mod+Shift+S.
codeInlineInline code. Mod+E.
linkInlineLinks: toolbar button, Mod+K, pasted links.
colorsInlineText and background colors: palette, brand swatches and any hex.
fontSizeInline

Toolbar#

toolbar picks the formatting toolbar's items and their order. Items for tools that are off are skipped. The default order is blockType, tableMerge, columns, file, imageLink, inlineImage, bold, italic, underline, strike, code, alignLeft, alignCenter, alignRight, linkPreview, then any plugin items.

Set placement: "fixed" to pin the toolbar above the editor instead of showing it over the selection, or pass toolbar={false} to turn it off.

Plugins#

A plugin bundles blocks, menu items, toolbar items, and shortcuts under one name. Declare it with definePlugin and pass it in plugins. Its blocks join the same menus as the built-ins, and its name works in tools like any built-in tool. The built-in tools are plugins too, so a plugin named quote replaces the built-in quote.

import { definePlugin } from "genesis-editor";

export const myPlugin = definePlugin({
  name: "my-plugin",           // also its tool name
  blocks: { … },               // block specs, e.g. createReactBlockSpec(...)()
  slashItems: [ … ],           // entries for the / and + menus
  toolbarItems: { … },         // formatting toolbar components, by toolbar name
  markdownShortcuts: [ … ],    // { find: /^!>\s$/, block: { type: "callout" } }
  keyboardShortcuts: { … },    // { "Mod-Shift-l": (editor) => true }
});

This callout plugin adds a block with a tone you can click to change, a slash menu item, a !> Markdown shortcut, and a toolbar button. It ships with these docs, not with the package.

// With a tools list, plugins are active only when listed.
<BlockEditor tools={["heading", "callout"]} plugins={[calloutPlugin]} />
tools and the plugin names are read when the editor is created. When they change, the editor is rebuilt with the current document, which keeps its content but loses undo history. Every field of a plugin is listed in the API reference.