UNPKG

@textbus/core

Version:

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

110 lines (109 loc) 3.07 kB
import { Formatter } from './attribute'; import { Slot } from './slot'; /** * 格式或属性的值,必须为可被 JSON 序列化的字面量 */ export type FormatValue = any; /** * 一组格式 */ export type Formats = [formatter: Formatter<any>, value: FormatValue][]; /** * 标识格式的范围 */ export interface FormatRange<T = FormatValue> { startIndex: number; endIndex: number; value: T; } /** * 格式的字面量 */ export interface FormatLiteral<T = FormatValue> { [key: string]: FormatRange<T>[]; } /** * 格式的详情 */ export interface FormatItem<T = FormatValue> extends FormatRange<T> { formatter: Formatter<T>; } /** * 格式树 */ export interface FormatTree<T = FormatValue> { startIndex: number; endIndex: number; children?: FormatTree<T>[]; formats?: FormatItem<T>[]; } /** * Textbus 格式管理类 * Format 类为 Slot 的私有属性,在实际场景中,开发者不需在关注此类,也不需要访问或操作此类 */ export declare class Format { private slot; private map; constructor(slot: Slot); /** * 将新样式合并到现有样式中 * @param formatter * @param value * @param background */ merge<T extends FormatValue>(formatter: Formatter<T>, value: FormatRange<T>, background?: boolean): this; /** * 将 index 后的样式起始和结束位置均增加 count 大小 * @param index * @param count */ stretch(index: number, count: number): this; /** * 将指定 index 位置后的样式向后平移 distance 长度 * @param index * @param distance */ split(index: number, distance: number): this; /** * 从指定 index 位置的样式删除 count * @param startIndex * @param count */ shrink(startIndex: number, count: number): this; /** * 提取指定范围内的样式 * @param startIndex * @param endIndex * @param formatter */ extract(startIndex: number, endIndex: number, formatter?: Formatter[]): Format; /** * 生成一个重置位置的 format * @param slot * @param startIndex * @param endIndex */ createFormatByRange(slot: Slot, startIndex: number, endIndex: number): Format; /** * 通过 formatter 提取指定范围内的样式数据 * @param startIndex * @param endIndex * @param formatter */ extractFormatRangesByFormatter(startIndex: number, endIndex: number, formatter: Formatter<any>): FormatRange<any>[]; /** * 丢弃指定范围内的样式 * @param formatter * @param startIndex * @param endIndex */ discard(formatter: Formatter<any>, startIndex: number, endIndex: number): this; extractFormatsByIndex(index: number): Formats; toGrid(): number[]; toJSON(): FormatLiteral<any>; toTree(startIndex: number, endIndex: number): FormatTree<any>; toArray(): FormatItem<any>[]; private normalizeFormatRange; private static equal; private static mergeRanges; }