"use strict";
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
const Slate = require("slate");
const index = require("../../../ContemberEditor/index.cjs");
const HeadingRenderer = require("./HeadingRenderer.cjs");
const headingElementType = "heading";
const isHeadingElement = (element, suchThat) => index.ContemberEditor.isElementType(element, headingElementType, suchThat);
const ejectHeadingElement = (editor, elementPath) => {
  index.ContemberEditor.ejectElement(editor, elementPath);
  Slate.Transforms.setNodes(editor, { type: editor.defaultElementType }, { at: elementPath });
};
const headingElementPlugin = {
  type: headingElementType,
  render: HeadingRenderer.HeadingRenderer,
  canContainAnyBlocks: false,
  acceptsAttributes: ({ editor, suchThat }) => {
    return "align" in suchThat;
  },
  // TODO in the following function, we need to conditionally trim the selection so that it doesn't potentially
  // 	include empty strings at the edges of top-level elements.
  toggleElement: ({ editor, suchThat }) => {
    Slate.Editor.withoutNormalizing(editor, () => {
      const headings = Array.from(Slate.Editor.nodes(editor, { match: (it) => isHeadingElement(it, suchThat) }));
      if (headings.length) {
        for (const heading of headings) {
          ejectHeadingElement(editor, heading[1]);
        }
      } else {
        Slate.Transforms.setNodes(editor, {
          ...suchThat,
          children: [],
          type: headingElementType
        });
      }
    });
  }
};
exports.ejectHeadingElement = ejectHeadingElement;
exports.headingElementPlugin = headingElementPlugin;
exports.headingElementType = headingElementType;
exports.isHeadingElement = isHeadingElement;
//# sourceMappingURL=HeadingElement.cjs.map
