/*
 * Returns the (absolute) position directly after the top parent node of a given `nodeType` in the current position.
 *
 * ```typescript
 * const nestingLevel = getEndTopParentNodeOfType(schema.nodes.table)(position);
 * ```
 */
export var getPositionAfterTopParentNodeOfType = function getPositionAfterTopParentNodeOfType(nodeType) {
  return function ($pos) {
    // Loop through parent nodes from top to bottom
    for (var depth = 1; depth <= $pos.depth; depth++) {
      var node = $pos.node(depth);
      // Count the table nodes
      if (node.type === nodeType) {
        return $pos.after(depth);
      }
    }
  };
};