Skip to content

Commit f9c4da9

Browse files
committed
fix(tables): keep tableProperties internal and honor continuation edges with spaced borders
1 parent 9ae5207 commit f9c4da9

4 files changed

Lines changed: 78 additions & 2 deletions

File tree

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
import { beforeEach, describe, expect, it, vi } from 'vitest';
2+
import { renderTableRow } from './renderTableRow.js';
3+
4+
const renderTableCellMock = vi.fn(() => ({ cellElement: document.createElement('div') }));
5+
6+
vi.mock('./renderTableCell.js', () => ({
7+
renderTableCell: (args: unknown) => renderTableCellMock(args),
8+
}));
9+
10+
describe('renderTableRow', () => {
11+
let doc: Document;
12+
let container: HTMLElement;
13+
14+
beforeEach(() => {
15+
doc = document.implementation.createHTMLDocument('table-row');
16+
container = doc.createElement('div');
17+
renderTableCellMock.mockClear();
18+
});
19+
20+
const createDeps = (overrides: Record<string, unknown> = {}) => ({
21+
doc,
22+
container,
23+
rowIndex: 3,
24+
y: 0,
25+
rowMeasure: {
26+
height: 20,
27+
cells: [{ width: 100, height: 20, gridColumnStart: 0, colSpan: 1, rowSpan: 1 }],
28+
},
29+
row: {
30+
id: 'row-1',
31+
cells: [{ id: 'cell-1', blocks: [{ kind: 'paragraph', id: 'p1', runs: [] }] }],
32+
},
33+
totalRows: 10,
34+
tableBorders: {
35+
top: { style: 'single', width: 1, color: '#000000' },
36+
bottom: { style: 'single', width: 1, color: '#000000' },
37+
left: { style: 'single', width: 1, color: '#000000' },
38+
right: { style: 'single', width: 1, color: '#000000' },
39+
insideH: { style: 'single', width: 1, color: '#111111' },
40+
insideV: { style: 'single', width: 1, color: '#222222' },
41+
},
42+
columnWidths: [100],
43+
allRowHeights: [20, 20, 20, 20, 20, 20, 20, 20, 20, 20],
44+
tableIndent: 0,
45+
context: { sectionIndex: 0, pageIndex: 0, columnIndex: 0 },
46+
renderLine: () => doc.createElement('div'),
47+
applySdtDataset: () => {},
48+
cellSpacingPx: 6,
49+
...overrides,
50+
});
51+
52+
it('does not draw insideH on top edge for continuation fragments with cell spacing', () => {
53+
renderTableRow(createDeps({ continuesFromPrev: true }) as never);
54+
55+
expect(renderTableCellMock).toHaveBeenCalledTimes(1);
56+
const call = renderTableCellMock.mock.calls[0][0] as { borders?: { top?: unknown; bottom?: unknown } };
57+
expect(call.borders?.top).toBeUndefined();
58+
expect(call.borders?.bottom).toBeDefined();
59+
});
60+
61+
it('does not draw insideH on bottom edge before continuation with cell spacing', () => {
62+
renderTableRow(createDeps({ continuesOnNext: true }) as never);
63+
64+
expect(renderTableCellMock).toHaveBeenCalledTimes(1);
65+
const call = renderTableCellMock.mock.calls[0][0] as { borders?: { top?: unknown; bottom?: unknown } };
66+
expect(call.borders?.top).toBeDefined();
67+
expect(call.borders?.bottom).toBeUndefined();
68+
});
69+
});

packages/layout-engine/painters/dom/src/table/renderTableRow.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -301,10 +301,12 @@ export const renderTableRow = (deps: TableRowRenderDependencies): void => {
301301
const isLastRow = rowIndex === totalRows - 1;
302302
const isFirstCol = gridColIndex === 0;
303303
const isLastCol = gridColIndex === totalCols - 1;
304+
const treatAsFirstRow = isFirstRow || continuesFromPrev;
305+
const treatAsLastRow = isLastRow || continuesOnNext;
304306

305307
resolvedBorders = {
306-
top: !isFirstRow ? borderValueToSpec(tableBorders.insideH) : undefined,
307-
bottom: !isLastRow ? borderValueToSpec(tableBorders.insideH) : undefined,
308+
top: !treatAsFirstRow ? borderValueToSpec(tableBorders.insideH) : undefined,
309+
bottom: !treatAsLastRow ? borderValueToSpec(tableBorders.insideH) : undefined,
308310
left: !isFirstCol ? borderValueToSpec(tableBorders.insideV) : undefined,
309311
right: !isLastCol ? borderValueToSpec(tableBorders.insideV) : undefined,
310312
};

packages/super-editor/src/extensions/table/table.import-width.test.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ import { Table } from './table.js';
55
describe('Table import width defaults', () => {
66
const attributes = Table.config.addAttributes.call(Table);
77

8+
it('keeps tableProperties as non-rendered metadata', () => {
9+
expect(attributes.tableProperties.rendered).toBe(false);
10+
});
11+
812
it('defaults imported HTML tables to 100% width', () => {
913
const tableElement = {
1014
closest: (selector) => (selector === '[data-superdoc-import="true"]' ? {} : null),

packages/super-editor/src/extensions/table/table.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -472,6 +472,7 @@ export const Table = Node.create({
472472
type: 'auto',
473473
},
474474
},
475+
rendered: false,
475476
parseDOM: (element) => {
476477
if (!isImportedTableElement(element)) return undefined;
477478

0 commit comments

Comments
 (0)