Skip to content

Commit c343f29

Browse files
fix(editor): resolve per-rId header refs for decorations
1 parent 5722b61 commit c343f29

1 file changed

Lines changed: 16 additions & 2 deletions

File tree

packages/super-editor/src/editors/v1/core/presentation-editor/header-footer/HeaderFooterSessionManager.ts

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -375,6 +375,15 @@ function storyIdFromHeaderFooterLayoutKey(key: string): string {
375375
return key.replace(/::s\d+$/, '');
376376
}
377377

378+
function refForVariant(
379+
refs: Partial<Record<'default' | 'first' | 'even' | 'odd', string | null | undefined>> | undefined,
380+
variant: 'default' | 'first' | 'even' | 'odd',
381+
): string | undefined {
382+
const ref = refs?.[variant];
383+
if (ref) return ref;
384+
return variant === 'odd' ? (refs?.default ?? undefined) : undefined;
385+
}
386+
378387
function resolveResult(result: HeaderFooterLayoutResult, storyId?: string | null): ResolvedHeaderFooterLayout {
379388
const story = buildHeaderFooterStory(result.kind, storyId ?? String(result.type));
380389
return resolveHeaderFooterLayout(result.layout, result.blocks, result.measures, story);
@@ -2384,15 +2393,20 @@ export class HeaderFooterSessionManager {
23842393
return null;
23852394
}
23862395

2387-
const effectiveRef = multiSectionId
2396+
const effectiveRef = multiSectionId?.sections?.length
23882397
? resolveEffectiveHeaderFooterRef({
23892398
sections: multiSectionId.sections,
23902399
sectionIndex,
23912400
kind,
23922401
variant: headerFooterType,
23932402
})
23942403
: null;
2395-
const sectionRId = effectiveRef?.refId;
2404+
const pageSectionRefs = kind === 'header' ? page?.sectionRefs?.headerRefs : page?.sectionRefs?.footerRefs;
2405+
const legacyRefs = kind === 'header' ? legacyIdentifier.headerIds : legacyIdentifier.footerIds;
2406+
const sectionRId =
2407+
effectiveRef?.refId ??
2408+
refForVariant(pageSectionRefs, headerFooterType) ??
2409+
refForVariant(legacyRefs, headerFooterType);
23962410
const layoutVariantType = effectiveRef?.matchedVariant ?? headerFooterType;
23972411

23982412
// PRIORITY 1: Try per-rId layout (composite key first for per-section margins, then plain rId)

0 commit comments

Comments
 (0)