@lobehub/editor
Version:
A powerful and extensible rich text editor built on Meta's Lexical framework, providing a modern editing experience with React integration.
92 lines (91 loc) • 3.74 kB
TypeScript
import EventEmitter from 'eventemitter3';
import { CommandListener, CommandListenerPriority, CommandPayloadType, DecoratorNode, LexicalCommand, LexicalEditor, LexicalNodeConfig } from 'lexical';
import { IEditor, IEditorKernel, IEditorPluginConstructor, IPlugin, IServiceID } from "../types/kernel";
import { ILocaleKeys } from "../types/locale";
import DataSource from './data-source';
export declare class Kernel extends EventEmitter implements IEditorKernel {
private static globalHotReloadMode;
private dataTypeMap;
private plugins;
private pluginsInstances;
private nodes;
private themes;
private decorators;
private serviceMap;
private localeMap;
private hotReloadMode;
private logger;
private editor?;
constructor();
private detectDevelopmentMode;
/**
* Globally enable or disable hot reload mode for all kernel instances
* @param enabled Whether to enable hot reload mode globally
*/
static setGlobalHotReloadMode(enabled: boolean): void;
/**
* Reset global hot reload mode to automatic detection
*/
static resetGlobalHotReloadMode(): void;
getLexicalEditor(): LexicalEditor | null;
destroy(): void;
getRootElement(): HTMLElement | null;
setRootElement(dom: HTMLElement): LexicalEditor;
setDocument(type: string, content: any): void;
focus(): void;
blur(): void;
getDocument(type: string): DataSource | undefined;
getSelectionDocument(type: string): unknown | null;
registerDecorator(name: string, decorator: (_node: DecoratorNode<any>, _editor: LexicalEditor) => any): this;
getDecorator(name: string): ((_node: DecoratorNode<any>, _editor: LexicalEditor) => any) | undefined;
/**
* Unregister a decorator
* @param name Decorator name
*/
unregisterDecorator(name: string): boolean;
/**
* Get all registered decorator names
*/
getRegisteredDecorators(): string[];
/**
* Support registering target data source
* @param dataSource Data source
*/
registerDataSource(dataSource: DataSource): void;
registerThemes(themes: Record<string, any>): void;
registerPlugin<T>(plugin: IEditorPluginConstructor<T>, config?: T): IEditor;
registerPlugins(plugins: Array<IPlugin>): IEditor;
registerNodes(nodes: Array<LexicalNodeConfig>): void;
registerService<T>(serviceId: IServiceID<T>, service: T): void;
/**
* Register service with hot reload support - allows overriding existing services
* @param serviceId Service identifier
* @param service Service instance
*/
registerServiceHotReload<T>(serviceId: IServiceID<T>, service: T): void;
/**
* Enable or disable hot reload mode
* @param enabled Whether to enable hot reload mode
*/
setHotReloadMode(enabled: boolean): void;
/**
* Check if hot reload mode is enabled
*/
isHotReloadMode(): boolean;
/**
* Get service
* @param serviceId Service ID
*/
requireService<T>(serviceId: IServiceID<T>): T | null;
dispatchCommand<TCommand extends LexicalCommand<unknown>>(type: TCommand, payload: CommandPayloadType<TCommand>): boolean;
getTheme(): Record<string, any>;
updateTheme(key: string, value: string | Record<string, string>): void;
registerLocale(locale: Partial<Record<keyof ILocaleKeys, string>>): void;
t<K extends keyof ILocaleKeys>(key: K, params?: Record<string, any>): string;
get isEmpty(): boolean;
get isSelected(): boolean;
cleanDocument(): void;
private _commands;
private _commandsClean;
registerHighCommand<P>(command: LexicalCommand<P>, listener: CommandListener<P>, priority: CommandListenerPriority): () => void;
}