UNPKG

@gechiui/block-editor

Version:
35 lines (33 loc) 827 B
/** * GeChiUI dependencies */ import { isKeyboardEvent } from '@gechiui/keycodes'; import { useEffect, useContext, useRef } from '@gechiui/element'; /** * Internal dependencies */ import { keyboardShortcutContext } from './'; export function RichTextShortcut(_ref) { let { character, type, onUse } = _ref; const keyboardShortcuts = useContext(keyboardShortcutContext); const onUseRef = useRef(); onUseRef.current = onUse; useEffect(() => { function callback(event) { if (isKeyboardEvent[type](event, character)) { onUseRef.current(); event.preventDefault(); } } keyboardShortcuts.current.add(callback); return () => { keyboardShortcuts.current.delete(callback); }; }, [character, type]); return null; } //# sourceMappingURL=shortcut.js.map