"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 toggleList_exports = {};
__export(toggleList_exports, {
  toggleList: () => toggleList
});
module.exports = __toCommonJS(toggleList_exports);
var import_slate = require("slate");
var import_controls = require("@makeswift/controls");
var import_unwrapList = require("./unwrapList");
var import_location = require("./utils/location");
var import_wrapList = require("./wrapList");
var import_types = require("../types");
function toggleList(editor, options = { type: import_types.BlockType.UnorderedList }) {
  const at = options.at ?? editor.selection;
  if (at == null)
    return;
  const start = import_location.LocationUtils.getStartPath(at);
  const ancestorPath = import_slate.Path.ancestors(start).at(1);
  if (!ancestorPath || !import_slate.Node.has(editor, ancestorPath))
    return;
  const ancestor = import_slate.Node.get(editor, ancestorPath);
  if (!import_controls.Slate.isList(ancestor)) {
    return (0, import_wrapList.wrapList)(editor, { type: options.type, at });
  }
  if (ancestor.type === options.type) {
    (0, import_unwrapList.unwrapList)(editor, { at });
  } else {
    import_slate.Transforms.setNodes(editor, { type: options.type }, { at: ancestorPath });
  }
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  toggleList
});
//# sourceMappingURL=toggleList.js.map