"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.imageUrlPaste = void 0;
const prosemirror_state_1 = require("prosemirror-state");
const utils_1 = require("../../../behavior/Clipboard/utils.js");
const ImageSpecs_1 = require("../ImageSpecs/index.js");
const imageUrlPaste = (builder, opts) => {
    builder.addPlugin(() => new prosemirror_state_1.Plugin({
        props: {
            handleDOMEvents: {
                paste(view, e) {
                    if (!opts.parseInsertedUrlAsImage ||
                        !e.clipboardData ||
                        view.state.selection.$from.parent.type.spec.code)
                        return false;
                    const { imageUrl, title } = opts.parseInsertedUrlAsImage(e.clipboardData.getData(utils_1.DataTransferType.Text) ?? '') || {};
                    if (!imageUrl) {
                        return false;
                    }
                    e.preventDefault();
                    const imageNode = (0, ImageSpecs_1.imageType)(view.state.schema).create({
                        src: imageUrl,
                        alt: title,
                    });
                    const tr = view.state.tr.replaceSelectionWith(imageNode);
                    view.dispatch(tr.scrollIntoView());
                    return true;
                },
            },
        },
    }), builder.Priority.High);
};
exports.imageUrlPaste = imageUrlPaste;
//# sourceMappingURL=index.js.map
