Skip to content

Commit a77894c

Browse files
committed
refactor(direction): finish dropping attrs.direction (diff.ts + stale fixtures)
Follow-up to 19b13fc. Two gaps caught on review: - layout-bridge/src/diff.ts:372 still compared a.direction !== b.direction inside paragraphAttrsEqual. Vitest passed because esbuild/swc skips cross-package types; the tsup DTS build was the one that caught it. Migrate to getParagraphInlineDirection(a) !== getParagraphInlineDirection(b) so the diff respects directionContext + paragraphProperties fallback. - Test fixtures across versionSignature.test.ts, rtl-date-parity.test.ts, cache.test.ts, and diff.test.ts still constructed hand-rolled FlowBlocks with { direction: 'rtl' }. They typecheck via Record<string, unknown> casts but no longer model the actual ParagraphAttrs shape. Migrate them all onto directionContext. Build sweep (contracts → pm-adapter → layout-bridge → layout-resolved → painter-dom) now passes; tests still green across all five.
1 parent edd24a6 commit a77894c

5 files changed

Lines changed: 20 additions & 11 deletions

File tree

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import type {
2020
DropCapDescriptor,
2121
ParagraphFrame,
2222
} from '@superdoc/contracts';
23+
import { getParagraphInlineDirection } from '@superdoc/contracts';
2324
import { fieldAnnotationKey } from './field-annotation-key.js';
2425
import { hashRunVisualMarks } from './run-visual-marks.js';
2526
import { hasTrackedChange, resolveTrackedChangesEnabled } from './tracked-changes-utils.js';
@@ -369,7 +370,7 @@ const paragraphAttrsEqual = (a?: ParagraphAttrs, b?: ParagraphAttrs): boolean =>
369370
a.tabIntervalTwips !== b.tabIntervalTwips ||
370371
a.keepNext !== b.keepNext ||
371372
a.keepLines !== b.keepLines ||
372-
a.direction !== b.direction ||
373+
getParagraphInlineDirection(a) !== getParagraphInlineDirection(b) ||
373374
a.floatAlignment !== b.floatAlignment
374375
) {
375376
return false;

packages/layout-engine/layout-bridge/test/cache.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2065,7 +2065,7 @@ describe('MeasureCache', () => {
20652065
{ val: 'end', pos: 8640, leader: 'dot' },
20662066
],
20672067
keepNext: true,
2068-
direction: 'ltr',
2068+
directionContext: { inlineDirection: 'ltr', writingMode: 'horizontal-tb' },
20692069
};
20702070

20712071
const block1 = paragraphWithAttrs('p1', 'Hello', complexAttrs);

packages/layout-engine/layout-bridge/test/diff.test.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -434,8 +434,16 @@ describe('computeDirtyRegions', () => {
434434

435435
describe('other paragraph attribute changes', () => {
436436
it('detects direction change', () => {
437-
const prev = [paragraphWithAttrs('p1', 'Hello', { direction: 'ltr' })];
438-
const next = [paragraphWithAttrs('p1', 'Hello', { direction: 'rtl' })];
437+
const prev = [
438+
paragraphWithAttrs('p1', 'Hello', {
439+
directionContext: { inlineDirection: 'ltr', writingMode: 'horizontal-tb' },
440+
}),
441+
];
442+
const next = [
443+
paragraphWithAttrs('p1', 'Hello', {
444+
directionContext: { inlineDirection: 'rtl', writingMode: 'horizontal-tb' },
445+
}),
446+
];
439447
const result = computeDirtyRegions(prev, next);
440448
expect(result.firstDirtyIndex).toBe(0);
441449
});
@@ -492,7 +500,7 @@ describe('computeDirtyRegions', () => {
492500
{ val: 'end' as const, pos: 8640, leader: 'dot' as const },
493501
],
494502
keepNext: true,
495-
direction: 'ltr' as const,
503+
directionContext: { inlineDirection: 'ltr' as const, writingMode: 'horizontal-tb' as const },
496504
};
497505
const prev = [paragraphWithAttrs('p1', 'Hello', complexAttrs)];
498506
const next = [paragraphWithAttrs('p1', 'Hello', complexAttrs)];

packages/layout-engine/layout-resolved/src/versionSignature.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ describe('deriveBlockVersion - bidi', () => {
3333
const makeParagraph = (bidi?: TextRun['bidi']): FlowBlock => ({
3434
kind: 'paragraph',
3535
id: 'p1',
36-
attrs: { direction: 'rtl' },
36+
attrs: { directionContext: { inlineDirection: 'rtl', writingMode: 'horizontal-tb' } },
3737
runs: [
3838
{
3939
text: '23.03.2026',

packages/layout-engine/painters/dom/src/rtl-date-parity.test.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ describe('RTL date parity', () => {
2525
const block: FlowBlock = {
2626
kind: 'paragraph',
2727
id: blockId,
28-
attrs: { direction: 'rtl' },
28+
attrs: { directionContext: { inlineDirection: 'rtl', writingMode: 'horizontal-tb' } },
2929
runs: [
3030
{
3131
text: runText,
@@ -54,7 +54,7 @@ describe('RTL date parity', () => {
5454
const block: FlowBlock = {
5555
kind: 'paragraph',
5656
id: blockId,
57-
attrs: { direction: 'rtl' },
57+
attrs: { directionContext: { inlineDirection: 'rtl', writingMode: 'horizontal-tb' } },
5858
runs: [{ text: runText, fontFamily: 'David, sans-serif', fontSize: 16, pmStart: 1, pmEnd: 7 }],
5959
};
6060

@@ -78,7 +78,7 @@ describe('RTL date parity', () => {
7878
const block: FlowBlock = {
7979
kind: 'paragraph',
8080
id: blockId,
81-
attrs: { direction: 'rtl' },
81+
attrs: { directionContext: { inlineDirection: 'rtl', writingMode: 'horizontal-tb' } },
8282
runs: [
8383
{ text: ltrText, fontFamily: 'David, sans-serif', fontSize: 16, pmStart: 1, pmEnd: 7 },
8484
{ text: rtlText, fontFamily: 'David, sans-serif', fontSize: 16, bidi: { rtl: true }, pmStart: 7, pmEnd: 11 },
@@ -122,7 +122,7 @@ describe('RTL date parity', () => {
122122
const block: FlowBlock = {
123123
kind: 'paragraph',
124124
id: blockId,
125-
attrs: { direction: 'rtl' },
125+
attrs: { directionContext: { inlineDirection: 'rtl', writingMode: 'horizontal-tb' } },
126126
runs: [
127127
{ text: runText, fontFamily: 'David, sans-serif', fontSize: 16, bidi: { rtl: true }, pmStart: 1, pmEnd: 5 },
128128
],
@@ -147,7 +147,7 @@ describe('RTL date parity', () => {
147147
const block: FlowBlock = {
148148
kind: 'paragraph',
149149
id: blockId,
150-
attrs: { direction: 'rtl' },
150+
attrs: { directionContext: { inlineDirection: 'rtl', writingMode: 'horizontal-tb' } },
151151
runs: [{ text: runText, fontFamily: 'David, sans-serif', fontSize: 16, pmStart: 1, pmEnd: 12 }],
152152
};
153153

0 commit comments

Comments
 (0)