import { HistoryState, HistoryStateEntry } from "@lexical/history"; import { CommandListener, CommandListenerPriority, CommandPayloadType, EditorState, LexicalCommand, LexicalEditor, LexicalNode, LexicalNodeConfig } from "lexical"; interface IWriteOptions { /** * Normalize the serialized output where the data source supports it (markdown: a remark * round-trip). Pass `false` to get the writers' output verbatim. * @default true */ format?: boolean; selection?: boolean; } declare class DataSource { protected dataType: string; constructor(dataType: string); get type(): string; read(editor: LexicalEditor, data: any, options?: Record): void; write(editor: LexicalEditor, options?: IWriteOptions): any; } declare const HotkeyEnum: { readonly Bold: "bold"; readonly BulletList: "bulletList"; readonly CodeInline: "codeInline"; readonly Italic: "italic"; readonly Link: "link"; readonly Mention: "mention"; readonly NumberList: "numberList"; readonly PasteAsPlainText: "pasteAsPlainText"; readonly Redo: "redo"; readonly Slash: "slash"; readonly Strikethrough: "strikethrough"; readonly Underline: "underline"; readonly Undo: "undo"; }; type HotkeyId = (typeof HotkeyEnum)[keyof typeof HotkeyEnum]; type ModifierCombination = { altKey?: boolean; ctrlKey?: boolean; metaKey?: boolean; shiftKey?: boolean; } | Record; type HotkeysEvent = { key?: string; keys: string; modifiers: ModifierCombination; scopes?: string[]; }; type HotkeyOptions = { enabled?: boolean; preventDefault?: boolean; stopImmediatePropagation?: boolean; stopPropagation?: boolean; }; declare const _default: { alert: { caution: string; changeType: string; important: string; note: string; tip: string; warning: string; }; block: { copy: string; delete: string; select: string; }; cancel: string; chart: { apply: string; editChart: string; editSource: string; form: { addRef: string; addRow: string; addSeries: string; compact: string; decimals: string; donut: string; fieldName: string; format: string; highlight: string; label: string; none: string; note: string; pieFirstSeries: string; refLabel: string; refValue: string; refs: string; removeRef: string; removeRow: string; removeSeries: string; series: string; signed: string; source: string; stacked: string; subtitle: string; tabs: { data: string; setup: string; style: string; }; title: string; type: string; unit: string; x: string; xLabel: string; yAxis: string; yMax: string; yMin: string; }; invalid: string; loading: string; reference: string; showChart: string; source: string; type: { area: string; bar: string; line: string; pie: string; }; }; codemirror: { copySuccess: string; preview: string; selectLanguage: string; selectTheme: string; showLineNumbers: string; tabSize: string; theme: string; useTabs: string; }; confirm: string; file: { download: string; error: string; preview: string; uploading: string; }; heading: { copyLink: string; copyLinkSuccess: string; fold: string; unfold: string; }; footnote: { backToReference: string; missingDefinition: string; unused: string; }; image: { broken: string; captionPlaceholder: string; copy: string; delete: string; more: string; preview: string; replace: string; }; link: { copy: string; copySuccess: string; convertToCard: string; convertToIframe: string; convertToLink: string; convertToSchema: string; edit: string; editLinkTitle: string; editTextTitle: string; open: string; placeholder: string; unlink: string; }; markdown: { autoFormatMessage: string; autoFormatTitle: string; cancel: string; confirm: string; parseMessage: string; parseTitle: string; }; math: { placeholder: string; }; media: { width: string; widthAuto: string; widthAutoHint: string; widthPercent: string; widthPx: string; }; modifier: { accept: string; acceptAll: string; reject: string; rejectedAll: string; }; table: { align: string; alignCenter: string; alignLeft: string; alignRight: string; autoFitWidth: string; columnWidth: string; delete: string; deleteColumn: string; deleteColumns: string; deleteRow: string; deleteRows: string; distributeWidth: string; gripColumn: string; gripRow: string; gripTable: string; insertColumn: string; insertColumnLeft: string; insertColumnRight: string; insertRow: string; insertRowAbove: string; insertRowBelow: string; syncWidth: string; }; toc: { ariaLabel: string; empty: string; expand: string; pin: string; title: string; unpin: string; }; video: { add: string; embed: string; embedConfirm: string; embedPlaceholder: string; error: string; formats: string; loop: string; remove: string; replace: string; settings: string; upload: string; uploading: string; }; }; /** * Internationalization key type declaration, plugins can extend through declaration merging */ type LocaleType = typeof _default; type FlattenKeys = { [K in keyof T & string]: T[K] extends string ? Prefix extends '' ? K : `${Prefix}.${K}` : T[K] extends Record ? FlattenKeys : never; }[keyof T & string]; type ILocaleKeys = Record, string>; type IDecoratorFunc = (_node: LexicalNode, _editor: LexicalEditor) => any; type INodeRegistrationTransform = (node: LexicalNodeConfig, index: number) => LexicalNodeConfig | null | undefined; type IBeforeEditorInitLifecycle = () => void; type IDecorator = { queryDOM: (_element: HTMLElement) => HTMLElement; render: IDecoratorFunc; } | IDecoratorFunc; /** * Service ID type */ type IServiceID = { readonly __serviceId: string; __serviceType?: Service; }; interface ISelectionObject { endNodeId: string; endOffset: number; startNodeId: string; startOffset: number; type: 'range' | 'node' | 'table'; } interface IDocumentOptions { [key: string]: unknown; keepHistory?: boolean; /** only work for json datasource */ keepId?: boolean; } interface IKernelEventMap { /** * Document change event */ documentChange: (type: string, content: any) => void; /** * Editor editable state change event */ editableChange: (editable: boolean) => void; /** * Editor error event */ error: (error: Error) => void; /** * Initialization event * @param editor Lexical editor instance * @returns */ initialized: (editor: LexicalEditor) => void; /** * handle markdown parse event */ markdownParse: (params: { cacheState: EditorState; historyState: HistoryStateEntry | null; markdown: string; matchedPatterns: string[]; score: number; }) => void; /** * handle paste event */ onPaste: (event: ClipboardEvent) => void; } /** * External API */ interface IEditor { /** * Lose focus */ blur(): void; /** * Clean editor content (clear all content) */ cleanDocument(): void; /** * Destroy editor instance */ destroy(): void; /** * Execute editor commands to manipulate editor content * @param type * @param payload */ dispatchCommand>(type: TCommand, payload: CommandPayloadType): boolean; /** * Focus editor */ focus(): void; /** * Get editor content of specified type */ getDocument(type: string, options?: IWriteOptions): DataSource | undefined; /** * Lexical history state (undo stack metadata) */ getHistoryState(): HistoryState; /** * Get Lexical editor instance */ getLexicalEditor(): LexicalEditor | null; /** * Get document editor root node */ getRootElement(): HTMLElement | null; /** * Get editor selection information */ getSelection(): ISelectionObject | null; /** * Get document editor selection content of specified type * @param type */ getSelectionDocument(type: string): unknown | null; /** * Get editor theme */ getTheme(): Record>; /** * Get headless editor instance */ initHeadlessEditor(): LexicalEditor | null; /** * Get node editor instance */ initNodeEditor(): LexicalEditor | null; /** * Check if editor is editable */ isEditable(): boolean; /** * Check if editor content is empty * @returns true if editor content is empty, false otherwise */ get isEmpty(): boolean; /** * Check if editor has active selection * @returns true if editor has selection, false otherwise */ get isSelected(): boolean; /** * Remove editor event listener * @param event * @param listener */ off(event: T, listener: IKernelEventMap[T]): this; /** * Add editor event listener * @param event * @param listener */ on(event: T, listener: IKernelEventMap[T]): this; /** * Listen to event once, automatically remove listener after trigger * @param event * @param listener */ once(event: T, listener: IKernelEventMap[T]): this; /** * Extends the priority level of Lexical commands. * Registers a listener that triggers when the provided command is dispatched * via {@link LexicalEditor.dispatch}. The listener is triggered based on its priority. * Listeners with higher priority can "intercept" commands and prevent them * from propagating to other handlers by returning true. * * Listeners are always invoked within {@link LexicalEditor.update} and can call dollar functions. * * Listeners registered at the same priority level will deterministically run * in the order of registration. * * @param command - The command that triggers the callback. * @param listener - The function executed when the command is dispatched. * @param priority - The relative priority of the listener. 0 | 1 | 2 | 3 | 4 * (or {@link COMMAND_PRIORITY_EDITOR} | * {@link COMMAND_PRIORITY_LOW} | * {@link COMMAND_PRIORITY_NORMAL} | * {@link COMMAND_PRIORITY_HIGH} | * {@link COMMAND_PRIORITY_CRITICAL}) * @returns A teardown function to clean up the listener. */ registerHighCommand

(command: LexicalCommand

, listener: CommandListener

, priority: CommandListenerPriority): () => void; /** * Register keyboard shortcut * @param hotkey * @param callback * @param options */ registerHotkey(hotkey: HotkeyId, callback: (event: KeyboardEvent, handler: HotkeysEvent) => void, options?: HotkeyOptions): () => void; /** * Register internationalization text * @param locale Internationalization text object */ registerLocale(locale: Partial>): void; /** * Register editor plugin */ registerPlugin(plugin: IEditorPluginConstructor, config?: T): IEditor; /** * Register multiple editor plugins */ registerPlugins(plugins: Array): IEditor; /** * Get editor Service, usually provided by plugins to extend certain functionalities * @param serviceId */ requireService(serviceId: IServiceID): T | null; /** * Set editor content, type is content type, content is content data * @param type * @param content */ setDocument(type: string, content: any, options?: IDocumentOptions): void; /** * Enable or disable editor editing capability * @param editable */ setEditable(editable: boolean): void; /** * Set document editor root node * @param dom */ setRootElement(dom: HTMLElement, editable?: boolean): LexicalEditor; setRootElement(dom: null, editable?: boolean): LexicalEditor | null; /** * set editor selection * @param selection */ setSelection(selection: ISelectionObject, opt?: { collapseToEnd?: boolean; collapseToStart?: boolean; }): Promise; /** * Get translation text * @param key Translation key * @param params Parameter replacement */ t(key: K, params?: Record): string; /** * Update editor theme * @param key * @param value */ updateTheme(key: string, value: string | Record): void; } /** * API provided to plugins */ interface IEditorKernel extends IEditor { /** * Clone the current editor kernel instance */ cloneNodeEditor(): IEditorKernel; emit(event: T, params: Parameters[0]): void; /** * Get editor Node decorator for specific Node rendering * @param name */ getDecorator(name: string): IDecorator | undefined; /** * Get all registered decorator names */ getRegisteredDecorators(): string[]; /** * Check if hot reload mode is enabled */ isHotReloadMode(): boolean; /** * Register a lifecycle hook that runs right before editor initialization. * @param hook * @returns unregister function */ registerBeforeEditorInit(hook: IBeforeEditorInitLifecycle): () => void; /** * Register data source for multi-format data conversion * @param dataSource */ registerDataSource(dataSource: DataSource): void; /** * Register editor node decorator * @param name * @param decorator */ registerDecorator(name: string, decorator: IDecorator): void; /** * Register a transform hook that runs before editor initialization * to rewrite registered nodes before createEditor/createHeadlessEditor is called. * @param transform * @returns unregister function */ registerNodeTransform(transform: INodeRegistrationTransform): () => void; /** * Register Lexical Node * @param nodes */ registerNodes(nodes: Array): void; /** * Register className(s) to the contenteditable root element. * @param className One or more class names separated by spaces * @returns unregister function */ registerRootClassName(className: string): () => void; /** * Register a callback for root attach/detach events. * * Call this after the kernel's Lexical editor has been initialized (usually * from plugin onInit). Lexical immediately invokes a newly registered root * listener with the current root, so listeners registered after the initial * setRootElement still receive the first root attach. Headless kernels * return a no-op cleanup because headless Lexical editors do not support * root listeners. */ registerRootListener(listener: (rootElement: HTMLElement | null) => void): () => void; /** * Register service * @param serviceId * @param service */ registerService(serviceId: IServiceID, service: T): void; /** * Register service with hot reload support - allows overriding existing services * @param serviceId Service identifier * @param service Service instance */ registerServiceHotReload(serviceId: IServiceID, service: T): void; /** * Register theme * @param themes */ registerThemes(themes: Record): void; /** * Enable or disable hot reload mode * @param enabled Whether to enable hot reload mode */ setHotReloadMode(enabled: boolean): void; /** * Unregister editor node decorator * @param name Decorator name */ unregisterDecorator(name: string): boolean; } /** * Plugin interface */ interface IEditorPlugin { config?: IConfig; /** * Editor destruction */ destroy(): void; /** * After editor document content is written by setDocument */ onDocumentChange?(type: string, content: any, options?: IDocumentOptions): void; /** * After Lexical editor instantiation * @param editor Lexical editor instance */ onInit?(editor: LexicalEditor): void; } /** * Plugin class interface */ interface IEditorPluginConstructor { readonly pluginName: string; new (kernel: IEditorKernel, config?: IConfig): IEditorPlugin; } type IPlugin = IEditorPluginConstructor | [IEditorPluginConstructor, T?]; /** A detached, immutable description of the currently active logical node. */ interface NodeIdentitySnapshot { readonly id: string; /** Native Lexical text; a review container can include both pending sides. */ readonly textContent: string; readonly type: string; } interface INodeIdentityService { /** Read the last committed editor state without retaining a LexicalNode. */ getNodeById(nodeId: string): Readonly | null; /** Subscribe to committed updates; query the service in the callback. */ subscribe(listener: () => void): () => void; } declare const INodeIdentityService: IServiceID; export { IPlugin as a, IEditor as i, NodeIdentitySnapshot as n, IDocumentOptions as r, INodeIdentityService as t };