import { Transforms, Range } from "slate";
import { isAnchorElement, isAnchorElementActive } from "./AnchorElement.js";
class AnchorModifications {
  static unwrapAnchor(editor) {
    Transforms.unwrapNodes(editor, { match: isAnchorElement });
  }
  static wrapAnchor(editor, url) {
    if (isAnchorElementActive(editor)) {
      AnchorModifications.unwrapAnchor(editor);
    }
    const selection = editor.selection;
    const isCollapsed = selection ? Range.isCollapsed(selection) : false;
    const anchor = {
      type: "anchor",
      href: url,
      children: isCollapsed ? [{ text: url }] : [{ text: "" }]
    };
    if (isCollapsed) {
      Transforms.insertNodes(editor, anchor);
    } else {
      Transforms.wrapNodes(editor, anchor, { split: true });
      Transforms.collapse(editor, { edge: "end" });
    }
  }
}
export { AnchorModifications };
//# sourceMappingURL=AnchorModifications.js.map
