Basic elements plugin for Plate rich-text editor that combines blockquote, code block, heading, and paragraph functionality
npx @tessl/cli install tessl/npm-udecode--plate-basic-elements@48.0.0Plate Basic Elements provides a convenient bundling plugin that combines four essential text editing elements into a single package for the Plate rich-text editor framework. It bundles blockquote, code block, heading, and paragraph plugins with their default configurations, offering a simple way to add basic text editing capabilities to any Plate editor.
npm install @udecode/plate-basic-elementsimport { BaseBasicElementsPlugin } from '@udecode/plate-basic-elements';For React-enhanced functionality:
import { BasicElementsPlugin } from '@udecode/plate-basic-elements/react';import { createPlateEditor } from '@udecode/plate/react';
import { BasicElementsPlugin } from '@udecode/plate-basic-elements/react';
// Create editor with basic elements
const editor = createPlateEditor({
plugins: [
BasicElementsPlugin,
// ... other plugins
],
});
// The plugin automatically provides:
// - Blockquotes (Cmd+Shift+.)
// - Code blocks (Cmd+Alt+8)
// - Headings H1-H3 (Cmd+Alt+1/2/3, Cmd+Shift+1/2/3)
// - Paragraphs (Cmd+Alt+0, Cmd+Shift+0)For headless/server-side usage:
import { createSlateEditor } from '@udecode/plate';
import { BaseBasicElementsPlugin } from '@udecode/plate-basic-elements';
const editor = createSlateEditor({
plugins: [
BaseBasicElementsPlugin,
// ... other plugins
],
});The package provides two plugin variants that bundle existing Plate plugins:
Both plugins are convenience wrappers that include four pre-configured plugins from separate packages.
The core plugin that bundles all basic elements functionality without React dependencies.
const BaseBasicElementsPlugin: SlatePlugin;Plugin Configuration:
'basicElements'BaseBlockquotePlugin, BaseCodeBlockPlugin, BaseHeadingPlugin, BaseParagraphPluginReact-enhanced plugin with keyboard shortcuts and UI components.
const BasicElementsPlugin: PlatePlugin;Plugin Configuration:
'basicElements'BlockquotePlugin, CodeBlockPlugin, HeadingPlugin, ParagraphPluginThis package bundles the following plugins from separate packages:
'blockquote'Cmd+Shift+.'code_block'Cmd+Alt+8'heading'Cmd+Alt+1/2/3, Cmd+Shift+1/2/3 (H1-H3 only)'p'Cmd+Alt+0, Cmd+Shift+0The basic-elements package only exports the two bundled plugins. To access individual plugin APIs, transforms, types, or configurations, import directly from the source packages:
// For blockquote functionality
import { toggleBlockquote, withBlockquote } from '@udecode/plate-block-quote';
// For code block functionality
import {
insertCodeBlock,
toggleCodeBlock,
type TCodeBlockElement,
type CodeBlockConfig
} from '@udecode/plate-code-block';
// For heading functionality
import {
isHeading,
HEADING_KEYS,
type HeadingConfig
} from '@udecode/plate-heading';To customize individual plugins while using the bundled approach, configure them separately:
import { createPlateEditor } from '@udecode/plate/react';
import { BlockquotePlugin } from '@udecode/plate-block-quote/react';
import { CodeBlockPlugin } from '@udecode/plate-code-block/react';
import { HeadingPlugin } from '@udecode/plate-heading/react';
import { ParagraphPlugin } from '@udecode/plate/react';
// Custom configuration approach
const editor = createPlateEditor({
plugins: [
BlockquotePlugin,
CodeBlockPlugin.configure({
options: {
defaultLanguage: 'typescript'
}
}),
HeadingPlugin.configure({
options: {
levels: [1, 2, 3] // Only H1-H3
}
}),
ParagraphPlugin,
],
});Use BasicElementsPlugin when you want standard basic elements with default settings:
import { BasicElementsPlugin } from '@udecode/plate-basic-elements/react';
const plugins = [BasicElementsPlugin];Use individual plugins when you need custom configuration:
import {
BlockquotePlugin,
CodeBlockPlugin,
HeadingPlugin,
ParagraphPlugin
} from their respective packages;
const plugins = [
BlockquotePlugin,
CodeBlockPlugin.configure({ /* custom options */ }),
HeadingPlugin.configure({ /* custom options */ }),
ParagraphPlugin,
];Use BaseBasicElementsPlugin for server-side rendering or custom UI:
import { BaseBasicElementsPlugin } from '@udecode/plate-basic-elements';
const editor = createSlateEditor({
plugins: [BaseBasicElementsPlugin]
});This package has peer dependencies on:
@udecode/plate (>=48.0.0)react (>=18.0.0) - for React plugin onlyreact-dom (>=18.0.0) - for React plugin onlyAnd direct dependencies on the bundled plugin packages:
@udecode/plate-block-quote (48.0.0)@udecode/plate-code-block (48.0.0)@udecode/plate-heading (48.0.0)