@lobehub/editor
Version:
A powerful and extensible rich text editor built on Meta's Lexical framework, providing a modern editing experience with React integration.
89 lines (88 loc) • 2.9 kB
TypeScript
import type { LexicalNode } from 'lexical';
/**
* XML Reader function type - converts XML element to Lexical node
*/
export type XMLReaderFunc = (xmlElement: Element, children: any[]) => any | any[] | false;
/**
* XML Writer function type - converts Lexical node to XML string
*/
export type XMLWriterFunc = (node: LexicalNode, ctx: IWriterContext, indent: number, nodeToXML: (node: any, lines: string[], indent?: number) => void) => IXmlNode | HandleChildrenResult | false;
/**
* Record of XML readers indexed by tag name
*/
export type XMLReaderRecord = {
[tagName: string]: XMLReaderFunc | XMLReaderFunc[];
};
/**
* Record of XML writers indexed by node type
*/
export type XMLWriterRecord = {
[nodeType: string]: XMLWriterFunc | XMLWriterFunc[];
};
export interface IXmlNode {
attributes: {
[key: string]: string;
};
children?: IXmlNode[];
tagName: string;
textContent?: string;
}
export interface HandleChildrenResult {
lines: string[];
}
export interface IWriterContext {
createXmlNode(tagName: string, attributes?: {
[key: string]: string;
}, textContent?: string): IXmlNode;
}
/**
* ILitexmlService - Service interface for extending Litexml plugin
* Allows other plugins to register custom XML readers and writers
*/
export interface ILitexmlService {
/**
* Get all registered XML readers
*/
getXMLReaders(): XMLReaderRecord;
/**
* Get all registered XML writers
*/
getXMLWriters(): XMLWriterRecord;
/**
* Check if a reader is registered for a tag
*/
hasXMLReader(tagName: string): boolean;
/**
* Check if a writer is registered for a node type
*/
hasXMLWriter(nodeType: string): boolean;
/**
* Register a custom XML reader for a specific tag name
* @param tagName - XML tag name to handle (case-insensitive)
* @param reader - Function that converts XML element to Lexical node
*/
registerXMLReader(tagName: string, reader: XMLReaderFunc): void;
/**
* Register a custom XML writer for a specific Lexical node type
* @param nodeType - Lexical node type to handle
* @param writer - Function that converts Lexical node to XML string
*/
registerXMLWriter(nodeType: string, writer: XMLWriterFunc): void;
}
/**
* Service ID for Litexml service
*/
export declare const ILitexmlService: import("../../../types").IServiceID<ILitexmlService>;
/**
* Default implementation of ILitexmlService
*/
export declare class LitexmlService implements ILitexmlService {
private readers;
private writers;
registerXMLReader(tagName: string, reader: XMLReaderFunc): void;
registerXMLWriter(nodeType: string, writer: XMLWriterFunc): void;
getXMLReaders(): XMLReaderRecord;
getXMLWriters(): XMLWriterRecord;
hasXMLReader(tagName: string): boolean;
hasXMLWriter(nodeType: string): boolean;
}