UNPKG

@textbus/core

Version:

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

128 lines (127 loc) 3.58 kB
import { Provider, ReflectiveInjector, Scope } from '@viewfly/core'; import { Observable, Subject } from '@tanbo/stream'; import { AsyncComponentConstructor, Attribute, Component, ComponentConstructor, ComponentLiteral, Formatter } from './model/_api'; import { Adapter } from './base/_api'; /** * Textbus 插件接口 */ export interface Plugin { /** * 编辑器初始化时调用的勾子 * @param textbus 访问 Textbus 内部实例的 IoC 容器 */ setup(textbus: Textbus): void; /** * 当编辑器销毁时调用 */ onDestroy?(): void; } /** * Textbus 模块配置 */ export interface Module { /** 组件列表 */ components?: (ComponentConstructor | AsyncComponentConstructor)[]; /** 格式列表 */ formatters?: Formatter<any>[]; /** 属性列表 */ attributes?: Attribute<any>[]; /** 跨平台及基础扩展实现的提供者 */ providers?: Provider[]; /** 插件集合 */ plugins?: Plugin[]; /** * 当模块注册时调用 */ beforeEach?(textbus: Textbus): void; /** * 初始化时的设置,返回一个函数,当 Textbus 销毁时调用 * @param textbus */ setup?(textbus: Textbus): Promise<(() => void) | void> | (() => void) | void; /** * 当启动完成时触发 */ onAfterStartup?(textbus: Textbus): void; /** * 当 Textbus 销毁时触发 */ onDestroy?(textbus: Textbus): void; } /** * Textbus 核心配置 */ export interface TextbusConfig extends Module { /** 导入第三方包 */ imports?: Module[]; /** 开启 Zen Coding 支持 */ zenCoding?: boolean; /** 最大历史记录栈 */ historyStackSize?: number; /** 是否只读 */ readonly?: boolean; /** 附加的渲染器。常用于在内存中渲染 HTML 字符串*/ additionalAdapters?: Adapter<any, any, any>[]; } /** * Textbus 内核启动器 */ export declare class Textbus extends ReflectiveInjector { config: TextbusConfig; static diScope: Scope; /** 当编辑器初始化完成时触发 */ onReady: Observable<void>; /** 当视图获得焦点时触发 */ onFocus: Observable<void>; /** 当视图失去焦点时触发 */ onBlur: Observable<void>; /** 当编辑器内容变化时触发 */ onChange: Observable<void>; /** 当用户按 Ctrl + S 时触发 */ onSave: Observable<void>; /** 编辑器是否已销毁 */ destroyed: boolean; /** 编辑器是否已准备好 */ isReady: boolean; get readonly(): boolean; set readonly(b: boolean); get isFocus(): boolean; protected _isFocus: boolean; private beforeDestroyCallbacks; private plugins; private isDestroyed; protected changeEvent: Subject<void>; private controller; private focusEvent; private blurEvent; private saveEvent; private readyEvent; private beforeSelection; constructor(config: TextbusConfig); /** * 启动一个 Textbus 实例,并将根组件渲染到原生节点 * @param rootComponent 根组件 */ render(rootComponent: Component): Promise<this>; /** * 获取焦点 */ focus(): void; /** * 取消编辑器焦点 */ blur(): void; /** * 获取 JSON 格式的内容 */ getJSON(): ComponentLiteral; nextTick(task: () => void): void; /** * 销毁 Textbus 实例 */ destroy(): void; protected guardReady(): void; private mergeModules; private bindContext; private initDefaultShortcut; }