"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.normalizeNestedList = void 0;
var _slate = require("slate");
var _core = require("../../../core");
var _elementTypes = require("../../../constants/element-types");
const normalizeNestedList = function (editor) {
  let {
    nestedListItem
  } = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  const [, path] = nestedListItem;
  const parentNodeEntry = _slate.Editor.parent(editor, path);
  const hasParentList = parentNodeEntry && (0, _core.match)(parentNodeEntry[0], [], {
    type: [_elementTypes.ORDERED_LIST, _elementTypes.UNORDERED_LIST]
  });
  if (!hasParentList) return false;
  let previousListItemPath = null;
  try {
    previousListItemPath = _slate.Path.previous(path);
  } catch (e) {
    return false;
  }
  const previousSiblingItem = _slate.Editor.node(editor, previousListItemPath);
  if (previousSiblingItem) {
    const [, previousPath] = previousSiblingItem;
    const newPath = previousPath.concat([1]);
    _slate.Transforms.moveNodes(editor, {
      at: path,
      to: newPath
    });
    return true;
  }
  return false;
};
exports.normalizeNestedList = normalizeNestedList;