feat: a cell's vertical alignment survives saving
Import read style:vertical-align but neither exporter wrote it, so a mid-cell callout label jumped to the row's top on every save. odf-kit's CellOptions and docx's TableCell both take it natively; DOCX import maps w:vAlign in as well.
This commit is contained in:
1 parent
3805654e8a
commit
a8dcd9b897
6 files changed
+45
-1
No files matched your search
@@ -507,6 +507,7 @@ describe('Leg 1b: merged table cells (colspan/rowspan)', () => {
|
||||
] },
|
||||
],
|
||||
};
|
||||
mergedDoc.content![1].content![0].content![1].attrs!.verticalAlign = 'middle';
|
||||
|
||||
it('exports spans + covered cells and re-imports them', async () => {
|
||||
const bytes = await buildOdt(mergedDoc, margins, 'portrait');
|
||||
@@ -527,6 +528,8 @@ describe('Leg 1b: merged table cells (colspan/rowspan)', () => {
|
||||
check('C has rowspan 2', rows[1]?.content?.[0]?.attrs?.rowspan === 2, rows[1]?.content?.[0]?.attrs);
|
||||
check('A shading round-trips (#FFFF00)', rows[0]?.content?.[0]?.attrs?.backgroundColor === '#FFFF00', rows[0]?.content?.[0]?.attrs?.backgroundColor);
|
||||
check('B has no shading', rows[0]?.content?.[1]?.attrs?.backgroundColor == null, rows[0]?.content?.[1]?.attrs?.backgroundColor);
|
||||
check('B keeps vertical-align middle', rows[0]?.content?.[1]?.attrs?.verticalAlign === 'middle', rows[0]?.content?.[1]?.attrs?.verticalAlign);
|
||||
check('A stays top-aligned', rows[0]?.content?.[0]?.attrs?.verticalAlign == null, rows[0]?.content?.[0]?.attrs?.verticalAlign);
|
||||
|
||||
const textOf = (cell: N) => cell?.content?.[0]?.content?.[0]?.text;
|
||||
check('A text preserved', textOf(rows[0]?.content?.[0]) === 'A', textOf(rows[0]?.content?.[0]));
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
// A cell's verticalAlign attr round-trips through DOCX (w:vAlign); the ODF leg
|
||||
// (style:vertical-align) rides along in roundtrip.test.ts.
|
||||
import { describe, it, expect } from 'vitest';
|
||||
import { buildDocx } from '../../src/lib/export/docx';
|
||||
import { importDocx } from '../../src/lib/import/docx';
|
||||
|
||||
type N = any;
|
||||
|
||||
const cell = (text: string, verticalAlign?: string): N => ({
|
||||
type: 'tableCell',
|
||||
attrs: { colspan: 1, rowspan: 1, colwidth: [120], ...(verticalAlign ? { verticalAlign } : {}) },
|
||||
content: [{ type: 'paragraph', content: [{ type: 'text', text }] }],
|
||||
});
|
||||
|
||||
describe('table cell vertical alignment', () => {
|
||||
it('round-trips middle/bottom and leaves top unset', async () => {
|
||||
const doc: N = {
|
||||
type: 'doc',
|
||||
content: [
|
||||
{ type: 'paragraph', content: [{ type: 'text', text: 'Before' }] },
|
||||
{ type: 'table', content: [
|
||||
{ type: 'tableRow', content: [cell('A', 'middle'), cell('B', 'bottom'), cell('C')] },
|
||||
] },
|
||||
],
|
||||
};
|
||||
const res = importDocx(await buildDocx(doc, { top: 2, bottom: 2, left: 2, right: 2 }, 'portrait'));
|
||||
const cells = (res.content.content!.find((n: N) => n.type === 'table') as N).content[0].content;
|
||||
expect(cells.map((c: N) => c.attrs?.verticalAlign ?? null)).toEqual(['middle', 'bottom', null]);
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user