import { Node_Type } from "./../ricos-types/index.js";
import { findParentNodeClosestToPos } from "./../tiptap/index.js";
import { liftTarget } from "./../tiptap/pm/transform.js";
const liftEmptyOrderedListItem = (state, dispatch) => {
  if (!dispatch) {
    console.error("dispatch is not defined");
    return false;
  }
  const isOrderedList = findParentNodeClosestToPos(
    state.selection.$from,
    (node) => node.type.name === Node_Type.ORDERED_LIST
  );
  if (!isOrderedList) {
    return false;
  }
  const { $cursor } = state.selection;
  if (!$cursor || $cursor.parent.content.size) {
    return false;
  }
  const range = $cursor?.blockRange();
  if (!range || range.parent.type.name !== Node_Type.LIST_ITEM) {
    return false;
  }
  const target = liftTarget(range);
  if (target === null) {
    return false;
  }
  const tr = state.tr;
  tr.lift(range, target).scrollIntoView();
  const nextNodePos = tr.selection.$from.blockRange()?.end;
  if (!nextNodePos) {
    dispatch(tr);
    return true;
  }
  const nextNode = tr.doc.nodeSize > nextNodePos && tr.doc.nodeAt(nextNodePos);
  if (!nextNode || nextNode && nextNode.type.name !== Node_Type.ORDERED_LIST) {
    dispatch(tr);
    return true;
  }
  tr.setNodeAttribute(nextNodePos, "start", 1);
  dispatch(tr);
  return true;
};
export {
  liftEmptyOrderedListItem
};
//# sourceMappingURL=lift-empty-ordered-list-item.js.map
