UNPKG

@nexusui/components

Version:

These are custom components specially-developed for NexusUI applications. They will make your life easier by giving you out-of-the-box implementations for various high-level UI elements that you can drop directly into your application.

2 lines (1 loc) 836 B
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react"),t=require("@lexical/react/LexicalComposerContext"),r=require("lexical"),a=require("@lexical/react/useLexicalIsTextContentEmpty"),s=require("../command/index.js");exports.KeyboardPlugin=o=>{const{onSave:n,isDataChanged:c,hasAttachments:u}=o,[i]=t.useLexicalComposerContext(),l=a.useLexicalIsTextContentEmpty(i)&&!u;return e.useLayoutEffect((()=>i.registerCommand(r.KEY_ENTER_COMMAND,(e=>(e&&!e.shiftKey&&(e.preventDefault(),c&&!l&&n?.(i)),!0)),r.COMMAND_PRIORITY_LOW)),[i,c,l,n]),e.useLayoutEffect((()=>i.registerCommand(r.KEY_MODIFIER_COMMAND,(e=>{const{code:t,ctrlKey:r,metaKey:a}=e;return"KeyK"===t&&(r||a)&&(e.preventDefault(),i.focus(),i.dispatchCommand(s.TOGGLE_INSERT_LINK_MODAL_COMMAND,"")),!0}),r.COMMAND_PRIORITY_NORMAL)),[i,n]),null};