"use strict";
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
const Slate = require("slate");
const AnchorModifications = require("./AnchorModifications.cjs");
const AnchorRenderer = require("./AnchorRenderer.cjs");
const anchorElementType = "anchor";
const isAnchorElement = (element) => Slate.Element.isElement(element) && element.type === anchorElementType;
const isAnchorElementActive = (editor) => {
  const [link] = Slate.Editor.nodes(editor, { match: isAnchorElement });
  return !!link;
};
const anchorElementPlugin = {
  type: anchorElementType,
  isInline: true,
  render: AnchorRenderer.AnchorRenderer,
  isActive: ({ editor }) => isAnchorElementActive(editor),
  toggleElement: ({ editor, suchThat }) => {
    if (isAnchorElementActive(editor)) {
      AnchorModifications.AnchorModifications.unwrapAnchor(editor);
    } else {
      const href = suchThat?.href ?? prompt("Insert the URL:");
      if (!href) {
        return;
      }
      AnchorModifications.AnchorModifications.wrapAnchor(editor, href);
    }
  },
  normalizeNode: ({ element, path, editor, preventDefault }) => {
    if (Slate.Node.string(element) === "") {
      const selection = editor.selection;
      Slate.Transforms.removeNodes(editor, {
        at: path
      });
      if (selection && Slate.Range.isCollapsed(selection) && Slate.Path.isCommon(path, selection.focus.path)) {
        Slate.Transforms.select(editor, Slate.Path.parent(path));
      }
      return preventDefault();
    }
  }
};
exports.anchorElementPlugin = anchorElementPlugin;
exports.anchorElementType = anchorElementType;
exports.isAnchorElement = isAnchorElement;
exports.isAnchorElementActive = isAnchorElementActive;
//# sourceMappingURL=AnchorElement.cjs.map
