Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 | 1x 1x 1x 1x 22x 22x 20x 20x 20x 21x 21x 13x 21x | import { copyFormat } from '../../modelApi/block/copyFormat';
import { mutateBlock } from './mutate';
import { setParagraphNotImplicit } from '../block/setParagraphNotImplicit';
import type {
ContentModelBlockFormat,
ReadonlyContentModelBlock,
ReadonlyContentModelBlockGroup,
} from 'roosterjs-content-model-types';
/**
* Unwrap a given block group, move its child blocks to be under its parent group
* @param parent Parent block group of the unwrapping group
* @param groupToUnwrap The block group to unwrap
*/
export function unwrapBlock(
parent: ReadonlyContentModelBlockGroup | null,
groupToUnwrap: ReadonlyContentModelBlockGroup & ReadonlyContentModelBlock,
formatsToKeep?: (keyof ContentModelBlockFormat)[]
) {
const index = parent?.blocks.indexOf(groupToUnwrap) ?? -1;
if (index >= 0) {
groupToUnwrap.blocks.forEach(setParagraphNotImplicit);
Eif (parent) {
mutateBlock(parent)?.blocks.splice(
index,
1,
...groupToUnwrap.blocks.map(x => {
const mutableBlock = mutateBlock(x);
if (formatsToKeep) {
copyFormat<ContentModelBlockFormat>(
mutableBlock.format,
groupToUnwrap.format,
formatsToKeep
);
}
return mutableBlock;
})
);
}
}
}
|