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