import { Plugin } from 'prosemirror-state';
import { DataTransferType } from "../../../behavior/Clipboard/utils.js";
import { imageType } from "../ImageSpecs/index.js";
export const imageUrlPaste = (builder, opts) => {
    builder.addPlugin(() => new 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(DataTransferType.Text) ?? '') || {};
                    if (!imageUrl) {
                        return false;
                    }
                    e.preventDefault();
                    const imageNode = 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);
};
//# sourceMappingURL=index.js.map
