UNPKG

@textbus/core

Version:

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

101 lines (100 loc) 4.67 kB
import { Observable } from '@tanbo/stream'; import { Injector } from '@viewfly/core'; import { Component } from '../model/component'; import { Slot } from '../model/slot'; import { NodeLocation, VElement, VTextNode } from '../model/element'; export interface ViewMount<ViewComponent, NativeElement> { (host: NativeElement, viewComponent: ViewComponent, injector: Injector): (void | (() => void)); } export interface Renderer<ViewComponent, ViewElement, NativeElement, NativeTextNode> { componentRender(component: Component<any>): ViewComponent; vElementToViewElement(vEle: VElement, children: Array<ViewElement | string>): ViewElement; getAndUpdateSlotRootNativeElement(vEle: VElement, update: (nativeElement: NativeElement | null) => void): void; createCompositionNode(compositionState: CompositionState, updateNativeCompositionNode: (nativeNode: NativeElement | null) => void): VElement; getChildByIndex(parentElement: NativeElement, index: number): NativeElement | NativeTextNode; getParentNode(node: NativeElement | NativeTextNode): NativeElement | null; getChildNodes(parentElement: NativeElement): Array<NativeElement | NativeTextNode>; isNativeElementNode(node: NativeElement | NativeTextNode): node is NativeElement; } export interface CompositionState { slot: Slot; text: string; offset: number; index: number; } /** * Textbus 渲染适配器 */ export declare abstract class Adapter<NativeElement extends {} = {}, NativeTextNode extends {} = {}, ViewComponent extends {} = {}, ViewElement extends {} = {}> { private adapter; private mount; composition: CompositionState | null; /** 当视图更新时触发事件的可观察对象,用于通知 Textbus 视图渲染已完成 */ abstract onViewUpdated: Observable<void>; abstract host: NativeElement; protected firstRending: boolean; protected slotRootVElementCaches: WeakMap<Slot, VElement>; protected slotRootNativeElementCaches: { set: { (key: Slot, value: NativeElement): void; (key: NativeElement, value: Slot): void; }; get: { (key: Slot): NativeElement; (key: NativeElement): Slot; }; remove: (key: Slot | NativeElement) => void; }; protected componentRootElementCaches: { set: { (key: Component<import("../public-api").State>, value: NativeElement): void; (key: NativeElement, value: Component<import("../public-api").State>): void; }; get: { (key: Component<import("../public-api").State>): NativeElement; (key: NativeElement): Component<import("../public-api").State>; }; remove: (key: Component<import("../public-api").State> | NativeElement) => void; }; compositionNode: any; protected constructor(adapter: Renderer<ViewComponent, ViewElement, NativeElement, NativeTextNode>, mount: ViewMount<ViewComponent, NativeElement>); /** 根组件渲染方法 */ render(rootComponent: Component, injector: Injector): void | (() => void); componentRender(component: Component<any>): ViewComponent; slotRender(slot: Slot, slotHostRender: (children: Array<VElement | VTextNode | Component>) => VElement, renderEnv?: any): ViewElement; protected insertCompositionByIndex(slot: Slot, vNode: VElement, composition: CompositionState, createCompositionNode: (composition: CompositionState) => VElement): void; /** * 根据组件获取组件的根 DOM 节点 * @param component */ getNativeNodeByComponent(component: Component): NativeElement | null; /** * 根据 DOM 节点,获对对应的组件根节点,如传入的 DOM 节点不为组件的根节点,则返回 null * @param node */ getComponentByNativeNode(node: NativeElement): Component | null; /** * 根据插槽获取插槽的根 DOM 节点 * @param slot */ getNativeNodeBySlot(slot: Slot): NativeElement | null; /** * 根据 DOM 节点,获对对应的插槽根节点,如传入的 DOM 节点不为插槽的根节点,则返回 null * @param node */ getSlotByNativeNode(node: NativeElement): Slot | null; /** * 获取插槽内容节点集合 * @param slot */ getNodesBySlot(slot: Slot): (NativeElement | NativeTextNode)[]; /** * 获取原生节点的原始数据在文档中的位置 * @param node */ getLocationByNativeNode(node: NativeElement | NativeTextNode): NodeLocation | null; private getNodes; private getLocation; /** 当前平台的复制能力 */ abstract copy(): void; }