UNPKG

@atlaskit/editor-plugin-highlight

Version:

Highlight plugin for @atlaskit/editor-core

26 lines 806 B
import { isMarkAllowedInRange, isMarkExcluded } from '@atlaskit/editor-common/mark'; import { GapCursorSelection } from '@atlaskit/editor-common/selection'; import { NodeSelection } from '@atlaskit/editor-prosemirror/state'; export const getDisabledState = state => { const { backgroundColor } = state.schema.marks; const { empty, ranges, $cursor } = state.selection; if (!backgroundColor) { return true; } if (state.selection instanceof NodeSelection || state.selection instanceof GapCursorSelection) { return true; } if (empty && !$cursor || isMarkAllowedInRange(state.doc, ranges, backgroundColor) === false) { return true; } if (isMarkExcluded(backgroundColor, state.storedMarks || $cursor && $cursor.marks())) { return true; } return false; };