Core plugin system and editor functionality for the Plate rich text editor framework
—
Pending
Does it follow best practices?
Impact
Pending
No eval scenarios have been run
Pending
The risk profile of this skill
Plate Core is the foundation of the Plate rich text editor framework, providing a comprehensive plugin system, editor creation utilities, serialization capabilities, and extensible architecture for building rich text editing experiences. It extends Slate.js with powerful abstractions, type safety, and a rich ecosystem of plugins and utilities.
npm install @platejs/coreimport { createSlateEditor, SlateEditor } from "@platejs/core";
import { createSlatePlugin, getCorePlugins } from "@platejs/core";For specific functionality:
import {
HtmlPlugin,
deserializeHtml,
HistoryPlugin,
DebugPlugin
} from "@platejs/core";import { createSlateEditor, getCorePlugins, createSlatePlugin } from "@platejs/core";
// Create a basic editor with core plugins
const editor = createSlateEditor({
plugins: getCorePlugins()
});
// Create a custom plugin
const CustomPlugin = createSlatePlugin({
key: 'custom',
node: { type: 'custom' }
});
// Create editor with custom plugins
const customEditor = createSlateEditor({
plugins: [
...getCorePlugins(),
CustomPlugin
]
});
// Basic editor operations
editor.insertText('Hello world');
editor.insertBreak();Plate Core is built around several key architectural components:
createSlateEditor function that creates fully-configured editor instances with plugin integrationCore functionality for creating and configuring Slate editors with Plate enhancements, plugin integration, and type safety.
function createSlateEditor(options?: {
plugins?: any[];
value?: any[];
editor?: BaseEditor;
}): SlateEditor;
function withSlate(editor: BaseEditor): SlateEditor;Comprehensive plugin architecture for extending editor functionality with type-safe configuration, lifecycle hooks, and extensibility patterns.
function createSlatePlugin<T>(config: PluginConfig<T>): SlatePlugin<T>;
function getCorePlugins(): CorePlugin[];
function getSlatePlugin<T>(plugin: WithRequiredKey<T>): T;
interface PluginConfig<T = {}> {
key: string;
node?: NodeConfig;
api?: ApiConfig;
transforms?: TransformConfig;
options?: T;
}Complete HTML serialization and deserialization system with customizable parsing, cleaning utilities, and Slate format conversion.
const HtmlPlugin: SlatePlugin;
function deserializeHtml(
editor: SlateEditor,
options: {
element: HTMLElement | string;
collapseWhiteSpace?: boolean;
}
): any[];
function serializeHtml(
editor: SlateEditor,
options?: { nodes?: any[] }
): string;Essential plugins that provide fundamental editor functionality including history, debugging, DOM management, and node handling.
const HistoryPlugin: SlatePlugin;
const DebugPlugin: SlatePlugin;
const DOMPlugin: SlatePlugin;
const ParserPlugin: SlatePlugin;
const NodeIdPlugin: SlatePlugin;Editor manipulation functions for programmatic content modification, selection handling, and editor state management.
interface EditorTransforms {
init(options: { value?: any[]; selection?: any }): void;
setValue(value: any[]): void;
insertExitBreak(): void;
resetBlock(options?: { type?: string }): void;
}Comprehensive TypeScript interfaces and type utilities for type-safe editor development with full plugin inference.
interface SlateEditor extends BaseEditor {
api: EditorApi;
plugins: Record<string, any>;
transforms: EditorTransforms;
getPlugin<T>(plugin: WithRequiredKey<T>): T;
getApi<T>(plugin?: WithRequiredKey<T>): EditorApi & InferApi<T>;
}
interface BaseEditor {
children: any[];
selection: any;
operations: any[];
}
type InferApi<T> = T extends { api: infer A } ? A : {};
type InferTransforms<T> = T extends { transforms: infer Tr } ? Tr : {};Comprehensive event handling system with cross-platform hotkey support, customizable shortcuts, and event pipeline management.
interface Hotkeys {
createHotkey(hotkey: string): (event: KeyboardEvent) => boolean;
isHotkey(hotkey: string, event: KeyboardEvent): boolean;
parseHotkey(hotkey: string): { key: string; modifiers: string[] };
}
const Hotkeys: Hotkeys;Essential utility functions for node manipulation, plugin management, and editor state operations.
function applyDeepToNodes(options: {
node: any;
source: any;
apply: (node: any) => any;
}): any;
function mergeDeepToNodes(options: {
node: any;
source: any;
}): any;
function overridePluginsByKey(
plugins: any[],
overrides: Record<string, any>
): any[];Support for multiple serialization formats including HTML, AST fragments, and custom format parsing with extensible parser system.
const AstPlugin: SlatePlugin;
const ParserPlugin: SlatePlugin;
interface ParserOptions {
format: string;
mimeType: string;
deserialize: (data: string) => any[];
}// Plugin priorities
const PRIORITY_LOW = 75;
const PRIORITY_NORMAL = 100;
const PRIORITY_HIGH = 125;
// Core plugin keys
const PLUGIN_KEYS = {
HISTORY: 'history',
DEBUG: 'debug',
HTML: 'html',
DOM: 'dom',
PARSER: 'parser'
} as const;