Extensions API
Core API reference for LexKit extensions
Complete API reference for creating, configuring, and using LexKit extensions. Learn about the core interfaces, types, and functions that power the extension system.
Quick Links
Core API Overview
The extension system is built around a few key interfaces and functions that work together to provide type safety and modularity.
Factory function for creating type-safe extensions with a functional API. Perfect for simple extensions and rapid development.
Abstract base class for creating extensions with traditional object-oriented patterns. Ideal for complex extensions with inheritance.
Core TypeScript interfaces and types that define the extension contract and ensure type safety throughout the system.
createExtension Function
The primary factory function for creating type-safe extensions.
createExtension Type Signature
| Parameter | Type | Description |
|---|---|---|
config | CreateExtensionConfig | Configuration object defining the extension's behavior |
| Property | Type | Required | Description |
|---|---|---|---|
name | string | Yes | Unique identifier for the extension |
category | ExtensionCategory[] | No | Categories this extension belongs to |
config | Partial<Config> | No | Default configuration values |
commands | (editor: LexicalEditor) => Commands | No | Function returning command implementations |
stateQueries | (editor: LexicalEditor) => StateQueries | No | Function returning state query implementations |
plugins | ReactNode[] | No | React components to render as plugins |
initialize | (editor: LexicalEditor) => (() => void) | void | No | Initialization function called when extension is registered |
nodes | any[] | No | Custom Lexical nodes provided by the extension |
supportedFormats | readonly TextFormatType[] | No | Text formats supported by this extension |
Creating an extension with createExtension
BaseExtension Class
Abstract base class for creating extensions with object-oriented patterns.
BaseExtension Class Definition
| Method | Return Type | Description |
|---|---|---|
register(editor) | () => void | Register the extension with the Lexical editor |
getCommands(editor) | Commands | Return command implementations |
getStateQueries(editor) | StateQueries | Return state query implementations |
getPlugins() | Plugins | Return React plugins/components |
getNodes() | any[] | Return custom Lexical nodes |
configure(config) | this | Configure the extension with new settings |
Creating an extension with BaseExtension
Core Types & Interfaces
Essential TypeScript types that define the extension system.
Extension Interface Definition
Extension Categories
Base Configuration Interface
API Best Practices
Guidelines for building robust and maintainable extensions.
Leverage TypeScript's type system to ensure compile-time safety. Define clear interfaces for commands and state queries.
Always return cleanup functions from registration methods. Properly dispose of event listeners and resources.
Use editor.read() for reading operations and editor.update() for mutations. Avoid unnecessary re-renders and optimize state queries.
Document your extension's API with JSDoc comments. Include examples and usage patterns for other developers.