All files / roosterjs-content-model-dom/lib/formatHandlers/block directionFormatHandler.ts

100% Statements 9/9
100% Branches 14/14
100% Functions 2/2
100% Lines 9/9

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 301x             1x   8856x   8856x 1512x       2139x 385x     2139x         10x        
import { isElementOfType } from '../../domUtils/isElementOfType';
import type { DirectionFormat } from 'roosterjs-content-model-types';
import type { FormatHandler } from '../FormatHandler';
 
/**
 * @internal
 */
export const directionFormatHandler: FormatHandler<DirectionFormat> = {
    parse: (format, element, _, defaultStyle) => {
        const dir = element.style.direction || element.dir || defaultStyle.direction;
 
        if (dir) {
            format.direction = dir == 'rtl' ? 'rtl' : 'ltr';
        }
    },
    apply: (format, element, context) => {
        if (format.direction) {
            element.style.direction = format.direction;
        }
 
        if (
            format.direction == 'rtl' &&
            isElementOfType(element, 'table') &&
            context.implicitFormat.direction != 'rtl'
        ) {
            element.style.justifySelf = 'flex-end';
        }
    },
};