RichText/Archived/Rooster/Rooster.gcomp/Support/node_modules/roosterjs/dist/rooster-amd.js
/**
 * Clear all formats of selected blocks.
 * When selection is collapsed, only clear format of current block.
 * @param editor The editor instance
 * @param tagsToUnwrap Optional. A string array contains HTML tags in upper case which we will unwrap when clear format
 * @param tagsToStopUnwrap Optional. A string array contains HTML tags in upper case which we will stop unwrap if these tags are hit
 */
Clear all formats of selected blocks.
When selection is collapsed, only clear format of current block.
@param editor The editor instance
@param tagsToUnwrap Optional. A string array contains HTML tags in upper case which we will unwrap when clear format
@param tagsToStopUnwrap Optional. A string array contains HTML tags in upper case which we will stop unwrap if these tags are hit
Clear all formats of selected blocks . When selection is collapsed only clear format of current block . @param editor The editor instance @param tagsToUnwrap Optional . A string array contains HTML tags in upper case which we will unwrap when clear format @param tagsToStopUnwrap Optional . A string array contains HTML tags in upper case which we will stop unwrap if these tags are hit
function clearBlockFormat(editor, tagsToUnwrap, tagsToStopUnwrap, attributesToPreserve) {
    if (tagsToUnwrap === void 0) { tagsToUnwrap = exports.TAGS_TO_UNWRAP; }
    if (tagsToStopUnwrap === void 0) { tagsToStopUnwrap = exports.TAGS_TO_STOP_UNWRAP; }
    if (attributesToPreserve === void 0) { attributesToPreserve = exports.ATTRIBUTES_TO_PRESERVE; }
    editor.focus();
    editor.addUndoSnapshot(function (start, end) {
        var groups = [{}];
        var stopUnwrapSelector = tagsToStopUnwrap.join(',');
        collapseSelectedBlocks_1.default(editor, function (element) {
            var group = groups[groups.length - 1];
            var td = editor.getElementAtCursor(stopUnwrapSelector, element);
            if (td != group.td && group.first) {
                groups.push((group = {}));
            }
            group.td = td;
            group.first = group.first || element;
            group.last = element;
        });
        groups
            .filter(function (group) { return group.first; })
            .forEach(function (group) {
            var nodes = editor.collapseNodes(group.first, group.last, true );
            if (canCollapse(tagsToStopUnwrap, nodes[0])) {
                while (editor.contains(nodes[0].parentNode) &&
                    canCollapse(tagsToStopUnwrap, nodes[0].parentNode)) {
                    nodes = [roosterjs_editor_dom_1.splitBalancedNodeRange(nodes)];
                }
            }
            nodes.forEach(function (node) {
                return clearNodeFormat(node, tagsToUnwrap, tagsToStopUnwrap, attributesToPreserve);
            });
            if (group.td) {
                var styles = group.td.getAttribute('style') || '';
                var styleArray = styles.split(';');
                styleArray = styleArray.filter(function (style) {
                    return style
                        .trim()
                        .toLowerCase()
                        .indexOf('border') == 0;
                });
                styles = styleArray.join(';');
                if (styles) {
                    group.td.setAttribute('style', styles);
                }
                else {
                    group.td.removeAttribute('style');
                }
            }
        });
        editor.select(start, end);
    }, "Format" );
}
function clearBlockFormat ( editor , tagsToUnwrap , tagsToStopUnwrap , attributesToPreserve ) { if ( tagsToUnwrap === void 0 ) { tagsToUnwrap = exports . TAGS_TO_UNWRAP ; } if ( tagsToStopUnwrap === void 0 ) { tagsToStopUnwrap = exports . TAGS_TO_STOP_UNWRAP ; } if ( attributesToPreserve === void 0 ) { attributesToPreserve = exports . ATTRIBUTES_TO_PRESERVE ; } editor . focus ( ) ; editor . addUndoSnapshot ( function ( start , end ) { var groups = [ { } ] ; var stopUnwrapSelector = tagsToStopUnwrap . join ( ',' ) ; collapseSelectedBlocks_1 . default ( editor , function ( element ) { var group = groups [ groups . length - 1 ] ; var td = editor . getElementAtCursor ( stopUnwrapSelector , element ) ; if ( td != group . td && group . first ) { groups . push ( ( group = { } ) ) ; } group . td = td ; group . first = group . first || element ; group . last = element ; } ) ; groups . filter ( function ( group ) { return group . first ; } ) . forEach ( function ( group ) { var nodes = editor . collapseNodes ( group . first , group . last , true ) ; if ( canCollapse ( tagsToStopUnwrap , nodes [ 0 ] ) ) { while ( editor . contains ( nodes [ 0 ] . parentNode ) && canCollapse ( tagsToStopUnwrap , nodes [ 0 ] . parentNode ) ) { nodes = [ roosterjs_editor_dom_1 . splitBalancedNodeRange ( nodes ) ] ; } } nodes . forEach ( function ( node ) { return clearNodeFormat ( node , tagsToUnwrap , tagsToStopUnwrap , attributesToPreserve ) ; } ) ; if ( group . td ) { var styles = group . td . getAttribute ( 'style' ) || '' ; var styleArray = styles . split ( ';' ) ; styleArray = styleArray . filter ( function ( style ) { return style . trim ( ) . toLowerCase ( ) . indexOf ( 'border' ) == 0 ; } ) ; styles = styleArray . join ( ';' ) ; if ( styles ) { group . td . setAttribute ( 'style' , styles ) ; } else { group . td . removeAttribute ( 'style' ) ; } } } ) ; editor . select ( start , end ) ; } , "Format" ) ; }
Clear all formats of selected blocks.
Clear all formats of selected blocks .
// 1. Collapse the selected blocks and get first and last element // 2. Collapse with first and last element to make them under same parent /*canSplitParent*/ // 3. Continue collapse until we can't collapse any more (hit root node, or a table) // 4. Clear formats of the nodes // 5. Clear CSS of container TD if exist /* Format */