@atlaskit/editor-plugin-block-menu
Version:
BlockMenu plugin for @atlaskit/editor-core
38 lines (36 loc) • 1.69 kB
JavaScript
import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
import { PluginKey } from '@atlaskit/editor-prosemirror/state';
import { shouldSuppressKeyboardEvent } from './utils/shouldSuppressKeyboardEvent';
export const blockMenuPluginKey = new PluginKey('blockMenuPlugin');
export const createPlugin = api => {
return new SafePlugin({
key: blockMenuPluginKey,
state: {
init() {
return {
showFlag: false
};
},
apply: (tr, currentPluginState) => {
var _meta$showFlag;
const meta = tr.getMeta(blockMenuPluginKey);
return {
showFlag: (_meta$showFlag = meta === null || meta === void 0 ? void 0 : meta.showFlag) !== null && _meta$showFlag !== void 0 ? _meta$showFlag : currentPluginState.showFlag
};
}
},
props: {
handleKeyDown: (_editorView, event) => {
var _api$userIntent, _api$userIntent$share;
const blockMenuOpen = (api === null || api === void 0 ? void 0 : (_api$userIntent = api.userIntent) === null || _api$userIntent === void 0 ? void 0 : (_api$userIntent$share = _api$userIntent.sharedState.currentState()) === null || _api$userIntent$share === void 0 ? void 0 : _api$userIntent$share.currentUserIntent) === 'blockMenuOpen';
// Exit early and do nothing when block menu is closed
if (!blockMenuOpen) {
return false;
}
// Block further handling of key events when block menu is open
// Except for backspace/delete/copy/cut/paste/undo/redo/copy-link-to-selection which should be handled by the selection preservation plugin
return shouldSuppressKeyboardEvent(event);
}
}
});
};