@atlaskit/editor-plugin-decorations
Version:
Decorations plugin for @atlaskit/editor-core
38 lines (37 loc) • 944 B
JavaScript
import { hoverDecorationCommand, removeDecorationCommand } from './pm-plugins/commands';
import decorationPlugin, { decorationStateKey, hoverDecoration, removeDecoration } from './pm-plugins/main';
/**
* Decorations plugin to be added to an `EditorPresetBuilder` and used with `ComposableEditor`
* from `@atlaskit/editor-core`.
*/
export const decorationsPlugin = () => ({
name: 'decorations',
pmPlugins() {
return [{
name: 'decorationPlugin',
plugin: () => decorationPlugin()
}];
},
actions: {
hoverDecoration,
removeDecoration
},
getSharedState(editorState) {
if (!editorState) {
return {
decoration: undefined
};
}
return decorationStateKey.getState(editorState);
},
commands: {
hoverDecoration: ({
add,
className
}) => hoverDecorationCommand({
add,
className
}),
removeDecoration: () => removeDecorationCommand()
}
});