All files / roosterjs-content-model-api/lib/publicApi/utils createEditorContextForEntity.ts

100% Statements 6/6
83.33% Branches 5/6
100% Functions 1/1
100% Lines 6/6

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                1x       4x 4x                     4x 1x     4x    
import type { ContentModelEntity, EditorContext, IEditor } from 'roosterjs-content-model-types';
 
/**
 * Create an EditorContext for an entity
 * @param editor The editor object
 * @param entity The entity to create the context for
 * @returns The generated EditorContext for the entity
 */
export function createEditorContextForEntity(
    editor: IEditor,
    entity: ContentModelEntity
): EditorContext {
    const domHelper = editor.getDOMHelper();
    const context: EditorContext = {
        isDarkMode: editor.isDarkMode(),
        defaultFormat: { ...entity.format },
        darkColorHandler: editor.getColorManager(),
        addDelimiterForEntity: false,
        allowCacheElement: false,
        domIndexer: undefined,
        zoomScale: domHelper.calculateZoomScale(),
        experimentalFeatures: [],
    };
 
    if (editor.getDocument().defaultView?.getComputedStyle(entity.wrapper).direction == 'rtl') {
        context.isRootRtl = true;
    }
 
    return context;
}