Skip to content

Commit

Permalink
Patch content model plugins package to 0.28.2 (#2534)
Browse files Browse the repository at this point in the history
* Do not update the segment format if it have a value when pasting from excel #2532

* bump version
  • Loading branch information
BryanValverdeU authored Mar 27, 2024
1 parent 4934b8d commit 49457ad
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 14 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
import { addParser } from '../utils/addParser';
import { isNodeOfType, moveChildNodes } from 'roosterjs-content-model-dom';
import { setProcessor } from '../utils/setProcessor';
import type { BeforePasteEvent, TrustedHTMLHandler } from 'roosterjs-content-model-types';
import type {
BeforePasteEvent,
ElementProcessor,
TrustedHTMLHandler,
} from 'roosterjs-content-model-types';

const LAST_TD_END_REGEX = /<\/\s*td\s*>((?!<\/\s*tr\s*>)[\s\S])*$/i;
const LAST_TR_END_REGEX = /<\/\s*tr\s*>((?!<\/\s*table\s*>)[\s\S])*$/i;
Expand Down Expand Up @@ -61,20 +65,30 @@ export function processPastedContentFromExcel(
}
});

setProcessor(event.domToModelOption, 'child', (group, element, context) => {
const segmentFormat = { ...context.segmentFormat };
if (group.blockGroupType === 'TableCell' && group.format.textColor) {
context.segmentFormat.textColor = group.format.textColor;
}
setProcessor(event.domToModelOption, 'child', childProcessor);
}

context.defaultElementProcessors.child(group, element, context);
/**
* @internal
* Exported only for unit test
*/
export const childProcessor: ElementProcessor<ParentNode> = (group, element, context) => {
const segmentFormat = { ...context.segmentFormat };
if (
group.blockGroupType === 'TableCell' &&
group.format.textColor &&
!context.segmentFormat.textColor
) {
context.segmentFormat.textColor = group.format.textColor;
}

if (group.blockGroupType === 'TableCell' && group.format.textColor) {
context.segmentFormat = segmentFormat;
delete group.format.textColor;
}
});
}
context.defaultElementProcessors.child(group, element, context);

if (group.blockGroupType === 'TableCell' && group.format.textColor) {
context.segmentFormat = segmentFormat;
delete group.format.textColor;
}
};

/**
* @internal Export for test only
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import {
contentModelToDom,
createDomToModelContext,
createModelToDomContext,
createTable,
createTableCell,
domToContentModel,
moveChildNodes,
} from 'roosterjs-content-model-dom';
Expand Down Expand Up @@ -376,3 +378,46 @@ describe('Do not run scenarios', () => {
);
});
});

describe('childProcessorTest', () => {
it('Remove segmentFormat', () => {
const spy = jasmine.createSpy('childProcessor');

const element: any = {};
const context: any = {
segmentFormat: {
textColor: undefined,
},
defaultElementProcessors: {
child: spy,
},
};
const tableCell = createTableCell();
tableCell.format.textColor = 'black';

PastePluginFile.childProcessor(tableCell, element, context);

expect(tableCell.format.textColor).toBeUndefined();
expect(context.segmentFormat.textColor).toBeUndefined();
});
it('Dont remove segmentFormat', () => {
const spy = jasmine.createSpy('childProcessor');

const element: any = {};
const context: any = {
segmentFormat: {
textColor: 'blue',
},
defaultElementProcessors: {
child: spy,
},
};
const tableCell = createTableCell();
tableCell.format.textColor = 'black';

PastePluginFile.childProcessor(tableCell, element, context);

expect(tableCell.format.textColor).toBeUndefined();
expect(context.segmentFormat.textColor).toEqual('blue');
});
});
2 changes: 1 addition & 1 deletion versions.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@
"legacyAdapter": "0.28.0",
"overrides": {
"roosterjs-content-model-core": "0.28.1",
"roosterjs-content-model-plugins": "0.28.1"
"roosterjs-content-model-plugins": "0.28.2"
}
}

0 comments on commit 49457ad

Please sign in to comment.