"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.isWrappingPossible = exports.getListLiftTarget = void 0;

var _prosemirrorTransform = require("prosemirror-transform");

var _node = require("./utils/node");

var isWrappingPossible = function isWrappingPossible(nodeType, state) {
  var _state$selection = state.selection,
      $from = _state$selection.$from,
      $to = _state$selection.$to;
  var range = $from.blockRange($to);

  if (!range) {
    return false;
  }

  var wrap = (0, _prosemirrorTransform.findWrapping)(range, nodeType);

  if (!wrap) {
    return false;
  }

  return true;
}; // This will return (depth - 1) for root list parent of a list.


exports.isWrappingPossible = isWrappingPossible;

var getListLiftTarget = function getListLiftTarget(resPos) {
  var target = resPos.depth;

  for (var i = resPos.depth; i > 0; i--) {
    var node = resPos.node(i);

    if ((0, _node.isListNode)(node)) {
      target = i;
    }

    if (!(0, _node.isListItemNode)(node) && !(0, _node.isListNode)(node)) {
      break;
    }
  }

  return target - 1;
};

exports.getListLiftTarget = getListLiftTarget;