'use strict';

Object.defineProperty(exports, '__esModule', { value: true });

const index$1 = require('../../../../../../../node_modules/.pnpm/prosemirror-state@1.4.4/node_modules/prosemirror-state/dist/index.cjs');
const index = require('../../../../../../../node_modules/.pnpm/@tiptap_core@3.15.3_@tiptap_pm@3.15.3/node_modules/@tiptap/core/dist/index.cjs');

function looksLikeMarkdown(text) {
  return /^#{1,6}\s/.test(text) || // Headings
  /\*\*[^*]+\*\*/.test(text) || // Bold
  /\*[^*]+\*/.test(text) || // Italic
  /\[.+\]\(.+\)/.test(text) || // Links
  /^[-*+]\s/.test(text) || // Unordered lists
  /^\d+\.\s/.test(text) || // Ordered lists
  /^>\s/.test(text) || // Blockquotes
  /`[^`]+`/.test(text) || // Inline code
  /^```/.test(text);
}
const MarkdownPaste = index.Extension.create({
  name: "markdownPaste",
  addProseMirrorPlugins() {
    const { editor } = this;
    return [
      new index$1.Plugin({
        key: new index$1.PluginKey("markdownPaste"),
        props: {
          handlePaste: (_view, event) => {
            const clipboardData = event.clipboardData;
            if (!clipboardData) return false;
            const html = clipboardData.getData("text/html");
            if (html) {
              return false;
            }
            const text = clipboardData.getData("text/plain");
            if (!text) return false;
            if (!editor.markdown) {
              return false;
            }
            if (!looksLikeMarkdown(text)) {
              return false;
            }
            try {
              editor.commands.insertContent(text, { contentType: "markdown" });
              event.preventDefault();
              return true;
            } catch (err) {
              return false;
            }
          }
        }
      })
    ];
  }
});

exports.MarkdownPaste = MarkdownPaste;
exports.default = MarkdownPaste;
