All files / roosterjs-content-model-dom/lib/modelApi/creators createListItem.ts

100% Statements 7/7
50% Branches 1/2
100% Functions 2/2
100% Lines 7/7

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 331x 1x                       1x       696x   696x   696x         967x            
import { createListLevel } from './createListLevel';
import { createSelectionMarker } from './createSelectionMarker';
import type {
    ContentModelListItem,
    ContentModelSegmentFormat,
    ReadonlyContentModelListLevel,
} from 'roosterjs-content-model-types';
 
/**
 * Create a ContentModelListItem model
 * @param levels Existing list levels
 * @param format @optional The format of this model
 */
export function createListItem(
    levels: ReadonlyArray<ReadonlyContentModelListLevel>,
    format?: Readonly<ContentModelSegmentFormat>
): ContentModelListItem {
    const formatHolder = createSelectionMarker(format);
 
    formatHolder.isSelected = false;
 
    return {
        blockType: 'BlockGroup',
        blockGroupType: 'ListItem',
        blocks: [],
        levels: levels
            ? levels.map(level => createListLevel(level.listType, level.format, level.dataset))
            : [],
        formatHolder,
        format: {},
    };
}