UNPKG

@atlaskit/adf-utils

Version:

Set of utilities to traverse, modify and create ADF documents.

47 lines 1.87 kB
import { traverse } from '../traverse/traverse'; const hasChildHeadingWithIndentation = node => { var _node$content$some, _node$content; return (_node$content$some = (_node$content = node.content) === null || _node$content === void 0 ? void 0 : _node$content.some(childNode => { var _childNode$marks; return (childNode === null || childNode === void 0 ? void 0 : childNode.type) === 'heading' && (childNode === null || childNode === void 0 ? void 0 : (_childNode$marks = childNode.marks) === null || _childNode$marks === void 0 ? void 0 : _childNode$marks.some(mark => mark.type === 'indentation')); })) !== null && _node$content$some !== void 0 ? _node$content$some : false; }; const removeIndentationFromHeadings = node => { var _node$content2; return { ...node, content: (_node$content2 = node.content) === null || _node$content2 === void 0 ? void 0 : _node$content2.map(childNode => { if ((childNode === null || childNode === void 0 ? void 0 : childNode.type) === 'heading') { var _childNode$marks2; return { ...childNode, marks: (_childNode$marks2 = childNode.marks) === null || _childNode$marks2 === void 0 ? void 0 : _childNode$marks2.filter(mark => mark.type !== 'indentation') }; } return childNode; }) }; }; export const transformIndentationMarks = adf => { let isTransformed = false; const transformedAdf = traverse(adf, { tableCell: node => { if (hasChildHeadingWithIndentation(node)) { isTransformed = true; return removeIndentationFromHeadings(node); } return; }, tableHeader: node => { if (hasChildHeadingWithIndentation(node)) { isTransformed = true; return removeIndentationFromHeadings(node); } return; } }); return { transformedAdf, isTransformed }; };