/** * @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved. * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license */ /** * @module list/documentlist/utils/listwalker */ import { type ArrayOrItem } from 'ckeditor5/src/utils'; import { type ListElement } from './model'; import type { Element, Node } from 'ckeditor5/src/engine'; /** * Document list blocks iterator. */ export default class ListWalker { /** * The start list item block element. */ private _startElement; /** * The reference indent. Initialized by the indent of the start block. */ private _referenceIndent; /** * The iterating direction. */ private _isForward; /** * Whether start block should be included in the result (if it's matching other criteria). */ private _includeSelf; /** * Additional attributes that must be the same for each block. */ private _sameAttributes; /** * Whether blocks with the same indent level as the start block should be included in the result. */ private _sameIndent; /** * Whether blocks with a lower indent level than the start block should be included in the result. */ private _lowerIndent; /** * Whether blocks with a higher indent level than the start block should be included in the result. */ private _higherIndent; /** * Creates a document list iterator. * * @param startElement The start list item block element. * @param options.direction The iterating direction. * @param options.includeSelf Whether start block should be included in the result (if it's matching other criteria). * @param options.sameAttributes Additional attributes that must be the same for each block. * @param options.sameIndent Whether blocks with the same indent level as the start block should be included * in the result. * @param options.lowerIndent Whether blocks with a lower indent level than the start block should be included * in the result. * @param options.higherIndent Whether blocks with a higher indent level than the start block should be included * in the result. */ constructor(startElement: Node, options: { direction?: 'forward' | 'backward'; includeSelf?: boolean; sameAttributes?: ArrayOrItem; sameIndent?: boolean; lowerIndent?: boolean; higherIndent?: boolean; }); /** * Performs only first step of iteration and returns the result. * * @param startElement The start list item block element. * @param options.direction The iterating direction. * @param options.includeSelf Whether start block should be included in the result (if it's matching other criteria). * @param options.sameAttributes Additional attributes that must be the same for each block. * @param options.sameIndent Whether blocks with the same indent level as the start block should be included * in the result. * @param options.lowerIndent Whether blocks with a lower indent level than the start block should be included * in the result. * @param options.higherIndent Whether blocks with a higher indent level than the start block should be included * in the result. */ static first(startElement: Node, options: { direction?: 'forward' | 'backward'; includeSelf?: boolean; sameAttributes?: ArrayOrItem; sameIndent?: boolean; lowerIndent?: boolean; higherIndent?: boolean; }): ListElement | null; /** * Iterable interface. */ [Symbol.iterator](): Iterator; /** * Returns the model element to start iterating. */ private _getStartNode; } /** * Iterates sibling list blocks starting from the given node. * * @internal * @param node The model node. * @param direction Iteration direction. * @returns The object with `node` and `previous` {@link module:engine/model/element~Element blocks}. */ export declare function iterateSiblingListBlocks(node: Node | null, direction?: 'forward' | 'backward'): IterableIterator; /** * The iterable protocol over the list elements. * * @internal */ export declare class ListBlocksIterable { private _listHead; /** * @param listHead The head element of a list. */ constructor(listHead: Element); /** * List blocks iterator. * * Iterates over all blocks of a list. */ [Symbol.iterator](): Iterator; } /** * Object returned by `iterateSiblingListBlocks()` when traversing a list. * * @internal */ export interface ListIteratorValue { /** * The current list node. */ node: ListElement; /** * The previous list node. */ previous: ListElement | null; }