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) 801 B
import{useLayoutEffect as e}from"react";import{useLexicalComposerContext as t}from"@lexical/react/LexicalComposerContext";import{KEY_ENTER_COMMAND as r,COMMAND_PRIORITY_LOW as o,KEY_MODIFIER_COMMAND as a,COMMAND_PRIORITY_NORMAL as m}from"lexical";import{useLexicalIsTextContentEmpty as n}from"@lexical/react/useLexicalIsTextContentEmpty";import{TOGGLE_INSERT_LINK_MODAL_COMMAND as c}from"../command/index.js";const i=i=>{const{onSave:s,isDataChanged:l,hasAttachments:p}=i,[f]=t(),x=n(f)&&!p;return e((()=>f.registerCommand(r,(e=>(e&&!e.shiftKey&&(e.preventDefault(),l&&!x&&s?.(f)),!0)),o)),[f,l,x,s]),e((()=>f.registerCommand(a,(e=>{const{code:t,ctrlKey:r,metaKey:o}=e;return"KeyK"===t&&(r||o)&&(e.preventDefault(),f.focus(),f.dispatchCommand(c,"")),!0}),m)),[f,s]),null};export{i as KeyboardPlugin};