UNPKG

@textbus/browser

Version:

Textbus is a rich text editor and framework that is highly customizable and extensible to achieve rich wysiwyg effects.

48 lines (47 loc) 1.59 kB
import { Injector } from '@tanbo/di'; import { ComponentInstance, Formatter, FormatValue, Slot } from '@textbus/core'; import { ViewOptions } from '../core/types'; export interface ComponentResources { links?: Array<{ [key: string]: string; }>; styles?: string[]; scripts?: string[]; editModeStyles?: string[]; } export interface SlotParser { <T extends Slot>(childSlot: T, childElement: HTMLElement): T; } /** * 组件加载器 */ export interface ComponentLoader { /** 组件所需要的外部资源 */ resources?: ComponentResources; /** 识别组件的匹配方法 */ match(element: HTMLElement): boolean; /** 读取组件内容的方法 */ read(element: HTMLElement, context: Injector, slotParser: SlotParser): ComponentInstance | Slot; } export interface FormatLoaderReadResult { formatter: Formatter; value: FormatValue; } export interface FormatLoader { match(element: HTMLElement): boolean; read(element: HTMLElement): FormatLoaderReadResult; } export declare class Parser { private options; private injector; static parseHTML(html: string): HTMLElement; componentLoaders: ComponentLoader[]; formatLoaders: FormatLoader[]; constructor(options: ViewOptions, injector: Injector); parseDoc(html: string, rootComponentLoader: ComponentLoader): Slot<any> | ComponentInstance<import("@textbus/core").ComponentExtends, any, unknown>; parse(html: string, rootSlot: Slot): Slot<any>; private readComponent; private readFormats; private readSlot; private applyFormats; }