@atlaskit/editor-common
Version:
A package that contains common classes and components for editor and renderer
41 lines • 1.41 kB
JavaScript
import { editorCommandToPMCommand } from './editor-commands';
/**
* Core plugin that is always included in the preset.
* Allows for executing `EditorCommand` and other core functionality.
*/
export var corePlugin = function corePlugin(_ref) {
var config = _ref.config;
return {
name: 'core',
actions: {
execute: function execute(command) {
var editorView = config === null || config === void 0 ? void 0 : config.getEditorView();
if (!editorView || !command) {
return false;
}
var state = editorView.state,
dispatch = editorView.dispatch;
return editorCommandToPMCommand(command)(state, dispatch);
},
// Code copied from `EditorActions.focus()`
focus: function focus() {
var editorView = config === null || config === void 0 ? void 0 : config.getEditorView();
if (!editorView || editorView.hasFocus()) {
return false;
}
editorView.focus();
editorView.dispatch(editorView.state.tr.scrollIntoView());
return true;
},
// Code copied from `EditorActions.blur()`
blur: function blur() {
var editorView = config === null || config === void 0 ? void 0 : config.getEditorView();
if (!editorView || !editorView.hasFocus()) {
return false;
}
editorView.dom.blur();
return true;
}
}
};
};