"use strict";
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
const Slate = require("slate");
const HorizontalRuleRenderer = require("./HorizontalRuleRenderer.cjs");
const horizontalRuleElementType = "horizontalRule";
const isHorizontalRuleElement = (element) => Slate.Element.isElement(element) && element.type === horizontalRuleElementType;
const isHorizontalRuleElementActive = (editor) => {
  const [hr] = Slate.Editor.nodes(editor, { match: isHorizontalRuleElement });
  return !!hr;
};
const horizontalRuleElementPlugin = {
  type: horizontalRuleElementType,
  render: HorizontalRuleRenderer.HorizontalRuleRenderer,
  isVoid: true,
  toggleElement: ({ editor }) => {
    if (isHorizontalRuleElementActive(editor)) {
      removeHorizontalRule(editor);
    } else {
      insertHorizontalRule(editor);
    }
  }
};
const removeHorizontalRule = (editor) => {
  Slate.Transforms.removeNodes(editor, { match: isHorizontalRuleElement });
};
const insertHorizontalRule = (editor) => {
  const selection = editor.selection;
  const isCollapsed = selection ? Slate.Range.isCollapsed(selection) : false;
  if (!isCollapsed || isHorizontalRuleElementActive(editor)) {
    return;
  }
  const horizontalRule = {
    type: horizontalRuleElementType,
    children: [{ text: "" }]
  };
  Slate.Transforms.insertNodes(editor, horizontalRule);
};
exports.horizontalRuleElementPlugin = horizontalRuleElementPlugin;
exports.horizontalRuleElementType = horizontalRuleElementType;
exports.isHorizontalRuleElement = isHorizontalRuleElement;
exports.isHorizontalRuleElementActive = isHorizontalRuleElementActive;
//# sourceMappingURL=HorizontalRuleElement.cjs.map
