UNPKG

phx-react

Version:

PHX REACT

33 lines 1.6 kB
import { useLexicalComposerContext } from '@lexical/react/LexicalComposerContext'; import { COMMAND_PRIORITY_NORMAL, PASTE_COMMAND } from 'lexical'; import * as React from 'react'; import { useEffect, useState } from 'react'; export default function PasteLogPlugin() { const [editor] = useLexicalComposerContext(); const [isActive, setIsActive] = useState(false); const [lastClipboardData, setLastClipboardData] = useState(null); useEffect(() => { if (isActive) { return editor.registerCommand(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; }, 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