UNPKG

@atlaskit/editor-plugin-highlight

Version:

Highlight plugin for @atlaskit/editor-core

63 lines (62 loc) 1.81 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.addPaddingDecorations = void 0; var _view = require("@atlaskit/editor-prosemirror/view"); var _utils = require("./utils"); var createPaddingDecoration = function createPaddingDecoration(_ref) { var pos = _ref.pos, node = _ref.node, padLeft = _ref.padLeft, padRight = _ref.padRight; var classes = []; var baseClass = 'background-color'; var padLeftClass = "".concat(baseClass, "-padding-left"); var padRightClass = "".concat(baseClass, "-padding-right"); if (padLeft) { classes.push(padLeftClass); } if (padRight) { classes.push(padRightClass); } return _view.Decoration.inline(pos, pos + node.nodeSize, { class: classes.join(' ') }); }; /** * Adds padding decorations to highlighted text * within the specified range. */ var addPaddingDecorations = exports.addPaddingDecorations = function addPaddingDecorations(_ref2) { var decorationSet = _ref2.decorationSet, state = _ref2.state, from = _ref2.from, to = _ref2.to; var newDecorationSet = decorationSet; state.doc.nodesBetween(from, to, function (node, pos) { if (!(0, _utils.isHighlightedTextNode)(node)) { return; } var nodeStart = pos; var nodeEnd = pos + node.nodeSize; var padLeft = (0, _utils.shouldPadLeft)({ state: state, nodeStart: nodeStart }); var padRight = (0, _utils.shouldPadRight)({ state: state, nodeEnd: nodeEnd }); if (padLeft && padRight) { var newDecoration = createPaddingDecoration({ pos: nodeStart, node: node, padLeft: padLeft, padRight: padRight }); newDecorationSet = newDecorationSet.add(state.doc, [newDecoration]); } }); return newDecorationSet; };