"use strict";
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
  for (var name in all)
    __defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
  if (from && typeof from === "object" || typeof from === "function") {
    for (let key of __getOwnPropNames(from))
      if (!__hasOwnProp.call(to, key) && key !== except)
        __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  }
  return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var lift_empty_ordered_list_item_exports = {};
__export(lift_empty_ordered_list_item_exports, {
  liftEmptyOrderedListItem: () => liftEmptyOrderedListItem
});
module.exports = __toCommonJS(lift_empty_ordered_list_item_exports);
var import_ricos_types = require("./../ricos-types/index.js");
var import_tiptap = require("./../tiptap/index.js");
var import_transform = require("./../tiptap/pm/transform.js");
const liftEmptyOrderedListItem = (state, dispatch) => {
  if (!dispatch) {
    console.error("dispatch is not defined");
    return false;
  }
  const isOrderedList = (0, import_tiptap.findParentNodeClosestToPos)(
    state.selection.$from,
    (node) => node.type.name === import_ricos_types.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 !== import_ricos_types.Node_Type.LIST_ITEM) {
    return false;
  }
  const target = (0, import_transform.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 !== import_ricos_types.Node_Type.ORDERED_LIST) {
    dispatch(tr);
    return true;
  }
  tr.setNodeAttribute(nextNodePos, "start", 1);
  dispatch(tr);
  return true;
};
//# sourceMappingURL=lift-empty-ordered-list-item.js.map
