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

100% Statements 3/3
100% Branches 2/2
100% Functions 1/1
100% Lines 3/3

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                    1x   152x         107x                        
import type { ContentModelEntity, ContentModelSegmentFormat } from 'roosterjs-content-model-types';
 
/**
 * Create a ContentModelEntity model
 * @param wrapper Wrapper element of this entity
 * @param isReadonly Whether this is a readonly entity @default true
 * @param segmentFormat @optional Segment format of this entity
 * @param type @optional Type of this entity
 * @param id @optional Id of this entity
 */
export function createEntity(
    wrapper: HTMLElement,
    isReadonly: boolean = true,
    segmentFormat?: Readonly<ContentModelSegmentFormat>,
    type?: string,
    id?: string
): ContentModelEntity {
    return {
        segmentType: 'Entity',
        blockType: 'Entity',
        format: { ...segmentFormat },
        entityFormat: {
            id,
            entityType: type,
            isReadonly,
        },
        wrapper,
    };
}