import { ContentPosition } from 'roosterjs-editor-types'; import type { CompatibleContentPosition } from 'roosterjs-editor-types/lib/compatibleTypes'; import type { BlockElement, IContentTraverser, InlineElement, NodePosition } from 'roosterjs-editor-types'; /** * The provides traversing of content inside editor. * There are two ways to traverse, block by block, or inline element by inline element * Block and inline traversing is independent from each other, meaning if you traverse block by block, it does not change * the current inline element position */ export default class ContentTraverser implements IContentTraverser { private scoper; private skipTags?; private currentInline; private currentBlock; /** * Create a content traverser for the whole body of given root node * @param scoper Traversing scoper object to help scope the traversing * @param skipTags (Optional) tags that child elements will be skipped */ private constructor(); /** * Create a content traverser for the whole body of given root node * @param rootNode The root node to traverse in * @param startNode The node to start from. If not passed, it will start from the beginning of the body * @param skipTags (Optional) tags that child elements will be skipped */ static createBodyTraverser(rootNode: Node, startNode?: Node, skipTags?: string[]): IContentTraverser; /** * Create a content traverser for the given selection * @param rootNode The root node to traverse in * @param range The selection range to scope the traversing * @param skipTags (Optional) tags that child elements will be skipped */ static createSelectionTraverser(rootNode: Node, range: Range, skipTags?: string[]): IContentTraverser; /** * Create a content traverser for a block element which contains the given position * @param rootNode The root node to traverse in * @param position A position inside a block, traversing will be scoped within this block. * If passing a range, the start position of this range will be used * @param startFrom Start position of traversing. The value can be Begin, End, SelectionStart * @param skipTags (Optional) tags that child elements will be skipped */ static createBlockTraverser(rootNode: Node, position: NodePosition | Range, start?: ContentPosition | CompatibleContentPosition, skipTags?: string[]): IContentTraverser; /** * Get current block */ get currentBlockElement(): BlockElement | null; /** * Get next block element */ getNextBlockElement(): BlockElement | null; /** * Get previous block element */ getPreviousBlockElement(): BlockElement | null; private getPreviousNextBlockElement; /** * Current inline element getter */ get currentInlineElement(): InlineElement | null; /** * Get next inline element */ getNextInlineElement(): InlineElement | null; /** * Get previous inline element */ getPreviousInlineElement(): InlineElement | null; private getPreviousNextInlineElement; }