-
Notifications
You must be signed in to change notification settings - Fork 205
feat: add w:pPrChange translator for paragraph property tracked changes (SD-2417) #2705
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
caio-pizzol
merged 7 commits into
main
from
luccas/sd-2417-investigation-structural-tracked-changes-dropped-on-import
Apr 22, 2026
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
3e946ec
feat: add translator for w:pPrChange
luccas-harbour aeb4024
fix(pPrChange): preserve empty w:pPr on round-trip
luccas-harbour b511ab1
chore(super-converter): drop unused emitWhenAttributesOnly option
luccas-harbour 6df83ac
fix(super-converter): order sectPr before pPrChange in w:pPr
luccas-harbour c25c3bf
Merge branch 'main' into luccas/sd-2417-investigation-structural-trac…
luccas-harbour c6f09d3
Merge branch 'main' into luccas/sd-2417-investigation-structural-trac…
caio-pizzol 8c07f00
test(pPrChange): cover mixed sectPr and pPr routing (SD-2417)
caio-pizzol File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
75 changes: 75 additions & 0 deletions
75
...uper-editor/src/editors/v1/core/super-converter/v3/handlers/w/pPr/pPr-base-translators.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,75 @@ | ||
| // @ts-check | ||
| import { translator as mcAlternateContentTranslator } from '../../mc/altermateContent'; | ||
| import { translator as wAdjustRightIndTranslator } from '../adjustRightInd'; | ||
| import { translator as wAutoSpaceDETranslator } from '../autoSpaceDE'; | ||
| import { translator as wAutoSpaceDNTranslator } from '../autoSpaceDN'; | ||
| import { translator as wBidiTranslator } from '../bidi'; | ||
| import { translator as wCnfStyleTranslator } from '../cnfStyle'; | ||
| import { translator as wContextualSpacingTranslator } from '../contextualSpacing'; | ||
| import { translator as wDivIdTranslator } from '../divId'; | ||
| import { translator as wFramePrTranslator } from '../framePr'; | ||
| import { translator as wIndTranslator } from '../ind'; | ||
| import { translator as wJcTranslatorTranslator } from '../jc'; | ||
| import { translator as wKeepLinesTranslator } from '../keepLines'; | ||
| import { translator as wKeepNextTranslator } from '../keepNext'; | ||
| import { translator as wKinsokuTranslator } from '../kinsoku'; | ||
| import { translator as wMirrorIndentsTranslator } from '../mirrorIndents'; | ||
| import { translator as wNumPrTranslator } from '../numPr'; | ||
| import { translator as wOutlineLvlTranslator } from '../outlineLvl'; | ||
| import { translator as wOverflowPunctTranslator } from '../overflowPunct'; | ||
| import { translator as wPBdrTranslator } from '../pBdr'; | ||
| import { translator as wPStyleTranslator } from '../pStyle'; | ||
| import { translator as wPageBreakBeforeTranslator } from '../pageBreakBefore'; | ||
| import { translator as wShdTranslator } from '../shd'; | ||
| import { translator as wSnapToGridTranslator } from '../snapToGrid'; | ||
| import { translator as wSpacingTranslator } from '../spacing'; | ||
| import { translator as wSuppressAutoHyphensTranslator } from '../suppressAutoHyphens'; | ||
| import { translator as wSuppressLineNumbersTranslator } from '../suppressLineNumbers'; | ||
| import { translator as wSuppressOverlapTranslator } from '../suppressOverlap'; | ||
| import { translator as wTabsTranslator } from '../tabs'; | ||
| import { translator as wTextAlignmentTranslator } from '../textAlignment'; | ||
| import { translator as wTextDirectionTranslator } from '../textDirection'; | ||
| import { translator as wTextboxTightWrapTranslator } from '../textboxTightWrap'; | ||
| import { translator as wTopLinePunctTranslator } from '../topLinePunct'; | ||
| import { translator as wWidowControlTranslator } from '../widowControl'; | ||
| import { translator as wWordWrapTranslator } from '../wordWrap'; | ||
| import { translator as wRPrTranslator } from '../rpr'; | ||
|
|
||
| /** @type {import('@translator').NodeTranslator[]} */ | ||
| export const basePropertyTranslators = [ | ||
| mcAlternateContentTranslator, | ||
| wAdjustRightIndTranslator, | ||
| wAutoSpaceDETranslator, | ||
| wAutoSpaceDNTranslator, | ||
| wBidiTranslator, | ||
| wCnfStyleTranslator, | ||
| wContextualSpacingTranslator, | ||
| wDivIdTranslator, | ||
| wFramePrTranslator, | ||
| wIndTranslator, | ||
| wJcTranslatorTranslator, | ||
| wKeepLinesTranslator, | ||
| wKeepNextTranslator, | ||
| wKinsokuTranslator, | ||
| wMirrorIndentsTranslator, | ||
| wNumPrTranslator, | ||
| wOutlineLvlTranslator, | ||
| wOverflowPunctTranslator, | ||
| wPBdrTranslator, | ||
| wPStyleTranslator, | ||
| wPageBreakBeforeTranslator, | ||
| wShdTranslator, | ||
| wSnapToGridTranslator, | ||
| wSpacingTranslator, | ||
| wSuppressAutoHyphensTranslator, | ||
| wSuppressLineNumbersTranslator, | ||
| wSuppressOverlapTranslator, | ||
| wTabsTranslator, | ||
| wTextAlignmentTranslator, | ||
| wTextDirectionTranslator, | ||
| wTextboxTightWrapTranslator, | ||
| wTopLinePunctTranslator, | ||
| wWidowControlTranslator, | ||
| wWordWrapTranslator, | ||
| wRPrTranslator, | ||
| ]; |
77 changes: 3 additions & 74 deletions
77
...ages/super-editor/src/editors/v1/core/super-converter/v3/handlers/w/pPr/pPr-translator.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
packages/super-editor/src/editors/v1/core/super-converter/v3/handlers/w/pPrChange/index.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| export * from './pPrChange-translator.js'; |
99 changes: 99 additions & 0 deletions
99
...ditor/src/editors/v1/core/super-converter/v3/handlers/w/pPrChange/pPrChange-translator.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,99 @@ | ||
| import { NodeTranslator } from '@translator'; | ||
| import { carbonCopy } from '@core/utilities/carbonCopy.js'; | ||
| import { createNestedPropertiesTranslator, createAttributeHandler } from '@converter/v3/handlers/utils.js'; | ||
| import { basePropertyTranslators } from '../pPr/pPr-base-translators.js'; | ||
|
|
||
| const pPrTranslator = NodeTranslator.from( | ||
| createNestedPropertiesTranslator('w:pPr', 'paragraphProperties', basePropertyTranslators), | ||
| ); | ||
|
|
||
| const ATTRIBUTE_HANDLERS = [ | ||
| createAttributeHandler('w:id'), | ||
| createAttributeHandler('w:author'), | ||
| createAttributeHandler('w:date'), | ||
| ]; | ||
|
|
||
| function getSectPr(pPrNode) { | ||
| const sectPr = pPrNode?.elements?.find((el) => el.name === 'w:sectPr'); | ||
| return sectPr ? carbonCopy(sectPr) : undefined; | ||
| } | ||
|
|
||
| /** | ||
| * The NodeTranslator instance for the w:pPrChange element. | ||
| * @type {import('@translator').NodeTranslator} | ||
| */ | ||
| export const translator = NodeTranslator.from({ | ||
| xmlName: 'w:pPrChange', | ||
| sdNodeOrKeyName: 'change', | ||
| type: NodeTranslator.translatorTypes.NODE, | ||
| attributes: ATTRIBUTE_HANDLERS, | ||
| encode: (params, encodedAttrs = {}) => { | ||
| const changeNode = params.nodes[0]; | ||
| const pPrNode = changeNode?.elements?.find((el) => el.name === 'w:pPr'); | ||
|
|
||
| let paragraphProperties = pPrNode ? (pPrTranslator.encode({ ...params, nodes: [pPrNode] }) ?? {}) : undefined; | ||
| const sectPr = getSectPr(pPrNode); | ||
| if (sectPr) { | ||
| paragraphProperties = { | ||
| ...(paragraphProperties || {}), | ||
| sectPr, | ||
| }; | ||
| } | ||
|
|
||
| const result = { | ||
| ...encodedAttrs, | ||
| ...(paragraphProperties ? { paragraphProperties } : {}), | ||
| }; | ||
|
|
||
| return Object.keys(result).length ? result : undefined; | ||
| }, | ||
| decode: function (params) { | ||
| const change = params.node?.attrs?.change; | ||
| if (!change || typeof change !== 'object') return undefined; | ||
|
|
||
| const decodedAttrs = this.decodeAttributes({ | ||
| node: { ...params.node, attrs: change }, | ||
| }); | ||
| const hasParagraphProperties = Object.prototype.hasOwnProperty.call(change, 'paragraphProperties'); | ||
| const paragraphProperties = hasParagraphProperties ? change.paragraphProperties : undefined; | ||
|
|
||
| let pPrNode = | ||
| paragraphProperties && typeof paragraphProperties === 'object' | ||
| ? pPrTranslator.decode({ | ||
| ...params, | ||
| node: { ...params.node, attrs: { paragraphProperties } }, | ||
| }) | ||
| : undefined; | ||
|
|
||
| const sectPr = paragraphProperties?.sectPr ? carbonCopy(paragraphProperties.sectPr) : undefined; | ||
| if (sectPr) { | ||
| if (!pPrNode) { | ||
| pPrNode = { | ||
| name: 'w:pPr', | ||
| type: 'element', | ||
| attributes: {}, | ||
| elements: [], | ||
| }; | ||
| } | ||
| pPrNode.elements = [...(pPrNode.elements || []), sectPr]; | ||
| } | ||
|
|
||
| if (!pPrNode && hasParagraphProperties) { | ||
| pPrNode = { | ||
| name: 'w:pPr', | ||
| type: 'element', | ||
| attributes: {}, | ||
| elements: [], | ||
| }; | ||
| } | ||
|
|
||
| if (!pPrNode && !Object.keys(decodedAttrs).length) return undefined; | ||
|
|
||
| return { | ||
| name: 'w:pPrChange', | ||
| type: 'element', | ||
| attributes: decodedAttrs, | ||
| elements: pPrNode ? [pPrNode] : [], | ||
| }; | ||
| }, | ||
| }); |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.