UNPKG

@atlaskit/editor-plugin-highlight

Version:

Highlight plugin for @atlaskit/editor-core

23 lines 872 B
import { isMarkAllowedInRange, isMarkExcluded } from '@atlaskit/editor-common/mark'; import { GapCursorSelection } from '@atlaskit/editor-common/selection'; import { NodeSelection } from '@atlaskit/editor-prosemirror/state'; export var getDisabledState = function getDisabledState(state) { var backgroundColor = state.schema.marks.backgroundColor; var _ref = state.selection, empty = _ref.empty, ranges = _ref.ranges, $cursor = _ref.$cursor; 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; };