Skip to content

Commit e11acc5

Browse files
authored
fix(layout): per-section footer constraints for multi-section docs (SD-1837) (#2022)
* fix(layout): per-section footer constraints and fldSimple field rendering (SD-1837) Footer tables now respect per-section margins in multi-section documents. Previously, all footers were measured using the first section's content width, causing table overflow on sections with different margins. Key changes: - Add margins/pageSize to SectionMetadata for per-section constraint computation - Refactor layoutPerRIdHeaderFooters to compute per-section constraints using composite keys (rId::sN) for section-specific measurements - Handle pct-based table widths by pre-expanding constraints - Add rescaleColumnWidths to all table fragment creation sites (SD-1859) - Unwrap unhandled w:fldSimple fields (FILENAME, etc.) to render cached text * fix(editor): footer editing and page interaction bugs (SD-1837) Fix multiple issues with footer editing in presentation mode: - Fix hover tooltip only showing on first page by detecting page index from DOM via elementsFromPoint in normalizeClientPoint - Fix double-click on footer selecting body text by properly preventing default browser behavior on pointerdown in footer regions - Fix clicking on page N redirecting to page 1 by keeping Y as global layout coordinates in normalizeClientPoint (only X is adjusted for page centering) and computing page-local Y separately from the page element's bounding rect for header/footer hit testing - Fix switching between footer editors on different pages by cleaning up the previous editing session in enterMode before setting up the new one - Fix footer table layout collapsing by setting table-layout:fixed on tables in the footer ProseMirror editor element - Fix wrong total page count in footer by reading body layout page count via getBodyPageCount dependency instead of header layout - Fix page-number NodeView reading incorrect totalPageCount property * docs(converter): clarify preProcessPageFieldsOnly is rendering-only, not import pipeline
1 parent 33e907b commit e11acc5

20 files changed

Lines changed: 666 additions & 110 deletions

File tree

packages/layout-engine/contracts/src/index.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -859,6 +859,17 @@ export type SectionMetadata = {
859859
titlePg?: boolean;
860860
/** Vertical alignment of content within this section's pages */
861861
vAlign?: SectionVerticalAlign;
862+
/** Section page margins in CSS px */
863+
margins?: {
864+
top?: number;
865+
right?: number;
866+
bottom?: number;
867+
left?: number;
868+
header?: number;
869+
footer?: number;
870+
} | null;
871+
/** Section page size in CSS px */
872+
pageSize?: { w: number; h: number } | null;
862873
};
863874

864875
export type PageBreakBlock = {

packages/layout-engine/layout-bridge/src/incrementalLayout.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ export type HeaderFooterLayoutResult = {
3636
layout: HeaderFooterLayout;
3737
blocks: FlowBlock[];
3838
measures: Measure[];
39+
/** Effective layout width when table grid widths exceed section content width (SD-1837). */
40+
effectiveWidth?: number;
3941
};
4042

4143
export type IncrementalLayoutResult = {

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

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1385,11 +1385,7 @@ export const renderTableCell = (deps: TableCellRenderDependencies): TableCellRen
13851385
* indentation but skips marker text rendering).
13861386
*/
13871387
const shouldRenderMarker =
1388-
markerLayout &&
1389-
markerMeasure &&
1390-
lineIdx === 0 &&
1391-
localStartLine === 0 &&
1392-
markerMeasure.markerWidth > 0;
1388+
markerLayout && markerMeasure && lineIdx === 0 && localStartLine === 0 && markerMeasure.markerWidth > 0;
13931389

13941390
if (shouldRenderMarker) {
13951391
// Prepend marker + suffix inside lineEl (mirrors renderer.ts approach)

packages/layout-engine/pm-adapter/src/sections/analysis.test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -846,6 +846,8 @@ describe('analysis', () => {
846846
footerRefs: { default: 'footer1' },
847847
numbering: { format: 'decimal' },
848848
titlePg: false,
849+
margins: null,
850+
pageSize: null,
849851
});
850852
});
851853

packages/layout-engine/pm-adapter/src/sections/analysis.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,8 @@ export function publishSectionMetadata(sectionRanges: SectionRange[], options?:
204204
numbering: section.numbering,
205205
titlePg: section.titlePg,
206206
vAlign: section.vAlign,
207+
margins: section.margins,
208+
pageSize: section.pageSize,
207209
});
208210
});
209211
}

packages/super-editor/src/assets/styles/elements/prosemirror.css

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,18 @@ https://github.com/ProseMirror/prosemirror-tables/blob/master/demo/index.html
162162
/* width: 100%; */
163163
}
164164

165+
/* Header/footer editors: constrain table to the editor's available width.
166+
Raw DOCX grid <col> widths may exceed the section's content area.
167+
table-layout:auto treats col widths as preferred (not hard) constraints,
168+
so the browser can redistribute columns to fit within width:100%.
169+
!important overrides inline styles set by TableView.updateTable()
170+
which resets styles via table.style.cssText. */
171+
.sd-editor-scoped .ProseMirror.sd-header-footer table {
172+
table-layout: auto !important;
173+
width: 100% !important;
174+
max-width: 100% !important;
175+
}
176+
165177
.sd-editor-scoped .ProseMirror tr {
166178
position: relative;
167179
}

packages/super-editor/src/core/header-footer/EditorOverlayManager.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -390,7 +390,7 @@ export class EditorOverlayManager {
390390
position: 'absolute',
391391
pointerEvents: 'auto', // Critical: enables click interaction
392392
visibility: 'hidden', // Hidden by default, shown during editing
393-
overflow: 'hidden',
393+
overflow: 'visible', // Allow table overflow (page's overflow:hidden still clips at page edge)
394394
boxSizing: 'border-box',
395395
});
396396

0 commit comments

Comments
 (0)