@atlaskit/editor-plugin-block-controls
Version:
Block controls plugin for @atlaskit/editor-core
38 lines • 2.02 kB
JavaScript
import { bindKeymapWithCommand, dragToMoveDown, dragToMoveLeft, dragToMoveRight, dragToMoveUp, showElementDragHandle } from '@atlaskit/editor-common/keymaps';
import { DIRECTION } from '@atlaskit/editor-common/types';
import { keydownHandler } from '@atlaskit/editor-prosemirror/keymap';
import { moveNodeViaShortcut } from '../editor-commands/move-node';
import { showDragHandleAtSelection } from '../editor-commands/show-drag-handle';
function keymapList(api, formatMessage) {
var keymapList = {};
if (api) {
bindKeymapWithCommand(
// Ignored via go/ees005
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
showElementDragHandle.common, function (state, dispatch, view) {
showDragHandleAtSelection(api)(state, dispatch, view);
//we always want to handle this shortcut to prevent default browser special char insert when option + alphabetical key is used
return true;
}, keymapList);
bindKeymapWithCommand(
// Ignored via go/ees005
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
dragToMoveUp.common, moveNodeViaShortcut(api, DIRECTION.UP, formatMessage), keymapList);
bindKeymapWithCommand(
// Ignored via go/ees005
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
dragToMoveDown.common, moveNodeViaShortcut(api, DIRECTION.DOWN, formatMessage), keymapList);
bindKeymapWithCommand(
// Ignored via go/ees005
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
dragToMoveLeft.common, moveNodeViaShortcut(api, DIRECTION.LEFT, formatMessage), keymapList);
bindKeymapWithCommand(
// Ignored via go/ees005
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
dragToMoveRight.common, moveNodeViaShortcut(api, DIRECTION.RIGHT, formatMessage), keymapList);
}
return keymapList;
}
export var boundKeydownHandler = function boundKeydownHandler(api, formatMessage) {
return keydownHandler(keymapList(api, formatMessage));
};