@atlaskit/editor-common
Version:
A package that contains common classes and components for editor and renderer
47 lines (46 loc) • 1.55 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.corePlugin = void 0;
var _editorCommands = require("./editor-commands");
/**
* Core plugin that is always included in the preset.
* Allows for executing `EditorCommand` and other core functionality.
*/
var corePlugin = exports.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 (0, _editorCommands.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;
}
}
};
};