UNPKG

@atlaskit/editor-plugin-selection-marker

Version:

Selection marker plugin for @atlaskit/editor-core.

31 lines (30 loc) 1.37 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.selectionDecoration = void 0; var _view = require("@atlaskit/editor-prosemirror/view"); var decorationStyle = "\n background-color: ".concat("var(--ds-background-neutral, #0515240F)", ";\n "); var decorationHighlightStyle = "\n background-color: ".concat("var(--ds-background-accent-blue-subtlest, #E9F2FE)", ";\n border-bottom: ", "var(--ds-border-width-selected, 2px)", " solid ", "var(--ds-background-accent-blue-subtler, #CFE1FD)", ";\n "); var selectionDecoration = exports.selectionDecoration = function selectionDecoration(doc, selection, isHighlight) { var selectionDecorations = []; doc.nodesBetween(selection.from, selection.to, function (currentNode, nodePos) { if (!currentNode.isText) { return true; } var decorationFrom = selection.from; var decorationTo = selection.to; if (nodePos > selection.from) { decorationFrom = nodePos; } if (nodePos + currentNode.nodeSize < selection.to) { decorationTo = nodePos + currentNode.nodeSize; } selectionDecorations.push(_view.Decoration.inline(decorationFrom, decorationTo, { style: isHighlight ? decorationHighlightStyle : decorationStyle, 'data-testid': 'selection-marker-selection' })); return true; }); return selectionDecorations; };