import { find } from "linkifyjs";
import { Plugin, PluginKey } from "./../../../tiptap/pm/state.js";
function pasteHandler(options) {
  return new Plugin({
    key: new PluginKey("handlePasteLink"),
    props: {
      handlePaste: (view, event, slice) => {
        const { state } = view;
        const { selection } = state;
        const { empty } = selection;
        if (empty) {
          return false;
        }
        let textContent = "";
        slice.content.forEach((node) => {
          textContent += node.textContent;
        });
        const link = find(textContent).find((item) => item.isLink && item.value === textContent);
        if (!textContent || !link) {
          return false;
        }
        const ricosLink = options.defaultLink.setUrl(link.href);
        options.editor.commands.setMark(options.type, {
          link: ricosLink.toLink()
        });
        return true;
      }
    }
  });
}
export {
  pasteHandler
};
//# sourceMappingURL=paste-handler.js.map
