UNPKG

@textbus/core

Version:

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

79 lines (78 loc) 3.11 kB
import { Range, Selection } from './selection'; import { Component, Formatter, FormatValue, ComponentConstructor, Attribute, State } from '../model/_api'; /** * Textbus 状态查询状态枚举 */ export declare enum QueryStateType { /** 正常 */ Normal = "Normal", /** 当前不可用 */ Disabled = "Disabled", /** 当前状态为生效 */ Enabled = "Enabled" } /** * Textbus 状态查询结果,当状态为 Normal,`value` 为 null */ export interface QueryState<V, S = QueryStateType, K = S extends QueryStateType.Enabled ? V : null> { state: S; value: K; } /** * Textbus 状态查询类,用于查询组件或格式在当前选区的状态 */ export declare class Query { private selection; constructor(selection: Selection); /** * 查询格式在当前选区的状态 * @param formatter 要查询的格式 */ queryFormat<T extends FormatValue>(formatter: Formatter<T>): QueryState<T>; /** * 根据指定范围查询格式在当前选区的状态 * @param formatter 要查询的格式 * @param range 要查询的格式的范围 */ queryFormatByRange<T extends FormatValue>(formatter: Formatter<T>, range: Range): QueryState<T>; /** * 查询属性在当前选区的状态 * @param attribute */ queryAttribute<T extends FormatValue>(attribute: Attribute<T>): QueryState<T>; /** * 根据指定范围查询属性在当前选区的状态 * @param attribute * @param range */ queryAttributeByRange<T extends FormatValue>(attribute: Attribute<T>, range: Range): QueryState<T>; /** * 查询组件在选区内的状态 * @param componentConstructor 要查询的组件 * @param filter 查询结构过滤函数,过滤不需要的数据 */ queryComponent<T extends State, U extends ComponentConstructor<T>>(componentConstructor: U, filter?: (instance: Component<T>) => boolean): QueryState<Component<T>>; /** * 根据指定范围查询组件在选区内的状态 * @param componentConstructor 要查询的组件 * @param range 要查询的范围 * @param filter 查询结构过滤函数,过滤不需要的数据 */ queryComponentByRange<T extends State, U extends ComponentConstructor<T>>(componentConstructor: U, range: Range, filter?: (instance: Component<T>) => boolean): QueryState<Component<T>>; /** * 查询当前选区是否包含在组件内 * @param componentConstructor 要查询的组件 */ queryWrappedComponent<T extends State>(componentConstructor: ComponentConstructor<T>): QueryState<Component<T>>; /** * 查询当前选区是否包含在组件内 * @param componentConstructor 要查询的组件 * @param range 要查询的范围 */ queryWrappedComponentByRange<T extends State>(componentConstructor: ComponentConstructor<T>, range: Range): QueryState<Component<T>>; private getStatesByRange; private mergeState; private getWrappedStateByComponent; private getStateByComponent; private getStateByAttribute; }