"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.moveChildren = void 0;
var _slate = require("slate");
var _queries = require("../queries");
const moveChildren = (editor, _ref) => {
  let {
    at,
    to,
    match,
    fromStartIndex = 0
  } = _ref;
  let moved = 0;
  const parentPath = _slate.Path.isPath(at) ? at : at[1];
  const parentNode = _slate.Path.isPath(at) ? (0, _queries.getNode)(editor, parentPath) : at[0];
  if (!parentNode) return moved;
  // There have none children in a not block element
  if (!_slate.Editor.isBlock(editor, parentNode)) return moved;
  for (let i = parentNode.children.length - 1; i >= fromStartIndex; i--) {
    const childPath = [...parentPath, i];
    const childNode = (0, _queries.getNode)(editor, childPath);
    if (!match || childNode && match([childNode, childPath])) {
      _slate.Transforms.moveNodes(editor, {
        at: childPath,
        to
      });
      moved++;
    }
  }
  return moved;
};
exports.moveChildren = moveChildren;