UNPKG

@atlaskit/editor-common

Version:

A package that contains common classes and components for editor and renderer

67 lines (66 loc) 2.06 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.isMarkExcluded = exports.isMarkAllowedInRange = exports.anyMarkActive = void 0; var _cellSelection = require("@atlaskit/editor-tables/cell-selection"); /** * Determine if a mark of a specific type exists anywhere in the selection. */ var anyMarkActive = exports.anyMarkActive = function anyMarkActive(state, markType) { var _state$selection = state.selection, $from = _state$selection.$from, from = _state$selection.from, to = _state$selection.to, empty = _state$selection.empty; if (empty) { return !!markType.isInSet(state.storedMarks || $from.marks()); } var rangeHasMark = false; if (state.selection instanceof _cellSelection.CellSelection) { state.selection.forEachCell(function (cell, cellPos) { var from = cellPos; var to = cellPos + cell.nodeSize; if (!rangeHasMark) { rangeHasMark = state.doc.rangeHasMark(from, to, markType); } }); } else { rangeHasMark = state.doc.rangeHasMark(from, to, markType); } return rangeHasMark; }; var isMarkAllowedInRange = exports.isMarkAllowedInRange = function isMarkAllowedInRange(doc, ranges, type) { var _loop = function _loop() { var _ranges$i = ranges[i], $from = _ranges$i.$from, $to = _ranges$i.$to; var can = $from.depth === 0 ? doc.type.allowsMarkType(type) : false; doc.nodesBetween($from.pos, $to.pos, function (node) { if (can) { return false; } can = node.inlineContent && node.type.allowsMarkType(type); return; }); if (can) { return { v: can }; } }, _ret; for (var i = 0; i < ranges.length; i++) { _ret = _loop(); if (_ret) return _ret.v; } return false; }; var isMarkExcluded = exports.isMarkExcluded = function isMarkExcluded(type, marks) { if (marks) { return marks.some(function (mark) { return mark.type !== type && mark.type.excludes(type); }); } return false; };