@20minutes/draft-convert
Version:
Extensibly serialize & deserialize Draft.js ContentState
25 lines (24 loc) • 997 B
JavaScript
import React from 'react';
import invariant from 'tiny-invariant';
import splitReactElement from './splitReactElement.mjs';
export default function getNestedBlockTags(blockHTML, depth) {
invariant(blockHTML !== null && blockHTML !== undefined, 'Expected block HTML value to be non-null');
if (typeof blockHTML.nest === 'function') {
const { start, end } = splitReactElement(blockHTML.nest(depth));
return {
...blockHTML,
nestStart: start,
nestEnd: end
};
}
if (/*#__PURE__*/ React.isValidElement(blockHTML.nest)) {
const { start, end } = splitReactElement(blockHTML.nest);
return {
...blockHTML,
nestStart: start,
nestEnd: end
};
}
invariant(Object.hasOwn(blockHTML, 'nestStart') && Object.hasOwn(blockHTML, 'nestEnd'), 'convertToHTML: received block information without either a ReactElement or an object with start/end tags');
return blockHTML;
}