UNPKG

@atlaskit/editor-plugin-decorations

Version:

Decorations plugin for @atlaskit/editor-core

39 lines (38 loc) 1.16 kB
import { editorExperiment } from '@atlaskit/tmp-editor-statsig/experiments'; 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: editorExperiment('platform_editor_block_menu', true) ? ({ add, className }) => hoverDecorationCommand({ add, className }) : undefined, removeDecoration: editorExperiment('platform_editor_block_menu', true) ? () => removeDecorationCommand() : undefined } });