Split SubmitPlugin out of StatePlugin

This commit is contained in:
Alex Gleason
2023-10-13 15:16:00 -05:00
parent 8edd1a830d
commit 8f55b6d5c2
3 changed files with 33 additions and 16 deletions

View File

@ -0,0 +1,28 @@
import { useLexicalComposerContext } from '@lexical/react/LexicalComposerContext';
import { KEY_ENTER_COMMAND } from 'lexical';
import { useEffect } from 'react';
interface ISubmitPlugin {
composeId: string;
handleSubmit?: () => void;
}
const SubmitPlugin: React.FC<ISubmitPlugin> = ({ composeId, handleSubmit }) => {
const [editor] = useLexicalComposerContext();
useEffect(() => {
if (handleSubmit) {
return editor.registerCommand(KEY_ENTER_COMMAND, (event) => {
if (event?.ctrlKey) {
handleSubmit();
return true;
}
return false;
}, 1);
}
}, [handleSubmit]);
return null;
};
export default SubmitPlugin;