Skip to content

Commit

Permalink
added parameter, fix tests (#2247)
Browse files Browse the repository at this point in the history
  • Loading branch information
Andres-CT98 authored Dec 7, 2023
1 parent 9f4e4f0 commit f136d03
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,12 @@ export class ContentModelPastePlugin implements EditorPlugin {
/**
* Construct a new instance of Paste class
* @param unknownTagReplacement Replace solution of unknown tags, default behavior is to replace with SPAN
* @param allowExcelNoBorderTable Allow table copied from Excel without border
*/
constructor(private unknownTagReplacement: string = 'SPAN') {}
constructor(
private unknownTagReplacement: string = 'SPAN',
private allowExcelNoBorderTable?: boolean
) {}

/**
* Get name of this plugin
Expand Down Expand Up @@ -110,7 +114,11 @@ export class ContentModelPastePlugin implements EditorPlugin {
case 'excelDesktop':
if (pasteType === 'normal' || pasteType === 'mergeFormat') {
// Handle HTML copied from Excel
processPastedContentFromExcel(ev, this.editor.getTrustedHTMLHandler());
processPastedContentFromExcel(
ev,
this.editor.getTrustedHTMLHandler(),
this.allowExcelNoBorderTable
);
}
break;
case 'googleSheets':
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ const DEFAULT_BORDER_STYLE = 'solid 1px #d4d4d4';

export function processPastedContentFromExcel(
event: ContentModelBeforePasteEvent,
trustedHTMLHandler: TrustedHTMLHandler
trustedHTMLHandler: TrustedHTMLHandler,
allowExcelNoBorderTable?: boolean
) {
const { fragment, htmlBefore, clipboardData } = event;
const html = clipboardData.html ? excelHandler(clipboardData.html, htmlBefore) : undefined;
Expand Down Expand Up @@ -53,7 +54,7 @@ export function processPastedContentFromExcel(
}

addParser(event.domToModelOption, 'tableCell', (format, element) => {
if (element.style.borderStyle === 'none') {
if (!allowExcelNoBorderTable && element.style.borderStyle === 'none') {
format.borderBottom = DEFAULT_BORDER_STYLE;
format.borderLeft = DEFAULT_BORDER_STYLE;
format.borderRight = DEFAULT_BORDER_STYLE;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,8 @@ describe('Content Model Paste Plugin Test', () => {

expect(ExcelFile.processPastedContentFromExcel).toHaveBeenCalledWith(
event,
trustedHTMLHandler
trustedHTMLHandler,
undefined /*allowExcelNoBorderTable*/
);
expect(addParser.default).toHaveBeenCalledTimes(DEFAULT_TIMES_ADD_PARSER_CALLED + 3);
expect(setProcessor.setProcessor).toHaveBeenCalledTimes(1);
Expand All @@ -122,7 +123,8 @@ describe('Content Model Paste Plugin Test', () => {

expect(ExcelFile.processPastedContentFromExcel).not.toHaveBeenCalledWith(
event,
trustedHTMLHandler
trustedHTMLHandler,
undefined /*allowExcelNoBorderTable*/
);
expect(addParser.default).toHaveBeenCalledTimes(DEFAULT_TIMES_ADD_PARSER_CALLED);
expect(chainSanitizerCallbackFile.default).toHaveBeenCalledTimes(1);
Expand All @@ -138,7 +140,8 @@ describe('Content Model Paste Plugin Test', () => {

expect(ExcelFile.processPastedContentFromExcel).toHaveBeenCalledWith(
event,
trustedHTMLHandler
trustedHTMLHandler,
undefined /*allowExcelNoBorderTable*/
);
expect(addParser.default).toHaveBeenCalledTimes(DEFAULT_TIMES_ADD_PARSER_CALLED + 1);
expect(setProcessor.setProcessor).toHaveBeenCalledTimes(1);
Expand All @@ -154,7 +157,8 @@ describe('Content Model Paste Plugin Test', () => {

expect(ExcelFile.processPastedContentFromExcel).toHaveBeenCalledWith(
event,
trustedHTMLHandler
trustedHTMLHandler,
undefined /*allowExcelNoBorderTable*/
);
expect(addParser.default).toHaveBeenCalledTimes(DEFAULT_TIMES_ADD_PARSER_CALLED + 1);
expect(setProcessor.setProcessor).toHaveBeenCalledTimes(1);
Expand Down

0 comments on commit f136d03

Please sign in to comment.