"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.default = PasteLogPlugin;
const tslib_1 = require("tslib");
const LexicalComposerContext_1 = require("@lexical/react/LexicalComposerContext");
const lexical_1 = require("lexical");
const React = tslib_1.__importStar(require("react"));
const react_1 = require("react");
function PasteLogPlugin() {
    const [editor] = (0, LexicalComposerContext_1.useLexicalComposerContext)();
    const [isActive, setIsActive] = (0, react_1.useState)(false);
    const [lastClipboardData, setLastClipboardData] = (0, react_1.useState)(null);
    (0, react_1.useEffect)(() => {
        if (isActive) {
            return editor.registerCommand(lexical_1.PASTE_COMMAND, (e) => {
                const { clipboardData } = e;
                const allData = [];
                if (clipboardData && clipboardData.types) {
                    clipboardData.types.forEach((type) => {
                        allData.push(type.toUpperCase(), clipboardData.getData(type));
                    });
                }
                setLastClipboardData(allData.join('\n\n'));
                return false;
            }, lexical_1.COMMAND_PRIORITY_NORMAL);
        }
        return () => {
            console.log('clean up');
        };
    }, [editor, isActive]);
    return (React.createElement(React.Fragment, null,
        React.createElement("button", { className: `editor-dev-button ${isActive ? 'active' : ''}`, id: 'paste-log-button', onClick: () => {
                setIsActive(!isActive);
            }, title: isActive ? 'Disable paste log' : 'Enable paste log', type: 'button' }),
        isActive && lastClipboardData !== null ? React.createElement("pre", null, lastClipboardData) : null));
}
//# sourceMappingURL=index.js.map