@lobehub/editor
Version:
A powerful and extensible rich text editor built on Meta's Lexical framework, providing a modern editing experience with React integration.
63 lines (62 loc) • 2.15 kB
TypeScript
import type { LexicalEditor } from 'lexical';
import { DataSource } from "../../../editor-kernel";
import type { IWriteOptions } from "../../../editor-kernel/data-source";
import { IServiceID } from "../../../types";
import type { ILitexmlService } from '../service/litexml-service';
/**
* LitexmlDataSource - Handles conversion between Lexical editor state and XML format
* Provides read (parse XML to Lexical) and write (export Lexical to XML) capabilities
*/
export default class LitexmlDataSource extends DataSource {
protected dataType: string;
protected getService?: (<T>(serviceId: IServiceID<T>) => T | null) | undefined;
private litexmlService;
private ctx;
constructor(dataType?: string, getService?: (<T>(serviceId: IServiceID<T>) => T | null) | undefined, service?: ILitexmlService);
readLiteXMLToInode(litexml: string): any;
/**
* Parse XML string and set it to the editor
* @param editor - The Lexical editor instance
* @param data - XML string to parse
*/
read(editor: LexicalEditor, data: string): void;
/**
* Export editor content to XML format
* @param editor - The Lexical editor instance
* @param options - Write options (e.g., selection flag)
* @returns XML string representation of the editor content
*/
write(editor: LexicalEditor, options?: IWriteOptions): any;
/**
* Parse XML string using browser's built-in parser
*/
private parseXMLString;
/**
* Convert XML document to Lexical node structure
*/
private xmlToLexical;
/**
* Recursively process XML elements and convert to Lexical nodes
*/
private processXMLElement;
/**
* Process XML element's children
*/
private processXMLChildren;
/**
* Convert Lexical node structure to XML string
*/
private lexicalToXML;
/**
* Recursively convert Lexical nodes to XML elements
*/
private nodesToXML;
/**
* Build XML attribute string from attributes object
*/
private buildXMLAttributes;
/**
* Escape XML special characters
*/
private escapeXML;
}