Commit 51627ac
authored
refactor(direction): drop ParagraphAttrs.direction scalar field (SD-2778) (#3290)
* refactor(direction): centralize last paragraph isRtl reads on helper (SD-2778)
Migrate the two remaining direct reads of attrs.direction/.dir on the
paragraph inline-direction axis onto getParagraphInlineDirection:
- layout-bridge/src/position-hit.ts: isRtlBlock
- layout-resolved/src/resolveParagraph.ts: isRtl
Behavior is unchanged on the typed directionContext path and strictly
broader on fallback (the helper also covers paragraphProperties.rightToLeft).
After this, no consumer outside the helper reads the legacy scalar fields;
a follow-up can stop pm-adapter from writing them and drop them from
ParagraphAttrs.
* test(direction): pin SD-2778 migration via typed-path + broader-fallback cases
Two coverage gaps caught in review:
- layout-resolved/src/resolveLayout.test.ts ("preserves increasing
first-line marker anchor for nested RTL list levels") used
attrs.direction: 'rtl'. The pre-migration code read attrs.direction
directly, so that fixture would have passed against the old
implementation. Switch to directionContext.inlineDirection so the test
only passes through the new helper-driven typed path.
- layout-bridge/test/position-hit.test.ts: switching isRtlBlock to
getParagraphInlineDirection is strictly broader on fallback (the helper
also picks up paragraphProperties.rightToLeft when no directionContext
is present). Pin that case so the broadening is intentional and not a
regression vector.
* refactor(direction): drop ParagraphAttrs.direction scalar field (SD-2778)
After #3289 centralized every paragraph isRtl read on
getParagraphInlineDirection, the scalar attrs.direction field has no
remaining consumers. Drop it from the producer and the type:
- pm-adapter no longer writes the conditional direction spread on
ParagraphAttrs. directionContext.inlineDirection is the only source.
- contracts/index.ts: remove direction?: 'ltr' | 'rtl' from
ParagraphAttrs and point the directionContext doc at the helper.
- contracts/direction-context.ts: tighten getParagraphInlineDirection's
signature and body to drop the attrs.direction/.dir/.rtl fallbacks.
paragraphProperties.rightToLeft fallback stays for PM-node / editor
paths that read direction off the raw OOXML properties.
Tests that asserted on attrs.direction or constructed hand-rolled
FlowBlocks with { direction: 'rtl' } now use
directionContext.inlineDirection. Expect additive layout JSON snapshot
drift once the direction field disappears from paragraph attrs in
serialized layouts.
Tests: contracts 229, pm-adapter 1838, layout-bridge 1210,
layout-resolved 118, painter-dom 1070, super-editor 12836, style-engine
129 - all green.
* 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.
* docs(direction): retire ParagraphAttrs.direction mention in pm-adapter direction README
After SD-2778 drops the scalar `direction` field, the README sentence
that pointed consumers at it is stale. Point them at
`getParagraphInlineDirection` instead so the next reader lands on the
helper that knows about the typed context + paragraphProperties fallback.
* test(direction): pin producer contract that attrs.direction is not emitted
SD-2778 removes ParagraphAttrs.direction from the type, but TypeScript's
structural typing permits index-signature extra keys. Add a runtime
assertion inside the SD-2778 describe block that pm-adapter never emits
the legacy scalar field. Catches accidental re-introduction via a
future spread that TypeScript would let through.1 parent 202325b commit 51627ac
16 files changed
Lines changed: 85 additions & 98 deletions
File tree
- packages
- layout-engine
- contracts/src
- layout-bridge
- src
- test
- layout-resolved/src
- painters/dom/src
- pm-adapter/src
- attributes
- direction
- super-editor/src/editors/v1/core/presentation-editor/tests
Lines changed: 7 additions & 20 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
10 | | - | |
| 10 | + | |
11 | 11 | | |
12 | 12 | | |
13 | | - | |
14 | | - | |
| 13 | + | |
15 | 14 | | |
16 | 15 | | |
17 | 16 | | |
18 | 17 | | |
19 | 18 | | |
20 | 19 | | |
21 | | - | |
22 | | - | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
23 | 25 | | |
24 | 26 | | |
25 | 27 | | |
26 | | - | |
27 | | - | |
28 | | - | |
29 | | - | |
30 | | - | |
31 | | - | |
32 | | - | |
33 | | - | |
34 | | - | |
35 | | - | |
36 | | - | |
37 | | - | |
38 | | - | |
39 | | - | |
40 | | - | |
41 | 28 | | |
42 | 29 | | |
43 | 30 | | |
| |||
Lines changed: 5 additions & 14 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
161 | 161 | | |
162 | 162 | | |
163 | 163 | | |
164 | | - | |
165 | | - | |
166 | | - | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
167 | 167 | | |
168 | 168 | | |
169 | 169 | | |
| |||
172 | 172 | | |
173 | 173 | | |
174 | 174 | | |
175 | | - | |
176 | | - | |
177 | | - | |
178 | 175 | | |
179 | 176 | | |
180 | 177 | | |
181 | 178 | | |
182 | 179 | | |
183 | 180 | | |
184 | 181 | | |
185 | | - | |
186 | | - | |
187 | 182 | | |
188 | | - | |
189 | | - | |
190 | | - | |
191 | | - | |
192 | | - | |
193 | | - | |
| 183 | + | |
| 184 | + | |
194 | 185 | | |
195 | 186 | | |
196 | 187 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1533 | 1533 | | |
1534 | 1534 | | |
1535 | 1535 | | |
1536 | | - | |
1537 | | - | |
1538 | | - | |
1539 | | - | |
1540 | | - | |
1541 | | - | |
1542 | | - | |
1543 | | - | |
1544 | | - | |
1545 | 1536 | | |
1546 | 1537 | | |
1547 | 1538 | | |
1548 | 1539 | | |
| 1540 | + | |
| 1541 | + | |
| 1542 | + | |
| 1543 | + | |
1549 | 1544 | | |
1550 | 1545 | | |
1551 | 1546 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
20 | 20 | | |
21 | 21 | | |
22 | 22 | | |
| 23 | + | |
23 | 24 | | |
24 | 25 | | |
25 | 26 | | |
| |||
369 | 370 | | |
370 | 371 | | |
371 | 372 | | |
372 | | - | |
| 373 | + | |
373 | 374 | | |
374 | 375 | | |
375 | 376 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2024 | 2024 | | |
2025 | 2025 | | |
2026 | 2026 | | |
2027 | | - | |
2028 | | - | |
| 2027 | + | |
| 2028 | + | |
| 2029 | + | |
| 2030 | + | |
| 2031 | + | |
| 2032 | + | |
2029 | 2033 | | |
2030 | 2034 | | |
2031 | 2035 | | |
| |||
2061 | 2065 | | |
2062 | 2066 | | |
2063 | 2067 | | |
2064 | | - | |
| 2068 | + | |
2065 | 2069 | | |
2066 | 2070 | | |
2067 | 2071 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
434 | 434 | | |
435 | 435 | | |
436 | 436 | | |
437 | | - | |
438 | | - | |
| 437 | + | |
| 438 | + | |
| 439 | + | |
| 440 | + | |
| 441 | + | |
| 442 | + | |
| 443 | + | |
| 444 | + | |
| 445 | + | |
| 446 | + | |
439 | 447 | | |
440 | 448 | | |
441 | 449 | | |
| |||
492 | 500 | | |
493 | 501 | | |
494 | 502 | | |
495 | | - | |
| 503 | + | |
496 | 504 | | |
497 | 505 | | |
498 | 506 | | |
| |||
Lines changed: 5 additions & 9 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
23 | 23 | | |
24 | 24 | | |
25 | 25 | | |
26 | | - | |
27 | | - | |
28 | | - | |
29 | | - | |
30 | 26 | | |
31 | 27 | | |
32 | 28 | | |
33 | 29 | | |
34 | | - | |
| 30 | + | |
35 | 31 | | |
36 | 32 | | |
37 | 33 | | |
38 | | - | |
| 34 | + | |
39 | 35 | | |
40 | 36 | | |
41 | 37 | | |
| |||
45 | 41 | | |
46 | 42 | | |
47 | 43 | | |
48 | | - | |
| 44 | + | |
49 | 45 | | |
50 | 46 | | |
51 | | - | |
| 47 | + | |
52 | 48 | | |
53 | 49 | | |
54 | 50 | | |
55 | | - | |
| 51 | + | |
56 | 52 | | |
57 | 53 | | |
58 | 54 | | |
| |||
Lines changed: 1 addition & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
33 | 33 | | |
34 | 34 | | |
35 | 35 | | |
36 | | - | |
| 36 | + | |
37 | 37 | | |
38 | 38 | | |
39 | 39 | | |
| |||
Lines changed: 5 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
159 | 159 | | |
160 | 160 | | |
161 | 161 | | |
162 | | - | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
163 | 167 | | |
164 | 168 | | |
165 | 169 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
5006 | 5006 | | |
5007 | 5007 | | |
5008 | 5008 | | |
5009 | | - | |
| 5009 | + | |
5010 | 5010 | | |
5011 | 5011 | | |
5012 | 5012 | | |
| |||
6072 | 6072 | | |
6073 | 6073 | | |
6074 | 6074 | | |
6075 | | - | |
| 6075 | + | |
6076 | 6076 | | |
6077 | 6077 | | |
6078 | 6078 | | |
| |||
8536 | 8536 | | |
8537 | 8537 | | |
8538 | 8538 | | |
8539 | | - | |
| 8539 | + | |
8540 | 8540 | | |
8541 | 8541 | | |
8542 | 8542 | | |
| |||
8591 | 8591 | | |
8592 | 8592 | | |
8593 | 8593 | | |
8594 | | - | |
| 8594 | + | |
8595 | 8595 | | |
8596 | 8596 | | |
8597 | 8597 | | |
| |||
0 commit comments