"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 wrapList_exports = {};
__export(wrapList_exports, {
  wrapList: () => wrapList
});
module.exports = __toCommonJS(wrapList_exports);
var import_slate = require("slate");
var import_controls = require("@makeswift/controls");
var import_element = require("../utils/element");
var import_types = require("../../slate/types");
function wrapList(editor, options = { type: import_types.BlockType.UnorderedList }) {
  const at = options.at ?? editor.selection;
  if (!at)
    return;
  const nonListEntries = Array.from(
    import_slate.Editor.nodes(editor, {
      at,
      match: (node) => {
        return import_slate.Element.isElement(node) && import_controls.Slate.isConvertibleToListTextNode(node);
      }
    })
  );
  const refs = nonListEntries.map(([_, path]) => import_slate.Editor.pathRef(editor, path));
  refs.forEach((ref) => {
    const path = ref.current;
    if (path) {
      import_slate.Editor.withoutNormalizing(editor, () => {
        import_slate.Transforms.setNodes(
          editor,
          { type: import_types.BlockType.ListItemChild },
          {
            at: path
          }
        );
        import_slate.Transforms.wrapNodes(editor, import_element.ElementUtils.createListItem(), {
          match: (node) => import_controls.Slate.isListItemChild(node),
          at: path
        });
        import_slate.Transforms.wrapNodes(editor, import_element.ElementUtils.createList(options.type), {
          at: path
        });
      });
    }
    ref.unref();
  });
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  wrapList
});
//# sourceMappingURL=wrapList.js.map