Skip to content

Commit

Permalink
add more changes
Browse files Browse the repository at this point in the history
  • Loading branch information
BryanValverdeU committed Sep 30, 2024
1 parent 7c8a32b commit 40db8f8
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export const tableSpacingFormatHandler: FormatHandler<SpacingFormat> = {
format.borderSeparate = true;
}
},
apply: (format, element) => {
apply: (format, element, context) => {
if (format.borderCollapse) {
element.style.borderCollapse = BorderCollapsed;
element.style.borderSpacing = '0';
Expand All @@ -46,5 +46,10 @@ export const tableSpacingFormatHandler: FormatHandler<SpacingFormat> = {
);
element.style.borderSpacing = cellSpacing;
}

if (!context.tableFormat) {
context.tableFormat = {};
}
context.tableFormat.cellPadding = format.cellPadding;
},
};
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ export const handleTable: ContentModelBlockHandler<ContentModelTable> = (
// Empty table, do not create TABLE element and just return
return refNode;
}
let previousTableContext = context.tableFormat;
const previousTableContext = context.tableFormat;
context.tableFormat = {};

let tableNode = context.allowCacheElement ? table.cachedElement : undefined;

Expand All @@ -45,9 +46,6 @@ export const handleTable: ContentModelBlockHandler<ContentModelTable> = (
applyFormat(tableNode, context.formatAppliers.table, table.format, context);
applyFormat(tableNode, context.formatAppliers.tableBorder, table.format, context);
applyFormat(tableNode, context.formatAppliers.dataset, table.dataset, context);
context.tableFormat = {
cellPadding: table.format.cellPadding,
};
}

context.onNodeCreated?.(table, tableNode);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,13 @@ describe('tableSpacingFormatHandler.parse', () => {
it('Non-collapsed border', () => {
div.style.borderCollapse = 'separate';
tableSpacingFormatHandler.parse(format, div, context, {});
expect(format).toEqual({ borderSeparate: true, cellPadding: '0' });
expect(format).toEqual({ borderSeparate: true });
});

it('Set border collapsed if element contains cellpadding attribute', () => {
div.setAttribute('cellPadding', '0');
tableSpacingFormatHandler.parse(format, div, context, {});
expect(format).toEqual({ borderCollapse: true });
expect(format).toEqual({ cellPadding: '0' });
});
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1285,7 +1285,7 @@ describe(ID, () => {
width: '157pt' as any,
useBorderBox: true,
borderCollapse: true,
cellPadding: '0',
cellSpacing: '0px',
} as any,
dataset: {},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,7 @@ describe(ID, () => {
useBorderBox: true,
borderCollapse: true,
textIndent: '0px',
cellSpacing: '0px',
},
dataset: {
tablestyle: 'MsoTableGrid',
Expand Down

0 comments on commit 40db8f8

Please sign in to comment.