docxmlater 11.0.9 → 11.0.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "docxmlater",
3
- "version": "11.0.9",
3
+ "version": "11.0.10",
4
4
  "description": "TypeScript library for editing existing Word documents with full tracked-changes, comment, and bookmark fidelity. Round-trip safe DOCX modification.",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -3787,13 +3787,18 @@ export class DocumentParser {
3787
3787
  hyperlink.setTooltip(parsed.tooltip);
3788
3788
  }
3789
3789
 
3790
- // Group field runs by paragraph index
3791
- const runsByParagraph = new Map<number, Set<number>>();
3790
+ // Group field runs by paragraph, keyed by Run OBJECT IDENTITY (not index).
3791
+ // Adjacent HYPERLINK fields chain across paragraph boundaries (one paragraph holds
3792
+ // the previous field's `end` followed by the next field's `begin`). Processing the
3793
+ // earlier field mutates that shared paragraph via setContent, shifting run indices;
3794
+ // a captured runIndex for a later field would then point at the wrong run and drop
3795
+ // its content. Matching by object identity is stable across those mutations.
3796
+ const runsByParagraph = new Map<number, Set<Run>>();
3792
3797
  for (const fr of fieldTracker.fieldRuns) {
3793
3798
  if (!runsByParagraph.has(fr.paragraphIndex)) {
3794
3799
  runsByParagraph.set(fr.paragraphIndex, new Set());
3795
3800
  }
3796
- runsByParagraph.get(fr.paragraphIndex)!.add(fr.runIndex);
3801
+ runsByParagraph.get(fr.paragraphIndex)!.add(fr.run);
3797
3802
  }
3798
3803
 
3799
3804
  // Process each affected paragraph
@@ -3801,7 +3806,7 @@ export class DocumentParser {
3801
3806
 
3802
3807
  for (const pIdx of affectedParagraphIndices) {
3803
3808
  const paragraph = allParagraphs[pIdx]!;
3804
- const runIndicesToRemove = runsByParagraph.get(pIdx)!;
3809
+ const runsToRemove = runsByParagraph.get(pIdx)!;
3805
3810
  const content = paragraph.getContent();
3806
3811
 
3807
3812
  if (pIdx === targetParagraphIndex) {
@@ -3810,7 +3815,7 @@ export class DocumentParser {
3810
3815
  let hyperlinkInserted = false;
3811
3816
 
3812
3817
  for (let rIdx = 0; rIdx < content.length; rIdx++) {
3813
- if (runIndicesToRemove.has(rIdx)) {
3818
+ if (runsToRemove.has(content[rIdx] as Run)) {
3814
3819
  // Insert Hyperlink at position of first field run in this paragraph
3815
3820
  if (!hyperlinkInserted) {
3816
3821
  newContent.push(hyperlink);
@@ -3826,7 +3831,7 @@ export class DocumentParser {
3826
3831
  } else {
3827
3832
  // Other paragraphs: remove field runs entirely
3828
3833
  const newContent = content.filter(
3829
- (_: ParagraphContent, rIdx: number) => !runIndicesToRemove.has(rIdx)
3834
+ (item: ParagraphContent) => !runsToRemove.has(item as Run)
3830
3835
  );
3831
3836
  paragraph.setContent(newContent);
3832
3837
  }