@atlaskit/editor-plugin-text-formatting
Version:
Text-formatting plugin for @atlaskit/editor-core
26 lines • 830 B
JavaScript
import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
import { PluginKey } from '@atlaskit/editor-prosemirror/state';
import { checkFormattingIsPresent } from '../editor-commands/utils';
export const pluginKey = new PluginKey('clearFormattingPlugin');
export const plugin = dispatch => new SafePlugin({
state: {
init(_config, state) {
return {
formattingIsPresent: checkFormattingIsPresent(state)
};
},
apply(_tr, pluginState, _oldState, newState) {
const formattingIsPresent = checkFormattingIsPresent(newState);
if (formattingIsPresent !== pluginState.formattingIsPresent) {
dispatch(pluginKey, {
formattingIsPresent
});
return {
formattingIsPresent
};
}
return pluginState;
}
},
key: pluginKey
});