"use strict";
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
const Slate = require("slate");
const index = require("../../../ContemberEditor/index.cjs");
const ParagraphRenderer = require("./ParagraphRenderer.cjs");
const paragraphElementType = "paragraph";
const isParagraphElement = (element, suchThat) => index.ContemberEditor.isElementType(element, paragraphElementType, suchThat);
const paragraphElementPlugin = {
  type: paragraphElementType,
  render: ParagraphRenderer.ParagraphRenderer,
  canContainAnyBlocks: false,
  acceptsAttributes: ({ editor, suchThat }) => {
    return "align" in suchThat;
  },
  toggleElement: ({ editor, suchThat }) => {
    Slate.Editor.withoutNormalizing(editor, () => {
      const topLevelNodes = Array.from(index.ContemberEditor.topLevelNodes(editor));
      if (topLevelNodes.every(([node]) => isParagraphElement(node, suchThat))) {
        for (const [, path] of topLevelNodes) {
          index.ContemberEditor.ejectElement(editor, path);
          Slate.Transforms.setNodes(editor, { type: editor.defaultElementType }, { at: path });
        }
      } else {
        for (const [node, path] of topLevelNodes) {
          if (isParagraphElement(node, suchThat)) {
            continue;
          }
          index.ContemberEditor.ejectElement(editor, path);
          const newProps = {
            ...suchThat,
            type: paragraphElementType
          };
          Slate.Transforms.setNodes(editor, newProps, { at: path });
        }
      }
    });
  },
  normalizeNode: ({ editor, element, path, preventDefault }) => {
    for (const [i, child] of element.children.entries()) {
      if (Slate.Editor.isBlock(editor, child)) {
        Slate.Transforms.unwrapNodes(editor, { at: [...path, i] });
        return preventDefault();
      }
    }
  }
};
exports.isParagraphElement = isParagraphElement;
exports.paragraphElementPlugin = paragraphElementPlugin;
exports.paragraphElementType = paragraphElementType;
//# sourceMappingURL=ParagraphElement.cjs.map
