UNPKG

@atlaskit/editor-plugin-block-menu

Version:

BlockMenu plugin for @atlaskit/editor-core

38 lines (36 loc) 1.69 kB
import { SafePlugin } from '@atlaskit/editor-common/safe-plugin'; import { PluginKey } from '@atlaskit/editor-prosemirror/state'; import { shouldSuppressKeyboardEvent } from './utils/shouldSuppressKeyboardEvent'; export var blockMenuPluginKey = new PluginKey('blockMenuPlugin'); export var createPlugin = function createPlugin(api) { return new SafePlugin({ key: blockMenuPluginKey, state: { init: function init() { return { showFlag: false }; }, apply: function apply(tr, currentPluginState) { var _meta$showFlag; var 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: function handleKeyDown(_editorView, event) { var _api$userIntent; var blockMenuOpen = (api === null || api === void 0 || (_api$userIntent = api.userIntent) === null || _api$userIntent === void 0 || (_api$userIntent = _api$userIntent.sharedState.currentState()) === null || _api$userIntent === void 0 ? void 0 : _api$userIntent.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); } } }); };