class TreeNodeQuery {
  constructor(node, parent, originalIndex, converters) {
    this.node = node;
    this.children = [];
    this.parent = parent;
    this.originalIndex = originalIndex;
    this.converter = converters;
  }
  /**
   * It returns an array of all the descendants of the current node that match the predicate
   * @param predicate - (node: ITreeNodeQuery) => boolean
   * @returns An array of ITreeNodeQuery objects that match the predicate.
   */
  descendants(predicate) {
    const descendants = [];
    this.children.forEach((child) => {
      if (predicate(child)) {
        descendants.push(child);
      }
      descendants.push(...child.descendants(predicate));
    });
    return descendants;
  }
  /**
   * The closest() method of the ITreeNodeQuery interface traverses the element and its parents
   *
   * The predicate is a function that takes a node and returns a boolean
   * @param predicate - (node: ITreeNodeQuery) => boolean
   * @returns The closest node that matches the predicate.
   */
  closest(predicate) {
    if (predicate(this)) {
      return this;
    }
    if (this.parent) {
      return this.parent.closest(predicate);
    }
    return null;
  }
  isTextBlock() {
    return this.node.isTextblock;
  }
  isBlock() {
    return this.node.isBlock;
  }
  isText() {
    return this.node.isText;
  }
  type() {
    return this.node.type.name;
  }
  getAttributes() {
    return this.node.attrs;
  }
  /**
   * It converts a Tiptap node to a Prosemirror node
   * @returns A Node object.
   */
  toNode() {
    return this.converter.fromPmNode(this.node.toJSON());
  }
}
export {
  TreeNodeQuery
};
//# sourceMappingURL=tree-node-query.js.map
