Single Block provides two input constraints: one root block with soft breaks, or one line with no breaks. Each constraint is an independent plugin.
Use SingleBlockPlugin when the field may contain line breaks.
import { SingleBlockPlugin } from "platejs";
import { createPlateEditor } from "platejs/react";
export const editor = createPlateEditor({
plugins: [SingleBlockPlugin],
});import { SingleBlockPlugin } from "platejs";
import { createPlateEditor } from "platejs/react";
export const editor = createPlateEditor({
plugins: [SingleBlockPlugin],
});Use SingleLinePlugin when the field must be plain one-line text.
import { SingleLinePlugin } from "platejs";
import { createPlateEditor } from "platejs/react";
export const editor = createPlateEditor({
plugins: [SingleLinePlugin],
});import { SingleLinePlugin } from "platejs";
import { createPlateEditor } from "platejs/react";
export const editor = createPlateEditor({
plugins: [SingleLinePlugin],
});SingleBlockPlugin weakly disables an installed TrailingBlockPlugin, so the
package remains correct even when it cannot control the consumer's broad kit:
import { SingleBlockPlugin } from "platejs";
import { createPlateEditor } from "platejs/react";
import { plugins as editorPlugins } from "@/components/editor/editor";
export const editor = createPlateEditor({
plugins: [...editorPlugins, SingleBlockPlugin],
});import { SingleBlockPlugin } from "platejs";
import { createPlateEditor } from "platejs/react";
import { plugins as editorPlugins } from "@/components/editor/editor";
export const editor = createPlateEditor({
plugins: [...editorPlugins, SingleBlockPlugin],
});Use SingleLinePlugin in the same shape for a one-line field.
The weak peer applies only when Trailing Block is installed. It never installs the target, and a missing target is a no-op. Required dependencies still reject disablement.
| Layer | Owner | What It Does |
|---|---|---|
SingleBlockPlugin | @platejs/utils | Keeps one root block and preserves line breaks as text. |
SingleLinePlugin | @platejs/utils | Keeps one root block and strips line break characters. |
TrailingBlockPlugin | @platejs/utils | Provides trailing-block normalization when enabled. |
single-block-demo | Registry example | Owns the broad composition and mode toggle. |
These plugins are editor constraints, not schema validation. Their Plite corrections rewrite invalid root content before publication.
| Plugin | Enter | Soft Break | Extra Root Blocks | Existing Text Breaks |
|---|---|---|---|---|
SingleBlockPlugin | Calls tx.break.insertSoft(). | Preserved as \n. | Merged into the first block with \n separators. | Preserved. |
SingleLinePlugin | No-op. | No-op. | Merged into the first block with no separator. | Removes \r, \n, \r\n, \u2028, and \u2029. |
Use single-block mode for descriptions, comments, or titles that may wrap across lines. Use single-line mode for labels, slugs, short titles, and command inputs.
Both behavior plugins register Plite corrections.
| Case | Result |
|---|---|
| Root has one block | Leaves the value alone. |
Root has multiple blocks with SingleBlockPlugin | Inserts \n at the start of each next block, then merges it into the first block. |
Root has multiple blocks with SingleLinePlugin | Merges each next block into the first block without a separator. |
Text node contains line separators with SingleLinePlugin | Replaces the text with the filtered one-line string. |
Each correction runs in the active Plite transaction, so the root collapse publishes as one update.
The registry example switches plugins from a checkbox.
import {
SingleBlockPlugin,
SingleLinePlugin,
} from "platejs";
const plugins = [
...editorPlugins,
isSingleBlock ? SingleBlockPlugin : SingleLinePlugin,
];import {
SingleBlockPlugin,
SingleLinePlugin,
} from "platejs";
const plugins = [
...editorPlugins,
isSingleBlock ? SingleBlockPlugin : SingleLinePlugin,
];Single Block Mode keeps pasted lines as \n. Turning it off switches to single-line mode and removes line breaks.
| API | Package | Use |
|---|---|---|
SingleBlockPlugin | platejs / @platejs/utils | One root block with soft breaks preserved. |
SingleLinePlugin | platejs / @platejs/utils | One root block with all line breaks removed. |
PLUGINS.singleBlock | platejs / @platejs/utils | Plugin name for SingleBlockPlugin. |
PLUGINS.singleLine | platejs / @platejs/utils | Plugin name for SingleLinePlugin. |
override.plugins[PLUGINS.trailingBlock] | @platejs/utils | Package-owned weak peer that disables Trailing Block only when installed. |