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

100% Statements 9/9
100% Branches 13/13
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 261x             1x   7361x   7361x 1401x       1763x 348x     1763x 3x        
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) => {
        if (format.direction) {
            element.style.direction = format.direction;
        }
 
        if (format.direction == 'rtl' && isElementOfType(element, 'table')) {
            element.style.justifySelf = 'flex-end';
        }
    },
};