@atlaskit/editor-plugin-block-menu
Version:
BlockMenu plugin for @atlaskit/editor-core
44 lines (41 loc) • 1.92 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.createPlugin = exports.blockMenuPluginKey = void 0;
var _safePlugin = require("@atlaskit/editor-common/safe-plugin");
var _state = require("@atlaskit/editor-prosemirror/state");
var _shouldSuppressKeyboardEvent = require("./utils/shouldSuppressKeyboardEvent");
var blockMenuPluginKey = exports.blockMenuPluginKey = new _state.PluginKey('blockMenuPlugin');
var createPlugin = exports.createPlugin = function createPlugin(api) {
return new _safePlugin.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 (0, _shouldSuppressKeyboardEvent.shouldSuppressKeyboardEvent)(event);
}
}
});
};