import type { KeyMap } from 'react-hotkeys'; import type { Decoration_Type, Node_Type } from 'ricos-schema'; import type { TFunction } from './commonTypes'; import type { Platform } from './context'; import type { EditorCommands } from './editorCommandsType'; import type { BasicKeyCombination, ValidKeyCombination } from './key-types'; import type { IKeys } from './keys'; import type { ModalService } from './modalTypes'; import type { TiptapEditor } from './tiptap'; export type LocalizedDisplayData = { name: KeyboardShortcut['name']; description: KeyboardShortcut['description']; keyCombinationText: string; tooltipHint: string; group: KeyboardShortcut['group']; }; type KeyboardShortcutId = 'AddHorizontalTabulation' | 'Enter' | 'NewLine' | 'SoftNewLine' | 'SoftNewLineMeta' | 'SoftNewLineShift' | 'MoveToNextCellTab' | 'MoveToNextCellArrow' | 'MoveToPreviousCellTab' | 'MoveToPreviousCellArrow' | 'EnterExitCell' | 'AddNewLineShift' | 'AddNewLineAlt' | 'DropLineInList' | 'SelectContentInCell' | 'SelectColumn' | 'SelectRow' | 'SelectTable' | 'AddNewColumnRow' | 'DeleteColumnRow' | 'ExitToolbar' | 'EnterToolbar' | 'ApplySelection' | 'MoveSelectionToNextOption' | 'MoveSelectionToPreviousOption' | 'SelectNextBlock' | 'SelectPrevBlock' | 'MoveSelectionThroughElements' | 'OpenBlocksMenu' | 'SelectAll' | 'SelectTextBlocks' | 'ClearSelection' | 'MoveSelectedBlockUp' | 'MoveSelectedBlockDown' | 'OpenBlocksMenu' | 'OpenShortcutsSheet' | 'SelectNextBlockWithTab' | 'SelectNextBlockArrows' | 'ApplySelection' | 'ExitBlocksMenu' | 'MoveToNextElementTab' | 'MoveToNextElementEnter' | 'SelectEntireList' | 'TextAlignment.LEFT' | 'TextAlignment.CENTER' | 'TextAlignment.RIGHT' | 'TextAlignment.JUSTIFY' | 'UNDO' | 'REDO' | 'INDENT.increase' | 'INDENT.decrease' | 'PasteWithoutFormatting' | keyof typeof Node_Type | keyof typeof Decoration_Type | `${Decoration_Type.FONT_SIZE}.increase` | `${Decoration_Type.FONT_SIZE}.decrease` | `${Node_Type.HEADING}.${1 | 2 | 3 | 4 | 5 | 6}` | 'Empty' | 'OpenAiModal'; /** * Customizable keyboard shortcut for Return API, currently limited to `Enter`-related shortcuts. * Allows to remap `new line` / `soft new line` editor functionalities to `Enter`-based combination, or to remap `Enter` key to custom action. * * Examples: * ```ts * { * name: 'NewLine', * description: 'Remap new line editor functionality to Shift+Enter', * keys: { macOs: 'Shift+Enter', windows: 'Shift+Enter' }, * command: editorCommands => editorCommands.newLine() * }, { * name: 'Enter', * description: 'Remap Enter key to custom action', * keys: { macOs: 'Enter', windows: 'Enter' }, * command: () => submitForm(); // user defined action * }, { * name: 'SoftNewLine', * description: 'Remap new line editor functionality to Ctrl+Enter', * keys: { macOs: 'Meta+Enter', windows: 'Ctrl+Enter' }, * command: editorCommands => editorCommands.softNewLine() * } * ``` */ export type CustomizableKeyboardShortcut = { /** * `Enter`-related shortcut name * */ name: 'NewLine' | 'SoftNewLine' | 'Enter'; /** * Free text description, displayed in Shortcuts Sheet help dialog * */ description: string; /** * Platform-dependent key combination * */ keys: { macOs: 'Shift+Enter' | 'Enter' | 'Meta+Enter' | 'Ctrl+Enter'; windows: 'Shift+Enter' | 'Enter' | 'Meta+Enter' | 'Ctrl+Enter'; }; /** * Command triggered by shortcut * */ command: KeyboardShortcut['command']; enabled: KeyboardShortcut['enabled']; group: 'ShortcutsSheet_Section_Formatting'; }; /** * Keyboard shortcut configuration * * @export * @interface KeyboardShortcut */ export type KeyboardShortcut = { /** * Shortcut identifier, used as localized display data * * @type {string} * @memberof KeyboardShortcut */ name: KeyboardShortcutId; /** * Shortcut description, used as localized display data * * @type {string} * @memberof KeyboardShortcut */ description: string; /** * Shortcut group (context), used both as grouping key and localized display data * * @type {string} * @memberof KeyboardShortcut */ group: string; /** * The shortcut keys like Control+B * Limited up to 2 modifiers and single Latin/number/some special character key * * The key names based on standard Web KeyboardEvent.key values: * https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/key/Key_Values * * @type {BasicKeyCombination} * @memberof KeyboardShortcut */ keys: { macOs: BasicKeyCombination; windows: BasicKeyCombination; }; /** * Command for execution * * @memberof KeyboardShortcut */ command: (args: { editorCommands: EditorCommands; editor: TiptapEditor; modalService: ModalService; event: KeyboardEvent; }) => void; /** * Enables shortcut * * @type {boolean} * @memberof KeyboardShortcut */ enabled: boolean; }; export type ValidatedShortcut = Omit & { keys: { macOs: ValidKeyCombination; windows: ValidKeyCombination; }; }; /** * Type checker for KeyboardShortcut * * @param {ValidatedShortcut} shortcut * @returns {KeyboardShortcut} shortcut */ export declare const createShortcut: (shortcut: ValidatedShortcut) => KeyboardShortcut; export interface ShortcutRegistrar { /** * Registers shortcut, validates it has no conflicts. * * @memberof ShortcutRegistrar */ register: (shortcut: KeyboardShortcut) => void; /** * Registers shortcut, override in case of a conflicts. * * @memberof ShortcutRegistrar */ mergeKeyboadShortcutProp: (shortcut: CustomizableKeyboardShortcut) => void; /** * Unregisters shortcut * * @memberof ShortcutRegistrar */ unregister: (shortcut: KeyboardShortcut) => void; } export interface ShortcutDataProvider { /** * Provides shortcut display data by given shortcut name for current locale and platform * * @param {KeyboardShortcut['name']} name * @param {TFunction} t * @param {Platform} platform * @returns {LocalizedDisplayData} * @memberof ShortcutDataProvider */ getShortcutDisplayData(name: KeyboardShortcut['name'], t: TFunction, platform: Platform): LocalizedDisplayData; getDisplayData(t: TFunction, platform: Platform): { [group: string]: LocalizedDisplayData[]; }; } export type HotKeysProps = { keyMap: KeyMap; handlers: { [name: string]: (e: KeyboardEvent) => void; }; allowChanges: boolean; }; /** * Represents a keyboard shortcut in Ricos Editor. * Admits key combination, command, relevant context, display data. * * @export * @interface Shortcut */ export interface Shortcut { /** * Parsed Keys * * @returns {Keys} * @memberof Shortcut */ getKeys(platform: Platform): IKeys; /** * Command to run * * @returns {KeyboardShortcut['command']} * @memberof Shortcut */ getCommand(): KeyboardShortcut['command']; /** * Pre-localized name * * @returns {KeyboardShortcut['name']} * @memberof Shortcut */ getName(): KeyboardShortcut['name']; /** * Pre-localized group * * @returns {KeyboardShortcut['group']} * @memberof Shortcut */ getGroup(): KeyboardShortcut['group']; /** * Localized shortcut data for tooltips, help dialogs, etc * * @param {TFunction} t * @returns {LocalizedDisplayData} * @memberof Shortcut */ getDisplayData(t: TFunction, platform: Platform): LocalizedDisplayData; /** * Enabled status * * @returns {KeyboardShortcut['enabled']} * @memberof Shortcut */ isEnabled(): KeyboardShortcut['enabled']; /** * KeyboardShortcut config * * @memberof Shortcut */ getKeyboardShortcut: () => KeyboardShortcut; /** * Reconfigure Shortcut * * @param {KeyboardShortcut} config * @returns {Shortcut} * @memberof Shortcut */ configure(config: Partial): Shortcut; /** * Determines whether shortcut equals to another shortcut, based on keys and group * * @param {Shortcut} shortcut * @returns {boolean} * @memberof Shortcut */ equals(shortcut: Shortcut): boolean; } /** * Aggregate over Shortcut entity. * Responsible for shortcut validation. * Conforms to `react-hotkeys` lib API. * * @export * @interface Shortcuts */ export interface Shortcuts extends ShortcutRegistrar, ShortcutDataProvider { isDebugMode: boolean; /** * Filters shortcuts according to predicate * * @memberof Shortcuts */ filter: (predicate: (shortcut: Shortcut) => boolean) => Shortcuts; /** * Gets shortcut array * * @memberof Shortcuts */ asArray: () => Shortcut[]; /** * Builds a map of shortcut display data, grouped by shortcut groups * * @memberof Shortcuts */ getDisplayData: (t: TFunction, platform: Platform) => { [group: string]: LocalizedDisplayData[]; }; /** * Constructs `react-hotkeys` compatible data for given group * * @memberof Shortcuts */ getHotKeysProps: (args: { group: string; editorCommands: EditorCommands; editor: TiptapEditor; t: TFunction; platform: Platform; }) => HotKeysProps; } export {}; //# sourceMappingURL=shortcuts.d.ts.map