"use strict";
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
const Slate = require("slate");
const index = require("../../../ContemberEditor/index.cjs");
const ListItemRenderer = require("./ListItemRenderer.cjs");
const ListElement = require("./ListElement.cjs");
const listItemElementType = "listItem";
const isListItemElement = (element, suchThat) => index.ContemberEditor.isElementType(element, listItemElementType, suchThat);
const listItemElementPlugin = {
  type: listItemElementType,
  render: ListItemRenderer.ListItemRenderer,
  canContainAnyBlocks: true,
  normalizeNode: ({ editor, path, element, preventDefault }) => {
    const parentEntry = Slate.Editor.above(editor, { at: path });
    if (parentEntry === void 0 || !ListElement.isListElement(parentEntry[0])) {
      Slate.Editor.withoutNormalizing(editor, () => {
        const defaultElement = editor.createDefaultElement([{ text: "" }]);
        Slate.Transforms.wrapNodes(editor, defaultElement, {
          at: path
        });
        Slate.Transforms.unwrapNodes(editor, {
          at: [...path, 0]
        });
      });
      return preventDefault();
    }
    if (element.children.every((it) => isListItemElement(it))) {
      Slate.Transforms.unwrapNodes(editor, {
        at: path
      });
      return preventDefault();
    }
    if (element.children.length === 1) {
      const onlyChild = element.children[0];
      if (Slate.Element.isElement(onlyChild) && editor.isDefaultElement(onlyChild)) {
        Slate.Transforms.unwrapNodes(editor, {
          at: [...path, 0]
        });
        return preventDefault();
      }
    }
    const firstChild = element.children[0];
    if (Slate.Element.isElement(firstChild) && ListElement.isListElement(firstChild)) {
      Slate.Transforms.insertNodes(editor, editor.createDefaultElement([{ text: "" }]), {
        at: [...path, 0]
      });
      return preventDefault();
    }
  }
};
exports.isListItemElement = isListItemElement;
exports.listItemElementPlugin = listItemElementPlugin;
exports.listItemElementType = listItemElementType;
//# sourceMappingURL=ListItemElement.cjs.map
