contenido
Version:
Contenido is a library with a set of tools to help you create your own rich text editor on top of draft-js without thinking about how to handle things.
27 lines (19 loc) • 700 B
text/typescript
// Custom Utilities
import initialShortcuts from './initial';
// Custom Types
import type { DraftHandleValue } from 'draft-js';
import type { ShortcutMap, State, StateHandler } from '../../types';
const shortcutHandler =
(stateHandler: StateHandler, customShortcutsMap?: ShortcutMap[]) =>
(command: string, state: State): DraftHandleValue => {
let shortcuts = customShortcutsMap || initialShortcuts;
const shortcutIndex = shortcuts.findIndex(
(shortcut) => shortcut.style === command
);
if (shortcutIndex > -1) {
shortcuts[shortcutIndex].handler(state, stateHandler);
return 'handled';
}
return 'not-handled';
};
export default shortcutHandler;