UNPKG

@lobehub/editor

Version:

A powerful and extensible rich text editor built on Meta's Lexical framework, providing a modern editing experience with React integration.

102 lines (101 loc) 4.16 kB
import { HistoryState } from '@lexical/history'; import EventEmitter from 'eventemitter3'; import { CommandListener, CommandListenerPriority, CommandPayloadType, LexicalCommand, LexicalEditor, LexicalNodeConfig } from 'lexical'; import { HotkeyId } from "../types/hotkey"; import { IDecorator, IEditor, IEditorKernel, IEditorPluginConstructor, IPlugin, IServiceID } from "../types/kernel"; import { ILocaleKeys } from "../types/locale"; import { HotkeyOptions, HotkeysEvent } from "../utils/hotkey/registerHotkey"; import DataSource from './data-source'; export declare class Kernel extends EventEmitter implements IEditorKernel { private static globalHotReloadMode; private dataTypeMap; private plugins; private pluginsConfig; private pluginsInstances; private nodes; private themes; private decorators; private serviceMap; private localeMap; private hotReloadMode; private logger; private historyState; private editor?; constructor(); getHistoryState(): HistoryState; isEditable(): boolean; 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, editable?: boolean): LexicalEditor; setEditable(editable: boolean): void; initNodeEditor(): 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: IDecorator): this; getDecorator(name: string): IDecorator | 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; registerHotkey(hotkeyId: HotkeyId, callback: (event: KeyboardEvent, handler: HotkeysEvent) => void, options?: HotkeyOptions): () => void; registerHighCommand<P>(command: LexicalCommand<P>, listener: CommandListener<P>, priority: CommandListenerPriority): () => void; }