mirror of
https://github.com/codex-team/editor.js
synced 2024-06-01 21:42:26 +02:00
Supported toolbox activate key setting in Config.
This commit is contained in:
parent
c9014e670d
commit
184609c5c6
|
@ -7,6 +7,7 @@ import { CriticalError } from './errors/critical';
|
|||
import EventsDispatcher from './utils/events';
|
||||
import Modules from './modules';
|
||||
import { EditorEventMap } from './events';
|
||||
import { keyCodes } from './utils';
|
||||
|
||||
/**
|
||||
* Editor.js core class. Bootstraps modules.
|
||||
|
@ -187,6 +188,11 @@ export default class Core {
|
|||
* Text direction. If not set, uses ltr
|
||||
*/
|
||||
this.config.i18n.direction = this.config.i18n?.direction || 'ltr';
|
||||
|
||||
/**
|
||||
* KeyCode for activate toolbox. If not set, uses TAB key
|
||||
*/
|
||||
this.config.toolboxKeyCode = this.config.toolboxKeyCode || keyCodes.TAB;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -49,7 +49,7 @@ export default class BlockEvents extends Module {
|
|||
this.arrowLeftAndUp(event);
|
||||
break;
|
||||
|
||||
case _.keyCodes.TAB:
|
||||
case this.config.toolboxKeyCode:
|
||||
this.tabPressed(event);
|
||||
break;
|
||||
}
|
||||
|
@ -135,18 +135,35 @@ export default class BlockEvents extends Module {
|
|||
const canOpenToolbox = currentBlock.tool.isDefault && isEmptyBlock;
|
||||
const conversionToolbarOpened = !isEmptyBlock && ConversionToolbar.opened;
|
||||
const inlineToolbarOpened = !isEmptyBlock && !SelectionUtils.isCollapsed && InlineToolbar.opened;
|
||||
const canOpenBlockTunes = !conversionToolbarOpened && !inlineToolbarOpened;
|
||||
const canOpenBlockTunes = !conversionToolbarOpened && !inlineToolbarOpened && this.isBlockSettingKeyPressed(event);
|
||||
|
||||
/**
|
||||
* For empty Blocks we show Plus button via Toolbox only for default Blocks
|
||||
*/
|
||||
if (canOpenToolbox) {
|
||||
event.stopPropagation();
|
||||
event.preventDefault();
|
||||
this.activateToolbox();
|
||||
} else if (canOpenBlockTunes) {
|
||||
event.stopPropagation();
|
||||
event.preventDefault();
|
||||
this.activateBlockSettings();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether the setting key is pressed
|
||||
*
|
||||
* @param {KeyboardEvent} event keyboard event
|
||||
* @private
|
||||
*/
|
||||
private isBlockSettingKeyPressed(event: KeyboardEvent): boolean {
|
||||
if (this.config.blockSettingModifier === undefined) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return event.getModifierState(this.config.blockSettingModifier);
|
||||
}
|
||||
/**
|
||||
* Add drop target styles
|
||||
*
|
||||
|
|
11
types/configs/editor-config.d.ts
vendored
11
types/configs/editor-config.d.ts
vendored
|
@ -104,4 +104,15 @@ export interface EditorConfig {
|
|||
* Common Block Tunes list. Will be added to all the blocks which do not specify their own 'tunes' set
|
||||
*/
|
||||
tunes?: string[];
|
||||
|
||||
/**
|
||||
* KeyCode for activate toolbox
|
||||
*/
|
||||
toolboxKeyCode?: number;
|
||||
|
||||
/**
|
||||
* Modifier key for activate block setting
|
||||
*/
|
||||
blockSettingModifier?: string;
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue