"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.ImagePlugin = exports.INSERT_IMAGE_COMMAND = void 0;
const LexicalComposerContext_1 = require("@lexical/react/LexicalComposerContext");
const lexical_1 = require("lexical");
const react_1 = require("react");
const ImageNode_1 = require("../nodes/ImageNode");
const utils_1 = require("@lexical/utils");
exports.INSERT_IMAGE_COMMAND = (0, lexical_1.createCommand)('INSERT_IMAGE_COMMAND');
function ImagePlugin() {
    const [editor] = (0, LexicalComposerContext_1.useLexicalComposerContext)();
    (0, react_1.useEffect)(() => {
        if (!editor.hasNodes([ImageNode_1.ImageNode])) {
            throw new Error('ImagePlugin: ImageNode not registered on editor');
        }
        return editor.registerCommand(exports.INSERT_IMAGE_COMMAND, (payload) => {
            const imageNode = (0, ImageNode_1.$createImageNode)(payload);
            (0, utils_1.$insertNodeToNearestRoot)(imageNode);
            return true;
        }, lexical_1.COMMAND_PRIORITY_EDITOR);
    }, [editor]);
    return null;
}
exports.ImagePlugin = ImagePlugin;
//# sourceMappingURL=ImagePlugin.js.map