UNPKG

@atlaskit/editor-core

Version:

A package contains Atlassian editor core functionality

61 lines 2.36 kB
import { liftFollowingList } from '../../commands/lists'; export function clearFormatting(markTypes) { return function (state, dispatch) { var tr = state.tr; var _a = state.selection, from = _a.from, to = _a.to; var paragraph = state.schema.nodes.paragraph; markTypes.forEach(function (mark) { return tr.removeMark(from, to, state.schema.marks[mark]); }); tr.setStoredMarks([]); if (paragraph) { tr.setBlockType(from, to, paragraph); tr = liftAllNodes(state, tr); } dispatch(tr); return true; }; } function liftAllNodes(state, tr) { var paragraph = state.schema.nodes.paragraph; var _a = state.selection, $to = _a.$to, from = _a.from, to = _a.to; var paragraphs = []; if (listPresentAtPos(state.schema, $to)) { var selection = state.selection; var _b = state.schema.nodes, bulletList = _b.bulletList, orderedList = _b.orderedList, listItem = _b.listItem; var rootListDepth = void 0; for (var i = selection.$to.depth - 1; i > 0; i--) { var node = selection.$to.node(i); if (node.type === bulletList || node.type === orderedList) { rootListDepth = i; } if (node.type !== bulletList && node.type !== orderedList && node.type !== listItem) { break; } } tr = liftFollowingList(state, selection.$to.pos, selection.$to.end(rootListDepth), rootListDepth, tr); } tr.doc.nodesBetween(from, to, function (node, pos) { if (node.type === paragraph) { paragraphs.push({ node: node, pos: pos }); } }); for (var i = paragraphs.length - 1; i >= 0; i--) { var _c = paragraphs[i], node = _c.node, pos = _c.pos; var start = tr.doc.resolve(tr.mapping.map(pos)); var end = tr.doc.resolve(tr.mapping.map(pos + node.textContent.length)); if (start.depth > 0) { var range = start.blockRange(end); tr = tr.lift(range, 0); } } return tr; } function listPresentAtPos(schema, resPos) { for (var i = resPos.depth; i > 0; i--) { var node = resPos.node(i); if (node.type === schema.nodes.listItem) { return true; } } return false; } //# sourceMappingURL=commands.js.map