import { Editor, Element, Transforms, Text, Node } from "slate";
import { ContemberEditor } from "../../../../ContemberEditor/index.js";
const indentListItem = (editor, listItem, listItemPath) => {
  const previousListEntry = ContemberEditor.getPreviousSibling(
    editor,
    listItem,
    listItemPath
  );
  if (previousListEntry === void 0) {
    return false;
  }
  Editor.withoutNormalizing(editor, () => {
    const [parentListElement] = Editor.parent(editor, listItemPath);
    let [previousListItem, previousListItemPath] = previousListEntry;
    const lastPreviousListItemChild = previousListItem.children[previousListItem.children.length - 1];
    const previousEndsWithCompatibleList = Element.isElement(lastPreviousListItemChild) && ContemberEditor.isElementType(
      lastPreviousListItemChild,
      parentListElement.type,
      ContemberEditor.elementToSpecifics(parentListElement)
    );
    if (previousEndsWithCompatibleList) {
      const newListItemPath = [
        ...previousListItemPath,
        previousListItem.children.length - 1,
        lastPreviousListItemChild.children.length
      ];
      Transforms.moveNodes(editor, {
        at: listItemPath,
        to: newListItemPath
      });
    } else {
      const previousContainsInlines = Editor.hasInlines(editor, previousListItem);
      if (previousContainsInlines) {
        const [previousStart, previousEnd] = Editor.edges(editor, previousListItemPath);
        Transforms.wrapNodes(editor, editor.createDefaultElement([]), {
          match: (node) => Text.isText(node) || Element.isElement(node) && editor.isInline(node),
          at: {
            anchor: previousStart,
            focus: previousEnd
          }
        });
      }
      previousListItem = Node.get(editor, previousListItemPath);
      const newListItemPath = [...previousListItemPath, previousListItem.children.length];
      Transforms.moveNodes(editor, {
        at: listItemPath,
        to: newListItemPath
      });
      Transforms.wrapNodes(editor, { ...parentListElement, children: [] }, { at: newListItemPath });
    }
  });
  return true;
};
export {
  indentListItem
};
//# sourceMappingURL=indentListItem.js.map
