///
import { Editor, Node, Path, Point, Range } from 'slate';
import { DOMNode } from 'slate-dom';
import { History } from 'slate-history';
import { ReactEditor } from 'slate-react';
import { CardNode, CustomLeaf, Elements, ListNode, ParagraphNode } from '../../el';
export declare class EditorUtils {
static get p(): {
readonly type: "paragraph";
readonly children: readonly [{
readonly text: "";
}];
};
static hasPath(editor: Editor, path: Path): boolean;
static focus(editor: Editor): void;
static blur(editor: Editor): void;
static isPrevious(firstPath: Path, nextPath: Path): boolean;
static isNextPath(firstPath: Path, nextPath: Path): boolean;
static isDirtLeaf(leaf: CustomLeaf): string | true | undefined;
static isTop(editor: Editor, path: Path): boolean;
static findPrev(editor: Editor, path: Path): Path;
static findMediaInsertPath(editor: Editor): Path | null;
static findNext(editor: Editor, path: Path): Path | undefined;
static moveNodes(editor: Editor, from: Path, to: Path, index?: number): void;
static moveAfterSpace(editor: Editor, path: Path): void;
static moveBeforeSpace(editor: Editor, path: Path): void;
private static readonly CLEARABLE_MARKS;
/**
* 清除编辑器中选中的文本的所有标记
*
* @param editor - 编辑器实例
* @param split - 是否在格式边界处分割文本节点,默认为 false
*
* @description
* 该方法执行以下操作:
* 1. 移除选中文本的所有格式标记
* 2. 处理列表项的提升和转换
* 3. 将选中区域转换为段落格式
*
* 当 split=true 时,会在不同格式的边界处分割文本节点,
* 这允许对部分文本应用/移除格式而不影响相邻文本
*/
static clearMarks(editor: Editor, split?: boolean): void;
/**
* 将列表节点转换为段落节点数组
*
* @param editor - 编辑器实例
* @param listNode - 要处理的列表节点
* @returns 从列表节点中提取的所有段落节点的数组
*
* @description
* 该方法通过递归遍历列表节点及其子节点,提取所有段落节点,
* 并将它们汇集成一个扁平化的数组。支持嵌套列表的处理。
*/
static listToParagraph(editor: Editor, listNode: ListNode): ParagraphNode[];
/**
* 替换编辑器中当前选中的节点
*
* @param editor - 编辑器实例
* @param newNode - 要插入的新节点数组
*
* @description
* 该方法会查找当前选区中的最低块级节点,然后用新的节点替换它。
* 替换过程包括:查找最低块级节点,选中整个节点,插入新节点来替换原内容。
*/
static replaceSelectedNode: (editor: Editor, newNode: Elements[]) => void;
/**
* 删除编辑器中的所有内容,并插入新的节点
*
* @param editor - 编辑器实例
* @param insertNodes - 要插入的新节点数组。如果未提供,将插入默认段落节点
*/
static deleteAll(editor: Editor, insertNodes?: Elements[]): void;
/**
* 重置编辑器的内容,并可选地插入新的节点和重置历史记录
*
* @param editor - 要重置的编辑器实例
* @param insertNodes - 可选的插入节点数组。如果未提供,则使用默认段落节点
* @param force - 可选的布尔值或历史记录对象。如果为布尔值,则强制重置历史记录;如果为历史记录对象,则使用提供的历史记录
*/
static reset(editor: Editor, insertNodes?: Elements[], force?: boolean | History): void;
/**
* 检查选区是否完全包含在指定节点路径中。
*
* @param editor - 编辑器实例。
* @param sel - 选区范围。
* @param nodePath - 节点路径。
* @returns 如果选区完全包含在节点路径中,则返回 true,否则返回 false。
*/
static includeAll(editor: Editor, sel: Range, nodePath: Path): boolean;
static copy(data: object): any;
/**
* 复制指定范围内的文本内容。
*
* @param editor - 编辑器实例。
* @param start - 文本复制的起始位置。
* @param end - (可选)文本复制的结束位置。如果未提供,则复制从起始位置到文档末尾的所有文本。
* @returns 返回指定范围内的文本内容。
*/
static copyText(editor: Editor, start: Point, end?: Point): string;
/**
* 从编辑器中剪切文本。
*
* @param editor - 编辑器实例。
* @param start - 开始位置的点。
* @param end - 结束位置的点(可选)。
* @returns 剪切的文本数组,每个元素为一个 CustomLeaf 对象。
*/
static cutText(editor: Editor, start: Point, end?: Point): CustomLeaf[];
/**
* 检查编辑器中是否有指定格式的活动节点
*
* @param editor - 编辑器实例
* @param format - 要检查的格式名称
* @param value - 可选的值,用于进一步验证格式是否匹配
* @returns 如果存在匹配的格式节点,则返回 true;否则返回 false
*/
static isFormatActive(editor: Editor, format: string, value?: any): boolean;
/**
* 获取编辑器中选中文本的URL
*
* @param editor - 编辑器实例
* @returns 返回选中文本的URL,如果没有则返回空字符串
*/
static getUrl(editor: Editor): string;
/**
* 切换文本格式(加粗、斜体等)
*
* @param editor - 编辑器实例
* @param format - 要切换的格式类型
*/
static toggleFormat(editor: Editor, format: string): void;
/**
* 为编辑器中的文本节点设置高亮颜色
*
* @param editor - 编辑器实例
* @param color - 可选的高亮颜色字符串。如果未提供,则移除高亮颜色
*/
static highColor(editor: Editor, color?: string): void;
/**
* 设置文本对齐方式
*
* @param editor - 编辑器实例
* @param alignment - 对齐方式:'left', 'center', 或 'right'
*/
static setAlignment(editor: Editor, alignment: 'left' | 'center' | 'right'): void;
/**
* 检查当前选中块的对齐方式
*
* @param editor - 编辑器实例
* @param alignment - 要检查的对齐方式
* @returns 是否处于指定的对齐方式
*/
static isAlignmentActive(editor: Editor, alignment: string): boolean;
/**
* 检查编辑器末尾是否需要添加段落节点
*
* @param editor - 编辑器实例
* @returns 如果添加了段落节点则返回 true,否则返回 false
*/
static checkEnd(editor: Editor): boolean;
/**
* 检查指定路径是否在编辑器末尾
*
* @param editor - 编辑器实例
* @param path - 要检查的路径
* @returns 如果路径在末尾则返回 true,否则返回 false
*/
static checkSelEnd(editor: Editor, path: Path): boolean;
/**
* 安全地查找元素对应的Slate路径
*
* @param editor - 编辑器实例
* @param el - DOM元素
* @returns 元素对应的路径,如果查找失败则返回编辑器起始路径
*/
static findPath(editor: Editor, el: any): Path;
/**
* 创建媒体节点(图片、视频等)
*
* @param src - 媒体资源URL
* @param type - 媒体类型
* @param extraPros - 额外属性
* @returns 创建的媒体节点
*/
static createMediaNode(src: string | undefined, type: string, extraPros?: Record): CardNode | {
text: string;
};
/**
* 标准化URL,添加协议前缀
*/
private static normalizeUrl;
/**
* 解析URL参数
*/
private static parseUrlParams;
/**
* 检查是否为图片类型
*/
private static isImageType;
/**
* 创建图片节点
*/
private static createImageNode;
/**
* 创建通用媒体节点
*/
private static createGenericMediaNode;
/**
* 用卡片节点包装普通节点
*
* @param node - 要包装的节点
* @param props - 额外属性
* @returns 包装后的卡片节点
*/
static wrapperCardNode(node: any, props?: Record): CardNode;
}
export declare const getDefaultView: (value: any) => Window | null;
export declare const isDOMNode: (value: any) => value is DOMNode;
export declare const isEventHandled: >(event: EventType, handler?: ((event: EventType) => void) | undefined) => boolean;
export declare const hasTarget: (editor: ReactEditor, target: EventTarget | null) => target is DOMNode;
export declare const isTargetInsideVoid: (editor: ReactEditor, target: EventTarget | null) => boolean;
/**
* 基于 anchorNode 和 focusNode 创建新的 DOM Selection 对象
*
* @param anchorNode - 选区起始节点
* @param anchorOffset - 起始节点中的偏移量
* @param focusNode - 选区结束节点
* @param focusOffset - 结束节点中的偏移量
* @returns 新创建的 Selection 对象,如果创建失败则返回 null
*/
export declare function createSelectionFromNodes(anchorNode: Node | null, anchorOffset: number, focusNode: Node | null, focusOffset: number): Selection | null;
/**
* 基于 anchorNode 和 focusNode 创建 DOM Range 对象
*
* @param anchorNode - 选区起始节点
* @param anchorOffset - 起始节点中的偏移量
* @param focusNode - 选区结束节点
* @param focusOffset - 结束节点中的偏移量
* @returns 新创建的 DOM Range 对象,如果创建失败则返回 null
*/
export declare function createDomRangeFromNodes(anchorNode: Node | null, anchorOffset: number, focusNode: Node | null, focusOffset: number): globalThis.Range | null;
/**
* 从 DOM Selection 对象中提取并转换为 Slate Range
*
* @param editor - React 编辑器实例
* @param domSelection - DOM Selection 对象
* @returns 转换后的 Slate Range 对象,如果转换失败则返回 null
*/
export declare function getSelectionFromDomSelection(editor: ReactEditor, domSelection: Selection): Range | null;
/**
* 检查目标是否为可编辑的 DOM 节点。
*
* @param editor - React 编辑器实例。
* @param target - 事件目标,可能为 null。
* @returns 如果目标是可编辑的 DOM 节点,则返回 true。
*/
export declare const hasEditableTarget: (editor: ReactEditor, target: EventTarget | null) => target is DOMNode;
export declare function getPointStrOffset(editor: Editor, point: Point): number;
export declare function getRelativePath(path: string | any[], anther: string | any[]): any[];
export declare function calcPath(path: string | any[], anther: string | any[]): any[];
export declare function isPath(path: string | any[]): boolean;
export declare function findLeafPath(editor: Editor, path: Path): Path;
/**
* 转义正则表达式特殊字符
*
* @param string - 需要转义的字符串
* @returns 转义后的字符串
* @private
*/
export declare function escapeRegExp(string: string): string;
/**
* 清理和标准化 Markdown 搜索文本
*
* @param searchText - 原始搜索文本,可能包含 Markdown 语法
* @returns 包含原文本和清理后文本的数组
* @public
*/
export declare function normalizeMarkdownSearchText(searchText: string): string[];
/**
* 在编辑器中按路径和文本搜索内容,支持 Markdown 文本的智能处理
*
* @param editor - 编辑器实例
* @param pathDescription - 搜索范围的路径描述
* @param searchText - 搜索文本,支持 Markdown 语法
* @param options - 搜索选项
* @param options.caseSensitive - 是否区分大小写,默认 false
* @param options.wholeWord - 是否全词匹配,默认 false
* @param options.maxResults - 最大结果数量,默认 2
* @param options.includeMarkdownVariants - 是否包含 Markdown 语法的清理变体,默认 true
* @returns 搜索结果数组,包含路径、范围、节点、链接信息等
*
* @description
* 该函数支持以下功能:
* - 自动清理 Markdown 语法(链接、粗体、斜体、代码等)
* - 生成多个搜索变体以提高匹配率
* - 避免重复匹配同一位置的文本
* - 记录匹配的搜索变体信息
* - 支持识别链接(a 标签):返回结果包含 isLink 和 linkUrl 字段
*
* @example
* // 搜索包含 Markdown 语法的文本
* const results = findByPathAndText(editor, [0], "**粗体文本**");
* // 将同时匹配 "**粗体文本**" 和 "粗体文本"
*
* @example
* // 搜索链接文本
* const results = findByPathAndText(editor, [0], "点击这里");
* // 如果匹配到的是链接,results[0].isLink === true 且 results[0].linkUrl 包含 URL
*/
export declare function findByPathAndText(editor: Editor, pathDescription: Path, searchText: string, options?: {
caseSensitive?: boolean;
wholeWord?: boolean;
maxResults?: number;
includeMarkdownVariants?: boolean;
}): {
path: Path;
range: Range;
node: Node;
matchedText: string;
offset: {
start: number;
end: number;
};
lineContent: string;
nodeType?: string | undefined;
searchVariant?: string | undefined;
isLink?: boolean | undefined;
linkUrl?: string | undefined;
}[];