"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 unwrapList_exports = {};
__export(unwrapList_exports, {
  unwrapList: () => unwrapList,
  unwrapPath: () => unwrapPath
});
module.exports = __toCommonJS(unwrapList_exports);
var import_slate = require("slate");
var import_controls = require("@makeswift/controls");
var import_editor = require("../utils/editor");
var import_constants = require("./constants");
var import_filterForSubtreeRoots = require("./utils/filterForSubtreeRoots");
function unwrapPath(editor, listItemPath) {
  const parentList = import_editor.EditorUtils.getFirstAncestorList(editor, listItemPath);
  const listItemContainingParentList = import_editor.EditorUtils.getFirstAncestorListItem(editor, listItemPath);
  if (!parentList || listItemContainingParentList)
    return;
  import_slate.Editor.withoutNormalizing(editor, () => {
    const listItemTextPath = [...listItemPath, import_constants.LIST_ITEM_CHILD_POSITION];
    const listItemNestedListPath = [...listItemPath, import_constants.LIST_ITEM_LIST_POSITION];
    if (import_slate.Node.has(editor, listItemNestedListPath)) {
      import_slate.Transforms.setNodes(editor, { type: parentList[0].type }, { at: listItemNestedListPath });
      import_slate.Transforms.liftNodes(editor, { at: listItemNestedListPath });
      import_slate.Transforms.liftNodes(editor, { at: import_slate.Path.next(listItemPath) });
    }
    if (import_slate.Node.has(editor, listItemTextPath)) {
      import_slate.Transforms.setNodes(
        editor,
        { type: import_controls.Slate.BlockType.Paragraph },
        {
          at: listItemTextPath
        }
      );
      import_slate.Transforms.liftNodes(editor, { at: listItemTextPath });
      import_slate.Transforms.liftNodes(editor, { at: listItemPath });
    }
  });
}
function unwrapList(editor, options) {
  const at = options?.at ?? editor.selection;
  if (!at)
    return;
  const listItems = Array.from(
    import_slate.Editor.nodes(editor, {
      at,
      match: (node) => {
        return import_slate.Element.isElement(node) && import_controls.Slate.isListItem(node);
      }
    })
  );
  const subRoots = (0, import_filterForSubtreeRoots.filterForSubtreeRoots)(listItems);
  const refs = subRoots.map(([_, path]) => import_slate.Editor.pathRef(editor, path));
  refs.forEach((ref) => {
    if (ref.current) {
      unwrapPath(editor, ref.current);
    }
    ref.unref();
  });
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  unwrapList,
  unwrapPath
});
//# sourceMappingURL=unwrapList.js.map