UNPKG

@mirrormedia/lilith-draft-renderer

Version:
44 lines (34 loc) 1.37 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.removeEmptyContentBlock = exports.hasContentInRawContentBlock = void 0; const hasContentInRawContentBlock = rawContentBlock => { if (!rawContentBlock || !rawContentBlock.blocks || !rawContentBlock.blocks.length) { return false; } const hasAtomicBlock = Boolean(rawContentBlock.blocks.some(block => block.type === 'atomic')); if (hasAtomicBlock) { return hasAtomicBlock; } const defaultBlockHasContent = Boolean(rawContentBlock.blocks.filter(block => block.type !== 'atomic').some(block => block.text.trim())); return defaultBlockHasContent; }; exports.hasContentInRawContentBlock = hasContentInRawContentBlock; const removeEmptyContentBlock = rawContentBlock => { const hasContent = hasContentInRawContentBlock(rawContentBlock); if (!hasContent) { throw new Error('There is no content in rawContentBlock, please check again.'); } const blocksWithHideEmptyBlock = rawContentBlock === null || rawContentBlock === void 0 ? void 0 : rawContentBlock.blocks.map(block => { if (block.type === 'atomic' || block.text) { return block; } else { return undefined; } }).filter(block => block); return { ...rawContentBlock, blocks: blocksWithHideEmptyBlock }; }; exports.removeEmptyContentBlock = removeEmptyContentBlock;