🐛(export) fix export column NaN
During the export of tables to PDF, columns with NaN widths were not handled correctly, leading to export not exporting. We now take in case NaN columnwidths. We update the regressions tests to include this kind of tables.
This commit is contained in:
File diff suppressed because one or more lines are too long
Binary file not shown.
@@ -135,7 +135,7 @@ export const utilTable = (
|
||||
columnWidths: (number | undefined)[],
|
||||
) => {
|
||||
const totalColumnWidthKnown = columnWidths.reduce(
|
||||
(sum: number, w) => sum + (w ?? 0),
|
||||
(sum: number, w) => sum + (w && !isNaN(w) ? w : 0),
|
||||
0,
|
||||
);
|
||||
const nbColumnWidthUnknown = columnWidths.filter((w) => !w).length;
|
||||
|
||||
@@ -22,6 +22,29 @@ export const docxDocsSchemaMappings: DocsExporterDocx['mappings'] = {
|
||||
quote: blockMappingQuoteDocx,
|
||||
image: blockMappingImageDocx,
|
||||
uploadLoader: blockMappingUploadLoaderDocx,
|
||||
table: (block, exporter, nestedLevel, numberedListIndex, children) => {
|
||||
/**
|
||||
* Nan values are not supported, so we need to replace them with undefined
|
||||
* to avoid issues during the export.
|
||||
*/
|
||||
const { columnWidths } = block.content;
|
||||
const hasNaN = columnWidths.some(
|
||||
(width) => typeof width === 'number' && Number.isNaN(width),
|
||||
);
|
||||
if (hasNaN) {
|
||||
block.content.columnWidths = columnWidths.map((width) =>
|
||||
typeof width === 'number' && Number.isNaN(width) ? undefined : width,
|
||||
);
|
||||
}
|
||||
|
||||
return docxDefaultSchemaMappings.blockMapping.table(
|
||||
block,
|
||||
exporter,
|
||||
nestedLevel,
|
||||
numberedListIndex,
|
||||
children,
|
||||
);
|
||||
},
|
||||
},
|
||||
inlineContentMapping: {
|
||||
...docxDefaultSchemaMappings.inlineContentMapping,
|
||||
|
||||
Reference in New Issue
Block a user